vesant-sdk 1.4.4 → 1.5.0

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 (65) hide show
  1. package/dist/{client-BlAt791q.d.ts → client-3cBb_Pp-.d.ts} +4 -4
  2. package/dist/{client-CY41e2Z_.d.mts → client-BQRONu8q.d.mts} +9 -5
  3. package/dist/{client-CY41e2Z_.d.ts → client-BQRONu8q.d.ts} +9 -5
  4. package/dist/{client-oo_3-0YW.d.mts → client-DKqyESgT.d.mts} +4 -4
  5. package/dist/compliance/index.d.mts +7 -7
  6. package/dist/compliance/index.d.ts +7 -7
  7. package/dist/compliance/index.js +55 -51
  8. package/dist/compliance/index.js.map +1 -1
  9. package/dist/compliance/index.mjs +55 -51
  10. package/dist/compliance/index.mjs.map +1 -1
  11. package/dist/decisions/index.d.mts +2 -2
  12. package/dist/decisions/index.d.ts +2 -2
  13. package/dist/decisions/index.js +41 -33
  14. package/dist/decisions/index.js.map +1 -1
  15. package/dist/decisions/index.mjs +41 -33
  16. package/dist/decisions/index.mjs.map +1 -1
  17. package/dist/geolocation/index.d.mts +4 -4
  18. package/dist/geolocation/index.d.ts +4 -4
  19. package/dist/geolocation/index.js +42 -34
  20. package/dist/geolocation/index.js.map +1 -1
  21. package/dist/geolocation/index.mjs +42 -34
  22. package/dist/geolocation/index.mjs.map +1 -1
  23. package/dist/index.d.mts +23 -19
  24. package/dist/index.d.ts +23 -19
  25. package/dist/index.js +58 -52
  26. package/dist/index.js.map +1 -1
  27. package/dist/index.mjs +58 -53
  28. package/dist/index.mjs.map +1 -1
  29. package/dist/kyc/core.d.mts +3 -3
  30. package/dist/kyc/core.d.ts +3 -3
  31. package/dist/kyc/core.js +41 -33
  32. package/dist/kyc/core.js.map +1 -1
  33. package/dist/kyc/core.mjs +41 -33
  34. package/dist/kyc/core.mjs.map +1 -1
  35. package/dist/kyc/index.d.mts +7 -7
  36. package/dist/kyc/index.d.ts +7 -7
  37. package/dist/kyc/index.js +41 -33
  38. package/dist/kyc/index.js.map +1 -1
  39. package/dist/kyc/index.mjs +41 -33
  40. package/dist/kyc/index.mjs.map +1 -1
  41. package/dist/react.d.mts +6 -6
  42. package/dist/react.d.ts +6 -6
  43. package/dist/react.js +5 -5
  44. package/dist/react.js.map +1 -1
  45. package/dist/react.mjs +5 -5
  46. package/dist/react.mjs.map +1 -1
  47. package/dist/risk-profile/index.d.mts +4 -4
  48. package/dist/risk-profile/index.d.ts +4 -4
  49. package/dist/risk-profile/index.js +44 -36
  50. package/dist/risk-profile/index.js.map +1 -1
  51. package/dist/risk-profile/index.mjs +44 -36
  52. package/dist/risk-profile/index.mjs.map +1 -1
  53. package/dist/scores/index.d.mts +2 -2
  54. package/dist/scores/index.d.ts +2 -2
  55. package/dist/scores/index.js +41 -33
  56. package/dist/scores/index.js.map +1 -1
  57. package/dist/scores/index.mjs +41 -33
  58. package/dist/scores/index.mjs.map +1 -1
  59. package/dist/{types-DZHongaK.d.mts → types-B1OzEQR3.d.mts} +1 -1
  60. package/dist/{types-DZHongaK.d.ts → types-B1OzEQR3.d.ts} +1 -1
  61. package/dist/{types-DLC7Sfy5.d.ts → types-BnL66DB3.d.ts} +2 -2
  62. package/dist/{types-jaLuzruy.d.mts → types-_hsTA3Ez.d.mts} +2 -2
  63. package/dist/webhooks/index.d.mts +1 -1
  64. package/dist/webhooks/index.d.ts +1 -1
  65. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -1,51 +1,52 @@
1
1
  // src/core/errors.ts
