@kwik-id/sdk-react-native 0.0.0-stage → 0.1.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (269) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +81 -2
  3. package/app.plugin.js +40 -0
  4. package/lib/commonjs/api/api-client.js +213 -0
  5. package/lib/commonjs/api/api-client.js.map +1 -0
  6. package/lib/commonjs/api/api-error.js +29 -0
  7. package/lib/commonjs/api/api-error.js.map +1 -0
  8. package/lib/commonjs/api/index.js +33 -0
  9. package/lib/commonjs/api/index.js.map +1 -0
  10. package/lib/commonjs/api/upload.js +74 -0
  11. package/lib/commonjs/api/upload.js.map +1 -0
  12. package/lib/commonjs/camera/camera-view.js +227 -0
  13. package/lib/commonjs/camera/camera-view.js.map +1 -0
  14. package/lib/commonjs/camera/index.js +20 -0
  15. package/lib/commonjs/camera/index.js.map +1 -0
  16. package/lib/commonjs/camera/photo-capture.js +50 -0
  17. package/lib/commonjs/camera/photo-capture.js.map +1 -0
  18. package/lib/commonjs/crypto/fingerprint.js +43 -0
  19. package/lib/commonjs/crypto/fingerprint.js.map +1 -0
  20. package/lib/commonjs/crypto/hmac.js +150 -0
  21. package/lib/commonjs/crypto/hmac.js.map +1 -0
  22. package/lib/commonjs/crypto/index.js +39 -0
  23. package/lib/commonjs/crypto/index.js.map +1 -0
  24. package/lib/commonjs/crypto/session-manager.js +173 -0
  25. package/lib/commonjs/crypto/session-manager.js.map +1 -0
  26. package/lib/commonjs/i18n/en.js +297 -0
  27. package/lib/commonjs/i18n/en.js.map +1 -0
  28. package/lib/commonjs/i18n/fr.js +294 -0
  29. package/lib/commonjs/i18n/fr.js.map +1 -0
  30. package/lib/commonjs/i18n/index.js +34 -0
  31. package/lib/commonjs/i18n/index.js.map +1 -0
  32. package/lib/commonjs/i18n/locale.js +20 -0
  33. package/lib/commonjs/i18n/locale.js.map +1 -0
  34. package/lib/commonjs/i18n/translator.js +37 -0
  35. package/lib/commonjs/i18n/translator.js.map +1 -0
  36. package/lib/commonjs/index.js +187 -0
  37. package/lib/commonjs/index.js.map +1 -0
  38. package/lib/commonjs/lib/device-detector.js +34 -0
  39. package/lib/commonjs/lib/device-detector.js.map +1 -0
  40. package/lib/commonjs/lib/event-emitter.js +85 -0
  41. package/lib/commonjs/lib/event-emitter.js.map +1 -0
  42. package/lib/commonjs/lib/index.js +63 -0
  43. package/lib/commonjs/lib/index.js.map +1 -0
  44. package/lib/commonjs/lib/kwik-id-rn-sdk.js +156 -0
  45. package/lib/commonjs/lib/kwik-id-rn-sdk.js.map +1 -0
  46. package/lib/commonjs/lib/verification-machine.js +276 -0
  47. package/lib/commonjs/lib/verification-machine.js.map +1 -0
  48. package/lib/commonjs/package.json +1 -0
  49. package/lib/commonjs/types/events.js +6 -0
  50. package/lib/commonjs/types/events.js.map +1 -0
  51. package/lib/commonjs/types/index.js +2 -0
  52. package/lib/commonjs/types/index.js.map +1 -0
  53. package/lib/commonjs/ui/components/KwikIDVerificationModal.js +407 -0
  54. package/lib/commonjs/ui/components/KwikIDVerificationModal.js.map +1 -0
  55. package/lib/commonjs/ui/components/screens.js +338 -0
  56. package/lib/commonjs/ui/components/screens.js.map +1 -0
  57. package/lib/commonjs/ui/context/kwik-id-provider.js +52 -0
  58. package/lib/commonjs/ui/context/kwik-id-provider.js.map +1 -0
  59. package/lib/commonjs/ui/hooks/use-kwik-verification.js +77 -0
  60. package/lib/commonjs/ui/hooks/use-kwik-verification.js.map +1 -0
  61. package/lib/commonjs/ui/index.js +33 -0
  62. package/lib/commonjs/ui/index.js.map +1 -0
  63. package/lib/module/api/api-client.js +208 -0
  64. package/lib/module/api/api-client.js.map +1 -0
  65. package/lib/module/api/api-error.js +24 -0
  66. package/lib/module/api/api-error.js.map +1 -0
  67. package/lib/module/api/index.js +6 -0
  68. package/lib/module/api/index.js.map +1 -0
  69. package/lib/module/api/upload.js +68 -0
  70. package/lib/module/api/upload.js.map +1 -0
  71. package/lib/module/camera/camera-view.js +222 -0
  72. package/lib/module/camera/camera-view.js.map +1 -0
  73. package/lib/module/camera/index.js +5 -0
  74. package/lib/module/camera/index.js.map +1 -0
  75. package/lib/module/camera/photo-capture.js +45 -0
  76. package/lib/module/camera/photo-capture.js.map +1 -0
  77. package/lib/module/crypto/fingerprint.js +37 -0
  78. package/lib/module/crypto/fingerprint.js.map +1 -0
  79. package/lib/module/crypto/hmac.js +143 -0
  80. package/lib/module/crypto/hmac.js.map +1 -0
  81. package/lib/module/crypto/index.js +6 -0
  82. package/lib/module/crypto/index.js.map +1 -0
  83. package/lib/module/crypto/session-manager.js +169 -0
  84. package/lib/module/crypto/session-manager.js.map +1 -0
  85. package/lib/module/i18n/en.js +293 -0
  86. package/lib/module/i18n/en.js.map +1 -0
  87. package/lib/module/i18n/fr.js +290 -0
  88. package/lib/module/i18n/fr.js.map +1 -0
  89. package/lib/module/i18n/index.js +11 -0
  90. package/lib/module/i18n/index.js.map +1 -0
  91. package/lib/module/i18n/locale.js +15 -0
  92. package/lib/module/i18n/locale.js.map +1 -0
  93. package/lib/module/i18n/translator.js +34 -0
  94. package/lib/module/i18n/translator.js.map +1 -0
  95. package/lib/module/index.js +30 -0
  96. package/lib/module/index.js.map +1 -0
  97. package/lib/module/lib/device-detector.js +26 -0
  98. package/lib/module/lib/device-detector.js.map +1 -0
  99. package/lib/module/lib/event-emitter.js +80 -0
  100. package/lib/module/lib/event-emitter.js.map +1 -0
  101. package/lib/module/lib/index.js +6 -0
  102. package/lib/module/lib/index.js.map +1 -0
  103. package/lib/module/lib/kwik-id-rn-sdk.js +150 -0
  104. package/lib/module/lib/kwik-id-rn-sdk.js.map +1 -0
  105. package/lib/module/lib/verification-machine.js +268 -0
  106. package/lib/module/lib/verification-machine.js.map +1 -0
  107. package/lib/module/package.json +1 -0
  108. package/lib/module/types/events.js +4 -0
  109. package/lib/module/types/events.js.map +1 -0
  110. package/lib/module/types/index.js +2 -0
  111. package/lib/module/types/index.js.map +1 -0
  112. package/lib/module/ui/components/KwikIDVerificationModal.js +402 -0
  113. package/lib/module/ui/components/KwikIDVerificationModal.js.map +1 -0
  114. package/lib/module/ui/components/screens.js +328 -0
  115. package/lib/module/ui/components/screens.js.map +1 -0
  116. package/lib/module/ui/context/kwik-id-provider.js +46 -0
  117. package/lib/module/ui/context/kwik-id-provider.js.map +1 -0
  118. package/lib/module/ui/hooks/use-kwik-verification.js +72 -0
  119. package/lib/module/ui/hooks/use-kwik-verification.js.map +1 -0
  120. package/lib/module/ui/index.js +6 -0
  121. package/lib/module/ui/index.js.map +1 -0
  122. package/lib/typescript/commonjs/api/api-client.d.ts +82 -0
  123. package/lib/typescript/commonjs/api/api-client.d.ts.map +1 -0
  124. package/lib/typescript/commonjs/api/api-error.d.ts +13 -0
  125. package/lib/typescript/commonjs/api/api-error.d.ts.map +1 -0
  126. package/lib/typescript/commonjs/api/index.d.ts +6 -0
  127. package/lib/typescript/commonjs/api/index.d.ts.map +1 -0
  128. package/lib/typescript/commonjs/api/upload.d.ts +19 -0
  129. package/lib/typescript/commonjs/api/upload.d.ts.map +1 -0
  130. package/lib/typescript/commonjs/camera/camera-view.d.ts +25 -0
  131. package/lib/typescript/commonjs/camera/camera-view.d.ts.map +1 -0
  132. package/lib/typescript/commonjs/camera/index.d.ts +5 -0
  133. package/lib/typescript/commonjs/camera/index.d.ts.map +1 -0
  134. package/lib/typescript/commonjs/camera/photo-capture.d.ts +9 -0
  135. package/lib/typescript/commonjs/camera/photo-capture.d.ts.map +1 -0
  136. package/lib/typescript/commonjs/crypto/fingerprint.d.ts +3 -0
  137. package/lib/typescript/commonjs/crypto/fingerprint.d.ts.map +1 -0
  138. package/lib/typescript/commonjs/crypto/hmac.d.ts +18 -0
  139. package/lib/typescript/commonjs/crypto/hmac.d.ts.map +1 -0
  140. package/lib/typescript/commonjs/crypto/index.d.ts +4 -0
  141. package/lib/typescript/commonjs/crypto/index.d.ts.map +1 -0
  142. package/lib/typescript/commonjs/crypto/session-manager.d.ts +27 -0
  143. package/lib/typescript/commonjs/crypto/session-manager.d.ts.map +1 -0
  144. package/lib/typescript/commonjs/i18n/en.d.ts +291 -0
  145. package/lib/typescript/commonjs/i18n/en.d.ts.map +1 -0
  146. package/lib/typescript/commonjs/i18n/fr.d.ts +6 -0
  147. package/lib/typescript/commonjs/i18n/fr.d.ts.map +1 -0
  148. package/lib/typescript/commonjs/i18n/index.d.ts +10 -0
  149. package/lib/typescript/commonjs/i18n/index.d.ts.map +1 -0
  150. package/lib/typescript/commonjs/i18n/locale.d.ts +4 -0
  151. package/lib/typescript/commonjs/i18n/locale.d.ts.map +1 -0
  152. package/lib/typescript/commonjs/i18n/translator.d.ts +15 -0
  153. package/lib/typescript/commonjs/i18n/translator.d.ts.map +1 -0
  154. package/lib/typescript/commonjs/index.d.ts +24 -0
  155. package/lib/typescript/commonjs/index.d.ts.map +1 -0
  156. package/lib/typescript/commonjs/lib/device-detector.d.ts +5 -0
  157. package/lib/typescript/commonjs/lib/device-detector.d.ts.map +1 -0
  158. package/lib/typescript/commonjs/lib/event-emitter.d.ts +19 -0
  159. package/lib/typescript/commonjs/lib/event-emitter.d.ts.map +1 -0
  160. package/lib/typescript/commonjs/lib/index.d.ts +5 -0
  161. package/lib/typescript/commonjs/lib/index.d.ts.map +1 -0
  162. package/lib/typescript/commonjs/lib/kwik-id-rn-sdk.d.ts +43 -0
  163. package/lib/typescript/commonjs/lib/kwik-id-rn-sdk.d.ts.map +1 -0
  164. package/lib/typescript/commonjs/lib/verification-machine.d.ts +78 -0
  165. package/lib/typescript/commonjs/lib/verification-machine.d.ts.map +1 -0
  166. package/lib/typescript/commonjs/package.json +1 -0
  167. package/lib/typescript/commonjs/types/events.d.ts +94 -0
  168. package/lib/typescript/commonjs/types/events.d.ts.map +1 -0
  169. package/lib/typescript/commonjs/types/index.d.ts +242 -0
  170. package/lib/typescript/commonjs/types/index.d.ts.map +1 -0
  171. package/lib/typescript/commonjs/ui/components/KwikIDVerificationModal.d.ts +21 -0
  172. package/lib/typescript/commonjs/ui/components/KwikIDVerificationModal.d.ts.map +1 -0
  173. package/lib/typescript/commonjs/ui/components/screens.d.ts +46 -0
  174. package/lib/typescript/commonjs/ui/components/screens.d.ts.map +1 -0
  175. package/lib/typescript/commonjs/ui/context/kwik-id-provider.d.ts +19 -0
  176. package/lib/typescript/commonjs/ui/context/kwik-id-provider.d.ts.map +1 -0
  177. package/lib/typescript/commonjs/ui/hooks/use-kwik-verification.d.ts +29 -0
  178. package/lib/typescript/commonjs/ui/hooks/use-kwik-verification.d.ts.map +1 -0
  179. package/lib/typescript/commonjs/ui/index.d.ts +7 -0
  180. package/lib/typescript/commonjs/ui/index.d.ts.map +1 -0
  181. package/lib/typescript/module/api/api-client.d.ts +82 -0
  182. package/lib/typescript/module/api/api-client.d.ts.map +1 -0
  183. package/lib/typescript/module/api/api-error.d.ts +13 -0
  184. package/lib/typescript/module/api/api-error.d.ts.map +1 -0
  185. package/lib/typescript/module/api/index.d.ts +6 -0
  186. package/lib/typescript/module/api/index.d.ts.map +1 -0
  187. package/lib/typescript/module/api/upload.d.ts +19 -0
  188. package/lib/typescript/module/api/upload.d.ts.map +1 -0
  189. package/lib/typescript/module/camera/camera-view.d.ts +25 -0
  190. package/lib/typescript/module/camera/camera-view.d.ts.map +1 -0
  191. package/lib/typescript/module/camera/index.d.ts +5 -0
  192. package/lib/typescript/module/camera/index.d.ts.map +1 -0
  193. package/lib/typescript/module/camera/photo-capture.d.ts +9 -0
  194. package/lib/typescript/module/camera/photo-capture.d.ts.map +1 -0
  195. package/lib/typescript/module/crypto/fingerprint.d.ts +3 -0
  196. package/lib/typescript/module/crypto/fingerprint.d.ts.map +1 -0
  197. package/lib/typescript/module/crypto/hmac.d.ts +18 -0
  198. package/lib/typescript/module/crypto/hmac.d.ts.map +1 -0
  199. package/lib/typescript/module/crypto/index.d.ts +4 -0
  200. package/lib/typescript/module/crypto/index.d.ts.map +1 -0
  201. package/lib/typescript/module/crypto/session-manager.d.ts +27 -0
  202. package/lib/typescript/module/crypto/session-manager.d.ts.map +1 -0
  203. package/lib/typescript/module/i18n/en.d.ts +291 -0
  204. package/lib/typescript/module/i18n/en.d.ts.map +1 -0
  205. package/lib/typescript/module/i18n/fr.d.ts +6 -0
  206. package/lib/typescript/module/i18n/fr.d.ts.map +1 -0
  207. package/lib/typescript/module/i18n/index.d.ts +10 -0
  208. package/lib/typescript/module/i18n/index.d.ts.map +1 -0
  209. package/lib/typescript/module/i18n/locale.d.ts +4 -0
  210. package/lib/typescript/module/i18n/locale.d.ts.map +1 -0
  211. package/lib/typescript/module/i18n/translator.d.ts +15 -0
  212. package/lib/typescript/module/i18n/translator.d.ts.map +1 -0
  213. package/lib/typescript/module/index.d.ts +24 -0
  214. package/lib/typescript/module/index.d.ts.map +1 -0
  215. package/lib/typescript/module/lib/device-detector.d.ts +5 -0
  216. package/lib/typescript/module/lib/device-detector.d.ts.map +1 -0
  217. package/lib/typescript/module/lib/event-emitter.d.ts +19 -0
  218. package/lib/typescript/module/lib/event-emitter.d.ts.map +1 -0
  219. package/lib/typescript/module/lib/index.d.ts +5 -0
  220. package/lib/typescript/module/lib/index.d.ts.map +1 -0
  221. package/lib/typescript/module/lib/kwik-id-rn-sdk.d.ts +43 -0
  222. package/lib/typescript/module/lib/kwik-id-rn-sdk.d.ts.map +1 -0
  223. package/lib/typescript/module/lib/verification-machine.d.ts +78 -0
  224. package/lib/typescript/module/lib/verification-machine.d.ts.map +1 -0
  225. package/lib/typescript/module/package.json +1 -0
  226. package/lib/typescript/module/types/events.d.ts +94 -0
  227. package/lib/typescript/module/types/events.d.ts.map +1 -0
  228. package/lib/typescript/module/types/index.d.ts +242 -0
  229. package/lib/typescript/module/types/index.d.ts.map +1 -0
  230. package/lib/typescript/module/ui/components/KwikIDVerificationModal.d.ts +21 -0
  231. package/lib/typescript/module/ui/components/KwikIDVerificationModal.d.ts.map +1 -0
  232. package/lib/typescript/module/ui/components/screens.d.ts +46 -0
  233. package/lib/typescript/module/ui/components/screens.d.ts.map +1 -0
  234. package/lib/typescript/module/ui/context/kwik-id-provider.d.ts +19 -0
  235. package/lib/typescript/module/ui/context/kwik-id-provider.d.ts.map +1 -0
  236. package/lib/typescript/module/ui/hooks/use-kwik-verification.d.ts +29 -0
  237. package/lib/typescript/module/ui/hooks/use-kwik-verification.d.ts.map +1 -0
  238. package/lib/typescript/module/ui/index.d.ts +7 -0
  239. package/lib/typescript/module/ui/index.d.ts.map +1 -0
  240. package/package.json +121 -3
  241. package/src/api/api-client.ts +319 -0
  242. package/src/api/api-error.ts +28 -0
  243. package/src/api/index.ts +12 -0
  244. package/src/api/upload.ts +87 -0
  245. package/src/camera/camera-view.tsx +217 -0
  246. package/src/camera/index.ts +4 -0
  247. package/src/camera/photo-capture.ts +58 -0
  248. package/src/crypto/fingerprint.ts +46 -0
  249. package/src/crypto/hmac.ts +172 -0
  250. package/src/crypto/index.ts +3 -0
  251. package/src/crypto/session-manager.ts +200 -0
  252. package/src/i18n/en.ts +315 -0
  253. package/src/i18n/fr.ts +325 -0
  254. package/src/i18n/index.ts +9 -0
  255. package/src/i18n/locale.ts +15 -0
  256. package/src/i18n/translator.ts +37 -0
  257. package/src/index.ts +102 -0
  258. package/src/lib/device-detector.ts +32 -0
  259. package/src/lib/event-emitter.ts +90 -0
  260. package/src/lib/index.ts +15 -0
  261. package/src/lib/kwik-id-rn-sdk.ts +160 -0
  262. package/src/lib/verification-machine.ts +273 -0
  263. package/src/types/events.ts +75 -0
  264. package/src/types/index.ts +309 -0
  265. package/src/ui/components/KwikIDVerificationModal.tsx +450 -0
  266. package/src/ui/components/screens.tsx +283 -0
  267. package/src/ui/context/kwik-id-provider.tsx +72 -0
  268. package/src/ui/hooks/use-kwik-verification.ts +121 -0
  269. package/src/ui/index.ts +9 -0
