vesant-sdk 1.4.5 → 1.5.2
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/README.md +5 -3
- package/dist/{client-BlAt791q.d.ts → client-B8pFrXx_.d.ts} +11 -5
- package/dist/{client-oo_3-0YW.d.mts → client-BZxzOidG.d.mts} +11 -5
- package/dist/{client-CY41e2Z_.d.mts → client-CIon-bGS.d.mts} +9 -5
- package/dist/{client-CY41e2Z_.d.ts → client-CIon-bGS.d.ts} +9 -5
- package/dist/compliance/index.d.mts +7 -7
- package/dist/compliance/index.d.ts +7 -7
- package/dist/compliance/index.js +46 -51
- package/dist/compliance/index.js.map +1 -1
- package/dist/compliance/index.mjs +46 -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 +32 -33
- package/dist/decisions/index.js.map +1 -1
- package/dist/decisions/index.mjs +32 -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 +33 -34
- package/dist/geolocation/index.js.map +1 -1
- package/dist/geolocation/index.mjs +33 -34
- package/dist/geolocation/index.mjs.map +1 -1
- package/dist/index.d.mts +553 -21
- package/dist/index.d.ts +553 -21
- package/dist/index.js +320 -161
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +318 -159
- 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 +32 -33
- package/dist/kyc/core.js.map +1 -1
- package/dist/kyc/core.mjs +32 -33
- package/dist/kyc/core.mjs.map +1 -1
- package/dist/kyc/index.d.mts +11 -7
- package/dist/kyc/index.d.ts +11 -7
- package/dist/kyc/index.js +32 -33
- package/dist/kyc/index.js.map +1 -1
- package/dist/kyc/index.mjs +32 -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 +35 -36
- package/dist/risk-profile/index.js.map +1 -1
- package/dist/risk-profile/index.mjs +35 -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 +32 -33
- package/dist/scores/index.js.map +1 -1
- package/dist/scores/index.mjs +32 -33
- package/dist/scores/index.mjs.map +1 -1
- package/dist/{types-jaLuzruy.d.mts → types-1RzYeSal.d.mts} +2 -2
- package/dist/{types-DZHongaK.d.mts → types-B4Ezqo7V.d.mts} +2 -2
- package/dist/{types-DZHongaK.d.ts → types-B4Ezqo7V.d.ts} +2 -2
- package/dist/{types-DLC7Sfy5.d.ts → types-X5Md_dD_.d.ts} +2 -2
- package/dist/webhooks/index.d.mts +1 -1
- package/dist/webhooks/index.d.ts +1 -1
- package/package.json +6 -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.2";
|
|
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();
|
|
@@ -314,7 +314,7 @@ var BaseClient = class {
|
|
|
314
314
|
}
|
|
315
315
|
environment = "sandbox";
|
|
316
316
|
} else if (apiKey.startsWith("pk_live_") && environment === "sandbox") {
|
|
317
|
-
this.logger.warn('Production API key (pk_live_*) used with environment: "sandbox" \u2014
|
|
317
|
+
this.logger.warn('Production API key (pk_live_*) used with environment: "sandbox" \u2014 sandbox isolation will still be applied for backward compatibility');
|
|
318
318
|
}
|
|
319
319
|
this.config = {
|
|
320
320
|
...config,
|
|
@@ -386,10 +386,7 @@ var BaseClient = class {
|
|
|
386
386
|
}
|
|
387
387
|
}
|
|
388
388
|
if (this.config.debug) {
|
|
389
|
-
this.logger.debug(`${finalOptions.method || "GET"} ${
|
|
390
|
-
headers: finalOptions.headers,
|
|
391
|
-
body: finalOptions.body
|
|
392
|
-
});
|
|
389
|
+
this.logger.debug(`${finalOptions.method || "GET"} ${endpoint}`);
|
|
393
390
|
}
|
|
394
391
|
const response = await fetch(url, {
|
|
395
392
|
...finalOptions,
|
|
@@ -423,17 +420,17 @@ var BaseClient = class {
|
|
|
423
420
|
}
|
|
424
421
|
}
|
|
425
422
|
if (this.config.debug) {
|
|
426
|
-
this.logger.debug(
|
|
423
|
+
this.logger.debug(`Response: ${response.status}`);
|
|
427
424
|
}
|
|
428
425
|
return result;
|
|
429
426
|
} catch (error) {
|
|
430
427
|
clearTimeout(timeoutId);
|
|
431
|
-
if (error instanceof
|
|
428
|
+
if (error instanceof VesantError && error.statusCode && error.statusCode >= 500) {
|
|
432
429
|
this.circuitBreaker?.onFailure();
|
|
433
430
|
} else if (error instanceof NetworkError || error instanceof TimeoutError) {
|
|
434
431
|
this.circuitBreaker?.onFailure();
|
|
435
432
|
}
|
|
436
|
-
if (error instanceof
|
|
433
|
+
if (error instanceof VesantError && !error.requestId) {
|
|
437
434
|
error.requestId = requestId;
|
|
438
435
|
}
|
|
439
436
|
if (error instanceof Error) {
|
|
@@ -446,7 +443,7 @@ var BaseClient = class {
|
|
|
446
443
|
if (error instanceof Error) {
|
|
447
444
|
if (error.name === "AbortError") {
|
|
448
445
|
if (requestOptions?.signal?.aborted) {
|
|
449
|
-
const abortError = new
|
|
446
|
+
const abortError = new VesantError("Request aborted", "REQUEST_ABORTED");
|
|
450
447
|
abortError.requestId = requestId;
|
|
451
448
|
throw abortError;
|
|
452
449
|
}
|
|
@@ -455,7 +452,7 @@ var BaseClient = class {
|
|
|
455
452
|
timeoutError.requestId = requestId;
|
|
456
453
|
throw timeoutError;
|
|
457
454
|
}
|
|
458
|
-
if (error instanceof
|
|
455
|
+
if (error instanceof VesantError) {
|
|
459
456
|
throw error;
|
|
460
457
|
}
|
|
461
458
|
}
|
|
@@ -478,7 +475,7 @@ var BaseClient = class {
|
|
|
478
475
|
if (requestOptions?.signal?.aborted) {
|
|
479
476
|
throw lastError;
|
|
480
477
|
}
|
|
481
|
-
if (lastError instanceof
|
|
478
|
+
if (lastError instanceof VesantError && lastError.statusCode && lastError.statusCode >= 400 && lastError.statusCode < 500 && lastError.statusCode !== 429) {
|
|
482
479
|
throw lastError;
|
|
483
480
|
}
|
|
484
481
|
if (attempt === retries) {
|
|
@@ -506,13 +503,15 @@ var BaseClient = class {
|
|
|
506
503
|
const createError = () => {
|
|
507
504
|
switch (status) {
|
|
508
505
|
case 400:
|
|
509
|
-
return new
|
|
506
|
+
return new VesantError(message, "BAD_REQUEST", 400);
|
|
510
507
|
case 401:
|
|
511
508
|
return new AuthenticationError(message);
|
|
512
509
|
case 403:
|
|
513
|
-
return new
|
|
510
|
+
return new VesantError(message, "FORBIDDEN", 403);
|
|
514
511
|
case 404:
|
|
515
|
-
return new
|
|
512
|
+
return new VesantError(message, "NOT_FOUND", 404);
|
|
513
|
+
case 409:
|
|
514
|
+
return new VesantError(message, "DUPLICATE_PROFILE", 409);
|
|
516
515
|
case 429: {
|
|
517
516
|
const retryAfter = data.retry_after || data.retryAfter;
|
|
518
517
|
return new RateLimitError(retryAfter);
|
|
@@ -523,7 +522,7 @@ var BaseClient = class {
|
|
|
523
522
|
case 504:
|
|
524
523
|
return new ServiceUnavailableError(message);
|
|
525
524
|
default:
|
|
526
|
-
return new
|
|
525
|
+
return new VesantError(message, "UNKNOWN_ERROR", status);
|
|
527
526
|
}
|
|
528
527
|
};
|
|
529
528
|
const error = createError();
|
|
@@ -1267,8 +1266,8 @@ var RiskProfileClient = class extends BaseClient {
|
|
|
1267
1266
|
requestOptions
|
|
1268
1267
|
);
|
|
1269
1268
|
} catch (error) {
|
|
1270
|
-
if (error instanceof
|
|
1271
|
-
throw new
|
|
1269
|
+
if (error instanceof VesantError && (error.statusCode === 404 || error.code === "NOT_FOUND")) {
|
|
1270
|
+
throw new VesantError("Profile not found", "NOT_FOUND", 404);
|
|
1272
1271
|
}
|
|
1273
1272
|
throw error;
|
|
1274
1273
|
}
|
|
@@ -1318,7 +1317,7 @@ var RiskProfileClient = class extends BaseClient {
|
|
|
1318
1317
|
try {
|
|
1319
1318
|
return await this.getProfile(customerId, requestOptions);
|
|
1320
1319
|
} catch (error) {
|
|
1321
|
-
if (error instanceof
|
|
1320
|
+
if (error instanceof VesantError && error.code === "NOT_FOUND") {
|
|
1322
1321
|
return await this.createProfile(createRequest, requestOptions);
|
|
1323
1322
|
}
|
|
1324
1323
|
throw error;
|
|
@@ -1485,8 +1484,6 @@ var ComplianceClient = class {
|
|
|
1485
1484
|
if (this.config.debug) {
|
|
1486
1485
|
this.logger.debug("Registration verification complete", {
|
|
1487
1486
|
allowed: true,
|
|
1488
|
-
riskScore: geoVerification.risk_score,
|
|
1489
|
-
profileId: profile.id,
|
|
1490
1487
|
requiresKYC,
|
|
1491
1488
|
requiresEDD
|
|
1492
1489
|
});
|
|
@@ -1502,16 +1499,14 @@ var ComplianceClient = class {
|
|
|
1502
1499
|
};
|
|
1503
1500
|
} catch (error) {
|
|
1504
1501
|
if (this.config.debug) {
|
|
1505
|
-
this.logger.error("Registration verification failed", {
|
|
1502
|
+
this.logger.error("Registration verification failed", {
|
|
1503
|
+
code: error instanceof Error ? error.code : void 0,
|
|
1504
|
+
message: error instanceof Error ? error.message : "Unknown error"
|
|
1505
|
+
});
|
|
1506
1506
|
}
|
|
1507
1507
|
throw new ComplianceError(
|
|
1508
1508
|
"Registration verification failed",
|
|
1509
|
-
|
|
1510
|
-
stage: geoVerification ? "profile_creation" : "geo_verification",
|
|
1511
|
-
geoRecordId: geoVerification?.record_id,
|
|
1512
|
-
customerId: request.customerId,
|
|
1513
|
-
cause: error
|
|
1514
|
-
},
|
|
1509
|
+
error instanceof Error ? error.message : void 0,
|
|
1515
1510
|
geoVerification ? "PROFILE_CREATION_FAILED" : "GEO_VERIFICATION_FAILED"
|
|
1516
1511
|
);
|
|
1517
1512
|
}
|
|
@@ -1728,7 +1723,7 @@ var ComplianceClient = class {
|
|
|
1728
1723
|
processingTime: Date.now() - startTime
|
|
1729
1724
|
};
|
|
1730
1725
|
} catch (error) {
|
|
1731
|
-
throw new ComplianceError("Login verification failed", error);
|
|
1726
|
+
throw new ComplianceError("Login verification failed", error instanceof Error ? error.message : void 0);
|
|
1732
1727
|
}
|
|
1733
1728
|
}
|
|
1734
1729
|
/**
|
|
@@ -1807,7 +1802,7 @@ var ComplianceClient = class {
|
|
|
1807
1802
|
processingTime: Date.now() - startTime
|
|
1808
1803
|
};
|
|
1809
1804
|
} catch (error) {
|
|
1810
|
-
throw new ComplianceError("Transaction verification failed", error);
|
|
1805
|
+
throw new ComplianceError("Transaction verification failed", error instanceof Error ? error.message : void 0);
|
|
1811
1806
|
}
|
|
1812
1807
|
}
|
|
1813
1808
|
/**
|
|
@@ -1853,7 +1848,7 @@ var ComplianceClient = class {
|
|
|
1853
1848
|
async createProfileFromGeo(customerId, geoVerification, customerData) {
|
|
1854
1849
|
if (!customerData?.email || !customerData?.fullName) {
|
|
1855
1850
|
this.logger.warn(
|
|
1856
|
-
|
|
1851
|
+
"Creating profile with incomplete data. Profiles should be created during registration with complete customer information."
|
|
1857
1852
|
);
|
|
1858
1853
|
}
|
|
1859
1854
|
return this.riskClient.createProfile({
|