@croct/sdk 0.9.1 → 0.11.0-alpha

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 (122) hide show
  1. package/activeRecord.js +32 -36
  2. package/cache/fallbackCache.js +15 -32
  3. package/cache/inMemoryCache.js +9 -10
  4. package/cache/index.js +1 -1
  5. package/cache/localStorageCache.js +24 -25
  6. package/channel/beaconSocketChannel.d.ts +1 -1
  7. package/channel/beaconSocketChannel.js +49 -79
  8. package/channel/channel.d.ts +1 -1
  9. package/channel/encodedChannel.js +8 -10
  10. package/channel/guaranteedChannel.d.ts +4 -4
  11. package/channel/guaranteedChannel.js +41 -43
  12. package/channel/index.js +1 -1
  13. package/channel/queuedChannel.js +35 -64
  14. package/channel/retryChannel.d.ts +1 -1
  15. package/channel/retryChannel.js +44 -77
  16. package/channel/sandboxChannel.js +17 -18
  17. package/channel/socketChannel.d.ts +4 -4
  18. package/channel/socketChannel.js +77 -79
  19. package/cid/cachedAssigner.js +15 -27
  20. package/cid/fixedAssigner.js +5 -6
  21. package/cid/index.js +1 -1
  22. package/cid/remoteAssigner.js +23 -36
  23. package/constants.d.ts +3 -2
  24. package/constants.js +6 -5
  25. package/container.d.ts +13 -6
  26. package/container.js +152 -168
  27. package/contentFetcher.d.ts +59 -0
  28. package/contentFetcher.js +129 -0
  29. package/context.d.ts +3 -3
  30. package/context.js +36 -38
  31. package/error.js +2 -2
  32. package/evaluator.d.ts +33 -24
  33. package/evaluator.js +126 -117
  34. package/eventManager.d.ts +1 -1
  35. package/eventManager.js +14 -15
  36. package/facade/contentFetcherFacade.d.ts +27 -0
  37. package/facade/contentFetcherFacade.js +40 -0
  38. package/facade/evaluatorFacade.d.ts +13 -3
  39. package/facade/evaluatorFacade.js +57 -72
  40. package/facade/sdkFacade.d.ts +10 -3
  41. package/facade/sdkFacade.js +129 -141
  42. package/facade/sessionFacade.js +6 -7
  43. package/facade/sessionPatch.js +9 -13
  44. package/facade/trackerFacade.js +32 -38
  45. package/facade/userFacade.js +10 -11
  46. package/facade/userPatch.js +9 -13
  47. package/index.js +2 -2
  48. package/logging/consoleLogger.js +18 -35
  49. package/logging/index.js +1 -1
  50. package/logging/namespacedLogger.js +14 -15
  51. package/logging/nullLogger.js +10 -13
  52. package/namespacedStorage.js +30 -47
  53. package/package.json +13 -16
  54. package/patch.d.ts +1 -1
  55. package/queue/capacityRestrictedQueue.js +17 -18
  56. package/queue/inMemoryQueue.js +22 -28
  57. package/queue/index.js +1 -1
  58. package/queue/monitoredQueue.d.ts +2 -2
  59. package/queue/monitoredQueue.js +39 -40
  60. package/queue/persistentQueue.js +33 -38
  61. package/retry/arbitraryPolicy.js +8 -10
  62. package/retry/backoffPolicy.d.ts +1 -1
  63. package/retry/backoffPolicy.js +11 -13
  64. package/retry/index.js +1 -1
  65. package/retry/maxAttemptsPolicy.js +7 -8
  66. package/retry/neverPolicy.js +6 -9
  67. package/schema/attributeSchema.js +1 -1
  68. package/schema/contentFetcherSchemas.d.ts +2 -0
  69. package/schema/contentFetcherSchemas.js +22 -0
  70. package/schema/contentSchemas.js +1 -1
  71. package/schema/contextSchemas.js +1 -1
  72. package/schema/ecommerceSchemas.js +1 -1
  73. package/schema/evaluatorSchemas.d.ts +2 -0
  74. package/schema/{evaluationSchemas.js → evaluatorSchemas.js} +3 -3
  75. package/schema/eventSchemas.js +8 -9
  76. package/schema/index.d.ts +2 -1
  77. package/schema/index.js +3 -2
  78. package/schema/loggerSchema.js +1 -1
  79. package/schema/operationSchemas.js +8 -8
  80. package/schema/sdkFacadeSchemas.js +9 -6
  81. package/schema/sdkSchemas.js +8 -5
  82. package/schema/tokenSchema.js +5 -4
  83. package/schema/userSchema.js +2 -2
  84. package/sdk.d.ts +9 -3
  85. package/sdk.js +81 -127
  86. package/sdkEvents.d.ts +3 -3
  87. package/sourceLocation.d.ts +3 -3
  88. package/sourceLocation.js +13 -14
  89. package/tab.d.ts +5 -5
  90. package/tab.js +50 -80
  91. package/token/cachedTokenStore.js +9 -10
  92. package/token/inMemoryTokenStore.js +7 -8
  93. package/token/index.js +1 -1
  94. package/token/replicatedTokenStore.js +7 -8
  95. package/token/token.d.ts +9 -5
  96. package/token/token.js +63 -57
  97. package/tracker.d.ts +4 -4
  98. package/tracker.js +145 -122
  99. package/trackingEvents.d.ts +36 -36
  100. package/trackingEvents.js +12 -6
  101. package/transformer.js +1 -1
  102. package/utilityTypes.d.ts +2 -2
  103. package/uuid.js +9 -7
  104. package/validation/arrayType.d.ts +2 -2
  105. package/validation/arrayType.js +29 -27
  106. package/validation/booleanType.js +11 -15
  107. package/validation/functionType.js +11 -15
  108. package/validation/index.js +1 -1
  109. package/validation/jsonType.d.ts +2 -2
  110. package/validation/jsonType.js +61 -80
  111. package/validation/mixedSchema.js +4 -7
  112. package/validation/nullType.js +11 -15
  113. package/validation/numberType.d.ts +1 -1
  114. package/validation/numberType.js +23 -22
  115. package/validation/objectType.d.ts +1 -1
  116. package/validation/objectType.js +61 -73
  117. package/validation/schema.js +6 -10
  118. package/validation/stringType.d.ts +1 -1
  119. package/validation/stringType.js +36 -47
  120. package/validation/unionType.js +27 -77
  121. package/validation/violation.js +1 -2
  122. package/schema/evaluationSchemas.d.ts +0 -2
