@croct/sdk 0.7.0 → 0.9.1

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 (56) hide show
  1. package/activeRecord.d.ts +4 -3
  2. package/activeRecord.js +8 -0
  3. package/channel/beaconSocketChannel.js +1 -1
  4. package/channel/guaranteedChannel.js +4 -4
  5. package/channel/queuedChannel.js +3 -3
  6. package/channel/retryChannel.js +2 -2
  7. package/channel/socketChannel.js +2 -2
  8. package/cid/remoteAssigner.js +1 -1
  9. package/constants.js +1 -1
  10. package/container.d.ts +1 -0
  11. package/container.js +13 -7
  12. package/context.js +1 -1
  13. package/evaluator.d.ts +1 -1
  14. package/evaluator.js +6 -6
  15. package/facade/evaluatorFacade.d.ts +1 -1
  16. package/facade/evaluatorFacade.js +1 -1
  17. package/facade/sdkFacade.d.ts +1 -0
  18. package/facade/sdkFacade.js +8 -8
  19. package/facade/trackerFacade.js +3 -2
  20. package/logging/consoleLogger.js +1 -1
  21. package/logging/namespacedLogger.js +1 -1
  22. package/namespacedStorage.js +1 -1
  23. package/package.json +13 -12
  24. package/patch.d.ts +12 -8
  25. package/queue/inMemoryQueue.js +1 -1
  26. package/queue/monitoredQueue.js +1 -1
  27. package/retry/arbitraryPolicy.js +1 -1
  28. package/schema/eventSchemas.d.ts +1 -0
  29. package/schema/eventSchemas.js +9 -1
  30. package/schema/operationSchemas.d.ts +1 -0
  31. package/schema/operationSchemas.js +8 -1
  32. package/schema/sdkFacadeSchemas.js +1 -0
  33. package/schema/sdkSchemas.js +1 -0
  34. package/schema/tokenSchema.js +1 -1
  35. package/sdk.d.ts +1 -0
  36. package/sdk.js +11 -10
  37. package/sourceLocation.js +2 -2
  38. package/token/token.d.ts +1 -1
  39. package/token/token.js +8 -8
  40. package/tracker.d.ts +1 -0
  41. package/tracker.js +15 -7
  42. package/trackingEvents.d.ts +9 -3
  43. package/trackingEvents.js +6 -5
  44. package/uuid.js +1 -1
  45. package/validation/arrayType.js +7 -7
  46. package/validation/booleanType.js +1 -1
  47. package/validation/functionType.js +1 -1
  48. package/validation/jsonType.js +4 -4
  49. package/validation/nullType.js +1 -1
  50. package/validation/numberType.js +5 -5
  51. package/validation/objectType.js +10 -10
  52. package/validation/stringType.js +27 -15
  53. package/validation/unionType.js +3 -3
  54. package/validation/violation.js +1 -1
  55. package/json.d.ts +0 -11
  56. package/json.js +0 -2
@@ -16,6 +16,7 @@ exports.sdkFacadeConfigurationSchema = new validation_1.ObjectType({
16
16
  }),
17
17
  tokenScope: contextSchemas_1.tokenScopeSchema,
18
18
  debug: new validation_1.BooleanType(),
19
+ test: new validation_1.BooleanType(),
19
20
  track: new validation_1.BooleanType(),
20
21
  logger: loggerSchema_1.loggerSchema,
21
22
  urlSanitizer: new validation_1.FunctionType(),
@@ -39,6 +39,7 @@ exports.sdkConfigurationSchema = new validation_1.ObjectType({
39
39
  integer: true,
40
40
  }),
41
41
  debug: new validation_1.BooleanType(),
42
+ test: new validation_1.BooleanType(),
42
43
  logger: loggerSchema_1.loggerSchema,
43
44
  urlSanitizer: new validation_1.FunctionType(),
44
45
  eventMetadata: exports.eventMetadataSchema,
