@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/sdk.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Sdk = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var container_1 = require("./container");
|
|
6
|
+
var constants_1 = require("./constants");
|
|
7
|
+
var schema_1 = require("./schema");
|
|
8
|
+
var error_1 = require("./error");
|
|
6
9
|
function validateConfiguration(configuration) {
|
|
7
10
|
if (typeof configuration !== 'object' || configuration === null) {
|
|
8
11
|
throw new Error('The configuration must be a key-value map.');
|
|
9
12
|
}
|
|
10
13
|
try {
|
|
11
|
-
|
|
14
|
+
schema_1.sdkConfigurationSchema.validate(configuration);
|
|
12
15
|
}
|
|
13
16
|
catch (violation) {
|
|
14
|
-
throw new Error("Invalid configuration: " + formatCause(violation));
|
|
17
|
+
throw new Error("Invalid configuration: " + error_1.formatCause(violation));
|
|
15
18
|
}
|
|
16
19
|
}
|
|
17
20
|
var Sdk = /** @class */ (function () {
|
|
@@ -22,12 +25,12 @@ var Sdk = /** @class */ (function () {
|
|
|
22
25
|
var e_1, _a;
|
|
23
26
|
var _b, _c, _d, _e;
|
|
24
27
|
validateConfiguration(configuration);
|
|
25
|
-
var _f = configuration.eventMetadata, customMetadata = _f === void 0 ? {} : _f, containerConfiguration = __rest(configuration, ["eventMetadata"]);
|
|
28
|
+
var _f = configuration.eventMetadata, customMetadata = _f === void 0 ? {} : _f, containerConfiguration = tslib_1.__rest(configuration, ["eventMetadata"]);
|
|
26
29
|
var eventMetadata = {
|
|
27
|
-
sdkVersion: VERSION,
|
|
30
|
+
sdkVersion: constants_1.VERSION,
|
|
28
31
|
};
|
|
29
32
|
try {
|
|
30
|
-
for (var _g = __values(Object.keys(customMetadata)), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
33
|
+
for (var _g = tslib_1.__values(Object.keys(customMetadata)), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
31
34
|
var metadata = _h.value;
|
|
32
35
|
eventMetadata["custom_" + metadata] = customMetadata[metadata];
|
|
33
36
|
}
|
|
@@ -39,7 +42,7 @@ var Sdk = /** @class */ (function () {
|
|
|
39
42
|
}
|
|
40
43
|
finally { if (e_1) throw e_1.error; }
|
|
41
44
|
}
|
|
42
|
-
var container = new Container(__assign(__assign({}, containerConfiguration), { evaluationEndpointUrl: (_b = containerConfiguration.evaluationEndpointUrl
|
|
45
|
+
var container = new container_1.Container(tslib_1.__assign(tslib_1.__assign({}, containerConfiguration), { evaluationEndpointUrl: (_b = containerConfiguration.evaluationEndpointUrl) !== null && _b !== void 0 ? _b : constants_1.EVALUATION_ENDPOINT_URL, trackerEndpointUrl: (_c = containerConfiguration.trackerEndpointUrl) !== null && _c !== void 0 ? _c : constants_1.TRACKER_ENDPOINT_URL, bootstrapEndpointUrl: (_d = containerConfiguration.bootstrapEndpointUrl) !== null && _d !== void 0 ? _d : constants_1.BOOTSTRAP_ENDPOINT_URL, beaconQueueSize: (_e = containerConfiguration.beaconQueueSize) !== null && _e !== void 0 ? _e : 100, eventMetadata: eventMetadata }));
|
|
43
46
|
var logger = container.getLogger();
|
|
44
47
|
var _j = container.getConfiguration(), appId = _j.appId, tokenScope = _j.tokenScope;
|
|
45
48
|
logger.debug('\n\n'
|
|
@@ -49,7 +52,7 @@ var Sdk = /** @class */ (function () {
|
|
|
49
52
|
+ '██ ██ ██ ██ ██ ██ ██ \n'
|
|
50
53
|
+ ' ██████ ██ ██ ██████ ██████ ██ \n'
|
|
51
54
|
+ '\n');
|
|
52
|
-
logger.info("Initializing SDK v" + VERSION + "...");
|
|
55
|
+
logger.info("Initializing SDK v" + constants_1.VERSION + "...");
|
|
53
56
|
logger.debug("App ID: " + appId);
|
|
54
57
|
var context = container.getContext();
|
|
55
58
|
var tab = context.getTab();
|
|
@@ -65,42 +68,42 @@ var Sdk = /** @class */ (function () {
|
|
|
65
68
|
var appId = this.container.getConfiguration().appId;
|
|
66
69
|
return appId;
|
|
67
70
|
},
|
|
68
|
-
enumerable:
|
|
71
|
+
enumerable: false,
|
|
69
72
|
configurable: true
|
|
70
73
|
});
|
|
71
74
|
Object.defineProperty(Sdk.prototype, "cidAssigner", {
|
|
72
75
|
get: function () {
|
|
73
76
|
return this.container.getCidAssigner();
|
|
74
77
|
},
|
|
75
|
-
enumerable:
|
|
78
|
+
enumerable: false,
|
|
76
79
|
configurable: true
|
|
77
80
|
});
|
|
78
81
|
Object.defineProperty(Sdk.prototype, "context", {
|
|
79
82
|
get: function () {
|
|
80
83
|
return this.container.getContext();
|
|
81
84
|
},
|
|
82
|
-
enumerable:
|
|
85
|
+
enumerable: false,
|
|
83
86
|
configurable: true
|
|
84
87
|
});
|
|
85
88
|
Object.defineProperty(Sdk.prototype, "tracker", {
|
|
86
89
|
get: function () {
|
|
87
90
|
return this.container.getTracker();
|
|
88
91
|
},
|
|
89
|
-
enumerable:
|
|
92
|
+
enumerable: false,
|
|
90
93
|
configurable: true
|
|
91
94
|
});
|
|
92
95
|
Object.defineProperty(Sdk.prototype, "evaluator", {
|
|
93
96
|
get: function () {
|
|
94
97
|
return this.container.getEvaluator();
|
|
95
98
|
},
|
|
96
|
-
enumerable:
|
|
99
|
+
enumerable: false,
|
|
97
100
|
configurable: true
|
|
98
101
|
});
|
|
99
102
|
Object.defineProperty(Sdk.prototype, "eventManager", {
|
|
100
103
|
get: function () {
|
|
101
104
|
return this.container.getEventManager();
|
|
102
105
|
},
|
|
103
|
-
enumerable:
|
|
106
|
+
enumerable: false,
|
|
104
107
|
configurable: true
|
|
105
108
|
});
|
|
106
109
|
Sdk.prototype.getLogger = function () {
|
|
@@ -109,7 +112,7 @@ var Sdk = /** @class */ (function () {
|
|
|
109
112
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
110
113
|
namespace[_i] = arguments[_i];
|
|
111
114
|
}
|
|
112
|
-
return (_a = this.container).getLogger.apply(_a,
|
|
115
|
+
return (_a = this.container).getLogger.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(namespace)));
|
|
113
116
|
};
|
|
114
117
|
Sdk.prototype.getTabStorage = function (namespace) {
|
|
115
118
|
var _a;
|
|
@@ -117,7 +120,7 @@ var Sdk = /** @class */ (function () {
|
|
|
117
120
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
118
121
|
subnamespace[_i - 1] = arguments[_i];
|
|
119
122
|
}
|
|
120
|
-
return (_a = this.container).getTabStorage.apply(_a,
|
|
123
|
+
return (_a = this.container).getTabStorage.apply(_a, tslib_1.__spreadArray([namespace], tslib_1.__read(subnamespace)));
|
|
121
124
|
};
|
|
122
125
|
Sdk.prototype.getBrowserStorage = function (namespace) {
|
|
123
126
|
var _a;
|
|
@@ -125,12 +128,12 @@ var Sdk = /** @class */ (function () {
|
|
|
125
128
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
126
129
|
subnamespace[_i - 1] = arguments[_i];
|
|
127
130
|
}
|
|
128
|
-
return (_a = this.container).getBrowserStorage.apply(_a,
|
|
131
|
+
return (_a = this.container).getBrowserStorage.apply(_a, tslib_1.__spreadArray([namespace], tslib_1.__read(subnamespace)));
|
|
129
132
|
};
|
|
130
133
|
Sdk.prototype.close = function () {
|
|
131
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
134
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
132
135
|
var logger;
|
|
133
|
-
return __generator(this, function (_a) {
|
|
136
|
+
return tslib_1.__generator(this, function (_a) {
|
|
134
137
|
switch (_a.label) {
|
|
135
138
|
case 0:
|
|
136
139
|
if (this.closed) {
|
|
@@ -150,4 +153,4 @@ var Sdk = /** @class */ (function () {
|
|
|
150
153
|
};
|
|
151
154
|
return Sdk;
|
|
152
155
|
}());
|
|
153
|
-
|
|
156
|
+
exports.Sdk = Sdk;
|
package/sdkEvents.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import Token from './token
|
|
1
|
+
import { Token } from './token';
|
|
2
2
|
export interface TokenChanged {
|
|
3
3
|
oldToken: Token | null;
|
|
4
4
|
newToken: Token | null;
|
|
5
5
|
}
|
|
6
|
-
export declare type SdkEventMap = Record<string,
|
|
6
|
+
export declare type SdkEventMap = Record<string, Record<string, unknown>> & {
|
|
7
7
|
tokenChanged: TokenChanged;
|
|
8
8
|
};
|
|
9
9
|
export declare type SdkEventType = keyof SdkEventMap;
|
package/sdkEvents.js
CHANGED
package/sourceLocation.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLocation = exports.getPosition = exports.getLength = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
function getLength(input) {
|
|
6
|
+
return tslib_1.__spreadArray([], tslib_1.__read(input)).length;
|
|
4
7
|
}
|
|
5
|
-
|
|
8
|
+
exports.getLength = getLength;
|
|
9
|
+
function getPosition(input, index) {
|
|
6
10
|
return getLocation(input, index, index).start;
|
|
7
11
|
}
|
|
8
|
-
|
|
12
|
+
exports.getPosition = getPosition;
|
|
13
|
+
function getLocation(input, startIndex, endIndex) {
|
|
9
14
|
if (startIndex < 0) {
|
|
10
15
|
throw Error('The start index cannot be negative.');
|
|
11
16
|
}
|
|
@@ -14,7 +19,7 @@ export function getLocation(input, startIndex, endIndex) {
|
|
|
14
19
|
}
|
|
15
20
|
var start;
|
|
16
21
|
var end;
|
|
17
|
-
var chars =
|
|
22
|
+
var chars = tslib_1.__spreadArray([], tslib_1.__read(input));
|
|
18
23
|
var line = 1;
|
|
19
24
|
var column = 0;
|
|
20
25
|
for (var offset = 0; offset < chars.length; offset++) {
|
|
@@ -61,3 +66,4 @@ export function getLocation(input, startIndex, endIndex) {
|
|
|
61
66
|
end: end,
|
|
62
67
|
};
|
|
63
68
|
}
|
|
69
|
+
exports.getLocation = getLocation;
|
package/tab.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EventListener } from './eventManager';
|
|
2
|
-
export declare type TabEvent<T =
|
|
2
|
+
export declare type TabEvent<T = Record<string, unknown>> = CustomEvent<{
|
|
3
3
|
tab: Tab;
|
|
4
4
|
} & T>;
|
|
5
5
|
export declare type TabVisibilityChangeEvent = TabEvent<{
|
|
@@ -17,7 +17,7 @@ declare type TabEventMap = {
|
|
|
17
17
|
visibilityChange: TabVisibilityChangeEvent;
|
|
18
18
|
urlChange: TabUrlChangeEvent;
|
|
19
19
|
};
|
|
20
|
-
export
|
|
20
|
+
export declare class Tab {
|
|
21
21
|
readonly id: string;
|
|
22
22
|
readonly isNew: boolean;
|
|
23
23
|
readonly urlSanitizer?: UrlSanitizer;
|
package/tab.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Tab = void 0;
|
|
4
|
+
var eventManager_1 = require("./eventManager");
|
|
2
5
|
var EventMap = {
|
|
3
6
|
focus: 'focus',
|
|
4
7
|
blur: 'blur',
|
|
@@ -8,7 +11,7 @@ var EventMap = {
|
|
|
8
11
|
};
|
|
9
12
|
var Tab = /** @class */ (function () {
|
|
10
13
|
function Tab(id, isNew, urlSanitizer) {
|
|
11
|
-
this.eventManager = new SynchronousEventManager();
|
|
14
|
+
this.eventManager = new eventManager_1.SynchronousEventManager();
|
|
12
15
|
this.id = id;
|
|
13
16
|
this.isNew = isNew;
|
|
14
17
|
this.urlSanitizer = urlSanitizer;
|
|
@@ -39,35 +42,35 @@ var Tab = /** @class */ (function () {
|
|
|
39
42
|
get: function () {
|
|
40
43
|
return this.sanitizeUrl(window.location.href);
|
|
41
44
|
},
|
|
42
|
-
enumerable:
|
|
45
|
+
enumerable: false,
|
|
43
46
|
configurable: true
|
|
44
47
|
});
|
|
45
48
|
Object.defineProperty(Tab.prototype, "title", {
|
|
46
49
|
get: function () {
|
|
47
50
|
return document.title;
|
|
48
51
|
},
|
|
49
|
-
enumerable:
|
|
52
|
+
enumerable: false,
|
|
50
53
|
configurable: true
|
|
51
54
|
});
|
|
52
55
|
Object.defineProperty(Tab.prototype, "referrer", {
|
|
53
56
|
get: function () {
|
|
54
|
-
return this.sanitizeUrl(document.referrer);
|
|
57
|
+
return document.referrer === '' ? '' : this.sanitizeUrl(document.referrer);
|
|
55
58
|
},
|
|
56
|
-
enumerable:
|
|
59
|
+
enumerable: false,
|
|
57
60
|
configurable: true
|
|
58
61
|
});
|
|
59
62
|
Object.defineProperty(Tab.prototype, "isVisible", {
|
|
60
63
|
get: function () {
|
|
61
64
|
return document.visibilityState === 'visible';
|
|
62
65
|
},
|
|
63
|
-
enumerable:
|
|
66
|
+
enumerable: false,
|
|
64
67
|
configurable: true
|
|
65
68
|
});
|
|
66
69
|
Object.defineProperty(Tab.prototype, "document", {
|
|
67
70
|
get: function () {
|
|
68
71
|
return document;
|
|
69
72
|
},
|
|
70
|
-
enumerable:
|
|
73
|
+
enumerable: false,
|
|
71
74
|
configurable: true
|
|
72
75
|
});
|
|
73
76
|
Tab.prototype.addListener = function (type, listener) {
|
|
@@ -119,4 +122,4 @@ var Tab = /** @class */ (function () {
|
|
|
119
122
|
};
|
|
120
123
|
return Tab;
|
|
121
124
|
}());
|
|
122
|
-
|
|
125
|
+
exports.Tab = Tab;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import Token,
|
|
2
|
-
import Cache from '../cache
|
|
3
|
-
export
|
|
1
|
+
import { Token, TokenStore } from './token';
|
|
2
|
+
import { Cache } from '../cache';
|
|
3
|
+
export declare class CachedTokenStore implements TokenStore {
|
|
4
4
|
private readonly cache;
|
|
5
5
|
constructor(cache: Cache);
|
|
6
6
|
getToken(): Token | null;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CachedTokenStore = void 0;
|
|
4
|
+
var token_1 = require("./token");
|
|
2
5
|
var CachedTokenStore = /** @class */ (function () {
|
|
3
6
|
function CachedTokenStore(cache) {
|
|
4
7
|
this.cache = cache;
|
|
@@ -9,7 +12,7 @@ var CachedTokenStore = /** @class */ (function () {
|
|
|
9
12
|
return null;
|
|
10
13
|
}
|
|
11
14
|
try {
|
|
12
|
-
return Token.parse(data);
|
|
15
|
+
return token_1.Token.parse(data);
|
|
13
16
|
}
|
|
14
17
|
catch (error) {
|
|
15
18
|
return null;
|
|
@@ -24,4 +27,4 @@ var CachedTokenStore = /** @class */ (function () {
|
|
|
24
27
|
};
|
|
25
28
|
return CachedTokenStore;
|
|
26
29
|
}());
|
|
27
|
-
|
|
30
|
+
exports.CachedTokenStore = CachedTokenStore;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import Token,
|
|
2
|
-
export
|
|
1
|
+
import { Token, TokenStore } from './token';
|
|
2
|
+
export declare class InMemoryTokenStore implements TokenStore {
|
|
3
3
|
private token;
|
|
4
4
|
getToken(): Token | null;
|
|
5
5
|
setToken(token: Token | null): void;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InMemoryTokenStore = void 0;
|
|
1
4
|
var InMemoryTokenStore = /** @class */ (function () {
|
|
2
5
|
function InMemoryTokenStore() {
|
|
3
6
|
this.token = null;
|
|
@@ -10,4 +13,4 @@ var InMemoryTokenStore = /** @class */ (function () {
|
|
|
10
13
|
};
|
|
11
14
|
return InMemoryTokenStore;
|
|
12
15
|
}());
|
|
13
|
-
|
|
16
|
+
exports.InMemoryTokenStore = InMemoryTokenStore;
|
package/token/index.d.ts
CHANGED
|
@@ -1,41 +1,4 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
appId: string;
|
|
6
|
-
};
|
|
7
|
-
export declare type Claims = {
|
|
8
|
-
iss: string;
|
|
9
|
-
aud: string;
|
|
10
|
-
iat: number;
|
|
11
|
-
exp?: number;
|
|
12
|
-
sub?: string;
|
|
13
|
-
jid?: string;
|
|
14
|
-
};
|
|
15
|
-
export default class Token {
|
|
16
|
-
private readonly headers;
|
|
17
|
-
private readonly claims;
|
|
18
|
-
private readonly signature;
|
|
19
|
-
private constructor();
|
|
20
|
-
static issue(appId: string, subject?: string | null, timestamp?: number): Token;
|
|
21
|
-
static parse(token: string): Token;
|
|
22
|
-
getHeaders(): Headers;
|
|
23
|
-
getClaims(): Claims;
|
|
24
|
-
getSignature(): string;
|
|
25
|
-
isAnonymous(): boolean;
|
|
26
|
-
getSubject(): string | null;
|
|
27
|
-
getIssueTime(): number;
|
|
28
|
-
toJSON(): string;
|
|
29
|
-
toString(): string;
|
|
30
|
-
}
|
|
31
|
-
export interface TokenProvider {
|
|
32
|
-
getToken(): Token | null;
|
|
33
|
-
}
|
|
34
|
-
export interface TokenStore extends TokenProvider {
|
|
35
|
-
setToken(token: Token | null): void;
|
|
36
|
-
}
|
|
37
|
-
export declare class FixedTokenProvider implements TokenProvider {
|
|
38
|
-
private readonly token;
|
|
39
|
-
constructor(token: Token | null);
|
|
40
|
-
getToken(): Token | null;
|
|
41
|
-
}
|
|
1
|
+
export * from './token';
|
|
2
|
+
export { CachedTokenStore } from './cachedTokenStore';
|
|
3
|
+
export { InMemoryTokenStore } from './inMemoryTokenStore';
|
|
4
|
+
export { ReplicatedTokenStore } from './replicatedTokenStore';
|
package/token/index.js
CHANGED
|
@@ -1,96 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
Token.issue = function (appId, subject, timestamp) {
|
|
13
|
-
if (subject === void 0) { subject = null; }
|
|
14
|
-
if (timestamp === void 0) { timestamp = Math.floor(Date.now() / 1000); }
|
|
15
|
-
if (timestamp < 0) {
|
|
16
|
-
throw new Error('The timestamp must be non-negative.');
|
|
17
|
-
}
|
|
18
|
-
if (subject === '') {
|
|
19
|
-
throw new Error('The subject must be non-empty.');
|
|
20
|
-
}
|
|
21
|
-
return new Token({
|
|
22
|
-
typ: 'JWT',
|
|
23
|
-
alg: 'none',
|
|
24
|
-
appId: appId,
|
|
25
|
-
}, __assign({ iss: 'croct.io', aud: 'croct.io', iat: timestamp }, (subject !== null ? { sub: subject } : null)));
|
|
26
|
-
};
|
|
27
|
-
Token.parse = function (token) {
|
|
28
|
-
if (token === '') {
|
|
29
|
-
throw new Error('The token cannot be empty.');
|
|
30
|
-
}
|
|
31
|
-
var parts = token.split('.', 3);
|
|
32
|
-
// This token is invalid
|
|
33
|
-
if (parts.length < 2) {
|
|
34
|
-
throw new Error('The token is malformed.');
|
|
35
|
-
}
|
|
36
|
-
var headers;
|
|
37
|
-
var claims;
|
|
38
|
-
var signature;
|
|
39
|
-
try {
|
|
40
|
-
headers = JSON.parse(base64UrlDecode(parts[0]));
|
|
41
|
-
claims = JSON.parse(base64UrlDecode(parts[1]));
|
|
42
|
-
if (parts.length === 3) {
|
|
43
|
-
signature = base64UrlDecode(parts[2]);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
catch (_a) {
|
|
47
|
-
throw new Error('The token is corrupted.');
|
|
48
|
-
}
|
|
49
|
-
try {
|
|
50
|
-
tokenSchema.validate({ headers: headers, claims: claims, signature: signature });
|
|
51
|
-
}
|
|
52
|
-
catch (violation) {
|
|
53
|
-
throw new Error("The token is invalid: " + formatCause(violation));
|
|
54
|
-
}
|
|
55
|
-
return new Token(headers, claims, signature);
|
|
56
|
-
};
|
|
57
|
-
Token.prototype.getHeaders = function () {
|
|
58
|
-
return __assign({}, this.headers);
|
|
59
|
-
};
|
|
60
|
-
Token.prototype.getClaims = function () {
|
|
61
|
-
return __assign({}, this.claims);
|
|
62
|
-
};
|
|
63
|
-
Token.prototype.getSignature = function () {
|
|
64
|
-
return this.signature;
|
|
65
|
-
};
|
|
66
|
-
Token.prototype.isAnonymous = function () {
|
|
67
|
-
return this.claims.sub === undefined;
|
|
68
|
-
};
|
|
69
|
-
Token.prototype.getSubject = function () {
|
|
70
|
-
return this.claims.sub !== undefined ? this.claims.sub : null;
|
|
71
|
-
};
|
|
72
|
-
Token.prototype.getIssueTime = function () {
|
|
73
|
-
return this.claims.iat;
|
|
74
|
-
};
|
|
75
|
-
Token.prototype.toJSON = function () {
|
|
76
|
-
return this.toString();
|
|
77
|
-
};
|
|
78
|
-
Token.prototype.toString = function () {
|
|
79
|
-
var headers = base64UrlEncode(JSON.stringify(this.headers));
|
|
80
|
-
var claims = base64UrlEncode(JSON.stringify(this.claims));
|
|
81
|
-
var signature = base64UrlEncode(this.signature);
|
|
82
|
-
return headers + "." + claims + "." + signature;
|
|
83
|
-
};
|
|
84
|
-
return Token;
|
|
85
|
-
}());
|
|
86
|
-
export default Token;
|
|
87
|
-
var FixedTokenProvider = /** @class */ (function () {
|
|
88
|
-
function FixedTokenProvider(token) {
|
|
89
|
-
this.token = token;
|
|
90
|
-
}
|
|
91
|
-
FixedTokenProvider.prototype.getToken = function () {
|
|
92
|
-
return this.token;
|
|
93
|
-
};
|
|
94
|
-
return FixedTokenProvider;
|
|
95
|
-
}());
|
|
96
|
-
export { FixedTokenProvider };
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReplicatedTokenStore = exports.InMemoryTokenStore = exports.CachedTokenStore = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
tslib_1.__exportStar(require("./token"), exports);
|
|
6
|
+
var cachedTokenStore_1 = require("./cachedTokenStore");
|
|
7
|
+
Object.defineProperty(exports, "CachedTokenStore", { enumerable: true, get: function () { return cachedTokenStore_1.CachedTokenStore; } });
|
|
8
|
+
var inMemoryTokenStore_1 = require("./inMemoryTokenStore");
|
|
9
|
+
Object.defineProperty(exports, "InMemoryTokenStore", { enumerable: true, get: function () { return inMemoryTokenStore_1.InMemoryTokenStore; } });
|
|
10
|
+
var replicatedTokenStore_1 = require("./replicatedTokenStore");
|
|
11
|
+
Object.defineProperty(exports, "ReplicatedTokenStore", { enumerable: true, get: function () { return replicatedTokenStore_1.ReplicatedTokenStore; } });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import Token,
|
|
2
|
-
export
|
|
1
|
+
import { Token, TokenStore } from './token';
|
|
2
|
+
export declare class ReplicatedTokenStore implements TokenStore {
|
|
3
3
|
private primary;
|
|
4
4
|
private secondary;
|
|
5
5
|
constructor(primary: TokenStore, secondary: TokenStore);
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReplicatedTokenStore = void 0;
|
|
1
4
|
var ReplicatedTokenStore = /** @class */ (function () {
|
|
2
5
|
function ReplicatedTokenStore(primary, secondary) {
|
|
3
6
|
this.primary = primary;
|
|
@@ -12,4 +15,4 @@ var ReplicatedTokenStore = /** @class */ (function () {
|
|
|
12
15
|
};
|
|
13
16
|
return ReplicatedTokenStore;
|
|
14
17
|
}());
|
|
15
|
-
|
|
18
|
+
exports.ReplicatedTokenStore = ReplicatedTokenStore;
|
package/token/token.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export declare type Headers = {
|
|
2
|
+
typ: string;
|
|
3
|
+
alg: string;
|
|
4
|
+
kid?: string;
|
|
5
|
+
appId: string;
|
|
6
|
+
};
|
|
7
|
+
export declare type Claims = {
|
|
8
|
+
iss: string;
|
|
9
|
+
aud: string;
|
|
10
|
+
iat: number;
|
|
11
|
+
exp?: number;
|
|
12
|
+
sub?: string;
|
|
13
|
+
jid?: string;
|
|
14
|
+
};
|
|
15
|
+
export declare class Token {
|
|
16
|
+
private readonly headers;
|
|
17
|
+
private readonly claims;
|
|
18
|
+
private readonly signature;
|
|
19
|
+
private constructor();
|
|
20
|
+
static issue(appId: string, subject?: string | null, timestamp?: number): Token;
|
|
21
|
+
static parse(token: string): Token;
|
|
22
|
+
getHeaders(): Headers;
|
|
23
|
+
getClaims(): Claims;
|
|
24
|
+
getSignature(): string;
|
|
25
|
+
isAnonymous(): boolean;
|
|
26
|
+
getSubject(): string | null;
|
|
27
|
+
getIssueTime(): number;
|
|
28
|
+
toJSON(): string;
|
|
29
|
+
toString(): string;
|
|
30
|
+
}
|
|
31
|
+
export interface TokenProvider {
|
|
32
|
+
getToken(): Token | null;
|
|
33
|
+
}
|
|
34
|
+
export interface TokenStore extends TokenProvider {
|
|
35
|
+
setToken(token: Token | null): void;
|
|
36
|
+
}
|
|
37
|
+
export declare class FixedTokenProvider implements TokenProvider {
|
|
38
|
+
private readonly token;
|
|
39
|
+
constructor(token: Token | null);
|
|
40
|
+
getToken(): Token | null;
|
|
41
|
+
}
|
package/token/token.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FixedTokenProvider = exports.Token = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var base64Url_1 = require("../base64Url");
|
|
6
|
+
var schema_1 = require("../schema");
|
|
7
|
+
var error_1 = require("../error");
|
|
8
|
+
var Token = /** @class */ (function () {
|
|
9
|
+
function Token(headers, claims, signature) {
|
|
10
|
+
if (signature === void 0) { signature = ''; }
|
|
11
|
+
this.headers = headers;
|
|
12
|
+
this.claims = claims;
|
|
13
|
+
this.signature = signature;
|
|
14
|
+
}
|
|
15
|
+
Token.issue = function (appId, subject, timestamp) {
|
|
16
|
+
if (subject === void 0) { subject = null; }
|
|
17
|
+
if (timestamp === void 0) { timestamp = Math.floor(Date.now() / 1000); }
|
|
18
|
+
if (timestamp < 0) {
|
|
19
|
+
throw new Error('The timestamp must be non-negative.');
|
|
20
|
+
}
|
|
21
|
+
if (subject === '') {
|
|
22
|
+
throw new Error('The subject must be non-empty.');
|
|
23
|
+
}
|
|
24
|
+
return new Token({
|
|
25
|
+
typ: 'JWT',
|
|
26
|
+
alg: 'none',
|
|
27
|
+
appId: appId,
|
|
28
|
+
}, tslib_1.__assign({ iss: 'croct.io', aud: 'croct.io', iat: timestamp }, (subject !== null ? { sub: subject } : null)));
|
|
29
|
+
};
|
|
30
|
+
Token.parse = function (token) {
|
|
31
|
+
if (token === '') {
|
|
32
|
+
throw new Error('The token cannot be empty.');
|
|
33
|
+
}
|
|
34
|
+
var parts = token.split('.', 3);
|
|
35
|
+
// This token is invalid
|
|
36
|
+
if (parts.length < 2) {
|
|
37
|
+
throw new Error('The token is malformed.');
|
|
38
|
+
}
|
|
39
|
+
var headers;
|
|
40
|
+
var claims;
|
|
41
|
+
var signature;
|
|
42
|
+
try {
|
|
43
|
+
headers = JSON.parse(base64Url_1.base64UrlDecode(parts[0]));
|
|
44
|
+
claims = JSON.parse(base64Url_1.base64UrlDecode(parts[1]));
|
|
45
|
+
if (parts.length === 3) {
|
|
46
|
+
signature = base64Url_1.base64UrlDecode(parts[2]);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
catch (_a) {
|
|
50
|
+
throw new Error('The token is corrupted.');
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
schema_1.tokenSchema.validate({ headers: headers, claims: claims, signature: signature });
|
|
54
|
+
}
|
|
55
|
+
catch (violation) {
|
|
56
|
+
throw new Error("The token is invalid: " + error_1.formatCause(violation));
|
|
57
|
+
}
|
|
58
|
+
return new Token(headers, claims, signature);
|
|
59
|
+
};
|
|
60
|
+
Token.prototype.getHeaders = function () {
|
|
61
|
+
return tslib_1.__assign({}, this.headers);
|
|
62
|
+
};
|
|
63
|
+
Token.prototype.getClaims = function () {
|
|
64
|
+
return tslib_1.__assign({}, this.claims);
|
|
65
|
+
};
|
|
66
|
+
Token.prototype.getSignature = function () {
|
|
67
|
+
return this.signature;
|
|
68
|
+
};
|
|
69
|
+
Token.prototype.isAnonymous = function () {
|
|
70
|
+
return this.claims.sub === undefined;
|
|
71
|
+
};
|
|
72
|
+
Token.prototype.getSubject = function () {
|
|
73
|
+
return this.claims.sub !== undefined ? this.claims.sub : null;
|
|
74
|
+
};
|
|
75
|
+
Token.prototype.getIssueTime = function () {
|
|
76
|
+
return this.claims.iat;
|
|
77
|
+
};
|
|
78
|
+
Token.prototype.toJSON = function () {
|
|
79
|
+
return this.toString();
|
|
80
|
+
};
|
|
81
|
+
Token.prototype.toString = function () {
|
|
82
|
+
var headers = base64Url_1.base64UrlEncode(JSON.stringify(this.headers));
|
|
83
|
+
var claims = base64Url_1.base64UrlEncode(JSON.stringify(this.claims));
|
|
84
|
+
var signature = base64Url_1.base64UrlEncode(this.signature);
|
|
85
|
+
return headers + "." + claims + "." + signature;
|
|
86
|
+
};
|
|
87
|
+
return Token;
|
|
88
|
+
}());
|
|
89
|
+
exports.Token = Token;
|
|
90
|
+
var FixedTokenProvider = /** @class */ (function () {
|
|
91
|
+
function FixedTokenProvider(token) {
|
|
92
|
+
this.token = token;
|
|
93
|
+
}
|
|
94
|
+
FixedTokenProvider.prototype.getToken = function () {
|
|
95
|
+
return this.token;
|
|
96
|
+
};
|
|
97
|
+
return FixedTokenProvider;
|
|
98
|
+
}());
|
|
99
|
+
exports.FixedTokenProvider = FixedTokenProvider;
|