@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.
Files changed (187) hide show
  1. package/activeRecord.d.ts +1 -1
  2. package/activeRecord.js +15 -12
  3. package/base64Url.js +7 -2
  4. package/cache/cache.d.ts +12 -0
  5. package/cache/cache.js +2 -0
  6. package/cache/fallbackCache.d.ts +2 -2
  7. package/cache/fallbackCache.js +6 -3
  8. package/cache/inMemoryCache.d.ts +2 -2
  9. package/cache/inMemoryCache.js +5 -2
  10. package/cache/index.d.ts +4 -12
  11. package/cache/index.js +11 -0
  12. package/cache/localStorageCache.d.ts +2 -2
  13. package/cache/localStorageCache.js +4 -1
  14. package/channel/beaconSocketChannel.d.ts +3 -3
  15. package/channel/beaconSocketChannel.js +12 -9
  16. package/channel/channel.d.ts +15 -0
  17. package/channel/channel.js +2 -0
  18. package/channel/encodedChannel.d.ts +2 -2
  19. package/channel/encodedChannel.js +4 -1
  20. package/channel/guaranteedChannel.d.ts +1 -1
  21. package/channel/guaranteedChannel.js +10 -7
  22. package/channel/index.d.ts +8 -15
  23. package/channel/index.js +19 -0
  24. package/channel/queuedChannel.d.ts +2 -2
  25. package/channel/queuedChannel.js +10 -7
  26. package/channel/retryChannel.d.ts +3 -3
  27. package/channel/retryChannel.js +18 -15
  28. package/channel/sandboxChannel.d.ts +2 -2
  29. package/channel/sandboxChannel.js +4 -1
  30. package/channel/socketChannel.d.ts +1 -1
  31. package/channel/socketChannel.js +12 -9
  32. package/cid/assigner.d.ts +3 -0
  33. package/cid/assigner.js +2 -0
  34. package/cid/cachedAssigner.d.ts +5 -5
  35. package/cid/cachedAssigner.js +9 -6
  36. package/cid/fixedAssigner.d.ts +6 -0
  37. package/cid/fixedAssigner.js +13 -0
  38. package/cid/index.d.ts +4 -3
  39. package/cid/index.js +11 -0
  40. package/cid/remoteAssigner.d.ts +3 -3
  41. package/cid/remoteAssigner.js +11 -8
  42. package/constants.js +8 -5
  43. package/container.d.ts +5 -5
  44. package/container.js +49 -55
  45. package/context.d.ts +4 -4
  46. package/context.js +14 -13
  47. package/error.d.ts +1 -1
  48. package/error.js +7 -2
  49. package/evaluator.d.ts +2 -2
  50. package/evaluator.js +26 -23
  51. package/eventManager.d.ts +1 -1
  52. package/eventManager.js +5 -2
  53. package/facade/evaluatorFacade.d.ts +3 -3
  54. package/facade/evaluatorFacade.js +13 -10
  55. package/facade/index.d.ts +7 -0
  56. package/facade/index.js +19 -0
  57. package/facade/sdkFacade.d.ts +9 -9
  58. package/facade/sdkFacade.js +35 -32
  59. package/facade/sessionFacade.d.ts +3 -3
  60. package/facade/sessionFacade.js +6 -3
  61. package/facade/sessionPatch.d.ts +3 -3
  62. package/facade/sessionPatch.js +8 -5
  63. package/facade/trackerFacade.d.ts +2 -2
  64. package/facade/trackerFacade.js +21 -17
  65. package/facade/userFacade.d.ts +4 -4
  66. package/facade/userFacade.js +6 -3
  67. package/facade/userPatch.d.ts +3 -3
  68. package/facade/userPatch.js +8 -5
  69. package/index.d.ts +2 -2
  70. package/index.js +7 -3
  71. package/json.js +2 -0
  72. package/logging/consoleLogger.d.ts +2 -2
  73. package/logging/consoleLogger.js +8 -5
  74. package/logging/index.d.ts +4 -9
  75. package/logging/index.js +11 -0
  76. package/logging/logger.d.ts +9 -0
  77. package/logging/logger.js +2 -0
  78. package/logging/namespacedLogger.d.ts +2 -2
  79. package/logging/namespacedLogger.js +4 -1
  80. package/logging/nullLogger.d.ts +2 -2
  81. package/logging/nullLogger.js +4 -1
  82. package/namespacedStorage.d.ts +1 -1
  83. package/namespacedStorage.js +7 -4
  84. package/package.json +21 -18
  85. package/patch.js +2 -0
  86. package/queue/capacityRestrictedQueue.d.ts +2 -2
  87. package/queue/capacityRestrictedQueue.js +4 -1
  88. package/queue/inMemoryQueue.d.ts +2 -2
  89. package/queue/inMemoryQueue.js +6 -3
  90. package/queue/index.d.ts +5 -9
  91. package/queue/index.js +13 -0
  92. package/queue/monitoredQueue.d.ts +6 -6
  93. package/queue/monitoredQueue.js +6 -3
  94. package/queue/persistentQueue.d.ts +2 -2
  95. package/queue/persistentQueue.js +5 -2
  96. package/queue/queue.d.ts +9 -0
  97. package/queue/queue.js +2 -0
  98. package/retry/arbitraryPolicy.d.ts +2 -2
  99. package/retry/arbitraryPolicy.js +6 -3
  100. package/retry/backoffPolicy.d.ts +2 -2
  101. package/retry/backoffPolicy.js +4 -1
  102. package/retry/index.d.ts +5 -4
  103. package/retry/index.js +13 -0
  104. package/retry/maxAttemptsPolicy.d.ts +2 -2
  105. package/retry/maxAttemptsPolicy.js +4 -1
  106. package/retry/neverPolicy.d.ts +2 -2
  107. package/retry/neverPolicy.js +4 -1
  108. package/retry/policy.d.ts +4 -0
  109. package/retry/policy.js +2 -0
  110. package/schema/attributeSchema.d.ts +2 -0
  111. package/schema/attributeSchema.js +8 -0
  112. package/schema/contentSchemas.d.ts +2 -0
  113. package/schema/contentSchemas.js +46 -0
  114. package/schema/contextSchemas.d.ts +1 -1
  115. package/schema/contextSchemas.js +5 -2
  116. package/schema/ecommerceSchemas.d.ts +1 -1
  117. package/schema/ecommerceSchemas.js +60 -60
  118. package/schema/evaluationSchemas.d.ts +1 -1
  119. package/schema/evaluationSchemas.js +7 -6
  120. package/schema/eventSchemas.d.ts +3 -2
  121. package/schema/eventSchemas.js +53 -48
  122. package/schema/index.d.ts +10 -0
  123. package/schema/index.js +13 -0
  124. package/schema/loggerSchema.d.ts +1 -1
  125. package/schema/loggerSchema.js +9 -7
  126. package/schema/operationSchemas.d.ts +1 -1
  127. package/schema/operationSchemas.js +26 -24
  128. package/schema/sdkFacadeSchemas.d.ts +2 -2
  129. package/schema/sdkFacadeSchemas.js +22 -24
  130. package/schema/sdkSchemas.d.ts +2 -2
  131. package/schema/sdkSchemas.js +21 -22
  132. package/schema/tokenSchema.d.ts +2 -3
  133. package/schema/tokenSchema.js +18 -17
  134. package/schema/userSchema.d.ts +1 -1
  135. package/schema/userSchema.js +47 -61
  136. package/sdk.d.ts +5 -5
  137. package/sdk.js +27 -24
  138. package/sdkEvents.d.ts +2 -2
  139. package/sdkEvents.js +2 -0
  140. package/sourceLocation.js +12 -6
  141. package/tab.d.ts +2 -2
  142. package/tab.js +12 -9
  143. package/token/cachedTokenStore.d.ts +3 -3
  144. package/token/cachedTokenStore.js +6 -3
  145. package/token/inMemoryTokenStore.d.ts +2 -2
  146. package/token/inMemoryTokenStore.js +4 -1
  147. package/token/index.d.ts +4 -41
  148. package/token/index.js +11 -96
  149. package/token/replicatedTokenStore.d.ts +2 -2
  150. package/token/replicatedTokenStore.js +4 -1
  151. package/token/token.d.ts +41 -0
  152. package/token/token.js +99 -0
  153. package/tracker.d.ts +3 -3
  154. package/tracker.js +29 -26
  155. package/trackingEvents.d.ts +29 -14
  156. package/trackingEvents.js +20 -14
  157. package/transformer.js +5 -1
  158. package/utilityTypes.js +2 -0
  159. package/uuid.js +5 -1
  160. package/validation/arrayType.d.ts +2 -2
  161. package/validation/arrayType.js +13 -9
  162. package/validation/booleanType.d.ts +2 -2
  163. package/validation/booleanType.js +7 -3
  164. package/validation/functionType.d.ts +2 -2
  165. package/validation/functionType.js +7 -3
  166. package/validation/index.d.ts +12 -18
  167. package/validation/index.js +29 -30
  168. package/validation/jsonType.d.ts +2 -1
  169. package/validation/jsonType.js +25 -14
  170. package/validation/mixedSchema.d.ts +2 -2
  171. package/validation/mixedSchema.js +4 -1
  172. package/validation/nullType.d.ts +2 -2
  173. package/validation/nullType.js +7 -3
  174. package/validation/numberType.d.ts +2 -2
  175. package/validation/numberType.js +13 -9
  176. package/validation/objectType.d.ts +2 -2
  177. package/validation/objectType.js +23 -18
  178. package/validation/schema.d.ts +16 -0
  179. package/validation/schema.js +15 -0
  180. package/validation/stringType.d.ts +2 -2
  181. package/validation/stringType.js +16 -12
  182. package/validation/unionType.d.ts +2 -2
  183. package/validation/unionType.js +14 -10
  184. package/validation/violation.d.ts +2 -0
  185. package/validation/violation.js +24 -0
  186. package/cid/fixedCidAssigner.d.ts +0 -6
  187. package/cid/fixedCidAssigner.js +0 -10
