@croct/sdk 0.17.10 → 0.17.11

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.
Files changed (108) hide show
  1. package/constants.cjs +1 -1
  2. package/constants.cjs.map +1 -1
  3. package/constants.d.ts +2 -2
  4. package/constants.js +1 -1
  5. package/constants.js.map +1 -1
  6. package/package.json +1 -1
  7. package/src/activeRecord.ts +0 -150
  8. package/src/apiKey.ts +0 -208
  9. package/src/base64Url.ts +0 -22
  10. package/src/cache/cache.ts +0 -22
  11. package/src/cache/cookieCache.ts +0 -88
  12. package/src/cache/fallbackCache.ts +0 -29
  13. package/src/cache/inMemoryCache.ts +0 -21
  14. package/src/cache/index.ts +0 -4
  15. package/src/cache/localStorageCache.ts +0 -85
  16. package/src/channel/channel.ts +0 -52
  17. package/src/channel/encodedChannel.ts +0 -21
  18. package/src/channel/guaranteedChannel.ts +0 -131
  19. package/src/channel/httpBeaconChannel.ts +0 -128
  20. package/src/channel/index.ts +0 -7
  21. package/src/channel/queuedChannel.ts +0 -143
  22. package/src/channel/retryChannel.ts +0 -94
  23. package/src/channel/sandboxChannel.ts +0 -47
  24. package/src/cid/assigner.ts +0 -3
  25. package/src/cid/cachedAssigner.ts +0 -68
  26. package/src/cid/fixedAssigner.ts +0 -13
  27. package/src/cid/index.ts +0 -4
  28. package/src/cid/remoteAssigner.ts +0 -57
  29. package/src/constants.ts +0 -4
  30. package/src/container.ts +0 -410
  31. package/src/contentFetcher.ts +0 -290
  32. package/src/context.ts +0 -139
  33. package/src/error.ts +0 -31
  34. package/src/evaluator.ts +0 -314
  35. package/src/eventManager.ts +0 -53
  36. package/src/eventSubjectProcessor.ts +0 -85
  37. package/src/facade/contentFetcherFacade.ts +0 -69
  38. package/src/facade/evaluatorFacade.ts +0 -111
  39. package/src/facade/index.ts +0 -7
  40. package/src/facade/sdkFacade.ts +0 -310
  41. package/src/facade/sessionFacade.ts +0 -14
  42. package/src/facade/sessionPatch.ts +0 -32
  43. package/src/facade/trackerFacade.ts +0 -98
  44. package/src/facade/userFacade.ts +0 -26
  45. package/src/facade/userPatch.ts +0 -32
  46. package/src/help.ts +0 -24
  47. package/src/index.ts +0 -4
  48. package/src/logging/consoleLogger.ts +0 -38
  49. package/src/logging/filteredLogger.ts +0 -57
  50. package/src/logging/index.ts +0 -5
  51. package/src/logging/logger.ts +0 -13
  52. package/src/logging/namespacedLogger.ts +0 -32
  53. package/src/logging/nullLogger.ts +0 -19
  54. package/src/namespacedStorage.ts +0 -69
  55. package/src/patch.ts +0 -64
  56. package/src/queue/capacityRestrictedQueue.ts +0 -44
  57. package/src/queue/inMemoryQueue.ts +0 -43
  58. package/src/queue/index.ts +0 -5
  59. package/src/queue/monitoredQueue.ts +0 -168
  60. package/src/queue/persistentQueue.ts +0 -73
  61. package/src/queue/queue.ts +0 -15
  62. package/src/retry/arbitraryPolicy.ts +0 -21
  63. package/src/retry/backoffPolicy.ts +0 -84
  64. package/src/retry/index.ts +0 -5
  65. package/src/retry/maxAttemptsPolicy.ts +0 -28
  66. package/src/retry/neverPolicy.ts +0 -11
  67. package/src/retry/policy.ts +0 -5
  68. package/src/schema/attributeSchema.ts +0 -6
  69. package/src/schema/contentFetcherSchemas.ts +0 -23
  70. package/src/schema/contentSchemas.ts +0 -44
  71. package/src/schema/contextSchemas.ts +0 -5
  72. package/src/schema/ecommerceSchemas.ts +0 -179
  73. package/src/schema/evaluatorSchemas.ts +0 -52
  74. package/src/schema/eventSchemas.ts +0 -134
  75. package/src/schema/index.ts +0 -11
  76. package/src/schema/loggerSchema.ts +0 -12
  77. package/src/schema/operationSchemas.ts +0 -102
  78. package/src/schema/sdkFacadeSchemas.ts +0 -64
  79. package/src/schema/sdkSchemas.ts +0 -82
  80. package/src/schema/tokenSchema.ts +0 -42
  81. package/src/schema/userSchema.ts +0 -184
  82. package/src/sdk.ts +0 -183
  83. package/src/sdkEvents.ts +0 -15
  84. package/src/sourceLocation.ts +0 -85
  85. package/src/tab.ts +0 -148
  86. package/src/token/cachedTokenStore.ts +0 -34
  87. package/src/token/inMemoryTokenStore.ts +0 -13
  88. package/src/token/index.ts +0 -4
  89. package/src/token/replicatedTokenStore.ts +0 -21
  90. package/src/token/token.ts +0 -301
  91. package/src/tracker.ts +0 -504
  92. package/src/trackingEvents.ts +0 -452
  93. package/src/transformer.ts +0 -7
  94. package/src/utilityTypes.ts +0 -3
  95. package/src/uuid.ts +0 -43
  96. package/src/validation/arrayType.ts +0 -71
  97. package/src/validation/booleanType.ts +0 -22
  98. package/src/validation/functionType.ts +0 -22
  99. package/src/validation/index.ts +0 -12
  100. package/src/validation/jsonType.ts +0 -156
  101. package/src/validation/mixedSchema.ts +0 -7
  102. package/src/validation/nullType.ts +0 -22
  103. package/src/validation/numberType.ts +0 -59
  104. package/src/validation/objectType.ts +0 -138
  105. package/src/validation/schema.ts +0 -21
  106. package/src/validation/stringType.ts +0 -118
  107. package/src/validation/unionType.ts +0 -53
  108. package/src/validation/violation.ts +0 -23
