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.
Files changed (67) hide show
  1. package/dist/{client-C3DCmGe9.d.ts → client-749WqhDT.d.ts} +2 -2
  2. package/dist/{client-DMIRx7Tu.d.mts → client-BG8KtVMc.d.mts} +14 -1
  3. package/dist/{client-ZNdnpWe7.d.mts → client-CRZea-eJ.d.mts} +2 -2
  4. package/dist/{client-DoMSYMMR.d.ts → client-D9JZgN3X.d.ts} +14 -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 -9
  10. package/dist/compliance/index.js.map +1 -1
  11. package/dist/compliance/index.mjs +61 -9
  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 +6 -6
  26. package/dist/index.d.ts +6 -6
  27. package/dist/index.js +138 -33
  28. package/dist/index.js.map +1 -1
  29. package/dist/index.mjs +137 -34
  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 +110 -13
  38. package/dist/kyc/index.d.ts +110 -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 +5 -3
  44. package/dist/react.d.ts +5 -3
  45. package/dist/react.js +112 -73
  46. package/dist/react.js.map +1 -1
  47. package/dist/react.mjs +112 -73
  48. package/dist/react.mjs.map +1 -1
  49. package/dist/risk-profile/index.d.mts +1 -1
  50. package/dist/risk-profile/index.d.ts +1 -1
  51. package/dist/risk-profile/index.js +61 -6
  52. package/dist/risk-profile/index.js.map +1 -1
  53. package/dist/risk-profile/index.mjs +61 -6
  54. package/dist/risk-profile/index.mjs.map +1 -1
  55. package/dist/scores/index.d.mts +1 -1
  56. package/dist/scores/index.d.ts +1 -1
  57. package/dist/scores/index.js +61 -6
  58. package/dist/scores/index.js.map +1 -1
  59. package/dist/scores/index.mjs +61 -6
  60. package/dist/scores/index.mjs.map +1 -1
  61. package/dist/tax/index.d.mts +3 -26
  62. package/dist/tax/index.d.ts +3 -26
  63. package/dist/tax/index.js +67 -18
  64. package/dist/tax/index.js.map +1 -1
  65. package/dist/tax/index.mjs +67 -18
  66. package/dist/tax/index.mjs.map +1 -1
  67. package/package.json +1 -1
package/dist/kyc/core.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) {
@@ -262,6 +275,7 @@ var BaseClient = class {
262
275
  interceptors: this.interceptors,
263
276
  logger: this.logger
264
277
  };
278
+ this.authProvider = config.authProvider ?? (apiKey ? new StaticApiKeyProvider(apiKey) : void 0);
265
279
  if (config.circuitBreaker) {
266
280
  this.circuitBreaker = new CircuitBreaker(config.circuitBreaker);
267
281
  }
@@ -269,6 +283,19 @@ var BaseClient = class {
269
283
  this.rateLimitTracker = new RateLimitTracker();
270
284
  }
271
285
  }
286
+ /**
287
+ * Resolve the Idempotency-Key for a request. Mutating methods (POST/PUT/PATCH)
288
+ * get the caller-supplied key or a freshly minted UUID; non-mutating methods get
289
+ * none. requestWithRetry resolves this once and injects it so every retry reuses
290
+ * one key (letting the server dedup replays); a direct request() resolves per call.
291
+ */
292
+ resolveIdempotencyKey(method, requestOptions) {
293
+ const isMutating = ["POST", "PUT", "PATCH"].includes((method || "GET").toUpperCase());
294
+ if (!isMutating) {
295
+ return void 0;
296
+ }
297
+ return requestOptions?.idempotencyKey ?? generateUUID();
298
+ }
272
299
  /**
273
300
  * Make an HTTP request with timeout and error handling
274
301
  */
@@ -294,15 +321,20 @@ var BaseClient = class {
294
321
  ...this.config.headers,
295
322
  ...options.headers || {}
296
323
  };
