@snap/camera-kit 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (554) hide show
  1. package/LICENSE.md +6247 -0
  2. package/README.md +166 -0
  3. package/docs/html/.nojekyll +1 -0
  4. package/docs/html/assets/highlight.css +106 -0
  5. package/docs/html/assets/main.js +54 -0
  6. package/docs/html/assets/search.js +1 -0
  7. package/docs/html/assets/style.css +1225 -0
  8. package/docs/html/assets/widgets.png +0 -0
  9. package/docs/html/assets/widgets@2x.png +0 -0
  10. package/docs/html/classes/CameraKit.html +121 -0
  11. package/docs/html/classes/CameraKitSession.html +347 -0
  12. package/docs/html/classes/CameraKitSource.html +152 -0
  13. package/docs/html/classes/LensPerformanceMeasurement.html +115 -0
  14. package/docs/html/classes/LensPerformanceMetrics.html +76 -0
  15. package/docs/html/classes/LensRepository.html +171 -0
  16. package/docs/html/classes/LensSources.html +82 -0
  17. package/docs/html/classes/Transform2D.html +99 -0
  18. package/docs/html/classes/TypedCustomEvent.html +109 -0
  19. package/docs/html/classes/TypedEventTarget.html +146 -0
  20. package/docs/html/functions/Injectable.html +193 -0
  21. package/docs/html/functions/bootstrapCameraKit.html +158 -0
  22. package/docs/html/functions/createExtension.html +127 -0
  23. package/docs/html/functions/createImageSource.html +123 -0
  24. package/docs/html/functions/createMediaStreamSource.html +123 -0
  25. package/docs/html/functions/createUserMediaSource.html +127 -0
  26. package/docs/html/functions/createVideoSource.html +124 -0
  27. package/docs/html/functions/estimateLensPerformance.html +116 -0
  28. package/docs/html/functions/getRequiredBootstrapURLs.html +124 -0
  29. package/docs/html/functions/lensSourcesFactory.html +116 -0
  30. package/docs/html/functions/uriHandlersFactory.html +118 -0
  31. package/docs/html/index.html +208 -0
  32. package/docs/html/interfaces/CameraKitBootstrapConfiguration.html +132 -0
  33. package/docs/html/interfaces/CameraKitSourceSubscriber.html +121 -0
  34. package/docs/html/interfaces/ComputedFrameMetrics.html +70 -0
  35. package/docs/html/interfaces/CreateSessionOptions.html +77 -0
  36. package/docs/html/interfaces/EstimatedLensPerformance.html +78 -0
  37. package/docs/html/interfaces/Lens.html +115 -0
  38. package/docs/html/interfaces/LensSource.html +113 -0
  39. package/docs/html/interfaces/MediaStreamSourceOptions.html +65 -0
  40. package/docs/html/interfaces/UriCancelRequest.html +65 -0
  41. package/docs/html/interfaces/UriHandler.html +128 -0
  42. package/docs/html/interfaces/UriRequest.html +80 -0
  43. package/docs/html/interfaces/UriResponse.html +80 -0
  44. package/docs/html/interfaces/VideoSourceOptions.html +60 -0
  45. package/docs/html/modules.html +198 -0
  46. package/docs/html/types/AssetLoader.html +126 -0
  47. package/docs/html/types/AssetTiming.html +116 -0
  48. package/docs/html/types/BenchmarkError.html +107 -0
  49. package/docs/html/types/BootstrapError.html +110 -0
  50. package/docs/html/types/CacheKeyNotFoundError.html +107 -0
  51. package/docs/html/types/CameraKitDeviceInfo.html +114 -0
  52. package/docs/html/types/CameraKitSessionEventListener.html +109 -0
  53. package/docs/html/types/CameraKitSessionEvents.html +118 -0
  54. package/docs/html/types/CameraKitSourceError.html +107 -0
  55. package/docs/html/types/CameraKitSourceInfo.html +107 -0
  56. package/docs/html/types/CameraKitSourceOptions.html +113 -0
  57. package/docs/html/types/ConfigurationError.html +109 -0
  58. package/docs/html/types/Keyboard.html +196 -0
  59. package/docs/html/types/KeyboardEvents.html +109 -0
  60. package/docs/html/types/LegalError.html +107 -0
  61. package/docs/html/types/LensAssetError.html +109 -0
  62. package/docs/html/types/LensContentValidationError.html +107 -0
  63. package/docs/html/types/LensError.html +107 -0
  64. package/docs/html/types/LensExecutionError.html +114 -0
  65. package/docs/html/types/LensImagePickerError.html +110 -0
  66. package/docs/html/types/LensLaunchParams.html +109 -0
  67. package/docs/html/types/LensMetricsEvents.html +110 -0
  68. package/docs/html/types/LensPerformanceCluster.html +107 -0
  69. package/docs/html/types/LensView.html +119 -0
  70. package/docs/html/types/LensWait.html +111 -0
  71. package/docs/html/types/PersistentStoreError.html +109 -0
  72. package/docs/html/types/PlatformNotSupportedError.html +110 -0
  73. package/docs/html/types/PublicContainer.html +110 -0
  74. package/docs/html/types/RenderTarget.html +111 -0
  75. package/docs/html/types/Uri.html +107 -0
  76. package/docs/html/types/UriHandlers.html +109 -0
  77. package/docs/html/types/WebGLError.html +107 -0
  78. package/docs/html/variables/extensionRequestContext.html +109 -0
  79. package/docs/md/.nojekyll +1 -0
  80. package/docs/md/README.md +168 -0
  81. package/docs/md/classes/CameraKit.md +94 -0
  82. package/docs/md/classes/CameraKitSession.md +359 -0
  83. package/docs/md/classes/CameraKitSource.md +110 -0
  84. package/docs/md/classes/LensPerformanceMeasurement.md +77 -0
  85. package/docs/md/classes/LensPerformanceMetrics.md +37 -0
  86. package/docs/md/classes/LensRepository.md +145 -0
  87. package/docs/md/classes/LensSources.md +29 -0
  88. package/docs/md/classes/Transform2D.md +55 -0
  89. package/docs/md/classes/TypedCustomEvent.md +65 -0
  90. package/docs/md/classes/TypedEventTarget.md +103 -0
  91. package/docs/md/interfaces/CameraKitBootstrapConfiguration.md +106 -0
  92. package/docs/md/interfaces/CameraKitSourceSubscriber.md +55 -0
  93. package/docs/md/interfaces/ComputedFrameMetrics.md +29 -0
  94. package/docs/md/interfaces/CreateSessionOptions.md +35 -0
  95. package/docs/md/interfaces/EstimatedLensPerformance.md +38 -0
  96. package/docs/md/interfaces/Lens.md +84 -0
  97. package/docs/md/interfaces/LensSource.md +68 -0
  98. package/docs/md/interfaces/MediaStreamSourceOptions.md +22 -0
  99. package/docs/md/interfaces/UriCancelRequest.md +22 -0
  100. package/docs/md/interfaces/UriHandler.md +63 -0
  101. package/docs/md/interfaces/UriRequest.md +43 -0
  102. package/docs/md/interfaces/UriResponse.md +43 -0
  103. package/docs/md/interfaces/VideoSourceOptions.md +15 -0
  104. package/docs/md/modules.md +827 -0
  105. package/lib/CameraKit.d.ts +170 -0
  106. package/lib/CameraKit.js +145 -0
  107. package/lib/CameraKit.js.map +1 -0
  108. package/lib/__tests__/data.d.ts +9 -0
  109. package/lib/__tests__/data.js +50 -0
  110. package/lib/__tests__/data.js.map +1 -0
  111. package/lib/__tests__/deferred.d.ts +16 -0
  112. package/lib/__tests__/deferred.js +29 -0
  113. package/lib/__tests__/deferred.js.map +1 -0
  114. package/lib/__tests__/jest.matchers.d.ts +17 -0
  115. package/lib/__tests__/jest.matchers.js +67 -0
  116. package/lib/__tests__/jest.matchers.js.map +1 -0
  117. package/lib/assertPlatformSupported.d.ts +4 -0
  118. package/lib/assertPlatformSupported.js +10 -0
  119. package/lib/assertPlatformSupported.js.map +1 -0
  120. package/lib/benchmark/benchmarkGflops.d.ts +16 -0
  121. package/lib/benchmark/benchmarkGflops.js +129 -0
  122. package/lib/benchmark/benchmarkGflops.js.map +1 -0
  123. package/lib/benchmark/estimateLensPerformanceCluster.d.ts +33 -0
  124. package/lib/benchmark/estimateLensPerformanceCluster.js +48 -0
  125. package/lib/benchmark/estimateLensPerformanceCluster.js.map +1 -0
  126. package/lib/benchmark/webglUtils.d.ts +7 -0
  127. package/lib/benchmark/webglUtils.js +87 -0
  128. package/lib/benchmark/webglUtils.js.map +1 -0
  129. package/lib/bootstrapCameraKit.d.ts +96 -0
  130. package/lib/bootstrapCameraKit.js +204 -0
  131. package/lib/bootstrapCameraKit.js.map +1 -0
  132. package/lib/common/__mocks__/loadScript.d.ts +1 -0
  133. package/lib/common/__mocks__/loadScript.js +10 -0
  134. package/lib/common/__mocks__/loadScript.js.map +1 -0
  135. package/lib/common/assertions.d.ts +27 -0
  136. package/lib/common/assertions.js +39 -0
  137. package/lib/common/assertions.js.map +1 -0
  138. package/lib/common/cameraKitUserAgent.d.ts +34 -0
  139. package/lib/common/cameraKitUserAgent.js +216 -0
  140. package/lib/common/cameraKitUserAgent.js.map +1 -0
  141. package/lib/common/copyDefinedProperties.d.ts +13 -0
  142. package/lib/common/copyDefinedProperties.js +16 -0
  143. package/lib/common/copyDefinedProperties.js.map +1 -0
  144. package/lib/common/entries.d.ts +3 -0
  145. package/lib/common/entries.js +3 -0
  146. package/lib/common/entries.js.map +1 -0
  147. package/lib/common/errorHelpers.d.ts +10 -0
  148. package/lib/common/errorHelpers.js +24 -0
  149. package/lib/common/errorHelpers.js.map +1 -0
  150. package/lib/common/getFilename.d.ts +1 -0
  151. package/lib/common/getFilename.js +4 -0
  152. package/lib/common/getFilename.js.map +1 -0
  153. package/lib/common/index.d.ts +2 -0
  154. package/lib/common/index.js +3 -0
  155. package/lib/common/index.js.map +1 -0
  156. package/lib/common/loadScript.d.ts +1 -0
  157. package/lib/common/loadScript.js +11 -0
  158. package/lib/common/loadScript.js.map +1 -0
  159. package/lib/common/locale.d.ts +2 -0
  160. package/lib/common/locale.js +11 -0
  161. package/lib/common/locale.js.map +1 -0
  162. package/lib/common/localization.d.ts +43 -0
  163. package/lib/common/localization.js +43 -0
  164. package/lib/common/localization.js.map +1 -0
  165. package/lib/common/memoize.d.ts +8 -0
  166. package/lib/common/memoize.js +15 -0
  167. package/lib/common/memoize.js.map +1 -0
  168. package/lib/common/pageVisibility.d.ts +20 -0
  169. package/lib/common/pageVisibility.js +62 -0
  170. package/lib/common/pageVisibility.js.map +1 -0
  171. package/lib/common/time.d.ts +1 -0
  172. package/lib/common/time.js +2 -0
  173. package/lib/common/time.js.map +1 -0
  174. package/lib/common/typeguards.d.ts +53 -0
  175. package/lib/common/typeguards.js +92 -0
  176. package/lib/common/typeguards.js.map +1 -0
  177. package/lib/common/types.d.ts +10 -0
  178. package/lib/common/types.js +2 -0
  179. package/lib/common/types.js.map +1 -0
  180. package/lib/common/validate.d.ts +14 -0
  181. package/lib/common/validate.js +104 -0
  182. package/lib/common/validate.js.map +1 -0
  183. package/lib/configuration.d.ts +92 -0
  184. package/lib/configuration.js +36 -0
  185. package/lib/configuration.js.map +1 -0
  186. package/lib/configurationOverrides.d.ts +12 -0
  187. package/lib/configurationOverrides.js +41 -0
  188. package/lib/configurationOverrides.js.map +1 -0
  189. package/lib/dependency-injection/Container.d.ts +177 -0
  190. package/lib/dependency-injection/Container.js +160 -0
  191. package/lib/dependency-injection/Container.js.map +1 -0
  192. package/lib/dependency-injection/Injectable.d.ts +39 -0
  193. package/lib/dependency-injection/Injectable.js +18 -0
  194. package/lib/dependency-injection/Injectable.js.map +1 -0
  195. package/lib/dependency-injection/PartialContainer.d.ts +81 -0
  196. package/lib/dependency-injection/PartialContainer.js +85 -0
  197. package/lib/dependency-injection/PartialContainer.js.map +1 -0
  198. package/lib/dependency-injection/RootServices.d.ts +62 -0
  199. package/lib/dependency-injection/RootServices.js +2 -0
  200. package/lib/dependency-injection/RootServices.js.map +1 -0
  201. package/lib/dependency-injection/types.d.ts +56 -0
  202. package/lib/dependency-injection/types.js +2 -0
  203. package/lib/dependency-injection/types.js.map +1 -0
  204. package/lib/environment.json +1 -0
  205. package/lib/events/TypedCustomEvent.d.ts +10 -0
  206. package/lib/events/TypedCustomEvent.js +11 -0
  207. package/lib/events/TypedCustomEvent.js.map +1 -0
  208. package/lib/events/TypedEventTarget.d.ts +25 -0
  209. package/lib/events/TypedEventTarget.js +57 -0
  210. package/lib/events/TypedEventTarget.js.map +1 -0
  211. package/lib/events/scan.d.ts +15 -0
  212. package/lib/events/scan.js +46 -0
  213. package/lib/events/scan.js.map +1 -0
  214. package/lib/extensions/LensSources.d.ts +58 -0
  215. package/lib/extensions/LensSources.js +50 -0
  216. package/lib/extensions/LensSources.js.map +1 -0
  217. package/lib/extensions/UriHandlers.d.ts +54 -0
  218. package/lib/extensions/UriHandlers.js +93 -0
  219. package/lib/extensions/UriHandlers.js.map +1 -0
  220. package/lib/extensions/extensionRequestContext.d.ts +4 -0
  221. package/lib/extensions/extensionRequestContext.js +14 -0
  222. package/lib/extensions/extensionRequestContext.js.map +1 -0
  223. package/lib/generated-proto/blizzard/cameraKitEvents.d.ts +5603 -0
  224. package/lib/generated-proto/blizzard/cameraKitEvents.js +522 -0
  225. package/lib/generated-proto/blizzard/cameraKitEvents.js.map +1 -0
  226. package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.d.ts +98 -0
  227. package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.js +260 -0
  228. package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.js.map +1 -0
  229. package/lib/generated-proto/pb_schema/camera_kit/v3/export.d.ts +543 -0
  230. package/lib/generated-proto/pb_schema/camera_kit/v3/export.js +429 -0
  231. package/lib/generated-proto/pb_schema/camera_kit/v3/export.js.map +1 -0
  232. package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.d.ts +100 -0
  233. package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.js +164 -0
  234. package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.js.map +1 -0
  235. package/lib/generated-proto/pb_schema/camera_kit/v3/lens.d.ts +395 -0
  236. package/lib/generated-proto/pb_schema/camera_kit/v3/lens.js +644 -0
  237. package/lib/generated-proto/pb_schema/camera_kit/v3/lens.js.map +1 -0
  238. package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.d.ts +185 -0
  239. package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.js +172 -0
  240. package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.js.map +1 -0
  241. package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.d.ts +86 -0
  242. package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.js +234 -0
  243. package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.js.map +1 -0
  244. package/lib/generated-proto/pb_schema/camera_kit/v3/service.d.ts +854 -0
  245. package/lib/generated-proto/pb_schema/camera_kit/v3/service.js +629 -0
  246. package/lib/generated-proto/pb_schema/camera_kit/v3/service.js.map +1 -0
  247. package/lib/generated-proto/pb_schema/cdp/cof/benchmark.d.ts +86 -0
  248. package/lib/generated-proto/pb_schema/cdp/cof/benchmark.js +185 -0
  249. package/lib/generated-proto/pb_schema/cdp/cof/benchmark.js.map +1 -0
  250. package/lib/generated-proto/pb_schema/cdp/cof/benchmark_name.d.ts +95 -0
  251. package/lib/generated-proto/pb_schema/cdp/cof/benchmark_name.js +104 -0
  252. package/lib/generated-proto/pb_schema/cdp/cof/benchmark_name.js.map +1 -0
  253. package/lib/generated-proto/pb_schema/cdp/cof/circumstance_service.d.ts +10212 -0
  254. package/lib/generated-proto/pb_schema/cdp/cof/circumstance_service.js +1300 -0
  255. package/lib/generated-proto/pb_schema/cdp/cof/circumstance_service.js.map +1 -0
  256. package/lib/generated-proto/pb_schema/cdp/cof/config_request.d.ts +401 -0
  257. package/lib/generated-proto/pb_schema/cdp/cof/config_request.js +525 -0
  258. package/lib/generated-proto/pb_schema/cdp/cof/config_request.js.map +1 -0
  259. package/lib/generated-proto/pb_schema/cdp/cof/config_response.d.ts +1287 -0
  260. package/lib/generated-proto/pb_schema/cdp/cof/config_response.js +135 -0
  261. package/lib/generated-proto/pb_schema/cdp/cof/config_response.js.map +1 -0
  262. package/lib/generated-proto/pb_schema/cdp/cof/config_result.d.ts +4208 -0
  263. package/lib/generated-proto/pb_schema/cdp/cof/config_result.js +1053 -0
  264. package/lib/generated-proto/pb_schema/cdp/cof/config_result.js.map +1 -0
  265. package/lib/generated-proto/pb_schema/cdp/cof/debug_info.d.ts +102 -0
  266. package/lib/generated-proto/pb_schema/cdp/cof/debug_info.js +165 -0
  267. package/lib/generated-proto/pb_schema/cdp/cof/debug_info.js.map +1 -0
  268. package/lib/generated-proto/pb_schema/cdp/cof/namespace.d.ts +8 -0
  269. package/lib/generated-proto/pb_schema/cdp/cof/namespace.js +17 -0
  270. package/lib/generated-proto/pb_schema/cdp/cof/namespace.js.map +1 -0
  271. package/lib/generated-proto/pb_schema/common/ruid.d.ts +75 -0
  272. package/lib/generated-proto/pb_schema/common/ruid.js +96 -0
  273. package/lib/generated-proto/pb_schema/common/ruid.js.map +1 -0
  274. package/lib/generated-proto/pb_schema/common/value.d.ts +131 -0
  275. package/lib/generated-proto/pb_schema/common/value.js +204 -0
  276. package/lib/generated-proto/pb_schema/common/value.js.map +1 -0
  277. package/lib/generated-proto/pb_schema/google/api/annotations.d.ts +1 -0
  278. package/lib/generated-proto/pb_schema/google/api/annotations.js +9 -0
  279. package/lib/generated-proto/pb_schema/google/api/annotations.js.map +1 -0
  280. package/lib/generated-proto/pb_schema/google/api/http.d.ts +3636 -0
  281. package/lib/generated-proto/pb_schema/google/api/http.js +271 -0
  282. package/lib/generated-proto/pb_schema/google/api/http.js.map +1 -0
  283. package/lib/generated-proto/pb_schema/google/protobuf/any.d.ts +139 -0
  284. package/lib/generated-proto/pb_schema/google/protobuf/any.js +94 -0
  285. package/lib/generated-proto/pb_schema/google/protobuf/any.js.map +1 -0
  286. package/lib/generated-proto/pb_schema/google/protobuf/descriptor.d.ts +50968 -0
  287. package/lib/generated-proto/pb_schema/google/protobuf/descriptor.js +2962 -0
  288. package/lib/generated-proto/pb_schema/google/protobuf/descriptor.js.map +1 -0
  289. package/lib/generated-proto/pb_schema/google/protobuf/timestamp.d.ts +98 -0
  290. package/lib/generated-proto/pb_schema/google/protobuf/timestamp.js +82 -0
  291. package/lib/generated-proto/pb_schema/google/protobuf/timestamp.js.map +1 -0
  292. package/lib/generated-proto/pb_schema/google/protobuf/wrappers.d.ts +173 -0
  293. package/lib/generated-proto/pb_schema/google/protobuf/wrappers.js +332 -0
  294. package/lib/generated-proto/pb_schema/google/protobuf/wrappers.js.map +1 -0
  295. package/lib/generated-proto/pb_schema/lenses/geocircle.d.ts +42 -0
  296. package/lib/generated-proto/pb_schema/lenses/geocircle.js +52 -0
  297. package/lib/generated-proto/pb_schema/lenses/geocircle.js.map +1 -0
  298. package/lib/generated-proto/pb_schema/lenses/geopoint.d.ts +32 -0
  299. package/lib/generated-proto/pb_schema/lenses/geopoint.js +50 -0
  300. package/lib/generated-proto/pb_schema/lenses/geopoint.js.map +1 -0
  301. package/lib/generated-proto/pb_schema/lenses/launch_params.d.ts +29 -0
  302. package/lib/generated-proto/pb_schema/lenses/launch_params.js +43 -0
  303. package/lib/generated-proto/pb_schema/lenses/launch_params.js.map +1 -0
  304. package/lib/generated-proto/pb_schema/lenses/launchdata.d.ts +365 -0
  305. package/lib/generated-proto/pb_schema/lenses/launchdata.js +216 -0
  306. package/lib/generated-proto/pb_schema/lenses/launchdata.js.map +1 -0
  307. package/lib/generated-proto/pb_schema/lenses/lures.d.ts +113 -0
  308. package/lib/generated-proto/pb_schema/lenses/lures.js +64 -0
  309. package/lib/generated-proto/pb_schema/lenses/lures.js.map +1 -0
  310. package/lib/generated-proto/pb_schema/lenses/persistent_store.d.ts +29 -0
  311. package/lib/generated-proto/pb_schema/lenses/persistent_store.js +43 -0
  312. package/lib/generated-proto/pb_schema/lenses/persistent_store.js.map +1 -0
  313. package/lib/generated-proto/pb_schema/lenses/snappable.d.ts +921 -0
  314. package/lib/generated-proto/pb_schema/lenses/snappable.js +954 -0
  315. package/lib/generated-proto/pb_schema/lenses/snappable.js.map +1 -0
  316. package/lib/generated-proto/pb_schema/lenses/user_data.d.ts +247 -0
  317. package/lib/generated-proto/pb_schema/lenses/user_data.js +362 -0
  318. package/lib/generated-proto/pb_schema/lenses/user_data.js.map +1 -0
  319. package/lib/handlers/HandlerChainBuilder.d.ts +95 -0
  320. package/lib/handlers/HandlerChainBuilder.js +187 -0
  321. package/lib/handlers/HandlerChainBuilder.js.map +1 -0
  322. package/lib/handlers/arrayBufferParsingHandler.d.ts +10 -0
  323. package/lib/handlers/arrayBufferParsingHandler.js +18 -0
  324. package/lib/handlers/arrayBufferParsingHandler.js.map +1 -0
  325. package/lib/handlers/batchingHandler.d.ts +25 -0
  326. package/lib/handlers/batchingHandler.js +79 -0
  327. package/lib/handlers/batchingHandler.js.map +1 -0
  328. package/lib/handlers/cameraKitServiceFetchHandlerFactory.d.ts +12 -0
  329. package/lib/handlers/cameraKitServiceFetchHandlerFactory.js +19 -0
  330. package/lib/handlers/cameraKitServiceFetchHandlerFactory.js.map +1 -0
  331. package/lib/handlers/debugHandler.d.ts +8 -0
  332. package/lib/handlers/debugHandler.js +27 -0
  333. package/lib/handlers/debugHandler.js.map +1 -0
  334. package/lib/handlers/defaultFetchHandler.d.ts +15 -0
  335. package/lib/handlers/defaultFetchHandler.js +29 -0
  336. package/lib/handlers/defaultFetchHandler.js.map +1 -0
  337. package/lib/handlers/headersModifyingFetchHandler.d.ts +8 -0
  338. package/lib/handlers/headersModifyingFetchHandler.js +13 -0
  339. package/lib/handlers/headersModifyingFetchHandler.js.map +1 -0
  340. package/lib/handlers/index.d.ts +2 -0
  341. package/lib/handlers/index.js +3 -0
  342. package/lib/handlers/index.js.map +1 -0
  343. package/lib/handlers/mappingHandler.d.ts +15 -0
  344. package/lib/handlers/mappingHandler.js +65 -0
  345. package/lib/handlers/mappingHandler.js.map +1 -0
  346. package/lib/handlers/noCorsRetryingFetchHandler.d.ts +48 -0
  347. package/lib/handlers/noCorsRetryingFetchHandler.js +94 -0
  348. package/lib/handlers/noCorsRetryingFetchHandler.js.map +1 -0
  349. package/lib/handlers/persistingHandler.d.ts +14 -0
  350. package/lib/handlers/persistingHandler.js +71 -0
  351. package/lib/handlers/persistingHandler.js.map +1 -0
  352. package/lib/handlers/rateLimitingHandler.d.ts +20 -0
  353. package/lib/handlers/rateLimitingHandler.js +43 -0
  354. package/lib/handlers/rateLimitingHandler.js.map +1 -0
  355. package/lib/handlers/requestStateEmittingHandler.d.ts +29 -0
  356. package/lib/handlers/requestStateEmittingHandler.js +43 -0
  357. package/lib/handlers/requestStateEmittingHandler.js.map +1 -0
  358. package/lib/handlers/responseCachingHandler.d.ts +27 -0
  359. package/lib/handlers/responseCachingHandler.js +94 -0
  360. package/lib/handlers/responseCachingHandler.js.map +1 -0
  361. package/lib/handlers/retryingHandler.d.ts +37 -0
  362. package/lib/handlers/retryingHandler.js +73 -0
  363. package/lib/handlers/retryingHandler.js.map +1 -0
  364. package/lib/handlers/timeoutHandler.d.ts +18 -0
  365. package/lib/handlers/timeoutHandler.js +30 -0
  366. package/lib/handlers/timeoutHandler.js.map +1 -0
  367. package/lib/index.d.ts +33 -0
  368. package/lib/index.js +32 -0
  369. package/lib/index.js.map +1 -0
  370. package/lib/legal/legalPrompt.d.ts +17 -0
  371. package/lib/legal/legalPrompt.js +144 -0
  372. package/lib/legal/legalPrompt.js.map +1 -0
  373. package/lib/legal/legalState.d.ts +50 -0
  374. package/lib/legal/legalState.js +149 -0
  375. package/lib/legal/legalState.js.map +1 -0
  376. package/lib/lens/Lens.d.ts +71 -0
  377. package/lib/lens/Lens.js +63 -0
  378. package/lib/lens/Lens.js.map +1 -0
  379. package/lib/lens/LensLaunchParams.d.ts +19 -0
  380. package/lib/lens/LensLaunchParams.js +38 -0
  381. package/lib/lens/LensLaunchParams.js.map +1 -0
  382. package/lib/lens/LensPersistenceStore.d.ts +7 -0
  383. package/lib/lens/LensPersistenceStore.js +20 -0
  384. package/lib/lens/LensPersistenceStore.js.map +1 -0
  385. package/lib/lens/LensRepository.d.ts +134 -0
  386. package/lib/lens/LensRepository.js +239 -0
  387. package/lib/lens/LensRepository.js.map +1 -0
  388. package/lib/lens/assets/LensAssetRepository.d.ts +66 -0
  389. package/lib/lens/assets/LensAssetRepository.js +179 -0
  390. package/lib/lens/assets/LensAssetRepository.js.map +1 -0
  391. package/lib/lens/assets/LensAssetsProvider.d.ts +21 -0
  392. package/lib/lens/assets/LensAssetsProvider.js +41 -0
  393. package/lib/lens/assets/LensAssetsProvider.js.map +1 -0
  394. package/lib/lens/assets/deviceDependentAssetLoader.d.ts +11 -0
  395. package/lib/lens/assets/deviceDependentAssetLoader.js +58 -0
  396. package/lib/lens/assets/deviceDependentAssetLoader.js.map +1 -0
  397. package/lib/lens/assets/remoteMediaAssetLoaderFactory.d.ts +10 -0
  398. package/lib/lens/assets/remoteMediaAssetLoaderFactory.js +26 -0
  399. package/lib/lens/assets/remoteMediaAssetLoaderFactory.js.map +1 -0
  400. package/lib/lens/assets/staticAssetLoader.d.ts +10 -0
  401. package/lib/lens/assets/staticAssetLoader.js +24 -0
  402. package/lib/lens/assets/staticAssetLoader.js.map +1 -0
  403. package/lib/lens/index.d.ts +7 -0
  404. package/lib/lens/index.js +7 -0
  405. package/lib/lens/index.js.map +1 -0
  406. package/lib/lens/lensEnvelopeUtil.d.ts +5 -0
  407. package/lib/lens/lensEnvelopeUtil.js +19 -0
  408. package/lib/lens/lensEnvelopeUtil.js.map +1 -0
  409. package/lib/lens/lensHttpUtil.d.ts +4 -0
  410. package/lib/lens/lensHttpUtil.js +30 -0
  411. package/lib/lens/lensHttpUtil.js.map +1 -0
  412. package/lib/lens-client-interface/exif.d.ts +20 -0
  413. package/lib/lens-client-interface/exif.js +61 -0
  414. package/lib/lens-client-interface/exif.js.map +1 -0
  415. package/lib/lens-client-interface/imagePicker.d.ts +7 -0
  416. package/lib/lens-client-interface/imagePicker.js +128 -0
  417. package/lib/lens-client-interface/imagePicker.js.map +1 -0
  418. package/lib/lens-client-interface/lensClientInterface.d.ts +13 -0
  419. package/lib/lens-client-interface/lensClientInterface.js +30 -0
  420. package/lib/lens-client-interface/lensClientInterface.js.map +1 -0
  421. package/lib/lens-core-module/generated-types.d.ts +426 -0
  422. package/lib/lens-core-module/generated-types.js +2 -0
  423. package/lib/lens-core-module/generated-types.js.map +1 -0
  424. package/lib/lens-core-module/index.d.ts +2 -0
  425. package/lib/lens-core-module/index.js +3 -0
  426. package/lib/lens-core-module/index.js.map +1 -0
  427. package/lib/lens-core-module/loader/index.d.ts +1 -0
  428. package/lib/lens-core-module/loader/index.js +2 -0
  429. package/lib/lens-core-module/loader/index.js.map +1 -0
  430. package/lib/lens-core-module/loader/lensCoreFactory.d.ts +30 -0
  431. package/lib/lens-core-module/loader/lensCoreFactory.js +121 -0
  432. package/lib/lens-core-module/loader/lensCoreFactory.js.map +1 -0
  433. package/lib/lensCoreWasmVersions.json +5 -0
  434. package/lib/logger/errorLoggingDecorator.d.ts +9 -0
  435. package/lib/logger/errorLoggingDecorator.js +32 -0
  436. package/lib/logger/errorLoggingDecorator.js.map +1 -0
  437. package/lib/logger/logEntries.d.ts +15 -0
  438. package/lib/logger/logEntries.js +14 -0
  439. package/lib/logger/logEntries.js.map +1 -0
  440. package/lib/logger/logger.d.ts +35 -0
  441. package/lib/logger/logger.js +48 -0
  442. package/lib/logger/logger.js.map +1 -0
  443. package/lib/logger/registerLogEntriesSubscriber.d.ts +14 -0
  444. package/lib/logger/registerLogEntriesSubscriber.js +23 -0
  445. package/lib/logger/registerLogEntriesSubscriber.js.map +1 -0
  446. package/lib/media-sources/CameraKitSource.d.ts +88 -0
  447. package/lib/media-sources/CameraKitSource.js +140 -0
  448. package/lib/media-sources/CameraKitSource.js.map +1 -0
  449. package/lib/media-sources/FunctionSource.d.ts +30 -0
  450. package/lib/media-sources/FunctionSource.js +132 -0
  451. package/lib/media-sources/FunctionSource.js.map +1 -0
  452. package/lib/media-sources/ImageSource.d.ts +13 -0
  453. package/lib/media-sources/ImageSource.js +28 -0
  454. package/lib/media-sources/ImageSource.js.map +1 -0
  455. package/lib/media-sources/MediaStreamSource.d.ts +41 -0
  456. package/lib/media-sources/MediaStreamSource.js +146 -0
  457. package/lib/media-sources/MediaStreamSource.js.map +1 -0
  458. package/lib/media-sources/VideoSource.d.ts +21 -0
  459. package/lib/media-sources/VideoSource.js +38 -0
  460. package/lib/media-sources/VideoSource.js.map +1 -0
  461. package/lib/metrics/businessEventsReporter.d.ts +37 -0
  462. package/lib/metrics/businessEventsReporter.js +160 -0
  463. package/lib/metrics/businessEventsReporter.js.map +1 -0
  464. package/lib/metrics/metricsEventTarget.d.ts +41 -0
  465. package/lib/metrics/metricsEventTarget.js +11 -0
  466. package/lib/metrics/metricsEventTarget.js.map +1 -0
  467. package/lib/metrics/metricsHandler.d.ts +9 -0
  468. package/lib/metrics/metricsHandler.js +13 -0
  469. package/lib/metrics/metricsHandler.js.map +1 -0
  470. package/lib/metrics/operationalMetricsReporter.d.ts +52 -0
  471. package/lib/metrics/operationalMetricsReporter.js +108 -0
  472. package/lib/metrics/operationalMetricsReporter.js.map +1 -0
  473. package/lib/metrics/reporters/reportBenchmarks.d.ts +10 -0
  474. package/lib/metrics/reporters/reportBenchmarks.js +29 -0
  475. package/lib/metrics/reporters/reportBenchmarks.js.map +1 -0
  476. package/lib/metrics/reporters/reportGlobalException.d.ts +19 -0
  477. package/lib/metrics/reporters/reportGlobalException.js +68 -0
  478. package/lib/metrics/reporters/reportGlobalException.js.map +1 -0
  479. package/lib/metrics/reporters/reportHttpMetrics.d.ts +17 -0
  480. package/lib/metrics/reporters/reportHttpMetrics.js +92 -0
  481. package/lib/metrics/reporters/reportHttpMetrics.js.map +1 -0
  482. package/lib/metrics/reporters/reportLegalState.d.ts +15 -0
  483. package/lib/metrics/reporters/reportLegalState.js +34 -0
  484. package/lib/metrics/reporters/reportLegalState.js.map +1 -0
  485. package/lib/metrics/reporters/reportLensAndAssetDownload.d.ts +38 -0
  486. package/lib/metrics/reporters/reportLensAndAssetDownload.js +88 -0
  487. package/lib/metrics/reporters/reportLensAndAssetDownload.js.map +1 -0
  488. package/lib/metrics/reporters/reportLensValidationFailed.d.ts +20 -0
  489. package/lib/metrics/reporters/reportLensValidationFailed.js +24 -0
  490. package/lib/metrics/reporters/reportLensValidationFailed.js.map +1 -0
  491. package/lib/metrics/reporters/reportLensView.d.ts +36 -0
  492. package/lib/metrics/reporters/reportLensView.js +101 -0
  493. package/lib/metrics/reporters/reportLensView.js.map +1 -0
  494. package/lib/metrics/reporters/reportLensWait.d.ts +33 -0
  495. package/lib/metrics/reporters/reportLensWait.js +56 -0
  496. package/lib/metrics/reporters/reportLensWait.js.map +1 -0
  497. package/lib/metrics/reporters/reportSessionException.d.ts +17 -0
  498. package/lib/metrics/reporters/reportSessionException.js +12 -0
  499. package/lib/metrics/reporters/reportSessionException.js.map +1 -0
  500. package/lib/metrics/reporters/reportUserSession.d.ts +14 -0
  501. package/lib/metrics/reporters/reportUserSession.js +67 -0
  502. package/lib/metrics/reporters/reportUserSession.js.map +1 -0
  503. package/lib/metrics/reporters/reporters.d.ts +44 -0
  504. package/lib/metrics/reporters/reporters.js +33 -0
  505. package/lib/metrics/reporters/reporters.js.map +1 -0
  506. package/lib/namedErrors.d.ts +107 -0
  507. package/lib/namedErrors.js +56 -0
  508. package/lib/namedErrors.js.map +1 -0
  509. package/lib/persistence/ExpiringPersistence.d.ts +20 -0
  510. package/lib/persistence/ExpiringPersistence.js +58 -0
  511. package/lib/persistence/ExpiringPersistence.js.map +1 -0
  512. package/lib/persistence/IndexedDBPersistence.d.ts +47 -0
  513. package/lib/persistence/IndexedDBPersistence.js +180 -0
  514. package/lib/persistence/IndexedDBPersistence.js.map +1 -0
  515. package/lib/persistence/Persistence.d.ts +25 -0
  516. package/lib/persistence/Persistence.js +10 -0
  517. package/lib/persistence/Persistence.js.map +1 -0
  518. package/lib/remote-configuration/cofHandler.d.ts +21 -0
  519. package/lib/remote-configuration/cofHandler.js +75 -0
  520. package/lib/remote-configuration/cofHandler.js.map +1 -0
  521. package/lib/remote-configuration/remoteConfiguration.d.ts +13 -0
  522. package/lib/remote-configuration/remoteConfiguration.js +43 -0
  523. package/lib/remote-configuration/remoteConfiguration.js.map +1 -0
  524. package/lib/session/CameraKitSession.d.ts +252 -0
  525. package/lib/session/CameraKitSession.js +439 -0
  526. package/lib/session/CameraKitSession.js.map +1 -0
  527. package/lib/session/CameraKitSessionEvents.d.ts +33 -0
  528. package/lib/session/CameraKitSessionEvents.js +21 -0
  529. package/lib/session/CameraKitSessionEvents.js.map +1 -0
  530. package/lib/session/LensKeyboard.d.ts +89 -0
  531. package/lib/session/LensKeyboard.js +95 -0
  532. package/lib/session/LensKeyboard.js.map +1 -0
  533. package/lib/session/LensPerformanceMeasurement.d.ts +55 -0
  534. package/lib/session/LensPerformanceMeasurement.js +91 -0
  535. package/lib/session/LensPerformanceMeasurement.js.map +1 -0
  536. package/lib/session/LensPerformanceMetrics.d.ts +31 -0
  537. package/lib/session/LensPerformanceMetrics.js +58 -0
  538. package/lib/session/LensPerformanceMetrics.js.map +1 -0
  539. package/lib/session/index.d.ts +1 -0
  540. package/lib/session/index.js +2 -0
  541. package/lib/session/index.js.map +1 -0
  542. package/lib/session/lensState.d.ts +29 -0
  543. package/lib/session/lensState.js +160 -0
  544. package/lib/session/lensState.js.map +1 -0
  545. package/lib/session/sessionState.d.ts +10 -0
  546. package/lib/session/sessionState.js +12 -0
  547. package/lib/session/sessionState.js.map +1 -0
  548. package/lib/transforms/Transform2D.d.ts +17 -0
  549. package/lib/transforms/Transform2D.js +18 -0
  550. package/lib/transforms/Transform2D.js.map +1 -0
  551. package/lib/transforms/index.d.ts +1 -0
  552. package/lib/transforms/index.js +2 -0
  553. package/lib/transforms/index.js.map +1 -0
  554. package/package.json +62 -0