@@ -1,42 +0,0 @@
1
- import {ObjectType, StringType, NumberType, UnionType, ArrayType} from '../validation';
2
-
3
- export const tokenSchema = new ObjectType({
4
- required: ['headers', 'payload'],
5
- properties: {
6
- headers: new ObjectType({
7
- required: ['typ', 'alg'],
8
- properties: {
9
- typ: new StringType(),
10
- alg: new StringType(),
11
- kid: new StringType(),
12
- appId: new StringType({
13
- format: 'uuid',
14
- }),
15
- },
16
- }),
17
- payload: new ObjectType({
18
- required: ['iss', 'aud', 'iat'],
19
- properties: {
20
- iss: new StringType(),
21
- aud: new UnionType(
22
- new StringType(),
23
- new ArrayType({items: new StringType()}),
24
- ),
25
- iat: new NumberType({
26
- minimum: 0,
27
- }),
28
- sub: new StringType({
29
- minLength: 1,
30
- }),
31
- exp: new NumberType({
32
- minimum: 0,
33
- }),
34
- jti: new StringType({
35
- format: 'uuid',
36
- }),
37
- },
38
- additionalProperties: true,
39
- }),
40
- signature: new StringType(),
41
- },
42
- });
@@ -1,184 +0,0 @@
1
- import {
2
- StringType,
3
- ObjectType,
4
- UnionType,
5
- BooleanType,
6
- NullType,
7
- NumberType,
8
- ArrayType,
9
- } from '../validation';
10
- import {attributeNameSchema} from './attributeSchema';
11
-
12
- export const userProfileSchema = new ObjectType({
13
- properties: {
14
- firstName: new StringType({
15
- minLength: 1,
16
- maxLength: 50,
17
- }),
18
- lastName: new StringType({
19
- minLength: 1,
20
- maxLength: 50,
21
- }),
22
- birthDate: new StringType({
23
- format: 'date',
24
- }),
25
- gender: new StringType({
26
- enumeration: ['male', 'female', 'neutral', 'unknown'],
27
- }),
28
- email: new StringType({
29
- minLength: 1,
30
- maxLength: 254,
31
- }),
32
- alternateEmail: new StringType({
33
- minLength: 1,
34
- maxLength: 254,
35
- }),
36
- phone: new StringType({
37
- minLength: 1,
38
- maxLength: 30,
39
- }),
40
- alternatePhone: new StringType({
41
- minLength: 1,
42
- maxLength: 30,
43
- }),
44
- address: new ObjectType({
45
- properties: {
46
- street: new StringType({
47
- minLength: 1,
48
- maxLength: 100,
49
- }),
50
- district: new StringType({
51
- minLength: 1,
52
- maxLength: 100,
53
- }),
54
- city: new StringType({
55
- minLength: 1,
56
- maxLength: 100,
57
- }),
58
- region: new StringType({
59
- minLength: 1,
60
- maxLength: 100,
61
- }),
62
- country: new StringType({
63
- minLength: 1,
64
- maxLength: 100,
65
- }),
66
- postalCode: new StringType({
67
- minLength: 1,
68
- maxLength: 20,
69
- }),
70
- },
71
- }),
72
- avatar: new StringType({
73
- maxLength: 500,
74
- format: 'url',
75
- }),
76
- company: new StringType({
77
- minLength: 1,
78
- maxLength: 200,
79
- }),
80
- companyUrl: new StringType({
81
- maxLength: 200,
82
- format: 'url',
83
- }),
84
- jobTitle: new StringType({
85
- minLength: 1,
86
- maxLength: 50,
87
- }),
88
- interests: new ArrayType({
89
- maxItems: 30,
90
- items: new StringType({
91
- minLength: 1,
92
- maxLength: 30,
93
- }),
94
- }),
95
- activities: new ArrayType({
96
- maxItems: 30,
97
- items: new StringType({
98
- minLength: 1,
99
- maxLength: 30,
100
- }),
101
- }),
102
- custom: new ObjectType({
103
- propertyNames: attributeNameSchema,
104
- maxProperties: 10,
105
- additionalProperties: new UnionType(
106
- new BooleanType(),
107
- new NullType(),
108
- new NumberType(),
109
- new StringType({
110
- maxLength: 100,
111
- }),
112
- new ArrayType({
113
- maxItems: 10,
114
- items: new UnionType(
115
- new BooleanType(),
116
- new NullType(),
117
- new NumberType(),
118
- new StringType({
119
- maxLength: 100,
120
- }),
121
- new ArrayType({
122
- maxItems: 10,
123
- items: new UnionType(
124
- new BooleanType(),
125
- new NullType(),
126
- new NumberType(),
127
- new StringType({
128
- maxLength: 100,
129
- }),
130
- ),
131
- }),
132
- new ObjectType({
133
- propertyNames: attributeNameSchema,
134
- maxProperties: 10,
135
- additionalProperties: new UnionType(
136
- new BooleanType(),
137
- new NullType(),
138
- new NumberType(),
139
- new StringType({
140
- maxLength: 100,
141
- }),
142
- ),
143
- }),
144
- ),
145
- }),
146
- new ObjectType({
147
- propertyNames: attributeNameSchema,
148
- maxProperties: 10,
149
- additionalProperties: new UnionType(
150
- new BooleanType(),
151
- new NullType(),
152
- new NumberType(),
153
- new StringType({
154
- maxLength: 100,
155
- }),
156
- new ArrayType({
157
- maxItems: 10,
158
- items: new UnionType(
159
- new BooleanType(),
160
- new NullType(),
161
- new NumberType(),
162
- new StringType({
163
- maxLength: 100,
164
- }),
165
- ),
166
- }),
167
- new ObjectType({
168
- propertyNames: attributeNameSchema,
169
- maxProperties: 10,
170
- additionalProperties: new UnionType(
171
- new BooleanType(),
172
- new NullType(),
173
- new NumberType(),
174
- new StringType({
175
- maxLength: 100,
176
- }),
177
- ),
178
- }),
179
- ),
180
- }),
181
- ),
182
- }),
183
- },
184
- });
package/src/sdk.ts DELETED
@@ -1,183 +0,0 @@
1
- import {Container, DependencyResolver} from './container';
2
- import {Context, TokenScope} from './context';
3
- import {Logger} from './logging';
4
- import {BASE_ENDPOINT_URL, VERSION} from './constants';
5
- import {sdkConfigurationSchema} from './schema';
6
- import {formatCause} from './error';
7
- import {Tracker, TrackingEventProcessor} from './tracker';
8
- import {Evaluator} from './evaluator';
9
- import {SdkEventMap} from './sdkEvents';
10
- import {EventManager} from './eventManager';
11
- import {CidAssigner} from './cid';
12
- import {UrlSanitizer} from './tab';
13
- import {ContentFetcher} from './contentFetcher';
14
- import {TokenStore} from './token';
15
- import {CookieCacheConfiguration} from './cache/cookieCache';
16
-
17
- export type Configuration = {
18
- appId: string,
19
- tokenScope: TokenScope,
20
- debug: boolean,
21
- test: boolean,
22
- clientId?: string,
23
- baseEndpointUrl?: string,
24
- disableCidMirroring: boolean,
25
- cidAssignerEndpointUrl?: string,
26
- beaconQueueSize?: number,
27
- urlSanitizer?: UrlSanitizer,
28
- logger?: Logger,
29
- eventMetadata?: {[key: string]: string},
30
- cookie?: {
31
- clientId?: CookieCacheConfiguration,
32
- userToken?: CookieCacheConfiguration,
33
- previewToken?: CookieCacheConfiguration,
34
- },
35
- eventProcessor?: DependencyResolver<TrackingEventProcessor>,
36
- defaultFetchTimeout?: number,
37
- defaultPreferredLocale?: string,
38
- };
39
-
40
- function validateConfiguration(configuration: unknown): asserts configuration is Configuration {
41
- if (typeof configuration !== 'object' || configuration === null) {
42
- throw new Error('The configuration must be a key-value map.');
43
- }
44
-
45
- try {
46
- sdkConfigurationSchema.validate(configuration);
47
- } catch (violation) {
48
- throw new Error(`Invalid configuration: ${formatCause(violation)}`);
49
- }
50
- }
51
-
52
- export class Sdk {
53
- private container: Container;
54
-
55
- private closed: boolean;
56
-
57
- private constructor(container: Container) {
58
- this.container = container;
59
- }
60
-
61
- public static init(configuration: Configuration): Sdk {
62
- validateConfiguration(configuration);
63
-
64
- const {
65
- eventMetadata: customMetadata = {},
66
- baseEndpointUrl = BASE_ENDPOINT_URL,
67
- cidAssignerEndpointUrl,
68
- ...containerConfiguration
69
- } = configuration;
70
-
71
- const eventMetadata: {[key: string]: string} = {
72
- sdkVersion: VERSION,
73
- };
74
-
75
- for (const metadata of Object.keys(customMetadata)) {
76
- eventMetadata[`custom_${metadata}`] = customMetadata[metadata];
77
- }
78
-
79
- const baseHttpEndpoint = baseEndpointUrl.replace(/\/+$/, '');
80
-
81
- const container = new Container({
82
- ...containerConfiguration,
83
- evaluationBaseEndpointUrl: baseHttpEndpoint,
84
- contentBaseEndpointUrl: baseHttpEndpoint,
85
- trackerEndpointUrl: `${baseHttpEndpoint}/client/web/track`,
86
- cidAssignerEndpointUrl: cidAssignerEndpointUrl ?? `${baseHttpEndpoint}/client/web/cid`,
87
- beaconQueueSize: containerConfiguration.beaconQueueSize ?? 100,
88
- eventMetadata: eventMetadata,
89
- });
90
-
91
- const logger = container.getLogger();
92
- const {appId, tokenScope} = container.getConfiguration();
93
-
94
- logger.debug(
95
- '\n\n'
96
- + ' ██████ ██████  ██████  ██████ ████████ \n'
97
- + '██      ██   ██ ██    ██ ██         ██    \n'
98
- + '██  ██████  ██  ██ ██  ██    \n'
99
- + '██  ██   ██ ██  ██ ██  ██    \n'
100
- + ' ██████ ██  ██  ██████   ██████  ██    \n'
101
- + '\n',
102
- );
103
-
104
- logger.info(`Initializing SDK v${VERSION}...`);
105
- logger.debug(`App ID: ${appId}`);
106
-
107
- const context = container.getContext();
108
- const tab = context.getTab();
109
- const user = context.getUser();
110
-
111
- logger.debug(`${tab.isNew ? 'New' : 'Current'} tab: ${tab.id}`);
112
- logger.debug(`Token scope: ${tokenScope}`);
113
- logger.debug(`Current user: ${user !== null ? user : 'anonymous'}`);
114
- logger.debug(`Test mode: ${containerConfiguration.test}`);
115
- logger.info('⚡ Croct SDK is ready!');
116
-
117
- return new Sdk(container);
118
- }
119
-
120
- public get appId(): string {
121
- const {appId} = this.container.getConfiguration();
122
-
123
- return appId;
124
- }
125
-
126
- public get cidAssigner(): CidAssigner {
127
- return this.container.getCidAssigner();
128
- }
129
-
130
- public get previewTokenStore(): TokenStore {
131
- return this.container.getPreviewTokenStore();
132
- }
133
-
134
- public get userTokenStore(): TokenStore {
135
- return this.container.getUserTokenStore();
136
- }
137
-
138
- public get context(): Context {
139
- return this.container.getContext();
140
- }
141
-
142
- public get tracker(): Tracker {
143
- return this.container.getTracker();
144
- }
145
-
146
- public get evaluator(): Evaluator {
147
- return this.container.getEvaluator();
148
- }
149
-
150
- public get contentFetcher(): ContentFetcher {
151
- return this.container.getContentFetcher();
152
- }
153
-
154
- public get eventManager(): EventManager<SdkEventMap> {
155
- return this.container.getEventManager();
156
- }
157
-
158
- public getLogger(...namespace: string[]): Logger {
159
- return this.container.getLogger(...namespace);
160
- }
161
-
162
- public getTabStorage(namespace: string, ...subnamespace: string[]): Storage {
163
- return this.container.getTabStorage(namespace, ...subnamespace);
164
- }
165
-
166
- public getBrowserStorage(namespace: string, ...subnamespace: string[]): Storage {
167
- return this.container.getBrowserStorage(namespace, ...subnamespace);
168
- }
169
-
170
- public async close(): Promise<void> {
171
- if (this.closed) {
172
- return;
173
- }
174
-
175
- const logger = this.getLogger();
176
-
177
- logger.debug('Closing SDK...');
178
- this.closed = true;
179
- await this.container.dispose();
180
-
181
- logger.info('SDK closed.');
182
- }
183
- }
package/src/sdkEvents.ts DELETED
@@ -1,15 +0,0 @@
1
- import {Token} from './token';
2
-
3
- export interface TokenChanged {
4
- oldToken: Token|null;
5
- newToken: Token|null;
6
- }
7
-
8
- export type SdkEventMap = Record<string, Record<string, unknown>> & {
9
- tokenChanged: TokenChanged,
10
- };
11
-
12
- export type SdkEventType = keyof SdkEventMap;
13
-
14
- export type SdkEvent<T extends SdkEventType = SdkEventType> =
15
- T extends SdkEventType ? SdkEventMap[T] : SdkEventMap[SdkEventType];
@@ -1,85 +0,0 @@
1
- export type Position = {
2
- line: number,
3
- column: number,
4
- index: number,
5
- };
6
-
7
- export type Location = {
8
- start: Position,
9
- end: Position,
10
- };
11
-
12
- export function getLength(input: string): number {
13
- return [...input].length;
14
- }
15
-
16
- export function getLocation(input: string, startIndex: number, endIndex: number): Location {
17
- if (startIndex < 0) {
18
- throw Error('The start index cannot be negative.');
19
- }
20
-
21
- if (endIndex < startIndex) {
22
- throw new Error('The end index must greater than or equal to the start index.');
23
- }
24
-
25
- let start: Position | undefined;
26
- let end: Position | undefined;
27
-
28
- const chars = [...input];
29
- let line = 1;
30
- let column = 0;
31
-
32
- for (let offset = 0; offset < chars.length; offset++) {
33
- const char = chars[offset];
34
-
35
- if (offset === startIndex) {
36
- start = {
37
- index: offset,
38
- line: line,
39
- column: column,
40
- };
41
- }
42
-
43
- if (offset === endIndex) {
44
- end = {
45
- index: offset,
46
- line: line,
47
- column: column,
48
- };
49
-
50
- break;
51
- }
52
-
53
- if (char === '\n') {
54
- line += 1;
55
- column = 0;
56
- } else {
57
- column += 1;
58
- }
59
- }
60
-
61
- if (start === undefined) {
62
- start = {
63
- index: chars.length,
64
- line: line,
65
- column: column,
66
- };
67
- }
68
-
69
- if (end === undefined) {
70
- end = {
71
- index: chars.length,
72
- line: line,
73
- column: column,
74
- };
75
- }
76
-
77
- return {
78
- start: start,
79
- end: end,
80
- };
81
- }
82
-
83
- export function getPosition(input: string, index: number): Position {
84
- return getLocation(input, index, index).start;
85
- }
package/src/tab.ts DELETED
@@ -1,148 +0,0 @@
1
- import {SynchronousEventManager, EventListener} from './eventManager';
2
-
3
- export type TabEvent<T = Record<string, unknown>> = CustomEvent<{tab: Tab} & T>;
4
- export type TabVisibilityChangeEvent = TabEvent<{visible: boolean}>;
5
- export type TabUrlChangeEvent = TabEvent<{url: string}>;
6
-
7
- export type UrlSanitizer = (url: string) => URL;
8
-
9
- type TabEventMap = {
10
- focus: TabEvent,
11
- blur: TabEvent,
12
- load: TabEvent,
13
- unload: TabEvent,
14
- visibilityChange: TabVisibilityChangeEvent,
15
- urlChange: TabUrlChangeEvent,
16
- };
17
-
18
- const EventMap: {[key: string]: keyof TabEventMap} = {
19
- focus: 'focus',
20
- blur: 'blur',
21
- beforeunload: 'unload',
22
- DOMContentLoaded: 'load',
23
- visibilitychange: 'visibilityChange',
24
- };
25
-
26
- export class Tab {
27
- public readonly id: string;
28
-
29
- public readonly isNew: boolean;
30
-
31
- public readonly urlSanitizer?: UrlSanitizer;
32
-
33
- private readonly eventManager = new SynchronousEventManager<TabEventMap>();
34
-
35
- public constructor(id: string, isNew: boolean, urlSanitizer?: UrlSanitizer) {
36
- this.id = id;
37
- this.isNew = isNew;
38
- this.urlSanitizer = urlSanitizer;
39
-
40
- this.initialize();
41
- }
42
-
43
- private initialize(): void {
44
- const listener = (event: Event): void => {
45
- this.emit(EventMap[event.type], new CustomEvent(EventMap[event.type], {detail: {tab: this}}));
46
- };
47
-
48
- window.addEventListener('focus', listener, true);
49
- window.addEventListener('blur', listener, true);
50
- window.addEventListener('beforeunload', listener, true);
51
- window.addEventListener('DOMContentLoaded', listener, true);
52
-
53
- document.addEventListener(
54
- 'visibilitychange',
55
- () => {
56
- this.emit('visibilityChange', new CustomEvent('visibilityChange', {
57
- detail: {
58
- tab: this,
59
- visible: this.isVisible,
60
- },
61
- }));
62
- },
63
- true,
64
- );
65
-
66
- Tab.addUrlChangeListener(url => {
67
- this.emit('urlChange', new CustomEvent('urlChange', {detail: {tab: this, url: this.sanitizeUrl(url)}}));
68
- });
69
- }
70
-
71
- public get url(): string {
72
- return this.sanitizeUrl(window.location.href);
73
- }
74
-
75
- public get title(): string {
76
- return document.title;
77
- }
78
-
79
- public get referrer(): string {
80
- return document.referrer === '' ? '' : this.sanitizeUrl(document.referrer);
81
- }
82
-
83
- public get isVisible(): boolean {
84
- return document.visibilityState === 'visible';
85
- }
86
-
87
- public get document(): Document {
88
- return document;
89
- }
90
-
91
- public addListener<T extends keyof TabEventMap>(type: T, listener: EventListener<TabEventMap[T]>): void {
92
- this.eventManager.addListener(type, listener);
93
- }
94
-
95
- public removeListener<T extends keyof TabEventMap>(type: T, listener: EventListener<TabEventMap[T]>): void {
96
- this.eventManager.removeListener(type, listener);
97
- }
98
-
99
- private sanitizeUrl(url: string): string {
100
- const normalized = window.encodeURI(window.decodeURI(url));
101
-
102
- if (this.urlSanitizer !== undefined) {
103
- return this.urlSanitizer(normalized).toString();
104
- }
105
-
106
- return normalized;
107
- }
108
-
109
- private emit<T extends keyof TabEventMap>(type: T, event: TabEventMap[T]): void {
110
- this.eventManager.dispatch(type, event);
111
- }
112
-
113
- private static addUrlChangeListener(listener: {(url: string): void}): void {
114
- let url = window.location.href;
115
-
116
- const updateUrl = (): void => {
117
- const currentUrl = window.location.href;
118
-
119
- if (url !== currentUrl) {
120
- listener(currentUrl);
121
-
122
- url = currentUrl;
123
- }
124
- };
125
-
126
- const {pushState} = window.history;
127
-
128
- window.history.pushState = function interceptPushState(...args): any {
129
- const result = pushState.apply(window.history, args);
130
-
131
- updateUrl();
132
-
133
- return result;
134
- };
135
-
136
- const {replaceState} = window.history;
137
-
138
- window.history.replaceState = function interceptReplaceState(...args): any {
139
- const result = replaceState.apply(window.history, args);
140
-
141
- updateUrl();
142
-
143
- return result;
144
- };
145
-
146
- window.addEventListener('popstate', updateUrl, true);
147
- }
148
- }
@@ -1,34 +0,0 @@
1
- import {Token, TokenStore} from './token';
2
- import {Cache} from '../cache';
3
-
4
- export class CachedTokenStore implements TokenStore {
5
- private readonly cache: Cache;
6
-
7
- public constructor(cache: Cache) {
8
- this.cache = cache;
9
- }
10
-
11
- public getToken(): Token | null {
12
- const data: string | null = this.cache.get();
13
-
14
- if (data === null) {
15
- return null;
16
- }
17
-
18
- try {
19
- return Token.parse(data);
20
- } catch (error) {
21
- return null;
22
- }
23
- }
24
-
25
- public setToken(token: Token | null): void {
26
- if (token === null) {
27
- this.cache.clear();
28
-
29
- return;
30
- }
31
-
32
- this.cache.put(token.toString());
33
- }
34
- }
@@ -1,13 +0,0 @@
1
- import {Token, TokenStore} from './token';
2
-
3
- export class InMemoryTokenStore implements TokenStore {
4
- private token: Token | null = null;
5
-
6
- public getToken(): Token | null {
7
- return this.token;
8
- }
9
-
10
- public setToken(token: Token | null): void {
11
- this.token = token;
12
- }
13
- }