@snap/camera-kit 0.18.1 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (324) hide show
  1. package/README.md +1 -1
  2. package/dist/CameraKit.d.ts +2 -2
  3. package/dist/bootstrapCameraKit.d.ts.map +1 -1
  4. package/dist/bootstrapCameraKit.js +3 -1
  5. package/dist/bootstrapCameraKit.js.map +1 -1
  6. package/dist/clients/grpcHandler.d.ts +9 -3
  7. package/dist/clients/grpcHandler.d.ts.map +1 -1
  8. package/dist/clients/grpcHandler.js +20 -3
  9. package/dist/clients/grpcHandler.js.map +1 -1
  10. package/dist/dependency-injection/RootServices.d.ts +2 -0
  11. package/dist/dependency-injection/RootServices.d.ts.map +1 -1
  12. package/dist/dependency-injection/RootServices.js.map +1 -1
  13. package/dist/environment.js +1 -1
  14. package/dist/environment.js.map +1 -1
  15. package/dist/generated-proto/pb_schema/camera_kit/v3/remote_api_spec.d.ts +644 -0
  16. package/dist/generated-proto/pb_schema/camera_kit/v3/remote_api_spec.d.ts.map +1 -0
  17. package/dist/generated-proto/pb_schema/camera_kit/v3/remote_api_spec.js +320 -0
  18. package/dist/generated-proto/pb_schema/camera_kit/v3/remote_api_spec.js.map +1 -0
  19. package/dist/generated-proto/pb_schema/cdp/cof/app_launch_type.d.ts +10 -0
  20. package/dist/generated-proto/pb_schema/cdp/cof/app_launch_type.d.ts.map +1 -0
  21. package/dist/generated-proto/pb_schema/cdp/cof/app_launch_type.js +17 -0
  22. package/dist/generated-proto/pb_schema/cdp/cof/app_launch_type.js.map +1 -0
  23. package/dist/generated-proto/pb_schema/cdp/cof/billboard_provided_signals.d.ts +167 -0
  24. package/dist/generated-proto/pb_schema/cdp/cof/billboard_provided_signals.d.ts.map +1 -0
  25. package/dist/generated-proto/pb_schema/cdp/cof/billboard_provided_signals.js +423 -0
  26. package/dist/generated-proto/pb_schema/cdp/cof/billboard_provided_signals.js.map +1 -0
  27. package/dist/generated-proto/pb_schema/cdp/cof/bolt_provided_signals.d.ts +34 -0
  28. package/dist/generated-proto/pb_schema/cdp/cof/bolt_provided_signals.d.ts.map +1 -0
  29. package/dist/generated-proto/pb_schema/cdp/cof/bolt_provided_signals.js +63 -0
  30. package/dist/generated-proto/pb_schema/cdp/cof/bolt_provided_signals.js.map +1 -0
  31. package/dist/generated-proto/pb_schema/cdp/cof/camera_provided_signals.d.ts +109 -0
  32. package/dist/generated-proto/pb_schema/cdp/cof/camera_provided_signals.d.ts.map +1 -0
  33. package/dist/generated-proto/pb_schema/cdp/cof/camera_provided_signals.js +192 -0
  34. package/dist/generated-proto/pb_schema/cdp/cof/camera_provided_signals.js.map +1 -0
  35. package/dist/generated-proto/pb_schema/cdp/cof/circumstance_service.d.ts +3203 -0
  36. package/dist/generated-proto/pb_schema/cdp/cof/circumstance_service.d.ts.map +1 -1
  37. package/dist/generated-proto/pb_schema/cdp/cof/circumstance_service.js +290 -0
  38. package/dist/generated-proto/pb_schema/cdp/cof/circumstance_service.js.map +1 -1
  39. package/dist/generated-proto/pb_schema/cdp/cof/cognac_provided_signals.d.ts +24 -0
  40. package/dist/generated-proto/pb_schema/cdp/cof/cognac_provided_signals.d.ts.map +1 -0
  41. package/dist/generated-proto/pb_schema/cdp/cof/cognac_provided_signals.js +42 -0
  42. package/dist/generated-proto/pb_schema/cdp/cof/cognac_provided_signals.js.map +1 -0
  43. package/dist/generated-proto/pb_schema/cdp/cof/config_request.d.ts +24 -0
  44. package/dist/generated-proto/pb_schema/cdp/cof/config_request.d.ts.map +1 -1
  45. package/dist/generated-proto/pb_schema/cdp/cof/config_request.js +54 -1
  46. package/dist/generated-proto/pb_schema/cdp/cof/config_request.js.map +1 -1
  47. package/dist/generated-proto/pb_schema/cdp/cof/config_response.d.ts +97 -0
  48. package/dist/generated-proto/pb_schema/cdp/cof/config_response.d.ts.map +1 -1
  49. package/dist/generated-proto/pb_schema/cdp/cof/config_result.d.ts +277 -0
  50. package/dist/generated-proto/pb_schema/cdp/cof/config_result.d.ts.map +1 -1
  51. package/dist/generated-proto/pb_schema/cdp/cof/config_result.js +39 -2
  52. package/dist/generated-proto/pb_schema/cdp/cof/config_result.js.map +1 -1
  53. package/dist/generated-proto/pb_schema/cdp/cof/contact_authorization_status.d.ts +11 -0
  54. package/dist/generated-proto/pb_schema/cdp/cof/contact_authorization_status.d.ts.map +1 -0
  55. package/dist/generated-proto/pb_schema/cdp/cof/contact_authorization_status.js +18 -0
  56. package/dist/generated-proto/pb_schema/cdp/cof/contact_authorization_status.js.map +1 -0
  57. package/dist/generated-proto/pb_schema/cdp/cof/content_manager_provided_signals.d.ts +89 -0
  58. package/dist/generated-proto/pb_schema/cdp/cof/content_manager_provided_signals.d.ts.map +1 -0
  59. package/dist/generated-proto/pb_schema/cdp/cof/content_manager_provided_signals.js +108 -0
  60. package/dist/generated-proto/pb_schema/cdp/cof/content_manager_provided_signals.js.map +1 -0
  61. package/dist/generated-proto/pb_schema/cdp/cof/creative_tools_provided_signals.d.ts +27 -0
  62. package/dist/generated-proto/pb_schema/cdp/cof/creative_tools_provided_signals.d.ts.map +1 -0
  63. package/dist/generated-proto/pb_schema/cdp/cof/creative_tools_provided_signals.js +49 -0
  64. package/dist/generated-proto/pb_schema/cdp/cof/creative_tools_provided_signals.js.map +1 -0
  65. package/dist/generated-proto/pb_schema/cdp/cof/feature_provided_signals.d.ts +1184 -0
  66. package/dist/generated-proto/pb_schema/cdp/cof/feature_provided_signals.d.ts.map +1 -0
  67. package/dist/generated-proto/pb_schema/cdp/cof/feature_provided_signals.js +507 -0
  68. package/dist/generated-proto/pb_schema/cdp/cof/feature_provided_signals.js.map +1 -0
  69. package/dist/generated-proto/pb_schema/cdp/cof/lenses_provided_signals.d.ts +30 -0
  70. package/dist/generated-proto/pb_schema/cdp/cof/lenses_provided_signals.d.ts.map +1 -0
  71. package/dist/generated-proto/pb_schema/cdp/cof/lenses_provided_signals.js +59 -0
  72. package/dist/generated-proto/pb_schema/cdp/cof/lenses_provided_signals.js.map +1 -0
  73. package/dist/generated-proto/pb_schema/cdp/cof/mdp_media_attribution.d.ts +29 -0
  74. package/dist/generated-proto/pb_schema/cdp/cof/mdp_media_attribution.d.ts.map +1 -0
  75. package/dist/generated-proto/pb_schema/cdp/cof/mdp_media_attribution.js +49 -0
  76. package/dist/generated-proto/pb_schema/cdp/cof/mdp_media_attribution.js.map +1 -0
  77. package/dist/generated-proto/pb_schema/cdp/cof/media_provided_signals.d.ts +35 -0
  78. package/dist/generated-proto/pb_schema/cdp/cof/media_provided_signals.d.ts.map +1 -0
  79. package/dist/generated-proto/pb_schema/cdp/cof/media_provided_signals.js +58 -0
  80. package/dist/generated-proto/pb_schema/cdp/cof/media_provided_signals.js.map +1 -0
  81. package/dist/generated-proto/pb_schema/cdp/cof/opera_provided_signals.d.ts +30 -0
  82. package/dist/generated-proto/pb_schema/cdp/cof/opera_provided_signals.d.ts.map +1 -0
  83. package/dist/generated-proto/pb_schema/cdp/cof/opera_provided_signals.js +56 -0
  84. package/dist/generated-proto/pb_schema/cdp/cof/opera_provided_signals.js.map +1 -0
  85. package/dist/generated-proto/pb_schema/cdp/cof/perception_provided_signals.d.ts +24 -0
  86. package/dist/generated-proto/pb_schema/cdp/cof/perception_provided_signals.d.ts.map +1 -0
  87. package/dist/generated-proto/pb_schema/cdp/cof/perception_provided_signals.js +42 -0
  88. package/dist/generated-proto/pb_schema/cdp/cof/perception_provided_signals.js.map +1 -0
  89. package/dist/generated-proto/pb_schema/cdp/cof/recipients_provided_signals.d.ts +24 -0
  90. package/dist/generated-proto/pb_schema/cdp/cof/recipients_provided_signals.d.ts.map +1 -0
  91. package/dist/generated-proto/pb_schema/cdp/cof/recipients_provided_signals.js +42 -0
  92. package/dist/generated-proto/pb_schema/cdp/cof/recipients_provided_signals.js.map +1 -0
  93. package/dist/generated-proto/pb_schema/cdp/cof/routing_provided_signals.d.ts +24 -0
  94. package/dist/generated-proto/pb_schema/cdp/cof/routing_provided_signals.d.ts.map +1 -0
  95. package/dist/generated-proto/pb_schema/cdp/cof/routing_provided_signals.js +42 -0
  96. package/dist/generated-proto/pb_schema/cdp/cof/routing_provided_signals.js.map +1 -0
  97. package/dist/generated-proto/pb_schema/cdp/cof/snap_kit_provided_signals.d.ts +24 -0
  98. package/dist/generated-proto/pb_schema/cdp/cof/snap_kit_provided_signals.d.ts.map +1 -0
  99. package/dist/generated-proto/pb_schema/cdp/cof/snap_kit_provided_signals.js +42 -0
  100. package/dist/generated-proto/pb_schema/cdp/cof/snap_kit_provided_signals.js.map +1 -0
  101. package/dist/generated-proto/pb_schema/cdp/cof/upload_provided_signals.d.ts +40 -0
  102. package/dist/generated-proto/pb_schema/cdp/cof/upload_provided_signals.d.ts.map +1 -0
  103. package/dist/generated-proto/pb_schema/cdp/cof/upload_provided_signals.js +71 -0
  104. package/dist/generated-proto/pb_schema/cdp/cof/upload_provided_signals.js.map +1 -0
  105. package/dist/generated-proto/pb_schema/cdp/media/snap_source.d.ts +14 -0
  106. package/dist/generated-proto/pb_schema/cdp/media/snap_source.d.ts.map +1 -0
  107. package/dist/generated-proto/pb_schema/cdp/media/snap_source.js +21 -0
  108. package/dist/generated-proto/pb_schema/cdp/media/snap_source.js.map +1 -0
  109. package/dist/generated-proto/pb_schema/content/asset.d.ts +51 -0
  110. package/dist/generated-proto/pb_schema/content/asset.d.ts.map +1 -0
  111. package/dist/generated-proto/pb_schema/content/asset.js +74 -0
  112. package/dist/generated-proto/pb_schema/content/asset.js.map +1 -0
  113. package/dist/generated-proto/pb_schema/content/media_reference.d.ts +103 -0
  114. package/dist/generated-proto/pb_schema/content/media_reference.d.ts.map +1 -0
  115. package/dist/generated-proto/pb_schema/content/media_reference.js +183 -0
  116. package/dist/generated-proto/pb_schema/content/media_reference.js.map +1 -0
  117. package/dist/generated-proto/pb_schema/content/media_source.d.ts +19 -0
  118. package/dist/generated-proto/pb_schema/content/media_source.d.ts.map +1 -0
  119. package/dist/generated-proto/pb_schema/content/media_source.js +26 -0
  120. package/dist/generated-proto/pb_schema/content/media_source.js.map +1 -0
  121. package/dist/generated-proto/pb_schema/content/media_types.d.ts +63 -0
  122. package/dist/generated-proto/pb_schema/content/media_types.d.ts.map +1 -0
  123. package/dist/generated-proto/pb_schema/content/media_types.js +71 -0
  124. package/dist/generated-proto/pb_schema/content/media_types.js.map +1 -0
  125. package/dist/generated-proto/pb_schema/lenses/launchdata.d.ts +3 -0
  126. package/dist/generated-proto/pb_schema/lenses/launchdata.d.ts.map +1 -1
  127. package/dist/generated-proto/pb_schema/lenses/launchdata.js +20 -1
  128. package/dist/generated-proto/pb_schema/lenses/launchdata.js.map +1 -1
  129. package/dist/generated-proto/pb_schema/lenses/remote_api/remote_api_spec.d.ts +2983 -0
  130. package/dist/generated-proto/pb_schema/lenses/remote_api/remote_api_spec.d.ts.map +1 -0
  131. package/dist/generated-proto/pb_schema/lenses/remote_api/remote_api_spec.js +2107 -0
  132. package/dist/generated-proto/pb_schema/lenses/remote_api/remote_api_spec.js.map +1 -0
  133. package/dist/generated-proto/pb_schema/snapdoc/capture_characteristics.d.ts +27 -0
  134. package/dist/generated-proto/pb_schema/snapdoc/capture_characteristics.d.ts.map +1 -0
  135. package/dist/generated-proto/pb_schema/snapdoc/capture_characteristics.js +49 -0
  136. package/dist/generated-proto/pb_schema/snapdoc/capture_characteristics.js.map +1 -0
  137. package/dist/generated-proto/pb_schema/snapdoc/extensions.d.ts +31 -0
  138. package/dist/generated-proto/pb_schema/snapdoc/extensions.d.ts.map +1 -0
  139. package/dist/generated-proto/pb_schema/snapdoc/extensions.js +56 -0
  140. package/dist/generated-proto/pb_schema/snapdoc/extensions.js.map +1 -0
  141. package/dist/generated-proto/pb_schema/snapdoc/media.d.ts +703 -0
  142. package/dist/generated-proto/pb_schema/snapdoc/media.d.ts.map +1 -0
  143. package/dist/generated-proto/pb_schema/snapdoc/media.js +992 -0
  144. package/dist/generated-proto/pb_schema/snapdoc/media.js.map +1 -0
  145. package/dist/generated-proto/pb_schema/snapdoc/media_codec_formats.d.ts +27 -0
  146. package/dist/generated-proto/pb_schema/snapdoc/media_codec_formats.d.ts.map +1 -0
  147. package/dist/generated-proto/pb_schema/snapdoc/media_codec_formats.js +36 -0
  148. package/dist/generated-proto/pb_schema/snapdoc/media_codec_formats.js.map +1 -0
  149. package/dist/generated-proto/pb_schema/snapdoc/media_file_formats.d.ts +8 -0
  150. package/dist/generated-proto/pb_schema/snapdoc/media_file_formats.d.ts.map +1 -0
  151. package/dist/generated-proto/pb_schema/snapdoc/media_file_formats.js +15 -0
  152. package/dist/generated-proto/pb_schema/snapdoc/media_file_formats.js.map +1 -0
  153. package/dist/generated-proto/pb_schema/snapdoc/media_id.d.ts +24 -0
  154. package/dist/generated-proto/pb_schema/snapdoc/media_id.d.ts.map +1 -0
  155. package/dist/generated-proto/pb_schema/snapdoc/media_id.js +45 -0
  156. package/dist/generated-proto/pb_schema/snapdoc/media_id.js.map +1 -0
  157. package/dist/generated-proto/pb_schema/snapdoc/snap_component_type.d.ts +68 -0
  158. package/dist/generated-proto/pb_schema/snapdoc/snap_component_type.d.ts.map +1 -0
  159. package/dist/generated-proto/pb_schema/snapdoc/snap_component_type.js +66 -0
  160. package/dist/generated-proto/pb_schema/snapdoc/snap_component_type.js.map +1 -0
  161. package/dist/index.d.ts +1 -0
  162. package/dist/index.d.ts.map +1 -1
  163. package/dist/index.js +1 -0
  164. package/dist/index.js.map +1 -1
  165. package/dist/lens-client-interface/filePicker.d.ts +31 -0
  166. package/dist/lens-client-interface/filePicker.d.ts.map +1 -0
  167. package/dist/lens-client-interface/filePicker.js +3 -0
  168. package/dist/lens-client-interface/filePicker.js.map +1 -0
  169. package/dist/lens-client-interface/imagePicker.d.ts +2 -1
  170. package/dist/lens-client-interface/imagePicker.d.ts.map +1 -1
  171. package/dist/lens-client-interface/imagePicker.js +6 -3
  172. package/dist/lens-client-interface/imagePicker.js.map +1 -1
  173. package/dist/lens-client-interface/lensClientInterface.d.ts +3 -2
  174. package/dist/lens-client-interface/lensClientInterface.d.ts.map +1 -1
  175. package/dist/lens-client-interface/lensClientInterface.js +3 -2
  176. package/dist/lens-client-interface/lensClientInterface.js.map +1 -1
  177. package/dist/lens-core-module/loader/lensCoreFactory.d.ts +9 -2
  178. package/dist/lens-core-module/loader/lensCoreFactory.d.ts.map +1 -1
  179. package/dist/lens-core-module/loader/lensCoreFactory.js +18 -6
  180. package/dist/lens-core-module/loader/lensCoreFactory.js.map +1 -1
  181. package/dist/lensCoreWasmVersions.js +3 -3
  182. package/dist/lensCoreWasmVersions.js.map +1 -1
  183. package/dist/metrics/reporters/reportHttpMetrics.d.ts +5 -1
  184. package/dist/metrics/reporters/reportHttpMetrics.d.ts.map +1 -1
  185. package/dist/metrics/reporters/reportHttpMetrics.js +21 -15
  186. package/dist/metrics/reporters/reportHttpMetrics.js.map +1 -1
  187. package/dist/metrics/reporters/reporters.d.ts +1 -1
  188. package/dist/remote-configuration/cofHandler.d.ts.map +1 -1
  189. package/dist/remote-configuration/cofHandler.js +1 -1
  190. package/dist/remote-configuration/cofHandler.js.map +1 -1
  191. package/docs/html/assets/navigation.js +1 -1
  192. package/docs/html/assets/search.js +1 -1
  193. package/docs/html/classes/CameraKit.html +2 -2
  194. package/docs/html/classes/CameraKitSession.html +2 -2
  195. package/docs/html/classes/CameraKitSource.html +2 -2
  196. package/docs/html/classes/LensPerformanceMeasurement.html +2 -2
  197. package/docs/html/classes/LensPerformanceMetrics.html +2 -2
  198. package/docs/html/classes/LensRepository.html +2 -2
  199. package/docs/html/classes/Transform2D.html +2 -2
  200. package/docs/html/classes/TypedCustomEvent.html +2 -2
  201. package/docs/html/classes/TypedEventTarget.html +2 -2
  202. package/docs/html/enums/Lens_CameraFacing.html +2 -2
  203. package/docs/html/functions/ConcatInjectable.html +2 -2
  204. package/docs/html/functions/Injectable.html +2 -2
  205. package/docs/html/functions/bootstrapCameraKit.html +2 -2
  206. package/docs/html/functions/createExtension.html +2 -2
  207. package/docs/html/functions/createImageSource.html +2 -2
  208. package/docs/html/functions/createMediaStreamSource.html +2 -2
  209. package/docs/html/functions/createVideoSource.html +2 -2
  210. package/docs/html/functions/estimateLensPerformance.html +2 -2
  211. package/docs/html/functions/filePickerFactory.html +5 -0
  212. package/docs/html/functions/lensSourcesFactory.html +2 -2
  213. package/docs/html/functions/remoteApiServicesFactory.html +2 -2
  214. package/docs/html/hierarchy.html +1 -1
  215. package/docs/html/index.html +3 -3
  216. package/docs/html/interfaces/BitmojiUserInfo.html +2 -2
  217. package/docs/html/interfaces/CameraKitBootstrapConfiguration.html +2 -2
  218. package/docs/html/interfaces/CameraKitDeviceOptions.html +2 -2
  219. package/docs/html/interfaces/CameraKitSourceInfo.html +2 -2
  220. package/docs/html/interfaces/CameraKitSourceSubscriber.html +2 -2
  221. package/docs/html/interfaces/ComputedFrameMetrics.html +2 -2
  222. package/docs/html/interfaces/CreateSessionOptions.html +2 -2
  223. package/docs/html/interfaces/EstimatedLensPerformance.html +2 -2
  224. package/docs/html/interfaces/FriendUserInfo.html +2 -2
  225. package/docs/html/interfaces/FunctionSourceOptions.html +2 -2
  226. package/docs/html/interfaces/Lens.html +2 -2
  227. package/docs/html/interfaces/LensCreator.html +2 -2
  228. package/docs/html/interfaces/LensLaunchData.html +2 -2
  229. package/docs/html/interfaces/LensSource.html +2 -2
  230. package/docs/html/interfaces/LensUserData.html +2 -2
  231. package/docs/html/interfaces/LoadAssetRequest.html +2 -2
  232. package/docs/html/interfaces/MediaStreamSourceOptions.html +2 -2
  233. package/docs/html/interfaces/Preview.html +2 -2
  234. package/docs/html/interfaces/RemoteApiRequest.html +2 -2
  235. package/docs/html/interfaces/RemoteApiResponse.html +2 -2
  236. package/docs/html/interfaces/RemoteApiService.html +2 -2
  237. package/docs/html/interfaces/Snapcode.html +2 -2
  238. package/docs/html/interfaces/UriCancelRequest.html +2 -2
  239. package/docs/html/interfaces/UriRequest.html +2 -2
  240. package/docs/html/interfaces/UriResponse.html +2 -2
  241. package/docs/html/interfaces/VideoSourceOptions.html +2 -2
  242. package/docs/html/modules.html +6 -2
  243. package/docs/html/types/ArgumentValidationError.html +2 -2
  244. package/docs/html/types/AssetLoader.html +2 -2
  245. package/docs/html/types/AssetResponse.html +1 -1
  246. package/docs/html/types/AssetTiming.html +2 -2
  247. package/docs/html/types/BenchmarkError.html +1 -1
  248. package/docs/html/types/BootstrapError.html +2 -2
  249. package/docs/html/types/CacheKeyNotFoundError.html +1 -1
  250. package/docs/html/types/CameraKitSessionEventListener.html +2 -2
  251. package/docs/html/types/CameraKitSessionEvents.html +2 -2
  252. package/docs/html/types/CameraKitSourceError.html +1 -1
  253. package/docs/html/types/ConfigurationError.html +2 -2
  254. package/docs/html/types/FetchHandler.html +1 -1
  255. package/docs/html/types/FilePicker.html +6 -0
  256. package/docs/html/types/FilePickerOptions.html +2 -0
  257. package/docs/html/types/FilePickerResult.html +2 -0
  258. package/docs/html/types/Keyboard.html +2 -2
  259. package/docs/html/types/KeyboardEvents.html +2 -2
  260. package/docs/html/types/LegalError.html +1 -1
  261. package/docs/html/types/LensAbortError.html +2 -2
  262. package/docs/html/types/LensAssetError.html +2 -2
  263. package/docs/html/types/LensContentValidationError.html +1 -1
  264. package/docs/html/types/LensError.html +1 -1
  265. package/docs/html/types/LensExecutionError.html +2 -2
  266. package/docs/html/types/LensImagePickerError.html +2 -2
  267. package/docs/html/types/LensLaunchParams.html +2 -2
  268. package/docs/html/types/LensMetricsEvents.html +2 -2
  269. package/docs/html/types/LensPerformanceCluster.html +1 -1
  270. package/docs/html/types/LensView.html +2 -2
  271. package/docs/html/types/LensWait.html +2 -2
  272. package/docs/html/types/Matrix.html +2 -2
  273. package/docs/html/types/PersistentStoreError.html +2 -2
  274. package/docs/html/types/PlatformNotSupportedError.html +2 -2
  275. package/docs/html/types/PublicContainer.html +2 -2
  276. package/docs/html/types/PublicServices.html +2 -2
  277. package/docs/html/types/RemoteApiCancelRequestHandler.html +2 -2
  278. package/docs/html/types/RemoteApiRequestHandler.html +2 -2
  279. package/docs/html/types/RemoteApiServices.html +1 -1
  280. package/docs/html/types/RemoteApiStatus.html +2 -2
  281. package/docs/html/types/RenderTarget.html +2 -2
  282. package/docs/html/types/Uri.html +1 -1
  283. package/docs/html/types/WebGLError.html +1 -1
  284. package/docs/html/types/Zodiac.html +1 -1
  285. package/docs/html/variables/extensionRequestContext.html +2 -2
  286. package/docs/md/README.md +1 -1
  287. package/docs/md/classes/CameraKit.md +1 -1
  288. package/docs/md/classes/CameraKitSession.md +1 -1
  289. package/docs/md/classes/CameraKitSource.md +1 -1
  290. package/docs/md/classes/LensPerformanceMeasurement.md +1 -1
  291. package/docs/md/classes/LensPerformanceMetrics.md +1 -1
  292. package/docs/md/classes/LensRepository.md +1 -1
  293. package/docs/md/classes/Transform2D.md +1 -1
  294. package/docs/md/classes/TypedCustomEvent.md +1 -1
  295. package/docs/md/classes/TypedEventTarget.md +1 -1
  296. package/docs/md/enums/Lens_CameraFacing.md +1 -1
  297. package/docs/md/interfaces/BitmojiUserInfo.md +1 -1
  298. package/docs/md/interfaces/CameraKitBootstrapConfiguration.md +1 -1
  299. package/docs/md/interfaces/CameraKitDeviceOptions.md +1 -1
  300. package/docs/md/interfaces/CameraKitSourceInfo.md +1 -1
  301. package/docs/md/interfaces/CameraKitSourceSubscriber.md +1 -1
  302. package/docs/md/interfaces/ComputedFrameMetrics.md +1 -1
  303. package/docs/md/interfaces/CreateSessionOptions.md +1 -1
  304. package/docs/md/interfaces/EstimatedLensPerformance.md +1 -1
  305. package/docs/md/interfaces/FriendUserInfo.md +1 -1
  306. package/docs/md/interfaces/FunctionSourceOptions.md +1 -1
  307. package/docs/md/interfaces/Lens.md +1 -1
  308. package/docs/md/interfaces/LensCreator.md +1 -1
  309. package/docs/md/interfaces/LensLaunchData.md +1 -1
  310. package/docs/md/interfaces/LensSource.md +1 -1
  311. package/docs/md/interfaces/LensUserData.md +1 -1
  312. package/docs/md/interfaces/LoadAssetRequest.md +1 -1
  313. package/docs/md/interfaces/MediaStreamSourceOptions.md +1 -1
  314. package/docs/md/interfaces/Preview.md +1 -1
  315. package/docs/md/interfaces/RemoteApiRequest.md +1 -1
  316. package/docs/md/interfaces/RemoteApiResponse.md +1 -1
  317. package/docs/md/interfaces/RemoteApiService.md +1 -1
  318. package/docs/md/interfaces/Snapcode.md +1 -1
  319. package/docs/md/interfaces/UriCancelRequest.md +1 -1
  320. package/docs/md/interfaces/UriRequest.md +1 -1
  321. package/docs/md/interfaces/UriResponse.md +1 -1
  322. package/docs/md/interfaces/VideoSourceOptions.md +1 -1
  323. package/docs/md/modules.md +65 -3
  324. package/package.json +6 -6