@@ -0,0 +1,208 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * RN API client for the KwikId SDK gateway (`/sdk/v1/*`).
5
+ *
6
+ * Ported from @kwik-id/sdk-core: the JSON `request()` (fetch + AbortController) is
7
+ * unchanged; the XMLHttpRequest upload is replaced with an injectable multipart
8
+ * uploader (expo-file-system by default). `liveness_frame` has no server endpoint
9
+ * and is rejected.
10
+ */
11
+
12
+ import { ApiError } from "./api-error.js";
13
+ import { uploadMultipart } from "./upload.js";
14
+ export const DEFAULT_BASE_URL = "https://api.identity.kwiknkap.com";
15
+ const CAPTURE_PATH = {
16
+ document_front: "front",
17
+ document_back: "back",
18
+ selfie: "selfie",
19
+ liveness_frame: null // no server endpoint — liveness evidence rides in /submit
20
+ };
21
+ export class ApiClient {
22
+ constructor(sessionManager, config) {
23
+ this.config = {
24
+ baseUrl: DEFAULT_BASE_URL,
25
+ timeout: 30000,
26
+ debug: false,
27
+ ...config
28
+ };
29
+ this.sessionManager = sessionManager;
30
+ this.uploader = config?.uploader ?? uploadMultipart;
31
+ }
32
+ async validateSession(clientSecret) {
33
+ await this.sessionManager.initializeFromClientSecret(clientSecret);
34
+ const response = await this.request("GET", "/sdk/v1/session");
35
+ this.sessionManager.updateSession({
36
+ expiresAt: new Date(response.expiresAt)
37
+ });
38
+ return response;
39
+ }
40
+ async uploadCapture(type, asset, onProgress) {
41
+ const path = CAPTURE_PATH[type];
42
+ if (!path) {
43
+ throw new Error(`Unsupported capture type for upload: ${type}`);
44
+ }
45
+ const url = `${this.config.baseUrl}/sdk/v1/upload/${path}`;
46
+ const headers = this.sessionManager.getRequestHeaders();
47
+ return this.uploader({
48
+ url,
49
+ asset,
50
+ headers,
51
+ onProgress,
52
+ timeoutMs: this.config.timeout
53
+ });
54
+ }
55
+ async submitVerification(documentType, clientAnalysis) {
56
+ const payload = await this.sessionManager.createSecurePayload({
57
+ documentType,
58
+ clientAnalysis,
59
+ submittedAt: Date.now()
60
+ });
61
+ return this.request("POST", "/sdk/v1/submit", payload);
62
+ }
63
+ async getStatus() {
64
+ return this.request("GET", "/sdk/v1/status");
65
+ }
66
+ async getResult() {
67
+ return this.request("GET", "/sdk/v1/result");
68
+ }
69
+ async pollForResult(options = {}) {
70
+ const {
71
+ maxAttempts = 60,
72
+ intervalMs = 2000,
73
+ onProgress
74
+ } = options;
75
+ let attempts = 0;
76
+ while (attempts < maxAttempts) {
77
+ const status = await this.getStatus();
78
+ onProgress?.(status);
79
+ if (status.status === "verified") {
80
+ return this.getResult();
81
+ }
82
+ if (status.status === "rejected") {
83
+ const result = await this.getResult();
84
+ const contextualError = status.errorDetails ? `${status.errorDetails.document === "front" ? "Front" : "Back"} document: ${status.errorDetails.errorMessage}` : undefined;
85
+ return {
86
+ ...result,
87
+ status: "rejected",
88
+ errorDetails: status.errorDetails,
89
+ rejectionReasons: [contextualError || status.errorMessage || "Verification rejected"]
90
+ };
91
+ }
92
+ if (status.status === "failed") {
93
+ // A failed job may have no result record, so fall back to a minimal one.
94
+ const result = await this.getResult().catch(() => ({
95
+ jobId: status.jobId,
96
+ status: "rejected",
97
+ overallScore: 0,
98
+ scores: {
99
+ documentQuality: 0,
100
+ documentAuthenticity: 0,
101
+ faceMatch: 0,
102
+ liveness: 0
103
+ },
104
+ timestamps: {
105
+ submitted: ""
106
+ },
107
+ referenceId: ""
108
+ }));
109
+ return {
110
+ ...result,
111
+ // VerificationResult has no "failed" status (it mirrors sdk-core).
112
+ status: "rejected",
113
+ errorDetails: status.errorDetails,
114
+ rejectionReasons: [status.errorDetails?.errorMessage || status.errorMessage || "Verification failed"]
115
+ };
116
+ }
117
+ attempts++;
118
+ await this.delay(intervalMs);
119
+ }
120
+ throw new Error("Verification timeout");
121
+ }
122
+
123
+ // ---- Handoff (mobile redeemer) ----
124
+
125
+ async validateHandoff(code) {
126
+ const url = `${this.config.baseUrl}/sdk/v1/handoff/${encodeURIComponent(code)}`;
127
+ const fetchFn = this.config.fetch || fetch;
128
+ const response = await fetchFn(url);
129
+ if (!response.ok) {
130
+ return {
131
+ valid: false,
132
+ error: `Validation failed: ${response.status}`
133
+ };
134
+ }
135
+ return await response.json();
136
+ }
137
+ async redeemHandoff(code) {
138
+ const url = `${this.config.baseUrl}/sdk/v1/handoff/${encodeURIComponent(code)}/redeem`;
139
+ const fetchFn = this.config.fetch || fetch;
140
+ const response = await fetchFn(url, {
141
+ method: "POST",
142
+ headers: {
143
+ "Content-Type": "application/json"
144
+ }
145
+ });
146
+ if (!response.ok) {
147
+ const error = await response.json().catch(() => ({}));
148
+ throw new ApiError(error.message || `Redeem failed: ${response.status}`, response.status);
149
+ }
150
+ return await response.json();
151
+ }
152
+ async reportHandoffStatus(code, status) {
153
+ await this.request("POST", `/sdk/v1/handoff/${encodeURIComponent(code)}/status`, {
154
+ status
155
+ });
156
+ }
157
+ getBaseUrl() {
158
+ return this.config.baseUrl;
159
+ }
160
+ async request(method, path, body) {
161
+ const url = `${this.config.baseUrl}${path}`;
162
+ const controller = new AbortController();
163
+ const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
164
+ try {
165
+ const headers = {
166
+ "Content-Type": "application/json",
167
+ ...this.sessionManager.getRequestHeaders()
168
+ };
169
+ const fetchFn = this.config.fetch || fetch;
170
+ const response = await fetchFn(url, {
171
+ method,
172
+ headers,
173
+ body: body ? JSON.stringify(body) : undefined,
174
+ signal: controller.signal
175
+ });
176
+ clearTimeout(timeoutId);
177
+ if (!response.ok) {
178
+ throw await this.parseErrorResponse(response);
179
+ }
180
+ const data = await response.json();
181
+ if (this.config.debug) {
182
+ console.log(`[KwikID API] ${method} ${path}`, {
183
+ body,
184
+ response: data
185
+ });
186
+ }
187
+ return data;
188
+ } catch (error) {
189
+ clearTimeout(timeoutId);
190
+ if (error instanceof Error && error.name === "AbortError") {
191
+ throw new Error("Request timeout");
192
+ }
193
+ throw error;
194
+ }
195
+ }
196
+ async parseErrorResponse(response) {
197
+ try {
198
+ const data = await response.json();
199
+ return new ApiError(data.message || `API error: ${response.status}`, response.status, data.code, data.details);
200
+ } catch {
201
+ return new ApiError(`API error: ${response.status}`, response.status);
202
+ }
203
+ }
204
+ delay(ms) {
205
+ return new Promise(resolve => setTimeout(resolve, ms));
206
+ }
207
+ }
208
+ //# sourceMappingURL=api-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["ApiError","uploadMultipart","DEFAULT_BASE_URL","CAPTURE_PATH","document_front","document_back","selfie","liveness_frame","ApiClient","constructor","sessionManager","config","baseUrl","timeout","debug","uploader","validateSession","clientSecret","initializeFromClientSecret","response","request","updateSession","expiresAt","Date","uploadCapture","type","asset","onProgress","path","Error","url","headers","getRequestHeaders","timeoutMs","submitVerification","documentType","clientAnalysis","payload","createSecurePayload","submittedAt","now","getStatus","getResult","pollForResult","options","maxAttempts","intervalMs","attempts","status","result","contextualError","errorDetails","document","errorMessage","undefined","rejectionReasons","catch","jobId","overallScore","scores","documentQuality","documentAuthenticity","faceMatch","liveness","timestamps","submitted","referenceId","delay","validateHandoff","code","encodeURIComponent","fetchFn","fetch","ok","valid","error","json","redeemHandoff","method","message","reportHandoffStatus","getBaseUrl","body","controller","AbortController","timeoutId","setTimeout","abort","JSON","stringify","signal","clearTimeout","parseErrorResponse","data","console","log","name","details","ms","Promise","resolve"],"sourceRoot":"../../../src","sources":["api/api-client.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAWA,SAASA,QAAQ,QAAQ,gBAAa;AACtC,SAAwBC,eAAe,QAAQ,aAAU;AAEzD,OAAO,MAAMC,gBAAgB,GAAG,mCAAmC;AAmDnE,MAAMC,YAAgD,GAAG;EACrDC,cAAc,EAAE,OAAO;EACvBC,aAAa,EAAE,MAAM;EACrBC,MAAM,EAAE,QAAQ;EAChBC,cAAc,EAAE,IAAI,CAAE;AAC1B,CAAC;AAED,OAAO,MAAMC,SAAS,CAAC;EAKnBC,WAAWA,CAACC,cAA8B,EAAEC,MAAiC,EAAE;IAC3E,IAAI,CAACA,MAAM,GAAG;MACVC,OAAO,EAAEV,gBAAgB;MACzBW,OAAO,EAAE,KAAK;MACdC,KAAK,EAAE,KAAK;MACZ,GAAGH;IACP,CAAC;IACD,IAAI,CAACD,cAAc,GAAGA,cAAc;IACpC,IA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AAI,CAAC,CAIjC;MACD,OAAO,IAAI5E,QAAQ,CACf6F,IAAI,CAACd,OAAO,IAAI,cAAc5D,QAAQ,CAAC6B,MAAM,EAAE,EAC/C7B,QAAQ,CAAC6B,MAAM,EACf6C,IAAI,CAACxB,IAAI,EACTwB,IAAI,CAACI,OACT,CAAC;IACL,CAAC,CAAC,MAAM;MACJ,OAAO,IAAIjG,QAAQ,CAAC,cAAcmB,QAAQ,CAAC6B,MAAM,EAAE,EAAE7B,QAAQ,CAAC6B,MAAM,CAAC;IACzE;EACJ;EAEQmB,KAAKA,CAAC+B,EAAU,EAAiB;IACrC,OAAO,IAAIC,OAAO,CAAEC,OAAO,IAAKd,UAAU,CAACc,OAAO,EAAEF,EAAE,CAAC,CAAC;EAC5D;AACJ","ignoreList":[]}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * API error (ported verbatim from @kwik-id/sdk-core).
5
+ */
6
+ export class ApiError extends Error {
7
+ constructor(message, statusCode, code, details) {
8
+ super(message);
9
+ this.name = "ApiError";
10
+ this.statusCode = statusCode;
11
+ this.code = code;
12
+ this.details = details;
13
+ }
14
+ isRetryable() {
15
+ return this.statusCode >= 500 || this.statusCode === 429;
16
+ }
17
+ isAuthError() {
18
+ return this.statusCode === 401 || this.statusCode === 403;
19
+ }
20
+ isValidationError() {
21
+ return this.statusCode === 400 || this.statusCode === 422;
22
+ }
23
+ }
24
+ //# sourceMappingURL=api-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["ApiError","Error","constructor","message","statusCode","code","details","name","isRetryable","isAuthError","isValidationError"],"sourceRoot":"../../../src","sources":["api/api-error.ts"],"mappings":";;AAAA;AACA;AACA;AACA,OAAO,MAAMA,QAAQ,SAASC,KAAK,CAAC;EAKhCC,WAAWA,CAACC,OAAe,EAAEC,UAAkB,EAAEC,IAAa,EAAEC,OAAiB,EAAE;IAC/E,KAAK,CAACH,OAAO,CAAC;IACd,IAAI,CAACI,IAAI,GAAG,UAAU;IACtB,IAAI,CAACH,UAAU,GAAGA,UAAU;IAC5B,IAAI,CAACC,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACC,OAAO,GAAGA,OAAO;EAC1B;EAEAE,WAAWA,CAAA,EAAY;IACnB,OAAO,IAAI,CAACJ,UAAU,IAAI,GAAG,IAAI,IAAI,CAACA,UAAU,KAAK,GAAG;EAC5D;EAEAK,WAAWA,CAAA,EAAY;IACnB,OAAO,IAAI,CAACL,UAAU,KAAK,GAAG,IAAI,IAAI,CAACA,UAAU,KAAK,GAAG;EAC7D;EAEAM,iBAAiBA,CAAA,EAAY;IACzB,OAAO,IAAI,CAACN,UAAU,KAAK,GAAG,IAAI,IAAI,CAACA,UAAU,KAAK,GAAG;EAC7D;AACJ","ignoreList":[]}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ export { ApiClient, DEFAULT_BASE_URL } from "./api-client.js";
4
+ export { ApiError } from "./api-error.js";
5
+ export { uploadMultipart } from "./upload.js";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["ApiClient","DEFAULT_BASE_URL","ApiError","uploadMultipart"],"sourceRoot":"../../../src","sources":["api/index.ts"],"mappings":";;AAAA,SAASA,SAAS,EAAEC,gBAAgB,QAAQ,iBAAc;AAS1D,SAASC,QAAQ,QAAQ,gBAAa;AACtC,SAASC,eAAe,QAAQ,aAAU","ignoreList":[]}
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Multipart upload for RN via expo-file-system (gives real upload progress, which
5
+ * RN's fetch/FormData path cannot). The gateway's multer expects the field `file`.
6
+ */
7
+ import { FileSystemUploadType, createUploadTask } from "expo-file-system";
8
+ import { ApiError } from "./api-error.js";
9
+ function parseBody(body) {
10
+ try {
11
+ return JSON.parse(body);
12
+ } catch {
13
+ return {};
14
+ }
15
+ }
16
+
17
+ /** Default uploader — used on device. */
18
+ export const uploadMultipart = async ({
19
+ url,
20
+ asset,
21
+ headers,
22
+ onProgress,
23
+ timeoutMs
24
+ }) => {
25
+ let timer;
26
+ let rejectTimeout = () => undefined;
27
+ const timedOut = new Promise((_, reject) => {
28
+ rejectTimeout = reject;
29
+ });
30
+ // Reset on every progress event so a slow-but-moving upload isn't killed.
31
+ const armTimeout = () => {
32
+ if (!timeoutMs) return;
33
+ if (timer) clearTimeout(timer);
34
+ timer = setTimeout(() => {
35
+ task.cancelAsync().catch(() => undefined);
36
+ rejectTimeout(new ApiError("Upload timeout", 0, "UPLOAD_TIMEOUT"));
37
+ }, timeoutMs);
38
+ };
39
+ const task = createUploadTask(url, asset.uri, {
40
+ httpMethod: "POST",
41
+ uploadType: FileSystemUploadType.MULTIPART,
42
+ fieldName: "file",
43
+ mimeType: asset.type,
44
+ headers
45
+ }, p => {
46
+ armTimeout();
47
+ if (p.totalBytesExpectedToSend > 0) {
48
+ onProgress?.(p.totalBytesSent / p.totalBytesExpectedToSend * 100);
49
+ }
50
+ });
51
+ armTimeout();
52
+ let res;
53
+ try {
54
+ res = await Promise.race([task.uploadAsync(), timedOut]);
55
+ } finally {
56
+ if (timer) clearTimeout(timer);
57
+ }
58
+ if (!res || res.status < 200 || res.status >= 300) {
59
+ const parsed = res ? parseBody(res.body) : {};
60
+ throw new ApiError(parsed.message || `Upload failed with status ${res?.status ?? 0}`, res?.status ?? 0);
61
+ }
62
+ const parsed = parseBody(res.body);
63
+ return {
64
+ uploadId: parsed.uploadId || "",
65
+ status: parsed.status || "uploaded"
66
+ };
67
+ };
68
+ //# sourceMappingURL=upload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["FileSystemUploadType","createUploadTask","ApiError","parseBody","body","JSON","parse","uploadMultipart","url","asset","headers","onProgress","timeoutMs","timer","rejectTimeout","undefined","timedOut","Promise","_","reject","armTimeout","clearTimeout","setTimeout","task","cancelAsync","catch","uri","httpMethod","uploadType","MULTIPART","fieldName","mimeType","type","p","totalBytesExpectedToSend","totalBytesSent","res","race","uploadAsync","status","parsed","message","uploadId"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CAAC,EACAuB,CAAC,IAAK;IACHb,UAAU,CAAC,CAAC;IACZ,IAAIa,CAAC,CAACC,wBAAwB,GAAG,CAAC,EAAE;MAChCvB,UAAU,GAAIsB,CAAC,CAACE,cAAc,GAAGF,CAAC,CAACC,wBAAwB,GAAI,GAAG,CAAC;IACvE;EACJ,CACJ,CAAC;EAEDd,UAAU,CAAC,CAAC;EACZ,IAAIgB,GAAiD;EACrD,IAAI;IACAA,GAAG,GAAG,MAAMnB,OAAO,CAACoB,IAAI,CAAC,CAACd,IAAI,CAACe,WAAW,CAAC,CAAC,EAAEtB,QAAQ,CAAC,CAAC;EAC5D,CAAC,SAAS;IACN,IAAIH,KAAK,EAAEQ,YAAY,CAACR,KAAK,CAAC;EAClC;EACA,IAAI,CAACuB,GAAG,IAAIA,GAAG,CAACG,MAAM,GAAG,GAAG,IAAIH,GAAG,CAACG,MAAM,IAAI,GAAG,EAAE;IAC/C,MAAMC,MAAM,GAAGJ,GAAG,GAAGjC,SAAS,CAACiC,GAAG,CAAChC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC7C,MAAM,IAAIF,QAAQ,CACdsC,MAAM,CAACC,OAAO,IAAI,6BAA6BL,GAAG,EAAEG,MAAM,IAAI,CAAC,EAAE,EACjEH,GAAG,EAAEG,MAAM,IAAI,CACnB,CAAC;EACL;EAEA,MAAMC,MAAM,GAAGrC,SAAS,CAACiC,GAAG,CAAChC,IAAI,CAAC;EAClC,OAAO;IAAEsC,QAAQ,EAAEF,MAAM,CAACE,QAAQ,IAAI,EAAE;IAAEH,MAAM,EAAEC,MAAM,CAACD,MAAM,IAAI;EAAW,CAAC;AACnF,CAAC","ignoreList":[]}
@@ -0,0 +1,222 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * CameraView — vision-camera wrapper for still capture (Phase 1).
5
+ *
6
+ * Phase 1 is capture-only, so this uses `takePhoto` and does NOT run a frame
7
+ * processor (that lands in Phase 2 for liveness). Handles permission + device
8
+ * selection and reports a RawPhoto to the caller.
9
+ *
10
+ * vision-camera is required lazily: its NativeCameraModule throws at import time
11
+ * when the native module is missing (e.g. Expo Go), which would crash any import of
12
+ * this SDK before KwikIdRNSDK.initialize() can report a friendly runtime error.
13
+ */
14
+ import { useEffect, useRef, useState } from "react";
15
+ import { ActivityIndicator, Linking, Pressable, StyleSheet, Text, View } from "react-native";
16
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
17
+ let visionCamera;
18
+ function loadVisionCamera() {
19
+ visionCamera ??= require("react-native-vision-camera");
20
+ return visionCamera;
21
+ }
22
+ export function CameraView({
23
+ facing,
24
+ active,
25
+ primaryColor,
26
+ overlay,
27
+ instruction,
28
+ captureErrorText = "Could not capture the photo. Please try again.",
29
+ permissionTitle = "Camera access needed",
30
+ permissionBody = "Enable camera access in Settings to continue verification.",
31
+ openSettingsLabel = "Open Settings",
32
+ captureLabel = "Capture photo",
33
+ onCapture,
34
+ onPermissionDenied
35
+ }) {
36
+ const {
37
+ Camera,
38
+ useCameraDevice,
39
+ useCameraPermission
40
+ } = loadVisionCamera();
41
+ const camera = useRef(null);
42
+ const device = useCameraDevice(facing);
43
+ const {
44
+ hasPermission,
45
+ requestPermission
46
+ } = useCameraPermission();
47
+ const [capturing, setCapturing] = useState(false);
48
+ const [permissionChecked, setPermissionChecked] = useState(false);
49
+ const [captureFailed, setCaptureFailed] = useState(false);
50
+ useEffect(() => {
51
+ let cancelled = false;
52
+ (async () => {
53
+ if (!hasPermission) {
54
+ const granted = await requestPermission();
55
+ if (!cancelled && !granted) {
56
+ onPermissionDenied?.(false);
57
+ }
58
+ }
59
+ if (!cancelled) setPermissionChecked(true);
60
+ })();
61
+ return () => {
62
+ cancelled = true;
63
+ };
64
+ }, [hasPermission, requestPermission, onPermissionDenied]);
65
+ const takePhoto = async () => {
66
+ if (!camera.current || capturing) return;
67
+ setCapturing(true);
68
+ setCaptureFailed(false);
69
+ try {
70
+ const photo = await camera.current.takePhoto({
71
+ flash: "off"
72
+ });
73
+ await onCapture({
74
+ path: photo.path,
75
+ width: photo.width,
76
+ height: photo.height
77
+ });
78
+ } catch {
79
+ setCaptureFailed(true);
80
+ } finally {
81
+ setCapturing(false);
82
+ }
83
+ };
84
+ if (!hasPermission && permissionChecked) {
85
+ return /*#__PURE__*/_jsxs(View, {
86
+ style: styles.center,
87
+ children: [/*#__PURE__*/_jsx(Text, {
88
+ style: styles.permTitle,
89
+ children: permissionTitle
90
+ }), /*#__PURE__*/_jsx(Text, {
91
+ style: styles.permBody,
92
+ children: permissionBody
93
+ }), /*#__PURE__*/_jsx(Pressable, {
94
+ style: [styles.settingsBtn, {
95
+ borderColor: primaryColor
96
+ }],
97
+ onPress: () => Linking.openSettings(),
98
+ children: /*#__PURE__*/_jsx(Text, {
99
+ style: [styles.settingsText, {
100
+ color: primaryColor
101
+ }],
102
+ children: openSettingsLabel
103
+ })
104
+ })]
105
+ });
106
+ }
107
+ if (!device || !permissionChecked) {
108
+ return /*#__PURE__*/_jsx(View, {
109
+ style: styles.center,
110
+ children: /*#__PURE__*/_jsx(ActivityIndicator, {
111
+ color: primaryColor
112
+ })
113
+ });
114
+ }
115
+ return /*#__PURE__*/_jsxs(View, {
116
+ style: styles.fill,
117
+ children: [/*#__PURE__*/_jsx(Camera, {
118
+ ref: camera,
119
+ style: StyleSheet.absoluteFill,
120
+ device: device,
121
+ isActive: active,
122
+ photo: true
123
+ }), overlay, /*#__PURE__*/_jsxs(View, {
124
+ style: styles.bottomBar,
125
+ children: [captureFailed ? /*#__PURE__*/_jsx(Text, {
126
+ accessibilityRole: "alert",
127
+ style: [styles.instruction, styles.captureError],
128
+ children: captureErrorText
129
+ }) : instruction ? /*#__PURE__*/_jsx(Text, {
130
+ style: styles.instruction,
131
+ children: instruction
132
+ }) : null, /*#__PURE__*/_jsx(Pressable, {
133
+ accessibilityLabel: captureLabel,
134
+ style: styles.shutterOuter,
135
+ onPress: takePhoto,
136
+ disabled: capturing,
137
+ children: /*#__PURE__*/_jsx(View, {
138
+ style: [styles.shutterInner, capturing && styles.shutterBusy],
139
+ children: capturing ? /*#__PURE__*/_jsx(ActivityIndicator, {
140
+ color: "#fff"
141
+ }) : null
142
+ })
143
+ })]
144
+ })]
145
+ });
146
+ }
147
+ const styles = StyleSheet.create({
148
+ fill: {
149
+ flex: 1,
150
+ backgroundColor: "#000"
151
+ },
152
+ center: {
153
+ flex: 1,
154
+ alignItems: "center",
155
+ justifyContent: "center",
156
+ padding: 24,
157
+ backgroundColor: "#000"
158
+ },
159
+ bottomBar: {
160
+ position: "absolute",
161
+ bottom: 0,
162
+ left: 0,
163
+ right: 0,
164
+ alignItems: "center",
165
+ paddingBottom: 40
166
+ },
167
+ instruction: {
168
+ color: "#fff",
169
+ fontSize: 15,
170
+ marginBottom: 16,
171
+ textAlign: "center",
172
+ paddingHorizontal: 24
173
+ },
174
+ captureError: {
175
+ color: "#fca5a5",
176
+ fontWeight: "600"
177
+ },
178
+ shutterOuter: {
179
+ width: 76,
180
+ height: 76,
181
+ borderRadius: 38,
182
+ borderWidth: 4,
183
+ borderColor: "#fff",
184
+ alignItems: "center",
185
+ justifyContent: "center"
186
+ },
187
+ shutterInner: {
188
+ width: 58,
189
+ height: 58,
190
+ borderRadius: 29,
191
+ backgroundColor: "#fff",
192
+ alignItems: "center",
193
+ justifyContent: "center"
194
+ },
195
+ shutterBusy: {
196
+ backgroundColor: "#1E3A8A"
197
+ },
198
+ permTitle: {
199
+ color: "#fff",
200
+ fontSize: 18,
201
+ fontWeight: "600",
202
+ marginBottom: 8,
203
+ textAlign: "center"
204
+ },
205
+ permBody: {
206
+ color: "#ccc",
207
+ fontSize: 14,
208
+ textAlign: "center",
209
+ marginBottom: 20
210
+ },
211
+ settingsBtn: {
212
+ borderWidth: 1.5,
213
+ borderRadius: 10,
214
+ paddingVertical: 12,
215
+ paddingHorizontal: 24
216
+ },
217
+ settingsText: {
218
+ fontSize: 15,
219
+ fontWeight: "600"
220
+ }
221
+ });
222
+ //# sourceMappingURL=camera-view.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useEffect","useRef","useState","ActivityIndicator","Linking","Pressable","StyleSheet","Text","View","jsx","_jsx","jsxs","_jsxs","visionCamera","loadVisionCamera","require","CameraView","facing","active","primaryColor","overlay","instruction","captureErrorText","permissionTitle","permissionBody","openSettingsLabel","captureLabel","onCapture","onPermissionDenied","Camera","useCameraDevice","useCameraPermission","camera","device","hasPermission","requestPermission","capturing","setCapturing","permissionChecked","setPermissionChecked","captureFailed","setCaptureFailed","cancelled","granted","takePhoto","current","photo","flash","path","width","height","style","styles","center","children","permTitle","permBody","settingsBtn","borderColor","onPress","openSettings","settingsText","color","fill","ref","absoluteFill","isActive","bottomBar","accessibilityRole","captureError","accessibilityLabel","shutterOuter","disabled","shutterInner","shutterBusy","create","flex","backgroundColor","alignItems","justifyContent","padding","position","bottom","left","right","paddingBottom","fontSize","marginBottom","textAlign","paddingHorizontal","fontWeight","borderRadius","borderWidth","paddingVertical"],"sourceRoot":"../../../src","sources":["camera/camera-view.tsx"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAEnD,SAASC,iBAAiB,EAAEC,OAAO,EAAEC,SAAS,EAAEC,UAAU,EAAEC,IAAI,EAAEC,IAAI,QAAQ,cAAc;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAO7F,IAAIC,YAAsC;AAE1C,SAASC,gBAAgBA,CAAA,EAAiB;EACtCD,YAAY,KAAKE,OAAO,CAAC,4BAA4B,CAAiB;EACtE,OAAOF,YAAY;AACvB;AAyBA,OAAO,SAASG,UAAUA,CAAC;EACvBC,MAAM;EACNC,MAAM;EACNC,YAAY;EACZC,OAAO;EACPC,WAAW;EACXC,gBAAgB,GAAG,gDAAgD;EACnEC,eAAe,GAAG,sBAAsB;EACxCC,cAAc,GAAG,4DAA4D;EAC7EC,iBAAiB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AE,KAAK;IACjBH,YAAY,EAAE,CAAC;IACfC,SAAS,EAAE;EACf,CAAC;EACDhC,QAAQ,EAAE;IAAEM,KAAK,EAAE,MAAM;IAAEwB,QAAQ,EAAE,EAAE;IAAEE,SAAS,EAAE,QAAQ;IAAED,YAAY,EAAE;EAAG,CAAC;EAChF9B,WAAW,EAAE;IAAEmC,WAAW,EAAE,GAAG;IAAED,YAAY,EAAE,EAAE;IAAEE,eAAe,EAAE,EAAE;IAAEJ,iBAAiB,EAAE;EAAG,CAAC;EAC/F5B,YAAY,EAAE;IAAEyB,QAAQ,EAAE,EAAE;IAAEI,UAAU,EAAE;EAAM;AACpD,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ export { CameraView } from "./camera-view.js";
4
+ export { compressCapture } from "./photo-capture.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["CameraView","compressCapture"],"sourceRoot":"../../../src","sources":["camera/index.ts"],"mappings":";;AAAA,SAASA,UAAU,QAAQ,kBAAe;AAE1C,SAASC,eAAe,QAAQ,oBAAiB","ignoreList":[]}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Normalize + compress a captured photo into a CaptureAsset ready for upload.
5
+ *
6
+ * Decoupled from vision-camera: callers pass a plain { path } (the camera hook maps
7
+ * VisionCamera's PhotoFile to this). Keeps the 10 MB server cap in mind by resizing
8
+ * the longest edge and compressing to JPEG.
9
+ */
10
+ import { SaveFormat, manipulateAsync } from "expo-image-manipulator";
11
+ const MAX_EDGE = 1600;
12
+ function toFileUri(path) {
13
+ return path.startsWith("file://") || path.startsWith("content://") ? path : `file://${path}`;
14
+ }
15
+ function fileName(type, ts) {
16
+ const base = type === "document_front" ? "front" : type === "document_back" ? "back" : "selfie";
17
+ return `${base}_${ts}.jpg`;
18
+ }
19
+ export async function compressCapture(type, photo, timestamp) {
20
+ const uri = toFileUri(photo.path);
21
+
22
+ // Resize the longest edge to MAX_EDGE (only downscale) and compress to JPEG.
23
+ const longest = Math.max(photo.width ?? 0, photo.height ?? 0);
24
+ const resize = longest > MAX_EDGE ? (photo.width ?? 0) >= (photo.height ?? 0) ? [{
25
+ resize: {
26
+ width: MAX_EDGE
27
+ }
28
+ }] : [{
29
+ resize: {
30
+ height: MAX_EDGE
31
+ }
32
+ }] : [];
33
+ const result = await manipulateAsync(uri, resize, {
34
+ compress: 0.8,
35
+ format: SaveFormat.JPEG
36
+ });
37
+ return {
38
+ uri: result.uri,
39
+ name: fileName(type, timestamp),
40
+ type: "image/jpeg",
41
+ width: result.width,
42
+ height: result.height
43
+ };
44
+ }
45
+ //# sourceMappingURL=photo-capture.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["SaveFormat","manipulateAsync","MAX_EDGE","toFileUri","path","startsWith","fileName","type","ts","base","compressCapture","photo","timestamp","uri","longest","Math","max","width","height","resize","result","compress","format","JPEG","name"],"sourceRoot":"../../../src","sources":["camera/photo-capture.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,UAAU,EAAEC,eAAe,QAAQ,wBAAwB;AAWpE,MAAMC,QAAQ,GAAG,IAAI;AAErB,SAASC,SAASA,CAACC,IAAY,EAAU;EACrC,OAAOA,IAAI,CAACC,UAAU,CAAC,SAAS,CAAC,IAAID,IAAI,CAACC,UAAU,CAAC,YAAY,CAAC,GAAGD,IAAI,GAAG,UAAUA,IAAI,EAAE;AAChG;AAEA,SAASE,QAAQA,CAACC,IAAiB,EAAEC,EAAU,EAAU;EACrD,MAAMC,IAAI,GAAGF,IAAI,KAAK,gBAAgB,GAAG,OAAO,GAAGA,IAAI,KAAK,eAAe,GAAG,MAAM,GAAG,QAAQ;EAC/F,OAAO,GAAGE,IAAI,IAAID,EAAE,MAAM;AAC9B;AAEA,OAAO,eAAeE,eAAeA,CACjCH,IAAiB,EACjBI,KAAe,EACfC,SAAiB,EACI;EACrB,MAAMC,GAAG,GAA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