vesant-sdk 1.7.2 → 1.8.0-dev.00f6233

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 (72) hide show
  1. package/README.md +3 -3
  2. package/dist/{client-B3DCAHlg.d.ts → client-BPALLldd.d.ts} +2 -2
  3. package/dist/{client-fy3trF2K.d.ts → client-BaUekQT8.d.ts} +32 -10
  4. package/dist/{client-BwXMQA2a.d.mts → client-XDEhh9VN.d.mts} +32 -10
  5. package/dist/{client-D23KhWeh.d.mts → client-_OhkfnyJ.d.mts} +2 -2
  6. package/dist/compliance/index.d.mts +3 -3
  7. package/dist/compliance/index.d.ts +3 -3
  8. package/dist/compliance/index.js +66 -11
  9. package/dist/compliance/index.js.map +1 -1
  10. package/dist/compliance/index.mjs +66 -11
  11. package/dist/compliance/index.mjs.map +1 -1
  12. package/dist/decisions/index.js +8 -7
  13. package/dist/decisions/index.js.map +1 -1
  14. package/dist/decisions/index.mjs +8 -7
  15. package/dist/decisions/index.mjs.map +1 -1
  16. package/dist/geolocation/index.d.mts +2 -2
  17. package/dist/geolocation/index.d.ts +2 -2
  18. package/dist/geolocation/index.js +47 -8
  19. package/dist/geolocation/index.js.map +1 -1
  20. package/dist/geolocation/index.mjs +47 -8
  21. package/dist/geolocation/index.mjs.map +1 -1
  22. package/dist/{index-DSDgS09k.d.ts → index-BosFSGan.d.ts} +57 -2
  23. package/dist/{index-C3zUKydT.d.mts → index-C49a7fg2.d.mts} +57 -2
  24. package/dist/index.d.mts +6 -6
  25. package/dist/index.d.ts +6 -6
  26. package/dist/index.js +104 -169
  27. package/dist/index.js.map +1 -1
  28. package/dist/index.mjs +101 -170
  29. package/dist/index.mjs.map +1 -1
  30. package/dist/kyc/core.d.mts +2 -2
  31. package/dist/kyc/core.d.ts +2 -2
  32. package/dist/kyc/core.js +39 -165
  33. package/dist/kyc/core.js.map +1 -1
  34. package/dist/kyc/core.mjs +38 -166
  35. package/dist/kyc/core.mjs.map +1 -1
  36. package/dist/kyc/index.d.mts +219 -218
  37. package/dist/kyc/index.d.ts +219 -218
  38. package/dist/kyc/index.js +39 -165
  39. package/dist/kyc/index.js.map +1 -1
  40. package/dist/kyc/index.mjs +38 -166
  41. package/dist/kyc/index.mjs.map +1 -1
  42. package/dist/react.d.mts +24 -115
  43. package/dist/react.d.ts +24 -115
  44. package/dist/react.js +23 -196
  45. package/dist/react.js.map +1 -1
  46. package/dist/react.mjs +24 -194
  47. package/dist/react.mjs.map +1 -1
  48. package/dist/risk-profile/index.d.mts +16 -6
  49. package/dist/risk-profile/index.d.ts +16 -6
  50. package/dist/risk-profile/index.js +26 -9
  51. package/dist/risk-profile/index.js.map +1 -1
  52. package/dist/risk-profile/index.mjs +26 -10
  53. package/dist/risk-profile/index.mjs.map +1 -1
  54. package/dist/scores/index.js +8 -7
  55. package/dist/scores/index.js.map +1 -1
  56. package/dist/scores/index.mjs +8 -7
  57. package/dist/scores/index.mjs.map +1 -1
  58. package/dist/tax/index.d.mts +1 -1
  59. package/dist/tax/index.d.ts +1 -1
  60. package/dist/tax/index.js +8 -7
  61. package/dist/tax/index.js.map +1 -1
  62. package/dist/tax/index.mjs +8 -7
  63. package/dist/tax/index.mjs.map +1 -1
  64. package/dist/{types-BOFaMQxI.d.mts → types-DbvVph_0.d.mts} +45 -2
  65. package/dist/{types-UGyDl1fd.d.ts → types-qXamJr2q.d.ts} +45 -2
  66. package/dist/webhooks/index.d.mts +1 -1
  67. package/dist/webhooks/index.d.ts +1 -1
  68. package/dist/webhooks/index.js +6 -0
  69. package/dist/webhooks/index.js.map +1 -1
  70. package/dist/webhooks/index.mjs +6 -1
  71. package/dist/webhooks/index.mjs.map +1 -1
  72. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -298,7 +298,7 @@ var noopLogger = {
298
298
  };