@@ -0,0 +1,31 @@
1
+ import type { FileWithHandle, fileOpen } from "browser-fs-access";
2
+ /**
3
+ * Default file picker dialog type.
4
+ */
5
+ export type OpenDefaultFilePicker = typeof fileOpen;
6
+ /**
7
+ * File picker options. For example, it indicates which MIME types of files are expected to be picked.
8
+ */
9
+ export type FilePickerOptions = Parameters<OpenDefaultFilePicker>[0];
10
+ /**
11
+ * File picker dialog result object, which is a Promise that resolves to a file or an array of files with handles.
12
+ */
13
+ export type FilePickerResult = Promise<FileWithHandle | FileWithHandle[]>;
14
+ /**
15
+ * A callback to show a file picker dialog.
16
+ * @param options - Options for the file picker dialog.
17
+ * @param openDefaultPicker - The default file picker function. The client app may choose to use
18
+ * the default file picker.
19
+ * @returns A promise that resolves to the result of the file picker dialog.
20
+ */
21
+ export type FilePicker = (options: FilePickerOptions, openDefaultPicker: OpenDefaultFilePicker) => FilePickerResult;
22
+ /**
23
+ * Default file picker factory function. The file picker is triggered when a lens issues a file request.
24
+ * Client applications can override this factory function to provide their custom file picker.
25
+ */
26
+ export declare const filePickerFactory: {
27
+ (): FilePicker;
28
+ token: "filePicker";
29
+ dependencies: [];
30
+ };
31
+ //# sourceMappingURL=filePicker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filePicker.d.ts","sourceRoot":"","sources":["../../src/lens-client-interface/filePicker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAGlE;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,OAAO,QAAQ,CAAC;AAEpD;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,UAAU,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAC;AAErE;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,OAAO,CAAC,cAAc,GAAG,cAAc,EAAE,CAAC,CAAC;AAE1E;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,qBAAqB,KAAK,gBAAgB,CAAC;AAEpH;;;GAGG;AACH,eAAO,MAAM,iBAAiB;;;;CAG7B,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { Injectable } from "../dependency-injection/Injectable";
2
+ export const filePickerFactory = Injectable("filePicker", () => (options, openDefaultPicker) => openDefaultPicker(options));
3
+ //# sourceMappingURL=filePicker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filePicker.js","sourceRoot":"","sources":["../../src/lens-client-interface/filePicker.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AA8BhE,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAU,CACvC,YAAY,EACZ,GAAe,EAAE,CAAC,CAAC,OAAO,EAAE,iBAAiB,EAAE,EAAE,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAC/E,CAAC","sourcesContent":["import type { FileWithHandle, fileOpen } from \"browser-fs-access\";\nimport { Injectable } from \"../dependency-injection/Injectable\";\n\n/**\n * Default file picker dialog type.\n */\nexport type OpenDefaultFilePicker = typeof fileOpen;\n\n/**\n * File picker options. For example, it indicates which MIME types of files are expected to be picked.\n */\nexport type FilePickerOptions = Parameters<OpenDefaultFilePicker>[0];\n\n/**\n * File picker dialog result object, which is a Promise that resolves to a file or an array of files with handles.\n */\nexport type FilePickerResult = Promise<FileWithHandle | FileWithHandle[]>;\n\n/**\n * A callback to show a file picker dialog.\n * @param options - Options for the file picker dialog.\n * @param openDefaultPicker - The default file picker function. The client app may choose to use\n * the default file picker.\n * @returns A promise that resolves to the result of the file picker dialog.\n */\nexport type FilePicker = (options: FilePickerOptions, openDefaultPicker: OpenDefaultFilePicker) => FilePickerResult;\n\n/**\n * Default file picker factory function. The file picker is triggered when a lens issues a file request.\n * Client applications can override this factory function to provide their custom file picker.\n */\nexport const filePickerFactory = Injectable(\n \"filePicker\",\n (): FilePicker => (options, openDefaultPicker) => openDefaultPicker(options)\n);\n"]}
@@ -1,9 +1,10 @@
1
1
  import type { ClientInterfaceData } from "../lens-core-module/generated-types";
