@croct/sdk 0.10.0 → 0.11.0-alpha.1
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/.src/activeRecord.ts +150 -0
- package/.src/base64Url.ts +18 -0
- package/.src/cache/cache.ts +15 -0
- package/.src/cache/fallbackCache.ts +29 -0
- package/.src/cache/inMemoryCache.ts +21 -0
- package/.src/cache/index.ts +4 -0
- package/.src/cache/localStorageCache.ts +85 -0
- package/.src/channel/beaconSocketChannel.ts +153 -0
- package/.src/channel/channel.ts +20 -0
- package/.src/channel/encodedChannel.ts +21 -0
- package/.src/channel/guaranteedChannel.ts +131 -0
- package/.src/channel/index.ts +8 -0
- package/.src/channel/queuedChannel.ts +112 -0
- package/.src/channel/retryChannel.ts +90 -0
- package/.src/channel/sandboxChannel.ts +43 -0
- package/.src/channel/socketChannel.ts +217 -0
- package/.src/cid/assigner.ts +3 -0
- package/.src/cid/cachedAssigner.ts +35 -0
- package/.src/cid/fixedAssigner.ts +13 -0
- package/.src/cid/index.ts +4 -0
- package/.src/cid/remoteAssigner.ts +47 -0
- package/.src/constants.ts +6 -0
- package/.src/container.ts +388 -0
- package/.src/contentFetcher.ts +226 -0
- package/.src/context.ts +137 -0
- package/.src/error.ts +31 -0
- package/.src/evaluator.ts +251 -0
- package/.src/eventManager.ts +53 -0
- package/.src/facade/contentFetcherFacade.ts +69 -0
- package/.src/facade/evaluatorFacade.ts +152 -0
- package/.src/facade/index.ts +7 -0
- package/.src/facade/sdkFacade.ts +291 -0
- package/.src/facade/sessionFacade.ts +14 -0
- package/.src/facade/sessionPatch.ts +32 -0
- package/.src/facade/trackerFacade.ts +98 -0
- package/.src/facade/userFacade.ts +26 -0
- package/.src/facade/userPatch.ts +32 -0
- package/.src/index.ts +4 -0
- package/.src/logging/consoleLogger.ts +37 -0
- package/.src/logging/index.ts +4 -0
- package/.src/logging/logger.ts +13 -0
- package/.src/logging/namespacedLogger.ts +32 -0
- package/.src/logging/nullLogger.ts +19 -0
- package/.src/namespacedStorage.ts +69 -0
- package/.src/patch.ts +64 -0
- package/.src/queue/capacityRestrictedQueue.ts +44 -0
- package/.src/queue/inMemoryQueue.ts +43 -0
- package/.src/queue/index.ts +5 -0
- package/.src/queue/monitoredQueue.ts +168 -0
- package/.src/queue/persistentQueue.ts +84 -0
- package/.src/queue/queue.ts +15 -0
- package/.src/retry/arbitraryPolicy.ts +21 -0
- package/.src/retry/backoffPolicy.ts +84 -0
- package/.src/retry/index.ts +5 -0
- package/.src/retry/maxAttemptsPolicy.ts +28 -0
- package/.src/retry/neverPolicy.ts +11 -0
- package/.src/retry/policy.ts +5 -0
- package/.src/schema/attributeSchema.ts +6 -0
- package/.src/schema/contentFetcherSchemas.ts +23 -0
- package/.src/schema/contentSchemas.ts +44 -0
- package/.src/schema/contextSchemas.ts +5 -0
- package/.src/schema/ecommerceSchemas.ts +179 -0
- package/.src/schema/evaluatorSchemas.ts +11 -0
- package/.src/schema/eventSchemas.ts +150 -0
- package/.src/schema/index.ts +11 -0
- package/.src/schema/loggerSchema.ts +12 -0
- package/.src/schema/operationSchemas.ts +102 -0
- package/.src/schema/sdkFacadeSchemas.ts +44 -0
- package/.src/schema/sdkSchemas.ts +49 -0
- package/.src/schema/tokenSchema.ts +42 -0
- package/.src/schema/userSchema.ts +184 -0
- package/.src/sdk.ts +174 -0
- package/.src/sdkEvents.ts +15 -0
- package/.src/sourceLocation.ts +85 -0
- package/.src/tab.ts +148 -0
- package/.src/token/cachedTokenStore.ts +34 -0
- package/.src/token/inMemoryTokenStore.ts +13 -0
- package/.src/token/index.ts +4 -0
- package/.src/token/replicatedTokenStore.ts +21 -0
- package/.src/token/token.ts +164 -0
- package/.src/tracker.ts +460 -0
- package/.src/trackingEvents.ts +456 -0
- package/.src/transformer.ts +7 -0
- package/.src/utilityTypes.ts +3 -0
- package/.src/uuid.ts +43 -0
- package/.src/validation/arrayType.ts +71 -0
- package/.src/validation/booleanType.ts +22 -0
- package/.src/validation/functionType.ts +22 -0
- package/.src/validation/index.ts +12 -0
- package/.src/validation/jsonType.ts +157 -0
- package/.src/validation/mixedSchema.ts +7 -0
- package/.src/validation/nullType.ts +22 -0
- package/.src/validation/numberType.ts +59 -0
- package/.src/validation/objectType.ts +138 -0
- package/.src/validation/schema.ts +21 -0
- package/.src/validation/stringType.ts +118 -0
- package/.src/validation/unionType.ts +53 -0
- package/.src/validation/violation.ts +23 -0
- package/activeRecord.js +33 -36
- package/base64Url.js +1 -0
- package/cache/cache.js +1 -0
- package/cache/fallbackCache.js +16 -32
- package/cache/inMemoryCache.js +10 -10
- package/cache/index.js +2 -1
- package/cache/localStorageCache.js +25 -25
- package/channel/beaconSocketChannel.d.ts +1 -1
- package/channel/beaconSocketChannel.js +50 -79
- package/channel/channel.d.ts +1 -1
- package/channel/channel.js +1 -0
- package/channel/encodedChannel.js +9 -10
- package/channel/guaranteedChannel.d.ts +4 -4
- package/channel/guaranteedChannel.js +42 -43
- package/channel/index.js +2 -1
- package/channel/queuedChannel.js +36 -64
- package/channel/retryChannel.d.ts +1 -1
- package/channel/retryChannel.js +45 -77
- package/channel/sandboxChannel.js +18 -18
- package/channel/socketChannel.d.ts +4 -4
- package/channel/socketChannel.js +78 -79
- package/cid/assigner.js +1 -0
- package/cid/cachedAssigner.js +16 -27
- package/cid/fixedAssigner.js +6 -6
- package/cid/index.js +2 -1
- package/cid/remoteAssigner.js +24 -36
- package/constants.d.ts +6 -5
- package/constants.js +7 -5
- package/container.d.ts +13 -6
- package/container.js +153 -168
- package/contentFetcher.d.ts +59 -0
- package/contentFetcher.js +130 -0
- package/context.d.ts +3 -3
- package/context.js +37 -38
- package/error.js +3 -2
- package/evaluator.d.ts +33 -24
- package/evaluator.js +127 -117
- package/eventManager.d.ts +1 -1
- package/eventManager.js +15 -15
- package/facade/contentFetcherFacade.d.ts +27 -0
- package/facade/contentFetcherFacade.js +41 -0
- package/facade/evaluatorFacade.d.ts +13 -3
- package/facade/evaluatorFacade.js +58 -72
- package/facade/index.js +1 -0
- package/facade/sdkFacade.d.ts +10 -3
- package/facade/sdkFacade.js +130 -141
- package/facade/sessionFacade.js +7 -7
- package/facade/sessionPatch.js +10 -13
- package/facade/trackerFacade.js +33 -38
- package/facade/userFacade.js +11 -11
- package/facade/userPatch.js +10 -13
- package/index.js +3 -2
- package/logging/consoleLogger.js +19 -35
- package/logging/index.js +2 -1
- package/logging/logger.js +1 -0
- package/logging/namespacedLogger.js +15 -15
- package/logging/nullLogger.js +11 -13
- package/namespacedStorage.js +31 -47
- package/package.json +13 -16
- package/patch.d.ts +1 -1
- package/patch.js +1 -0
- package/queue/capacityRestrictedQueue.js +18 -18
- package/queue/inMemoryQueue.js +23 -28
- package/queue/index.js +2 -1
- package/queue/monitoredQueue.d.ts +2 -2
- package/queue/monitoredQueue.js +40 -40
- package/queue/persistentQueue.js +34 -38
- package/queue/queue.js +1 -0
- package/retry/arbitraryPolicy.js +9 -10
- package/retry/backoffPolicy.d.ts +1 -1
- package/retry/backoffPolicy.js +12 -13
- package/retry/index.js +2 -1
- package/retry/maxAttemptsPolicy.js +8 -8
- package/retry/neverPolicy.js +7 -9
- package/retry/policy.js +1 -0
- package/schema/attributeSchema.js +2 -1
- package/schema/contentFetcherSchemas.d.ts +2 -0
- package/schema/contentFetcherSchemas.js +23 -0
- package/schema/contentSchemas.js +2 -1
- package/schema/contextSchemas.js +2 -1
- package/schema/ecommerceSchemas.js +2 -1
- package/schema/evaluatorSchemas.d.ts +2 -0
- package/schema/{evaluationSchemas.js → evaluatorSchemas.js} +4 -3
- package/schema/eventSchemas.js +6 -7
- package/schema/index.d.ts +2 -1
- package/schema/index.js +4 -2
- package/schema/loggerSchema.js +2 -1
- package/schema/operationSchemas.js +9 -8
- package/schema/sdkFacadeSchemas.js +10 -6
- package/schema/sdkSchemas.js +9 -5
- package/schema/tokenSchema.js +6 -4
- package/schema/userSchema.js +3 -2
- package/sdk.d.ts +9 -3
- package/sdk.js +82 -127
- package/sdkEvents.d.ts +3 -3
- package/sdkEvents.js +1 -0
- package/sourceLocation.d.ts +3 -3
- package/sourceLocation.js +14 -14
- package/tab.d.ts +5 -5
- package/tab.js +51 -80
- package/token/cachedTokenStore.js +10 -10
- package/token/inMemoryTokenStore.js +8 -8
- package/token/index.js +2 -1
- package/token/replicatedTokenStore.js +8 -8
- package/token/token.d.ts +9 -5
- package/token/token.js +64 -57
- package/tracker.d.ts +4 -4
- package/tracker.js +146 -122
- package/trackingEvents.d.ts +36 -36
- package/trackingEvents.js +13 -6
- package/transformer.js +2 -1
- package/utilityTypes.d.ts +2 -2
- package/utilityTypes.js +1 -0
- package/uuid.js +10 -7
- package/validation/arrayType.d.ts +2 -2
- package/validation/arrayType.js +30 -27
- package/validation/booleanType.js +12 -15
- package/validation/functionType.js +12 -15
- package/validation/index.js +2 -1
- package/validation/jsonType.d.ts +2 -2
- package/validation/jsonType.js +62 -80
- package/validation/mixedSchema.js +5 -7
- package/validation/nullType.js +12 -15
- package/validation/numberType.d.ts +1 -1
- package/validation/numberType.js +24 -22
- package/validation/objectType.d.ts +1 -1
- package/validation/objectType.js +62 -72
- package/validation/schema.js +7 -10
- package/validation/stringType.d.ts +1 -1
- package/validation/stringType.js +37 -47
- package/validation/unionType.js +28 -77
- package/validation/violation.js +2 -2
- package/schema/evaluationSchemas.d.ts +0 -2
package/schema/loggerSchema.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.loggerSchema = void 0;
|
|
4
|
-
|
|
4
|
+
const validation_1 = require("../validation");
|
|
5
5
|
exports.loggerSchema = new validation_1.ObjectType({
|
|
6
6
|
required: ['debug', 'info', 'warn', 'error'],
|
|
7
7
|
additionalProperties: true,
|
|
@@ -12,3 +12,4 @@ exports.loggerSchema = new validation_1.ObjectType({
|
|
|
12
12
|
error: new validation_1.FunctionType(),
|
|
13
13
|
},
|
|
14
14
|
});
|
|
15
|
+
//# sourceMappingURL=loggerSchema.js.map
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.removeOperation = exports.unsetOperation = exports.clearOperation = exports.incrementOperation = exports.decrementOperation = exports.mergeOperation = exports.combineOperation = exports.setOperation = exports.addOperation = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const validation_1 = require("../validation");
|
|
5
|
+
const attributeSchema_1 = require("./attributeSchema");
|
|
6
|
+
const pointer = new validation_1.StringType({
|
|
7
7
|
format: 'pointer',
|
|
8
8
|
});
|
|
9
|
-
|
|
9
|
+
const simpleArray = new validation_1.JsonArrayType({
|
|
10
10
|
items: new validation_1.JsonPrimitiveType(),
|
|
11
11
|
});
|
|
12
|
-
|
|
12
|
+
const simpleMap = new validation_1.JsonObjectType({
|
|
13
13
|
properties: new validation_1.JsonPrimitiveType(),
|
|
14
14
|
propertyNames: attributeSchema_1.attributeNameSchema,
|
|
15
15
|
});
|
|
16
|
-
|
|
16
|
+
const complexMap = new validation_1.JsonObjectType({
|
|
17
17
|
properties: new validation_1.UnionType(new validation_1.JsonPrimitiveType(), simpleArray, simpleMap),
|
|
18
18
|
propertyNames: attributeSchema_1.attributeNameSchema,
|
|
19
19
|
});
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const collectionValue = new validation_1.UnionType(simpleArray, complexMap);
|
|
21
|
+
const mixedValue = new validation_1.UnionType(new validation_1.JsonPrimitiveType(), simpleArray, complexMap);
|
|
22
22
|
exports.addOperation = new validation_1.ObjectType({
|
|
23
23
|
required: ['path', 'value'],
|
|
24
24
|
properties: {
|
|
@@ -80,3 +80,4 @@ exports.removeOperation = new validation_1.ObjectType({
|
|
|
80
80
|
value: mixedValue,
|
|
81
81
|
},
|
|
82
82
|
});
|
|
83
|
+
//# sourceMappingURL=operationSchemas.js.map
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.sdkFacadeConfigurationSchema = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
const validation_1 = require("../validation");
|
|
5
|
+
const contextSchemas_1 = require("./contextSchemas");
|
|
6
|
+
const sdkSchemas_1 = require("./sdkSchemas");
|
|
7
|
+
const loggerSchema_1 = require("./loggerSchema");
|
|
8
8
|
exports.sdkFacadeConfigurationSchema = new validation_1.ObjectType({
|
|
9
9
|
required: ['appId'],
|
|
10
10
|
properties: {
|
|
11
11
|
appId: new validation_1.StringType({
|
|
12
12
|
format: 'uuid',
|
|
13
13
|
}),
|
|
14
|
-
|
|
14
|
+
clientId: new validation_1.StringType({
|
|
15
15
|
pattern: /^[0-9a-f]{32}$/i,
|
|
16
16
|
}),
|
|
17
17
|
tokenScope: contextSchemas_1.tokenScopeSchema,
|
|
@@ -33,8 +33,12 @@ exports.sdkFacadeConfigurationSchema = new validation_1.ObjectType({
|
|
|
33
33
|
evaluationEndpointUrl: new validation_1.StringType({
|
|
34
34
|
format: 'url',
|
|
35
35
|
}),
|
|
36
|
-
|
|
36
|
+
contentEndpointUrl: new validation_1.StringType({
|
|
37
|
+
format: 'url',
|
|
38
|
+
}),
|
|
39
|
+
cidAssignerEndpointUrl: new validation_1.StringType({
|
|
37
40
|
format: 'url',
|
|
38
41
|
}),
|
|
39
42
|
},
|
|
40
43
|
});
|
|
44
|
+
//# sourceMappingURL=sdkFacadeSchemas.js.map
|
package/schema/sdkSchemas.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.sdkConfigurationSchema = exports.eventMetadataSchema = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const validation_1 = require("../validation");
|
|
5
|
+
const contextSchemas_1 = require("./contextSchemas");
|
|
6
|
+
const loggerSchema_1 = require("./loggerSchema");
|
|
7
7
|
exports.eventMetadataSchema = new validation_1.ObjectType({
|
|
8
8
|
maxProperties: 5,
|
|
9
9
|
propertyNames: new validation_1.StringType({
|
|
@@ -21,7 +21,7 @@ exports.sdkConfigurationSchema = new validation_1.ObjectType({
|
|
|
21
21
|
appId: new validation_1.StringType({
|
|
22
22
|
format: 'uuid',
|
|
23
23
|
}),
|
|
24
|
-
|
|
24
|
+
clientId: new validation_1.StringType({
|
|
25
25
|
pattern: /^[0-9a-f]{32}$/i,
|
|
26
26
|
}),
|
|
27
27
|
tokenScope: contextSchemas_1.tokenScopeSchema,
|
|
@@ -31,7 +31,10 @@ exports.sdkConfigurationSchema = new validation_1.ObjectType({
|
|
|
31
31
|
evaluationEndpointUrl: new validation_1.StringType({
|
|
32
32
|
format: 'url',
|
|
33
33
|
}),
|
|
34
|
-
|
|
34
|
+
contentEndpointUrl: new validation_1.StringType({
|
|
35
|
+
format: 'url',
|
|
36
|
+
}),
|
|
37
|
+
cidAssignerEndpointUrl: new validation_1.StringType({
|
|
35
38
|
format: 'url',
|
|
36
39
|
}),
|
|
37
40
|
beaconQueueSize: new validation_1.NumberType({
|
|
@@ -45,3 +48,4 @@ exports.sdkConfigurationSchema = new validation_1.ObjectType({
|
|
|
45
48
|
eventMetadata: exports.eventMetadataSchema,
|
|
46
49
|
},
|
|
47
50
|
});
|
|
51
|
+
//# sourceMappingURL=sdkSchemas.js.map
|
package/schema/tokenSchema.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.tokenSchema = void 0;
|
|
4
|
-
|
|
4
|
+
const validation_1 = require("../validation");
|
|
5
5
|
exports.tokenSchema = new validation_1.ObjectType({
|
|
6
|
-
required: ['headers', '
|
|
6
|
+
required: ['headers', 'payload'],
|
|
7
7
|
properties: {
|
|
8
8
|
headers: new validation_1.ObjectType({
|
|
9
|
-
required: ['typ', 'alg'
|
|
9
|
+
required: ['typ', 'alg'],
|
|
10
10
|
properties: {
|
|
11
11
|
typ: new validation_1.StringType(),
|
|
12
12
|
alg: new validation_1.StringType(),
|
|
@@ -16,7 +16,7 @@ exports.tokenSchema = new validation_1.ObjectType({
|
|
|
16
16
|
}),
|
|
17
17
|
},
|
|
18
18
|
}),
|
|
19
|
-
|
|
19
|
+
payload: new validation_1.ObjectType({
|
|
20
20
|
required: ['iss', 'aud', 'iat'],
|
|
21
21
|
properties: {
|
|
22
22
|
iss: new validation_1.StringType(),
|
|
@@ -34,7 +34,9 @@ exports.tokenSchema = new validation_1.ObjectType({
|
|
|
34
34
|
format: 'uuid',
|
|
35
35
|
}),
|
|
36
36
|
},
|
|
37
|
+
additionalProperties: true,
|
|
37
38
|
}),
|
|
38
39
|
signature: new validation_1.StringType(),
|
|
39
40
|
},
|
|
40
41
|
});
|
|
42
|
+
//# sourceMappingURL=tokenSchema.js.map
|
package/schema/userSchema.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.userProfileSchema = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const validation_1 = require("../validation");
|
|
5
|
+
const attributeSchema_1 = require("./attributeSchema");
|
|
6
6
|
exports.userProfileSchema = new validation_1.ObjectType({
|
|
7
7
|
properties: {
|
|
8
8
|
firstName: new validation_1.StringType({
|
|
@@ -135,3 +135,4 @@ exports.userProfileSchema = new validation_1.ObjectType({
|
|
|
135
135
|
}),
|
|
136
136
|
},
|
|
137
137
|
});
|
|
138
|
+
//# sourceMappingURL=userSchema.js.map
|
package/sdk.d.ts
CHANGED
|
@@ -6,15 +6,18 @@ import { SdkEventMap } from './sdkEvents';
|
|
|
6
6
|
import { EventManager } from './eventManager';
|
|
7
7
|
import { CidAssigner } from './cid';
|
|
8
8
|
import { UrlSanitizer } from './tab';
|
|
9
|
-
|
|
9
|
+
import { ContentFetcher } from './contentFetcher';
|
|
10
|
+
import { TokenStore } from './token';
|
|
11
|
+
export type Configuration = {
|
|
10
12
|
appId: string;
|
|
11
13
|
tokenScope: TokenScope;
|
|
12
14
|
debug: boolean;
|
|
13
15
|
test: boolean;
|
|
14
|
-
|
|
16
|
+
clientId?: string;
|
|
15
17
|
trackerEndpointUrl?: string;
|
|
16
18
|
evaluationEndpointUrl?: string;
|
|
17
|
-
|
|
19
|
+
contentEndpointUrl?: string;
|
|
20
|
+
cidAssignerEndpointUrl?: string;
|
|
18
21
|
beaconQueueSize?: number;
|
|
19
22
|
urlSanitizer?: UrlSanitizer;
|
|
20
23
|
logger?: Logger;
|
|
@@ -29,9 +32,12 @@ export declare class Sdk {
|
|
|
29
32
|
static init(configuration: Configuration): Sdk;
|
|
30
33
|
get appId(): string;
|
|
31
34
|
get cidAssigner(): CidAssigner;
|
|
35
|
+
get previewTokenStore(): TokenStore;
|
|
36
|
+
get userTokenStore(): TokenStore;
|
|
32
37
|
get context(): Context;
|
|
33
38
|
get tracker(): Tracker;
|
|
34
39
|
get evaluator(): Evaluator;
|
|
40
|
+
get contentFetcher(): ContentFetcher;
|
|
35
41
|
get eventManager(): EventManager<SdkEventMap>;
|
|
36
42
|
getLogger(...namespace: string[]): Logger;
|
|
37
43
|
getTabStorage(namespace: string, ...subnamespace: string[]): Storage;
|
package/sdk.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Sdk = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var error_1 = require("./error");
|
|
4
|
+
const container_1 = require("./container");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
const schema_1 = require("./schema");
|
|
7
|
+
const error_1 = require("./error");
|
|
9
8
|
function validateConfiguration(configuration) {
|
|
10
9
|
if (typeof configuration !== 'object' || configuration === null) {
|
|
11
10
|
throw new Error('The configuration must be a key-value map.');
|
|
@@ -14,37 +13,34 @@ function validateConfiguration(configuration) {
|
|
|
14
13
|
schema_1.sdkConfigurationSchema.validate(configuration);
|
|
15
14
|
}
|
|
16
15
|
catch (violation) {
|
|
17
|
-
throw new Error(
|
|
16
|
+
throw new Error(`Invalid configuration: ${(0, error_1.formatCause)(violation)}`);
|
|
18
17
|
}
|
|
19
18
|
}
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
class Sdk {
|
|
20
|
+
constructor(container) {
|
|
22
21
|
this.container = container;
|
|
23
22
|
}
|
|
24
|
-
|
|
25
|
-
var
|
|
26
|
-
var _b, _c, _d, _e;
|
|
23
|
+
static init(configuration) {
|
|
24
|
+
var _a, _b, _c, _d, _e;
|
|
27
25
|
validateConfiguration(configuration);
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
const { eventMetadata: customMetadata = {}, ...containerConfiguration } = configuration;
|
|
27
|
+
const eventMetadata = {
|
|
30
28
|
sdkVersion: constants_1.VERSION,
|
|
31
29
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
var metadata = _h.value;
|
|
35
|
-
eventMetadata["custom_".concat(metadata)] = customMetadata[metadata];
|
|
36
|
-
}
|
|
30
|
+
for (const metadata of Object.keys(customMetadata)) {
|
|
31
|
+
eventMetadata[`custom_${metadata}`] = customMetadata[metadata];
|
|
37
32
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
33
|
+
const container = new container_1.Container({
|
|
34
|
+
...containerConfiguration,
|
|
35
|
+
evaluationEndpointUrl: (_a = containerConfiguration.evaluationEndpointUrl) !== null && _a !== void 0 ? _a : constants_1.EVALUATION_ENDPOINT_URL,
|
|
36
|
+
contentEndpointUrl: (_b = containerConfiguration.contentEndpointUrl) !== null && _b !== void 0 ? _b : constants_1.CONTENT_ENDPOINT_URL,
|
|
37
|
+
trackerEndpointUrl: (_c = containerConfiguration.trackerEndpointUrl) !== null && _c !== void 0 ? _c : constants_1.TRACKER_ENDPOINT_URL,
|
|
38
|
+
cidAssignerEndpointUrl: (_d = containerConfiguration.cidAssignerEndpointUrl) !== null && _d !== void 0 ? _d : constants_1.CID_ASSIGNER_ENDPOINT_URL,
|
|
39
|
+
beaconQueueSize: (_e = containerConfiguration.beaconQueueSize) !== null && _e !== void 0 ? _e : 100,
|
|
40
|
+
eventMetadata: eventMetadata,
|
|
41
|
+
});
|
|
42
|
+
const logger = container.getLogger();
|
|
43
|
+
const { appId, tokenScope } = container.getConfiguration();
|
|
48
44
|
logger.debug('\n\n'
|
|
49
45
|
+ ' ██████ ██████ ██████ ██████ ████████ \n'
|
|
50
46
|
+ '██ ██ ██ ██ ██ ██ ██ \n'
|
|
@@ -52,106 +48,65 @@ var Sdk = /** @class */ (function () {
|
|
|
52
48
|
+ '██ ██ ██ ██ ██ ██ ██ \n'
|
|
53
49
|
+ ' ██████ ██ ██ ██████ ██████ ██ \n'
|
|
54
50
|
+ '\n');
|
|
55
|
-
logger.info(
|
|
56
|
-
logger.debug(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
logger.debug(
|
|
61
|
-
logger.debug(
|
|
62
|
-
logger.debug(
|
|
63
|
-
logger.debug(
|
|
51
|
+
logger.info(`Initializing SDK v${constants_1.VERSION}...`);
|
|
52
|
+
logger.debug(`App ID: ${appId}`);
|
|
53
|
+
const context = container.getContext();
|
|
54
|
+
const tab = context.getTab();
|
|
55
|
+
const user = context.getUser();
|
|
56
|
+
logger.debug(`${tab.isNew ? 'New' : 'Current'} tab: ${tab.id}`);
|
|
57
|
+
logger.debug(`Token scope: ${tokenScope}`);
|
|
58
|
+
logger.debug(`Current user: ${user !== null ? user : 'anonymous'}`);
|
|
59
|
+
logger.debug(`Test mode: ${containerConfiguration.test}`);
|
|
64
60
|
logger.info('⚡ Croct SDK is ready!');
|
|
65
61
|
return new Sdk(container);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
enumerable: false,
|
|
108
|
-
configurable: true
|
|
109
|
-
});
|
|
110
|
-
Sdk.prototype.getLogger = function () {
|
|
111
|
-
var _a;
|
|
112
|
-
var namespace = [];
|
|
113
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
114
|
-
namespace[_i] = arguments[_i];
|
|
115
|
-
}
|
|
116
|
-
return (_a = this.container).getLogger.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(namespace), false));
|
|
117
|
-
};
|
|
118
|
-
Sdk.prototype.getTabStorage = function (namespace) {
|
|
119
|
-
var _a;
|
|
120
|
-
var subnamespace = [];
|
|
121
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
122
|
-
subnamespace[_i - 1] = arguments[_i];
|
|
123
|
-
}
|
|
124
|
-
return (_a = this.container).getTabStorage.apply(_a, tslib_1.__spreadArray([namespace], tslib_1.__read(subnamespace), false));
|
|
125
|
-
};
|
|
126
|
-
Sdk.prototype.getBrowserStorage = function (namespace) {
|
|
127
|
-
var _a;
|
|
128
|
-
var subnamespace = [];
|
|
129
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
130
|
-
subnamespace[_i - 1] = arguments[_i];
|
|
62
|
+
}
|
|
63
|
+
get appId() {
|
|
64
|
+
const { appId } = this.container.getConfiguration();
|
|
65
|
+
return appId;
|
|
66
|
+
}
|
|
67
|
+
get cidAssigner() {
|
|
68
|
+
return this.container.getCidAssigner();
|
|
69
|
+
}
|
|
70
|
+
get previewTokenStore() {
|
|
71
|
+
return this.container.getPreviewTokenStore();
|
|
72
|
+
}
|
|
73
|
+
get userTokenStore() {
|
|
74
|
+
return this.container.getUserTokenStore();
|
|
75
|
+
}
|
|
76
|
+
get context() {
|
|
77
|
+
return this.container.getContext();
|
|
78
|
+
}
|
|
79
|
+
get tracker() {
|
|
80
|
+
return this.container.getTracker();
|
|
81
|
+
}
|
|
82
|
+
get evaluator() {
|
|
83
|
+
return this.container.getEvaluator();
|
|
84
|
+
}
|
|
85
|
+
get contentFetcher() {
|
|
86
|
+
return this.container.getContentFetcher();
|
|
87
|
+
}
|
|
88
|
+
get eventManager() {
|
|
89
|
+
return this.container.getEventManager();
|
|
90
|
+
}
|
|
91
|
+
getLogger(...namespace) {
|
|
92
|
+
return this.container.getLogger(...namespace);
|
|
93
|
+
}
|
|
94
|
+
getTabStorage(namespace, ...subnamespace) {
|
|
95
|
+
return this.container.getTabStorage(namespace, ...subnamespace);
|
|
96
|
+
}
|
|
97
|
+
getBrowserStorage(namespace, ...subnamespace) {
|
|
98
|
+
return this.container.getBrowserStorage(namespace, ...subnamespace);
|
|
99
|
+
}
|
|
100
|
+
async close() {
|
|
101
|
+
if (this.closed) {
|
|
102
|
+
return;
|
|
131
103
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
case 0:
|
|
140
|
-
if (this.closed) {
|
|
141
|
-
return [2 /*return*/];
|
|
142
|
-
}
|
|
143
|
-
logger = this.getLogger();
|
|
144
|
-
logger.debug('Closing SDK...');
|
|
145
|
-
this.closed = true;
|
|
146
|
-
return [4 /*yield*/, this.container.dispose()];
|
|
147
|
-
case 1:
|
|
148
|
-
_a.sent();
|
|
149
|
-
logger.info('SDK closed.');
|
|
150
|
-
return [2 /*return*/];
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
};
|
|
155
|
-
return Sdk;
|
|
156
|
-
}());
|
|
104
|
+
const logger = this.getLogger();
|
|
105
|
+
logger.debug('Closing SDK...');
|
|
106
|
+
this.closed = true;
|
|
107
|
+
await this.container.dispose();
|
|
108
|
+
logger.info('SDK closed.');
|
|
109
|
+
}
|
|
110
|
+
}
|
|
157
111
|
exports.Sdk = Sdk;
|
|
112
|
+
//# sourceMappingURL=sdk.js.map
|
package/sdkEvents.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ export interface TokenChanged {
|
|
|
3
3
|
oldToken: Token | null;
|
|
4
4
|
newToken: Token | null;
|
|
5
5
|
}
|
|
6
|
-
export
|
|
6
|
+
export type SdkEventMap = Record<string, Record<string, unknown>> & {
|
|
7
7
|
tokenChanged: TokenChanged;
|
|
8
8
|
};
|
|
9
|
-
export
|
|
10
|
-
export
|
|
9
|
+
export type SdkEventType = keyof SdkEventMap;
|
|
10
|
+
export type SdkEvent<T extends SdkEventType = SdkEventType> = T extends SdkEventType ? SdkEventMap[T] : SdkEventMap[SdkEventType];
|
package/sdkEvents.js
CHANGED
package/sourceLocation.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type Position = {
|
|
2
2
|
line: number;
|
|
3
3
|
column: number;
|
|
4
4
|
index: number;
|
|
5
5
|
};
|
|
6
|
-
export
|
|
6
|
+
export type Location = {
|
|
7
7
|
start: Position;
|
|
8
8
|
end: Position;
|
|
9
9
|
};
|
|
10
10
|
export declare function getLength(input: string): number;
|
|
11
|
-
export declare function getPosition(input: string, index: number): Position;
|
|
12
11
|
export declare function getLocation(input: string, startIndex: number, endIndex: number): Location;
|
|
12
|
+
export declare function getPosition(input: string, index: number): Position;
|
package/sourceLocation.js
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
3
|
+
exports.getPosition = exports.getLocation = exports.getLength = void 0;
|
|
5
4
|
function getLength(input) {
|
|
6
|
-
return
|
|
5
|
+
return [...input].length;
|
|
7
6
|
}
|
|
8
7
|
exports.getLength = getLength;
|
|
9
|
-
function getPosition(input, index) {
|
|
10
|
-
return getLocation(input, index, index).start;
|
|
11
|
-
}
|
|
12
|
-
exports.getPosition = getPosition;
|
|
13
8
|
function getLocation(input, startIndex, endIndex) {
|
|
14
9
|
if (startIndex < 0) {
|
|
15
10
|
throw Error('The start index cannot be negative.');
|
|
@@ -17,13 +12,13 @@ function getLocation(input, startIndex, endIndex) {
|
|
|
17
12
|
if (endIndex < startIndex) {
|
|
18
13
|
throw new Error('The end index must greater than or equal to the start index.');
|
|
19
14
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
for (
|
|
26
|
-
|
|
15
|
+
let start;
|
|
16
|
+
let end;
|
|
17
|
+
const chars = [...input];
|
|
18
|
+
let line = 1;
|
|
19
|
+
let column = 0;
|
|
20
|
+
for (let offset = 0; offset < chars.length; offset++) {
|
|
21
|
+
const char = chars[offset];
|
|
27
22
|
if (offset === startIndex) {
|
|
28
23
|
start = {
|
|
29
24
|
index: offset,
|
|
@@ -67,3 +62,8 @@ function getLocation(input, startIndex, endIndex) {
|
|
|
67
62
|
};
|
|
68
63
|
}
|
|
69
64
|
exports.getLocation = getLocation;
|
|
65
|
+
function getPosition(input, index) {
|
|
66
|
+
return getLocation(input, index, index).start;
|
|
67
|
+
}
|
|
68
|
+
exports.getPosition = getPosition;
|
|
69
|
+
//# sourceMappingURL=sourceLocation.js.map
|
package/tab.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { EventListener } from './eventManager';
|
|
2
|
-
export
|
|
2
|
+
export type TabEvent<T = Record<string, unknown>> = CustomEvent<{
|
|
3
3
|
tab: Tab;
|
|
4
4
|
} & T>;
|
|
5
|
-
export
|
|
5
|
+
export type TabVisibilityChangeEvent = TabEvent<{
|
|
6
6
|
visible: boolean;
|
|
7
7
|
}>;
|
|
8
|
-
export
|
|
8
|
+
export type TabUrlChangeEvent = TabEvent<{
|
|
9
9
|
url: string;
|
|
10
10
|
}>;
|
|
11
|
-
export
|
|
12
|
-
|
|
11
|
+
export type UrlSanitizer = (url: string) => URL;
|
|
12
|
+
type TabEventMap = {
|
|
13
13
|
focus: TabEvent;
|
|
14
14
|
blur: TabEvent;
|
|
15
15
|
load: TabEvent;
|