@aws-amplify/analytics 7.0.1-console-preview.a1c533e.0 → 7.0.1-console-preview.23dc225.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/providers/kinesis/types/buffer.d.ts +2 -2
- package/lib/providers/kinesis-firehose/types/buffer.d.ts +2 -2
- package/lib/providers/personalize/apis/record.js +59 -45
- package/lib/providers/personalize/types/buffer.d.ts +2 -2
- package/lib/providers/personalize/utils/cachedSession.d.ts +2 -2
- package/lib/providers/personalize/utils/cachedSession.js +23 -14
- package/lib/providers/pinpoint/utils/resolveCredentials.d.ts +1 -6
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/utils/resolveCredentials.d.ts +1 -6
- package/lib-esm/providers/kinesis/types/buffer.d.ts +2 -2
- package/lib-esm/providers/kinesis-firehose/types/buffer.d.ts +2 -2
- package/lib-esm/providers/personalize/apis/record.js +59 -45
- package/lib-esm/providers/personalize/types/buffer.d.ts +2 -2
- package/lib-esm/providers/personalize/utils/cachedSession.d.ts +2 -2
- package/lib-esm/providers/personalize/utils/cachedSession.js +24 -15
- package/lib-esm/providers/pinpoint/utils/resolveCredentials.d.ts +1 -6
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/utils/resolveCredentials.d.ts +1 -6
- package/package.json +5 -7
- package/src/providers/kinesis/types/buffer.ts +2 -2
- package/src/providers/kinesis-firehose/types/buffer.ts +2 -2
- package/src/providers/personalize/apis/record.ts +3 -3
- package/src/providers/personalize/types/buffer.ts +2 -2
- package/src/providers/personalize/utils/cachedSession.ts +8 -7
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { AWSCredentials } from '@aws-amplify/core/internals/utils';
|
|
1
2
|
import { EventBufferConfig } from '../../../utils';
|
|
2
|
-
import { Credentials } from '@aws-sdk/types';
|
|
3
3
|
import { KinesisShard } from '../../../types';
|
|
4
4
|
export type KinesisBufferEvent = KinesisShard & {
|
|
5
5
|
event: Uint8Array;
|
|
@@ -8,7 +8,7 @@ export type KinesisBufferEvent = KinesisShard & {
|
|
|
8
8
|
};
|
|
9
9
|
export type KinesisEventBufferConfig = EventBufferConfig & {
|
|
10
10
|
region: string;
|
|
11
|
-
credentials:
|
|
11
|
+
credentials: AWSCredentials;
|
|
12
12
|
identityId?: string;
|
|
13
13
|
resendLimit?: number;
|
|
14
14
|
userAgentValue?: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EventBufferConfig } from '../../../utils';
|
|
2
2
|
import { KinesisStream } from '../../../types';
|
|
3
|
-
import {
|
|
3
|
+
import { AWSCredentials } from '@aws-amplify/core/internals/utils';
|
|
4
4
|
export type KinesisFirehoseBufferEvent = KinesisStream & {
|
|
5
5
|
event: Uint8Array;
|
|
6
6
|
retryCount: number;
|
|
@@ -8,7 +8,7 @@ export type KinesisFirehoseBufferEvent = KinesisStream & {
|
|
|
8
8
|
};
|
|
9
9
|
export type KinesisFirehoseEventBufferConfig = EventBufferConfig & {
|
|
10
10
|
region: string;
|
|
11
|
-
credentials:
|
|
11
|
+
credentials: AWSCredentials;
|
|
12
12
|
identityId?: string;
|
|
13
13
|
resendLimit?: number;
|
|
14
14
|
userAgentValue?: string;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.record = void 0;
|
|
6
|
+
var tslib_1 = require("tslib");
|
|
6
7
|
var utils_1 = require("../utils");
|
|
7
8
|
var utils_2 = require("../../../utils");
|
|
8
9
|
var utils_3 = require("@aws-amplify/core/internals/utils");
|
|
@@ -18,52 +19,65 @@ var record = function (_a) {
|
|
|
18
19
|
(0, utils_2.resolveCredentials)()
|
|
19
20
|
.then(function (_a) {
|
|
20
21
|
var credentials = _a.credentials, identityId = _a.identityId;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
22
|
+
return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
23
|
+
var timestamp, _b, cachedSessionId, cachedUserId, _c, updatedSessionId, updatedUserId, eventBuffer;
|
|
24
|
+
return tslib_1.__generator(this, function (_d) {
|
|
25
|
+
switch (_d.label) {
|
|
26
|
+
case 0:
|
|
27
|
+
timestamp = Date.now();
|
|
28
|
+
return [4 /*yield*/, (0, utils_1.resolveCachedSession)()];
|
|
29
|
+
case 1:
|
|
30
|
+
_b = _d.sent(), cachedSessionId = _b.sessionId, cachedUserId = _b.userId;
|
|
31
|
+
if (eventType === constants_1.IDENTIFY_EVENT_TYPE) {
|
|
32
|
+
(0, utils_1.updateCachedSession)(typeof properties.userId === 'string' ? properties.userId : '', cachedSessionId, cachedUserId);
|
|
33
|
+
}
|
|
34
|
+
else if (!!userId) {
|
|
35
|
+
(0, utils_1.updateCachedSession)(userId, cachedSessionId, cachedUserId);
|
|
36
|
+
}
|
|
37
|
+
return [4 /*yield*/, (0, utils_1.resolveCachedSession)()];
|
|
38
|
+
case 2:
|
|
39
|
+
_c = _d.sent(), updatedSessionId = _c.sessionId, updatedUserId = _c.userId;
|
|
40
|
+
eventBuffer = (0, utils_1.getEventBuffer)({
|
|
41
|
+
region: region,
|
|
42
|
+
flushSize: flushSize,
|
|
43
|
+
flushInterval: flushInterval,
|
|
44
|
+
bufferSize: bufferSize,
|
|
45
|
+
credentials: credentials,
|
|
46
|
+
identityId: identityId,
|
|
47
|
+
userAgentValue: (0, utils_2.getAnalyticsUserAgentString)(utils_3.AnalyticsAction.Record),
|
|
48
|
+
});
|
|
49
|
+
if (eventType === constants_1.MEDIA_AUTO_TRACK_EVENT_TYPE) {
|
|
50
|
+
(0, utils_1.autoTrackMedia)({
|
|
51
|
+
trackingId: trackingId,
|
|
52
|
+
sessionId: updatedSessionId,
|
|
53
|
+
userId: updatedUserId,
|
|
54
|
+
event: {
|
|
55
|
+
eventId: eventId,
|
|
56
|
+
eventType: eventType,
|
|
57
|
+
properties: properties,
|
|
58
|
+
},
|
|
59
|
+
}, eventBuffer);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
eventBuffer.append({
|
|
63
|
+
trackingId: trackingId,
|
|
64
|
+
sessionId: updatedSessionId,
|
|
65
|
+
userId: updatedUserId,
|
|
66
|
+
event: {
|
|
67
|
+
eventId: eventId,
|
|
68
|
+
eventType: eventType,
|
|
69
|
+
properties: properties,
|
|
70
|
+
},
|
|
71
|
+
timestamp: timestamp,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
if (eventBuffer.length >= bufferSize) {
|
|
75
|
+
eventBuffer.flushAll();
|
|
76
|
+
}
|
|
77
|
+
return [2 /*return*/];
|
|
78
|
+
}
|
|
62
79
|
});
|
|
63
|
-
}
|
|
64
|
-
if (eventBuffer.length >= bufferSize) {
|
|
65
|
-
eventBuffer.flushAll();
|
|
66
|
-
}
|
|
80
|
+
});
|
|
67
81
|
})
|
|
68
82
|
.catch(function (e) {
|
|
69
83
|
logger.warn('Failed to record event.', e);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PersonalizeEvent } from './';
|
|
2
2
|
import { EventBufferConfig } from '../../../utils';
|
|
3
|
-
import {
|
|
3
|
+
import { AWSCredentials } from '@aws-amplify/core/internals/utils';
|
|
4
4
|
export type PersonalizeBufferEvent = {
|
|
5
5
|
trackingId: string;
|
|
6
6
|
sessionId?: string;
|
|
@@ -10,7 +10,7 @@ export type PersonalizeBufferEvent = {
|
|
|
10
10
|
};
|
|
11
11
|
export type PersonalizeBufferConfig = EventBufferConfig & {
|
|
12
12
|
region: string;
|
|
13
|
-
credentials:
|
|
13
|
+
credentials: AWSCredentials;
|
|
14
14
|
identityId?: string;
|
|
15
15
|
userAgentValue?: string;
|
|
16
16
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export declare const resolveCachedSession: (
|
|
1
|
+
export declare const resolveCachedSession: () => Promise<{
|
|
2
2
|
sessionId: string;
|
|
3
3
|
userId: string | undefined;
|
|
4
|
-
}
|
|
4
|
+
}>;
|
|
5
5
|
export declare const updateCachedSession: (newUserId?: string, currentSessionId?: string, currentUserId?: string) => void;
|
|
@@ -3,9 +3,9 @@
|
|
|
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");
|
|
6
7
|
var core_1 = require("@aws-amplify/core");
|
|
7
8
|
var utils_1 = require("@aws-amplify/core/internals/utils");
|
|
8
|
-
var uuid_1 = require("uuid");
|
|
9
9
|
var PERSONALIZE_CACHE_USERID = '_awsct_uid';
|
|
10
10
|
var PERSONALIZE_CACHE_SESSIONID = '_awsct_sid';
|
|
11
11
|
var DEFAULT_CACHE_PREFIX = 'personalize';
|
|
@@ -21,18 +21,27 @@ var setCache = function (key, value) {
|
|
|
21
21
|
expires: expiredAt.getTime(),
|
|
22
22
|
});
|
|
23
23
|
};
|
|
24
|
-
var resolveCachedSession = function (
|
|
25
|
-
var sessionId
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
+
}); };
|
|
36
45
|
exports.resolveCachedSession = resolveCachedSession;
|
|
37
46
|
var updateCachedSession = function (newUserId, currentSessionId, currentUserId) {
|
|
38
47
|
var isNoCachedSession = !currentSessionId;
|
|
@@ -41,7 +50,7 @@ var updateCachedSession = function (newUserId, currentSessionId, currentUserId)
|
|
|
41
50
|
var isRequireNewSession = isNoCachedSession || isSignOutCase || isSwitchUserCase;
|
|
42
51
|
var isRequireUpdateSession = !!currentSessionId && !currentUserId && !!newUserId;
|
|
43
52
|
if (isRequireNewSession) {
|
|
44
|
-
var newSessionId = (0,
|
|
53
|
+
var newSessionId = (0, utils_1.amplifyUuid)();
|
|
45
54
|
setCache(PERSONALIZE_CACHE_SESSIONID, newSessionId);
|
|
46
55
|
setCache(PERSONALIZE_CACHE_USERID, newUserId);
|
|
47
56
|
}
|
|
@@ -2,11 +2,6 @@
|
|
|
2
2
|
* @internal
|
|
3
3
|
*/
|
|
4
4
|
export declare const resolveCredentials: () => Promise<{
|
|
5
|
-
credentials:
|
|
6
|
-
accessKeyId: string;
|
|
7
|
-
secretAccessKey: string;
|
|
8
|
-
sessionToken?: string | undefined;
|
|
9
|
-
expiration?: Date | undefined;
|
|
10
|
-
};
|
|
5
|
+
credentials: import("@aws-amplify/core/lib-esm/libraryUtils").AWSCredentials;
|
|
11
6
|
identityId: string | undefined;
|
|
12
7
|
}>;
|