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.
Files changed (75) hide show
  1. package/dist/{client-B32yBt1b.d.ts → client-0NOPDnT0.d.ts} +16 -26
  2. package/dist/{client-BqPVh5jH.d.mts → client-CvWNRwwg.d.mts} +16 -26
  3. package/dist/{client-CHPEgasE.d.mts → client-Dps40EtF.d.mts} +2 -2
  4. package/dist/{client-pKE_gii_.d.ts → client-SMxqod4j.d.ts} +2 -2
  5. package/dist/{client-6sSaxufk.d.mts → client-q9fN8Hhf.d.mts} +96 -1
  6. package/dist/{client-6sSaxufk.d.ts → client-q9fN8Hhf.d.ts} +96 -1
  7. package/dist/compliance/index.d.mts +3 -3
  8. package/dist/compliance/index.d.ts +3 -3
  9. package/dist/compliance/index.js +114 -16
  10. package/dist/compliance/index.js.map +1 -1
  11. package/dist/compliance/index.mjs +114 -16
  12. package/dist/compliance/index.mjs.map +1 -1
  13. package/dist/decisions/index.d.mts +1 -1
  14. package/dist/decisions/index.d.ts +1 -1
  15. package/dist/decisions/index.js +49 -4
  16. package/dist/decisions/index.js.map +1 -1
  17. package/dist/decisions/index.mjs +49 -4
  18. package/dist/decisions/index.mjs.map +1 -1
  19. package/dist/geolocation/index.d.mts +59 -4
  20. package/dist/geolocation/index.d.ts +59 -4
  21. package/dist/geolocation/index.js +117 -16
  22. package/dist/geolocation/index.js.map +1 -1
  23. package/dist/geolocation/index.mjs +115 -17
  24. package/dist/geolocation/index.mjs.map +1 -1
  25. package/dist/index-CPOrMRaH.d.ts +264 -0
  26. package/dist/index-CimDmgZb.d.mts +264 -0
  27. package/dist/index.d.mts +25 -8
  28. package/dist/index.d.ts +25 -8
  29. package/dist/index.js +274 -37
  30. package/dist/index.js.map +1 -1
  31. package/dist/index.mjs +267 -38
  32. package/dist/index.mjs.map +1 -1
  33. package/dist/kyc/core.d.mts +1 -1
  34. package/dist/kyc/core.d.ts +1 -1
  35. package/dist/kyc/core.js +49 -4
  36. package/dist/kyc/core.js.map +1 -1
  37. package/dist/kyc/core.mjs +49 -4
  38. package/dist/kyc/core.mjs.map +1 -1
  39. package/dist/kyc/index.d.mts +1 -1
  40. package/dist/kyc/index.d.ts +1 -1
  41. package/dist/kyc/index.js +49 -4
  42. package/dist/kyc/index.js.map +1 -1
  43. package/dist/kyc/index.mjs +49 -4
  44. package/dist/kyc/index.mjs.map +1 -1
  45. package/dist/react.d.mts +7 -3
  46. package/dist/react.d.ts +7 -3
  47. package/dist/react.js +68 -4
  48. package/dist/react.js.map +1 -1
  49. package/dist/react.mjs +68 -4
  50. package/dist/react.mjs.map +1 -1
  51. package/dist/risk-profile/index.d.mts +1 -1
  52. package/dist/risk-profile/index.d.ts +1 -1
  53. package/dist/risk-profile/index.js +49 -4
  54. package/dist/risk-profile/index.js.map +1 -1
  55. package/dist/risk-profile/index.mjs +49 -4
  56. package/dist/risk-profile/index.mjs.map +1 -1
  57. package/dist/scores/index.d.mts +1 -1
  58. package/dist/scores/index.d.ts +1 -1
  59. package/dist/scores/index.js +49 -4
  60. package/dist/scores/index.js.map +1 -1
  61. package/dist/scores/index.mjs +49 -4
  62. package/dist/scores/index.mjs.map +1 -1
  63. package/dist/tax/index.d.mts +1 -1
  64. package/dist/tax/index.d.ts +1 -1
  65. package/dist/tax/index.js +49 -4
  66. package/dist/tax/index.js.map +1 -1
  67. package/dist/tax/index.mjs +49 -4
  68. package/dist/tax/index.mjs.map +1 -1
  69. package/dist/webhooks/index.d.mts +2 -189
  70. package/dist/webhooks/index.d.ts +2 -189
  71. package/dist/webhooks/index.js +85 -21
  72. package/dist/webhooks/index.js.map +1 -1
  73. package/dist/webhooks/index.mjs +85 -22
  74. package/dist/webhooks/index.mjs.map +1 -1
  75. package/package.json +4 -1
@@ -1,6 +1,6 @@
1
1
  import { P as ProfileFilters, b as ProfileListResponse, C as CustomerProfile, a as CreateProfileRequest } from '../types-BOFaMQxI.mjs';
