@aws-amplify/analytics
Advanced tools
Comparing version 1.2.9-unstable.1 to 1.2.9-unstable.2
@@ -6,2 +6,13 @@ # Change Log | ||
<a name="1.2.9-unstable.2"></a> | ||
## [1.2.9-unstable.2](https://github.com/aws/aws-amplify/compare/@aws-amplify/analytics@1.2.9-unstable.1...@aws-amplify/analytics@1.2.9-unstable.2) (2018-12-24) | ||
### Bug Fixes | ||
* **@aws-amplify/analytics:** unlink user id from endpoint when limit exceeds ([b2de140](https://github.com/aws/aws-amplify/commit/b2de140)) | ||
<a name="1.2.9-unstable.1"></a> | ||
@@ -8,0 +19,0 @@ ## [1.2.9-unstable.1](https://github.com/aws/aws-amplify/compare/@aws-amplify/analytics@1.2.9-unstable.0...@aws-amplify/analytics@1.2.9-unstable.1) (2018-12-24) |
@@ -60,2 +60,3 @@ import { AnalyticsProvider } from '../types'; | ||
private _updateEndpoint; | ||
private _removeUnusedEndpoints; | ||
/** | ||
@@ -62,0 +63,0 @@ * @private |
@@ -412,2 +412,3 @@ "use strict"; | ||
var timestamp, config, credentials, event, appId, region, endpointId, request, update_params, that; | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
@@ -429,7 +430,20 @@ timestamp = params.timestamp, config = params.config, credentials = params.credentials, event = params.event; | ||
logger.debug('updateEndpoint failed', err); | ||
res(false); | ||
if (err.message === 'Exceeded maximum endpoint per user count 10') { | ||
_this._removeUnusedEndpoints(appId, credentials.identityId) | ||
.then(function () { | ||
logger.debug('Remove the unused endpoints successfully'); | ||
return res(false); | ||
}).catch(function (e) { | ||
logger.warn("Failed to remove unused endpoints with error: " + e); | ||
logger.warn("Please ensure you have updated you Pinpoint IAM Policy " + | ||
"with the Action: \"mobiletargeting:GetUserEndpoints\" " + | ||
"in order to get endpoints info of the user"); | ||
return res(false); | ||
}); | ||
} | ||
return res(false); | ||
} | ||
else { | ||
logger.debug('updateEndpoint success', data); | ||
res(true); | ||
return res(true); | ||
} | ||
@@ -441,2 +455,55 @@ }); | ||
}; | ||
AWSPinpointProvider.prototype._removeUnusedEndpoints = function (appId, userId) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, new Promise(function (res, rej) { | ||
_this.pinpointClient.getUserEndpoints({ | ||
ApplicationId: appId, | ||
UserId: userId | ||
}, function (err, data) { | ||
if (err) { | ||
logger.debug("Failed to get endpoints associated with the userId: " + userId + " with error", err); | ||
return rej(err); | ||
} | ||
var endpoints = data.EndpointsResponse.Item; | ||
logger.debug("get endpoints associated with the userId: " + userId + " with data", endpoints); | ||
var endpointToBeDeleted = endpoints[0]; | ||
for (var i = 1; i < endpoints.length; i++) { | ||
var timeStamp1 = Date.parse(endpointToBeDeleted['EffectiveDate']); | ||
var timeStamp2 = Date.parse(endpoints[i]['EffectiveDate']); | ||
// delete the one with invalid effective date | ||
if (isNaN(timeStamp1)) | ||
break; | ||
if (isNaN(timeStamp2)) { | ||
endpointToBeDeleted = endpoints[i]; | ||
break; | ||
} | ||
if (timeStamp2 < timeStamp1) { | ||
endpointToBeDeleted = endpoints[i]; | ||
} | ||
} | ||
// update the endpoint's user id with an empty string | ||
var update_params = { | ||
ApplicationId: appId, | ||
EndpointId: endpointToBeDeleted['Id'], | ||
EndpointRequest: { | ||
User: { | ||
UserId: '' | ||
} | ||
} | ||
}; | ||
_this.pinpointClient.updateEndpoint(update_params, function (err, data) { | ||
if (err) { | ||
logger.debug('Failed to update the endpoint', err); | ||
return rej(err); | ||
} | ||
logger.debug('The old endpoint is updated with an empty string for user id'); | ||
return res(data); | ||
}); | ||
}); | ||
})]; | ||
}); | ||
}); | ||
}; | ||
/** | ||
@@ -443,0 +510,0 @@ * @private |
{ | ||
"name": "@aws-amplify/analytics", | ||
"version": "1.2.9-unstable.1", | ||
"version": "1.2.9-unstable.2", | ||
"description": "Analytics category of aws-amplify", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4944706
26265