vesant-sdk 1.6.6-next.ac58d2b → 1.7.0-dev.059da4f

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