@croct/sdk 0.6.1 → 0.9.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 (60) 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 +5 -3
  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/attributeSchema.d.ts +2 -0
  29. package/schema/attributeSchema.js +8 -0
  30. package/schema/contentSchemas.d.ts +2 -0
  31. package/schema/contentSchemas.js +46 -0
  32. package/schema/eventSchemas.d.ts +3 -1
  33. package/schema/eventSchemas.js +29 -14
  34. package/schema/operationSchemas.d.ts +1 -0
  35. package/schema/operationSchemas.js +11 -1
  36. package/schema/sdkFacadeSchemas.js +1 -0
  37. package/schema/sdkSchemas.js +1 -0
  38. package/schema/userSchema.js +5 -16
  39. package/sdk.d.ts +1 -0
  40. package/sdk.js +11 -10
  41. package/sourceLocation.js +2 -2
  42. package/token/token.js +8 -8
  43. package/tracker.d.ts +1 -0
  44. package/tracker.js +15 -7
  45. package/trackingEvents.d.ts +31 -10
  46. package/trackingEvents.js +8 -6
  47. package/uuid.js +1 -1
  48. package/validation/arrayType.js +7 -7
  49. package/validation/booleanType.js +1 -1
  50. package/validation/functionType.js +1 -1
  51. package/validation/jsonType.d.ts +1 -0
  52. package/validation/jsonType.js +12 -6
  53. package/validation/nullType.js +1 -1
  54. package/validation/numberType.js +5 -5
  55. package/validation/objectType.js +10 -10
  56. package/validation/stringType.js +27 -15
  57. package/validation/unionType.js +3 -3
  58. package/validation/violation.js +1 -1
  59. package/json.d.ts +0 -11
  60. package/json.js +0 -2
package/activeRecord.d.ts CHANGED
@@ -1,5 +1,5 @@
1
+ import { JsonStructure, JsonValue } from '@croct/json';
1
2
  import { Patch } from './patch';
2
- import { JsonArray, JsonObject, JsonValue } from './json';
3
3
  import { TrackingEvent } from './trackingEvents';
