@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.
@@ -3272,7 +3272,7 @@ function getTrustLevel(score) {
3272
3272
  }
3273
3273
 
3274
3274
  // src/version.ts
3275
- var SDK_VERSION = "2.4.9";
3275
+ var SDK_VERSION = "2.4.11";
3276
3276
 
3277
3277
  // src/verify.ts
3278
3278
  var DEFAULT_CONFIG = {
@@ -3283,8 +3283,10 @@ var DEFAULT_CONFIG = {
3283
3283
  // through (`hasMinimumAccess('guidance', 'guidance') === true`).
3284
3284
  defaultAccessLevel: "none",
3285
3285
  // minTrustScore + minTrustScoreForFull deprecated in v2.3.0 — server decides.
3286
- cacheTtl: 300,
3287
- // 5 minutes
3286
+ // Round-18.5 F4: cacheTtl deliberately unset. When undefined, cacheResult
3287
+ // applies the split default (60s autonomous / 300s step-up). When the
3288
+ // caller sets cacheTtl explicitly, that value is honoured uniformly.
3289
+ // Set cacheTtl: 0 to disable caching entirely.
3288
3290
  debug: false
3289
3291
  };
3290
3292
  var initCheckPerformed = false;
@@ -3311,11 +3313,28 @@ async function performInitCheck(apiBaseUrl, debug) {
3311
3313
  }
3312
3314
  }
3313
3315
  var verificationCache = /* @__PURE__ */ new Map();
3314
- function getCacheKey(credentials) {
3315
- return `${credentials.astraId || ""}-${credentials.apiKey || ""}-${credentials.jwt || ""}`;
3316
- }
3317
- function getCachedResult(credentials) {
3318
- const key = getCacheKey(credentials);
3316
+ function getCacheKey(request) {
3317
+ const c = request.credentials;
3318
+ return [
3319
+ c.astraId || "",
3320
+ c.apiKey || "",
3321
+ c.jwt || "",
3322
+ request.purpose || "",
3323
+ request.action || "",
3324
+ request.resourceType || "",
3325
+ request.resource || "",
3326
+ request.jurisdiction || "",
3327
+ request.transactionValue ?? "",
3328
+ request.currency || "",
3329
+ request.counterpartyUrl || "",
3330
+ request.counterpartyType || "",
3331
+ request.isSubAgentRequest ? "1" : "0",
3332
+ request.parentAgentId || "",
3333
+ request.subAgentDepth ?? ""
3334
+ ].join("|");
3335
+ }
3336
+ function getCachedResult(request) {
3337
+ const key = getCacheKey(request);
3319
3338
  const cached = verificationCache.get(key);
3320
3339
  if (cached && cached.expiresAt > Date.now()) {
3321
3340
  return cached.result;
@@ -3325,8 +3344,11 @@ function getCachedResult(credentials) {
3325
3344
  }
3326
3345
  return null;
3327
3346
  }
3328
- function cacheResult(credentials, result, ttlSeconds) {
3329
- const key = getCacheKey(credentials);
3347
+ var DEFAULT_AUTONOMOUS_TTL_SECONDS = 60;
3348
+ var DEFAULT_STEP_UP_TTL_SECONDS = 300;
3349
+ function cacheResult(request, result, configuredTtl) {
3350
+ const ttlSeconds = configuredTtl && configuredTtl > 0 ? configuredTtl : result.requiresStepUp ? DEFAULT_STEP_UP_TTL_SECONDS : DEFAULT_AUTONOMOUS_TTL_SECONDS;
3351
+ const key = getCacheKey(request);
3330
3352
  verificationCache.set(key, {
3331
3353
  result,
3332
3354
  expiresAt: Date.now() + ttlSeconds * 1e3
@@ -3481,8 +3503,8 @@ async function verify(config, request) {
3481
3503
  "[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."
3482
3504
  );
3483
3505
  }
3484
- if (mergedConfig.cacheTtl && mergedConfig.cacheTtl > 0) {
3485
- const cached = getCachedResult(request.credentials);
3506
+ if (mergedConfig.cacheTtl !== 0) {
3507
+ const cached = getCachedResult(request);
3486
3508
  if (cached) {
3487
3509
  if (mergedConfig.debug) {
3488
3510
  console.log("[VerificationGateway] Returning cached result");
@@ -3611,8 +3633,8 @@ async function verify(config, request) {
3611
3633
  }
3612
3634
  result.denialReasons = result.recommendationReasons || ["Step-up verification required"];
3613
3635
  }
3614
- if (mergedConfig.cacheTtl && mergedConfig.cacheTtl > 0 && result.recommendation !== "deny") {
3615
- cacheResult(request.credentials, result, mergedConfig.cacheTtl);
3636
+ if (mergedConfig.cacheTtl !== 0 && result.recommendation !== "deny") {
3637
+ cacheResult(request, result, mergedConfig.cacheTtl);
3616
3638
  }
3617
3639
  return result;
3618
3640
  }