@croct/sdk 0.17.7 → 0.17.8
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.cjs.map +1 -0
- package/activeRecord.d.ts +8 -4
- package/activeRecord.js +115 -106
- package/activeRecord.js.map +1 -1
- package/apiKey.cjs.map +1 -0
- package/apiKey.d.ts +4 -2
- package/apiKey.js +152 -141
- package/apiKey.js.map +1 -1
- package/base64Url.cjs.map +1 -0
- package/base64Url.d.ts +4 -2
- package/base64Url.js +8 -15
- package/base64Url.js.map +1 -1
- package/cache/cache.cjs.map +1 -0
- package/cache/cache.d.ts +6 -4
- package/cache/cache.js +9 -10
- package/cache/cache.js.map +1 -1
- package/cache/cookieCache.cjs.map +1 -0
- package/cache/cookieCache.d.ts +6 -3
- package/cache/cookieCache.js +52 -54
- package/cache/cookieCache.js.map +1 -1
- package/cache/fallbackCache.cjs.map +1 -0
- package/cache/fallbackCache.d.ts +5 -2
- package/cache/fallbackCache.js +20 -21
- package/cache/fallbackCache.js.map +1 -1
- package/cache/inMemoryCache.cjs.map +1 -0
- package/cache/inMemoryCache.d.ts +5 -2
- package/cache/inMemoryCache.js +15 -17
- package/cache/inMemoryCache.js.map +1 -1
- package/cache/index.cjs.map +1 -0
- package/cache/index.d.ts +4 -4
- package/cache/index.js +9 -11
- package/cache/index.js.map +1 -1
- package/cache/localStorageCache.cjs.map +1 -0
- package/cache/localStorageCache.d.ts +5 -2
- package/cache/localStorageCache.js +55 -63
- package/cache/localStorageCache.js.map +1 -1
- package/channel/channel.cjs.map +1 -0
- package/channel/channel.d.ts +8 -6
- package/channel/channel.js +21 -22
- package/channel/channel.js.map +1 -1
- package/channel/encodedChannel.cjs.map +1 -0
- package/channel/encodedChannel.d.ts +6 -3
- package/channel/encodedChannel.js +13 -14
- package/channel/encodedChannel.js.map +1 -1
- package/channel/guaranteedChannel.cjs.map +1 -0
- package/channel/guaranteedChannel.d.ts +9 -7
- package/channel/guaranteedChannel.js +74 -73
- package/channel/guaranteedChannel.js.map +1 -1
- package/channel/httpBeaconChannel.cjs.map +1 -0
- package/channel/httpBeaconChannel.d.ts +9 -6
- package/channel/httpBeaconChannel.js +82 -83
- package/channel/httpBeaconChannel.js.map +1 -1
- package/channel/index.cjs.map +1 -0
- package/channel/index.d.ts +12 -7
- package/channel/index.js +15 -17
- package/channel/index.js.map +1 -1
- package/channel/queuedChannel.cjs.map +1 -0
- package/channel/queuedChannel.d.ts +7 -4
- package/channel/queuedChannel.js +87 -97
- package/channel/queuedChannel.js.map +1 -1
- package/channel/retryChannel.cjs.map +1 -0
- package/channel/retryChannel.d.ts +7 -5
- package/channel/retryChannel.js +58 -57
- package/channel/retryChannel.js.map +1 -1
- package/channel/sandboxChannel.cjs.map +1 -0
- package/channel/sandboxChannel.d.ts +5 -2
- package/channel/sandboxChannel.js +34 -35
- package/channel/sandboxChannel.js.map +1 -1
- package/cid/assigner.cjs.map +1 -0
- package/cid/assigner.d.ts +3 -1
- package/cid/assigner.js +0 -2
- package/cid/assigner.js.map +1 -1
- package/cid/cachedAssigner.cjs.map +1 -0
- package/cid/cachedAssigner.d.ts +7 -5
- package/cid/cachedAssigner.js +37 -43
- package/cid/cachedAssigner.js.map +1 -1
- package/cid/fixedAssigner.cjs.map +1 -0
- package/cid/fixedAssigner.d.ts +5 -2
- package/cid/fixedAssigner.js +9 -10
- package/cid/fixedAssigner.js.map +1 -1
- package/cid/index.cjs.map +1 -0
- package/cid/index.d.ts +6 -4
- package/cid/index.js +9 -11
- package/cid/index.js.map +1 -1
- package/cid/remoteAssigner.cjs.map +1 -0
- package/cid/remoteAssigner.d.ts +6 -3
- package/cid/remoteAssigner.js +36 -37
- package/cid/remoteAssigner.js.map +1 -1
- package/constants.cjs.map +1 -0
- package/constants.d.ts +6 -4
- package/constants.js +10 -7
- package/constants.js.map +1 -1
- package/container.cjs.map +1 -0
- package/container.d.ts +28 -15
- package/container.js +269 -252
- package/container.js.map +1 -1
- package/contentFetcher.cjs.map +1 -0
- package/contentFetcher.d.ts +17 -14
- package/contentFetcher.js +156 -163
- package/contentFetcher.js.map +1 -1
- package/context.cjs.map +1 -0
- package/context.d.ts +13 -9
- package/context.js +80 -81
- package/context.js.map +1 -1
- package/error.cjs.map +1 -0
- package/error.d.ts +4 -2
- package/error.js +21 -21
- package/error.js.map +1 -1
- package/evaluator.cjs.map +1 -0
- package/evaluator.d.ts +18 -16
- package/evaluator.js +179 -179
- package/evaluator.js.map +1 -1
- package/eventManager.cjs.map +1 -0
- package/eventManager.d.ts +8 -6
- package/eventManager.js +24 -26
- package/eventManager.js.map +1 -1
- package/eventSubjectProcessor.cjs.map +1 -0
- package/eventSubjectProcessor.d.ts +16 -3
- package/eventSubjectProcessor.js +53 -59
- package/eventSubjectProcessor.js.map +1 -1
- package/facade/contentFetcherFacade.cjs.map +1 -0
- package/facade/contentFetcherFacade.d.ts +16 -7
- package/facade/contentFetcherFacade.js +32 -35
- package/facade/contentFetcherFacade.js.map +1 -1
- package/facade/evaluatorFacade.cjs.map +1 -0
- package/facade/evaluatorFacade.d.ts +17 -10
- package/facade/evaluatorFacade.js +56 -60
- package/facade/evaluatorFacade.js.map +1 -1
- package/facade/index.cjs.map +1 -0
- package/facade/index.d.ts +29 -7
- package/facade/index.js +19 -19
- package/facade/index.js.map +1 -1
- package/facade/sdkFacade.cjs.map +1 -0
- package/facade/sdkFacade.d.ts +33 -15
- package/facade/sdkFacade.js +201 -214
- package/facade/sdkFacade.js.map +1 -1
- package/facade/sessionFacade.cjs.map +1 -0
- package/facade/sessionFacade.d.ts +18 -3
- package/facade/sessionFacade.js +10 -11
- package/facade/sessionFacade.js.map +1 -1
- package/facade/sessionPatch.cjs.map +1 -0
- package/facade/sessionPatch.d.ts +17 -4
- package/facade/sessionPatch.js +22 -24
- package/facade/sessionPatch.js.map +1 -1
- package/facade/trackerFacade.cjs.map +1 -0
- package/facade/trackerFacade.d.ts +17 -4
- package/facade/trackerFacade.js +67 -57
- package/facade/trackerFacade.js.map +1 -1
- package/facade/userFacade.cjs.map +1 -0
- package/facade/userFacade.d.ts +21 -4
- package/facade/userFacade.js +17 -18
- package/facade/userFacade.js.map +1 -1
- package/facade/userPatch.cjs.map +1 -0
- package/facade/userPatch.d.ts +17 -4
- package/facade/userPatch.js +22 -24
- package/facade/userPatch.js.map +1 -1
- package/help.cjs.map +1 -0
- package/help.d.ts +3 -1
- package/help.js +19 -23
- package/help.js.map +1 -1
- package/index.cjs.map +1 -0
- package/index.d.ts +25 -3
- package/index.js +7 -7
- package/index.js.map +1 -1
- package/logging/consoleLogger.cjs.map +1 -0
- package/logging/consoleLogger.d.ts +5 -2
- package/logging/consoleLogger.js +23 -24
- package/logging/consoleLogger.js.map +1 -1
- package/logging/filteredLogger.cjs.map +1 -0
- package/logging/filteredLogger.d.ts +8 -5
- package/logging/filteredLogger.js +36 -37
- package/logging/filteredLogger.js.map +1 -1
- package/logging/index.cjs.map +1 -0
- package/logging/index.d.ts +5 -5
- package/logging/index.js +11 -13
- package/logging/index.js.map +1 -1
- package/logging/logger.cjs.map +1 -0
- package/logging/logger.d.ts +4 -2
- package/logging/logger.js +0 -2
- package/logging/logger.js.map +1 -1
- package/logging/namespacedLogger.cjs.map +1 -0
- package/logging/namespacedLogger.d.ts +5 -2
- package/logging/namespacedLogger.js +22 -23
- package/logging/namespacedLogger.js.map +1 -1
- package/logging/nullLogger.cjs.map +1 -0
- package/logging/nullLogger.d.ts +5 -2
- package/logging/nullLogger.js +11 -16
- package/logging/nullLogger.js.map +1 -1
- package/namespacedStorage.cjs.map +1 -0
- package/namespacedStorage.d.ts +3 -1
- package/namespacedStorage.js +51 -52
- package/namespacedStorage.js.map +1 -1
- package/package.json +60 -6
- package/patch.cjs.map +1 -0
- package/patch.d.ts +6 -4
- package/patch.js +0 -2
- package/patch.js.map +1 -1
- package/queue/capacityRestrictedQueue.cjs.map +1 -0
- package/queue/capacityRestrictedQueue.d.ts +5 -2
- package/queue/capacityRestrictedQueue.js +31 -32
- package/queue/capacityRestrictedQueue.js.map +1 -1
- package/queue/inMemoryQueue.cjs.map +1 -0
- package/queue/inMemoryQueue.d.ts +5 -2
- package/queue/inMemoryQueue.js +32 -34
- package/queue/inMemoryQueue.js.map +1 -1
- package/queue/index.cjs.map +1 -0
- package/queue/index.d.ts +6 -5
- package/queue/index.js +11 -13
- package/queue/index.js.map +1 -1
- package/queue/monitoredQueue.cjs.map +1 -0
- package/queue/monitoredQueue.d.ts +8 -5
- package/queue/monitoredQueue.js +104 -110
- package/queue/monitoredQueue.js.map +1 -1
- package/queue/persistentQueue.cjs.map +1 -0
- package/queue/persistentQueue.d.ts +5 -2
- package/queue/persistentQueue.js +52 -54
- package/queue/persistentQueue.js.map +1 -1
- package/queue/queue.cjs.map +1 -0
- package/queue/queue.d.ts +3 -1
- package/queue/queue.js +0 -2
- package/queue/queue.js.map +1 -1
- package/retry/arbitraryPolicy.cjs.map +1 -0
- package/retry/arbitraryPolicy.d.ts +5 -2
- package/retry/arbitraryPolicy.js +14 -15
- package/retry/arbitraryPolicy.js.map +1 -1
- package/retry/backoffPolicy.cjs.map +1 -0
- package/retry/backoffPolicy.d.ts +5 -3
- package/retry/backoffPolicy.js +52 -50
- package/retry/backoffPolicy.js.map +1 -1
- package/retry/index.cjs.map +1 -0
- package/retry/index.d.ts +5 -5
- package/retry/index.js +11 -13
- package/retry/index.js.map +1 -1
- package/retry/maxAttemptsPolicy.cjs.map +1 -0
- package/retry/maxAttemptsPolicy.d.ts +5 -2
- package/retry/maxAttemptsPolicy.js +17 -18
- package/retry/maxAttemptsPolicy.js.map +1 -1
- package/retry/neverPolicy.cjs.map +1 -0
- package/retry/neverPolicy.d.ts +5 -2
- package/retry/neverPolicy.js +9 -10
- package/retry/neverPolicy.js.map +1 -1
- package/retry/policy.cjs.map +1 -0
- package/retry/policy.d.ts +3 -1
- package/retry/policy.js +0 -2
- package/retry/policy.js.map +1 -1
- package/schema/attributeSchema.cjs.map +1 -0
- package/schema/attributeSchema.d.ts +6 -2
- package/schema/attributeSchema.js +7 -7
- package/schema/attributeSchema.js.map +1 -1
- package/schema/contentFetcherSchemas.cjs.map +1 -0
- package/schema/contentFetcherSchemas.d.ts +6 -2
- package/schema/contentFetcherSchemas.js +24 -21
- package/schema/contentFetcherSchemas.js.map +1 -1
- package/schema/contentSchemas.cjs.map +1 -0
- package/schema/contentSchemas.d.ts +6 -2
- package/schema/contentSchemas.js +45 -45
- package/schema/contentSchemas.js.map +1 -1
- package/schema/contextSchemas.cjs.map +1 -0
- package/schema/contextSchemas.d.ts +6 -2
- package/schema/contextSchemas.js +6 -6
- package/schema/contextSchemas.js.map +1 -1
- package/schema/ecommerceSchemas.cjs.map +1 -0
- package/schema/ecommerceSchemas.d.ts +10 -6
- package/schema/ecommerceSchemas.js +176 -172
- package/schema/ecommerceSchemas.js.map +1 -1
- package/schema/evaluatorSchemas.cjs.map +1 -0
- package/schema/evaluatorSchemas.d.ts +6 -2
- package/schema/evaluatorSchemas.js +46 -30
- package/schema/evaluatorSchemas.js.map +1 -1
- package/schema/eventSchemas.cjs.map +1 -0
- package/schema/eventSchemas.d.ts +16 -12
- package/schema/eventSchemas.js +125 -102
- package/schema/eventSchemas.js.map +1 -1
- package/schema/index.cjs.map +1 -0
- package/schema/index.d.ts +14 -11
- package/schema/index.js +11 -14
- package/schema/index.js.map +1 -1
- package/schema/loggerSchema.cjs.map +1 -0
- package/schema/loggerSchema.d.ts +6 -2
- package/schema/loggerSchema.js +13 -13
- package/schema/loggerSchema.js.map +1 -1
- package/schema/operationSchemas.cjs.map +1 -0
- package/schema/operationSchemas.d.ts +14 -10
- package/schema/operationSchemas.js +85 -69
- package/schema/operationSchemas.js.map +1 -1
- package/schema/sdkFacadeSchemas.cjs.map +1 -0
- package/schema/sdkFacadeSchemas.d.ts +6 -2
- package/schema/sdkFacadeSchemas.js +65 -51
- package/schema/sdkFacadeSchemas.js.map +1 -1
- package/schema/sdkSchemas.cjs.map +1 -0
- package/schema/sdkSchemas.d.ts +8 -4
- package/schema/sdkSchemas.js +80 -78
- package/schema/sdkSchemas.js.map +1 -1
- package/schema/tokenSchema.cjs.map +1 -0
- package/schema/tokenSchema.d.ts +6 -2
- package/schema/tokenSchema.js +41 -38
- package/schema/tokenSchema.js.map +1 -1
- package/schema/userSchema.cjs.map +1 -0
- package/schema/userSchema.d.ts +6 -2
- package/schema/userSchema.js +183 -134
- package/schema/userSchema.js.map +1 -1
- package/sdk.cjs.map +1 -0
- package/sdk.d.ts +28 -14
- package/sdk.js +106 -108
- package/sdk.js.map +1 -1
- package/sdkEvents.cjs.map +1 -0
- package/sdkEvents.d.ts +10 -5
- package/sdkEvents.js +0 -2
- package/sdkEvents.js.map +1 -1
- package/sourceLocation.cjs.map +1 -0
- package/sourceLocation.d.ts +7 -5
- package/sourceLocation.js +56 -57
- package/sourceLocation.js.map +1 -1
- package/tab.cjs.map +1 -0
- package/tab.d.ts +9 -7
- package/tab.js +93 -90
- package/tab.js.map +1 -1
- package/token/cachedTokenStore.cjs.map +1 -0
- package/token/cachedTokenStore.d.ts +8 -3
- package/token/cachedTokenStore.js +22 -24
- package/token/cachedTokenStore.js.map +1 -1
- package/token/inMemoryTokenStore.cjs.map +1 -0
- package/token/inMemoryTokenStore.d.ts +7 -2
- package/token/inMemoryTokenStore.js +12 -13
- package/token/inMemoryTokenStore.js.map +1 -1
- package/token/index.cjs.map +1 -0
- package/token/index.d.ts +7 -4
- package/token/index.js +9 -11
- package/token/index.js.map +1 -1
- package/token/replicatedTokenStore.cjs.map +1 -0
- package/token/replicatedTokenStore.d.ts +7 -2
- package/token/replicatedTokenStore.js +14 -15
- package/token/replicatedTokenStore.js.map +1 -1
- package/token/token.cjs.map +1 -0
- package/token/token.d.ts +11 -8
- package/token/token.js +212 -195
- package/token/token.js.map +1 -1
- package/tracker.cjs.map +1 -0
- package/tracker.d.ts +20 -13
- package/tracker.js +307 -307
- package/tracker.js.map +1 -1
- package/trackingEvents.cjs.map +1 -0
- package/trackingEvents.d.ts +65 -62
- package/trackingEvents.js +57 -56
- package/trackingEvents.js.map +1 -1
- package/transformer.cjs.map +1 -0
- package/transformer.d.ts +4 -2
- package/transformer.js +5 -6
- package/transformer.js.map +1 -1
- package/utilityTypes.cjs.map +1 -0
- package/utilityTypes.d.ts +4 -2
- package/utilityTypes.js +0 -2
- package/utilityTypes.js.map +1 -1
- package/uuid.cjs.map +1 -0
- package/uuid.d.ts +3 -1
- package/uuid.js +27 -32
- package/uuid.js.map +1 -1
- package/validation/arrayType.cjs.map +1 -0
- package/validation/arrayType.d.ts +5 -3
- package/validation/arrayType.js +45 -41
- package/validation/arrayType.js.map +1 -1
- package/validation/booleanType.cjs.map +1 -0
- package/validation/booleanType.d.ts +5 -2
- package/validation/booleanType.js +19 -16
- package/validation/booleanType.js.map +1 -1
- package/validation/functionType.cjs.map +1 -0
- package/validation/functionType.d.ts +5 -2
- package/validation/functionType.js +19 -16
- package/validation/functionType.js.map +1 -1
- package/validation/index.cjs.map +1 -0
- package/validation/index.d.ts +12 -12
- package/validation/index.js +27 -29
- package/validation/index.js.map +1 -1
- package/validation/jsonType.cjs.map +1 -0
- package/validation/jsonType.d.ts +8 -6
- package/validation/jsonType.js +89 -82
- package/validation/jsonType.js.map +1 -1
- package/validation/mixedSchema.cjs.map +1 -0
- package/validation/mixedSchema.d.ts +5 -2
- package/validation/mixedSchema.js +5 -7
- package/validation/mixedSchema.js.map +1 -1
- package/validation/nullType.cjs.map +1 -0
- package/validation/nullType.d.ts +5 -2
- package/validation/nullType.js +19 -16
- package/validation/nullType.js.map +1 -1
- package/validation/numberType.cjs.map +1 -0
- package/validation/numberType.d.ts +5 -3
- package/validation/numberType.js +40 -32
- package/validation/numberType.js.map +1 -1
- package/validation/objectType.cjs.map +1 -0
- package/validation/objectType.d.ts +5 -3
- package/validation/objectType.js +84 -85
- package/validation/objectType.js.map +1 -1
- package/validation/schema.cjs.map +1 -0
- package/validation/schema.d.ts +5 -3
- package/validation/schema.js +8 -9
- package/validation/schema.js.map +1 -1
- package/validation/stringType.cjs.map +1 -0
- package/validation/stringType.d.ts +5 -3
- package/validation/stringType.js +74 -70
- package/validation/stringType.js.map +1 -1
- package/validation/unionType.cjs.map +1 -0
- package/validation/unionType.d.ts +5 -2
- package/validation/unionType.js +37 -35
- package/validation/unionType.js.map +1 -1
- package/validation/violation.cjs.map +1 -0
- package/validation/violation.d.ts +4 -2
- package/validation/violation.js +18 -18
- package/validation/violation.js.map +1 -1
package/eventSubjectProcessor.js
CHANGED
|
@@ -1,67 +1,61 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EventSubjectProcessor = void 0;
|
|
4
1
|
class EventSubjectProcessor {
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
constructor(logger) {
|
|
3
|
+
this.logger = logger;
|
|
4
|
+
}
|
|
5
|
+
process(event) {
|
|
6
|
+
const { currentToken } = this;
|
|
7
|
+
this.currentToken = event.userToken ?? null;
|
|
8
|
+
if (currentToken === void 0) {
|
|
9
|
+
return [event];
|
|
7
10
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
const events = [];
|
|
28
|
-
if (currentToken !== null && currentSubject !== null) {
|
|
29
|
-
this.logger.info('External user sign out automatically tracked');
|
|
30
|
-
events.push({
|
|
31
|
-
timestamp: event.timestamp,
|
|
32
|
-
context: event.context,
|
|
33
|
-
userToken: currentToken,
|
|
34
|
-
event: {
|
|
35
|
-
type: 'userSignedOut',
|
|
36
|
-
userId: currentSubject,
|
|
37
|
-
},
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
if (newSubject !== null) {
|
|
41
|
-
this.logger.info('External user sign in automatically tracked');
|
|
42
|
-
events.push({
|
|
43
|
-
timestamp: event.timestamp,
|
|
44
|
-
context: event.context,
|
|
45
|
-
userToken: event.userToken,
|
|
46
|
-
event: {
|
|
47
|
-
type: 'userSignedIn',
|
|
48
|
-
userId: newSubject,
|
|
49
|
-
},
|
|
50
|
-
});
|
|
11
|
+
if (EventSubjectProcessor.isIdentificationEvent(event.event)) {
|
|
12
|
+
return [event];
|
|
13
|
+
}
|
|
14
|
+
const currentSubject = currentToken?.getSubject() ?? null;
|
|
15
|
+
const newSubject = event.userToken?.getSubject() ?? null;
|
|
16
|
+
if (newSubject === currentSubject) {
|
|
17
|
+
return [event];
|
|
18
|
+
}
|
|
19
|
+
const events = [];
|
|
20
|
+
if (currentToken !== null && currentSubject !== null) {
|
|
21
|
+
this.logger.info("External user sign out automatically tracked");
|
|
22
|
+
events.push({
|
|
23
|
+
timestamp: event.timestamp,
|
|
24
|
+
context: event.context,
|
|
25
|
+
userToken: currentToken,
|
|
26
|
+
event: {
|
|
27
|
+
type: "userSignedOut",
|
|
28
|
+
userId: currentSubject
|
|
51
29
|
}
|
|
52
|
-
|
|
53
|
-
return events;
|
|
30
|
+
});
|
|
54
31
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
32
|
+
if (newSubject !== null) {
|
|
33
|
+
this.logger.info("External user sign in automatically tracked");
|
|
34
|
+
events.push({
|
|
35
|
+
timestamp: event.timestamp,
|
|
36
|
+
context: event.context,
|
|
37
|
+
userToken: event.userToken,
|
|
38
|
+
event: {
|
|
39
|
+
type: "userSignedIn",
|
|
40
|
+
userId: newSubject
|
|
63
41
|
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
events.push(event);
|
|
45
|
+
return events;
|
|
46
|
+
}
|
|
47
|
+
static isIdentificationEvent(event) {
|
|
48
|
+
switch (event.type) {
|
|
49
|
+
case "userSignedIn":
|
|
50
|
+
case "userSignedUp":
|
|
51
|
+
case "userSignedOut":
|
|
52
|
+
return true;
|
|
53
|
+
default:
|
|
54
|
+
return false;
|
|
64
55
|
}
|
|
56
|
+
}
|
|
65
57
|
}
|
|
66
|
-
|
|
58
|
+
export {
|
|
59
|
+
EventSubjectProcessor
|
|
60
|
+
};
|
|
67
61
|
//# sourceMappingURL=eventSubjectProcessor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["src/eventSubjectProcessor.ts"],"sourcesContent":["import {QueuedEventInfo, TrackingEventProcessor} from './tracker';\nimport {Token} from './token';\nimport {Logger} from './logging';\nimport {TrackingEvent} from './trackingEvents';\n\nexport class EventSubjectProcessor implements TrackingEventProcessor {\n private currentToken?: Token|null;\n\n private logger: Logger;\n\n public constructor(logger: Logger) {\n this.logger = logger;\n }\n\n public process(event: QueuedEventInfo): QueuedEventInfo[] {\n const {currentToken} = this;\n\n this.currentToken = event.userToken ?? null;\n\n if (currentToken === undefined) {\n // This is the first event, no subject to compare.\n // If the user is already identified at this point,\n // assume that the event was previously tracked.\n return [event];\n }\n\n if (EventSubjectProcessor.isIdentificationEvent(event.event)) {\n return [event];\n }\n\n const currentSubject = currentToken?.getSubject() ?? null;\n const newSubject = event.userToken?.getSubject() ?? null;\n\n if (newSubject === currentSubject) {\n // No change in subject\n return [event];\n }\n\n const events: QueuedEventInfo[] = [];\n\n if (currentToken !== null && currentSubject !== null) {\n this.logger.info('External user sign out automatically tracked');\n\n events.push({\n timestamp: event.timestamp,\n context: event.context,\n userToken: currentToken,\n event: {\n type: 'userSignedOut',\n userId: currentSubject,\n },\n });\n }\n\n if (newSubject !== null) {\n this.logger.info('External user sign in automatically tracked');\n\n events.push({\n timestamp: event.timestamp,\n context: event.context,\n userToken: event.userToken,\n event: {\n type: 'userSignedIn',\n userId: newSubject,\n },\n });\n }\n\n events.push(event);\n\n return events;\n }\n\n private static isIdentificationEvent(event: TrackingEvent): boolean {\n switch (event.type) {\n case 'userSignedIn':\n case 'userSignedUp':\n case 'userSignedOut':\n return true;\n\n default:\n return false;\n }\n }\n}\n"],"mappings":"AAKO,MAAM,sBAAwD;AAAA,EAK1D,YAAY,QAAgB;AAC/B,SAAK,SAAS;AAAA,EAClB;AAAA,EAEO,QAAQ,OAA2C;AACtD,UAAM,EAAC,aAAY,IAAI;AAEvB,SAAK,eAAe,MAAM,aAAa;AAEvC,QAAI,iBAAiB,QAAW;AAI5B,aAAO,CAAC,KAAK;AAAA,IACjB;AAEA,QAAI,sBAAsB,sBAAsB,MAAM,KAAK,GAAG;AAC1D,aAAO,CAAC,KAAK;AAAA,IACjB;AAEA,UAAM,iBAAiB,cAAc,WAAW,KAAK;AACrD,UAAM,aAAa,MAAM,WAAW,WAAW,KAAK;AAEpD,QAAI,eAAe,gBAAgB;AAE/B,aAAO,CAAC,KAAK;AAAA,IACjB;AAEA,UAAM,SAA4B,CAAC;AAEnC,QAAI,iBAAiB,QAAQ,mBAAmB,MAAM;AAClD,WAAK,OAAO,KAAK,8CAA8C;AAE/D,aAAO,KAAK;AAAA,QACR,WAAW,MAAM;AAAA,QACjB,SAAS,MAAM;AAAA,QACf,WAAW;AAAA,QACX,OAAO;AAAA,UACH,MAAM;AAAA,UACN,QAAQ;AAAA,QACZ;AAAA,MACJ,CAAC;AAAA,IACL;AAEA,QAAI,eAAe,MAAM;AACrB,WAAK,OAAO,KAAK,6CAA6C;AAE9D,aAAO,KAAK;AAAA,QACR,WAAW,MAAM;AAAA,QACjB,SAAS,MAAM;AAAA,QACf,WAAW,MAAM;AAAA,QACjB,OAAO;AAAA,UACH,MAAM;AAAA,UACN,QAAQ;AAAA,QACZ;AAAA,MACJ,CAAC;AAAA,IACL;AAEA,WAAO,KAAK,KAAK;AAEjB,WAAO;AAAA,EACX;AAAA,EAEA,OAAe,sBAAsB,OAA+B;AAChE,YAAQ,MAAM,MAAM;AAAA,MAChB,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AACD,eAAO;AAAA,MAEX;AACI,eAAO;AAAA,IACf;AAAA,EACJ;AACJ;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/facade/contentFetcherFacade.ts"],"sourcesContent":["import {JsonObject} from '@croct/json';\nimport {formatCause} from '../error';\nimport {ContentFetcher, FetchResponse} from '../contentFetcher';\nimport {ContextFactory} from './evaluatorFacade';\nimport {fetchOptionsSchema as optionsSchema} from '../schema';\nimport {TokenProvider} from '../token';\nimport {CidAssigner} from '../cid';\n\nexport type FetchOptions = {\n version?: `${number}`|number,\n preferredLocale?: string,\n timeout?: number,\n attributes?: JsonObject,\n};\n\nfunction validate(options: unknown): asserts options is FetchOptions {\n try {\n optionsSchema.validate(options);\n } catch (violation) {\n throw new Error(`Invalid options: ${formatCause(violation)}`);\n }\n}\n\nexport type Configuration = {\n contentFetcher: ContentFetcher,\n contextFactory: ContextFactory,\n previewTokenProvider: TokenProvider,\n userTokenProvider: TokenProvider,\n cidAssigner: CidAssigner,\n};\n\nexport class ContentFetcherFacade {\n private readonly fetcher: ContentFetcher;\n\n private readonly contextFactory: ContextFactory;\n\n private readonly previewTokenProvider: TokenProvider;\n\n private readonly userTokenProvider: TokenProvider;\n\n private readonly cidAssigner: CidAssigner;\n\n public constructor(configuration: Configuration) {\n this.fetcher = configuration.contentFetcher;\n this.previewTokenProvider = configuration.previewTokenProvider;\n this.userTokenProvider = configuration.userTokenProvider;\n this.cidAssigner = configuration.cidAssigner;\n this.contextFactory = configuration.contextFactory;\n }\n\n public async fetch<P extends JsonObject>(slotId: string, options: FetchOptions = {}): Promise<FetchResponse<P>> {\n if (typeof slotId !== 'string' || slotId.length === 0) {\n throw new Error('The slot ID must be a non-empty string.');\n }\n\n validate(options);\n\n return this.fetcher.fetch(slotId, {\n static: false,\n clientId: await this.cidAssigner.assignCid(),\n userToken: this.userTokenProvider.getToken() ?? undefined,\n previewToken: this.previewTokenProvider.getToken() ?? undefined,\n version: options.version,\n context: this.contextFactory.createContext(options.attributes),\n timeout: options.timeout,\n preferredLocale: options.preferredLocale,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAA0B;AAG1B,oBAAkD;AAWlD,SAAS,SAAS,SAAmD;AACjE,MAAI;AACA,kBAAAA,mBAAc,SAAS,OAAO;AAAA,EAClC,SAAS,WAAW;AAChB,UAAM,IAAI,MAAM,wBAAoB,0BAAY,SAAS,CAAC,EAAE;AAAA,EAChE;AACJ;AAUO,MAAM,qBAAqB;AAAA,EAWvB,YAAY,eAA8B;AAC7C,SAAK,UAAU,cAAc;AAC7B,SAAK,uBAAuB,cAAc;AAC1C,SAAK,oBAAoB,cAAc;AACvC,SAAK,cAAc,cAAc;AACjC,SAAK,iBAAiB,cAAc;AAAA,EACxC;AAAA,EAEA,MAAa,MAA4B,QAAgB,UAAwB,CAAC,GAA8B;AAC5G,QAAI,OAAO,WAAW,YAAY,OAAO,WAAW,GAAG;AACnD,YAAM,IAAI,MAAM,yCAAyC;AAAA,IAC7D;AAEA,aAAS,OAAO;AAEhB,WAAO,KAAK,QAAQ,MAAM,QAAQ;AAAA,MAC9B,QAAQ;AAAA,MACR,UAAU,MAAM,KAAK,YAAY,UAAU;AAAA,MAC3C,WAAW,KAAK,kBAAkB,SAAS,KAAK;AAAA,MAChD,cAAc,KAAK,qBAAqB,SAAS,KAAK;AAAA,MACtD,SAAS,QAAQ;AAAA,MACjB,SAAS,KAAK,eAAe,cAAc,QAAQ,UAAU;AAAA,MAC7D,SAAS,QAAQ;AAAA,MACjB,iBAAiB,QAAQ;AAAA,IAC7B,CAAC;AAAA,EACL;AACJ;","names":["optionsSchema"]}
|
|
@@ -1,22 +1,29 @@
|
|
|
1
1
|
import { JsonObject } from '@croct/json';
|
|
2
|
-
import { ContentFetcher, FetchResponse } from '../contentFetcher';
|
|
3
|
-
import { ContextFactory } from './evaluatorFacade';
|
|
4
|
-
import { TokenProvider } from '../token';
|
|
5
|
-
import { CidAssigner } from '../cid';
|
|
6
|
-
|
|
2
|
+
import { ContentFetcher, FetchResponse } from '../contentFetcher.js';
|
|
3
|
+
import { ContextFactory } from './evaluatorFacade.js';
|
|
4
|
+
import { TokenProvider } from '../token/token.js';
|
|
5
|
+
import { CidAssigner } from '../cid/assigner.js';
|
|
6
|
+
import '../evaluator.js';
|
|
7
|
+
import '../sourceLocation.js';
|
|
8
|
+
import '../logging/logger.js';
|
|
9
|
+
import '../apiKey.js';
|
|
10
|
+
import '../tab.js';
|
|
11
|
+
import '../eventManager.js';
|
|
12
|
+
|
|
13
|
+
type FetchOptions = {
|
|
7
14
|
version?: `${number}` | number;
|
|
8
15
|
preferredLocale?: string;
|
|
9
16
|
timeout?: number;
|
|
10
17
|
attributes?: JsonObject;
|
|
11
18
|
};
|
|
12
|
-
|
|
19
|
+
type Configuration = {
|
|
13
20
|
contentFetcher: ContentFetcher;
|
|
14
21
|
contextFactory: ContextFactory;
|
|
15
22
|
previewTokenProvider: TokenProvider;
|
|
16
23
|
userTokenProvider: TokenProvider;
|
|
17
24
|
cidAssigner: CidAssigner;
|
|
18
25
|
};
|
|
19
|
-
|
|
26
|
+
declare class ContentFetcherFacade {
|
|
20
27
|
private readonly fetcher;
|
|
21
28
|
private readonly contextFactory;
|
|
22
29
|
private readonly previewTokenProvider;
|
|
@@ -25,3 +32,5 @@ export declare class ContentFetcherFacade {
|
|
|
25
32
|
constructor(configuration: Configuration);
|
|
26
33
|
fetch<P extends JsonObject>(slotId: string, options?: FetchOptions): Promise<FetchResponse<P>>;
|
|
27
34
|
}
|
|
35
|
+
|
|
36
|
+
export { type Configuration, ContentFetcherFacade, type FetchOptions };
|
|
@@ -1,41 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.ContentFetcherFacade = void 0;
|
|
4
|
-
const error_1 = require("../error");
|
|
5
|
-
const schema_1 = require("../schema");
|
|
1
|
+
import { formatCause } from "../error";
|
|
2
|
+
import { fetchOptionsSchema as optionsSchema } from "../schema";
|
|
6
3
|
function validate(options) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
4
|
+
try {
|
|
5
|
+
optionsSchema.validate(options);
|
|
6
|
+
} catch (violation) {
|
|
7
|
+
throw new Error(`Invalid options: ${formatCause(violation)}`);
|
|
8
|
+
}
|
|
13
9
|
}
|
|
14
10
|
class ContentFetcherFacade {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
throw new Error('The slot ID must be a non-empty string.');
|
|
26
|
-
}
|
|
27
|
-
validate(options);
|
|
28
|
-
return this.fetcher.fetch(slotId, {
|
|
29
|
-
static: false,
|
|
30
|
-
clientId: await this.cidAssigner.assignCid(),
|
|
31
|
-
userToken: (_a = this.userTokenProvider.getToken()) !== null && _a !== void 0 ? _a : undefined,
|
|
32
|
-
previewToken: (_b = this.previewTokenProvider.getToken()) !== null && _b !== void 0 ? _b : undefined,
|
|
33
|
-
version: options.version,
|
|
34
|
-
context: this.contextFactory.createContext(options.attributes),
|
|
35
|
-
timeout: options.timeout,
|
|
36
|
-
preferredLocale: options.preferredLocale,
|
|
37
|
-
});
|
|
11
|
+
constructor(configuration) {
|
|
12
|
+
this.fetcher = configuration.contentFetcher;
|
|
13
|
+
this.previewTokenProvider = configuration.previewTokenProvider;
|
|
14
|
+
this.userTokenProvider = configuration.userTokenProvider;
|
|
15
|
+
this.cidAssigner = configuration.cidAssigner;
|
|
16
|
+
this.contextFactory = configuration.contextFactory;
|
|
17
|
+
}
|
|
18
|
+
async fetch(slotId, options = {}) {
|
|
19
|
+
if (typeof slotId !== "string" || slotId.length === 0) {
|
|
20
|
+
throw new Error("The slot ID must be a non-empty string.");
|
|
38
21
|
}
|
|
22
|
+
validate(options);
|
|
23
|
+
return this.fetcher.fetch(slotId, {
|
|
24
|
+
static: false,
|
|
25
|
+
clientId: await this.cidAssigner.assignCid(),
|
|
26
|
+
userToken: this.userTokenProvider.getToken() ?? void 0,
|
|
27
|
+
previewToken: this.previewTokenProvider.getToken() ?? void 0,
|
|
28
|
+
version: options.version,
|
|
29
|
+
context: this.contextFactory.createContext(options.attributes),
|
|
30
|
+
timeout: options.timeout,
|
|
31
|
+
preferredLocale: options.preferredLocale
|
|
32
|
+
});
|
|
33
|
+
}
|
|
39
34
|
}
|
|
40
|
-
|
|
35
|
+
export {
|
|
36
|
+
ContentFetcherFacade
|
|
37
|
+
};
|
|
41
38
|
//# sourceMappingURL=contentFetcherFacade.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../src/facade/contentFetcherFacade.ts"],"sourcesContent":["import {JsonObject} from '@croct/json';\nimport {formatCause} from '../error';\nimport {ContentFetcher, FetchResponse} from '../contentFetcher';\nimport {ContextFactory} from './evaluatorFacade';\nimport {fetchOptionsSchema as optionsSchema} from '../schema';\nimport {TokenProvider} from '../token';\nimport {CidAssigner} from '../cid';\n\nexport type FetchOptions = {\n version?: `${number}`|number,\n preferredLocale?: string,\n timeout?: number,\n attributes?: JsonObject,\n};\n\nfunction validate(options: unknown): asserts options is FetchOptions {\n try {\n optionsSchema.validate(options);\n } catch (violation) {\n throw new Error(`Invalid options: ${formatCause(violation)}`);\n }\n}\n\nexport type Configuration = {\n contentFetcher: ContentFetcher,\n contextFactory: ContextFactory,\n previewTokenProvider: TokenProvider,\n userTokenProvider: TokenProvider,\n cidAssigner: CidAssigner,\n};\n\nexport class ContentFetcherFacade {\n private readonly fetcher: ContentFetcher;\n\n private readonly contextFactory: ContextFactory;\n\n private readonly previewTokenProvider: TokenProvider;\n\n private readonly userTokenProvider: TokenProvider;\n\n private readonly cidAssigner: CidAssigner;\n\n public constructor(configuration: Configuration) {\n this.fetcher = configuration.contentFetcher;\n this.previewTokenProvider = configuration.previewTokenProvider;\n this.userTokenProvider = configuration.userTokenProvider;\n this.cidAssigner = configuration.cidAssigner;\n this.contextFactory = configuration.contextFactory;\n }\n\n public async fetch<P extends JsonObject>(slotId: string, options: FetchOptions = {}): Promise<FetchResponse<P>> {\n if (typeof slotId !== 'string' || slotId.length === 0) {\n throw new Error('The slot ID must be a non-empty string.');\n }\n\n validate(options);\n\n return this.fetcher.fetch(slotId, {\n static: false,\n clientId: await this.cidAssigner.assignCid(),\n userToken: this.userTokenProvider.getToken() ?? undefined,\n previewToken: this.previewTokenProvider.getToken() ?? undefined,\n version: options.version,\n context: this.contextFactory.createContext(options.attributes),\n timeout: options.timeout,\n preferredLocale: options.preferredLocale,\n });\n }\n}\n"],"mappings":"AACA,SAAQ,mBAAkB;AAG1B,SAAQ,sBAAsB,qBAAoB;AAWlD,SAAS,SAAS,SAAmD;AACjE,MAAI;AACA,kBAAc,SAAS,OAAO;AAAA,EAClC,SAAS,WAAW;AAChB,UAAM,IAAI,MAAM,oBAAoB,YAAY,SAAS,CAAC,EAAE;AAAA,EAChE;AACJ;AAUO,MAAM,qBAAqB;AAAA,EAWvB,YAAY,eAA8B;AAC7C,SAAK,UAAU,cAAc;AAC7B,SAAK,uBAAuB,cAAc;AAC1C,SAAK,oBAAoB,cAAc;AACvC,SAAK,cAAc,cAAc;AACjC,SAAK,iBAAiB,cAAc;AAAA,EACxC;AAAA,EAEA,MAAa,MAA4B,QAAgB,UAAwB,CAAC,GAA8B;AAC5G,QAAI,OAAO,WAAW,YAAY,OAAO,WAAW,GAAG;AACnD,YAAM,IAAI,MAAM,yCAAyC;AAAA,IAC7D;AAEA,aAAS,OAAO;AAEhB,WAAO,KAAK,QAAQ,MAAM,QAAQ;AAAA,MAC9B,QAAQ;AAAA,MACR,UAAU,MAAM,KAAK,YAAY,UAAU;AAAA,MAC3C,WAAW,KAAK,kBAAkB,SAAS,KAAK;AAAA,MAChD,cAAc,KAAK,qBAAqB,SAAS,KAAK;AAAA,MACtD,SAAS,QAAQ;AAAA,MACjB,SAAS,KAAK,eAAe,cAAc,QAAQ,UAAU;AAAA,MAC7D,SAAS,QAAQ;AAAA,MACjB,iBAAiB,QAAQ;AAAA,IAC7B,CAAC;AAAA,EACL;AACJ;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/facade/evaluatorFacade.ts"],"sourcesContent":["import {JsonObject, JsonValue} from '@croct/json';\nimport {Evaluator, EvaluationContext, Page} from '../evaluator';\nimport {Tab} from '../tab';\nimport {evaluationOptionsSchema as optionsSchema} from '../schema';\nimport {formatCause} from '../error';\nimport {TokenProvider} from '../token';\nimport {CidAssigner} from '../cid';\n\nexport type EvaluationOptions = {\n timeout?: number,\n attributes?: JsonObject,\n};\n\nfunction validate(options: unknown): asserts options is EvaluationOptions {\n try {\n optionsSchema.validate(options);\n } catch (violation) {\n throw new Error(`Invalid options: ${formatCause(violation)}`);\n }\n}\n\nexport interface ContextFactory {\n createContext(attributes?: JsonObject): EvaluationContext;\n}\n\nexport type Configuration = {\n evaluator: Evaluator,\n contextFactory: ContextFactory,\n userTokenProvider: TokenProvider,\n cidAssigner: CidAssigner,\n};\n\nexport class EvaluatorFacade {\n private readonly evaluator: Evaluator;\n\n private readonly contextFactory: ContextFactory;\n\n private readonly tokenProvider: TokenProvider;\n\n private readonly cidAssigner: CidAssigner;\n\n public constructor(configuration: Configuration) {\n this.evaluator = configuration.evaluator;\n this.contextFactory = configuration.contextFactory;\n this.tokenProvider = configuration.userTokenProvider;\n this.cidAssigner = configuration.cidAssigner;\n }\n\n public async evaluate(query: string, options: EvaluationOptions = {}): Promise<JsonValue> {\n if (typeof query !== 'string' || query.length === 0) {\n throw new Error('The query must be a non-empty string.');\n }\n\n validate(options);\n\n return this.evaluator.evaluate(query, {\n clientId: await this.cidAssigner.assignCid(),\n userToken: this.tokenProvider.getToken() ?? undefined,\n timeout: options.timeout,\n context: this.contextFactory.createContext(options.attributes),\n });\n }\n}\n\nexport class MinimalContextFactory implements ContextFactory {\n public createContext(attributes?: JsonObject): EvaluationContext {\n if (attributes === undefined) {\n return {};\n }\n\n return {attributes: attributes};\n }\n}\n\nexport class TabContextFactory implements ContextFactory {\n private readonly tab: Tab;\n\n public constructor(tab: Tab) {\n this.tab = tab;\n }\n\n public createContext(attributes?: JsonObject): EvaluationContext {\n const url = new URL(this.tab.url);\n const context: EvaluationContext = {};\n\n const page: Page = {\n title: this.tab.title,\n url: url.toString(),\n };\n\n const {referrer} = this.tab;\n\n if (referrer.length > 0) {\n page.referrer = referrer;\n }\n\n context.page = page;\n\n const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone ?? null;\n\n if (timeZone !== null) {\n context.timeZone = timeZone;\n }\n\n if (attributes !== undefined && Object.keys(attributes).length > 0) {\n context.attributes = attributes;\n }\n\n return context;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAAuD;AACvD,mBAA0B;AAS1B,SAAS,SAAS,SAAwD;AACtE,MAAI;AACA,kBAAAA,wBAAc,SAAS,OAAO;AAAA,EAClC,SAAS,WAAW;AAChB,UAAM,IAAI,MAAM,wBAAoB,0BAAY,SAAS,CAAC,EAAE;AAAA,EAChE;AACJ;AAaO,MAAM,gBAAgB;AAAA,EASlB,YAAY,eAA8B;AAC7C,SAAK,YAAY,cAAc;AAC/B,SAAK,iBAAiB,cAAc;AACpC,SAAK,gBAAgB,cAAc;AACnC,SAAK,cAAc,cAAc;AAAA,EACrC;AAAA,EAEA,MAAa,SAAS,OAAe,UAA6B,CAAC,GAAuB;AACtF,QAAI,OAAO,UAAU,YAAY,MAAM,WAAW,GAAG;AACjD,YAAM,IAAI,MAAM,uCAAuC;AAAA,IAC3D;AAEA,aAAS,OAAO;AAEhB,WAAO,KAAK,UAAU,SAAS,OAAO;AAAA,MAClC,UAAU,MAAM,KAAK,YAAY,UAAU;AAAA,MAC3C,WAAW,KAAK,cAAc,SAAS,KAAK;AAAA,MAC5C,SAAS,QAAQ;AAAA,MACjB,SAAS,KAAK,eAAe,cAAc,QAAQ,UAAU;AAAA,IACjE,CAAC;AAAA,EACL;AACJ;AAEO,MAAM,sBAAgD;AAAA,EAClD,cAAc,YAA4C;AAC7D,QAAI,eAAe,QAAW;AAC1B,aAAO,CAAC;AAAA,IACZ;AAEA,WAAO,EAAC,WAAsB;AAAA,EAClC;AACJ;AAEO,MAAM,kBAA4C;AAAA,EAG9C,YAAY,KAAU;AACzB,SAAK,MAAM;AAAA,EACf;AAAA,EAEO,cAAc,YAA4C;AAC7D,UAAM,MAAM,IAAI,IAAI,KAAK,IAAI,GAAG;AAChC,UAAM,UAA6B,CAAC;AAEpC,UAAM,OAAa;AAAA,MACf,OAAO,KAAK,IAAI;AAAA,MAChB,KAAK,IAAI,SAAS;AAAA,IACtB;AAEA,UAAM,EAAC,SAAQ,IAAI,KAAK;AAExB,QAAI,SAAS,SAAS,GAAG;AACrB,WAAK,WAAW;AAAA,IACpB;AAEA,YAAQ,OAAO;AAEf,UAAM,WAAW,KAAK,eAAe,EAAE,gBAAgB,EAAE,YAAY;AAErE,QAAI,aAAa,MAAM;AACnB,cAAQ,WAAW;AAAA,IACvB;AAEA,QAAI,eAAe,UAAa,OAAO,KAAK,UAAU,EAAE,SAAS,GAAG;AAChE,cAAQ,aAAa;AAAA,IACzB;AAEA,WAAO;AAAA,EACX;AACJ;","names":["optionsSchema"]}
|
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
import { JsonObject, JsonValue } from '@croct/json';
|
|
2
|
-
import {
|
|
3
|
-
import { Tab } from '../tab';
|
|
4
|
-
import { TokenProvider } from '../token';
|
|
5
|
-
import { CidAssigner } from '../cid';
|
|
6
|
-
|
|
2
|
+
import { EvaluationContext, Evaluator } from '../evaluator.js';
|
|
3
|
+
import { Tab } from '../tab.js';
|
|
4
|
+
import { TokenProvider } from '../token/token.js';
|
|
5
|
+
import { CidAssigner } from '../cid/assigner.js';
|
|
6
|
+
import '../sourceLocation.js';
|
|
7
|
+
import '../logging/logger.js';
|
|
8
|
+
import '../apiKey.js';
|
|
9
|
+
import '../eventManager.js';
|
|
10
|
+
|
|
11
|
+
type EvaluationOptions = {
|
|
7
12
|
timeout?: number;
|
|
8
13
|
attributes?: JsonObject;
|
|
9
14
|
};
|
|
10
|
-
|
|
15
|
+
interface ContextFactory {
|
|
11
16
|
createContext(attributes?: JsonObject): EvaluationContext;
|
|
12
17
|
}
|
|
13
|
-
|
|
18
|
+
type Configuration = {
|
|
14
19
|
evaluator: Evaluator;
|
|
15
20
|
contextFactory: ContextFactory;
|
|
16
21
|
userTokenProvider: TokenProvider;
|
|
17
22
|
cidAssigner: CidAssigner;
|
|
18
23
|
};
|
|
19
|
-
|
|
24
|
+
declare class EvaluatorFacade {
|
|
20
25
|
private readonly evaluator;
|
|
21
26
|
private readonly contextFactory;
|
|
22
27
|
private readonly tokenProvider;
|
|
@@ -24,11 +29,13 @@ export declare class EvaluatorFacade {
|
|
|
24
29
|
constructor(configuration: Configuration);
|
|
25
30
|
evaluate(query: string, options?: EvaluationOptions): Promise<JsonValue>;
|
|
26
31
|
}
|
|
27
|
-
|
|
32
|
+
declare class MinimalContextFactory implements ContextFactory {
|
|
28
33
|
createContext(attributes?: JsonObject): EvaluationContext;
|
|
29
34
|
}
|
|
30
|
-
|
|
35
|
+
declare class TabContextFactory implements ContextFactory {
|
|
31
36
|
private readonly tab;
|
|
32
37
|
constructor(tab: Tab);
|
|
33
38
|
createContext(attributes?: JsonObject): EvaluationContext;
|
|
34
39
|
}
|
|
40
|
+
|
|
41
|
+
export { type Configuration, type ContextFactory, type EvaluationOptions, EvaluatorFacade, MinimalContextFactory, TabContextFactory };
|
|
@@ -1,73 +1,69 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.TabContextFactory = exports.MinimalContextFactory = exports.EvaluatorFacade = void 0;
|
|
4
|
-
const schema_1 = require("../schema");
|
|
5
|
-
const error_1 = require("../error");
|
|
1
|
+
import { evaluationOptionsSchema as optionsSchema } from "../schema";
|
|
2
|
+
import { formatCause } from "../error";
|
|
6
3
|
function validate(options) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
4
|
+
try {
|
|
5
|
+
optionsSchema.validate(options);
|
|
6
|
+
} catch (violation) {
|
|
7
|
+
throw new Error(`Invalid options: ${formatCause(violation)}`);
|
|
8
|
+
}
|
|
13
9
|
}
|
|
14
10
|
class EvaluatorFacade {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
throw new Error('The query must be a non-empty string.');
|
|
25
|
-
}
|
|
26
|
-
validate(options);
|
|
27
|
-
return this.evaluator.evaluate(query, {
|
|
28
|
-
clientId: await this.cidAssigner.assignCid(),
|
|
29
|
-
userToken: (_a = this.tokenProvider.getToken()) !== null && _a !== void 0 ? _a : undefined,
|
|
30
|
-
timeout: options.timeout,
|
|
31
|
-
context: this.contextFactory.createContext(options.attributes),
|
|
32
|
-
});
|
|
11
|
+
constructor(configuration) {
|
|
12
|
+
this.evaluator = configuration.evaluator;
|
|
13
|
+
this.contextFactory = configuration.contextFactory;
|
|
14
|
+
this.tokenProvider = configuration.userTokenProvider;
|
|
15
|
+
this.cidAssigner = configuration.cidAssigner;
|
|
16
|
+
}
|
|
17
|
+
async evaluate(query, options = {}) {
|
|
18
|
+
if (typeof query !== "string" || query.length === 0) {
|
|
19
|
+
throw new Error("The query must be a non-empty string.");
|
|
33
20
|
}
|
|
21
|
+
validate(options);
|
|
22
|
+
return this.evaluator.evaluate(query, {
|
|
23
|
+
clientId: await this.cidAssigner.assignCid(),
|
|
24
|
+
userToken: this.tokenProvider.getToken() ?? void 0,
|
|
25
|
+
timeout: options.timeout,
|
|
26
|
+
context: this.contextFactory.createContext(options.attributes)
|
|
27
|
+
});
|
|
28
|
+
}
|
|
34
29
|
}
|
|
35
|
-
exports.EvaluatorFacade = EvaluatorFacade;
|
|
36
30
|
class MinimalContextFactory {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
return { attributes: attributes };
|
|
31
|
+
createContext(attributes) {
|
|
32
|
+
if (attributes === void 0) {
|
|
33
|
+
return {};
|
|
42
34
|
}
|
|
35
|
+
return { attributes };
|
|
36
|
+
}
|
|
43
37
|
}
|
|
44
|
-
exports.MinimalContextFactory = MinimalContextFactory;
|
|
45
38
|
class TabContextFactory {
|
|
46
|
-
|
|
47
|
-
|
|
39
|
+
constructor(tab) {
|
|
40
|
+
this.tab = tab;
|
|
41
|
+
}
|
|
42
|
+
createContext(attributes) {
|
|
43
|
+
const url = new URL(this.tab.url);
|
|
44
|
+
const context = {};
|
|
45
|
+
const page = {
|
|
46
|
+
title: this.tab.title,
|
|
47
|
+
url: url.toString()
|
|
48
|
+
};
|
|
49
|
+
const { referrer } = this.tab;
|
|
50
|
+
if (referrer.length > 0) {
|
|
51
|
+
page.referrer = referrer;
|
|
52
|
+
}
|
|
53
|
+
context.page = page;
|
|
54
|
+
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone ?? null;
|
|
55
|
+
if (timeZone !== null) {
|
|
56
|
+
context.timeZone = timeZone;
|
|
48
57
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const url = new URL(this.tab.url);
|
|
52
|
-
const context = {};
|
|
53
|
-
const page = {
|
|
54
|
-
title: this.tab.title,
|
|
55
|
-
url: url.toString(),
|
|
56
|
-
};
|
|
57
|
-
const { referrer } = this.tab;
|
|
58
|
-
if (referrer.length > 0) {
|
|
59
|
-
page.referrer = referrer;
|
|
60
|
-
}
|
|
61
|
-
context.page = page;
|
|
62
|
-
const timeZone = (_a = Intl.DateTimeFormat().resolvedOptions().timeZone) !== null && _a !== void 0 ? _a : null;
|
|
63
|
-
if (timeZone !== null) {
|
|
64
|
-
context.timeZone = timeZone;
|
|
65
|
-
}
|
|
66
|
-
if (attributes !== undefined && Object.keys(attributes).length > 0) {
|
|
67
|
-
context.attributes = attributes;
|
|
68
|
-
}
|
|
69
|
-
return context;
|
|
58
|
+
if (attributes !== void 0 && Object.keys(attributes).length > 0) {
|
|
59
|
+
context.attributes = attributes;
|
|
70
60
|
}
|
|
61
|
+
return context;
|
|
62
|
+
}
|
|
71
63
|
}
|
|
72
|
-
|
|
64
|
+
export {
|
|
65
|
+
EvaluatorFacade,
|
|
66
|
+
MinimalContextFactory,
|
|
67
|
+
TabContextFactory
|
|
68
|
+
};
|
|
73
69
|
//# sourceMappingURL=evaluatorFacade.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../src/facade/evaluatorFacade.ts"],"sourcesContent":["import {JsonObject, JsonValue} from '@croct/json';\nimport {Evaluator, EvaluationContext, Page} from '../evaluator';\nimport {Tab} from '../tab';\nimport {evaluationOptionsSchema as optionsSchema} from '../schema';\nimport {formatCause} from '../error';\nimport {TokenProvider} from '../token';\nimport {CidAssigner} from '../cid';\n\nexport type EvaluationOptions = {\n timeout?: number,\n attributes?: JsonObject,\n};\n\nfunction validate(options: unknown): asserts options is EvaluationOptions {\n try {\n optionsSchema.validate(options);\n } catch (violation) {\n throw new Error(`Invalid options: ${formatCause(violation)}`);\n }\n}\n\nexport interface ContextFactory {\n createContext(attributes?: JsonObject): EvaluationContext;\n}\n\nexport type Configuration = {\n evaluator: Evaluator,\n contextFactory: ContextFactory,\n userTokenProvider: TokenProvider,\n cidAssigner: CidAssigner,\n};\n\nexport class EvaluatorFacade {\n private readonly evaluator: Evaluator;\n\n private readonly contextFactory: ContextFactory;\n\n private readonly tokenProvider: TokenProvider;\n\n private readonly cidAssigner: CidAssigner;\n\n public constructor(configuration: Configuration) {\n this.evaluator = configuration.evaluator;\n this.contextFactory = configuration.contextFactory;\n this.tokenProvider = configuration.userTokenProvider;\n this.cidAssigner = configuration.cidAssigner;\n }\n\n public async evaluate(query: string, options: EvaluationOptions = {}): Promise<JsonValue> {\n if (typeof query !== 'string' || query.length === 0) {\n throw new Error('The query must be a non-empty string.');\n }\n\n validate(options);\n\n return this.evaluator.evaluate(query, {\n clientId: await this.cidAssigner.assignCid(),\n userToken: this.tokenProvider.getToken() ?? undefined,\n timeout: options.timeout,\n context: this.contextFactory.createContext(options.attributes),\n });\n }\n}\n\nexport class MinimalContextFactory implements ContextFactory {\n public createContext(attributes?: JsonObject): EvaluationContext {\n if (attributes === undefined) {\n return {};\n }\n\n return {attributes: attributes};\n }\n}\n\nexport class TabContextFactory implements ContextFactory {\n private readonly tab: Tab;\n\n public constructor(tab: Tab) {\n this.tab = tab;\n }\n\n public createContext(attributes?: JsonObject): EvaluationContext {\n const url = new URL(this.tab.url);\n const context: EvaluationContext = {};\n\n const page: Page = {\n title: this.tab.title,\n url: url.toString(),\n };\n\n const {referrer} = this.tab;\n\n if (referrer.length > 0) {\n page.referrer = referrer;\n }\n\n context.page = page;\n\n const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone ?? null;\n\n if (timeZone !== null) {\n context.timeZone = timeZone;\n }\n\n if (attributes !== undefined && Object.keys(attributes).length > 0) {\n context.attributes = attributes;\n }\n\n return context;\n }\n}\n"],"mappings":"AAGA,SAAQ,2BAA2B,qBAAoB;AACvD,SAAQ,mBAAkB;AAS1B,SAAS,SAAS,SAAwD;AACtE,MAAI;AACA,kBAAc,SAAS,OAAO;AAAA,EAClC,SAAS,WAAW;AAChB,UAAM,IAAI,MAAM,oBAAoB,YAAY,SAAS,CAAC,EAAE;AAAA,EAChE;AACJ;AAaO,MAAM,gBAAgB;AAAA,EASlB,YAAY,eAA8B;AAC7C,SAAK,YAAY,cAAc;AAC/B,SAAK,iBAAiB,cAAc;AACpC,SAAK,gBAAgB,cAAc;AACnC,SAAK,cAAc,cAAc;AAAA,EACrC;AAAA,EAEA,MAAa,SAAS,OAAe,UAA6B,CAAC,GAAuB;AACtF,QAAI,OAAO,UAAU,YAAY,MAAM,WAAW,GAAG;AACjD,YAAM,IAAI,MAAM,uCAAuC;AAAA,IAC3D;AAEA,aAAS,OAAO;AAEhB,WAAO,KAAK,UAAU,SAAS,OAAO;AAAA,MAClC,UAAU,MAAM,KAAK,YAAY,UAAU;AAAA,MAC3C,WAAW,KAAK,cAAc,SAAS,KAAK;AAAA,MAC5C,SAAS,QAAQ;AAAA,MACjB,SAAS,KAAK,eAAe,cAAc,QAAQ,UAAU;AAAA,IACjE,CAAC;AAAA,EACL;AACJ;AAEO,MAAM,sBAAgD;AAAA,EAClD,cAAc,YAA4C;AAC7D,QAAI,eAAe,QAAW;AAC1B,aAAO,CAAC;AAAA,IACZ;AAEA,WAAO,EAAC,WAAsB;AAAA,EAClC;AACJ;AAEO,MAAM,kBAA4C;AAAA,EAG9C,YAAY,KAAU;AACzB,SAAK,MAAM;AAAA,EACf;AAAA,EAEO,cAAc,YAA4C;AAC7D,UAAM,MAAM,IAAI,IAAI,KAAK,IAAI,GAAG;AAChC,UAAM,UAA6B,CAAC;AAEpC,UAAM,OAAa;AAAA,MACf,OAAO,KAAK,IAAI;AAAA,MAChB,KAAK,IAAI,SAAS;AAAA,IACtB;AAEA,UAAM,EAAC,SAAQ,IAAI,KAAK;AAExB,QAAI,SAAS,SAAS,GAAG;AACrB,WAAK,WAAW;AAAA,IACpB;AAEA,YAAQ,OAAO;AAEf,UAAM,WAAW,KAAK,eAAe,EAAE,gBAAgB,EAAE,YAAY;AAErE,QAAI,aAAa,MAAM;AACnB,cAAQ,WAAW;AAAA,IACvB;AAEA,QAAI,eAAe,UAAa,OAAO,KAAK,UAAU,EAAE,SAAS,GAAG;AAChE,cAAQ,aAAa;AAAA,IACzB;AAEA,WAAO;AAAA,EACX;AACJ;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/facade/index.ts"],"sourcesContent":["export {EvaluatorFacade, ContextFactory, MinimalContextFactory, TabContextFactory} from './evaluatorFacade';\nexport {SdkFacade} from './sdkFacade';\nexport {SessionFacade} from './sessionFacade';\nexport {SessionPatch} from './sessionPatch';\nexport {TrackerFacade} from './trackerFacade';\nexport {UserFacade} from './userFacade';\nexport {UserPatch} from './userPatch';\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6BAAwF;AACxF,uBAAwB;AACxB,2BAA4B;AAC5B,0BAA2B;AAC3B,2BAA4B;AAC5B,wBAAyB;AACzB,uBAAwB;","names":[]}
|
package/facade/index.d.ts
CHANGED
|
@@ -1,7 +1,29 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { SdkFacade } from './sdkFacade';
|
|
3
|
-
export { SessionFacade } from './sessionFacade';
|
|
4
|
-
export { SessionPatch } from './sessionPatch';
|
|
5
|
-
export { TrackerFacade } from './trackerFacade';
|
|
6
|
-
export { UserFacade } from './userFacade';
|
|
7
|
-
export { UserPatch } from './userPatch';
|
|
1
|
+
export { ContextFactory, EvaluatorFacade, MinimalContextFactory, TabContextFactory } from './evaluatorFacade.js';
|
|
2
|
+
export { SdkFacade } from './sdkFacade.js';
|
|
3
|
+
export { SessionFacade } from './sessionFacade.js';
|
|
4
|
+
export { SessionPatch } from './sessionPatch.js';
|
|
5
|
+
export { TrackerFacade } from './trackerFacade.js';
|
|
6
|
+
export { UserFacade } from './userFacade.js';
|
|
7
|
+
export { UserPatch } from './userPatch.js';
|
|
8
|
+
import '@croct/json';
|
|
9
|
+
import '../evaluator.js';
|
|
10
|
+
import '../token/token.js';
|
|
11
|
+
import '../apiKey.js';
|
|
12
|
+
import '../sourceLocation.js';
|
|
13
|
+
import '../logging/logger.js';
|
|
14
|
+
import '../tab.js';
|
|
15
|
+
import '../eventManager.js';
|
|
16
|
+
import '../cid/assigner.js';
|
|
17
|
+
import '../context.js';
|
|
18
|
+
import '../cache/cache.js';
|
|
19
|
+
import '../sdkEvents.js';
|
|
20
|
+
import './contentFetcherFacade.js';
|
|
21
|
+
import '../contentFetcher.js';
|
|
22
|
+
import '../cache/cookieCache.js';
|
|
23
|
+
import '../trackingEvents.js';
|
|
24
|
+
import '../patch.js';
|
|
25
|
+
import '../utilityTypes.js';
|
|
26
|
+
import '../tracker.js';
|
|
27
|
+
import '../channel/channel.js';
|
|
28
|
+
import '../retry/policy.js';
|
|
29
|
+
import '../activeRecord.js';
|
package/facade/index.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
import { EvaluatorFacade, ContextFactory, MinimalContextFactory, TabContextFactory } from "./evaluatorFacade";
|
|
2
|
+
import { SdkFacade } from "./sdkFacade";
|
|
3
|
+
import { SessionFacade } from "./sessionFacade";
|
|
4
|
+
import { SessionPatch } from "./sessionPatch";
|
|
5
|
+
import { TrackerFacade } from "./trackerFacade";
|
|
6
|
+
import { UserFacade } from "./userFacade";
|
|
7
|
+
import { UserPatch } from "./userPatch";
|
|
8
|
+
export {
|
|
9
|
+
ContextFactory,
|
|
10
|
+
EvaluatorFacade,
|
|
11
|
+
MinimalContextFactory,
|
|
12
|
+
SdkFacade,
|
|
13
|
+
SessionFacade,
|
|
14
|
+
SessionPatch,
|
|
15
|
+
TabContextFactory,
|
|
16
|
+
TrackerFacade,
|
|
17
|
+
UserFacade,
|
|
18
|
+
UserPatch
|
|
19
|
+
};
|
|
20
20
|
//# sourceMappingURL=index.js.map
|
package/facade/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../src/facade/index.ts"],"sourcesContent":["export {EvaluatorFacade, ContextFactory, MinimalContextFactory, TabContextFactory} from './evaluatorFacade';\nexport {SdkFacade} from './sdkFacade';\nexport {SessionFacade} from './sessionFacade';\nexport {SessionPatch} from './sessionPatch';\nexport {TrackerFacade} from './trackerFacade';\nexport {UserFacade} from './userFacade';\nexport {UserPatch} from './userPatch';\n"],"mappings":"AAAA,SAAQ,iBAAiB,gBAAgB,uBAAuB,yBAAwB;AACxF,SAAQ,iBAAgB;AACxB,SAAQ,qBAAoB;AAC5B,SAAQ,oBAAmB;AAC3B,SAAQ,qBAAoB;AAC5B,SAAQ,kBAAiB;AACzB,SAAQ,iBAAgB;","names":[]}
|