vesant-sdk 1.7.0-dev.117915b → 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.
Files changed (63) hide show
  1. package/dist/{client-DtH2RLuy.d.ts → client-749WqhDT.d.ts} +2 -2
  2. package/dist/{client-DrjgZoH_.d.mts → client-BG8KtVMc.d.mts} +1 -1
  3. package/dist/{client-B0qhE2kr.d.mts → client-CRZea-eJ.d.mts} +2 -2
  4. package/dist/{client-DF7hlMEz.d.ts → client-D9JZgN3X.d.ts} +1 -1
  5. package/dist/{client-BolQlL5e.d.mts → client-q9fN8Hhf.d.mts} +103 -1
  6. package/dist/{client-BolQlL5e.d.ts → client-q9fN8Hhf.d.ts} +103 -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 +61 -6
  10. package/dist/compliance/index.js.map +1 -1
  11. package/dist/compliance/index.mjs +61 -6
  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 +61 -6
  16. package/dist/decisions/index.js.map +1 -1
  17. package/dist/decisions/index.mjs +61 -6
  18. package/dist/decisions/index.mjs.map +1 -1
  19. package/dist/geolocation/index.d.mts +3 -3
  20. package/dist/geolocation/index.d.ts +3 -3
  21. package/dist/geolocation/index.js +61 -6
  22. package/dist/geolocation/index.js.map +1 -1
  23. package/dist/geolocation/index.mjs +61 -6
  24. package/dist/geolocation/index.mjs.map +1 -1
  25. package/dist/index.d.mts +5 -5
  26. package/dist/index.d.ts +5 -5
  27. package/dist/index.js +137 -20
  28. package/dist/index.js.map +1 -1
  29. package/dist/index.mjs +136 -21
  30. package/dist/index.mjs.map +1 -1
  31. package/dist/kyc/core.d.mts +2 -2
  32. package/dist/kyc/core.d.ts +2 -2
  33. package/dist/kyc/core.js +87 -18
  34. package/dist/kyc/core.js.map +1 -1
  35. package/dist/kyc/core.mjs +87 -18
  36. package/dist/kyc/core.mjs.map +1 -1
  37. package/dist/kyc/index.d.mts +81 -13
  38. package/dist/kyc/index.d.ts +81 -13
  39. package/dist/kyc/index.js +87 -18
  40. package/dist/kyc/index.js.map +1 -1
  41. package/dist/kyc/index.mjs +87 -18
  42. package/dist/kyc/index.mjs.map +1 -1
  43. package/dist/react.d.mts +3 -3
  44. package/dist/react.d.ts +3 -3
  45. package/dist/risk-profile/index.d.mts +1 -1
  46. package/dist/risk-profile/index.d.ts +1 -1
  47. package/dist/risk-profile/index.js +61 -6
  48. package/dist/risk-profile/index.js.map +1 -1
  49. package/dist/risk-profile/index.mjs +61 -6
  50. package/dist/risk-profile/index.mjs.map +1 -1
  51. package/dist/scores/index.d.mts +1 -1
  52. package/dist/scores/index.d.ts +1 -1
  53. package/dist/scores/index.js +61 -6
  54. package/dist/scores/index.js.map +1 -1
  55. package/dist/scores/index.mjs +61 -6
  56. package/dist/scores/index.mjs.map +1 -1
  57. package/dist/tax/index.d.mts +2 -2
  58. package/dist/tax/index.d.ts +2 -2
  59. package/dist/tax/index.js +66 -8
  60. package/dist/tax/index.js.map +1 -1
  61. package/dist/tax/index.mjs +66 -8
  62. package/dist/tax/index.mjs.map +1 -1
  63. 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
