@croct/sdk 0.5.0 → 0.7.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 (187) hide show
  1. package/activeRecord.d.ts +1 -1
  2. package/activeRecord.js +15 -12
  3. package/base64Url.js +7 -2
  4. package/cache/cache.d.ts +12 -0
  5. package/cache/cache.js +2 -0
  6. package/cache/fallbackCache.d.ts +2 -2
  7. package/cache/fallbackCache.js +6 -3
  8. package/cache/inMemoryCache.d.ts +2 -2
  9. package/cache/inMemoryCache.js +5 -2
  10. package/cache/index.d.ts +4 -12
  11. package/cache/index.js +11 -0
  12. package/cache/localStorageCache.d.ts +2 -2
  13. package/cache/localStorageCache.js +4 -1
  14. package/channel/beaconSocketChannel.d.ts +3 -3
  15. package/channel/beaconSocketChannel.js +12 -9
  16. package/channel/channel.d.ts +15 -0
  17. package/channel/channel.js +2 -0
  18. package/channel/encodedChannel.d.ts +2 -2
  19. package/channel/encodedChannel.js +4 -1
  20. package/channel/guaranteedChannel.d.ts +1 -1
  21. package/channel/guaranteedChannel.js +10 -7
  22. package/channel/index.d.ts +8 -15
  23. package/channel/index.js +19 -0
  24. package/channel/queuedChannel.d.ts +2 -2
  25. package/channel/queuedChannel.js +10 -7
  26. package/channel/retryChannel.d.ts +3 -3
  27. package/channel/retryChannel.js +18 -15
  28. package/channel/sandboxChannel.d.ts +2 -2
  29. package/channel/sandboxChannel.js +4 -1
  30. package/channel/socketChannel.d.ts +1 -1
  31. package/channel/socketChannel.js +12 -9
  32. package/cid/assigner.d.ts +3 -0
  33. package/cid/assigner.js +2 -0
  34. package/cid/cachedAssigner.d.ts +5 -5
  35. package/cid/cachedAssigner.js +9 -6
  36. package/cid/fixedAssigner.d.ts +6 -0
  37. package/cid/fixedAssigner.js +13 -0
  38. package/cid/index.d.ts +4 -3
  39. package/cid/index.js +11 -0
  40. package/cid/remoteAssigner.d.ts +3 -3
  41. package/cid/remoteAssigner.js +11 -8
  42. package/constants.js +8 -5
  43. package/container.d.ts +5 -5
  44. package/container.js +49 -55
  45. package/context.d.ts +4 -4
  46. package/context.js +14 -13
  47. package/error.d.ts +1 -1
  48. package/error.js +7 -2
  49. package/evaluator.d.ts +2 -2
  50. package/evaluator.js +26 -23
  51. package/eventManager.d.ts +1 -1
  52. package/eventManager.js +5 -2
  53. package/facade/evaluatorFacade.d.ts +3 -3
  54. package/facade/evaluatorFacade.js +13 -10
  55. package/facade/index.d.ts +7 -0
  56. package/facade/index.js +19 -0
  57. package/facade/sdkFacade.d.ts +9 -9
  58. package/facade/sdkFacade.js +35 -32
  59. package/facade/sessionFacade.d.ts +3 -3
  60. package/facade/sessionFacade.js +6 -3
  61. package/facade/sessionPatch.d.ts +3 -3
  62. package/facade/sessionPatch.js +8 -5
  63. package/facade/trackerFacade.d.ts +2 -2
  64. package/facade/trackerFacade.js +21 -17
  65. package/facade/userFacade.d.ts +4 -4
  66. package/facade/userFacade.js +6 -3
  67. package/facade/userPatch.d.ts +3 -3
  68. package/facade/userPatch.js +8 -5
  69. package/index.d.ts +2 -2
  70. package/index.js +7 -3
  71. package/json.js +2 -0
  72. package/logging/consoleLogger.d.ts +2 -2
  73. package/logging/consoleLogger.js +8 -5
  74. package/logging/index.d.ts +4 -9
  75. package/logging/index.js +11 -0
  76. package/logging/logger.d.ts +9 -0
  77. package/logging/logger.js +2 -0
  78. package/logging/namespacedLogger.d.ts +2 -2
  79. package/logging/namespacedLogger.js +4 -1
  80. package/logging/nullLogger.d.ts +2 -2
  81. package/logging/nullLogger.js +4 -1
  82. package/namespacedStorage.d.ts +1 -1
  83. package/namespacedStorage.js +7 -4
  84. package/package.json +21 -18
  85. package/patch.js +2 -0
  86. package/queue/capacityRestrictedQueue.d.ts +2 -2
  87. package/queue/capacityRestrictedQueue.js +4 -1
  88. package/queue/inMemoryQueue.d.ts +2 -2
  89. package/queue/inMemoryQueue.js +6 -3
  90. package/queue/index.d.ts +5 -9
  91. package/queue/index.js +13 -0
  92. package/queue/monitoredQueue.d.ts +6 -6
  93. package/queue/monitoredQueue.js +6 -3
  94. package/queue/persistentQueue.d.ts +2 -2
  95. package/queue/persistentQueue.js +5 -2
  96. package/queue/queue.d.ts +9 -0
  97. package/queue/queue.js +2 -0
  98. package/retry/arbitraryPolicy.d.ts +2 -2
  99. package/retry/arbitraryPolicy.js +6 -3
  100. package/retry/backoffPolicy.d.ts +2 -2
  101. package/retry/backoffPolicy.js +4 -1
  102. package/retry/index.d.ts +5 -4
  103. package/retry/index.js +13 -0
  104. package/retry/maxAttemptsPolicy.d.ts +2 -2
  105. package/retry/maxAttemptsPolicy.js +4 -1
  106. package/retry/neverPolicy.d.ts +2 -2
  107. package/retry/neverPolicy.js +4 -1
  108. package/retry/policy.d.ts +4 -0
  109. package/retry/policy.js +2 -0
  110. package/schema/attributeSchema.d.ts +2 -0
  111. package/schema/attributeSchema.js +8 -0
  112. package/schema/contentSchemas.d.ts +2 -0
  113. package/schema/contentSchemas.js +46 -0
  114. package/schema/contextSchemas.d.ts +1 -1
  115. package/schema/contextSchemas.js +5 -2
  116. package/schema/ecommerceSchemas.d.ts +1 -1
  117. package/schema/ecommerceSchemas.js +60 -60
  118. package/schema/evaluationSchemas.d.ts +1 -1
  119. package/schema/evaluationSchemas.js +7 -6
  120. package/schema/eventSchemas.d.ts +3 -2
  121. package/schema/eventSchemas.js +53 -48
  122. package/schema/index.d.ts +10 -0
  123. package/schema/index.js +13 -0
  124. package/schema/loggerSchema.d.ts +1 -1
  125. package/schema/loggerSchema.js +9 -7
  126. package/schema/operationSchemas.d.ts +1 -1
  127. package/schema/operationSchemas.js +26 -24
  128. package/schema/sdkFacadeSchemas.d.ts +2 -2
  129. package/schema/sdkFacadeSchemas.js +22 -24
  130. package/schema/sdkSchemas.d.ts +2 -2
  131. package/schema/sdkSchemas.js +21 -22
  132. package/schema/tokenSchema.d.ts +2 -3
  133. package/schema/tokenSchema.js +18 -17
  134. package/schema/userSchema.d.ts +1 -1
  135. package/schema/userSchema.js +47 -61
  136. package/sdk.d.ts +5 -5
  137. package/sdk.js +27 -24
  138. package/sdkEvents.d.ts +2 -2
  139. package/sdkEvents.js +2 -0
  140. package/sourceLocation.js +12 -6
  141. package/tab.d.ts +2 -2
  142. package/tab.js +12 -9
  143. package/token/cachedTokenStore.d.ts +3 -3
  144. package/token/cachedTokenStore.js +6 -3
  145. package/token/inMemoryTokenStore.d.ts +2 -2
  146. package/token/inMemoryTokenStore.js +4 -1
  147. package/token/index.d.ts +4 -41
  148. package/token/index.js +11 -96
  149. package/token/replicatedTokenStore.d.ts +2 -2
  150. package/token/replicatedTokenStore.js +4 -1
  151. package/token/token.d.ts +41 -0
  152. package/token/token.js +99 -0
  153. package/tracker.d.ts +3 -3
  154. package/tracker.js +29 -26
  155. package/trackingEvents.d.ts +29 -14
  156. package/trackingEvents.js +20 -14
  157. package/transformer.js +5 -1
  158. package/utilityTypes.js +2 -0
  159. package/uuid.js +5 -1
  160. package/validation/arrayType.d.ts +2 -2
  161. package/validation/arrayType.js +13 -9
  162. package/validation/booleanType.d.ts +2 -2
  163. package/validation/booleanType.js +7 -3
  164. package/validation/functionType.d.ts +2 -2
  165. package/validation/functionType.js +7 -3
  166. package/validation/index.d.ts +12 -18
  167. package/validation/index.js +29 -30
  168. package/validation/jsonType.d.ts +2 -1
  169. package/validation/jsonType.js +25 -14
  170. package/validation/mixedSchema.d.ts +2 -2
  171. package/validation/mixedSchema.js +4 -1
  172. package/validation/nullType.d.ts +2 -2
  173. package/validation/nullType.js +7 -3
  174. package/validation/numberType.d.ts +2 -2
  175. package/validation/numberType.js +13 -9
  176. package/validation/objectType.d.ts +2 -2
  177. package/validation/objectType.js +23 -18
  178. package/validation/schema.d.ts +16 -0
  179. package/validation/schema.js +15 -0
  180. package/validation/stringType.d.ts +2 -2
  181. package/validation/stringType.js +16 -12
  182. package/validation/unionType.d.ts +2 -2
  183. package/validation/unionType.js +14 -10
  184. package/validation/violation.d.ts +2 -0
  185. package/validation/violation.js +24 -0
  186. package/cid/fixedCidAssigner.d.ts +0 -6
  187. package/cid/fixedCidAssigner.js +0 -10
