@croct/sdk 0.10.0 → 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 +5 -7
  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 -72
  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
package/token/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ReplicatedTokenStore = exports.InMemoryTokenStore = exports.CachedTokenStore = void 0;
4
- var tslib_1 = require("tslib");
4
+ const tslib_1 = require("tslib");
5
5
  tslib_1.__exportStar(require("./token"), exports);
6
6
  var cachedTokenStore_1 = require("./cachedTokenStore");
7
7
  Object.defineProperty(exports, "CachedTokenStore", { enumerable: true, get: function () { return cachedTokenStore_1.CachedTokenStore; } });
@@ -1,18 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ReplicatedTokenStore = void 0;
4
- var ReplicatedTokenStore = /** @class */ (function () {
5
- function ReplicatedTokenStore(primary, secondary) {
4
+ class ReplicatedTokenStore {
5
+ constructor(primary, secondary) {
6
6
  this.primary = primary;
7
7
  this.secondary = secondary;
8
8
  }
9
- ReplicatedTokenStore.prototype.getToken = function () {
9
+ getToken() {
10
10
  return this.primary.getToken();
11
- };
12
- ReplicatedTokenStore.prototype.setToken = function (token) {
11
+ }
12
+ setToken(token) {
13
13
  this.primary.setToken(token);
14
14
  this.secondary.setToken(token);
15
- };
16
- return ReplicatedTokenStore;
17
- }());
15
+ }
16
+ }
18
17
  exports.ReplicatedTokenStore = ReplicatedTokenStore;
package/token/token.d.ts CHANGED
@@ -1,10 +1,11 @@
1
- export declare type Headers = {
1
+ import { JsonObject } from '@croct/json';
2
+ export type Headers = {
2
3
  typ: string;
3
4
  alg: string;
4
5
  kid?: string;
5
- appId: string;
6
+ appId?: string;
6
7
  };
7
- export declare type Claims = {
8
+ type Claims = {
8
9
  iss: string;
9
10
  aud: string | string[];
10
11
  iat: number;
@@ -12,15 +13,17 @@ export declare type Claims = {
12
13
  sub?: string;
13
14
  jid?: string;
14
15
  };
16
+ export type TokenPayload = JsonObject & Claims;
15
17
  export declare class Token {
16
18
  private readonly headers;
17
- private readonly claims;
19
+ private readonly payload;
18
20
  private readonly signature;
19
21
  private constructor();
20
22
  static issue(appId: string, subject?: string | null, timestamp?: number): Token;
21
23
  static parse(token: string): Token;
24
+ static of(headers: Headers, payload: TokenPayload, signature?: string): Token;
22
25
  getHeaders(): Headers;
23
- getClaims(): Claims;
26
+ getPayload(): TokenPayload;
24
27
  getSignature(): string;
25
28
  isAnonymous(): boolean;
26
29
  getSubject(): string | null;
@@ -39,3 +42,4 @@ export declare class FixedTokenProvider implements TokenProvider {
39
42
  constructor(token: Token | null);
40
43
  getToken(): Token | null;
41
44
  }
45
+ export {};
package/token/token.js CHANGED
@@ -1,20 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FixedTokenProvider = exports.Token = void 0;
4
- var tslib_1 = require("tslib");
5
- var base64Url_1 = require("../base64Url");
6
- var schema_1 = require("../schema");
7
- var error_1 = require("../error");
8
- var Token = /** @class */ (function () {
9
- function Token(headers, claims, signature) {
10
- if (signature === void 0) { signature = ''; }
4
+ const base64Url_1 = require("../base64Url");
5
+ const schema_1 = require("../schema");
6
+ const error_1 = require("../error");
7
+ class Token {
8
+ constructor(headers, payload, signature = '') {
11
9
  this.headers = headers;
12
- this.claims = claims;
10
+ this.payload = payload;
13
11
  this.signature = signature;
14
12
  }
15
- Token.issue = function (appId, subject, timestamp) {
16
- if (subject === void 0) { subject = null; }
17
- if (timestamp === void 0) { timestamp = Math.floor(Date.now() / 1000); }
13
+ static issue(appId, subject = null, timestamp = Math.floor(Date.now() / 1000)) {
18
14
  if (timestamp < 0) {
19
15
  throw new Error('The timestamp must be non-negative.');
20
16
  }
@@ -25,75 +21,85 @@ var Token = /** @class */ (function () {
25
21
  typ: 'JWT',
26
22
  alg: 'none',
27
23
  appId: appId,
28
- }, tslib_1.__assign({ iss: 'croct.io', aud: 'croct.io', iat: timestamp }, (subject !== null ? { sub: subject } : null)));
29
- };
30
- Token.parse = function (token) {
24
+ }, {
25
+ iss: 'croct.io',
26
+ aud: 'croct.io',
27
+ iat: timestamp,
28
+ ...(subject !== null ? { sub: subject } : null),
29
+ });
30
+ }
31
+ static parse(token) {
31
32
  if (token === '') {
32
33
  throw new Error('The token cannot be empty.');
33
34
  }
34
- var parts = token.split('.', 3);
35
+ const parts = token.split('.', 3);
35
36
  // This token is invalid
36
37
  if (parts.length < 2) {
37
38
  throw new Error('The token is malformed.');
38
39
  }
39
- var headers;
40
- var claims;
41
- var signature;
40
+ let headers;
41
+ let payload;
42
+ let signature;
42
43
  try {
43
44
  headers = JSON.parse((0, base64Url_1.base64UrlDecode)(parts[0]));
44
- claims = JSON.parse((0, base64Url_1.base64UrlDecode)(parts[1]));
45
+ payload = JSON.parse((0, base64Url_1.base64UrlDecode)(parts[1]));
45
46
  if (parts.length === 3) {
46
47
  signature = (0, base64Url_1.base64UrlDecode)(parts[2]);
47
48
  }
48
49
  }
49
- catch (_a) {
50
+ catch {
50
51
  throw new Error('The token is corrupted.');
51
52
  }
53
+ return Token.of(headers, payload, signature);
54
+ }
55
+ static of(headers, payload, signature = '') {
52
56
  try {
53
- schema_1.tokenSchema.validate({ headers: headers, claims: claims, signature: signature });
57
+ schema_1.tokenSchema.validate({
58
+ headers: headers,
59
+ payload: payload,
60
+ signature: signature,
61
+ });
54
62
  }
55
63
  catch (violation) {
56
- throw new Error("The token is invalid: ".concat((0, error_1.formatCause)(violation)));
64
+ throw new Error(`The token is invalid: ${(0, error_1.formatCause)(violation)}`);
57
65
  }
58
- return new Token(headers, claims, signature);
59
- };
60
- Token.prototype.getHeaders = function () {
61
- return tslib_1.__assign({}, this.headers);
62
- };
63
- Token.prototype.getClaims = function () {
64
- return tslib_1.__assign({}, this.claims);
65
- };
66
- Token.prototype.getSignature = function () {
66
+ return new Token(headers, payload, signature);
67
+ }
68
+ getHeaders() {
69
+ return { ...this.headers };
70
+ }
71
+ getPayload() {
72
+ return { ...this.payload };
73
+ }
74
+ getSignature() {
67
75
  return this.signature;
68
- };
69
- Token.prototype.isAnonymous = function () {
70
- return this.claims.sub === undefined;
71
- };
72
- Token.prototype.getSubject = function () {
73
- return this.claims.sub !== undefined ? this.claims.sub : null;
74
- };
75
- Token.prototype.getIssueTime = function () {
76
- return this.claims.iat;
77
- };
78
- Token.prototype.toJSON = function () {
76
+ }
77
+ isAnonymous() {
78
+ return this.payload.sub === undefined;
79
+ }
80
+ getSubject() {
81
+ return this.payload.sub !== undefined ? this.payload.sub : null;
82
+ }
83
+ getIssueTime() {
84
+ return this.payload.iat;
85
+ }
86
+ toJSON() {
79
87
  return this.toString();
80
- };
81
- Token.prototype.toString = function () {
82
- var headers = (0, base64Url_1.base64UrlEncode)(JSON.stringify(this.headers));
83
- var claims = (0, base64Url_1.base64UrlEncode)(JSON.stringify(this.claims));
84
- var signature = (0, base64Url_1.base64UrlEncode)(this.signature);
85
- return "".concat(headers, ".").concat(claims, ".").concat(signature);
86
- };
87
- return Token;
88
- }());
88
+ }
89
+ toString() {
90
+ const headers = (0, base64Url_1.base64UrlEncode)(JSON.stringify(this.headers));
91
+ const payload = (0, base64Url_1.base64UrlEncode)(JSON.stringify(this.payload));
92
+ const signature = (0, base64Url_1.base64UrlEncode)(this.signature);
93
+ return `${headers}.${payload}.${signature}`;
94
+ }
95
+ }
89
96
  exports.Token = Token;
90
- var FixedTokenProvider = /** @class */ (function () {
91
- function FixedTokenProvider(token) {
97
+ class FixedTokenProvider {
98
+ constructor(token) {
92
99
  this.token = token;
93
100
  }
94
- FixedTokenProvider.prototype.getToken = function () {
101
+ getToken() {
95
102
  return this.token;
96
- };
97
- return FixedTokenProvider;
98
- }());
103
+ }
104
+ }
99
105
  exports.FixedTokenProvider = FixedTokenProvider;
package/tracker.d.ts CHANGED
@@ -4,19 +4,19 @@ import { OutputChannel } from './channel';
4
4
  import { TokenProvider } from './token';
5
5
  import { RetryPolicy } from './retry';
6
6
  import { Beacon, TrackingEvent, TrackingEventContext, PartialTrackingEvent } from './trackingEvents';
7
- declare type Options = {
7
+ type Options = {
8
8
  eventMetadata?: {
9
9
  [key: string]: string;
10
10
  };
11
11
  };
12
- export declare type Configuration = Options & {
12
+ export type Configuration = Options & {
13
13
  channel: OutputChannel<Beacon>;
14
14
  logger?: Logger;
15
15
  tab: Tab;
16
16
  tokenProvider: TokenProvider;
17
17
  inactivityRetryPolicy: RetryPolicy<number>;
18
18
  };
19
- export declare type EventInfo<T extends TrackingEvent = TrackingEvent> = {
19
+ export type EventInfo<T extends TrackingEvent = TrackingEvent> = {
20
20
  context: TrackingEventContext;
21
21
  event: T;
22
22
  timestamp: number;
@@ -36,7 +36,7 @@ export declare class Tracker {
36
36
  private readonly pending;
37
37
  private readonly state;
38
38
  private readonly inactivityTimer;
39
- constructor({ tab, tokenProvider, channel, logger, inactivityRetryPolicy, ...options }: Configuration);
39
+ constructor(config: Configuration);
40
40
  addListener(listener: EventListener): void;
41
41
  removeListener(listener: EventListener): void;
42
42
  get flushed(): Promise<void>;