@croct/sdk 0.7.0 → 0.8.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 -0
- package/activeRecord.js +9 -1
- package/cache/fallbackCache.js +1 -1
- package/cache/index.js +1 -1
- package/channel/beaconSocketChannel.js +5 -5
- package/channel/guaranteedChannel.js +6 -6
- package/channel/index.js +1 -1
- package/channel/queuedChannel.js +6 -6
- package/channel/retryChannel.js +5 -5
- package/channel/socketChannel.js +4 -4
- package/cid/cachedAssigner.js +2 -2
- package/cid/index.js +1 -1
- package/cid/remoteAssigner.js +3 -3
- package/constants.js +1 -1
- package/container.d.ts +1 -0
- package/container.js +15 -9
- package/context.js +1 -1
- package/evaluator.js +14 -14
- package/facade/evaluatorFacade.js +3 -3
- package/facade/sdkFacade.d.ts +1 -0
- package/facade/sdkFacade.js +8 -8
- package/facade/sessionPatch.js +1 -1
- package/facade/trackerFacade.js +5 -4
- package/facade/userPatch.js +1 -1
- package/logging/consoleLogger.js +1 -1
- package/logging/index.js +1 -1
- package/logging/namespacedLogger.js +1 -1
- package/namespacedStorage.js +2 -2
- package/package.json +12 -12
- package/patch.d.ts +5 -1
- package/queue/inMemoryQueue.js +1 -1
- package/queue/index.js +1 -1
- package/queue/monitoredQueue.js +1 -1
- package/retry/arbitraryPolicy.js +1 -1
- package/retry/index.js +1 -1
- package/schema/eventSchemas.d.ts +1 -0
- package/schema/eventSchemas.js +9 -1
- package/schema/index.js +10 -10
- package/schema/operationSchemas.d.ts +1 -0
- package/schema/operationSchemas.js +8 -1
- package/schema/sdkFacadeSchemas.js +1 -0
- package/schema/sdkSchemas.js +1 -0
- package/sdk.d.ts +1 -0
- package/sdk.js +16 -15
- package/sourceLocation.js +2 -2
- package/token/index.js +1 -1
- package/token/token.js +11 -11
- package/tracker.d.ts +1 -0
- package/tracker.js +30 -22
- package/trackingEvents.d.ts +9 -3
- package/trackingEvents.js +6 -5
- package/uuid.js +1 -1
- package/validation/arrayType.js +8 -8
- package/validation/booleanType.js +1 -1
- package/validation/functionType.js +1 -1
- package/validation/index.js +2 -2
- package/validation/jsonType.js +6 -6
- package/validation/nullType.js +1 -1
- package/validation/numberType.js +6 -6
- package/validation/objectType.js +16 -16
- package/validation/schema.js +1 -1
- package/validation/stringType.js +28 -16
- package/validation/unionType.js +7 -7
- package/validation/violation.js +1 -1
package/activeRecord.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export declare abstract class ActiveRecord<T extends TrackingEvent> {
|
|
|
13
13
|
decrement(property: string, amount?: number): this;
|
|
14
14
|
clear(property: string): this;
|
|
15
15
|
unset(property: string): this;
|
|
16
|
+
remove(property: string, value: JsonValue): this;
|
|
16
17
|
private pushOperation;
|
|
17
18
|
protected reset(): this;
|
|
18
19
|
abstract save(): Promise<T>;
|
package/activeRecord.js
CHANGED
|
@@ -12,6 +12,7 @@ var operationSchema = {
|
|
|
12
12
|
decrement: schema_1.decrementOperation,
|
|
13
13
|
clear: schema_1.clearOperation,
|
|
14
14
|
unset: schema_1.unsetOperation,
|
|
15
|
+
remove: schema_1.removeOperation,
|
|
15
16
|
};
|
|
16
17
|
var ActiveRecord = /** @class */ (function () {
|
|
17
18
|
function ActiveRecord() {
|
|
@@ -87,8 +88,15 @@ var ActiveRecord = /** @class */ (function () {
|
|
|
87
88
|
path: property,
|
|
88
89
|
});
|
|
89
90
|
};
|
|
91
|
+
ActiveRecord.prototype.remove = function (property, value) {
|
|
92
|
+
return this.pushOperation({
|
|
93
|
+
type: 'remove',
|
|
94
|
+
path: property,
|
|
95
|
+
value: value,
|
|
96
|
+
});
|
|
97
|
+
};
|
|
90
98
|
ActiveRecord.prototype.pushOperation = function (operation) {
|
|
91
|
-
var type = operation.type, data = tslib_1.__rest(operation, ["type"]);
|
|
99
|
+
var type = operation.type, data = (0, tslib_1.__rest)(operation, ["type"]);
|
|
92
100
|
operationSchema[type].validate(data);
|
|
93
101
|
this.operations.push(operation);
|
|
94
102
|
return this;
|
package/cache/fallbackCache.js
CHANGED
|
@@ -13,7 +13,7 @@ var FallbackCache = /** @class */ (function () {
|
|
|
13
13
|
FallbackCache.prototype.get = function () {
|
|
14
14
|
var e_1, _a;
|
|
15
15
|
try {
|
|
16
|
-
for (var _b = tslib_1.__values(this.caches), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
16
|
+
for (var _b = (0, tslib_1.__values)(this.caches), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
17
17
|
var cache = _c.value;
|
|
18
18
|
var value = cache.get();
|
|
19
19
|
if (value !== null) {
|
package/cache/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LocalStorageCache = exports.InMemoryCache = exports.FallbackCache = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
|
-
tslib_1.__exportStar(require("./cache"), exports);
|
|
5
|
+
(0, tslib_1.__exportStar)(require("./cache"), exports);
|
|
6
6
|
var fallbackCache_1 = require("./fallbackCache");
|
|
7
7
|
Object.defineProperty(exports, "FallbackCache", { enumerable: true, get: function () { return fallbackCache_1.FallbackCache; } });
|
|
8
8
|
var inMemoryCache_1 = require("./inMemoryCache");
|
|
@@ -19,9 +19,9 @@ var BeaconSocketChannel = /** @class */ (function () {
|
|
|
19
19
|
}
|
|
20
20
|
BeaconSocketChannel.prototype.publish = function (_a) {
|
|
21
21
|
var receiptId = _a.id, message = _a.message;
|
|
22
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
22
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
23
23
|
var _b, token, timestamp, context, payload, _c;
|
|
24
|
-
return tslib_1.__generator(this, function (_d) {
|
|
24
|
+
return (0, tslib_1.__generator)(this, function (_d) {
|
|
25
25
|
switch (_d.label) {
|
|
26
26
|
case 0:
|
|
27
27
|
_b = JSON.parse(message), token = _b.token, timestamp = _b.timestamp, context = _b.context, payload = _b.payload;
|
|
@@ -52,9 +52,9 @@ var BeaconSocketChannel = /** @class */ (function () {
|
|
|
52
52
|
});
|
|
53
53
|
};
|
|
54
54
|
BeaconSocketChannel.prototype.createSocketChannel = function (token) {
|
|
55
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
55
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
56
56
|
var endpoint, _a, _b, _c, channel;
|
|
57
|
-
return tslib_1.__generator(this, function (_d) {
|
|
57
|
+
return (0, tslib_1.__generator)(this, function (_d) {
|
|
58
58
|
switch (_d.label) {
|
|
59
59
|
case 0:
|
|
60
60
|
endpoint = new URL(this.trackerEndpointUrl);
|
|
@@ -66,7 +66,7 @@ var BeaconSocketChannel = /** @class */ (function () {
|
|
|
66
66
|
if (token !== undefined) {
|
|
67
67
|
endpoint.searchParams.append(this.tokenParameter, token);
|
|
68
68
|
}
|
|
69
|
-
channel = this.socketFactory(endpoint.toString(), this.loggerFactory("WebSocket#"
|
|
69
|
+
channel = this.socketFactory(endpoint.toString(), this.loggerFactory("WebSocket#".concat(this.connectionIndex)));
|
|
70
70
|
this.connectionIndex += 1;
|
|
71
71
|
channel.subscribe(this.notify);
|
|
72
72
|
return [2 /*return*/, channel];
|
|
@@ -15,12 +15,12 @@ exports.TimeStamper = TimeStamper;
|
|
|
15
15
|
var GuaranteedChannel = /** @class */ (function () {
|
|
16
16
|
function GuaranteedChannel(_a) {
|
|
17
17
|
var _b;
|
|
18
|
-
var channel = _a.channel, logger = _a.logger, stamper = _a.stamper, options = tslib_1.__rest(_a, ["channel", "logger", "stamper"]);
|
|
18
|
+
var channel = _a.channel, logger = _a.logger, stamper = _a.stamper, options = (0, tslib_1.__rest)(_a, ["channel", "logger", "stamper"]);
|
|
19
19
|
this.closed = false;
|
|
20
20
|
this.channel = channel;
|
|
21
21
|
this.logger = logger !== null && logger !== void 0 ? logger : new logging_1.NullLogger();
|
|
22
22
|
this.stamper = stamper;
|
|
23
|
-
this.options = tslib_1.__assign(tslib_1.__assign({}, options), { ackTimeout: (_b = options.ackTimeout) !== null && _b !== void 0 ? _b : 5000 });
|
|
23
|
+
this.options = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, options), { ackTimeout: (_b = options.ackTimeout) !== null && _b !== void 0 ? _b : 5000 });
|
|
24
24
|
}
|
|
25
25
|
GuaranteedChannel.prototype.publish = function (message) {
|
|
26
26
|
var _this = this;
|
|
@@ -39,7 +39,7 @@ var GuaranteedChannel = /** @class */ (function () {
|
|
|
39
39
|
var elapsed = Date.now() - start;
|
|
40
40
|
window.clearTimeout(timeoutTimer);
|
|
41
41
|
window.clearInterval(closeWatcher);
|
|
42
|
-
_this.logger.debug("Delivery confirmed #"
|
|
42
|
+
_this.logger.debug("Delivery confirmed #".concat(id, ", elapsed ").concat(elapsed, "ms."));
|
|
43
43
|
_this.channel.unsubscribe(acknowledge);
|
|
44
44
|
resolve();
|
|
45
45
|
}
|
|
@@ -48,7 +48,7 @@ var GuaranteedChannel = /** @class */ (function () {
|
|
|
48
48
|
var abort = function (error) {
|
|
49
49
|
window.clearTimeout(timeoutTimer);
|
|
50
50
|
window.clearInterval(closeWatcher);
|
|
51
|
-
_this.logger.error("Failed to send message #"
|
|
51
|
+
_this.logger.error("Failed to send message #".concat(id));
|
|
52
52
|
_this.channel.unsubscribe(acknowledge);
|
|
53
53
|
reject(error);
|
|
54
54
|
};
|
|
@@ -62,12 +62,12 @@ var GuaranteedChannel = /** @class */ (function () {
|
|
|
62
62
|
abort(new Error('Connection deliberately closed.'));
|
|
63
63
|
}
|
|
64
64
|
}, 0);
|
|
65
|
-
_this.logger.debug("Waiting confirmation #"
|
|
65
|
+
_this.logger.debug("Waiting confirmation #".concat(id, "..."));
|
|
66
66
|
timeoutTimer = window.setTimeout(function () {
|
|
67
67
|
abort(new Error('Maximum confirmation time reached.'));
|
|
68
68
|
}, _this.options.ackTimeout);
|
|
69
69
|
};
|
|
70
|
-
_this.logger.debug("Sending message #"
|
|
70
|
+
_this.logger.debug("Sending message #".concat(id, "..."));
|
|
71
71
|
_this.channel.publish({ id: id, message: message }).then(wait, abort);
|
|
72
72
|
});
|
|
73
73
|
};
|
package/channel/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SocketChannel = exports.SandboxChannel = exports.RetryChannel = exports.QueuedChannel = exports.GuaranteedChannel = exports.EncodedChannel = exports.BeaconSocketChannel = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
|
-
tslib_1.__exportStar(require("./channel"), exports);
|
|
5
|
+
(0, tslib_1.__exportStar)(require("./channel"), exports);
|
|
6
6
|
var beaconSocketChannel_1 = require("./beaconSocketChannel");
|
|
7
7
|
Object.defineProperty(exports, "BeaconSocketChannel", { enumerable: true, get: function () { return beaconSocketChannel_1.BeaconSocketChannel; } });
|
|
8
8
|
var encodedChannel_1 = require("./encodedChannel");
|
package/channel/queuedChannel.js
CHANGED
|
@@ -36,12 +36,12 @@ var QueuedChannel = /** @class */ (function () {
|
|
|
36
36
|
};
|
|
37
37
|
QueuedChannel.prototype.enqueue = function (message) {
|
|
38
38
|
this.logger.debug('Enqueueing message...');
|
|
39
|
-
this.logger.debug("Queue length: "
|
|
39
|
+
this.logger.debug("Queue length: ".concat(this.queue.length() + 1));
|
|
40
40
|
this.queue.push(message);
|
|
41
41
|
};
|
|
42
42
|
QueuedChannel.prototype.dequeue = function () {
|
|
43
43
|
this.logger.debug('Dequeuing message...');
|
|
44
|
-
this.logger.debug("Queue length: "
|
|
44
|
+
this.logger.debug("Queue length: ".concat(Math.max(0, this.queue.length() - 1)));
|
|
45
45
|
this.queue.shift();
|
|
46
46
|
};
|
|
47
47
|
QueuedChannel.prototype.requeue = function () {
|
|
@@ -56,13 +56,13 @@ var QueuedChannel = /** @class */ (function () {
|
|
|
56
56
|
}
|
|
57
57
|
var length = this.queue.length();
|
|
58
58
|
this.logger.debug('Requeuing messages...');
|
|
59
|
-
this.logger.debug("Queue length: "
|
|
59
|
+
this.logger.debug("Queue length: ".concat(length));
|
|
60
60
|
var _loop_1 = function (message) {
|
|
61
61
|
this_1.pending = this_1.pending.then(function () { return _this.channel.publish(message).then(_this.dequeue.bind(_this)); });
|
|
62
62
|
};
|
|
63
63
|
var this_1 = this;
|
|
64
64
|
try {
|
|
65
|
-
for (var _b = tslib_1.__values(this.queue.all()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
65
|
+
for (var _b = (0, tslib_1.__values)(this.queue.all()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
66
66
|
var message = _c.value;
|
|
67
67
|
_loop_1(message);
|
|
68
68
|
}
|
|
@@ -77,9 +77,9 @@ var QueuedChannel = /** @class */ (function () {
|
|
|
77
77
|
return this.pending;
|
|
78
78
|
};
|
|
79
79
|
QueuedChannel.prototype.close = function () {
|
|
80
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
80
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
81
81
|
var _a;
|
|
82
|
-
return tslib_1.__generator(this, function (_b) {
|
|
82
|
+
return (0, tslib_1.__generator)(this, function (_b) {
|
|
83
83
|
switch (_b.label) {
|
|
84
84
|
case 0:
|
|
85
85
|
this.closed = true;
|
package/channel/retryChannel.js
CHANGED
|
@@ -19,25 +19,25 @@ var RetryChannel = /** @class */ (function () {
|
|
|
19
19
|
return this.channel.publish(message).catch(function (error) { return _this.retry(message, error); });
|
|
20
20
|
};
|
|
21
21
|
RetryChannel.prototype.retry = function (message, error) {
|
|
22
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
22
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
23
23
|
var attempt, _loop_1, this_1, state_1;
|
|
24
24
|
var _this = this;
|
|
25
|
-
return tslib_1.__generator(this, function (_a) {
|
|
25
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
26
26
|
switch (_a.label) {
|
|
27
27
|
case 0:
|
|
28
28
|
attempt = 0;
|
|
29
29
|
_loop_1 = function () {
|
|
30
30
|
var delay, _b, _c;
|
|
31
|
-
return tslib_1.__generator(this, function (_d) {
|
|
31
|
+
return (0, tslib_1.__generator)(this, function (_d) {
|
|
32
32
|
switch (_d.label) {
|
|
33
33
|
case 0:
|
|
34
34
|
if (this_1.closed) {
|
|
35
35
|
throw new Error('Connection deliberately closed.');
|
|
36
36
|
}
|
|
37
37
|
delay = this_1.retryPolicy.getDelay(attempt);
|
|
38
|
-
this_1.logger.debug("Retry attempt "
|
|
38
|
+
this_1.logger.debug("Retry attempt ".concat(attempt + 1));
|
|
39
39
|
if (!(delay > 0)) return [3 /*break*/, 2];
|
|
40
|
-
this_1.logger.debug("Retry attempt delayed in "
|
|
40
|
+
this_1.logger.debug("Retry attempt delayed in ".concat(delay, "ms"));
|
|
41
41
|
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
42
42
|
var closeWatcher = window.setInterval(function () {
|
|
43
43
|
if (_this.closed) {
|
package/channel/socketChannel.js
CHANGED
|
@@ -7,12 +7,12 @@ var error_1 = require("../error");
|
|
|
7
7
|
var SocketChannel = /** @class */ (function () {
|
|
8
8
|
function SocketChannel(_a) {
|
|
9
9
|
var _b, _c, _d;
|
|
10
|
-
var url = _a.url, logger = _a.logger, options = tslib_1.__rest(_a, ["url", "logger"]);
|
|
10
|
+
var url = _a.url, logger = _a.logger, options = (0, tslib_1.__rest)(_a, ["url", "logger"]);
|
|
11
11
|
this.listeners = [];
|
|
12
12
|
this.closed = false;
|
|
13
13
|
this.url = url;
|
|
14
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 : [] });
|
|
15
|
+
this.options = (0, tslib_1.__assign)((0, 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 : [] });
|
|
16
16
|
}
|
|
17
17
|
Object.defineProperty(SocketChannel.prototype, "connected", {
|
|
18
18
|
get: function () {
|
|
@@ -93,8 +93,8 @@ var SocketChannel = /** @class */ (function () {
|
|
|
93
93
|
};
|
|
94
94
|
var closeListener = function (event) {
|
|
95
95
|
window.clearTimeout(abortTimer);
|
|
96
|
-
var reason = error_1.formatCause(event.reason || 'unknown')
|
|
97
|
-
var message = "Connection has been closed, reason: "
|
|
96
|
+
var reason = "".concat((0, error_1.formatCause)(event.reason || 'unknown'), " (code ").concat(event.code, ")");
|
|
97
|
+
var message = "Connection has been closed, reason: ".concat(reason);
|
|
98
98
|
if (!_this.closed) {
|
|
99
99
|
_this.logger.info(message);
|
|
100
100
|
}
|
package/cid/cachedAssigner.js
CHANGED
|
@@ -10,9 +10,9 @@ var CachedAssigner = /** @class */ (function () {
|
|
|
10
10
|
this.logger = logger !== null && logger !== void 0 ? logger : new logging_1.NullLogger();
|
|
11
11
|
}
|
|
12
12
|
CachedAssigner.prototype.assignCid = function () {
|
|
13
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
13
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
14
14
|
var cid, newCid;
|
|
15
|
-
return tslib_1.__generator(this, function (_a) {
|
|
15
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
16
16
|
switch (_a.label) {
|
|
17
17
|
case 0:
|
|
18
18
|
cid = this.cache.get();
|
package/cid/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RemoteAssigner = exports.FixedAssigner = exports.CachedAssigner = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
|
-
tslib_1.__exportStar(require("./assigner"), exports);
|
|
5
|
+
(0, tslib_1.__exportStar)(require("./assigner"), exports);
|
|
6
6
|
var cachedAssigner_1 = require("./cachedAssigner");
|
|
7
7
|
Object.defineProperty(exports, "CachedAssigner", { enumerable: true, get: function () { return cachedAssigner_1.CachedAssigner; } });
|
|
8
8
|
var fixedAssigner_1 = require("./fixedAssigner");
|
package/cid/remoteAssigner.js
CHANGED
|
@@ -19,9 +19,9 @@ var RemoteAssigner = /** @class */ (function () {
|
|
|
19
19
|
return this.pending;
|
|
20
20
|
};
|
|
21
21
|
RemoteAssigner.prototype.fetchCid = function () {
|
|
22
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
22
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
23
23
|
var options, response, error;
|
|
24
|
-
return tslib_1.__generator(this, function (_a) {
|
|
24
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
25
25
|
switch (_a.label) {
|
|
26
26
|
case 0:
|
|
27
27
|
options = {
|
|
@@ -32,7 +32,7 @@ var RemoteAssigner = /** @class */ (function () {
|
|
|
32
32
|
case 1:
|
|
33
33
|
response = _a.sent();
|
|
34
34
|
if (!response.ok) {
|
|
35
|
-
error = new Error("Failed to assign CID: "
|
|
35
|
+
error = new Error("Failed to assign CID: ".concat((0, error_1.formatCause)(response.statusText)));
|
|
36
36
|
this.logger.error(error.message);
|
|
37
37
|
throw error;
|
|
38
38
|
}
|
package/constants.js
CHANGED
|
@@ -5,4 +5,4 @@ exports.TRACKER_ENDPOINT_URL = 'wss://api.croct.io/client/web/connect';
|
|
|
5
5
|
exports.EVALUATION_ENDPOINT_URL = 'https://api.croct.io/client/web/evaluate';
|
|
6
6
|
exports.BOOTSTRAP_ENDPOINT_URL = 'https://api.croct.io/client/web/bootstrap';
|
|
7
7
|
exports.MAX_EXPRESSION_LENGTH = 300;
|
|
8
|
-
exports.VERSION = '0.
|
|
8
|
+
exports.VERSION = '0.8.0';
|
package/container.d.ts
CHANGED
package/container.js
CHANGED
|
@@ -96,12 +96,15 @@ var Container = /** @class */ (function () {
|
|
|
96
96
|
return this.beaconChannel;
|
|
97
97
|
};
|
|
98
98
|
Container.prototype.createBeaconChannel = function () {
|
|
99
|
+
if (this.configuration.test) {
|
|
100
|
+
return new channel_1.SandboxChannel();
|
|
101
|
+
}
|
|
99
102
|
var channelLogger = this.getLogger('BeaconChannel');
|
|
100
103
|
var _a = this.configuration, appId = _a.appId, trackerEndpointUrl = _a.trackerEndpointUrl;
|
|
101
104
|
var queuedChannel = new channel_1.QueuedChannel(new channel_1.RetryChannel({
|
|
102
105
|
channel: new channel_1.GuaranteedChannel({
|
|
103
106
|
channel: new channel_1.BeaconSocketChannel({
|
|
104
|
-
trackerEndpointUrl: trackerEndpointUrl
|
|
107
|
+
trackerEndpointUrl: "".concat(trackerEndpointUrl, "/").concat(appId),
|
|
105
108
|
tokenParameter: 'token',
|
|
106
109
|
loggerFactory: this.getLogger.bind(this),
|
|
107
110
|
logger: channelLogger,
|
|
@@ -136,6 +139,9 @@ var Container = /** @class */ (function () {
|
|
|
136
139
|
if (this.configuration.cid !== undefined) {
|
|
137
140
|
return new cid_1.FixedAssigner(this.configuration.cid);
|
|
138
141
|
}
|
|
142
|
+
if (this.configuration.test) {
|
|
143
|
+
return new cid_1.FixedAssigner('00000000-0000-0000-0000-000000000000');
|
|
144
|
+
}
|
|
139
145
|
var logger = this.getLogger('CidAssigner');
|
|
140
146
|
return new cid_1.CachedAssigner(new cid_1.RemoteAssigner(this.configuration.bootstrapEndpointUrl, logger), new cache_1.LocalStorageCache(this.getLocalStorage(), 'croct.cid'), logger);
|
|
141
147
|
};
|
|
@@ -155,7 +161,7 @@ var Container = /** @class */ (function () {
|
|
|
155
161
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
156
162
|
namespace[_i] = arguments[_i];
|
|
157
163
|
}
|
|
158
|
-
var prefix = "Croct"
|
|
164
|
+
var prefix = "Croct".concat(namespace.length === 0 ? '' : ":".concat(namespace.join(':')));
|
|
159
165
|
if (this.configuration.logger !== undefined) {
|
|
160
166
|
return new logging_1.NamespacedLogger(this.configuration.logger, prefix);
|
|
161
167
|
}
|
|
@@ -169,35 +175,35 @@ var Container = /** @class */ (function () {
|
|
|
169
175
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
170
176
|
subnamespace[_i - 1] = arguments[_i];
|
|
171
177
|
}
|
|
172
|
-
return this.getGlobalTabStorage.apply(this, tslib_1.__spreadArray(['external', namespace], tslib_1.__read(subnamespace)));
|
|
178
|
+
return this.getGlobalTabStorage.apply(this, (0, tslib_1.__spreadArray)(['external', namespace], (0, tslib_1.__read)(subnamespace), false));
|
|
173
179
|
};
|
|
174
180
|
Container.prototype.getBrowserStorage = function (namespace) {
|
|
175
181
|
var subnamespace = [];
|
|
176
182
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
177
183
|
subnamespace[_i - 1] = arguments[_i];
|
|
178
184
|
}
|
|
179
|
-
return this.getGlobalBrowserStorage.apply(this, tslib_1.__spreadArray(['external', namespace], tslib_1.__read(subnamespace)));
|
|
185
|
+
return this.getGlobalBrowserStorage.apply(this, (0, tslib_1.__spreadArray)(['external', namespace], (0, tslib_1.__read)(subnamespace), false));
|
|
180
186
|
};
|
|
181
187
|
Container.prototype.getGlobalTabStorage = function (namespace) {
|
|
182
188
|
var subnamespace = [];
|
|
183
189
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
184
190
|
subnamespace[_i - 1] = arguments[_i];
|
|
185
191
|
}
|
|
186
|
-
return new namespacedStorage_1.NamespacedStorage(this.getSessionStorage(), this.resolveStorageNamespace.apply(this, tslib_1.__spreadArray([namespace], tslib_1.__read(subnamespace))));
|
|
192
|
+
return new namespacedStorage_1.NamespacedStorage(this.getSessionStorage(), this.resolveStorageNamespace.apply(this, (0, tslib_1.__spreadArray)([namespace], (0, tslib_1.__read)(subnamespace), false)));
|
|
187
193
|
};
|
|
188
194
|
Container.prototype.getGlobalBrowserStorage = function (namespace) {
|
|
189
195
|
var subnamespace = [];
|
|
190
196
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
191
197
|
subnamespace[_i - 1] = arguments[_i];
|
|
192
198
|
}
|
|
193
|
-
return new namespacedStorage_1.NamespacedStorage(this.getLocalStorage(), this.resolveStorageNamespace.apply(this, tslib_1.__spreadArray([namespace], tslib_1.__read(subnamespace))));
|
|
199
|
+
return new namespacedStorage_1.NamespacedStorage(this.getLocalStorage(), this.resolveStorageNamespace.apply(this, (0, tslib_1.__spreadArray)([namespace], (0, tslib_1.__read)(subnamespace), false)));
|
|
194
200
|
};
|
|
195
201
|
Container.prototype.resolveStorageNamespace = function (namespace) {
|
|
196
202
|
var subnamespace = [];
|
|
197
203
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
198
204
|
subnamespace[_i - 1] = arguments[_i];
|
|
199
205
|
}
|
|
200
|
-
return "croct["
|
|
206
|
+
return "croct[".concat(this.configuration.appId.toLowerCase(), "].").concat([namespace].concat(subnamespace).join('.'));
|
|
201
207
|
};
|
|
202
208
|
Container.prototype.getLocalStorage = function () {
|
|
203
209
|
return localStorage;
|
|
@@ -209,9 +215,9 @@ var Container = /** @class */ (function () {
|
|
|
209
215
|
return this.eventManager;
|
|
210
216
|
};
|
|
211
217
|
Container.prototype.dispose = function () {
|
|
212
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
218
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
213
219
|
var logger;
|
|
214
|
-
return tslib_1.__generator(this, function (_a) {
|
|
220
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
215
221
|
switch (_a.label) {
|
|
216
222
|
case 0:
|
|
217
223
|
logger = this.getLogger();
|
package/context.js
CHANGED
|
@@ -20,7 +20,7 @@ var Context = /** @class */ (function () {
|
|
|
20
20
|
var tabId = cache.tabId.get();
|
|
21
21
|
var newTab = false;
|
|
22
22
|
if (tabId === null) {
|
|
23
|
-
tabId = uuid_1.uuid4(true);
|
|
23
|
+
tabId = (0, uuid_1.uuid4)(true);
|
|
24
24
|
newTab = true;
|
|
25
25
|
}
|
|
26
26
|
var tab = new tab_1.Tab(tabId, newTab, urlSanitizer);
|
package/evaluator.js
CHANGED
|
@@ -16,7 +16,7 @@ var EvaluationErrorType;
|
|
|
16
16
|
EvaluationErrorType["UNSERIALIZABLE_RESULT"] = "https://croct.help/api/evaluation#unserializable-result";
|
|
17
17
|
})(EvaluationErrorType = exports.EvaluationErrorType || (exports.EvaluationErrorType = {}));
|
|
18
18
|
var EvaluationError = /** @class */ (function (_super) {
|
|
19
|
-
tslib_1.__extends(EvaluationError, _super);
|
|
19
|
+
(0, tslib_1.__extends)(EvaluationError, _super);
|
|
20
20
|
function EvaluationError(response) {
|
|
21
21
|
var _this = _super.call(this, response.title) || this;
|
|
22
22
|
_this.response = response;
|
|
@@ -27,7 +27,7 @@ var EvaluationError = /** @class */ (function (_super) {
|
|
|
27
27
|
}(Error));
|
|
28
28
|
exports.EvaluationError = EvaluationError;
|
|
29
29
|
var ExpressionError = /** @class */ (function (_super) {
|
|
30
|
-
tslib_1.__extends(ExpressionError, _super);
|
|
30
|
+
(0, tslib_1.__extends)(ExpressionError, _super);
|
|
31
31
|
function ExpressionError(response) {
|
|
32
32
|
var _this = _super.call(this, response) || this;
|
|
33
33
|
Object.setPrototypeOf(_this, ExpressionError.prototype);
|
|
@@ -39,25 +39,25 @@ exports.ExpressionError = ExpressionError;
|
|
|
39
39
|
var Evaluator = /** @class */ (function () {
|
|
40
40
|
function Evaluator(configuration) {
|
|
41
41
|
var _a;
|
|
42
|
-
this.configuration = tslib_1.__assign(tslib_1.__assign({}, configuration), { endpointUrl: (_a = configuration.endpointUrl) !== null && _a !== void 0 ? _a : constants_1.EVALUATION_ENDPOINT_URL });
|
|
42
|
+
this.configuration = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, configuration), { endpointUrl: (_a = configuration.endpointUrl) !== null && _a !== void 0 ? _a : constants_1.EVALUATION_ENDPOINT_URL });
|
|
43
43
|
}
|
|
44
44
|
Evaluator.prototype.evaluate = function (expression, options) {
|
|
45
45
|
if (options === void 0) { options = {}; }
|
|
46
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
46
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
47
47
|
var length, response, endpoint;
|
|
48
48
|
var _this = this;
|
|
49
|
-
return tslib_1.__generator(this, function (_a) {
|
|
50
|
-
length = sourceLocation_1.getLength(expression);
|
|
49
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
50
|
+
length = (0, sourceLocation_1.getLength)(expression);
|
|
51
51
|
if (length > Evaluator.MAX_EXPRESSION_LENGTH) {
|
|
52
52
|
response = {
|
|
53
53
|
title: 'The expression is too complex.',
|
|
54
54
|
status: 422,
|
|
55
55
|
type: EvaluationErrorType.TOO_COMPLEX_EXPRESSION,
|
|
56
|
-
detail: "The expression must be at most "
|
|
57
|
-
+
|
|
56
|
+
detail: "The expression must be at most ".concat(Evaluator.MAX_EXPRESSION_LENGTH, " characters long, ")
|
|
57
|
+
+ "but it is ".concat(length, " characters long."),
|
|
58
58
|
errors: [{
|
|
59
59
|
cause: 'The expression is longer than expected.',
|
|
60
|
-
location: sourceLocation_1.getLocation(expression, 0, Math.max(length - 1, 0)),
|
|
60
|
+
location: (0, sourceLocation_1.getLocation)(expression, 0, Math.max(length - 1, 0)),
|
|
61
61
|
}],
|
|
62
62
|
};
|
|
63
63
|
return [2 /*return*/, Promise.reject(new ExpressionError(response))];
|
|
@@ -73,7 +73,7 @@ var Evaluator = /** @class */ (function () {
|
|
|
73
73
|
var response = {
|
|
74
74
|
title: 'Maximum evaluation timeout reached before evaluation could complete.',
|
|
75
75
|
type: EvaluationErrorType.TIMEOUT,
|
|
76
|
-
detail: "The evaluation took more than "
|
|
76
|
+
detail: "The evaluation took more than ".concat(options.timeout, "ms to complete."),
|
|
77
77
|
status: 408, // Request Timeout
|
|
78
78
|
};
|
|
79
79
|
reject(new EvaluationError(response));
|
|
@@ -100,7 +100,7 @@ var Evaluator = /** @class */ (function () {
|
|
|
100
100
|
});
|
|
101
101
|
}, function (error) {
|
|
102
102
|
var errorResponse = {
|
|
103
|
-
title: error_1.formatMessage(error),
|
|
103
|
+
title: (0, error_1.formatMessage)(error),
|
|
104
104
|
type: EvaluationErrorType.UNEXPECTED_ERROR,
|
|
105
105
|
detail: 'Please try again or contact Croct support if the error persists.',
|
|
106
106
|
status: 500, // Internal Server Error
|
|
@@ -112,9 +112,9 @@ var Evaluator = /** @class */ (function () {
|
|
|
112
112
|
});
|
|
113
113
|
};
|
|
114
114
|
Evaluator.prototype.fetch = function (endpoint) {
|
|
115
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
115
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
116
116
|
var _a, tokenProvider, cidAssigner, appId, token, cid, headers;
|
|
117
|
-
return tslib_1.__generator(this, function (_b) {
|
|
117
|
+
return (0, tslib_1.__generator)(this, function (_b) {
|
|
118
118
|
switch (_b.label) {
|
|
119
119
|
case 0:
|
|
120
120
|
_a = this.configuration, tokenProvider = _a.tokenProvider, cidAssigner = _a.cidAssigner, appId = _a.appId;
|
|
@@ -122,7 +122,7 @@ var Evaluator = /** @class */ (function () {
|
|
|
122
122
|
return [4 /*yield*/, cidAssigner.assignCid()];
|
|
123
123
|
case 1:
|
|
124
124
|
cid = _b.sent();
|
|
125
|
-
headers = tslib_1.__assign({ 'X-App-Id': appId, 'X-Client-Id': cid }, (token !== null && { 'X-Token': token.toString() }));
|
|
125
|
+
headers = (0, tslib_1.__assign)({ 'X-App-Id': appId, 'X-Client-Id': cid }, (token !== null && { 'X-Token': token.toString() }));
|
|
126
126
|
return [2 /*return*/, window.fetch(endpoint.toString(), {
|
|
127
127
|
method: 'GET',
|
|
128
128
|
headers: headers,
|
|
@@ -12,7 +12,7 @@ function validate(options) {
|
|
|
12
12
|
schema_1.optionsSchema.validate(options);
|
|
13
13
|
}
|
|
14
14
|
catch (violation) {
|
|
15
|
-
throw new Error("Invalid options: "
|
|
15
|
+
throw new Error("Invalid options: ".concat((0, error_1.formatCause)(violation)));
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
var EvaluatorFacade = /** @class */ (function () {
|
|
@@ -79,8 +79,8 @@ var TabContextFactory = /** @class */ (function () {
|
|
|
79
79
|
var e_1, _a;
|
|
80
80
|
var campaign = {};
|
|
81
81
|
try {
|
|
82
|
-
for (var _b = tslib_1.__values(url.searchParams.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
83
|
-
var _d = tslib_1.__read(_c.value, 2), parameter = _d[0], value = _d[1];
|
|
82
|
+
for (var _b = (0, tslib_1.__values)(url.searchParams.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
83
|
+
var _d = (0, tslib_1.__read)(_c.value, 2), parameter = _d[0], value = _d[1];
|
|
84
84
|
switch (parameter.toLowerCase()) {
|
|
85
85
|
case 'utm_campaign':
|
|
86
86
|
campaign.name = value;
|
package/facade/sdkFacade.d.ts
CHANGED
package/facade/sdkFacade.js
CHANGED
|
@@ -18,7 +18,7 @@ function validateConfiguration(configuration) {
|
|
|
18
18
|
schema_1.sdkFacadeConfigurationSchema.validate(configuration);
|
|
19
19
|
}
|
|
20
20
|
catch (violation) {
|
|
21
|
-
throw new Error("Invalid configuration: "
|
|
21
|
+
throw new Error("Invalid configuration: ".concat((0, error_1.formatCause)(violation)));
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
var SdkFacade = /** @class */ (function () {
|
|
@@ -26,13 +26,13 @@ var SdkFacade = /** @class */ (function () {
|
|
|
26
26
|
this.sdk = sdk;
|
|
27
27
|
}
|
|
28
28
|
SdkFacade.init = function (configuration) {
|
|
29
|
-
var _a, _b;
|
|
29
|
+
var _a, _b, _c;
|
|
30
30
|
validateConfiguration(configuration);
|
|
31
|
-
var
|
|
31
|
+
var _d = configuration.track, track = _d === void 0 ? true : _d, userId = configuration.userId, token = configuration.token, containerConfiguration = (0, tslib_1.__rest)(configuration, ["track", "userId", "token"]);
|
|
32
32
|
if (userId !== undefined && token !== undefined) {
|
|
33
33
|
throw new Error('Either the user ID or token can be specified, but not both.');
|
|
34
34
|
}
|
|
35
|
-
var sdk = new SdkFacade(sdk_1.Sdk.init(tslib_1.__assign(tslib_1.__assign({}, containerConfiguration), { tokenScope: (_a = containerConfiguration.tokenScope) !== null && _a !== void 0 ? _a : 'global', debug: (_b = containerConfiguration.debug) !== null && _b !== void 0 ? _b : false })));
|
|
35
|
+
var sdk = new SdkFacade(sdk_1.Sdk.init((0, tslib_1.__assign)((0, tslib_1.__assign)({}, containerConfiguration), { tokenScope: (_a = containerConfiguration.tokenScope) !== null && _a !== void 0 ? _a : 'global', debug: (_b = containerConfiguration.debug) !== null && _b !== void 0 ? _b : false, test: (_c = containerConfiguration.test) !== null && _c !== void 0 ? _c : false })));
|
|
36
36
|
if (userId !== undefined) {
|
|
37
37
|
sdk.identify(userId);
|
|
38
38
|
}
|
|
@@ -160,7 +160,7 @@ var SdkFacade = /** @class */ (function () {
|
|
|
160
160
|
type: 'userSignedIn',
|
|
161
161
|
userId: subject,
|
|
162
162
|
});
|
|
163
|
-
logger.info("User signed in as "
|
|
163
|
+
logger.info("User signed in as ".concat(subject));
|
|
164
164
|
}
|
|
165
165
|
logger.debug('New token saved, ');
|
|
166
166
|
};
|
|
@@ -192,7 +192,7 @@ var SdkFacade = /** @class */ (function () {
|
|
|
192
192
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
193
193
|
namespace[_i] = arguments[_i];
|
|
194
194
|
}
|
|
195
|
-
return (_a = this.sdk).getLogger.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(namespace)));
|
|
195
|
+
return (_a = this.sdk).getLogger.apply(_a, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(namespace), false));
|
|
196
196
|
};
|
|
197
197
|
SdkFacade.prototype.getTabStorage = function (namespace) {
|
|
198
198
|
var _a;
|
|
@@ -200,7 +200,7 @@ var SdkFacade = /** @class */ (function () {
|
|
|
200
200
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
201
201
|
subnamespace[_i - 1] = arguments[_i];
|
|
202
202
|
}
|
|
203
|
-
return (_a = this.sdk).getTabStorage.apply(_a, tslib_1.__spreadArray([namespace], tslib_1.__read(subnamespace)));
|
|
203
|
+
return (_a = this.sdk).getTabStorage.apply(_a, (0, tslib_1.__spreadArray)([namespace], (0, tslib_1.__read)(subnamespace), false));
|
|
204
204
|
};
|
|
205
205
|
SdkFacade.prototype.getBrowserStorage = function (namespace) {
|
|
206
206
|
var _a;
|
|
@@ -208,7 +208,7 @@ var SdkFacade = /** @class */ (function () {
|
|
|
208
208
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
209
209
|
subnamespace[_i - 1] = arguments[_i];
|
|
210
210
|
}
|
|
211
|
-
return (_a = this.sdk).getBrowserStorage.apply(_a, tslib_1.__spreadArray([namespace], tslib_1.__read(subnamespace)));
|
|
211
|
+
return (_a = this.sdk).getBrowserStorage.apply(_a, (0, tslib_1.__spreadArray)([namespace], (0, tslib_1.__read)(subnamespace), false));
|
|
212
212
|
};
|
|
213
213
|
SdkFacade.prototype.close = function () {
|
|
214
214
|
return this.sdk.close();
|
package/facade/sessionPatch.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.SessionPatch = void 0;
|
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var activeRecord_1 = require("../activeRecord");
|
|
6
6
|
var SessionPatch = /** @class */ (function (_super) {
|
|
7
|
-
tslib_1.__extends(SessionPatch, _super);
|
|
7
|
+
(0, tslib_1.__extends)(SessionPatch, _super);
|
|
8
8
|
function SessionPatch(tracker) {
|
|
9
9
|
var _this = _super.call(this) || this;
|
|
10
10
|
_this.tracker = tracker;
|