@croct/sdk 0.17.9 → 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 (209) hide show
  1. package/activeRecord.cjs +135 -0
  2. package/apiKey.cjs +178 -0
  3. package/base64Url.cjs +41 -0
  4. package/cache/cache.cjs +34 -0
  5. package/cache/cookieCache.cjs +85 -0
  6. package/cache/fallbackCache.cjs +47 -0
  7. package/cache/inMemoryCache.cjs +41 -0
  8. package/cache/index.cjs +37 -0
  9. package/cache/localStorageCache.cjs +81 -0
  10. package/channel/channel.cjs +48 -0
  11. package/channel/encodedChannel.cjs +39 -0
  12. package/channel/guaranteedChannel.cjs +105 -0
  13. package/channel/httpBeaconChannel.cjs +111 -0
  14. package/channel/index.cjs +46 -0
  15. package/channel/queuedChannel.cjs +122 -0
  16. package/channel/retryChannel.cjs +87 -0
  17. package/channel/sandboxChannel.cjs +63 -0
  18. package/cid/assigner.cjs +16 -0
  19. package/cid/cachedAssigner.cjs +66 -0
  20. package/cid/fixedAssigner.cjs +35 -0
  21. package/cid/index.cjs +37 -0
  22. package/cid/remoteAssigner.cjs +65 -0
  23. package/constants.cjs +37 -0
  24. package/constants.cjs.map +1 -1
  25. package/constants.d.ts +2 -2
  26. package/constants.js +1 -1
  27. package/constants.js.map +1 -1
  28. package/container.cjs +305 -0
  29. package/contentFetcher.cjs +193 -0
  30. package/context.cjs +114 -0
  31. package/error.cjs +52 -0
  32. package/evaluator.cjs +219 -0
  33. package/eventManager.cjs +53 -0
  34. package/eventSubjectProcessor.cjs +84 -0
  35. package/facade/contentFetcherFacade.cjs +61 -0
  36. package/facade/evaluatorFacade.cjs +94 -0
  37. package/facade/index.cjs +52 -0
  38. package/facade/sdkFacade.cjs +229 -0
  39. package/facade/sessionFacade.cjs +36 -0
  40. package/facade/sessionPatch.cjs +48 -0
  41. package/facade/trackerFacade.cjs +87 -0
  42. package/facade/userFacade.cjs +43 -0
  43. package/facade/userPatch.cjs +48 -0
  44. package/help.cjs +45 -0
  45. package/index.cjs +33 -0
  46. package/logging/consoleLogger.cjs +50 -0
  47. package/logging/filteredLogger.cjs +62 -0
  48. package/logging/index.cjs +40 -0
  49. package/logging/logger.cjs +16 -0
  50. package/logging/namespacedLogger.cjs +48 -0
  51. package/logging/nullLogger.cjs +37 -0
  52. package/namespacedStorage.cjs +77 -0
  53. package/package.json +7 -6
  54. package/patch.cjs +16 -0
  55. package/queue/capacityRestrictedQueue.cjs +57 -0
  56. package/queue/inMemoryQueue.cjs +58 -0
  57. package/queue/index.cjs +40 -0
  58. package/queue/monitoredQueue.cjs +141 -0
  59. package/queue/persistentQueue.cjs +78 -0
  60. package/queue/queue.cjs +16 -0
  61. package/retry/arbitraryPolicy.cjs +41 -0
  62. package/retry/backoffPolicy.cjs +81 -0
  63. package/retry/index.cjs +40 -0
  64. package/retry/maxAttemptsPolicy.cjs +45 -0
  65. package/retry/neverPolicy.cjs +35 -0
  66. package/retry/policy.cjs +16 -0
  67. package/schema/attributeSchema.cjs +32 -0
  68. package/schema/contentFetcherSchemas.cjs +49 -0
  69. package/schema/contentSchemas.cjs +70 -0
  70. package/schema/contextSchemas.cjs +31 -0
  71. package/schema/ecommerceSchemas.cjs +209 -0
  72. package/schema/evaluatorSchemas.cjs +64 -0
  73. package/schema/eventSchemas.cjs +162 -0
  74. package/schema/index.cjs +42 -0
  75. package/schema/loggerSchema.cjs +38 -0
  76. package/schema/operationSchemas.cjs +122 -0
  77. package/schema/sdkFacadeSchemas.cjs +82 -0
  78. package/schema/sdkSchemas.cjs +110 -0
  79. package/schema/tokenSchema.cjs +68 -0
  80. package/schema/userSchema.cjs +202 -0
  81. package/sdk.cjs +134 -0
  82. package/sdkEvents.cjs +16 -0
  83. package/sourceLocation.cjs +92 -0
  84. package/tab.cjs +122 -0
  85. package/token/cachedTokenStore.cjs +51 -0
  86. package/token/inMemoryTokenStore.cjs +38 -0
  87. package/token/index.cjs +37 -0
  88. package/token/replicatedTokenStore.cjs +40 -0
  89. package/token/token.cjs +239 -0
  90. package/tracker.cjs +358 -0
  91. package/trackingEvents.cjs +94 -0
  92. package/transformer.cjs +30 -0
  93. package/utilityTypes.cjs +16 -0
  94. package/uuid.cjs +55 -0
  95. package/validation/arrayType.cjs +75 -0
  96. package/validation/booleanType.cjs +46 -0
  97. package/validation/functionType.cjs +46 -0
  98. package/validation/index.cjs +66 -0
  99. package/validation/jsonType.cjs +142 -0
  100. package/validation/mixedSchema.cjs +31 -0
  101. package/validation/nullType.cjs +46 -0
  102. package/validation/numberType.cjs +69 -0
  103. package/validation/objectType.cjs +114 -0
  104. package/validation/schema.cjs +34 -0
  105. package/validation/stringType.cjs +106 -0
  106. package/validation/unionType.cjs +67 -0
  107. package/validation/violation.cjs +47 -0
  108. package/src/activeRecord.ts +0 -150
  109. package/src/apiKey.ts +0 -208
  110. package/src/base64Url.ts +0 -22
  111. package/src/cache/cache.ts +0 -22
  112. package/src/cache/cookieCache.ts +0 -88
  113. package/src/cache/fallbackCache.ts +0 -29
  114. package/src/cache/inMemoryCache.ts +0 -21
  115. package/src/cache/index.ts +0 -4
  116. package/src/cache/localStorageCache.ts +0 -85
  117. package/src/channel/channel.ts +0 -52
  118. package/src/channel/encodedChannel.ts +0 -21
  119. package/src/channel/guaranteedChannel.ts +0 -131
  120. package/src/channel/httpBeaconChannel.ts +0 -128
  121. package/src/channel/index.ts +0 -7
  122. package/src/channel/queuedChannel.ts +0 -143
  123. package/src/channel/retryChannel.ts +0 -94
  124. package/src/channel/sandboxChannel.ts +0 -47
  125. package/src/cid/assigner.ts +0 -3
  126. package/src/cid/cachedAssigner.ts +0 -68
  127. package/src/cid/fixedAssigner.ts +0 -13
  128. package/src/cid/index.ts +0 -4
  129. package/src/cid/remoteAssigner.ts +0 -57
  130. package/src/constants.ts +0 -4
  131. package/src/container.ts +0 -410
  132. package/src/contentFetcher.ts +0 -290
  133. package/src/context.ts +0 -139
  134. package/src/error.ts +0 -31
  135. package/src/evaluator.ts +0 -314
  136. package/src/eventManager.ts +0 -53
  137. package/src/eventSubjectProcessor.ts +0 -85
  138. package/src/facade/contentFetcherFacade.ts +0 -69
  139. package/src/facade/evaluatorFacade.ts +0 -111
  140. package/src/facade/index.ts +0 -7
  141. package/src/facade/sdkFacade.ts +0 -310
  142. package/src/facade/sessionFacade.ts +0 -14
  143. package/src/facade/sessionPatch.ts +0 -32
  144. package/src/facade/trackerFacade.ts +0 -98
  145. package/src/facade/userFacade.ts +0 -26
  146. package/src/facade/userPatch.ts +0 -32
  147. package/src/help.ts +0 -24
  148. package/src/index.ts +0 -4
  149. package/src/logging/consoleLogger.ts +0 -38
  150. package/src/logging/filteredLogger.ts +0 -57
  151. package/src/logging/index.ts +0 -5
  152. package/src/logging/logger.ts +0 -13
  153. package/src/logging/namespacedLogger.ts +0 -32
  154. package/src/logging/nullLogger.ts +0 -19
  155. package/src/namespacedStorage.ts +0 -69
  156. package/src/patch.ts +0 -64
  157. package/src/queue/capacityRestrictedQueue.ts +0 -44
  158. package/src/queue/inMemoryQueue.ts +0 -43
  159. package/src/queue/index.ts +0 -5
  160. package/src/queue/monitoredQueue.ts +0 -168
  161. package/src/queue/persistentQueue.ts +0 -73
  162. package/src/queue/queue.ts +0 -15
  163. package/src/retry/arbitraryPolicy.ts +0 -21
  164. package/src/retry/backoffPolicy.ts +0 -84
  165. package/src/retry/index.ts +0 -5
  166. package/src/retry/maxAttemptsPolicy.ts +0 -28
  167. package/src/retry/neverPolicy.ts +0 -11
  168. package/src/retry/policy.ts +0 -5
  169. package/src/schema/attributeSchema.ts +0 -6
  170. package/src/schema/contentFetcherSchemas.ts +0 -23
  171. package/src/schema/contentSchemas.ts +0 -44
  172. package/src/schema/contextSchemas.ts +0 -5
  173. package/src/schema/ecommerceSchemas.ts +0 -179
  174. package/src/schema/evaluatorSchemas.ts +0 -52
  175. package/src/schema/eventSchemas.ts +0 -134
  176. package/src/schema/index.ts +0 -11
  177. package/src/schema/loggerSchema.ts +0 -12
  178. package/src/schema/operationSchemas.ts +0 -102
  179. package/src/schema/sdkFacadeSchemas.ts +0 -64
  180. package/src/schema/sdkSchemas.ts +0 -82
  181. package/src/schema/tokenSchema.ts +0 -42
  182. package/src/schema/userSchema.ts +0 -184
  183. package/src/sdk.ts +0 -183
  184. package/src/sdkEvents.ts +0 -15
  185. package/src/sourceLocation.ts +0 -85
  186. package/src/tab.ts +0 -148
  187. package/src/token/cachedTokenStore.ts +0 -34
  188. package/src/token/inMemoryTokenStore.ts +0 -13
  189. package/src/token/index.ts +0 -4
  190. package/src/token/replicatedTokenStore.ts +0 -21
  191. package/src/token/token.ts +0 -301
  192. package/src/tracker.ts +0 -504
  193. package/src/trackingEvents.ts +0 -452
  194. package/src/transformer.ts +0 -7
  195. package/src/utilityTypes.ts +0 -3
  196. package/src/uuid.ts +0 -43
  197. package/src/validation/arrayType.ts +0 -71
  198. package/src/validation/booleanType.ts +0 -22
  199. package/src/validation/functionType.ts +0 -22
  200. package/src/validation/index.ts +0 -12
  201. package/src/validation/jsonType.ts +0 -156
  202. package/src/validation/mixedSchema.ts +0 -7
  203. package/src/validation/nullType.ts +0 -22
  204. package/src/validation/numberType.ts +0 -59
  205. package/src/validation/objectType.ts +0 -138
  206. package/src/validation/schema.ts +0 -21
  207. package/src/validation/stringType.ts +0 -118
  208. package/src/validation/unionType.ts +0 -53
  209. package/src/validation/violation.ts +0 -23
