@privateid/ultrapass-web-sdk 1.3.1 → 1.3.3-1300478

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 (216) hide show
  1. package/README.md +75 -75
  2. package/dist/apiUtils.d.ts +46 -46
  3. package/dist/apiUtils.js +922 -922
  4. package/dist/application/index.d.ts +7 -7
  5. package/dist/application/index.js +27 -27
  6. package/dist/application/modules/core/document/DocumentService.d.ts +22 -22
  7. package/dist/application/modules/core/document/DocumentService.js +254 -254
  8. package/dist/application/modules/core/document/document.constants.d.ts +15 -15
  9. package/dist/application/modules/core/document/document.constants.js +21 -21
  10. package/dist/application/modules/core/document/document.domain.d.ts +7 -7
  11. package/dist/application/modules/core/document/document.domain.js +1 -1
  12. package/dist/application/modules/core/document/document.types.d.ts +17 -17
  13. package/dist/application/modules/core/document/document.types.js +1 -1
  14. package/dist/application/modules/core/document/document.utils.d.ts +3 -3
  15. package/dist/application/modules/core/document/document.utils.js +58 -58
  16. package/dist/application/modules/core/document/index.d.ts +3 -3
  17. package/dist/application/modules/core/document/index.js +1 -1
  18. package/dist/application/modules/core/face/FaceService.d.ts +33 -33
  19. package/dist/application/modules/core/face/FaceService.js +228 -221
  20. package/dist/application/modules/core/face/FaceService.js.map +1 -1
  21. package/dist/application/modules/core/face/face.constants.d.ts +53 -53
  22. package/dist/application/modules/core/face/face.constants.js +53 -53
  23. package/dist/application/modules/core/face/face.domain.d.ts +10 -10
  24. package/dist/application/modules/core/face/face.domain.js +1 -1
  25. package/dist/application/modules/core/face/face.types.d.ts +41 -38
  26. package/dist/application/modules/core/face/face.types.js +1 -1
  27. package/dist/application/modules/core/face/face.utils.d.ts +15 -15
  28. package/dist/application/modules/core/face/face.utils.js +101 -101
  29. package/dist/application/modules/core/face/index.d.ts +3 -3
  30. package/dist/application/modules/core/face/index.js +1 -1
  31. package/dist/application/modules/global/shared.constants.d.ts +2 -2
  32. package/dist/application/modules/global/shared.constants.js +2 -2
  33. package/dist/application/modules/global/shared.utils.d.ts +25 -25
  34. package/dist/application/modules/global/shared.utils.js +100 -100
  35. package/dist/application/modules/global/shared.utils.js.map +1 -1
  36. package/dist/application/modules/internal/feature-flag/LDFeatureFlagService.d.ts +9 -0
  37. package/dist/application/modules/internal/feature-flag/LDFeatureFlagService.js +32 -0
  38. package/dist/application/modules/internal/feature-flag/LDFeatureFlagService.js.map +1 -0
  39. package/dist/application/modules/internal/feature-flag/feature-flag-init.d.ts +11 -0
  40. package/dist/application/modules/internal/feature-flag/feature-flag-init.js +24 -0
  41. package/dist/application/modules/internal/feature-flag/feature-flag-init.js.map +1 -0
  42. package/dist/application/modules/internal/feature-flag/feature-flag.domain.d.ts +10 -0
  43. package/dist/application/modules/internal/feature-flag/feature-flag.domain.js +7 -0
  44. package/dist/application/modules/internal/feature-flag/feature-flag.domain.js.map +1 -0
  45. package/dist/application/modules/internal/feature-flag/featureFlagInit.d.ts +11 -0
  46. package/dist/application/modules/internal/feature-flag/featureFlagInit.js +44 -0
  47. package/dist/application/modules/internal/feature-flag/featureFlagInit.js.map +1 -0
  48. package/dist/application/modules/internal/feature-flag/index.d.ts +2 -0
  49. package/dist/application/modules/internal/feature-flag/index.js +3 -0
  50. package/dist/application/modules/internal/feature-flag/index.js.map +1 -0
  51. package/dist/application/modules/internal/shared/index.d.ts +2 -0
  52. package/dist/application/modules/internal/shared/index.js +3 -0
  53. package/dist/application/modules/internal/shared/index.js.map +1 -0
  54. package/dist/application/modules/internal/shared/shared.constants.d.ts +2 -0
  55. package/dist/application/modules/internal/shared/shared.constants.js +3 -0
  56. package/dist/application/modules/internal/shared/shared.constants.js.map +1 -0
  57. package/dist/application/modules/internal/shared/shared.utils.d.ts +44 -0
  58. package/dist/application/modules/internal/shared/shared.utils.js +204 -0
  59. package/dist/application/modules/internal/shared/shared.utils.js.map +1 -0
  60. package/dist/application/modules/internal/wasm-orchestrator/WasmOrchestratorService.d.ts +28 -0
  61. package/dist/application/modules/internal/wasm-orchestrator/WasmOrchestratorService.js +380 -0
  62. package/dist/application/modules/internal/wasm-orchestrator/WasmOrchestratorService.js.map +1 -0
  63. package/dist/application/modules/internal/wasm-orchestrator/index.d.ts +6 -0
  64. package/dist/application/modules/internal/wasm-orchestrator/index.js +9 -0
  65. package/dist/application/modules/internal/wasm-orchestrator/index.js.map +1 -0
  66. package/dist/application/modules/internal/wasm-orchestrator/wasm-orchestrator.constants.d.ts +28 -0
  67. package/dist/application/modules/internal/wasm-orchestrator/wasm-orchestrator.constants.js +35 -0
  68. package/dist/application/modules/internal/wasm-orchestrator/wasm-orchestrator.constants.js.map +1 -0
  69. package/dist/application/modules/internal/wasm-orchestrator/wasm-orchestrator.domain.d.ts +51 -0
  70. package/dist/application/modules/internal/wasm-orchestrator/wasm-orchestrator.domain.js +2 -0
  71. package/dist/application/modules/internal/wasm-orchestrator/wasm-orchestrator.domain.js.map +1 -0
  72. package/dist/application/modules/internal/wasm-orchestrator/wasm-orchestrator.types.d.ts +142 -0
  73. package/dist/application/modules/internal/wasm-orchestrator/wasm-orchestrator.types.js +2 -0
  74. package/dist/application/modules/internal/wasm-orchestrator/wasm-orchestrator.types.js.map +1 -0
  75. package/dist/application/modules/internal/wasm-orchestrator/wasm-orchestrator.utils.d.ts +86 -0
  76. package/dist/application/modules/internal/wasm-orchestrator/wasm-orchestrator.utils.js +201 -0
  77. package/dist/application/modules/internal/wasm-orchestrator/wasm-orchestrator.utils.js.map +1 -0
  78. package/dist/application/modules/support/camera/CameraServiceFactory.d.ts +10 -10
  79. package/dist/application/modules/support/camera/CameraServiceFactory.js +33 -33
  80. package/dist/application/modules/support/camera/CameraServiceFactory.js.map +1 -1
  81. package/dist/application/modules/support/camera/camera.constants.d.ts +9 -9
  82. package/dist/application/modules/support/camera/camera.constants.js +48 -48
  83. package/dist/application/modules/support/camera/camera.domain.d.ts +15 -15
  84. package/dist/application/modules/support/camera/camera.domain.js +1 -1
  85. package/dist/application/modules/support/camera/camera.types.d.ts +42 -42
  86. package/dist/application/modules/support/camera/camera.types.js +10 -10
  87. package/dist/application/modules/support/camera/camera.utils.d.ts +157 -157
  88. package/dist/application/modules/support/camera/camera.utils.js +623 -623
  89. package/dist/application/modules/support/camera/index.d.ts +24 -24
  90. package/dist/application/modules/support/camera/index.js +27 -27
  91. package/dist/application/modules/support/camera/services/BaseCameraService.d.ts +41 -41
  92. package/dist/application/modules/support/camera/services/BaseCameraService.js +278 -278
  93. package/dist/application/modules/support/camera/services/DesktopCameraService.d.ts +5 -5
  94. package/dist/application/modules/support/camera/services/DesktopCameraService.js +46 -46
  95. package/dist/application/modules/support/camera/services/FirefoxCameraService.d.ts +5 -5
  96. package/dist/application/modules/support/camera/services/FirefoxCameraService.js +46 -46
  97. package/dist/application/modules/support/camera/services/MacSafariCameraService.d.ts +5 -5
  98. package/dist/application/modules/support/camera/services/MacSafariCameraService.js +47 -47
  99. package/dist/application/modules/support/camera/services/MobileCameraService.d.ts +5 -5
  100. package/dist/application/modules/support/camera/services/MobileCameraService.js +133 -133
  101. package/dist/application/modules/support/engine/EngineService.d.ts +15 -0
  102. package/dist/application/modules/support/engine/EngineService.js +106 -0
  103. package/dist/application/modules/support/engine/EngineService.js.map +1 -0
  104. package/dist/application/modules/support/engine/engine.constants.d.ts +33 -0
  105. package/dist/application/modules/support/engine/engine.constants.js +35 -0
  106. package/dist/application/modules/support/engine/engine.constants.js.map +1 -0
  107. package/dist/application/modules/support/engine/engine.domain.d.ts +23 -0
  108. package/dist/application/modules/support/engine/engine.domain.js +2 -0
  109. package/dist/application/modules/support/engine/engine.domain.js.map +1 -0
  110. package/dist/application/modules/support/engine/engine.types.d.ts +32 -0
  111. package/dist/application/modules/support/engine/engine.types.js +2 -0
  112. package/dist/application/modules/support/engine/engine.types.js.map +1 -0
  113. package/dist/application/modules/support/engine/engine.utils.d.ts +65 -0
  114. package/dist/application/modules/support/engine/engine.utils.js +135 -0
  115. package/dist/application/modules/support/engine/engine.utils.js.map +1 -0
  116. package/dist/application/modules/support/engine/index.d.ts +3 -0
  117. package/dist/application/modules/support/engine/index.js +2 -0
  118. package/dist/application/modules/support/engine/index.js.map +1 -0
  119. package/dist/application/modules/support/permissions/PermissionsService.d.ts +55 -55
  120. package/dist/application/modules/support/permissions/PermissionsService.js +183 -183
  121. package/dist/application/modules/support/permissions/index.d.ts +4 -4
  122. package/dist/application/modules/support/permissions/index.js +2 -2
  123. package/dist/application/modules/support/permissions/permission.utils.d.ts +6 -6
  124. package/dist/application/modules/support/permissions/permission.utils.js +33 -33
  125. package/dist/application/modules/support/permissions/permissions.domain.d.ts +6 -6
  126. package/dist/application/modules/support/permissions/permissions.domain.js +1 -1
  127. package/dist/application/modules/support/permissions/permissions.types.d.ts +9 -9
  128. package/dist/application/modules/support/permissions/permissions.types.js +1 -1
  129. package/dist/application/modules/support/wasm/WasmService.d.ts +25 -25
  130. package/dist/application/modules/support/wasm/WasmService.js +156 -155
  131. package/dist/application/modules/support/wasm/WasmService.js.map +1 -1
  132. package/dist/application/modules/support/wasm/index.d.ts +6 -6
  133. package/dist/application/modules/support/wasm/index.js +8 -8
  134. package/dist/application/modules/support/wasm/wasm.constants.d.ts +78 -78
  135. package/dist/application/modules/support/wasm/wasm.constants.js +86 -86
  136. package/dist/application/modules/support/wasm/wasm.domain.d.ts +52 -52
  137. package/dist/application/modules/support/wasm/wasm.domain.js +1 -1
  138. package/dist/application/modules/support/wasm/wasm.types.d.ts +119 -118
  139. package/dist/application/modules/support/wasm/wasm.types.js +1 -1
  140. package/dist/application/modules/support/wasm/wasm.utils.d.ts +88 -88
  141. package/dist/application/modules/support/wasm/wasm.utils.js +243 -243
  142. package/dist/application/modules/support/wasm-orchestrator/WasmOrchestratorService.d.ts +28 -0
  143. package/dist/application/modules/support/wasm-orchestrator/WasmOrchestratorService.js +324 -0
  144. package/dist/application/modules/support/wasm-orchestrator/WasmOrchestratorService.js.map +1 -0
  145. package/dist/application/modules/support/wasm-orchestrator/index.d.ts +6 -0
  146. package/dist/application/modules/support/wasm-orchestrator/index.js +9 -0
  147. package/dist/application/modules/support/wasm-orchestrator/index.js.map +1 -0
  148. package/dist/application/modules/support/wasm-orchestrator/wasm-orchestrator.constants.d.ts +36 -0
  149. package/dist/application/modules/support/wasm-orchestrator/wasm-orchestrator.constants.js +44 -0
  150. package/dist/application/modules/support/wasm-orchestrator/wasm-orchestrator.constants.js.map +1 -0
  151. package/dist/application/modules/support/wasm-orchestrator/wasm-orchestrator.domain.d.ts +47 -0
  152. package/dist/application/modules/support/wasm-orchestrator/wasm-orchestrator.domain.js +2 -0
  153. package/dist/application/modules/support/wasm-orchestrator/wasm-orchestrator.domain.js.map +1 -0
  154. package/dist/application/modules/support/wasm-orchestrator/wasm-orchestrator.types.d.ts +136 -0
  155. package/dist/application/modules/support/wasm-orchestrator/wasm-orchestrator.types.js +2 -0
  156. package/dist/application/modules/support/wasm-orchestrator/wasm-orchestrator.types.js.map +1 -0
  157. package/dist/application/modules/support/wasm-orchestrator/wasm-orchestrator.utils.d.ts +91 -0
  158. package/dist/application/modules/support/wasm-orchestrator/wasm-orchestrator.utils.js +250 -0
  159. package/dist/application/modules/support/wasm-orchestrator/wasm-orchestrator.utils.js.map +1 -0
  160. package/dist/application/workers/index.d.ts +42 -42
  161. package/dist/application/workers/index.js +8 -8
  162. package/dist/application/workers/wasm/WasmWorkerService.d.ts +66 -0
  163. package/dist/application/workers/wasm/WasmWorkerService.js +801 -0
  164. package/dist/application/workers/wasm/WasmWorkerService.js.map +1 -0
  165. package/dist/application/workers/wasm/index.d.ts +4 -0
  166. package/dist/application/workers/wasm/index.js +9 -0
  167. package/dist/application/workers/wasm/index.js.map +1 -0
  168. package/dist/application/workers/wasm/wasm-worker.constants.d.ts +5 -0
  169. package/dist/application/workers/wasm/wasm-worker.constants.js +6 -0
  170. package/dist/application/workers/wasm/wasm-worker.constants.js.map +1 -0
  171. package/dist/application/workers/wasm/wasm-worker.domain.d.ts +99 -0
  172. package/dist/application/workers/wasm/wasm-worker.domain.js +2 -0
  173. package/dist/application/workers/wasm/wasm-worker.domain.js.map +1 -0
  174. package/dist/application/workers/wasm/wasm-worker.types.d.ts +88 -0
  175. package/dist/application/workers/wasm/wasm-worker.types.js +2 -0
  176. package/dist/application/workers/wasm/wasm-worker.types.js.map +1 -0
  177. package/dist/application/workers/wasm/wasm-worker.utils.d.ts +10 -0
  178. package/dist/application/workers/wasm/wasm-worker.utils.js +130 -0
  179. package/dist/application/workers/wasm/wasm-worker.utils.js.map +1 -0
  180. package/dist/buildConfig.d.ts +3 -0
  181. package/dist/buildConfig.js +7 -0
  182. package/dist/buildConfig.js.map +1 -0
  183. package/dist/cameraUtils.d.ts +77 -77
  184. package/dist/cameraUtils.js +361 -361
  185. package/dist/constants.d.ts +9 -9
  186. package/dist/constants.js +13 -13
  187. package/dist/createCallback.d.ts +56 -56
  188. package/dist/createCallback.js +332 -331
  189. package/dist/createCallback.js.map +1 -1
  190. package/dist/dbUtils.d.ts +14 -14
  191. package/dist/dbUtils.js +148 -148
  192. package/dist/envUtils.d.ts +4 -4
  193. package/dist/envUtils.js +16 -16
  194. package/dist/faceModule.d.ts +196 -196
  195. package/dist/faceModule.js +978 -978
  196. package/dist/featureFlagInit.d.ts +11 -0
  197. package/dist/featureFlagInit.js +44 -0
  198. package/dist/featureFlagInit.js.map +1 -0
  199. package/dist/index.d.ts +38 -38
  200. package/dist/index.js +82 -82
  201. package/dist/main.d.ts +30 -30
  202. package/dist/main.js +84 -84
  203. package/dist/types.d.ts +139 -139
  204. package/dist/types.js +77 -77
  205. package/dist/utils.d.ts +84 -84
  206. package/dist/utils.js +580 -580
  207. package/package.json +102 -102
  208. package/wasm/ultra/nosimd/{25.11.13-1357710 → 26.01.08-1300478}/privid_fhe_uber.js +18 -18
  209. package/wasm/ultra/nosimd/{25.11.13-1357710 → 26.01.08-1300478}/privid_fhe_uber.wasm +0 -0
  210. package/wasm/ultra/nosimd/version.json +2 -2
  211. package/wasm/ultra/simd/{25.11.13-1357710 → 26.01.08-1300478}/privid_fhe_uber.js +18 -18
  212. package/wasm/ultra/simd/{25.11.13-1357710 → 26.01.08-1300478}/privid_fhe_uber.wasm +0 -0
  213. package/wasm/ultra/simd/version.json +2 -2
  214. package/workers/comlink.min.js +7 -7
  215. package/workers/comlink.min.js.map +1 -1
  216. package/workers/wasm.worker.js +936 -924
