@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.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.0";
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 res = await fetchWithTimeout(`${apiBase}/public/widget-token`, {
93
- headers: { "x-kyc-pk": pk },
94
- credentials: "include"
95
- });
96
- if (!res.ok) {
97
- let message = `Widget token request failed (${res.status})`;
98
- try {
99
- const b = await res.json();
100
- message = b.error || b.message || message;
101
- } catch {
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
- throw new Error(message);
104
- }
105
- return res.json();
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 res = await fetchWithTimeout(serverUrl, {
163
- method: "POST",
164
- headers: { "Content-Type": "application/json", ...requestHeaders },
165
- credentials: "include",
166
- body: JSON.stringify({ clientMetadata })
167
- });
168
- if (!res.ok) {
169
- let message = `Session request failed (${res.status})`;
170
- try {
171
- const body = await res.json();
172
- if (body.error) message = body.error;
173
- else if (body.message) message = body.message;
174
- } catch {
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
- throw new Error(message);
177
- }
178
- return res.json();
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
  }