@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.
@@ -3293,7 +3293,7 @@ function getTrustLevel(score) {
3293
3293
  }
3294
3294
 
3295
3295
  // src/version.ts
3296
- var SDK_VERSION = "2.4.9";
3296
+ var SDK_VERSION = "2.4.11";
3297
3297
 
3298
3298
  // src/verify.ts
3299
3299
  var DEFAULT_CONFIG = {
@@ -3304,8 +3304,10 @@ var DEFAULT_CONFIG = {
3304
3304
  // through (`hasMinimumAccess('guidance', 'guidance') === true`).
3305
3305
  defaultAccessLevel: "none",
3306
3306
  // minTrustScore + minTrustScoreForFull deprecated in v2.3.0 — server decides.
3307
- cacheTtl: 300,
3308
- // 5 minutes
3307
+ // Round-18.5 F4: cacheTtl deliberately unset. When undefined, cacheResult
3308
+ // applies the split default (60s autonomous / 300s step-up). When the
3309
+ // caller sets cacheTtl explicitly, that value is honoured uniformly.
3310
+ // Set cacheTtl: 0 to disable caching entirely.
3309
3311
  debug: false
3310
3312
  };
3311
3313
  var initCheckPerformed = false;
@@ -3332,11 +3334,28 @@ async function performInitCheck(apiBaseUrl, debug) {
3332
3334
  }
3333
3335
  }
3334
3336
  var verificationCache = /* @__PURE__ */ new Map();
3335
- function getCacheKey(credentials) {
3336
- return `${credentials.astraId || ""}-${credentials.apiKey || ""}-${credentials.jwt || ""}`;
3337
- }
3338
- function getCachedResult(credentials) {
3339
- const key = getCacheKey(credentials);
3337
+ function getCacheKey(request) {
3338
+ const c = request.credentials;
3339
+ return [
3340
+ c.astraId || "",
3341
+ c.apiKey || "",
3342
+ c.jwt || "",
3343
+ request.purpose || "",
3344
+ request.action || "",
3345
+ request.resourceType || "",
3346
+ request.resource || "",
3347
+ request.jurisdiction || "",
3348
+ request.transactionValue ?? "",
3349
+ request.currency || "",
3350
+ request.counterpartyUrl || "",
3351
+ request.counterpartyType || "",
3352
+ request.isSubAgentRequest ? "1" : "0",
3353
+ request.parentAgentId || "",
3354
+ request.subAgentDepth ?? ""
3355
+ ].join("|");
3356
+ }
3357
+ function getCachedResult(request) {
3358
+ const key = getCacheKey(request);
3340
3359
  const cached = verificationCache.get(key);
3341
3360
  if (cached && cached.expiresAt > Date.now()) {
3342
3361
  return cached.result;
@@ -3346,8 +3365,11 @@ function getCachedResult(credentials) {
3346
3365
  }
3347
3366
  return null;
3348
3367
  }
3349
- function cacheResult(credentials, result, ttlSeconds) {
3350
- const key = getCacheKey(credentials);
3368
+ var DEFAULT_AUTONOMOUS_TTL_SECONDS = 60;
3369
+ var DEFAULT_STEP_UP_TTL_SECONDS = 300;
3370
+ function cacheResult(request, result, configuredTtl) {
3371
+ const ttlSeconds = configuredTtl && configuredTtl > 0 ? configuredTtl : result.requiresStepUp ? DEFAULT_STEP_UP_TTL_SECONDS : DEFAULT_AUTONOMOUS_TTL_SECONDS;
3372
+ const key = getCacheKey(request);
3351
3373
  verificationCache.set(key, {
3352
3374
  result,
3353
3375
  expiresAt: Date.now() + ttlSeconds * 1e3
@@ -3502,8 +3524,8 @@ async function verify(config, request) {
3502
3524
  "[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."
3503
3525
  );
3504
3526
  }
3505
- if (mergedConfig.cacheTtl && mergedConfig.cacheTtl > 0) {
3506
- const cached = getCachedResult(request.credentials);
3527
+ if (mergedConfig.cacheTtl !== 0) {
3528
+ const cached = getCachedResult(request);
3507
3529
  if (cached) {
3508
3530
  if (mergedConfig.debug) {
3509
3531
  console.log("[VerificationGateway] Returning cached result");
@@ -3632,8 +3654,8 @@ async function verify(config, request) {
3632
3654
  }
3633
3655
  result.denialReasons = result.recommendationReasons || ["Step-up verification required"];
3634
3656
  }
3635
- if (mergedConfig.cacheTtl && mergedConfig.cacheTtl > 0 && result.recommendation !== "deny") {
3636
- cacheResult(request.credentials, result, mergedConfig.cacheTtl);
3657
+ if (mergedConfig.cacheTtl !== 0 && result.recommendation !== "deny") {
3658
+ cacheResult(request, result, mergedConfig.cacheTtl);
3637
3659
  }
3638
3660
  return result;
3639
3661
  }