@aws-amplify/analytics 7.0.1-api-v6-models.9351bcf.0 → 7.0.1-api-v6-models.891fe0d.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,54 +3,42 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.updateCachedSession = exports.resolveCachedSession = void 0;
6
- var tslib_1 = require("tslib");
7
- var core_1 = require("@aws-amplify/core");
8
- var utils_1 = require("@aws-amplify/core/internals/utils");
9
- var PERSONALIZE_CACHE_USERID = '_awsct_uid';
10
- var PERSONALIZE_CACHE_SESSIONID = '_awsct_sid';
11
- var DEFAULT_CACHE_PREFIX = 'personalize';
12
- var DELIMITER = '.';
13
- var CACHE_EXPIRY_IN_DAYS = 7;
14
- var normalize = function (key) {
15
- return [key, (0, utils_1.isBrowser)() ? window.location.host : DEFAULT_CACHE_PREFIX].join(DELIMITER);
16
- };
17
- var getCache = function (key) { return core_1.Cache.getItem(normalize(key)); };
18
- var setCache = function (key, value) {
19
- var expiredAt = new Date(Date.now() + 3600000 * 24 * CACHE_EXPIRY_IN_DAYS);
6
+ const core_1 = require("@aws-amplify/core");
7
+ const utils_1 = require("@aws-amplify/core/internals/utils");
8
+ const PERSONALIZE_CACHE_USERID = '_awsct_uid';
9
+ const PERSONALIZE_CACHE_SESSIONID = '_awsct_sid';
10
+ const DEFAULT_CACHE_PREFIX = 'personalize';
11
+ const DELIMITER = '.';
12
+ const CACHE_EXPIRY_IN_DAYS = 7;
13
+ const normalize = (key) => [key, (0, utils_1.isBrowser)() ? window.location.host : DEFAULT_CACHE_PREFIX].join(DELIMITER);
14
+ const getCache = (key) => core_1.Cache.getItem(normalize(key));
15
+ const setCache = (key, value) => {
16
+ const expiredAt = new Date(Date.now() + 3600000 * 24 * CACHE_EXPIRY_IN_DAYS);
20
17
  core_1.Cache.setItem(normalize(key), value, {
21
18
  expires: expiredAt.getTime(),
22
19
  });
23
20
  };
24
- var resolveCachedSession = function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
25
- var sessionId, userId;
26
- return tslib_1.__generator(this, function (_a) {
27
- switch (_a.label) {
28
- case 0: return [4 /*yield*/, getCache(PERSONALIZE_CACHE_SESSIONID)];
29
- case 1:
30
- sessionId = _a.sent();
31
- if (!sessionId) {
32
- sessionId = (0, utils_1.amplifyUuid)();
33
- setCache(PERSONALIZE_CACHE_SESSIONID, sessionId);
34
- }
35
- return [4 /*yield*/, getCache(PERSONALIZE_CACHE_USERID)];
36
- case 2:
37
- userId = _a.sent();
38
- return [2 /*return*/, {
39
- sessionId: sessionId,
40
- userId: userId,
41
- }];
42
- }
43
- });
44
- }); };
21
+ const resolveCachedSession = async () => {
22
+ let sessionId = await getCache(PERSONALIZE_CACHE_SESSIONID);
23
+ if (!sessionId) {
24
+ sessionId = (0, utils_1.amplifyUuid)();
25
+ setCache(PERSONALIZE_CACHE_SESSIONID, sessionId);
26
+ }
27
+ const userId = await getCache(PERSONALIZE_CACHE_USERID);
28
+ return {
29
+ sessionId,
30
+ userId,
31
+ };
32
+ };
45
33
  exports.resolveCachedSession = resolveCachedSession;
