vesant-sdk 1.7.0-dev.7d59b3e → 1.7.0-dev.80b25e7
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-DoMSYMMR.d.ts → client-0NOPDnT0.d.ts} +29 -26
- package/dist/{client-DMIRx7Tu.d.mts → client-CvWNRwwg.d.mts} +29 -26
- package/dist/{client-ZNdnpWe7.d.mts → client-Dps40EtF.d.mts} +2 -2
- package/dist/{client-C3DCmGe9.d.ts → client-SMxqod4j.d.ts} +2 -2
- 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 +126 -21
- package/dist/compliance/index.js.map +1 -1
- package/dist/compliance/index.mjs +126 -21
- 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 +61 -6
- package/dist/decisions/index.js.map +1 -1
- package/dist/decisions/index.mjs +61 -6
- package/dist/decisions/index.mjs.map +1 -1
- package/dist/geolocation/index.d.mts +59 -4
- package/dist/geolocation/index.d.ts +59 -4
- package/dist/geolocation/index.js +129 -18
- package/dist/geolocation/index.js.map +1 -1
- package/dist/geolocation/index.mjs +127 -19
- package/dist/geolocation/index.mjs.map +1 -1
- package/dist/index.d.mts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +209 -36
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +205 -37
- 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 +87 -18
- package/dist/kyc/core.js.map +1 -1
- package/dist/kyc/core.mjs +87 -18
- package/dist/kyc/core.mjs.map +1 -1
- package/dist/kyc/index.d.mts +110 -13
- package/dist/kyc/index.d.ts +110 -13
- package/dist/kyc/index.js +87 -18
- package/dist/kyc/index.js.map +1 -1
- package/dist/kyc/index.mjs +87 -18
- package/dist/kyc/index.mjs.map +1 -1
- package/dist/react.d.mts +9 -3
- package/dist/react.d.ts +9 -3
- package/dist/react.js +180 -77
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +180 -77
- 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 +61 -6
- package/dist/risk-profile/index.js.map +1 -1
- package/dist/risk-profile/index.mjs +61 -6
- 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 +61 -6
- package/dist/scores/index.js.map +1 -1
- package/dist/scores/index.mjs +61 -6
- package/dist/scores/index.mjs.map +1 -1
- package/dist/tax/index.d.mts +20 -3
- package/dist/tax/index.d.ts +20 -3
- package/dist/tax/index.js +70 -9
- package/dist/tax/index.js.map +1 -1
- package/dist/tax/index.mjs +70 -9
- package/dist/tax/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/kyc/index.js
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
// src/core/auth.ts
|
|
4
|
+
var StaticApiKeyProvider = class {
|
|
5
|
+
constructor(apiKey) {
|
|
6
|
+
this.apiKey = apiKey;
|
|
7
|
+
}
|
|
8
|
+
async getCredential() {
|
|
9
|
+
return this.apiKey ? { scheme: "Bearer", token: this.apiKey } : null;
|
|
10
|
+
}
|
|
11
|
+
canRefresh() {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
3
16
|
// src/core/errors.ts
|
|
4
17
|
var VesantError = class _VesantError extends Error {
|
|
5
18
|
constructor(message, code, statusCode, details) {
|
|
@@ -264,6 +277,7 @@ var BaseClient = class {
|
|
|
264
277
|
interceptors: this.interceptors,
|
|
265
278
|
logger: this.logger
|
|
266
279
|
};
|
|
280
|
+
this.authProvider = config.authProvider ?? (apiKey ? new StaticApiKeyProvider(apiKey) : void 0);
|
|
267
281
|
if (config.circuitBreaker) {
|
|
268
282
|
this.circuitBreaker = new CircuitBreaker(config.circuitBreaker);
|
|
269
283
|
}
|
|
@@ -271,6 +285,19 @@ var BaseClient = class {
|
|
|
271
285
|
this.rateLimitTracker = new RateLimitTracker();
|
|
272
286
|
}
|
|
273
287
|
}
|
|
288
|
+
/**
|
|
289
|
+
* Resolve the Idempotency-Key for a request. Mutating methods (POST/PUT/PATCH)
|
|
290
|
+
* get the caller-supplied key or a freshly minted UUID; non-mutating methods get
|
|
291
|
+
* none. requestWithRetry resolves this once and injects it so every retry reuses
|
|
292
|
+
* one key (letting the server dedup replays); a direct request() resolves per call.
|
|
293
|
+
*/
|
|
294
|
+
resolveIdempotencyKey(method, requestOptions) {
|
|
295
|
+
const isMutating = ["POST", "PUT", "PATCH"].includes((method || "GET").toUpperCase());
|
|
296
|
+
if (!isMutating) {
|
|
297
|
+
return void 0;
|
|
298
|
+
}
|
|
299
|
+
return requestOptions?.idempotencyKey ?? generateUUID();
|
|
300
|
+
}
|
|
274
301
|
/**
|
|
275
302
|
* Make an HTTP request with timeout and error handling
|
|
276
303
|
*/
|
|
@@ -296,15 +323,20 @@ var BaseClient = class {
|
|
|
296
323
|
...this.config.headers,
|
|
297
324
|
...options.headers || {}
|
|
298
325
|
};
|
|
299
|
-
|
|
300
|
-
|
|
326
|
+
const credential = await this.authProvider?.getCredential({
|
|
327
|
+
tenantId: this.config.tenantId,
|
|
328
|
+
requestId
|
|
329
|
+
});
|
|
330
|
+
if (credential) {
|
|
331
|
+
headers["Authorization"] = `${credential.scheme ?? "Bearer"} ${credential.token}`;
|
|
301
332
|
}
|
|
302
333
|
if (this.config.environment === "sandbox") {
|
|
303
334
|
headers["X-Sandbox"] = "true";
|
|
304
335
|
}
|
|
305
336
|
const method = (options.method || "GET").toUpperCase();
|
|
306
|
-
|
|
307
|
-
|
|
337
|
+
const idempotencyKey = this.resolveIdempotencyKey(method, requestOptions);
|
|
338
|
+
if (idempotencyKey) {
|
|
339
|
+
headers["Idempotency-Key"] = idempotencyKey;
|
|
308
340
|
}
|
|
309
341
|
const controller = new AbortController();
|
|
310
342
|
const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
|
|
@@ -325,10 +357,28 @@ var BaseClient = class {
|
|
|
325
357
|
if (this.config.debug) {
|
|
326
358
|
this.logger.debug(`${finalOptions.method || "GET"} ${endpoint}`);
|
|
327
359
|
}
|
|
328
|
-
|
|
360
|
+
let response = await fetch(url, {
|
|
329
361
|
...finalOptions,
|
|
330
362
|
signal: controller.signal
|
|
331
363
|
});
|
|
364
|
+
if (response.status === 401 && this.authProvider?.canRefresh?.()) {
|
|
365
|
+
const refreshed = await this.authProvider.getCredential({
|
|
366
|
+
tenantId: this.config.tenantId,
|
|
367
|
+
requestId,
|
|
368
|
+
forceRefresh: true
|
|
369
|
+
});
|
|
370
|
+
if (refreshed) {
|
|
371
|
+
this.config.onCredentialRotated?.({ reason: "unauthorized" });
|
|
372
|
+
finalOptions = {
|
|
373
|
+
...finalOptions,
|
|
374
|
+
headers: {
|
|
375
|
+
...finalOptions.headers,
|
|
376
|
+
Authorization: `${refreshed.scheme ?? "Bearer"} ${refreshed.token}`
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
response = await fetch(url, { ...finalOptions, signal: controller.signal });
|
|
380
|
+
}
|
|
381
|
+
}
|
|
332
382
|
clearTimeout(timeoutId);
|
|
333
383
|
if (this.rateLimitTracker) {
|
|
334
384
|
this.rateLimitTracker.updateFromHeaders(response.headers);
|
|
@@ -417,9 +467,11 @@ var BaseClient = class {
|
|
|
417
467
|
*/
|
|
418
468
|
async requestWithRetry(endpoint, options = {}, serviceURL, retries = this.config.retries, requestOptions) {
|
|
419
469
|
let lastError;
|
|
470
|
+
const idempotencyKey = this.resolveIdempotencyKey(options.method || "GET", requestOptions);
|
|
471
|
+
const attemptOptions = idempotencyKey ? { ...requestOptions, idempotencyKey } : requestOptions;
|
|
420
472
|
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
421
473
|
try {
|
|
422
|
-
return await this.request(endpoint, options, serviceURL,
|
|
474
|
+
return await this.request(endpoint, options, serviceURL, attemptOptions);
|
|
423
475
|
} catch (error) {
|
|
424
476
|
lastError = error instanceof Error ? error : new Error("Unknown error");
|
|
425
477
|
if (requestOptions?.signal?.aborted) {
|
|
@@ -516,6 +568,9 @@ var BaseClient = class {
|
|
|
516
568
|
if (config.interceptors) {
|
|
517
569
|
this.interceptors = config.interceptors;
|
|
518
570
|
}
|
|
571
|
+
if (config.authProvider !== void 0 || config.apiKey !== void 0) {
|
|
572
|
+
this.authProvider = this.config.authProvider ?? (this.config.apiKey ? new StaticApiKeyProvider(this.config.apiKey) : void 0);
|
|
573
|
+
}
|
|
519
574
|
}
|
|
520
575
|
/**
|
|
521
576
|
* Get current configuration (readonly)
|
|
@@ -603,7 +658,13 @@ var KycClient = class extends BaseClient {
|
|
|
603
658
|
*
|
|
604
659
|
* Generates a link that the user can visit to submit their KYC documents.
|
|
605
660
|
*
|
|
606
|
-
*
|
|
661
|
+
* Optionally pass the customer's registered identity data as
|
|
662
|
+
* `customer_data` (same shape as the geolocation `customer_data` block).
|
|
663
|
+
* It seeds the customer's risk profile so document verification can
|
|
664
|
+
* cross-check the submitted document against trusted reference data;
|
|
665
|
+
* fields never overwrite data already on the profile.
|
|
666
|
+
*
|
|
667
|
+
* @param request - Request containing the user ID, optional redirect URL, optional callback URL (receives POST requests), and optional customer identity data
|
|
607
668
|
* @returns Response containing the redirect link and KYC ID
|
|
608
669
|
*
|
|
609
670
|
* @example
|
|
@@ -611,19 +672,27 @@ var KycClient = class extends BaseClient {
|
|
|
611
672
|
* const result = await client.requestKycSubmitLink({
|
|
612
673
|
* user_id: "user_123",
|
|
613
674
|
* redirect_url: "https://merchant.com/kyc-complete", // optional
|
|
614
|
-
* callback_url: "https://merchant.com/api/kyc-webhook" // optional - receives POST requests on status change
|
|
675
|
+
* callback_url: "https://merchant.com/api/kyc-webhook", // optional - receives POST requests on status change
|
|
676
|
+
* customer_data: { // optional - seeds the risk profile for document cross-checks
|
|
677
|
+
* full_name: "John Doe",
|
|
678
|
+
* date_of_birth: "1999-06-02", // ISO 8601
|
|
679
|
+
* email: "john@example.com",
|
|
680
|
+
* phone: "+94771234567",
|
|
681
|
+
* address: "12 Main St, Colombo", // used for address verification
|
|
682
|
+
* country: "LK"
|
|
683
|
+
* }
|
|
615
684
|
* });
|
|
616
685
|
*
|
|
617
686
|
* console.log(`Redirect user to: ${result.link}`);
|
|
618
687
|
* console.log(`KYC ID: ${result.kyc_id}`);
|
|
619
688
|
* ```
|
|
620
689
|
*/
|
|
621
|
-
async requestKycSubmitLink(request) {
|
|
690
|
+
async requestKycSubmitLink(request, requestOptions) {
|
|
622
691
|
return this.requestWithRetry("/api/v1/kyc/request", {
|
|
623
692
|
method: "POST",
|
|
624
693
|
body: JSON.stringify(request),
|
|
625
694
|
headers: this.getUserHeaders()
|
|
626
|
-
});
|
|
695
|
+
}, void 0, void 0, requestOptions);
|
|
627
696
|
}
|
|
628
697
|
/**
|
|
629
698
|
* Create a Event-Based Face Verification session.
|
|
@@ -656,12 +725,12 @@ var KycClient = class extends BaseClient {
|
|
|
656
725
|
*
|
|
657
726
|
* @param request - Token from `createEventBasedFaceVerificationSession`, plus the base64 selfie.
|
|
658
727
|
*/
|
|
659
|
-
async submitEventBasedFaceVerificationSession(request) {
|
|
728
|
+
async submitEventBasedFaceVerificationSession(request, requestOptions) {
|
|
660
729
|
return this.request("/api/v1/kyc/face/submit", {
|
|
661
730
|
method: "POST",
|
|
662
731
|
body: JSON.stringify(request),
|
|
663
732
|
headers: this.getUserHeaders()
|
|
664
|
-
});
|
|
733
|
+
}, void 0, requestOptions);
|
|
665
734
|
}
|
|
666
735
|
/**
|
|
667
736
|
* Look up the current state of a Event-Based Face Verification session by its
|
|
@@ -760,7 +829,7 @@ var KycClient = class extends BaseClient {
|
|
|
760
829
|
* @example
|
|
761
830
|
* ```typescript
|
|
762
831
|
* const result = await client.submitVerification({
|
|
763
|
-
* reference: "
|
|
832
|
+
* reference: "4d2aff34-ab86-422d-992e-50b1234a5b67",
|
|
764
833
|
* email: "customer@example.com",
|
|
765
834
|
* country: "US",
|
|
766
835
|
* document: {
|
|
@@ -777,12 +846,12 @@ var KycClient = class extends BaseClient {
|
|
|
777
846
|
* console.log(`Verification submitted: ${result.reference}`);
|
|
778
847
|
* ```
|
|
779
848
|
*/
|
|
780
|
-
async submitVerification(request) {
|
|
849
|
+
async submitVerification(request, requestOptions) {
|
|
781
850
|
return this.requestWithRetry("/api/v1/kyc/submit", {
|
|
782
851
|
method: "POST",
|
|
783
852
|
body: JSON.stringify(request),
|
|
784
853
|
headers: this.getUserHeaders()
|
|
785
|
-
});
|
|
854
|
+
}, void 0, void 0, requestOptions);
|
|
786
855
|
}
|
|
787
856
|
/**
|
|
788
857
|
* Get a KYC request by ID
|
|
@@ -792,7 +861,7 @@ var KycClient = class extends BaseClient {
|
|
|
792
861
|
*
|
|
793
862
|
* @example
|
|
794
863
|
* ```typescript
|
|
795
|
-
* const kyc = await client.getKycRequest("
|
|
864
|
+
* const kyc = await client.getKycRequest("550e8400-e29b-41d4-a716-446655440000");
|
|
796
865
|
* console.log(`Status: ${kyc.status}, ID Verified: ${kyc.id_verified}`);
|
|
797
866
|
* ```
|
|
798
867
|
*/
|
|
@@ -867,7 +936,7 @@ var KycClient = class extends BaseClient {
|
|
|
867
936
|
* @example
|
|
868
937
|
* ```typescript
|
|
869
938
|
* await client.requestAdditionalDocuments({
|
|
870
|
-
* id: "
|
|
939
|
+
* id: "550e8400-e29b-41d4-a716-446655440000",
|
|
871
940
|
* document_types: ["address", "document_two"],
|
|
872
941
|
* message: "Please provide proof of address and secondary ID"
|
|
873
942
|
* });
|
|
@@ -888,7 +957,7 @@ var KycClient = class extends BaseClient {
|
|
|
888
957
|
*
|
|
889
958
|
* @example
|
|
890
959
|
* ```typescript
|
|
891
|
-
* const proofs = await client.getProofDownloadURLs("
|
|
960
|
+
* const proofs = await client.getProofDownloadURLs("550e8400-e29b-41d4-a716-446655440000");
|
|
892
961
|
* proofs.forEach(proof => {
|
|
893
962
|
* console.log(`${proof.type}: ${proof.url} (expires: ${proof.expires_at})`);
|
|
894
963
|
* });
|