vesant-sdk 1.7.1-dev.096c933 → 1.7.1-dev.23e1696

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.
package/dist/react.mjs CHANGED
@@ -924,19 +924,19 @@ var Close = "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0id
924
924
  var FACE_MESSAGES = {
925
925
  idle: "Initializing camera...",
926
926
  loading: "Loading face detection...",
927
- scanning: "Position your face in the circle",
927
+ scanning: "Position your face in the oval",
928
928
  too_far: "Face too far. Please move closer to the camera",
929
929
  too_close: "Too close. Please move back a little",
930
- off_center: "Center your face in the circle",
930
+ off_center: "Center your face in the oval",
931
931
  ok: "Looking great! Tap the button to capture"
932
932
  };
933
933
  var FACE_COLORS = {
934
934
  idle: "#9ca3af",
935
- loading: "#3b82f6",
936
- scanning: "#3b82f6",
935
+ loading: "#ef4444",
936
+ scanning: "#ef4444",
937
937
  too_far: "#ef4444",
938
- too_close: "#f59e0b",
939
- off_center: "#f59e0b",
938
+ too_close: "#ef4444",
939
+ off_center: "#ef4444",
940
940
  ok: "#10b981"
941
941
  };
942
942
  var MEDIAPIPE_BASE = "https://cdn.jsdelivr.net/npm/@mediapipe/face_detection";
@@ -1001,11 +1001,24 @@ function loadMediaPipeFaceDetection(assetBasePath) {
1001
1001
  return loader;
1002
1002
  }
1003
1003
 
1004
+ // src/kyc/hostedJourney.ts
1005
+ var REUSE_KYC_SESSION_EXPIRY_MS = 10 * 60 * 1e3;
1006
+ function tryStartOperation(guard) {
1007
+ if (guard.current) return false;
1008
+ guard.current = true;
1009
+ return true;
1010
+ }
1011
+ function releaseOperation(guard) {
1012
+ guard.current = false;
1013
+ }
1014
+ function retryTarget(hasHostedJourney) {
1015
+ return hasHostedJourney ? "journey" : "capture";
1016
+ }
1017
+
1004
1018
  // src/kyc/FaceCaptureModal.tsx
1005
1019
  var MOBILE_UA = /Mobi|Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i;
