@astrasyncai/verification-gateway 2.4.9 → 2.4.11

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.
@@ -3299,7 +3299,7 @@ function getTrustLevel(score) {
3299
3299
  }
3300
3300
 
3301
3301
  // src/version.ts
3302
- var SDK_VERSION = "2.4.9";
3302
+ var SDK_VERSION = "2.4.11";
3303
3303
 
3304
3304
  // src/verify.ts
3305
3305
  var DEFAULT_CONFIG = {
@@ -3310,8 +3310,10 @@ var DEFAULT_CONFIG = {
3310
3310
  // through (`hasMinimumAccess('guidance', 'guidance') === true`).
3311
3311
  defaultAccessLevel: "none",
3312
3312
  // minTrustScore + minTrustScoreForFull deprecated in v2.3.0 — server decides.
3313
- cacheTtl: 300,
3314
- // 5 minutes
3313
+ // Round-18.5 F4: cacheTtl deliberately unset. When undefined, cacheResult
3314
+ // applies the split default (60s autonomous / 300s step-up). When the
3315
+ // caller sets cacheTtl explicitly, that value is honoured uniformly.
3316
+ // Set cacheTtl: 0 to disable caching entirely.
3315
3317
  debug: false
3316
3318
  };
3317
3319
  var initCheckPerformed = false;
@@ -3338,11 +3340,28 @@ async function performInitCheck(apiBaseUrl, debug) {
3338
3340
  }
3339
3341
  }
3340
3342
  var verificationCache = /* @__PURE__ */ new Map();
3341
- function getCacheKey(credentials) {
3342
- return `${credentials.astraId || ""}-${credentials.apiKey || ""}-${credentials.jwt || ""}`;
3343
- }
3344
- function getCachedResult(credentials) {
3345
- const key = getCacheKey(credentials);
3343
+ function getCacheKey(request) {
3344
+ const c = request.credentials;
3345
+ return [
3346
+ c.astraId || "",
3347
+ c.apiKey || "",
3348
+ c.jwt || "",
3349
+ request.purpose || "",
3350
+ request.action || "",
3351
+ request.resourceType || "",
3352
+ request.resource || "",
3353
+ request.jurisdiction || "",
3354
+ request.transactionValue ?? "",
3355
+ request.currency || "",
3356
+ request.counterpartyUrl || "",
3357
+ request.counterpartyType || "",
3358
+ request.isSubAgentRequest ? "1" : "0",
3359
+ request.parentAgentId || "",
3360
+ request.subAgentDepth ?? ""
3361
+ ].join("|");
3362
+ }
3363
+ function getCachedResult(request) {
3364
+ const key = getCacheKey(request);
3346
3365
  const cached = verificationCache.get(key);
3347
3366
  if (cached && cached.expiresAt > Date.now()) {
3348
3367
  return cached.result;
@@ -3352,8 +3371,11 @@ function getCachedResult(credentials) {
3352
3371
  }
3353
3372
  return null;
3354
3373
  }
3355
- function cacheResult(credentials, result, ttlSeconds) {
3356
- const key = getCacheKey(credentials);
3374
+ var DEFAULT_AUTONOMOUS_TTL_SECONDS = 60;
3375
+ var DEFAULT_STEP_UP_TTL_SECONDS = 300;
3376
+ function cacheResult(request, result, configuredTtl) {
3377
+ const ttlSeconds = configuredTtl && configuredTtl > 0 ? configuredTtl : result.requiresStepUp ? DEFAULT_STEP_UP_TTL_SECONDS : DEFAULT_AUTONOMOUS_TTL_SECONDS;
3378
+ const key = getCacheKey(request);
3357
3379
  verificationCache.set(key, {
3358
3380
  result,
3359
3381
  expiresAt: Date.now() + ttlSeconds * 1e3
@@ -3508,8 +3530,8 @@ async function verify(config, request) {
3508
3530
  "[VerificationGateway] minTrustScore / minTrustScoreForFull are deprecated in v2.3.0 and have no effect. Server is now the single source of truth for access-level decisions (the SDK reads access.accessLevel from the verify-access response). To gate access to an endpoint, configure the endpoint's trust_score_requirement server-side."
3509
3531
  );
3510
3532
  }
3511
- if (mergedConfig.cacheTtl && mergedConfig.cacheTtl > 0) {
3512
- const cached = getCachedResult(request.credentials);
3533
+ if (mergedConfig.cacheTtl !== 0) {
3534
+ const cached = getCachedResult(request);
3513
3535
  if (cached) {
3514
3536
  if (mergedConfig.debug) {
3515
3537
  console.log("[VerificationGateway] Returning cached result");
@@ -3638,8 +3660,8 @@ async function verify(config, request) {
3638
3660
  }
3639
3661
  result.denialReasons = result.recommendationReasons || ["Step-up verification required"];
3640
3662
  }
3641
- if (mergedConfig.cacheTtl && mergedConfig.cacheTtl > 0 && result.recommendation !== "deny") {
3642
- cacheResult(request.credentials, result, mergedConfig.cacheTtl);
3663
+ if (mergedConfig.cacheTtl !== 0 && result.recommendation !== "deny") {
3664
+ cacheResult(request, result, mergedConfig.cacheTtl);
3643
3665
  }
3644
3666
  return result;
3645
3667
  }