vesant-sdk 1.6.6 → 1.7.0-dev.254dc8c
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/README.md +14 -4
- package/dist/{client-ePzhQKp9.d.mts → client-BolQlL5e.d.mts} +1 -1
- package/dist/{client-ePzhQKp9.d.ts → client-BolQlL5e.d.ts} +1 -1
- package/dist/client-C3DCmGe9.d.ts +436 -0
- package/dist/{client-C_A7QLcB.d.ts → client-DMIRx7Tu.d.mts} +5 -3
- package/dist/{client-BlCxjbY2.d.mts → client-DoMSYMMR.d.ts} +5 -3
- package/dist/client-ZNdnpWe7.d.mts +436 -0
- package/dist/compliance/index.d.mts +25 -429
- package/dist/compliance/index.d.ts +25 -429
- package/dist/compliance/index.js +187 -103
- package/dist/compliance/index.js.map +1 -1
- package/dist/compliance/index.mjs +187 -104
- package/dist/compliance/index.mjs.map +1 -1
- package/dist/decisions/index.d.mts +2 -2
- package/dist/decisions/index.d.ts +2 -2
- package/dist/decisions/index.js +1 -1
- package/dist/decisions/index.js.map +1 -1
- package/dist/decisions/index.mjs +1 -1
- package/dist/decisions/index.mjs.map +1 -1
- package/dist/geolocation/index.d.mts +4 -4
- package/dist/geolocation/index.d.ts +4 -4
- package/dist/geolocation/index.js +7 -24
- package/dist/geolocation/index.js.map +1 -1
- package/dist/geolocation/index.mjs +7 -24
- package/dist/geolocation/index.mjs.map +1 -1
- package/dist/index.d.mts +12 -70
- package/dist/index.d.ts +12 -70
- package/dist/index.js +302 -296
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +301 -295
- package/dist/index.mjs.map +1 -1
- package/dist/kyc/core.d.mts +4 -4
- package/dist/kyc/core.d.ts +4 -4
- package/dist/kyc/core.js +86 -27
- package/dist/kyc/core.js.map +1 -1
- package/dist/kyc/core.mjs +86 -28
- package/dist/kyc/core.mjs.map +1 -1
- package/dist/kyc/index.d.mts +280 -50
- package/dist/kyc/index.d.ts +280 -50
- package/dist/kyc/index.js +86 -27
- package/dist/kyc/index.js.map +1 -1
- package/dist/kyc/index.mjs +86 -28
- package/dist/kyc/index.mjs.map +1 -1
- package/dist/react.d.mts +46 -9
- package/dist/react.d.ts +46 -9
- package/dist/react.js +891 -276
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +890 -275
- package/dist/react.mjs.map +1 -1
- package/dist/risk-profile/index.d.mts +4 -4
- package/dist/risk-profile/index.d.ts +4 -4
- package/dist/risk-profile/index.js +1 -1
- package/dist/risk-profile/index.js.map +1 -1
- package/dist/risk-profile/index.mjs +1 -1
- package/dist/risk-profile/index.mjs.map +1 -1
- package/dist/scores/index.d.mts +2 -2
- package/dist/scores/index.d.ts +2 -2
- package/dist/scores/index.js +1 -1
- package/dist/scores/index.js.map +1 -1
- package/dist/scores/index.mjs +1 -1
- package/dist/scores/index.mjs.map +1 -1
- package/dist/tax/index.d.mts +6 -41
- package/dist/tax/index.d.ts +6 -41
- package/dist/tax/index.js +1 -36
- package/dist/tax/index.js.map +1 -1
- package/dist/tax/index.mjs +1 -36
- package/dist/tax/index.mjs.map +1 -1
- package/dist/{types-1RzYeSal.d.mts → types-BOFaMQxI.d.mts} +2 -2
- package/dist/{types-B4Ezqo7V.d.mts → types-CBQRNL-l.d.mts} +14 -1
- package/dist/{types-B4Ezqo7V.d.ts → types-CBQRNL-l.d.ts} +14 -1
- package/dist/{types-X5Md_dD_.d.ts → types-UGyDl1fd.d.ts} +2 -2
- package/dist/webhooks/index.d.mts +189 -2
- package/dist/webhooks/index.d.ts +189 -2
- package/dist/webhooks/index.js +49 -7
- package/dist/webhooks/index.js.map +1 -1
- package/dist/webhooks/index.mjs +49 -7
- package/dist/webhooks/index.mjs.map +1 -1
- package/package.json +16 -13
- package/dist/fraud/index.d.mts +0 -80
- package/dist/fraud/index.d.ts +0 -80
- package/dist/fraud/index.js +0 -606
- package/dist/fraud/index.js.map +0 -1
- package/dist/fraud/index.mjs +0 -604
- package/dist/fraud/index.mjs.map +0 -1
- package/dist/index-B04H4xfJ.d.mts +0 -320
- package/dist/index-CItMPmLL.d.ts +0 -320
package/dist/react.mjs
CHANGED
|
@@ -4,7 +4,19 @@ import { createRoot } from 'react-dom/client';
|
|
|
4
4
|
// src/geolocation/hooks.ts
|
|
5
5
|
|
|
6
6
|
// src/core/version.ts
|
|
7
|
-
var SDK_VERSION = "1.
|
|
7
|
+
var SDK_VERSION = "1.7.0";
|
|
8
|
+
|
|
9
|
+
// src/core/errors.ts
|
|
10
|
+
var VesantError = class _VesantError extends Error {
|
|
11
|
+
constructor(message, code, statusCode, details) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.code = code;
|
|
14
|
+
this.statusCode = statusCode;
|
|
15
|
+
this.details = details;
|
|
16
|
+
this.name = "VesantError";
|
|
17
|
+
Object.setPrototypeOf(this, _VesantError.prototype);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
8
20
|
|
|
9
21
|
// src/shared/browser-utils.ts
|
|
10
22
|
function generateUUID() {
|
|
@@ -194,7 +206,7 @@ function encodePayload(payload) {
|
|
|
194
206
|
} else if (typeof Buffer !== "undefined") {
|
|
195
207
|
return Buffer.from(json, "utf-8").toString("base64");
|
|
196
208
|
}
|
|
197
|
-
throw new
|
|
209
|
+
throw new VesantError("No base64 encoding method available", "BASE64_UNAVAILABLE");
|
|
198
210
|
}
|
|
199
211
|
async function generateCipherText(options, config) {
|
|
200
212
|
const warnings = [];
|
|
@@ -219,8 +231,9 @@ async function generateCipherText(options, config) {
|
|
|
219
231
|
if (location) {
|
|
220
232
|
locationData = location;
|
|
221
233
|
} else if (gpsRequiredByConfig) {
|
|
222
|
-
throw new
|
|
223
|
-
`GPS location is required for ${options.reason} by tenant configuration, but GPS was not available or permission was denied
|
|
234
|
+
throw new VesantError(
|
|
235
|
+
`GPS location is required for ${options.reason} by tenant configuration, but GPS was not available or permission was denied`,
|
|
236
|
+
"GPS_REQUIRED"
|
|
224
237
|
);
|
|
225
238
|
} else {
|
|
226
239
|
warnings.push("GPS location not available or permission denied");
|
|
@@ -833,7 +846,7 @@ function useCustomerProfile(client, customerId, options = {}) {
|
|
|
833
846
|
profileRef.current = profile;
|
|
834
847
|
const updateProfile = useCallback(
|
|
835
848
|
async (updates) => {
|
|
836
|
-
if (!profileRef.current) throw new
|
|
849
|
+
if (!profileRef.current) throw new VesantError("Profile not loaded", "PROFILE_NOT_LOADED");
|
|
837
850
|
setLoading(true);
|
|
838
851
|
setError(null);
|
|
839
852
|
try {
|
|
@@ -869,280 +882,872 @@ function useCustomerProfile(client, customerId, options = {}) {
|
|
|
869
882
|
var Camera = "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCg0KPCFET0NUWVBFIHN2ZyBQVUJMSUMgIi0vL1czQy8vRFREIFNWRyAxLjAvL0VOIiAiaHR0cDovL3d3dy53My5vcmcvVFIvMjAwMS9SRUMtU1ZHLTIwMDEwOTA0L0RURC9zdmcxMC5kdGQiPg0KPCEtLSBVcGxvYWRlZCB0bzogU1ZHIFJlcG8sIHd3dy5zdmdyZXBvLmNvbSwgR2VuZXJhdG9yOiBTVkcgUmVwbyBNaXhlciBUb29scyAtLT4NCjxzdmcgdmVyc2lvbj0iMS4wIiBpZD0iTGF5ZXJfMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgDQoJIHdpZHRoPSI4MDBweCIgaGVpZ2h0PSI4MDBweCIgdmlld0JveD0iMCAwIDY0IDY0IiBlbmFibGUtYmFja2dyb3VuZD0ibmV3IDAgMCA2NCA2NCIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+DQo8Zz4NCgk8cGF0aCBmaWxsPSIjMjMxRjIwIiBkPSJNNjAsMTBINDkuNjU2bC02LjgyOC02LjgyOEM0Mi4wNzgsMi40MjIsNDEuMDYyLDIsNDAsMkgyNGMtMS4wNjIsMC0yLjA3OCwwLjQyMi0yLjgyOCwxLjE3MkwxNC4zNDQsMTBINA0KCQljLTIuMjExLDAtNCwxLjc4OS00LDR2NDRjMCwyLjIxMSwxLjc4OSw0LDQsNGg1NmMyLjIxMSwwLDQtMS43ODksNC00VjE0QzY0LDExLjc4OSw2Mi4yMTEsMTAsNjAsMTB6IE0zMiw1MA0KCQljLTguODM2LDAtMTYtNy4xNjQtMTYtMTZzNy4xNjQtMTYsMTYtMTZzMTYsNy4xNjQsMTYsMTZTNDAuODM2LDUwLDMyLDUweiIvPg0KCTxjaXJjbGUgZmlsbD0iIzIzMUYyMCIgY3g9IjMyIiBjeT0iMzQiIHI9IjgiLz4NCjwvZz4NCjwvc3ZnPg==";
|
|
870
883
|
var Done = "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48IS0tIFVwbG9hZGVkIHRvOiBTVkcgUmVwbywgd3d3LnN2Z3JlcG8uY29tLCBHZW5lcmF0b3I6IFNWRyBSZXBvIE1peGVyIFRvb2xzIC0tPg0KPHN2ZyB3aWR0aD0iODAwcHgiIGhlaWdodD0iODAwcHgiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4NCjxwYXRoIGQ9Ik04LjUgMTIuNUwxMC41IDE0LjVMMTUuNSA5LjUiIHN0cm9rZT0iIzFDMjc0QyIgc3Ryb2tlLXdpZHRoPSIxLjUiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIvPg0KPHBhdGggZD0iTTcgMy4zMzc4MkM4LjQ3MDg3IDIuNDg2OTcgMTAuMTc4NiAyIDEyIDJDMTcuNTIyOCAyIDIyIDYuNDc3MTUgMjIgMTJDMjIgMTcuNTIyOCAxNy41MjI4IDIyIDEyIDIyQzYuNDc3MTUgMjIgMiAxNy41MjI4IDIgMTJDMiAxMC4xNzg2IDIuNDg2OTcgOC40NzA4NyAzLjMzNzgyIDciIHN0cm9rZT0iIzFDMjc0QyIgc3Ryb2tlLXdpZHRoPSIxLjUiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIvPg0KPC9zdmc+";
|
|
871
884
|
var Close = "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48IS0tIFVwbG9hZGVkIHRvOiBTVkcgUmVwbywgd3d3LnN2Z3JlcG8uY29tLCBHZW5lcmF0b3I6IFNWRyBSZXBvIE1peGVyIFRvb2xzIC0tPg0KPHN2ZyB3aWR0aD0iODAwcHgiIGhlaWdodD0iODAwcHgiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4NCjxwYXRoIGQ9Ik0xNC41IDkuNTAwMDJMOS41IDE0LjVNOS40OTk5OCA5LjVMMTQuNSAxNC41IiBzdHJva2U9IiMxQzI3NEMiIHN0cm9rZS13aWR0aD0iMS41IiBzdHJva2UtbGluZWNhcD0icm91bmQiLz4NCjxwYXRoIGQ9Ik03IDMuMzM3ODJDOC40NzA4NyAyLjQ4Njk3IDEwLjE3ODYgMiAxMiAyQzE3LjUyMjggMiAyMiA2LjQ3NzE1IDIyIDEyQzIyIDE3LjUyMjggMTcuNTIyOCAyMiAxMiAyMkM2LjQ3NzE1IDIyIDIgMTcuNTIyOCAyIDEyQzIgMTAuMTc4NiAyLjQ4Njk3IDguNDcwODcgMy4zMzc4MiA3IiBzdHJva2U9IiMxQzI3NEMiIHN0cm9rZS13aWR0aD0iMS41IiBzdHJva2UtbGluZWNhcD0icm91bmQiLz4NCjwvc3ZnPg==";
|
|
872
|
-
var Upload = "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48IS0tIFVwbG9hZGVkIHRvOiBTVkcgUmVwbywgd3d3LnN2Z3JlcG8uY29tLCBHZW5lcmF0b3I6IFNWRyBSZXBvIE1peGVyIFRvb2xzIC0tPg0KPHN2ZyB3aWR0aD0iODAwcHgiIGhlaWdodD0iODAwcHgiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4NCjxwYXRoIGQ9Ik0xNyAxN0gxNy4wMU0xNS42IDE0SDE4QzE4LjkzMTkgMTQgMTkuMzk3OCAxNCAxOS43NjU0IDE0LjE1MjJDMjAuMjU1NCAxNC4zNTUyIDIwLjY0NDggMTQuNzQ0NiAyMC44NDc4IDE1LjIzNDZDMjEgMTUuNjAyMiAyMSAxNi4wNjgxIDIxIDE3QzIxIDE3LjkzMTkgMjEgMTguMzk3OCAyMC44NDc4IDE4Ljc2NTRDMjAuNjQ0OCAxOS4yNTU0IDIwLjI1NTQgMTkuNjQ0OCAxOS43NjU0IDE5Ljg0NzhDMTkuMzk3OCAyMCAxOC45MzE5IDIwIDE4IDIwSDZDNS4wNjgxMiAyMCA0LjYwMjE4IDIwIDQuMjM0NjMgMTkuODQ3OEMzLjc0NDU4IDE5LjY0NDggMy4zNTUyMyAxOS4yNTU0IDMuMTUyMjQgMTguNzY1NEMzIDE4LjM5NzggMyAxNy45MzE5IDMgMTdDMyAxNi4wNjgxIDMgMTUuNjAyMiAzLjE1MjI0IDE1LjIzNDZDMy4zNTUyMyAxNC43NDQ2IDMuNzQ0NTggMTQuMzU1MiA0LjIzNDYzIDE0LjE1MjJDNC42MDIxOCAxNCA1LjA2ODEyIDE0IDYgMTRIOC40TTEyIDE1VjRNMTIgNEwxNSA3TTEyIDRMOSA3IiBzdHJva2U9IiMwMDAwMDAiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIi8+DQo8L3N2Zz4=";
|
|
873
885
|
|
|
874
886
|
// src/kyc/FaceCaptureModal.tsx
|
|
875
|
-
var
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
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
|
+
}
|
|
883
913
|
function FaceCaptureModal({
|
|
884
|
-
|
|
885
|
-
|
|
914
|
+
client,
|
|
915
|
+
session,
|
|
916
|
+
onComplete,
|
|
917
|
+
onCancel,
|
|
918
|
+
defaultDevice,
|
|
919
|
+
renderQR
|
|
886
920
|
}) {
|
|
887
|
-
const
|
|
888
|
-
const
|
|
889
|
-
const
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
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;
|
|
905
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;
|
|
906
1011
|
};
|
|
907
|
-
const
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
display: "flex",
|
|
974
|
-
alignItems: "center",
|
|
975
|
-
justifyContent: "center"
|
|
976
|
-
};
|
|
977
|
-
const badgeStyle = {
|
|
978
|
-
position: "absolute",
|
|
979
|
-
top: "-4px",
|
|
980
|
-
right: "-4px",
|
|
981
|
-
width: "32px",
|
|
982
|
-
height: "32px",
|
|
983
|
-
background: "#ffffff",
|
|
984
|
-
borderRadius: "50%",
|
|
985
|
-
boxShadow: "0 4px 6px -1px rgba(0, 0, 0, 0.1)",
|
|
986
|
-
display: "flex",
|
|
987
|
-
alignItems: "center",
|
|
988
|
-
justifyContent: "center"
|
|
989
|
-
};
|
|
990
|
-
const instructionsBoxStyle = {
|
|
991
|
-
background: "linear-gradient(135deg, #f9fafb 0%, rgba(243, 244, 246, 0.5) 100%)",
|
|
992
|
-
borderRadius: "12px",
|
|
993
|
-
padding: "16px",
|
|
994
|
-
marginBottom: "24px"
|
|
995
|
-
};
|
|
996
|
-
const instructionsTitleStyle = {
|
|
997
|
-
fontSize: "14px",
|
|
998
|
-
fontWeight: 500,
|
|
999
|
-
color: "#111827",
|
|
1000
|
-
marginBottom: "8px"
|
|
1001
|
-
};
|
|
1002
|
-
const instructionsListStyle = {
|
|
1003
|
-
fontSize: "12px",
|
|
1004
|
-
color: "#6b7280",
|
|
1005
|
-
listStyle: "none",
|
|
1006
|
-
padding: 0,
|
|
1007
|
-
margin: 0
|
|
1008
|
-
};
|
|
1009
|
-
const instructionItemStyle = {
|
|
1010
|
-
display: "flex",
|
|
1011
|
-
alignItems: "flex-start",
|
|
1012
|
-
marginBottom: "6px"
|
|
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
|
+
}
|
|
1013
1078
|
};
|
|
1014
|
-
const
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1079
|
+
const handleCameraCapture = (dataUrl) => {
|
|
1080
|
+
const raw = dataUrl.split(",")[1] ?? "";
|
|
1081
|
+
setCapturedPreview(dataUrl);
|
|
1082
|
+
setCapturedBase64(raw);
|
|
1083
|
+
setCaptureMode("preview");
|
|
1018
1084
|
};
|
|
1019
|
-
const
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1085
|
+
const handleCameraCancel = () => setCaptureMode("idle");
|
|
1086
|
+
const handleRetake = () => {
|
|
1087
|
+
setCapturedPreview(null);
|
|
1088
|
+
setCapturedBase64(null);
|
|
1089
|
+
setCaptureMode("live");
|
|
1023
1090
|
};
|
|
1024
|
-
const
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
color: "#ffffff",
|
|
1028
|
-
fontWeight: 500,
|
|
1029
|
-
padding: "14px 24px",
|
|
1030
|
-
borderRadius: "12px",
|
|
1031
|
-
border: "none",
|
|
1032
|
-
cursor: isProcessing ? "not-allowed" : "pointer",
|
|
1033
|
-
transition: "all 0.2s",
|
|
1034
|
-
display: "flex",
|
|
1035
|
-
alignItems: "center",
|
|
1036
|
-
justifyContent: "center",
|
|
1037
|
-
gap: "12px",
|
|
1038
|
-
boxShadow: isProcessing ? "none" : isHoveringPrimary ? "0 20px 25px -5px rgba(0, 188, 125, 0.3)" : "0 10px 15px -3px rgba(0, 188, 125, 0.2)",
|
|
1039
|
-
fontSize: "16px"
|
|
1091
|
+
const handleConfirmSubmit = () => {
|
|
1092
|
+
if (!capturedBase64) return;
|
|
1093
|
+
void runSubmit(capturedBase64);
|
|
1040
1094
|
};
|
|
1041
|
-
const
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
color: "#374151",
|
|
1045
|
-
fontWeight: 500,
|
|
1046
|
-
padding: "14px 24px",
|
|
1047
|
-
borderRadius: "12px",
|
|
1048
|
-
border: "2px solid #e5e7eb",
|
|
1049
|
-
cursor: isProcessing ? "not-allowed" : "pointer",
|
|
1050
|
-
transition: "all 0.2s",
|
|
1051
|
-
fontSize: "16px"
|
|
1095
|
+
const handleOpenCamera = () => {
|
|
1096
|
+
if (submittingRef.current) return;
|
|
1097
|
+
setCaptureMode("live");
|
|
1052
1098
|
};
|
|
1053
|
-
const
|
|
1054
|
-
|
|
1099
|
+
const handleRetakeAfterDecline = () => {
|
|
1100
|
+
setCapturedPreview(null);
|
|
1101
|
+
setCapturedBase64(null);
|
|
1102
|
+
setCaptureMode("live");
|
|
1103
|
+
setStage({ kind: "capture" });
|
|
1055
1104
|
};
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
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);
|
|
1061
1121
|
};
|
|
1062
|
-
const
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
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));
|
|
1069
1175
|
};
|
|
1070
|
-
const
|
|
1071
|
-
|
|
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")));
|
|
1072
1183
|
};
|
|
1073
|
-
const
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
@keyframes spin {
|
|
1095
|
-
from {
|
|
1096
|
-
transform: rotate(0deg);
|
|
1097
|
-
}
|
|
1098
|
-
to {
|
|
1099
|
-
transform: rotate(360deg);
|
|
1100
|
-
}
|
|
1101
|
-
}
|
|
1102
|
-
`);
|
|
1103
|
-
return /* @__PURE__ */ React.createElement(React.Fragment, null, styleTag, /* @__PURE__ */ React.createElement("div", { style: overlayStyle }, /* @__PURE__ */ React.createElement("div", { style: modalStyle }, /* @__PURE__ */ React.createElement("div", { style: headerStyle }, /* @__PURE__ */ React.createElement(
|
|
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(
|
|
1104
1205
|
"button",
|
|
1105
1206
|
{
|
|
1106
|
-
onClick:
|
|
1107
|
-
onMouseEnter: () => setIsHoveringClose(true),
|
|
1108
|
-
onMouseLeave: () => setIsHoveringClose(false),
|
|
1207
|
+
onClick: () => close(null),
|
|
1109
1208
|
style: closeButtonStyle,
|
|
1110
1209
|
"aria-label": "Close"
|
|
1111
1210
|
},
|
|
1112
|
-
/* @__PURE__ */ React.createElement("img", { src: Close, alt: "
|
|
1113
|
-
), /* @__PURE__ */ React.createElement("h2", { style: titleStyle }, "Face Verification"), /* @__PURE__ */ React.createElement("p", { style: subtitleStyle },
|
|
1114
|
-
|
|
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",
|
|
1115
1592
|
{
|
|
1116
|
-
ref:
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
style:
|
|
1121
|
-
onChange: handleFileChange,
|
|
1122
|
-
disabled: isProcessing
|
|
1593
|
+
ref: videoRef,
|
|
1594
|
+
playsInline: true,
|
|
1595
|
+
muted: true,
|
|
1596
|
+
autoPlay: true,
|
|
1597
|
+
style: videoStyle
|
|
1123
1598
|
}
|
|
1124
|
-
), /* @__PURE__ */ React.createElement("div", { style:
|
|
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(
|
|
1125
1600
|
"button",
|
|
1126
1601
|
{
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
style: primaryButtonStyle
|
|
1602
|
+
type: "button",
|
|
1603
|
+
onClick: onCancel,
|
|
1604
|
+
"aria-label": "Close camera",
|
|
1605
|
+
style: overlayCloseButtonStyle
|
|
1132
1606
|
},
|
|
1133
|
-
|
|
1134
|
-
), /* @__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(
|
|
1135
1609
|
"button",
|
|
1136
1610
|
{
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
style:
|
|
1611
|
+
type: "button",
|
|
1612
|
+
onClick: capture,
|
|
1613
|
+
disabled: captureDisabled,
|
|
1614
|
+
"aria-label": "Capture",
|
|
1615
|
+
style: captureDisabled ? { ...shutterButtonStyle, opacity: 0.5, cursor: "not-allowed" } : shutterButtonStyle
|
|
1142
1616
|
},
|
|
1143
|
-
"
|
|
1144
|
-
)))
|
|
1617
|
+
/* @__PURE__ */ React.createElement("span", { style: shutterInnerStyle })
|
|
1618
|
+
)));
|
|
1145
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
|
+
};
|
|
1146
1751
|
var FaceCaptureModal_default = FaceCaptureModal;
|
|
1147
1752
|
|
|
1148
1753
|
// src/kyc/hooks.ts
|
|
@@ -1426,7 +2031,7 @@ function useKycPreferences(client, autoFetch = true) {
|
|
|
1426
2031
|
refresh: fetchPreferences
|
|
1427
2032
|
};
|
|
1428
2033
|
}
|
|
1429
|
-
function
|
|
2034
|
+
function fileToBase64(file) {
|
|
1430
2035
|
return new Promise((resolve, reject) => {
|
|
1431
2036
|
const reader = new FileReader();
|
|
1432
2037
|
reader.onload = () => {
|
|
@@ -1482,42 +2087,52 @@ function getRiskColor(risk) {
|
|
|
1482
2087
|
};
|
|
1483
2088
|
return colorMap[risk] || "#6b7280";
|
|
1484
2089
|
}
|
|
1485
|
-
function
|
|
1486
|
-
const
|
|
1487
|
-
|
|
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) => {
|
|
1488
2097
|
const container = document.createElement("div");
|
|
1489
2098
|
document.body.appendChild(container);
|
|
1490
2099
|
const root = createRoot(container);
|
|
1491
2100
|
const cleanup = () => {
|
|
1492
2101
|
root.unmount();
|
|
1493
|
-
|
|
2102
|
+
container.remove();
|
|
1494
2103
|
};
|
|
1495
2104
|
const modal = createElement(FaceCaptureModal_default, {
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
});
|
|
1503
|
-
resolve(resp);
|
|
1504
|
-
} catch (error) {
|
|
1505
|
-
reject(error instanceof Error ? error : new Error("Face verification failed"));
|
|
1506
|
-
} finally {
|
|
1507
|
-
cleanup();
|
|
1508
|
-
}
|
|
1509
|
-
},
|
|
1510
|
-
onCancel: () => {
|
|
2105
|
+
client,
|
|
2106
|
+
session,
|
|
2107
|
+
defaultDevice: opts.defaultDevice,
|
|
2108
|
+
renderQR: opts.renderQR,
|
|
2109
|
+
onCancel: opts.onCancel,
|
|
2110
|
+
onComplete: (result) => {
|
|
1511
2111
|
cleanup();
|
|
1512
|
-
resolve(
|
|
2112
|
+
resolve(result);
|
|
1513
2113
|
}
|
|
1514
2114
|
});
|
|
1515
2115
|
root.render(modal);
|
|
1516
|
-
})
|
|
1517
|
-
|
|
1518
|
-
|
|
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 };
|
|
1519
2134
|
}
|
|
1520
2135
|
|
|
1521
|
-
export { createDeviceFingerprint,
|
|
2136
|
+
export { createDeviceFingerprint, fileToBase64, formatKycStatus, getBrowserInfo, getRiskColor, getStatusColor, isValidFileSize, isValidFileType, useCipherText, useCustomerProfile, useEventBasedFaceVerificationSubmission, useGeolocation, useKycAlerts, useKycOverview, useKycPreferences, useKycRequests, useKycSubmission, useLocationCapture, useLocationRequests, useLoginVerification, useRegistration, useTransactionVerification };
|
|
1522
2137
|
//# sourceMappingURL=react.mjs.map
|
|
1523
2138
|
//# sourceMappingURL=react.mjs.map
|