1006
- var SESSION_EXPIRY_MS = 15 * 60 * 1e3;
1007
1020
  var LIVENESS_MESSAGES = [
1008
- "Position your face inside the circle",
1021
+ "Position your face inside the oval",
1009
1022
  "Make sure your face is well lit",
1010
1023
  "Remove glasses or hats if possible",
1011
1024
  "Look straight at the camera, then tap Capture"
@@ -1014,6 +1027,8 @@ function headerSubtitle(stageKind) {
1014
1027
  switch (stageKind) {
1015
1028
  case "qr":
1016
1029
  return "Use your phone to continue";
1030
+ case "journey":
1031
+ return "Follow the steps to verify your identity";
1017
1032
  case "accepted":
1018
1033
  return "All set";
1019
1034
  case "declined":
@@ -1039,7 +1054,9 @@ function FaceCaptureModal({
1039
1054
  }) {
1040
1055
  const isMobile = typeof navigator !== "undefined" && MOBILE_UA.test(navigator.userAgent);
1041
1056
  const initialChoice = defaultDevice ?? (isMobile ? "this" : "ask");
1057
+ const journeyMode = Boolean(session.verification_url);
1042
1058
  const initialStage = (() => {
1059
+ if (journeyMode) return { kind: "journey", url: session.verification_url ?? "" };
1043
1060
  if (initialChoice === "this") return { kind: "capture" };
1044
1061
  if (initialChoice === "mobile") return { kind: "qr", mobileConnected: false };
1045
1062
  return { kind: "choose" };
@@ -1057,19 +1074,20 @@ function FaceCaptureModal({
1057
1074
  const qrPayload = session.link || `vesant://reuse-kyc?token=${encodeURIComponent(session.token)}`;
1058
1075
  const cancelledRef = useRef(false);
1059
1076
  const submittingRef = useRef(false);
1077
+ const journeyRetryingRef = useRef(false);
1060
1078
  useEffect(() => {
1061
1079
  const timer = setTimeout(() => {
1062
1080
  setStage(
1063
- (prev) => prev.kind === "choose" || prev.kind === "qr" || prev.kind === "capture" ? { kind: "error", message: "Session expired" } : prev
1081
+ (prev) => prev.kind === "choose" || prev.kind === "qr" || prev.kind === "capture" || prev.kind === "journey" ? { kind: "error", message: "Session expired" } : prev
1064
1082
  );
1065
- }, SESSION_EXPIRY_MS);
1083
+ }, REUSE_KYC_SESSION_EXPIRY_MS);
1066
1084
  return () => clearTimeout(timer);
1067
1085
  }, [session.token]);
1068
1086
  useEffect(() => {
1069
1087
  if (stage.kind !== "qr") return;
1070
1088
  let stopped = false;
1071
1089
  const intervalMs = 2e3;
1072
- const deadline = Date.now() + SESSION_EXPIRY_MS;
1090
+ const deadline = Date.now() + REUSE_KYC_SESSION_EXPIRY_MS;
1073
1091
  let mobileSeen = stage.mobileConnected;
1074
1092
  const tick = async () => {
1075
1093
  if (stopped || cancelledRef.current) return;
@@ -1110,6 +1128,64 @@ function FaceCaptureModal({
1110
1128
  stopped = true;
1111
1129
  };
1112
1130
  }, [stage.kind, stage.kind === "qr" ? stage.mobileConnected : false]);
1131
+ useEffect(() => {
1132
+ if (stage.kind !== "journey" || !stage.url) return;
1133
+ let stopped = false;
1134
+ const checkOnce = async () => {
1135
+ try {
1136
+ const result = await client.getEventBasedFaceVerificationSessionStatus(session.token);
1137
+ if (applyResult(result)) {
1138
+ stopped = true;
1139
+ return true;
1140
+ }
1141
+ } catch {
1142
+ }
1143
+ return false;
1144
+ };
1145
+ const tick = async () => {
1146
+ if (stopped || cancelledRef.current) return;
1147
+ await checkOnce();
1148
+ if (!stopped && !cancelledRef.current) {
1149
+ setTimeout(tick, 2500);
1150
+ }
1151
+ };
1152
+ void tick();
1153
+ let frameOrigin = "";
1154
+ try {
1155
+ frameOrigin = new URL(stage.url).origin;
1156
+ } catch {
1157
+ frameOrigin = "";
1158
+ }
1159
+ const onMessage = (e) => {
1160
+ if (!frameOrigin || e.origin !== frameOrigin) return;
1161
+ const status = e.data?.verification_status;
1162
+ if (status) void checkOnce();
1163
+ };
1164
+ window.addEventListener("message", onMessage);
1165
+ return () => {
1166
+ stopped = true;
1167
+ window.removeEventListener("message", onMessage);
1168
+ };
1169
+ }, [stage.kind, stage.kind === "journey" ? stage.url : ""]);
1170
+ const handleJourneyRetry = async () => {
1171
+ if (!tryStartOperation(journeyRetryingRef)) return;
1172
+ setStage({ kind: "journey", url: "" });
1173
+ try {
1174
+ const refreshed = await client.retryEventBasedFaceVerificationJourney(session.token);
1175
+ if (refreshed.verification_url) {
1176
+ setStage({ kind: "journey", url: refreshed.verification_url });
1177
+ return;
1178
+ }
1179
+ setStage({ kind: "error", message: "Unable to start a new attempt. Please try again." });
1180
+ } catch (err) {
1181
+ setStage({
1182
+ kind: "error",
1183
+ message: err instanceof Error ? err.message : "Unable to start a new attempt. Please try again."
1184
+ });
1185
+ } finally {
1186
+ releaseOperation(journeyRetryingRef);
1187
+ }
1188
+ };
1113
1189
  const applyResult = (result) => {
1114
1190
  if (result.status === "accepted") {
1115
1191
  setStage({ kind: "accepted", result });
@@ -1301,12 +1377,28 @@ function FaceCaptureModal({
1301
1377
  };
1302
1378
  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."));
1303
1379
  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")));
1304
- 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));
1380
+ 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 }, journeyMode ? /* @__PURE__ */ React.createElement("button", { style: primaryButtonStyle, onClick: () => void handleJourneyRetry() }, /* @__PURE__ */ React.createElement("span", null, "Try Again")) : /* @__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));
1305
1381
  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")));
1306
1382
  const renderError = (message) => {
1307
1383
  const sessionExpired = /session\s+expired/i.test(message);
1308
- 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")));
1384
+ 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(
1385
+ "button",
1386
+ {
1387
+ style: primaryButtonStyle,
1388
+ onClick: () => retryTarget(journeyMode) === "journey" ? void handleJourneyRetry() : setStage({ kind: "capture" })
1389
+ },
1390
+ "Try Again"
1391
+ ), /* @__PURE__ */ React.createElement("button", { style: cancelButtonStyle, onClick: () => close(null) }, sessionExpired ? "Close" : "Cancel")));
1309
1392
  };
1393
+ const renderJourney = (url) => /* @__PURE__ */ React.createElement("div", { style: contentStyle }, url ? /* @__PURE__ */ React.createElement(
1394
+ "iframe",
1395
+ {
1396
+ src: url,
1397
+ title: "Identity verification",
1398
+ allow: "camera; microphone",
1399
+ style: journeyFrameStyle
1400
+ }
1401
+ ) : /* @__PURE__ */ React.createElement("div", { style: { padding: 24, textAlign: "center" } }, /* @__PURE__ */ React.createElement("div", { style: { ...spinnerStyle, margin: "24px auto", width: 32, height: 32 } }), /* @__PURE__ */ React.createElement("p", { style: subtitleStyle }, "Preparing your next attempt\u2026")), /* @__PURE__ */ React.createElement("p", { style: { ...attemptsTextStyle, textAlign: "center" } }, "Attempt ", Math.min(attempts + 1, maxAttempts), " of ", maxAttempts));
1310
1402
  const body = (() => {
1311
1403
  switch (stage.kind) {
1312
1404
  case "choose":
@@ -1315,6 +1407,8 @@ function FaceCaptureModal({
1315
1407
  return renderQRStage(stage.mobileConnected);
1316
1408
  case "capture":
1317
1409
  return renderCapture(stage.declinedReason);
1410
+ case "journey":
1411
+ return renderJourney(stage.url);
1318
1412
  case "submitting":
1319
1413
  return renderSubmitting();
1320
1414
  case "accepted":
@@ -1361,6 +1455,8 @@ var modalStyle = {
1361
1455
  boxShadow: "0 25px 50px -12px rgba(0,0,0,.25)",
1362
1456
  width: "100%",
1363
1457
  maxWidth: 448,
1458
+ maxHeight: "calc(100vh - 32px)",
1459
+ overflowY: "auto",
1364
1460
  animation: "zoomIn .2s ease-out"
1365
1461
  };
1366
1462
  var headerStyle = {
@@ -1386,6 +1482,13 @@ var contentStyle = {
1386
1482
  flexDirection: "column",
1387
1483
  gap: 16
1388
1484
  };
1485
+ var journeyFrameStyle = {
1486
+ width: "100%",
1487
+ height: "min(520px, 60vh)",
1488
+ border: 0,
1489
+ borderRadius: 12,
1490
+ background: "#f9fafb"
1491
+ };
1389
1492
  var visualGuideContainerStyle = { display: "flex", justifyContent: "center" };
1390
1493
  var visualGuideStyle = { position: "relative" };
1391
1494
  var circleStyle = {
@@ -1652,9 +1755,10 @@ function LiveCamera({ onCapture, onCancel, message, assetBasePath }) {
1652
1755
  if (error) {
1653
1756
  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")));
1654
1757
  }
1655
- const detectionActive = ready && !faceDetectionFailed;
1656
- const liveMessage = detectionActive ? FACE_MESSAGES[faceStatus] : message;
1657
- const liveFaceColor = detectionActive ? FACE_COLORS[faceStatus] : void 0;
1758
+ const detectionAvailable = !faceDetectionFailed;
1759
+ const detectionActive = ready && detectionAvailable;
1760
+ const liveMessage = detectionAvailable ? FACE_MESSAGES[faceStatus] : message;
1761
+ const liveFaceColor = detectionAvailable ? FACE_COLORS[faceStatus] : void 0;
1658
1762
  const captureDisabled = isCaptureDisabled(ready, detectionActive, faceStatus);
1659
1763
  const ringPulse = detectionActive && (faceStatus === "too_far" || faceStatus === "too_close") ? "pulse 1.5s ease-in-out infinite" : void 0;
1660
1764
  const dynamicCircleStyle = {
@@ -1770,20 +1874,22 @@ var faceOverlayContainerStyle = {
1770
1874
  };
1771
1875
  var faceRingWrapStyle = {
1772
1876
  position: "relative",
1773
- width: "72%",
1774
- aspectRatio: "1 / 1"
1877
+ height: "64%",
1878
+ aspectRatio: "3 / 4"
1775
1879
  };
1776
1880
  var faceDashedRingStyle = {
1777
1881
  position: "absolute",
1778
1882
  inset: -6,
1779
- borderRadius: "50%",
1780
- border: "6px dashed rgba(255, 255, 255, 0.4)",
1781
- animation: "spin 10s linear infinite"
1883
+ borderRadius: 9999,
1884
+ border: "6px dashed rgba(255, 255, 255, 0.4)"
1782
1885
  };
1783
1886
  var faceCircleStyle = {
1784
1887
  position: "absolute",
1785
1888
  inset: 0,
1786
- borderRadius: "50%",
1889
+ // Tailwind's `rounded-full` resolves to a very large fixed radius. On a
1890
+ // 3:4 box that creates the normal KYC capsule/head guide with straighter
1891
+ // sides; 50% would instead produce a mathematically perfect ellipse.
1892
+ borderRadius: 9999,
1787
1893
  border: "4px solid #00bc7d",
1788
1894
  boxShadow: "0 0 0 1000px rgba(0, 0, 0, 0.5)"
1789
1895
  };