@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,4 +0,0 @@
1
- export * from './token';
2
- export {CachedTokenStore} from './cachedTokenStore';
3
- export {InMemoryTokenStore} from './inMemoryTokenStore';
4
- export {ReplicatedTokenStore} from './replicatedTokenStore';
@@ -1,21 +0,0 @@
1
- import {Token, TokenStore} from './token';
2
-
3
- export class ReplicatedTokenStore implements TokenStore {
4
- private primary: TokenStore;
5
-
6
- private secondary: TokenStore;
7
-
8
- public constructor(primary: TokenStore, secondary: TokenStore) {
9
- this.primary = primary;
10
- this.secondary = secondary;
11
- }
12
-
13
- public getToken(): Token | null {
14
- return this.primary.getToken();
15
- }
16
-
17
- public setToken(token: Token | null): void {
18
- this.primary.setToken(token);
19
- this.secondary.setToken(token);
20
- }
21
- }
@@ -1,301 +0,0 @@
1
- import {JsonObject} from '@croct/json';
2
- import {tokenSchema} from '../schema';
3
- import {formatCause} from '../error';
4
- import {ApiKey} from '../apiKey';
5
- import {base64UrlDecode, base64UrlEncode} from '../base64Url';
6
-
7
- export type TokenHeaders = {
8
- typ: string,
9
- alg: string,
10
- kid?: string,
11
- appId?: string,
12
- };
13
-
14
- export type TokenClaims = {
15
- iss: string,
16
- aud: string|string[],
17
- iat: number,
18
- exp?: number,
19
- sub?: string,
20
- jti?: string,
21
- };
22
-
23
- export type TokenPayload = JsonObject & TokenClaims;
24
-
25
- export class Token {
26
- private static readonly UUID_PATTERN = /^[a-f0-9]{8}-([a-f0-9]{4}-){3}[a-f0-9]{12}$/;
27
-
28
- private readonly headers: TokenHeaders;
29
-
30
- private readonly payload: TokenPayload;
31
-
32
- private readonly signature: string;
33
-
34
- private constructor(headers: TokenHeaders, payload: TokenPayload, signature = '') {
35
- this.headers = headers;
36
- this.payload = payload;
37
- this.signature = signature;
38
- }
39
-
40
- public static issue(
41
- appId: string,
42
- subject: string|null = null,
43
- timestamp: number = Math.floor(Date.now() / 1000),
44
- ): Token {
45
- if (timestamp < 0) {
46
- throw new Error('The timestamp must be non-negative.');
47
- }
48
-
49
- if (subject === '') {
50
- throw new Error('The subject must be non-empty.');
51
- }
52
-
53
- return new Token(
54
- {
55
- typ: 'JWT',
56
- alg: 'none',
57
- appId: appId,
58
- },
59
- {
60
- iss: 'croct.io',
61
- aud: 'croct.io',
62
- iat: timestamp,
63
- ...(subject !== null ? {sub: subject} : null),
64
- },
65
- );
66
- }
67
-
68
- public static parse(token: string): Token {
69
- if (token === '') {
70
- throw new Error('The token cannot be empty.');
71
- }
72
-
73
- const parts = token.split('.', 3);
74
-
75
- // This token is invalid
76
- if (parts.length < 2) {
77
- throw new Error('The token is malformed.');
78
- }
79
-
80
- let headers;
81
- let payload;
82
-
83
- try {
84
- headers = JSON.parse(base64UrlDecode(parts[0], true));
85
- payload = JSON.parse(base64UrlDecode(parts[1], true));
86
- } catch (error) {
87
- throw new Error('The token is corrupted.');
88
- }
89
-
90
- return Token.of(headers, payload, parts[2]);
91
- }
92
-
93
- public static of(headers: TokenHeaders, payload: TokenPayload, signature = ''): Token {
94
- try {
95
- tokenSchema.validate({
96
- headers: headers,
97
- payload: payload,
98
- signature: signature,
99
- });
100
- } catch (violation) {
101
- throw new Error(`The token is invalid: ${formatCause(violation)}`);
102
- }
103
-
104
- return new Token(headers as TokenHeaders, payload as TokenPayload, signature as string);
105
- }
106
-
107
- public async signedWith(apiKey: ApiKey): Promise<Token> {
108
- const keyId = await apiKey.getIdentifierHash();
109
- const headers: TokenHeaders = {
110
- ...this.headers,
111
- kid: keyId,
112
- alg: apiKey.getSigningAlgorithm(),
113
- };
114
-
115
- const encodedHeader = base64UrlEncode(JSON.stringify(headers), true);
116
- const encodedPayload = base64UrlEncode(JSON.stringify(this.payload), true);
117
- const signature = await apiKey.sign(`${encodedHeader}.${encodedPayload}`);
118
-
119
- return new Token(headers, this.payload, base64UrlEncode(signature, false));
120
- }
121
-
122
- public isSigned(): boolean {
123
- return this.headers.alg !== 'none' && this.signature !== '';
124
- }
125
-
126
- public isSubject(subject: string): boolean {
127
- return this.getSubject() === subject;
128
- }
129
-
130
- public isAnonymous(): boolean {
131
- return this.payload.sub === undefined;
132
- }
133
-
134
- public isValidNow(now: number = Math.floor(Date.now() / 1000)): boolean {
135
- const {exp, iat} = this.payload;
136
-
137
- return (exp === undefined || exp >= now) && iat <= now;
138
- }
139
-
140
- public isNewerThan(token: Token): boolean {
141
- return this.payload.iat > token.payload.iat;
142
- }
143
-
144
- public async matchesKeyId(apiKey: ApiKey): Promise<boolean> {
145
- return this.headers.kid === await apiKey.getIdentifierHash();
146
- }
147
-
148
- public getHeaders(): TokenHeaders {
149
- return {...this.headers};
150
- }
151
-
152
- public getPayload(): TokenPayload {
153
- return {...this.payload};
154
- }
155
-
156
- public getSignature(): string {
157
- return this.signature;
158
- }
159
-
160
- public getApplicationId(): string | null {
161
- return this.headers.appId ?? null;
162
- }
163
-
164
- public getAlgorithm(): string {
165
- return this.headers.alg;
166
- }
167
-
168
- public getType(): string {
169
- return this.headers.typ;
170
- }
171
-
172
- public getKeyId(): string | null {
173
- return this.headers.kid ?? null;
174
- }
175
-
176
- public getSubject(): string | null {
177
- return this.payload.sub ?? null;
178
- }
179
-
180
- public getIssueTime(): number {
181
- return this.payload.iat;
182
- }
183
-
184
- public getExpirationTime(): number | null {
185
- return this.payload.exp ?? null;
186
- }
187
-
188
- public getTokenId(): string | null {
189
- return this.payload.jti ?? null;
190
- }
191
-
192
- public getAudience(): string | string[] {
193
- return this.payload.aud;
194
- }
195
-
196
- public getIssuer(): string {
197
- return this.payload.iss;
198
- }
199
-
200
- public withTokenId(tokenId: string): Token {
201
- if (tokenId === '' || !Token.UUID_PATTERN.test(tokenId)) {
202
- throw new Error('The token ID must be a valid UUID.');
203
- }
204
-
205
- return new Token(
206
- this.headers,
207
- {
208
- ...this.payload,
209
- jti: tokenId,
210
- },
211
- this.signature,
212
- );
213
- }
214
-
215
- public withDuration(duration: number, now: number = Math.floor(Date.now() / 1000)): Token {
216
- return new Token(
217
- this.headers,
218
- {
219
- ...this.payload,
220
- iat: now,
221
- exp: now + duration,
222
- },
223
- this.signature,
224
- );
225
- }
226
-
227
- public withAddedHeaders(headers: Partial<TokenHeaders>): Token {
228
- return this.withHeaders({
229
- ...this.headers,
230
- ...Object.fromEntries(
231
- Object.entries(headers)
232
- .filter(([, value]) => value !== undefined),
233
- ),
234
- });
235
- }
236
-
237
- public withAddedClaims(claims: Partial<TokenClaims>): Token {
238
- return this.withPayload({
239
- ...this.payload,
240
- ...Object.fromEntries(
241
- Object.entries(claims)
242
- .filter(([, value]) => value !== undefined),
243
- ),
244
- });
245
- }
246
-
247
- public withHeaders(headers: TokenHeaders): Token {
248
- return new Token(
249
- headers,
250
- this.payload,
251
- this.signature,
252
- );
253
- }
254
-
255
- public withPayload(payload: TokenPayload): Token {
256
- return new Token(
257
- this.headers,
258
- payload,
259
- this.signature,
260
- );
261
- }
262
-
263
- public withSignature(signature: string): Token {
264
- return new Token(
265
- this.headers,
266
- this.payload,
267
- signature,
268
- );
269
- }
270
-
271
- public toJSON(): string {
272
- return this.toString();
273
- }
274
-
275
- public toString(): string {
276
- const headers = base64UrlEncode(JSON.stringify(this.headers), true);
277
- const payload = base64UrlEncode(JSON.stringify(this.payload), true);
278
-
279
- return `${headers}.${payload}.${this.signature}`;
280
- }
281
- }
282
-
283
- export interface TokenProvider {
284
- getToken(): Token | null;
285
- }
286
-
287
- export interface TokenStore extends TokenProvider {
288
- setToken(token: Token | null): void;
289
- }
290
-
291
- export class FixedTokenProvider implements TokenProvider {
292
- private readonly token: Token | null;
293
-
294
- public constructor(token: Token | null) {
295
- this.token = token;
296
- }
297
-
298
- public getToken(): Token | null {
299
- return this.token;
300
- }
301
- }