vesant-sdk 1.7.0 → 1.7.1-dev.0520b46
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/{client-B0qhE2kr.d.mts → client-5q4whhGu.d.mts} +2 -2
- package/dist/{client-DF7hlMEz.d.ts → client-BaUekQT8.d.ts} +96 -52
- package/dist/{client-DtH2RLuy.d.ts → client-DUHC-68_.d.ts} +2 -2
- package/dist/{client-DrjgZoH_.d.mts → client-XDEhh9VN.d.mts} +96 -52
- package/dist/{client-BolQlL5e.d.mts → client-q9fN8Hhf.d.mts} +103 -1
- package/dist/{client-BolQlL5e.d.ts → client-q9fN8Hhf.d.ts} +103 -1
- package/dist/compliance/index.d.mts +3 -3
- package/dist/compliance/index.d.ts +3 -3
- package/dist/compliance/index.js +218 -90
- package/dist/compliance/index.js.map +1 -1
- package/dist/compliance/index.mjs +218 -90
- package/dist/compliance/index.mjs.map +1 -1
- package/dist/decisions/index.d.mts +1 -1
- package/dist/decisions/index.d.ts +1 -1
- package/dist/decisions/index.js +69 -8
- package/dist/decisions/index.js.map +1 -1
- package/dist/decisions/index.mjs +69 -8
- package/dist/decisions/index.mjs.map +1 -1
- package/dist/geolocation/index.d.mts +68 -7
- package/dist/geolocation/index.d.ts +68 -7
- package/dist/geolocation/index.js +223 -90
- package/dist/geolocation/index.js.map +1 -1
- package/dist/geolocation/index.mjs +220 -91
- package/dist/geolocation/index.mjs.map +1 -1
- package/dist/index-C3zUKydT.d.mts +264 -0
- package/dist/index-DSDgS09k.d.ts +264 -0
- package/dist/index.d.mts +27 -10
- package/dist/index.d.ts +27 -10
- package/dist/index.js +418 -126
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +409 -127
- package/dist/index.mjs.map +1 -1
- package/dist/kyc/core.d.mts +2 -2
- package/dist/kyc/core.d.ts +2 -2
- package/dist/kyc/core.js +102 -21
- package/dist/kyc/core.js.map +1 -1
- package/dist/kyc/core.mjs +102 -22
- package/dist/kyc/core.mjs.map +1 -1
- package/dist/kyc/index.d.mts +154 -30
- package/dist/kyc/index.d.ts +154 -30
- package/dist/kyc/index.js +102 -21
- package/dist/kyc/index.js.map +1 -1
- package/dist/kyc/index.mjs +102 -22
- package/dist/kyc/index.mjs.map +1 -1
- package/dist/react.d.mts +14 -3
- package/dist/react.d.ts +14 -3
- package/dist/react.js +317 -68
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +317 -68
- package/dist/react.mjs.map +1 -1
- package/dist/risk-profile/index.d.mts +1 -1
- package/dist/risk-profile/index.d.ts +1 -1
- package/dist/risk-profile/index.js +69 -8
- package/dist/risk-profile/index.js.map +1 -1
- package/dist/risk-profile/index.mjs +69 -8
- package/dist/risk-profile/index.mjs.map +1 -1
- package/dist/scores/index.d.mts +1 -1
- package/dist/scores/index.d.ts +1 -1
- package/dist/scores/index.js +69 -8
- package/dist/scores/index.js.map +1 -1
- package/dist/scores/index.mjs +69 -8
- package/dist/scores/index.mjs.map +1 -1
- package/dist/tax/index.d.mts +2 -2
- package/dist/tax/index.d.ts +2 -2
- package/dist/tax/index.js +74 -10
- package/dist/tax/index.js.map +1 -1
- package/dist/tax/index.mjs +74 -10
- package/dist/tax/index.mjs.map +1 -1
- package/dist/webhooks/index.d.mts +2 -189
- package/dist/webhooks/index.d.ts +2 -189
- package/dist/webhooks/index.js +85 -21
- package/dist/webhooks/index.js.map +1 -1
- package/dist/webhooks/index.mjs +85 -22
- package/dist/webhooks/index.mjs.map +1 -1
- package/package.json +4 -1
package/dist/kyc/core.mjs
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
// src/core/auth.ts
|
|
2
|
+
var StaticApiKeyProvider = class {
|
|
3
|
+
constructor(apiKey) {
|
|
4
|
+
this.apiKey = apiKey;
|
|
5
|
+
}
|
|
6
|
+
async getCredential() {
|
|
7
|
+
return this.apiKey ? { scheme: "Bearer", token: this.apiKey } : null;
|
|
8
|
+
}
|
|
9
|
+
canRefresh() {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
1
14
|
// src/core/errors.ts
|
|
2
15
|
var VesantError = class _VesantError extends Error {
|
|
3
16
|
constructor(message, code, statusCode, details) {
|
|
@@ -214,7 +227,7 @@ function createConsoleLogger() {
|
|
|
214
227
|
}
|
|
215
228
|
|
|
216
229
|
// src/core/version.ts
|
|
217
|
-
var SDK_VERSION = "1.7.
|
|
230
|
+
var SDK_VERSION = "1.7.1";
|
|
218
231
|
|
|
219
232
|
// src/shared/browser-utils.ts
|
|
220
233
|
function generateUUID() {
|
|
@@ -239,6 +252,12 @@ var BaseClient = class {
|
|
|
239
252
|
if (!config.tenantId?.trim()) {
|
|
240
253
|
throw new ValidationError("tenantId is required and must be a non-empty string", ["tenantId"]);
|
|
241
254
|
}
|
|
255
|
+
if (typeof fetch === "undefined") {
|
|
256
|
+
throw new VesantError(
|
|
257
|
+
"The Vesant SDK requires a global fetch (Node.js >= 18). Upgrade Node or provide a fetch polyfill.",
|
|
258
|
+
"RUNTIME_UNSUPPORTED"
|
|
259
|
+
);
|
|
260
|
+
}
|
|
242
261
|
this.interceptors = config.interceptors || [];
|
|
243
262
|
this.logger = config.logger || createConsoleLogger();
|
|
244
263
|
let environment = config.environment;
|
|
@@ -257,11 +276,12 @@ var BaseClient = class {
|
|
|
257
276
|
environment,
|
|
258
277
|
headers: config.headers || {},
|
|
259
278
|
timeout: config.timeout || 1e4,
|
|
260
|
-
retries: config.retries
|
|
279
|
+
retries: config.retries ?? 3,
|
|
261
280
|
debug: config.debug || false,
|
|
262
281
|
interceptors: this.interceptors,
|
|
263
282
|
logger: this.logger
|
|
264
283
|
};
|
|
284
|
+
this.authProvider = config.authProvider ?? (apiKey ? new StaticApiKeyProvider(apiKey) : void 0);
|
|
265
285
|
if (config.circuitBreaker) {
|
|
266
286
|
this.circuitBreaker = new CircuitBreaker(config.circuitBreaker);
|
|
267
287
|
}
|
|
@@ -269,6 +289,19 @@ var BaseClient = class {
|
|
|
269
289
|
this.rateLimitTracker = new RateLimitTracker();
|
|
270
290
|
}
|
|
271
291
|
}
|
|
292
|
+
/**
|
|
293
|
+
* Resolve the Idempotency-Key for a request. Mutating methods (POST/PUT/PATCH)
|
|
294
|
+
* get the caller-supplied key or a freshly minted UUID; non-mutating methods get
|
|
295
|
+
* none. requestWithRetry resolves this once and injects it so every retry reuses
|
|
296
|
+
* one key (letting the server dedup replays); a direct request() resolves per call.
|
|
297
|
+
*/
|
|
298
|
+
resolveIdempotencyKey(method, requestOptions) {
|
|
299
|
+
const isMutating = ["POST", "PUT", "PATCH"].includes((method || "GET").toUpperCase());
|
|
300
|
+
if (!isMutating) {
|
|
301
|
+
return void 0;
|
|
302
|
+
}
|
|
303
|
+
return requestOptions?.idempotencyKey ?? generateUUID();
|
|
304
|
+
}
|
|
272
305
|
/**
|
|
273
306
|
* Make an HTTP request with timeout and error handling
|
|
274
307
|
*/
|
|
@@ -294,15 +327,20 @@ var BaseClient = class {
|
|
|
294
327
|
...this.config.headers,
|
|
295
328
|
...options.headers || {}
|
|
296
329
|
};
|
|
297
|
-
|
|
298
|
-
|
|
330
|
+
const credential = await this.authProvider?.getCredential({
|
|
331
|
+
tenantId: this.config.tenantId,
|
|
332
|
+
requestId
|
|
333
|
+
});
|
|
334
|
+
if (credential) {
|
|
335
|
+
headers["Authorization"] = `${credential.scheme ?? "Bearer"} ${credential.token}`;
|
|
299
336
|
}
|
|
300
337
|
if (this.config.environment === "sandbox") {
|
|
301
338
|
headers["X-Sandbox"] = "true";
|
|
302
339
|
}
|
|
303
340
|
const method = (options.method || "GET").toUpperCase();
|
|
304
|
-
|
|
305
|
-
|
|
341
|
+
const idempotencyKey = this.resolveIdempotencyKey(method, requestOptions);
|
|
342
|
+
if (idempotencyKey) {
|
|
343
|
+
headers["Idempotency-Key"] = idempotencyKey;
|
|
306
344
|
}
|
|
307
345
|
const controller = new AbortController();
|
|
308
346
|
const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
|
|
@@ -323,10 +361,28 @@ var BaseClient = class {
|
|
|
323
361
|
if (this.config.debug) {
|
|
324
362
|
this.logger.debug(`${finalOptions.method || "GET"} ${endpoint}`);
|
|
325
363
|
}
|
|
326
|
-
|
|
364
|
+
let response = await fetch(url, {
|
|
327
365
|
...finalOptions,
|
|
328
366
|
signal: controller.signal
|
|
329
367
|
});
|
|
368
|
+
if (response.status === 401 && this.authProvider?.canRefresh?.()) {
|
|
369
|
+
const refreshed = await this.authProvider.getCredential({
|
|
370
|
+
tenantId: this.config.tenantId,
|
|
371
|
+
requestId,
|
|
372
|
+
forceRefresh: true
|
|
373
|
+
});
|
|
374
|
+
if (refreshed) {
|
|
375
|
+
this.config.onCredentialRotated?.({ reason: "unauthorized" });
|
|
376
|
+
finalOptions = {
|
|
377
|
+
...finalOptions,
|
|
378
|
+
headers: {
|
|
379
|
+
...finalOptions.headers,
|
|
380
|
+
Authorization: `${refreshed.scheme ?? "Bearer"} ${refreshed.token}`
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
response = await fetch(url, { ...finalOptions, signal: controller.signal });
|
|
384
|
+
}
|
|
385
|
+
}
|
|
330
386
|
clearTimeout(timeoutId);
|
|
331
387
|
if (this.rateLimitTracker) {
|
|
332
388
|
this.rateLimitTracker.updateFromHeaders(response.headers);
|
|
@@ -415,9 +471,11 @@ var BaseClient = class {
|
|
|
415
471
|
*/
|
|
416
472
|
async requestWithRetry(endpoint, options = {}, serviceURL, retries = this.config.retries, requestOptions) {
|
|
417
473
|
let lastError;
|
|
474
|
+
const idempotencyKey = this.resolveIdempotencyKey(options.method || "GET", requestOptions);
|
|
475
|
+
const attemptOptions = idempotencyKey ? { ...requestOptions, idempotencyKey } : requestOptions;
|
|
418
476
|
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
419
477
|
try {
|
|
420
|
-
return await this.request(endpoint, options, serviceURL,
|
|
478
|
+
return await this.request(endpoint, options, serviceURL, attemptOptions);
|
|
421
479
|
} catch (error) {
|
|
422
480
|
lastError = error instanceof Error ? error : new Error("Unknown error");
|
|
423
481
|
if (requestOptions?.signal?.aborted) {
|
|
@@ -514,6 +572,9 @@ var BaseClient = class {
|
|
|
514
572
|
if (config.interceptors) {
|
|
515
573
|
this.interceptors = config.interceptors;
|
|
516
574
|
}
|
|
575
|
+
if (config.authProvider !== void 0 || config.apiKey !== void 0) {
|
|
576
|
+
this.authProvider = this.config.authProvider ?? (this.config.apiKey ? new StaticApiKeyProvider(this.config.apiKey) : void 0);
|
|
577
|
+
}
|
|
517
578
|
}
|
|
518
579
|
/**
|
|
519
580
|
* Get current configuration (readonly)
|
|
@@ -630,21 +691,20 @@ var KycClient = class extends BaseClient {
|
|
|
630
691
|
* console.log(`KYC ID: ${result.kyc_id}`);
|
|
631
692
|
* ```
|
|
632
693
|
*/
|
|
633
|
-
async requestKycSubmitLink(request) {
|
|
694
|
+
async requestKycSubmitLink(request, requestOptions) {
|
|
634
695
|
return this.requestWithRetry("/api/v1/kyc/request", {
|
|
635
696
|
method: "POST",
|
|
636
697
|
body: JSON.stringify(request),
|
|
637
698
|
headers: this.getUserHeaders()
|
|
638
|
-
});
|
|
699
|
+
}, void 0, void 0, requestOptions);
|
|
639
700
|
}
|
|
640
701
|
/**
|
|
641
702
|
* Create a Event-Based Face Verification session.
|
|
642
703
|
*
|
|
643
704
|
* Inspect the response before showing UI:
|
|
644
|
-
* - `is_required === false` → skip face
|
|
645
|
-
* - `
|
|
646
|
-
*
|
|
647
|
-
* - `device_type === 'mobile'` → open the face capture modal directly.
|
|
705
|
+
* - `is_required === false` → skip face verification; `reason` explains why.
|
|
706
|
+
* - `verification_url` present → embed the hosted journey and poll status.
|
|
707
|
+
* - `verification_url` absent → use the local camera / QR fallback.
|
|
648
708
|
*
|
|
649
709
|
* @param request - Reference, customer_id, event, amount (for threshold events), optional URLs.
|
|
650
710
|
*/
|
|
@@ -668,12 +728,12 @@ var KycClient = class extends BaseClient {
|
|
|
668
728
|
*
|
|
669
729
|
* @param request - Token from `createEventBasedFaceVerificationSession`, plus the base64 selfie.
|
|
670
730
|
*/
|
|
671
|
-
async submitEventBasedFaceVerificationSession(request) {
|
|
731
|
+
async submitEventBasedFaceVerificationSession(request, requestOptions) {
|
|
672
732
|
return this.request("/api/v1/kyc/face/submit", {
|
|
673
733
|
method: "POST",
|
|
674
734
|
body: JSON.stringify(request),
|
|
675
735
|
headers: this.getUserHeaders()
|
|
676
|
-
});
|
|
736
|
+
}, void 0, requestOptions);
|
|
677
737
|
}
|
|
678
738
|
/**
|
|
679
739
|
* Look up the current state of a Event-Based Face Verification session by its
|
|
@@ -691,11 +751,28 @@ var KycClient = class extends BaseClient {
|
|
|
691
751
|
headers: this.getUserHeaders()
|
|
692
752
|
});
|
|
693
753
|
}
|
|
754
|
+
/**
|
|
755
|
+
* Mint a fresh hosted verification journey for the next attempt on an
|
|
756
|
+
* active session whose previous hosted-journey attempt was declined.
|
|
757
|
+
* Only valid while the session is active and attempts remain; the
|
|
758
|
+
* response carries the new `verification_url` to embed. Used internally
|
|
759
|
+
* by `FaceCaptureModal`'s Try Again flow in hosted-journey mode.
|
|
760
|
+
*
|
|
761
|
+
* @param token - The session token returned by `createEventBasedFaceVerificationSession`.
|
|
762
|
+
*/
|
|
763
|
+
async retryEventBasedFaceVerificationJourney(token) {
|
|
764
|
+
return this.request("/api/v1/kyc/face/onsite/journey", {
|
|
765
|
+
method: "POST",
|
|
766
|
+
body: JSON.stringify({ token }),
|
|
767
|
+
headers: this.getUserHeaders()
|
|
768
|
+
});
|
|
769
|
+
}
|
|
694
770
|
/**
|
|
695
771
|
* Fetch the Redis-backed handoff session for a token. Same backing
|
|
696
|
-
* store as normal KYC (`kyc:session:<token>`, 15-minute TTL).
|
|
697
|
-
*
|
|
698
|
-
*
|
|
772
|
+
* store as normal KYC (`kyc:session:<token>`, 15-minute TTL). The
|
|
773
|
+
* Event-Based Face Verification database session still expires after
|
|
774
|
+
* 10 minutes. Desktop callers poll `mobile_connected` to detect when a
|
|
775
|
+
* mobile device has scanned the QR and attached.
|
|
699
776
|
*
|
|
700
777
|
* @param token - The session token returned by `createEventBasedFaceVerificationSession`.
|
|
701
778
|
*/
|
|
@@ -789,12 +866,12 @@ var KycClient = class extends BaseClient {
|
|
|
789
866
|
* console.log(`Verification submitted: ${result.reference}`);
|
|
790
867
|
* ```
|
|
791
868
|
*/
|
|
792
|
-
async submitVerification(request) {
|
|
869
|
+
async submitVerification(request, requestOptions) {
|
|
793
870
|
return this.requestWithRetry("/api/v1/kyc/submit", {
|
|
794
871
|
method: "POST",
|
|
795
872
|
body: JSON.stringify(request),
|
|
796
873
|
headers: this.getUserHeaders()
|
|
797
|
-
});
|
|
874
|
+
}, void 0, void 0, requestOptions);
|
|
798
875
|
}
|
|
799
876
|
/**
|
|
800
877
|
* Get a KYC request by ID
|
|
@@ -1204,7 +1281,10 @@ var KYC_DECLINED_DESCRIPTIONS = {
|
|
|
1204
1281
|
KYC_PROVIDER_REJECTED: "Identity verification was rejected by the verification provider",
|
|
1205
1282
|
KYC_DECLINED: "Identity verification was declined"
|
|
1206
1283
|
};
|
|
1284
|
+
function isKycDocumentExpiredCallbackEvent(value) {
|
|
1285
|
+
return typeof value === "object" && value !== null && value.event === "kyc_document_expired";
|
|
1286
|
+
}
|
|
1207
1287
|
|
|
1208
|
-
export { KYC_DECLINED_DESCRIPTIONS, KycClient };
|
|
1288
|
+
export { KYC_DECLINED_DESCRIPTIONS, KycClient, isKycDocumentExpiredCallbackEvent };
|
|
1209
1289
|
//# sourceMappingURL=core.mjs.map
|
|
1210
1290
|
//# sourceMappingURL=core.mjs.map
|