@aws-amplify/analytics 7.0.1-api-v6-models.9351bcf.0 → 7.0.1-api-v6-models.58f2536.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.
Files changed (87) hide show
  1. package/lib/apis/disable.js +1 -1
  2. package/lib/apis/enable.js +1 -1
  3. package/lib/errors/AnalyticsError.js +7 -11
  4. package/lib/errors/assertValidationError.js +6 -6
  5. package/lib/errors/validation.js +10 -11
  6. package/lib/providers/kinesis/apis/flushEvents.js +20 -23
  7. package/lib/providers/kinesis/apis/record.js +24 -26
  8. package/lib/providers/kinesis/utils/getEventBuffer.js +39 -70
  9. package/lib/providers/kinesis/utils/resolveConfig.js +14 -13
  10. package/lib/providers/kinesis-firehose/apis/flushEvents.js +19 -22
  11. package/lib/providers/kinesis-firehose/apis/record.js +22 -24
  12. package/lib/providers/kinesis-firehose/utils/getEventBuffer.js +39 -68
  13. package/lib/providers/kinesis-firehose/utils/resolveConfig.js +14 -13
  14. package/lib/providers/personalize/apis/flushEvents.js +18 -21
  15. package/lib/providers/personalize/apis/record.js +55 -71
  16. package/lib/providers/personalize/utils/autoTrackMedia.js +96 -98
  17. package/lib/providers/personalize/utils/cachedSession.js +30 -42
  18. package/lib/providers/personalize/utils/getEventBuffer.js +35 -62
  19. package/lib/providers/personalize/utils/resolveConfig.js +14 -13
  20. package/lib/providers/pinpoint/apis/configureAutoTrack.js +6 -6
  21. package/lib/providers/pinpoint/apis/flushEvents.js +10 -13
  22. package/lib/providers/pinpoint/apis/identifyUser.js +18 -30
  23. package/lib/providers/pinpoint/apis/record.js +15 -16
  24. package/lib/providers/pinpoint/utils/resolveConfig.js +5 -6
  25. package/lib/providers/pinpoint/utils/resolveCredentials.js +7 -15
  26. package/lib/setupTests.js +1 -1
  27. package/lib/trackers/EventTracker.js +39 -45
  28. package/lib/trackers/PageViewTracker.js +41 -45
  29. package/lib/trackers/SessionTracker.js +25 -31
  30. package/lib/trackers/SessionTracker.native.js +25 -31
  31. package/lib/tsconfig.tsbuildinfo +1 -1
  32. package/lib/utils/eventBuffer/EventBuffer.js +34 -62
  33. package/lib/utils/groupBy.js +4 -7
  34. package/lib/utils/resolveCredentials.js +7 -15
  35. package/lib/utils/statusHelpers.js +4 -4
  36. package/lib/utils/trackerConfigHelpers.js +2 -2
  37. package/lib/utils/trackerConfigHelpers.native.js +2 -2
  38. package/lib/utils/trackerHelpers.js +5 -5
  39. package/lib/utils/userAgent.js +3 -3
  40. package/lib-esm/apis/disable.js +1 -1
  41. package/lib-esm/apis/enable.js +1 -1
  42. package/lib-esm/errors/AnalyticsError.js +6 -11
  43. package/lib-esm/errors/assertValidationError.js +4 -4
  44. package/lib-esm/errors/validation.js +10 -11
  45. package/lib-esm/providers/kinesis/apis/flushEvents.js +15 -18
  46. package/lib-esm/providers/kinesis/apis/record.js +18 -20
  47. package/lib-esm/providers/kinesis/utils/constants.js +1 -1
  48. package/lib-esm/providers/kinesis/utils/getEventBuffer.js +37 -68
  49. package/lib-esm/providers/kinesis/utils/resolveConfig.js +11 -10
  50. package/lib-esm/providers/kinesis-firehose/apis/flushEvents.js +15 -18
  51. package/lib-esm/providers/kinesis-firehose/apis/record.js +17 -19
  52. package/lib-esm/providers/kinesis-firehose/utils/constants.js +1 -1
  53. package/lib-esm/providers/kinesis-firehose/utils/getEventBuffer.js +37 -66
  54. package/lib-esm/providers/kinesis-firehose/utils/resolveConfig.js +11 -10
  55. package/lib-esm/providers/personalize/apis/flushEvents.js +14 -17
  56. package/lib-esm/providers/personalize/apis/record.js +50 -66
  57. package/lib-esm/providers/personalize/utils/autoTrackMedia.js +94 -96
  58. package/lib-esm/providers/personalize/utils/cachedSession.js +28 -40
  59. package/lib-esm/providers/personalize/utils/constants.js +4 -4
  60. package/lib-esm/providers/personalize/utils/getEventBuffer.js +33 -60
  61. package/lib-esm/providers/personalize/utils/resolveConfig.js +11 -10
  62. package/lib-esm/providers/pinpoint/apis/configureAutoTrack.js +4 -4
  63. package/lib-esm/providers/pinpoint/apis/flushEvents.js +5 -8
  64. package/lib-esm/providers/pinpoint/apis/identifyUser.js +14 -26
  65. package/lib-esm/providers/pinpoint/apis/record.js +9 -10
  66. package/lib-esm/providers/pinpoint/utils/resolveConfig.js +3 -4
  67. package/lib-esm/providers/pinpoint/utils/resolveCredentials.js +5 -13
  68. package/lib-esm/setupTests.js +1 -1
  69. package/lib-esm/trackers/EventTracker.js +37 -44
  70. package/lib-esm/trackers/PageViewTracker.js +39 -44
  71. package/lib-esm/trackers/SessionTracker.js +22 -29
  72. package/lib-esm/trackers/SessionTracker.native.js +22 -29
  73. package/lib-esm/tsconfig.tsbuildinfo +1 -1
  74. package/lib-esm/utils/eventBuffer/EventBuffer.js +33 -62
  75. package/lib-esm/utils/groupBy.js +4 -7
  76. package/lib-esm/utils/resolveCredentials.js +5 -13
  77. package/lib-esm/utils/statusHelpers.js +4 -4
  78. package/lib-esm/utils/trackerConfigHelpers.js +1 -1
  79. package/lib-esm/utils/trackerConfigHelpers.native.js +1 -1
  80. package/lib-esm/utils/trackerHelpers.js +4 -4
  81. package/lib-esm/utils/userAgent.js +2 -2
  82. package/package.json +6 -9
  83. package/src/providers/kinesis/utils/getEventBuffer.ts +6 -7
  84. package/src/providers/kinesis-firehose/utils/getEventBuffer.ts +6 -7
  85. package/src/providers/personalize/utils/getEventBuffer.ts +6 -7
  86. package/src/trackers/SessionTracker.native.ts +2 -3
  87. package/src/trackers/SessionTracker.ts +2 -3
