@snap/camera-kit 0.14.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (265) hide show
  1. package/LICENSE.md +5921 -1485
  2. package/README.md +1 -1
  3. package/docs/html/assets/search.js +1 -1
  4. package/docs/html/classes/CameraKit.html +7 -7
  5. package/docs/html/classes/CameraKitSession.html +17 -25
  6. package/docs/html/classes/CameraKitSource.html +15 -10
  7. package/docs/html/classes/LensPerformanceMeasurement.html +7 -7
  8. package/docs/html/classes/LensPerformanceMetrics.html +7 -7
  9. package/docs/html/classes/LensRepository.html +7 -7
  10. package/docs/html/classes/Transform2D.html +7 -7
  11. package/docs/html/classes/TypedCustomEvent.html +7 -7
  12. package/docs/html/classes/TypedEventTarget.html +7 -7
  13. package/docs/html/functions/ConcatInjectable.html +202 -0
  14. package/docs/html/functions/Injectable.html +15 -16
  15. package/docs/html/functions/bootstrapCameraKit.html +7 -7
  16. package/docs/html/functions/createExtension.html +7 -7
  17. package/docs/html/functions/createImageSource.html +7 -7
  18. package/docs/html/functions/createMediaStreamSource.html +7 -7
  19. package/docs/html/functions/createUserMediaSource.html +7 -7
  20. package/docs/html/functions/createVideoSource.html +7 -7
  21. package/docs/html/functions/estimateLensPerformance.html +7 -7
  22. package/docs/html/functions/getRequiredBootstrapURLs.html +7 -7
  23. package/docs/html/functions/lensSourcesFactory.html +17 -9
  24. package/docs/html/functions/remoteApiServicesFactory.html +7 -7
  25. package/docs/html/index.html +9 -9
  26. package/docs/html/interfaces/CameraKitBootstrapConfiguration.html +7 -7
  27. package/docs/html/interfaces/CameraKitSourceSubscriber.html +7 -7
  28. package/docs/html/interfaces/ComputedFrameMetrics.html +7 -7
  29. package/docs/html/interfaces/CreateSessionOptions.html +7 -7
  30. package/docs/html/interfaces/EstimatedLensPerformance.html +7 -7
  31. package/docs/html/interfaces/Lens.html +7 -7
  32. package/docs/html/interfaces/LensLaunchData.html +183 -0
  33. package/docs/html/interfaces/LensSource.html +28 -46
  34. package/docs/html/interfaces/MediaStreamSourceOptions.html +7 -7
  35. package/docs/html/interfaces/Preview.html +7 -7
  36. package/docs/html/interfaces/RemoteApiRequest.html +7 -7
  37. package/docs/html/interfaces/RemoteApiResponse.html +7 -7
  38. package/docs/html/interfaces/RemoteApiService.html +7 -7
  39. package/docs/html/interfaces/Snapcode.html +7 -7
  40. package/docs/html/interfaces/UriCancelRequest.html +7 -7
  41. package/docs/html/interfaces/UriRequest.html +7 -7
  42. package/docs/html/interfaces/UriResponse.html +7 -7
  43. package/docs/html/interfaces/VideoSourceOptions.html +7 -7
  44. package/docs/html/modules.html +12 -12
  45. package/docs/html/types/AssetLoader.html +7 -7
  46. package/docs/html/types/AssetTiming.html +7 -7
  47. package/docs/html/types/BenchmarkError.html +7 -7
  48. package/docs/html/types/BootstrapError.html +7 -7
  49. package/docs/html/types/CacheKeyNotFoundError.html +7 -7
  50. package/docs/html/types/CameraKitDeviceInfo.html +7 -7
  51. package/docs/html/types/CameraKitDeviceOptions.html +7 -7
  52. package/docs/html/types/CameraKitSessionEventListener.html +7 -7
  53. package/docs/html/types/CameraKitSessionEvents.html +7 -7
  54. package/docs/html/types/CameraKitSourceError.html +7 -7
  55. package/docs/html/types/CameraKitSourceInfo.html +7 -7
  56. package/docs/html/types/CameraKitSourceOptions.html +7 -7
  57. package/docs/html/types/ConfigurationError.html +7 -7
  58. package/docs/html/types/Keyboard.html +7 -7
  59. package/docs/html/types/KeyboardEvents.html +7 -7
  60. package/docs/html/types/LegalError.html +7 -7
  61. package/docs/html/types/LensAbortError.html +7 -7
  62. package/docs/html/types/LensAssetError.html +7 -7
  63. package/docs/html/types/LensContentValidationError.html +7 -7
  64. package/docs/html/types/LensError.html +7 -7
  65. package/docs/html/types/LensExecutionError.html +7 -7
  66. package/docs/html/types/LensImagePickerError.html +7 -7
  67. package/docs/html/types/LensMetricsEvents.html +7 -7
  68. package/docs/html/types/LensPerformanceCluster.html +7 -7
  69. package/docs/html/types/LensView.html +7 -7
  70. package/docs/html/types/LensWait.html +7 -7
  71. package/docs/html/types/PersistentStoreError.html +7 -7
  72. package/docs/html/types/PlatformNotSupportedError.html +7 -7
  73. package/docs/html/types/PublicContainer.html +7 -7
  74. package/docs/html/types/RemoteApiRequestHandler.html +7 -7
  75. package/docs/html/types/RemoteApiServices.html +7 -7
  76. package/docs/html/types/RemoteApiStatus.html +7 -7
  77. package/docs/html/types/RenderTarget.html +7 -7
  78. package/docs/html/types/Uri.html +7 -7
  79. package/docs/html/types/WebGLError.html +7 -7
  80. package/docs/html/variables/extensionRequestContext.html +7 -7
  81. package/docs/md/README.md +1 -1
  82. package/docs/md/classes/CameraKit.md +1 -1
  83. package/docs/md/classes/CameraKitSession.md +11 -22
  84. package/docs/md/classes/CameraKitSource.md +11 -5
  85. package/docs/md/classes/LensPerformanceMeasurement.md +1 -1
  86. package/docs/md/classes/LensPerformanceMetrics.md +1 -1
  87. package/docs/md/classes/LensRepository.md +1 -1
  88. package/docs/md/classes/Transform2D.md +1 -1
  89. package/docs/md/classes/TypedCustomEvent.md +1 -1
  90. package/docs/md/classes/TypedEventTarget.md +1 -1
  91. package/docs/md/interfaces/CameraKitBootstrapConfiguration.md +1 -1
  92. package/docs/md/interfaces/CameraKitSourceSubscriber.md +1 -1
  93. package/docs/md/interfaces/ComputedFrameMetrics.md +1 -1
  94. package/docs/md/interfaces/CreateSessionOptions.md +1 -1
  95. package/docs/md/interfaces/EstimatedLensPerformance.md +1 -1
  96. package/docs/md/interfaces/Lens.md +1 -1
  97. package/docs/md/interfaces/LensLaunchData.md +53 -0
  98. package/docs/md/interfaces/LensSource.md +23 -25
  99. package/docs/md/interfaces/MediaStreamSourceOptions.md +1 -1
  100. package/docs/md/interfaces/Preview.md +1 -1
  101. package/docs/md/interfaces/RemoteApiRequest.md +1 -1
  102. package/docs/md/interfaces/RemoteApiResponse.md +1 -1
  103. package/docs/md/interfaces/RemoteApiService.md +1 -1
  104. package/docs/md/interfaces/Snapcode.md +1 -1
  105. package/docs/md/interfaces/UriCancelRequest.md +1 -1
  106. package/docs/md/interfaces/UriRequest.md +1 -1
  107. package/docs/md/interfaces/UriResponse.md +1 -1
  108. package/docs/md/interfaces/VideoSourceOptions.md +1 -1
  109. package/docs/md/modules.md +125 -28
  110. package/lib/CameraKit.d.ts +14 -6
  111. package/lib/__tests__/data.d.ts +2 -2
  112. package/lib/__tests__/data.js +2 -2
  113. package/lib/__tests__/data.js.map +1 -1
  114. package/lib/bootstrapCameraKit.js +12 -3
  115. package/lib/bootstrapCameraKit.js.map +1 -1
  116. package/lib/clients/createTsProtoClient.d.ts +47 -0
  117. package/lib/clients/createTsProtoClient.js +53 -0
  118. package/lib/clients/createTsProtoClient.js.map +1 -0
  119. package/lib/clients/grpcHandler.d.ts +23 -0
  120. package/lib/clients/grpcHandler.js +87 -0
  121. package/lib/clients/grpcHandler.js.map +1 -0
  122. package/lib/clients/lensesClient.d.ts +9 -0
  123. package/lib/clients/lensesClient.js +6 -0
  124. package/lib/clients/lensesClient.js.map +1 -0
  125. package/lib/common/entries.d.ts +1 -0
  126. package/lib/common/entries.js +2 -0
  127. package/lib/common/entries.js.map +1 -1
  128. package/lib/common/result.d.ts +36 -0
  129. package/lib/common/result.js +40 -0
  130. package/lib/common/result.js.map +1 -0
  131. package/lib/common/unionBy.d.ts +28 -0
  132. package/lib/common/unionBy.js +46 -0
  133. package/lib/common/unionBy.js.map +1 -0
  134. package/lib/configuration.js +14 -1
  135. package/lib/configuration.js.map +1 -1
  136. package/lib/dependency-injection/Injectable.d.ts +67 -11
  137. package/lib/dependency-injection/Injectable.js +21 -2
  138. package/lib/dependency-injection/Injectable.js.map +1 -1
  139. package/lib/dependency-injection/RootServices.d.ts +5 -1
  140. package/lib/dependency-injection/RootServices.js.map +1 -1
  141. package/lib/environment.json +1 -1
  142. package/lib/extensions/RemoteApiServices.d.ts +1 -1
  143. package/lib/extensions/RemoteApiServices.js +7 -7
  144. package/lib/extensions/RemoteApiServices.js.map +1 -1
  145. package/lib/extensions/uriHandlersRegister.d.ts +6 -6
  146. package/lib/extensions/uriHandlersRegister.js +1 -1
  147. package/lib/extensions/uriHandlersRegister.js.map +1 -1
  148. package/lib/generated-proto/blizzard/cameraKitEvents.js.map +1 -1
  149. package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.d.ts +15 -17
  150. package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.js +62 -69
  151. package/lib/generated-proto/pb_schema/camera_kit/v3/business_events.js.map +1 -1
  152. package/lib/generated-proto/pb_schema/camera_kit/v3/export.d.ts +6 -0
  153. package/lib/generated-proto/pb_schema/camera_kit/v3/export.js +68 -0
  154. package/lib/generated-proto/pb_schema/camera_kit/v3/export.js.map +1 -1
  155. package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.d.ts +5 -6
  156. package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.js +11 -25
  157. package/lib/generated-proto/pb_schema/camera_kit/v3/legal_prompt.js.map +1 -1
  158. package/lib/generated-proto/pb_schema/camera_kit/v3/lens.d.ts +19 -14
  159. package/lib/generated-proto/pb_schema/camera_kit/v3/lens.js +145 -64
  160. package/lib/generated-proto/pb_schema/camera_kit/v3/lens.js.map +1 -1
  161. package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.d.ts +2 -0
  162. package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.js +30 -0
  163. package/lib/generated-proto/pb_schema/camera_kit/v3/operational_metrics.js.map +1 -1
  164. package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.d.ts +15 -16
  165. package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.js +36 -62
  166. package/lib/generated-proto/pb_schema/camera_kit/v3/ranking.js.map +1 -1
  167. package/lib/generated-proto/pb_schema/camera_kit/v3/service.d.ts +1294 -12
  168. package/lib/generated-proto/pb_schema/camera_kit/v3/service.js +200 -0
  169. package/lib/generated-proto/pb_schema/camera_kit/v3/service.js.map +1 -1
  170. package/lib/generated-proto/pb_schema/cdp/cof/config_result.d.ts +4 -0
  171. package/lib/generated-proto/pb_schema/cdp/cof/config_result.js +4 -0
  172. package/lib/generated-proto/pb_schema/cdp/cof/config_result.js.map +1 -1
  173. package/lib/generated-proto/pb_schema/google/protobuf/descriptor.d.ts +39 -45
  174. package/lib/generated-proto/pb_schema/google/protobuf/descriptor.js +74 -192
  175. package/lib/generated-proto/pb_schema/google/protobuf/descriptor.js.map +1 -1
  176. package/lib/handlers/defaultFetchHandler.js +1 -5
  177. package/lib/handlers/defaultFetchHandler.js.map +1 -1
  178. package/lib/index.d.ts +3 -3
  179. package/lib/index.js +2 -6
  180. package/lib/index.js.map +1 -1
  181. package/lib/lens/Lens.d.ts +2 -12
  182. package/lib/lens/Lens.js +2 -2
  183. package/lib/lens/Lens.js.map +1 -1
  184. package/lib/lens/LensLaunchData.d.ts +37 -0
  185. package/lib/lens/LensLaunchData.js +35 -0
  186. package/lib/lens/LensLaunchData.js.map +1 -0
  187. package/lib/lens/LensRepository.d.ts +4 -7
  188. package/lib/lens/LensRepository.js +24 -35
  189. package/lib/lens/LensRepository.js.map +1 -1
  190. package/lib/lens/LensSource.d.ts +43 -0
  191. package/lib/lens/LensSource.js +42 -0
  192. package/lib/lens/LensSource.js.map +1 -0
  193. package/lib/lens/assets/LensAssetRepository.js +2 -4
  194. package/lib/lens/assets/LensAssetRepository.js.map +1 -1
  195. package/lib/lens/assets/LensAssetsProvider.d.ts +1 -1
  196. package/lib/lens/cameraKitLensSource.d.ts +16 -0
  197. package/lib/lens/cameraKitLensSource.js +59 -0
  198. package/lib/lens/cameraKitLensSource.js.map +1 -0
  199. package/lib/lens-core-module/lensCore.d.ts +2 -1
  200. package/lib/lens-core-module/lensCore.js +6 -1
  201. package/lib/lens-core-module/lensCore.js.map +1 -1
  202. package/lib/lens-core-module/lensCoreError.js +1 -1
  203. package/lib/lens-core-module/lensCoreError.js.map +1 -1
  204. package/lib/lensCoreWasmVersions.json +3 -3
  205. package/lib/media-sources/CameraKitSource.d.ts +10 -4
  206. package/lib/media-sources/CameraKitSource.js +11 -4
  207. package/lib/media-sources/CameraKitSource.js.map +1 -1
  208. package/lib/media-sources/ImageSource.js +1 -11
  209. package/lib/media-sources/ImageSource.js.map +1 -1
  210. package/lib/media-sources/MediaStreamSource.js +1 -5
  211. package/lib/media-sources/MediaStreamSource.js.map +1 -1
  212. package/lib/media-sources/VideoSource.js +1 -11
  213. package/lib/media-sources/VideoSource.js.map +1 -1
  214. package/lib/metrics/businessEventsReporter.js +1 -1
  215. package/lib/metrics/businessEventsReporter.js.map +1 -1
  216. package/lib/metrics/reporters/reportGlobalException.d.ts +7 -0
  217. package/lib/metrics/reporters/reportGlobalException.js +22 -4
  218. package/lib/metrics/reporters/reportGlobalException.js.map +1 -1
  219. package/lib/metrics/reporters/reportHttpMetrics.js +14 -0
  220. package/lib/metrics/reporters/reportHttpMetrics.js.map +1 -1
  221. package/lib/metrics/reporters/reportLensValidationFailed.d.ts +1 -1
  222. package/lib/metrics/reporters/reportLensView.d.ts +1 -1
  223. package/lib/metrics/reporters/reportLensWait.d.ts +1 -1
  224. package/lib/metrics/reporters/reportSessionException.d.ts +1 -1
  225. package/lib/metrics/reporters/reporters.d.ts +1 -1
  226. package/lib/persistence/ExpiringPersistence.js +3 -4
  227. package/lib/persistence/ExpiringPersistence.js.map +1 -1
  228. package/lib/platform/platformCapabilities.js +2 -1
  229. package/lib/platform/platformCapabilities.js.map +1 -1
  230. package/lib/platform/platformInfo.js +1 -1
  231. package/lib/platform/platformInfo.js.map +1 -1
  232. package/lib/remote-configuration/cofHandler.d.ts +1 -0
  233. package/lib/remote-configuration/cofHandler.js +61 -50
  234. package/lib/remote-configuration/cofHandler.js.map +1 -1
  235. package/lib/session/CameraKitSession.d.ts +9 -11
  236. package/lib/session/CameraKitSession.js +22 -18
  237. package/lib/session/CameraKitSession.js.map +1 -1
  238. package/lib/session/CameraKitSessionEvents.d.ts +1 -1
  239. package/lib/session/CameraKitSessionEvents.js.map +1 -1
  240. package/lib/session/LensKeyboard.d.ts +7 -1
  241. package/lib/session/lensState.d.ts +3 -3
  242. package/lib/session/lensState.js +40 -15
  243. package/lib/session/lensState.js.map +1 -1
  244. package/package.json +1 -1
  245. package/docs/html/classes/LensSources.html +0 -160
  246. package/docs/html/types/LensLaunchParams.html +0 -115
  247. package/docs/md/classes/LensSources.md +0 -29
  248. package/lib/common/any.d.ts +0 -19
  249. package/lib/common/any.js +0 -53
  250. package/lib/common/any.js.map +0 -1
  251. package/lib/extensions/LensSources.d.ts +0 -58
  252. package/lib/extensions/LensSources.js +0 -54
  253. package/lib/extensions/LensSources.js.map +0 -1
  254. package/lib/lens/LensLaunchParams.d.ts +0 -19
  255. package/lib/lens/LensLaunchParams.js +0 -40
  256. package/lib/lens/LensLaunchParams.js.map +0 -1
  257. package/lib/lens/index.d.ts +0 -7
  258. package/lib/lens/index.js +0 -7
  259. package/lib/lens/index.js.map +0 -1
  260. package/lib/lens/lensEnvelopeUtil.d.ts +0 -5
  261. package/lib/lens/lensEnvelopeUtil.js +0 -19
  262. package/lib/lens/lensEnvelopeUtil.js.map +0 -1
  263. package/lib/lens/lensHttpUtil.d.ts +0 -5
  264. package/lib/lens/lensHttpUtil.js +0 -52
  265. package/lib/lens/lensHttpUtil.js.map +0 -1