- if (this.config.apiKey) {
383
- headers["Authorization"] = `Bearer ${this.config.apiKey}`;
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
- if (["POST", "PUT", "PATCH"].includes(method)) {
390
- headers["Idempotency-Key"] = requestOptions?.idempotencyKey || generateUUID();
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
- const response = await fetch(url, {
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, requestOptions);
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)
@@ -2709,7 +2807,13 @@ var KycClient = class extends BaseClient {
2709
2807
  *
2710
2808
  * Generates a link that the user can visit to submit their KYC documents.
2711
2809
  *
2712
- * @param request - Request containing the user ID, optional redirect URL, and optional callback URL (receives POST requests)
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
2713
2817
  * @returns Response containing the redirect link and KYC ID
2714
2818
  *
2715
2819
  * @example
@@ -2717,19 +2821,27 @@ var KycClient = class extends BaseClient {
2717
2821
  * const result = await client.requestKycSubmitLink({
2718
2822
  * user_id: "user_123",
2719
2823
  * redirect_url: "https://merchant.com/kyc-complete", // optional
2720
- * 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
+ * }
2721
2833
  * });
2722
2834
  *
2723
2835
  * console.log(`Redirect user to: ${result.link}`);
2724
2836
  * console.log(`KYC ID: ${result.kyc_id}`);
2725
2837
  * ```
2726
2838
  */
2727
- async requestKycSubmitLink(request) {
2839
+ async requestKycSubmitLink(request, requestOptions) {
2728
2840
  return this.requestWithRetry("/api/v1/kyc/request", {
2729
2841
  method: "POST",
2730
2842
  body: JSON.stringify(request),
2731
2843
  headers: this.getUserHeaders()
2732
- });
2844
+ }, void 0, void 0, requestOptions);
2733
2845
  }
2734
2846
  /**
2735
2847
  * Create a Event-Based Face Verification session.
@@ -2762,12 +2874,12 @@ var KycClient = class extends BaseClient {
2762
2874
  *
2763
2875
  * @param request - Token from `createEventBasedFaceVerificationSession`, plus the base64 selfie.
2764
2876
  */
2765
- async submitEventBasedFaceVerificationSession(request) {
2877
+ async submitEventBasedFaceVerificationSession(request, requestOptions) {
2766
2878
  return this.request("/api/v1/kyc/face/submit", {
2767
2879
  method: "POST",
2768
2880
  body: JSON.stringify(request),
2769
2881
  headers: this.getUserHeaders()
2770
- });
2882
+ }, void 0, requestOptions);
2771
2883
  }
2772
2884
  /**
2773
2885
  * Look up the current state of a Event-Based Face Verification session by its
@@ -2866,7 +2978,7 @@ var KycClient = class extends BaseClient {
2866
2978
  * @example
2867
2979
  * ```typescript
2868
2980
  * const result = await client.submitVerification({
2869
- * reference: "customer_123",
2981
+ * reference: "4d2aff34-ab86-422d-992e-50b1234a5b67",
2870
2982
  * email: "customer@example.com",
2871
2983
  * country: "US",
2872
2984
  * document: {
@@ -2883,12 +2995,12 @@ var KycClient = class extends BaseClient {
2883
2995
  * console.log(`Verification submitted: ${result.reference}`);
2884
2996
  * ```
2885
2997
  */
2886
- async submitVerification(request) {
2998
+ async submitVerification(request, requestOptions) {
2887
2999
  return this.requestWithRetry("/api/v1/kyc/submit", {
2888
3000
  method: "POST",
2889
3001
  body: JSON.stringify(request),
2890
3002
  headers: this.getUserHeaders()
2891
- });
3003
+ }, void 0, void 0, requestOptions);
2892
3004
  }
2893
3005
  /**
2894
3006
  * Get a KYC request by ID
@@ -2898,7 +3010,7 @@ var KycClient = class extends BaseClient {
2898
3010
  *
2899
3011
  * @example
2900
3012
  * ```typescript
2901
- * const kyc = await client.getKycRequest("kyc_abc123");
3013
+ * const kyc = await client.getKycRequest("550e8400-e29b-41d4-a716-446655440000");
2902
3014
  * console.log(`Status: ${kyc.status}, ID Verified: ${kyc.id_verified}`);
2903
3015
  * ```
2904
3016
  */
@@ -2973,7 +3085,7 @@ var KycClient = class extends BaseClient {
2973
3085
  * @example
2974
3086
  * ```typescript
2975
3087
  * await client.requestAdditionalDocuments({
2976
- * id: "kyc_abc123",
3088
+ * id: "550e8400-e29b-41d4-a716-446655440000",
2977
3089
  * document_types: ["address", "document_two"],
2978
3090
  * message: "Please provide proof of address and secondary ID"
2979
3091
  * });
@@ -2994,7 +3106,7 @@ var KycClient = class extends BaseClient {
2994
3106
  *
2995
3107
  * @example
2996
3108
  * ```typescript
2997
- * const proofs = await client.getProofDownloadURLs("kyc_abc123");
3109
+ * const proofs = await client.getProofDownloadURLs("550e8400-e29b-41d4-a716-446655440000");
2998
3110
  * proofs.forEach(proof => {
2999
3111
  * console.log(`${proof.type}: ${proof.url} (expires: ${proof.expires_at})`);
3000
3112
  * });
@@ -3328,10 +3440,13 @@ var TaxClient = class extends BaseClient {
3328
3440
  { method: "POST" }
3329
3441
  );
3330
3442
  }
3331
- async checkTINStatus(customerID) {
3443
+ async checkTINStatus(customerID, requestOptions) {
3332
3444
  return this.requestWithRetry(
3333
3445
  `/api/v1/tax/customer-tax-profiles/${customerID}/check-tin`,
3334
- { method: "POST" }
3446
+ { method: "POST" },
3447
+ void 0,
3448
+ void 0,
3449
+ requestOptions
3335
3450
  );
3336
3451
  }
3337
3452
  async reRequestTaxForm(customerID, input) {
@@ -3591,9 +3706,11 @@ exports.KycClient = KycClient;
3591
3706
  exports.NetworkError = NetworkError;
3592
3707
  exports.RateLimitError = RateLimitError;
3593
3708
  exports.RateLimitTracker = RateLimitTracker;
3709
+ exports.RefreshingTokenProvider = RefreshingTokenProvider;
3594
3710
  exports.RiskProfileClient = RiskProfileClient;
3595
3711
  exports.SDK_VERSION = SDK_VERSION;
3596
3712
  exports.ServiceUnavailableError = ServiceUnavailableError;
3713
+ exports.StaticApiKeyProvider = StaticApiKeyProvider;
3597
3714
  exports.TaxClient = TaxClient;
3598
3715
  exports.TimeoutError = TimeoutError;
3599
3716
  exports.ValidationError = ValidationError;