vesant-sdk 1.6.6 → 1.7.0-dev.117915b

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 (86) hide show
  1. package/README.md +14 -4
  2. package/dist/client-B0qhE2kr.d.mts +436 -0
  3. package/dist/{client-ePzhQKp9.d.mts → client-BolQlL5e.d.mts} +1 -1
  4. package/dist/{client-ePzhQKp9.d.ts → client-BolQlL5e.d.ts} +1 -1
  5. package/dist/{client-BlCxjbY2.d.mts → client-DF7hlMEz.d.ts} +18 -3
  6. package/dist/{client-C_A7QLcB.d.ts → client-DrjgZoH_.d.mts} +18 -3
  7. package/dist/client-DtH2RLuy.d.ts +436 -0
  8. package/dist/compliance/index.d.mts +25 -429
  9. package/dist/compliance/index.d.ts +25 -429
  10. package/dist/compliance/index.js +186 -105
  11. package/dist/compliance/index.js.map +1 -1
  12. package/dist/compliance/index.mjs +186 -106
  13. package/dist/compliance/index.mjs.map +1 -1
  14. package/dist/decisions/index.d.mts +2 -2
  15. package/dist/decisions/index.d.ts +2 -2
  16. package/dist/decisions/index.js +1 -1
  17. package/dist/decisions/index.js.map +1 -1
  18. package/dist/decisions/index.mjs +1 -1
  19. package/dist/decisions/index.mjs.map +1 -1
  20. package/dist/geolocation/index.d.mts +4 -4
  21. package/dist/geolocation/index.d.ts +4 -4
  22. package/dist/geolocation/index.js +7 -24
  23. package/dist/geolocation/index.js.map +1 -1
  24. package/dist/geolocation/index.mjs +7 -24
  25. package/dist/geolocation/index.mjs.map +1 -1
  26. package/dist/index.d.mts +12 -70
  27. package/dist/index.d.ts +12 -70
  28. package/dist/index.js +305 -299
  29. package/dist/index.js.map +1 -1
  30. package/dist/index.mjs +304 -298
  31. package/dist/index.mjs.map +1 -1
  32. package/dist/kyc/core.d.mts +4 -4
  33. package/dist/kyc/core.d.ts +4 -4
  34. package/dist/kyc/core.js +86 -27
  35. package/dist/kyc/core.js.map +1 -1
  36. package/dist/kyc/core.mjs +86 -28
  37. package/dist/kyc/core.mjs.map +1 -1
  38. package/dist/kyc/index.d.mts +309 -50
  39. package/dist/kyc/index.d.ts +309 -50
  40. package/dist/kyc/index.js +86 -27
  41. package/dist/kyc/index.js.map +1 -1
  42. package/dist/kyc/index.mjs +86 -28
  43. package/dist/kyc/index.mjs.map +1 -1
  44. package/dist/react.d.mts +48 -9
  45. package/dist/react.d.ts +48 -9
  46. package/dist/react.js +930 -276
  47. package/dist/react.js.map +1 -1
  48. package/dist/react.mjs +929 -275
  49. package/dist/react.mjs.map +1 -1
  50. package/dist/risk-profile/index.d.mts +4 -4
  51. package/dist/risk-profile/index.d.ts +4 -4
  52. package/dist/risk-profile/index.js +1 -1
  53. package/dist/risk-profile/index.js.map +1 -1
  54. package/dist/risk-profile/index.mjs +1 -1
  55. package/dist/risk-profile/index.mjs.map +1 -1
  56. package/dist/scores/index.d.mts +2 -2
  57. package/dist/scores/index.d.ts +2 -2
  58. package/dist/scores/index.js +1 -1
  59. package/dist/scores/index.js.map +1 -1
  60. package/dist/scores/index.mjs +1 -1
  61. package/dist/scores/index.mjs.map +1 -1
  62. package/dist/tax/index.d.mts +23 -41
  63. package/dist/tax/index.d.ts +23 -41
  64. package/dist/tax/index.js +5 -37
  65. package/dist/tax/index.js.map +1 -1
  66. package/dist/tax/index.mjs +5 -37
  67. package/dist/tax/index.mjs.map +1 -1
  68. package/dist/{types-1RzYeSal.d.mts → types-BOFaMQxI.d.mts} +2 -2
  69. package/dist/{types-B4Ezqo7V.d.mts → types-CBQRNL-l.d.mts} +14 -1
  70. package/dist/{types-B4Ezqo7V.d.ts → types-CBQRNL-l.d.ts} +14 -1
  71. package/dist/{types-X5Md_dD_.d.ts → types-UGyDl1fd.d.ts} +2 -2
  72. package/dist/webhooks/index.d.mts +189 -2
  73. package/dist/webhooks/index.d.ts +189 -2
  74. package/dist/webhooks/index.js +49 -7
  75. package/dist/webhooks/index.js.map +1 -1
  76. package/dist/webhooks/index.mjs +49 -7
  77. package/dist/webhooks/index.mjs.map +1 -1
  78. package/package.json +16 -13
  79. package/dist/fraud/index.d.mts +0 -80
  80. package/dist/fraud/index.d.ts +0 -80
  81. package/dist/fraud/index.js +0 -606
  82. package/dist/fraud/index.js.map +0 -1
  83. package/dist/fraud/index.mjs +0 -604
  84. package/dist/fraud/index.mjs.map +0 -1
  85. package/dist/index-B04H4xfJ.d.mts +0 -320
  86. package/dist/index-CItMPmLL.d.ts +0 -320
package/dist/react.js CHANGED
@@ -10,7 +10,19 @@ var React__default = /*#__PURE__*/_interopDefault(React);
10
10
  // src/geolocation/hooks.ts
11
11
 
12
12
  // src/core/version.ts
13
- var SDK_VERSION = "1.6.6";
13
+ var SDK_VERSION = "1.7.0";
14
+
15
+ // src/core/errors.ts
16
+ var VesantError = class _VesantError extends Error {
17
+ constructor(message, code, statusCode, details) {
18
+ super(message);
19
+ this.code = code;
20
+ this.statusCode = statusCode;
21
+ this.details = details;
22
+ this.name = "VesantError";
23
+ Object.setPrototypeOf(this, _VesantError.prototype);
24
+ }
25
+ };
14
26
 
15
27
  // src/shared/browser-utils.ts
16
28
  function generateUUID() {
@@ -200,7 +212,7 @@ function encodePayload(payload) {
200
212
  } else if (typeof Buffer !== "undefined") {
201
213
  return Buffer.from(json, "utf-8").toString("base64");
202
214
  }
203
- throw new Error("No base64 encoding method available");
215
+ throw new VesantError("No base64 encoding method available", "BASE64_UNAVAILABLE");
204
216
  }
