@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
package/tab.js
CHANGED
|
@@ -1,125 +1,96 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Tab = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const eventManager_1 = require("./eventManager");
|
|
5
|
+
const EventMap = {
|
|
6
6
|
focus: 'focus',
|
|
7
7
|
blur: 'blur',
|
|
8
8
|
beforeunload: 'unload',
|
|
9
9
|
DOMContentLoaded: 'load',
|
|
10
10
|
visibilitychange: 'visibilityChange',
|
|
11
11
|
};
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
class Tab {
|
|
13
|
+
constructor(id, isNew, urlSanitizer) {
|
|
14
14
|
this.eventManager = new eventManager_1.SynchronousEventManager();
|
|
15
15
|
this.id = id;
|
|
16
16
|
this.isNew = isNew;
|
|
17
17
|
this.urlSanitizer = urlSanitizer;
|
|
18
18
|
this.initialize();
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
_this.emit(EventMap[event.type], new CustomEvent(EventMap[event.type], { detail: { tab: _this } }));
|
|
20
|
+
initialize() {
|
|
21
|
+
const listener = (event) => {
|
|
22
|
+
this.emit(EventMap[event.type], new CustomEvent(EventMap[event.type], { detail: { tab: this } }));
|
|
24
23
|
};
|
|
25
24
|
window.addEventListener('focus', listener, true);
|
|
26
25
|
window.addEventListener('blur', listener, true);
|
|
27
26
|
window.addEventListener('beforeunload', listener, true);
|
|
28
27
|
window.addEventListener('DOMContentLoaded', listener, true);
|
|
29
|
-
document.addEventListener('visibilitychange',
|
|
30
|
-
|
|
28
|
+
document.addEventListener('visibilitychange', () => {
|
|
29
|
+
this.emit('visibilityChange', new CustomEvent('visibilityChange', {
|
|
31
30
|
detail: {
|
|
32
|
-
tab:
|
|
33
|
-
visible:
|
|
31
|
+
tab: this,
|
|
32
|
+
visible: this.isVisible,
|
|
34
33
|
},
|
|
35
34
|
}));
|
|
36
35
|
}, true);
|
|
37
|
-
Tab.addUrlChangeListener(
|
|
38
|
-
|
|
36
|
+
Tab.addUrlChangeListener(url => {
|
|
37
|
+
this.emit('urlChange', new CustomEvent('urlChange', { detail: { tab: this, url: this.sanitizeUrl(url) } }));
|
|
39
38
|
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return document.referrer === '' ? '' : this.sanitizeUrl(document.referrer);
|
|
58
|
-
},
|
|
59
|
-
enumerable: false,
|
|
60
|
-
configurable: true
|
|
61
|
-
});
|
|
62
|
-
Object.defineProperty(Tab.prototype, "isVisible", {
|
|
63
|
-
get: function () {
|
|
64
|
-
return document.visibilityState === 'visible';
|
|
65
|
-
},
|
|
66
|
-
enumerable: false,
|
|
67
|
-
configurable: true
|
|
68
|
-
});
|
|
69
|
-
Object.defineProperty(Tab.prototype, "document", {
|
|
70
|
-
get: function () {
|
|
71
|
-
return document;
|
|
72
|
-
},
|
|
73
|
-
enumerable: false,
|
|
74
|
-
configurable: true
|
|
75
|
-
});
|
|
76
|
-
Tab.prototype.addListener = function (type, listener) {
|
|
39
|
+
}
|
|
40
|
+
get url() {
|
|
41
|
+
return this.sanitizeUrl(window.location.href);
|
|
42
|
+
}
|
|
43
|
+
get title() {
|
|
44
|
+
return document.title;
|
|
45
|
+
}
|
|
46
|
+
get referrer() {
|
|
47
|
+
return document.referrer === '' ? '' : this.sanitizeUrl(document.referrer);
|
|
48
|
+
}
|
|
49
|
+
get isVisible() {
|
|
50
|
+
return document.visibilityState === 'visible';
|
|
51
|
+
}
|
|
52
|
+
get document() {
|
|
53
|
+
return document;
|
|
54
|
+
}
|
|
55
|
+
addListener(type, listener) {
|
|
77
56
|
this.eventManager.addListener(type, listener);
|
|
78
|
-
}
|
|
79
|
-
|
|
57
|
+
}
|
|
58
|
+
removeListener(type, listener) {
|
|
80
59
|
this.eventManager.removeListener(type, listener);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
60
|
+
}
|
|
61
|
+
sanitizeUrl(url) {
|
|
62
|
+
const normalized = window.encodeURI(window.decodeURI(url));
|
|
84
63
|
if (this.urlSanitizer !== undefined) {
|
|
85
64
|
return this.urlSanitizer(normalized).toString();
|
|
86
65
|
}
|
|
87
66
|
return normalized;
|
|
88
|
-
}
|
|
89
|
-
|
|
67
|
+
}
|
|
68
|
+
emit(type, event) {
|
|
90
69
|
this.eventManager.dispatch(type, event);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
70
|
+
}
|
|
71
|
+
static addUrlChangeListener(listener) {
|
|
72
|
+
let url = window.location.href;
|
|
73
|
+
const updateUrl = () => {
|
|
74
|
+
const currentUrl = window.location.href;
|
|
96
75
|
if (url !== currentUrl) {
|
|
97
76
|
listener(currentUrl);
|
|
98
77
|
url = currentUrl;
|
|
99
78
|
}
|
|
100
79
|
};
|
|
101
|
-
|
|
102
|
-
window.history.pushState = function interceptPushState() {
|
|
103
|
-
|
|
104
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
105
|
-
args[_i] = arguments[_i];
|
|
106
|
-
}
|
|
107
|
-
var result = pushState.apply(window.history, args);
|
|
80
|
+
const { pushState } = window.history;
|
|
81
|
+
window.history.pushState = function interceptPushState(...args) {
|
|
82
|
+
const result = pushState.apply(window.history, args);
|
|
108
83
|
updateUrl();
|
|
109
84
|
return result;
|
|
110
85
|
};
|
|
111
|
-
|
|
112
|
-
window.history.replaceState = function interceptReplaceState() {
|
|
113
|
-
|
|
114
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
115
|
-
args[_i] = arguments[_i];
|
|
116
|
-
}
|
|
117
|
-
var result = replaceState.apply(window.history, args);
|
|
86
|
+
const { replaceState } = window.history;
|
|
87
|
+
window.history.replaceState = function interceptReplaceState(...args) {
|
|
88
|
+
const result = replaceState.apply(window.history, args);
|
|
118
89
|
updateUrl();
|
|
119
90
|
return result;
|
|
120
91
|
};
|
|
121
92
|
window.addEventListener('popstate', updateUrl, true);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
}());
|
|
93
|
+
}
|
|
94
|
+
}
|
|
125
95
|
exports.Tab = Tab;
|
|
96
|
+
//# sourceMappingURL=tab.js.map
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CachedTokenStore = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const token_1 = require("./token");
|
|
5
|
+
class CachedTokenStore {
|
|
6
|
+
constructor(cache) {
|
|
7
7
|
this.cache = cache;
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
getToken() {
|
|
10
|
+
const data = this.cache.get();
|
|
11
11
|
if (data === null) {
|
|
12
12
|
return null;
|
|
13
13
|
}
|
|
@@ -17,14 +17,14 @@ var CachedTokenStore = /** @class */ (function () {
|
|
|
17
17
|
catch (error) {
|
|
18
18
|
return null;
|
|
19
19
|
}
|
|
20
|
-
}
|
|
21
|
-
|
|
20
|
+
}
|
|
21
|
+
setToken(token) {
|
|
22
22
|
if (token === null) {
|
|
23
23
|
this.cache.clear();
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
26
|
this.cache.put(token.toString());
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
}());
|
|
27
|
+
}
|
|
28
|
+
}
|
|
30
29
|
exports.CachedTokenStore = CachedTokenStore;
|
|
30
|
+
//# sourceMappingURL=cachedTokenStore.js.map
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InMemoryTokenStore = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
class InMemoryTokenStore {
|
|
5
|
+
constructor() {
|
|
6
6
|
this.token = null;
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
getToken() {
|
|
9
9
|
return this.token;
|
|
10
|
-
}
|
|
11
|
-
|
|
10
|
+
}
|
|
11
|
+
setToken(token) {
|
|
12
12
|
this.token = token;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
}());
|
|
13
|
+
}
|
|
14
|
+
}
|
|
16
15
|
exports.InMemoryTokenStore = InMemoryTokenStore;
|
|
16
|
+
//# sourceMappingURL=inMemoryTokenStore.js.map
|
package/token/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ReplicatedTokenStore = exports.InMemoryTokenStore = exports.CachedTokenStore = void 0;
|
|
4
|
-
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
5
|
tslib_1.__exportStar(require("./token"), exports);
|
|
6
6
|
var cachedTokenStore_1 = require("./cachedTokenStore");
|
|
7
7
|
Object.defineProperty(exports, "CachedTokenStore", { enumerable: true, get: function () { return cachedTokenStore_1.CachedTokenStore; } });
|
|
@@ -9,3 +9,4 @@ var inMemoryTokenStore_1 = require("./inMemoryTokenStore");
|
|
|
9
9
|
Object.defineProperty(exports, "InMemoryTokenStore", { enumerable: true, get: function () { return inMemoryTokenStore_1.InMemoryTokenStore; } });
|
|
10
10
|
var replicatedTokenStore_1 = require("./replicatedTokenStore");
|
|
11
11
|
Object.defineProperty(exports, "ReplicatedTokenStore", { enumerable: true, get: function () { return replicatedTokenStore_1.ReplicatedTokenStore; } });
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ReplicatedTokenStore = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
class ReplicatedTokenStore {
|
|
5
|
+
constructor(primary, secondary) {
|
|
6
6
|
this.primary = primary;
|
|
7
7
|
this.secondary = secondary;
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
getToken() {
|
|
10
10
|
return this.primary.getToken();
|
|
11
|
-
}
|
|
12
|
-
|
|
11
|
+
}
|
|
12
|
+
setToken(token) {
|
|
13
13
|
this.primary.setToken(token);
|
|
14
14
|
this.secondary.setToken(token);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
}());
|
|
15
|
+
}
|
|
16
|
+
}
|
|
18
17
|
exports.ReplicatedTokenStore = ReplicatedTokenStore;
|
|
18
|
+
//# sourceMappingURL=replicatedTokenStore.js.map
|
package/token/token.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import { JsonObject } from '@croct/json';
|
|
2
|
+
export type Headers = {
|
|
2
3
|
typ: string;
|
|
3
4
|
alg: string;
|
|
4
5
|
kid?: string;
|
|
5
|
-
appId
|
|
6
|
+
appId?: string;
|
|
6
7
|
};
|
|
7
|
-
|
|
8
|
+
type Claims = {
|
|
8
9
|
iss: string;
|
|
9
10
|
aud: string | string[];
|
|
10
11
|
iat: number;
|
|
@@ -12,15 +13,17 @@ export declare type Claims = {
|
|
|
12
13
|
sub?: string;
|
|
13
14
|
jid?: string;
|
|
14
15
|
};
|
|
16
|
+
export type TokenPayload = JsonObject & Claims;
|
|
15
17
|
export declare class Token {
|
|
16
18
|
private readonly headers;
|
|
17
|
-
private readonly
|
|
19
|
+
private readonly payload;
|
|
18
20
|
private readonly signature;
|
|
19
21
|
private constructor();
|
|
20
22
|
static issue(appId: string, subject?: string | null, timestamp?: number): Token;
|
|
21
23
|
static parse(token: string): Token;
|
|
24
|
+
static of(headers: Headers, payload: TokenPayload, signature?: string): Token;
|
|
22
25
|
getHeaders(): Headers;
|
|
23
|
-
|
|
26
|
+
getPayload(): TokenPayload;
|
|
24
27
|
getSignature(): string;
|
|
25
28
|
isAnonymous(): boolean;
|
|
26
29
|
getSubject(): string | null;
|
|
@@ -39,3 +42,4 @@ export declare class FixedTokenProvider implements TokenProvider {
|
|
|
39
42
|
constructor(token: Token | null);
|
|
40
43
|
getToken(): Token | null;
|
|
41
44
|
}
|
|
45
|
+
export {};
|
package/token/token.js
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FixedTokenProvider = exports.Token = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
function Token(headers, claims, signature) {
|
|
10
|
-
if (signature === void 0) { signature = ''; }
|
|
4
|
+
const base64Url_1 = require("../base64Url");
|
|
5
|
+
const schema_1 = require("../schema");
|
|
6
|
+
const error_1 = require("../error");
|
|
7
|
+
class Token {
|
|
8
|
+
constructor(headers, payload, signature = '') {
|
|
11
9
|
this.headers = headers;
|
|
12
|
-
this.
|
|
10
|
+
this.payload = payload;
|
|
13
11
|
this.signature = signature;
|
|
14
12
|
}
|
|
15
|
-
|
|
16
|
-
if (subject === void 0) { subject = null; }
|
|
17
|
-
if (timestamp === void 0) { timestamp = Math.floor(Date.now() / 1000); }
|
|
13
|
+
static issue(appId, subject = null, timestamp = Math.floor(Date.now() / 1000)) {
|
|
18
14
|
if (timestamp < 0) {
|
|
19
15
|
throw new Error('The timestamp must be non-negative.');
|
|
20
16
|
}
|
|
@@ -25,75 +21,86 @@ var Token = /** @class */ (function () {
|
|
|
25
21
|
typ: 'JWT',
|
|
26
22
|
alg: 'none',
|
|
27
23
|
appId: appId,
|
|
28
|
-
},
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
}, {
|
|
25
|
+
iss: 'croct.io',
|
|
26
|
+
aud: 'croct.io',
|
|
27
|
+
iat: timestamp,
|
|
28
|
+
...(subject !== null ? { sub: subject } : null),
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
static parse(token) {
|
|
31
32
|
if (token === '') {
|
|
32
33
|
throw new Error('The token cannot be empty.');
|
|
33
34
|
}
|
|
34
|
-
|
|
35
|
+
const parts = token.split('.', 3);
|
|
35
36
|
// This token is invalid
|
|
36
37
|
if (parts.length < 2) {
|
|
37
38
|
throw new Error('The token is malformed.');
|
|
38
39
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
let headers;
|
|
41
|
+
let payload;
|
|
42
|
+
let signature;
|
|
42
43
|
try {
|
|
43
44
|
headers = JSON.parse((0, base64Url_1.base64UrlDecode)(parts[0]));
|
|
44
|
-
|
|
45
|
+
payload = JSON.parse((0, base64Url_1.base64UrlDecode)(parts[1]));
|
|
45
46
|
if (parts.length === 3) {
|
|
46
47
|
signature = (0, base64Url_1.base64UrlDecode)(parts[2]);
|
|
47
48
|
}
|
|
48
49
|
}
|
|
49
|
-
catch
|
|
50
|
+
catch {
|
|
50
51
|
throw new Error('The token is corrupted.');
|
|
51
52
|
}
|
|
53
|
+
return Token.of(headers, payload, signature);
|
|
54
|
+
}
|
|
55
|
+
static of(headers, payload, signature = '') {
|
|
52
56
|
try {
|
|
53
|
-
schema_1.tokenSchema.validate({
|
|
57
|
+
schema_1.tokenSchema.validate({
|
|
58
|
+
headers: headers,
|
|
59
|
+
payload: payload,
|
|
60
|
+
signature: signature,
|
|
61
|
+
});
|
|
54
62
|
}
|
|
55
63
|
catch (violation) {
|
|
56
|
-
throw new Error(
|
|
64
|
+
throw new Error(`The token is invalid: ${(0, error_1.formatCause)(violation)}`);
|
|
57
65
|
}
|
|
58
|
-
return new Token(headers,
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return
|
|
65
|
-
}
|
|
66
|
-
|
|
66
|
+
return new Token(headers, payload, signature);
|
|
67
|
+
}
|
|
68
|
+
getHeaders() {
|
|
69
|
+
return { ...this.headers };
|
|
70
|
+
}
|
|
71
|
+
getPayload() {
|
|
72
|
+
return { ...this.payload };
|
|
73
|
+
}
|
|
74
|
+
getSignature() {
|
|
67
75
|
return this.signature;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return this.
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return this.
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return this.
|
|
77
|
-
}
|
|
78
|
-
|
|
76
|
+
}
|
|
77
|
+
isAnonymous() {
|
|
78
|
+
return this.payload.sub === undefined;
|
|
79
|
+
}
|
|
80
|
+
getSubject() {
|
|
81
|
+
return this.payload.sub !== undefined ? this.payload.sub : null;
|
|
82
|
+
}
|
|
83
|
+
getIssueTime() {
|
|
84
|
+
return this.payload.iat;
|
|
85
|
+
}
|
|
86
|
+
toJSON() {
|
|
79
87
|
return this.toString();
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
}());
|
|
88
|
+
}
|
|
89
|
+
toString() {
|
|
90
|
+
const headers = (0, base64Url_1.base64UrlEncode)(JSON.stringify(this.headers));
|
|
91
|
+
const payload = (0, base64Url_1.base64UrlEncode)(JSON.stringify(this.payload));
|
|
92
|
+
const signature = (0, base64Url_1.base64UrlEncode)(this.signature);
|
|
93
|
+
return `${headers}.${payload}.${signature}`;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
89
96
|
exports.Token = Token;
|
|
90
|
-
|
|
91
|
-
|
|
97
|
+
class FixedTokenProvider {
|
|
98
|
+
constructor(token) {
|
|
92
99
|
this.token = token;
|
|
93
100
|
}
|
|
94
|
-
|
|
101
|
+
getToken() {
|
|
95
102
|
return this.token;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
}());
|
|
103
|
+
}
|
|
104
|
+
}
|
|
99
105
|
exports.FixedTokenProvider = FixedTokenProvider;
|
|
106
|
+
//# sourceMappingURL=token.js.map
|
package/tracker.d.ts
CHANGED
|
@@ -4,19 +4,19 @@ import { OutputChannel } from './channel';
|
|
|
4
4
|
import { TokenProvider } from './token';
|
|
5
5
|
import { RetryPolicy } from './retry';
|
|
6
6
|
import { Beacon, TrackingEvent, TrackingEventContext, PartialTrackingEvent } from './trackingEvents';
|
|
7
|
-
|
|
7
|
+
type Options = {
|
|
8
8
|
eventMetadata?: {
|
|
9
9
|
[key: string]: string;
|
|
10
10
|
};
|
|
11
11
|
};
|
|
12
|
-
export
|
|
12
|
+
export type Configuration = Options & {
|
|
13
13
|
channel: OutputChannel<Beacon>;
|
|
14
14
|
logger?: Logger;
|
|
15
15
|
tab: Tab;
|
|
16
16
|
tokenProvider: TokenProvider;
|
|
17
17
|
inactivityRetryPolicy: RetryPolicy<number>;
|
|
18
18
|
};
|
|
19
|
-
export
|
|
19
|
+
export type EventInfo<T extends TrackingEvent = TrackingEvent> = {
|
|
20
20
|
context: TrackingEventContext;
|
|
21
21
|
event: T;
|
|
22
22
|
timestamp: number;
|
|
@@ -36,7 +36,7 @@ export declare class Tracker {
|
|
|
36
36
|
private readonly pending;
|
|
37
37
|
private readonly state;
|
|
38
38
|
private readonly inactivityTimer;
|
|
39
|
-
constructor(
|
|
39
|
+
constructor(config: Configuration);
|
|
40
40
|
addListener(listener: EventListener): void;
|
|
41
41
|
removeListener(listener: EventListener): void;
|
|
42
42
|
get flushed(): Promise<void>;
|