@croct/sdk 0.7.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 (64) 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 +15 -9
  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 +5 -4
  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/eventSchemas.d.ts +1 -0
  37. package/schema/eventSchemas.js +9 -1
  38. package/schema/index.js +10 -10
  39. package/schema/operationSchemas.d.ts +1 -0
  40. package/schema/operationSchemas.js +8 -1
  41. package/schema/sdkFacadeSchemas.js +1 -0
  42. package/schema/sdkSchemas.js +1 -0
  43. package/sdk.d.ts +1 -0
  44. package/sdk.js +16 -15
  45. package/sourceLocation.js +2 -2
  46. package/token/index.js +1 -1
  47. package/token/token.js +11 -11
  48. package/tracker.d.ts +1 -0
  49. package/tracker.js +30 -22
  50. package/trackingEvents.d.ts +9 -3
  51. package/trackingEvents.js +6 -5
  52. package/uuid.js +1 -1
  53. package/validation/arrayType.js +8 -8
  54. package/validation/booleanType.js +1 -1
  55. package/validation/functionType.js +1 -1
  56. package/validation/index.js +2 -2
  57. package/validation/jsonType.js +6 -6
  58. package/validation/nullType.js +1 -1
  59. package/validation/numberType.js +6 -6
  60. package/validation/objectType.js +16 -16
  61. package/validation/schema.js +1 -1
  62. package/validation/stringType.js +28 -16
  63. package/validation/unionType.js +7 -7
  64. package/validation/violation.js +1 -1
@@ -15,6 +15,7 @@ var eventSchemas = {
15
15
  interestShown: schema_1.interestShown,
16
16
  postViewed: schema_1.postViewed,
17
17
  goalCompleted: schema_1.goalCompleted,
18
+ linkOpened: schema_1.linkOpened,
18
19
  };
