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
|
@@ -73,6 +73,19 @@ var sdkReasons = {
|
|
|
73
73
|
})
|
|
74
74
|
};
|
|
75
75
|
|
|
76
|
+
// src/core/auth.ts
|
|
77
|
+
var StaticApiKeyProvider = class {
|
|
78
|
+
constructor(apiKey) {
|
|
79
|
+
this.apiKey = apiKey;
|
|
80
|
+
}
|
|
81
|
+
async getCredential() {
|
|
82
|
+
return this.apiKey ? { scheme: "Bearer", token: this.apiKey } : null;
|
|
83
|
+
}
|
|
84
|
+
canRefresh() {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
76
89
|
// src/core/errors.ts
|
|
77
90
|
var VesantError = class _VesantError extends Error {
|
|
78
91
|
constructor(message, code, statusCode, details) {
|
|
@@ -402,6 +415,7 @@ var BaseClient = class {
|
|
|
402
415
|
interceptors: this.interceptors,
|
|
403
416
|
logger: this.logger
|
|
404
417
|
};
|
|
418
|
+
this.authProvider = config.authProvider ?? (apiKey ? new StaticApiKeyProvider(apiKey) : void 0);
|
|
405
419
|
if (config.circuitBreaker) {
|
|
406
420
|
this.circuitBreaker = new CircuitBreaker(config.circuitBreaker);
|
|
407
421
|
}
|
|
@@ -409,6 +423,19 @@ var BaseClient = class {
|
|
|
409
423
|
this.rateLimitTracker = new RateLimitTracker();
|
|
410
424
|
}
|
|
411
425
|
}
|
|
426
|
+
/**
|
|
427
|
+
* Resolve the Idempotency-Key for a request. Mutating methods (POST/PUT/PATCH)
|
|
428
|
+
* get the caller-supplied key or a freshly minted UUID; non-mutating methods get
|
|
429
|
+
* none. requestWithRetry resolves this once and injects it so every retry reuses
|
|
430
|
+
* one key (letting the server dedup replays); a direct request() resolves per call.
|
|
431
|
+
*/
|
|
432
|
+
resolveIdempotencyKey(method, requestOptions) {
|
|
433
|
+
const isMutating = ["POST", "PUT", "PATCH"].includes((method || "GET").toUpperCase());
|
|
434
|
+
if (!isMutating) {
|
|
435
|
+
return void 0;
|
|
436
|
+
}
|
|
437
|
+
return requestOptions?.idempotencyKey ?? generateUUID();
|
|
438
|
+
}
|
|
412
439
|
/**
|
|
413
440
|
* Make an HTTP request with timeout and error handling
|
|
414
441
|
*/
|
|
@@ -434,15 +461,20 @@ var BaseClient = class {
|
|
|
434
461
|
...this.config.headers,
|
|
435
462
|
...options.headers || {}
|
|
436
463
|
};
|
|
437
|
-
|
|
438
|
-
|
|
464
|
+
const credential = await this.authProvider?.getCredential({
|
|
465
|
+
tenantId: this.config.tenantId,
|
|
466
|
+
requestId
|
|
467
|
+
});
|
|
468
|
+
if (credential) {
|
|
469
|
+
headers["Authorization"] = `${credential.scheme ?? "Bearer"} ${credential.token}`;
|
|
439
470
|
}
|
|
440
471
|
if (this.config.environment === "sandbox") {
|
|
441
472
|
headers["X-Sandbox"] = "true";
|
|
442
473
|
}
|
|
443
474
|
const method = (options.method || "GET").toUpperCase();
|
|
444
|
-
|
|
445
|
-
|
|
475
|
+
const idempotencyKey = this.resolveIdempotencyKey(method, requestOptions);
|
|
476
|
+
if (idempotencyKey) {
|
|
477
|
+
headers["Idempotency-Key"] = idempotencyKey;
|
|
446
478
|
}
|
|
447
479
|
const controller = new AbortController();
|
|
448
480
|
const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
|
|
@@ -463,10 +495,28 @@ var BaseClient = class {
|
|
|
463
495
|
if (this.config.debug) {
|
|
464
496
|
this.logger.debug(`${finalOptions.method || "GET"} ${endpoint}`);
|
|
465
497
|
}
|
|
466
|
-
|
|
498
|
+
let response = await fetch(url, {
|
|
467
499
|
...finalOptions,
|
|
468
500
|
signal: controller.signal
|
|
469
501
|
});
|
|
502
|
+
if (response.status === 401 && this.authProvider?.canRefresh?.()) {
|
|
503
|
+
const refreshed = await this.authProvider.getCredential({
|
|
504
|
+
tenantId: this.config.tenantId,
|
|
505
|
+
requestId,
|
|
506
|
+
forceRefresh: true
|
|
507
|
+
});
|
|
508
|
+
if (refreshed) {
|
|
509
|
+
this.config.onCredentialRotated?.({ reason: "unauthorized" });
|
|
510
|
+
finalOptions = {
|
|
511
|
+
...finalOptions,
|
|
512
|
+
headers: {
|
|
513
|
+
...finalOptions.headers,
|
|
514
|
+
Authorization: `${refreshed.scheme ?? "Bearer"} ${refreshed.token}`
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
response = await fetch(url, { ...finalOptions, signal: controller.signal });
|
|
518
|
+
}
|
|
519
|
+
}
|
|
470
520
|
clearTimeout(timeoutId);
|
|
471
521
|
if (this.rateLimitTracker) {
|
|
472
522
|
this.rateLimitTracker.updateFromHeaders(response.headers);
|
|
@@ -555,9 +605,11 @@ var BaseClient = class {
|
|
|
555
605
|
*/
|
|
556
606
|
async requestWithRetry(endpoint, options = {}, serviceURL, retries = this.config.retries, requestOptions) {
|
|
557
607
|
let lastError;
|
|
608
|
+
const idempotencyKey = this.resolveIdempotencyKey(options.method || "GET", requestOptions);
|
|
609
|
+
const attemptOptions = idempotencyKey ? { ...requestOptions, idempotencyKey } : requestOptions;
|
|
558
610
|
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
559
611
|
try {
|
|
560
|
-
return await this.request(endpoint, options, serviceURL,
|
|
612
|
+
return await this.request(endpoint, options, serviceURL, attemptOptions);
|
|
561
613
|
} catch (error) {
|
|
562
614
|
lastError = error instanceof Error ? error : new Error("Unknown error");
|
|
563
615
|
if (requestOptions?.signal?.aborted) {
|
|
@@ -654,6 +706,9 @@ var BaseClient = class {
|
|
|
654
706
|
if (config.interceptors) {
|
|
655
707
|
this.interceptors = config.interceptors;
|
|
656
708
|
}
|
|
709
|
+
if (config.authProvider !== void 0 || config.apiKey !== void 0) {
|
|
710
|
+
this.authProvider = this.config.authProvider ?? (this.config.apiKey ? new StaticApiKeyProvider(this.config.apiKey) : void 0);
|
|
711
|
+
}
|
|
657
712
|
}
|
|
658
713
|
/**
|
|
659
714
|
* Get current configuration (readonly)
|
|
@@ -1712,9 +1767,6 @@ var ComplianceClient = class {
|
|
|
1712
1767
|
if (cipherTextResult.risk?.is_blocked) {
|
|
1713
1768
|
blockReasons.push(...cipherTextResult.risk.block_reasons_structured ?? []);
|
|
1714
1769
|
}
|
|
1715
|
-
if (cipherTextResult.risk?.location_mismatch) {
|
|
1716
|
-
blockReasons.push(sdkReasons.gpsIPMismatch());
|
|
1717
|
-
}
|
|
1718
1770
|
}
|
|
1719
1771
|
if (geoVerification.gps_required && !cipherTextResult) {
|
|
1720
1772
|
blockReasons.push(sdkReasons.gpsRequired());
|