@snap/camera-kit 1.14.0 → 1.15.1

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 (270) hide show
  1. package/README.md +1 -1
  2. package/dist/CameraKit.d.ts +2 -2
  3. package/dist/CameraKit.d.ts.map +1 -1
  4. package/dist/CameraKit.js +4 -0
  5. package/dist/CameraKit.js.map +1 -1
  6. package/dist/RootServices.d.ts +5 -2
  7. package/dist/RootServices.d.ts.map +1 -1
  8. package/dist/RootServices.js.map +1 -1
  9. package/dist/bootstrapCameraKit.d.ts.map +1 -1
  10. package/dist/bootstrapCameraKit.js +5 -2
  11. package/dist/bootstrapCameraKit.js.map +1 -1
  12. package/dist/clients/metricsClient.d.ts +16 -3
  13. package/dist/clients/metricsClient.d.ts.map +1 -1
  14. package/dist/clients/metricsClient.js +14 -6
  15. package/dist/clients/metricsClient.js.map +1 -1
  16. package/dist/configuration.d.ts +52 -2
  17. package/dist/configuration.d.ts.map +1 -1
  18. package/dist/configuration.js +1 -0
  19. package/dist/configuration.js.map +1 -1
  20. package/dist/environment.js +1 -1
  21. package/dist/environment.js.map +1 -1
  22. package/dist/index.d.ts +4 -2
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +2 -1
  25. package/dist/index.js.map +1 -1
  26. package/dist/lens/analytics/lensAnalyticEventsHandler.d.ts +9 -0
  27. package/dist/lens/analytics/lensAnalyticEventsHandler.d.ts.map +1 -0
  28. package/dist/lens/analytics/lensAnalyticEventsHandler.js +5 -0
  29. package/dist/lens/analytics/lensAnalyticEventsHandler.js.map +1 -0
  30. package/dist/lens/analytics/registerLensAnalyticEventsHandler.d.ts +35 -0
  31. package/dist/lens/analytics/registerLensAnalyticEventsHandler.d.ts.map +1 -0
  32. package/dist/lens/analytics/registerLensAnalyticEventsHandler.js +13 -0
  33. package/dist/lens/analytics/registerLensAnalyticEventsHandler.js.map +1 -0
  34. package/dist/lensCoreWasmVersions.js +3 -3
  35. package/dist/lensCoreWasmVersions.js.map +1 -1
  36. package/dist/remote-configuration/configurationProvider.d.ts +15 -0
  37. package/dist/remote-configuration/configurationProvider.d.ts.map +1 -0
  38. package/dist/remote-configuration/configurationProvider.js +32 -0
  39. package/dist/remote-configuration/configurationProvider.js.map +1 -0
  40. package/dist/remote-configuration/preloadConfiguration.d.ts.map +1 -1
  41. package/dist/remote-configuration/preloadConfiguration.js +18 -6
  42. package/dist/remote-configuration/preloadConfiguration.js.map +1 -1
  43. package/dist/remote-configuration/util.d.ts +4 -0
  44. package/dist/remote-configuration/util.d.ts.map +1 -0
  45. package/dist/remote-configuration/util.js +17 -0
  46. package/dist/remote-configuration/util.js.map +1 -0
  47. package/dist/uri-handlers/internal-handlers/httpUriHandler.d.ts +7 -5
  48. package/dist/uri-handlers/internal-handlers/httpUriHandler.d.ts.map +1 -1
  49. package/dist/uri-handlers/internal-handlers/httpUriHandler.js +4 -4
  50. package/dist/uri-handlers/internal-handlers/httpUriHandler.js.map +1 -1
  51. package/dist/uri-handlers/internal-handlers/httpValidators.d.ts +2 -1
  52. package/dist/uri-handlers/internal-handlers/httpValidators.d.ts.map +1 -1
  53. package/dist/uri-handlers/internal-handlers/httpValidators.js +13 -1
  54. package/dist/uri-handlers/internal-handlers/httpValidators.js.map +1 -1
  55. package/dist/uri-handlers/uriHandlersRegister.d.ts.map +1 -1
  56. package/dist/uri-handlers/uriHandlersRegister.js +1 -1
  57. package/dist/uri-handlers/uriHandlersRegister.js.map +1 -1
  58. package/docs/html/assets/hierarchy.js +1 -1
  59. package/docs/html/assets/navigation.js +1 -1
  60. package/docs/html/assets/search.js +1 -1
  61. package/docs/html/classes/CameraKit.html +2 -2
  62. package/docs/html/classes/CameraKitSession.html +2 -2
  63. package/docs/html/classes/CameraKitSource.html +2 -2
  64. package/docs/html/classes/LensPerformanceMeasurement.html +2 -2
  65. package/docs/html/classes/LensPerformanceMetrics.html +2 -2
  66. package/docs/html/classes/LensRepository.html +2 -2
  67. package/docs/html/classes/Transform2D.html +2 -2
  68. package/docs/html/classes/TypedCustomEvent.html +3 -3
  69. package/docs/html/classes/TypedEventTarget.html +2 -2
  70. package/docs/html/enums/Lens_CameraFacing.html +2 -2
  71. package/docs/html/functions/bootstrapCameraKit.html +2 -2
  72. package/docs/html/functions/createExtension.html +2 -2
  73. package/docs/html/functions/createImageSource.html +2 -2
  74. package/docs/html/functions/createMediaStreamSource.html +2 -2
  75. package/docs/html/functions/createVideoSource.html +2 -2
  76. package/docs/html/functions/estimateLensPerformance.html +2 -2
  77. package/docs/html/functions/filePickerFactory.html +2 -2
  78. package/docs/html/functions/getExtensionRequestContext.html +2 -2
  79. package/docs/html/functions/lensSourcesFactory.html +2 -2
  80. package/docs/html/functions/remoteApiServicesFactory.html +1 -1
  81. package/docs/html/hierarchy.html +1 -1
  82. package/docs/html/index.html +3 -3
  83. package/docs/html/interfaces/BitmojiUserInfo.html +2 -2
  84. package/docs/html/interfaces/CameraKitBootstrapConfiguration.html +24 -5
  85. package/docs/html/interfaces/CameraKitDeviceOptions.html +3 -3
  86. package/docs/html/interfaces/CameraKitSourceInfo.html +2 -2
  87. package/docs/html/interfaces/CameraKitSourceSubscriber.html +2 -2
  88. package/docs/html/interfaces/ComputedFrameMetrics.html +2 -2
  89. package/docs/html/interfaces/CreateSessionOptions.html +2 -2
  90. package/docs/html/interfaces/EstimatedLensPerformance.html +2 -2
  91. package/docs/html/interfaces/Font.html +2 -2
  92. package/docs/html/interfaces/FriendUserInfo.html +2 -2
  93. package/docs/html/interfaces/FunctionSourceOptions.html +2 -2
  94. package/docs/html/interfaces/Keyboard.html +2 -2
  95. package/docs/html/interfaces/KeyboardActiveEvent.html +2 -2
  96. package/docs/html/interfaces/Lens.html +2 -2
  97. package/docs/html/interfaces/LensCreator.html +2 -2
  98. package/docs/html/interfaces/LensHttpRequest.html +2 -2
  99. package/docs/html/interfaces/LensLaunchData.html +2 -2
  100. package/docs/html/interfaces/LensSource.html +2 -2
  101. package/docs/html/interfaces/LensUserData.html +2 -2
  102. package/docs/html/interfaces/LoadAssetRequest.html +2 -2
  103. package/docs/html/interfaces/MediaStreamSourceOptions.html +3 -3
  104. package/docs/html/interfaces/Preview.html +2 -2
  105. package/docs/html/interfaces/RemoteApiRequest.html +2 -2
  106. package/docs/html/interfaces/RemoteApiResponse.html +2 -2
  107. package/docs/html/interfaces/RemoteApiService.html +2 -2
  108. package/docs/html/interfaces/ScreenRegion.html +2 -2
  109. package/docs/html/interfaces/Snapcode.html +2 -2
  110. package/docs/html/interfaces/UriCancelRequest.html +2 -2
  111. package/docs/html/interfaces/UriRequest.html +2 -2
  112. package/docs/html/interfaces/UriResponse.html +2 -2
  113. package/docs/html/interfaces/VideoSourceOptions.html +3 -3
  114. package/docs/html/modules.html +1 -1
  115. package/docs/html/types/ArgumentValidationError.html +2 -2
  116. package/docs/html/types/AssetLoader.html +2 -2
  117. package/docs/html/types/AssetResponse.html +1 -1
  118. package/docs/html/types/AssetTiming.html +2 -2
  119. package/docs/html/types/BenchmarkError.html +1 -1
  120. package/docs/html/types/BootstrapError.html +2 -2
  121. package/docs/html/types/CacheKeyNotFoundError.html +1 -1
  122. package/docs/html/types/CameraKitSessionEventListener.html +2 -2
  123. package/docs/html/types/CameraKitSessionEvents.html +2 -2
  124. package/docs/html/types/CameraKitSourceError.html +1 -1
  125. package/docs/html/types/ConfigurationError.html +2 -2
  126. package/docs/html/types/FetchHandler.html +1 -1
  127. package/docs/html/types/FilePicker.html +2 -2
  128. package/docs/html/types/FilePickerOptions.html +2 -2
  129. package/docs/html/types/FilePickerResult.html +2 -2
  130. package/docs/html/types/KeyboardEventListener.html +2 -2
  131. package/docs/html/types/KeyboardEvents.html +2 -2
  132. package/docs/html/types/LegalError.html +1 -1
  133. package/docs/html/types/LensAbortError.html +2 -2
  134. package/docs/html/types/LensAssetError.html +2 -2
  135. package/docs/html/types/LensContentValidationError.html +1 -1
  136. package/docs/html/types/LensError.html +1 -1
  137. package/docs/html/types/LensExecutionError.html +2 -2
  138. package/docs/html/types/LensHttpHandler.html +2 -2
  139. package/docs/html/types/LensImagePickerError.html +2 -2
  140. package/docs/html/types/LensLaunchParams.html +2 -2
  141. package/docs/html/types/LensMetricsEvents.html +2 -2
  142. package/docs/html/types/LensPerformanceCluster.html +1 -1
  143. package/docs/html/types/LensView.html +2 -2
  144. package/docs/html/types/LensWait.html +2 -2
  145. package/docs/html/types/LogLevel.html +2 -2
  146. package/docs/html/types/Logger.html +2 -2
  147. package/docs/html/types/Matrix.html +2 -2
  148. package/docs/html/types/OpenDefaultFilePicker.html +2 -2
  149. package/docs/html/types/PersistentStoreError.html +2 -2
  150. package/docs/html/types/PickedFile.html +2 -2
  151. package/docs/html/types/PlatformNotSupportedError.html +2 -2
  152. package/docs/html/types/PublicContainer.html +2 -2
  153. package/docs/html/types/PublicServices.html +2 -2
  154. package/docs/html/types/RemoteApiCancelRequestHandler.html +2 -2
  155. package/docs/html/types/RemoteApiRequestHandler.html +2 -2
  156. package/docs/html/types/RemoteApiServices.html +1 -1
  157. package/docs/html/types/RemoteApiStatus.html +2 -2
  158. package/docs/html/types/RenderTarget.html +2 -2
  159. package/docs/html/types/ScreenRegionType.html +2 -2
  160. package/docs/html/types/ScreenRegions.html +2 -2
  161. package/docs/html/types/Uri.html +1 -1
  162. package/docs/html/types/ValidationStrategy.html +11 -0
  163. package/docs/html/types/WebGLError.html +1 -1
  164. package/docs/html/types/Zodiac.html +1 -1
  165. package/docs/html/variables/extensionRequestContext.html +2 -2
  166. package/docs/md/README.md +2 -2
  167. package/docs/md/classes/CameraKit.md +1 -1
  168. package/docs/md/classes/CameraKitSession.md +1 -1
  169. package/docs/md/classes/CameraKitSource.md +1 -1
  170. package/docs/md/classes/LensPerformanceMeasurement.md +1 -1
  171. package/docs/md/classes/LensPerformanceMetrics.md +1 -1
  172. package/docs/md/classes/LensRepository.md +1 -1
  173. package/docs/md/classes/Transform2D.md +1 -1
  174. package/docs/md/classes/TypedCustomEvent.md +1 -1
  175. package/docs/md/classes/TypedEventTarget.md +1 -1
  176. package/docs/md/enumerations/Lens_CameraFacing.md +1 -1
  177. package/docs/md/functions/bootstrapCameraKit.md +1 -1
  178. package/docs/md/functions/createExtension.md +1 -1
  179. package/docs/md/functions/createImageSource.md +1 -1
  180. package/docs/md/functions/createMediaStreamSource.md +1 -1
  181. package/docs/md/functions/createVideoSource.md +1 -1
  182. package/docs/md/functions/estimateLensPerformance.md +1 -1
  183. package/docs/md/functions/filePickerFactory.md +1 -1
  184. package/docs/md/functions/getExtensionRequestContext.md +1 -1
  185. package/docs/md/functions/lensSourcesFactory.md +1 -1
  186. package/docs/md/functions/remoteApiServicesFactory.md +1 -1
  187. package/docs/md/globals.md +3 -2
  188. package/docs/md/interfaces/BitmojiUserInfo.md +1 -1
  189. package/docs/md/interfaces/CameraKitBootstrapConfiguration.md +43 -3
  190. package/docs/md/interfaces/CameraKitDeviceOptions.md +1 -1
  191. package/docs/md/interfaces/CameraKitSourceInfo.md +1 -1
  192. package/docs/md/interfaces/CameraKitSourceSubscriber.md +1 -1
  193. package/docs/md/interfaces/ComputedFrameMetrics.md +1 -1
  194. package/docs/md/interfaces/CreateSessionOptions.md +1 -1
  195. package/docs/md/interfaces/EstimatedLensPerformance.md +1 -1
  196. package/docs/md/interfaces/Font.md +1 -1
  197. package/docs/md/interfaces/FriendUserInfo.md +1 -1
  198. package/docs/md/interfaces/FunctionSourceOptions.md +1 -1
  199. package/docs/md/interfaces/Keyboard.md +1 -1
  200. package/docs/md/interfaces/KeyboardActiveEvent.md +1 -1
  201. package/docs/md/interfaces/Lens.md +1 -1
  202. package/docs/md/interfaces/LensCreator.md +1 -1
  203. package/docs/md/interfaces/LensHttpRequest.md +1 -1
  204. package/docs/md/interfaces/LensLaunchData.md +1 -1
  205. package/docs/md/interfaces/LensSource.md +1 -1
  206. package/docs/md/interfaces/LensUserData.md +1 -1
  207. package/docs/md/interfaces/LoadAssetRequest.md +1 -1
  208. package/docs/md/interfaces/MediaStreamSourceOptions.md +1 -1
  209. package/docs/md/interfaces/Preview.md +1 -1
  210. package/docs/md/interfaces/RemoteApiRequest.md +1 -1
  211. package/docs/md/interfaces/RemoteApiResponse.md +1 -1
  212. package/docs/md/interfaces/RemoteApiService.md +1 -1
  213. package/docs/md/interfaces/ScreenRegion.md +1 -1
  214. package/docs/md/interfaces/Snapcode.md +1 -1
  215. package/docs/md/interfaces/UriCancelRequest.md +1 -1
  216. package/docs/md/interfaces/UriRequest.md +1 -1
  217. package/docs/md/interfaces/UriResponse.md +1 -1
  218. package/docs/md/interfaces/VideoSourceOptions.md +1 -1
  219. package/docs/md/type-aliases/ArgumentValidationError.md +1 -1
  220. package/docs/md/type-aliases/AssetLoader.md +1 -1
  221. package/docs/md/type-aliases/AssetResponse.md +1 -1
  222. package/docs/md/type-aliases/AssetTiming.md +1 -1
  223. package/docs/md/type-aliases/BenchmarkError.md +1 -1
  224. package/docs/md/type-aliases/BootstrapError.md +1 -1
  225. package/docs/md/type-aliases/CacheKeyNotFoundError.md +1 -1
  226. package/docs/md/type-aliases/CameraKitSessionEventListener.md +1 -1
  227. package/docs/md/type-aliases/CameraKitSessionEvents.md +1 -1
  228. package/docs/md/type-aliases/CameraKitSourceError.md +1 -1
  229. package/docs/md/type-aliases/ConfigurationError.md +1 -1
  230. package/docs/md/type-aliases/FetchHandler.md +1 -1
  231. package/docs/md/type-aliases/FilePicker.md +1 -1
  232. package/docs/md/type-aliases/FilePickerOptions.md +1 -1
  233. package/docs/md/type-aliases/FilePickerResult.md +1 -1
  234. package/docs/md/type-aliases/KeyboardEventListener.md +1 -1
  235. package/docs/md/type-aliases/KeyboardEvents.md +1 -1
  236. package/docs/md/type-aliases/LegalError.md +1 -1
  237. package/docs/md/type-aliases/LensAbortError.md +1 -1
  238. package/docs/md/type-aliases/LensAssetError.md +1 -1
  239. package/docs/md/type-aliases/LensContentValidationError.md +1 -1
  240. package/docs/md/type-aliases/LensError.md +1 -1
  241. package/docs/md/type-aliases/LensExecutionError.md +1 -1
  242. package/docs/md/type-aliases/LensHttpHandler.md +1 -1
  243. package/docs/md/type-aliases/LensImagePickerError.md +1 -1
  244. package/docs/md/type-aliases/LensLaunchParams.md +1 -1
  245. package/docs/md/type-aliases/LensMetricsEvents.md +1 -1
  246. package/docs/md/type-aliases/LensPerformanceCluster.md +1 -1
  247. package/docs/md/type-aliases/LensView.md +1 -1
  248. package/docs/md/type-aliases/LensWait.md +1 -1
  249. package/docs/md/type-aliases/LogLevel.md +1 -1
  250. package/docs/md/type-aliases/Logger.md +1 -1
  251. package/docs/md/type-aliases/Matrix.md +1 -1
  252. package/docs/md/type-aliases/OpenDefaultFilePicker.md +1 -1
  253. package/docs/md/type-aliases/PersistentStoreError.md +1 -1
  254. package/docs/md/type-aliases/PickedFile.md +1 -1
  255. package/docs/md/type-aliases/PlatformNotSupportedError.md +1 -1
  256. package/docs/md/type-aliases/PublicContainer.md +1 -1
  257. package/docs/md/type-aliases/PublicServices.md +2 -2
  258. package/docs/md/type-aliases/RemoteApiCancelRequestHandler.md +1 -1
  259. package/docs/md/type-aliases/RemoteApiRequestHandler.md +1 -1
  260. package/docs/md/type-aliases/RemoteApiServices.md +1 -1
  261. package/docs/md/type-aliases/RemoteApiStatus.md +1 -1
  262. package/docs/md/type-aliases/RenderTarget.md +1 -1
  263. package/docs/md/type-aliases/ScreenRegionType.md +1 -1
  264. package/docs/md/type-aliases/ScreenRegions.md +1 -1
  265. package/docs/md/type-aliases/Uri.md +1 -1
  266. package/docs/md/type-aliases/ValidationStrategy.md +22 -0
  267. package/docs/md/type-aliases/WebGLError.md +1 -1
  268. package/docs/md/type-aliases/Zodiac.md +1 -1
  269. package/docs/md/variables/extensionRequestContext.md +1 -1
  270. package/package.json +2 -2
