@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,180 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { isValidKey } from "./Persistence";
|
|
3
|
+
function wrapRequest(request) {
|
|
4
|
+
const p = new Promise((resolve, reject) => {
|
|
5
|
+
request.onsuccess = () => resolve(request.result);
|
|
6
|
+
request.onerror = () => reject(request.error);
|
|
7
|
+
});
|
|
8
|
+
p.request = request;
|
|
9
|
+
return p;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* IndexedDB cursor requests are unique, in that their `onsuccess` handler may be called multiple times. To support
|
|
13
|
+
* this, and allow for an easier-to-use Promise-based API, we wrap the cursor request to support usage like:
|
|
14
|
+
* ```ts
|
|
15
|
+
* let request = await wrapCursorRequest(store.openCursor())
|
|
16
|
+
* while (request.cursor) {
|
|
17
|
+
* console.log(request.cursor.key, request.cursor.value)
|
|
18
|
+
* request = await request.continue()
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
function wrapCursorRequest(request) {
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
request.onsuccess = () => {
|
|
25
|
+
const cursor = request.result;
|
|
26
|
+
if (!cursor)
|
|
27
|
+
resolve({ cursor: null, continue: () => Promise.reject() });
|
|
28
|
+
else
|
|
29
|
+
resolve({
|
|
30
|
+
cursor,
|
|
31
|
+
continue: () => {
|
|
32
|
+
cursor.continue();
|
|
33
|
+
return wrapCursorRequest(request);
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
request.onerror = () => reject(request.error);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A simple key/value persistence using an IndexedDB storage backend.
|
|
42
|
+
*
|
|
43
|
+
* See [Using IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB) for an
|
|
44
|
+
* introduction to how IndexedDB works, its APIs, and how to use it.
|
|
45
|
+
*
|
|
46
|
+
* Note: Currently there is no support for database upgrades. Each instance of this class uses a single IDBObjectStore
|
|
47
|
+
* object set at instantiation time, and there are no hooks for performing migrations between versions. This may be
|
|
48
|
+
* added in the future if such functionality is needed.
|
|
49
|
+
*/
|
|
50
|
+
export class IndexedDBPersistence {
|
|
51
|
+
/**
|
|
52
|
+
* Construct an {@link IndexedDBPersistence} instance corresponding to a given IndexedDB database version.
|
|
53
|
+
*
|
|
54
|
+
* Throws `ConstraintError` if the version number is invalid (e.g. NaN, or less than 1).
|
|
55
|
+
*/
|
|
56
|
+
constructor(options) {
|
|
57
|
+
var _a;
|
|
58
|
+
// We'll namespace our DB names to A) avoid collisions with host applications and B) be transparent about who
|
|
59
|
+
// is using persistence.
|
|
60
|
+
this.databaseName = `Snap.CameraKit.${options.databaseName}`;
|
|
61
|
+
this.databaseVersion = options.databaseVersion;
|
|
62
|
+
this.objectStore = (_a = options.objectStore) !== null && _a !== void 0 ? _a : options.databaseName;
|
|
63
|
+
// `open()` will throw if the version is invalid -- this is desirable vs. rejecting the `db` promise, since then
|
|
64
|
+
// the error is only reported when callers try to perform some operation. Instead, we want the instantiating
|
|
65
|
+
// code to see the error.
|
|
66
|
+
this.db = this.openDatabase(indexedDB.open(this.databaseName, this.databaseVersion));
|
|
67
|
+
this.size = 0;
|
|
68
|
+
}
|
|
69
|
+
retrieve(key) {
|
|
70
|
+
return this.simpleTransaction("readonly", (store) => store.get(key));
|
|
71
|
+
}
|
|
72
|
+
retrieveAll() {
|
|
73
|
+
return this.simpleTransaction("readonly", (store) => store.getAll());
|
|
74
|
+
}
|
|
75
|
+
remove(key) {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
yield this.simpleTransaction("readwrite", (store) => store.delete(key));
|
|
78
|
+
this.size--;
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
removeAll() {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
const results = [];
|
|
84
|
+
const { store, done } = yield this.transaction("readwrite");
|
|
85
|
+
let request = yield wrapCursorRequest(store.openCursor());
|
|
86
|
+
const deleteRequests = [];
|
|
87
|
+
while (request.cursor) {
|
|
88
|
+
results.push(request.cursor.value);
|
|
89
|
+
// If any of the deletes fail (e.g. if the user deletes the object store during the transaction), it will
|
|
90
|
+
// fail the whole transaction. Since the primary expected cause of this failure mode is that the entire
|
|
91
|
+
// object store no longer exists, it's unlikely this will result in unbounded DB growth. That said, callers
|
|
92
|
+
// may want to attempt to retry the removal, or raise an alarm if the persistence size grows unexpectedly.
|
|
93
|
+
deleteRequests.push(wrapRequest(store.delete(request.cursor.key)));
|
|
94
|
+
request = yield request.continue();
|
|
95
|
+
}
|
|
96
|
+
yield Promise.all(deleteRequests.concat(done));
|
|
97
|
+
this.size = 0;
|
|
98
|
+
return results;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
store(keyOrValue, maybeValue) {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
const [key, value] = maybeValue === undefined ? [undefined, keyOrValue] : [keyOrValue, maybeValue];
|
|
104
|
+
// The key must be ValidKey | undefined.
|
|
105
|
+
if (!isValidKey(key) && typeof key !== "undefined")
|
|
106
|
+
throw new TypeError(`IndexedDBPersistence failed to ` + `store a value. Invalid key type: ${typeof key}`);
|
|
107
|
+
const storedKey = yield this.simpleTransaction("readwrite", (store) => store.put(value, key));
|
|
108
|
+
this.size++;
|
|
109
|
+
// Type safety: we already assert any given key is valid, and if the key is undefined IndexedDB will generate
|
|
110
|
+
// a numeric key (https://w3c.github.io/IndexedDB/#key-generator).
|
|
111
|
+
return storedKey;
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
openDatabase(request) {
|
|
115
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
// The `open()` call will throw if databaseVersion is invalid (e.g. < 1).
|
|
117
|
+
const dbPromise = wrapRequest(request);
|
|
118
|
+
dbPromise.request.onupgradeneeded = () => {
|
|
119
|
+
try {
|
|
120
|
+
// The following DOMExceptions may be thrown by `createObjectStore()` – they should all be logically
|
|
121
|
+
// impossible. We handle the one recoverable exception which could occur below.
|
|
122
|
+
//
|
|
123
|
+
// TransactionInactiveError: the database does not exist.
|
|
124
|
+
// InvalidStateError: `createObjectStore` was called outside a `versionchange` transaction.
|
|
125
|
+
// InvalidAccessError: `autoIncrement` is true and `keyPath` contains an empty string.
|
|
126
|
+
dbPromise.request.result.createObjectStore(this.objectStore, { autoIncrement: true });
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
// ConstraintError is thrown if the object store already exists. Could happen if multiple tabs to the
|
|
130
|
+
// same domain are opened and race to create the object store. In this case we can safely ignore the
|
|
131
|
+
// error and continue.
|
|
132
|
+
if (error instanceof DOMException && error.name === "ConstraintError")
|
|
133
|
+
return;
|
|
134
|
+
throw error;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
const db = yield dbPromise;
|
|
138
|
+
db.onclose = () => {
|
|
139
|
+
// The 'close` event fires when the DB is unexpectedly closed (e.g. user clears application data). We'll
|
|
140
|
+
// attempt to re-open it (which may fail, in which case no further attempts will be made, and all future
|
|
141
|
+
// transactions will fail).
|
|
142
|
+
this.db = this.openDatabase(indexedDB.open(this.databaseName, this.databaseVersion));
|
|
143
|
+
};
|
|
144
|
+
return db;
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
simpleTransaction(mode, operation) {
|
|
148
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
149
|
+
const { store, done } = yield this.transaction(mode);
|
|
150
|
+
const [result] = yield Promise.all([wrapRequest(operation(store)), done]);
|
|
151
|
+
return result;
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
transaction(mode) {
|
|
155
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
156
|
+
const db = yield this.db;
|
|
157
|
+
// The following DOMExceptions may be thrown – they should all be logically impossible, or could be
|
|
158
|
+
// triggered by the user deleting or modifying the database (e.g. via DevTools) at the right time. We won't
|
|
159
|
+
// attempt to recover from them now, but may decide to do so in the future (if we see them in the wild).
|
|
160
|
+
//
|
|
161
|
+
// InvalidStateError: `close()` has previously been called on the IDBDatabase
|
|
162
|
+
// NotFoundError: the object store does not exist.
|
|
163
|
+
// TypeError: the `mode` parameter is invalid.
|
|
164
|
+
// InvalidAccessError: the function was called with an empty list of object stores.
|
|
165
|
+
const tx = db.transaction(this.objectStore, mode);
|
|
166
|
+
// Similarly, the following DOMExceptions may be thrown by `objectStore()`:
|
|
167
|
+
//
|
|
168
|
+
// InvalidStateError: the transaction has already completed.
|
|
169
|
+
// NotFoundError: the object store is not in the transaction's scope.
|
|
170
|
+
const store = tx.objectStore(this.objectStore);
|
|
171
|
+
const done = new Promise((resolve, reject) => {
|
|
172
|
+
tx.oncomplete = () => resolve();
|
|
173
|
+
tx.onerror = () => reject(tx.error);
|
|
174
|
+
tx.onabort = () => reject(new DOMException("The transaction was aborted", "AbortError"));
|
|
175
|
+
});
|
|
176
|
+
return { tx, store, done };
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
//# sourceMappingURL=IndexedDBPersistence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IndexedDBPersistence.js","sourceRoot":"","sources":["../../src/persistence/IndexedDBPersistence.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAyB,MAAM,eAAe,CAAC;AAqBlE,SAAS,WAAW,CAAC,OAAmB;IACpC,MAAM,CAAC,GAAG,IAAI,OA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;YAC7E,kDAAkD;YAClD,8CAA8C;YAC9C,mFAAmF;YACnF,MAAM,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;YAElD,2EAA2E;YAC3E,EAAE;YACF,4DAA4D;YAC5D,qEAAqE;YACrE,MAAM,KAAK,GAAG,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YAC/C,MAAM,IAAI,GAAG,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;gBAC/C,EAAE,CAAC,UAAU,GAAG,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC;gBAChC,EAAE,CAAC,OAAO,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;gBACpC,EAAE,CAAC,OAAO,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,YAAY,CAAC,6BAA6B,EAAE,YAAY,CAAC,CAAC,CAAC;YAC7F,CAAC,CAAC,CAAC;YACH,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;QAC/B,CAAC;KAAA;CACJ","sourcesContent":["import { isValidKey, Persistence, ValidKey } from \"./Persistence\";\n\ntype IDBRequestPromise<T = any> = Promise<T> & { request: IDBRequest<T> };\n\ninterface EnhancedIDBTransaction {\n tx: IDBTransaction;\n store: IDBObjectStore;\n done: Promise<void>;\n}\n\ninterface EnhancedIDBCursor<T> {\n cursor: (IDBCursor & { readonly value: T }) | null;\n continue: () => Promise<EnhancedIDBCursor<T>>;\n}\n\n/**\n * The IndexedDB API makes use of event callbacks that can be cumbersome to use. This method wraps an IDBRequest in a\n * Promise, making it easier to use.\n */\nfunction wrapRequest(request: IDBOpenDBRequest): Promise<IDBDatabase> & { request: IDBOpenDBRequest };\nfunction wrapRequest<T>(request: IDBRequest<T>): IDBRequestPromise<T>;\nfunction wrapRequest(request: IDBRequest): IDBRequestPromise {\n const p = new Promise((resolve, reject) => {\n request.onsuccess = () => resolve(request.result);\n request.onerror = () => reject(request.error);\n });\n (p as IDBRequestPromise).request = request;\n return p as IDBRequestPromise;\n}\n\n/**\n * IndexedDB cursor requests are unique, in that their `onsuccess` handler may be called multiple times. To support\n * this, and allow for an easier-to-use Promise-based API, we wrap the cursor request to support usage like:\n * ```ts\n * let request = await wrapCursorRequest(store.openCursor())\n * while (request.cursor) {\n * console.log(request.cursor.key, request.cursor.value)\n * request = await request.continue()\n * }\n * ```\n */\nfunction wrapCursorRequest<T>(request: IDBRequest<IDBCursorWithValue | null>): Promise<EnhancedIDBCursor<T>> {\n return new Promise((resolve, reject) => {\n request.onsuccess = () => {\n const cursor = request.result;\n if (!cursor) resolve({ cursor: null, continue: () => Promise.reject() });\n else\n resolve({\n cursor,\n continue: () => {\n cursor.continue();\n return wrapCursorRequest<T>(request);\n },\n });\n };\n request.onerror = () => reject(request.error);\n });\n}\n\n/**\n * Specify a database name for this {@link IndexedDBPersistence} instance to use.\n * This will be prefixed by `Snap.CameraKit`.\n *\n * A databaseVersion and objectStore may also be specified. Keep in mind the following limitations:\n * - IndexedDBPersistence currently does nothing to migrate data between versions.\n * - If two different IndexedDBPersistence instances use the same databaseName, they must also use the same objectStore.\n * Otherwise a race condition will occur which prevents the creation of all but one objectStore per database.\n */\nexport interface IndexedDBPersistenceOptions {\n databaseName: string;\n databaseVersion?: number;\n objectStore?: string;\n}\n\n/**\n * A simple key/value persistence using an IndexedDB storage backend.\n *\n * See [Using IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB) for an\n * introduction to how IndexedDB works, its APIs, and how to use it.\n *\n * Note: Currently there is no support for database upgrades. Each instance of this class uses a single IDBObjectStore\n * object set at instantiation time, and there are no hooks for performing migrations between versions. This may be\n * added in the future if such functionality is needed.\n */\nexport class IndexedDBPersistence<T> implements Persistence<T> {\n size: number;\n\n private db: Promise<IDBDatabase>;\n private readonly databaseName: string;\n private readonly databaseVersion?: number;\n private readonly objectStore: string;\n\n /**\n * Construct an {@link IndexedDBPersistence} instance corresponding to a given IndexedDB database version.\n *\n * Throws `ConstraintError` if the version number is invalid (e.g. NaN, or less than 1).\n */\n constructor(options: IndexedDBPersistenceOptions) {\n // We'll namespace our DB names to A) avoid collisions with host applications and B) be transparent about who\n // is using persistence.\n this.databaseName = `Snap.CameraKit.${options.databaseName}`;\n this.databaseVersion = options.databaseVersion;\n this.objectStore = options.objectStore ?? options.databaseName;\n\n // `open()` will throw if the version is invalid -- this is desirable vs. rejecting the `db` promise, since then\n // the error is only reported when callers try to perform some operation. Instead, we want the instantiating\n // code to see the error.\n this.db = this.openDatabase(indexedDB.open(this.databaseName, this.databaseVersion));\n this.size = 0;\n }\n\n retrieve(key: ValidKey): Promise<T | undefined> {\n return this.simpleTransaction(\"readonly\", (store) => store.get(key));\n }\n\n retrieveAll(): Promise<T[]> {\n return this.simpleTransaction(\"readonly\", (store) => store.getAll());\n }\n\n async remove(key: ValidKey): Promise<void> {\n await this.simpleTransaction(\"readwrite\", (store) => store.delete(key));\n this.size--;\n }\n\n async removeAll(): Promise<T[]> {\n const results: T[] = [];\n const { store, done } = await this.transaction(\"readwrite\");\n let request = await wrapCursorRequest<T>(store.openCursor());\n const deleteRequests: Promise<any>[] = [];\n while (request.cursor) {\n results.push(request.cursor.value);\n // If any of the deletes fail (e.g. if the user deletes the object store during the transaction), it will\n // fail the whole transaction. Since the primary expected cause of this failure mode is that the entire\n // object store no longer exists, it's unlikely this will result in unbounded DB growth. That said, callers\n // may want to attempt to retry the removal, or raise an alarm if the persistence size grows unexpectedly.\n deleteRequests.push(wrapRequest(store.delete(request.cursor.key)));\n request = await request.continue();\n }\n await Promise.all(deleteRequests.concat(done));\n this.size = 0;\n return results;\n }\n\n async store(value: T): Promise<ValidKey>;\n async store(key: ValidKey, value: T): Promise<ValidKey>;\n async store(keyOrValue: T | ValidKey, maybeValue?: T): Promise<ValidKey> {\n const [key, value] = maybeValue === undefined ? [undefined, keyOrValue] : [keyOrValue, maybeValue];\n\n // The key must be ValidKey | undefined.\n if (!isValidKey(key) && typeof key !== \"undefined\")\n throw new TypeError(`IndexedDBPersistence failed to ` + `store a value. Invalid key type: ${typeof key}`);\n\n const storedKey = await this.simpleTransaction(\"readwrite\", (store) => store.put(value, key));\n this.size++;\n\n // Type safety: we already assert any given key is valid, and if the key is undefined IndexedDB will generate\n // a numeric key (https://w3c.github.io/IndexedDB/#key-generator).\n return storedKey as ValidKey;\n }\n\n private async openDatabase(request: IDBOpenDBRequest): Promise<IDBDatabase> {\n // The `open()` call will throw if databaseVersion is invalid (e.g. < 1).\n const dbPromise = wrapRequest(request);\n dbPromise.request.onupgradeneeded = () => {\n try {\n // The following DOMExceptions may be thrown by `createObjectStore()` – they should all be logically\n // impossible. We handle the one recoverable exception which could occur below.\n //\n // TransactionInactiveError: the database does not exist.\n // InvalidStateError: `createObjectStore` was called outside a `versionchange` transaction.\n // InvalidAccessError: `autoIncrement` is true and `keyPath` contains an empty string.\n dbPromise.request.result.createObjectStore(this.objectStore, { autoIncrement: true });\n } catch (error) {\n // ConstraintError is thrown if the object store already exists. Could happen if multiple tabs to the\n // same domain are opened and race to create the object store. In this case we can safely ignore the\n // error and continue.\n if (error instanceof DOMException && error.name === \"ConstraintError\") return;\n throw error;\n }\n };\n const db = await dbPromise;\n db.onclose = () => {\n // The 'close` event fires when the DB is unexpectedly closed (e.g. user clears application data). We'll\n // attempt to re-open it (which may fail, in which case no further attempts will be made, and all future\n // transactions will fail).\n this.db = this.openDatabase(indexedDB.open(this.databaseName, this.databaseVersion));\n };\n return db;\n }\n\n private async simpleTransaction<R>(\n mode: IDBTransactionMode,\n operation: (tx: IDBObjectStore) => IDBRequest<R>\n ): Promise<R> {\n const { store, done } = await this.transaction(mode);\n const [result] = await Promise.all([wrapRequest(operation(store)), done]);\n return result;\n }\n\n private async transaction(mode: IDBTransactionMode): Promise<EnhancedIDBTransaction> {\n const db = await this.db;\n // The following DOMExceptions may be thrown – they should all be logically impossible, or could be\n // triggered by the user deleting or modifying the database (e.g. via DevTools) at the right time. We won't\n // attempt to recover from them now, but may decide to do so in the future (if we see them in the wild).\n //\n // InvalidStateError: `close()` has previously been called on the IDBDatabase\n // NotFoundError: the object store does not exist.\n // TypeError: the `mode` parameter is invalid.\n // InvalidAccessError: the function was called with an empty list of object stores.\n const tx = db.transaction(this.objectStore, mode);\n\n // Similarly, the following DOMExceptions may be thrown by `objectStore()`:\n //\n // InvalidStateError: the transaction has already completed.\n // NotFoundError: the object store is not in the transaction's scope.\n const store = tx.objectStore(this.objectStore);\n const done = new Promise<void>((resolve, reject) => {\n tx.oncomplete = () => resolve();\n tx.onerror = () => reject(tx.error);\n tx.onabort = () => reject(new DOMException(\"The transaction was aborted\", \"AbortError\"));\n });\n return { tx, store, done };\n }\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Different persistence mechanisms (e.g. localStorage, IndexedDB) may support different key types. This type should be
|
|
3
|
+
* a valid key across all concrete Persistence implementations.
|
|
4
|
+
*/
|
|
5
|
+
export declare type ValidKey = string | number;
|
|
6
|
+
export declare const isValidKey: (key: unknown) => key is ValidKey;
|
|
7
|
+
/**
|
|
8
|
+
* The abstract Persistence class defines an async interface for interacting with persistent client-side storage. This
|
|
9
|
+
* is modeled as a simple key/value store.
|
|
10
|
+
*
|
|
11
|
+
* Subclasses may be implemented to support a variety of persistence mechanisms – e.g. localStorage, IndexedDB, etc.
|
|
12
|
+
*/
|
|
13
|
+
export declare abstract class Persistence<T> {
|
|
14
|
+
abstract size: number;
|
|
15
|
+
abstract retrieve(key: ValidKey): Promise<T | undefined>;
|
|
16
|
+
abstract retrieveAll(): Promise<T[]>;
|
|
17
|
+
abstract remove(key: ValidKey): Promise<void>;
|
|
18
|
+
abstract removeAll(): Promise<T[]>;
|
|
19
|
+
/**
|
|
20
|
+
* Persistence implementations must be capable of generating unique keys, or accepting a unique key from the
|
|
21
|
+
* caller.
|
|
22
|
+
*/
|
|
23
|
+
abstract store(value: T): Promise<ValidKey>;
|
|
24
|
+
abstract store(key: ValidKey, value: T): Promise<ValidKey>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const isValidKey = (key) => typeof key === "string" || typeof key === "number";
|
|
2
|
+
/**
|
|
3
|
+
* The abstract Persistence class defines an async interface for interacting with persistent client-side storage. This
|
|
4
|
+
* is modeled as a simple key/value store.
|
|
5
|
+
*
|
|
6
|
+
* Subclasses may be implemented to support a variety of persistence mechanisms – e.g. localStorage, IndexedDB, etc.
|
|
7
|
+
*/
|
|
8
|
+
export class Persistence {
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=Persistence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Persistence.js","sourceRoot":"","sources":["../../src/persistence/Persistence.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,GAAY,EAAmB,EAAE,CAAC,OAAO,GAAG,KAAK,QAAQ,IAAI,OAAO,GAAG,KAAK,QAAQ,CAAC;AAEhH;;;;;GAKG;AACH,MAAM,OAAgB,WAAW;CAiBhC","sourcesContent":["/**\n * Different persistence mechanisms (e.g. localStorage, IndexedDB) may support different key types. This type should be\n * a valid key across all concrete Persistence implementations.\n */\nexport type ValidKey = string | number;\n\nexport const isValidKey = (key: unknown): key is ValidKey => typeof key === \"string\" || typeof key === \"number\";\n\n/**\n * The abstract Persistence class defines an async interface for interacting with persistent client-side storage. This\n * is modeled as a simple key/value store.\n *\n * Subclasses may be implemented to support a variety of persistence mechanisms – e.g. localStorage, IndexedDB, etc.\n */\nexport abstract class Persistence<T> {\n abstract size: number;\n\n abstract retrieve(key: ValidKey): Promise<T | undefined>;\n\n abstract retrieveAll(): Promise<T[]>;\n\n abstract remove(key: ValidKey): Promise<void>;\n\n abstract removeAll(): Promise<T[]>;\n\n /**\n * Persistence implementations must be capable of generating unique keys, or accepting a unique key from the\n * caller.\n */\n abstract store(value: T): Promise<ValidKey>;\n abstract store(key: ValidKey, value: T): Promise<ValidKey>;\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ConfigTargetingRequest } from "../generated-proto/pb_schema/cdp/cof/config_request";
|
|
2
|
+
import { ConfigTargetingResponse } from "../generated-proto/pb_schema/cdp/cof/config_response";
|
|
3
|
+
interface Metadata {
|
|
4
|
+
[key: string]: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const COF_REQUEST_TYPE = "cof";
|
|
7
|
+
export declare type CofDimensions = {
|
|
8
|
+
requestType: typeof COF_REQUEST_TYPE;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Handler chain used to make COF requests. Uses the COF client to perform the
|
|
12
|
+
* requests, with retries, timeout, and caching.
|
|
13
|
+
*
|
|
14
|
+
* The handler will first attempt to retrieve the COF response from cache. If it is found, the result is returned
|
|
15
|
+
* immediately and the cache is updated in the background. If no response is found, a COF request is made. This request
|
|
16
|
+
* will retry (with exponential backoff + jitter) for 5 seconds before returning an error to the caller.
|
|
17
|
+
*/
|
|
18
|
+
export declare const cofHandlerFactory: (apiToken: string) => import("../handlers/HandlerChainBuilder").Handler<Partial<ConfigTargetingRequest>, ConfigTargetingResponse, Metadata & {
|
|
19
|
+
signal?: AbortSignal | null | undefined;
|
|
20
|
+
}>;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { __awaiter, __rest } from "tslib";
|
|
2
|
+
import { BrowserHeaders } from "browser-headers";
|
|
3
|
+
import { cameraKitUserAgent } from "../common/cameraKitUserAgent";
|
|
4
|
+
import { ensureError } from "../common/errorHelpers";
|
|
5
|
+
import { CircumstancesServiceClientImpl, GrpcWebImpl } from "../generated-proto/pb_schema/cdp/cof/circumstance_service";
|
|
6
|
+
import { HandlerChainBuilder } from "../handlers/HandlerChainBuilder";
|
|
7
|
+
import { dispatchRequestCompleted, dispatchRequestErrored, dispatchRequestStarted, } from "../handlers/requestStateEmittingHandler";
|
|
8
|
+
import { createResponseCachingHandler, staleWhileRevalidateStrategy } from "../handlers/responseCachingHandler";
|
|
9
|
+
import { createRetryingHandler } from "../handlers/retryingHandler";
|
|
10
|
+
import { createTimeoutHandler } from "../handlers/timeoutHandler";
|
|
11
|
+
import { ExpiringPersistence } from "../persistence/ExpiringPersistence";
|
|
12
|
+
import { IndexedDBPersistence } from "../persistence/IndexedDBPersistence";
|
|
13
|
+
const id = (h) => h;
|
|
14
|
+
// We need to wrap `targetingQuery` to create a usable Handler – the main issue is that HandlerChainBuilder always adds
|
|
15
|
+
// a `signal` property to the metadata argument (second argument of the Handler), but `targetingQuery` expects the
|
|
16
|
+
// second argument to only contain headers.
|
|
17
|
+
const createTargetingQueryHandler = (apiToken) => (request, _a) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
var { signal } = _a, metadata = __rest(_a, ["signal"]);
|
|
19
|
+
const rpc = new GrpcWebImpl("https://api-kit.snapchat.com", {});
|
|
20
|
+
const client = new CircumstancesServiceClientImpl(rpc);
|
|
21
|
+
const response = yield client.targetingQuery(request, new BrowserHeaders(Object.assign({ authorization: `Bearer ${apiToken}`, "x-snap-client-user-agent": cameraKitUserAgent.userAgent }, metadata)));
|
|
22
|
+
// NOTE: in order for cache persistance to work, we need to make the object cloneable,
|
|
23
|
+
// i.e. with no methods (it appears targetingQuery() attaches toObject() to response object).
|
|
24
|
+
delete response["toObject"];
|
|
25
|
+
return response;
|
|
26
|
+
});
|
|
27
|
+
export const COF_REQUEST_TYPE = "cof";
|
|
28
|
+
/**
|
|
29
|
+
* Handler chain used to make COF requests. Uses the COF client to perform the
|
|
30
|
+
* requests, with retries, timeout, and caching.
|
|
31
|
+
*
|
|
32
|
+
* The handler will first attempt to retrieve the COF response from cache. If it is found, the result is returned
|
|
33
|
+
* immediately and the cache is updated in the background. If no response is found, a COF request is made. This request
|
|
34
|
+
* will retry (with exponential backoff + jitter) for 5 seconds before returning an error to the caller.
|
|
35
|
+
*/
|
|
36
|
+
export const cofHandlerFactory = (apiToken) => new HandlerChainBuilder(createTargetingQueryHandler(apiToken))
|
|
37
|
+
.map(id((next) => (request, metadata) => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
+
const dimensions = { requestType: COF_REQUEST_TYPE };
|
|
39
|
+
const { requestId } = dispatchRequestStarted({ dimensions });
|
|
40
|
+
try {
|
|
41
|
+
const response = yield next(request, metadata);
|
|
42
|
+
// TODO: We hardcode status code and sizeByte values because we do not have access to underlying
|
|
43
|
+
// transport of configs-web.
|
|
44
|
+
// When this ticket is done https://jira.sc-corp.net/browse/CAMKIT-2840,
|
|
45
|
+
// we will remove this handler and benefit from existing ones.
|
|
46
|
+
const status = 200;
|
|
47
|
+
let sizeByte = 0;
|
|
48
|
+
try {
|
|
49
|
+
sizeByte = new TextEncoder().encode(JSON.stringify(response)).byteLength;
|
|
50
|
+
}
|
|
51
|
+
finally {
|
|
52
|
+
dispatchRequestCompleted({ requestId, dimensions, status, sizeByte });
|
|
53
|
+
return response;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
dispatchRequestErrored({ requestId, dimensions, error: ensureError(error) });
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
})))
|
|
61
|
+
// targetingQuery() always converts failed responses into errors (unlike fetch()), so we need a custom
|
|
62
|
+
// retryPredicate that retries all errors. We'll keep retrying (with backoff) for 20 seconds total elapsed
|
|
63
|
+
// time before we return an error back up the chain.
|
|
64
|
+
.map(createRetryingHandler({ retryPredicate: (r) => r instanceof Error }))
|
|
65
|
+
// API gateway has 15 seconds timeout, so we rely on that first
|
|
66
|
+
.map(createTimeoutHandler({ timeout: 20 * 1000 }))
|
|
67
|
+
.map(createResponseCachingHandler(
|
|
68
|
+
// COF responses will be removed from cache after 1 week. Keep in mind that the staleWhileRevalidate
|
|
69
|
+
// strategy will update the cache each time COF is requested – this expiration comes into play only if
|
|
70
|
+
// e.g. a user doesn't load the page for more than a week.
|
|
71
|
+
new ExpiringPersistence(() => 7 * 24 * 60 * 60, new IndexedDBPersistence({ databaseName: "COFCache" })), (r) => JSON.stringify(r),
|
|
72
|
+
// If we have a matching response already in cache, we'll return it immediately and then update the
|
|
73
|
+
// cache in the background.
|
|
74
|
+
staleWhileRevalidateStrategy())).handler;
|
|
75
|
+
//# sourceMappingURL=cofHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cofHandler.js","sourceRoot":"","sources":["../../src/remote-configuration/cofHandler.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,8BAA8B,EAAE,WAAW,EAAE,MAAM,2DAA2D,CAAC;AAGxH,OAAO,EAAoB,mBAAmB,EAAmB,MAAM,iCAAiC,CAAC;AACzG,OAAO,EACH,wBAAwB,EACxB,sBAAsB,EACtB,sBAAsB,GACzB,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,4BAA4B,EAAE,4BAA4B,EAAE,MAAM,oCAAoC,CAAC;AAChH,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAM3E,MAAM,EAAE,GAAG,CAAyC,CAA6C,EAAE,EAAE,CAAC,CAAC,CAAC;AAExG,uHAAuH;AACvH,kHAAkH;AAClH,2CAA2C;AAC3C,MAAM,2BAA2B,GAAG,CAAC,QAAgB,EAAE,EAAE,CAAC,CACtD,OAAwC,EACxC,EAAmD,EACrD,EAAE;QADA,EAAE,MAAM,OAA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Q,CAAC,CAAC,CAAC,UAAU,CAAC;SAC5E;gBAAS;YACN,wBAAwB,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;YACtE,OAAO,QAAQ,CAAC;SACnB;KACJ;IAAC,OAAO,KAAK,EAAE;QACZ,sBAAsB,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC7E,MAAM,KAAK,CAAC;KACf;AACL,CAAC,CAAA,CAAC,CACL;IACD,sGAAsG;IACtG,0GAA0G;IAC1G,oDAAoD;KACnD,GAAG,CAAC,qBAAqB,CAAC,EAAE,cAAc,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,YAAY,KAAK,EAAE,CAAC,CAAC;IAC1E,+DAA+D;KAC9D,GAAG,CAAC,oBAAoB,CAAC,EAAE,OAAO,EAAE,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;KACjD,GAAG,CACA,4BAA4B;AACxB,oGAAoG;AACpG,sGAAsG;AACtG,0DAA0D;AAC1D,IAAI,mBAAmB,CACnB,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,EACtB,IAAI,oBAAoB,CAAC,EAAE,YAAY,EAAE,UAAU,EAAE,CAAC,CACzD,EACD,CAAC,CAAkC,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;AAEzD,mGAAmG;AACnG,2BAA2B;AAC3B,4BAA4B,EAAE,CACjC,CACJ,CAAC,OAAO,CAAC","sourcesContent":["import { BrowserHeaders } from \"browser-headers\";\nimport { cameraKitUserAgent } from \"../common/cameraKitUserAgent\";\nimport { ensureError } from \"../common/errorHelpers\";\nimport { CircumstancesServiceClientImpl, GrpcWebImpl } from \"../generated-proto/pb_schema/cdp/cof/circumstance_service\";\nimport { ConfigTargetingRequest } from \"../generated-proto/pb_schema/cdp/cof/config_request\";\nimport { ConfigTargetingResponse } from \"../generated-proto/pb_schema/cdp/cof/config_response\";\nimport { ChainableHandler, HandlerChainBuilder, RequestMetadata } from \"../handlers/HandlerChainBuilder\";\nimport {\n dispatchRequestCompleted,\n dispatchRequestErrored,\n dispatchRequestStarted,\n} from \"../handlers/requestStateEmittingHandler\";\nimport { createResponseCachingHandler, staleWhileRevalidateStrategy } from \"../handlers/responseCachingHandler\";\nimport { createRetryingHandler } from \"../handlers/retryingHandler\";\nimport { createTimeoutHandler } from \"../handlers/timeoutHandler\";\nimport { ExpiringPersistence } from \"../persistence/ExpiringPersistence\";\nimport { IndexedDBPersistence } from \"../persistence/IndexedDBPersistence\";\n\ninterface Metadata {\n [key: string]: string;\n}\n\nconst id = <Req, Res, Meta extends RequestMetadata>(h: ChainableHandler<Req, Res, Req, Res, Meta>) => h;\n\n// We need to wrap `targetingQuery` to create a usable Handler – the main issue is that HandlerChainBuilder always adds\n// a `signal` property to the metadata argument (second argument of the Handler), but `targetingQuery` expects the\n// second argument to only contain headers.\nconst createTargetingQueryHandler = (apiToken: string) => async (\n request: Partial<ConfigTargetingRequest>,\n { signal, ...metadata }: Metadata & RequestMetadata\n) => {\n const rpc = new GrpcWebImpl(\"https://api-kit.snapchat.com\", {});\n const client = new CircumstancesServiceClientImpl(rpc);\n const response = await client.targetingQuery(\n request,\n new BrowserHeaders({\n authorization: `Bearer ${apiToken}`,\n \"x-snap-client-user-agent\": cameraKitUserAgent.userAgent,\n ...metadata,\n })\n );\n\n // NOTE: in order for cache persistance to work, we need to make the object cloneable,\n // i.e. with no methods (it appears targetingQuery() attaches toObject() to response object).\n delete response[\"toObject\"];\n return response;\n};\n\nexport const COF_REQUEST_TYPE = \"cof\";\n\nexport type CofDimensions = { requestType: typeof COF_REQUEST_TYPE };\n\n/**\n * Handler chain used to make COF requests. Uses the COF client to perform the\n * requests, with retries, timeout, and caching.\n *\n * The handler will first attempt to retrieve the COF response from cache. If it is found, the result is returned\n * immediately and the cache is updated in the background. If no response is found, a COF request is made. This request\n * will retry (with exponential backoff + jitter) for 5 seconds before returning an error to the caller.\n */\nexport const cofHandlerFactory = (apiToken: string) =>\n new HandlerChainBuilder(createTargetingQueryHandler(apiToken))\n .map(\n id((next) => async (request, metadata) => {\n const dimensions: CofDimensions = { requestType: COF_REQUEST_TYPE };\n const { requestId } = dispatchRequestStarted({ dimensions });\n try {\n const response = await next(request, metadata);\n // TODO: We hardcode status code and sizeByte values because we do not have access to underlying\n // transport of configs-web.\n // When this ticket is done https://jira.sc-corp.net/browse/CAMKIT-2840,\n // we will remove this handler and benefit from existing ones.\n const status = 200;\n let sizeByte = 0;\n try {\n sizeByte = new TextEncoder().encode(JSON.stringify(response)).byteLength;\n } finally {\n dispatchRequestCompleted({ requestId, dimensions, status, sizeByte });\n return response;\n }\n } catch (error) {\n dispatchRequestErrored({ requestId, dimensions, error: ensureError(error) });\n throw error;\n }\n })\n )\n // targetingQuery() always converts failed responses into errors (unlike fetch()), so we need a custom\n // retryPredicate that retries all errors. We'll keep retrying (with backoff) for 20 seconds total elapsed\n // time before we return an error back up the chain.\n .map(createRetryingHandler({ retryPredicate: (r) => r instanceof Error }))\n // API gateway has 15 seconds timeout, so we rely on that first\n .map(createTimeoutHandler({ timeout: 20 * 1000 }))\n .map(\n createResponseCachingHandler(\n // COF responses will be removed from cache after 1 week. Keep in mind that the staleWhileRevalidate\n // strategy will update the cache each time COF is requested – this expiration comes into play only if\n // e.g. a user doesn't load the page for more than a week.\n new ExpiringPersistence<ConfigTargetingResponse>(\n () => 7 * 24 * 60 * 60,\n new IndexedDBPersistence({ databaseName: \"COFCache\" })\n ),\n (r: Partial<ConfigTargetingRequest>) => JSON.stringify(r),\n\n // If we have a matching response already in cache, we'll return it immediately and then update the\n // cache in the background.\n staleWhileRevalidateStrategy()\n )\n ).handler;\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Observable } from "rxjs";
|
|
2
|
+
import { CameraKitConfiguration } from "../configuration";
|
|
3
|
+
import { ConfigResult } from "../generated-proto/pb_schema/cdp/cof/config_result";
|
|
4
|
+
export declare class RemoteConfiguration {
|
|
5
|
+
private readonly configById;
|
|
6
|
+
constructor(apiToken: string, lensPerformance: CameraKitConfiguration["lensPerformance"]);
|
|
7
|
+
get(configId: string): Observable<ConfigResult[]>;
|
|
8
|
+
}
|
|
9
|
+
export declare const remoteConfigurationFactory: {
|
|
10
|
+
(args_0: CameraKitConfiguration): RemoteConfiguration;
|
|
11
|
+
token: "remoteConfiguration";
|
|
12
|
+
dependencies: readonly ["configuration"];
|
|
13
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { from, map, mergeMap, shareReplay, take } from "rxjs";
|
|
2
|
+
import { configurationToken } from "../configuration";
|
|
3
|
+
import { Injectable } from "../dependency-injection/Injectable";
|
|
4
|
+
import { Namespace } from "../generated-proto/pb_schema/cdp/cof/namespace";
|
|
5
|
+
import { cofHandlerFactory } from "./cofHandler";
|
|
6
|
+
const defaultTargetingRequest = {
|
|
7
|
+
namespaces: [Namespace.LENS_CORE, Namespace.CAMERA_KIT_CORE],
|
|
8
|
+
};
|
|
9
|
+
export class RemoteConfiguration {
|
|
10
|
+
constructor(apiToken, lensPerformance) {
|
|
11
|
+
const lensCluster = Promise.resolve(lensPerformance).then((lensPerformance) => {
|
|
12
|
+
// `0` means no cluster could be determined. For COF, we'll omit a value in that case.
|
|
13
|
+
return (lensPerformance === null || lensPerformance === void 0 ? void 0 : lensPerformance.cluster) === 0 ? undefined : lensPerformance === null || lensPerformance === void 0 ? void 0 : lensPerformance.cluster;
|
|
14
|
+
});
|
|
15
|
+
const cofHandler = cofHandlerFactory(apiToken);
|
|
16
|
+
this.configById = from(lensCluster).pipe(
|
|
17
|
+
// Note: we don't catch errors here, purposefully letting them propagate to subscribers outside this class.
|
|
18
|
+
// Subscribers, having more context about the config use-case, will know better how to handle an error than
|
|
19
|
+
// we do here (e.g. their logging / reporting will have more context, and they can use the error they get
|
|
20
|
+
// from this Observable as a cause).
|
|
21
|
+
mergeMap((lensClusterOrig4) => from(cofHandler(Object.assign(Object.assign({}, defaultTargetingRequest), { lensClusterOrig4 })))), map((result) => {
|
|
22
|
+
const configById = new Map();
|
|
23
|
+
result.configResults.forEach((config) => {
|
|
24
|
+
var _a;
|
|
25
|
+
const configsWithId = (_a = configById.get(config.configId)) !== null && _a !== void 0 ? _a : [];
|
|
26
|
+
configsWithId.push(config);
|
|
27
|
+
configById.set(config.configId, configsWithId);
|
|
28
|
+
});
|
|
29
|
+
return configById;
|
|
30
|
+
}), shareReplay(1));
|
|
31
|
+
}
|
|
32
|
+
get(configId) {
|
|
33
|
+
return this.configById.pipe(map((config) => { var _a; return (_a = config.get(configId)) !== null && _a !== void 0 ? _a : []; }));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export const remoteConfigurationFactory = Injectable("remoteConfiguration", [configurationToken], (config) => {
|
|
37
|
+
const remoteConfig = new RemoteConfiguration(config.apiToken, config.lensPerformance);
|
|
38
|
+
// We'll kick off remote configuration loading by subscribing (and then unsubscribing) to a dummy config value.
|
|
39
|
+
// Subsequent requests for config will use the shared Observable, benefitting from this eager loading.
|
|
40
|
+
remoteConfig.get("").pipe(take(1)).subscribe();
|
|
41
|
+
return remoteConfig;
|
|
42
|
+
});
|
|
43
|
+
//# sourceMappingURL=remoteConfiguration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remoteConfiguration.js","sourceRoot":"","sources":["../../src/remote-configuration/remoteConfiguration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAc,WAAW,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC1E,OAAO,EAA0B,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAGhE,OAAO,EAAE,SAAS,EAAE,MAAM,gDAAgD,CAAC;AAC3E,OAAO,E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,OAAO,UAAU,CAAC;QACtB,CAAC,CAAC,EACF,WAAW,CAAC,CAAC,CAAC,CACjB,CAAC;IACN,CAAC;IAED,GAAG,CAAC,QAAgB;QAChB,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,WAAC,OAAA,MAAA,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,mCAAI,EAAE,CAAA,EAAA,CAAC,CAAC,CAAC;IAC7E,CAAC;CACJ;AAED,MAAM,CAAC,MAAM,0BAA0B,GAAG,UAAU,CAChD,qBAAqB,EACrB,CAAC,kBAAkB,CAAU,EAC7B,CAAC,MAA8B,EAAuB,EAAE;IACpD,MAAM,YAAY,GAAG,IAAI,mBAAmB,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,CAAC;IAEtF,+GAA+G;IAC/G,sGAAsG;IACtG,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;IAE/C,OAAO,YAAY,CAAC;AACxB,CAAC,CACJ,CAAC","sourcesContent":["import { from, map, mergeMap, Observable, shareReplay, take } from \"rxjs\";\nimport { CameraKitConfiguration, configurationToken } from \"../configuration\";\nimport { Injectable } from \"../dependency-injection/Injectable\";\nimport { ConfigTargetingRequest } from \"../generated-proto/pb_schema/cdp/cof/config_request\";\nimport { ConfigResult } from \"../generated-proto/pb_schema/cdp/cof/config_result\";\nimport { Namespace } from \"../generated-proto/pb_schema/cdp/cof/namespace\";\nimport { cofHandlerFactory } from \"./cofHandler\";\n\nconst defaultTargetingRequest: Partial<ConfigTargetingRequest> = {\n namespaces: [Namespace.LENS_CORE, Namespace.CAMERA_KIT_CORE],\n};\n\nexport class RemoteConfiguration {\n private readonly configById: Observable<Map<string, ConfigResult[]>>;\n\n constructor(apiToken: string, lensPerformance: CameraKitConfiguration[\"lensPerformance\"]) {\n const lensCluster = Promise.resolve(lensPerformance).then((lensPerformance) => {\n // `0` means no cluster could be determined. For COF, we'll omit a value in that case.\n return lensPerformance?.cluster === 0 ? undefined : lensPerformance?.cluster;\n });\n\n const cofHandler = cofHandlerFactory(apiToken);\n\n this.configById = from(lensCluster).pipe(\n // Note: we don't catch errors here, purposefully letting them propagate to subscribers outside this class.\n // Subscribers, having more context about the config use-case, will know better how to handle an error than\n // we do here (e.g. their logging / reporting will have more context, and they can use the error they get\n // from this Observable as a cause).\n mergeMap((lensClusterOrig4) =>\n from(\n cofHandler({\n ...defaultTargetingRequest,\n lensClusterOrig4,\n })\n )\n ),\n map((result) => {\n const configById = new Map<string, ConfigResult[]>();\n result.configResults.forEach((config) => {\n const configsWithId = configById.get(config.configId) ?? [];\n configsWithId.push(config);\n configById.set(config.configId, configsWithId);\n });\n return configById;\n }),\n shareReplay(1)\n );\n }\n\n get(configId: string): Observable<ConfigResult[]> {\n return this.configById.pipe(map((config) => config.get(configId) ?? []));\n }\n}\n\nexport const remoteConfigurationFactory = Injectable(\n \"remoteConfiguration\",\n [configurationToken] as const,\n (config: CameraKitConfiguration): RemoteConfiguration => {\n const remoteConfig = new RemoteConfiguration(config.apiToken, config.lensPerformance);\n\n // We'll kick off remote configuration loading by subscribing (and then unsubscribing) to a dummy config value.\n // Subsequent requests for config will use the shared Observable, benefitting from this eager loading.\n remoteConfig.get(\"\").pipe(take(1)).subscribe();\n\n return remoteConfig;\n }\n);\n"]}
|