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,46 +1,46 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
// src/core/errors.ts
|
|
4
|
-
var
|
|
4
|
+
var VesantError = class _VesantError extends Error {
|
|
5
5
|
constructor(message, code, statusCode, details) {
|
|
6
6
|
super(message);
|
|
7
7
|
this.code = code;
|
|
8
8
|
this.statusCode = statusCode;
|
|
9
9
|
this.details = details;
|
|
10
|
-
this.name = "
|
|
11
|
-
Object.setPrototypeOf(this,
|
|
10
|
+
this.name = "VesantError";
|
|
11
|
+
Object.setPrototypeOf(this, _VesantError.prototype);
|
|
12
12
|
}
|
|
13
13
|
};
|
|
14
|
-
var NetworkError = class _NetworkError extends
|
|
14
|
+
var NetworkError = class _NetworkError extends VesantError {
|
|
15
15
|
constructor(message, originalError) {
|
|
16
|
-
super(message, "NETWORK_ERROR"
|
|
16
|
+
super(message, "NETWORK_ERROR");
|
|
17
17
|
this.originalError = originalError;
|
|
18
18
|
this.name = "NetworkError";
|
|
19
19
|
Object.setPrototypeOf(this, _NetworkError.prototype);
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
|
-
var ValidationError = class _ValidationError extends
|
|
22
|
+
var ValidationError = class _ValidationError extends VesantError {
|
|
23
23
|
constructor(message, fields) {
|
|
24
24
|
super(message, "VALIDATION_ERROR", 400, { fields });
|
|
25
25
|
this.name = "ValidationError";
|
|
26
26
|
Object.setPrototypeOf(this, _ValidationError.prototype);
|
|
27
27
|
}
|
|
28
28
|
};
|
|
29
|
-
var ServiceUnavailableError = class _ServiceUnavailableError extends
|
|
30
|
-
constructor(message) {
|
|
31
|
-
super(
|
|
29
|
+
var ServiceUnavailableError = class _ServiceUnavailableError extends VesantError {
|
|
30
|
+
constructor(message = "Service unavailable") {
|
|
31
|
+
super(message, "SERVICE_UNAVAILABLE", 503);
|
|
32
32
|
this.name = "ServiceUnavailableError";
|
|
33
33
|
Object.setPrototypeOf(this, _ServiceUnavailableError.prototype);
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
|
-
var AuthenticationError = class _AuthenticationError extends
|
|
36
|
+
var AuthenticationError = class _AuthenticationError extends VesantError {
|
|
37
37
|
constructor(message = "Authentication failed") {
|
|
38
38
|
super(message, "AUTHENTICATION_ERROR", 401);
|
|
39
39
|
this.name = "AuthenticationError";
|
|
40
40
|
Object.setPrototypeOf(this, _AuthenticationError.prototype);
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
|
-
var RateLimitError = class _RateLimitError extends
|
|
43
|
+
var RateLimitError = class _RateLimitError extends VesantError {
|
|
44
44
|
constructor(retryAfter) {
|
|
45
45
|
super("Rate limit exceeded", "RATE_LIMIT_EXCEEDED", 429, { retryAfter });
|
|
46
46
|
this.retryAfter = retryAfter;
|
|
@@ -48,7 +48,7 @@ var RateLimitError = class _RateLimitError extends CGSError {
|
|
|
48
48
|
Object.setPrototypeOf(this, _RateLimitError.prototype);
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
var TimeoutError = class _TimeoutError extends
|
|
51
|
+
var TimeoutError = class _TimeoutError extends VesantError {
|
|
52
52
|
constructor(timeout) {
|
|
53
53
|
super(`Request timeout after ${timeout}ms`, "TIMEOUT", 408, { timeout });
|
|
54
54
|
this.timeout = timeout;
|
|
@@ -56,7 +56,7 @@ var TimeoutError = class _TimeoutError extends CGSError {
|
|
|
56
56
|
Object.setPrototypeOf(this, _TimeoutError.prototype);
|
|
57
57
|
}
|
|
58
58
|
};
|
|
59
|
-
var CircuitBreakerOpenError = class _CircuitBreakerOpenError extends
|
|
59
|
+
var CircuitBreakerOpenError = class _CircuitBreakerOpenError extends VesantError {
|
|
60
60
|
constructor() {
|
|
61
61
|
super("Circuit breaker is open \u2014 requests are temporarily blocked", "CIRCUIT_BREAKER_OPEN", 503);
|
|
62
62
|
this.name = "CircuitBreakerOpenError";
|
|
@@ -201,22 +201,22 @@ var RateLimitTracker = class {
|
|
|
201
201
|
function createConsoleLogger() {
|
|
202
202
|
return {
|
|
203
203
|
debug(message, meta) {
|
|
204
|
-
console.log(`[
|
|
204
|
+
console.log(`[Vesant SDK] ${message}`, meta !== void 0 ? meta : "");
|
|
205
205
|
},
|
|
206
206
|
info(message, meta) {
|
|
207
|
-
console.info(`[
|
|
207
|
+
console.info(`[Vesant SDK] ${message}`, meta !== void 0 ? meta : "");
|
|
208
208
|
},
|
|
209
209
|
warn(message, meta) {
|
|
210
|
-
console.warn(`[
|
|
210
|
+
console.warn(`[Vesant SDK] ${message}`, meta !== void 0 ? meta : "");
|
|
211
211
|
},
|
|
212
212
|
error(message, meta) {
|
|
213
|
-
console.error(`[
|
|
213
|
+
console.error(`[Vesant SDK] ${message}`, meta !== void 0 ? meta : "");
|
|
214
214
|
}
|
|
215
215
|
};
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
// src/core/version.ts
|
|
219
|
-
var SDK_VERSION = "1.
|
|
219
|
+
var SDK_VERSION = "1.5.0";
|
|
220
220
|
|
|
221
221
|
// src/shared/browser-utils.ts
|
|
222
222
|
function generateUUID() {
|
|
@@ -233,7 +233,7 @@ function generateDeviceId() {
|
|
|
233
233
|
if (typeof window === "undefined" || typeof localStorage === "undefined") {
|
|
234
234
|
return generateUUID();
|
|
235
235
|
}
|
|
236
|
-
const storageKey = "
|
|
236
|
+
const storageKey = "vesant_device_id";
|
|
237
237
|
let deviceId = localStorage.getItem(storageKey);
|
|
238
238
|
if (!deviceId) {
|
|
239
239
|
deviceId = generateUUID();
|
|
@@ -300,9 +300,20 @@ var BaseClient = class {
|
|
|
300
300
|
}
|
|
301
301
|
this.interceptors = config.interceptors || [];
|
|
302
302
|
this.logger = config.logger || createConsoleLogger();
|
|
303
|
+
let environment = config.environment;
|
|
304
|
+
const apiKey = config.apiKey || "";
|
|
305
|
+
if (apiKey.startsWith("pk_test_")) {
|
|
306
|
+
if (environment === "production") {
|
|
307
|
+
this.logger.warn('Sandbox API key (pk_test_*) used with environment: "production" \u2014 overriding to "sandbox"');
|
|
308
|
+
}
|
|
309
|
+
environment = "sandbox";
|
|
310
|
+
} else if (apiKey.startsWith("pk_live_") && environment === "sandbox") {
|
|
311
|
+
this.logger.warn('Production API key (pk_live_*) used with environment: "sandbox" \u2014 sandbox isolation will still be applied for backward compatibility');
|
|
312
|
+
}
|
|
303
313
|
this.config = {
|
|
304
314
|
...config,
|
|
305
|
-
apiKey
|
|
315
|
+
apiKey,
|
|
316
|
+
environment,
|
|
306
317
|
headers: config.headers || {},
|
|
307
318
|
timeout: config.timeout || 1e4,
|
|
308
319
|
retries: config.retries || 3,
|
|
@@ -369,10 +380,7 @@ var BaseClient = class {
|
|
|
369
380
|
}
|
|
370
381
|
}
|
|
371
382
|
if (this.config.debug) {
|
|
372
|
-
this.logger.debug(`${finalOptions.method || "GET"} ${
|
|
373
|
-
headers: finalOptions.headers,
|
|
374
|
-
body: finalOptions.body
|
|
375
|
-
});
|
|
383
|
+
this.logger.debug(`${finalOptions.method || "GET"} ${endpoint}`);
|
|
376
384
|
}
|
|
377
385
|
const response = await fetch(url, {
|
|
378
386
|
...finalOptions,
|
|
@@ -406,17 +414,17 @@ var BaseClient = class {
|
|
|
406
414
|
}
|
|
407
415
|
}
|
|
408
416
|
if (this.config.debug) {
|
|
409
|
-
this.logger.debug(
|
|
417
|
+
this.logger.debug(`Response: ${response.status}`);
|
|
410
418
|
}
|
|
411
419
|
return result;
|
|
412
420
|
} catch (error) {
|
|
413
421
|
clearTimeout(timeoutId);
|
|
414
|
-
if (error instanceof
|
|
422
|
+
if (error instanceof VesantError && error.statusCode && error.statusCode >= 500) {
|
|
415
423
|
this.circuitBreaker?.onFailure();
|
|
416
424
|
} else if (error instanceof NetworkError || error instanceof TimeoutError) {
|
|
417
425
|
this.circuitBreaker?.onFailure();
|
|
418
426
|
}
|
|
419
|
-
if (error instanceof
|
|
427
|
+
if (error instanceof VesantError && !error.requestId) {
|
|
420
428
|
error.requestId = requestId;
|
|
421
429
|
}
|
|
422
430
|
if (error instanceof Error) {
|
|
@@ -429,7 +437,7 @@ var BaseClient = class {
|
|
|
429
437
|
if (error instanceof Error) {
|
|
430
438
|
if (error.name === "AbortError") {
|
|
431
439
|
if (requestOptions?.signal?.aborted) {
|
|
432
|
-
const abortError = new
|
|
440
|
+
const abortError = new VesantError("Request aborted", "REQUEST_ABORTED");
|
|
433
441
|
abortError.requestId = requestId;
|
|
434
442
|
throw abortError;
|
|
435
443
|
}
|
|
@@ -438,7 +446,7 @@ var BaseClient = class {
|
|
|
438
446
|
timeoutError.requestId = requestId;
|
|
439
447
|
throw timeoutError;
|
|
440
448
|
}
|
|
441
|
-
if (error instanceof
|
|
449
|
+
if (error instanceof VesantError) {
|
|
442
450
|
throw error;
|
|
443
451
|
}
|
|
444
452
|
}
|
|
@@ -461,7 +469,7 @@ var BaseClient = class {
|
|
|
461
469
|
if (requestOptions?.signal?.aborted) {
|
|
462
470
|
throw lastError;
|
|
463
471
|
}
|
|
464
|
-
if (lastError instanceof
|
|
472
|
+
if (lastError instanceof VesantError && lastError.statusCode && lastError.statusCode >= 400 && lastError.statusCode < 500 && lastError.statusCode !== 429) {
|
|
465
473
|
throw lastError;
|
|
466
474
|
}
|
|
467
475
|
if (attempt === retries) {
|
|
@@ -489,13 +497,13 @@ var BaseClient = class {
|
|
|
489
497
|
const createError = () => {
|
|
490
498
|
switch (status) {
|
|
491
499
|
case 400:
|
|
492
|
-
return new
|
|
500
|
+
return new VesantError(message, "BAD_REQUEST", 400);
|
|
493
501
|
case 401:
|
|
494
502
|
return new AuthenticationError(message);
|
|
495
503
|
case 403:
|
|
496
|
-
return new
|
|
504
|
+
return new VesantError(message, "FORBIDDEN", 403);
|
|
497
505
|
case 404:
|
|
498
|
-
return new
|
|
506
|
+
return new VesantError(message, "NOT_FOUND", 404);
|
|
499
507
|
case 429: {
|
|
500
508
|
const retryAfter = data.retry_after || data.retryAfter;
|
|
501
509
|
return new RateLimitError(retryAfter);
|
|
@@ -506,7 +514,7 @@ var BaseClient = class {
|
|
|
506
514
|
case 504:
|
|
507
515
|
return new ServiceUnavailableError(message);
|
|
508
516
|
default:
|
|
509
|
-
return new
|
|
517
|
+
return new VesantError(message, "UNKNOWN_ERROR", status);
|
|
510
518
|
}
|
|
511
519
|
};
|
|
512
520
|
const error = createError();
|