@croct/sdk 0.17.12 → 0.18.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 (227) hide show
  1. package/README.md +13 -15
  2. package/activeRecord.cjs +1 -1
  3. package/activeRecord.d.cts +26 -0
  4. package/activeRecord.js +1 -1
  5. package/apiKey.d.cts +48 -0
  6. package/base64Url.d.cts +4 -0
  7. package/cache/cache.d.cts +17 -0
  8. package/cache/cookieCache.d.cts +22 -0
  9. package/cache/fallbackCache.d.cts +11 -0
  10. package/cache/inMemoryCache.d.cts +11 -0
  11. package/cache/index.cjs +5 -5
  12. package/cache/index.d.cts +4 -0
  13. package/cache/index.js +4 -4
  14. package/cache/localStorageCache.d.cts +19 -0
  15. package/channel/channel.cjs +1 -1
  16. package/channel/channel.d.cts +24 -0
  17. package/channel/channel.js +1 -1
  18. package/channel/encodedChannel.d.cts +12 -0
  19. package/channel/guaranteedChannel.cjs +2 -2
  20. package/channel/guaranteedChannel.d.cts +33 -0
  21. package/channel/guaranteedChannel.js +2 -2
  22. package/channel/httpBeaconChannel.cjs +5 -5
  23. package/channel/httpBeaconChannel.d.cts +26 -0
  24. package/channel/httpBeaconChannel.js +5 -5
  25. package/channel/index.cjs +8 -8
  26. package/channel/index.d.cts +12 -0
  27. package/channel/index.js +7 -7
  28. package/channel/queuedChannel.cjs +7 -3
  29. package/channel/queuedChannel.d.cts +21 -0
  30. package/channel/queuedChannel.js +7 -3
  31. package/channel/retryChannel.cjs +2 -2
  32. package/channel/retryChannel.d.cts +21 -0
  33. package/channel/retryChannel.js +2 -2
  34. package/channel/sandboxChannel.cjs +1 -1
  35. package/channel/sandboxChannel.d.cts +15 -0
  36. package/channel/sandboxChannel.js +1 -1
  37. package/cid/assigner.d.cts +5 -0
  38. package/cid/cachedAssigner.cjs +1 -1
  39. package/cid/cachedAssigner.d.cts +17 -0
  40. package/cid/cachedAssigner.js +1 -1
  41. package/cid/fixedAssigner.d.cts +9 -0
  42. package/cid/index.cjs +5 -5
  43. package/cid/index.d.cts +6 -0
  44. package/cid/index.js +4 -4
  45. package/cid/remoteAssigner.cjs +3 -3
  46. package/cid/remoteAssigner.d.cts +13 -0
  47. package/cid/remoteAssigner.js +3 -3
  48. package/constants.cjs +1 -1
  49. package/constants.d.cts +6 -0
  50. package/constants.d.ts +2 -2
  51. package/constants.js +1 -1
  52. package/container.cjs +18 -18
  53. package/container.d.cts +95 -0
  54. package/container.js +18 -18
  55. package/contentFetcher.cjs +4 -4
  56. package/contentFetcher.d.cts +69 -0
  57. package/contentFetcher.js +4 -4
  58. package/context.cjs +4 -4
  59. package/context.d.cts +36 -0
  60. package/context.js +4 -4
  61. package/error.d.cts +4 -0
  62. package/evaluator.cjs +5 -5
  63. package/evaluator.d.cts +86 -0
  64. package/evaluator.js +5 -5
  65. package/eventManager.d.cts +21 -0
  66. package/eventSubjectProcessor.d.cts +22 -0
  67. package/facade/contentFetcherFacade.cjs +2 -2
  68. package/facade/contentFetcherFacade.d.cts +36 -0
  69. package/facade/contentFetcherFacade.js +2 -2
  70. package/facade/evaluatorFacade.cjs +2 -2
  71. package/facade/evaluatorFacade.d.cts +41 -0
  72. package/facade/evaluatorFacade.js +2 -2
  73. package/facade/index.cjs +7 -9
  74. package/facade/index.d.cts +29 -0
  75. package/facade/index.js +7 -8
  76. package/facade/sdkFacade.cjs +10 -10
  77. package/facade/sdkFacade.d.cts +86 -0
  78. package/facade/sdkFacade.js +10 -10
  79. package/facade/sessionFacade.cjs +1 -1
  80. package/facade/sessionFacade.d.cts +22 -0
  81. package/facade/sessionFacade.js +1 -1
  82. package/facade/sessionPatch.cjs +1 -1
  83. package/facade/sessionPatch.d.cts +21 -0
  84. package/facade/sessionPatch.js +1 -1
  85. package/facade/trackerFacade.cjs +2 -2
  86. package/facade/trackerFacade.d.cts +25 -0
  87. package/facade/trackerFacade.js +2 -2
  88. package/facade/userFacade.cjs +1 -1
  89. package/facade/userFacade.d.cts +28 -0
  90. package/facade/userFacade.js +1 -1
  91. package/facade/userPatch.cjs +1 -1
  92. package/facade/userPatch.d.cts +21 -0
  93. package/facade/userPatch.js +1 -1
  94. package/help.d.cts +5 -0
  95. package/index.cjs +2 -4
  96. package/index.d.cts +25 -0
  97. package/index.js +2 -3
  98. package/logging/consoleLogger.d.cts +13 -0
  99. package/logging/filteredLogger.d.cts +22 -0
  100. package/logging/index.cjs +6 -6
  101. package/logging/index.d.cts +5 -0
  102. package/logging/index.js +5 -5
  103. package/logging/logger.d.cts +11 -0
  104. package/logging/namespacedLogger.d.cts +14 -0
  105. package/logging/nullLogger.d.cts +10 -0
  106. package/namespacedStorage.d.cts +16 -0
  107. package/package.json +4 -1
  108. package/patch.d.cts +46 -0
  109. package/queue/capacityRestrictedQueue.d.cts +16 -0
  110. package/queue/inMemoryQueue.d.cts +15 -0
  111. package/queue/index.cjs +6 -6
  112. package/queue/index.d.cts +6 -0
  113. package/queue/index.js +5 -5
  114. package/queue/monitoredQueue.cjs +1 -1
  115. package/queue/monitoredQueue.d.cts +28 -0
  116. package/queue/monitoredQueue.js +1 -1
  117. package/queue/persistentQueue.d.cts +18 -0
  118. package/queue/queue.d.cts +11 -0
  119. package/retry/arbitraryPolicy.d.cts +10 -0
  120. package/retry/backoffPolicy.d.cts +26 -0
  121. package/retry/index.cjs +6 -6
  122. package/retry/index.d.cts +5 -0
  123. package/retry/index.js +5 -5
  124. package/retry/maxAttemptsPolicy.d.cts +11 -0
  125. package/retry/neverPolicy.d.cts +8 -0
  126. package/retry/policy.d.cts +6 -0
  127. package/schema/attributeSchema.cjs +1 -1
  128. package/schema/attributeSchema.d.cts +6 -0
  129. package/schema/attributeSchema.js +1 -1
  130. package/schema/contentFetcherSchemas.cjs +1 -1
  131. package/schema/contentFetcherSchemas.d.cts +6 -0
  132. package/schema/contentFetcherSchemas.js +1 -1
  133. package/schema/contentSchemas.cjs +1 -1
  134. package/schema/contentSchemas.d.cts +6 -0
  135. package/schema/contentSchemas.js +1 -1
  136. package/schema/contextSchemas.cjs +1 -1
  137. package/schema/contextSchemas.d.cts +6 -0
  138. package/schema/contextSchemas.js +1 -1
  139. package/schema/ecommerceSchemas.cjs +1 -1
  140. package/schema/ecommerceSchemas.d.cts +10 -0
  141. package/schema/ecommerceSchemas.js +1 -1
  142. package/schema/evaluatorSchemas.cjs +1 -1
  143. package/schema/evaluatorSchemas.d.cts +6 -0
  144. package/schema/evaluatorSchemas.js +1 -1
  145. package/schema/eventSchemas.cjs +4 -4
  146. package/schema/eventSchemas.d.cts +16 -0
  147. package/schema/eventSchemas.js +4 -4
  148. package/schema/index.cjs +22 -22
  149. package/schema/index.d.cts +14 -0
  150. package/schema/index.js +11 -11
  151. package/schema/loggerSchema.cjs +1 -1
  152. package/schema/loggerSchema.d.cts +6 -0
  153. package/schema/loggerSchema.js +1 -1
  154. package/schema/operationSchemas.cjs +2 -2
  155. package/schema/operationSchemas.d.cts +14 -0
  156. package/schema/operationSchemas.js +2 -2
  157. package/schema/sdkFacadeSchemas.cjs +4 -4
  158. package/schema/sdkFacadeSchemas.d.cts +6 -0
  159. package/schema/sdkFacadeSchemas.js +4 -4
  160. package/schema/sdkSchemas.cjs +3 -3
  161. package/schema/sdkSchemas.d.cts +8 -0
  162. package/schema/sdkSchemas.js +3 -3
  163. package/schema/tokenSchema.cjs +1 -1
  164. package/schema/tokenSchema.d.cts +6 -0
  165. package/schema/tokenSchema.js +1 -1
  166. package/schema/userSchema.cjs +2 -2
  167. package/schema/userSchema.d.cts +6 -0
  168. package/schema/userSchema.js +2 -2
  169. package/sdk.cjs +4 -4
  170. package/sdk.d.cts +69 -0
  171. package/sdk.js +4 -4
  172. package/sdkEvents.d.cts +15 -0
  173. package/sourceLocation.d.cts +14 -0
  174. package/tab.cjs +1 -1
  175. package/tab.d.cts +40 -0
  176. package/tab.js +1 -1
  177. package/token/cachedTokenStore.cjs +1 -1
  178. package/token/cachedTokenStore.d.cts +13 -0
  179. package/token/cachedTokenStore.js +1 -1
  180. package/token/inMemoryTokenStore.d.cts +11 -0
  181. package/token/index.cjs +5 -5
  182. package/token/index.d.cts +7 -0
  183. package/token/index.js +4 -4
  184. package/token/replicatedTokenStore.d.cts +13 -0
  185. package/token/token.cjs +3 -3
  186. package/token/token.d.cts +70 -0
  187. package/token/token.js +3 -3
  188. package/tracker.cjs +3 -3
  189. package/tracker.d.cts +82 -0
  190. package/tracker.js +3 -3
  191. package/trackingEvents.d.cts +309 -0
  192. package/transformer.d.cts +6 -0
  193. package/utilityTypes.d.cts +4 -0
  194. package/uuid.d.cts +3 -0
  195. package/validation/arrayType.cjs +2 -2
  196. package/validation/arrayType.d.cts +16 -0
  197. package/validation/arrayType.js +2 -2
  198. package/validation/booleanType.cjs +2 -2
  199. package/validation/booleanType.d.cts +9 -0
  200. package/validation/booleanType.js +2 -2
  201. package/validation/functionType.cjs +2 -2
  202. package/validation/functionType.d.cts +9 -0
  203. package/validation/functionType.js +2 -2
  204. package/validation/index.cjs +14 -14
  205. package/validation/index.d.cts +12 -0
  206. package/validation/index.js +12 -12
  207. package/validation/jsonType.cjs +2 -2
  208. package/validation/jsonType.d.cts +35 -0
  209. package/validation/jsonType.js +2 -2
  210. package/validation/mixedSchema.d.cts +7 -0
  211. package/validation/nullType.cjs +2 -2
  212. package/validation/nullType.d.cts +9 -0
  213. package/validation/nullType.js +2 -2
  214. package/validation/numberType.cjs +2 -2
  215. package/validation/numberType.d.cts +16 -0
  216. package/validation/numberType.js +2 -2
  217. package/validation/objectType.cjs +3 -3
  218. package/validation/objectType.d.cts +30 -0
  219. package/validation/objectType.js +3 -3
  220. package/validation/schema.d.cts +18 -0
  221. package/validation/stringType.cjs +2 -2
  222. package/validation/stringType.d.cts +24 -0
  223. package/validation/stringType.js +2 -2
  224. package/validation/unionType.cjs +2 -2
  225. package/validation/unionType.d.cts +11 -0
  226. package/validation/unionType.js +2 -2
  227. package/validation/violation.d.cts +4 -0
