vesant-sdk 1.6.6 → 2.0.0-dev.40d1c39

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 (86) hide show
  1. package/README.md +14 -4
  2. package/dist/client-BJ87_Vv5.d.ts +430 -0
  3. package/dist/{client-ePzhQKp9.d.mts → client-BolQlL5e.d.mts} +1 -1
  4. package/dist/{client-ePzhQKp9.d.ts → client-BolQlL5e.d.ts} +1 -1
  5. package/dist/{client-BlCxjbY2.d.mts → client-Bvp-f05-.d.ts} +7 -7
  6. package/dist/{client-C_A7QLcB.d.ts → client-CIEa7xYG.d.mts} +7 -7
  7. package/dist/client-IAOGCBfm.d.mts +430 -0
  8. package/dist/compliance/index.d.mts +25 -429
  9. package/dist/compliance/index.d.ts +25 -429
  10. package/dist/compliance/index.js +137 -58
  11. package/dist/compliance/index.js.map +1 -1
  12. package/dist/compliance/index.mjs +137 -59
  13. package/dist/compliance/index.mjs.map +1 -1
  14. package/dist/decisions/index.d.mts +2 -2
  15. package/dist/decisions/index.d.ts +2 -2
  16. package/dist/decisions/index.js +1 -1
  17. package/dist/decisions/index.js.map +1 -1
  18. package/dist/decisions/index.mjs +1 -1
  19. package/dist/decisions/index.mjs.map +1 -1
  20. package/dist/geolocation/index.d.mts +4 -4
  21. package/dist/geolocation/index.d.ts +4 -4
  22. package/dist/geolocation/index.js +6 -24
  23. package/dist/geolocation/index.js.map +1 -1
  24. package/dist/geolocation/index.mjs +6 -24
  25. package/dist/geolocation/index.mjs.map +1 -1
  26. package/dist/index.d.mts +14 -71
  27. package/dist/index.d.ts +14 -71
  28. package/dist/index.js +190 -237
  29. package/dist/index.js.map +1 -1
  30. package/dist/index.mjs +189 -236
  31. package/dist/index.mjs.map +1 -1
  32. package/dist/kyc/core.d.mts +4 -4
  33. package/dist/kyc/core.d.ts +4 -4
  34. package/dist/kyc/core.js +24 -13
  35. package/dist/kyc/core.js.map +1 -1
  36. package/dist/kyc/core.mjs +24 -14
  37. package/dist/kyc/core.mjs.map +1 -1
  38. package/dist/kyc/index.d.mts +20 -27
  39. package/dist/kyc/index.d.ts +20 -27
  40. package/dist/kyc/index.js +24 -13
  41. package/dist/kyc/index.js.map +1 -1
  42. package/dist/kyc/index.mjs +24 -14
  43. package/dist/kyc/index.mjs.map +1 -1
  44. package/dist/react.d.mts +6 -6
  45. package/dist/react.d.ts +6 -6
  46. package/dist/react.js +18 -5
  47. package/dist/react.js.map +1 -1
  48. package/dist/react.mjs +18 -5
  49. package/dist/react.mjs.map +1 -1
  50. package/dist/risk-profile/index.d.mts +4 -4
  51. package/dist/risk-profile/index.d.ts +4 -4
  52. package/dist/risk-profile/index.js +1 -1
  53. package/dist/risk-profile/index.js.map +1 -1
  54. package/dist/risk-profile/index.mjs +1 -1
  55. package/dist/risk-profile/index.mjs.map +1 -1
  56. package/dist/scores/index.d.mts +2 -2
  57. package/dist/scores/index.d.ts +2 -2
  58. package/dist/scores/index.js +1 -1
  59. package/dist/scores/index.js.map +1 -1
  60. package/dist/scores/index.mjs +1 -1
  61. package/dist/scores/index.mjs.map +1 -1
  62. package/dist/tax/index.d.mts +6 -41
  63. package/dist/tax/index.d.ts +6 -41
  64. package/dist/tax/index.js +1 -36
  65. package/dist/tax/index.js.map +1 -1
  66. package/dist/tax/index.mjs +1 -36
  67. package/dist/tax/index.mjs.map +1 -1
  68. package/dist/{types-X5Md_dD_.d.ts → types-2utj53GK.d.ts} +2 -2
  69. package/dist/{types-1RzYeSal.d.mts → types-C4Zx0d_u.d.mts} +2 -2
  70. package/dist/{types-B4Ezqo7V.d.mts → types-QUCWam16.d.mts} +7 -1
  71. package/dist/{types-B4Ezqo7V.d.ts → types-QUCWam16.d.ts} +7 -1
  72. package/dist/webhooks/index.d.mts +181 -2
  73. package/dist/webhooks/index.d.ts +181 -2
  74. package/dist/webhooks/index.js +49 -7
  75. package/dist/webhooks/index.js.map +1 -1
  76. package/dist/webhooks/index.mjs +49 -7
  77. package/dist/webhooks/index.mjs.map +1 -1
  78. package/package.json +16 -13
  79. package/dist/fraud/index.d.mts +0 -80
  80. package/dist/fraud/index.d.ts +0 -80
  81. package/dist/fraud/index.js +0 -606
  82. package/dist/fraud/index.js.map +0 -1
  83. package/dist/fraud/index.mjs +0 -604
  84. package/dist/fraud/index.mjs.map +0 -1
  85. package/dist/index-B04H4xfJ.d.mts +0 -320
  86. package/dist/index-CItMPmLL.d.ts +0 -320
