@croct/sdk 0.10.0 → 0.11.0-alpha.1
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/.src/activeRecord.ts +150 -0
- package/.src/base64Url.ts +18 -0
- package/.src/cache/cache.ts +15 -0
- package/.src/cache/fallbackCache.ts +29 -0
- package/.src/cache/inMemoryCache.ts +21 -0
- package/.src/cache/index.ts +4 -0
- package/.src/cache/localStorageCache.ts +85 -0
- package/.src/channel/beaconSocketChannel.ts +153 -0
- package/.src/channel/channel.ts +20 -0
- package/.src/channel/encodedChannel.ts +21 -0
- package/.src/channel/guaranteedChannel.ts +131 -0
- package/.src/channel/index.ts +8 -0
- package/.src/channel/queuedChannel.ts +112 -0
- package/.src/channel/retryChannel.ts +90 -0
- package/.src/channel/sandboxChannel.ts +43 -0
- package/.src/channel/socketChannel.ts +217 -0
- package/.src/cid/assigner.ts +3 -0
- package/.src/cid/cachedAssigner.ts +35 -0
- package/.src/cid/fixedAssigner.ts +13 -0
- package/.src/cid/index.ts +4 -0
- package/.src/cid/remoteAssigner.ts +47 -0
- package/.src/constants.ts +6 -0
- package/.src/container.ts +388 -0
- package/.src/contentFetcher.ts +226 -0
- package/.src/context.ts +137 -0
- package/.src/error.ts +31 -0
- package/.src/evaluator.ts +251 -0
- package/.src/eventManager.ts +53 -0
- package/.src/facade/contentFetcherFacade.ts +69 -0
- package/.src/facade/evaluatorFacade.ts +152 -0
- package/.src/facade/index.ts +7 -0
- package/.src/facade/sdkFacade.ts +291 -0
- package/.src/facade/sessionFacade.ts +14 -0
- package/.src/facade/sessionPatch.ts +32 -0
- package/.src/facade/trackerFacade.ts +98 -0
- package/.src/facade/userFacade.ts +26 -0
- package/.src/facade/userPatch.ts +32 -0
- package/.src/index.ts +4 -0
- package/.src/logging/consoleLogger.ts +37 -0
- package/.src/logging/index.ts +4 -0
- package/.src/logging/logger.ts +13 -0
- package/.src/logging/namespacedLogger.ts +32 -0
- package/.src/logging/nullLogger.ts +19 -0
- package/.src/namespacedStorage.ts +69 -0
- package/.src/patch.ts +64 -0
- package/.src/queue/capacityRestrictedQueue.ts +44 -0
- package/.src/queue/inMemoryQueue.ts +43 -0
- package/.src/queue/index.ts +5 -0
- package/.src/queue/monitoredQueue.ts +168 -0
- package/.src/queue/persistentQueue.ts +84 -0
- package/.src/queue/queue.ts +15 -0
- package/.src/retry/arbitraryPolicy.ts +21 -0
- package/.src/retry/backoffPolicy.ts +84 -0
- package/.src/retry/index.ts +5 -0
- package/.src/retry/maxAttemptsPolicy.ts +28 -0
- package/.src/retry/neverPolicy.ts +11 -0
- package/.src/retry/policy.ts +5 -0
- package/.src/schema/attributeSchema.ts +6 -0
- package/.src/schema/contentFetcherSchemas.ts +23 -0
- package/.src/schema/contentSchemas.ts +44 -0
- package/.src/schema/contextSchemas.ts +5 -0
- package/.src/schema/ecommerceSchemas.ts +179 -0
- package/.src/schema/evaluatorSchemas.ts +11 -0
- package/.src/schema/eventSchemas.ts +150 -0
- package/.src/schema/index.ts +11 -0
- package/.src/schema/loggerSchema.ts +12 -0
- package/.src/schema/operationSchemas.ts +102 -0
- package/.src/schema/sdkFacadeSchemas.ts +44 -0
- package/.src/schema/sdkSchemas.ts +49 -0
- package/.src/schema/tokenSchema.ts +42 -0
- package/.src/schema/userSchema.ts +184 -0
- package/.src/sdk.ts +174 -0
- package/.src/sdkEvents.ts +15 -0
- package/.src/sourceLocation.ts +85 -0
- package/.src/tab.ts +148 -0
- package/.src/token/cachedTokenStore.ts +34 -0
- package/.src/token/inMemoryTokenStore.ts +13 -0
- package/.src/token/index.ts +4 -0
- package/.src/token/replicatedTokenStore.ts +21 -0
- package/.src/token/token.ts +164 -0
- package/.src/tracker.ts +460 -0
- package/.src/trackingEvents.ts +456 -0
- package/.src/transformer.ts +7 -0
- package/.src/utilityTypes.ts +3 -0
- package/.src/uuid.ts +43 -0
- package/.src/validation/arrayType.ts +71 -0
- package/.src/validation/booleanType.ts +22 -0
- package/.src/validation/functionType.ts +22 -0
- package/.src/validation/index.ts +12 -0
- package/.src/validation/jsonType.ts +157 -0
- package/.src/validation/mixedSchema.ts +7 -0
- package/.src/validation/nullType.ts +22 -0
- package/.src/validation/numberType.ts +59 -0
- package/.src/validation/objectType.ts +138 -0
- package/.src/validation/schema.ts +21 -0
- package/.src/validation/stringType.ts +118 -0
- package/.src/validation/unionType.ts +53 -0
- package/.src/validation/violation.ts +23 -0
- package/activeRecord.js +33 -36
- package/base64Url.js +1 -0
- package/cache/cache.js +1 -0
- package/cache/fallbackCache.js +16 -32
- package/cache/inMemoryCache.js +10 -10
- package/cache/index.js +2 -1
- package/cache/localStorageCache.js +25 -25
- package/channel/beaconSocketChannel.d.ts +1 -1
- package/channel/beaconSocketChannel.js +50 -79
- package/channel/channel.d.ts +1 -1
- package/channel/channel.js +1 -0
- package/channel/encodedChannel.js +9 -10
- package/channel/guaranteedChannel.d.ts +4 -4
- package/channel/guaranteedChannel.js +42 -43
- package/channel/index.js +2 -1
- package/channel/queuedChannel.js +36 -64
- package/channel/retryChannel.d.ts +1 -1
- package/channel/retryChannel.js +45 -77
- package/channel/sandboxChannel.js +18 -18
- package/channel/socketChannel.d.ts +4 -4
- package/channel/socketChannel.js +78 -79
- package/cid/assigner.js +1 -0
- package/cid/cachedAssigner.js +16 -27
- package/cid/fixedAssigner.js +6 -6
- package/cid/index.js +2 -1
- package/cid/remoteAssigner.js +24 -36
- package/constants.d.ts +6 -5
- package/constants.js +7 -5
- package/container.d.ts +13 -6
- package/container.js +153 -168
- package/contentFetcher.d.ts +59 -0
- package/contentFetcher.js +130 -0
- package/context.d.ts +3 -3
- package/context.js +37 -38
- package/error.js +3 -2
- package/evaluator.d.ts +33 -24
- package/evaluator.js +127 -117
- package/eventManager.d.ts +1 -1
- package/eventManager.js +15 -15
- package/facade/contentFetcherFacade.d.ts +27 -0
- package/facade/contentFetcherFacade.js +41 -0
- package/facade/evaluatorFacade.d.ts +13 -3
- package/facade/evaluatorFacade.js +58 -72
- package/facade/index.js +1 -0
- package/facade/sdkFacade.d.ts +10 -3
- package/facade/sdkFacade.js +130 -141
- package/facade/sessionFacade.js +7 -7
- package/facade/sessionPatch.js +10 -13
- package/facade/trackerFacade.js +33 -38
- package/facade/userFacade.js +11 -11
- package/facade/userPatch.js +10 -13
- package/index.js +3 -2
- package/logging/consoleLogger.js +19 -35
- package/logging/index.js +2 -1
- package/logging/logger.js +1 -0
- package/logging/namespacedLogger.js +15 -15
- package/logging/nullLogger.js +11 -13
- package/namespacedStorage.js +31 -47
- package/package.json +13 -16
- package/patch.d.ts +1 -1
- package/patch.js +1 -0
- package/queue/capacityRestrictedQueue.js +18 -18
- package/queue/inMemoryQueue.js +23 -28
- package/queue/index.js +2 -1
- package/queue/monitoredQueue.d.ts +2 -2
- package/queue/monitoredQueue.js +40 -40
- package/queue/persistentQueue.js +34 -38
- package/queue/queue.js +1 -0
- package/retry/arbitraryPolicy.js +9 -10
- package/retry/backoffPolicy.d.ts +1 -1
- package/retry/backoffPolicy.js +12 -13
- package/retry/index.js +2 -1
- package/retry/maxAttemptsPolicy.js +8 -8
- package/retry/neverPolicy.js +7 -9
- package/retry/policy.js +1 -0
- package/schema/attributeSchema.js +2 -1
- package/schema/contentFetcherSchemas.d.ts +2 -0
- package/schema/contentFetcherSchemas.js +23 -0
- package/schema/contentSchemas.js +2 -1
- package/schema/contextSchemas.js +2 -1
- package/schema/ecommerceSchemas.js +2 -1
- package/schema/evaluatorSchemas.d.ts +2 -0
- package/schema/{evaluationSchemas.js → evaluatorSchemas.js} +4 -3
- package/schema/eventSchemas.js +6 -7
- package/schema/index.d.ts +2 -1
- package/schema/index.js +4 -2
- package/schema/loggerSchema.js +2 -1
- package/schema/operationSchemas.js +9 -8
- package/schema/sdkFacadeSchemas.js +10 -6
- package/schema/sdkSchemas.js +9 -5
- package/schema/tokenSchema.js +6 -4
- package/schema/userSchema.js +3 -2
- package/sdk.d.ts +9 -3
- package/sdk.js +82 -127
- package/sdkEvents.d.ts +3 -3
- package/sdkEvents.js +1 -0
- package/sourceLocation.d.ts +3 -3
- package/sourceLocation.js +14 -14
- package/tab.d.ts +5 -5
- package/tab.js +51 -80
- package/token/cachedTokenStore.js +10 -10
- package/token/inMemoryTokenStore.js +8 -8
- package/token/index.js +2 -1
- package/token/replicatedTokenStore.js +8 -8
- package/token/token.d.ts +9 -5
- package/token/token.js +64 -57
- package/tracker.d.ts +4 -4
- package/tracker.js +146 -122
- package/trackingEvents.d.ts +36 -36
- package/trackingEvents.js +13 -6
- package/transformer.js +2 -1
- package/utilityTypes.d.ts +2 -2
- package/utilityTypes.js +1 -0
- package/uuid.js +10 -7
- package/validation/arrayType.d.ts +2 -2
- package/validation/arrayType.js +30 -27
- package/validation/booleanType.js +12 -15
- package/validation/functionType.js +12 -15
- package/validation/index.js +2 -1
- package/validation/jsonType.d.ts +2 -2
- package/validation/jsonType.js +62 -80
- package/validation/mixedSchema.js +5 -7
- package/validation/nullType.js +12 -15
- package/validation/numberType.d.ts +1 -1
- package/validation/numberType.js +24 -22
- package/validation/objectType.d.ts +1 -1
- package/validation/objectType.js +62 -72
- package/validation/schema.js +7 -10
- package/validation/stringType.d.ts +1 -1
- package/validation/stringType.js +37 -47
- package/validation/unionType.js +28 -77
- package/validation/violation.js +2 -2
- package/schema/evaluationSchemas.d.ts +0 -2
|
@@ -1,80 +1,79 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GuaranteedChannel = exports.TimeStamper = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function TimeStamper() {
|
|
8
|
-
}
|
|
9
|
-
TimeStamper.prototype.generate = function () {
|
|
4
|
+
const logging_1 = require("../logging");
|
|
5
|
+
class TimeStamper {
|
|
6
|
+
generate() {
|
|
10
7
|
return String(Date.now());
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
}());
|
|
8
|
+
}
|
|
9
|
+
}
|
|
14
10
|
exports.TimeStamper = TimeStamper;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var
|
|
18
|
-
var channel = _a.channel, logger = _a.logger, stamper = _a.stamper, options = tslib_1.__rest(_a, ["channel", "logger", "stamper"]);
|
|
11
|
+
class GuaranteedChannel {
|
|
12
|
+
constructor({ channel, logger, stamper, ...options }) {
|
|
13
|
+
var _a;
|
|
19
14
|
this.closed = false;
|
|
20
15
|
this.channel = channel;
|
|
21
16
|
this.logger = logger !== null && logger !== void 0 ? logger : new logging_1.NullLogger();
|
|
22
17
|
this.stamper = stamper;
|
|
23
|
-
this.options =
|
|
18
|
+
this.options = {
|
|
19
|
+
...options,
|
|
20
|
+
ackTimeout: (_a = options.ackTimeout) !== null && _a !== void 0 ? _a : 5000,
|
|
21
|
+
};
|
|
24
22
|
}
|
|
25
|
-
|
|
26
|
-
var _this = this;
|
|
23
|
+
publish(message) {
|
|
27
24
|
if (this.closed) {
|
|
28
25
|
return Promise.reject(new Error('Channel is closed.'));
|
|
29
26
|
}
|
|
30
|
-
return new Promise(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
const id = this.stamper.generate(message);
|
|
29
|
+
let timeoutTimer;
|
|
30
|
+
let closeWatcher;
|
|
31
|
+
let confirmed = false;
|
|
32
|
+
const start = Date.now();
|
|
33
|
+
const acknowledge = (response) => {
|
|
37
34
|
if (response === id) {
|
|
38
35
|
confirmed = true;
|
|
39
|
-
|
|
36
|
+
const elapsed = Date.now() - start;
|
|
40
37
|
window.clearTimeout(timeoutTimer);
|
|
41
38
|
window.clearInterval(closeWatcher);
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
this.logger.debug(`Delivery confirmed #${id}, elapsed ${elapsed}ms.`);
|
|
40
|
+
this.channel.unsubscribe(acknowledge);
|
|
44
41
|
resolve();
|
|
45
42
|
}
|
|
46
43
|
};
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
this.channel.subscribe(acknowledge);
|
|
45
|
+
const abort = (error) => {
|
|
49
46
|
window.clearTimeout(timeoutTimer);
|
|
50
47
|
window.clearInterval(closeWatcher);
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
this.logger.error(`Failed to send message #${id}`);
|
|
49
|
+
this.channel.unsubscribe(acknowledge);
|
|
53
50
|
reject(error);
|
|
54
51
|
};
|
|
55
|
-
|
|
52
|
+
const wait = () => {
|
|
56
53
|
if (confirmed) {
|
|
57
54
|
return;
|
|
58
55
|
}
|
|
59
|
-
closeWatcher = window.setInterval(
|
|
60
|
-
if (
|
|
56
|
+
closeWatcher = window.setInterval(() => {
|
|
57
|
+
if (this.closed) {
|
|
61
58
|
// Cancel delay immediately when the channel is closed
|
|
62
59
|
abort(new Error('Connection deliberately closed.'));
|
|
63
60
|
}
|
|
64
61
|
}, 0);
|
|
65
|
-
|
|
66
|
-
timeoutTimer = window.setTimeout(
|
|
62
|
+
this.logger.debug(`Waiting confirmation #${id}...`);
|
|
63
|
+
timeoutTimer = window.setTimeout(() => {
|
|
67
64
|
abort(new Error('Maximum confirmation time reached.'));
|
|
68
|
-
},
|
|
65
|
+
}, this.options.ackTimeout);
|
|
69
66
|
};
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
this.logger.debug(`Sending message #${id}...`);
|
|
68
|
+
this.channel
|
|
69
|
+
.publish({ id: id, message: message })
|
|
70
|
+
.then(wait, abort);
|
|
72
71
|
});
|
|
73
|
-
}
|
|
74
|
-
|
|
72
|
+
}
|
|
73
|
+
close() {
|
|
75
74
|
this.closed = true;
|
|
76
75
|
return this.channel.close();
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
}());
|
|
76
|
+
}
|
|
77
|
+
}
|
|
80
78
|
exports.GuaranteedChannel = GuaranteedChannel;
|
|
79
|
+
//# sourceMappingURL=guaranteedChannel.js.map
|
package/channel/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
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
|
+
const tslib_1 = require("tslib");
|
|
5
5
|
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; } });
|
|
@@ -17,3 +17,4 @@ var sandboxChannel_1 = require("./sandboxChannel");
|
|
|
17
17
|
Object.defineProperty(exports, "SandboxChannel", { enumerable: true, get: function () { return sandboxChannel_1.SandboxChannel; } });
|
|
18
18
|
var socketChannel_1 = require("./socketChannel");
|
|
19
19
|
Object.defineProperty(exports, "SocketChannel", { enumerable: true, get: function () { return socketChannel_1.SocketChannel; } });
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
package/channel/queuedChannel.js
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.QueuedChannel = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function QueuedChannel(channel, queue, logger) {
|
|
4
|
+
const logging_1 = require("../logging");
|
|
5
|
+
class QueuedChannel {
|
|
6
|
+
constructor(channel, queue, logger) {
|
|
8
7
|
this.closed = false;
|
|
9
8
|
this.channel = channel;
|
|
10
9
|
this.queue = queue;
|
|
11
10
|
this.logger = logger !== null && logger !== void 0 ? logger : new logging_1.NullLogger();
|
|
12
11
|
}
|
|
13
|
-
|
|
12
|
+
flush() {
|
|
14
13
|
if (this.pending === undefined) {
|
|
15
14
|
return this.requeue();
|
|
16
15
|
}
|
|
17
16
|
return this.pending.catch(this.requeue.bind(this));
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
var _this = this;
|
|
17
|
+
}
|
|
18
|
+
publish(message) {
|
|
21
19
|
if (this.closed) {
|
|
22
20
|
return Promise.reject(new Error('Channel is closed.'));
|
|
23
21
|
}
|
|
@@ -31,22 +29,22 @@ var QueuedChannel = /** @class */ (function () {
|
|
|
31
29
|
: Promise.reject(new Error('The queue must be flushed.'));
|
|
32
30
|
}
|
|
33
31
|
this.enqueue(message);
|
|
34
|
-
this.pending = this.pending.then(
|
|
32
|
+
this.pending = this.pending.then(() => this.channel
|
|
33
|
+
.publish(message)
|
|
34
|
+
.then(this.dequeue.bind(this)));
|
|
35
35
|
return this.pending;
|
|
36
|
-
}
|
|
37
|
-
|
|
36
|
+
}
|
|
37
|
+
enqueue(message) {
|
|
38
38
|
this.logger.debug('Enqueueing message...');
|
|
39
|
-
this.logger.debug(
|
|
39
|
+
this.logger.debug(`Queue length: ${this.queue.length() + 1}`);
|
|
40
40
|
this.queue.push(message);
|
|
41
|
-
}
|
|
42
|
-
|
|
41
|
+
}
|
|
42
|
+
dequeue() {
|
|
43
43
|
this.logger.debug('Dequeuing message...');
|
|
44
|
-
this.logger.debug(
|
|
44
|
+
this.logger.debug(`Queue length: ${Math.max(0, this.queue.length() - 1)}`);
|
|
45
45
|
this.queue.shift();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
var e_1, _a;
|
|
49
|
-
var _this = this;
|
|
46
|
+
}
|
|
47
|
+
requeue() {
|
|
50
48
|
if (this.closed) {
|
|
51
49
|
return Promise.reject(new Error('Channel is closed.'));
|
|
52
50
|
}
|
|
@@ -54,54 +52,28 @@ var QueuedChannel = /** @class */ (function () {
|
|
|
54
52
|
if (this.queue.isEmpty()) {
|
|
55
53
|
return this.pending;
|
|
56
54
|
}
|
|
57
|
-
|
|
55
|
+
const length = this.queue.length();
|
|
58
56
|
this.logger.debug('Requeuing messages...');
|
|
59
|
-
this.logger.debug(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
try {
|
|
65
|
-
for (var _b = tslib_1.__values(this.queue.all()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
66
|
-
var message = _c.value;
|
|
67
|
-
_loop_1(message);
|
|
68
|
-
}
|
|
57
|
+
this.logger.debug(`Queue length: ${length}`);
|
|
58
|
+
for (const message of this.queue.all()) {
|
|
59
|
+
this.pending = this.pending.then(() => this.channel
|
|
60
|
+
.publish(message)
|
|
61
|
+
.then(this.dequeue.bind(this)));
|
|
69
62
|
}
|
|
70
|
-
|
|
71
|
-
|
|
63
|
+
return this.pending;
|
|
64
|
+
}
|
|
65
|
+
async close() {
|
|
66
|
+
this.closed = true;
|
|
67
|
+
await this.channel.close();
|
|
68
|
+
if (this.pending !== undefined) {
|
|
72
69
|
try {
|
|
73
|
-
|
|
70
|
+
await this.pending;
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
// suppress errors
|
|
74
74
|
}
|
|
75
|
-
finally { if (e_1) throw e_1.error; }
|
|
76
75
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
QueuedChannel.prototype.close = function () {
|
|
80
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
81
|
-
var _a;
|
|
82
|
-
return tslib_1.__generator(this, function (_b) {
|
|
83
|
-
switch (_b.label) {
|
|
84
|
-
case 0:
|
|
85
|
-
this.closed = true;
|
|
86
|
-
return [4 /*yield*/, this.channel.close()];
|
|
87
|
-
case 1:
|
|
88
|
-
_b.sent();
|
|
89
|
-
if (!(this.pending !== undefined)) return [3 /*break*/, 5];
|
|
90
|
-
_b.label = 2;
|
|
91
|
-
case 2:
|
|
92
|
-
_b.trys.push([2, 4, , 5]);
|
|
93
|
-
return [4 /*yield*/, this.pending];
|
|
94
|
-
case 3:
|
|
95
|
-
_b.sent();
|
|
96
|
-
return [3 /*break*/, 5];
|
|
97
|
-
case 4:
|
|
98
|
-
_a = _b.sent();
|
|
99
|
-
return [3 /*break*/, 5];
|
|
100
|
-
case 5: return [2 /*return*/];
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
};
|
|
105
|
-
return QueuedChannel;
|
|
106
|
-
}());
|
|
76
|
+
}
|
|
77
|
+
}
|
|
107
78
|
exports.QueuedChannel = QueuedChannel;
|
|
79
|
+
//# sourceMappingURL=queuedChannel.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { OutputChannel } from './channel';
|
|
2
2
|
import { Logger } from '../logging';
|
|
3
3
|
import { RetryPolicy } from '../retry';
|
|
4
|
-
|
|
4
|
+
type Configuration<T> = {
|
|
5
5
|
channel: OutputChannel<T>;
|
|
6
6
|
retryPolicy: RetryPolicy<T>;
|
|
7
7
|
logger?: Logger;
|
package/channel/retryChannel.js
CHANGED
|
@@ -1,91 +1,59 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RetryChannel = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function RetryChannel(_a) {
|
|
8
|
-
var channel = _a.channel, retryPolicy = _a.retryPolicy, logger = _a.logger;
|
|
4
|
+
const logging_1 = require("../logging");
|
|
5
|
+
class RetryChannel {
|
|
6
|
+
constructor({ channel, retryPolicy, logger }) {
|
|
9
7
|
this.closed = false;
|
|
10
8
|
this.channel = channel;
|
|
11
9
|
this.retryPolicy = retryPolicy;
|
|
12
10
|
this.logger = logger !== null && logger !== void 0 ? logger : new logging_1.NullLogger();
|
|
13
11
|
}
|
|
14
|
-
|
|
15
|
-
var _this = this;
|
|
12
|
+
publish(message) {
|
|
16
13
|
if (this.closed) {
|
|
17
14
|
return Promise.reject(new Error('The channel is closed.'));
|
|
18
15
|
}
|
|
19
|
-
return this.channel
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
case 2:
|
|
58
|
-
_d.trys.push([2, 4, , 5]);
|
|
59
|
-
_b = {};
|
|
60
|
-
return [4 /*yield*/, this_1.channel.publish(message)];
|
|
61
|
-
case 3: return [2 /*return*/, (_b.value = _d.sent(), _b)];
|
|
62
|
-
case 4:
|
|
63
|
-
_c = _d.sent();
|
|
64
|
-
attempt += 1;
|
|
65
|
-
return [3 /*break*/, 5];
|
|
66
|
-
case 5: return [2 /*return*/];
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
};
|
|
70
|
-
this_1 = this;
|
|
71
|
-
_a.label = 1;
|
|
72
|
-
case 1:
|
|
73
|
-
if (!this.retryPolicy.shouldRetry(attempt, message, error)) return [3 /*break*/, 3];
|
|
74
|
-
return [5 /*yield**/, _loop_1()];
|
|
75
|
-
case 2:
|
|
76
|
-
state_1 = _a.sent();
|
|
77
|
-
if (typeof state_1 === "object")
|
|
78
|
-
return [2 /*return*/, state_1.value];
|
|
79
|
-
return [3 /*break*/, 1];
|
|
80
|
-
case 3: throw new Error('Maximum retry attempts reached.');
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
};
|
|
85
|
-
RetryChannel.prototype.close = function () {
|
|
16
|
+
return this.channel
|
|
17
|
+
.publish(message)
|
|
18
|
+
.catch(error => this.retry(message, error));
|
|
19
|
+
}
|
|
20
|
+
async retry(message, error) {
|
|
21
|
+
let attempt = 0;
|
|
22
|
+
while (this.retryPolicy.shouldRetry(attempt, message, error)) {
|
|
23
|
+
if (this.closed) {
|
|
24
|
+
throw new Error('Connection deliberately closed.');
|
|
25
|
+
}
|
|
26
|
+
const delay = this.retryPolicy.getDelay(attempt);
|
|
27
|
+
this.logger.debug(`Retry attempt ${attempt + 1}`);
|
|
28
|
+
if (delay > 0) {
|
|
29
|
+
this.logger.debug(`Retry attempt delayed in ${delay}ms`);
|
|
30
|
+
await new Promise((resolve, reject) => {
|
|
31
|
+
const closeWatcher = window.setInterval(() => {
|
|
32
|
+
if (this.closed) {
|
|
33
|
+
// Cancel delay immediately when the channel is closed
|
|
34
|
+
window.clearInterval(closeWatcher);
|
|
35
|
+
reject(new Error('Connection deliberately closed.'));
|
|
36
|
+
}
|
|
37
|
+
}, 0);
|
|
38
|
+
window.setTimeout(() => {
|
|
39
|
+
window.clearInterval(closeWatcher);
|
|
40
|
+
resolve();
|
|
41
|
+
}, delay);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
return await this.channel.publish(message);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
attempt += 1;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
throw new Error('Maximum retry attempts reached.');
|
|
52
|
+
}
|
|
53
|
+
close() {
|
|
86
54
|
this.closed = true;
|
|
87
55
|
return this.channel.close();
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
}());
|
|
56
|
+
}
|
|
57
|
+
}
|
|
91
58
|
exports.RetryChannel = RetryChannel;
|
|
59
|
+
//# sourceMappingURL=retryChannel.js.map
|
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SandboxChannel = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
class SandboxChannel {
|
|
5
|
+
constructor() {
|
|
6
6
|
this.listeners = [];
|
|
7
7
|
this.messages = [];
|
|
8
8
|
this.closed = false;
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
publish(message) {
|
|
11
11
|
this.messages.push(message);
|
|
12
12
|
return Promise.resolve();
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
this.listeners.forEach(
|
|
16
|
-
}
|
|
17
|
-
|
|
13
|
+
}
|
|
14
|
+
notify(message) {
|
|
15
|
+
this.listeners.forEach(dispatch => dispatch(message));
|
|
16
|
+
}
|
|
17
|
+
subscribe(listener) {
|
|
18
18
|
if (!this.listeners.includes(listener)) {
|
|
19
19
|
this.listeners.push(listener);
|
|
20
20
|
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
}
|
|
22
|
+
unsubscribe(listener) {
|
|
23
|
+
const index = this.listeners.indexOf(listener);
|
|
24
24
|
if (index >= 0) {
|
|
25
25
|
this.listeners.splice(index, 1);
|
|
26
26
|
}
|
|
27
|
-
}
|
|
28
|
-
|
|
27
|
+
}
|
|
28
|
+
close() {
|
|
29
29
|
this.closed = true;
|
|
30
30
|
return Promise.resolve();
|
|
31
|
-
}
|
|
32
|
-
|
|
31
|
+
}
|
|
32
|
+
isClosed() {
|
|
33
33
|
return this.closed;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
}());
|
|
34
|
+
}
|
|
35
|
+
}
|
|
37
36
|
exports.SandboxChannel = SandboxChannel;
|
|
37
|
+
//# sourceMappingURL=sandboxChannel.js.map
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Logger } from '../logging';
|
|
2
2
|
import { ChannelListener, DuplexChannel } from './channel';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
type Input = string | ArrayBufferLike | Blob | ArrayBufferView;
|
|
4
|
+
type Output = string | ArrayBuffer | Blob;
|
|
5
|
+
type Options = {
|
|
6
6
|
closeTimeout: number;
|
|
7
7
|
connectionTimeout: number;
|
|
8
8
|
protocols: string | string[];
|
|
9
9
|
binaryType?: BinaryType;
|
|
10
10
|
};
|
|
11
|
-
export
|
|
11
|
+
export type Configuration = Partial<Options> & {
|
|
12
12
|
url: string;
|
|
13
13
|
logger?: Logger;
|
|
14
14
|
};
|