299
299
 
300
300
  // src/core/version.ts
301
- var SDK_VERSION = "1.7.2";
301
+ var SDK_VERSION = "1.8.0";
302
302
 
303
303
  // src/shared/browser-utils.ts
304
304
  function generateUUID() {
@@ -633,19 +633,20 @@ var BaseClient = class {
633
633
  * Handle error responses from API
634
634
  */
635
635
  handleErrorResponse(status, data, requestId) {
636
- const message = data.error || data.message || `HTTP ${status}`;
636
+ const structured = data.error && typeof data.error === "object" && !Array.isArray(data.error) ? data.error : void 0;
637
+ const message = typeof data.error === "string" && data.error || typeof structured?.message === "string" && structured.message || typeof data.message === "string" && data.message || `HTTP ${status}`;
637
638
  const createError = () => {
638
639
  switch (status) {
639
640
  case 400:
640
- return new VesantError(message, "BAD_REQUEST", 400);
641
+ return new VesantError(message, "BAD_REQUEST", 400, structured);
641
642
  case 401:
642
643
  return new AuthenticationError(message);
643
644
  case 403:
644
- return new VesantError(message, "FORBIDDEN", 403);
645
+ return new VesantError(message, "FORBIDDEN", 403, structured);
645
646
  case 404:
646
- return new VesantError(message, "NOT_FOUND", 404);
647
+ return new VesantError(message, "NOT_FOUND", 404, structured);
647
648
  case 409:
648
- return new VesantError(message, "DUPLICATE_PROFILE", 409);
649
+ return new VesantError(message, "DUPLICATE_PROFILE", 409, structured);
649
650
  case 429: {
650
651
  const retryAfter = data.retry_after || data.retryAfter;
651
652
  return new RateLimitError(retryAfter);
@@ -656,7 +657,7 @@ var BaseClient = class {
656
657
  case 504:
657
658
  return new ServiceUnavailableError(message);
658
659
  default:
659
- return new VesantError(message, "UNKNOWN_ERROR", status);
660
+ return new VesantError(message, "UNKNOWN_ERROR", status, structured);
660
661
  }
661
662
  };
662
663
  const error = createError();
@@ -1104,6 +1105,7 @@ function isCipherTextExpired(cipherText) {
1104
1105
  }
1105
1106
 
1106
1107
  // src/geolocation/client.ts
1108
+ var DEFAULT_GPS_CONFIG_TTL_MS = 5 * 60 * 1e3;
1107
1109
  var GeolocationClient = class extends BaseClient {
1108
1110
  constructor(config) {
1109
1111
  const baseConfig = {
@@ -1119,6 +1121,8 @@ var GeolocationClient = class extends BaseClient {
1119
1121
  environment: config.environment
1120
1122
  };
1121
1123
  super(baseConfig);
1124
+ this.gpsConfigCache = null;
1125
+ this.gpsConfigTtlMs = config.gpsConfigTtlMs ?? DEFAULT_GPS_CONFIG_TTL_MS;
1122
1126
  }
1123
1127
  // ============================================================================
1124
1128
  // IP Verification & Compliance
@@ -1204,7 +1208,42 @@ var GeolocationClient = class extends BaseClient {
1204
1208
  * ```
1205
1209
  */
1206
1210
  async getGPSConfig(requestOptions) {
1207
- return this.requestWithRetry("/api/v1/geo/config", void 0, void 0, void 0, requestOptions);
1211
+ const cached = this.gpsConfigCache;
1212
+ if (cached && cached.expiresAt > Date.now()) {
1213
+ return cached.value;
1214
+ }
1215
+ return this.refreshGPSConfig(requestOptions);
1216
+ }
1217
+ /**
1218
+ * Re-read the tenant's GPS requirement configuration, ignoring any copy held
1219
+ * from an earlier read.
1220
+ *
1221
+ * These requirements are edited in the compliance console while your
1222
+ * application is running. `getGPSConfig` reuses a fetched copy for a short
1223
+ * period so a long-lived session does not call the API on every event; call
1224
+ * this when you need a change to take effect immediately — for example right
1225
+ * after an administrator saves new settings.
1226
+ *
1227
+ * @returns The current GPS requirement config per event type
1228
+ *
1229
+ * @example
1230
+ * ```typescript
1231
+ * const config = await client.refreshGPSConfig();
1232
+ * if (config.require_gps.login) {
1233
+ * // GPS is now required for login
1234
+ * }
1235
+ * ```
1236
+ */
1237
+ async refreshGPSConfig(requestOptions) {
1238
+ const value = await this.requestWithRetry(
1239
+ "/api/v1/geo/config",
1240
+ void 0,
1241
+ void 0,
1242
+ void 0,
1243
+ requestOptions
1244
+ );
1245
+ this.gpsConfigCache = { value, expiresAt: Date.now() + this.gpsConfigTtlMs };
1246
+ return value;
1208
1247
  }
1209
1248
  /**
1210
1249
  * Mint a short-lived, single-use device-signals nonce.
@@ -1621,17 +1660,27 @@ var RiskProfileClient = class extends BaseClient {
1621
1660
  /**
1622
1661
  * Update customer profile
1623
1662
  *
1663
+ * Omitted fields keep their stored values. When the tenant has the
1664
+ * **On Account Sensitive Action** KYC trigger enabled and the update changes
1665
+ * the customer's name, date of birth or residential address, Vesant applies
1666
+ * the other fields, holds the sensitive ones and answers `202` with a
1667
+ * {@link ProfileUpdateHeldResponse} instead of the profile. Narrow with
1668
+ * {@link isProfileUpdateHeld}, then request a `profile_change` submit link.
1669
+ *
1624
1670
  * @param profileId - Profile UUID
1625
1671
  * @param updates - Fields to update
1626
- * @returns Updated customer profile
1672
+ * @returns Updated customer profile, or the held change
1627
1673
  *
1628
1674
  * @example
1629
1675
  * ```typescript
1630
- * const updated = await client.updateProfile(profileId, {
1676
+ * const result = await client.updateProfile(profileId, {
1631
1677
  * location: 'New York, USA',
1632
1678
  * location_compliance: 'compliant',
1633
1679
  * last_recorded_activity: new Date().toISOString()
1634
1680
  * });
1681
+ * if (isProfileUpdateHeld(result)) {
1682
+ * // name / DOB / address held: start KYC with trigger_event 'profile_change'
1683
+ * }
1635
1684
  * ```
1636
1685
  */
1637
1686
  async updateProfile(profileId, updates, requestOptions) {
@@ -1671,6 +1720,11 @@ var RiskProfileClient = class extends BaseClient {
1671
1720
  }
1672
1721
  };
1673
1722
 
1723
+ // src/risk-profile/types.ts
1724
+ function isProfileUpdateHeld(result) {
1725
+ return typeof result === "object" && result !== null && result.status === "kyc_required" && result.kyc_required === true;
1726
+ }
1727
+
1674
1728
  // src/compliance/block-reasons.ts
1675
1729
  var sdkReasons = {
1676
1730
  // Jurisdiction
@@ -2201,11 +2255,12 @@ var ComplianceClient = class {
2201
2255
  if (profileResult) {
2202
2256
  profile = profileResult;
2203
2257
  if (!isBlocked && this.shouldUpdateProfile(profile, geoVerification.location.city)) {
2204
- profile = await this.riskClient.updateProfile(profile.id, {
2258
+ const updated = await this.riskClient.updateProfile(profile.id, {
2205
2259
  last_recorded_activity: (/* @__PURE__ */ new Date()).toISOString(),
2206
2260
  location: `${geoVerification.location.city}, ${geoVerification.location.country}`,
2207
2261
  location_compliance: geoVerification.is_compliant ? "compliant" : "non-compliant"
2208
2262
  }, requestOptions);
2263
+ profile = isProfileUpdateHeld(updated) ? updated.profile : updated;
2209
2264
  }
2210
2265
  } else {
2211
2266
  if (this.config.autoCreateProfiles && this.config.debug) {
@@ -3151,77 +3206,24 @@ var KycClient = class extends BaseClient {
3151
3206
  }, void 0, requestOptions);
3152
3207
  }
3153
3208
  /**
3154
- * Get a KYC request by ID
3209
+ * Get a KYC record by ID
3155
3210
  *
3156
- * @param id - KYC request ID
3157
- * @returns KYC request details including proofs and alerts
3211
+ * Works with your tenant API key. Each entry in `proofs` carries a
3212
+ * short-lived `link` for downloading that document, and `reference` holds
3213
+ * your own customer reference (the `forward_reference`).
3214
+ *
3215
+ * @param id - KYC record ID (the `kyc_id` returned by `requestKycSubmitLink`)
3216
+ * @returns KYC record including proofs (with download links) and alerts
3158
3217
  *
3159
3218
  * @example
3160
3219
  * ```typescript
3161
3220
  * const kyc = await client.getKycRequest("550e8400-e29b-41d4-a716-446655440000");
3162
3221
  * console.log(`Status: ${kyc.status}, ID Verified: ${kyc.id_verified}`);
3222
+ * kyc.proofs?.forEach(proof => console.log(`${proof.type}: ${proof.link}`));
3163
3223
  * ```
3164
3224
  */
3165
3225
  async getKycRequest(id) {
3166
- return this.request(`/api/v1/kyc/requests/${id}`);
3167
- }
3168
- /**
3169
- * List KYC requests with filters and pagination
3170
- *
3171
- * @param filters - Optional filters (status, search, date range)
3172
- * @param pagination - Optional pagination (page, page_size)
3173
- * @returns Paginated list of KYC requests
3174
- *
3175
- * @example
3176
- * ```typescript
3177
- * const requests = await client.listKycRequests(
3178
- * { status: "pending", search: "john" },
3179
- * { page: 1, page_size: 20 }
3180
- * );
3181
- * console.log(`Found ${requests.total} pending requests`);
3182
- * ```
3183
- */
3184
- async listKycRequests(filters, pagination) {
3185
- const params = {};
3186
- if (filters) {
3187
- addFilterParam(params, "status", filters.status);
3188
- addSimpleParams(params, filters, ["search", "fromDate", "toDate", "sortBy", "order"]);
3189
- }
3190
- if (pagination) {
3191
- if (pagination.page) params.page = pagination.page;
3192
- if (pagination.page_size) params.limit = pagination.page_size;
3193
- }
3194
- return this.request(
3195
- `/api/v1/kyc/requests${this.buildQueryString(params)}`,
3196
- { headers: this.getUserHeaders() }
3197
- );
3198
- }
3199
- /**
3200
- * Update KYC request status (accept/decline)
3201
- *
3202
- * @param request - Status update request with reference, status, and reason
3203
- *
3204
- * @example
3205
- * ```typescript
3206
- * // Accept a KYC request
3207
- * await client.updateKycStatus({
3208
- * reference: "kyc-ref-123",
3209
- * status: "accepted",
3210
- * reason: "All documents verified successfully"
3211
- * });
3212
- *
3213
- * // Decline a KYC request
3214
- * await client.updateKycStatus({
3215
- * reference: "kyc-ref-456",
3216
- * status: "declined",
3217
- * reason: "Document expired"
3218
- * });
3219
- * ```
3220
- */
3221
- async updateKycStatus(request) {
3222
- await this.request("/api/v1/kyc/status", {
3223
- method: "PUT",
3224
- body: JSON.stringify(request),
3226
+ return this.request(`/api/v1/kyc/${encodeURIComponent(id)}`, {
3225
3227
  headers: this.getUserHeaders()
3226
3228
  });
3227
3229
  }
@@ -3253,63 +3255,28 @@ var KycClient = class extends BaseClient {
3253
3255
  /**
3254
3256
  * Get downloadable URLs for KYC proofs/documents
3255
3257
  *
3256
- * @param kycId - KYC request ID
3257
- * @returns Array of proof download URLs with expiration
3258
+ * Derived from the `proofs` of `getKycRequest`: the platform attaches a
3259
+ * short-lived download link to every proof on the KYC record, so no
3260
+ * separate endpoint is needed. Proofs without a link are omitted.
3261
+ *
3262
+ * @param kycId - KYC record ID
3263
+ * @returns Array of proof download URLs
3258
3264
  *
3259
3265
  * @example
3260
3266
  * ```typescript
3261
3267
  * const proofs = await client.getProofDownloadURLs("550e8400-e29b-41d4-a716-446655440000");
3262
3268
  * proofs.forEach(proof => {
3263
- * console.log(`${proof.type}: ${proof.url} (expires: ${proof.expires_at})`);
3269
+ * console.log(`${proof.type}: ${proof.url}`);
3264
3270
  * });
3265
3271
  * ```
3266
3272
  */
3267
3273
  async getProofDownloadURLs(kycId) {
3268
- return this.request(
3269
- `/api/v1/kyc/proofs/${kycId}`,
3270
- { headers: this.getUserHeaders() }
3271
- );
3272
- }
3273
- // ============================================================================
3274
- // KYC Overview & Statistics
3275
- // ============================================================================
3276
- /**
3277
- * Get KYC overview statistics
3278
- *
3279
- * @param fromDate - Optional start date (ISO 8601)
3280
- * @param toDate - Optional end date (ISO 8601)
3281
- * @returns KYC statistics including counts by status
3282
- *
3283
- * @example
3284
- * ```typescript
3285
- * const overview = await client.getOverview(
3286
- * "2024-01-01T00:00:00Z",
3287
- * "2024-12-31T23:59:59Z"
3288
- * );
3289
- * console.log(`Total: ${overview.total}, Pending: ${overview.pending}`);
3290
- * console.log(`Approved: ${overview.approved}, Rejected: ${overview.rejected}`);
3291
- * ```
3292
- */
3293
- async getOverview(fromDate, toDate) {
3294
- const params = {};
3295
- if (fromDate) params.fromDate = fromDate;
3296
- if (toDate) params.toDate = toDate;
3297
- return this.request(
3298
- `/api/v1/kyc/overview${this.buildQueryString(params)}`
3299
- );
3274
+ const kyc = await this.getKycRequest(kycId);
3275
+ return (kyc.proofs ?? []).filter((proof) => typeof proof.link === "string" && proof.link !== "").map((proof) => ({ id: proof.id, type: proof.type, url: proof.link }));
3300
3276
  }
3301
3277
  // ============================================================================
3302
3278
  // Alert Management
3303
3279
  // ============================================================================
3304
- /**
3305
- * Get a KYC alert by ID
3306
- *
3307
- * @param alertId - Alert ID
3308
- * @returns Alert details
3309
- */
3310
- async getAlert(alertId) {
3311
- return this.request(`/api/v1/kyc/alerts/${alertId}`);
3312
- }
3313
3280
  /**
3314
3281
  * List KYC alerts with filters and pagination
3315
3282
  *
@@ -3329,6 +3296,10 @@ var KycClient = class extends BaseClient {
3329
3296
  * );
3330
3297
  * console.log(`Found ${alerts.total} alerts`);
3331
3298
  * ```
3299
+ *
3300
+ * @remarks Console session only. This endpoint accepts a Vesant console
3301
+ * (dashboard login) token, not a tenant API key; called with an API key it
3302
+ * fails with `AuthenticationError` or a permission error.
3332
3303
  */
3333
3304
  async listAlerts(filters, pagination) {
3334
3305
  const params = {};
@@ -3348,66 +3319,15 @@ var KycClient = class extends BaseClient {
3348
3319
  `/api/v1/kyc/alerts${this.buildQueryString(params)}`
3349
3320
  );
3350
3321
  }
3351
- /**
3352
- * Update a KYC alert
3353
- *
3354
- * @param alertId - Alert ID
3355
- * @param update - Fields to update (status, assigned_for, reason, alert_type)
3356
- *
3357
- * @example
3358
- * ```typescript
3359
- * // Assign an alert
3360
- * await client.updateAlert("alert_123", {
3361
- * assigned_for: "analyst_user_id",
3362
- * status: "in_progress"
3363
- * });
3364
- *
3365
- * // Resolve an alert
3366
- * await client.updateAlert("alert_123", {
3367
- * status: "resolved",
3368
- * reason: "Customer verified via phone call"
3369
- * });
3370
- *
3371
- * // Escalate an alert
3372
- * await client.updateAlert("alert_123", {
3373
- * status: "escalated",
3374
- * assigned_for: "manager_user_id",
3375
- * reason: "Requires senior review - suspicious documents"
3376
- * });
3377
- * ```
3378
- */
3379
- async updateAlert(alertId, update) {
3380
- await this.request(`/api/v1/kyc/alerts/${alertId}`, {
3381
- method: "PUT",
3382
- body: JSON.stringify(update),
3383
- headers: this.getUserHeaders()
3384
- });
3385
- }
3386
3322
  // ============================================================================
3387
3323
  // KYC Preferences
3388
3324
  // ============================================================================
3389
- /**
3390
- * Get KYC preferences for the tenant
3391
- *
3392
- * @returns KYC preferences configuration
3393
- *
3394
- * @example
3395
- * ```typescript
3396
- * const prefs = await client.getPreferences();
3397
- * console.log(`Face verification required: ${prefs.is_face_verification_required}`);
3398
- * console.log(`Required documents: ${prefs.required_document_count}`);
3399
- * ```
3400
- */
3401
- async getPreferences() {
3402
- return this.request("/api/v1/kyc/preferences");
3403
- }
3404
3325
  /**
3405
3326
  * Update KYC preferences for the tenant
3406
3327
  *
3407
3328
  * @deprecated KYC preferences are managed in the Vesant console; the
3408
3329
  * platform exposes no update operation to the SDK, so this call always
3409
- * fails. Use `getPreferences()` to read them. This method will be removed
3410
- * in a future release.
3330
+ * fails. This method will be removed in a future release.
3411
3331
  *
3412
3332
  * @param update - Fields to update
3413
3333
  * @returns Updated preferences
@@ -3570,6 +3490,12 @@ var KYC_DECLINED_DESCRIPTIONS = {
3570
3490
  function isKycDocumentExpiredCallbackEvent(value) {
3571
3491
  return typeof value === "object" && value !== null && value.event === "kyc_document_expired";
3572
3492
  }
3493
+ function isKycStatusCallbackEvent(value) {
3494
+ return typeof value === "object" && value !== null && value.event === "kyc";
3495
+ }
3496
+ function isProfileChangeCallbackEvent(value) {
3497
+ return typeof value === "object" && value !== null && value.event === "profile_change";
3498
+ }
3573
3499
 
3574
3500
  // src/tax/client.ts
3575
3501
  var TaxClient = class extends BaseClient {
@@ -3859,6 +3785,11 @@ function buildHandler(options) {
3859
3785
  return handler;
3860
3786
  }
3861
3787
 
3788
+ // src/webhooks/types.ts
3789
+ function isAmlBlockCallbackEvent(value) {
3790
+ return typeof value === "object" && value !== null && value.event === "aml" && value.block === true;
3791
+ }
3792
+
3862
3793
  exports.AuthenticationError = AuthenticationError;
3863
3794
  exports.BaseClient = BaseClient;
3864
3795
  exports.CGSError = CGSError;
@@ -3894,8 +3825,12 @@ exports.createWebhookMiddleware = createWebhookMiddleware;
3894
3825
  exports.decodeCipherText = decodeCipherText;
3895
3826
  exports.generateCipherText = generateCipherText;
3896
3827
  exports.gpsIntegrityInputFromPosition = gpsIntegrityInputFromPosition;
3828
+ exports.isAmlBlockCallbackEvent = isAmlBlockCallbackEvent;
3897
3829
  exports.isCipherTextExpired = isCipherTextExpired;
3898
3830
  exports.isKycDocumentExpiredCallbackEvent = isKycDocumentExpiredCallbackEvent;
3831
+ exports.isKycStatusCallbackEvent = isKycStatusCallbackEvent;
3832
+ exports.isProfileChangeCallbackEvent = isProfileChangeCallbackEvent;
3833
+ exports.isProfileUpdateHeld = isProfileUpdateHeld;
3899
3834
  exports.noopLogger = noopLogger;
3900
3835
  exports.paginate = paginate;
3901
3836
  exports.probeGeolocationPermission = probeGeolocationPermission;