@aws-amplify/analytics 7.0.10-unstable.ef15561.0 → 7.0.10
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/utils/getEventBuffer.js +22 -11
- package/dist/cjs/providers/kinesis/utils/getEventBuffer.js.map +1 -1
- package/dist/cjs/providers/kinesis-firehose/utils/getEventBuffer.js +21 -11
- package/dist/cjs/providers/kinesis-firehose/utils/getEventBuffer.js.map +1 -1
- package/dist/cjs/providers/personalize/utils/getEventBuffer.js +22 -11
- package/dist/cjs/providers/personalize/utils/getEventBuffer.js.map +1 -1
- package/dist/esm/providers/kinesis/utils/getEventBuffer.mjs +20 -10
- package/dist/esm/providers/kinesis/utils/getEventBuffer.mjs.map +1 -1
- package/dist/esm/providers/kinesis-firehose/utils/getEventBuffer.mjs +19 -10
- package/dist/esm/providers/kinesis-firehose/utils/getEventBuffer.mjs.map +1 -1
- package/dist/esm/providers/personalize/utils/getEventBuffer.mjs +20 -10
- package/dist/esm/providers/personalize/utils/getEventBuffer.mjs.map +1 -1
- package/package.json +113 -113
- package/src/providers/kinesis/utils/getEventBuffer.ts +31 -11
- package/src/providers/kinesis-firehose/utils/getEventBuffer.ts +29 -10
- package/src/providers/personalize/utils/getEventBuffer.ts +32 -11
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
// SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getEventBuffer = void 0;
|
|
7
|
-
const utils_1 = require("
|
|
7
|
+
const utils_1 = require("@aws-amplify/core/internals/utils");
|
|
8
8
|
const client_kinesis_1 = require("@aws-sdk/client-kinesis");
|
|
9
|
+
const utils_2 = require("../../../utils");
|
|
9
10
|
/**
|
|
10
11
|
* These Records hold cached event buffers and AWS clients.
|
|
11
12
|
* The hash key is determined by the region and session,
|
|
@@ -24,7 +25,7 @@ const createKinesisPutRecordsCommand = (streamName, events) => new client_kinesi
|
|
|
24
25
|
})),
|
|
25
26
|
});
|
|
26
27
|
const submitEvents = async (events, client, resendLimit) => {
|
|
27
|
-
const groupedByStreamName = Object.entries((0,
|
|
28
|
+
const groupedByStreamName = Object.entries((0, utils_2.groupBy)(event => event.streamName, events));
|
|
28
29
|
const requests = groupedByStreamName
|
|
29
30
|
.map(([streamName, events]) => createKinesisPutRecordsCommand(streamName, events))
|
|
30
31
|
.map(command => client.send(command));
|
|
@@ -41,19 +42,29 @@ const submitEvents = async (events, client, resendLimit) => {
|
|
|
41
42
|
};
|
|
42
43
|
const getEventBuffer = ({ region, flushInterval, flushSize, bufferSize, credentials, identityId, resendLimit, userAgentValue, }) => {
|
|
43
44
|
const sessionIdentityKey = [region, identityId].filter(x => !!x).join('-');
|
|
44
|
-
|
|
45
|
+
const [cachedClient, cachedCredentials] = cachedClients[sessionIdentityKey] ?? [];
|
|
46
|
+
let credentialsHaveChanged = false;
|
|
47
|
+
// Check if credentials have changed for the cached client
|
|
48
|
+
if (cachedClient) {
|
|
49
|
+
credentialsHaveChanged = (0, utils_1.haveCredentialsChanged)(cachedCredentials, credentials);
|
|
50
|
+
}
|
|
51
|
+
if (!eventBufferMap[sessionIdentityKey] || credentialsHaveChanged) {
|
|
45
52
|
const getKinesisClient = () => {
|
|
46
|
-
if (!
|
|
47
|
-
cachedClients[sessionIdentityKey] =
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
if (!cachedClient || credentialsHaveChanged) {
|
|
54
|
+
cachedClients[sessionIdentityKey] = [
|
|
55
|
+
new client_kinesis_1.KinesisClient({
|
|
56
|
+
credentials,
|
|
57
|
+
region,
|
|
58
|
+
customUserAgent: userAgentValue,
|
|
59
|
+
}),
|
|
60
|
+
credentials
|
|
61
|
+
];
|
|
52
62
|
}
|
|
53
|
-
|
|
63
|
+
const [kinesisClient] = cachedClients[sessionIdentityKey];
|
|
64
|
+
return events => submitEvents(events, kinesisClient, resendLimit);
|
|
54
65
|
};
|
|
55
66
|
// create new session
|
|
56
|
-
eventBufferMap[sessionIdentityKey] = new
|
|
67
|
+
eventBufferMap[sessionIdentityKey] = new utils_2.EventBuffer({
|
|
57
68
|
flushInterval,
|
|
58
69
|
flushSize,
|
|
59
70
|
bufferSize,
|
|
@@ -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(\"
|
|
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, events]) => createKinesisPutRecordsCommand(streamName, events))\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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|
4
4
|
// SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getEventBuffer = void 0;
|
|
7
|
-
const utils_1 = require("
|
|
7
|
+
const utils_1 = require("@aws-amplify/core/internals/utils");
|
|
8
8
|
const client_firehose_1 = require("@aws-sdk/client-firehose");
|
|
9
|
+
const utils_2 = require("../../../utils");
|
|
9
10
|
/**
|
|
10
11
|
* These Records hold cached event buffers and AWS clients.
|
|
11
12
|
* The hash key is determined by the region and session,
|
|
@@ -23,7 +24,7 @@ const createPutRecordsBatchCommand = (streamName, events) => new client_firehose
|
|
|
23
24
|
})),
|
|
24
25
|
});
|
|
25
26
|
const submitEvents = async (events, client, resendLimit) => {
|
|
26
|
-
const groupedByStreamName = Object.entries((0,
|
|
27
|
+
const groupedByStreamName = Object.entries((0, utils_2.groupBy)(event => event.streamName, events));
|
|
27
28
|
const requests = groupedByStreamName
|
|
28
29
|
.map(([streamName, events]) => createPutRecordsBatchCommand(streamName, events))
|
|
29
30
|
.map(command => client.send(command));
|
|
@@ -40,20 +41,29 @@ const submitEvents = async (events, client, resendLimit) => {
|
|
|
40
41
|
};
|
|
41
42
|
const getEventBuffer = ({ region, credentials, identityId, bufferSize, flushSize, flushInterval, resendLimit, userAgentValue, }) => {
|
|
42
43
|
const sessionIdentityKey = [region, identityId].filter(id => !!id).join('-');
|
|
43
|
-
|
|
44
|
+
const [cachedClient, cachedCredentials] = cachedClients[sessionIdentityKey] ?? [];
|
|
45
|
+
let credentialsHaveChanged = false;
|
|
46
|
+
// Check if credentials have changed for the cached client
|
|
47
|
+
if (cachedClient) {
|
|
48
|
+
credentialsHaveChanged = (0, utils_1.haveCredentialsChanged)(cachedCredentials, credentials);
|
|
49
|
+
}
|
|
50
|
+
if (!eventBufferMap[sessionIdentityKey] || credentialsHaveChanged) {
|
|
44
51
|
const getClient = () => {
|
|
45
|
-
if (!
|
|
46
|
-
cachedClients[sessionIdentityKey] =
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
52
|
+
if (!cachedClient || credentialsHaveChanged) {
|
|
53
|
+
cachedClients[sessionIdentityKey] = [
|
|
54
|
+
new client_firehose_1.FirehoseClient({
|
|
55
|
+
region,
|
|
56
|
+
credentials,
|
|
57
|
+
customUserAgent: userAgentValue,
|
|
58
|
+
}),
|
|
59
|
+
credentials
|
|
60
|
+
];
|
|
51
61
|
}
|
|
52
|
-
const firehoseClient = cachedClients[sessionIdentityKey];
|
|
62
|
+
const [firehoseClient] = cachedClients[sessionIdentityKey];
|
|
53
63
|
return events => submitEvents(events, firehoseClient, resendLimit);
|
|
54
64
|
};
|
|
55
65
|
eventBufferMap[sessionIdentityKey] =
|
|
56
|
-
new
|
|
66
|
+
new utils_2.EventBuffer({
|
|
57
67
|
bufferSize,
|
|
58
68
|
flushSize,
|
|
59
69
|
flushInterval,
|
|
@@ -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(\"
|
|
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, events]) => createPutRecordsBatchCommand(streamName, events))\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,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,iBAAiB,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAC;AAC9D,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,4BAA4B,GAAG,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,iBAAiB,CAAC,qBAAqB,CAAC;AACzG,IAAI,kBAAkB,EAAE,UAAU;AAClC,IAAI,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,KAAK,KAAK;AAClC,QAAQ,IAAI,EAAE,KAAK,CAAC,KAAK;AACzB,KAAK,CAAC,CAAC;AACP,CAAC,CAAC,CAAC;AACH,MAAM,YAAY,GAAG,OAAO,MAAM,EAAE,MAAM,EAAE,WAAW,KAAK;AAC5D,IAAI,MAAM,mBAAmB,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,OAAO,EAAE,KAAK,IAAI,KAAK,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC;AACxG,IAAI,MAAM,QAAQ,GAAG,mBAAmB;AACxC,SAAS,GAAG,CAAC,CAAC,CAAC,UAAU,EAAE,MAAM,CAAC,KAAK,4B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AO,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,8 +4,9 @@
|
|
|
4
4
|
// SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getEventBuffer = void 0;
|
|
7
|
-
const utils_1 = require("
|
|
7
|
+
const utils_1 = require("@aws-amplify/core/internals/utils");
|
|
8
8
|
const client_personalize_events_1 = require("@aws-sdk/client-personalize-events");
|
|
9
|
+
const utils_2 = require("../../../utils");
|
|
9
10
|
/**
|
|
10
11
|
* These Records hold cached event buffers and AWS clients.
|
|
11
12
|
* The hash key is determined by the region and session,
|
|
@@ -32,7 +33,7 @@ const createPutEventsCommand = (ids, events) => {
|
|
|
32
33
|
});
|
|
33
34
|
};
|
|
34
35
|
const submitEvents = async (events, client) => {
|
|
35
|
-
const groupedByIds = Object.entries((0,
|
|
36
|
+
const groupedByIds = Object.entries((0, utils_2.groupBy)(event => [event.trackingId, event.sessionId, event.userId]
|
|
36
37
|
.filter(id => !!id)
|
|
37
38
|
.join(DELIMITER), events));
|
|
38
39
|
const requests = groupedByIds
|
|
@@ -43,19 +44,29 @@ const submitEvents = async (events, client) => {
|
|
|
43
44
|
};
|
|
44
45
|
const getEventBuffer = ({ region, flushSize, flushInterval, bufferSize, credentials, identityId, userAgentValue, }) => {
|
|
45
46
|
const sessionIdentityKey = [region, identityId].filter(x => !!x).join('-');
|
|
46
|
-
|
|
47
|
+
const [cachedClient, cachedCredentials] = cachedClients[sessionIdentityKey] ?? [];
|
|
48
|
+
let credentialsHaveChanged = false;
|
|
49
|
+
// Check if credentials have changed for the cached client
|
|
50
|
+
if (cachedClient) {
|
|
51
|
+
credentialsHaveChanged = (0, utils_1.haveCredentialsChanged)(cachedCredentials, credentials);
|
|
52
|
+
}
|
|
53
|
+
if (!eventBufferMap[sessionIdentityKey] || credentialsHaveChanged) {
|
|
47
54
|
const getClient = () => {
|
|
48
|
-
if (!
|
|
49
|
-
cachedClients[sessionIdentityKey] =
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
55
|
+
if (!cachedClient || credentialsHaveChanged) {
|
|
56
|
+
cachedClients[sessionIdentityKey] = [
|
|
57
|
+
new client_personalize_events_1.PersonalizeEventsClient({
|
|
58
|
+
region,
|
|
59
|
+
credentials,
|
|
60
|
+
customUserAgent: userAgentValue,
|
|
61
|
+
}),
|
|
62
|
+
credentials
|
|
63
|
+
];
|
|
54
64
|
}
|
|
55
|
-
|
|
65
|
+
const [personalizeClient] = cachedClients[sessionIdentityKey];
|
|
66
|
+
return events => submitEvents(events, personalizeClient);
|
|
56
67
|
};
|
|
57
68
|
eventBufferMap[sessionIdentityKey] =
|
|
58
|
-
new
|
|
69
|
+
new utils_2.EventBuffer({
|
|
59
70
|
bufferSize,
|
|
60
71
|
flushSize,
|
|
61
72
|
flushInterval,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getEventBuffer.js","sources":["../../../../../src/providers/personalize/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(\"
|
|
1
|
+
{"version":3,"file":"getEventBuffer.js","sources":["../../../../../src/providers/personalize/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_personalize_events_1 = require(\"@aws-sdk/client-personalize-events\");\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 DELIMITER = '#';\nconst createPutEventsCommand = (ids, events) => {\n const [trackingId, sessionId, userId] = ids.split(DELIMITER);\n return new client_personalize_events_1.PutEventsCommand({\n trackingId,\n sessionId,\n userId,\n eventList: events.map(event => ({\n eventId: event.event.eventId,\n eventType: event.event.eventType,\n properties: JSON.stringify(event.event.properties),\n sentAt: new Date(event.timestamp),\n })),\n });\n};\nconst submitEvents = async (events, client) => {\n const groupedByIds = Object.entries((0, utils_2.groupBy)(event => [event.trackingId, event.sessionId, event.userId]\n .filter(id => !!id)\n .join(DELIMITER), events));\n const requests = groupedByIds\n .map(([ids, events]) => createPutEventsCommand(ids, events))\n .map(command => client.send(command));\n await Promise.allSettled(requests);\n return Promise.resolve([]);\n};\nconst getEventBuffer = ({ region, flushSize, flushInterval, bufferSize, credentials, identityId, 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 getClient = () => {\n if (!cachedClient || credentialsHaveChanged) {\n cachedClients[sessionIdentityKey] = [\n new client_personalize_events_1.PersonalizeEventsClient({\n region,\n credentials,\n customUserAgent: userAgentValue,\n }),\n credentials\n ];\n }\n const [personalizeClient] = cachedClients[sessionIdentityKey];\n return events => submitEvents(events, personalizeClient);\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,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,2BAA2B,GAAG,OAAO,CAAC,oCAAoC,CAAC,CAAC;AAClF,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,SAAS,GAAG,GAAG,CAAC;AACtB,MAAM,sBAAsB,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK;AAChD,IAAI,MAAM,CAAC,UAAU,EAAE,SAAS,EAAE,MAAM,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;AACjE,IAAI,OAAO,IAAI,2BAA2B,CAAC,gBAAgB,CAAC;AAC5D,QAAQ,UAAU;AAClB,QAAQ,SAAS;AACjB,QAAQ,MAAM;AACd,QAAQ,SAAS,EAAE,MAAM,CAAC,GAAG,CAAC,KAAK,KAAK;AACxC,YAAY,OAAO,EAAE,KAAK,C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B,CAAC,CAAC;AACzG,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;;"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import '@aws-amplify/core/internals/utils';
|
|
1
|
+
import { haveCredentialsChanged } from '@aws-amplify/core/internals/utils';
|
|
2
|
+
import { KinesisClient, PutRecordsCommand } from '@aws-sdk/client-kinesis';
|
|
2
3
|
import '../../../errors/validation.mjs';
|
|
3
4
|
import '@aws-amplify/core';
|
|
4
5
|
import { groupBy } from '../../../utils/groupBy.mjs';
|
|
@@ -6,7 +7,6 @@ import { EventBuffer } from '../../../utils/eventBuffer/EventBuffer.mjs';
|
|
|
6
7
|
import '../../../trackers/EventTracker.mjs';
|
|
7
8
|
import '../../../trackers/PageViewTracker.mjs';
|
|
8
9
|
import '../../../trackers/SessionTracker.mjs';
|
|
9
|
-
import { KinesisClient, PutRecordsCommand } from '@aws-sdk/client-kinesis';
|
|
10
10
|
|
|
11
11
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
12
12
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -45,16 +45,26 @@ const submitEvents = async (events, client, resendLimit) => {
|
|
|
45
45
|
};
|
|
46
46
|
const getEventBuffer = ({ region, flushInterval, flushSize, bufferSize, credentials, identityId, resendLimit, userAgentValue, }) => {
|
|
47
47
|
const sessionIdentityKey = [region, identityId].filter(x => !!x).join('-');
|
|
48
|
-
|
|
48
|
+
const [cachedClient, cachedCredentials] = cachedClients[sessionIdentityKey] ?? [];
|
|
49
|
+
let credentialsHaveChanged = false;
|
|
50
|
+
// Check if credentials have changed for the cached client
|
|
51
|
+
if (cachedClient) {
|
|
52
|
+
credentialsHaveChanged = haveCredentialsChanged(cachedCredentials, credentials);
|
|
53
|
+
}
|
|
54
|
+
if (!eventBufferMap[sessionIdentityKey] || credentialsHaveChanged) {
|
|
49
55
|
const getKinesisClient = () => {
|
|
50
|
-
if (!
|
|
51
|
-
cachedClients[sessionIdentityKey] =
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
if (!cachedClient || credentialsHaveChanged) {
|
|
57
|
+
cachedClients[sessionIdentityKey] = [
|
|
58
|
+
new KinesisClient({
|
|
59
|
+
credentials,
|
|
60
|
+
region,
|
|
61
|
+
customUserAgent: userAgentValue,
|
|
62
|
+
}),
|
|
63
|
+
credentials
|
|
64
|
+
];
|
|
56
65
|
}
|
|
57
|
-
|
|
66
|
+
const [kinesisClient] = cachedClients[sessionIdentityKey];
|
|
67
|
+
return events => submitEvents(events, kinesisClient, resendLimit);
|
|
58
68
|
};
|
|
59
69
|
// create new session
|
|
60
70
|
eventBufferMap[sessionIdentityKey] = new EventBuffer({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getEventBuffer.mjs","sources":["../../../../../src/providers/kinesis/utils/getEventBuffer.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport {
|
|
1
|
+
{"version":3,"file":"getEventBuffer.mjs","sources":["../../../../../src/providers/kinesis/utils/getEventBuffer.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { haveCredentialsChanged } from '@aws-amplify/core/internals/utils';\nimport { KinesisClient, PutRecordsCommand } from '@aws-sdk/client-kinesis';\nimport { EventBuffer, groupBy } from '../../../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 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(groupBy(event => event.streamName, events));\n const requests = groupedByStreamName\n .map(([streamName, events]) => createKinesisPutRecordsCommand(streamName, events))\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};\nexport const 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 = haveCredentialsChanged(cachedCredentials, credentials);\n }\n if (!eventBufferMap[sessionIdentityKey] || credentialsHaveChanged) {\n const getKinesisClient = () => {\n if (!cachedClient || credentialsHaveChanged) {\n cachedClients[sessionIdentityKey] = [\n new 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 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};\n"],"names":[],"mappings":";;;;;;;;;;AAAA;AACA;AAIA;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,iBAAiB,CAAC;AACrF,IAAI,UAAU,EAAE,UAAU;AAC1B,IAAI,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,KAAK,KAAK;AAClC,QAAQ,YAAY,EAAE,KAAK,CAAC,YAAY;AACxC,QAAQ,IAAI,EAAE,KAAK,CAAC,KAAK;AACzB,KAAK,CAAC,CAAC;AACP,CAAC,CAAC,CAAC;AACH,MAAM,YAAY,GAAG,OAAO,MAAM,EAAE,MAAM,EAAE,WAAW,KAAK;AAC5D,IAAI,MAAM,mBAAmB,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC;AAC3F,IAAI,MAAM,QAAQ,GAAG,mBAAmB;AACxC,SAAS,GAAG,CAAC,CAAC,CAAC,UAAU,EAAE,MAAM,CAAC,KAAK,8BAA8B,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;AAC1F,SAAS,GAAG,CAAC,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AAC9C,IAAI,MAAM,SAAS,GAAG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AAkB,CAAC,CAAC;AAC9C;;;;"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import '@aws-amplify/core/internals/utils';
|
|
1
|
+
import { haveCredentialsChanged } from '@aws-amplify/core/internals/utils';
|
|
2
|
+
import { FirehoseClient, PutRecordBatchCommand } from '@aws-sdk/client-firehose';
|
|
2
3
|
import '../../../errors/validation.mjs';
|
|
3
4
|
import '@aws-amplify/core';
|
|
4
5
|
import { groupBy } from '../../../utils/groupBy.mjs';
|
|
@@ -6,7 +7,6 @@ import { EventBuffer } from '../../../utils/eventBuffer/EventBuffer.mjs';
|
|
|
6
7
|
import '../../../trackers/EventTracker.mjs';
|
|
7
8
|
import '../../../trackers/PageViewTracker.mjs';
|
|
8
9
|
import '../../../trackers/SessionTracker.mjs';
|
|
9
|
-
import { FirehoseClient, PutRecordBatchCommand } from '@aws-sdk/client-firehose';
|
|
10
10
|
|
|
11
11
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
12
12
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -44,16 +44,25 @@ const submitEvents = async (events, client, resendLimit) => {
|
|
|
44
44
|
};
|
|
45
45
|
const getEventBuffer = ({ region, credentials, identityId, bufferSize, flushSize, flushInterval, resendLimit, userAgentValue, }) => {
|
|
46
46
|
const sessionIdentityKey = [region, identityId].filter(id => !!id).join('-');
|
|
47
|
-
|
|
47
|
+
const [cachedClient, cachedCredentials] = cachedClients[sessionIdentityKey] ?? [];
|
|
48
|
+
let credentialsHaveChanged = false;
|
|
49
|
+
// Check if credentials have changed for the cached client
|
|
50
|
+
if (cachedClient) {
|
|
51
|
+
credentialsHaveChanged = haveCredentialsChanged(cachedCredentials, credentials);
|
|
52
|
+
}
|
|
53
|
+
if (!eventBufferMap[sessionIdentityKey] || credentialsHaveChanged) {
|
|
48
54
|
const getClient = () => {
|
|
49
|
-
if (!
|
|
50
|
-
cachedClients[sessionIdentityKey] =
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
if (!cachedClient || credentialsHaveChanged) {
|
|
56
|
+
cachedClients[sessionIdentityKey] = [
|
|
57
|
+
new FirehoseClient({
|
|
58
|
+
region,
|
|
59
|
+
credentials,
|
|
60
|
+
customUserAgent: userAgentValue,
|
|
61
|
+
}),
|
|
62
|
+
credentials
|
|
63
|
+
];
|
|
55
64
|
}
|
|
56
|
-
const firehoseClient = cachedClients[sessionIdentityKey];
|
|
65
|
+
const [firehoseClient] = cachedClients[sessionIdentityKey];
|
|
57
66
|
return events => submitEvents(events, firehoseClient, resendLimit);
|
|
58
67
|
};
|
|
59
68
|
eventBufferMap[sessionIdentityKey] =
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getEventBuffer.mjs","sources":["../../../../../src/providers/kinesis-firehose/utils/getEventBuffer.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport {
|
|
1
|
+
{"version":3,"file":"getEventBuffer.mjs","sources":["../../../../../src/providers/kinesis-firehose/utils/getEventBuffer.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { haveCredentialsChanged } from '@aws-amplify/core/internals/utils';\nimport { FirehoseClient, PutRecordBatchCommand, } from '@aws-sdk/client-firehose';\nimport { EventBuffer, groupBy } from '../../../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 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(groupBy(event => event.streamName, events));\n const requests = groupedByStreamName\n .map(([streamName, events]) => createPutRecordsBatchCommand(streamName, events))\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};\nexport const 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 = haveCredentialsChanged(cachedCredentials, credentials);\n }\n if (!eventBufferMap[sessionIdentityKey] || credentialsHaveChanged) {\n const getClient = () => {\n if (!cachedClient || credentialsHaveChanged) {\n cachedClients[sessionIdentityKey] = [\n new 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 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};\n"],"names":[],"mappings":";;;;;;;;;;AAAA;AACA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,cAAc,GAAG,EAAE,CAAC;AAC1B,MAAM,aAAa,GAAG,EAAE,CAA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W,CAAC,CAAC;AAC/E,SAAS,CAAC;AACV,QAAQ,cAAc,CAAC,kBAAkB,CAAC;AAC1C,YAAY,IAAI,WAAW,CAAC;AAC5B,gBAAgB,UAAU;AAC1B,gBAAgB,SAAS;AACzB,gBAAgB,aAAa;AAC7B,aAAa,EAAE,SAAS,CAAC,CAAC;AAC1B,QAAQ,MAAM,kBAAkB,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,KAAK,kBAAkB,CAAC,CAAC;AACzG,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;;;;"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import '@aws-amplify/core/internals/utils';
|
|
1
|
+
import { haveCredentialsChanged } from '@aws-amplify/core/internals/utils';
|
|
2
|
+
import { PersonalizeEventsClient, PutEventsCommand } from '@aws-sdk/client-personalize-events';
|
|
2
3
|
import '../../../errors/validation.mjs';
|
|
3
4
|
import '@aws-amplify/core';
|
|
4
5
|
import { groupBy } from '../../../utils/groupBy.mjs';
|
|
@@ -6,7 +7,6 @@ import { EventBuffer } from '../../../utils/eventBuffer/EventBuffer.mjs';
|
|
|
6
7
|
import '../../../trackers/EventTracker.mjs';
|
|
7
8
|
import '../../../trackers/PageViewTracker.mjs';
|
|
8
9
|
import '../../../trackers/SessionTracker.mjs';
|
|
9
|
-
import { PersonalizeEventsClient, PutEventsCommand } from '@aws-sdk/client-personalize-events';
|
|
10
10
|
|
|
11
11
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
12
12
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -47,16 +47,26 @@ const submitEvents = async (events, client) => {
|
|
|
47
47
|
};
|
|
48
48
|
const getEventBuffer = ({ region, flushSize, flushInterval, bufferSize, credentials, identityId, userAgentValue, }) => {
|
|
49
49
|
const sessionIdentityKey = [region, identityId].filter(x => !!x).join('-');
|
|
50
|
-
|
|
50
|
+
const [cachedClient, cachedCredentials] = cachedClients[sessionIdentityKey] ?? [];
|
|
51
|
+
let credentialsHaveChanged = false;
|
|
52
|
+
// Check if credentials have changed for the cached client
|
|
53
|
+
if (cachedClient) {
|
|
54
|
+
credentialsHaveChanged = haveCredentialsChanged(cachedCredentials, credentials);
|
|
55
|
+
}
|
|
56
|
+
if (!eventBufferMap[sessionIdentityKey] || credentialsHaveChanged) {
|
|
51
57
|
const getClient = () => {
|
|
52
|
-
if (!
|
|
53
|
-
cachedClients[sessionIdentityKey] =
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
+
if (!cachedClient || credentialsHaveChanged) {
|
|
59
|
+
cachedClients[sessionIdentityKey] = [
|
|
60
|
+
new PersonalizeEventsClient({
|
|
61
|
+
region,
|
|
62
|
+
credentials,
|
|
63
|
+
customUserAgent: userAgentValue,
|
|
64
|
+
}),
|
|
65
|
+
credentials
|
|
66
|
+
];
|
|
58
67
|
}
|
|
59
|
-
|
|
68
|
+
const [personalizeClient] = cachedClients[sessionIdentityKey];
|
|
69
|
+
return events => submitEvents(events, personalizeClient);
|
|
60
70
|
};
|
|
61
71
|
eventBufferMap[sessionIdentityKey] =
|
|
62
72
|
new EventBuffer({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getEventBuffer.mjs","sources":["../../../../../src/providers/personalize/utils/getEventBuffer.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport {
|
|
1
|
+
{"version":3,"file":"getEventBuffer.mjs","sources":["../../../../../src/providers/personalize/utils/getEventBuffer.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { haveCredentialsChanged } from '@aws-amplify/core/internals/utils';\nimport { PersonalizeEventsClient, PutEventsCommand, } from '@aws-sdk/client-personalize-events';\nimport { EventBuffer, groupBy } from '../../../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 DELIMITER = '#';\nconst createPutEventsCommand = (ids, events) => {\n const [trackingId, sessionId, userId] = ids.split(DELIMITER);\n return new PutEventsCommand({\n trackingId,\n sessionId,\n userId,\n eventList: events.map(event => ({\n eventId: event.event.eventId,\n eventType: event.event.eventType,\n properties: JSON.stringify(event.event.properties),\n sentAt: new Date(event.timestamp),\n })),\n });\n};\nconst submitEvents = async (events, client) => {\n const groupedByIds = Object.entries(groupBy(event => [event.trackingId, event.sessionId, event.userId]\n .filter(id => !!id)\n .join(DELIMITER), events));\n const requests = groupedByIds\n .map(([ids, events]) => createPutEventsCommand(ids, events))\n .map(command => client.send(command));\n await Promise.allSettled(requests);\n return Promise.resolve([]);\n};\nexport const getEventBuffer = ({ region, flushSize, flushInterval, bufferSize, credentials, identityId, 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 = haveCredentialsChanged(cachedCredentials, credentials);\n }\n if (!eventBufferMap[sessionIdentityKey] || credentialsHaveChanged) {\n const getClient = () => {\n if (!cachedClient || credentialsHaveChanged) {\n cachedClients[sessionIdentityKey] = [\n new PersonalizeEventsClient({\n region,\n credentials,\n customUserAgent: userAgentValue,\n }),\n credentials\n ];\n }\n const [personalizeClient] = cachedClients[sessionIdentityKey];\n return events => submitEvents(events, personalizeClient);\n };\n eventBufferMap[sessionIdentityKey] =\n new 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};\n"],"names":[],"mappings":";;;;;;;;;;AAAA;AACA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,cAAc,GAAG,EAAE,CAAC;AAC1B,MAAM,aAAa,GAAG,EAAE,CAAC;AACzB,MAAM,SAAS,GAAG,GAAG,CAAC;AACtB,MAAM,sBAAsB,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK;AAChD,IAAI,MAAM,CAAC,UAAU,EAAE,SAAS,EAAE,MAAM,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;AACjE,IAAI,OAAO,IAAI,gBAAgB,CAAC;AAChC,QAAQ,UAAU;AAClB,QAAQ,SAAS;AACjB,QAAQ,MAAM;AACd,QAAQ,SAAS,EAAE,MAAM,CAAC,GAAG,CAAC,KAAK,KAAK;AACxC,YAAY,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO;AACxC,YAAY,SAAS,EAAE,KAAK,CAAC,KAAK,CAAC,SAAS;AAC5C,YAAY,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC;AAC9D,YAAY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
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
2
|
+
"name": "@aws-amplify/analytics",
|
|
3
|
+
"version": "7.0.10",
|
|
4
|
+
"description": "Analytics category of aws-amplify",
|
|
5
|
+
"main": "./dist/cjs/index.js",
|
|
6
|
+
"module": "./dist/esm/index.mjs",
|
|
7
|
+
"react-native": "./src/index.ts",
|
|
8
|
+
"typings": "./dist/esm/index.d.ts",
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"test": "npm run lint && jest -w 1 --coverage --logHeapUsage",
|
|
15
|
+
"test:watch": "tslint 'src/**/*.ts' && jest -w 1 --watch",
|
|
16
|
+
"build-with-test": "npm run clean && npm run test && npm run build",
|
|
17
|
+
"build:umd": "webpack && webpack --config ./webpack.config.dev.js",
|
|
18
|
+
"build:esm-cjs": "rollup -c rollup.config.mjs",
|
|
19
|
+
"build:cjs:watch": "rimraf dist/cjs && tsc -m commonjs --outDir dist/cjs --watch",
|
|
20
|
+
"build:esm:watch": "rimraf dist/esm && tsc -m esnext --outDir dist/esm --watch",
|
|
21
|
+
"build": "npm run clean && npm run build:esm-cjs && npm run build:umd",
|
|
22
|
+
"clean": "npm run clean:size && rimraf dist lib lib-esm",
|
|
23
|
+
"clean:size": "rimraf dual-publish-tmp tmp*",
|
|
24
|
+
"format": "echo \"Not implemented\"",
|
|
25
|
+
"lint": "tslint 'src/**/*.ts' && npm run ts-coverage",
|
|
26
|
+
"ts-coverage": "typescript-coverage-report -p ./tsconfig.json -t 71.4"
|
|
27
|
+
},
|
|
28
|
+
"typesVersions": {
|
|
29
|
+
">=4.2": {
|
|
30
|
+
"pinpoint": [
|
|
31
|
+
"./dist/esm/providers/pinpoint/index.d.ts"
|
|
32
|
+
],
|
|
33
|
+
"kinesis": [
|
|
34
|
+
"./dist/esm/providers/kinesis/index.d.ts"
|
|
35
|
+
],
|
|
36
|
+
"kinesis-firehose": [
|
|
37
|
+
"./dist/esm/providers/kinesis-firehose/index.d.ts"
|
|
38
|
+
],
|
|
39
|
+
"personalize": [
|
|
40
|
+
"./dist/esm/providers/personalize/index.d.ts"
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"exports": {
|
|
45
|
+
".": {
|
|
46
|
+
"types": "./dist/esm/index.d.ts",
|
|
47
|
+
"import": "./dist/esm/index.mjs",
|
|
48
|
+
"require": "./dist/cjs/index.js",
|
|
49
|
+
"react-native": "./src/index.ts"
|
|
50
|
+
},
|
|
51
|
+
"./pinpoint": {
|
|
52
|
+
"types": "./dist/esm/providers/pinpoint/index.d.ts",
|
|
53
|
+
"import": "./dist/esm/providers/pinpoint/index.mjs",
|
|
54
|
+
"require": "./dist/cjs/providers/pinpoint/index.js",
|
|
55
|
+
"react-native": "./src/providers/pinpoint/index.ts"
|
|
56
|
+
},
|
|
57
|
+
"./kinesis": {
|
|
58
|
+
"types": "./dist/esm/providers/kinesis/index.d.ts",
|
|
59
|
+
"import": "./dist/esm/providers/kinesis/index.mjs",
|
|
60
|
+
"require": "./dist/cjs/providers/kinesis/index.js",
|
|
61
|
+
"react-native": "./src/providers/kinesis/index.ts"
|
|
62
|
+
},
|
|
63
|
+
"./kinesis-firehose": {
|
|
64
|
+
"types": "./dist/esm/providers/kinesis-firehose/index.d.ts",
|
|
65
|
+
"import": "./dist/esm/providers/kinesis-firehose/index.mjs",
|
|
66
|
+
"require": "./dist/cjs/providers/kinesis-firehose/index.js",
|
|
67
|
+
"react-native": "./src/providers/kinesis-firehose/index.ts"
|
|
68
|
+
},
|
|
69
|
+
"./personalize": {
|
|
70
|
+
"types": "./dist/esm/providers/personalize/index.d.ts",
|
|
71
|
+
"import": "./dist/esm/providers/personalize/index.mjs",
|
|
72
|
+
"require": "./dist/cjs/providers/personalize/index.js",
|
|
73
|
+
"react-native": "./src/providers/personalize/index.ts"
|
|
74
|
+
},
|
|
75
|
+
"./package.json": "./package.json"
|
|
76
|
+
},
|
|
77
|
+
"repository": {
|
|
78
|
+
"type": "git",
|
|
79
|
+
"url": "https://github.com/aws-amplify/amplify-js.git"
|
|
80
|
+
},
|
|
81
|
+
"author": "Amazon Web Services",
|
|
82
|
+
"license": "Apache-2.0",
|
|
83
|
+
"bugs": {
|
|
84
|
+
"url": "https://github.com/aws/aws-amplify/issues"
|
|
85
|
+
},
|
|
86
|
+
"homepage": "https://aws-amplify.github.io/",
|
|
87
|
+
"files": [
|
|
88
|
+
"dist/cjs",
|
|
89
|
+
"dist/esm",
|
|
90
|
+
"src",
|
|
91
|
+
"pinpoint",
|
|
92
|
+
"kinesis",
|
|
93
|
+
"kinesis-firehose",
|
|
94
|
+
"personalize"
|
|
95
|
+
],
|
|
96
|
+
"dependencies": {
|
|
97
|
+
"@aws-sdk/client-firehose": "3.398.0",
|
|
98
|
+
"@aws-sdk/client-kinesis": "3.398.0",
|
|
99
|
+
"@aws-sdk/client-personalize-events": "3.398.0",
|
|
100
|
+
"@smithy/util-utf8": "2.0.0",
|
|
101
|
+
"tslib": "^2.5.0"
|
|
102
|
+
},
|
|
103
|
+
"peerDependencies": {
|
|
104
|
+
"@aws-amplify/core": "^6.0.0"
|
|
105
|
+
},
|
|
106
|
+
"devDependencies": {
|
|
107
|
+
"@aws-amplify/core": "6.0.10",
|
|
108
|
+
"@aws-amplify/react-native": "1.0.10",
|
|
109
|
+
"@aws-sdk/types": "3.398.0",
|
|
110
|
+
"@rollup/plugin-typescript": "11.1.5",
|
|
111
|
+
"rollup": "3.29.4",
|
|
112
|
+
"typescript": "5.0.2"
|
|
113
|
+
},
|
|
114
|
+
"gitHead": "954287b65ed268a8b37ec236db4a9e5701665c53"
|
|
115
115
|
}
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import {
|
|
5
|
+
AWSCredentials,
|
|
6
|
+
haveCredentialsChanged
|
|
7
|
+
} from '@aws-amplify/core/internals/utils';
|
|
6
8
|
import { KinesisClient, PutRecordsCommand } from '@aws-sdk/client-kinesis';
|
|
9
|
+
import { KinesisBufferEvent, KinesisEventBufferConfig } from '../types';
|
|
10
|
+
import {
|
|
11
|
+
EventBuffer,
|
|
12
|
+
groupBy,
|
|
13
|
+
IAnalyticsClient
|
|
14
|
+
} from '../../../utils';
|
|
7
15
|
|
|
8
16
|
/**
|
|
9
17
|
* These Records hold cached event buffers and AWS clients.
|
|
@@ -14,7 +22,7 @@ import { KinesisClient, PutRecordsCommand } from '@aws-sdk/client-kinesis';
|
|
|
14
22
|
* When a new session is initiated, the previous ones should be released.
|
|
15
23
|
* */
|
|
16
24
|
const eventBufferMap: Record<string, EventBuffer<KinesisBufferEvent>> = {};
|
|
17
|
-
const cachedClients: Record<string, KinesisClient> = {};
|
|
25
|
+
const cachedClients: Record<string, [KinesisClient, AWSCredentials]> = {};
|
|
18
26
|
|
|
19
27
|
const createKinesisPutRecordsCommand = (
|
|
20
28
|
streamName: string,
|
|
@@ -67,19 +75,31 @@ export const getEventBuffer = ({
|
|
|
67
75
|
userAgentValue,
|
|
68
76
|
}: KinesisEventBufferConfig): EventBuffer<KinesisBufferEvent> => {
|
|
69
77
|
const sessionIdentityKey = [region, identityId].filter(x => !!x).join('-');
|
|
78
|
+
const [ cachedClient, cachedCredentials ] = cachedClients[sessionIdentityKey] ?? [];
|
|
79
|
+
let credentialsHaveChanged = false;
|
|
70
80
|
|
|
71
|
-
if
|
|
81
|
+
// Check if credentials have changed for the cached client
|
|
82
|
+
if (cachedClient) {
|
|
83
|
+
credentialsHaveChanged = haveCredentialsChanged(cachedCredentials, credentials);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (!eventBufferMap[sessionIdentityKey] || credentialsHaveChanged) {
|
|
72
87
|
const getKinesisClient = (): IAnalyticsClient<KinesisBufferEvent> => {
|
|
73
|
-
if (!
|
|
74
|
-
cachedClients[sessionIdentityKey] =
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
88
|
+
if (!cachedClient || credentialsHaveChanged) {
|
|
89
|
+
cachedClients[sessionIdentityKey] = [
|
|
90
|
+
new KinesisClient({
|
|
91
|
+
credentials,
|
|
92
|
+
region,
|
|
93
|
+
customUserAgent: userAgentValue,
|
|
94
|
+
}),
|
|
95
|
+
credentials
|
|
96
|
+
];
|
|
79
97
|
}
|
|
80
98
|
|
|
99
|
+
const [ kinesisClient ] = cachedClients[sessionIdentityKey];
|
|
100
|
+
|
|
81
101
|
return events =>
|
|
82
|
-
submitEvents(events,
|
|
102
|
+
submitEvents(events, kinesisClient, resendLimit);
|
|
83
103
|
};
|
|
84
104
|
|
|
85
105
|
// create new session
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
AWSCredentials,
|
|
6
|
+
haveCredentialsChanged
|
|
7
|
+
} from '@aws-amplify/core/internals/utils';
|
|
5
8
|
import {
|
|
6
9
|
FirehoseClient,
|
|
7
10
|
PutRecordBatchCommand,
|
|
8
11
|
} from '@aws-sdk/client-firehose';
|
|
12
|
+
import {
|
|
13
|
+
EventBuffer,
|
|
14
|
+
groupBy,
|
|
15
|
+
IAnalyticsClient
|
|
16
|
+
} from '../../../utils';
|
|
9
17
|
import {
|
|
10
18
|
KinesisFirehoseBufferEvent,
|
|
11
19
|
KinesisFirehoseEventBufferConfig,
|
|
@@ -23,7 +31,7 @@ const eventBufferMap: Record<
|
|
|
23
31
|
string,
|
|
24
32
|
EventBuffer<KinesisFirehoseBufferEvent>
|
|
25
33
|
> = {};
|
|
26
|
-
const cachedClients: Record<string, FirehoseClient> = {};
|
|
34
|
+
const cachedClients: Record<string, [FirehoseClient, AWSCredentials]> = {};
|
|
27
35
|
|
|
28
36
|
const createPutRecordsBatchCommand = (
|
|
29
37
|
streamName: string,
|
|
@@ -76,18 +84,29 @@ export const getEventBuffer = ({
|
|
|
76
84
|
userAgentValue,
|
|
77
85
|
}: KinesisFirehoseEventBufferConfig): EventBuffer<KinesisFirehoseBufferEvent> => {
|
|
78
86
|
const sessionIdentityKey = [region, identityId].filter(id => !!id).join('-');
|
|
87
|
+
const [ cachedClient, cachedCredentials ] = cachedClients[sessionIdentityKey] ?? [];
|
|
88
|
+
let credentialsHaveChanged = false;
|
|
79
89
|
|
|
80
|
-
if
|
|
90
|
+
// Check if credentials have changed for the cached client
|
|
91
|
+
if (cachedClient) {
|
|
92
|
+
credentialsHaveChanged = haveCredentialsChanged(cachedCredentials, credentials);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (!eventBufferMap[sessionIdentityKey] || credentialsHaveChanged) {
|
|
81
96
|
const getClient = (): IAnalyticsClient<KinesisFirehoseBufferEvent> => {
|
|
82
|
-
if (!
|
|
83
|
-
cachedClients[sessionIdentityKey] =
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
97
|
+
if (!cachedClient || credentialsHaveChanged) {
|
|
98
|
+
cachedClients[sessionIdentityKey] = [
|
|
99
|
+
new FirehoseClient({
|
|
100
|
+
region,
|
|
101
|
+
credentials,
|
|
102
|
+
customUserAgent: userAgentValue,
|
|
103
|
+
}),
|
|
104
|
+
credentials
|
|
105
|
+
];
|
|
88
106
|
}
|
|
89
107
|
|
|
90
|
-
const firehoseClient = cachedClients[sessionIdentityKey];
|
|
108
|
+
const [ firehoseClient ] = cachedClients[sessionIdentityKey];
|
|
109
|
+
|
|
91
110
|
return events => submitEvents(events, firehoseClient, resendLimit);
|
|
92
111
|
};
|
|
93
112
|
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import {
|
|
5
|
+
AWSCredentials,
|
|
6
|
+
haveCredentialsChanged
|
|
7
|
+
} from '@aws-amplify/core/internals/utils';
|
|
6
8
|
import {
|
|
7
9
|
PersonalizeEventsClient,
|
|
8
10
|
PutEventsCommand,
|
|
9
11
|
} from '@aws-sdk/client-personalize-events';
|
|
12
|
+
import {
|
|
13
|
+
EventBuffer,
|
|
14
|
+
groupBy,
|
|
15
|
+
IAnalyticsClient
|
|
16
|
+
} from '../../../utils';
|
|
17
|
+
import { PersonalizeBufferConfig, PersonalizeBufferEvent } from '../types';
|
|
10
18
|
|
|
11
19
|
/**
|
|
12
20
|
* These Records hold cached event buffers and AWS clients.
|
|
@@ -17,7 +25,7 @@ import {
|
|
|
17
25
|
* When a new session is initiated, the previous ones should be released.
|
|
18
26
|
* */
|
|
19
27
|
const eventBufferMap: Record<string, EventBuffer<PersonalizeBufferEvent>> = {};
|
|
20
|
-
const cachedClients: Record<string, PersonalizeEventsClient> = {};
|
|
28
|
+
const cachedClients: Record<string, [PersonalizeEventsClient, AWSCredentials]> = {};
|
|
21
29
|
|
|
22
30
|
const DELIMITER = '#';
|
|
23
31
|
|
|
@@ -71,17 +79,30 @@ export const getEventBuffer = ({
|
|
|
71
79
|
userAgentValue,
|
|
72
80
|
}: PersonalizeBufferConfig): EventBuffer<PersonalizeBufferEvent> => {
|
|
73
81
|
const sessionIdentityKey = [region, identityId].filter(x => !!x).join('-');
|
|
82
|
+
const [ cachedClient, cachedCredentials ] = cachedClients[sessionIdentityKey] ?? [];
|
|
83
|
+
let credentialsHaveChanged = false;
|
|
84
|
+
|
|
85
|
+
// Check if credentials have changed for the cached client
|
|
86
|
+
if (cachedClient) {
|
|
87
|
+
credentialsHaveChanged = haveCredentialsChanged(cachedCredentials, credentials);
|
|
88
|
+
}
|
|
74
89
|
|
|
75
|
-
if (!eventBufferMap[sessionIdentityKey]) {
|
|
90
|
+
if (!eventBufferMap[sessionIdentityKey] || credentialsHaveChanged) {
|
|
76
91
|
const getClient = (): IAnalyticsClient<PersonalizeBufferEvent> => {
|
|
77
|
-
if (!
|
|
78
|
-
cachedClients[sessionIdentityKey] =
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
92
|
+
if (!cachedClient || credentialsHaveChanged) {
|
|
93
|
+
cachedClients[sessionIdentityKey] = [
|
|
94
|
+
new PersonalizeEventsClient({
|
|
95
|
+
region,
|
|
96
|
+
credentials,
|
|
97
|
+
customUserAgent: userAgentValue,
|
|
98
|
+
}),
|
|
99
|
+
credentials
|
|
100
|
+
];
|
|
83
101
|
}
|
|
84
|
-
|
|
102
|
+
|
|
103
|
+
const [ personalizeClient ] = cachedClients[sessionIdentityKey];
|
|
104
|
+
|
|
105
|
+
return events => submitEvents(events, personalizeClient);
|
|
85
106
|
};
|
|
86
107
|
|
|
87
108
|
eventBufferMap[sessionIdentityKey] =
|