Skip to content

Commit

Permalink
Merge pull request aws-amplify#161 from powerful23/endpointID_missing…
Browse files Browse the repository at this point in the history
…_error

Endpoint id missing error
  • Loading branch information
powerful23 authored Jan 18, 2018
2 parents 0db1923 + e84b804 commit 968e054
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 111 deletions.
10 changes: 10 additions & 0 deletions packages/aws-amplify/__tests__/Analytics/Analytics-unit-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ describe("Analytics test", () => {
spyon.mockClear();
});

test("with no config", () => {
const spyon = jest.spyOn(Analytics.prototype, "configure");

const analytics = new Analytics(null);

expect(spyon).not.toBeCalled();

spyon.mockClear();
});

test('with client_info platform', () => {
const spyon = jest.spyOn(Analytics.prototype, "configure");
const spyon2 = jest.spyOn(ClientDevice, 'clientInfo').mockImplementationOnce(() => {
Expand Down
63 changes: 28 additions & 35 deletions packages/aws-amplify/dist/aws-amplify.js
Original file line number Diff line number Diff line change
Expand Up @@ -32543,30 +32543,16 @@ var AnalyticsClass = /** @class */ (function () {
* @param config - Configuration of the Analytics
*/
function AnalyticsClass(config) {
this.configure(config);
if (config) {
this.configure(config);
}
else {
this._config = {};
}
var client_info = Common_1.ClientDevice.clientInfo();
if (client_info.platform) {
this._config.platform = client_info.platform;
}
// store endpointId into localstorage
if (!this._config.endpointId) {
/*
if (window.localStorage) {
let endpointId = window.localStorage.getItem('amplify_endpoint_id');
if (!endpointId) {
endpointId = this.generateRandomString();
window.localStorage.setItem('amplify_endpoint_id', endpointId);
}
this._config.endpointId = endpointId;
}
else {
this._config.endpointId = this.generateRandomString();
}*/
var credentials = this._config.credentials;
if (credentials && credentials.identityId) {
this._config.endpointId = credentials.identityId;
}
}
this._buffer = [];
}
/**
Expand Down Expand Up @@ -32621,11 +32607,11 @@ var AnalyticsClass = /** @class */ (function () {
return new Promise(function (res, rej) {
_this.mobileAnalytics.putEvents(params, function (err, data) {
if (err) {
logger.debug('record event failed. ' + err);
logger.debug('record event failed. ', err);
rej(err);
}
else {
logger.debug('record event success. ' + data);
logger.debug('record event success. ', data);
res(data);
}
});
Expand Down Expand Up @@ -32656,11 +32642,11 @@ var AnalyticsClass = /** @class */ (function () {
return new Promise(function (res, rej) {
_this.mobileAnalytics.putEvents(params, function (err, data) {
if (err) {
logger.debug('record event failed. ' + err);
logger.debug('record event failed. ', err);
rej(err);
}
else {
logger.debug('record event success. ' + data);
logger.debug('record event success. ', data);
res(data);
}
});
Expand All @@ -32676,6 +32662,7 @@ var AnalyticsClass = /** @class */ (function () {
var _this = this;
return __generator(this, function (_a) {
this.stopSession().then(function (data) {
logger.debug('restarting clients');
return _this._initClients();
}).catch(function (e) {
logger.debug('restart error', e);
Expand Down Expand Up @@ -32719,11 +32706,11 @@ var AnalyticsClass = /** @class */ (function () {
return new Promise(function (res, rej) {
_this.mobileAnalytics.putEvents(params, function (err, data) {
if (err) {
logger.debug('record event failed. ' + err);
logger.debug('record event failed. ', err);
rej(err);
}
else {
logger.debug('record event success. ' + data);
logger.debug('record event success. ', data);
res(data);
}
});
Expand Down Expand Up @@ -32810,11 +32797,10 @@ var AnalyticsClass = /** @class */ (function () {
return Auth_1.default.currentCredentials()
.then(function (credentials) {
var cred = Auth_1.default.essentialCredentials(credentials);
logger.debug('set credentials for analytics', cred);
conf.credentials = cred;
if (!conf.endpointId && conf.credentials) {
conf.endpointId = conf.credentials.identityId;
}
conf.endpointId = conf.credentials.identityId;
logger.debug('set endpointId for analytics', conf.endpointId);
logger.debug('set credentials for analytics', conf.credentials);
return true;
})
.catch(function (err) {
Expand All @@ -32830,7 +32816,7 @@ var AnalyticsClass = /** @class */ (function () {
*/
AnalyticsClass.prototype._initClients = function () {
return __awaiter(this, void 0, void 0, function () {
var credentialsOK;
var credentialsOK, e_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
Expand All @@ -32844,11 +32830,18 @@ var AnalyticsClass = /** @class */ (function () {
return [2 /*return*/, false];
}
this._initMobileAnalytics();
return [4 /*yield*/, this._initPinpoint()];
_a.label = 2;
case 2:
_a.trys.push([2, 4, , 5]);
return [4 /*yield*/, this._initPinpoint()];
case 3:
_a.sent();
this.startSession();
return [2 /*return*/, true];
return [3 /*break*/, 5];
case 4:
e_1 = _a.sent();
return [2 /*return*/, false];
case 5: return [2 /*return*/, true];
}
});
});
Expand Down Expand Up @@ -32888,7 +32881,7 @@ var AnalyticsClass = /** @class */ (function () {
EndpointId: endpointId,
EndpointRequest: request
};
logger.debug(update_params);
logger.debug('updateEndpoint with params: ', update_params);
return new Promise(function (res, rej) {
_this.pinpointClient.updateEndpoint(update_params, function (err, data) {
if (err) {
Expand All @@ -32910,7 +32903,7 @@ var AnalyticsClass = /** @class */ (function () {
var client_info = Common_1.ClientDevice.clientInfo();
var credentials = this._config.credentials;
var user_id = (credentials && credentials.authenticated) ? credentials.identityId : null;
logger.debug('demographic user id: ' + user_id);
logger.debug('demographic user id: ', user_id);
return {
Demographic: {
AppVersion: this._config.appVersion || client_info.appVersion,
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-amplify/dist/aws-amplify.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/aws-amplify/dist/aws-amplify.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/aws-amplify/dist/aws-amplify.min.js.map

Large diffs are not rendered by default.

63 changes: 28 additions & 35 deletions packages/aws-amplify/lib/Analytics/Analytics.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 968e054

Please sign in to comment.