2
2
  import type { LensCore } from "../lens-core-module/lensCore";
3
+ import type { FilePicker } from "./filePicker";
3
4
  /**
4
5
  * Shows file open dialog to allow user to select image/video and provides the selection to LensCore.
5
6
  *
6
7
  * @internal
7
8
  */
8
- export declare function pickClientImage(clientInterfaceData: ClientInterfaceData, lensCore: LensCore): Promise<void>;
9
+ export declare function pickClientImage(clientInterfaceData: ClientInterfaceData, lensCore: LensCore, filePicker: FilePicker): Promise<void>;
9
10
  //# sourceMappingURL=imagePicker.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"imagePicker.d.ts","sourceRoot":"","sources":["../../src/lens-client-interface/imagePicker.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAC/E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAoF7D;;;;GAIG;AACH,wBAAsB,eAAe,CAAC,mBAAmB,EAAE,mBAAmB,EAAE,QAAQ,EAAE,QAAQ,iBAqCjG"}
1
+ {"version":3,"file":"imagePicker.d.ts","sourceRoot":"","sources":["../../src/lens-client-interface/imagePicker.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAC/E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAE7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAmF/C;;;;GAIG;AACH,wBAAsB,eAAe,CACjC,mBAAmB,EAAE,mBAAmB,EACxC,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,UAAU,iBAyCzB"}
@@ -73,15 +73,18 @@ function getOrientation(data, lensCore) {
73
73
  return orientationMap[(_a = extractJpegOrientationTag(data)) !== null && _a !== void 0 ? _a : 1];
74
74
  }
75
75
  catch (error) {
76
- logger.info("Error occured while reading EXIF orientation tag.", error);
76
+ logger.info("Error occurred while reading EXIF orientation tag.", error);
77
77
  return lensCore.ExternalMediaOrientation.CW0;
78
78
  }
79
79
  }
