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.
- package/dist/{client-BlAt791q.d.ts → client-3cBb_Pp-.d.ts} +4 -4
- package/dist/{client-CY41e2Z_.d.mts → client-BQRONu8q.d.mts} +9 -5
- package/dist/{client-CY41e2Z_.d.ts → client-BQRONu8q.d.ts} +9 -5
- package/dist/{client-oo_3-0YW.d.mts → client-DKqyESgT.d.mts} +4 -4
- package/dist/compliance/index.d.mts +7 -7
- package/dist/compliance/index.d.ts +7 -7
- package/dist/compliance/index.js +55 -51
- package/dist/compliance/index.js.map +1 -1
- package/dist/compliance/index.mjs +55 -51
- package/dist/compliance/index.mjs.map +1 -1
- package/dist/decisions/index.d.mts +2 -2
- package/dist/decisions/index.d.ts +2 -2
- package/dist/decisions/index.js +41 -33
- package/dist/decisions/index.js.map +1 -1
- package/dist/decisions/index.mjs +41 -33
- package/dist/decisions/index.mjs.map +1 -1
- package/dist/geolocation/index.d.mts +4 -4
- package/dist/geolocation/index.d.ts +4 -4
- package/dist/geolocation/index.js +42 -34
- package/dist/geolocation/index.js.map +1 -1
- package/dist/geolocation/index.mjs +42 -34
- package/dist/geolocation/index.mjs.map +1 -1
- package/dist/index.d.mts +23 -19
- package/dist/index.d.ts +23 -19
- package/dist/index.js +58 -52
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -53
- package/dist/index.mjs.map +1 -1
- package/dist/kyc/core.d.mts +3 -3
- package/dist/kyc/core.d.ts +3 -3
- package/dist/kyc/core.js +41 -33
- package/dist/kyc/core.js.map +1 -1
- package/dist/kyc/core.mjs +41 -33
- package/dist/kyc/core.mjs.map +1 -1
- package/dist/kyc/index.d.mts +7 -7
- package/dist/kyc/index.d.ts +7 -7
- package/dist/kyc/index.js +41 -33
- package/dist/kyc/index.js.map +1 -1
- package/dist/kyc/index.mjs +41 -33
- package/dist/kyc/index.mjs.map +1 -1
- package/dist/react.d.mts +6 -6
- package/dist/react.d.ts +6 -6
- package/dist/react.js +5 -5
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +5 -5
- package/dist/react.mjs.map +1 -1
- package/dist/risk-profile/index.d.mts +4 -4
- package/dist/risk-profile/index.d.ts +4 -4
- package/dist/risk-profile/index.js +44 -36
- package/dist/risk-profile/index.js.map +1 -1
- package/dist/risk-profile/index.mjs +44 -36
- package/dist/risk-profile/index.mjs.map +1 -1
- package/dist/scores/index.d.mts +2 -2
- package/dist/scores/index.d.ts +2 -2
- package/dist/scores/index.js +41 -33
- package/dist/scores/index.js.map +1 -1
- package/dist/scores/index.mjs +41 -33
- package/dist/scores/index.mjs.map +1 -1
- package/dist/{types-DZHongaK.d.mts → types-B1OzEQR3.d.mts} +1 -1
- package/dist/{types-DZHongaK.d.ts → types-B1OzEQR3.d.ts} +1 -1
- package/dist/{types-DLC7Sfy5.d.ts → types-BnL66DB3.d.ts} +2 -2
- package/dist/{types-jaLuzruy.d.mts → types-_hsTA3Ez.d.mts} +2 -2
- package/dist/webhooks/index.d.mts +1 -1
- package/dist/webhooks/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,44 +1,44 @@
|
|
|
1
1
|
// src/core/errors.ts
|
|
2
|
-
var
|
|
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 = "
|
|
9
|
-
Object.setPrototypeOf(this,
|
|
8
|
+
this.name = "VesantError";
|
|
9
|
+
Object.setPrototypeOf(this, _VesantError.prototype);
|
|
10
10
|
}
|
|
11
11
|
};
|
|
12
|
-
var NetworkError = class _NetworkError extends
|
|
12
|
+
var NetworkError = class _NetworkError extends VesantError {
|
|
13
13
|
constructor(message, originalError) {
|
|
14
|
-
super(message, "NETWORK_ERROR"
|
|
14
|
+
super(message, "NETWORK_ERROR");
|
|
15
15
|
this.originalError = originalError;
|
|
16
16
|
this.name = "NetworkError";
|
|
17
17
|
Object.setPrototypeOf(this, _NetworkError.prototype);
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
|
-
var ValidationError = class _ValidationError extends
|
|
20
|
+
var ValidationError = class _ValidationError extends VesantError {
|
|
21
21
|
constructor(message, fields) {
|
|
22
22
|
super(message, "VALIDATION_ERROR", 400, { fields });
|
|
23
23
|
this.name = "ValidationError";
|
|
24
24
|
Object.setPrototypeOf(this, _ValidationError.prototype);
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
|
-
var ServiceUnavailableError = class _ServiceUnavailableError extends
|
|
28
|
-
constructor(message) {
|
|
29
|
-
super(
|
|
27
|
+
var ServiceUnavailableError = class _ServiceUnavailableError extends VesantError {
|
|
28
|
+
constructor(message = "Service unavailable") {
|
|
29
|
+
super(message, "SERVICE_UNAVAILABLE", 503);
|
|
30
30
|
this.name = "ServiceUnavailableError";
|
|
31
31
|
Object.setPrototypeOf(this, _ServiceUnavailableError.prototype);
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
|
-
var AuthenticationError = class _AuthenticationError extends
|
|
34
|
+
var AuthenticationError = class _AuthenticationError extends VesantError {
|
|
35
35
|
constructor(message = "Authentication failed") {
|
|
36
36
|
super(message, "AUTHENTICATION_ERROR", 401);
|
|
37
37
|
this.name = "AuthenticationError";
|
|
38
38
|
Object.setPrototypeOf(this, _AuthenticationError.prototype);
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
|
-
var RateLimitError = class _RateLimitError extends
|
|
41
|
+
var RateLimitError = class _RateLimitError extends VesantError {
|
|
42
42
|
constructor(retryAfter) {
|
|
43
43
|
super("Rate limit exceeded", "RATE_LIMIT_EXCEEDED", 429, { retryAfter });
|
|
44
44
|
this.retryAfter = retryAfter;
|
|
@@ -46,7 +46,7 @@ var RateLimitError = class _RateLimitError extends CGSError {
|
|
|
46
46
|
Object.setPrototypeOf(this, _RateLimitError.prototype);
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
|
-
var TimeoutError = class _TimeoutError extends
|
|
49
|
+
var TimeoutError = class _TimeoutError extends VesantError {
|
|
50
50
|
constructor(timeout) {
|
|
51
51
|
super(`Request timeout after ${timeout}ms`, "TIMEOUT", 408, { timeout });
|
|
52
52
|
this.timeout = timeout;
|
|
@@ -54,15 +54,15 @@ var TimeoutError = class _TimeoutError extends CGSError {
|
|
|
54
54
|
Object.setPrototypeOf(this, _TimeoutError.prototype);
|
|
55
55
|
}
|
|
56
56
|
};
|
|
57
|
-
var ComplianceError = class _ComplianceError extends
|
|
57
|
+
var ComplianceError = class _ComplianceError extends VesantError {
|
|
58
58
|
constructor(message, originalError, code = "COMPLIANCE_ERROR") {
|
|
59
|
-
super(message, code
|
|
59
|
+
super(message, code);
|
|
60
60
|
this.originalError = originalError;
|
|
61
61
|
this.name = "ComplianceError";
|
|
62
62
|
Object.setPrototypeOf(this, _ComplianceError.prototype);
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
|
-
var CircuitBreakerOpenError = class _CircuitBreakerOpenError extends
|
|
65
|
+
var CircuitBreakerOpenError = class _CircuitBreakerOpenError extends VesantError {
|
|
66
66
|
constructor() {
|
|
67
67
|
super("Circuit breaker is open \u2014 requests are temporarily blocked", "CIRCUIT_BREAKER_OPEN", 503);
|
|
68
68
|
this.name = "CircuitBreakerOpenError";
|
|
@@ -207,22 +207,22 @@ var RateLimitTracker = class {
|
|
|
207
207
|
function createConsoleLogger() {
|
|
208
208
|
return {
|
|
209
209
|
debug(message, meta) {
|
|
210
|
-
console.log(`[
|
|
210
|
+
console.log(`[Vesant SDK] ${message}`, meta !== void 0 ? meta : "");
|
|
211
211
|
},
|
|
212
212
|
info(message, meta) {
|
|
213
|
-
console.info(`[
|
|
213
|
+
console.info(`[Vesant SDK] ${message}`, meta !== void 0 ? meta : "");
|
|
214
214
|
},
|
|
215
215
|
warn(message, meta) {
|
|
216
|
-
console.warn(`[
|
|
216
|
+
console.warn(`[Vesant SDK] ${message}`, meta !== void 0 ? meta : "");
|
|
217
217
|
},
|
|
218
218
|
error(message, meta) {
|
|
219
|
-
console.error(`[
|
|
219
|
+
console.error(`[Vesant SDK] ${message}`, meta !== void 0 ? meta : "");
|
|
220
220
|
}
|
|
221
221
|
};
|
|
222
222
|
}
|
|
223
223
|
|
|
224
224
|
// src/core/version.ts
|
|
225
|
-
var SDK_VERSION = "1.
|
|
225
|
+
var SDK_VERSION = "1.5.0";
|
|
226
226
|
|
|
227
227
|
// src/shared/browser-utils.ts
|
|
228
228
|
function generateUUID() {
|
|
@@ -239,7 +239,7 @@ function generateDeviceId() {
|
|
|
239
239
|
if (typeof window === "undefined" || typeof localStorage === "undefined") {
|
|
240
240
|
return generateUUID();
|
|
241
241
|
}
|
|
242
|
-
const storageKey = "
|
|
242
|
+
const storageKey = "vesant_device_id";
|
|
243
243
|
let deviceId = localStorage.getItem(storageKey);
|
|
244
244
|
if (!deviceId) {
|
|
245
245
|
deviceId = generateUUID();
|
|
@@ -306,9 +306,20 @@ var BaseClient = class {
|
|
|
306
306
|
}
|
|
307
307
|
this.interceptors = config.interceptors || [];
|
|
308
308
|
this.logger = config.logger || createConsoleLogger();
|
|
309
|
+
let environment = config.environment;
|
|
310
|
+
const apiKey = config.apiKey || "";
|
|
311
|
+
if (apiKey.startsWith("pk_test_")) {
|
|
312
|
+
if (environment === "production") {
|
|
313
|
+
this.logger.warn('Sandbox API key (pk_test_*) used with environment: "production" \u2014 overriding to "sandbox"');
|
|
314
|
+
}
|
|
315
|
+
environment = "sandbox";
|
|
316
|
+
} else if (apiKey.startsWith("pk_live_") && environment === "sandbox") {
|
|
317
|
+
this.logger.warn('Production API key (pk_live_*) used with environment: "sandbox" \u2014 sandbox isolation will still be applied for backward compatibility');
|
|
318
|
+
}
|
|
309
319
|
this.config = {
|
|
310
320
|
...config,
|
|
311
|
-
apiKey
|
|
321
|
+
apiKey,
|
|
322
|
+
environment,
|
|
312
323
|
headers: config.headers || {},
|
|
313
324
|
timeout: config.timeout || 1e4,
|
|
314
325
|
retries: config.retries || 3,
|
|
@@ -375,10 +386,7 @@ var BaseClient = class {
|
|
|
375
386
|
}
|
|
376
387
|
}
|
|
377
388
|
if (this.config.debug) {
|
|
378
|
-
this.logger.debug(`${finalOptions.method || "GET"} ${
|
|
379
|
-
headers: finalOptions.headers,
|
|
380
|
-
body: finalOptions.body
|
|
381
|
-
});
|
|
389
|
+
this.logger.debug(`${finalOptions.method || "GET"} ${endpoint}`);
|
|
382
390
|
}
|
|
383
391
|
const response = await fetch(url, {
|
|
384
392
|
...finalOptions,
|
|
@@ -412,17 +420,17 @@ var BaseClient = class {
|
|
|
412
420
|
}
|
|
413
421
|
}
|
|
414
422
|
if (this.config.debug) {
|
|
415
|
-
this.logger.debug(
|
|
423
|
+
this.logger.debug(`Response: ${response.status}`);
|
|
416
424
|
}
|
|
417
425
|
return result;
|
|
418
426
|
} catch (error) {
|
|
419
427
|
clearTimeout(timeoutId);
|
|
420
|
-
if (error instanceof
|
|
428
|
+
if (error instanceof VesantError && error.statusCode && error.statusCode >= 500) {
|
|
421
429
|
this.circuitBreaker?.onFailure();
|
|
422
430
|
} else if (error instanceof NetworkError || error instanceof TimeoutError) {
|
|
423
431
|
this.circuitBreaker?.onFailure();
|
|
424
432
|
}
|
|
425
|
-
if (error instanceof
|
|
433
|
+
if (error instanceof VesantError && !error.requestId) {
|
|
426
434
|
error.requestId = requestId;
|
|
427
435
|
}
|
|
428
436
|
if (error instanceof Error) {
|
|
@@ -435,7 +443,7 @@ var BaseClient = class {
|
|
|
435
443
|
if (error instanceof Error) {
|
|
436
444
|
if (error.name === "AbortError") {
|
|
437
445
|
if (requestOptions?.signal?.aborted) {
|
|
438
|
-
const abortError = new
|
|
446
|
+
const abortError = new VesantError("Request aborted", "REQUEST_ABORTED");
|
|
439
447
|
abortError.requestId = requestId;
|
|
440
448
|
throw abortError;
|
|
441
449
|
}
|
|
@@ -444,7 +452,7 @@ var BaseClient = class {
|
|
|
444
452
|
timeoutError.requestId = requestId;
|
|
445
453
|
throw timeoutError;
|
|
446
454
|
}
|
|
447
|
-
if (error instanceof
|
|
455
|
+
if (error instanceof VesantError) {
|
|
448
456
|
throw error;
|
|
449
457
|
}
|
|
450
458
|
}
|
|
@@ -467,7 +475,7 @@ var BaseClient = class {
|
|
|
467
475
|
if (requestOptions?.signal?.aborted) {
|
|
468
476
|
throw lastError;
|
|
469
477
|
}
|
|
470
|
-
if (lastError instanceof
|
|
478
|
+
if (lastError instanceof VesantError && lastError.statusCode && lastError.statusCode >= 400 && lastError.statusCode < 500 && lastError.statusCode !== 429) {
|
|
471
479
|
throw lastError;
|
|
472
480
|
}
|
|
473
481
|
if (attempt === retries) {
|
|
@@ -495,13 +503,13 @@ var BaseClient = class {
|
|
|
495
503
|
const createError = () => {
|
|
496
504
|
switch (status) {
|
|
497
505
|
case 400:
|
|
498
|
-
return new
|
|
506
|
+
return new VesantError(message, "BAD_REQUEST", 400);
|
|
499
507
|
case 401:
|
|
500
508
|
return new AuthenticationError(message);
|
|
501
509
|
case 403:
|
|
502
|
-
return new
|
|
510
|
+
return new VesantError(message, "FORBIDDEN", 403);
|
|
503
511
|
case 404:
|
|
504
|
-
return new
|
|
512
|
+
return new VesantError(message, "NOT_FOUND", 404);
|
|
505
513
|
case 429: {
|
|
506
514
|
const retryAfter = data.retry_after || data.retryAfter;
|
|
507
515
|
return new RateLimitError(retryAfter);
|
|
@@ -512,7 +520,7 @@ var BaseClient = class {
|
|
|
512
520
|
case 504:
|
|
513
521
|
return new ServiceUnavailableError(message);
|
|
514
522
|
default:
|
|
515
|
-
return new
|
|
523
|
+
return new VesantError(message, "UNKNOWN_ERROR", status);
|
|
516
524
|
}
|
|
517
525
|
};
|
|
518
526
|
const error = createError();
|
|
@@ -1256,8 +1264,8 @@ var RiskProfileClient = class extends BaseClient {
|
|
|
1256
1264
|
requestOptions
|
|
1257
1265
|
);
|
|
1258
1266
|
} catch (error) {
|
|
1259
|
-
if (error instanceof
|
|
1260
|
-
throw new
|
|
1267
|
+
if (error instanceof VesantError && (error.statusCode === 404 || error.code === "NOT_FOUND")) {
|
|
1268
|
+
throw new VesantError("Profile not found", "NOT_FOUND", 404);
|
|
1261
1269
|
}
|
|
1262
1270
|
throw error;
|
|
1263
1271
|
}
|
|
@@ -1307,7 +1315,7 @@ var RiskProfileClient = class extends BaseClient {
|
|
|
1307
1315
|
try {
|
|
1308
1316
|
return await this.getProfile(customerId, requestOptions);
|
|
1309
1317
|
} catch (error) {
|
|
1310
|
-
if (error instanceof
|
|
1318
|
+
if (error instanceof VesantError && error.code === "NOT_FOUND") {
|
|
1311
1319
|
return await this.createProfile(createRequest, requestOptions);
|
|
1312
1320
|
}
|
|
1313
1321
|
throw error;
|
|
@@ -1474,8 +1482,6 @@ var ComplianceClient = class {
|
|
|
1474
1482
|
if (this.config.debug) {
|
|
1475
1483
|
this.logger.debug("Registration verification complete", {
|
|
1476
1484
|
allowed: true,
|
|
1477
|
-
riskScore: geoVerification.risk_score,
|
|
1478
|
-
profileId: profile.id,
|
|
1479
1485
|
requiresKYC,
|
|
1480
1486
|
requiresEDD
|
|
1481
1487
|
});
|
|
@@ -1491,16 +1497,14 @@ var ComplianceClient = class {
|
|
|
1491
1497
|
};
|
|
1492
1498
|
} catch (error) {
|
|
1493
1499
|
if (this.config.debug) {
|
|
1494
|
-
this.logger.error("Registration verification failed", {
|
|
1500
|
+
this.logger.error("Registration verification failed", {
|
|
1501
|
+
code: error instanceof Error ? error.code : void 0,
|
|
1502
|
+
message: error instanceof Error ? error.message : "Unknown error"
|
|
1503
|
+
});
|
|
1495
1504
|
}
|
|
1496
1505
|
throw new ComplianceError(
|
|
1497
1506
|
"Registration verification failed",
|
|
1498
|
-
|
|
1499
|
-
stage: geoVerification ? "profile_creation" : "geo_verification",
|
|
1500
|
-
geoRecordId: geoVerification?.record_id,
|
|
1501
|
-
customerId: request.customerId,
|
|
1502
|
-
cause: error
|
|
1503
|
-
},
|
|
1507
|
+
error instanceof Error ? error.message : void 0,
|
|
1504
1508
|
geoVerification ? "PROFILE_CREATION_FAILED" : "GEO_VERIFICATION_FAILED"
|
|
1505
1509
|
);
|
|
1506
1510
|
}
|
|
@@ -1717,7 +1721,7 @@ var ComplianceClient = class {
|
|
|
1717
1721
|
processingTime: Date.now() - startTime
|
|
1718
1722
|
};
|
|
1719
1723
|
} catch (error) {
|
|
1720
|
-
throw new ComplianceError("Login verification failed", error);
|
|
1724
|
+
throw new ComplianceError("Login verification failed", error instanceof Error ? error.message : void 0);
|
|
1721
1725
|
}
|
|
1722
1726
|
}
|
|
1723
1727
|
/**
|
|
@@ -1796,7 +1800,7 @@ var ComplianceClient = class {
|
|
|
1796
1800
|
processingTime: Date.now() - startTime
|
|
1797
1801
|
};
|
|
1798
1802
|
} catch (error) {
|
|
1799
|
-
throw new ComplianceError("Transaction verification failed", error);
|
|
1803
|
+
throw new ComplianceError("Transaction verification failed", error instanceof Error ? error.message : void 0);
|
|
1800
1804
|
}
|
|
1801
1805
|
}
|
|
1802
1806
|
/**
|
|
@@ -1842,7 +1846,7 @@ var ComplianceClient = class {
|
|
|
1842
1846
|
async createProfileFromGeo(customerId, geoVerification, customerData) {
|
|
1843
1847
|
if (!customerData?.email || !customerData?.fullName) {
|
|
1844
1848
|
this.logger.warn(
|
|
1845
|
-
|
|
1849
|
+
"Creating profile with incomplete data. Profiles should be created during registration with complete customer information."
|
|
1846
1850
|
);
|
|
1847
1851
|
}
|
|
1848
1852
|
return this.riskClient.createProfile({
|