@snap/camera-kit 0.15.0 → 0.16.2

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.
Files changed (412) hide show
  1. package/README.md +3 -3
  2. package/docs/html/assets/main.js +4 -3
  3. package/docs/html/assets/navigation.js +1 -0
  4. package/docs/html/assets/search.js +1 -1
  5. package/docs/html/assets/style.css +72 -25
  6. package/docs/html/classes/CameraKit.html +11 -196
  7. package/docs/html/classes/CameraKitSession.html +43 -366
  8. package/docs/html/classes/CameraKitSource.html +14 -223
  9. package/docs/html/classes/LensPerformanceMeasurement.html +9 -184
  10. package/docs/html/classes/LensPerformanceMetrics.html +7 -148
  11. package/docs/html/classes/LensRepository.html +17 -234
  12. package/docs/html/classes/Transform2D.html +7 -176
  13. package/docs/html/classes/TypedCustomEvent.html +4 -178
  14. package/docs/html/classes/TypedEventTarget.html +4 -209
  15. package/docs/html/enums/Lens_CameraFacing.html +5 -0
  16. package/docs/html/enums/UserData_Zodiac.html +15 -0
  17. package/docs/html/functions/ConcatInjectable.html +10 -193
  18. package/docs/html/functions/Injectable.html +9 -192
  19. package/docs/html/functions/bootstrapCameraKit.html +6 -147
  20. package/docs/html/functions/createExtension.html +6 -123
  21. package/docs/html/functions/createImageSource.html +4 -130
  22. package/docs/html/functions/createMediaStreamSource.html +4 -130
  23. package/docs/html/functions/createVideoSource.html +4 -130
  24. package/docs/html/functions/estimateLensPerformance.html +3 -120
  25. package/docs/html/functions/lensSourcesFactory.html +6 -127
  26. package/docs/html/functions/remoteApiServicesFactory.html +3 -121
  27. package/docs/html/hierarchy.html +1 -0
  28. package/docs/html/index.html +8 -165
  29. package/docs/html/interfaces/CameraKitBootstrapConfiguration.html +11 -192
  30. package/docs/html/interfaces/CameraKitDeviceOptions.html +11 -0
  31. package/docs/html/interfaces/CameraKitSourceInfo.html +9 -0
  32. package/docs/html/interfaces/CameraKitSourceSubscriber.html +3 -194
  33. package/docs/html/interfaces/ComputedFrameMetrics.html +2 -150
  34. package/docs/html/interfaces/CreateSessionOptions.html +5 -148
  35. package/docs/html/interfaces/EstimatedLensPerformance.html +3 -146
  36. package/docs/html/interfaces/FunctionSourceOptions.html +7 -0
  37. package/docs/html/interfaces/Lens.html +12 -205
  38. package/docs/html/interfaces/LensCreator.html +3 -0
  39. package/docs/html/interfaces/LensLaunchData.html +3 -179
  40. package/docs/html/interfaces/LensSource.html +3 -172
  41. package/docs/html/interfaces/LoadAssetRequest.html +13 -0
  42. package/docs/html/interfaces/MediaStreamSourceOptions.html +16 -138
  43. package/docs/html/interfaces/Preview.html +4 -141
  44. package/docs/html/interfaces/RemoteApiRequest.html +7 -162
  45. package/docs/html/interfaces/RemoteApiResponse.html +6 -155
  46. package/docs/html/interfaces/RemoteApiService.html +9 -171
  47. package/docs/html/interfaces/Snapcode.html +5 -148
  48. package/docs/html/interfaces/UriCancelRequest.html +2 -138
  49. package/docs/html/interfaces/UriRequest.html +2 -154
  50. package/docs/html/interfaces/UriResponse.html +2 -150
  51. package/docs/html/interfaces/VideoSourceOptions.html +15 -134
  52. package/docs/html/modules.html +57 -175
  53. package/docs/html/types/AssetLoader.html +5 -132
  54. package/docs/html/types/AssetResponse.html +1 -0
  55. package/docs/html/types/AssetTiming.html +2 -115
  56. package/docs/html/types/BenchmarkError.html +1 -112
  57. package/docs/html/types/BootstrapError.html +2 -115
  58. package/docs/html/types/CacheKeyNotFoundError.html +1 -112
  59. package/docs/html/types/CameraKitSessionEventListener.html +2 -115
  60. package/docs/html/types/CameraKitSessionEvents.html +2 -122
  61. package/docs/html/types/CameraKitSourceError.html +1 -112
  62. package/docs/html/types/ConfigurationError.html +2 -115
  63. package/docs/html/types/FetchHandler.html +1 -0
  64. package/docs/html/types/Keyboard.html +14 -194
  65. package/docs/html/types/KeyboardEvents.html +2 -124
  66. package/docs/html/types/LegalError.html +1 -112
  67. package/docs/html/types/LensAbortError.html +2 -115
  68. package/docs/html/types/LensAssetError.html +2 -115
  69. package/docs/html/types/LensContentValidationError.html +1 -112
  70. package/docs/html/types/LensError.html +1 -112
  71. package/docs/html/types/LensExecutionError.html +2 -115
  72. package/docs/html/types/LensImagePickerError.html +2 -115
  73. package/docs/html/types/LensLaunchParams.html +2 -0
  74. package/docs/html/types/LensMetricsEvents.html +2 -115
  75. package/docs/html/types/LensPerformanceCluster.html +1 -113
  76. package/docs/html/types/LensView.html +2 -115
  77. package/docs/html/types/LensWait.html +2 -115
  78. package/docs/html/types/Matrix.html +3 -0
  79. package/docs/html/types/PersistentStoreError.html +2 -115
  80. package/docs/html/types/PlatformNotSupportedError.html +2 -115
  81. package/docs/html/types/PublicContainer.html +2 -115
  82. package/docs/html/types/PublicServices.html +2 -0
  83. package/docs/html/types/RemoteApiCancelRequestHandler.html +2 -0
  84. package/docs/html/types/RemoteApiRequestHandler.html +2 -139
  85. package/docs/html/types/RemoteApiServices.html +1 -112
  86. package/docs/html/types/RemoteApiStatus.html +2 -115
  87. package/docs/html/types/RenderTarget.html +2 -115
  88. package/docs/html/types/Uri.html +1 -112
  89. package/docs/html/types/WebGLError.html +1 -112
  90. package/docs/html/variables/extensionRequestContext.html +2 -115
  91. package/docs/md/README.md +3 -3
  92. package/docs/md/classes/CameraKit.md +15 -15
  93. package/docs/md/classes/CameraKitSession.md +38 -38
  94. package/docs/md/classes/CameraKitSource.md +22 -30
  95. package/docs/md/classes/LensPerformanceMeasurement.md +10 -6
  96. package/docs/md/classes/LensPerformanceMetrics.md +2 -2
  97. package/docs/md/classes/LensRepository.md +18 -18
  98. package/docs/md/classes/Transform2D.md +7 -3
  99. package/docs/md/classes/TypedCustomEvent.md +10 -6
  100. package/docs/md/classes/TypedEventTarget.md +12 -8
  101. package/docs/md/enums/Lens_CameraFacing.md +36 -0
  102. package/docs/md/enums/UserData_Zodiac.md +106 -0
  103. package/docs/md/interfaces/CameraKitBootstrapConfiguration.md +2 -2
  104. package/docs/md/interfaces/CameraKitDeviceOptions.md +41 -0
  105. package/docs/md/interfaces/CameraKitSourceInfo.md +43 -0
  106. package/docs/md/interfaces/CameraKitSourceSubscriber.md +7 -7
  107. package/docs/md/interfaces/ComputedFrameMetrics.md +1 -1
  108. package/docs/md/interfaces/CreateSessionOptions.md +1 -1
  109. package/docs/md/interfaces/EstimatedLensPerformance.md +1 -1
  110. package/docs/md/interfaces/FunctionSourceOptions.md +22 -0
  111. package/docs/md/interfaces/Lens.md +4 -4
  112. package/docs/md/interfaces/LensCreator.md +17 -0
  113. package/docs/md/interfaces/LensLaunchData.md +6 -6
  114. package/docs/md/interfaces/LensSource.md +5 -5
  115. package/docs/md/interfaces/LoadAssetRequest.md +49 -0
  116. package/docs/md/interfaces/MediaStreamSourceOptions.md +46 -1
  117. package/docs/md/interfaces/Preview.md +1 -1
  118. package/docs/md/interfaces/RemoteApiRequest.md +2 -2
  119. package/docs/md/interfaces/RemoteApiResponse.md +2 -2
  120. package/docs/md/interfaces/RemoteApiService.md +1 -1
  121. package/docs/md/interfaces/Snapcode.md +1 -1
  122. package/docs/md/interfaces/UriCancelRequest.md +2 -2
  123. package/docs/md/interfaces/UriRequest.md +3 -3
  124. package/docs/md/interfaces/UriResponse.md +2 -2
  125. package/docs/md/interfaces/VideoSourceOptions.md +44 -1
  126. package/docs/md/modules.md +183 -201
  127. package/lib/CameraKit.d.ts +108 -108
  128. package/lib/CameraKit.js +1 -1
  129. package/lib/CameraKit.js.map +1 -1
  130. package/lib/bootstrapCameraKit.d.ts +4 -4
  131. package/lib/bootstrapCameraKit.js +18 -19
  132. package/lib/bootstrapCameraKit.js.map +1 -1
  133. package/lib/clients/createTsProtoClient.d.ts +5 -12
  134. package/lib/clients/createTsProtoClient.js +1 -2
  135. package/lib/clients/createTsProtoClient.js.map +1 -1
  136. package/lib/clients/grpcHandler.d.ts +7 -4
  137. package/lib/clients/grpcHandler.js +8 -5
  138. package/lib/clients/grpcHandler.js.map +1 -1
  139. package/lib/clients/lensesClient.d.ts +3 -3
  140. package/lib/clients/lensesClient.js +2 -2
  141. package/lib/clients/lensesClient.js.map +1 -1
  142. package/lib/clients/metricsClient.d.ts +26 -0
  143. package/lib/clients/metricsClient.js +120 -0
  144. package/lib/clients/metricsClient.js.map +1 -0
  145. package/lib/configuration.js +1 -1
  146. package/lib/configuration.js.map +1 -1
  147. package/lib/dependency-injection/Container.d.ts +1 -1
  148. package/lib/dependency-injection/Container.js +1 -1
  149. package/lib/dependency-injection/Container.js.map +1 -1
  150. package/lib/dependency-injection/Injectable.d.ts +6 -6
  151. package/lib/dependency-injection/Injectable.js.map +1 -1
  152. package/lib/dependency-injection/RootServices.d.ts +7 -8
  153. package/lib/dependency-injection/RootServices.js.map +1 -1
  154. package/lib/environment.d.ts +4 -0
  155. package/lib/environment.js +2 -0
  156. package/lib/environment.js.map +1 -0
  157. package/lib/extensions/RemoteApiServices.d.ts +2 -2
  158. package/lib/extensions/RemoteApiServices.js +11 -6
  159. package/lib/extensions/RemoteApiServices.js.map +1 -1
  160. package/lib/extensions/uriHandlersRegister.d.ts +4 -4
  161. package/lib/extensions/uriHandlersRegister.js +6 -6
  162. package/lib/extensions/uriHandlersRegister.js.map +1 -1
  163. package/lib/generated-proto/blizzard/cameraKitEvents.d.ts +4330 -678
  164. package/lib/generated-proto/blizzard/cameraKitEvents.js +515 -72
  165. package/lib/generated-proto/blizzard/cameraKitEvents.js.map +1 -1
  166. package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.d.ts +3 -11
  167. package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.js +6 -156
  168. package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.js.map +1 -1
  169. package/lib/generated-proto/pb_schema/camera_kit/v3/export.d.ts +19 -19
  170. package/lib/generated-proto/pb_schema/camera_kit/v3/export.js +13 -27
  171. package/lib/generated-proto/pb_schema/camera_kit/v3/export.js.map +1 -1
  172. package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.d.ts +0 -6
  173. package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.js +2 -83
  174. package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.js.map +1 -1
  175. package/lib/generated-proto/pb_schema/camera_kit/v3/lens.d.ts +0 -22
  176. package/lib/generated-proto/pb_schema/camera_kit/v3/lens.js +0 -263
  177. package/lib/generated-proto/pb_schema/camera_kit/v3/lens.js.map +1 -1
  178. package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.d.ts +30 -34
  179. package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.js +7 -73
  180. package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.js.map +1 -1
  181. package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.d.ts +0 -6
  182. package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.js +0 -110
  183. package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.js.map +1 -1
  184. package/lib/generated-proto/pb_schema/camera_kit/v3/service.d.ts +48 -114
  185. package/lib/generated-proto/pb_schema/camera_kit/v3/service.js +0 -225
  186. package/lib/generated-proto/pb_schema/camera_kit/v3/service.js.map +1 -1
  187. package/lib/generated-proto/pb_schema/cdp/cof/benchmark.d.ts +6 -6
  188. package/lib/generated-proto/pb_schema/cdp/cof/benchmark.js +5 -19
  189. package/lib/generated-proto/pb_schema/cdp/cof/benchmark.js.map +1 -1
  190. package/lib/generated-proto/pb_schema/cdp/cof/circumstance_service.d.ts +1422 -1422
  191. package/lib/generated-proto/pb_schema/cdp/cof/config_request.d.ts +12 -12
  192. package/lib/generated-proto/pb_schema/cdp/cof/config_request.js +10 -24
  193. package/lib/generated-proto/pb_schema/cdp/cof/config_request.js.map +1 -1
  194. package/lib/generated-proto/pb_schema/cdp/cof/config_response.d.ts +207 -207
  195. package/lib/generated-proto/pb_schema/cdp/cof/config_result.d.ts +530 -530
  196. package/lib/generated-proto/pb_schema/cdp/cof/config_result.js +10 -24
  197. package/lib/generated-proto/pb_schema/cdp/cof/config_result.js.map +1 -1
  198. package/lib/generated-proto/pb_schema/common/value.d.ts +6 -6
  199. package/lib/generated-proto/pb_schema/common/value.js +4 -18
  200. package/lib/generated-proto/pb_schema/common/value.js.map +1 -1
  201. package/lib/generated-proto/pb_schema/google/api/http.d.ts +0 -6
  202. package/lib/generated-proto/pb_schema/google/api/http.js +0 -77
  203. package/lib/generated-proto/pb_schema/google/api/http.js.map +1 -1
  204. package/lib/generated-proto/pb_schema/google/protobuf/any.d.ts +0 -2
  205. package/lib/generated-proto/pb_schema/google/protobuf/any.js +0 -44
  206. package/lib/generated-proto/pb_schema/google/protobuf/any.js.map +1 -1
  207. package/lib/generated-proto/pb_schema/google/protobuf/descriptor.d.ts +4830 -4896
  208. package/lib/generated-proto/pb_schema/google/protobuf/descriptor.js +10 -997
  209. package/lib/generated-proto/pb_schema/google/protobuf/descriptor.js.map +1 -1
  210. package/lib/generated-proto/pb_schema/google/protobuf/timestamp.d.ts +3 -5
  211. package/lib/generated-proto/pb_schema/google/protobuf/timestamp.js +6 -35
  212. package/lib/generated-proto/pb_schema/google/protobuf/timestamp.js.map +1 -1
  213. package/lib/generated-proto/pb_schema/google/protobuf/wrappers.d.ts +6 -6
  214. package/lib/generated-proto/pb_schema/google/protobuf/wrappers.js +10 -24
  215. package/lib/generated-proto/pb_schema/google/protobuf/wrappers.js.map +1 -1
  216. package/lib/generated-proto/pb_schema/lenses/launchdata.d.ts +9 -9
  217. package/lib/generated-proto/pb_schema/lenses/remote_api/remote_api_service.d.ts +11 -11
  218. package/lib/generated-proto/pb_schema/lenses/remote_api/remote_api_service.js +6 -20
  219. package/lib/generated-proto/pb_schema/lenses/remote_api/remote_api_service.js.map +1 -1
  220. package/lib/generated-proto/pb_schema/lenses/snappable.d.ts +42 -42
  221. package/lib/generated-proto/pb_schema/lenses/snappable.js +14 -28
  222. package/lib/generated-proto/pb_schema/lenses/snappable.js.map +1 -1
  223. package/lib/generated-proto/pb_schema/lenses/user_data.d.ts +8 -8
  224. package/lib/generated-proto/pb_schema/lenses/user_data.js +8 -22
  225. package/lib/generated-proto/pb_schema/lenses/user_data.js.map +1 -1
  226. package/lib/handlers/defaultFetchHandler.d.ts +1 -1
  227. package/lib/handlers/defaultFetchHandler.js.map +1 -1
  228. package/lib/handlers/requestStateEmittingHandler.d.ts +5 -6
  229. package/lib/handlers/requestStateEmittingHandler.js +6 -8
  230. package/lib/handlers/requestStateEmittingHandler.js.map +1 -1
  231. package/lib/handlers/responseCachingHandler.d.ts +9 -10
  232. package/lib/handlers/responseCachingHandler.js +9 -3
  233. package/lib/handlers/responseCachingHandler.js.map +1 -1
  234. package/lib/handlers/utils.d.ts +12 -0
  235. package/lib/handlers/utils.js +19 -0
  236. package/lib/handlers/utils.js.map +1 -0
  237. package/lib/index.d.ts +21 -15
  238. package/lib/index.js +17 -12
  239. package/lib/index.js.map +1 -1
  240. package/lib/lens/Lens.d.ts +12 -2
  241. package/lib/lens/Lens.js +5 -0
  242. package/lib/lens/Lens.js.map +1 -1
  243. package/lib/lens/LensLaunchData.d.ts +6 -3
  244. package/lib/lens/LensLaunchData.js +2 -0
  245. package/lib/lens/LensLaunchData.js.map +1 -1
  246. package/lib/lens/LensPersistenceStore.d.ts +1 -1
  247. package/lib/lens/LensPersistenceStore.js +1 -1
  248. package/lib/lens/LensPersistenceStore.js.map +1 -1
  249. package/lib/lens/LensRepository.d.ts +5 -1
  250. package/lib/lens/LensRepository.js +9 -5
  251. package/lib/lens/LensRepository.js.map +1 -1
  252. package/lib/lens/LensSource.d.ts +2 -2
  253. package/lib/lens/LensSource.js +2 -2
  254. package/lib/lens/LensSource.js.map +1 -1
  255. package/lib/lens/assets/LensAssetRepository.d.ts +35 -4
  256. package/lib/lens/assets/LensAssetRepository.js +9 -9
  257. package/lib/lens/assets/LensAssetRepository.js.map +1 -1
  258. package/lib/lens/assets/LensAssetsProvider.d.ts +1 -1
  259. package/lib/lens/assets/LensAssetsProvider.js +9 -4
  260. package/lib/lens/assets/LensAssetsProvider.js.map +1 -1
  261. package/lib/lens/assets/deviceDependentAssetLoader.js +3 -2
  262. package/lib/lens/assets/deviceDependentAssetLoader.js.map +1 -1
  263. package/lib/lens/assets/remoteMediaAssetLoaderFactory.js +4 -3
  264. package/lib/lens/assets/remoteMediaAssetLoaderFactory.js.map +1 -1
  265. package/lib/lens/assets/staticAssetLoader.js +5 -4
  266. package/lib/lens/assets/staticAssetLoader.js.map +1 -1
  267. package/lib/lens/cameraKitLensSource.js.map +1 -1
  268. package/lib/lens-client-interface/imagePicker.d.ts +2 -1
  269. package/lib/lens-client-interface/imagePicker.js.map +1 -1
  270. package/lib/lens-client-interface/lensClientInterface.d.ts +1 -1
  271. package/lib/lens-client-interface/lensClientInterface.js +1 -1
  272. package/lib/lens-client-interface/lensClientInterface.js.map +1 -1
  273. package/lib/lens-core-module/lensCore.d.ts +2 -1
  274. package/lib/lens-core-module/lensCore.js.map +1 -1
  275. package/lib/lens-core-module/loader/bootstrapURLs.d.ts +12 -0
  276. package/lib/lens-core-module/loader/bootstrapURLs.js +48 -0
  277. package/lib/lens-core-module/loader/bootstrapURLs.js.map +1 -0
  278. package/lib/lens-core-module/loader/lensCoreFactory.d.ts +0 -12
  279. package/lib/lens-core-module/loader/lensCoreFactory.js +4 -49
  280. package/lib/lens-core-module/loader/lensCoreFactory.js.map +1 -1
  281. package/lib/lensCoreWasmVersions.d.ts +6 -0
  282. package/lib/lensCoreWasmVersions.js +6 -0
  283. package/lib/lensCoreWasmVersions.js.map +1 -0
  284. package/lib/media-sources/CameraKitSource.d.ts +39 -17
  285. package/lib/media-sources/CameraKitSource.js +8 -2
  286. package/lib/media-sources/CameraKitSource.js.map +1 -1
  287. package/lib/media-sources/FunctionSource.d.ts +15 -4
  288. package/lib/media-sources/FunctionSource.js +1 -2
  289. package/lib/media-sources/FunctionSource.js.map +1 -1
  290. package/lib/media-sources/ImageSource.d.ts +3 -5
  291. package/lib/media-sources/ImageSource.js +1 -3
  292. package/lib/media-sources/ImageSource.js.map +1 -1
  293. package/lib/media-sources/MediaStreamSource.d.ts +17 -33
  294. package/lib/media-sources/MediaStreamSource.js +6 -41
  295. package/lib/media-sources/MediaStreamSource.js.map +1 -1
  296. package/lib/media-sources/VideoSource.d.ts +14 -10
  297. package/lib/media-sources/VideoSource.js +5 -11
  298. package/lib/media-sources/VideoSource.js.map +1 -1
  299. package/lib/metrics/businessEventsReporter.d.ts +3 -4
  300. package/lib/metrics/businessEventsReporter.js +11 -55
  301. package/lib/metrics/businessEventsReporter.js.map +1 -1
  302. package/lib/metrics/operational/Count.d.ts +2 -0
  303. package/lib/metrics/operational/Count.js +6 -1
  304. package/lib/metrics/operational/Count.js.map +1 -1
  305. package/lib/metrics/operational/Histogram.d.ts +1 -1
  306. package/lib/metrics/operational/Histogram.js +7 -3
  307. package/lib/metrics/operational/Histogram.js.map +1 -1
  308. package/lib/metrics/operational/Metric.js +2 -0
  309. package/lib/metrics/operational/Metric.js.map +1 -1
  310. package/lib/metrics/operational/Timer.d.ts +9 -6
  311. package/lib/metrics/operational/Timer.js +12 -26
  312. package/lib/metrics/operational/Timer.js.map +1 -1
  313. package/lib/metrics/reporters/reportBenchmarks.d.ts +3 -3
  314. package/lib/metrics/reporters/reportBenchmarks.js +6 -5
  315. package/lib/metrics/reporters/reportBenchmarks.js.map +1 -1
  316. package/lib/metrics/reporters/reportGlobalException.d.ts +4 -4
  317. package/lib/metrics/reporters/reportGlobalException.js +13 -11
  318. package/lib/metrics/reporters/reportGlobalException.js.map +1 -1
  319. package/lib/metrics/reporters/reportHttpMetrics.d.ts +3 -3
  320. package/lib/metrics/reporters/reportHttpMetrics.js +19 -16
  321. package/lib/metrics/reporters/reportHttpMetrics.js.map +1 -1
  322. package/lib/metrics/reporters/reportLegalState.d.ts +3 -3
  323. package/lib/metrics/reporters/reportLegalState.js +7 -9
  324. package/lib/metrics/reporters/reportLegalState.js.map +1 -1
  325. package/lib/metrics/reporters/reportLensAndAssetDownload.d.ts +3 -3
  326. package/lib/metrics/reporters/reportLensAndAssetDownload.js +12 -12
  327. package/lib/metrics/reporters/reportLensAndAssetDownload.js.map +1 -1
  328. package/lib/metrics/reporters/reportLensView.d.ts +3 -3
  329. package/lib/metrics/reporters/reportLensView.js +6 -6
  330. package/lib/metrics/reporters/reportLensView.js.map +1 -1
  331. package/lib/metrics/reporters/reportLensWait.d.ts +2 -3
  332. package/lib/metrics/reporters/reportLensWait.js +1 -3
  333. package/lib/metrics/reporters/reportLensWait.js.map +1 -1
  334. package/lib/metrics/reporters/reportPlatformCapabilities.d.ts +3 -3
  335. package/lib/metrics/reporters/reportPlatformCapabilities.js +6 -5
  336. package/lib/metrics/reporters/reportPlatformCapabilities.js.map +1 -1
  337. package/lib/metrics/reporters/reportUserSession.js +3 -3
  338. package/lib/metrics/reporters/reportUserSession.js.map +1 -1
  339. package/lib/metrics/reporters/reporters.d.ts +2 -2
  340. package/lib/namedErrors.d.ts +1 -1
  341. package/lib/namedErrors.js +1 -1
  342. package/lib/namedErrors.js.map +1 -1
  343. package/lib/observable-operators/unsubscribed.d.ts +1 -1
  344. package/lib/observable-operators/unsubscribed.js +1 -1
  345. package/lib/observable-operators/unsubscribed.js.map +1 -1
  346. package/lib/platform/platformCapabilities.d.ts +1 -1
  347. package/lib/platform/platformCapabilities.js +9 -3
  348. package/lib/platform/platformCapabilities.js.map +1 -1
  349. package/lib/platform/platformInfo.d.ts +1 -0
  350. package/lib/platform/platformInfo.js +3 -3
  351. package/lib/platform/platformInfo.js.map +1 -1
  352. package/lib/remote-configuration/cofHandler.d.ts +3 -3
  353. package/lib/remote-configuration/cofHandler.js +6 -4
  354. package/lib/remote-configuration/cofHandler.js.map +1 -1
  355. package/lib/remote-configuration/preloadConfiguration.d.ts +1 -1
  356. package/lib/remote-configuration/preloadConfiguration.js +1 -1
  357. package/lib/remote-configuration/preloadConfiguration.js.map +1 -1
  358. package/lib/remote-configuration/remoteConfiguration.d.ts +7 -6
  359. package/lib/remote-configuration/remoteConfiguration.js +18 -15
  360. package/lib/remote-configuration/remoteConfiguration.js.map +1 -1
  361. package/lib/session/CameraKitSession.d.ts +8 -8
  362. package/lib/session/CameraKitSession.js +11 -9
  363. package/lib/session/CameraKitSession.js.map +1 -1
  364. package/lib/session/LensKeyboard.d.ts +2 -3
  365. package/lib/session/LensKeyboard.js.map +1 -1
  366. package/lib/session/LensPerformanceMeasurement.d.ts +1 -1
  367. package/lib/session/LensPerformanceMeasurement.js +3 -3
  368. package/lib/session/LensPerformanceMeasurement.js.map +1 -1
  369. package/lib/session/LensPerformanceMetrics.d.ts +1 -1
  370. package/lib/session/LensPerformanceMetrics.js.map +1 -1
  371. package/lib/session/lensState.d.ts +4 -4
  372. package/lib/session/lensState.js +10 -10
  373. package/lib/session/lensState.js.map +1 -1
  374. package/lib/transforms/Transform2D.d.ts +8 -3
  375. package/lib/transforms/Transform2D.js +1 -1
  376. package/lib/transforms/Transform2D.js.map +1 -1
  377. package/lib/utils.d.ts +3 -0
  378. package/lib/utils.js +4 -0
  379. package/lib/utils.js.map +1 -0
  380. package/package.json +27 -6
  381. package/docs/html/functions/createUserMediaSource.html +0 -138
  382. package/docs/html/functions/getRequiredBootstrapURLs.html +0 -130
  383. package/docs/html/types/CameraKitDeviceInfo.html +0 -125
  384. package/docs/html/types/CameraKitDeviceOptions.html +0 -120
  385. package/docs/html/types/CameraKitSourceInfo.html +0 -112
  386. package/docs/html/types/CameraKitSourceOptions.html +0 -118
  387. package/lib/common/index.d.ts +0 -2
  388. package/lib/common/index.js +0 -3
  389. package/lib/common/index.js.map +0 -1
  390. package/lib/environment.json +0 -1
  391. package/lib/handlers/index.d.ts +0 -2
  392. package/lib/handlers/index.js +0 -3
  393. package/lib/handlers/index.js.map +0 -1
  394. package/lib/lens-core-module/index.d.ts +0 -3
  395. package/lib/lens-core-module/index.js +0 -4
  396. package/lib/lens-core-module/index.js.map +0 -1
  397. package/lib/lens-core-module/loader/index.d.ts +0 -1
  398. package/lib/lens-core-module/loader/index.js +0 -2
  399. package/lib/lens-core-module/loader/index.js.map +0 -1
  400. package/lib/lensCoreWasmVersions.json +0 -5
  401. package/lib/metrics/metricsHandler.d.ts +0 -10
  402. package/lib/metrics/metricsHandler.js +0 -13
  403. package/lib/metrics/metricsHandler.js.map +0 -1
  404. package/lib/metrics/operational/operationalMetricsReporter.d.ts +0 -64
  405. package/lib/metrics/operational/operationalMetricsReporter.js +0 -144
  406. package/lib/metrics/operational/operationalMetricsReporter.js.map +0 -1
  407. package/lib/session/index.d.ts +0 -1
  408. package/lib/session/index.js +0 -2
  409. package/lib/session/index.js.map +0 -1
  410. package/lib/transforms/index.d.ts +0 -1
  411. package/lib/transforms/index.js +0 -2
  412. package/lib/transforms/index.js.map +0 -1
