vesant-sdk 1.7.0-dev.b2c9ecf → 1.7.0-dev.b4284ca
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-B32yBt1b.d.ts → client-0NOPDnT0.d.ts} +16 -26
- package/dist/{client-BqPVh5jH.d.mts → client-CvWNRwwg.d.mts} +16 -26
- package/dist/{client-CHPEgasE.d.mts → client-Dps40EtF.d.mts} +2 -2
- package/dist/{client-pKE_gii_.d.ts → client-SMxqod4j.d.ts} +2 -2
- package/dist/{client-6sSaxufk.d.mts → client-q9fN8Hhf.d.mts} +96 -1
- package/dist/{client-6sSaxufk.d.ts → client-q9fN8Hhf.d.ts} +96 -1
- package/dist/compliance/index.d.mts +3 -3
- package/dist/compliance/index.d.ts +3 -3
- package/dist/compliance/index.js +114 -16
- package/dist/compliance/index.js.map +1 -1
- package/dist/compliance/index.mjs +114 -16
- 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 +49 -4
- package/dist/decisions/index.js.map +1 -1
- package/dist/decisions/index.mjs +49 -4
- 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 +117 -16
- package/dist/geolocation/index.js.map +1 -1
- package/dist/geolocation/index.mjs +115 -17
- package/dist/geolocation/index.mjs.map +1 -1
- package/dist/index-CPOrMRaH.d.ts +264 -0
- package/dist/index-CimDmgZb.d.mts +264 -0
- package/dist/index.d.mts +25 -8
- package/dist/index.d.ts +25 -8
- package/dist/index.js +274 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +267 -38
- package/dist/index.mjs.map +1 -1
- package/dist/kyc/core.d.mts +1 -1
- package/dist/kyc/core.d.ts +1 -1
- package/dist/kyc/core.js +49 -4
- package/dist/kyc/core.js.map +1 -1
- package/dist/kyc/core.mjs +49 -4
- package/dist/kyc/core.mjs.map +1 -1
- package/dist/kyc/index.d.mts +1 -1
- package/dist/kyc/index.d.ts +1 -1
- package/dist/kyc/index.js +49 -4
- package/dist/kyc/index.js.map +1 -1
- package/dist/kyc/index.mjs +49 -4
- package/dist/kyc/index.mjs.map +1 -1
- package/dist/react.d.mts +7 -3
- package/dist/react.d.ts +7 -3
- package/dist/react.js +68 -4
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +68 -4
- 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 +49 -4
- package/dist/risk-profile/index.js.map +1 -1
- package/dist/risk-profile/index.mjs +49 -4
- 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 +49 -4
- package/dist/scores/index.js.map +1 -1
- package/dist/scores/index.mjs +49 -4
- package/dist/scores/index.mjs.map +1 -1
- package/dist/tax/index.d.mts +1 -1
- package/dist/tax/index.d.ts +1 -1
- package/dist/tax/index.js +49 -4
- package/dist/tax/index.js.map +1 -1
- package/dist/tax/index.mjs +49 -4
- 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/index.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) {
|
|
@@ -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
|
}
|
|
@@ -307,8 +327,12 @@ var BaseClient = class {
|
|
|
307
327
|
...this.config.headers,
|
|
308
328
|
...options.headers || {}
|
|
309
329
|
};
|
|
310
|
-
|
|
311
|
-
|
|
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}`;
|
|
312
336
|
}
|
|
313
337
|
if (this.config.environment === "sandbox") {
|
|
314
338
|
headers["X-Sandbox"] = "true";
|
|
@@ -337,10 +361,28 @@ var BaseClient = class {
|
|
|
337
361
|
if (this.config.debug) {
|
|
338
362
|
this.logger.debug(`${finalOptions.method || "GET"} ${endpoint}`);
|
|
339
363
|
}
|
|
340
|
-
|
|
364
|
+
let response = await fetch(url, {
|
|
341
365
|
...finalOptions,
|
|
342
366
|
signal: controller.signal
|
|
343
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
|
+
}
|
|
344
386
|
clearTimeout(timeoutId);
|
|
345
387
|
if (this.rateLimitTracker) {
|
|
346
388
|
this.rateLimitTracker.updateFromHeaders(response.headers);
|
|
@@ -530,6 +572,9 @@ var BaseClient = class {
|
|
|
530
572
|
if (config.interceptors) {
|
|
531
573
|
this.interceptors = config.interceptors;
|
|
532
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
|
+
}
|
|
533
578
|
}
|
|
534
579
|
/**
|
|
535
580
|
* Get current configuration (readonly)
|