vesant-sdk 1.7.0 → 1.7.1-dev.0520b46
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-B0qhE2kr.d.mts → client-5q4whhGu.d.mts} +2 -2
- package/dist/{client-DF7hlMEz.d.ts → client-BaUekQT8.d.ts} +96 -52
- package/dist/{client-DtH2RLuy.d.ts → client-DUHC-68_.d.ts} +2 -2
- package/dist/{client-DrjgZoH_.d.mts → client-XDEhh9VN.d.mts} +96 -52
- package/dist/{client-BolQlL5e.d.mts → client-q9fN8Hhf.d.mts} +103 -1
- package/dist/{client-BolQlL5e.d.ts → client-q9fN8Hhf.d.ts} +103 -1
- package/dist/compliance/index.d.mts +3 -3
- package/dist/compliance/index.d.ts +3 -3
- package/dist/compliance/index.js +218 -90
- package/dist/compliance/index.js.map +1 -1
- package/dist/compliance/index.mjs +218 -90
- package/dist/compliance/index.mjs.map +1 -1
- package/dist/decisions/index.d.mts +1 -1
- package/dist/decisions/index.d.ts +1 -1
- package/dist/decisions/index.js +69 -8
- package/dist/decisions/index.js.map +1 -1
- package/dist/decisions/index.mjs +69 -8
- package/dist/decisions/index.mjs.map +1 -1
- package/dist/geolocation/index.d.mts +68 -7
- package/dist/geolocation/index.d.ts +68 -7
- package/dist/geolocation/index.js +223 -90
- package/dist/geolocation/index.js.map +1 -1
- package/dist/geolocation/index.mjs +220 -91
- package/dist/geolocation/index.mjs.map +1 -1
- package/dist/index-C3zUKydT.d.mts +264 -0
- package/dist/index-DSDgS09k.d.ts +264 -0
- package/dist/index.d.mts +27 -10
- package/dist/index.d.ts +27 -10
- package/dist/index.js +418 -126
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +409 -127
- package/dist/index.mjs.map +1 -1
- package/dist/kyc/core.d.mts +2 -2
- package/dist/kyc/core.d.ts +2 -2
- package/dist/kyc/core.js +102 -21
- package/dist/kyc/core.js.map +1 -1
- package/dist/kyc/core.mjs +102 -22
- package/dist/kyc/core.mjs.map +1 -1
- package/dist/kyc/index.d.mts +154 -30
- package/dist/kyc/index.d.ts +154 -30
- package/dist/kyc/index.js +102 -21
- package/dist/kyc/index.js.map +1 -1
- package/dist/kyc/index.mjs +102 -22
- package/dist/kyc/index.mjs.map +1 -1
- package/dist/react.d.mts +14 -3
- package/dist/react.d.ts +14 -3
- package/dist/react.js +317 -68
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +317 -68
- package/dist/react.mjs.map +1 -1
- package/dist/risk-profile/index.d.mts +1 -1
- package/dist/risk-profile/index.d.ts +1 -1
- package/dist/risk-profile/index.js +69 -8
- package/dist/risk-profile/index.js.map +1 -1
- package/dist/risk-profile/index.mjs +69 -8
- package/dist/risk-profile/index.mjs.map +1 -1
- package/dist/scores/index.d.mts +1 -1
- package/dist/scores/index.d.ts +1 -1
- package/dist/scores/index.js +69 -8
- package/dist/scores/index.js.map +1 -1
- package/dist/scores/index.mjs +69 -8
- package/dist/scores/index.mjs.map +1 -1
- package/dist/tax/index.d.mts +2 -2
- package/dist/tax/index.d.ts +2 -2
- package/dist/tax/index.js +74 -10
- package/dist/tax/index.js.map +1 -1
- package/dist/tax/index.mjs +74 -10
- package/dist/tax/index.mjs.map +1 -1
- package/dist/webhooks/index.d.mts +2 -189
- package/dist/webhooks/index.d.ts +2 -189
- package/dist/webhooks/index.js +85 -21
- package/dist/webhooks/index.js.map +1 -1
- package/dist/webhooks/index.mjs +85 -22
- package/dist/webhooks/index.mjs.map +1 -1
- package/package.json +4 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,61 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
// src/core/auth.ts
|
|
4
|
+
var StaticApiKeyProvider = class {
|
|
5
|
+
constructor(apiKey) {
|
|
6
|
+
this.apiKey = apiKey;
|
|
7
|
+
}
|
|
8
|
+
async getCredential() {
|
|
9
|
+
return this.apiKey ? { scheme: "Bearer", token: this.apiKey } : null;
|
|
10
|
+
}
|
|
11
|
+
canRefresh() {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
var RefreshingTokenProvider = class {
|
|
16
|
+
constructor(opts) {
|
|
17
|
+
this.opts = opts;
|
|
18
|
+
this.cached = null;
|
|
19
|
+
this.inFlight = null;
|
|
20
|
+
this.skewMs = opts.skewMs ?? 3e4;
|
|
21
|
+
this.scheme = opts.scheme ?? "Bearer";
|
|
22
|
+
this.now = opts.now ?? (() => Date.now());
|
|
23
|
+
}
|
|
24
|
+
canRefresh() {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
async getCredential(ctx) {
|
|
28
|
+
const forceRefresh = ctx?.forceRefresh ?? false;
|
|
29
|
+
if (!forceRefresh && this.cached && !this.isExpiring(this.cached)) {
|
|
30
|
+
return { scheme: this.scheme, token: this.cached.token };
|
|
31
|
+
}
|
|
32
|
+
const fresh = await this.refresh();
|
|
33
|
+
return { scheme: this.scheme, token: fresh.token };
|
|
34
|
+
}
|
|
35
|
+
isExpiring(token) {
|
|
36
|
+
if (token.expiresAt === void 0) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
return this.now() >= token.expiresAt - this.skewMs;
|
|
40
|
+
}
|
|
41
|
+
refresh() {
|
|
42
|
+
if (this.inFlight) {
|
|
43
|
+
return this.inFlight;
|
|
44
|
+
}
|
|
45
|
+
this.inFlight = (async () => {
|
|
46
|
+
try {
|
|
47
|
+
const fresh = await this.opts.fetchToken();
|
|
48
|
+
this.cached = fresh;
|
|
49
|
+
this.opts.onRotate?.({ expiresAt: fresh.expiresAt });
|
|
50
|
+
return fresh;
|
|
51
|
+
} finally {
|
|
52
|
+
this.inFlight = null;
|
|
53
|
+
}
|
|
54
|
+
})();
|
|
55
|
+
return this.inFlight;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
3
59
|
// src/core/errors.ts
|
|
4
60
|
var VesantError = class _VesantError extends Error {
|
|
5
61
|
constructor(message, code, statusCode, details) {
|
|
@@ -242,7 +298,7 @@ var noopLogger = {
|
|
|
242
298
|
};
|
|
243
299
|
|
|
244
300
|
// src/core/version.ts
|
|
245
|
-
var SDK_VERSION = "1.7.
|
|
301
|
+
var SDK_VERSION = "1.7.1";
|
|
246
302
|
|
|
247
303
|
// src/shared/browser-utils.ts
|
|
248
304
|
function generateUUID() {
|
|
@@ -324,6 +380,12 @@ var BaseClient = class {
|
|
|
324
380
|
if (!config.tenantId?.trim()) {
|
|
325
381
|
throw new ValidationError("tenantId is required and must be a non-empty string", ["tenantId"]);
|
|
326
382
|
}
|
|
383
|
+
if (typeof fetch === "undefined") {
|
|
384
|
+
throw new VesantError(
|
|
385
|
+
"The Vesant SDK requires a global fetch (Node.js >= 18). Upgrade Node or provide a fetch polyfill.",
|
|
386
|
+
"RUNTIME_UNSUPPORTED"
|
|
387
|
+
);
|
|
388
|
+
}
|
|
327
389
|
this.interceptors = config.interceptors || [];
|
|
328
390
|
this.logger = config.logger || createConsoleLogger();
|
|
329
391
|
let environment = config.environment;
|
|
@@ -342,11 +404,12 @@ var BaseClient = class {
|
|
|
342
404
|
environment,
|
|
343
405
|
headers: config.headers || {},
|
|
344
406
|
timeout: config.timeout || 1e4,
|
|
345
|
-
retries: config.retries
|
|
407
|
+
retries: config.retries ?? 3,
|
|
346
408
|
debug: config.debug || false,
|
|
347
409
|
interceptors: this.interceptors,
|
|
348
410
|
logger: this.logger
|
|
349
411
|
};
|
|
412
|
+
this.authProvider = config.authProvider ?? (apiKey ? new StaticApiKeyProvider(apiKey) : void 0);
|
|
350
413
|
if (config.circuitBreaker) {
|
|
351
414
|
this.circuitBreaker = new CircuitBreaker(config.circuitBreaker);
|
|
352
415
|
}
|
|
@@ -354,6 +417,19 @@ var BaseClient = class {
|
|
|
354
417
|
this.rateLimitTracker = new RateLimitTracker();
|
|
355
418
|
}
|
|
356
419
|
}
|
|
420
|
+
/**
|
|
421
|
+
* Resolve the Idempotency-Key for a request. Mutating methods (POST/PUT/PATCH)
|
|
422
|
+
* get the caller-supplied key or a freshly minted UUID; non-mutating methods get
|
|
423
|
+
* none. requestWithRetry resolves this once and injects it so every retry reuses
|
|
424
|
+
* one key (letting the server dedup replays); a direct request() resolves per call.
|
|
425
|
+
*/
|
|
426
|
+
resolveIdempotencyKey(method, requestOptions) {
|
|
427
|
+
const isMutating = ["POST", "PUT", "PATCH"].includes((method || "GET").toUpperCase());
|
|
428
|
+
if (!isMutating) {
|
|
429
|
+
return void 0;
|
|
430
|
+
}
|
|
431
|
+
return requestOptions?.idempotencyKey ?? generateUUID();
|
|
432
|
+
}
|
|
357
433
|
/**
|
|
358
434
|
* Make an HTTP request with timeout and error handling
|
|
359
435
|
*/
|
|
@@ -379,15 +455,20 @@ var BaseClient = class {
|
|
|
379
455
|
...this.config.headers,
|
|
380
456
|
...options.headers || {}
|
|
381
457
|
};
|
|
382
|
-
|
|
383
|
-
|
|
458
|
+
const credential = await this.authProvider?.getCredential({
|
|
459
|
+
tenantId: this.config.tenantId,
|
|
460
|
+
requestId
|
|
461
|
+
});
|
|
462
|
+
if (credential) {
|
|
463
|
+
headers["Authorization"] = `${credential.scheme ?? "Bearer"} ${credential.token}`;
|
|
384
464
|
}
|
|
385
465
|
if (this.config.environment === "sandbox") {
|
|
386
466
|
headers["X-Sandbox"] = "true";
|
|
387
467
|
}
|
|
388
468
|
const method = (options.method || "GET").toUpperCase();
|
|
389
|
-
|
|
390
|
-
|
|
469
|
+
const idempotencyKey = this.resolveIdempotencyKey(method, requestOptions);
|
|
470
|
+
if (idempotencyKey) {
|
|
471
|
+
headers["Idempotency-Key"] = idempotencyKey;
|
|
391
472
|
}
|
|
392
473
|
const controller = new AbortController();
|
|
393
474
|
const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
|
|
@@ -408,10 +489,28 @@ var BaseClient = class {
|
|
|
408
489
|
if (this.config.debug) {
|
|
409
490
|
this.logger.debug(`${finalOptions.method || "GET"} ${endpoint}`);
|
|
410
491
|
}
|
|
411
|
-
|
|
492
|
+
let response = await fetch(url, {
|
|
412
493
|
...finalOptions,
|
|
413
494
|
signal: controller.signal
|
|
414
495
|
});
|
|
496
|
+
if (response.status === 401 && this.authProvider?.canRefresh?.()) {
|
|
497
|
+
const refreshed = await this.authProvider.getCredential({
|
|
498
|
+
tenantId: this.config.tenantId,
|
|
499
|
+
requestId,
|
|
500
|
+
forceRefresh: true
|
|
501
|
+
});
|
|
502
|
+
if (refreshed) {
|
|
503
|
+
this.config.onCredentialRotated?.({ reason: "unauthorized" });
|
|
504
|
+
finalOptions = {
|
|
505
|
+
...finalOptions,
|
|
506
|
+
headers: {
|
|
507
|
+
...finalOptions.headers,
|
|
508
|
+
Authorization: `${refreshed.scheme ?? "Bearer"} ${refreshed.token}`
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
response = await fetch(url, { ...finalOptions, signal: controller.signal });
|
|
512
|
+
}
|
|
513
|
+
}
|
|
415
514
|
clearTimeout(timeoutId);
|
|
416
515
|
if (this.rateLimitTracker) {
|
|
417
516
|
this.rateLimitTracker.updateFromHeaders(response.headers);
|
|
@@ -500,9 +599,11 @@ var BaseClient = class {
|
|
|
500
599
|
*/
|
|
501
600
|
async requestWithRetry(endpoint, options = {}, serviceURL, retries = this.config.retries, requestOptions) {
|
|
502
601
|
let lastError;
|
|
602
|
+
const idempotencyKey = this.resolveIdempotencyKey(options.method || "GET", requestOptions);
|
|
603
|
+
const attemptOptions = idempotencyKey ? { ...requestOptions, idempotencyKey } : requestOptions;
|
|
503
604
|
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
504
605
|
try {
|
|
505
|
-
return await this.request(endpoint, options, serviceURL,
|
|
606
|
+
return await this.request(endpoint, options, serviceURL, attemptOptions);
|
|
506
607
|
} catch (error) {
|
|
507
608
|
lastError = error instanceof Error ? error : new Error("Unknown error");
|
|
508
609
|
if (requestOptions?.signal?.aborted) {
|
|
@@ -599,6 +700,9 @@ var BaseClient = class {
|
|
|
599
700
|
if (config.interceptors) {
|
|
600
701
|
this.interceptors = config.interceptors;
|
|
601
702
|
}
|
|
703
|
+
if (config.authProvider !== void 0 || config.apiKey !== void 0) {
|
|
704
|
+
this.authProvider = this.config.authProvider ?? (this.config.apiKey ? new StaticApiKeyProvider(this.config.apiKey) : void 0);
|
|
705
|
+
}
|
|
602
706
|
}
|
|
603
707
|
/**
|
|
604
708
|
* Get current configuration (readonly)
|
|
@@ -626,8 +730,69 @@ var BaseClient = class {
|
|
|
626
730
|
}
|
|
627
731
|
};
|
|
628
732
|
|
|
733
|
+
// src/core/pagination.ts
|
|
734
|
+
async function* paginate(fetchPage) {
|
|
735
|
+
let page = 1;
|
|
736
|
+
let totalPages;
|
|
737
|
+
do {
|
|
738
|
+
const response = await fetchPage(page);
|
|
739
|
+
const items = response.data ?? [];
|
|
740
|
+
for (const item of items) {
|
|
741
|
+
yield item;
|
|
742
|
+
}
|
|
743
|
+
totalPages = response.total_pages ?? page;
|
|
744
|
+
if (items.length === 0) {
|
|
745
|
+
break;
|
|
746
|
+
}
|
|
747
|
+
page += 1;
|
|
748
|
+
} while (page <= totalPages);
|
|
749
|
+
}
|
|
750
|
+
async function collectAll(fetchPage) {
|
|
751
|
+
const items = [];
|
|
752
|
+
for await (const item of paginate(fetchPage)) {
|
|
753
|
+
items.push(item);
|
|
754
|
+
}
|
|
755
|
+
return items;
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
// src/core/dedup.ts
|
|
759
|
+
var InMemoryDedupStore = class {
|
|
760
|
+
constructor(opts = {}) {
|
|
761
|
+
this.expiryById = /* @__PURE__ */ new Map();
|
|
762
|
+
this.maxEntries = opts.maxEntries ?? 1e3;
|
|
763
|
+
this.now = opts.now ?? (() => Date.now());
|
|
764
|
+
}
|
|
765
|
+
async seen(id) {
|
|
766
|
+
return this.expiryById.has(id);
|
|
767
|
+
}
|
|
768
|
+
async mark(id, ttlMs) {
|
|
769
|
+
const now = this.now();
|
|
770
|
+
this.expiryById.set(id, now + ttlMs);
|
|
771
|
+
if (this.expiryById.size > this.maxEntries) {
|
|
772
|
+
for (const [key, expiresAt] of this.expiryById) {
|
|
773
|
+
if (now > expiresAt) {
|
|
774
|
+
this.expiryById.delete(key);
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
};
|
|
780
|
+
|
|
629
781
|
// src/core/webhook-utils.ts
|
|
630
|
-
async function verifyWebhookSignature(payload, signature, secret) {
|
|
782
|
+
async function verifyWebhookSignature(payload, signature, secret, opts = {}) {
|
|
783
|
+
const signed = parseSignedTimestamp(signature);
|
|
784
|
+
if (signed) {
|
|
785
|
+
const tolerance = opts.tolerance ?? 3e5;
|
|
786
|
+
const now = opts.now?.() ?? Date.now();
|
|
787
|
+
if (tolerance > 0 && Math.abs(now - signed.t * 1e3) > tolerance) {
|
|
788
|
+
return false;
|
|
789
|
+
}
|
|
790
|
+
const expected = await computeHmacSha256(`${signed.t}.${payload}`, secret);
|
|
791
|
+
return constantTimeEqual(signed.v1, expected);
|
|
792
|
+
}
|
|
793
|
+
if (opts.allowLegacy === false) {
|
|
794
|
+
return false;
|
|
795
|
+
}
|
|
631
796
|
const hexDigest = await computeHmacSha256(payload, secret);
|
|
632
797
|
const expectedPrefixed = `sha256=${hexDigest}`;
|
|
633
798
|
if (signature.startsWith("sha256=")) {
|
|
@@ -635,6 +800,25 @@ async function verifyWebhookSignature(payload, signature, secret) {
|
|
|
635
800
|
}
|
|
636
801
|
return constantTimeEqual(signature, hexDigest);
|
|
637
802
|
}
|
|
803
|
+
function parseSignedTimestamp(signature) {
|
|
804
|
+
if (!signature.includes("t=") || !signature.includes("v1=")) {
|
|
805
|
+
return null;
|
|
806
|
+
}
|
|
807
|
+
let t;
|
|
808
|
+
let v1;
|
|
809
|
+
for (const part of signature.split(",")) {
|
|
810
|
+
const eq = part.indexOf("=");
|
|
811
|
+
if (eq === -1) continue;
|
|
812
|
+
const key = part.slice(0, eq).trim();
|
|
813
|
+
const value = part.slice(eq + 1).trim();
|
|
814
|
+
if (key === "t") t = Number(value);
|
|
815
|
+
else if (key === "v1") v1 = value;
|
|
816
|
+
}
|
|
817
|
+
if (t === void 0 || Number.isNaN(t) || !v1) {
|
|
818
|
+
return null;
|
|
819
|
+
}
|
|
820
|
+
return { t, v1 };
|
|
821
|
+
}
|
|
638
822
|
async function computeHmacSha256(message, secret) {
|
|
639
823
|
if (typeof globalThis.crypto !== "undefined" && globalThis.crypto.subtle) {
|
|
640
824
|
const encoder = new TextEncoder();
|
|
@@ -669,27 +853,63 @@ function constantTimeEqual(a, b) {
|
|
|
669
853
|
return result === 0;
|
|
670
854
|
}
|
|
671
855
|
|
|
672
|
-
// src/geolocation/
|
|
673
|
-
var
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
);
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
856
|
+
// src/geolocation/integrity.ts
|
|
857
|
+
var isNil = (v) => v === null || v === void 0;
|
|
858
|
+
function assessGpsIntegrity(input, opts = {}) {
|
|
859
|
+
const flags = [];
|
|
860
|
+
const now = opts.now ?? (() => Date.now());
|
|
861
|
+
const maxAgeMs = opts.maxAgeMs ?? 6e4;
|
|
862
|
+
const minAccuracy = opts.minAccuracyMeters ?? 1;
|
|
863
|
+
const { accuracy, altitude, altitudeAccuracy, heading, speed, timestamp } = input;
|
|
864
|
+
if (isNil(accuracy)) {
|
|
865
|
+
flags.push("accuracy_missing");
|
|
866
|
+
} else if (accuracy === 0) {
|
|
867
|
+
flags.push("accuracy_zero");
|
|
868
|
+
} else if (accuracy < minAccuracy) {
|
|
869
|
+
flags.push("accuracy_implausibly_small");
|
|
870
|
+
}
|
|
871
|
+
const hasMotion = !isNil(heading) || !isNil(speed);
|
|
872
|
+
if (hasMotion && (isNil(accuracy) || accuracy === 0)) {
|
|
873
|
+
flags.push("motion_without_accuracy");
|
|
874
|
+
}
|
|
875
|
+
if (!isNil(altitude) && isNil(altitudeAccuracy)) {
|
|
876
|
+
flags.push("altitude_without_accuracy");
|
|
877
|
+
}
|
|
878
|
+
if (timestamp !== void 0 && now() - timestamp > maxAgeMs) {
|
|
879
|
+
flags.push("stale_timestamp");
|
|
880
|
+
}
|
|
881
|
+
if (opts.permissionState === "denied" || opts.permissionState === "prompt") {
|
|
882
|
+
flags.push(`permission_${opts.permissionState}`);
|
|
883
|
+
}
|
|
884
|
+
return { suspicious: flags.length > 0, flags };
|
|
885
|
+
}
|
|
886
|
+
function gpsIntegrityInputFromPosition(position) {
|
|
887
|
+
const c = position.coords;
|
|
888
|
+
return {
|
|
889
|
+
latitude: c.latitude,
|
|
890
|
+
longitude: c.longitude,
|
|
891
|
+
accuracy: c.accuracy,
|
|
892
|
+
altitude: c.altitude,
|
|
893
|
+
altitudeAccuracy: c.altitudeAccuracy,
|
|
894
|
+
heading: c.heading,
|
|
895
|
+
speed: c.speed,
|
|
896
|
+
timestamp: position.timestamp
|
|
897
|
+
};
|
|
898
|
+
}
|
|
899
|
+
async function probeGeolocationPermission() {
|
|
900
|
+
try {
|
|
901
|
+
if (typeof navigator === "undefined" || !navigator.permissions?.query) {
|
|
902
|
+
return "unavailable";
|
|
903
|
+
}
|
|
904
|
+
const status = await navigator.permissions.query({ name: "geolocation" });
|
|
905
|
+
return status.state;
|
|
906
|
+
} catch {
|
|
907
|
+
return "unavailable";
|
|
689
908
|
}
|
|
690
|
-
const { createHmac } = await import('crypto');
|
|
691
|
-
return createHmac("sha256", key).update(message).digest("hex");
|
|
692
909
|
}
|
|
910
|
+
|
|
911
|
+
// src/geolocation/ciphertext.ts
|
|
912
|
+
var CIPHER_TEXT_EXPIRY_MINUTES = 5;
|
|
693
913
|
function getWebGLInfo() {
|
|
694
914
|
if (typeof document === "undefined") return null;
|
|
695
915
|
try {
|
|
@@ -721,6 +941,7 @@ async function requestGPSLocation(timeout = 1e4, highAccuracy = true) {
|
|
|
721
941
|
if (typeof navigator === "undefined" || !navigator.geolocation) {
|
|
722
942
|
return null;
|
|
723
943
|
}
|
|
944
|
+
const permissionState = await probeGeolocationPermission();
|
|
724
945
|
return new Promise((resolve) => {
|
|
725
946
|
navigator.geolocation.getCurrentPosition(
|
|
726
947
|
(position) => {
|
|
@@ -737,6 +958,7 @@ async function requestGPSLocation(timeout = 1e4, highAccuracy = true) {
|
|
|
737
958
|
resolve(null);
|
|
738
959
|
return;
|
|
739
960
|
}
|
|
961
|
+
const { flags } = assessGpsIntegrity(gpsIntegrityInputFromPosition(position), { permissionState });
|
|
740
962
|
resolve({
|
|
741
963
|
latitude,
|
|
742
964
|
longitude,
|
|
@@ -745,7 +967,8 @@ async function requestGPSLocation(timeout = 1e4, highAccuracy = true) {
|
|
|
745
967
|
altitude_accuracy: position.coords.altitudeAccuracy ?? void 0,
|
|
746
968
|
heading: position.coords.heading ?? void 0,
|
|
747
969
|
speed: position.coords.speed ?? void 0,
|
|
748
|
-
timestamp: position.timestamp
|
|
970
|
+
timestamp: position.timestamp,
|
|
971
|
+
integrity_flags: flags.length ? flags : void 0
|
|
749
972
|
});
|
|
750
973
|
},
|
|
751
974
|
() => {
|
|
@@ -812,6 +1035,9 @@ async function generateCipherText(options, config) {
|
|
|
812
1035
|
);
|
|
813
1036
|
if (location) {
|
|
814
1037
|
locationData = location;
|
|
1038
|
+
if (location.integrity_flags?.length) {
|
|
1039
|
+
warnings.push(`GPS integrity flags (advisory): ${location.integrity_flags.join(", ")}`);
|
|
1040
|
+
}
|
|
815
1041
|
} else if (gpsRequiredByConfig) {
|
|
816
1042
|
throw new VesantError(
|
|
817
1043
|
`GPS location is required for ${options.reason} by tenant configuration, but GPS was not available or permission was denied`,
|
|
@@ -841,15 +1067,7 @@ async function generateCipherText(options, config) {
|
|
|
841
1067
|
};
|
|
842
1068
|
const encoded = encodePayload(payload);
|
|
843
1069
|
const timestamp = now.getTime().toString(36);
|
|
844
|
-
|
|
845
|
-
const hmacKey = options.signingKey || options.apiKey;
|
|
846
|
-
if (hmacKey) {
|
|
847
|
-
const message = `02.${timestamp}.${encoded}`;
|
|
848
|
-
const hmac = await computeHMAC(hmacKey, message);
|
|
849
|
-
cipherText = `${message}.${hmac}`;
|
|
850
|
-
} else {
|
|
851
|
-
cipherText = `01.${timestamp}.${encoded}`;
|
|
852
|
-
}
|
|
1070
|
+
const cipherText = `01.${timestamp}.${encoded}`;
|
|
853
1071
|
return {
|
|
854
1072
|
cipherText,
|
|
855
1073
|
locationCaptured: !!locationData,
|
|
@@ -858,6 +1076,7 @@ async function generateCipherText(options, config) {
|
|
|
858
1076
|
expiresAt: expiry.toISOString()
|
|
859
1077
|
};
|
|
860
1078
|
}
|
|
1079
|
+
var collectDeviceSignals = generateCipherText;
|
|
861
1080
|
function decodeCipherText(cipherText) {
|
|
862
1081
|
try {
|
|
863
1082
|
const parts = cipherText.split(".");
|
|
@@ -885,6 +1104,7 @@ function isCipherTextExpired(cipherText) {
|
|
|
885
1104
|
}
|
|
886
1105
|
|
|
887
1106
|
// src/geolocation/client.ts
|
|
1107
|
+
var DEFAULT_GPS_CONFIG_TTL_MS = 5 * 60 * 1e3;
|
|
888
1108
|
var GeolocationClient = class extends BaseClient {
|
|
889
1109
|
constructor(config) {
|
|
890
1110
|
const baseConfig = {
|
|
@@ -900,6 +1120,8 @@ var GeolocationClient = class extends BaseClient {
|
|
|
900
1120
|
environment: config.environment
|
|
901
1121
|
};
|
|
902
1122
|
super(baseConfig);
|
|
1123
|
+
this.gpsConfigCache = null;
|
|
1124
|
+
this.gpsConfigTtlMs = config.gpsConfigTtlMs ?? DEFAULT_GPS_CONFIG_TTL_MS;
|
|
903
1125
|
}
|
|
904
1126
|
// ============================================================================
|
|
905
1127
|
// IP Verification & Compliance
|
|
@@ -931,8 +1153,8 @@ var GeolocationClient = class extends BaseClient {
|
|
|
931
1153
|
* ```
|
|
932
1154
|
*/
|
|
933
1155
|
async verifyIP(request, requestOptions) {
|
|
934
|
-
if (!request.ip_address
|
|
935
|
-
throw new ValidationError("ip_address
|
|
1156
|
+
if (request.ip_address !== void 0 && !request.ip_address.trim()) {
|
|
1157
|
+
throw new ValidationError("ip_address, when provided, must be a non-empty string", ["ip_address"]);
|
|
936
1158
|
}
|
|
937
1159
|
return this.requestWithRetry("/api/v1/geo/verify", {
|
|
938
1160
|
method: "POST",
|
|
@@ -985,37 +1207,85 @@ var GeolocationClient = class extends BaseClient {
|
|
|
985
1207
|
* ```
|
|
986
1208
|
*/
|
|
987
1209
|
async getGPSConfig(requestOptions) {
|
|
988
|
-
const
|
|
989
|
-
if (
|
|
990
|
-
|
|
1210
|
+
const cached = this.gpsConfigCache;
|
|
1211
|
+
if (cached && cached.expiresAt > Date.now()) {
|
|
1212
|
+
return cached.value;
|
|
991
1213
|
}
|
|
992
|
-
return
|
|
1214
|
+
return this.refreshGPSConfig(requestOptions);
|
|
1215
|
+
}
|
|
1216
|
+
/**
|
|
1217
|
+
* Re-read the tenant's GPS requirement configuration, ignoring any copy held
|
|
1218
|
+
* from an earlier read.
|
|
1219
|
+
*
|
|
1220
|
+
* These requirements are edited in the compliance console while your
|
|
1221
|
+
* application is running. `getGPSConfig` reuses a fetched copy for a short
|
|
1222
|
+
* period so a long-lived session does not call the API on every event; call
|
|
1223
|
+
* this when you need a change to take effect immediately — for example right
|
|
1224
|
+
* after an administrator saves new settings.
|
|
1225
|
+
*
|
|
1226
|
+
* @returns The current GPS requirement config per event type
|
|
1227
|
+
*
|
|
1228
|
+
* @example
|
|
1229
|
+
* ```typescript
|
|
1230
|
+
* const config = await client.refreshGPSConfig();
|
|
1231
|
+
* if (config.require_gps.login) {
|
|
1232
|
+
* // GPS is now required for login
|
|
1233
|
+
* }
|
|
1234
|
+
* ```
|
|
1235
|
+
*/
|
|
1236
|
+
async refreshGPSConfig(requestOptions) {
|
|
1237
|
+
const value = await this.requestWithRetry(
|
|
1238
|
+
"/api/v1/geo/config",
|
|
1239
|
+
void 0,
|
|
1240
|
+
void 0,
|
|
1241
|
+
void 0,
|
|
1242
|
+
requestOptions
|
|
1243
|
+
);
|
|
1244
|
+
this.gpsConfigCache = { value, expiresAt: Date.now() + this.gpsConfigTtlMs };
|
|
1245
|
+
return value;
|
|
993
1246
|
}
|
|
994
1247
|
/**
|
|
995
|
-
*
|
|
1248
|
+
* Mint a short-lived, single-use device-signals nonce.
|
|
996
1249
|
*
|
|
997
|
-
*
|
|
998
|
-
*
|
|
1250
|
+
* The nonce is bound to the tenant, user, and event type and is consumed
|
|
1251
|
+
* server-side during validation, so a captured device-signals envelope cannot
|
|
1252
|
+
* be replayed. `validateCipherText` mints and attaches one automatically; call
|
|
1253
|
+
* this directly only if you manage the nonce yourself.
|
|
999
1254
|
*
|
|
1000
|
-
* @
|
|
1255
|
+
* @param userId - User ID the nonce is bound to
|
|
1256
|
+
* @param eventType - Event type the nonce is bound to (login, registration, ...)
|
|
1257
|
+
* @returns The nonce and its expiry
|
|
1258
|
+
*/
|
|
1259
|
+
async fetchSignalsNonce(userId, eventType, requestOptions) {
|
|
1260
|
+
if (!userId?.trim()) {
|
|
1261
|
+
throw new ValidationError("userId is required and must be a non-empty string", ["userId"]);
|
|
1262
|
+
}
|
|
1263
|
+
const request = { user_id: userId, event_type: eventType };
|
|
1264
|
+
return this.request(
|
|
1265
|
+
"/api/v1/geo/signals-token",
|
|
1266
|
+
{
|
|
1267
|
+
method: "POST",
|
|
1268
|
+
body: JSON.stringify(request)
|
|
1269
|
+
},
|
|
1270
|
+
void 0,
|
|
1271
|
+
requestOptions
|
|
1272
|
+
);
|
|
1273
|
+
}
|
|
1274
|
+
/**
|
|
1275
|
+
* Best-effort nonce mint for validation. Returns undefined if minting fails —
|
|
1276
|
+
* the server is the sole authority and blocks when a nonce is required, so this
|
|
1277
|
+
* never downgrades security on the client's say-so.
|
|
1001
1278
|
*/
|
|
1002
|
-
async
|
|
1279
|
+
async resolveSignalsNonce(userId, eventType, requestOptions) {
|
|
1003
1280
|
try {
|
|
1004
|
-
const
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
requestOptions
|
|
1281
|
+
const { nonce } = await this.fetchSignalsNonce(userId, eventType, requestOptions);
|
|
1282
|
+
return nonce;
|
|
1283
|
+
} catch (err) {
|
|
1284
|
+
this.logger.warn(
|
|
1285
|
+
`Failed to mint device-signals nonce; proceeding without it: ${err instanceof Error ? err.message : String(err)}`
|
|
1010
1286
|
);
|
|
1011
|
-
|
|
1012
|
-
this.cachedSigningKey = response.signing_key;
|
|
1013
|
-
return response.signing_key;
|
|
1014
|
-
}
|
|
1015
|
-
} catch {
|
|
1287
|
+
return void 0;
|
|
1016
1288
|
}
|
|
1017
|
-
const config = await this.getGPSConfig(requestOptions);
|
|
1018
|
-
return config.signing_key;
|
|
1019
1289
|
}
|
|
1020
1290
|
// ============================================================================
|
|
1021
1291
|
// CipherText Validation
|
|
@@ -1068,12 +1338,14 @@ var GeolocationClient = class extends BaseClient {
|
|
|
1068
1338
|
if (!userId?.trim()) {
|
|
1069
1339
|
throw new ValidationError("userId is required and must be a non-empty string", ["userId"]);
|
|
1070
1340
|
}
|
|
1341
|
+
const nonce = await this.resolveSignalsNonce(userId, eventType, requestOptions);
|
|
1071
1342
|
const request = {
|
|
1072
1343
|
cipher_text: cipherText,
|
|
1073
1344
|
user_id: userId,
|
|
1074
1345
|
event_type: eventType,
|
|
1075
1346
|
expected_ip: expectedIP,
|
|
1076
|
-
customer_data: customerData
|
|
1347
|
+
customer_data: customerData,
|
|
1348
|
+
nonce
|
|
1077
1349
|
};
|
|
1078
1350
|
return this.requestWithRetry(
|
|
1079
1351
|
"/api/v1/geo/validate-ciphertext",
|
|
@@ -1282,20 +1554,12 @@ var GeolocationClient = class extends BaseClient {
|
|
|
1282
1554
|
*
|
|
1283
1555
|
* @example
|
|
1284
1556
|
* ```typescript
|
|
1285
|
-
* //
|
|
1557
|
+
* // GPS (the web SDK is GPS + IP only; the server handles the IP fallback)
|
|
1286
1558
|
* const result = await client.captureLocation(token, {
|
|
1287
1559
|
* latitude: 37.7749,
|
|
1288
1560
|
* longitude: -122.4194,
|
|
1289
1561
|
* accuracy: 10
|
|
1290
1562
|
* });
|
|
1291
|
-
*
|
|
1292
|
-
* // Using WiFi positioning (fallback)
|
|
1293
|
-
* const result = await client.captureLocation(token, {
|
|
1294
|
-
* wifi_networks: [
|
|
1295
|
-
* { macAddress: "00:11:22:33:44:55", signalStrength: -50 },
|
|
1296
|
-
* { macAddress: "AA:BB:CC:DD:EE:FF", signalStrength: -70 }
|
|
1297
|
-
* ]
|
|
1298
|
-
* });
|
|
1299
1563
|
* ```
|
|
1300
1564
|
*/
|
|
1301
1565
|
async captureLocation(token, capture, requestOptions) {
|
|
@@ -1308,34 +1572,22 @@ var GeolocationClient = class extends BaseClient {
|
|
|
1308
1572
|
// CipherText Generation
|
|
1309
1573
|
// ============================================================================
|
|
1310
1574
|
/**
|
|
1311
|
-
* Generate a
|
|
1575
|
+
* Generate a device-signals envelope containing device and location data,
|
|
1576
|
+
* validated by the server.
|
|
1312
1577
|
*
|
|
1313
|
-
*
|
|
1314
|
-
* If no API key is configured, falls back to unsigned v01 format.
|
|
1315
|
-
*
|
|
1316
|
-
* @param options - Options for cipherText generation
|
|
1578
|
+
* @param options - Options for envelope generation
|
|
1317
1579
|
* @param gpsConfig - Optional GPS config (from getGPSConfig)
|
|
1318
|
-
* @returns
|
|
1580
|
+
* @returns The device-signals envelope result
|
|
1319
1581
|
*
|
|
1320
1582
|
* @example
|
|
1321
1583
|
* ```typescript
|
|
1322
1584
|
* const result = await client.generateCipherText({ reason: 'login' });
|
|
1323
|
-
* console.log(result.cipherText); //
|
|
1585
|
+
* console.log(result.cipherText); // device-signals envelope
|
|
1324
1586
|
* ```
|
|
1325
1587
|
*/
|
|
1326
1588
|
async generateCipherText(options, gpsConfig) {
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
if (!signingKey) {
|
|
1330
|
-
signingKey = await this.fetchSigningKey();
|
|
1331
|
-
}
|
|
1332
|
-
if (!resolvedGpsConfig) {
|
|
1333
|
-
resolvedGpsConfig = await this.getGPSConfig();
|
|
1334
|
-
}
|
|
1335
|
-
return generateCipherText(
|
|
1336
|
-
{ ...options, signingKey: signingKey || void 0 },
|
|
1337
|
-
resolvedGpsConfig
|
|
1338
|
-
);
|
|
1589
|
+
const resolvedGpsConfig = gpsConfig ?? await this.getGPSConfig();
|
|
1590
|
+
return generateCipherText(options, resolvedGpsConfig);
|
|
1339
1591
|
}
|
|
1340
1592
|
// ============================================================================
|
|
1341
1593
|
// Utility Methods (inherited from BaseClient: healthCheck, updateConfig, getConfig, buildQueryString)
|
|
@@ -2738,21 +2990,20 @@ var KycClient = class extends BaseClient {
|
|
|
2738
2990
|
* console.log(`KYC ID: ${result.kyc_id}`);
|
|
2739
2991
|
* ```
|
|
2740
2992
|
*/
|
|
2741
|
-
async requestKycSubmitLink(request) {
|
|
2993
|
+
async requestKycSubmitLink(request, requestOptions) {
|
|
2742
2994
|
return this.requestWithRetry("/api/v1/kyc/request", {
|
|
2743
2995
|
method: "POST",
|
|
2744
2996
|
body: JSON.stringify(request),
|
|
2745
2997
|
headers: this.getUserHeaders()
|
|
2746
|
-
});
|
|
2998
|
+
}, void 0, void 0, requestOptions);
|
|
2747
2999
|
}
|
|
2748
3000
|
/**
|
|
2749
3001
|
* Create a Event-Based Face Verification session.
|
|
2750
3002
|
*
|
|
2751
3003
|
* Inspect the response before showing UI:
|
|
2752
|
-
* - `is_required === false` → skip face
|
|
2753
|
-
* - `
|
|
2754
|
-
*
|
|
2755
|
-
* - `device_type === 'mobile'` → open the face capture modal directly.
|
|
3004
|
+
* - `is_required === false` → skip face verification; `reason` explains why.
|
|
3005
|
+
* - `verification_url` present → embed the hosted journey and poll status.
|
|
3006
|
+
* - `verification_url` absent → use the local camera / QR fallback.
|
|
2756
3007
|
*
|
|
2757
3008
|
* @param request - Reference, customer_id, event, amount (for threshold events), optional URLs.
|
|
2758
3009
|
*/
|
|
@@ -2776,12 +3027,12 @@ var KycClient = class extends BaseClient {
|
|
|
2776
3027
|
*
|
|
2777
3028
|
* @param request - Token from `createEventBasedFaceVerificationSession`, plus the base64 selfie.
|
|
2778
3029
|
*/
|
|
2779
|
-
async submitEventBasedFaceVerificationSession(request) {
|
|
3030
|
+
async submitEventBasedFaceVerificationSession(request, requestOptions) {
|
|
2780
3031
|
return this.request("/api/v1/kyc/face/submit", {
|
|
2781
3032
|
method: "POST",
|
|
2782
3033
|
body: JSON.stringify(request),
|
|
2783
3034
|
headers: this.getUserHeaders()
|
|
2784
|
-
});
|
|
3035
|
+
}, void 0, requestOptions);
|
|
2785
3036
|
}
|
|
2786
3037
|
/**
|
|
2787
3038
|
* Look up the current state of a Event-Based Face Verification session by its
|
|
@@ -2799,11 +3050,28 @@ var KycClient = class extends BaseClient {
|
|
|
2799
3050
|
headers: this.getUserHeaders()
|
|
2800
3051
|
});
|
|
2801
3052
|
}
|
|
3053
|
+
/**
|
|
3054
|
+
* Mint a fresh hosted verification journey for the next attempt on an
|
|
3055
|
+
* active session whose previous hosted-journey attempt was declined.
|
|
3056
|
+
* Only valid while the session is active and attempts remain; the
|
|
3057
|
+
* response carries the new `verification_url` to embed. Used internally
|
|
3058
|
+
* by `FaceCaptureModal`'s Try Again flow in hosted-journey mode.
|
|
3059
|
+
*
|
|
3060
|
+
* @param token - The session token returned by `createEventBasedFaceVerificationSession`.
|
|
3061
|
+
*/
|
|
3062
|
+
async retryEventBasedFaceVerificationJourney(token) {
|
|
3063
|
+
return this.request("/api/v1/kyc/face/onsite/journey", {
|
|
3064
|
+
method: "POST",
|
|
3065
|
+
body: JSON.stringify({ token }),
|
|
3066
|
+
headers: this.getUserHeaders()
|
|
3067
|
+
});
|
|
3068
|
+
}
|
|
2802
3069
|
/**
|
|
2803
3070
|
* Fetch the Redis-backed handoff session for a token. Same backing
|
|
2804
|
-
* store as normal KYC (`kyc:session:<token>`, 15-minute TTL).
|
|
2805
|
-
*
|
|
2806
|
-
*
|
|
3071
|
+
* store as normal KYC (`kyc:session:<token>`, 15-minute TTL). The
|
|
3072
|
+
* Event-Based Face Verification database session still expires after
|
|
3073
|
+
* 10 minutes. Desktop callers poll `mobile_connected` to detect when a
|
|
3074
|
+
* mobile device has scanned the QR and attached.
|
|
2807
3075
|
*
|
|
2808
3076
|
* @param token - The session token returned by `createEventBasedFaceVerificationSession`.
|
|
2809
3077
|
*/
|
|
@@ -2897,12 +3165,12 @@ var KycClient = class extends BaseClient {
|
|
|
2897
3165
|
* console.log(`Verification submitted: ${result.reference}`);
|
|
2898
3166
|
* ```
|
|
2899
3167
|
*/
|
|
2900
|
-
async submitVerification(request) {
|
|
3168
|
+
async submitVerification(request, requestOptions) {
|
|
2901
3169
|
return this.requestWithRetry("/api/v1/kyc/submit", {
|
|
2902
3170
|
method: "POST",
|
|
2903
3171
|
body: JSON.stringify(request),
|
|
2904
3172
|
headers: this.getUserHeaders()
|
|
2905
|
-
});
|
|
3173
|
+
}, void 0, void 0, requestOptions);
|
|
2906
3174
|
}
|
|
2907
3175
|
/**
|
|
2908
3176
|
* Get a KYC request by ID
|
|
@@ -3312,6 +3580,9 @@ var KYC_DECLINED_DESCRIPTIONS = {
|
|
|
3312
3580
|
KYC_PROVIDER_REJECTED: "Identity verification was rejected by the verification provider",
|
|
3313
3581
|
KYC_DECLINED: "Identity verification was declined"
|
|
3314
3582
|
};
|
|
3583
|
+
function isKycDocumentExpiredCallbackEvent(value) {
|
|
3584
|
+
return typeof value === "object" && value !== null && value.event === "kyc_document_expired";
|
|
3585
|
+
}
|
|
3315
3586
|
|
|
3316
3587
|
// src/tax/client.ts
|
|
3317
3588
|
var TaxClient = class extends BaseClient {
|
|
@@ -3342,10 +3613,13 @@ var TaxClient = class extends BaseClient {
|
|
|
3342
3613
|
{ method: "POST" }
|
|
3343
3614
|
);
|
|
3344
3615
|
}
|
|
3345
|
-
async checkTINStatus(customerID) {
|
|
3616
|
+
async checkTINStatus(customerID, requestOptions) {
|
|
3346
3617
|
return this.requestWithRetry(
|
|
3347
3618
|
`/api/v1/tax/customer-tax-profiles/${customerID}/check-tin`,
|
|
3348
|
-
{ method: "POST" }
|
|
3619
|
+
{ method: "POST" },
|
|
3620
|
+
void 0,
|
|
3621
|
+
void 0,
|
|
3622
|
+
requestOptions
|
|
3349
3623
|
);
|
|
3350
3624
|
}
|
|
3351
3625
|
async reRequestTaxForm(customerID, input) {
|
|
@@ -3426,14 +3700,24 @@ var TaxClient = class extends BaseClient {
|
|
|
3426
3700
|
};
|
|
3427
3701
|
|
|
3428
3702
|
// src/webhooks/handler.ts
|
|
3703
|
+
function resolveEventId(event) {
|
|
3704
|
+
if (event.id) {
|
|
3705
|
+
return event.id;
|
|
3706
|
+
}
|
|
3707
|
+
if (event.event_type === "notification.created") {
|
|
3708
|
+
return event.notification?.id;
|
|
3709
|
+
}
|
|
3710
|
+
return void 0;
|
|
3711
|
+
}
|
|
3429
3712
|
var WebhookHandler = class {
|
|
3430
3713
|
constructor(config) {
|
|
3431
3714
|
this.handlers = /* @__PURE__ */ new Map();
|
|
3432
3715
|
this.anyHandlers = [];
|
|
3433
|
-
this.seenEventIds = /* @__PURE__ */ new Map();
|
|
3434
3716
|
this.secret = config.secret;
|
|
3435
3717
|
this.tolerance = config.tolerance ?? 3e5;
|
|
3436
3718
|
this.replayProtection = config.replayProtection ?? true;
|
|
3719
|
+
this.allowLegacySignature = config.allowLegacySignature ?? true;
|
|
3720
|
+
this.dedupStore = config.dedupStore ?? new InMemoryDedupStore();
|
|
3437
3721
|
}
|
|
3438
3722
|
/**
|
|
3439
3723
|
* Register a handler for a specific event type.
|
|
@@ -3455,7 +3739,10 @@ var WebhookHandler = class {
|
|
|
3455
3739
|
* Verify signature and parse the webhook body.
|
|
3456
3740
|
*/
|
|
3457
3741
|
async verifyAndParse(body, signature) {
|
|
3458
|
-
const isValid = await verifyWebhookSignature(body, signature, this.secret
|
|
3742
|
+
const isValid = await verifyWebhookSignature(body, signature, this.secret, {
|
|
3743
|
+
tolerance: this.tolerance,
|
|
3744
|
+
allowLegacy: this.allowLegacySignature
|
|
3745
|
+
});
|
|
3459
3746
|
if (!isValid) {
|
|
3460
3747
|
throw new ValidationError("Invalid webhook signature", ["signature"]);
|
|
3461
3748
|
}
|
|
@@ -3471,18 +3758,21 @@ var WebhookHandler = class {
|
|
|
3471
3758
|
/**
|
|
3472
3759
|
* Parse an event without signature verification (for testing).
|
|
3473
3760
|
*/
|
|
3474
|
-
parseEvent(body) {
|
|
3761
|
+
async parseEvent(body) {
|
|
3475
3762
|
return this.parseAndValidate(body);
|
|
3476
3763
|
}
|
|
3477
|
-
parseAndValidate(body) {
|
|
3764
|
+
async parseAndValidate(body) {
|
|
3478
3765
|
const event = JSON.parse(body);
|
|
3479
|
-
|
|
3480
|
-
|
|
3766
|
+
const eventId = resolveEventId(event);
|
|
3767
|
+
if (!event.event_type || !eventId || !event.timestamp) {
|
|
3768
|
+
throw new ValidationError(
|
|
3769
|
+
"Invalid webhook event: missing required fields (event_type, id, timestamp)",
|
|
3770
|
+
["event_type", "id", "timestamp"]
|
|
3771
|
+
);
|
|
3481
3772
|
}
|
|
3482
3773
|
if (this.tolerance > 0) {
|
|
3483
3774
|
const eventTime = new Date(event.timestamp).getTime();
|
|
3484
|
-
|
|
3485
|
-
if (Math.abs(now - eventTime) > this.tolerance) {
|
|
3775
|
+
if (Math.abs(Date.now() - eventTime) > this.tolerance) {
|
|
3486
3776
|
throw new ValidationError(
|
|
3487
3777
|
`Webhook event timestamp is outside tolerance window (${this.tolerance}ms)`,
|
|
3488
3778
|
["timestamp"]
|
|
@@ -3490,26 +3780,18 @@ var WebhookHandler = class {
|
|
|
3490
3780
|
}
|
|
3491
3781
|
}
|
|
3492
3782
|
if (this.replayProtection) {
|
|
3493
|
-
if (this.
|
|
3783
|
+
if (await this.dedupStore.seen(eventId)) {
|
|
3494
3784
|
throw new ValidationError(
|
|
3495
|
-
`Duplicate webhook event: ${
|
|
3785
|
+
`Duplicate webhook event: ${eventId} has already been processed`,
|
|
3496
3786
|
["id"]
|
|
3497
3787
|
);
|
|
3498
3788
|
}
|
|
3499
|
-
|
|
3500
|
-
this.seenEventIds.set(event.id, now);
|
|
3501
|
-
if (this.seenEventIds.size > 1e3) {
|
|
3502
|
-
for (const [id, seenAt] of this.seenEventIds) {
|
|
3503
|
-
if (now - seenAt > this.tolerance) {
|
|
3504
|
-
this.seenEventIds.delete(id);
|
|
3505
|
-
}
|
|
3506
|
-
}
|
|
3507
|
-
}
|
|
3789
|
+
await this.dedupStore.mark(eventId, this.tolerance);
|
|
3508
3790
|
}
|
|
3509
3791
|
return event;
|
|
3510
3792
|
}
|
|
3511
3793
|
async dispatch(event) {
|
|
3512
|
-
const typeHandlers = this.handlers.get(event.
|
|
3794
|
+
const typeHandlers = this.handlers.get(event.event_type) || [];
|
|
3513
3795
|
const allHandlers = [...typeHandlers, ...this.anyHandlers];
|
|
3514
3796
|
for (const handler of allHandlers) {
|
|
3515
3797
|
await handler(event);
|
|
@@ -3600,26 +3882,36 @@ exports.ComplianceClient = ComplianceClient;
|
|
|
3600
3882
|
exports.ComplianceError = ComplianceError;
|
|
3601
3883
|
exports.DEFAULT_CURRENCY_RATES = DEFAULT_CURRENCY_RATES;
|
|
3602
3884
|
exports.GeolocationClient = GeolocationClient;
|
|
3885
|
+
exports.InMemoryDedupStore = InMemoryDedupStore;
|
|
3603
3886
|
exports.KYC_DECLINED_DESCRIPTIONS = KYC_DECLINED_DESCRIPTIONS;
|
|
3604
3887
|
exports.KycClient = KycClient;
|
|
3605
3888
|
exports.NetworkError = NetworkError;
|
|
3606
3889
|
exports.RateLimitError = RateLimitError;
|
|
3607
3890
|
exports.RateLimitTracker = RateLimitTracker;
|
|
3891
|
+
exports.RefreshingTokenProvider = RefreshingTokenProvider;
|
|
3608
3892
|
exports.RiskProfileClient = RiskProfileClient;
|
|
3609
3893
|
exports.SDK_VERSION = SDK_VERSION;
|
|
3610
3894
|
exports.ServiceUnavailableError = ServiceUnavailableError;
|
|
3895
|
+
exports.StaticApiKeyProvider = StaticApiKeyProvider;
|
|
3611
3896
|
exports.TaxClient = TaxClient;
|
|
3612
3897
|
exports.TimeoutError = TimeoutError;
|
|
3613
3898
|
exports.ValidationError = ValidationError;
|
|
3614
3899
|
exports.VesantError = VesantError;
|
|
3615
3900
|
exports.WebhookHandler = WebhookHandler;
|
|
3901
|
+
exports.assessGpsIntegrity = assessGpsIntegrity;
|
|
3902
|
+
exports.collectAll = collectAll;
|
|
3903
|
+
exports.collectDeviceSignals = collectDeviceSignals;
|
|
3616
3904
|
exports.createConsoleLogger = createConsoleLogger;
|
|
3617
3905
|
exports.createNextWebhookHandler = createNextWebhookHandler;
|
|
3618
3906
|
exports.createWebhookMiddleware = createWebhookMiddleware;
|
|
3619
3907
|
exports.decodeCipherText = decodeCipherText;
|
|
3620
3908
|
exports.generateCipherText = generateCipherText;
|
|
3909
|
+
exports.gpsIntegrityInputFromPosition = gpsIntegrityInputFromPosition;
|
|
3621
3910
|
exports.isCipherTextExpired = isCipherTextExpired;
|
|
3911
|
+
exports.isKycDocumentExpiredCallbackEvent = isKycDocumentExpiredCallbackEvent;
|
|
3622
3912
|
exports.noopLogger = noopLogger;
|
|
3913
|
+
exports.paginate = paginate;
|
|
3914
|
+
exports.probeGeolocationPermission = probeGeolocationPermission;
|
|
3623
3915
|
exports.sdkReasons = sdkReasons;
|
|
3624
3916
|
exports.verifyWebhookSignature = verifyWebhookSignature;
|
|
3625
3917
|
//# sourceMappingURL=index.js.map
|