@croct/sdk 0.10.0 → 0.11.0-alpha.1

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 (231) hide show
  1. package/.src/activeRecord.ts +150 -0
  2. package/.src/base64Url.ts +18 -0
  3. package/.src/cache/cache.ts +15 -0
  4. package/.src/cache/fallbackCache.ts +29 -0
  5. package/.src/cache/inMemoryCache.ts +21 -0
  6. package/.src/cache/index.ts +4 -0
  7. package/.src/cache/localStorageCache.ts +85 -0
  8. package/.src/channel/beaconSocketChannel.ts +153 -0
  9. package/.src/channel/channel.ts +20 -0
  10. package/.src/channel/encodedChannel.ts +21 -0
  11. package/.src/channel/guaranteedChannel.ts +131 -0
  12. package/.src/channel/index.ts +8 -0
  13. package/.src/channel/queuedChannel.ts +112 -0
  14. package/.src/channel/retryChannel.ts +90 -0
  15. package/.src/channel/sandboxChannel.ts +43 -0
  16. package/.src/channel/socketChannel.ts +217 -0
  17. package/.src/cid/assigner.ts +3 -0
  18. package/.src/cid/cachedAssigner.ts +35 -0
  19. package/.src/cid/fixedAssigner.ts +13 -0
  20. package/.src/cid/index.ts +4 -0
  21. package/.src/cid/remoteAssigner.ts +47 -0
  22. package/.src/constants.ts +6 -0
  23. package/.src/container.ts +388 -0
  24. package/.src/contentFetcher.ts +226 -0
  25. package/.src/context.ts +137 -0
  26. package/.src/error.ts +31 -0
  27. package/.src/evaluator.ts +251 -0
  28. package/.src/eventManager.ts +53 -0
  29. package/.src/facade/contentFetcherFacade.ts +69 -0
  30. package/.src/facade/evaluatorFacade.ts +152 -0
  31. package/.src/facade/index.ts +7 -0
  32. package/.src/facade/sdkFacade.ts +291 -0
  33. package/.src/facade/sessionFacade.ts +14 -0
  34. package/.src/facade/sessionPatch.ts +32 -0
  35. package/.src/facade/trackerFacade.ts +98 -0
  36. package/.src/facade/userFacade.ts +26 -0
  37. package/.src/facade/userPatch.ts +32 -0
  38. package/.src/index.ts +4 -0
  39. package/.src/logging/consoleLogger.ts +37 -0
  40. package/.src/logging/index.ts +4 -0
  41. package/.src/logging/logger.ts +13 -0
  42. package/.src/logging/namespacedLogger.ts +32 -0
  43. package/.src/logging/nullLogger.ts +19 -0
  44. package/.src/namespacedStorage.ts +69 -0
  45. package/.src/patch.ts +64 -0
  46. package/.src/queue/capacityRestrictedQueue.ts +44 -0
  47. package/.src/queue/inMemoryQueue.ts +43 -0
  48. package/.src/queue/index.ts +5 -0
  49. package/.src/queue/monitoredQueue.ts +168 -0
  50. package/.src/queue/persistentQueue.ts +84 -0
  51. package/.src/queue/queue.ts +15 -0
  52. package/.src/retry/arbitraryPolicy.ts +21 -0
  53. package/.src/retry/backoffPolicy.ts +84 -0
  54. package/.src/retry/index.ts +5 -0
  55. package/.src/retry/maxAttemptsPolicy.ts +28 -0
  56. package/.src/retry/neverPolicy.ts +11 -0
  57. package/.src/retry/policy.ts +5 -0
  58. package/.src/schema/attributeSchema.ts +6 -0
  59. package/.src/schema/contentFetcherSchemas.ts +23 -0
  60. package/.src/schema/contentSchemas.ts +44 -0
  61. package/.src/schema/contextSchemas.ts +5 -0
  62. package/.src/schema/ecommerceSchemas.ts +179 -0
  63. package/.src/schema/evaluatorSchemas.ts +11 -0
  64. package/.src/schema/eventSchemas.ts +150 -0
  65. package/.src/schema/index.ts +11 -0
  66. package/.src/schema/loggerSchema.ts +12 -0
  67. package/.src/schema/operationSchemas.ts +102 -0
  68. package/.src/schema/sdkFacadeSchemas.ts +44 -0
  69. package/.src/schema/sdkSchemas.ts +49 -0
  70. package/.src/schema/tokenSchema.ts +42 -0
  71. package/.src/schema/userSchema.ts +184 -0
  72. package/.src/sdk.ts +174 -0
  73. package/.src/sdkEvents.ts +15 -0
  74. package/.src/sourceLocation.ts +85 -0
  75. package/.src/tab.ts +148 -0
  76. package/.src/token/cachedTokenStore.ts +34 -0
  77. package/.src/token/inMemoryTokenStore.ts +13 -0
  78. package/.src/token/index.ts +4 -0
  79. package/.src/token/replicatedTokenStore.ts +21 -0
  80. package/.src/token/token.ts +164 -0
  81. package/.src/tracker.ts +460 -0
  82. package/.src/trackingEvents.ts +456 -0
  83. package/.src/transformer.ts +7 -0
  84. package/.src/utilityTypes.ts +3 -0
  85. package/.src/uuid.ts +43 -0
  86. package/.src/validation/arrayType.ts +71 -0
  87. package/.src/validation/booleanType.ts +22 -0
  88. package/.src/validation/functionType.ts +22 -0
  89. package/.src/validation/index.ts +12 -0
  90. package/.src/validation/jsonType.ts +157 -0
  91. package/.src/validation/mixedSchema.ts +7 -0
  92. package/.src/validation/nullType.ts +22 -0
  93. package/.src/validation/numberType.ts +59 -0
  94. package/.src/validation/objectType.ts +138 -0
  95. package/.src/validation/schema.ts +21 -0
  96. package/.src/validation/stringType.ts +118 -0
  97. package/.src/validation/unionType.ts +53 -0
  98. package/.src/validation/violation.ts +23 -0
  99. package/activeRecord.js +33 -36
  100. package/base64Url.js +1 -0
  101. package/cache/cache.js +1 -0
  102. package/cache/fallbackCache.js +16 -32
  103. package/cache/inMemoryCache.js +10 -10
  104. package/cache/index.js +2 -1
  105. package/cache/localStorageCache.js +25 -25
  106. package/channel/beaconSocketChannel.d.ts +1 -1
  107. package/channel/beaconSocketChannel.js +50 -79
  108. package/channel/channel.d.ts +1 -1
  109. package/channel/channel.js +1 -0
  110. package/channel/encodedChannel.js +9 -10
  111. package/channel/guaranteedChannel.d.ts +4 -4
  112. package/channel/guaranteedChannel.js +42 -43
  113. package/channel/index.js +2 -1
  114. package/channel/queuedChannel.js +36 -64
  115. package/channel/retryChannel.d.ts +1 -1
  116. package/channel/retryChannel.js +45 -77
  117. package/channel/sandboxChannel.js +18 -18
  118. package/channel/socketChannel.d.ts +4 -4
  119. package/channel/socketChannel.js +78 -79
  120. package/cid/assigner.js +1 -0
  121. package/cid/cachedAssigner.js +16 -27
  122. package/cid/fixedAssigner.js +6 -6
  123. package/cid/index.js +2 -1
  124. package/cid/remoteAssigner.js +24 -36
  125. package/constants.d.ts +6 -5
  126. package/constants.js +7 -5
  127. package/container.d.ts +13 -6
  128. package/container.js +153 -168
  129. package/contentFetcher.d.ts +59 -0
  130. package/contentFetcher.js +130 -0
  131. package/context.d.ts +3 -3
  132. package/context.js +37 -38
  133. package/error.js +3 -2
  134. package/evaluator.d.ts +33 -24
  135. package/evaluator.js +127 -117
  136. package/eventManager.d.ts +1 -1
  137. package/eventManager.js +15 -15
  138. package/facade/contentFetcherFacade.d.ts +27 -0
  139. package/facade/contentFetcherFacade.js +41 -0
  140. package/facade/evaluatorFacade.d.ts +13 -3
  141. package/facade/evaluatorFacade.js +58 -72
  142. package/facade/index.js +1 -0
  143. package/facade/sdkFacade.d.ts +10 -3
  144. package/facade/sdkFacade.js +130 -141
  145. package/facade/sessionFacade.js +7 -7
  146. package/facade/sessionPatch.js +10 -13
  147. package/facade/trackerFacade.js +33 -38
  148. package/facade/userFacade.js +11 -11
  149. package/facade/userPatch.js +10 -13
  150. package/index.js +3 -2
  151. package/logging/consoleLogger.js +19 -35
  152. package/logging/index.js +2 -1
  153. package/logging/logger.js +1 -0
  154. package/logging/namespacedLogger.js +15 -15
  155. package/logging/nullLogger.js +11 -13
  156. package/namespacedStorage.js +31 -47
  157. package/package.json +13 -16
  158. package/patch.d.ts +1 -1
  159. package/patch.js +1 -0
  160. package/queue/capacityRestrictedQueue.js +18 -18
  161. package/queue/inMemoryQueue.js +23 -28
  162. package/queue/index.js +2 -1
  163. package/queue/monitoredQueue.d.ts +2 -2
  164. package/queue/monitoredQueue.js +40 -40
  165. package/queue/persistentQueue.js +34 -38
  166. package/queue/queue.js +1 -0
  167. package/retry/arbitraryPolicy.js +9 -10
  168. package/retry/backoffPolicy.d.ts +1 -1
  169. package/retry/backoffPolicy.js +12 -13
  170. package/retry/index.js +2 -1
  171. package/retry/maxAttemptsPolicy.js +8 -8
  172. package/retry/neverPolicy.js +7 -9
  173. package/retry/policy.js +1 -0
  174. package/schema/attributeSchema.js +2 -1
  175. package/schema/contentFetcherSchemas.d.ts +2 -0
  176. package/schema/contentFetcherSchemas.js +23 -0
  177. package/schema/contentSchemas.js +2 -1
  178. package/schema/contextSchemas.js +2 -1
  179. package/schema/ecommerceSchemas.js +2 -1
  180. package/schema/evaluatorSchemas.d.ts +2 -0
  181. package/schema/{evaluationSchemas.js → evaluatorSchemas.js} +4 -3
  182. package/schema/eventSchemas.js +6 -7
  183. package/schema/index.d.ts +2 -1
  184. package/schema/index.js +4 -2
  185. package/schema/loggerSchema.js +2 -1
  186. package/schema/operationSchemas.js +9 -8
  187. package/schema/sdkFacadeSchemas.js +10 -6
  188. package/schema/sdkSchemas.js +9 -5
  189. package/schema/tokenSchema.js +6 -4
  190. package/schema/userSchema.js +3 -2
  191. package/sdk.d.ts +9 -3
  192. package/sdk.js +82 -127
  193. package/sdkEvents.d.ts +3 -3
  194. package/sdkEvents.js +1 -0
  195. package/sourceLocation.d.ts +3 -3
  196. package/sourceLocation.js +14 -14
  197. package/tab.d.ts +5 -5
  198. package/tab.js +51 -80
  199. package/token/cachedTokenStore.js +10 -10
  200. package/token/inMemoryTokenStore.js +8 -8
  201. package/token/index.js +2 -1
  202. package/token/replicatedTokenStore.js +8 -8
  203. package/token/token.d.ts +9 -5
  204. package/token/token.js +64 -57
  205. package/tracker.d.ts +4 -4
  206. package/tracker.js +146 -122
  207. package/trackingEvents.d.ts +36 -36
  208. package/trackingEvents.js +13 -6
  209. package/transformer.js +2 -1
  210. package/utilityTypes.d.ts +2 -2
  211. package/utilityTypes.js +1 -0
  212. package/uuid.js +10 -7
  213. package/validation/arrayType.d.ts +2 -2
  214. package/validation/arrayType.js +30 -27
  215. package/validation/booleanType.js +12 -15
  216. package/validation/functionType.js +12 -15
  217. package/validation/index.js +2 -1
  218. package/validation/jsonType.d.ts +2 -2
  219. package/validation/jsonType.js +62 -80
  220. package/validation/mixedSchema.js +5 -7
  221. package/validation/nullType.js +12 -15
  222. package/validation/numberType.d.ts +1 -1
  223. package/validation/numberType.js +24 -22
  224. package/validation/objectType.d.ts +1 -1
  225. package/validation/objectType.js +62 -72
  226. package/validation/schema.js +7 -10
  227. package/validation/stringType.d.ts +1 -1
  228. package/validation/stringType.js +37 -47
  229. package/validation/unionType.js +28 -77
  230. package/validation/violation.js +2 -2
  231. package/schema/evaluationSchemas.d.ts +0 -2
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.loggerSchema = void 0;
4
- var validation_1 = require("../validation");
4
+ const validation_1 = require("../validation");
5
5
  exports.loggerSchema = new validation_1.ObjectType({
6
6
  required: ['debug', 'info', 'warn', 'error'],
7
7
  additionalProperties: true,
@@ -12,3 +12,4 @@ exports.loggerSchema = new validation_1.ObjectType({
12
12
  error: new validation_1.FunctionType(),
13
13
  },
14
14
  });
15
+ //# sourceMappingURL=loggerSchema.js.map
@@ -1,24 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.removeOperation = exports.unsetOperation = exports.clearOperation = exports.incrementOperation = exports.decrementOperation = exports.mergeOperation = exports.combineOperation = exports.setOperation = exports.addOperation = void 0;
4
- var validation_1 = require("../validation");
5
- var attributeSchema_1 = require("./attributeSchema");
6
- var pointer = new validation_1.StringType({
4
+ const validation_1 = require("../validation");
5
+ const attributeSchema_1 = require("./attributeSchema");
6
+ const pointer = new validation_1.StringType({
7
7
  format: 'pointer',
8
8
  });
9
- var simpleArray = new validation_1.JsonArrayType({
9
+ const simpleArray = new validation_1.JsonArrayType({
10
10
  items: new validation_1.JsonPrimitiveType(),
11
11
  });
12
- var simpleMap = new validation_1.JsonObjectType({
12
+ const simpleMap = new validation_1.JsonObjectType({
13
13
  properties: new validation_1.JsonPrimitiveType(),
14
14
  propertyNames: attributeSchema_1.attributeNameSchema,
15
15
  });
16
- var complexMap = new validation_1.JsonObjectType({
16
+ const complexMap = new validation_1.JsonObjectType({
17
17
  properties: new validation_1.UnionType(new validation_1.JsonPrimitiveType(), simpleArray, simpleMap),
18
18
  propertyNames: attributeSchema_1.attributeNameSchema,
19
19
  });
20
- var collectionValue = new validation_1.UnionType(simpleArray, complexMap);
21
- var mixedValue = new validation_1.UnionType(new validation_1.JsonPrimitiveType(), simpleArray, complexMap);
20
+ const collectionValue = new validation_1.UnionType(simpleArray, complexMap);
21
+ const mixedValue = new validation_1.UnionType(new validation_1.JsonPrimitiveType(), simpleArray, complexMap);
22
22
  exports.addOperation = new validation_1.ObjectType({
23
23
  required: ['path', 'value'],
24
24
  properties: {
@@ -80,3 +80,4 @@ exports.removeOperation = new validation_1.ObjectType({
80
80
  value: mixedValue,
81
81
  },
82
82
  });
83
+ //# sourceMappingURL=operationSchemas.js.map
@@ -1,17 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.sdkFacadeConfigurationSchema = void 0;
4
- var validation_1 = require("../validation");
5
- var contextSchemas_1 = require("./contextSchemas");
6
- var sdkSchemas_1 = require("./sdkSchemas");
7
- var loggerSchema_1 = require("./loggerSchema");
4
+ const validation_1 = require("../validation");
5
+ const contextSchemas_1 = require("./contextSchemas");
6
+ const sdkSchemas_1 = require("./sdkSchemas");
7
+ const loggerSchema_1 = require("./loggerSchema");
8
8
  exports.sdkFacadeConfigurationSchema = new validation_1.ObjectType({
9
9
  required: ['appId'],
10
10
  properties: {
11
11
  appId: new validation_1.StringType({
12
12
  format: 'uuid',
13
13
  }),
14
- cid: new validation_1.StringType({
14
+ clientId: new validation_1.StringType({
15
15
  pattern: /^[0-9a-f]{32}$/i,
16
16
  }),
17
17
  tokenScope: contextSchemas_1.tokenScopeSchema,
@@ -33,8 +33,12 @@ exports.sdkFacadeConfigurationSchema = new validation_1.ObjectType({
33
33
  evaluationEndpointUrl: new validation_1.StringType({
34
34
  format: 'url',
35
35
  }),
36
- bootstrapEndpointUrl: new validation_1.StringType({
36
+ contentEndpointUrl: new validation_1.StringType({
37
+ format: 'url',
38
+ }),
39
+ cidAssignerEndpointUrl: new validation_1.StringType({
37
40
  format: 'url',
38
41
  }),
39
42
  },
40
43
  });
44
+ //# sourceMappingURL=sdkFacadeSchemas.js.map
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.sdkConfigurationSchema = exports.eventMetadataSchema = void 0;
4
- var validation_1 = require("../validation");
5
- var contextSchemas_1 = require("./contextSchemas");
6
- var loggerSchema_1 = require("./loggerSchema");
4
+ const validation_1 = require("../validation");
5
+ const contextSchemas_1 = require("./contextSchemas");
6
+ const loggerSchema_1 = require("./loggerSchema");
7
7
  exports.eventMetadataSchema = new validation_1.ObjectType({
8
8
  maxProperties: 5,
9
9
  propertyNames: new validation_1.StringType({
@@ -21,7 +21,7 @@ exports.sdkConfigurationSchema = new validation_1.ObjectType({
21
21
  appId: new validation_1.StringType({
22
22
  format: 'uuid',
23
23
  }),
24
- cid: new validation_1.StringType({
24
+ clientId: new validation_1.StringType({
25
25
  pattern: /^[0-9a-f]{32}$/i,
26
26
  }),
27
27
  tokenScope: contextSchemas_1.tokenScopeSchema,
@@ -31,7 +31,10 @@ exports.sdkConfigurationSchema = new validation_1.ObjectType({
31
31
  evaluationEndpointUrl: new validation_1.StringType({
32
32
  format: 'url',
33
33
  }),
34
- bootstrapEndpointUrl: new validation_1.StringType({
34
+ contentEndpointUrl: new validation_1.StringType({
35
+ format: 'url',
36
+ }),
37
+ cidAssignerEndpointUrl: new validation_1.StringType({
35
38
  format: 'url',
36
39
  }),
37
40
  beaconQueueSize: new validation_1.NumberType({
@@ -45,3 +48,4 @@ exports.sdkConfigurationSchema = new validation_1.ObjectType({
45
48
  eventMetadata: exports.eventMetadataSchema,
46
49
  },
47
50
  });
51
+ //# sourceMappingURL=sdkSchemas.js.map
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.tokenSchema = void 0;
4
- var validation_1 = require("../validation");
4
+ const validation_1 = require("../validation");
5
5
  exports.tokenSchema = new validation_1.ObjectType({
6
- required: ['headers', 'claims'],
6
+ required: ['headers', 'payload'],
7
7
  properties: {
8
8
  headers: new validation_1.ObjectType({
9
- required: ['typ', 'alg', 'appId'],
9
+ required: ['typ', 'alg'],
10
10
  properties: {
11
11
  typ: new validation_1.StringType(),
12
12
  alg: new validation_1.StringType(),
@@ -16,7 +16,7 @@ exports.tokenSchema = new validation_1.ObjectType({
16
16
  }),
17
17
  },
18
18
  }),
19
- claims: new validation_1.ObjectType({
19
+ payload: new validation_1.ObjectType({
20
20
  required: ['iss', 'aud', 'iat'],
21
21
  properties: {
22
22
  iss: new validation_1.StringType(),
@@ -34,7 +34,9 @@ exports.tokenSchema = new validation_1.ObjectType({
34
34
  format: 'uuid',
35
35
  }),
36
36
  },
37
+ additionalProperties: true,
37
38
  }),
38
39
  signature: new validation_1.StringType(),
39
40
  },
40
41
  });
42
+ //# sourceMappingURL=tokenSchema.js.map
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.userProfileSchema = void 0;
4
- var validation_1 = require("../validation");
5
- var attributeSchema_1 = require("./attributeSchema");
4
+ const validation_1 = require("../validation");
5
+ const attributeSchema_1 = require("./attributeSchema");
6
6
  exports.userProfileSchema = new validation_1.ObjectType({
7
7
  properties: {
8
8
  firstName: new validation_1.StringType({
@@ -135,3 +135,4 @@ exports.userProfileSchema = new validation_1.ObjectType({
135
135
  }),
136
136
  },
137
137
  });
138
+ //# sourceMappingURL=userSchema.js.map
package/sdk.d.ts CHANGED
@@ -6,15 +6,18 @@ import { SdkEventMap } from './sdkEvents';
6
6
  import { EventManager } from './eventManager';
7
7
  import { CidAssigner } from './cid';
8
8
  import { UrlSanitizer } from './tab';
9
- export declare type Configuration = {
9
+ import { ContentFetcher } from './contentFetcher';
10
+ import { TokenStore } from './token';
11
+ export type Configuration = {
10
12
  appId: string;
11
13
  tokenScope: TokenScope;
12
14
  debug: boolean;
13
15
  test: boolean;
14
- cid?: string;
16
+ clientId?: string;
15
17
  trackerEndpointUrl?: string;
16
18
  evaluationEndpointUrl?: string;
17
- bootstrapEndpointUrl?: string;
19
+ contentEndpointUrl?: string;
20
+ cidAssignerEndpointUrl?: string;
18
21
  beaconQueueSize?: number;
19
22
  urlSanitizer?: UrlSanitizer;
20
23
  logger?: Logger;
@@ -29,9 +32,12 @@ export declare class Sdk {
29
32
  static init(configuration: Configuration): Sdk;
30
33
  get appId(): string;
31
34
  get cidAssigner(): CidAssigner;
35
+ get previewTokenStore(): TokenStore;
36
+ get userTokenStore(): TokenStore;
32
37
  get context(): Context;
33
38
  get tracker(): Tracker;
34
39
  get evaluator(): Evaluator;
40
+ get contentFetcher(): ContentFetcher;
35
41
  get eventManager(): EventManager<SdkEventMap>;
36
42
  getLogger(...namespace: string[]): Logger;
37
43
  getTabStorage(namespace: string, ...subnamespace: string[]): Storage;
package/sdk.js CHANGED
@@ -1,11 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Sdk = void 0;
4
- var tslib_1 = require("tslib");
5
- var container_1 = require("./container");
6
- var constants_1 = require("./constants");
7
- var schema_1 = require("./schema");
8
- var error_1 = require("./error");
4
+ const container_1 = require("./container");
5
+ const constants_1 = require("./constants");
6
+ const schema_1 = require("./schema");
7
+ const error_1 = require("./error");
9
8
  function validateConfiguration(configuration) {
10
9
  if (typeof configuration !== 'object' || configuration === null) {
11
10
  throw new Error('The configuration must be a key-value map.');
@@ -14,37 +13,34 @@ function validateConfiguration(configuration) {
14
13
  schema_1.sdkConfigurationSchema.validate(configuration);
15
14
  }
16
15
  catch (violation) {
17
- throw new Error("Invalid configuration: ".concat((0, error_1.formatCause)(violation)));
16
+ throw new Error(`Invalid configuration: ${(0, error_1.formatCause)(violation)}`);
18
17
  }
19
18
  }
20
- var Sdk = /** @class */ (function () {
21
- function Sdk(container) {
19
+ class Sdk {
20
+ constructor(container) {
22
21
  this.container = container;
23
22
  }
24
- Sdk.init = function (configuration) {
25
- var e_1, _a;
26
- var _b, _c, _d, _e;
23
+ static init(configuration) {
24
+ var _a, _b, _c, _d, _e;
27
25
  validateConfiguration(configuration);
28
- var _f = configuration.eventMetadata, customMetadata = _f === void 0 ? {} : _f, containerConfiguration = tslib_1.__rest(configuration, ["eventMetadata"]);
29
- var eventMetadata = {
26
+ const { eventMetadata: customMetadata = {}, ...containerConfiguration } = configuration;
27
+ const eventMetadata = {
30
28
  sdkVersion: constants_1.VERSION,
31
29
  };
32
- try {
33
- for (var _g = tslib_1.__values(Object.keys(customMetadata)), _h = _g.next(); !_h.done; _h = _g.next()) {
34
- var metadata = _h.value;
35
- eventMetadata["custom_".concat(metadata)] = customMetadata[metadata];
36
- }
30
+ for (const metadata of Object.keys(customMetadata)) {
31
+ eventMetadata[`custom_${metadata}`] = customMetadata[metadata];
37
32
  }
38
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
39
- finally {
40
- try {
41
- if (_h && !_h.done && (_a = _g.return)) _a.call(_g);
42
- }
43
- finally { if (e_1) throw e_1.error; }
44
- }
45
- var container = new container_1.Container(tslib_1.__assign(tslib_1.__assign({}, containerConfiguration), { evaluationEndpointUrl: (_b = containerConfiguration.evaluationEndpointUrl) !== null && _b !== void 0 ? _b : constants_1.EVALUATION_ENDPOINT_URL, trackerEndpointUrl: (_c = containerConfiguration.trackerEndpointUrl) !== null && _c !== void 0 ? _c : constants_1.TRACKER_ENDPOINT_URL, bootstrapEndpointUrl: (_d = containerConfiguration.bootstrapEndpointUrl) !== null && _d !== void 0 ? _d : constants_1.BOOTSTRAP_ENDPOINT_URL, beaconQueueSize: (_e = containerConfiguration.beaconQueueSize) !== null && _e !== void 0 ? _e : 100, eventMetadata: eventMetadata }));
46
- var logger = container.getLogger();
47
- var _j = container.getConfiguration(), appId = _j.appId, tokenScope = _j.tokenScope;
33
+ const container = new container_1.Container({
34
+ ...containerConfiguration,
35
+ evaluationEndpointUrl: (_a = containerConfiguration.evaluationEndpointUrl) !== null && _a !== void 0 ? _a : constants_1.EVALUATION_ENDPOINT_URL,
36
+ contentEndpointUrl: (_b = containerConfiguration.contentEndpointUrl) !== null && _b !== void 0 ? _b : constants_1.CONTENT_ENDPOINT_URL,
37
+ trackerEndpointUrl: (_c = containerConfiguration.trackerEndpointUrl) !== null && _c !== void 0 ? _c : constants_1.TRACKER_ENDPOINT_URL,
38
+ cidAssignerEndpointUrl: (_d = containerConfiguration.cidAssignerEndpointUrl) !== null && _d !== void 0 ? _d : constants_1.CID_ASSIGNER_ENDPOINT_URL,
39
+ beaconQueueSize: (_e = containerConfiguration.beaconQueueSize) !== null && _e !== void 0 ? _e : 100,
40
+ eventMetadata: eventMetadata,
41
+ });
42
+ const logger = container.getLogger();
43
+ const { appId, tokenScope } = container.getConfiguration();
48
44
  logger.debug('\n\n'
49
45
  + ' ██████ ██████  ██████  ██████ ████████ \n'
50
46
  + '██      ██   ██ ██    ██ ██         ██    \n'
@@ -52,106 +48,65 @@ var Sdk = /** @class */ (function () {
52
48
  + '██  ██   ██ ██  ██ ██  ██    \n'
53
49
  + ' ██████ ██  ██  ██████   ██████  ██    \n'
54
50
  + '\n');
55
- logger.info("Initializing SDK v".concat(constants_1.VERSION, "..."));
56
- logger.debug("App ID: ".concat(appId));
57
- var context = container.getContext();
58
- var tab = context.getTab();
59
- var user = context.getUser();
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));
51
+ logger.info(`Initializing SDK v${constants_1.VERSION}...`);
52
+ logger.debug(`App ID: ${appId}`);
53
+ const context = container.getContext();
54
+ const tab = context.getTab();
55
+ const user = context.getUser();
56
+ logger.debug(`${tab.isNew ? 'New' : 'Current'} tab: ${tab.id}`);
57
+ logger.debug(`Token scope: ${tokenScope}`);
58
+ logger.debug(`Current user: ${user !== null ? user : 'anonymous'}`);
59
+ logger.debug(`Test mode: ${containerConfiguration.test}`);
64
60
  logger.info('⚡ Croct SDK is ready!');
65
61
  return new Sdk(container);
66
- };
67
- Object.defineProperty(Sdk.prototype, "appId", {
68
- get: function () {
69
- var appId = this.container.getConfiguration().appId;
70
- return appId;
71
- },
72
- enumerable: false,
73
- configurable: true
74
- });
75
- Object.defineProperty(Sdk.prototype, "cidAssigner", {
76
- get: function () {
77
- return this.container.getCidAssigner();
78
- },
79
- enumerable: false,
80
- configurable: true
81
- });
82
- Object.defineProperty(Sdk.prototype, "context", {
83
- get: function () {
84
- return this.container.getContext();
85
- },
86
- enumerable: false,
87
- configurable: true
88
- });
89
- Object.defineProperty(Sdk.prototype, "tracker", {
90
- get: function () {
91
- return this.container.getTracker();
92
- },
93
- enumerable: false,
94
- configurable: true
95
- });
96
- Object.defineProperty(Sdk.prototype, "evaluator", {
97
- get: function () {
98
- return this.container.getEvaluator();
99
- },
100
- enumerable: false,
101
- configurable: true
102
- });
103
- Object.defineProperty(Sdk.prototype, "eventManager", {
104
- get: function () {
105
- return this.container.getEventManager();
106
- },
107
- enumerable: false,
108
- configurable: true
109
- });
110
- Sdk.prototype.getLogger = function () {
111
- var _a;
112
- var namespace = [];
113
- for (var _i = 0; _i < arguments.length; _i++) {
114
- namespace[_i] = arguments[_i];
115
- }
116
- return (_a = this.container).getLogger.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(namespace), false));
117
- };
118
- Sdk.prototype.getTabStorage = function (namespace) {
119
- var _a;
120
- var subnamespace = [];
121
- for (var _i = 1; _i < arguments.length; _i++) {
122
- subnamespace[_i - 1] = arguments[_i];
123
- }
124
- return (_a = this.container).getTabStorage.apply(_a, tslib_1.__spreadArray([namespace], tslib_1.__read(subnamespace), false));
125
- };
126
- Sdk.prototype.getBrowserStorage = function (namespace) {
127
- var _a;
128
- var subnamespace = [];
129
- for (var _i = 1; _i < arguments.length; _i++) {
130
- subnamespace[_i - 1] = arguments[_i];
62
+ }
63
+ get appId() {
64
+ const { appId } = this.container.getConfiguration();
65
+ return appId;
66
+ }
67
+ get cidAssigner() {
68
+ return this.container.getCidAssigner();
69
+ }
70
+ get previewTokenStore() {
71
+ return this.container.getPreviewTokenStore();
72
+ }
73
+ get userTokenStore() {
74
+ return this.container.getUserTokenStore();
75
+ }
76
+ get context() {
77
+ return this.container.getContext();
78
+ }
79
+ get tracker() {
80
+ return this.container.getTracker();
81
+ }
82
+ get evaluator() {
83
+ return this.container.getEvaluator();
84
+ }
85
+ get contentFetcher() {
86
+ return this.container.getContentFetcher();
87
+ }
88
+ get eventManager() {
89
+ return this.container.getEventManager();
90
+ }
91
+ getLogger(...namespace) {
92
+ return this.container.getLogger(...namespace);
93
+ }
94
+ getTabStorage(namespace, ...subnamespace) {
95
+ return this.container.getTabStorage(namespace, ...subnamespace);
96
+ }
97
+ getBrowserStorage(namespace, ...subnamespace) {
98
+ return this.container.getBrowserStorage(namespace, ...subnamespace);
99
+ }
100
+ async close() {
101
+ if (this.closed) {
102
+ return;
131
103
  }
132
- return (_a = this.container).getBrowserStorage.apply(_a, tslib_1.__spreadArray([namespace], tslib_1.__read(subnamespace), false));
133
- };
134
- Sdk.prototype.close = function () {
135
- return tslib_1.__awaiter(this, void 0, void 0, function () {
136
- var logger;
137
- return tslib_1.__generator(this, function (_a) {
138
- switch (_a.label) {
139
- case 0:
140
- if (this.closed) {
141
- return [2 /*return*/];
142
- }
143
- logger = this.getLogger();
144
- logger.debug('Closing SDK...');
145
- this.closed = true;
146
- return [4 /*yield*/, this.container.dispose()];
147
- case 1:
148
- _a.sent();
149
- logger.info('SDK closed.');
150
- return [2 /*return*/];
151
- }
152
- });
153
- });
154
- };
155
- return Sdk;
156
- }());
104
+ const logger = this.getLogger();
105
+ logger.debug('Closing SDK...');
106
+ this.closed = true;
107
+ await this.container.dispose();
108
+ logger.info('SDK closed.');
109
+ }
110
+ }
157
111
  exports.Sdk = Sdk;
112
+ //# sourceMappingURL=sdk.js.map
package/sdkEvents.d.ts CHANGED
@@ -3,8 +3,8 @@ export interface TokenChanged {
3
3
  oldToken: Token | null;
4
4
  newToken: Token | null;
5
5
  }
6
- export declare type SdkEventMap = Record<string, Record<string, unknown>> & {
6
+ export type SdkEventMap = Record<string, Record<string, unknown>> & {
7
7
  tokenChanged: TokenChanged;
8
8
  };
9
- export declare type SdkEventType = keyof SdkEventMap;
10
- export declare type SdkEvent<T extends SdkEventType = SdkEventType> = T extends SdkEventType ? SdkEventMap[T] : SdkEventMap[SdkEventType];
9
+ export type SdkEventType = keyof SdkEventMap;
10
+ export type SdkEvent<T extends SdkEventType = SdkEventType> = T extends SdkEventType ? SdkEventMap[T] : SdkEventMap[SdkEventType];
package/sdkEvents.js CHANGED
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=sdkEvents.js.map
@@ -1,12 +1,12 @@
1
- export declare type Position = {
1
+ export type Position = {
2
2
  line: number;
3
3
  column: number;
4
4
  index: number;
5
5
  };
6
- export declare type Location = {
6
+ export type Location = {
7
7
  start: Position;
8
8
  end: Position;
9
9
  };
10
10
  export declare function getLength(input: string): number;
11
- export declare function getPosition(input: string, index: number): Position;
12
11
  export declare function getLocation(input: string, startIndex: number, endIndex: number): Location;
12
+ export declare function getPosition(input: string, index: number): Position;
package/sourceLocation.js CHANGED
@@ -1,15 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getLocation = exports.getPosition = exports.getLength = void 0;
4
- var tslib_1 = require("tslib");
3
+ exports.getPosition = exports.getLocation = exports.getLength = void 0;
5
4
  function getLength(input) {
6
- return tslib_1.__spreadArray([], tslib_1.__read(input), false).length;
5
+ return [...input].length;
7
6
  }
8
7
  exports.getLength = getLength;
9
- function getPosition(input, index) {
10
- return getLocation(input, index, index).start;
11
- }
12
- exports.getPosition = getPosition;
13
8
  function getLocation(input, startIndex, endIndex) {
14
9
  if (startIndex < 0) {
15
10
  throw Error('The start index cannot be negative.');
@@ -17,13 +12,13 @@ function getLocation(input, startIndex, endIndex) {
17
12
  if (endIndex < startIndex) {
18
13
  throw new Error('The end index must greater than or equal to the start index.');
19
14
  }
20
- var start;
21
- var end;
22
- var chars = tslib_1.__spreadArray([], tslib_1.__read(input), false);
23
- var line = 1;
24
- var column = 0;
25
- for (var offset = 0; offset < chars.length; offset++) {
26
- var char = chars[offset];
15
+ let start;
16
+ let end;
17
+ const chars = [...input];
18
+ let line = 1;
19
+ let column = 0;
20
+ for (let offset = 0; offset < chars.length; offset++) {
21
+ const char = chars[offset];
27
22
  if (offset === startIndex) {
28
23
  start = {
29
24
  index: offset,
@@ -67,3 +62,8 @@ function getLocation(input, startIndex, endIndex) {
67
62
  };
68
63
  }
69
64
  exports.getLocation = getLocation;
65
+ function getPosition(input, index) {
66
+ return getLocation(input, index, index).start;
67
+ }
68
+ exports.getPosition = getPosition;
69
+ //# sourceMappingURL=sourceLocation.js.map
package/tab.d.ts CHANGED
@@ -1,15 +1,15 @@
1
1
  import { EventListener } from './eventManager';
2
- export declare type TabEvent<T = Record<string, unknown>> = CustomEvent<{
2
+ export type TabEvent<T = Record<string, unknown>> = CustomEvent<{
3
3
  tab: Tab;
4
4
  } & T>;
5
- export declare type TabVisibilityChangeEvent = TabEvent<{
5
+ export type TabVisibilityChangeEvent = TabEvent<{
6
6
  visible: boolean;
7
7
  }>;
8
- export declare type TabUrlChangeEvent = TabEvent<{
8
+ export type TabUrlChangeEvent = TabEvent<{
9
9
  url: string;
10
10
  }>;
11
- export declare type UrlSanitizer = (url: string) => URL;
12
- declare type TabEventMap = {
11
+ export type UrlSanitizer = (url: string) => URL;
12
+ type TabEventMap = {
13
13
  focus: TabEvent;
14
14
  blur: TabEvent;
15
15
  load: TabEvent;