package/lib/lens/Lens.js CHANGED
@@ -1,5 +1,10 @@
1
1
  import { assert } from "../common/assertions";
2
2
  import { predicateRecordValues, isRecord, isString, isUndefined, isEmptyOrSafeUrl, isArrayOfType, isTypedArray, isNumber, } from "../common/typeguards";
3
+ import { Lens_CameraFacing } from "../generated-proto/pb_schema/camera_kit/v3/lens";
4
+ /**
5
+ * Camera facing.
6
+ */
7
+ export { Lens_CameraFacing };
3
8
  export function isLensArray(value) {
4
9
  return isArrayOfType(isLens, value);
5
10
  }
@@ -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,EACZ,QAAQ,GACX,MAAM,sBAAsB,CAAC;AA4G9B,MAAM,UAAU,WAAW,CAAC,KAAc;IACtC,OAAO,aAAa,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,KAAc;IACjC,OAAO,CACH,QAAQ,CAAC,KAAK,CAAC;QACf,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAClB,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC;QACpB,CAAC,WAAW,CAA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C,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"]}
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;AAC9B,OAAO,EAAW,iBAAiB,EAAqB,MAAM,iDAAiD,CAAC;AAIhH;;GAEG;AACH,OAAO,EAAE,iBAAiB,EAAE,CAAC;AA2G7B,MAAM,UAAU,WAAW,CAAC,KAAc;IACtC,OAAO,aAAa,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,KAAc;IACjC,OAAO,CACH,QAAQ,CAAC,KAAK,CAAC;QACf,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAClB,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC;QACpB,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACvD,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC;QAC1B,qBAAqB,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC;QACjD,QAAQ,CAAC,KAAK,CAAC,sBAAsB,CAAC;QACtC,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACxD,CAAC,WAAW,CAAC,KAAK,CAAC,WAAW,C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,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 { Content, Lens_CameraFacing, Lens as LensProto } 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\n/**\n * Camera facing.\n */\nexport { Lens_CameraFacing };\n\n/**\n * Lens creator.\n */\nexport interface LensCreator {\n displayName: string;\n}\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 {@link 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"]}
@@ -1,5 +1,9 @@
1
1
  import { UserData_Zodiac } from "../generated-proto/pb_schema/lenses/user_data";
2
- type LensLaunchParams = Record<string, string | number | string[] | number[]>;
2
+ /**
3
+ * Lens launch params.
4
+ */
5
+ export type LensLaunchParams = Record<string, string | number | string[] | number[]>;
6
+ export { UserData_Zodiac };
3
7
  /**
4
8
  * Some Lenses may accept (or require) certain data provided to them when the Lens is applied.
5
9
  *
@@ -16,7 +20,7 @@ export interface LensLaunchData {
16
20
  birthdate: string;
17
21
  displayName: string;
18
22
  countrycode: string;
19
- score: number;
23
+ score: string;
20
24
  bitmojiInfo?: {
21
25
  avatarId: string;
22
26
  selfieId: string;
@@ -34,4 +38,3 @@ export interface LensLaunchData {
34
38
  * @internal
35
39
  */
36
40
  export declare const encodeLensLaunchData: (launchData: LensLaunchData, persistentStore: ArrayBuffer) => Uint8Array;
37
- export {};
@@ -1,5 +1,6 @@
1
1
  import { LaunchData } from "../generated-proto/pb_schema/lenses/launchdata";
2
2
  import { isNumber, isRecord, isString } from "../common/typeguards";
3
+ import { UserData_Zodiac } from "../generated-proto/pb_schema/lenses/user_data";
3
4
  const isValidNumber = (value) => {
4
5
  return isNumber(value) && !Number.isNaN(value) && Number.isFinite(value);
5
6
  };
@@ -8,6 +9,7 @@ const isValidLaunchParam = (value) => {
8
9
  return value.every(isString) || value.every(isValidNumber);
9
10
  return isString(value) || isValidNumber(value);
10
11
  };
12
+ export { UserData_Zodiac };
11
13
  /**
12
14
  * @internal
13
15
  */
@@ -1 +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,KAA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,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
+ {"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;AAEpE,OAAO,EAAE,eAAe,EAAE,MAAM,+CAA+C,CAAC;AAEhF,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;AAOF,OAA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enses/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\n/**\n * Lens launch params.\n */\nexport type LensLaunchParams = Record<string, string | number | string[] | number[]>;\n\nexport { UserData_Zodiac };\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: string;\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,5 +1,5 @@
1
- import { LensCore } from "../lens-core-module";
2
1
  import { IndexedDBPersistence } from "../persistence/IndexedDBPersistence";
2
+ import { LensCore } from "../lens-core-module/lensCore";
3
3
  export declare const lensPersistenceStoreFactory: {
4
4
  (args_0: LensCore): IndexedDBPersistence<ArrayBuffer>;
5
5
  token: "lensPersistenceStore";
@@ -1,9 +1,9 @@
1
1
  import { __awaiter } from "tslib";
2
2
  import { Injectable } from "../dependency-injection/Injectable";
3
3
  import { persistentStoreError } from "../namedErrors";
4
- import { lensCoreFactory } from "../lens-core-module";
5
4
  import { getLogger } from "../logger/logger";
6
5
  import { IndexedDBPersistence } from "../persistence/IndexedDBPersistence";
6
+ import { lensCoreFactory } from "../lens-core-module/loader/lensCoreFactory";
7
7
  const logger = getLogger("LensPersistenceStore");
8
8
  export const lensPersistenceStoreFactory = Injectable("lensPersistenceStore", [lensCoreFactory.token], (lensCore) => {
9
9
  const db = new IndexedDBPersistence({ databaseName: "lensPersistenceStore" });
@@ -1 +1 @@
1
- {"version":3,"file":"LensPersistenceStore.js","sourceRoot":"","sources":["../../src/lens/LensPersistenceStore.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAY,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAE3E,MAAM,MAAM,GAAG,SAAS,CAAC,sBAAsB,CAAC,CAAC;AAEjD,MAAM,CAAC,MAAM,2BAA2B,GAAG,UAAU,CACjD,sBAAsB,EACtB,CAAC,eAAe,CAAC,KAAK,CAAU,EAChC,CAAC,QAAkB,EAAqC,EAAE;IACtD,MAAM,EAAE,GAAG,IAAI,oBAAoB,CAAc,EAAE,YAAY,EAAE,sBAAsB,EAAE,CAAC,CAAC;IAC3F,QAAQ,CAAC,mCAAmC,CAAC,CAAO,EAAE,EAAE,IAAI,EAAE,EAAE;QAC5D,IAAI;YACA,MAAM,EAAE,CAAC,KAAK,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;SAC5B;QAAC,OAAO,KAAK,EAAE;YACZ,MAAM,CAAC,KAAK,CAAC,oBAAoB,CAAC,8CAA8C,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;SAClG;IACL,CAAC,CAAA,CAAC,CAAC;IACH,OAAO,EAAE,CAAC;AACd,CAAC,CACJ,CAAC","sourcesContent":["import { Injectable } from \"../dependency-injection/Injectable\";\nimport { persistentStoreError } from \"../namedErrors\";\nimport { lensCoreFactory, LensCore } from \"../lens-core-module\";\nimport { getLogger } from \"../logger/logger\";\nimport { IndexedDBPersistence } from \"../persistence/IndexedDBPersistence\";\n\nconst logger = getLogger(\"LensPersistenceStore\");\n\nexport const lensPersistenceStoreFactory = Injectable(\n \"lensPersistenceStore\",\n [lensCoreFactory.token] as const,\n (lensCore: LensCore): IndexedDBPersistence<ArrayBuffer> => {\n const db = new IndexedDBPersistence<ArrayBuffer>({ databaseName: \"lensPersistenceStore\" });\n lensCore.registerSavePersistentStoreCallback(async (id, data) => {\n try {\n await db.store(id, data);\n } catch (error) {\n logger.error(persistentStoreError(`Error occurred while storing data for lens ${id}.`, error));\n }\n });\n return db;\n }\n);\n"]}
1
+ {"version":3,"file":"LensPersistenceStore.js","sourceRoot":"","sources":["../../src/lens/LensPersistenceStore.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAG7E,MAAM,MAAM,GAAG,SAAS,CAAC,sBAAsB,CAAC,CAAC;AAEjD,MAAM,CAAC,MAAM,2BAA2B,GAAG,UAAU,CACjD,sBAAsB,EACtB,CAAC,eAAe,CAAC,KAAK,CAAU,EAChC,CAAC,QAAkB,EAAqC,EAAE;IACtD,MAAM,EAAE,GAAG,IAAI,oBAAoB,CAAc,EAAE,YAAY,EAAE,sBAAsB,EAAE,CAAC,CAAC;IAC3F,QAAQ,CAAC,mCAAmC,CAAC,CAAO,EAAE,EAAE,IAAI,EAAE,EAAE;QAC5D,IAAI;YACA,MAAM,EAAE,CAAC,KAAK,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;SAC5B;QAAC,OAAO,KAAK,EAAE;YACZ,MAAM,CAAC,KAAK,CAAC,oBAAoB,CAAC,8CAA8C,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;SAClG;IACL,CAAC,CAAA,CAAC,CAAC;IACH,OAAO,EAAE,CAAC;AACd,CAAC,CACJ,CAAC","sourcesContent":["import { Injectable } from \"../dependency-injection/Injectable\";\nimport { persistentStoreError } from \"../namedErrors\";\nimport { getLogger } from \"../logger/logger\";\nimport { IndexedDBPersistence } from \"../persistence/IndexedDBPersistence\";\nimport { lensCoreFactory } from \"../lens-core-module/loader/lensCoreFactory\";\nimport { LensCore } from \"../lens-core-module/lensCore\";\n\nconst logger = getLogger(\"LensPersistenceStore\");\n\nexport const lensPersistenceStoreFactory = Injectable(\n \"lensPersistenceStore\",\n [lensCoreFactory.token] as const,\n (lensCore: LensCore): IndexedDBPersistence<ArrayBuffer> => {\n const db = new IndexedDBPersistence<ArrayBuffer>({ databaseName: \"lensPersistenceStore\" });\n lensCore.registerSavePersistentStoreCallback(async (id, data) => {\n try {\n await db.store(id, data);\n } catch (error) {\n logger.error(persistentStoreError(`Error occurred while storing data for lens ${id}.`, error));\n }\n });\n return db;\n }\n);\n"]}
@@ -119,8 +119,12 @@ export declare class LensRepository {
119
119
  * Fetches lens content and assets. This may come from the cache, otherwise network requests will be made.
120
120
  *
121
121
  * @internal
122
+ *
123
+ * @param lens Lens to fetch content for.
124
+ * @param lowPriority Flag indicating if the fetch requests should be treated with lower priority,
125
+ * leveraging browser capabilities to defer or deprioritize network traffic.
122
126
  */
123
- getLensContent(lens: Lens): Promise<LensBinary>;
127
+ getLensContent(lens: Lens, lowPriority?: boolean): Promise<LensBinary>;
124
128
  }
125
129
  /**
126
130
  * @internal
@@ -10,6 +10,7 @@ import { LensAssetManifestItem_RequestTiming } from "../generated-proto/pb_schem
10
10
  import { getLogger } from "../logger/logger";
11
11
  import { errorLoggingDecorator } from "../logger/errorLoggingDecorator";
12
12
  import { ensureError } from "../common/errorHelpers";
13
+ import { withRequestPriority } from "../handlers/utils";
13
14
  import { isLensArray, toPublicLens } from "./Lens";
14
15
  import { lensAssetRepositoryFactory } from "./assets/LensAssetRepository";
15
16
  import { loadLensesFromSources, lensSourcesFactory } from "./LensSource";
@@ -134,11 +135,11 @@ export class LensRepository {
134
135
  const assetTimingsToLoad = assetTimingsToCache.map((timing) => assetTimingMap[timing]);
135
136
  yield Promise.all(lenses.map((lens) => __awaiter(this, void 0, void 0, function* () {
136
137
  try {
137
- const { lensBuffer } = yield this.getLensContent(lens);
138
+ const { lensBuffer } = yield this.getLensContent(lens, true);
138
139
  // Safety: getLensContent() call above ensures metadata to exist
139
140
  const { content } = this.metadataCache.get(lens.id);
140
141
  this.binariesCache.set(lens.id, lensBuffer);
141
- yield this.lensAssetRepository.cacheAssets(content.assetManifest, lens, assetTimingsToLoad);
142
+ yield this.lensAssetRepository.cacheAssets(content.assetManifest, lens, assetTimingsToLoad, true);
142
143
  }
143
144
  catch (error) {
144
145
  logger.warn(`Failed to cache lens ${lens.id}.`, error);
@@ -162,8 +163,12 @@ export class LensRepository {
162
163
  * Fetches lens content and assets. This may come from the cache, otherwise network requests will be made.
163
164
  *
164
165
  * @internal
166
+ *
167
+ * @param lens Lens to fetch content for.
168
+ * @param lowPriority Flag indicating if the fetch requests should be treated with lower priority,
169
+ * leveraging browser capabilities to defer or deprioritize network traffic.
165
170
  */
166
- getLensContent(lens) {
171
+ getLensContent(lens, lowPriority = false) {
167
172
  var _a;
168
173
  return __awaiter(this, void 0, void 0, function* () {
169
174
  const { content } = (_a = this.metadataCache.get(lens.id)) !== null && _a !== void 0 ? _a : {};
@@ -177,10 +182,9 @@ export class LensRepository {
177
182
  lensChecksum: content.lnsSha256,
178
183
  };
179
184
  }
180
- // Load required lens assets and the lens itself in parallel. We count both toward lens download time.
181
185
  const [lensBuffer] = yield this.lensFetchHandler([
182
186
  // TODO: remove force-cache once https://jira.sc-corp.net/browse/CAMKIT-3671 is addressed
183
- new Request(content.lnsUrlBolt, { cache: "force-cache" }),
187
+ new Request(content.lnsUrlBolt, withRequestPriority({ cache: "force-cache" }, lowPriority)),
184
188
  {
185
189
  requestType: "lens_content",
186
190
  lensId: lens.id,
@@ -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,0BAA0B,EAAgB,MAAM,iCAAiC,CAAC;AAC3F,OAAO,EAEH,iCAAiC,EACjC,8BAA8B,GACjC,MAAM,yCAAyC,CAAC;AAEjD,OAAO,EAAW,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AAO,EAAE,UAAU,EAAE,YAAY,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC;;KAC1D;CACJ;AA/IS;IAFL,QAAQ;IACR,GAAG;IACY,WAAA,KAAK,CAAC,YAAY,CAAC,CAAA;IAAkB,WAAA,KAAK,CAAC,YAAY,CAAC,CAAA;;;;8CAQvE;AAgBK;IAFL,QAAQ;IACR,GAAG;IACkB,WAAA,KAAK,CAAC,iBAAiB,CAAC,CAAA;;;;oDA4B7C;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,0BAA0B,CAAC,KAAK;IAChC,kBAAkB,CAAC,KAAK;IACxB,0BAA0B,CAAC,KAAK;CACnC,EACD,CACI,uBAAgD,EAChD,mBAAiC,EACjC,WAAyB,EACzB,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;IAEpD,OAAO,IAAI,cAAc,CAAC,gBAAgB,EAAE,WAAW,EAAE,mBAAmB,CAAC,CAAC;AAClF,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 { 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"]}
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,0BAA0B,EAAgB,MAAM,iCAAiC,CAAC;AAC3F,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,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,WAAW,EAA8B,YAAY,EAAE,MAAM,QAAQ,CAAC;AAC/E,OAAO,EAAuB,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC/F,OAAO,EAAc,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAErF,MAAM,MAAM,GAAG,SAAS,CAAC,gBAAgB,CAAC,CAAC;AAC3C,MAAM,GAAG,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC;AAQ1C,MAAM,cAAc,GAAG;IACnB,QAAQ,EAAE,mCAAmC,CAAC,QAAQ;IACtD,QAAQ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AK;CAC1B,EACV,CACI,uBAAgD,EAChD,mBAAiC,EACjC,WAAyB,EACzB,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;IAEpD,OAAO,IAAI,cAAc,CAAC,gBAAgB,EAAE,WAAW,EAAE,mBAAmB,CAAC,CAAC;AAClF,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 { 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 { withRequestPriority } from \"../handlers/utils\";\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, true);\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, true);\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 * @param lens Lens to fetch content for.\n * @param lowPriority Flag indicating if the fetch requests should be treated with lower priority,\n * leveraging browser capabilities to defer or deprioritize network traffic.\n */\n async getLensContent(lens: Lens, lowPriority: boolean = false): 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 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, withRequestPriority({ cache: \"force-cache\" }, lowPriority)),\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 ] as const,\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"]}
@@ -12,8 +12,8 @@ export interface LensSource {
12
12
  loadLensGroup(groupId: string): Promise<ArrayBuffer>;
13
13
  }
14
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.
15
+ * By default, no custom {@link LensSource} is provided to CameraKit. But to enable certain advanced use-cases,
16
+ * applications may provide their own {@link LensSource}.
17
17
  *
18
18
  * Perhaps the most convenient way to do this is with {@link ConcatInjectable}, as shown here:
19
19
  *
@@ -2,8 +2,8 @@ import { __awaiter } from "tslib";
2
2
  import { Injectable } from "../dependency-injection/Injectable";
3
3
  import { Envelope } from "../generated-proto/pb_schema/camera_kit/v3/export";
4
4
  /**
5
- * By default, no custom {@link LensSources} are provided to CameraKit. But to enable certain advanced use-cases,
6
- * applications may provide their own LensSources.
5
+ * By default, no custom {@link LensSource} is provided to CameraKit. But to enable certain advanced use-cases,
6
+ * applications may provide their own {@link LensSource}.
7
7
  *
8
8
  * Perhaps the most convenient way to do this is with {@link ConcatInjectable}, as shown here:
9
9
  *
@@ -1 +1 @@
1
- {"version":3,"file":"LensSource.js","sourceRoot":"","sources":["../../src/lens/LensSource.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,mDAAmD,CAAC;AAgB7E;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,UAAU,CAAC,aAAa,EAAE,GAAiB,EAAE,CAAC,EAAE,CAAC,CAAC;AAEpF;;;;;GAKG;AACH,MAAM,UAAgB,qBAAqB,CAAC,OAAqB,EAAE,OAAe,EAAE,MAAe;;QAC/F,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;QACtE,IAAI,CAAC,MAAM,EAAE;YACT,MAAM,IAAI,KAAK,CACX,oBAAoB,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,QAAQ,CAAC,CAAC,CAAC,EAAE,SAAS,OAAO,sCAAsC;gBACrG,kBAAkB,CACzB,CAAC;SACL;QACD,MAAM,QAAQ,GACV,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAExG,OAAO,QAAQ,YAAY,WAAW,IAAI,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC;YAClE,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,YAAY,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM;YAC9F,CAAC,CAAC,EAAE,CAAC;IACb,CAAC;CAAA","sourcesContent":["import { Injectable } from \"../dependency-injection/Injectable\";\nimport { Envelope } from \"../generated-proto/pb_schema/camera_kit/v3/export\";\nimport { Lens } from \"../generated-proto/pb_schema/camera_kit/v3/lens\";\n\n/**\n * Provides Lens metadata for one or more Lens groups.\n *\n * When a Lens or Lens group is requested via the {@link LensRepository}, CameraKit will find the LensSource which\n * claims ownership of that group. The appropriate LensSource method will be called and must return an ArrayBuffer\n * containing the encoded Lens metadata -- this can be obtained from a CameraKit backend API.\n */\nexport interface LensSource {\n isGroupOwner(groupId: string): boolean;\n loadLens(lensId: string, groupId: string): Promise<ArrayBuffer>;\n loadLensGroup(groupId: string): Promise<ArrayBuffer>;\n}\n\n/**\n * By default, no custom {@link LensSources} are provided to CameraKit. But to enable certain advanced use-cases,\n * applications may provide their own LensSources.\n *\n * Perhaps the most convenient way to do this is with {@link ConcatInjectable}, as shown here:\n *\n * @example\n * ```ts\n * import { bootstrapCameraKit, lensSourcesFactory, LensSource } from '@snap/camera-kit'\n *\n * const cameraKit = bootstrapCameraKit(config, (container) => {\n * return container.provides(ConcatInjectable(\n * lensSourcesFactory.token,\n * (): LensSource => { return ... }\n * ))\n * })\n * ```\n */\nexport const lensSourcesFactory = Injectable(\"lensSources\", (): LensSource[] => []);\n\n/**\n * Given a list of LensSources (like the one provided by CameraKit's DI container under the `'lensSources'` token), and\n * a groupId/lensId, return a list of lenses loaded by the first LensSource claiming ownership of the given groupId.\n *\n * @internal\n */\nexport async function loadLensesFromSources(sources: LensSource[], groupId: string, lensId?: string): Promise<Lens[]> {\n const source = sources.find((source) => source.isGroupOwner(groupId));\n if (!source) {\n throw new Error(\n `Cannot load lens ${lensId ? `${lensId} from ` : \"\"}group ${groupId}. No LensSource claimed ownership of` +\n `that lens group.`\n );\n }\n const envelope =\n lensId === undefined ? await source.loadLensGroup(groupId) : await source.loadLens(lensId, groupId);\n\n return envelope instanceof ArrayBuffer || ArrayBuffer.isView(envelope)\n ? Envelope.decode(envelope instanceof Uint8Array ? envelope : new Uint8Array(envelope)).lenses\n : [];\n}\n"]}
1
+ {"version":3,"file":"LensSource.js","sourceRoot":"","sources":["../../src/lens/LensSource.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,mDAAmD,CAAC;AAgB7E;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,UAAU,CAAC,aAAa,EAAE,GAAiB,EAAE,CAAC,EAAE,CAAC,CAAC;AAEpF;;;;;GAKG;AACH,MAAM,UAAgB,qBAAqB,CAAC,OAAqB,EAAE,OAAe,EAAE,MAAe;;QAC/F,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;QACtE,IAAI,CAAC,MAAM,EAAE;YACT,MAAM,IAAI,KAAK,CACX,oBAAoB,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,QAAQ,CAAC,CAAC,CAAC,EAAE,SAAS,OAAO,sCAAsC;gBACrG,kBAAkB,CACzB,CAAC;SACL;QACD,MAAM,QAAQ,GACV,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAExG,OAAO,QAAQ,YAAY,WAAW,IAAI,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC;YAClE,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,YAAY,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM;YAC9F,CAAC,CAAC,EAAE,CAAC;IACb,CAAC;CAAA","sourcesContent":["import { Injectable } from \"../dependency-injection/Injectable\";\nimport { Envelope } from \"../generated-proto/pb_schema/camera_kit/v3/export\";\nimport { Lens } from \"../generated-proto/pb_schema/camera_kit/v3/lens\";\n\n/**\n * Provides Lens metadata for one or more Lens groups.\n *\n * When a Lens or Lens group is requested via the {@link LensRepository}, CameraKit will find the LensSource which\n * claims ownership of that group. The appropriate LensSource method will be called and must return an ArrayBuffer\n * containing the encoded Lens metadata -- this can be obtained from a CameraKit backend API.\n */\nexport interface LensSource {\n isGroupOwner(groupId: string): boolean;\n loadLens(lensId: string, groupId: string): Promise<ArrayBuffer>;\n loadLensGroup(groupId: string): Promise<ArrayBuffer>;\n}\n\n/**\n * By default, no custom {@link LensSource} is provided to CameraKit. But to enable certain advanced use-cases,\n * applications may provide their own {@link LensSource}.\n *\n * Perhaps the most convenient way to do this is with {@link ConcatInjectable}, as shown here:\n *\n * @example\n * ```ts\n * import { bootstrapCameraKit, lensSourcesFactory, LensSource } from '@snap/camera-kit'\n *\n * const cameraKit = bootstrapCameraKit(config, (container) => {\n * return container.provides(ConcatInjectable(\n * lensSourcesFactory.token,\n * (): LensSource => { return ... }\n * ))\n * })\n * ```\n */\nexport const lensSourcesFactory = Injectable(\"lensSources\", (): LensSource[] => []);\n\n/**\n * Given a list of LensSources (like the one provided by CameraKit's DI container under the `'lensSources'` token), and\n * a groupId/lensId, return a list of lenses loaded by the first LensSource claiming ownership of the given groupId.\n *\n * @internal\n */\nexport async function loadLensesFromSources(sources: LensSource[], groupId: string, lensId?: string): Promise<Lens[]> {\n const source = sources.find((source) => source.isGroupOwner(groupId));\n if (!source) {\n throw new Error(\n `Cannot load lens ${lensId ? `${lensId} from ` : \"\"}group ${groupId}. No LensSource claimed ownership of` +\n `that lens group.`\n );\n }\n const envelope =\n lensId === undefined ? await source.loadLensGroup(groupId) : await source.loadLens(lensId, groupId);\n\n return envelope instanceof ArrayBuffer || ArrayBuffer.isView(envelope)\n ? Envelope.decode(envelope instanceof Uint8Array ? envelope : new Uint8Array(envelope)).lenses\n : [];\n}\n"]}
@@ -1,8 +1,9 @@
1
1
  import { Lens } from "../Lens";
2
2
  import { RequestStateEventTarget } from "../../handlers/requestStateEmittingHandler";
3
3
  import { LensAssetManifestItem, LensAssetManifestItem_RequestTiming, LensAssetManifestItem_Type } from "../../generated-proto/pb_schema/camera_kit/v3/lens";
4
- import { AssetDescriptor, AssetType, LensCore } from "../../lens-core-module";
5
4
  import { MetricsEventTarget } from "../../metrics/metricsEventTarget";
5
+ import { AssetDescriptor, AssetType } from "../../lens-core-module/generated-types";
6
+ import { LensCore } from "../../lens-core-module/lensCore";
6
7
  export declare function mapManfiestItemToAssetType(lensCore: LensCore, type: LensAssetManifestItem_Type): AssetType;
7
8
  export interface Asset {
8
9
  assetId: string;
@@ -14,12 +15,42 @@ export type AssetResponse = ArrayBuffer | {
14
15
  data: ArrayBuffer;
15
16
  checksum?: string;
16
17
  };
18
+ /**
19
+ * Represents a request for loading assets through {@link AssetLoader}. This object specifies the asset to be loaded,
20
+ * optionally defines the lens context, includes an asset manifest if available, and indicates the priority of the load.
21
+ *
22
+ * @category Lenses
23
+ */
24
+ export interface LoadAssetRequest {
25
+ /**
26
+ * Describes the asset to be loaded.
27
+ */
28
+ assetDescriptor: AssetDescriptor;
29
+ /**
30
+ * Specifies the lens context for the asset load, if applicable.
31
+ */
32
+ lens: Lens | undefined;
33
+ /**
34
+ * Lens asset manifest.
35
+ */
36
+ assetManifest: LensAssetManifestItem[];
37
+ /**
38
+ * Indicates whether the asset fetch should be treated with lower priority compared to other
39
+ * network requests on the page. When set to true, this request may be deferred in favor of higher-priority
40
+ * traffic, potentially improving overall page responsiveness and load times for critical assets.
41
+ */
42
+ lowPriority: boolean;
43
+ }
17
44
  /**
18
45
  * An AssetLoader is used to retrieve assets. A separate loader may be defined to retrieve different asset types.
19
46
  *
20
47
  * @category Lenses
48
+ *
49
+ * @param request The {@link LoadAssetRequest} detailing the asset to be loaded, its context, and loading priority.
50
+ * @returns A promise that resolves to an {@link AssetResponse} for asynchronous loading,
51
+ * or an {@link AssetResponse} directly for synchronous operations.
21
52
  */
22
- export type AssetLoader = (asset: AssetDescriptor, lens?: Lens, assetManifest?: LensAssetManifestItem[]) => Promise<AssetResponse> | AssetResponse;
53
+ export type AssetLoader = (request: LoadAssetRequest) => Promise<AssetResponse> | AssetResponse;
23
54
  /**
24
55
  * Registers a remote asset provider function with a given instance of LensCore, and uses a provided mapping of asset
25
56
  * types to loading functions to acquire remote asset data and pass it to LensCore.
@@ -44,12 +75,12 @@ export declare class LensAssetRepository {
44
75
  * @returns Promise rejects if any required assets could not be loaded – if this occurs, it's very likely the Lens
45
76
  * with this manifest will not function.
46
77
  */
47
- cacheAssets(assetManifest: LensAssetManifestItem[], lens: Lens, assetTimings?: LensAssetManifestItem_RequestTiming[]): Promise<void>;
78
+ cacheAssets(assetManifest: LensAssetManifestItem[], lens: Lens, assetTimings?: LensAssetManifestItem_RequestTiming[], lowPriority?: boolean): Promise<void>;
48
79
  /**
49
80
  * Calls the correct asset loader to fetch the asset's data,
50
81
  * depending on the requested asset's type and provides that to LensCore.
51
82
  */
52
- loadAsset(assetDescriptor: AssetDescriptor, lens: Lens | undefined, assetManifest: LensAssetManifestItem[] | undefined): Promise<void>;
83
+ loadAsset(request: LoadAssetRequest): Promise<void>;
53
84
  /**
54
85
  * Downloads and caches assets if applicable. Does nothing for assets that are already in cache.
55
86
  * @param assetDescriptors Asset ID and type pairs.
@@ -2,11 +2,11 @@ import { __awaiter } from "tslib";
2
2
  import { Injectable } from "../../dependency-injection/Injectable";
3
3
  import { dispatchRequestCompleted, dispatchRequestErrored, dispatchRequestStarted, requestStateEventTargetFactory, } from "../../handlers/requestStateEmittingHandler";
4
4
  import { LensAssetManifestItem_RequestTiming, LensAssetManifestItem_Type, } from "../../generated-proto/pb_schema/camera_kit/v3/lens";
5
- import { lensCoreFactory } from "../../lens-core-module";
6
5
  import { assertUnreachable } from "../../common/assertions";
7
6
  import { getLogger } from "../../logger/logger";
8
7
  import { metricsEventTargetFactory } from "../../metrics/metricsEventTarget";
9
8
  import { TypedCustomEvent } from "../../events/TypedCustomEvent";
9
+ import { lensCoreFactory } from "../../lens-core-module/loader/lensCoreFactory";
10
10
  import { deviceDependentAssetLoaderFactory } from "./deviceDependentAssetLoader";
11
11
  import { remoteMediaAssetLoaderFactory } from "./remoteMediaAssetLoaderFactory";
12
12
  import { staticAssetLoaderFactory } from "./staticAssetLoader";
@@ -55,7 +55,7 @@ export class LensAssetRepository {
55
55
  * @returns Promise rejects if any required assets could not be loaded – if this occurs, it's very likely the Lens
56
56
  * with this manifest will not function.
57
57
  */
58
- cacheAssets(assetManifest, lens, assetTimings = [LensAssetManifestItem_RequestTiming.REQUIRED]) {
58
+ cacheAssets(assetManifest, lens, assetTimings = [LensAssetManifestItem_RequestTiming.REQUIRED], lowPriority = false) {
59
59
  return __awaiter(this, void 0, void 0, function* () {
60
60
  const assetTimingsToPreload = new Set([
61
61
  // That is a bad naming, but PRELOAD_UNSET actually means
@@ -74,7 +74,7 @@ export class LensAssetRepository {
74
74
  if (assetDescriptors.length) {
75
75
  // When preloading, we *do* want load failures to reject Promise.all (assets listed in the manifest
76
76
  // are known to be hard requirements of the lens).
77
- return this.cacheAssetsByDescriptor(assetDescriptors, lens, assetManifest);
77
+ return this.cacheAssetsByDescriptor(assetDescriptors, lens, assetManifest, lowPriority);
78
78
  }
79
79
  });
80
80
  }
@@ -82,10 +82,10 @@ export class LensAssetRepository {
82
82
  * Calls the correct asset loader to fetch the asset's data,
83
83
  * depending on the requested asset's type and provides that to LensCore.
84
84
  */
85
- loadAsset(assetDescriptor, lens, assetManifest) {
85
+ loadAsset(request) {
86
86
  var _a, _b;
87
87
  return __awaiter(this, void 0, void 0, function* () {
88
- const { assetId, assetType } = assetDescriptor;
88
+ const { assetDescriptor: { assetId, assetType }, lens, } = request;
89
89
  const [assetTypeName, assetLoader] = (_a = this.assetLoaders.get(assetType)) !== null && _a !== void 0 ? _a : [];
90
90
  const safeAssetTypeName = assetTypeName !== null && assetTypeName !== void 0 ? assetTypeName : "unknown";
91
91
  const dimensions = {
@@ -99,7 +99,7 @@ export class LensAssetRepository {
99
99
  if (!assetLoader) {
100
100
  throw new Error(`Cannot get asset ${assetId}. Asset type ${safeAssetTypeName} is not supported.`);
101
101
  }
102
- const assetResponse = yield assetLoader(assetDescriptor, lens, assetManifest);
102
+ const assetResponse = yield assetLoader(request);
103
103
  const assetBuffer = "data" in assetResponse ? assetResponse.data : assetResponse;
104
104
  const assetChecksum = "checksum" in assetResponse ? assetResponse.checksum : undefined;
105
105
  if (assetBuffer.byteLength === 0) {
@@ -140,7 +140,7 @@ export class LensAssetRepository {
140
140
  * @param lens Lens to load assets for.
141
141
  * @param assetManifest Lens asset manifest.
142
142
  */
143
- cacheAssetsByDescriptor(assetDescriptors, lens, assetManifest) {
143
+ cacheAssetsByDescriptor(assetDescriptors, lens, assetManifest, lowPriority) {
144
144
  return __awaiter(this, void 0, void 0, function* () {
145
145
  yield Promise.all(assetDescriptors
146
146
  .filter((assetDescriptors) => !this.cachedAssetKeys.has(getCacheKey(assetDescriptors)))
@@ -149,9 +149,9 @@ export class LensAssetRepository {
149
149
  try {
150
150
  // NOTE: we allow concurrent cache request to download the same asset more than once,
151
151
  // because that is better than skipping second request when the firs one fails.
152
- // In future we could improve concurretn logic with observables as part of
152
+ // In future we could improve concurrent logic with observables as part of
153
153
  // https://jira.sc-corp.net/browse/CAMKIT-3931
154
- yield this.loadAsset(assetDescriptor, lens, assetManifest);
154
+ yield this.loadAsset({ assetDescriptor, lens, assetManifest, lowPriority });
155
155
  this.cachedAssetKeys.add(getCacheKey(assetDescriptor));
156
156
  }
157
157
  catch (error) {
@@ -1 +1 @@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AM,EAAE,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAAC;CAC7D,CAAC,EACF,OAAO,EACP,uBAAuB,CAC1B,CACR,CAAC","sourcesContent":["import { Injectable } from \"../../dependency-injection/Injectable\";\nimport { Lens } from \"../Lens\";\nimport {\n RequestStateEventTarget,\n dispatchRequestCompleted,\n dispatchRequestErrored,\n dispatchRequestStarted,\n requestStateEventTargetFactory,\n} from \"../../handlers/requestStateEmittingHandler\";\nimport { AssetDownloadDimensions } from \"../../metrics/reporters/reportLensAndAssetDownload\";\nimport {\n LensAssetManifestItem,\n LensAssetManifestItem_RequestTiming,\n LensAssetManifestItem_Type,\n} from \"../../generated-proto/pb_schema/camera_kit/v3/lens\";\nimport { AssetDescriptor, AssetType, LensCore, lensCoreFactory } from \"../../lens-core-module\";\nimport { assertUnreachable } from \"../../common/assertions\";\nimport { getLogger } from \"../../logger/logger\";\nimport { MetricsEventTarget, metricsEventTargetFactory } from \"../../metrics/metricsEventTarget\";\nimport { TypedCustomEvent } from \"../../events/TypedCustomEvent\";\nimport { deviceDependentAssetLoaderFactory } from \"./deviceDependentAssetLoader\";\nimport { remoteMediaAssetLoaderFactory } from \"./remoteMediaAssetLoaderFactory\";\nimport { staticAssetLoaderFactory } from \"./staticAssetLoader\";\n\nconst logger = getLogger(\"LensAssetRepository\");\n\n/**\n * Computes cache key for asset ID and loader type pair.\n * @param asset Asset ID and loader type pair.\n * @returns Cache key.\n */\nfunction getCacheKey(asset: AssetDescriptor) {\n return `${asset.assetId}_${asset.assetType.value}`;\n}\n\nexport function mapManfiestItemToAssetType(lensCore: LensCore, type: LensAssetManifestItem_Type): AssetType {\n switch (type) {\n case LensAssetManifestItem_Type.ASSET:\n return lensCore.AssetType.Static;\n case LensAssetManifestItem_Type.DEVICE_DEPENDENT_ASSET_UNSET:\n case LensAssetManifestItem_Type.UNRECOGNIZED:\n return lensCore.AssetType.DeviceDependent;\n default:\n return assertUnreachable(type);\n }\n}\n\nexport interface Asset {\n assetId: string;\n assetBuffer: ArrayBuffer;\n assetType: AssetType;\n assetChecksum: string | undefined;\n}\n\nexport type AssetResponse =\n | ArrayBuffer\n | {\n data: ArrayBuffer;\n checksum?: string;\n };\n\n/**\n * An AssetLoader is used to retrieve assets. A separate loader may be defined to retrieve different asset types.\n *\n * @category Lenses\n */\nexport type AssetLoader = (\n asset: AssetDescriptor,\n lens?: Lens,\n assetManifest?: LensAssetManifestItem[]\n) => Promise<AssetResponse> | AssetResponse;\n\n/**\n * Registers a remote asset provider function with a given instance of LensCore, and uses a provided mapping of asset\n * types to loading functions to acquire remote asset data and pass it to LensCore.\n *\n * *Note:* LensCoreModule.initialize must be called on the desired LensCoreModule instance **prior** to passing it\n * to the LensAssetProvider 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 */\nexport class LensAssetRepository {\n private readonly cachedAssetKeys = new Set<string>();\n\n constructor(\n private readonly lensCore: LensCore,\n private readonly assetLoaders: Map<AssetType, [keyof LensCore[\"AssetType\"], AssetLoader]>,\n private readonly metrics: MetricsEventTarget,\n private readonly requestStateEventTarget: RequestStateEventTarget\n ) {}\n\n /**\n * Caches lens assets defined in asset manifest.\n *\n * @param assetManifest Lens asset manifest.\n * @param lens Lens to cache assets of.\n * @param assetTimings Optionally specifies what assets to cache. By default, on-demand assets are not cached.\n * @returns Promise rejects if any required assets could not be loaded – if this occurs, it's very likely the Lens\n * with this manifest will not function.\n */\n public async cacheAssets(\n assetManifest: LensAssetManifestItem[],\n lens: Lens,\n assetTimings: LensAssetManifestItem_RequestTiming[] = [LensAssetManifestItem_RequestTiming.REQUIRED]\n ): Promise<void> {\n const assetTimingsToPreload = new Set([\n // That is a bad naming, but PRELOAD_UNSET actually means\n // that an asset has to be preloaded\n LensAssetManifestItem_RequestTiming.PRELOAD_UNSET,\n ...assetTimings,\n ]);\n const assetDescriptors = assetManifest\n .filter((asset) => {\n return assetTimingsToPreload.has(asset.requestTiming);\n })\n .map(({ id, type }) => ({\n assetId: id,\n assetType: mapManfiestItemToAssetType(this.lensCore, type),\n }));\n\n if (assetDescriptors.length) {\n // When preloading, we *do* want load failures to reject Promise.all (assets listed in the manifest\n // are known to be hard requirements of the lens).\n return this.cacheAssetsByDescriptor(assetDescriptors, lens, assetManifest);\n }\n }\n\n /**\n * Calls the correct asset loader to fetch the asset's data,\n * depending on the requested asset's type and provides that to LensCore.\n */\n public async loadAsset(\n assetDescriptor: AssetDescriptor,\n lens: Lens | undefined,\n assetManifest: LensAssetManifestItem[] | undefined\n ): Promise<void> {\n const { assetId, assetType } = assetDescriptor;\n const [assetTypeName, assetLoader] = this.assetLoaders.get(assetType) ?? [];\n const safeAssetTypeName = assetTypeName ?? \"unknown\";\n const dimensions: AssetDownloadDimensions = {\n requestType: \"asset\",\n assetId: assetId,\n assetType: safeAssetTypeName,\n lensId: lens?.id ?? \"unknown\",\n };\n\n const { requestId } = dispatchRequestStarted(this.requestStateEventTarget, { dimensions });\n\n try {\n if (!assetLoader) {\n throw new Error(`Cannot get asset ${assetId}. Asset type ${safeAssetTypeName} is not supported.`);\n }\n\n const assetResponse = await assetLoader(assetDescriptor, lens, assetManifest);\n const assetBuffer = \"data\" in assetResponse ? assetResponse.data : assetResponse;\n const assetChecksum = \"checksum\" in assetResponse ? assetResponse.checksum : undefined;\n\n if (assetBuffer.byteLength === 0) {\n throw new Error(`Got empty response for asset ${assetId} from ${safeAssetTypeName} loader.`);\n }\n\n dispatchRequestCompleted(this.requestStateEventTarget, {\n requestId,\n dimensions,\n status: 200,\n sizeByte: assetBuffer.byteLength,\n });\n\n this.lensCore.provideRemoteAssetsResponse({\n assetId,\n assetBuffer,\n assetType,\n assetChecksum,\n onFailure: (lensCoreError) => {\n if (/validation failed/.test(lensCoreError.message)) {\n this.metrics.dispatchEvent(\n new TypedCustomEvent(\"assetValidationFailed\", {\n name: \"assetValidationFailed\",\n assetId,\n })\n );\n }\n logger.warn(`Failed to provide lens asset ${assetId}.`, lensCoreError);\n },\n });\n } catch (error) {\n const wrappedError = new Error(`Failed to load lens asset ${assetId}.`, { cause: error });\n dispatchRequestErrored(this.requestStateEventTarget, { requestId, dimensions, error: wrappedError });\n throw wrappedError;\n }\n }\n\n /**\n * Downloads and caches assets if applicable. Does nothing for assets that are already in cache.\n * @param assetDescriptors Asset ID and type pairs.\n * @param lens Lens to load assets for.\n * @param assetManifest Lens asset manifest.\n */\n private async cacheAssetsByDescriptor(\n assetDescriptors: AssetDescriptor[],\n lens: Lens,\n assetManifest: LensAssetManifestItem[] | undefined\n ): Promise<void> {\n await Promise.all(\n assetDescriptors\n .filter((assetDescriptors) => !this.cachedAssetKeys.has(getCacheKey(assetDescriptors)))\n .map(async (assetDescriptor) => {\n try {\n // NOTE: we allow concurrent cache request to download the same asset more than once,\n // because that is better than skipping second request when the firs one fails.\n // In future we could improve concurretn logic with observables as part of\n // https://jira.sc-corp.net/browse/CAMKIT-3931\n await this.loadAsset(assetDescriptor, lens, assetManifest);\n this.cachedAssetKeys.add(getCacheKey(assetDescriptor));\n } catch (error) {\n const { assetId, assetType } = assetDescriptor;\n const [assetTypeName] = this.assetLoaders.get(assetType) ?? [];\n logger.warn(\n `Failed to cache asset ${assetId} of type ${assetTypeName ?? assetType.value}.`,\n error\n );\n }\n })\n );\n }\n}\n\n/**\n * @internal\n */\nexport const lensAssetRepositoryFactory = Injectable(\n \"lensAssetRepository\",\n [\n lensCoreFactory.token,\n deviceDependentAssetLoaderFactory.token,\n remoteMediaAssetLoaderFactory.token,\n staticAssetLoaderFactory.token,\n metricsEventTargetFactory.token,\n requestStateEventTargetFactory.token,\n ] as const,\n (\n lensCore: LensCore,\n deviceDependentAssetLoader: AssetLoader,\n remoteMediaAssetLoader: AssetLoader,\n staticAssetLoader: AssetLoader,\n metrics: MetricsEventTarget,\n requestStateEventTarget: RequestStateEventTarget\n ) =>\n new LensAssetRepository(\n lensCore,\n new Map([\n [lensCore.AssetType.DeviceDependent, [\"DeviceDependent\", deviceDependentAssetLoader]],\n [lensCore.AssetType.RemoteMediaByUrl, [\"RemoteMediaByUrl\", remoteMediaAssetLoader]],\n // URL type is deprecated and was introduced before RemoteMediaByURL\n // however, there are some lenses still using it so we need to support it\n [lensCore.AssetType.URL, [\"URL\", remoteMediaAssetLoader]],\n [lensCore.AssetType.Static, [\"Static\", staticAssetLoader]],\n ]),\n metrics,\n requestStateEventTarget\n )\n);\n"]}
1
+ {"version":3,"file":"LensAssetRepository.js","sourceRoot":"","sources":["../../../src/lens/assets/LensAssetRepository.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AAEnE,OAAO,EAEH,wBAAwB,EACxB,sBAAsB,EACtB,sBAAsB,EACtB,8BAA8B,GACjC,MAAM,4CAA4C,CAAC;AAEpD,OAAO,EAEH,mCAAmC,EACnC,0BAA0B,GAC7B,MAAM,oDAAoD,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAsB,yBAAyB,EAAE,MAAM,kCAAkC,CAAC;AACjG,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAGjE,OAAO,EAAE,eAAe,EAAE,MAAM,+CAA+C,CAAC;AAChF,OAAO,EAAE,iCAAiC,EAAE,MAAM,8BAA8B,CAAC;AACjF,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAE/D,MAAM,MAAM,GAAG,SAAS,CAAC,qBAAqB,CAAC,CAAC;AAEhD;;;;GAIG;AACH,SAAS,WAAW,CAAC,KAAsB;IACvC,OAAO,GAAG,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;AACvD,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,QAAkB,EAAE,IAAgC;IA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e,EAAE,CAAC,iBAAiB,EAAE,0BAA0B,CAAC,CAAC;IACrF,CAAC,QAAQ,CAAC,SAAS,CAAC,gBAAgB,EAAE,CAAC,kBAAkB,EAAE,sBAAsB,CAAC,CAAC;IACnF,oEAAoE;IACpE,yEAAyE;IACzE,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,sBAAsB,CAAC,CAAC;IACzD,CAAC,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAAC;CAC7D,CAAC,EACF,OAAO,EACP,uBAAuB,CAC1B,CACR,CAAC","sourcesContent":["import { Injectable } from \"../../dependency-injection/Injectable\";\nimport { Lens } from \"../Lens\";\nimport {\n RequestStateEventTarget,\n dispatchRequestCompleted,\n dispatchRequestErrored,\n dispatchRequestStarted,\n requestStateEventTargetFactory,\n} from \"../../handlers/requestStateEmittingHandler\";\nimport { AssetDownloadDimensions } from \"../../metrics/reporters/reportLensAndAssetDownload\";\nimport {\n LensAssetManifestItem,\n LensAssetManifestItem_RequestTiming,\n LensAssetManifestItem_Type,\n} from \"../../generated-proto/pb_schema/camera_kit/v3/lens\";\nimport { assertUnreachable } from \"../../common/assertions\";\nimport { getLogger } from \"../../logger/logger\";\nimport { MetricsEventTarget, metricsEventTargetFactory } from \"../../metrics/metricsEventTarget\";\nimport { TypedCustomEvent } from \"../../events/TypedCustomEvent\";\nimport { AssetDescriptor, AssetType } from \"../../lens-core-module/generated-types\";\nimport { LensCore } from \"../../lens-core-module/lensCore\";\nimport { lensCoreFactory } from \"../../lens-core-module/loader/lensCoreFactory\";\nimport { deviceDependentAssetLoaderFactory } from \"./deviceDependentAssetLoader\";\nimport { remoteMediaAssetLoaderFactory } from \"./remoteMediaAssetLoaderFactory\";\nimport { staticAssetLoaderFactory } from \"./staticAssetLoader\";\n\nconst logger = getLogger(\"LensAssetRepository\");\n\n/**\n * Computes cache key for asset ID and loader type pair.\n * @param asset Asset ID and loader type pair.\n * @returns Cache key.\n */\nfunction getCacheKey(asset: AssetDescriptor) {\n return `${asset.assetId}_${asset.assetType.value}`;\n}\n\nexport function mapManfiestItemToAssetType(lensCore: LensCore, type: LensAssetManifestItem_Type): AssetType {\n switch (type) {\n case LensAssetManifestItem_Type.ASSET:\n return lensCore.AssetType.Static;\n case LensAssetManifestItem_Type.DEVICE_DEPENDENT_ASSET_UNSET:\n case LensAssetManifestItem_Type.UNRECOGNIZED:\n return lensCore.AssetType.DeviceDependent;\n default:\n return assertUnreachable(type);\n }\n}\n\nexport interface Asset {\n assetId: string;\n assetBuffer: ArrayBuffer;\n assetType: AssetType;\n assetChecksum: string | undefined;\n}\n\nexport type AssetResponse =\n | ArrayBuffer\n | {\n data: ArrayBuffer;\n checksum?: string;\n };\n\n/**\n * Represents a request for loading assets through {@link AssetLoader}. This object specifies the asset to be loaded,\n * optionally defines the lens context, includes an asset manifest if available, and indicates the priority of the load.\n *\n * @category Lenses\n */\nexport interface LoadAssetRequest {\n /**\n * Describes the asset to be loaded.\n */\n assetDescriptor: AssetDescriptor;\n\n /**\n * Specifies the lens context for the asset load, if applicable.\n */\n lens: Lens | undefined;\n\n /**\n * Lens asset manifest.\n */\n assetManifest: LensAssetManifestItem[];\n\n /**\n * Indicates whether the asset fetch should be treated with lower priority compared to other\n * network requests on the page. When set to true, this request may be deferred in favor of higher-priority\n * traffic, potentially improving overall page responsiveness and load times for critical assets.\n */\n lowPriority: boolean;\n}\n\n/**\n * An AssetLoader is used to retrieve assets. A separate loader may be defined to retrieve different asset types.\n *\n * @category Lenses\n *\n * @param request The {@link LoadAssetRequest} detailing the asset to be loaded, its context, and loading priority.\n * @returns A promise that resolves to an {@link AssetResponse} for asynchronous loading,\n * or an {@link AssetResponse} directly for synchronous operations.\n */\nexport type AssetLoader = (request: LoadAssetRequest) => Promise<AssetResponse> | AssetResponse;\n\n/**\n * Registers a remote asset provider function with a given instance of LensCore, and uses a provided mapping of asset\n * types to loading functions to acquire remote asset data and pass it to LensCore.\n *\n * *Note:* LensCoreModule.initialize must be called on the desired LensCoreModule instance **prior** to passing it\n * to the LensAssetProvider 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 */\nexport class LensAssetRepository {\n private readonly cachedAssetKeys = new Set<string>();\n\n constructor(\n private readonly lensCore: LensCore,\n private readonly assetLoaders: Map<AssetType, [keyof LensCore[\"AssetType\"], AssetLoader]>,\n private readonly metrics: MetricsEventTarget,\n private readonly requestStateEventTarget: RequestStateEventTarget\n ) {}\n\n /**\n * Caches lens assets defined in asset manifest.\n *\n * @param assetManifest Lens asset manifest.\n * @param lens Lens to cache assets of.\n * @param assetTimings Optionally specifies what assets to cache. By default, on-demand assets are not cached.\n * @returns Promise rejects if any required assets could not be loaded – if this occurs, it's very likely the Lens\n * with this manifest will not function.\n */\n public async cacheAssets(\n assetManifest: LensAssetManifestItem[],\n lens: Lens,\n assetTimings: LensAssetManifestItem_RequestTiming[] = [LensAssetManifestItem_RequestTiming.REQUIRED],\n lowPriority: boolean = false\n ): Promise<void> {\n const assetTimingsToPreload = new Set([\n // That is a bad naming, but PRELOAD_UNSET actually means\n // that an asset has to be preloaded\n LensAssetManifestItem_RequestTiming.PRELOAD_UNSET,\n ...assetTimings,\n ]);\n const assetDescriptors = assetManifest\n .filter((asset) => {\n return assetTimingsToPreload.has(asset.requestTiming);\n })\n .map(({ id, type }) => ({\n assetId: id,\n assetType: mapManfiestItemToAssetType(this.lensCore, type),\n }));\n\n if (assetDescriptors.length) {\n // When preloading, we *do* want load failures to reject Promise.all (assets listed in the manifest\n // are known to be hard requirements of the lens).\n return this.cacheAssetsByDescriptor(assetDescriptors, lens, assetManifest, lowPriority);\n }\n }\n\n /**\n * Calls the correct asset loader to fetch the asset's data,\n * depending on the requested asset's type and provides that to LensCore.\n */\n public async loadAsset(request: LoadAssetRequest): Promise<void> {\n const {\n assetDescriptor: { assetId, assetType },\n lens,\n } = request;\n const [assetTypeName, assetLoader] = this.assetLoaders.get(assetType) ?? [];\n const safeAssetTypeName = assetTypeName ?? \"unknown\";\n const dimensions: AssetDownloadDimensions = {\n requestType: \"asset\",\n assetId: assetId,\n assetType: safeAssetTypeName,\n lensId: lens?.id ?? \"unknown\",\n };\n\n const { requestId } = dispatchRequestStarted(this.requestStateEventTarget, { dimensions });\n\n try {\n if (!assetLoader) {\n throw new Error(`Cannot get asset ${assetId}. Asset type ${safeAssetTypeName} is not supported.`);\n }\n\n const assetResponse = await assetLoader(request);\n const assetBuffer = \"data\" in assetResponse ? assetResponse.data : assetResponse;\n const assetChecksum = \"checksum\" in assetResponse ? assetResponse.checksum : undefined;\n\n if (assetBuffer.byteLength === 0) {\n throw new Error(`Got empty response for asset ${assetId} from ${safeAssetTypeName} loader.`);\n }\n\n dispatchRequestCompleted(this.requestStateEventTarget, {\n requestId,\n dimensions,\n status: 200,\n sizeByte: assetBuffer.byteLength,\n });\n\n this.lensCore.provideRemoteAssetsResponse({\n assetId,\n assetBuffer,\n assetType,\n assetChecksum,\n onFailure: (lensCoreError) => {\n if (/validation failed/.test(lensCoreError.message)) {\n this.metrics.dispatchEvent(\n new TypedCustomEvent(\"assetValidationFailed\", {\n name: \"assetValidationFailed\",\n assetId,\n })\n );\n }\n logger.warn(`Failed to provide lens asset ${assetId}.`, lensCoreError);\n },\n });\n } catch (error) {\n const wrappedError = new Error(`Failed to load lens asset ${assetId}.`, { cause: error });\n dispatchRequestErrored(this.requestStateEventTarget, { requestId, dimensions, error: wrappedError });\n throw wrappedError;\n }\n }\n\n /**\n * Downloads and caches assets if applicable. Does nothing for assets that are already in cache.\n * @param assetDescriptors Asset ID and type pairs.\n * @param lens Lens to load assets for.\n * @param assetManifest Lens asset manifest.\n */\n private async cacheAssetsByDescriptor(\n assetDescriptors: AssetDescriptor[],\n lens: Lens,\n assetManifest: LensAssetManifestItem[],\n lowPriority: boolean\n ): Promise<void> {\n await Promise.all(\n assetDescriptors\n .filter((assetDescriptors) => !this.cachedAssetKeys.has(getCacheKey(assetDescriptors)))\n .map(async (assetDescriptor) => {\n try {\n // NOTE: we allow concurrent cache request to download the same asset more than once,\n // because that is better than skipping second request when the firs one fails.\n // In future we could improve concurrent logic with observables as part of\n // https://jira.sc-corp.net/browse/CAMKIT-3931\n await this.loadAsset({ assetDescriptor, lens, assetManifest, lowPriority });\n this.cachedAssetKeys.add(getCacheKey(assetDescriptor));\n } catch (error) {\n const { assetId, assetType } = assetDescriptor;\n const [assetTypeName] = this.assetLoaders.get(assetType) ?? [];\n logger.warn(\n `Failed to cache asset ${assetId} of type ${assetTypeName ?? assetType.value}.`,\n error\n );\n }\n })\n );\n }\n}\n\n/**\n * @internal\n */\nexport const lensAssetRepositoryFactory = Injectable(\n \"lensAssetRepository\",\n [\n lensCoreFactory.token,\n deviceDependentAssetLoaderFactory.token,\n remoteMediaAssetLoaderFactory.token,\n staticAssetLoaderFactory.token,\n metricsEventTargetFactory.token,\n requestStateEventTargetFactory.token,\n ] as const,\n (\n lensCore: LensCore,\n deviceDependentAssetLoader: AssetLoader,\n remoteMediaAssetLoader: AssetLoader,\n staticAssetLoader: AssetLoader,\n metrics: MetricsEventTarget,\n requestStateEventTarget: RequestStateEventTarget\n ) =>\n new LensAssetRepository(\n lensCore,\n new Map([\n [lensCore.AssetType.DeviceDependent, [\"DeviceDependent\", deviceDependentAssetLoader]],\n [lensCore.AssetType.RemoteMediaByUrl, [\"RemoteMediaByUrl\", remoteMediaAssetLoader]],\n // URL type is deprecated and was introduced before RemoteMediaByURL\n // however, there are some lenses still using it so we need to support it\n [lensCore.AssetType.URL, [\"URL\", remoteMediaAssetLoader]],\n [lensCore.AssetType.Static, [\"Static\", staticAssetLoader]],\n ]),\n metrics,\n requestStateEventTarget\n )\n);\n"]}
@@ -1,6 +1,6 @@
1
- import { LensCore } from "../../lens-core-module";
2
1
  import { MakeTaggedBusinessEvent } from "../../metrics/businessEventsReporter";
3
2
  import { LensRepository } from "../LensRepository";
3
+ import { LensCore } from "../../lens-core-module/lensCore";
4
4
  import { LensAssetRepository } from "./LensAssetRepository";
5
5
  /**
6
6
  * The AssetValidationFailed metric reports every time we handle an asset checksum validation failure.