package/README.md CHANGED
@@ -1,24 +1,22 @@
1
1
  <p align="center">
2
- <a href="https://croct.com">
3
- <img src="https://cdn.croct.io/brand/logo/repo-icon-green.svg" alt="Croct" height="80" />
4
- </a>
5
- <br />
6
- <strong>SDK JS</strong>
7
- <br />
8
- The official Croct SDK for JavaScript.
2
+ <a href="https://croct.com" target="_blank">
3
+ <picture>
4
+ <source media="(min-width: 769px) and (prefers-color-scheme: light)" srcset="https://github.com/croct-tech/plug-js/blob/master/.github/assets/header-light.svg">
5
+ <source media="(min-width: 769px) and (prefers-color-scheme: dark)" srcset="https://github.com/croct-tech/plug-js/blob/master/.github/assets/header-dark.svg">
6
+ <source media="(max-width: 768px) and (prefers-color-scheme: dark)" srcset="https://github.com/croct-tech/plug-js/blob/master/.github/assets/header-dark-mobile.svg">
7
+ <source media="(max-width: 768px) and (prefers-color-scheme: light)" srcset="https://github.com/croct-tech/plug-js/blob/master/.github/assets/header-light-mobile.svg">
8
+ <img src="https://github.com/croct-tech/plug-js/blob/master/.github/assets/header-light-mobile.svg" alt="Croct JavaScript SDK" title="Croct JavaScript SDK" width="100%">
9
+ </picture>
10
+ </a>
11
+ <br/>
12
+ <strong>SDK JS</strong><br/>
13
+ The official Croct SDK for JavaScript.
9
14
  </p>
