@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
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.postDetails = void 0;
4
+ var validation_1 = require("../validation");
5
+ exports.postDetails = new validation_1.ObjectType({
6
+ required: ['postId', 'title', 'publishTime'],
7
+ properties: {
8
+ postId: new validation_1.StringType({
9
+ minLength: 1,
10
+ maxLength: 100,
11
+ }),
12
+ url: new validation_1.StringType({
13
+ format: 'url',
14
+ }),
15
+ title: new validation_1.StringType({
16
+ minLength: 1,
17
+ maxLength: 100,
18
+ }),
19
+ tags: new validation_1.ArrayType({
20
+ items: new validation_1.StringType({
21
+ minLength: 1,
22
+ maxLength: 50,
23
+ }),
24
+ minItems: 1,
25
+ maxItems: 10,
26
+ }),
27
+ categories: new validation_1.ArrayType({
28
+ items: new validation_1.StringType({
29
+ minLength: 1,
30
+ maxLength: 50,
31
+ }),
32
+ minItems: 1,
33
+ maxItems: 10,
34
+ }),
35
+ authors: new validation_1.ArrayType({
36
+ items: new validation_1.StringType({
37
+ minLength: 1,
38
+ maxLength: 50,
39
+ }),
40
+ minItems: 1,
41
+ maxItems: 10,
42
+ }),
43
+ publishTime: new validation_1.NumberType(),
44
+ updateTime: new validation_1.NumberType(),
45
+ },
46
+ });
@@ -5,6 +5,8 @@ export declare const checkoutStarted: ObjectType;
5
5
  export declare const orderPlaced: ObjectType;
6
6
  export declare const productViewed: ObjectType;
7
7
  export declare const userSignedUp: ObjectType;
8
- export declare const testGroupAssigned: ObjectType;
9
8
  export declare const goalCompleted: ObjectType;