@@ -20,7 +20,7 @@ exports.tokenSchema = new validation_1.ObjectType({
20
20
  required: ['iss', 'aud', 'iat'],
21
21
  properties: {
22
22
  iss: new validation_1.StringType(),
23
- aud: new validation_1.StringType(),
23
+ aud: new validation_1.UnionType(new validation_1.StringType(), new validation_1.ArrayType({ items: new validation_1.StringType() })),
24
24
  iat: new validation_1.NumberType({
25
25
  minimum: 0,
26
26
  }),
package/sdk.d.ts CHANGED
@@ -10,6 +10,7 @@ export declare type Configuration = {
10
10
  appId: string;
11
11
  tokenScope: TokenScope;
12
12
  debug: boolean;
13
+ test: boolean;
13
14
  cid?: string;
14
15
  trackerEndpointUrl?: string;
15
16
  evaluationEndpointUrl?: string;
package/sdk.js CHANGED
@@ -14,7 +14,7 @@ function validateConfiguration(configuration) {
14
14
  schema_1.sdkConfigurationSchema.validate(configuration);
15
15
  }
16
16
  catch (violation) {
17
- throw new Error("Invalid configuration: " + error_1.formatCause(violation));
17
+ throw new Error("Invalid configuration: ".concat((0, error_1.formatCause)(violation)));
18
18
  }
19
19
  }
20
20
  var Sdk = /** @class */ (function () {
@@ -32,7 +32,7 @@ var Sdk = /** @class */ (function () {
32
32
  try {
33
33
  for (var _g = tslib_1.__values(Object.keys(customMetadata)), _h = _g.next(); !_h.done; _h = _g.next()) {
34
34
  var metadata = _h.value;
35
- eventMetadata["custom_" + metadata] = customMetadata[metadata];
35
+ eventMetadata["custom_".concat(metadata)] = customMetadata[metadata];
36
36
  }
37
37
  }
38
38
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
@@ -52,14 +52,15 @@ var Sdk = /** @class */ (function () {
52
52
  + '██  ██   ██ ██  ██ ██  ██    \n'
53
53
  + ' ██████ ██  ██  ██████   ██████  ██    \n'
54
54
  + '\n');
55
- logger.info("Initializing SDK v" + constants_1.VERSION + "...");
56
- logger.debug("App ID: " + appId);
55
+ logger.info("Initializing SDK v".concat(constants_1.VERSION, "..."));
56
+ logger.debug("App ID: ".concat(appId));
57
57
  var context = container.getContext();
58
58
  var tab = context.getTab();
59
59
  var user = context.getUser();
60
- logger.debug((tab.isNew ? 'New' : 'Current') + " tab: " + tab.id);
61
- logger.debug("Token scope: " + tokenScope);
62
- logger.debug("Current user: " + (user !== null ? user : 'anonymous'));
60
+ logger.debug("".concat(tab.isNew ? 'New' : 'Current', " tab: ").concat(tab.id));
61
+ logger.debug("Token scope: ".concat(tokenScope));
62
+ logger.debug("Current user: ".concat(user !== null ? user : 'anonymous'));
63
+ logger.debug("Test mode: ".concat(containerConfiguration.test));
63
64
  logger.info('⚡ Croct SDK is ready!');
64
65
  return new Sdk(container);
65
66
  };
@@ -112,7 +113,7 @@ var Sdk = /** @class */ (function () {
112
113
  for (var _i = 0; _i < arguments.length; _i++) {
113
114
  namespace[_i] = arguments[_i];
114
115
  }
115
- return (_a = this.container).getLogger.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(namespace)));
116
+ return (_a = this.container).getLogger.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(namespace), false));
116
117
  };
117
118
  Sdk.prototype.getTabStorage = function (namespace) {
118
119
  var _a;
@@ -120,7 +121,7 @@ var Sdk = /** @class */ (function () {
120
121
  for (var _i = 1; _i < arguments.length; _i++) {
121
122
  subnamespace[_i - 1] = arguments[_i];
122
123
  }
123
- return (_a = this.container).getTabStorage.apply(_a, tslib_1.__spreadArray([namespace], tslib_1.__read(subnamespace)));
124
+ return (_a = this.container).getTabStorage.apply(_a, tslib_1.__spreadArray([namespace], tslib_1.__read(subnamespace), false));
124
125
  };
125
126
  Sdk.prototype.getBrowserStorage = function (namespace) {
126
127
  var _a;
@@ -128,7 +129,7 @@ var Sdk = /** @class */ (function () {
128
129
  for (var _i = 1; _i < arguments.length; _i++) {
129
130
  subnamespace[_i - 1] = arguments[_i];
130
131
  }
131
- return (_a = this.container).getBrowserStorage.apply(_a, tslib_1.__spreadArray([namespace], tslib_1.__read(subnamespace)));
132
+ return (_a = this.container).getBrowserStorage.apply(_a, tslib_1.__spreadArray([namespace], tslib_1.__read(subnamespace), false));
132
133
  };
133
134
  Sdk.prototype.close = function () {
134
135
  return tslib_1.__awaiter(this, void 0, void 0, function () {
package/sourceLocation.js CHANGED
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getLocation = exports.getPosition = exports.getLength = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  function getLength(input) {
6
- return tslib_1.__spreadArray([], tslib_1.__read(input)).length;
6
+ return tslib_1.__spreadArray([], tslib_1.__read(input), false).length;
7
7
  }
8
8
  exports.getLength = getLength;
9
9
  function getPosition(input, index) {
@@ -19,7 +19,7 @@ function getLocation(input, startIndex, endIndex) {
19
19
  }
20
20
  var start;
21
21
  var end;
22
- var chars = tslib_1.__spreadArray([], tslib_1.__read(input));
22
+ var chars = tslib_1.__spreadArray([], tslib_1.__read(input), false);
23
23
  var line = 1;
24
24
  var column = 0;
25
25
  for (var offset = 0; offset < chars.length; offset++) {
package/token/token.d.ts CHANGED
@@ -6,7 +6,7 @@ export declare type Headers = {
6
6
  };
7
7
  export declare type Claims = {
8
8
  iss: string;
9
- aud: string;
9
+ aud: string | string[];
10
10
  iat: number;
11
11
  exp?: number;
12
12
  sub?: string;
package/token/token.js CHANGED
@@ -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,7 +53,7 @@ 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
  };
@@ -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
@@ -221,19 +221,19 @@ 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 + "\"");
224
+ this.logger.warn("Tracker is suspended, ignoring event \"".concat(event.type, "\""));
225
225
  this.notifyEvent(tslib_1.__assign(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 + "\"");
232
+ _this.logger.debug("Successfully published event \"".concat(event.type, "\""));
233
233
  _this.notifyEvent(tslib_1.__assign(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));
236
+ _this.logger.error("Failed to publish event \"".concat(event.type, "\", reason: ").concat((0, error_1.formatCause)(cause)));
237
237
  _this.notifyEvent(tslib_1.__assign(tslib_1.__assign({}, eventInfo), { status: 'failed' }));
238
238
  reject(cause);
239
239
  });
@@ -247,7 +247,7 @@ var Tracker = /** @class */ (function () {
247
247
  });
248
248
  };
249
249
  Tracker.prototype.enrichEvent = function (event, timestamp) {
250
- if (trackingEvents_1.isCartPartialEvent(event)) {
250
+ if ((0, trackingEvents_1.isCartPartialEvent)(event)) {
251
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
252
  return tslib_1.__assign(tslib_1.__assign({}, payload), { cart: tslib_1.__assign(tslib_1.__assign({}, cart), { lastUpdateTime: lastUpdateTime }) });
253
253
  }
@@ -255,10 +255,10 @@ var Tracker = /** @class */ (function () {
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 tslib_1.__assign(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) {
@@ -276,6 +276,14 @@ var Tracker = /** @class */ (function () {
276
276
  var userId = event.userId, payload = tslib_1.__rest(event, ["userId"]);
277
277
  return tslib_1.__assign(tslib_1.__assign({}, payload), { externalUserId: userId });
278
278
  };
279
+ Tracker.prototype.enrichBeaconPayload = function (event) {
280
+ switch (event.type) {
281
+ case 'linkOpened':
282
+ return tslib_1.__assign(tslib_1.__assign({}, event), { link: new URL(event.link, this.tab.url).toString() });
283
+ default:
284
+ return event;
285
+ }
286
+ };
279
287
  return Tracker;
280
288
  }());
281
289
  exports.Tracker = Tracker;
@@ -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", "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"];
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
  }
@@ -235,7 +235,11 @@ export interface EventOccurred extends BaseEvent {
235
235
  [key: string]: string | number | boolean | null;
236
236
  };
237
237
  }
238
- export declare type MiscEvent = NothingChanged | SessionAttributesChanged | EventOccurred | GoalCompleted | InterestShown | PostViewed;
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;
239
243
  declare type EventMap = {
240
244
  tabVisibilityChanged: TabVisibilityChanged;
241
245
  tabUrlChanged: TabUrlChanged;
@@ -257,6 +261,7 @@ declare type EventMap = {
257
261
  interestShown: InterestShown;
258
262
  postViewed: PostViewed;
259
263
  eventOccurred: EventOccurred;
264
+ linkOpened: LinkOpened;
260
265
  };
261
266
  export declare type TrackingEventType = keyof EventMap;
262
267
  export declare type TrackingEvent<T extends TrackingEventType = TrackingEventType> = T extends TrackingEventType ? EventMap[T] : EventMap[TrackingEventType];
@@ -278,6 +283,7 @@ declare type ExternalEventMap = {
278
283
  goalCompleted: GoalCompleted;
279
284
  interestShown: InterestShown;
280
285
  postViewed: PostViewed;
286
+ linkOpened: LinkOpened;
281
287
  eventOccurred: EventOccurred;
282
288
  };
283
289
  export declare type ExternalTrackingEventType = keyof ExternalEventMap;
package/trackingEvents.js CHANGED
@@ -19,18 +19,18 @@ 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 = tslib_1.__spreadArray(tslib_1.__spreadArray([], 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 = tslib_1.__spreadArray(tslib_1.__spreadArray([], tslib_1.__read(exports.identifiedUserEventTypes), false), [
32
32
  'userProfileChanged',
33
- ]);
33
+ ], false);
34
34
  exports.miscEventTypes = [
35
35
  'nothingChanged',
36
36
  'sessionAttributesChanged',
@@ -38,8 +38,9 @@ exports.miscEventTypes = [
38
38
  'interestShown',
39
39
  'postViewed',
40
40
  'eventOccurred',
41
+ 'linkOpened',
41
42
  ];
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));
43
+ exports.eventTypes = tslib_1.__spreadArray(tslib_1.__spreadArray(tslib_1.__spreadArray(tslib_1.__spreadArray([], tslib_1.__read(exports.pageEventTypes), false), tslib_1.__read(exports.ecommerceEventTypes), false), tslib_1.__read(exports.userEventTypes), false), tslib_1.__read(exports.miscEventTypes), false);
43
44
  /*
44
45
  * Type guards
45
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) {
@@ -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;
@@ -35,7 +35,7 @@ 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
40
  if (this.definition.properties === undefined && this.definition.propertyNames === undefined) {
41
41
  return;
@@ -77,7 +77,7 @@ var JsonArrayType = /** @class */ (function () {
77
77
  JsonArrayType.prototype.validate = function (value, path) {
78
78
  if (path === void 0) { path = []; }
79
79
  if (!isJsonArray(value)) {
80
- 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' });
81
81
  }
82
82
  if (this.definition.items === undefined) {
83
83
  return;
@@ -101,7 +101,7 @@ var JsonPrimitiveType = /** @class */ (function () {
101
101
  JsonPrimitiveType.prototype.validate = function (value, path) {
102
102
  if (path === void 0) { path = []; }
103
103
  if (!this.isValidType(value)) {
104
- 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('|') });
105
105
  }
106
106
  };
107
107
  return JsonPrimitiveType;
@@ -119,7 +119,7 @@ var JsonType = /** @class */ (function () {
119
119
  JsonType.prototype.validate = function (value, path) {
120
120
  if (path === void 0) { path = []; }
121
121
  if (!isJsonValue(value)) {
122
- 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('|') });
123
123
  }
124
124
  };
125
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;
@@ -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;
@@ -29,27 +29,27 @@ var ObjectType = /** @class */ (function () {
29
29
  if (path === void 0) { path = []; }
30
30
  if (!this.isValidType(value)) {
31
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 });
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
47
  var additionalProperties = tslib_1.__assign({}, value);
48
48
  try {
49
49
  for (var _e = 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
  }
@@ -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
  }
@@ -5,7 +5,7 @@ var tslib_1 = require("tslib");
5
5
  var schema_1 = require("./schema");
6
6
  var violation_1 = require("./violation");
7
7
  var FORMAT = {
8
- pointer: function identifier(value) {
8
+ pointer: function pointer(value) {
9
9
  return /^(\.|([a-zA-Z_][a-zA-Z0-9_]*|\[[0-9]+])(\.[a-zA-Z_][a-zA-Z0-9_]*|\[[0-9]+])*)$/.test(value);
10
10
  },
11
11
  identifier: function identifier(value) {
@@ -17,7 +17,7 @@ var FORMAT = {
17
17
  date: function date(value) {
18
18
  return /^(\d\d\d\d)-(\d\d)-(\d\d)$/.test(value);
19
19
  },
20
- url: function date(value) {
20
+ url: function url(value) {
21
21
  try {
22
22
  // eslint-disable-next-line no-new
23
23
  new URL(value);
@@ -27,6 +27,18 @@ var FORMAT = {
27
27
  }
28
28
  return true;
29
29
  },
30
+ 'uri-reference': function uriReference(value) {
31
+ try {
32
+ // This simplistic approach covers the most common cases
33
+ // without inflating the library with an RFC 3986-compliant parser.
34
+ // eslint-disable-next-line no-new
35
+ new URL(value, 'http://any.thing');
36
+ }
37
+ catch (_a) {
38
+ return false;
39
+ }
40
+ return true;
41
+ },
30
42
  };
31
43
  var StringType = /** @class */ (function () {
32
44
  function StringType(definition) {
@@ -43,33 +55,33 @@ var StringType = /** @class */ (function () {
43
55
  StringType.prototype.validate = function (value, path) {
44
56
  if (path === void 0) { path = []; }
45
57
  if (!this.isValidType(value)) {
46
- throw new schema_1.Violation("Expected value of type string at path '" + violation_1.formatPath(path) + "', actual " + violation_1.describe(value) + ".", path, { type: 'string' });
58
+ throw new schema_1.Violation("Expected value of type string at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat((0, violation_1.describe)(value), "."), path, { type: 'string' });
47
59
  }
48
60
  var _a = this.definition, minLength = _a.minLength, maxLength = _a.maxLength;
49
61
  if (minLength >= 0 && minLength > value.length) {
50
- throw new schema_1.Violation("Expected " + (minLength === maxLength ? 'exactly' : 'at least') + " "
51
- + (minLength + " " + (minLength === 1 ? 'character' : 'characters') + " ")
52
- + ("at path '" + violation_1.formatPath(path) + "', actual " + value.length + "."), path, { limit: minLength });
62
+ throw new schema_1.Violation("Expected ".concat(minLength === maxLength ? 'exactly' : 'at least', " ")
63
+ + "".concat(minLength, " ").concat(minLength === 1 ? 'character' : 'characters', " ")
64
+ + "at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat(value.length, "."), path, { limit: minLength });
53
65
  }
54
66
  if (maxLength >= 0 && maxLength < value.length) {
55
- throw new schema_1.Violation("Expected " + (minLength === maxLength ? 'exactly' : 'at most') + " "
56
- + (maxLength + " " + (maxLength === 1 ? 'character' : 'characters') + " ")
57
- + ("at path '" + violation_1.formatPath(path) + "', actual " + value.length + "."), path, { limit: maxLength });
67
+ throw new schema_1.Violation("Expected ".concat(minLength === maxLength ? 'exactly' : 'at most', " ")
68
+ + "".concat(maxLength, " ").concat(maxLength === 1 ? 'character' : 'characters', " ")
69
+ + "at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat(value.length, "."), path, { limit: maxLength });
58
70
  }
59
71
  var enumeration = this.definition.enumeration;
60
72
  if (enumeration.length > 0 && enumeration.indexOf(value) < 0) {
61
- throw new schema_1.Violation("Unexpected value at path '" + violation_1.formatPath(path) + "', expecting "
62
- + ("'" + (enumeration.length === 1
73
+ throw new schema_1.Violation("Unexpected value at path '".concat((0, violation_1.formatPath)(path), "', expecting ")
74
+ + "'".concat(enumeration.length === 1
63
75
  ? enumeration[0]
64
- : enumeration.slice(0, -1).join('\', \'') + "' or '" + enumeration.slice(-1)) + "', ")
65
- + ("found '" + value + "'."), path, { enumeration: enumeration });
76
+ : "".concat(enumeration.slice(0, -1).join('\', \''), "' or '").concat(enumeration.slice(-1)), "', ")
77
+ + "found '".concat(value, "'."), path, { enumeration: enumeration });
66
78
  }
67
79
  var _b = this.definition, format = _b.format, pattern = _b.pattern;
68
80
  if (format !== undefined && !FORMAT[format](value)) {
69
- throw new schema_1.Violation("Invalid " + format + " format at path '" + violation_1.formatPath(path) + "'.", path, { format: format });
81
+ throw new schema_1.Violation("Invalid ".concat(format, " format at path '").concat((0, violation_1.formatPath)(path), "'."), path, { format: format });
70
82
  }
71
83
  if (pattern !== undefined && !pattern.test(value)) {
72
- throw new schema_1.Violation("Invalid format at path '" + violation_1.formatPath(path) + "'.", path, { pattern: pattern });
84
+ throw new schema_1.Violation("Invalid format at path '".concat((0, violation_1.formatPath)(path), "'."), path, { pattern: pattern });
73
85
  }
74
86
  };
75
87
  return StringType;
@@ -10,7 +10,7 @@ var UnionType = /** @class */ (function () {
10
10
  for (var _i = 2; _i < arguments.length; _i++) {
11
11
  others[_i - 2] = arguments[_i];
12
12
  }
13
- this.schemas = tslib_1.__spreadArray([first, second], tslib_1.__read(others));
13
+ this.schemas = tslib_1.__spreadArray([first, second], tslib_1.__read(others), false);
14
14
  }
15
15
  UnionType.prototype.getTypes = function () {
16
16
  var e_1, _a, e_2, _b;
@@ -83,8 +83,8 @@ var UnionType = /** @class */ (function () {
83
83
  finally { if (e_4) throw e_4.error; }
84
84
  }
85
85
  var types = this.getTypes();
86
- throw new schema_1.Violation("Expected value of type " + types.slice(0, -1).join(', ') + " or " + types[types.length - 1] + " "
87
- + ("at path '" + violation_1.formatPath(path) + "', actual " + violation_1.describe(value) + "."), path, { type: types.join('|') });
86
+ throw new schema_1.Violation("Expected value of type ".concat(types.slice(0, -1).join(', '), " or ").concat(types[types.length - 1], " ")
87
+ + "at path '".concat((0, violation_1.formatPath)(path), "', actual ").concat((0, violation_1.describe)(value), "."), path, { type: types.join('|') });
88
88
  };
89
89
  return UnionType;
90
90
  }());
@@ -19,6 +19,6 @@ function describe(value) {
19
19
  }
20
20
  exports.describe = describe;
21
21
  function formatPath(path) {
22
- return "/" + path.join('/');
22
+ return "/".concat(path.join('/'));
23
23
  }
24
24
  exports.formatPath = formatPath;