@snap/camera-kit 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +5921 -1485
- package/README.md +1 -1
- package/docs/html/assets/search.js +1 -1
- package/docs/html/classes/CameraKit.html +7 -7
- package/docs/html/classes/CameraKitSession.html +17 -25
- package/docs/html/classes/CameraKitSource.html +15 -10
- package/docs/html/classes/LensPerformanceMeasurement.html +7 -7
- package/docs/html/classes/LensPerformanceMetrics.html +7 -7
- package/docs/html/classes/LensRepository.html +7 -7
- package/docs/html/classes/Transform2D.html +7 -7
- package/docs/html/classes/TypedCustomEvent.html +7 -7
- package/docs/html/classes/TypedEventTarget.html +7 -7
- package/docs/html/functions/ConcatInjectable.html +202 -0
- package/docs/html/functions/Injectable.html +15 -16
- package/docs/html/functions/bootstrapCameraKit.html +7 -7
- package/docs/html/functions/createExtension.html +7 -7
- package/docs/html/functions/createImageSource.html +7 -7
- package/docs/html/functions/createMediaStreamSource.html +7 -7
- package/docs/html/functions/createUserMediaSource.html +7 -7
- package/docs/html/functions/createVideoSource.html +7 -7
- package/docs/html/functions/estimateLensPerformance.html +7 -7
- package/docs/html/functions/getRequiredBootstrapURLs.html +7 -7
- package/docs/html/functions/lensSourcesFactory.html +17 -9
- package/docs/html/functions/remoteApiServicesFactory.html +7 -7
- package/docs/html/index.html +9 -9
- package/docs/html/interfaces/CameraKitBootstrapConfiguration.html +7 -7
- package/docs/html/interfaces/CameraKitSourceSubscriber.html +7 -7
- package/docs/html/interfaces/ComputedFrameMetrics.html +7 -7
- package/docs/html/interfaces/CreateSessionOptions.html +7 -7
- package/docs/html/interfaces/EstimatedLensPerformance.html +7 -7
- package/docs/html/interfaces/Lens.html +7 -7
- package/docs/html/interfaces/LensLaunchData.html +183 -0
- package/docs/html/interfaces/LensSource.html +28 -46
- package/docs/html/interfaces/MediaStreamSourceOptions.html +7 -7
- package/docs/html/interfaces/Preview.html +7 -7
- package/docs/html/interfaces/RemoteApiRequest.html +7 -7
- package/docs/html/interfaces/RemoteApiResponse.html +7 -7
- package/docs/html/interfaces/RemoteApiService.html +7 -7
- package/docs/html/interfaces/Snapcode.html +7 -7
- package/docs/html/interfaces/UriCancelRequest.html +7 -7
- package/docs/html/interfaces/UriRequest.html +7 -7
- package/docs/html/interfaces/UriResponse.html +7 -7
- package/docs/html/interfaces/VideoSourceOptions.html +7 -7
- package/docs/html/modules.html +12 -12
- package/docs/html/types/AssetLoader.html +7 -7
- package/docs/html/types/AssetTiming.html +7 -7
- package/docs/html/types/BenchmarkError.html +7 -7
- package/docs/html/types/BootstrapError.html +7 -7
- package/docs/html/types/CacheKeyNotFoundError.html +7 -7
- package/docs/html/types/CameraKitDeviceInfo.html +7 -7
- package/docs/html/types/CameraKitDeviceOptions.html +7 -7
- package/docs/html/types/CameraKitSessionEventListener.html +7 -7
- package/docs/html/types/CameraKitSessionEvents.html +7 -7
- package/docs/html/types/CameraKitSourceError.html +7 -7
- package/docs/html/types/CameraKitSourceInfo.html +7 -7
- package/docs/html/types/CameraKitSourceOptions.html +7 -7
- package/docs/html/types/ConfigurationError.html +7 -7
- package/docs/html/types/Keyboard.html +7 -7
- package/docs/html/types/KeyboardEvents.html +7 -7
- package/docs/html/types/LegalError.html +7 -7
- package/docs/html/types/LensAbortError.html +7 -7
- package/docs/html/types/LensAssetError.html +7 -7
- package/docs/html/types/LensContentValidationError.html +7 -7
- package/docs/html/types/LensError.html +7 -7
- package/docs/html/types/LensExecutionError.html +7 -7
- package/docs/html/types/LensImagePickerError.html +7 -7
- package/docs/html/types/LensMetricsEvents.html +7 -7
- package/docs/html/types/LensPerformanceCluster.html +7 -7
- package/docs/html/types/LensView.html +7 -7
- package/docs/html/types/LensWait.html +7 -7
- package/docs/html/types/PersistentStoreError.html +7 -7
- package/docs/html/types/PlatformNotSupportedError.html +7 -7
- package/docs/html/types/PublicContainer.html +7 -7
- package/docs/html/types/RemoteApiRequestHandler.html +7 -7
- package/docs/html/types/RemoteApiServices.html +7 -7
- package/docs/html/types/RemoteApiStatus.html +7 -7
- package/docs/html/types/RenderTarget.html +7 -7
- package/docs/html/types/Uri.html +7 -7
- package/docs/html/types/WebGLError.html +7 -7
- package/docs/html/variables/extensionRequestContext.html +7 -7
- package/docs/md/README.md +1 -1
- package/docs/md/classes/CameraKit.md +1 -1
- package/docs/md/classes/CameraKitSession.md +11 -22
- package/docs/md/classes/CameraKitSource.md +11 -5
- 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/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/LensLaunchData.md +53 -0
- package/docs/md/interfaces/LensSource.md +23 -25
- package/docs/md/interfaces/MediaStreamSourceOptions.md +1 -1
- package/docs/md/interfaces/Preview.md +1 -1
- package/docs/md/interfaces/RemoteApiRequest.md +1 -1
- package/docs/md/interfaces/RemoteApiResponse.md +1 -1
- package/docs/md/interfaces/RemoteApiService.md +1 -1
- package/docs/md/interfaces/Snapcode.md +1 -1
- package/docs/md/interfaces/UriCancelRequest.md +1 -1
- package/docs/md/interfaces/UriRequest.md +1 -1
- package/docs/md/interfaces/UriResponse.md +1 -1
- package/docs/md/interfaces/VideoSourceOptions.md +1 -1
- package/docs/md/modules.md +125 -28
- package/lib/CameraKit.d.ts +14 -6
- package/lib/__tests__/data.d.ts +2 -2
- package/lib/__tests__/data.js +2 -2
- package/lib/__tests__/data.js.map +1 -1
- package/lib/bootstrapCameraKit.js +12 -3
- package/lib/bootstrapCameraKit.js.map +1 -1
- package/lib/clients/createTsProtoClient.d.ts +47 -0
- package/lib/clients/createTsProtoClient.js +53 -0
- package/lib/clients/createTsProtoClient.js.map +1 -0
- package/lib/clients/grpcHandler.d.ts +23 -0
- package/lib/clients/grpcHandler.js +87 -0
- package/lib/clients/grpcHandler.js.map +1 -0
- package/lib/clients/lensesClient.d.ts +9 -0
- package/lib/clients/lensesClient.js +6 -0
- package/lib/clients/lensesClient.js.map +1 -0
- package/lib/common/entries.d.ts +1 -0
- package/lib/common/entries.js +2 -0
- package/lib/common/entries.js.map +1 -1
- package/lib/common/result.d.ts +36 -0
- package/lib/common/result.js +40 -0
- package/lib/common/result.js.map +1 -0
- package/lib/common/unionBy.d.ts +28 -0
- package/lib/common/unionBy.js +46 -0
- package/lib/common/unionBy.js.map +1 -0
- package/lib/configuration.js +14 -1
- package/lib/configuration.js.map +1 -1
- package/lib/dependency-injection/Injectable.d.ts +67 -11
- package/lib/dependency-injection/Injectable.js +21 -2
- package/lib/dependency-injection/Injectable.js.map +1 -1
- package/lib/dependency-injection/RootServices.d.ts +5 -1
- package/lib/dependency-injection/RootServices.js.map +1 -1
- package/lib/environment.json +1 -1
- package/lib/extensions/RemoteApiServices.d.ts +1 -1
- package/lib/extensions/RemoteApiServices.js +7 -7
- package/lib/extensions/RemoteApiServices.js.map +1 -1
- package/lib/extensions/uriHandlersRegister.d.ts +6 -6
- package/lib/extensions/uriHandlersRegister.js +1 -1
- package/lib/extensions/uriHandlersRegister.js.map +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 +15 -17
- package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.js +62 -69
- 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 +6 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/export.js +68 -0
- 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 +5 -6
- package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.js +11 -25
- 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 +19 -14
- package/lib/generated-proto/pb_schema/camera_kit/v3/lens.js +145 -64
- 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 +2 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.js +30 -0
- 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 +15 -16
- package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.js +36 -62
- 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 +1294 -12
- package/lib/generated-proto/pb_schema/camera_kit/v3/service.js +200 -0
- package/lib/generated-proto/pb_schema/camera_kit/v3/service.js.map +1 -1
- package/lib/generated-proto/pb_schema/cdp/cof/config_result.d.ts +4 -0
- package/lib/generated-proto/pb_schema/cdp/cof/config_result.js +4 -0
- package/lib/generated-proto/pb_schema/cdp/cof/config_result.js.map +1 -1
- package/lib/generated-proto/pb_schema/google/protobuf/descriptor.d.ts +39 -45
- package/lib/generated-proto/pb_schema/google/protobuf/descriptor.js +74 -192
- package/lib/generated-proto/pb_schema/google/protobuf/descriptor.js.map +1 -1
- package/lib/handlers/defaultFetchHandler.js +1 -5
- package/lib/handlers/defaultFetchHandler.js.map +1 -1
- package/lib/index.d.ts +3 -3
- package/lib/index.js +2 -6
- package/lib/index.js.map +1 -1
- package/lib/lens/Lens.d.ts +2 -12
- package/lib/lens/Lens.js +2 -2
- package/lib/lens/Lens.js.map +1 -1
- package/lib/lens/LensLaunchData.d.ts +37 -0
- package/lib/lens/LensLaunchData.js +35 -0
- package/lib/lens/LensLaunchData.js.map +1 -0
- package/lib/lens/LensRepository.d.ts +4 -7
- package/lib/lens/LensRepository.js +24 -35
- package/lib/lens/LensRepository.js.map +1 -1
- package/lib/lens/LensSource.d.ts +43 -0
- package/lib/lens/LensSource.js +42 -0
- package/lib/lens/LensSource.js.map +1 -0
- package/lib/lens/assets/LensAssetRepository.js +2 -4
- package/lib/lens/assets/LensAssetRepository.js.map +1 -1
- package/lib/lens/assets/LensAssetsProvider.d.ts +1 -1
- package/lib/lens/cameraKitLensSource.d.ts +16 -0
- package/lib/lens/cameraKitLensSource.js +59 -0
- package/lib/lens/cameraKitLensSource.js.map +1 -0
- package/lib/lens-core-module/lensCore.d.ts +2 -1
- package/lib/lens-core-module/lensCore.js +6 -1
- package/lib/lens-core-module/lensCore.js.map +1 -1
- package/lib/lens-core-module/lensCoreError.js +1 -1
- package/lib/lens-core-module/lensCoreError.js.map +1 -1
- package/lib/lensCoreWasmVersions.json +3 -3
- package/lib/media-sources/CameraKitSource.d.ts +10 -4
- package/lib/media-sources/CameraKitSource.js +11 -4
- package/lib/media-sources/CameraKitSource.js.map +1 -1
- package/lib/media-sources/ImageSource.js +1 -11
- package/lib/media-sources/ImageSource.js.map +1 -1
- package/lib/media-sources/MediaStreamSource.js +1 -5
- package/lib/media-sources/MediaStreamSource.js.map +1 -1
- package/lib/media-sources/VideoSource.js +1 -11
- package/lib/media-sources/VideoSource.js.map +1 -1
- package/lib/metrics/businessEventsReporter.js +1 -1
- package/lib/metrics/businessEventsReporter.js.map +1 -1
- package/lib/metrics/reporters/reportGlobalException.d.ts +7 -0
- package/lib/metrics/reporters/reportGlobalException.js +22 -4
- package/lib/metrics/reporters/reportGlobalException.js.map +1 -1
- package/lib/metrics/reporters/reportHttpMetrics.js +14 -0
- package/lib/metrics/reporters/reportHttpMetrics.js.map +1 -1
- package/lib/metrics/reporters/reportLensValidationFailed.d.ts +1 -1
- package/lib/metrics/reporters/reportLensView.d.ts +1 -1
- package/lib/metrics/reporters/reportLensWait.d.ts +1 -1
- package/lib/metrics/reporters/reportSessionException.d.ts +1 -1
- package/lib/metrics/reporters/reporters.d.ts +1 -1
- package/lib/persistence/ExpiringPersistence.js +3 -4
- package/lib/persistence/ExpiringPersistence.js.map +1 -1
- package/lib/platform/platformCapabilities.js +2 -1
- package/lib/platform/platformCapabilities.js.map +1 -1
- package/lib/platform/platformInfo.js +1 -1
- package/lib/platform/platformInfo.js.map +1 -1
- package/lib/remote-configuration/cofHandler.d.ts +1 -0
- package/lib/remote-configuration/cofHandler.js +61 -50
- package/lib/remote-configuration/cofHandler.js.map +1 -1
- package/lib/session/CameraKitSession.d.ts +9 -11
- package/lib/session/CameraKitSession.js +22 -18
- package/lib/session/CameraKitSession.js.map +1 -1
- package/lib/session/CameraKitSessionEvents.d.ts +1 -1
- package/lib/session/CameraKitSessionEvents.js.map +1 -1
- package/lib/session/LensKeyboard.d.ts +7 -1
- package/lib/session/lensState.d.ts +3 -3
- package/lib/session/lensState.js +40 -15
- package/lib/session/lensState.js.map +1 -1
- package/package.json +1 -1
- package/docs/html/classes/LensSources.html +0 -160
- package/docs/html/types/LensLaunchParams.html +0 -115
- package/docs/md/classes/LensSources.md +0 -29
- package/lib/common/any.d.ts +0 -19
- package/lib/common/any.js +0 -53
- package/lib/common/any.js.map +0 -1
- package/lib/extensions/LensSources.d.ts +0 -58
- package/lib/extensions/LensSources.js +0 -54
- package/lib/extensions/LensSources.js.map +0 -1
- package/lib/lens/LensLaunchParams.d.ts +0 -19
- package/lib/lens/LensLaunchParams.js +0 -40
- package/lib/lens/LensLaunchParams.js.map +0 -1
- package/lib/lens/index.d.ts +0 -7
- package/lib/lens/index.js +0 -7
- package/lib/lens/index.js.map +0 -1
- package/lib/lens/lensEnvelopeUtil.d.ts +0 -5
- package/lib/lens/lensEnvelopeUtil.js +0 -19
- package/lib/lens/lensEnvelopeUtil.js.map +0 -1
- package/lib/lens/lensHttpUtil.d.ts +0 -5
- package/lib/lens/lensHttpUtil.js +0 -52
- package/lib/lens/lensHttpUtil.js.map +0 -1
|
@@ -14,11 +14,7 @@ import { createTimeoutHandler } from "./timeoutHandler";
|
|
|
14
14
|
* @internal
|
|
15
15
|
*/
|
|
16
16
|
export const defaultFetchHandlerFactory = Injectable("defaultFetchHandler", () => {
|
|
17
|
-
return (
|
|
18
|
-
// Safety: We're re-typing fetch's second argument from `init?: RequestInit | undefined` to
|
|
19
|
-
// `init: RequestInit | void` – this is semantically equivalent, but the void makes for nicer ergonomics
|
|
20
|
-
// elsewhere (e.g. so that callers can omit the second argument instead of being forced to pass undefined).
|
|
21
|
-
new HandlerChainBuilder(fetch)
|
|
17
|
+
return (new HandlerChainBuilder(fetch)
|
|
22
18
|
.map(createDebugHandler())
|
|
23
19
|
// The 20-second per-request timeout is pretty arbitrary, it's just set to be longer than our API gateway
|
|
24
20
|
// timeout (15s) and lower than the browsers own timeout (variable, Chrome's is 5m).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaultFetchHandler.js","sourceRoot":"","sources":["../../src/handlers/defaultFetchHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,gCAAgC,EAAE,MAAM,8BAA8B,CAAC;AAChF,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAIxD;;;;;;;;GAQG;AAEH,MAAM,CAAC,MAAM,0BAA0B,GAAG,UAAU,CAAC,qBAAqB,EAAE,GAAG,EAAE;IAC7E,OAAO
|
|
1
|
+
{"version":3,"file":"defaultFetchHandler.js","sourceRoot":"","sources":["../../src/handlers/defaultFetchHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,gCAAgC,EAAE,MAAM,8BAA8B,CAAC;AAChF,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAIxD;;;;;;;;GAQG;AAEH,MAAM,CAAC,MAAM,0BAA0B,GAAG,UAAU,CAAC,qBAAqB,EAAE,GAAG,EAAE;IAC7E,OAAO,CACH,IAAI,mBAAmB,CAAC,KAAK,CAAC;SACzB,GAAG,CAAC,kBAAkB,EAAE,CAAC;QAC1B,yGAAyG;QACzG,oFAAoF;SACnF,GAAG,CAAC,oBAAoB,CAAC,EAAE,OAAO,EAAE,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;SACjD,GAAG,CAAC,gCAAgC,EAAE,CAAC;SACvC,GAAG,CACA,qBAAqB,CAAC;QAClB,UAAU,EAAE,CAAC;QACb,cAAc,EAAE,CAAC,eAAe,EAAE,EAAE;YAChC,0FAA0F;YAC1F,qDAAqD;YACrD,IAAI,eAAe,YAAY,QAAQ,EAAE;gBACrC,IAAI,eAAe,CAAC,EAAE;oBAAE,OAAO,KAAK,CAAC;gBACrC,IAAI,eAAe,CAAC,MAAM,GAAG,GAAG,GAAG,GAAG;oBAAE,OAAO,KAAK,CAAC;aACxD;YACD,OAAO,IAAI,CAAC;QAChB,CAAC;KACJ,CAAC,CACL,CAAC,OAAO,CAChB,CAAC;AACN,CAAC,CAAC,CAAC","sourcesContent":["import { Injectable } from \"../dependency-injection/Injectable\";\nimport { createDebugHandler } from \"./debugHandler\";\nimport { HandlerChainBuilder } from \"./HandlerChainBuilder\";\nimport { createNoCorsRetryingFetchHandler } from \"./noCorsRetryingFetchHandler\";\nimport { createRetryingHandler } from \"./retryingHandler\";\nimport { createTimeoutHandler } from \"./timeoutHandler\";\n\nexport type FetchHandler<R = Response> = (input: RequestInfo, init?: RequestInit) => Promise<R>;\n\n/**\n * The default Fetch implementation, used to make a simple HTTP requests without any custom headers. This can be passed\n * to `HandlerChainBuilder` to form the basis for other Fetch implementations (e.g. with custom headers, which extract\n * the Response body, etc.)\n *\n * Has support for retries, client-side timeout, and navigating federated auth flows that may not support CORs requests.\n *\n * @internal\n */\n\nexport const defaultFetchHandlerFactory = Injectable(\"defaultFetchHandler\", () => {\n return (\n new HandlerChainBuilder(fetch)\n .map(createDebugHandler())\n // The 20-second per-request timeout is pretty arbitrary, it's just set to be longer than our API gateway\n // timeout (15s) and lower than the browsers own timeout (variable, Chrome's is 5m).\n .map(createTimeoutHandler({ timeout: 20 * 1000 }))\n .map(createNoCorsRetryingFetchHandler())\n .map(\n createRetryingHandler({\n maxRetries: 3,\n retryPredicate: (responseOrError) => {\n // Don't retry successful Responses or Responses with a 4xx HTTP status code (indicating a\n // client error). Do retry all 5xx HTTP status codes.\n if (responseOrError instanceof Response) {\n if (responseOrError.ok) return false;\n if (responseOrError.status % 400 < 100) return false;\n }\n return true;\n },\n })\n ).handler\n );\n});\n"]}
|
package/lib/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { getRequiredBootstrapURLs } from "./lens-core-module/loader/lensCoreFact
|
|
|
4
4
|
export { estimateLensPerformance, EstimatedLensPerformance, LensPerformanceCluster, } from "./benchmark/estimateLensPerformanceCluster";
|
|
5
5
|
export * from "./bootstrapCameraKit";
|
|
6
6
|
export { extensionRequestContext } from "./extensions/extensionRequestContext";
|
|
7
|
-
export { LensSource,
|
|
7
|
+
export { LensSource, lensSourcesFactory } from "./lens/LensSource";
|
|
8
8
|
export { Uri, UriRequest, UriResponse, UriCancelRequest, UriHandler, UriHandlers, uriHandlersFactory, } from "./extensions/UriHandlers";
|
|
9
9
|
export { RemoteApiStatus, RemoteApiRequest, RemoteApiRequestHandler, RemoteApiResponse, RemoteApiService, RemoteApiServices, remoteApiServicesFactory, } from "./extensions/RemoteApiServices";
|
|
10
10
|
export { CameraKit, CreateSessionOptions, LensMetricsEvents } from "./CameraKit";
|
|
@@ -14,7 +14,7 @@ export { getCameraKitUserAgent } from "./platform/cameraKitUserAgent";
|
|
|
14
14
|
export { getPlatformInfo, PlatformInfo } from "./platform/platformInfo";
|
|
15
15
|
export { Lens, toPublicLens, Snapcode, Preview } from "./lens/Lens";
|
|
16
16
|
export { AssetTiming, LensRepository } from "./lens/LensRepository";
|
|
17
|
-
export {
|
|
17
|
+
export { LensLaunchData } from "./lens/LensLaunchData";
|
|
18
18
|
export { AssetLoader } from "./lens/assets/LensAssetRepository";
|
|
19
19
|
export { remoteMediaAssetLoaderFactory } from "./lens/assets/remoteMediaAssetLoaderFactory";
|
|
20
20
|
export * from "./media-sources/CameraKitSource";
|
|
@@ -24,7 +24,7 @@ export * from "./media-sources/VideoSource";
|
|
|
24
24
|
export * from "./media-sources/ImageSource";
|
|
25
25
|
export * from "./session/CameraKitSession";
|
|
26
26
|
export { CameraKitSessionEvents, CameraKitSessionEventListener } from "./session/CameraKitSessionEvents";
|
|
27
|
-
export { Injectable } from "./dependency-injection/Injectable";
|
|
27
|
+
export { Injectable, ConcatInjectable } from "./dependency-injection/Injectable";
|
|
28
28
|
export { PartialContainer } from "./dependency-injection/PartialContainer";
|
|
29
29
|
export * from "./transforms";
|
|
30
30
|
export * from "./namedErrors";
|
package/lib/index.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import environment from "./environment.json";
|
|
2
|
-
import lensCoreWasm from "./lensCoreWasmVersions.json";
|
|
3
|
-
console.info(`SDK: ${environment.PACKAGE_VERSION} \
|
|
4
|
-
(${lensCoreWasm.version}/${lensCoreWasm.buildNumber})`);
|
|
5
1
|
export { configurationToken } from "./configuration";
|
|
6
2
|
export { getRequiredBootstrapURLs } from "./lens-core-module/loader/lensCoreFactory";
|
|
7
3
|
export { estimateLensPerformance, } from "./benchmark/estimateLensPerformanceCluster";
|
|
8
4
|
export * from "./bootstrapCameraKit";
|
|
9
5
|
export { extensionRequestContext } from "./extensions/extensionRequestContext";
|
|
10
|
-
export {
|
|
6
|
+
export { lensSourcesFactory } from "./lens/LensSource";
|
|
11
7
|
export { uriHandlersFactory, } from "./extensions/UriHandlers";
|
|
12
8
|
export { remoteApiServicesFactory, } from "./extensions/RemoteApiServices";
|
|
13
9
|
export { CameraKit } from "./CameraKit";
|
|
@@ -22,7 +18,7 @@ export * from "./media-sources/FunctionSource";
|
|
|
22
18
|
export * from "./media-sources/VideoSource";
|
|
23
19
|
export * from "./media-sources/ImageSource";
|
|
24
20
|
export * from "./session/CameraKitSession";
|
|
25
|
-
export { Injectable } from "./dependency-injection/Injectable";
|
|
21
|
+
export { Injectable, ConcatInjectable } from "./dependency-injection/Injectable";
|
|
26
22
|
export { PartialContainer } from "./dependency-injection/PartialContainer";
|
|
27
23
|
export * from "./transforms";
|
|
28
24
|
export * from "./namedErrors";
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAA2D,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAC9G,OAAO,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAC;AACrF,OAAO,EACH,uBAAuB,GAG1B,MAAM,4CAA4C,CAAC;AACpD,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AAC/E,OAAO,EAAc,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAOH,kBAAkB,GACrB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAOH,wBAAwB,GAC3B,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,SAAS,EAA2C,MAAM,aAAa,CAAC;AAGjF,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,eAAe,EAAgB,MAAM,yBAAyB,CAAC;AACxE,OAAO,EAAQ,YAAY,EAAqB,MAAM,aAAa,CAAC;AACpE,OAAO,EAAe,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAGpE,OAAO,EAAE,6BAA6B,EAAE,MAAM,6CAA6C,CAAC;AAC5F,cAAc,iCAAiC,CAAC;AAChD,cAAc,mCAAmC,CAAC;AAClD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAE3C,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAC3E,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,0BAA0B,EAAwB,MAAM,sCAAsC,CAAC;AACxG,OAAO,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,GAAG,EAAE,MAAM,iDAAiD,CAAC","sourcesContent":["export { Keyboard, KeyboardEvents } from \"./session/LensKeyboard\";\nexport { CameraKitConfiguration, CameraKitBootstrapConfiguration, configurationToken } from \"./configuration\";\nexport { getRequiredBootstrapURLs } from \"./lens-core-module/loader/lensCoreFactory\";\nexport {\n estimateLensPerformance,\n EstimatedLensPerformance,\n LensPerformanceCluster,\n} from \"./benchmark/estimateLensPerformanceCluster\";\nexport * from \"./bootstrapCameraKit\";\nexport { extensionRequestContext } from \"./extensions/extensionRequestContext\";\nexport { LensSource, lensSourcesFactory } from \"./lens/LensSource\";\nexport {\n Uri,\n UriRequest,\n UriResponse,\n UriCancelRequest,\n UriHandler,\n UriHandlers,\n uriHandlersFactory,\n} from \"./extensions/UriHandlers\";\nexport {\n RemoteApiStatus,\n RemoteApiRequest,\n RemoteApiRequestHandler,\n RemoteApiResponse,\n RemoteApiService,\n RemoteApiServices,\n remoteApiServicesFactory,\n} from \"./extensions/RemoteApiServices\";\nexport { CameraKit, CreateSessionOptions, LensMetricsEvents } from \"./CameraKit\";\nexport { LensView } from \"./metrics/reporters/reportLensView\";\nexport { LensWait } from \"./metrics/reporters/reportLensWait\";\nexport { getCameraKitUserAgent } from \"./platform/cameraKitUserAgent\";\nexport { getPlatformInfo, PlatformInfo } from \"./platform/platformInfo\";\nexport { Lens, toPublicLens, Snapcode, Preview } from \"./lens/Lens\";\nexport { AssetTiming, LensRepository } from \"./lens/LensRepository\";\nexport { LensLaunchData } from \"./lens/LensLaunchData\";\nexport { AssetLoader } from \"./lens/assets/LensAssetRepository\";\nexport { remoteMediaAssetLoaderFactory } from \"./lens/assets/remoteMediaAssetLoaderFactory\";\nexport * from \"./media-sources/CameraKitSource\";\nexport * from \"./media-sources/MediaStreamSource\";\nexport * from \"./media-sources/FunctionSource\";\nexport * from \"./media-sources/VideoSource\";\nexport * from \"./media-sources/ImageSource\";\nexport * from \"./session/CameraKitSession\";\nexport { CameraKitSessionEvents, CameraKitSessionEventListener } from \"./session/CameraKitSessionEvents\";\nexport { Injectable, ConcatInjectable } from \"./dependency-injection/Injectable\";\nexport { PartialContainer } from \"./dependency-injection/PartialContainer\";\nexport * from \"./transforms\";\nexport * from \"./namedErrors\";\nexport { LensPerformanceMeasurement, ComputedFrameMetrics } from \"./session/LensPerformanceMeasurement\";\nexport { LensPerformanceMetrics } from \"./session/LensPerformanceMetrics\";\nexport { TypedCustomEvent } from \"./events/TypedCustomEvent\";\nexport { TypedEventTarget } from \"./events/TypedEventTarget\";\nexport { namedError } from \"./namedErrors\";\nexport { Any } from \"./generated-proto/pb_schema/google/protobuf/any\";\n"]}
|
package/lib/lens/Lens.d.ts
CHANGED
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
import { Content, Lens_CameraFacing, Lens as
|
|
1
|
+
import { Content, Lens_CameraFacing, Lens as LensProto, LensCreator } from "../generated-proto/pb_schema/camera_kit/v3/lens";
|
|
2
2
|
import { GetGroupResponse } from "../generated-proto/pb_schema/camera_kit/v3/service";
|
|
3
3
|
import { Any } from "../generated-proto/pb_schema/google/protobuf/any";
|
|
4
4
|
export interface LensProtoWithGroupId extends LensProto {
|
|
5
5
|
groupId: string;
|
|
6
6
|
}
|
|
7
|
-
/**
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
10
|
-
export type ContentProto = Omit<Content, "lnsUrl" | "iconUrl">;
|
|
11
|
-
/**
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
export interface LensProto extends Omit<LensGeneratedProto, "content"> {
|
|
15
|
-
content: ContentProto | undefined;
|
|
16
|
-
}
|
|
17
7
|
/**
|
|
18
8
|
* @category Lenses
|
|
19
9
|
*/
|
|
@@ -101,7 +91,7 @@ export declare function isLensProto(value: unknown): value is LensProto;
|
|
|
101
91
|
export declare function isPreview(value: unknown): value is Preview;
|
|
102
92
|
export declare function isLensCreator(value: unknown): value is LensCreator;
|
|
103
93
|
export declare function isSnapcode(value: unknown): value is Snapcode;
|
|
104
|
-
export declare function isLensContent(value: unknown): value is
|
|
94
|
+
export declare function isLensContent(value: unknown): value is Omit<Content, "lnsUrl" | "iconUrl">;
|
|
105
95
|
export declare function isGetGroupResponse(value: unknown): value is GetGroupResponse;
|
|
106
96
|
export declare function isAny(value: unknown): value is Any;
|
|
107
97
|
export declare function isAnyArray(value: unknown): value is Any[];
|
package/lib/lens/Lens.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { assert } from "../common/assertions";
|
|
2
|
-
import { predicateRecordValues, isRecord, isString, isUndefined, isEmptyOrSafeUrl, isArrayOfType, isTypedArray, } from "../common/typeguards";
|
|
2
|
+
import { predicateRecordValues, isRecord, isString, isUndefined, isEmptyOrSafeUrl, isArrayOfType, isTypedArray, isNumber, } from "../common/typeguards";
|
|
3
3
|
export function isLensArray(value) {
|
|
4
4
|
return isArrayOfType(isLens, value);
|
|
5
5
|
}
|
|
@@ -10,7 +10,7 @@ export function isLens(value) {
|
|
|
10
10
|
(isUndefined(value.iconUrl) || isString(value.iconUrl)) &&
|
|
11
11
|
isRecord(value.vendorData) &&
|
|
12
12
|
predicateRecordValues(isString)(value.vendorData) &&
|
|
13
|
-
|
|
13
|
+
isNumber(value.cameraFacingPreference) &&
|
|
14
14
|
(isUndefined(value.preview) || isPreview(value.preview)) &&
|
|
15
15
|
(isUndefined(value.lensCreator) || isLensCreator(value.lensCreator)) &&
|
|
16
16
|
(isUndefined(value.snapcode) || isSnapcode(value.snapcode)) &&
|
package/lib/lens/Lens.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Lens.js","sourceRoot":"","sources":["../../src/lens/Lens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EACH,qBAAqB,EACrB,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,gBAAgB,EAChB,aAAa,EACb,YAAY,
|
|
1
|
+
{"version":3,"file":"Lens.js","sourceRoot":"","sources":["../../src/lens/Lens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EACH,qBAAqB,EACrB,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,QAAQ,GACX,MAAM,sBAAsB,CAAC;AA4G9B,MAAM,UAAU,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AAU,CAAC,KAAc;IACrC,OAAO,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AACvC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,EACzB,EAAE,EACF,OAAO,EACP,IAAI,EACJ,OAAO,EACP,UAAU,EACV,sBAAsB,EACtB,WAAW,EACX,SAAS,EACT,eAAe,GACI;;IACnB,MAAM,CAAC,gBAAgB,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,CAAC,EAAE,iBAAiB,CAAC,CAAC;IAClE,MAAM,CAAC,gBAAgB,CAAC,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,0CAAE,QAAQ,CAAC,EAAE,oBAAoB,CAAC,CAAC;IAC3E,OAAO;QACH,EAAE;QACF,OAAO;QACP,IAAI;QACJ,OAAO,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW;QAC7B,OAAO,EAAE,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,EAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,SAAS;QAC9E,UAAU;QACV,sBAAsB;QACtB,WAAW;QACX,QAAQ,EAAE,SAAS;YACf,CAAC,CAAC,EAAE,QAAQ,EAAE,SAAS,CAAC,gBAAgB,EAAE,QAAQ,EAAE,SAAS,CAAC,gBAAgB,EAAE;YAChF,CAAC,CAAC,SAAS;QACf,eAAe;KAClB,CAAC;AACN,CAAC","sourcesContent":["import { assert } from \"../common/assertions\";\nimport {\n predicateRecordValues,\n isRecord,\n isString,\n isUndefined,\n isEmptyOrSafeUrl,\n isArrayOfType,\n isTypedArray,\n isNumber,\n} from \"../common/typeguards\";\nimport {\n Content,\n Lens_CameraFacing,\n Lens as LensProto,\n LensCreator,\n} from \"../generated-proto/pb_schema/camera_kit/v3/lens\";\nimport { GetGroupResponse } from \"../generated-proto/pb_schema/camera_kit/v3/service\";\nimport { Any } from \"../generated-proto/pb_schema/google/protobuf/any\";\n\nexport interface LensProtoWithGroupId extends LensProto {\n groupId: string;\n}\n\n/**\n * @category Lenses\n */\nexport interface Lens {\n /**\n * Non-empty identifier of a unique lens available to be applied in current session.\n *\n * NOTE: This value may contain unsafe characters\n * and therefore may require additional processing depending on usages.\n */\n id: string;\n\n /**\n * The unique identifier for the group that this lens is a part of,\n * correlating to a collection of lenses grouped for organizational or functional purposes.\n */\n groupId: string;\n\n /**\n * Human readable name of this lens.\n *\n * NOTE: This value may contain unsafe characters\n * and therefore may require additional processing depending on usages.\n */\n name: string;\n\n /**\n * Icon resource URI that represents this lens if available.\n */\n iconUrl: string | undefined;\n\n /**\n * Vendor specific metadata associated with this lens, empty by default.\n *\n * NOTE: Metadata values may contain unsafe characters\n * and therefore may require additional processing depending on usages.\n */\n vendorData: { [key: string]: string };\n\n /**\n * Specifies a [Lens_CameraFacing] that this lens is designed for.\n */\n cameraFacingPreference: Lens_CameraFacing;\n\n /**\n * Preview representing this lens, if available.\n */\n preview: Preview | undefined;\n\n /**\n * Information about the lens creator.\n */\n lensCreator: LensCreator | undefined;\n\n /**\n * A [snapcode](https://scan.snapchat.com/snapcodes) that represents the lens if available.\n *\n * The snapcode points to the lens in the Snapchat app, when used on mobile, or a dedicated web page.\n */\n snapcode: Snapcode | undefined;\n\n /**\n * Metadata pertaining to a specific set of lens features\n */\n featureMetadata: Any[];\n}\n\n/**\n * Lens preview.\n */\n// That corresponds to Preview interface in packages/web-sdk/src/generated-proto/pb_schema/camera_kit/v3/lens.ts\nexport interface Preview {\n /**\n * Link to a lens preview image.\n */\n imageUrl: string;\n}\n\n/**\n * [Snapcode](https://scan.snapchat.com/snapcodes) representing a lens.\n */\n// That corresponds to Scannable interface in packages/web-sdk/src/generated-proto/pb_schema/camera_kit/v3/lens.ts\nexport interface Snapcode {\n /**\n * Snapcode image URL scannable with Snapchat app.\n */\n imageUrl: string;\n\n /**\n * Deeplink URL that directs to a lens web page.\n */\n deepLink: string;\n}\n\nexport function isLensArray(value: unknown): value is Lens[] {\n return isArrayOfType(isLens, value);\n}\n\nexport function isLens(value: unknown): value is Lens {\n return (\n isRecord(value) &&\n isString(value.id) &&\n isString(value.name) &&\n (isUndefined(value.iconUrl) || isString(value.iconUrl)) &&\n isRecord(value.vendorData) &&\n predicateRecordValues(isString)(value.vendorData) &&\n isNumber(value.cameraFacingPreference) &&\n (isUndefined(value.preview) || isPreview(value.preview)) &&\n (isUndefined(value.lensCreator) || isLensCreator(value.lensCreator)) &&\n (isUndefined(value.snapcode) || isSnapcode(value.snapcode)) &&\n isAnyArray(value.featureMetadata)\n );\n}\n\nexport function isLensProto(value: unknown): value is LensProto {\n return (\n isRecord(value) &&\n isString(value.id) &&\n isString(value.name) &&\n isRecord(value.vendorData) &&\n predicateRecordValues(isString)(value.vendorData) &&\n (typeof value.content === \"undefined\" || isLensContent(value.content))\n );\n}\n\nexport function isPreview(value: unknown): value is Preview {\n return isRecord(value) && isString(value.imageUrl);\n}\n\nexport function isLensCreator(value: unknown): value is LensCreator {\n return isRecord(value) && isString(value.displayName);\n}\n\nexport function isSnapcode(value: unknown): value is Snapcode {\n return isRecord(value) && isString(value.imageUrl) && isString(value.deepLink);\n}\n\nexport function isLensContent(value: unknown): value is Omit<Content, \"lnsUrl\" | \"iconUrl\"> {\n return (\n isRecord(value) &&\n isString(value.iconUrlBolt) &&\n isString(value.lnsSha256) &&\n isString(value.lnsUrlBolt) &&\n isRecord(value.preview) &&\n isString(value.preview.imageUrl)\n );\n}\n\nexport function isGetGroupResponse(value: unknown): value is GetGroupResponse {\n return isRecord(value) && isString(value.id) && Array.isArray(value.lenses) && value.lenses.every(isLensProto);\n}\n\nexport function isAny(value: unknown): value is Any {\n return isRecord(value) && isString(value.typeUrl) && isTypedArray(value.value);\n}\n\nexport function isAnyArray(value: unknown): value is Any[] {\n return isArrayOfType(isAny, value);\n}\n\n/**\n * Converts lens proto to a public lens object.\n * @param lens Lens proto\n * @returns Public lens object.\n *\n * @internal\n */\nexport function toPublicLens({\n id,\n groupId,\n name,\n content,\n vendorData,\n cameraFacingPreference,\n lensCreator,\n scannable,\n featureMetadata,\n}: LensProtoWithGroupId): Lens {\n assert(isEmptyOrSafeUrl(content?.iconUrlBolt), \"Unsafe icon URL\");\n assert(isEmptyOrSafeUrl(content?.preview?.imageUrl), \"Unsafe preview URL\");\n return {\n id,\n groupId,\n name,\n iconUrl: content?.iconUrlBolt,\n preview: content?.preview ? { imageUrl: content.preview.imageUrl } : undefined,\n vendorData,\n cameraFacingPreference,\n lensCreator,\n snapcode: scannable\n ? { imageUrl: scannable.snapcodeImageUrl, deepLink: scannable.snapcodeDeeplink }\n : undefined,\n featureMetadata,\n };\n}\n"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { UserData_Zodiac } from "../generated-proto/pb_schema/lenses/user_data";
|
|
2
|
+
type LensLaunchParams = Record<string, string | number | string[] | number[]>;
|
|
3
|
+
/**
|
|
4
|
+
* Some Lenses may accept (or require) certain data provided to them when the Lens is applied.
|
|
5
|
+
*
|
|
6
|
+
* This data may include things like user info (to render the user's name, for example, or perform some task based on
|
|
7
|
+
* their birth date), or arbitrary `launchParams` defined by the Lens.
|
|
8
|
+
*
|
|
9
|
+
* @category Lenses
|
|
10
|
+
*/
|
|
11
|
+
export interface LensLaunchData {
|
|
12
|
+
userId?: string;
|
|
13
|
+
userData?: {
|
|
14
|
+
userId: string;
|
|
15
|
+
username: string;
|
|
16
|
+
birthdate: string;
|
|
17
|
+
displayName: string;
|
|
18
|
+
countrycode: string;
|
|
19
|
+
score: number;
|
|
20
|
+
bitmojiInfo?: {
|
|
21
|
+
avatarId: string;
|
|
22
|
+
selfieId: string;
|
|
23
|
+
};
|
|
24
|
+
friendInfo?: {
|
|
25
|
+
friendshipStart?: Date;
|
|
26
|
+
lastInteraction?: Date;
|
|
27
|
+
streak: number;
|
|
28
|
+
};
|
|
29
|
+
zodiac: UserData_Zodiac;
|
|
30
|
+
};
|
|
31
|
+
launchParams?: LensLaunchParams;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
export declare const encodeLensLaunchData: (launchData: LensLaunchData, persistentStore: ArrayBuffer) => Uint8Array;
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { LaunchData } from "../generated-proto/pb_schema/lenses/launchdata";
|
|
2
|
+
import { isNumber, isRecord, isString } from "../common/typeguards";
|
|
3
|
+
const isValidNumber = (value) => {
|
|
4
|
+
return isNumber(value) && !Number.isNaN(value) && Number.isFinite(value);
|
|
5
|
+
};
|
|
6
|
+
const isValidLaunchParam = (value) => {
|
|
7
|
+
if (Array.isArray(value))
|
|
8
|
+
return value.every(isString) || value.every(isValidNumber);
|
|
9
|
+
return isString(value) || isValidNumber(value);
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export const encodeLensLaunchData = (launchData, persistentStore) => {
|
|
15
|
+
// finish() protobufjs method returns UInt8Array with shared ArrayBuffer
|
|
16
|
+
// to avoid of detached buffer error when passing data to Lens Core
|
|
17
|
+
// data should be copied using slice() method
|
|
18
|
+
return LaunchData.encode(LaunchData.fromPartial(Object.assign(Object.assign({}, launchData), { launchParams: launchData.launchParams ? encodeLensLaunchParams(launchData.launchParams) : undefined, persistentStore: { store: new Uint8Array(persistentStore) } })))
|
|
19
|
+
.finish()
|
|
20
|
+
.slice();
|
|
21
|
+
};
|
|
22
|
+
function encodeLensLaunchParams(launchParams) {
|
|
23
|
+
const newError = (message) => new Error(`Failed to encode lens launchParams. ${message}`);
|
|
24
|
+
if (!isRecord(launchParams) || launchParams instanceof Date) {
|
|
25
|
+
throw newError(`Expected a plain object, got ${typeof launchParams} instead.`);
|
|
26
|
+
}
|
|
27
|
+
for (const [key, value] of Object.entries(launchParams)) {
|
|
28
|
+
if (!isValidLaunchParam(value)) {
|
|
29
|
+
throw newError(`Values must be strings, numbers, or arrays of strings or numbers. Field ${key} is ` +
|
|
30
|
+
`a ${typeof value} instead, with value: ${JSON.stringify(value)}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return { data: new TextEncoder().encode(JSON.stringify(launchParams)) };
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=LensLaunchData.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LensLaunchData.js","sourceRoot":"","sources":["../../src/lens/LensLaunchData.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gDAAgD,CAAC;AAC5E,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAIpE,MAAM,aAAa,GAAG,CAAC,KAAc,EAAmB,EAAE;IACtD,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC7E,CAAC,CAAC;AACF,MAAM,kBAAkB,GAAG,CAAC,KAAc,EAAW,EAAE;IACnD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IACrF,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,aAAa,CAAC,KAAK,CAAC,CAAC;AACnD,CAAC,CAAC;AAmCF;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,UAA0B,EAAE,eAA4B,EAAc,EAAE;IACzG,wEAAwE;IACxE,mEAAmE;IACnE,6CAA6C;IAC7C,OAAO,UAAU,CAAC,MAAM,CACpB,UAAU,CAAC,WAAW,iCACf,UAAU,KACb,YAAY,EAAE,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,sBAAsB,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,SAAS,EACnG,eAAe,EAAE,EAAE,KAAK,EAAE,IAAI,UAAU,CAAC,eAAe,CAAC,EAAE,IAC7D,CACL;SACI,MAAM,EAAE;SACR,KAAK,EAAE,CAAC;AACjB,CAAC,CAAC;AAEF,SAAS,sBAAsB,CAAC,YAA+B;IAC3D,MAAM,QAAQ,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,uCAAuC,OAAO,EAAE,CAAC,CAAC;IAElG,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,YAAY,YAAY,IAAI,EAAE;QACzD,MAAM,QAAQ,CAAC,gCAAgC,OAAO,YAAY,WAAW,CAAC,CAAC;KAClF;IAED,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE;QACrD,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,EAAE;YAC5B,MAAM,QAAQ,CACV,2EAA2E,GAAG,MAAM;gBAChF,KAAK,OAAO,KAAK,yBAAyB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CACxE,CAAC;SACL;KACJ;IAED,OAAO,EAAE,IAAI,EAAE,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC;AAC5E,CAAC","sourcesContent":["import { LaunchData } from \"../generated-proto/pb_schema/lenses/launchdata\";\nimport { isNumber, isRecord, isString } from \"../common/typeguards\";\nimport { LaunchParams } from \"../generated-proto/pb_schema/lenses/launch_params\";\nimport { UserData_Zodiac } from \"../generated-proto/pb_schema/lenses/user_data\";\n\nconst isValidNumber = (value: unknown): value is number => {\n return isNumber(value) && !Number.isNaN(value) && Number.isFinite(value);\n};\nconst isValidLaunchParam = (value: unknown): boolean => {\n if (Array.isArray(value)) return value.every(isString) || value.every(isValidNumber);\n return isString(value) || isValidNumber(value);\n};\n\ntype LensLaunchParams = Record<string, string | number | string[] | number[]>;\n\n/**\n * Some Lenses may accept (or require) certain data provided to them when the Lens is applied.\n *\n * This data may include things like user info (to render the user's name, for example, or perform some task based on\n * their birth date), or arbitrary `launchParams` defined by the Lens.\n *\n * @category Lenses\n */\nexport interface LensLaunchData {\n userId?: string;\n userData?: {\n userId: string;\n username: string;\n birthdate: string;\n displayName: string;\n countrycode: string;\n score: number;\n bitmojiInfo?: {\n avatarId: string;\n selfieId: string;\n };\n friendInfo?: {\n friendshipStart?: Date;\n lastInteraction?: Date;\n streak: number;\n };\n zodiac: UserData_Zodiac;\n };\n launchParams?: LensLaunchParams;\n}\n\n/**\n * @internal\n */\nexport const encodeLensLaunchData = (launchData: LensLaunchData, persistentStore: ArrayBuffer): Uint8Array => {\n // finish() protobufjs method returns UInt8Array with shared ArrayBuffer\n // to avoid of detached buffer error when passing data to Lens Core\n // data should be copied using slice() method\n return LaunchData.encode(\n LaunchData.fromPartial({\n ...launchData,\n launchParams: launchData.launchParams ? encodeLensLaunchParams(launchData.launchParams) : undefined,\n persistentStore: { store: new Uint8Array(persistentStore) },\n })\n )\n .finish()\n .slice();\n};\n\nfunction encodeLensLaunchParams(launchParams?: LensLaunchParams): LaunchParams {\n const newError = (message: string) => new Error(`Failed to encode lens launchParams. ${message}`);\n\n if (!isRecord(launchParams) || launchParams instanceof Date) {\n throw newError(`Expected a plain object, got ${typeof launchParams} instead.`);\n }\n\n for (const [key, value] of Object.entries(launchParams)) {\n if (!isValidLaunchParam(value)) {\n throw newError(\n `Values must be strings, numbers, or arrays of strings or numbers. Field ${key} is ` +\n `a ${typeof value} instead, with value: ${JSON.stringify(value)}`\n );\n }\n }\n\n return { data: new TextEncoder().encode(JSON.stringify(launchParams)) };\n}\n"]}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { FetchHandler } from "../handlers/defaultFetchHandler";
|
|
2
|
-
import { LensSources } from "../extensions/LensSources";
|
|
3
2
|
import { RequestStateEventTarget } from "../handlers/requestStateEmittingHandler";
|
|
4
3
|
import { LensDownloadDimensions } from "../metrics/reporters/reportLensAndAssetDownload";
|
|
5
4
|
import { Handler } from "../handlers/HandlerChainBuilder";
|
|
6
5
|
import { LensAssetManifestItem_RequestTiming } from "../generated-proto/pb_schema/camera_kit/v3/lens";
|
|
7
|
-
import { CameraKitApiHostname, CameraKitConfiguration } from "../configuration";
|
|
8
6
|
import { Lens, LensProtoWithGroupId } from "./Lens";
|
|
9
7
|
import { LensAssetRepository } from "./assets/LensAssetRepository";
|
|
8
|
+
import { LensSource } from "./LensSource";
|
|
10
9
|
type LensFetchHandler = Handler<[
|
|
11
10
|
RequestInfo,
|
|
12
11
|
LensDownloadDimensions
|
|
@@ -53,15 +52,13 @@ export interface LensBinary {
|
|
|
53
52
|
* @category Lenses
|
|
54
53
|
*/
|
|
55
54
|
export declare class LensRepository {
|
|
56
|
-
private readonly lensMetadataFetchHandler;
|
|
57
55
|
private readonly lensFetchHandler;
|
|
58
56
|
private readonly lensSources;
|
|
59
57
|
private readonly lensAssetRepository;
|
|
60
|
-
private readonly apiHostname;
|
|
61
58
|
private readonly metadataCache;
|
|
62
59
|
private readonly binariesCache;
|
|
63
60
|
/** @internal */
|
|
64
|
-
constructor(
|
|
61
|
+
constructor(lensFetchHandler: LensFetchHandler, lensSources: LensSource[], lensAssetRepository: LensAssetRepository);
|
|
65
62
|
/**
|
|
66
63
|
* Retrieve a single Lens.
|
|
67
64
|
*
|
|
@@ -129,8 +126,8 @@ export declare class LensRepository {
|
|
|
129
126
|
* @internal
|
|
130
127
|
*/
|
|
131
128
|
export declare const lensRepositoryFactory: {
|
|
132
|
-
(args_0: RequestStateEventTarget, args_1: FetchHandler, args_2:
|
|
129
|
+
(args_0: RequestStateEventTarget, args_1: FetchHandler, args_2: LensSource[], args_3: LensAssetRepository): LensRepository;
|
|
133
130
|
token: "LensRepository";
|
|
134
|
-
dependencies: readonly ["requestStateEventTarget", "
|
|
131
|
+
dependencies: readonly ["requestStateEventTarget", "defaultFetchHandler", "lensSources", "lensAssetRepository"];
|
|
135
132
|
};
|
|
136
133
|
export {};
|
|
@@ -2,20 +2,17 @@ import { __awaiter, __decorate, __metadata, __param } from "tslib";
|
|
|
2
2
|
import { guard, validate } from "../common/validate";
|
|
3
3
|
import { isArrayOfType, isSafeString, isSafeStringArray, isString, isUndefined } from "../common/typeguards";
|
|
4
4
|
import { Injectable } from "../dependency-injection/Injectable";
|
|
5
|
-
import { cameraKitServiceFetchHandlerFactory } from "../handlers/cameraKitServiceFetchHandlerFactory";
|
|
6
5
|
import { defaultFetchHandlerFactory } from "../handlers/defaultFetchHandler";
|
|
7
|
-
import { lensSourcesFactory } from "../extensions/LensSources";
|
|
8
6
|
import { createRequestStateEmittingHandler, requestStateEventTargetFactory, } from "../handlers/requestStateEmittingHandler";
|
|
9
7
|
import { HandlerChainBuilder } from "../handlers/HandlerChainBuilder";
|
|
10
8
|
import { createArrayBufferParsingHandler } from "../handlers/arrayBufferParsingHandler";
|
|
11
9
|
import { LensAssetManifestItem_RequestTiming } from "../generated-proto/pb_schema/camera_kit/v3/lens";
|
|
12
10
|
import { getLogger } from "../logger/logger";
|
|
13
11
|
import { errorLoggingDecorator } from "../logger/errorLoggingDecorator";
|
|
14
|
-
import {
|
|
12
|
+
import { ensureError } from "../common/errorHelpers";
|
|
15
13
|
import { isLensArray, toPublicLens } from "./Lens";
|
|
16
|
-
import { retrieveCameraKitLens, retrieveCameraKitLensGroup } from "./lensHttpUtil";
|
|
17
|
-
import { decodeEnvelopes } from "./lensEnvelopeUtil";
|
|
18
14
|
import { lensAssetRepositoryFactory } from "./assets/LensAssetRepository";
|
|
15
|
+
import { loadLensesFromSources, lensSourcesFactory } from "./LensSource";
|
|
19
16
|
const logger = getLogger("LensRepository");
|
|
20
17
|
const log = errorLoggingDecorator(logger);
|
|
21
18
|
const assetTimingMap = {
|
|
@@ -47,12 +44,10 @@ function isOptionalAssetTimingArray(value) {
|
|
|
47
44
|
*/
|
|
48
45
|
export class LensRepository {
|
|
49
46
|
/** @internal */
|
|
50
|
-
constructor(
|
|
51
|
-
this.lensMetadataFetchHandler = lensMetadataFetchHandler;
|
|
47
|
+
constructor(lensFetchHandler, lensSources, lensAssetRepository) {
|
|
52
48
|
this.lensFetchHandler = lensFetchHandler;
|
|
53
49
|
this.lensSources = lensSources;
|
|
54
50
|
this.lensAssetRepository = lensAssetRepository;
|
|
55
|
-
this.apiHostname = apiHostname;
|
|
56
51
|
this.metadataCache = new Map();
|
|
57
52
|
this.binariesCache = new Map();
|
|
58
53
|
}
|
|
@@ -65,16 +60,9 @@ export class LensRepository {
|
|
|
65
60
|
*/
|
|
66
61
|
loadLens(lensId, groupId) {
|
|
67
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
lens = decodeEnvelopes(envelopes)[0];
|
|
72
|
-
if (!lens) {
|
|
73
|
-
throw new Error("Expected non-empty envelope.");
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
lens = yield retrieveCameraKitLens(this.lensMetadataFetchHandler, lensId, groupId, this.apiHostname);
|
|
63
|
+
const lens = (yield loadLensesFromSources(this.lensSources, groupId, lensId))[0];
|
|
64
|
+
if (!lens) {
|
|
65
|
+
throw new Error(`Cannot load lens. No lens with id ${lensId} was found in lens group ${groupId}.`);
|
|
78
66
|
}
|
|
79
67
|
const lensWithGroup = Object.assign(Object.assign({}, lens), { groupId });
|
|
80
68
|
this.metadataCache.set(lens.id, lensWithGroup);
|
|
@@ -97,22 +85,25 @@ export class LensRepository {
|
|
|
97
85
|
return __awaiter(this, void 0, void 0, function* () {
|
|
98
86
|
const responses = yield Promise.all(groupIds.map((groupId) => __awaiter(this, void 0, void 0, function* () {
|
|
99
87
|
try {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
return lenses.map((lens) => toPublicLens(Object.assign(Object.assign({}, lens), { groupId })));
|
|
88
|
+
return (yield loadLensesFromSources(this.lensSources, groupId)).map((lens) => {
|
|
89
|
+
const lensWithGroup = Object.assign(Object.assign({}, lens), { groupId });
|
|
90
|
+
this.metadataCache.set(lens.id, lensWithGroup);
|
|
91
|
+
return toPublicLens(lensWithGroup);
|
|
92
|
+
});
|
|
106
93
|
}
|
|
107
|
-
catch (
|
|
94
|
+
catch (e) {
|
|
95
|
+
const error = ensureError(e);
|
|
108
96
|
logger.error(new Error(`Failed to load lens group ${groupId}.`, { cause: error }));
|
|
109
97
|
return error;
|
|
110
98
|
}
|
|
111
99
|
})));
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
100
|
+
return responses.reduce((result, response) => {
|
|
101
|
+
if (response instanceof Error)
|
|
102
|
+
result.errors.push(response);
|
|
103
|
+
else
|
|
104
|
+
result.lenses.push(...response);
|
|
105
|
+
return result;
|
|
106
|
+
}, { errors: [], lenses: [] });
|
|
116
107
|
});
|
|
117
108
|
}
|
|
118
109
|
/**
|
|
@@ -149,8 +140,8 @@ export class LensRepository {
|
|
|
149
140
|
this.binariesCache.set(lens.id, lensBuffer);
|
|
150
141
|
yield this.lensAssetRepository.cacheAssets(content.assetManifest, lens, assetTimingsToLoad);
|
|
151
142
|
}
|
|
152
|
-
catch (
|
|
153
|
-
logger.warn(
|
|
143
|
+
catch (error) {
|
|
144
|
+
logger.warn(`Failed to cache lens ${lens.id}.`, error);
|
|
154
145
|
}
|
|
155
146
|
})));
|
|
156
147
|
});
|
|
@@ -230,15 +221,13 @@ __decorate([
|
|
|
230
221
|
*/
|
|
231
222
|
export const lensRepositoryFactory = Injectable("LensRepository", [
|
|
232
223
|
requestStateEventTargetFactory.token,
|
|
233
|
-
cameraKitServiceFetchHandlerFactory.token,
|
|
234
224
|
defaultFetchHandlerFactory.token,
|
|
235
225
|
lensSourcesFactory.token,
|
|
236
226
|
lensAssetRepositoryFactory.token,
|
|
237
|
-
|
|
238
|
-
], (requestStateEventTarget, lensMetadataFetchHandler, defaultFetchHandler, lensSources, lensAssetRepository, configuration) => {
|
|
227
|
+
], (requestStateEventTarget, defaultFetchHandler, lensSources, lensAssetRepository) => {
|
|
239
228
|
const lensFetchHandler = new HandlerChainBuilder(defaultFetchHandler)
|
|
240
229
|
.map(createRequestStateEmittingHandler(requestStateEventTarget))
|
|
241
230
|
.map(createArrayBufferParsingHandler()).handler;
|
|
242
|
-
return new LensRepository(
|
|
231
|
+
return new LensRepository(lensFetchHandler, lensSources, lensAssetRepository);
|
|
243
232
|
});
|
|
244
233
|
//# 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;AAC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,+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, LensProtoWithGroupId, 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, LensProtoWithGroupId>();\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 const lensWithGroup = { ...lens, groupId };\n this.metadataCache.set(lens.id, lensWithGroup);\n return toPublicLens(lensWithGroup);\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, groupId }));\n return lenses.map((lens) => toPublicLens({ ...lens, groupId }));\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): LensProtoWithGroupId | 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"]}
|
|
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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port { isArrayOfType, isSafeString, isSafeStringArray, isString, isUndefined } from \"../common/typeguards\";\nimport { Injectable } from \"../dependency-injection/Injectable\";\nimport { defaultFetchHandlerFactory, FetchHandler } from \"../handlers/defaultFetchHandler\";\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 { ensureError } from \"../common/errorHelpers\";\nimport { isLensArray, Lens, LensProtoWithGroupId, toPublicLens } from \"./Lens\";\nimport { LensAssetRepository, lensAssetRepositoryFactory } from \"./assets/LensAssetRepository\";\nimport { LensSource, loadLensesFromSources, lensSourcesFactory } from \"./LensSource\";\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, LensProtoWithGroupId>();\n private readonly binariesCache = new Map<string, ArrayBuffer>();\n\n /** @internal */\n constructor(\n private readonly lensFetchHandler: LensFetchHandler,\n private readonly lensSources: LensSource[],\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 lens = (await loadLensesFromSources(this.lensSources, groupId, lensId))[0];\n if (!lens) {\n throw new Error(`Cannot load lens. No lens with id ${lensId} was found in lens group ${groupId}.`);\n }\n const lensWithGroup: LensProtoWithGroupId = { ...lens, groupId };\n this.metadataCache.set(lens.id, lensWithGroup);\n return toPublicLens(lensWithGroup);\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 return (await loadLensesFromSources(this.lensSources, groupId)).map((lens) => {\n const lensWithGroup = { ...lens, groupId };\n this.metadataCache.set(lens.id, lensWithGroup);\n return toPublicLens(lensWithGroup);\n });\n } catch (e) {\n const error = ensureError(e);\n logger.error(new Error(`Failed to load lens group ${groupId}.`, { cause: error }));\n return error;\n }\n })\n );\n\n return responses.reduce(\n (result, response) => {\n if (response instanceof Error) result.errors.push(response);\n else result.lenses.push(...response);\n return result;\n },\n { errors: [], lenses: [] } as { errors: Error[]; lenses: Lens[] }\n );\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 (error) {\n logger.warn(`Failed to cache lens ${lens.id}.`, error);\n }\n })\n );\n }\n\n /**\n * Returns loaded Lens metadata if available.\n */\n getLensMetadata(lensId: string): LensProtoWithGroupId | 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 defaultFetchHandlerFactory.token,\n lensSourcesFactory.token,\n lensAssetRepositoryFactory.token,\n ],\n (\n requestStateEventTarget: RequestStateEventTarget,\n defaultFetchHandler: FetchHandler,\n lensSources: LensSource[],\n lensAssetRepository: LensAssetRepository\n ) => {\n const lensFetchHandler = new HandlerChainBuilder(defaultFetchHandler)\n .map(createRequestStateEmittingHandler<LensDownloadDimensions>(requestStateEventTarget))\n .map(createArrayBufferParsingHandler()).handler;\n\n return new LensRepository(lensFetchHandler, lensSources, lensAssetRepository);\n }\n);\n"]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Lens } from "../generated-proto/pb_schema/camera_kit/v3/lens";
|
|
2
|
+
/**
|
|
3
|
+
* Provides Lens metadata for one or more Lens groups.
|
|
4
|
+
*
|
|
5
|
+
* When a Lens or Lens group is requested via the {@link LensRepository}, CameraKit will find the LensSource which
|
|
6
|
+
* claims ownership of that group. The appropriate LensSource method will be called and must return an ArrayBuffer
|
|
7
|
+
* containing the encoded Lens metadata -- this can be obtained from a CameraKit backend API.
|
|
8
|
+
*/
|
|
9
|
+
export interface LensSource {
|
|
10
|
+
isGroupOwner(groupId: string): boolean;
|
|
11
|
+
loadLens(lensId: string, groupId: string): Promise<ArrayBuffer>;
|
|
12
|
+
loadLensGroup(groupId: string): Promise<ArrayBuffer>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* By default, no custom {@link LensSources} are provided to CameraKit. But to enable certain advanced use-cases,
|
|
16
|
+
* applications may provide their own LensSources.
|
|
17
|
+
*
|
|
18
|
+
* Perhaps the most convenient way to do this is with {@link ConcatInjectable}, as shown here:
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { bootstrapCameraKit, lensSourcesFactory, LensSource } from '@snap/camera-kit'
|
|
23
|
+
*
|
|
24
|
+
* const cameraKit = bootstrapCameraKit(config, (container) => {
|
|
25
|
+
* return container.provides(ConcatInjectable(
|
|
26
|
+
* lensSourcesFactory.token,
|
|
27
|
+
* (): LensSource => { return ... }
|
|
28
|
+
* ))
|
|
29
|
+
* })
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare const lensSourcesFactory: {
|
|
33
|
+
(): LensSource[];
|
|
34
|
+
token: "lensSources";
|
|
35
|
+
dependencies: [];
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Given a list of LensSources (like the one provided by CameraKit's DI container under the `'lensSources'` token), and
|
|
39
|
+
* a groupId/lensId, return a list of lenses loaded by the first LensSource claiming ownership of the given groupId.
|
|
40
|
+
*
|
|
41
|
+
* @internal
|
|
42
|
+
*/
|
|
43
|
+
export declare function loadLensesFromSources(sources: LensSource[], groupId: string, lensId?: string): Promise<Lens[]>;
|