@privateid/ultrapass-web-sdk 1.3.1 → 1.3.2-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
package/dist/utils.js CHANGED
@@ -1,581 +1,581 @@
1
- /* eslint-disable */
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var _a;
12
- import { simd } from 'wasm-feature-detect';
13
- import { wrap } from 'comlink';
14
- import { detect } from 'detect-browser';
15
- import { LANDSCAPE, PORTRAIT } from './constants';
16
- import { getEnvironment } from './envUtils';
17
- const windowOrigin = (_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.origin;
18
- const workerUrl = `${windowOrigin}/workers/wasm.worker.js`;
19
- const functions = wrap(new Worker(workerUrl));
20
- export const { isLoad, ultraEnroll, ultraPredict, compareEmbeddings, pkiEncrypt, checkIfModelsLoaded, ultraScanBackDocument, ultraScanFrontDocument, ultraCompareEmbeddings, ultraAgeEstimate, ultraDocumentOcr, freeMemory, } = functions;
21
- export function iOS() {
22
- return ['iPad Simulator', 'iPhone Simulator', 'iPod Simulator', 'iPad', 'iPhone', 'iPod'].includes(navigator.platform);
23
- }
24
- export function isMobileFunc() {
25
- let check = false;
26
- (function (a) {
27
- if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(a) ||
28
- /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4)))
29
- check = true;
30
- })(navigator.userAgent || navigator.vendor || window.opera);
31
- return check;
32
- }
33
- export const getIsSIMD = () => __awaiter(void 0, void 0, void 0, function* () {
34
- const isSimd = yield simd();
35
- return isSimd;
36
- });
37
- export const getUrlParameter = function getUrlParameter(sParam, defaultValue) {
38
- const sPageURL = window.location.search.substring(1);
39
- const sURLVariables = sPageURL.split('&');
40
- let sParameterName;
41
- let i;
42
- for (i = 0; i < sURLVariables.length; i++) {
43
- sParameterName = sURLVariables[i].split('=');
44
- if (sParameterName[0] === sParam) {
45
- return typeof sParameterName[1] === undefined ? defaultValue : decodeURIComponent(sParameterName[1]);
46
- }
47
- }
48
- return defaultValue;
49
- };
50
- /**
51
- * This function does the printing in the console based on the type and will only print based on @param debugType
52
- * Please make sure to use this so that logs on the module would only print depending on the debug level
53
- * @param title title of the printing. sample console.log(tiltle, message)
54
- * @param message message of the printing. sample console.log(tiltle, message) if this is not needed just throw an empy string. sample: printLogs(title, '', debugType)
55
- * @param debugType this variable will determine the type of printing in the console
56
- * @param type this variable will determing the type of printing in the console, "LOG", "WARNING" or "ERROR" by default it is "LOG"
57
- */
58
- // export const printLogs = (message: string, data: any, debugType: string, type: LOGTYPE = LOGTYPE.LOG) => {
59
- // const errorLogs = ['1', '2', '3', '901', '902', '903'];
60
- // const warningLogs = ['2', '3', '902', '903'];
61
- // const allLogs = ['3', '903'];
62
- // if (type === LOGTYPE.ERROR && errorLogs.includes(debugType.toString())) {
63
- // console.error('DEBUG_SDK', message, data);
64
- // } else if (type === LOGTYPE.WARN && warningLogs.includes(debugType.toString())) {
65
- // console.warn('DEBUG_SDK', message, data);
66
- // } else if (type === LOGTYPE.LOG && allLogs.includes(debugType.toString())) {
67
- // console.log('DEBUG_SDK', message, data);
68
- // }
69
- // };
70
- export const getDebugType = () => {
71
- const queryParams = new URLSearchParams(window.location.search);
72
- const searchedParameterResult = queryParams.get('debug_type');
73
- const environment = getEnvironment();
74
- if (searchedParameterResult) {
75
- return searchedParameterResult;
76
- }
77
- if (environment === 'dev') {
78
- return '3';
79
- }
80
- return '0';
81
- };
82
- export const printLogs = (message, data, type = 'LOG') => {
83
- const errorLogs = ['1', '2', '3', '901', '902', '903'];
84
- const warningLogs = ['2', '3', '902', '903'];
85
- const allLogs = ['3', '903'];
86
- const debugType = getDebugType();
87
- if (type === 'ERROR' && errorLogs.includes(debugType)) {
88
- console.error('DEBUG_SDK', message);
89
- }
90
- else if (type === 'WARN' && warningLogs.includes(debugType)) {
91
- console.warn('DEBUG_SDK', message, data);
92
- }
93
- else if (type === 'LOG' && allLogs.includes(debugType)) {
94
- console.log('DEBUG_SDK', message, data);
95
- }
96
- };
97
- export const getPortraitBase64 = (content) => __awaiter(void 0, void 0, void 0, function* () {
98
- const canvas = document.createElement('canvas');
99
- canvas.width = content.width;
100
- canvas.height = content.height;
101
- const context = canvas.getContext('2d');
102
- context.putImageData(content, 0, 0);
103
- const blob = yield new Promise((resolve) => canvas.toBlob(resolve));
104
- const base64 = yield blobToBase64(blob);
105
- return base64;
106
- });
107
- export const createImages = (images, title, action) => __awaiter(void 0, void 0, void 0, function* () {
108
- const promises = images.map((content) => new Promise((resolve) => __awaiter(void 0, void 0, void 0, function* () {
109
- const canvas = document.createElement('canvas');
110
- canvas.width = content.width;
111
- canvas.height = content.height;
112
- const context = canvas.getContext('2d');
113
- context.putImageData(content, 0, 0);
114
- const blob = yield new Promise((resolve) => canvas.toBlob(resolve, 'image/jpeg'));
115
- const base64 = yield blobToBase64(blob);
116
- const url = URL.createObjectURL(blob);
117
- resolve({ url, base64 });
118
- })));
119
- const data = yield Promise.all(promises);
120
- const a = document.createElement('a');
121
- for (let i = 0; i < data.length; i++) {
122
- // if(!iOS()) {
123
- // eslint-disable-next-line no-loop-func
124
- yield new Promise((resolve) => {
125
- a.href = data[i].url;
126
- a.type = 'image/png';
127
- a.download = `${title}_${action ? 'enroll' : 'predict'}` + '.png';
128
- document.body.appendChild(a);
129
- a.click();
130
- setTimeout(() => {
131
- resolve();
132
- }, 1000);
133
- });
134
- // }
135
- // postImages(data[i].base64);
136
- }
137
- });
138
- export function blobToBase64(blob) {
139
- return new Promise((resolve) => {
140
- const reader = new FileReader();
141
- reader.onloadend = () => resolve(reader.result);
142
- reader.readAsDataURL(blob);
143
- });
144
- }
145
- // export function downloadBase64File(base64Data, fileName) {
146
- // const downloadLink = document.createElement("a");
147
- // downloadLink.href = base64Data;
148
- // downloadLink.download = fileName;
149
- // downloadLink.click();
150
- // }
151
- export const wait = (timeout) => __awaiter(void 0, void 0, void 0, function* () {
152
- return new Promise((resolve) => {
153
- setTimeout(() => {
154
- resolve('true');
155
- }, timeout);
156
- });
157
- });
158
- export const arrayToTextDownload = (data, filename) => {
159
- // const text = data.join(', ');
160
- // const blob = new Blob([text], { type: 'text/plain' });
161
- // const url = URL.createObjectURL(blob);
162
- // const a = document.createElement('a');
163
- // a.href = url;
164
- // a.download = filename;
165
- // document.body.appendChild(a);
166
- // a.click();
167
- };
168
- export function setDefaultCameraDeviceId(deviceId) {
169
- localStorage.setItem('defaultDeviceId', deviceId);
170
- }
171
- export function getDefaultCameraDeviceId() {
172
- return localStorage.getItem('defaultDeviceId');
173
- }
174
- // eslint-disable-next-line consistent-return
175
- export const convertCroppedImage = (croppedBarcode, cropImageWidth, cropImageHeight) => __awaiter(void 0, void 0, void 0, function* () {
176
- try {
177
- const image = new ImageData(croppedBarcode, cropImageWidth, cropImageHeight);
178
- const canvas = document.createElement('canvas');
179
- canvas.width = image.width;
180
- canvas.height = image.height;
181
- const context = canvas.getContext('2d');
182
- context.putImageData(image, 0, 0);
183
- return canvas.toDataURL('image/png');
184
- }
185
- catch (e) {
186
- printLogs(`Error: ${e}`, 'ERROR');
187
- }
188
- });
189
- export const isMobileDevice = () => {
190
- const { os } = detect();
191
- return ['iOS', 'Android OS', 'Windows Mobile'].includes(os);
192
- };
193
- export var MessageType;
194
- (function (MessageType) {
195
- MessageType["faceValidation"] = "Face Validation";
196
- MessageType["antispoofStatus"] = "Antispoof Status";
197
- })(MessageType || (MessageType = {}));
198
- export const getStatusMessage = (result, type = MessageType.faceValidation) => {
199
- if (type === MessageType.faceValidation) {
200
- switch (result) {
201
- case -100:
202
- case -1:
203
- return '';
204
- case 0:
205
- return 'Processing hold still';
206
- case 1:
207
- case 2:
208
- case 3:
209
- return 'Please move back';
210
- case 4:
211
- return 'Please move closer';
212
- case 5:
213
- return 'Move slightly left';
214
- case 6:
215
- return 'Move slightly right';
216
- case 7:
217
- return 'Move down';
218
- case 8:
219
- return 'Move up';
220
- case 9:
221
- return 'Please hold still';
222
- case 10:
223
- return 'Remove glasses';
224
- case 11:
225
- return 'Remove mask ';
226
- case 12:
227
- case 13:
228
- return 'Please look at camera';
229
- case 14:
230
- if (isMobileDevice()) {
231
- return 'Raise phone level to face';
232
- }
233
- return 'Move your chin down';
234
- case 15:
235
- if (isMobileDevice()) {
236
- return 'Lower phone level to face';
237
- }
238
- return 'Move your chin up';
239
- case 16:
240
- return 'Too dim - increase lighting';
241
- case 17:
242
- return 'Too bright - lower lighting';
243
- case 18:
244
- return 'Please hold still';
245
- case 19:
246
- return '';
247
- case 20:
248
- return 'Please hold still';
249
- case 21:
250
- return 'Please close mouth';
251
- case 22:
252
- case 23:
253
- return 'Keep your head straight';
254
- case 24:
255
- return 'Face mask and glasses detected';
256
- case 25:
257
- return 'Align your face with the white oval';
258
- default:
259
- return '';
260
- }
261
- }
262
- else if (type === MessageType.antispoofStatus) {
263
- switch (result) {
264
- case -100:
265
- case -5:
266
- case -4:
267
- case -2:
268
- case 1:
269
- return 'Too dim - increase lighting';
270
- case -3:
271
- return 'Center your face in the circle';
272
- case -1:
273
- return 'Looking for face';
274
- case 0:
275
- return '';
276
- default:
277
- return '';
278
- }
279
- }
280
- };
281
- export const getRawFaceValidationStatus = (status) => {
282
- switch (status) {
283
- case -1:
284
- return 'No Face';
285
- case 0:
286
- return 'Valid Face';
287
- case 1:
288
- return 'Image Spoof';
289
- case 2:
290
- return 'Video Spoof';
291
- case 3:
292
- return 'Too Close';
293
- case 4:
294
- return 'Too far away';
295
- case 5:
296
- return 'Too far to right';
297
- case 6:
298
- return 'Too far to left';
299
- case 7:
300
- return 'Too far up';
301
- case 8:
302
- return 'Too far down';
303
- case 9:
304
- return 'Too blurry';
305
- case 10:
306
- return 'Glasses on';
307
- case 11:
308
- return 'Mask on';
309
- case 12:
310
- return 'Chin too far left';
311
- case 13:
312
- return 'Chin too far right';
313
- case 14:
314
- return 'Chin too far up';
315
- case 15:
316
- return 'Chin too far down';
317
- case 16:
318
- return 'Image too dim';
319
- case 17:
320
- return 'Image too bright';
321
- case 18:
322
- return 'Face low confidence value';
323
- case 19:
324
- return 'Invalid face background';
325
- case 20:
326
- return 'Eyes blink';
327
- case 21:
328
- return 'Mouth Open';
329
- case 22:
330
- return 'Face rotated right';
331
- case 23:
332
- return 'Face rotated left';
333
- case 24:
334
- return 'Face mask and glasses detected';
335
- case -100:
336
- return '-100 Invalid Image';
337
- default:
338
- return '';
339
- }
340
- };
341
- export const getRawSpoofStatusMessage = (status) => {
342
- switch (status) {
343
- case -100:
344
- return 'Generic Error';
345
- case -4:
346
- return 'Invalid Face';
347
- case -3:
348
- return 'Face Too Close To Edge';
349
- case -2:
350
- return 'Mobile Phone Detected';
351
- case -1:
352
- return 'No Face Detected';
353
- case 0:
354
- return 'Real';
355
- case 1:
356
- return 'Spoof Detected';
357
- default:
358
- return '';
359
- }
360
- };
361
- export const checkPackageSupport = () => __awaiter(void 0, void 0, void 0, function* () {
362
- const { name: browserName, os, version } = detect();
363
- const parsedVersion = parseInt(version.split('.')[0], 10);
364
- if (os === 'Mac OS') {
365
- if (browserName === 'safari' && parseInt(version.split('.')[0], 10) <= 10) {
366
- return { support: false, message: 'Safari version 10 and below is not supported.' };
367
- }
368
- }
369
- if (os === 'iOS') {
370
- if (browserName === 'safari' && parseInt(version.split('.')[0], 10) <= 10) {
371
- return { support: false, message: 'Safari version 10 and below is not supported.' };
372
- }
373
- if (browserName === 'opera' && parseInt(version.split('.')[0], 10) <= 72) {
374
- return { support: false, message: 'Opera mobile version 72 and below is not support WASM' };
375
- }
376
- }
377
- if (os === 'Android OS' || os === 'android') {
378
- if (browserName === 'chrome' && parseInt(version.split('.')[0], 10) <= 96) {
379
- return { support: false, message: 'Android Chrome version 96 and below is not supported.' };
380
- }
381
- if (browserName === 'samsung' && parseInt(version.split('.')[0], 10) <= 6.2) {
382
- return { support: false, message: 'Samsung browser version 6 and below is not supported.' };
383
- }
384
- if (browserName === 'firefox' && parseInt(version.split('.')[0], 10) <= 94) {
385
- return { support: false, message: 'Firefox mobile version 94 and below is not supported.' };
386
- }
387
- if (browserName === 'opera' && parseInt(version.split('.')[0], 10) <= 72) {
388
- return { support: false, message: 'Opera mobile version 72 and below is not support WASM' };
389
- }
390
- if (browserName === 'android' && parseInt(version.split('.')[0], 10) <= 96) {
391
- return { support: false, message: 'Android Browser version 96 and below is not supported.' };
392
- }
393
- }
394
- if (browserName === 'ie') {
395
- return { support: false, message: 'Internet Explorer is not supported.' };
396
- }
397
- if (browserName === 'edge' && parseInt(version.split('.')[0], 10) <= 78) {
398
- return { support: false, message: 'Edge version 78 and below is not supported.' };
399
- }
400
- if (browserName === 'chrome' && parseInt(version.split('.')[0], 10) <= 57) {
401
- return { support: false, message: 'Chrome version 57 and below is not support WASM' };
402
- }
403
- if (browserName === 'firefox' && parseInt(version.split('.')[0], 10) <= 52) {
404
- return { support: false, message: 'Firefox version 52 and below is not supported.' };
405
- }
406
- if (browserName === 'opera' && parseInt(version.split('.')[0], 10) <= 43) {
407
- return { support: false, message: 'Opera version 43 and below is not support WASM' };
408
- }
409
- return { support: true };
410
- });
411
- export const getDocumentValidationStatusMessage = (result, isPassport = false) => {
412
- switch (result) {
413
- case -2:
414
- return 'SYSTEM ERROR. Please try again later.';
415
- case -1:
416
- return !isPassport
417
- ? 'Please show ID at the center of the screen'
418
- : 'Please show identity page at the center of the screen';
419
- case 2:
420
- return 'Please hold still';
421
- case 3:
422
- return 'Move back a little';
423
- case 4:
424
- return 'Move just a little closer';
425
- case 5:
426
- case 6:
427
- case 7:
428
- case 8:
429
- return !isPassport
430
- ? 'Please show ID at the center of the screen'
431
- : 'Please show identity page at the center of the screen';
432
- case 9:
433
- return 'Please remove finger blocking document';
434
- default:
435
- return '';
436
- }
437
- };
438
- export const getBarcodeValidationStatusMessage = (result) => {
439
- switch (result) {
440
- case -1:
441
- return 'Barcode not detected';
442
- case 0:
443
- return 'Success';
444
- case 3:
445
- return 'Unsupported barcode detected';
446
- case 4:
447
- return 'Unable to parse barcode data';
448
- default:
449
- return '';
450
- }
451
- };
452
- // To Deprecate and remove soon
453
- export const getFrontDocumentStatusMessage = (result) => {
454
- switch (result) {
455
- case 0:
456
- return 'Success';
457
- case 12:
458
- return '';
459
- case -1:
460
- return 'Please show ID at the center of the screen';
461
- case 2:
462
- return 'Please hold still';
463
- case 18:
464
- return 'Please show front of the ID';
465
- case 3:
466
- return 'Please hold still';
467
- case 4:
468
- return 'Move just a little closer';
469
- case 9:
470
- return 'Please remove finger blocking document';
471
- case -2:
472
- return 'SYSTEM ERROR. Please try again later.';
473
- case 5:
474
- case 6:
475
- case 7:
476
- case 8:
477
- return 'Please show ID at the center of the screen';
478
- case -100:
479
- return 'Please show front of the ID';
480
- default:
481
- return '';
482
- }
483
- };
484
- // To Deprecate and remove soon
485
- export const getPassporttStatusMessage = (result) => {
486
- switch (result) {
487
- case 0:
488
- return 'Success';
489
- case 12:
490
- return '';
491
- case -1:
492
- return 'Please show identity page at the center of the screen';
493
- case 3:
494
- return 'Please hold still';
495
- case 4:
496
- return 'Move just a little closer';
497
- case 9:
498
- return 'Please remove finger blocking document';
499
- case -2:
500
- return 'SYSTEM ERROR. Please try again later.';
501
- case 5:
502
- case 6:
503
- case 7:
504
- case 8:
505
- return 'Please show identity page at the center of the screen';
506
- case -100:
507
- return 'Please show identity page at the center of the screen';
508
- default:
509
- return '';
510
- }
511
- };
512
- // To Deprecate and remove soon
513
- export const getBackDocumentStatusMessage = (result) => {
514
- switch (result) {
515
- case 0:
516
- return 'Success';
517
- case 12:
518
- return '';
519
- case -1:
520
- return 'Please show ID at the center of the screen';
521
- case 10:
522
- return 'Move the barcode closer';
523
- case 3:
524
- return 'Please move the barcode closer';
525
- case 4:
526
- return 'Move just a little closer';
527
- case 18:
528
- return 'Please show barcode in the box';
529
- case 9:
530
- return 'Please remove finger blocking document';
531
- case -2:
532
- return 'SYSTEM ERROR. Please try again later.';
533
- case 5:
534
- case 6:
535
- case 7:
536
- case 8:
537
- return 'Please show ID at the center of the screen';
538
- default:
539
- return '';
540
- }
541
- };
542
- export function getScreenOrientation() {
543
- if (window.innerHeight > window.innerWidth) {
544
- return PORTRAIT;
545
- }
546
- return LANDSCAPE;
547
- }
548
- export function convertPngBase64ToJpegBase64(pngBase64, maxWidth = 800, maxHeight = 800, quality = 0.85) {
549
- return __awaiter(this, void 0, void 0, function* () {
550
- return new Promise((resolve, reject) => {
551
- const img = new Image();
552
- img.src = pngBase64;
553
- img.onload = () => {
554
- const canvas = document.createElement('canvas');
555
- const ctx = canvas.getContext('2d');
556
- // Resize logic
557
- let { width, height } = img;
558
- const aspectRatio = width / height;
559
- if (width > maxWidth || height > maxHeight) {
560
- if (width > height) {
561
- width = maxWidth;
562
- height = width / aspectRatio;
563
- }
564
- else {
565
- height = maxHeight;
566
- width = height * aspectRatio;
567
- }
568
- }
569
- canvas.width = width;
570
- canvas.height = height;
571
- // Draw image onto resized canvas
572
- ctx.drawImage(img, 0, 0, width, height);
573
- // Convert to JPEG Base64 (with compression)
574
- const jpegBase64 = canvas.toDataURL('image/jpeg', quality);
575
- resolve(jpegBase64);
576
- };
577
- img.onerror = reject;
578
- });
579
- });
580
- }
1
+ /* eslint-disable */
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var _a;
12
+ import { simd } from 'wasm-feature-detect';
13
+ import { wrap } from 'comlink';
14
+ import { detect } from 'detect-browser';
15
+ import { LANDSCAPE, PORTRAIT } from './constants';
16
+ import { getEnvironment } from './envUtils';
17
+ const windowOrigin = (_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.origin;
18
+ const workerUrl = `${windowOrigin}/workers/wasm.worker.js`;
19
+ const functions = wrap(new Worker(workerUrl));
20
+ export const { isLoad, ultraEnroll, ultraPredict, compareEmbeddings, pkiEncrypt, checkIfModelsLoaded, ultraScanBackDocument, ultraScanFrontDocument, ultraCompareEmbeddings, ultraAgeEstimate, ultraDocumentOcr, freeMemory, } = functions;
21
+ export function iOS() {
22
+ return ['iPad Simulator', 'iPhone Simulator', 'iPod Simulator', 'iPad', 'iPhone', 'iPod'].includes(navigator.platform);
23
+ }
24
+ export function isMobileFunc() {
25
+ let check = false;
26
+ (function (a) {
27
+ if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(a) ||
28
+ /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4)))
29
+ check = true;
30
+ })(navigator.userAgent || navigator.vendor || window.opera);
31
+ return check;
32
+ }
33
+ export const getIsSIMD = () => __awaiter(void 0, void 0, void 0, function* () {
34
+ const isSimd = yield simd();
35
+ return isSimd;
36
+ });
37
+ export const getUrlParameter = function getUrlParameter(sParam, defaultValue) {
38
+ const sPageURL = window.location.search.substring(1);
39
+ const sURLVariables = sPageURL.split('&');
40
+ let sParameterName;
41
+ let i;
42
+ for (i = 0; i < sURLVariables.length; i++) {
43
+ sParameterName = sURLVariables[i].split('=');
44
+ if (sParameterName[0] === sParam) {
45
+ return typeof sParameterName[1] === undefined ? defaultValue : decodeURIComponent(sParameterName[1]);
46
+ }
47
+ }
48
+ return defaultValue;
49
+ };
50
+ /**
51
+ * This function does the printing in the console based on the type and will only print based on @param debugType
52
+ * Please make sure to use this so that logs on the module would only print depending on the debug level
53
+ * @param title title of the printing. sample console.log(tiltle, message)
54
+ * @param message message of the printing. sample console.log(tiltle, message) if this is not needed just throw an empy string. sample: printLogs(title, '', debugType)
55
+ * @param debugType this variable will determine the type of printing in the console
56
+ * @param type this variable will determing the type of printing in the console, "LOG", "WARNING" or "ERROR" by default it is "LOG"
57
+ */
58
+ // export const printLogs = (message: string, data: any, debugType: string, type: LOGTYPE = LOGTYPE.LOG) => {
59
+ // const errorLogs = ['1', '2', '3', '901', '902', '903'];
60
+ // const warningLogs = ['2', '3', '902', '903'];
61
+ // const allLogs = ['3', '903'];
62
+ // if (type === LOGTYPE.ERROR && errorLogs.includes(debugType.toString())) {
63
+ // console.error('DEBUG_SDK', message, data);
64
+ // } else if (type === LOGTYPE.WARN && warningLogs.includes(debugType.toString())) {
65
+ // console.warn('DEBUG_SDK', message, data);
66
+ // } else if (type === LOGTYPE.LOG && allLogs.includes(debugType.toString())) {
67
+ // console.log('DEBUG_SDK', message, data);
68
+ // }
69
+ // };
70
+ export const getDebugType = () => {
71
+ const queryParams = new URLSearchParams(window.location.search);
72
+ const searchedParameterResult = queryParams.get('debug_type');
73
+ const environment = getEnvironment();
74
+ if (searchedParameterResult) {
75
+ return searchedParameterResult;
76
+ }
77
+ if (environment === 'dev') {
78
+ return '3';
79
+ }
80
+ return '0';
81
+ };
82
+ export const printLogs = (message, data, type = 'LOG') => {
83
+ const errorLogs = ['1', '2', '3', '901', '902', '903'];
84
+ const warningLogs = ['2', '3', '902', '903'];
85
+ const allLogs = ['3', '903'];
86
+ const debugType = getDebugType();
87
+ if (type === 'ERROR' && errorLogs.includes(debugType)) {
88
+ console.error('DEBUG_SDK', message);
89
+ }
90
+ else if (type === 'WARN' && warningLogs.includes(debugType)) {
91
+ console.warn('DEBUG_SDK', message, data);
92
+ }
93
+ else if (type === 'LOG' && allLogs.includes(debugType)) {
94
+ console.log('DEBUG_SDK', message, data);
95
+ }
96
+ };
97
+ export const getPortraitBase64 = (content) => __awaiter(void 0, void 0, void 0, function* () {
98
+ const canvas = document.createElement('canvas');
99
+ canvas.width = content.width;
100
+ canvas.height = content.height;
101
+ const context = canvas.getContext('2d');
102
+ context.putImageData(content, 0, 0);
103
+ const blob = yield new Promise((resolve) => canvas.toBlob(resolve));
104
+ const base64 = yield blobToBase64(blob);
105
+ return base64;
106
+ });
107
+ export const createImages = (images, title, action) => __awaiter(void 0, void 0, void 0, function* () {
108
+ const promises = images.map((content) => new Promise((resolve) => __awaiter(void 0, void 0, void 0, function* () {
109
+ const canvas = document.createElement('canvas');
110
+ canvas.width = content.width;
111
+ canvas.height = content.height;
112
+ const context = canvas.getContext('2d');
113
+ context.putImageData(content, 0, 0);
114
+ const blob = yield new Promise((resolve) => canvas.toBlob(resolve, 'image/jpeg'));
115
+ const base64 = yield blobToBase64(blob);
116
+ const url = URL.createObjectURL(blob);
117
+ resolve({ url, base64 });
118
+ })));
119
+ const data = yield Promise.all(promises);
120
+ const a = document.createElement('a');
121
+ for (let i = 0; i < data.length; i++) {
122
+ // if(!iOS()) {
123
+ // eslint-disable-next-line no-loop-func
124
+ yield new Promise((resolve) => {
125
+ a.href = data[i].url;
126
+ a.type = 'image/png';
127
+ a.download = `${title}_${action ? 'enroll' : 'predict'}` + '.png';
128
+ document.body.appendChild(a);
129
+ a.click();
130
+ setTimeout(() => {
131
+ resolve();
132
+ }, 1000);
133
+ });
134
+ // }
135
+ // postImages(data[i].base64);
136
+ }
137
+ });
138
+ export function blobToBase64(blob) {
139
+ return new Promise((resolve) => {
140
+ const reader = new FileReader();
141
+ reader.onloadend = () => resolve(reader.result);
142
+ reader.readAsDataURL(blob);
143
+ });
144
+ }
145
+ // export function downloadBase64File(base64Data, fileName) {
146
+ // const downloadLink = document.createElement("a");
147
+ // downloadLink.href = base64Data;
148
+ // downloadLink.download = fileName;
149
+ // downloadLink.click();
150
+ // }
151
+ export const wait = (timeout) => __awaiter(void 0, void 0, void 0, function* () {
152
+ return new Promise((resolve) => {
153
+ setTimeout(() => {
154
+ resolve('true');
155
+ }, timeout);
156
+ });
157
+ });
158
+ export const arrayToTextDownload = (data, filename) => {
159
+ // const text = data.join(', ');
160
+ // const blob = new Blob([text], { type: 'text/plain' });
161
+ // const url = URL.createObjectURL(blob);
162
+ // const a = document.createElement('a');
163
+ // a.href = url;
164
+ // a.download = filename;
165
+ // document.body.appendChild(a);
166
+ // a.click();
167
+ };
168
+ export function setDefaultCameraDeviceId(deviceId) {
169
+ localStorage.setItem('defaultDeviceId', deviceId);
170
+ }
171
+ export function getDefaultCameraDeviceId() {
172
+ return localStorage.getItem('defaultDeviceId');
173
+ }
174
+ // eslint-disable-next-line consistent-return
175
+ export const convertCroppedImage = (croppedBarcode, cropImageWidth, cropImageHeight) => __awaiter(void 0, void 0, void 0, function* () {
176
+ try {
177
+ const image = new ImageData(croppedBarcode, cropImageWidth, cropImageHeight);
178
+ const canvas = document.createElement('canvas');
179
+ canvas.width = image.width;
180
+ canvas.height = image.height;
181
+ const context = canvas.getContext('2d');
182
+ context.putImageData(image, 0, 0);
183
+ return canvas.toDataURL('image/png');
184
+ }
185
+ catch (e) {
186
+ printLogs(`Error: ${e}`, 'ERROR');
187
+ }
188
+ });
189
+ export const isMobileDevice = () => {
190
+ const { os } = detect();
191
+ return ['iOS', 'Android OS', 'Windows Mobile'].includes(os);
192
+ };
193
+ export var MessageType;
194
+ (function (MessageType) {
195
+ MessageType["faceValidation"] = "Face Validation";
196
+ MessageType["antispoofStatus"] = "Antispoof Status";
197
+ })(MessageType || (MessageType = {}));
198
+ export const getStatusMessage = (result, type = MessageType.faceValidation) => {
199
+ if (type === MessageType.faceValidation) {
200
+ switch (result) {
201
+ case -100:
202
+ case -1:
203
+ return '';
204
+ case 0:
205
+ return 'Processing hold still';
206
+ case 1:
207
+ case 2:
208
+ case 3:
209
+ return 'Please move back';
210
+ case 4:
211
+ return 'Please move closer';
212
+ case 5:
213
+ return 'Move slightly left';
214
+ case 6:
215
+ return 'Move slightly right';
216
+ case 7:
217
+ return 'Move down';
218
+ case 8:
219
+ return 'Move up';
220
+ case 9:
221
+ return 'Please hold still';
222
+ case 10:
223
+ return 'Remove glasses';
224
+ case 11:
225
+ return 'Remove mask ';
226
+ case 12:
227
+ case 13:
228
+ return 'Please look at camera';
229
+ case 14:
230
+ if (isMobileDevice()) {
231
+ return 'Raise phone level to face';
232
+ }
233
+ return 'Move your chin down';
234
+ case 15:
235
+ if (isMobileDevice()) {
236
+ return 'Lower phone level to face';
237
+ }
238
+ return 'Move your chin up';
239
+ case 16:
240
+ return 'Too dim - increase lighting';
241
+ case 17:
242
+ return 'Too bright - lower lighting';
243
+ case 18:
244
+ return 'Please hold still';
245
+ case 19:
246
+ return '';
247
+ case 20:
248
+ return 'Please hold still';
249
+ case 21:
250
+ return 'Please close mouth';
251
+ case 22:
252
+ case 23:
253
+ return 'Keep your head straight';
254
+ case 24:
255
+ return 'Face mask and glasses detected';
256
+ case 25:
257
+ return 'Align your face with the white oval';
258
+ default:
259
+ return '';
260
+ }
261
+ }
262
+ else if (type === MessageType.antispoofStatus) {
263
+ switch (result) {
264
+ case -100:
265
+ case -5:
266
+ case -4:
267
+ case -2:
268
+ case 1:
269
+ return 'Too dim - increase lighting';
270
+ case -3:
271
+ return 'Center your face in the circle';
272
+ case -1:
273
+ return 'Looking for face';
274
+ case 0:
275
+ return '';
276
+ default:
277
+ return '';
278
+ }
279
+ }
280
+ };
281
+ export const getRawFaceValidationStatus = (status) => {
282
+ switch (status) {
283
+ case -1:
284
+ return 'No Face';
285
+ case 0:
286
+ return 'Valid Face';
287
+ case 1:
288
+ return 'Image Spoof';
289
+ case 2:
290
+ return 'Video Spoof';
291
+ case 3:
292
+ return 'Too Close';
293
+ case 4:
294
+ return 'Too far away';
295
+ case 5:
296
+ return 'Too far to right';
297
+ case 6:
298
+ return 'Too far to left';
299
+ case 7:
300
+ return 'Too far up';
301
+ case 8:
302
+ return 'Too far down';
303
+ case 9:
304
+ return 'Too blurry';
305
+ case 10:
306
+ return 'Glasses on';
307
+ case 11:
308
+ return 'Mask on';
309
+ case 12:
310
+ return 'Chin too far left';
311
+ case 13:
312
+ return 'Chin too far right';
313
+ case 14:
314
+ return 'Chin too far up';
315
+ case 15:
316
+ return 'Chin too far down';
317
+ case 16:
318
+ return 'Image too dim';
319
+ case 17:
320
+ return 'Image too bright';
321
+ case 18:
322
+ return 'Face low confidence value';
323
+ case 19:
324
+ return 'Invalid face background';
325
+ case 20:
326
+ return 'Eyes blink';
327
+ case 21:
328
+ return 'Mouth Open';
329
+ case 22:
330
+ return 'Face rotated right';
331
+ case 23:
332
+ return 'Face rotated left';
333
+ case 24:
334
+ return 'Face mask and glasses detected';
335
+ case -100:
336
+ return '-100 Invalid Image';
337
+ default:
338
+ return '';
339
+ }
340
+ };
341
+ export const getRawSpoofStatusMessage = (status) => {
342
+ switch (status) {
343
+ case -100:
344
+ return 'Generic Error';
345
+ case -4:
346
+ return 'Invalid Face';
347
+ case -3:
348
+ return 'Face Too Close To Edge';
349
+ case -2:
350
+ return 'Mobile Phone Detected';
351
+ case -1:
352
+ return 'No Face Detected';
353
+ case 0:
354
+ return 'Real';
355
+ case 1:
356
+ return 'Spoof Detected';
357
+ default:
358
+ return '';
359
+ }
360
+ };
361
+ export const checkPackageSupport = () => __awaiter(void 0, void 0, void 0, function* () {
362
+ const { name: browserName, os, version } = detect();
363
+ const parsedVersion = parseInt(version.split('.')[0], 10);
364
+ if (os === 'Mac OS') {
365
+ if (browserName === 'safari' && parseInt(version.split('.')[0], 10) <= 10) {
366
+ return { support: false, message: 'Safari version 10 and below is not supported.' };
367
+ }
368
+ }
369
+ if (os === 'iOS') {
370
+ if (browserName === 'safari' && parseInt(version.split('.')[0], 10) <= 10) {
371
+ return { support: false, message: 'Safari version 10 and below is not supported.' };
372
+ }
373
+ if (browserName === 'opera' && parseInt(version.split('.')[0], 10) <= 72) {
374
+ return { support: false, message: 'Opera mobile version 72 and below is not support WASM' };
375
+ }
376
+ }
377
+ if (os === 'Android OS' || os === 'android') {
378
+ if (browserName === 'chrome' && parseInt(version.split('.')[0], 10) <= 96) {
379
+ return { support: false, message: 'Android Chrome version 96 and below is not supported.' };
380
+ }
381
+ if (browserName === 'samsung' && parseInt(version.split('.')[0], 10) <= 6.2) {
382
+ return { support: false, message: 'Samsung browser version 6 and below is not supported.' };
383
+ }
384
+ if (browserName === 'firefox' && parseInt(version.split('.')[0], 10) <= 94) {
385
+ return { support: false, message: 'Firefox mobile version 94 and below is not supported.' };
386
+ }
387
+ if (browserName === 'opera' && parseInt(version.split('.')[0], 10) <= 72) {
388
+ return { support: false, message: 'Opera mobile version 72 and below is not support WASM' };
389
+ }
390
+ if (browserName === 'android' && parseInt(version.split('.')[0], 10) <= 96) {
391
+ return { support: false, message: 'Android Browser version 96 and below is not supported.' };
392
+ }
393
+ }
394
+ if (browserName === 'ie') {
395
+ return { support: false, message: 'Internet Explorer is not supported.' };
396
+ }
397
+ if (browserName === 'edge' && parseInt(version.split('.')[0], 10) <= 78) {
398
+ return { support: false, message: 'Edge version 78 and below is not supported.' };
399
+ }
400
+ if (browserName === 'chrome' && parseInt(version.split('.')[0], 10) <= 57) {
401
+ return { support: false, message: 'Chrome version 57 and below is not support WASM' };
402
+ }
403
+ if (browserName === 'firefox' && parseInt(version.split('.')[0], 10) <= 52) {
404
+ return { support: false, message: 'Firefox version 52 and below is not supported.' };
405
+ }
406
+ if (browserName === 'opera' && parseInt(version.split('.')[0], 10) <= 43) {
407
+ return { support: false, message: 'Opera version 43 and below is not support WASM' };
408
+ }
409
+ return { support: true };
410
+ });
411
+ export const getDocumentValidationStatusMessage = (result, isPassport = false) => {
412
+ switch (result) {
413
+ case -2:
414
+ return 'SYSTEM ERROR. Please try again later.';
415
+ case -1:
416
+ return !isPassport
417
+ ? 'Please show ID at the center of the screen'
418
+ : 'Please show identity page at the center of the screen';
419
+ case 2:
420
+ return 'Please hold still';
421
+ case 3:
422
+ return 'Move back a little';
423
+ case 4:
424
+ return 'Move just a little closer';
425
+ case 5:
426
+ case 6:
427
+ case 7:
428
+ case 8:
429
+ return !isPassport
430
+ ? 'Please show ID at the center of the screen'
431
+ : 'Please show identity page at the center of the screen';
432
+ case 9:
433
+ return 'Please remove finger blocking document';
434
+ default:
435
+ return '';
436
+ }
437
+ };
438
+ export const getBarcodeValidationStatusMessage = (result) => {
439
+ switch (result) {
440
+ case -1:
441
+ return 'Barcode not detected';
442
+ case 0:
443
+ return 'Success';
444
+ case 3:
445
+ return 'Unsupported barcode detected';
446
+ case 4:
447
+ return 'Unable to parse barcode data';
448
+ default:
449
+ return '';
450
+ }
451
+ };
452
+ // To Deprecate and remove soon
453
+ export const getFrontDocumentStatusMessage = (result) => {
454
+ switch (result) {
455
+ case 0:
456
+ return 'Success';
457
+ case 12:
458
+ return '';
459
+ case -1:
460
+ return 'Please show ID at the center of the screen';
461
+ case 2:
462
+ return 'Please hold still';
463
+ case 18:
464
+ return 'Please show front of the ID';
465
+ case 3:
466
+ return 'Please hold still';
467
+ case 4:
468
+ return 'Move just a little closer';
469
+ case 9:
470
+ return 'Please remove finger blocking document';
471
+ case -2:
472
+ return 'SYSTEM ERROR. Please try again later.';
473
+ case 5:
474
+ case 6:
475
+ case 7:
476
+ case 8:
477
+ return 'Please show ID at the center of the screen';
478
+ case -100:
479
+ return 'Please show front of the ID';
480
+ default:
481
+ return '';
482
+ }
483
+ };
484
+ // To Deprecate and remove soon
485
+ export const getPassporttStatusMessage = (result) => {
486
+ switch (result) {
487
+ case 0:
488
+ return 'Success';
489
+ case 12:
490
+ return '';
491
+ case -1:
492
+ return 'Please show identity page at the center of the screen';
493
+ case 3:
494
+ return 'Please hold still';
495
+ case 4:
496
+ return 'Move just a little closer';
497
+ case 9:
498
+ return 'Please remove finger blocking document';
499
+ case -2:
500
+ return 'SYSTEM ERROR. Please try again later.';
501
+ case 5:
502
+ case 6:
503
+ case 7:
504
+ case 8:
505
+ return 'Please show identity page at the center of the screen';
506
+ case -100:
507
+ return 'Please show identity page at the center of the screen';
508
+ default:
509
+ return '';
510
+ }
511
+ };
512
+ // To Deprecate and remove soon
513
+ export const getBackDocumentStatusMessage = (result) => {
514
+ switch (result) {
515
+ case 0:
516
+ return 'Success';
517
+ case 12:
518
+ return '';
519
+ case -1:
520
+ return 'Please show ID at the center of the screen';
521
+ case 10:
522
+ return 'Move the barcode closer';
523
+ case 3:
524
+ return 'Please move the barcode closer';
525
+ case 4:
526
+ return 'Move just a little closer';
527
+ case 18:
528
+ return 'Please show barcode in the box';
529
+ case 9:
530
+ return 'Please remove finger blocking document';
531
+ case -2:
532
+ return 'SYSTEM ERROR. Please try again later.';
533
+ case 5:
534
+ case 6:
535
+ case 7:
536
+ case 8:
537
+ return 'Please show ID at the center of the screen';
538
+ default:
539
+ return '';
540
+ }
541
+ };
542
+ export function getScreenOrientation() {
543
+ if (window.innerHeight > window.innerWidth) {
544
+ return PORTRAIT;
545
+ }
546
+ return LANDSCAPE;
547
+ }
548
+ export function convertPngBase64ToJpegBase64(pngBase64, maxWidth = 800, maxHeight = 800, quality = 0.85) {
549
+ return __awaiter(this, void 0, void 0, function* () {
550
+ return new Promise((resolve, reject) => {
551
+ const img = new Image();
552
+ img.src = pngBase64;
553
+ img.onload = () => {
554
+ const canvas = document.createElement('canvas');
555
+ const ctx = canvas.getContext('2d');
556
+ // Resize logic
557
+ let { width, height } = img;
558
+ const aspectRatio = width / height;
559
+ if (width > maxWidth || height > maxHeight) {
560
+ if (width > height) {
561
+ width = maxWidth;
562
+ height = width / aspectRatio;
563
+ }
564
+ else {
565
+ height = maxHeight;
566
+ width = height * aspectRatio;
567
+ }
568
+ }
569
+ canvas.width = width;
570
+ canvas.height = height;
571
+ // Draw image onto resized canvas
572
+ ctx.drawImage(img, 0, 0, width, height);
573
+ // Convert to JPEG Base64 (with compression)
574
+ const jpegBase64 = canvas.toDataURL('image/jpeg', quality);
575
+ resolve(jpegBase64);
576
+ };
577
+ img.onerror = reject;
578
+ });
579
+ });
580
+ }
581
581
  //# sourceMappingURL=utils.js.map