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,7 +54,7 @@ var TimeoutError = class _TimeoutError extends CGSError {
|
|
|
54
54
|
Object.setPrototypeOf(this, _TimeoutError.prototype);
|
|
55
55
|
}
|
|
56
56
|
};
|
|
57
|
-
var CircuitBreakerOpenError = class _CircuitBreakerOpenError extends
|
|
57
|
+
var CircuitBreakerOpenError = class _CircuitBreakerOpenError extends VesantError {
|
|
58
58
|
constructor() {
|
|
59
59
|
super("Circuit breaker is open \u2014 requests are temporarily blocked", "CIRCUIT_BREAKER_OPEN", 503);
|
|
60
60
|
this.name = "CircuitBreakerOpenError";
|
|
@@ -199,22 +199,22 @@ var RateLimitTracker = class {
|
|
|
199
199
|
function createConsoleLogger() {
|
|
200
200
|
return {
|
|
201
201
|
debug(message, meta) {
|
|
202
|
-
console.log(`[
|
|
202
|
+
console.log(`[Vesant SDK] ${message}`, meta !== void 0 ? meta : "");
|
|
203
203
|
},
|
|
204
204
|
info(message, meta) {
|
|
205
|
-
console.info(`[
|
|
205
|
+
console.info(`[Vesant SDK] ${message}`, meta !== void 0 ? meta : "");
|
|
206
206
|
},
|
|
207
207
|
warn(message, meta) {
|
|
208
|
-
console.warn(`[
|
|
208
|
+
console.warn(`[Vesant SDK] ${message}`, meta !== void 0 ? meta : "");
|
|
209
209
|
},
|
|
210
210
|
error(message, meta) {
|
|
211
|
-
console.error(`[
|
|
211
|
+
console.error(`[Vesant SDK] ${message}`, meta !== void 0 ? meta : "");
|
|
212
212
|
}
|
|
213
213
|
};
|
|
214
214
|
}
|
|
215
215
|
|
|
216
216
|
// src/core/version.ts
|
|
217
|
-
var SDK_VERSION = "1.
|
|
217
|
+
var SDK_VERSION = "1.5.0";
|
|
218
218
|
|
|
219
219
|
// src/shared/browser-utils.ts
|
|
220
220
|
function generateUUID() {
|
|
@@ -231,7 +231,7 @@ function generateDeviceId() {
|
|
|
231
231
|
if (typeof window === "undefined" || typeof localStorage === "undefined") {
|
|
232
232
|
return generateUUID();
|
|
233
233
|
}
|
|
234
|
-
const storageKey = "
|
|
234
|
+
const storageKey = "vesant_device_id";
|
|
235
235
|
let deviceId = localStorage.getItem(storageKey);
|
|
236
236
|
if (!deviceId) {
|
|
237
237
|
deviceId = generateUUID();
|
|
@@ -298,9 +298,20 @@ var BaseClient = class {
|
|
|
298
298
|
}
|
|
299
299
|
this.interceptors = config.interceptors || [];
|
|
300
300
|
this.logger = config.logger || createConsoleLogger();
|
|
301
|
+
let environment = config.environment;
|
|
302
|
+
const apiKey = config.apiKey || "";
|
|
303
|
+
if (apiKey.startsWith("pk_test_")) {
|
|
304
|
+
if (environment === "production") {
|
|
305
|
+
this.logger.warn('Sandbox API key (pk_test_*) used with environment: "production" \u2014 overriding to "sandbox"');
|
|
306
|
+
}
|
|
307
|
+
environment = "sandbox";
|
|
308
|
+
} else if (apiKey.startsWith("pk_live_") && environment === "sandbox") {
|
|
309
|
+
this.logger.warn('Production API key (pk_live_*) used with environment: "sandbox" \u2014 sandbox isolation will still be applied for backward compatibility');
|
|
310
|
+
}
|
|
301
311
|
this.config = {
|
|
302
312
|
...config,
|
|
303
|
-
apiKey
|
|
313
|
+
apiKey,
|
|
314
|
+
environment,
|
|
304
315
|
headers: config.headers || {},
|
|
305
316
|
timeout: config.timeout || 1e4,
|
|
306
317
|
retries: config.retries || 3,
|
|
@@ -367,10 +378,7 @@ var BaseClient = class {
|
|
|
367
378
|
}
|
|
368
379
|
}
|
|
369
380
|
if (this.config.debug) {
|
|
370
|
-
this.logger.debug(`${finalOptions.method || "GET"} ${
|
|
371
|
-
headers: finalOptions.headers,
|
|
372
|
-
body: finalOptions.body
|
|
373
|
-
});
|
|
381
|
+
this.logger.debug(`${finalOptions.method || "GET"} ${endpoint}`);
|
|
374
382
|
}
|
|
375
383
|
const response = await fetch(url, {
|
|
376
384
|
...finalOptions,
|
|
@@ -404,17 +412,17 @@ var BaseClient = class {
|
|
|
404
412
|
}
|
|
405
413
|
}
|
|
406
414
|
if (this.config.debug) {
|
|
407
|
-
this.logger.debug(
|
|
415
|
+
this.logger.debug(`Response: ${response.status}`);
|
|
408
416
|
}
|
|
409
417
|
return result;
|
|
410
418
|
} catch (error) {
|
|
411
419
|
clearTimeout(timeoutId);
|
|
412
|
-
if (error instanceof
|
|
420
|
+
if (error instanceof VesantError && error.statusCode && error.statusCode >= 500) {
|
|
413
421
|
this.circuitBreaker?.onFailure();
|
|
414
422
|
} else if (error instanceof NetworkError || error instanceof TimeoutError) {
|
|
415
423
|
this.circuitBreaker?.onFailure();
|
|
416
424
|
}
|
|
417
|
-
if (error instanceof
|
|
425
|
+
if (error instanceof VesantError && !error.requestId) {
|
|
418
426
|
error.requestId = requestId;
|
|
419
427
|
}
|
|
420
428
|
if (error instanceof Error) {
|
|
@@ -427,7 +435,7 @@ var BaseClient = class {
|
|
|
427
435
|
if (error instanceof Error) {
|
|
428
436
|
if (error.name === "AbortError") {
|
|
429
437
|
if (requestOptions?.signal?.aborted) {
|
|
430
|
-
const abortError = new
|
|
438
|
+
const abortError = new VesantError("Request aborted", "REQUEST_ABORTED");
|
|
431
439
|
abortError.requestId = requestId;
|
|
432
440
|
throw abortError;
|
|
433
441
|
}
|
|
@@ -436,7 +444,7 @@ var BaseClient = class {
|
|
|
436
444
|
timeoutError.requestId = requestId;
|
|
437
445
|
throw timeoutError;
|
|
438
446
|
}
|
|
439
|
-
if (error instanceof
|
|
447
|
+
if (error instanceof VesantError) {
|
|
440
448
|
throw error;
|
|
441
449
|
}
|
|
442
450
|
}
|
|
@@ -459,7 +467,7 @@ var BaseClient = class {
|
|
|
459
467
|
if (requestOptions?.signal?.aborted) {
|
|
460
468
|
throw lastError;
|
|
461
469
|
}
|
|
462
|
-
if (lastError instanceof
|
|
470
|
+
if (lastError instanceof VesantError && lastError.statusCode && lastError.statusCode >= 400 && lastError.statusCode < 500 && lastError.statusCode !== 429) {
|
|
463
471
|
throw lastError;
|
|
464
472
|
}
|
|
465
473
|
if (attempt === retries) {
|
|
@@ -487,13 +495,13 @@ var BaseClient = class {
|
|
|
487
495
|
const createError = () => {
|
|
488
496
|
switch (status) {
|
|
489
497
|
case 400:
|
|
490
|
-
return new
|
|
498
|
+
return new VesantError(message, "BAD_REQUEST", 400);
|
|
491
499
|
case 401:
|
|
492
500
|
return new AuthenticationError(message);
|
|
493
501
|
case 403:
|
|
494
|
-
return new
|
|
502
|
+
return new VesantError(message, "FORBIDDEN", 403);
|
|
495
503
|
case 404:
|
|
496
|
-
return new
|
|
504
|
+
return new VesantError(message, "NOT_FOUND", 404);
|
|
497
505
|
case 429: {
|
|
498
506
|
const retryAfter = data.retry_after || data.retryAfter;
|
|
499
507
|
return new RateLimitError(retryAfter);
|
|
@@ -504,7 +512,7 @@ var BaseClient = class {
|
|
|
504
512
|
case 504:
|
|
505
513
|
return new ServiceUnavailableError(message);
|
|
506
514
|
default:
|
|
507
|
-
return new
|
|
515
|
+
return new VesantError(message, "UNKNOWN_ERROR", status);
|
|
508
516
|
}
|
|
509
517
|
};
|
|
510
518
|
const error = createError();
|