@@ -1,452 +0,0 @@
1
- import {Patch} from './patch';
2
- import {DistributiveOmit, Optional} from './utilityTypes';
3
-
4
- /*
5
- * Object values
6
- */
7
-
8
- export type ProductDetails = {
9
- productId: string,
10
- sku?: string,
11
- name: string,
12
- category?: string,
13
- brand?: string,
14
- variant?: string,
15
- displayPrice: number,
16
- originalPrice?: number,
17
- url?: string,
18
- imageUrl?: string,
19
- };
20
-
21
- export type CartItem = {
22
- index: number,
23
- product: ProductDetails,
24
- quantity: number,
25
- total: number,
26
- discount?: number,
27
- coupon?: string,
28
- };
29
-
30
- export type Cart = {
31
- currency: string,
32
- items: CartItem[],
33
- subtotal?: number,
34
- shippingPrice?: number,
35
- taxes?: {[key: string]: number},
36
- costs?: {[key: string]: number},
37
- discount?: number,
38
- total: number,
39
- coupon?: string,
40
- lastUpdateTime: number,
41
- };
42
-
43
- export type OrderItem = {
44
- index: number,
45
- product: ProductDetails,
46
- quantity?: number,
47
- total: number,
48
- discount?: number,
49
- coupon?: string,
50
- };
51
-
52
- export type OrderStatus = 'placed' | 'paid' | 'completed';
53
-
54
- export type Order = {
55
- orderId: string,
56
- currency: string,
57
- items: OrderItem[],
58
- subtotal?: number,
59
- shippingPrice?: number,
60
- taxes?: {[key: string]: number},
61
- costs?: {[key: string]: number},
62
- discount?: number,
63
- total: number,
64
- coupon?: string,
65
- paymentMethod?: string,
66
- installments?: number,
67
- status?: OrderStatus,
68
- };
69
-
70
- export type Gender = 'male' | 'female' | 'neutral' | 'unknown';
71
-
72
- /*
73
- * Events
74
- */
75
-
76
- export const pageEventTypes = [
77
- 'pageLoaded',
78
- 'pageOpened',
79
- ] as const;
80
-
81
- export const tabEventTypes = [
82
- 'tabOpened',
83
- 'tabUrlChanged',
84
- 'tabVisibilityChanged',
85
- ] as const;
86
-
87
- export const cartEventTypes = [
88
- 'cartModified',
89
- 'cartViewed',
90
- 'checkoutStarted',
91
- ] as const;
92
-
93
- export const ecommerceEventTypes = [
94
- ...cartEventTypes,
95
- 'orderPlaced',
96
- 'productViewed',
97
- ] as const;
98
-
99
- export const identifiedUserEventTypes = [
100
- 'userSignedIn',
101
- 'userSignedOut',
102
- 'userSignedUp',
103
- ];
104
-
105
- export const userEventTypes = [
106
- ...identifiedUserEventTypes,
107
- 'userProfileChanged',
108
- ] as const;
109
-
110
- export const miscEventTypes = [
111
- 'nothingChanged',
112
- 'sessionAttributesChanged',
113
- 'goalCompleted',
114
- 'interestShown',
115
- 'postViewed',
116
- 'eventOccurred',
117
- 'linkOpened',
118
- ] as const;
119
-
120
- export const eventTypes = [
121
- ...pageEventTypes,
122
- ...ecommerceEventTypes,
123
- ...userEventTypes,
124
- ...miscEventTypes,
125
- ] as const;
126
-
127
- interface BaseEvent {
128
- type: string;
129
- }
130
-
131
- /*
132
- * User events
133
- */
134
-
135
- export interface UserProfileChanged extends BaseEvent {
136
- type: 'userProfileChanged';
137
- patch: Patch;
138
- }
139
-
140
- type Primitive = null | string | number | boolean;
141
- type PrimitiveMap = {[member: string]: Primitive};
142
- type PrimitiveArray = Primitive[];
143
- type TwoLevelMap = {[member: string]: Primitive | PrimitiveMap | PrimitiveArray};
144
- type TwoLevelArray = PrimitiveArray | PrimitiveMap[] | PrimitiveArray[];
145
- type CustomAttribute = Primitive | TwoLevelMap | TwoLevelArray;
146
-
147
- export type UserProfile = {
148
- firstName?: string,
149
- lastName?: string,
150
- birthDate?: string,
151
- gender?: Gender,
152
- email?: string,
153
- alternateEmail?: string,
154
- phone?: string,
155
- alternatePhone?: string,
156
- address?: {
157
- street?: string,
158
- district?: string,
159
- city?: string,
160
- region?: string,
161
- country?: string,
162
- postalCode?: string,
163
- },
164
- avatar?: string,
165
- company?: string,
166
- companyUrl?: string,
167
- jobTitle?: string,
168
- interests?: string[],
169
- activities?: string[],
170
- custom?: {
171
- [member: string]: CustomAttribute,
172
- },
173
- };
174
-
175
- export interface UserSignedUp extends BaseEvent {
176
- type: 'userSignedUp';
177
- userId: string;
178
- profile?: UserProfile;
179
- }
180
-
181
- export interface UserSignedIn extends BaseEvent {
182
- type: 'userSignedIn';
183
- userId: string;
184
- }
185
-
186
- export interface UserSignedOut extends BaseEvent {
187
- type: 'userSignedOut';
188
- userId: string;
189
- }
190
-
191
- export type IdentifiedUserEvent = UserSignedIn | UserSignedOut | UserSignedUp;
192
- export type UserEvent = UserProfileChanged | IdentifiedUserEvent;
193
-
194
- /*
195
- * E-commerce events
196
- */
197
-
198
- export type CartEventType = typeof cartEventTypes[number];
199
-
200
- interface BaseCartEvent extends BaseEvent {
201
- type: CartEventType;
202
- cart: Cart;
203
- }
204
-
205
- export interface CartViewed extends BaseCartEvent {
206
- type: 'cartViewed';
207
- }
208
-
209
- export interface CartModified extends BaseCartEvent {
210
- type: 'cartModified';
211
- }
212
-
213
- export interface CheckoutStarted extends BaseCartEvent {
214
- type: 'checkoutStarted';
215
- orderId?: string;
216
- }
217
-
218
- export type CartEvent = CartModified | CartViewed | CheckoutStarted;
219
-
220
- export interface OrderPlaced extends BaseEvent {
221
- type: 'orderPlaced';
222
- order: Order;
223
- }
224
-
225
- export interface ProductViewed extends BaseEvent {
226
- type: 'productViewed';
227
- product: ProductDetails;
228
- }
229
-
230
- export type EcommerceEvent = OrderPlaced | ProductViewed | CartEvent;
231
-
232
- /**
233
- * Tab event
234
- */
235
-
236
- export type TabEventType = typeof tabEventTypes[number];
237
-
238
- interface BaseTabEvent extends BaseEvent {
239
- type: TabEventType;
240
- tabId: string;
241
- }
242
-
243
- export interface TabOpened extends BaseTabEvent {
244
- type: 'tabOpened';
245
- }
246
-
247
- export interface TabUrlChanged extends BaseTabEvent {
248
- type: 'tabUrlChanged';
249
- url: string;
250
- }
251
-
252
- export interface TabVisibilityChanged extends BaseTabEvent {
253
- type: 'tabVisibilityChanged';
254
- visibility: 'visible' | 'hidden';
255
- }
256
-
257
- export type TabEvent = TabVisibilityChanged | TabUrlChanged | TabOpened;
258
-
259
- /*
260
- * Page events
261
- */
262
-
263
- export type PageEventType = typeof pageEventTypes[number];
264
-
265
- interface BasePageEvent extends BaseEvent {
266
- type: PageEventType;
267
- url: string;
268
- }
269
-
270
- export interface PageOpened extends BasePageEvent {
271
- type: 'pageOpened';
272
- referrer?: string;
273
- }
274
-
275
- export interface PageLoaded extends BasePageEvent {
276
- type: 'pageLoaded';
277
- title: string;
278
- lastModifiedTime: number;
279
- }
280
-
281
- export type PageEvent = PageLoaded | PageOpened;
282
-
283
- /*
284
- * Misc events
285
- */
286
-
287
- export interface NothingChanged extends BaseEvent {
288
- type: 'nothingChanged';
289
- sinceTime: number;
290
- }
291
-
292
- export interface SessionAttributesChanged extends BaseEvent {
293
- type: 'sessionAttributesChanged';
294
- patch: Patch;
295
- }
296
-
297
- export interface GoalCompleted extends BaseEvent {
298
- type: 'goalCompleted';
299
- goalId: string;
300
- value?: number;
301
- currency?: string;
302
- }
303
-
304
- export interface InterestShown extends BaseEvent {
305
- type: 'interestShown';
306
- interests: string[];
307
- }
308
-
309
- export interface PostDetails {
310
- postId: string;
311
- url?: string;
312
- title: string;
313
- tags?: string[];
314
- categories?: string[];
315
- authors?: string[];
316
- publishTime: number;
317
- updateTime?: number;
318
- }
319
-
320
- export interface PostViewed extends BaseEvent {
321
- type: 'postViewed';
322
- post: PostDetails;
323
- }
324
-
325
- export interface EventOccurred extends BaseEvent {
326
- type: 'eventOccurred';
327
- name: string;
328
- details?: {[key: string]: string|number|boolean|null};
329
- }
330
-
331
- export interface LinkOpened extends BaseEvent {
332
- type: 'linkOpened';
333
- link: string;
334
- }
335
-
336
- export type MiscEvent =
337
- NothingChanged
338
- | SessionAttributesChanged
339
- | EventOccurred
340
- | GoalCompleted
341
- | InterestShown
342
- | PostViewed
343
- | LinkOpened;
344
-
345
- type EventMap = {
346
- // Tab events
347
- tabVisibilityChanged: TabVisibilityChanged,
348
- tabUrlChanged: TabUrlChanged,
349
- tabOpened: TabOpened,
350
- // Page events
351
- pageLoaded: PageLoaded,
352
- pageOpened: PageOpened,
353
- // User events
354
- userSignedIn: UserSignedIn,
355
- userSignedOut: UserSignedOut,
356
- userSignedUp: UserSignedUp,
357
- userProfileChanged: UserProfileChanged,
358
- // E-commerce events
359
- productViewed: ProductViewed,
360
- cartViewed: CartViewed,
361
- cartModified: CartModified,
362
- checkoutStarted: CheckoutStarted,
363
- orderPlaced: OrderPlaced,
364
- // Misc events
365
- nothingChanged: NothingChanged,
366
- sessionAttributesChanged: SessionAttributesChanged,
367
- goalCompleted: GoalCompleted,
368
- interestShown: InterestShown,
369
- postViewed: PostViewed,
370
- eventOccurred: EventOccurred,
371
- linkOpened: LinkOpened,
372
- };
373
-
374
- export type TrackingEventType = keyof EventMap;
375
-
376
- export type TrackingEvent<T extends TrackingEventType = TrackingEventType> =
377
- T extends TrackingEventType ? EventMap[T] : EventMap[TrackingEventType];
378
-
379
- /**
380
- * Partial Events
381
- */
382
-
383
- type CartPartialEvent <T extends CartEvent = CartEvent> =
384
- DistributiveOmit<T, 'cart'> & Record<'cart', Optional<Cart, 'lastUpdateTime'>>;
385
-
386
- export type PartialTrackingEvent = Exclude<TrackingEvent, PageEvent | TabEvent | CartEvent> | CartPartialEvent;
387
-
388
- /**
389
- * External Events
390
- */
391
-
392
- type ExternalEventMap = {
393
- cartModified: CartPartialEvent<CartModified>,
394
- cartViewed: CartPartialEvent<CartViewed>,
395
- checkoutStarted: CartPartialEvent<CheckoutStarted>,
396
- orderPlaced: OrderPlaced,
397
- productViewed: ProductViewed,
398
- userSignedUp: UserSignedUp,
399
- goalCompleted: GoalCompleted,
400
- interestShown: InterestShown,
401
- postViewed: PostViewed,
402
- linkOpened: LinkOpened,
403
- eventOccurred: EventOccurred,
404
- };
405
-
406
- export type ExternalTrackingEventType = keyof ExternalEventMap;
407
-
408
- export type ExternalTrackingEvent<T extends ExternalTrackingEventType = ExternalTrackingEventType> =
409
- T extends ExternalTrackingEventType
410
- ? ExternalEventMap[T]
411
- : ExternalEventMap[ExternalTrackingEventType];
412
-
413
- export type ExternalTrackingEventPayload<T extends ExternalTrackingEventType> = Omit<ExternalEventMap[T], 'type'>;
414
-
415
- /*
416
- * Type guards
417
- */
418
-
419
- export function isIdentifiedUserEvent(event: TrackingEvent): event is IdentifiedUserEvent {
420
- return identifiedUserEventTypes.includes((event as IdentifiedUserEvent).type);
421
- }
422
-
423
- export function isCartPartialEvent(event: PartialTrackingEvent): event is CartPartialEvent {
424
- return cartEventTypes.includes((event as CartEvent).type);
425
- }
426
-
427
- /*
428
- * Beacon
429
- */
430
-
431
- export type TrackingEventContext = {
432
- tabId: string,
433
- url: string,
434
- metadata?: {[key: string]: string},
435
- };
436
-
437
- export type BeaconPayload =
438
- Exclude<TrackingEvent, IdentifiedUserEvent>
439
- // Renames "userId" to "externalUserId"
440
- | DistributiveOmit<Exclude<IdentifiedUserEvent, UserSignedUp>, 'userId'>
441
- & Record<'externalUserId', IdentifiedUserEvent['userId']>
442
- // Renames "userId" to "externalUserId", remove "profile" and add "patch"
443
- | Omit<UserSignedUp, 'userId' | 'profile'>
444
- & Record<'externalUserId', IdentifiedUserEvent['userId']>
445
- & {patch?: Patch};
446
-
447
- export type Beacon = {
448
- timestamp: number,
449
- token?: string,
450
- context: TrackingEventContext,
451
- payload: BeaconPayload,
452
- };
@@ -1,7 +0,0 @@
1
- export interface Transformer<I, O> {
2
- (input: I): Promise<O>;
3
- }
4
-
5
- export const encodeJson: Transformer<any, string> = function encodeJson(input: any): Promise<string> {
6
- return Promise.resolve(JSON.stringify(input));
7
- };
@@ -1,3 +0,0 @@
1
- export type DistributiveOmit<T, K extends keyof T> = T extends unknown ? Omit<T, K> : never;
2
-
3
- export type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
package/src/uuid.ts DELETED
@@ -1,43 +0,0 @@
1
- export function uuid4(sortable = false): string {
2
- let uuid = '';
3
-
4
- if (sortable) {
5
- const prefix = Date.now()
6
- .toString(16)
7
- .padStart(12, '0')
8
- .substring(0, 12);
9
-
10
- uuid = `${prefix.substring(0, 8)}-${prefix.substring(8, 12)}`;
11
- }
12
-
13
- for (let index = uuid.length; index < 36; index++) {
14
- switch (index) {
15
- case 8:
16
- case 13:
17
- case 18:
18
- case 23:
19
- uuid += '-';
20
-
21
- break;
22
-
23
- case 14:
24
- // bits 12-15 of the time_hi_and_version field to 0010
25
- uuid += '4';
26
-
27
- break;
28
-
29
- default: {
30
- let random = (Math.random() * 16) | 0;
31
-
32
- if (index === 19) {
33
- // bits 6-7 of the clock_seq_hi_and_reserved to 01
34
- random = (random & 3) | 8;
35
- }
36
-
37
- uuid += random.toString(16);
38
- }
39
- }
40
- }
41
-
42
- return uuid;
43
- }
@@ -1,71 +0,0 @@
1
- import {Schema, TypeSchema, Violation} from './schema';
2
- import {describe, formatPath} from './violation';
3
-
4
- type ArrayDefinition = {
5
- minItems: number,
6
- maxItems: number,
7
- items?: Schema,
8
- };
9
-
10
- export class ArrayType implements TypeSchema {
11
- private readonly definition: ArrayDefinition;
12
-
13
- public constructor(definition: Partial<ArrayDefinition> = {}) {
14
- this.definition = {
15
- ...definition,
16
- minItems: definition.minItems ?? -1,
17
- maxItems: definition.maxItems ?? -1,
18
- };
19
- }
20
-
21
- public getTypes(): string[] {
22
- return ['array'];
23
- }
24
-
25
- public isValidType(value: unknown): value is unknown[] {
26
- return Array.isArray(value);
27
- }
28
-
29
- public validate(value: unknown, path: string[] = []): void {
30
- if (!this.isValidType(value)) {
31
- throw new Violation(
32
- `Expected value of type array at path '${formatPath(path)}', actual ${describe(value)}.`,
33
- path,
34
- {type: 'string'},
35
- );
36
- }
37
-
38
- const {minItems, maxItems} = this.definition;
39
- const {length} = value;
40
-
41
- if (minItems >= 0 && minItems > length) {
42
- throw new Violation(
43
- `Expected ${minItems === maxItems ? 'exactly' : 'at least'} `
44
- + `${minItems} ${minItems === 1 ? 'item' : 'items'} `
45
- + `at path '${formatPath(path)}', actual ${length}.`,
46
- path,
47
- {limit: minItems},
48
- );
49
- }
50
-
51
- if (maxItems >= 0 && maxItems < length) {
52
- throw new Violation(
53
- `Expected ${minItems === maxItems ? 'exactly' : 'at most'} `
54
- + `${maxItems} ${maxItems === 1 ? 'item' : 'items'} `
55
- + `at path '${formatPath(path)}', actual ${length}.`,
56
- path,
57
- {limit: maxItems},
58
- );
59
- }
60
-
61
- if (this.definition.items === undefined) {
62
- return;
63
- }
64
-
65
- for (let index = 0; index < length; index++) {
66
- this.definition
67
- .items
68
- .validate(value[index], path.concat([index.toString()]));
69
- }
70
- }
71
- }
@@ -1,22 +0,0 @@
1
- import {TypeSchema, Violation} from './schema';
2
- import {describe, formatPath} from './violation';
3
-
4
- export class BooleanType implements TypeSchema {
5
- public getTypes(): string[] {
6
- return ['boolean'];
7
- }
8
-
9
- public isValidType(value: unknown): value is boolean {
10
- return typeof value === 'boolean';
11
- }
12
-
13
- public validate(value: unknown, path: string[] = []): void {
14
- if (!this.isValidType(value)) {
15
- throw new Violation(
16
- `Expected value of type boolean at path '${formatPath(path)}', actual ${describe(value)}.`,
17
- path,
18
- {type: 'boolean'},
19
- );
20
- }
21
- }
22
- }
@@ -1,22 +0,0 @@
1
- import {TypeSchema, Violation} from './schema';
2
- import {describe, formatPath} from './violation';
3
-
4
- export class FunctionType implements TypeSchema {
5
- public getTypes(): string[] {
6
- return ['function'];
7
- }
8
-
9
- public isValidType(value: unknown): value is boolean {
10
- return typeof value === 'function';
11
- }
12
-
13
- public validate(value: unknown, path: string[] = []): void {
14
- if (!this.isValidType(value)) {
15
- throw new Violation(
16
- `Expected value of type function at path '${formatPath(path)}', actual ${describe(value)}.`,
17
- path,
18
- {type: 'function'},
19
- );
20
- }
21
- }
22
- }
@@ -1,12 +0,0 @@
1
- export * from './schema';
2
- export * from './violation';
3
- export {ArrayType} from './arrayType';
4
- export {BooleanType} from './booleanType';
5
- export {FunctionType} from './functionType';
6
- export {JsonType, JsonArrayType, JsonObjectType, JsonPrimitiveType} from './jsonType';
7
- export {MixedSchema} from './mixedSchema';
8
- export {NullType} from './nullType';
9
- export {NumberType} from './numberType';
10
- export {ObjectType} from './objectType';
11
- export {StringType} from './stringType';
12
- export {UnionType} from './unionType';