vesant-sdk 1.4.5 → 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 +44 -51
- package/dist/compliance/index.js.map +1 -1
- package/dist/compliance/index.mjs +44 -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 +30 -33
- package/dist/decisions/index.js.map +1 -1
- package/dist/decisions/index.mjs +30 -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 +31 -34
- package/dist/geolocation/index.js.map +1 -1
- package/dist/geolocation/index.mjs +31 -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 +47 -52
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +47 -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 +30 -33
- package/dist/kyc/core.js.map +1 -1
- package/dist/kyc/core.mjs +30 -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 +30 -33
- package/dist/kyc/index.js.map +1 -1
- package/dist/kyc/index.mjs +30 -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 +33 -36
- package/dist/risk-profile/index.js.map +1 -1
- package/dist/risk-profile/index.mjs +33 -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 +30 -33
- package/dist/scores/index.js.map +1 -1
- package/dist/scores/index.mjs +30 -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
package/dist/index.mjs
CHANGED
|
@@ -1,51 +1,52 @@
|
|
|
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
|
|
12
|
+
var CGSError = VesantError;
|
|
13
|
+
var NetworkError = class _NetworkError extends VesantError {
|
|
13
14
|
constructor(message, originalError) {
|
|
14
|
-
super(message, "NETWORK_ERROR"
|
|
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
|
|
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
|
|
28
|
-
constructor(message) {
|
|
29
|
-
super(
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
65
|
+
var ComplianceError = class _ComplianceError extends VesantError {
|
|
65
66
|
constructor(message, originalError, code = "COMPLIANCE_ERROR") {
|
|
66
|
-
super(message, code
|
|
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
|
|
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(`[
|
|
218
|
+
console.log(`[Vesant SDK] ${message}`, meta !== void 0 ? meta : "");
|
|
218
219
|
},
|
|
219
220
|
info(message, meta) {
|
|
220
|
-
console.info(`[
|
|
221
|
+
console.info(`[Vesant SDK] ${message}`, meta !== void 0 ? meta : "");
|
|
221
222
|
},
|
|
222
223
|
warn(message, meta) {
|
|
223
|
-
console.warn(`[
|
|
224
|
+
console.warn(`[Vesant SDK] ${message}`, meta !== void 0 ? meta : "");
|
|
224
225
|
},
|
|
225
226
|
error(message, meta) {
|
|
226
|
-
console.error(`[
|
|
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.
|
|
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 = "
|
|
260
|
+
const storageKey = "vesant_device_id";
|
|
260
261
|
let deviceId = localStorage.getItem(storageKey);
|
|
261
262
|
if (!deviceId) {
|
|
262
263
|
deviceId = generateUUID();
|
|
@@ -331,7 +332,7 @@ var BaseClient = class {
|
|
|
331
332
|
}
|
|
332
333
|
environment = "sandbox";
|
|
333
334
|
} else if (apiKey.startsWith("pk_live_") && environment === "sandbox") {
|
|
334
|
-
this.logger.warn('Production API key (pk_live_*) used with environment: "sandbox" \u2014
|
|
335
|
+
this.logger.warn('Production API key (pk_live_*) used with environment: "sandbox" \u2014 sandbox isolation will still be applied for backward compatibility');
|
|
335
336
|
}
|
|
336
337
|
this.config = {
|
|
337
338
|
...config,
|
|
@@ -403,10 +404,7 @@ var BaseClient = class {
|
|
|
403
404
|
}
|
|
404
405
|
}
|
|
405
406
|
if (this.config.debug) {
|
|
406
|
-
this.logger.debug(`${finalOptions.method || "GET"} ${
|
|
407
|
-
headers: finalOptions.headers,
|
|
408
|
-
body: finalOptions.body
|
|
409
|
-
});
|
|
407
|
+
this.logger.debug(`${finalOptions.method || "GET"} ${endpoint}`);
|
|
410
408
|
}
|
|
411
409
|
const response = await fetch(url, {
|
|
412
410
|
...finalOptions,
|
|
@@ -440,17 +438,17 @@ var BaseClient = class {
|
|
|
440
438
|
}
|
|
441
439
|
}
|
|
442
440
|
if (this.config.debug) {
|
|
443
|
-
this.logger.debug(
|
|
441
|
+
this.logger.debug(`Response: ${response.status}`);
|
|
444
442
|
}
|
|
445
443
|
return result;
|
|
446
444
|
} catch (error) {
|
|
447
445
|
clearTimeout(timeoutId);
|
|
448
|
-
if (error instanceof
|
|
446
|
+
if (error instanceof VesantError && error.statusCode && error.statusCode >= 500) {
|
|
449
447
|
this.circuitBreaker?.onFailure();
|
|
450
448
|
} else if (error instanceof NetworkError || error instanceof TimeoutError) {
|
|
451
449
|
this.circuitBreaker?.onFailure();
|
|
452
450
|
}
|
|
453
|
-
if (error instanceof
|
|
451
|
+
if (error instanceof VesantError && !error.requestId) {
|
|
454
452
|
error.requestId = requestId;
|
|
455
453
|
}
|
|
456
454
|
if (error instanceof Error) {
|
|
@@ -463,7 +461,7 @@ var BaseClient = class {
|
|
|
463
461
|
if (error instanceof Error) {
|
|
464
462
|
if (error.name === "AbortError") {
|
|
465
463
|
if (requestOptions?.signal?.aborted) {
|
|
466
|
-
const abortError = new
|
|
464
|
+
const abortError = new VesantError("Request aborted", "REQUEST_ABORTED");
|
|
467
465
|
abortError.requestId = requestId;
|
|
468
466
|
throw abortError;
|
|
469
467
|
}
|
|
@@ -472,7 +470,7 @@ var BaseClient = class {
|
|
|
472
470
|
timeoutError.requestId = requestId;
|
|
473
471
|
throw timeoutError;
|
|
474
472
|
}
|
|
475
|
-
if (error instanceof
|
|
473
|
+
if (error instanceof VesantError) {
|
|
476
474
|
throw error;
|
|
477
475
|
}
|
|
478
476
|
}
|
|
@@ -495,7 +493,7 @@ var BaseClient = class {
|
|
|
495
493
|
if (requestOptions?.signal?.aborted) {
|
|
496
494
|
throw lastError;
|
|
497
495
|
}
|
|
498
|
-
if (lastError instanceof
|
|
496
|
+
if (lastError instanceof VesantError && lastError.statusCode && lastError.statusCode >= 400 && lastError.statusCode < 500 && lastError.statusCode !== 429) {
|
|
499
497
|
throw lastError;
|
|
500
498
|
}
|
|
501
499
|
if (attempt === retries) {
|
|
@@ -523,13 +521,13 @@ var BaseClient = class {
|
|
|
523
521
|
const createError = () => {
|
|
524
522
|
switch (status) {
|
|
525
523
|
case 400:
|
|
526
|
-
return new
|
|
524
|
+
return new VesantError(message, "BAD_REQUEST", 400);
|
|
527
525
|
case 401:
|
|
528
526
|
return new AuthenticationError(message);
|
|
529
527
|
case 403:
|
|
530
|
-
return new
|
|
528
|
+
return new VesantError(message, "FORBIDDEN", 403);
|
|
531
529
|
case 404:
|
|
532
|
-
return new
|
|
530
|
+
return new VesantError(message, "NOT_FOUND", 404);
|
|
533
531
|
case 429: {
|
|
534
532
|
const retryAfter = data.retry_after || data.retryAfter;
|
|
535
533
|
return new RateLimitError(retryAfter);
|
|
@@ -540,7 +538,7 @@ var BaseClient = class {
|
|
|
540
538
|
case 504:
|
|
541
539
|
return new ServiceUnavailableError(message);
|
|
542
540
|
default:
|
|
543
|
-
return new
|
|
541
|
+
return new VesantError(message, "UNKNOWN_ERROR", status);
|
|
544
542
|
}
|
|
545
543
|
};
|
|
546
544
|
const error = createError();
|
|
@@ -1351,8 +1349,8 @@ var RiskProfileClient = class extends BaseClient {
|
|
|
1351
1349
|
requestOptions
|
|
1352
1350
|
);
|
|
1353
1351
|
} catch (error) {
|
|
1354
|
-
if (error instanceof
|
|
1355
|
-
throw new
|
|
1352
|
+
if (error instanceof VesantError && (error.statusCode === 404 || error.code === "NOT_FOUND")) {
|
|
1353
|
+
throw new VesantError("Profile not found", "NOT_FOUND", 404);
|
|
1356
1354
|
}
|
|
1357
1355
|
throw error;
|
|
1358
1356
|
}
|
|
@@ -1402,7 +1400,7 @@ var RiskProfileClient = class extends BaseClient {
|
|
|
1402
1400
|
try {
|
|
1403
1401
|
return await this.getProfile(customerId, requestOptions);
|
|
1404
1402
|
} catch (error) {
|
|
1405
|
-
if (error instanceof
|
|
1403
|
+
if (error instanceof VesantError && error.code === "NOT_FOUND") {
|
|
1406
1404
|
return await this.createProfile(createRequest, requestOptions);
|
|
1407
1405
|
}
|
|
1408
1406
|
throw error;
|
|
@@ -1569,8 +1567,6 @@ var ComplianceClient = class {
|
|
|
1569
1567
|
if (this.config.debug) {
|
|
1570
1568
|
this.logger.debug("Registration verification complete", {
|
|
1571
1569
|
allowed: true,
|
|
1572
|
-
riskScore: geoVerification.risk_score,
|
|
1573
|
-
profileId: profile.id,
|
|
1574
1570
|
requiresKYC,
|
|
1575
1571
|
requiresEDD
|
|
1576
1572
|
});
|
|
@@ -1586,16 +1582,14 @@ var ComplianceClient = class {
|
|
|
1586
1582
|
};
|
|
1587
1583
|
} catch (error) {
|
|
1588
1584
|
if (this.config.debug) {
|
|
1589
|
-
this.logger.error("Registration verification failed", {
|
|
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
|
+
});
|
|
1590
1589
|
}
|
|
1591
1590
|
throw new ComplianceError(
|
|
1592
1591
|
"Registration verification failed",
|
|
1593
|
-
|
|
1594
|
-
stage: geoVerification ? "profile_creation" : "geo_verification",
|
|
1595
|
-
geoRecordId: geoVerification?.record_id,
|
|
1596
|
-
customerId: request.customerId,
|
|
1597
|
-
cause: error
|
|
1598
|
-
},
|
|
1592
|
+
error instanceof Error ? error.message : void 0,
|
|
1599
1593
|
geoVerification ? "PROFILE_CREATION_FAILED" : "GEO_VERIFICATION_FAILED"
|
|
1600
1594
|
);
|
|
1601
1595
|
}
|
|
@@ -1812,7 +1806,7 @@ var ComplianceClient = class {
|
|
|
1812
1806
|
processingTime: Date.now() - startTime
|
|
1813
1807
|
};
|
|
1814
1808
|
} catch (error) {
|
|
1815
|
-
throw new ComplianceError("Login verification failed", error);
|
|
1809
|
+
throw new ComplianceError("Login verification failed", error instanceof Error ? error.message : void 0);
|
|
1816
1810
|
}
|
|
1817
1811
|
}
|
|
1818
1812
|
/**
|
|
@@ -1891,7 +1885,7 @@ var ComplianceClient = class {
|
|
|
1891
1885
|
processingTime: Date.now() - startTime
|
|
1892
1886
|
};
|
|
1893
1887
|
} catch (error) {
|
|
1894
|
-
throw new ComplianceError("Transaction verification failed", error);
|
|
1888
|
+
throw new ComplianceError("Transaction verification failed", error instanceof Error ? error.message : void 0);
|
|
1895
1889
|
}
|
|
1896
1890
|
}
|
|
1897
1891
|
/**
|
|
@@ -1937,7 +1931,7 @@ var ComplianceClient = class {
|
|
|
1937
1931
|
async createProfileFromGeo(customerId, geoVerification, customerData) {
|
|
1938
1932
|
if (!customerData?.email || !customerData?.fullName) {
|
|
1939
1933
|
this.logger.warn(
|
|
1940
|
-
|
|
1934
|
+
"Creating profile with incomplete data. Profiles should be created during registration with complete customer information."
|
|
1941
1935
|
);
|
|
1942
1936
|
}
|
|
1943
1937
|
return this.riskClient.createProfile({
|
|
@@ -3133,6 +3127,6 @@ function buildHandler(options) {
|
|
|
3133
3127
|
return handler;
|
|
3134
3128
|
}
|
|
3135
3129
|
|
|
3136
|
-
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 };
|
|
3137
3131
|
//# sourceMappingURL=index.mjs.map
|
|
3138
3132
|
//# sourceMappingURL=index.mjs.map
|