2
- var CGSError = class _CGSError extends Error {
2
+ var VesantError = class _VesantError extends Error {
3
3
  constructor(message, code, statusCode, details) {
4
4
  super(message);
5
5
  this.code = code;
6
6
  this.statusCode = statusCode;
7
7
  this.details = details;
8
- this.name = "CGSError";
9
- Object.setPrototypeOf(this, _CGSError.prototype);
8
+ this.name = "VesantError";
9
+ Object.setPrototypeOf(this, _VesantError.prototype);
10
10
  }
11
11
  };
12
- var NetworkError = class _NetworkError extends CGSError {
12
+ var CGSError = VesantError;
13
+ var NetworkError = class _NetworkError extends VesantError {
13
14
  constructor(message, originalError) {
14
- super(message, "NETWORK_ERROR", void 0, { originalError });
15
+ super(message, "NETWORK_ERROR");
15
16
  this.originalError = originalError;
16
17
  this.name = "NetworkError";
17
18
  Object.setPrototypeOf(this, _NetworkError.prototype);
18
19
  }
19
20
  };
20
- var ValidationError = class _ValidationError extends CGSError {
21
+ var ValidationError = class _ValidationError extends VesantError {
21
22
  constructor(message, fields) {
22
23
  super(message, "VALIDATION_ERROR", 400, { fields });
23
24
  this.name = "ValidationError";
24
25
  Object.setPrototypeOf(this, _ValidationError.prototype);
25
26
  }
26
27
  };
27
- var ServiceUnavailableError = class _ServiceUnavailableError extends CGSError {
28
- constructor(message) {
29
- super(`${message} is unavailable`, "SERVICE_UNAVAILABLE", 503, { service: message });
28
+ var ServiceUnavailableError = class _ServiceUnavailableError extends VesantError {
29
+ constructor(message = "Service unavailable") {
30
+ super(message, "SERVICE_UNAVAILABLE", 503);
30
31
  this.name = "ServiceUnavailableError";
31
32
  Object.setPrototypeOf(this, _ServiceUnavailableError.prototype);
32
33
  }
33
34
  };
34
- var ComplianceBlockedError = class _ComplianceBlockedError extends CGSError {
35
+ var ComplianceBlockedError = class _ComplianceBlockedError extends VesantError {
35
36
  constructor(reasons) {
36
37
  super("Access blocked due to compliance rules", "COMPLIANCE_BLOCKED", 403, { reasons });
37
38
  this.name = "ComplianceBlockedError";
38
39
  Object.setPrototypeOf(this, _ComplianceBlockedError.prototype);
39
40
  }
40
41
  };
41
- var AuthenticationError = class _AuthenticationError extends CGSError {
42
+ var AuthenticationError = class _AuthenticationError extends VesantError {
42
43
  constructor(message = "Authentication failed") {
43
44
  super(message, "AUTHENTICATION_ERROR", 401);
44
45
  this.name = "AuthenticationError";
45
46
  Object.setPrototypeOf(this, _AuthenticationError.prototype);
46
47
  }
47
48
  };
48
- var RateLimitError = class _RateLimitError extends CGSError {
49
+ var RateLimitError = class _RateLimitError extends VesantError {
49
50
  constructor(retryAfter) {
50
51
  super("Rate limit exceeded", "RATE_LIMIT_EXCEEDED", 429, { retryAfter });
51
52
  this.retryAfter = retryAfter;
@@ -53,7 +54,7 @@ var RateLimitError = class _RateLimitError extends CGSError {
53
54
  Object.setPrototypeOf(this, _RateLimitError.prototype);
54
55
  }
55
56
  };
56
- var TimeoutError = class _TimeoutError extends CGSError {
57
+ var TimeoutError = class _TimeoutError extends VesantError {
57
58
  constructor(timeout) {
58
59
  super(`Request timeout after ${timeout}ms`, "TIMEOUT", 408, { timeout });
59
60
  this.timeout = timeout;
@@ -61,15 +62,15 @@ var TimeoutError = class _TimeoutError extends CGSError {
61
62
  Object.setPrototypeOf(this, _TimeoutError.prototype);
62
63
  }
63
64
  };
64
- var ComplianceError = class _ComplianceError extends CGSError {
65
+ var ComplianceError = class _ComplianceError extends VesantError {
65
66
  constructor(message, originalError, code = "COMPLIANCE_ERROR") {
66
- super(message, code, void 0, { originalError });
67
+ super(message, code);
67
68
  this.originalError = originalError;
68
69
  this.name = "ComplianceError";
69
70
  Object.setPrototypeOf(this, _ComplianceError.prototype);
70
71
  }
71
72
  };
72
- var CircuitBreakerOpenError = class _CircuitBreakerOpenError extends CGSError {
73
+ var CircuitBreakerOpenError = class _CircuitBreakerOpenError extends VesantError {
73
74
  constructor() {
74
75
  super("Circuit breaker is open \u2014 requests are temporarily blocked", "CIRCUIT_BREAKER_OPEN", 503);
75
76
  this.name = "CircuitBreakerOpenError";
@@ -214,16 +215,16 @@ var RateLimitTracker = class {
214
215
  function createConsoleLogger() {
215
216
  return {
216
217
  debug(message, meta) {
217
- console.log(`[CGS SDK] ${message}`, meta !== void 0 ? meta : "");
218
+ console.log(`[Vesant SDK] ${message}`, meta !== void 0 ? meta : "");
218
219
  },
219
220
  info(message, meta) {
220
- console.info(`[CGS SDK] ${message}`, meta !== void 0 ? meta : "");
221
+ console.info(`[Vesant SDK] ${message}`, meta !== void 0 ? meta : "");
221
222
  },
222
223
  warn(message, meta) {
223
- console.warn(`[CGS SDK] ${message}`, meta !== void 0 ? meta : "");
224
+ console.warn(`[Vesant SDK] ${message}`, meta !== void 0 ? meta : "");
224
225
  },
225
226
  error(message, meta) {
226
- console.error(`[CGS SDK] ${message}`, meta !== void 0 ? meta : "");
227
+ console.error(`[Vesant SDK] ${message}`, meta !== void 0 ? meta : "");
227
228
  }
228
229
  };
229
230
  }
@@ -239,7 +240,7 @@ var noopLogger = {
239
240
  };
240
241
 
241
242
  // src/core/version.ts
242
- var SDK_VERSION = "1.4.4";
243
+ var SDK_VERSION = "1.5.0";
243
244
 
244
245
  // src/shared/browser-utils.ts
245
246
  function generateUUID() {
@@ -256,7 +257,7 @@ function generateDeviceId() {
256
257
  if (typeof window === "undefined" || typeof localStorage === "undefined") {
257
258
  return generateUUID();
258
259
  }
259
- const storageKey = "cgs_device_id";
260
+ const storageKey = "vesant_device_id";
260
261
  let deviceId = localStorage.getItem(storageKey);
261
262
  if (!deviceId) {
262
263
  deviceId = generateUUID();
@@ -323,9 +324,20 @@ var BaseClient = class {
323
324
  }
324
325
  this.interceptors = config.interceptors || [];
325
326
  this.logger = config.logger || createConsoleLogger();
327
+ let environment = config.environment;
328
+ const apiKey = config.apiKey || "";
329
+ if (apiKey.startsWith("pk_test_")) {
330
+ if (environment === "production") {
331
+ this.logger.warn('Sandbox API key (pk_test_*) used with environment: "production" \u2014 overriding to "sandbox"');
332
+ }
333
+ environment = "sandbox";
334
+ } else if (apiKey.startsWith("pk_live_") && environment === "sandbox") {
335
+ this.logger.warn('Production API key (pk_live_*) used with environment: "sandbox" \u2014 sandbox isolation will still be applied for backward compatibility');
336
+ }
326
337
  this.config = {
327
338
  ...config,
328
- apiKey: config.apiKey || "",
339
+ apiKey,
340
+ environment,
329
341
  headers: config.headers || {},
330
342
  timeout: config.timeout || 1e4,
331
343
  retries: config.retries || 3,
@@ -392,10 +404,7 @@ var BaseClient = class {
392
404
  }
393
405
  }
394
406
  if (this.config.debug) {
395
- this.logger.debug(`${finalOptions.method || "GET"} ${url}`, {
396
- headers: finalOptions.headers,
397
- body: finalOptions.body
398
- });
407
+ this.logger.debug(`${finalOptions.method || "GET"} ${endpoint}`);
399
408
  }
400
409
  const response = await fetch(url, {
401
410
  ...finalOptions,
@@ -429,17 +438,17 @@ var BaseClient = class {
429
438
  }
430
439
  }
431
440
  if (this.config.debug) {
432
- this.logger.debug("Response:", { data: result });
441
+ this.logger.debug(`Response: ${response.status}`);
433
442
  }
434
443
  return result;
435
444
  } catch (error) {
436
445
  clearTimeout(timeoutId);
437
- if (error instanceof CGSError && error.statusCode && error.statusCode >= 500) {
446
+ if (error instanceof VesantError && error.statusCode && error.statusCode >= 500) {
438
447
  this.circuitBreaker?.onFailure();
439
448
  } else if (error instanceof NetworkError || error instanceof TimeoutError) {
440
449
  this.circuitBreaker?.onFailure();
441
450
  }
442
- if (error instanceof CGSError && !error.requestId) {
451
+ if (error instanceof VesantError && !error.requestId) {
443
452
  error.requestId = requestId;
444
453
  }
445
454
  if (error instanceof Error) {
@@ -452,7 +461,7 @@ var BaseClient = class {
452
461
  if (error instanceof Error) {
453
462
  if (error.name === "AbortError") {
454
463
  if (requestOptions?.signal?.aborted) {
455
- const abortError = new CGSError("Request aborted", "REQUEST_ABORTED");
464
+ const abortError = new VesantError("Request aborted", "REQUEST_ABORTED");
456
465
  abortError.requestId = requestId;
457
466
  throw abortError;
458
467
  }
@@ -461,7 +470,7 @@ var BaseClient = class {
461
470
  timeoutError.requestId = requestId;
462
471
  throw timeoutError;
463
472
  }
464
- if (error instanceof CGSError) {
473
+ if (error instanceof VesantError) {
465
474
  throw error;
466
475
  }
467
476
  }
@@ -484,7 +493,7 @@ var BaseClient = class {
484
493
  if (requestOptions?.signal?.aborted) {
485
494
  throw lastError;
486
495
  }
487
- if (lastError instanceof CGSError && lastError.statusCode && lastError.statusCode >= 400 && lastError.statusCode < 500 && lastError.statusCode !== 429) {
496
+ if (lastError instanceof VesantError && lastError.statusCode && lastError.statusCode >= 400 && lastError.statusCode < 500 && lastError.statusCode !== 429) {
488
497
  throw lastError;
489
498
  }
490
499
  if (attempt === retries) {
@@ -512,13 +521,13 @@ var BaseClient = class {
512
521
  const createError = () => {
513
522
  switch (status) {
514
523
  case 400:
515
- return new CGSError(message, "BAD_REQUEST", 400, data);
524
+ return new VesantError(message, "BAD_REQUEST", 400);
516
525
  case 401:
517
526
  return new AuthenticationError(message);
518
527
  case 403:
519
- return new CGSError(message, "FORBIDDEN", 403, data);
528
+ return new VesantError(message, "FORBIDDEN", 403);
520
529
  case 404:
521
- return new CGSError(message, "NOT_FOUND", 404, data);
530
+ return new VesantError(message, "NOT_FOUND", 404);
522
531
  case 429: {
523
532
  const retryAfter = data.retry_after || data.retryAfter;
524
533
  return new RateLimitError(retryAfter);
@@ -529,7 +538,7 @@ var BaseClient = class {
529
538
  case 504:
530
539
  return new ServiceUnavailableError(message);
531
540
  default:
532
- return new CGSError(message, "UNKNOWN_ERROR", status, data);
541
+ return new VesantError(message, "UNKNOWN_ERROR", status);
533
542
  }
534
543
  };
535
544
  const error = createError();
@@ -1340,8 +1349,8 @@ var RiskProfileClient = class extends BaseClient {
1340
1349
  requestOptions
1341
1350
  );
1342
1351
  } catch (error) {
1343
- if (error instanceof CGSError && (error.statusCode === 404 || error.code === "NOT_FOUND")) {
1344
- throw new CGSError(`Profile not found for customer ID: ${customerId}`, "NOT_FOUND", 404);
1352
+ if (error instanceof VesantError && (error.statusCode === 404 || error.code === "NOT_FOUND")) {
1353
+ throw new VesantError("Profile not found", "NOT_FOUND", 404);
1345
1354
  }
1346
1355
  throw error;
1347
1356
  }
@@ -1391,7 +1400,7 @@ var RiskProfileClient = class extends BaseClient {
1391
1400
  try {
1392
1401
  return await this.getProfile(customerId, requestOptions);
1393
1402
  } catch (error) {
1394
- if (error instanceof CGSError && error.code === "NOT_FOUND") {
1403
+ if (error instanceof VesantError && error.code === "NOT_FOUND") {
1395
1404
  return await this.createProfile(createRequest, requestOptions);
1396
1405
  }
1397
1406
  throw error;
@@ -1558,8 +1567,6 @@ var ComplianceClient = class {
1558
1567
  if (this.config.debug) {
1559
1568
  this.logger.debug("Registration verification complete", {
1560
1569
  allowed: true,
1561
- riskScore: geoVerification.risk_score,
1562
- profileId: profile.id,
1563
1570
  requiresKYC,
1564
1571
  requiresEDD
1565
1572
  });
@@ -1575,16 +1582,14 @@ var ComplianceClient = class {
1575
1582
  };
1576
1583
  } catch (error) {
1577
1584
  if (this.config.debug) {
1578
- this.logger.error("Registration verification failed", { error });
1585
+ this.logger.error("Registration verification failed", {
1586
+ code: error instanceof Error ? error.code : void 0,
1587
+ message: error instanceof Error ? error.message : "Unknown error"
1588
+ });
1579
1589
  }
1580
1590
  throw new ComplianceError(
1581
1591
  "Registration verification failed",
1582
- {
1583
- stage: geoVerification ? "profile_creation" : "geo_verification",
1584
- geoRecordId: geoVerification?.record_id,
1585
- customerId: request.customerId,
1586
- cause: error
1587
- },
1592
+ error instanceof Error ? error.message : void 0,
1588
1593
  geoVerification ? "PROFILE_CREATION_FAILED" : "GEO_VERIFICATION_FAILED"
1589
1594
  );
1590
1595
  }
@@ -1801,7 +1806,7 @@ var ComplianceClient = class {
1801
1806
  processingTime: Date.now() - startTime
1802
1807
  };
1803
1808
  } catch (error) {
1804
- throw new ComplianceError("Login verification failed", error);
1809
+ throw new ComplianceError("Login verification failed", error instanceof Error ? error.message : void 0);
1805
1810
  }
1806
1811
  }
1807
1812
  /**
@@ -1880,7 +1885,7 @@ var ComplianceClient = class {
1880
1885
  processingTime: Date.now() - startTime
1881
1886
  };
1882
1887
  } catch (error) {
1883
- throw new ComplianceError("Transaction verification failed", error);
1888
+ throw new ComplianceError("Transaction verification failed", error instanceof Error ? error.message : void 0);
1884
1889
  }
1885
1890
  }
1886
1891
  /**
@@ -1926,7 +1931,7 @@ var ComplianceClient = class {
1926
1931
  async createProfileFromGeo(customerId, geoVerification, customerData) {
1927
1932
  if (!customerData?.email || !customerData?.fullName) {
1928
1933
  this.logger.warn(
1929
- `Creating profile for ${customerId} with incomplete data. Profiles should be created during registration with complete customer information.`
1934
+ "Creating profile with incomplete data. Profiles should be created during registration with complete customer information."
1930
1935
  );
1931
1936
  }
1932
1937
  return this.riskClient.createProfile({
@@ -3122,6 +3127,6 @@ function buildHandler(options) {
3122
3127
  return handler;
3123
3128
  }
3124
3129
 
3125
- export { AuthenticationError, BaseClient, CGSError, CircuitBreaker, CircuitBreakerOpenError, ComplianceBlockedError, ComplianceClient, ComplianceError, DEFAULT_CURRENCY_RATES, DecisionsClient, GeolocationClient, KycClient, NetworkError, RateLimitError, RateLimitTracker, RiskProfileClient, SDK_VERSION, ScoresClient, ServiceUnavailableError, TimeoutError, ValidationError, WebhookHandler, WorkflowClient, createConsoleLogger, createNextWebhookHandler, createWebhookMiddleware, decodeCipherText, generateCipherText, isCipherTextExpired, noopLogger, verifyWebhookSignature };
3130
+ export { AuthenticationError, BaseClient, CGSError, CircuitBreaker, CircuitBreakerOpenError, ComplianceBlockedError, ComplianceClient, ComplianceError, DEFAULT_CURRENCY_RATES, DecisionsClient, GeolocationClient, KycClient, NetworkError, RateLimitError, RateLimitTracker, RiskProfileClient, SDK_VERSION, ScoresClient, ServiceUnavailableError, TimeoutError, ValidationError, VesantError, WebhookHandler, WorkflowClient, createConsoleLogger, createNextWebhookHandler, createWebhookMiddleware, decodeCipherText, generateCipherText, isCipherTextExpired, noopLogger, verifyWebhookSignature };
3126
3131
  //# sourceMappingURL=index.mjs.map
3127
3132
  //# sourceMappingURL=index.mjs.map