@@ -1,54 +0,0 @@
1
- import { __awaiter } from "tslib";
2
- import { isUndefined } from "../common/typeguards";
3
- import { Injectable } from "../dependency-injection/Injectable";
4
- /**
5
- * A chain of {@link LensSource} objects to be registered in Camera Kit on bootstrap. Camera Kit evaluates all
6
- * registered {@link LensSource} objects for a group ownership during Lens retrieval ({@link CameraKit.lenses}).
7
- * And if a source claims the ownership, its {@link LensSource.getLens} or {@link LensSource.getLensGroup}
8
- * methods are called.
9
- */
10
- export class LensSources {
11
- /**
12
- * Returns empty LensSources instance.
13
- * @internal
14
- */
15
- static empty() {
16
- // NOTE: we want to keep LensSources constructor to require arguments
17
- // but internally we don't need them for the base case
18
- // @ts-expect-error
19
- return new LensSources();
20
- }
21
- /**
22
- * Creates an instance of Lens sources.
23
- * @param fallbackSources A fallback sources if given {@link LensSource} doesn't claim a group ownership.
24
- * @param source Lens source.
25
- */
26
- constructor(fallbackSources, source) {
27
- this.fallbackSources = fallbackSources;
28
- this.source = source;
29
- }
30
- /**
31
- * Returns envelopes of lens/groups taking into account group ownership.
32
- * @internal
33
- * @param groupId A group to test ownership and get lens envelopes of.
34
- * @param lensId An optional lens ID to narrow envelopes down to a single lens.
35
- * @returns Envelopes or undefined if not applicable.
36
- */
37
- retrieveLenses({ groupId, lensId }) {
38
- var _a, _b;
39
- return __awaiter(this, void 0, void 0, function* () {
40
- if ((_a = this.source) === null || _a === void 0 ? void 0 : _a.isGroupOwner(groupId)) {
41
- if (isUndefined(lensId)) {
42
- if (this.source.getLensGroup)
43
- return this.source.getLensGroup(groupId);
44
- }
45
- else if (this.source.getLens) {
46
- return this.source.getLens(lensId, groupId).then((envelope) => [envelope]);
47
- }
48
- }
49
- return (_b = this.fallbackSources) === null || _b === void 0 ? void 0 : _b.retrieveLenses({ groupId, lensId });
50
- });
51
- }
52
- }
53
- export const lensSourcesFactory = Injectable("lensSources", () => LensSources.empty());
54
- //# sourceMappingURL=LensSources.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LensSources.js","sourceRoot":"","sources":["../../src/extensions/LensSources.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AA0BhE;;;;;GAKG;AACH,MAAM,OAAO,WAAW;IACpB;;;OAGG;IACH,MAAM,CAAC,KAAK;QACR,qEAAqE;QACrE,sDAAsD;QACtD,mBAAmB;QACnB,OAAO,IAAI,WAAW,EAAE,CAAC;IAC7B,CAAC;IAKD;;;;OAIG;IACH,YAAY,eAA4B,EAAE,MAAkB;QACxD,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAED;;;;;;OAMG;IACG,cAAc,CAAC,EAAE,OAAO,EAAE,MAAM,EAAwC;;;YAC1E,IAAI,MAAA,IAAI,CAAC,MAAM,0CAAE,YAAY,CAAC,OAAO,CAAC,EAAE;gBACpC,IAAI,WAAW,CAAC,MAAM,CAAC,EAAE;oBACrB,IAAI,IAAI,CAAC,MAAM,CAAC,YAAY;wBAAE,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;iBAC1E;qBAAM,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE;oBAC5B,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;iBAC9E;aACJ;YACD,OAAO,MAAA,IAAI,CAAC,eAAe,0CAAE,cAAc,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;;KACpE;CACJ;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAG,UAAU,CAAC,aAAa,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC,CAAC","sourcesContent":["import { isUndefined } from \"../common/typeguards\";\nimport { Injectable } from \"../dependency-injection/Injectable\";\n\n/**\n * A source of a lens group.\n */\nexport interface LensSource {\n /**\n * Whether the given source is able to load lenses of the supplied group.\n * @param groupId Group ID to check.\n */\n isGroupOwner(groupId: string): boolean;\n\n /**\n * Returns an encoded lens object.\n * @param lensId Lens ID to get.\n * @param groupId Group ID the lens belongs to.\n */\n getLens?(lensId: string, groupId: string): Promise<ArrayBuffer>;\n\n /**\n * Returns encoded lens objects.\n * @param groupId Group ID to get lenses of.\n */\n getLensGroup?(groupId: string): Promise<ArrayBuffer[]>;\n}\n\n/**\n * A chain of {@link LensSource} objects to be registered in Camera Kit on bootstrap. Camera Kit evaluates all\n * registered {@link LensSource} objects for a group ownership during Lens retrieval ({@link CameraKit.lenses}).\n * And if a source claims the ownership, its {@link LensSource.getLens} or {@link LensSource.getLensGroup}\n * methods are called.\n */\nexport class LensSources {\n /**\n * Returns empty LensSources instance.\n * @internal\n */\n static empty() {\n // NOTE: we want to keep LensSources constructor to require arguments\n // but internally we don't need them for the base case\n // @ts-expect-error\n return new LensSources();\n }\n\n private readonly fallbackSources: LensSources | undefined;\n private readonly source: LensSource | undefined;\n\n /**\n * Creates an instance of Lens sources.\n * @param fallbackSources A fallback sources if given {@link LensSource} doesn't claim a group ownership.\n * @param source Lens source.\n */\n constructor(fallbackSources: LensSources, source: LensSource) {\n this.fallbackSources = fallbackSources;\n this.source = source;\n }\n\n /**\n * Returns envelopes of lens/groups taking into account group ownership.\n * @internal\n * @param groupId A group to test ownership and get lens envelopes of.\n * @param lensId An optional lens ID to narrow envelopes down to a single lens.\n * @returns Envelopes or undefined if not applicable.\n */\n async retrieveLenses({ groupId, lensId }: { groupId: string; lensId?: string }): Promise<ArrayBuffer[] | void> {\n if (this.source?.isGroupOwner(groupId)) {\n if (isUndefined(lensId)) {\n if (this.source.getLensGroup) return this.source.getLensGroup(groupId);\n } else if (this.source.getLens) {\n return this.source.getLens(lensId, groupId).then((envelope) => [envelope]);\n }\n }\n return this.fallbackSources?.retrieveLenses({ groupId, lensId });\n }\n}\n\nexport const lensSourcesFactory = Injectable(\"lensSources\", () => LensSources.empty());\n"]}
@@ -1,19 +0,0 @@
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 type LensLaunchParams = Record<string, string | number | string[] | number[]>;
7
- export 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;
@@ -1,40 +0,0 @@
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("Expected an object.");
11
- }
12
- for (const [key, value] of Object.entries(launchParams)) {
13
- if (Array.isArray(value)) {
14
- if (!value.every(isString) && !value.every(isValidNumber)) {
15
- throw new Error(`Field ${key} expects a value of type string, number, string array, or number array. ` +
16
- `Received: ${JSON.stringify(value)}.`);
17
- }
18
- }
19
- else if (isNotValid(value)) {
20
- throw new Error(`Field ${key} expects a value of type string, number, string array, or number array. ` +
21
- `Received: ${JSON.stringify(value)}.`);
22
- }
23
- }
24
- return true;
25
- }
26
- /**
27
- * @param launchDetails
28
- * @internal
29
- */
30
- export const createLaunchData = ({ launchParams, persistentStore }) =>
31
- // finish() protobufjs method returns UInt8Array with shared ArrayBuffer
32
- // to avoid of detached buffer error when passing data to Lens Core
33
- // data should be copied using slice() method
34
- LaunchData.encode(LaunchData.fromPartial(Object.assign(Object.assign({}, (launchParams &&
35
- isLaunchParamsValid(launchParams) && {
36
- launchParams: { data: new TextEncoder().encode(JSON.stringify(launchParams)) },
37
- })), (persistentStore && { persistentStore: { store: new Uint8Array(persistentStore) } }))))
38
- .finish()
39
- .slice();
40
- //# sourceMappingURL=LensLaunchParams.js.map
@@ -1 +0,0 @@
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,qBAAqB,CAAC,CAAC;KAC1C;IAED,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE;QACrD,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,CACX,SAAS,GAAG,0EAA0E;oBAClF,aAAa,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAC5C,CAAC;aACL;SACJ;aAAM,IAAI,UAAU,CAAC,KAAK,CAAC,EAAE;YAC1B,MAAM,IAAI,KAAK,CACX,SAAS,GAAG,0EAA0E;gBAClF,aAAa,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAC5C,CAAC;SACL;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(\"Expected an object.\");\n }\n\n for (const [key, value] of Object.entries(launchParams)) {\n if (Array.isArray(value)) {\n if (!value.every(isString) && !value.every(isValidNumber)) {\n throw new Error(\n `Field ${key} expects a value of type string, number, string array, or number array. ` +\n `Received: ${JSON.stringify(value)}.`\n );\n }\n } else if (isNotValid(value)) {\n throw new Error(\n `Field ${key} expects a value of type string, number, string array, or number array. ` +\n `Received: ${JSON.stringify(value)}.`\n );\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"]}
@@ -1,7 +0,0 @@
1
- export { Lens_CameraFacing, LensAssetManifestItem_RequestTiming, LensAssetManifestItem_Type, LensAssetManifestItem, } from "../generated-proto/pb_schema/camera_kit/v3/lens";
2
- export { LensProto, ContentProto, Lens, isLens, isPreview, toPublicLens } from "./Lens";
3
- export { AssetTiming, LensRepository, lensRepositoryFactory } from "./LensRepository";
4
- export { lensSourcesFactory, LensSources } from "../extensions/LensSources";
5
- export { LensAssetRepository } from "./assets/LensAssetRepository";
6
- export { remoteMediaAssetLoaderFactory } from "./assets/remoteMediaAssetLoaderFactory";
7
- export { AssetLoader } from "./assets/LensAssetRepository";
package/lib/lens/index.js DELETED
@@ -1,7 +0,0 @@
1
- export { Lens_CameraFacing, LensAssetManifestItem_RequestTiming, LensAssetManifestItem_Type, LensAssetManifestItem, } from "../generated-proto/pb_schema/camera_kit/v3/lens";
2
- export { isLens, isPreview, toPublicLens } from "./Lens";
3
- export { LensRepository, lensRepositoryFactory } from "./LensRepository";
4
- export { lensSourcesFactory, LensSources } from "../extensions/LensSources";
5
- export { LensAssetRepository } from "./assets/LensAssetRepository";
6
- export { remoteMediaAssetLoaderFactory } from "./assets/remoteMediaAssetLoaderFactory";
7
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lens/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,iBAAiB,EACjB,mCAAmC,EACnC,0BAA0B,EAC1B,qBAAqB,GACxB,MAAM,iDAAiD,CAAC;AACzD,OAAO,EAAiC,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACxF,OAAO,EAAe,cAAc,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACtF,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC","sourcesContent":["export {\n Lens_CameraFacing,\n LensAssetManifestItem_RequestTiming,\n LensAssetManifestItem_Type,\n LensAssetManifestItem,\n} from \"../generated-proto/pb_schema/camera_kit/v3/lens\";\nexport { LensProto, ContentProto, Lens, isLens, isPreview, toPublicLens } from \"./Lens\";\nexport { AssetTiming, LensRepository, lensRepositoryFactory } from \"./LensRepository\";\nexport { lensSourcesFactory, LensSources } from \"../extensions/LensSources\";\nexport { LensAssetRepository } from \"./assets/LensAssetRepository\";\nexport { remoteMediaAssetLoaderFactory } from \"./assets/remoteMediaAssetLoaderFactory\";\nexport { AssetLoader } from \"./assets/LensAssetRepository\";\n"]}
@@ -1,5 +0,0 @@
1
- import { LensProto } from "./Lens";
2
- /**
3
- * @internal
4
- */
5
- export declare function decodeEnvelopes(envelopes: ArrayBuffer[]): LensProto[];
@@ -1,19 +0,0 @@
1
- import { Envelope } from "../generated-proto/pb_schema/camera_kit/v3/export";
2
- /**
3
- * @internal
4
- */
5
- function decodeEnvelope(envelope) {
6
- try {
7
- return Envelope.decode(new Uint8Array(envelope)).lenses;
8
- }
9
- catch (_a) {
10
- throw new Error("Invalid lens envelope.");
11
- }
12
- }
13
- /**
14
- * @internal
15
- */
16
- export function decodeEnvelopes(envelopes) {
17
- return envelopes.reduce((lenses, envelope) => [...lenses, ...decodeEnvelope(envelope)], []);
18
- }
19
- //# sourceMappingURL=lensEnvelopeUtil.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lensEnvelopeUtil.js","sourceRoot":"","sources":["../../src/lens/lensEnvelopeUtil.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mDAAmD,CAAC;AAG7E;;GAEG;AACH,SAAS,cAAc,CAAC,QAAqB;IACzC,IAAI;QACA,OAAO,QAAQ,CAAC,MAAM,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC;KAC3D;IAAC,WAAM;QACJ,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;KAC7C;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,SAAwB;IACpD,OAAO,SAAS,CAAC,MAAM,CAAc,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC,GAAG,MAAM,EAAE,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC7G,CAAC","sourcesContent":["import { Envelope } from \"../generated-proto/pb_schema/camera_kit/v3/export\";\nimport { LensProto } from \"./Lens\";\n\n/**\n * @internal\n */\nfunction decodeEnvelope(envelope: ArrayBuffer) {\n try {\n return Envelope.decode(new Uint8Array(envelope)).lenses;\n } catch {\n throw new Error(\"Invalid lens envelope.\");\n }\n}\n\n/**\n * @internal\n */\nexport function decodeEnvelopes(envelopes: ArrayBuffer[]) {\n return envelopes.reduce<LensProto[]>((lenses, envelope) => [...lenses, ...decodeEnvelope(envelope)], []);\n}\n"]}
@@ -1,5 +0,0 @@
1
- import { CameraKitApiHostname } from "../configuration";
2
- import { FetchHandler } from "../handlers/defaultFetchHandler";
3
- import { LensProto } from "./Lens";
4
- export declare function retrieveCameraKitLens(httpClient: FetchHandler, lensId: string, groupId: string, apiHostname: CameraKitApiHostname): Promise<LensProto>;
5
- export declare function retrieveCameraKitLensGroup(httpClient: FetchHandler, groupId: string, apiHostname: CameraKitApiHostname): Promise<LensProto[]>;
@@ -1,52 +0,0 @@
1
- import { __awaiter } from "tslib";
2
- import { encodeKnownAnyJson } from "../common/any";
3
- import { isGetGroupResponse, isLensProto } from "./Lens";
4
- const relativePath = "/com.snap.camerakit.v3.Lenses";
5
- function fixAny(lens) {
6
- // The Lens is serialized into JSON by the CameraKit backend, which is vulnerable
7
- // to serialization discrepancies between the backend and ts-proto generated serializers.
8
- // See packages/web-sdk/src/common/any.ts
9
- const featureMetadata = lens.featureMetadata.reduce((fixedAnys, anyToFix) => {
10
- // Safety: anyToFix is actually AnyJson, due to how our backend serializes it
11
- const fixedAny = encodeKnownAnyJson(anyToFix);
12
- return fixedAny ? [...fixedAnys, fixedAny] : fixedAnys;
13
- }, []);
14
- return Object.assign(Object.assign({}, lens), { featureMetadata });
15
- }
16
- function getRequestId(res) {
17
- return res.headers.get("x-request-id");
18
- }
19
- export function retrieveCameraKitLens(httpClient, lensId, groupId, apiHostname) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- const url = `https://${apiHostname}${relativePath}/groups/${groupId}/lenses/${lensId}`;
22
- const response = yield httpClient(url, { credentials: "include" });
23
- const body = yield response.json();
24
- const lens = body.lens;
25
- if (!response.ok) {
26
- throw new Error(`Cannot load lens ${lensId} in group ${groupId}. GetGroupLens responded with status ` +
27
- `${response.status} and body:\n\t${JSON.stringify(body)} for requestId ${getRequestId(response)}`);
28
- }
29
- if (!isLensProto(lens)) {
30
- throw new Error(`Cannot load lens ${lensId} in group ${groupId}. The response was not a Lens:` +
31
- `\n\t${JSON.stringify(body)} for requestId ${getRequestId(response)}`);
32
- }
33
- return fixAny(lens);
34
- });
35
- }
36
- export function retrieveCameraKitLensGroup(httpClient, groupId, apiHostname) {
37
- return __awaiter(this, void 0, void 0, function* () {
38
- const url = `https://${apiHostname}${relativePath}/groups/${groupId}`;
39
- const response = yield httpClient(url, { credentials: "include" });
40
- const body = yield response.json();
41
- if (!response.ok) {
42
- throw new Error(`Cannot load lens group ${groupId}. GetGroup responded with status ` +
43
- `${response.status} and body:\n\t${JSON.stringify(body)} for requestId ${getRequestId(response)}`);
44
- }
45
- if (!isGetGroupResponse(body)) {
46
- throw new Error(`Cannot load lens group ${groupId}. The response was not a LensGroup:` +
47
- `\n\t${JSON.stringify(body)} for requestId ${getRequestId(response)}`);
48
- }
49
- return body.lenses.map(fixAny);
50
- });
51
- }
52
- //# sourceMappingURL=lensHttpUtil.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lensHttpUtil.js","sourceRoot":"","sources":["../../src/lens/lensHttpUtil.ts"],"names":[],"mappings":"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","sourcesContent":["import { AnyJson, encodeKnownAnyJson } from \"../common/any\";\nimport { Any } from \"../generated-proto/pb_schema/google/protobuf/any\";\nimport { CameraKitApiHostname } from \"../configuration\";\nimport { FetchHandler } from \"../handlers/defaultFetchHandler\";\nimport { isGetGroupResponse, isLensProto, LensProto } from \"./Lens\";\n\nconst relativePath = \"/com.snap.camerakit.v3.Lenses\";\n\nfunction fixAny(lens: LensProto): LensProto {\n // The Lens is serialized into JSON by the CameraKit backend, which is vulnerable\n // to serialization discrepancies between the backend and ts-proto generated serializers.\n // See packages/web-sdk/src/common/any.ts\n const featureMetadata = lens.featureMetadata.reduce((fixedAnys, anyToFix) => {\n // Safety: anyToFix is actually AnyJson, due to how our backend serializes it\n const fixedAny = encodeKnownAnyJson(anyToFix as unknown as AnyJson);\n return fixedAny ? [...fixedAnys, fixedAny] : fixedAnys;\n }, [] as Any[]);\n\n return {\n ...lens,\n featureMetadata,\n };\n}\n\nfunction getRequestId(res: Response) {\n return res.headers.get(\"x-request-id\");\n}\n\nexport async function retrieveCameraKitLens(\n httpClient: FetchHandler,\n lensId: string,\n groupId: string,\n apiHostname: CameraKitApiHostname\n): Promise<LensProto> {\n const url = `https://${apiHostname}${relativePath}/groups/${groupId}/lenses/${lensId}`;\n const response = await httpClient(url, { credentials: \"include\" });\n const body = await response.json();\n const lens = body.lens;\n\n if (!response.ok) {\n throw new Error(\n `Cannot load lens ${lensId} in group ${groupId}. GetGroupLens responded with status ` +\n `${response.status} and body:\\n\\t${JSON.stringify(body)} for requestId ${getRequestId(response)}`\n );\n }\n\n if (!isLensProto(lens)) {\n throw new Error(\n `Cannot load lens ${lensId} in group ${groupId}. The response was not a Lens:` +\n `\\n\\t${JSON.stringify(body)} for requestId ${getRequestId(response)}`\n );\n }\n return fixAny(lens);\n}\n\nexport async function retrieveCameraKitLensGroup(\n httpClient: FetchHandler,\n groupId: string,\n apiHostname: CameraKitApiHostname\n): Promise<LensProto[]> {\n const url = `https://${apiHostname}${relativePath}/groups/${groupId}`;\n const response = await httpClient(url, { credentials: \"include\" });\n const body = await response.json();\n\n if (!response.ok) {\n throw new Error(\n `Cannot load lens group ${groupId}. GetGroup responded with status ` +\n `${response.status} and body:\\n\\t${JSON.stringify(body)} for requestId ${getRequestId(response)}`\n );\n }\n\n if (!isGetGroupResponse(body)) {\n throw new Error(\n `Cannot load lens group ${groupId}. The response was not a LensGroup:` +\n `\\n\\t${JSON.stringify(body)} for requestId ${getRequestId(response)}`\n );\n }\n return body.lenses.map(fixAny);\n}\n"]}