vesant-sdk 1.6.6 → 1.7.0-dev.362ac6b

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