@@ -1,5 +1,80 @@
1
1
  'use strict';
2
2
 
3
+ // src/compliance/block-reasons.ts
4
+ var sdkReasons = {
5
+ // Jurisdiction
6
+ jurisdictionBlocked: (country, countryISO) => ({
7
+ code: "JURISDICTION_BLOCKED",
8
+ message: "Access from a blocked jurisdiction",
9
+ metadata: { country, country_iso: countryISO }
10
+ }),
11
+ jurisdictionNonCompliant: () => ({
12
+ code: "JURISDICTION_NON_COMPLIANT",
13
+ message: "Location does not meet compliance requirements"
14
+ }),
15
+ jurisdictionRegistrationDenied: () => ({
16
+ code: "JURISDICTION_REGISTRATION_DENIED",
17
+ message: "Registration is not permitted in this jurisdiction"
18
+ }),
19
+ jurisdictionRestricted: () => ({
20
+ code: "JURISDICTION_RESTRICTED",
21
+ message: "Access from a restricted jurisdiction"
22
+ }),
23
+ // Risk
24
+ riskCriticalLevel: () => ({
25
+ code: "RISK_CRITICAL_LEVEL",
26
+ message: "Risk assessment reached critical threshold"
27
+ }),
28
+ accountSuspended: () => ({
29
+ code: "RISK_ACCOUNT_SUSPENDED",
30
+ message: "Customer account is suspended"
31
+ }),
32
+ sanctionsMatch: () => ({
33
+ code: "RISK_SANCTIONS_MATCH",
34
+ message: "Customer profile matched against sanctions list"
35
+ }),
36
+ riskHighLocation: () => ({
37
+ code: "RISK_HIGH_LOCATION",
38
+ message: "High-risk geographic location"
39
+ }),
40
+ riskHighCustomer: () => ({
41
+ code: "RISK_HIGH_CUSTOMER",
42
+ message: "Customer flagged as high risk"
43
+ }),
44
+ // Device
45
+ ciphertextInvalid: () => ({
46
+ code: "DEVICE_CIPHERTEXT_INVALID",
47
+ message: "Device verification payload failed validation"
48
+ }),
49
+ gpsIPMismatch: () => ({
50
+ code: "DEVICE_GPS_IP_MISMATCH",
51
+ message: "GPS location does not match IP-derived location"
52
+ }),
53
+ gpsRequired: () => ({
54
+ code: "DEVICE_GPS_REQUIRED",
55
+ message: "GPS verification is required but was not provided"
56
+ }),
57
+ // Transaction
58
+ transactionHighAmount: (amount, currency, threshold) => ({
59
+ code: "TRANSACTION_HIGH_AMOUNT",
60
+ message: "Transaction amount exceeds high-value threshold",
61
+ metadata: { amount, currency, threshold }
62
+ }),
63
+ transactionElevatedAmount: (amount, currency, threshold) => ({
64
+ code: "TRANSACTION_ELEVATED_AMOUNT",
65
+ message: "Transaction amount exceeds elevated-value threshold",
66
+ metadata: { amount, currency, threshold }
67
+ }),
68
+ transactionJurisdictionLimit: () => ({
69
+ code: "TRANSACTION_JURISDICTION_LIMIT",
70
+ message: "Transaction amount exceeds jurisdiction limit"
71
+ }),
72
+ anonymizationDetected: () => ({
73
+ code: "NETWORK_ANONYMIZER_DETECTED",
74
+ message: "Anonymization tool detected"
75
+ })
76
+ };
77
+
3
78
  // src/core/errors.ts