@@ -3,7 +3,7 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.disable = void 0;
6
- var utils_1 = require("../utils");
6
+ const utils_1 = require("../utils");
7
7
  /**
8
8
  * Disables the Analytics category.
9
9
  *
@@ -3,7 +3,7 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.enable = void 0;
6
- var utils_1 = require("../utils");
6
+ const utils_1 = require("../utils");
7
7
  /**
8
8
  * Enables the Analytics category to permit the transmission of events.
9
9
  *
@@ -3,21 +3,17 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.AnalyticsError = void 0;
6
- var tslib_1 = require("tslib");
7
- var utils_1 = require("@aws-amplify/core/internals/utils");
6
+ const utils_1 = require("@aws-amplify/core/internals/utils");
8
7
  /**
9
8
  * @internal
10
9
  */
11
- var AnalyticsError = /** @class */ (function (_super) {
12
- tslib_1.__extends(AnalyticsError, _super);
13
- function AnalyticsError(params) {
14
- var _this = _super.call(this, params) || this;
10
+ class AnalyticsError extends utils_1.AmplifyError {
11
+ constructor(params) {
12
+ super(params);
15
13
  // Hack for making the custom error class work when transpiled to es5
16
14
  // TODO: Delete the following 2 lines after we change the build target to >= es2015
17
- _this.constructor = AnalyticsError;
18
- Object.setPrototypeOf(_this, AnalyticsError.prototype);
19
- return _this;
15
+ this.constructor = AnalyticsError;
16
+ Object.setPrototypeOf(this, AnalyticsError.prototype);
20
17
  }
21
- return AnalyticsError;
22
- }(utils_1.AmplifyError));
18
+ }
23
19
  exports.AnalyticsError = AnalyticsError;
@@ -3,18 +3,18 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.assertValidationError = void 0;
6
- var AnalyticsError_1 = require("./AnalyticsError");
7
- var validation_1 = require("./validation");
6
+ const AnalyticsError_1 = require("./AnalyticsError");
7
+ const validation_1 = require("./validation");
8
8
  /**
9
9
  * @internal
10
10
  */
11
11
  function assertValidationError(assertion, name, message) {
12
- var _a = validation_1.validationErrorMap[name], defaultMessage = _a.message, recoverySuggestion = _a.recoverySuggestion;
12
+ const { message: defaultMessage, recoverySuggestion } = validation_1.validationErrorMap[name];
13
13
  if (!assertion) {
14
14
  throw new AnalyticsError_1.AnalyticsError({
15
- name: name,
16
- message: message !== null && message !== void 0 ? message : defaultMessage,
17
- recoverySuggestion: recoverySuggestion,
15
+ name,
16
+ message: message ?? defaultMessage,
17
+ recoverySuggestion,
18
18
  });
19
19
  }
20
20
  }
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
3
  // SPDX-License-Identifier: Apache-2.0
4
- var _a;
5
4
  Object.defineProperty(exports, "__esModule", { value: true });
6
5
  exports.validationErrorMap = exports.AnalyticsValidationErrorCode = void 0;
7
6
  var AnalyticsValidationErrorCode;
@@ -15,29 +14,29 @@ var AnalyticsValidationErrorCode;
15
14
  AnalyticsValidationErrorCode["NoTrackingId"] = "NoTrackingId";
16
15
  AnalyticsValidationErrorCode["InvalidFlushSize"] = "InvalidFlushSize";
17
16
  })(AnalyticsValidationErrorCode = exports.AnalyticsValidationErrorCode || (exports.AnalyticsValidationErrorCode = {}));
