vesant-sdk 1.6.6 → 2.0.0-dev.0d9ee60

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-BJ87_Vv5.d.ts +430 -0
  3. package/dist/{client-ePzhQKp9.d.mts → client-BolQlL5e.d.mts} +1 -1
  4. package/dist/{client-ePzhQKp9.d.ts → client-BolQlL5e.d.ts} +1 -1
  5. package/dist/{client-BlCxjbY2.d.mts → client-Bvp-f05-.d.ts} +7 -7
  6. package/dist/{client-C_A7QLcB.d.ts → client-CIEa7xYG.d.mts} +7 -7
  7. package/dist/client-IAOGCBfm.d.mts +430 -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 +137 -58
  11. package/dist/compliance/index.js.map +1 -1
  12. package/dist/compliance/index.mjs +137 -59
  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 +6 -24
  23. package/dist/geolocation/index.js.map +1 -1
  24. package/dist/geolocation/index.mjs +6 -24
  25. package/dist/geolocation/index.mjs.map +1 -1
  26. package/dist/index.d.mts +14 -71
  27. package/dist/index.d.ts +14 -71
  28. package/dist/index.js +244 -247
  29. package/dist/index.js.map +1 -1
  30. package/dist/index.mjs +243 -246
  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 +267 -44
  39. package/dist/kyc/index.d.ts +267 -44
  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 +42 -7
  45. package/dist/react.d.ts +42 -7
  46. package/dist/react.js +621 -277
  47. package/dist/react.js.map +1 -1
  48. package/dist/react.mjs +621 -277
  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-X5Md_dD_.d.ts → types-2utj53GK.d.ts} +2 -2
  69. package/dist/{types-1RzYeSal.d.mts → types-C4Zx0d_u.d.mts} +2 -2
  70. package/dist/{types-B4Ezqo7V.d.mts → types-QUCWam16.d.mts} +7 -1
  71. package/dist/{types-B4Ezqo7V.d.ts → types-QUCWam16.d.ts} +7 -1
  72. package/dist/webhooks/index.d.mts +181 -2
  73. package/dist/webhooks/index.d.ts +181 -2
  74. package/dist/webhooks/index.js +49 -7
  75. package/dist/webhooks/index.js.map +1 -1
  76. package/dist/webhooks/index.mjs +49 -7
  77. package/dist/webhooks/index.mjs.map +1 -1
  78. package/package.json +16 -13
  79. package/dist/fraud/index.d.mts +0 -80
  80. package/dist/fraud/index.d.ts +0 -80
  81. package/dist/fraud/index.js +0 -606
  82. package/dist/fraud/index.js.map +0 -1
  83. package/dist/fraud/index.mjs +0 -604
  84. package/dist/fraud/index.mjs.map +0 -1
  85. package/dist/index-B04H4xfJ.d.mts +0 -320
  86. package/dist/index-CItMPmLL.d.ts +0 -320
package/dist/react.js CHANGED
@@ -10,7 +10,19 @@ var React__default = /*#__PURE__*/_interopDefault(React);
10
10
  // src/geolocation/hooks.ts
11
11
 
12
12
  // src/core/version.ts
13
- var SDK_VERSION = "1.6.6";
13
+ var SDK_VERSION = "2.0.0";
14
+
15
+ // src/core/errors.ts
16
+ var VesantError = class _VesantError extends Error {
17
+ constructor(message, code, statusCode, details) {
18
+ super(message);
19
+ this.code = code;
20
+ this.statusCode = statusCode;
21
+ this.details = details;
22
+ this.name = "VesantError";
23
+ Object.setPrototypeOf(this, _VesantError.prototype);
24
+ }
25
+ };
14
26
 
15
27
  // src/shared/browser-utils.ts
16
28
  function generateUUID() {
@@ -200,7 +212,7 @@ function encodePayload(payload) {
200
212
  } else if (typeof Buffer !== "undefined") {
201
213
  return Buffer.from(json, "utf-8").toString("base64");
202
214
  }
203
- throw new Error("No base64 encoding method available");
215
+ throw new VesantError("No base64 encoding method available", "BASE64_UNAVAILABLE");
204
216
  }