package/README.md CHANGED
@@ -182,7 +182,7 @@ session.pause("capture");
182
182
 
183
183
  ## Error Handling
184
184
 
185
- Camera Kit Web SDK methods may throw errors, or return rejected Promises -- these are documented in the [API docs](https://kit.snapchat.com/reference/CameraKit/web/1.14.0/index.html). It is good practice to handle such cases, to provide a good experience to your users.
185
+ Camera Kit Web SDK methods may throw errors, or return rejected Promises -- these are documented in the [API docs](https://kit.snapchat.com/reference/CameraKit/web/1.15.1/index.html). It is good practice to handle such cases, to provide a good experience to your users.
186
186
 
187
187
  Errors may also occur during Lens rendering. For example, Lenses contain their own scripting, which could throw an error. A rendering error could also occur if a Lens attempts to use a feature that is not supported by Camera Kit Web SDK.
188
188
 
@@ -322,9 +322,9 @@ export declare const cameraKitFactory: {
322
322
  token: "lensPersistenceStore";
323
323
  dependencies: readonly ["lensCore"];
324
324
  }, {
325
- (args_0: import("rxjs").Subject<import(".").Metric>, args_1: import("./clients/grpcHandler").GrpcHandler, args_2: PageVisibility): import("./clients/metricsClient").MetricsClient;
325
+ (args_0: import("rxjs").Subject<import(".").Metric>, args_1: import("rxjs").Observable<import(".").Metric>[], args_2: import("./clients/grpcHandler").GrpcHandler, args_3: PageVisibility): import("./clients/metricsClient").MetricsClient;
326
326
  token: "metricsClient";
327
- dependencies: readonly ["externalMetricsSubject", "grpcHandlerFactory", "pageVisibility"];
327
+ dependencies: readonly ["externalMetricsSubject", "externalMetrics", "grpcHandlerFactory", "pageVisibility"];
328
328
  }, {
329
329
  (args_0: LensCore, args_1: import(".").AssetLoader, args_2: import(".").AssetLoader, args_3: import(".").AssetLoader, args_4: MetricsEventTarget, args_5: import("./handlers/requestStateEmittingHandler").RequestStateEventTarget): import("./lens/assets/LensAssetRepository").LensAssetRepository;
330
330
  token: "lensAssetRepository";
@@ -1 +1 @@
1
- {"version":3,"file":"CameraKit.d.ts","sourceRoot":"","sources":["../src/CameraKit.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;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OAEG;IACM,cAAc,EAAE,cAAc,EAEtB,QAAQ,EAAE,QAAQ,EAClB,cAAc,EAAE,cAAc,EAC9B,SAAS,EAAE,SAAS,CAAC,YAAY,CAAC,EAClC,YAAY,EAAE,mBAAmB,EAClD,UAAU,EAAE,kBAAkB;IAUlC;;;;;;;;;;;;;;;;OAgBG;IAEG,aAAa,CAAC,EAChB,gBAAgB,EAChB,oBAAoB,GACvB,GAAE,oBAAyB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAkHxD;;OAEG;IAEG,OAAO;CAMhB;AAED,gBAAgB;AAChB,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkB5B,CAAC"}
package/dist/CameraKit.js CHANGED
@@ -19,10 +19,12 @@ import { errorLoggingDecorator } from "./logger/errorLoggingDecorator";
19
19
  import { TypedEventTarget } from "./events/TypedEventTarget";
20
20
  import { pageVisibilityFactory } from "./common/pageVisibility";
21
21
  import { setPreloadedConfiguration } from "./remote-configuration/preloadConfiguration";
22
+ import { registerConfigurationProvider } from "./remote-configuration/configurationProvider";
22
23
  import { getTrustedTypesHandler } from "./trusted-types/trustedTypesHandler";
23
24
  import { remoteConfigurationFactory } from "./remote-configuration/remoteConfiguration";
24
25
  import { registerGeoDataProvider } from "./geo/registerGeoDataProvider";
25
26
  import { frameEventsFactory } from "./session/frameEvents";
27
+ import { registerLensAnalyticEventsHandler } from "./lens/analytics/registerLensAnalyticEventsHandler";
26
28
  const logger = getLogger("CameraKit");
27
29
  const publicMetricsEventNames = ["lensView", "lensWait"];
28
30
  export let CameraKit = (() => {
@@ -98,7 +100,9 @@ export let CameraKit = (() => {
98
100
  .run(registerLensAssetsProvider)
99
101
  .run(registerLensClientInterfaceHandler)
100
102
  .run(registerGeoDataProvider)
103
+ .run(registerConfigurationProvider)
101
104
  .run(setPreloadedConfiguration)
105
+ .run(registerLensAnalyticEventsHandler)
102
106
  .run(reportSessionScopedMetrics)
103
107
  .run(registerUriHandlers);
104
108
  const session = sessionContainer.get(cameraKitSessionFactory.token);
@@ -1 +1 @@
1
- {"version":3,"file":"CameraKit.js","sourceRoot":"","sources":["../src/CameraKit.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAEtC,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAI9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,EAAE,0BAA0B,EAAE,MAAM,kCAAkC,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAEzE,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,kCAAkC,EAAE,MAAM,6CAA6C,CAAC;AACjG,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,WAAW,E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;YAMK,OAAO;;oBACT,WAAW,EAAE,CAAC;oBACd,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC;oBAC9B,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;oBACrE,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;gBACvB,CAAC;aAAA;;;yCA7HA,qBAAqB,CAAC,MAAM,CAAC;mCAuH7B,qBAAqB,CAAC,MAAM,CAAC;YAtH9B,wLAAM,aAAa,wCAiHlB;YAMD,sKAAM,OAAO,wCAKZ;;;;AAIL,MAAM,CAAC,MAAM,gBAAgB,GAAG,UAAU,CACtC,WAAW,EACX;IACI,qBAAqB,CAAC,KAAK;IAC3B,yBAAyB,CAAC,KAAK;IAC/B,eAAe,CAAC,KAAK;IACrB,qBAAqB,CAAC,KAAK;IAC3B,0BAA0B,CAAC,KAAK;IAChC,SAAS;CACH,EACV,CACI,cAA8B,EAC9B,OAA2B,EAC3B,QAAkB,EAClB,cAA8B,EAC9B,mBAAwC,EACxC,SAAkC,EACpC,EAAE,CAAC,IAAI,SAAS,CAAC,cAAc,EAAE,QAAQ,EAAE,cAAc,EAAE,SAAS,EAAE,mBAAmB,EAAE,OAAO,CAAC,CACxG,CAAC","sourcesContent":["import type { Container } from \"@snap/ts-inject\";\nimport { CONTAINER, Injectable } from \"@snap/ts-inject\";\nimport { firstValueFrom } from \"rxjs\";\nimport type { LensRepository } from \"./lens/LensRepository\";\nimport { lensRepositoryFactory } from \"./lens/LensRepository\";\nimport type { LensCoreError } from \"./lens-core-module/lensCoreError\";\nimport type { LensCore } from \"./lens-core-module/lensCore\";\nimport type { CameraKitSession } from \"./session/CameraKitSession\";\nimport { cameraKitSessionFactory } from \"./session/CameraKitSession\";\nimport { registerLensAssetsProvider } from \"./lens/assets/LensAssetsProvider\";\nimport { lensCoreFactory } from \"./lens-core-module/loader/lensCoreFactory\";\nimport { configurationToken } from \"./configuration\";\nimport type { RootServices } from \"./RootServices\";\nimport { registerUriHandlers } from \"./uri-handlers/uriHandlersRegister\";\nimport type { MetricsEventTarget } from \"./metrics/metricsEventTarget\";\nimport { metricsEventTargetFactory } from \"./metrics/metricsEventTarget\";\nimport { reportSessionScopedMetrics } from \"./metrics/reporters/reporters\";\nimport { lensStateFactory } from \"./session/lensState\";\nimport { lensKeyboardFactory } from \"./session/LensKeyboard\";\nimport { registerLensClientInterfaceHandler } from \"./lens-client-interface/lensClientInterface\";\nimport { sessionStateFactory } from \"./session/sessionState\";\nimport { lensExecutionError, lensAbortError } from \"./namedErrors\";\nimport { getLogger, resetLogger } from \"./logger/logger\";\nimport { errorLoggingDecorator } from \"./logger/errorLoggingDecorator\";\nimport { TypedEventTarget } from \"./events/TypedEventTarget\";\nimport type { TypedCustomEvent } from \"./events/TypedCustomEvent\";\nimport type { LensView } from \"./metrics/reporters/reportLensView\";\nimport type { LensWait } from \"./metrics/reporters/reportLensWait\";\nimport type { PageVisibility } from \"./common/pageVisibility\";\nimport { pageVisibilityFactory } from \"./common/pageVisibility\";\nimport { setPreloadedConfiguration } from \"./remote-configuration/preloadConfiguration\";\nimport type { RemoteConfiguration } from \"./remote-configuration/remoteConfiguration\";\nimport { getTrustedTypesHandler } from \"./trusted-types/trustedTypesHandler\";\nimport { remoteConfigurationFactory } from \"./remote-configuration/remoteConfiguration\";\nimport { registerGeoDataProvider } from \"./geo/registerGeoDataProvider\";\nimport { frameEventsFactory } from \"./session/frameEvents\";\n\nconst logger = getLogger(\"CameraKit\");\n\n/**\n * Metrics event names that are exposed to apps.\n */\nconst publicMetricsEventNames: Array<LensMetricsEvents[\"detail\"][\"name\"]> = [\"lensView\", \"lensWait\"];\n\n/**\n * Lens metrics events.\n *\n * These events are emitted by {@link CameraKit} to report lens usage, performance, apply latency, etc.\n *\n * @category Lenses\n * @category Metrics\n */\nexport type LensMetricsEvents =\n | TypedCustomEvent<LensView[\"name\"], LensView>\n | TypedCustomEvent<LensWait[\"name\"], LensWait>;\n\n/**\n * Options available when creating a {@link CameraKitSession}.\n *\n * @category Rendering\n */\nexport interface CreateSessionOptions {\n /**\n * Optionally provide an existing canvas element, on which the Live RenderTarget will be rendered.\n *\n * If this is not provided, CameraKit will create a new canvas element which can be added to the DOM.\n */\n liveRenderTarget?: HTMLCanvasElement;\n\n /**\n * Browsers optimize tabs when they are hidden - for example, by pausing the execution of requestAnimationFrame\n * callbacks.\n *\n * If you need the CameraKitSession to continue rendering even when the tab is in the background, set this to true.\n * There is a small performance penalty, and it's a good practice to only render in the background if absolutely\n * necessary.\n */\n renderWhileTabHidden?: boolean;\n}\n\n/**\n * The entry point to the CameraKit SDK's API. Most of CameraKit's features are accessed via this class.\n *\n * Applications obtain an instance of CameraKit by calling {@link bootstrapCameraKit}.\n *\n * @example\n * ```ts\n * const cameraKit = await bootstrapCameraKit(config)\n * ```\n *\n * Then this class can be used to:\n * - Create a {@link CameraKitSession} instance, which provides the API for setting up media inputs, applying Lenses,\n * and obtaining rendered `<canvas>` outputs.\n * - Query for lenses using {@link LensRepository}.\n * - Listen for lens usage metrics events using {@link MetricsEventTarget}.\n *\n * @category Rendering\n * @category Lenses\n */\nexport class CameraKit {\n /** @deprecated Use {@link lensRepository} */\n readonly lenses: { repository: LensRepository };\n\n /**\n * Business metrics (e.g. each time a lens is viewed) are emitted here.\n */\n readonly metrics: TypedEventTarget<LensMetricsEvents> = new TypedEventTarget();\n\n private sessions: CameraKitSession[] = [];\n\n /** @internal */\n constructor(\n /**\n * Used to query for lenses and lens groups.\n */\n readonly lensRepository: LensRepository,\n\n private readonly lensCore: LensCore,\n private readonly pageVisibility: PageVisibility,\n private readonly container: Container<RootServices>,\n private readonly remoteConfig: RemoteConfiguration,\n allMetrics: MetricsEventTarget\n ) {\n this.lenses = { repository: this.lensRepository };\n // Proxy only a subset of all metrics events to the public-facing emitter -- applications don't need to\n // know about most events.\n publicMetricsEventNames.forEach((eventName) => {\n allMetrics.addEventListener(eventName, (e) => this.metrics.dispatchEvent(e));\n });\n }\n\n /**\n * Create a CameraKitSession.\n *\n * This initializes the rendering engine and returns a {@link CameraKitSession} instance, which provides access\n * to Lens rendering.\n *\n * @example\n * ```ts\n * const cameraKit = await bootstrapCameraKit(config)\n * const session = await cameraKit.createSession()\n *\n * const lens = await cameraKit.lensRepository.loadLens(lensId, groupId)\n * session.applyLens(lens)\n * ```\n *\n * @param options\n */\n @errorLoggingDecorator(logger)\n async createSession({\n liveRenderTarget,\n renderWhileTabHidden,\n }: CreateSessionOptions = {}): Promise<CameraKitSession> {\n // Any error happened during lens rendering can be processed by subscribing to sessionErrors\n const exceptionHandler = (error: LensCoreError) => {\n if (error.name === \"LensCoreAbortError\") {\n logger.error(\n lensAbortError(\n \"Unrecoverable error occurred during lens execution. \" +\n \"The CameraKitSession will be destroyed.\",\n error\n )\n );\n } else {\n logger.error(\n lensExecutionError(\n \"Error occurred during lens execution. \" +\n \"The lens cannot be rendered and will be removed from the CameraKitSession.\",\n error\n )\n );\n }\n };\n\n const config = this.container.get(configurationToken);\n\n /**\n * If/when we add support for multiple concurrent sessions, we'll need to create a copy of the LensCore WASM\n * module. If we move managing web workers into JS, spawning a new worker thread with its own copy of LensCore\n * probably becomes a lot more straightforward.\n *\n * Currently chromium has a bug preventing rendering while tab is hidden when LensCore is in worker mode.\n * In order to process tab while it is hidden, the current stopgap is to pass in renderWhileTabHidden as true,\n * which will initiate session in non worker mode, and set the RenderLoopMode to `SetTimeout`.\n */\n const trustedTypesHandler = getTrustedTypesHandler(config.trustedTypesPolicyName);\n await this.lensCore.initialize({\n canvas: liveRenderTarget,\n shouldUseWorker: !renderWhileTabHidden && config.shouldUseWorker,\n exceptionHandler,\n trustedTypes: {\n policyName: trustedTypesHandler.policyName,\n getTrustedUrls: trustedTypesHandler.getTrustedUrls,\n trustUrl: trustedTypesHandler.trustUrl,\n },\n });\n\n if (this.lensCore.setGpuIndex) {\n // NOTE: setGpuIndex was added in LensCore@292. This check ensures compatibility with older versions.\n\n // Camera Kit allows a performance cluster to be provided during bootstrap.\n // This cluster is passed to the LENS_FEATURE_GPU_INDEX config as LENS_CLUSTER_ORIG_4,\n // which maps the cluster to a GPU index.\n try {\n await this.lensCore.setGpuIndex({\n gpuIndex: await firstValueFrom(this.remoteConfig.getGpuIndexConfig()),\n });\n } catch (cause) {\n // LensCore initialization can proceed without the GPU index,\n // as it is mainly needed for ML lenses.\n logger.error(new Error(\"Cannot set GPU index.\", { cause }));\n }\n }\n\n if (config.fonts.length > 0) {\n // LensCore detaches font data and mutates font properties during processing.\n // To prevent issues when reusing font objects across multiple applications,\n // we create deep copies of font objects before passing them to LensCore.\n this.lensCore.setSystemFonts({\n fonts: config.fonts.map((font) => ({\n ...font,\n data: font.data.slice(0),\n })),\n });\n }\n\n await this.lensCore.setRenderLoopMode({\n mode: renderWhileTabHidden\n ? this.lensCore.RenderLoopMode.SetTimeout\n : this.lensCore.RenderLoopMode.RequestAnimationFrame,\n });\n\n // Each session gets its own DI Container – some Services provided by this Container may be shared with the\n // root CameraKit Container, but others may be scoped to the session by passing their token to `copy()`.\n const sessionContainer = this.container\n // Right now this is a no-op. If/when we add support for multiple concurrent sessions, we may end up\n // scoping LensCore to the session.\n .copy()\n\n .provides(sessionStateFactory)\n .provides(lensStateFactory)\n .provides(lensKeyboardFactory)\n .provides(frameEventsFactory)\n .provides(cameraKitSessionFactory)\n\n .run(registerLensAssetsProvider)\n .run(registerLensClientInterfaceHandler)\n .run(registerGeoDataProvider)\n .run(setPreloadedConfiguration)\n\n // We'll run a PartialContainer containing reporters for session-scoped metrics. Running this container\n // allows each metric reporter to initialize itself (e.g. by adding event listeners to detect when certain\n // actions occur).\n .run(reportSessionScopedMetrics)\n\n // UriHandlers may have dependencies on session-scoped services (e.g. LensState, LensKeyboard), so they'll\n // be registered with LensCore here.\n .run(registerUriHandlers);\n\n const session = sessionContainer.get(cameraKitSessionFactory.token);\n this.sessions.push(session);\n return session;\n }\n\n /**\n * Destroys all sessions and frees all resources.\n */\n @errorLoggingDecorator(logger)\n async destroy() {\n resetLogger();\n this.pageVisibility.destroy();\n await Promise.all(this.sessions.map((session) => session.destroy()));\n this.sessions = [];\n }\n}\n\n/** @internal */\nexport const cameraKitFactory = Injectable(\n \"CameraKit\",\n [\n lensRepositoryFactory.token,\n metricsEventTargetFactory.token,\n lensCoreFactory.token,\n pageVisibilityFactory.token,\n remoteConfigurationFactory.token,\n CONTAINER,\n ] as const,\n (\n lensRepository: LensRepository,\n metrics: MetricsEventTarget,\n lensCore: LensCore,\n pageVisibility: PageVisibility,\n remoteConfiguration: RemoteConfiguration,\n container: Container<RootServices>\n ) => new CameraKit(lensRepository, lensCore, pageVisibility, container, remoteConfiguration, metrics)\n);\n"]}
1
+ {"version":3,"file":"CameraKit.js","sourceRoot":"","sources":["../src/CameraKit.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAEtC,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAI9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,EAAE,0BAA0B,EAAE,MAAM,kCAAkC,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAEzE,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,kCAAkC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from \"@snap/ts-inject\";\nimport { CONTAINER, Injectable } from \"@snap/ts-inject\";\nimport { firstValueFrom } from \"rxjs\";\nimport type { LensRepository } from \"./lens/LensRepository\";\nimport { lensRepositoryFactory } from \"./lens/LensRepository\";\nimport type { LensCoreError } from \"./lens-core-module/lensCoreError\";\nimport type { LensCore } from \"./lens-core-module/lensCore\";\nimport type { CameraKitSession } from \"./session/CameraKitSession\";\nimport { cameraKitSessionFactory } from \"./session/CameraKitSession\";\nimport { registerLensAssetsProvider } from \"./lens/assets/LensAssetsProvider\";\nimport { lensCoreFactory } from \"./lens-core-module/loader/lensCoreFactory\";\nimport { configurationToken } from \"./configuration\";\nimport type { RootServices } from \"./RootServices\";\nimport { registerUriHandlers } from \"./uri-handlers/uriHandlersRegister\";\nimport type { MetricsEventTarget } from \"./metrics/metricsEventTarget\";\nimport { metricsEventTargetFactory } from \"./metrics/metricsEventTarget\";\nimport { reportSessionScopedMetrics } from \"./metrics/reporters/reporters\";\nimport { lensStateFactory } from \"./session/lensState\";\nimport { lensKeyboardFactory } from \"./session/LensKeyboard\";\nimport { registerLensClientInterfaceHandler } from \"./lens-client-interface/lensClientInterface\";\nimport { sessionStateFactory } from \"./session/sessionState\";\nimport { lensExecutionError, lensAbortError } from \"./namedErrors\";\nimport { getLogger, resetLogger } from \"./logger/logger\";\nimport { errorLoggingDecorator } from \"./logger/errorLoggingDecorator\";\nimport { TypedEventTarget } from \"./events/TypedEventTarget\";\nimport type { TypedCustomEvent } from \"./events/TypedCustomEvent\";\nimport type { LensView } from \"./metrics/reporters/reportLensView\";\nimport type { LensWait } from \"./metrics/reporters/reportLensWait\";\nimport type { PageVisibility } from \"./common/pageVisibility\";\nimport { pageVisibilityFactory } from \"./common/pageVisibility\";\nimport { setPreloadedConfiguration } from \"./remote-configuration/preloadConfiguration\";\nimport { registerConfigurationProvider } from \"./remote-configuration/configurationProvider\";\nimport type { RemoteConfiguration } from \"./remote-configuration/remoteConfiguration\";\nimport { getTrustedTypesHandler } from \"./trusted-types/trustedTypesHandler\";\nimport { remoteConfigurationFactory } from \"./remote-configuration/remoteConfiguration\";\nimport { registerGeoDataProvider } from \"./geo/registerGeoDataProvider\";\nimport { frameEventsFactory } from \"./session/frameEvents\";\nimport { registerLensAnalyticEventsHandler } from \"./lens/analytics/registerLensAnalyticEventsHandler\";\n\nconst logger = getLogger(\"CameraKit\");\n\n/**\n * Metrics event names that are exposed to apps.\n */\nconst publicMetricsEventNames: Array<LensMetricsEvents[\"detail\"][\"name\"]> = [\"lensView\", \"lensWait\"];\n\n/**\n * Lens metrics events.\n *\n * These events are emitted by {@link CameraKit} to report lens usage, performance, apply latency, etc.\n *\n * @category Lenses\n * @category Metrics\n */\nexport type LensMetricsEvents =\n | TypedCustomEvent<LensView[\"name\"], LensView>\n | TypedCustomEvent<LensWait[\"name\"], LensWait>;\n\n/**\n * Options available when creating a {@link CameraKitSession}.\n *\n * @category Rendering\n */\nexport interface CreateSessionOptions {\n /**\n * Optionally provide an existing canvas element, on which the Live RenderTarget will be rendered.\n *\n * If this is not provided, CameraKit will create a new canvas element which can be added to the DOM.\n */\n liveRenderTarget?: HTMLCanvasElement;\n\n /**\n * Browsers optimize tabs when they are hidden - for example, by pausing the execution of requestAnimationFrame\n * callbacks.\n *\n * If you need the CameraKitSession to continue rendering even when the tab is in the background, set this to true.\n * There is a small performance penalty, and it's a good practice to only render in the background if absolutely\n * necessary.\n */\n renderWhileTabHidden?: boolean;\n}\n\n/**\n * The entry point to the CameraKit SDK's API. Most of CameraKit's features are accessed via this class.\n *\n * Applications obtain an instance of CameraKit by calling {@link bootstrapCameraKit}.\n *\n * @example\n * ```ts\n * const cameraKit = await bootstrapCameraKit(config)\n * ```\n *\n * Then this class can be used to:\n * - Create a {@link CameraKitSession} instance, which provides the API for setting up media inputs, applying Lenses,\n * and obtaining rendered `<canvas>` outputs.\n * - Query for lenses using {@link LensRepository}.\n * - Listen for lens usage metrics events using {@link MetricsEventTarget}.\n *\n * @category Rendering\n * @category Lenses\n */\nexport class CameraKit {\n /** @deprecated Use {@link lensRepository} */\n readonly lenses: { repository: LensRepository };\n\n /**\n * Business metrics (e.g. each time a lens is viewed) are emitted here.\n */\n readonly metrics: TypedEventTarget<LensMetricsEvents> = new TypedEventTarget();\n\n private sessions: CameraKitSession[] = [];\n\n /** @internal */\n constructor(\n /**\n * Used to query for lenses and lens groups.\n */\n readonly lensRepository: LensRepository,\n\n private readonly lensCore: LensCore,\n private readonly pageVisibility: PageVisibility,\n private readonly container: Container<RootServices>,\n private readonly remoteConfig: RemoteConfiguration,\n allMetrics: MetricsEventTarget\n ) {\n this.lenses = { repository: this.lensRepository };\n // Proxy only a subset of all metrics events to the public-facing emitter -- applications don't need to\n // know about most events.\n publicMetricsEventNames.forEach((eventName) => {\n allMetrics.addEventListener(eventName, (e) => this.metrics.dispatchEvent(e));\n });\n }\n\n /**\n * Create a CameraKitSession.\n *\n * This initializes the rendering engine and returns a {@link CameraKitSession} instance, which provides access\n * to Lens rendering.\n *\n * @example\n * ```ts\n * const cameraKit = await bootstrapCameraKit(config)\n * const session = await cameraKit.createSession()\n *\n * const lens = await cameraKit.lensRepository.loadLens(lensId, groupId)\n * session.applyLens(lens)\n * ```\n *\n * @param options\n */\n @errorLoggingDecorator(logger)\n async createSession({\n liveRenderTarget,\n renderWhileTabHidden,\n }: CreateSessionOptions = {}): Promise<CameraKitSession> {\n // Any error happened during lens rendering can be processed by subscribing to sessionErrors\n const exceptionHandler = (error: LensCoreError) => {\n if (error.name === \"LensCoreAbortError\") {\n logger.error(\n lensAbortError(\n \"Unrecoverable error occurred during lens execution. \" +\n \"The CameraKitSession will be destroyed.\",\n error\n )\n );\n } else {\n logger.error(\n lensExecutionError(\n \"Error occurred during lens execution. \" +\n \"The lens cannot be rendered and will be removed from the CameraKitSession.\",\n error\n )\n );\n }\n };\n\n const config = this.container.get(configurationToken);\n\n /**\n * If/when we add support for multiple concurrent sessions, we'll need to create a copy of the LensCore WASM\n * module. If we move managing web workers into JS, spawning a new worker thread with its own copy of LensCore\n * probably becomes a lot more straightforward.\n *\n * Currently chromium has a bug preventing rendering while tab is hidden when LensCore is in worker mode.\n * In order to process tab while it is hidden, the current stopgap is to pass in renderWhileTabHidden as true,\n * which will initiate session in non worker mode, and set the RenderLoopMode to `SetTimeout`.\n */\n const trustedTypesHandler = getTrustedTypesHandler(config.trustedTypesPolicyName);\n await this.lensCore.initialize({\n canvas: liveRenderTarget,\n shouldUseWorker: !renderWhileTabHidden && config.shouldUseWorker,\n exceptionHandler,\n trustedTypes: {\n policyName: trustedTypesHandler.policyName,\n getTrustedUrls: trustedTypesHandler.getTrustedUrls,\n trustUrl: trustedTypesHandler.trustUrl,\n },\n });\n\n if (this.lensCore.setGpuIndex) {\n // NOTE: setGpuIndex was added in LensCore@292. This check ensures compatibility with older versions.\n\n // Camera Kit allows a performance cluster to be provided during bootstrap.\n // This cluster is passed to the LENS_FEATURE_GPU_INDEX config as LENS_CLUSTER_ORIG_4,\n // which maps the cluster to a GPU index.\n try {\n await this.lensCore.setGpuIndex({\n gpuIndex: await firstValueFrom(this.remoteConfig.getGpuIndexConfig()),\n });\n } catch (cause) {\n // LensCore initialization can proceed without the GPU index,\n // as it is mainly needed for ML lenses.\n logger.error(new Error(\"Cannot set GPU index.\", { cause }));\n }\n }\n\n if (config.fonts.length > 0) {\n // LensCore detaches font data and mutates font properties during processing.\n // To prevent issues when reusing font objects across multiple applications,\n // we create deep copies of font objects before passing them to LensCore.\n this.lensCore.setSystemFonts({\n fonts: config.fonts.map((font) => ({\n ...font,\n data: font.data.slice(0),\n })),\n });\n }\n\n await this.lensCore.setRenderLoopMode({\n mode: renderWhileTabHidden\n ? this.lensCore.RenderLoopMode.SetTimeout\n : this.lensCore.RenderLoopMode.RequestAnimationFrame,\n });\n\n // Each session gets its own DI Container – some Services provided by this Container may be shared with the\n // root CameraKit Container, but others may be scoped to the session by passing their token to `copy()`.\n const sessionContainer = this.container\n // Right now this is a no-op. If/when we add support for multiple concurrent sessions, we may end up\n // scoping LensCore to the session.\n .copy()\n\n .provides(sessionStateFactory)\n .provides(lensStateFactory)\n .provides(lensKeyboardFactory)\n .provides(frameEventsFactory)\n .provides(cameraKitSessionFactory)\n\n .run(registerLensAssetsProvider)\n .run(registerLensClientInterfaceHandler)\n .run(registerGeoDataProvider)\n .run(registerConfigurationProvider)\n .run(setPreloadedConfiguration)\n .run(registerLensAnalyticEventsHandler)\n\n // We'll run a PartialContainer containing reporters for session-scoped metrics. Running this container\n // allows each metric reporter to initialize itself (e.g. by adding event listeners to detect when certain\n // actions occur).\n .run(reportSessionScopedMetrics)\n\n // UriHandlers may have dependencies on session-scoped services (e.g. LensState, LensKeyboard), so they'll\n // be registered with LensCore here.\n .run(registerUriHandlers);\n\n const session = sessionContainer.get(cameraKitSessionFactory.token);\n this.sessions.push(session);\n return session;\n }\n\n /**\n * Destroys all sessions and frees all resources.\n */\n @errorLoggingDecorator(logger)\n async destroy() {\n resetLogger();\n this.pageVisibility.destroy();\n await Promise.all(this.sessions.map((session) => session.destroy()));\n this.sessions = [];\n }\n}\n\n/** @internal */\nexport const cameraKitFactory = Injectable(\n \"CameraKit\",\n [\n lensRepositoryFactory.token,\n metricsEventTargetFactory.token,\n lensCoreFactory.token,\n pageVisibilityFactory.token,\n remoteConfigurationFactory.token,\n CONTAINER,\n ] as const,\n (\n lensRepository: LensRepository,\n metrics: MetricsEventTarget,\n lensCore: LensCore,\n pageVisibility: PageVisibility,\n remoteConfiguration: RemoteConfiguration,\n container: Container<RootServices>\n ) => new CameraKit(lensRepository, lensCore, pageVisibility, container, remoteConfiguration, metrics)\n);\n"]}
@@ -7,7 +7,7 @@ import type { staticAssetLoaderFactory } from "./lens/assets/staticAssetLoader";
7
7
  import type { defaultFetchHandlerFactory } from "./handlers/defaultFetchHandler";
8
8
  import type { cameraKitServiceFetchHandlerFactory } from "./handlers/cameraKitServiceFetchHandlerFactory";
9
9
  import type { createCameraKitConfigurationFactory } from "./configuration";
10
- import type { externalMetricsSubjectFactory, metricsClientFactory } from "./clients/metricsClient";
10
+ import type { externalMetricsFactory, externalMetricsSubjectFactory, metricsClientFactory } from "./clients/metricsClient";
11
11
  import type { LensCore } from "./lens-core-module/lensCore";
12
12
  import type { metricsEventTargetFactory } from "./metrics/metricsEventTarget";
13
13
  import type { lensSourcesFactory } from "./lens/LensSource";
@@ -29,6 +29,7 @@ import type { filePickerFactory } from "./lens-client-interface/filePicker";
29
29
  import type { userDataAccessResolverFactory } from "./lens/userDataAccessResolver";
30
30
  import type { remoteApiSpecsClientFactory } from "./clients/remoteApiSpecsClient";
31
31
  import type { geoDataProviderFactory } from "./geo/geoDataProvider";
32
+ import type { lensAnalyticEventsHandlerFactory } from "./lens/analytics/lensAnalyticEventsHandler";
32
33
  /**
33
34
  * All services available to be customized by client app.
34
35
  */
@@ -42,7 +43,9 @@ export type PublicServices = ServicesFromInjectables<[
42
43
  typeof remoteApiServicesFactory,
43
44
  typeof uriHandlersFactory,
44
45
  typeof geoDataProviderFactory,
45
- typeof externalMetricsSubjectFactory
46
+ typeof externalMetricsSubjectFactory,
47
+ typeof externalMetricsFactory,
48
+ typeof lensAnalyticEventsHandlerFactory
46
49
  ]>;
47
50
  /**
48
51
  * Define all the Services contained in CameraKit's root dependency injection container.
@@ -1 +1 @@
1
- {"version":3,"file":"RootServices.d.ts","sourceRoot":"","sources":["../src/RootServices.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AACnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,6CAA6C,CAAC;AACjG,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,0CAA0C,CAAC;AAClG,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,KAAK,EAAE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kBAAkB;IACzB,OAAO,mBAAmB;IAC1B,OAAO,2BAA2B;IAClC,OAAO,iBAAiB;IACxB,OAAO,0BAA0B;IACjC,OAAO,qBAAqB;IAC5B,OAAO,2BAA2B;IAClC,OAAO,oBAAoB;IAC3B,OAAO,0BAA0B;IACjC,OAAO,iCAAiC;IACxC,OAAO,wBAAwB;IAC/B,OAAO,iBAAiB;IACxB,OAAO,kBAAkB;IACzB,OAAO,iBAAiB;IACxB,OAAO,qBAAqB;CAC/B,CACJ,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"RootServices.js","sourceRoot":"","sources":["../src/RootServices.ts"],"names":[],"mappings":"","sourcesContent":["import type { ServicesFromInjectables } from \"@snap/ts-inject\";\nimport type { lensRepositoryFactory } from \"./lens/LensRepository\";\nimport type { lensCoreFactory } from \"./lens-core-module/loader/lensCoreFactory\";\nimport type { remoteMediaAssetLoaderFactory } from \"./lens/assets/remoteMediaAssetLoaderFactory\";\nimport type { deviceDependentAssetLoaderFactory } from \"./lens/assets/deviceDependentAssetLoader\";\nimport type { staticAssetLoaderFactory } from \"./lens/assets/staticAssetLoader\";\nimport type { defaultFetchHandlerFactory } from \"./handlers/defaultFetchHandler\";\nimport type { cameraKitServiceFetchHandlerFactory } from \"./handlers/cameraKitServiceFetchHandlerFactory\";\nimport type { createCameraKitConfigurationFactory } from \"./configuration\";\nimport type { externalMetricsSubjectFactory, metricsClientFactory } from \"./clients/metricsClient\";\nimport type { LensCore } from \"./lens-core-module/lensCore\";\nimport type { metricsEventTargetFactory } from \"./metrics/metricsEventTarget\";\nimport type { lensSourcesFactory } from \"./lens/LensSource\";\nimport type { uriHandlersFactory } from \"./uri-handlers/UriHandlers\";\nimport type { lensPersistenceStoreFactory } from \"./lens/LensPersistenceStore\";\nimport type { cofHandlerFactory } from \"./remote-configuration/cofHandler\";\nimport type { remoteConfigurationFactory } from \"./remote-configuration/remoteConfiguration\";\nimport type { lensAssetRepositoryFactory } from \"./lens/assets/LensAssetRepository\";\nimport type { legalStateFactory } from \"./legal/legalState\";\nimport type { legalPromptFactory } from \"./legal/legalPrompt\";\nimport type { logEntriesFactory } from \"./logger/logEntries\";\nimport type { reportGlobalException } from \"./metrics/reporters/reportGlobalException\";\nimport type { requestStateEventTargetFactory } from \"./handlers/requestStateEmittingHandler\";\nimport type { lensesClientFactory } from \"./clients/lensesClient\";\nimport type { pageVisibilityFactory } from \"./common/pageVisibility\";\nimport type { remoteApiServicesFactory } from \"./uri-handlers/internal-handlers/remoteApiUriHandler\";\nimport type { grpcHandlerFactory } from \"./clients/grpcHandler\";\nimport type { filePickerFactory } from \"./lens-client-interface/filePicker\";\nimport type { userDataAccessResolverFactory } from \"./lens/userDataAccessResolver\";\nimport type { remoteApiSpecsClientFactory } from \"./clients/remoteApiSpecsClient\";\nimport type { geoDataProviderFactory } from \"./geo/geoDataProvider\";\n\n/**\n * All services available to be customized by client app.\n */\nexport type PublicServices = ServicesFromInjectables<\n [\n ReturnType<typeof createCameraKitConfigurationFactory>,\n typeof userDataAccessResolverFactory,\n typeof filePickerFactory,\n typeof defaultFetchHandlerFactory,\n typeof remoteMediaAssetLoaderFactory,\n typeof lensSourcesFactory,\n typeof remoteApiServicesFactory,\n typeof uriHandlersFactory,\n typeof geoDataProviderFactory,\n typeof externalMetricsSubjectFactory\n ]\n>;\n\n/**\n * Define all the Services contained in CameraKit's root dependency injection container.\n *\n * Note: we do end up defining this list of Services twice (once here to create the type, once when we actually\n * create the Container inside the `bootstrapCameraKit` function). We could avoid doing this and just infer the\n * RootContainer type from the constructed container – but since we can only do that *inside* `bootstrapCameraKit`, it\n * makes it more awkward to provide a type for the `provide` user-supplied function (or use the type elsewhere, like in\n * CameraKitSession).\n *\n * There may be a way to eliminate this extra boilerplate, but for now it's required in order to present a cleaner\n * `bootstrapCameraKit` API to applications.\n */\nexport type RootServices = {\n // bootstrapCameraKit replaces the lensCoreFactory token's value with the resolved LensCore (rather than the\n // Promise of the LensCore), so we need to do the same re-mapping here.\n [lensCoreFactory.token]: LensCore;\n} & PublicServices &\n ServicesFromInjectables<\n [\n typeof pageVisibilityFactory,\n typeof metricsEventTargetFactory,\n typeof requestStateEventTargetFactory,\n typeof cameraKitServiceFetchHandlerFactory,\n typeof grpcHandlerFactory,\n typeof lensesClientFactory,\n typeof remoteApiSpecsClientFactory,\n typeof cofHandlerFactory,\n typeof remoteConfigurationFactory,\n typeof lensRepositoryFactory,\n typeof lensPersistenceStoreFactory,\n typeof metricsClientFactory,\n typeof lensAssetRepositoryFactory,\n typeof deviceDependentAssetLoaderFactory,\n typeof staticAssetLoaderFactory,\n typeof legalStateFactory,\n typeof legalPromptFactory,\n typeof logEntriesFactory,\n typeof reportGlobalException\n ]\n >;\n"]}
1
+ {"version":3,"file":"RootServices.js","sourceRoot":"","sources":["../src/RootServices.ts"],"names":[],"mappings":"","sourcesContent":["import type { ServicesFromInjectables } from \"@snap/ts-inject\";\nimport type { lensRepositoryFactory } from \"./lens/LensRepository\";\nimport type { lensCoreFactory } from \"./lens-core-module/loader/lensCoreFactory\";\nimport type { remoteMediaAssetLoaderFactory } from \"./lens/assets/remoteMediaAssetLoaderFactory\";\nimport type { deviceDependentAssetLoaderFactory } from \"./lens/assets/deviceDependentAssetLoader\";\nimport type { staticAssetLoaderFactory } from \"./lens/assets/staticAssetLoader\";\nimport type { defaultFetchHandlerFactory } from \"./handlers/defaultFetchHandler\";\nimport type { cameraKitServiceFetchHandlerFactory } from \"./handlers/cameraKitServiceFetchHandlerFactory\";\nimport type { createCameraKitConfigurationFactory } from \"./configuration\";\nimport type {\n externalMetricsFactory,\n externalMetricsSubjectFactory,\n metricsClientFactory,\n} from \"./clients/metricsClient\";\nimport type { LensCore } from \"./lens-core-module/lensCore\";\nimport type { metricsEventTargetFactory } from \"./metrics/metricsEventTarget\";\nimport type { lensSourcesFactory } from \"./lens/LensSource\";\nimport type { uriHandlersFactory } from \"./uri-handlers/UriHandlers\";\nimport type { lensPersistenceStoreFactory } from \"./lens/LensPersistenceStore\";\nimport type { cofHandlerFactory } from \"./remote-configuration/cofHandler\";\nimport type { remoteConfigurationFactory } from \"./remote-configuration/remoteConfiguration\";\nimport type { lensAssetRepositoryFactory } from \"./lens/assets/LensAssetRepository\";\nimport type { legalStateFactory } from \"./legal/legalState\";\nimport type { legalPromptFactory } from \"./legal/legalPrompt\";\nimport type { logEntriesFactory } from \"./logger/logEntries\";\nimport type { reportGlobalException } from \"./metrics/reporters/reportGlobalException\";\nimport type { requestStateEventTargetFactory } from \"./handlers/requestStateEmittingHandler\";\nimport type { lensesClientFactory } from \"./clients/lensesClient\";\nimport type { pageVisibilityFactory } from \"./common/pageVisibility\";\nimport type { remoteApiServicesFactory } from \"./uri-handlers/internal-handlers/remoteApiUriHandler\";\nimport type { grpcHandlerFactory } from \"./clients/grpcHandler\";\nimport type { filePickerFactory } from \"./lens-client-interface/filePicker\";\nimport type { userDataAccessResolverFactory } from \"./lens/userDataAccessResolver\";\nimport type { remoteApiSpecsClientFactory } from \"./clients/remoteApiSpecsClient\";\nimport type { geoDataProviderFactory } from \"./geo/geoDataProvider\";\nimport type { lensAnalyticEventsHandlerFactory } from \"./lens/analytics/lensAnalyticEventsHandler\";\n\n/**\n * All services available to be customized by client app.\n */\nexport type PublicServices = ServicesFromInjectables<\n [\n ReturnType<typeof createCameraKitConfigurationFactory>,\n typeof userDataAccessResolverFactory,\n typeof filePickerFactory,\n typeof defaultFetchHandlerFactory,\n typeof remoteMediaAssetLoaderFactory,\n typeof lensSourcesFactory,\n typeof remoteApiServicesFactory,\n typeof uriHandlersFactory,\n typeof geoDataProviderFactory,\n typeof externalMetricsSubjectFactory,\n typeof externalMetricsFactory,\n typeof lensAnalyticEventsHandlerFactory\n ]\n>;\n\n/**\n * Define all the Services contained in CameraKit's root dependency injection container.\n *\n * Note: we do end up defining this list of Services twice (once here to create the type, once when we actually\n * create the Container inside the `bootstrapCameraKit` function). We could avoid doing this and just infer the\n * RootContainer type from the constructed container – but since we can only do that *inside* `bootstrapCameraKit`, it\n * makes it more awkward to provide a type for the `provide` user-supplied function (or use the type elsewhere, like in\n * CameraKitSession).\n *\n * There may be a way to eliminate this extra boilerplate, but for now it's required in order to present a cleaner\n * `bootstrapCameraKit` API to applications.\n */\nexport type RootServices = {\n // bootstrapCameraKit replaces the lensCoreFactory token's value with the resolved LensCore (rather than the\n // Promise of the LensCore), so we need to do the same re-mapping here.\n [lensCoreFactory.token]: LensCore;\n} & PublicServices &\n ServicesFromInjectables<\n [\n typeof pageVisibilityFactory,\n typeof metricsEventTargetFactory,\n typeof requestStateEventTargetFactory,\n typeof cameraKitServiceFetchHandlerFactory,\n typeof grpcHandlerFactory,\n typeof lensesClientFactory,\n typeof remoteApiSpecsClientFactory,\n typeof cofHandlerFactory,\n typeof remoteConfigurationFactory,\n typeof lensRepositoryFactory,\n typeof lensPersistenceStoreFactory,\n typeof metricsClientFactory,\n typeof lensAssetRepositoryFactory,\n typeof deviceDependentAssetLoaderFactory,\n typeof staticAssetLoaderFactory,\n typeof legalStateFactory,\n typeof legalPromptFactory,\n typeof logEntriesFactory,\n typeof reportGlobalException\n ]\n >;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"bootstrapCameraKit.d.ts","sourceRoot":"","sources":["../src/bootstrapCameraKit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAc,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAM1E,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,iBAAiB,CAAC;AAEvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAwD7C;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG,SAAS,CAAC,cAAc,CAAC,CAAC;AAExD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAsB,kBAAkB,CACpC,aAAa,EAAE,+BAA+B,EAC9C,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,eAAe,KAAK,eAAe,GAClD,OAAO,CAAC,SAAS,CAAC,CA8FpB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,eAAe,IAAI,gBAAgB,CAElD"}
1
+ {"version":3,"file":"bootstrapCameraKit.d.ts","sourceRoot":"","sources":["../src/bootstrapCameraKit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAc,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAM1E,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,iBAAiB,CAAC;AAEvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAyD7C;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG,SAAS,CAAC,cAAc,CAAC,CAAC;AAExD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAsB,kBAAkB,CACpC,aAAa,EAAE,+BAA+B,EAC9C,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,eAAe,KAAK,eAAe,GAClD,OAAO,CAAC,SAAS,CAAC,CAkGpB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,eAAe,IAAI,gBAAgB,CAElD"}
@@ -36,13 +36,14 @@ import { lensesClientFactory } from "./clients/lensesClient";
36
36
  import { grpcHandlerFactory } from "./clients/grpcHandler";
37
37
  import { lensSourcesFactory } from "./lens/LensSource";
38
38
  import { cameraKitLensSourceFactory } from "./lens/cameraKitLensSource";
39
- import { externalMetricsSubjectFactory, metricsClientFactory } from "./clients/metricsClient";
39
+ import { externalMetricsFactory, externalMetricsSubjectFactory, metricsClientFactory } from "./clients/metricsClient";
40
40
  import { Timer } from "./metrics/operational/Timer";
41
41
  import { fetchWatermarkLens } from "./lens/fetchWatermarkLens";
42
42
  import { filePickerFactory } from "./lens-client-interface/filePicker";
43
43
  import { userDataAccessResolverFactory } from "./lens/userDataAccessResolver";
44
44
  import { remoteApiSpecsClientFactory } from "./clients/remoteApiSpecsClient";
45
45
  import { geoDataProviderFactory } from "./geo/geoDataProvider";
46
+ import { lensAnalyticEventsHandlerFactory } from "./lens/analytics/lensAnalyticEventsHandler";
46
47
  const logger = getLogger("bootstrapCameraKit");
47
48
  const nonWrappableErrors = [
48
49
  "ConfigurationError",
@@ -70,7 +71,9 @@ export function bootstrapCameraKit(configuration, provide) {
70
71
  .provides(remoteApiServicesFactory)
71
72
  .provides(uriHandlersFactory)
72
73
  .provides(geoDataProviderFactory)
73
- .provides(externalMetricsSubjectFactory);
74
+ .provides(externalMetricsFactory)
75
+ .provides(externalMetricsSubjectFactory)
76
+ .provides(lensAnalyticEventsHandlerFactory);
74
77
  const publicContainer = provide ? provide(defaultPublicContainer) : defaultPublicContainer;
75
78
  const telemetryContainer = Container.provides(publicContainer)
76
79
  .provides(pageVisibilityFactory)
@@ -1 +1 @@
1
- {"version":3,"file":"bootstrapCameraKit.js","sourceRoot":"","sources":["../src/bootstrapCameraKit.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAAE,6BAA6B,EAAE,MAAM,6CAA6C,CAAC;AAC5F,OAAO,EAAE,iCAAiC,EAAE,MAAM,0CAA0C,CAAC;AAC7F,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,EAAE,0BAA0B,EAAE,MAAM,gCAAgC,CAAC;AAC5E,OAAO,EAAE,mCAAmC,EAAE,MAAM,gDAAgD,CAAC;AAErG,OAAO,EAAE,mCAAmC,EAAE,MAAM,iBAAiB,CAAC;AAEtE,OAAO,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAC;AAC5E,OAAO,EAAE,gBAAgB,EAA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CAAA;AA0CD,MAAM,UAAU,eAAe;IAC3B,OAAO,IAAI,gBAAgB,CAAC,EAAE,CAAC,CAAC;AACpC,CAAC","sourcesContent":["import { Container, Injectable, PartialContainer } from \"@snap/ts-inject\";\nimport { remoteMediaAssetLoaderFactory } from \"./lens/assets/remoteMediaAssetLoaderFactory\";\nimport { deviceDependentAssetLoaderFactory } from \"./lens/assets/deviceDependentAssetLoader\";\nimport { staticAssetLoaderFactory } from \"./lens/assets/staticAssetLoader\";\nimport { defaultFetchHandlerFactory } from \"./handlers/defaultFetchHandler\";\nimport { cameraKitServiceFetchHandlerFactory } from \"./handlers/cameraKitServiceFetchHandlerFactory\";\nimport type { CameraKitBootstrapConfiguration } from \"./configuration\";\nimport { createCameraKitConfigurationFactory } from \"./configuration\";\nimport type { PublicServices } from \"./RootServices\";\nimport { lensCoreFactory } from \"./lens-core-module/loader/lensCoreFactory\";\nimport { cameraKitFactory } from \"./CameraKit\";\nimport type { CameraKit } from \"./CameraKit\";\nimport { lensRepositoryFactory } from \"./lens/LensRepository\";\nimport lensCoreWasm from \"./lensCoreWasmVersions\";\nimport environment from \"./environment\";\nimport { uriHandlersFactory } from \"./uri-handlers/UriHandlers\";\nimport { assert } from \"./common/assertions\";\nimport { isSafeString } from \"./common/typeguards\";\nimport { metricsEventTargetFactory } from \"./metrics/metricsEventTarget\";\nimport { reportGloballyScopedMetrics } from \"./metrics/reporters/reporters\";\nimport { getLogger } from \"./logger/logger\";\nimport { logEntriesFactory } from \"./logger/logEntries\";\nimport { assertPlatformSupported } from \"./platform/assertPlatformSupported\";\nimport { lensPersistenceStoreFactory } from \"./lens/LensPersistenceStore\";\nimport { remoteConfigurationFactory } from \"./remote-configuration/remoteConfiguration\";\nimport { lensAssetRepositoryFactory } from \"./lens/assets/LensAssetRepository\";\nimport { legalStateFactory } from \"./legal/legalState\";\nimport { legalPromptFactory } from \"./legal/legalPrompt\";\nimport type { ConfigurationError, PlatformNotSupportedError } from \"./namedErrors\";\nimport { bootstrapError, configurationError } from \"./namedErrors\";\nimport { businessEventsReporterFactory } from \"./metrics/businessEventsReporter\";\nimport { reportGlobalException } from \"./metrics/reporters/reportGlobalException\";\nimport { registerLogEntriesSubscriber } from \"./logger/registerLogEntriesSubscriber\";\nimport { requestStateEventTargetFactory } from \"./handlers/requestStateEmittingHandler\";\nimport { pageVisibilityFactory } from \"./common/pageVisibility\";\nimport { cofHandlerFactory } from \"./remote-configuration/cofHandler\";\nimport { remoteApiServicesFactory } from \"./uri-handlers/internal-handlers/remoteApiUriHandler\";\nimport { lensesClientFactory } from \"./clients/lensesClient\";\nimport { grpcHandlerFactory } from \"./clients/grpcHandler\";\nimport { lensSourcesFactory } from \"./lens/LensSource\";\nimport { cameraKitLensSourceFactory } from \"./lens/cameraKitLensSource\";\nimport { externalMetricsSubjectFactory, metricsClientFactory } from \"./clients/metricsClient\";\nimport { Timer } from \"./metrics/operational/Timer\";\nimport { fetchWatermarkLens } from \"./lens/fetchWatermarkLens\";\nimport { filePickerFactory } from \"./lens-client-interface/filePicker\";\nimport { userDataAccessResolverFactory } from \"./lens/userDataAccessResolver\";\nimport { remoteApiSpecsClientFactory } from \"./clients/remoteApiSpecsClient\";\nimport { geoDataProviderFactory } from \"./geo/geoDataProvider\";\n\nconst logger = getLogger(\"bootstrapCameraKit\");\n\n// The following errors are not wrapped with BootstrapError and bubble up as is.\nconst nonWrappableErrors: [ConfigurationError[\"name\"], PlatformNotSupportedError[\"name\"]] = [\n \"ConfigurationError\",\n \"PlatformNotSupportedError\",\n];\n\n/**\n * Returns true if given error has to be wrapped with BootstrapError.\n */\nfunction shouldWrapError(error: unknown): boolean {\n if (error instanceof Error) {\n return !nonWrappableErrors.some((name) => error.name === name);\n }\n return true;\n}\n\n/**\n * For more advanced use-cases, this DI Container holds services for which a custom implementation may be provided by\n * the application.\n *\n * @category Bootstrapping and Configuration\n */\nexport type PublicContainer = Container<PublicServices>;\n\n/**\n * Bootstrap CameraKit. This will download the WebAssembly code which powers CameraKit's rendering engine, and return\n * an instance of {@link CameraKit}.\n *\n * CameraKit must be provided with some configuration (the application's API token), and there are some additional\n * configurations which are optional.\n *\n * Descriptions of the available configurations can be found in the documentation for\n * {@link CameraKitBootstrapConfiguration}\n *\n * ---\n *\n * There is also a second, more advanced way to modify CameraKit to provide greater flexibility to support less common\n * use cases.\n *\n * This requires some knowledge of CameraKit's dependency injection system, and allows applications to provide their\n * own custom implementations of certain CameraKit components. This functionality will only be needed by applications\n * with very specific, more advanced requirements.\n *\n * @example\n * ```ts\n * // The most common way to bootstrap:\n * const cameraKit = await bootstrapCameraKit({ apiToken: myApiToken })\n *\n * // For special advanced use-cases, it is possible to provide custom implementations for certain CameraKit components.\n * const cameraKit = await bootstrapCameraKit(config, (container) => {\n * return container.provides(myCustomRemoteMediaAssetLoaderFactory)\n * })\n * ```\n *\n * @param configuration Configure CameraKit with e.g. credentials, global resource endpoints, etc.\n * @param provide Optional function that can make modifications to CameraKit's root DI container.\n * @returns A {@link CameraKit} instance, which is the entry point to CameraKit's API.\n *\n * @throws\n * - {@link ConfigurationError} when provided configuration object is invalid\n * - {@link PlatformNotSupportedError} when current platform is not supported by CameraKit\n * - {@link BootstrapError} when a failure occurs while initializing CameraKit and downloading the render engine\n * WebAssembly binary.\n *\n * @category Bootstrapping and Configuration\n */\nexport async function bootstrapCameraKit(\n configuration: CameraKitBootstrapConfiguration,\n provide?: (c: PublicContainer) => PublicContainer\n): Promise<CameraKit> {\n console.info(\n `Camera Kit SDK: ${environment.PACKAGE_VERSION} (${lensCoreWasm.version}/${lensCoreWasm.buildNumber})`\n );\n\n try {\n const bootstrapLatency = new Timer(\"bootstrap_time\");\n\n assert(isSafeString(configuration.apiToken), configurationError(\"Invalid or unsafe apiToken provided.\"));\n\n const configurationFactory = createCameraKitConfigurationFactory(configuration);\n\n // Public container holds services which applications can overwrite with their own implementations.\n const defaultPublicContainer = Container.provides(configurationFactory)\n .provides(userDataAccessResolverFactory)\n .provides(filePickerFactory)\n .provides(defaultFetchHandlerFactory)\n .provides(remoteMediaAssetLoaderFactory)\n .provides(lensSourcesFactory)\n .provides(remoteApiServicesFactory)\n .provides(uriHandlersFactory)\n .provides(geoDataProviderFactory)\n .provides(externalMetricsSubjectFactory);\n\n const publicContainer = provide ? provide(defaultPublicContainer) : defaultPublicContainer;\n\n // Now that the client's provide() function has completed and the configuration override is ready,\n // we create another container to initialize the logger. This ensures that logging is available\n // as we continue bootstrapping. We don't initialize the logger as part of the defaultPublicContainer\n // because we don't want applications to provide their own logger implementations,\n // and we're not interested in errors thrown by their provide() function.\n // Below is the minimum required container to report errors to Blizzard.\n const telemetryContainer = Container.provides(publicContainer)\n .provides(pageVisibilityFactory)\n .provides(cameraKitServiceFetchHandlerFactory)\n .provides(requestStateEventTargetFactory)\n .provides(grpcHandlerFactory)\n .provides(metricsClientFactory)\n .provides(logEntriesFactory)\n .run(registerLogEntriesSubscriber)\n .provides(metricsEventTargetFactory)\n .provides(reportGlobalException)\n .provides(cofHandlerFactory)\n .provides(remoteConfigurationFactory)\n .provides(legalPromptFactory)\n .provides(legalStateFactory)\n // We'll run a PartialContainer containing reporters for globally-scoped metrics. Running this container\n // allows each metric reporter to initialize itself (e.g. by adding event listeners to detect when certain\n // actions occur). This PartialContainer also includes the service which listens to locally-reported metrics\n // and sends them to our backend.\n .run(reportGloballyScopedMetrics)\n .run(businessEventsReporterFactory);\n\n // Run the exception logger so that it can subscribe to log events -- we can't use `Container.run()` because\n // reportGlobalException is also used as a dependency by other Services (and run does not provide Services,\n // it just runs them once).\n telemetryContainer.get(reportGlobalException.token);\n\n // At this point, logger is configured to report to console and Blizzard.\n\n await assertPlatformSupported();\n\n // LensCore is a foundational component which must be created asynchronously.\n // But it's annoying for every consumer of LensCore to have to wait on Promise<LensCore>\n // (which means they become async themselves). So we'll create a DI container which provides Promise<LensCore>,\n // wait for that promise once here, then create a new DI container that just contains LensCore.\n const lensCore = await telemetryContainer.provides(lensCoreFactory).get(lensCoreFactory.token);\n\n const container = telemetryContainer\n .provides(Injectable(lensCoreFactory.token, () => lensCore))\n .provides(lensesClientFactory)\n .provides(remoteApiSpecsClientFactory)\n .provides(cameraKitLensSourceFactory)\n .provides(lensPersistenceStoreFactory)\n .provides(deviceDependentAssetLoaderFactory)\n .provides(staticAssetLoaderFactory)\n .provides(lensAssetRepositoryFactory)\n .provides(lensRepositoryFactory)\n .provides(cameraKitFactory)\n .run(fetchWatermarkLens);\n\n const cameraKit = container.get(cameraKitFactory.token);\n\n bootstrapLatency.measure();\n container.get(metricsClientFactory.token).setOperationalMetrics(bootstrapLatency);\n\n return cameraKit;\n } catch (error) {\n if (shouldWrapError(error)) {\n error = bootstrapError(\"Error occurred during Camera Kit bootstrapping.\", error);\n }\n logger.error(error);\n throw error;\n }\n}\n\n/**\n * Extensions offer a way to provide custom implementations of certain parts of the CameraKit SDK.\n *\n * This enables more advanced use-cases, in which the default behavior of the SDK is substantially altered. For example,\n * replacing the default implementation that loads remote lens assets with a custom implementation that returns\n * different assets based on some business logic within the application.\n *\n * An extension is implemented as a {@link PartialContainer} – a collection of factory functions, each with its own\n * dependencies, which each provide some \"Service\". A Service can be of any type, and the CameraKit SDK defines its\n * own Services, some of which can be overridden by providing a custom implementation of the type via an extension.\n *\n * Here's an example of how extensions might be used:\n * ```ts\n * import { bootstrapCameraKit, createExtension, remoteMediaAssetLoaderFactory } from '@snap/camera-kit'\n *\n * const myCustomRemoteAssetLoader = Injectable(\n * remoteMediaAssetLoaderFactory.token,\n * [remoteMediaAssetLoaderFactory.token] as const,\n * (defaultLoader: AssetLoader): AssetLoader => {\n * return async (asset, lens) => {\n * if (lens?.id === MY_SPECIAL_LENS) {\n * return (await fetch('my/asset.glb')).arrayBuffer()\n * }\n * return defaultLoader(asset, lens)\n * }\n * },\n * )\n *\n * const myExtension = createExtension().provides(myCustomRemoteAssetLoader);\n * const cameraKit = bootstrapCameraKit(config, container => container.provides(myExtension));\n * ```\n *\n * This also enables greater modularity – the person/team creating the extension can do so in their own package, which\n * could be shared by many applications that all require the same functionality.\n *\n * @returns A {@link PartialContainer} which can be used to create a collection of Services, and can later be provided\n * to CameraKit's DI container during {@link bootstrapCameraKit}.\n *\n * @category Bootstrapping and Configuration\n */\nexport function createExtension(): PartialContainer {\n return new PartialContainer({});\n}\n"]}
1
+ {"version":3,"file":"bootstrapCameraKit.js","sourceRoot":"","sources":["../src/bootstrapCameraKit.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAAE,6BAA6B,EAAE,MAAM,6CAA6C,CAAC;AAC5F,OAAO,EAAE,iCAAiC,EAAE,MAAM,0CAA0C,CAAC;AAC7F,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,EAAE,0BAA0B,EAAE,MAAM,gCAAgC,CAAC;AAC5E,OAAO,EAAE,mCAAmC,EAAE,MAAM,gDAAgD,CAAC;AAErG,OAAO,EAAE,mCAAmC,EAAE,MAAM,iBAAiB,CAAC;AAEtE,OAAO,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAC;AAC5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,YAAY,MAAM,wBAAwB,CAAC;AAClD,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE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EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC;iBAC3D,QAAQ,CAAC,mBAAmB,CAAC;iBAC7B,QAAQ,CAAC,2BAA2B,CAAC;iBACrC,QAAQ,CAAC,0BAA0B,CAAC;iBACpC,QAAQ,CAAC,2BAA2B,CAAC;iBACrC,QAAQ,CAAC,iCAAiC,CAAC;iBAC3C,QAAQ,CAAC,wBAAwB,CAAC;iBAClC,QAAQ,CAAC,0BAA0B,CAAC;iBACpC,QAAQ,CAAC,qBAAqB,CAAC;iBAC/B,QAAQ,CAAC,gBAAgB,CAAC;iBAC1B,GAAG,CAAC,kBAAkB,CAAC,CAAC;YAE7B,MAAM,SAAS,GAAG,SAAS,CAAC,GAAG,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;YAExD,gBAAgB,CAAC,OAAO,EAAE,CAAC;YAC3B,SAAS,CAAC,GAAG,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC,qBAAqB,CAAC,gBAAgB,CAAC,CAAC;YAElF,OAAO,SAAS,CAAC;SACpB;QAAC,OAAO,KAAK,EAAE;YACZ,IAAI,eAAe,CAAC,KAAK,CAAC,EAAE;gBACxB,KAAK,GAAG,cAAc,CAAC,iDAAiD,EAAE,KAAK,CAAC,CAAC;aACpF;YACD,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YACpB,MAAM,KAAK,CAAC;SACf;IACL,CAAC;CAAA;AA0CD,MAAM,UAAU,eAAe;IAC3B,OAAO,IAAI,gBAAgB,CAAC,EAAE,CAAC,CAAC;AACpC,CAAC","sourcesContent":["import { Container, Injectable, PartialContainer } from \"@snap/ts-inject\";\nimport { remoteMediaAssetLoaderFactory } from \"./lens/assets/remoteMediaAssetLoaderFactory\";\nimport { deviceDependentAssetLoaderFactory } from \"./lens/assets/deviceDependentAssetLoader\";\nimport { staticAssetLoaderFactory } from \"./lens/assets/staticAssetLoader\";\nimport { defaultFetchHandlerFactory } from \"./handlers/defaultFetchHandler\";\nimport { cameraKitServiceFetchHandlerFactory } from \"./handlers/cameraKitServiceFetchHandlerFactory\";\nimport type { CameraKitBootstrapConfiguration } from \"./configuration\";\nimport { createCameraKitConfigurationFactory } from \"./configuration\";\nimport type { PublicServices } from \"./RootServices\";\nimport { lensCoreFactory } from \"./lens-core-module/loader/lensCoreFactory\";\nimport { cameraKitFactory } from \"./CameraKit\";\nimport type { CameraKit } from \"./CameraKit\";\nimport { lensRepositoryFactory } from \"./lens/LensRepository\";\nimport lensCoreWasm from \"./lensCoreWasmVersions\";\nimport environment from \"./environment\";\nimport { uriHandlersFactory } from \"./uri-handlers/UriHandlers\";\nimport { assert } from \"./common/assertions\";\nimport { isSafeString } from \"./common/typeguards\";\nimport { metricsEventTargetFactory } from \"./metrics/metricsEventTarget\";\nimport { reportGloballyScopedMetrics } from \"./metrics/reporters/reporters\";\nimport { getLogger } from \"./logger/logger\";\nimport { logEntriesFactory } from \"./logger/logEntries\";\nimport { assertPlatformSupported } from \"./platform/assertPlatformSupported\";\nimport { lensPersistenceStoreFactory } from \"./lens/LensPersistenceStore\";\nimport { remoteConfigurationFactory } from \"./remote-configuration/remoteConfiguration\";\nimport { lensAssetRepositoryFactory } from \"./lens/assets/LensAssetRepository\";\nimport { legalStateFactory } from \"./legal/legalState\";\nimport { legalPromptFactory } from \"./legal/legalPrompt\";\nimport type { ConfigurationError, PlatformNotSupportedError } from \"./namedErrors\";\nimport { bootstrapError, configurationError } from \"./namedErrors\";\nimport { businessEventsReporterFactory } from \"./metrics/businessEventsReporter\";\nimport { reportGlobalException } from \"./metrics/reporters/reportGlobalException\";\nimport { registerLogEntriesSubscriber } from \"./logger/registerLogEntriesSubscriber\";\nimport { requestStateEventTargetFactory } from \"./handlers/requestStateEmittingHandler\";\nimport { pageVisibilityFactory } from \"./common/pageVisibility\";\nimport { cofHandlerFactory } from \"./remote-configuration/cofHandler\";\nimport { remoteApiServicesFactory } from \"./uri-handlers/internal-handlers/remoteApiUriHandler\";\nimport { lensesClientFactory } from \"./clients/lensesClient\";\nimport { grpcHandlerFactory } from \"./clients/grpcHandler\";\nimport { lensSourcesFactory } from \"./lens/LensSource\";\nimport { cameraKitLensSourceFactory } from \"./lens/cameraKitLensSource\";\nimport { externalMetricsFactory, externalMetricsSubjectFactory, metricsClientFactory } from \"./clients/metricsClient\";\nimport { Timer } from \"./metrics/operational/Timer\";\nimport { fetchWatermarkLens } from \"./lens/fetchWatermarkLens\";\nimport { filePickerFactory } from \"./lens-client-interface/filePicker\";\nimport { userDataAccessResolverFactory } from \"./lens/userDataAccessResolver\";\nimport { remoteApiSpecsClientFactory } from \"./clients/remoteApiSpecsClient\";\nimport { geoDataProviderFactory } from \"./geo/geoDataProvider\";\nimport { lensAnalyticEventsHandlerFactory } from \"./lens/analytics/lensAnalyticEventsHandler\";\n\nconst logger = getLogger(\"bootstrapCameraKit\");\n\n// The following errors are not wrapped with BootstrapError and bubble up as is.\nconst nonWrappableErrors: [ConfigurationError[\"name\"], PlatformNotSupportedError[\"name\"]] = [\n \"ConfigurationError\",\n \"PlatformNotSupportedError\",\n];\n\n/**\n * Returns true if given error has to be wrapped with BootstrapError.\n */\nfunction shouldWrapError(error: unknown): boolean {\n if (error instanceof Error) {\n return !nonWrappableErrors.some((name) => error.name === name);\n }\n return true;\n}\n\n/**\n * For more advanced use-cases, this DI Container holds services for which a custom implementation may be provided by\n * the application.\n *\n * @category Bootstrapping and Configuration\n */\nexport type PublicContainer = Container<PublicServices>;\n\n/**\n * Bootstrap CameraKit. This will download the WebAssembly code which powers CameraKit's rendering engine, and return\n * an instance of {@link CameraKit}.\n *\n * CameraKit must be provided with some configuration (the application's API token), and there are some additional\n * configurations which are optional.\n *\n * Descriptions of the available configurations can be found in the documentation for\n * {@link CameraKitBootstrapConfiguration}\n *\n * ---\n *\n * There is also a second, more advanced way to modify CameraKit to provide greater flexibility to support less common\n * use cases.\n *\n * This requires some knowledge of CameraKit's dependency injection system, and allows applications to provide their\n * own custom implementations of certain CameraKit components. This functionality will only be needed by applications\n * with very specific, more advanced requirements.\n *\n * @example\n * ```ts\n * // The most common way to bootstrap:\n * const cameraKit = await bootstrapCameraKit({ apiToken: myApiToken })\n *\n * // For special advanced use-cases, it is possible to provide custom implementations for certain CameraKit components.\n * const cameraKit = await bootstrapCameraKit(config, (container) => {\n * return container.provides(myCustomRemoteMediaAssetLoaderFactory)\n * })\n * ```\n *\n * @param configuration Configure CameraKit with e.g. credentials, global resource endpoints, etc.\n * @param provide Optional function that can make modifications to CameraKit's root DI container.\n * @returns A {@link CameraKit} instance, which is the entry point to CameraKit's API.\n *\n * @throws\n * - {@link ConfigurationError} when provided configuration object is invalid\n * - {@link PlatformNotSupportedError} when current platform is not supported by CameraKit\n * - {@link BootstrapError} when a failure occurs while initializing CameraKit and downloading the render engine\n * WebAssembly binary.\n *\n * @category Bootstrapping and Configuration\n */\nexport async function bootstrapCameraKit(\n configuration: CameraKitBootstrapConfiguration,\n provide?: (c: PublicContainer) => PublicContainer\n): Promise<CameraKit> {\n console.info(\n `Camera Kit SDK: ${environment.PACKAGE_VERSION} (${lensCoreWasm.version}/${lensCoreWasm.buildNumber})`\n );\n\n try {\n const bootstrapLatency = new Timer(\"bootstrap_time\");\n\n assert(isSafeString(configuration.apiToken), configurationError(\"Invalid or unsafe apiToken provided.\"));\n\n const configurationFactory = createCameraKitConfigurationFactory(configuration);\n\n // Public container holds services which applications can overwrite with their own implementations.\n const defaultPublicContainer = Container.provides(configurationFactory)\n .provides(userDataAccessResolverFactory)\n .provides(filePickerFactory)\n .provides(defaultFetchHandlerFactory)\n .provides(remoteMediaAssetLoaderFactory)\n .provides(lensSourcesFactory)\n .provides(remoteApiServicesFactory)\n .provides(uriHandlersFactory)\n .provides(geoDataProviderFactory)\n .provides(externalMetricsFactory)\n .provides(externalMetricsSubjectFactory)\n // This handler is primarily used by internal consumers. It's safe on the public surface because it only\n // triggers for lenses using private APIs that external partners cannot access.\n .provides(lensAnalyticEventsHandlerFactory);\n\n const publicContainer = provide ? provide(defaultPublicContainer) : defaultPublicContainer;\n\n // Now that the client's provide() function has completed and the configuration override is ready,\n // we create another container to initialize the logger. This ensures that logging is available\n // as we continue bootstrapping. We don't initialize the logger as part of the defaultPublicContainer\n // because we don't want applications to provide their own logger implementations,\n // and we're not interested in errors thrown by their provide() function.\n // Below is the minimum required container to report errors to Blizzard.\n const telemetryContainer = Container.provides(publicContainer)\n .provides(pageVisibilityFactory)\n .provides(cameraKitServiceFetchHandlerFactory)\n .provides(requestStateEventTargetFactory)\n .provides(grpcHandlerFactory)\n .provides(metricsClientFactory)\n .provides(logEntriesFactory)\n .run(registerLogEntriesSubscriber)\n .provides(metricsEventTargetFactory)\n .provides(reportGlobalException)\n .provides(cofHandlerFactory)\n .provides(remoteConfigurationFactory)\n .provides(legalPromptFactory)\n .provides(legalStateFactory)\n // We'll run a PartialContainer containing reporters for globally-scoped metrics. Running this container\n // allows each metric reporter to initialize itself (e.g. by adding event listeners to detect when certain\n // actions occur). This PartialContainer also includes the service which listens to locally-reported metrics\n // and sends them to our backend.\n .run(reportGloballyScopedMetrics)\n .run(businessEventsReporterFactory);\n\n // Run the exception logger so that it can subscribe to log events -- we can't use `Container.run()` because\n // reportGlobalException is also used as a dependency by other Services (and run does not provide Services,\n // it just runs them once).\n telemetryContainer.get(reportGlobalException.token);\n\n // At this point, logger is configured to report to console and Blizzard.\n\n await assertPlatformSupported();\n\n // LensCore is a foundational component which must be created asynchronously.\n // But it's annoying for every consumer of LensCore to have to wait on Promise<LensCore>\n // (which means they become async themselves). So we'll create a DI container which provides Promise<LensCore>,\n // wait for that promise once here, then create a new DI container that just contains LensCore.\n const lensCore = await telemetryContainer.provides(lensCoreFactory).get(lensCoreFactory.token);\n\n const container = telemetryContainer\n .provides(Injectable(lensCoreFactory.token, () => lensCore))\n .provides(lensesClientFactory)\n .provides(remoteApiSpecsClientFactory)\n .provides(cameraKitLensSourceFactory)\n .provides(lensPersistenceStoreFactory)\n .provides(deviceDependentAssetLoaderFactory)\n .provides(staticAssetLoaderFactory)\n .provides(lensAssetRepositoryFactory)\n .provides(lensRepositoryFactory)\n .provides(cameraKitFactory)\n .run(fetchWatermarkLens);\n\n const cameraKit = container.get(cameraKitFactory.token);\n\n bootstrapLatency.measure();\n container.get(metricsClientFactory.token).setOperationalMetrics(bootstrapLatency);\n\n return cameraKit;\n } catch (error) {\n if (shouldWrapError(error)) {\n error = bootstrapError(\"Error occurred during Camera Kit bootstrapping.\", error);\n }\n logger.error(error);\n throw error;\n }\n}\n\n/**\n * Extensions offer a way to provide custom implementations of certain parts of the CameraKit SDK.\n *\n * This enables more advanced use-cases, in which the default behavior of the SDK is substantially altered. For example,\n * replacing the default implementation that loads remote lens assets with a custom implementation that returns\n * different assets based on some business logic within the application.\n *\n * An extension is implemented as a {@link PartialContainer} – a collection of factory functions, each with its own\n * dependencies, which each provide some \"Service\". A Service can be of any type, and the CameraKit SDK defines its\n * own Services, some of which can be overridden by providing a custom implementation of the type via an extension.\n *\n * Here's an example of how extensions might be used:\n * ```ts\n * import { bootstrapCameraKit, createExtension, remoteMediaAssetLoaderFactory } from '@snap/camera-kit'\n *\n * const myCustomRemoteAssetLoader = Injectable(\n * remoteMediaAssetLoaderFactory.token,\n * [remoteMediaAssetLoaderFactory.token] as const,\n * (defaultLoader: AssetLoader): AssetLoader => {\n * return async (asset, lens) => {\n * if (lens?.id === MY_SPECIAL_LENS) {\n * return (await fetch('my/asset.glb')).arrayBuffer()\n * }\n * return defaultLoader(asset, lens)\n * }\n * },\n * )\n *\n * const myExtension = createExtension().provides(myCustomRemoteAssetLoader);\n * const cameraKit = bootstrapCameraKit(config, container => container.provides(myExtension));\n * ```\n *\n * This also enables greater modularity – the person/team creating the extension can do so in their own package, which\n * could be shared by many applications that all require the same functionality.\n *\n * @returns A {@link PartialContainer} which can be used to create a collection of Services, and can later be provided\n * to CameraKit's DI container during {@link bootstrapCameraKit}.\n *\n * @category Bootstrapping and Configuration\n */\nexport function createExtension(): PartialContainer {\n return new PartialContainer({});\n}\n"]}
@@ -1,3 +1,4 @@
1
+ import type { Observable } from "rxjs";
1
2
  import { Subject } from "rxjs";
2
3
  import type { PageVisibility } from "../common/pageVisibility";
3
4
  import type { ServerEvent } from "../generated-proto/blizzard/cameraKitEvents";
@@ -13,15 +14,27 @@ export declare class MetricsClient {
13
14
  setBusinessEvents(event: ServerEvent): Promise<void>;
14
15
  setOperationalMetrics(metric: Metric): Promise<void>;
15
16
  }
16
- /** @internal */
17
+ /**
18
+ * @internal
19
+ * @deprecated Use externalMetricsFactory instead, which provides an array of Observables that can be subscribed to,
20
+ * rather than a single Subject that is shared across all consumers.
21
+ * This allows for better encapsulation and prevents unintended interactions between
22
+ * different consumers of the metrics data.
23
+ */
17
24
  export declare const externalMetricsSubjectFactory: {
18
25
  (): Subject<Metric>;
19
26
  token: "externalMetricsSubject";
20
27
  dependencies: [];
21
28
  };
29
+ /** @internal */
30
+ export declare const externalMetricsFactory: {
31
+ (): Observable<Metric>[];
32
+ token: "externalMetrics";
33
+ dependencies: [];
34
+ };
22
35
  export declare const metricsClientFactory: {
23
- (args_0: Subject<Metric>, args_1: GrpcHandler, args_2: PageVisibility): MetricsClient;
36
+ (args_0: Subject<Metric>, args_1: Observable<Metric>[], args_2: GrpcHandler, args_3: PageVisibility): MetricsClient;
24
37
  token: "metricsClient";
25
- dependencies: readonly ["externalMetricsSubject", "grpcHandlerFactory", "pageVisibility"];
38
+ dependencies: readonly ["externalMetricsSubject", "externalMetrics", "grpcHandlerFactory", "pageVisibility"];
26
39
  };
27
40
  //# sourceMappingURL=metricsClient.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"metricsClient.d.ts","sourceRoot":"","sources":["../../src/clients/metricsClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAU,MAAM,MAAM,CAAC;AAEvC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6CAA6C,CAAC;AAO/E,OAAO,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,CAAC;AAqBjD,qBAAa,aAAa;IAKlB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAJ/B,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAsD;IAC5F,OAAO,CAAC,QAAQ,CAAC,yBAAyB,CAA4D;gBAGjF,UAAU,EAAE,oBAAoB,CAAC,OAAO,iBAAiB,CAAC,EAC3E,cAAc,EAAE,cAAc,GAAG,KAAK;IAgFpC,iBAAiB,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAIpD,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAO7D;AAID;;;;;;GAMG;AACH,eAAO,MAAM,6BAA6B;;;;CAAoE,CAAC;AAE/G,gBAAgB;AAChB,eAAO,MAAM,sBAAsB;;;;CAAkE,CAAC;AAEtG,eAAO,MAAM,oBAAoB;;;;CAuBhC,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import { __awaiter } from "tslib";
2
+ import { merge } from "rxjs";
2
3
  import { Subject, filter } from "rxjs";
3
4
  import { Injectable } from "@snap/ts-inject";
4
5
  import { pageVisibilityFactory } from "../common/pageVisibility";
@@ -82,15 +83,22 @@ export class MetricsClient {
82
83
  });
83
84
  }
84
85
  }
85
- const validExternalMetrics = /^push2web_/;
86
+ const validExternalMetrics = /^(push2web|react_camera_kit)_/;
86
87
  export const externalMetricsSubjectFactory = Injectable("externalMetricsSubject", () => new Subject());
87
- export const metricsClientFactory = Injectable("metricsClient", [externalMetricsSubjectFactory.token, grpcHandlerFactory.token, pageVisibilityFactory.token], (externalMetricsSubjectFactory, grpcHandler, pageVisibility) => {
88
- const metrics = new MetricsClient(createTsProtoClient(MetricsDefinition, grpcHandler), pageVisibility);
89
- externalMetricsSubjectFactory.pipe(filter((metric) => validExternalMetrics.test(metric.name))).subscribe({
88
+ export const externalMetricsFactory = Injectable("externalMetrics", () => []);
89
+ export const metricsClientFactory = Injectable("metricsClient", [
90
+ externalMetricsSubjectFactory.token,
91
+ externalMetricsFactory.token,
92
+ grpcHandlerFactory.token,
93
+ pageVisibilityFactory.token,
94
+ ], (externalMetricsSubjectFactory, externalMetrics, grpcHandler, pageVisibility) => {
95
+ const client = new MetricsClient(createTsProtoClient(MetricsDefinition, grpcHandler), pageVisibility);
96
+ const metrics = merge(externalMetricsSubjectFactory, ...externalMetrics);
97
+ metrics.pipe(filter((metric) => validExternalMetrics.test(metric.name))).subscribe({
90
98
  next: (metric) => {
91
- metrics.setOperationalMetrics(metric);
99
+ client.setOperationalMetrics(metric);
92
100
  },
93
101
  });
94
- return metrics;
102
+ return client;
95
103
  });
96
104
  //# sourceMappingURL=metricsClient.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"metricsClient.js","sourceRoot":"","sources":["../../src/clients/metricsClient.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAEjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6CAA6C,CAAC;AAM/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,oDAAoD,CAAC;AAEvF,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAG7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAGnD,MAAM,4BAA4B,GAAG,IAAI,CAAC;AAQ1C,MAAM,6BAA6B,GAAG,EAAE,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CAAC;IAEK,iBAAiB,CAAC,KAAkB;;YACtC,MAAM,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC;QAC5C,CAAC;KAAA;IAEK,qBAAqB,CAAC,MAAc;;YACtC,MAAM,OAAO,CAAC,GAAG,CACb,MAAM,CAAC,mBAAmB,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;gBACxC,OAAO,IAAI,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAC;YAClD,CAAC,CAAC,CACL,CAAC;QACN,CAAC;KAAA;CACJ;AAED,MAAM,oBAAoB,GAAG,YAAY,CAAC;AAG1C,MAAM,CAAC,MAAM,6BAA6B,GAAG,UAAU,CAAC,wBAAwB,EAAE,GAAG,EAAE,CAAC,IAAI,OAAO,EAAU,CAAC,CAAC;AAE/G,MAAM,CAAC,MAAM,oBAAoB,GAAG,UAAU,CAC1C,eAAe,EACf,CAAC,6BAA6B,CAAC,KAAK,EAAE,kBAAkB,CAAC,KAAK,EAAE,qBAAqB,CAAC,KAAK,CAAU,EACrG,CAAC,6BAA8C,EAAE,WAAwB,EAAE,cAA8B,EAAE,EAAE;IACzG,MAAM,OAAO,GAAG,IAAI,aAAa,CAAC,mBAAmB,CAAC,iBAAiB,EAAE,WAAW,CAAC,EAAE,cAAc,CAAC,CAAC;IACvG,6BAA6B,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,oBAAoB,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACrG,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE;YACb,OAAO,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC;QAC1C,CAAC;KACJ,CAAC,CAAC;IACH,OAAO,OAAO,CAAC;AACnB,CAAC,CACJ,CAAC","sourcesContent":["import { Subject, filter } from \"rxjs\";\nimport { Injectable } from \"@snap/ts-inject\";\nimport type { PageVisibility } from \"../common/pageVisibility\";\nimport { pageVisibilityFactory } from \"../common/pageVisibility\";\nimport type { ServerEvent } from \"../generated-proto/blizzard/cameraKitEvents\";\nimport { ServerEventBatch } from \"../generated-proto/blizzard/cameraKitEvents\";\nimport type {\n OperationalMetric,\n OperationalMetricsBundle,\n} from \"../generated-proto/pb_schema/camera_kit/v3/operational_metrics\";\nimport type { SetBusinessEventsRequest } from \"../generated-proto/pb_schema/camera_kit/v3/service\";\nimport { MetricsDefinition } from \"../generated-proto/pb_schema/camera_kit/v3/service\";\nimport type { Handler, RequestMetadata } from \"../handlers/HandlerChainBuilder\";\nimport { HandlerChainBuilder } from \"../handlers/HandlerChainBuilder\";\nimport { createBatchingHandler } from \"../handlers/batchingHandler\";\nimport { createMappingHandler } from \"../handlers/mappingHandler\";\nimport { createRateLimitingHandler } from \"../handlers/rateLimitingHandler\";\nimport { isCountMetric } from \"../metrics/operational/Count\";\nimport type { Metric } from \"../metrics/operational/Metric\";\nimport type { TsProtoServiceClient } from \"./createTsProtoClient\";\nimport { createTsProtoClient } from \"./createTsProtoClient\";\nimport type { GrpcHandler } from \"./grpcHandler\";\nimport { grpcHandlerFactory } from \"./grpcHandler\";\n\n// Send at most one metric (operational or business) per second.\nconst METRIC_REQUEST_RATE_LIMIT_MS = 1000;\n\n// It is rather cumbersome to check the actual final size of a batch, but we can easily limit the number of events we\n// include in each batch -- looking at historical data, typical events average ~1.3kb per event. But there are some\n// events (like CAMERA_KIT_EXCEPTION, which includes a stack trace) that can be much larger.\n//\n// To prevent us running over the 64kibibyte limit imposed by browsers on `keep-alive` requests, we'll set quite a low\n// limit to ensure we don't lose events which are larger in size than we expect.\nconst BUSINESS_EVENT_BATCH_MAX_SIZE = 10;\nconst BUSINESS_EVENT_BATCH_MAX_AGE_MS = 5000;\n\n// These values are (currently) arbitrarily selected.\n// TODO: Once we have gathered a sufficient quantity of metrics data, we should tune these numbers to ensure we're\n// operating with the right cost vs. alarming SLA vs. IDB storage size tradeoffs.\nconst METRIC_BATCH_MAX_SIZE = 100;\nconst METRIC_BATCH_MAX_AGE_MS = 5000;\n\nexport class MetricsClient {\n private readonly businessEventsHandler: Handler<ServerEvent, void, RequestInit | undefined>;\n private readonly operationalMetricsHandler: Handler<OperationalMetric, void, RequestInit | undefined>;\n\n constructor(\n private readonly grpcClient: TsProtoServiceClient<typeof MetricsDefinition>,\n pageVisibility: PageVisibility | false\n ) {\n // Both business events and operational metrics will share a rate limit.\n const rateLimitingHandler = createRateLimitingHandler<any, any, RequestMetadata>(\n METRIC_REQUEST_RATE_LIMIT_MS,\n pageVisibility\n );\n\n // The business events handler has to do some manual encoding, because the CameraKit service's backend expects\n // an `Any` type inside of SetBusinessEventsRequest -- even though this `Any` type is always `ServerEventBatch`.\n // eslint-disable-next-line max-len\n // See: https://github.sc-corp.net/Snapchat/pb_schema/blob/4bc5ec98243c472c848cccc577d8cfd21317af51/proto/camera_kit/v3/service.proto#L94\n this.businessEventsHandler = new HandlerChainBuilder(async (request: SetBusinessEventsRequest) => {\n await this.grpcClient.setBusinessEvents(request);\n })\n .map(rateLimitingHandler)\n .map(\n createMappingHandler((serverEvents: ServerEvent[]) => {\n const batch: ServerEventBatch = ServerEventBatch.fromPartial({ serverEvents });\n const request: SetBusinessEventsRequest = {\n batchEvents: {\n typeUrl: \"com.snapchat.analytics.blizzard.ServerEventBatch\",\n value: ServerEventBatch.encode(batch).finish(),\n },\n };\n return request;\n }, pageVisibility)\n )\n .map(\n createBatchingHandler({\n batchReduce: (previous: ServerEvent[] | undefined, event: ServerEvent) => {\n const batch = previous ?? [];\n batch.push(event);\n return batch;\n },\n isBatchComplete: (batch) => batch.length >= BUSINESS_EVENT_BATCH_MAX_SIZE,\n maxBatchAge: BUSINESS_EVENT_BATCH_MAX_AGE_MS,\n pageVisibility,\n })\n ).handler;\n\n // The operational metrics handler is slightly simpler, but it has more interesting batching logic (e.g. we can\n // sum up Count metrics, for example, rather than sending multiple single-count metrics objects).\n this.operationalMetricsHandler = new HandlerChainBuilder(async (metrics: OperationalMetricsBundle) => {\n await this.grpcClient.setOperationalMetrics({ metrics });\n })\n .map(rateLimitingHandler)\n .map(\n createBatchingHandler({\n // The batching logic here is very simple – it could be improved by e.g.\n // computing statistics to reduce overall data sent, etc. Right now this is\n // premature optimization, but could become a good idea in the future.\n batchReduce: (previous: OperationalMetricsBundle | undefined, metric: OperationalMetric) => {\n const batch: OperationalMetricsBundle = { metrics: previous?.metrics ?? [] };\n\n // For \"count\" metrics, it's straightforward to merge them into\n // a single metric with the same name.\n if (isCountMetric(metric)) {\n const priorCount = batch.metrics.find((m) => {\n return isCountMetric(m) && m.name === metric.name;\n });\n if (priorCount && isCountMetric(priorCount)) {\n priorCount.metric.count = `${\n Number(priorCount.metric.count) + Number(metric.metric.count)\n }`;\n return batch;\n }\n }\n\n // For all other cases, we'll just add the metric separately to the batch.\n batch.metrics.push(metric);\n return batch;\n },\n isBatchComplete: (bundle) => bundle.metrics.length >= METRIC_BATCH_MAX_SIZE,\n maxBatchAge: METRIC_BATCH_MAX_AGE_MS,\n pageVisibility,\n })\n ).handler;\n }\n\n async setBusinessEvents(event: ServerEvent): Promise<void> {\n await this.businessEventsHandler(event);\n }\n\n async setOperationalMetrics(metric: Metric): Promise<void> {\n await Promise.all(\n metric.toOperationalMetric().map((metric) => {\n return this.operationalMetricsHandler(metric);\n })\n );\n }\n}\n\nconst validExternalMetrics = /^push2web_/;\n\n/** @internal */\nexport const externalMetricsSubjectFactory = Injectable(\"externalMetricsSubject\", () => new Subject<Metric>());\n\nexport const metricsClientFactory = Injectable(\n \"metricsClient\",\n [externalMetricsSubjectFactory.token, grpcHandlerFactory.token, pageVisibilityFactory.token] as const,\n (externalMetricsSubjectFactory: Subject<Metric>, grpcHandler: GrpcHandler, pageVisibility: PageVisibility) => {\n const metrics = new MetricsClient(createTsProtoClient(MetricsDefinition, grpcHandler), pageVisibility);\n externalMetricsSubjectFactory.pipe(filter((metric) => validExternalMetrics.test(metric.name))).subscribe({\n next: (metric) => {\n metrics.setOperationalMetrics(metric);\n },\n });\n return metrics;\n }\n);\n"]}
1
+ {"version":3,"file":"metricsClient.js","sourceRoot":"","sources":["../../src/clients/metricsClient.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAEjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6CAA6C,CAAC;AAM/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,oDAAoD,CAAC;AAEvF,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAG7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAGnD,MAAM,4BAA4B,GAAG,IAAI,CAAC;AAQ1C,MAAM,6BAA6B,GAAG,EAAE,CAAC;AACzC,MAAM,+BAA+B,GAAG,IAAI,CAAC;AAK7C,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAClC,MAAM,uBAAuB,GAAG,IAAI,CAAC;AAErC,MAAM,OAAO,aAAa;IAItB,YACqB,UAA0D,EAC3E,cAAsC;QADrB,eAAU,GAAV,UAAU,CAAgD;QAI3E,MAAM,mBAAmB,GAAG,yBAAyB,CACjD,4BAA4B,EAC5B,cAAc,CACjB,CAAC;QAMF,IAAI,CAAC,qBAAqB,GAAG,IAAI,mBAAmB,CAAC,CAAO,OAA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;AAED,MAAM,oBAAoB,GAAG,+BAA+B,CAAC;AAS7D,MAAM,CAAC,MAAM,6BAA6B,GAAG,UAAU,CAAC,wBAAwB,EAAE,GAAG,EAAE,CAAC,IAAI,OAAO,EAAU,CAAC,CAAC;AAG/G,MAAM,CAAC,MAAM,sBAAsB,GAAG,UAAU,CAAC,iBAAiB,EAAE,GAAG,EAAE,CAAC,EAA0B,CAAC,CAAC;AAEtG,MAAM,CAAC,MAAM,oBAAoB,GAAG,UAAU,CAC1C,eAAe,EACf;IACI,6BAA6B,CAAC,KAAK;IACnC,sBAAsB,CAAC,KAAK;IAC5B,kBAAkB,CAAC,KAAK;IACxB,qBAAqB,CAAC,KAAK;CACrB,EACV,CACI,6BAA8C,EAC9C,eAAqC,EACrC,WAAwB,EACxB,cAA8B,EAChC,EAAE;IACA,MAAM,MAAM,GAAG,IAAI,aAAa,CAAC,mBAAmB,CAAC,iBAAiB,EAAE,WAAW,CAAC,EAAE,cAAc,CAAC,CAAC;IACtG,MAAM,OAAO,GAAG,KAAK,CAAC,6BAA6B,EAAE,GAAG,eAAe,CAAC,CAAC;IACzE,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,oBAAoB,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAC/E,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE;YACb,MAAM,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC;QACzC,CAAC;KACJ,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAClB,CAAC,CACJ,CAAC","sourcesContent":["import type { Observable } from \"rxjs\";\nimport { merge } from \"rxjs\";\nimport { Subject, filter } from \"rxjs\";\nimport { Injectable } from \"@snap/ts-inject\";\nimport type { PageVisibility } from \"../common/pageVisibility\";\nimport { pageVisibilityFactory } from \"../common/pageVisibility\";\nimport type { ServerEvent } from \"../generated-proto/blizzard/cameraKitEvents\";\nimport { ServerEventBatch } from \"../generated-proto/blizzard/cameraKitEvents\";\nimport type {\n OperationalMetric,\n OperationalMetricsBundle,\n} from \"../generated-proto/pb_schema/camera_kit/v3/operational_metrics\";\nimport type { SetBusinessEventsRequest } from \"../generated-proto/pb_schema/camera_kit/v3/service\";\nimport { MetricsDefinition } from \"../generated-proto/pb_schema/camera_kit/v3/service\";\nimport type { Handler, RequestMetadata } from \"../handlers/HandlerChainBuilder\";\nimport { HandlerChainBuilder } from \"../handlers/HandlerChainBuilder\";\nimport { createBatchingHandler } from \"../handlers/batchingHandler\";\nimport { createMappingHandler } from \"../handlers/mappingHandler\";\nimport { createRateLimitingHandler } from \"../handlers/rateLimitingHandler\";\nimport { isCountMetric } from \"../metrics/operational/Count\";\nimport type { Metric } from \"../metrics/operational/Metric\";\nimport type { TsProtoServiceClient } from \"./createTsProtoClient\";\nimport { createTsProtoClient } from \"./createTsProtoClient\";\nimport type { GrpcHandler } from \"./grpcHandler\";\nimport { grpcHandlerFactory } from \"./grpcHandler\";\n\n// Send at most one metric (operational or business) per second.\nconst METRIC_REQUEST_RATE_LIMIT_MS = 1000;\n\n// It is rather cumbersome to check the actual final size of a batch, but we can easily limit the number of events we\n// include in each batch -- looking at historical data, typical events average ~1.3kb per event. But there are some\n// events (like CAMERA_KIT_EXCEPTION, which includes a stack trace) that can be much larger.\n//\n// To prevent us running over the 64kibibyte limit imposed by browsers on `keep-alive` requests, we'll set quite a low\n// limit to ensure we don't lose events which are larger in size than we expect.\nconst BUSINESS_EVENT_BATCH_MAX_SIZE = 10;\nconst BUSINESS_EVENT_BATCH_MAX_AGE_MS = 5000;\n\n// These values are (currently) arbitrarily selected.\n// TODO: Once we have gathered a sufficient quantity of metrics data, we should tune these numbers to ensure we're\n// operating with the right cost vs. alarming SLA vs. IDB storage size tradeoffs.\nconst METRIC_BATCH_MAX_SIZE = 100;\nconst METRIC_BATCH_MAX_AGE_MS = 5000;\n\nexport class MetricsClient {\n private readonly businessEventsHandler: Handler<ServerEvent, void, RequestInit | undefined>;\n private readonly operationalMetricsHandler: Handler<OperationalMetric, void, RequestInit | undefined>;\n\n constructor(\n private readonly grpcClient: TsProtoServiceClient<typeof MetricsDefinition>,\n pageVisibility: PageVisibility | false\n ) {\n // Both business events and operational metrics will share a rate limit.\n const rateLimitingHandler = createRateLimitingHandler<any, any, RequestMetadata>(\n METRIC_REQUEST_RATE_LIMIT_MS,\n pageVisibility\n );\n\n // The business events handler has to do some manual encoding, because the CameraKit service's backend expects\n // an `Any` type inside of SetBusinessEventsRequest -- even though this `Any` type is always `ServerEventBatch`.\n // eslint-disable-next-line max-len\n // See: https://github.sc-corp.net/Snapchat/pb_schema/blob/4bc5ec98243c472c848cccc577d8cfd21317af51/proto/camera_kit/v3/service.proto#L94\n this.businessEventsHandler = new HandlerChainBuilder(async (request: SetBusinessEventsRequest) => {\n await this.grpcClient.setBusinessEvents(request);\n })\n .map(rateLimitingHandler)\n .map(\n createMappingHandler((serverEvents: ServerEvent[]) => {\n const batch: ServerEventBatch = ServerEventBatch.fromPartial({ serverEvents });\n const request: SetBusinessEventsRequest = {\n batchEvents: {\n typeUrl: \"com.snapchat.analytics.blizzard.ServerEventBatch\",\n value: ServerEventBatch.encode(batch).finish(),\n },\n };\n return request;\n }, pageVisibility)\n )\n .map(\n createBatchingHandler({\n batchReduce: (previous: ServerEvent[] | undefined, event: ServerEvent) => {\n const batch = previous ?? [];\n batch.push(event);\n return batch;\n },\n isBatchComplete: (batch) => batch.length >= BUSINESS_EVENT_BATCH_MAX_SIZE,\n maxBatchAge: BUSINESS_EVENT_BATCH_MAX_AGE_MS,\n pageVisibility,\n })\n ).handler;\n\n // The operational metrics handler is slightly simpler, but it has more interesting batching logic (e.g. we can\n // sum up Count metrics, for example, rather than sending multiple single-count metrics objects).\n this.operationalMetricsHandler = new HandlerChainBuilder(async (metrics: OperationalMetricsBundle) => {\n await this.grpcClient.setOperationalMetrics({ metrics });\n })\n .map(rateLimitingHandler)\n .map(\n createBatchingHandler({\n // The batching logic here is very simple – it could be improved by e.g.\n // computing statistics to reduce overall data sent, etc. Right now this is\n // premature optimization, but could become a good idea in the future.\n batchReduce: (previous: OperationalMetricsBundle | undefined, metric: OperationalMetric) => {\n const batch: OperationalMetricsBundle = { metrics: previous?.metrics ?? [] };\n\n // For \"count\" metrics, it's straightforward to merge them into\n // a single metric with the same name.\n if (isCountMetric(metric)) {\n const priorCount = batch.metrics.find((m) => {\n return isCountMetric(m) && m.name === metric.name;\n });\n if (priorCount && isCountMetric(priorCount)) {\n priorCount.metric.count = `${\n Number(priorCount.metric.count) + Number(metric.metric.count)\n }`;\n return batch;\n }\n }\n\n // For all other cases, we'll just add the metric separately to the batch.\n batch.metrics.push(metric);\n return batch;\n },\n isBatchComplete: (bundle) => bundle.metrics.length >= METRIC_BATCH_MAX_SIZE,\n maxBatchAge: METRIC_BATCH_MAX_AGE_MS,\n pageVisibility,\n })\n ).handler;\n }\n\n async setBusinessEvents(event: ServerEvent): Promise<void> {\n await this.businessEventsHandler(event);\n }\n\n async setOperationalMetrics(metric: Metric): Promise<void> {\n await Promise.all(\n metric.toOperationalMetric().map((metric) => {\n return this.operationalMetricsHandler(metric);\n })\n );\n }\n}\n\nconst validExternalMetrics = /^(push2web|react_camera_kit)_/;\n\n/**\n * @internal\n * @deprecated Use externalMetricsFactory instead, which provides an array of Observables that can be subscribed to,\n * rather than a single Subject that is shared across all consumers.\n * This allows for better encapsulation and prevents unintended interactions between\n * different consumers of the metrics data.\n */\nexport const externalMetricsSubjectFactory = Injectable(\"externalMetricsSubject\", () => new Subject<Metric>());\n\n/** @internal */\nexport const externalMetricsFactory = Injectable(\"externalMetrics\", () => [] as Observable<Metric>[]);\n\nexport const metricsClientFactory = Injectable(\n \"metricsClient\",\n [\n externalMetricsSubjectFactory.token,\n externalMetricsFactory.token,\n grpcHandlerFactory.token,\n pageVisibilityFactory.token,\n ] as const,\n (\n externalMetricsSubjectFactory: Subject<Metric>,\n externalMetrics: Observable<Metric>[],\n grpcHandler: GrpcHandler,\n pageVisibility: PageVisibility\n ) => {\n const client = new MetricsClient(createTsProtoClient(MetricsDefinition, grpcHandler), pageVisibility);\n const metrics = merge(externalMetricsSubjectFactory, ...externalMetrics);\n metrics.pipe(filter((metric) => validExternalMetrics.test(metric.name))).subscribe({\n next: (metric) => {\n client.setOperationalMetrics(metric);\n },\n });\n return client;\n }\n);\n"]}
@@ -10,9 +10,24 @@ interface CameraKitRuntimeConfiguration {
10
10
  userAgentFlavor: "release" | "debug";
11
11
  fonts: Font[];
12
12
  lensHttpHandler?: LensHttpHandler;
13
+ lensHttpValidationStrategy: ValidationStrategy;
13
14
  trustedTypesPolicyName: string;
14
15
  }
15
16
  export type CameraKitApiHostname = "camera-kit-api.snapar.com" | "api-kit.snapchat.com";
17
+ /**
18
+ * Defines how Camera Kit handles lens HTTP requests against Remote API specs in the My Lenses portal.
19
+ *
20
+ * - `"deny"`: Rejects all lens HTTP requests.
21
+ * - `"strict"`: Full validation: host + path + method + path parameters + query parameters + headers. Default.
22
+ * - `"route"`: Validates host + path + method + path parameters (skips query parameters and headers).
23
+ * - `"host"`: Validates host only.
24
+ * - `"unrestricted"`: No validation.
25
+ *
26
+ * @remarks
27
+ * Use `"unrestricted"` only if you fully trust your lens developers. Lenses will be able to make
28
+ * HTTP requests to any endpoint without validation against the allowlist.
29
+ */
30
+ export type ValidationStrategy = "deny" | "strict" | "route" | "host" | "unrestricted";
16
31
  /**
17
32
  * Represents a font to be used by Camera Kit for text rendering.
18
33
  */
@@ -170,8 +185,6 @@ export interface CameraKitBootstrapConfiguration {
170
185
  * If not specified, the Lens system will use a default HTTP implementation.
171
186
  *
172
187
  * @example
173
- * Here is an example of how to configure a custom `LensHttpHandler` to add an authentication token:
174
- *
175
188
  * ```typescript
176
189
  * const customLensHttpHandler: LensHttpHandler = async (url, init, lensRequest) => {
177
190
  * // Add an authentication token to the headers
@@ -198,6 +211,43 @@ export interface CameraKitBootstrapConfiguration {
198
211
  * ```
199
212
  */
200
213
  lensHttpHandler?: LensHttpHandler;
214
+ /**
215
+ * Configures how Camera Kit validates lens HTTP requests against Remote API specs.
216
+ *
217
+ * Available strategies:
218
+ * - `"deny"`: Rejects all lens HTTP requests.
219
+ * - `"strict"` (default): Full validation of host, path, method, and parameters.
220
+ * - `"route"`: Validates host, path (including path parameters), and method.
221
+ * Skips validation of query parameters and headers.
222
+ * - `"host"`: Only validates the host.
223
+ * - `"unrestricted"`: No validation.
224
+ *
225
+ * @remarks
226
+ * Use `"unrestricted"` only if you fully trust your lens developers, as lenses will be able to make
227
+ * HTTP requests to any endpoint without validation.
228
+ *
229
+ * @example
230
+ * ```typescript
231
+ * const cameraKit = bootstrapCameraKit({
232
+ * apiToken,
233
+ * lensHttpValidationStrategy: "host",
234
+ * });
235
+ * ```
236
+ *
237
+ * @example
238
+ * Combine with custom handler:
239
+ * ```typescript
240
+ * const cameraKit = bootstrapCameraKit({
241
+ * apiToken,
242
+ * lensHttpValidationStrategy: "unrestricted",
243
+ * lensHttpHandler: async (url, init, lensRequest) => {
244
+ * // Custom logic here
245
+ * return fetch(url, init);
246
+ * },
247
+ * });
248
+ * ```
249
+ */
250
+ lensHttpValidationStrategy?: ValidationStrategy;
201
251
  /**
202
252
  * The name of the Trusted Types policy to use when loading scripts.
203
253
  * Defaults to "snap-camera-kit".
@@ -1 +1 @@
1
- {"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../src/configuration.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,4CAA4C,CAAC;AAG3F,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAyB,KAAK,MAAM,EAAE,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AA2BpF,UAAU,6BAA6B;IACnC,eAAe,EAAE,wBAAwB,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;IAC9E,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,QAAQ,CAAC;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AE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IAEpD;;;;;OAKG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAE9B;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;;;;;;;;;;;;OAcG;IACH,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC;IAEf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACH,eAAe,CAAC,EAAE,eAAe,CAAC;IAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmCG;IACH,0BAA0B,CAAC,EAAE,kBAAkB,CAAC;IAEhD;;;OAGG;IACH,sBAAsB,CAAC,EAAE,MAAM,CAAC;CACnC;AAED;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAAG,6BAA6B,GAAG,+BAA+B,CAAC;AAErG,gBAAgB;AAChB,eAAO,MAAM,kBAAkB,kBAAkB,CAAC;AAelD,gBAAgB;AAChB,eAAO,MAAM,mCAAmC,kBAAmB,+BAA+B;;;;CA4BjG,CAAC"}
@@ -10,6 +10,7 @@ const defaultConfiguration = {
10
10
  apiHostname: "camera-kit-api.snapar.com",
11
11
  userAgentFlavor: "release",
12
12
  fonts: [],
13
+ lensHttpValidationStrategy: "strict",
13
14
  trustedTypesPolicyName: "snap-camera-kit",
14
15
  };
15
16
  export const configurationToken = "configuration";