@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.
- package/lib/apis/disable.js +1 -1
- package/lib/apis/enable.js +1 -1
- package/lib/errors/AnalyticsError.js +7 -11
- package/lib/errors/assertValidationError.js +6 -6
- package/lib/errors/validation.js +10 -11
- package/lib/providers/kinesis/apis/flushEvents.js +20 -23
- package/lib/providers/kinesis/apis/record.js +24 -26
- package/lib/providers/kinesis/utils/getEventBuffer.js +39 -70
- package/lib/providers/kinesis/utils/resolveConfig.js +14 -13
- package/lib/providers/kinesis-firehose/apis/flushEvents.js +19 -22
- package/lib/providers/kinesis-firehose/apis/record.js +22 -24
- package/lib/providers/kinesis-firehose/utils/getEventBuffer.js +39 -68
- package/lib/providers/kinesis-firehose/utils/resolveConfig.js +14 -13
- package/lib/providers/personalize/apis/flushEvents.js +18 -21
- package/lib/providers/personalize/apis/record.js +55 -71
- package/lib/providers/personalize/utils/autoTrackMedia.js +96 -98
- package/lib/providers/personalize/utils/cachedSession.js +30 -42
- package/lib/providers/personalize/utils/getEventBuffer.js +35 -62
- package/lib/providers/personalize/utils/resolveConfig.js +14 -13
- package/lib/providers/pinpoint/apis/configureAutoTrack.js +6 -6
- package/lib/providers/pinpoint/apis/flushEvents.js +10 -13
- package/lib/providers/pinpoint/apis/identifyUser.js +18 -30
- package/lib/providers/pinpoint/apis/record.js +15 -16
- package/lib/providers/pinpoint/utils/resolveConfig.js +5 -6
- package/lib/providers/pinpoint/utils/resolveCredentials.js +7 -15
- package/lib/setupTests.js +1 -1
- package/lib/trackers/EventTracker.js +39 -45
- package/lib/trackers/PageViewTracker.js +41 -45
- package/lib/trackers/SessionTracker.js +25 -31
- package/lib/trackers/SessionTracker.native.js +25 -31
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/utils/eventBuffer/EventBuffer.js +34 -62
- package/lib/utils/groupBy.js +4 -7
- package/lib/utils/resolveCredentials.js +7 -15
- package/lib/utils/statusHelpers.js +4 -4
- package/lib/utils/trackerConfigHelpers.js +2 -2
- package/lib/utils/trackerConfigHelpers.native.js +2 -2
- package/lib/utils/trackerHelpers.js +5 -5
- package/lib/utils/userAgent.js +3 -3
- package/lib-esm/apis/disable.js +1 -1
- package/lib-esm/apis/enable.js +1 -1
- package/lib-esm/errors/AnalyticsError.js +6 -11
- package/lib-esm/errors/assertValidationError.js +4 -4
- package/lib-esm/errors/validation.js +10 -11
- package/lib-esm/providers/kinesis/apis/flushEvents.js +15 -18
- package/lib-esm/providers/kinesis/apis/record.js +18 -20
- package/lib-esm/providers/kinesis/utils/constants.js +1 -1
- package/lib-esm/providers/kinesis/utils/getEventBuffer.js +37 -68
- package/lib-esm/providers/kinesis/utils/resolveConfig.js +11 -10
- package/lib-esm/providers/kinesis-firehose/apis/flushEvents.js +15 -18
- package/lib-esm/providers/kinesis-firehose/apis/record.js +17 -19
- package/lib-esm/providers/kinesis-firehose/utils/constants.js +1 -1
- package/lib-esm/providers/kinesis-firehose/utils/getEventBuffer.js +37 -66
- package/lib-esm/providers/kinesis-firehose/utils/resolveConfig.js +11 -10
- package/lib-esm/providers/personalize/apis/flushEvents.js +14 -17
- package/lib-esm/providers/personalize/apis/record.js +50 -66
- package/lib-esm/providers/personalize/utils/autoTrackMedia.js +94 -96
- package/lib-esm/providers/personalize/utils/cachedSession.js +28 -40
- package/lib-esm/providers/personalize/utils/constants.js +4 -4
- package/lib-esm/providers/personalize/utils/getEventBuffer.js +33 -60
- package/lib-esm/providers/personalize/utils/resolveConfig.js +11 -10
- package/lib-esm/providers/pinpoint/apis/configureAutoTrack.js +4 -4
- package/lib-esm/providers/pinpoint/apis/flushEvents.js +5 -8
- package/lib-esm/providers/pinpoint/apis/identifyUser.js +14 -26
- package/lib-esm/providers/pinpoint/apis/record.js +9 -10
- package/lib-esm/providers/pinpoint/utils/resolveConfig.js +3 -4
- package/lib-esm/providers/pinpoint/utils/resolveCredentials.js +5 -13
- package/lib-esm/setupTests.js +1 -1
- package/lib-esm/trackers/EventTracker.js +37 -44
- package/lib-esm/trackers/PageViewTracker.js +39 -44
- package/lib-esm/trackers/SessionTracker.js +22 -29
- package/lib-esm/trackers/SessionTracker.native.js +22 -29
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/utils/eventBuffer/EventBuffer.js +33 -62
- package/lib-esm/utils/groupBy.js +4 -7
- package/lib-esm/utils/resolveCredentials.js +5 -13
- package/lib-esm/utils/statusHelpers.js +4 -4
- package/lib-esm/utils/trackerConfigHelpers.js +1 -1
- package/lib-esm/utils/trackerConfigHelpers.native.js +1 -1
- package/lib-esm/utils/trackerHelpers.js +4 -4
- package/lib-esm/utils/userAgent.js +2 -2
- package/package.json +6 -9
- package/src/providers/kinesis/utils/getEventBuffer.ts +6 -7
- package/src/providers/kinesis-firehose/utils/getEventBuffer.ts +6 -7
- package/src/providers/personalize/utils/getEventBuffer.ts +6 -7
- package/src/trackers/SessionTracker.native.ts +2 -3
- package/src/trackers/SessionTracker.ts +2 -3
package/lib/apis/disable.js
CHANGED
package/lib/apis/enable.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
18
|
-
Object.setPrototypeOf(
|
|
19
|
-
return _this;
|
|
15
|
+
this.constructor = AnalyticsError;
|
|
16
|
+
Object.setPrototypeOf(this, AnalyticsError.prototype);
|
|
20
17
|
}
|
|
21
|
-
|
|
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
|
-
|
|
7
|
-
|
|
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
|
-
|
|
12
|
+
const { message: defaultMessage, recoverySuggestion } = validation_1.validationErrorMap[name];
|
|
13
13
|
if (!assertion) {
|
|
14
14
|
throw new AnalyticsError_1.AnalyticsError({
|
|
15
|
-
name
|
|
16
|
-
message: message
|
|
17
|
-
recoverySuggestion
|
|
15
|
+
name,
|
|
16
|
+
message: message ?? defaultMessage,
|
|
17
|
+
recoverySuggestion,
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
}
|
package/lib/errors/validation.js
CHANGED
|
@@ -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 =
|
|
19
|
-
|
|
17
|
+
exports.validationErrorMap = {
|
|
18
|
+
[AnalyticsValidationErrorCode.NoAppId]: {
|
|
20
19
|
message: 'Missing application id.',
|
|
21
20
|
},
|
|
22
|
-
|
|
21
|
+
[AnalyticsValidationErrorCode.NoCredentials]: {
|
|
23
22
|
message: 'Credentials should not be empty.',
|
|
24
23
|
},
|
|
25
|
-
|
|
24
|
+
[AnalyticsValidationErrorCode.NoEventName]: {
|
|
26
25
|
message: 'Events must specify a name.',
|
|
27
26
|
},
|
|
28
|
-
|
|
27
|
+
[AnalyticsValidationErrorCode.NoRegion]: {
|
|
29
28
|
message: 'Missing region.',
|
|
30
29
|
},
|
|
31
|
-
|
|
30
|
+
[AnalyticsValidationErrorCode.InvalidTracker]: {
|
|
32
31
|
message: 'Invalid tracker type specified.',
|
|
33
32
|
},
|
|
34
|
-
|
|
33
|
+
[AnalyticsValidationErrorCode.UnsupportedPlatform]: {
|
|
35
34
|
message: 'Only session tracking is supported on React Native.',
|
|
36
35
|
},
|
|
37
|
-
|
|
36
|
+
[AnalyticsValidationErrorCode.InvalidFlushSize]: {
|
|
38
37
|
message: 'Invalid FlushSize, it should be smaller than BufferSize',
|
|
39
38
|
},
|
|
40
|
-
|
|
39
|
+
[AnalyticsValidationErrorCode.NoTrackingId]: {
|
|
41
40
|
message: 'A trackingId is required to use Amazon Personalize',
|
|
42
41
|
},
|
|
43
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
20
|
-
|
|
19
|
+
const flushEvents = () => {
|
|
20
|
+
const { region, flushSize, flushInterval, bufferSize, resendLimit } = (0, resolveConfig_1.resolveConfig)();
|
|
21
21
|
(0, utils_1.resolveCredentials)()
|
|
22
|
-
.then(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
20
|
-
|
|
18
|
+
const timestamp = Date.now();
|
|
19
|
+
const { region, bufferSize, flushSize, flushInterval, resendLimit } = (0, resolveConfig_1.resolveConfig)();
|
|
21
20
|
(0, utils_1.resolveCredentials)()
|
|
22
|
-
.then(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
|
36
|
-
streamName
|
|
37
|
-
partitionKey
|
|
33
|
+
region,
|
|
34
|
+
streamName,
|
|
35
|
+
partitionKey,
|
|
38
36
|
event: ArrayBuffer.isView(data) ? data : (0, util_utf8_1.fromUtf8)(JSON.stringify(data)),
|
|
39
|
-
timestamp
|
|
37
|
+
timestamp,
|
|
40
38
|
retryCount: 0,
|
|
41
39
|
});
|
|
42
40
|
})
|
|
43
|
-
.catch(
|
|
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
|
-
|
|
7
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
29
|
-
|
|
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
|
-
|
|
44
|
+
const getKinesisClient = () => {
|
|
66
45
|
if (!cachedClients[sessionIdentityKey]) {
|
|
67
46
|
cachedClients[sessionIdentityKey] = new client_kinesis_1.KinesisClient({
|
|
68
|
-
credentials
|
|
69
|
-
region
|
|
47
|
+
credentials,
|
|
48
|
+
region,
|
|
70
49
|
customUserAgent: userAgentValue,
|
|
71
50
|
});
|
|
72
51
|
}
|
|
73
|
-
return
|
|
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
|
|
80
|
-
flushSize
|
|
81
|
-
bufferSize
|
|
56
|
+
flushInterval,
|
|
57
|
+
flushSize,
|
|
58
|
+
bufferSize,
|
|
82
59
|
}, getKinesisClient);
|
|
83
60
|
// release other sessions
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
|
18
|
-
bufferSize
|
|
19
|
-
flushSize
|
|
20
|
-
flushInterval
|
|
21
|
-
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
19
|
-
|
|
18
|
+
const flushEvents = () => {
|
|
19
|
+
const { region, flushSize, flushInterval, bufferSize, resendLimit } = (0, utils_1.resolveConfig)();
|
|
20
20
|
(0, utils_2.resolveCredentials)()
|
|
21
|
-
.then(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
19
|
-
|
|
17
|
+
const timestamp = Date.now();
|
|
18
|
+
const { region, bufferSize, flushSize, flushInterval, resendLimit } = (0, utils_1.resolveConfig)();
|
|
20
19
|
(0, utils_2.resolveCredentials)()
|
|
21
|
-
.then(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
|
35
|
-
streamName
|
|
32
|
+
region,
|
|
33
|
+
streamName,
|
|
36
34
|
event: ArrayBuffer.isView(data) ? data : (0, util_utf8_1.fromUtf8)(JSON.stringify(data)),
|
|
37
|
-
timestamp
|
|
35
|
+
timestamp,
|
|
38
36
|
retryCount: 0,
|
|
39
37
|
});
|
|
40
38
|
})
|
|
41
|
-
.catch(
|
|
39
|
+
.catch(e => {
|
|
42
40
|
logger.warn('Failed to record event.', e);
|
|
43
41
|
});
|
|
44
42
|
};
|