@@ -1,7 +1,7 @@
1
- import { DocumentService } from './modules/core/document';
2
- import { FaceService } from './modules/core/face';
3
- import { WasmService } from './modules/support/wasm';
4
- export declare const cameraService: import("./modules/support/camera").Camera;
5
- export declare const wasmService: WasmService;
6
- export declare const faceService: FaceService;
7
- export declare const documentService: DocumentService;
1
+ import { DocumentService } from './modules/core/document';
2
+ import { FaceService } from './modules/core/face';
3
+ import { WasmService } from './modules/support/wasm';
4
+ export declare const cameraService: import("./modules/support/camera").Camera;
5
+ export declare const wasmService: WasmService;
6
+ export declare const faceService: FaceService;
7
+ export declare const documentService: DocumentService;
@@ -1,28 +1,28 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { DocumentService } from './modules/core/document';
11
- import { FaceService } from './modules/core/face';
12
- import { CameraServiceFactory } from './modules/support/camera';
13
- import { PermissionService } from './modules/support/permissions';
14
- import { WasmService } from './modules/support/wasm';
15
- // Support Modules
16
- const permissionsService = PermissionService.getInstance();
17
- export const cameraService = CameraServiceFactory.create(permissionsService);
18
- export const wasmService = new WasmService();
19
- // TODO: Migrate to top-level await when upgrading to node 20
20
- (() => __awaiter(void 0, void 0, void 0, function* () {
21
- yield wasmService.initialize();
22
- }))();
23
- // Core Modules
24
- // FACE
25
- export const faceService = new FaceService(wasmService, cameraService);
26
- // DOCUMENT
27
- export const documentService = new DocumentService(wasmService, cameraService);
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { DocumentService } from './modules/core/document';
11
+ import { FaceService } from './modules/core/face';
12
+ import { CameraServiceFactory } from './modules/support/camera';
13
+ import { PermissionService } from './modules/support/permissions';
14
+ import { WasmService } from './modules/support/wasm';
15
+ // Support Modules
16
+ const permissionsService = PermissionService.getInstance();
17
+ export const cameraService = CameraServiceFactory.create(permissionsService);
18
+ export const wasmService = new WasmService();
19
+ // TODO: Migrate to top-level await when upgrading to node 20
20
+ (() => __awaiter(void 0, void 0, void 0, function* () {
21
+ yield wasmService.initialize();
22
+ }))();
23
+ // Core Modules
24
+ // FACE
25
+ export const faceService = new FaceService(wasmService, cameraService);
26
+ // DOCUMENT
27
+ export const documentService = new DocumentService(wasmService, cameraService);
28
28
  //# sourceMappingURL=index.js.map