19
20
  function createEvent(type, payload) {
20
21
  if (typeof type !== 'string') {
@@ -23,20 +24,20 @@ function createEvent(type, payload) {
23
24
  if (typeof payload !== 'object' || payload == null) {
24
25
  throw new Error('The event payload must of type object.');
25
26
  }
26
- var event = tslib_1.__assign({ type: type }, payload);
27
+ var event = (0, tslib_1.__assign)({ type: type }, payload);
27
28
  validateEvent(event);
28
29
  return event;
29
30
  }
30
31
  function validateEvent(event) {
31
- var type = event.type, payload = tslib_1.__rest(event, ["type"]);
32
+ var type = event.type, payload = (0, tslib_1.__rest)(event, ["type"]);
32
33
  if (!(type in eventSchemas)) {
33
- throw new Error("Unknown event type '" + type + "'.");
34
+ throw new Error("Unknown event type '".concat(type, "'."));
34
35
  }
35
36
  try {
36
37
  eventSchemas[type].validate(payload);
37
38
  }
38
39
  catch (violation) {
39
- throw new Error("Invalid event payload: " + error_1.formatCause(violation));
40
+ throw new Error("Invalid event payload: ".concat((0, error_1.formatCause)(violation)));
40
41
  }
41
42
  }
42
43
  var TrackerFacade = /** @class */ (function () {
@@ -4,7 +4,7 @@ exports.UserPatch = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var activeRecord_1 = require("../activeRecord");
6
6
  var UserPatch = /** @class */ (function (_super) {
7
- tslib_1.__extends(UserPatch, _super);
7
+ (0, tslib_1.__extends)(UserPatch, _super);
8
8
  function UserPatch(tracker) {
9
9
  var _this = _super.call(this) || this;
10
10
  _this.tracker = tracker;
@@ -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
  };
package/logging/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NullLogger = exports.NamespacedLogger = exports.ConsoleLogger = void 0;
4
4
  var tslib_1 = require("tslib");
5
- tslib_1.__exportStar(require("./logger"), exports);
5
+ (0, tslib_1.__exportStar)(require("./logger"), exports);
6
6
  var consoleLogger_1 = require("./consoleLogger");
7
7
  Object.defineProperty(exports, "ConsoleLogger", { enumerable: true, get: function () { return consoleLogger_1.ConsoleLogger; } });
8
8
  var namespacedLogger_1 = require("./namespacedLogger");
@@ -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
  }());
@@ -20,7 +20,7 @@ var NamespacedStorage = /** @class */ (function () {
20
20
  NamespacedStorage.prototype.clear = function () {
21
21
  var e_1, _a;
22
22
  try {
23
- for (var _b = tslib_1.__values(this.getKeys()), _c = _b.next(); !_c.done; _c = _b.next()) {
23
+ for (var _b = (0, tslib_1.__values)(this.getKeys()), _c = _b.next(); !_c.done; _c = _b.next()) {
24
24
  var key = _c.value;
25
25
  this.storage.removeItem(key);
26
26
  }
@@ -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.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Croct SDK for JavaScript.",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -28,24 +28,24 @@
28
28
  "build": "tsc"
29
29
  },
30
30
  "dependencies": {
31
- "tslib": "^2.2.0"
31
+ "tslib": "^2.3.1"
32
32
  },
33
33
  "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",
34
+ "@types/jest": "^26.0.24",
35
+ "@typescript-eslint/eslint-plugin": "^4.33.0",
36
+ "@typescript-eslint/parser": "^4.33.0",
37
+ "eslint": "^7.32.0",
38
38
  "eslint-config-airbnb-base": "^14.2.1",
39
- "eslint-plugin-import": "^2.23.3",
40
- "eslint-plugin-jest": "^24.3.6",
39
+ "eslint-plugin-import": "^2.25.4",
40
+ "eslint-plugin-jest": "^24.7.0",
41
41
  "fetch-mock": "^9.11.0",
42
42
  "jest": "^26.6.3",
43
- "jest-websocket-mock": "^2.2.0",
44
- "mock-socket": "^9.0.3",
45
- "node-fetch": "^2.6.1",
43
+ "jest-websocket-mock": "^2.3.0",
44
+ "mock-socket": "^9.1.0",
45
+ "node-fetch": "^2.6.7",
46
46
  "temp-dir": "^2.0.0",
47
47
  "ts-jest": "^26.5.6",
48
- "typescript": "^4.2.4"
48
+ "typescript": "^4.5.4"
49
49
  },
50
50
  "files": [
51
51
  "**/*.js",
package/patch.d.ts CHANGED
@@ -33,7 +33,11 @@ interface DecrementOperation extends AbstractOperation {
33
33
  type: 'decrement';
34
34
  value: LenientJsonValue;
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: LenientJsonValue;
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, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(values), false));
14
14
  }
15
15
  InMemoryQueue.prototype.all = function () {
16
16
  return this.queue.slice();
package/queue/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PersistentQueue = exports.MonitoredQueue = exports.InMemoryQueue = exports.CapacityRestrictedQueue = void 0;
4
4
  var tslib_1 = require("tslib");
5
- tslib_1.__exportStar(require("./queue"), exports);
5
+ (0, tslib_1.__exportStar)(require("./queue"), exports);
6
6
  var capacityRestrictedQueue_1 = require("./capacityRestrictedQueue");
7
7
  Object.defineProperty(exports, "CapacityRestrictedQueue", { enumerable: true, get: function () { return capacityRestrictedQueue_1.CapacityRestrictedQueue; } });
8
8
  var inMemoryQueue_1 = require("./inMemoryQueue");
@@ -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 = (0, tslib_1.__spreadArray)([], (0, 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)];
package/retry/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NeverPolicy = exports.MaxAttemptsPolicy = exports.BackoffPolicy = exports.ArbitraryPolicy = void 0;
4
4
  var tslib_1 = require("tslib");
5
- tslib_1.__exportStar(require("./policy"), exports);
5
+ (0, tslib_1.__exportStar)(require("./policy"), exports);
6
6
  var arbitraryPolicy_1 = require("./arbitraryPolicy");
7
7
  Object.defineProperty(exports, "ArbitraryPolicy", { enumerable: true, get: function () { return arbitraryPolicy_1.ArbitraryPolicy; } });
8
8
  var backoffPolicy_1 = require("./backoffPolicy");
@@ -8,4 +8,5 @@ export declare const userSignedUp: ObjectType;
8
8
  export declare const goalCompleted: ObjectType;
9
9
  export declare const interestShown: ObjectType;
10
10
  export declare const postViewed: ObjectType;
11
+ export declare const linkOpened: ObjectType;
11
12
  export declare const eventOccurred: ObjectType;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.eventOccurred = exports.postViewed = exports.interestShown = exports.goalCompleted = exports.userSignedUp = exports.productViewed = exports.orderPlaced = exports.checkoutStarted = exports.cartViewed = exports.cartModified = void 0;
3
+ exports.eventOccurred = exports.linkOpened = exports.postViewed = exports.interestShown = exports.goalCompleted = exports.userSignedUp = exports.productViewed = exports.orderPlaced = exports.checkoutStarted = exports.cartViewed = exports.cartModified = void 0;
4
4
  var validation_1 = require("../validation");
5
5
  var ecommerceSchemas_1 = require("./ecommerceSchemas");
6
6
  var userSchema_1 = require("./userSchema");
@@ -84,6 +84,14 @@ exports.postViewed = new validation_1.ObjectType({
84
84
  post: contentSchemas_1.postDetails,
85
85
  },
86
86
  });
87
+ exports.linkOpened = new validation_1.ObjectType({
88
+ required: ['link'],
89
+ properties: {
90
+ link: new validation_1.StringType({
91
+ format: 'uri-reference',
92
+ }),
93
+ },
94
+ });
87
95
  exports.eventOccurred = new validation_1.ObjectType({
88
96
  required: ['name'],
89
97
  properties: {
package/schema/index.js CHANGED
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./contextSchemas"), exports);
5
- tslib_1.__exportStar(require("./ecommerceSchemas"), exports);
6
- tslib_1.__exportStar(require("./evaluationSchemas"), exports);
7
- tslib_1.__exportStar(require("./eventSchemas"), exports);
8
- tslib_1.__exportStar(require("./loggerSchema"), exports);
9
- tslib_1.__exportStar(require("./operationSchemas"), exports);
10
- tslib_1.__exportStar(require("./sdkFacadeSchemas"), exports);
11
- tslib_1.__exportStar(require("./sdkSchemas"), exports);
12
- tslib_1.__exportStar(require("./tokenSchema"), exports);
13
- tslib_1.__exportStar(require("./userSchema"), exports);
4
+ (0, tslib_1.__exportStar)(require("./contextSchemas"), exports);
5
+ (0, tslib_1.__exportStar)(require("./ecommerceSchemas"), exports);
6
+ (0, tslib_1.__exportStar)(require("./evaluationSchemas"), exports);
7
+ (0, tslib_1.__exportStar)(require("./eventSchemas"), exports);
8
+ (0, tslib_1.__exportStar)(require("./loggerSchema"), exports);
9
+ (0, tslib_1.__exportStar)(require("./operationSchemas"), exports);
10
+ (0, tslib_1.__exportStar)(require("./sdkFacadeSchemas"), exports);
11
+ (0, tslib_1.__exportStar)(require("./sdkSchemas"), exports);
12
+ (0, tslib_1.__exportStar)(require("./tokenSchema"), exports);
13
+ (0, tslib_1.__exportStar)(require("./userSchema"), exports);
@@ -7,3 +7,4 @@ export declare const decrementOperation: ObjectType;
7
7
  export declare const incrementOperation: ObjectType;
8
8
  export declare const clearOperation: ObjectType;
9
9
  export declare const unsetOperation: ObjectType;
10
+ export declare const removeOperation: ObjectType;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.unsetOperation = exports.clearOperation = exports.incrementOperation = exports.decrementOperation = exports.mergeOperation = exports.combineOperation = exports.setOperation = exports.addOperation = void 0;
3
+ exports.removeOperation = exports.unsetOperation = exports.clearOperation = exports.incrementOperation = exports.decrementOperation = exports.mergeOperation = exports.combineOperation = exports.setOperation = exports.addOperation = void 0;
4
4
  var validation_1 = require("../validation");
5
5
  var attributeSchema_1 = require("./attributeSchema");
6
6
  var pointer = new validation_1.StringType({
@@ -73,3 +73,10 @@ exports.unsetOperation = new validation_1.ObjectType({
73
73
  path: pointer,
74
74
  },
75
75
  });
76
+ exports.removeOperation = new validation_1.ObjectType({
77
+ required: ['path', 'value'],
78
+ properties: {
79
+ path: pointer,
80
+ value: mixedValue,
81
+ },
82
+ });
@@ -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,
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 () {
@@ -25,14 +25,14 @@ var Sdk = /** @class */ (function () {
25
25
  var e_1, _a;
26
26
  var _b, _c, _d, _e;
27
27
  validateConfiguration(configuration);
28
- var _f = configuration.eventMetadata, customMetadata = _f === void 0 ? {} : _f, containerConfiguration = tslib_1.__rest(configuration, ["eventMetadata"]);
28
+ var _f = configuration.eventMetadata, customMetadata = _f === void 0 ? {} : _f, containerConfiguration = (0, tslib_1.__rest)(configuration, ["eventMetadata"]);
29
29
  var eventMetadata = {
30
30
  sdkVersion: constants_1.VERSION,
31
31
  };
32
32
  try {
33
- for (var _g = tslib_1.__values(Object.keys(customMetadata)), _h = _g.next(); !_h.done; _h = _g.next()) {
33
+ for (var _g = (0, 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 }; }
@@ -42,7 +42,7 @@ var Sdk = /** @class */ (function () {
42
42
  }
43
43
  finally { if (e_1) throw e_1.error; }
44
44
  }
45
- var container = new container_1.Container(tslib_1.__assign(tslib_1.__assign({}, containerConfiguration), { evaluationEndpointUrl: (_b = containerConfiguration.evaluationEndpointUrl) !== null && _b !== void 0 ? _b : constants_1.EVALUATION_ENDPOINT_URL, trackerEndpointUrl: (_c = containerConfiguration.trackerEndpointUrl) !== null && _c !== void 0 ? _c : constants_1.TRACKER_ENDPOINT_URL, bootstrapEndpointUrl: (_d = containerConfiguration.bootstrapEndpointUrl) !== null && _d !== void 0 ? _d : constants_1.BOOTSTRAP_ENDPOINT_URL, beaconQueueSize: (_e = containerConfiguration.beaconQueueSize) !== null && _e !== void 0 ? _e : 100, eventMetadata: eventMetadata }));
45
+ var container = new container_1.Container((0, tslib_1.__assign)((0, tslib_1.__assign)({}, containerConfiguration), { evaluationEndpointUrl: (_b = containerConfiguration.evaluationEndpointUrl) !== null && _b !== void 0 ? _b : constants_1.EVALUATION_ENDPOINT_URL, trackerEndpointUrl: (_c = containerConfiguration.trackerEndpointUrl) !== null && _c !== void 0 ? _c : constants_1.TRACKER_ENDPOINT_URL, bootstrapEndpointUrl: (_d = containerConfiguration.bootstrapEndpointUrl) !== null && _d !== void 0 ? _d : constants_1.BOOTSTRAP_ENDPOINT_URL, beaconQueueSize: (_e = containerConfiguration.beaconQueueSize) !== null && _e !== void 0 ? _e : 100, eventMetadata: eventMetadata }));
46
46
  var logger = container.getLogger();
47
47
  var _j = container.getConfiguration(), appId = _j.appId, tokenScope = _j.tokenScope;
48
48
  logger.debug('\n\n'
@@ -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, (0, tslib_1.__spreadArray)([], (0, 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, (0, tslib_1.__spreadArray)([namespace], (0, tslib_1.__read)(subnamespace), false));
124
125
  };
125
126
  Sdk.prototype.getBrowserStorage = function (namespace) {
126
127
  var _a;
@@ -128,12 +129,12 @@ 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, (0, tslib_1.__spreadArray)([namespace], (0, tslib_1.__read)(subnamespace), false));
132
133
  };
133
134
  Sdk.prototype.close = function () {
134
- return tslib_1.__awaiter(this, void 0, void 0, function () {
135
+ return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
135
136
  var logger;
136
- return tslib_1.__generator(this, function (_a) {
137
+ return (0, tslib_1.__generator)(this, function (_a) {
137
138
  switch (_a.label) {
138
139
  case 0:
139
140
  if (this.closed) {
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 (0, tslib_1.__spreadArray)([], (0, 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 = (0, tslib_1.__spreadArray)([], (0, 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/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ReplicatedTokenStore = exports.InMemoryTokenStore = exports.CachedTokenStore = void 0;
4
4
  var tslib_1 = require("tslib");
5
- tslib_1.__exportStar(require("./token"), exports);
5
+ (0, tslib_1.__exportStar)(require("./token"), exports);
6
6
  var cachedTokenStore_1 = require("./cachedTokenStore");
7
7
  Object.defineProperty(exports, "CachedTokenStore", { enumerable: true, get: function () { return cachedTokenStore_1.CachedTokenStore; } });
8
8
  var inMemoryTokenStore_1 = require("./inMemoryTokenStore");
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
  }());