15
+
10
16
  <p align="center">
11
17
  <a href="https://www.npmjs.com/package/@croct/sdk"><img alt="Version" src="https://img.shields.io/npm/v/@croct/sdk"/></a>
12
18
  <a href="https://github.com/croct-tech/sdk-js/actions?query=workflow%3AValidations"><img alt="Build" src="https://github.com/croct-tech/sdk-js/workflows/Validations/badge.svg"/></a>
13
- <a href="https://codeclimate.com/repos/5e7251b3172af05fe9000e27/maintainability"><img alt="Maintainability" src="https://api.codeclimate.com/v1/badges/c44df78a3ed891af11bb/maintainability"/></a>
14
19
  <a href="https://codeclimate.com/repos/5e7251b3172af05fe9000e27/test_coverage"><img alt="Coverage" src="https://api.codeclimate.com/v1/badges/c44df78a3ed891af11bb/test_coverage"/></a>
15
- <br />
16
- <br />
17
- <a href="https://github.com/croct-tech/sdk-js/releases">📦Releases</a>
18
- ·
19
- <a href="https://github.com/croct-tech/sdk-js/issues/new?labels=bug&template=bug-report.md">🐞Report Bug</a>
20
- ·
21
- <a href="https://github.com/croct-tech/sdk-js/issues/new?labels=enhancement&template=feature-request.md">✨Request Feature</a>
22
20
  </p>
23
21
 
24
22
  ## Installation