@@ -1,22 +1,22 @@
1
- import { Document } from './document.domain';
2
- import { BackScanParams, DocumentOcrParams, FrontDocumentScanParams, DocumentScanResponse } from './document.types';
3
- import { Wasm } from '../../support/wasm';
4
- import { Camera } from '../../support/camera/camera.domain';
5
- export declare class DocumentService implements Document {
6
- private isSimd;
7
- private hasDebugWithImages;
8
- private canvas;
9
- private debugCanvas;
10
- private wasmService;
11
- private cameraService;
12
- privid_wasm_result: (operation: string, id: string, response_str: any) => void;
13
- constructor(wasmService: Wasm, cameraService: Camera);
14
- scanGovernmentPhotoId(params: FrontDocumentScanParams): Promise<DocumentScanResponse>;
15
- scanPassport(params: FrontDocumentScanParams): Promise<DocumentScanResponse>;
16
- scanBackDocument(params: BackScanParams): Promise<void>;
17
- documentOcr(params: DocumentOcrParams): Promise<void>;
18
- private getVideoElement;
19
- private generateDebugImages;
20
- private generateImageData;
21
- private prepareCanvas;
22
- }
1
+ import { Document } from './document.domain';
2
+ import { BackScanParams, DocumentOcrParams, FrontDocumentScanParams, DocumentScanResponse } from './document.types';
3
+ import { Wasm } from '../../support/wasm';
4
+ import { Camera } from '../../support/camera/camera.domain';
5
+ export declare class DocumentService implements Document {
6
+ private isSimd;
7
+ private hasDebugWithImages;
8
+ private canvas;
9
+ private debugCanvas;
10
+ private wasmService;
11
+ private cameraService;
12
+ privid_wasm_result: (operation: string, id: string, response_str: any) => void;
13
+ constructor(wasmService: Wasm, cameraService: Camera);
14
+ scanGovernmentPhotoId(params: FrontDocumentScanParams): Promise<DocumentScanResponse>;
15
+ scanPassport(params: FrontDocumentScanParams): Promise<DocumentScanResponse>;
16
+ scanBackDocument(params: BackScanParams): Promise<void>;
17
+ documentOcr(params: DocumentOcrParams): Promise<void>;
18
+ private getVideoElement;
19
+ private generateDebugImages;
20
+ private generateImageData;
21
+ private prepareCanvas;
22
+ }
@@ -1,255 +1,255 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- /* eslint-disable lines-between-class-members */
11
- /* eslint-disable import/prefer-default-export */
12
- import { detect } from 'detect-browser';
13
- import { proxy } from 'comlink';
14
- import { callbackTypeEnum, createCallback } from '../../../../createCallback';
15
- import { ImageType } from '../../../../types';
16
- import { getDebugType, getIsSIMD, printLogs, iOS } from '../../global/shared.utils';
17
- import { imageDataFromBase64, releaseCanvas } from './document.utils';
18
- import { DEBUG_TYPES_WITH_IMAGES, INPUT_IMAGE_FORMAT, FINGERS_OVER_DOCUMENT_THRESHOLD, DOCUMENT_THRESHOLD_X, DOCUMENT_THRESHOLD_Y, DOCUMENT_TOO_CLOSE_THRESHOLD, DOCUMENT_TOO_FAR_THRESHOLD, CALCULATE_AGE_FROM_OCR_TEXT, ERROR_RESULT, ERROR_CODE, IMAGE_EXPORT_FORMAT, DOWNLOAD_IMAGE_TYPE, FILE_EXTENSION, DOWNLOAD_DELAY_TIMEOUT, } from './document.constants';
19
- import { CANVAS_ID, INVALID_VIDEO_ERROR } from '../../global/shared.constants';
20
- export class DocumentService {
21
- constructor(wasmService, cameraService) {
22
- // TODO: Remove isSimd from here, it should belong to WasmService.
23
- this.isSimd = false;
24
- this.hasDebugWithImages = false;
25
- getIsSIMD().then((simd) => (this.isSimd = simd));
26
- const canvas = document.createElement('canvas');
27
- canvas.setAttribute('id', CANVAS_ID);
28
- const debugCanvas = document.createElement('canvas');
29
- const debugType = getDebugType();
30
- this.hasDebugWithImages = DEBUG_TYPES_WITH_IMAGES.includes(debugType);
31
- this.canvas = canvas;
32
- this.debugCanvas = debugCanvas;
33
- this.wasmService = wasmService;
34
- this.cameraService = cameraService;
35
- }
36
- scanGovernmentPhotoId(params) {
37
- return __awaiter(this, void 0, void 0, function* () {
38
- printLogs('[DocumentService] scanGovernmentPhotoId params', params);
39
- try {
40
- let configuration = {
41
- input_image_format: INPUT_IMAGE_FORMAT,
42
- fingers_over_document_threshold: FINGERS_OVER_DOCUMENT_THRESHOLD,
43
- };
44
- if (params.config) {
45
- configuration = Object.assign(Object.assign({}, configuration), params.config);
46
- }
47
- const callback = createCallback({
48
- type: callbackTypeEnum.frontScan,
49
- callbackFunction: params.callback,
50
- });
51
- const workerCallback = proxy(callback);
52
- const imageData = this.generateImageData();
53
- if (this.hasDebugWithImages) {
54
- yield this.generateDebugImages([imageData], `${ImageType.original}_front_gov_photo_id_document_scan`, 'enroll');
55
- }
56
- yield this.wasmService.scanFrontPhotoIdDocument(imageData, JSON.stringify(configuration), workerCallback);
57
- return {
58
- success: true,
59
- };
60
- }
61
- catch (error) {
62
- printLogs(`[DocumentService] scanGovernmentPhotoId error: `, error.message, 'ERROR');
63
- return {
64
- success: false,
65
- };
66
- }
67
- });
68
- }
69
- scanPassport(params) {
70
- return __awaiter(this, void 0, void 0, function* () {
71
- printLogs('[DocumentService] scanPassport params', params);
72
- try {
73
- let configuration = {
74
- input_image_format: INPUT_IMAGE_FORMAT,
75
- };
76
- if (params.config) {
77
- configuration = Object.assign(Object.assign({}, configuration), params.config);
78
- }
79
- const callback = createCallback({
80
- type: callbackTypeEnum.passportScan,
81
- callbackFunction: params.callback,
82
- });
83
- const workerCallback = proxy(callback);
84
- const imageData = this.generateImageData();
85
- if (this.hasDebugWithImages) {
86
- yield this.generateDebugImages([imageData], `${ImageType.original}_passport_scan`, 'enroll');
87
- }
88
- yield this.wasmService.scanPassport(imageData, JSON.stringify(configuration), workerCallback);
89
- return {
90
- success: true,
91
- };
92
- }
93
- catch (error) {
94
- printLogs(`[DocumentService] scanPassport error: `, error, 'ERROR');
95
- return {
96
- success: false,
97
- };
98
- }
99
- });
100
- }
101
- scanBackDocument(params) {
102
- return __awaiter(this, void 0, void 0, function* () {
103
- const { callback, image, config } = params;
104
- printLogs('________________ DOCUMENT SCAN ______________', '');
105
- const videoEl = this.getVideoElement();
106
- let configuration = {
107
- input_image_format: INPUT_IMAGE_FORMAT,
108
- };
109
- if (config) {
110
- configuration = Object.assign(Object.assign({}, configuration), config);
111
- }
112
- const { os } = detect();
113
- if (iOS() || ['iOS', 'android', 'Android OS'].includes(os)) {
114
- this.privid_wasm_result = createCallback({
115
- type: callbackTypeEnum.backScan,
116
- callbackFunction: callback,
117
- isMobile: true,
118
- });
119
- }
120
- else if (configuration === null || configuration === void 0 ? void 0 : configuration.document_scan_barcode_only) {
121
- this.privid_wasm_result = createCallback({
122
- type: callbackTypeEnum.backScan,
123
- callbackFunction: callback,
124
- isMobile: true,
125
- });
126
- }
127
- else if (configuration === null || configuration === void 0 ? void 0 : configuration.detect_barcode_without_parsing) {
128
- this.privid_wasm_result = createCallback({
129
- type: callbackTypeEnum.backScan,
130
- callbackFunction: callback,
131
- });
132
- }
133
- else {
134
- configuration = Object.assign(Object.assign({}, configuration), { detect_document_only: true });
135
- this.privid_wasm_result = createCallback({ type: callbackTypeEnum.backScan, callbackFunction: callback });
136
- }
137
- configuration = JSON.stringify(configuration);
138
- if (!videoEl) {
139
- printLogs(`Capture need the video element id`, '', 'ERROR');
140
- return { result: ERROR_RESULT };
141
- }
142
- const imageData = this.generateImageData();
143
- if ((imageData === null || imageData === void 0 ? void 0 : imageData.width) === 0)
144
- return { result: ERROR_RESULT };
145
- let result = null;
146
- if (this.hasDebugWithImages) {
147
- yield this.generateDebugImages([imageData], ImageType.original, 'enroll');
148
- }
149
- try {
150
- printLogs(`Configuration: back scan: `, configuration);
151
- result = yield this.wasmService.scanBackDocument(imageData, this.isSimd, configuration, proxy(this.privid_wasm_result));
152
- // TODO: Validate if we need to release, and when, since we will have only one instance of canvas
153
- releaseCanvas(this.canvas);
154
- return Object.assign({}, result);
155
- }
156
- catch (e) {
157
- printLogs(`isValidPhotoID error: `, e, 'ERROR');
158
- return {
159
- result: ERROR_CODE,
160
- };
161
- }
162
- });
163
- }
164
- documentOcr(params) {
165
- return __awaiter(this, void 0, void 0, function* () {
166
- printLogs('________________ DOCUMENT OCR ______________', '');
167
- let configuration = {
168
- input_image_format: INPUT_IMAGE_FORMAT,
169
- calculate_age_from_ocr_text: CALCULATE_AGE_FROM_OCR_TEXT,
170
- threshold_doc_x: DOCUMENT_THRESHOLD_X,
171
- threshold_doc_y: DOCUMENT_THRESHOLD_Y,
172
- threshold_doc_too_close: DOCUMENT_TOO_CLOSE_THRESHOLD,
173
- threshold_doc_too_far: DOCUMENT_TOO_FAR_THRESHOLD,
174
- };
175
- if (params.config) {
176
- configuration = Object.assign(Object.assign({}, configuration), params.config);
177
- }
178
- this.privid_wasm_result = createCallback({ type: callbackTypeEnum.documentOcr, callbackFunction: params.callback });
179
- const cb = proxy(this.privid_wasm_result);
180
- if (this.hasDebugWithImages) {
181
- const imageData = yield imageDataFromBase64(params.inputImage);
182
- yield this.generateDebugImages([imageData], `${ImageType.original}_document_ocr`, 'enroll');
183
- }
184
- try {
185
- configuration = JSON.stringify(configuration);
186
- return yield this.wasmService.documentOcr(params.inputImage, configuration, cb);
187
- }
188
- catch (e) {
189
- printLogs(`isValidPhotoID error: `, e, 'ERROR');
190
- return {
191
- result: ERROR_CODE,
192
- };
193
- }
194
- });
195
- }
196
- getVideoElement() {
197
- return this.cameraService.getVideoElementDOM();
198
- }
199
- generateDebugImages(images, title, action) {
200
- return __awaiter(this, void 0, void 0, function* () {
201
- const a = document.createElement('a');
202
- a.type = DOWNLOAD_IMAGE_TYPE;
203
- document.body.appendChild(a);
204
- for (const imageContent of images) {
205
- this.debugCanvas.width = imageContent.width;
206
- this.debugCanvas.height = imageContent.height;
207
- const ctx = this.debugCanvas.getContext('2d');
208
- ctx.putImageData(imageContent, 0, 0);
209
- const blob = yield new Promise((resolve) => this.debugCanvas.toBlob((b) => resolve(b), IMAGE_EXPORT_FORMAT));
210
- if (blob) {
211
- const url = URL.createObjectURL(blob);
212
- try {
213
- a.href = url;
214
- a.download = `${title}_${action}${FILE_EXTENSION}`;
215
- a.click();
216
- yield new Promise((r) => setTimeout(r, DOWNLOAD_DELAY_TIMEOUT));
217
- }
218
- catch (error) {
219
- printLogs('[DocumentService] generateDebugImages error', error, 'ERROR');
220
- }
221
- finally {
222
- URL.revokeObjectURL(url);
223
- }
224
- }
225
- }
226
- a.remove();
227
- });
228
- }
229
- // TODO: Both DocumentService and FaceService uses generateImageData and prepareCanvas
230
- // but in different ways, should we create an interface to secure these implementations?
231
- // Or should we bring that to a different Class called CanvasService?
232
- generateImageData() {
233
- var _a;
234
- const videoElement = this.cameraService.getVideoElementDOM();
235
- printLogs('[DocumentService] generateImageData videoElement', videoElement);
236
- const canvas = this.prepareCanvas(videoElement);
237
- const context = this.canvas.getContext('2d', { willReadFrequently: true });
238
- (_a = context.resetTransform) === null || _a === void 0 ? void 0 : _a.call(context);
239
- context.clearRect(0, 0, canvas.width, canvas.height);
240
- context.drawImage(videoElement, 0, 0, canvas.width, canvas.height);
241
- return context.getImageData(0, 0, canvas.width, canvas.height);
242
- }
243
- prepareCanvas(videoElement) {
244
- const height = videoElement.videoHeight || 0;
245
- const width = videoElement.videoWidth || 0;
246
- if (width === 0) {
247
- throw new Error(INVALID_VIDEO_ERROR);
248
- }
249
- this.canvas.setAttribute('height', `${height}`);
250
- this.canvas.setAttribute('width', `${width}`);
251
- this.canvas.setAttribute('id', CANVAS_ID);
252
- return this.canvas;
253
- }
254
- }
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ /* eslint-disable lines-between-class-members */
11
+ /* eslint-disable import/prefer-default-export */
12
+ import { detect } from 'detect-browser';
13
+ import { proxy } from 'comlink';
14
+ import { callbackTypeEnum, createCallback } from '../../../../createCallback';
15
+ import { ImageType } from '../../../../types';
16
+ import { getDebugType, getIsSIMD, printLogs, iOS } from '../../global/shared.utils';
17
+ import { imageDataFromBase64, releaseCanvas } from './document.utils';
18
+ import { DEBUG_TYPES_WITH_IMAGES, INPUT_IMAGE_FORMAT, FINGERS_OVER_DOCUMENT_THRESHOLD, DOCUMENT_THRESHOLD_X, DOCUMENT_THRESHOLD_Y, DOCUMENT_TOO_CLOSE_THRESHOLD, DOCUMENT_TOO_FAR_THRESHOLD, CALCULATE_AGE_FROM_OCR_TEXT, ERROR_RESULT, ERROR_CODE, IMAGE_EXPORT_FORMAT, DOWNLOAD_IMAGE_TYPE, FILE_EXTENSION, DOWNLOAD_DELAY_TIMEOUT, } from './document.constants';
19
+ import { CANVAS_ID, INVALID_VIDEO_ERROR } from '../../global/shared.constants';
20
+ export class DocumentService {
21
+ constructor(wasmService, cameraService) {
22
+ // TODO: Remove isSimd from here, it should belong to WasmService.
23
+ this.isSimd = false;
24
+ this.hasDebugWithImages = false;
25
+ getIsSIMD().then((simd) => (this.isSimd = simd));
26
+ const canvas = document.createElement('canvas');
27
+ canvas.setAttribute('id', CANVAS_ID);
28
+ const debugCanvas = document.createElement('canvas');
29
+ const debugType = getDebugType();
30
+ this.hasDebugWithImages = DEBUG_TYPES_WITH_IMAGES.includes(debugType);
31
+ this.canvas = canvas;
32
+ this.debugCanvas = debugCanvas;
33
+ this.wasmService = wasmService;
34
+ this.cameraService = cameraService;
35
+ }
36
+ scanGovernmentPhotoId(params) {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ printLogs('[DocumentService] scanGovernmentPhotoId params', params);
39
+ try {
40
+ let configuration = {
41
+ input_image_format: INPUT_IMAGE_FORMAT,
42
+ fingers_over_document_threshold: FINGERS_OVER_DOCUMENT_THRESHOLD,
43
+ };
44
+ if (params.config) {
45
+ configuration = Object.assign(Object.assign({}, configuration), params.config);
46
+ }
47
+ const callback = createCallback({
48
+ type: callbackTypeEnum.frontScan,
49
+ callbackFunction: params.callback,
50
+ });
51
+ const workerCallback = proxy(callback);
52
+ const imageData = this.generateImageData();
53
+ if (this.hasDebugWithImages) {
54
+ yield this.generateDebugImages([imageData], `${ImageType.original}_front_gov_photo_id_document_scan`, 'enroll');
55
+ }
56
+ yield this.wasmService.scanFrontPhotoIdDocument(imageData, JSON.stringify(configuration), workerCallback);
57
+ return {
58
+ success: true,
59
+ };
60
+ }
61
+ catch (error) {
62
+ printLogs(`[DocumentService] scanGovernmentPhotoId error: `, error.message, 'ERROR');
63
+ return {
64
+ success: false,
65
+ };
66
+ }
67
+ });
68
+ }
69
+ scanPassport(params) {
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ printLogs('[DocumentService] scanPassport params', params);
72
+ try {
73
+ let configuration = {
74
+ input_image_format: INPUT_IMAGE_FORMAT,
75
+ };
76
+ if (params.config) {
77
+ configuration = Object.assign(Object.assign({}, configuration), params.config);
78
+ }
79
+ const callback = createCallback({
80
+ type: callbackTypeEnum.passportScan,
81
+ callbackFunction: params.callback,
82
+ });
83
+ const workerCallback = proxy(callback);
84
+ const imageData = this.generateImageData();
85
+ if (this.hasDebugWithImages) {
86
+ yield this.generateDebugImages([imageData], `${ImageType.original}_passport_scan`, 'enroll');
87
+ }
88
+ yield this.wasmService.scanPassport(imageData, JSON.stringify(configuration), workerCallback);
89
+ return {
90
+ success: true,
91
+ };
92
+ }
93
+ catch (error) {
94
+ printLogs(`[DocumentService] scanPassport error: `, error, 'ERROR');
95
+ return {
96
+ success: false,
97
+ };
98
+ }
99
+ });
100
+ }
101
+ scanBackDocument(params) {
102
+ return __awaiter(this, void 0, void 0, function* () {
103
+ const { callback, image, config } = params;
104
+ printLogs('________________ DOCUMENT SCAN ______________', '');
105
+ const videoEl = this.getVideoElement();
106
+ let configuration = {
107
+ input_image_format: INPUT_IMAGE_FORMAT,
108
+ };
109
+ if (config) {
110
+ configuration = Object.assign(Object.assign({}, configuration), config);
111
+ }
112
+ const { os } = detect();
113
+ if (iOS() || ['iOS', 'android', 'Android OS'].includes(os)) {
114
+ this.privid_wasm_result = createCallback({
115
+ type: callbackTypeEnum.backScan,
116
+ callbackFunction: callback,
117
+ isMobile: true,
118
+ });
119
+ }
120
+ else if (configuration === null || configuration === void 0 ? void 0 : configuration.document_scan_barcode_only) {
121
+ this.privid_wasm_result = createCallback({
122
+ type: callbackTypeEnum.backScan,
123
+ callbackFunction: callback,
124
+ isMobile: true,
125
+ });
126
+ }
127
+ else if (configuration === null || configuration === void 0 ? void 0 : configuration.detect_barcode_without_parsing) {
128
+ this.privid_wasm_result = createCallback({
129
+ type: callbackTypeEnum.backScan,
130
+ callbackFunction: callback,
131
+ });
132
+ }
133
+ else {
134
+ configuration = Object.assign(Object.assign({}, configuration), { detect_document_only: true });
135
+ this.privid_wasm_result = createCallback({ type: callbackTypeEnum.backScan, callbackFunction: callback });
136
+ }
137
+ configuration = JSON.stringify(configuration);
138
+ if (!videoEl) {
139
+ printLogs(`Capture need the video element id`, '', 'ERROR');
140
+ return { result: ERROR_RESULT };
141
+ }
142
+ const imageData = this.generateImageData();
143
+ if ((imageData === null || imageData === void 0 ? void 0 : imageData.width) === 0)
144
+ return { result: ERROR_RESULT };
145
+ let result = null;
146
+ if (this.hasDebugWithImages) {
147
+ yield this.generateDebugImages([imageData], ImageType.original, 'enroll');
148
+ }
149
+ try {
150
+ printLogs(`Configuration: back scan: `, configuration);
151
+ result = yield this.wasmService.scanBackDocument(imageData, this.isSimd, configuration, proxy(this.privid_wasm_result));
152
+ // TODO: Validate if we need to release, and when, since we will have only one instance of canvas
153
+ releaseCanvas(this.canvas);
154
+ return Object.assign({}, result);
155
+ }
156
+ catch (e) {
157
+ printLogs(`isValidPhotoID error: `, e, 'ERROR');
158
+ return {
159
+ result: ERROR_CODE,
160
+ };
161
+ }
162
+ });
163
+ }
164
+ documentOcr(params) {
165
+ return __awaiter(this, void 0, void 0, function* () {
166
+ printLogs('________________ DOCUMENT OCR ______________', '');
167
+ let configuration = {
168
+ input_image_format: INPUT_IMAGE_FORMAT,
169
+ calculate_age_from_ocr_text: CALCULATE_AGE_FROM_OCR_TEXT,
170
+ threshold_doc_x: DOCUMENT_THRESHOLD_X,
171
+ threshold_doc_y: DOCUMENT_THRESHOLD_Y,
172
+ threshold_doc_too_close: DOCUMENT_TOO_CLOSE_THRESHOLD,
173
+ threshold_doc_too_far: DOCUMENT_TOO_FAR_THRESHOLD,
174
+ };
175
+ if (params.config) {
176
+ configuration = Object.assign(Object.assign({}, configuration), params.config);
177
+ }
178
+ this.privid_wasm_result = createCallback({ type: callbackTypeEnum.documentOcr, callbackFunction: params.callback });
179
+ const cb = proxy(this.privid_wasm_result);
180
+ if (this.hasDebugWithImages) {
181
+ const imageData = yield imageDataFromBase64(params.inputImage);
182
+ yield this.generateDebugImages([imageData], `${ImageType.original}_document_ocr`, 'enroll');
183
+ }
184
+ try {
185
+ configuration = JSON.stringify(configuration);
186
+ return yield this.wasmService.documentOcr(params.inputImage, configuration, cb);
187
+ }
188
+ catch (e) {
189
+ printLogs(`isValidPhotoID error: `, e, 'ERROR');
190
+ return {
191
+ result: ERROR_CODE,
192
+ };
193
+ }
194
+ });
195
+ }
196
+ getVideoElement() {
197
+ return this.cameraService.getVideoElementDOM();
198
+ }
199
+ generateDebugImages(images, title, action) {
200
+ return __awaiter(this, void 0, void 0, function* () {
201
+ const a = document.createElement('a');
202
+ a.type = DOWNLOAD_IMAGE_TYPE;
203
+ document.body.appendChild(a);
204
+ for (const imageContent of images) {
205
+ this.debugCanvas.width = imageContent.width;
206
+ this.debugCanvas.height = imageContent.height;
207
+ const ctx = this.debugCanvas.getContext('2d');
208
+ ctx.putImageData(imageContent, 0, 0);
209
+ const blob = yield new Promise((resolve) => this.debugCanvas.toBlob((b) => resolve(b), IMAGE_EXPORT_FORMAT));
210
+ if (blob) {
211
+ const url = URL.createObjectURL(blob);
212
+ try {
213
+ a.href = url;
214
+ a.download = `${title}_${action}${FILE_EXTENSION}`;
215
+ a.click();
216
+ yield new Promise((r) => setTimeout(r, DOWNLOAD_DELAY_TIMEOUT));
217
+ }
218
+ catch (error) {
219
+ printLogs('[DocumentService] generateDebugImages error', error, 'ERROR');
220
+ }
221
+ finally {
222
+ URL.revokeObjectURL(url);
223
+ }
224
+ }
225
+ }
226
+ a.remove();
227
+ });
228
+ }
229
+ // TODO: Both DocumentService and FaceService uses generateImageData and prepareCanvas
230
+ // but in different ways, should we create an interface to secure these implementations?
231
+ // Or should we bring that to a different Class called CanvasService?
232
+ generateImageData() {
233
+ var _a;
234
+ const videoElement = this.cameraService.getVideoElementDOM();
235
+ printLogs('[DocumentService] generateImageData videoElement', videoElement);
236
+ const canvas = this.prepareCanvas(videoElement);
237
+ const context = this.canvas.getContext('2d', { willReadFrequently: true });
238
+ (_a = context.resetTransform) === null || _a === void 0 ? void 0 : _a.call(context);
239
+ context.clearRect(0, 0, canvas.width, canvas.height);
240
+ context.drawImage(videoElement, 0, 0, canvas.width, canvas.height);
241
+ return context.getImageData(0, 0, canvas.width, canvas.height);
242
+ }
243
+ prepareCanvas(videoElement) {
244
+ const height = videoElement.videoHeight || 0;
245
+ const width = videoElement.videoWidth || 0;
246
+ if (width === 0) {
247
+ throw new Error(INVALID_VIDEO_ERROR);
248
+ }
249
+ this.canvas.setAttribute('height', `${height}`);
250
+ this.canvas.setAttribute('width', `${width}`);
251
+ this.canvas.setAttribute('id', CANVAS_ID);
252
+ return this.canvas;
253
+ }
254
+ }
255
255
  //# sourceMappingURL=DocumentService.js.map