package/tracker.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { Logger } from './logging';
2
- import Tab from './tab';
2
+ import { Tab } from './tab';
3
3
  import { OutputChannel } from './channel';
4
- import { Beacon, TrackingEvent, TrackingEventContext, PartialTrackingEvent } from './trackingEvents';
5
4
  import { TokenProvider } from './token';
6
5
  import { RetryPolicy } from './retry';
6
+ import { Beacon, TrackingEvent, TrackingEventContext, PartialTrackingEvent } from './trackingEvents';
7
7
  declare type Options = {
8
8
  eventMetadata?: {
9
9
  [key: string]: string;
@@ -25,7 +25,7 @@ export declare type EventInfo<T extends TrackingEvent = TrackingEvent> = {
25
25
  export interface EventListener {
26
26
  (event: EventInfo): void;
27
27
  }
28
- export default class Tracker {
28
+ export declare class Tracker {
29
29
  private readonly options;
30
30
  private tab;
31
31
  private tokenProvider;
package/tracker.js CHANGED
@@ -1,12 +1,15 @@
1
- import { __assign, __rest } from "tslib";
2
- import NullLogger from './logging/nullLogger';
3
- import { formatCause } from './error';
4
- import { isCartPartialEvent, isIdentifiedUserEvent, } from './trackingEvents';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Tracker = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var logging_1 = require("./logging");
6
+ var error_1 = require("./error");
7
+ var trackingEvents_1 = require("./trackingEvents");
5
8
  var trackedEvents = {};
6
9
  var Tracker = /** @class */ (function () {
7
10
  function Tracker(_a) {
8
11
  var _b;
9
- var tab = _a.tab, tokenProvider = _a.tokenProvider, channel = _a.channel, logger = _a.logger, inactivityRetryPolicy = _a.inactivityRetryPolicy, options = __rest(_a, ["tab", "tokenProvider", "channel", "logger", "inactivityRetryPolicy"]);
12
+ var tab = _a.tab, tokenProvider = _a.tokenProvider, channel = _a.channel, logger = _a.logger, inactivityRetryPolicy = _a.inactivityRetryPolicy, options = tslib_1.__rest(_a, ["tab", "tokenProvider", "channel", "logger", "inactivityRetryPolicy"]);
10
13
  this.listeners = [];
11
14
  this.pending = [];
12
15
  this.state = {
@@ -21,8 +24,8 @@ var Tracker = /** @class */ (function () {
21
24
  this.tokenProvider = tokenProvider;
22
25
  this.inactivityRetryPolicy = inactivityRetryPolicy;
23
26
  this.channel = channel;
24
- this.logger = (logger !== null && logger !== void 0 ? logger : new NullLogger());
25
- this.options = __assign(__assign({}, options), { eventMetadata: (_b = options.eventMetadata, (_b !== null && _b !== void 0 ? _b : {})) });
27
+ this.logger = logger !== null && logger !== void 0 ? logger : new logging_1.NullLogger();
28
+ this.options = tslib_1.__assign(tslib_1.__assign({}, options), { eventMetadata: (_b = options.eventMetadata) !== null && _b !== void 0 ? _b : {} });
26
29
  this.enable = this.enable.bind(this);
27
30
  this.disable = this.disable.bind(this);
28
31
  this.suspend = this.suspend.bind(this);
@@ -49,7 +52,7 @@ var Tracker = /** @class */ (function () {
49
52
  };
50
53
  return Promise.all(this.pending).then(suppress, suppress);
51
54
  },
52
- enumerable: true,
55
+ enumerable: false,
53
56
  configurable: true
54
57
  });
55
58
  Tracker.prototype.isEnabled = function () {
@@ -158,8 +161,8 @@ var Tracker = /** @class */ (function () {
158
161
  return this.publish(this.enrichEvent(event, timestamp), timestamp).then(function () { return event; });
159
162
  };
160
163
  Tracker.prototype.trackPageOpen = function (_a) {
161
- var referrer = _a.referrer, payload = __rest(_a, ["referrer"]);
162
- this.enqueue(__assign(__assign({ type: 'pageOpened' }, payload), (referrer.length > 0 ? { referrer: referrer } : {})));
164
+ var referrer = _a.referrer, payload = tslib_1.__rest(_a, ["referrer"]);
165
+ this.enqueue(tslib_1.__assign(tslib_1.__assign({ type: 'pageOpened' }, payload), (referrer.length > 0 ? { referrer: referrer } : {})));
163
166
  };
164
167
  Tracker.prototype.trackPageLoad = function (_a) {
165
168
  var tab = _a.detail.tab;
@@ -171,7 +174,7 @@ var Tracker = /** @class */ (function () {
171
174
  });
172
175
  };
173
176
  Tracker.prototype.trackTabOpen = function (payload) {
174
- this.enqueue(__assign({ type: 'tabOpened' }, payload));
177
+ this.enqueue(tslib_1.__assign({ type: 'tabOpened' }, payload));
175
178
  };
176
179
  Tracker.prototype.trackTabUrlChange = function (_a) {
177
180
  var detail = _a.detail;
@@ -210,7 +213,7 @@ var Tracker = /** @class */ (function () {
210
213
  this.stopInactivityTimer();
211
214
  }
212
215
  var metadata = this.options.eventMetadata;
213
- var context = __assign({ tabId: this.tab.id, url: this.tab.url }, (Object.keys(metadata).length > 0 ? { metadata: metadata } : {}));
216
+ var context = tslib_1.__assign({ tabId: this.tab.id, url: this.tab.url }, (Object.keys(metadata).length > 0 ? { metadata: metadata } : {}));
214
217
  var eventInfo = {
215
218
  event: event,
216
219
  context: context,
@@ -219,7 +222,7 @@ var Tracker = /** @class */ (function () {
219
222
  };
220
223
  if (this.state.suspended) {
221
224
  this.logger.warn("Tracker is suspended, ignoring event \"" + event.type + "\"");
222
- this.notifyEvent(__assign(__assign({}, eventInfo), { status: 'ignored' }));
225
+ this.notifyEvent(tslib_1.__assign(tslib_1.__assign({}, eventInfo), { status: 'ignored' }));
223
226
  return Promise.reject(new Error('The tracker is suspended.'));
224
227
  }
225
228
  this.logger.info("Tracked event \"" + event.type + "\"");
@@ -227,11 +230,11 @@ var Tracker = /** @class */ (function () {
227
230
  return new Promise(function (resolve, reject) {
228
231
  var promise = _this.channel.publish(_this.createBeacon(event, timestamp, context)).then(function () {
229
232
  _this.logger.debug("Successfully published event \"" + event.type + "\"");
230
- _this.notifyEvent(__assign(__assign({}, eventInfo), { status: 'confirmed' }));
233
+ _this.notifyEvent(tslib_1.__assign(tslib_1.__assign({}, eventInfo), { status: 'confirmed' }));
231
234
  resolve(event);
232
235
  }, function (cause) {
233
- _this.logger.error("Failed to publish event \"" + event.type + "\", reason: " + formatCause(cause));
234
- _this.notifyEvent(__assign(__assign({}, eventInfo), { status: 'failed' }));
236
+ _this.logger.error("Failed to publish event \"" + event.type + "\", reason: " + error_1.formatCause(cause));
237
+ _this.notifyEvent(tslib_1.__assign(tslib_1.__assign({}, eventInfo), { status: 'failed' }));
235
238
  reject(cause);
236
239
  });
237
240
  _this.pending.push(promise);
@@ -244,23 +247,23 @@ var Tracker = /** @class */ (function () {
244
247
  });
245
248
  };
246
249
  Tracker.prototype.enrichEvent = function (event, timestamp) {
247
- if (isCartPartialEvent(event)) {
248
- var _a = event.cart, _b = _a.lastUpdateTime, lastUpdateTime = _b === void 0 ? timestamp : _b, cart = __rest(_a, ["lastUpdateTime"]), payload = __rest(event, ["cart"]);
249
- return __assign(__assign({}, payload), { cart: __assign(__assign({}, cart), { lastUpdateTime: lastUpdateTime }) });
250
+ if (trackingEvents_1.isCartPartialEvent(event)) {
251
+ var _a = event.cart, _b = _a.lastUpdateTime, lastUpdateTime = _b === void 0 ? timestamp : _b, cart = tslib_1.__rest(_a, ["lastUpdateTime"]), payload = tslib_1.__rest(event, ["cart"]);
252
+ return tslib_1.__assign(tslib_1.__assign({}, payload), { cart: tslib_1.__assign(tslib_1.__assign({}, cart), { lastUpdateTime: lastUpdateTime }) });
250
253
  }
251
254
  return event;
252
255
  };
253
256
  Tracker.prototype.createBeacon = function (event, timestamp, context) {
254
257
  var token = this.tokenProvider.getToken();
255
- return __assign(__assign({ timestamp: timestamp }, (token !== null ? { token: token.toString() } : {})), { context: context, payload: this.createBeaconPayload(event) });
258
+ return tslib_1.__assign(tslib_1.__assign({ timestamp: timestamp }, (token !== null ? { token: token.toString() } : {})), { context: context, payload: this.createBeaconPayload(event) });
256
259
  };
257
260
  Tracker.prototype.createBeaconPayload = function (event) {
258
- if (!isIdentifiedUserEvent(event)) {
261
+ if (!trackingEvents_1.isIdentifiedUserEvent(event)) {
259
262
  return event;
260
263
  }
261
264
  if (event.type === 'userSignedUp' && event.profile !== undefined) {
262
- var userId_1 = event.userId, profile = event.profile, payload_1 = __rest(event, ["userId", "profile"]);
263
- return __assign(__assign({}, payload_1), { externalUserId: userId_1, patch: {
265
+ var userId_1 = event.userId, profile = event.profile, payload_1 = tslib_1.__rest(event, ["userId", "profile"]);
266
+ return tslib_1.__assign(tslib_1.__assign({}, payload_1), { externalUserId: userId_1, patch: {
264
267
  operations: [
265
268
  {
266
269
  type: 'set',
@@ -270,9 +273,9 @@ var Tracker = /** @class */ (function () {
270
273
  ],
271
274
  } });
272
275
  }
273
- var userId = event.userId, payload = __rest(event, ["userId"]);
274
- return __assign(__assign({}, payload), { externalUserId: userId });
276
+ var userId = event.userId, payload = tslib_1.__rest(event, ["userId"]);
277
+ return tslib_1.__assign(tslib_1.__assign({}, payload), { externalUserId: userId });
275
278
  };
276
279
  return Tracker;
277
280
  }());
278
- export default Tracker;
281
+ exports.Tracker = Tracker;
@@ -68,11 +68,11 @@ export declare type Gender = 'male' | 'female' | 'neutral' | 'unknown';
68
68
  export declare const pageEventTypes: readonly ["pageLoaded", "pageOpened"];
69
69
  export declare const tabEventTypes: readonly ["tabOpened", "tabUrlChanged", "tabVisibilityChanged"];
70
70
  export declare const cartEventTypes: readonly ["cartModified", "cartViewed", "checkoutStarted"];
71
- export declare const ecommerceEventTypes: readonly ("cartModified" | "cartViewed" | "checkoutStarted" | "orderPlaced" | "productViewed")[];
71
+ export declare const ecommerceEventTypes: readonly ["cartModified", "cartViewed", "checkoutStarted", "orderPlaced", "productViewed"];
72
72
  export declare const identifiedUserEventTypes: string[];
73
- export declare const userEventTypes: readonly string[];
74
- export declare const miscEventTypes: readonly ["nothingChanged", "sessionAttributesChanged", "testGroupAssigned", "goalCompleted", "eventOccurred"];
75
- export declare const eventTypes: readonly string[];
73
+ export declare const userEventTypes: readonly [...string[], "userProfileChanged"];
74
+ export declare const miscEventTypes: readonly ["nothingChanged", "sessionAttributesChanged", "goalCompleted", "interestShown", "postViewed", "eventOccurred"];
75
+ export declare const eventTypes: readonly ["pageLoaded", "pageOpened", "cartModified", "cartViewed", "checkoutStarted", "orderPlaced", "productViewed", ...string[], "userProfileChanged", "nothingChanged", "sessionAttributesChanged", "goalCompleted", "interestShown", "postViewed", "eventOccurred"];
76
76
  interface BaseEvent {
77
77
  type: string;
78
78
  }
@@ -200,17 +200,30 @@ export interface SessionAttributesChanged extends BaseEvent {
200
200
  type: 'sessionAttributesChanged';
201
201
  patch: Patch;
202
202
  }
203
- export interface TestGroupAssigned extends BaseEvent {
204
- type: 'testGroupAssigned';
205
- testId: string;
206
- groupId: string;
207
- }
208
203
  export interface GoalCompleted extends BaseEvent {
209
204
  type: 'goalCompleted';
210
205
  goalId: string;
211
206
  value?: number;
212
207
  currency?: string;
213
208
  }
209
+ export interface InterestShown extends BaseEvent {
210
+ type: 'interestShown';
211
+ interests: string[];
212
+ }
213
+ export interface PostDetails {
214
+ postId: string;
215
+ url?: string;
216
+ title: string;
217
+ tags?: string[];
218
+ categories?: string[];
219
+ authors?: string[];
220
+ publishTime: number;
221
+ updateTime?: number;
222
+ }
223
+ export interface PostViewed extends BaseEvent {
224
+ type: 'postViewed';
225
+ post: PostDetails;
226
+ }
214
227
  export interface EventOccurred extends BaseEvent {
215
228
  type: 'eventOccurred';
216
229
  name: string;
@@ -222,7 +235,7 @@ export interface EventOccurred extends BaseEvent {
222
235
  [key: string]: string | number | boolean | null;
223
236
  };
224
237
  }
225
- export declare type MiscEvent = NothingChanged | SessionAttributesChanged | TestGroupAssigned | EventOccurred | GoalCompleted;
238
+ export declare type MiscEvent = NothingChanged | SessionAttributesChanged | EventOccurred | GoalCompleted | InterestShown | PostViewed;
226
239
  declare type EventMap = {
227
240
  tabVisibilityChanged: TabVisibilityChanged;
228
241
  tabUrlChanged: TabUrlChanged;
@@ -240,8 +253,9 @@ declare type EventMap = {
240
253
  orderPlaced: OrderPlaced;
241
254
  nothingChanged: NothingChanged;
242
255
  sessionAttributesChanged: SessionAttributesChanged;
243
- testGroupAssigned: TestGroupAssigned;
244
256
  goalCompleted: GoalCompleted;
257
+ interestShown: InterestShown;
258
+ postViewed: PostViewed;
245
259
  eventOccurred: EventOccurred;
246
260
  };
247
261
  export declare type TrackingEventType = keyof EventMap;
@@ -261,8 +275,9 @@ declare type ExternalEventMap = {
261
275
  orderPlaced: OrderPlaced;
262
276
  productViewed: ProductViewed;
263
277
  userSignedUp: UserSignedUp;
264
- testGroupAssigned: TestGroupAssigned;
265
278
  goalCompleted: GoalCompleted;
279
+ interestShown: InterestShown;
280
+ postViewed: PostViewed;
266
281
  eventOccurred: EventOccurred;
267
282
  };
268
283
  export declare type ExternalTrackingEventType = keyof ExternalEventMap;
@@ -277,9 +292,9 @@ export declare type TrackingEventContext = {
277
292
  [key: string]: string;
278
293
  };
279
294
  };
280
- export declare type BeaconPayload = Exclude<TrackingEvent, IdentifiedUserEvent> | (DistributiveOmit<Exclude<IdentifiedUserEvent, UserSignedUp>, 'userId'> & Record<'externalUserId', IdentifiedUserEvent['userId']>) | (Omit<UserSignedUp, 'userId' | 'profile'> & Record<'externalUserId', IdentifiedUserEvent['userId']> & {
295
+ export declare type BeaconPayload = Exclude<TrackingEvent, IdentifiedUserEvent> | DistributiveOmit<Exclude<IdentifiedUserEvent, UserSignedUp>, 'userId'> & Record<'externalUserId', IdentifiedUserEvent['userId']> | Omit<UserSignedUp, 'userId' | 'profile'> & Record<'externalUserId', IdentifiedUserEvent['userId']> & {
281
296
  patch?: Patch;
282
- });
297
+ };
283
298
  export declare type Beacon = {
284
299
  timestamp: number;
285
300
  token?: string;
package/trackingEvents.js CHANGED
@@ -1,47 +1,53 @@
1
- import { __read, __spread } from "tslib";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isCartPartialEvent = exports.isIdentifiedUserEvent = exports.eventTypes = exports.miscEventTypes = exports.userEventTypes = exports.identifiedUserEventTypes = exports.ecommerceEventTypes = exports.cartEventTypes = exports.tabEventTypes = exports.pageEventTypes = void 0;
4
+ var tslib_1 = require("tslib");
2
5
  /*
3
6
  * Events
4
7
  */
5
- export var pageEventTypes = [
8
+ exports.pageEventTypes = [
6
9
  'pageLoaded',
7
10
  'pageOpened',
8
11
  ];
9
- export var tabEventTypes = [
12
+ exports.tabEventTypes = [
10
13
  'tabOpened',
11
14
  'tabUrlChanged',
12
15
  'tabVisibilityChanged',
13
16
  ];
14
- export var cartEventTypes = [
17
+ exports.cartEventTypes = [
15
18
  'cartModified',
16
19
  'cartViewed',
17
20
  'checkoutStarted',
18
21
  ];
19
- export var ecommerceEventTypes = __spread(cartEventTypes, [
22
+ exports.ecommerceEventTypes = tslib_1.__spreadArray(tslib_1.__spreadArray([], tslib_1.__read(exports.cartEventTypes)), [
20
23
  'orderPlaced',
21
24
  'productViewed',
22
25
  ]);
23
- export var identifiedUserEventTypes = [
26
+ exports.identifiedUserEventTypes = [
24
27
  'userSignedIn',
25
28
  'userSignedOut',
26
29
  'userSignedUp',
27
30
  ];
28
- export var userEventTypes = __spread(identifiedUserEventTypes, [
31
+ exports.userEventTypes = tslib_1.__spreadArray(tslib_1.__spreadArray([], tslib_1.__read(exports.identifiedUserEventTypes)), [
29
32
  'userProfileChanged',
30
33
  ]);
31
- export var miscEventTypes = [
34
+ exports.miscEventTypes = [
32
35
  'nothingChanged',
33
36
  'sessionAttributesChanged',
34
- 'testGroupAssigned',
35
37
  'goalCompleted',
38
+ 'interestShown',
39
+ 'postViewed',
36
40
  'eventOccurred',
37
41
  ];
38
- export var eventTypes = __spread(pageEventTypes, ecommerceEventTypes, userEventTypes, miscEventTypes);
42
+ exports.eventTypes = tslib_1.__spreadArray(tslib_1.__spreadArray(tslib_1.__spreadArray(tslib_1.__spreadArray([], tslib_1.__read(exports.pageEventTypes)), tslib_1.__read(exports.ecommerceEventTypes)), tslib_1.__read(exports.userEventTypes)), tslib_1.__read(exports.miscEventTypes));
39
43
  /*
40
44
  * Type guards
41
45
  */
42
- export function isIdentifiedUserEvent(event) {
43
- return identifiedUserEventTypes.includes(event.type);
46
+ function isIdentifiedUserEvent(event) {
47
+ return exports.identifiedUserEventTypes.includes(event.type);
44
48
  }
45
- export function isCartPartialEvent(event) {
46
- return cartEventTypes.includes(event.type);
49
+ exports.isIdentifiedUserEvent = isIdentifiedUserEvent;
50
+ function isCartPartialEvent(event) {
51
+ return exports.cartEventTypes.includes(event.type);
47
52
  }
53
+ exports.isCartPartialEvent = isCartPartialEvent;
package/transformer.js CHANGED
@@ -1,3 +1,7 @@
1
- export var encodeJson = function encodeJson(input) {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.encodeJson = void 0;
4
+ var encodeJson = function encodeJson(input) {
2
5
  return Promise.resolve(JSON.stringify(input));
3
6
  };
7
+ exports.encodeJson = encodeJson;
package/utilityTypes.js CHANGED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/uuid.js CHANGED
@@ -1,4 +1,7 @@
1
- export function uuid4(sortable) {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.uuid4 = void 0;
4
+ function uuid4(sortable) {
2
5
  if (sortable === void 0) { sortable = false; }
3
6
  var uuid = '';
4
7
  if (sortable) {
@@ -29,3 +32,4 @@ export function uuid4(sortable) {
29
32
  }
30
33
  return uuid;
31
34
  }
35
+ exports.uuid4 = uuid4;
@@ -1,10 +1,10 @@
1
- import { Schema, TypeSchema } from './index';
1
+ import { Schema, TypeSchema } from './schema';
2
2
  declare type ArrayDefinition = {
3
3
  minItems: number;
4
4
  maxItems: number;
5
5
  items?: Schema;
6
6
  };
7
- export default class ArrayType implements TypeSchema {
7
+ export declare class ArrayType implements TypeSchema {
8
8
  private readonly definition;
9
9
  constructor(definition?: Partial<ArrayDefinition>);
10
10
  getTypes(): string[];
@@ -1,10 +1,14 @@
1
- import { __assign } from "tslib";
2
- import { describe, formatPath, Violation } from './index';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ArrayType = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var schema_1 = require("./schema");
6
+ var violation_1 = require("./violation");
3
7
  var ArrayType = /** @class */ (function () {
4
8
  function ArrayType(definition) {
5
9
  if (definition === void 0) { definition = {}; }
6
10
  var _a, _b;
7
- this.definition = __assign(__assign({}, definition), { minItems: (_a = definition.minItems, (_a !== null && _a !== void 0 ? _a : -1)), maxItems: (_b = definition.maxItems, (_b !== null && _b !== void 0 ? _b : -1)) });
11
+ this.definition = tslib_1.__assign(tslib_1.__assign({}, definition), { minItems: (_a = definition.minItems) !== null && _a !== void 0 ? _a : -1, maxItems: (_b = definition.maxItems) !== null && _b !== void 0 ? _b : -1 });
8
12
  }
9
13
  ArrayType.prototype.getTypes = function () {
10
14
  return ['array'];
@@ -15,19 +19,19 @@ var ArrayType = /** @class */ (function () {
15
19
  ArrayType.prototype.validate = function (value, path) {
16
20
  if (path === void 0) { path = []; }
17
21
  if (!this.isValidType(value)) {
18
- throw new Violation("Expected value of type array at path '" + formatPath(path) + "', actual " + describe(value) + ".", path, { type: 'string' });
22
+ throw new schema_1.Violation("Expected value of type array at path '" + violation_1.formatPath(path) + "', actual " + violation_1.describe(value) + ".", path, { type: 'string' });
19
23
  }
20
24
  var _a = this.definition, minItems = _a.minItems, maxItems = _a.maxItems;
21
25
  var length = value.length;
22
26
  if (minItems >= 0 && minItems > length) {
23
- throw new Violation("Expected " + (minItems === maxItems ? 'exactly' : 'at least') + " "
27
+ throw new schema_1.Violation("Expected " + (minItems === maxItems ? 'exactly' : 'at least') + " "
24
28
  + (minItems + " " + (minItems === 1 ? 'item' : 'items') + " ")
25
- + ("at path '" + formatPath(path) + "', actual " + length + "."), path, { limit: minItems });
29
+ + ("at path '" + violation_1.formatPath(path) + "', actual " + length + "."), path, { limit: minItems });
26
30
  }
27
31
  if (maxItems >= 0 && maxItems < length) {
28
- throw new Violation("Expected " + (minItems === maxItems ? 'exactly' : 'at most') + " "
32
+ throw new schema_1.Violation("Expected " + (minItems === maxItems ? 'exactly' : 'at most') + " "
29
33
  + (maxItems + " " + (maxItems === 1 ? 'item' : 'items') + " ")
30
- + ("at path '" + formatPath(path) + "', actual " + length + "."), path, { limit: maxItems });
34
+ + ("at path '" + violation_1.formatPath(path) + "', actual " + length + "."), path, { limit: maxItems });
31
35
  }
32
36
  if (this.definition.items === undefined) {
33
37
  return;
@@ -38,4 +42,4 @@ var ArrayType = /** @class */ (function () {
38
42
  };
39
43
  return ArrayType;
40
44
  }());
41
- export default ArrayType;
45
+ exports.ArrayType = ArrayType;
@@ -1,5 +1,5 @@
1
- import { TypeSchema } from './index';
2
- export default class BooleanType implements TypeSchema {
1
+ import { TypeSchema } from './schema';
2
+ export declare class BooleanType implements TypeSchema {
3
3
  getTypes(): string[];
4
4
  isValidType(value: unknown): value is boolean;
5
5
  validate(value: unknown, path?: string[]): void;
@@ -1,4 +1,8 @@
1
- import { describe, formatPath, Violation } from './index';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BooleanType = void 0;
4
+ var schema_1 = require("./schema");
5
+ var violation_1 = require("./violation");
2
6
  var BooleanType = /** @class */ (function () {
3
7
  function BooleanType() {
4
8
  }
@@ -11,9 +15,9 @@ var BooleanType = /** @class */ (function () {
11
15
  BooleanType.prototype.validate = function (value, path) {
12
16
  if (path === void 0) { path = []; }
13
17
  if (!this.isValidType(value)) {
14
- throw new Violation("Expected value of type boolean at path '" + formatPath(path) + "', actual " + describe(value) + ".", path, { type: 'boolean' });
18
+ throw new schema_1.Violation("Expected value of type boolean at path '" + violation_1.formatPath(path) + "', actual " + violation_1.describe(value) + ".", path, { type: 'boolean' });
15
19
  }
16
20
  };
17
21
  return BooleanType;
18
22
  }());
19
- export default BooleanType;
23
+ exports.BooleanType = BooleanType;
@@ -1,5 +1,5 @@
1
- import { TypeSchema } from './index';
2
- export default class FunctionType implements TypeSchema {
1
+ import { TypeSchema } from './schema';
2
+ export declare class FunctionType implements TypeSchema {
3
3
  getTypes(): string[];
4
4
  isValidType(value: unknown): value is boolean;
5
5
  validate(value: unknown, path?: string[]): void;
@@ -1,4 +1,8 @@
1
- import { describe, formatPath, Violation } from './index';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FunctionType = void 0;
4
+ var schema_1 = require("./schema");
5
+ var violation_1 = require("./violation");
2
6
  var FunctionType = /** @class */ (function () {
3
7
  function FunctionType() {
4
8
  }
@@ -11,9 +15,9 @@ var FunctionType = /** @class */ (function () {
11
15
  FunctionType.prototype.validate = function (value, path) {
12
16
  if (path === void 0) { path = []; }
13
17
  if (!this.isValidType(value)) {
14
- throw new Violation("Expected value of type function at path '" + formatPath(path) + "', actual " + describe(value) + ".", path, { type: 'function' });
18
+ throw new schema_1.Violation("Expected value of type function at path '" + violation_1.formatPath(path) + "', actual " + violation_1.describe(value) + ".", path, { type: 'function' });
15
19
  }
16
20
  };
17
21
  return FunctionType;
18
22
  }());
19
- export default FunctionType;
23
+ exports.FunctionType = FunctionType;
@@ -1,18 +1,12 @@
1
- export declare function formatPath(path: string[]): string;
2
- export declare function describe(value: unknown): string;
3
- export declare class Violation extends Error {
4
- readonly path: string[];
5
- readonly params: {
6
- [key: string]: unknown;
7
- };
8
- constructor(message: string, path: string[], params: {
9
- [p: string]: unknown;
10
- });
11
- }
12
- export interface Schema {
13
- validate(value: unknown, path?: string[]): void;
14
- }
15
- export interface TypeSchema extends Schema {
16
- getTypes(): string[];
17
- isValidType(value: unknown): boolean;
18
- }
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';
@@ -1,30 +1,29 @@
1
- import { __extends } from "tslib";
2
- export function formatPath(path) {
3
- return "/" + path.join('/');
4
- }
5
- export function describe(value) {
6
- if (value === null) {
7
- return 'null';
8
- }
9
- if (Array.isArray(value)) {
10
- return 'array';
11
- }
12
- if (typeof value === 'number') {
13
- return Number.isInteger(value) ? 'integer' : 'number';
14
- }
15
- if (typeof value === 'object') {
16
- return value.constructor.name;
17
- }
18
- return typeof value;
19
- }
20
- var Violation = /** @class */ (function (_super) {
21
- __extends(Violation, _super);
22
- function Violation(message, path, params) {
23
- var _this = _super.call(this, message) || this;
24
- _this.path = path;
25
- _this.params = params;
26
- return _this;
27
- }
28
- return Violation;
29
- }(Error));
30
- export { Violation };
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UnionType = exports.StringType = exports.ObjectType = exports.NumberType = exports.NullType = exports.MixedSchema = exports.JsonPrimitiveType = exports.JsonObjectType = exports.JsonArrayType = exports.JsonType = exports.FunctionType = exports.BooleanType = exports.ArrayType = void 0;
4
+ var tslib_1 = require("tslib");
5
+ tslib_1.__exportStar(require("./schema"), exports);
6
+ tslib_1.__exportStar(require("./violation"), exports);
7
+ var arrayType_1 = require("./arrayType");
8
+ Object.defineProperty(exports, "ArrayType", { enumerable: true, get: function () { return arrayType_1.ArrayType; } });
9
+ var booleanType_1 = require("./booleanType");
10
+ Object.defineProperty(exports, "BooleanType", { enumerable: true, get: function () { return booleanType_1.BooleanType; } });
11
+ var functionType_1 = require("./functionType");
12
+ Object.defineProperty(exports, "FunctionType", { enumerable: true, get: function () { return functionType_1.FunctionType; } });
13
+ var jsonType_1 = require("./jsonType");
14
+ Object.defineProperty(exports, "JsonType", { enumerable: true, get: function () { return jsonType_1.JsonType; } });
15
+ Object.defineProperty(exports, "JsonArrayType", { enumerable: true, get: function () { return jsonType_1.JsonArrayType; } });
16
+ Object.defineProperty(exports, "JsonObjectType", { enumerable: true, get: function () { return jsonType_1.JsonObjectType; } });
17
+ Object.defineProperty(exports, "JsonPrimitiveType", { enumerable: true, get: function () { return jsonType_1.JsonPrimitiveType; } });
18
+ var mixedSchema_1 = require("./mixedSchema");
19
+ Object.defineProperty(exports, "MixedSchema", { enumerable: true, get: function () { return mixedSchema_1.MixedSchema; } });
20
+ var nullType_1 = require("./nullType");
21
+ Object.defineProperty(exports, "NullType", { enumerable: true, get: function () { return nullType_1.NullType; } });
22
+ var numberType_1 = require("./numberType");
23
+ Object.defineProperty(exports, "NumberType", { enumerable: true, get: function () { return numberType_1.NumberType; } });
24
+ var objectType_1 = require("./objectType");
25
+ Object.defineProperty(exports, "ObjectType", { enumerable: true, get: function () { return objectType_1.ObjectType; } });
26
+ var stringType_1 = require("./stringType");
27
+ Object.defineProperty(exports, "StringType", { enumerable: true, get: function () { return stringType_1.StringType; } });
28
+ var unionType_1 = require("./unionType");
29
+ Object.defineProperty(exports, "UnionType", { enumerable: true, get: function () { return unionType_1.UnionType; } });
@@ -1,6 +1,7 @@
1
- import { Schema, TypeSchema } from './index';
1
+ import { Schema, TypeSchema } from './schema';
2
2
  declare type JsonObjectDefinition = {
3
3
  properties?: Schema;
4
+ propertyNames?: Schema;
4
5
  };
5
6
  export declare class JsonObjectType implements TypeSchema {
6
7
  private readonly definition;