205
217
  async function generateCipherText(options, config) {
206
218
  const warnings = [];
@@ -225,8 +237,9 @@ async function generateCipherText(options, config) {
225
237
  if (location) {
226
238
  locationData = location;
227
239
  } else if (gpsRequiredByConfig) {
228
- throw new Error(
229
- `GPS location is required for ${options.reason} by tenant configuration, but GPS was not available or permission was denied`
240
+ throw new VesantError(
241
+ `GPS location is required for ${options.reason} by tenant configuration, but GPS was not available or permission was denied`,
242
+ "GPS_REQUIRED"
230
243
  );
231
244
  } else {
232
245
  warnings.push("GPS location not available or permission denied");
@@ -839,7 +852,7 @@ function useCustomerProfile(client, customerId, options = {}) {
839
852
  profileRef.current = profile;
840
853
  const updateProfile = React.useCallback(
841
854
  async (updates) => {
842
- if (!profileRef.current) throw new Error("Profile not loaded");
855
+ if (!profileRef.current) throw new VesantError("Profile not loaded", "PROFILE_NOT_LOADED");
843
856
  setLoading(true);
844
857
  setError(null);
845
858
  try {
@@ -878,277 +891,599 @@ var Close = "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0id
878
891
  var Upload = "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48IS0tIFVwbG9hZGVkIHRvOiBTVkcgUmVwbywgd3d3LnN2Z3JlcG8uY29tLCBHZW5lcmF0b3I6IFNWRyBSZXBvIE1peGVyIFRvb2xzIC0tPg0KPHN2ZyB3aWR0aD0iODAwcHgiIGhlaWdodD0iODAwcHgiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4NCjxwYXRoIGQ9Ik0xNyAxN0gxNy4wMU0xNS42IDE0SDE4QzE4LjkzMTkgMTQgMTkuMzk3OCAxNCAxOS43NjU0IDE0LjE1MjJDMjAuMjU1NCAxNC4zNTUyIDIwLjY0NDggMTQuNzQ0NiAyMC44NDc4IDE1LjIzNDZDMjEgMTUuNjAyMiAyMSAxNi4wNjgxIDIxIDE3QzIxIDE3LjkzMTkgMjEgMTguMzk3OCAyMC44NDc4IDE4Ljc2NTRDMjAuNjQ0OCAxOS4yNTU0IDIwLjI1NTQgMTkuNjQ0OCAxOS43NjU0IDE5Ljg0NzhDMTkuMzk3OCAyMCAxOC45MzE5IDIwIDE4IDIwSDZDNS4wNjgxMiAyMCA0LjYwMjE4IDIwIDQuMjM0NjMgMTkuODQ3OEMzLjc0NDU4IDE5LjY0NDggMy4zNTUyMyAxOS4yNTU0IDMuMTUyMjQgMTguNzY1NEMzIDE4LjM5NzggMyAxNy45MzE5IDMgMTdDMyAxNi4wNjgxIDMgMTUuNjAyMiAzLjE1MjI0IDE1LjIzNDZDMy4zNTUyMyAxNC43NDQ2IDMuNzQ0NTggMTQuMzU1MiA0LjIzNDYzIDE0LjE1MjJDNC42MDIxOCAxNCA1LjA2ODEyIDE0IDYgMTRIOC40TTEyIDE1VjRNMTIgNEwxNSA3TTEyIDRMOSA3IiBzdHJva2U9IiMwMDAwMDAiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIi8+DQo8L3N2Zz4=";
879
892
 
880
893
  // src/kyc/FaceCaptureModal.tsx
881
- var fileToBase64 = (file) => {
882
- return new Promise((resolve, reject) => {
883
- const reader = new FileReader();
884
- reader.readAsDataURL(file);
885
- reader.onload = () => resolve(reader.result);
886
- reader.onerror = (error) => reject(error);
887
- });
888
- };
894
+ var MOBILE_UA = /Mobi|Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i;
895
+ var LIVENESS_MESSAGES = [
896
+ "Align your face in the oval",
897
+ "Face too far. Please, move closer to the camera",
898
+ "Looking good! Stay still...",
899
+ "Processing liveness..."
900
+ ];
901
+ function headerSubtitle(stageKind) {
902
+ switch (stageKind) {
903
+ case "qr":
904
+ return "Use your phone to continue";
905
+ case "accepted":
906
+ return "All set";
907
+ case "declined":
908
+ return "Verification didn't match \u2014 try once more";
909
+ case "max_attempts":
910
+ return "We couldn't verify you";
911
+ default:
912
+ return "Please capture a clear photo of your face";
913
+ }
914
+ }
915
+ function defaultRenderQR(payload) {
916
+ const url = `https://api.qrserver.com/v1/create-qr-code/?size=220x220&data=${encodeURIComponent(payload)}`;
917
+ return /* @__PURE__ */ React__default.default.createElement("img", { src: url, alt: "QR code", width: 220, height: 220 });
918
+ }
889
919
  function FaceCaptureModal({
890
- onCapture,
891
- onCancel
920
+ client,
921
+ session,
922
+ onComplete,
923
+ defaultDevice,
924
+ renderQR
892
925
  }) {
893
- const inputRef = React.useRef(null);
894
- const [isProcessing, setIsProcessing] = React.useState(false);
895
- const [isHoveringPrimary, setIsHoveringPrimary] = React.useState(false);
896
- const [isHoveringCancel, setIsHoveringCancel] = React.useState(false);
897
- const [isHoveringClose, setIsHoveringClose] = React.useState(false);
898
- const isMobile = /Mobi|Android/i.test(navigator.userAgent);
899
- const handleFileChange = async (e) => {
900
- const file = e.target.files?.[0];
901
- if (!file) return;
902
- setIsProcessing(true);
903
- try {
904
- const base64 = await fileToBase64(file);
905
- setTimeout(() => {
906
- onCapture(base64);
907
- }, 300);
908
- } catch (error) {
909
- console.error("[Vesant SDK] Error processing image:", error instanceof Error ? error.message : "Unknown error");
910
- setIsProcessing(false);
926
+ const isMobile = typeof navigator !== "undefined" && MOBILE_UA.test(navigator.userAgent);
927
+ const initialStage = (() => {
928
+ const choice = defaultDevice ?? (isMobile ? "this" : "ask");
929
+ if (choice === "this") return { kind: "capture" };
930
+ if (choice === "mobile") return { kind: "qr", mobileConnected: false };
931
+ return { kind: "choose" };
932
+ })();
933
+ const [stage, setStage] = React.useState(initialStage);
934
+ const [attempts, setAttempts] = React.useState(session.attempts);
935
+ const maxAttempts = session.max_attempts || 1;
936
+ const [qrDeclinedReason, setQrDeclinedReason] = React.useState(null);
937
+ const [captureMode, setCaptureMode] = React.useState("idle");
938
+ const [capturedPreview, setCapturedPreview] = React.useState(null);
939
+ const [capturedBase64, setCapturedBase64] = React.useState(null);
940
+ const [livenessMessage, setLivenessMessage] = React.useState(LIVENESS_MESSAGES[0]);
941
+ const qrPayload = session.link || `vesant://reuse-kyc?token=${encodeURIComponent(session.token)}`;
942
+ const cancelledRef = React.useRef(false);
943
+ const submittingRef = React.useRef(false);
944
+ React.useEffect(() => {
945
+ if (stage.kind !== "qr") return;
946
+ let stopped = false;
947
+ const intervalMs = 2e3;
948
+ const deadline = Date.now() + 15 * 60 * 1e3;
949
+ let mobileSeen = stage.mobileConnected;
950
+ const tick = async () => {
951
+ if (stopped || cancelledRef.current) return;
952
+ try {
953
+ if (mobileSeen) {
954
+ const result = await client.getReuseKycSessionStatus(session.reference);
955
+ if (result.status === "accepted") {
956
+ setStage({ kind: "accepted", result });
957
+ stopped = true;
958
+ return;
959
+ }
960
+ if (result.status === "declined") {
961
+ setAttempts(maxAttempts - (result.data?.retries_remaining ?? 0));
962
+ if (result.data?.retry_limit_exceeded) {
963
+ setStage({ kind: "max_attempts", result });
964
+ stopped = true;
965
+ return;
966
+ }
967
+ if (result.declined_reason) {
968
+ setQrDeclinedReason(result.declined_reason);
969
+ }
970
+ }
971
+ } else {
972
+ const handoff = await client.getHandoffSession(session.token);
973
+ if (handoff.mobile_connected) {
974
+ mobileSeen = true;
975
+ setStage({ kind: "qr", mobileConnected: true });
976
+ }
977
+ }
978
+ } catch {
979
+ }
980
+ if (Date.now() < deadline) {
981
+ setTimeout(tick, intervalMs);
982
+ }
983
+ };
984
+ tick();
985
+ return () => {
986
+ stopped = true;
987
+ };
988
+ }, [stage.kind, stage.kind === "qr" ? stage.mobileConnected : false]);
989
+ const applyResult = (result) => {
990
+ if (result.status === "accepted") {
991
+ setStage({ kind: "accepted", result });
992
+ return true;
911
993
  }
994
+ if (result.status === "declined") {
995
+ const nextAttempts = maxAttempts - (result.data?.retries_remaining ?? 0);
996
+ setAttempts(nextAttempts);
997
+ setCapturedPreview(null);
998
+ setCapturedBase64(null);
999
+ if (result.data?.retry_limit_exceeded) {
1000
+ setStage({ kind: "max_attempts", result });
1001
+ } else {
1002
+ setStage({ kind: "declined", result });
1003
+ }
1004
+ return true;
1005
+ }
1006
+ return false;
912
1007
  };
913
- const overlayStyle = {
914
- position: "fixed",
915
- inset: 0,
916
- background: "rgba(0, 0, 0, 0.6)",
917
- backdropFilter: "blur(4px)",
918
- display: "flex",
919
- alignItems: "center",
920
- justifyContent: "center",
921
- zIndex: 999999,
922
- padding: "16px",
923
- animation: "fadeIn 0.2s ease-out"
924
- };
925
- const modalStyle = {
926
- background: "#ffffff",
927
- borderRadius: "16px",
928
- boxShadow: "0 25px 50px -12px rgba(0, 0, 0, 0.25)",
929
- width: "100%",
930
- maxWidth: "448px",
931
- animation: "zoomIn 0.2s ease-out"
932
- };
933
- const headerStyle = {
934
- position: "relative",
935
- padding: "24px 24px 16px",
936
- borderBottom: "1px solid #f3f4f6"
937
- };
938
- const closeButtonStyle = {
939
- position: "absolute",
940
- top: "16px",
941
- right: "16px",
942
- padding: "8px",
943
- background: isHoveringClose ? "#f3f4f6" : "transparent",
944
- border: "none",
945
- borderRadius: "9999px",
946
- cursor: "pointer",
947
- transition: "background-color 0.2s",
948
- display: "flex",
949
- alignItems: "center",
950
- justifyContent: "center"
951
- };
952
- const titleStyle = {
953
- fontSize: "24px",
954
- fontWeight: 600,
955
- color: "#111827",
956
- margin: 0
957
- };
958
- const subtitleStyle = {
959
- fontSize: "14px",
960
- color: "#6b7280",
961
- marginTop: "4px"
962
- };
963
- const contentStyle = {
964
- padding: "32px 24px"
965
- };
966
- const visualGuideContainerStyle = {
967
- marginBottom: "32px",
968
- display: "flex",
969
- justifyContent: "center"
970
- };
971
- const visualGuideStyle = {
972
- position: "relative"
973
- };
974
- const circleStyle = {
975
- width: "128px",
976
- height: "128px",
977
- borderRadius: "50%",
978
- background: "linear-gradient(135deg, rgba(0, 188, 125, 0.2) 0%, rgba(0, 188, 125, 0.05) 100%)",
979
- display: "flex",
980
- alignItems: "center",
981
- justifyContent: "center"
982
- };
983
- const badgeStyle = {
984
- position: "absolute",
985
- top: "-4px",
986
- right: "-4px",
987
- width: "32px",
988
- height: "32px",
989
- background: "#ffffff",
990
- borderRadius: "50%",
991
- boxShadow: "0 4px 6px -1px rgba(0, 0, 0, 0.1)",
992
- display: "flex",
993
- alignItems: "center",
994
- justifyContent: "center"
995
- };
996
- const instructionsBoxStyle = {
997
- background: "linear-gradient(135deg, #f9fafb 0%, rgba(243, 244, 246, 0.5) 100%)",
998
- borderRadius: "12px",
999
- padding: "16px",
1000
- marginBottom: "24px"
1001
- };
1002
- const instructionsTitleStyle = {
1003
- fontSize: "14px",
1004
- fontWeight: 500,
1005
- color: "#111827",
1006
- marginBottom: "8px"
1007
- };
1008
- const instructionsListStyle = {
1009
- fontSize: "12px",
1010
- color: "#6b7280",
1011
- listStyle: "none",
1012
- padding: 0,
1013
- margin: 0
1014
- };
1015
- const instructionItemStyle = {
1016
- display: "flex",
1017
- alignItems: "flex-start",
1018
- marginBottom: "6px"
1019
- };
1020
- const bulletStyle = {
1021
- color: "#00bc7d",
1022
- marginRight: "8px",
1023
- flexShrink: 0
1024
- };
1025
- const buttonsContainerStyle = {
1026
- display: "flex",
1027
- flexDirection: "column",
1028
- gap: "12px"
1008
+ const runSubmit = async (proof) => {
1009
+ if (submittingRef.current) return;
1010
+ submittingRef.current = true;
1011
+ setStage({ kind: "submitting" });
1012
+ let settled = false;
1013
+ const ref = session.reference;
1014
+ try {
1015
+ const postPromise = (async () => {
1016
+ try {
1017
+ const data = await client.submitReuseKycSession({
1018
+ token: session.token,
1019
+ reference: ref,
1020
+ proof
1021
+ });
1022
+ return { ok: true, data };
1023
+ } catch (err2) {
1024
+ return { ok: false, error: err2 };
1025
+ }
1026
+ })();
1027
+ const pollPromise = (async () => {
1028
+ await new Promise((r) => setTimeout(r, 12e3));
1029
+ const deadline = Date.now() + 12e4;
1030
+ while (Date.now() < deadline) {
1031
+ if (settled || cancelledRef.current) return null;
1032
+ try {
1033
+ const r = await client.getReuseKycSessionStatus(ref);
1034
+ if (r.status === "accepted" || r.status === "declined") return r;
1035
+ } catch {
1036
+ }
1037
+ if (settled || cancelledRef.current) return null;
1038
+ await new Promise((r) => setTimeout(r, 3e3));
1039
+ }
1040
+ return null;
1041
+ })();
1042
+ const winner = await Promise.race([
1043
+ postPromise.then(
1044
+ (r) => r.ok ? { from: "post", data: r.data } : { from: "post_err" }
1045
+ ),
1046
+ pollPromise.then(
1047
+ (data) => data ? { from: "poll", data } : { from: "poll_done" }
1048
+ )
1049
+ ]);
1050
+ settled = true;
1051
+ if (winner.from === "post" && applyResult(winner.data)) return;
1052
+ if (winner.from === "poll" && applyResult(winner.data)) return;
1053
+ const [postResult, pollResult] = await Promise.all([postPromise, pollPromise]);
1054
+ if (postResult.ok && applyResult(postResult.data)) return;
1055
+ if (pollResult && applyResult(pollResult)) return;
1056
+ const err = postResult.ok ? null : postResult.error;
1057
+ setStage({
1058
+ kind: "error",
1059
+ message: err instanceof Error ? err.message : "Submission failed. Please try again."
1060
+ });
1061
+ } finally {
1062
+ settled = true;
1063
+ submittingRef.current = false;
1064
+ }
1029
1065
  };
1030
- const primaryButtonStyle = {
1031
- width: "100%",
1032
- background: isProcessing ? "#d1d5db" : isHoveringPrimary ? "#00a86d" : "#00bc7d",
1033
- color: "#ffffff",
1034
- fontWeight: 500,
1035
- padding: "14px 24px",
1036
- borderRadius: "12px",
1037
- border: "none",
1038
- cursor: isProcessing ? "not-allowed" : "pointer",
1039
- transition: "all 0.2s",
1040
- display: "flex",
1041
- alignItems: "center",
1042
- justifyContent: "center",
1043
- gap: "12px",
1044
- boxShadow: isProcessing ? "none" : isHoveringPrimary ? "0 20px 25px -5px rgba(0, 188, 125, 0.3)" : "0 10px 15px -3px rgba(0, 188, 125, 0.2)",
1045
- fontSize: "16px"
1066
+ const handleCameraCapture = (dataUrl) => {
1067
+ const raw = dataUrl.split(",")[1] ?? "";
1068
+ setCapturedPreview(dataUrl);
1069
+ setCapturedBase64(raw);
1070
+ setCaptureMode("preview");
1046
1071
  };
1047
- const cancelButtonStyle = {
1048
- width: "100%",
1049
- background: isProcessing ? "#f3f4f6" : isHoveringCancel ? "#f9fafb" : "#ffffff",
1050
- color: "#374151",
1051
- fontWeight: 500,
1052
- padding: "14px 24px",
1053
- borderRadius: "12px",
1054
- border: "2px solid #e5e7eb",
1055
- cursor: isProcessing ? "not-allowed" : "pointer",
1056
- transition: "all 0.2s",
1057
- fontSize: "16px"
1072
+ const handleCameraCancel = () => setCaptureMode("idle");
1073
+ const handleRetake = () => {
1074
+ setCapturedPreview(null);
1075
+ setCapturedBase64(null);
1076
+ setCaptureMode("live");
1058
1077
  };
1059
- const footerStyle = {
1060
- padding: "0 24px 24px"
1078
+ const handleConfirmSubmit = () => {
1079
+ if (!capturedBase64) return;
1080
+ void runSubmit(capturedBase64);
1061
1081
  };
1062
- const footerTextStyle = {
1063
- fontSize: "12px",
1064
- textAlign: "center",
1065
- color: "#9ca3af",
1066
- margin: 0
1082
+ const handleOpenCamera = () => {
1083
+ if (submittingRef.current) return;
1084
+ setCaptureMode("live");
1067
1085
  };
1068
- const spinnerStyle = {
1069
- width: "20px",
1070
- height: "20px",
1071
- border: "2px solid rgba(255, 255, 255, 0.3)",
1072
- borderTopColor: "#ffffff",
1073
- borderRadius: "50%",
1074
- animation: "spin 0.6s linear infinite"
1086
+ const handleRetakeAfterDecline = () => {
1087
+ setCapturedPreview(null);
1088
+ setCapturedBase64(null);
1089
+ setCaptureMode("live");
1090
+ setStage({ kind: "capture" });
1075
1091
  };
1076
- const hiddenInputStyle = {
1077
- display: "none"
1092
+ React.useEffect(() => {
1093
+ if (captureMode !== "live") return;
1094
+ setLivenessMessage(LIVENESS_MESSAGES[0]);
1095
+ let i = 0;
1096
+ const interval = setInterval(() => {
1097
+ i = (i + 1) % LIVENESS_MESSAGES.length;
1098
+ setLivenessMessage(LIVENESS_MESSAGES[i]);
1099
+ }, 3e3);
1100
+ return () => clearInterval(interval);
1101
+ }, [captureMode]);
1102
+ const close = (result) => {
1103
+ cancelledRef.current = true;
1104
+ onComplete(result);
1078
1105
  };
1079
- const styleTag = /* @__PURE__ */ React__default.default.createElement("style", null, `
1080
- @keyframes fadeIn {
1081
- from {
1082
- opacity: 0;
1083
- }
1084
- to {
1085
- opacity: 1;
1086
- }
1087
- }
1088
-
1089
- @keyframes zoomIn {
1090
- from {
1091
- opacity: 0;
1092
- transform: scale(0.95);
1093
- }
1094
- to {
1095
- opacity: 1;
1096
- transform: scale(1);
1097
- }
1098
- }
1099
-
1100
- @keyframes spin {
1101
- from {
1102
- transform: rotate(0deg);
1103
- }
1104
- to {
1105
- transform: rotate(360deg);
1106
- }
1107
- }
1108
- `);
1109
- return /* @__PURE__ */ React__default.default.createElement(React__default.default.Fragment, null, styleTag, /* @__PURE__ */ React__default.default.createElement("div", { style: overlayStyle }, /* @__PURE__ */ React__default.default.createElement("div", { style: modalStyle }, /* @__PURE__ */ React__default.default.createElement("div", { style: headerStyle }, /* @__PURE__ */ React__default.default.createElement(
1106
+ const renderChoose = () => /* @__PURE__ */ React__default.default.createElement("div", { style: contentStyle }, /* @__PURE__ */ React__default.default.createElement("div", { style: visualGuideContainerStyle }, /* @__PURE__ */ React__default.default.createElement("div", { style: visualGuideStyle }, /* @__PURE__ */ React__default.default.createElement("div", { style: circleStyle }, /* @__PURE__ */ React__default.default.createElement("img", { src: Camera, alt: "", width: 48, height: 48 })))), /* @__PURE__ */ React__default.default.createElement("p", { style: subtitleStyle }, "How would you like to verify?"), /* @__PURE__ */ React__default.default.createElement("div", { style: buttonsContainerStyle }, /* @__PURE__ */ React__default.default.createElement(
1110
1107
  "button",
1111
1108
  {
1112
- onClick: onCancel,
1113
- onMouseEnter: () => setIsHoveringClose(true),
1114
- onMouseLeave: () => setIsHoveringClose(false),
1115
- style: closeButtonStyle,
1116
- "aria-label": "Close"
1109
+ style: primaryButtonStyle,
1110
+ onClick: () => setStage({ kind: "capture" })
1111
+ },
1112
+ /* @__PURE__ */ React__default.default.createElement("img", { src: isMobile ? Camera : Upload, alt: "", width: 20, height: 20 }),
1113
+ /* @__PURE__ */ React__default.default.createElement("span", null, "Continue on this device")
1114
+ ), /* @__PURE__ */ React__default.default.createElement(
1115
+ "button",
1116
+ {
1117
+ style: secondaryButtonStyle,
1118
+ onClick: () => setStage({ kind: "qr", mobileConnected: false })
1117
1119
  },
1118
- /* @__PURE__ */ React__default.default.createElement("img", { src: Close, alt: "Close Icon", width: 16, height: 16 })
1119
- ), /* @__PURE__ */ React__default.default.createElement("h2", { style: titleStyle }, "Face Verification"), /* @__PURE__ */ React__default.default.createElement("p", { style: subtitleStyle }, "Please capture or upload a clear photo of your face")), /* @__PURE__ */ React__default.default.createElement("div", { style: contentStyle }, /* @__PURE__ */ React__default.default.createElement("div", { style: visualGuideContainerStyle }, /* @__PURE__ */ React__default.default.createElement("div", { style: visualGuideStyle }, /* @__PURE__ */ React__default.default.createElement("div", { style: circleStyle }, /* @__PURE__ */ React__default.default.createElement("img", { src: Camera, alt: "Camera Icon", width: 48, height: 48 })), /* @__PURE__ */ React__default.default.createElement("div", { style: badgeStyle }, /* @__PURE__ */ React__default.default.createElement("img", { src: Done, alt: "Check Icon", width: 16, height: 16 })))), /* @__PURE__ */ React__default.default.createElement("div", { style: instructionsBoxStyle }, /* @__PURE__ */ React__default.default.createElement("h3", { style: instructionsTitleStyle }, "Tips for best results:"), /* @__PURE__ */ React__default.default.createElement("ul", { style: instructionsListStyle }, /* @__PURE__ */ React__default.default.createElement("li", { style: instructionItemStyle }, /* @__PURE__ */ React__default.default.createElement("span", { style: bulletStyle }, "\u2022"), /* @__PURE__ */ React__default.default.createElement("span", null, "Ensure good lighting on your face")), /* @__PURE__ */ React__default.default.createElement("li", { style: instructionItemStyle }, /* @__PURE__ */ React__default.default.createElement("span", { style: bulletStyle }, "\u2022"), /* @__PURE__ */ React__default.default.createElement("span", null, "Remove glasses or accessories if possible")), /* @__PURE__ */ React__default.default.createElement("li", { style: instructionItemStyle }, /* @__PURE__ */ React__default.default.createElement("span", { style: bulletStyle }, "\u2022"), /* @__PURE__ */ React__default.default.createElement("span", null, "Look directly at the camera")))), /* @__PURE__ */ React__default.default.createElement(
1120
- "input",
1120
+ "Continue on mobile (scan QR)"
1121
+ ), /* @__PURE__ */ React__default.default.createElement("button", { style: cancelButtonStyle, onClick: () => close(null) }, "Cancel")));
1122
+ const renderQRStage = (mobileConnected) => /* @__PURE__ */ React__default.default.createElement("div", { style: contentStyle }, /* @__PURE__ */ React__default.default.createElement("div", { style: qrBoxStyle }, (renderQR ?? defaultRenderQR)(qrPayload)), /* @__PURE__ */ React__default.default.createElement("p", { style: subtitleStyle }, mobileConnected ? "Phone connected. Complete the capture on your mobile device\u2026" : "Scan this QR with your phone camera, then complete the face capture there."), mobileConnected && /* @__PURE__ */ React__default.default.createElement("div", { style: { ...spinnerStyle, margin: "12px auto" } }), qrDeclinedReason && /* @__PURE__ */ React__default.default.createElement("div", { style: alertBoxStyle }, /* @__PURE__ */ React__default.default.createElement("strong", null, "Last attempt was declined."), /* @__PURE__ */ React__default.default.createElement("p", { style: alertTextStyle }, qrDeclinedReason), /* @__PURE__ */ React__default.default.createElement("p", { style: { ...alertTextStyle, marginTop: 4 } }, "Try again on your phone. Attempt ", Math.min(attempts + 1, maxAttempts), " of ", maxAttempts, ".")), /* @__PURE__ */ React__default.default.createElement("div", { style: buttonsContainerStyle }, /* @__PURE__ */ React__default.default.createElement(
1123
+ "button",
1121
1124
  {
1122
- ref: inputRef,
1123
- type: "file",
1124
- accept: "image/*",
1125
- capture: isMobile ? "user" : void 0,
1126
- style: hiddenInputStyle,
1127
- onChange: handleFileChange,
1128
- disabled: isProcessing
1125
+ style: secondaryButtonStyle,
1126
+ onClick: () => setStage({ kind: "capture" })
1127
+ },
1128
+ "Use this device instead"
1129
+ ), /* @__PURE__ */ React__default.default.createElement("button", { style: cancelButtonStyle, onClick: () => close(null) }, "Cancel")));
1130
+ const renderCapture = (declinedReason) => {
1131
+ if (captureMode === "live") {
1132
+ return /* @__PURE__ */ React__default.default.createElement("div", { style: contentStyle }, /* @__PURE__ */ React__default.default.createElement(
1133
+ LiveCamera,
1134
+ {
1135
+ onCapture: handleCameraCapture,
1136
+ onCancel: handleCameraCancel,
1137
+ message: livenessMessage
1138
+ }
1139
+ ), /* @__PURE__ */ React__default.default.createElement("p", { style: attemptsTextStyle }, "Attempt ", attempts + 1, " of ", maxAttempts));
1140
+ }
1141
+ if (captureMode === "preview" && capturedPreview) {
1142
+ return /* @__PURE__ */ React__default.default.createElement("div", { style: contentStyle }, declinedReason && /* @__PURE__ */ React__default.default.createElement("div", { style: alertBoxStyle }, /* @__PURE__ */ React__default.default.createElement("strong", null, "Verification declined."), /* @__PURE__ */ React__default.default.createElement("p", { style: alertTextStyle }, declinedReason)), /* @__PURE__ */ React__default.default.createElement("p", { style: subtitleStyle }, "Looks good? Submit this selfie or retake it."), /* @__PURE__ */ React__default.default.createElement("div", { style: previewBoxStyle }, /* @__PURE__ */ React__default.default.createElement("img", { src: capturedPreview, alt: "Captured selfie preview", style: previewImgStyle })), /* @__PURE__ */ React__default.default.createElement("div", { style: buttonsContainerStyle }, /* @__PURE__ */ React__default.default.createElement("button", { style: primaryButtonStyle, onClick: handleConfirmSubmit }, /* @__PURE__ */ React__default.default.createElement("img", { src: Done, alt: "", width: 20, height: 20 }), /* @__PURE__ */ React__default.default.createElement("span", null, "Submit")), /* @__PURE__ */ React__default.default.createElement("button", { style: secondaryButtonStyle, onClick: handleRetake }, "Retake"), /* @__PURE__ */ React__default.default.createElement("button", { style: cancelButtonStyle, onClick: () => close(null) }, "Cancel")), /* @__PURE__ */ React__default.default.createElement("p", { style: attemptsTextStyle }, "Attempt ", attempts + 1, " of ", maxAttempts));
1129
1143
  }
1130
- ), /* @__PURE__ */ React__default.default.createElement("div", { style: buttonsContainerStyle }, /* @__PURE__ */ React__default.default.createElement(
1144
+ return /* @__PURE__ */ React__default.default.createElement("div", { style: contentStyle }, /* @__PURE__ */ React__default.default.createElement("div", { style: visualGuideContainerStyle }, /* @__PURE__ */ React__default.default.createElement("div", { style: visualGuideStyle }, /* @__PURE__ */ React__default.default.createElement("div", { style: circleStyle }, /* @__PURE__ */ React__default.default.createElement("img", { src: Camera, alt: "", width: 48, height: 48 })), /* @__PURE__ */ React__default.default.createElement("div", { style: badgeStyle }, /* @__PURE__ */ React__default.default.createElement("img", { src: Done, alt: "", width: 16, height: 16 })))), declinedReason && /* @__PURE__ */ React__default.default.createElement("div", { style: alertBoxStyle }, /* @__PURE__ */ React__default.default.createElement("strong", null, "Verification declined."), /* @__PURE__ */ React__default.default.createElement("p", { style: alertTextStyle }, declinedReason)), /* @__PURE__ */ React__default.default.createElement("div", { style: instructionsBoxStyle }, /* @__PURE__ */ React__default.default.createElement("h3", { style: instructionsTitleStyle }, "Tips for best results:"), /* @__PURE__ */ React__default.default.createElement("ul", { style: instructionsListStyle }, /* @__PURE__ */ React__default.default.createElement("li", { style: instructionItemStyle }, /* @__PURE__ */ React__default.default.createElement("span", { style: bulletStyle }, "\u2022"), /* @__PURE__ */ React__default.default.createElement("span", null, "Ensure good lighting on your face")), /* @__PURE__ */ React__default.default.createElement("li", { style: instructionItemStyle }, /* @__PURE__ */ React__default.default.createElement("span", { style: bulletStyle }, "\u2022"), /* @__PURE__ */ React__default.default.createElement("span", null, "Remove glasses or accessories if possible")), /* @__PURE__ */ React__default.default.createElement("li", { style: instructionItemStyle }, /* @__PURE__ */ React__default.default.createElement("span", { style: bulletStyle }, "\u2022"), /* @__PURE__ */ React__default.default.createElement("span", null, "Look directly at the camera")))), /* @__PURE__ */ React__default.default.createElement("div", { style: buttonsContainerStyle }, /* @__PURE__ */ React__default.default.createElement("button", { style: primaryButtonStyle, onClick: handleOpenCamera }, /* @__PURE__ */ React__default.default.createElement("img", { src: Camera, alt: "", width: 20, height: 20 }), /* @__PURE__ */ React__default.default.createElement("span", null, declinedReason ? "Try again" : "Open Camera")), /* @__PURE__ */ React__default.default.createElement("button", { style: cancelButtonStyle, onClick: () => close(null) }, "Cancel")), /* @__PURE__ */ React__default.default.createElement("p", { style: attemptsTextStyle }, "Attempt ", attempts + 1, " of ", maxAttempts));
1145
+ };
1146
+ const renderSubmitting = () => /* @__PURE__ */ React__default.default.createElement("div", { style: { ...contentStyle, alignItems: "center", textAlign: "center" } }, /* @__PURE__ */ React__default.default.createElement("div", { style: { ...spinnerStyle, margin: "24px auto", width: 32, height: 32 } }), /* @__PURE__ */ React__default.default.createElement("p", { style: subtitleStyle }, "Verifying your photo\u2026"), /* @__PURE__ */ React__default.default.createElement("p", { style: { ...attemptsTextStyle, marginTop: 8 } }, "This usually takes a few seconds."));
1147
+ const renderAccepted = (result) => /* @__PURE__ */ React__default.default.createElement("div", { style: { ...contentStyle, alignItems: "center", textAlign: "center" } }, /* @__PURE__ */ React__default.default.createElement("div", { style: successCircleStyle }, /* @__PURE__ */ React__default.default.createElement("img", { src: Done, alt: "", width: 48, height: 48 })), /* @__PURE__ */ React__default.default.createElement("h3", { style: titleStyle }, "Verified"), /* @__PURE__ */ React__default.default.createElement("p", { style: subtitleStyle }, "Your identity has been confirmed. You can continue."), /* @__PURE__ */ React__default.default.createElement("div", { style: buttonsContainerStyle }, /* @__PURE__ */ React__default.default.createElement("button", { style: primaryButtonStyle, onClick: () => close(result) }, "Continue")));
1148
+ const renderDeclined = (result) => /* @__PURE__ */ React__default.default.createElement("div", { style: contentStyle }, /* @__PURE__ */ React__default.default.createElement("div", { style: alertBoxStyle }, /* @__PURE__ */ React__default.default.createElement("strong", null, "Verification declined."), /* @__PURE__ */ React__default.default.createElement("p", { style: alertTextStyle }, result.declined_reason ?? "We couldn't match your selfie. Please take a new one.")), /* @__PURE__ */ React__default.default.createElement("div", { style: buttonsContainerStyle }, /* @__PURE__ */ React__default.default.createElement("button", { style: primaryButtonStyle, onClick: handleRetakeAfterDecline }, /* @__PURE__ */ React__default.default.createElement("img", { src: Camera, alt: "", width: 20, height: 20 }), /* @__PURE__ */ React__default.default.createElement("span", null, "Retake")), /* @__PURE__ */ React__default.default.createElement("button", { style: cancelButtonStyle, onClick: () => close(result) }, "Cancel")), /* @__PURE__ */ React__default.default.createElement("p", { style: attemptsTextStyle }, "Attempt ", Math.min(attempts + 1, maxAttempts), " of ", maxAttempts));
1149
+ const renderMaxAttempts = (result) => /* @__PURE__ */ React__default.default.createElement("div", { style: { ...contentStyle, alignItems: "center", textAlign: "center" } }, /* @__PURE__ */ React__default.default.createElement("div", { style: errorCircleStyle }, "!"), /* @__PURE__ */ React__default.default.createElement("h3", { style: titleStyle }, "Maximum attempts reached"), /* @__PURE__ */ React__default.default.createElement("p", { style: subtitleStyle }, result.declined_reason ?? "We couldn't verify your identity after several attempts."), result.data?.freeze_account && /* @__PURE__ */ React__default.default.createElement("p", { style: alertTextStyle }, "For your security, your account has been temporarily restricted", result.data.freeze_duration_minutes ? ` for ${result.data.freeze_duration_minutes} minutes` : "", ". Please contact support if you need immediate help."), result.data?.enforce_logout && /* @__PURE__ */ React__default.default.createElement("p", { style: alertTextStyle }, "You will be signed out of your session."), /* @__PURE__ */ React__default.default.createElement("div", { style: buttonsContainerStyle }, /* @__PURE__ */ React__default.default.createElement("button", { style: primaryButtonStyle, onClick: () => close(result) }, "Close")));
1150
+ const renderError = (message) => /* @__PURE__ */ React__default.default.createElement("div", { style: { ...contentStyle, alignItems: "center", textAlign: "center" } }, /* @__PURE__ */ React__default.default.createElement("div", { style: errorCircleStyle }, "!"), /* @__PURE__ */ React__default.default.createElement("h3", { style: titleStyle }, "Something went wrong"), /* @__PURE__ */ React__default.default.createElement("p", { style: alertTextStyle }, message), /* @__PURE__ */ React__default.default.createElement("div", { style: buttonsContainerStyle }, /* @__PURE__ */ React__default.default.createElement("button", { style: primaryButtonStyle, onClick: () => setStage({ kind: "capture" }) }, "Try again"), /* @__PURE__ */ React__default.default.createElement("button", { style: cancelButtonStyle, onClick: () => close(null) }, "Cancel")));
1151
+ const body = (() => {
1152
+ switch (stage.kind) {
1153
+ case "choose":
1154
+ return renderChoose();
1155
+ case "qr":
1156
+ return renderQRStage(stage.mobileConnected);
1157
+ case "capture":
1158
+ return renderCapture(stage.declinedReason);
1159
+ case "submitting":
1160
+ return renderSubmitting();
1161
+ case "accepted":
1162
+ return renderAccepted(stage.result);
1163
+ case "declined":
1164
+ return renderDeclined(stage.result);
1165
+ case "max_attempts":
1166
+ return renderMaxAttempts(stage.result);
1167
+ case "error":
1168
+ return renderError(stage.message);
1169
+ }
1170
+ })();
1171
+ return /* @__PURE__ */ React__default.default.createElement(React__default.default.Fragment, null, /* @__PURE__ */ React__default.default.createElement("style", null, keyframes), /* @__PURE__ */ React__default.default.createElement("div", { style: overlayStyle }, /* @__PURE__ */ React__default.default.createElement("div", { style: modalStyle }, /* @__PURE__ */ React__default.default.createElement("div", { style: headerStyle }, /* @__PURE__ */ React__default.default.createElement(
1131
1172
  "button",
1132
1173
  {
1133
- onClick: () => inputRef.current?.click(),
1134
- onMouseEnter: () => setIsHoveringPrimary(true),
1135
- onMouseLeave: () => setIsHoveringPrimary(false),
1136
- disabled: isProcessing,
1137
- style: primaryButtonStyle
1174
+ onClick: () => close(null),
1175
+ style: closeButtonStyle,
1176
+ "aria-label": "Close"
1138
1177
  },
1139
- isProcessing ? /* @__PURE__ */ React__default.default.createElement(React__default.default.Fragment, null, /* @__PURE__ */ React__default.default.createElement("div", { style: spinnerStyle }), /* @__PURE__ */ React__default.default.createElement("span", null, "Processing...")) : /* @__PURE__ */ React__default.default.createElement(React__default.default.Fragment, null, isMobile ? /* @__PURE__ */ React__default.default.createElement("img", { src: Camera, alt: "Camera Icon", width: 20, height: 20 }) : /* @__PURE__ */ React__default.default.createElement("img", { src: Upload, alt: "Upload Icon", width: 20, height: 20 }), /* @__PURE__ */ React__default.default.createElement("span", null, isMobile ? "Capture Photo" : "Upload Photo"))
1140
- ), /* @__PURE__ */ React__default.default.createElement(
1178
+ /* @__PURE__ */ React__default.default.createElement("img", { src: Close, alt: "", width: 16, height: 16 })
1179
+ ), /* @__PURE__ */ React__default.default.createElement("h2", { style: titleStyle }, "Face Verification"), /* @__PURE__ */ React__default.default.createElement("p", { style: subtitleStyle }, headerSubtitle(stage.kind))), body, /* @__PURE__ */ React__default.default.createElement("div", { style: footerStyle }, /* @__PURE__ */ React__default.default.createElement("p", { style: footerTextStyle }, "Your photo is securely processed and used only for verification.")))));
1180
+ }
1181
+ var keyframes = `
1182
+ @keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
1183
+ @keyframes zoomIn { from { transform: scale(.96); opacity: 0 } to { transform: scale(1); opacity: 1 } }
1184
+ @keyframes spin { to { transform: rotate(360deg) } }
1185
+ `;
1186
+ var overlayStyle = {
1187
+ position: "fixed",
1188
+ inset: 0,
1189
+ background: "rgba(0,0,0,.6)",
1190
+ backdropFilter: "blur(4px)",
1191
+ display: "flex",
1192
+ alignItems: "center",
1193
+ justifyContent: "center",
1194
+ zIndex: 999999,
1195
+ padding: 16,
1196
+ animation: "fadeIn .2s ease-out"
1197
+ };
1198
+ var modalStyle = {
1199
+ background: "#fff",
1200
+ borderRadius: 16,
1201
+ boxShadow: "0 25px 50px -12px rgba(0,0,0,.25)",
1202
+ width: "100%",
1203
+ maxWidth: 448,
1204
+ animation: "zoomIn .2s ease-out"
1205
+ };
1206
+ var headerStyle = {
1207
+ position: "relative",
1208
+ padding: "24px 24px 16px",
1209
+ borderBottom: "1px solid #f3f4f6"
1210
+ };
1211
+ var closeButtonStyle = {
1212
+ position: "absolute",
1213
+ top: 16,
1214
+ right: 16,
1215
+ padding: 8,
1216
+ background: "transparent",
1217
+ border: "none",
1218
+ borderRadius: 8,
1219
+ cursor: "pointer"
1220
+ };
1221
+ var titleStyle = { margin: "0 0 4px", fontSize: 18, fontWeight: 600, color: "#111827" };
1222
+ var subtitleStyle = { margin: 0, fontSize: 14, color: "#6b7280" };
1223
+ var contentStyle = {
1224
+ padding: 24,
1225
+ display: "flex",
1226
+ flexDirection: "column",
1227
+ gap: 16
1228
+ };
1229
+ var visualGuideContainerStyle = { display: "flex", justifyContent: "center" };
1230
+ var visualGuideStyle = { position: "relative" };
1231
+ var circleStyle = {
1232
+ width: 96,
1233
+ height: 96,
1234
+ borderRadius: "50%",
1235
+ background: "linear-gradient(135deg, rgba(0, 188, 125, 0.2) 0%, rgba(0, 188, 125, 0.05) 100%)",
1236
+ display: "flex",
1237
+ alignItems: "center",
1238
+ justifyContent: "center"
1239
+ };
1240
+ var badgeStyle = {
1241
+ position: "absolute",
1242
+ bottom: -4,
1243
+ right: -4,
1244
+ width: 28,
1245
+ height: 28,
1246
+ borderRadius: "50%",
1247
+ background: "#ffffff",
1248
+ border: "2px solid #00bc7d",
1249
+ display: "flex",
1250
+ alignItems: "center",
1251
+ justifyContent: "center"
1252
+ };
1253
+ var successCircleStyle = {
1254
+ ...circleStyle,
1255
+ background: "linear-gradient(135deg, rgba(0, 188, 125, 0.25) 0%, rgba(0, 188, 125, 0.1) 100%)",
1256
+ margin: "0 auto"
1257
+ };
1258
+ var errorCircleStyle = {
1259
+ width: 64,
1260
+ height: 64,
1261
+ borderRadius: "50%",
1262
+ background: "#fee2e2",
1263
+ color: "#b91c1c",
1264
+ fontSize: 32,
1265
+ fontWeight: 700,
1266
+ display: "flex",
1267
+ alignItems: "center",
1268
+ justifyContent: "center",
1269
+ margin: "0 auto"
1270
+ };
1271
+ var qrBoxStyle = {
1272
+ display: "flex",
1273
+ justifyContent: "center",
1274
+ padding: 12,
1275
+ background: "linear-gradient(135deg, #f9fafb 0%, rgba(243, 244, 246, 0.5) 100%)",
1276
+ borderRadius: 12
1277
+ };
1278
+ var alertBoxStyle = {
1279
+ background: "#fef3c7",
1280
+ border: "1px solid #fde68a",
1281
+ color: "#92400e",
1282
+ borderRadius: 8,
1283
+ padding: 12,
1284
+ fontSize: 14
1285
+ };
1286
+ var alertTextStyle = { margin: "4px 0 0", fontSize: 13, color: "#92400e" };
1287
+ var instructionsBoxStyle = {
1288
+ background: "linear-gradient(135deg, #f9fafb 0%, rgba(243, 244, 246, 0.5) 100%)",
1289
+ borderRadius: 8,
1290
+ padding: 16
1291
+ };
1292
+ var instructionsTitleStyle = { margin: "0 0 8px", fontSize: 14, fontWeight: 600, color: "#374151" };
1293
+ var instructionsListStyle = { margin: 0, padding: 0, listStyle: "none" };
1294
+ var instructionItemStyle = { display: "flex", gap: 8, fontSize: 13, color: "#4b5563", lineHeight: 1.5 };
1295
+ var bulletStyle = { color: "#00bc7d" };
1296
+ var previewBoxStyle = {
1297
+ borderRadius: 12,
1298
+ overflow: "hidden",
1299
+ border: "2px solid rgba(0, 188, 125, 0.4)",
1300
+ background: "#0f172a",
1301
+ display: "flex",
1302
+ justifyContent: "center"
1303
+ };
1304
+ var previewImgStyle = {
1305
+ width: "100%",
1306
+ maxHeight: 320,
1307
+ objectFit: "contain",
1308
+ background: "#0f172a"
1309
+ };
1310
+ var buttonsContainerStyle = {
1311
+ display: "flex",
1312
+ flexDirection: "column",
1313
+ gap: 8
1314
+ };
1315
+ var primaryButtonStyle = {
1316
+ display: "flex",
1317
+ alignItems: "center",
1318
+ justifyContent: "center",
1319
+ gap: 8,
1320
+ padding: "12px 16px",
1321
+ background: "#00bc7d",
1322
+ color: "#ffffff",
1323
+ border: "none",
1324
+ borderRadius: 8,
1325
+ fontSize: 14,
1326
+ fontWeight: 600,
1327
+ cursor: "pointer"
1328
+ };
1329
+ var secondaryButtonStyle = {
1330
+ ...primaryButtonStyle,
1331
+ background: "#ffffff",
1332
+ color: "#374151",
1333
+ border: "2px solid #e5e7eb"
1334
+ };
1335
+ var cancelButtonStyle = {
1336
+ ...primaryButtonStyle,
1337
+ background: "transparent",
1338
+ color: "#6b7280",
1339
+ border: "none"
1340
+ };
1341
+ var spinnerStyle = {
1342
+ width: 16,
1343
+ height: 16,
1344
+ border: "2px solid rgba(0, 188, 125, 0.25)",
1345
+ borderTopColor: "#00bc7d",
1346
+ borderRadius: "50%",
1347
+ animation: "spin .8s linear infinite"
1348
+ };
1349
+ var attemptsTextStyle = {
1350
+ margin: "8px 0 0",
1351
+ fontSize: 12,
1352
+ color: "#9ca3af",
1353
+ textAlign: "center"
1354
+ };
1355
+ var footerStyle = { padding: "12px 24px 16px", borderTop: "1px solid #f3f4f6" };
1356
+ var footerTextStyle = { margin: 0, fontSize: 12, color: "#9ca3af", textAlign: "center" };
1357
+ function LiveCamera({ onCapture, onCancel, message }) {
1358
+ const videoRef = React.useRef(null);
1359
+ const streamRef = React.useRef(null);
1360
+ const [ready, setReady] = React.useState(false);
1361
+ const [error, setError] = React.useState(null);
1362
+ React.useEffect(() => {
1363
+ let cancelled = false;
1364
+ async function init() {
1365
+ try {
1366
+ if (typeof navigator === "undefined" || !navigator.mediaDevices?.getUserMedia) {
1367
+ throw new Error("Camera is not available in this browser");
1368
+ }
1369
+ const stream = await navigator.mediaDevices.getUserMedia({
1370
+ video: {
1371
+ facingMode: "user",
1372
+ width: { ideal: 1280 },
1373
+ height: { ideal: 1280 }
1374
+ },
1375
+ audio: false
1376
+ });
1377
+ if (cancelled) {
1378
+ stream.getTracks().forEach((t) => t.stop());
1379
+ return;
1380
+ }
1381
+ streamRef.current = stream;
1382
+ const video = videoRef.current;
1383
+ if (video) {
1384
+ video.srcObject = stream;
1385
+ video.onloadedmetadata = () => {
1386
+ video.play().catch(() => {
1387
+ });
1388
+ setReady(true);
1389
+ };
1390
+ }
1391
+ } catch (err) {
1392
+ setError(err instanceof Error ? err.message : "Unable to access camera");
1393
+ }
1394
+ }
1395
+ init();
1396
+ return () => {
1397
+ cancelled = true;
1398
+ streamRef.current?.getTracks().forEach((t) => t.stop());
1399
+ streamRef.current = null;
1400
+ };
1401
+ }, []);
1402
+ const capture = () => {
1403
+ const video = videoRef.current;
1404
+ if (!video || !video.videoWidth) return;
1405
+ const size = Math.min(video.videoWidth, video.videoHeight);
1406
+ const sx = (video.videoWidth - size) / 2;
1407
+ const sy = (video.videoHeight - size) / 2;
1408
+ const canvas = document.createElement("canvas");
1409
+ canvas.width = size;
1410
+ canvas.height = size;
1411
+ const ctx = canvas.getContext("2d");
1412
+ if (!ctx) return;
1413
+ ctx.translate(size, 0);
1414
+ ctx.scale(-1, 1);
1415
+ ctx.drawImage(video, sx, sy, size, size, 0, 0, size, size);
1416
+ streamRef.current?.getTracks().forEach((t) => t.stop());
1417
+ streamRef.current = null;
1418
+ onCapture(canvas.toDataURL("image/jpeg", 0.9));
1419
+ };
1420
+ if (error) {
1421
+ return /* @__PURE__ */ React__default.default.createElement("div", { style: { ...contentStyle, alignItems: "center", textAlign: "center", padding: 0 } }, /* @__PURE__ */ React__default.default.createElement("div", { style: errorCircleStyle }, "!"), /* @__PURE__ */ React__default.default.createElement("h3", { style: titleStyle }, "Camera unavailable"), /* @__PURE__ */ React__default.default.createElement("p", { style: alertTextStyle }, error), /* @__PURE__ */ React__default.default.createElement("div", { style: buttonsContainerStyle }, /* @__PURE__ */ React__default.default.createElement("button", { style: secondaryButtonStyle, onClick: onCancel }, "Back")));
1422
+ }
1423
+ return /* @__PURE__ */ React__default.default.createElement("div", { style: { display: "flex", flexDirection: "column", gap: 12 } }, /* @__PURE__ */ React__default.default.createElement("div", { style: videoFrameStyle }, /* @__PURE__ */ React__default.default.createElement(
1424
+ "video",
1425
+ {
1426
+ ref: videoRef,
1427
+ playsInline: true,
1428
+ muted: true,
1429
+ autoPlay: true,
1430
+ style: videoStyle
1431
+ }
1432
+ ), /* @__PURE__ */ React__default.default.createElement("div", { style: faceOvalOverlayStyle, "aria-hidden": "true" }), !ready && /* @__PURE__ */ React__default.default.createElement("div", { style: videoLoadingStyle }, "Starting camera\u2026")), message && /* @__PURE__ */ React__default.default.createElement("p", { style: livenessMessageStyle }, message), /* @__PURE__ */ React__default.default.createElement("div", { style: buttonsContainerStyle }, /* @__PURE__ */ React__default.default.createElement(
1141
1433
  "button",
1142
1434
  {
1143
- onClick: onCancel,
1144
- onMouseEnter: () => setIsHoveringCancel(true),
1145
- onMouseLeave: () => setIsHoveringCancel(false),
1146
- disabled: isProcessing,
1147
- style: cancelButtonStyle
1435
+ style: ready ? primaryButtonStyle : { ...primaryButtonStyle, opacity: 0.5, cursor: "not-allowed" },
1436
+ onClick: capture,
1437
+ disabled: !ready
1148
1438
  },
1149
- "Cancel"
1150
- ))), /* @__PURE__ */ React__default.default.createElement("div", { style: footerStyle }, /* @__PURE__ */ React__default.default.createElement("p", { style: footerTextStyle }, "Your photo will be securely processed and used only for verification purposes")))));
1439
+ /* @__PURE__ */ React__default.default.createElement("img", { src: Camera, alt: "", width: 20, height: 20 }),
1440
+ /* @__PURE__ */ React__default.default.createElement("span", null, "Capture")
1441
+ ), /* @__PURE__ */ React__default.default.createElement("button", { style: secondaryButtonStyle, onClick: onCancel }, "Cancel")));
1151
1442
  }
1443
+ var videoFrameStyle = {
1444
+ position: "relative",
1445
+ width: "100%",
1446
+ aspectRatio: "1 / 1",
1447
+ borderRadius: 12,
1448
+ overflow: "hidden",
1449
+ background: "#0f172a"
1450
+ };
1451
+ var videoStyle = {
1452
+ width: "100%",
1453
+ height: "100%",
1454
+ objectFit: "cover",
1455
+ transform: "scaleX(-1)"
1456
+ // mirror so the preview matches the user's POV
1457
+ };
1458
+ var faceOvalOverlayStyle = {
1459
+ position: "absolute",
1460
+ inset: 0,
1461
+ pointerEvents: "none",
1462
+ background: "radial-gradient(ellipse 38% 50% at center, transparent 60%, rgba(15, 23, 42, 0.55) 62%)",
1463
+ border: "2px solid rgba(0, 188, 125, 0.6)",
1464
+ borderRadius: 12
1465
+ };
1466
+ var videoLoadingStyle = {
1467
+ position: "absolute",
1468
+ inset: 0,
1469
+ display: "flex",
1470
+ alignItems: "center",
1471
+ justifyContent: "center",
1472
+ color: "#e5e7eb",
1473
+ fontSize: 14,
1474
+ fontWeight: 500
1475
+ };
1476
+ var livenessMessageStyle = {
1477
+ margin: 0,
1478
+ textAlign: "center",
1479
+ fontSize: 13,
1480
+ fontWeight: 500,
1481
+ color: "#374151",
1482
+ background: "rgba(0, 188, 125, 0.08)",
1483
+ border: "1px solid rgba(0, 188, 125, 0.25)",
1484
+ borderRadius: 8,
1485
+ padding: "8px 12px"
1486
+ };
1152
1487
  var FaceCaptureModal_default = FaceCaptureModal;
1153
1488
 
1154
1489
  // src/kyc/hooks.ts
@@ -1432,7 +1767,7 @@ function useKycPreferences(client, autoFetch = true) {
1432
1767
  refresh: fetchPreferences
1433
1768
  };
1434
1769
  }
1435
- function fileToBase642(file) {
1770
+ function fileToBase64(file) {
1436
1771
  return new Promise((resolve, reject) => {
1437
1772
  const reader = new FileReader();
1438
1773
  reader.onload = () => {
@@ -1489,43 +1824,52 @@ function getRiskColor(risk) {
1489
1824
  return colorMap[risk] || "#6b7280";
1490
1825
  }
1491
1826
  function useReuseKYCSubmission(client$1) {
1492
- const verifyFace = (reference, token) => {
1493
- return new Promise((resolve, reject) => {
1827
+ const startSession = React.useCallback(
1828
+ (request) => client$1.createReuseKycSession(request),
1829
+ [client$1]
1830
+ );
1831
+ const verifyFace = React.useCallback(
1832
+ (session, opts = {}) => new Promise((resolve) => {
1494
1833
  const container = document.createElement("div");
1495
1834
  document.body.appendChild(container);
1496
1835
  const root = client.createRoot(container);
1497
1836
  const cleanup = () => {
1498
1837
  root.unmount();
1499
- document.body.removeChild(container);
1838
+ container.remove();
1500
1839
  };
1501
1840
  const modal = React.createElement(FaceCaptureModal_default, {
1502
- onCapture: async (base64) => {
1503
- try {
1504
- const resp = await client$1.submitReuseKycSession({
1505
- proof: base64,
1506
- reference,
1507
- token
1508
- });
1509
- resolve(resp);
1510
- } catch (error) {
1511
- reject(error instanceof Error ? error : new Error("Face verification failed"));
1512
- } finally {
1513
- cleanup();
1514
- }
1515
- },
1516
- onCancel: () => {
1841
+ client: client$1,
1842
+ session,
1843
+ defaultDevice: opts.defaultDevice,
1844
+ renderQR: opts.renderQR,
1845
+ onComplete: (result) => {
1517
1846
  cleanup();
1518
- resolve(null);
1847
+ resolve(result);
1519
1848
  }
1520
1849
  });
1521
1850
  root.render(modal);
1522
- });
1523
- };
1524
- return { verifyFace };
1851
+ }),
1852
+ [client$1]
1853
+ );
1854
+ const runFlow = React.useCallback(
1855
+ async (request, opts = {}) => {
1856
+ const session = await startSession(request);
1857
+ if (!session.is_required) {
1858
+ return { kind: "not_required", session };
1859
+ }
1860
+ const result = await verifyFace(session, opts);
1861
+ if (result === null) {
1862
+ return { kind: "cancelled", session };
1863
+ }
1864
+ return { kind: "completed", session, result };
1865
+ },
1866
+ [startSession, verifyFace]
1867
+ );
1868
+ return { startSession, verifyFace, runFlow };
1525
1869
  }
1526
1870
 
1527
1871
  exports.createDeviceFingerprint = createDeviceFingerprint;
1528
- exports.fileToBase64 = fileToBase642;
1872
+ exports.fileToBase64 = fileToBase64;
1529
1873
  exports.formatKycStatus = formatKycStatus;
1530
1874
  exports.getBrowserInfo = getBrowserInfo;
1531
1875
  exports.getRiskColor = getRiskColor;