@aws-amplify/analytics 7.0.1-console-preview.f63250a.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,685 +0,0 @@
|
|
|
1
|
-
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
ConsoleLogger as Logger,
|
|
6
|
-
ClientDevice,
|
|
7
|
-
Credentials,
|
|
8
|
-
Signer,
|
|
9
|
-
Hub,
|
|
10
|
-
transferKeyToLowerCase,
|
|
11
|
-
transferKeyToUpperCase,
|
|
12
|
-
AnalyticsAction,
|
|
13
|
-
Cache,
|
|
14
|
-
} from '@aws-amplify/core';
|
|
15
|
-
import {
|
|
16
|
-
putEvents,
|
|
17
|
-
PutEventsInput,
|
|
18
|
-
PutEventsOutput,
|
|
19
|
-
updateEndpoint,
|
|
20
|
-
UpdateEndpointInput,
|
|
21
|
-
UpdateEndpointOutput,
|
|
22
|
-
} from '@aws-amplify/core/internals/aws-clients/pinpoint';
|
|
23
|
-
|
|
24
|
-
import {
|
|
25
|
-
AnalyticsProvider,
|
|
26
|
-
PromiseHandlers,
|
|
27
|
-
EndpointBuffer,
|
|
28
|
-
EventParams,
|
|
29
|
-
EventObject,
|
|
30
|
-
EndpointFailureData,
|
|
31
|
-
} from '../types';
|
|
32
|
-
import { v1 as uuid } from 'uuid';
|
|
33
|
-
import { getAnalyticsUserAgentString } from '../utils/UserAgent';
|
|
34
|
-
import EventBuffer from './EventBuffer';
|
|
35
|
-
|
|
36
|
-
const AMPLIFY_SYMBOL = (
|
|
37
|
-
typeof Symbol !== 'undefined' && typeof Symbol.for === 'function'
|
|
38
|
-
? Symbol.for('amplify_default')
|
|
39
|
-
: '@@amplify_default'
|
|
40
|
-
) as Symbol;
|
|
41
|
-
|
|
42
|
-
const dispatchAnalyticsEvent = (event, data) => {
|
|
43
|
-
Hub.dispatch('analytics', { event, data }, 'Analytics', AMPLIFY_SYMBOL);
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const logger = new Logger('AWSPinpointProvider');
|
|
47
|
-
const RETRYABLE_CODES = [429, 500];
|
|
48
|
-
const ACCEPTED_CODES = [202];
|
|
49
|
-
const FORBIDDEN_CODE = 403;
|
|
50
|
-
const MOBILE_SERVICE_NAME = 'mobiletargeting';
|
|
51
|
-
const EXPIRED_TOKEN_CODE = 'ExpiredTokenException';
|
|
52
|
-
const UPDATE_ENDPOINT = '_update_endpoint';
|
|
53
|
-
const SESSION_START = '_session.start';
|
|
54
|
-
const SESSION_STOP = '_session.stop';
|
|
55
|
-
|
|
56
|
-
const BEACON_SUPPORTED =
|
|
57
|
-
typeof navigator !== 'undefined' &&
|
|
58
|
-
navigator &&
|
|
59
|
-
typeof navigator.sendBeacon === 'function';
|
|
60
|
-
|
|
61
|
-
// events buffer
|
|
62
|
-
const BUFFER_SIZE = 1000;
|
|
63
|
-
const FLUSH_SIZE = 100;
|
|
64
|
-
const FLUSH_INTERVAL = 5 * 1000; // 5s
|
|
65
|
-
const RESEND_LIMIT = 5;
|
|
66
|
-
|
|
67
|
-
// params: { event: {name: , .... }, timeStamp, config, resendLimits }
|
|
68
|
-
export class AWSPinpointProvider implements AnalyticsProvider {
|
|
69
|
-
static category = 'Analytics';
|
|
70
|
-
static providerName = 'AWSPinpoint';
|
|
71
|
-
|
|
72
|
-
private _config;
|
|
73
|
-
private _sessionId;
|
|
74
|
-
private _sessionStartTimestamp;
|
|
75
|
-
private _buffer: EventBuffer | null;
|
|
76
|
-
private _endpointBuffer: EndpointBuffer;
|
|
77
|
-
private _clientInfo;
|
|
78
|
-
private _endpointGenerating = true;
|
|
79
|
-
private _endpointUpdateInProgress = false;
|
|
80
|
-
|
|
81
|
-
constructor(config?) {
|
|
82
|
-
this._buffer = null;
|
|
83
|
-
this._endpointBuffer = [];
|
|
84
|
-
this._config = config ? config : {};
|
|
85
|
-
this._config.bufferSize = this._config.bufferSize || BUFFER_SIZE;
|
|
86
|
-
this._config.flushSize = this._config.flushSize || FLUSH_SIZE;
|
|
87
|
-
this._config.flushInterval = this._config.flushInterval || FLUSH_INTERVAL;
|
|
88
|
-
this._config.resendLimit = this._config.resendLimit || RESEND_LIMIT;
|
|
89
|
-
this._clientInfo = ClientDevice.clientInfo();
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* get the category of the plugin
|
|
94
|
-
*/
|
|
95
|
-
getCategory(): string {
|
|
96
|
-
return AWSPinpointProvider.category;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* get provider name of the plugin
|
|
101
|
-
*/
|
|
102
|
-
getProviderName(): string {
|
|
103
|
-
return AWSPinpointProvider.providerName;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* configure the plugin
|
|
108
|
-
* @param {Object} config - configuration
|
|
109
|
-
*/
|
|
110
|
-
public configure(config): object {
|
|
111
|
-
logger.debug('configure Analytics', config);
|
|
112
|
-
const conf = config || {};
|
|
113
|
-
this._config = Object.assign({}, this._config, conf);
|
|
114
|
-
|
|
115
|
-
// If autoSessionRecord is enabled, we need to wait for the endpoint to be
|
|
116
|
-
// updated before sending any events. See `sendEvents` in `Analytics.ts`
|
|
117
|
-
this._endpointGenerating = !!config['autoSessionRecord'];
|
|
118
|
-
|
|
119
|
-
if (this._config.appId && !this._config.disabled) {
|
|
120
|
-
if (!this._config.endpointId) {
|
|
121
|
-
const cacheKey = this.getProviderName() + '_' + this._config.appId;
|
|
122
|
-
this._getEndpointId(cacheKey)
|
|
123
|
-
.then(endpointId => {
|
|
124
|
-
logger.debug('setting endpoint id from the cache', endpointId);
|
|
125
|
-
this._config.endpointId = endpointId;
|
|
126
|
-
dispatchAnalyticsEvent('pinpointProvider_configured', null);
|
|
127
|
-
})
|
|
128
|
-
.catch(err => {
|
|
129
|
-
logger.debug('Failed to generate endpointId', err);
|
|
130
|
-
});
|
|
131
|
-
} else {
|
|
132
|
-
dispatchAnalyticsEvent('pinpointProvider_configured', null);
|
|
133
|
-
}
|
|
134
|
-
} else {
|
|
135
|
-
this._flushBuffer();
|
|
136
|
-
}
|
|
137
|
-
return this._config;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* record an event
|
|
142
|
-
* @param {Object} params - the params of an event
|
|
143
|
-
*/
|
|
144
|
-
public async record(params: EventParams, handlers: PromiseHandlers) {
|
|
145
|
-
logger.debug('_public record', params);
|
|
146
|
-
const credentials = await this._getCredentials();
|
|
147
|
-
if (!credentials || !this._config.appId || !this._config.region) {
|
|
148
|
-
logger.debug(
|
|
149
|
-
'cannot send events without credentials, applicationId or region'
|
|
150
|
-
);
|
|
151
|
-
return handlers.reject(
|
|
152
|
-
new Error('No credentials, applicationId or region')
|
|
153
|
-
);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
this._init(credentials);
|
|
157
|
-
|
|
158
|
-
const timestamp = new Date().getTime();
|
|
159
|
-
// attach the session and eventId
|
|
160
|
-
this._generateSession(params);
|
|
161
|
-
params.event.eventId = uuid();
|
|
162
|
-
|
|
163
|
-
Object.assign(params, { timestamp, config: this._config });
|
|
164
|
-
|
|
165
|
-
if (params.event.immediate) {
|
|
166
|
-
return this._send(params, handlers);
|
|
167
|
-
} else {
|
|
168
|
-
this._putToBuffer(params, handlers);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
private async _sendEndpointUpdate(endpointObject: EventObject) {
|
|
173
|
-
if (this._endpointUpdateInProgress) {
|
|
174
|
-
this._endpointBuffer.push(endpointObject);
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
this._endpointUpdateInProgress = true;
|
|
179
|
-
await this._updateEndpoint(endpointObject);
|
|
180
|
-
|
|
181
|
-
const next = this._endpointBuffer.shift();
|
|
182
|
-
this._endpointUpdateInProgress = false;
|
|
183
|
-
|
|
184
|
-
next && this._sendEndpointUpdate(next);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* @private
|
|
189
|
-
* @param params - params for event recording
|
|
190
|
-
* Put events into buffer
|
|
191
|
-
*/
|
|
192
|
-
private _putToBuffer(params, handlers) {
|
|
193
|
-
if (params.event.name === UPDATE_ENDPOINT) {
|
|
194
|
-
this._sendEndpointUpdate({ params, handlers });
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
this._buffer?.push({ params, handlers });
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
private _generateSession(params) {
|
|
202
|
-
this._sessionId = this._sessionId || uuid();
|
|
203
|
-
const { event } = params;
|
|
204
|
-
|
|
205
|
-
switch (event.name) {
|
|
206
|
-
case SESSION_START:
|
|
207
|
-
// refresh the session id and session start time
|
|
208
|
-
this._sessionStartTimestamp = new Date().getTime();
|
|
209
|
-
this._sessionId = uuid();
|
|
210
|
-
event.session = {
|
|
211
|
-
Id: this._sessionId,
|
|
212
|
-
StartTimestamp: new Date(this._sessionStartTimestamp).toISOString(),
|
|
213
|
-
};
|
|
214
|
-
break;
|
|
215
|
-
case SESSION_STOP:
|
|
216
|
-
const stopTimestamp = new Date().getTime();
|
|
217
|
-
this._sessionStartTimestamp =
|
|
218
|
-
this._sessionStartTimestamp || new Date().getTime();
|
|
219
|
-
this._sessionId = this._sessionId || uuid();
|
|
220
|
-
event.session = {
|
|
221
|
-
Id: this._sessionId,
|
|
222
|
-
Duration: stopTimestamp - this._sessionStartTimestamp,
|
|
223
|
-
StartTimestamp: new Date(this._sessionStartTimestamp).toISOString(),
|
|
224
|
-
StopTimestamp: new Date(stopTimestamp).toISOString(),
|
|
225
|
-
};
|
|
226
|
-
this._sessionId = undefined;
|
|
227
|
-
this._sessionStartTimestamp = undefined;
|
|
228
|
-
break;
|
|
229
|
-
default:
|
|
230
|
-
this._sessionStartTimestamp =
|
|
231
|
-
this._sessionStartTimestamp || new Date().getTime();
|
|
232
|
-
this._sessionId = this._sessionId || uuid();
|
|
233
|
-
event.session = {
|
|
234
|
-
Id: this._sessionId,
|
|
235
|
-
StartTimestamp: new Date(this._sessionStartTimestamp).toISOString(),
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
private async _send(params, handlers) {
|
|
241
|
-
const { event } = params;
|
|
242
|
-
|
|
243
|
-
switch (event.name) {
|
|
244
|
-
case UPDATE_ENDPOINT:
|
|
245
|
-
return this._updateEndpoint({ params, handlers });
|
|
246
|
-
case SESSION_STOP:
|
|
247
|
-
return this._pinpointSendStopSession(params, handlers);
|
|
248
|
-
default:
|
|
249
|
-
return this._pinpointPutEvents(params, handlers);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
private _generateBatchItemContext(params): PutEventsInput {
|
|
254
|
-
const { event, timestamp, config } = params;
|
|
255
|
-
const { name, attributes, metrics, eventId, session } = event;
|
|
256
|
-
const { appId, endpointId } = config;
|
|
257
|
-
const endpointContext = {};
|
|
258
|
-
|
|
259
|
-
return {
|
|
260
|
-
ApplicationId: appId,
|
|
261
|
-
EventsRequest: {
|
|
262
|
-
BatchItem: {
|
|
263
|
-
[endpointId]: {
|
|
264
|
-
Endpoint: endpointContext,
|
|
265
|
-
Events: {
|
|
266
|
-
[eventId]: {
|
|
267
|
-
EventType: name,
|
|
268
|
-
Timestamp: new Date(timestamp).toISOString(),
|
|
269
|
-
Attributes: attributes,
|
|
270
|
-
Metrics: metrics,
|
|
271
|
-
Session: session,
|
|
272
|
-
},
|
|
273
|
-
},
|
|
274
|
-
},
|
|
275
|
-
},
|
|
276
|
-
},
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
private async _pinpointPutEvents(params, handlers) {
|
|
281
|
-
const {
|
|
282
|
-
event: { eventId },
|
|
283
|
-
config: { endpointId },
|
|
284
|
-
} = params;
|
|
285
|
-
const eventParams = this._generateBatchItemContext(params);
|
|
286
|
-
|
|
287
|
-
try {
|
|
288
|
-
const { credentials, region } = this._config;
|
|
289
|
-
const data: PutEventsOutput = await putEvents(
|
|
290
|
-
{
|
|
291
|
-
credentials,
|
|
292
|
-
region,
|
|
293
|
-
userAgentValue: getAnalyticsUserAgentString(AnalyticsAction.Record),
|
|
294
|
-
},
|
|
295
|
-
eventParams
|
|
296
|
-
);
|
|
297
|
-
|
|
298
|
-
const { StatusCode, Message } =
|
|
299
|
-
data.EventsResponse?.Results?.[endpointId]?.EventsItemResponse?.[
|
|
300
|
-
eventId
|
|
301
|
-
] ?? {};
|
|
302
|
-
|
|
303
|
-
if (StatusCode && ACCEPTED_CODES.includes(StatusCode)) {
|
|
304
|
-
logger.debug('record event success. ', data);
|
|
305
|
-
return handlers.resolve(data);
|
|
306
|
-
} else if (StatusCode && RETRYABLE_CODES.includes(StatusCode)) {
|
|
307
|
-
// TODO: v6 integrate retry to the service handler retryDecider
|
|
308
|
-
this._retry(params, handlers);
|
|
309
|
-
} else {
|
|
310
|
-
logger.error(
|
|
311
|
-
`Event ${eventId} is not accepted, the error is ${Message}`
|
|
312
|
-
);
|
|
313
|
-
return handlers.reject(data);
|
|
314
|
-
}
|
|
315
|
-
} catch (err) {
|
|
316
|
-
this._eventError(err);
|
|
317
|
-
return handlers.reject(err);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
private _pinpointSendStopSession(params, handlers): Promise<string> | void {
|
|
322
|
-
if (!BEACON_SUPPORTED) {
|
|
323
|
-
this._pinpointPutEvents(params, handlers);
|
|
324
|
-
return;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
const eventParams = this._generateBatchItemContext(params);
|
|
328
|
-
|
|
329
|
-
const { region } = this._config;
|
|
330
|
-
const { ApplicationId, EventsRequest } = eventParams;
|
|
331
|
-
|
|
332
|
-
const accessInfo = {
|
|
333
|
-
secret_key: this._config.credentials.secretAccessKey,
|
|
334
|
-
access_key: this._config.credentials.accessKeyId,
|
|
335
|
-
session_token: this._config.credentials.sessionToken,
|
|
336
|
-
};
|
|
337
|
-
|
|
338
|
-
const url = `https://pinpoint.${region}.amazonaws.com/v1/apps/${ApplicationId}/events/legacy`;
|
|
339
|
-
const body = JSON.stringify(EventsRequest);
|
|
340
|
-
const method = 'POST';
|
|
341
|
-
|
|
342
|
-
const request = {
|
|
343
|
-
url,
|
|
344
|
-
body,
|
|
345
|
-
method,
|
|
346
|
-
};
|
|
347
|
-
|
|
348
|
-
const serviceInfo = { region, service: MOBILE_SERVICE_NAME };
|
|
349
|
-
|
|
350
|
-
const requestUrl: string = Signer.signUrl(request, accessInfo, serviceInfo);
|
|
351
|
-
|
|
352
|
-
const success: boolean = navigator.sendBeacon(requestUrl, body);
|
|
353
|
-
|
|
354
|
-
if (success) {
|
|
355
|
-
return handlers.resolve('sendBeacon success');
|
|
356
|
-
}
|
|
357
|
-
return handlers.reject('sendBeacon failure');
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
private _retry(params, handlers) {
|
|
361
|
-
const {
|
|
362
|
-
config: { resendLimit },
|
|
363
|
-
} = params;
|
|
364
|
-
// For backward compatibility
|
|
365
|
-
params.resendLimit =
|
|
366
|
-
typeof params.resendLimit === 'number' ? params.resendLimit : resendLimit;
|
|
367
|
-
if (params.resendLimit-- > 0) {
|
|
368
|
-
logger.debug(
|
|
369
|
-
`resending event ${params.eventName} with ${params.resendLimit} retry times left`
|
|
370
|
-
);
|
|
371
|
-
this._pinpointPutEvents(params, handlers);
|
|
372
|
-
} else {
|
|
373
|
-
logger.debug(`retry times used up for event ${params.eventName}`);
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
private async _updateEndpoint(endpointObject: EventObject) {
|
|
378
|
-
const { params, handlers } = endpointObject;
|
|
379
|
-
const { config, event } = params;
|
|
380
|
-
const { appId, endpointId } = config;
|
|
381
|
-
|
|
382
|
-
const request = this._endpointRequest(
|
|
383
|
-
config,
|
|
384
|
-
transferKeyToLowerCase(
|
|
385
|
-
event,
|
|
386
|
-
[],
|
|
387
|
-
['attributes', 'userAttributes', 'Attributes', 'UserAttributes']
|
|
388
|
-
)
|
|
389
|
-
);
|
|
390
|
-
const update_params: UpdateEndpointInput = {
|
|
391
|
-
ApplicationId: appId,
|
|
392
|
-
EndpointId: endpointId,
|
|
393
|
-
EndpointRequest: request,
|
|
394
|
-
};
|
|
395
|
-
|
|
396
|
-
try {
|
|
397
|
-
const { credentials, region } = this._config;
|
|
398
|
-
const data: UpdateEndpointOutput = await updateEndpoint(
|
|
399
|
-
{
|
|
400
|
-
credentials,
|
|
401
|
-
region,
|
|
402
|
-
userAgentValue: getAnalyticsUserAgentString(
|
|
403
|
-
AnalyticsAction.UpdateEndpoint
|
|
404
|
-
),
|
|
405
|
-
},
|
|
406
|
-
update_params
|
|
407
|
-
);
|
|
408
|
-
logger.debug('updateEndpoint success', data);
|
|
409
|
-
this._endpointGenerating = false;
|
|
410
|
-
this._resumeBuffer();
|
|
411
|
-
|
|
412
|
-
handlers.resolve(data);
|
|
413
|
-
return;
|
|
414
|
-
} catch (err) {
|
|
415
|
-
const failureData: EndpointFailureData = {
|
|
416
|
-
err,
|
|
417
|
-
update_params,
|
|
418
|
-
endpointObject,
|
|
419
|
-
};
|
|
420
|
-
|
|
421
|
-
return this._handleEndpointUpdateFailure(failureData);
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
private async _handleEndpointUpdateFailure(failureData: EndpointFailureData) {
|
|
426
|
-
const { err, endpointObject } = failureData;
|
|
427
|
-
const statusCode = err.$metadata && err.$metadata.httpStatusCode;
|
|
428
|
-
|
|
429
|
-
logger.debug('updateEndpoint error', err);
|
|
430
|
-
|
|
431
|
-
switch (statusCode) {
|
|
432
|
-
case FORBIDDEN_CODE:
|
|
433
|
-
return this._handleEndpointUpdateForbidden(failureData);
|
|
434
|
-
default:
|
|
435
|
-
if (RETRYABLE_CODES.includes(statusCode)) {
|
|
436
|
-
// Server error. Attempt exponential retry
|
|
437
|
-
const exponential = true;
|
|
438
|
-
return this._retryEndpointUpdate(endpointObject, exponential);
|
|
439
|
-
}
|
|
440
|
-
logger.error('updateEndpoint failed', err);
|
|
441
|
-
endpointObject.handlers.reject(err);
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
private _handleEndpointUpdateForbidden(failureData: EndpointFailureData) {
|
|
446
|
-
const { err, endpointObject } = failureData;
|
|
447
|
-
|
|
448
|
-
const { code, retryable } = err;
|
|
449
|
-
|
|
450
|
-
if (code !== EXPIRED_TOKEN_CODE && !retryable) {
|
|
451
|
-
return endpointObject.handlers.reject(err);
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
this._retryEndpointUpdate(endpointObject);
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
private _retryEndpointUpdate(
|
|
458
|
-
endpointObject: EventObject,
|
|
459
|
-
exponential: boolean = false
|
|
460
|
-
) {
|
|
461
|
-
logger.debug('_retryEndpointUpdate', endpointObject);
|
|
462
|
-
const { params } = endpointObject;
|
|
463
|
-
|
|
464
|
-
// TODO: implement retry with exp back off once exp function is available
|
|
465
|
-
const {
|
|
466
|
-
config: { resendLimit },
|
|
467
|
-
} = params;
|
|
468
|
-
|
|
469
|
-
params.resendLimit =
|
|
470
|
-
typeof params.resendLimit === 'number' ? params.resendLimit : resendLimit;
|
|
471
|
-
|
|
472
|
-
if (params.resendLimit-- > 0) {
|
|
473
|
-
logger.debug(
|
|
474
|
-
`resending endpoint update ${params.event.eventId} with ${params.resendLimit} retry attempts remaining`
|
|
475
|
-
);
|
|
476
|
-
// insert at the front of endpointBuffer
|
|
477
|
-
this._endpointBuffer.length
|
|
478
|
-
? this._endpointBuffer.unshift(endpointObject)
|
|
479
|
-
: this._updateEndpoint(endpointObject);
|
|
480
|
-
return;
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
logger.warn(
|
|
484
|
-
`resending endpoint update ${params.event.eventId} failed after ${params.config.resendLimit} attempts`
|
|
485
|
-
);
|
|
486
|
-
|
|
487
|
-
if (this._endpointGenerating) {
|
|
488
|
-
logger.error('Initial endpoint update failed. ');
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
/**
|
|
493
|
-
* @private
|
|
494
|
-
* @param config
|
|
495
|
-
* Configure credentials and init buffer
|
|
496
|
-
*/
|
|
497
|
-
private async _init(credentials) {
|
|
498
|
-
logger.debug('init provider');
|
|
499
|
-
|
|
500
|
-
if (
|
|
501
|
-
this._config.credentials &&
|
|
502
|
-
this._config.credentials.sessionToken === credentials.sessionToken &&
|
|
503
|
-
this._config.credentials.identityId === credentials.identityId
|
|
504
|
-
) {
|
|
505
|
-
logger.debug('no change for aws credentials, directly return from init');
|
|
506
|
-
return;
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
const identityId = this._config.credentials
|
|
510
|
-
? this._config.credentials.identityId
|
|
511
|
-
: null;
|
|
512
|
-
|
|
513
|
-
this._config.credentials = credentials;
|
|
514
|
-
|
|
515
|
-
if (!this._bufferExists() || identityId !== credentials.identityId) {
|
|
516
|
-
// if the identity has changed, flush the buffer and instantiate a new one
|
|
517
|
-
// this will cause the old buffer to send any remaining events
|
|
518
|
-
// with the old credentials and then stop looping and shortly thereafter get picked up by GC
|
|
519
|
-
this._initBuffer();
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
private _bufferExists() {
|
|
524
|
-
return this._buffer && this._buffer instanceof EventBuffer;
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
private _initBuffer() {
|
|
528
|
-
if (this._bufferExists()) {
|
|
529
|
-
this._flushBuffer();
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
this._buffer = new EventBuffer(this._config);
|
|
533
|
-
|
|
534
|
-
// if the first endpoint update hasn't yet resolved pause the buffer to
|
|
535
|
-
// prevent race conditions. It will be resumed as soon as that request succeeds
|
|
536
|
-
if (this._endpointGenerating) {
|
|
537
|
-
this._buffer.pause();
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
private _flushBuffer() {
|
|
542
|
-
if (this._bufferExists()) {
|
|
543
|
-
this._buffer?.flush();
|
|
544
|
-
this._buffer = null;
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
private _resumeBuffer() {
|
|
549
|
-
if (this._bufferExists()) {
|
|
550
|
-
this._buffer?.resume();
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
private async _getEndpointId(cacheKey) {
|
|
555
|
-
// try to get from cache
|
|
556
|
-
let endpointId = await Cache.getItem(cacheKey);
|
|
557
|
-
logger.debug(
|
|
558
|
-
'endpointId from cache',
|
|
559
|
-
endpointId,
|
|
560
|
-
'type',
|
|
561
|
-
typeof endpointId
|
|
562
|
-
);
|
|
563
|
-
if (!endpointId) {
|
|
564
|
-
endpointId = uuid();
|
|
565
|
-
// set a longer TTL to avoid endpoint id being deleted after the default TTL (3 days)
|
|
566
|
-
// also set its priority to the highest to reduce its chance of being deleted when cache is full
|
|
567
|
-
const ttl = 1000 * 60 * 60 * 24 * 365 * 100; // 100 years
|
|
568
|
-
const expiration = new Date().getTime() + ttl;
|
|
569
|
-
Cache.setItem(cacheKey, endpointId, {
|
|
570
|
-
expires: expiration,
|
|
571
|
-
priority: 1,
|
|
572
|
-
});
|
|
573
|
-
}
|
|
574
|
-
return endpointId;
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
/**
|
|
578
|
-
* EndPoint request
|
|
579
|
-
* @return {Object} - The request of updating endpoint
|
|
580
|
-
*/
|
|
581
|
-
private _endpointRequest(config, event) {
|
|
582
|
-
const { credentials } = config;
|
|
583
|
-
const clientInfo = this._clientInfo || {};
|
|
584
|
-
const clientContext = config.clientContext || {};
|
|
585
|
-
// for now we have three different ways for default endpoint configurations
|
|
586
|
-
// clientInfo
|
|
587
|
-
// clientContext (deprecated)
|
|
588
|
-
// config.endpoint
|
|
589
|
-
const defaultEndpointConfig = config.endpoint || {};
|
|
590
|
-
const demographicByClientInfo = {
|
|
591
|
-
appVersion: clientInfo.appVersion,
|
|
592
|
-
make: clientInfo.make,
|
|
593
|
-
model: clientInfo.model,
|
|
594
|
-
modelVersion: clientInfo.version,
|
|
595
|
-
platform: clientInfo.platform,
|
|
596
|
-
};
|
|
597
|
-
// for backward compatibility
|
|
598
|
-
const {
|
|
599
|
-
clientId,
|
|
600
|
-
appTitle,
|
|
601
|
-
appVersionName,
|
|
602
|
-
appVersionCode,
|
|
603
|
-
appPackageName,
|
|
604
|
-
...demographicByClientContext
|
|
605
|
-
} = clientContext;
|
|
606
|
-
const channelType = event.address
|
|
607
|
-
? clientInfo.platform === 'android'
|
|
608
|
-
? 'GCM'
|
|
609
|
-
: 'APNS'
|
|
610
|
-
: undefined;
|
|
611
|
-
const tmp = {
|
|
612
|
-
channelType,
|
|
613
|
-
requestId: uuid(),
|
|
614
|
-
effectiveDate: new Date().toISOString(),
|
|
615
|
-
...defaultEndpointConfig,
|
|
616
|
-
...event,
|
|
617
|
-
attributes: {
|
|
618
|
-
...defaultEndpointConfig.attributes,
|
|
619
|
-
...event.attributes,
|
|
620
|
-
},
|
|
621
|
-
demographic: {
|
|
622
|
-
...demographicByClientInfo,
|
|
623
|
-
...demographicByClientContext,
|
|
624
|
-
...defaultEndpointConfig.demographic,
|
|
625
|
-
...event.demographic,
|
|
626
|
-
},
|
|
627
|
-
location: {
|
|
628
|
-
...defaultEndpointConfig.location,
|
|
629
|
-
...event.location,
|
|
630
|
-
},
|
|
631
|
-
metrics: {
|
|
632
|
-
...defaultEndpointConfig.metrics,
|
|
633
|
-
...event.metrics,
|
|
634
|
-
},
|
|
635
|
-
user: {
|
|
636
|
-
userId:
|
|
637
|
-
event.userId ||
|
|
638
|
-
defaultEndpointConfig.userId ||
|
|
639
|
-
credentials.identityId,
|
|
640
|
-
userAttributes: {
|
|
641
|
-
...defaultEndpointConfig.userAttributes,
|
|
642
|
-
...event.userAttributes,
|
|
643
|
-
},
|
|
644
|
-
},
|
|
645
|
-
};
|
|
646
|
-
|
|
647
|
-
// eliminate unnecessary params
|
|
648
|
-
const {
|
|
649
|
-
userId,
|
|
650
|
-
userAttributes,
|
|
651
|
-
name,
|
|
652
|
-
session,
|
|
653
|
-
eventId,
|
|
654
|
-
immediate,
|
|
655
|
-
...ret
|
|
656
|
-
} = tmp;
|
|
657
|
-
return transferKeyToUpperCase(
|
|
658
|
-
ret,
|
|
659
|
-
[],
|
|
660
|
-
['metrics', 'userAttributes', 'attributes']
|
|
661
|
-
);
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
private _eventError(err: any) {
|
|
665
|
-
logger.error('record event failed.', err);
|
|
666
|
-
logger.warn(
|
|
667
|
-
`Please ensure you have updated your Pinpoint IAM Policy ` +
|
|
668
|
-
`with the Action: "mobiletargeting:PutEvents" ` +
|
|
669
|
-
`in order to record events`
|
|
670
|
-
);
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
private async _getCredentials() {
|
|
674
|
-
try {
|
|
675
|
-
const credentials = await Credentials.get();
|
|
676
|
-
if (!credentials) return null;
|
|
677
|
-
|
|
678
|
-
logger.debug('set credentials for analytics', credentials);
|
|
679
|
-
return Credentials.shear(credentials);
|
|
680
|
-
} catch (err) {
|
|
681
|
-
logger.debug('ensure credentials error', err);
|
|
682
|
-
return null;
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
}
|