@aws-amplify/analytics 7.0.16 → 7.0.17-unstable.0d2aa5d.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/dist/cjs/providers/kinesis/apis/flushEvents.js +8 -6
- package/dist/cjs/providers/kinesis/apis/flushEvents.js.map +1 -1
- package/dist/cjs/providers/kinesis/apis/record.js +7 -7
- package/dist/cjs/providers/kinesis/apis/record.js.map +1 -1
- package/dist/cjs/providers/kinesis/utils/getEventBuffer.js +2 -2
- package/dist/cjs/providers/kinesis/utils/getEventBuffer.js.map +1 -1
- package/dist/cjs/providers/kinesis-firehose/apis/flushEvents.js +10 -8
- package/dist/cjs/providers/kinesis-firehose/apis/flushEvents.js.map +1 -1
- package/dist/cjs/providers/kinesis-firehose/apis/record.js +8 -8
- package/dist/cjs/providers/kinesis-firehose/apis/record.js.map +1 -1
- package/dist/cjs/providers/kinesis-firehose/utils/getEventBuffer.js +2 -2
- package/dist/cjs/providers/kinesis-firehose/utils/getEventBuffer.js.map +1 -1
- package/dist/cjs/providers/personalize/apis/flushEvents.js +10 -8
- package/dist/cjs/providers/personalize/apis/flushEvents.js.map +1 -1
- package/dist/cjs/providers/personalize/apis/record.js +14 -14
- package/dist/cjs/providers/personalize/apis/record.js.map +1 -1
- package/dist/cjs/providers/personalize/utils/autoTrackMedia.js +8 -8
- package/dist/cjs/providers/personalize/utils/autoTrackMedia.js.map +1 -1
- package/dist/cjs/providers/personalize/utils/getEventBuffer.js +2 -2
- package/dist/cjs/providers/personalize/utils/getEventBuffer.js.map +1 -1
- package/dist/cjs/providers/pinpoint/apis/flushEvents.js +20 -16
- package/dist/cjs/providers/pinpoint/apis/flushEvents.js.map +1 -1
- package/dist/cjs/providers/pinpoint/apis/identifyUser.js +1 -1
- package/dist/cjs/providers/pinpoint/apis/identifyUser.js.map +1 -1
- package/dist/cjs/trackers/PageViewTracker.js +2 -4
- package/dist/cjs/trackers/PageViewTracker.js.map +1 -1
- package/dist/cjs/utils/resolveCredentials.js +1 -1
- package/dist/cjs/utils/resolveCredentials.js.map +1 -1
- package/dist/esm/apis/disable.mjs +1 -1
- package/dist/esm/apis/enable.mjs +1 -1
- package/dist/esm/providers/kinesis/apis/flushEvents.mjs +5 -3
- package/dist/esm/providers/kinesis/apis/flushEvents.mjs.map +1 -1
- package/dist/esm/providers/kinesis/apis/record.mjs +3 -3
- package/dist/esm/providers/kinesis/apis/record.mjs.map +1 -1
- package/dist/esm/providers/kinesis/types/inputs.d.ts +2 -2
- package/dist/esm/providers/kinesis/utils/getEventBuffer.mjs +3 -3
- package/dist/esm/providers/kinesis/utils/getEventBuffer.mjs.map +1 -1
- package/dist/esm/providers/kinesis-firehose/apis/flushEvents.mjs +5 -3
- package/dist/esm/providers/kinesis-firehose/apis/flushEvents.mjs.map +1 -1
- package/dist/esm/providers/kinesis-firehose/apis/record.mjs +3 -3
- package/dist/esm/providers/kinesis-firehose/apis/record.mjs.map +1 -1
- package/dist/esm/providers/kinesis-firehose/types/buffer.d.ts +1 -1
- package/dist/esm/providers/kinesis-firehose/types/inputs.d.ts +2 -2
- package/dist/esm/providers/kinesis-firehose/utils/getEventBuffer.mjs +3 -3
- package/dist/esm/providers/kinesis-firehose/utils/getEventBuffer.mjs.map +1 -1
- package/dist/esm/providers/personalize/apis/flushEvents.mjs +5 -3
- package/dist/esm/providers/personalize/apis/flushEvents.mjs.map +1 -1
- package/dist/esm/providers/personalize/apis/record.mjs +3 -3
- package/dist/esm/providers/personalize/apis/record.mjs.map +1 -1
- package/dist/esm/providers/personalize/types/buffer.d.ts +4 -4
- package/dist/esm/providers/personalize/types/inputs.d.ts +2 -2
- package/dist/esm/providers/personalize/utils/autoTrackMedia.d.ts +2 -2
- package/dist/esm/providers/personalize/utils/autoTrackMedia.mjs +8 -8
- package/dist/esm/providers/personalize/utils/autoTrackMedia.mjs.map +1 -1
- package/dist/esm/providers/personalize/utils/cachedSession.mjs.map +1 -1
- package/dist/esm/providers/personalize/utils/getEventBuffer.mjs +3 -3
- package/dist/esm/providers/personalize/utils/getEventBuffer.mjs.map +1 -1
- package/dist/esm/providers/pinpoint/apis/configureAutoTrack.mjs +1 -1
- package/dist/esm/providers/pinpoint/apis/flushEvents.mjs +18 -14
- package/dist/esm/providers/pinpoint/apis/flushEvents.mjs.map +1 -1
- package/dist/esm/providers/pinpoint/apis/identifyUser.d.ts +1 -1
- package/dist/esm/providers/pinpoint/apis/identifyUser.mjs +2 -2
- package/dist/esm/providers/pinpoint/apis/identifyUser.mjs.map +1 -1
- package/dist/esm/providers/pinpoint/apis/record.mjs.map +1 -1
- package/dist/esm/providers/pinpoint/types/inputs.d.ts +1 -1
- package/dist/esm/trackers/PageViewTracker.mjs +2 -4
- package/dist/esm/trackers/PageViewTracker.mjs.map +1 -1
- package/dist/esm/trackers/SessionTracker.mjs.map +1 -1
- package/dist/esm/trackers/SessionTracker.native.mjs.map +1 -1
- package/dist/esm/types/inputs.d.ts +3 -3
- package/dist/esm/types/kinesis.d.ts +2 -2
- package/dist/esm/types/trackers.d.ts +7 -7
- package/dist/esm/utils/eventBuffer/types.d.ts +3 -5
- package/dist/esm/utils/resolveCredentials.mjs +1 -1
- package/dist/esm/utils/resolveCredentials.mjs.map +1 -1
- package/dist/esm/utils/userAgent.mjs.map +1 -1
- package/package.json +110 -110
- package/src/errors/assertValidationError.ts +1 -1
- package/src/providers/kinesis/apis/flushEvents.ts +7 -4
- package/src/providers/kinesis/apis/record.ts +6 -3
- package/src/providers/kinesis/types/buffer.ts +1 -0
- package/src/providers/kinesis/types/inputs.ts +2 -2
- package/src/providers/kinesis/utils/getEventBuffer.ts +22 -21
- package/src/providers/kinesis/utils/resolveConfig.ts +4 -1
- package/src/providers/kinesis-firehose/apis/flushEvents.ts +7 -4
- package/src/providers/kinesis-firehose/apis/record.ts +6 -3
- package/src/providers/kinesis-firehose/types/buffer.ts +2 -1
- package/src/providers/kinesis-firehose/types/inputs.ts +2 -2
- package/src/providers/kinesis-firehose/utils/getEventBuffer.ts +23 -21
- package/src/providers/kinesis-firehose/utils/resolveConfig.ts +4 -1
- package/src/providers/personalize/apis/flushEvents.ts +7 -4
- package/src/providers/personalize/apis/record.ts +8 -5
- package/src/providers/personalize/types/buffer.ts +6 -4
- package/src/providers/personalize/types/inputs.ts +2 -2
- package/src/providers/personalize/utils/autoTrackMedia.ts +34 -26
- package/src/providers/personalize/utils/cachedSession.ts +5 -5
- package/src/providers/personalize/utils/getEventBuffer.ts +24 -20
- package/src/providers/personalize/utils/resolveConfig.ts +4 -2
- package/src/providers/pinpoint/apis/configureAutoTrack.ts +5 -2
- package/src/providers/pinpoint/apis/flushEvents.ts +8 -5
- package/src/providers/pinpoint/apis/identifyUser.ts +3 -2
- package/src/providers/pinpoint/apis/record.ts +4 -2
- package/src/providers/pinpoint/types/inputs.ts +3 -1
- package/src/providers/pinpoint/utils/resolveConfig.ts +1 -0
- package/src/providers/pinpoint/utils/resolveCredentials.ts +3 -1
- package/src/trackers/EventTracker.ts +7 -6
- package/src/trackers/PageViewTracker.ts +8 -13
- package/src/trackers/SessionTracker.native.ts +6 -5
- package/src/trackers/SessionTracker.ts +6 -5
- package/src/types/inputs.ts +6 -5
- package/src/types/kinesis.ts +2 -2
- package/src/types/trackers.ts +8 -8
- package/src/utils/eventBuffer/EventBuffer.ts +3 -2
- package/src/utils/eventBuffer/types.ts +3 -5
- package/src/utils/groupBy.ts +3 -2
- package/src/utils/resolveCredentials.ts +4 -2
- package/src/utils/trackerConfigHelpers.native.ts +2 -2
- package/src/utils/trackerConfigHelpers.ts +2 -2
- package/src/utils/trackerHelpers.ts +1 -2
- package/src/utils/userAgent.ts +1 -1
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
// SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.flushEvents = void 0;
|
|
7
|
+
const utils_1 = require("@aws-amplify/core/internals/utils");
|
|
8
|
+
const core_1 = require("@aws-amplify/core");
|
|
7
9
|
const resolveConfig_1 = require("../utils/resolveConfig");
|
|
8
|
-
const
|
|
10
|
+
const utils_2 = require("../../../utils");
|
|
9
11
|
const getEventBuffer_1 = require("../utils/getEventBuffer");
|
|
10
|
-
const utils_2 = require("@aws-amplify/core/internals/utils");
|
|
11
|
-
const core_1 = require("@aws-amplify/core");
|
|
12
12
|
const logger = new core_1.ConsoleLogger('Kinesis');
|
|
13
13
|
/**
|
|
14
14
|
* Flushes all buffered Kinesis events to the service.
|
|
@@ -19,7 +19,7 @@ const logger = new core_1.ConsoleLogger('Kinesis');
|
|
|
19
19
|
*/
|
|
20
20
|
const flushEvents = () => {
|
|
21
21
|
const { region, flushSize, flushInterval, bufferSize, resendLimit } = (0, resolveConfig_1.resolveConfig)();
|
|
22
|
-
(0,
|
|
22
|
+
(0, utils_2.resolveCredentials)()
|
|
23
23
|
.then(({ credentials, identityId }) => (0, getEventBuffer_1.getEventBuffer)({
|
|
24
24
|
region,
|
|
25
25
|
flushSize,
|
|
@@ -28,10 +28,12 @@ const flushEvents = () => {
|
|
|
28
28
|
credentials,
|
|
29
29
|
identityId,
|
|
30
30
|
resendLimit,
|
|
31
|
-
userAgentValue: (0,
|
|
31
|
+
userAgentValue: (0, utils_2.getAnalyticsUserAgentString)(utils_1.AnalyticsAction.Record),
|
|
32
32
|
}))
|
|
33
33
|
.then(eventBuffer => eventBuffer.flushAll())
|
|
34
|
-
.catch(e =>
|
|
34
|
+
.catch(e => {
|
|
35
|
+
logger.warn('Failed to flush events.', e);
|
|
36
|
+
});
|
|
35
37
|
};
|
|
36
38
|
exports.flushEvents = flushEvents;
|
|
37
39
|
//# sourceMappingURL=flushEvents.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flushEvents.js","sources":["../../../../../src/providers/kinesis/apis/flushEvents.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.flushEvents = void 0;\nconst
|
|
1
|
+
{"version":3,"file":"flushEvents.js","sources":["../../../../../src/providers/kinesis/apis/flushEvents.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.flushEvents = void 0;\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst core_1 = require(\"@aws-amplify/core\");\nconst resolveConfig_1 = require(\"../utils/resolveConfig\");\nconst utils_2 = require(\"../../../utils\");\nconst getEventBuffer_1 = require(\"../utils/getEventBuffer\");\nconst logger = new core_1.ConsoleLogger('Kinesis');\n/**\n * Flushes all buffered Kinesis events to the service.\n *\n * @note\n * This API will make a best-effort attempt to flush events from the buffer. Events recorded immediately after invoking\n * this API may not be included in the flush.\n */\nconst flushEvents = () => {\n const { region, flushSize, flushInterval, bufferSize, resendLimit } = (0, resolveConfig_1.resolveConfig)();\n (0, utils_2.resolveCredentials)()\n .then(({ credentials, identityId }) => (0, getEventBuffer_1.getEventBuffer)({\n region,\n flushSize,\n flushInterval,\n bufferSize,\n credentials,\n identityId,\n resendLimit,\n userAgentValue: (0, utils_2.getAnalyticsUserAgentString)(utils_1.AnalyticsAction.Record),\n }))\n .then(eventBuffer => eventBuffer.flushAll())\n .catch(e => {\n logger.warn('Failed to flush events.', e);\n });\n};\nexports.flushEvents = flushEvents;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,WAAW,GAAG,KAAK,CAAC,CAAC;AAC7B,MAAM,OAAO,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAAC;AAC7D,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC5C,MAAM,eAAe,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;AAC1D,MAAM,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAC1C,MAAM,gBAAgB,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;AAC5D,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;AACnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,WAAW,GAAG,MAAM;AAC1B,IAAI,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,GAAG,IAAI,eAAe,CAAC,aAAa,GAAG,CAAC;AAC/G,IAAI,IAAI,OAAO,CAAC,kBAAkB,GAAG;AACrC,SAAS,IAAI,CAAC,CAAC,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK,IAAI,gBAAgB,CAAC,cAAc,EAAE;AACpF,QAAQ,MAAM;AACd,QAAQ,SAAS;AACjB,QAAQ,aAAa;AACrB,QAAQ,UAAU;AAClB,QAAQ,WAAW;AACnB,QAAQ,UAAU;AAClB,QAAQ,WAAW;AACnB,QAAQ,cAAc,EAAE,IAAI,OAAO,CAAC,2BAA2B,EAAE,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC;AAChG,KAAK,CAAC,CAAC;AACP,SAAS,IAAI,CAAC,WAAW,IAAI,WAAW,CAAC,QAAQ,EAAE,CAAC;AACpD,SAAS,KAAK,CAAC,CAAC,IAAI;AACpB,QAAQ,MAAM,CAAC,IAAI,CAAC,yBAAyB,EAAE,CAAC,CAAC,CAAC;AAClD,KAAK,CAAC,CAAC;AACP,CAAC,CAAC;AACF,OAAO,CAAC,WAAW,GAAG,WAAW;;"}
|
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
// SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.record = void 0;
|
|
7
|
-
const getEventBuffer_1 = require("../utils/getEventBuffer");
|
|
8
|
-
const resolveConfig_1 = require("../utils/resolveConfig");
|
|
9
|
-
const utils_1 = require("../../../utils");
|
|
10
7
|
const util_utf8_1 = require("@smithy/util-utf8");
|
|
11
|
-
const
|
|
8
|
+
const utils_1 = require("@aws-amplify/core/internals/utils");
|
|
12
9
|
const core_1 = require("@aws-amplify/core");
|
|
10
|
+
const getEventBuffer_1 = require("../utils/getEventBuffer");
|
|
11
|
+
const resolveConfig_1 = require("../utils/resolveConfig");
|
|
12
|
+
const utils_2 = require("../../../utils");
|
|
13
13
|
const logger = new core_1.ConsoleLogger('Kinesis');
|
|
14
14
|
/**
|
|
15
15
|
* Record one analytic event and send it to Kinesis. Events will be buffered and periodically sent to
|
|
@@ -33,13 +33,13 @@ const logger = new core_1.ConsoleLogger('Kinesis');
|
|
|
33
33
|
* @returns void
|
|
34
34
|
*/
|
|
35
35
|
const record = ({ streamName, partitionKey, data, }) => {
|
|
36
|
-
if (!(0,
|
|
36
|
+
if (!(0, utils_2.isAnalyticsEnabled)()) {
|
|
37
37
|
logger.debug('Analytics is disabled, event will not be recorded.');
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
40
|
const timestamp = Date.now();
|
|
41
41
|
const { region, bufferSize, flushSize, flushInterval, resendLimit } = (0, resolveConfig_1.resolveConfig)();
|
|
42
|
-
(0,
|
|
42
|
+
(0, utils_2.resolveCredentials)()
|
|
43
43
|
.then(({ credentials, identityId }) => {
|
|
44
44
|
const buffer = (0, getEventBuffer_1.getEventBuffer)({
|
|
45
45
|
region,
|
|
@@ -49,7 +49,7 @@ const record = ({ streamName, partitionKey, data, }) => {
|
|
|
49
49
|
credentials,
|
|
50
50
|
identityId,
|
|
51
51
|
resendLimit,
|
|
52
|
-
userAgentValue: (0,
|
|
52
|
+
userAgentValue: (0, utils_2.getAnalyticsUserAgentString)(utils_1.AnalyticsAction.Record),
|
|
53
53
|
});
|
|
54
54
|
buffer.append({
|
|
55
55
|
region,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"record.js","sources":["../../../../../src/providers/kinesis/apis/record.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.record = void 0;\nconst
|
|
1
|
+
{"version":3,"file":"record.js","sources":["../../../../../src/providers/kinesis/apis/record.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.record = void 0;\nconst util_utf8_1 = require(\"@smithy/util-utf8\");\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst core_1 = require(\"@aws-amplify/core\");\nconst getEventBuffer_1 = require(\"../utils/getEventBuffer\");\nconst resolveConfig_1 = require(\"../utils/resolveConfig\");\nconst utils_2 = require(\"../../../utils\");\nconst logger = new core_1.ConsoleLogger('Kinesis');\n/**\n * Record one analytic event and send it to Kinesis. Events will be buffered and periodically sent to\n * Kinesis.\n *\n * @param params The input object used to construct the request.\n *\n * @throws validation: {@link AnalyticsValidationErrorCode} - Thrown when the provided parameters or library\n * configuration is incorrect.\n *\n * @example\n * ```ts\n * record({\n * streamName: 'myKinesisStream',\n * partitionKey: 'myPartitionKey',\n * data: { } // The data blob to put into the record\n * });\n * ```\n * @param input - The event to record.\n *\n * @returns void\n */\nconst record = ({ streamName, partitionKey, data, }) => {\n if (!(0, utils_2.isAnalyticsEnabled)()) {\n logger.debug('Analytics is disabled, event will not be recorded.');\n return;\n }\n const timestamp = Date.now();\n const { region, bufferSize, flushSize, flushInterval, resendLimit } = (0, resolveConfig_1.resolveConfig)();\n (0, utils_2.resolveCredentials)()\n .then(({ credentials, identityId }) => {\n const buffer = (0, getEventBuffer_1.getEventBuffer)({\n region,\n bufferSize,\n flushSize,\n flushInterval,\n credentials,\n identityId,\n resendLimit,\n userAgentValue: (0, utils_2.getAnalyticsUserAgentString)(utils_1.AnalyticsAction.Record),\n });\n buffer.append({\n region,\n streamName,\n partitionKey,\n event: ArrayBuffer.isView(data) ? data : (0, util_utf8_1.fromUtf8)(JSON.stringify(data)),\n timestamp,\n retryCount: 0,\n });\n })\n .catch(e => {\n // An error occured while fetching credentials or persisting the event to the buffer\n logger.warn('Failed to record event.', e);\n });\n};\nexports.record = record;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,CAAC;AACxB,MAAM,WAAW,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AACjD,MAAM,OAAO,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAAC;AAC7D,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC5C,MAAM,gBAAgB,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;AAC5D,MAAM,eAAe,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;AAC1D,MAAM,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAC1C,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;AACnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,MAAM,GAAG,CAAC,EAAE,UAAU,EAAE,YAAY,EAAE,IAAI,GAAG,KAAK;AACxD,IAAI,IAAI,CAAC,IAAI,OAAO,CAAC,kBAAkB,GAAG,EAAE;AAC5C,QAAQ,MAAM,CAAC,KAAK,CAAC,oDAAoD,CAAC,CAAC;AAC3E,QAAQ,OAAO;AACf,KAAK;AACL,IAAI,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;AACjC,IAAI,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,WAAW,EAAE,GAAG,IAAI,eAAe,CAAC,aAAa,GAAG,CAAC;AAC/G,IAAI,IAAI,OAAO,CAAC,kBAAkB,GAAG;AACrC,SAAS,IAAI,CAAC,CAAC,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK;AAC/C,QAAQ,MAAM,MAAM,GAAG,IAAI,gBAAgB,CAAC,cAAc,EAAE;AAC5D,YAAY,MAAM;AAClB,YAAY,UAAU;AACtB,YAAY,SAAS;AACrB,YAAY,aAAa;AACzB,YAAY,WAAW;AACvB,YAAY,UAAU;AACtB,YAAY,WAAW;AACvB,YAAY,cAAc,EAAE,IAAI,OAAO,CAAC,2BAA2B,EAAE,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC;AACpG,SAAS,CAAC,CAAC;AACX,QAAQ,MAAM,CAAC,MAAM,CAAC;AACtB,YAAY,MAAM;AAClB,YAAY,UAAU;AACtB,YAAY,YAAY;AACxB,YAAY,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,IAAI,WAAW,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AACpG,YAAY,SAAS;AACrB,YAAY,UAAU,EAAE,CAAC;AACzB,SAAS,CAAC,CAAC;AACX,KAAK,CAAC;AACN,SAAS,KAAK,CAAC,CAAC,IAAI;AACpB;AACA,QAAQ,MAAM,CAAC,IAAI,CAAC,yBAAyB,EAAE,CAAC,CAAC,CAAC;AAClD,KAAK,CAAC,CAAC;AACP,CAAC,CAAC;AACF,OAAO,CAAC,MAAM,GAAG,MAAM;;"}
|
|
@@ -27,7 +27,7 @@ const createKinesisPutRecordsCommand = (streamName, events) => new client_kinesi
|
|
|
27
27
|
const submitEvents = async (events, client, resendLimit) => {
|
|
28
28
|
const groupedByStreamName = Object.entries((0, utils_2.groupBy)(event => event.streamName, events));
|
|
29
29
|
const requests = groupedByStreamName
|
|
30
|
-
.map(([streamName,
|
|
30
|
+
.map(([streamName, groupedEvents]) => createKinesisPutRecordsCommand(streamName, groupedEvents))
|
|
31
31
|
.map(command => client.send(command));
|
|
32
32
|
const responses = await Promise.allSettled(requests);
|
|
33
33
|
const failedEvents = responses
|
|
@@ -57,7 +57,7 @@ const getEventBuffer = ({ region, flushInterval, flushSize, bufferSize, credenti
|
|
|
57
57
|
region,
|
|
58
58
|
customUserAgent: userAgentValue,
|
|
59
59
|
}),
|
|
60
|
-
credentials
|
|
60
|
+
credentials,
|
|
61
61
|
];
|
|
62
62
|
}
|
|
63
63
|
const [kinesisClient] = cachedClients[sessionIdentityKey];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getEventBuffer.js","sources":["../../../../../src/providers/kinesis/utils/getEventBuffer.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.getEventBuffer = void 0;\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst client_kinesis_1 = require(\"@aws-sdk/client-kinesis\");\nconst utils_2 = require(\"../../../utils\");\n/**\n * These Records hold cached event buffers and AWS clients.\n * The hash key is determined by the region and session,\n * consisting of a combined value comprising [region, sessionToken, identityId].\n *\n * Only one active session should exist at any given moment.\n * When a new session is initiated, the previous ones should be released.\n * */\nconst eventBufferMap = {};\nconst cachedClients = {};\nconst createKinesisPutRecordsCommand = (streamName, events) => new client_kinesis_1.PutRecordsCommand({\n StreamName: streamName,\n Records: events.map(event => ({\n PartitionKey: event.partitionKey,\n Data: event.event,\n })),\n});\nconst submitEvents = async (events, client, resendLimit) => {\n const groupedByStreamName = Object.entries((0, utils_2.groupBy)(event => event.streamName, events));\n const requests = groupedByStreamName\n .map(([streamName,
|
|
1
|
+
{"version":3,"file":"getEventBuffer.js","sources":["../../../../../src/providers/kinesis/utils/getEventBuffer.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.getEventBuffer = void 0;\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst client_kinesis_1 = require(\"@aws-sdk/client-kinesis\");\nconst utils_2 = require(\"../../../utils\");\n/**\n * These Records hold cached event buffers and AWS clients.\n * The hash key is determined by the region and session,\n * consisting of a combined value comprising [region, sessionToken, identityId].\n *\n * Only one active session should exist at any given moment.\n * When a new session is initiated, the previous ones should be released.\n * */\nconst eventBufferMap = {};\nconst cachedClients = {};\nconst createKinesisPutRecordsCommand = (streamName, events) => new client_kinesis_1.PutRecordsCommand({\n StreamName: streamName,\n Records: events.map(event => ({\n PartitionKey: event.partitionKey,\n Data: event.event,\n })),\n});\nconst submitEvents = async (events, client, resendLimit) => {\n const groupedByStreamName = Object.entries((0, utils_2.groupBy)(event => event.streamName, events));\n const requests = groupedByStreamName\n .map(([streamName, groupedEvents]) => createKinesisPutRecordsCommand(streamName, groupedEvents))\n .map(command => client.send(command));\n const responses = await Promise.allSettled(requests);\n const failedEvents = responses\n .map((response, i) => response.status === 'rejected' ? groupedByStreamName[i][1] : [])\n .flat();\n return resendLimit\n ? failedEvents\n .filter(event => event.retryCount < resendLimit)\n .map(event => ({ ...event, retryCount: event.retryCount + 1 }))\n .sort((a, b) => a.timestamp - b.timestamp)\n : [];\n};\nconst getEventBuffer = ({ region, flushInterval, flushSize, bufferSize, credentials, identityId, resendLimit, userAgentValue, }) => {\n const sessionIdentityKey = [region, identityId].filter(x => !!x).join('-');\n const [cachedClient, cachedCredentials] = cachedClients[sessionIdentityKey] ?? [];\n let credentialsHaveChanged = false;\n // Check if credentials have changed for the cached client\n if (cachedClient) {\n credentialsHaveChanged = (0, utils_1.haveCredentialsChanged)(cachedCredentials, credentials);\n }\n if (!eventBufferMap[sessionIdentityKey] || credentialsHaveChanged) {\n const getKinesisClient = () => {\n if (!cachedClient || credentialsHaveChanged) {\n cachedClients[sessionIdentityKey] = [\n new client_kinesis_1.KinesisClient({\n credentials,\n region,\n customUserAgent: userAgentValue,\n }),\n credentials,\n ];\n }\n const [kinesisClient] = cachedClients[sessionIdentityKey];\n return events => submitEvents(events, kinesisClient, resendLimit);\n };\n // create new session\n eventBufferMap[sessionIdentityKey] = new utils_2.EventBuffer({\n flushInterval,\n flushSize,\n bufferSize,\n }, getKinesisClient);\n // release other sessions\n const releaseSessionKeys = Object.keys(eventBufferMap).filter(x => x !== sessionIdentityKey);\n for (const releaseSessionKey of releaseSessionKeys) {\n eventBufferMap[releaseSessionKey].flushAll().finally(() => {\n eventBufferMap[releaseSessionKey].release();\n delete eventBufferMap[releaseSessionKey];\n delete cachedClients[releaseSessionKey];\n });\n }\n }\n return eventBufferMap[sessionIdentityKey];\n};\nexports.getEventBuffer = getEventBuffer;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,cAAc,GAAG,KAAK,CAAC,CAAC;AAChC,MAAM,OAAO,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAAC;AAC7D,MAAM,gBAAgB,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;AAC5D,MAAM,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAC1C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,cAAc,GAAG,EAAE,CAAC;AAC1B,MAAM,aAAa,GAAG,EAAE,CAAC;AACzB,MAAM,8BAA8B,GAAG,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,gBAAgB,CAAC,iBAAiB,CAAC;AACtG,IAAI,UAAU,EAAE,UAAU;AAC1B,IAAI,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,KAAK,KAAK;AAClC,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IAAI,OAAO,CAAC,WAAW,CAAC;AACrE,YAAY,aAAa;AACzB,YAAY,SAAS;AACrB,YAAY,UAAU;AACtB,SAAS,EAAE,gBAAgB,CAAC,CAAC;AAC7B;AACA,QAAQ,MAAM,kBAAkB,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,kBAAkB,CAAC,CAAC;AACrG,QAAQ,KAAK,MAAM,iBAAiB,IAAI,kBAAkB,EAAE;AAC5D,YAAY,cAAc,CAAC,iBAAiB,CAAC,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,MAAM;AACvE,gBAAgB,cAAc,CAAC,iBAAiB,CAAC,CAAC,OAAO,EAAE,CAAC;AAC5D,gBAAgB,OAAO,cAAc,CAAC,iBAAiB,CAAC,CAAC;AACzD,gBAAgB,OAAO,aAAa,CAAC,iBAAiB,CAAC,CAAC;AACxD,aAAa,CAAC,CAAC;AACf,SAAS;AACT,KAAK;AACL,IAAI,OAAO,cAAc,CAAC,kBAAkB,CAAC,CAAC;AAC9C,CAAC,CAAC;AACF,OAAO,CAAC,cAAc,GAAG,cAAc;;"}
|
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
// SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.flushEvents = void 0;
|
|
7
|
-
const utils_1 = require("
|
|
8
|
-
const utils_2 = require("../../../utils");
|
|
9
|
-
const utils_3 = require("@aws-amplify/core/internals/utils");
|
|
7
|
+
const utils_1 = require("@aws-amplify/core/internals/utils");
|
|
10
8
|
const core_1 = require("@aws-amplify/core");
|
|
9
|
+
const utils_2 = require("../utils");
|
|
10
|
+
const utils_3 = require("../../../utils");
|
|
11
11
|
const logger = new core_1.ConsoleLogger('KinesisFirehose');
|
|
12
12
|
/**
|
|
13
13
|
* Flushes all buffered Kinesis events to the service.
|
|
@@ -17,9 +17,9 @@ const logger = new core_1.ConsoleLogger('KinesisFirehose');
|
|
|
17
17
|
* this API may not be included in the flush.
|
|
18
18
|
*/
|
|
19
19
|
const flushEvents = () => {
|
|
20
|
-
const { region, flushSize, flushInterval, bufferSize, resendLimit } = (0,
|
|
21
|
-
(0,
|
|
22
|
-
.then(({ credentials, identityId }) => (0,
|
|
20
|
+
const { region, flushSize, flushInterval, bufferSize, resendLimit } = (0, utils_2.resolveConfig)();
|
|
21
|
+
(0, utils_3.resolveCredentials)()
|
|
22
|
+
.then(({ credentials, identityId }) => (0, utils_2.getEventBuffer)({
|
|
23
23
|
region,
|
|
24
24
|
flushSize,
|
|
25
25
|
flushInterval,
|
|
@@ -27,10 +27,12 @@ const flushEvents = () => {
|
|
|
27
27
|
credentials,
|
|
28
28
|
identityId,
|
|
29
29
|
resendLimit,
|
|
30
|
-
userAgentValue: (0,
|
|
30
|
+
userAgentValue: (0, utils_3.getAnalyticsUserAgentString)(utils_1.AnalyticsAction.Record),
|
|
31
31
|
}))
|
|
32
32
|
.then(eventBuffer => eventBuffer.flushAll())
|
|
33
|
-
.catch(e =>
|
|
33
|
+
.catch(e => {
|
|
34
|
+
logger.warn('Failed to flush events.', e);
|
|
35
|
+
});
|
|
34
36
|
};
|
|
35
37
|
exports.flushEvents = flushEvents;
|
|
36
38
|
//# sourceMappingURL=flushEvents.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flushEvents.js","sources":["../../../../../src/providers/kinesis-firehose/apis/flushEvents.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.flushEvents = void 0;\nconst utils_1 = require(\"
|
|
1
|
+
{"version":3,"file":"flushEvents.js","sources":["../../../../../src/providers/kinesis-firehose/apis/flushEvents.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.flushEvents = void 0;\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst core_1 = require(\"@aws-amplify/core\");\nconst utils_2 = require(\"../utils\");\nconst utils_3 = require(\"../../../utils\");\nconst logger = new core_1.ConsoleLogger('KinesisFirehose');\n/**\n * Flushes all buffered Kinesis events to the service.\n *\n * @note\n * This API will make a best-effort attempt to flush events from the buffer. Events recorded immediately after invoking\n * this API may not be included in the flush.\n */\nconst flushEvents = () => {\n const { region, flushSize, flushInterval, bufferSize, resendLimit } = (0, utils_2.resolveConfig)();\n (0, utils_3.resolveCredentials)()\n .then(({ credentials, identityId }) => (0, utils_2.getEventBuffer)({\n region,\n flushSize,\n flushInterval,\n bufferSize,\n credentials,\n identityId,\n resendLimit,\n userAgentValue: (0, utils_3.getAnalyticsUserAgentString)(utils_1.AnalyticsAction.Record),\n }))\n .then(eventBuffer => eventBuffer.flushAll())\n .catch(e => {\n logger.warn('Failed to flush events.', e);\n });\n};\nexports.flushEvents = flushEvents;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,WAAW,GAAG,KAAK,CAAC,CAAC;AAC7B,MAAM,OAAO,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAAC;AAC7D,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AACpC,MAAM,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAC1C,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,aAAa,CAAC,iBAAiB,CAAC,CAAC;AAC3D;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,WAAW,GAAG,MAAM;AAC1B,IAAI,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,GAAG,IAAI,OAAO,CAAC,aAAa,GAAG,CAAC;AACvG,IAAI,IAAI,OAAO,CAAC,kBAAkB,GAAG;AACrC,SAAS,IAAI,CAAC,CAAC,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK,IAAI,OAAO,CAAC,cAAc,EAAE;AAC3E,QAAQ,MAAM;AACd,QAAQ,SAAS;AACjB,QAAQ,aAAa;AACrB,QAAQ,UAAU;AAClB,QAAQ,WAAW;AACnB,QAAQ,UAAU;AAClB,QAAQ,WAAW;AACnB,QAAQ,cAAc,EAAE,IAAI,OAAO,CAAC,2BAA2B,EAAE,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC;AAChG,KAAK,CAAC,CAAC;AACP,SAAS,IAAI,CAAC,WAAW,IAAI,WAAW,CAAC,QAAQ,EAAE,CAAC;AACpD,SAAS,KAAK,CAAC,CAAC,IAAI;AACpB,QAAQ,MAAM,CAAC,IAAI,CAAC,yBAAyB,EAAE,CAAC,CAAC,CAAC;AAClD,KAAK,CAAC,CAAC;AACP,CAAC,CAAC;AACF,OAAO,CAAC,WAAW,GAAG,WAAW;;"}
|
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
// SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.record = void 0;
|
|
7
|
-
const utils_1 = require("../utils");
|
|
8
|
-
const utils_2 = require("../../../utils");
|
|
9
7
|
const util_utf8_1 = require("@smithy/util-utf8");
|
|
10
|
-
const
|
|
8
|
+
const utils_1 = require("@aws-amplify/core/internals/utils");
|
|
11
9
|
const core_1 = require("@aws-amplify/core");
|
|
10
|
+
const utils_2 = require("../utils");
|
|
11
|
+
const utils_3 = require("../../../utils");
|
|
12
12
|
const logger = new core_1.ConsoleLogger('KinesisFirehose');
|
|
13
13
|
/**
|
|
14
14
|
* Record one analytic event and send it to Kinesis Data Firehose. Events will be buffered and periodically sent to
|
|
@@ -28,15 +28,15 @@ const logger = new core_1.ConsoleLogger('KinesisFirehose');
|
|
|
28
28
|
* ```
|
|
29
29
|
*/
|
|
30
30
|
const record = ({ streamName, data }) => {
|
|
31
|
-
if (!(0,
|
|
31
|
+
if (!(0, utils_3.isAnalyticsEnabled)()) {
|
|
32
32
|
logger.debug('Analytics is disabled, event will not be recorded.');
|
|
33
33
|
return;
|
|
34
34
|
}
|
|
35
35
|
const timestamp = Date.now();
|
|
36
|
-
const { region, bufferSize, flushSize, flushInterval, resendLimit } = (0,
|
|
37
|
-
(0,
|
|
36
|
+
const { region, bufferSize, flushSize, flushInterval, resendLimit } = (0, utils_2.resolveConfig)();
|
|
37
|
+
(0, utils_3.resolveCredentials)()
|
|
38
38
|
.then(({ credentials, identityId }) => {
|
|
39
|
-
const buffer = (0,
|
|
39
|
+
const buffer = (0, utils_2.getEventBuffer)({
|
|
40
40
|
region,
|
|
41
41
|
credentials,
|
|
42
42
|
identityId,
|
|
@@ -44,7 +44,7 @@ const record = ({ streamName, data }) => {
|
|
|
44
44
|
flushSize,
|
|
45
45
|
flushInterval,
|
|
46
46
|
resendLimit,
|
|
47
|
-
userAgentValue: (0,
|
|
47
|
+
userAgentValue: (0, utils_3.getAnalyticsUserAgentString)(utils_1.AnalyticsAction.Record),
|
|
48
48
|
});
|
|
49
49
|
buffer.append({
|
|
50
50
|
region,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"record.js","sources":["../../../../../src/providers/kinesis-firehose/apis/record.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.record = void 0;\nconst
|
|
1
|
+
{"version":3,"file":"record.js","sources":["../../../../../src/providers/kinesis-firehose/apis/record.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.record = void 0;\nconst util_utf8_1 = require(\"@smithy/util-utf8\");\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst core_1 = require(\"@aws-amplify/core\");\nconst utils_2 = require(\"../utils\");\nconst utils_3 = require(\"../../../utils\");\nconst logger = new core_1.ConsoleLogger('KinesisFirehose');\n/**\n * Record one analytic event and send it to Kinesis Data Firehose. Events will be buffered and periodically sent to\n * Kinesis Data Firehose.\n *\n * @param params The input object used to construct the request.\n *\n * @throws validation: {@link AnalyticsValidationErrorCode} - Thrown when the provided parameters or library\n * configuration is incorrect.\n *\n * @example\n * ```ts\n * record({\n * streamName: 'myFirehoseStream',\n * data: { } // The data blob to put into the record\n * });\n * ```\n */\nconst record = ({ streamName, data }) => {\n if (!(0, utils_3.isAnalyticsEnabled)()) {\n logger.debug('Analytics is disabled, event will not be recorded.');\n return;\n }\n const timestamp = Date.now();\n const { region, bufferSize, flushSize, flushInterval, resendLimit } = (0, utils_2.resolveConfig)();\n (0, utils_3.resolveCredentials)()\n .then(({ credentials, identityId }) => {\n const buffer = (0, utils_2.getEventBuffer)({\n region,\n credentials,\n identityId,\n bufferSize,\n flushSize,\n flushInterval,\n resendLimit,\n userAgentValue: (0, utils_3.getAnalyticsUserAgentString)(utils_1.AnalyticsAction.Record),\n });\n buffer.append({\n region,\n streamName,\n event: ArrayBuffer.isView(data) ? data : (0, util_utf8_1.fromUtf8)(JSON.stringify(data)),\n timestamp,\n retryCount: 0,\n });\n })\n .catch(e => {\n logger.warn('Failed to record event.', e);\n });\n};\nexports.record = record;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,CAAC;AACxB,MAAM,WAAW,GAAG,OAAO,CAAC,mBAAmB,CAAC,CA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,MAAM,CAAC;AACtB,YAAY,MAAM;AAClB,YAAY,UAAU;AACtB,YAAY,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,IAAI,WAAW,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AACpG,YAAY,SAAS;AACrB,YAAY,UAAU,EAAE,CAAC;AACzB,SAAS,CAAC,CAAC;AACX,KAAK,CAAC;AACN,SAAS,KAAK,CAAC,CAAC,IAAI;AACpB,QAAQ,MAAM,CAAC,IAAI,CAAC,yBAAyB,EAAE,CAAC,CAAC,CAAC;AAClD,KAAK,CAAC,CAAC;AACP,CAAC,CAAC;AACF,OAAO,CAAC,MAAM,GAAG,MAAM;;"}
|
|
@@ -26,7 +26,7 @@ const createPutRecordsBatchCommand = (streamName, events) => new client_firehose
|
|
|
26
26
|
const submitEvents = async (events, client, resendLimit) => {
|
|
27
27
|
const groupedByStreamName = Object.entries((0, utils_2.groupBy)(event => event.streamName, events));
|
|
28
28
|
const requests = groupedByStreamName
|
|
29
|
-
.map(([streamName,
|
|
29
|
+
.map(([streamName, groupedEvents]) => createPutRecordsBatchCommand(streamName, groupedEvents))
|
|
30
30
|
.map(command => client.send(command));
|
|
31
31
|
const responses = await Promise.allSettled(requests);
|
|
32
32
|
const failedEvents = responses
|
|
@@ -56,7 +56,7 @@ const getEventBuffer = ({ region, credentials, identityId, bufferSize, flushSize
|
|
|
56
56
|
credentials,
|
|
57
57
|
customUserAgent: userAgentValue,
|
|
58
58
|
}),
|
|
59
|
-
credentials
|
|
59
|
+
credentials,
|
|
60
60
|
];
|
|
61
61
|
}
|
|
62
62
|
const [firehoseClient] = cachedClients[sessionIdentityKey];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getEventBuffer.js","sources":["../../../../../src/providers/kinesis-firehose/utils/getEventBuffer.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.getEventBuffer = void 0;\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst client_firehose_1 = require(\"@aws-sdk/client-firehose\");\nconst utils_2 = require(\"../../../utils\");\n/**\n * These Records hold cached event buffers and AWS clients.\n * The hash key is determined by the region and session,\n * consisting of a combined value comprising [region, sessionToken, identityId].\n *\n * Only one active session should exist at any given moment.\n * When a new session is initiated, the previous ones should be released.\n * */\nconst eventBufferMap = {};\nconst cachedClients = {};\nconst createPutRecordsBatchCommand = (streamName, events) => new client_firehose_1.PutRecordBatchCommand({\n DeliveryStreamName: streamName,\n Records: events.map(event => ({\n Data: event.event,\n })),\n});\nconst submitEvents = async (events, client, resendLimit) => {\n const groupedByStreamName = Object.entries((0, utils_2.groupBy)(event => event.streamName, events));\n const requests = groupedByStreamName\n .map(([streamName,
|
|
1
|
+
{"version":3,"file":"getEventBuffer.js","sources":["../../../../../src/providers/kinesis-firehose/utils/getEventBuffer.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.getEventBuffer = void 0;\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst client_firehose_1 = require(\"@aws-sdk/client-firehose\");\nconst utils_2 = require(\"../../../utils\");\n/**\n * These Records hold cached event buffers and AWS clients.\n * The hash key is determined by the region and session,\n * consisting of a combined value comprising [region, sessionToken, identityId].\n *\n * Only one active session should exist at any given moment.\n * When a new session is initiated, the previous ones should be released.\n * */\nconst eventBufferMap = {};\nconst cachedClients = {};\nconst createPutRecordsBatchCommand = (streamName, events) => new client_firehose_1.PutRecordBatchCommand({\n DeliveryStreamName: streamName,\n Records: events.map(event => ({\n Data: event.event,\n })),\n});\nconst submitEvents = async (events, client, resendLimit) => {\n const groupedByStreamName = Object.entries((0, utils_2.groupBy)(event => event.streamName, events));\n const requests = groupedByStreamName\n .map(([streamName, groupedEvents]) => createPutRecordsBatchCommand(streamName, groupedEvents))\n .map(command => client.send(command));\n const responses = await Promise.allSettled(requests);\n const failedEvents = responses\n .map((response, i) => response.status === 'rejected' ? groupedByStreamName[i][1] : [])\n .flat();\n return resendLimit\n ? failedEvents\n .filter(event => event.retryCount < resendLimit)\n .map(event => ({ ...event, retryCount: event.retryCount + 1 }))\n .sort((a, b) => a.timestamp - b.timestamp)\n : [];\n};\nconst getEventBuffer = ({ region, credentials, identityId, bufferSize, flushSize, flushInterval, resendLimit, userAgentValue, }) => {\n const sessionIdentityKey = [region, identityId].filter(id => !!id).join('-');\n const [cachedClient, cachedCredentials] = cachedClients[sessionIdentityKey] ?? [];\n let credentialsHaveChanged = false;\n // Check if credentials have changed for the cached client\n if (cachedClient) {\n credentialsHaveChanged = (0, utils_1.haveCredentialsChanged)(cachedCredentials, credentials);\n }\n if (!eventBufferMap[sessionIdentityKey] || credentialsHaveChanged) {\n const getClient = () => {\n if (!cachedClient || credentialsHaveChanged) {\n cachedClients[sessionIdentityKey] = [\n new client_firehose_1.FirehoseClient({\n region,\n credentials,\n customUserAgent: userAgentValue,\n }),\n credentials,\n ];\n }\n const [firehoseClient] = cachedClients[sessionIdentityKey];\n return events => submitEvents(events, firehoseClient, resendLimit);\n };\n eventBufferMap[sessionIdentityKey] =\n new utils_2.EventBuffer({\n bufferSize,\n flushSize,\n flushInterval,\n }, getClient);\n const releaseSessionKeys = Object.keys(eventBufferMap).filter(key => key !== sessionIdentityKey);\n for (const releaseSessionKey of releaseSessionKeys) {\n eventBufferMap[releaseSessionKey].flushAll().finally(() => {\n eventBufferMap[releaseSessionKey].release();\n delete eventBufferMap[releaseSessionKey];\n delete cachedClients[releaseSessionKey];\n });\n }\n }\n return eventBufferMap[sessionIdentityKey];\n};\nexports.getEventBuffer = getEventBuffer;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,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AC;AACF,OAAO,CAAC,cAAc,GAAG,cAAc;;"}
|
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
// SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.flushEvents = void 0;
|
|
7
|
-
const utils_1 = require("
|
|
8
|
-
const utils_2 = require("../../../utils");
|
|
9
|
-
const utils_3 = require("@aws-amplify/core/internals/utils");
|
|
7
|
+
const utils_1 = require("@aws-amplify/core/internals/utils");
|
|
10
8
|
const core_1 = require("@aws-amplify/core");
|
|
9
|
+
const utils_2 = require("../utils");
|
|
10
|
+
const utils_3 = require("../../../utils");
|
|
11
11
|
const logger = new core_1.ConsoleLogger('Personalize');
|
|
12
12
|
/**
|
|
13
13
|
* Flushes all buffered Personalize events to the service.
|
|
@@ -17,19 +17,21 @@ const logger = new core_1.ConsoleLogger('Personalize');
|
|
|
17
17
|
* this API may not be included in the flush.
|
|
18
18
|
*/
|
|
19
19
|
const flushEvents = () => {
|
|
20
|
-
const { region, flushSize, bufferSize, flushInterval } = (0,
|
|
21
|
-
(0,
|
|
22
|
-
.then(({ credentials, identityId }) => (0,
|
|
20
|
+
const { region, flushSize, bufferSize, flushInterval } = (0, utils_2.resolveConfig)();
|
|
21
|
+
(0, utils_3.resolveCredentials)()
|
|
22
|
+
.then(({ credentials, identityId }) => (0, utils_2.getEventBuffer)({
|
|
23
23
|
region,
|
|
24
24
|
flushSize,
|
|
25
25
|
flushInterval,
|
|
26
26
|
bufferSize,
|
|
27
27
|
credentials,
|
|
28
28
|
identityId,
|
|
29
|
-
userAgentValue: (0,
|
|
29
|
+
userAgentValue: (0, utils_3.getAnalyticsUserAgentString)(utils_1.AnalyticsAction.Record),
|
|
30
30
|
}))
|
|
31
31
|
.then(eventBuffer => eventBuffer.flushAll())
|
|
32
|
-
.catch(e =>
|
|
32
|
+
.catch(e => {
|
|
33
|
+
logger.warn('Failed to flush events', e);
|
|
34
|
+
});
|
|
33
35
|
};
|
|
34
36
|
exports.flushEvents = flushEvents;
|
|
35
37
|
//# sourceMappingURL=flushEvents.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flushEvents.js","sources":["../../../../../src/providers/personalize/apis/flushEvents.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.flushEvents = void 0;\nconst utils_1 = require(\"
|
|
1
|
+
{"version":3,"file":"flushEvents.js","sources":["../../../../../src/providers/personalize/apis/flushEvents.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.flushEvents = void 0;\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst core_1 = require(\"@aws-amplify/core\");\nconst utils_2 = require(\"../utils\");\nconst utils_3 = require(\"../../../utils\");\nconst logger = new core_1.ConsoleLogger('Personalize');\n/**\n * Flushes all buffered Personalize events to the service.\n *\n * @note\n * This API will make a best-effort attempt to flush events from the buffer. Events recorded immediately after invoking\n * this API may not be included in the flush.\n */\nconst flushEvents = () => {\n const { region, flushSize, bufferSize, flushInterval } = (0, utils_2.resolveConfig)();\n (0, utils_3.resolveCredentials)()\n .then(({ credentials, identityId }) => (0, utils_2.getEventBuffer)({\n region,\n flushSize,\n flushInterval,\n bufferSize,\n credentials,\n identityId,\n userAgentValue: (0, utils_3.getAnalyticsUserAgentString)(utils_1.AnalyticsAction.Record),\n }))\n .then(eventBuffer => eventBuffer.flushAll())\n .catch(e => {\n logger.warn('Failed to flush events', e);\n });\n};\nexports.flushEvents = flushEvents;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC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.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.record = void 0;
|
|
7
|
-
const utils_1 = require("
|
|
8
|
-
const utils_2 = require("../../../utils");
|
|
9
|
-
const utils_3 = require("@aws-amplify/core/internals/utils");
|
|
7
|
+
const utils_1 = require("@aws-amplify/core/internals/utils");
|
|
10
8
|
const core_1 = require("@aws-amplify/core");
|
|
9
|
+
const utils_2 = require("../utils");
|
|
10
|
+
const utils_3 = require("../../../utils");
|
|
11
11
|
const constants_1 = require("../utils/constants");
|
|
12
12
|
const logger = new core_1.ConsoleLogger('Personalize');
|
|
13
13
|
/**
|
|
@@ -36,33 +36,33 @@ const logger = new core_1.ConsoleLogger('Personalize');
|
|
|
36
36
|
* @returns void
|
|
37
37
|
*/
|
|
38
38
|
const record = ({ userId, eventId, eventType, properties, }) => {
|
|
39
|
-
if (!(0,
|
|
39
|
+
if (!(0, utils_3.isAnalyticsEnabled)()) {
|
|
40
40
|
logger.debug('Analytics is disabled, event will not be recorded.');
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
|
-
const { region, trackingId, bufferSize, flushSize, flushInterval } = (0,
|
|
44
|
-
(0,
|
|
43
|
+
const { region, trackingId, bufferSize, flushSize, flushInterval } = (0, utils_2.resolveConfig)();
|
|
44
|
+
(0, utils_3.resolveCredentials)()
|
|
45
45
|
.then(async ({ credentials, identityId }) => {
|
|
46
46
|
const timestamp = Date.now();
|
|
47
|
-
const { sessionId: cachedSessionId, userId: cachedUserId } = await (0,
|
|
47
|
+
const { sessionId: cachedSessionId, userId: cachedUserId } = await (0, utils_2.resolveCachedSession)();
|
|
48
48
|
if (eventType === constants_1.IDENTIFY_EVENT_TYPE) {
|
|
49
|
-
(0,
|
|
49
|
+
(0, utils_2.updateCachedSession)(typeof properties.userId === 'string' ? properties.userId : '', cachedSessionId, cachedUserId);
|
|
50
50
|
}
|
|
51
|
-
else if (
|
|
52
|
-
(0,
|
|
51
|
+
else if (userId) {
|
|
52
|
+
(0, utils_2.updateCachedSession)(userId, cachedSessionId, cachedUserId);
|
|
53
53
|
}
|
|
54
|
-
const { sessionId: updatedSessionId, userId: updatedUserId } = await (0,
|
|
55
|
-
const eventBuffer = (0,
|
|
54
|
+
const { sessionId: updatedSessionId, userId: updatedUserId } = await (0, utils_2.resolveCachedSession)();
|
|
55
|
+
const eventBuffer = (0, utils_2.getEventBuffer)({
|
|
56
56
|
region,
|
|
57
57
|
flushSize,
|
|
58
58
|
flushInterval,
|
|
59
59
|
bufferSize,
|
|
60
60
|
credentials,
|
|
61
61
|
identityId,
|
|
62
|
-
userAgentValue: (0,
|
|
62
|
+
userAgentValue: (0, utils_3.getAnalyticsUserAgentString)(utils_1.AnalyticsAction.Record),
|
|
63
63
|
});
|
|
64
64
|
if (eventType === constants_1.MEDIA_AUTO_TRACK_EVENT_TYPE) {
|
|
65
|
-
(0,
|
|
65
|
+
(0, utils_2.autoTrackMedia)({
|
|
66
66
|
trackingId,
|
|
67
67
|
sessionId: updatedSessionId,
|
|
68
68
|
userId: updatedUserId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"record.js","sources":["../../../../../src/providers/personalize/apis/record.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.record = void 0;\nconst utils_1 = require(\"
|
|
1
|
+
{"version":3,"file":"record.js","sources":["../../../../../src/providers/personalize/apis/record.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.record = void 0;\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst core_1 = require(\"@aws-amplify/core\");\nconst utils_2 = require(\"../utils\");\nconst utils_3 = require(\"../../../utils\");\nconst constants_1 = require(\"../utils/constants\");\nconst logger = new core_1.ConsoleLogger('Personalize');\n/**\n * Record one analytic event and send it to Personalize. Events will be buffered and periodically sent to Amazon\n * Personalize.\n *\n * For more examples, you can refer to {@link https://docs.amplify.aws/javascript/build-a-backend/more-features/analytics/personalize-recommendations/#working-with-the-api the API usage guidance.}\n *\n * @param input The input object used to construct the request.\n *\n * @throws validation: {@link AnalyticsValidationErrorCode} - Thrown when the provided parameters or library\n * configuration is incorrect.\n *\n * @example\n * ```ts\n * // Record an `Identify` event to Personalize.\n * record({\n * eventType: \"Identify\",\n * properties: {\n * userId: \"<USER_ID>\"\n * }\n * });\n * ```\n * @param input - The event to record.\n *\n * @returns void\n */\nconst record = ({ userId, eventId, eventType, properties, }) => {\n if (!(0, utils_3.isAnalyticsEnabled)()) {\n logger.debug('Analytics is disabled, event will not be recorded.');\n return;\n }\n const { region, trackingId, bufferSize, flushSize, flushInterval } = (0, utils_2.resolveConfig)();\n (0, utils_3.resolveCredentials)()\n .then(async ({ credentials, identityId }) => {\n const timestamp = Date.now();\n const { sessionId: cachedSessionId, userId: cachedUserId } = await (0, utils_2.resolveCachedSession)();\n if (eventType === constants_1.IDENTIFY_EVENT_TYPE) {\n (0, utils_2.updateCachedSession)(typeof properties.userId === 'string' ? properties.userId : '', cachedSessionId, cachedUserId);\n }\n else if (userId) {\n (0, utils_2.updateCachedSession)(userId, cachedSessionId, cachedUserId);\n }\n const { sessionId: updatedSessionId, userId: updatedUserId } = await (0, utils_2.resolveCachedSession)();\n const eventBuffer = (0, utils_2.getEventBuffer)({\n region,\n flushSize,\n flushInterval,\n bufferSize,\n credentials,\n identityId,\n userAgentValue: (0, utils_3.getAnalyticsUserAgentString)(utils_1.AnalyticsAction.Record),\n });\n if (eventType === constants_1.MEDIA_AUTO_TRACK_EVENT_TYPE) {\n (0, utils_2.autoTrackMedia)({\n trackingId,\n sessionId: updatedSessionId,\n userId: updatedUserId,\n event: {\n eventId,\n eventType,\n properties,\n },\n }, eventBuffer);\n }\n else {\n eventBuffer.append({\n trackingId,\n sessionId: updatedSessionId,\n userId: updatedUserId,\n event: {\n eventId,\n eventType,\n properties,\n },\n timestamp,\n });\n }\n if (eventBuffer.length >= bufferSize) {\n eventBuffer.flushAll();\n }\n })\n .catch(e => {\n logger.warn('Failed to record event.', e);\n });\n};\nexports.record = record;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,CAAC;AACxB,MAAM,OAAO,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAAC;AAC7D,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AACpC,MAAM,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAC1C,MAAM,WAAW,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAClD,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC;AACvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,MAAM,GAAG,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,GAAG,KAAK;AAChE,IAAI,IAAI,CAAC,IAAI,OAAO,CAAC,kBAAkB,GAAG,EAAE;AAC5C,QAAQ,MAAM,CAAC,KAAK,CAAC,oDAAoD,CAAC,CAAC;AAC3E,QAAQ,OAAO;AACf,KAAK;AACL,IAAI,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,GAAG,IAAI,OAAO,CAAC,aAAa,GAAG,CAAC;AACtG,IAAI,IAAI,OAAO,CAAC,kBAAkB,GAAG;AACrC,SAA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AAoB,OAAO;AAC3B,oBAAoB,SAAS;AAC7B,oBAAoB,UAAU;AAC9B,iBAAiB;AACjB,aAAa,EAAE,WAAW,CAAC,CAAC;AAC5B,SAAS;AACT,aAAa;AACb,YAAY,WAAW,CAAC,MAAM,CAAC;AAC/B,gBAAgB,UAAU;AAC1B,gBAAgB,SAAS,EAAE,gBAAgB;AAC3C,gBAAgB,MAAM,EAAE,aAAa;AACrC,gBAAgB,KAAK,EAAE;AACvB,oBAAoB,OAAO;AAC3B,oBAAoB,SAAS;AAC7B,oBAAoB,UAAU;AAC9B,iBAAiB;AACjB,gBAAgB,SAAS;AACzB,aAAa,CAAC,CAAC;AACf,SAAS;AACT,QAAQ,IAAI,WAAW,CAAC,MAAM,IAAI,UAAU,EAAE;AAC9C,YAAY,WAAW,CAAC,QAAQ,EAAE,CAAC;AACnC,SAAS;AACT,KAAK,CAAC;AACN,SAAS,KAAK,CAAC,CAAC,IAAI;AACpB,QAAQ,MAAM,CAAC,IAAI,CAAC,yBAAyB,EAAE,CAAC,CAAC,CAAC;AAClD,KAAK,CAAC,CAAC;AACP,CAAC,CAAC;AACF,OAAO,CAAC,MAAM,GAAG,MAAM;;"}
|
|
@@ -46,12 +46,11 @@ const startIframeAutoTracking = (element, recordEvent) => {
|
|
|
46
46
|
recordEvent(EVENT_TYPE.TIME_WATCHED, mediaProperties());
|
|
47
47
|
}
|
|
48
48
|
}, 3000);
|
|
49
|
-
element.addEventListener('unload', () =>
|
|
50
|
-
|
|
49
|
+
element.addEventListener('unload', () => {
|
|
50
|
+
clearInterval(timer);
|
|
51
|
+
});
|
|
51
52
|
window.onYouTubeIframeAPIReady = () => {
|
|
52
|
-
// @ts-ignore
|
|
53
53
|
delete window.onYouTubeIframeAPIReady;
|
|
54
|
-
// @ts-ignore
|
|
55
54
|
player = new window.YT.Player(element.id, {
|
|
56
55
|
events: {
|
|
57
56
|
onStateChange: (event) => {
|
|
@@ -60,7 +59,6 @@ const startIframeAutoTracking = (element, recordEvent) => {
|
|
|
60
59
|
1: EVENT_TYPE.PLAY,
|
|
61
60
|
2: EVENT_TYPE.PAUSE,
|
|
62
61
|
};
|
|
63
|
-
// @ts-ignore
|
|
64
62
|
const eventType = iframeEventMapping[event.data];
|
|
65
63
|
switch (eventType) {
|
|
66
64
|
case EVENT_TYPE.ENDED:
|
|
@@ -90,7 +88,9 @@ const startHTMLMediaAutoTracking = (element, recordEvent) => {
|
|
|
90
88
|
recordEvent(EVENT_TYPE.TIME_WATCHED, mediaProperties());
|
|
91
89
|
}
|
|
92
90
|
}, 3000);
|
|
93
|
-
element.addEventListener('unload', () =>
|
|
91
|
+
element.addEventListener('unload', () => {
|
|
92
|
+
clearInterval(timer);
|
|
93
|
+
});
|
|
94
94
|
element.addEventListener(HTML5_MEDIA_EVENT.PLAY, () => {
|
|
95
95
|
isPlaying = true;
|
|
96
96
|
recordEvent(EVENT_TYPE.PLAY, mediaProperties());
|
|
@@ -106,7 +106,7 @@ const startHTMLMediaAutoTracking = (element, recordEvent) => {
|
|
|
106
106
|
};
|
|
107
107
|
const checkElementLoaded = (interval, maxTries) => {
|
|
108
108
|
let retryCount = 0;
|
|
109
|
-
const wait = () => new Promise(
|
|
109
|
+
const wait = () => new Promise(resolve => setTimeout(resolve, interval));
|
|
110
110
|
const check = async (elementId) => {
|
|
111
111
|
if (retryCount >= maxTries) {
|
|
112
112
|
return false;
|
|
@@ -118,7 +118,7 @@ const checkElementLoaded = (interval, maxTries) => {
|
|
|
118
118
|
else {
|
|
119
119
|
retryCount += 1;
|
|
120
120
|
await wait();
|
|
121
|
-
return
|
|
121
|
+
return check(elementId);
|
|
122
122
|
}
|
|
123
123
|
};
|
|
124
124
|
return check;
|