@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
@@ -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,12 +27,24 @@ 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) {
33
45
  if (definition === void 0) { definition = {}; }
34
46
  var _a, _b, _c;
35
- this.definition = tslib_1.__assign(tslib_1.__assign({}, definition), { minLength: (_a = definition.minLength) !== null && _a !== void 0 ? _a : -1, maxLength: (_b = definition.maxLength) !== null && _b !== void 0 ? _b : -1, enumeration: (_c = definition.enumeration) !== null && _c !== void 0 ? _c : [] });
47
+ this.definition = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, definition), { minLength: (_a = definition.minLength) !== null && _a !== void 0 ? _a : -1, maxLength: (_b = definition.maxLength) !== null && _b !== void 0 ? _b : -1, enumeration: (_c = definition.enumeration) !== null && _c !== void 0 ? _c : [] });
36
48
  }
37
49
  StringType.prototype.getTypes = function () {
38
50
  return ['string'];
@@ -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,16 +10,16 @@ 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 = (0, tslib_1.__spreadArray)([first, second], (0, tslib_1.__read)(others), false);
14
14
  }
15
15
  UnionType.prototype.getTypes = function () {
16
16
  var e_1, _a, e_2, _b;
17
17
  var types = [];
18
18
  try {
19
- for (var _c = tslib_1.__values(this.schemas), _d = _c.next(); !_d.done; _d = _c.next()) {
19
+ for (var _c = (0, tslib_1.__values)(this.schemas), _d = _c.next(); !_d.done; _d = _c.next()) {
20
20
  var schema = _d.value;
21
21
  try {
22
- for (var _e = (e_2 = void 0, tslib_1.__values(schema.getTypes())), _f = _e.next(); !_f.done; _f = _e.next()) {
22
+ for (var _e = (e_2 = void 0, (0, tslib_1.__values)(schema.getTypes())), _f = _e.next(); !_f.done; _f = _e.next()) {
23
23
  var type = _f.value;
24
24
  if (types.indexOf(type) < 0) {
25
25
  types.push(type);
@@ -47,7 +47,7 @@ var UnionType = /** @class */ (function () {
47
47
  UnionType.prototype.isValidType = function (value) {
48
48
  var e_3, _a;
49
49
  try {
50
- for (var _b = tslib_1.__values(this.schemas), _c = _b.next(); !_c.done; _c = _b.next()) {
50
+ for (var _b = (0, tslib_1.__values)(this.schemas), _c = _b.next(); !_c.done; _c = _b.next()) {
51
51
  var schema = _c.value;
52
52
  if (schema.isValidType(value)) {
53
53
  return true;
@@ -67,7 +67,7 @@ var UnionType = /** @class */ (function () {
67
67
  var e_4, _a;
68
68
  if (path === void 0) { path = []; }
69
69
  try {
70
- for (var _b = tslib_1.__values(this.schemas), _c = _b.next(); !_c.done; _c = _b.next()) {
70
+ for (var _b = (0, tslib_1.__values)(this.schemas), _c = _b.next(); !_c.done; _c = _b.next()) {
71
71
  var schema = _c.value;
72
72
  if (schema.isValidType(value)) {
73
73
  schema.validate(value, path);
@@ -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;