@snap/camera-kit 0.7.0
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/LICENSE.md +6247 -0
- package/README.md +166 -0
- package/docs/html/.nojekyll +1 -0
- package/docs/html/assets/highlight.css +106 -0
- package/docs/html/assets/main.js +54 -0
- package/docs/html/assets/search.js +1 -0
- package/docs/html/assets/style.css +1225 -0
- package/docs/html/assets/widgets.png +0 -0
- package/docs/html/assets/widgets@2x.png +0 -0
- package/docs/html/classes/CameraKit.html +121 -0
- package/docs/html/classes/CameraKitSession.html +347 -0
- package/docs/html/classes/CameraKitSource.html +152 -0
- package/docs/html/classes/LensPerformanceMeasurement.html +115 -0
- package/docs/html/classes/LensPerformanceMetrics.html +76 -0
- package/docs/html/classes/LensRepository.html +171 -0
- package/docs/html/classes/LensSources.html +82 -0
- package/docs/html/classes/Transform2D.html +99 -0
- package/docs/html/classes/TypedCustomEvent.html +109 -0
- package/docs/html/classes/TypedEventTarget.html +146 -0
- package/docs/html/functions/Injectable.html +193 -0
- package/docs/html/functions/bootstrapCameraKit.html +158 -0
- package/docs/html/functions/createExtension.html +127 -0
- package/docs/html/functions/createImageSource.html +123 -0
- package/docs/html/functions/createMediaStreamSource.html +123 -0
- package/docs/html/functions/createUserMediaSource.html +127 -0
- package/docs/html/functions/createVideoSource.html +124 -0
- package/docs/html/functions/estimateLensPerformance.html +116 -0
- package/docs/html/functions/getRequiredBootstrapURLs.html +124 -0
- package/docs/html/functions/lensSourcesFactory.html +116 -0
- package/docs/html/functions/uriHandlersFactory.html +118 -0
- package/docs/html/index.html +208 -0
- package/docs/html/interfaces/CameraKitBootstrapConfiguration.html +132 -0
- package/docs/html/interfaces/CameraKitSourceSubscriber.html +121 -0
- package/docs/html/interfaces/ComputedFrameMetrics.html +70 -0
- package/docs/html/interfaces/CreateSessionOptions.html +77 -0
- package/docs/html/interfaces/EstimatedLensPerformance.html +78 -0
- package/docs/html/interfaces/Lens.html +115 -0
- package/docs/html/interfaces/LensSource.html +113 -0
- package/docs/html/interfaces/MediaStreamSourceOptions.html +65 -0
- package/docs/html/interfaces/UriCancelRequest.html +65 -0
- package/docs/html/interfaces/UriHandler.html +128 -0
- package/docs/html/interfaces/UriRequest.html +80 -0
- package/docs/html/interfaces/UriResponse.html +80 -0
- package/docs/html/interfaces/VideoSourceOptions.html +60 -0
- package/docs/html/modules.html +198 -0
- package/docs/html/types/AssetLoader.html +126 -0
- package/docs/html/types/AssetTiming.html +116 -0
- package/docs/html/types/BenchmarkError.html +107 -0
- package/docs/html/types/BootstrapError.html +110 -0
- package/docs/html/types/CacheKeyNotFoundError.html +107 -0
- package/docs/html/types/CameraKitDeviceInfo.html +114 -0
- package/docs/html/types/CameraKitSessionEventListener.html +109 -0
- package/docs/html/types/CameraKitSessionEvents.html +118 -0
- package/docs/html/types/CameraKitSourceError.html +107 -0
- package/docs/html/types/CameraKitSourceInfo.html +107 -0
- package/docs/html/types/CameraKitSourceOptions.html +113 -0
- package/docs/html/types/ConfigurationError.html +109 -0
- package/docs/html/types/Keyboard.html +196 -0
- package/docs/html/types/KeyboardEvents.html +109 -0
- package/docs/html/types/LegalError.html +107 -0
- package/docs/html/types/LensAssetError.html +109 -0
- package/docs/html/types/LensContentValidationError.html +107 -0
- package/docs/html/types/LensError.html +107 -0
- package/docs/html/types/LensExecutionError.html +114 -0
- package/docs/html/types/LensImagePickerError.html +110 -0
- package/docs/html/types/LensLaunchParams.html +109 -0
- package/docs/html/types/LensMetricsEvents.html +110 -0
- package/docs/html/types/LensPerformanceCluster.html +107 -0
- package/docs/html/types/LensView.html +119 -0
- package/docs/html/types/LensWait.html +111 -0
- package/docs/html/types/PersistentStoreError.html +109 -0
- package/docs/html/types/PlatformNotSupportedError.html +110 -0
- package/docs/html/types/PublicContainer.html +110 -0
- package/docs/html/types/RenderTarget.html +111 -0
- package/docs/html/types/Uri.html +107 -0
- package/docs/html/types/UriHandlers.html +109 -0
- package/docs/html/types/WebGLError.html +107 -0
- package/docs/html/variables/extensionRequestContext.html +109 -0
- package/docs/md/.nojekyll +1 -0
- package/docs/md/README.md +168 -0
- package/docs/md/classes/CameraKit.md +94 -0
- package/docs/md/classes/CameraKitSession.md +359 -0
- package/docs/md/classes/CameraKitSource.md +110 -0
- package/docs/md/classes/LensPerformanceMeasurement.md +77 -0
- package/docs/md/classes/LensPerformanceMetrics.md +37 -0
- package/docs/md/classes/LensRepository.md +145 -0
- package/docs/md/classes/LensSources.md +29 -0
- package/docs/md/classes/Transform2D.md +55 -0
- package/docs/md/classes/TypedCustomEvent.md +65 -0
- package/docs/md/classes/TypedEventTarget.md +103 -0
- package/docs/md/interfaces/CameraKitBootstrapConfiguration.md +106 -0
- package/docs/md/interfaces/CameraKitSourceSubscriber.md +55 -0
- package/docs/md/interfaces/ComputedFrameMetrics.md +29 -0
- package/docs/md/interfaces/CreateSessionOptions.md +35 -0
- package/docs/md/interfaces/EstimatedLensPerformance.md +38 -0
- package/docs/md/interfaces/Lens.md +84 -0
- package/docs/md/interfaces/LensSource.md +68 -0
- package/docs/md/interfaces/MediaStreamSourceOptions.md +22 -0
- package/docs/md/interfaces/UriCancelRequest.md +22 -0
- package/docs/md/interfaces/UriHandler.md +63 -0
- package/docs/md/interfaces/UriRequest.md +43 -0
- package/docs/md/interfaces/UriResponse.md +43 -0
- package/docs/md/interfaces/VideoSourceOptions.md +15 -0
- package/docs/md/modules.md +827 -0
- package/lib/CameraKit.d.ts +170 -0
- package/lib/CameraKit.js +145 -0
- package/lib/CameraKit.js.map +1 -0
- package/lib/__tests__/data.d.ts +9 -0
- package/lib/__tests__/data.js +50 -0
- package/lib/__tests__/data.js.map +1 -0
- package/lib/__tests__/deferred.d.ts +16 -0
- package/lib/__tests__/deferred.js +29 -0
- package/lib/__tests__/deferred.js.map +1 -0
- package/lib/__tests__/jest.matchers.d.ts +17 -0
- package/lib/__tests__/jest.matchers.js +67 -0
- package/lib/__tests__/jest.matchers.js.map +1 -0
- package/lib/assertPlatformSupported.d.ts +4 -0
- package/lib/assertPlatformSupported.js +10 -0
- package/lib/assertPlatformSupported.js.map +1 -0
- package/lib/benchmark/benchmarkGflops.d.ts +16 -0
- package/lib/benchmark/benchmarkGflops.js +129 -0
- package/lib/benchmark/benchmarkGflops.js.map +1 -0
- package/lib/benchmark/estimateLensPerformanceCluster.d.ts +33 -0
- package/lib/benchmark/estimateLensPerformanceCluster.js +48 -0
- package/lib/benchmark/estimateLensPerformanceCluster.js.map +1 -0
- package/lib/benchmark/webglUtils.d.ts +7 -0
- package/lib/benchmark/webglUtils.js +87 -0
- package/lib/benchmark/webglUtils.js.map +1 -0
- package/lib/bootstrapCameraKit.d.ts +96 -0
- package/lib/bootstrapCameraKit.js +204 -0
- package/lib/bootstrapCameraKit.js.map +1 -0
- package/lib/common/__mocks__/loadScript.d.ts +1 -0
- package/lib/common/__mocks__/loadScript.js +10 -0
- package/lib/common/__mocks__/loadScript.js.map +1 -0
- package/lib/common/assertions.d.ts +27 -0
- package/lib/common/assertions.js +39 -0
- package/lib/common/assertions.js.map +1 -0
- package/lib/common/cameraKitUserAgent.d.ts +34 -0
- package/lib/common/cameraKitUserAgent.js +216 -0
- package/lib/common/cameraKitUserAgent.js.map +1 -0
- package/lib/common/copyDefinedProperties.d.ts +13 -0
- package/lib/common/copyDefinedProperties.js +16 -0
- package/lib/common/copyDefinedProperties.js.map +1 -0
- package/lib/common/entries.d.ts +3 -0
- package/lib/common/entries.js +3 -0
- package/lib/common/entries.js.map +1 -0
- package/lib/common/errorHelpers.d.ts +10 -0
- package/lib/common/errorHelpers.js +24 -0
- package/lib/common/errorHelpers.js.map +1 -0
- package/lib/common/getFilename.d.ts +1 -0
- package/lib/common/getFilename.js +4 -0
- package/lib/common/getFilename.js.map +1 -0
- package/lib/common/index.d.ts +2 -0
- package/lib/common/index.js +3 -0
- package/lib/common/index.js.map +1 -0
- package/lib/common/loadScript.d.ts +1 -0
- package/lib/common/loadScript.js +11 -0
- package/lib/common/loadScript.js.map +1 -0
- package/lib/common/locale.d.ts +2 -0
- package/lib/common/locale.js +11 -0
- package/lib/common/locale.js.map +1 -0
- package/lib/common/localization.d.ts +43 -0
- package/lib/common/localization.js +43 -0
- package/lib/common/localization.js.map +1 -0
- package/lib/common/memoize.d.ts +8 -0
- package/lib/common/memoize.js +15 -0
- package/lib/common/memoize.js.map +1 -0
- package/lib/common/pageVisibility.d.ts +20 -0
- package/lib/common/pageVisibility.js +62 -0
- package/lib/common/pageVisibility.js.map +1 -0
- package/lib/common/time.d.ts +1 -0
- package/lib/common/time.js +2 -0
- package/lib/common/time.js.map +1 -0
- package/lib/common/typeguards.d.ts +53 -0
- package/lib/common/typeguards.js +92 -0
- package/lib/common/typeguards.js.map +1 -0
- package/lib/common/types.d.ts +10 -0
- package/lib/common/types.js +2 -0
- package/lib/common/types.js.map +1 -0
- package/lib/common/validate.d.ts +14 -0
- package/lib/common/validate.js +104 -0
- package/lib/common/validate.js.map +1 -0
- package/lib/configuration.d.ts +92 -0
- package/lib/configuration.js +36 -0
- package/lib/configuration.js.map +1 -0
- package/lib/configurationOverrides.d.ts +12 -0
- package/lib/configurationOverrides.js +41 -0
- package/lib/configurationOverrides.js.map +1 -0
- package/lib/dependency-injection/Container.d.ts +177 -0
- package/lib/dependency-injection/Container.js +160 -0
- package/lib/dependency-injection/Container.js.map +1 -0
- package/lib/dependency-injection/Injectable.d.ts +39 -0
- package/lib/dependency-injection/Injectable.js +18 -0
- package/lib/dependency-injection/Injectable.js.map +1 -0
- package/lib/dependency-injection/PartialContainer.d.ts +81 -0
- package/lib/dependency-injection/PartialContainer.js +85 -0
- package/lib/dependency-injection/PartialContainer.js.map +1 -0
- package/lib/dependency-injection/RootServices.d.ts +62 -0
- package/lib/dependency-injection/RootServices.js +2 -0
- package/lib/dependency-injection/RootServices.js.map +1 -0
- package/lib/dependency-injection/types.d.ts +56 -0
- package/lib/dependency-injection/types.js +2 -0
- package/lib/dependency-injection/types.js.map +1 -0
- package/lib/environment.json +1 -0
- package/lib/events/TypedCustomEvent.d.ts +10 -0
- package/lib/events/TypedCustomEvent.js +11 -0
- package/lib/events/TypedCustomEvent.js.map +1 -0
- package/lib/events/TypedEventTarget.d.ts +25 -0
- package/lib/events/TypedEventTarget.js +57 -0
- package/lib/events/TypedEventTarget.js.map +1 -0
- package/lib/events/scan.d.ts +15 -0
- package/lib/events/scan.js +46 -0
- package/lib/events/scan.js.map +1 -0
- package/lib/extensions/LensSources.d.ts +58 -0
- package/lib/extensions/LensSources.js +50 -0
- package/lib/extensions/LensSources.js.map +1 -0
- package/lib/extensions/UriHandlers.d.ts +54 -0
- package/lib/extensions/UriHandlers.js +93 -0
- package/lib/extensions/UriHandlers.js.map +1 -0
- package/lib/extensions/extensionRequestContext.d.ts +4 -0
- package/lib/extensions/extensionRequestContext.js +14 -0
- package/lib/extensions/extensionRequestContext.js.map +1 -0
- package/lib/generated-proto/blizzard/cameraKitEvents.d.ts +5603 -0
- package/lib/generated-proto/blizzard/cameraKitEvents.js +522 -0
- package/lib/generated-proto/blizzard/cameraKitEvents.js.map +1 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.d.ts +98 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.js +260 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.js.map +1 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/export.d.ts +543 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/export.js +429 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/export.js.map +1 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.d.ts +100 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.js +164 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.js.map +1 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/lens.d.ts +395 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/lens.js +644 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/lens.js.map +1 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.d.ts +185 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.js +172 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.js.map +1 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.d.ts +86 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.js +234 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.js.map +1 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/service.d.ts +854 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/service.js +629 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/service.js.map +1 -0
- package/lib/generated-proto/pb_schema/cdp/cof/benchmark.d.ts +86 -0
- package/lib/generated-proto/pb_schema/cdp/cof/benchmark.js +185 -0
- package/lib/generated-proto/pb_schema/cdp/cof/benchmark.js.map +1 -0
- package/lib/generated-proto/pb_schema/cdp/cof/benchmark_name.d.ts +95 -0
- package/lib/generated-proto/pb_schema/cdp/cof/benchmark_name.js +104 -0
- package/lib/generated-proto/pb_schema/cdp/cof/benchmark_name.js.map +1 -0
- package/lib/generated-proto/pb_schema/cdp/cof/circumstance_service.d.ts +10212 -0
- package/lib/generated-proto/pb_schema/cdp/cof/circumstance_service.js +1300 -0
- package/lib/generated-proto/pb_schema/cdp/cof/circumstance_service.js.map +1 -0
- package/lib/generated-proto/pb_schema/cdp/cof/config_request.d.ts +401 -0
- package/lib/generated-proto/pb_schema/cdp/cof/config_request.js +525 -0
- package/lib/generated-proto/pb_schema/cdp/cof/config_request.js.map +1 -0
- package/lib/generated-proto/pb_schema/cdp/cof/config_response.d.ts +1287 -0
- package/lib/generated-proto/pb_schema/cdp/cof/config_response.js +135 -0
- package/lib/generated-proto/pb_schema/cdp/cof/config_response.js.map +1 -0
- package/lib/generated-proto/pb_schema/cdp/cof/config_result.d.ts +4208 -0
- package/lib/generated-proto/pb_schema/cdp/cof/config_result.js +1053 -0
- package/lib/generated-proto/pb_schema/cdp/cof/config_result.js.map +1 -0
- package/lib/generated-proto/pb_schema/cdp/cof/debug_info.d.ts +102 -0
- package/lib/generated-proto/pb_schema/cdp/cof/debug_info.js +165 -0
- package/lib/generated-proto/pb_schema/cdp/cof/debug_info.js.map +1 -0
- package/lib/generated-proto/pb_schema/cdp/cof/namespace.d.ts +8 -0
- package/lib/generated-proto/pb_schema/cdp/cof/namespace.js +17 -0
- package/lib/generated-proto/pb_schema/cdp/cof/namespace.js.map +1 -0
- package/lib/generated-proto/pb_schema/common/ruid.d.ts +75 -0
- package/lib/generated-proto/pb_schema/common/ruid.js +96 -0
- package/lib/generated-proto/pb_schema/common/ruid.js.map +1 -0
- package/lib/generated-proto/pb_schema/common/value.d.ts +131 -0
- package/lib/generated-proto/pb_schema/common/value.js +204 -0
- package/lib/generated-proto/pb_schema/common/value.js.map +1 -0
- package/lib/generated-proto/pb_schema/google/api/annotations.d.ts +1 -0
- package/lib/generated-proto/pb_schema/google/api/annotations.js +9 -0
- package/lib/generated-proto/pb_schema/google/api/annotations.js.map +1 -0
- package/lib/generated-proto/pb_schema/google/api/http.d.ts +3636 -0
- package/lib/generated-proto/pb_schema/google/api/http.js +271 -0
- package/lib/generated-proto/pb_schema/google/api/http.js.map +1 -0
- package/lib/generated-proto/pb_schema/google/protobuf/any.d.ts +139 -0
- package/lib/generated-proto/pb_schema/google/protobuf/any.js +94 -0
- package/lib/generated-proto/pb_schema/google/protobuf/any.js.map +1 -0
- package/lib/generated-proto/pb_schema/google/protobuf/descriptor.d.ts +50968 -0
- package/lib/generated-proto/pb_schema/google/protobuf/descriptor.js +2962 -0
- package/lib/generated-proto/pb_schema/google/protobuf/descriptor.js.map +1 -0
- package/lib/generated-proto/pb_schema/google/protobuf/timestamp.d.ts +98 -0
- package/lib/generated-proto/pb_schema/google/protobuf/timestamp.js +82 -0
- package/lib/generated-proto/pb_schema/google/protobuf/timestamp.js.map +1 -0
- package/lib/generated-proto/pb_schema/google/protobuf/wrappers.d.ts +173 -0
- package/lib/generated-proto/pb_schema/google/protobuf/wrappers.js +332 -0
- package/lib/generated-proto/pb_schema/google/protobuf/wrappers.js.map +1 -0
- package/lib/generated-proto/pb_schema/lenses/geocircle.d.ts +42 -0
- package/lib/generated-proto/pb_schema/lenses/geocircle.js +52 -0
- package/lib/generated-proto/pb_schema/lenses/geocircle.js.map +1 -0
- package/lib/generated-proto/pb_schema/lenses/geopoint.d.ts +32 -0
- package/lib/generated-proto/pb_schema/lenses/geopoint.js +50 -0
- package/lib/generated-proto/pb_schema/lenses/geopoint.js.map +1 -0
- package/lib/generated-proto/pb_schema/lenses/launch_params.d.ts +29 -0
- package/lib/generated-proto/pb_schema/lenses/launch_params.js +43 -0
- package/lib/generated-proto/pb_schema/lenses/launch_params.js.map +1 -0
- package/lib/generated-proto/pb_schema/lenses/launchdata.d.ts +365 -0
- package/lib/generated-proto/pb_schema/lenses/launchdata.js +216 -0
- package/lib/generated-proto/pb_schema/lenses/launchdata.js.map +1 -0
- package/lib/generated-proto/pb_schema/lenses/lures.d.ts +113 -0
- package/lib/generated-proto/pb_schema/lenses/lures.js +64 -0
- package/lib/generated-proto/pb_schema/lenses/lures.js.map +1 -0
- package/lib/generated-proto/pb_schema/lenses/persistent_store.d.ts +29 -0
- package/lib/generated-proto/pb_schema/lenses/persistent_store.js +43 -0
- package/lib/generated-proto/pb_schema/lenses/persistent_store.js.map +1 -0
- package/lib/generated-proto/pb_schema/lenses/snappable.d.ts +921 -0
- package/lib/generated-proto/pb_schema/lenses/snappable.js +954 -0
- package/lib/generated-proto/pb_schema/lenses/snappable.js.map +1 -0
- package/lib/generated-proto/pb_schema/lenses/user_data.d.ts +247 -0
- package/lib/generated-proto/pb_schema/lenses/user_data.js +362 -0
- package/lib/generated-proto/pb_schema/lenses/user_data.js.map +1 -0
- package/lib/handlers/HandlerChainBuilder.d.ts +95 -0
- package/lib/handlers/HandlerChainBuilder.js +187 -0
- package/lib/handlers/HandlerChainBuilder.js.map +1 -0
- package/lib/handlers/arrayBufferParsingHandler.d.ts +10 -0
- package/lib/handlers/arrayBufferParsingHandler.js +18 -0
- package/lib/handlers/arrayBufferParsingHandler.js.map +1 -0
- package/lib/handlers/batchingHandler.d.ts +25 -0
- package/lib/handlers/batchingHandler.js +79 -0
- package/lib/handlers/batchingHandler.js.map +1 -0
- package/lib/handlers/cameraKitServiceFetchHandlerFactory.d.ts +12 -0
- package/lib/handlers/cameraKitServiceFetchHandlerFactory.js +19 -0
- package/lib/handlers/cameraKitServiceFetchHandlerFactory.js.map +1 -0
- package/lib/handlers/debugHandler.d.ts +8 -0
- package/lib/handlers/debugHandler.js +27 -0
- package/lib/handlers/debugHandler.js.map +1 -0
- package/lib/handlers/defaultFetchHandler.d.ts +15 -0
- package/lib/handlers/defaultFetchHandler.js +29 -0
- package/lib/handlers/defaultFetchHandler.js.map +1 -0
- package/lib/handlers/headersModifyingFetchHandler.d.ts +8 -0
- package/lib/handlers/headersModifyingFetchHandler.js +13 -0
- package/lib/handlers/headersModifyingFetchHandler.js.map +1 -0
- package/lib/handlers/index.d.ts +2 -0
- package/lib/handlers/index.js +3 -0
- package/lib/handlers/index.js.map +1 -0
- package/lib/handlers/mappingHandler.d.ts +15 -0
- package/lib/handlers/mappingHandler.js +65 -0
- package/lib/handlers/mappingHandler.js.map +1 -0
- package/lib/handlers/noCorsRetryingFetchHandler.d.ts +48 -0
- package/lib/handlers/noCorsRetryingFetchHandler.js +94 -0
- package/lib/handlers/noCorsRetryingFetchHandler.js.map +1 -0
- package/lib/handlers/persistingHandler.d.ts +14 -0
- package/lib/handlers/persistingHandler.js +71 -0
- package/lib/handlers/persistingHandler.js.map +1 -0
- package/lib/handlers/rateLimitingHandler.d.ts +20 -0
- package/lib/handlers/rateLimitingHandler.js +43 -0
- package/lib/handlers/rateLimitingHandler.js.map +1 -0
- package/lib/handlers/requestStateEmittingHandler.d.ts +29 -0
- package/lib/handlers/requestStateEmittingHandler.js +43 -0
- package/lib/handlers/requestStateEmittingHandler.js.map +1 -0
- package/lib/handlers/responseCachingHandler.d.ts +27 -0
- package/lib/handlers/responseCachingHandler.js +94 -0
- package/lib/handlers/responseCachingHandler.js.map +1 -0
- package/lib/handlers/retryingHandler.d.ts +37 -0
- package/lib/handlers/retryingHandler.js +73 -0
- package/lib/handlers/retryingHandler.js.map +1 -0
- package/lib/handlers/timeoutHandler.d.ts +18 -0
- package/lib/handlers/timeoutHandler.js +30 -0
- package/lib/handlers/timeoutHandler.js.map +1 -0
- package/lib/index.d.ts +33 -0
- package/lib/index.js +32 -0
- package/lib/index.js.map +1 -0
- package/lib/legal/legalPrompt.d.ts +17 -0
- package/lib/legal/legalPrompt.js +144 -0
- package/lib/legal/legalPrompt.js.map +1 -0
- package/lib/legal/legalState.d.ts +50 -0
- package/lib/legal/legalState.js +149 -0
- package/lib/legal/legalState.js.map +1 -0
- package/lib/lens/Lens.d.ts +71 -0
- package/lib/lens/Lens.js +63 -0
- package/lib/lens/Lens.js.map +1 -0
- package/lib/lens/LensLaunchParams.d.ts +19 -0
- package/lib/lens/LensLaunchParams.js +38 -0
- package/lib/lens/LensLaunchParams.js.map +1 -0
- package/lib/lens/LensPersistenceStore.d.ts +7 -0
- package/lib/lens/LensPersistenceStore.js +20 -0
- package/lib/lens/LensPersistenceStore.js.map +1 -0
- package/lib/lens/LensRepository.d.ts +134 -0
- package/lib/lens/LensRepository.js +239 -0
- package/lib/lens/LensRepository.js.map +1 -0
- package/lib/lens/assets/LensAssetRepository.d.ts +66 -0
- package/lib/lens/assets/LensAssetRepository.js +179 -0
- package/lib/lens/assets/LensAssetRepository.js.map +1 -0
- package/lib/lens/assets/LensAssetsProvider.d.ts +21 -0
- package/lib/lens/assets/LensAssetsProvider.js +41 -0
- package/lib/lens/assets/LensAssetsProvider.js.map +1 -0
- package/lib/lens/assets/deviceDependentAssetLoader.d.ts +11 -0
- package/lib/lens/assets/deviceDependentAssetLoader.js +58 -0
- package/lib/lens/assets/deviceDependentAssetLoader.js.map +1 -0
- package/lib/lens/assets/remoteMediaAssetLoaderFactory.d.ts +10 -0
- package/lib/lens/assets/remoteMediaAssetLoaderFactory.js +26 -0
- package/lib/lens/assets/remoteMediaAssetLoaderFactory.js.map +1 -0
- package/lib/lens/assets/staticAssetLoader.d.ts +10 -0
- package/lib/lens/assets/staticAssetLoader.js +24 -0
- package/lib/lens/assets/staticAssetLoader.js.map +1 -0
- package/lib/lens/index.d.ts +7 -0
- package/lib/lens/index.js +7 -0
- package/lib/lens/index.js.map +1 -0
- package/lib/lens/lensEnvelopeUtil.d.ts +5 -0
- package/lib/lens/lensEnvelopeUtil.js +19 -0
- package/lib/lens/lensEnvelopeUtil.js.map +1 -0
- package/lib/lens/lensHttpUtil.d.ts +4 -0
- package/lib/lens/lensHttpUtil.js +30 -0
- package/lib/lens/lensHttpUtil.js.map +1 -0
- package/lib/lens-client-interface/exif.d.ts +20 -0
- package/lib/lens-client-interface/exif.js +61 -0
- package/lib/lens-client-interface/exif.js.map +1 -0
- package/lib/lens-client-interface/imagePicker.d.ts +7 -0
- package/lib/lens-client-interface/imagePicker.js +128 -0
- package/lib/lens-client-interface/imagePicker.js.map +1 -0
- package/lib/lens-client-interface/lensClientInterface.d.ts +13 -0
- package/lib/lens-client-interface/lensClientInterface.js +30 -0
- package/lib/lens-client-interface/lensClientInterface.js.map +1 -0
- package/lib/lens-core-module/generated-types.d.ts +426 -0
- package/lib/lens-core-module/generated-types.js +2 -0
- package/lib/lens-core-module/generated-types.js.map +1 -0
- package/lib/lens-core-module/index.d.ts +2 -0
- package/lib/lens-core-module/index.js +3 -0
- package/lib/lens-core-module/index.js.map +1 -0
- package/lib/lens-core-module/loader/index.d.ts +1 -0
- package/lib/lens-core-module/loader/index.js +2 -0
- package/lib/lens-core-module/loader/index.js.map +1 -0
- package/lib/lens-core-module/loader/lensCoreFactory.d.ts +30 -0
- package/lib/lens-core-module/loader/lensCoreFactory.js +121 -0
- package/lib/lens-core-module/loader/lensCoreFactory.js.map +1 -0
- package/lib/lensCoreWasmVersions.json +5 -0
- package/lib/logger/errorLoggingDecorator.d.ts +9 -0
- package/lib/logger/errorLoggingDecorator.js +32 -0
- package/lib/logger/errorLoggingDecorator.js.map +1 -0
- package/lib/logger/logEntries.d.ts +15 -0
- package/lib/logger/logEntries.js +14 -0
- package/lib/logger/logEntries.js.map +1 -0
- package/lib/logger/logger.d.ts +35 -0
- package/lib/logger/logger.js +48 -0
- package/lib/logger/logger.js.map +1 -0
- package/lib/logger/registerLogEntriesSubscriber.d.ts +14 -0
- package/lib/logger/registerLogEntriesSubscriber.js +23 -0
- package/lib/logger/registerLogEntriesSubscriber.js.map +1 -0
- package/lib/media-sources/CameraKitSource.d.ts +88 -0
- package/lib/media-sources/CameraKitSource.js +140 -0
- package/lib/media-sources/CameraKitSource.js.map +1 -0
- package/lib/media-sources/FunctionSource.d.ts +30 -0
- package/lib/media-sources/FunctionSource.js +132 -0
- package/lib/media-sources/FunctionSource.js.map +1 -0
- package/lib/media-sources/ImageSource.d.ts +13 -0
- package/lib/media-sources/ImageSource.js +28 -0
- package/lib/media-sources/ImageSource.js.map +1 -0
- package/lib/media-sources/MediaStreamSource.d.ts +41 -0
- package/lib/media-sources/MediaStreamSource.js +146 -0
- package/lib/media-sources/MediaStreamSource.js.map +1 -0
- package/lib/media-sources/VideoSource.d.ts +21 -0
- package/lib/media-sources/VideoSource.js +38 -0
- package/lib/media-sources/VideoSource.js.map +1 -0
- package/lib/metrics/businessEventsReporter.d.ts +37 -0
- package/lib/metrics/businessEventsReporter.js +160 -0
- package/lib/metrics/businessEventsReporter.js.map +1 -0
- package/lib/metrics/metricsEventTarget.d.ts +41 -0
- package/lib/metrics/metricsEventTarget.js +11 -0
- package/lib/metrics/metricsEventTarget.js.map +1 -0
- package/lib/metrics/metricsHandler.d.ts +9 -0
- package/lib/metrics/metricsHandler.js +13 -0
- package/lib/metrics/metricsHandler.js.map +1 -0
- package/lib/metrics/operationalMetricsReporter.d.ts +52 -0
- package/lib/metrics/operationalMetricsReporter.js +108 -0
- package/lib/metrics/operationalMetricsReporter.js.map +1 -0
- package/lib/metrics/reporters/reportBenchmarks.d.ts +10 -0
- package/lib/metrics/reporters/reportBenchmarks.js +29 -0
- package/lib/metrics/reporters/reportBenchmarks.js.map +1 -0
- package/lib/metrics/reporters/reportGlobalException.d.ts +19 -0
- package/lib/metrics/reporters/reportGlobalException.js +68 -0
- package/lib/metrics/reporters/reportGlobalException.js.map +1 -0
- package/lib/metrics/reporters/reportHttpMetrics.d.ts +17 -0
- package/lib/metrics/reporters/reportHttpMetrics.js +92 -0
- package/lib/metrics/reporters/reportHttpMetrics.js.map +1 -0
- package/lib/metrics/reporters/reportLegalState.d.ts +15 -0
- package/lib/metrics/reporters/reportLegalState.js +34 -0
- package/lib/metrics/reporters/reportLegalState.js.map +1 -0
- package/lib/metrics/reporters/reportLensAndAssetDownload.d.ts +38 -0
- package/lib/metrics/reporters/reportLensAndAssetDownload.js +88 -0
- package/lib/metrics/reporters/reportLensAndAssetDownload.js.map +1 -0
- package/lib/metrics/reporters/reportLensValidationFailed.d.ts +20 -0
- package/lib/metrics/reporters/reportLensValidationFailed.js +24 -0
- package/lib/metrics/reporters/reportLensValidationFailed.js.map +1 -0
- package/lib/metrics/reporters/reportLensView.d.ts +36 -0
- package/lib/metrics/reporters/reportLensView.js +101 -0
- package/lib/metrics/reporters/reportLensView.js.map +1 -0
- package/lib/metrics/reporters/reportLensWait.d.ts +33 -0
- package/lib/metrics/reporters/reportLensWait.js +56 -0
- package/lib/metrics/reporters/reportLensWait.js.map +1 -0
- package/lib/metrics/reporters/reportSessionException.d.ts +17 -0
- package/lib/metrics/reporters/reportSessionException.js +12 -0
- package/lib/metrics/reporters/reportSessionException.js.map +1 -0
- package/lib/metrics/reporters/reportUserSession.d.ts +14 -0
- package/lib/metrics/reporters/reportUserSession.js +67 -0
- package/lib/metrics/reporters/reportUserSession.js.map +1 -0
- package/lib/metrics/reporters/reporters.d.ts +44 -0
- package/lib/metrics/reporters/reporters.js +33 -0
- package/lib/metrics/reporters/reporters.js.map +1 -0
- package/lib/namedErrors.d.ts +107 -0
- package/lib/namedErrors.js +56 -0
- package/lib/namedErrors.js.map +1 -0
- package/lib/persistence/ExpiringPersistence.d.ts +20 -0
- package/lib/persistence/ExpiringPersistence.js +58 -0
- package/lib/persistence/ExpiringPersistence.js.map +1 -0
- package/lib/persistence/IndexedDBPersistence.d.ts +47 -0
- package/lib/persistence/IndexedDBPersistence.js +180 -0
- package/lib/persistence/IndexedDBPersistence.js.map +1 -0
- package/lib/persistence/Persistence.d.ts +25 -0
- package/lib/persistence/Persistence.js +10 -0
- package/lib/persistence/Persistence.js.map +1 -0
- package/lib/remote-configuration/cofHandler.d.ts +21 -0
- package/lib/remote-configuration/cofHandler.js +75 -0
- package/lib/remote-configuration/cofHandler.js.map +1 -0
- package/lib/remote-configuration/remoteConfiguration.d.ts +13 -0
- package/lib/remote-configuration/remoteConfiguration.js +43 -0
- package/lib/remote-configuration/remoteConfiguration.js.map +1 -0
- package/lib/session/CameraKitSession.d.ts +252 -0
- package/lib/session/CameraKitSession.js +439 -0
- package/lib/session/CameraKitSession.js.map +1 -0
- package/lib/session/CameraKitSessionEvents.d.ts +33 -0
- package/lib/session/CameraKitSessionEvents.js +21 -0
- package/lib/session/CameraKitSessionEvents.js.map +1 -0
- package/lib/session/LensKeyboard.d.ts +89 -0
- package/lib/session/LensKeyboard.js +95 -0
- package/lib/session/LensKeyboard.js.map +1 -0
- package/lib/session/LensPerformanceMeasurement.d.ts +55 -0
- package/lib/session/LensPerformanceMeasurement.js +91 -0
- package/lib/session/LensPerformanceMeasurement.js.map +1 -0
- package/lib/session/LensPerformanceMetrics.d.ts +31 -0
- package/lib/session/LensPerformanceMetrics.js +58 -0
- package/lib/session/LensPerformanceMetrics.js.map +1 -0
- package/lib/session/index.d.ts +1 -0
- package/lib/session/index.js +2 -0
- package/lib/session/index.js.map +1 -0
- package/lib/session/lensState.d.ts +29 -0
- package/lib/session/lensState.js +160 -0
- package/lib/session/lensState.js.map +1 -0
- package/lib/session/sessionState.d.ts +10 -0
- package/lib/session/sessionState.js +12 -0
- package/lib/session/sessionState.js.map +1 -0
- package/lib/transforms/Transform2D.d.ts +17 -0
- package/lib/transforms/Transform2D.js +18 -0
- package/lib/transforms/Transform2D.js.map +1 -0
- package/lib/transforms/index.d.ts +1 -0
- package/lib/transforms/index.js +2 -0
- package/lib/transforms/index.js.map +1 -0
- package/package.json +62 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a Handler chain – a series of functions composed such that each function may call a supplied `next` function
|
|
3
|
+
* which passes execution down the chain. When the final Handler in the chain returns, execution passes back up the
|
|
4
|
+
* chain eventually returning to the caller.
|
|
5
|
+
*
|
|
6
|
+
* Each Handler chain begins with a "raw" Handler – this is a function which takes some request and returns some
|
|
7
|
+
* response. A chain is then created by supplying a series of mapping functions – the ChainableHandler type – which will
|
|
8
|
+
* be called with the `next` Handler in the chain.
|
|
9
|
+
*
|
|
10
|
+
* Ex:
|
|
11
|
+
* ```ts
|
|
12
|
+
* const handler = (request: string, metadata?: RequestMetadata) => Promise.resolve(`Responded to ${request}`)
|
|
13
|
+
* const chainable = (next: Handler<string, string>) => (request: string, metadata?: RequestMetadata) => {
|
|
14
|
+
* return next(`modified ${request}`, metadata)
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* const chain = new HandlerChainBuilder(handler)
|
|
18
|
+
* .map(chainable)
|
|
19
|
+
* .handler
|
|
20
|
+
*
|
|
21
|
+
* const response = await chain('hello')
|
|
22
|
+
* expect(response).toBe('Responded to modified hello; 0')
|
|
23
|
+
* ```
|
|
24
|
+
* You can largely ignore the `metadata` argument present in the above example. This is the mechanism by which an
|
|
25
|
+
* AbortSignal is passed to each Handler in the chain, but the only real requirement when implementing a Handler is
|
|
26
|
+
* to pass this argument along to the `next` function. In fact, many Handlers will want to be generic over the type
|
|
27
|
+
* of metadata:
|
|
28
|
+
* ```ts
|
|
29
|
+
* const chainable = <Meta>(next: Handler<string, string, Meta>) => (request: string, metadata: Meta) => {
|
|
30
|
+
* return next(`modified ${request}`, metadata)
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
* Actually, it's a very good idea for Handlers to be as generic as possible, since that will allow greater re-use. In
|
|
34
|
+
* the above example, we don't do anything with the response from `next`, so we can let that be generic, too:
|
|
35
|
+
* ```ts
|
|
36
|
+
* const chainable = <Res, Meta>(next: Handler<string, Res, Meta>) => (request: string, metadata: Meta) => {
|
|
37
|
+
* return next(`modified ${request}`, metadata)
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
* Now if some other Handler in the chain decides to return a different response type, our Handler won't require any
|
|
41
|
+
* changes to compile.
|
|
42
|
+
*
|
|
43
|
+
* ---
|
|
44
|
+
*
|
|
45
|
+
* Since execution passes from handler to handler in the chain, and then back, handlers have the opportunity to modify
|
|
46
|
+
* or observe both the request and response. This might be useful for implementing serialization/deserialization, but
|
|
47
|
+
* the simplest example that demonstrates this feature is measuring request latency:
|
|
48
|
+
* ```ts
|
|
49
|
+
* const latencyMeasuringHandler = <Req, Res, Meta>(next: Handler<Req, Res, Meta>) =>
|
|
50
|
+
* async (req: Req, metadata: Meta) => {
|
|
51
|
+
* const start = performance.now()
|
|
52
|
+
* const response = await next(req, metadata)
|
|
53
|
+
* const latency = performance.now() - start
|
|
54
|
+
* console.log(`latency for request ${request} was ${latency}`)
|
|
55
|
+
* return response
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
58
|
+
* Execution is first passed to our measuring handler, which marks the `start` timestamp. Then it passes execution on
|
|
59
|
+
* down the chain. After a response is received (by some handler down the chain), execution passes back up to our
|
|
60
|
+
* handler here, which records the amount of time spent inside `next`.
|
|
61
|
+
*
|
|
62
|
+
* ---
|
|
63
|
+
*
|
|
64
|
+
* Handlers may also abort requests. They can do this in two ways:
|
|
65
|
+
* 1. Create an `AbortController` and add its `AbortSignal` to the `metadata` object when calling `next`.
|
|
66
|
+
* 2. Resolve its returned Promise.
|
|
67
|
+
*
|
|
68
|
+
* The first approach is straightforward, but the second may benefit from an example – the simplest is a handler which
|
|
69
|
+
* will timeout a request:
|
|
70
|
+
* ```ts
|
|
71
|
+
* const timeoutHandler = <Req, Res, Meta>(next: Handler<Req, Res, Meta>) => (req: Req, metadata: Meta) => {
|
|
72
|
+
* return Promise.race([
|
|
73
|
+
* next(req, metadata),
|
|
74
|
+
* sleep(1000),
|
|
75
|
+
* ])
|
|
76
|
+
* }
|
|
77
|
+
* ```
|
|
78
|
+
* The Promise returned by this handler will resolve either when the `next` handler resolves or 1 second has elapsed,
|
|
79
|
+
* whichever happens first. If the timeout happens first, we want the `next` handler to recieve an abort signal so that
|
|
80
|
+
* it can terminate early (since its result is no longer needed).
|
|
81
|
+
*
|
|
82
|
+
* HandlerChainBuilder makes this happen by observing when each handler completes, and sending an abort signal to all
|
|
83
|
+
* the handlers "downstream" from the aborting handler.
|
|
84
|
+
*/
|
|
85
|
+
export class HandlerChainBuilder {
|
|
86
|
+
constructor(inner) {
|
|
87
|
+
// The TS compiler has the following behavior:
|
|
88
|
+
//
|
|
89
|
+
// class Infer<T extends SomeType | undefined> { constructor(f: (t?: T) => void) {} }
|
|
90
|
+
// const f = (t?: SomeType) => {}
|
|
91
|
+
// const i = new Infer(f)
|
|
92
|
+
//
|
|
93
|
+
// The type of `i` is inferred to be `Infer<SomeType>` instead of `Infer<SomeType | undefined>`, even though the
|
|
94
|
+
// type of `f`'s argument is `SomeType | undefined`. This seems to be a bug in type inference. Note that making
|
|
95
|
+
// the constructor argument required gives the expected behavior:
|
|
96
|
+
//
|
|
97
|
+
// class Infer<T extends SomeType | undefined> { constructor(f: (t: T) => void) {} }
|
|
98
|
+
// const f = (t?: SomeType) => {}
|
|
99
|
+
// const i = new Infer(f)
|
|
100
|
+
//
|
|
101
|
+
// Now `i` is inferred to be `Infer<SomeType | undefined>`.
|
|
102
|
+
//
|
|
103
|
+
// This has consequences if the inferred type T is used elsewhere in the class.
|
|
104
|
+
//
|
|
105
|
+
// In this case, we need to make sure that if the given `inner` function marks the metadata argument as
|
|
106
|
+
// optional, that HandlerChainBuilder correctly infers that the Meta type includes undefined. So we don't mark
|
|
107
|
+
// metadata as optional, and so we must cast to `Handler` (which does mark it as optional).
|
|
108
|
+
//
|
|
109
|
+
// Safety: We're adding `| undefined` to the metadata type, which may be unsafe – `undefined` may not be
|
|
110
|
+
// assignable to Meta. But when handling the argument of type Meta, we simply pass it through from handler to
|
|
111
|
+
// handler – we never call `inner` without passing the metadata argument we've received from some call to an
|
|
112
|
+
// outer handler. The typing visible to callers remains safe.
|
|
113
|
+
this.inner = inner;
|
|
114
|
+
}
|
|
115
|
+
get handler() {
|
|
116
|
+
return this.inner;
|
|
117
|
+
}
|
|
118
|
+
map(outer) {
|
|
119
|
+
// To create the next handler in the chain, we compose the "outer" handler with the "inner" handler.
|
|
120
|
+
//
|
|
121
|
+
// The outer handler observes its own completion and sends an abort signal to the inner handler when it has
|
|
122
|
+
// resolved. To prevent unexpected behavior, the inner handler also observes its own completion, setting a flag
|
|
123
|
+
// when it resolves so that – if it resolves before the outer handler – the outer handler can skip sending the
|
|
124
|
+
// abort signal (since the inner handler has already completed).
|
|
125
|
+
const outerHandler = (req, metadata) => {
|
|
126
|
+
var _a;
|
|
127
|
+
const abort = new AbortController();
|
|
128
|
+
const signal = abort.signal;
|
|
129
|
+
// It's important to not signal an abort to an inner handler which has already completed – it seems like
|
|
130
|
+
// this would be a non-issue (shouldn't aborting after completion be a no-op?), but specifically for the
|
|
131
|
+
// browser's implementation of `fetch`, aborting even after the `fetch` Promise resolves can cause an abort
|
|
132
|
+
// error if e.g. the Fetch Response's body has not yet been read.
|
|
133
|
+
//
|
|
134
|
+
// So, for safety, we will only abort inner handlers which are still executing.
|
|
135
|
+
let innerCompleted = false;
|
|
136
|
+
const maybeAbort = () => {
|
|
137
|
+
var _a;
|
|
138
|
+
// Safety: we never give `abort` to anyone else, so we know if the signal is aborted, this function
|
|
139
|
+
// has already run, so we can return early without fear of leaking. We also know if inner has completed,
|
|
140
|
+
// it has already performed cleanup.
|
|
141
|
+
if (signal.aborted || innerCompleted)
|
|
142
|
+
return;
|
|
143
|
+
// If we've gotten here, the outer handler has either completed, or we heard an abort event while the
|
|
144
|
+
// inner handler is still executing – so we pass the abort signal down to the inner handler.
|
|
145
|
+
abort.abort();
|
|
146
|
+
(_a = metadata === null || metadata === void 0 ? void 0 : metadata.signal) === null || _a === void 0 ? void 0 : _a.removeEventListener("abort", maybeAbort);
|
|
147
|
+
};
|
|
148
|
+
(_a = metadata === null || metadata === void 0 ? void 0 : metadata.signal) === null || _a === void 0 ? void 0 : _a.addEventListener("abort", maybeAbort);
|
|
149
|
+
const innerHandler = new Proxy(this.inner, {
|
|
150
|
+
apply: (target, thisArg, args) => {
|
|
151
|
+
const [req, metadata] = args;
|
|
152
|
+
// To help Handler authors out, we'll do some bookkeeping and cleanup for them – if they forget to
|
|
153
|
+
// remove an abort event listener, we'll remove it for them when the Promise they return resolves.
|
|
154
|
+
// Note: No need to proxy removeEventListener, since removing a non-existent listener just no-ops.
|
|
155
|
+
const abortListeners = [];
|
|
156
|
+
signal.addEventListener = new Proxy(signal.addEventListener, {
|
|
157
|
+
apply: (target, thisArg, args) => {
|
|
158
|
+
abortListeners.push(args[1]);
|
|
159
|
+
return Reflect.apply(target, thisArg, args);
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
const cleanupAndMarkComplete = () => {
|
|
163
|
+
var _a;
|
|
164
|
+
// The only reason we listen to upstream aborts is to pass them to the inner handler – since the
|
|
165
|
+
// inner handler has completed, we no longer need the listener.
|
|
166
|
+
(_a = metadata === null || metadata === void 0 ? void 0 : metadata.signal) === null || _a === void 0 ? void 0 : _a.removeEventListener("abort", maybeAbort);
|
|
167
|
+
abortListeners.forEach((listener) => signal.removeEventListener("abort", listener));
|
|
168
|
+
innerCompleted = true;
|
|
169
|
+
};
|
|
170
|
+
const innerResponse = Reflect.apply(target, thisArg, [
|
|
171
|
+
req,
|
|
172
|
+
Object.assign(Object.assign({}, metadata), { signal }),
|
|
173
|
+
]);
|
|
174
|
+
// Using `finally` is more idiomatic, but causes trouble in some environments (e.g. some testing
|
|
175
|
+
// runtimes which detect uncaught rejected promises).
|
|
176
|
+
innerResponse.catch(() => { }).then(cleanupAndMarkComplete);
|
|
177
|
+
return innerResponse;
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
const outerResponse = outer(innerHandler)(req, metadata);
|
|
181
|
+
outerResponse.catch(() => { }).then(maybeAbort);
|
|
182
|
+
return outerResponse;
|
|
183
|
+
};
|
|
184
|
+
return new HandlerChainBuilder(outerHandler);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=HandlerChainBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HandlerChainBuilder.js","sourceRoot":"","sources":["../../src/handlers/HandlerChainBuilder.ts"],"names":[],"mappings":"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","sourcesContent":["export type RequestMetadata =\n | {\n signal?: AbortSignal | null | undefined;\n }\n | undefined;\nexport type Handler<Req, Res, Meta extends RequestMetadata> = (req: Req, metadata?: Meta) => Promise<Res>;\nexport type ChainableHandler<Req, Res, NextReq, NextRes, Meta extends RequestMetadata | undefined> = (\n next: Handler<NextReq, NextRes, Meta>\n) => Handler<Req, Res, Meta>;\n\n/**\n * Creates a Handler chain – a series of functions composed such that each function may call a supplied `next` function\n * which passes execution down the chain. When the final Handler in the chain returns, execution passes back up the\n * chain eventually returning to the caller.\n *\n * Each Handler chain begins with a \"raw\" Handler – this is a function which takes some request and returns some\n * response. A chain is then created by supplying a series of mapping functions – the ChainableHandler type – which will\n * be called with the `next` Handler in the chain.\n *\n * Ex:\n * ```ts\n * const handler = (request: string, metadata?: RequestMetadata) => Promise.resolve(`Responded to ${request}`)\n * const chainable = (next: Handler<string, string>) => (request: string, metadata?: RequestMetadata) => {\n * return next(`modified ${request}`, metadata)\n * }\n *\n * const chain = new HandlerChainBuilder(handler)\n * .map(chainable)\n * .handler\n *\n * const response = await chain('hello')\n * expect(response).toBe('Responded to modified hello; 0')\n * ```\n * You can largely ignore the `metadata` argument present in the above example. This is the mechanism by which an\n * AbortSignal is passed to each Handler in the chain, but the only real requirement when implementing a Handler is\n * to pass this argument along to the `next` function. In fact, many Handlers will want to be generic over the type\n * of metadata:\n * ```ts\n * const chainable = <Meta>(next: Handler<string, string, Meta>) => (request: string, metadata: Meta) => {\n * return next(`modified ${request}`, metadata)\n * }\n * ```\n * Actually, it's a very good idea for Handlers to be as generic as possible, since that will allow greater re-use. In\n * the above example, we don't do anything with the response from `next`, so we can let that be generic, too:\n * ```ts\n * const chainable = <Res, Meta>(next: Handler<string, Res, Meta>) => (request: string, metadata: Meta) => {\n * return next(`modified ${request}`, metadata)\n * }\n * ```\n * Now if some other Handler in the chain decides to return a different response type, our Handler won't require any\n * changes to compile.\n *\n * ---\n *\n * Since execution passes from handler to handler in the chain, and then back, handlers have the opportunity to modify\n * or observe both the request and response. This might be useful for implementing serialization/deserialization, but\n * the simplest example that demonstrates this feature is measuring request latency:\n * ```ts\n * const latencyMeasuringHandler = <Req, Res, Meta>(next: Handler<Req, Res, Meta>) =>\n * async (req: Req, metadata: Meta) => {\n * const start = performance.now()\n * const response = await next(req, metadata)\n * const latency = performance.now() - start\n * console.log(`latency for request ${request} was ${latency}`)\n * return response\n * }\n * ```\n * Execution is first passed to our measuring handler, which marks the `start` timestamp. Then it passes execution on\n * down the chain. After a response is received (by some handler down the chain), execution passes back up to our\n * handler here, which records the amount of time spent inside `next`.\n *\n * ---\n *\n * Handlers may also abort requests. They can do this in two ways:\n * 1. Create an `AbortController` and add its `AbortSignal` to the `metadata` object when calling `next`.\n * 2. Resolve its returned Promise.\n *\n * The first approach is straightforward, but the second may benefit from an example – the simplest is a handler which\n * will timeout a request:\n * ```ts\n * const timeoutHandler = <Req, Res, Meta>(next: Handler<Req, Res, Meta>) => (req: Req, metadata: Meta) => {\n * return Promise.race([\n * next(req, metadata),\n * sleep(1000),\n * ])\n * }\n * ```\n * The Promise returned by this handler will resolve either when the `next` handler resolves or 1 second has elapsed,\n * whichever happens first. If the timeout happens first, we want the `next` handler to recieve an abort signal so that\n * it can terminate early (since its result is no longer needed).\n *\n * HandlerChainBuilder makes this happen by observing when each handler completes, and sending an abort signal to all\n * the handlers \"downstream\" from the aborting handler.\n */\nexport class HandlerChainBuilder<Req, Res, Meta extends RequestMetadata> {\n private readonly inner: Handler<Req, Res, Meta>;\n\n constructor(inner: (req: Req, metadata: Meta) => Promise<Res>) {\n // The TS compiler has the following behavior:\n //\n // class Infer<T extends SomeType | undefined> { constructor(f: (t?: T) => void) {} }\n // const f = (t?: SomeType) => {}\n // const i = new Infer(f)\n //\n // The type of `i` is inferred to be `Infer<SomeType>` instead of `Infer<SomeType | undefined>`, even though the\n // type of `f`'s argument is `SomeType | undefined`. This seems to be a bug in type inference. Note that making\n // the constructor argument required gives the expected behavior:\n //\n // class Infer<T extends SomeType | undefined> { constructor(f: (t: T) => void) {} }\n // const f = (t?: SomeType) => {}\n // const i = new Infer(f)\n //\n // Now `i` is inferred to be `Infer<SomeType | undefined>`.\n //\n // This has consequences if the inferred type T is used elsewhere in the class.\n //\n // In this case, we need to make sure that if the given `inner` function marks the metadata argument as\n // optional, that HandlerChainBuilder correctly infers that the Meta type includes undefined. So we don't mark\n // metadata as optional, and so we must cast to `Handler` (which does mark it as optional).\n //\n // Safety: We're adding `| undefined` to the metadata type, which may be unsafe – `undefined` may not be\n // assignable to Meta. But when handling the argument of type Meta, we simply pass it through from handler to\n // handler – we never call `inner` without passing the metadata argument we've received from some call to an\n // outer handler. The typing visible to callers remains safe.\n this.inner = inner as Handler<Req, Res, Meta>;\n }\n\n get handler(): Handler<Req, Res, Meta> {\n return this.inner;\n }\n\n map<PriorReq, PriorRes>(\n outer: ChainableHandler<PriorReq, PriorRes, Req, Res, Meta>\n ): HandlerChainBuilder<PriorReq, PriorRes, Meta> {\n // To create the next handler in the chain, we compose the \"outer\" handler with the \"inner\" handler.\n //\n // The outer handler observes its own completion and sends an abort signal to the inner handler when it has\n // resolved. To prevent unexpected behavior, the inner handler also observes its own completion, setting a flag\n // when it resolves so that – if it resolves before the outer handler – the outer handler can skip sending the\n // abort signal (since the inner handler has already completed).\n const outerHandler = (req: PriorReq, metadata: Meta): Promise<PriorRes> => {\n const abort = new AbortController();\n const signal = abort.signal;\n\n // It's important to not signal an abort to an inner handler which has already completed – it seems like\n // this would be a non-issue (shouldn't aborting after completion be a no-op?), but specifically for the\n // browser's implementation of `fetch`, aborting even after the `fetch` Promise resolves can cause an abort\n // error if e.g. the Fetch Response's body has not yet been read.\n //\n // So, for safety, we will only abort inner handlers which are still executing.\n let innerCompleted = false;\n\n const maybeAbort = () => {\n // Safety: we never give `abort` to anyone else, so we know if the signal is aborted, this function\n // has already run, so we can return early without fear of leaking. We also know if inner has completed,\n // it has already performed cleanup.\n if (signal.aborted || innerCompleted) return;\n\n // If we've gotten here, the outer handler has either completed, or we heard an abort event while the\n // inner handler is still executing – so we pass the abort signal down to the inner handler.\n abort.abort();\n metadata?.signal?.removeEventListener(\"abort\", maybeAbort);\n };\n\n metadata?.signal?.addEventListener(\"abort\", maybeAbort);\n\n const innerHandler = new Proxy(this.inner, {\n apply: (target, thisArg, args) => {\n const [req, metadata] = args as Parameters<typeof target>;\n\n // To help Handler authors out, we'll do some bookkeeping and cleanup for them – if they forget to\n // remove an abort event listener, we'll remove it for them when the Promise they return resolves.\n // Note: No need to proxy removeEventListener, since removing a non-existent listener just no-ops.\n const abortListeners: EventListenerOrEventListenerObject[] = [];\n signal.addEventListener = new Proxy(signal.addEventListener, {\n apply: (target, thisArg, args) => {\n abortListeners.push(args[1]);\n return Reflect.apply(target, thisArg, args);\n },\n });\n\n const cleanupAndMarkComplete = () => {\n // The only reason we listen to upstream aborts is to pass them to the inner handler – since the\n // inner handler has completed, we no longer need the listener.\n metadata?.signal?.removeEventListener(\"abort\", maybeAbort);\n abortListeners.forEach((listener) => signal.removeEventListener(\"abort\", listener));\n innerCompleted = true;\n };\n\n const innerResponse: ReturnType<typeof target> = Reflect.apply(target, thisArg, [\n req,\n { ...metadata, signal },\n ]);\n\n // Using `finally` is more idiomatic, but causes trouble in some environments (e.g. some testing\n // runtimes which detect uncaught rejected promises).\n innerResponse.catch(() => {}).then(cleanupAndMarkComplete);\n return innerResponse;\n },\n });\n\n const outerResponse = outer(innerHandler)(req, metadata);\n outerResponse.catch(() => {}).then(maybeAbort);\n return outerResponse;\n };\n return new HandlerChainBuilder(outerHandler as Handler<PriorReq, PriorRes, Meta>);\n }\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ChainableHandler, RequestMetadata } from "./HandlerChainBuilder";
|
|
2
|
+
declare type ArrayBufferResponse = [ArrayBuffer, Response];
|
|
3
|
+
declare type ChainableArrayBufferHandler<Req, Meta extends RequestMetadata> = ChainableHandler<Req, ArrayBufferResponse, Req, Response, Meta>;
|
|
4
|
+
/**
|
|
5
|
+
* Parse a Fetch Response body into an ArrayBuffer.
|
|
6
|
+
*
|
|
7
|
+
* @returns {@link ChainableHandler}, suitable for use in {@link HandlerChainBuilder.map}
|
|
8
|
+
*/
|
|
9
|
+
export declare const createArrayBufferParsingHandler: <Req, Meta extends RequestMetadata>() => ChainableArrayBufferHandler<Req, Meta>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
/**
|
|
3
|
+
* Parse a Fetch Response body into an ArrayBuffer.
|
|
4
|
+
*
|
|
5
|
+
* @returns {@link ChainableHandler}, suitable for use in {@link HandlerChainBuilder.map}
|
|
6
|
+
*/
|
|
7
|
+
export const createArrayBufferParsingHandler = () => (next) => (req, metadata) => __awaiter(void 0, void 0, void 0, function* () {
|
|
8
|
+
const response = yield next(req, metadata);
|
|
9
|
+
let buffer;
|
|
10
|
+
try {
|
|
11
|
+
buffer = yield response.arrayBuffer();
|
|
12
|
+
}
|
|
13
|
+
catch (_) {
|
|
14
|
+
buffer = new ArrayBuffer(0);
|
|
15
|
+
}
|
|
16
|
+
return [buffer, response];
|
|
17
|
+
});
|
|
18
|
+
//# sourceMappingURL=arrayBufferParsingHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arrayBufferParsingHandler.js","sourceRoot":"","sources":["../../src/handlers/arrayBufferParsingHandler.ts"],"names":[],"mappings":";AAWA;;;;GAIG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG,GAG7C,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAO,GAAG,EAAE,QAAQ,EAAE,EAAE;IACnC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IAC3C,IAAI,MAAmB,CAAC;IACxB,IAAI;QACA,MAAM,GAAG,MAAM,QAAQ,CAAC,WAAW,EAAE,CAAC;KACzC;IAAC,OAAO,CAAC,EAAE;QACR,MAAM,GAAG,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC;KAC/B;IACD,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAC9B,CAAC,CAAA,CAAC","sourcesContent":["import { ChainableHandler, RequestMetadata } from \"./HandlerChainBuilder\";\n\ntype ArrayBufferResponse = [ArrayBuffer, Response];\ntype ChainableArrayBufferHandler<Req, Meta extends RequestMetadata> = ChainableHandler<\n Req,\n ArrayBufferResponse,\n Req,\n Response,\n Meta\n>;\n\n/**\n * Parse a Fetch Response body into an ArrayBuffer.\n *\n * @returns {@link ChainableHandler}, suitable for use in {@link HandlerChainBuilder.map}\n */\nexport const createArrayBufferParsingHandler = <Req, Meta extends RequestMetadata>(): ChainableArrayBufferHandler<\n Req,\n Meta\n> => (next) => async (req, metadata) => {\n const response = await next(req, metadata);\n let buffer: ArrayBuffer;\n try {\n buffer = await response.arrayBuffer();\n } catch (_) {\n buffer = new ArrayBuffer(0);\n }\n return [buffer, response];\n};\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ChainableHandler, RequestMetadata } from "./HandlerChainBuilder";
|
|
2
|
+
export interface BatchingHandlerOptions<Req, BatchReq> {
|
|
3
|
+
batchReduce: (batch: BatchReq | undefined, req: Req) => BatchReq | Promise<BatchReq>;
|
|
4
|
+
isBatchComplete: (batch: BatchReq) => boolean;
|
|
5
|
+
maxBatchAge?: number;
|
|
6
|
+
flushOnPageHidden?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Accumulate requests into batches, which are then sent to the next handler in the chain. Batches are sent when either:
|
|
10
|
+
* - the given `isBatchComplete` function returns true, closing the current batch and sending it down the chain.
|
|
11
|
+
* - an optional `maxBatchAge` time has elapsed since the first request in the batch was received.
|
|
12
|
+
* - the page terminates.
|
|
13
|
+
*
|
|
14
|
+
* When handling a request, the Promise returned will resolve when that request has been successfully added to the
|
|
15
|
+
* current batch – **NOT** when that batch has been successfully processed by the rest of the handler chain.
|
|
16
|
+
*
|
|
17
|
+
* The `next` handler in the chain will receive the batch and should handle any errors arising from further processing
|
|
18
|
+
* on the batch (e.g. sending it to a server).
|
|
19
|
+
*
|
|
20
|
+
* **Note:** This handler does not support aborting handled requests via AbortSignal.
|
|
21
|
+
*
|
|
22
|
+
* @param options
|
|
23
|
+
* @returns {@link ChainableHandler}, suitable for use in {@link HandlerChainBuilder.map}
|
|
24
|
+
*/
|
|
25
|
+
export declare const createBatchingHandler: <Req, BatchReq, BatchRes, Meta extends RequestMetadata>({ batchReduce, isBatchComplete, maxBatchAge, flushOnPageHidden, }: BatchingHandlerOptions<Req, BatchReq>) => ChainableHandler<Req, void, BatchReq, BatchRes, Meta>;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { isDuringVisibilityTransition, onPageHidden } from "../common/pageVisibility";
|
|
3
|
+
import { createMappingHandler } from "./mappingHandler";
|
|
4
|
+
/**
|
|
5
|
+
* Accumulate requests into batches, which are then sent to the next handler in the chain. Batches are sent when either:
|
|
6
|
+
* - the given `isBatchComplete` function returns true, closing the current batch and sending it down the chain.
|
|
7
|
+
* - an optional `maxBatchAge` time has elapsed since the first request in the batch was received.
|
|
8
|
+
* - the page terminates.
|
|
9
|
+
*
|
|
10
|
+
* When handling a request, the Promise returned will resolve when that request has been successfully added to the
|
|
11
|
+
* current batch – **NOT** when that batch has been successfully processed by the rest of the handler chain.
|
|
12
|
+
*
|
|
13
|
+
* The `next` handler in the chain will receive the batch and should handle any errors arising from further processing
|
|
14
|
+
* on the batch (e.g. sending it to a server).
|
|
15
|
+
*
|
|
16
|
+
* **Note:** This handler does not support aborting handled requests via AbortSignal.
|
|
17
|
+
*
|
|
18
|
+
* @param options
|
|
19
|
+
* @returns {@link ChainableHandler}, suitable for use in {@link HandlerChainBuilder.map}
|
|
20
|
+
*/
|
|
21
|
+
export const createBatchingHandler = ({ batchReduce, isBatchComplete, maxBatchAge, flushOnPageHidden, }) => {
|
|
22
|
+
// Flush batches when the page is hidden by default.
|
|
23
|
+
const doFlushOnPageHidden = flushOnPageHidden !== null && flushOnPageHidden !== void 0 ? flushOnPageHidden : true;
|
|
24
|
+
// TODO: this should just be `number`, but we're picking up NodeJS types (@types/node) when building, so setTimeout
|
|
25
|
+
// gets a different return type than what it should have in the browser. We should build without NodeJS types, but
|
|
26
|
+
// that will require some fixes across the codebase.
|
|
27
|
+
let batchTimeout;
|
|
28
|
+
let currentBatch = undefined;
|
|
29
|
+
let clearOnHidden = () => { };
|
|
30
|
+
const reducingHandler = createMappingHandler((request) => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
|
+
currentBatch = yield batchReduce(currentBatch, request);
|
|
32
|
+
return currentBatch;
|
|
33
|
+
}), 1);
|
|
34
|
+
const batchAndSend = (next, request, metadata) => {
|
|
35
|
+
const batch = request ? batchReduce(currentBatch, request) : currentBatch;
|
|
36
|
+
if (!batch)
|
|
37
|
+
return;
|
|
38
|
+
// `next` should handle its own errors – that is, the batchingHandler is meant to be placed in a handler chain
|
|
39
|
+
// prior to any error logging, retrying, etc. handlers.
|
|
40
|
+
const complete = batch instanceof Promise
|
|
41
|
+
? batch.then((b) => next(b, metadata)).catch(() => { })
|
|
42
|
+
: next(batch, metadata).catch(() => { });
|
|
43
|
+
currentBatch = undefined;
|
|
44
|
+
clearTimeout(batchTimeout);
|
|
45
|
+
clearOnHidden();
|
|
46
|
+
return complete;
|
|
47
|
+
};
|
|
48
|
+
return (next) => (request, metadata) => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
+
// Requests may be made while the page is transitioning to hidden – for example, the page is being unloaded and
|
|
50
|
+
// we're reporting final metrics. In this case, we need to skip batching and synchronously call `next` so that
|
|
51
|
+
// the request is not lost.
|
|
52
|
+
if (isDuringVisibilityTransition("hidden") && doFlushOnPageHidden) {
|
|
53
|
+
yield batchAndSend(next, request, metadata);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
// If this is the first request in a batch, we need to set up some callbacks to flush the batch when certain
|
|
57
|
+
// events occur:
|
|
58
|
+
//
|
|
59
|
+
// - maxBatchAge time passes.
|
|
60
|
+
// - page visibility transitions to hidden (which could indicate the page is being unloaded).
|
|
61
|
+
//
|
|
62
|
+
if (currentBatch === undefined) {
|
|
63
|
+
const sendBatch = () => batchAndSend(next, undefined, metadata);
|
|
64
|
+
if (maxBatchAge !== undefined)
|
|
65
|
+
batchTimeout = setTimeout(sendBatch, maxBatchAge);
|
|
66
|
+
if (doFlushOnPageHidden)
|
|
67
|
+
clearOnHidden = onPageHidden(sendBatch);
|
|
68
|
+
}
|
|
69
|
+
const handle = reducingHandler(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
70
|
+
if (!currentBatch)
|
|
71
|
+
return;
|
|
72
|
+
if (!isBatchComplete(currentBatch))
|
|
73
|
+
return;
|
|
74
|
+
yield batchAndSend(next, undefined, metadata);
|
|
75
|
+
}));
|
|
76
|
+
return handle(request, metadata);
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=batchingHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batchingHandler.js","sourceRoot":"","sources":["../../src/handlers/batchingHandler.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,4BAA4B,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAEtF,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AASxD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAwD,EACzF,WAAW,EACX,eAAe,EACf,WAAW,EACX,iBAAiB,GACmB,EAAyD,EAAE;IAC/F,oDAAoD;IACpD,MAAM,mBAAmB,GAAG,iBAAiB,aAAjB,iBAAiB,cAAjB,iBAAiB,GAAI,IAAI,CAAC;IACtD,mHAAmH;IACnH,kHAAkH;IAClH,oDAAoD;IACpD,IAAI,YAA2C,CAAC;IAChD,IAAI,YAAY,GAAyB,SAAS,CAAC;IACnD,IAAI,aAAa,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;IAE7B,MAAM,eAAe,GAAG,oBAAoB,CAA4B,CAAO,OAAO,EAAE,EAAE;QACtF,YAAY,GAAG,MAAM,WAAW,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;QACxD,OAAO,YAAY,CAAC;IACxB,CAAC,CAAA,EAAE,CAAC,CAAC,CAAC;IAEN,MAAM,YAAY,GAAG,CAAC,IAAuC,EAAE,OAAa,EAAE,QAAe,EAAE,EAAE;QAC7F,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC;QAC1E,IAAI,CAAC,KAAK;YAAE,OAAO;QAEnB,8GAA8G;QAC9G,uDAAuD;QACvD,MAAM,QAAQ,GACV,KAAK,YAAY,OAAO;YACpB,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC;YACtD,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QAEhD,YAAY,GAAG,SAAS,CAAC;QACzB,YAAY,CAAC,YAAY,CAAC,CAAC;QAC3B,aAAa,EAAE,CAAC;QAEhB,OAAO,QAAQ,CAAC;IACpB,CAAC,CAAC;IAEF,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAO,OAAO,EAAE,QAAQ,EAAE,EAAE;QACzC,+GAA+G;QAC/G,8GAA8G;QAC9G,2BAA2B;QAC3B,IAAI,4BAA4B,CAAC,QAAQ,CAAC,IAAI,mBAAmB,EAAE;YAC/D,MAAM,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;YAC5C,OAAO;SACV;QAED,4GAA4G;QAC5G,gBAAgB;QAChB,EAAE;QACF,6BAA6B;QAC7B,6FAA6F;QAC7F,EAAE;QACF,IAAI,YAAY,KAAK,SAAS,EAAE;YAC5B,MAAM,SAAS,GAAG,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;YAChE,IAAI,WAAW,KAAK,SAAS;gBAAE,YAAY,GAAG,UAAU,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;YACjF,IAAI,mBAAmB;gBAAE,aAAa,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC;SACpE;QAED,MAAM,MAAM,GAAG,eAAe,CAAC,GAAS,EAAE;YACtC,IAAI,CAAC,YAAY;gBAAE,OAAO;YAC1B,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC;gBAAE,OAAO;YAC3C,MAAM,YAAY,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;QAClD,CAAC,CAAA,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACrC,CAAC,CAAA,CAAC;AACN,CAAC,CAAC","sourcesContent":["import { isDuringVisibilityTransition, onPageHidden } from \"../common/pageVisibility\";\nimport { ChainableHandler, Handler, RequestMetadata } from \"./HandlerChainBuilder\";\nimport { createMappingHandler } from \"./mappingHandler\";\n\nexport interface BatchingHandlerOptions<Req, BatchReq> {\n batchReduce: (batch: BatchReq | undefined, req: Req) => BatchReq | Promise<BatchReq>;\n isBatchComplete: (batch: BatchReq) => boolean;\n maxBatchAge?: number;\n flushOnPageHidden?: boolean;\n}\n\n/**\n * Accumulate requests into batches, which are then sent to the next handler in the chain. Batches are sent when either:\n * - the given `isBatchComplete` function returns true, closing the current batch and sending it down the chain.\n * - an optional `maxBatchAge` time has elapsed since the first request in the batch was received.\n * - the page terminates.\n *\n * When handling a request, the Promise returned will resolve when that request has been successfully added to the\n * current batch – **NOT** when that batch has been successfully processed by the rest of the handler chain.\n *\n * The `next` handler in the chain will receive the batch and should handle any errors arising from further processing\n * on the batch (e.g. sending it to a server).\n *\n * **Note:** This handler does not support aborting handled requests via AbortSignal.\n *\n * @param options\n * @returns {@link ChainableHandler}, suitable for use in {@link HandlerChainBuilder.map}\n */\nexport const createBatchingHandler = <Req, BatchReq, BatchRes, Meta extends RequestMetadata>({\n batchReduce,\n isBatchComplete,\n maxBatchAge,\n flushOnPageHidden,\n}: BatchingHandlerOptions<Req, BatchReq>): ChainableHandler<Req, void, BatchReq, BatchRes, Meta> => {\n // Flush batches when the page is hidden by default.\n const doFlushOnPageHidden = flushOnPageHidden ?? true;\n // TODO: this should just be `number`, but we're picking up NodeJS types (@types/node) when building, so setTimeout\n // gets a different return type than what it should have in the browser. We should build without NodeJS types, but\n // that will require some fixes across the codebase.\n let batchTimeout: ReturnType<typeof setTimeout>;\n let currentBatch: BatchReq | undefined = undefined;\n let clearOnHidden = () => {};\n\n const reducingHandler = createMappingHandler<Req, BatchReq, void, Meta>(async (request) => {\n currentBatch = await batchReduce(currentBatch, request);\n return currentBatch;\n }, 1);\n\n const batchAndSend = (next: Handler<BatchReq, BatchRes, Meta>, request?: Req, metadata?: Meta) => {\n const batch = request ? batchReduce(currentBatch, request) : currentBatch;\n if (!batch) return;\n\n // `next` should handle its own errors – that is, the batchingHandler is meant to be placed in a handler chain\n // prior to any error logging, retrying, etc. handlers.\n const complete =\n batch instanceof Promise\n ? batch.then((b) => next(b, metadata)).catch(() => {})\n : next(batch, metadata).catch(() => {});\n\n currentBatch = undefined;\n clearTimeout(batchTimeout);\n clearOnHidden();\n\n return complete;\n };\n\n return (next) => async (request, metadata) => {\n // Requests may be made while the page is transitioning to hidden – for example, the page is being unloaded and\n // we're reporting final metrics. In this case, we need to skip batching and synchronously call `next` so that\n // the request is not lost.\n if (isDuringVisibilityTransition(\"hidden\") && doFlushOnPageHidden) {\n await batchAndSend(next, request, metadata);\n return;\n }\n\n // If this is the first request in a batch, we need to set up some callbacks to flush the batch when certain\n // events occur:\n //\n // - maxBatchAge time passes.\n // - page visibility transitions to hidden (which could indicate the page is being unloaded).\n //\n if (currentBatch === undefined) {\n const sendBatch = () => batchAndSend(next, undefined, metadata);\n if (maxBatchAge !== undefined) batchTimeout = setTimeout(sendBatch, maxBatchAge);\n if (doFlushOnPageHidden) clearOnHidden = onPageHidden(sendBatch);\n }\n\n const handle = reducingHandler(async () => {\n if (!currentBatch) return;\n if (!isBatchComplete(currentBatch)) return;\n await batchAndSend(next, undefined, metadata);\n });\n\n return handle(request, metadata);\n };\n};\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CameraKitConfiguration } from "../configuration";
|
|
2
|
+
import { FetchHandler } from "./defaultFetchHandler";
|
|
3
|
+
/**
|
|
4
|
+
* A Fetch implementation which adds headers required to make authenticated calls to the CameraKit backend service.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export declare const cameraKitServiceFetchHandlerFactory: {
|
|
9
|
+
(args_0: CameraKitConfiguration, args_1: FetchHandler<Response>): import("./HandlerChainBuilder").Handler<RequestInfo, Response, RequestInit | undefined>;
|
|
10
|
+
token: "cameraKitServiceFetchHandler";
|
|
11
|
+
dependencies: readonly ["configuration", "defaultFetchHandler"];
|
|
12
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { cameraKitUserAgent } from "../common/cameraKitUserAgent";
|
|
2
|
+
import { configurationToken } from "../configuration";
|
|
3
|
+
import { Injectable } from "../dependency-injection/Injectable";
|
|
4
|
+
import { defaultFetchHandlerFactory } from "./defaultFetchHandler";
|
|
5
|
+
import { HandlerChainBuilder } from "./HandlerChainBuilder";
|
|
6
|
+
import { createHeadersModifyingFetchHandler } from "./headersModifyingFetchHandler";
|
|
7
|
+
/**
|
|
8
|
+
* A Fetch implementation which adds headers required to make authenticated calls to the CameraKit backend service.
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export const cameraKitServiceFetchHandlerFactory = Injectable("cameraKitServiceFetchHandler", [configurationToken, defaultFetchHandlerFactory.token], ({ apiToken }, defaultFetchHandler) => {
|
|
13
|
+
return new HandlerChainBuilder(defaultFetchHandler).map(createHeadersModifyingFetchHandler((headers) => {
|
|
14
|
+
headers.append("x-snap-client-user-agent", cameraKitUserAgent.userAgent);
|
|
15
|
+
headers.append("authorization", `Bearer ${apiToken}`);
|
|
16
|
+
return headers;
|
|
17
|
+
})).handler;
|
|
18
|
+
});
|
|
19
|
+
//# sourceMappingURL=cameraKitServiceFetchHandlerFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cameraKitServiceFetchHandlerFactory.js","sourceRoot":"","sources":["../../src/handlers/cameraKitServiceFetchHandlerFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAA0B,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,0BAA0B,EAAgB,MAAM,uBAAuB,CAAC;AACjF,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,kCAAkC,EAAE,MAAM,gCAAgC,CAAC;AAEpF;;;;GAIG;AACH,MAAM,CAAC,MAAM,mCAAmC,GAAG,UAAU,CACzD,8BAA8B,EAC9B,CAAC,kBAAkB,EAAE,0BAA0B,CAAC,KAAK,CAAU,EAC/D,CAAC,EAAE,QAAQ,EAA0B,EAAE,mBAAiC,EAAE,EAAE;IACxE,OAAO,IAAI,mBAAmB,CAAC,mBAAmB,CAAC,CAAC,GAAG,CACnD,kCAAkC,CAAC,CAAC,OAAO,EAAE,EAAE;QAC3C,OAAO,CAAC,MAAM,CAAC,0BAA0B,EAAE,kBAAkB,CAAC,SAAS,CAAC,CAAC;QACzE,OAAO,CAAC,MAAM,CAAC,eAAe,EAAE,UAAU,QAAQ,EAAE,CAAC,CAAC;QACtD,OAAO,OAAO,CAAC;IACnB,CAAC,CAAC,CACL,CAAC,OAAO,CAAC;AACd,CAAC,CACJ,CAAC","sourcesContent":["import { cameraKitUserAgent } from \"../common/cameraKitUserAgent\";\nimport { CameraKitConfiguration, configurationToken } from \"../configuration\";\nimport { Injectable } from \"../dependency-injection/Injectable\";\nimport { defaultFetchHandlerFactory, FetchHandler } from \"./defaultFetchHandler\";\nimport { HandlerChainBuilder } from \"./HandlerChainBuilder\";\nimport { createHeadersModifyingFetchHandler } from \"./headersModifyingFetchHandler\";\n\n/**\n * A Fetch implementation which adds headers required to make authenticated calls to the CameraKit backend service.\n *\n * @internal\n */\nexport const cameraKitServiceFetchHandlerFactory = Injectable(\n \"cameraKitServiceFetchHandler\",\n [configurationToken, defaultFetchHandlerFactory.token] as const,\n ({ apiToken }: CameraKitConfiguration, defaultFetchHandler: FetchHandler) => {\n return new HandlerChainBuilder(defaultFetchHandler).map(\n createHeadersModifyingFetchHandler((headers) => {\n headers.append(\"x-snap-client-user-agent\", cameraKitUserAgent.userAgent);\n headers.append(\"authorization\", `Bearer ${apiToken}`);\n return headers;\n })\n ).handler;\n }\n);\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ChainableHandler } from "./HandlerChainBuilder";
|
|
2
|
+
/**
|
|
3
|
+
* Addes cookies to auth requests to custom LensCore binaries
|
|
4
|
+
* when there are debugging overrides.
|
|
5
|
+
*
|
|
6
|
+
* @returns {@link ChainableHandler}, suitable for use in {@link HandlerChainBuilder.map}
|
|
7
|
+
*/
|
|
8
|
+
export declare const createDebugHandler: <Res>() => ChainableHandler<RequestInfo, Res, RequestInfo, Res, RequestInit | undefined>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { isString } from "../common/typeguards";
|
|
2
|
+
import { getConfigurationOverrides } from "../configurationOverrides";
|
|
3
|
+
/**
|
|
4
|
+
* Addes cookies to auth requests to custom LensCore binaries
|
|
5
|
+
* when there are debugging overrides.
|
|
6
|
+
*
|
|
7
|
+
* @returns {@link ChainableHandler}, suitable for use in {@link HandlerChainBuilder.map}
|
|
8
|
+
*/
|
|
9
|
+
export const createDebugHandler = () => {
|
|
10
|
+
var _a;
|
|
11
|
+
const noCustomWasmEndpoint = !((_a = getConfigurationOverrides()) === null || _a === void 0 ? void 0 : _a.wasmEndpointOverride);
|
|
12
|
+
if (noCustomWasmEndpoint) {
|
|
13
|
+
return (next) => next;
|
|
14
|
+
}
|
|
15
|
+
return (next) => (input, init) => {
|
|
16
|
+
var _a;
|
|
17
|
+
const url = isString(input) ? input : (_a = input === null || input === void 0 ? void 0 : input.url) !== null && _a !== void 0 ? _a : "";
|
|
18
|
+
// if requests are made to internal LensCore binaries site
|
|
19
|
+
// we have to include cookies for auth purposes
|
|
20
|
+
// as per https://wiki.sc-corp.net/x/KsnRCg
|
|
21
|
+
if (url.startsWith("https://lens-core-wasm.sc-corp.net/")) {
|
|
22
|
+
return next(input, Object.assign(Object.assign({}, init), { credentials: "include" }));
|
|
23
|
+
}
|
|
24
|
+
return next(input, init);
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=debugHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debugHandler.js","sourceRoot":"","sources":["../../src/handlers/debugHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AAGtE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAMhC,EAAE;;IACA,MAAM,oBAAoB,GAAG,CAAC,CAAA,MAAA,yBAAyB,EAAE,0CAAE,oBAAoB,CAAA,CAAC;IAEhF,IAAI,oBAAoB,EAAE;QACtB,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC;KACzB;IACD,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;;QAC7B,MAAM,GAAG,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,GAAG,mCAAI,EAAE,CAAC;QACvD,0DAA0D;QAC1D,+CAA+C;QAC/C,2CAA2C;QAC3C,IAAI,GAAG,CAAC,UAAU,CAAC,qCAAqC,CAAC,EAAE;YACvD,OAAO,IAAI,CAAC,KAAK,kCACV,IAAI,KACP,WAAW,EAAE,SAAS,IACxB,CAAC;SACN;QACD,OAAO,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC7B,CAAC,CAAC;AACN,CAAC,CAAC","sourcesContent":["import { isString } from \"../common/typeguards\";\nimport { getConfigurationOverrides } from \"../configurationOverrides\";\nimport { ChainableHandler, HandlerChainBuilder } from \"./HandlerChainBuilder\";\n\n/**\n * Addes cookies to auth requests to custom LensCore binaries\n * when there are debugging overrides.\n *\n * @returns {@link ChainableHandler}, suitable for use in {@link HandlerChainBuilder.map}\n */\nexport const createDebugHandler = <Res>(): ChainableHandler<\n RequestInfo,\n Res,\n RequestInfo,\n Res,\n RequestInit | undefined\n> => {\n const noCustomWasmEndpoint = !getConfigurationOverrides()?.wasmEndpointOverride;\n\n if (noCustomWasmEndpoint) {\n return (next) => next;\n }\n return (next) => (input, init) => {\n const url = isString(input) ? input : input?.url ?? \"\";\n // if requests are made to internal LensCore binaries site\n // we have to include cookies for auth purposes\n // as per https://wiki.sc-corp.net/x/KsnRCg\n if (url.startsWith(\"https://lens-core-wasm.sc-corp.net/\")) {\n return next(input, {\n ...init,\n credentials: \"include\",\n });\n }\n return next(input, init);\n };\n};\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare type FetchHandler<R = Response> = (input: RequestInfo, init?: RequestInit) => Promise<R>;
|
|
2
|
+
/**
|
|
3
|
+
* The default Fetch implementation, used to make a simple HTTP requests without any custom headers. This can be passed
|
|
4
|
+
* to `HandlerChainBuilder` to form the basis for other Fetch implementations (e.g. with custom headers, which extract
|
|
5
|
+
* the Response body, etc.)
|
|
6
|
+
*
|
|
7
|
+
* Has support for retries, client-side timeout, and navigating federated auth flows that may not support CORs requests.
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export declare const defaultFetchHandlerFactory: {
|
|
12
|
+
(): import("./HandlerChainBuilder").Handler<RequestInfo, Response, RequestInit | undefined>;
|
|
13
|
+
token: "defaultFetchHandler";
|
|
14
|
+
dependencies: [];
|
|
15
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Injectable } from "../dependency-injection/Injectable";
|
|
2
|
+
import { createDebugHandler } from "./debugHandler";
|
|
3
|
+
import { HandlerChainBuilder } from "./HandlerChainBuilder";
|
|
4
|
+
import { createNoCorsRetryingFetchHandler } from "./noCorsRetryingFetchHandler";
|
|
5
|
+
import { createRetryingHandler } from "./retryingHandler";
|
|
6
|
+
import { createTimeoutHandler } from "./timeoutHandler";
|
|
7
|
+
/**
|
|
8
|
+
* The default Fetch implementation, used to make a simple HTTP requests without any custom headers. This can be passed
|
|
9
|
+
* to `HandlerChainBuilder` to form the basis for other Fetch implementations (e.g. with custom headers, which extract
|
|
10
|
+
* the Response body, etc.)
|
|
11
|
+
*
|
|
12
|
+
* Has support for retries, client-side timeout, and navigating federated auth flows that may not support CORs requests.
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export const defaultFetchHandlerFactory = Injectable("defaultFetchHandler", () => {
|
|
17
|
+
return (
|
|
18
|
+
// Safety: We're re-typing fetch's second argument from `init?: RequestInit | undefined` to
|
|
19
|
+
// `init: RequestInit | void` – this is semantically equivalent, but the void makes for nicer ergonomics
|
|
20
|
+
// elsewhere (e.g. so that callers can omit the second argument instead of being forced to pass undefined).
|
|
21
|
+
new HandlerChainBuilder(fetch)
|
|
22
|
+
.map(createDebugHandler())
|
|
23
|
+
.map(createNoCorsRetryingFetchHandler())
|
|
24
|
+
.map(createRetryingHandler())
|
|
25
|
+
// TODO: completely arbitrary timeout -- this should be configurable by consumers, and we should think
|
|
26
|
+
// about a sane default timeout UX... it's probably less than 10 seconds.
|
|
27
|
+
.map(createTimeoutHandler({ timeout: 10 * 1000 })).handler);
|
|
28
|
+
});
|
|
29
|
+
//# sourceMappingURL=defaultFetchHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultFetchHandler.js","sourceRoot":"","sources":["../../src/handlers/defaultFetchHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,gCAAgC,EAAE,MAAM,8BAA8B,CAAC;AAChF,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAIxD;;;;;;;;GAQG;AAEH,MAAM,CAAC,MAAM,0BAA0B,GAAG,UAAU,CAAC,qBAAqB,EAAE,GAAG,EAAE;IAC7E,OAAO;IACH,2FAA2F;IAC3F,wGAAwG;IACxG,2GAA2G;IAC3G,IAAI,mBAAmB,CAAiD,KAAK,CAAC;SACzE,GAAG,CAAC,kBAAkB,EAAE,CAAC;SACzB,GAAG,CAAC,gCAAgC,EAAE,CAAC;SACvC,GAAG,CAAC,qBAAqB,EAAE,CAAC;QAE7B,sGAAsG;QACtG,yEAAyE;SACxE,GAAG,CAAC,oBAAoB,CAAC,EAAE,OAAO,EAAE,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC,OAAO,CACjE,CAAC;AACN,CAAC,CAAC,CAAC","sourcesContent":["import { Injectable } from \"../dependency-injection/Injectable\";\nimport { createDebugHandler } from \"./debugHandler\";\nimport { HandlerChainBuilder } from \"./HandlerChainBuilder\";\nimport { createNoCorsRetryingFetchHandler } from \"./noCorsRetryingFetchHandler\";\nimport { createRetryingHandler } from \"./retryingHandler\";\nimport { createTimeoutHandler } from \"./timeoutHandler\";\n\nexport type FetchHandler<R = Response> = (input: RequestInfo, init?: RequestInit) => Promise<R>;\n\n/**\n * The default Fetch implementation, used to make a simple HTTP requests without any custom headers. This can be passed\n * to `HandlerChainBuilder` to form the basis for other Fetch implementations (e.g. with custom headers, which extract\n * the Response body, etc.)\n *\n * Has support for retries, client-side timeout, and navigating federated auth flows that may not support CORs requests.\n *\n * @internal\n */\n\nexport const defaultFetchHandlerFactory = Injectable(\"defaultFetchHandler\", () => {\n return (\n // Safety: We're re-typing fetch's second argument from `init?: RequestInit | undefined` to\n // `init: RequestInit | void` – this is semantically equivalent, but the void makes for nicer ergonomics\n // elsewhere (e.g. so that callers can omit the second argument instead of being forced to pass undefined).\n new HandlerChainBuilder<RequestInfo, Response, RequestInit | undefined>(fetch)\n .map(createDebugHandler())\n .map(createNoCorsRetryingFetchHandler())\n .map(createRetryingHandler())\n\n // TODO: completely arbitrary timeout -- this should be configurable by consumers, and we should think\n // about a sane default timeout UX... it's probably less than 10 seconds.\n .map(createTimeoutHandler({ timeout: 10 * 1000 })).handler\n );\n});\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ChainableHandler } from "./HandlerChainBuilder";
|
|
2
|
+
/**
|
|
3
|
+
* Modify a Fetch Request's headers.
|
|
4
|
+
*
|
|
5
|
+
* @param modifyHeaders
|
|
6
|
+
* @returns {@link ChainableHandler}, suitable for use in {@link HandlerChainBuilder.map}
|
|
7
|
+
*/
|
|
8
|
+
export declare const createHeadersModifyingFetchHandler: <Res>(modifyHeaders: (headers: Headers) => Headers) => ChainableHandler<RequestInfo, Res, RequestInfo, Res, RequestInit | undefined>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modify a Fetch Request's headers.
|
|
3
|
+
*
|
|
4
|
+
* @param modifyHeaders
|
|
5
|
+
* @returns {@link ChainableHandler}, suitable for use in {@link HandlerChainBuilder.map}
|
|
6
|
+
*/
|
|
7
|
+
export const createHeadersModifyingFetchHandler = (modifyHeaders) => (next) => (input, init) => {
|
|
8
|
+
const headers = init && init.headers ? new Headers(init.headers) : typeof input === "string" ? new Headers() : input.headers;
|
|
9
|
+
const modifiedHeaders = modifyHeaders(headers);
|
|
10
|
+
// When `init` contains headers, `fetch` uses these *instead* of any headers found in the `input` Request.
|
|
11
|
+
return next(input, Object.assign(Object.assign({}, init), { headers: modifiedHeaders }));
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=headersModifyingFetchHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"headersModifyingFetchHandler.js","sourceRoot":"","sources":["../../src/handlers/headersModifyingFetchHandler.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAC9C,aAA4C,EACiC,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;IAC1G,MAAM,OAAO,GACT,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,OAAO,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC;IAEjH,MAAM,eAAe,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;IAE/C,0GAA0G;IAC1G,OAAO,IAAI,CAAC,KAAK,kCAAO,IAAI,KAAE,OAAO,EAAE,eAAe,IAAG,CAAC;AAC9D,CAAC,CAAC","sourcesContent":["import { ChainableHandler } from \"./HandlerChainBuilder\";\n\n/**\n * Modify a Fetch Request's headers.\n *\n * @param modifyHeaders\n * @returns {@link ChainableHandler}, suitable for use in {@link HandlerChainBuilder.map}\n */\nexport const createHeadersModifyingFetchHandler = <Res>(\n modifyHeaders: (headers: Headers) => Headers\n): ChainableHandler<RequestInfo, Res, RequestInfo, Res, RequestInit | undefined> => (next) => (input, init) => {\n const headers =\n init && init.headers ? new Headers(init.headers) : typeof input === \"string\" ? new Headers() : input.headers;\n\n const modifiedHeaders = modifyHeaders(headers);\n\n // When `init` contains headers, `fetch` uses these *instead* of any headers found in the `input` Request.\n return next(input, { ...init, headers: modifiedHeaders });\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/handlers/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,uCAAuC,CAAC","sourcesContent":["export * from \"./defaultFetchHandler\";\nexport * from \"./cameraKitServiceFetchHandlerFactory\";\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ChainableHandler, RequestMetadata } from "./HandlerChainBuilder";
|
|
2
|
+
/**
|
|
3
|
+
* Map from one request type to another, potentially asynchronously.
|
|
4
|
+
*
|
|
5
|
+
* **NOTE:** If `maxMapConcurrency` is set to some finite number, and more requests are handled than are allowed to
|
|
6
|
+
* be concurrently mapped, the waiting requests will be placed into a unbounded buffer. If, for example, requests are
|
|
7
|
+
* handled with high frequency, `maxMapConcurrency` is low, and the `map` function returns a long-running Promise, this
|
|
8
|
+
* buffer could use a large amount of memory. Keep this in mind when using this handler.
|
|
9
|
+
*
|
|
10
|
+
* @param map Transform each request, may be sync or async.
|
|
11
|
+
* @param maxMapConcurrency If the `map` function is async, it will be invoked at most this number of times
|
|
12
|
+
* concurrently. Setting this to 1 could be useful if it's important for `map` to be called in serial.
|
|
13
|
+
* @returns {@link ChainableHandler}, suitable for use in {@link HandlerChainBuilder.map}
|
|
14
|
+
*/
|
|
15
|
+
export declare const createMappingHandler: <Req, MappedReq, Res, Meta extends RequestMetadata>(map: (request: Req) => MappedReq | Promise<MappedReq>, maxMapConcurrency?: number, flushOnPageHidden?: boolean) => ChainableHandler<Req, Res, MappedReq, Res, Meta>;
|