@flonkid/kyc 1.8.0 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +55 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +55 -30
- package/dist/index.js.map +1 -1
- package/dist/server.cjs +1 -1
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { useRef, useMemo, useEffect } from 'react';
|
|
|
2
2
|
import { jsx } from 'react/jsx-runtime';
|
|
3
3
|
|
|
4
4
|
// src/shared/constants.ts
|
|
5
|
-
var SDK_VERSION = "1.8.
|
|
5
|
+
var SDK_VERSION = "1.8.1";
|
|
6
6
|
var DEFAULT_WIDGET_URL = "https://widget.flonk.id";
|
|
7
7
|
var DEFAULT_API_BASE = "https://api.flonk.id/v1";
|
|
8
8
|
var WIDGET_EVENTS = {
|
|
@@ -88,21 +88,31 @@ async function fetchWithTimeout(url, init = {}, timeoutMs = DEFAULT_FETCH_TIMEOU
|
|
|
88
88
|
clearTimeout(timer);
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
|
+
var widgetTokenInflight = /* @__PURE__ */ new Map();
|
|
91
92
|
async function fetchWidgetToken(pk, apiBase) {
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
93
|
+
const key = `${apiBase}|${pk}`;
|
|
94
|
+
const existing = widgetTokenInflight.get(key);
|
|
95
|
+
if (existing) return existing;
|
|
96
|
+
const promise = (async () => {
|
|
97
|
+
const res = await fetchWithTimeout(`${apiBase}/public/widget-token`, {
|
|
98
|
+
headers: { "x-kyc-pk": pk },
|
|
99
|
+
credentials: "include"
|
|
100
|
+
});
|
|
101
|
+
if (!res.ok) {
|
|
102
|
+
let message = `Widget token request failed (${res.status})`;
|
|
103
|
+
try {
|
|
104
|
+
const b = await res.json();
|
|
105
|
+
message = b.error || b.message || message;
|
|
106
|
+
} catch {
|
|
107
|
+
}
|
|
108
|
+
throw new Error(message);
|
|
102
109
|
}
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
|
|
110
|
+
return res.json();
|
|
111
|
+
})().finally(() => {
|
|
112
|
+
widgetTokenInflight.delete(key);
|
|
113
|
+
});
|
|
114
|
+
widgetTokenInflight.set(key, promise);
|
|
115
|
+
return promise;
|
|
106
116
|
}
|
|
107
117
|
var BRANDING_CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
108
118
|
var brandingCache = /* @__PURE__ */ new Map();
|
|
@@ -157,25 +167,35 @@ function validateServerUrl(url) {
|
|
|
157
167
|
throw new Error(`Invalid serverUrl: ${url}`);
|
|
158
168
|
}
|
|
159
169
|
}
|
|
170
|
+
var sessionCreateInflight = /* @__PURE__ */ new Map();
|
|
160
171
|
async function fetchSessionFromServer(serverUrl, clientMetadata, requestHeaders) {
|
|
161
172
|
validateServerUrl(serverUrl);
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
173
|
+
const key = `${serverUrl}|${JSON.stringify(clientMetadata ?? null)}`;
|
|
174
|
+
const existing = sessionCreateInflight.get(key);
|
|
175
|
+
if (existing) return existing;
|
|
176
|
+
const promise = (async () => {
|
|
177
|
+
const res = await fetchWithTimeout(serverUrl, {
|
|
178
|
+
method: "POST",
|
|
179
|
+
headers: { "Content-Type": "application/json", ...requestHeaders },
|
|
180
|
+
credentials: "include",
|
|
181
|
+
body: JSON.stringify({ clientMetadata })
|
|
182
|
+
});
|
|
183
|
+
if (!res.ok) {
|
|
184
|
+
let message = `Session request failed (${res.status})`;
|
|
185
|
+
try {
|
|
186
|
+
const body = await res.json();
|
|
187
|
+
if (body.error) message = body.error;
|
|
188
|
+
else if (body.message) message = body.message;
|
|
189
|
+
} catch {
|
|
190
|
+
}
|
|
191
|
+
throw new Error(message);
|
|
175
192
|
}
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
|
|
193
|
+
return res.json();
|
|
194
|
+
})().finally(() => {
|
|
195
|
+
sessionCreateInflight.delete(key);
|
|
196
|
+
});
|
|
197
|
+
sessionCreateInflight.set(key, promise);
|
|
198
|
+
return promise;
|
|
179
199
|
}
|
|
180
200
|
async function fetchPublicSession(apiBase, sessionId, embedToken) {
|
|
181
201
|
const res = await fetchWithTimeout(`${apiBase}/public/session/${sessionId}`, {
|
|
@@ -1012,6 +1032,11 @@ var FlonkKYC = class {
|
|
|
1012
1032
|
if (session.mlAutoCaptureEnabled) params.mlAutoCaptureEnabled = "true";
|
|
1013
1033
|
if (session.mlCropEnabled !== false) params.mlCropEnabled = "true";
|
|
1014
1034
|
if (session.mlVerifyEnabled) params.mlVerifyEnabled = "true";
|
|
1035
|
+
if (session.vaultReuseEnabled) params.vaultReuseEnabled = "true";
|
|
1036
|
+
if (session.vaultReuseChallenge) params.vaultReuseChallenge = session.vaultReuseChallenge;
|
|
1037
|
+
if (session.faceAutoCapture) params.faceAutoCapture = JSON.stringify(session.faceAutoCapture);
|
|
1038
|
+
if (session.project) params.project = JSON.stringify(session.project);
|
|
1039
|
+
params.policyReady = "1";
|
|
1015
1040
|
if (designTokens?.colors) {
|
|
1016
1041
|
params.designTokens = JSON.stringify(designTokens);
|
|
1017
1042
|
}
|