@snap/camera-kit 0.11.0 → 0.12.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/README.md +242 -67
- package/docs/html/assets/search.js +1 -1
- package/docs/html/classes/CameraKit.html +3 -3
- package/docs/html/classes/CameraKitSession.html +3 -3
- package/docs/html/classes/CameraKitSource.html +3 -3
- package/docs/html/classes/LensPerformanceMeasurement.html +3 -3
- package/docs/html/classes/LensPerformanceMetrics.html +3 -3
- package/docs/html/classes/LensRepository.html +3 -3
- package/docs/html/classes/LensSources.html +3 -3
- package/docs/html/classes/Transform2D.html +3 -3
- package/docs/html/classes/TypedCustomEvent.html +3 -3
- package/docs/html/classes/TypedEventTarget.html +3 -3
- package/docs/html/functions/Injectable.html +3 -3
- package/docs/html/functions/bootstrapCameraKit.html +3 -3
- package/docs/html/functions/createExtension.html +3 -3
- package/docs/html/functions/createImageSource.html +3 -3
- package/docs/html/functions/createMediaStreamSource.html +3 -3
- package/docs/html/functions/createUserMediaSource.html +3 -3
- package/docs/html/functions/createVideoSource.html +3 -3
- package/docs/html/functions/estimateLensPerformance.html +3 -3
- package/docs/html/functions/getRequiredBootstrapURLs.html +3 -3
- package/docs/html/functions/lensSourcesFactory.html +3 -3
- package/docs/html/functions/uriHandlersFactory.html +3 -3
- package/docs/html/index.html +162 -46
- package/docs/html/interfaces/CameraKitBootstrapConfiguration.html +3 -3
- package/docs/html/interfaces/CameraKitSourceSubscriber.html +3 -3
- package/docs/html/interfaces/ComputedFrameMetrics.html +3 -3
- package/docs/html/interfaces/CreateSessionOptions.html +3 -3
- package/docs/html/interfaces/EstimatedLensPerformance.html +3 -3
- package/docs/html/interfaces/Lens.html +3 -3
- package/docs/html/interfaces/LensSource.html +3 -3
- package/docs/html/interfaces/MediaStreamSourceOptions.html +3 -3
- package/docs/html/interfaces/Preview.html +3 -3
- package/docs/html/interfaces/Snapcode.html +3 -3
- package/docs/html/interfaces/UriCancelRequest.html +3 -3
- package/docs/html/interfaces/UriHandler.html +3 -3
- package/docs/html/interfaces/UriRequest.html +10 -5
- package/docs/html/interfaces/UriResponse.html +3 -3
- package/docs/html/interfaces/VideoSourceOptions.html +3 -3
- package/docs/html/modules.html +4 -4
- package/docs/html/types/AssetLoader.html +3 -3
- package/docs/html/types/AssetTiming.html +3 -3
- package/docs/html/types/BenchmarkError.html +3 -3
- package/docs/html/types/BootstrapError.html +3 -3
- package/docs/html/types/CacheKeyNotFoundError.html +3 -3
- package/docs/html/types/CameraKitDeviceInfo.html +3 -3
- package/docs/html/types/CameraKitSessionEventListener.html +3 -3
- package/docs/html/types/CameraKitSessionEvents.html +3 -3
- package/docs/html/types/CameraKitSourceError.html +3 -3
- package/docs/html/types/CameraKitSourceInfo.html +3 -3
- package/docs/html/types/CameraKitSourceOptions.html +3 -3
- package/docs/html/types/ConfigurationError.html +3 -3
- package/docs/html/types/Keyboard.html +3 -3
- package/docs/html/types/KeyboardEvents.html +3 -3
- package/docs/html/types/LegalError.html +3 -3
- package/docs/html/types/LensAssetError.html +3 -3
- package/docs/html/types/LensContentValidationError.html +3 -3
- package/docs/html/types/LensError.html +3 -3
- package/docs/html/types/LensExecutionError.html +3 -3
- package/docs/html/types/LensImagePickerError.html +3 -3
- package/docs/html/types/LensLaunchParams.html +3 -3
- package/docs/html/types/LensMetricsEvents.html +3 -3
- package/docs/html/types/LensPerformanceCluster.html +3 -3
- package/docs/html/types/LensView.html +3 -3
- package/docs/html/types/LensWait.html +3 -3
- package/docs/html/types/PersistentStoreError.html +3 -3
- package/docs/html/types/PlatformNotSupportedError.html +3 -3
- package/docs/html/types/PublicContainer.html +3 -3
- package/docs/html/types/RenderTarget.html +3 -3
- package/docs/html/types/Uri.html +3 -3
- package/docs/html/types/UriHandlers.html +3 -3
- package/docs/html/types/WebGLError.html +3 -3
- package/docs/html/variables/extensionRequestContext.html +3 -3
- package/docs/md/README.md +242 -67
- package/docs/md/classes/CameraKit.md +1 -1
- package/docs/md/classes/CameraKitSession.md +1 -1
- package/docs/md/classes/CameraKitSource.md +1 -1
- package/docs/md/classes/LensPerformanceMeasurement.md +1 -1
- package/docs/md/classes/LensPerformanceMetrics.md +1 -1
- package/docs/md/classes/LensRepository.md +1 -1
- package/docs/md/classes/LensSources.md +1 -1
- package/docs/md/classes/Transform2D.md +1 -1
- package/docs/md/classes/TypedCustomEvent.md +1 -1
- package/docs/md/classes/TypedEventTarget.md +1 -1
- package/docs/md/interfaces/CameraKitBootstrapConfiguration.md +1 -1
- package/docs/md/interfaces/CameraKitSourceSubscriber.md +1 -1
- package/docs/md/interfaces/ComputedFrameMetrics.md +1 -1
- package/docs/md/interfaces/CreateSessionOptions.md +1 -1
- package/docs/md/interfaces/EstimatedLensPerformance.md +1 -1
- package/docs/md/interfaces/Lens.md +1 -1
- package/docs/md/interfaces/LensSource.md +1 -1
- package/docs/md/interfaces/MediaStreamSourceOptions.md +1 -1
- package/docs/md/interfaces/Preview.md +1 -1
- package/docs/md/interfaces/Snapcode.md +1 -1
- package/docs/md/interfaces/UriCancelRequest.md +1 -1
- package/docs/md/interfaces/UriHandler.md +1 -1
- package/docs/md/interfaces/UriRequest.md +8 -1
- package/docs/md/interfaces/UriResponse.md +1 -1
- package/docs/md/interfaces/VideoSourceOptions.md +1 -1
- package/docs/md/modules.md +2 -2
- package/lib/CameraKit.d.ts +16 -6
- package/lib/assertPlatformSupported.d.ts +3 -1
- package/lib/assertPlatformSupported.js +13 -2
- package/lib/assertPlatformSupported.js.map +1 -1
- package/lib/bootstrapCameraKit.js +2 -0
- package/lib/bootstrapCameraKit.js.map +1 -1
- package/lib/common/cameraKitUserAgent.js +17 -2
- package/lib/common/cameraKitUserAgent.js.map +1 -1
- package/lib/common/dialog.d.ts +43 -0
- package/lib/common/dialog.js +26 -12
- package/lib/common/dialog.js.map +1 -1
- package/lib/configuration.d.ts +2 -0
- package/lib/configuration.js +1 -0
- package/lib/configuration.js.map +1 -1
- package/lib/dependency-injection/RootServices.d.ts +2 -0
- package/lib/dependency-injection/RootServices.js.map +1 -1
- package/lib/environment.json +1 -1
- package/lib/generated-proto/blizzard/cameraKitEvents.js.map +1 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.d.ts +0 -26
- package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.js +0 -15
- package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.js.map +1 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/export.d.ts +0 -59
- package/lib/generated-proto/pb_schema/camera_kit/v3/export.js +0 -10
- package/lib/generated-proto/pb_schema/camera_kit/v3/export.js.map +1 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.d.ts +0 -13
- package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.js +0 -7
- package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.js.map +1 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/lens.d.ts +0 -55
- package/lib/generated-proto/pb_schema/camera_kit/v3/lens.js +0 -12
- package/lib/generated-proto/pb_schema/camera_kit/v3/lens.js.map +1 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.d.ts +0 -5
- package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.js +0 -7
- package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.js.map +1 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.d.ts +0 -23
- package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.js +0 -15
- package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.js.map +1 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/service.d.ts +0 -62
- package/lib/generated-proto/pb_schema/camera_kit/v3/service.js +0 -1
- package/lib/generated-proto/pb_schema/camera_kit/v3/service.js.map +1 -1
- package/lib/generated-proto/pb_schema/cdp/cof/benchmark.d.ts +0 -8
- package/lib/generated-proto/pb_schema/cdp/cof/benchmark.js +0 -1
- package/lib/generated-proto/pb_schema/cdp/cof/benchmark.js.map +1 -1
- package/lib/generated-proto/pb_schema/cdp/cof/benchmark_name.d.ts +0 -45
- package/lib/generated-proto/pb_schema/cdp/cof/benchmark_name.js +0 -46
- package/lib/generated-proto/pb_schema/cdp/cof/benchmark_name.js.map +1 -1
- package/lib/generated-proto/pb_schema/cdp/cof/circumstance_service.d.ts +0 -104
- package/lib/generated-proto/pb_schema/cdp/cof/circumstance_service.js +0 -1
- package/lib/generated-proto/pb_schema/cdp/cof/circumstance_service.js.map +1 -1
- package/lib/generated-proto/pb_schema/cdp/cof/config_request.d.ts +0 -129
- package/lib/generated-proto/pb_schema/cdp/cof/config_request.js +0 -24
- package/lib/generated-proto/pb_schema/cdp/cof/config_request.js.map +1 -1
- package/lib/generated-proto/pb_schema/cdp/cof/config_response.d.ts +0 -22
- package/lib/generated-proto/pb_schema/cdp/cof/config_response.js +0 -1
- package/lib/generated-proto/pb_schema/cdp/cof/config_response.js.map +1 -1
- package/lib/generated-proto/pb_schema/cdp/cof/config_result.d.ts +0 -510
- package/lib/generated-proto/pb_schema/cdp/cof/config_result.js +0 -415
- package/lib/generated-proto/pb_schema/cdp/cof/config_result.js.map +1 -1
- package/lib/generated-proto/pb_schema/cdp/cof/debug_info.d.ts +0 -9
- package/lib/generated-proto/pb_schema/cdp/cof/debug_info.js +0 -3
- package/lib/generated-proto/pb_schema/cdp/cof/debug_info.js.map +1 -1
- package/lib/generated-proto/pb_schema/cdp/cof/namespace.d.ts +0 -1
- package/lib/generated-proto/pb_schema/cdp/cof/namespace.js +0 -2
- package/lib/generated-proto/pb_schema/cdp/cof/namespace.js.map +1 -1
- package/lib/generated-proto/pb_schema/common/ruid.d.ts +0 -27
- package/lib/generated-proto/pb_schema/common/ruid.js +0 -20
- package/lib/generated-proto/pb_schema/common/ruid.js.map +1 -1
- package/lib/generated-proto/pb_schema/common/value.d.ts +0 -9
- package/lib/generated-proto/pb_schema/common/value.js +0 -1
- package/lib/generated-proto/pb_schema/common/value.js.map +1 -1
- package/lib/generated-proto/pb_schema/google/protobuf/any.d.ts +0 -105
- package/lib/generated-proto/pb_schema/google/protobuf/any.js +0 -1
- package/lib/generated-proto/pb_schema/google/protobuf/any.js.map +1 -1
- package/lib/generated-proto/pb_schema/google/protobuf/timestamp.d.ts +0 -64
- package/lib/generated-proto/pb_schema/google/protobuf/timestamp.js +0 -1
- package/lib/generated-proto/pb_schema/google/protobuf/timestamp.js.map +1 -1
- package/lib/generated-proto/pb_schema/google/protobuf/wrappers.d.ts +0 -54
- package/lib/generated-proto/pb_schema/google/protobuf/wrappers.js +0 -1
- package/lib/generated-proto/pb_schema/google/protobuf/wrappers.js.map +1 -1
- package/lib/generated-proto/pb_schema/lenses/geocircle.js +0 -1
- package/lib/generated-proto/pb_schema/lenses/geocircle.js.map +1 -1
- package/lib/generated-proto/pb_schema/lenses/geopoint.js +0 -1
- package/lib/generated-proto/pb_schema/lenses/geopoint.js.map +1 -1
- package/lib/generated-proto/pb_schema/lenses/launch_params.js +0 -1
- package/lib/generated-proto/pb_schema/lenses/launch_params.js.map +1 -1
- package/lib/generated-proto/pb_schema/lenses/launchdata.d.ts +0 -2
- package/lib/generated-proto/pb_schema/lenses/launchdata.js +0 -3
- package/lib/generated-proto/pb_schema/lenses/launchdata.js.map +1 -1
- package/lib/generated-proto/pb_schema/lenses/lures.d.ts +0 -2
- package/lib/generated-proto/pb_schema/lenses/lures.js +0 -1
- package/lib/generated-proto/pb_schema/lenses/lures.js.map +1 -1
- package/lib/generated-proto/pb_schema/lenses/persistent_store.js +0 -1
- package/lib/generated-proto/pb_schema/lenses/persistent_store.js.map +1 -1
- package/lib/generated-proto/pb_schema/lenses/snappable.d.ts +0 -19
- package/lib/generated-proto/pb_schema/lenses/snappable.js +0 -2
- package/lib/generated-proto/pb_schema/lenses/snappable.js.map +1 -1
- package/lib/generated-proto/pb_schema/lenses/user_data.d.ts +0 -18
- package/lib/generated-proto/pb_schema/lenses/user_data.js +0 -1
- package/lib/generated-proto/pb_schema/lenses/user_data.js.map +1 -1
- package/lib/legal/legalPrompt.js +29 -27
- package/lib/legal/legalPrompt.js.map +1 -1
- package/lib/lens/LensRepository.d.ts +5 -3
- package/lib/lens/LensRepository.js +8 -5
- package/lib/lens/LensRepository.js.map +1 -1
- package/lib/lens/assets/LensAssetsProvider.js +18 -3
- package/lib/lens/assets/LensAssetsProvider.js.map +1 -1
- package/lib/lens/lensHttpUtil.d.ts +3 -2
- package/lib/lens/lensHttpUtil.js +5 -5
- package/lib/lens/lensHttpUtil.js.map +1 -1
- package/lib/lens-core-module/generated-types.d.ts +21 -0
- package/lib/lens-core-module/generated-types.js.map +1 -1
- package/lib/lensCoreWasmVersions.json +3 -3
- package/lib/media-sources/MediaStreamSource.js +4 -0
- package/lib/media-sources/MediaStreamSource.js.map +1 -1
- package/lib/metrics/businessEventsReporter.d.ts +3 -2
- package/lib/metrics/businessEventsReporter.js +13 -7
- package/lib/metrics/businessEventsReporter.js.map +1 -1
- package/lib/metrics/operational/operationalMetricsReporter.d.ts +3 -2
- package/lib/metrics/operational/operationalMetricsReporter.js +8 -6
- package/lib/metrics/operational/operationalMetricsReporter.js.map +1 -1
- package/lib/remote-configuration/cofHandler.d.ts +10 -6
- package/lib/remote-configuration/cofHandler.js +77 -67
- package/lib/remote-configuration/cofHandler.js.map +1 -1
- package/lib/remote-configuration/remoteConfiguration.d.ts +9 -6
- package/lib/remote-configuration/remoteConfiguration.js +5 -13
- package/lib/remote-configuration/remoteConfiguration.js.map +1 -1
- package/package.json +1 -1
package/lib/legal/legalPrompt.js
CHANGED
|
@@ -6,35 +6,34 @@ import { assertUnreachable } from "../common/assertions";
|
|
|
6
6
|
import { computeHash } from "../common/hash";
|
|
7
7
|
/* eslint-disable max-len */
|
|
8
8
|
const snapIcon = `
|
|
9
|
-
<
|
|
10
|
-
<
|
|
11
|
-
<
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
<
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
</svg>
|
|
28
|
-
</div>
|
|
29
|
-
`;
|
|
9
|
+
<svg xmlns="http://www.w3.org/2000/svg" role="img" viewBox="0 0 32 32" height="48px">
|
|
10
|
+
<g>
|
|
11
|
+
<path
|
|
12
|
+
d="M 30.898 23.477 C 30.77 23.045 30.148 22.743 30.148 22.743 C 30.092 22.71 30.039 22.684 29.994 22.663 C 28.962 22.161 28.048 21.561 27.277 20.876 C 26.659 20.325 26.128 19.719 25.701 19.074 C 25.182 18.288 24.937 17.632 24.831 17.275 C 24.773 17.043 24.782 16.951 24.831 16.832 C 24.873 16.731 24.99 16.632 25.049 16.588 C 25.397 16.341 25.96 15.976 26.303 15.75 C 26.602 15.556 26.859 15.389 27.009 15.283 C 27.494 14.944 27.824 14.596 28.02 14.223 C 28.275 13.74 28.303 13.208 28.107 12.684 C 27.84 11.978 27.184 11.556 26.35 11.556 C 26.163 11.556 25.974 11.577 25.785 11.62 C 25.308 11.723 24.852 11.894 24.474 12.042 C 24.446 12.054 24.416 12.032 24.418 12.002 C 24.457 11.059 24.502 9.79 24.399 8.584 C 24.306 7.493 24.082 6.576 23.717 5.776 C 23.351 4.972 22.874 4.376 22.5 3.947 C 22.143 3.536 21.519 2.936 20.577 2.394 C 19.251 1.631 17.742 1.244 16.09 1.244 C 14.443 1.244 12.934 1.631 11.605 2.394 C 10.607 2.966 9.97 3.614 9.678 3.947 C 9.304 4.376 8.827 4.972 8.46 5.776 C 8.096 6.576 7.872 7.496 7.778 8.584 C 7.673 9.792 7.715 10.96 7.76 11.999 C 7.762 12.03 7.732 12.051 7.704 12.039 C 7.325 11.892 6.87 11.72 6.393 11.617 C 6.204 11.575 6.012 11.554 5.828 11.554 C 4.994 11.554 4.337 11.976 4.071 12.682 C 3.875 13.205 3.903 13.738 4.157 14.221 C 4.354 14.594 4.685 14.941 5.169 15.281 C 5.318 15.387 5.575 15.553 5.874 15.748 C 6.211 15.968 6.758 16.323 7.108 16.569 C 7.152 16.599 7.299 16.712 7.346 16.827 C 7.397 16.951 7.404 17.045 7.341 17.289 C 7.234 17.648 6.989 18.298 6.479 19.069 C 6.052 19.715 5.522 20.32 4.902 20.871 C 4.132 21.556 3.218 22.157 2.186 22.658 C 2.137 22.682 2.078 22.712 2.015 22.748 C 2.015 22.748 1.399 23.064 1.282 23.472 C 1.109 24.075 1.567 24.64 2.036 24.943 C 2.8 25.438 3.732 25.703 4.272 25.849 C 4.421 25.889 4.559 25.926 4.683 25.964 C 4.76 25.989 4.956 26.062 5.038 26.17 C 5.143 26.306 5.155 26.473 5.192 26.66 C 5.253 26.977 5.384 27.373 5.774 27.643 C 6.204 27.941 6.75 27.962 7.444 27.99 C 8.168 28.018 9.07 28.054 10.1 28.394 C 10.579 28.553 11.011 28.818 11.514 29.128 C 12.56 29.773 13.864 30.578 16.09 30.578 C 18.318 30.578 19.629 29.768 20.685 29.119 C 21.183 28.811 21.612 28.546 22.08 28.391 C 23.11 28.049 24.011 28.014 24.735 27.988 C 25.427 27.962 25.974 27.941 26.404 27.641 C 26.822 27.35 26.943 26.918 26.997 26.59 C 27.027 26.428 27.046 26.285 27.14 26.165 C 27.219 26.064 27.399 25.992 27.483 25.964 C 27.609 25.924 27.751 25.886 27.906 25.844 C 28.445 25.698 29.123 25.527 29.945 25.061 C 30.933 24.511 31.001 23.82 30.898 23.477"
|
|
13
|
+
fill="#ffffff"
|
|
14
|
+
stroke="#00000000"
|
|
15
|
+
stroke-width="1"
|
|
16
|
+
/>
|
|
17
|
+
</g>
|
|
18
|
+
<g>
|
|
19
|
+
<path
|
|
20
|
+
d="M 29.56 24.299 C 28.21 25.045 27.312 24.965 26.613 25.414 C 26.021 25.795 26.37 26.618 25.939 26.915 C 25.411 27.279 23.843 26.889 21.822 27.555 C 20.155 28.107 19.09 29.689 16.089 29.689 C 13.081 29.689 12.047 28.114 10.357 27.555 C 8.335 26.889 6.768 27.279 6.24 26.915 C 5.809 26.618 6.16 25.795 5.566 25.414 C 4.869 24.965 3.969 25.045 2.619 24.299 C 1.758 23.825 2.247 23.53 2.532 23.393 C 7.426 21.027 8.204 17.372 8.24 17.096 C 8.282 16.769 8.328 16.509 7.966 16.175 C 7.615 15.853 6.066 14.895 5.636 14.593 C 4.925 14.098 4.612 13.6 4.841 12.99 C 5 12.569 5.395 12.41 5.812 12.41 C 5.94 12.41 6.071 12.426 6.2 12.452 C 6.981 12.623 7.741 13.013 8.179 13.118 C 8.24 13.132 8.293 13.139 8.34 13.139 C 8.574 13.139 8.656 13.022 8.639 12.754 C 8.59 11.9 8.469 10.234 8.602 8.677 C 8.787 6.536 9.477 5.476 10.298 4.538 C 10.693 4.087 12.543 2.133 16.082 2.133 C 19.633 2.133 21.474 4.087 21.867 4.538 C 22.688 5.478 23.378 6.536 23.563 8.677 C 23.698 10.234 23.581 11.898 23.525 12.754 C 23.506 13.034 23.591 13.139 23.825 13.139 C 23.872 13.139 23.925 13.132 23.986 13.118 C 24.426 13.013 25.184 12.62 25.965 12.452 C 26.091 12.424 26.222 12.41 26.353 12.41 C 26.77 12.41 27.165 12.569 27.324 12.99 C 27.555 13.6 27.242 14.095 26.529 14.593 C 26.098 14.892 24.547 15.85 24.199 16.175 C 23.836 16.509 23.883 16.767 23.925 17.096 C 23.96 17.372 24.739 21.025 29.633 23.393 C 29.932 23.53 30.421 23.825 29.56 24.299 M 31.709 23.12 C 31.489 22.523 31.07 22.203 30.594 21.939 C 30.505 21.887 30.423 21.845 30.355 21.812 C 30.212 21.74 30.067 21.667 29.922 21.592 C 28.435 20.806 27.275 19.812 26.469 18.635 C 26.198 18.238 26.008 17.88 25.877 17.587 C 25.809 17.391 25.811 17.281 25.86 17.178 C 25.898 17.101 25.996 17.019 26.05 16.979 C 26.305 16.811 26.57 16.64 26.748 16.525 C 27.067 16.319 27.317 16.156 27.481 16.043 C 28.093 15.617 28.519 15.164 28.786 14.658 C 29.163 13.945 29.21 13.131 28.919 12.363 C 28.517 11.301 27.509 10.642 26.291 10.642 C 26.038 10.642 25.783 10.67 25.527 10.726 C 25.46 10.74 25.394 10.756 25.328 10.773 C 25.34 10.05 25.324 9.278 25.258 8.524 C 25.029 5.872 24.099 4.48 23.129 3.371 C 22.724 2.908 22.021 2.232 20.964 1.628 C 19.491 0.781 17.821 0.356 16 0.356 C 14.185 0.356 12.518 0.781 11.044 1.623 C 9.983 2.229 9.278 2.905 8.875 3.366 C 7.905 4.475 6.975 5.867 6.746 8.52 C 6.68 9.273 6.663 10.045 6.675 10.768 C 6.61 10.752 6.544 10.735 6.476 10.721 C 6.221 10.665 5.965 10.637 5.713 10.637 C 4.494 10.637 3.487 11.297 3.084 12.359 C 2.794 13.126 2.841 13.94 3.218 14.654 C 3.485 15.159 3.911 15.613 4.522 16.039 C 4.686 16.153 4.937 16.314 5.256 16.52 C 5.427 16.633 5.68 16.794 5.926 16.958 C 5.963 16.984 6.097 17.082 6.141 17.173 C 6.193 17.279 6.195 17.393 6.118 17.604 C 5.987 17.891 5.801 18.242 5.535 18.631 C 4.747 19.782 3.62 20.757 2.18 21.536 C 1.419 21.941 0.54 22.355 0.29 23.118 C 0.039 23.88 0.203 24.582 0.842 25.239 C 1.053 25.466 1.318 25.665 1.653 25.85 C 2.438 26.283 3.105 26.496 3.63 26.641 C 3.721 26.669 3.937 26.736 4.031 26.819 C 4.265 27.022 4.23 27.331 4.543 27.78 C 4.731 28.061 4.949 28.25 5.129 28.374 C 5.783 28.826 6.516 28.854 7.294 28.881 C 7.997 28.908 8.793 28.94 9.702 29.24 C 10.079 29.364 10.47 29.605 10.922 29.883 C 12.011 30.552 13.501 31.467 15.998 31.467 C 18.493 31.467 19.995 30.547 21.091 29.876 C 21.541 29.6 21.93 29.361 22.297 29.242 C 23.206 28.942 24.003 28.912 24.706 28.884 C 25.483 28.854 26.216 28.826 26.87 28.377 C 27.076 28.234 27.331 28.004 27.535 27.651 C 27.76 27.272 27.753 27.003 27.964 26.821 C 28.05 26.746 28.238 26.68 28.338 26.65 C 28.868 26.505 29.545 26.292 30.344 25.852 C 30.697 25.658 30.976 25.443 31.192 25.2 C 31.194 25.197 31.196 25.192 31.199 25.19 C 31.805 24.544 31.955 23.787 31.709 23.12"
|
|
21
|
+
fill="#000000"
|
|
22
|
+
stroke="#00000000"
|
|
23
|
+
stroke-width="1"
|
|
24
|
+
/>
|
|
25
|
+
</g>
|
|
26
|
+
</svg>`;
|
|
30
27
|
/* eslint-enable */
|
|
31
|
-
function showTosDialog(title, body) {
|
|
28
|
+
function showTosDialog(title, titleText, body) {
|
|
32
29
|
return __awaiter(this, void 0, void 0, function* () {
|
|
33
30
|
const result = yield showDialog({
|
|
34
31
|
container: document.body,
|
|
35
32
|
dataTestId: "tos-dialog",
|
|
33
|
+
lang: supportedLocale,
|
|
36
34
|
title,
|
|
37
|
-
|
|
35
|
+
titleText,
|
|
36
|
+
body,
|
|
38
37
|
dismissButtonText: localizedString("legalPromptReject"),
|
|
39
38
|
buttons: [
|
|
40
39
|
{
|
|
@@ -50,6 +49,7 @@ function showAdultOrChildDialog() {
|
|
|
50
49
|
return showDialog({
|
|
51
50
|
container: document.body,
|
|
52
51
|
dataTestId: "adult-or-child-dialog",
|
|
52
|
+
lang: supportedLocale,
|
|
53
53
|
title: localizedString("legalPromptVariantGAdultOrChild"),
|
|
54
54
|
buttons: [
|
|
55
55
|
{
|
|
@@ -67,6 +67,7 @@ function showFindGuardianDialog() {
|
|
|
67
67
|
return showDialog({
|
|
68
68
|
container: document.body,
|
|
69
69
|
dataTestId: "find-guardian-dialog",
|
|
70
|
+
lang: supportedLocale,
|
|
70
71
|
title: localizedString("legalPromptVariantGFindYourParent"),
|
|
71
72
|
buttons: [
|
|
72
73
|
{
|
|
@@ -93,13 +94,14 @@ export const legalPromptFactory = Injectable("legalPrompt", () => {
|
|
|
93
94
|
termsOfServiceUrl: termsOfService.webUrl,
|
|
94
95
|
learnMoreUrl: learnMore.webUrl,
|
|
95
96
|
});
|
|
96
|
-
const
|
|
97
|
+
const legalTitleText = localizedString("legalPromptTermsOfService");
|
|
98
|
+
const legalTitle = childrenProtectionActRestricted ? legalTitleText : snapIcon;
|
|
97
99
|
return {
|
|
98
100
|
contentHash: computeHash(legalMessage),
|
|
99
101
|
show() {
|
|
100
102
|
return __awaiter(this, void 0, void 0, function* () {
|
|
101
103
|
if (!childrenProtectionActRestricted) {
|
|
102
|
-
return showTosDialog(legalTitle, legalMessage);
|
|
104
|
+
return showTosDialog(legalTitle, legalTitleText, legalMessage);
|
|
103
105
|
}
|
|
104
106
|
while (true) {
|
|
105
107
|
const adultOrChild = yield showAdultOrChildDialog();
|
|
@@ -110,7 +112,7 @@ export const legalPromptFactory = Injectable("legalPrompt", () => {
|
|
|
110
112
|
case "cancel":
|
|
111
113
|
continue;
|
|
112
114
|
case "guardian":
|
|
113
|
-
return showTosDialog(legalTitle, legalMessage);
|
|
115
|
+
return showTosDialog(legalTitle, legalTitleText, legalMessage);
|
|
114
116
|
case "dismiss":
|
|
115
117
|
return false;
|
|
116
118
|
default:
|
|
@@ -118,7 +120,7 @@ export const legalPromptFactory = Injectable("legalPrompt", () => {
|
|
|
118
120
|
}
|
|
119
121
|
}
|
|
120
122
|
case "adult":
|
|
121
|
-
return showTosDialog(legalTitle, legalMessage);
|
|
123
|
+
return showTosDialog(legalTitle, legalTitleText, legalMessage);
|
|
122
124
|
case "dismiss":
|
|
123
125
|
return false;
|
|
124
126
|
default:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"legalPrompt.js","sourceRoot":"","sources":["../../src/legal/legalPrompt.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAEhE,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAA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gCACR,OAAO,aAAa,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;4BACnD,KAAK,SAAS;gCACV,OAAO,KAAK,CAAC;4BACjB;gCACI,iBAAiB,CAAC,YAAY,CAAC,CAAC;yBACvC;qBACJ;gBACL,CAAC;aAAA;SACJ,CAAC;IACN,CAAC,CAAC;AACN,CAAC,CAAC,CAAC","sourcesContent":["import { Injectable } from \"../dependency-injection/Injectable\";\nimport { LegalDocument, LegalDocument_Type } from \"../generated-proto/pb_schema/camera_kit/v3/legal_prompt\";\nimport { supportedLocale, localizedString } from \"../common/localization\";\nimport { showDialog } from \"../common/dialog\";\nimport { assertUnreachable } from \"../common/assertions\";\nimport { computeHash } from \"../common/hash\";\n\n/* eslint-disable max-len */\nconst snapIcon = `\n<div style=\"text-align: center\">\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 32 32\" height=\"48px\">\n <g>\n <path\n d=\"M 30.898 23.477 C 30.77 23.045 30.148 22.743 30.148 22.743 C 30.092 22.71 30.039 22.684 29.994 22.663 C 28.962 22.161 28.048 21.561 27.277 20.876 C 26.659 20.325 26.128 19.719 25.701 19.074 C 25.182 18.288 24.937 17.632 24.831 17.275 C 24.773 17.043 24.782 16.951 24.831 16.832 C 24.873 16.731 24.99 16.632 25.049 16.588 C 25.397 16.341 25.96 15.976 26.303 15.75 C 26.602 15.556 26.859 15.389 27.009 15.283 C 27.494 14.944 27.824 14.596 28.02 14.223 C 28.275 13.74 28.303 13.208 28.107 12.684 C 27.84 11.978 27.184 11.556 26.35 11.556 C 26.163 11.556 25.974 11.577 25.785 11.62 C 25.308 11.723 24.852 11.894 24.474 12.042 C 24.446 12.054 24.416 12.032 24.418 12.002 C 24.457 11.059 24.502 9.79 24.399 8.584 C 24.306 7.493 24.082 6.576 23.717 5.776 C 23.351 4.972 22.874 4.376 22.5 3.947 C 22.143 3.536 21.519 2.936 20.577 2.394 C 19.251 1.631 17.742 1.244 16.09 1.244 C 14.443 1.244 12.934 1.631 11.605 2.394 C 10.607 2.966 9.97 3.614 9.678 3.947 C 9.304 4.376 8.827 4.972 8.46 5.776 C 8.096 6.576 7.872 7.496 7.778 8.584 C 7.673 9.792 7.715 10.96 7.76 11.999 C 7.762 12.03 7.732 12.051 7.704 12.039 C 7.325 11.892 6.87 11.72 6.393 11.617 C 6.204 11.575 6.012 11.554 5.828 11.554 C 4.994 11.554 4.337 11.976 4.071 12.682 C 3.875 13.205 3.903 13.738 4.157 14.221 C 4.354 14.594 4.685 14.941 5.169 15.281 C 5.318 15.387 5.575 15.553 5.874 15.748 C 6.211 15.968 6.758 16.323 7.108 16.569 C 7.152 16.599 7.299 16.712 7.346 16.827 C 7.397 16.951 7.404 17.045 7.341 17.289 C 7.234 17.648 6.989 18.298 6.479 19.069 C 6.052 19.715 5.522 20.32 4.902 20.871 C 4.132 21.556 3.218 22.157 2.186 22.658 C 2.137 22.682 2.078 22.712 2.015 22.748 C 2.015 22.748 1.399 23.064 1.282 23.472 C 1.109 24.075 1.567 24.64 2.036 24.943 C 2.8 25.438 3.732 25.703 4.272 25.849 C 4.421 25.889 4.559 25.926 4.683 25.964 C 4.76 25.989 4.956 26.062 5.038 26.17 C 5.143 26.306 5.155 26.473 5.192 26.66 C 5.253 26.977 5.384 27.373 5.774 27.643 C 6.204 27.941 6.75 27.962 7.444 27.99 C 8.168 28.018 9.07 28.054 10.1 28.394 C 10.579 28.553 11.011 28.818 11.514 29.128 C 12.56 29.773 13.864 30.578 16.09 30.578 C 18.318 30.578 19.629 29.768 20.685 29.119 C 21.183 28.811 21.612 28.546 22.08 28.391 C 23.11 28.049 24.011 28.014 24.735 27.988 C 25.427 27.962 25.974 27.941 26.404 27.641 C 26.822 27.35 26.943 26.918 26.997 26.59 C 27.027 26.428 27.046 26.285 27.14 26.165 C 27.219 26.064 27.399 25.992 27.483 25.964 C 27.609 25.924 27.751 25.886 27.906 25.844 C 28.445 25.698 29.123 25.527 29.945 25.061 C 30.933 24.511 31.001 23.82 30.898 23.477\"\n fill=\"#ffffff\"\n stroke=\"#00000000\"\n stroke-width=\"1\"\n />\n </g>\n <g>\n <path\n d=\"M 29.56 24.299 C 28.21 25.045 27.312 24.965 26.613 25.414 C 26.021 25.795 26.37 26.618 25.939 26.915 C 25.411 27.279 23.843 26.889 21.822 27.555 C 20.155 28.107 19.09 29.689 16.089 29.689 C 13.081 29.689 12.047 28.114 10.357 27.555 C 8.335 26.889 6.768 27.279 6.24 26.915 C 5.809 26.618 6.16 25.795 5.566 25.414 C 4.869 24.965 3.969 25.045 2.619 24.299 C 1.758 23.825 2.247 23.53 2.532 23.393 C 7.426 21.027 8.204 17.372 8.24 17.096 C 8.282 16.769 8.328 16.509 7.966 16.175 C 7.615 15.853 6.066 14.895 5.636 14.593 C 4.925 14.098 4.612 13.6 4.841 12.99 C 5 12.569 5.395 12.41 5.812 12.41 C 5.94 12.41 6.071 12.426 6.2 12.452 C 6.981 12.623 7.741 13.013 8.179 13.118 C 8.24 13.132 8.293 13.139 8.34 13.139 C 8.574 13.139 8.656 13.022 8.639 12.754 C 8.59 11.9 8.469 10.234 8.602 8.677 C 8.787 6.536 9.477 5.476 10.298 4.538 C 10.693 4.087 12.543 2.133 16.082 2.133 C 19.633 2.133 21.474 4.087 21.867 4.538 C 22.688 5.478 23.378 6.536 23.563 8.677 C 23.698 10.234 23.581 11.898 23.525 12.754 C 23.506 13.034 23.591 13.139 23.825 13.139 C 23.872 13.139 23.925 13.132 23.986 13.118 C 24.426 13.013 25.184 12.62 25.965 12.452 C 26.091 12.424 26.222 12.41 26.353 12.41 C 26.77 12.41 27.165 12.569 27.324 12.99 C 27.555 13.6 27.242 14.095 26.529 14.593 C 26.098 14.892 24.547 15.85 24.199 16.175 C 23.836 16.509 23.883 16.767 23.925 17.096 C 23.96 17.372 24.739 21.025 29.633 23.393 C 29.932 23.53 30.421 23.825 29.56 24.299 M 31.709 23.12 C 31.489 22.523 31.07 22.203 30.594 21.939 C 30.505 21.887 30.423 21.845 30.355 21.812 C 30.212 21.74 30.067 21.667 29.922 21.592 C 28.435 20.806 27.275 19.812 26.469 18.635 C 26.198 18.238 26.008 17.88 25.877 17.587 C 25.809 17.391 25.811 17.281 25.86 17.178 C 25.898 17.101 25.996 17.019 26.05 16.979 C 26.305 16.811 26.57 16.64 26.748 16.525 C 27.067 16.319 27.317 16.156 27.481 16.043 C 28.093 15.617 28.519 15.164 28.786 14.658 C 29.163 13.945 29.21 13.131 28.919 12.363 C 28.517 11.301 27.509 10.642 26.291 10.642 C 26.038 10.642 25.783 10.67 25.527 10.726 C 25.46 10.74 25.394 10.756 25.328 10.773 C 25.34 10.05 25.324 9.278 25.258 8.524 C 25.029 5.872 24.099 4.48 23.129 3.371 C 22.724 2.908 22.021 2.232 20.964 1.628 C 19.491 0.781 17.821 0.356 16 0.356 C 14.185 0.356 12.518 0.781 11.044 1.623 C 9.983 2.229 9.278 2.905 8.875 3.366 C 7.905 4.475 6.975 5.867 6.746 8.52 C 6.68 9.273 6.663 10.045 6.675 10.768 C 6.61 10.752 6.544 10.735 6.476 10.721 C 6.221 10.665 5.965 10.637 5.713 10.637 C 4.494 10.637 3.487 11.297 3.084 12.359 C 2.794 13.126 2.841 13.94 3.218 14.654 C 3.485 15.159 3.911 15.613 4.522 16.039 C 4.686 16.153 4.937 16.314 5.256 16.52 C 5.427 16.633 5.68 16.794 5.926 16.958 C 5.963 16.984 6.097 17.082 6.141 17.173 C 6.193 17.279 6.195 17.393 6.118 17.604 C 5.987 17.891 5.801 18.242 5.535 18.631 C 4.747 19.782 3.62 20.757 2.18 21.536 C 1.419 21.941 0.54 22.355 0.29 23.118 C 0.039 23.88 0.203 24.582 0.842 25.239 C 1.053 25.466 1.318 25.665 1.653 25.85 C 2.438 26.283 3.105 26.496 3.63 26.641 C 3.721 26.669 3.937 26.736 4.031 26.819 C 4.265 27.022 4.23 27.331 4.543 27.78 C 4.731 28.061 4.949 28.25 5.129 28.374 C 5.783 28.826 6.516 28.854 7.294 28.881 C 7.997 28.908 8.793 28.94 9.702 29.24 C 10.079 29.364 10.47 29.605 10.922 29.883 C 12.011 30.552 13.501 31.467 15.998 31.467 C 18.493 31.467 19.995 30.547 21.091 29.876 C 21.541 29.6 21.93 29.361 22.297 29.242 C 23.206 28.942 24.003 28.912 24.706 28.884 C 25.483 28.854 26.216 28.826 26.87 28.377 C 27.076 28.234 27.331 28.004 27.535 27.651 C 27.76 27.272 27.753 27.003 27.964 26.821 C 28.05 26.746 28.238 26.68 28.338 26.65 C 28.868 26.505 29.545 26.292 30.344 25.852 C 30.697 25.658 30.976 25.443 31.192 25.2 C 31.194 25.197 31.196 25.192 31.199 25.19 C 31.805 24.544 31.955 23.787 31.709 23.12\"\n fill=\"#000000\"\n stroke=\"#00000000\"\n stroke-width=\"1\"\n />\n </g>\n </svg>\n</div>\n`;\n/* eslint-enable */\n\nasync function showTosDialog(title: string, body: string) {\n const result = await showDialog({\n container: document.body,\n dataTestId: \"tos-dialog\",\n title,\n body: `<div lang=\"${supportedLocale}\" dir=\"auto\" >${body}</div>`,\n dismissButtonText: localizedString(\"legalPromptReject\"),\n buttons: [\n {\n text: localizedString(\"legalPromptAccept\"),\n key: \"accept\",\n },\n ],\n });\n return result === \"accept\";\n}\n\nfunction showAdultOrChildDialog() {\n return showDialog({\n container: document.body,\n dataTestId: \"adult-or-child-dialog\",\n title: localizedString(\"legalPromptVariantGAdultOrChild\"),\n buttons: [\n {\n text: localizedString(\"legalPromptVariantGAdult\"),\n key: \"adult\",\n },\n {\n text: localizedString(\"legalPromptVariantGChild\"),\n key: \"child\",\n },\n ],\n });\n}\n\nfunction showFindGuardianDialog() {\n return showDialog({\n container: document.body,\n dataTestId: \"find-guardian-dialog\",\n title: localizedString(\"legalPromptVariantGFindYourParent\"),\n buttons: [\n {\n text: localizedString(\"legalPromptVariantGIAmGuardian\"),\n key: \"guardian\",\n },\n {\n text: localizedString(\"legalPromptVariantGCancel\"),\n key: \"cancel\",\n isSecondary: true,\n },\n ],\n });\n}\n\nexport type LegalPromptFactory = (\n privacyPolicy: LegalDocument & { type: LegalDocument_Type.PRIVACY_POLICY },\n termsOfService: LegalDocument & { type: LegalDocument_Type.TERMS_OF_SERVICE },\n learnMore: LegalDocument & { type: LegalDocument_Type.LEARN_MORE },\n childrenProtectionActRestricted: boolean\n) => LegalPrompt;\n\nexport type LegalPrompt = {\n contentHash: string;\n show: () => Promise<boolean>;\n};\n\n/**\n * @internal\n */\nexport const legalPromptFactory = Injectable(\"legalPrompt\", (): LegalPromptFactory => {\n return function legalPrompt(\n privacyPolicy: LegalDocument & { type: LegalDocument_Type.PRIVACY_POLICY },\n termsOfService: LegalDocument & { type: LegalDocument_Type.TERMS_OF_SERVICE },\n learnMore: LegalDocument & { type: LegalDocument_Type.LEARN_MORE },\n childrenProtectionActRestricted: boolean\n ) {\n const legalMessage = childrenProtectionActRestricted\n ? localizedString(\"legalPromptVariantGMessage\")\n : localizedString(\"legalPromptMessage\")({\n privacyPolicyUrl: privacyPolicy.webUrl,\n termsOfServiceUrl: termsOfService.webUrl,\n learnMoreUrl: learnMore.webUrl,\n });\n const legalTitle = childrenProtectionActRestricted ? localizedString(\"legalPromptTermsOfService\") : snapIcon;\n\n return {\n contentHash: computeHash(legalMessage),\n\n async show() {\n if (!childrenProtectionActRestricted) {\n return showTosDialog(legalTitle, legalMessage);\n }\n\n while (true) {\n const adultOrChild = await showAdultOrChildDialog();\n switch (adultOrChild) {\n case \"child\": {\n const findGuardian = await showFindGuardianDialog();\n switch (findGuardian) {\n case \"cancel\":\n continue;\n case \"guardian\":\n return showTosDialog(legalTitle, legalMessage);\n case \"dismiss\":\n return false;\n default:\n assertUnreachable(findGuardian);\n }\n }\n case \"adult\":\n return showTosDialog(legalTitle, legalMessage);\n case \"dismiss\":\n return false;\n default:\n assertUnreachable(adultOrChild);\n }\n }\n },\n };\n };\n});\n"]}
|
|
1
|
+
{"version":3,"file":"legalPrompt.js","sourceRoot":"","sources":["../../src/legal/legalPrompt.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE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AO,CAAC,CAAC;gCACV,MAAM,YAAY,GAAG,MAAM,sBAAsB,EAAE,CAAC;gCACpD,QAAQ,YAAY,EAAE;oCAClB,KAAK,QAAQ;wCACT,SAAS;oCACb,KAAK,UAAU;wCACX,OAAO,aAAa,CAAC,UAAU,EAAE,cAAc,EAAE,YAAY,CAAC,CAAC;oCACnE,KAAK,SAAS;wCACV,OAAO,KAAK,CAAC;oCACjB;wCACI,iBAAiB,CAAC,YAAY,CAAC,CAAC;iCACvC;6BACJ;4BACD,KAAK,OAAO;gCACR,OAAO,aAAa,CAAC,UAAU,EAAE,cAAc,EAAE,YAAY,CAAC,CAAC;4BACnE,KAAK,SAAS;gCACV,OAAO,KAAK,CAAC;4BACjB;gCACI,iBAAiB,CAAC,YAAY,CAAC,CAAC;yBACvC;qBACJ;gBACL,CAAC;aAAA;SACJ,CAAC;IACN,CAAC,CAAC;AACN,CAAC,CAAC,CAAC","sourcesContent":["import { Injectable } from \"../dependency-injection/Injectable\";\nimport { LegalDocument, LegalDocument_Type } from \"../generated-proto/pb_schema/camera_kit/v3/legal_prompt\";\nimport { supportedLocale, localizedString } from \"../common/localization\";\nimport { showDialog } from \"../common/dialog\";\nimport { assertUnreachable } from \"../common/assertions\";\nimport { computeHash } from \"../common/hash\";\n\n/* eslint-disable max-len */\nconst snapIcon = `\n<svg xmlns=\"http://www.w3.org/2000/svg\" role=\"img\" viewBox=\"0 0 32 32\" height=\"48px\">\n <g>\n <path\n d=\"M 30.898 23.477 C 30.77 23.045 30.148 22.743 30.148 22.743 C 30.092 22.71 30.039 22.684 29.994 22.663 C 28.962 22.161 28.048 21.561 27.277 20.876 C 26.659 20.325 26.128 19.719 25.701 19.074 C 25.182 18.288 24.937 17.632 24.831 17.275 C 24.773 17.043 24.782 16.951 24.831 16.832 C 24.873 16.731 24.99 16.632 25.049 16.588 C 25.397 16.341 25.96 15.976 26.303 15.75 C 26.602 15.556 26.859 15.389 27.009 15.283 C 27.494 14.944 27.824 14.596 28.02 14.223 C 28.275 13.74 28.303 13.208 28.107 12.684 C 27.84 11.978 27.184 11.556 26.35 11.556 C 26.163 11.556 25.974 11.577 25.785 11.62 C 25.308 11.723 24.852 11.894 24.474 12.042 C 24.446 12.054 24.416 12.032 24.418 12.002 C 24.457 11.059 24.502 9.79 24.399 8.584 C 24.306 7.493 24.082 6.576 23.717 5.776 C 23.351 4.972 22.874 4.376 22.5 3.947 C 22.143 3.536 21.519 2.936 20.577 2.394 C 19.251 1.631 17.742 1.244 16.09 1.244 C 14.443 1.244 12.934 1.631 11.605 2.394 C 10.607 2.966 9.97 3.614 9.678 3.947 C 9.304 4.376 8.827 4.972 8.46 5.776 C 8.096 6.576 7.872 7.496 7.778 8.584 C 7.673 9.792 7.715 10.96 7.76 11.999 C 7.762 12.03 7.732 12.051 7.704 12.039 C 7.325 11.892 6.87 11.72 6.393 11.617 C 6.204 11.575 6.012 11.554 5.828 11.554 C 4.994 11.554 4.337 11.976 4.071 12.682 C 3.875 13.205 3.903 13.738 4.157 14.221 C 4.354 14.594 4.685 14.941 5.169 15.281 C 5.318 15.387 5.575 15.553 5.874 15.748 C 6.211 15.968 6.758 16.323 7.108 16.569 C 7.152 16.599 7.299 16.712 7.346 16.827 C 7.397 16.951 7.404 17.045 7.341 17.289 C 7.234 17.648 6.989 18.298 6.479 19.069 C 6.052 19.715 5.522 20.32 4.902 20.871 C 4.132 21.556 3.218 22.157 2.186 22.658 C 2.137 22.682 2.078 22.712 2.015 22.748 C 2.015 22.748 1.399 23.064 1.282 23.472 C 1.109 24.075 1.567 24.64 2.036 24.943 C 2.8 25.438 3.732 25.703 4.272 25.849 C 4.421 25.889 4.559 25.926 4.683 25.964 C 4.76 25.989 4.956 26.062 5.038 26.17 C 5.143 26.306 5.155 26.473 5.192 26.66 C 5.253 26.977 5.384 27.373 5.774 27.643 C 6.204 27.941 6.75 27.962 7.444 27.99 C 8.168 28.018 9.07 28.054 10.1 28.394 C 10.579 28.553 11.011 28.818 11.514 29.128 C 12.56 29.773 13.864 30.578 16.09 30.578 C 18.318 30.578 19.629 29.768 20.685 29.119 C 21.183 28.811 21.612 28.546 22.08 28.391 C 23.11 28.049 24.011 28.014 24.735 27.988 C 25.427 27.962 25.974 27.941 26.404 27.641 C 26.822 27.35 26.943 26.918 26.997 26.59 C 27.027 26.428 27.046 26.285 27.14 26.165 C 27.219 26.064 27.399 25.992 27.483 25.964 C 27.609 25.924 27.751 25.886 27.906 25.844 C 28.445 25.698 29.123 25.527 29.945 25.061 C 30.933 24.511 31.001 23.82 30.898 23.477\"\n fill=\"#ffffff\"\n stroke=\"#00000000\"\n stroke-width=\"1\"\n />\n </g>\n <g>\n <path\n d=\"M 29.56 24.299 C 28.21 25.045 27.312 24.965 26.613 25.414 C 26.021 25.795 26.37 26.618 25.939 26.915 C 25.411 27.279 23.843 26.889 21.822 27.555 C 20.155 28.107 19.09 29.689 16.089 29.689 C 13.081 29.689 12.047 28.114 10.357 27.555 C 8.335 26.889 6.768 27.279 6.24 26.915 C 5.809 26.618 6.16 25.795 5.566 25.414 C 4.869 24.965 3.969 25.045 2.619 24.299 C 1.758 23.825 2.247 23.53 2.532 23.393 C 7.426 21.027 8.204 17.372 8.24 17.096 C 8.282 16.769 8.328 16.509 7.966 16.175 C 7.615 15.853 6.066 14.895 5.636 14.593 C 4.925 14.098 4.612 13.6 4.841 12.99 C 5 12.569 5.395 12.41 5.812 12.41 C 5.94 12.41 6.071 12.426 6.2 12.452 C 6.981 12.623 7.741 13.013 8.179 13.118 C 8.24 13.132 8.293 13.139 8.34 13.139 C 8.574 13.139 8.656 13.022 8.639 12.754 C 8.59 11.9 8.469 10.234 8.602 8.677 C 8.787 6.536 9.477 5.476 10.298 4.538 C 10.693 4.087 12.543 2.133 16.082 2.133 C 19.633 2.133 21.474 4.087 21.867 4.538 C 22.688 5.478 23.378 6.536 23.563 8.677 C 23.698 10.234 23.581 11.898 23.525 12.754 C 23.506 13.034 23.591 13.139 23.825 13.139 C 23.872 13.139 23.925 13.132 23.986 13.118 C 24.426 13.013 25.184 12.62 25.965 12.452 C 26.091 12.424 26.222 12.41 26.353 12.41 C 26.77 12.41 27.165 12.569 27.324 12.99 C 27.555 13.6 27.242 14.095 26.529 14.593 C 26.098 14.892 24.547 15.85 24.199 16.175 C 23.836 16.509 23.883 16.767 23.925 17.096 C 23.96 17.372 24.739 21.025 29.633 23.393 C 29.932 23.53 30.421 23.825 29.56 24.299 M 31.709 23.12 C 31.489 22.523 31.07 22.203 30.594 21.939 C 30.505 21.887 30.423 21.845 30.355 21.812 C 30.212 21.74 30.067 21.667 29.922 21.592 C 28.435 20.806 27.275 19.812 26.469 18.635 C 26.198 18.238 26.008 17.88 25.877 17.587 C 25.809 17.391 25.811 17.281 25.86 17.178 C 25.898 17.101 25.996 17.019 26.05 16.979 C 26.305 16.811 26.57 16.64 26.748 16.525 C 27.067 16.319 27.317 16.156 27.481 16.043 C 28.093 15.617 28.519 15.164 28.786 14.658 C 29.163 13.945 29.21 13.131 28.919 12.363 C 28.517 11.301 27.509 10.642 26.291 10.642 C 26.038 10.642 25.783 10.67 25.527 10.726 C 25.46 10.74 25.394 10.756 25.328 10.773 C 25.34 10.05 25.324 9.278 25.258 8.524 C 25.029 5.872 24.099 4.48 23.129 3.371 C 22.724 2.908 22.021 2.232 20.964 1.628 C 19.491 0.781 17.821 0.356 16 0.356 C 14.185 0.356 12.518 0.781 11.044 1.623 C 9.983 2.229 9.278 2.905 8.875 3.366 C 7.905 4.475 6.975 5.867 6.746 8.52 C 6.68 9.273 6.663 10.045 6.675 10.768 C 6.61 10.752 6.544 10.735 6.476 10.721 C 6.221 10.665 5.965 10.637 5.713 10.637 C 4.494 10.637 3.487 11.297 3.084 12.359 C 2.794 13.126 2.841 13.94 3.218 14.654 C 3.485 15.159 3.911 15.613 4.522 16.039 C 4.686 16.153 4.937 16.314 5.256 16.52 C 5.427 16.633 5.68 16.794 5.926 16.958 C 5.963 16.984 6.097 17.082 6.141 17.173 C 6.193 17.279 6.195 17.393 6.118 17.604 C 5.987 17.891 5.801 18.242 5.535 18.631 C 4.747 19.782 3.62 20.757 2.18 21.536 C 1.419 21.941 0.54 22.355 0.29 23.118 C 0.039 23.88 0.203 24.582 0.842 25.239 C 1.053 25.466 1.318 25.665 1.653 25.85 C 2.438 26.283 3.105 26.496 3.63 26.641 C 3.721 26.669 3.937 26.736 4.031 26.819 C 4.265 27.022 4.23 27.331 4.543 27.78 C 4.731 28.061 4.949 28.25 5.129 28.374 C 5.783 28.826 6.516 28.854 7.294 28.881 C 7.997 28.908 8.793 28.94 9.702 29.24 C 10.079 29.364 10.47 29.605 10.922 29.883 C 12.011 30.552 13.501 31.467 15.998 31.467 C 18.493 31.467 19.995 30.547 21.091 29.876 C 21.541 29.6 21.93 29.361 22.297 29.242 C 23.206 28.942 24.003 28.912 24.706 28.884 C 25.483 28.854 26.216 28.826 26.87 28.377 C 27.076 28.234 27.331 28.004 27.535 27.651 C 27.76 27.272 27.753 27.003 27.964 26.821 C 28.05 26.746 28.238 26.68 28.338 26.65 C 28.868 26.505 29.545 26.292 30.344 25.852 C 30.697 25.658 30.976 25.443 31.192 25.2 C 31.194 25.197 31.196 25.192 31.199 25.19 C 31.805 24.544 31.955 23.787 31.709 23.12\"\n fill=\"#000000\"\n stroke=\"#00000000\"\n stroke-width=\"1\"\n />\n </g>\n</svg>`;\n/* eslint-enable */\n\nasync function showTosDialog(title: string, titleText: string, body: string) {\n const result = await showDialog({\n container: document.body,\n dataTestId: \"tos-dialog\",\n lang: supportedLocale,\n title,\n titleText,\n body,\n dismissButtonText: localizedString(\"legalPromptReject\"),\n buttons: [\n {\n text: localizedString(\"legalPromptAccept\"),\n key: \"accept\",\n },\n ],\n });\n return result === \"accept\";\n}\n\nfunction showAdultOrChildDialog() {\n return showDialog({\n container: document.body,\n dataTestId: \"adult-or-child-dialog\",\n lang: supportedLocale,\n title: localizedString(\"legalPromptVariantGAdultOrChild\"),\n buttons: [\n {\n text: localizedString(\"legalPromptVariantGAdult\"),\n key: \"adult\",\n },\n {\n text: localizedString(\"legalPromptVariantGChild\"),\n key: \"child\",\n },\n ],\n });\n}\n\nfunction showFindGuardianDialog() {\n return showDialog({\n container: document.body,\n dataTestId: \"find-guardian-dialog\",\n lang: supportedLocale,\n title: localizedString(\"legalPromptVariantGFindYourParent\"),\n buttons: [\n {\n text: localizedString(\"legalPromptVariantGIAmGuardian\"),\n key: \"guardian\",\n },\n {\n text: localizedString(\"legalPromptVariantGCancel\"),\n key: \"cancel\",\n isSecondary: true,\n },\n ],\n });\n}\n\nexport type LegalPromptFactory = (\n privacyPolicy: LegalDocument & { type: LegalDocument_Type.PRIVACY_POLICY },\n termsOfService: LegalDocument & { type: LegalDocument_Type.TERMS_OF_SERVICE },\n learnMore: LegalDocument & { type: LegalDocument_Type.LEARN_MORE },\n childrenProtectionActRestricted: boolean\n) => LegalPrompt;\n\nexport type LegalPrompt = {\n contentHash: string;\n show: () => Promise<boolean>;\n};\n\n/**\n * @internal\n */\nexport const legalPromptFactory = Injectable(\"legalPrompt\", (): LegalPromptFactory => {\n return function legalPrompt(\n privacyPolicy: LegalDocument & { type: LegalDocument_Type.PRIVACY_POLICY },\n termsOfService: LegalDocument & { type: LegalDocument_Type.TERMS_OF_SERVICE },\n learnMore: LegalDocument & { type: LegalDocument_Type.LEARN_MORE },\n childrenProtectionActRestricted: boolean\n ) {\n const legalMessage = childrenProtectionActRestricted\n ? localizedString(\"legalPromptVariantGMessage\")\n : localizedString(\"legalPromptMessage\")({\n privacyPolicyUrl: privacyPolicy.webUrl,\n termsOfServiceUrl: termsOfService.webUrl,\n learnMoreUrl: learnMore.webUrl,\n });\n const legalTitleText = localizedString(\"legalPromptTermsOfService\");\n const legalTitle = childrenProtectionActRestricted ? legalTitleText : snapIcon;\n\n return {\n contentHash: computeHash(legalMessage),\n\n async show() {\n if (!childrenProtectionActRestricted) {\n return showTosDialog(legalTitle, legalTitleText, legalMessage);\n }\n\n while (true) {\n const adultOrChild = await showAdultOrChildDialog();\n switch (adultOrChild) {\n case \"child\": {\n const findGuardian = await showFindGuardianDialog();\n switch (findGuardian) {\n case \"cancel\":\n continue;\n case \"guardian\":\n return showTosDialog(legalTitle, legalTitleText, legalMessage);\n case \"dismiss\":\n return false;\n default:\n assertUnreachable(findGuardian);\n }\n }\n case \"adult\":\n return showTosDialog(legalTitle, legalTitleText, legalMessage);\n case \"dismiss\":\n return false;\n default:\n assertUnreachable(adultOrChild);\n }\n }\n },\n };\n };\n});\n"]}
|
|
@@ -4,6 +4,7 @@ import { RequestStateEventTarget } from "../handlers/requestStateEmittingHandler
|
|
|
4
4
|
import { LensDownloadDimensions } from "../metrics/reporters/reportLensAndAssetDownload";
|
|
5
5
|
import { Handler } from "../handlers/HandlerChainBuilder";
|
|
6
6
|
import { LensAssetManifestItem_RequestTiming } from "../generated-proto/pb_schema/camera_kit/v3/lens";
|
|
7
|
+
import { CameraKitApiHostname, CameraKitConfiguration } from "../configuration";
|
|
7
8
|
import { Lens, LensProto } from "./Lens";
|
|
8
9
|
import { LensAssetRepository } from "./assets/LensAssetRepository";
|
|
9
10
|
type LensFetchHandler = Handler<[
|
|
@@ -56,10 +57,11 @@ export declare class LensRepository {
|
|
|
56
57
|
private readonly lensFetchHandler;
|
|
57
58
|
private readonly lensSources;
|
|
58
59
|
private readonly lensAssetRepository;
|
|
60
|
+
private readonly apiHostname;
|
|
59
61
|
private readonly metadataCache;
|
|
60
62
|
private readonly binariesCache;
|
|
61
63
|
/** @internal */
|
|
62
|
-
constructor(lensMetadataFetchHandler: FetchHandler, lensFetchHandler: LensFetchHandler, lensSources: LensSources, lensAssetRepository: LensAssetRepository);
|
|
64
|
+
constructor(lensMetadataFetchHandler: FetchHandler, lensFetchHandler: LensFetchHandler, lensSources: LensSources, lensAssetRepository: LensAssetRepository, apiHostname: CameraKitApiHostname);
|
|
63
65
|
/**
|
|
64
66
|
* Retrieve a single Lens.
|
|
65
67
|
*
|
|
@@ -127,8 +129,8 @@ export declare class LensRepository {
|
|
|
127
129
|
* @internal
|
|
128
130
|
*/
|
|
129
131
|
export declare const lensRepositoryFactory: {
|
|
130
|
-
(args_0: RequestStateEventTarget, args_1: FetchHandler, args_2: FetchHandler, args_3: LensSources, args_4: LensAssetRepository): LensRepository;
|
|
132
|
+
(args_0: RequestStateEventTarget, args_1: FetchHandler, args_2: FetchHandler, args_3: LensSources, args_4: LensAssetRepository, args_5: CameraKitConfiguration): LensRepository;
|
|
131
133
|
token: "LensRepository";
|
|
132
|
-
dependencies: readonly ["requestStateEventTarget", "cameraKitServiceFetchHandler", "defaultFetchHandler", "lensSources", "lensAssetRepository"];
|
|
134
|
+
dependencies: readonly ["requestStateEventTarget", "cameraKitServiceFetchHandler", "defaultFetchHandler", "lensSources", "lensAssetRepository", "configuration"];
|
|
133
135
|
};
|
|
134
136
|
export {};
|
|
@@ -11,6 +11,7 @@ import { createArrayBufferParsingHandler } from "../handlers/arrayBufferParsingH
|
|
|
11
11
|
import { LensAssetManifestItem_RequestTiming } from "../generated-proto/pb_schema/camera_kit/v3/lens";
|
|
12
12
|
import { getLogger } from "../logger/logger";
|
|
13
13
|
import { errorLoggingDecorator } from "../logger/errorLoggingDecorator";
|
|
14
|
+
import { configurationToken } from "../configuration";
|
|
14
15
|
import { isLensArray, toPublicLens } from "./Lens";
|
|
15
16
|
import { retrieveCameraKitLens, retrieveCameraKitLensGroup } from "./lensHttpUtil";
|
|
16
17
|
import { decodeEnvelopes } from "./lensEnvelopeUtil";
|
|
@@ -46,11 +47,12 @@ function isOptionalAssetTimingArray(value) {
|
|
|
46
47
|
*/
|
|
47
48
|
export class LensRepository {
|
|
48
49
|
/** @internal */
|
|
49
|
-
constructor(lensMetadataFetchHandler, lensFetchHandler, lensSources, lensAssetRepository) {
|
|
50
|
+
constructor(lensMetadataFetchHandler, lensFetchHandler, lensSources, lensAssetRepository, apiHostname) {
|
|
50
51
|
this.lensMetadataFetchHandler = lensMetadataFetchHandler;
|
|
51
52
|
this.lensFetchHandler = lensFetchHandler;
|
|
52
53
|
this.lensSources = lensSources;
|
|
53
54
|
this.lensAssetRepository = lensAssetRepository;
|
|
55
|
+
this.apiHostname = apiHostname;
|
|
54
56
|
this.metadataCache = new Map();
|
|
55
57
|
this.binariesCache = new Map();
|
|
56
58
|
}
|
|
@@ -72,7 +74,7 @@ export class LensRepository {
|
|
|
72
74
|
}
|
|
73
75
|
}
|
|
74
76
|
else {
|
|
75
|
-
lens = yield retrieveCameraKitLens(this.lensMetadataFetchHandler, lensId, groupId);
|
|
77
|
+
lens = yield retrieveCameraKitLens(this.lensMetadataFetchHandler, lensId, groupId, this.apiHostname);
|
|
76
78
|
}
|
|
77
79
|
this.metadataCache.set(lens.id, lens);
|
|
78
80
|
return toPublicLens(lens);
|
|
@@ -97,7 +99,7 @@ export class LensRepository {
|
|
|
97
99
|
const envelopes = yield this.lensSources.retrieveLenses({ groupId });
|
|
98
100
|
const lenses = envelopes
|
|
99
101
|
? decodeEnvelopes(envelopes)
|
|
100
|
-
: yield retrieveCameraKitLensGroup(this.lensMetadataFetchHandler, groupId);
|
|
102
|
+
: yield retrieveCameraKitLensGroup(this.lensMetadataFetchHandler, groupId, this.apiHostname);
|
|
101
103
|
lenses.forEach((lens) => this.metadataCache.set(lens.id, lens));
|
|
102
104
|
return lenses.map(toPublicLens);
|
|
103
105
|
}
|
|
@@ -231,10 +233,11 @@ export const lensRepositoryFactory = Injectable("LensRepository", [
|
|
|
231
233
|
defaultFetchHandlerFactory.token,
|
|
232
234
|
lensSourcesFactory.token,
|
|
233
235
|
lensAssetRepositoryFactory.token,
|
|
234
|
-
|
|
236
|
+
configurationToken,
|
|
237
|
+
], (requestStateEventTarget, lensMetadataFetchHandler, defaultFetchHandler, lensSources, lensAssetRepository, configuration) => {
|
|
235
238
|
const lensFetchHandler = new HandlerChainBuilder(defaultFetchHandler)
|
|
236
239
|
.map(createRequestStateEmittingHandler(requestStateEventTarget))
|
|
237
240
|
.map(createArrayBufferParsingHandler()).handler;
|
|
238
|
-
return new LensRepository(lensMetadataFetchHandler, lensFetchHandler, lensSources, lensAssetRepository);
|
|
241
|
+
return new LensRepository(lensMetadataFetchHandler, lensFetchHandler, lensSources, lensAssetRepository, configuration.apiHostname);
|
|
239
242
|
});
|
|
240
243
|
//# sourceMappingURL=LensRepository.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LensRepository.js","sourceRoot":"","sources":["../../src/lens/LensRepository.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,iBAAiB,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC7G,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,mCAAmC,EAAE,MAAM,iDAAiD,CAAC;AACtG,OAAO,EAAE,0BAA0B,EAAgB,MAAM,iCAAiC,CAAC;AAC3F,OAAO,EAAe,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAEH,iCAAiC,EACjC,8BAA8B,GACjC,MAAM,yCAAyC,CAAC;AAEjD,OAAO,EAAW,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAC/E,OAAO,EAAE,+BAA+B,EAAE,MAAM,uCAAuC,CAAC;AACxF,OAAO,EAAE,mCAAmC,EAAE,MAAM,iDAAiD,CAAC;AACtG,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAE,WAAW,EAAmB,YAAY,EAAE,MAAM,QAAQ,CAAC;AACpE,OAAO,EAAE,qBAAqB,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AACnF,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAuB,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAE/F,MAAM,MAAM,GAAG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AAA;;;;8CAavE;AAgBK;IAFL,QAAQ;IACR,GAAG;IACkB,WAAA,KAAK,CAAC,iBAAiB,CAAC,CAAA;;;;oDAwB7C;AA2BK;IAFL,QAAQ;IACR,GAAG;IAEC,WAAA,KAAK,CAAC,WAAW,CAAC,CAAA;IAClB,WAAA,KAAK,CAAC,0BAA0B,CAAC,CAAA;;;;sDAgBrC;AAgDL;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,UAAU,CAC3C,gBAAgB,EAChB;IACI,8BAA8B,CAAC,KAAK;IACpC,mCAAmC,CAAC,KAAK;IACzC,0BAA0B,CAAC,KAAK;IAChC,kBAAkB,CAAC,KAAK;IACxB,0BAA0B,CAAC,KAAK;CAC1B,EACV,CACI,uBAAgD,EAChD,wBAAsC,EACtC,mBAAiC,EACjC,WAAwB,EACxB,mBAAwC,EAC1C,EAAE;IACA,MAAM,gBAAgB,GAAG,IAAI,mBAAmB,CAAC,mBAAmB,CAAC;SAChE,GAAG,CAAC,iCAAiC,CAAyB,uBAAuB,CAAC,CAAC;SACvF,GAAG,CAAC,+BAA+B,EAAE,CAAC,CAAC,OAAO,CAAC;IACpD,OAAO,IAAI,cAAc,CAAC,wBAAwB,EAAE,gBAAgB,EAAE,WAAW,EAAE,mBAAmB,CAAC,CAAC;AAC5G,CAAC,CACJ,CAAC","sourcesContent":["import { guard, validate } from \"../common/validate\";\nimport { isArrayOfType, isSafeString, isSafeStringArray, isString, isUndefined } from \"../common/typeguards\";\nimport { Injectable } from \"../dependency-injection/Injectable\";\nimport { cameraKitServiceFetchHandlerFactory } from \"../handlers/cameraKitServiceFetchHandlerFactory\";\nimport { defaultFetchHandlerFactory, FetchHandler } from \"../handlers/defaultFetchHandler\";\nimport { LensSources, lensSourcesFactory } from \"../extensions/LensSources\";\nimport {\n RequestStateEventTarget,\n createRequestStateEmittingHandler,\n requestStateEventTargetFactory,\n} from \"../handlers/requestStateEmittingHandler\";\nimport { LensDownloadDimensions } from \"../metrics/reporters/reportLensAndAssetDownload\";\nimport { Handler, HandlerChainBuilder } from \"../handlers/HandlerChainBuilder\";\nimport { createArrayBufferParsingHandler } from \"../handlers/arrayBufferParsingHandler\";\nimport { LensAssetManifestItem_RequestTiming } from \"../generated-proto/pb_schema/camera_kit/v3/lens\";\nimport { getLogger } from \"../logger/logger\";\nimport { errorLoggingDecorator } from \"../logger/errorLoggingDecorator\";\nimport { isLensArray, Lens, LensProto, toPublicLens } from \"./Lens\";\nimport { retrieveCameraKitLens, retrieveCameraKitLensGroup } from \"./lensHttpUtil\";\nimport { decodeEnvelopes } from \"./lensEnvelopeUtil\";\nimport { LensAssetRepository, lensAssetRepositoryFactory } from \"./assets/LensAssetRepository\";\n\nconst logger = getLogger(\"LensRepository\");\nconst log = errorLoggingDecorator(logger);\n\ntype LensFetchHandler = Handler<\n [RequestInfo, LensDownloadDimensions],\n [ArrayBuffer, Response],\n RequestInit | undefined\n>;\n\nconst assetTimingMap = {\n required: LensAssetManifestItem_RequestTiming.REQUIRED,\n onDemand: LensAssetManifestItem_RequestTiming.ON_DEMAND,\n};\n\nfunction isAssetTiming(value: unknown): value is AssetTiming {\n return isString(value) && assetTimingMap.hasOwnProperty(value);\n}\n\nfunction isOptionalAssetTimingArray(value: unknown): value is undefined | AssetTiming[] {\n return isUndefined(value) || isArrayOfType(isAssetTiming, value);\n}\n\n/**\n * Lens assets are included in a manifest, and each will indicate when that asset will be used by the lens.\n *\n * Assets can have the following timing values:\n * - `required`: the lens will definitely request this asset immediately when the lens is applied.\n * - `onDemand`: the lens may request this asset at some time while the lens is applied.\n *\n * Depending on the use-case, an application may want to cache both required and onDemand assets for\n * a particular lens, or may decide to only cache required assets (or cache no assets).\n *\n * @category Lenses\n */\nexport type AssetTiming = keyof typeof assetTimingMap;\n\nexport interface LensBinary {\n lensBuffer: ArrayBuffer;\n lensChecksum: string;\n}\n\n/**\n * The LensRepository is used to query for lenses from specific lens groups, or for a lens with a specific ID.\n *\n * Lens groups are configured in the CameraKit Portal -- that's where you'll find lens group IDs and lens IDs.\n *\n * Lenses must be loaded by the LensRepository before they can be applied to a {@link CameraKitSession}.\n *\n * @example\n * ```ts\n * const cameraKit = await bootstrapCameraKit(options)\n * const session = await cameraKit.createSession()\n * const lens = await cameraKit.lensRepository.loadLens(lensId, groupId)\n * session.applyLens(lens)\n * ```\n *\n * @category Lenses\n */\nexport class LensRepository {\n private readonly metadataCache = new Map<string, LensProto>();\n private readonly binariesCache = new Map<string, ArrayBuffer>();\n\n /** @internal */\n constructor(\n private readonly lensMetadataFetchHandler: FetchHandler,\n private readonly lensFetchHandler: LensFetchHandler,\n private readonly lensSources: LensSources,\n private readonly lensAssetRepository: LensAssetRepository\n ) {}\n\n /**\n * Retrieve a single Lens.\n *\n * @param lensId Desired Lens's unique ID. Can be found in the CameraKit Portal.\n * @param groupId The ID of a group containing the desired Lens. Can be found in the CameraKit Portal.\n * @returns Resolves with the desired Lens, or rejects if an error occurred (including a missing Lens).\n */\n @validate\n @log\n async loadLens(@guard(isSafeString) lensId: string, @guard(isSafeString) groupId: string): Promise<Lens> {\n const envelopes = await this.lensSources.retrieveLenses({ lensId, groupId });\n let lens: LensProto;\n if (envelopes) {\n lens = decodeEnvelopes(envelopes)[0];\n if (!lens) {\n throw new Error(\"Expected non-empty envelope.\");\n }\n } else {\n lens = await retrieveCameraKitLens(this.lensMetadataFetchHandler, lensId, groupId);\n }\n this.metadataCache.set(lens.id, lens);\n return toPublicLens(lens);\n }\n\n /**\n * Retrieve the Lenses contained in a list of Lens Groups.\n *\n * This may result in multiple requests to retrieve Lens data (e.g. one per desired group). If any constituent\n * requests fail, those errors will be reported in the response – but the returned Promise will not be rejected. Any\n * Lenses which could be successfully retrieved will be available in the response.\n *\n * @param groupIds A list of Lens Group IDs. Can be found in the CameraKit Portal.\n * @returns Resolves with a flattened list of all lenses in the desired groups. If any errors occurred during the\n * query operation, these will be included in a separate list. If errors are present, the list of Lenses may not\n * contain all the Lenses from the desired groups.\n */\n @validate\n @log\n async loadLensGroups(@guard(isSafeStringArray) groupIds: string[]): Promise<{\n errors: Error[];\n lenses: Lens[];\n }> {\n const responses = await Promise.all(\n groupIds.map(async (groupId) => {\n try {\n const envelopes = await this.lensSources.retrieveLenses({ groupId });\n const lenses = envelopes\n ? decodeEnvelopes(envelopes)\n : await retrieveCameraKitLensGroup(this.lensMetadataFetchHandler, groupId);\n lenses.forEach((lens) => this.metadataCache.set(lens.id, lens));\n return lenses.map(toPublicLens);\n } catch (error) {\n logger.error(new Error(`Failed to load lens group ${groupId}.`, { cause: error }));\n return error as Error;\n }\n })\n );\n\n const errors: Error[] = [];\n const lenses: Lens[] = [];\n responses.forEach((response) => (Array.isArray(response) ? lenses.push(...response) : errors.push(response)));\n return { errors, lenses };\n }\n\n /**\n * Loads and caches lens content and dependencies to reduce latency when {@link CameraKitSession.applyLens} is later\n * called to apply the lens. This is an in-memory cache, it will not be persisted across page loads.\n *\n * This may useful if the application A) knows which lenses will be applied and B) has some opportunity to call\n * this method before a lens is applied. For example, if the user must perform some other actions before lenses\n * become active, this might be a good opportunity to cache lenses to improve applyLens latency.\n *\n * @example\n * ```ts\n * const lens = await cameraKit.lensRepository.loadLens(lensId, groupId)\n * await cameraKit.lensRepository.cacheLensContent([lens])\n *\n * // sometime later -- this call will use the cached lens content, making lens application faster.\n * await cameraKitSession.applyLens(lens)\n * ```\n *\n * @param lenses Array of lenses to cache in memory.\n * @param assetTimingsToCache Lenses specify certain required assets that are necessary for the lens to render, and\n * other assets which may be needed by the lens. By default this method will cache all of those assets, but this\n * behavior can be modified to only load the required assets, only the \"onDemand\" assets, or neither (by passing\n * an empty array).\n */\n @validate\n @log\n async cacheLensContent(\n @guard(isLensArray) lenses: Lens[],\n @guard(isOptionalAssetTimingArray) assetTimingsToCache: AssetTiming[] = [\"required\", \"onDemand\"]\n ) {\n const assetTimingsToLoad = assetTimingsToCache.map((timing) => assetTimingMap[timing]);\n await Promise.all(\n lenses.map(async (lens) => {\n try {\n const { lensBuffer } = await this.getLensContent(lens);\n // Safety: getLensContent() call above ensures metadata to exist\n const { content } = this.metadataCache.get(lens.id)!;\n this.binariesCache.set(lens.id, lensBuffer);\n await this.lensAssetRepository.cacheAssets(content!.assetManifest, lens, assetTimingsToLoad);\n } catch (e) {\n logger.warn(new Error(`Failed to cache lens ${lens.id}.`, { cause: e }));\n }\n })\n );\n }\n\n /**\n * Returns loaded Lens metadata if available.\n */\n getLensMetadata(lensId: string): LensProto | undefined {\n return this.metadataCache.get(lensId);\n }\n\n /**\n * Removes Lens content from the in-memory cache.\n */\n removeCachedLenses(lenses: Lens[]) {\n lenses.forEach((lens) => this.binariesCache.delete(lens.id));\n }\n\n /**\n * Fetches lens content and assets. This may come from the cache, otherwise network requests will be made.\n *\n * @internal\n */\n async getLensContent(lens: Lens): Promise<LensBinary> {\n const { content } = this.metadataCache.get(lens.id) ?? {};\n if (!content) {\n throw new Error(`Cannot find metadata for lens ${lens.id}.`);\n }\n\n const cachedLensBuffer = this.binariesCache.get(lens.id);\n if (cachedLensBuffer) {\n return {\n lensBuffer: cachedLensBuffer,\n lensChecksum: content.lnsSha256,\n };\n }\n\n // Load required lens assets and the lens itself in parallel. We count both toward lens download time.\n const [lensBuffer] = await this.lensFetchHandler([\n // TODO: remove force-cache once https://jira.sc-corp.net/browse/CAMKIT-3671 is addressed\n new Request(content.lnsUrlBolt, { cache: \"force-cache\" }),\n {\n requestType: \"lens_content\",\n lensId: lens.id,\n },\n ]);\n return { lensBuffer, lensChecksum: content.lnsSha256 };\n }\n}\n\n/**\n * @internal\n */\nexport const lensRepositoryFactory = Injectable(\n \"LensRepository\",\n [\n requestStateEventTargetFactory.token,\n cameraKitServiceFetchHandlerFactory.token,\n defaultFetchHandlerFactory.token,\n lensSourcesFactory.token,\n lensAssetRepositoryFactory.token,\n ] as const,\n (\n requestStateEventTarget: RequestStateEventTarget,\n lensMetadataFetchHandler: FetchHandler,\n defaultFetchHandler: FetchHandler,\n lensSources: LensSources,\n lensAssetRepository: LensAssetRepository\n ) => {\n const lensFetchHandler = new HandlerChainBuilder(defaultFetchHandler)\n .map(createRequestStateEmittingHandler<LensDownloadDimensions>(requestStateEventTarget))\n .map(createArrayBufferParsingHandler()).handler;\n return new LensRepository(lensMetadataFetchHandler, lensFetchHandler, lensSources, lensAssetRepository);\n }\n);\n"]}
|
|
1
|
+
{"version":3,"file":"LensRepository.js","sourceRoot":"","sources":["../../src/lens/LensRepository.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,iBAAiB,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC7G,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,mCAAmC,EAAE,MAAM,iDAAiD,CAAC;AACtG,OAAO,EAAE,0BAA0B,EAAgB,MAAM,iCAAiC,CAAC;AAC3F,OAAO,EAAe,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAEH,iCAAiC,EACjC,8BAA8B,GACjC,MAAM,yCAAyC,CAAC;AAEjD,OAAO,EAAW,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAC/E,OAAO,EAAE,+BAA+B,EAAE,MAAM,uCAAuC,CAAC;AACxF,OAAO,EAAE,mCAAmC,EAAE,MAAM,iDAAiD,CAAC;AACtG,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAgD,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACpG,OAAO,EAAE,WAAW,EAAmB,YAAY,EAAE,MAAM,QAAQ,CAAC;AACpE,OAAO,EAAE,qBAAqB,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AACnF,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAA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AE,OAAO,CAAC,SAAS,EAAE,CAAC;;KAC1D;CACJ;AAhJS;IAFL,QAAQ;IACR,GAAG;IACY,WAAA,KAAK,CAAC,YAAY,CAAC,CAAA;IAAkB,WAAA,KAAK,CAAC,YAAY,CAAC,CAAA;;;;8CAavE;AAgBK;IAFL,QAAQ;IACR,GAAG;IACkB,WAAA,KAAK,CAAC,iBAAiB,CAAC,CAAA;;;;oDAwB7C;AA2BK;IAFL,QAAQ;IACR,GAAG;IAEC,WAAA,KAAK,CAAC,WAAW,CAAC,CAAA;IAClB,WAAA,KAAK,CAAC,0BAA0B,CAAC,CAAA;;;;sDAgBrC;AAgDL;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,UAAU,CAC3C,gBAAgB,EAChB;IACI,8BAA8B,CAAC,KAAK;IACpC,mCAAmC,CAAC,KAAK;IACzC,0BAA0B,CAAC,KAAK;IAChC,kBAAkB,CAAC,KAAK;IACxB,0BAA0B,CAAC,KAAK;IAChC,kBAAkB;CACZ,EACV,CACI,uBAAgD,EAChD,wBAAsC,EACtC,mBAAiC,EACjC,WAAwB,EACxB,mBAAwC,EACxC,aAAqC,EACvC,EAAE;IACA,MAAM,gBAAgB,GAAG,IAAI,mBAAmB,CAAC,mBAAmB,CAAC;SAChE,GAAG,CAAC,iCAAiC,CAAyB,uBAAuB,CAAC,CAAC;SACvF,GAAG,CAAC,+BAA+B,EAAE,CAAC,CAAC,OAAO,CAAC;IACpD,OAAO,IAAI,cAAc,CACrB,wBAAwB,EACxB,gBAAgB,EAChB,WAAW,EACX,mBAAmB,EACnB,aAAa,CAAC,WAAW,CAC5B,CAAC;AACN,CAAC,CACJ,CAAC","sourcesContent":["import { guard, validate } from \"../common/validate\";\nimport { isArrayOfType, isSafeString, isSafeStringArray, isString, isUndefined } from \"../common/typeguards\";\nimport { Injectable } from \"../dependency-injection/Injectable\";\nimport { cameraKitServiceFetchHandlerFactory } from \"../handlers/cameraKitServiceFetchHandlerFactory\";\nimport { defaultFetchHandlerFactory, FetchHandler } from \"../handlers/defaultFetchHandler\";\nimport { LensSources, lensSourcesFactory } from \"../extensions/LensSources\";\nimport {\n RequestStateEventTarget,\n createRequestStateEmittingHandler,\n requestStateEventTargetFactory,\n} from \"../handlers/requestStateEmittingHandler\";\nimport { LensDownloadDimensions } from \"../metrics/reporters/reportLensAndAssetDownload\";\nimport { Handler, HandlerChainBuilder } from \"../handlers/HandlerChainBuilder\";\nimport { createArrayBufferParsingHandler } from \"../handlers/arrayBufferParsingHandler\";\nimport { LensAssetManifestItem_RequestTiming } from \"../generated-proto/pb_schema/camera_kit/v3/lens\";\nimport { getLogger } from \"../logger/logger\";\nimport { errorLoggingDecorator } from \"../logger/errorLoggingDecorator\";\nimport { CameraKitApiHostname, CameraKitConfiguration, configurationToken } from \"../configuration\";\nimport { isLensArray, Lens, LensProto, toPublicLens } from \"./Lens\";\nimport { retrieveCameraKitLens, retrieveCameraKitLensGroup } from \"./lensHttpUtil\";\nimport { decodeEnvelopes } from \"./lensEnvelopeUtil\";\nimport { LensAssetRepository, lensAssetRepositoryFactory } from \"./assets/LensAssetRepository\";\n\nconst logger = getLogger(\"LensRepository\");\nconst log = errorLoggingDecorator(logger);\n\ntype LensFetchHandler = Handler<\n [RequestInfo, LensDownloadDimensions],\n [ArrayBuffer, Response],\n RequestInit | undefined\n>;\n\nconst assetTimingMap = {\n required: LensAssetManifestItem_RequestTiming.REQUIRED,\n onDemand: LensAssetManifestItem_RequestTiming.ON_DEMAND,\n};\n\nfunction isAssetTiming(value: unknown): value is AssetTiming {\n return isString(value) && assetTimingMap.hasOwnProperty(value);\n}\n\nfunction isOptionalAssetTimingArray(value: unknown): value is undefined | AssetTiming[] {\n return isUndefined(value) || isArrayOfType(isAssetTiming, value);\n}\n\n/**\n * Lens assets are included in a manifest, and each will indicate when that asset will be used by the lens.\n *\n * Assets can have the following timing values:\n * - `required`: the lens will definitely request this asset immediately when the lens is applied.\n * - `onDemand`: the lens may request this asset at some time while the lens is applied.\n *\n * Depending on the use-case, an application may want to cache both required and onDemand assets for\n * a particular lens, or may decide to only cache required assets (or cache no assets).\n *\n * @category Lenses\n */\nexport type AssetTiming = keyof typeof assetTimingMap;\n\nexport interface LensBinary {\n lensBuffer: ArrayBuffer;\n lensChecksum: string;\n}\n\n/**\n * The LensRepository is used to query for lenses from specific lens groups, or for a lens with a specific ID.\n *\n * Lens groups are configured in the CameraKit Portal -- that's where you'll find lens group IDs and lens IDs.\n *\n * Lenses must be loaded by the LensRepository before they can be applied to a {@link CameraKitSession}.\n *\n * @example\n * ```ts\n * const cameraKit = await bootstrapCameraKit(options)\n * const session = await cameraKit.createSession()\n * const lens = await cameraKit.lensRepository.loadLens(lensId, groupId)\n * session.applyLens(lens)\n * ```\n *\n * @category Lenses\n */\nexport class LensRepository {\n private readonly metadataCache = new Map<string, LensProto>();\n private readonly binariesCache = new Map<string, ArrayBuffer>();\n\n /** @internal */\n constructor(\n private readonly lensMetadataFetchHandler: FetchHandler,\n private readonly lensFetchHandler: LensFetchHandler,\n private readonly lensSources: LensSources,\n private readonly lensAssetRepository: LensAssetRepository,\n private readonly apiHostname: CameraKitApiHostname\n ) {}\n\n /**\n * Retrieve a single Lens.\n *\n * @param lensId Desired Lens's unique ID. Can be found in the CameraKit Portal.\n * @param groupId The ID of a group containing the desired Lens. Can be found in the CameraKit Portal.\n * @returns Resolves with the desired Lens, or rejects if an error occurred (including a missing Lens).\n */\n @validate\n @log\n async loadLens(@guard(isSafeString) lensId: string, @guard(isSafeString) groupId: string): Promise<Lens> {\n const envelopes = await this.lensSources.retrieveLenses({ lensId, groupId });\n let lens: LensProto;\n if (envelopes) {\n lens = decodeEnvelopes(envelopes)[0];\n if (!lens) {\n throw new Error(\"Expected non-empty envelope.\");\n }\n } else {\n lens = await retrieveCameraKitLens(this.lensMetadataFetchHandler, lensId, groupId, this.apiHostname);\n }\n this.metadataCache.set(lens.id, lens);\n return toPublicLens(lens);\n }\n\n /**\n * Retrieve the Lenses contained in a list of Lens Groups.\n *\n * This may result in multiple requests to retrieve Lens data (e.g. one per desired group). If any constituent\n * requests fail, those errors will be reported in the response – but the returned Promise will not be rejected. Any\n * Lenses which could be successfully retrieved will be available in the response.\n *\n * @param groupIds A list of Lens Group IDs. Can be found in the CameraKit Portal.\n * @returns Resolves with a flattened list of all lenses in the desired groups. If any errors occurred during the\n * query operation, these will be included in a separate list. If errors are present, the list of Lenses may not\n * contain all the Lenses from the desired groups.\n */\n @validate\n @log\n async loadLensGroups(@guard(isSafeStringArray) groupIds: string[]): Promise<{\n errors: Error[];\n lenses: Lens[];\n }> {\n const responses = await Promise.all(\n groupIds.map(async (groupId) => {\n try {\n const envelopes = await this.lensSources.retrieveLenses({ groupId });\n const lenses = envelopes\n ? decodeEnvelopes(envelopes)\n : await retrieveCameraKitLensGroup(this.lensMetadataFetchHandler, groupId, this.apiHostname);\n lenses.forEach((lens) => this.metadataCache.set(lens.id, lens));\n return lenses.map(toPublicLens);\n } catch (error) {\n logger.error(new Error(`Failed to load lens group ${groupId}.`, { cause: error }));\n return error as Error;\n }\n })\n );\n\n const errors: Error[] = [];\n const lenses: Lens[] = [];\n responses.forEach((response) => (Array.isArray(response) ? lenses.push(...response) : errors.push(response)));\n return { errors, lenses };\n }\n\n /**\n * Loads and caches lens content and dependencies to reduce latency when {@link CameraKitSession.applyLens} is later\n * called to apply the lens. This is an in-memory cache, it will not be persisted across page loads.\n *\n * This may useful if the application A) knows which lenses will be applied and B) has some opportunity to call\n * this method before a lens is applied. For example, if the user must perform some other actions before lenses\n * become active, this might be a good opportunity to cache lenses to improve applyLens latency.\n *\n * @example\n * ```ts\n * const lens = await cameraKit.lensRepository.loadLens(lensId, groupId)\n * await cameraKit.lensRepository.cacheLensContent([lens])\n *\n * // sometime later -- this call will use the cached lens content, making lens application faster.\n * await cameraKitSession.applyLens(lens)\n * ```\n *\n * @param lenses Array of lenses to cache in memory.\n * @param assetTimingsToCache Lenses specify certain required assets that are necessary for the lens to render, and\n * other assets which may be needed by the lens. By default this method will cache all of those assets, but this\n * behavior can be modified to only load the required assets, only the \"onDemand\" assets, or neither (by passing\n * an empty array).\n */\n @validate\n @log\n async cacheLensContent(\n @guard(isLensArray) lenses: Lens[],\n @guard(isOptionalAssetTimingArray) assetTimingsToCache: AssetTiming[] = [\"required\", \"onDemand\"]\n ) {\n const assetTimingsToLoad = assetTimingsToCache.map((timing) => assetTimingMap[timing]);\n await Promise.all(\n lenses.map(async (lens) => {\n try {\n const { lensBuffer } = await this.getLensContent(lens);\n // Safety: getLensContent() call above ensures metadata to exist\n const { content } = this.metadataCache.get(lens.id)!;\n this.binariesCache.set(lens.id, lensBuffer);\n await this.lensAssetRepository.cacheAssets(content!.assetManifest, lens, assetTimingsToLoad);\n } catch (e) {\n logger.warn(new Error(`Failed to cache lens ${lens.id}.`, { cause: e }));\n }\n })\n );\n }\n\n /**\n * Returns loaded Lens metadata if available.\n */\n getLensMetadata(lensId: string): LensProto | undefined {\n return this.metadataCache.get(lensId);\n }\n\n /**\n * Removes Lens content from the in-memory cache.\n */\n removeCachedLenses(lenses: Lens[]) {\n lenses.forEach((lens) => this.binariesCache.delete(lens.id));\n }\n\n /**\n * Fetches lens content and assets. This may come from the cache, otherwise network requests will be made.\n *\n * @internal\n */\n async getLensContent(lens: Lens): Promise<LensBinary> {\n const { content } = this.metadataCache.get(lens.id) ?? {};\n if (!content) {\n throw new Error(`Cannot find metadata for lens ${lens.id}.`);\n }\n\n const cachedLensBuffer = this.binariesCache.get(lens.id);\n if (cachedLensBuffer) {\n return {\n lensBuffer: cachedLensBuffer,\n lensChecksum: content.lnsSha256,\n };\n }\n\n // Load required lens assets and the lens itself in parallel. We count both toward lens download time.\n const [lensBuffer] = await this.lensFetchHandler([\n // TODO: remove force-cache once https://jira.sc-corp.net/browse/CAMKIT-3671 is addressed\n new Request(content.lnsUrlBolt, { cache: \"force-cache\" }),\n {\n requestType: \"lens_content\",\n lensId: lens.id,\n },\n ]);\n return { lensBuffer, lensChecksum: content.lnsSha256 };\n }\n}\n\n/**\n * @internal\n */\nexport const lensRepositoryFactory = Injectable(\n \"LensRepository\",\n [\n requestStateEventTargetFactory.token,\n cameraKitServiceFetchHandlerFactory.token,\n defaultFetchHandlerFactory.token,\n lensSourcesFactory.token,\n lensAssetRepositoryFactory.token,\n configurationToken,\n ] as const,\n (\n requestStateEventTarget: RequestStateEventTarget,\n lensMetadataFetchHandler: FetchHandler,\n defaultFetchHandler: FetchHandler,\n lensSources: LensSources,\n lensAssetRepository: LensAssetRepository,\n configuration: CameraKitConfiguration\n ) => {\n const lensFetchHandler = new HandlerChainBuilder(defaultFetchHandler)\n .map(createRequestStateEmittingHandler<LensDownloadDimensions>(requestStateEventTarget))\n .map(createArrayBufferParsingHandler()).handler;\n return new LensRepository(\n lensMetadataFetchHandler,\n lensFetchHandler,\n lensSources,\n lensAssetRepository,\n configuration.apiHostname\n );\n }\n);\n"]}
|
|
@@ -7,6 +7,7 @@ import { toPublicLens } from "../Lens";
|
|
|
7
7
|
import { lensRepositoryFactory } from "../LensRepository";
|
|
8
8
|
import { lensAssetRepositoryFactory } from "./LensAssetRepository";
|
|
9
9
|
const logger = getLogger("LensAssetProvider");
|
|
10
|
+
const maxConsecutiveErrors = 3;
|
|
10
11
|
/**
|
|
11
12
|
* Registers a remote asset provider function with a given instance of LensCore.
|
|
12
13
|
*
|
|
@@ -16,15 +17,20 @@ const logger = getLogger("LensAssetProvider");
|
|
|
16
17
|
* @internal
|
|
17
18
|
*/
|
|
18
19
|
export const registerLensAssetsProvider = Injectable("registerLensAssetsProvider", [lensCoreFactory.token, lensRepositoryFactory.token, lensAssetRepositoryFactory.token], (lensCore, lensRepository, lensAssetRepository) => {
|
|
20
|
+
const consecutiveErrorsPerAsset = new Map();
|
|
19
21
|
lensCore.setRemoteAssetsProvider((assetDescriptor) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
-
var _a;
|
|
22
|
+
var _a, _b, _c;
|
|
21
23
|
// Fetch an asset and provide it to LensCore. If fetching the asset fails we give LensCore
|
|
22
24
|
// an empty response (which it may handle in a variety of ways, e.g. retry, gracefully
|
|
23
25
|
// degrade lens behavior, throw error) and then reject.
|
|
24
26
|
const { assetId, assetType, effectId } = assetDescriptor;
|
|
25
27
|
try {
|
|
28
|
+
if (((_a = consecutiveErrorsPerAsset.get(assetId)) !== null && _a !== void 0 ? _a : 0) > maxConsecutiveErrors) {
|
|
29
|
+
throw new Error(`Maximum consecutive asset load errors reached for asset ${assetId}`);
|
|
30
|
+
}
|
|
26
31
|
const lens = effectId ? lensRepository.getLensMetadata(effectId) : undefined;
|
|
27
|
-
yield lensAssetRepository.loadAsset(assetDescriptor, lens && toPublicLens(lens), (
|
|
32
|
+
yield lensAssetRepository.loadAsset(assetDescriptor, lens && toPublicLens(lens), (_b = lens === null || lens === void 0 ? void 0 : lens.content) === null || _b === void 0 ? void 0 : _b.assetManifest);
|
|
33
|
+
consecutiveErrorsPerAsset.set(assetId, 0);
|
|
28
34
|
}
|
|
29
35
|
catch (error) {
|
|
30
36
|
// if an error occurs, LensCore handles things in different ways
|
|
@@ -34,7 +40,16 @@ export const registerLensAssetsProvider = Injectable("registerLensAssetsProvider
|
|
|
34
40
|
assetId,
|
|
35
41
|
assetType,
|
|
36
42
|
});
|
|
37
|
-
|
|
43
|
+
const consecutiveErrors = ((_c = consecutiveErrorsPerAsset.get(assetId)) !== null && _c !== void 0 ? _c : 0) + 1;
|
|
44
|
+
consecutiveErrorsPerAsset.set(assetId, consecutiveErrors);
|
|
45
|
+
// We've already reported `maxConsecutiveErrors` number of errors for this asset, so we can skip
|
|
46
|
+
// logging additional errors.
|
|
47
|
+
if (consecutiveErrors <= maxConsecutiveErrors) {
|
|
48
|
+
logger.error(lensAssetError(`Error occurred while handling lens asset ${assetId} request.`, error));
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
logger.warn(`Maximum consecutive asset load errors reached for asset ${assetId}`);
|
|
52
|
+
}
|
|
38
53
|
}
|
|
39
54
|
}));
|
|
40
55
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LensAssetsProvider.js","sourceRoot":"","sources":["../../../src/lens/assets/LensAssetsProvider.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAkB,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAkB,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAAuB,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AAExF,MAAM,MAAM,GAAG,SAAS,CAAC,mBAAmB,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"LensAssetsProvider.js","sourceRoot":"","sources":["../../../src/lens/assets/LensAssetsProvider.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAkB,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAkB,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAAuB,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AAExF,MAAM,MAAM,GAAG,SAAS,CAAC,mBAAmB,CAAC,CAAC;AAC9C,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAO/B;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,UAAU,CAChD,4BAA4B,EAC5B,CAAC,eAAe,CAAC,KAAK,EAAE,qBAAqB,CAAC,KAAK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,iBAAiB,IAAI,oBAAoB,EAAE;gBAC3C,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,4CAA4C,OAAO,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;aACvG;iBAAM;gBACH,MAAM,CAAC,IAAI,CAAC,2DAA2D,OAAO,EAAE,CAAC,CAAC;aACrF;SACJ;IACL,CAAC,CAAA,CAAC,CAAC;AACP,CAAC,CACJ,CAAC","sourcesContent":["import { Injectable } from \"../../dependency-injection/Injectable\";\nimport { lensAssetError } from \"../../namedErrors\";\nimport { lensCoreFactory, LensCoreModule } from \"../../lens-core-module\";\nimport { getLogger } from \"../../logger/logger\";\nimport { MakeTaggedBusinessEvent } from \"../../metrics/businessEventsReporter\";\nimport { toPublicLens } from \"../Lens\";\nimport { LensRepository, lensRepositoryFactory } from \"../LensRepository\";\nimport { LensAssetRepository, lensAssetRepositoryFactory } from \"./LensAssetRepository\";\n\nconst logger = getLogger(\"LensAssetProvider\");\nconst maxConsecutiveErrors = 3;\n\n/**\n * The AssetValidationFailed metric reports every time we handle an asset checksum validation failure.\n */\nexport type AssetValidationFailed = MakeTaggedBusinessEvent<\"assetValidationFailed\">;\n\n/**\n * Registers a remote asset provider function with a given instance of LensCore.\n *\n * *Note:* LensCoreModule.initialize must be called on the desired LensCoreModule instance **prior** to passing it\n * to the LensAssetsProvider constructor. If this class is instantiated with a LensCoreModule that has not been\n * initialized, the registry of the asset provider function will fail silently and no remote assets will be loaded.\n * @internal\n */\nexport const registerLensAssetsProvider = Injectable(\n \"registerLensAssetsProvider\",\n [lensCoreFactory.token, lensRepositoryFactory.token, lensAssetRepositoryFactory.token] as const,\n (lensCore: LensCoreModule, lensRepository: LensRepository, lensAssetRepository: LensAssetRepository) => {\n const consecutiveErrorsPerAsset = new Map<string, number>();\n\n lensCore.setRemoteAssetsProvider(async (assetDescriptor) => {\n // Fetch an asset and provide it to LensCore. If fetching the asset fails we give LensCore\n // an empty response (which it may handle in a variety of ways, e.g. retry, gracefully\n // degrade lens behavior, throw error) and then reject.\n const { assetId, assetType, effectId } = assetDescriptor;\n\n try {\n if ((consecutiveErrorsPerAsset.get(assetId) ?? 0) > maxConsecutiveErrors) {\n throw new Error(`Maximum consecutive asset load errors reached for asset ${assetId}`);\n }\n\n const lens = effectId ? lensRepository.getLensMetadata(effectId) : undefined;\n await lensAssetRepository.loadAsset(\n assetDescriptor,\n lens && toPublicLens(lens),\n lens?.content?.assetManifest\n );\n consecutiveErrorsPerAsset.set(assetId, 0);\n } catch (error) {\n // if an error occurs, LensCore handles things in different ways\n // depending on the active lens. It might: 1) retry, 2) gracefully degrade lens behavior,\n // 3) lens JS might throw, which will be passed to the exceptionHandler we register with LensCore.\n lensCore.provideRemoteAssetsResponse({\n assetId,\n assetType,\n });\n\n const consecutiveErrors = (consecutiveErrorsPerAsset.get(assetId) ?? 0) + 1;\n consecutiveErrorsPerAsset.set(assetId, consecutiveErrors);\n\n // We've already reported `maxConsecutiveErrors` number of errors for this asset, so we can skip\n // logging additional errors.\n if (consecutiveErrors <= maxConsecutiveErrors) {\n logger.error(lensAssetError(`Error occurred while handling lens asset ${assetId} request.`, error));\n } else {\n logger.warn(`Maximum consecutive asset load errors reached for asset ${assetId}`);\n }\n }\n });\n }\n);\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import { CameraKitApiHostname } from "../configuration";
|
|
1
2
|
import { FetchHandler } from "../handlers/defaultFetchHandler";
|
|
2
3
|
import { LensProto } from "./Lens";
|
|
3
|
-
export declare function retrieveCameraKitLens(httpClient: FetchHandler, lensId: string, groupId: string): Promise<LensProto>;
|
|
4
|
-
export declare function retrieveCameraKitLensGroup(httpClient: FetchHandler, groupId: string): Promise<LensProto[]>;
|
|
4
|
+
export declare function retrieveCameraKitLens(httpClient: FetchHandler, lensId: string, groupId: string, apiHostname: CameraKitApiHostname): Promise<LensProto>;
|
|
5
|
+
export declare function retrieveCameraKitLensGroup(httpClient: FetchHandler, groupId: string, apiHostname: CameraKitApiHostname): Promise<LensProto[]>;
|
package/lib/lens/lensHttpUtil.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
2
|
import { isGetGroupResponse, isLensProto } from "./Lens";
|
|
3
|
-
const
|
|
3
|
+
const relativePath = "/com.snap.camerakit.v3.Lenses";
|
|
4
4
|
function getRequestId(res) {
|
|
5
5
|
return res.headers.get("x-request-id");
|
|
6
6
|
}
|
|
7
|
-
export function retrieveCameraKitLens(httpClient, lensId, groupId) {
|
|
7
|
+
export function retrieveCameraKitLens(httpClient, lensId, groupId, apiHostname) {
|
|
8
8
|
return __awaiter(this, void 0, void 0, function* () {
|
|
9
|
-
const url =
|
|
9
|
+
const url = `https://${apiHostname}${relativePath}/groups/${groupId}/lenses/${lensId}`;
|
|
10
10
|
const response = yield httpClient(url, { credentials: "include" });
|
|
11
11
|
const body = yield response.json();
|
|
12
12
|
const lens = body.lens;
|
|
@@ -16,9 +16,9 @@ export function retrieveCameraKitLens(httpClient, lensId, groupId) {
|
|
|
16
16
|
return lens;
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
|
-
export function retrieveCameraKitLensGroup(httpClient, groupId) {
|
|
19
|
+
export function retrieveCameraKitLensGroup(httpClient, groupId, apiHostname) {
|
|
20
20
|
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
-
const url =
|
|
21
|
+
const url = `https://${apiHostname}${relativePath}/groups/${groupId}`;
|
|
22
22
|
const response = yield httpClient(url, { credentials: "include" });
|
|
23
23
|
const body = yield response.json();
|
|
24
24
|
if (!isGetGroupResponse(body)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lensHttpUtil.js","sourceRoot":"","sources":["../../src/lens/lensHttpUtil.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"lensHttpUtil.js","sourceRoot":"","sources":["../../src/lens/lensHttpUtil.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAa,M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,CAAC,GAAG,CACrD,CAAC;SACL;QACD,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;CAAA","sourcesContent":["import { CameraKitApiHostname } from \"../configuration\";\nimport { FetchHandler } from \"../handlers/defaultFetchHandler\";\nimport { isGetGroupResponse, isLensProto, LensProto } from \"./Lens\";\n\nconst relativePath = \"/com.snap.camerakit.v3.Lenses\";\n\nfunction getRequestId(res: Response) {\n return res.headers.get(\"x-request-id\");\n}\n\nexport async function retrieveCameraKitLens(\n httpClient: FetchHandler,\n lensId: string,\n groupId: string,\n apiHostname: CameraKitApiHostname\n): Promise<LensProto> {\n const url = `https://${apiHostname}${relativePath}/groups/${groupId}/lenses/${lensId}`;\n const response = await httpClient(url, { credentials: \"include\" });\n const body = await response.json();\n const lens = body.lens;\n if (!isLensProto(lens)) {\n throw new Error(\n `Expected request to ${url} to return a Lens. Got:\\n\\n${JSON.stringify(\n body\n )} with request-id of \"${getRequestId(response)}\"`\n );\n }\n return lens;\n}\n\nexport async function retrieveCameraKitLensGroup(\n httpClient: FetchHandler,\n groupId: string,\n apiHostname: CameraKitApiHostname\n): Promise<LensProto[]> {\n const url = `https://${apiHostname}${relativePath}/groups/${groupId}`;\n const response = await httpClient(url, { credentials: \"include\" });\n const body = await response.json();\n if (!isGetGroupResponse(body)) {\n throw new Error(\n `Expected request to ${url} to return a LensGroup. Got:\\n\\n${JSON.stringify(\n body\n )} with request-id of \"${getRequestId(response)}\"`\n );\n }\n return body.lenses;\n}\n"]}
|
|
@@ -7,6 +7,7 @@ export type LensCoreEnumValue = {
|
|
|
7
7
|
export type GetOutputCanvasesOutput = Record<number, HTMLCanvasElement>;
|
|
8
8
|
export type SetRenderSizeInput = SetRenderSizeMatchInputResolutionInput | SetRenderSizeExplicitInput;
|
|
9
9
|
export type SetRemoteAssetsProviderInput = (assetDescriptor: AssetDescriptor) => void;
|
|
10
|
+
export type SetRemoteAssetsUploadHandlerInput = (assetUploadDescriptor: AssetUploadDescriptor) => void;
|
|
10
11
|
export type ContentType = "text/plain" | "text/html" | "application/json" | "application/octet-stream" | "application/x-protobuf" | "application/grpc";
|
|
11
12
|
export type SavePersistentStoreCallback = (id: string, data: ArrayBuffer) => void;
|
|
12
13
|
export type ShowHintCallback = (effectId: string, hintId: string) => void;
|
|
@@ -128,6 +129,7 @@ export interface UriRequest {
|
|
|
128
129
|
method: "GET" | "POST";
|
|
129
130
|
contentType: ContentType;
|
|
130
131
|
data: ArrayBuffer;
|
|
132
|
+
metadata: Record<string, string>;
|
|
131
133
|
}
|
|
132
134
|
export interface UriResponse {
|
|
133
135
|
code: number;
|
|
@@ -172,6 +174,17 @@ export interface AssetDescriptor {
|
|
|
172
174
|
assetType: AssetType;
|
|
173
175
|
avatarId?: string;
|
|
174
176
|
effectId?: string;
|
|
177
|
+
encryptionKey?: string;
|
|
178
|
+
}
|
|
179
|
+
export interface AssetUploadDescriptor {
|
|
180
|
+
requestId: number;
|
|
181
|
+
assetId: string;
|
|
182
|
+
assetType: AssetType;
|
|
183
|
+
effectId: string;
|
|
184
|
+
assetBuffer: ArrayBuffer;
|
|
185
|
+
encryptionKey?: string;
|
|
186
|
+
encryptionIv?: string;
|
|
187
|
+
assetBatchId?: string;
|
|
175
188
|
}
|
|
176
189
|
export interface ProvideRemoteAssetsResponseInput {
|
|
177
190
|
assetId: string;
|
|
@@ -180,6 +193,12 @@ export interface ProvideRemoteAssetsResponseInput {
|
|
|
180
193
|
assetChecksum?: string;
|
|
181
194
|
onFailure?: DefaultErrorHandler;
|
|
182
195
|
}
|
|
196
|
+
export interface ProvideRemoteAssetsUploadResponseInput {
|
|
197
|
+
requestId: number;
|
|
198
|
+
success: boolean;
|
|
199
|
+
assetUrl?: string;
|
|
200
|
+
assetUploadMetadata?: ArrayBuffer;
|
|
201
|
+
}
|
|
183
202
|
export interface ProcessFrameInput {
|
|
184
203
|
inputFrame: ImageBitmap | HTMLCanvasElement | HTMLImageElement | VideoFrame;
|
|
185
204
|
timestampMillis: number;
|
|
@@ -402,6 +421,8 @@ export interface LensCoreModule extends InitialEmscriptenModule {
|
|
|
402
421
|
provideUriResponse: (requestId: string, response: UriResponse) => void;
|
|
403
422
|
setRemoteAssetsProvider: (provider: SetRemoteAssetsProviderInput) => void;
|
|
404
423
|
provideRemoteAssetsResponse: (assetResponse: ProvideRemoteAssetsResponseInput) => void;
|
|
424
|
+
setRemoteAssetsUploadHandler: (provider: SetRemoteAssetsUploadHandlerInput) => void;
|
|
425
|
+
provideRemoteAssetsUploadResponse: (assetResponse: ProvideRemoteAssetsUploadResponseInput) => void;
|
|
405
426
|
registerShowHintCallback: (callback: ShowHintCallback) => void;
|
|
406
427
|
registerHideHintCallback: (callback: HideHintCallback) => void;
|
|
407
428
|
registerSavePersistentStoreCallback: (callback: SavePersistentStoreCallback) => void;
|