package/evaluator.js CHANGED
@@ -1,8 +1,11 @@
1
- import { __assign, __awaiter, __extends, __generator } from "tslib";
2
- import { EVALUATION_ENDPOINT_URL, MAX_EXPRESSION_LENGTH } from './constants';
3
- import { formatMessage } from './error';
4
- import { getLength, getLocation } from './sourceLocation';
5
- export var EvaluationErrorType;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Evaluator = exports.ExpressionError = exports.EvaluationError = exports.EvaluationErrorType = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var constants_1 = require("./constants");
6
+ var error_1 = require("./error");
7
+ var sourceLocation_1 = require("./sourceLocation");
8
+ var EvaluationErrorType;
6
9
  (function (EvaluationErrorType) {
7
10
  EvaluationErrorType["TIMEOUT"] = "https://croct.help/api/evaluation#timeout";
8
11
  EvaluationErrorType["UNEXPECTED_ERROR"] = "https://croct.help/api/evaluation#unexpected-error";
@@ -11,9 +14,9 @@ export var EvaluationErrorType;
11
14
  EvaluationErrorType["EVALUATION_FAILED"] = "https://croct.help/api/evaluation#evaluation-failed";
12
15
  EvaluationErrorType["UNALLOWED_RESULT"] = "https://croct.help/api/evaluation#unallowed-result";
13
16
  EvaluationErrorType["UNSERIALIZABLE_RESULT"] = "https://croct.help/api/evaluation#unserializable-result";
14
- })(EvaluationErrorType || (EvaluationErrorType = {}));
17
+ })(EvaluationErrorType = exports.EvaluationErrorType || (exports.EvaluationErrorType = {}));
15
18
  var EvaluationError = /** @class */ (function (_super) {
16
- __extends(EvaluationError, _super);
19
+ tslib_1.__extends(EvaluationError, _super);
17
20
  function EvaluationError(response) {
18
21
  var _this = _super.call(this, response.title) || this;
19
22
  _this.response = response;
@@ -22,9 +25,9 @@ var EvaluationError = /** @class */ (function (_super) {
22
25
  }
23
26
  return EvaluationError;
24
27
  }(Error));
25
- export { EvaluationError };
28
+ exports.EvaluationError = EvaluationError;
26
29
  var ExpressionError = /** @class */ (function (_super) {
27
- __extends(ExpressionError, _super);
30
+ tslib_1.__extends(ExpressionError, _super);
28
31
  function ExpressionError(response) {
29
32
  var _this = _super.call(this, response) || this;
30
33
  Object.setPrototypeOf(_this, ExpressionError.prototype);
@@ -32,19 +35,19 @@ var ExpressionError = /** @class */ (function (_super) {
32
35
  }
33
36
  return ExpressionError;
34
37
  }(EvaluationError));
35
- export { ExpressionError };
38
+ exports.ExpressionError = ExpressionError;
36
39
  var Evaluator = /** @class */ (function () {
37
40
  function Evaluator(configuration) {
38
41
  var _a;
39
- this.configuration = __assign(__assign({}, configuration), { endpointUrl: (_a = configuration.endpointUrl, (_a !== null && _a !== void 0 ? _a : EVALUATION_ENDPOINT_URL)) });
42
+ this.configuration = tslib_1.__assign(tslib_1.__assign({}, configuration), { endpointUrl: (_a = configuration.endpointUrl) !== null && _a !== void 0 ? _a : constants_1.EVALUATION_ENDPOINT_URL });
40
43
  }
41
44
  Evaluator.prototype.evaluate = function (expression, options) {
42
45
  if (options === void 0) { options = {}; }
43
- return __awaiter(this, void 0, void 0, function () {
46
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
44
47
  var length, response, endpoint;
45
48
  var _this = this;
46
- return __generator(this, function (_a) {
47
- length = getLength(expression);
49
+ return tslib_1.__generator(this, function (_a) {
50
+ length = sourceLocation_1.getLength(expression);
48
51
  if (length > Evaluator.MAX_EXPRESSION_LENGTH) {
49
52
  response = {
50
53
  title: 'The expression is too complex.',
@@ -54,7 +57,7 @@ var Evaluator = /** @class */ (function () {
54
57
  + ("but it is " + length + " characters long."),
55
58
  errors: [{
56
59
  cause: 'The expression is longer than expected.',
57
- location: getLocation(expression, 0, Math.max(length - 1, 0)),
60
+ location: sourceLocation_1.getLocation(expression, 0, Math.max(length - 1, 0)),
58
61
  }],
59
62
  };
60
63
  return [2 /*return*/, Promise.reject(new ExpressionError(response))];
@@ -71,7 +74,7 @@ var Evaluator = /** @class */ (function () {
71
74
  title: 'Maximum evaluation timeout reached before evaluation could complete.',
72
75
  type: EvaluationErrorType.TIMEOUT,
73
76
  detail: "The evaluation took more than " + options.timeout + "ms to complete.",
74
- status: 408,
77
+ status: 408, // Request Timeout
75
78
  };
76
79
  reject(new EvaluationError(response));
77
80
  }, options.timeout);
@@ -97,10 +100,10 @@ var Evaluator = /** @class */ (function () {
97
100
  });
98
101
  }, function (error) {
99
102
  var errorResponse = {
100
- title: formatMessage(error),
103
+ title: error_1.formatMessage(error),
101
104
  type: EvaluationErrorType.UNEXPECTED_ERROR,
102
105
  detail: 'Please try again or contact Croct support if the error persists.',
103
- status: 500,
106
+ status: 500, // Internal Server Error
104
107
  };
105
108
  reject(new EvaluationError(errorResponse));
106
109
  });
@@ -109,9 +112,9 @@ var Evaluator = /** @class */ (function () {
109
112
  });
110
113
  };
111
114
  Evaluator.prototype.fetch = function (endpoint) {
112
- return __awaiter(this, void 0, void 0, function () {
115
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
113
116
  var _a, tokenProvider, cidAssigner, appId, token, cid, headers;
114
- return __generator(this, function (_b) {
117
+ return tslib_1.__generator(this, function (_b) {
115
118
  switch (_b.label) {
116
119
  case 0:
117
120
  _a = this.configuration, tokenProvider = _a.tokenProvider, cidAssigner = _a.cidAssigner, appId = _a.appId;
@@ -119,7 +122,7 @@ var Evaluator = /** @class */ (function () {
119
122
  return [4 /*yield*/, cidAssigner.assignCid()];
120
123
  case 1:
121
124
  cid = _b.sent();
122
- headers = __assign({ 'X-App-Id': appId, 'X-Client-Id': cid }, (token !== null && { 'X-Token': token.toString() }));
125
+ headers = tslib_1.__assign({ 'X-App-Id': appId, 'X-Client-Id': cid }, (token !== null && { 'X-Token': token.toString() }));
123
126
  return [2 /*return*/, window.fetch(endpoint.toString(), {
124
127
  method: 'GET',
125
128
  headers: headers,
@@ -129,7 +132,7 @@ var Evaluator = /** @class */ (function () {
129
132
  });
130
133
  });
131
134
  };
132
- Evaluator.MAX_EXPRESSION_LENGTH = MAX_EXPRESSION_LENGTH;
135
+ Evaluator.MAX_EXPRESSION_LENGTH = constants_1.MAX_EXPRESSION_LENGTH;
133
136
  return Evaluator;
134
137
  }());
135
- export default Evaluator;
138
+ exports.Evaluator = Evaluator;
package/eventManager.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export interface EventListener<T> {
2
2
  (event: T): void;
3
3
  }
4
- export declare type EventMap = Record<string, object>;
4
+ export declare type EventMap = Record<string, Record<string, any>>;
5
5
  export interface EventDispatcher<TEvents extends EventMap> {
6
6
  dispatch<T extends keyof TEvents>(eventName: T, event: TEvents[T]): void;
7
7
  }
package/eventManager.js CHANGED
@@ -1,10 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SynchronousEventManager = void 0;
1
4
  var SynchronousEventManager = /** @class */ (function () {
2
5
  function SynchronousEventManager() {
3
6
  this.listeners = {};
4
7
  }
5
8
  SynchronousEventManager.prototype.addListener = function (type, listener) {
6
9
  var _a;
7
- var listeners = (_a = this.listeners[type], (_a !== null && _a !== void 0 ? _a : []));
10
+ var listeners = (_a = this.listeners[type]) !== null && _a !== void 0 ? _a : [];
8
11
  listeners.push(listener);
9
12
  this.listeners[type] = listeners;
10
13
  };
@@ -26,4 +29,4 @@ var SynchronousEventManager = /** @class */ (function () {
26
29
  };
27
30
  return SynchronousEventManager;
28
31
  }());
29
- export { SynchronousEventManager };
32
+ exports.SynchronousEventManager = SynchronousEventManager;
@@ -1,6 +1,6 @@
1
- import Evaluator, { EvaluationContext } from '../evaluator';
1
+ import { Evaluator, EvaluationContext } from '../evaluator';
2
2
  import { JsonObject, JsonValue } from '../json';
3
- import Tab from '../tab';
3
+ import { Tab } from '../tab';
4
4
  export declare type EvaluationOptions = {
5
5
  timeout?: number;
6
6
  attributes?: JsonObject;
@@ -8,7 +8,7 @@ export declare type EvaluationOptions = {
8
8
  export interface ContextFactory {
9
9
  createContext(attributes?: JsonObject): EvaluationContext;
10
10
  }
11
- export default class EvaluatorFacade {
11
+ export declare class EvaluatorFacade {
12
12
  private readonly evaluator;
13
13
  private readonly contextFactory;
14
14
  constructor(evaluator: Evaluator, contextFactory: ContextFactory);
@@ -1,15 +1,18 @@
1
- import { __read, __values } from "tslib";
2
- import { optionsSchema } from '../schema/evaluationSchemas';
3
- import { formatCause } from '../error';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TabContextFactory = exports.MinimalContextFactory = exports.EvaluatorFacade = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var schema_1 = require("../schema");
6
+ var error_1 = require("../error");
4
7
  function validate(options) {
5
8
  if (typeof options !== 'object' || options === null) {
6
9
  throw new Error('The options must be an object.');
7
10
  }
8
11
  try {
9
- optionsSchema.validate(options);
12
+ schema_1.optionsSchema.validate(options);
10
13
  }
11
14
  catch (violation) {
12
- throw new Error("Invalid options: " + formatCause(violation));
15
+ throw new Error("Invalid options: " + error_1.formatCause(violation));
13
16
  }
14
17
  }
15
18
  var EvaluatorFacade = /** @class */ (function () {
@@ -30,7 +33,7 @@ var EvaluatorFacade = /** @class */ (function () {
30
33
  };
31
34
  return EvaluatorFacade;
32
35
  }());
33
- export default EvaluatorFacade;
36
+ exports.EvaluatorFacade = EvaluatorFacade;
34
37
  var MinimalContextFactory = /** @class */ (function () {
35
38
  function MinimalContextFactory() {
36
39
  }
@@ -42,7 +45,7 @@ var MinimalContextFactory = /** @class */ (function () {
42
45
  };
43
46
  return MinimalContextFactory;
44
47
  }());
45
- export { MinimalContextFactory };
48
+ exports.MinimalContextFactory = MinimalContextFactory;
46
49
  var TabContextFactory = /** @class */ (function () {
47
50
  function TabContextFactory(tab) {
48
51
  this.tab = tab;
@@ -76,8 +79,8 @@ var TabContextFactory = /** @class */ (function () {
76
79
  var e_1, _a;
77
80
  var campaign = {};
78
81
  try {
79
- for (var _b = __values(url.searchParams.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
80
- var _d = __read(_c.value, 2), parameter = _d[0], value = _d[1];
82
+ for (var _b = tslib_1.__values(url.searchParams.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
83
+ var _d = tslib_1.__read(_c.value, 2), parameter = _d[0], value = _d[1];
81
84
  switch (parameter.toLowerCase()) {
82
85
  case 'utm_campaign':
83
86
  campaign.name = value;
@@ -108,4 +111,4 @@ var TabContextFactory = /** @class */ (function () {
108
111
  };
109
112
  return TabContextFactory;
110
113
  }());
111
- export { TabContextFactory };
114
+ exports.TabContextFactory = TabContextFactory;
@@ -0,0 +1,7 @@
1
+ export { EvaluatorFacade, ContextFactory, MinimalContextFactory, TabContextFactory } from './evaluatorFacade';
2
+ export { SdkFacade } from './sdkFacade';
3
+ export { SessionFacade } from './sessionFacade';
4
+ export { SessionPatch } from './sessionPatch';
5
+ export { TrackerFacade } from './trackerFacade';
6
+ export { UserFacade } from './userFacade';
7
+ export { UserPatch } from './userPatch';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UserPatch = exports.UserFacade = exports.TrackerFacade = exports.SessionPatch = exports.SessionFacade = exports.SdkFacade = exports.TabContextFactory = exports.MinimalContextFactory = exports.EvaluatorFacade = void 0;
4
+ var evaluatorFacade_1 = require("./evaluatorFacade");
5
+ Object.defineProperty(exports, "EvaluatorFacade", { enumerable: true, get: function () { return evaluatorFacade_1.EvaluatorFacade; } });
6
+ Object.defineProperty(exports, "MinimalContextFactory", { enumerable: true, get: function () { return evaluatorFacade_1.MinimalContextFactory; } });
7
+ Object.defineProperty(exports, "TabContextFactory", { enumerable: true, get: function () { return evaluatorFacade_1.TabContextFactory; } });
8
+ var sdkFacade_1 = require("./sdkFacade");
9
+ Object.defineProperty(exports, "SdkFacade", { enumerable: true, get: function () { return sdkFacade_1.SdkFacade; } });
10
+ var sessionFacade_1 = require("./sessionFacade");
11
+ Object.defineProperty(exports, "SessionFacade", { enumerable: true, get: function () { return sessionFacade_1.SessionFacade; } });
12
+ var sessionPatch_1 = require("./sessionPatch");
13
+ Object.defineProperty(exports, "SessionPatch", { enumerable: true, get: function () { return sessionPatch_1.SessionPatch; } });
14
+ var trackerFacade_1 = require("./trackerFacade");
15
+ Object.defineProperty(exports, "TrackerFacade", { enumerable: true, get: function () { return trackerFacade_1.TrackerFacade; } });
16
+ var userFacade_1 = require("./userFacade");
17
+ Object.defineProperty(exports, "UserFacade", { enumerable: true, get: function () { return userFacade_1.UserFacade; } });
18
+ var userPatch_1 = require("./userPatch");
19
+ Object.defineProperty(exports, "UserPatch", { enumerable: true, get: function () { return userPatch_1.UserPatch; } });
@@ -1,13 +1,13 @@
1
- import EvaluatorFacade from './evaluatorFacade';
2
- import TrackerFacade from './trackerFacade';
3
- import Context, { TokenScope } from '../context';
4
- import UserFacade from './userFacade';
5
- import Token from '../token';
6
- import SessionFacade from './sessionFacade';
1
+ import { EvaluatorFacade } from './evaluatorFacade';
2
+ import { TrackerFacade } from './trackerFacade';
3
+ import { Context, TokenScope } from '../context';
4
+ import { UserFacade } from './userFacade';
5
+ import { Token } from '../token';
6
+ import { SessionFacade } from './sessionFacade';
7
7
  import { Logger } from '../logging';
8
8
  import { SdkEventMap } from '../sdkEvents';
9
9
  import { EventManager } from '../eventManager';
10
- import CidAssigner from '../cid/index';
10
+ import { CidAssigner } from '../cid';
11
11
  import { UrlSanitizer } from '../tab';
12
12
  export declare type Configuration = {
13
13
  appId: string;
@@ -25,7 +25,7 @@ export declare type Configuration = {
25
25
  evaluationEndpointUrl?: string;
26
26
  bootstrapEndpointUrl?: string;
27
27
  };
28
- export default class SdkFacade {
28
+ export declare class SdkFacade {
29
29
  private readonly sdk;
30
30
  private trackerFacade?;
31
31
  private userFacade?;
@@ -39,7 +39,7 @@ export default class SdkFacade {
39
39
  get user(): UserFacade;
40
40
  get session(): SessionFacade;
41
41
  get evaluator(): EvaluatorFacade;
42
- get eventManager(): EventManager<Record<string, object>, SdkEventMap>;
42
+ get eventManager(): EventManager<Record<string, Record<string, unknown>>, SdkEventMap>;
43
43
  identify(userId: string): void;
44
44
  anonymize(): void;
45
45
  getToken(): Token | null;
@@ -1,21 +1,24 @@
1
- import { __assign, __read, __rest, __spread } from "tslib";
2
- import EvaluatorFacade, { TabContextFactory } from './evaluatorFacade';
3
- import TrackerFacade from './trackerFacade';
4
- import UserFacade from './userFacade';
5
- import Token from '../token';
6
- import { formatCause } from '../error';
7
- import { configurationSchema } from '../schema/sdkFacadeSchemas';
8
- import Sdk from '../sdk';
9
- import SessionFacade from './sessionFacade';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SdkFacade = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var evaluatorFacade_1 = require("./evaluatorFacade");
6
+ var trackerFacade_1 = require("./trackerFacade");
7
+ var userFacade_1 = require("./userFacade");
8
+ var token_1 = require("../token");
9
+ var error_1 = require("../error");
10
+ var schema_1 = require("../schema");
11
+ var sdk_1 = require("../sdk");
12
+ var sessionFacade_1 = require("./sessionFacade");
10
13
  function validateConfiguration(configuration) {
11
14
  if (typeof configuration !== 'object' || configuration === null) {
12
15
  throw new Error('The configuration must be a key-value map.');
13
16
  }
14
17
  try {
15
- configurationSchema.validate(configuration);
18
+ schema_1.sdkFacadeConfigurationSchema.validate(configuration);
16
19
  }
17
20
  catch (violation) {
18
- throw new Error("Invalid configuration: " + formatCause(violation));
21
+ throw new Error("Invalid configuration: " + error_1.formatCause(violation));
19
22
  }
20
23
  }
21
24
  var SdkFacade = /** @class */ (function () {
@@ -25,11 +28,11 @@ var SdkFacade = /** @class */ (function () {
25
28
  SdkFacade.init = function (configuration) {
26
29
  var _a, _b;
27
30
  validateConfiguration(configuration);
28
- var _c = configuration.track, track = _c === void 0 ? true : _c, userId = configuration.userId, token = configuration.token, containerConfiguration = __rest(configuration, ["track", "userId", "token"]);
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"]);
29
32
  if (userId !== undefined && token !== undefined) {
30
33
  throw new Error('Either the user ID or token can be specified, but not both.');
31
34
  }
32
- var sdk = new SdkFacade(Sdk.init(__assign(__assign({}, containerConfiguration), { tokenScope: (_a = containerConfiguration.tokenScope, (_a !== null && _a !== void 0 ? _a : 'global')), debug: (_b = containerConfiguration.debug, (_b !== 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 })));
33
36
  if (userId !== undefined) {
34
37
  sdk.identify(userId);
35
38
  }
@@ -38,7 +41,7 @@ var SdkFacade = /** @class */ (function () {
38
41
  sdk.unsetToken();
39
42
  }
40
43
  else {
41
- sdk.setToken(Token.parse(token));
44
+ sdk.setToken(token_1.Token.parse(token));
42
45
  }
43
46
  }
44
47
  if (track) {
@@ -50,54 +53,54 @@ var SdkFacade = /** @class */ (function () {
50
53
  get: function () {
51
54
  return this.sdk.context;
52
55
  },
53
- enumerable: true,
56
+ enumerable: false,
54
57
  configurable: true
55
58
  });
56
59
  Object.defineProperty(SdkFacade.prototype, "cidAssigner", {
57
60
  get: function () {
58
61
  return this.sdk.cidAssigner;
59
62
  },
60
- enumerable: true,
63
+ enumerable: false,
61
64
  configurable: true
62
65
  });
63
66
  Object.defineProperty(SdkFacade.prototype, "tracker", {
64
67
  get: function () {
65
68
  if (this.trackerFacade === undefined) {
66
- this.trackerFacade = new TrackerFacade(this.sdk.tracker);
69
+ this.trackerFacade = new trackerFacade_1.TrackerFacade(this.sdk.tracker);
67
70
  }
68
71
  return this.trackerFacade;
69
72
  },
70
- enumerable: true,
73
+ enumerable: false,
71
74
  configurable: true
72
75
  });
73
76
  Object.defineProperty(SdkFacade.prototype, "user", {
74
77
  get: function () {
75
78
  if (this.userFacade === undefined) {
76
- this.userFacade = new UserFacade(this.context, this.sdk.tracker);
79
+ this.userFacade = new userFacade_1.UserFacade(this.context, this.sdk.tracker);
77
80
  }
78
81
  return this.userFacade;
79
82
  },
80
- enumerable: true,
83
+ enumerable: false,
81
84
  configurable: true
82
85
  });
83
86
  Object.defineProperty(SdkFacade.prototype, "session", {
84
87
  get: function () {
85
88
  if (this.sessionFacade === undefined) {
86
- this.sessionFacade = new SessionFacade(this.sdk.tracker);
89
+ this.sessionFacade = new sessionFacade_1.SessionFacade(this.sdk.tracker);
87
90
  }
88
91
  return this.sessionFacade;
89
92
  },
90
- enumerable: true,
93
+ enumerable: false,
91
94
  configurable: true
92
95
  });
93
96
  Object.defineProperty(SdkFacade.prototype, "evaluator", {
94
97
  get: function () {
95
98
  if (this.evaluatorFacade === undefined) {
96
- this.evaluatorFacade = new EvaluatorFacade(this.sdk.evaluator, new TabContextFactory(this.sdk.context.getTab()));
99
+ this.evaluatorFacade = new evaluatorFacade_1.EvaluatorFacade(this.sdk.evaluator, new evaluatorFacade_1.TabContextFactory(this.sdk.context.getTab()));
97
100
  }
98
101
  return this.evaluatorFacade;
99
102
  },
100
- enumerable: true,
103
+ enumerable: false,
101
104
  configurable: true
102
105
  });
103
106
  Object.defineProperty(SdkFacade.prototype, "eventManager", {
@@ -116,11 +119,11 @@ var SdkFacade = /** @class */ (function () {
116
119
  },
117
120
  };
118
121
  },
119
- enumerable: true,
122
+ enumerable: false,
120
123
  configurable: true
121
124
  });
122
125
  SdkFacade.prototype.identify = function (userId) {
123
- this.setToken(Token.issue(this.sdk.appId, userId));
126
+ this.setToken(token_1.Token.issue(this.sdk.appId, userId));
124
127
  };
125
128
  SdkFacade.prototype.anonymize = function () {
126
129
  if (!this.context.isAnonymous()) {
@@ -131,12 +134,12 @@ var SdkFacade = /** @class */ (function () {
131
134
  return this.context.getToken();
132
135
  };
133
136
  SdkFacade.prototype.setToken = function (token) {
134
- var _a, _b;
137
+ var _a;
135
138
  var currentToken = this.getToken();
136
139
  if (currentToken !== null && currentToken.toString() === token.toString()) {
137
140
  return;
138
141
  }
139
- var currentSubject = (_b = (_a = currentToken) === null || _a === void 0 ? void 0 : _a.getSubject(), (_b !== null && _b !== void 0 ? _b : null));
142
+ var currentSubject = (_a = currentToken === null || currentToken === void 0 ? void 0 : currentToken.getSubject()) !== null && _a !== void 0 ? _a : null;
140
143
  var subject = token.getSubject();
141
144
  var logger = this.getLogger();
142
145
  if (subject === currentSubject) {
@@ -189,7 +192,7 @@ var SdkFacade = /** @class */ (function () {
189
192
  for (var _i = 0; _i < arguments.length; _i++) {
190
193
  namespace[_i] = arguments[_i];
191
194
  }
192
- return (_a = this.sdk).getLogger.apply(_a, __spread(namespace));
195
+ return (_a = this.sdk).getLogger.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(namespace)));
193
196
  };
194
197
  SdkFacade.prototype.getTabStorage = function (namespace) {
195
198
  var _a;
@@ -197,7 +200,7 @@ var SdkFacade = /** @class */ (function () {
197
200
  for (var _i = 1; _i < arguments.length; _i++) {
198
201
  subnamespace[_i - 1] = arguments[_i];
199
202
  }
200
- return (_a = this.sdk).getTabStorage.apply(_a, __spread([namespace], subnamespace));
203
+ return (_a = this.sdk).getTabStorage.apply(_a, tslib_1.__spreadArray([namespace], tslib_1.__read(subnamespace)));
201
204
  };
202
205
  SdkFacade.prototype.getBrowserStorage = function (namespace) {
203
206
  var _a;
@@ -205,11 +208,11 @@ var SdkFacade = /** @class */ (function () {
205
208
  for (var _i = 1; _i < arguments.length; _i++) {
206
209
  subnamespace[_i - 1] = arguments[_i];
207
210
  }
208
- return (_a = this.sdk).getBrowserStorage.apply(_a, __spread([namespace], subnamespace));
211
+ return (_a = this.sdk).getBrowserStorage.apply(_a, tslib_1.__spreadArray([namespace], tslib_1.__read(subnamespace)));
209
212
  };
210
213
  SdkFacade.prototype.close = function () {
211
214
  return this.sdk.close();
212
215
  };
213
216
  return SdkFacade;
214
217
  }());
215
- export default SdkFacade;
218
+ exports.SdkFacade = SdkFacade;
@@ -1,6 +1,6 @@
1
- import Tracker from '../tracker';
2
- import SessionPatch from './sessionPatch';
3
- export default class SessionFacade {
1
+ import { Tracker } from '../tracker';
2
+ import { SessionPatch } from './sessionPatch';
3
+ export declare class SessionFacade {
4
4
  private readonly tracker;
5
5
  constructor(tracker: Tracker);
6
6
  edit(): SessionPatch;
@@ -1,11 +1,14 @@
1
- import SessionPatch from './sessionPatch';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SessionFacade = void 0;
4
+ var sessionPatch_1 = require("./sessionPatch");
2
5
  var SessionFacade = /** @class */ (function () {
3
6
  function SessionFacade(tracker) {
4
7
  this.tracker = tracker;
5
8
  }
6
9
  SessionFacade.prototype.edit = function () {
7
- return new SessionPatch(this.tracker);
10
+ return new sessionPatch_1.SessionPatch(this.tracker);
8
11
  };
9
12
  return SessionFacade;
10
13
  }());
11
- export default SessionFacade;
14
+ exports.SessionFacade = SessionFacade;
@@ -1,7 +1,7 @@
1
- import ActiveRecord from '../activeRecord';
2
- import Tracker from '../tracker';
1
+ import { ActiveRecord } from '../activeRecord';
2
+ import { Tracker } from '../tracker';
3
3
  import { SessionAttributesChanged } from '../trackingEvents';
4
- export default class SessionPatch extends ActiveRecord<SessionAttributesChanged> {
4
+ export declare class SessionPatch extends ActiveRecord<SessionAttributesChanged> {
5
5
  private readonly tracker;
6
6
  constructor(tracker: Tracker);
7
7
  save(): Promise<SessionAttributesChanged>;
@@ -1,7 +1,10 @@
1
- import { __extends } from "tslib";
2
- import ActiveRecord from '../activeRecord';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SessionPatch = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var activeRecord_1 = require("../activeRecord");
3
6
  var SessionPatch = /** @class */ (function (_super) {
4
- __extends(SessionPatch, _super);
7
+ tslib_1.__extends(SessionPatch, _super);
5
8
  function SessionPatch(tracker) {
6
9
  var _this = _super.call(this) || this;
7
10
  _this.tracker = tracker;
@@ -23,5 +26,5 @@ var SessionPatch = /** @class */ (function (_super) {
23
26
  return promise;
24
27
  };
25
28
  return SessionPatch;
26
- }(ActiveRecord));
27
- export default SessionPatch;
29
+ }(activeRecord_1.ActiveRecord));
30
+ exports.SessionPatch = SessionPatch;
@@ -1,6 +1,6 @@
1
1
  import { ExternalTrackingEvent as ExternalEvent, ExternalTrackingEventPayload as ExternalEventPayload, ExternalTrackingEventType as ExternalEventType } from '../trackingEvents';
2
- import Tracker, { EventListener } from '../tracker';
3
- export default class TrackerFacade {
2
+ import { Tracker, EventListener } from '../tracker';
3
+ export declare class TrackerFacade {
4
4
  private readonly tracker;
5
5
  constructor(tracker: Tracker);
6
6
  get flushed(): Promise<void>;
@@ -1,16 +1,20 @@
1
- import { __assign, __rest } from "tslib";
2
- import { formatCause } from '../error';
3
- import { cartModified, cartViewed, checkoutStarted, eventOccurred, goalCompleted, orderPlaced, productViewed, testGroupAssigned, userSignedUp, } from '../schema/eventSchemas';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TrackerFacade = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var error_1 = require("../error");
6
+ var schema_1 = require("../schema");
4
7
  var eventSchemas = {
5
- cartViewed: cartViewed,
6
- cartModified: cartModified,
7
- checkoutStarted: checkoutStarted,
8
- orderPlaced: orderPlaced,
9
- productViewed: productViewed,
10
- userSignedUp: userSignedUp,
11
- testGroupAssigned: testGroupAssigned,
12
- eventOccurred: eventOccurred,
13
- goalCompleted: goalCompleted,
8
+ cartViewed: schema_1.cartViewed,
9
+ cartModified: schema_1.cartModified,
10
+ checkoutStarted: schema_1.checkoutStarted,
11
+ orderPlaced: schema_1.orderPlaced,
12
+ productViewed: schema_1.productViewed,
13
+ userSignedUp: schema_1.userSignedUp,
14
+ eventOccurred: schema_1.eventOccurred,
15
+ interestShown: schema_1.interestShown,
16
+ postViewed: schema_1.postViewed,
17
+ goalCompleted: schema_1.goalCompleted,
14
18
  };
15
19
  function createEvent(type, payload) {
16
20
  if (typeof type !== 'string') {
@@ -19,12 +23,12 @@ function createEvent(type, payload) {
19
23
  if (typeof payload !== 'object' || payload == null) {
20
24
  throw new Error('The event payload must of type object.');
21
25
  }
22
- var event = __assign({ type: type }, payload);
26
+ var event = tslib_1.__assign({ type: type }, payload);
23
27
  validateEvent(event);
24
28
  return event;
25
29
  }
26
30
  function validateEvent(event) {
27
- var type = event.type, payload = __rest(event, ["type"]);
31
+ var type = event.type, payload = tslib_1.__rest(event, ["type"]);
28
32
  if (!(type in eventSchemas)) {
29
33
  throw new Error("Unknown event type '" + type + "'.");
30
34
  }
@@ -32,7 +36,7 @@ function validateEvent(event) {
32
36
  eventSchemas[type].validate(payload);
33
37
  }
34
38
  catch (violation) {
35
- throw new Error("Invalid event payload: " + formatCause(violation));
39
+ throw new Error("Invalid event payload: " + error_1.formatCause(violation));
36
40
  }
37
41
  }
38
42
  var TrackerFacade = /** @class */ (function () {
@@ -43,7 +47,7 @@ var TrackerFacade = /** @class */ (function () {
43
47
  get: function () {
44
48
  return this.tracker.flushed;
45
49
  },
46
- enumerable: true,
50
+ enumerable: false,
47
51
  configurable: true
48
52
  });
49
53
  TrackerFacade.prototype.enable = function () {
@@ -63,4 +67,4 @@ var TrackerFacade = /** @class */ (function () {
63
67
  };
64
68
  return TrackerFacade;
65
69
  }());
66
- export default TrackerFacade;
70
+ exports.TrackerFacade = TrackerFacade;
@@ -1,7 +1,7 @@
1
- import Tracker from '../tracker';
2
- import UserPatch from './userPatch';
3
- import Context from '../context';
4
- export default class UserFacade {
1
+ import { Tracker } from '../tracker';
2
+ import { UserPatch } from './userPatch';
3
+ import { Context } from '../context';
4
+ export declare class UserFacade {
5
5
  private readonly context;
6
6
  private readonly tracker;
7
7
  constructor(context: Context, tracker: Tracker);