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