@croct/sdk 0.9.1 → 0.11.0-alpha
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.js +32 -36
- package/cache/fallbackCache.js +15 -32
- package/cache/inMemoryCache.js +9 -10
- package/cache/index.js +1 -1
- package/cache/localStorageCache.js +24 -25
- package/channel/beaconSocketChannel.d.ts +1 -1
- package/channel/beaconSocketChannel.js +49 -79
- package/channel/channel.d.ts +1 -1
- package/channel/encodedChannel.js +8 -10
- package/channel/guaranteedChannel.d.ts +4 -4
- package/channel/guaranteedChannel.js +41 -43
- package/channel/index.js +1 -1
- package/channel/queuedChannel.js +35 -64
- package/channel/retryChannel.d.ts +1 -1
- package/channel/retryChannel.js +44 -77
- package/channel/sandboxChannel.js +17 -18
- package/channel/socketChannel.d.ts +4 -4
- package/channel/socketChannel.js +77 -79
- package/cid/cachedAssigner.js +15 -27
- package/cid/fixedAssigner.js +5 -6
- package/cid/index.js +1 -1
- package/cid/remoteAssigner.js +23 -36
- package/constants.d.ts +3 -2
- package/constants.js +6 -5
- package/container.d.ts +13 -6
- package/container.js +152 -168
- package/contentFetcher.d.ts +59 -0
- package/contentFetcher.js +129 -0
- package/context.d.ts +3 -3
- package/context.js +36 -38
- package/error.js +2 -2
- package/evaluator.d.ts +33 -24
- package/evaluator.js +126 -117
- package/eventManager.d.ts +1 -1
- package/eventManager.js +14 -15
- package/facade/contentFetcherFacade.d.ts +27 -0
- package/facade/contentFetcherFacade.js +40 -0
- package/facade/evaluatorFacade.d.ts +13 -3
- package/facade/evaluatorFacade.js +57 -72
- package/facade/sdkFacade.d.ts +10 -3
- package/facade/sdkFacade.js +129 -141
- package/facade/sessionFacade.js +6 -7
- package/facade/sessionPatch.js +9 -13
- package/facade/trackerFacade.js +32 -38
- package/facade/userFacade.js +10 -11
- package/facade/userPatch.js +9 -13
- package/index.js +2 -2
- package/logging/consoleLogger.js +18 -35
- package/logging/index.js +1 -1
- package/logging/namespacedLogger.js +14 -15
- package/logging/nullLogger.js +10 -13
- package/namespacedStorage.js +30 -47
- package/package.json +13 -16
- package/patch.d.ts +1 -1
- package/queue/capacityRestrictedQueue.js +17 -18
- package/queue/inMemoryQueue.js +22 -28
- package/queue/index.js +1 -1
- package/queue/monitoredQueue.d.ts +2 -2
- package/queue/monitoredQueue.js +39 -40
- package/queue/persistentQueue.js +33 -38
- package/retry/arbitraryPolicy.js +8 -10
- package/retry/backoffPolicy.d.ts +1 -1
- package/retry/backoffPolicy.js +11 -13
- package/retry/index.js +1 -1
- package/retry/maxAttemptsPolicy.js +7 -8
- package/retry/neverPolicy.js +6 -9
- package/schema/attributeSchema.js +1 -1
- package/schema/contentFetcherSchemas.d.ts +2 -0
- package/schema/contentFetcherSchemas.js +22 -0
- package/schema/contentSchemas.js +1 -1
- package/schema/contextSchemas.js +1 -1
- package/schema/ecommerceSchemas.js +1 -1
- package/schema/evaluatorSchemas.d.ts +2 -0
- package/schema/{evaluationSchemas.js → evaluatorSchemas.js} +3 -3
- package/schema/eventSchemas.js +8 -9
- package/schema/index.d.ts +2 -1
- package/schema/index.js +3 -2
- package/schema/loggerSchema.js +1 -1
- package/schema/operationSchemas.js +8 -8
- package/schema/sdkFacadeSchemas.js +9 -6
- package/schema/sdkSchemas.js +8 -5
- package/schema/tokenSchema.js +5 -4
- package/schema/userSchema.js +2 -2
- package/sdk.d.ts +9 -3
- package/sdk.js +81 -127
- package/sdkEvents.d.ts +3 -3
- package/sourceLocation.d.ts +3 -3
- package/sourceLocation.js +13 -14
- package/tab.d.ts +5 -5
- package/tab.js +50 -80
- package/token/cachedTokenStore.js +9 -10
- package/token/inMemoryTokenStore.js +7 -8
- package/token/index.js +1 -1
- package/token/replicatedTokenStore.js +7 -8
- package/token/token.d.ts +9 -5
- package/token/token.js +63 -57
- package/tracker.d.ts +4 -4
- package/tracker.js +145 -122
- package/trackingEvents.d.ts +36 -36
- package/trackingEvents.js +12 -6
- package/transformer.js +1 -1
- package/utilityTypes.d.ts +2 -2
- package/uuid.js +9 -7
- package/validation/arrayType.d.ts +2 -2
- package/validation/arrayType.js +29 -27
- package/validation/booleanType.js +11 -15
- package/validation/functionType.js +11 -15
- package/validation/index.js +1 -1
- package/validation/jsonType.d.ts +2 -2
- package/validation/jsonType.js +61 -80
- package/validation/mixedSchema.js +4 -7
- package/validation/nullType.js +11 -15
- package/validation/numberType.d.ts +1 -1
- package/validation/numberType.js +23 -22
- package/validation/objectType.d.ts +1 -1
- package/validation/objectType.js +61 -73
- package/validation/schema.js +6 -10
- package/validation/stringType.d.ts +1 -1
- package/validation/stringType.js +36 -47
- package/validation/unionType.js +27 -77
- package/validation/violation.js +1 -2
- package/schema/evaluationSchemas.d.ts +0 -2
package/schema/tokenSchema.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.tokenSchema = void 0;
|
|
4
|
-
|
|
4
|
+
const validation_1 = require("../validation");
|
|
5
5
|
exports.tokenSchema = new validation_1.ObjectType({
|
|
6
|
-
required: ['headers', '
|
|
6
|
+
required: ['headers', 'payload'],
|
|
7
7
|
properties: {
|
|
8
8
|
headers: new validation_1.ObjectType({
|
|
9
|
-
required: ['typ', 'alg'
|
|
9
|
+
required: ['typ', 'alg'],
|
|
10
10
|
properties: {
|
|
11
11
|
typ: new validation_1.StringType(),
|
|
12
12
|
alg: new validation_1.StringType(),
|
|
@@ -16,7 +16,7 @@ exports.tokenSchema = new validation_1.ObjectType({
|
|
|
16
16
|
}),
|
|
17
17
|
},
|
|
18
18
|
}),
|
|
19
|
-
|
|
19
|
+
payload: new validation_1.ObjectType({
|
|
20
20
|
required: ['iss', 'aud', 'iat'],
|
|
21
21
|
properties: {
|
|
22
22
|
iss: new validation_1.StringType(),
|
|
@@ -34,6 +34,7 @@ exports.tokenSchema = new validation_1.ObjectType({
|
|
|
34
34
|
format: 'uuid',
|
|
35
35
|
}),
|
|
36
36
|
},
|
|
37
|
+
additionalProperties: true,
|
|
37
38
|
}),
|
|
38
39
|
signature: new validation_1.StringType(),
|
|
39
40
|
},
|
package/schema/userSchema.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.userProfileSchema = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const validation_1 = require("../validation");
|
|
5
|
+
const attributeSchema_1 = require("./attributeSchema");
|
|
6
6
|
exports.userProfileSchema = new validation_1.ObjectType({
|
|
7
7
|
properties: {
|
|
8
8
|
firstName: new validation_1.StringType({
|
package/sdk.d.ts
CHANGED
|
@@ -6,15 +6,18 @@ import { SdkEventMap } from './sdkEvents';
|
|
|
6
6
|
import { EventManager } from './eventManager';
|
|
7
7
|
import { CidAssigner } from './cid';
|
|
8
8
|
import { UrlSanitizer } from './tab';
|
|
9
|
-
|
|
9
|
+
import { ContentFetcher } from './contentFetcher';
|
|
10
|
+
import { TokenStore } from './token';
|
|
11
|
+
export type Configuration = {
|
|
10
12
|
appId: string;
|
|
11
13
|
tokenScope: TokenScope;
|
|
12
14
|
debug: boolean;
|
|
13
15
|
test: boolean;
|
|
14
|
-
|
|
16
|
+
clientId?: string;
|
|
15
17
|
trackerEndpointUrl?: string;
|
|
16
18
|
evaluationEndpointUrl?: string;
|
|
17
|
-
|
|
19
|
+
contentEndpointUrl?: string;
|
|
20
|
+
cidAssignerEndpointUrl?: string;
|
|
18
21
|
beaconQueueSize?: number;
|
|
19
22
|
urlSanitizer?: UrlSanitizer;
|
|
20
23
|
logger?: Logger;
|
|
@@ -29,9 +32,12 @@ export declare class Sdk {
|
|
|
29
32
|
static init(configuration: Configuration): Sdk;
|
|
30
33
|
get appId(): string;
|
|
31
34
|
get cidAssigner(): CidAssigner;
|
|
35
|
+
get previewTokenStore(): TokenStore;
|
|
36
|
+
get userTokenStore(): TokenStore;
|
|
32
37
|
get context(): Context;
|
|
33
38
|
get tracker(): Tracker;
|
|
34
39
|
get evaluator(): Evaluator;
|
|
40
|
+
get contentFetcher(): ContentFetcher;
|
|
35
41
|
get eventManager(): EventManager<SdkEventMap>;
|
|
36
42
|
getLogger(...namespace: string[]): Logger;
|
|
37
43
|
getTabStorage(namespace: string, ...subnamespace: string[]): Storage;
|
package/sdk.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Sdk = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var error_1 = require("./error");
|
|
4
|
+
const container_1 = require("./container");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
const schema_1 = require("./schema");
|
|
7
|
+
const error_1 = require("./error");
|
|
9
8
|
function validateConfiguration(configuration) {
|
|
10
9
|
if (typeof configuration !== 'object' || configuration === null) {
|
|
11
10
|
throw new Error('The configuration must be a key-value map.');
|
|
@@ -14,37 +13,34 @@ function validateConfiguration(configuration) {
|
|
|
14
13
|
schema_1.sdkConfigurationSchema.validate(configuration);
|
|
15
14
|
}
|
|
16
15
|
catch (violation) {
|
|
17
|
-
throw new Error(
|
|
16
|
+
throw new Error(`Invalid configuration: ${(0, error_1.formatCause)(violation)}`);
|
|
18
17
|
}
|
|
19
18
|
}
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
class Sdk {
|
|
20
|
+
constructor(container) {
|
|
22
21
|
this.container = container;
|
|
23
22
|
}
|
|
24
|
-
|
|
25
|
-
var
|
|
26
|
-
var _b, _c, _d, _e;
|
|
23
|
+
static init(configuration) {
|
|
24
|
+
var _a, _b, _c, _d, _e;
|
|
27
25
|
validateConfiguration(configuration);
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
const { eventMetadata: customMetadata = {}, ...containerConfiguration } = configuration;
|
|
27
|
+
const eventMetadata = {
|
|
30
28
|
sdkVersion: constants_1.VERSION,
|
|
31
29
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
var metadata = _h.value;
|
|
35
|
-
eventMetadata["custom_".concat(metadata)] = customMetadata[metadata];
|
|
36
|
-
}
|
|
30
|
+
for (const metadata of Object.keys(customMetadata)) {
|
|
31
|
+
eventMetadata[`custom_${metadata}`] = customMetadata[metadata];
|
|
37
32
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
33
|
+
const container = new container_1.Container({
|
|
34
|
+
...containerConfiguration,
|
|
35
|
+
evaluationEndpointUrl: (_a = containerConfiguration.evaluationEndpointUrl) !== null && _a !== void 0 ? _a : constants_1.EVALUATION_ENDPOINT_URL,
|
|
36
|
+
contentEndpointUrl: (_b = containerConfiguration.contentEndpointUrl) !== null && _b !== void 0 ? _b : constants_1.CONTENT_ENDPOINT_URL,
|
|
37
|
+
trackerEndpointUrl: (_c = containerConfiguration.trackerEndpointUrl) !== null && _c !== void 0 ? _c : constants_1.TRACKER_ENDPOINT_URL,
|
|
38
|
+
cidAssignerEndpointUrl: (_d = containerConfiguration.cidAssignerEndpointUrl) !== null && _d !== void 0 ? _d : constants_1.CID_ASSIGNER_ENDPOINT_URL,
|
|
39
|
+
beaconQueueSize: (_e = containerConfiguration.beaconQueueSize) !== null && _e !== void 0 ? _e : 100,
|
|
40
|
+
eventMetadata: eventMetadata,
|
|
41
|
+
});
|
|
42
|
+
const logger = container.getLogger();
|
|
43
|
+
const { appId, tokenScope } = container.getConfiguration();
|
|
48
44
|
logger.debug('\n\n'
|
|
49
45
|
+ ' ██████ ██████ ██████ ██████ ████████ \n'
|
|
50
46
|
+ '██ ██ ██ ██ ██ ██ ██ \n'
|
|
@@ -52,106 +48,64 @@ var Sdk = /** @class */ (function () {
|
|
|
52
48
|
+ '██ ██ ██ ██ ██ ██ ██ \n'
|
|
53
49
|
+ ' ██████ ██ ██ ██████ ██████ ██ \n'
|
|
54
50
|
+ '\n');
|
|
55
|
-
logger.info(
|
|
56
|
-
logger.debug(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
logger.debug(
|
|
61
|
-
logger.debug(
|
|
62
|
-
logger.debug(
|
|
63
|
-
logger.debug(
|
|
51
|
+
logger.info(`Initializing SDK v${constants_1.VERSION}...`);
|
|
52
|
+
logger.debug(`App ID: ${appId}`);
|
|
53
|
+
const context = container.getContext();
|
|
54
|
+
const tab = context.getTab();
|
|
55
|
+
const user = context.getUser();
|
|
56
|
+
logger.debug(`${tab.isNew ? 'New' : 'Current'} tab: ${tab.id}`);
|
|
57
|
+
logger.debug(`Token scope: ${tokenScope}`);
|
|
58
|
+
logger.debug(`Current user: ${user !== null ? user : 'anonymous'}`);
|
|
59
|
+
logger.debug(`Test mode: ${containerConfiguration.test}`);
|
|
64
60
|
logger.info('⚡ Croct SDK is ready!');
|
|
65
61
|
return new Sdk(container);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
enumerable: false,
|
|
108
|
-
configurable: true
|
|
109
|
-
});
|
|
110
|
-
Sdk.prototype.getLogger = function () {
|
|
111
|
-
var _a;
|
|
112
|
-
var namespace = [];
|
|
113
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
114
|
-
namespace[_i] = arguments[_i];
|
|
115
|
-
}
|
|
116
|
-
return (_a = this.container).getLogger.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(namespace), false));
|
|
117
|
-
};
|
|
118
|
-
Sdk.prototype.getTabStorage = function (namespace) {
|
|
119
|
-
var _a;
|
|
120
|
-
var subnamespace = [];
|
|
121
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
122
|
-
subnamespace[_i - 1] = arguments[_i];
|
|
123
|
-
}
|
|
124
|
-
return (_a = this.container).getTabStorage.apply(_a, tslib_1.__spreadArray([namespace], tslib_1.__read(subnamespace), false));
|
|
125
|
-
};
|
|
126
|
-
Sdk.prototype.getBrowserStorage = function (namespace) {
|
|
127
|
-
var _a;
|
|
128
|
-
var subnamespace = [];
|
|
129
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
130
|
-
subnamespace[_i - 1] = arguments[_i];
|
|
62
|
+
}
|
|
63
|
+
get appId() {
|
|
64
|
+
const { appId } = this.container.getConfiguration();
|
|
65
|
+
return appId;
|
|
66
|
+
}
|
|
67
|
+
get cidAssigner() {
|
|
68
|
+
return this.container.getCidAssigner();
|
|
69
|
+
}
|
|
70
|
+
get previewTokenStore() {
|
|
71
|
+
return this.container.getPreviewTokenStore();
|
|
72
|
+
}
|
|
73
|
+
get userTokenStore() {
|
|
74
|
+
return this.container.getUserTokenStore();
|
|
75
|
+
}
|
|
76
|
+
get context() {
|
|
77
|
+
return this.container.getContext();
|
|
78
|
+
}
|
|
79
|
+
get tracker() {
|
|
80
|
+
return this.container.getTracker();
|
|
81
|
+
}
|
|
82
|
+
get evaluator() {
|
|
83
|
+
return this.container.getEvaluator();
|
|
84
|
+
}
|
|
85
|
+
get contentFetcher() {
|
|
86
|
+
return this.container.getContentFetcher();
|
|
87
|
+
}
|
|
88
|
+
get eventManager() {
|
|
89
|
+
return this.container.getEventManager();
|
|
90
|
+
}
|
|
91
|
+
getLogger(...namespace) {
|
|
92
|
+
return this.container.getLogger(...namespace);
|
|
93
|
+
}
|
|
94
|
+
getTabStorage(namespace, ...subnamespace) {
|
|
95
|
+
return this.container.getTabStorage(namespace, ...subnamespace);
|
|
96
|
+
}
|
|
97
|
+
getBrowserStorage(namespace, ...subnamespace) {
|
|
98
|
+
return this.container.getBrowserStorage(namespace, ...subnamespace);
|
|
99
|
+
}
|
|
100
|
+
async close() {
|
|
101
|
+
if (this.closed) {
|
|
102
|
+
return;
|
|
131
103
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
case 0:
|
|
140
|
-
if (this.closed) {
|
|
141
|
-
return [2 /*return*/];
|
|
142
|
-
}
|
|
143
|
-
logger = this.getLogger();
|
|
144
|
-
logger.debug('Closing SDK...');
|
|
145
|
-
this.closed = true;
|
|
146
|
-
return [4 /*yield*/, this.container.dispose()];
|
|
147
|
-
case 1:
|
|
148
|
-
_a.sent();
|
|
149
|
-
logger.info('SDK closed.');
|
|
150
|
-
return [2 /*return*/];
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
};
|
|
155
|
-
return Sdk;
|
|
156
|
-
}());
|
|
104
|
+
const logger = this.getLogger();
|
|
105
|
+
logger.debug('Closing SDK...');
|
|
106
|
+
this.closed = true;
|
|
107
|
+
await this.container.dispose();
|
|
108
|
+
logger.info('SDK closed.');
|
|
109
|
+
}
|
|
110
|
+
}
|
|
157
111
|
exports.Sdk = Sdk;
|
package/sdkEvents.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ export interface TokenChanged {
|
|
|
3
3
|
oldToken: Token | null;
|
|
4
4
|
newToken: Token | null;
|
|
5
5
|
}
|
|
6
|
-
export
|
|
6
|
+
export type SdkEventMap = Record<string, Record<string, unknown>> & {
|
|
7
7
|
tokenChanged: TokenChanged;
|
|
8
8
|
};
|
|
9
|
-
export
|
|
10
|
-
export
|
|
9
|
+
export type SdkEventType = keyof SdkEventMap;
|
|
10
|
+
export type SdkEvent<T extends SdkEventType = SdkEventType> = T extends SdkEventType ? SdkEventMap[T] : SdkEventMap[SdkEventType];
|
package/sourceLocation.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type Position = {
|
|
2
2
|
line: number;
|
|
3
3
|
column: number;
|
|
4
4
|
index: number;
|
|
5
5
|
};
|
|
6
|
-
export
|
|
6
|
+
export type Location = {
|
|
7
7
|
start: Position;
|
|
8
8
|
end: Position;
|
|
9
9
|
};
|
|
10
10
|
export declare function getLength(input: string): number;
|
|
11
|
-
export declare function getPosition(input: string, index: number): Position;
|
|
12
11
|
export declare function getLocation(input: string, startIndex: number, endIndex: number): Location;
|
|
12
|
+
export declare function getPosition(input: string, index: number): Position;
|
package/sourceLocation.js
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
3
|
+
exports.getPosition = exports.getLocation = exports.getLength = void 0;
|
|
5
4
|
function getLength(input) {
|
|
6
|
-
return
|
|
5
|
+
return [...input].length;
|
|
7
6
|
}
|
|
8
7
|
exports.getLength = getLength;
|
|
9
|
-
function getPosition(input, index) {
|
|
10
|
-
return getLocation(input, index, index).start;
|
|
11
|
-
}
|
|
12
|
-
exports.getPosition = getPosition;
|
|
13
8
|
function getLocation(input, startIndex, endIndex) {
|
|
14
9
|
if (startIndex < 0) {
|
|
15
10
|
throw Error('The start index cannot be negative.');
|
|
@@ -17,13 +12,13 @@ function getLocation(input, startIndex, endIndex) {
|
|
|
17
12
|
if (endIndex < startIndex) {
|
|
18
13
|
throw new Error('The end index must greater than or equal to the start index.');
|
|
19
14
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
for (
|
|
26
|
-
|
|
15
|
+
let start;
|
|
16
|
+
let end;
|
|
17
|
+
const chars = [...input];
|
|
18
|
+
let line = 1;
|
|
19
|
+
let column = 0;
|
|
20
|
+
for (let offset = 0; offset < chars.length; offset++) {
|
|
21
|
+
const char = chars[offset];
|
|
27
22
|
if (offset === startIndex) {
|
|
28
23
|
start = {
|
|
29
24
|
index: offset,
|
|
@@ -67,3 +62,7 @@ function getLocation(input, startIndex, endIndex) {
|
|
|
67
62
|
};
|
|
68
63
|
}
|
|
69
64
|
exports.getLocation = getLocation;
|
|
65
|
+
function getPosition(input, index) {
|
|
66
|
+
return getLocation(input, index, index).start;
|
|
67
|
+
}
|
|
68
|
+
exports.getPosition = getPosition;
|
package/tab.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { EventListener } from './eventManager';
|
|
2
|
-
export
|
|
2
|
+
export type TabEvent<T = Record<string, unknown>> = CustomEvent<{
|
|
3
3
|
tab: Tab;
|
|
4
4
|
} & T>;
|
|
5
|
-
export
|
|
5
|
+
export type TabVisibilityChangeEvent = TabEvent<{
|
|
6
6
|
visible: boolean;
|
|
7
7
|
}>;
|
|
8
|
-
export
|
|
8
|
+
export type TabUrlChangeEvent = TabEvent<{
|
|
9
9
|
url: string;
|
|
10
10
|
}>;
|
|
11
|
-
export
|
|
12
|
-
|
|
11
|
+
export type UrlSanitizer = (url: string) => URL;
|
|
12
|
+
type TabEventMap = {
|
|
13
13
|
focus: TabEvent;
|
|
14
14
|
blur: TabEvent;
|
|
15
15
|
load: TabEvent;
|
package/tab.js
CHANGED
|
@@ -1,125 +1,95 @@
|
|
|
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;
|
|
@@ -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,13 @@ 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;
|
|
@@ -1,16 +1,15 @@
|
|
|
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;
|