4
4
  export declare abstract class ActiveRecord<T extends TrackingEvent> {
5
5
  private readonly operations;
@@ -7,12 +7,13 @@ export declare abstract class ActiveRecord<T extends TrackingEvent> {
7
7
  set(property: string, value: JsonValue): this;
8
8
  add(property: string, value: JsonValue): this;
9
9
  combine(property: string, value: JsonValue): this;
10
- merge(value: JsonObject | JsonArray): this;
11
- merge(property: string, value: JsonObject | JsonArray): this;
10
+ merge(value: JsonStructure): this;
11
+ merge(property: string, value: JsonStructure): this;
12
12
  increment(property: string, amount?: number): this;
13
13
  decrement(property: string, amount?: number): this;
14
14
  clear(property: string): this;
15
15
  unset(property: string): this;
16
+ remove(property: string, value: JsonValue): this;
16
17
  private pushOperation;
17
18
  protected reset(): this;
18
19
  abstract save(): Promise<T>;
package/activeRecord.js CHANGED
@@ -12,6 +12,7 @@ var operationSchema = {
12
12
  decrement: schema_1.decrementOperation,
13
13
  clear: schema_1.clearOperation,
14
14
  unset: schema_1.unsetOperation,
15
+ remove: schema_1.removeOperation,
15
16
  };
16
17
  var ActiveRecord = /** @class */ (function () {
17
18
  function ActiveRecord() {
@@ -87,6 +88,13 @@ var ActiveRecord = /** @class */ (function () {
87
88
  path: property,
88
89
  });
89
90
  };
91
+ ActiveRecord.prototype.remove = function (property, value) {
92
+ return this.pushOperation({
93
+ type: 'remove',
94
+ path: property,
95
+ value: value,
96
+ });
97
+ };
90
98
  ActiveRecord.prototype.pushOperation = function (operation) {
91
99
  var type = operation.type, data = tslib_1.__rest(operation, ["type"]);
92
100
  operationSchema[type].validate(data);
@@ -66,7 +66,7 @@ var BeaconSocketChannel = /** @class */ (function () {
66
66
  if (token !== undefined) {
67
67
  endpoint.searchParams.append(this.tokenParameter, token);
68
68
  }
69
- channel = this.socketFactory(endpoint.toString(), this.loggerFactory("WebSocket#" + this.connectionIndex));
69
+ channel = this.socketFactory(endpoint.toString(), this.loggerFactory("WebSocket#".concat(this.connectionIndex)));
70
70
  this.connectionIndex += 1;
71
71
  channel.subscribe(this.notify);
72
72
  return [2 /*return*/, channel];
@@ -39,7 +39,7 @@ var GuaranteedChannel = /** @class */ (function () {
39
39
  var elapsed = Date.now() - start;
40
40
  window.clearTimeout(timeoutTimer);
41
41
  window.clearInterval(closeWatcher);
42
- _this.logger.debug("Delivery confirmed #" + id + ", elapsed " + elapsed + "ms.");
42
+ _this.logger.debug("Delivery confirmed #".concat(id, ", elapsed ").concat(elapsed, "ms."));
43
43
  _this.channel.unsubscribe(acknowledge);
44
44
  resolve();
45
45
  }
@@ -48,7 +48,7 @@ var GuaranteedChannel = /** @class */ (function () {
48
48
  var abort = function (error) {
49
49
  window.clearTimeout(timeoutTimer);
50
50
  window.clearInterval(closeWatcher);
51
- _this.logger.error("Failed to send message #" + id);
51
+ _this.logger.error("Failed to send message #".concat(id));
52
52
  _this.channel.unsubscribe(acknowledge);
53
53
  reject(error);
54
54
  };
@@ -62,12 +62,12 @@ var GuaranteedChannel = /** @class */ (function () {
62
62
  abort(new Error('Connection deliberately closed.'));
63
63
  }
64
64
  }, 0);
65
- _this.logger.debug("Waiting confirmation #" + id + "...");
65
+ _this.logger.debug("Waiting confirmation #".concat(id, "..."));
66
66
  timeoutTimer = window.setTimeout(function () {
67
67
  abort(new Error('Maximum confirmation time reached.'));
68
68
  }, _this.options.ackTimeout);
69
69
  };
70
- _this.logger.debug("Sending message #" + id + "...");
70
+ _this.logger.debug("Sending message #".concat(id, "..."));
71
71
  _this.channel.publish({ id: id, message: message }).then(wait, abort);
72
72
  });
73
73
  };
@@ -36,12 +36,12 @@ var QueuedChannel = /** @class */ (function () {
36
36
  };
37
37
  QueuedChannel.prototype.enqueue = function (message) {
38
38
  this.logger.debug('Enqueueing message...');
39
- this.logger.debug("Queue length: " + (this.queue.length() + 1));
39
+ this.logger.debug("Queue length: ".concat(this.queue.length() + 1));
40
40
  this.queue.push(message);
41
41
  };
42
42
  QueuedChannel.prototype.dequeue = function () {
43
43
  this.logger.debug('Dequeuing message...');
44
- this.logger.debug("Queue length: " + Math.max(0, this.queue.length() - 1));
44
+ this.logger.debug("Queue length: ".concat(Math.max(0, this.queue.length() - 1)));
45
45
  this.queue.shift();
46
46
  };
47
47
  QueuedChannel.prototype.requeue = function () {
@@ -56,7 +56,7 @@ var QueuedChannel = /** @class */ (function () {
56
56
  }
57
57
  var length = this.queue.length();
58
58
  this.logger.debug('Requeuing messages...');
59
- this.logger.debug("Queue length: " + length);
59
+ this.logger.debug("Queue length: ".concat(length));
60
60
  var _loop_1 = function (message) {
61
61
  this_1.pending = this_1.pending.then(function () { return _this.channel.publish(message).then(_this.dequeue.bind(_this)); });
62
62
  };
@@ -35,9 +35,9 @@ var RetryChannel = /** @class */ (function () {
35
35
  throw new Error('Connection deliberately closed.');
36
36
  }
37
37
  delay = this_1.retryPolicy.getDelay(attempt);
38
- this_1.logger.debug("Retry attempt " + (attempt + 1));
38
+ this_1.logger.debug("Retry attempt ".concat(attempt + 1));
39
39
  if (!(delay > 0)) return [3 /*break*/, 2];
40
- this_1.logger.debug("Retry attempt delayed in " + delay + "ms");
40
+ this_1.logger.debug("Retry attempt delayed in ".concat(delay, "ms"));
41
41
  return [4 /*yield*/, new Promise(function (resolve, reject) {
42
42
  var closeWatcher = window.setInterval(function () {
43
43
  if (_this.closed) {
@@ -93,8 +93,8 @@ var SocketChannel = /** @class */ (function () {
93
93
  };
94
94
  var closeListener = function (event) {
95
95
  window.clearTimeout(abortTimer);
96
- var reason = error_1.formatCause(event.reason || 'unknown') + " (code " + event.code + ")";
97
- var message = "Connection has been closed, reason: " + reason;
96
+ var reason = "".concat((0, error_1.formatCause)(event.reason || 'unknown'), " (code ").concat(event.code, ")");
97
+ var message = "Connection has been closed, reason: ".concat(reason);
98
98
  if (!_this.closed) {
99
99
  _this.logger.info(message);
100
100
  }
@@ -32,7 +32,7 @@ var RemoteAssigner = /** @class */ (function () {
32
32
  case 1:
33
33
  response = _a.sent();
34
34
  if (!response.ok) {
35
- error = new Error("Failed to assign CID: " + error_1.formatCause(response.statusText));
35
+ error = new Error("Failed to assign CID: ".concat((0, error_1.formatCause)(response.statusText)));
36
36
  this.logger.error(error.message);
37
37
  throw error;
38
38
  }
package/constants.js CHANGED
@@ -5,4 +5,4 @@ exports.TRACKER_ENDPOINT_URL = 'wss://api.croct.io/client/web/connect';
5
5
  exports.EVALUATION_ENDPOINT_URL = 'https://api.croct.io/client/web/evaluate';
6
6
  exports.BOOTSTRAP_ENDPOINT_URL = 'https://api.croct.io/client/web/bootstrap';
7
7
  exports.MAX_EXPRESSION_LENGTH = 300;
8
- exports.VERSION = '0.6.1';
8
+ exports.VERSION = '0.9.0';
package/container.d.ts CHANGED
@@ -13,6 +13,7 @@ export declare type Configuration = {
13
13
  tokenScope: TokenScope;
14
14
  cid?: string;
15
15
  debug: boolean;
16
+ test: boolean;
16
17
  trackerEndpointUrl: string;
17
18
  evaluationEndpointUrl: string;
18
19
  bootstrapEndpointUrl: string;
package/container.js CHANGED
@@ -96,12 +96,15 @@ var Container = /** @class */ (function () {
96
96
  return this.beaconChannel;
97
97
  };
98
98
  Container.prototype.createBeaconChannel = function () {
99
+ if (this.configuration.test) {
100
+ return new channel_1.SandboxChannel();
101
+ }
99
102
  var channelLogger = this.getLogger('BeaconChannel');
100
103
  var _a = this.configuration, appId = _a.appId, trackerEndpointUrl = _a.trackerEndpointUrl;
101
104
  var queuedChannel = new channel_1.QueuedChannel(new channel_1.RetryChannel({
102
105
  channel: new channel_1.GuaranteedChannel({
103
106
  channel: new channel_1.BeaconSocketChannel({
104
- trackerEndpointUrl: trackerEndpointUrl + "/" + appId,
107
+ trackerEndpointUrl: "".concat(trackerEndpointUrl, "/").concat(appId),
105
108
  tokenParameter: 'token',
106
109
  loggerFactory: this.getLogger.bind(this),
107
110
  logger: channelLogger,
@@ -136,6 +139,9 @@ var Container = /** @class */ (function () {
136
139
  if (this.configuration.cid !== undefined) {
137
140
  return new cid_1.FixedAssigner(this.configuration.cid);
138
141
  }
142
+ if (this.configuration.test) {
143
+ return new cid_1.FixedAssigner('00000000-0000-0000-0000-000000000000');
144
+ }
139
145
  var logger = this.getLogger('CidAssigner');
140
146
  return new cid_1.CachedAssigner(new cid_1.RemoteAssigner(this.configuration.bootstrapEndpointUrl, logger), new cache_1.LocalStorageCache(this.getLocalStorage(), 'croct.cid'), logger);
141
147
  };
@@ -155,7 +161,7 @@ var Container = /** @class */ (function () {
155
161
  for (var _i = 0; _i < arguments.length; _i++) {
156
162
  namespace[_i] = arguments[_i];
157
163
  }
158
- var prefix = "Croct" + (namespace.length === 0 ? '' : ":" + namespace.join(':'));
164
+ var prefix = "Croct".concat(namespace.length === 0 ? '' : ":".concat(namespace.join(':')));
159
165
  if (this.configuration.logger !== undefined) {
160
166
  return new logging_1.NamespacedLogger(this.configuration.logger, prefix);
161
167
  }
@@ -169,35 +175,35 @@ var Container = /** @class */ (function () {
169
175
  for (var _i = 1; _i < arguments.length; _i++) {
170
176
  subnamespace[_i - 1] = arguments[_i];
171
177
  }
172
- return this.getGlobalTabStorage.apply(this, tslib_1.__spreadArray(['external', namespace], tslib_1.__read(subnamespace)));
178
+ return this.getGlobalTabStorage.apply(this, tslib_1.__spreadArray(['external', namespace], tslib_1.__read(subnamespace), false));
173
179
  };
174
180
  Container.prototype.getBrowserStorage = function (namespace) {
175
181
  var subnamespace = [];
176
182
  for (var _i = 1; _i < arguments.length; _i++) {
177
183
  subnamespace[_i - 1] = arguments[_i];
178
184
  }
179
- return this.getGlobalBrowserStorage.apply(this, tslib_1.__spreadArray(['external', namespace], tslib_1.__read(subnamespace)));
185
+ return this.getGlobalBrowserStorage.apply(this, tslib_1.__spreadArray(['external', namespace], tslib_1.__read(subnamespace), false));
180
186
  };
181
187
  Container.prototype.getGlobalTabStorage = function (namespace) {
182
188
  var subnamespace = [];
183
189
  for (var _i = 1; _i < arguments.length; _i++) {
184
190
  subnamespace[_i - 1] = arguments[_i];
185
191
  }
186
- return new namespacedStorage_1.NamespacedStorage(this.getSessionStorage(), this.resolveStorageNamespace.apply(this, tslib_1.__spreadArray([namespace], tslib_1.__read(subnamespace))));
192
+ return new namespacedStorage_1.NamespacedStorage(this.getSessionStorage(), this.resolveStorageNamespace.apply(this, tslib_1.__spreadArray([namespace], tslib_1.__read(subnamespace), false)));
187
193
  };
188
194
  Container.prototype.getGlobalBrowserStorage = function (namespace) {
189
195
  var subnamespace = [];
190
196
  for (var _i = 1; _i < arguments.length; _i++) {
191
197
  subnamespace[_i - 1] = arguments[_i];
192
198
  }
193
- return new namespacedStorage_1.NamespacedStorage(this.getLocalStorage(), this.resolveStorageNamespace.apply(this, tslib_1.__spreadArray([namespace], tslib_1.__read(subnamespace))));
199
+ return new namespacedStorage_1.NamespacedStorage(this.getLocalStorage(), this.resolveStorageNamespace.apply(this, tslib_1.__spreadArray([namespace], tslib_1.__read(subnamespace), false)));
194
200
  };
195
201
  Container.prototype.resolveStorageNamespace = function (namespace) {
196
202
  var subnamespace = [];
197
203
  for (var _i = 1; _i < arguments.length; _i++) {
198
204
  subnamespace[_i - 1] = arguments[_i];
199
205
  }
200
- return "croct[" + this.configuration.appId.toLowerCase() + "]." + [namespace].concat(subnamespace).join('.');
206
+ return "croct[".concat(this.configuration.appId.toLowerCase(), "].").concat([namespace].concat(subnamespace).join('.'));
201
207
  };
202
208
  Container.prototype.getLocalStorage = function () {
203
209
  return localStorage;
package/context.js CHANGED
@@ -20,7 +20,7 @@ var Context = /** @class */ (function () {
20
20
  var tabId = cache.tabId.get();
21
21
  var newTab = false;
22
22
  if (tabId === null) {
23
- tabId = uuid_1.uuid4(true);
23
+ tabId = (0, uuid_1.uuid4)(true);
24
24
  newTab = true;
25
25
  }
26
26
  var tab = new tab_1.Tab(tabId, newTab, urlSanitizer);
package/evaluator.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { JsonObject, JsonValue } from './json';
1
+ import { JsonObject, JsonValue } from '@croct/json';
2
2
  import { TokenProvider } from './token';
3
3
  import { Location } from './sourceLocation';
4
4
  import { CidAssigner } from './cid';
package/evaluator.js CHANGED
@@ -47,17 +47,17 @@ var Evaluator = /** @class */ (function () {
47
47
  var length, response, endpoint;
48
48
  var _this = this;
49
49
  return tslib_1.__generator(this, function (_a) {
50
- length = sourceLocation_1.getLength(expression);
50
+ length = (0, sourceLocation_1.getLength)(expression);
51
51
  if (length > Evaluator.MAX_EXPRESSION_LENGTH) {
52
52
  response = {
53
53
  title: 'The expression is too complex.',
54
54
  status: 422,
55
55
  type: EvaluationErrorType.TOO_COMPLEX_EXPRESSION,
56
- detail: "The expression must be at most " + Evaluator.MAX_EXPRESSION_LENGTH + " characters long, "
57
- + ("but it is " + length + " characters long."),
56
+ detail: "The expression must be at most ".concat(Evaluator.MAX_EXPRESSION_LENGTH, " characters long, ")
57
+ + "but it is ".concat(length, " characters long."),
58
58
  errors: [{
59
59
  cause: 'The expression is longer than expected.',
60
- location: sourceLocation_1.getLocation(expression, 0, Math.max(length - 1, 0)),
60
+ location: (0, sourceLocation_1.getLocation)(expression, 0, Math.max(length - 1, 0)),
61
61
  }],
62
62
  };
63
63
  return [2 /*return*/, Promise.reject(new ExpressionError(response))];
@@ -73,7 +73,7 @@ var Evaluator = /** @class */ (function () {
73
73
  var response = {
74
74
  title: 'Maximum evaluation timeout reached before evaluation could complete.',
75
75
  type: EvaluationErrorType.TIMEOUT,
76
- detail: "The evaluation took more than " + options.timeout + "ms to complete.",
76
+ detail: "The evaluation took more than ".concat(options.timeout, "ms to complete."),
77
77
  status: 408, // Request Timeout
78
78
  };
79
79
  reject(new EvaluationError(response));
@@ -100,7 +100,7 @@ var Evaluator = /** @class */ (function () {
100
100
  });
101
101
  }, function (error) {
102
102
  var errorResponse = {
103
- title: error_1.formatMessage(error),
103
+ title: (0, error_1.formatMessage)(error),
104
104
  type: EvaluationErrorType.UNEXPECTED_ERROR,
105
105
  detail: 'Please try again or contact Croct support if the error persists.',
106
106
  status: 500, // Internal Server Error
@@ -1,5 +1,5 @@
1
+ import { JsonObject, JsonValue } from '@croct/json';
1
2
  import { Evaluator, EvaluationContext } from '../evaluator';
2
- import { JsonObject, JsonValue } from '../json';
3
3
  import { Tab } from '../tab';
4
4
  export declare type EvaluationOptions = {
5
5
  timeout?: number;
@@ -12,7 +12,7 @@ function validate(options) {
12
12
  schema_1.optionsSchema.validate(options);
13
13
  }
14
14
  catch (violation) {
15
- throw new Error("Invalid options: " + error_1.formatCause(violation));
15
+ throw new Error("Invalid options: ".concat((0, error_1.formatCause)(violation)));
16
16
  }
17
17
  }
18
18
  var EvaluatorFacade = /** @class */ (function () {
@@ -13,6 +13,7 @@ export declare type Configuration = {
13
13
  appId: string;
14
14
  tokenScope?: TokenScope;
15
15
  debug?: boolean;
16
+ test?: boolean;
16
17
  track?: boolean;
17
18
  token?: string | null;
18
19
  userId?: string;
@@ -18,7 +18,7 @@ function validateConfiguration(configuration) {
18
18
  schema_1.sdkFacadeConfigurationSchema.validate(configuration);
19
19
  }
20
20
  catch (violation) {
21
- throw new Error("Invalid configuration: " + error_1.formatCause(violation));
21
+ throw new Error("Invalid configuration: ".concat((0, error_1.formatCause)(violation)));
22
22
  }
23
23
  }
24
24
  var SdkFacade = /** @class */ (function () {
@@ -26,13 +26,13 @@ var SdkFacade = /** @class */ (function () {
26
26
  this.sdk = sdk;
27
27
  }
28
28
  SdkFacade.init = function (configuration) {
29
- var _a, _b;
29
+ var _a, _b, _c;
30
30
  validateConfiguration(configuration);
31
- var _c = configuration.track, track = _c === void 0 ? true : _c, userId = configuration.userId, token = configuration.token, containerConfiguration = tslib_1.__rest(configuration, ["track", "userId", "token"]);
31
+ var _d = configuration.track, track = _d === void 0 ? true : _d, userId = configuration.userId, token = configuration.token, containerConfiguration = tslib_1.__rest(configuration, ["track", "userId", "token"]);
32
32
  if (userId !== undefined && token !== undefined) {
33
33
  throw new Error('Either the user ID or token can be specified, but not both.');
34
34
  }
35
- var sdk = new SdkFacade(sdk_1.Sdk.init(tslib_1.__assign(tslib_1.__assign({}, containerConfiguration), { tokenScope: (_a = containerConfiguration.tokenScope) !== null && _a !== void 0 ? _a : 'global', debug: (_b = containerConfiguration.debug) !== null && _b !== void 0 ? _b : false })));
35
+ var sdk = new SdkFacade(sdk_1.Sdk.init(tslib_1.__assign(tslib_1.__assign({}, containerConfiguration), { tokenScope: (_a = containerConfiguration.tokenScope) !== null && _a !== void 0 ? _a : 'global', debug: (_b = containerConfiguration.debug) !== null && _b !== void 0 ? _b : false, test: (_c = containerConfiguration.test) !== null && _c !== void 0 ? _c : false })));
36
36
  if (userId !== undefined) {
37
37
  sdk.identify(userId);
38
38
  }
@@ -160,7 +160,7 @@ var SdkFacade = /** @class */ (function () {
160
160
  type: 'userSignedIn',
161
161
  userId: subject,
162
162
  });
163
- logger.info("User signed in as " + subject);
163
+ logger.info("User signed in as ".concat(subject));
164
164
  }
165
165
  logger.debug('New token saved, ');
166
166
  };
@@ -192,7 +192,7 @@ var SdkFacade = /** @class */ (function () {
192
192
  for (var _i = 0; _i < arguments.length; _i++) {
193
193
  namespace[_i] = arguments[_i];
194
194
  }
195
- return (_a = this.sdk).getLogger.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(namespace)));
195
+ return (_a = this.sdk).getLogger.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(namespace), false));
196
196
  };
197
197
  SdkFacade.prototype.getTabStorage = function (namespace) {
198
198
  var _a;
@@ -200,7 +200,7 @@ var SdkFacade = /** @class */ (function () {
200
200
  for (var _i = 1; _i < arguments.length; _i++) {
201
201
  subnamespace[_i - 1] = arguments[_i];
202
202
  }
203
- return (_a = this.sdk).getTabStorage.apply(_a, tslib_1.__spreadArray([namespace], tslib_1.__read(subnamespace)));
203
+ return (_a = this.sdk).getTabStorage.apply(_a, tslib_1.__spreadArray([namespace], tslib_1.__read(subnamespace), false));
204
204
  };
205
205
  SdkFacade.prototype.getBrowserStorage = function (namespace) {
206
206
  var _a;
@@ -208,7 +208,7 @@ var SdkFacade = /** @class */ (function () {
208
208
  for (var _i = 1; _i < arguments.length; _i++) {
209
209
  subnamespace[_i - 1] = arguments[_i];
210
210
  }
211
- return (_a = this.sdk).getBrowserStorage.apply(_a, tslib_1.__spreadArray([namespace], tslib_1.__read(subnamespace)));
211
+ return (_a = this.sdk).getBrowserStorage.apply(_a, tslib_1.__spreadArray([namespace], tslib_1.__read(subnamespace), false));
212
212
  };
213
213
  SdkFacade.prototype.close = function () {
214
214
  return this.sdk.close();
@@ -11,9 +11,11 @@ var eventSchemas = {
11
11
  orderPlaced: schema_1.orderPlaced,
12
12
  productViewed: schema_1.productViewed,
13
13
  userSignedUp: schema_1.userSignedUp,
14
- testGroupAssigned: schema_1.testGroupAssigned,
15
14
  eventOccurred: schema_1.eventOccurred,
15
+ interestShown: schema_1.interestShown,
16
+ postViewed: schema_1.postViewed,
16
17
  goalCompleted: schema_1.goalCompleted,
18
+ linkOpened: schema_1.linkOpened,
17
19
  };
18
20
  function createEvent(type, payload) {
19
21
  if (typeof type !== 'string') {
@@ -29,13 +31,13 @@ function createEvent(type, payload) {
29
31
  function validateEvent(event) {
30
32
  var type = event.type, payload = tslib_1.__rest(event, ["type"]);
31
33
  if (!(type in eventSchemas)) {
32
- throw new Error("Unknown event type '" + type + "'.");
34
+ throw new Error("Unknown event type '".concat(type, "'."));
33
35
  }
34
36
  try {
35
37
  eventSchemas[type].validate(payload);
36
38
  }
37
39
  catch (violation) {
38
- throw new Error("Invalid event payload: " + error_1.formatCause(violation));
40
+ throw new Error("Invalid event payload: ".concat((0, error_1.formatCause)(violation)));
39
41
  }
40
42
  }
41
43
  var TrackerFacade = /** @class */ (function () {
@@ -35,7 +35,7 @@ var ConsoleLogger = /** @class */ (function () {
35
35
  });
36
36
  ConsoleLogger.prototype.bind = function (method) {
37
37
  if (this.namespace !== undefined) {
38
- return method.bind(window.console, "[" + this.namespace + "]");
38
+ return method.bind(window.console, "[".concat(this.namespace, "]"));
39
39
  }
40
40
  return method.bind(window.console);
41
41
  };
@@ -19,7 +19,7 @@ var NamespacedLogger = /** @class */ (function () {
19
19
  this.logger.error(this.format(message));
20
20
  };
21
21
  NamespacedLogger.prototype.format = function (message) {
22
- return "[" + this.namespace + "] " + message;
22
+ return "[".concat(this.namespace, "] ").concat(message);
23
23
  };
24
24
  return NamespacedLogger;
25
25
  }());
@@ -64,7 +64,7 @@ var NamespacedStorage = /** @class */ (function () {
64
64
  return this.getPrefix() + key;
65
65
  };
66
66
  NamespacedStorage.prototype.getPrefix = function () {
67
- return this.namespace + ".";
67
+ return "".concat(this.namespace, ".");
68
68
  };
69
69
  return NamespacedStorage;
70
70
  }());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@croct/sdk",
3
- "version": "0.6.1",
3
+ "version": "0.9.0",
4
4
  "description": "Croct SDK for JavaScript.",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -28,24 +28,25 @@
28
28
  "build": "tsc"
29
29
  },
30
30
  "dependencies": {
31
- "tslib": "^2.2.0"
31
+ "@croct/json": "^1.0",
32
+ "tslib": "^2.3.1"
32
33
  },
33
34
  "devDependencies": {
34
- "@types/jest": "^26.0.23",
35
- "@typescript-eslint/eslint-plugin": "^4.24.0",
36
- "@typescript-eslint/parser": "^4.24.0",
37
- "eslint": "^7.27.0",
35
+ "@types/jest": "^26.0.24",
36
+ "@typescript-eslint/eslint-plugin": "^4.33.0",
37
+ "@typescript-eslint/parser": "^4.33.0",
38
+ "eslint": "^7.32.0",
38
39
  "eslint-config-airbnb-base": "^14.2.1",
39
- "eslint-plugin-import": "^2.23.3",
40
- "eslint-plugin-jest": "^24.3.6",
40
+ "eslint-plugin-import": "^2.25.4",
41
+ "eslint-plugin-jest": "^24.7.0",
41
42
  "fetch-mock": "^9.11.0",
42
43
  "jest": "^26.6.3",
43
- "jest-websocket-mock": "^2.2.0",
44
- "mock-socket": "^9.0.3",
45
- "node-fetch": "^2.6.1",
44
+ "jest-websocket-mock": "^2.3.0",
45
+ "mock-socket": "^9.1.0",
46
+ "node-fetch": "^2.6.7",
46
47
  "temp-dir": "^2.0.0",
47
48
  "ts-jest": "^26.5.6",
48
- "typescript": "^4.2.4"
49
+ "typescript": "^4.5.4"
49
50
  },
50
51
  "files": [
51
52
  "**/*.js",
package/patch.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { LenientJsonArray, LenientJsonObject, LenientJsonValue } from './json';
1
+ import { JsonStructure, JsonValue } from '@croct/json';
2
2
  interface AbstractOperation {
3
3
  type: string;
4
4
  path: string;
@@ -11,29 +11,33 @@ interface ClearOperation extends AbstractOperation {
11
11
  }
12
12
  interface SetOperation extends AbstractOperation {
13
13
  type: 'set';
14
- value: LenientJsonValue;
14
+ value: JsonValue;
15
15
  }
16
16
  interface AddOperation extends AbstractOperation {
17
17
  type: 'add';
18
- value: LenientJsonValue;
18
+ value: JsonValue;
19
19
  }
20
20
  interface CombineOperation extends AbstractOperation {
21
21
  type: 'combine';
22
- value: LenientJsonValue;
22
+ value: JsonValue;
23
23
  }
24
24
  interface MergeOperation extends AbstractOperation {
25
25
  type: 'merge';
26
- value: LenientJsonArray | LenientJsonObject;
26
+ value: JsonStructure;
27
27
  }
28
28
  interface IncrementOperation extends AbstractOperation {
29
29
  type: 'increment';
30
- value: LenientJsonValue;
30
+ value: JsonValue;
31
31
  }
32
32
  interface DecrementOperation extends AbstractOperation {
33
33
  type: 'decrement';
34
- value: LenientJsonValue;
34
+ value: JsonValue;
35
35
  }
36
- export declare type Operation = UnsetOperation | ClearOperation | AddOperation | SetOperation | CombineOperation | MergeOperation | IncrementOperation | DecrementOperation;
36
+ interface removeOperation extends AbstractOperation {
37
+ type: 'remove';
38
+ value: JsonValue;
39
+ }
40
+ export declare type Operation = UnsetOperation | ClearOperation | AddOperation | SetOperation | CombineOperation | MergeOperation | IncrementOperation | DecrementOperation | removeOperation;
37
41
  export interface Patch {
38
42
  operations: Operation[];
39
43
  }
@@ -10,7 +10,7 @@ var InMemoryQueue = /** @class */ (function () {
10
10
  values[_i] = arguments[_i];
11
11
  }
12
12
  this.queue = [];
13
- (_a = this.queue).unshift.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(values)));
13
+ (_a = this.queue).unshift.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(values), false));
14
14
  }
15
15
  InMemoryQueue.prototype.all = function () {
16
16
  return this.queue.slice();
@@ -53,7 +53,7 @@ var MonitoredQueue = /** @class */ (function () {
53
53
  if (this.status === status) {
54
54
  return;
55
55
  }
56
- this.logger.debug("Queue status changed to \"" + status + "\"");
56
+ this.logger.debug("Queue status changed to \"".concat(status, "\""));
57
57
  this.report(status);
58
58
  this.status = status;
59
59
  };
@@ -7,7 +7,7 @@ var ArbitraryPolicy = /** @class */ (function () {
7
7
  if (delays.length < 1) {
8
8
  throw new Error('The list of delays cannot be empty.');
9
9
  }
10
- this.delays = tslib_1.__spreadArray([], tslib_1.__read(delays));
10
+ this.delays = tslib_1.__spreadArray([], tslib_1.__read(delays), false);
11
11
  }
12
12
  ArbitraryPolicy.prototype.getDelay = function (attempt) {
13
13
  return this.delays[Math.min(attempt < 0 ? 0 : attempt, this.delays.length - 1)];
@@ -0,0 +1,2 @@
1
+ import { StringType } from '../validation';
2
+ export declare const attributeNameSchema: StringType;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.attributeNameSchema = void 0;
4
+ var validation_1 = require("../validation");
5
+ exports.attributeNameSchema = new validation_1.StringType({
6
+ maxLength: 50,
7
+ format: 'identifier',
8
+ });
@@ -0,0 +1,2 @@
1
+ import { ObjectType } from '../validation';
2
+ export declare const postDetails: ObjectType;