18
- exports.validationErrorMap = (_a = {},
19
- _a[AnalyticsValidationErrorCode.NoAppId] = {
17
+ exports.validationErrorMap = {
18
+ [AnalyticsValidationErrorCode.NoAppId]: {
20
19
  message: 'Missing application id.',
21
20
  },
22
- _a[AnalyticsValidationErrorCode.NoCredentials] = {
21
+ [AnalyticsValidationErrorCode.NoCredentials]: {
23
22
  message: 'Credentials should not be empty.',
24
23
  },
25
- _a[AnalyticsValidationErrorCode.NoEventName] = {
24
+ [AnalyticsValidationErrorCode.NoEventName]: {
26
25
  message: 'Events must specify a name.',
27
26
  },
28
- _a[AnalyticsValidationErrorCode.NoRegion] = {
27
+ [AnalyticsValidationErrorCode.NoRegion]: {
29
28
  message: 'Missing region.',
30
29
  },
31
- _a[AnalyticsValidationErrorCode.InvalidTracker] = {
30
+ [AnalyticsValidationErrorCode.InvalidTracker]: {
32
31
  message: 'Invalid tracker type specified.',
33
32
  },
34
- _a[AnalyticsValidationErrorCode.UnsupportedPlatform] = {
33
+ [AnalyticsValidationErrorCode.UnsupportedPlatform]: {
35
34
  message: 'Only session tracking is supported on React Native.',
36
35
  },
37
- _a[AnalyticsValidationErrorCode.InvalidFlushSize] = {
36
+ [AnalyticsValidationErrorCode.InvalidFlushSize]: {
38
37
  message: 'Invalid FlushSize, it should be smaller than BufferSize',
39
38
  },
40
- _a[AnalyticsValidationErrorCode.NoTrackingId] = {
39
+ [AnalyticsValidationErrorCode.NoTrackingId]: {
41
40
  message: 'A trackingId is required to use Amazon Personalize',
42
41
  },
43
- _a);
42
+ };
@@ -3,12 +3,12 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.flushEvents = void 0;
6
- var resolveConfig_1 = require("../utils/resolveConfig");
7
- var utils_1 = require("../../../utils");
8
- var getEventBuffer_1 = require("../utils/getEventBuffer");
9
- var utils_2 = require("@aws-amplify/core/internals/utils");
10
- var core_1 = require("@aws-amplify/core");
11
- var logger = new core_1.ConsoleLogger('Kinesis');
6
+ const resolveConfig_1 = require("../utils/resolveConfig");
7
+ const utils_1 = require("../../../utils");
8
+ const getEventBuffer_1 = require("../utils/getEventBuffer");
9
+ const utils_2 = require("@aws-amplify/core/internals/utils");
10
+ const core_1 = require("@aws-amplify/core");
11
+ const logger = new core_1.ConsoleLogger('Kinesis');
12
12
  /**
13
13
  * Flushes all buffered Kinesis events to the service.
14
14
  *
@@ -16,23 +16,20 @@ var logger = new core_1.ConsoleLogger('Kinesis');
16
16
  * This API will make a best-effort attempt to flush events from the buffer. Events recorded immediately after invoking
17
17
  * this API may not be included in the flush.
18
18
  */
19
- var flushEvents = function () {
20
- var _a = (0, resolveConfig_1.resolveConfig)(), region = _a.region, flushSize = _a.flushSize, flushInterval = _a.flushInterval, bufferSize = _a.bufferSize, resendLimit = _a.resendLimit;
19
+ const flushEvents = () => {
20
+ const { region, flushSize, flushInterval, bufferSize, resendLimit } = (0, resolveConfig_1.resolveConfig)();
21
21
  (0, utils_1.resolveCredentials)()
22
- .then(function (_a) {
23
- var credentials = _a.credentials, identityId = _a.identityId;
24
- return (0, getEventBuffer_1.getEventBuffer)({
25
- region: region,
26
- flushSize: flushSize,
27
- flushInterval: flushInterval,
28
- bufferSize: bufferSize,
29
- credentials: credentials,
30
- identityId: identityId,
31
- resendLimit: resendLimit,
32
- userAgentValue: (0, utils_1.getAnalyticsUserAgentString)(utils_2.AnalyticsAction.Record),
33
- });
34
- })
35
- .then(function (eventBuffer) { return eventBuffer.flushAll(); })
36
- .catch(function (e) { return logger.warn('Failed to flush events.', e); });
22
+ .then(({ credentials, identityId }) => (0, getEventBuffer_1.getEventBuffer)({
23
+ region,
24
+ flushSize,
25
+ flushInterval,
26
+ bufferSize,
27
+ credentials,
28
+ identityId,
29
+ resendLimit,
30
+ userAgentValue: (0, utils_1.getAnalyticsUserAgentString)(utils_2.AnalyticsAction.Record),
31
+ }))
32
+ .then(eventBuffer => eventBuffer.flushAll())
33
+ .catch(e => logger.warn('Failed to flush events.', e));
37
34
  };
38
35
  exports.flushEvents = flushEvents;
@@ -3,44 +3,42 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.record = void 0;
6
- var getEventBuffer_1 = require("../utils/getEventBuffer");
7
- var resolveConfig_1 = require("../utils/resolveConfig");
8
- var utils_1 = require("../../../utils");
9
- var util_utf8_1 = require("@smithy/util-utf8");
10
- var utils_2 = require("@aws-amplify/core/internals/utils");
11
- var core_1 = require("@aws-amplify/core");
12
- var logger = new core_1.ConsoleLogger('Kinesis');
13
- var record = function (_a) {
14
- var streamName = _a.streamName, partitionKey = _a.partitionKey, data = _a.data;
6
+ const getEventBuffer_1 = require("../utils/getEventBuffer");
7
+ const resolveConfig_1 = require("../utils/resolveConfig");
8
+ const utils_1 = require("../../../utils");
9
+ const util_utf8_1 = require("@smithy/util-utf8");
10
+ const utils_2 = require("@aws-amplify/core/internals/utils");
11
+ const core_1 = require("@aws-amplify/core");
12
+ const logger = new core_1.ConsoleLogger('Kinesis');
13
+ const record = ({ streamName, partitionKey, data, }) => {
15
14
  if (!(0, utils_1.isAnalyticsEnabled)()) {
16
15
  logger.debug('Analytics is disabled, event will not be recorded.');
17
16
  return;
18
17
  }
19
- var timestamp = Date.now();
20
- var _b = (0, resolveConfig_1.resolveConfig)(), region = _b.region, bufferSize = _b.bufferSize, flushSize = _b.flushSize, flushInterval = _b.flushInterval, resendLimit = _b.resendLimit;
18
+ const timestamp = Date.now();
19
+ const { region, bufferSize, flushSize, flushInterval, resendLimit } = (0, resolveConfig_1.resolveConfig)();
21
20
  (0, utils_1.resolveCredentials)()
22
- .then(function (_a) {
23
- var credentials = _a.credentials, identityId = _a.identityId;
24
- var buffer = (0, getEventBuffer_1.getEventBuffer)({
25
- region: region,
26
- bufferSize: bufferSize,
27
- flushSize: flushSize,
28
- flushInterval: flushInterval,
29
- credentials: credentials,
30
- identityId: identityId,
31
- resendLimit: resendLimit,
21
+ .then(({ credentials, identityId }) => {
22
+ const buffer = (0, getEventBuffer_1.getEventBuffer)({
23
+ region,
24
+ bufferSize,
25
+ flushSize,
26
+ flushInterval,
27
+ credentials,
28
+ identityId,
29
+ resendLimit,
32
30
  userAgentValue: (0, utils_1.getAnalyticsUserAgentString)(utils_2.AnalyticsAction.Record),
33
31
  });
34
32
  buffer.append({
35
- region: region,
36
- streamName: streamName,
37
- partitionKey: partitionKey,
33
+ region,
34
+ streamName,
35
+ partitionKey,
38
36
  event: ArrayBuffer.isView(data) ? data : (0, util_utf8_1.fromUtf8)(JSON.stringify(data)),
39
- timestamp: timestamp,
37
+ timestamp,
40
38
  retryCount: 0,
41
39
  });
42
40
  })
43
- .catch(function (e) {
41
+ .catch(e => {
44
42
  // An error occured while fetching credentials or persisting the event to the buffer
45
43
  logger.warn('Failed to record event.', e);
46
44
  });
@@ -3,9 +3,8 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.getEventBuffer = void 0;
6
- var tslib_1 = require("tslib");
7
- var utils_1 = require("../../../utils");
8
- var client_kinesis_1 = require("@aws-sdk/client-kinesis");
6
+ const utils_1 = require("../../../utils");
7
+ const client_kinesis_1 = require("@aws-sdk/client-kinesis");
9
8
  /**
10
9
  * These Records hold cached event buffers and AWS clients.
11
10
  * The hash key is determined by the region and session,
@@ -14,88 +13,58 @@ var client_kinesis_1 = require("@aws-sdk/client-kinesis");
14
13
  * Only one active session should exist at any given moment.
15
14
  * When a new session is initiated, the previous ones should be released.
16
15
  * */
17
- var eventBufferMap = {};
18
- var cachedClients = {};
19
- var createKinesisPutRecordsCommand = function (streamName, events) {
20
- return new client_kinesis_1.PutRecordsCommand({
21
- StreamName: streamName,
22
- Records: events.map(function (event) { return ({
23
- PartitionKey: event.partitionKey,
24
- Data: event.event,
25
- }); }),
26
- });
16
+ const eventBufferMap = {};
17
+ const cachedClients = {};
18
+ const createKinesisPutRecordsCommand = (streamName, events) => new client_kinesis_1.PutRecordsCommand({
19
+ StreamName: streamName,
20
+ Records: events.map(event => ({
21
+ PartitionKey: event.partitionKey,
22
+ Data: event.event,
23
+ })),
24
+ });
25
+ const submitEvents = async (events, client, resendLimit) => {
26
+ const groupedByStreamName = Object.entries((0, utils_1.groupBy)(event => event.streamName, events));
27
+ const requests = groupedByStreamName
28
+ .map(([streamName, events]) => createKinesisPutRecordsCommand(streamName, events))
29
+ .map(command => client.send(command));
30
+ const responses = await Promise.allSettled(requests);
31
+ const failedEvents = responses
32
+ .map((response, i) => response.status === 'rejected' ? groupedByStreamName[i][1] : [])
33
+ .flat();
34
+ return resendLimit
35
+ ? failedEvents
36
+ .filter(event => event.retryCount < resendLimit)
37
+ .map(event => ({ ...event, retryCount: event.retryCount + 1 }))
38
+ .sort((a, b) => a.timestamp - b.timestamp)
39
+ : [];
27
40
  };
28
- var submitEvents = function (events, client, resendLimit) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
29
- var groupedByStreamName, requests, responses, failedEvents;
30
- return tslib_1.__generator(this, function (_a) {
31
- switch (_a.label) {
32
- case 0:
33
- groupedByStreamName = Object.entries((0, utils_1.groupBy)(function (event) { return event.streamName; }, events));
34
- requests = groupedByStreamName
35
- .map(function (_a) {
36
- var _b = tslib_1.__read(_a, 2), streamName = _b[0], events = _b[1];
37
- return createKinesisPutRecordsCommand(streamName, events);
38
- })
39
- .map(function (command) { return client.send(command); });
40
- return [4 /*yield*/, Promise.allSettled(requests)];
41
- case 1:
42
- responses = _a.sent();
43
- failedEvents = responses
44
- .map(function (response, i) {
45
- return response.status === 'rejected' ? groupedByStreamName[i][1] : [];
46
- })
47
- .flat();
48
- return [2 /*return*/, resendLimit
49
- ? failedEvents
50
- .filter(function (event) { return event.retryCount < resendLimit; })
51
- .map(function (event) { return (tslib_1.__assign(tslib_1.__assign({}, event), { retryCount: event.retryCount + 1 })); })
52
- .sort(function (a, b) { return a.timestamp - b.timestamp; })
53
- : []];
54
- }
55
- });
56
- }); };
57
- var getEventBuffer = function (_a) {
58
- var e_1, _b;
59
- var region = _a.region, flushInterval = _a.flushInterval, flushSize = _a.flushSize, bufferSize = _a.bufferSize, credentials = _a.credentials, identityId = _a.identityId, resendLimit = _a.resendLimit, userAgentValue = _a.userAgentValue;
60
- var sessionToken = credentials.sessionToken;
61
- var sessionIdentityKey = [region, sessionToken, identityId]
62
- .filter(function (x) { return !!x; })
63
- .join('-');
41
+ const getEventBuffer = ({ region, flushInterval, flushSize, bufferSize, credentials, identityId, resendLimit, userAgentValue, }) => {
42
+ const sessionIdentityKey = [region, identityId].filter(x => !!x).join('-');
64
43
  if (!eventBufferMap[sessionIdentityKey]) {
65
- var getKinesisClient = function () {
44
+ const getKinesisClient = () => {
66
45
  if (!cachedClients[sessionIdentityKey]) {
67
46
  cachedClients[sessionIdentityKey] = new client_kinesis_1.KinesisClient({
68
- credentials: credentials,
69
- region: region,
47
+ credentials,
48
+ region,
70
49
  customUserAgent: userAgentValue,
71
50
  });
72
51
  }
73
- return function (events) {
74
- return submitEvents(events, cachedClients[sessionIdentityKey], resendLimit);
75
- };
52
+ return events => submitEvents(events, cachedClients[sessionIdentityKey], resendLimit);
76
53
  };
77
54
  // create new session
78
55
  eventBufferMap[sessionIdentityKey] = new utils_1.EventBuffer({
79
- flushInterval: flushInterval,
80
- flushSize: flushSize,
81
- bufferSize: bufferSize,
56
+ flushInterval,
57
+ flushSize,
58
+ bufferSize,
82
59
  }, getKinesisClient);
83
60
  // release other sessions
84
- var releaseSessionKeys = Object.keys(eventBufferMap).filter(function (x) { return x !== sessionIdentityKey; });
85
- try {
86
- for (var releaseSessionKeys_1 = tslib_1.__values(releaseSessionKeys), releaseSessionKeys_1_1 = releaseSessionKeys_1.next(); !releaseSessionKeys_1_1.done; releaseSessionKeys_1_1 = releaseSessionKeys_1.next()) {
87
- var releaseSessionKey = releaseSessionKeys_1_1.value;
61
+ const releaseSessionKeys = Object.keys(eventBufferMap).filter(x => x !== sessionIdentityKey);
62
+ for (const releaseSessionKey of releaseSessionKeys) {
63
+ eventBufferMap[releaseSessionKey].flushAll().finally(() => {
88
64
  eventBufferMap[releaseSessionKey].release();
89
65
  delete eventBufferMap[releaseSessionKey];
90
66
  delete cachedClients[releaseSessionKey];
91
- }
92
- }
93
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
94
- finally {
95
- try {
96
- if (releaseSessionKeys_1_1 && !releaseSessionKeys_1_1.done && (_b = releaseSessionKeys_1.return)) _b.call(releaseSessionKeys_1);
97
- }
98
- finally { if (e_1) throw e_1.error; }
67
+ });
99
68
  }
100
69
  }
101
70
  return eventBufferMap[sessionIdentityKey];
@@ -3,22 +3,23 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.resolveConfig = void 0;
6
- var tslib_1 = require("tslib");
7
- var core_1 = require("@aws-amplify/core");
8
- var errors_1 = require("../../../errors");
9
- var constants_1 = require("./constants");
10
- var resolveConfig = function () {
11
- var _a;
12
- var config = (_a = core_1.Amplify.getConfig().Analytics) === null || _a === void 0 ? void 0 : _a.Kinesis;
13
- var _b = tslib_1.__assign(tslib_1.__assign({}, constants_1.DEFAULT_KINESIS_CONFIG), config), region = _b.region, _c = _b.bufferSize, bufferSize = _c === void 0 ? constants_1.DEFAULT_KINESIS_CONFIG.bufferSize : _c, _d = _b.flushSize, flushSize = _d === void 0 ? constants_1.DEFAULT_KINESIS_CONFIG.flushSize : _d, _e = _b.flushInterval, flushInterval = _e === void 0 ? constants_1.DEFAULT_KINESIS_CONFIG.flushInterval : _e, resendLimit = _b.resendLimit;
6
+ const core_1 = require("@aws-amplify/core");
7
+ const errors_1 = require("../../../errors");
8
+ const constants_1 = require("./constants");
9
+ const resolveConfig = () => {
10
+ const config = core_1.Amplify.getConfig().Analytics?.Kinesis;
11
+ const { region, bufferSize = constants_1.DEFAULT_KINESIS_CONFIG.bufferSize, flushSize = constants_1.DEFAULT_KINESIS_CONFIG.flushSize, flushInterval = constants_1.DEFAULT_KINESIS_CONFIG.flushInterval, resendLimit, } = {
12
+ ...constants_1.DEFAULT_KINESIS_CONFIG,
13
+ ...config,
14
+ };
14
15
  (0, errors_1.assertValidationError)(!!region, errors_1.AnalyticsValidationErrorCode.NoRegion);
15
16
  (0, errors_1.assertValidationError)(flushSize < bufferSize, errors_1.AnalyticsValidationErrorCode.InvalidFlushSize);
16
17
  return {
17
- region: region,
18
- bufferSize: bufferSize,
19
- flushSize: flushSize,
20
- flushInterval: flushInterval,
21
- resendLimit: resendLimit,
18
+ region,
19
+ bufferSize,
20
+ flushSize,
21
+ flushInterval,
22
+ resendLimit,
22
23
  };
23
24
  };
24
25
  exports.resolveConfig = resolveConfig;
@@ -3,11 +3,11 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.flushEvents = void 0;
6
- var utils_1 = require("../utils");
7
- var utils_2 = require("../../../utils");
8
- var utils_3 = require("@aws-amplify/core/internals/utils");
9
- var core_1 = require("@aws-amplify/core");
10
- var logger = new core_1.ConsoleLogger('KinesisFirehose');
6
+ const utils_1 = require("../utils");
7
+ const utils_2 = require("../../../utils");
8
+ const utils_3 = require("@aws-amplify/core/internals/utils");
9
+ const core_1 = require("@aws-amplify/core");
10
+ const logger = new core_1.ConsoleLogger('KinesisFirehose');
11
11
  /**
12
12
  * Flushes all buffered Kinesis events to the service.
13
13
  *
@@ -15,23 +15,20 @@ var logger = new core_1.ConsoleLogger('KinesisFirehose');
15
15
  * This API will make a best-effort attempt to flush events from the buffer. Events recorded immediately after invoking
16
16
  * this API may not be included in the flush.
17
17
  */
18
- var flushEvents = function () {
19
- var _a = (0, utils_1.resolveConfig)(), region = _a.region, flushSize = _a.flushSize, flushInterval = _a.flushInterval, bufferSize = _a.bufferSize, resendLimit = _a.resendLimit;
18
+ const flushEvents = () => {
19
+ const { region, flushSize, flushInterval, bufferSize, resendLimit } = (0, utils_1.resolveConfig)();
20
20
  (0, utils_2.resolveCredentials)()
21
- .then(function (_a) {
22
- var credentials = _a.credentials, identityId = _a.identityId;
23
- return (0, utils_1.getEventBuffer)({
24
- region: region,
25
- flushSize: flushSize,
26
- flushInterval: flushInterval,
27
- bufferSize: bufferSize,
28
- credentials: credentials,
29
- identityId: identityId,
30
- resendLimit: resendLimit,
31
- userAgentValue: (0, utils_2.getAnalyticsUserAgentString)(utils_3.AnalyticsAction.Record),
32
- });
33
- })
34
- .then(function (eventBuffer) { return eventBuffer.flushAll(); })
35
- .catch(function (e) { return logger.warn('Failed to flush events.', e); });
21
+ .then(({ credentials, identityId }) => (0, utils_1.getEventBuffer)({
22
+ region,
23
+ flushSize,
24
+ flushInterval,
25
+ bufferSize,
26
+ credentials,
27
+ identityId,
28
+ resendLimit,
29
+ userAgentValue: (0, utils_2.getAnalyticsUserAgentString)(utils_3.AnalyticsAction.Record),
30
+ }))
31
+ .then(eventBuffer => eventBuffer.flushAll())
32
+ .catch(e => logger.warn('Failed to flush events.', e));
36
33
  };
37
34
  exports.flushEvents = flushEvents;
@@ -3,42 +3,40 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.record = void 0;
6
- var utils_1 = require("../utils");
7
- var utils_2 = require("../../../utils");
8
- var util_utf8_1 = require("@smithy/util-utf8");
9
- var utils_3 = require("@aws-amplify/core/internals/utils");
10
- var core_1 = require("@aws-amplify/core");
11
- var logger = new core_1.ConsoleLogger('KinesisFirehose');
12
- var record = function (_a) {
13
- var streamName = _a.streamName, data = _a.data;
6
+ const utils_1 = require("../utils");
7
+ const utils_2 = require("../../../utils");
8
+ const util_utf8_1 = require("@smithy/util-utf8");
9
+ const utils_3 = require("@aws-amplify/core/internals/utils");
10
+ const core_1 = require("@aws-amplify/core");
11
+ const logger = new core_1.ConsoleLogger('KinesisFirehose');
12
+ const record = ({ streamName, data }) => {
14
13
  if (!(0, utils_2.isAnalyticsEnabled)()) {
15
14
  logger.debug('Analytics is disabled, event will not be recorded.');
16
15
  return;
17
16
  }
18
- var timestamp = Date.now();
19
- var _b = (0, utils_1.resolveConfig)(), region = _b.region, bufferSize = _b.bufferSize, flushSize = _b.flushSize, flushInterval = _b.flushInterval, resendLimit = _b.resendLimit;
17
+ const timestamp = Date.now();
18
+ const { region, bufferSize, flushSize, flushInterval, resendLimit } = (0, utils_1.resolveConfig)();
20
19
  (0, utils_2.resolveCredentials)()
21
- .then(function (_a) {
22
- var credentials = _a.credentials, identityId = _a.identityId;
23
- var buffer = (0, utils_1.getEventBuffer)({
24
- region: region,
25
- credentials: credentials,
26
- identityId: identityId,
27
- bufferSize: bufferSize,
28
- flushSize: flushSize,
29
- flushInterval: flushInterval,
30
- resendLimit: resendLimit,
20
+ .then(({ credentials, identityId }) => {
21
+ const buffer = (0, utils_1.getEventBuffer)({
22
+ region,
23
+ credentials,
24
+ identityId,
25
+ bufferSize,
26
+ flushSize,
27
+ flushInterval,
28
+ resendLimit,
31
29
  userAgentValue: (0, utils_2.getAnalyticsUserAgentString)(utils_3.AnalyticsAction.Record),
32
30
  });
33
31
  buffer.append({
34
- region: region,
35
- streamName: streamName,
32
+ region,
33
+ streamName,
36
34
  event: ArrayBuffer.isView(data) ? data : (0, util_utf8_1.fromUtf8)(JSON.stringify(data)),
37
- timestamp: timestamp,
35
+ timestamp,
38
36
  retryCount: 0,
39
37
  });
40
38
  })
41
- .catch(function (e) {
39
+ .catch(e => {
42
40
  logger.warn('Failed to record event.', e);
43
41
  });
44
42
  };