@aws-amplify/analytics 7.0.1-console-preview.7919075.0 → 7.0.1-console-preview.5dc0b68.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/errors/AnalyticsError.d.ts +7 -0
- package/lib/errors/AnalyticsError.js +23 -0
- package/lib/errors/assertValidationError.d.ts +5 -0
- package/lib/errors/assertValidationError.js +17 -0
- package/lib/errors/index.d.ts +3 -0
- package/lib/errors/index.js +12 -0
- package/lib/errors/validation.d.ts +9 -0
- package/lib/errors/validation.js +31 -0
- package/lib/index.d.ts +0 -3
- package/lib/index.js +0 -15
- package/lib/providers/pinpoint/apis/identifyUser.d.ts +10 -0
- package/lib/providers/pinpoint/apis/identifyUser.js +44 -0
- package/lib/providers/pinpoint/apis/index.d.ts +2 -0
- package/lib/providers/pinpoint/apis/index.js +9 -0
- package/lib/providers/pinpoint/apis/record.d.ts +11 -0
- package/lib/providers/pinpoint/apis/record.js +44 -0
- package/lib/providers/pinpoint/index.d.ts +1 -1
- package/lib/providers/pinpoint/index.js +1 -7
- package/lib/providers/pinpoint/types/errors.d.ts +9 -0
- package/lib/providers/pinpoint/types/errors.js +15 -0
- package/lib/providers/pinpoint/types/index.d.ts +2 -0
- package/lib/providers/pinpoint/types/index.js +7 -0
- package/lib/providers/pinpoint/types/parameters.d.ts +18 -0
- package/lib/providers/pinpoint/utils/index.d.ts +2 -0
- package/lib/providers/pinpoint/utils/index.js +9 -0
- package/lib/providers/pinpoint/utils/resolveConfig.d.ts +7 -0
- package/lib/providers/pinpoint/utils/resolveConfig.js +18 -0
- package/lib/providers/pinpoint/utils/resolveCredentials.d.ts +12 -0
- package/lib/providers/pinpoint/utils/resolveCredentials.js +24 -0
- package/lib/setupTests.js +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/{lib-esm/types/Analytics.d.ts → lib/types/analytics.d.ts} +0 -8
- package/lib/types/index.d.ts +1 -3
- package/lib/types/index.js +1 -3
- package/lib/utils/{UserAgent.d.ts → userAgent.d.ts} +1 -1
- package/lib/utils/{UserAgent.js → userAgent.js} +5 -5
- package/lib-esm/errors/AnalyticsError.d.ts +7 -0
- package/lib-esm/errors/AnalyticsError.js +20 -0
- package/lib-esm/errors/assertValidationError.d.ts +5 -0
- package/lib-esm/errors/assertValidationError.js +13 -0
- package/lib-esm/errors/index.d.ts +3 -0
- package/lib-esm/errors/index.js +5 -0
- package/lib-esm/errors/validation.d.ts +9 -0
- package/lib-esm/errors/validation.js +28 -0
- package/lib-esm/index.d.ts +0 -3
- package/lib-esm/index.js +0 -12
- package/lib-esm/providers/pinpoint/apis/identifyUser.d.ts +10 -0
- package/lib-esm/providers/pinpoint/apis/identifyUser.js +40 -0
- package/lib-esm/providers/pinpoint/apis/index.d.ts +2 -0
- package/{src/types/providers/index.ts → lib-esm/providers/pinpoint/apis/index.js} +2 -1
- package/lib-esm/providers/pinpoint/apis/record.d.ts +11 -0
- package/lib-esm/providers/pinpoint/apis/record.js +40 -0
- package/lib-esm/providers/pinpoint/index.d.ts +1 -1
- package/lib-esm/providers/pinpoint/index.js +1 -6
- package/lib-esm/providers/pinpoint/types/errors.d.ts +9 -0
- package/lib-esm/providers/pinpoint/types/errors.js +12 -0
- package/lib-esm/providers/pinpoint/types/index.d.ts +2 -0
- package/lib-esm/{types/providers → providers/pinpoint/types}/index.js +1 -1
- package/lib-esm/providers/pinpoint/types/parameters.d.ts +18 -0
- package/lib-esm/providers/pinpoint/utils/index.d.ts +2 -0
- package/lib-esm/{utils/AppUtils.js → providers/pinpoint/utils/index.js} +2 -4
- package/lib-esm/providers/pinpoint/utils/resolveConfig.d.ts +7 -0
- package/lib-esm/providers/pinpoint/utils/resolveConfig.js +14 -0
- package/lib-esm/providers/pinpoint/utils/resolveCredentials.d.ts +12 -0
- package/lib-esm/providers/pinpoint/utils/resolveCredentials.js +20 -0
- package/lib-esm/setupTests.js +1 -0
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/{lib/types/Analytics.d.ts → lib-esm/types/analytics.d.ts} +0 -8
- package/lib-esm/types/index.d.ts +1 -3
- package/lib-esm/types/index.js +1 -3
- package/lib-esm/utils/{UserAgent.d.ts → userAgent.d.ts} +1 -1
- package/lib-esm/utils/{UserAgent.js → userAgent.js} +1 -1
- package/package.json +11 -29
- package/src/errors/AnalyticsError.ts +18 -0
- package/src/errors/assertValidationError.ts +19 -0
- package/src/errors/index.ts +6 -0
- package/src/errors/validation.ts +31 -0
- package/src/index.ts +0 -15
- package/src/providers/pinpoint/apis/identifyUser.ts +35 -0
- package/src/{utils/AppUtils.ts → providers/pinpoint/apis/index.ts} +2 -4
- package/src/providers/pinpoint/apis/record.ts +50 -0
- package/src/providers/pinpoint/index.ts +1 -3
- package/src/providers/pinpoint/types/errors.ts +12 -0
- package/src/providers/pinpoint/types/index.ts +5 -0
- package/src/providers/pinpoint/types/parameters.ts +24 -0
- package/src/providers/pinpoint/utils/index.ts +5 -0
- package/src/providers/pinpoint/utils/resolveConfig.ts +18 -0
- package/src/providers/pinpoint/utils/resolveCredentials.ts +20 -0
- package/src/types/{Analytics.ts → analytics.ts} +1 -10
- package/src/types/index.ts +1 -3
- package/src/utils/{UserAgent.ts → userAgent.ts} +1 -1
- package/lib/Analytics.d.ts +0 -87
- package/lib/Analytics.js +0 -354
- package/lib/providers/AWSKinesisFirehoseProvider.d.ts +0 -12
- package/lib/providers/AWSKinesisFirehoseProvider.js +0 -82
- package/lib/providers/AWSKinesisProvider.d.ts +0 -43
- package/lib/providers/AWSKinesisProvider.js +0 -240
- package/lib/providers/AWSPinpointProvider.d.ts +0 -67
- package/lib/providers/AWSPinpointProvider.js +0 -576
- package/lib/providers/AmazonPersonalizeHelper/DataType.d.ts +0 -40
- package/lib/providers/AmazonPersonalizeHelper/MediaAutoTrack.d.ts +0 -20
- package/lib/providers/AmazonPersonalizeHelper/MediaAutoTrack.js +0 -156
- package/lib/providers/AmazonPersonalizeHelper/SessionInfoManager.d.ts +0 -17
- package/lib/providers/AmazonPersonalizeHelper/SessionInfoManager.js +0 -96
- package/lib/providers/AmazonPersonalizeHelper/index.d.ts +0 -3
- package/lib/providers/AmazonPersonalizeHelper/index.js +0 -7
- package/lib/providers/AmazonPersonalizeProvider.d.ts +0 -76
- package/lib/providers/AmazonPersonalizeProvider.js +0 -331
- package/lib/providers/EventBuffer.d.ts +0 -28
- package/lib/providers/EventBuffer.js +0 -209
- package/lib/providers/index.d.ts +0 -4
- package/lib/providers/index.js +0 -14
- package/lib/trackers/EventTracker.d.ts +0 -9
- package/lib/trackers/EventTracker.js +0 -99
- package/lib/trackers/PageViewTracker.d.ts +0 -12
- package/lib/trackers/PageViewTracker.js +0 -158
- package/lib/trackers/SessionTracker-rn.d.ts +0 -12
- package/lib/trackers/SessionTracker-rn.js +0 -134
- package/lib/trackers/SessionTracker.d.ts +0 -14
- package/lib/trackers/SessionTracker.js +0 -163
- package/lib/trackers/index.d.ts +0 -3
- package/lib/trackers/index.js +0 -11
- package/lib/trackers/reactnative.d.ts +0 -8
- package/lib/trackers/reactnative.js +0 -19
- package/lib/types/Analytics.js +0 -2
- package/lib/types/Provider.d.ts +0 -10
- package/lib/types/providers/AWSKinesisProvider.d.ts +0 -6
- package/lib/types/providers/AWSKinesisProvider.js +0 -2
- package/lib/types/providers/AWSPinpointProvider.d.ts +0 -50
- package/lib/types/providers/AWSPinpointProvider.js +0 -2
- package/lib/types/providers/AmazonPersonalizeProvider.d.ts +0 -7
- package/lib/types/providers/AmazonPersonalizeProvider.js +0 -2
- package/lib/types/providers/index.d.ts +0 -1
- package/lib/types/providers/index.js +0 -6
- package/lib/utils/AppUtils.d.ts +0 -2
- package/lib/utils/AppUtils.js +0 -9
- package/lib/utils/AppUtils.native.d.ts +0 -2
- package/lib/utils/AppUtils.native.js +0 -10
- package/lib/utils/MethodEmbed.d.ts +0 -11
- package/lib/utils/MethodEmbed.js +0 -43
- package/lib/vendor/dom-utils/closest.d.ts +0 -12
- package/lib/vendor/dom-utils/closest.js +0 -27
- package/lib/vendor/dom-utils/delegate.d.ts +0 -18
- package/lib/vendor/dom-utils/delegate.js +0 -51
- package/lib/vendor/dom-utils/dispatch.d.ts +0 -17
- package/lib/vendor/dom-utils/dispatch.js +0 -51
- package/lib/vendor/dom-utils/get-attributes.d.ts +0 -11
- package/lib/vendor/dom-utils/get-attributes.js +0 -28
- package/lib/vendor/dom-utils/index.d.ts +0 -7
- package/lib/vendor/dom-utils/index.js +0 -17
- package/lib/vendor/dom-utils/matches.d.ts +0 -11
- package/lib/vendor/dom-utils/matches.js +0 -69
- package/lib/vendor/dom-utils/parents.d.ts +0 -10
- package/lib/vendor/dom-utils/parents.js +0 -22
- package/lib/vendor/dom-utils/parse-url.d.ts +0 -9
- package/lib/vendor/dom-utils/parse-url.js +0 -59
- package/lib-esm/Analytics.d.ts +0 -87
- package/lib-esm/Analytics.js +0 -351
- package/lib-esm/providers/AWSKinesisFirehoseProvider.d.ts +0 -12
- package/lib-esm/providers/AWSKinesisFirehoseProvider.js +0 -79
- package/lib-esm/providers/AWSKinesisProvider.d.ts +0 -43
- package/lib-esm/providers/AWSKinesisProvider.js +0 -237
- package/lib-esm/providers/AWSPinpointProvider.d.ts +0 -67
- package/lib-esm/providers/AWSPinpointProvider.js +0 -573
- package/lib-esm/providers/AmazonPersonalizeHelper/DataType.d.ts +0 -40
- package/lib-esm/providers/AmazonPersonalizeHelper/MediaAutoTrack.d.ts +0 -20
- package/lib-esm/providers/AmazonPersonalizeHelper/MediaAutoTrack.js +0 -153
- package/lib-esm/providers/AmazonPersonalizeHelper/SessionInfoManager.d.ts +0 -17
- package/lib-esm/providers/AmazonPersonalizeHelper/SessionInfoManager.js +0 -92
- package/lib-esm/providers/AmazonPersonalizeHelper/index.d.ts +0 -3
- package/lib-esm/providers/AmazonPersonalizeHelper/index.js +0 -2
- package/lib-esm/providers/AmazonPersonalizeProvider.d.ts +0 -76
- package/lib-esm/providers/AmazonPersonalizeProvider.js +0 -328
- package/lib-esm/providers/EventBuffer.d.ts +0 -28
- package/lib-esm/providers/EventBuffer.js +0 -207
- package/lib-esm/providers/index.d.ts +0 -4
- package/lib-esm/providers/index.js +0 -7
- package/lib-esm/trackers/EventTracker.d.ts +0 -9
- package/lib-esm/trackers/EventTracker.js +0 -96
- package/lib-esm/trackers/PageViewTracker.d.ts +0 -12
- package/lib-esm/trackers/PageViewTracker.js +0 -155
- package/lib-esm/trackers/SessionTracker-rn.d.ts +0 -12
- package/lib-esm/trackers/SessionTracker-rn.js +0 -131
- package/lib-esm/trackers/SessionTracker.d.ts +0 -14
- package/lib-esm/trackers/SessionTracker.js +0 -160
- package/lib-esm/trackers/index.d.ts +0 -3
- package/lib-esm/trackers/index.js +0 -5
- package/lib-esm/trackers/reactnative.d.ts +0 -8
- package/lib-esm/trackers/reactnative.js +0 -14
- package/lib-esm/types/Analytics.js +0 -1
- package/lib-esm/types/Provider.d.ts +0 -10
- package/lib-esm/types/providers/AWSKinesisProvider.d.ts +0 -6
- package/lib-esm/types/providers/AWSKinesisProvider.js +0 -1
- package/lib-esm/types/providers/AWSPinpointProvider.d.ts +0 -50
- package/lib-esm/types/providers/AWSPinpointProvider.js +0 -1
- package/lib-esm/types/providers/AmazonPersonalizeProvider.d.ts +0 -7
- package/lib-esm/types/providers/AmazonPersonalizeProvider.js +0 -1
- package/lib-esm/types/providers/index.d.ts +0 -1
- package/lib-esm/utils/AppUtils.d.ts +0 -2
- package/lib-esm/utils/AppUtils.native.d.ts +0 -2
- package/lib-esm/utils/AppUtils.native.js +0 -7
- package/lib-esm/utils/MethodEmbed.d.ts +0 -11
- package/lib-esm/utils/MethodEmbed.js +0 -40
- package/lib-esm/vendor/dom-utils/closest.d.ts +0 -12
- package/lib-esm/vendor/dom-utils/closest.js +0 -23
- package/lib-esm/vendor/dom-utils/delegate.d.ts +0 -18
- package/lib-esm/vendor/dom-utils/delegate.js +0 -47
- package/lib-esm/vendor/dom-utils/dispatch.d.ts +0 -17
- package/lib-esm/vendor/dom-utils/dispatch.js +0 -47
- package/lib-esm/vendor/dom-utils/get-attributes.d.ts +0 -11
- package/lib-esm/vendor/dom-utils/get-attributes.js +0 -24
- package/lib-esm/vendor/dom-utils/index.d.ts +0 -7
- package/lib-esm/vendor/dom-utils/index.js +0 -7
- package/lib-esm/vendor/dom-utils/matches.d.ts +0 -11
- package/lib-esm/vendor/dom-utils/matches.js +0 -65
- package/lib-esm/vendor/dom-utils/parents.d.ts +0 -10
- package/lib-esm/vendor/dom-utils/parents.js +0 -18
- package/lib-esm/vendor/dom-utils/parse-url.d.ts +0 -9
- package/lib-esm/vendor/dom-utils/parse-url.js +0 -55
- package/src/Analytics.ts +0 -446
- package/src/providers/AWSKinesisFirehoseProvider.ts +0 -105
- package/src/providers/AWSKinesisProvider.ts +0 -250
- package/src/providers/AWSPinpointProvider.ts +0 -685
- package/src/providers/AmazonPersonalizeHelper/DataType.ts +0 -49
- package/src/providers/AmazonPersonalizeHelper/MediaAutoTrack.ts +0 -196
- package/src/providers/AmazonPersonalizeHelper/SessionInfoManager.ts +0 -121
- package/src/providers/AmazonPersonalizeHelper/index.ts +0 -11
- package/src/providers/AmazonPersonalizeProvider.ts +0 -398
- package/src/providers/EventBuffer.ts +0 -257
- package/src/providers/index.ts +0 -8
- package/src/trackers/EventTracker.ts +0 -115
- package/src/trackers/PageViewTracker.ts +0 -157
- package/src/trackers/SessionTracker-rn.ts +0 -134
- package/src/trackers/SessionTracker.ts +0 -179
- package/src/trackers/index.ts +0 -5
- package/src/trackers/reactnative.ts +0 -13
- package/src/types/Provider.ts +0 -26
- package/src/types/providers/AWSKinesisProvider.ts +0 -8
- package/src/types/providers/AWSPinpointProvider.ts +0 -60
- package/src/types/providers/AmazonPersonalizeProvider.ts +0 -9
- package/src/utils/AppUtils.native.ts +0 -9
- package/src/utils/MethodEmbed.ts +0 -49
- package/src/vendor/dom-utils/closest.ts +0 -25
- package/src/vendor/dom-utils/delegate.ts +0 -51
- package/src/vendor/dom-utils/dispatch.ts +0 -59
- package/src/vendor/dom-utils/get-attributes.ts +0 -26
- package/src/vendor/dom-utils/index.ts +0 -7
- package/src/vendor/dom-utils/matches.ts +0 -68
- package/src/vendor/dom-utils/parents.ts +0 -19
- package/src/vendor/dom-utils/parse-url.ts +0 -66
- /package/lib/{types/Provider.js → providers/pinpoint/types/parameters.js} +0 -0
- /package/lib/{providers/AmazonPersonalizeHelper/DataType.js → types/analytics.js} +0 -0
- /package/lib-esm/{types/Provider.js → providers/pinpoint/types/parameters.js} +0 -0
- /package/lib-esm/{providers/AmazonPersonalizeHelper/DataType.js → types/analytics.js} +0 -0
|
@@ -1,576 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.AWSPinpointProvider = void 0;
|
|
6
|
-
var tslib_1 = require("tslib");
|
|
7
|
-
var core_1 = require("@aws-amplify/core");
|
|
8
|
-
var pinpoint_1 = require("@aws-amplify/core/internals/aws-clients/pinpoint");
|
|
9
|
-
var uuid_1 = require("uuid");
|
|
10
|
-
var UserAgent_1 = require("../utils/UserAgent");
|
|
11
|
-
var EventBuffer_1 = tslib_1.__importDefault(require("./EventBuffer"));
|
|
12
|
-
var AMPLIFY_SYMBOL = (typeof Symbol !== 'undefined' && typeof Symbol.for === 'function'
|
|
13
|
-
? Symbol.for('amplify_default')
|
|
14
|
-
: '@@amplify_default');
|
|
15
|
-
var dispatchAnalyticsEvent = function (event, data) {
|
|
16
|
-
core_1.Hub.dispatch('analytics', { event: event, data: data }, 'Analytics', AMPLIFY_SYMBOL);
|
|
17
|
-
};
|
|
18
|
-
var logger = new core_1.ConsoleLogger('AWSPinpointProvider');
|
|
19
|
-
var RETRYABLE_CODES = [429, 500];
|
|
20
|
-
var ACCEPTED_CODES = [202];
|
|
21
|
-
var FORBIDDEN_CODE = 403;
|
|
22
|
-
var MOBILE_SERVICE_NAME = 'mobiletargeting';
|
|
23
|
-
var EXPIRED_TOKEN_CODE = 'ExpiredTokenException';
|
|
24
|
-
var UPDATE_ENDPOINT = '_update_endpoint';
|
|
25
|
-
var SESSION_START = '_session.start';
|
|
26
|
-
var SESSION_STOP = '_session.stop';
|
|
27
|
-
var BEACON_SUPPORTED = typeof navigator !== 'undefined' &&
|
|
28
|
-
navigator &&
|
|
29
|
-
typeof navigator.sendBeacon === 'function';
|
|
30
|
-
// events buffer
|
|
31
|
-
var BUFFER_SIZE = 1000;
|
|
32
|
-
var FLUSH_SIZE = 100;
|
|
33
|
-
var FLUSH_INTERVAL = 5 * 1000; // 5s
|
|
34
|
-
var RESEND_LIMIT = 5;
|
|
35
|
-
// params: { event: {name: , .... }, timeStamp, config, resendLimits }
|
|
36
|
-
var AWSPinpointProvider = exports.AWSPinpointProvider = /** @class */ (function () {
|
|
37
|
-
function AWSPinpointProvider(config) {
|
|
38
|
-
this._endpointGenerating = true;
|
|
39
|
-
this._endpointUpdateInProgress = false;
|
|
40
|
-
this._buffer = null;
|
|
41
|
-
this._endpointBuffer = [];
|
|
42
|
-
this._config = config ? config : {};
|
|
43
|
-
this._config.bufferSize = this._config.bufferSize || BUFFER_SIZE;
|
|
44
|
-
this._config.flushSize = this._config.flushSize || FLUSH_SIZE;
|
|
45
|
-
this._config.flushInterval = this._config.flushInterval || FLUSH_INTERVAL;
|
|
46
|
-
this._config.resendLimit = this._config.resendLimit || RESEND_LIMIT;
|
|
47
|
-
this._clientInfo = core_1.ClientDevice.clientInfo();
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* get the category of the plugin
|
|
51
|
-
*/
|
|
52
|
-
AWSPinpointProvider.prototype.getCategory = function () {
|
|
53
|
-
return AWSPinpointProvider.category;
|
|
54
|
-
};
|
|
55
|
-
/**
|
|
56
|
-
* get provider name of the plugin
|
|
57
|
-
*/
|
|
58
|
-
AWSPinpointProvider.prototype.getProviderName = function () {
|
|
59
|
-
return AWSPinpointProvider.providerName;
|
|
60
|
-
};
|
|
61
|
-
/**
|
|
62
|
-
* configure the plugin
|
|
63
|
-
* @param {Object} config - configuration
|
|
64
|
-
*/
|
|
65
|
-
AWSPinpointProvider.prototype.configure = function (config) {
|
|
66
|
-
var _this = this;
|
|
67
|
-
logger.debug('configure Analytics', config);
|
|
68
|
-
var conf = config || {};
|
|
69
|
-
this._config = Object.assign({}, this._config, conf);
|
|
70
|
-
// If autoSessionRecord is enabled, we need to wait for the endpoint to be
|
|
71
|
-
// updated before sending any events. See `sendEvents` in `Analytics.ts`
|
|
72
|
-
this._endpointGenerating = !!config['autoSessionRecord'];
|
|
73
|
-
if (this._config.appId && !this._config.disabled) {
|
|
74
|
-
if (!this._config.endpointId) {
|
|
75
|
-
var cacheKey = this.getProviderName() + '_' + this._config.appId;
|
|
76
|
-
this._getEndpointId(cacheKey)
|
|
77
|
-
.then(function (endpointId) {
|
|
78
|
-
logger.debug('setting endpoint id from the cache', endpointId);
|
|
79
|
-
_this._config.endpointId = endpointId;
|
|
80
|
-
dispatchAnalyticsEvent('pinpointProvider_configured', null);
|
|
81
|
-
})
|
|
82
|
-
.catch(function (err) {
|
|
83
|
-
logger.debug('Failed to generate endpointId', err);
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
dispatchAnalyticsEvent('pinpointProvider_configured', null);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
this._flushBuffer();
|
|
92
|
-
}
|
|
93
|
-
return this._config;
|
|
94
|
-
};
|
|
95
|
-
/**
|
|
96
|
-
* record an event
|
|
97
|
-
* @param {Object} params - the params of an event
|
|
98
|
-
*/
|
|
99
|
-
AWSPinpointProvider.prototype.record = function (params, handlers) {
|
|
100
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
101
|
-
var credentials, timestamp;
|
|
102
|
-
return tslib_1.__generator(this, function (_a) {
|
|
103
|
-
switch (_a.label) {
|
|
104
|
-
case 0:
|
|
105
|
-
logger.debug('_public record', params);
|
|
106
|
-
return [4 /*yield*/, this._getCredentials()];
|
|
107
|
-
case 1:
|
|
108
|
-
credentials = _a.sent();
|
|
109
|
-
if (!credentials || !this._config.appId || !this._config.region) {
|
|
110
|
-
logger.debug('cannot send events without credentials, applicationId or region');
|
|
111
|
-
return [2 /*return*/, handlers.reject(new Error('No credentials, applicationId or region'))];
|
|
112
|
-
}
|
|
113
|
-
this._init(credentials);
|
|
114
|
-
timestamp = new Date().getTime();
|
|
115
|
-
// attach the session and eventId
|
|
116
|
-
this._generateSession(params);
|
|
117
|
-
params.event.eventId = (0, uuid_1.v1)();
|
|
118
|
-
Object.assign(params, { timestamp: timestamp, config: this._config });
|
|
119
|
-
if (params.event.immediate) {
|
|
120
|
-
return [2 /*return*/, this._send(params, handlers)];
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
this._putToBuffer(params, handlers);
|
|
124
|
-
}
|
|
125
|
-
return [2 /*return*/];
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
};
|
|
130
|
-
AWSPinpointProvider.prototype._sendEndpointUpdate = function (endpointObject) {
|
|
131
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
132
|
-
var next;
|
|
133
|
-
return tslib_1.__generator(this, function (_a) {
|
|
134
|
-
switch (_a.label) {
|
|
135
|
-
case 0:
|
|
136
|
-
if (this._endpointUpdateInProgress) {
|
|
137
|
-
this._endpointBuffer.push(endpointObject);
|
|
138
|
-
return [2 /*return*/];
|
|
139
|
-
}
|
|
140
|
-
this._endpointUpdateInProgress = true;
|
|
141
|
-
return [4 /*yield*/, this._updateEndpoint(endpointObject)];
|
|
142
|
-
case 1:
|
|
143
|
-
_a.sent();
|
|
144
|
-
next = this._endpointBuffer.shift();
|
|
145
|
-
this._endpointUpdateInProgress = false;
|
|
146
|
-
next && this._sendEndpointUpdate(next);
|
|
147
|
-
return [2 /*return*/];
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
};
|
|
152
|
-
/**
|
|
153
|
-
* @private
|
|
154
|
-
* @param params - params for event recording
|
|
155
|
-
* Put events into buffer
|
|
156
|
-
*/
|
|
157
|
-
AWSPinpointProvider.prototype._putToBuffer = function (params, handlers) {
|
|
158
|
-
var _a;
|
|
159
|
-
if (params.event.name === UPDATE_ENDPOINT) {
|
|
160
|
-
this._sendEndpointUpdate({ params: params, handlers: handlers });
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
(_a = this._buffer) === null || _a === void 0 ? void 0 : _a.push({ params: params, handlers: handlers });
|
|
164
|
-
};
|
|
165
|
-
AWSPinpointProvider.prototype._generateSession = function (params) {
|
|
166
|
-
this._sessionId = this._sessionId || (0, uuid_1.v1)();
|
|
167
|
-
var event = params.event;
|
|
168
|
-
switch (event.name) {
|
|
169
|
-
case SESSION_START:
|
|
170
|
-
// refresh the session id and session start time
|
|
171
|
-
this._sessionStartTimestamp = new Date().getTime();
|
|
172
|
-
this._sessionId = (0, uuid_1.v1)();
|
|
173
|
-
event.session = {
|
|
174
|
-
Id: this._sessionId,
|
|
175
|
-
StartTimestamp: new Date(this._sessionStartTimestamp).toISOString(),
|
|
176
|
-
};
|
|
177
|
-
break;
|
|
178
|
-
case SESSION_STOP:
|
|
179
|
-
var stopTimestamp = new Date().getTime();
|
|
180
|
-
this._sessionStartTimestamp =
|
|
181
|
-
this._sessionStartTimestamp || new Date().getTime();
|
|
182
|
-
this._sessionId = this._sessionId || (0, uuid_1.v1)();
|
|
183
|
-
event.session = {
|
|
184
|
-
Id: this._sessionId,
|
|
185
|
-
Duration: stopTimestamp - this._sessionStartTimestamp,
|
|
186
|
-
StartTimestamp: new Date(this._sessionStartTimestamp).toISOString(),
|
|
187
|
-
StopTimestamp: new Date(stopTimestamp).toISOString(),
|
|
188
|
-
};
|
|
189
|
-
this._sessionId = undefined;
|
|
190
|
-
this._sessionStartTimestamp = undefined;
|
|
191
|
-
break;
|
|
192
|
-
default:
|
|
193
|
-
this._sessionStartTimestamp =
|
|
194
|
-
this._sessionStartTimestamp || new Date().getTime();
|
|
195
|
-
this._sessionId = this._sessionId || (0, uuid_1.v1)();
|
|
196
|
-
event.session = {
|
|
197
|
-
Id: this._sessionId,
|
|
198
|
-
StartTimestamp: new Date(this._sessionStartTimestamp).toISOString(),
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
AWSPinpointProvider.prototype._send = function (params, handlers) {
|
|
203
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
204
|
-
var event;
|
|
205
|
-
return tslib_1.__generator(this, function (_a) {
|
|
206
|
-
event = params.event;
|
|
207
|
-
switch (event.name) {
|
|
208
|
-
case UPDATE_ENDPOINT:
|
|
209
|
-
return [2 /*return*/, this._updateEndpoint({ params: params, handlers: handlers })];
|
|
210
|
-
case SESSION_STOP:
|
|
211
|
-
return [2 /*return*/, this._pinpointSendStopSession(params, handlers)];
|
|
212
|
-
default:
|
|
213
|
-
return [2 /*return*/, this._pinpointPutEvents(params, handlers)];
|
|
214
|
-
}
|
|
215
|
-
return [2 /*return*/];
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
};
|
|
219
|
-
AWSPinpointProvider.prototype._generateBatchItemContext = function (params) {
|
|
220
|
-
var _a, _b;
|
|
221
|
-
var event = params.event, timestamp = params.timestamp, config = params.config;
|
|
222
|
-
var name = event.name, attributes = event.attributes, metrics = event.metrics, eventId = event.eventId, session = event.session;
|
|
223
|
-
var appId = config.appId, endpointId = config.endpointId;
|
|
224
|
-
var endpointContext = {};
|
|
225
|
-
return {
|
|
226
|
-
ApplicationId: appId,
|
|
227
|
-
EventsRequest: {
|
|
228
|
-
BatchItem: (_a = {},
|
|
229
|
-
_a[endpointId] = {
|
|
230
|
-
Endpoint: endpointContext,
|
|
231
|
-
Events: (_b = {},
|
|
232
|
-
_b[eventId] = {
|
|
233
|
-
EventType: name,
|
|
234
|
-
Timestamp: new Date(timestamp).toISOString(),
|
|
235
|
-
Attributes: attributes,
|
|
236
|
-
Metrics: metrics,
|
|
237
|
-
Session: session,
|
|
238
|
-
},
|
|
239
|
-
_b),
|
|
240
|
-
},
|
|
241
|
-
_a),
|
|
242
|
-
},
|
|
243
|
-
};
|
|
244
|
-
};
|
|
245
|
-
AWSPinpointProvider.prototype._pinpointPutEvents = function (params, handlers) {
|
|
246
|
-
var _a, _b, _c, _d, _e;
|
|
247
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
248
|
-
var eventId, endpointId, eventParams, credentials, region, data, StatusCode, Message, err_1;
|
|
249
|
-
var _f, _g;
|
|
250
|
-
return tslib_1.__generator(this, function (_h) {
|
|
251
|
-
switch (_h.label) {
|
|
252
|
-
case 0:
|
|
253
|
-
eventId = params.event.eventId, endpointId = params.config.endpointId;
|
|
254
|
-
eventParams = this._generateBatchItemContext(params);
|
|
255
|
-
_h.label = 1;
|
|
256
|
-
case 1:
|
|
257
|
-
_h.trys.push([1, 3, , 4]);
|
|
258
|
-
credentials = (_f = this._config, _f.credentials), region = _f.region;
|
|
259
|
-
return [4 /*yield*/, (0, pinpoint_1.putEvents)({
|
|
260
|
-
credentials: credentials,
|
|
261
|
-
region: region,
|
|
262
|
-
userAgentValue: (0, UserAgent_1.getAnalyticsUserAgentString)(core_1.AnalyticsAction.Record),
|
|
263
|
-
}, eventParams)];
|
|
264
|
-
case 2:
|
|
265
|
-
data = _h.sent();
|
|
266
|
-
StatusCode = (_g = (_e = (_d = (_c = (_b = (_a = data.EventsResponse) === null || _a === void 0 ? void 0 : _a.Results) === null || _b === void 0 ? void 0 : _b[endpointId]) === null || _c === void 0 ? void 0 : _c.EventsItemResponse) === null || _d === void 0 ? void 0 : _d[eventId]) !== null && _e !== void 0 ? _e : {}, _g.StatusCode), Message = _g.Message;
|
|
267
|
-
if (StatusCode && ACCEPTED_CODES.includes(StatusCode)) {
|
|
268
|
-
logger.debug('record event success. ', data);
|
|
269
|
-
return [2 /*return*/, handlers.resolve(data)];
|
|
270
|
-
}
|
|
271
|
-
else if (StatusCode && RETRYABLE_CODES.includes(StatusCode)) {
|
|
272
|
-
// TODO: v6 integrate retry to the service handler retryDecider
|
|
273
|
-
this._retry(params, handlers);
|
|
274
|
-
}
|
|
275
|
-
else {
|
|
276
|
-
logger.error("Event ".concat(eventId, " is not accepted, the error is ").concat(Message));
|
|
277
|
-
return [2 /*return*/, handlers.reject(data)];
|
|
278
|
-
}
|
|
279
|
-
return [3 /*break*/, 4];
|
|
280
|
-
case 3:
|
|
281
|
-
err_1 = _h.sent();
|
|
282
|
-
this._eventError(err_1);
|
|
283
|
-
return [2 /*return*/, handlers.reject(err_1)];
|
|
284
|
-
case 4: return [2 /*return*/];
|
|
285
|
-
}
|
|
286
|
-
});
|
|
287
|
-
});
|
|
288
|
-
};
|
|
289
|
-
AWSPinpointProvider.prototype._pinpointSendStopSession = function (params, handlers) {
|
|
290
|
-
if (!BEACON_SUPPORTED) {
|
|
291
|
-
this._pinpointPutEvents(params, handlers);
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
var eventParams = this._generateBatchItemContext(params);
|
|
295
|
-
var region = this._config.region;
|
|
296
|
-
var ApplicationId = eventParams.ApplicationId, EventsRequest = eventParams.EventsRequest;
|
|
297
|
-
var accessInfo = {
|
|
298
|
-
secret_key: this._config.credentials.secretAccessKey,
|
|
299
|
-
access_key: this._config.credentials.accessKeyId,
|
|
300
|
-
session_token: this._config.credentials.sessionToken,
|
|
301
|
-
};
|
|
302
|
-
var url = "https://pinpoint.".concat(region, ".amazonaws.com/v1/apps/").concat(ApplicationId, "/events/legacy");
|
|
303
|
-
var body = JSON.stringify(EventsRequest);
|
|
304
|
-
var method = 'POST';
|
|
305
|
-
var request = {
|
|
306
|
-
url: url,
|
|
307
|
-
body: body,
|
|
308
|
-
method: method,
|
|
309
|
-
};
|
|
310
|
-
var serviceInfo = { region: region, service: MOBILE_SERVICE_NAME };
|
|
311
|
-
var requestUrl = core_1.Signer.signUrl(request, accessInfo, serviceInfo);
|
|
312
|
-
var success = navigator.sendBeacon(requestUrl, body);
|
|
313
|
-
if (success) {
|
|
314
|
-
return handlers.resolve('sendBeacon success');
|
|
315
|
-
}
|
|
316
|
-
return handlers.reject('sendBeacon failure');
|
|
317
|
-
};
|
|
318
|
-
AWSPinpointProvider.prototype._retry = function (params, handlers) {
|
|
319
|
-
var resendLimit = params.config.resendLimit;
|
|
320
|
-
// For backward compatibility
|
|
321
|
-
params.resendLimit =
|
|
322
|
-
typeof params.resendLimit === 'number' ? params.resendLimit : resendLimit;
|
|
323
|
-
if (params.resendLimit-- > 0) {
|
|
324
|
-
logger.debug("resending event ".concat(params.eventName, " with ").concat(params.resendLimit, " retry times left"));
|
|
325
|
-
this._pinpointPutEvents(params, handlers);
|
|
326
|
-
}
|
|
327
|
-
else {
|
|
328
|
-
logger.debug("retry times used up for event ".concat(params.eventName));
|
|
329
|
-
}
|
|
330
|
-
};
|
|
331
|
-
AWSPinpointProvider.prototype._updateEndpoint = function (endpointObject) {
|
|
332
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
333
|
-
var params, handlers, config, event, appId, endpointId, request, update_params, credentials, region, data, err_2, failureData;
|
|
334
|
-
var _a;
|
|
335
|
-
return tslib_1.__generator(this, function (_b) {
|
|
336
|
-
switch (_b.label) {
|
|
337
|
-
case 0:
|
|
338
|
-
params = endpointObject.params, handlers = endpointObject.handlers;
|
|
339
|
-
config = params.config, event = params.event;
|
|
340
|
-
appId = config.appId, endpointId = config.endpointId;
|
|
341
|
-
request = this._endpointRequest(config, (0, core_1.transferKeyToLowerCase)(event, [], ['attributes', 'userAttributes', 'Attributes', 'UserAttributes']));
|
|
342
|
-
update_params = {
|
|
343
|
-
ApplicationId: appId,
|
|
344
|
-
EndpointId: endpointId,
|
|
345
|
-
EndpointRequest: request,
|
|
346
|
-
};
|
|
347
|
-
_b.label = 1;
|
|
348
|
-
case 1:
|
|
349
|
-
_b.trys.push([1, 3, , 4]);
|
|
350
|
-
credentials = (_a = this._config, _a.credentials), region = _a.region;
|
|
351
|
-
return [4 /*yield*/, (0, pinpoint_1.updateEndpoint)({
|
|
352
|
-
credentials: credentials,
|
|
353
|
-
region: region,
|
|
354
|
-
userAgentValue: (0, UserAgent_1.getAnalyticsUserAgentString)(core_1.AnalyticsAction.UpdateEndpoint),
|
|
355
|
-
}, update_params)];
|
|
356
|
-
case 2:
|
|
357
|
-
data = _b.sent();
|
|
358
|
-
logger.debug('updateEndpoint success', data);
|
|
359
|
-
this._endpointGenerating = false;
|
|
360
|
-
this._resumeBuffer();
|
|
361
|
-
handlers.resolve(data);
|
|
362
|
-
return [2 /*return*/];
|
|
363
|
-
case 3:
|
|
364
|
-
err_2 = _b.sent();
|
|
365
|
-
failureData = {
|
|
366
|
-
err: err_2,
|
|
367
|
-
update_params: update_params,
|
|
368
|
-
endpointObject: endpointObject,
|
|
369
|
-
};
|
|
370
|
-
return [2 /*return*/, this._handleEndpointUpdateFailure(failureData)];
|
|
371
|
-
case 4: return [2 /*return*/];
|
|
372
|
-
}
|
|
373
|
-
});
|
|
374
|
-
});
|
|
375
|
-
};
|
|
376
|
-
AWSPinpointProvider.prototype._handleEndpointUpdateFailure = function (failureData) {
|
|
377
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
378
|
-
var err, endpointObject, statusCode, exponential;
|
|
379
|
-
return tslib_1.__generator(this, function (_a) {
|
|
380
|
-
err = failureData.err, endpointObject = failureData.endpointObject;
|
|
381
|
-
statusCode = err.$metadata && err.$metadata.httpStatusCode;
|
|
382
|
-
logger.debug('updateEndpoint error', err);
|
|
383
|
-
switch (statusCode) {
|
|
384
|
-
case FORBIDDEN_CODE:
|
|
385
|
-
return [2 /*return*/, this._handleEndpointUpdateForbidden(failureData)];
|
|
386
|
-
default:
|
|
387
|
-
if (RETRYABLE_CODES.includes(statusCode)) {
|
|
388
|
-
exponential = true;
|
|
389
|
-
return [2 /*return*/, this._retryEndpointUpdate(endpointObject, exponential)];
|
|
390
|
-
}
|
|
391
|
-
logger.error('updateEndpoint failed', err);
|
|
392
|
-
endpointObject.handlers.reject(err);
|
|
393
|
-
}
|
|
394
|
-
return [2 /*return*/];
|
|
395
|
-
});
|
|
396
|
-
});
|
|
397
|
-
};
|
|
398
|
-
AWSPinpointProvider.prototype._handleEndpointUpdateForbidden = function (failureData) {
|
|
399
|
-
var err = failureData.err, endpointObject = failureData.endpointObject;
|
|
400
|
-
var code = err.code, retryable = err.retryable;
|
|
401
|
-
if (code !== EXPIRED_TOKEN_CODE && !retryable) {
|
|
402
|
-
return endpointObject.handlers.reject(err);
|
|
403
|
-
}
|
|
404
|
-
this._retryEndpointUpdate(endpointObject);
|
|
405
|
-
};
|
|
406
|
-
AWSPinpointProvider.prototype._retryEndpointUpdate = function (endpointObject, exponential) {
|
|
407
|
-
if (exponential === void 0) { exponential = false; }
|
|
408
|
-
logger.debug('_retryEndpointUpdate', endpointObject);
|
|
409
|
-
var params = endpointObject.params;
|
|
410
|
-
// TODO: implement retry with exp back off once exp function is available
|
|
411
|
-
var resendLimit = params.config.resendLimit;
|
|
412
|
-
params.resendLimit =
|
|
413
|
-
typeof params.resendLimit === 'number' ? params.resendLimit : resendLimit;
|
|
414
|
-
if (params.resendLimit-- > 0) {
|
|
415
|
-
logger.debug("resending endpoint update ".concat(params.event.eventId, " with ").concat(params.resendLimit, " retry attempts remaining"));
|
|
416
|
-
// insert at the front of endpointBuffer
|
|
417
|
-
this._endpointBuffer.length
|
|
418
|
-
? this._endpointBuffer.unshift(endpointObject)
|
|
419
|
-
: this._updateEndpoint(endpointObject);
|
|
420
|
-
return;
|
|
421
|
-
}
|
|
422
|
-
logger.warn("resending endpoint update ".concat(params.event.eventId, " failed after ").concat(params.config.resendLimit, " attempts"));
|
|
423
|
-
if (this._endpointGenerating) {
|
|
424
|
-
logger.error('Initial endpoint update failed. ');
|
|
425
|
-
}
|
|
426
|
-
};
|
|
427
|
-
/**
|
|
428
|
-
* @private
|
|
429
|
-
* @param config
|
|
430
|
-
* Configure credentials and init buffer
|
|
431
|
-
*/
|
|
432
|
-
AWSPinpointProvider.prototype._init = function (credentials) {
|
|
433
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
434
|
-
var identityId;
|
|
435
|
-
return tslib_1.__generator(this, function (_a) {
|
|
436
|
-
logger.debug('init provider');
|
|
437
|
-
if (this._config.credentials &&
|
|
438
|
-
this._config.credentials.sessionToken === credentials.sessionToken &&
|
|
439
|
-
this._config.credentials.identityId === credentials.identityId) {
|
|
440
|
-
logger.debug('no change for aws credentials, directly return from init');
|
|
441
|
-
return [2 /*return*/];
|
|
442
|
-
}
|
|
443
|
-
identityId = this._config.credentials
|
|
444
|
-
? this._config.credentials.identityId
|
|
445
|
-
: null;
|
|
446
|
-
this._config.credentials = credentials;
|
|
447
|
-
if (!this._bufferExists() || identityId !== credentials.identityId) {
|
|
448
|
-
// if the identity has changed, flush the buffer and instantiate a new one
|
|
449
|
-
// this will cause the old buffer to send any remaining events
|
|
450
|
-
// with the old credentials and then stop looping and shortly thereafter get picked up by GC
|
|
451
|
-
this._initBuffer();
|
|
452
|
-
}
|
|
453
|
-
return [2 /*return*/];
|
|
454
|
-
});
|
|
455
|
-
});
|
|
456
|
-
};
|
|
457
|
-
AWSPinpointProvider.prototype._bufferExists = function () {
|
|
458
|
-
return this._buffer && this._buffer instanceof EventBuffer_1.default;
|
|
459
|
-
};
|
|
460
|
-
AWSPinpointProvider.prototype._initBuffer = function () {
|
|
461
|
-
if (this._bufferExists()) {
|
|
462
|
-
this._flushBuffer();
|
|
463
|
-
}
|
|
464
|
-
this._buffer = new EventBuffer_1.default(this._config);
|
|
465
|
-
// if the first endpoint update hasn't yet resolved pause the buffer to
|
|
466
|
-
// prevent race conditions. It will be resumed as soon as that request succeeds
|
|
467
|
-
if (this._endpointGenerating) {
|
|
468
|
-
this._buffer.pause();
|
|
469
|
-
}
|
|
470
|
-
};
|
|
471
|
-
AWSPinpointProvider.prototype._flushBuffer = function () {
|
|
472
|
-
var _a;
|
|
473
|
-
if (this._bufferExists()) {
|
|
474
|
-
(_a = this._buffer) === null || _a === void 0 ? void 0 : _a.flush();
|
|
475
|
-
this._buffer = null;
|
|
476
|
-
}
|
|
477
|
-
};
|
|
478
|
-
AWSPinpointProvider.prototype._resumeBuffer = function () {
|
|
479
|
-
var _a;
|
|
480
|
-
if (this._bufferExists()) {
|
|
481
|
-
(_a = this._buffer) === null || _a === void 0 ? void 0 : _a.resume();
|
|
482
|
-
}
|
|
483
|
-
};
|
|
484
|
-
AWSPinpointProvider.prototype._getEndpointId = function (cacheKey) {
|
|
485
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
486
|
-
var endpointId, ttl, expiration;
|
|
487
|
-
return tslib_1.__generator(this, function (_a) {
|
|
488
|
-
switch (_a.label) {
|
|
489
|
-
case 0: return [4 /*yield*/, core_1.Cache.getItem(cacheKey)];
|
|
490
|
-
case 1:
|
|
491
|
-
endpointId = _a.sent();
|
|
492
|
-
logger.debug('endpointId from cache', endpointId, 'type', typeof endpointId);
|
|
493
|
-
if (!endpointId) {
|
|
494
|
-
endpointId = (0, uuid_1.v1)();
|
|
495
|
-
ttl = 1000 * 60 * 60 * 24 * 365 * 100;
|
|
496
|
-
expiration = new Date().getTime() + ttl;
|
|
497
|
-
core_1.Cache.setItem(cacheKey, endpointId, {
|
|
498
|
-
expires: expiration,
|
|
499
|
-
priority: 1,
|
|
500
|
-
});
|
|
501
|
-
}
|
|
502
|
-
return [2 /*return*/, endpointId];
|
|
503
|
-
}
|
|
504
|
-
});
|
|
505
|
-
});
|
|
506
|
-
};
|
|
507
|
-
/**
|
|
508
|
-
* EndPoint request
|
|
509
|
-
* @return {Object} - The request of updating endpoint
|
|
510
|
-
*/
|
|
511
|
-
AWSPinpointProvider.prototype._endpointRequest = function (config, event) {
|
|
512
|
-
var credentials = config.credentials;
|
|
513
|
-
var clientInfo = this._clientInfo || {};
|
|
514
|
-
var clientContext = config.clientContext || {};
|
|
515
|
-
// for now we have three different ways for default endpoint configurations
|
|
516
|
-
// clientInfo
|
|
517
|
-
// clientContext (deprecated)
|
|
518
|
-
// config.endpoint
|
|
519
|
-
var defaultEndpointConfig = config.endpoint || {};
|
|
520
|
-
var demographicByClientInfo = {
|
|
521
|
-
appVersion: clientInfo.appVersion,
|
|
522
|
-
make: clientInfo.make,
|
|
523
|
-
model: clientInfo.model,
|
|
524
|
-
modelVersion: clientInfo.version,
|
|
525
|
-
platform: clientInfo.platform,
|
|
526
|
-
};
|
|
527
|
-
// for backward compatibility
|
|
528
|
-
var clientId = clientContext.clientId, appTitle = clientContext.appTitle, appVersionName = clientContext.appVersionName, appVersionCode = clientContext.appVersionCode, appPackageName = clientContext.appPackageName, demographicByClientContext = tslib_1.__rest(clientContext, ["clientId", "appTitle", "appVersionName", "appVersionCode", "appPackageName"]);
|
|
529
|
-
var channelType = event.address
|
|
530
|
-
? clientInfo.platform === 'android'
|
|
531
|
-
? 'GCM'
|
|
532
|
-
: 'APNS'
|
|
533
|
-
: undefined;
|
|
534
|
-
var tmp = tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({ channelType: channelType, requestId: (0, uuid_1.v1)(), effectiveDate: new Date().toISOString() }, defaultEndpointConfig), event), { attributes: tslib_1.__assign(tslib_1.__assign({}, defaultEndpointConfig.attributes), event.attributes), demographic: tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, demographicByClientInfo), demographicByClientContext), defaultEndpointConfig.demographic), event.demographic), location: tslib_1.__assign(tslib_1.__assign({}, defaultEndpointConfig.location), event.location), metrics: tslib_1.__assign(tslib_1.__assign({}, defaultEndpointConfig.metrics), event.metrics), user: {
|
|
535
|
-
userId: event.userId ||
|
|
536
|
-
defaultEndpointConfig.userId ||
|
|
537
|
-
credentials.identityId,
|
|
538
|
-
userAttributes: tslib_1.__assign(tslib_1.__assign({}, defaultEndpointConfig.userAttributes), event.userAttributes),
|
|
539
|
-
} });
|
|
540
|
-
// eliminate unnecessary params
|
|
541
|
-
var userId = tmp.userId, userAttributes = tmp.userAttributes, name = tmp.name, session = tmp.session, eventId = tmp.eventId, immediate = tmp.immediate, ret = tslib_1.__rest(tmp, ["userId", "userAttributes", "name", "session", "eventId", "immediate"]);
|
|
542
|
-
return (0, core_1.transferKeyToUpperCase)(ret, [], ['metrics', 'userAttributes', 'attributes']);
|
|
543
|
-
};
|
|
544
|
-
AWSPinpointProvider.prototype._eventError = function (err) {
|
|
545
|
-
logger.error('record event failed.', err);
|
|
546
|
-
logger.warn("Please ensure you have updated your Pinpoint IAM Policy " +
|
|
547
|
-
"with the Action: \"mobiletargeting:PutEvents\" " +
|
|
548
|
-
"in order to record events");
|
|
549
|
-
};
|
|
550
|
-
AWSPinpointProvider.prototype._getCredentials = function () {
|
|
551
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
552
|
-
var credentials, err_3;
|
|
553
|
-
return tslib_1.__generator(this, function (_a) {
|
|
554
|
-
switch (_a.label) {
|
|
555
|
-
case 0:
|
|
556
|
-
_a.trys.push([0, 2, , 3]);
|
|
557
|
-
return [4 /*yield*/, core_1.Credentials.get()];
|
|
558
|
-
case 1:
|
|
559
|
-
credentials = _a.sent();
|
|
560
|
-
if (!credentials)
|
|
561
|
-
return [2 /*return*/, null];
|
|
562
|
-
logger.debug('set credentials for analytics', credentials);
|
|
563
|
-
return [2 /*return*/, core_1.Credentials.shear(credentials)];
|
|
564
|
-
case 2:
|
|
565
|
-
err_3 = _a.sent();
|
|
566
|
-
logger.debug('ensure credentials error', err_3);
|
|
567
|
-
return [2 /*return*/, null];
|
|
568
|
-
case 3: return [2 /*return*/];
|
|
569
|
-
}
|
|
570
|
-
});
|
|
571
|
-
});
|
|
572
|
-
};
|
|
573
|
-
AWSPinpointProvider.category = 'Analytics';
|
|
574
|
-
AWSPinpointProvider.providerName = 'AWSPinpoint';
|
|
575
|
-
return AWSPinpointProvider;
|
|
576
|
-
}());
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { ICredentials } from '@aws-amplify/core';
|
|
2
|
-
interface BasePayload {
|
|
3
|
-
userId: string;
|
|
4
|
-
trackingId: string;
|
|
5
|
-
sessionId: string;
|
|
6
|
-
}
|
|
7
|
-
type Config = {
|
|
8
|
-
[key: string]: string | number;
|
|
9
|
-
};
|
|
10
|
-
type Properties = {
|
|
11
|
-
[key: string]: any;
|
|
12
|
-
};
|
|
13
|
-
export interface RequestParams {
|
|
14
|
-
eventData: EventData;
|
|
15
|
-
sessionInfo: SessionInfo;
|
|
16
|
-
config: Config;
|
|
17
|
-
sentAt: number;
|
|
18
|
-
credentials: ICredentials;
|
|
19
|
-
}
|
|
20
|
-
export interface EventData {
|
|
21
|
-
eventType: string;
|
|
22
|
-
properties: Properties;
|
|
23
|
-
}
|
|
24
|
-
export interface SessionInfo {
|
|
25
|
-
userId: string;
|
|
26
|
-
trackingId: string;
|
|
27
|
-
sessionId: string;
|
|
28
|
-
}
|
|
29
|
-
export interface RecordEventPayload {
|
|
30
|
-
eventId: string;
|
|
31
|
-
eventType: string;
|
|
32
|
-
sentAt: number;
|
|
33
|
-
properties?: string;
|
|
34
|
-
}
|
|
35
|
-
export interface RecordEventListPayload extends BasePayload {
|
|
36
|
-
eventList: RecordEventPayload[];
|
|
37
|
-
config?: Config;
|
|
38
|
-
credentials?: ICredentials;
|
|
39
|
-
}
|
|
40
|
-
export {};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { RequestParams } from './DataType';
|
|
2
|
-
export declare class MediaAutoTrack {
|
|
3
|
-
private _mediaElement;
|
|
4
|
-
private _provider;
|
|
5
|
-
private _params;
|
|
6
|
-
private _started;
|
|
7
|
-
private _iframePlayer;
|
|
8
|
-
private eventActionMapping;
|
|
9
|
-
private _youTubeIframeLoader;
|
|
10
|
-
constructor(params: RequestParams, provider: any);
|
|
11
|
-
private _initYoutubeFrame;
|
|
12
|
-
private _iframeMediaTracker;
|
|
13
|
-
private _onPlayerStateChange;
|
|
14
|
-
private _html5MediaTracker;
|
|
15
|
-
private playEventAction;
|
|
16
|
-
private pauseEventAction;
|
|
17
|
-
private endedEventAction;
|
|
18
|
-
private recordEvent;
|
|
19
|
-
private _financial;
|
|
20
|
-
}
|