4
79
  var VesantError = class _VesantError extends Error {
5
80
  constructor(message, code, statusCode, details) {
@@ -224,7 +299,7 @@ function createConsoleLogger() {
224
299
  }
225
300
 
226
301
  // src/core/version.ts
227
- var SDK_VERSION = "1.6.6";
302
+ var SDK_VERSION = "2.0.0";
228
303
 
229
304
  // src/shared/browser-utils.ts
230
305
  function generateUUID() {
@@ -727,7 +802,7 @@ function encodePayload(payload) {
727
802
  } else if (typeof Buffer !== "undefined") {
728
803
  return Buffer.from(json, "utf-8").toString("base64");
729
804
  }
730
- throw new Error("No base64 encoding method available");
805
+ throw new VesantError("No base64 encoding method available", "BASE64_UNAVAILABLE");
731
806
  }
732
807
  async function generateCipherText(options, config) {
733
808
  const warnings = [];
@@ -752,8 +827,9 @@ async function generateCipherText(options, config) {
752
827
  if (location) {
753
828
  locationData = location;
754
829
  } else if (gpsRequiredByConfig) {
755
- throw new Error(
756
- `GPS location is required for ${options.reason} by tenant configuration, but GPS was not available or permission was denied`
830
+ throw new VesantError(
831
+ `GPS location is required for ${options.reason} by tenant configuration, but GPS was not available or permission was denied`,
832
+ "GPS_REQUIRED"
757
833
  );
758
834
  } else {
759
835
  warnings.push("GPS location not available or permission denied");
@@ -847,10 +923,9 @@ var GeolocationClient = class extends BaseClient {
847
923
  if (!request.ip_address?.trim()) {
848
924
  throw new ValidationError("ip_address is required and must be a non-empty string", ["ip_address"]);
849
925
  }
850
- const enrichedRequest = request.device_fingerprint ? request : { ...request, device_fingerprint: collectDeviceFingerprint() };
851
926
  return this.requestWithRetry("/api/v1/geo/verify", {
852
927
  method: "POST",
853
- body: JSON.stringify(enrichedRequest)
928
+ body: JSON.stringify(request)
854
929
  }, void 0, void 0, requestOptions);
855
930
  }
856
931
  /**
@@ -1254,24 +1329,6 @@ var GeolocationClient = class extends BaseClient {
1254
1329
  // Utility Methods (inherited from BaseClient: healthCheck, updateConfig, getConfig, buildQueryString)
1255
1330
  // ============================================================================
1256
1331
  };
1257
- function collectDeviceFingerprint() {
1258
- const deviceId = generateDeviceId();
1259
- const browserInfo = getBrowserInfo();
1260
- const userAgent = typeof navigator !== "undefined" ? navigator.userAgent : "server";
1261
- const platform = typeof navigator !== "undefined" ? navigator.platform || "unknown" : "server";
1262
- return {
1263
- device_id: deviceId,
1264
- user_agent: userAgent,
1265
- platform,
1266
- browser: browserInfo.browser,
1267
- browser_version: browserInfo.browser_version,
1268
- os: browserInfo.os,
1269
- os_version: browserInfo.os_version,
1270
- screen_resolution: typeof screen !== "undefined" ? `${screen.width}x${screen.height}` : void 0,
1271
- language: typeof navigator !== "undefined" ? navigator.language : void 0,
1272
- timezone: Intl?.DateTimeFormat?.()?.resolvedOptions?.()?.timeZone
1273
- };
1274
- }
1275
1332
 
1276
1333
  // src/risk-profile/client.ts
1277
1334
  var RiskProfileClient = class extends BaseClient {
@@ -1588,7 +1645,7 @@ var ComplianceClient = class {
1588
1645
  } catch (error) {
1589
1646
  if (this.config.debug) {
1590
1647
  this.logger.error("Registration verification failed", {
1591
- code: error instanceof Error ? error.code : void 0,
1648
+ code: error instanceof VesantError ? error.code : void 0,
1592
1649
  message: error instanceof Error ? error.message : "Unknown error"
1593
1650
  });
1594
1651
  }
@@ -1620,23 +1677,23 @@ var ComplianceClient = class {
1620
1677
  blockReasons.push(...geoVerification.risk_reasons ?? []);
1621
1678
  }
1622
1679
  if (!geoVerification.is_compliant) {
1623
- if (!blockReasons.includes("non_compliant_jurisdiction")) {
1624
- blockReasons.push("non_compliant_jurisdiction");
1680
+ if (!blockReasons.some((r) => r.code === "JURISDICTION_NON_COMPLIANT")) {
1681
+ blockReasons.push(sdkReasons.jurisdictionNonCompliant());
1625
1682
  }
1626
1683
  }
1627
1684
  const jurisdiction = geoVerification.jurisdiction;
1628
1685
  if (jurisdiction) {
1629
1686
  if (jurisdiction.allow_registration === false) {
1630
- blockReasons.push("registration_not_allowed_in_jurisdiction");
1687
+ blockReasons.push(sdkReasons.jurisdictionRegistrationDenied());
1631
1688
  }
1632
1689
  if (jurisdiction.status === "blocked" || jurisdiction.status === "sanctioned") {
1633
- if (!blockReasons.includes("blocked_jurisdiction")) {
1634
- blockReasons.push("blocked_jurisdiction");
1690
+ if (!blockReasons.some((r) => r.code === "JURISDICTION_BLOCKED")) {
1691
+ blockReasons.push(sdkReasons.jurisdictionBlocked(jurisdiction.country_name ?? "", jurisdiction.country_iso ?? ""));
1635
1692
  }
1636
1693
  }
1637
1694
  if (jurisdiction.status === "restricted" && jurisdiction.allow_registration === false) {
1638
- if (!blockReasons.includes("restricted_jurisdiction_no_registration")) {
1639
- blockReasons.push("restricted_jurisdiction_no_registration");
1695
+ if (!blockReasons.some((r) => r.code === "JURISDICTION_RESTRICTED")) {
1696
+ blockReasons.push(sdkReasons.jurisdictionRestricted());
1640
1697
  }
1641
1698
  }
1642
1699
  }
@@ -1644,25 +1701,30 @@ var ComplianceClient = class {
1644
1701
  blockReasons.push(...geoVerification.geofence_evaluation.reasons ?? []);
1645
1702
  }
1646
1703
  if (geoVerification.risk_level === "critical") {
1647
- if (!blockReasons.includes("critical_risk_level")) {
1648
- blockReasons.push("critical_risk_level");
1704
+ if (!blockReasons.some((r) => r.code === "RISK_CRITICAL_LEVEL")) {
1705
+ blockReasons.push(sdkReasons.riskCriticalLevel());
1649
1706
  }
1650
1707
  }
1651
1708
  if (cipherTextResult) {
1652
1709
  if (!cipherTextResult.valid) {
1653
- blockReasons.push("ciphertext_validation_failed");
1710
+ blockReasons.push(sdkReasons.ciphertextInvalid());
1654
1711
  }
1655
1712
  if (cipherTextResult.risk?.is_blocked) {
1656
1713
  blockReasons.push(...cipherTextResult.risk.block_reasons || []);
1657
1714
  }
1658
1715
  if (cipherTextResult.risk?.location_mismatch) {
1659
- blockReasons.push("gps_ip_location_mismatch");
1716
+ blockReasons.push(sdkReasons.gpsIPMismatch());
1660
1717
  }
1661
1718
  }
1662
1719
  if (geoVerification.gps_required && !cipherTextResult) {
1663
- blockReasons.push("gps_verification_required");
1720
+ blockReasons.push(sdkReasons.gpsRequired());
1664
1721
  }
1665
- return [...new Set(blockReasons)];
1722
+ const seen = /* @__PURE__ */ new Set();
1723
+ return blockReasons.filter((r) => {
1724
+ if (seen.has(r.code)) return false;
1725
+ seen.add(r.code);
1726
+ return true;
1727
+ });
1666
1728
  }
1667
1729
  /**
1668
1730
  * Validate registration request has all required fields
@@ -2046,7 +2108,7 @@ var ComplianceClient = class {
2046
2108
  const blockReasons = [...geoVerification.risk_reasons ?? []];
2047
2109
  if (cipherTextResult) {
2048
2110
  if (!cipherTextResult.valid) {
2049
- blockReasons.push("ciphertext_validation_failed");
2111
+ blockReasons.push(sdkReasons.ciphertextInvalid());
2050
2112
  }
2051
2113
  if (cipherTextResult.risk?.is_blocked) {
2052
2114
  blockReasons.push(...cipherTextResult.risk.block_reasons || []);
@@ -2054,12 +2116,18 @@ var ComplianceClient = class {
2054
2116
  }
2055
2117
  const gpsBlocked = geoVerification.gps_required && !cipherTextResult;
2056
2118
  if (gpsBlocked) {
2057
- blockReasons.push("gps_verification_required");
2119
+ blockReasons.push(sdkReasons.gpsRequired());
2058
2120
  }
2121
+ const seen = /* @__PURE__ */ new Set();
2122
+ const dedupedBlockReasons = blockReasons.filter((r) => {
2123
+ if (seen.has(r.code)) return false;
2124
+ seen.add(r.code);
2125
+ return true;
2126
+ });
2059
2127
  return {
2060
2128
  allowed: geoVerification.is_compliant && !geoVerification.is_blocked && !cipherTextBlocked && !gpsBlocked,
2061
2129
  geolocation: geoVerification,
2062
- blockReasons: [...new Set(blockReasons)],
2130
+ blockReasons: dedupedBlockReasons,
2063
2131
  processingTime: Date.now() - startTime,
2064
2132
  cipherTextValidation: cipherTextResult
2065
2133
  };
@@ -2162,31 +2230,31 @@ var ComplianceClient = class {
2162
2230
  const normalizedAmount = this.normalizeToUSD(amount, currency);
2163
2231
  if (normalizedAmount > 1e4) {
2164
2232
  riskScore += 30;
2165
- factors.push("high_transaction_amount");
2233
+ factors.push(sdkReasons.transactionHighAmount(normalizedAmount, currency, 1e4));
2166
2234
  } else if (normalizedAmount > 5e3) {
2167
2235
  riskScore += 15;
2168
- factors.push("elevated_transaction_amount");
2236
+ factors.push(sdkReasons.transactionElevatedAmount(normalizedAmount, currency, 5e3));
2169
2237
  }
2170
2238
  riskScore += geoVerification.risk_score * 0.4;
2171
2239
  if (geoVerification.risk_level === "high" || geoVerification.risk_level === "critical") {
2172
- factors.push("high_risk_location");
2240
+ factors.push(sdkReasons.riskHighLocation());
2173
2241
  }
2174
2242
  riskScore += profile.risk_score * 0.3;
2175
2243
  if (profile.risk_category === "high" || profile.risk_category === "critical") {
2176
- factors.push("high_risk_customer");
2244
+ factors.push(sdkReasons.riskHighCustomer());
2177
2245
  }
2178
2246
  if (geoVerification.location.is_vpn || geoVerification.location.is_proxy) {
2179
2247
  riskScore += 20;
2180
- factors.push("anonymization_detected");
2248
+ factors.push(sdkReasons.anonymizationDetected());
2181
2249
  }
2182
2250
  if (profile.customer_status === "suspended") {
2183
2251
  riskScore += 50;
2184
- factors.push("account_suspended");
2252
+ factors.push(sdkReasons.accountSuspended());
2185
2253
  }
2186
2254
  if (cipherTextResult) {
2187
2255
  if (cipherTextResult.risk?.location_mismatch) {
2188
2256
  riskScore += 20;
2189
- factors.push("gps_ip_location_mismatch");
2257
+ factors.push(sdkReasons.gpsIPMismatch());
2190
2258
  }
2191
2259
  if (cipherTextResult.risk?.score) {
2192
2260
  riskScore += cipherTextResult.risk.score * 0.2;
@@ -2224,48 +2292,58 @@ var ComplianceClient = class {
2224
2292
  }
2225
2293
  if (profile) {
2226
2294
  if (profile.customer_status === "suspended") {
2227
- reasons.push("account_suspended");
2295
+ reasons.push(sdkReasons.accountSuspended());
2228
2296
  }
2229
2297
  if (profile.has_sanctions) {
2230
- reasons.push("sanctions_match");
2298
+ reasons.push(sdkReasons.sanctionsMatch());
2231
2299
  }
2232
2300
  }
2233
2301
  if (cipherTextResult) {
2234
2302
  if (!cipherTextResult.valid) {
2235
- reasons.push("ciphertext_validation_failed");
2303
+ reasons.push(sdkReasons.ciphertextInvalid());
2236
2304
  }
2237
2305
  if (cipherTextResult.risk?.is_blocked) {
2238
2306
  reasons.push(...cipherTextResult.risk.block_reasons || []);
2239
2307
  }
2240
2308
  }
2241
2309
  if (geoVerification.gps_required && !cipherTextResult) {
2242
- reasons.push("gps_verification_required");
2310
+ reasons.push(sdkReasons.gpsRequired());
2243
2311
  }
2244
- return [...new Set(reasons)];
2312
+ const seen = /* @__PURE__ */ new Set();
2313
+ return reasons.filter((r) => {
2314
+ if (seen.has(r.code)) return false;
2315
+ seen.add(r.code);
2316
+ return true;
2317
+ });
2245
2318
  }
2246
2319
  getTransactionBlockReasons(geoVerification, transactionRisk, jurisdictionAllowed, cipherTextResult) {
2247
2320
  const reasons = [];
2248
2321
  if (!geoVerification.is_compliant) {
2249
- reasons.push("non_compliant_jurisdiction");
2322
+ reasons.push(sdkReasons.jurisdictionNonCompliant());
2250
2323
  }
2251
2324
  if (!jurisdictionAllowed) {
2252
- reasons.push("exceeds_jurisdiction_limit");
2325
+ reasons.push(sdkReasons.transactionJurisdictionLimit());
2253
2326
  }
2254
2327
  if (!transactionRisk.allowed) {
2255
2328
  reasons.push(...transactionRisk.factors);
2256
2329
  }
2257
2330
  if (cipherTextResult) {
2258
2331
  if (!cipherTextResult.valid) {
2259
- reasons.push("ciphertext_validation_failed");
2332
+ reasons.push(sdkReasons.ciphertextInvalid());
2260
2333
  }
2261
2334
  if (cipherTextResult.risk?.is_blocked) {
2262
2335
  reasons.push(...cipherTextResult.risk.block_reasons || []);
2263
2336
  }
2264
2337
  }
2265
2338
  if (geoVerification.gps_required && !cipherTextResult) {
2266
- reasons.push("gps_verification_required");
2339
+ reasons.push(sdkReasons.gpsRequired());
2267
2340
  }
2268
- return [...new Set(reasons)];
2341
+ const seen = /* @__PURE__ */ new Set();
2342
+ return reasons.filter((r) => {
2343
+ if (seen.has(r.code)) return false;
2344
+ seen.add(r.code);
2345
+ return true;
2346
+ });
2269
2347
  }
2270
2348
  // ============================================================================
2271
2349
  // Location Request Methods
@@ -2485,5 +2563,6 @@ var ComplianceClient = class {
2485
2563
 
2486
2564
  exports.ComplianceClient = ComplianceClient;
2487
2565
  exports.DEFAULT_CURRENCY_RATES = DEFAULT_CURRENCY_RATES;
2566
+ exports.sdkReasons = sdkReasons;
2488
2567
  //# sourceMappingURL=index.js.map
2489
2568
  //# sourceMappingURL=index.js.map