@croct/sdk 0.6.0 → 0.8.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 (70) hide show
  1. package/activeRecord.d.ts +1 -0
  2. package/activeRecord.js +9 -1
  3. package/cache/fallbackCache.js +1 -1
  4. package/cache/index.js +1 -1
  5. package/channel/beaconSocketChannel.js +5 -5
  6. package/channel/guaranteedChannel.js +6 -6
  7. package/channel/index.js +1 -1
  8. package/channel/queuedChannel.js +6 -6
  9. package/channel/retryChannel.js +5 -5
  10. package/channel/socketChannel.js +4 -4
  11. package/cid/cachedAssigner.js +2 -2
  12. package/cid/index.js +1 -1
  13. package/cid/remoteAssigner.js +3 -3
  14. package/constants.js +1 -1
  15. package/container.d.ts +1 -0
  16. package/container.js +20 -12
  17. package/context.js +1 -1
  18. package/evaluator.js +14 -14
  19. package/facade/evaluatorFacade.js +3 -3
  20. package/facade/sdkFacade.d.ts +1 -0
  21. package/facade/sdkFacade.js +8 -8
  22. package/facade/sessionPatch.js +1 -1
  23. package/facade/trackerFacade.js +7 -5
  24. package/facade/userPatch.js +1 -1
  25. package/logging/consoleLogger.js +1 -1
  26. package/logging/index.js +1 -1
  27. package/logging/namespacedLogger.js +1 -1
  28. package/namespacedStorage.js +2 -2
  29. package/package.json +12 -12
  30. package/patch.d.ts +5 -1
  31. package/queue/inMemoryQueue.js +1 -1
  32. package/queue/index.js +1 -1
  33. package/queue/monitoredQueue.js +1 -1
  34. package/retry/arbitraryPolicy.js +1 -1
  35. package/retry/index.js +1 -1
  36. package/schema/attributeSchema.d.ts +2 -0
  37. package/schema/attributeSchema.js +8 -0
  38. package/schema/contentSchemas.d.ts +2 -0
  39. package/schema/contentSchemas.js +46 -0
  40. package/schema/eventSchemas.d.ts +3 -1
  41. package/schema/eventSchemas.js +29 -14
  42. package/schema/index.js +10 -10
  43. package/schema/operationSchemas.d.ts +1 -0
  44. package/schema/operationSchemas.js +11 -1
  45. package/schema/sdkFacadeSchemas.js +1 -0
  46. package/schema/sdkSchemas.js +1 -0
  47. package/schema/userSchema.js +5 -16
  48. package/sdk.d.ts +1 -0
  49. package/sdk.js +16 -15
  50. package/sourceLocation.js +2 -2
  51. package/token/index.js +1 -1
  52. package/token/token.js +11 -11
  53. package/tracker.d.ts +1 -0
  54. package/tracker.js +30 -22
  55. package/trackingEvents.d.ts +31 -10
  56. package/trackingEvents.js +8 -6
  57. package/uuid.js +1 -1
  58. package/validation/arrayType.js +8 -8
  59. package/validation/booleanType.js +1 -1
  60. package/validation/functionType.js +1 -1
  61. package/validation/index.js +2 -2
  62. package/validation/jsonType.d.ts +1 -0
  63. package/validation/jsonType.js +14 -8
  64. package/validation/nullType.js +1 -1
  65. package/validation/numberType.js +6 -6
  66. package/validation/objectType.js +16 -16
  67. package/validation/schema.js +1 -1
  68. package/validation/stringType.js +28 -16
  69. package/validation/unionType.js +7 -7
  70. package/validation/violation.js +1 -1
package/token/token.js CHANGED
@@ -25,7 +25,7 @@ var Token = /** @class */ (function () {
25
25
  typ: 'JWT',
26
26
  alg: 'none',
27
27
  appId: appId,
28
- }, tslib_1.__assign({ iss: 'croct.io', aud: 'croct.io', iat: timestamp }, (subject !== null ? { sub: subject } : null)));
28
+ }, (0, tslib_1.__assign)({ iss: 'croct.io', aud: 'croct.io', iat: timestamp }, (subject !== null ? { sub: subject } : null)));
29
29
  };