@@ -1,18 +1,28 @@
1
1
  import { JsonObject, JsonValue } from '@croct/json';
2
2
  import { Evaluator, EvaluationContext } from '../evaluator';
3
3
  import { Tab } from '../tab';
4
- export declare type EvaluationOptions = {
4
+ import { TokenProvider } from '../token';
5
+ import { CidAssigner } from '../cid';
6
+ export type EvaluationOptions = {
5
7
  timeout?: number;
6
8
  attributes?: JsonObject;
7
9
  };
8
10
  export interface ContextFactory {
9
11
  createContext(attributes?: JsonObject): EvaluationContext;
10
12
  }
13
+ export type Configuration = {
14
+ evaluator: Evaluator;
15
+ contextFactory: ContextFactory;
16
+ userTokenProvider: TokenProvider;
17
+ cidAssigner: CidAssigner;
18
+ };
11
19
  export declare class EvaluatorFacade {
12
20
  private readonly evaluator;
13
21
  private readonly contextFactory;
14
- constructor(evaluator: Evaluator, contextFactory: ContextFactory);
15
- evaluate(expression: string, options?: EvaluationOptions): Promise<JsonValue>;
22
+ private readonly tokenProvider;
23
+ private readonly cidAssigner;
24
+ constructor(configuration: Configuration);
25
+ evaluate(query: string, options?: EvaluationOptions): Promise<JsonValue>;
16
26
  }
17
27
  export declare class MinimalContextFactory implements ContextFactory {
18
28
  createContext(attributes?: JsonObject): EvaluationContext;
@@ -1,72 +1,69 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
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
+ const schema_1 = require("../schema");
5
+ const error_1 = require("../error");
7
6
  function validate(options) {
8
- if (typeof options !== 'object' || options === null) {
9
- throw new Error('The options must be an object.');
10
- }
11
7
  try {
12
- schema_1.optionsSchema.validate(options);
8
+ schema_1.evaluationOptionsSchema.validate(options);
13
9
  }
14
10
  catch (violation) {
15
- throw new Error("Invalid options: ".concat((0, error_1.formatCause)(violation)));
11
+ throw new Error(`Invalid options: ${(0, error_1.formatCause)(violation)}`);
16
12
  }
17
13
  }
18
- var EvaluatorFacade = /** @class */ (function () {
19
- function EvaluatorFacade(evaluator, contextFactory) {
20
- this.evaluator = evaluator;
21
- this.contextFactory = contextFactory;
14
+ class EvaluatorFacade {
15
+ constructor(configuration) {
16
+ this.evaluator = configuration.evaluator;
17
+ this.contextFactory = configuration.contextFactory;
18
+ this.tokenProvider = configuration.userTokenProvider;
19
+ this.cidAssigner = configuration.cidAssigner;
22
20
  }
23
- EvaluatorFacade.prototype.evaluate = function (expression, options) {
24
- if (options === void 0) { options = {}; }
25
- if (typeof expression !== 'string' || expression.length === 0) {
26
- throw new Error('The expression must be a non-empty string.');
21
+ async evaluate(query, options = {}) {
22
+ var _a;
23
+ if (typeof query !== 'string' || query.length === 0) {
24
+ throw new Error('The query must be a non-empty string.');
27
25
  }
28
26
  validate(options);
29
- return this.evaluator.evaluate(expression, {
27
+ return this.evaluator.evaluate(query, {
28
+ clientId: await this.cidAssigner.assignCid(),
29
+ userToken: (_a = this.tokenProvider.getToken()) !== null && _a !== void 0 ? _a : undefined,
30
30
  timeout: options.timeout,
31
31
  context: this.contextFactory.createContext(options.attributes),
32
32
  });
33
- };
34
- return EvaluatorFacade;
35
- }());
36
- exports.EvaluatorFacade = EvaluatorFacade;
37
- var MinimalContextFactory = /** @class */ (function () {
38
- function MinimalContextFactory() {
39
33
  }
40
- MinimalContextFactory.prototype.createContext = function (attributes) {
34
+ }
35
+ exports.EvaluatorFacade = EvaluatorFacade;
36
+ class MinimalContextFactory {
37
+ createContext(attributes) {
41
38
  if (attributes === undefined) {
42
39
  return {};
43
40
  }
44
41
  return { attributes: attributes };
45
- };
46
- return MinimalContextFactory;
47
- }());
42
+ }
43
+ }
48
44
  exports.MinimalContextFactory = MinimalContextFactory;
49
- var TabContextFactory = /** @class */ (function () {
50
- function TabContextFactory(tab) {
45
+ class TabContextFactory {
46
+ constructor(tab) {
51
47
  this.tab = tab;
52
48
  }
53
- TabContextFactory.prototype.createContext = function (attributes) {
54
- var url = new URL(this.tab.url);
55
- var context = {};
56
- var page = {
49
+ createContext(attributes) {
50
+ var _a;
51
+ const url = new URL(this.tab.url);
52
+ const context = {};
53
+ const page = {
57
54
  title: this.tab.title,
58
55
  url: url.toString(),
59
56
  };
60
- var referrer = this.tab.referrer;
57
+ const { referrer } = this.tab;
61
58
  if (referrer.length > 0) {
62
59
  page.referrer = referrer;
63
60
  }
64
61
  context.page = page;
65
- var timezone = Intl.DateTimeFormat().resolvedOptions().timeZone || null;
66
- if (timezone !== null) {
67
- context.timezone = timezone;
62
+ const timeZone = (_a = Intl.DateTimeFormat().resolvedOptions().timeZone) !== null && _a !== void 0 ? _a : null;
63
+ if (timeZone !== null) {
64
+ context.timeZone = timeZone;
68
65
  }
69
- var campaign = TabContextFactory.createCampaign(url);
66
+ const campaign = TabContextFactory.createCampaign(url);
70
67
  if (Object.keys(campaign).length > 0) {
71
68
  context.campaign = campaign;
72
69
  }
@@ -74,41 +71,29 @@ var TabContextFactory = /** @class */ (function () {
74
71
  context.attributes = attributes;
75
72
  }
76
73
  return context;
77
- };
78
- TabContextFactory.createCampaign = function (url) {
79
- var e_1, _a;
80
- var campaign = {};
81
- try {
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];
84
- switch (parameter.toLowerCase()) {
85
- case 'utm_campaign':
86
- campaign.name = value;
87
- break;
88
- case 'utm_source':
89
- campaign.source = value;
90
- break;
91
- case 'utm_term':
92
- campaign.term = value;
93
- break;
94
- case 'utm_medium':
95
- campaign.medium = value;
96
- break;
97
- case 'utm_content':
98
- campaign.content = value;
99
- break;
100
- }
101
- }
102
- }
103
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
104
- finally {
105
- try {
106
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
74
+ }
75
+ static createCampaign(url) {
76
+ const campaign = {};
77
+ for (const [parameter, value] of url.searchParams.entries()) {
78
+ switch (parameter.toLowerCase()) {
79
+ case 'utm_campaign':
80
+ campaign.name = value;
81
+ break;
82
+ case 'utm_source':
83
+ campaign.source = value;
84
+ break;
85
+ case 'utm_term':
86
+ campaign.term = value;
87
+ break;
88
+ case 'utm_medium':
89
+ campaign.medium = value;
90
+ break;
91
+ case 'utm_content':
92
+ campaign.content = value;
93
+ break;
107
94
  }
108
- finally { if (e_1) throw e_1.error; }
109
95
  }
110
96
  return campaign;
111
- };
112
- return TabContextFactory;
113
- }());
97
+ }
98
+ }
114
99
  exports.TabContextFactory = TabContextFactory;
@@ -2,14 +2,15 @@ import { EvaluatorFacade } from './evaluatorFacade';
2
2
  import { TrackerFacade } from './trackerFacade';
3
3
  import { Context, TokenScope } from '../context';
4
4
  import { UserFacade } from './userFacade';
5
- import { Token } from '../token';
5
+ import { Token, TokenStore } from '../token';
6
6
  import { SessionFacade } from './sessionFacade';
7
7
  import { Logger } from '../logging';
8
8
  import { SdkEventMap } from '../sdkEvents';
9
9
  import { EventManager } from '../eventManager';
10
10
  import { CidAssigner } from '../cid';
11
11
  import { UrlSanitizer } from '../tab';
12
- export declare type Configuration = {
12
+ import { ContentFetcherFacade } from './contentFetcherFacade';
13
+ export type Configuration = {
13
14
  appId: string;
14
15
  tokenScope?: TokenScope;
15
16
  debug?: boolean;
@@ -17,6 +18,7 @@ export declare type Configuration = {
17
18
  track?: boolean;
18
19
  token?: string | null;
19
20
  userId?: string;
21
+ clientId?: string;
20
22
  eventMetadata?: {
21
23
  [key: string]: string;
22
24
  };
@@ -24,7 +26,8 @@ export declare type Configuration = {
24
26
  urlSanitizer?: UrlSanitizer;
25
27
  trackerEndpointUrl?: string;
26
28
  evaluationEndpointUrl?: string;
27
- bootstrapEndpointUrl?: string;
29
+ contentEndpointUrl?: string;
30
+ cidAssignerEndpointUrl?: string;
28
31
  };
29
32
  export declare class SdkFacade {
30
33
  private readonly sdk;
@@ -32,14 +35,18 @@ export declare class SdkFacade {
32
35
  private userFacade?;
33
36
  private sessionFacade?;
34
37
  private evaluatorFacade?;
38
+ private contentFetcherFacade?;
35
39
  private constructor();
36
40
  static init(configuration: Configuration): SdkFacade;
37
41
  get context(): Context;
38
42
  get cidAssigner(): CidAssigner;
43
+ get previewTokenStore(): TokenStore;
44
+ get userTokenStore(): TokenStore;
39
45
  get tracker(): TrackerFacade;
40
46
  get user(): UserFacade;
41
47
  get session(): SessionFacade;
42
48
  get evaluator(): EvaluatorFacade;
49
+ get contentFetcher(): ContentFetcherFacade;
43
50
  get eventManager(): EventManager<Record<string, Record<string, unknown>>, SdkEventMap>;
44
51
  identify(userId: string): void;
45
52
  anonymize(): void;
@@ -1,38 +1,40 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
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");
4
+ const evaluatorFacade_1 = require("./evaluatorFacade");
5
+ const trackerFacade_1 = require("./trackerFacade");
6
+ const userFacade_1 = require("./userFacade");
7
+ const token_1 = require("../token");
8
+ const error_1 = require("../error");
9
+ const schema_1 = require("../schema");
10
+ const sdk_1 = require("../sdk");
11
+ const sessionFacade_1 = require("./sessionFacade");
12
+ const contentFetcherFacade_1 = require("./contentFetcherFacade");
13
13
  function validateConfiguration(configuration) {
14
- if (typeof configuration !== 'object' || configuration === null) {
15
- throw new Error('The configuration must be a key-value map.');
16
- }
17
14
  try {
18
15
  schema_1.sdkFacadeConfigurationSchema.validate(configuration);
19
16
  }
20
17
  catch (violation) {
21
- throw new Error("Invalid configuration: ".concat((0, error_1.formatCause)(violation)));
18
+ throw new Error(`Invalid configuration: ${(0, error_1.formatCause)(violation)}`);
22
19
  }
23
20
  }
24
- var SdkFacade = /** @class */ (function () {
25
- function SdkFacade(sdk) {
21
+ class SdkFacade {
22
+ constructor(sdk) {
26
23
  this.sdk = sdk;
27
24
  }
28
- SdkFacade.init = function (configuration) {
25
+ static init(configuration) {
29
26
  var _a, _b, _c;
30
27
  validateConfiguration(configuration);
31
- var _d = configuration.track, track = _d === void 0 ? true : _d, userId = configuration.userId, token = configuration.token, containerConfiguration = tslib_1.__rest(configuration, ["track", "userId", "token"]);
28
+ const { track = true, userId, token, ...containerConfiguration } = configuration;
32
29
  if (userId !== undefined && token !== undefined) {
33
30
  throw new Error('Either the user ID or token can be specified, but not both.');
34
31
  }
35
- var sdk = new SdkFacade(sdk_1.Sdk.init(tslib_1.__assign(tslib_1.__assign({}, containerConfiguration), { tokenScope: (_a = containerConfiguration.tokenScope) !== null && _a !== void 0 ? _a : 'global', debug: (_b = containerConfiguration.debug) !== null && _b !== void 0 ? _b : false, test: (_c = containerConfiguration.test) !== null && _c !== void 0 ? _c : false })));
32
+ const sdk = new SdkFacade(sdk_1.Sdk.init({
33
+ ...containerConfiguration,
34
+ tokenScope: (_a = containerConfiguration.tokenScope) !== null && _a !== void 0 ? _a : 'global',
35
+ debug: (_b = containerConfiguration.debug) !== null && _b !== void 0 ? _b : false,
36
+ test: (_c = containerConfiguration.test) !== null && _c !== void 0 ? _c : false,
37
+ }));
36
38
  if (userId !== undefined) {
37
39
  sdk.identify(userId);
38
40
  }
@@ -48,100 +50,99 @@ var SdkFacade = /** @class */ (function () {
48
50
  sdk.tracker.enable();
49
51
  }
50
52
  return sdk;
51
- };
52
- Object.defineProperty(SdkFacade.prototype, "context", {
53
- get: function () {
54
- return this.sdk.context;
55
- },
56
- enumerable: false,
57
- configurable: true
58
- });
59
- Object.defineProperty(SdkFacade.prototype, "cidAssigner", {
60
- get: function () {
61
- return this.sdk.cidAssigner;
62
- },
63
- enumerable: false,
64
- configurable: true
65
- });
66
- Object.defineProperty(SdkFacade.prototype, "tracker", {
67
- get: function () {
68
- if (this.trackerFacade === undefined) {
69
- this.trackerFacade = new trackerFacade_1.TrackerFacade(this.sdk.tracker);
70
- }
71
- return this.trackerFacade;
72
- },
73
- enumerable: false,
74
- configurable: true
75
- });
76
- Object.defineProperty(SdkFacade.prototype, "user", {
77
- get: function () {
78
- if (this.userFacade === undefined) {
79
- this.userFacade = new userFacade_1.UserFacade(this.context, this.sdk.tracker);
80
- }
81
- return this.userFacade;
82
- },
83
- enumerable: false,
84
- configurable: true
85
- });
86
- Object.defineProperty(SdkFacade.prototype, "session", {
87
- get: function () {
88
- if (this.sessionFacade === undefined) {
89
- this.sessionFacade = new sessionFacade_1.SessionFacade(this.sdk.tracker);
90
- }
91
- return this.sessionFacade;
92
- },
93
- enumerable: false,
94
- configurable: true
95
- });
96
- Object.defineProperty(SdkFacade.prototype, "evaluator", {
97
- get: function () {
98
- if (this.evaluatorFacade === undefined) {
99
- this.evaluatorFacade = new evaluatorFacade_1.EvaluatorFacade(this.sdk.evaluator, new evaluatorFacade_1.TabContextFactory(this.sdk.context.getTab()));
100
- }
101
- return this.evaluatorFacade;
102
- },
103
- enumerable: false,
104
- configurable: true
105
- });
106
- Object.defineProperty(SdkFacade.prototype, "eventManager", {
107
- get: function () {
108
- var eventManager = this.sdk.eventManager;
109
- return {
110
- addListener: eventManager.addListener.bind(eventManager),
111
- removeListener: eventManager.removeListener.bind(eventManager),
112
- dispatch: function (eventName, event) {
113
- if (!/[a-z][a-z_]+\.[a-z][a-z_]+/i.test(eventName)) {
114
- throw new Error('The event name must be in the form of "namespaced.eventName", where '
115
- + 'both the namespace and event name must start with a letter, followed by '
116
- + 'any series of letters and underscores.');
117
- }
118
- eventManager.dispatch(eventName, event);
119
- },
120
- };
121
- },
122
- enumerable: false,
123
- configurable: true
124
- });
125
- SdkFacade.prototype.identify = function (userId) {
53
+ }
54
+ get context() {
55
+ return this.sdk.context;
56
+ }
57
+ get cidAssigner() {
58
+ return this.sdk.cidAssigner;
59
+ }
60
+ get previewTokenStore() {
61
+ return this.sdk.previewTokenStore;
62
+ }
63
+ get userTokenStore() {
64
+ return this.sdk.userTokenStore;
65
+ }
66
+ get tracker() {
67
+ if (this.trackerFacade === undefined) {
68
+ this.trackerFacade = new trackerFacade_1.TrackerFacade(this.sdk.tracker);
69
+ }
70
+ return this.trackerFacade;
71
+ }
72
+ get user() {
73
+ if (this.userFacade === undefined) {
74
+ this.userFacade = new userFacade_1.UserFacade(this.context, this.sdk.tracker);
75
+ }
76
+ return this.userFacade;
77
+ }
78
+ get session() {
79
+ if (this.sessionFacade === undefined) {
80
+ this.sessionFacade = new sessionFacade_1.SessionFacade(this.sdk.tracker);
81
+ }
82
+ return this.sessionFacade;
83
+ }
84
+ get evaluator() {
85
+ if (this.evaluatorFacade === undefined) {
86
+ this.evaluatorFacade = new evaluatorFacade_1.EvaluatorFacade({
87
+ evaluator: this.sdk.evaluator,
88
+ contextFactory: new evaluatorFacade_1.TabContextFactory(this.sdk
89
+ .context
90
+ .getTab()),
91
+ cidAssigner: this.sdk.cidAssigner,
92
+ userTokenProvider: this.sdk.userTokenStore,
93
+ });
94
+ }
95
+ return this.evaluatorFacade;
96
+ }
97
+ get contentFetcher() {
98
+ if (this.contentFetcherFacade === undefined) {
99
+ this.contentFetcherFacade = new contentFetcherFacade_1.ContentFetcherFacade({
100
+ contentFetcher: this.sdk.contentFetcher,
101
+ contextFactory: new evaluatorFacade_1.TabContextFactory(this.sdk
102
+ .context
103
+ .getTab()),
104
+ cidAssigner: this.sdk.cidAssigner,
105
+ previewTokenProvider: this.sdk.previewTokenStore,
106
+ userTokenProvider: this.sdk.userTokenStore,
107
+ });
108
+ }
109
+ return this.contentFetcherFacade;
110
+ }
111
+ get eventManager() {
112
+ const { eventManager } = this.sdk;
113
+ return {
114
+ addListener: eventManager.addListener.bind(eventManager),
115
+ removeListener: eventManager.removeListener.bind(eventManager),
116
+ dispatch: (eventName, event) => {
117
+ if (!/[a-z][a-z_]+\.[a-z][a-z_]+/i.test(eventName)) {
118
+ throw new Error('The event name must be in the form of "namespaced.eventName", where '
119
+ + 'both the namespace and event name must start with a letter, followed by '
120
+ + 'any series of letters and underscores.');
121
+ }
122
+ eventManager.dispatch(eventName, event);
123
+ },
124
+ };
125
+ }
126
+ identify(userId) {
126
127
  this.setToken(token_1.Token.issue(this.sdk.appId, userId));
127
- };
128
- SdkFacade.prototype.anonymize = function () {
128
+ }
129
+ anonymize() {
129
130
  if (!this.context.isAnonymous()) {
130
131
  this.unsetToken();
131
132
  }
132
- };
133
- SdkFacade.prototype.getToken = function () {
133
+ }
134
+ getToken() {
134
135
  return this.context.getToken();
135
- };
136
- SdkFacade.prototype.setToken = function (token) {
136
+ }
137
+ setToken(token) {
137
138
  var _a;
138
- var currentToken = this.getToken();
139
+ const currentToken = this.getToken();
139
140
  if (currentToken !== null && currentToken.toString() === token.toString()) {
140
141
  return;
141
142
  }
142
- var currentSubject = (_a = currentToken === null || currentToken === void 0 ? void 0 : currentToken.getSubject()) !== null && _a !== void 0 ? _a : null;
143
- var subject = token.getSubject();
144
- var logger = this.getLogger();
143
+ const currentSubject = (_a = currentToken === null || currentToken === void 0 ? void 0 : currentToken.getSubject()) !== null && _a !== void 0 ? _a : null;
144
+ const subject = token.getSubject();
145
+ const logger = this.getLogger();
145
146
  if (subject === currentSubject) {
146
147
  this.context.setToken(token);
147
148
  logger.debug('Token refreshed');
@@ -160,17 +161,17 @@ var SdkFacade = /** @class */ (function () {
160
161
  type: 'userSignedIn',
161
162
  userId: subject,
162
163
  });
163
- logger.info("User signed in as ".concat(subject));
164
+ logger.info(`User signed in as ${subject}`);
164
165
  }
165
166
  logger.debug('New token saved, ');
166
- };
167
- SdkFacade.prototype.unsetToken = function () {
168
- var token = this.getToken();
167
+ }
168
+ unsetToken() {
169
+ const token = this.getToken();
169
170
  if (token === null) {
170
171
  return;
171
172
  }
172
- var logger = this.getLogger();
173
- var subject = token.getSubject();
173
+ const logger = this.getLogger();
174
+ const subject = token.getSubject();
174
175
  if (subject !== null) {
175
176
  this.trackInternalEvent({
176
177
  type: 'userSignedOut',
@@ -180,39 +181,26 @@ var SdkFacade = /** @class */ (function () {
180
181
  }
181
182
  this.context.setToken(null);
182
183
  logger.debug('Token removed');
183
- };
184
- SdkFacade.prototype.trackInternalEvent = function (event) {
185
- this.sdk.tracker.track(event).catch(function () {
184
+ }
185
+ trackInternalEvent(event) {
186
+ this.sdk
187
+ .tracker
188
+ .track(event)
189
+ .catch(() => {
186
190
  // suppress error as it is already logged by the tracker
187
191
  });
188
- };
189
- SdkFacade.prototype.getLogger = function () {
190
- var _a;
191
- var namespace = [];
192
- for (var _i = 0; _i < arguments.length; _i++) {
193
- namespace[_i] = arguments[_i];
194
- }
195
- return (_a = this.sdk).getLogger.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(namespace), false));
196
- };
197
- SdkFacade.prototype.getTabStorage = function (namespace) {
198
- var _a;
199
- var subnamespace = [];
200
- for (var _i = 1; _i < arguments.length; _i++) {
201
- subnamespace[_i - 1] = arguments[_i];
202
- }
203
- return (_a = this.sdk).getTabStorage.apply(_a, tslib_1.__spreadArray([namespace], tslib_1.__read(subnamespace), false));
204
- };
205
- SdkFacade.prototype.getBrowserStorage = function (namespace) {
206
- var _a;
207
- var subnamespace = [];
208
- for (var _i = 1; _i < arguments.length; _i++) {
209
- subnamespace[_i - 1] = arguments[_i];
210
- }
211
- return (_a = this.sdk).getBrowserStorage.apply(_a, tslib_1.__spreadArray([namespace], tslib_1.__read(subnamespace), false));
212
- };
213
- SdkFacade.prototype.close = function () {
192
+ }
193
+ getLogger(...namespace) {
194
+ return this.sdk.getLogger(...namespace);
195
+ }
196
+ getTabStorage(namespace, ...subnamespace) {
197
+ return this.sdk.getTabStorage(namespace, ...subnamespace);
198
+ }
199
+ getBrowserStorage(namespace, ...subnamespace) {
200
+ return this.sdk.getBrowserStorage(namespace, ...subnamespace);
201
+ }
202
+ close() {
214
203
  return this.sdk.close();
215
- };
216
- return SdkFacade;
217
- }());
204
+ }
205
+ }
218
206
  exports.SdkFacade = SdkFacade;
@@ -1,14 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SessionFacade = void 0;
4
- var sessionPatch_1 = require("./sessionPatch");
5
- var SessionFacade = /** @class */ (function () {
6
- function SessionFacade(tracker) {
4
+ const sessionPatch_1 = require("./sessionPatch");
5
+ class SessionFacade {
6
+ constructor(tracker) {
7
7
  this.tracker = tracker;
8
8
  }
9
- SessionFacade.prototype.edit = function () {
9
+ edit() {
10
10
  return new sessionPatch_1.SessionPatch(this.tracker);
11
- };
12
- return SessionFacade;
13
- }());
11
+ }
12
+ }
14
13
  exports.SessionFacade = SessionFacade;
@@ -1,16 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SessionPatch = void 0;
4
- var tslib_1 = require("tslib");
5
- var activeRecord_1 = require("../activeRecord");
6
- var SessionPatch = /** @class */ (function (_super) {
7
- tslib_1.__extends(SessionPatch, _super);
8
- function SessionPatch(tracker) {
9
- var _this = _super.call(this) || this;
10
- _this.tracker = tracker;
11
- return _this;
4
+ const activeRecord_1 = require("../activeRecord");
5
+ class SessionPatch extends activeRecord_1.ActiveRecord {
6
+ constructor(tracker) {
7
+ super();
8
+ this.tracker = tracker;
12
9
  }
13
- SessionPatch.prototype.save = function () {
10
+ save() {
14
11
  if (!this.isDirty()) {
15
12
  // Empty patch
16
13
  return Promise.resolve({
@@ -18,13 +15,12 @@ var SessionPatch = /** @class */ (function (_super) {
18
15
  patch: { operations: [] },
19
16
  });
20
17
  }
21
- var promise = this.tracker.track({
18
+ const promise = this.tracker.track({
22
19
  type: 'sessionAttributesChanged',
23
20
  patch: this.buildPatch(),
24
21
  });
25
22
  this.reset();
26
23
  return promise;
27
- };
28
- return SessionPatch;
29
- }(activeRecord_1.ActiveRecord));
24
+ }
25
+ }
30
26
  exports.SessionPatch = SessionPatch;