@croct/sdk 0.10.0 → 0.11.0-alpha
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/activeRecord.js +32 -36
- package/cache/fallbackCache.js +15 -32
- package/cache/inMemoryCache.js +9 -10
- package/cache/index.js +1 -1
- package/cache/localStorageCache.js +24 -25
- package/channel/beaconSocketChannel.d.ts +1 -1
- package/channel/beaconSocketChannel.js +49 -79
- package/channel/channel.d.ts +1 -1
- package/channel/encodedChannel.js +8 -10
- package/channel/guaranteedChannel.d.ts +4 -4
- package/channel/guaranteedChannel.js +41 -43
- package/channel/index.js +1 -1
- package/channel/queuedChannel.js +35 -64
- package/channel/retryChannel.d.ts +1 -1
- package/channel/retryChannel.js +44 -77
- package/channel/sandboxChannel.js +17 -18
- package/channel/socketChannel.d.ts +4 -4
- package/channel/socketChannel.js +77 -79
- package/cid/cachedAssigner.js +15 -27
- package/cid/fixedAssigner.js +5 -6
- package/cid/index.js +1 -1
- package/cid/remoteAssigner.js +23 -36
- package/constants.d.ts +3 -2
- package/constants.js +6 -5
- package/container.d.ts +13 -6
- package/container.js +152 -168
- package/contentFetcher.d.ts +59 -0
- package/contentFetcher.js +129 -0
- package/context.d.ts +3 -3
- package/context.js +36 -38
- package/error.js +2 -2
- package/evaluator.d.ts +33 -24
- package/evaluator.js +126 -117
- package/eventManager.d.ts +1 -1
- package/eventManager.js +14 -15
- package/facade/contentFetcherFacade.d.ts +27 -0
- package/facade/contentFetcherFacade.js +40 -0
- package/facade/evaluatorFacade.d.ts +13 -3
- package/facade/evaluatorFacade.js +57 -72
- package/facade/sdkFacade.d.ts +10 -3
- package/facade/sdkFacade.js +129 -141
- package/facade/sessionFacade.js +6 -7
- package/facade/sessionPatch.js +9 -13
- package/facade/trackerFacade.js +32 -38
- package/facade/userFacade.js +10 -11
- package/facade/userPatch.js +9 -13
- package/index.js +2 -2
- package/logging/consoleLogger.js +18 -35
- package/logging/index.js +1 -1
- package/logging/namespacedLogger.js +14 -15
- package/logging/nullLogger.js +10 -13
- package/namespacedStorage.js +30 -47
- package/package.json +13 -16
- package/patch.d.ts +1 -1
- package/queue/capacityRestrictedQueue.js +17 -18
- package/queue/inMemoryQueue.js +22 -28
- package/queue/index.js +1 -1
- package/queue/monitoredQueue.d.ts +2 -2
- package/queue/monitoredQueue.js +39 -40
- package/queue/persistentQueue.js +33 -38
- package/retry/arbitraryPolicy.js +8 -10
- package/retry/backoffPolicy.d.ts +1 -1
- package/retry/backoffPolicy.js +11 -13
- package/retry/index.js +1 -1
- package/retry/maxAttemptsPolicy.js +7 -8
- package/retry/neverPolicy.js +6 -9
- package/schema/attributeSchema.js +1 -1
- package/schema/contentFetcherSchemas.d.ts +2 -0
- package/schema/contentFetcherSchemas.js +22 -0
- package/schema/contentSchemas.js +1 -1
- package/schema/contextSchemas.js +1 -1
- package/schema/ecommerceSchemas.js +1 -1
- package/schema/evaluatorSchemas.d.ts +2 -0
- package/schema/{evaluationSchemas.js → evaluatorSchemas.js} +3 -3
- package/schema/eventSchemas.js +5 -7
- package/schema/index.d.ts +2 -1
- package/schema/index.js +3 -2
- package/schema/loggerSchema.js +1 -1
- package/schema/operationSchemas.js +8 -8
- package/schema/sdkFacadeSchemas.js +9 -6
- package/schema/sdkSchemas.js +8 -5
- package/schema/tokenSchema.js +5 -4
- package/schema/userSchema.js +2 -2
- package/sdk.d.ts +9 -3
- package/sdk.js +81 -127
- package/sdkEvents.d.ts +3 -3
- package/sourceLocation.d.ts +3 -3
- package/sourceLocation.js +13 -14
- package/tab.d.ts +5 -5
- package/tab.js +50 -80
- package/token/cachedTokenStore.js +9 -10
- package/token/inMemoryTokenStore.js +7 -8
- package/token/index.js +1 -1
- package/token/replicatedTokenStore.js +7 -8
- package/token/token.d.ts +9 -5
- package/token/token.js +63 -57
- package/tracker.d.ts +4 -4
- package/tracker.js +145 -122
- package/trackingEvents.d.ts +36 -36
- package/trackingEvents.js +12 -6
- package/transformer.js +1 -1
- package/utilityTypes.d.ts +2 -2
- package/uuid.js +9 -7
- package/validation/arrayType.d.ts +2 -2
- package/validation/arrayType.js +29 -27
- package/validation/booleanType.js +11 -15
- package/validation/functionType.js +11 -15
- package/validation/index.js +1 -1
- package/validation/jsonType.d.ts +2 -2
- package/validation/jsonType.js +61 -80
- package/validation/mixedSchema.js +4 -7
- package/validation/nullType.js +11 -15
- package/validation/numberType.d.ts +1 -1
- package/validation/numberType.js +23 -22
- package/validation/objectType.d.ts +1 -1
- package/validation/objectType.js +61 -72
- package/validation/schema.js +6 -10
- package/validation/stringType.d.ts +1 -1
- package/validation/stringType.js +36 -47
- package/validation/unionType.js +27 -77
- package/validation/violation.js +1 -2
- package/schema/evaluationSchemas.d.ts +0 -2
package/token/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ReplicatedTokenStore = exports.InMemoryTokenStore = exports.CachedTokenStore = void 0;
|
|
4
|
-
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
5
|
tslib_1.__exportStar(require("./token"), exports);
|
|
6
6
|
var cachedTokenStore_1 = require("./cachedTokenStore");
|
|
7
7
|
Object.defineProperty(exports, "CachedTokenStore", { enumerable: true, get: function () { return cachedTokenStore_1.CachedTokenStore; } });
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ReplicatedTokenStore = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
class ReplicatedTokenStore {
|
|
5
|
+
constructor(primary, secondary) {
|
|
6
6
|
this.primary = primary;
|
|
7
7
|
this.secondary = secondary;
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
getToken() {
|
|
10
10
|
return this.primary.getToken();
|
|
11
|
-
}
|
|
12
|
-
|
|
11
|
+
}
|
|
12
|
+
setToken(token) {
|
|
13
13
|
this.primary.setToken(token);
|
|
14
14
|
this.secondary.setToken(token);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
}());
|
|
15
|
+
}
|
|
16
|
+
}
|
|
18
17
|
exports.ReplicatedTokenStore = ReplicatedTokenStore;
|
package/token/token.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import { JsonObject } from '@croct/json';
|
|
2
|
+
export type Headers = {
|
|
2
3
|
typ: string;
|
|
3
4
|
alg: string;
|
|
4
5
|
kid?: string;
|
|
5
|
-
appId
|
|
6
|
+
appId?: string;
|
|
6
7
|
};
|
|
7
|
-
|
|
8
|
+
type Claims = {
|
|
8
9
|
iss: string;
|
|
9
10
|
aud: string | string[];
|
|
10
11
|
iat: number;
|
|
@@ -12,15 +13,17 @@ export declare type Claims = {
|
|
|
12
13
|
sub?: string;
|
|
13
14
|
jid?: string;
|
|
14
15
|
};
|
|
16
|
+
export type TokenPayload = JsonObject & Claims;
|
|
15
17
|
export declare class Token {
|
|
16
18
|
private readonly headers;
|
|
17
|
-
private readonly
|
|
19
|
+
private readonly payload;
|
|
18
20
|
private readonly signature;
|
|
19
21
|
private constructor();
|
|
20
22
|
static issue(appId: string, subject?: string | null, timestamp?: number): Token;
|
|
21
23
|
static parse(token: string): Token;
|
|
24
|
+
static of(headers: Headers, payload: TokenPayload, signature?: string): Token;
|
|
22
25
|
getHeaders(): Headers;
|
|
23
|
-
|
|
26
|
+
getPayload(): TokenPayload;
|
|
24
27
|
getSignature(): string;
|
|
25
28
|
isAnonymous(): boolean;
|
|
26
29
|
getSubject(): string | null;
|
|
@@ -39,3 +42,4 @@ export declare class FixedTokenProvider implements TokenProvider {
|
|
|
39
42
|
constructor(token: Token | null);
|
|
40
43
|
getToken(): Token | null;
|
|
41
44
|
}
|
|
45
|
+
export {};
|
package/token/token.js
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FixedTokenProvider = exports.Token = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
function Token(headers, claims, signature) {
|
|
10
|
-
if (signature === void 0) { signature = ''; }
|
|
4
|
+
const base64Url_1 = require("../base64Url");
|
|
5
|
+
const schema_1 = require("../schema");
|
|
6
|
+
const error_1 = require("../error");
|
|
7
|
+
class Token {
|
|
8
|
+
constructor(headers, payload, signature = '') {
|
|
11
9
|
this.headers = headers;
|
|
12
|
-
this.
|
|
10
|
+
this.payload = payload;
|
|
13
11
|
this.signature = signature;
|
|
14
12
|
}
|
|
15
|
-
|
|
16
|
-
if (subject === void 0) { subject = null; }
|
|
17
|
-
if (timestamp === void 0) { timestamp = Math.floor(Date.now() / 1000); }
|
|
13
|
+
static issue(appId, subject = null, timestamp = Math.floor(Date.now() / 1000)) {
|
|
18
14
|
if (timestamp < 0) {
|
|
19
15
|
throw new Error('The timestamp must be non-negative.');
|
|
20
16
|
}
|
|
@@ -25,75 +21,85 @@ var Token = /** @class */ (function () {
|
|
|
25
21
|
typ: 'JWT',
|
|
26
22
|
alg: 'none',
|
|
27
23
|
appId: appId,
|
|
28
|
-
},
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
}, {
|
|
25
|
+
iss: 'croct.io',
|
|
26
|
+
aud: 'croct.io',
|
|
27
|
+
iat: timestamp,
|
|
28
|
+
...(subject !== null ? { sub: subject } : null),
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
static parse(token) {
|
|
31
32
|
if (token === '') {
|
|
32
33
|
throw new Error('The token cannot be empty.');
|
|
33
34
|
}
|
|
34
|
-
|
|
35
|
+
const parts = token.split('.', 3);
|
|
35
36
|
// This token is invalid
|
|
36
37
|
if (parts.length < 2) {
|
|
37
38
|
throw new Error('The token is malformed.');
|
|
38
39
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
let headers;
|
|
41
|
+
let payload;
|
|
42
|
+
let signature;
|
|
42
43
|
try {
|
|
43
44
|
headers = JSON.parse((0, base64Url_1.base64UrlDecode)(parts[0]));
|
|
44
|
-
|
|
45
|
+
payload = JSON.parse((0, base64Url_1.base64UrlDecode)(parts[1]));
|
|
45
46
|
if (parts.length === 3) {
|
|
46
47
|
signature = (0, base64Url_1.base64UrlDecode)(parts[2]);
|
|
47
48
|
}
|
|
48
49
|
}
|
|
49
|
-
catch
|
|
50
|
+
catch {
|
|
50
51
|
throw new Error('The token is corrupted.');
|
|
51
52
|
}
|
|
53
|
+
return Token.of(headers, payload, signature);
|
|
54
|
+
}
|
|
55
|
+
static of(headers, payload, signature = '') {
|
|
52
56
|
try {
|
|
53
|
-
schema_1.tokenSchema.validate({
|
|
57
|
+
schema_1.tokenSchema.validate({
|
|
58
|
+
headers: headers,
|
|
59
|
+
payload: payload,
|
|
60
|
+
signature: signature,
|
|
61
|
+
});
|
|
54
62
|
}
|
|
55
63
|
catch (violation) {
|
|
56
|
-
throw new Error(
|
|
64
|
+
throw new Error(`The token is invalid: ${(0, error_1.formatCause)(violation)}`);
|
|
57
65
|
}
|
|
58
|
-
return new Token(headers,
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return
|
|
65
|
-
}
|
|
66
|
-
|
|
66
|
+
return new Token(headers, payload, signature);
|
|
67
|
+
}
|
|
68
|
+
getHeaders() {
|
|
69
|
+
return { ...this.headers };
|
|
70
|
+
}
|
|
71
|
+
getPayload() {
|
|
72
|
+
return { ...this.payload };
|
|
73
|
+
}
|
|
74
|
+
getSignature() {
|
|
67
75
|
return this.signature;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return this.
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return this.
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return this.
|
|
77
|
-
}
|
|
78
|
-
|
|
76
|
+
}
|
|
77
|
+
isAnonymous() {
|
|
78
|
+
return this.payload.sub === undefined;
|
|
79
|
+
}
|
|
80
|
+
getSubject() {
|
|
81
|
+
return this.payload.sub !== undefined ? this.payload.sub : null;
|
|
82
|
+
}
|
|
83
|
+
getIssueTime() {
|
|
84
|
+
return this.payload.iat;
|
|
85
|
+
}
|
|
86
|
+
toJSON() {
|
|
79
87
|
return this.toString();
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
}());
|
|
88
|
+
}
|
|
89
|
+
toString() {
|
|
90
|
+
const headers = (0, base64Url_1.base64UrlEncode)(JSON.stringify(this.headers));
|
|
91
|
+
const payload = (0, base64Url_1.base64UrlEncode)(JSON.stringify(this.payload));
|
|
92
|
+
const signature = (0, base64Url_1.base64UrlEncode)(this.signature);
|
|
93
|
+
return `${headers}.${payload}.${signature}`;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
89
96
|
exports.Token = Token;
|
|
90
|
-
|
|
91
|
-
|
|
97
|
+
class FixedTokenProvider {
|
|
98
|
+
constructor(token) {
|
|
92
99
|
this.token = token;
|
|
93
100
|
}
|
|
94
|
-
|
|
101
|
+
getToken() {
|
|
95
102
|
return this.token;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
}());
|
|
103
|
+
}
|
|
104
|
+
}
|
|
99
105
|
exports.FixedTokenProvider = FixedTokenProvider;
|
package/tracker.d.ts
CHANGED
|
@@ -4,19 +4,19 @@ import { OutputChannel } from './channel';
|
|
|
4
4
|
import { TokenProvider } from './token';
|
|
5
5
|
import { RetryPolicy } from './retry';
|
|
6
6
|
import { Beacon, TrackingEvent, TrackingEventContext, PartialTrackingEvent } from './trackingEvents';
|
|
7
|
-
|
|
7
|
+
type Options = {
|
|
8
8
|
eventMetadata?: {
|
|
9
9
|
[key: string]: string;
|
|
10
10
|
};
|
|
11
11
|
};
|
|
12
|
-
export
|
|
12
|
+
export type Configuration = Options & {
|
|
13
13
|
channel: OutputChannel<Beacon>;
|
|
14
14
|
logger?: Logger;
|
|
15
15
|
tab: Tab;
|
|
16
16
|
tokenProvider: TokenProvider;
|
|
17
17
|
inactivityRetryPolicy: RetryPolicy<number>;
|
|
18
18
|
};
|
|
19
|
-
export
|
|
19
|
+
export type EventInfo<T extends TrackingEvent = TrackingEvent> = {
|
|
20
20
|
context: TrackingEventContext;
|
|
21
21
|
event: T;
|
|
22
22
|
timestamp: number;
|
|
@@ -36,7 +36,7 @@ export declare class Tracker {
|
|
|
36
36
|
private readonly pending;
|
|
37
37
|
private readonly state;
|
|
38
38
|
private readonly inactivityTimer;
|
|
39
|
-
constructor(
|
|
39
|
+
constructor(config: Configuration);
|
|
40
40
|
addListener(listener: EventListener): void;
|
|
41
41
|
removeListener(listener: EventListener): void;
|
|
42
42
|
get flushed(): Promise<void>;
|