@aws-amplify/analytics 7.0.1-console-preview.5f040a2.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,9 +1,4 @@
|
|
|
1
1
|
export declare const resolveCredentials: () => Promise<{
|
|
2
|
-
credentials:
|
|
3
|
-
accessKeyId: string;
|
|
4
|
-
secretAccessKey: string;
|
|
5
|
-
sessionToken?: string | undefined;
|
|
6
|
-
expiration?: Date | undefined;
|
|
7
|
-
};
|
|
2
|
+
credentials: import("@aws-amplify/core/lib-esm/libraryUtils").AWSCredentials;
|
|
8
3
|
identityId: string | undefined;
|
|
9
4
|
}>;
|
|
@@ -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;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { __awaiter, __generator } from "tslib";
|
|
3
4
|
import { autoTrackMedia, getEventBuffer, resolveCachedSession, resolveConfig, updateCachedSession, } from '../utils';
|
|
4
5
|
import { getAnalyticsUserAgentString, isAnalyticsEnabled, resolveCredentials, } from '../../../utils';
|
|
5
6
|
import { AnalyticsAction, ConsoleLogger, } from '@aws-amplify/core/internals/utils';
|
|
@@ -15,52 +16,65 @@ export var record = function (_a) {
|
|
|
15
16
|
resolveCredentials()
|
|
16
17
|
.then(function (_a) {
|
|
17
18
|
var credentials = _a.credentials, identityId = _a.identityId;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
19
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
20
|
+
var timestamp, _b, cachedSessionId, cachedUserId, _c, updatedSessionId, updatedUserId, eventBuffer;
|
|
21
|
+
return __generator(this, function (_d) {
|
|
22
|
+
switch (_d.label) {
|
|
23
|
+
case 0:
|
|
24
|
+
timestamp = Date.now();
|
|
25
|
+
return [4 /*yield*/, resolveCachedSession()];
|
|
26
|
+
case 1:
|
|
27
|
+
_b = _d.sent(), cachedSessionId = _b.sessionId, cachedUserId = _b.userId;
|
|
28
|
+
if (eventType === IDENTIFY_EVENT_TYPE) {
|
|
29
|
+
updateCachedSession(typeof properties.userId === 'string' ? properties.userId : '', cachedSessionId, cachedUserId);
|
|
30
|
+
}
|
|
31
|
+
else if (!!userId) {
|
|
32
|
+
updateCachedSession(userId, cachedSessionId, cachedUserId);
|
|
33
|
+
}
|
|
34
|
+
return [4 /*yield*/, resolveCachedSession()];
|
|
35
|
+
case 2:
|
|
36
|
+
_c = _d.sent(), updatedSessionId = _c.sessionId, updatedUserId = _c.userId;
|
|
37
|
+
eventBuffer = getEventBuffer({
|
|
38
|
+
region: region,
|
|
39
|
+
flushSize: flushSize,
|
|
40
|
+
flushInterval: flushInterval,
|
|
41
|
+
bufferSize: bufferSize,
|
|
42
|
+
credentials: credentials,
|
|
43
|
+
identityId: identityId,
|
|
44
|
+
userAgentValue: getAnalyticsUserAgentString(AnalyticsAction.Record),
|
|
45
|
+
});
|
|
46
|
+
if (eventType === MEDIA_AUTO_TRACK_EVENT_TYPE) {
|
|
47
|
+
autoTrackMedia({
|
|
48
|
+
trackingId: trackingId,
|
|
49
|
+
sessionId: updatedSessionId,
|
|
50
|
+
userId: updatedUserId,
|
|
51
|
+
event: {
|
|
52
|
+
eventId: eventId,
|
|
53
|
+
eventType: eventType,
|
|
54
|
+
properties: properties,
|
|
55
|
+
},
|
|
56
|
+
}, eventBuffer);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
eventBuffer.append({
|
|
60
|
+
trackingId: trackingId,
|
|
61
|
+
sessionId: updatedSessionId,
|
|
62
|
+
userId: updatedUserId,
|
|
63
|
+
event: {
|
|
64
|
+
eventId: eventId,
|
|
65
|
+
eventType: eventType,
|
|
66
|
+
properties: properties,
|
|
67
|
+
},
|
|
68
|
+
timestamp: timestamp,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
if (eventBuffer.length >= bufferSize) {
|
|
72
|
+
eventBuffer.flushAll();
|
|
73
|
+
}
|
|
74
|
+
return [2 /*return*/];
|
|
75
|
+
}
|
|
59
76
|
});
|
|
60
|
-
}
|
|
61
|
-
if (eventBuffer.length >= bufferSize) {
|
|
62
|
-
eventBuffer.flushAll();
|
|
63
|
-
}
|
|
77
|
+
});
|
|
64
78
|
})
|
|
65
79
|
.catch(function (e) {
|
|
66
80
|
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;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { __awaiter, __generator } from "tslib";
|
|
3
4
|
import { Cache } from '@aws-amplify/core';
|
|
4
|
-
import { isBrowser } from '@aws-amplify/core/internals/utils';
|
|
5
|
-
import { v4 as uuid } from 'uuid';
|
|
5
|
+
import { isBrowser, amplifyUuid } from '@aws-amplify/core/internals/utils';
|
|
6
6
|
var PERSONALIZE_CACHE_USERID = '_awsct_uid';
|
|
7
7
|
var PERSONALIZE_CACHE_SESSIONID = '_awsct_sid';
|
|
8
8
|
var DEFAULT_CACHE_PREFIX = 'personalize';
|
|
@@ -18,18 +18,27 @@ var setCache = function (key, value) {
|
|
|
18
18
|
expires: expiredAt.getTime(),
|
|
19
19
|
});
|
|
20
20
|
};
|
|
21
|
-
export var resolveCachedSession = function (
|
|
22
|
-
var sessionId
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
21
|
+
export var resolveCachedSession = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
22
|
+
var sessionId, userId;
|
|
23
|
+
return __generator(this, function (_a) {
|
|
24
|
+
switch (_a.label) {
|
|
25
|
+
case 0: return [4 /*yield*/, getCache(PERSONALIZE_CACHE_SESSIONID)];
|
|
26
|
+
case 1:
|
|
27
|
+
sessionId = _a.sent();
|
|
28
|
+
if (!sessionId) {
|
|
29
|
+
sessionId = amplifyUuid();
|
|
30
|
+
setCache(PERSONALIZE_CACHE_SESSIONID, sessionId);
|
|
31
|
+
}
|
|
32
|
+
return [4 /*yield*/, getCache(PERSONALIZE_CACHE_USERID)];
|
|
33
|
+
case 2:
|
|
34
|
+
userId = _a.sent();
|
|
35
|
+
return [2 /*return*/, {
|
|
36
|
+
sessionId: sessionId,
|
|
37
|
+
userId: userId,
|
|
38
|
+
}];
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}); };
|
|
33
42
|
export var updateCachedSession = function (newUserId, currentSessionId, currentUserId) {
|
|
34
43
|
var isNoCachedSession = !currentSessionId;
|
|
35
44
|
var isSignOutCase = !newUserId && !currentUserId;
|
|
@@ -37,7 +46,7 @@ export var updateCachedSession = function (newUserId, currentSessionId, currentU
|
|
|
37
46
|
var isRequireNewSession = isNoCachedSession || isSignOutCase || isSwitchUserCase;
|
|
38
47
|
var isRequireUpdateSession = !!currentSessionId && !currentUserId && !!newUserId;
|
|
39
48
|
if (isRequireNewSession) {
|
|
40
|
-
var newSessionId =
|
|
49
|
+
var newSessionId = amplifyUuid();
|
|
41
50
|
setCache(PERSONALIZE_CACHE_SESSIONID, newSessionId);
|
|
42
51
|
setCache(PERSONALIZE_CACHE_USERID, newUserId);
|
|
43
52
|
}
|
|
@@ -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
|
}>;
|