@croct/sdk 0.17.8 → 0.17.10
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 +135 -0
- package/apiKey.cjs +178 -0
- package/base64Url.cjs +41 -0
- package/cache/cache.cjs +34 -0
- package/cache/cookieCache.cjs +85 -0
- package/cache/fallbackCache.cjs +47 -0
- package/cache/inMemoryCache.cjs +41 -0
- package/cache/index.cjs +37 -0
- package/cache/localStorageCache.cjs +81 -0
- package/channel/channel.cjs +48 -0
- package/channel/encodedChannel.cjs +39 -0
- package/channel/guaranteedChannel.cjs +105 -0
- package/channel/httpBeaconChannel.cjs +111 -0
- package/channel/index.cjs +46 -0
- package/channel/queuedChannel.cjs +122 -0
- package/channel/retryChannel.cjs +87 -0
- package/channel/sandboxChannel.cjs +63 -0
- package/cid/assigner.cjs +16 -0
- package/cid/cachedAssigner.cjs +66 -0
- package/cid/fixedAssigner.cjs +35 -0
- package/cid/index.cjs +37 -0
- package/cid/remoteAssigner.cjs +65 -0
- package/constants.cjs +37 -0
- package/constants.cjs.map +1 -1
- package/constants.d.ts +2 -2
- package/constants.js +1 -1
- package/constants.js.map +1 -1
- package/container.cjs +305 -0
- package/contentFetcher.cjs +193 -0
- package/context.cjs +114 -0
- package/error.cjs +52 -0
- package/evaluator.cjs +219 -0
- package/eventManager.cjs +53 -0
- package/eventSubjectProcessor.cjs +84 -0
- package/facade/contentFetcherFacade.cjs +61 -0
- package/facade/evaluatorFacade.cjs +94 -0
- package/facade/index.cjs +52 -0
- package/facade/sdkFacade.cjs +229 -0
- package/facade/sessionFacade.cjs +36 -0
- package/facade/sessionPatch.cjs +48 -0
- package/facade/trackerFacade.cjs +87 -0
- package/facade/userFacade.cjs +43 -0
- package/facade/userPatch.cjs +48 -0
- package/help.cjs +45 -0
- package/index.cjs +33 -0
- package/logging/consoleLogger.cjs +50 -0
- package/logging/filteredLogger.cjs +62 -0
- package/logging/index.cjs +40 -0
- package/logging/logger.cjs +16 -0
- package/logging/namespacedLogger.cjs +48 -0
- package/logging/nullLogger.cjs +37 -0
- package/namespacedStorage.cjs +77 -0
- package/package.json +29 -28
- package/patch.cjs +16 -0
- package/queue/capacityRestrictedQueue.cjs +57 -0
- package/queue/inMemoryQueue.cjs +58 -0
- package/queue/index.cjs +40 -0
- package/queue/monitoredQueue.cjs +141 -0
- package/queue/persistentQueue.cjs +78 -0
- package/queue/queue.cjs +16 -0
- package/retry/arbitraryPolicy.cjs +41 -0
- package/retry/backoffPolicy.cjs +81 -0
- package/retry/index.cjs +40 -0
- package/retry/maxAttemptsPolicy.cjs +45 -0
- package/retry/neverPolicy.cjs +35 -0
- package/retry/policy.cjs +16 -0
- package/schema/attributeSchema.cjs +32 -0
- package/schema/contentFetcherSchemas.cjs +49 -0
- package/schema/contentSchemas.cjs +70 -0
- package/schema/contextSchemas.cjs +31 -0
- package/schema/ecommerceSchemas.cjs +209 -0
- package/schema/evaluatorSchemas.cjs +64 -0
- package/schema/eventSchemas.cjs +162 -0
- package/schema/index.cjs +42 -0
- package/schema/loggerSchema.cjs +38 -0
- package/schema/operationSchemas.cjs +122 -0
- package/schema/sdkFacadeSchemas.cjs +82 -0
- package/schema/sdkSchemas.cjs +110 -0
- package/schema/tokenSchema.cjs +68 -0
- package/schema/userSchema.cjs +202 -0
- package/sdk.cjs +134 -0
- package/sdkEvents.cjs +16 -0
- package/sourceLocation.cjs +92 -0
- package/tab.cjs +122 -0
- package/token/cachedTokenStore.cjs +51 -0
- package/token/inMemoryTokenStore.cjs +38 -0
- package/token/index.cjs +37 -0
- package/token/replicatedTokenStore.cjs +40 -0
- package/token/token.cjs +239 -0
- package/tracker.cjs +358 -0
- package/trackingEvents.cjs +94 -0
- package/transformer.cjs +30 -0
- package/utilityTypes.cjs +16 -0
- package/uuid.cjs +55 -0
- package/validation/arrayType.cjs +75 -0
- package/validation/booleanType.cjs +46 -0
- package/validation/functionType.cjs +46 -0
- package/validation/index.cjs +66 -0
- package/validation/jsonType.cjs +142 -0
- package/validation/mixedSchema.cjs +31 -0
- package/validation/nullType.cjs +46 -0
- package/validation/numberType.cjs +69 -0
- package/validation/objectType.cjs +114 -0
- package/validation/schema.cjs +34 -0
- package/validation/stringType.cjs +106 -0
- package/validation/unionType.cjs +67 -0
- package/validation/violation.cjs +47 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var eventSubjectProcessor_exports = {};
|
|
19
|
+
__export(eventSubjectProcessor_exports, {
|
|
20
|
+
EventSubjectProcessor: () => EventSubjectProcessor
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(eventSubjectProcessor_exports);
|
|
23
|
+
class EventSubjectProcessor {
|
|
24
|
+
constructor(logger) {
|
|
25
|
+
this.logger = logger;
|
|
26
|
+
}
|
|
27
|
+
process(event) {
|
|
28
|
+
const { currentToken } = this;
|
|
29
|
+
this.currentToken = event.userToken ?? null;
|
|
30
|
+
if (currentToken === void 0) {
|
|
31
|
+
return [event];
|
|
32
|
+
}
|
|
33
|
+
if (EventSubjectProcessor.isIdentificationEvent(event.event)) {
|
|
34
|
+
return [event];
|
|
35
|
+
}
|
|
36
|
+
const currentSubject = currentToken?.getSubject() ?? null;
|
|
37
|
+
const newSubject = event.userToken?.getSubject() ?? null;
|
|
38
|
+
if (newSubject === currentSubject) {
|
|
39
|
+
return [event];
|
|
40
|
+
}
|
|
41
|
+
const events = [];
|
|
42
|
+
if (currentToken !== null && currentSubject !== null) {
|
|
43
|
+
this.logger.info("External user sign out automatically tracked");
|
|
44
|
+
events.push({
|
|
45
|
+
timestamp: event.timestamp,
|
|
46
|
+
context: event.context,
|
|
47
|
+
userToken: currentToken,
|
|
48
|
+
event: {
|
|
49
|
+
type: "userSignedOut",
|
|
50
|
+
userId: currentSubject
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
if (newSubject !== null) {
|
|
55
|
+
this.logger.info("External user sign in automatically tracked");
|
|
56
|
+
events.push({
|
|
57
|
+
timestamp: event.timestamp,
|
|
58
|
+
context: event.context,
|
|
59
|
+
userToken: event.userToken,
|
|
60
|
+
event: {
|
|
61
|
+
type: "userSignedIn",
|
|
62
|
+
userId: newSubject
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
events.push(event);
|
|
67
|
+
return events;
|
|
68
|
+
}
|
|
69
|
+
static isIdentificationEvent(event) {
|
|
70
|
+
switch (event.type) {
|
|
71
|
+
case "userSignedIn":
|
|
72
|
+
case "userSignedUp":
|
|
73
|
+
case "userSignedOut":
|
|
74
|
+
return true;
|
|
75
|
+
default:
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
81
|
+
0 && (module.exports = {
|
|
82
|
+
EventSubjectProcessor
|
|
83
|
+
});
|
|
84
|
+
//# sourceMappingURL=eventSubjectProcessor.cjs.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var contentFetcherFacade_exports = {};
|
|
19
|
+
__export(contentFetcherFacade_exports, {
|
|
20
|
+
ContentFetcherFacade: () => ContentFetcherFacade
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(contentFetcherFacade_exports);
|
|
23
|
+
var import_error = require("../error");
|
|
24
|
+
var import_schema = require("../schema");
|
|
25
|
+
function validate(options) {
|
|
26
|
+
try {
|
|
27
|
+
import_schema.fetchOptionsSchema.validate(options);
|
|
28
|
+
} catch (violation) {
|
|
29
|
+
throw new Error(`Invalid options: ${(0, import_error.formatCause)(violation)}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
class ContentFetcherFacade {
|
|
33
|
+
constructor(configuration) {
|
|
34
|
+
this.fetcher = configuration.contentFetcher;
|
|
35
|
+
this.previewTokenProvider = configuration.previewTokenProvider;
|
|
36
|
+
this.userTokenProvider = configuration.userTokenProvider;
|
|
37
|
+
this.cidAssigner = configuration.cidAssigner;
|
|
38
|
+
this.contextFactory = configuration.contextFactory;
|
|
39
|
+
}
|
|
40
|
+
async fetch(slotId, options = {}) {
|
|
41
|
+
if (typeof slotId !== "string" || slotId.length === 0) {
|
|
42
|
+
throw new Error("The slot ID must be a non-empty string.");
|
|
43
|
+
}
|
|
44
|
+
validate(options);
|
|
45
|
+
return this.fetcher.fetch(slotId, {
|
|
46
|
+
static: false,
|
|
47
|
+
clientId: await this.cidAssigner.assignCid(),
|
|
48
|
+
userToken: this.userTokenProvider.getToken() ?? void 0,
|
|
49
|
+
previewToken: this.previewTokenProvider.getToken() ?? void 0,
|
|
50
|
+
version: options.version,
|
|
51
|
+
context: this.contextFactory.createContext(options.attributes),
|
|
52
|
+
timeout: options.timeout,
|
|
53
|
+
preferredLocale: options.preferredLocale
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
58
|
+
0 && (module.exports = {
|
|
59
|
+
ContentFetcherFacade
|
|
60
|
+
});
|
|
61
|
+
//# sourceMappingURL=contentFetcherFacade.cjs.map
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var evaluatorFacade_exports = {};
|
|
19
|
+
__export(evaluatorFacade_exports, {
|
|
20
|
+
EvaluatorFacade: () => EvaluatorFacade,
|
|
21
|
+
MinimalContextFactory: () => MinimalContextFactory,
|
|
22
|
+
TabContextFactory: () => TabContextFactory
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(evaluatorFacade_exports);
|
|
25
|
+
var import_schema = require("../schema");
|
|
26
|
+
var import_error = require("../error");
|
|
27
|
+
function validate(options) {
|
|
28
|
+
try {
|
|
29
|
+
import_schema.evaluationOptionsSchema.validate(options);
|
|
30
|
+
} catch (violation) {
|
|
31
|
+
throw new Error(`Invalid options: ${(0, import_error.formatCause)(violation)}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
class EvaluatorFacade {
|
|
35
|
+
constructor(configuration) {
|
|
36
|
+
this.evaluator = configuration.evaluator;
|
|
37
|
+
this.contextFactory = configuration.contextFactory;
|
|
38
|
+
this.tokenProvider = configuration.userTokenProvider;
|
|
39
|
+
this.cidAssigner = configuration.cidAssigner;
|
|
40
|
+
}
|
|
41
|
+
async evaluate(query, options = {}) {
|
|
42
|
+
if (typeof query !== "string" || query.length === 0) {
|
|
43
|
+
throw new Error("The query must be a non-empty string.");
|
|
44
|
+
}
|
|
45
|
+
validate(options);
|
|
46
|
+
return this.evaluator.evaluate(query, {
|
|
47
|
+
clientId: await this.cidAssigner.assignCid(),
|
|
48
|
+
userToken: this.tokenProvider.getToken() ?? void 0,
|
|
49
|
+
timeout: options.timeout,
|
|
50
|
+
context: this.contextFactory.createContext(options.attributes)
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
class MinimalContextFactory {
|
|
55
|
+
createContext(attributes) {
|
|
56
|
+
if (attributes === void 0) {
|
|
57
|
+
return {};
|
|
58
|
+
}
|
|
59
|
+
return { attributes };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
class TabContextFactory {
|
|
63
|
+
constructor(tab) {
|
|
64
|
+
this.tab = tab;
|
|
65
|
+
}
|
|
66
|
+
createContext(attributes) {
|
|
67
|
+
const url = new URL(this.tab.url);
|
|
68
|
+
const context = {};
|
|
69
|
+
const page = {
|
|
70
|
+
title: this.tab.title,
|
|
71
|
+
url: url.toString()
|
|
72
|
+
};
|
|
73
|
+
const { referrer } = this.tab;
|
|
74
|
+
if (referrer.length > 0) {
|
|
75
|
+
page.referrer = referrer;
|
|
76
|
+
}
|
|
77
|
+
context.page = page;
|
|
78
|
+
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone ?? null;
|
|
79
|
+
if (timeZone !== null) {
|
|
80
|
+
context.timeZone = timeZone;
|
|
81
|
+
}
|
|
82
|
+
if (attributes !== void 0 && Object.keys(attributes).length > 0) {
|
|
83
|
+
context.attributes = attributes;
|
|
84
|
+
}
|
|
85
|
+
return context;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
89
|
+
0 && (module.exports = {
|
|
90
|
+
EvaluatorFacade,
|
|
91
|
+
MinimalContextFactory,
|
|
92
|
+
TabContextFactory
|
|
93
|
+
});
|
|
94
|
+
//# sourceMappingURL=evaluatorFacade.cjs.map
|
package/facade/index.cjs
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var facade_exports = {};
|
|
19
|
+
__export(facade_exports, {
|
|
20
|
+
ContextFactory: () => import_evaluatorFacade.ContextFactory,
|
|
21
|
+
EvaluatorFacade: () => import_evaluatorFacade.EvaluatorFacade,
|
|
22
|
+
MinimalContextFactory: () => import_evaluatorFacade.MinimalContextFactory,
|
|
23
|
+
SdkFacade: () => import_sdkFacade.SdkFacade,
|
|
24
|
+
SessionFacade: () => import_sessionFacade.SessionFacade,
|
|
25
|
+
SessionPatch: () => import_sessionPatch.SessionPatch,
|
|
26
|
+
TabContextFactory: () => import_evaluatorFacade.TabContextFactory,
|
|
27
|
+
TrackerFacade: () => import_trackerFacade.TrackerFacade,
|
|
28
|
+
UserFacade: () => import_userFacade.UserFacade,
|
|
29
|
+
UserPatch: () => import_userPatch.UserPatch
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(facade_exports);
|
|
32
|
+
var import_evaluatorFacade = require("./evaluatorFacade");
|
|
33
|
+
var import_sdkFacade = require("./sdkFacade");
|
|
34
|
+
var import_sessionFacade = require("./sessionFacade");
|
|
35
|
+
var import_sessionPatch = require("./sessionPatch");
|
|
36
|
+
var import_trackerFacade = require("./trackerFacade");
|
|
37
|
+
var import_userFacade = require("./userFacade");
|
|
38
|
+
var import_userPatch = require("./userPatch");
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
ContextFactory,
|
|
42
|
+
EvaluatorFacade,
|
|
43
|
+
MinimalContextFactory,
|
|
44
|
+
SdkFacade,
|
|
45
|
+
SessionFacade,
|
|
46
|
+
SessionPatch,
|
|
47
|
+
TabContextFactory,
|
|
48
|
+
TrackerFacade,
|
|
49
|
+
UserFacade,
|
|
50
|
+
UserPatch
|
|
51
|
+
});
|
|
52
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var sdkFacade_exports = {};
|
|
19
|
+
__export(sdkFacade_exports, {
|
|
20
|
+
SdkFacade: () => SdkFacade
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(sdkFacade_exports);
|
|
23
|
+
var import_evaluatorFacade = require("./evaluatorFacade");
|
|
24
|
+
var import_trackerFacade = require("./trackerFacade");
|
|
25
|
+
var import_userFacade = require("./userFacade");
|
|
26
|
+
var import_token = require("../token");
|
|
27
|
+
var import_error = require("../error");
|
|
28
|
+
var import_schema = require("../schema");
|
|
29
|
+
var import_sdk = require("../sdk");
|
|
30
|
+
var import_sessionFacade = require("./sessionFacade");
|
|
31
|
+
var import_contentFetcherFacade = require("./contentFetcherFacade");
|
|
32
|
+
var import_eventSubjectProcessor = require("../eventSubjectProcessor");
|
|
33
|
+
function validateConfiguration(configuration) {
|
|
34
|
+
try {
|
|
35
|
+
import_schema.sdkFacadeConfigurationSchema.validate(configuration);
|
|
36
|
+
} catch (violation) {
|
|
37
|
+
throw new Error(`Invalid configuration: ${(0, import_error.formatCause)(violation)}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
class SdkFacade {
|
|
41
|
+
constructor(sdk) {
|
|
42
|
+
this.sdk = sdk;
|
|
43
|
+
}
|
|
44
|
+
static init(configuration) {
|
|
45
|
+
validateConfiguration(configuration);
|
|
46
|
+
const { track = true, userId, token, ...containerConfiguration } = configuration;
|
|
47
|
+
if (userId !== void 0 && token !== void 0) {
|
|
48
|
+
throw new Error("Either the user ID or token can be specified, but not both.");
|
|
49
|
+
}
|
|
50
|
+
const sdk = new SdkFacade(
|
|
51
|
+
import_sdk.Sdk.init({
|
|
52
|
+
...containerConfiguration,
|
|
53
|
+
tokenScope: containerConfiguration.tokenScope ?? "global",
|
|
54
|
+
debug: containerConfiguration.debug ?? false,
|
|
55
|
+
test: containerConfiguration.test ?? false,
|
|
56
|
+
disableCidMirroring: containerConfiguration.disableCidMirroring ?? false,
|
|
57
|
+
eventProcessor: (container) => new import_eventSubjectProcessor.EventSubjectProcessor(container.getLogger("EventSubjectProcessor"))
|
|
58
|
+
})
|
|
59
|
+
);
|
|
60
|
+
if (userId !== void 0) {
|
|
61
|
+
const currentToken = sdk.context.getToken();
|
|
62
|
+
const currentSubject = currentToken?.getSubject() ?? null;
|
|
63
|
+
if (currentSubject !== userId) {
|
|
64
|
+
if (userId === null) {
|
|
65
|
+
sdk.unsetToken();
|
|
66
|
+
} else {
|
|
67
|
+
sdk.identify(userId);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
} else if (token !== void 0) {
|
|
71
|
+
if (token === null) {
|
|
72
|
+
sdk.unsetToken();
|
|
73
|
+
} else {
|
|
74
|
+
sdk.setToken(import_token.Token.parse(token));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (track) {
|
|
78
|
+
sdk.tracker.enable();
|
|
79
|
+
}
|
|
80
|
+
return sdk;
|
|
81
|
+
}
|
|
82
|
+
get context() {
|
|
83
|
+
return this.sdk.context;
|
|
84
|
+
}
|
|
85
|
+
get cidAssigner() {
|
|
86
|
+
return this.sdk.cidAssigner;
|
|
87
|
+
}
|
|
88
|
+
get previewTokenStore() {
|
|
89
|
+
return this.sdk.previewTokenStore;
|
|
90
|
+
}
|
|
91
|
+
get userTokenStore() {
|
|
92
|
+
return this.sdk.userTokenStore;
|
|
93
|
+
}
|
|
94
|
+
get tracker() {
|
|
95
|
+
if (this.trackerFacade === void 0) {
|
|
96
|
+
this.trackerFacade = new import_trackerFacade.TrackerFacade(this.sdk.tracker);
|
|
97
|
+
}
|
|
98
|
+
return this.trackerFacade;
|
|
99
|
+
}
|
|
100
|
+
get user() {
|
|
101
|
+
if (this.userFacade === void 0) {
|
|
102
|
+
this.userFacade = new import_userFacade.UserFacade(this.context, this.sdk.tracker);
|
|
103
|
+
}
|
|
104
|
+
return this.userFacade;
|
|
105
|
+
}
|
|
106
|
+
get session() {
|
|
107
|
+
if (this.sessionFacade === void 0) {
|
|
108
|
+
this.sessionFacade = new import_sessionFacade.SessionFacade(this.sdk.tracker);
|
|
109
|
+
}
|
|
110
|
+
return this.sessionFacade;
|
|
111
|
+
}
|
|
112
|
+
get evaluator() {
|
|
113
|
+
if (this.evaluatorFacade === void 0) {
|
|
114
|
+
this.evaluatorFacade = new import_evaluatorFacade.EvaluatorFacade({
|
|
115
|
+
evaluator: this.sdk.evaluator,
|
|
116
|
+
contextFactory: new import_evaluatorFacade.TabContextFactory(this.sdk.context.getTab()),
|
|
117
|
+
cidAssigner: this.sdk.cidAssigner,
|
|
118
|
+
userTokenProvider: this.sdk.userTokenStore
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
return this.evaluatorFacade;
|
|
122
|
+
}
|
|
123
|
+
get contentFetcher() {
|
|
124
|
+
if (this.contentFetcherFacade === void 0) {
|
|
125
|
+
this.contentFetcherFacade = new import_contentFetcherFacade.ContentFetcherFacade({
|
|
126
|
+
contentFetcher: this.sdk.contentFetcher,
|
|
127
|
+
contextFactory: new import_evaluatorFacade.TabContextFactory(this.sdk.context.getTab()),
|
|
128
|
+
cidAssigner: this.sdk.cidAssigner,
|
|
129
|
+
previewTokenProvider: this.sdk.previewTokenStore,
|
|
130
|
+
userTokenProvider: this.sdk.userTokenStore
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return this.contentFetcherFacade;
|
|
134
|
+
}
|
|
135
|
+
get eventManager() {
|
|
136
|
+
const { eventManager } = this.sdk;
|
|
137
|
+
return {
|
|
138
|
+
addListener: eventManager.addListener.bind(eventManager),
|
|
139
|
+
removeListener: eventManager.removeListener.bind(eventManager),
|
|
140
|
+
dispatch: (eventName, event) => {
|
|
141
|
+
if (!/[a-z][a-z_]+\.[a-z][a-z_]+/i.test(eventName)) {
|
|
142
|
+
throw new Error(
|
|
143
|
+
'The event name must be in the form of "namespaced.eventName", where both the namespace and event name must start with a letter, followed by any series of letters and underscores.'
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
eventManager.dispatch(eventName, event);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
identify(userId) {
|
|
151
|
+
this.setToken(import_token.Token.issue(this.sdk.appId, userId));
|
|
152
|
+
}
|
|
153
|
+
anonymize() {
|
|
154
|
+
if (!this.context.isAnonymous()) {
|
|
155
|
+
this.unsetToken();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
getToken() {
|
|
159
|
+
return this.context.getToken();
|
|
160
|
+
}
|
|
161
|
+
setToken(token) {
|
|
162
|
+
const currentToken = this.getToken();
|
|
163
|
+
if (currentToken !== null && currentToken.toString() === token.toString()) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const currentSubject = currentToken?.getSubject() ?? null;
|
|
167
|
+
const subject = token.getSubject();
|
|
168
|
+
const logger = this.getLogger();
|
|
169
|
+
if (subject === currentSubject) {
|
|
170
|
+
this.context.setToken(token);
|
|
171
|
+
logger.debug("Token refreshed");
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (currentSubject !== null) {
|
|
175
|
+
this.trackInternalEvent({
|
|
176
|
+
type: "userSignedOut",
|
|
177
|
+
userId: currentSubject
|
|
178
|
+
});
|
|
179
|
+
logger.info("User signed out");
|
|
180
|
+
}
|
|
181
|
+
this.context.setToken(token);
|
|
182
|
+
if (subject !== null) {
|
|
183
|
+
this.trackInternalEvent({
|
|
184
|
+
type: "userSignedIn",
|
|
185
|
+
userId: subject
|
|
186
|
+
});
|
|
187
|
+
logger.info(`User signed in as ${subject}`);
|
|
188
|
+
}
|
|
189
|
+
logger.debug("New token saved, ");
|
|
190
|
+
}
|
|
191
|
+
unsetToken() {
|
|
192
|
+
const token = this.getToken();
|
|
193
|
+
if (token === null) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const logger = this.getLogger();
|
|
197
|
+
const subject = token.getSubject();
|
|
198
|
+
if (subject !== null) {
|
|
199
|
+
this.trackInternalEvent({
|
|
200
|
+
type: "userSignedOut",
|
|
201
|
+
userId: subject
|
|
202
|
+
});
|
|
203
|
+
logger.info("User signed out");
|
|
204
|
+
}
|
|
205
|
+
this.context.setToken(null);
|
|
206
|
+
logger.debug("Token removed");
|
|
207
|
+
}
|
|
208
|
+
trackInternalEvent(event) {
|
|
209
|
+
this.sdk.tracker.track(event).catch(() => {
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
getLogger(...namespace) {
|
|
213
|
+
return this.sdk.getLogger(...namespace);
|
|
214
|
+
}
|
|
215
|
+
getTabStorage(namespace, ...subnamespace) {
|
|
216
|
+
return this.sdk.getTabStorage(namespace, ...subnamespace);
|
|
217
|
+
}
|
|
218
|
+
getBrowserStorage(namespace, ...subnamespace) {
|
|
219
|
+
return this.sdk.getBrowserStorage(namespace, ...subnamespace);
|
|
220
|
+
}
|
|
221
|
+
close() {
|
|
222
|
+
return this.sdk.close();
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
226
|
+
0 && (module.exports = {
|
|
227
|
+
SdkFacade
|
|
228
|
+
});
|
|
229
|
+
//# sourceMappingURL=sdkFacade.cjs.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var sessionFacade_exports = {};
|
|
19
|
+
__export(sessionFacade_exports, {
|
|
20
|
+
SessionFacade: () => SessionFacade
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(sessionFacade_exports);
|
|
23
|
+
var import_sessionPatch = require("./sessionPatch");
|
|
24
|
+
class SessionFacade {
|
|
25
|
+
constructor(tracker) {
|
|
26
|
+
this.tracker = tracker;
|
|
27
|
+
}
|
|
28
|
+
edit() {
|
|
29
|
+
return new import_sessionPatch.SessionPatch(this.tracker);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
33
|
+
0 && (module.exports = {
|
|
34
|
+
SessionFacade
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=sessionFacade.cjs.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var sessionPatch_exports = {};
|
|
19
|
+
__export(sessionPatch_exports, {
|
|
20
|
+
SessionPatch: () => SessionPatch
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(sessionPatch_exports);
|
|
23
|
+
var import_activeRecord = require("../activeRecord");
|
|
24
|
+
class SessionPatch extends import_activeRecord.ActiveRecord {
|
|
25
|
+
constructor(tracker) {
|
|
26
|
+
super();
|
|
27
|
+
this.tracker = tracker;
|
|
28
|
+
}
|
|
29
|
+
save() {
|
|
30
|
+
if (!this.isDirty()) {
|
|
31
|
+
return Promise.resolve({
|
|
32
|
+
type: "sessionAttributesChanged",
|
|
33
|
+
patch: { operations: [] }
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
const promise = this.tracker.track({
|
|
37
|
+
type: "sessionAttributesChanged",
|
|
38
|
+
patch: this.buildPatch()
|
|
39
|
+
});
|
|
40
|
+
this.reset();
|
|
41
|
+
return promise;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
+
0 && (module.exports = {
|
|
46
|
+
SessionPatch
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=sessionPatch.cjs.map
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var trackerFacade_exports = {};
|
|
19
|
+
__export(trackerFacade_exports, {
|
|
20
|
+
TrackerFacade: () => TrackerFacade
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(trackerFacade_exports);
|
|
23
|
+
var import_error = require("../error");
|
|
24
|
+
var import_schema = require("../schema");
|
|
25
|
+
const eventSchemas = {
|
|
26
|
+
cartViewed: import_schema.cartViewed,
|
|
27
|
+
cartModified: import_schema.cartModified,
|
|
28
|
+
checkoutStarted: import_schema.checkoutStarted,
|
|
29
|
+
orderPlaced: import_schema.orderPlaced,
|
|
30
|
+
productViewed: import_schema.productViewed,
|
|
31
|
+
userSignedUp: import_schema.userSignedUp,
|
|
32
|
+
eventOccurred: import_schema.eventOccurred,
|
|
33
|
+
interestShown: import_schema.interestShown,
|
|
34
|
+
postViewed: import_schema.postViewed,
|
|
35
|
+
goalCompleted: import_schema.goalCompleted,
|
|
36
|
+
linkOpened: import_schema.linkOpened
|
|
37
|
+
};
|
|
38
|
+
function validateEvent(event) {
|
|
39
|
+
const { type, ...payload } = event;
|
|
40
|
+
if (!(type in eventSchemas)) {
|
|
41
|
+
throw new Error(`Unknown event type '${type}'.`);
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
eventSchemas[type].validate(payload);
|
|
45
|
+
} catch (violation) {
|
|
46
|
+
throw new Error(`Invalid event payload: ${(0, import_error.formatCause)(violation)}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function createEvent(type, payload) {
|
|
50
|
+
if (typeof type !== "string") {
|
|
51
|
+
throw new Error("The event type must of type string.");
|
|
52
|
+
}
|
|
53
|
+
if (typeof payload !== "object" || payload == null) {
|
|
54
|
+
throw new Error("The event payload must of type object.");
|
|
55
|
+
}
|
|
56
|
+
const event = { type, ...payload };
|
|
57
|
+
validateEvent(event);
|
|
58
|
+
return event;
|
|
59
|
+
}
|
|
60
|
+
class TrackerFacade {
|
|
61
|
+
constructor(tracker) {
|
|
62
|
+
this.tracker = tracker;
|
|
63
|
+
}
|
|
64
|
+
get flushed() {
|
|
65
|
+
return this.tracker.flushed;
|
|
66
|
+
}
|
|
67
|
+
enable() {
|
|
68
|
+
this.tracker.enable();
|
|
69
|
+
}
|
|
70
|
+
disable() {
|
|
71
|
+
this.tracker.disable();
|
|
72
|
+
}
|
|
73
|
+
addListener(listener) {
|
|
74
|
+
this.tracker.addListener(listener);
|
|
75
|
+
}
|
|
76
|
+
removeListener(listener) {
|
|
77
|
+
this.tracker.removeListener(listener);
|
|
78
|
+
}
|
|
79
|
+
track(type, payload) {
|
|
80
|
+
return this.tracker.track(createEvent(type, payload));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
84
|
+
0 && (module.exports = {
|
|
85
|
+
TrackerFacade
|
|
86
|
+
});
|
|
87
|
+
//# sourceMappingURL=trackerFacade.cjs.map
|