@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,66 @@
|
|
|
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 cachedAssigner_exports = {};
|
|
19
|
+
__export(cachedAssigner_exports, {
|
|
20
|
+
CachedAssigner: () => CachedAssigner
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(cachedAssigner_exports);
|
|
23
|
+
var import_logging = require("../logging");
|
|
24
|
+
class CachedAssigner {
|
|
25
|
+
constructor(assigner, cache, options = {}) {
|
|
26
|
+
this.assigner = assigner;
|
|
27
|
+
this.cache = cache;
|
|
28
|
+
this.options = {
|
|
29
|
+
logger: options.logger ?? new import_logging.NullLogger(),
|
|
30
|
+
mirror: options.mirror ?? false
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
async assignCid(currentCid) {
|
|
34
|
+
const cachedCid = this.cache.get();
|
|
35
|
+
const previousCid = currentCid ?? cachedCid ?? null;
|
|
36
|
+
const { logger, mirror } = this.options;
|
|
37
|
+
if (previousCid === null) {
|
|
38
|
+
const newCid = await this.assigner.assignCid();
|
|
39
|
+
this.cache.put(newCid);
|
|
40
|
+
logger.debug("New CID stored into cache");
|
|
41
|
+
return newCid;
|
|
42
|
+
}
|
|
43
|
+
logger.debug("Using existing CID");
|
|
44
|
+
if (cachedCid !== previousCid) {
|
|
45
|
+
logger.debug("The cached CID is stale, updating cache...");
|
|
46
|
+
this.cache.put(previousCid);
|
|
47
|
+
}
|
|
48
|
+
if (mirror) {
|
|
49
|
+
logger.debug("Mirroring CID");
|
|
50
|
+
this.assigner.assignCid(previousCid).then((newCid) => {
|
|
51
|
+
if (newCid !== previousCid) {
|
|
52
|
+
logger.warn("The CID has changed, updating cache...");
|
|
53
|
+
this.cache.put(newCid);
|
|
54
|
+
}
|
|
55
|
+
}).catch(() => {
|
|
56
|
+
logger.error("Failed to mirror CID");
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return previousCid;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
63
|
+
0 && (module.exports = {
|
|
64
|
+
CachedAssigner
|
|
65
|
+
});
|
|
66
|
+
//# sourceMappingURL=cachedAssigner.cjs.map
|
|
@@ -0,0 +1,35 @@
|
|
|
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 fixedAssigner_exports = {};
|
|
19
|
+
__export(fixedAssigner_exports, {
|
|
20
|
+
FixedAssigner: () => FixedAssigner
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(fixedAssigner_exports);
|
|
23
|
+
class FixedAssigner {
|
|
24
|
+
constructor(cid) {
|
|
25
|
+
this.cid = cid;
|
|
26
|
+
}
|
|
27
|
+
assignCid() {
|
|
28
|
+
return Promise.resolve(this.cid);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
32
|
+
0 && (module.exports = {
|
|
33
|
+
FixedAssigner
|
|
34
|
+
});
|
|
35
|
+
//# sourceMappingURL=fixedAssigner.cjs.map
|
package/cid/index.cjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var cid_exports = {};
|
|
20
|
+
__export(cid_exports, {
|
|
21
|
+
CachedAssigner: () => import_cachedAssigner.CachedAssigner,
|
|
22
|
+
FixedAssigner: () => import_fixedAssigner.FixedAssigner,
|
|
23
|
+
RemoteAssigner: () => import_remoteAssigner.RemoteAssigner
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(cid_exports);
|
|
26
|
+
__reExport(cid_exports, require("./assigner"), module.exports);
|
|
27
|
+
var import_cachedAssigner = require("./cachedAssigner");
|
|
28
|
+
var import_fixedAssigner = require("./fixedAssigner");
|
|
29
|
+
var import_remoteAssigner = require("./remoteAssigner");
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 && (module.exports = {
|
|
32
|
+
CachedAssigner,
|
|
33
|
+
FixedAssigner,
|
|
34
|
+
RemoteAssigner,
|
|
35
|
+
...require("./assigner")
|
|
36
|
+
});
|
|
37
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1,65 @@
|
|
|
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 remoteAssigner_exports = {};
|
|
19
|
+
__export(remoteAssigner_exports, {
|
|
20
|
+
RemoteAssigner: () => RemoteAssigner
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(remoteAssigner_exports);
|
|
23
|
+
var import_logging = require("../logging");
|
|
24
|
+
var import_error = require("../error");
|
|
25
|
+
var import_constants = require("../constants");
|
|
26
|
+
class RemoteAssigner {
|
|
27
|
+
constructor(endpoint, logger) {
|
|
28
|
+
this.endpoint = endpoint;
|
|
29
|
+
this.logger = logger ?? new import_logging.NullLogger();
|
|
30
|
+
}
|
|
31
|
+
assignCid(currentCid) {
|
|
32
|
+
if (this.pending === void 0) {
|
|
33
|
+
this.pending = this.fetchCid(currentCid).finally(() => {
|
|
34
|
+
this.pending = void 0;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return this.pending;
|
|
38
|
+
}
|
|
39
|
+
async fetchCid(currentCid) {
|
|
40
|
+
const options = {
|
|
41
|
+
method: "GET",
|
|
42
|
+
credentials: "include",
|
|
43
|
+
headers: {
|
|
44
|
+
"X-Client-Library": import_constants.CLIENT_LIBRARY
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const endpoint = new URL(this.endpoint);
|
|
48
|
+
if (currentCid !== void 0) {
|
|
49
|
+
endpoint.searchParams.set("cid", currentCid);
|
|
50
|
+
}
|
|
51
|
+
const response = await fetch(endpoint, options);
|
|
52
|
+
if (!response.ok) {
|
|
53
|
+
const error = new Error(`Failed to assign CID: ${(0, import_error.formatCause)(response.statusText)}`);
|
|
54
|
+
this.logger.error(error.message);
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
this.logger.debug("New CID successfully assigned");
|
|
58
|
+
return response.text();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
62
|
+
0 && (module.exports = {
|
|
63
|
+
RemoteAssigner
|
|
64
|
+
});
|
|
65
|
+
//# sourceMappingURL=remoteAssigner.cjs.map
|
package/constants.cjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
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 constants_exports = {};
|
|
19
|
+
__export(constants_exports, {
|
|
20
|
+
BASE_ENDPOINT_URL: () => BASE_ENDPOINT_URL,
|
|
21
|
+
CLIENT_LIBRARY: () => CLIENT_LIBRARY,
|
|
22
|
+
MAX_QUERY_LENGTH: () => MAX_QUERY_LENGTH,
|
|
23
|
+
VERSION: () => VERSION
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(constants_exports);
|
|
26
|
+
const BASE_ENDPOINT_URL = "https://api.croct.io";
|
|
27
|
+
const MAX_QUERY_LENGTH = parseInt("<@maxQueryLength@>", 10);
|
|
28
|
+
const VERSION = "0.17.10";
|
|
29
|
+
const CLIENT_LIBRARY = `Croct SDK JS v${VERSION}`;
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 && (module.exports = {
|
|
32
|
+
BASE_ENDPOINT_URL,
|
|
33
|
+
CLIENT_LIBRARY,
|
|
34
|
+
MAX_QUERY_LENGTH,
|
|
35
|
+
VERSION
|
|
36
|
+
});
|
|
37
|
+
//# sourceMappingURL=constants.cjs.map
|
package/constants.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/constants.ts"],"sourcesContent":["export const BASE_ENDPOINT_URL = 'https://api.croct.io';\nexport const MAX_QUERY_LENGTH = 500;\nexport const VERSION = '0.17.
|
|
1
|
+
{"version":3,"sources":["../src/constants.ts"],"sourcesContent":["export const BASE_ENDPOINT_URL = 'https://api.croct.io';\nexport const MAX_QUERY_LENGTH = 500;\nexport const VERSION = '0.17.10';\nexport const CLIENT_LIBRARY = `Croct SDK JS v${VERSION}`;\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,MAAM,oBAAoB;AAC1B,MAAM,mBAAmB,SAAS,sBAAsB,EAAE;AAC1D,MAAM,UAAU;AAChB,MAAM,iBAAiB,iBAAiB,OAAO;","names":[]}
|
package/constants.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
declare const BASE_ENDPOINT_URL = "https://api.croct.io";
|
|
2
2
|
declare const MAX_QUERY_LENGTH: number;
|
|
3
|
-
declare const VERSION = "0.17.
|
|
4
|
-
declare const CLIENT_LIBRARY = "Croct SDK JS v0.17.
|
|
3
|
+
declare const VERSION = "0.17.10";
|
|
4
|
+
declare const CLIENT_LIBRARY = "Croct SDK JS v0.17.10";
|
|
5
5
|
|
|
6
6
|
export { BASE_ENDPOINT_URL, CLIENT_LIBRARY, MAX_QUERY_LENGTH, VERSION };
|
package/constants.js
CHANGED
package/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["src/constants.ts"],"sourcesContent":["export const BASE_ENDPOINT_URL = 'https://api.croct.io';\nexport const MAX_QUERY_LENGTH = 500;\nexport const VERSION = '0.17.
|
|
1
|
+
{"version":3,"sources":["src/constants.ts"],"sourcesContent":["export const BASE_ENDPOINT_URL = 'https://api.croct.io';\nexport const MAX_QUERY_LENGTH = 500;\nexport const VERSION = '0.17.10';\nexport const CLIENT_LIBRARY = `Croct SDK JS v${VERSION}`;\n"],"mappings":"AAAO,MAAM,oBAAoB;AAC1B,MAAM,mBAAmB,SAAS,sBAAsB,EAAE;AAC1D,MAAM,UAAU;AAChB,MAAM,iBAAiB,iBAAiB,OAAO;","names":[]}
|
package/container.cjs
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
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 container_exports = {};
|
|
19
|
+
__export(container_exports, {
|
|
20
|
+
Container: () => Container
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(container_exports);
|
|
23
|
+
var import_logging = require("./logging");
|
|
24
|
+
var import_context = require("./context");
|
|
25
|
+
var import_namespacedStorage = require("./namespacedStorage");
|
|
26
|
+
var import_retry = require("./retry");
|
|
27
|
+
var import_queue = require("./queue");
|
|
28
|
+
var import_token = require("./token");
|
|
29
|
+
var import_tracker = require("./tracker");
|
|
30
|
+
var import_evaluator = require("./evaluator");
|
|
31
|
+
var import_transformer = require("./transformer");
|
|
32
|
+
var import_cid = require("./cid");
|
|
33
|
+
var import_eventManager = require("./eventManager");
|
|
34
|
+
var import_cache = require("./cache");
|
|
35
|
+
var import_guaranteedChannel = require("./channel/guaranteedChannel");
|
|
36
|
+
var import_channel = require("./channel");
|
|
37
|
+
var import_contentFetcher = require("./contentFetcher");
|
|
38
|
+
var import_cookieCache = require("./cache/cookieCache");
|
|
39
|
+
var import_filteredLogger = require("./logging/filteredLogger");
|
|
40
|
+
var import_httpBeaconChannel = require("./channel/httpBeaconChannel");
|
|
41
|
+
const _Container = class _Container {
|
|
42
|
+
constructor(configuration) {
|
|
43
|
+
this.eventManager = new import_eventManager.SynchronousEventManager();
|
|
44
|
+
this.configuration = configuration;
|
|
45
|
+
}
|
|
46
|
+
getConfiguration() {
|
|
47
|
+
return this.configuration;
|
|
48
|
+
}
|
|
49
|
+
getEvaluator() {
|
|
50
|
+
if (this.evaluator === void 0) {
|
|
51
|
+
this.evaluator = this.createEvaluator();
|
|
52
|
+
}
|
|
53
|
+
return this.evaluator;
|
|
54
|
+
}
|
|
55
|
+
createEvaluator() {
|
|
56
|
+
return new import_evaluator.Evaluator({
|
|
57
|
+
appId: this.configuration.appId,
|
|
58
|
+
baseEndpointUrl: this.configuration.evaluationBaseEndpointUrl,
|
|
59
|
+
logger: this.getLogger("Evaluator"),
|
|
60
|
+
defaultTimeout: this.configuration.defaultFetchTimeout ?? _Container.DEFAULT_FETCH_TIMEOUT
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
getContentFetcher() {
|
|
64
|
+
if (this.contentFetcher === void 0) {
|
|
65
|
+
this.contentFetcher = this.createContentFetcher();
|
|
66
|
+
}
|
|
67
|
+
return this.contentFetcher;
|
|
68
|
+
}
|
|
69
|
+
createContentFetcher() {
|
|
70
|
+
return new import_contentFetcher.ContentFetcher({
|
|
71
|
+
appId: this.configuration.appId,
|
|
72
|
+
baseEndpointUrl: this.configuration.contentBaseEndpointUrl,
|
|
73
|
+
logger: this.getLogger("ContentFetcher"),
|
|
74
|
+
defaultTimeout: this.configuration.defaultFetchTimeout ?? _Container.DEFAULT_FETCH_TIMEOUT,
|
|
75
|
+
defaultPreferredLocale: this.configuration.defaultPreferredLocale
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
getPreviewTokenStore() {
|
|
79
|
+
if (this.previewTokenStore === void 0) {
|
|
80
|
+
this.previewTokenStore = new import_token.CachedTokenStore(
|
|
81
|
+
this.configuration.cookie?.previewToken !== void 0 ? new import_cookieCache.CookieCache(this.configuration.cookie.previewToken) : new import_cache.LocalStorageCache(this.getGlobalBrowserStorage("preview"), "token")
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
return this.previewTokenStore;
|
|
85
|
+
}
|
|
86
|
+
getTracker() {
|
|
87
|
+
if (this.tracker === void 0) {
|
|
88
|
+
this.tracker = this.createTracker();
|
|
89
|
+
}
|
|
90
|
+
return this.tracker;
|
|
91
|
+
}
|
|
92
|
+
createTracker() {
|
|
93
|
+
const context = this.getContext();
|
|
94
|
+
const tracker = new import_tracker.Tracker({
|
|
95
|
+
tab: context.getTab(),
|
|
96
|
+
tokenProvider: this.getUserTokenStore(),
|
|
97
|
+
inactivityRetryPolicy: new import_retry.ArbitraryPolicy([3e4, 3e4, 12e4, 12e4, 3e5, 3e5, 9e5]),
|
|
98
|
+
logger: this.getLogger("Tracker"),
|
|
99
|
+
channel: this.getBeaconChannel(),
|
|
100
|
+
eventMetadata: this.configuration.eventMetadata,
|
|
101
|
+
processor: this.configuration.eventProcessor === void 0 ? void 0 : this.configuration.eventProcessor(this)
|
|
102
|
+
});
|
|
103
|
+
const queue = this.getBeaconQueue();
|
|
104
|
+
queue.addCallback("halfEmpty", tracker.unsuspend);
|
|
105
|
+
queue.addCallback("full", tracker.suspend);
|
|
106
|
+
return tracker;
|
|
107
|
+
}
|
|
108
|
+
getUserTokenStore() {
|
|
109
|
+
if (this.userTokenProvider === void 0) {
|
|
110
|
+
const context = this.getContext();
|
|
111
|
+
this.userTokenProvider = {
|
|
112
|
+
getToken: context.getToken.bind(context),
|
|
113
|
+
setToken: context.setToken.bind(context)
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
return this.userTokenProvider;
|
|
117
|
+
}
|
|
118
|
+
getContext() {
|
|
119
|
+
if (this.context === void 0) {
|
|
120
|
+
this.context = this.createContext();
|
|
121
|
+
}
|
|
122
|
+
return this.context;
|
|
123
|
+
}
|
|
124
|
+
createContext() {
|
|
125
|
+
const tokenKey = this.resolveStorageNamespace("token");
|
|
126
|
+
const tabKey = this.resolveStorageNamespace("tab");
|
|
127
|
+
const browserCache = this.configuration.tokenScope === "global" && this.configuration.cookie?.userToken !== void 0 ? new import_cookieCache.CookieCache(this.configuration.cookie.userToken) : new import_cache.LocalStorageCache(this.getLocalStorage(), tokenKey);
|
|
128
|
+
const tabStorage = this.getSessionStorage();
|
|
129
|
+
if (browserCache instanceof import_cache.LocalStorageCache) {
|
|
130
|
+
this.removeTokenSyncListener = import_cache.LocalStorageCache.autoSync(browserCache);
|
|
131
|
+
}
|
|
132
|
+
return import_context.Context.load({
|
|
133
|
+
tokenScope: this.configuration.tokenScope,
|
|
134
|
+
eventDispatcher: this.getEventManager(),
|
|
135
|
+
urlSanitizer: this.configuration.urlSanitizer,
|
|
136
|
+
cache: {
|
|
137
|
+
tabId: new import_cache.LocalStorageCache(tabStorage, tabKey),
|
|
138
|
+
tabToken: new import_cache.LocalStorageCache(tabStorage, tokenKey),
|
|
139
|
+
browserToken: browserCache
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
getBeaconChannel() {
|
|
144
|
+
if (this.beaconChannel === void 0) {
|
|
145
|
+
this.beaconChannel = this.createBeaconChannel();
|
|
146
|
+
}
|
|
147
|
+
return this.beaconChannel;
|
|
148
|
+
}
|
|
149
|
+
createBeaconChannel() {
|
|
150
|
+
if (this.configuration.test) {
|
|
151
|
+
return new import_channel.SandboxChannel();
|
|
152
|
+
}
|
|
153
|
+
const channelLogger = this.getLogger("BeaconChannel");
|
|
154
|
+
const { appId, trackerEndpointUrl } = this.configuration;
|
|
155
|
+
const queuedChannel = new import_channel.QueuedChannel(
|
|
156
|
+
new import_channel.RetryChannel({
|
|
157
|
+
channel: new import_channel.GuaranteedChannel({
|
|
158
|
+
channel: new import_httpBeaconChannel.HttpBeaconChannel({
|
|
159
|
+
appId,
|
|
160
|
+
endpointUrl: trackerEndpointUrl,
|
|
161
|
+
cidAssigner: this.getCidAssigner(),
|
|
162
|
+
logger: channelLogger
|
|
163
|
+
}),
|
|
164
|
+
stamper: new import_guaranteedChannel.TimeStamper(),
|
|
165
|
+
ackTimeout: 1e4,
|
|
166
|
+
logger: channelLogger
|
|
167
|
+
}),
|
|
168
|
+
retryPolicy: new import_retry.BackoffPolicy({
|
|
169
|
+
minRetryDelay: 3e3,
|
|
170
|
+
// 3 seconds
|
|
171
|
+
maxRetryDelay: 60 * 1e3,
|
|
172
|
+
// 60 seconds
|
|
173
|
+
backoffFactor: 1.5,
|
|
174
|
+
// 1.5 ^ attempt
|
|
175
|
+
backoffJitter: 1
|
|
176
|
+
// add randomness
|
|
177
|
+
}),
|
|
178
|
+
logger: channelLogger
|
|
179
|
+
}),
|
|
180
|
+
this.getBeaconQueue(),
|
|
181
|
+
channelLogger
|
|
182
|
+
);
|
|
183
|
+
queuedChannel.flush().catch(() => {
|
|
184
|
+
});
|
|
185
|
+
return new import_channel.EncodedChannel(queuedChannel, import_transformer.encodeJson);
|
|
186
|
+
}
|
|
187
|
+
getCidAssigner() {
|
|
188
|
+
if (this.cidAssigner === void 0) {
|
|
189
|
+
this.cidAssigner = this.createCidAssigner();
|
|
190
|
+
}
|
|
191
|
+
return this.cidAssigner;
|
|
192
|
+
}
|
|
193
|
+
createCidAssigner() {
|
|
194
|
+
if (this.configuration.clientId !== void 0) {
|
|
195
|
+
return new import_cid.FixedAssigner(this.configuration.clientId);
|
|
196
|
+
}
|
|
197
|
+
if (this.configuration.test) {
|
|
198
|
+
return new import_cid.FixedAssigner("00000000-0000-0000-0000-000000000000");
|
|
199
|
+
}
|
|
200
|
+
const logger = this.getLogger("CidAssigner");
|
|
201
|
+
return new import_cid.CachedAssigner(
|
|
202
|
+
new import_cid.RemoteAssigner(this.configuration.cidAssignerEndpointUrl, logger),
|
|
203
|
+
this.configuration.cookie?.clientId !== void 0 ? new import_cookieCache.CookieCache(this.configuration.cookie?.clientId) : new import_cache.LocalStorageCache(this.getLocalStorage(), "croct.cid"),
|
|
204
|
+
{
|
|
205
|
+
logger,
|
|
206
|
+
mirror: !this.configuration.disableCidMirroring
|
|
207
|
+
}
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
getBeaconQueue() {
|
|
211
|
+
if (this.beaconQueue === void 0) {
|
|
212
|
+
this.beaconQueue = this.createBeaconQueue();
|
|
213
|
+
}
|
|
214
|
+
return this.beaconQueue;
|
|
215
|
+
}
|
|
216
|
+
createBeaconQueue() {
|
|
217
|
+
return new import_queue.MonitoredQueue(
|
|
218
|
+
new import_queue.CapacityRestrictedQueue(
|
|
219
|
+
new import_queue.PersistentQueue(this.getGlobalTabStorage("queue")),
|
|
220
|
+
this.configuration.beaconQueueSize
|
|
221
|
+
),
|
|
222
|
+
this.getLogger("BeaconQueue")
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
getLogger(...namespace) {
|
|
226
|
+
const prefix = `Croct${namespace.length === 0 ? "" : `:${namespace.join(":")}`}`;
|
|
227
|
+
if (this.configuration.logger !== void 0) {
|
|
228
|
+
return new import_logging.NamespacedLogger(this.configuration.logger, prefix);
|
|
229
|
+
}
|
|
230
|
+
if (this.configuration.debug) {
|
|
231
|
+
return new import_logging.ConsoleLogger(prefix);
|
|
232
|
+
}
|
|
233
|
+
return import_filteredLogger.FilteredLogger.include(new import_logging.ConsoleLogger(), ["error", "warn"]);
|
|
234
|
+
}
|
|
235
|
+
getTabStorage(namespace, ...subnamespace) {
|
|
236
|
+
return this.getGlobalTabStorage("external", namespace, ...subnamespace);
|
|
237
|
+
}
|
|
238
|
+
getBrowserStorage(namespace, ...subnamespace) {
|
|
239
|
+
return this.getGlobalBrowserStorage("external", namespace, ...subnamespace);
|
|
240
|
+
}
|
|
241
|
+
getGlobalTabStorage(namespace, ...subnamespace) {
|
|
242
|
+
return new import_namespacedStorage.NamespacedStorage(
|
|
243
|
+
this.getSessionStorage(),
|
|
244
|
+
this.resolveStorageNamespace(namespace, ...subnamespace)
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
getGlobalBrowserStorage(namespace, ...subnamespace) {
|
|
248
|
+
return new import_namespacedStorage.NamespacedStorage(
|
|
249
|
+
this.getLocalStorage(),
|
|
250
|
+
this.resolveStorageNamespace(namespace, ...subnamespace)
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
resolveStorageNamespace(namespace, ...subnamespace) {
|
|
254
|
+
const { appId } = this.configuration;
|
|
255
|
+
return `croct[${appId.toLowerCase()}].${[namespace].concat(subnamespace).join(".")}`;
|
|
256
|
+
}
|
|
257
|
+
getLocalStorage() {
|
|
258
|
+
return localStorage;
|
|
259
|
+
}
|
|
260
|
+
getSessionStorage() {
|
|
261
|
+
return sessionStorage;
|
|
262
|
+
}
|
|
263
|
+
getEventManager() {
|
|
264
|
+
return this.eventManager;
|
|
265
|
+
}
|
|
266
|
+
async dispose() {
|
|
267
|
+
const logger = this.getLogger();
|
|
268
|
+
if (this.beaconChannel !== void 0) {
|
|
269
|
+
logger.debug("Closing beacon channel...");
|
|
270
|
+
await this.beaconChannel.close();
|
|
271
|
+
}
|
|
272
|
+
if (this.removeTokenSyncListener !== void 0) {
|
|
273
|
+
logger.debug("Removing token sync listener...");
|
|
274
|
+
this.removeTokenSyncListener();
|
|
275
|
+
}
|
|
276
|
+
if (this.tracker !== void 0) {
|
|
277
|
+
if (this.beaconQueue !== void 0) {
|
|
278
|
+
logger.debug("Removing queue listeners...");
|
|
279
|
+
this.beaconQueue.removeCallback("halfEmpty", this.tracker.unsuspend);
|
|
280
|
+
this.beaconQueue.removeCallback("full", this.tracker.suspend);
|
|
281
|
+
}
|
|
282
|
+
logger.debug("Suspending tracker...");
|
|
283
|
+
this.tracker.suspend();
|
|
284
|
+
await this.tracker.flushed;
|
|
285
|
+
}
|
|
286
|
+
delete this.context;
|
|
287
|
+
delete this.userTokenProvider;
|
|
288
|
+
delete this.previewTokenStore;
|
|
289
|
+
delete this.cidAssigner;
|
|
290
|
+
delete this.tracker;
|
|
291
|
+
delete this.evaluator;
|
|
292
|
+
delete this.contentFetcher;
|
|
293
|
+
delete this.beaconChannel;
|
|
294
|
+
delete this.beaconQueue;
|
|
295
|
+
delete this.removeTokenSyncListener;
|
|
296
|
+
logger.debug("Container resources released.");
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
_Container.DEFAULT_FETCH_TIMEOUT = 5e3;
|
|
300
|
+
let Container = _Container;
|
|
301
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
302
|
+
0 && (module.exports = {
|
|
303
|
+
Container
|
|
304
|
+
});
|
|
305
|
+
//# sourceMappingURL=container.cjs.map
|