package/activeRecord.cjs CHANGED
@@ -20,7 +20,7 @@ __export(activeRecord_exports, {
20
20
  ActiveRecord: () => ActiveRecord
21
21
  });
22
22
  module.exports = __toCommonJS(activeRecord_exports);
23
- var import_schema = require("./schema");
23
+ var import_schema = require('./schema/index.cjs');
24
24
  const operationSchema = {
25
25
  add: import_schema.addOperation,
26
26
  set: import_schema.setOperation,
@@ -0,0 +1,26 @@
1
+ import { JsonValue, JsonStructure } from '@croct/json';
2
+ import { Patch } from './patch.cjs';
3
+ import { TrackingEvent } from './trackingEvents.cjs';
4
+ import './utilityTypes.cjs';
5
+
6
+ declare abstract class ActiveRecord<T extends TrackingEvent> {
7
+ private readonly operations;
8
+ set(value: JsonValue): this;
9
+ set(property: string, value: JsonValue): this;
10
+ add(property: string, value: JsonValue): this;
11
+ combine(property: string, value: JsonValue): this;
12
+ merge(value: JsonStructure): this;
13
+ merge(property: string, value: JsonStructure): this;
14
+ increment(property: string, amount?: number): this;
15
+ decrement(property: string, amount?: number): this;
16
+ clear(property: string): this;
17
+ unset(property: string): this;
18
+ remove(property: string, value: JsonValue): this;
19
+ private pushOperation;
20
+ protected reset(): this;
21
+ abstract save(): Promise<T>;
22
+ protected isDirty(): boolean;
23
+ protected buildPatch(): Patch;
24
+ }
25
+
26
+ export { ActiveRecord };
package/activeRecord.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  setOperation,
9
9
  unsetOperation,
10
10
  removeOperation
11
- } from "./schema";
11
+ } from "./schema/index.js";
12
12
  const operationSchema = {
13
13
  add: addOperation,
14
14
  set: setOperation,
package/apiKey.d.cts ADDED
@@ -0,0 +1,48 @@
1
+ type ParsedPrivateKey = {
2
+ algorithm: string;
3
+ encodedKey: string;
4
+ };
5
+ declare class ApiKey {
6
+ private static readonly IDENTIFIER_PATTERN;
7
+ private static readonly PRIVATE_KEY_PATTERN;
8
+ private static readonly ALGORITHMS;
9
+ private readonly identifier;
10
+ private readonly privateKey?;
11
+ private importedKey;
12
+ private constructor();
13
+ static from(apiKey: string | ApiKey): ApiKey;
14
+ static parse(apiKey: string): ApiKey;
15
+ static of(identifier: string, privateKey?: string): ApiKey;
16
+ getIdentifier(): string;
17
+ getIdentifierHash(): Promise<string>;
18
+ hasPrivateKey(): boolean;
19
+ getPrivateKey(): string;
20
+ sign(data: string): Promise<string>;
21
+ getSigningAlgorithm(): string;
22
+ private importKey;
23
+ private getParsedPrivateKey;
24
+ export(): string;
25
+ toString(): string;
26
+ /**
27
+ * Create an array buffer from a string.
28
+ *
29
+ * @see https://developers.google.com/web/updates/2012/06/How-to-convert-ArrayBuffer-to-and-from-String
30
+ *
31
+ * @param data The string to convert.
32
+ * @returns The array buffer.
33
+ */
34
+ private static createByteArrayFromString;
35
+ private static createByteArrayFromHexString;
36
+ /**
37
+ * Convert an array buffer to a string.
38
+ *
39
+ * @see https://developers.google.com/web/updates/2012/06/How-to-convert-ArrayBuffer-to-and-from-String
40
+ *
41
+ * @param buffer The buffer to convert.
42
+ * @returns The string.
43
+ */
44
+ private static convertBufferToString;
45
+ private static convertBufferToHexString;
46
+ }
47
+
48
+ export { ApiKey, type ParsedPrivateKey };
@@ -0,0 +1,4 @@
1
+ declare function base64UrlEncode(value: string, utf8?: boolean): string;
2
+ declare function base64UrlDecode(value: string, utf8?: boolean): string;
3
+
4
+ export { base64UrlDecode, base64UrlEncode };
@@ -0,0 +1,17 @@
1
+ interface Cache {
2
+ get(): string | null;
3
+ put(value: string): void;
4
+ clear(): void;
5
+ }
6
+ interface CacheListener {
7
+ (value: string | null): void;
8
+ }
9
+ interface ObservableCache extends Cache {
10
+ addListener(listener: CacheListener): void;
11
+ removeListener(listener: CacheListener): void;
12
+ }
13
+ declare namespace ObservableCache {
14
+ function isObservable(cache: Cache): cache is ObservableCache;
15
+ }
16
+
17
+ export { type Cache, type CacheListener, ObservableCache };
@@ -0,0 +1,22 @@
1
+ import { Cache } from './cache.cjs';
2
+
3
+ type CookieCacheConfiguration = {
4
+ name: string;
5
+ secure?: boolean;
6
+ maxAge?: number;
7
+ domain?: string;
8
+ path?: string;
9
+ sameSite?: 'strict' | 'lax' | 'none';
10
+ };
11
+ declare class CookieCache implements Cache {
12
+ private readonly config;
13
+ constructor(config: CookieCacheConfiguration, defaultSecure?: boolean);
14
+ get(): string | null;
15
+ put(value: string): void;
16
+ clear(): void;
17
+ private static serializeCookie;
18
+ private static encode;
19
+ private static decode;
20
+ }
21
+
22
+ export { CookieCache, type CookieCacheConfiguration };
@@ -0,0 +1,11 @@
1
+ import { Cache } from './cache.cjs';
2
+
3
+ declare class FallbackCache implements Cache {
4
+ private readonly caches;
5
+ constructor(...caches: Cache[]);
6
+ get(): string | null;
7
+ put(value: string): void;
8
+ clear(): void;
9
+ }
10
+
11
+ export { FallbackCache };
@@ -0,0 +1,11 @@
1
+ import { Cache } from './cache.cjs';
2
+
3
+ declare class InMemoryCache implements Cache {
4
+ private cache?;
5
+ constructor(cache?: string);
6
+ get(): string | null;
7
+ put(value: string): void;
8
+ clear(): void;
9
+ }
10
+
11
+ export { InMemoryCache };
package/cache/index.cjs CHANGED
@@ -23,14 +23,14 @@ __export(cache_exports, {
23
23
  LocalStorageCache: () => import_localStorageCache.LocalStorageCache
24
24
  });
25
25
  module.exports = __toCommonJS(cache_exports);
26
- __reExport(cache_exports, require("./cache"), module.exports);
27
- var import_fallbackCache = require("./fallbackCache");
28
- var import_inMemoryCache = require("./inMemoryCache");
29
- var import_localStorageCache = require("./localStorageCache");
26
+ __reExport(cache_exports, require('./cache.cjs'), module.exports);
27
+ var import_fallbackCache = require('./fallbackCache.cjs');
28
+ var import_inMemoryCache = require('./inMemoryCache.cjs');
29
+ var import_localStorageCache = require('./localStorageCache.cjs');
30
30
  // Annotate the CommonJS export names for ESM import in node:
31
31
  0 && (module.exports = {
32
32
  FallbackCache,
33
33
  InMemoryCache,
34
34
  LocalStorageCache,
35
- ...require("./cache")
35
+ ...require('./cache.cjs')
36
36
  });
@@ -0,0 +1,4 @@
1
+ export { Cache, CacheListener, ObservableCache } from './cache.cjs';
2
+ export { FallbackCache } from './fallbackCache.cjs';
3
+ export { InMemoryCache } from './inMemoryCache.cjs';
4
+ export { LocalStorageCache } from './localStorageCache.cjs';
package/cache/index.js CHANGED
@@ -1,7 +1,7 @@
1
- export * from "./cache";
2
- import { FallbackCache } from "./fallbackCache";
3
- import { InMemoryCache } from "./inMemoryCache";
4
- import { LocalStorageCache } from "./localStorageCache";
1
+ export * from "./cache.js";
2
+ import { FallbackCache } from "./fallbackCache.js";
3
+ import { InMemoryCache } from "./inMemoryCache.js";
4
+ import { LocalStorageCache } from "./localStorageCache.js";
5
5
  export {
6
6
  FallbackCache,
7
7
  InMemoryCache,
@@ -0,0 +1,19 @@
1
+ import { ObservableCache, CacheListener } from './cache.cjs';
2
+
3
+ declare class LocalStorageCache implements ObservableCache {
4
+ private readonly storage;
5
+ private readonly key;
6
+ private value;
7
+ private readonly listeners;
8
+ constructor(storage: Storage, key: string);
9
+ static autoSync(cache: LocalStorageCache): (() => void);
10
+ get(): string | null;
11
+ put(value: string): void;
12
+ clear(): void;
13
+ addListener(listener: CacheListener): void;
14
+ removeListener(listener: CacheListener): void;
15
+ private notifyChange;
16
+ private sync;
17
+ }
18
+
19
+ export { LocalStorageCache };
@@ -20,7 +20,7 @@ __export(channel_exports, {
20
20
  MessageDeliveryError: () => MessageDeliveryError
21
21
  });
22
22
  module.exports = __toCommonJS(channel_exports);
23
- var import_error = require("../error");
23
+ var import_error = require('../error.cjs');
24
24
  class MessageDeliveryError extends Error {
25
25
  constructor(message, retryable) {
26
26
  super(message);
@@ -0,0 +1,24 @@
1
+ declare class MessageDeliveryError extends Error {
2
+ readonly retryable: boolean;
3
+ constructor(message: string, retryable: boolean);
4
+ static retryable(cause: unknown): MessageDeliveryError;
5
+ static nonRetryable(cause: unknown): MessageDeliveryError;
6
+ private static fromCause;
7
+ }
8
+ interface Closeable {
9
+ close(): Promise<void>;
10
+ }
11
+ interface OutputChannel<O> extends Closeable {
12
+ publish(message: O): Promise<void>;
13
+ }
14
+ type ChannelListener<T> = {
15
+ (message: T): void;
16
+ };
17
+ interface InputChannel<I> extends Closeable {
18
+ subscribe(listener: ChannelListener<I>): void;
19
+ unsubscribe(listener: ChannelListener<I>): void;
20
+ }
21
+ interface DuplexChannel<I, O> extends InputChannel<I>, OutputChannel<O> {
22
+ }
23
+
24
+ export { type ChannelListener, type Closeable, type DuplexChannel, type InputChannel, MessageDeliveryError, type OutputChannel };
@@ -1,4 +1,4 @@
1
- import { formatMessage } from "../error";
1
+ import { formatMessage } from "../error.js";
2
2
  class MessageDeliveryError extends Error {
3
3
  constructor(message, retryable) {
4
4
  super(message);
@@ -0,0 +1,12 @@
1
+ import { OutputChannel } from './channel.cjs';
2
+ import { Transformer } from '../transformer.cjs';
3
+
4
+ declare class EncodedChannel<D, E> implements OutputChannel<D> {
5
+ private readonly encode;
6
+ private readonly channel;
7
+ constructor(channel: OutputChannel<E>, encoder: Transformer<D, E>);
8
+ publish(message: D): Promise<void>;
9
+ close(): Promise<void>;
10
+ }
11
+
12
+ export { EncodedChannel };
@@ -21,8 +21,8 @@ __export(guaranteedChannel_exports, {
21
21
  TimeStamper: () => TimeStamper
22
22
  });
23
23
  module.exports = __toCommonJS(guaranteedChannel_exports);
24
- var import_logging = require("../logging");
25
- var import_channel = require("./channel");
24
+ var import_logging = require('../logging/index.cjs');
25
+ var import_channel = require('./channel.cjs');
26
26
  class TimeStamper {
27
27
  generate() {
28
28
  return String(Date.now());
@@ -0,0 +1,33 @@
1
+ import { Logger } from '../logging/logger.cjs';
2
+ import { OutputChannel, DuplexChannel } from './channel.cjs';
3
+
4
+ type MessageStamper<M, S> = {
5
+ generate(message: M): S;
6
+ };
7
+ declare class TimeStamper implements MessageStamper<any, string> {
8
+ generate(): string;
9
+ }
10
+ type Envelope<M, S> = {
11
+ id: S;
12
+ message: M;
13
+ };
14
+ type Options = {
15
+ ackTimeout: number;
16
+ };
17
+ type Configuration<M, S> = Partial<Options> & {
18
+ channel: DuplexChannel<S, Envelope<M, S>>;
19
+ stamper: MessageStamper<M, S>;
20
+ logger?: Logger;
21
+ };
22
+ declare class GuaranteedChannel<M, S> implements OutputChannel<M> {
23
+ private readonly channel;
24
+ private readonly stamper;
25
+ private readonly logger;
26
+ private readonly options;
27
+ private closed;
28
+ constructor({ channel, logger, stamper, ...options }: Configuration<M, S>);
29
+ publish(message: M): Promise<void>;
30
+ close(): Promise<void>;
31
+ }
32
+
33
+ export { type Envelope, GuaranteedChannel, type MessageStamper, TimeStamper };
@@ -1,5 +1,5 @@
1
- import { NullLogger } from "../logging";
2
- import { MessageDeliveryError } from "./channel";
1
+ import { NullLogger } from "../logging/index.js";
2
+ import { MessageDeliveryError } from "./channel.js";
3
3
  class TimeStamper {
4
4
  generate() {
5
5
  return String(Date.now());
@@ -20,11 +20,11 @@ __export(httpBeaconChannel_exports, {
20
20
  HttpBeaconChannel: () => HttpBeaconChannel
21
21
  });
22
22
  module.exports = __toCommonJS(httpBeaconChannel_exports);
23
- var import_channel = require("./channel");
24
- var import_logging = require("../logging");
25
- var import_error = require("../error");
26
- var import_constants = require("../constants");
27
- var import_help = require("../help");
23
+ var import_channel = require('./channel.cjs');
24
+ var import_logging = require('../logging/index.cjs');
25
+ var import_error = require('../error.cjs');
26
+ var import_constants = require('../constants.cjs');
27
+ var import_help = require('../help.cjs');
28
28
  class HttpBeaconChannel {
29
29
  constructor({ logger = new import_logging.NullLogger(), ...configuration }) {
30
30
  this.listeners = [];
@@ -0,0 +1,26 @@
1
+ import { DuplexChannel, ChannelListener } from './channel.cjs';
2
+ import { Envelope } from './guaranteedChannel.cjs';
3
+ import { Logger } from '../logging/logger.cjs';
4
+ import { CidAssigner } from '../cid/assigner.cjs';
5
+
6
+ type Configuration = {
7
+ appId: string;
8
+ endpointUrl: string;
9
+ cidAssigner: CidAssigner;
10
+ logger?: Logger;
11
+ };
12
+ declare class HttpBeaconChannel implements DuplexChannel<string, Envelope<string, string>> {
13
+ private readonly configuration;
14
+ private readonly logger;
15
+ private readonly listeners;
16
+ private closed;
17
+ constructor({ logger, ...configuration }: Configuration);
18
+ publish({ id: receiptId, message }: Envelope<string, string>): Promise<void>;
19
+ subscribe(listener: ChannelListener<string>): void;
20
+ unsubscribe(listener: ChannelListener<string>): void;
21
+ private notify;
22
+ close(): Promise<void>;
23
+ private static isRetryable;
24
+ }
25
+
26
+ export { type Configuration, HttpBeaconChannel };
@@ -1,8 +1,8 @@
1
- import { MessageDeliveryError } from "./channel";
2
- import { NullLogger } from "../logging";
3
- import { formatMessage } from "../error";
4
- import { CLIENT_LIBRARY } from "../constants";
5
- import { Help } from "../help";
1
+ import { MessageDeliveryError } from "./channel.js";
2
+ import { NullLogger } from "../logging/index.js";
3
+ import { formatMessage } from "../error.js";
4
+ import { CLIENT_LIBRARY } from "../constants.js";
5
+ import { Help } from "../help.js";
6
6
  class HttpBeaconChannel {
7
7
  constructor({ logger = new NullLogger(), ...configuration }) {
8
8
  this.listeners = [];
package/channel/index.cjs CHANGED
@@ -26,13 +26,13 @@ __export(channel_exports, {
26
26
  SandboxChannel: () => import_sandboxChannel.SandboxChannel
27
27
  });
28
28
  module.exports = __toCommonJS(channel_exports);
29
- __reExport(channel_exports, require("./channel"), module.exports);
30
- var import_encodedChannel = require("./encodedChannel");
31
- var import_guaranteedChannel = require("./guaranteedChannel");
32
- var import_queuedChannel = require("./queuedChannel");
33
- var import_retryChannel = require("./retryChannel");
34
- var import_sandboxChannel = require("./sandboxChannel");
35
- var import_httpBeaconChannel = require("./httpBeaconChannel");
29
+ __reExport(channel_exports, require('./channel.cjs'), module.exports);
30
+ var import_encodedChannel = require('./encodedChannel.cjs');
31
+ var import_guaranteedChannel = require('./guaranteedChannel.cjs');
32
+ var import_queuedChannel = require('./queuedChannel.cjs');
33
+ var import_retryChannel = require('./retryChannel.cjs');
34
+ var import_sandboxChannel = require('./sandboxChannel.cjs');
35
+ var import_httpBeaconChannel = require('./httpBeaconChannel.cjs');
36
36
  // Annotate the CommonJS export names for ESM import in node:
37
37
  0 && (module.exports = {
38
38
  EncodedChannel,
@@ -41,5 +41,5 @@ var import_httpBeaconChannel = require("./httpBeaconChannel");
41
41
  QueuedChannel,
42
42
  RetryChannel,
43
43
  SandboxChannel,
44
- ...require("./channel")
44
+ ...require('./channel.cjs')
45
45
  });
@@ -0,0 +1,12 @@
1
+ export { ChannelListener, Closeable, DuplexChannel, InputChannel, MessageDeliveryError, OutputChannel } from './channel.cjs';
2
+ export { EncodedChannel } from './encodedChannel.cjs';
3
+ export { GuaranteedChannel } from './guaranteedChannel.cjs';
4
+ export { QueuedChannel } from './queuedChannel.cjs';
5
+ export { RetryChannel } from './retryChannel.cjs';
6
+ export { SandboxChannel } from './sandboxChannel.cjs';
7
+ export { HttpBeaconChannel } from './httpBeaconChannel.cjs';
8
+ import '../transformer.cjs';
9
+ import '../logging/logger.cjs';
10
+ import '../queue/queue.cjs';
11
+ import '../retry/policy.cjs';
12
+ import '../cid/assigner.cjs';
package/channel/index.js CHANGED
@@ -1,10 +1,10 @@
1
- export * from "./channel";
2
- import { EncodedChannel } from "./encodedChannel";
3
- import { GuaranteedChannel } from "./guaranteedChannel";
4
- import { QueuedChannel } from "./queuedChannel";
5
- import { RetryChannel } from "./retryChannel";
6
- import { SandboxChannel } from "./sandboxChannel";
7
- import { HttpBeaconChannel } from "./httpBeaconChannel";
1
+ export * from "./channel.js";
2
+ import { EncodedChannel } from "./encodedChannel.js";
3
+ import { GuaranteedChannel } from "./guaranteedChannel.js";
4
+ import { QueuedChannel } from "./queuedChannel.js";
5
+ import { RetryChannel } from "./retryChannel.js";
6
+ import { SandboxChannel } from "./sandboxChannel.js";
7
+ import { HttpBeaconChannel } from "./httpBeaconChannel.js";
8
8
  export {
9
9
  EncodedChannel,
10
10
  GuaranteedChannel,
@@ -20,8 +20,8 @@ __export(queuedChannel_exports, {
20
20
  QueuedChannel: () => QueuedChannel
21
21
  });
22
22
  module.exports = __toCommonJS(queuedChannel_exports);
23
- var import_channel = require("./channel");
24
- var import_logging = require("../logging");
23
+ var import_channel = require('./channel.cjs');
24
+ var import_logging = require('../logging/index.cjs');
25
25
  class QueuedChannel {
26
26
  constructor(channel, queue, logger) {
27
27
  this.closed = false;
@@ -57,7 +57,11 @@ class QueuedChannel {
57
57
  dequeue() {
58
58
  this.logger.debug("Dequeuing message...");
59
59
  this.logger.debug(`Queue length: ${Math.max(0, this.queue.length() - 1)}`);
60
- this.queue.shift();
60
+ if (this.queue.length() === 0) {
61
+ this.logger.debug("Queue unexpectedly empty, possibly due to concurrent modification.");
62
+ } else {
63
+ this.queue.shift();
64
+ }
61
65
  }
62
66
  requeue() {
63
67
  if (this.closed) {
@@ -0,0 +1,21 @@
1
+ import { OutputChannel } from './channel.cjs';
2
+ import { Queue } from '../queue/queue.cjs';
3
+ import { Logger } from '../logging/logger.cjs';
4
+
5
+ declare class QueuedChannel<T> implements OutputChannel<T> {
6
+ private readonly channel;
7
+ private readonly queue;
8
+ private readonly logger;
9
+ private pending?;
10
+ private closed;
11
+ constructor(channel: OutputChannel<T>, queue: Queue<T>, logger?: Logger);
12
+ flush(): Promise<void>;
13
+ publish(message: T): Promise<void>;
14
+ private enqueue;
15
+ private dequeue;
16
+ private requeue;
17
+ private chainNext;
18
+ close(): Promise<void>;
19
+ }
20
+
21
+ export { QueuedChannel };
@@ -1,5 +1,5 @@
1
- import { MessageDeliveryError } from "./channel";
2
- import { NullLogger } from "../logging";
1
+ import { MessageDeliveryError } from "./channel.js";
2
+ import { NullLogger } from "../logging/index.js";
3
3
  class QueuedChannel {
4
4
  constructor(channel, queue, logger) {
5
5
  this.closed = false;
@@ -35,7 +35,11 @@ class QueuedChannel {
35
35
  dequeue() {
36
36
  this.logger.debug("Dequeuing message...");
37
37
  this.logger.debug(`Queue length: ${Math.max(0, this.queue.length() - 1)}`);
38
- this.queue.shift();
38
+ if (this.queue.length() === 0) {
39
+ this.logger.debug("Queue unexpectedly empty, possibly due to concurrent modification.");
40
+ } else {
41
+ this.queue.shift();
42
+ }
39
43
  }
40
44
  requeue() {
41
45
  if (this.closed) {
@@ -20,8 +20,8 @@ __export(retryChannel_exports, {
20
20
  RetryChannel: () => RetryChannel
21
21
  });
22
22
  module.exports = __toCommonJS(retryChannel_exports);
23
- var import_channel = require("./channel");
24
- var import_logging = require("../logging");
23
+ var import_channel = require('./channel.cjs');
24
+ var import_logging = require('../logging/index.cjs');
25
25
  class RetryChannel {
26
26
  constructor({ channel, retryPolicy, logger }) {
27
27
  this.closed = false;
@@ -0,0 +1,21 @@
1
+ import { OutputChannel } from './channel.cjs';
2
+ import { Logger } from '../logging/logger.cjs';
3
+ import { RetryPolicy } from '../retry/policy.cjs';
4
+
5
+ type Configuration<T> = {
6
+ channel: OutputChannel<T>;
7
+ retryPolicy: RetryPolicy<T>;
8
+ logger?: Logger;
9
+ };
10
+ declare class RetryChannel<T> implements OutputChannel<T> {
11
+ private readonly channel;
12
+ private readonly retryPolicy;
13
+ private readonly logger;
14
+ private closed;
15
+ constructor({ channel, retryPolicy, logger }: Configuration<T>);
16
+ publish(message: T): Promise<void>;
17
+ retry(message: T, error: unknown): Promise<void>;
18
+ close(): Promise<void>;
19
+ }
20
+
21
+ export { RetryChannel };
@@ -1,5 +1,5 @@
1
- import { MessageDeliveryError } from "./channel";
2
- import { NullLogger } from "../logging";
1
+ import { MessageDeliveryError } from "./channel.js";
2
+ import { NullLogger } from "../logging/index.js";
3
3
  class RetryChannel {
4
4
  constructor({ channel, retryPolicy, logger }) {
5
5
  this.closed = false;
@@ -20,7 +20,7 @@ __export(sandboxChannel_exports, {
20
20
  SandboxChannel: () => SandboxChannel
21
21
  });
22
22
  module.exports = __toCommonJS(sandboxChannel_exports);
23
- var import_channel = require("./channel");
23
+ var import_channel = require('./channel.cjs');
24
24
  class SandboxChannel {
25
25
  constructor() {
26
26
  this.listeners = [];
@@ -0,0 +1,15 @@
1
+ import { DuplexChannel, ChannelListener } from './channel.cjs';
2
+
3
+ declare class SandboxChannel<I, O> implements DuplexChannel<I, O> {
4
+ private readonly listeners;
5
+ readonly messages: O[];
6
+ private closed;
7
+ publish(message: O): Promise<void>;
8
+ notify(message: I): void;
9
+ subscribe(listener: ChannelListener<I>): void;
10
+ unsubscribe(listener: ChannelListener<I>): void;
11
+ close(): Promise<void>;
12
+ isClosed(): boolean;
13
+ }
14
+
15
+ export { SandboxChannel };