9
+ export declare const interestShown: ObjectType;
10
+ export declare const postViewed: ObjectType;
11
+ export declare const linkOpened: ObjectType;
10
12
  export declare const eventOccurred: ObjectType;
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.eventOccurred = exports.goalCompleted = exports.testGroupAssigned = 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");
7
+ var contentSchemas_1 = require("./contentSchemas");
7
8
  exports.cartModified = new validation_1.ObjectType({
8
9
  required: ['cart'],
9
10
  properties: {
@@ -48,19 +49,6 @@ exports.userSignedUp = new validation_1.ObjectType({
48
49
  profile: userSchema_1.userProfileSchema,
49
50
  },
50
51
  });
51
- exports.testGroupAssigned = new validation_1.ObjectType({
52
- required: ['testId', 'groupId'],
53
- properties: {
54
- testId: new validation_1.StringType({
55
- minLength: 1,
56
- maxLength: 50,
57
- }),
58
- groupId: new validation_1.StringType({
59
- minLength: 1,
60
- maxLength: 50,
61
- }),
62
- },
63
- });
64
52
  exports.goalCompleted = new validation_1.ObjectType({
65
53
  required: ['goalId'],
66
54
  properties: {
@@ -77,6 +65,33 @@ exports.goalCompleted = new validation_1.ObjectType({
77
65
  }),
78
66
  },
79
67
  });
68
+ exports.interestShown = new validation_1.ObjectType({
69
+ required: ['interests'],
70
+ properties: {
71
+ interests: new validation_1.ArrayType({
72
+ items: new validation_1.StringType({
73
+ minLength: 1,
74
+ maxLength: 50,
75
+ }),
76
+ minItems: 1,
77
+ maxItems: 10,
78
+ }),
79
+ },
80
+ });
81
+ exports.postViewed = new validation_1.ObjectType({
82
+ required: ['post'],
83
+ properties: {
84
+ post: contentSchemas_1.postDetails,
85
+ },
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
+ });
80
95
  exports.eventOccurred = new validation_1.ObjectType({
81
96
  required: ['name'],
82
97
  properties: {
@@ -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,7 +1,8 @@
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
+ var attributeSchema_1 = require("./attributeSchema");
5
6
  var pointer = new validation_1.StringType({
6
7
  format: 'pointer',
7
8
  });
@@ -10,9 +11,11 @@ var simpleArray = new validation_1.JsonArrayType({
10
11
  });
11
12
  var simpleMap = new validation_1.JsonObjectType({
12
13
  properties: new validation_1.JsonPrimitiveType(),
14
+ propertyNames: attributeSchema_1.attributeNameSchema,
13
15
  });
14
16
  var complexMap = new validation_1.JsonObjectType({
15
17
  properties: new validation_1.UnionType(new validation_1.JsonPrimitiveType(), simpleArray, simpleMap),
18
+ propertyNames: attributeSchema_1.attributeNameSchema,
16
19
  });
17
20
  var collectionValue = new validation_1.UnionType(simpleArray, complexMap);
18
21
  var mixedValue = new validation_1.UnionType(new validation_1.JsonPrimitiveType(), simpleArray, complexMap);
@@ -70,3 +73,10 @@ exports.unsetOperation = new validation_1.ObjectType({
70
73
  path: pointer,
71
74
  },
72
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,
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.userProfileSchema = void 0;
4
4
  var validation_1 = require("../validation");
5
+ var attributeSchema_1 = require("./attributeSchema");
5
6
  exports.userProfileSchema = new validation_1.ObjectType({
6
7
  properties: {
7
8
  firstName: new validation_1.StringType({
@@ -93,10 +94,7 @@ exports.userProfileSchema = new validation_1.ObjectType({
93
94
  }),
94
95
  }),
95
96
  custom: new validation_1.ObjectType({
96
- propertyNames: new validation_1.StringType({
97
- maxLength: 50,
98
- format: 'identifier',
99
- }),
97
+ propertyNames: attributeSchema_1.attributeNameSchema,
100
98
  maxProperties: 10,
101
99
  additionalProperties: new validation_1.UnionType(new validation_1.BooleanType(), new validation_1.NullType(), new validation_1.NumberType(), new validation_1.StringType({
102
100
  maxLength: 100,
@@ -110,20 +108,14 @@ exports.userProfileSchema = new validation_1.ObjectType({
110
108
  maxLength: 100,
111
109
  })),
112
110
  }), new validation_1.ObjectType({
113
- propertyNames: new validation_1.StringType({
114
- maxLength: 50,
115
- format: 'identifier',
116
- }),
111
+ propertyNames: attributeSchema_1.attributeNameSchema,
117
112
  maxProperties: 10,
118
113
  additionalProperties: new validation_1.UnionType(new validation_1.BooleanType(), new validation_1.NullType(), new validation_1.NumberType(), new validation_1.StringType({
119
114
  maxLength: 100,
120
115
  })),
121
116
  })),
122
117
  }), new validation_1.ObjectType({
123
- propertyNames: new validation_1.StringType({
124
- maxLength: 50,
125
- format: 'identifier',
126
- }),
118
+ propertyNames: attributeSchema_1.attributeNameSchema,
127
119
  maxProperties: 10,
128
120
  additionalProperties: new validation_1.UnionType(new validation_1.BooleanType(), new validation_1.NullType(), new validation_1.NumberType(), new validation_1.StringType({
129
121
  maxLength: 100,
@@ -133,10 +125,7 @@ exports.userProfileSchema = new validation_1.ObjectType({
133
125
  maxLength: 100,
134
126
  })),
135
127
  }), new validation_1.ObjectType({
136
- propertyNames: new validation_1.StringType({
137
- maxLength: 50,
138
- format: 'identifier',
139
- }),
128
+ propertyNames: attributeSchema_1.attributeNameSchema,
140
129
  maxProperties: 10,
141
130
  additionalProperties: new validation_1.UnionType(new validation_1.BooleanType(), new validation_1.NullType(), new validation_1.NumberType(), new validation_1.StringType({
142
131
  maxLength: 100,
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.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", "testGroupAssigned", "goalCompleted", "eventOccurred"];
75
- export declare const eventTypes: readonly ["pageLoaded", "pageOpened", "cartModified", "cartViewed", "checkoutStarted", "orderPlaced", "productViewed", ...string[], "userProfileChanged", "nothingChanged", "sessionAttributesChanged", "testGroupAssigned", "goalCompleted", "eventOccurred"];
74
+ export declare const miscEventTypes: readonly ["nothingChanged", "sessionAttributesChanged", "goalCompleted", "interestShown", "postViewed", "eventOccurred", "linkOpened"];
75
+ export declare const eventTypes: readonly ["pageLoaded", "pageOpened", "cartModified", "cartViewed", "checkoutStarted", "orderPlaced", "productViewed", ...string[], "userProfileChanged", "nothingChanged", "sessionAttributesChanged", "goalCompleted", "interestShown", "postViewed", "eventOccurred", "linkOpened"];
76
76
  interface BaseEvent {
77
77
  type: string;
78
78
  }
@@ -200,17 +200,30 @@ export interface SessionAttributesChanged extends BaseEvent {
200
200
  type: 'sessionAttributesChanged';
201
201
  patch: Patch;
202
202
  }
203
- export interface TestGroupAssigned extends BaseEvent {
204
- type: 'testGroupAssigned';
205
- testId: string;
206
- groupId: string;
207
- }
208
203
  export interface GoalCompleted extends BaseEvent {
209
204
  type: 'goalCompleted';
210
205
  goalId: string;
211
206
  value?: number;
212
207
  currency?: string;
213
208
  }
209
+ export interface InterestShown extends BaseEvent {
210
+ type: 'interestShown';
211
+ interests: string[];
212
+ }
213
+ export interface PostDetails {
214
+ postId: string;
215
+ url?: string;
216
+ title: string;
217
+ tags?: string[];
218
+ categories?: string[];
219
+ authors?: string[];
220
+ publishTime: number;
221
+ updateTime?: number;
222
+ }
223
+ export interface PostViewed extends BaseEvent {
224
+ type: 'postViewed';
225
+ post: PostDetails;
226
+ }
214
227
  export interface EventOccurred extends BaseEvent {
215
228
  type: 'eventOccurred';
216
229
  name: string;
@@ -222,7 +235,11 @@ export interface EventOccurred extends BaseEvent {
222
235
  [key: string]: string | number | boolean | null;
223
236
  };
224
237
  }
225
- export declare type MiscEvent = NothingChanged | SessionAttributesChanged | TestGroupAssigned | EventOccurred | GoalCompleted;
238
+ export interface LinkOpened extends BaseEvent {
239
+ type: 'linkOpened';
240
+ link: string;
241
+ }
242
+ export declare type MiscEvent = NothingChanged | SessionAttributesChanged | EventOccurred | GoalCompleted | InterestShown | PostViewed | LinkOpened;
226
243
  declare type EventMap = {
227
244
  tabVisibilityChanged: TabVisibilityChanged;
228
245
  tabUrlChanged: TabUrlChanged;
@@ -240,9 +257,11 @@ declare type EventMap = {
240
257
  orderPlaced: OrderPlaced;
241
258
  nothingChanged: NothingChanged;
242
259
  sessionAttributesChanged: SessionAttributesChanged;
243
- testGroupAssigned: TestGroupAssigned;
244
260
  goalCompleted: GoalCompleted;
261
+ interestShown: InterestShown;
262
+ postViewed: PostViewed;
245
263
  eventOccurred: EventOccurred;
264
+ linkOpened: LinkOpened;
246
265
  };
247
266
  export declare type TrackingEventType = keyof EventMap;
248
267
  export declare type TrackingEvent<T extends TrackingEventType = TrackingEventType> = T extends TrackingEventType ? EventMap[T] : EventMap[TrackingEventType];
@@ -261,8 +280,10 @@ declare type ExternalEventMap = {
261
280
  orderPlaced: OrderPlaced;
262
281
  productViewed: ProductViewed;
263
282
  userSignedUp: UserSignedUp;
264
- testGroupAssigned: TestGroupAssigned;
265
283
  goalCompleted: GoalCompleted;
284
+ interestShown: InterestShown;
285
+ postViewed: PostViewed;
286
+ linkOpened: LinkOpened;
266
287
  eventOccurred: EventOccurred;
267
288
  };
268
289
  export declare type ExternalTrackingEventType = keyof ExternalEventMap;
package/trackingEvents.js CHANGED
@@ -19,26 +19,28 @@ exports.cartEventTypes = [
19
19
  'cartViewed',
20
20
  'checkoutStarted',
21
21
  ];
22
- exports.ecommerceEventTypes = tslib_1.__spreadArray(tslib_1.__spreadArray([], tslib_1.__read(exports.cartEventTypes)), [
22
+ exports.ecommerceEventTypes = 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',
37
- 'testGroupAssigned',
38
37
  'goalCompleted',
38
+ 'interestShown',
39
+ 'postViewed',
39
40
  'eventOccurred',
41
+ 'linkOpened',
40
42
  ];
41
- exports.eventTypes = tslib_1.__spreadArray(tslib_1.__spreadArray(tslib_1.__spreadArray(tslib_1.__spreadArray([], tslib_1.__read(exports.pageEventTypes)), tslib_1.__read(exports.ecommerceEventTypes)), tslib_1.__read(exports.userEventTypes)), tslib_1.__read(exports.miscEventTypes));
43
+ exports.eventTypes = 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);
42
44
  /*
43
45
  * Type guards
44
46
  */
package/uuid.js CHANGED
@@ -6,7 +6,7 @@ function uuid4(sortable) {
6
6
  var uuid = '';
7
7
  if (sortable) {
8
8
  var prefix = Date.now().toString(16).padStart(12, '0').substring(0, 12);
9
- uuid = prefix.substring(0, 8) + "-" + prefix.substring(8, 12);
9
+ uuid = "".concat(prefix.substring(0, 8), "-").concat(prefix.substring(8, 12));
10
10
  }
11
11
  for (var index = uuid.length; index < 36; index++) {
12
12
  switch (index) {
@@ -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;
@@ -1,6 +1,7 @@
1
1
  import { Schema, TypeSchema } from './schema';
2
2
  declare type JsonObjectDefinition = {
3
3
  properties?: Schema;
4
+ propertyNames?: Schema;
4
5
  };
5
6
  export declare class JsonObjectType implements TypeSchema {
6
7
  private readonly definition;