@croct/sdk 0.5.0 → 0.7.0
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.d.ts +1 -1
- package/activeRecord.js +15 -12
- package/base64Url.js +7 -2
- package/cache/cache.d.ts +12 -0
- package/cache/cache.js +2 -0
- package/cache/fallbackCache.d.ts +2 -2
- package/cache/fallbackCache.js +6 -3
- package/cache/inMemoryCache.d.ts +2 -2
- package/cache/inMemoryCache.js +5 -2
- package/cache/index.d.ts +4 -12
- package/cache/index.js +11 -0
- package/cache/localStorageCache.d.ts +2 -2
- package/cache/localStorageCache.js +4 -1
- package/channel/beaconSocketChannel.d.ts +3 -3
- package/channel/beaconSocketChannel.js +12 -9
- package/channel/channel.d.ts +15 -0
- package/channel/channel.js +2 -0
- package/channel/encodedChannel.d.ts +2 -2
- package/channel/encodedChannel.js +4 -1
- package/channel/guaranteedChannel.d.ts +1 -1
- package/channel/guaranteedChannel.js +10 -7
- package/channel/index.d.ts +8 -15
- package/channel/index.js +19 -0
- package/channel/queuedChannel.d.ts +2 -2
- package/channel/queuedChannel.js +10 -7
- package/channel/retryChannel.d.ts +3 -3
- package/channel/retryChannel.js +18 -15
- package/channel/sandboxChannel.d.ts +2 -2
- package/channel/sandboxChannel.js +4 -1
- package/channel/socketChannel.d.ts +1 -1
- package/channel/socketChannel.js +12 -9
- package/cid/assigner.d.ts +3 -0
- package/cid/assigner.js +2 -0
- package/cid/cachedAssigner.d.ts +5 -5
- package/cid/cachedAssigner.js +9 -6
- package/cid/fixedAssigner.d.ts +6 -0
- package/cid/fixedAssigner.js +13 -0
- package/cid/index.d.ts +4 -3
- package/cid/index.js +11 -0
- package/cid/remoteAssigner.d.ts +3 -3
- package/cid/remoteAssigner.js +11 -8
- package/constants.js +8 -5
- package/container.d.ts +5 -5
- package/container.js +49 -55
- package/context.d.ts +4 -4
- package/context.js +14 -13
- package/error.d.ts +1 -1
- package/error.js +7 -2
- package/evaluator.d.ts +2 -2
- package/evaluator.js +26 -23
- package/eventManager.d.ts +1 -1
- package/eventManager.js +5 -2
- package/facade/evaluatorFacade.d.ts +3 -3
- package/facade/evaluatorFacade.js +13 -10
- package/facade/index.d.ts +7 -0
- package/facade/index.js +19 -0
- package/facade/sdkFacade.d.ts +9 -9
- package/facade/sdkFacade.js +35 -32
- package/facade/sessionFacade.d.ts +3 -3
- package/facade/sessionFacade.js +6 -3
- package/facade/sessionPatch.d.ts +3 -3
- package/facade/sessionPatch.js +8 -5
- package/facade/trackerFacade.d.ts +2 -2
- package/facade/trackerFacade.js +21 -17
- package/facade/userFacade.d.ts +4 -4
- package/facade/userFacade.js +6 -3
- package/facade/userPatch.d.ts +3 -3
- package/facade/userPatch.js +8 -5
- package/index.d.ts +2 -2
- package/index.js +7 -3
- package/json.js +2 -0
- package/logging/consoleLogger.d.ts +2 -2
- package/logging/consoleLogger.js +8 -5
- package/logging/index.d.ts +4 -9
- package/logging/index.js +11 -0
- package/logging/logger.d.ts +9 -0
- package/logging/logger.js +2 -0
- package/logging/namespacedLogger.d.ts +2 -2
- package/logging/namespacedLogger.js +4 -1
- package/logging/nullLogger.d.ts +2 -2
- package/logging/nullLogger.js +4 -1
- package/namespacedStorage.d.ts +1 -1
- package/namespacedStorage.js +7 -4
- package/package.json +21 -18
- package/patch.js +2 -0
- package/queue/capacityRestrictedQueue.d.ts +2 -2
- package/queue/capacityRestrictedQueue.js +4 -1
- package/queue/inMemoryQueue.d.ts +2 -2
- package/queue/inMemoryQueue.js +6 -3
- package/queue/index.d.ts +5 -9
- package/queue/index.js +13 -0
- package/queue/monitoredQueue.d.ts +6 -6
- package/queue/monitoredQueue.js +6 -3
- package/queue/persistentQueue.d.ts +2 -2
- package/queue/persistentQueue.js +5 -2
- package/queue/queue.d.ts +9 -0
- package/queue/queue.js +2 -0
- package/retry/arbitraryPolicy.d.ts +2 -2
- package/retry/arbitraryPolicy.js +6 -3
- package/retry/backoffPolicy.d.ts +2 -2
- package/retry/backoffPolicy.js +4 -1
- package/retry/index.d.ts +5 -4
- package/retry/index.js +13 -0
- package/retry/maxAttemptsPolicy.d.ts +2 -2
- package/retry/maxAttemptsPolicy.js +4 -1
- package/retry/neverPolicy.d.ts +2 -2
- package/retry/neverPolicy.js +4 -1
- package/retry/policy.d.ts +4 -0
- package/retry/policy.js +2 -0
- package/schema/attributeSchema.d.ts +2 -0
- package/schema/attributeSchema.js +8 -0
- package/schema/contentSchemas.d.ts +2 -0
- package/schema/contentSchemas.js +46 -0
- package/schema/contextSchemas.d.ts +1 -1
- package/schema/contextSchemas.js +5 -2
- package/schema/ecommerceSchemas.d.ts +1 -1
- package/schema/ecommerceSchemas.js +60 -60
- package/schema/evaluationSchemas.d.ts +1 -1
- package/schema/evaluationSchemas.js +7 -6
- package/schema/eventSchemas.d.ts +3 -2
- package/schema/eventSchemas.js +53 -48
- package/schema/index.d.ts +10 -0
- package/schema/index.js +13 -0
- package/schema/loggerSchema.d.ts +1 -1
- package/schema/loggerSchema.js +9 -7
- package/schema/operationSchemas.d.ts +1 -1
- package/schema/operationSchemas.js +26 -24
- package/schema/sdkFacadeSchemas.d.ts +2 -2
- package/schema/sdkFacadeSchemas.js +22 -24
- package/schema/sdkSchemas.d.ts +2 -2
- package/schema/sdkSchemas.js +21 -22
- package/schema/tokenSchema.d.ts +2 -3
- package/schema/tokenSchema.js +18 -17
- package/schema/userSchema.d.ts +1 -1
- package/schema/userSchema.js +47 -61
- package/sdk.d.ts +5 -5
- package/sdk.js +27 -24
- package/sdkEvents.d.ts +2 -2
- package/sdkEvents.js +2 -0
- package/sourceLocation.js +12 -6
- package/tab.d.ts +2 -2
- package/tab.js +12 -9
- package/token/cachedTokenStore.d.ts +3 -3
- package/token/cachedTokenStore.js +6 -3
- package/token/inMemoryTokenStore.d.ts +2 -2
- package/token/inMemoryTokenStore.js +4 -1
- package/token/index.d.ts +4 -41
- package/token/index.js +11 -96
- package/token/replicatedTokenStore.d.ts +2 -2
- package/token/replicatedTokenStore.js +4 -1
- package/token/token.d.ts +41 -0
- package/token/token.js +99 -0
- package/tracker.d.ts +3 -3
- package/tracker.js +29 -26
- package/trackingEvents.d.ts +29 -14
- package/trackingEvents.js +20 -14
- package/transformer.js +5 -1
- package/utilityTypes.js +2 -0
- package/uuid.js +5 -1
- package/validation/arrayType.d.ts +2 -2
- package/validation/arrayType.js +13 -9
- package/validation/booleanType.d.ts +2 -2
- package/validation/booleanType.js +7 -3
- package/validation/functionType.d.ts +2 -2
- package/validation/functionType.js +7 -3
- package/validation/index.d.ts +12 -18
- package/validation/index.js +29 -30
- package/validation/jsonType.d.ts +2 -1
- package/validation/jsonType.js +25 -14
- package/validation/mixedSchema.d.ts +2 -2
- package/validation/mixedSchema.js +4 -1
- package/validation/nullType.d.ts +2 -2
- package/validation/nullType.js +7 -3
- package/validation/numberType.d.ts +2 -2
- package/validation/numberType.js +13 -9
- package/validation/objectType.d.ts +2 -2
- package/validation/objectType.js +23 -18
- package/validation/schema.d.ts +16 -0
- package/validation/schema.js +15 -0
- package/validation/stringType.d.ts +2 -2
- package/validation/stringType.js +16 -12
- package/validation/unionType.d.ts +2 -2
- package/validation/unionType.js +14 -10
- package/validation/violation.d.ts +2 -0
- package/validation/violation.js +24 -0
- package/cid/fixedCidAssigner.d.ts +0 -6
- package/cid/fixedCidAssigner.js +0 -10
package/channel/socketChannel.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SocketChannel = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var logging_1 = require("../logging");
|
|
6
|
+
var error_1 = require("../error");
|
|
4
7
|
var SocketChannel = /** @class */ (function () {
|
|
5
8
|
function SocketChannel(_a) {
|
|
6
9
|
var _b, _c, _d;
|
|
7
|
-
var url = _a.url, logger = _a.logger, options = __rest(_a, ["url", "logger"]);
|
|
10
|
+
var url = _a.url, logger = _a.logger, options = tslib_1.__rest(_a, ["url", "logger"]);
|
|
8
11
|
this.listeners = [];
|
|
9
12
|
this.closed = false;
|
|
10
13
|
this.url = url;
|
|
11
|
-
this.logger =
|
|
12
|
-
this.options = __assign(__assign({}, options), { closeTimeout: (_b = options.closeTimeout
|
|
14
|
+
this.logger = logger !== null && logger !== void 0 ? logger : new logging_1.NullLogger();
|
|
15
|
+
this.options = tslib_1.__assign(tslib_1.__assign({}, options), { closeTimeout: (_b = options.closeTimeout) !== null && _b !== void 0 ? _b : 5000, connectionTimeout: (_c = options.connectionTimeout) !== null && _c !== void 0 ? _c : 10000, protocols: (_d = options.protocols) !== null && _d !== void 0 ? _d : [] });
|
|
13
16
|
}
|
|
14
17
|
Object.defineProperty(SocketChannel.prototype, "connected", {
|
|
15
18
|
get: function () {
|
|
@@ -18,7 +21,7 @@ var SocketChannel = /** @class */ (function () {
|
|
|
18
21
|
}
|
|
19
22
|
return this.connection.then(function () { return true; }, function () { return false; });
|
|
20
23
|
},
|
|
21
|
-
enumerable:
|
|
24
|
+
enumerable: false,
|
|
22
25
|
configurable: true
|
|
23
26
|
});
|
|
24
27
|
SocketChannel.prototype.publish = function (message) {
|
|
@@ -90,7 +93,7 @@ var SocketChannel = /** @class */ (function () {
|
|
|
90
93
|
};
|
|
91
94
|
var closeListener = function (event) {
|
|
92
95
|
window.clearTimeout(abortTimer);
|
|
93
|
-
var reason = formatCause(event.reason || 'unknown') + " (code " + event.code + ")";
|
|
96
|
+
var reason = error_1.formatCause(event.reason || 'unknown') + " (code " + event.code + ")";
|
|
94
97
|
var message = "Connection has been closed, reason: " + reason;
|
|
95
98
|
if (!_this.closed) {
|
|
96
99
|
_this.logger.info(message);
|
|
@@ -140,4 +143,4 @@ var SocketChannel = /** @class */ (function () {
|
|
|
140
143
|
};
|
|
141
144
|
return SocketChannel;
|
|
142
145
|
}());
|
|
143
|
-
|
|
146
|
+
exports.SocketChannel = SocketChannel;
|
package/cid/assigner.js
ADDED
package/cid/cachedAssigner.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Logger } from '../logging
|
|
2
|
-
import
|
|
3
|
-
import CidAssigner from './
|
|
4
|
-
export
|
|
1
|
+
import { Logger } from '../logging';
|
|
2
|
+
import { Cache } from '../cache';
|
|
3
|
+
import { CidAssigner } from './assigner';
|
|
4
|
+
export declare class CachedAssigner implements CidAssigner {
|
|
5
5
|
private readonly assigner;
|
|
6
6
|
private readonly cache;
|
|
7
7
|
private readonly logger;
|
|
8
|
-
constructor(assigner: CidAssigner, cache:
|
|
8
|
+
constructor(assigner: CidAssigner, cache: Cache, logger?: Logger);
|
|
9
9
|
assignCid(): Promise<string>;
|
|
10
10
|
}
|
package/cid/cachedAssigner.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CachedAssigner = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var logging_1 = require("../logging");
|
|
3
6
|
var CachedAssigner = /** @class */ (function () {
|
|
4
7
|
function CachedAssigner(assigner, cache, logger) {
|
|
5
8
|
this.assigner = assigner;
|
|
6
9
|
this.cache = cache;
|
|
7
|
-
this.logger =
|
|
10
|
+
this.logger = logger !== null && logger !== void 0 ? logger : new logging_1.NullLogger();
|
|
8
11
|
}
|
|
9
12
|
CachedAssigner.prototype.assignCid = function () {
|
|
10
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
13
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
11
14
|
var cid, newCid;
|
|
12
|
-
return __generator(this, function (_a) {
|
|
15
|
+
return tslib_1.__generator(this, function (_a) {
|
|
13
16
|
switch (_a.label) {
|
|
14
17
|
case 0:
|
|
15
18
|
cid = this.cache.get();
|
|
@@ -29,4 +32,4 @@ var CachedAssigner = /** @class */ (function () {
|
|
|
29
32
|
};
|
|
30
33
|
return CachedAssigner;
|
|
31
34
|
}());
|
|
32
|
-
|
|
35
|
+
exports.CachedAssigner = CachedAssigner;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FixedAssigner = void 0;
|
|
4
|
+
var FixedAssigner = /** @class */ (function () {
|
|
5
|
+
function FixedAssigner(cid) {
|
|
6
|
+
this.cid = cid;
|
|
7
|
+
}
|
|
8
|
+
FixedAssigner.prototype.assignCid = function () {
|
|
9
|
+
return Promise.resolve(this.cid);
|
|
10
|
+
};
|
|
11
|
+
return FixedAssigner;
|
|
12
|
+
}());
|
|
13
|
+
exports.FixedAssigner = FixedAssigner;
|
package/cid/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
}
|
|
1
|
+
export * from './assigner';
|
|
2
|
+
export { CachedAssigner } from './cachedAssigner';
|
|
3
|
+
export { FixedAssigner } from './fixedAssigner';
|
|
4
|
+
export { RemoteAssigner } from './remoteAssigner';
|
package/cid/index.js
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RemoteAssigner = exports.FixedAssigner = exports.CachedAssigner = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
tslib_1.__exportStar(require("./assigner"), exports);
|
|
6
|
+
var cachedAssigner_1 = require("./cachedAssigner");
|
|
7
|
+
Object.defineProperty(exports, "CachedAssigner", { enumerable: true, get: function () { return cachedAssigner_1.CachedAssigner; } });
|
|
8
|
+
var fixedAssigner_1 = require("./fixedAssigner");
|
|
9
|
+
Object.defineProperty(exports, "FixedAssigner", { enumerable: true, get: function () { return fixedAssigner_1.FixedAssigner; } });
|
|
10
|
+
var remoteAssigner_1 = require("./remoteAssigner");
|
|
11
|
+
Object.defineProperty(exports, "RemoteAssigner", { enumerable: true, get: function () { return remoteAssigner_1.RemoteAssigner; } });
|
package/cid/remoteAssigner.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Logger } from '../logging
|
|
2
|
-
import CidAssigner from './
|
|
3
|
-
export
|
|
1
|
+
import { Logger } from '../logging';
|
|
2
|
+
import { CidAssigner } from './assigner';
|
|
3
|
+
export declare class RemoteAssigner implements CidAssigner {
|
|
4
4
|
private readonly logger;
|
|
5
5
|
private readonly endpoint;
|
|
6
6
|
private pending?;
|
package/cid/remoteAssigner.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RemoteAssigner = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var logging_1 = require("../logging");
|
|
6
|
+
var error_1 = require("../error");
|
|
4
7
|
var RemoteAssigner = /** @class */ (function () {
|
|
5
8
|
function RemoteAssigner(endpoint, logger) {
|
|
6
9
|
this.endpoint = endpoint;
|
|
7
|
-
this.logger =
|
|
10
|
+
this.logger = logger !== null && logger !== void 0 ? logger : new logging_1.NullLogger();
|
|
8
11
|
}
|
|
9
12
|
RemoteAssigner.prototype.assignCid = function () {
|
|
10
13
|
var _this = this;
|
|
@@ -16,9 +19,9 @@ var RemoteAssigner = /** @class */ (function () {
|
|
|
16
19
|
return this.pending;
|
|
17
20
|
};
|
|
18
21
|
RemoteAssigner.prototype.fetchCid = function () {
|
|
19
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
22
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
20
23
|
var options, response, error;
|
|
21
|
-
return __generator(this, function (_a) {
|
|
24
|
+
return tslib_1.__generator(this, function (_a) {
|
|
22
25
|
switch (_a.label) {
|
|
23
26
|
case 0:
|
|
24
27
|
options = {
|
|
@@ -29,7 +32,7 @@ var RemoteAssigner = /** @class */ (function () {
|
|
|
29
32
|
case 1:
|
|
30
33
|
response = _a.sent();
|
|
31
34
|
if (!response.ok) {
|
|
32
|
-
error = new Error("Failed to assign CID: " + formatCause(response.statusText));
|
|
35
|
+
error = new Error("Failed to assign CID: " + error_1.formatCause(response.statusText));
|
|
33
36
|
this.logger.error(error.message);
|
|
34
37
|
throw error;
|
|
35
38
|
}
|
|
@@ -41,4 +44,4 @@ var RemoteAssigner = /** @class */ (function () {
|
|
|
41
44
|
};
|
|
42
45
|
return RemoteAssigner;
|
|
43
46
|
}());
|
|
44
|
-
|
|
47
|
+
exports.RemoteAssigner = RemoteAssigner;
|
package/constants.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VERSION = exports.MAX_EXPRESSION_LENGTH = exports.BOOTSTRAP_ENDPOINT_URL = exports.EVALUATION_ENDPOINT_URL = exports.TRACKER_ENDPOINT_URL = void 0;
|
|
4
|
+
exports.TRACKER_ENDPOINT_URL = 'wss://api.croct.io/client/web/connect';
|
|
5
|
+
exports.EVALUATION_ENDPOINT_URL = 'https://api.croct.io/client/web/evaluate';
|
|
6
|
+
exports.BOOTSTRAP_ENDPOINT_URL = 'https://api.croct.io/client/web/bootstrap';
|
|
7
|
+
exports.MAX_EXPRESSION_LENGTH = 300;
|
|
8
|
+
exports.VERSION = '0.7.0';
|
package/container.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Logger } from './logging';
|
|
2
|
-
import Context,
|
|
3
|
-
import MonitoredQueue from './queue
|
|
2
|
+
import { Context, TokenScope } from './context';
|
|
3
|
+
import { MonitoredQueue } from './queue';
|
|
4
4
|
import { TokenProvider } from './token';
|
|
5
|
-
import Tracker from './tracker';
|
|
6
|
-
import Evaluator from './evaluator';
|
|
7
|
-
import CidAssigner from './cid
|
|
5
|
+
import { Tracker } from './tracker';
|
|
6
|
+
import { Evaluator } from './evaluator';
|
|
7
|
+
import { CidAssigner } from './cid';
|
|
8
8
|
import { EventManager } from './eventManager';
|
|
9
9
|
import { SdkEventMap } from './sdkEvents';
|
|
10
10
|
import { UrlSanitizer } from './tab';
|
package/container.js
CHANGED
|
@@ -1,31 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
import NamespacedLogger from './logging/namespacedLogger';
|
|
19
|
-
import { encodeJson } from './transformer';
|
|
20
|
-
import CachedAssigner from './cid/cachedAssigner';
|
|
21
|
-
import RemoteAssigner from './cid/remoteAssigner';
|
|
22
|
-
import FixedCidAssigner from './cid/fixedCidAssigner';
|
|
23
|
-
import { SynchronousEventManager } from './eventManager';
|
|
24
|
-
import LocalStorageCache from './cache/localStorageCache';
|
|
25
|
-
import ArbitraryPolicy from './retry/arbitraryPolicy';
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Container = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var logging_1 = require("./logging");
|
|
6
|
+
var context_1 = require("./context");
|
|
7
|
+
var namespacedStorage_1 = require("./namespacedStorage");
|
|
8
|
+
var retry_1 = require("./retry");
|
|
9
|
+
var queue_1 = require("./queue");
|
|
10
|
+
var tracker_1 = require("./tracker");
|
|
11
|
+
var evaluator_1 = require("./evaluator");
|
|
12
|
+
var transformer_1 = require("./transformer");
|
|
13
|
+
var cid_1 = require("./cid");
|
|
14
|
+
var eventManager_1 = require("./eventManager");
|
|
15
|
+
var cache_1 = require("./cache");
|
|
16
|
+
var guaranteedChannel_1 = require("./channel/guaranteedChannel");
|
|
17
|
+
var channel_1 = require("./channel");
|
|
26
18
|
var Container = /** @class */ (function () {
|
|
27
19
|
function Container(configuration) {
|
|
28
|
-
this.eventManager = new SynchronousEventManager();
|
|
20
|
+
this.eventManager = new eventManager_1.SynchronousEventManager();
|
|
29
21
|
this.configuration = configuration;
|
|
30
22
|
}
|
|
31
23
|
Container.prototype.getConfiguration = function () {
|
|
@@ -38,7 +30,7 @@ var Container = /** @class */ (function () {
|
|
|
38
30
|
return this.evaluator;
|
|
39
31
|
};
|
|
40
32
|
Container.prototype.createEvaluator = function () {
|
|
41
|
-
return new Evaluator({
|
|
33
|
+
return new evaluator_1.Evaluator({
|
|
42
34
|
appId: this.configuration.appId,
|
|
43
35
|
endpointUrl: this.configuration.evaluationEndpointUrl,
|
|
44
36
|
tokenProvider: this.getTokenProvider(),
|
|
@@ -53,10 +45,10 @@ var Container = /** @class */ (function () {
|
|
|
53
45
|
};
|
|
54
46
|
Container.prototype.createTracker = function () {
|
|
55
47
|
var context = this.getContext();
|
|
56
|
-
var tracker = new Tracker({
|
|
48
|
+
var tracker = new tracker_1.Tracker({
|
|
57
49
|
tab: context.getTab(),
|
|
58
50
|
tokenProvider: this.getTokenProvider(),
|
|
59
|
-
inactivityRetryPolicy: new ArbitraryPolicy([30000, 30000, 120000, 120000, 300000, 300000, 900000]),
|
|
51
|
+
inactivityRetryPolicy: new retry_1.ArbitraryPolicy([30000, 30000, 120000, 120000, 300000, 300000, 900000]),
|
|
60
52
|
logger: this.getLogger('Tracker'),
|
|
61
53
|
channel: this.getBeaconChannel(),
|
|
62
54
|
eventMetadata: this.configuration.eventMetadata || {},
|
|
@@ -80,17 +72,19 @@ var Container = /** @class */ (function () {
|
|
|
80
72
|
return this.context;
|
|
81
73
|
};
|
|
82
74
|
Container.prototype.createContext = function () {
|
|
75
|
+
var tokenKey = this.resolveStorageNamespace('token');
|
|
76
|
+
var tabKey = this.resolveStorageNamespace('tab');
|
|
83
77
|
var browserStorage = this.getLocalStorage();
|
|
84
|
-
var browserCache = new LocalStorageCache(browserStorage,
|
|
78
|
+
var browserCache = new cache_1.LocalStorageCache(browserStorage, tokenKey);
|
|
85
79
|
var tabStorage = this.getSessionStorage();
|
|
86
|
-
this.removeTokenSyncListener = LocalStorageCache.autoSync(browserCache);
|
|
87
|
-
return Context.load({
|
|
80
|
+
this.removeTokenSyncListener = cache_1.LocalStorageCache.autoSync(browserCache);
|
|
81
|
+
return context_1.Context.load({
|
|
88
82
|
tokenScope: this.configuration.tokenScope,
|
|
89
83
|
eventDispatcher: this.getEventManager(),
|
|
90
84
|
urlSanitizer: this.configuration.urlSanitizer,
|
|
91
85
|
cache: {
|
|
92
|
-
tabId: new LocalStorageCache(tabStorage,
|
|
93
|
-
tabToken: new LocalStorageCache(tabStorage,
|
|
86
|
+
tabId: new cache_1.LocalStorageCache(tabStorage, tabKey),
|
|
87
|
+
tabToken: new cache_1.LocalStorageCache(tabStorage, tokenKey),
|
|
94
88
|
browserToken: browserCache,
|
|
95
89
|
},
|
|
96
90
|
});
|
|
@@ -104,33 +98,33 @@ var Container = /** @class */ (function () {
|
|
|
104
98
|
Container.prototype.createBeaconChannel = function () {
|
|
105
99
|
var channelLogger = this.getLogger('BeaconChannel');
|
|
106
100
|
var _a = this.configuration, appId = _a.appId, trackerEndpointUrl = _a.trackerEndpointUrl;
|
|
107
|
-
var queuedChannel = new QueuedChannel(new RetryChannel({
|
|
108
|
-
channel: new GuaranteedChannel({
|
|
109
|
-
channel: new BeaconSocketChannel({
|
|
101
|
+
var queuedChannel = new channel_1.QueuedChannel(new channel_1.RetryChannel({
|
|
102
|
+
channel: new channel_1.GuaranteedChannel({
|
|
103
|
+
channel: new channel_1.BeaconSocketChannel({
|
|
110
104
|
trackerEndpointUrl: trackerEndpointUrl + "/" + appId,
|
|
111
105
|
tokenParameter: 'token',
|
|
112
106
|
loggerFactory: this.getLogger.bind(this),
|
|
113
107
|
logger: channelLogger,
|
|
114
|
-
channelFactory: function (url, logger) { return new SocketChannel({ url: url, logger: logger }); },
|
|
108
|
+
channelFactory: function (url, logger) { return new channel_1.SocketChannel({ url: url, logger: logger }); },
|
|
115
109
|
cidAssigner: this.getCidAssigner(),
|
|
116
110
|
cidParameter: 'clientId',
|
|
117
111
|
}),
|
|
118
|
-
stamper: new TimeStamper(),
|
|
112
|
+
stamper: new guaranteedChannel_1.TimeStamper(),
|
|
119
113
|
ackTimeout: 10000,
|
|
120
114
|
logger: channelLogger,
|
|
121
115
|
}),
|
|
122
|
-
retryPolicy: new BackoffPolicy({
|
|
116
|
+
retryPolicy: new retry_1.BackoffPolicy({
|
|
123
117
|
minRetryDelay: 1000,
|
|
124
118
|
maxRetryDelay: 60 * 1000,
|
|
125
119
|
backoffFactor: 1.5,
|
|
126
|
-
backoffJitter: 1,
|
|
120
|
+
backoffJitter: 1, // add randomness
|
|
127
121
|
}),
|
|
128
122
|
logger: channelLogger,
|
|
129
123
|
}), this.getBeaconQueue(), channelLogger);
|
|
130
124
|
queuedChannel.flush().catch(function () {
|
|
131
125
|
// Suppress errors as they are already reported by the channel
|
|
132
126
|
});
|
|
133
|
-
return new EncodedChannel(queuedChannel, encodeJson);
|
|
127
|
+
return new channel_1.EncodedChannel(queuedChannel, transformer_1.encodeJson);
|
|
134
128
|
};
|
|
135
129
|
Container.prototype.getCidAssigner = function () {
|
|
136
130
|
if (this.cidAssigner === undefined) {
|
|
@@ -140,10 +134,10 @@ var Container = /** @class */ (function () {
|
|
|
140
134
|
};
|
|
141
135
|
Container.prototype.createCidAssigner = function () {
|
|
142
136
|
if (this.configuration.cid !== undefined) {
|
|
143
|
-
return new
|
|
137
|
+
return new cid_1.FixedAssigner(this.configuration.cid);
|
|
144
138
|
}
|
|
145
139
|
var logger = this.getLogger('CidAssigner');
|
|
146
|
-
return new CachedAssigner(new RemoteAssigner(this.configuration.bootstrapEndpointUrl, logger), new LocalStorageCache(this.getLocalStorage(), 'croct.cid'), logger);
|
|
140
|
+
return new cid_1.CachedAssigner(new cid_1.RemoteAssigner(this.configuration.bootstrapEndpointUrl, logger), new cache_1.LocalStorageCache(this.getLocalStorage(), 'croct.cid'), logger);
|
|
147
141
|
};
|
|
148
142
|
Container.prototype.getBeaconQueue = function () {
|
|
149
143
|
if (this.beaconQueue === undefined) {
|
|
@@ -154,7 +148,7 @@ var Container = /** @class */ (function () {
|
|
|
154
148
|
Container.prototype.createBeaconQueue = function () {
|
|
155
149
|
var context = this.getContext();
|
|
156
150
|
var tab = context.getTab();
|
|
157
|
-
return new MonitoredQueue(new CapacityRestrictedQueue(new PersistentQueue(this.getGlobalTabStorage('queue'), tab.id), this.configuration.beaconQueueSize), this.getLogger('BeaconQueue'));
|
|
151
|
+
return new queue_1.MonitoredQueue(new queue_1.CapacityRestrictedQueue(new queue_1.PersistentQueue(this.getGlobalTabStorage('queue'), tab.id), this.configuration.beaconQueueSize), this.getLogger('BeaconQueue'));
|
|
158
152
|
};
|
|
159
153
|
Container.prototype.getLogger = function () {
|
|
160
154
|
var namespace = [];
|
|
@@ -163,40 +157,40 @@ var Container = /** @class */ (function () {
|
|
|
163
157
|
}
|
|
164
158
|
var prefix = "Croct" + (namespace.length === 0 ? '' : ":" + namespace.join(':'));
|
|
165
159
|
if (this.configuration.logger !== undefined) {
|
|
166
|
-
return new NamespacedLogger(this.configuration.logger, prefix);
|
|
160
|
+
return new logging_1.NamespacedLogger(this.configuration.logger, prefix);
|
|
167
161
|
}
|
|
168
162
|
if (this.configuration.debug) {
|
|
169
|
-
return new ConsoleLogger(prefix);
|
|
163
|
+
return new logging_1.ConsoleLogger(prefix);
|
|
170
164
|
}
|
|
171
|
-
return new NullLogger();
|
|
165
|
+
return new logging_1.NullLogger();
|
|
172
166
|
};
|
|
173
167
|
Container.prototype.getTabStorage = function (namespace) {
|
|
174
168
|
var subnamespace = [];
|
|
175
169
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
176
170
|
subnamespace[_i - 1] = arguments[_i];
|
|
177
171
|
}
|
|
178
|
-
return this.getGlobalTabStorage.apply(this,
|
|
172
|
+
return this.getGlobalTabStorage.apply(this, tslib_1.__spreadArray(['external', namespace], tslib_1.__read(subnamespace)));
|
|
179
173
|
};
|
|
180
174
|
Container.prototype.getBrowserStorage = function (namespace) {
|
|
181
175
|
var subnamespace = [];
|
|
182
176
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
183
177
|
subnamespace[_i - 1] = arguments[_i];
|
|
184
178
|
}
|
|
185
|
-
return this.getGlobalBrowserStorage.apply(this,
|
|
179
|
+
return this.getGlobalBrowserStorage.apply(this, tslib_1.__spreadArray(['external', namespace], tslib_1.__read(subnamespace)));
|
|
186
180
|
};
|
|
187
181
|
Container.prototype.getGlobalTabStorage = function (namespace) {
|
|
188
182
|
var subnamespace = [];
|
|
189
183
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
190
184
|
subnamespace[_i - 1] = arguments[_i];
|
|
191
185
|
}
|
|
192
|
-
return new NamespacedStorage(this.getSessionStorage(), this.resolveStorageNamespace.apply(this,
|
|
186
|
+
return new namespacedStorage_1.NamespacedStorage(this.getSessionStorage(), this.resolveStorageNamespace.apply(this, tslib_1.__spreadArray([namespace], tslib_1.__read(subnamespace))));
|
|
193
187
|
};
|
|
194
188
|
Container.prototype.getGlobalBrowserStorage = function (namespace) {
|
|
195
189
|
var subnamespace = [];
|
|
196
190
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
197
191
|
subnamespace[_i - 1] = arguments[_i];
|
|
198
192
|
}
|
|
199
|
-
return new NamespacedStorage(this.getLocalStorage(), this.resolveStorageNamespace.apply(this,
|
|
193
|
+
return new namespacedStorage_1.NamespacedStorage(this.getLocalStorage(), this.resolveStorageNamespace.apply(this, tslib_1.__spreadArray([namespace], tslib_1.__read(subnamespace))));
|
|
200
194
|
};
|
|
201
195
|
Container.prototype.resolveStorageNamespace = function (namespace) {
|
|
202
196
|
var subnamespace = [];
|
|
@@ -215,9 +209,9 @@ var Container = /** @class */ (function () {
|
|
|
215
209
|
return this.eventManager;
|
|
216
210
|
};
|
|
217
211
|
Container.prototype.dispose = function () {
|
|
218
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
212
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
219
213
|
var logger;
|
|
220
|
-
return __generator(this, function (_a) {
|
|
214
|
+
return tslib_1.__generator(this, function (_a) {
|
|
221
215
|
switch (_a.label) {
|
|
222
216
|
case 0:
|
|
223
217
|
logger = this.getLogger();
|
|
@@ -261,4 +255,4 @@ var Container = /** @class */ (function () {
|
|
|
261
255
|
};
|
|
262
256
|
return Container;
|
|
263
257
|
}());
|
|
264
|
-
|
|
258
|
+
exports.Container = Container;
|
package/context.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import Token from './token';
|
|
2
|
-
import Tab,
|
|
1
|
+
import { Token } from './token';
|
|
2
|
+
import { Tab, UrlSanitizer } from './tab';
|
|
3
3
|
import { EventDispatcher } from './eventManager';
|
|
4
4
|
import { SdkEventMap } from './sdkEvents';
|
|
5
|
-
import LocalStorageCache from './cache
|
|
5
|
+
import { LocalStorageCache } from './cache';
|
|
6
6
|
export declare type TokenScope = 'isolated' | 'global' | 'contextual';
|
|
7
7
|
export declare type Configuration = {
|
|
8
8
|
tokenScope: TokenScope;
|
|
@@ -15,7 +15,7 @@ export declare type Configuration = {
|
|
|
15
15
|
};
|
|
16
16
|
};
|
|
17
17
|
declare type ContextEventDispatcher = EventDispatcher<Pick<SdkEventMap, 'tokenChanged'>>;
|
|
18
|
-
export
|
|
18
|
+
export declare class Context {
|
|
19
19
|
private readonly tab;
|
|
20
20
|
private readonly tokenStore;
|
|
21
21
|
private readonly eventDispatcher;
|
package/context.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Context = void 0;
|
|
4
|
+
var token_1 = require("./token");
|
|
5
|
+
var tab_1 = require("./tab");
|
|
6
|
+
var uuid_1 = require("./uuid");
|
|
6
7
|
function tokenEquals(left, right) {
|
|
7
8
|
return left === right || (left !== null && right !== null && left.toString() === right.toString());
|
|
8
9
|
}
|
|
@@ -19,23 +20,23 @@ var Context = /** @class */ (function () {
|
|
|
19
20
|
var tabId = cache.tabId.get();
|
|
20
21
|
var newTab = false;
|
|
21
22
|
if (tabId === null) {
|
|
22
|
-
tabId = uuid4(true);
|
|
23
|
+
tabId = uuid_1.uuid4(true);
|
|
23
24
|
newTab = true;
|
|
24
25
|
}
|
|
25
|
-
var tab = new Tab(tabId, newTab, urlSanitizer);
|
|
26
|
+
var tab = new tab_1.Tab(tabId, newTab, urlSanitizer);
|
|
26
27
|
cache.tabId.clear();
|
|
27
28
|
tab.addListener('unload', function () { return cache.tabId.put(tab.id); });
|
|
28
29
|
switch (tokenScope) {
|
|
29
30
|
case 'isolated':
|
|
30
|
-
return new Context(tab, new InMemoryTokenStore(), eventDispatcher);
|
|
31
|
+
return new Context(tab, new token_1.InMemoryTokenStore(), eventDispatcher);
|
|
31
32
|
case 'global': {
|
|
32
|
-
var context = new Context(tab, new CachedTokenStore(cache.browserToken), eventDispatcher);
|
|
33
|
+
var context = new Context(tab, new token_1.CachedTokenStore(cache.browserToken), eventDispatcher);
|
|
33
34
|
cache.browserToken.addListener(context.syncToken);
|
|
34
35
|
return context;
|
|
35
36
|
}
|
|
36
37
|
case 'contextual': {
|
|
37
|
-
var primaryStorage_1 = new CachedTokenStore(cache.tabToken);
|
|
38
|
-
var secondaryStorage_1 = new CachedTokenStore(cache.browserToken);
|
|
38
|
+
var primaryStorage_1 = new token_1.CachedTokenStore(cache.tabToken);
|
|
39
|
+
var secondaryStorage_1 = new token_1.CachedTokenStore(cache.browserToken);
|
|
39
40
|
if (tab.isNew) {
|
|
40
41
|
primaryStorage_1.setToken(secondaryStorage_1.getToken());
|
|
41
42
|
}
|
|
@@ -44,7 +45,7 @@ var Context = /** @class */ (function () {
|
|
|
44
45
|
secondaryStorage_1.setToken(primaryStorage_1.getToken());
|
|
45
46
|
}
|
|
46
47
|
});
|
|
47
|
-
return new Context(tab, new ReplicatedTokenStore(primaryStorage_1, secondaryStorage_1), eventDispatcher);
|
|
48
|
+
return new Context(tab, new token_1.ReplicatedTokenStore(primaryStorage_1, secondaryStorage_1), eventDispatcher);
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
51
|
};
|
|
@@ -86,4 +87,4 @@ var Context = /** @class */ (function () {
|
|
|
86
87
|
};
|
|
87
88
|
return Context;
|
|
88
89
|
}());
|
|
89
|
-
|
|
90
|
+
exports.Context = Context;
|
package/error.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare function formatMessage(error: unknown): string;
|
|
2
|
-
export declare function formatCause(error:
|
|
2
|
+
export declare function formatCause(error: unknown): string;
|
package/error.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatCause = exports.formatMessage = void 0;
|
|
1
4
|
function extractMessage(error) {
|
|
2
5
|
if (error instanceof Error) {
|
|
3
6
|
return error.message;
|
|
@@ -7,17 +10,19 @@ function extractMessage(error) {
|
|
|
7
10
|
}
|
|
8
11
|
return 'unknown error';
|
|
9
12
|
}
|
|
10
|
-
|
|
13
|
+
function formatMessage(error) {
|
|
11
14
|
var message = extractMessage(error);
|
|
12
15
|
if (message.length === 0) {
|
|
13
16
|
return message;
|
|
14
17
|
}
|
|
15
18
|
return message.charAt(0).toUpperCase() + message.slice(1);
|
|
16
19
|
}
|
|
17
|
-
|
|
20
|
+
exports.formatMessage = formatMessage;
|
|
21
|
+
function formatCause(error) {
|
|
18
22
|
var message = formatMessage(error);
|
|
19
23
|
if (message.length === 0) {
|
|
20
24
|
return message;
|
|
21
25
|
}
|
|
22
26
|
return message.charAt(0).toLowerCase() + message.slice(1);
|
|
23
27
|
}
|
|
28
|
+
exports.formatCause = formatCause;
|
package/evaluator.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { JsonObject, JsonValue } from './json';
|
|
2
2
|
import { TokenProvider } from './token';
|
|
3
3
|
import { Location } from './sourceLocation';
|
|
4
|
-
import CidAssigner from './cid';
|
|
4
|
+
import { CidAssigner } from './cid';
|
|
5
5
|
export declare type Configuration = {
|
|
6
6
|
appId: string;
|
|
7
7
|
endpointUrl?: string;
|
|
@@ -59,7 +59,7 @@ export declare type ExpressionErrorResponse = ErrorResponse & {
|
|
|
59
59
|
export declare class ExpressionError extends EvaluationError<ExpressionErrorResponse> {
|
|
60
60
|
constructor(response: ExpressionErrorResponse);
|
|
61
61
|
}
|
|
62
|
-
export
|
|
62
|
+
export declare class Evaluator {
|
|
63
63
|
static readonly MAX_EXPRESSION_LENGTH: number;
|
|
64
64
|
private readonly configuration;
|
|
65
65
|
constructor(configuration: Configuration);
|