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