vesant-sdk 1.7.0-dev.059da4f → 1.7.0-dev.13bd228
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-C3DCmGe9.d.ts → client-749WqhDT.d.ts} +2 -2
- package/dist/{client-DMIRx7Tu.d.mts → client-BG8KtVMc.d.mts} +14 -1
- package/dist/{client-ZNdnpWe7.d.mts → client-CRZea-eJ.d.mts} +2 -2
- package/dist/{client-DoMSYMMR.d.ts → client-D9JZgN3X.d.ts} +14 -1
- 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 +61 -9
- package/dist/compliance/index.js.map +1 -1
- package/dist/compliance/index.mjs +61 -9
- 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 +3 -3
- package/dist/geolocation/index.d.ts +3 -3
- package/dist/geolocation/index.js +61 -6
- package/dist/geolocation/index.js.map +1 -1
- package/dist/geolocation/index.mjs +61 -6
- package/dist/geolocation/index.mjs.map +1 -1
- package/dist/index.d.mts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +138 -33
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +137 -34
- 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 +5 -3
- package/dist/react.d.ts +5 -3
- package/dist/react.js +112 -73
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +112 -73
- 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 +3 -26
- package/dist/tax/index.d.ts +3 -26
- package/dist/tax/index.js +67 -18
- package/dist/tax/index.js.map +1 -1
- package/dist/tax/index.mjs +67 -18
- package/dist/tax/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,61 @@
|
|
|
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
|
+
var RefreshingTokenProvider = class {
|
|
16
|
+
constructor(opts) {
|
|
17
|
+
this.opts = opts;
|
|
18
|
+
this.cached = null;
|
|
19
|
+
this.inFlight = null;
|
|
20
|
+
this.skewMs = opts.skewMs ?? 3e4;
|
|
21
|
+
this.scheme = opts.scheme ?? "Bearer";
|
|
22
|
+
this.now = opts.now ?? (() => Date.now());
|
|
23
|
+
}
|
|
24
|
+
canRefresh() {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
async getCredential(ctx) {
|
|
28
|
+
const forceRefresh = ctx?.forceRefresh ?? false;
|
|
29
|
+
if (!forceRefresh && this.cached && !this.isExpiring(this.cached)) {
|
|
30
|
+
return { scheme: this.scheme, token: this.cached.token };
|
|
31
|
+
}
|
|
32
|
+
const fresh = await this.refresh();
|
|
33
|
+
return { scheme: this.scheme, token: fresh.token };
|
|
34
|
+
}
|
|
35
|
+
isExpiring(token) {
|
|
36
|
+
if (token.expiresAt === void 0) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
return this.now() >= token.expiresAt - this.skewMs;
|
|
40
|
+
}
|
|
41
|
+
refresh() {
|
|
42
|
+
if (this.inFlight) {
|
|
43
|
+
return this.inFlight;
|
|
44
|
+
}
|
|
45
|
+
this.inFlight = (async () => {
|
|
46
|
+
try {
|
|
47
|
+
const fresh = await this.opts.fetchToken();
|
|
48
|
+
this.cached = fresh;
|
|
49
|
+
this.opts.onRotate?.({ expiresAt: fresh.expiresAt });
|
|
50
|
+
return fresh;
|
|
51
|
+
} finally {
|
|
52
|
+
this.inFlight = null;
|
|
53
|
+
}
|
|
54
|
+
})();
|
|
55
|
+
return this.inFlight;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
3
59
|
// src/core/errors.ts
|
|
4
60
|
var VesantError = class _VesantError extends Error {
|
|
5
61
|
constructor(message, code, statusCode, details) {
|
|
@@ -347,6 +403,7 @@ var BaseClient = class {
|
|
|
347
403
|
interceptors: this.interceptors,
|
|
348
404
|
logger: this.logger
|
|
349
405
|
};
|
|
406
|
+
this.authProvider = config.authProvider ?? (apiKey ? new StaticApiKeyProvider(apiKey) : void 0);
|
|
350
407
|
if (config.circuitBreaker) {
|
|
351
408
|
this.circuitBreaker = new CircuitBreaker(config.circuitBreaker);
|
|
352
409
|
}
|
|
@@ -354,6 +411,19 @@ var BaseClient = class {
|
|
|
354
411
|
this.rateLimitTracker = new RateLimitTracker();
|
|
355
412
|
}
|
|
356
413
|
}
|
|
414
|
+
/**
|
|
415
|
+
* Resolve the Idempotency-Key for a request. Mutating methods (POST/PUT/PATCH)
|
|
416
|
+
* get the caller-supplied key or a freshly minted UUID; non-mutating methods get
|
|
417
|
+
* none. requestWithRetry resolves this once and injects it so every retry reuses
|
|
418
|
+
* one key (letting the server dedup replays); a direct request() resolves per call.
|
|
419
|
+
*/
|
|
420
|
+
resolveIdempotencyKey(method, requestOptions) {
|
|
421
|
+
const isMutating = ["POST", "PUT", "PATCH"].includes((method || "GET").toUpperCase());
|
|
422
|
+
if (!isMutating) {
|
|
423
|
+
return void 0;
|
|
424
|
+
}
|
|
425
|
+
return requestOptions?.idempotencyKey ?? generateUUID();
|
|
426
|
+
}
|
|
357
427
|
/**
|
|
358
428
|
* Make an HTTP request with timeout and error handling
|
|
359
429
|
*/
|
|
@@ -379,15 +449,20 @@ var BaseClient = class {
|
|
|
379
449
|
...this.config.headers,
|
|
380
450
|
...options.headers || {}
|
|
381
451
|
};
|
|
382
|
-
|
|
383
|
-
|
|
452
|
+
const credential = await this.authProvider?.getCredential({
|
|
453
|
+
tenantId: this.config.tenantId,
|
|
454
|
+
requestId
|
|
455
|
+
});
|
|
456
|
+
if (credential) {
|
|
457
|
+
headers["Authorization"] = `${credential.scheme ?? "Bearer"} ${credential.token}`;
|
|
384
458
|
}
|
|
385
459
|
if (this.config.environment === "sandbox") {
|
|
386
460
|
headers["X-Sandbox"] = "true";
|
|
387
461
|
}
|
|
388
462
|
const method = (options.method || "GET").toUpperCase();
|
|
389
|
-
|
|
390
|
-
|
|
463
|
+
const idempotencyKey = this.resolveIdempotencyKey(method, requestOptions);
|
|
464
|
+
if (idempotencyKey) {
|
|
465
|
+
headers["Idempotency-Key"] = idempotencyKey;
|
|
391
466
|
}
|
|
392
467
|
const controller = new AbortController();
|
|
393
468
|
const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
|
|
@@ -408,10 +483,28 @@ var BaseClient = class {
|
|
|
408
483
|
if (this.config.debug) {
|
|
409
484
|
this.logger.debug(`${finalOptions.method || "GET"} ${endpoint}`);
|
|
410
485
|
}
|
|
411
|
-
|
|
486
|
+
let response = await fetch(url, {
|
|
412
487
|
...finalOptions,
|
|
413
488
|
signal: controller.signal
|
|
414
489
|
});
|
|
490
|
+
if (response.status === 401 && this.authProvider?.canRefresh?.()) {
|
|
491
|
+
const refreshed = await this.authProvider.getCredential({
|
|
492
|
+
tenantId: this.config.tenantId,
|
|
493
|
+
requestId,
|
|
494
|
+
forceRefresh: true
|
|
495
|
+
});
|
|
496
|
+
if (refreshed) {
|
|
497
|
+
this.config.onCredentialRotated?.({ reason: "unauthorized" });
|
|
498
|
+
finalOptions = {
|
|
499
|
+
...finalOptions,
|
|
500
|
+
headers: {
|
|
501
|
+
...finalOptions.headers,
|
|
502
|
+
Authorization: `${refreshed.scheme ?? "Bearer"} ${refreshed.token}`
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
response = await fetch(url, { ...finalOptions, signal: controller.signal });
|
|
506
|
+
}
|
|
507
|
+
}
|
|
415
508
|
clearTimeout(timeoutId);
|
|
416
509
|
if (this.rateLimitTracker) {
|
|
417
510
|
this.rateLimitTracker.updateFromHeaders(response.headers);
|
|
@@ -500,9 +593,11 @@ var BaseClient = class {
|
|
|
500
593
|
*/
|
|
501
594
|
async requestWithRetry(endpoint, options = {}, serviceURL, retries = this.config.retries, requestOptions) {
|
|
502
595
|
let lastError;
|
|
596
|
+
const idempotencyKey = this.resolveIdempotencyKey(options.method || "GET", requestOptions);
|
|
597
|
+
const attemptOptions = idempotencyKey ? { ...requestOptions, idempotencyKey } : requestOptions;
|
|
503
598
|
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
504
599
|
try {
|
|
505
|
-
return await this.request(endpoint, options, serviceURL,
|
|
600
|
+
return await this.request(endpoint, options, serviceURL, attemptOptions);
|
|
506
601
|
} catch (error) {
|
|
507
602
|
lastError = error instanceof Error ? error : new Error("Unknown error");
|
|
508
603
|
if (requestOptions?.signal?.aborted) {
|
|
@@ -599,6 +694,9 @@ var BaseClient = class {
|
|
|
599
694
|
if (config.interceptors) {
|
|
600
695
|
this.interceptors = config.interceptors;
|
|
601
696
|
}
|
|
697
|
+
if (config.authProvider !== void 0 || config.apiKey !== void 0) {
|
|
698
|
+
this.authProvider = this.config.authProvider ?? (this.config.apiKey ? new StaticApiKeyProvider(this.config.apiKey) : void 0);
|
|
699
|
+
}
|
|
602
700
|
}
|
|
603
701
|
/**
|
|
604
702
|
* Get current configuration (readonly)
|
|
@@ -1800,9 +1898,6 @@ var ComplianceClient = class {
|
|
|
1800
1898
|
if (cipherTextResult.risk?.is_blocked) {
|
|
1801
1899
|
blockReasons.push(...cipherTextResult.risk.block_reasons_structured ?? []);
|
|
1802
1900
|
}
|
|
1803
|
-
if (cipherTextResult.risk?.location_mismatch) {
|
|
1804
|
-
blockReasons.push(sdkReasons.gpsIPMismatch());
|
|
1805
|
-
}
|
|
1806
1901
|
}
|
|
1807
1902
|
if (geoVerification.gps_required && !cipherTextResult) {
|
|
1808
1903
|
blockReasons.push(sdkReasons.gpsRequired());
|
|
@@ -2712,7 +2807,13 @@ var KycClient = class extends BaseClient {
|
|
|
2712
2807
|
*
|
|
2713
2808
|
* Generates a link that the user can visit to submit their KYC documents.
|
|
2714
2809
|
*
|
|
2715
|
-
*
|
|
2810
|
+
* Optionally pass the customer's registered identity data as
|
|
2811
|
+
* `customer_data` (same shape as the geolocation `customer_data` block).
|
|
2812
|
+
* It seeds the customer's risk profile so document verification can
|
|
2813
|
+
* cross-check the submitted document against trusted reference data;
|
|
2814
|
+
* fields never overwrite data already on the profile.
|
|
2815
|
+
*
|
|
2816
|
+
* @param request - Request containing the user ID, optional redirect URL, optional callback URL (receives POST requests), and optional customer identity data
|
|
2716
2817
|
* @returns Response containing the redirect link and KYC ID
|
|
2717
2818
|
*
|
|
2718
2819
|
* @example
|
|
@@ -2720,19 +2821,27 @@ var KycClient = class extends BaseClient {
|
|
|
2720
2821
|
* const result = await client.requestKycSubmitLink({
|
|
2721
2822
|
* user_id: "user_123",
|
|
2722
2823
|
* redirect_url: "https://merchant.com/kyc-complete", // optional
|
|
2723
|
-
* callback_url: "https://merchant.com/api/kyc-webhook" // optional - receives POST requests on status change
|
|
2824
|
+
* callback_url: "https://merchant.com/api/kyc-webhook", // optional - receives POST requests on status change
|
|
2825
|
+
* customer_data: { // optional - seeds the risk profile for document cross-checks
|
|
2826
|
+
* full_name: "John Doe",
|
|
2827
|
+
* date_of_birth: "1999-06-02", // ISO 8601
|
|
2828
|
+
* email: "john@example.com",
|
|
2829
|
+
* phone: "+94771234567",
|
|
2830
|
+
* address: "12 Main St, Colombo", // used for address verification
|
|
2831
|
+
* country: "LK"
|
|
2832
|
+
* }
|
|
2724
2833
|
* });
|
|
2725
2834
|
*
|
|
2726
2835
|
* console.log(`Redirect user to: ${result.link}`);
|
|
2727
2836
|
* console.log(`KYC ID: ${result.kyc_id}`);
|
|
2728
2837
|
* ```
|
|
2729
2838
|
*/
|
|
2730
|
-
async requestKycSubmitLink(request) {
|
|
2839
|
+
async requestKycSubmitLink(request, requestOptions) {
|
|
2731
2840
|
return this.requestWithRetry("/api/v1/kyc/request", {
|
|
2732
2841
|
method: "POST",
|
|
2733
2842
|
body: JSON.stringify(request),
|
|
2734
2843
|
headers: this.getUserHeaders()
|
|
2735
|
-
});
|
|
2844
|
+
}, void 0, void 0, requestOptions);
|
|
2736
2845
|
}
|
|
2737
2846
|
/**
|
|
2738
2847
|
* Create a Event-Based Face Verification session.
|
|
@@ -2765,12 +2874,12 @@ var KycClient = class extends BaseClient {
|
|
|
2765
2874
|
*
|
|
2766
2875
|
* @param request - Token from `createEventBasedFaceVerificationSession`, plus the base64 selfie.
|
|
2767
2876
|
*/
|
|
2768
|
-
async submitEventBasedFaceVerificationSession(request) {
|
|
2877
|
+
async submitEventBasedFaceVerificationSession(request, requestOptions) {
|
|
2769
2878
|
return this.request("/api/v1/kyc/face/submit", {
|
|
2770
2879
|
method: "POST",
|
|
2771
2880
|
body: JSON.stringify(request),
|
|
2772
2881
|
headers: this.getUserHeaders()
|
|
2773
|
-
});
|
|
2882
|
+
}, void 0, requestOptions);
|
|
2774
2883
|
}
|
|
2775
2884
|
/**
|
|
2776
2885
|
* Look up the current state of a Event-Based Face Verification session by its
|
|
@@ -2869,7 +2978,7 @@ var KycClient = class extends BaseClient {
|
|
|
2869
2978
|
* @example
|
|
2870
2979
|
* ```typescript
|
|
2871
2980
|
* const result = await client.submitVerification({
|
|
2872
|
-
* reference: "
|
|
2981
|
+
* reference: "4d2aff34-ab86-422d-992e-50b1234a5b67",
|
|
2873
2982
|
* email: "customer@example.com",
|
|
2874
2983
|
* country: "US",
|
|
2875
2984
|
* document: {
|
|
@@ -2886,12 +2995,12 @@ var KycClient = class extends BaseClient {
|
|
|
2886
2995
|
* console.log(`Verification submitted: ${result.reference}`);
|
|
2887
2996
|
* ```
|
|
2888
2997
|
*/
|
|
2889
|
-
async submitVerification(request) {
|
|
2998
|
+
async submitVerification(request, requestOptions) {
|
|
2890
2999
|
return this.requestWithRetry("/api/v1/kyc/submit", {
|
|
2891
3000
|
method: "POST",
|
|
2892
3001
|
body: JSON.stringify(request),
|
|
2893
3002
|
headers: this.getUserHeaders()
|
|
2894
|
-
});
|
|
3003
|
+
}, void 0, void 0, requestOptions);
|
|
2895
3004
|
}
|
|
2896
3005
|
/**
|
|
2897
3006
|
* Get a KYC request by ID
|
|
@@ -2901,7 +3010,7 @@ var KycClient = class extends BaseClient {
|
|
|
2901
3010
|
*
|
|
2902
3011
|
* @example
|
|
2903
3012
|
* ```typescript
|
|
2904
|
-
* const kyc = await client.getKycRequest("
|
|
3013
|
+
* const kyc = await client.getKycRequest("550e8400-e29b-41d4-a716-446655440000");
|
|
2905
3014
|
* console.log(`Status: ${kyc.status}, ID Verified: ${kyc.id_verified}`);
|
|
2906
3015
|
* ```
|
|
2907
3016
|
*/
|
|
@@ -2976,7 +3085,7 @@ var KycClient = class extends BaseClient {
|
|
|
2976
3085
|
* @example
|
|
2977
3086
|
* ```typescript
|
|
2978
3087
|
* await client.requestAdditionalDocuments({
|
|
2979
|
-
* id: "
|
|
3088
|
+
* id: "550e8400-e29b-41d4-a716-446655440000",
|
|
2980
3089
|
* document_types: ["address", "document_two"],
|
|
2981
3090
|
* message: "Please provide proof of address and secondary ID"
|
|
2982
3091
|
* });
|
|
@@ -2997,7 +3106,7 @@ var KycClient = class extends BaseClient {
|
|
|
2997
3106
|
*
|
|
2998
3107
|
* @example
|
|
2999
3108
|
* ```typescript
|
|
3000
|
-
* const proofs = await client.getProofDownloadURLs("
|
|
3109
|
+
* const proofs = await client.getProofDownloadURLs("550e8400-e29b-41d4-a716-446655440000");
|
|
3001
3110
|
* proofs.forEach(proof => {
|
|
3002
3111
|
* console.log(`${proof.type}: ${proof.url} (expires: ${proof.expires_at})`);
|
|
3003
3112
|
* });
|
|
@@ -3331,19 +3440,13 @@ var TaxClient = class extends BaseClient {
|
|
|
3331
3440
|
{ method: "POST" }
|
|
3332
3441
|
);
|
|
3333
3442
|
}
|
|
3334
|
-
async
|
|
3335
|
-
return this.request(
|
|
3336
|
-
"/api/v1/tax/customer-tax-profiles/request-form-with-profile",
|
|
3337
|
-
{
|
|
3338
|
-
method: "POST",
|
|
3339
|
-
body: JSON.stringify(input)
|
|
3340
|
-
}
|
|
3341
|
-
);
|
|
3342
|
-
}
|
|
3343
|
-
async checkTINStatus(customerID) {
|
|
3443
|
+
async checkTINStatus(customerID, requestOptions) {
|
|
3344
3444
|
return this.requestWithRetry(
|
|
3345
3445
|
`/api/v1/tax/customer-tax-profiles/${customerID}/check-tin`,
|
|
3346
|
-
{ method: "POST" }
|
|
3446
|
+
{ method: "POST" },
|
|
3447
|
+
void 0,
|
|
3448
|
+
void 0,
|
|
3449
|
+
requestOptions
|
|
3347
3450
|
);
|
|
3348
3451
|
}
|
|
3349
3452
|
async reRequestTaxForm(customerID, input) {
|
|
@@ -3366,7 +3469,7 @@ var TaxClient = class extends BaseClient {
|
|
|
3366
3469
|
}
|
|
3367
3470
|
async getCustomerDocuments(customerID) {
|
|
3368
3471
|
return this.request(
|
|
3369
|
-
`/api/v1/
|
|
3472
|
+
`/api/v1/tm/customer-tax-profiles/${customerID}/documents`
|
|
3370
3473
|
);
|
|
3371
3474
|
}
|
|
3372
3475
|
async downloadTaxForm(customerID, requestOptions) {
|
|
@@ -3603,9 +3706,11 @@ exports.KycClient = KycClient;
|
|
|
3603
3706
|
exports.NetworkError = NetworkError;
|
|
3604
3707
|
exports.RateLimitError = RateLimitError;
|
|
3605
3708
|
exports.RateLimitTracker = RateLimitTracker;
|
|
3709
|
+
exports.RefreshingTokenProvider = RefreshingTokenProvider;
|
|
3606
3710
|
exports.RiskProfileClient = RiskProfileClient;
|
|
3607
3711
|
exports.SDK_VERSION = SDK_VERSION;
|
|
3608
3712
|
exports.ServiceUnavailableError = ServiceUnavailableError;
|
|
3713
|
+
exports.StaticApiKeyProvider = StaticApiKeyProvider;
|
|
3609
3714
|
exports.TaxClient = TaxClient;
|
|
3610
3715
|
exports.TimeoutError = TimeoutError;
|
|
3611
3716
|
exports.ValidationError = ValidationError;
|