2
2
  import { c as Reason, R as RiskLevel, P as PaginationParams } from '../types-CBQRNL-l.mjs';
3
- import { B as BaseClient, R as RequestOptions } from '../client-6sSaxufk.mjs';
3
+ import { B as BaseClient, R as RequestOptions } from '../client-q9fN8Hhf.mjs';
4
4
 
5
5
  /**
6
6
  * TypeScript type definitions for Vesant KYC Service API
@@ -1,6 +1,6 @@
1
1
  import { P as ProfileFilters, b as ProfileListResponse, C as CustomerProfile, a as CreateProfileRequest } from '../types-UGyDl1fd.js';
2
2
  import { c as Reason, R as RiskLevel, P as PaginationParams } from '../types-CBQRNL-l.js';
3
- import { B as BaseClient, R as RequestOptions } from '../client-6sSaxufk.js';
3
+ import { B as BaseClient, R as RequestOptions } from '../client-q9fN8Hhf.js';
4
4
 
5
5
  /**
6
6
  * TypeScript type definitions for Vesant KYC Service API
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) {
@@ -241,6 +254,12 @@ var BaseClient = class {
241
254
  if (!config.tenantId?.trim()) {
242
255
  throw new ValidationError("tenantId is required and must be a non-empty string", ["tenantId"]);
243
256
  }
257
+ if (typeof fetch === "undefined") {
258
+ throw new VesantError(
259
+ "The Vesant SDK requires a global fetch (Node.js >= 18). Upgrade Node or provide a fetch polyfill.",
260
+ "RUNTIME_UNSUPPORTED"
261
+ );
262
+ }
244
263
  this.interceptors = config.interceptors || [];
245
264
  this.logger = config.logger || createConsoleLogger();
246
265
  let environment = config.environment;
@@ -259,11 +278,12 @@ var BaseClient = class {
259
278
  environment,
260
279
  headers: config.headers || {},
261
280
  timeout: config.timeout || 1e4,
262
- retries: config.retries || 3,
281
+ retries: config.retries ?? 3,
263
282
  debug: config.debug || false,
264
283
  interceptors: this.interceptors,
265
284
  logger: this.logger
266
285
  };
286
+ this.authProvider = config.authProvider ?? (apiKey ? new StaticApiKeyProvider(apiKey) : void 0);
267
287
  if (config.circuitBreaker) {
268
288
  this.circuitBreaker = new CircuitBreaker(config.circuitBreaker);
269
289
  }
@@ -309,8 +329,12 @@ var BaseClient = class {
309
329
  ...this.config.headers,
310
330
  ...options.headers || {}
311
331
  };
312
- if (this.config.apiKey) {
313
- headers["Authorization"] = `Bearer ${this.config.apiKey}`;
332
+ const credential = await this.authProvider?.getCredential({
333
+ tenantId: this.config.tenantId,
334
+ requestId
335
+ });
336
+ if (credential) {
337
+ headers["Authorization"] = `${credential.scheme ?? "Bearer"} ${credential.token}`;
314
338
  }
315
339
  if (this.config.environment === "sandbox") {
316
340
  headers["X-Sandbox"] = "true";
@@ -339,10 +363,28 @@ var BaseClient = class {
339
363
  if (this.config.debug) {
340
364
  this.logger.debug(`${finalOptions.method || "GET"} ${endpoint}`);
341
365
  }
342
- const response = await fetch(url, {
366
+ let response = await fetch(url, {
343
367
  ...finalOptions,
344
368
  signal: controller.signal
345
369
  });
370
+ if (response.status === 401 && this.authProvider?.canRefresh?.()) {
371
+ const refreshed = await this.authProvider.getCredential({
372
+ tenantId: this.config.tenantId,
373
+ requestId,
374
+ forceRefresh: true
375
+ });
376
+ if (refreshed) {
377
+ this.config.onCredentialRotated?.({ reason: "unauthorized" });
378
+ finalOptions = {
379
+ ...finalOptions,
380
+ headers: {
381
+ ...finalOptions.headers,
382
+ Authorization: `${refreshed.scheme ?? "Bearer"} ${refreshed.token}`
383
+ }
384
+ };
385
+ response = await fetch(url, { ...finalOptions, signal: controller.signal });
386
+ }
387
+ }
346
388
  clearTimeout(timeoutId);
347
389
  if (this.rateLimitTracker) {
348
390
  this.rateLimitTracker.updateFromHeaders(response.headers);
@@ -532,6 +574,9 @@ var BaseClient = class {
532
574
  if (config.interceptors) {
533
575
  this.interceptors = config.interceptors;
534
576
  }
577
+ if (config.authProvider !== void 0 || config.apiKey !== void 0) {
578
+ this.authProvider = this.config.authProvider ?? (this.config.apiKey ? new StaticApiKeyProvider(this.config.apiKey) : void 0);
579
+ }
535
580
  }
536
581
  /**
537
582
  * Get current configuration (readonly)