@croct/sdk 0.17.10 → 0.17.12
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.
- package/activeRecord.cjs +0 -1
- package/activeRecord.js +0 -1
- package/apiKey.cjs +0 -1
- package/apiKey.js +0 -1
- package/base64Url.cjs +0 -1
- package/base64Url.js +0 -1
- package/cache/cache.cjs +0 -1
- package/cache/cache.js +0 -1
- package/cache/cookieCache.cjs +0 -1
- package/cache/cookieCache.js +0 -1
- package/cache/fallbackCache.cjs +0 -1
- package/cache/fallbackCache.js +0 -1
- package/cache/inMemoryCache.cjs +0 -1
- package/cache/inMemoryCache.js +0 -1
- package/cache/index.cjs +0 -1
- package/cache/index.js +0 -1
- package/cache/localStorageCache.cjs +0 -1
- package/cache/localStorageCache.js +0 -1
- package/channel/channel.cjs +0 -1
- package/channel/channel.js +0 -1
- package/channel/encodedChannel.cjs +0 -1
- package/channel/encodedChannel.js +0 -1
- package/channel/guaranteedChannel.cjs +0 -1
- package/channel/guaranteedChannel.js +0 -1
- package/channel/httpBeaconChannel.cjs +0 -1
- package/channel/httpBeaconChannel.js +0 -1
- package/channel/index.cjs +0 -1
- package/channel/index.js +0 -1
- package/channel/queuedChannel.cjs +0 -1
- package/channel/queuedChannel.js +0 -1
- package/channel/retryChannel.cjs +0 -1
- package/channel/retryChannel.js +0 -1
- package/channel/sandboxChannel.cjs +0 -1
- package/channel/sandboxChannel.js +0 -1
- package/cid/assigner.cjs +0 -1
- package/cid/assigner.js +0 -1
- package/cid/cachedAssigner.cjs +0 -1
- package/cid/cachedAssigner.js +0 -1
- package/cid/fixedAssigner.cjs +0 -1
- package/cid/fixedAssigner.js +0 -1
- package/cid/index.cjs +0 -1
- package/cid/index.js +0 -1
- package/cid/remoteAssigner.cjs +0 -1
- package/cid/remoteAssigner.js +0 -1
- package/constants.cjs +1 -2
- package/constants.d.ts +2 -2
- package/constants.js +1 -2
- package/container.cjs +0 -1
- package/container.js +0 -1
- package/contentFetcher.cjs +0 -1
- package/contentFetcher.js +0 -1
- package/context.cjs +0 -1
- package/context.js +0 -1
- package/error.cjs +0 -1
- package/error.js +0 -1
- package/evaluator.cjs +0 -1
- package/evaluator.js +0 -1
- package/eventManager.cjs +0 -1
- package/eventManager.js +0 -1
- package/eventSubjectProcessor.cjs +0 -1
- package/eventSubjectProcessor.js +0 -1
- package/facade/contentFetcherFacade.cjs +0 -1
- package/facade/contentFetcherFacade.js +0 -1
- package/facade/evaluatorFacade.cjs +0 -1
- package/facade/evaluatorFacade.js +0 -1
- package/facade/index.cjs +0 -1
- package/facade/index.js +0 -1
- package/facade/sdkFacade.cjs +0 -1
- package/facade/sdkFacade.js +0 -1
- package/facade/sessionFacade.cjs +0 -1
- package/facade/sessionFacade.js +0 -1
- package/facade/sessionPatch.cjs +0 -1
- package/facade/sessionPatch.js +0 -1
- package/facade/trackerFacade.cjs +0 -1
- package/facade/trackerFacade.js +0 -1
- package/facade/userFacade.cjs +0 -1
- package/facade/userFacade.js +0 -1
- package/facade/userPatch.cjs +0 -1
- package/facade/userPatch.js +0 -1
- package/help.cjs +0 -1
- package/help.js +0 -1
- package/index.cjs +0 -1
- package/index.js +0 -1
- package/logging/consoleLogger.cjs +0 -1
- package/logging/consoleLogger.js +0 -1
- package/logging/filteredLogger.cjs +0 -1
- package/logging/filteredLogger.js +0 -1
- package/logging/index.cjs +0 -1
- package/logging/index.js +0 -1
- package/logging/logger.cjs +0 -1
- package/logging/logger.js +0 -1
- package/logging/namespacedLogger.cjs +0 -1
- package/logging/namespacedLogger.js +0 -1
- package/logging/nullLogger.cjs +0 -1
- package/logging/nullLogger.js +0 -1
- package/namespacedStorage.cjs +0 -1
- package/namespacedStorage.js +0 -1
- package/package.json +1 -1
- package/patch.cjs +0 -1
- package/patch.js +0 -1
- package/queue/capacityRestrictedQueue.cjs +0 -1
- package/queue/capacityRestrictedQueue.js +0 -1
- package/queue/inMemoryQueue.cjs +0 -1
- package/queue/inMemoryQueue.js +0 -1
- package/queue/index.cjs +0 -1
- package/queue/index.js +0 -1
- package/queue/monitoredQueue.cjs +0 -1
- package/queue/monitoredQueue.js +0 -1
- package/queue/persistentQueue.cjs +0 -1
- package/queue/persistentQueue.js +0 -1
- package/queue/queue.cjs +0 -1
- package/queue/queue.js +0 -1
- package/retry/arbitraryPolicy.cjs +0 -1
- package/retry/arbitraryPolicy.js +0 -1
- package/retry/backoffPolicy.cjs +0 -1
- package/retry/backoffPolicy.js +0 -1
- package/retry/index.cjs +0 -1
- package/retry/index.js +0 -1
- package/retry/maxAttemptsPolicy.cjs +0 -1
- package/retry/maxAttemptsPolicy.js +0 -1
- package/retry/neverPolicy.cjs +0 -1
- package/retry/neverPolicy.js +0 -1
- package/retry/policy.cjs +0 -1
- package/retry/policy.js +0 -1
- package/schema/attributeSchema.cjs +0 -1
- package/schema/attributeSchema.js +0 -1
- package/schema/contentFetcherSchemas.cjs +0 -1
- package/schema/contentFetcherSchemas.js +0 -1
- package/schema/contentSchemas.cjs +0 -1
- package/schema/contentSchemas.js +0 -1
- package/schema/contextSchemas.cjs +0 -1
- package/schema/contextSchemas.js +0 -1
- package/schema/ecommerceSchemas.cjs +0 -1
- package/schema/ecommerceSchemas.js +0 -1
- package/schema/evaluatorSchemas.cjs +0 -1
- package/schema/evaluatorSchemas.js +0 -1
- package/schema/eventSchemas.cjs +0 -1
- package/schema/eventSchemas.js +0 -1
- package/schema/index.cjs +0 -1
- package/schema/index.js +0 -1
- package/schema/loggerSchema.cjs +0 -1
- package/schema/loggerSchema.js +0 -1
- package/schema/operationSchemas.cjs +0 -1
- package/schema/operationSchemas.js +0 -1
- package/schema/sdkFacadeSchemas.cjs +0 -1
- package/schema/sdkFacadeSchemas.js +0 -1
- package/schema/sdkSchemas.cjs +0 -1
- package/schema/sdkSchemas.js +0 -1
- package/schema/tokenSchema.cjs +0 -1
- package/schema/tokenSchema.js +0 -1
- package/schema/userSchema.cjs +0 -1
- package/schema/userSchema.js +0 -1
- package/sdk.cjs +0 -1
- package/sdk.js +0 -1
- package/sdkEvents.cjs +0 -1
- package/sdkEvents.js +0 -1
- package/sourceLocation.cjs +0 -1
- package/sourceLocation.js +0 -1
- package/tab.cjs +0 -1
- package/tab.js +0 -1
- package/token/cachedTokenStore.cjs +0 -1
- package/token/cachedTokenStore.js +0 -1
- package/token/inMemoryTokenStore.cjs +0 -1
- package/token/inMemoryTokenStore.js +0 -1
- package/token/index.cjs +0 -1
- package/token/index.js +0 -1
- package/token/replicatedTokenStore.cjs +0 -1
- package/token/replicatedTokenStore.js +0 -1
- package/token/token.cjs +0 -1
- package/token/token.js +0 -1
- package/tracker.cjs +0 -1
- package/tracker.js +0 -1
- package/trackingEvents.cjs +0 -1
- package/trackingEvents.js +0 -1
- package/transformer.cjs +0 -1
- package/transformer.js +0 -1
- package/utilityTypes.cjs +0 -1
- package/utilityTypes.js +0 -1
- package/uuid.cjs +0 -1
- package/uuid.js +0 -1
- package/validation/arrayType.cjs +0 -1
- package/validation/arrayType.js +0 -1
- package/validation/booleanType.cjs +0 -1
- package/validation/booleanType.js +0 -1
- package/validation/functionType.cjs +0 -1
- package/validation/functionType.js +0 -1
- package/validation/index.cjs +0 -1
- package/validation/index.js +0 -1
- package/validation/jsonType.cjs +0 -1
- package/validation/jsonType.js +0 -1
- package/validation/mixedSchema.cjs +0 -1
- package/validation/mixedSchema.js +0 -1
- package/validation/nullType.cjs +0 -1
- package/validation/nullType.js +0 -1
- package/validation/numberType.cjs +0 -1
- package/validation/numberType.js +0 -1
- package/validation/objectType.cjs +0 -1
- package/validation/objectType.js +0 -1
- package/validation/schema.cjs +0 -1
- package/validation/schema.js +0 -1
- package/validation/stringType.cjs +0 -1
- package/validation/stringType.js +0 -1
- package/validation/unionType.cjs +0 -1
- package/validation/unionType.js +0 -1
- package/validation/violation.cjs +0 -1
- package/validation/violation.js +0 -1
- package/activeRecord.cjs.map +0 -1
- package/activeRecord.js.map +0 -1
- package/apiKey.cjs.map +0 -1
- package/apiKey.js.map +0 -1
- package/base64Url.cjs.map +0 -1
- package/base64Url.js.map +0 -1
- package/cache/cache.cjs.map +0 -1
- package/cache/cache.js.map +0 -1
- package/cache/cookieCache.cjs.map +0 -1
- package/cache/cookieCache.js.map +0 -1
- package/cache/fallbackCache.cjs.map +0 -1
- package/cache/fallbackCache.js.map +0 -1
- package/cache/inMemoryCache.cjs.map +0 -1
- package/cache/inMemoryCache.js.map +0 -1
- package/cache/index.cjs.map +0 -1
- package/cache/index.js.map +0 -1
- package/cache/localStorageCache.cjs.map +0 -1
- package/cache/localStorageCache.js.map +0 -1
- package/channel/channel.cjs.map +0 -1
- package/channel/channel.js.map +0 -1
- package/channel/encodedChannel.cjs.map +0 -1
- package/channel/encodedChannel.js.map +0 -1
- package/channel/guaranteedChannel.cjs.map +0 -1
- package/channel/guaranteedChannel.js.map +0 -1
- package/channel/httpBeaconChannel.cjs.map +0 -1
- package/channel/httpBeaconChannel.js.map +0 -1
- package/channel/index.cjs.map +0 -1
- package/channel/index.js.map +0 -1
- package/channel/queuedChannel.cjs.map +0 -1
- package/channel/queuedChannel.js.map +0 -1
- package/channel/retryChannel.cjs.map +0 -1
- package/channel/retryChannel.js.map +0 -1
- package/channel/sandboxChannel.cjs.map +0 -1
- package/channel/sandboxChannel.js.map +0 -1
- package/cid/assigner.cjs.map +0 -1
- package/cid/assigner.js.map +0 -1
- package/cid/cachedAssigner.cjs.map +0 -1
- package/cid/cachedAssigner.js.map +0 -1
- package/cid/fixedAssigner.cjs.map +0 -1
- package/cid/fixedAssigner.js.map +0 -1
- package/cid/index.cjs.map +0 -1
- package/cid/index.js.map +0 -1
- package/cid/remoteAssigner.cjs.map +0 -1
- package/cid/remoteAssigner.js.map +0 -1
- package/constants.cjs.map +0 -1
- package/constants.js.map +0 -1
- package/container.cjs.map +0 -1
- package/container.js.map +0 -1
- package/contentFetcher.cjs.map +0 -1
- package/contentFetcher.js.map +0 -1
- package/context.cjs.map +0 -1
- package/context.js.map +0 -1
- package/error.cjs.map +0 -1
- package/error.js.map +0 -1
- package/evaluator.cjs.map +0 -1
- package/evaluator.js.map +0 -1
- package/eventManager.cjs.map +0 -1
- package/eventManager.js.map +0 -1
- package/eventSubjectProcessor.cjs.map +0 -1
- package/eventSubjectProcessor.js.map +0 -1
- package/facade/contentFetcherFacade.cjs.map +0 -1
- package/facade/contentFetcherFacade.js.map +0 -1
- package/facade/evaluatorFacade.cjs.map +0 -1
- package/facade/evaluatorFacade.js.map +0 -1
- package/facade/index.cjs.map +0 -1
- package/facade/index.js.map +0 -1
- package/facade/sdkFacade.cjs.map +0 -1
- package/facade/sdkFacade.js.map +0 -1
- package/facade/sessionFacade.cjs.map +0 -1
- package/facade/sessionFacade.js.map +0 -1
- package/facade/sessionPatch.cjs.map +0 -1
- package/facade/sessionPatch.js.map +0 -1
- package/facade/trackerFacade.cjs.map +0 -1
- package/facade/trackerFacade.js.map +0 -1
- package/facade/userFacade.cjs.map +0 -1
- package/facade/userFacade.js.map +0 -1
- package/facade/userPatch.cjs.map +0 -1
- package/facade/userPatch.js.map +0 -1
- package/help.cjs.map +0 -1
- package/help.js.map +0 -1
- package/index.cjs.map +0 -1
- package/index.js.map +0 -1
- package/logging/consoleLogger.cjs.map +0 -1
- package/logging/consoleLogger.js.map +0 -1
- package/logging/filteredLogger.cjs.map +0 -1
- package/logging/filteredLogger.js.map +0 -1
- package/logging/index.cjs.map +0 -1
- package/logging/index.js.map +0 -1
- package/logging/logger.cjs.map +0 -1
- package/logging/logger.js.map +0 -1
- package/logging/namespacedLogger.cjs.map +0 -1
- package/logging/namespacedLogger.js.map +0 -1
- package/logging/nullLogger.cjs.map +0 -1
- package/logging/nullLogger.js.map +0 -1
- package/namespacedStorage.cjs.map +0 -1
- package/namespacedStorage.js.map +0 -1
- package/patch.cjs.map +0 -1
- package/patch.js.map +0 -1
- package/queue/capacityRestrictedQueue.cjs.map +0 -1
- package/queue/capacityRestrictedQueue.js.map +0 -1
- package/queue/inMemoryQueue.cjs.map +0 -1
- package/queue/inMemoryQueue.js.map +0 -1
- package/queue/index.cjs.map +0 -1
- package/queue/index.js.map +0 -1
- package/queue/monitoredQueue.cjs.map +0 -1
- package/queue/monitoredQueue.js.map +0 -1
- package/queue/persistentQueue.cjs.map +0 -1
- package/queue/persistentQueue.js.map +0 -1
- package/queue/queue.cjs.map +0 -1
- package/queue/queue.js.map +0 -1
- package/retry/arbitraryPolicy.cjs.map +0 -1
- package/retry/arbitraryPolicy.js.map +0 -1
- package/retry/backoffPolicy.cjs.map +0 -1
- package/retry/backoffPolicy.js.map +0 -1
- package/retry/index.cjs.map +0 -1
- package/retry/index.js.map +0 -1
- package/retry/maxAttemptsPolicy.cjs.map +0 -1
- package/retry/maxAttemptsPolicy.js.map +0 -1
- package/retry/neverPolicy.cjs.map +0 -1
- package/retry/neverPolicy.js.map +0 -1
- package/retry/policy.cjs.map +0 -1
- package/retry/policy.js.map +0 -1
- package/schema/attributeSchema.cjs.map +0 -1
- package/schema/attributeSchema.js.map +0 -1
- package/schema/contentFetcherSchemas.cjs.map +0 -1
- package/schema/contentFetcherSchemas.js.map +0 -1
- package/schema/contentSchemas.cjs.map +0 -1
- package/schema/contentSchemas.js.map +0 -1
- package/schema/contextSchemas.cjs.map +0 -1
- package/schema/contextSchemas.js.map +0 -1
- package/schema/ecommerceSchemas.cjs.map +0 -1
- package/schema/ecommerceSchemas.js.map +0 -1
- package/schema/evaluatorSchemas.cjs.map +0 -1
- package/schema/evaluatorSchemas.js.map +0 -1
- package/schema/eventSchemas.cjs.map +0 -1
- package/schema/eventSchemas.js.map +0 -1
- package/schema/index.cjs.map +0 -1
- package/schema/index.js.map +0 -1
- package/schema/loggerSchema.cjs.map +0 -1
- package/schema/loggerSchema.js.map +0 -1
- package/schema/operationSchemas.cjs.map +0 -1
- package/schema/operationSchemas.js.map +0 -1
- package/schema/sdkFacadeSchemas.cjs.map +0 -1
- package/schema/sdkFacadeSchemas.js.map +0 -1
- package/schema/sdkSchemas.cjs.map +0 -1
- package/schema/sdkSchemas.js.map +0 -1
- package/schema/tokenSchema.cjs.map +0 -1
- package/schema/tokenSchema.js.map +0 -1
- package/schema/userSchema.cjs.map +0 -1
- package/schema/userSchema.js.map +0 -1
- package/sdk.cjs.map +0 -1
- package/sdk.js.map +0 -1
- package/sdkEvents.cjs.map +0 -1
- package/sdkEvents.js.map +0 -1
- package/sourceLocation.cjs.map +0 -1
- package/sourceLocation.js.map +0 -1
- package/src/activeRecord.ts +0 -150
- package/src/apiKey.ts +0 -208
- package/src/base64Url.ts +0 -22
- package/src/cache/cache.ts +0 -22
- package/src/cache/cookieCache.ts +0 -88
- package/src/cache/fallbackCache.ts +0 -29
- package/src/cache/inMemoryCache.ts +0 -21
- package/src/cache/index.ts +0 -4
- package/src/cache/localStorageCache.ts +0 -85
- package/src/channel/channel.ts +0 -52
- package/src/channel/encodedChannel.ts +0 -21
- package/src/channel/guaranteedChannel.ts +0 -131
- package/src/channel/httpBeaconChannel.ts +0 -128
- package/src/channel/index.ts +0 -7
- package/src/channel/queuedChannel.ts +0 -143
- package/src/channel/retryChannel.ts +0 -94
- package/src/channel/sandboxChannel.ts +0 -47
- package/src/cid/assigner.ts +0 -3
- package/src/cid/cachedAssigner.ts +0 -68
- package/src/cid/fixedAssigner.ts +0 -13
- package/src/cid/index.ts +0 -4
- package/src/cid/remoteAssigner.ts +0 -57
- package/src/constants.ts +0 -4
- package/src/container.ts +0 -410
- package/src/contentFetcher.ts +0 -290
- package/src/context.ts +0 -139
- package/src/error.ts +0 -31
- package/src/evaluator.ts +0 -314
- package/src/eventManager.ts +0 -53
- package/src/eventSubjectProcessor.ts +0 -85
- package/src/facade/contentFetcherFacade.ts +0 -69
- package/src/facade/evaluatorFacade.ts +0 -111
- package/src/facade/index.ts +0 -7
- package/src/facade/sdkFacade.ts +0 -310
- package/src/facade/sessionFacade.ts +0 -14
- package/src/facade/sessionPatch.ts +0 -32
- package/src/facade/trackerFacade.ts +0 -98
- package/src/facade/userFacade.ts +0 -26
- package/src/facade/userPatch.ts +0 -32
- package/src/help.ts +0 -24
- package/src/index.ts +0 -4
- package/src/logging/consoleLogger.ts +0 -38
- package/src/logging/filteredLogger.ts +0 -57
- package/src/logging/index.ts +0 -5
- package/src/logging/logger.ts +0 -13
- package/src/logging/namespacedLogger.ts +0 -32
- package/src/logging/nullLogger.ts +0 -19
- package/src/namespacedStorage.ts +0 -69
- package/src/patch.ts +0 -64
- package/src/queue/capacityRestrictedQueue.ts +0 -44
- package/src/queue/inMemoryQueue.ts +0 -43
- package/src/queue/index.ts +0 -5
- package/src/queue/monitoredQueue.ts +0 -168
- package/src/queue/persistentQueue.ts +0 -73
- package/src/queue/queue.ts +0 -15
- package/src/retry/arbitraryPolicy.ts +0 -21
- package/src/retry/backoffPolicy.ts +0 -84
- package/src/retry/index.ts +0 -5
- package/src/retry/maxAttemptsPolicy.ts +0 -28
- package/src/retry/neverPolicy.ts +0 -11
- package/src/retry/policy.ts +0 -5
- package/src/schema/attributeSchema.ts +0 -6
- package/src/schema/contentFetcherSchemas.ts +0 -23
- package/src/schema/contentSchemas.ts +0 -44
- package/src/schema/contextSchemas.ts +0 -5
- package/src/schema/ecommerceSchemas.ts +0 -179
- package/src/schema/evaluatorSchemas.ts +0 -52
- package/src/schema/eventSchemas.ts +0 -134
- package/src/schema/index.ts +0 -11
- package/src/schema/loggerSchema.ts +0 -12
- package/src/schema/operationSchemas.ts +0 -102
- package/src/schema/sdkFacadeSchemas.ts +0 -64
- package/src/schema/sdkSchemas.ts +0 -82
- package/src/schema/tokenSchema.ts +0 -42
- package/src/schema/userSchema.ts +0 -184
- package/src/sdk.ts +0 -183
- package/src/sdkEvents.ts +0 -15
- package/src/sourceLocation.ts +0 -85
- package/src/tab.ts +0 -148
- package/src/token/cachedTokenStore.ts +0 -34
- package/src/token/inMemoryTokenStore.ts +0 -13
- package/src/token/index.ts +0 -4
- package/src/token/replicatedTokenStore.ts +0 -21
- package/src/token/token.ts +0 -301
- package/src/tracker.ts +0 -504
- package/src/trackingEvents.ts +0 -452
- package/src/transformer.ts +0 -7
- package/src/utilityTypes.ts +0 -3
- package/src/uuid.ts +0 -43
- package/src/validation/arrayType.ts +0 -71
- package/src/validation/booleanType.ts +0 -22
- package/src/validation/functionType.ts +0 -22
- package/src/validation/index.ts +0 -12
- package/src/validation/jsonType.ts +0 -156
- package/src/validation/mixedSchema.ts +0 -7
- package/src/validation/nullType.ts +0 -22
- package/src/validation/numberType.ts +0 -59
- package/src/validation/objectType.ts +0 -138
- package/src/validation/schema.ts +0 -21
- package/src/validation/stringType.ts +0 -118
- package/src/validation/unionType.ts +0 -53
- package/src/validation/violation.ts +0 -23
- package/tab.cjs.map +0 -1
- package/tab.js.map +0 -1
- package/token/cachedTokenStore.cjs.map +0 -1
- package/token/cachedTokenStore.js.map +0 -1
- package/token/inMemoryTokenStore.cjs.map +0 -1
- package/token/inMemoryTokenStore.js.map +0 -1
- package/token/index.cjs.map +0 -1
- package/token/index.js.map +0 -1
- package/token/replicatedTokenStore.cjs.map +0 -1
- package/token/replicatedTokenStore.js.map +0 -1
- package/token/token.cjs.map +0 -1
- package/token/token.js.map +0 -1
- package/tracker.cjs.map +0 -1
- package/tracker.js.map +0 -1
- package/trackingEvents.cjs.map +0 -1
- package/trackingEvents.js.map +0 -1
- package/transformer.cjs.map +0 -1
- package/transformer.js.map +0 -1
- package/utilityTypes.cjs.map +0 -1
- package/utilityTypes.js.map +0 -1
- package/uuid.cjs.map +0 -1
- package/uuid.js.map +0 -1
- package/validation/arrayType.cjs.map +0 -1
- package/validation/arrayType.js.map +0 -1
- package/validation/booleanType.cjs.map +0 -1
- package/validation/booleanType.js.map +0 -1
- package/validation/functionType.cjs.map +0 -1
- package/validation/functionType.js.map +0 -1
- package/validation/index.cjs.map +0 -1
- package/validation/index.js.map +0 -1
- package/validation/jsonType.cjs.map +0 -1
- package/validation/jsonType.js.map +0 -1
- package/validation/mixedSchema.cjs.map +0 -1
- package/validation/mixedSchema.js.map +0 -1
- package/validation/nullType.cjs.map +0 -1
- package/validation/nullType.js.map +0 -1
- package/validation/numberType.cjs.map +0 -1
- package/validation/numberType.js.map +0 -1
- package/validation/objectType.cjs.map +0 -1
- package/validation/objectType.js.map +0 -1
- package/validation/schema.cjs.map +0 -1
- package/validation/schema.js.map +0 -1
- package/validation/stringType.cjs.map +0 -1
- package/validation/stringType.js.map +0 -1
- package/validation/unionType.cjs.map +0 -1
- package/validation/unionType.js.map +0 -1
- package/validation/violation.cjs.map +0 -1
- package/validation/violation.js.map +0 -1
package/src/channel/channel.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import {formatMessage} from '../error';
|
|
2
|
-
|
|
3
|
-
export class MessageDeliveryError extends Error {
|
|
4
|
-
public readonly retryable: boolean;
|
|
5
|
-
|
|
6
|
-
public constructor(message: string, retryable: boolean) {
|
|
7
|
-
super(message);
|
|
8
|
-
|
|
9
|
-
this.retryable = retryable;
|
|
10
|
-
|
|
11
|
-
Object.setPrototypeOf(this, MessageDeliveryError.prototype);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
public static retryable(cause: unknown): MessageDeliveryError {
|
|
15
|
-
return MessageDeliveryError.fromCause(cause, true);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
public static nonRetryable(cause: unknown): MessageDeliveryError {
|
|
19
|
-
return MessageDeliveryError.fromCause(cause, false);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
private static fromCause(cause: unknown, retryable: boolean): MessageDeliveryError {
|
|
23
|
-
const error = new MessageDeliveryError(formatMessage(cause), retryable);
|
|
24
|
-
|
|
25
|
-
if (cause instanceof Error) {
|
|
26
|
-
error.stack = cause.stack;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return error;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface Closeable {
|
|
34
|
-
close(): Promise<void>;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface OutputChannel<O> extends Closeable {
|
|
38
|
-
publish(message: O): Promise<void>;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export type ChannelListener<T> = {
|
|
42
|
-
(message: T): void,
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export interface InputChannel<I> extends Closeable {
|
|
46
|
-
subscribe(listener: ChannelListener<I>): void;
|
|
47
|
-
|
|
48
|
-
unsubscribe(listener: ChannelListener<I>): void;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export interface DuplexChannel<I, O> extends InputChannel<I>, OutputChannel<O> {
|
|
52
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import {OutputChannel} from './channel';
|
|
2
|
-
import {Transformer} from '../transformer';
|
|
3
|
-
|
|
4
|
-
export class EncodedChannel<D, E> implements OutputChannel<D> {
|
|
5
|
-
private readonly encode: Transformer<D, E>;
|
|
6
|
-
|
|
7
|
-
private readonly channel: OutputChannel<E>;
|
|
8
|
-
|
|
9
|
-
public constructor(channel: OutputChannel<E>, encoder: Transformer<D, E>) {
|
|
10
|
-
this.channel = channel;
|
|
11
|
-
this.encode = encoder;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
public publish(message: D): Promise<void> {
|
|
15
|
-
return this.encode(message).then((result => this.channel.publish(result)));
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
public close(): Promise<void> {
|
|
19
|
-
return this.channel.close();
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import {Logger, NullLogger} from '../logging';
|
|
2
|
-
import {DuplexChannel, MessageDeliveryError, OutputChannel} from './channel';
|
|
3
|
-
|
|
4
|
-
export type MessageStamper<M, S> = {
|
|
5
|
-
generate(message: M): S,
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export class TimeStamper implements MessageStamper<any, string> {
|
|
9
|
-
public generate(): string {
|
|
10
|
-
return String(Date.now());
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export type Envelope<M, S> = {
|
|
15
|
-
id: S,
|
|
16
|
-
message: M,
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
type Options = {
|
|
20
|
-
ackTimeout: number,
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
type Configuration<M, S> = Partial<Options> & {
|
|
24
|
-
channel: DuplexChannel<S, Envelope<M, S>>,
|
|
25
|
-
stamper: MessageStamper<M, S>,
|
|
26
|
-
logger?: Logger,
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export class GuaranteedChannel<M, S> implements OutputChannel<M> {
|
|
30
|
-
private readonly channel: DuplexChannel<S, Envelope<M, S>>;
|
|
31
|
-
|
|
32
|
-
private readonly stamper: MessageStamper<M, S>;
|
|
33
|
-
|
|
34
|
-
private readonly logger: Logger;
|
|
35
|
-
|
|
36
|
-
private readonly options: Options;
|
|
37
|
-
|
|
38
|
-
private closed = false;
|
|
39
|
-
|
|
40
|
-
public constructor({channel, logger, stamper, ...options}: Configuration<M, S>) {
|
|
41
|
-
this.channel = channel;
|
|
42
|
-
this.logger = logger ?? new NullLogger();
|
|
43
|
-
this.stamper = stamper;
|
|
44
|
-
this.options = {
|
|
45
|
-
...options,
|
|
46
|
-
ackTimeout: options.ackTimeout ?? 5000,
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
public publish(message: M): Promise<void> {
|
|
51
|
-
if (this.closed) {
|
|
52
|
-
return Promise.reject(MessageDeliveryError.nonRetryable('Channel is closed.'));
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return new Promise((resolve, reject): void => {
|
|
56
|
-
const id = this.stamper.generate(message);
|
|
57
|
-
|
|
58
|
-
let timeoutTimer: number;
|
|
59
|
-
let closeWatcher: number;
|
|
60
|
-
let confirmed = false;
|
|
61
|
-
const start = Date.now();
|
|
62
|
-
|
|
63
|
-
const acknowledge = (response: any): void => {
|
|
64
|
-
if (response === id) {
|
|
65
|
-
confirmed = true;
|
|
66
|
-
|
|
67
|
-
const elapsed = Date.now() - start;
|
|
68
|
-
|
|
69
|
-
window.clearTimeout(timeoutTimer);
|
|
70
|
-
window.clearInterval(closeWatcher);
|
|
71
|
-
|
|
72
|
-
this.logger.debug(`Delivery confirmed #${id}, elapsed ${elapsed}ms.`);
|
|
73
|
-
|
|
74
|
-
this.channel.unsubscribe(acknowledge);
|
|
75
|
-
|
|
76
|
-
resolve();
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
this.channel.subscribe(acknowledge);
|
|
81
|
-
|
|
82
|
-
const abort = (error: any): void => {
|
|
83
|
-
window.clearTimeout(timeoutTimer);
|
|
84
|
-
window.clearInterval(closeWatcher);
|
|
85
|
-
|
|
86
|
-
this.logger.error(`Failed to send message #${id}`);
|
|
87
|
-
|
|
88
|
-
this.channel.unsubscribe(acknowledge);
|
|
89
|
-
|
|
90
|
-
reject(error);
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
const wait = (): void => {
|
|
94
|
-
if (confirmed) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
closeWatcher = window.setInterval(
|
|
99
|
-
() => {
|
|
100
|
-
if (this.closed) {
|
|
101
|
-
// Cancel delay immediately when the channel is closed
|
|
102
|
-
abort(MessageDeliveryError.retryable('Connection deliberately closed.'));
|
|
103
|
-
}
|
|
104
|
-
},
|
|
105
|
-
0,
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
this.logger.debug(`Waiting confirmation #${id}...`);
|
|
109
|
-
|
|
110
|
-
timeoutTimer = window.setTimeout(
|
|
111
|
-
() => {
|
|
112
|
-
abort(MessageDeliveryError.retryable('Maximum confirmation time reached.'));
|
|
113
|
-
},
|
|
114
|
-
this.options.ackTimeout,
|
|
115
|
-
);
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
this.logger.debug(`Sending message #${id}...`);
|
|
119
|
-
|
|
120
|
-
this.channel
|
|
121
|
-
.publish({id: id, message: message})
|
|
122
|
-
.then(wait, abort);
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
public close(): Promise<void> {
|
|
127
|
-
this.closed = true;
|
|
128
|
-
|
|
129
|
-
return this.channel.close();
|
|
130
|
-
}
|
|
131
|
-
}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import {ChannelListener, DuplexChannel, MessageDeliveryError} from './channel';
|
|
2
|
-
import {Envelope} from './guaranteedChannel';
|
|
3
|
-
import {Logger, NullLogger} from '../logging';
|
|
4
|
-
import {CidAssigner} from '../cid';
|
|
5
|
-
import {formatMessage} from '../error';
|
|
6
|
-
import {CLIENT_LIBRARY} from '../constants';
|
|
7
|
-
import {Help} from '../help';
|
|
8
|
-
|
|
9
|
-
export type Configuration = {
|
|
10
|
-
appId: string,
|
|
11
|
-
endpointUrl: string,
|
|
12
|
-
cidAssigner: CidAssigner,
|
|
13
|
-
logger?: Logger,
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
type ApiProblem = {
|
|
17
|
-
type: string,
|
|
18
|
-
title: string,
|
|
19
|
-
status: number,
|
|
20
|
-
detail: string,
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export class HttpBeaconChannel implements DuplexChannel<string, Envelope<string, string>> {
|
|
24
|
-
private readonly configuration: Omit<Configuration, 'logger'>;
|
|
25
|
-
|
|
26
|
-
private readonly logger: Logger;
|
|
27
|
-
|
|
28
|
-
private readonly listeners: Array<ChannelListener<string>> = [];
|
|
29
|
-
|
|
30
|
-
private closed = false;
|
|
31
|
-
|
|
32
|
-
public constructor({logger = new NullLogger(), ...configuration}: Configuration) {
|
|
33
|
-
this.configuration = configuration;
|
|
34
|
-
this.logger = logger;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
public async publish({id: receiptId, message}: Envelope<string, string>): Promise<void> {
|
|
38
|
-
if (this.closed) {
|
|
39
|
-
return Promise.reject(MessageDeliveryError.nonRetryable('Channel is closed'));
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const {token, timestamp, context, payload} = JSON.parse(message);
|
|
43
|
-
const {endpointUrl, appId, cidAssigner} = this.configuration;
|
|
44
|
-
|
|
45
|
-
return fetch(endpointUrl, {
|
|
46
|
-
method: 'POST',
|
|
47
|
-
headers: {
|
|
48
|
-
'X-App-Id': appId,
|
|
49
|
-
'X-Client-Id': await cidAssigner.assignCid(),
|
|
50
|
-
'X-Client-Library': CLIENT_LIBRARY,
|
|
51
|
-
'Content-Type': 'application/json',
|
|
52
|
-
...(token !== undefined ? {'X-Token': token} : {}),
|
|
53
|
-
},
|
|
54
|
-
body: JSON.stringify({
|
|
55
|
-
context: context,
|
|
56
|
-
payload: payload,
|
|
57
|
-
originalTime: timestamp,
|
|
58
|
-
departureTime: Date.now(),
|
|
59
|
-
}),
|
|
60
|
-
}).then(async response => {
|
|
61
|
-
if (response.ok) {
|
|
62
|
-
this.notify(receiptId);
|
|
63
|
-
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const problem: ApiProblem = await response.json().catch(
|
|
68
|
-
() => ({
|
|
69
|
-
type: 'https://croct.help/api/event-tracker#unexpected-error',
|
|
70
|
-
title: response.statusText,
|
|
71
|
-
status: response.status,
|
|
72
|
-
}),
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
const isRetryable = HttpBeaconChannel.isRetryable(problem.status);
|
|
76
|
-
const help = Help.forStatusCode(problem.status);
|
|
77
|
-
|
|
78
|
-
if (help !== undefined) {
|
|
79
|
-
this.logger.error(help);
|
|
80
|
-
} else if (!isRetryable) {
|
|
81
|
-
this.logger.error(`Beacon rejected with non-retryable status: ${problem.title}`);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return Promise.reject(
|
|
85
|
-
isRetryable
|
|
86
|
-
? MessageDeliveryError.retryable(problem.title)
|
|
87
|
-
: MessageDeliveryError.nonRetryable(problem.title),
|
|
88
|
-
);
|
|
89
|
-
}).catch(error => {
|
|
90
|
-
this.logger.error(`Failed to publish beacon: ${formatMessage(error)}`);
|
|
91
|
-
|
|
92
|
-
return Promise.reject(
|
|
93
|
-
error instanceof MessageDeliveryError
|
|
94
|
-
? error
|
|
95
|
-
: MessageDeliveryError.retryable(error),
|
|
96
|
-
);
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
public subscribe(listener: ChannelListener<string>): void {
|
|
101
|
-
if (!this.listeners.includes(listener)) {
|
|
102
|
-
this.listeners.push(listener);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
public unsubscribe(listener: ChannelListener<string>): void {
|
|
107
|
-
const index = this.listeners.indexOf(listener);
|
|
108
|
-
|
|
109
|
-
if (index >= 0) {
|
|
110
|
-
this.listeners.splice(index, 1);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
private notify(receiptId: string): void {
|
|
115
|
-
this.listeners.forEach(dispatch => dispatch(receiptId));
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
public close(): Promise<void> {
|
|
119
|
-
this.closed = true;
|
|
120
|
-
|
|
121
|
-
return Promise.resolve();
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
private static isRetryable(status: number): boolean {
|
|
125
|
-
// Retry on any server error and client errors 429 (rate limit) and 408 (request timeout)
|
|
126
|
-
return status >= 500 || status === 429 || status === 408;
|
|
127
|
-
}
|
|
128
|
-
}
|
package/src/channel/index.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export * from './channel';
|
|
2
|
-
export {EncodedChannel} from './encodedChannel';
|
|
3
|
-
export {GuaranteedChannel} from './guaranteedChannel';
|
|
4
|
-
export {QueuedChannel} from './queuedChannel';
|
|
5
|
-
export {RetryChannel} from './retryChannel';
|
|
6
|
-
export {SandboxChannel} from './sandboxChannel';
|
|
7
|
-
export {HttpBeaconChannel} from './httpBeaconChannel';
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import {MessageDeliveryError, OutputChannel} from './channel';
|
|
2
|
-
import {Queue} from '../queue';
|
|
3
|
-
import {Logger, NullLogger} from '../logging';
|
|
4
|
-
|
|
5
|
-
export class QueuedChannel<T> implements OutputChannel<T> {
|
|
6
|
-
private readonly channel: OutputChannel<T>;
|
|
7
|
-
|
|
8
|
-
private readonly queue: Queue<T>;
|
|
9
|
-
|
|
10
|
-
private readonly logger: Logger;
|
|
11
|
-
|
|
12
|
-
private pending?: Promise<void>;
|
|
13
|
-
|
|
14
|
-
private closed = false;
|
|
15
|
-
|
|
16
|
-
public constructor(channel: OutputChannel<T>, queue: Queue<T>, logger?: Logger) {
|
|
17
|
-
this.channel = channel;
|
|
18
|
-
this.queue = queue;
|
|
19
|
-
this.logger = logger ?? new NullLogger();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
public flush(): Promise<void> {
|
|
23
|
-
if (this.pending === undefined) {
|
|
24
|
-
return this.requeue();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return this.pending.catch(this.requeue.bind(this));
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public publish(message: T): Promise<void> {
|
|
31
|
-
if (this.closed) {
|
|
32
|
-
return Promise.reject(MessageDeliveryError.nonRetryable('Channel is closed.'));
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (this.queue.length() >= this.queue.getCapacity()) {
|
|
36
|
-
this.logger.warn('The queue is full, message rejected.');
|
|
37
|
-
|
|
38
|
-
return Promise.reject(MessageDeliveryError.retryable('The queue is full.'));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (this.pending === undefined) {
|
|
42
|
-
this.pending = this.requeue();
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
this.pending = this.chainNext(this.pending, message, true);
|
|
46
|
-
|
|
47
|
-
return this.pending;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
private enqueue(message: T): void {
|
|
51
|
-
this.logger.debug('Enqueueing message...');
|
|
52
|
-
this.logger.debug(`Queue length: ${this.queue.length() + 1}`);
|
|
53
|
-
|
|
54
|
-
this.queue.push(message);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
private dequeue(): void {
|
|
58
|
-
this.logger.debug('Dequeuing message...');
|
|
59
|
-
this.logger.debug(`Queue length: ${Math.max(0, this.queue.length() - 1)}`);
|
|
60
|
-
|
|
61
|
-
this.queue.shift();
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
private requeue(): Promise<void> {
|
|
65
|
-
if (this.closed) {
|
|
66
|
-
return Promise.reject(MessageDeliveryError.nonRetryable('Channel is closed.'));
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
this.pending = Promise.resolve();
|
|
70
|
-
|
|
71
|
-
if (this.queue.isEmpty()) {
|
|
72
|
-
return this.pending;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const length = this.queue.length();
|
|
76
|
-
|
|
77
|
-
this.logger.debug('Requeuing messages...');
|
|
78
|
-
this.logger.debug(`Queue length: ${length}`);
|
|
79
|
-
|
|
80
|
-
for (const message of this.queue.all()) {
|
|
81
|
-
this.pending = this.chainNext(this.pending, message);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return this.pending;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
private async chainNext(previous: Promise<void>, message: T, enqueue = false): Promise<void> {
|
|
88
|
-
if (enqueue) {
|
|
89
|
-
this.enqueue(message);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
try {
|
|
93
|
-
await previous;
|
|
94
|
-
} catch (error) {
|
|
95
|
-
if (error instanceof MessageDeliveryError && error.retryable) {
|
|
96
|
-
// If the previous message failed to deliver, requeue all messages
|
|
97
|
-
// including the current one that was just enqueued
|
|
98
|
-
return this.requeue();
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
throw error;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (this.closed) {
|
|
105
|
-
throw MessageDeliveryError.retryable('Connection deliberately closed.');
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
try {
|
|
109
|
-
const result = await this.channel.publish(message);
|
|
110
|
-
|
|
111
|
-
this.dequeue();
|
|
112
|
-
|
|
113
|
-
return result;
|
|
114
|
-
} catch (error) {
|
|
115
|
-
if (!(error instanceof MessageDeliveryError) || !error.retryable) {
|
|
116
|
-
// Discard the message if it's non-retryable
|
|
117
|
-
this.dequeue();
|
|
118
|
-
|
|
119
|
-
if (!enqueue) {
|
|
120
|
-
// If the message was not enqueued, suppress the error
|
|
121
|
-
// so that the next message in the queue can be immediately
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
throw error;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
public async close(): Promise<void> {
|
|
131
|
-
this.closed = true;
|
|
132
|
-
|
|
133
|
-
await this.channel.close();
|
|
134
|
-
|
|
135
|
-
if (this.pending !== undefined) {
|
|
136
|
-
try {
|
|
137
|
-
await this.pending;
|
|
138
|
-
} catch {
|
|
139
|
-
// suppress errors
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import {MessageDeliveryError, OutputChannel} from './channel';
|
|
2
|
-
import {Logger, NullLogger} from '../logging';
|
|
3
|
-
import {RetryPolicy} from '../retry';
|
|
4
|
-
|
|
5
|
-
type Configuration<T> = {
|
|
6
|
-
channel: OutputChannel<T>,
|
|
7
|
-
retryPolicy: RetryPolicy<T>,
|
|
8
|
-
logger?: Logger,
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export class RetryChannel<T> implements OutputChannel<T> {
|
|
12
|
-
private readonly channel: OutputChannel<T>;
|
|
13
|
-
|
|
14
|
-
private readonly retryPolicy: RetryPolicy<T>;
|
|
15
|
-
|
|
16
|
-
private readonly logger: Logger;
|
|
17
|
-
|
|
18
|
-
private closed = false;
|
|
19
|
-
|
|
20
|
-
public constructor({channel, retryPolicy, logger}: Configuration<T>) {
|
|
21
|
-
this.channel = channel;
|
|
22
|
-
this.retryPolicy = retryPolicy;
|
|
23
|
-
this.logger = logger ?? new NullLogger();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public publish(message: T): Promise<void> {
|
|
27
|
-
if (this.closed) {
|
|
28
|
-
return Promise.reject(MessageDeliveryError.nonRetryable('The channel is closed.'));
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return this.channel
|
|
32
|
-
.publish(message)
|
|
33
|
-
.catch(error => this.retry(message, error));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
public async retry(message: T, error: unknown): Promise<void> {
|
|
37
|
-
if (error instanceof MessageDeliveryError && !error.retryable) {
|
|
38
|
-
throw error;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
let attempt = 0;
|
|
42
|
-
|
|
43
|
-
while (this.retryPolicy.shouldRetry(attempt, message, error)) {
|
|
44
|
-
if (this.closed) {
|
|
45
|
-
throw MessageDeliveryError.retryable('Connection deliberately closed.');
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const delay = this.retryPolicy.getDelay(attempt);
|
|
49
|
-
|
|
50
|
-
this.logger.debug(`Retry attempt ${attempt + 1}`);
|
|
51
|
-
|
|
52
|
-
if (delay > 0) {
|
|
53
|
-
this.logger.debug(`Retry attempt delayed in ${delay}ms`);
|
|
54
|
-
|
|
55
|
-
await new Promise<void>((resolve, reject): void => {
|
|
56
|
-
const closeWatcher = window.setInterval(
|
|
57
|
-
() => {
|
|
58
|
-
if (this.closed) {
|
|
59
|
-
// Cancel delay immediately when the channel is closed
|
|
60
|
-
window.clearInterval(closeWatcher);
|
|
61
|
-
|
|
62
|
-
reject(MessageDeliveryError.retryable('Connection deliberately closed.'));
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
0,
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
window.setTimeout(
|
|
69
|
-
(): void => {
|
|
70
|
-
window.clearInterval(closeWatcher);
|
|
71
|
-
|
|
72
|
-
resolve();
|
|
73
|
-
},
|
|
74
|
-
delay,
|
|
75
|
-
);
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
try {
|
|
80
|
-
return await this.channel.publish(message);
|
|
81
|
-
} catch {
|
|
82
|
-
attempt += 1;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
throw MessageDeliveryError.nonRetryable('Maximum retry attempts reached.');
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
public close(): Promise<void> {
|
|
90
|
-
this.closed = true;
|
|
91
|
-
|
|
92
|
-
return this.channel.close();
|
|
93
|
-
}
|
|
94
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import {ChannelListener, DuplexChannel, MessageDeliveryError} from './channel';
|
|
2
|
-
|
|
3
|
-
export class SandboxChannel<I, O> implements DuplexChannel<I, O> {
|
|
4
|
-
private readonly listeners: Array<ChannelListener<I>> = [];
|
|
5
|
-
|
|
6
|
-
public readonly messages: O[] = [];
|
|
7
|
-
|
|
8
|
-
private closed = false;
|
|
9
|
-
|
|
10
|
-
public publish(message: O): Promise<void> {
|
|
11
|
-
if (this.closed) {
|
|
12
|
-
return Promise.reject(MessageDeliveryError.nonRetryable('Channel is closed.'));
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
this.messages.push(message);
|
|
16
|
-
|
|
17
|
-
return Promise.resolve();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
public notify(message: I): void {
|
|
21
|
-
this.listeners.forEach(dispatch => dispatch(message));
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
public subscribe(listener: ChannelListener<I>): void {
|
|
25
|
-
if (!this.listeners.includes(listener)) {
|
|
26
|
-
this.listeners.push(listener);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public unsubscribe(listener: ChannelListener<I>): void {
|
|
31
|
-
const index = this.listeners.indexOf(listener);
|
|
32
|
-
|
|
33
|
-
if (index >= 0) {
|
|
34
|
-
this.listeners.splice(index, 1);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
public close(): Promise<void> {
|
|
39
|
-
this.closed = true;
|
|
40
|
-
|
|
41
|
-
return Promise.resolve();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
public isClosed(): boolean {
|
|
45
|
-
return this.closed;
|
|
46
|
-
}
|
|
47
|
-
}
|
package/src/cid/assigner.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import {Logger, NullLogger} from '../logging';
|
|
2
|
-
import {Cache} from '../cache';
|
|
3
|
-
import {CidAssigner} from './assigner';
|
|
4
|
-
|
|
5
|
-
type CachedAssignerOptions = {
|
|
6
|
-
logger?: Logger,
|
|
7
|
-
mirror?: boolean,
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export class CachedAssigner implements CidAssigner {
|
|
11
|
-
private readonly assigner: CidAssigner;
|
|
12
|
-
|
|
13
|
-
private readonly cache: Cache;
|
|
14
|
-
|
|
15
|
-
private readonly options: Required<CachedAssignerOptions>;
|
|
16
|
-
|
|
17
|
-
public constructor(assigner: CidAssigner, cache: Cache, options: CachedAssignerOptions = {}) {
|
|
18
|
-
this.assigner = assigner;
|
|
19
|
-
this.cache = cache;
|
|
20
|
-
this.options = {
|
|
21
|
-
logger: options.logger ?? new NullLogger(),
|
|
22
|
-
mirror: options.mirror ?? false,
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public async assignCid(currentCid?: string): Promise<string> {
|
|
27
|
-
const cachedCid = this.cache.get();
|
|
28
|
-
const previousCid = currentCid ?? cachedCid ?? null;
|
|
29
|
-
const {logger, mirror} = this.options;
|
|
30
|
-
|
|
31
|
-
if (previousCid === null) {
|
|
32
|
-
const newCid = await this.assigner.assignCid();
|
|
33
|
-
|
|
34
|
-
this.cache.put(newCid);
|
|
35
|
-
|
|
36
|
-
logger.debug('New CID stored into cache');
|
|
37
|
-
|
|
38
|
-
return newCid;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
logger.debug('Using existing CID');
|
|
42
|
-
|
|
43
|
-
if (cachedCid !== previousCid) {
|
|
44
|
-
logger.debug('The cached CID is stale, updating cache...');
|
|
45
|
-
|
|
46
|
-
this.cache.put(previousCid);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (mirror) {
|
|
50
|
-
logger.debug('Mirroring CID');
|
|
51
|
-
|
|
52
|
-
this.assigner
|
|
53
|
-
.assignCid(previousCid)
|
|
54
|
-
.then(newCid => {
|
|
55
|
-
if (newCid !== previousCid) {
|
|
56
|
-
logger.warn('The CID has changed, updating cache...');
|
|
57
|
-
|
|
58
|
-
this.cache.put(newCid);
|
|
59
|
-
}
|
|
60
|
-
})
|
|
61
|
-
.catch(() => {
|
|
62
|
-
logger.error('Failed to mirror CID');
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return previousCid;
|
|
67
|
-
}
|
|
68
|
-
}
|