46
- var updateCachedSession = function (newUserId, currentSessionId, currentUserId) {
47
- var isNoCachedSession = !currentSessionId;
48
- var isSignOutCase = !newUserId && !currentUserId;
49
- var isSwitchUserCase = !!newUserId && !!currentUserId && newUserId !== currentUserId;
50
- var isRequireNewSession = isNoCachedSession || isSignOutCase || isSwitchUserCase;
51
- var isRequireUpdateSession = !!currentSessionId && !currentUserId && !!newUserId;
34
+ const updateCachedSession = (newUserId, currentSessionId, currentUserId) => {
35
+ const isNoCachedSession = !currentSessionId;
36
+ const isSignOutCase = !newUserId && !currentUserId;
37
+ const isSwitchUserCase = !!newUserId && !!currentUserId && newUserId !== currentUserId;
38
+ const isRequireNewSession = isNoCachedSession || isSignOutCase || isSwitchUserCase;
39
+ const isRequireUpdateSession = !!currentSessionId && !currentUserId && !!newUserId;
52
40
  if (isRequireNewSession) {
53
- var newSessionId = (0, utils_1.amplifyUuid)();
41
+ const newSessionId = (0, utils_1.amplifyUuid)();
54
42
  setCache(PERSONALIZE_CACHE_SESSIONID, newSessionId);
55
43
  setCache(PERSONALIZE_CACHE_USERID, newUserId);
56
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_personalize_events_1 = require("@aws-sdk/client-personalize-events");
6
+ const utils_1 = require("../../../utils");
7
+ const client_personalize_events_1 = require("@aws-sdk/client-personalize-events");
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,85 +13,59 @@ var client_personalize_events_1 = require("@aws-sdk/client-personalize-events");
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 DELIMITER = '#';
20
- var createPutEventsCommand = function (ids, events) {
21
- var _a = tslib_1.__read(ids.split(DELIMITER), 3), trackingId = _a[0], sessionId = _a[1], userId = _a[2];
16
+ const eventBufferMap = {};
17
+ const cachedClients = {};
18
+ const DELIMITER = '#';
19
+ const createPutEventsCommand = (ids, events) => {
20
+ const [trackingId, sessionId, userId] = ids.split(DELIMITER);
22
21
  return new client_personalize_events_1.PutEventsCommand({
23
- trackingId: trackingId,
24
- sessionId: sessionId,
25
- userId: userId,
26
- eventList: events.map(function (event) { return ({
22
+ trackingId,
23
+ sessionId,
24
+ userId,
25
+ eventList: events.map(event => ({
27
26
  eventId: event.event.eventId,
28
27
  eventType: event.event.eventType,
29
28
  properties: JSON.stringify(event.event.properties),
30
29
  sentAt: new Date(event.timestamp),
31
- }); }),
30
+ })),
32
31
  });
33
32
  };
34
- var submitEvents = function (events, client) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
35
- var groupedByIds, requests;
36
- return tslib_1.__generator(this, function (_a) {
37
- switch (_a.label) {
38
- case 0:
39
- groupedByIds = Object.entries((0, utils_1.groupBy)(function (event) {
40
- return [event.trackingId, event.sessionId, event.userId]
41
- .filter(function (id) { return !!id; })
42
- .join(DELIMITER);
43
- }, events));
44
- requests = groupedByIds
45
- .map(function (_a) {
46
- var _b = tslib_1.__read(_a, 2), ids = _b[0], events = _b[1];
47
- return createPutEventsCommand(ids, events);
48
- })
49
- .map(function (command) { return client.send(command); });
50
- return [4 /*yield*/, Promise.allSettled(requests)];
51
- case 1:
52
- _a.sent();
53
- return [2 /*return*/, Promise.resolve([])];
54
- }
55
- });
56
- }); };
57
- var getEventBuffer = function (_a) {
58
- var e_1, _b;
59
- var region = _a.region, flushSize = _a.flushSize, flushInterval = _a.flushInterval, bufferSize = _a.bufferSize, credentials = _a.credentials, identityId = _a.identityId, userAgentValue = _a.userAgentValue;
60
- var sessionToken = credentials.sessionToken;
61
- var sessionIdentityKey = [region, sessionToken, identityId]
62
- .filter(function (x) { return !!x; })
63
- .join('-');
33
+ const submitEvents = async (events, client) => {
34
+ const groupedByIds = Object.entries((0, utils_1.groupBy)(event => [event.trackingId, event.sessionId, event.userId]
35
+ .filter(id => !!id)
36
+ .join(DELIMITER), events));
37
+ const requests = groupedByIds
38
+ .map(([ids, events]) => createPutEventsCommand(ids, events))
39
+ .map(command => client.send(command));
40
+ await Promise.allSettled(requests);
41
+ return Promise.resolve([]);
42
+ };
43
+ const getEventBuffer = ({ region, flushSize, flushInterval, bufferSize, credentials, identityId, userAgentValue, }) => {
44
+ const sessionIdentityKey = [region, identityId].filter(x => !!x).join('-');
64
45
  if (!eventBufferMap[sessionIdentityKey]) {
65
- var getClient = function () {
46
+ const getClient = () => {
66
47
  if (!cachedClients[sessionIdentityKey]) {
67
48
  cachedClients[sessionIdentityKey] = new client_personalize_events_1.PersonalizeEventsClient({
68
- region: region,
69
- credentials: credentials,
49
+ region,
50
+ credentials,
70
51
  customUserAgent: userAgentValue,
71
52
  });
72
53
  }
73
- return function (events) { return submitEvents(events, cachedClients[sessionIdentityKey]); };
54
+ return events => submitEvents(events, cachedClients[sessionIdentityKey]);
74
55
  };
75
56
  eventBufferMap[sessionIdentityKey] =
76
57
  new utils_1.EventBuffer({
77
- bufferSize: bufferSize,
78
- flushSize: flushSize,
79
- flushInterval: flushInterval,
58
+ bufferSize,
59
+ flushSize,
60
+ flushInterval,
80
61
  }, getClient);
81
- var releaseSessionKeys = Object.keys(eventBufferMap).filter(function (key) { return key !== sessionIdentityKey; });
82
- try {
83
- for (var releaseSessionKeys_1 = tslib_1.__values(releaseSessionKeys), releaseSessionKeys_1_1 = releaseSessionKeys_1.next(); !releaseSessionKeys_1_1.done; releaseSessionKeys_1_1 = releaseSessionKeys_1.next()) {
84
- var releaseSessionKey = releaseSessionKeys_1_1.value;
62
+ const releaseSessionKeys = Object.keys(eventBufferMap).filter(key => key !== sessionIdentityKey);
63
+ for (const releaseSessionKey of releaseSessionKeys) {
64
+ eventBufferMap[releaseSessionKey].flushAll().finally(() => {
85
65
  eventBufferMap[releaseSessionKey].release();
86
66
  delete eventBufferMap[releaseSessionKey];
87
67
  delete cachedClients[releaseSessionKey];
88
- }
89
- }
90
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
91
- finally {
92
- try {
93
- if (releaseSessionKeys_1_1 && !releaseSessionKeys_1_1.done && (_b = releaseSessionKeys_1.return)) _b.call(releaseSessionKeys_1);
94
- }
95
- finally { if (e_1) throw e_1.error; }
68
+ });
96
69
  }
97
70
  }
98
71
  return eventBufferMap[sessionIdentityKey];
@@ -3,23 +3,24 @@
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 _1 = require("./");
10
- var resolveConfig = function () {
11
- var _a;
12
- var config = (_a = core_1.Amplify.getConfig().Analytics) === null || _a === void 0 ? void 0 : _a.Personalize;
13
- var _b = tslib_1.__assign(tslib_1.__assign({}, _1.DEFAULT_PERSONALIZE_CONFIG), config), region = _b.region, trackingId = _b.trackingId, _c = _b.flushSize, flushSize = _c === void 0 ? _1.DEFAULT_PERSONALIZE_CONFIG.flushSize : _c, _d = _b.flushInterval, flushInterval = _d === void 0 ? _1.DEFAULT_PERSONALIZE_CONFIG.flushInterval : _d;
6
+ const core_1 = require("@aws-amplify/core");
7
+ const errors_1 = require("../../../errors");
8
+ const _1 = require("./");
9
+ const resolveConfig = () => {
10
+ const config = core_1.Amplify.getConfig().Analytics?.Personalize;
11
+ const { region, trackingId, flushSize = _1.DEFAULT_PERSONALIZE_CONFIG.flushSize, flushInterval = _1.DEFAULT_PERSONALIZE_CONFIG.flushInterval, } = {
12
+ ..._1.DEFAULT_PERSONALIZE_CONFIG,
13
+ ...config,
14
+ };
14
15
  (0, errors_1.assertValidationError)(!!region, errors_1.AnalyticsValidationErrorCode.NoRegion);
15
16
  (0, errors_1.assertValidationError)(!!trackingId, errors_1.AnalyticsValidationErrorCode.NoTrackingId);
16
- (0, errors_1.assertValidationError)(flushSize <= _1.PERSONALIZE_FLUSH_SIZE_MAX, errors_1.AnalyticsValidationErrorCode.InvalidFlushSize, "FlushSize for Personalize should be less or equal than ".concat(_1.PERSONALIZE_FLUSH_SIZE_MAX));
17
+ (0, errors_1.assertValidationError)(flushSize <= _1.PERSONALIZE_FLUSH_SIZE_MAX, errors_1.AnalyticsValidationErrorCode.InvalidFlushSize, `FlushSize for Personalize should be less or equal than ${_1.PERSONALIZE_FLUSH_SIZE_MAX}`);
17
18
  return {
18
- region: region,
19
- trackingId: trackingId,
19
+ region,
20
+ trackingId,
20
21
  bufferSize: flushSize + 1,
21
- flushSize: flushSize,
22
- flushInterval: flushInterval,
22
+ flushSize,
23
+ flushInterval,
23
24
  };
24
25
  };
25
26
  exports.resolveConfig = resolveConfig;
@@ -3,15 +3,15 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.configureAutoTrack = void 0;
6
- var utils_1 = require("../../../utils");
7
- var record_1 = require("./record");
6
+ const utils_1 = require("../../../utils");
7
+ const record_1 = require("./record");
8
8
  // Configured Tracker instances for Pinpoint
9
- var configuredTrackers = {};
9
+ const configuredTrackers = {};
10
10
  // Callback that will emit an appropriate event to Pinpoint when required by the Tracker
11
- var emitTrackingEvent = function (eventName, attributes) {
11
+ const emitTrackingEvent = (eventName, attributes) => {
12
12
  (0, record_1.record)({
13
13
  name: eventName,
14
- attributes: attributes,
14
+ attributes,
15
15
  });
16
16
  };
17
17
  /**
@@ -27,7 +27,7 @@ var emitTrackingEvent = function (eventName, attributes) {
27
27
  * @throws validation: {@link AnalyticsValidationErrorCode} - Thrown when the provided parameters or library
28
28
  * configuration is incorrect.
29
29
  */
30
- var configureAutoTrack = function (input) {
30
+ const configureAutoTrack = (input) => {
31
31
  (0, utils_1.validateTrackerConfiguration)(input);
32
32
  // Initialize or update this provider's trackers
33
33
  (0, utils_1.updateProviderTrackers)(input, emitTrackingEvent, configuredTrackers);
@@ -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 utils_1 = require("../utils");
7
- var pinpoint_1 = require("@aws-amplify/core/internals/providers/pinpoint");
8
- var utils_2 = require("@aws-amplify/core/internals/utils");
9
- var core_1 = require("@aws-amplify/core");
10
- var utils_3 = require("../../../utils");
11
- var logger = new core_1.ConsoleLogger('Analytics');
6
+ const utils_1 = require("../utils");
7
+ const pinpoint_1 = require("@aws-amplify/core/internals/providers/pinpoint");
8
+ const utils_2 = require("@aws-amplify/core/internals/utils");
9
+ const core_1 = require("@aws-amplify/core");
10
+ const utils_3 = require("../../../utils");
11
+ const logger = new core_1.ConsoleLogger('Analytics');
12
12
  /**
13
13
  * Flushes all buffered Pinpoint events to the service.
14
14
  *
@@ -16,13 +16,10 @@ var logger = new core_1.ConsoleLogger('Analytics');
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, utils_1.resolveConfig)(), appId = _a.appId, region = _a.region;
19
+ const flushEvents = () => {
20
+ const { appId, region } = (0, utils_1.resolveConfig)();
21
21
  (0, utils_1.resolveCredentials)()
22
- .then(function (_a) {
23
- var credentials = _a.credentials, identityId = _a.identityId;
24
- return (0, pinpoint_1.flushEvents)(appId, region, credentials, identityId, (0, utils_3.getAnalyticsUserAgentString)(utils_2.AnalyticsAction.Record));
25
- })
26
- .catch(function (e) { return logger.warn('Failed to flush events', e); });
22
+ .then(({ credentials, identityId }) => (0, pinpoint_1.flushEvents)(appId, region, credentials, identityId, (0, utils_3.getAnalyticsUserAgentString)(utils_2.AnalyticsAction.Record)))
23
+ .catch(e => logger.warn('Failed to flush events', e));
27
24
  };
28
25
  exports.flushEvents = flushEvents;
@@ -3,11 +3,10 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.identifyUser = void 0;
6
- var tslib_1 = require("tslib");
7
- var utils_1 = require("@aws-amplify/core/internals/utils");
8
- var pinpoint_1 = require("@aws-amplify/core/internals/providers/pinpoint");
9
- var utils_2 = require("../../../utils");
10
- var utils_3 = require("../utils");
6
+ const utils_1 = require("@aws-amplify/core/internals/utils");
7
+ const pinpoint_1 = require("@aws-amplify/core/internals/providers/pinpoint");
8
+ const utils_2 = require("../../../utils");
9
+ const utils_3 = require("../utils");
11
10
  /**
12
11
  * Sends information about a user to Pinpoint. Sending user information allows you to associate a user to their user
13
12
  * profile and activities or actions in your application. Activity can be tracked across devices & platforms by using
@@ -53,31 +52,20 @@ var utils_3 = require("../utils");
53
52
  * }
54
53
  * });
55
54
  */
56
- var identifyUser = function (_a) {
57
- var userId = _a.userId, userProfile = _a.userProfile, options = _a.options;
58
- return tslib_1.__awaiter(void 0, void 0, void 0, function () {
59
- var _b, credentials, identityId, _c, appId, region, userAttributes;
60
- return tslib_1.__generator(this, function (_d) {
61
- switch (_d.label) {
62
- case 0: return [4 /*yield*/, (0, utils_3.resolveCredentials)()];
63
- case 1:
64
- _b = _d.sent(), credentials = _b.credentials, identityId = _b.identityId;
65
- _c = (0, utils_3.resolveConfig)(), appId = _c.appId, region = _c.region;
66
- userAttributes = (options !== null && options !== void 0 ? options : {}).userAttributes;
67
- (0, pinpoint_1.updateEndpoint)({
68
- appId: appId,
69
- category: 'Analytics',
70
- credentials: credentials,
71
- identityId: identityId,
72
- region: region,
73
- userAttributes: userAttributes,
74
- userId: userId,
75
- userProfile: userProfile,
76
- userAgentValue: (0, utils_2.getAnalyticsUserAgentString)(utils_1.AnalyticsAction.IdentifyUser),
77
- });
78
- return [2 /*return*/];
79
- }
80
- });
55
+ const identifyUser = async ({ userId, userProfile, options, }) => {
56
+ const { credentials, identityId } = await (0, utils_3.resolveCredentials)();
57
+ const { appId, region } = (0, utils_3.resolveConfig)();
58
+ const { userAttributes } = options ?? {};
59
+ (0, pinpoint_1.updateEndpoint)({
60
+ appId,
61
+ category: 'Analytics',
62
+ credentials,
63
+ identityId,
64
+ region,
65
+ userAttributes,
66
+ userId,
67
+ userProfile,
68
+ userAgentValue: (0, utils_2.getAnalyticsUserAgentString)(utils_1.AnalyticsAction.IdentifyUser),
81
69
  });
82
70
  };
83
71
  exports.identifyUser = identifyUser;
@@ -3,13 +3,13 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.record = void 0;
6
- var core_1 = require("@aws-amplify/core");
7
- var utils_1 = require("@aws-amplify/core/internals/utils");
8
- var pinpoint_1 = require("@aws-amplify/core/internals/providers/pinpoint");
9
- var errors_1 = require("../../../errors");
10
- var utils_2 = require("../../../utils");
11
- var utils_3 = require("../utils");
12
- var logger = new core_1.ConsoleLogger('Analytics');
6
+ const core_1 = require("@aws-amplify/core");
7
+ const utils_1 = require("@aws-amplify/core/internals/utils");
8
+ const pinpoint_1 = require("@aws-amplify/core/internals/providers/pinpoint");
9
+ const errors_1 = require("../../../errors");
10
+ const utils_2 = require("../../../utils");
11
+ const utils_3 = require("../utils");
12
+ const logger = new core_1.ConsoleLogger('Analytics');
13
13
  /**
14
14
  * Records an Analytic event to Pinpoint. Events will be buffered and periodically sent to Pinpoint.
15
15
  *
@@ -38,28 +38,27 @@ var logger = new core_1.ConsoleLogger('Analytics');
38
38
  * })
39
39
  * ```
40
40
  */
41
- var record = function (input) {
42
- var _a = (0, utils_3.resolveConfig)(), appId = _a.appId, region = _a.region;
41
+ const record = (input) => {
42
+ const { appId, region } = (0, utils_3.resolveConfig)();
43
43
  if (!(0, utils_2.isAnalyticsEnabled)()) {
44
44
  logger.debug('Analytics is disabled, event will not be recorded.');
45
45
  return;
46
46
  }
47
47
  (0, errors_1.assertValidationError)(!!input.name, errors_1.AnalyticsValidationErrorCode.NoEventName);
48
48
  (0, utils_3.resolveCredentials)()
49
- .then(function (_a) {
50
- var credentials = _a.credentials, identityId = _a.identityId;
49
+ .then(({ credentials, identityId }) => {
51
50
  core_1.Hub.dispatch('analytics', { event: 'record', data: input, message: 'Recording Analytics event' }, 'Analytics', utils_1.AMPLIFY_SYMBOL);
52
51
  (0, pinpoint_1.record)({
53
- appId: appId,
52
+ appId,
54
53
  category: 'Analytics',
55
- credentials: credentials,
54
+ credentials,
56
55
  event: input,
57
- identityId: identityId,
58
- region: region,
56
+ identityId,
57
+ region,
59
58
  userAgentValue: (0, utils_2.getAnalyticsUserAgentString)(utils_1.AnalyticsAction.Record),
60
59
  });
61
60
  })
62
- .catch(function (e) {
61
+ .catch(e => {
63
62
  // An error occured while fetching credentials or persisting the event to the buffer
64
63
  logger.warn('Failed to record event.', e);
65
64
  });
@@ -3,16 +3,15 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.resolveConfig = void 0;
6
- var core_1 = require("@aws-amplify/core");
7
- var errors_1 = require("../../../errors");
6
+ const core_1 = require("@aws-amplify/core");
7
+ const errors_1 = require("../../../errors");
8
8
  /**
9
9
  * @internal
10
10
  */
11
- var resolveConfig = function () {
12
- var _a, _b;
13
- var _c = (_b = (_a = core_1.Amplify.getConfig().Analytics) === null || _a === void 0 ? void 0 : _a.Pinpoint) !== null && _b !== void 0 ? _b : {}, appId = _c.appId, region = _c.region;
11
+ const resolveConfig = () => {
12
+ const { appId, region } = core_1.Amplify.getConfig().Analytics?.Pinpoint ?? {};
14
13
  (0, errors_1.assertValidationError)(!!appId, errors_1.AnalyticsValidationErrorCode.NoAppId);
15
14
  (0, errors_1.assertValidationError)(!!region, errors_1.AnalyticsValidationErrorCode.NoRegion);
16
- return { appId: appId, region: region };
15
+ return { appId, region };
17
16
  };
18
17
  exports.resolveConfig = resolveConfig;
@@ -3,22 +3,14 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.resolveCredentials = void 0;
6
- var tslib_1 = require("tslib");
7
- var core_1 = require("@aws-amplify/core");
8
- var errors_1 = require("../../../errors");
6
+ const core_1 = require("@aws-amplify/core");
7
+ const errors_1 = require("../../../errors");
9
8
  /**
10
9
  * @internal
11
10
  */
12
- var resolveCredentials = function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
13
- var _a, credentials, identityId;
14
- return tslib_1.__generator(this, function (_b) {
15
- switch (_b.label) {
16
- case 0: return [4 /*yield*/, (0, core_1.fetchAuthSession)()];
17
- case 1:
18
- _a = _b.sent(), credentials = _a.credentials, identityId = _a.identityId;
19
- (0, errors_1.assertValidationError)(!!credentials, errors_1.AnalyticsValidationErrorCode.NoCredentials);
20
- return [2 /*return*/, { credentials: credentials, identityId: identityId }];
21
- }
22
- });
23
- }); };
11
+ const resolveCredentials = async () => {
12
+ const { credentials, identityId } = await (0, core_1.fetchAuthSession)();
13
+ (0, errors_1.assertValidationError)(!!credentials, errors_1.AnalyticsValidationErrorCode.NoCredentials);
14
+ return { credentials, identityId };
15
+ };
24
16
  exports.resolveCredentials = resolveCredentials;
package/lib/setupTests.js CHANGED
@@ -1,7 +1,7 @@
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 anyGlobal = global;
4
+ const anyGlobal = global;
5
5
  anyGlobal.navigator = anyGlobal.navigator || {};
6
6
  // @ts-ignore
7
7
  anyGlobal.navigator.sendBeacon = anyGlobal.navigator.sendBeacon || jest.fn();