205
217
  async function generateCipherText(options, config) {
206
218
  const warnings = [];
@@ -225,8 +237,9 @@ async function generateCipherText(options, config) {
225
237
  if (location) {
226
238
  locationData = location;
227
239
  } else if (gpsRequiredByConfig) {
228
- throw new Error(
229
- `GPS location is required for ${options.reason} by tenant configuration, but GPS was not available or permission was denied`
240
+ throw new VesantError(
241
+ `GPS location is required for ${options.reason} by tenant configuration, but GPS was not available or permission was denied`,
242
+ "GPS_REQUIRED"
230
243
  );
231
244
  } else {
232
245
  warnings.push("GPS location not available or permission denied");
@@ -839,7 +852,7 @@ function useCustomerProfile(client, customerId, options = {}) {
839
852
  profileRef.current = profile;
840
853
  const updateProfile = React.useCallback(
841
854
  async (updates) => {
842
- if (!profileRef.current) throw new Error("Profile not loaded");
855
+ if (!profileRef.current) throw new VesantError("Profile not loaded", "PROFILE_NOT_LOADED");
843
856
  setLoading(true);
844
857
  setError(null);
845
858
  try {
@@ -875,280 +888,910 @@ function useCustomerProfile(client, customerId, options = {}) {
875
888
  var Camera = "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCg0KPCFET0NUWVBFIHN2ZyBQVUJMSUMgIi0vL1czQy8vRFREIFNWRyAxLjAvL0VOIiAiaHR0cDovL3d3dy53My5vcmcvVFIvMjAwMS9SRUMtU1ZHLTIwMDEwOTA0L0RURC9zdmcxMC5kdGQiPg0KPCEtLSBVcGxvYWRlZCB0bzogU1ZHIFJlcG8sIHd3dy5zdmdyZXBvLmNvbSwgR2VuZXJhdG9yOiBTVkcgUmVwbyBNaXhlciBUb29scyAtLT4NCjxzdmcgdmVyc2lvbj0iMS4wIiBpZD0iTGF5ZXJfMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgDQoJIHdpZHRoPSI4MDBweCIgaGVpZ2h0PSI4MDBweCIgdmlld0JveD0iMCAwIDY0IDY0IiBlbmFibGUtYmFja2dyb3VuZD0ibmV3IDAgMCA2NCA2NCIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+DQo8Zz4NCgk8cGF0aCBmaWxsPSIjMjMxRjIwIiBkPSJNNjAsMTBINDkuNjU2bC02LjgyOC02LjgyOEM0Mi4wNzgsMi40MjIsNDEuMDYyLDIsNDAsMkgyNGMtMS4wNjIsMC0yLjA3OCwwLjQyMi0yLjgyOCwxLjE3MkwxNC4zNDQsMTBINA0KCQljLTIuMjExLDAtNCwxLjc4OS00LDR2NDRjMCwyLjIxMSwxLjc4OSw0LDQsNGg1NmMyLjIxMSwwLDQtMS43ODksNC00VjE0QzY0LDExLjc4OSw2Mi4yMTEsMTAsNjAsMTB6IE0zMiw1MA0KCQljLTguODM2LDAtMTYtNy4xNjQtMTYtMTZzNy4xNjQtMTYsMTYtMTZzMTYsNy4xNjQsMTYsMTZTNDAuODM2LDUwLDMyLDUweiIvPg0KCTxjaXJjbGUgZmlsbD0iIzIzMUYyMCIgY3g9IjMyIiBjeT0iMzQiIHI9IjgiLz4NCjwvZz4NCjwvc3ZnPg==";
876
889
  var Done = "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48IS0tIFVwbG9hZGVkIHRvOiBTVkcgUmVwbywgd3d3LnN2Z3JlcG8uY29tLCBHZW5lcmF0b3I6IFNWRyBSZXBvIE1peGVyIFRvb2xzIC0tPg0KPHN2ZyB3aWR0aD0iODAwcHgiIGhlaWdodD0iODAwcHgiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4NCjxwYXRoIGQ9Ik04LjUgMTIuNUwxMC41IDE0LjVMMTUuNSA5LjUiIHN0cm9rZT0iIzFDMjc0QyIgc3Ryb2tlLXdpZHRoPSIxLjUiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIvPg0KPHBhdGggZD0iTTcgMy4zMzc4MkM4LjQ3MDg3IDIuNDg2OTcgMTAuMTc4NiAyIDEyIDJDMTcuNTIyOCAyIDIyIDYuNDc3MTUgMjIgMTJDMjIgMTcuNTIyOCAxNy41MjI4IDIyIDEyIDIyQzYuNDc3MTUgMjIgMiAxNy41MjI4IDIgMTJDMiAxMC4xNzg2IDIuNDg2OTcgOC40NzA4NyAzLjMzNzgyIDciIHN0cm9rZT0iIzFDMjc0QyIgc3Ryb2tlLXdpZHRoPSIxLjUiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIvPg0KPC9zdmc+";
877
890
  var Close = "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48IS0tIFVwbG9hZGVkIHRvOiBTVkcgUmVwbywgd3d3LnN2Z3JlcG8uY29tLCBHZW5lcmF0b3I6IFNWRyBSZXBvIE1peGVyIFRvb2xzIC0tPg0KPHN2ZyB3aWR0aD0iODAwcHgiIGhlaWdodD0iODAwcHgiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4NCjxwYXRoIGQ9Ik0xNC41IDkuNTAwMDJMOS41IDE0LjVNOS40OTk5OCA5LjVMMTQuNSAxNC41IiBzdHJva2U9IiMxQzI3NEMiIHN0cm9rZS13aWR0aD0iMS41IiBzdHJva2UtbGluZWNhcD0icm91bmQiLz4NCjxwYXRoIGQ9Ik03IDMuMzM3ODJDOC40NzA4NyAyLjQ4Njk3IDEwLjE3ODYgMiAxMiAyQzE3LjUyMjggMiAyMiA2LjQ3NzE1IDIyIDEyQzIyIDE3LjUyMjggMTcuNTIyOCAyMiAxMiAyMkM2LjQ3NzE1IDIyIDIgMTcuNTIyOCAyIDEyQzIgMTAuMTc4NiAyLjQ4Njk3IDguNDcwODcgMy4zMzc4MiA3IiBzdHJva2U9IiMxQzI3NEMiIHN0cm9rZS13aWR0aD0iMS41IiBzdHJva2UtbGluZWNhcD0icm91bmQiLz4NCjwvc3ZnPg==";
878
- var Upload = "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48IS0tIFVwbG9hZGVkIHRvOiBTVkcgUmVwbywgd3d3LnN2Z3JlcG8uY29tLCBHZW5lcmF0b3I6IFNWRyBSZXBvIE1peGVyIFRvb2xzIC0tPg0KPHN2ZyB3aWR0aD0iODAwcHgiIGhlaWdodD0iODAwcHgiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4NCjxwYXRoIGQ9Ik0xNyAxN0gxNy4wMU0xNS42IDE0SDE4QzE4LjkzMTkgMTQgMTkuMzk3OCAxNCAxOS43NjU0IDE0LjE1MjJDMjAuMjU1NCAxNC4zNTUyIDIwLjY0NDggMTQuNzQ0NiAyMC44NDc4IDE1LjIzNDZDMjEgMTUuNjAyMiAyMSAxNi4wNjgxIDIxIDE3QzIxIDE3LjkzMTkgMjEgMTguMzk3OCAyMC44NDc4IDE4Ljc2NTRDMjAuNjQ0OCAxOS4yNTU0IDIwLjI1NTQgMTkuNjQ0OCAxOS43NjU0IDE5Ljg0NzhDMTkuMzk3OCAyMCAxOC45MzE5IDIwIDE4IDIwSDZDNS4wNjgxMiAyMCA0LjYwMjE4IDIwIDQuMjM0NjMgMTkuODQ3OEMzLjc0NDU4IDE5LjY0NDggMy4zNTUyMyAxOS4yNTU0IDMuMTUyMjQgMTguNzY1NEMzIDE4LjM5NzggMyAxNy45MzE5IDMgMTdDMyAxNi4wNjgxIDMgMTUuNjAyMiAzLjE1MjI0IDE1LjIzNDZDMy4zNTUyMyAxNC43NDQ2IDMuNzQ0NTggMTQuMzU1MiA0LjIzNDYzIDE0LjE1MjJDNC42MDIxOCAxNCA1LjA2ODEyIDE0IDYgMTRIOC40TTEyIDE1VjRNMTIgNEwxNSA3TTEyIDRMOSA3IiBzdHJva2U9IiMwMDAwMDAiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIi8+DQo8L3N2Zz4=";
879
891
 
880
- // src/kyc/FaceCaptureModal.tsx
881
- var fileToBase64 = (file) => {
882
- return new Promise((resolve, reject) => {
883
- const reader = new FileReader();
884
- reader.readAsDataURL(file);
885
- reader.onload = () => resolve(reader.result);
886
- reader.onerror = (error) => reject(error);
887
- });
892
+ // src/kyc/faceDetection.ts
893
+ var FACE_MESSAGES = {
894
+ idle: "Initializing camera...",
895
+ loading: "Loading face detection...",
896
+ scanning: "Position your face in the circle",
897
+ too_far: "Face too far. Please move closer to the camera",
898
+ too_close: "Too close. Please move back a little",
899
+ off_center: "Center your face in the circle",
900
+ ok: "Looking great! Tap the button to capture"
901
+ };
902
+ var FACE_COLORS = {
903
+ idle: "#9ca3af",
904
+ loading: "#3b82f6",
905
+ scanning: "#3b82f6",
906
+ too_far: "#ef4444",
907
+ too_close: "#f59e0b",
908
+ off_center: "#f59e0b",
909
+ ok: "#10b981"
888
910
  };
911
+ var MEDIAPIPE_BASE = "https://cdn.jsdelivr.net/npm/@mediapipe/face_detection";
912
+ function mapDetectionsToFaceStatus(detections) {
913
+ if (detections.length === 0) return "scanning";
914
+ const bb = detections[0].boundingBox;
915
+ if (bb.width < 0.18) return "too_far";
916
+ if (bb.width > 0.72) return "too_close";
917
+ if (bb.xCenter < 0.28 || bb.xCenter > 0.72 || bb.yCenter < 0.28 || bb.yCenter > 0.72) {
918
+ return "off_center";
919
+ }
920
+ return "ok";
921
+ }
922
+ function isCaptureDisabled(ready, detectionActive, faceStatus) {
923
+ return !ready || detectionActive && faceStatus !== "ok";
924
+ }
925
+ function resolveMediaPipeBase(base) {
926
+ if (!base) return MEDIAPIPE_BASE;
927
+ return base.endsWith("/") ? base.slice(0, -1) : base;
928
+ }
929
+ var LIVENESS_SAMPLE_LIMIT = 20;
930
+ function buildLivenessArtifact(samples) {
931
+ if (samples.length === 0) return void 0;
932
+ return JSON.stringify({
933
+ version: 1,
934
+ source: "mediapipe-face-detection",
935
+ samples: samples.slice(-LIVENESS_SAMPLE_LIMIT)
936
+ });
937
+ }
938
+ var mediapipeLoaderPromises = /* @__PURE__ */ new Map();
939
+ function loadMediaPipeFaceDetection(assetBasePath) {
940
+ if (typeof window === "undefined" || typeof document === "undefined") {
941
+ return Promise.reject(new Error("MediaPipe requires a browser environment"));
942
+ }
943
+ const w = window;
944
+ if (w.FaceDetection) {
945
+ return Promise.resolve(w.FaceDetection);
946
+ }
947
+ const src = `${resolveMediaPipeBase(assetBasePath)}/face_detection.js`;
948
+ const existing = mediapipeLoaderPromises.get(src);
949
+ if (existing) return existing;
950
+ const loader = new Promise((resolve, reject) => {
951
+ const script = document.createElement("script");
952
+ script.src = src;
953
+ script.async = true;
954
+ script.crossOrigin = "anonymous";
955
+ script.onload = () => {
956
+ if (w.FaceDetection) {
957
+ resolve(w.FaceDetection);
958
+ } else {
959
+ mediapipeLoaderPromises.delete(src);
960
+ reject(new Error("MediaPipe loaded but FaceDetection global is missing"));
961
+ }
962
+ };
963
+ script.onerror = () => {
964
+ mediapipeLoaderPromises.delete(src);
965
+ reject(new Error("Failed to load MediaPipe face_detection script"));
966
+ };
967
+ document.head.appendChild(script);
968
+ });
969
+ mediapipeLoaderPromises.set(src, loader);
970
+ return loader;
971
+ }
972
+
973
+ // src/kyc/FaceCaptureModal.tsx
974
+ var MOBILE_UA = /Mobi|Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i;
975
+ var SESSION_EXPIRY_MS = 15 * 60 * 1e3;
976
+ var LIVENESS_MESSAGES = [
977
+ "Position your face inside the circle",
978
+ "Make sure your face is well lit",
979
+ "Remove glasses or hats if possible",
980
+ "Look straight at the camera, then tap Capture"
981
+ ];
982
+ function headerSubtitle(stageKind) {
983
+ switch (stageKind) {
984
+ case "qr":
985
+ return "Use your phone to continue";
986
+ case "accepted":
987
+ return "All set";
988
+ case "declined":
989
+ return "Verification Declined";
990
+ case "max_attempts":
991
+ return "We couldn't verify your identity";
992
+ default:
993
+ return "Please capture a clear photo of your face";
994
+ }
995
+ }
996
+ function defaultRenderQR(payload) {
997
+ const url = `https://api.qrserver.com/v1/create-qr-code/?size=220x220&data=${encodeURIComponent(payload)}`;
998
+ return /* @__PURE__ */ React__default.default.createElement("img", { src: url, alt: "QR code", width: 220, height: 220 });
999
+ }
889
1000
  function FaceCaptureModal({
890
- onCapture,
891
- onCancel
1001
+ client,
1002
+ session,
1003
+ onComplete,
1004
+ onCancel,
1005
+ defaultDevice,
1006
+ renderQR,
1007
+ mediapipeAssetBasePath
892
1008
  }) {
893
- const inputRef = React.useRef(null);
894
- const [isProcessing, setIsProcessing] = React.useState(false);
895
- const [isHoveringPrimary, setIsHoveringPrimary] = React.useState(false);
896
- const [isHoveringCancel, setIsHoveringCancel] = React.useState(false);
897
- const [isHoveringClose, setIsHoveringClose] = React.useState(false);
898
- const isMobile = /Mobi|Android/i.test(navigator.userAgent);
899
- const handleFileChange = async (e) => {
900
- const file = e.target.files?.[0];
901
- if (!file) return;
902
- setIsProcessing(true);
903
- try {
904
- const base64 = await fileToBase64(file);
905
- setTimeout(() => {
906
- onCapture(base64);
907
- }, 300);
908
- } catch (error) {
909
- console.error("[Vesant SDK] Error processing image:", error instanceof Error ? error.message : "Unknown error");
910
- setIsProcessing(false);
1009
+ const isMobile = typeof navigator !== "undefined" && MOBILE_UA.test(navigator.userAgent);
1010
+ const initialChoice = defaultDevice ?? (isMobile ? "this" : "ask");
1011
+ const initialStage = (() => {
1012
+ if (initialChoice === "this") return { kind: "capture" };
1013
+ if (initialChoice === "mobile") return { kind: "qr", mobileConnected: false };
1014
+ return { kind: "choose" };
1015
+ })();
1016
+ const hasMethodChoice = initialChoice === "ask";
1017
+ const [stage, setStage] = React.useState(initialStage);
1018
+ const [attempts, setAttempts] = React.useState(session.attempts);
1019
+ const maxAttempts = session.max_attempts || 1;
1020
+ const [qrDeclinedReason, setQrDeclinedReason] = React.useState(null);
1021
+ const [captureMode, setCaptureMode] = React.useState("idle");
1022
+ const [capturedPreview, setCapturedPreview] = React.useState(null);
1023
+ const [capturedBase64, setCapturedBase64] = React.useState(null);
1024
+ const [capturedArtifact, setCapturedArtifact] = React.useState(null);
1025
+ const [livenessMessage, setLivenessMessage] = React.useState(LIVENESS_MESSAGES[0]);
1026
+ const qrPayload = session.link || `vesant://reuse-kyc?token=${encodeURIComponent(session.token)}`;
1027
+ const cancelledRef = React.useRef(false);
1028
+ const submittingRef = React.useRef(false);
1029
+ React.useEffect(() => {
1030
+ const timer = setTimeout(() => {
1031
+ setStage(
1032
+ (prev) => prev.kind === "choose" || prev.kind === "qr" || prev.kind === "capture" ? { kind: "error", message: "Session expired" } : prev
1033
+ );
1034
+ }, SESSION_EXPIRY_MS);
1035
+ return () => clearTimeout(timer);
1036
+ }, [session.token]);
1037
+ React.useEffect(() => {
1038
+ if (stage.kind !== "qr") return;
1039
+ let stopped = false;
1040
+ const intervalMs = 2e3;
1041
+ const deadline = Date.now() + SESSION_EXPIRY_MS;
1042
+ let mobileSeen = stage.mobileConnected;
1043
+ const tick = async () => {
1044
+ if (stopped || cancelledRef.current) return;
1045
+ try {
1046
+ if (mobileSeen) {
1047
+ const result = await client.getEventBasedFaceVerificationSessionStatus(session.token);
1048
+ if (result.status === "accepted") {
1049
+ setStage({ kind: "accepted", result });
1050
+ stopped = true;
1051
+ return;
1052
+ }
1053
+ if (result.status === "declined") {
1054
+ setAttempts(maxAttempts - (result.data?.retries_remaining ?? 0));
1055
+ if (result.data?.retry_limit_exceeded) {
1056
+ setStage({ kind: "max_attempts", result });
1057
+ stopped = true;
1058
+ return;
1059
+ }
1060
+ if (result.declined_reason) {
1061
+ setQrDeclinedReason(result.declined_reason);
1062
+ }
1063
+ }
1064
+ } else {
1065
+ const handoff = await client.getHandoffSession(session.token);
1066
+ if (handoff.mobile_connected) {
1067
+ mobileSeen = true;
1068
+ setStage({ kind: "qr", mobileConnected: true });
1069
+ }
1070
+ }
1071
+ } catch {
1072
+ }
1073
+ if (Date.now() < deadline) {
1074
+ setTimeout(tick, intervalMs);
1075
+ }
1076
+ };
1077
+ tick();
1078
+ return () => {
1079
+ stopped = true;
1080
+ };
1081
+ }, [stage.kind, stage.kind === "qr" ? stage.mobileConnected : false]);
1082
+ const applyResult = (result) => {
1083
+ if (result.status === "accepted") {
1084
+ setStage({ kind: "accepted", result });
1085
+ return true;
911
1086
  }
1087
+ if (result.status === "declined") {
1088
+ const nextAttempts = maxAttempts - (result.data?.retries_remaining ?? 0);
1089
+ setAttempts(nextAttempts);
1090
+ setCapturedPreview(null);
1091
+ setCapturedBase64(null);
1092
+ if (result.data?.retry_limit_exceeded) {
1093
+ setStage({ kind: "max_attempts", result });
1094
+ } else {
1095
+ setStage({ kind: "declined", result });
1096
+ }
1097
+ return true;
1098
+ }
1099
+ return false;
912
1100
  };
913
- const overlayStyle = {
914
- position: "fixed",
915
- inset: 0,
916
- background: "rgba(0, 0, 0, 0.6)",
917
- backdropFilter: "blur(4px)",
918
- display: "flex",
919
- alignItems: "center",
920
- justifyContent: "center",
921
- zIndex: 999999,
922
- padding: "16px",
923
- animation: "fadeIn 0.2s ease-out"
924
- };
925
- const modalStyle = {
926
- background: "#ffffff",
927
- borderRadius: "16px",
928
- boxShadow: "0 25px 50px -12px rgba(0, 0, 0, 0.25)",
929
- width: "100%",
930
- maxWidth: "448px",
931
- animation: "zoomIn 0.2s ease-out"
932
- };
933
- const headerStyle = {
934
- position: "relative",
935
- padding: "24px 24px 16px",
936
- borderBottom: "1px solid #f3f4f6"
937
- };
938
- const closeButtonStyle = {
939
- position: "absolute",
940
- top: "16px",
941
- right: "16px",
942
- padding: "8px",
943
- background: isHoveringClose ? "#f3f4f6" : "transparent",
944
- border: "none",
945
- borderRadius: "9999px",
946
- cursor: "pointer",
947
- transition: "background-color 0.2s",
948
- display: "flex",
949
- alignItems: "center",
950
- justifyContent: "center"
951
- };
952
- const titleStyle = {
953
- fontSize: "24px",
954
- fontWeight: 600,
955
- color: "#111827",
956
- margin: 0
957
- };
958
- const subtitleStyle = {
959
- fontSize: "14px",
960
- color: "#6b7280",
961
- marginTop: "4px"
962
- };
963
- const contentStyle = {
964
- padding: "32px 24px"
965
- };
966
- const visualGuideContainerStyle = {
967
- marginBottom: "32px",
968
- display: "flex",
969
- justifyContent: "center"
970
- };
971
- const visualGuideStyle = {
972
- position: "relative"
973
- };
974
- const circleStyle = {
975
- width: "128px",
976
- height: "128px",
977
- borderRadius: "50%",
978
- background: "linear-gradient(135deg, rgba(0, 188, 125, 0.2) 0%, rgba(0, 188, 125, 0.05) 100%)",
979
- display: "flex",
980
- alignItems: "center",
981
- justifyContent: "center"
982
- };
983
- const badgeStyle = {
984
- position: "absolute",
985
- top: "-4px",
986
- right: "-4px",
987
- width: "32px",
988
- height: "32px",
989
- background: "#ffffff",
990
- borderRadius: "50%",
991
- boxShadow: "0 4px 6px -1px rgba(0, 0, 0, 0.1)",
992
- display: "flex",
993
- alignItems: "center",
994
- justifyContent: "center"
995
- };
996
- const instructionsBoxStyle = {
997
- background: "linear-gradient(135deg, #f9fafb 0%, rgba(243, 244, 246, 0.5) 100%)",
998
- borderRadius: "12px",
999
- padding: "16px",
1000
- marginBottom: "24px"
1001
- };
1002
- const instructionsTitleStyle = {
1003
- fontSize: "14px",
1004
- fontWeight: 500,
1005
- color: "#111827",
1006
- marginBottom: "8px"
1007
- };
1008
- const instructionsListStyle = {
1009
- fontSize: "12px",
1010
- color: "#6b7280",
1011
- listStyle: "none",
1012
- padding: 0,
1013
- margin: 0
1014
- };
1015
- const instructionItemStyle = {
1016
- display: "flex",
1017
- alignItems: "flex-start",
1018
- marginBottom: "6px"
1101
+ const runSubmit = async (proof) => {
1102
+ if (submittingRef.current) return;
1103
+ submittingRef.current = true;
1104
+ setStage({ kind: "submitting" });
1105
+ let settled = false;
1106
+ const ref = session.reference;
1107
+ const baselineAttempts = attempts;
1108
+ const isFreshPollResult = (r) => {
1109
+ if (r.status === "accepted") return true;
1110
+ if (r.status === "declined") {
1111
+ const derivedAttempts = maxAttempts - (r.data?.retries_remaining ?? 0);
1112
+ return derivedAttempts > baselineAttempts;
1113
+ }
1114
+ return false;
1115
+ };
1116
+ try {
1117
+ const postPromise = (async () => {
1118
+ try {
1119
+ const data = await client.submitEventBasedFaceVerificationSession({
1120
+ token: session.token,
1121
+ reference: ref,
1122
+ proof,
1123
+ // undefined when detection wasn't running for this capture —
1124
+ // JSON.stringify drops it, so the field is absent on the wire.
1125
+ liveness_artifact: capturedArtifact ?? void 0
1126
+ });
1127
+ return { ok: true, data };
1128
+ } catch (err2) {
1129
+ return { ok: false, error: err2 };
1130
+ }
1131
+ })();
1132
+ const pollPromise = (async () => {
1133
+ await new Promise((r) => setTimeout(r, 12e3));
1134
+ const deadline = Date.now() + 12e4;
1135
+ while (Date.now() < deadline) {
1136
+ if (settled || cancelledRef.current) return null;
1137
+ try {
1138
+ const r = await client.getEventBasedFaceVerificationSessionStatus(session.token);
1139
+ if (isFreshPollResult(r)) return r;
1140
+ } catch {
1141
+ }
1142
+ if (settled || cancelledRef.current) return null;
1143
+ await new Promise((r) => setTimeout(r, 3e3));
1144
+ }
1145
+ return null;
1146
+ })();
1147
+ const winner = await Promise.race([
1148
+ postPromise.then(
1149
+ (r) => r.ok ? { from: "post", data: r.data } : { from: "post_err" }
1150
+ ),
1151
+ pollPromise.then(
1152
+ (data) => data ? { from: "poll", data } : { from: "poll_done" }
1153
+ )
1154
+ ]);
1155
+ settled = true;
1156
+ if (winner.from === "post" && applyResult(winner.data)) return;
1157
+ if (winner.from === "poll" && applyResult(winner.data)) return;
1158
+ const [postResult, pollResult] = await Promise.all([postPromise, pollPromise]);
1159
+ if (postResult.ok && applyResult(postResult.data)) return;
1160
+ if (pollResult && applyResult(pollResult)) return;
1161
+ const err = postResult.ok ? null : postResult.error;
1162
+ setStage({
1163
+ kind: "error",
1164
+ message: err instanceof Error ? err.message : "Submission failed. Please try again."
1165
+ });
1166
+ } finally {
1167
+ settled = true;
1168
+ submittingRef.current = false;
1169
+ }
1019
1170
  };
1020
- const bulletStyle = {
1021
- color: "#00bc7d",
1022
- marginRight: "8px",
1023
- flexShrink: 0
1171
+ const handleCameraCapture = (dataUrl, livenessArtifact) => {
1172
+ const raw = dataUrl.split(",")[1] ?? "";
1173
+ setCapturedPreview(dataUrl);
1174
+ setCapturedBase64(raw);
1175
+ setCapturedArtifact(livenessArtifact ?? null);
1176
+ setCaptureMode("preview");
1024
1177
  };
1025
- const buttonsContainerStyle = {
1026
- display: "flex",
1027
- flexDirection: "column",
1028
- gap: "12px"
1178
+ const handleCameraCancel = () => setCaptureMode("idle");
1179
+ const handleRetake = () => {
1180
+ setCapturedPreview(null);
1181
+ setCapturedBase64(null);
1182
+ setCapturedArtifact(null);
1183
+ setCaptureMode("live");
1029
1184
  };
1030
- const primaryButtonStyle = {
1031
- width: "100%",
1032
- background: isProcessing ? "#d1d5db" : isHoveringPrimary ? "#00a86d" : "#00bc7d",
1033
- color: "#ffffff",
1034
- fontWeight: 500,
1035
- padding: "14px 24px",
1036
- borderRadius: "12px",
1037
- border: "none",
1038
- cursor: isProcessing ? "not-allowed" : "pointer",
1039
- transition: "all 0.2s",
1040
- display: "flex",
1041
- alignItems: "center",
1042
- justifyContent: "center",
1043
- gap: "12px",
1044
- boxShadow: isProcessing ? "none" : isHoveringPrimary ? "0 20px 25px -5px rgba(0, 188, 125, 0.3)" : "0 10px 15px -3px rgba(0, 188, 125, 0.2)",
1045
- fontSize: "16px"
1185
+ const handleConfirmSubmit = () => {
1186
+ if (!capturedBase64) return;
1187
+ void runSubmit(capturedBase64);
1046
1188
  };
1047
- const cancelButtonStyle = {
1048
- width: "100%",
1049
- background: isProcessing ? "#f3f4f6" : isHoveringCancel ? "#f9fafb" : "#ffffff",
1050
- color: "#374151",
1051
- fontWeight: 500,
1052
- padding: "14px 24px",
1053
- borderRadius: "12px",
1054
- border: "2px solid #e5e7eb",
1055
- cursor: isProcessing ? "not-allowed" : "pointer",
1056
- transition: "all 0.2s",
1057
- fontSize: "16px"
1189
+ const handleOpenCamera = () => {
1190
+ if (submittingRef.current) return;
1191
+ setCaptureMode("live");
1058
1192
  };
1059
- const footerStyle = {
1060
- padding: "0 24px 24px"
1193
+ const handleRetakeAfterDecline = () => {
1194
+ setCapturedPreview(null);
1195
+ setCapturedBase64(null);
1196
+ setCaptureMode("live");
1197
+ setStage({ kind: "capture" });
1061
1198
  };
1062
- const footerTextStyle = {
1063
- fontSize: "12px",
1064
- textAlign: "center",
1065
- color: "#9ca3af",
1066
- margin: 0
1199
+ React.useEffect(() => {
1200
+ if (captureMode !== "live") return;
1201
+ setLivenessMessage(LIVENESS_MESSAGES[0]);
1202
+ let i = 0;
1203
+ const interval = setInterval(() => {
1204
+ i = (i + 1) % LIVENESS_MESSAGES.length;
1205
+ setLivenessMessage(LIVENESS_MESSAGES[i]);
1206
+ }, 3e3);
1207
+ return () => clearInterval(interval);
1208
+ }, [captureMode]);
1209
+ const close = (result) => {
1210
+ cancelledRef.current = true;
1211
+ if (result === null && onCancel) {
1212
+ onCancel();
1213
+ }
1214
+ onComplete(result);
1067
1215
  };
1068
- const spinnerStyle = {
1069
- width: "20px",
1070
- height: "20px",
1071
- border: "2px solid rgba(255, 255, 255, 0.3)",
1072
- borderTopColor: "#ffffff",
1073
- borderRadius: "50%",
1074
- animation: "spin 0.6s linear infinite"
1216
+ const renderChoose = () => /* @__PURE__ */ React__default.default.createElement("div", { style: contentStyle }, /* @__PURE__ */ React__default.default.createElement("div", { style: visualGuideContainerStyle }, /* @__PURE__ */ React__default.default.createElement("div", { style: visualGuideStyle }, /* @__PURE__ */ React__default.default.createElement("div", { style: circleStyle }, /* @__PURE__ */ React__default.default.createElement("img", { src: Camera, alt: "", width: 48, height: 48 })))), /* @__PURE__ */ React__default.default.createElement("p", { style: subtitleStyle }, "How would you like to verify?"), /* @__PURE__ */ React__default.default.createElement("div", { style: buttonsContainerStyle }, /* @__PURE__ */ React__default.default.createElement(
1217
+ "button",
1218
+ {
1219
+ style: primaryButtonStyle,
1220
+ onClick: () => setStage({ kind: "capture" })
1221
+ },
1222
+ /* @__PURE__ */ React__default.default.createElement("img", { src: Camera, alt: "", width: 20, height: 20 }),
1223
+ /* @__PURE__ */ React__default.default.createElement("span", null, "Continue on this device")
1224
+ ), /* @__PURE__ */ React__default.default.createElement(
1225
+ "button",
1226
+ {
1227
+ style: secondaryButtonStyle,
1228
+ onClick: () => setStage({ kind: "qr", mobileConnected: false })
1229
+ },
1230
+ "Continue on mobile (scan QR)"
1231
+ ), /* @__PURE__ */ React__default.default.createElement("button", { style: cancelButtonStyle, onClick: () => close(null) }, "Cancel")));
1232
+ const renderQRStage = (mobileConnected) => /* @__PURE__ */ React__default.default.createElement("div", { style: contentStyle }, /* @__PURE__ */ React__default.default.createElement("div", { style: qrBoxStyle }, (renderQR ?? defaultRenderQR)(qrPayload)), /* @__PURE__ */ React__default.default.createElement("p", { style: subtitleStyle }, mobileConnected ? "Phone connected. Complete the capture on your mobile device\u2026" : "Scan this QR with your phone camera, then complete the face capture there."), mobileConnected && /* @__PURE__ */ React__default.default.createElement("div", { style: { ...spinnerStyle, margin: "12px auto" } }), qrDeclinedReason && /* @__PURE__ */ React__default.default.createElement("div", { style: alertBoxStyle }, /* @__PURE__ */ React__default.default.createElement("strong", null, "Last attempt was declined."), /* @__PURE__ */ React__default.default.createElement("p", { style: alertTextStyle }, qrDeclinedReason), /* @__PURE__ */ React__default.default.createElement("p", { style: { ...alertTextStyle, marginTop: 4 } }, "Try again on your phone. Attempt ", Math.min(attempts + 1, maxAttempts), " of ", maxAttempts, ".")), /* @__PURE__ */ React__default.default.createElement("div", { style: buttonsContainerStyle }, /* @__PURE__ */ React__default.default.createElement(
1233
+ "button",
1234
+ {
1235
+ style: secondaryButtonStyle,
1236
+ onClick: () => setStage({ kind: "capture" })
1237
+ },
1238
+ "Use this device instead"
1239
+ ), hasMethodChoice && /* @__PURE__ */ React__default.default.createElement(
1240
+ "button",
1241
+ {
1242
+ style: secondaryButtonStyle,
1243
+ onClick: () => setStage({ kind: "choose" })
1244
+ },
1245
+ "Change verification method"
1246
+ ), /* @__PURE__ */ React__default.default.createElement("button", { style: cancelButtonStyle, onClick: () => close(null) }, "Cancel")));
1247
+ const renderCapture = (declinedReason) => {
1248
+ if (captureMode === "live") {
1249
+ return /* @__PURE__ */ React__default.default.createElement("div", { style: contentStyle }, /* @__PURE__ */ React__default.default.createElement(
1250
+ LiveCamera,
1251
+ {
1252
+ onCapture: handleCameraCapture,
1253
+ onCancel: handleCameraCancel,
1254
+ message: livenessMessage,
1255
+ assetBasePath: mediapipeAssetBasePath
1256
+ }
1257
+ ), /* @__PURE__ */ React__default.default.createElement("p", { style: attemptsTextStyle }, "Attempt ", attempts + 1, " of ", maxAttempts));
1258
+ }
1259
+ if (captureMode === "preview" && capturedPreview) {
1260
+ return /* @__PURE__ */ React__default.default.createElement("div", { style: contentStyle }, declinedReason && /* @__PURE__ */ React__default.default.createElement("div", { style: alertBoxStyle }, /* @__PURE__ */ React__default.default.createElement("strong", null, "Verification declined."), /* @__PURE__ */ React__default.default.createElement("p", { style: alertTextStyle }, declinedReason)), /* @__PURE__ */ React__default.default.createElement("p", { style: subtitleStyle }, "Looks good? Submit this selfie or retake it."), /* @__PURE__ */ React__default.default.createElement("div", { style: previewBoxStyle }, /* @__PURE__ */ React__default.default.createElement("img", { src: capturedPreview, alt: "Captured selfie preview", style: previewImgStyle })), /* @__PURE__ */ React__default.default.createElement("div", { style: buttonsContainerStyle }, /* @__PURE__ */ React__default.default.createElement("button", { style: primaryButtonStyle, onClick: handleConfirmSubmit }, /* @__PURE__ */ React__default.default.createElement("img", { src: Done, alt: "", width: 20, height: 20 }), /* @__PURE__ */ React__default.default.createElement("span", null, "Submit")), /* @__PURE__ */ React__default.default.createElement("button", { style: secondaryButtonStyle, onClick: handleRetake }, "Retake"), /* @__PURE__ */ React__default.default.createElement("button", { style: cancelButtonStyle, onClick: () => close(null) }, "Cancel")), /* @__PURE__ */ React__default.default.createElement("p", { style: attemptsTextStyle }, "Attempt ", attempts + 1, " of ", maxAttempts));
1261
+ }
1262
+ return /* @__PURE__ */ React__default.default.createElement("div", { style: contentStyle }, /* @__PURE__ */ React__default.default.createElement("div", { style: visualGuideContainerStyle }, /* @__PURE__ */ React__default.default.createElement("div", { style: visualGuideStyle }, /* @__PURE__ */ React__default.default.createElement("div", { style: circleStyle }, /* @__PURE__ */ React__default.default.createElement("img", { src: Camera, alt: "", width: 48, height: 48 })), /* @__PURE__ */ React__default.default.createElement("div", { style: badgeStyle }, /* @__PURE__ */ React__default.default.createElement("img", { src: Done, alt: "", width: 16, height: 16 })))), declinedReason && /* @__PURE__ */ React__default.default.createElement("div", { style: alertBoxStyle }, /* @__PURE__ */ React__default.default.createElement("strong", null, "Verification declined."), /* @__PURE__ */ React__default.default.createElement("p", { style: alertTextStyle }, declinedReason)), /* @__PURE__ */ React__default.default.createElement("div", { style: instructionsBoxStyle }, /* @__PURE__ */ React__default.default.createElement("h3", { style: instructionsTitleStyle }, "Tips for best results:"), /* @__PURE__ */ React__default.default.createElement("ul", { style: instructionsListStyle }, /* @__PURE__ */ React__default.default.createElement("li", { style: instructionItemStyle }, /* @__PURE__ */ React__default.default.createElement("span", { style: bulletStyle }, "\u2022"), /* @__PURE__ */ React__default.default.createElement("span", null, "Ensure good lighting on your face")), /* @__PURE__ */ React__default.default.createElement("li", { style: instructionItemStyle }, /* @__PURE__ */ React__default.default.createElement("span", { style: bulletStyle }, "\u2022"), /* @__PURE__ */ React__default.default.createElement("span", null, "Remove glasses or accessories if possible")), /* @__PURE__ */ React__default.default.createElement("li", { style: instructionItemStyle }, /* @__PURE__ */ React__default.default.createElement("span", { style: bulletStyle }, "\u2022"), /* @__PURE__ */ React__default.default.createElement("span", null, "Look directly at the camera")))), /* @__PURE__ */ React__default.default.createElement("div", { style: buttonsContainerStyle }, /* @__PURE__ */ React__default.default.createElement("button", { style: primaryButtonStyle, onClick: handleOpenCamera }, /* @__PURE__ */ React__default.default.createElement("img", { src: Camera, alt: "", width: 20, height: 20 }), /* @__PURE__ */ React__default.default.createElement("span", null, declinedReason ? "Try Again" : "Open Camera")), hasMethodChoice && /* @__PURE__ */ React__default.default.createElement(
1263
+ "button",
1264
+ {
1265
+ style: secondaryButtonStyle,
1266
+ onClick: () => setStage({ kind: "choose" })
1267
+ },
1268
+ "Change verification method"
1269
+ ), /* @__PURE__ */ React__default.default.createElement("button", { style: cancelButtonStyle, onClick: () => close(null) }, "Cancel")), /* @__PURE__ */ React__default.default.createElement("p", { style: attemptsTextStyle }, "Attempt ", attempts + 1, " of ", maxAttempts));
1075
1270
  };
1076
- const hiddenInputStyle = {
1077
- display: "none"
1271
+ const renderSubmitting = () => /* @__PURE__ */ React__default.default.createElement("div", { style: { ...contentStyle, alignItems: "center", textAlign: "center" } }, /* @__PURE__ */ React__default.default.createElement("div", { style: { ...spinnerStyle, margin: "24px auto", width: 32, height: 32 } }), /* @__PURE__ */ React__default.default.createElement("p", { style: subtitleStyle }, "Verifying your photo\u2026"), /* @__PURE__ */ React__default.default.createElement("p", { style: { ...attemptsTextStyle, marginTop: 8 } }, "This usually takes a few seconds."));
1272
+ const renderAccepted = (result) => /* @__PURE__ */ React__default.default.createElement("div", { style: { ...contentStyle, alignItems: "center", textAlign: "center" } }, /* @__PURE__ */ React__default.default.createElement("div", { style: successCircleStyle }, /* @__PURE__ */ React__default.default.createElement("img", { src: Done, alt: "", width: 48, height: 48 })), /* @__PURE__ */ React__default.default.createElement("h3", { style: titleStyle }, "Verified"), /* @__PURE__ */ React__default.default.createElement("p", { style: subtitleStyle }, "Your identity has been confirmed. You can continue."), /* @__PURE__ */ React__default.default.createElement("div", { style: buttonsContainerStyle }, /* @__PURE__ */ React__default.default.createElement("button", { style: primaryButtonStyle, onClick: () => close(result) }, "Continue")));
1273
+ const renderDeclined = (result) => /* @__PURE__ */ React__default.default.createElement("div", { style: contentStyle }, /* @__PURE__ */ React__default.default.createElement("div", { style: alertBoxStyle }, /* @__PURE__ */ React__default.default.createElement("p", { style: alertTextStyle }, result.declined_reason ?? "We couldn't match your selfie. Please take a new one.")), /* @__PURE__ */ React__default.default.createElement("div", { style: buttonsContainerStyle }, /* @__PURE__ */ React__default.default.createElement("button", { style: primaryButtonStyle, onClick: handleRetakeAfterDecline }, /* @__PURE__ */ React__default.default.createElement("img", { src: Camera, alt: "", width: 20, height: 20 }), /* @__PURE__ */ React__default.default.createElement("span", null, "Retake")), /* @__PURE__ */ React__default.default.createElement("button", { style: cancelButtonStyle, onClick: () => close(result) }, "Cancel")), /* @__PURE__ */ React__default.default.createElement("p", { style: attemptsTextStyle }, "Attempt ", Math.min(attempts + 1, maxAttempts), " of ", maxAttempts));
1274
+ const renderMaxAttempts = (result) => /* @__PURE__ */ React__default.default.createElement("div", { style: { ...contentStyle, alignItems: "center", textAlign: "center" } }, /* @__PURE__ */ React__default.default.createElement("div", { style: errorCircleStyle }, "!"), /* @__PURE__ */ React__default.default.createElement("h3", { style: titleStyle }, "Maximum Attempts Reached"), /* @__PURE__ */ React__default.default.createElement("p", { style: subtitleStyle }, result.declined_reason ?? "We couldn't verify your identity after several attempts."), result.data?.freeze_account && /* @__PURE__ */ React__default.default.createElement("p", { style: alertTextStyle }, "For your security, your account has been temporarily restricted", result.data.freeze_duration_minutes ? ` for ${result.data.freeze_duration_minutes} minutes` : "", ". Please contact support if you need immediate help."), result.data?.enforce_logout && /* @__PURE__ */ React__default.default.createElement("p", { style: alertTextStyle }, "You will be signed out of your session."), result.data?.block && /* @__PURE__ */ React__default.default.createElement("p", { style: alertTextStyle }, "This action has been blocked for security reasons."), /* @__PURE__ */ React__default.default.createElement("div", { style: buttonsContainerStyle }, /* @__PURE__ */ React__default.default.createElement("button", { style: primaryButtonStyle, onClick: () => close(result) }, "Close")));
1275
+ const renderError = (message) => {
1276
+ const sessionExpired = /session\s+expired/i.test(message);
1277
+ return /* @__PURE__ */ React__default.default.createElement("div", { style: { ...contentStyle, alignItems: "center", textAlign: "center" } }, /* @__PURE__ */ React__default.default.createElement("div", { style: errorCircleStyle }, "!"), /* @__PURE__ */ React__default.default.createElement("h3", { style: titleStyle }, sessionExpired ? "Session expired" : "Something Went Wrong"), /* @__PURE__ */ React__default.default.createElement("p", { style: alertTextStyle }, sessionExpired ? "Your verification session is no longer valid. Please start a new verification from the beginning." : message), /* @__PURE__ */ React__default.default.createElement("div", { style: buttonsContainerStyle }, !sessionExpired && /* @__PURE__ */ React__default.default.createElement("button", { style: primaryButtonStyle, onClick: () => setStage({ kind: "capture" }) }, "Try Again"), /* @__PURE__ */ React__default.default.createElement("button", { style: cancelButtonStyle, onClick: () => close(null) }, sessionExpired ? "Close" : "Cancel")));
1078
1278
  };
1079
- const styleTag = /* @__PURE__ */ React__default.default.createElement("style", null, `
1080
- @keyframes fadeIn {
1081
- from {
1082
- opacity: 0;
1083
- }
1084
- to {
1085
- opacity: 1;
1086
- }
1087
- }
1088
-
1089
- @keyframes zoomIn {
1090
- from {
1091
- opacity: 0;
1092
- transform: scale(0.95);
1093
- }
1094
- to {
1095
- opacity: 1;
1096
- transform: scale(1);
1097
- }
1098
- }
1099
-
1100
- @keyframes spin {
1101
- from {
1102
- transform: rotate(0deg);
1103
- }
1104
- to {
1105
- transform: rotate(360deg);
1106
- }
1107
- }
1108
- `);
1109
- return /* @__PURE__ */ React__default.default.createElement(React__default.default.Fragment, null, styleTag, /* @__PURE__ */ React__default.default.createElement("div", { style: overlayStyle }, /* @__PURE__ */ React__default.default.createElement("div", { style: modalStyle }, /* @__PURE__ */ React__default.default.createElement("div", { style: headerStyle }, /* @__PURE__ */ React__default.default.createElement(
1279
+ const body = (() => {
1280
+ switch (stage.kind) {
1281
+ case "choose":
1282
+ return renderChoose();
1283
+ case "qr":
1284
+ return renderQRStage(stage.mobileConnected);
1285
+ case "capture":
1286
+ return renderCapture(stage.declinedReason);
1287
+ case "submitting":
1288
+ return renderSubmitting();
1289
+ case "accepted":
1290
+ return renderAccepted(stage.result);
1291
+ case "declined":
1292
+ return renderDeclined(stage.result);
1293
+ case "max_attempts":
1294
+ return renderMaxAttempts(stage.result);
1295
+ case "error":
1296
+ return renderError(stage.message);
1297
+ }
1298
+ })();
1299
+ return /* @__PURE__ */ React__default.default.createElement(React__default.default.Fragment, null, /* @__PURE__ */ React__default.default.createElement("style", null, keyframes), /* @__PURE__ */ React__default.default.createElement("div", { style: overlayStyle }, /* @__PURE__ */ React__default.default.createElement("div", { style: modalStyle }, /* @__PURE__ */ React__default.default.createElement("div", { style: headerStyle }, /* @__PURE__ */ React__default.default.createElement(
1110
1300
  "button",
1111
1301
  {
1112
- onClick: onCancel,
1113
- onMouseEnter: () => setIsHoveringClose(true),
1114
- onMouseLeave: () => setIsHoveringClose(false),
1302
+ onClick: () => close(null),
1115
1303
  style: closeButtonStyle,
1116
1304
  "aria-label": "Close"
1117
1305
  },
1118
- /* @__PURE__ */ React__default.default.createElement("img", { src: Close, alt: "Close Icon", width: 16, height: 16 })
1119
- ), /* @__PURE__ */ React__default.default.createElement("h2", { style: titleStyle }, "Face Verification"), /* @__PURE__ */ React__default.default.createElement("p", { style: subtitleStyle }, "Please capture or upload a clear photo of your face")), /* @__PURE__ */ React__default.default.createElement("div", { style: contentStyle }, /* @__PURE__ */ React__default.default.createElement("div", { style: visualGuideContainerStyle }, /* @__PURE__ */ React__default.default.createElement("div", { style: visualGuideStyle }, /* @__PURE__ */ React__default.default.createElement("div", { style: circleStyle }, /* @__PURE__ */ React__default.default.createElement("img", { src: Camera, alt: "Camera Icon", width: 48, height: 48 })), /* @__PURE__ */ React__default.default.createElement("div", { style: badgeStyle }, /* @__PURE__ */ React__default.default.createElement("img", { src: Done, alt: "Check Icon", width: 16, height: 16 })))), /* @__PURE__ */ React__default.default.createElement("div", { style: instructionsBoxStyle }, /* @__PURE__ */ React__default.default.createElement("h3", { style: instructionsTitleStyle }, "Tips for best results:"), /* @__PURE__ */ React__default.default.createElement("ul", { style: instructionsListStyle }, /* @__PURE__ */ React__default.default.createElement("li", { style: instructionItemStyle }, /* @__PURE__ */ React__default.default.createElement("span", { style: bulletStyle }, "\u2022"), /* @__PURE__ */ React__default.default.createElement("span", null, "Ensure good lighting on your face")), /* @__PURE__ */ React__default.default.createElement("li", { style: instructionItemStyle }, /* @__PURE__ */ React__default.default.createElement("span", { style: bulletStyle }, "\u2022"), /* @__PURE__ */ React__default.default.createElement("span", null, "Remove glasses or accessories if possible")), /* @__PURE__ */ React__default.default.createElement("li", { style: instructionItemStyle }, /* @__PURE__ */ React__default.default.createElement("span", { style: bulletStyle }, "\u2022"), /* @__PURE__ */ React__default.default.createElement("span", null, "Look directly at the camera")))), /* @__PURE__ */ React__default.default.createElement(
1120
- "input",
1306
+ /* @__PURE__ */ React__default.default.createElement("img", { src: Close, alt: "", width: 16, height: 16 })
1307
+ ), /* @__PURE__ */ React__default.default.createElement("h2", { style: titleStyle }, "Face Verification"), /* @__PURE__ */ React__default.default.createElement("p", { style: subtitleStyle }, headerSubtitle(stage.kind))), body, /* @__PURE__ */ React__default.default.createElement("div", { style: footerStyle }, /* @__PURE__ */ React__default.default.createElement("p", { style: footerTextStyle }, "Your photo is securely processed and used only for verification.")))));
1308
+ }
1309
+ var keyframes = `
1310
+ @keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
1311
+ @keyframes zoomIn { from { transform: scale(.96); opacity: 0 } to { transform: scale(1); opacity: 1 } }
1312
+ @keyframes spin { to { transform: rotate(360deg) } }
1313
+ @keyframes pulse { 0%, 100% { opacity: 1 } 50% { opacity: .5 } }
1314
+ `;
1315
+ var overlayStyle = {
1316
+ position: "fixed",
1317
+ inset: 0,
1318
+ background: "rgba(0,0,0,.6)",
1319
+ backdropFilter: "blur(4px)",
1320
+ display: "flex",
1321
+ alignItems: "center",
1322
+ justifyContent: "center",
1323
+ zIndex: 999999,
1324
+ padding: 16,
1325
+ animation: "fadeIn .2s ease-out"
1326
+ };
1327
+ var modalStyle = {
1328
+ background: "#fff",
1329
+ borderRadius: 16,
1330
+ boxShadow: "0 25px 50px -12px rgba(0,0,0,.25)",
1331
+ width: "100%",
1332
+ maxWidth: 448,
1333
+ animation: "zoomIn .2s ease-out"
1334
+ };
1335
+ var headerStyle = {
1336
+ position: "relative",
1337
+ padding: "24px 24px 16px",
1338
+ borderBottom: "1px solid #f3f4f6"
1339
+ };
1340
+ var closeButtonStyle = {
1341
+ position: "absolute",
1342
+ top: 16,
1343
+ right: 16,
1344
+ padding: 8,
1345
+ background: "transparent",
1346
+ border: "none",
1347
+ borderRadius: 8,
1348
+ cursor: "pointer"
1349
+ };
1350
+ var titleStyle = { margin: "0 0 4px", fontSize: 18, fontWeight: 600, color: "#111827" };
1351
+ var subtitleStyle = { margin: 0, fontSize: 14, color: "#6b7280" };
1352
+ var contentStyle = {
1353
+ padding: 24,
1354
+ display: "flex",
1355
+ flexDirection: "column",
1356
+ gap: 16
1357
+ };
1358
+ var visualGuideContainerStyle = { display: "flex", justifyContent: "center" };
1359
+ var visualGuideStyle = { position: "relative" };
1360
+ var circleStyle = {
1361
+ width: 96,
1362
+ height: 96,
1363
+ borderRadius: "50%",
1364
+ background: "linear-gradient(135deg, rgba(0, 188, 125, 0.2) 0%, rgba(0, 188, 125, 0.05) 100%)",
1365
+ display: "flex",
1366
+ alignItems: "center",
1367
+ justifyContent: "center"
1368
+ };
1369
+ var badgeStyle = {
1370
+ position: "absolute",
1371
+ bottom: -4,
1372
+ right: -4,
1373
+ width: 28,
1374
+ height: 28,
1375
+ borderRadius: "50%",
1376
+ background: "#ffffff",
1377
+ border: "2px solid #00bc7d",
1378
+ display: "flex",
1379
+ alignItems: "center",
1380
+ justifyContent: "center"
1381
+ };
1382
+ var successCircleStyle = {
1383
+ ...circleStyle,
1384
+ background: "linear-gradient(135deg, rgba(0, 188, 125, 0.25) 0%, rgba(0, 188, 125, 0.1) 100%)",
1385
+ margin: "0 auto"
1386
+ };
1387
+ var errorCircleStyle = {
1388
+ width: 64,
1389
+ height: 64,
1390
+ borderRadius: "50%",
1391
+ background: "#fee2e2",
1392
+ color: "#b91c1c",
1393
+ fontSize: 32,
1394
+ fontWeight: 700,
1395
+ display: "flex",
1396
+ alignItems: "center",
1397
+ justifyContent: "center",
1398
+ margin: "0 auto"
1399
+ };
1400
+ var qrBoxStyle = {
1401
+ display: "flex",
1402
+ justifyContent: "center",
1403
+ padding: 12,
1404
+ background: "linear-gradient(135deg, #f9fafb 0%, rgba(243, 244, 246, 0.5) 100%)",
1405
+ borderRadius: 12
1406
+ };
1407
+ var alertBoxStyle = {
1408
+ background: "#fef3c7",
1409
+ border: "1px solid #fde68a",
1410
+ color: "#92400e",
1411
+ borderRadius: 8,
1412
+ padding: 12,
1413
+ fontSize: 14
1414
+ };
1415
+ var alertTextStyle = { margin: "4px 0 0", fontSize: 13, color: "#92400e" };
1416
+ var instructionsBoxStyle = {
1417
+ background: "linear-gradient(135deg, #f9fafb 0%, rgba(243, 244, 246, 0.5) 100%)",
1418
+ borderRadius: 8,
1419
+ padding: 16
1420
+ };
1421
+ var instructionsTitleStyle = { margin: "0 0 8px", fontSize: 14, fontWeight: 600, color: "#374151" };
1422
+ var instructionsListStyle = { margin: 0, padding: 0, listStyle: "none" };
1423
+ var instructionItemStyle = { display: "flex", gap: 8, fontSize: 13, color: "#4b5563", lineHeight: 1.5 };
1424
+ var bulletStyle = { color: "#00bc7d" };
1425
+ var previewBoxStyle = {
1426
+ borderRadius: 12,
1427
+ overflow: "hidden",
1428
+ border: "2px solid rgba(0, 188, 125, 0.4)",
1429
+ background: "#0f172a",
1430
+ display: "flex",
1431
+ justifyContent: "center"
1432
+ };
1433
+ var previewImgStyle = {
1434
+ width: "100%",
1435
+ maxHeight: 320,
1436
+ objectFit: "contain",
1437
+ background: "#0f172a"
1438
+ };
1439
+ var buttonsContainerStyle = {
1440
+ display: "flex",
1441
+ flexDirection: "column",
1442
+ gap: 8
1443
+ };
1444
+ var primaryButtonStyle = {
1445
+ display: "flex",
1446
+ alignItems: "center",
1447
+ justifyContent: "center",
1448
+ gap: 8,
1449
+ padding: "12px 16px",
1450
+ background: "#00bc7d",
1451
+ color: "#ffffff",
1452
+ border: "none",
1453
+ borderRadius: 8,
1454
+ fontSize: 14,
1455
+ fontWeight: 600,
1456
+ cursor: "pointer"
1457
+ };
1458
+ var secondaryButtonStyle = {
1459
+ ...primaryButtonStyle,
1460
+ background: "#ffffff",
1461
+ color: "#374151",
1462
+ border: "2px solid #e5e7eb"
1463
+ };
1464
+ var cancelButtonStyle = {
1465
+ ...primaryButtonStyle,
1466
+ background: "transparent",
1467
+ color: "#6b7280",
1468
+ border: "none"
1469
+ };
1470
+ var spinnerStyle = {
1471
+ width: 16,
1472
+ height: 16,
1473
+ border: "2px solid rgba(0, 188, 125, 0.25)",
1474
+ borderTopColor: "#00bc7d",
1475
+ borderRadius: "50%",
1476
+ animation: "spin .8s linear infinite"
1477
+ };
1478
+ var attemptsTextStyle = {
1479
+ margin: "8px 0 0",
1480
+ fontSize: 12,
1481
+ color: "#9ca3af",
1482
+ textAlign: "center"
1483
+ };
1484
+ var footerStyle = { padding: "12px 24px 16px", borderTop: "1px solid #f3f4f6" };
1485
+ var footerTextStyle = { margin: 0, fontSize: 12, color: "#9ca3af", textAlign: "center" };
1486
+ function LiveCamera({ onCapture, onCancel, message, assetBasePath }) {
1487
+ const videoRef = React.useRef(null);
1488
+ const streamRef = React.useRef(null);
1489
+ const samplesRef = React.useRef([]);
1490
+ const [ready, setReady] = React.useState(false);
1491
+ const [error, setError] = React.useState(null);
1492
+ const [faceStatus, setFaceStatus] = React.useState("idle");
1493
+ const [faceDetectionFailed, setFaceDetectionFailed] = React.useState(false);
1494
+ React.useEffect(() => {
1495
+ let cancelled = false;
1496
+ async function init() {
1497
+ try {
1498
+ if (typeof navigator === "undefined" || !navigator.mediaDevices?.getUserMedia) {
1499
+ throw new Error("Camera is not available in this browser");
1500
+ }
1501
+ const stream = await navigator.mediaDevices.getUserMedia({
1502
+ video: {
1503
+ facingMode: "user",
1504
+ width: { ideal: 1280 },
1505
+ height: { ideal: 1280 }
1506
+ },
1507
+ audio: false
1508
+ });
1509
+ if (cancelled) {
1510
+ stream.getTracks().forEach((t) => t.stop());
1511
+ return;
1512
+ }
1513
+ streamRef.current = stream;
1514
+ const video = videoRef.current;
1515
+ if (video) {
1516
+ video.srcObject = stream;
1517
+ video.onloadedmetadata = () => {
1518
+ video.play().catch(() => {
1519
+ });
1520
+ setReady(true);
1521
+ };
1522
+ }
1523
+ } catch (err) {
1524
+ setError(err instanceof Error ? err.message : "Unable to access camera");
1525
+ }
1526
+ }
1527
+ init();
1528
+ return () => {
1529
+ cancelled = true;
1530
+ streamRef.current?.getTracks().forEach((t) => t.stop());
1531
+ streamRef.current = null;
1532
+ };
1533
+ }, []);
1534
+ React.useEffect(() => {
1535
+ if (!ready) {
1536
+ setFaceStatus("idle");
1537
+ return;
1538
+ }
1539
+ let cancelled = false;
1540
+ let rafId = null;
1541
+ let detector = null;
1542
+ setFaceStatus("loading");
1543
+ setFaceDetectionFailed(false);
1544
+ samplesRef.current = [];
1545
+ (async () => {
1546
+ try {
1547
+ const FaceDetection = await loadMediaPipeFaceDetection(assetBasePath);
1548
+ if (cancelled) return;
1549
+ const assetBase = resolveMediaPipeBase(assetBasePath);
1550
+ const d = new FaceDetection({
1551
+ locateFile: (f) => `${assetBase}/${f}`
1552
+ });
1553
+ d.setOptions({ model: "short", minDetectionConfidence: 0.5 });
1554
+ d.onResults((results) => {
1555
+ if (cancelled) return;
1556
+ const detections = results.detections ?? [];
1557
+ const status = mapDetectionsToFaceStatus(detections);
1558
+ samplesRef.current.push({
1559
+ t: Date.now(),
1560
+ status,
1561
+ ...detections.length > 0 ? { boundingBox: detections[0].boundingBox } : {}
1562
+ });
1563
+ if (samplesRef.current.length > LIVENESS_SAMPLE_LIMIT) {
1564
+ samplesRef.current.shift();
1565
+ }
1566
+ setFaceStatus(status);
1567
+ });
1568
+ await d.initialize();
1569
+ if (cancelled) return;
1570
+ detector = d;
1571
+ setFaceStatus("scanning");
1572
+ const tick = async () => {
1573
+ if (cancelled) return;
1574
+ const v = videoRef.current;
1575
+ if (v?.readyState === 4 && detector) {
1576
+ try {
1577
+ await detector.send({ image: v });
1578
+ } catch {
1579
+ }
1580
+ }
1581
+ if (!cancelled) {
1582
+ rafId = requestAnimationFrame(tick);
1583
+ }
1584
+ };
1585
+ tick();
1586
+ } catch (err) {
1587
+ console.error("Face detection failed to initialize:", err);
1588
+ if (!cancelled) {
1589
+ setFaceDetectionFailed(true);
1590
+ setFaceStatus("scanning");
1591
+ }
1592
+ }
1593
+ })();
1594
+ return () => {
1595
+ cancelled = true;
1596
+ if (rafId !== null) cancelAnimationFrame(rafId);
1597
+ try {
1598
+ detector?.close?.();
1599
+ } catch {
1600
+ }
1601
+ };
1602
+ }, [ready, assetBasePath]);
1603
+ const capture = () => {
1604
+ const video = videoRef.current;
1605
+ if (!video || !video.videoWidth) return;
1606
+ const size = Math.min(video.videoWidth, video.videoHeight);
1607
+ const sx = (video.videoWidth - size) / 2;
1608
+ const sy = (video.videoHeight - size) / 2;
1609
+ const canvas = document.createElement("canvas");
1610
+ canvas.width = size;
1611
+ canvas.height = size;
1612
+ const ctx = canvas.getContext("2d");
1613
+ if (!ctx) return;
1614
+ ctx.translate(size, 0);
1615
+ ctx.scale(-1, 1);
1616
+ ctx.drawImage(video, sx, sy, size, size, 0, 0, size, size);
1617
+ streamRef.current?.getTracks().forEach((t) => t.stop());
1618
+ streamRef.current = null;
1619
+ onCapture(canvas.toDataURL("image/jpeg", 0.9), buildLivenessArtifact(samplesRef.current));
1620
+ };
1621
+ if (error) {
1622
+ return /* @__PURE__ */ React__default.default.createElement("div", { style: { ...contentStyle, alignItems: "center", textAlign: "center", padding: 0 } }, /* @__PURE__ */ React__default.default.createElement("div", { style: errorCircleStyle }, "!"), /* @__PURE__ */ React__default.default.createElement("h3", { style: titleStyle }, "Camera unavailable"), /* @__PURE__ */ React__default.default.createElement("p", { style: alertTextStyle }, error), /* @__PURE__ */ React__default.default.createElement("div", { style: buttonsContainerStyle }, /* @__PURE__ */ React__default.default.createElement("button", { style: secondaryButtonStyle, onClick: onCancel }, "Back")));
1623
+ }
1624
+ const detectionActive = ready && !faceDetectionFailed;
1625
+ const liveMessage = detectionActive ? FACE_MESSAGES[faceStatus] : message;
1626
+ const liveFaceColor = detectionActive ? FACE_COLORS[faceStatus] : void 0;
1627
+ const captureDisabled = isCaptureDisabled(ready, detectionActive, faceStatus);
1628
+ const ringPulse = detectionActive && (faceStatus === "too_far" || faceStatus === "too_close") ? "pulse 1.5s ease-in-out infinite" : void 0;
1629
+ const dynamicCircleStyle = {
1630
+ ...faceCircleStyle,
1631
+ ...liveFaceColor ? { borderColor: liveFaceColor } : null,
1632
+ ...ringPulse ? { animation: ringPulse } : null
1633
+ };
1634
+ return /* @__PURE__ */ React__default.default.createElement("div", { style: videoFrameStyle }, /* @__PURE__ */ React__default.default.createElement(
1635
+ "video",
1121
1636
  {
1122
- ref: inputRef,
1123
- type: "file",
1124
- accept: "image/*",
1125
- capture: isMobile ? "user" : void 0,
1126
- style: hiddenInputStyle,
1127
- onChange: handleFileChange,
1128
- disabled: isProcessing
1637
+ ref: videoRef,
1638
+ playsInline: true,
1639
+ muted: true,
1640
+ autoPlay: true,
1641
+ style: videoStyle
1129
1642
  }
1130
- ), /* @__PURE__ */ React__default.default.createElement("div", { style: buttonsContainerStyle }, /* @__PURE__ */ React__default.default.createElement(
1643
+ ), /* @__PURE__ */ React__default.default.createElement("div", { style: faceOverlayContainerStyle, "aria-hidden": "true" }, /* @__PURE__ */ React__default.default.createElement("div", { style: faceRingWrapStyle }, /* @__PURE__ */ React__default.default.createElement("div", { style: faceDashedRingStyle }), /* @__PURE__ */ React__default.default.createElement("div", { style: dynamicCircleStyle }))), liveMessage && /* @__PURE__ */ React__default.default.createElement("div", { style: liveMessagePillContainerStyle }, /* @__PURE__ */ React__default.default.createElement("div", { style: liveMessagePillStyle }, /* @__PURE__ */ React__default.default.createElement("span", { style: liveMessagePillTextStyle }, liveMessage))), /* @__PURE__ */ React__default.default.createElement(
1131
1644
  "button",
1132
1645
  {
1133
- onClick: () => inputRef.current?.click(),
1134
- onMouseEnter: () => setIsHoveringPrimary(true),
1135
- onMouseLeave: () => setIsHoveringPrimary(false),
1136
- disabled: isProcessing,
1137
- style: primaryButtonStyle
1646
+ type: "button",
1647
+ onClick: onCancel,
1648
+ "aria-label": "Close camera",
1649
+ style: overlayCloseButtonStyle
1138
1650
  },
1139
- isProcessing ? /* @__PURE__ */ React__default.default.createElement(React__default.default.Fragment, null, /* @__PURE__ */ React__default.default.createElement("div", { style: spinnerStyle }), /* @__PURE__ */ React__default.default.createElement("span", null, "Processing...")) : /* @__PURE__ */ React__default.default.createElement(React__default.default.Fragment, null, isMobile ? /* @__PURE__ */ React__default.default.createElement("img", { src: Camera, alt: "Camera Icon", width: 20, height: 20 }) : /* @__PURE__ */ React__default.default.createElement("img", { src: Upload, alt: "Upload Icon", width: 20, height: 20 }), /* @__PURE__ */ React__default.default.createElement("span", null, isMobile ? "Capture Photo" : "Upload Photo"))
1140
- ), /* @__PURE__ */ React__default.default.createElement(
1651
+ /* @__PURE__ */ React__default.default.createElement("img", { src: Close, alt: "", width: 16, height: 16 })
1652
+ ), !ready && /* @__PURE__ */ React__default.default.createElement("div", { style: videoLoadingStyle }, "Starting camera\u2026"), /* @__PURE__ */ React__default.default.createElement("div", { style: bottomGradientStyle }, /* @__PURE__ */ React__default.default.createElement(
1141
1653
  "button",
1142
1654
  {
1143
- onClick: onCancel,
1144
- onMouseEnter: () => setIsHoveringCancel(true),
1145
- onMouseLeave: () => setIsHoveringCancel(false),
1146
- disabled: isProcessing,
1147
- style: cancelButtonStyle
1655
+ type: "button",
1656
+ onClick: capture,
1657
+ disabled: captureDisabled,
1658
+ "aria-label": "Capture",
1659
+ style: captureDisabled ? { ...shutterButtonStyle, opacity: 0.5, cursor: "not-allowed" } : shutterButtonStyle
1148
1660
  },
1149
- "Cancel"
1150
- ))), /* @__PURE__ */ React__default.default.createElement("div", { style: footerStyle }, /* @__PURE__ */ React__default.default.createElement("p", { style: footerTextStyle }, "Your photo will be securely processed and used only for verification purposes")))));
1661
+ /* @__PURE__ */ React__default.default.createElement("span", { style: shutterInnerStyle })
1662
+ )));
1151
1663
  }
1664
+ var videoFrameStyle = {
1665
+ position: "relative",
1666
+ width: "100%",
1667
+ aspectRatio: "3 / 4",
1668
+ borderRadius: 24,
1669
+ overflow: "hidden",
1670
+ background: "#000000",
1671
+ border: "4px solid rgba(255, 255, 255, 0.08)",
1672
+ boxShadow: "0 25px 50px -12px rgba(0, 0, 0, 0.5)"
1673
+ };
1674
+ var overlayCloseButtonStyle = {
1675
+ position: "absolute",
1676
+ top: 12,
1677
+ right: 12,
1678
+ width: 32,
1679
+ height: 32,
1680
+ display: "inline-flex",
1681
+ alignItems: "center",
1682
+ justifyContent: "center",
1683
+ padding: 0,
1684
+ border: "none",
1685
+ borderRadius: "50%",
1686
+ background: "rgba(0, 0, 0, 0.4)",
1687
+ backdropFilter: "blur(6px)",
1688
+ color: "#ffffff",
1689
+ cursor: "pointer",
1690
+ zIndex: 10
1691
+ };
1692
+ var bottomGradientStyle = {
1693
+ position: "absolute",
1694
+ bottom: 0,
1695
+ left: 0,
1696
+ right: 0,
1697
+ padding: "16px",
1698
+ background: "linear-gradient(to top, rgba(0, 0, 0, 0.8) 0%, rgba(0, 0, 0, 0) 100%)",
1699
+ display: "flex",
1700
+ alignItems: "center",
1701
+ justifyContent: "center",
1702
+ zIndex: 10
1703
+ };
1704
+ var shutterButtonStyle = {
1705
+ width: 64,
1706
+ height: 64,
1707
+ borderRadius: "50%",
1708
+ background: "rgba(255, 255, 255, 0.15)",
1709
+ backdropFilter: "blur(6px)",
1710
+ border: "2px solid rgba(255, 255, 255, 0.7)",
1711
+ display: "inline-flex",
1712
+ alignItems: "center",
1713
+ justifyContent: "center",
1714
+ cursor: "pointer",
1715
+ padding: 0,
1716
+ transition: "transform 120ms ease-out, background 120ms"
1717
+ };
1718
+ var shutterInnerStyle = {
1719
+ display: "block",
1720
+ width: 44,
1721
+ height: 44,
1722
+ borderRadius: "50%",
1723
+ background: "rgba(255, 255, 255, 0.85)"
1724
+ };
1725
+ var videoStyle = {
1726
+ width: "100%",
1727
+ height: "100%",
1728
+ objectFit: "cover",
1729
+ transform: "scaleX(-1)"
1730
+ // mirror so the preview matches the user's POV
1731
+ };
1732
+ var faceOverlayContainerStyle = {
1733
+ position: "absolute",
1734
+ inset: 0,
1735
+ pointerEvents: "none",
1736
+ display: "flex",
1737
+ alignItems: "center",
1738
+ justifyContent: "center"
1739
+ };
1740
+ var faceRingWrapStyle = {
1741
+ position: "relative",
1742
+ width: "72%",
1743
+ aspectRatio: "1 / 1"
1744
+ };
1745
+ var faceDashedRingStyle = {
1746
+ position: "absolute",
1747
+ inset: -6,
1748
+ borderRadius: "50%",
1749
+ border: "6px dashed rgba(255, 255, 255, 0.4)",
1750
+ animation: "spin 10s linear infinite"
1751
+ };
1752
+ var faceCircleStyle = {
1753
+ position: "absolute",
1754
+ inset: 0,
1755
+ borderRadius: "50%",
1756
+ border: "4px solid #00bc7d",
1757
+ boxShadow: "0 0 0 1000px rgba(0, 0, 0, 0.5)"
1758
+ };
1759
+ var videoLoadingStyle = {
1760
+ position: "absolute",
1761
+ inset: 0,
1762
+ display: "flex",
1763
+ alignItems: "center",
1764
+ justifyContent: "center",
1765
+ color: "#e5e7eb",
1766
+ fontSize: 14,
1767
+ fontWeight: 500,
1768
+ background: "rgba(0, 0, 0, 0.4)",
1769
+ zIndex: 5
1770
+ };
1771
+ var liveMessagePillContainerStyle = {
1772
+ position: "absolute",
1773
+ top: 12,
1774
+ left: "50%",
1775
+ transform: "translateX(-50%)",
1776
+ maxWidth: "84%",
1777
+ pointerEvents: "none"
1778
+ };
1779
+ var liveMessagePillStyle = {
1780
+ background: "rgba(0, 0, 0, 0.7)",
1781
+ backdropFilter: "blur(6px)",
1782
+ border: "1px solid rgba(255, 255, 255, 0.2)",
1783
+ borderRadius: 999,
1784
+ padding: "6px 12px",
1785
+ textAlign: "center",
1786
+ boxShadow: "0 10px 25px -5px rgba(0,0,0,.3)"
1787
+ };
1788
+ var liveMessagePillTextStyle = {
1789
+ margin: 0,
1790
+ fontSize: 12,
1791
+ fontWeight: 500,
1792
+ color: "#ffffff",
1793
+ animation: "pulse 2s ease-in-out infinite"
1794
+ };
1152
1795
  var FaceCaptureModal_default = FaceCaptureModal;
1153
1796
 
1154
1797
  // src/kyc/hooks.ts
@@ -1432,7 +2075,7 @@ function useKycPreferences(client, autoFetch = true) {
1432
2075
  refresh: fetchPreferences
1433
2076
  };
1434
2077
  }
1435
- function fileToBase642(file) {
2078
+ function fileToBase64(file) {
1436
2079
  return new Promise((resolve, reject) => {
1437
2080
  const reader = new FileReader();
1438
2081
  reader.onload = () => {
@@ -1488,44 +2131,55 @@ function getRiskColor(risk) {
1488
2131
  };
1489
2132
  return colorMap[risk] || "#6b7280";
1490
2133
  }
1491
- function useReuseKYCSubmission(client$1) {
1492
- const verifyFace = (reference, token) => {
1493
- return new Promise((resolve, reject) => {
2134
+ function useEventBasedFaceVerificationSubmission(client$1) {
2135
+ const startSession = React.useCallback(
2136
+ (request) => client$1.createEventBasedFaceVerificationSession(request),
2137
+ [client$1]
2138
+ );
2139
+ const verifyFace = React.useCallback(
2140
+ (session, opts = {}) => new Promise((resolve) => {
1494
2141
  const container = document.createElement("div");
1495
2142
  document.body.appendChild(container);
1496
2143
  const root = client.createRoot(container);
1497
2144
  const cleanup = () => {
1498
2145
  root.unmount();
1499
- document.body.removeChild(container);
2146
+ container.remove();
1500
2147
  };
1501
2148
  const modal = React.createElement(FaceCaptureModal_default, {
1502
- onCapture: async (base64) => {
1503
- try {
1504
- const resp = await client$1.submitReuseKycSession({
1505
- proof: base64,
1506
- reference,
1507
- token
1508
- });
1509
- resolve(resp);
1510
- } catch (error) {
1511
- reject(error instanceof Error ? error : new Error("Face verification failed"));
1512
- } finally {
1513
- cleanup();
1514
- }
1515
- },
1516
- onCancel: () => {
2149
+ client: client$1,
2150
+ session,
2151
+ defaultDevice: opts.defaultDevice,
2152
+ renderQR: opts.renderQR,
2153
+ onCancel: opts.onCancel,
2154
+ mediapipeAssetBasePath: opts.mediapipeAssetBasePath,
2155
+ onComplete: (result) => {
1517
2156
  cleanup();
1518
- resolve(null);
2157
+ resolve(result);
1519
2158
  }
1520
2159
  });
1521
2160
  root.render(modal);
1522
- });
1523
- };
1524
- return { verifyFace };
2161
+ }),
2162
+ [client$1]
2163
+ );
2164
+ const runFlow = React.useCallback(
2165
+ async (request, opts = {}) => {
2166
+ const session = await startSession(request);
2167
+ if (!session.is_required) {
2168
+ return { kind: "not_required", session };
2169
+ }
2170
+ const result = await verifyFace(session, opts);
2171
+ if (result === null) {
2172
+ return { kind: "cancelled", session };
2173
+ }
2174
+ return { kind: "completed", session, result };
2175
+ },
2176
+ [startSession, verifyFace]
2177
+ );
2178
+ return { startSession, verifyFace, runFlow };
1525
2179
  }
1526
2180
 
1527
2181
  exports.createDeviceFingerprint = createDeviceFingerprint;
1528
- exports.fileToBase64 = fileToBase642;
2182
+ exports.fileToBase64 = fileToBase64;
1529
2183
  exports.formatKycStatus = formatKycStatus;
1530
2184
  exports.getBrowserInfo = getBrowserInfo;
1531
2185
  exports.getRiskColor = getRiskColor;
@@ -1534,6 +2188,7 @@ exports.isValidFileSize = isValidFileSize;
1534
2188
  exports.isValidFileType = isValidFileType;
1535
2189
  exports.useCipherText = useCipherText;
1536
2190
  exports.useCustomerProfile = useCustomerProfile;
2191
+ exports.useEventBasedFaceVerificationSubmission = useEventBasedFaceVerificationSubmission;
1537
2192
  exports.useGeolocation = useGeolocation;
1538
2193
  exports.useKycAlerts = useKycAlerts;
1539
2194
  exports.useKycOverview = useKycOverview;
@@ -1544,7 +2199,6 @@ exports.useLocationCapture = useLocationCapture;
1544
2199
  exports.useLocationRequests = useLocationRequests;
1545
2200
  exports.useLoginVerification = useLoginVerification;
1546
2201
  exports.useRegistration = useRegistration;
1547
- exports.useReuseKYCSubmission = useReuseKYCSubmission;
1548
2202
  exports.useTransactionVerification = useTransactionVerification;
1549
2203
  //# sourceMappingURL=react.js.map
1550
2204
  //# sourceMappingURL=react.js.map