@@ -0,0 +1,149 @@
1
+ import { defineAction, defineActions, defineState, defineStates, dispatch, forActions, inStates, StateMachine, } from "@snap/state-management";
2
+ import { catchError, from, map, merge, of, switchMap } from "rxjs";
3
+ import { Injectable } from "../dependency-injection/Injectable";
4
+ import { LegalDocument, LegalDocument_Type, LegalPrompt as LegalPromptProto, } from "../generated-proto/pb_schema/camera_kit/v3/legal_prompt";
5
+ import { getLogger } from "../logger/logger";
6
+ import { ExpiringPersistence } from "../persistence/ExpiringPersistence";
7
+ import { IndexedDBPersistence } from "../persistence/IndexedDBPersistence";
8
+ import { remoteConfigurationFactory } from "../remote-configuration/remoteConfiguration";
9
+ import { legalPromptFactory } from "./legalPrompt";
10
+ const logger = getLogger("LegalState");
11
+ /**
12
+ * We store a hash of the last accepted ToS content. This is how we determine if the user previously accepted the
13
+ * relevant ToS.
14
+ *
15
+ * ToS acceptance is only valid for 12 hours. That is, if legal status is checked and the last acceptance occurred more
16
+ * than 12 hours ago, the user must be prompted to accept again.
17
+ */
18
+ const tosContentHashExpiry = 12 * 60 * 60;
19
+ const tosContentHashKey = "lastAcceptedTosContentHash";
20
+ /**
21
+ * Fast, simple hashing function from github.com/bryc
22
+ * https://github.com/bryc/code/blob/master/jshash/experimental/cyrb53.js
23
+ */
24
+ const computeHash = (str) => {
25
+ let h1 = 0xdeadbeef;
26
+ let h2 = 0x41c6ce57;
27
+ for (let i = 0; i < str.length; i++) {
28
+ const ch = str.charCodeAt(i);
29
+ h1 = Math.imul(h1 ^ ch, 2654435761);
30
+ h2 = Math.imul(h2 ^ ch, 1597334677);
31
+ }
32
+ h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
33
+ h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
34
+ return (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString(16);
35
+ };
36
+ const createLegalState = () => {
37
+ const states = defineStates(defineState("unknown")(), defineState("accepted")(), defineState("rejected")());
38
+ const actions = defineActions(defineAction("requestLegalPrompt")(), defineAction("accept")(), defineAction("reject")());
39
+ return new StateMachine(actions, states, states.unknown(), (actions) => {
40
+ return merge(actions.pipe(inStates("unknown"), forActions("accept"), map(() => states.accepted())), actions.pipe(inStates("unknown"), forActions("reject"), map(() => states.rejected())), actions.pipe(forActions("requestLegalPrompt"), map(() => states.unknown())));
41
+ });
42
+ };
43
+ const defaultLegalDocumentDate = new Date("2021-09-30T00:00:00+00:00");
44
+ const defaultLegalPrompt = LegalPromptProto.fromPartial({
45
+ documents: [
46
+ LegalDocument.fromPartial({
47
+ type: LegalDocument_Type.PRIVACY_POLICY,
48
+ webUrl: "https://values.snap.com/privacy/privacy-policy",
49
+ version: "1",
50
+ timestamp: defaultLegalDocumentDate,
51
+ }),
52
+ LegalDocument.fromPartial({
53
+ type: LegalDocument_Type.TERMS_OF_SERVICE,
54
+ webUrl: "https://snap.com/terms",
55
+ version: "1",
56
+ timestamp: defaultLegalDocumentDate,
57
+ }),
58
+ LegalDocument.fromPartial({
59
+ type: LegalDocument_Type.LEARN_MORE,
60
+ webUrl: "https://support.snapchat.com/article/camera-information-use",
61
+ version: "1",
62
+ timestamp: defaultLegalDocumentDate,
63
+ }),
64
+ ],
65
+ disabled: false,
66
+ });
67
+ const hasAnyValue = (c) => {
68
+ var _a, _b;
69
+ return ((_b = (_a = c.value) === null || _a === void 0 ? void 0 : _a.anyValue) === null || _b === void 0 ? void 0 : _b.value) instanceof Uint8Array;
70
+ };
71
+ const getDocumentOrDefault = (documents) => (type) => {
72
+ var _a;
73
+ return ((_a = documents.find((d) => d.type === type)) !== null && _a !== void 0 ? _a : defaultLegalPrompt.documents.find((d) => d.type === type));
74
+ };
75
+ /**
76
+ * We maintain the state of the user's acceptance of Snap's various legal documents. Other components may require that
77
+ * the legal state be "accepted" before proceeding (e.g. to apply a lens).
78
+ *
79
+ * On page load, the legal state starts as "unknown." If a request is made to determine the legal state, the following
80
+ * business logic is implemented:
81
+ *
82
+ * 1. Download remote COF config value containing the legal documents + a `disabled` field to optionally skip the legal
83
+ * requirement.
84
+ * 2. Check for a `lastAcceptedTosContentHash` stored in IndexedDB.
85
+ * 3. Prompt the user to accept/reject the legal documents.
86
+ *
87
+ * ┌────────────────────────────────────────────────────────┐
88
+ * │ COF config value includes "disabled: true" │
89
+ * └────────────────────────────────────────────────────────┘
90
+ * │
91
+ * │
92
+ * ┌────────No────────────┴────────────Yes──────────────────┐
93
+ * │ │
94
+ * ▼ │
95
+ * ┌────────────────────────────────────┐ ▼
96
+ * │"lastAcceptedTosContentHash" exists │ ┌────────────┐
97
+ * └────────────────────────────────────┘ │ Skip ToS │
98
+ * │ └────────────┘
99
+ * │ ▲
100
+ * ┌─────────────No───┴───────Yes────────────┐ │
101
+ * │ │ │
102
+ * │ │ │
103
+ * ▼ ▼ │
104
+ * ┌────────────┐ ┌────────────────────────────────────────┐ │
105
+ * │ Show ToS │ │ Hash of ToS content from COF matches │ │
106
+ * └────────────┘ │ "lastAcceptedTosContentHash" │ │
107
+ * ▲ └────────────────────────────────────────┘ │
108
+ * │ │ │
109
+ * │ │ │
110
+ * └──────────────────No─────────────────────┴───────────────────Yes───────────┘
111
+ *
112
+ * @internal
113
+ */
114
+ export const legalStateFactory = Injectable("legalState", [remoteConfigurationFactory.token, legalPromptFactory.token], (remoteConfig, legalPrompt) => {
115
+ const persistance = new ExpiringPersistence(() => tosContentHashExpiry, new IndexedDBPersistence({ databaseName: "Legal" }));
116
+ const getLastAcceptedTosContentHash = () => from(persistance.retrieve(tosContentHashKey).catch((error) => logger.warn(error)));
117
+ const setLastAcceptedTosContentHash = (hash) => persistance.store(tosContentHashKey, hash).catch((error) => logger.warn(error));
118
+ const legalState = createLegalState();
119
+ legalState.events
120
+ .pipe(inStates("unknown", "rejected"), forActions("requestLegalPrompt"), switchMap(() => remoteConfig.get("CAMERA_KIT_LEGAL_PROMPT").pipe(map((configResults) => {
121
+ const config = configResults.find(hasAnyValue);
122
+ if (!config)
123
+ return defaultLegalPrompt;
124
+ return LegalPromptProto.decode(config.value.anyValue.value);
125
+ }), catchError((error) => {
126
+ logger.error(error);
127
+ return of(defaultLegalPrompt);
128
+ }))), switchMap((config) => {
129
+ if (config.disabled)
130
+ return of(legalState.actions.accept("disabled"));
131
+ const currentTosContentHash = computeHash(JSON.stringify(config.documents));
132
+ return getLastAcceptedTosContentHash().pipe(switchMap((lastAcceptedTosContentHash) => {
133
+ if (currentTosContentHash === lastAcceptedTosContentHash)
134
+ return of(true);
135
+ // Delegate prompting the end-user to accept/reject the legal documents. This returns with
136
+ // an Observable<boolean> indicating accept/reject.
137
+ const documentOfType = getDocumentOrDefault(config.documents);
138
+ return legalPrompt(documentOfType(LegalDocument_Type.PRIVACY_POLICY), documentOfType(LegalDocument_Type.TERMS_OF_SERVICE), documentOfType(LegalDocument_Type.LEARN_MORE));
139
+ }), map((didAccept) => {
140
+ if (!didAccept)
141
+ return legalState.actions.reject(currentTosContentHash);
142
+ setLastAcceptedTosContentHash(currentTosContentHash);
143
+ return legalState.actions.accept(currentTosContentHash);
144
+ }));
145
+ }), dispatch(legalState))
146
+ .subscribe();
147
+ return legalState;
148
+ });
149
+ //# sourceMappingURL=legalState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legalState.js","sourceRoot":"","sources":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C,EACF,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE;YACd,IAAI,CAAC,SAAS;gBAAE,OAAO,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC;YACxE,6BAA6B,CAAC,qBAAqB,CAAC,CAAC;YACrD,OAAO,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC;QAC5D,CAAC,CAAC,CACL,CAAC;IACN,CAAC,CAAC,EACF,QAAQ,CAAC,UAAU,CAAC,CACvB;SACA,SAAS,EAAE,CAAC;IAEjB,OAAO,UAAU,CAAC;AACtB,CAAC,CACJ,CAAC","sourcesContent":["import {\n defineAction,\n defineActions,\n defineState,\n defineStates,\n dispatch,\n forActions,\n inStates,\n StateMachine,\n} from \"@snap/state-management\";\nimport { catchError, from, map, merge, of, switchMap } from \"rxjs\";\nimport { Injectable } from \"../dependency-injection/Injectable\";\nimport {\n LegalDocument,\n LegalDocument_Type,\n LegalPrompt as LegalPromptProto,\n} from \"../generated-proto/pb_schema/camera_kit/v3/legal_prompt\";\nimport { ConfigResult } from \"../generated-proto/pb_schema/cdp/cof/config_result\";\nimport { getLogger } from \"../logger/logger\";\nimport { ExpiringPersistence } from \"../persistence/ExpiringPersistence\";\nimport { IndexedDBPersistence } from \"../persistence/IndexedDBPersistence\";\nimport { RemoteConfiguration, remoteConfigurationFactory } from \"../remote-configuration/remoteConfiguration\";\nimport { LegalPrompt, legalPromptFactory } from \"./legalPrompt\";\n\nconst logger = getLogger(\"LegalState\");\n\ntype SupportedDocumentType =\n | LegalDocument_Type.PRIVACY_POLICY\n | LegalDocument_Type.TERMS_OF_SERVICE\n | LegalDocument_Type.LEARN_MORE;\n\n/**\n * We store a hash of the last accepted ToS content. This is how we determine if the user previously accepted the\n * relevant ToS.\n *\n * ToS acceptance is only valid for 12 hours. That is, if legal status is checked and the last acceptance occurred more\n * than 12 hours ago, the user must be prompted to accept again.\n */\nconst tosContentHashExpiry = 12 * 60 * 60;\nconst tosContentHashKey = \"lastAcceptedTosContentHash\";\n\n/**\n * Fast, simple hashing function from github.com/bryc\n * https://github.com/bryc/code/blob/master/jshash/experimental/cyrb53.js\n */\nconst computeHash = (str: string): string => {\n let h1 = 0xdeadbeef;\n let h2 = 0x41c6ce57;\n for (let i = 0; i < str.length; i++) {\n const ch = str.charCodeAt(i);\n h1 = Math.imul(h1 ^ ch, 2654435761);\n h2 = Math.imul(h2 ^ ch, 1597334677);\n }\n h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);\n h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);\n return (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString(16);\n};\n\nconst createLegalState = () => {\n const states = defineStates(defineState(\"unknown\")(), defineState(\"accepted\")(), defineState(\"rejected\")());\n\n const actions = defineActions(\n defineAction(\"requestLegalPrompt\")(),\n defineAction(\"accept\")<string>(),\n defineAction(\"reject\")<string>()\n );\n\n return new StateMachine(actions, states, states.unknown(), (actions) => {\n return merge(\n actions.pipe(\n inStates(\"unknown\"),\n forActions(\"accept\"),\n map(() => states.accepted())\n ),\n actions.pipe(\n inStates(\"unknown\"),\n forActions(\"reject\"),\n map(() => states.rejected())\n ),\n actions.pipe(\n forActions(\"requestLegalPrompt\"),\n map(() => states.unknown())\n )\n );\n });\n};\n\nconst defaultLegalDocumentDate = new Date(\"2021-09-30T00:00:00+00:00\");\nconst defaultLegalPrompt = LegalPromptProto.fromPartial({\n documents: [\n LegalDocument.fromPartial({\n type: LegalDocument_Type.PRIVACY_POLICY,\n webUrl: \"https://values.snap.com/privacy/privacy-policy\",\n version: \"1\",\n timestamp: defaultLegalDocumentDate,\n }),\n LegalDocument.fromPartial({\n type: LegalDocument_Type.TERMS_OF_SERVICE,\n webUrl: \"https://snap.com/terms\",\n version: \"1\",\n timestamp: defaultLegalDocumentDate,\n }),\n LegalDocument.fromPartial({\n type: LegalDocument_Type.LEARN_MORE,\n webUrl: \"https://support.snapchat.com/article/camera-information-use\",\n version: \"1\",\n timestamp: defaultLegalDocumentDate,\n }),\n ],\n disabled: false,\n});\n\nconst hasAnyValue = (c: ConfigResult): c is ConfigResult & { value: { anyValue: { value: Uint8Array } } } => {\n return c.value?.anyValue?.value instanceof Uint8Array;\n};\n\nconst getDocumentOrDefault = (documents: LegalDocument[]) => <T extends SupportedDocumentType>(\n type: T\n): LegalDocument & { type: T } => {\n return (documents.find((d) => d.type === type) ??\n defaultLegalPrompt.documents.find((d) => d.type === type)!) as LegalDocument & { type: T };\n};\n\nexport type LegalState = ReturnType<typeof createLegalState>;\n\n/**\n * We maintain the state of the user's acceptance of Snap's various legal documents. Other components may require that\n * the legal state be \"accepted\" before proceeding (e.g. to apply a lens).\n *\n * On page load, the legal state starts as \"unknown.\" If a request is made to determine the legal state, the following\n * business logic is implemented:\n *\n * 1. Download remote COF config value containing the legal documents + a `disabled` field to optionally skip the legal\n * requirement.\n * 2. Check for a `lastAcceptedTosContentHash` stored in IndexedDB.\n * 3. Prompt the user to accept/reject the legal documents.\n *\n * ┌────────────────────────────────────────────────────────┐\n * │ COF config value includes \"disabled: true\" │\n * └────────────────────────────────────────────────────────┘\n * │\n * │\n * ┌────────No────────────┴────────────Yes──────────────────┐\n * │ │\n * ▼ │\n * ┌────────────────────────────────────┐ ▼\n * │\"lastAcceptedTosContentHash\" exists │ ┌────────────┐\n * └────────────────────────────────────┘ │ Skip ToS │\n * │ └────────────┘\n * │ ▲\n * ┌─────────────No───┴───────Yes────────────┐ │\n * │ │ │\n * │ │ │\n * ▼ ▼ │\n * ┌────────────┐ ┌────────────────────────────────────────┐ │\n * │ Show ToS │ │ Hash of ToS content from COF matches │ │\n * └────────────┘ │ \"lastAcceptedTosContentHash\" │ │\n * ▲ └────────────────────────────────────────┘ │\n * │ │ │\n * │ │ │\n * └──────────────────No─────────────────────┴───────────────────Yes───────────┘\n *\n * @internal\n */\nexport const legalStateFactory = Injectable(\n \"legalState\",\n [remoteConfigurationFactory.token, legalPromptFactory.token] as const,\n (remoteConfig: RemoteConfiguration, legalPrompt: LegalPrompt): LegalState => {\n const persistance = new ExpiringPersistence<string>(\n () => tosContentHashExpiry,\n new IndexedDBPersistence({ databaseName: \"Legal\" })\n );\n const getLastAcceptedTosContentHash = () =>\n from(persistance.retrieve(tosContentHashKey).catch((error) => logger.warn(error)));\n\n const setLastAcceptedTosContentHash = (hash: string) =>\n persistance.store(tosContentHashKey, hash).catch((error) => logger.warn(error));\n\n const legalState = createLegalState();\n\n legalState.events\n .pipe(\n inStates(\"unknown\", \"rejected\"),\n forActions(\"requestLegalPrompt\"),\n switchMap(() =>\n remoteConfig.get(\"CAMERA_KIT_LEGAL_PROMPT\").pipe(\n map((configResults) => {\n const config = configResults.find(hasAnyValue);\n if (!config) return defaultLegalPrompt;\n return LegalPromptProto.decode(config.value.anyValue.value);\n }),\n catchError((error) => {\n logger.error(error);\n return of(defaultLegalPrompt);\n })\n )\n ),\n switchMap((config) => {\n if (config.disabled) return of(legalState.actions.accept(\"disabled\"));\n\n const currentTosContentHash = computeHash(JSON.stringify(config.documents));\n\n return getLastAcceptedTosContentHash().pipe(\n switchMap((lastAcceptedTosContentHash) => {\n if (currentTosContentHash === lastAcceptedTosContentHash) return of(true);\n\n // Delegate prompting the end-user to accept/reject the legal documents. This returns with\n // an Observable<boolean> indicating accept/reject.\n const documentOfType = getDocumentOrDefault(config.documents);\n return legalPrompt(\n documentOfType(LegalDocument_Type.PRIVACY_POLICY),\n documentOfType(LegalDocument_Type.TERMS_OF_SERVICE),\n documentOfType(LegalDocument_Type.LEARN_MORE)\n );\n }),\n map((didAccept) => {\n if (!didAccept) return legalState.actions.reject(currentTosContentHash);\n setLastAcceptedTosContentHash(currentTosContentHash);\n return legalState.actions.accept(currentTosContentHash);\n })\n );\n }),\n dispatch(legalState)\n )\n .subscribe();\n\n return legalState;\n }\n);\n"]}
@@ -0,0 +1,71 @@
1
+ import { Content, Lens_CameraFacing, Preview, Lens as LensGeneratedProto, LensCreator } from "../generated-proto/pb_schema/camera_kit/v3/lens";
2
+ import { GetGroupResponse } from "../generated-proto/pb_schema/camera_kit/v3/service";
3
+ /**
4
+ * @internal
5
+ */
6
+ export declare type ContentProto = Omit<Content, "lnsUrl" | "iconUrl">;
7
+ /**
8
+ * @internal
9
+ */
10
+ export interface LensProto extends Omit<LensGeneratedProto, "content"> {
11
+ content: ContentProto | undefined;
12
+ }
13
+ /**
14
+ * @category Lenses
15
+ */
16
+ export interface Lens {
17
+ /**
18
+ * Non-empty identifier of a unique lens available to be applied in current session.
19
+ *
20
+ * NOTE: This value may contain unsafe characters
21
+ * and therefore may require additional processing depending on usages.
22
+ */
23
+ id: string;
24
+ /**
25
+ * Human readable name of this lens.
26
+ *
27
+ * NOTE: This value may contain unsafe characters
28
+ * and therefore may require additional processing depending on usages.
29
+ */
30
+ name: string;
31
+ /**
32
+ * Icon resource URI that represents this lens if available.
33
+ */
34
+ iconUrl: string | undefined;
35
+ /**
36
+ * Vendor specific metadata associated with this lens, empty by default.
37
+ *
38
+ * NOTE: Metadata values may contain unsafe characters
39
+ * and therefore may require additional processing depending on usages.
40
+ */
41
+ vendorData: {
42
+ [key: string]: string;
43
+ };
44
+ /**
45
+ * Specifies a [Lens_CameraFacing] that this lens is designed for.
46
+ */
47
+ cameraFacingPreference: Lens_CameraFacing;
48
+ /**
49
+ * Preview that represents this lens if available.
50
+ */
51
+ preview: Preview | undefined;
52
+ /**
53
+ * Information about the lens creator.
54
+ */
55
+ lensCreator: LensCreator | undefined;
56
+ }
57
+ export declare function isLensArray(value: unknown): value is Lens[];
58
+ export declare function isLens(value: unknown): value is Lens;
59
+ export declare function isLensProto(value: unknown): value is LensProto;
60
+ export declare function isPreview(value: unknown): value is Preview;
61
+ export declare function isLensCreator(value: unknown): value is LensCreator;
62
+ export declare function isLensContent(value: unknown): value is ContentProto;
63
+ export declare function isGetGroupResponse(value: unknown): value is GetGroupResponse;
64
+ /**
65
+ * Converts lens proto to a public lens object.
66
+ * @param lens Lens proto
67
+ * @returns Public lens object.
68
+ *
69
+ * @internal
70
+ */
71
+ export declare function toPublicLens({ id, name, content, vendorData, cameraFacingPreference, lensCreator }: LensProto): Lens;
@@ -0,0 +1,63 @@
1
+ import { assert } from "../common/assertions";
2
+ import { predicateRecordValues, isRecord, isString, isUndefined, isEmptyOrSafeUrl, isArrayOfType, } from "../common/typeguards";
3
+ export function isLensArray(value) {
4
+ return isArrayOfType(isLens, value);
5
+ }
6
+ export function isLens(value) {
7
+ return (isRecord(value) &&
8
+ isString(value.id) &&
9
+ isString(value.name) &&
10
+ (isUndefined(value.iconUrl) || isString(value.iconUrl)) &&
11
+ isRecord(value.vendorData) &&
12
+ predicateRecordValues(isString)(value.vendorData) &&
13
+ isString(value.cameraFacingPreference) &&
14
+ (isUndefined(value.preview) || isPreview(value.preview)) &&
15
+ (isUndefined(value.lensCreator) || isLensCreator(value.lensCreator)));
16
+ }
17
+ export function isLensProto(value) {
18
+ return (isRecord(value) &&
19
+ isString(value.id) &&
20
+ isString(value.name) &&
21
+ isRecord(value.vendorData) &&
22
+ predicateRecordValues(isString)(value.vendorData) &&
23
+ (typeof value.content === "undefined" || isLensContent(value.content)));
24
+ }
25
+ export function isPreview(value) {
26
+ return isRecord(value) && isString(value.imageUrl);
27
+ }
28
+ export function isLensCreator(value) {
29
+ return isRecord(value) && isString(value.displayName);
30
+ }
31
+ export function isLensContent(value) {
32
+ return (isRecord(value) &&
33
+ isString(value.iconUrlBolt) &&
34
+ isString(value.lnsSha256) &&
35
+ isString(value.lnsUrlBolt) &&
36
+ isRecord(value.preview) &&
37
+ isString(value.preview.imageUrl));
38
+ }
39
+ export function isGetGroupResponse(value) {
40
+ return isRecord(value) && isString(value.id) && Array.isArray(value.lenses) && value.lenses.every(isLensProto);
41
+ }
42
+ /**
43
+ * Converts lens proto to a public lens object.
44
+ * @param lens Lens proto
45
+ * @returns Public lens object.
46
+ *
47
+ * @internal
48
+ */
49
+ export function toPublicLens({ id, name, content, vendorData, cameraFacingPreference, lensCreator }) {
50
+ var _a;
51
+ assert(isEmptyOrSafeUrl(content === null || content === void 0 ? void 0 : content.iconUrlBolt), "Unsafe icon URL");
52
+ assert(isEmptyOrSafeUrl((_a = content === null || content === void 0 ? void 0 : content.preview) === null || _a === void 0 ? void 0 : _a.imageUrl), "Unsafe preview URL");
53
+ return {
54
+ id,
55
+ name,
56
+ iconUrl: content === null || content === void 0 ? void 0 : content.iconUrlBolt,
57
+ preview: content === null || content === void 0 ? void 0 : content.preview,
58
+ vendorData,
59
+ cameraFacingPreference,
60
+ lensCreator,
61
+ };
62
+ }
63
+ //# sourceMappingURL=Lens.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Lens.js","sourceRoot":"","sources":["../../src/lens/Lens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EACH,qBAAqB,EACrB,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,gBAAgB,EAChB,aAAa,GAChB,MAAM,sBAAsB,CAAC;AAuE9B,MAAM,UAAU,WAAW,CAAC,KAAc;IACtC,OAAO,aAAa,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,KAAc;IACjC,OAAO,CACH,QAAQ,CAAC,KAAK,CAAC;QACf,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAClB,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC;QACpB,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACvD,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC;QAC1B,qBAAqB,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC;QACjD,QAAQ,CAAC,KAAK,CAAC,sBAAsB,CAAC;QACtC,CAAC,W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C7C,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;AACnH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,sBAAsB,EAAE,WAAW,EAAa;;IAC1G,MAAM,CAAC,gBAAgB,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,CAAC,EAAE,iBAAiB,CAAC,CAAC;IAClE,MAAM,CAAC,gBAAgB,CAAC,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,0CAAE,QAAQ,CAAC,EAAE,oBAAoB,CAAC,CAAC;IAC3E,OAAO;QACH,EAAE;QACF,IAAI;QACJ,OAAO,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW;QAC7B,OAAO,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO;QACzB,UAAU;QACV,sBAAsB;QACtB,WAAW;KACd,CAAC;AACN,CAAC","sourcesContent":["import { assert } from \"../common/assertions\";\nimport {\n predicateRecordValues,\n isRecord,\n isString,\n isUndefined,\n isEmptyOrSafeUrl,\n isArrayOfType,\n} from \"../common/typeguards\";\nimport {\n Content,\n Lens_CameraFacing,\n Preview,\n Lens as LensGeneratedProto,\n LensCreator,\n} from \"../generated-proto/pb_schema/camera_kit/v3/lens\";\nimport { GetGroupResponse } from \"../generated-proto/pb_schema/camera_kit/v3/service\";\n\n/**\n * @internal\n */\nexport type ContentProto = Omit<Content, \"lnsUrl\" | \"iconUrl\">;\n\n/**\n * @internal\n */\nexport interface LensProto extends Omit<LensGeneratedProto, \"content\"> {\n content: ContentProto | undefined;\n}\n\n/**\n * @category Lenses\n */\nexport interface Lens {\n /**\n * Non-empty identifier of a unique lens available to be applied in current session.\n *\n * NOTE: This value may contain unsafe characters\n * and therefore may require additional processing depending on usages.\n */\n id: string;\n\n /**\n * Human readable name of this lens.\n *\n * NOTE: This value may contain unsafe characters\n * and therefore may require additional processing depending on usages.\n */\n name: string;\n\n /**\n * Icon resource URI that represents this lens if available.\n */\n iconUrl: string | undefined;\n\n /**\n * Vendor specific metadata associated with this lens, empty by default.\n *\n * NOTE: Metadata values may contain unsafe characters\n * and therefore may require additional processing depending on usages.\n */\n vendorData: { [key: string]: string };\n\n /**\n * Specifies a [Lens_CameraFacing] that this lens is designed for.\n */\n cameraFacingPreference: Lens_CameraFacing;\n\n /**\n * Preview that represents this lens if available.\n */\n preview: Preview | undefined;\n\n /**\n * Information about the lens creator.\n */\n lensCreator: LensCreator | undefined;\n}\n\nexport function isLensArray(value: unknown): value is Lens[] {\n return isArrayOfType(isLens, value);\n}\n\nexport function isLens(value: unknown): value is Lens {\n return (\n isRecord(value) &&\n isString(value.id) &&\n isString(value.name) &&\n (isUndefined(value.iconUrl) || isString(value.iconUrl)) &&\n isRecord(value.vendorData) &&\n predicateRecordValues(isString)(value.vendorData) &&\n isString(value.cameraFacingPreference) &&\n (isUndefined(value.preview) || isPreview(value.preview)) &&\n (isUndefined(value.lensCreator) || isLensCreator(value.lensCreator))\n );\n}\n\nexport function isLensProto(value: unknown): value is LensProto {\n return (\n isRecord(value) &&\n isString(value.id) &&\n isString(value.name) &&\n isRecord(value.vendorData) &&\n predicateRecordValues(isString)(value.vendorData) &&\n (typeof value.content === \"undefined\" || isLensContent(value.content))\n );\n}\n\nexport function isPreview(value: unknown): value is Preview {\n return isRecord(value) && isString(value.imageUrl);\n}\n\nexport function isLensCreator(value: unknown): value is LensCreator {\n return isRecord(value) && isString(value.displayName);\n}\n\nexport function isLensContent(value: unknown): value is ContentProto {\n return (\n isRecord(value) &&\n isString(value.iconUrlBolt) &&\n isString(value.lnsSha256) &&\n isString(value.lnsUrlBolt) &&\n isRecord(value.preview) &&\n isString(value.preview.imageUrl)\n );\n}\n\nexport function isGetGroupResponse(value: unknown): value is GetGroupResponse {\n return isRecord(value) && isString(value.id) && Array.isArray(value.lenses) && value.lenses.every(isLensProto);\n}\n\n/**\n * Converts lens proto to a public lens object.\n * @param lens Lens proto\n * @returns Public lens object.\n *\n * @internal\n */\nexport function toPublicLens({ id, name, content, vendorData, cameraFacingPreference, lensCreator }: LensProto): Lens {\n assert(isEmptyOrSafeUrl(content?.iconUrlBolt), \"Unsafe icon URL\");\n assert(isEmptyOrSafeUrl(content?.preview?.imageUrl), \"Unsafe preview URL\");\n return {\n id,\n name,\n iconUrl: content?.iconUrlBolt,\n preview: content?.preview,\n vendorData,\n cameraFacingPreference,\n lensCreator,\n };\n}\n"]}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Various lenses may support the passing of certain parameters from the application to the lens when it is launched.
3
+ *
4
+ * @category Lenses
5
+ */
6
+ export declare type LensLaunchParams = Record<string, string | number | string[] | number[]>;
7
+ export declare type LaunchDetails = {
8
+ launchParams?: LensLaunchParams;
9
+ persistentStore?: ArrayBuffer;
10
+ };
11
+ /**
12
+ * @internal
13
+ */
14
+ export declare function isLaunchParamsValid(launchParams: unknown): launchParams is LensLaunchParams;
15
+ /**
16
+ * @param launchDetails
17
+ * @internal
18
+ */
19
+ export declare const createLaunchData: ({ launchParams, persistentStore }: LaunchDetails) => Uint8Array;
@@ -0,0 +1,38 @@
1
+ import { LaunchData } from "../generated-proto/pb_schema/lenses/launchdata";
2
+ import { isNumber, isRecord, isString } from "../common/typeguards";
3
+ const isNotValid = (value) => !(isString(value) || isValidNumber(value));
4
+ const isValidNumber = (value) => isNumber(value) && !Number.isNaN(value) && Number.isFinite(value);
5
+ /**
6
+ * @internal
7
+ */
8
+ export function isLaunchParamsValid(launchParams) {
9
+ if (!isRecord(launchParams) || launchParams instanceof Date) {
10
+ throw new Error("should be a record <string, number | string | string[] | number[]>");
11
+ }
12
+ for (const value of Object.values(launchParams)) {
13
+ if (Array.isArray(value)) {
14
+ if (!value.every(isString) && !value.every(isValidNumber)) {
15
+ throw new Error("only number, string, string[], number[] values are allowed");
16
+ }
17
+ }
18
+ else if (isNotValid(value)) {
19
+ throw new Error("only number, string, string[], number[] values are allowed");
20
+ }
21
+ }
22
+ return true;
23
+ }
24
+ /**
25
+ * @param launchDetails
26
+ * @internal
27
+ */
28
+ export const createLaunchData = ({ launchParams, persistentStore }) =>
29
+ // finish() protobufjs method returns UInt8Array with shared ArrayBuffer
30
+ // to avoid of detached buffer error when passing data to Lens Core
31
+ // data should be copied using slice() method
32
+ LaunchData.encode(LaunchData.fromPartial(Object.assign(Object.assign({}, (launchParams &&
33
+ isLaunchParamsValid(launchParams) && {
34
+ launchParams: { data: new TextEncoder().encode(JSON.stringify(launchParams)) },
35
+ })), (persistentStore && { persistentStore: { store: new Uint8Array(persistentStore) } }))))
36
+ .finish()
37
+ .slice();
38
+ //# sourceMappingURL=LensLaunchParams.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LensLaunchParams.js","sourceRoot":"","sources":["../../src/lens/LensLaunchParams.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gDAAgD,CAAC;AAC5E,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEpE,MAAM,UAAU,GAAG,CAAC,KAAc,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;AAElF,MAAM,aAAa,GAAG,CAAC,KAAc,EAAmB,EAAE,CACtD,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AActE;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,YAAqB;IACrD,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,YAAY,YAAY,IAAI,EAAE;QACzD,MAAM,IAAI,KAAK,CAAC,oEAAoE,CAAC,CAAC;KACzF;IAED,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE;QAC7C,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YACtB,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE;gBACvD,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAC;aACjF;SACJ;aAAM,IAAI,UAAU,CAAC,KAAK,CAAC,EAAE;YAC1B,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAC;SACjF;KACJ;IAED,OAAO,IAAI,CAAC;AAChB,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,EAAE,YAAY,EAAE,eAAe,EAAiB,EAAE,EAAE;AACjF,wEAAwE;AACxE,mEAAmE;AACnE,6CAA6C;AAC7C,UAAU,CAAC,MAAM,CACb,UAAU,CAAC,WAAW,iCACf,CAAC,YAAY;IACZ,mBAAmB,CAAC,YAAY,CAAC,IAAI;IACjC,YAAY,EAAE,EAAE,IAAI,EAAE,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,EAAE;CACjF,CAAC,GACH,CAAC,eAAe,IAAI,EAAE,eAAe,EAAE,EAAE,KAAK,EAAE,IAAI,UAAU,CAAC,eAAe,CAAC,EAAE,EAAE,CAAC,EACzF,CACL;KACI,MAAM,EAAE;KACR,KAAK,EAAE,CAAC","sourcesContent":["import { LaunchData } from \"../generated-proto/pb_schema/lenses/launchdata\";\nimport { isNumber, isRecord, isString } from \"../common/typeguards\";\n\nconst isNotValid = (value: unknown) => !(isString(value) || isValidNumber(value));\n\nconst isValidNumber = (value: unknown): value is number =>\n isNumber(value) && !Number.isNaN(value) && Number.isFinite(value);\n\n/**\n * Various lenses may support the passing of certain parameters from the application to the lens when it is launched.\n *\n * @category Lenses\n */\nexport type LensLaunchParams = Record<string, string | number | string[] | number[]>;\n\nexport type LaunchDetails = {\n launchParams?: LensLaunchParams;\n persistentStore?: ArrayBuffer;\n};\n\n/**\n * @internal\n */\nexport function isLaunchParamsValid(launchParams: unknown): launchParams is LensLaunchParams {\n if (!isRecord(launchParams) || launchParams instanceof Date) {\n throw new Error(\"should be a record <string, number | string | string[] | number[]>\");\n }\n\n for (const value of Object.values(launchParams)) {\n if (Array.isArray(value)) {\n if (!value.every(isString) && !value.every(isValidNumber)) {\n throw new Error(\"only number, string, string[], number[] values are allowed\");\n }\n } else if (isNotValid(value)) {\n throw new Error(\"only number, string, string[], number[] values are allowed\");\n }\n }\n\n return true;\n}\n\n/**\n * @param launchDetails\n * @internal\n */\nexport const createLaunchData = ({ launchParams, persistentStore }: LaunchDetails) =>\n // finish() protobufjs method returns UInt8Array with shared ArrayBuffer\n // to avoid of detached buffer error when passing data to Lens Core\n // data should be copied using slice() method\n LaunchData.encode(\n LaunchData.fromPartial({\n ...(launchParams &&\n isLaunchParamsValid(launchParams) && {\n launchParams: { data: new TextEncoder().encode(JSON.stringify(launchParams)) },\n }),\n ...(persistentStore && { persistentStore: { store: new Uint8Array(persistentStore) } }),\n })\n )\n .finish()\n .slice();\n"]}
@@ -0,0 +1,7 @@
1
+ import { LensCoreModule } from "../lens-core-module";
2
+ import { IndexedDBPersistence } from "../persistence/IndexedDBPersistence";
3
+ export declare const lensPersistenceStoreFactory: {
4
+ (args_0: LensCoreModule): IndexedDBPersistence<ArrayBuffer>;
5
+ token: "lensPersistenceStore";
6
+ dependencies: readonly ["lensCore"];
7
+ };
@@ -0,0 +1,20 @@
1
+ import { __awaiter } from "tslib";
2
+ import { Injectable } from "../dependency-injection/Injectable";
3
+ import { persistentStoreError } from "../namedErrors";
4
+ import { lensCoreFactory } from "../lens-core-module";
5
+ import { getLogger } from "../logger/logger";
6
+ import { IndexedDBPersistence } from "../persistence/IndexedDBPersistence";
7
+ const logger = getLogger("LensPersistenceStore");
8
+ export const lensPersistenceStoreFactory = Injectable("lensPersistenceStore", [lensCoreFactory.token], (lensCore) => {
9
+ const db = new IndexedDBPersistence({ databaseName: "lensPersistenceStore" });
10
+ lensCore.registerSavePersistentStoreCallback((id, data) => __awaiter(void 0, void 0, void 0, function* () {
11
+ try {
12
+ yield db.store(id, data);
13
+ }
14
+ catch (error) {
15
+ logger.error(persistentStoreError(`Unable to store data for lens "${id}".`, error));
16
+ }
17
+ }));
18
+ return db;
19
+ });
20
+ //# sourceMappingURL=LensPersistenceStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LensPersistenceStore.js","sourceRoot":"","sources":["../../src/lens/LensPersistenceStore.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAkB,MAAM,qBAAqB,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAE3E,MAAM,MAAM,GAAG,SAAS,CAAC,sBAAsB,CAAC,CAAC;AAEjD,MAAM,CAAC,MAAM,2BAA2B,GAAG,UAAU,CACjD,sBAAsB,EACtB,CAAC,eAAe,CAAC,KAAK,CAAU,EAChC,CAAC,QAAwB,EAAqC,EAAE;IAC5D,MAAM,EAAE,GAAG,IAAI,oBAAoB,CAAc,EAAE,YAAY,EAAE,sBAAsB,EAAE,CAAC,CAAC;IAC3F,QAAQ,CAAC,mCAAmC,CAAC,CAAO,EAAE,EAAE,IAAI,EAAE,EAAE;QAC5D,IAAI;YACA,MAAM,EAAE,CAAC,KAAK,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;SAC5B;QAAC,OAAO,KAAK,EAAE;YACZ,MAAM,CAAC,KAAK,CAAC,oBAAoB,CAAC,kCAAkC,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;SACvF;IACL,CAAC,CAAA,CAAC,CAAC;IACH,OAAO,EAAE,CAAC;AACd,CAAC,CACJ,CAAC","sourcesContent":["import { Injectable } from \"../dependency-injection/Injectable\";\nimport { persistentStoreError } from \"../namedErrors\";\nimport { lensCoreFactory, LensCoreModule } from \"../lens-core-module\";\nimport { getLogger } from \"../logger/logger\";\nimport { IndexedDBPersistence } from \"../persistence/IndexedDBPersistence\";\n\nconst logger = getLogger(\"LensPersistenceStore\");\n\nexport const lensPersistenceStoreFactory = Injectable(\n \"lensPersistenceStore\",\n [lensCoreFactory.token] as const,\n (lensCore: LensCoreModule): IndexedDBPersistence<ArrayBuffer> => {\n const db = new IndexedDBPersistence<ArrayBuffer>({ databaseName: \"lensPersistenceStore\" });\n lensCore.registerSavePersistentStoreCallback(async (id, data) => {\n try {\n await db.store(id, data);\n } catch (error) {\n logger.error(persistentStoreError(`Unable to store data for lens \"${id}\".`, error));\n }\n });\n return db;\n }\n);\n"]}
@@ -0,0 +1,134 @@
1
+ import { FetchHandler } from "../handlers/defaultFetchHandler";
2
+ import { LensSources } from "../extensions/LensSources";
3
+ import { LensDownloadDimensions } from "../metrics/reporters/reportLensAndAssetDownload";
4
+ import { Handler } from "../handlers/HandlerChainBuilder";
5
+ import { LensAssetManifestItem_RequestTiming } from "../generated-proto/pb_schema/camera_kit/v3/lens";
6
+ import { Lens, LensProto } from "./Lens";
7
+ import { LensAssetRepository } from "./assets/LensAssetRepository";
8
+ declare type LensFetchHandler = Handler<[
9
+ RequestInfo,
10
+ LensDownloadDimensions
11
+ ], [
12
+ ArrayBuffer,
13
+ Response
14
+ ], RequestInit | undefined>;
15
+ declare const assetTimingMap: {
16
+ required: LensAssetManifestItem_RequestTiming;
17
+ onDemand: LensAssetManifestItem_RequestTiming;
18
+ };
19
+ /**
20
+ * Lens assets are included in a manifest, and each will indicate when that asset will be used by the lens.
21
+ *
22
+ * Assets can have the following timing values:
23
+ * - `required`: the lens will definitely request this asset immediately when the lens is applied.
24
+ * - `onDemand`: the lens may request this asset at some time while the lens is applied.
25
+ *
26
+ * Depending on the use-case, an application may want to cache both required and onDemand assets for
27
+ * a particular lens, or may decide to only cache required assets (or cache no assets).
28
+ *
29
+ * @category Lenses
30
+ */
31
+ export declare type AssetTiming = keyof typeof assetTimingMap;
32
+ export interface LensGroupsQueryResponse {
33
+ errors: Error[];
34
+ lenses: Lens[];
35
+ }
36
+ export interface LensBinary {
37
+ lensBuffer: ArrayBuffer;
38
+ lensChecksum: string;
39
+ }
40
+ /**
41
+ * The LensRepository is used to query for lenses from specific lens groups, or for a lens with a specific ID.
42
+ *
43
+ * Lens groups are configured in the CameraKit Portal -- that's where you'll find lens group IDs and lens IDs.
44
+ *
45
+ * Lenses must be loaded by the LensRepository before they can be applied to a {@link CameraKitSession}.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * const cameraKit = await bootstrapCameraKit(options)
50
+ * const session = await cameraKit.createSession()
51
+ * const lens = await cameraKit.lensRepository.loadLens(lensId, groupId)
52
+ * session.applyLens(lens)
53
+ * ```
54
+ *
55
+ * @category Lenses
56
+ */
57
+ export declare class LensRepository {
58
+ private readonly lensMetadataFetchHandler;
59
+ private readonly lensFetchHandler;
60
+ private readonly lensSources;
61
+ private readonly lensAssetRepository;
62
+ private readonly metadataCache;
63
+ private readonly binariesCache;
64
+ /** @internal */
65
+ constructor(lensMetadataFetchHandler: FetchHandler, lensFetchHandler: LensFetchHandler, lensSources: LensSources, lensAssetRepository: LensAssetRepository);
66
+ /**
67
+ * Retrieve a single Lens.
68
+ *
69
+ * @param lensId Desired Lens's unique ID. Can be found in the CameraKit Portal.
70
+ * @param groupId The ID of a group containing the desired Lens. Can be found in the CameraKit Portal.
71
+ * @returns Resolves with the desired Lens, or rejects if an error occurred (including a missing Lens).
72
+ */
73
+ loadLens(lensId: string, groupId: string): Promise<Lens>;
74
+ /**
75
+ * Retrieve the Lenses contained in a list of Lens Groups.
76
+ *
77
+ * This may result in multiple requests to retrieve Lens data (e.g. one per desired group). If any constituent
78
+ * requests fail, those errors will be reported in the response – but the returned Promise will not be rejected. Any
79
+ * Lenses which could be successfully retrieved will be available in the response.
80
+ *
81
+ * @param groupIds A list of Lens Group IDs. Can be found in the CameraKit Portal.
82
+ * @returns Resolves with a flattened list of all lenses in the desired groups. If any errors occurred during the
83
+ * query operation, these will be included in a separate list. If errors are present, the list of Lenses may not
84
+ * contain all the Lenses from the desired groups.
85
+ */
86
+ loadLensGroups(groupIds: string[]): Promise<LensGroupsQueryResponse>;
87
+ /**
88
+ * Loads and caches lens content and dependencies to reduce latency when {@link CameraKitSession.applyLens} is later
89
+ * called to apply the lens. This is an in-memory cache, it will not be persisted across page loads.
90
+ *
91
+ * This may useful if the application A) knows which lenses will be applied and B) has some opportunity to call
92
+ * this method before a lens is applied. For example, if the user must perform some other actions before lenses
93
+ * become active, this might be a good opportunity to cache lenses to improve applyLens latency.
94
+ *
95
+ * @example
96
+ * ```ts
97
+ * const lens = await cameraKit.lensRepository.loadLens(lensId, groupId)
98
+ * await cameraKit.lensRepository.cacheLensContent([lens])
99
+ *
100
+ * // sometime later -- this call will use the cached lens content, making lens application faster.
101
+ * await cameraKitSession.applyLens(lens)
102
+ * ```
103
+ *
104
+ * @param lenses Array of lenses to cache in memory.
105
+ * @param assetTimingsToCache Lenses specify certain required assets that are necessary for the lens to render, and
106
+ * other assets which may be needed by the lens. By default this method will cache all of those assets, but this
107
+ * behavior can be modified to only load the required assets, only the "onDemand" assets, or neither (by passing
108
+ * an empty array).
109
+ */
110
+ cacheLensContent(lenses: Lens[], assetTimingsToCache?: AssetTiming[]): Promise<void>;
111
+ /**
112
+ * Returns loaded Lens metadata if available.
113
+ */
114
+ getLensMetadata(lensId: string): LensProto | undefined;
115
+ /**
116
+ * Removes Lens content from the in-memory cache.
117
+ */
118
+ removeCachedLenses(lenses: Lens[]): void;
119
+ /**
120
+ * Fetches lens content and assets. This may come from the cache, otherwise network requests will be made.
121
+ *
122
+ * @internal
123
+ */
124
+ getLensContent(lens: Lens): Promise<LensBinary>;
125
+ }
126
+ /**
127
+ * @internal
128
+ */
129
+ export declare const lensRepositoryFactory: {
130
+ (args_0: FetchHandler<Response>, args_1: FetchHandler<Response>, args_2: LensSources, args_3: LensAssetRepository): LensRepository;
131
+ token: "LensRepository";
132
+ dependencies: readonly ["cameraKitServiceFetchHandler", "defaultFetchHandler", "lensSources", "lensAssetRepository"];
133
+ };
134
+ export {};