30
30
  Token.parse = function (token) {
31
31
  if (token === '') {
@@ -40,10 +40,10 @@ var Token = /** @class */ (function () {
40
40
  var claims;
41
41
  var signature;
42
42
  try {
43
- headers = JSON.parse(base64Url_1.base64UrlDecode(parts[0]));
44
- claims = JSON.parse(base64Url_1.base64UrlDecode(parts[1]));
43
+ headers = JSON.parse((0, base64Url_1.base64UrlDecode)(parts[0]));
44
+ claims = JSON.parse((0, base64Url_1.base64UrlDecode)(parts[1]));
45
45
  if (parts.length === 3) {
46
- signature = base64Url_1.base64UrlDecode(parts[2]);
46
+ signature = (0, base64Url_1.base64UrlDecode)(parts[2]);
47
47
  }
48
48
  }
49
49
  catch (_a) {
@@ -53,15 +53,15 @@ var Token = /** @class */ (function () {
53
53
  schema_1.tokenSchema.validate({ headers: headers, claims: claims, signature: signature });
54
54
  }
55
55
  catch (violation) {
56
- throw new Error("The token is invalid: " + error_1.formatCause(violation));
56
+ throw new Error("The token is invalid: ".concat((0, error_1.formatCause)(violation)));
57
57
  }
58
58
  return new Token(headers, claims, signature);
59
59
  };
60
60
  Token.prototype.getHeaders = function () {
61
- return tslib_1.__assign({}, this.headers);
61
+ return (0, tslib_1.__assign)({}, this.headers);
62
62
  };
63
63
  Token.prototype.getClaims = function () {
64
- return tslib_1.__assign({}, this.claims);
64
+ return (0, tslib_1.__assign)({}, this.claims);
65
65
  };
66
66
  Token.prototype.getSignature = function () {
67
67
  return this.signature;
@@ -79,10 +79,10 @@ var Token = /** @class */ (function () {
79
79
  return this.toString();
80
80
  };
81
81
  Token.prototype.toString = function () {
82
- var headers = base64Url_1.base64UrlEncode(JSON.stringify(this.headers));
83
- var claims = base64Url_1.base64UrlEncode(JSON.stringify(this.claims));
84
- var signature = base64Url_1.base64UrlEncode(this.signature);
85
- return headers + "." + claims + "." + signature;
82
+ var headers = (0, base64Url_1.base64UrlEncode)(JSON.stringify(this.headers));
83
+ var claims = (0, base64Url_1.base64UrlEncode)(JSON.stringify(this.claims));
84
+ var signature = (0, base64Url_1.base64UrlEncode)(this.signature);
85
+ return "".concat(headers, ".").concat(claims, ".").concat(signature);
86
86
  };
87
87
  return Token;
88
88
  }());
package/tracker.d.ts CHANGED
@@ -62,5 +62,6 @@ export declare class Tracker {
62
62
  private enrichEvent;
63
63
  private createBeacon;
64
64
  private createBeaconPayload;
65
+ private enrichBeaconPayload;
65
66
  }
66
67
  export {};
package/tracker.js CHANGED
@@ -9,7 +9,7 @@ var trackedEvents = {};
9
9
  var Tracker = /** @class */ (function () {
10
10
  function Tracker(_a) {
11
11
  var _b;
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"]);
12
+ var tab = _a.tab, tokenProvider = _a.tokenProvider, channel = _a.channel, logger = _a.logger, inactivityRetryPolicy = _a.inactivityRetryPolicy, options = (0, tslib_1.__rest)(_a, ["tab", "tokenProvider", "channel", "logger", "inactivityRetryPolicy"]);
13
13
  this.listeners = [];
14
14
  this.pending = [];
15
15
  this.state = {
@@ -25,7 +25,7 @@ var Tracker = /** @class */ (function () {
25
25
  this.inactivityRetryPolicy = inactivityRetryPolicy;
26
26
  this.channel = channel;
27
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 : {} });
28
+ this.options = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, options), { eventMetadata: (_b = options.eventMetadata) !== null && _b !== void 0 ? _b : {} });
29
29
  this.enable = this.enable.bind(this);
30
30
  this.disable = this.disable.bind(this);
31
31
  this.suspend = this.suspend.bind(this);
@@ -161,8 +161,8 @@ var Tracker = /** @class */ (function () {
161
161
  return this.publish(this.enrichEvent(event, timestamp), timestamp).then(function () { return event; });
162
162
  };
163
163
  Tracker.prototype.trackPageOpen = function (_a) {
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 } : {})));
164
+ var referrer = _a.referrer, payload = (0, tslib_1.__rest)(_a, ["referrer"]);
165
+ this.enqueue((0, tslib_1.__assign)((0, tslib_1.__assign)({ type: 'pageOpened' }, payload), (referrer.length > 0 ? { referrer: referrer } : {})));
166
166
  };
167
167
  Tracker.prototype.trackPageLoad = function (_a) {
168
168
  var tab = _a.detail.tab;
@@ -174,7 +174,7 @@ var Tracker = /** @class */ (function () {
174
174
  });
175
175
  };
176
176
  Tracker.prototype.trackTabOpen = function (payload) {
177
- this.enqueue(tslib_1.__assign({ type: 'tabOpened' }, payload));
177
+ this.enqueue((0, tslib_1.__assign)({ type: 'tabOpened' }, payload));
178
178
  };
179
179
  Tracker.prototype.trackTabUrlChange = function (_a) {
180
180
  var detail = _a.detail;
@@ -213,7 +213,7 @@ var Tracker = /** @class */ (function () {
213
213
  this.stopInactivityTimer();
214
214
  }
215
215
  var metadata = this.options.eventMetadata;
216
- var context = tslib_1.__assign({ tabId: this.tab.id, url: this.tab.url }, (Object.keys(metadata).length > 0 ? { metadata: metadata } : {}));
216
+ var context = (0, tslib_1.__assign)({ tabId: this.tab.id, url: this.tab.url }, (Object.keys(metadata).length > 0 ? { metadata: metadata } : {}));
217
217
  var eventInfo = {
218
218
  event: event,
219
219
  context: context,
@@ -221,20 +221,20 @@ var Tracker = /** @class */ (function () {
221
221
  status: 'pending',
222
222
  };
223
223
  if (this.state.suspended) {
224
- this.logger.warn("Tracker is suspended, ignoring event \"" + event.type + "\"");
225
- this.notifyEvent(tslib_1.__assign(tslib_1.__assign({}, eventInfo), { status: 'ignored' }));
224
+ this.logger.warn("Tracker is suspended, ignoring event \"".concat(event.type, "\""));
225
+ this.notifyEvent((0, tslib_1.__assign)((0, tslib_1.__assign)({}, eventInfo), { status: 'ignored' }));
226
226
  return Promise.reject(new Error('The tracker is suspended.'));
227
227
  }
228
- this.logger.info("Tracked event \"" + event.type + "\"");
228
+ this.logger.info("Tracked event \"".concat(event.type, "\""));
229
229
  this.notifyEvent(eventInfo);
230
230
  return new Promise(function (resolve, reject) {
231
231
  var promise = _this.channel.publish(_this.createBeacon(event, timestamp, context)).then(function () {
232
- _this.logger.debug("Successfully published event \"" + event.type + "\"");
233
- _this.notifyEvent(tslib_1.__assign(tslib_1.__assign({}, eventInfo), { status: 'confirmed' }));
232
+ _this.logger.debug("Successfully published event \"".concat(event.type, "\""));
233
+ _this.notifyEvent((0, tslib_1.__assign)((0, tslib_1.__assign)({}, eventInfo), { status: 'confirmed' }));
234
234
  resolve(event);
235
235
  }, function (cause) {
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' }));
236
+ _this.logger.error("Failed to publish event \"".concat(event.type, "\", reason: ").concat((0, error_1.formatCause)(cause)));
237
+ _this.notifyEvent((0, tslib_1.__assign)((0, tslib_1.__assign)({}, eventInfo), { status: 'failed' }));
238
238
  reject(cause);
239
239
  });
240
240
  _this.pending.push(promise);
@@ -247,23 +247,23 @@ var Tracker = /** @class */ (function () {
247
247
  });
248
248
  };
249
249
  Tracker.prototype.enrichEvent = function (event, timestamp) {
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
+ if ((0, trackingEvents_1.isCartPartialEvent)(event)) {
251
+ var _a = event.cart, _b = _a.lastUpdateTime, lastUpdateTime = _b === void 0 ? timestamp : _b, cart = (0, tslib_1.__rest)(_a, ["lastUpdateTime"]), payload = (0, tslib_1.__rest)(event, ["cart"]);
252
+ return (0, tslib_1.__assign)((0, tslib_1.__assign)({}, payload), { cart: (0, tslib_1.__assign)((0, tslib_1.__assign)({}, cart), { lastUpdateTime: lastUpdateTime }) });
253
253
  }
254
254
  return event;
255
255
  };
256
256
  Tracker.prototype.createBeacon = function (event, timestamp, context) {
257
257
  var token = this.tokenProvider.getToken();
258
- return tslib_1.__assign(tslib_1.__assign({ timestamp: timestamp }, (token !== null ? { token: token.toString() } : {})), { context: context, payload: this.createBeaconPayload(event) });
258
+ return (0, tslib_1.__assign)((0, tslib_1.__assign)({ timestamp: timestamp }, (token !== null ? { token: token.toString() } : {})), { context: context, payload: this.enrichBeaconPayload(this.createBeaconPayload(event)) });
259
259
  };
260
260
  Tracker.prototype.createBeaconPayload = function (event) {
261
- if (!trackingEvents_1.isIdentifiedUserEvent(event)) {
261
+ if (!(0, trackingEvents_1.isIdentifiedUserEvent)(event)) {
262
262
  return event;
263
263
  }
264
264
  if (event.type === 'userSignedUp' && event.profile !== undefined) {
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: {
265
+ var userId_1 = event.userId, profile = event.profile, payload_1 = (0, tslib_1.__rest)(event, ["userId", "profile"]);
266
+ return (0, tslib_1.__assign)((0, tslib_1.__assign)({}, payload_1), { externalUserId: userId_1, patch: {
267
267
  operations: [
268
268
  {
269
269
  type: 'set',
@@ -273,8 +273,16 @@ var Tracker = /** @class */ (function () {
273
273
  ],
274
274
  } });
275
275
  }
276
- var userId = event.userId, payload = tslib_1.__rest(event, ["userId"]);
277
- return tslib_1.__assign(tslib_1.__assign({}, payload), { externalUserId: userId });
276
+ var userId = event.userId, payload = (0, tslib_1.__rest)(event, ["userId"]);
277
+ return (0, tslib_1.__assign)((0, tslib_1.__assign)({}, payload), { externalUserId: userId });
278
+ };
279
+ Tracker.prototype.enrichBeaconPayload = function (event) {
280
+ switch (event.type) {
281
+ case 'linkOpened':
282
+ return (0, tslib_1.__assign)((0, tslib_1.__assign)({}, event), { link: new URL(event.link, this.tab.url).toString() });
283
+ default:
284
+ return event;
285
+ }
278
286
  };
279
287
  return Tracker;
280
288
  }());
@@ -71,8 +71,8 @@ export declare const cartEventTypes: readonly ["cartModified", "cartViewed", "ch
71
71
  export declare const ecommerceEventTypes: readonly ["cartModified", "cartViewed", "checkoutStarted", "orderPlaced", "productViewed"];
72
72
  export declare const identifiedUserEventTypes: string[];
73
73
  export declare const userEventTypes: readonly [...string[], "userProfileChanged"];
74
- export declare const miscEventTypes: readonly ["nothingChanged", "sessionAttributesChanged", "testGroupAssigned", "goalCompleted", "eventOccurred"];
75
- export declare const eventTypes: readonly ["pageLoaded", "pageOpened", "cartModified", "cartViewed", "checkoutStarted", "orderPlaced", "productViewed", ...string[], "userProfileChanged", "nothingChanged", "sessionAttributesChanged", "testGroupAssigned", "goalCompleted", "eventOccurred"];
74
+ export declare const miscEventTypes: readonly ["nothingChanged", "sessionAttributesChanged", "goalCompleted", "interestShown", "postViewed", "eventOccurred", "linkOpened"];
75
+ export declare const eventTypes: readonly ["pageLoaded", "pageOpened", "cartModified", "cartViewed", "checkoutStarted", "orderPlaced", "productViewed", ...string[], "userProfileChanged", "nothingChanged", "sessionAttributesChanged", "goalCompleted", "interestShown", "postViewed", "eventOccurred", "linkOpened"];
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,11 @@ 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 interface LinkOpened extends BaseEvent {
239
+ type: 'linkOpened';
240
+ link: string;
241
+ }
242
+ export declare type MiscEvent = NothingChanged | SessionAttributesChanged | EventOccurred | GoalCompleted | InterestShown | PostViewed | LinkOpened;
226
243
  declare type EventMap = {
227
244
  tabVisibilityChanged: TabVisibilityChanged;
228
245
  tabUrlChanged: TabUrlChanged;
@@ -240,9 +257,11 @@ declare type EventMap = {
240
257
  orderPlaced: OrderPlaced;
241
258
  nothingChanged: NothingChanged;
242
259
  sessionAttributesChanged: SessionAttributesChanged;
243
- testGroupAssigned: TestGroupAssigned;
244
260
  goalCompleted: GoalCompleted;
261
+ interestShown: InterestShown;
262
+ postViewed: PostViewed;
245
263
  eventOccurred: EventOccurred;
264
+ linkOpened: LinkOpened;
246
265
  };
247
266
  export declare type TrackingEventType = keyof EventMap;
248
267
  export declare type TrackingEvent<T extends TrackingEventType = TrackingEventType> = T extends TrackingEventType ? EventMap[T] : EventMap[TrackingEventType];
@@ -261,8 +280,10 @@ declare type ExternalEventMap = {
261
280
  orderPlaced: OrderPlaced;
262
281
  productViewed: ProductViewed;
263
282
  userSignedUp: UserSignedUp;
264
- testGroupAssigned: TestGroupAssigned;
265
283
  goalCompleted: GoalCompleted;
284
+ interestShown: InterestShown;
285
+ postViewed: PostViewed;
286
+ linkOpened: LinkOpened;
266
287
  eventOccurred: EventOccurred;
267
288
  };
268
289
  export declare type ExternalTrackingEventType = keyof ExternalEventMap;
package/trackingEvents.js CHANGED
@@ -19,26 +19,28 @@ exports.cartEventTypes = [
19
19
  'cartViewed',
20
20
  'checkoutStarted',
21
21
  ];
22
- exports.ecommerceEventTypes = tslib_1.__spreadArray(tslib_1.__spreadArray([], tslib_1.__read(exports.cartEventTypes)), [
22
+ exports.ecommerceEventTypes = (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(exports.cartEventTypes), false), [
23
23
  'orderPlaced',
24
24
  'productViewed',
25
- ]);
25
+ ], false);
26
26
  exports.identifiedUserEventTypes = [
27
27
  'userSignedIn',
28
28
  'userSignedOut',
29
29
  'userSignedUp',
30
30
  ];
31
- exports.userEventTypes = tslib_1.__spreadArray(tslib_1.__spreadArray([], tslib_1.__read(exports.identifiedUserEventTypes)), [
31
+ exports.userEventTypes = (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(exports.identifiedUserEventTypes), false), [
32
32
  'userProfileChanged',
33
- ]);
33
+ ], false);
34
34
  exports.miscEventTypes = [
35
35
  'nothingChanged',
36
36
  'sessionAttributesChanged',
37
- 'testGroupAssigned',
38
37
  'goalCompleted',
38
+ 'interestShown',
39
+ 'postViewed',
39
40
  'eventOccurred',
41
+ 'linkOpened',
40
42
  ];
41
- 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));
43
+ exports.eventTypes = (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(exports.pageEventTypes), false), (0, tslib_1.__read)(exports.ecommerceEventTypes), false), (0, tslib_1.__read)(exports.userEventTypes), false), (0, tslib_1.__read)(exports.miscEventTypes), false);
42
44
  /*
43
45
  * Type guards
44
46
  */
package/uuid.js CHANGED
@@ -6,7 +6,7 @@ function uuid4(sortable) {
6
6
  var uuid = '';
7
7
  if (sortable) {
8
8
  var prefix = Date.now().toString(16).padStart(12, '0').substring(0, 12);
9
- uuid = prefix.substring(0, 8) + "-" + prefix.substring(8, 12);
9
+ uuid = "".concat(prefix.substring(0, 8), "-").concat(prefix.substring(8, 12));
10
10
  }
11
11
  for (var index = uuid.length; index < 36; index++) {
12
12
  switch (index) {
@@ -8,7 +8,7 @@ var ArrayType = /** @class */ (function () {
8
8
  function ArrayType(definition) {
9
9
  if (definition === void 0) { definition = {}; }
10
10
  var _a, _b;
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 });
11
+ this.definition = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, definition), { minItems: (_a = definition.minItems) !== null && _a !== void 0 ? _a : -1, maxItems: (_b = definition.maxItems) !== null && _b !== void 0 ? _b : -1 });
12
12
  }
13
13
  ArrayType.prototype.getTypes = function () {
14
14
  return ['array'];
@@ -19,19 +19,19 @@ var ArrayType = /** @class */ (function () {
19
19
  ArrayType.prototype.validate = function (value, path) {
20
20
  if (path === void 0) { path = []; }
21
21
  if (!this.isValidType(value)) {
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' });
22
+ throw new schema_1.Violation("Expected value of type array at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat((0, violation_1.describe)(value), "."), path, { type: 'string' });
23
23
  }
24
24
  var _a = this.definition, minItems = _a.minItems, maxItems = _a.maxItems;
25
25
  var length = value.length;
26
26
  if (minItems >= 0 && minItems > length) {
27
- throw new schema_1.Violation("Expected " + (minItems === maxItems ? 'exactly' : 'at least') + " "
28
- + (minItems + " " + (minItems === 1 ? 'item' : 'items') + " ")
29
- + ("at path '" + violation_1.formatPath(path) + "', actual " + length + "."), path, { limit: minItems });
27
+ throw new schema_1.Violation("Expected ".concat(minItems === maxItems ? 'exactly' : 'at least', " ")
28
+ + "".concat(minItems, " ").concat(minItems === 1 ? 'item' : 'items', " ")
29
+ + "at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat(length, "."), path, { limit: minItems });
30
30
  }
31
31
  if (maxItems >= 0 && maxItems < length) {
32
- throw new schema_1.Violation("Expected " + (minItems === maxItems ? 'exactly' : 'at most') + " "
33
- + (maxItems + " " + (maxItems === 1 ? 'item' : 'items') + " ")
34
- + ("at path '" + violation_1.formatPath(path) + "', actual " + length + "."), path, { limit: maxItems });
32
+ throw new schema_1.Violation("Expected ".concat(minItems === maxItems ? 'exactly' : 'at most', " ")
33
+ + "".concat(maxItems, " ").concat(maxItems === 1 ? 'item' : 'items', " ")
34
+ + "at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat(length, "."), path, { limit: maxItems });
35
35
  }
36
36
  if (this.definition.items === undefined) {
37
37
  return;
@@ -15,7 +15,7 @@ var BooleanType = /** @class */ (function () {
15
15
  BooleanType.prototype.validate = function (value, path) {
16
16
  if (path === void 0) { path = []; }
17
17
  if (!this.isValidType(value)) {
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' });
18
+ throw new schema_1.Violation("Expected value of type boolean at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat((0, violation_1.describe)(value), "."), path, { type: 'boolean' });
19
19
  }
20
20
  };
21
21
  return BooleanType;
@@ -15,7 +15,7 @@ var FunctionType = /** @class */ (function () {
15
15
  FunctionType.prototype.validate = function (value, path) {
16
16
  if (path === void 0) { path = []; }
17
17
  if (!this.isValidType(value)) {
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' });
18
+ throw new schema_1.Violation("Expected value of type function at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat((0, violation_1.describe)(value), "."), path, { type: 'function' });
19
19
  }
20
20
  };
21
21
  return FunctionType;
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
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
4
  var tslib_1 = require("tslib");
5
- tslib_1.__exportStar(require("./schema"), exports);
6
- tslib_1.__exportStar(require("./violation"), exports);
5
+ (0, tslib_1.__exportStar)(require("./schema"), exports);
6
+ (0, tslib_1.__exportStar)(require("./violation"), exports);
7
7
  var arrayType_1 = require("./arrayType");
8
8
  Object.defineProperty(exports, "ArrayType", { enumerable: true, get: function () { return arrayType_1.ArrayType; } });
9
9
  var booleanType_1 = require("./booleanType");
@@ -1,6 +1,7 @@
1
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;
@@ -35,15 +35,21 @@ var JsonObjectType = /** @class */ (function () {
35
35
  var e_1, _a;
36
36
  if (path === void 0) { path = []; }
37
37
  if (!isJsonObject(value)) {
38
- throw new schema_1.Violation("Expected a JSON object at path '" + violation_1.formatPath(path) + "', actual " + violation_1.describe(value) + ".", path, { type: 'object' });
38
+ throw new schema_1.Violation("Expected a JSON object at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat((0, violation_1.describe)(value), "."), path, { type: 'object' });
39
39
  }
40
- if (this.definition.properties === undefined) {
40
+ if (this.definition.properties === undefined && this.definition.propertyNames === undefined) {
41
41
  return;
42
42
  }
43
43
  try {
44
- for (var _b = tslib_1.__values(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
45
- var _d = tslib_1.__read(_c.value, 2), entryName = _d[0], entryValue = _d[1];
46
- this.definition.properties.validate(entryValue, path.concat([entryName]));
44
+ for (var _b = (0, tslib_1.__values)(Object.entries(value)), _c = _b.next(); !_c.done; _c = _b.next()) {
45
+ var _d = (0, tslib_1.__read)(_c.value, 2), entryName = _d[0], entryValue = _d[1];
46
+ var propertyPath = path.concat([entryName]);
47
+ if (this.definition.propertyNames !== undefined) {
48
+ this.definition.propertyNames.validate(entryName, propertyPath);
49
+ }
50
+ if (this.definition.properties !== undefined) {
51
+ this.definition.properties.validate(entryValue, path.concat([entryName]));
52
+ }
47
53
  }
48
54
  }
49
55
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
@@ -71,7 +77,7 @@ var JsonArrayType = /** @class */ (function () {
71
77
  JsonArrayType.prototype.validate = function (value, path) {
72
78
  if (path === void 0) { path = []; }
73
79
  if (!isJsonArray(value)) {
74
- throw new schema_1.Violation("Expected a JSON array at path '" + violation_1.formatPath(path) + "', actual " + violation_1.describe(value) + ".", path, { type: 'array' });
80
+ throw new schema_1.Violation("Expected a JSON array at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat((0, violation_1.describe)(value), "."), path, { type: 'array' });
75
81
  }
76
82
  if (this.definition.items === undefined) {
77
83
  return;
@@ -95,7 +101,7 @@ var JsonPrimitiveType = /** @class */ (function () {
95
101
  JsonPrimitiveType.prototype.validate = function (value, path) {
96
102
  if (path === void 0) { path = []; }
97
103
  if (!this.isValidType(value)) {
98
- throw new schema_1.Violation("Expected a JSON primitive at path '" + violation_1.formatPath(path) + "', actual " + violation_1.describe(value) + ".", path, { type: this.getTypes().join('|') });
104
+ throw new schema_1.Violation("Expected a JSON primitive at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat((0, violation_1.describe)(value), "."), path, { type: this.getTypes().join('|') });
99
105
  }
100
106
  };
101
107
  return JsonPrimitiveType;
@@ -113,7 +119,7 @@ var JsonType = /** @class */ (function () {
113
119
  JsonType.prototype.validate = function (value, path) {
114
120
  if (path === void 0) { path = []; }
115
121
  if (!isJsonValue(value)) {
116
- throw new schema_1.Violation("Expected a JSON value at path '" + violation_1.formatPath(path) + "', actual " + violation_1.describe(value) + ".", path, { type: this.getTypes().join('|') });
122
+ throw new schema_1.Violation("Expected a JSON value at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat((0, violation_1.describe)(value), "."), path, { type: this.getTypes().join('|') });
117
123
  }
118
124
  };
119
125
  return JsonType;
@@ -15,7 +15,7 @@ var NullType = /** @class */ (function () {
15
15
  NullType.prototype.validate = function (value, path) {
16
16
  if (path === void 0) { path = []; }
17
17
  if (!this.isValidType(value)) {
18
- throw new schema_1.Violation("Expected value of type null at path '" + violation_1.formatPath(path) + "', actual " + violation_1.describe(value) + ".", path, { type: 'null' });
18
+ throw new schema_1.Violation("Expected value of type null at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat((0, violation_1.describe)(value), "."), path, { type: 'null' });
19
19
  }
20
20
  };
21
21
  return NullType;
@@ -8,7 +8,7 @@ var NumberType = /** @class */ (function () {
8
8
  function NumberType(definition) {
9
9
  if (definition === void 0) { definition = {}; }
10
10
  var _a, _b, _c;
11
- this.definition = tslib_1.__assign(tslib_1.__assign({}, definition), { integer: (_a = definition.integer) !== null && _a !== void 0 ? _a : false, minimum: (_b = definition.minimum) !== null && _b !== void 0 ? _b : Number.NEGATIVE_INFINITY, maximum: (_c = definition.maximum) !== null && _c !== void 0 ? _c : Number.POSITIVE_INFINITY });
11
+ this.definition = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, definition), { integer: (_a = definition.integer) !== null && _a !== void 0 ? _a : false, minimum: (_b = definition.minimum) !== null && _b !== void 0 ? _b : Number.NEGATIVE_INFINITY, maximum: (_c = definition.maximum) !== null && _c !== void 0 ? _c : Number.POSITIVE_INFINITY });
12
12
  }
13
13
  NumberType.prototype.getTypes = function () {
14
14
  return [this.definition.integer ? 'integer' : 'number'];
@@ -20,15 +20,15 @@ var NumberType = /** @class */ (function () {
20
20
  if (path === void 0) { path = []; }
21
21
  if (!this.isValidType(value)) {
22
22
  var type = this.getTypes()[0];
23
- throw new schema_1.Violation("Expected value of type " + type + " at path '" + violation_1.formatPath(path) + "', actual " + violation_1.describe(value) + ".", path, { type: type });
23
+ throw new schema_1.Violation("Expected value of type ".concat(type, " at path '").concat((0, violation_1.formatPath)(path), "', actual ").concat((0, violation_1.describe)(value), "."), path, { type: type });
24
24
  }
25
25
  if (value < this.definition.minimum) {
26
- throw new schema_1.Violation("Expected a value greater than or equal to " + this.definition.minimum + " "
27
- + ("at path '" + violation_1.formatPath(path) + "', actual " + value + "."), path, { limit: this.definition.minimum });
26
+ throw new schema_1.Violation("Expected a value greater than or equal to ".concat(this.definition.minimum, " ")
27
+ + "at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat(value, "."), path, { limit: this.definition.minimum });
28
28
  }
29
29
  if (value > this.definition.maximum) {
30
- throw new schema_1.Violation("Expected a value less than or equal to " + this.definition.maximum + " "
31
- + ("at path '" + violation_1.formatPath(path) + "', actual " + value + "."), path, { limit: this.definition.maximum });
30
+ throw new schema_1.Violation("Expected a value less than or equal to ".concat(this.definition.maximum, " ")
31
+ + "at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat(value, "."), path, { limit: this.definition.maximum });
32
32
  }
33
33
  };
34
34
  return NumberType;
@@ -9,7 +9,7 @@ var ObjectType = /** @class */ (function () {
9
9
  function ObjectType(schema) {
10
10
  if (schema === void 0) { schema = {}; }
11
11
  var _a, _b, _c, _d, _e, _f;
12
- this.definition = tslib_1.__assign(tslib_1.__assign({}, schema), { properties: (_a = schema.properties) !== null && _a !== void 0 ? _a : {}, required: (_b = schema.required) !== null && _b !== void 0 ? _b : [], additionalProperties: (_c = schema.additionalProperties) !== null && _c !== void 0 ? _c : false, propertyNames: (_d = schema.propertyNames) !== null && _d !== void 0 ? _d : new mixedSchema_1.MixedSchema(), minProperties: (_e = schema.minProperties) !== null && _e !== void 0 ? _e : -1, maxProperties: (_f = schema.maxProperties) !== null && _f !== void 0 ? _f : -1 });
12
+ this.definition = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, schema), { properties: (_a = schema.properties) !== null && _a !== void 0 ? _a : {}, required: (_b = schema.required) !== null && _b !== void 0 ? _b : [], additionalProperties: (_c = schema.additionalProperties) !== null && _c !== void 0 ? _c : false, propertyNames: (_d = schema.propertyNames) !== null && _d !== void 0 ? _d : new mixedSchema_1.MixedSchema(), minProperties: (_e = schema.minProperties) !== null && _e !== void 0 ? _e : -1, maxProperties: (_f = schema.maxProperties) !== null && _f !== void 0 ? _f : -1 });
13
13
  }
14
14
  ObjectType.prototype.getTypes = function () {
15
15
  if (this.definition.type !== undefined) {
@@ -28,28 +28,28 @@ var ObjectType = /** @class */ (function () {
28
28
  var e_1, _a, e_2, _b;
29
29
  if (path === void 0) { path = []; }
30
30
  if (!this.isValidType(value)) {
31
- var _c = tslib_1.__read(this.getTypes(), 1), type = _c[0];
32
- throw new schema_1.Violation("Expected value of type " + type + " at path '" + violation_1.formatPath(path) + "', "
33
- + ("actual " + violation_1.describe(value) + "."), path, { type: type });
31
+ var _c = (0, tslib_1.__read)(this.getTypes(), 1), type = _c[0];
32
+ throw new schema_1.Violation("Expected value of type ".concat(type, " at path '").concat((0, violation_1.formatPath)(path), "', ")
33
+ + "actual ".concat((0, violation_1.describe)(value), "."), path, { type: type });
34
34
  }
35
35
  var entries = Object.entries(value);
36
36
  var _d = this.definition, minProperties = _d.minProperties, maxProperties = _d.maxProperties;
37
37
  if (minProperties >= 0 && minProperties > entries.length) {
38
- throw new schema_1.Violation("Expected " + (minProperties === maxProperties ? 'exactly' : 'at least') + " "
39
- + (minProperties + " " + (minProperties === 1 ? 'entry' : 'entries') + " ")
40
- + ("at path '" + violation_1.formatPath(path) + "', actual " + entries.length + "."), path, { limit: minProperties });
38
+ throw new schema_1.Violation("Expected ".concat(minProperties === maxProperties ? 'exactly' : 'at least', " ")
39
+ + "".concat(minProperties, " ").concat(minProperties === 1 ? 'entry' : 'entries', " ")
40
+ + "at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat(entries.length, "."), path, { limit: minProperties });
41
41
  }
42
42
  if (maxProperties >= 0 && maxProperties < entries.length) {
43
- throw new schema_1.Violation("Expected " + (minProperties === maxProperties ? 'exactly' : 'at most') + " "
44
- + (maxProperties + " " + (maxProperties === 1 ? 'entry' : 'entries') + " ")
45
- + ("at path '" + violation_1.formatPath(path) + "', actual " + entries.length + "."), path, { limit: maxProperties });
43
+ throw new schema_1.Violation("Expected ".concat(minProperties === maxProperties ? 'exactly' : 'at most', " ")
44
+ + "".concat(maxProperties, " ").concat(maxProperties === 1 ? 'entry' : 'entries', " ")
45
+ + "at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat(entries.length, "."), path, { limit: maxProperties });
46
46
  }
47
- var additionalProperties = tslib_1.__assign({}, value);
47
+ var additionalProperties = (0, tslib_1.__assign)({}, value);
48
48
  try {
49
- for (var _e = tslib_1.__values(this.definition.required), _f = _e.next(); !_f.done; _f = _e.next()) {
49
+ for (var _e = (0, tslib_1.__values)(this.definition.required), _f = _e.next(); !_f.done; _f = _e.next()) {
50
50
  var property = _f.value;
51
51
  if (!(property in value)) {
52
- throw new schema_1.Violation("Missing property '" + violation_1.formatPath(path.concat([property])) + "'.", path, {
52
+ throw new schema_1.Violation("Missing property '".concat((0, violation_1.formatPath)(path.concat([property])), "'."), path, {
53
53
  required: property,
54
54
  });
55
55
  }
@@ -63,8 +63,8 @@ var ObjectType = /** @class */ (function () {
63
63
  finally { if (e_1) throw e_1.error; }
64
64
  }
65
65
  try {
66
- for (var entries_1 = tslib_1.__values(entries), entries_1_1 = entries_1.next(); !entries_1_1.done; entries_1_1 = entries_1.next()) {
67
- var _g = tslib_1.__read(entries_1_1.value, 2), entryName = _g[0], entryValue = _g[1];
66
+ for (var entries_1 = (0, tslib_1.__values)(entries), entries_1_1 = entries_1.next(); !entries_1_1.done; entries_1_1 = entries_1.next()) {
67
+ var _g = (0, tslib_1.__read)(entries_1_1.value, 2), entryName = _g[0], entryValue = _g[1];
68
68
  var propertyPath = path.concat([entryName]);
69
69
  this.definition.propertyNames.validate(entryName, propertyPath);
70
70
  var propertyRule = this.definition.properties[entryName];
@@ -74,7 +74,7 @@ var ObjectType = /** @class */ (function () {
74
74
  continue;
75
75
  }
76
76
  if (this.definition.additionalProperties === false) {
77
- throw new schema_1.Violation("Unknown property '" + violation_1.formatPath(propertyPath) + "'.", propertyPath, {
77
+ throw new schema_1.Violation("Unknown property '".concat((0, violation_1.formatPath)(propertyPath), "'."), propertyPath, {
78
78
  additionalProperty: entryName,
79
79
  });
80
80
  }
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Violation = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var Violation = /** @class */ (function (_super) {
6
- tslib_1.__extends(Violation, _super);
6
+ (0, tslib_1.__extends)(Violation, _super);
7
7
  function Violation(message, path, params) {
8
8
  var _this = _super.call(this, message) || this;
9
9
  _this.path = path;