@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.
@@ -3055,7 +3055,7 @@ function getTrustLevel(score) {
3055
3055
  }
3056
3056
 
3057
3057
  // src/version.ts
3058
- var SDK_VERSION = "2.4.9";
3058
+ var SDK_VERSION = "2.4.11";
3059
3059
 
3060
3060
  // src/verify.ts
3061
3061
  var DEFAULT_CONFIG = {
@@ -3066,8 +3066,10 @@ var DEFAULT_CONFIG = {
3066
3066
  // through (`hasMinimumAccess('guidance', 'guidance') === true`).
3067
3067
  defaultAccessLevel: "none",
3068
3068
  // minTrustScore + minTrustScoreForFull deprecated in v2.3.0 — server decides.
3069
- cacheTtl: 300,
3070
- // 5 minutes
3069
+ // Round-18.5 F4: cacheTtl deliberately unset. When undefined, cacheResult
3070
+ // applies the split default (60s autonomous / 300s step-up). When the
3071
+ // caller sets cacheTtl explicitly, that value is honoured uniformly.
3072
+ // Set cacheTtl: 0 to disable caching entirely.
3071
3073
  debug: false
3072
3074
  };
3073
3075
  var initCheckPerformed = false;
@@ -3094,11 +3096,28 @@ async function performInitCheck(apiBaseUrl, debug) {
3094
3096
  }
3095
3097
  }
3096
3098
  var verificationCache = /* @__PURE__ */ new Map();
3097
- function getCacheKey(credentials) {
3098
- return `${credentials.astraId || ""}-${credentials.apiKey || ""}-${credentials.jwt || ""}`;
3099
- }
3100
- function getCachedResult(credentials) {
3101
- const key = getCacheKey(credentials);
3099
+ function getCacheKey(request) {
3100
+ const c = request.credentials;
3101
+ return [
3102
+ c.astraId || "",
3103
+ c.apiKey || "",
3104
+ c.jwt || "",
3105
+ request.purpose || "",
3106
+ request.action || "",
3107
+ request.resourceType || "",
3108
+ request.resource || "",
3109
+ request.jurisdiction || "",
3110
+ request.transactionValue ?? "",
3111
+ request.currency || "",
3112
+ request.counterpartyUrl || "",
3113
+ request.counterpartyType || "",
3114
+ request.isSubAgentRequest ? "1" : "0",
3115
+ request.parentAgentId || "",
3116
+ request.subAgentDepth ?? ""
3117
+ ].join("|");
3118
+ }
3119
+ function getCachedResult(request) {
3120
+ const key = getCacheKey(request);
3102
3121
  const cached = verificationCache.get(key);
3103
3122
  if (cached && cached.expiresAt > Date.now()) {
3104
3123
  return cached.result;
@@ -3108,8 +3127,11 @@ function getCachedResult(credentials) {
3108
3127
  }
3109
3128
  return null;
3110
3129
  }
3111
- function cacheResult(credentials, result, ttlSeconds) {
3112
- const key = getCacheKey(credentials);
3130
+ var DEFAULT_AUTONOMOUS_TTL_SECONDS = 60;
3131
+ var DEFAULT_STEP_UP_TTL_SECONDS = 300;
3132
+ function cacheResult(request, result, configuredTtl) {
3133
+ const ttlSeconds = configuredTtl && configuredTtl > 0 ? configuredTtl : result.requiresStepUp ? DEFAULT_STEP_UP_TTL_SECONDS : DEFAULT_AUTONOMOUS_TTL_SECONDS;
3134
+ const key = getCacheKey(request);
3113
3135
  verificationCache.set(key, {
3114
3136
  result,
3115
3137
  expiresAt: Date.now() + ttlSeconds * 1e3
@@ -3264,8 +3286,8 @@ async function verify(config, request) {
3264
3286
  "[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."
3265
3287
  );
3266
3288
  }
3267
- if (mergedConfig.cacheTtl && mergedConfig.cacheTtl > 0) {
3268
- const cached = getCachedResult(request.credentials);
3289
+ if (mergedConfig.cacheTtl !== 0) {
3290
+ const cached = getCachedResult(request);
3269
3291
  if (cached) {
3270
3292
  if (mergedConfig.debug) {
3271
3293
  console.log("[VerificationGateway] Returning cached result");
@@ -3394,8 +3416,8 @@ async function verify(config, request) {
3394
3416
  }
3395
3417
  result.denialReasons = result.recommendationReasons || ["Step-up verification required"];
3396
3418
  }
3397
- if (mergedConfig.cacheTtl && mergedConfig.cacheTtl > 0 && result.recommendation !== "deny") {
3398
- cacheResult(request.credentials, result, mergedConfig.cacheTtl);
3419
+ if (mergedConfig.cacheTtl !== 0 && result.recommendation !== "deny") {
3420
+ cacheResult(request, result, mergedConfig.cacheTtl);
3399
3421
  }
3400
3422
  return result;
3401
3423
  }