297
- if (this.config.apiKey) {
298
- headers["Authorization"] = `Bearer ${this.config.apiKey}`;
324
+ const credential = await this.authProvider?.getCredential({
325
+ tenantId: this.config.tenantId,
326
+ requestId
327
+ });
328
+ if (credential) {
329
+ headers["Authorization"] = `${credential.scheme ?? "Bearer"} ${credential.token}`;
299
330
  }
300
331
  if (this.config.environment === "sandbox") {
301
332
  headers["X-Sandbox"] = "true";
302
333
  }
303
334
  const method = (options.method || "GET").toUpperCase();
304
- if (["POST", "PUT", "PATCH"].includes(method)) {
305
- headers["Idempotency-Key"] = requestOptions?.idempotencyKey || generateUUID();
335
+ const idempotencyKey = this.resolveIdempotencyKey(method, requestOptions);
336
+ if (idempotencyKey) {
337
+ headers["Idempotency-Key"] = idempotencyKey;
306
338
  }
307
339
  const controller = new AbortController();
308
340
  const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
@@ -323,10 +355,28 @@ var BaseClient = class {
323
355
  if (this.config.debug) {
324
356
  this.logger.debug(`${finalOptions.method || "GET"} ${endpoint}`);
325
357
  }
326
- const response = await fetch(url, {
358
+ let response = await fetch(url, {
327
359
  ...finalOptions,
328
360
  signal: controller.signal
329
361
  });
362
+ if (response.status === 401 && this.authProvider?.canRefresh?.()) {
363
+ const refreshed = await this.authProvider.getCredential({
364
+ tenantId: this.config.tenantId,
365
+ requestId,
366
+ forceRefresh: true
367
+ });
368
+ if (refreshed) {
369
+ this.config.onCredentialRotated?.({ reason: "unauthorized" });
370
+ finalOptions = {
371
+ ...finalOptions,
372
+ headers: {
373
+ ...finalOptions.headers,
374
+ Authorization: `${refreshed.scheme ?? "Bearer"} ${refreshed.token}`
375
+ }
376
+ };
377
+ response = await fetch(url, { ...finalOptions, signal: controller.signal });
378
+ }
379
+ }
330
380
  clearTimeout(timeoutId);
331
381
  if (this.rateLimitTracker) {
332
382
  this.rateLimitTracker.updateFromHeaders(response.headers);
@@ -415,9 +465,11 @@ var BaseClient = class {
415
465
  */
416
466
  async requestWithRetry(endpoint, options = {}, serviceURL, retries = this.config.retries, requestOptions) {
417
467
  let lastError;
468
+ const idempotencyKey = this.resolveIdempotencyKey(options.method || "GET", requestOptions);
469
+ const attemptOptions = idempotencyKey ? { ...requestOptions, idempotencyKey } : requestOptions;
418
470
  for (let attempt = 0; attempt <= retries; attempt++) {
419
471
  try {
420
- return await this.request(endpoint, options, serviceURL, requestOptions);
472
+ return await this.request(endpoint, options, serviceURL, attemptOptions);
421
473
  } catch (error) {
422
474
  lastError = error instanceof Error ? error : new Error("Unknown error");
423
475
  if (requestOptions?.signal?.aborted) {
@@ -514,6 +566,9 @@ var BaseClient = class {
514
566
  if (config.interceptors) {
515
567
  this.interceptors = config.interceptors;
516
568
  }
569
+ if (config.authProvider !== void 0 || config.apiKey !== void 0) {
570
+ this.authProvider = this.config.authProvider ?? (this.config.apiKey ? new StaticApiKeyProvider(this.config.apiKey) : void 0);
571
+ }
517
572
  }
518
573
  /**
519
574
  * Get current configuration (readonly)
@@ -601,7 +656,13 @@ var KycClient = class extends BaseClient {
601
656
  *
602
657
  * Generates a link that the user can visit to submit their KYC documents.
603
658
  *
604
- * @param request - Request containing the user ID, optional redirect URL, and optional callback URL (receives POST requests)
659
+ * Optionally pass the customer's registered identity data as
660
+ * `customer_data` (same shape as the geolocation `customer_data` block).
661
+ * It seeds the customer's risk profile so document verification can
662
+ * cross-check the submitted document against trusted reference data;
663
+ * fields never overwrite data already on the profile.
664
+ *
665
+ * @param request - Request containing the user ID, optional redirect URL, optional callback URL (receives POST requests), and optional customer identity data
605
666
  * @returns Response containing the redirect link and KYC ID
606
667
  *
607
668
  * @example
@@ -609,19 +670,27 @@ var KycClient = class extends BaseClient {
609
670
  * const result = await client.requestKycSubmitLink({
610
671
  * user_id: "user_123",
611
672
  * redirect_url: "https://merchant.com/kyc-complete", // optional
612
- * callback_url: "https://merchant.com/api/kyc-webhook" // optional - receives POST requests on status change
673
+ * callback_url: "https://merchant.com/api/kyc-webhook", // optional - receives POST requests on status change
674
+ * customer_data: { // optional - seeds the risk profile for document cross-checks
675
+ * full_name: "John Doe",
676
+ * date_of_birth: "1999-06-02", // ISO 8601
677
+ * email: "john@example.com",
678
+ * phone: "+94771234567",
679
+ * address: "12 Main St, Colombo", // used for address verification
680
+ * country: "LK"
681
+ * }
613
682
  * });
614
683
  *
615
684
  * console.log(`Redirect user to: ${result.link}`);
616
685
  * console.log(`KYC ID: ${result.kyc_id}`);
617
686
  * ```
618
687
  */
619
- async requestKycSubmitLink(request) {
688
+ async requestKycSubmitLink(request, requestOptions) {
620
689
  return this.requestWithRetry("/api/v1/kyc/request", {
621
690
  method: "POST",
622
691
  body: JSON.stringify(request),
623
692
  headers: this.getUserHeaders()
624
- });
693
+ }, void 0, void 0, requestOptions);
625
694
  }
626
695
  /**
627
696
  * Create a Event-Based Face Verification session.
@@ -654,12 +723,12 @@ var KycClient = class extends BaseClient {
654
723
  *
655
724
  * @param request - Token from `createEventBasedFaceVerificationSession`, plus the base64 selfie.
656
725
  */
657
- async submitEventBasedFaceVerificationSession(request) {
726
+ async submitEventBasedFaceVerificationSession(request, requestOptions) {
658
727
  return this.request("/api/v1/kyc/face/submit", {
659
728
  method: "POST",
660
729
  body: JSON.stringify(request),
661
730
  headers: this.getUserHeaders()
662
- });
731
+ }, void 0, requestOptions);
663
732
  }
664
733
  /**
665
734
  * Look up the current state of a Event-Based Face Verification session by its
@@ -758,7 +827,7 @@ var KycClient = class extends BaseClient {
758
827
  * @example
759
828
  * ```typescript
760
829
  * const result = await client.submitVerification({
761
- * reference: "customer_123",
830
+ * reference: "4d2aff34-ab86-422d-992e-50b1234a5b67",
762
831
  * email: "customer@example.com",
763
832
  * country: "US",
764
833
  * document: {
@@ -775,12 +844,12 @@ var KycClient = class extends BaseClient {
775
844
  * console.log(`Verification submitted: ${result.reference}`);
776
845
  * ```
777
846
  */
778
- async submitVerification(request) {
847
+ async submitVerification(request, requestOptions) {
779
848
  return this.requestWithRetry("/api/v1/kyc/submit", {
780
849
  method: "POST",
781
850
  body: JSON.stringify(request),
782
851
  headers: this.getUserHeaders()
783
- });
852
+ }, void 0, void 0, requestOptions);
784
853
  }
785
854
  /**
786
855
  * Get a KYC request by ID
@@ -790,7 +859,7 @@ var KycClient = class extends BaseClient {
790
859
  *
791
860
  * @example
792
861
  * ```typescript
793
- * const kyc = await client.getKycRequest("kyc_abc123");
862
+ * const kyc = await client.getKycRequest("550e8400-e29b-41d4-a716-446655440000");
794
863
  * console.log(`Status: ${kyc.status}, ID Verified: ${kyc.id_verified}`);
795
864
  * ```
796
865
  */
@@ -865,7 +934,7 @@ var KycClient = class extends BaseClient {
865
934
  * @example
866
935
  * ```typescript
867
936
  * await client.requestAdditionalDocuments({
868
- * id: "kyc_abc123",
937
+ * id: "550e8400-e29b-41d4-a716-446655440000",
869
938
  * document_types: ["address", "document_two"],
870
939
  * message: "Please provide proof of address and secondary ID"
871
940
  * });
@@ -886,7 +955,7 @@ var KycClient = class extends BaseClient {
886
955
  *
887
956
  * @example
888
957
  * ```typescript
889
- * const proofs = await client.getProofDownloadURLs("kyc_abc123");
958
+ * const proofs = await client.getProofDownloadURLs("550e8400-e29b-41d4-a716-446655440000");
890
959
  * proofs.forEach(proof => {
891
960
  * console.log(`${proof.type}: ${proof.url} (expires: ${proof.expires_at})`);
892
961
  * });