80
- export function pickClientImage(clientInterfaceData, lensCore) {
80
+ export function pickClientImage(clientInterfaceData, lensCore, filePicker) {
81
81
  return __awaiter(this, void 0, void 0, function* () {
82
82
  const mimeTypes = getMimeType(clientInterfaceData);
83
83
  logger.debug(`Opening file dialog for MIME types: ${mimeTypes}`);
84
- const file = yield fileOpen({ mimeTypes });
84
+ const file = yield filePicker({ mimeTypes }, fileOpen);
85
+ if (Array.isArray(file)) {
86
+ throw new Error("Multiple files are not supported.");
87
+ }
85
88
  logger.debug(`Selected file MIME type: ${file.type}`);
86
89
  const data = yield readFileAsArrayBuffer(file);
87
90
  if (file.type.startsWith("image/")) {
@@ -1 +1 @@
1
- {"version":3,"file":"imagePicker.js","sourceRoot":"","sources":["../../src/lens-client-interface/imagePicker.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAG7C,OAAO,EAAE,yBAAyB,EAAe,MAAM,QAAQ,CAAC;AAEhE,MAAM,MAAM,GAAG,SAAS,CAAC,gCAAgC,CAAC,CAAC;AAI3D,MAAM,SAAS,GAAG;IACd,KAAK,EAAE;QACH,YAAY;QACZ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,CAAC,KAAK,CAAC,uCAAuC,SAAS,EAAE,CAAC,CAAC;QAEjE,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC;QAC3C,MAAM,CAAC,KAAK,CAAC,4BAA4B,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAEtD,MAAM,IAAI,GAAG,MAAM,qBAAqB,CAAC,IAAI,CAAC,CAAC;QAC/C,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;YAChC,QAAQ,CAAC,oBAAoB,CAAC;gBAC1B,IAAI;gBACJ,WAAW,EAAE,cAAc,CAAC,IAAI,EAAE,QAAQ,CAAC;gBAO3C,SAAS,EAAE;oBACP;wBACI,MAAM,EAAE;4BACJ,CAAC,EAAE,CAAC;4BACJ,CAAC,EAAE,CAAC;yBACP;wBACD,IAAI,EAAE;4BACF,KAAK,EAAE,CAAC;4BACR,MAAM,EAAE,CAAC;yBACZ;qBACJ;iBACJ;aACJ,CAAC,CAAC;SACN;aAAM;YACH,QAAQ,CAAC,oBAAoB,CAAC;gBAC1B,IAAI;gBACJ,WAAW,EAAE,QAAQ,CAAC,wBAAwB,CAAC,GAAG;aACrD,CAAC,CAAC;SACN;IACL,CAAC;CAAA","sourcesContent":["import type { FileWithHandle } from \"browser-fs-access\";\nimport { fileOpen } from \"browser-fs-access\";\nimport { getLogger } from \"../logger/logger\";\nimport type { ClientInterfaceData } from \"../lens-core-module/generated-types\";\nimport type { LensCore } from \"../lens-core-module/lensCore\";\nimport { extractJpegOrientationTag, Orientation } from \"./exif\";\n\nconst logger = getLogger(\"lensClientInterfaceImagePicker\");\n\n// Common MIME types supported by all browsers as per:\n// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types\nconst mimeTypes = {\n image: [\n \"image/avif\",\n \"image/bmp\",\n \"image/gif\",\n \"image/jpeg\",\n \"image/png\",\n \"image/svg+xml\",\n \"image/tiff\",\n \"image/webp\",\n ],\n video: [\n \"video/3gpp\",\n \"video/3gpp2\",\n \"video/mp2t\",\n \"video/mp4\",\n \"video/mpeg\",\n \"video/ogg\",\n \"video/quicktime\",\n \"video/webm\",\n \"video/x-msvideo\",\n ],\n} as const;\n\nfunction* enumerateSupportedVideoTypes(types: typeof mimeTypes.video) {\n // test video element to perform MIME types support check\n const testVideoElement = typeof document !== \"undefined\" ? document.createElement(\"video\") : undefined;\n for (const type of types) {\n if (testVideoElement?.canPlayType(type) || false) {\n yield type;\n }\n }\n}\n\nfunction readFileAsArrayBuffer(file: FileWithHandle): Promise<ArrayBuffer> {\n return new Promise((resolve, reject) => {\n const reader = new FileReader();\n reader.addEventListener(\"load\", (event) => {\n // Safety: target.result is always an ArrayBuffer because we read file using readAsArrayBuffer()\n resolve(event.target!.result as ArrayBuffer);\n });\n reader.addEventListener(\"error\", (event) => {\n reject(event.target!.error);\n });\n reader.readAsArrayBuffer(file);\n });\n}\n\nfunction getMimeType({ ImageEnabled, VideoEnabled }: ClientInterfaceData) {\n const types = [];\n if (ImageEnabled === \"1\") types.push(...mimeTypes.image);\n if (VideoEnabled === \"1\") types.push(...enumerateSupportedVideoTypes(mimeTypes.video));\n if (types.length === 0) {\n throw new Error(\"Unknown media type requested.\");\n }\n return types;\n}\n\nfunction getOrientation(data: ArrayBuffer, lensCore: LensCore) {\n const orientationMap = {\n [Orientation.TopLeft]: lensCore.ExternalMediaOrientation.CW0,\n [Orientation.TopRight]: lensCore.ExternalMediaOrientation.CW0,\n [Orientation.BottomRight]: lensCore.ExternalMediaOrientation.CW180,\n [Orientation.BottomLeft]: lensCore.ExternalMediaOrientation.CW180,\n [Orientation.LeftTop]: lensCore.ExternalMediaOrientation.CW90,\n [Orientation.RightTop]: lensCore.ExternalMediaOrientation.CW90,\n [Orientation.RightBottom]: lensCore.ExternalMediaOrientation.CW270,\n [Orientation.LeftBottom]: lensCore.ExternalMediaOrientation.CW270,\n };\n try {\n return orientationMap[extractJpegOrientationTag(data) ?? Orientation.TopLeft];\n } catch (error) {\n logger.info(\"Error occured while reading EXIF orientation tag.\", error);\n return lensCore.ExternalMediaOrientation.CW0;\n }\n}\n\n/**\n * Shows file open dialog to allow user to select image/video and provides the selection to LensCore.\n *\n * @internal\n */\nexport async function pickClientImage(clientInterfaceData: ClientInterfaceData, lensCore: LensCore) {\n const mimeTypes = getMimeType(clientInterfaceData);\n logger.debug(`Opening file dialog for MIME types: ${mimeTypes}`);\n\n const file = await fileOpen({ mimeTypes });\n logger.debug(`Selected file MIME type: ${file.type}`);\n\n const data = await readFileAsArrayBuffer(file);\n if (file.type.startsWith(\"image/\")) {\n lensCore.provideExternalImage({\n data,\n orientation: getOrientation(data, lensCore),\n // As per Corvyn: both iOS and Android clients have the ability to pick out individual faces\n // from an image to apply the effect on, using each of their native face detectors (not using LensCore).\n // That's what the faceRects is for. For now, we can just apply the effect to the whole image (so face rect\n // [[0,0][1,1]]). In future, in order to be able to pick out individual faces in the media picker, we could:\n // - hook up some external web face tracking library\n // - make LensCore to expose face tracker to external clients\n faceRects: [\n {\n origin: {\n x: 0,\n y: 0,\n },\n size: {\n width: 1,\n height: 1,\n },\n },\n ],\n });\n } else {\n lensCore.provideExternalVideo({\n data,\n orientation: lensCore.ExternalMediaOrientation.CW0,\n });\n }\n}\n"]}
1
+ {"version":3,"file":"imagePicker.js","sourceRoot":"","sources":["../../src/lens-client-interface/imagePicker.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAG7C,OAAO,EAAE,yBAAyB,EAAe,MAAM,QAAQ,CAAC;AAGhE,MAAM,MAAM,GAAG,SAAS,CAAC,gCAAgC,CAAC,CAAC;AAI3D,MAAM,SAAS,GAAG;IACd,KAAK,EAAE;QACH,YAAY;QACZ,WAAW;QACX,WAAW;QACX,YAAY;QACZ,WAAW;QACX,eAAe;QACf,YAAY;QACZ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EjE,MAAM,IAAI,GAAG,MAAM,UAAU,CAAC,EAAE,SAAS,EAAE,EAAE,QAAQ,CAAC,CAAC;QACvD,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YACrB,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;SACxD;QACD,MAAM,CAAC,KAAK,CAAC,4BAA4B,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAEtD,MAAM,IAAI,GAAG,MAAM,qBAAqB,CAAC,IAAI,CAAC,CAAC;QAC/C,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;YAChC,QAAQ,CAAC,oBAAoB,CAAC;gBAC1B,IAAI;gBACJ,WAAW,EAAE,cAAc,CAAC,IAAI,EAAE,QAAQ,CAAC;gBAO3C,SAAS,EAAE;oBACP;wBACI,MAAM,EAAE;4BACJ,CAAC,EAAE,CAAC;4BACJ,CAAC,EAAE,CAAC;yBACP;wBACD,IAAI,EAAE;4BACF,KAAK,EAAE,CAAC;4BACR,MAAM,EAAE,CAAC;yBACZ;qBACJ;iBACJ;aACJ,CAAC,CAAC;SACN;aAAM;YACH,QAAQ,CAAC,oBAAoB,CAAC;gBAC1B,IAAI;gBACJ,WAAW,EAAE,QAAQ,CAAC,wBAAwB,CAAC,GAAG;aACrD,CAAC,CAAC;SACN;IACL,CAAC;CAAA","sourcesContent":["import type { FileWithHandle } from \"browser-fs-access\";\nimport { fileOpen } from \"browser-fs-access\";\nimport { getLogger } from \"../logger/logger\";\nimport type { ClientInterfaceData } from \"../lens-core-module/generated-types\";\nimport type { LensCore } from \"../lens-core-module/lensCore\";\nimport { extractJpegOrientationTag, Orientation } from \"./exif\";\nimport type { FilePicker } from \"./filePicker\";\n\nconst logger = getLogger(\"lensClientInterfaceImagePicker\");\n\n// Common MIME types supported by all browsers as per:\n// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types\nconst mimeTypes = {\n image: [\n \"image/avif\",\n \"image/bmp\",\n \"image/gif\",\n \"image/jpeg\",\n \"image/png\",\n \"image/svg+xml\",\n \"image/tiff\",\n \"image/webp\",\n ],\n video: [\n \"video/3gpp\",\n \"video/3gpp2\",\n \"video/mp2t\",\n \"video/mp4\",\n \"video/mpeg\",\n \"video/ogg\",\n \"video/quicktime\",\n \"video/webm\",\n \"video/x-msvideo\",\n ],\n} as const;\n\nfunction* enumerateSupportedVideoTypes(types: typeof mimeTypes.video) {\n // test video element to perform MIME types support check\n const testVideoElement = typeof document !== \"undefined\" ? document.createElement(\"video\") : undefined;\n for (const type of types) {\n if (testVideoElement?.canPlayType(type) || false) {\n yield type;\n }\n }\n}\n\nfunction readFileAsArrayBuffer(file: FileWithHandle): Promise<ArrayBuffer> {\n return new Promise((resolve, reject) => {\n const reader = new FileReader();\n reader.addEventListener(\"load\", (event) => {\n // Safety: target.result is always an ArrayBuffer because we read file using readAsArrayBuffer()\n resolve(event.target!.result as ArrayBuffer);\n });\n reader.addEventListener(\"error\", (event) => {\n reject(event.target!.error);\n });\n reader.readAsArrayBuffer(file);\n });\n}\n\nfunction getMimeType({ ImageEnabled, VideoEnabled }: ClientInterfaceData) {\n const types = [];\n if (ImageEnabled === \"1\") types.push(...mimeTypes.image);\n if (VideoEnabled === \"1\") types.push(...enumerateSupportedVideoTypes(mimeTypes.video));\n if (types.length === 0) {\n throw new Error(\"Unknown media type requested.\");\n }\n return types;\n}\n\nfunction getOrientation(data: ArrayBuffer, lensCore: LensCore) {\n const orientationMap = {\n [Orientation.TopLeft]: lensCore.ExternalMediaOrientation.CW0,\n [Orientation.TopRight]: lensCore.ExternalMediaOrientation.CW0,\n [Orientation.BottomRight]: lensCore.ExternalMediaOrientation.CW180,\n [Orientation.BottomLeft]: lensCore.ExternalMediaOrientation.CW180,\n [Orientation.LeftTop]: lensCore.ExternalMediaOrientation.CW90,\n [Orientation.RightTop]: lensCore.ExternalMediaOrientation.CW90,\n [Orientation.RightBottom]: lensCore.ExternalMediaOrientation.CW270,\n [Orientation.LeftBottom]: lensCore.ExternalMediaOrientation.CW270,\n };\n try {\n return orientationMap[extractJpegOrientationTag(data) ?? Orientation.TopLeft];\n } catch (error) {\n logger.info(\"Error occurred while reading EXIF orientation tag.\", error);\n return lensCore.ExternalMediaOrientation.CW0;\n }\n}\n\n/**\n * Shows file open dialog to allow user to select image/video and provides the selection to LensCore.\n *\n * @internal\n */\nexport async function pickClientImage(\n clientInterfaceData: ClientInterfaceData,\n lensCore: LensCore,\n filePicker: FilePicker\n) {\n const mimeTypes = getMimeType(clientInterfaceData);\n logger.debug(`Opening file dialog for MIME types: ${mimeTypes}`);\n\n const file = await filePicker({ mimeTypes }, fileOpen);\n if (Array.isArray(file)) {\n throw new Error(\"Multiple files are not supported.\");\n }\n logger.debug(`Selected file MIME type: ${file.type}`);\n\n const data = await readFileAsArrayBuffer(file);\n if (file.type.startsWith(\"image/\")) {\n lensCore.provideExternalImage({\n data,\n orientation: getOrientation(data, lensCore),\n // As per Corvyn: both iOS and Android clients have the ability to pick out individual faces\n // from an image to apply the effect on, using each of their native face detectors (not using LensCore).\n // That's what the faceRects is for. For now, we can just apply the effect to the whole image (so face rect\n // [[0,0][1,1]]). In future, in order to be able to pick out individual faces in the media picker, we could:\n // - hook up some external web face tracking library\n // - make LensCore to expose face tracker to external clients\n faceRects: [\n {\n origin: {\n x: 0,\n y: 0,\n },\n size: {\n width: 1,\n height: 1,\n },\n },\n ],\n });\n } else {\n lensCore.provideExternalVideo({\n data,\n orientation: lensCore.ExternalMediaOrientation.CW0,\n });\n }\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  import type { LensCore } from "../lens-core-module/lensCore";
2
+ import type { FilePicker } from "./filePicker";
2
3
  /**
3
4
  * Registers client interface handler in LensCore.
4
5
  *
@@ -7,8 +8,8 @@ import type { LensCore } from "../lens-core-module/lensCore";
7
8
  * @param sessionErrors EventTarget to dispatch errors in.
8
9
  */
9
10
  export declare const registerLensClientInterfaceHandler: {
10
- (args_0: LensCore): void;
11
+ (args_0: LensCore, args_1: FilePicker): void;
11
12
  token: "registerLensClientInterfaceHandler";
12
- dependencies: readonly ["lensCore"];
13
+ dependencies: readonly ["lensCore", "filePicker"];
13
14
  };
14
15
  //# sourceMappingURL=lensClientInterface.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"lensClientInterface.d.ts","sourceRoot":"","sources":["../../src/lens-client-interface/lensClientInterface.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAK7D;;;;;;GAMG;AACH,eAAO,MAAM,kCAAkC;;;;CA0B9C,CAAC"}
1
+ {"version":3,"file":"lensClientInterface.d.ts","sourceRoot":"","sources":["../../src/lens-client-interface/lensClientInterface.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAE7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAK/C;;;;;;GAMG;AACH,eAAO,MAAM,kCAAkC;;;;CA0B9C,CAAC"}
@@ -4,8 +4,9 @@ import { Injectable } from "../dependency-injection/Injectable";
4
4
  import { getLogger } from "../logger/logger";
5
5
  import { lensCoreFactory } from "../lens-core-module/loader/lensCoreFactory";
6
6
  import { pickClientImage } from "./imagePicker";
7
+ import { filePickerFactory } from "./filePicker";
7
8
  const logger = getLogger("lensClientInterface");
8
- export const registerLensClientInterfaceHandler = Injectable("registerLensClientInterfaceHandler", [lensCoreFactory.token], (lensCore) => {
9
+ export const registerLensClientInterfaceHandler = Injectable("registerLensClientInterfaceHandler", [lensCoreFactory.token, filePickerFactory.token], (lensCore, filePicker) => {
9
10
  if (!lensCore.setClientInterfaceRequestHandler) {
10
11
  logger.warn("Current LensCore version doesn't support lens client interface requests");
11
12
  return;
@@ -13,7 +14,7 @@ export const registerLensClientInterfaceHandler = Injectable("registerLensClient
13
14
  lensCore.setClientInterfaceRequestHandler(({ data, interfaceControl, interfaceAction }) => __awaiter(void 0, void 0, void 0, function* () {
14
15
  if (interfaceControl === lensCore.InterfaceControl.ImagePicker &&
15
16
  interfaceAction === lensCore.InterfaceAction.Show) {
16
- yield pickClientImage(data, lensCore).catch((error) => {
17
+ yield pickClientImage(data, lensCore, filePicker).catch((error) => {
17
18
  logger.error(lensImagePickerError("Error occurred while attempting to select an image file for the lens request.", error));
18
19
  });
19
20
  }
@@ -1 +1 @@
1
- {"version":3,"file":"lensClientInterface.js","sourceRoot":"","sources":["../../src/lens-client-interface/lensClientInterface.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAE7E,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,MAAM,MAAM,GAAG,SAAS,CAAC,qBAAqB,CAAC,CAAC;AAShD,MAAM,CAAC,MAAM,kCAAkC,GAAG,UAAU,CACxD,oCAAoC,EACpC,CAAC,eAAe,CAAC,KAAK,CAAU,EAChC,CAAC,QAAkB,EAAE,EAAE;IAEnB,IAAI,CAAC,QAAQ,CAAC,gCAAgC,EAAE;QAC5C,MAAM,CAAC,IAAI,CAAC,yEAAyE,CAAC,CAAC;QACvF,OAAO;KACV;IAED,QAAQ,CAAC,gCAAgC,CAAC,CAAO,EAAE,IAAI,EAAE,gBAAgB,EAAE,eAAe,EAAE,EAAE,EAAE;QAC5F,IACI,gBAAgB,KAAK,QAAQ,CAAC,gBAAgB,CAAC,WAAW;YAC1D,eAAe,KAAK,QAAQ,CAAC,eAAe,CAAC,IAAI,EACnD;YACE,MAAM,eAAe,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;gBAClD,MAAM,CAAC,KAAK,CACR,oBAAoB,CAChB,+EAA+E,EAC/E,KAAK,CACR,CACJ,CAAC;YACN,CAAC,CAAC,CAAC;SACN;IACL,CAAC,CAAA,CAAC,CAAC;AACP,CAAC,CACJ,CAAC","sourcesContent":["import { lensImagePickerError } from \"../namedErrors\";\nimport { Injectable } from \"../dependency-injection/Injectable\";\nimport { getLogger } from \"../logger/logger\";\nimport { lensCoreFactory } from \"../lens-core-module/loader/lensCoreFactory\";\nimport type { LensCore } from \"../lens-core-module/lensCore\";\nimport { pickClientImage } from \"./imagePicker\";\n\nconst logger = getLogger(\"lensClientInterface\");\n\n/**\n * Registers client interface handler in LensCore.\n *\n * @internal\n * @param lensCore LensCore instance to register in.\n * @param sessionErrors EventTarget to dispatch errors in.\n */\nexport const registerLensClientInterfaceHandler = Injectable(\n \"registerLensClientInterfaceHandler\",\n [lensCoreFactory.token] as const,\n (lensCore: LensCore) => {\n // Make sure we are compatible with previous LensCore versions\n if (!lensCore.setClientInterfaceRequestHandler) {\n logger.warn(\"Current LensCore version doesn't support lens client interface requests\");\n return;\n }\n\n lensCore.setClientInterfaceRequestHandler(async ({ data, interfaceControl, interfaceAction }) => {\n if (\n interfaceControl === lensCore.InterfaceControl.ImagePicker &&\n interfaceAction === lensCore.InterfaceAction.Show\n ) {\n await pickClientImage(data, lensCore).catch((error) => {\n logger.error(\n lensImagePickerError(\n \"Error occurred while attempting to select an image file for the lens request.\",\n error\n )\n );\n });\n }\n });\n }\n);\n"]}
1
+ {"version":3,"file":"lensClientInterface.js","sourceRoot":"","sources":["../../src/lens-client-interface/lensClientInterface.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAE7E,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD,MAAM,MAAM,GAAG,SAAS,CAAC,qBAAqB,CAAC,CAAC;AAShD,MAAM,CAAC,MAAM,kCAAkC,GAAG,UAAU,CACxD,oCAAoC,EACpC,CAAC,eAAe,CAAC,KAAK,EAAE,iBAAiB,CAAC,KAAK,CAAU,EACzD,CAAC,QAAkB,EAAE,UAAsB,EAAE,EAAE;IAE3C,IAAI,CAAC,QAAQ,CAAC,gCAAgC,EAAE;QAC5C,MAAM,CAAC,IAAI,CAAC,yEAAyE,CAAC,CAAC;QACvF,OAAO;KACV;IAED,QAAQ,CAAC,gCAAgC,CAAC,CAAO,EAAE,IAAI,EAAE,gBAAgB,EAAE,eAAe,EAAE,EAAE,EAAE;QAC5F,IACI,gBAAgB,KAAK,QAAQ,CAAC,gBAAgB,CAAC,WAAW;YAC1D,eAAe,KAAK,QAAQ,CAAC,eAAe,CAAC,IAAI,EACnD;YACE,MAAM,eAAe,CAAC,IAAI,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;gBAC9D,MAAM,CAAC,KAAK,CACR,oBAAoB,CAChB,+EAA+E,EAC/E,KAAK,CACR,CACJ,CAAC;YACN,CAAC,CAAC,CAAC;SACN;IACL,CAAC,CAAA,CAAC,CAAC;AACP,CAAC,CACJ,CAAC","sourcesContent":["import { lensImagePickerError } from \"../namedErrors\";\nimport { Injectable } from \"../dependency-injection/Injectable\";\nimport { getLogger } from \"../logger/logger\";\nimport { lensCoreFactory } from \"../lens-core-module/loader/lensCoreFactory\";\nimport type { LensCore } from \"../lens-core-module/lensCore\";\nimport { pickClientImage } from \"./imagePicker\";\nimport type { FilePicker } from \"./filePicker\";\nimport { filePickerFactory } from \"./filePicker\";\n\nconst logger = getLogger(\"lensClientInterface\");\n\n/**\n * Registers client interface handler in LensCore.\n *\n * @internal\n * @param lensCore LensCore instance to register in.\n * @param sessionErrors EventTarget to dispatch errors in.\n */\nexport const registerLensClientInterfaceHandler = Injectable(\n \"registerLensClientInterfaceHandler\",\n [lensCoreFactory.token, filePickerFactory.token] as const,\n (lensCore: LensCore, filePicker: FilePicker) => {\n // Make sure we are compatible with previous LensCore versions\n if (!lensCore.setClientInterfaceRequestHandler) {\n logger.warn(\"Current LensCore version doesn't support lens client interface requests\");\n return;\n }\n\n lensCore.setClientInterfaceRequestHandler(async ({ data, interfaceControl, interfaceAction }) => {\n if (\n interfaceControl === lensCore.InterfaceControl.ImagePicker &&\n interfaceAction === lensCore.InterfaceAction.Show\n ) {\n await pickClientImage(data, lensCore, filePicker).catch((error) => {\n logger.error(\n lensImagePickerError(\n \"Error occurred while attempting to select an image file for the lens request.\",\n error\n )\n );\n });\n }\n });\n }\n);\n"]}
@@ -1,5 +1,12 @@
1
1
  import type { CameraKitConfiguration } from "../../configuration";
2
2
  import type { FetchHandler } from "../../handlers/defaultFetchHandler";
3
+ import type { RequestStateEventTarget } from "../../handlers/requestStateEmittingHandler";
4
+ export declare const LENS_CORE_JS_REQUEST_TYPE = "lens_core_js";
5
+ export declare const LENS_CORE_WASM_REQUEST_TYPE = "lens_core_wasm";
6
+ export interface LensCoreDownloadDimensions extends Record<string, string> {
7
+ requestType: typeof LENS_CORE_JS_REQUEST_TYPE | typeof LENS_CORE_WASM_REQUEST_TYPE;
8
+ customBuild: string;
9
+ }
3
10
  /**
4
11
  * This component is responsible for:
5
12
  * 1) Loading LensCore WebAssembly (WASM) assets
@@ -11,8 +18,8 @@ import type { FetchHandler } from "../../handlers/defaultFetchHandler";
11
18
  * @internal
12
19
  */
13
20
  export declare const lensCoreFactory: {
14
- (args_0: FetchHandler, args_1: CameraKitConfiguration): Promise<import("../lensCore").LensCore>;
21
+ (args_0: FetchHandler, args_1: CameraKitConfiguration, args_2: RequestStateEventTarget): Promise<import("../lensCore").LensCore>;
15
22
  token: "lensCore";
16
- dependencies: readonly ["defaultFetchHandler", "configuration"];
23
+ dependencies: readonly ["defaultFetchHandler", "configuration", "requestStateEventTarget"];
17
24
  };
18
25
  //# sourceMappingURL=lensCoreFactory.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"lensCoreFactory.d.ts","sourceRoot":"","sources":["../../../src/lens-core-module/loader/lensCoreFactory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAGlE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAcvE;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe;;;;CA6E3B,CAAC"}
1
+ {"version":3,"file":"lensCoreFactory.d.ts","sourceRoot":"","sources":["../../../src/lens-core-module/loader/lensCoreFactory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAGlE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAQvE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,4CAA4C,CAAC;AAW1F,eAAO,MAAM,yBAAyB,iBAAiB,CAAC;AACxD,eAAO,MAAM,2BAA2B,mBAAmB,CAAC;AAE5D,MAAM,WAAW,0BAA2B,SAAQ,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IACtE,WAAW,EAAE,OAAO,yBAAyB,GAAG,OAAO,2BAA2B,CAAC;IACnF,WAAW,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe;;;;CAiG3B,CAAC"}
@@ -8,16 +8,22 @@ import { createLensCore } from "../lensCore";
8
8
  import { loadScript } from "../../common/loadScript";
9
9
  import { HandlerChainBuilder } from "../../handlers/HandlerChainBuilder";
10
10
  import { createCustomLensCoreHandler } from "../../handlers/customLensCoreHandler";
11
+ import { createRequestStateEmittingHandler, requestStateEventTargetFactory, } from "../../handlers/requestStateEmittingHandler";
11
12
  import { getRequiredBootstrapURLs } from "./bootstrapURLs";
12
13
  const logger = getLogger("lensCoreFactory");
13
14
  const findMatch = (regex, strings) => strings.find((s) => regex.test(s));
14
- export const lensCoreFactory = Injectable("lensCore", [defaultFetchHandlerFactory.token, configurationToken], (handler, { lensCoreOverrideUrls, wasmEndpointOverride }) => __awaiter(void 0, void 0, void 0, function* () {
15
+ export const LENS_CORE_JS_REQUEST_TYPE = "lens_core_js";
16
+ export const LENS_CORE_WASM_REQUEST_TYPE = "lens_core_wasm";
17
+ export const lensCoreFactory = Injectable("lensCore", [defaultFetchHandlerFactory.token, configurationToken, requestStateEventTargetFactory.token], (handler, { lensCoreOverrideUrls, wasmEndpointOverride }, requestStateEventTarget) => __awaiter(void 0, void 0, void 0, function* () {
15
18
  var _a, _b;
16
19
  let lensCoreJS;
17
20
  let lensCoreWASM;
18
- let lensCoreHandler = lensCoreOverrideUrls || wasmEndpointOverride
19
- ? new HandlerChainBuilder(handler).map(createCustomLensCoreHandler()).handler
20
- : handler;
21
+ const customBuild = !!(lensCoreOverrideUrls || wasmEndpointOverride);
22
+ let lensCoreHandlerChainBuilder = new HandlerChainBuilder(handler);
23
+ if (customBuild) {
24
+ lensCoreHandlerChainBuilder = lensCoreHandlerChainBuilder.map(createCustomLensCoreHandler());
25
+ }
26
+ const lensCoreHandler = lensCoreHandlerChainBuilder.map(createRequestStateEmittingHandler(requestStateEventTarget)).handler;
21
27
  if (lensCoreOverrideUrls) {
22
28
  lensCoreJS = lensCoreOverrideUrls.js;
23
29
  lensCoreWASM = lensCoreOverrideUrls.wasm;
@@ -31,7 +37,10 @@ export const lensCoreFactory = Injectable("lensCore", [defaultFetchHandlerFactor
31
37
  throw new Error(`Cannot fetch required LensCore assets. Either the JS or WASM filename is missing from ` +
32
38
  `this list: ${assetURLs}.`);
33
39
  }
34
- const glueScript = yield lensCoreHandler(lensCoreJS).then((r) => r.blob());
40
+ const glueScript = yield lensCoreHandler([
41
+ lensCoreJS,
42
+ { requestType: LENS_CORE_JS_REQUEST_TYPE, customBuild: `${customBuild}` },
43
+ ]).then((r) => r.blob());
35
44
  lensCoreJS = URL.createObjectURL(glueScript);
36
45
  }
37
46
  const scriptElement = yield loadScript(lensCoreJS);
@@ -40,7 +49,10 @@ export const lensCoreFactory = Injectable("lensCore", [defaultFetchHandlerFactor
40
49
  const moduleInit = globalThis.createLensesModule((initialModule = {
41
50
  mainScriptUrlOrBlob: lensCoreJS,
42
51
  instantiateWasm: (importObject, receiveInstance) => {
43
- WebAssembly.instantiateStreaming(lensCoreHandler(lensCoreWASM), importObject)
52
+ WebAssembly.instantiateStreaming(lensCoreHandler([
53
+ lensCoreWASM,
54
+ { requestType: LENS_CORE_WASM_REQUEST_TYPE, customBuild: `${customBuild}` },
55
+ ]), importObject)
44
56
  .then(function ({ instance, module }) {
45
57
  receiveInstance(instance, module);
46
58
  initialModule.compiledModule = module;
@@ -1 +1 @@
1
- {"version":3,"file":"lensCoreFactory.js","sourceRoot":"","sources":["../../../src/lens-core-module/loader/lensCoreFactory.ts"],"names":[],"mappings":";AAAA,OAAO,YAAY,MAAM,4BAA4B,CAAC;AAEtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AAEnE,OAAO,EAAE,0BAA0B,EAAE,MAAM,oCAAoC,CAAC;AAEhF,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAE3D,MAAM,MAAM,GAAG,SAAS,CAAC,iBAAiB,CAAC,CAAC;AAE5C,MAAM,SAAS,GAAG,CAAC,KA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AI,EAAE,CAAC,CAAC;QAC3E,UAAU,GAAG,GAAG,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;KAChD;IAED,MAAM,aAAa,GAAG,MAAM,UAAU,CAAC,UAAU,CAAC,CAAC;IAEnD,MAAM,QAAQ,GAAG,MAAM,IAAI,OAAO,CAA2C,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC7F,IAAI,aAA+C,CAAC;QAMpD,MAAM,UAAU,GAAG,UAAU,CAAC,kBAAkB,CAC5C,CAAC,aAAa,GAAG;YAEb,mBAAmB,EAAE,UAAU;YAE/B,eAAe,EAAE,CAAC,YAAY,EAAE,eAAe,EAAE,EAAE;gBAC/C,WAAW,CAAC,oBAAoB,CAAC,eAAe,CAAC,YAAY,CAAC,EAAE,YAAY,CAAC;qBACxE,IAAI,CAAC,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE;oBAChC,eAAe,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;oBAElC,aAAa,CAAC,cAAc,GAAG,MAAM,CAAC;oBACtC,OAAO,CAAC,UAAU,CAAC,CAAC;gBACxB,CAAC,CAAC;qBACD,KAAK,CAAC,MAAM,CAAC,CAAC;YACvB,CAAC;SACJ,CAAC,CACL,CAAC;IACN,CAAC,CAAC,CAAC;IAGH,aAAa,CAAC,MAAM,EAAE,CAAC;IAGvB,IAAI,YAAY,CAAC,OAAO,IAAI,GAAG,QAAQ,CAAC,cAAc,EAAE,EAAE,EAAE;QACxD,MAAM,CAAC,IAAI,CACP,4BAA4B,QAAQ,CAAC,cAAc,EAAE,gCACjD,YAAY,CAAC,OACjB,GAAG,CACN,CAAC;KACL;IAED,OAAO,cAAc,CAAC,QAAQ,CAAC,CAAC;AACpC,CAAC,CAAA,CACJ,CAAC","sourcesContent":["import lensCoreWasm from \"../../lensCoreWasmVersions\";\nimport type { CameraKitConfiguration } from \"../../configuration\";\nimport { configurationToken } from \"../../configuration\";\nimport { Injectable } from \"../../dependency-injection/Injectable\";\nimport type { FetchHandler } from \"../../handlers/defaultFetchHandler\";\nimport { defaultFetchHandlerFactory } from \"../../handlers/defaultFetchHandler\";\nimport type { InitialEmscriptenModule, LensCoreModule } from \"../generated-types\";\nimport { getLogger } from \"../../logger/logger\";\nimport { createLensCore } from \"../lensCore\";\nimport { loadScript } from \"../../common/loadScript\";\nimport { HandlerChainBuilder } from \"../../handlers/HandlerChainBuilder\";\nimport { createCustomLensCoreHandler } from \"../../handlers/customLensCoreHandler\";\nimport { getRequiredBootstrapURLs } from \"./bootstrapURLs\";\n\nconst logger = getLogger(\"lensCoreFactory\");\n\nconst findMatch = (regex: RegExp, strings: string[]) => strings.find((s) => regex.test(s));\n\n/**\n * This component is responsible for:\n * 1) Loading LensCore WebAssembly (WASM) assets\n * 2) Using the WASM assets to initialize the LensCore WASM module\n *\n * By default, WASM assets will be loaded from the Bolt CDN – but if `endpoint` is provided, assets will be loaded\n * using it as a base URL.\n *\n * @internal\n */\nexport const lensCoreFactory = Injectable(\n \"lensCore\",\n [defaultFetchHandlerFactory.token, configurationToken] as const,\n async (handler: FetchHandler, { lensCoreOverrideUrls, wasmEndpointOverride }: CameraKitConfiguration) => {\n let lensCoreJS: string;\n let lensCoreWASM: string;\n // We only use custom handler when LensCore is loaded from a custom location.\n let lensCoreHandler =\n lensCoreOverrideUrls || wasmEndpointOverride\n ? new HandlerChainBuilder(handler).map(createCustomLensCoreHandler()).handler\n : handler;\n\n if (lensCoreOverrideUrls) {\n lensCoreJS = lensCoreOverrideUrls.js;\n lensCoreWASM = lensCoreOverrideUrls.wasm;\n } else {\n const endpointOverride = wasmEndpointOverride ?? undefined;\n const assetURLs = await getRequiredBootstrapURLs(endpointOverride);\n\n lensCoreJS = findMatch(/\\.js/, assetURLs) ?? \"\";\n lensCoreWASM = findMatch(/\\.wasm/, assetURLs) ?? \"\";\n\n if (!lensCoreJS || !lensCoreWASM) {\n throw new Error(\n `Cannot fetch required LensCore assets. Either the JS or WASM filename is missing from ` +\n `this list: ${assetURLs}.`\n );\n }\n\n // Fetching here and creating an Object URL lets LensCore optimized loading itself in a WebWorker,\n // otherwise the glue script would need to be downloaded again.\n const glueScript = await lensCoreHandler(lensCoreJS).then((r) => r.blob());\n lensCoreJS = URL.createObjectURL(glueScript);\n }\n\n const scriptElement = await loadScript(lensCoreJS);\n\n const lensCore = await new Promise<InitialEmscriptenModule & LensCoreModule>((resolve, reject) => {\n let initialModule: Partial<InitialEmscriptenModule>;\n // will trigger WASM initialization and data loading,\n // after completion it will be safe to call imported WASM functions\n // More about emscripten initialization:\n // eslint-disable-next-line max-len\n // https://emscripten.org/docs/getting_started/FAQ.html?highlight=modularize#how-can-i-tell-when-the-page-is-fully-loaded-and-it-is-safe-to-call-compiled-functions\n const moduleInit = globalThis.createLensesModule(\n (initialModule = {\n // url will be used for loading glue JS during Worker initialization\n mainScriptUrlOrBlob: lensCoreJS,\n // will be triggered by Emscripten during the initialization\n instantiateWasm: (importObject, receiveInstance) => {\n WebAssembly.instantiateStreaming(lensCoreHandler(lensCoreWASM), importObject)\n .then(function ({ instance, module }) {\n receiveInstance(instance, module);\n // compiled module will be reused in Worker\n initialModule.compiledModule = module;\n resolve(moduleInit);\n })\n .catch(reject);\n },\n })\n );\n });\n\n // now when we have LensCore WASM in memory we can release the script element\n scriptElement.remove();\n\n // print warning if loaded version differs from hardcoded one\n if (lensCoreWasm.version != `${lensCore.getCoreVersion()}`) {\n logger.warn(\n `Loaded LensCore version (${lensCore.getCoreVersion()}) differs from expected one (${\n lensCoreWasm.version\n })`\n );\n }\n\n return createLensCore(lensCore);\n }\n);\n"]}
1
+ {"version":3,"file":"lensCoreFactory.js","sourceRoot":"","sources":["../../../src/lens-core-module/loader/lensCoreFactory.ts"],"names":[],"mappings":";AAAA,OAAO,YAAY,MAAM,4BAA4B,CAAC;AAEtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AAEnE,OAAO,EAAE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,GAAG;YAEb,mBAAmB,EAAE,UAAU;YAE/B,eAAe,EAAE,CAAC,YAAY,EAAE,eAAe,EAAE,EAAE;gBAC/C,WAAW,CAAC,oBAAoB,CAC5B,eAAe,CAAC;oBACZ,YAAY;oBACZ,EAAE,WAAW,EAAE,2BAA2B,EAAE,WAAW,EAAE,GAAG,WAAW,EAAE,EAAE;iBAC9E,CAAC,EACF,YAAY,CACf;qBACI,IAAI,CAAC,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE;oBAChC,eAAe,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;oBAElC,aAAa,CAAC,cAAc,GAAG,MAAM,CAAC;oBACtC,OAAO,CAAC,UAAU,CAAC,CAAC;gBACxB,CAAC,CAAC;qBACD,KAAK,CAAC,MAAM,CAAC,CAAC;YACvB,CAAC;SACJ,CAAC,CACL,CAAC;IACN,CAAC,CAAC,CAAC;IAGH,aAAa,CAAC,MAAM,EAAE,CAAC;IAGvB,IAAI,YAAY,CAAC,OAAO,IAAI,GAAG,QAAQ,CAAC,cAAc,EAAE,EAAE,EAAE;QACxD,MAAM,CAAC,IAAI,CACP,4BAA4B,QAAQ,CAAC,cAAc,EAAE,gCACjD,YAAY,CAAC,OACjB,GAAG,CACN,CAAC;KACL;IAED,OAAO,cAAc,CAAC,QAAQ,CAAC,CAAC;AACpC,CAAC,CAAA,CACJ,CAAC","sourcesContent":["import lensCoreWasm from \"../../lensCoreWasmVersions\";\nimport type { CameraKitConfiguration } from \"../../configuration\";\nimport { configurationToken } from \"../../configuration\";\nimport { Injectable } from \"../../dependency-injection/Injectable\";\nimport type { FetchHandler } from \"../../handlers/defaultFetchHandler\";\nimport { defaultFetchHandlerFactory } from \"../../handlers/defaultFetchHandler\";\nimport type { InitialEmscriptenModule, LensCoreModule } from \"../generated-types\";\nimport { getLogger } from \"../../logger/logger\";\nimport { createLensCore } from \"../lensCore\";\nimport { loadScript } from \"../../common/loadScript\";\nimport { HandlerChainBuilder } from \"../../handlers/HandlerChainBuilder\";\nimport { createCustomLensCoreHandler } from \"../../handlers/customLensCoreHandler\";\nimport type { RequestStateEventTarget } from \"../../handlers/requestStateEmittingHandler\";\nimport {\n createRequestStateEmittingHandler,\n requestStateEventTargetFactory,\n} from \"../../handlers/requestStateEmittingHandler\";\nimport { getRequiredBootstrapURLs } from \"./bootstrapURLs\";\n\nconst logger = getLogger(\"lensCoreFactory\");\n\nconst findMatch = (regex: RegExp, strings: string[]) => strings.find((s) => regex.test(s));\n\nexport const LENS_CORE_JS_REQUEST_TYPE = \"lens_core_js\";\nexport const LENS_CORE_WASM_REQUEST_TYPE = \"lens_core_wasm\";\n\nexport interface LensCoreDownloadDimensions extends Record<string, string> {\n requestType: typeof LENS_CORE_JS_REQUEST_TYPE | typeof LENS_CORE_WASM_REQUEST_TYPE;\n customBuild: string;\n}\n\n/**\n * This component is responsible for:\n * 1) Loading LensCore WebAssembly (WASM) assets\n * 2) Using the WASM assets to initialize the LensCore WASM module\n *\n * By default, WASM assets will be loaded from the Bolt CDN – but if `endpoint` is provided, assets will be loaded\n * using it as a base URL.\n *\n * @internal\n */\nexport const lensCoreFactory = Injectable(\n \"lensCore\",\n [defaultFetchHandlerFactory.token, configurationToken, requestStateEventTargetFactory.token] as const,\n async (\n handler: FetchHandler,\n { lensCoreOverrideUrls, wasmEndpointOverride }: CameraKitConfiguration,\n requestStateEventTarget: RequestStateEventTarget\n ) => {\n let lensCoreJS: string;\n let lensCoreWASM: string;\n\n const customBuild = !!(lensCoreOverrideUrls || wasmEndpointOverride);\n let lensCoreHandlerChainBuilder = new HandlerChainBuilder(handler);\n if (customBuild) {\n // We only use custom handler when LensCore is loaded from a custom location.\n lensCoreHandlerChainBuilder = lensCoreHandlerChainBuilder.map(createCustomLensCoreHandler());\n }\n // add metrics to LC requests\n const lensCoreHandler = lensCoreHandlerChainBuilder.map(\n // TODO: ideally we don't need it here: https://jira.sc-corp.net/browse/CAMKIT-6350\n createRequestStateEmittingHandler<LensCoreDownloadDimensions>(requestStateEventTarget)\n ).handler;\n\n if (lensCoreOverrideUrls) {\n lensCoreJS = lensCoreOverrideUrls.js;\n lensCoreWASM = lensCoreOverrideUrls.wasm;\n } else {\n const endpointOverride = wasmEndpointOverride ?? undefined;\n const assetURLs = await getRequiredBootstrapURLs(endpointOverride);\n\n lensCoreJS = findMatch(/\\.js/, assetURLs) ?? \"\";\n lensCoreWASM = findMatch(/\\.wasm/, assetURLs) ?? \"\";\n\n if (!lensCoreJS || !lensCoreWASM) {\n throw new Error(\n `Cannot fetch required LensCore assets. Either the JS or WASM filename is missing from ` +\n `this list: ${assetURLs}.`\n );\n }\n\n // Fetching here and creating an Object URL lets LensCore optimized loading itself in a WebWorker,\n // otherwise the glue script would need to be downloaded again.\n const glueScript = await lensCoreHandler([\n lensCoreJS,\n { requestType: LENS_CORE_JS_REQUEST_TYPE, customBuild: `${customBuild}` },\n ]).then((r) => r.blob());\n lensCoreJS = URL.createObjectURL(glueScript);\n }\n\n const scriptElement = await loadScript(lensCoreJS);\n\n const lensCore = await new Promise<InitialEmscriptenModule & LensCoreModule>((resolve, reject) => {\n let initialModule: Partial<InitialEmscriptenModule>;\n // will trigger WASM initialization and data loading,\n // after completion it will be safe to call imported WASM functions\n // More about emscripten initialization:\n // eslint-disable-next-line max-len\n // https://emscripten.org/docs/getting_started/FAQ.html?highlight=modularize#how-can-i-tell-when-the-page-is-fully-loaded-and-it-is-safe-to-call-compiled-functions\n const moduleInit = globalThis.createLensesModule(\n (initialModule = {\n // url will be used for loading glue JS during Worker initialization\n mainScriptUrlOrBlob: lensCoreJS,\n // will be triggered by Emscripten during the initialization\n instantiateWasm: (importObject, receiveInstance) => {\n WebAssembly.instantiateStreaming(\n lensCoreHandler([\n lensCoreWASM,\n { requestType: LENS_CORE_WASM_REQUEST_TYPE, customBuild: `${customBuild}` },\n ]),\n importObject\n )\n .then(function ({ instance, module }) {\n receiveInstance(instance, module);\n // compiled module will be reused in Worker\n initialModule.compiledModule = module;\n resolve(moduleInit);\n })\n .catch(reject);\n },\n })\n );\n });\n\n // now when we have LensCore WASM in memory we can release the script element\n scriptElement.remove();\n\n // print warning if loaded version differs from hardcoded one\n if (lensCoreWasm.version != `${lensCore.getCoreVersion()}`) {\n logger.warn(\n `Loaded LensCore version (${lensCore.getCoreVersion()}) differs from expected one (${\n lensCoreWasm.version\n })`\n );\n }\n\n return createLensCore(lensCore);\n }\n);\n"]}
@@ -1,6 +1,6 @@
1
1
  export default {
2
- version: "267",
3
- buildNumber: "312",
4
- baseUrl: "https://cf-st.sc-cdn.net/d/P7GNr57Olcevwd0qGstFA?go=IgsKCTIBBEgBUFxgAQ%3D%3D&uc=92",
2
+ version: "273",
3
+ buildNumber: "336",
4
+ baseUrl: "https://cf-st.sc-cdn.net/d/YGNditIgLs88TKEbvTnKN?go=IgsKCTIBBEgBUFxgAQ%3D%3D&uc=92",
5
5
  };
6
6
  //# sourceMappingURL=lensCoreWasmVersions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"lensCoreWasmVersions.js","sourceRoot":"","sources":["../src/lensCoreWasmVersions.ts"],"names":[],"mappings":"AAAA,eAAe;IACX,OAAO,EAAE,KAAK;IACd,WAAW,EAAE,KAAK;IAClB,OAAO,EAAE,oFAAoF;CAChG,CAAC","sourcesContent":["export default {\n version: \"267\",\n buildNumber: \"312\",\n baseUrl: \"https://cf-st.sc-cdn.net/d/P7GNr57Olcevwd0qGstFA?go=IgsKCTIBBEgBUFxgAQ%3D%3D&uc=92\",\n};\n"]}
1
+ {"version":3,"file":"lensCoreWasmVersions.js","sourceRoot":"","sources":["../src/lensCoreWasmVersions.ts"],"names":[],"mappings":"AAAA,eAAe;IACX,OAAO,EAAE,KAAK;IACd,WAAW,EAAE,KAAK;IAClB,OAAO,EAAE,oFAAoF;CAChG,CAAC","sourcesContent":["export default {\n version: \"273\",\n buildNumber: \"336\",\n baseUrl: \"https://cf-st.sc-cdn.net/d/YGNditIgLs88TKEbvTnKN?go=IgsKCTIBBEgBUFxgAQ%3D%3D&uc=92\",\n};\n"]}
@@ -1,11 +1,15 @@
1
1
  import type { CofDimensions } from "../../remote-configuration/cofHandler";
2
2
  import type { Dimensions, RequestStateEventTarget } from "../../handlers/requestStateEmittingHandler";
3
3
  import type { MetricsClient } from "../../clients/metricsClient";
4
+ import { type LensCoreDownloadDimensions } from "../../lens-core-module/loader/lensCoreFactory";
5
+ import { type GrpcRequestDimensions } from "../../clients/grpcHandler";
4
6
  import type { AssetDownloadDimensions, LensDownloadDimensions } from "./reportLensAndAssetDownload";
5
- export declare const isRelevantRequest: (value: Dimensions) => value is CofDimensions | AssetDownloadDimensions | LensDownloadDimensions;
7
+ type ReportableMetricDimensions = LensDownloadDimensions | AssetDownloadDimensions | CofDimensions | LensCoreDownloadDimensions | GrpcRequestDimensions;
8
+ export declare const isRelevantRequest: (value: Dimensions) => value is ReportableMetricDimensions;
6
9
  export declare const reportHttpMetrics: {
7
10
  (args_0: MetricsClient, args_1: RequestStateEventTarget): void;
8
11
  token: "reportHttpMetrics";
9
12
  dependencies: readonly ["metricsClient", "requestStateEventTarget"];
10
13
  };
14
+ export {};
11
15
  //# sourceMappingURL=reportHttpMetrics.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"reportHttpMetrics.d.ts","sourceRoot":"","sources":["../../../src/metrics/reporters/reportHttpMetrics.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AAE3E,OAAO,KAAK,EACR,UAAU,EACV,uBAAuB,EAE1B,MAAM,4CAA4C,CAAC;AAGpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAKjE,OAAO,KAAK,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAuEpG,eAAO,MAAM,iBAAiB,UACnB,UAAU,8EAGpB,CAAC;AAEF,eAAO,MAAM,iBAAiB;;;;CA2D7B,CAAC"}
1
+ {"version":3,"file":"reportHttpMetrics.d.ts","sourceRoot":"","sources":["../../../src/metrics/reporters/reportHttpMetrics.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AAE3E,OAAO,KAAK,EACR,UAAU,EACV,uBAAuB,EAE1B,MAAM,4CAA4C,CAAC;AAGpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAKjE,OAAO,EAGH,KAAK,0BAA0B,EAClC,MAAM,+CAA+C,CAAC;AACvD,OAAO,EAA0B,KAAK,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAC/F,OAAO,KAAK,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAgBpG,KAAK,0BAA0B,GACzB,sBAAsB,GACtB,uBAAuB,GACvB,aAAa,GACb,0BAA0B,GAC1B,qBAAqB,CAAC;AA2D5B,eAAO,MAAM,iBAAiB,UAAW,UAAU,wCAGlD,CAAC;AAEF,eAAO,MAAM,iBAAiB;;;;CA2D7B,CAAC"}
@@ -7,29 +7,34 @@ import { getPlatformInfo } from "../../platform/platformInfo";
7
7
  import { metricsClientFactory } from "../../clients/metricsClient";
8
8
  import { Count } from "../operational/Count";
9
9
  import { Histogram } from "../operational/Histogram";
10
- import { isLensOrAssetRequest } from "./reportLensAndAssetDownload";
10
+ import { LENS_CORE_JS_REQUEST_TYPE, LENS_CORE_WASM_REQUEST_TYPE, } from "../../lens-core-module/loader/lensCoreFactory";
11
+ import { GRPC_CALL_REQUEST_TYPE } from "../../clients/grpcHandler";
12
+ const reportableMetricRequestTypes = [
13
+ "asset",
14
+ "lens_content",
15
+ LENS_CORE_JS_REQUEST_TYPE,
16
+ LENS_CORE_WASM_REQUEST_TYPE,
17
+ COF_REQUEST_TYPE,
18
+ GRPC_CALL_REQUEST_TYPE,
19
+ ];
11
20
  const getAdditionalDimensions = (dimensions) => {
12
21
  switch (dimensions.requestType) {
13
- case "lens_content":
14
- case "asset":
15
- return [];
16
22
  case COF_REQUEST_TYPE:
17
23
  return [["delta", dimensions.delta]];
24
+ case GRPC_CALL_REQUEST_TYPE:
25
+ return [["method", dimensions.methodName]];
26
+ case LENS_CORE_JS_REQUEST_TYPE:
27
+ case LENS_CORE_WASM_REQUEST_TYPE:
28
+ return [["custom", dimensions.customBuild]];
18
29
  default:
19
- assertUnreachable(dimensions);
30
+ return [];
20
31
  }
21
32
  };
22
33
  const getContentType = (dimensions) => {
23
- switch (dimensions.requestType) {
24
- case "lens_content":
25
- return "lens_content";
26
- case "asset":
27
- return dimensions.assetType;
28
- case COF_REQUEST_TYPE:
29
- return COF_REQUEST_TYPE;
30
- default:
31
- assertUnreachable(dimensions);
34
+ if (dimensions.requestType === "asset") {
35
+ return dimensions.assetType;
32
36
  }
37
+ return dimensions.requestType;
33
38
  };
34
39
  const getSizeKb = (event) => {
35
40
  switch (event.type) {
@@ -54,7 +59,8 @@ const getStatus = (event) => {
54
59
  }
55
60
  };
56
61
  export const isRelevantRequest = (value) => {
57
- return isLensOrAssetRequest(value) || value["requestType"] === COF_REQUEST_TYPE;
62
+ const reportableMetricDimensions = value;
63
+ return reportableMetricRequestTypes.includes(reportableMetricDimensions.requestType);
58
64
  };
59
65
  export const reportHttpMetrics = Injectable("reportHttpMetrics", [metricsClientFactory.token, requestStateEventTargetFactory.token], (metrics, requestStateEventTarget) => {
60
66
  scan({ name: "inProgress", inProgress: new Map() })(requestStateEventTarget, ["started", "completed", "errored"], (state, event) => {
@@ -1 +1 @@
1
- {"version":3,"file":"reportHttpMetrics.js","sourceRoot":"","sources":["../../../src/metrics/reporters/reportHttpMetrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AACnE,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AAMzE,OAAO,E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CAAC,mBAAmB,EAAE,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC;QAC/E,OAAO,CAAC,qBAAqB,CAAC,SAAS,CAAC,KAAK,CAAC,kBAAkB,EAAE,cAAc,EAAE,UAAU,CAAC,CAAC,CAAC;QAC/F,OAAO,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;AACP,CAAC,CACJ,CAAC","sourcesContent":["import { assertUnreachable } from \"../../common/assertions\";\nimport { Injectable } from \"../../dependency-injection/Injectable\";\nimport { scan } from \"../../events/scan\";\nimport type { CofDimensions } from \"../../remote-configuration/cofHandler\";\nimport { COF_REQUEST_TYPE } from \"../../remote-configuration/cofHandler\";\nimport type {\n Dimensions,\n RequestStateEventTarget,\n RequestStateEvents,\n} from \"../../handlers/requestStateEmittingHandler\";\nimport { requestStateEventTargetFactory } from \"../../handlers/requestStateEmittingHandler\";\nimport { getPlatformInfo } from \"../../platform/platformInfo\";\nimport type { MetricsClient } from \"../../clients/metricsClient\";\nimport { metricsClientFactory } from \"../../clients/metricsClient\";\nimport { Count } from \"../operational/Count\";\nimport { Histogram } from \"../operational/Histogram\";\nimport type { Timer } from \"../operational/Timer\";\nimport type { AssetDownloadDimensions, LensDownloadDimensions } from \"./reportLensAndAssetDownload\";\nimport { isLensOrAssetRequest } from \"./reportLensAndAssetDownload\";\n\ntype InProgressMap = Map<number, { timer: Timer<\"download_latency\"> }>;\ninterface InProgress {\n name: \"inProgress\";\n inProgress: InProgressMap;\n}\ninterface Completed {\n name: \"completed\";\n inProgress: InProgressMap;\n dimensions: Record<string, string>;\n timer: Timer<\"download_latency\">;\n downloadSizeKb: number;\n}\ntype RequestState = InProgress | Completed;\n\nconst getAdditionalDimensions = (\n dimensions: LensDownloadDimensions | AssetDownloadDimensions | CofDimensions\n): [string, string][] => {\n switch (dimensions.requestType) {\n case \"lens_content\":\n case \"asset\":\n return [];\n case COF_REQUEST_TYPE:\n return [[\"delta\", dimensions.delta]];\n default:\n assertUnreachable(dimensions);\n }\n};\n\nconst getContentType = (dimensions: LensDownloadDimensions | AssetDownloadDimensions | CofDimensions): string => {\n switch (dimensions.requestType) {\n case \"lens_content\":\n return \"lens_content\";\n case \"asset\":\n return dimensions.assetType;\n case COF_REQUEST_TYPE:\n return COF_REQUEST_TYPE;\n default:\n assertUnreachable(dimensions);\n }\n};\n\nconst getSizeKb = (event: RequestStateEvents): number => {\n switch (event.type) {\n case \"started\":\n case \"errored\":\n return 0;\n case \"completed\":\n return event.detail.sizeByte / 1024;\n default:\n assertUnreachable(event);\n }\n};\n\nconst getStatus = (event: RequestStateEvents): string => {\n switch (event.type) {\n case \"started\":\n case \"errored\":\n // We'll use status 0 to indicate that an exception occurred during the request. This is somewhat in keeping\n // with browsers that set the response status to 0 if the request was not able to be made (e.g. CORs\n // preflight failed, or the user canceled the request).\n return \"0\";\n case \"completed\":\n return event.detail.status.toString();\n default:\n assertUnreachable(event);\n }\n};\n\nexport const isRelevantRequest = (\n value: Dimensions\n): value is LensDownloadDimensions | AssetDownloadDimensions | CofDimensions => {\n return isLensOrAssetRequest(value) || value[\"requestType\"] === COF_REQUEST_TYPE;\n};\n\nexport const reportHttpMetrics = Injectable(\n \"reportHttpMetrics\",\n [metricsClientFactory.token, requestStateEventTargetFactory.token] as const,\n (metrics: MetricsClient, requestStateEventTarget: RequestStateEventTarget) => {\n scan<RequestState>({ name: \"inProgress\", inProgress: new Map() })(\n requestStateEventTarget,\n [\"started\", \"completed\", \"errored\"],\n (state, event) => {\n const { inProgress } = state;\n const { dimensions, requestId } = event.detail;\n\n if (!isRelevantRequest(dimensions)) return state;\n\n switch (event.type) {\n case \"started\":\n const timer = event.detail.timer;\n inProgress.set(requestId, { timer });\n return { name: \"inProgress\", inProgress };\n case \"completed\":\n case \"errored\":\n const completedRequest = inProgress.get(requestId);\n if (!completedRequest) return state;\n inProgress.delete(requestId);\n\n const downloadSizeKb = getSizeKb(event);\n const status = getStatus(event);\n const operationalDimensions: Record<string, string> = {\n content_type: getContentType(dimensions),\n network_type: getPlatformInfo().connectionType ?? \"unknown\",\n status,\n };\n\n for (const [key, value] of getAdditionalDimensions(dimensions)) {\n operationalDimensions[key] = value;\n }\n\n completedRequest.timer.measure(operationalDimensions);\n\n return {\n name: \"completed\",\n inProgress: state.inProgress,\n dimensions: operationalDimensions,\n downloadSizeKb,\n timer: completedRequest.timer,\n };\n default:\n assertUnreachable(event);\n }\n }\n ).addEventListener(\"state\", ({ detail: state }) => {\n if (state.name !== \"completed\") return;\n\n const { dimensions, timer, downloadSizeKb } = state;\n\n metrics.setOperationalMetrics(Count.count(\"download_finished\", 1, dimensions));\n metrics.setOperationalMetrics(Histogram.level(\"download_size_kb\", downloadSizeKb, dimensions));\n metrics.setOperationalMetrics(timer);\n });\n }\n);\n"]}
1
+ {"version":3,"file":"reportHttpMetrics.js","sourceRoot":"","sources":["../../../src/metrics/reporters/reportHttpMetrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AACnE,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AAMzE,OAAO,EAAE,8BAA8B,EAAE,MAAM,4CAA4C,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAErD,OAAO,EACH,yBAAyB,EACzB,2BAA2B,GAE9B,MAAM,+CAA+C,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAA8B,MAAM,2BAA2B,CAAC;AAwB/F,MAAM,4BAA4B,GAAgD;IAC9E,OAAO;IACP,cAA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O,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;AACP,CAAC,CACJ,CAAC","sourcesContent":["import { assertUnreachable } from \"../../common/assertions\";\nimport { Injectable } from \"../../dependency-injection/Injectable\";\nimport { scan } from \"../../events/scan\";\nimport type { CofDimensions } from \"../../remote-configuration/cofHandler\";\nimport { COF_REQUEST_TYPE } from \"../../remote-configuration/cofHandler\";\nimport type {\n Dimensions,\n RequestStateEventTarget,\n RequestStateEvents,\n} from \"../../handlers/requestStateEmittingHandler\";\nimport { requestStateEventTargetFactory } from \"../../handlers/requestStateEmittingHandler\";\nimport { getPlatformInfo } from \"../../platform/platformInfo\";\nimport type { MetricsClient } from \"../../clients/metricsClient\";\nimport { metricsClientFactory } from \"../../clients/metricsClient\";\nimport { Count } from \"../operational/Count\";\nimport { Histogram } from \"../operational/Histogram\";\nimport type { Timer } from \"../operational/Timer\";\nimport {\n LENS_CORE_JS_REQUEST_TYPE,\n LENS_CORE_WASM_REQUEST_TYPE,\n type LensCoreDownloadDimensions,\n} from \"../../lens-core-module/loader/lensCoreFactory\";\nimport { GRPC_CALL_REQUEST_TYPE, type GrpcRequestDimensions } from \"../../clients/grpcHandler\";\nimport type { AssetDownloadDimensions, LensDownloadDimensions } from \"./reportLensAndAssetDownload\";\n\ntype InProgressMap = Map<number, { timer: Timer<\"download_latency\"> }>;\ninterface InProgress {\n name: \"inProgress\";\n inProgress: InProgressMap;\n}\ninterface Completed {\n name: \"completed\";\n inProgress: InProgressMap;\n dimensions: Record<string, string>;\n timer: Timer<\"download_latency\">;\n downloadSizeKb: number;\n}\ntype RequestState = InProgress | Completed;\n\ntype ReportableMetricDimensions =\n | LensDownloadDimensions\n | AssetDownloadDimensions\n | CofDimensions\n | LensCoreDownloadDimensions\n | GrpcRequestDimensions;\n\nconst reportableMetricRequestTypes: ReportableMetricDimensions[\"requestType\"][] = [\n \"asset\",\n \"lens_content\",\n LENS_CORE_JS_REQUEST_TYPE,\n LENS_CORE_WASM_REQUEST_TYPE,\n COF_REQUEST_TYPE,\n GRPC_CALL_REQUEST_TYPE,\n];\n\nconst getAdditionalDimensions = (dimensions: ReportableMetricDimensions): [string, string][] => {\n switch (dimensions.requestType) {\n case COF_REQUEST_TYPE:\n return [[\"delta\", dimensions.delta]];\n case GRPC_CALL_REQUEST_TYPE:\n return [[\"method\", dimensions.methodName]];\n case LENS_CORE_JS_REQUEST_TYPE:\n case LENS_CORE_WASM_REQUEST_TYPE:\n return [[\"custom\", dimensions.customBuild]];\n default:\n return [];\n }\n};\n\nconst getContentType = (dimensions: ReportableMetricDimensions): string => {\n if (dimensions.requestType === \"asset\") {\n return dimensions.assetType;\n }\n return dimensions.requestType;\n};\n\nconst getSizeKb = (event: RequestStateEvents): number => {\n switch (event.type) {\n case \"started\":\n case \"errored\":\n return 0;\n case \"completed\":\n return event.detail.sizeByte / 1024;\n default:\n assertUnreachable(event);\n }\n};\n\nconst getStatus = (event: RequestStateEvents): string => {\n switch (event.type) {\n case \"started\":\n case \"errored\":\n // We'll use status 0 to indicate that an exception occurred during the request. This is somewhat in keeping\n // with browsers that set the response status to 0 if the request was not able to be made (e.g. CORs\n // preflight failed, or the user canceled the request).\n return \"0\";\n case \"completed\":\n return event.detail.status.toString();\n default:\n assertUnreachable(event);\n }\n};\n\nexport const isRelevantRequest = (value: Dimensions): value is ReportableMetricDimensions => {\n const reportableMetricDimensions = value as ReportableMetricDimensions;\n return reportableMetricRequestTypes.includes(reportableMetricDimensions.requestType);\n};\n\nexport const reportHttpMetrics = Injectable(\n \"reportHttpMetrics\",\n [metricsClientFactory.token, requestStateEventTargetFactory.token] as const,\n (metrics: MetricsClient, requestStateEventTarget: RequestStateEventTarget) => {\n scan<RequestState>({ name: \"inProgress\", inProgress: new Map() })(\n requestStateEventTarget,\n [\"started\", \"completed\", \"errored\"],\n (state, event) => {\n const { inProgress } = state;\n const { dimensions, requestId } = event.detail;\n\n if (!isRelevantRequest(dimensions)) return state;\n\n switch (event.type) {\n case \"started\":\n const timer = event.detail.timer;\n inProgress.set(requestId, { timer });\n return { name: \"inProgress\", inProgress };\n case \"completed\":\n case \"errored\":\n const completedRequest = inProgress.get(requestId);\n if (!completedRequest) return state;\n inProgress.delete(requestId);\n\n const downloadSizeKb = getSizeKb(event);\n const status = getStatus(event);\n const operationalDimensions: Record<string, string> = {\n content_type: getContentType(dimensions),\n network_type: getPlatformInfo().connectionType ?? \"unknown\",\n status,\n };\n\n for (const [key, value] of getAdditionalDimensions(dimensions)) {\n operationalDimensions[key] = value;\n }\n\n completedRequest.timer.measure(operationalDimensions);\n\n return {\n name: \"completed\",\n inProgress: state.inProgress,\n dimensions: operationalDimensions,\n downloadSizeKb,\n timer: completedRequest.timer,\n };\n default:\n assertUnreachable(event);\n }\n }\n ).addEventListener(\"state\", ({ detail: state }) => {\n if (state.name !== \"completed\") return;\n\n const { dimensions, timer, downloadSizeKb } = state;\n\n metrics.setOperationalMetrics(Count.count(\"download_finished\", 1, dimensions));\n metrics.setOperationalMetrics(Histogram.level(\"download_size_kb\", downloadSizeKb, dimensions));\n metrics.setOperationalMetrics(timer);\n });\n }\n);\n"]}
@@ -14,8 +14,8 @@ export declare const reportGloballyScopedMetrics: PartialContainer<{
14
14
  reportPlatformCapabilities: Promise<void>;
15
15
  }, {
16
16
  configuration: import("../..").CameraKitConfiguration;
17
- metricsClient: import("../../clients/metricsClient").MetricsClient;
18
17
  requestStateEventTarget: import("../../handlers/requestStateEmittingHandler").RequestStateEventTarget;
18
+ metricsClient: import("../../clients/metricsClient").MetricsClient;
19
19
  legalState: import("@snap/state-management").StateMachine<import("@snap/state-management").Action<"requestLegalPrompt", undefined> | import("@snap/state-management").Action<"accept", string> | import("@snap/state-management").Action<"reject", string>, import("@snap/state-management").State<"unknown", undefined> | import("@snap/state-management").State<"accepted", undefined> | import("@snap/state-management").State<"rejected", undefined>>;
20
20
  metricsEventTarget: import("../metricsEventTarget").MetricsEventTarget;
21
21
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"cofHandler.d.ts","sourceRoot":"","sources":["../../src/remote-configuration/cofHandler.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qDAAqD,CAAC;AAClG,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sDAAsD,CAAC;AAGpG,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAWvF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAM/D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAI9D,MAAM,WAAW,QAAQ;IACrB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACzB;AAED,eAAO,MAAM,gBAAgB,QAAQ,CAAC;AAEtC,MAAM,MAAM,aAAa,GAAG;IAAE,WAAW,EAAE,OAAO,gBAAgB,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAIpF;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB;;;;;;;CA6H7B,CAAC"}
1
+ {"version":3,"file":"cofHandler.d.ts","sourceRoot":"","sources":["../../src/remote-configuration/cofHandler.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qDAAqD,CAAC;AAClG,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sDAAsD,CAAC;AAGpG,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAWvF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAM/D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAI9D,MAAM,WAAW,QAAQ;IACrB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACzB;AAED,eAAO,MAAM,gBAAgB,QAAQ,CAAC;AAEtC,MAAM,MAAM,aAAa,GAAG;IAAE,WAAW,EAAE,OAAO,gBAAgB,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAIpF;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB;;;;;;;CA+H7B,CAAC"}
@@ -76,7 +76,7 @@ export const cofHandlerFactory = Injectable("cofHandler", [configurationToken, r
76
76
  .map(createTimeoutHandler({ timeout: 20 * 1000 }))
77
77
  .map(createResponseCachingHandler(cofCache, getCacheKey, staleWhileRevalidateStrategy({
78
78
  onMiss: () => {
79
- metrics.setOperationalMetrics(Count.count("cache_miss", 1, { request_type: "cof" }));
79
+ metrics.setOperationalMetrics(Count.count("cache_miss", 1, { request_type: COF_REQUEST_TYPE }));
80
80
  },
81
81
  }))).handler);
82
82
  });
@@ -1 +1 @@
1
- {"version":3,"file":"cofHandler.js","sourceRoot":"","sources":["../../src/remote-configuration/cofHandler.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,8BAA8B,EAAE,WAAW,EAAE,MAAM,2DAA2D,CAAC;AAIxH,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAEtE,OAAO,EACH,wBAAwB,EACxB,sBAAsB,EACtB,sBAAsB,EACtB,8BAA8B,GACjC,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,4BAA4B,EAAE,4BAA4B,EAAE,MAAM,oCAAoC,CAAC;AAChH,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAE3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,C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ACL,CACJ,CAAC,OAAO,CAChB,CAAC;AACN,CAAC,CACJ,CAAC","sourcesContent":["/* eslint-disable max-len */\nimport { BrowserHeaders } from \"browser-headers\";\nimport { getCameraKitUserAgent } from \"../platform/cameraKitUserAgent\";\nimport { ensureError } from \"../common/errorHelpers\";\nimport { unionBy } from \"../common/unionBy\";\nimport { CircumstancesServiceClientImpl, GrpcWebImpl } from \"../generated-proto/pb_schema/cdp/cof/circumstance_service\";\nimport type { ConfigTargetingRequest } from \"../generated-proto/pb_schema/cdp/cof/config_request\";\nimport type { ConfigTargetingResponse } from \"../generated-proto/pb_schema/cdp/cof/config_response\";\nimport type { RequestMetadata } from \"../handlers/HandlerChainBuilder\";\nimport { HandlerChainBuilder } from \"../handlers/HandlerChainBuilder\";\nimport type { RequestStateEventTarget } from \"../handlers/requestStateEmittingHandler\";\nimport {\n dispatchRequestCompleted,\n dispatchRequestErrored,\n dispatchRequestStarted,\n requestStateEventTargetFactory,\n} from \"../handlers/requestStateEmittingHandler\";\nimport { createResponseCachingHandler, staleWhileRevalidateStrategy } from \"../handlers/responseCachingHandler\";\nimport { createRetryingHandler } from \"../handlers/retryingHandler\";\nimport { createTimeoutHandler } from \"../handlers/timeoutHandler\";\nimport { IndexedDBPersistence } from \"../persistence/IndexedDBPersistence\";\nimport type { CameraKitConfiguration } from \"../configuration\";\nimport { configurationToken } from \"../configuration\";\nimport { Injectable } from \"../dependency-injection/Injectable\";\nimport { getLogger } from \"../logger/logger\";\nimport { ExpiringPersistence } from \"../persistence/ExpiringPersistence\";\nimport { convertDaysToSeconds } from \"../common/time\";\nimport type { MetricsClient } from \"../clients/metricsClient\";\nimport { metricsClientFactory } from \"../clients/metricsClient\";\nimport { Count } from \"../metrics/operational/Count\";\n\nexport interface Metadata {\n [key: string]: string;\n}\n\nexport const COF_REQUEST_TYPE = \"cof\";\n\nexport type CofDimensions = { requestType: typeof COF_REQUEST_TYPE; delta: string };\n\nconst logger = getLogger(\"cofHandler\");\n\n/**\n * Handler chain used to make COF requests. Uses the COF client to perform the\n * requests, with retries, timeout, and caching.\n *\n * The handler will first attempt to retrieve the COF response from cache. If it is found, the result is returned\n * immediately and the cache is updated in the background. If no response is found, a COF request is made. This request\n * will retry (with exponential backoff + jitter) for 5 seconds before returning an error to the caller.\n */\nexport const cofHandlerFactory = Injectable(\n \"cofHandler\",\n [configurationToken, requestStateEventTargetFactory.token, metricsClientFactory.token] as const,\n (config: CameraKitConfiguration, requestStateEventTarget: RequestStateEventTarget, metrics: MetricsClient) => {\n const cofCache = new ExpiringPersistence<ConfigTargetingResponse>(\n () => convertDaysToSeconds(365),\n new IndexedDBPersistence({ databaseName: \"COFCache\" })\n );\n const getCacheKey = (r: Partial<ConfigTargetingRequest>) => JSON.stringify(r);\n // We need to wrap `targetingQuery` to create a usable Handler – the main issue is that HandlerChainBuilder\n // always adds a `signal` property to the metadata argument (second argument of the Handler), but\n // `targetingQuery` expects the second argument to only contain headers.\n return (\n new HandlerChainBuilder(\n async (\n request: Partial<ConfigTargetingRequest>,\n { signal, isSideEffect: _, ...metadata }: Metadata & RequestMetadata\n ) => {\n const rpc = new GrpcWebImpl(`https://${config.apiHostname}`, {});\n const client = new CircumstancesServiceClientImpl(rpc);\n return new Promise<ConfigTargetingResponse>(async (resolve, reject) => {\n if (signal) {\n signal.addEventListener(\"abort\", () =>\n reject(new Error(\"COF request aborted by handler chain.\"))\n );\n }\n\n const cachedResponse = await cofCache.retrieve(getCacheKey(request)).catch((e) => {\n logger.warn(\"Unable to get COF response from cache.\", e);\n return {\n configResultsEtag: undefined,\n configResults: [],\n };\n });\n const dimensions: CofDimensions = {\n requestType: COF_REQUEST_TYPE,\n delta: `${!!cachedResponse?.configResultsEtag}`,\n };\n const { requestId } = dispatchRequestStarted(requestStateEventTarget, { dimensions });\n\n try {\n const response = await client.targetingQuery(\n {\n ...request,\n configResultsEtag: cachedResponse?.configResultsEtag,\n deltaSync: !!cachedResponse?.configResultsEtag,\n },\n new BrowserHeaders({\n authorization: `Bearer ${config.apiToken}`,\n \"x-snap-client-user-agent\": getCameraKitUserAgent(),\n ...metadata,\n })\n );\n\n // NOTE: in order for cache persistance to work, we need to make the\n // object cloneable i.e. with no methods (it appears targetingQuery()\n // attaches toObject() to response object). Safety: We have to cast response\n // object to a type that has toObject defined, because that is indeed\n // what generated code has:\n // eslint-disable-next-line max-len\n // https://github.sc-corp.net/Snapchat/camera-kit-web-sdk/blob/8d6b4e8bfa3717b376ab197a49972a1e410851f7/packages/web-sdk/src/generated-proto/pb_schema/cdp/cof/circumstance_service.ts#L1459\n delete (response as any).toObject;\n\n // Merge the cached configs into the just-returned configs,\n // making sure to remove any configs that are marked as deleted -- this will then get cached\n // by the responseCachingHandler as we return up the handler chain.\n const configResults = unionBy(\n \"configId\",\n cachedResponse?.configResults ?? [],\n response.configResults\n ).filter((config) => !config.delete);\n\n // TODO: We hardcode status code and sizeByte values because we do not have access to\n // underlying transport of configs-web.\n // When this ticket is done https://jira.sc-corp.net/browse/CAMKIT-2840,\n // we will remove this handler and benefit from existing ones.\n const status = 200;\n let sizeByte = 0;\n try {\n sizeByte = new TextEncoder().encode(JSON.stringify(response)).byteLength;\n } finally {\n dispatchRequestCompleted(requestStateEventTarget, {\n requestId,\n dimensions,\n status,\n sizeByte,\n });\n }\n\n resolve({\n ...response,\n configResults,\n });\n } catch (error) {\n dispatchRequestErrored(requestStateEventTarget, {\n requestId,\n dimensions,\n error: ensureError(error),\n });\n reject(error);\n }\n });\n }\n )\n // targetingQuery() always converts failed responses into errors (unlike fetch()), so we need a custom\n // retryPredicate that retries all errors. We'll keep retrying (with backoff) for 20 seconds total\n // elapsed time before we return an error back up the chain.\n .map(createRetryingHandler({ retryPredicate: (r) => r instanceof Error }))\n // API gateway has 15 seconds timeout, so we rely on that first\n .map(createTimeoutHandler({ timeout: 20 * 1000 }))\n .map(\n createResponseCachingHandler(\n cofCache,\n getCacheKey,\n // If we have a matching response already in cache,\n // we'll return it immediately and then update the cache in the background.\n staleWhileRevalidateStrategy({\n onMiss: () => {\n metrics.setOperationalMetrics(Count.count(\"cache_miss\", 1, { request_type: \"cof\" }));\n },\n })\n )\n ).handler\n );\n }\n);\n"]}
1
+ {"version":3,"file":"cofHandler.js","sourceRoot":"","sources":["../../src/remote-configuration/cofHandler.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,8BAA8B,EAAE,WAAW,EAAE,MAAM,2DAA2D,CAAC;AAIxH,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAEtE,OAAO,EACH,wBAAwB,EACxB,sBAAsB,EACtB,sBAAsB,EACtB,8BAA8B,GACjC,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,4BAA4B,EAAE,4BAA4B,EAAE,MAAM,oCAAoC,CAAC;AAChH,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAE3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAEtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAMrD,MAAM,CAAC,MAAM,gBAAg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CAAC;iBAC5E;wBAAS;oBACN,wBAAwB,CAAC,uBAAuB,EAAE;wBAC9C,SAAS;wBACT,UAAU;wBACV,MAAM;wBACN,QAAQ;qBACX,CAAC,CAAC;iBACN;gBAED,OAAO,iCACA,QAAQ,KACX,aAAa,IACf,CAAC;aACN;YAAC,OAAO,KAAK,EAAE;gBACZ,sBAAsB,CAAC,uBAAuB,EAAE;oBAC5C,SAAS;oBACT,UAAU;oBACV,KAAK,EAAE,WAAW,CAAC,KAAK,CAAC;iBAC5B,CAAC,CAAC;gBACH,MAAM,CAAC,KAAK,CAAC,CAAC;aACjB;QACL,CAAC,CAAA,CAAC,CAAC;IACP,CAAC,CAAA,CACJ;SAII,GAAG,CAAC,qBAAqB,CAAC,EAAE,cAAc,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,YAAY,KAAK,EAAE,CAAC,CAAC;SAEzE,GAAG,CAAC,oBAAoB,CAAC,EAAE,OAAO,EAAE,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;SACjD,GAAG,CACA,4BAA4B,CACxB,QAAQ,EACR,WAAW,EAGX,4BAA4B,CAAC;QACzB,MAAM,EAAE,GAAG,EAAE;YACT,OAAO,CAAC,qBAAqB,CACzB,KAAK,CAAC,KAAK,CAAC,YAAY,EAAE,CAAC,EAAE,EAAE,YAAY,EAAE,gBAAgB,EAAE,CAAC,CACnE,CAAC;QACN,CAAC;KACJ,CAAC,CACL,CACJ,CAAC,OAAO,CAChB,CAAC;AACN,CAAC,CACJ,CAAC","sourcesContent":["/* eslint-disable max-len */\nimport { BrowserHeaders } from \"browser-headers\";\nimport { getCameraKitUserAgent } from \"../platform/cameraKitUserAgent\";\nimport { ensureError } from \"../common/errorHelpers\";\nimport { unionBy } from \"../common/unionBy\";\nimport { CircumstancesServiceClientImpl, GrpcWebImpl } from \"../generated-proto/pb_schema/cdp/cof/circumstance_service\";\nimport type { ConfigTargetingRequest } from \"../generated-proto/pb_schema/cdp/cof/config_request\";\nimport type { ConfigTargetingResponse } from \"../generated-proto/pb_schema/cdp/cof/config_response\";\nimport type { RequestMetadata } from \"../handlers/HandlerChainBuilder\";\nimport { HandlerChainBuilder } from \"../handlers/HandlerChainBuilder\";\nimport type { RequestStateEventTarget } from \"../handlers/requestStateEmittingHandler\";\nimport {\n dispatchRequestCompleted,\n dispatchRequestErrored,\n dispatchRequestStarted,\n requestStateEventTargetFactory,\n} from \"../handlers/requestStateEmittingHandler\";\nimport { createResponseCachingHandler, staleWhileRevalidateStrategy } from \"../handlers/responseCachingHandler\";\nimport { createRetryingHandler } from \"../handlers/retryingHandler\";\nimport { createTimeoutHandler } from \"../handlers/timeoutHandler\";\nimport { IndexedDBPersistence } from \"../persistence/IndexedDBPersistence\";\nimport type { CameraKitConfiguration } from \"../configuration\";\nimport { configurationToken } from \"../configuration\";\nimport { Injectable } from \"../dependency-injection/Injectable\";\nimport { getLogger } from \"../logger/logger\";\nimport { ExpiringPersistence } from \"../persistence/ExpiringPersistence\";\nimport { convertDaysToSeconds } from \"../common/time\";\nimport type { MetricsClient } from \"../clients/metricsClient\";\nimport { metricsClientFactory } from \"../clients/metricsClient\";\nimport { Count } from \"../metrics/operational/Count\";\n\nexport interface Metadata {\n [key: string]: string;\n}\n\nexport const COF_REQUEST_TYPE = \"cof\";\n\nexport type CofDimensions = { requestType: typeof COF_REQUEST_TYPE; delta: string };\n\nconst logger = getLogger(\"cofHandler\");\n\n/**\n * Handler chain used to make COF requests. Uses the COF client to perform the\n * requests, with retries, timeout, and caching.\n *\n * The handler will first attempt to retrieve the COF response from cache. If it is found, the result is returned\n * immediately and the cache is updated in the background. If no response is found, a COF request is made. This request\n * will retry (with exponential backoff + jitter) for 5 seconds before returning an error to the caller.\n */\nexport const cofHandlerFactory = Injectable(\n \"cofHandler\",\n [configurationToken, requestStateEventTargetFactory.token, metricsClientFactory.token] as const,\n (config: CameraKitConfiguration, requestStateEventTarget: RequestStateEventTarget, metrics: MetricsClient) => {\n const cofCache = new ExpiringPersistence<ConfigTargetingResponse>(\n () => convertDaysToSeconds(365),\n new IndexedDBPersistence({ databaseName: \"COFCache\" })\n );\n const getCacheKey = (r: Partial<ConfigTargetingRequest>) => JSON.stringify(r);\n // We need to wrap `targetingQuery` to create a usable Handler – the main issue is that HandlerChainBuilder\n // always adds a `signal` property to the metadata argument (second argument of the Handler), but\n // `targetingQuery` expects the second argument to only contain headers.\n return (\n new HandlerChainBuilder(\n async (\n request: Partial<ConfigTargetingRequest>,\n { signal, isSideEffect: _, ...metadata }: Metadata & RequestMetadata\n ) => {\n const rpc = new GrpcWebImpl(`https://${config.apiHostname}`, {});\n const client = new CircumstancesServiceClientImpl(rpc);\n return new Promise<ConfigTargetingResponse>(async (resolve, reject) => {\n if (signal) {\n signal.addEventListener(\"abort\", () =>\n reject(new Error(\"COF request aborted by handler chain.\"))\n );\n }\n\n const cachedResponse = await cofCache.retrieve(getCacheKey(request)).catch((e) => {\n logger.warn(\"Unable to get COF response from cache.\", e);\n return {\n configResultsEtag: undefined,\n configResults: [],\n };\n });\n const dimensions: CofDimensions = {\n requestType: COF_REQUEST_TYPE,\n delta: `${!!cachedResponse?.configResultsEtag}`,\n };\n const { requestId } = dispatchRequestStarted(requestStateEventTarget, { dimensions });\n\n try {\n const response = await client.targetingQuery(\n {\n ...request,\n configResultsEtag: cachedResponse?.configResultsEtag,\n deltaSync: !!cachedResponse?.configResultsEtag,\n },\n new BrowserHeaders({\n authorization: `Bearer ${config.apiToken}`,\n \"x-snap-client-user-agent\": getCameraKitUserAgent(),\n ...metadata,\n })\n );\n\n // NOTE: in order for cache persistance to work, we need to make the\n // object cloneable i.e. with no methods (it appears targetingQuery()\n // attaches toObject() to response object). Safety: We have to cast response\n // object to a type that has toObject defined, because that is indeed\n // what generated code has:\n // eslint-disable-next-line max-len\n // https://github.sc-corp.net/Snapchat/camera-kit-web-sdk/blob/8d6b4e8bfa3717b376ab197a49972a1e410851f7/packages/web-sdk/src/generated-proto/pb_schema/cdp/cof/circumstance_service.ts#L1459\n delete (response as any).toObject;\n\n // Merge the cached configs into the just-returned configs,\n // making sure to remove any configs that are marked as deleted -- this will then get cached\n // by the responseCachingHandler as we return up the handler chain.\n const configResults = unionBy(\n \"configId\",\n cachedResponse?.configResults ?? [],\n response.configResults\n ).filter((config) => !config.delete);\n\n // TODO: We hardcode status code and sizeByte values because we do not have access to\n // underlying transport of configs-web.\n // When this ticket is done https://jira.sc-corp.net/browse/CAMKIT-2840,\n // we will remove this handler and benefit from existing ones.\n const status = 200;\n let sizeByte = 0;\n try {\n sizeByte = new TextEncoder().encode(JSON.stringify(response)).byteLength;\n } finally {\n dispatchRequestCompleted(requestStateEventTarget, {\n requestId,\n dimensions,\n status,\n sizeByte,\n });\n }\n\n resolve({\n ...response,\n configResults,\n });\n } catch (error) {\n dispatchRequestErrored(requestStateEventTarget, {\n requestId,\n dimensions,\n error: ensureError(error),\n });\n reject(error);\n }\n });\n }\n )\n // targetingQuery() always converts failed responses into errors (unlike fetch()), so we need a custom\n // retryPredicate that retries all errors. We'll keep retrying (with backoff) for 20 seconds total\n // elapsed time before we return an error back up the chain.\n .map(createRetryingHandler({ retryPredicate: (r) => r instanceof Error }))\n // API gateway has 15 seconds timeout, so we rely on that first\n .map(createTimeoutHandler({ timeout: 20 * 1000 }))\n .map(\n createResponseCachingHandler(\n cofCache,\n getCacheKey,\n // If we have a matching response already in cache,\n // we'll return it immediately and then update the cache in the background.\n staleWhileRevalidateStrategy({\n onMiss: () => {\n metrics.setOperationalMetrics(\n Count.count(\"cache_miss\", 1, { request_type: COF_REQUEST_TYPE })\n );\n },\n })\n )\n ).handler\n );\n }\n);\n"]}