@astrasyncai/verification-gateway 2.4.8 → 2.4.10

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.
Files changed (89) hide show
  1. package/dist/adapter-interface/interface.d.mts +2 -2
  2. package/dist/adapter-interface/interface.d.ts +2 -2
  3. package/dist/adapters/express.d.mts +2 -2
  4. package/dist/adapters/express.d.ts +2 -2
  5. package/dist/adapters/express.js +81 -31
  6. package/dist/adapters/express.js.map +1 -1
  7. package/dist/adapters/express.mjs +81 -31
  8. package/dist/adapters/express.mjs.map +1 -1
  9. package/dist/adapters/mcp.d.mts +1 -1
  10. package/dist/adapters/mcp.d.ts +1 -1
  11. package/dist/adapters/mcp.js +64 -26
  12. package/dist/adapters/mcp.js.map +1 -1
  13. package/dist/adapters/mcp.mjs +64 -26
  14. package/dist/adapters/mcp.mjs.map +1 -1
  15. package/dist/adapters/nextjs.d.mts +2 -2
  16. package/dist/adapters/nextjs.d.ts +2 -2
  17. package/dist/adapters/nextjs.js +89 -32
  18. package/dist/adapters/nextjs.js.map +1 -1
  19. package/dist/adapters/nextjs.mjs +89 -32
  20. package/dist/adapters/nextjs.mjs.map +1 -1
  21. package/dist/adapters/sdk.d.mts +2 -2
  22. package/dist/adapters/sdk.d.ts +2 -2
  23. package/dist/adapters/sdk.js +65 -25
  24. package/dist/adapters/sdk.js.map +1 -1
  25. package/dist/adapters/sdk.mjs +65 -25
  26. package/dist/adapters/sdk.mjs.map +1 -1
  27. package/dist/agent/index.d.mts +2 -2
  28. package/dist/agent/index.d.ts +2 -2
  29. package/dist/browser/background.js +60 -25
  30. package/dist/browser/background.js.map +1 -1
  31. package/dist/browser/background.mjs +60 -25
  32. package/dist/browser/background.mjs.map +1 -1
  33. package/dist/browser/browser-adapter.d.mts +2 -2
  34. package/dist/browser/browser-adapter.d.ts +2 -2
  35. package/dist/cli/index.d.mts +2 -2
  36. package/dist/cli/index.d.ts +2 -2
  37. package/dist/cursor/cursor-adapter.d.mts +2 -2
  38. package/dist/cursor/cursor-adapter.d.ts +2 -2
  39. package/dist/cursor/extension.d.mts +2 -2
  40. package/dist/cursor/extension.d.ts +2 -2
  41. package/dist/cursor/extension.js +60 -25
  42. package/dist/cursor/extension.js.map +1 -1
  43. package/dist/cursor/extension.mjs +60 -25
  44. package/dist/cursor/extension.mjs.map +1 -1
  45. package/dist/{express-DvVjR2H4.d.mts → express-4WStX3PV.d.mts} +1 -1
  46. package/dist/{express-714gJbaW.d.ts → express-C1ePFB7n.d.ts} +1 -1
  47. package/dist/gateway/gateway.d.mts +2 -2
  48. package/dist/gateway/gateway.d.ts +2 -2
  49. package/dist/gateway/gateway.js +60 -25
  50. package/dist/gateway/gateway.js.map +1 -1
  51. package/dist/gateway/gateway.mjs +60 -25
  52. package/dist/gateway/gateway.mjs.map +1 -1
  53. package/dist/git-trigger/git-hooks.d.mts +2 -2
  54. package/dist/git-trigger/git-hooks.d.ts +2 -2
  55. package/dist/{index-DYFS9QVb.d.mts → index-ChPX4WHl.d.mts} +1 -1
  56. package/dist/{index-DO0oG8ED.d.ts → index-Cjm-zBeZ.d.ts} +1 -1
  57. package/dist/{index-2WAlxs2G.d.ts → index-CzJMCgEy.d.ts} +1 -1
  58. package/dist/{index-P9t7M_dJ.d.mts → index-D8IEntil.d.mts} +1 -1
  59. package/dist/index.d.mts +22 -11
  60. package/dist/index.d.ts +22 -11
  61. package/dist/index.js +133 -42
  62. package/dist/index.js.map +1 -1
  63. package/dist/index.mjs +132 -42
  64. package/dist/index.mjs.map +1 -1
  65. package/dist/local-evaluator/evaluator.d.mts +2 -2
  66. package/dist/local-evaluator/evaluator.d.ts +2 -2
  67. package/dist/{nextjs-CZ-MwSOT.d.ts → nextjs-BIORS__0.d.ts} +1 -1
  68. package/dist/{nextjs-BCoH7EqF.d.mts → nextjs-CjzHdaXA.d.mts} +1 -1
  69. package/dist/registration/index.d.mts +76 -1
  70. package/dist/registration/index.d.ts +76 -1
  71. package/dist/registration/index.js +27 -2
  72. package/dist/registration/index.js.map +1 -1
  73. package/dist/registration/index.mjs +25 -1
  74. package/dist/registration/index.mjs.map +1 -1
  75. package/dist/{sdk-wwhFDXWX.d.mts → sdk-Chhz-FcT.d.mts} +9 -4
  76. package/dist/{sdk-kiA49vqJ.d.ts → sdk-CqTEQAc6.d.ts} +9 -4
  77. package/dist/transport/index.d.mts +2 -2
  78. package/dist/transport/index.d.ts +2 -2
  79. package/dist/{types-DOAb89cm.d.mts → types-DNK2BgIf.d.mts} +1 -1
  80. package/dist/{types-aucqzfUa.d.ts → types-DoWIuzfj.d.ts} +1 -1
  81. package/dist/{types-BwDmjIdr.d.mts → types-L15pYd2c.d.mts} +21 -4
  82. package/dist/{types-BwDmjIdr.d.ts → types-L15pYd2c.d.ts} +21 -4
  83. package/dist/ui/index.d.mts +1 -1
  84. package/dist/ui/index.d.ts +1 -1
  85. package/dist/ui/index.js +1 -1
  86. package/dist/ui/index.js.map +1 -1
  87. package/dist/ui/index.mjs +1 -1
  88. package/dist/ui/index.mjs.map +1 -1
  89. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  import { AstraSyncGateway } from '../gateway/gateway.mjs';
2
- import { V as VerificationDecision, P as PDLSSContext } from '../types-DOAb89cm.mjs';
3
- import '../types-BwDmjIdr.mjs';
2
+ import { V as VerificationDecision, P as PDLSSContext } from '../types-DNK2BgIf.mjs';
3
+ import '../types-L15pYd2c.mjs';
4
4
 
5
5
  /**
6
6
  * Git Trigger — Enterprise git push / PR verification
@@ -1,6 +1,6 @@
1
1
  import { AstraSyncGateway } from '../gateway/gateway.js';
2
- import { V as VerificationDecision, P as PDLSSContext } from '../types-aucqzfUa.js';
3
- import '../types-BwDmjIdr.js';
2
+ import { V as VerificationDecision, P as PDLSSContext } from '../types-DoWIuzfj.js';
3
+ import '../types-L15pYd2c.js';
4
4
 
5
5
  /**
6
6
  * Git Trigger — Enterprise git push / PR verification
@@ -1,4 +1,4 @@
1
- import { b as AstraSyncCredentials, f as ProtocolTransport, G as GatewayConfig } from './types-BwDmjIdr.mjs';
1
+ import { b as AstraSyncCredentials, f as ProtocolTransport, G as GatewayConfig } from './types-L15pYd2c.mjs';
2
2
 
3
3
  /**
4
4
  * AgentClient — Credential Presentation
@@ -1,4 +1,4 @@
1
- import { b as AstraSyncCredentials, f as ProtocolTransport, G as GatewayConfig } from './types-BwDmjIdr.js';
1
+ import { b as AstraSyncCredentials, f as ProtocolTransport, G as GatewayConfig } from './types-L15pYd2c.js';
2
2
 
3
3
  /**
4
4
  * AgentClient — Credential Presentation
@@ -1,4 +1,4 @@
1
- import { b as AstraSyncCredentials, f as ProtocolTransport } from './types-BwDmjIdr.js';
1
+ import { b as AstraSyncCredentials, f as ProtocolTransport } from './types-L15pYd2c.js';
2
2
  import { JWK } from 'jose';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { b as AstraSyncCredentials, f as ProtocolTransport } from './types-BwDmjIdr.mjs';
1
+ import { b as AstraSyncCredentials, f as ProtocolTransport } from './types-L15pYd2c.mjs';
2
2
  import { JWK } from 'jose';
3
3
 
4
4
  /**
package/dist/index.d.mts CHANGED
@@ -1,12 +1,12 @@
1
- import { a as AgentCredentials, G as GatewayConfig, A as AccessLevel, V as VerificationRequest, i as VerificationResult } from './types-BwDmjIdr.mjs';
2
- export { b as AstraSyncCredentials, C as CommerceShieldProps, c as CounterpartyType, E as EnhancedVerificationResult, d as ExpressMiddlewareOptions, e as GuidanceInfo, N as NextJsMiddlewareOptions, P as PDLSSInfo, f as ProtocolTransport, R as RouteAccessConfig, g as RuntimeChallengeResult, S as SDKOptions, T as TokenGuidance, h as TrustLevel, j as VerifiedAgent, k as VerifiedDeveloper, l as VerifiedOrganization } from './types-BwDmjIdr.mjs';
3
- export { A as ACCESS_LEVEL_DESCRIPTIONS, a as ACCESS_LEVEL_HIERARCHY, b as AccessCapabilities, D as DEFAULT_TRUST_THRESHOLDS, T as TRUST_LEVEL_RANGES, d as determineAccessLevel, g as getAccessLevelForScore, e as getCapabilities, f as getTrustLevel, h as hasMinimumAccess, s as sdk } from './sdk-wwhFDXWX.mjs';
4
- export { e as express } from './express-DvVjR2H4.mjs';
5
- export { n as nextjs } from './nextjs-BCoH7EqF.mjs';
6
- export { aR as extractMcpCredentials, bg as setMcpMeta, b1 as transport } from './index-P9t7M_dJ.mjs';
1
+ import { a as AgentCredentials, G as GatewayConfig, A as AccessLevel, V as VerificationRequest, i as VerificationResult } from './types-L15pYd2c.mjs';
2
+ export { b as AstraSyncCredentials, C as CommerceShieldProps, c as CounterpartyType, E as EnhancedVerificationResult, d as ExpressMiddlewareOptions, e as GuidanceInfo, N as NextJsMiddlewareOptions, P as PDLSSInfo, f as ProtocolTransport, R as RouteAccessConfig, g as RuntimeChallengeResult, S as SDKOptions, T as TokenGuidance, h as TrustLevel, j as VerifiedAgent, k as VerifiedDeveloper, l as VerifiedOrganization } from './types-L15pYd2c.mjs';
3
+ export { A as ACCESS_LEVEL_DESCRIPTIONS, a as ACCESS_LEVEL_HIERARCHY, b as AccessCapabilities, D as DEFAULT_TRUST_THRESHOLDS, T as TRUST_LEVEL_RANGES, d as determineAccessLevel, g as getAccessLevelForScore, e as getCapabilities, f as getTrustLevel, h as hasMinimumAccess, s as sdk } from './sdk-Chhz-FcT.mjs';
4
+ export { e as express } from './express-4WStX3PV.mjs';
5
+ export { n as nextjs } from './nextjs-CjzHdaXA.mjs';
6
+ export { aR as extractMcpCredentials, bg as setMcpMeta, b1 as transport } from './index-D8IEntil.mjs';
7
7
  export { McpMiddlewareOptions, createMcpMiddleware } from './adapters/mcp.mjs';
8
- export { AgentProtocol, AgentRecord, AstraSync, AstraSyncConfig, AstraSyncError, AuthenticationError, FrameworkConfig, HealthResponse, KYDRequiredError, ModelConfig, PDLSSConfig, PDLSSDuration, PDLSSLimits, PDLSSPurpose, PDLSSScope, PDLSSSelfInstantiation, PendingRegistrationResponse, PollRegistrationResult, RegisterOptions, RegisterResult, RegistrationDeniedError, RegistrationExpiredError, RegistrationResponse, RegistrationTimeoutError, VerifyResponse, WaitForApprovalOptions } from './registration/index.mjs';
9
- export { A as AgentClient, C as ChallengeHandler, i as agent, r as recordDecision } from './index-DYFS9QVb.mjs';
8
+ export { AgentProtocol, AgentRecord, AstraSync, AstraSyncConfig, AstraSyncError, AuthenticationError, BuildGuidanceParams, FrameworkConfig, GuidanceEnvelope, HealthResponse, KYDRequiredError, ModelConfig, PDLSSConfig, PDLSSDuration, PDLSSLimits, PDLSSPurpose, PDLSSScope, PDLSSSelfInstantiation, PendingRegistrationResponse, PollRegistrationResult, RegisterOptions, RegisterResult, RegistrationDeniedError, RegistrationExpiredError, RegistrationResponse, RegistrationTimeoutError, VerifyResponse, WaitForApprovalOptions, buildGuidance } from './registration/index.mjs';
9
+ export { A as AgentClient, C as ChallengeHandler, i as agent, r as recordDecision } from './index-ChPX4WHl.mjs';
10
10
  import 'express';
11
11
  import 'next/server';
12
12
  import 'jose';
@@ -35,10 +35,17 @@ declare function hasCredentials(credentials: AgentCredentials): boolean;
35
35
  */
36
36
  declare function verify(config: GatewayConfig, request: VerificationRequest): Promise<VerificationResult>;
37
37
  /**
38
- * Quick verification - just check if credentials are valid
38
+ * Quick verification checks credentials and policy in one call.
39
+ *
40
+ * Round-18 G4: return shape mirrors `VerificationResult`'s split — partners
41
+ * writing custom handlers around `quickVerify` get the same identity/policy
42
+ * distinction as those calling `verify()` directly. Map to HTTP status the
43
+ * same way: `!identityVerified` → 401; `identityVerified && !policyAllowed`
44
+ * → 403.
39
45
  */
40
46
  declare function quickVerify(config: GatewayConfig, credentials: AgentCredentials): Promise<{
41
- verified: boolean;
47
+ identityVerified: boolean;
48
+ policyAllowed: boolean;
42
49
  accessLevel: AccessLevel;
43
50
  reason?: string;
44
51
  }>;
@@ -56,9 +63,13 @@ declare function quickVerify(config: GatewayConfig, credentials: AgentCredential
56
63
  * const credentials = extractCredentials(request.headers);
57
64
  * const result = await verify(config, { credentials, purpose: 'data-access' });
58
65
  *
59
- * if (result.verified && result.accessLevel !== 'none') {
66
+ * if (result.identityVerified && result.policyAllowed && result.accessLevel !== 'none') {
60
67
  * // Grant access based on result.accessLevel
61
68
  * }
69
+ *
70
+ * // Or map to HTTP status codes directly:
71
+ * if (!result.identityVerified) return res.status(401).json({ ... }); // re-auth
72
+ * if (!result.policyAllowed) return res.status(403).json({ ... }); // step up / update PDLSS
62
73
  * ```
63
74
  *
64
75
  * @packageDocumentation
package/dist/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- import { a as AgentCredentials, G as GatewayConfig, A as AccessLevel, V as VerificationRequest, i as VerificationResult } from './types-BwDmjIdr.js';
2
- export { b as AstraSyncCredentials, C as CommerceShieldProps, c as CounterpartyType, E as EnhancedVerificationResult, d as ExpressMiddlewareOptions, e as GuidanceInfo, N as NextJsMiddlewareOptions, P as PDLSSInfo, f as ProtocolTransport, R as RouteAccessConfig, g as RuntimeChallengeResult, S as SDKOptions, T as TokenGuidance, h as TrustLevel, j as VerifiedAgent, k as VerifiedDeveloper, l as VerifiedOrganization } from './types-BwDmjIdr.js';
3
- export { A as ACCESS_LEVEL_DESCRIPTIONS, a as ACCESS_LEVEL_HIERARCHY, b as AccessCapabilities, D as DEFAULT_TRUST_THRESHOLDS, T as TRUST_LEVEL_RANGES, d as determineAccessLevel, g as getAccessLevelForScore, e as getCapabilities, f as getTrustLevel, h as hasMinimumAccess, s as sdk } from './sdk-kiA49vqJ.js';
4
- export { e as express } from './express-714gJbaW.js';
5
- export { n as nextjs } from './nextjs-CZ-MwSOT.js';
6
- export { aR as extractMcpCredentials, bg as setMcpMeta, b1 as transport } from './index-2WAlxs2G.js';
1
+ import { a as AgentCredentials, G as GatewayConfig, A as AccessLevel, V as VerificationRequest, i as VerificationResult } from './types-L15pYd2c.js';
2
+ export { b as AstraSyncCredentials, C as CommerceShieldProps, c as CounterpartyType, E as EnhancedVerificationResult, d as ExpressMiddlewareOptions, e as GuidanceInfo, N as NextJsMiddlewareOptions, P as PDLSSInfo, f as ProtocolTransport, R as RouteAccessConfig, g as RuntimeChallengeResult, S as SDKOptions, T as TokenGuidance, h as TrustLevel, j as VerifiedAgent, k as VerifiedDeveloper, l as VerifiedOrganization } from './types-L15pYd2c.js';
3
+ export { A as ACCESS_LEVEL_DESCRIPTIONS, a as ACCESS_LEVEL_HIERARCHY, b as AccessCapabilities, D as DEFAULT_TRUST_THRESHOLDS, T as TRUST_LEVEL_RANGES, d as determineAccessLevel, g as getAccessLevelForScore, e as getCapabilities, f as getTrustLevel, h as hasMinimumAccess, s as sdk } from './sdk-CqTEQAc6.js';
4
+ export { e as express } from './express-C1ePFB7n.js';
5
+ export { n as nextjs } from './nextjs-BIORS__0.js';
6
+ export { aR as extractMcpCredentials, bg as setMcpMeta, b1 as transport } from './index-CzJMCgEy.js';
7
7
  export { McpMiddlewareOptions, createMcpMiddleware } from './adapters/mcp.js';
8
- export { AgentProtocol, AgentRecord, AstraSync, AstraSyncConfig, AstraSyncError, AuthenticationError, FrameworkConfig, HealthResponse, KYDRequiredError, ModelConfig, PDLSSConfig, PDLSSDuration, PDLSSLimits, PDLSSPurpose, PDLSSScope, PDLSSSelfInstantiation, PendingRegistrationResponse, PollRegistrationResult, RegisterOptions, RegisterResult, RegistrationDeniedError, RegistrationExpiredError, RegistrationResponse, RegistrationTimeoutError, VerifyResponse, WaitForApprovalOptions } from './registration/index.js';
9
- export { A as AgentClient, C as ChallengeHandler, i as agent, r as recordDecision } from './index-DO0oG8ED.js';
8
+ export { AgentProtocol, AgentRecord, AstraSync, AstraSyncConfig, AstraSyncError, AuthenticationError, BuildGuidanceParams, FrameworkConfig, GuidanceEnvelope, HealthResponse, KYDRequiredError, ModelConfig, PDLSSConfig, PDLSSDuration, PDLSSLimits, PDLSSPurpose, PDLSSScope, PDLSSSelfInstantiation, PendingRegistrationResponse, PollRegistrationResult, RegisterOptions, RegisterResult, RegistrationDeniedError, RegistrationExpiredError, RegistrationResponse, RegistrationTimeoutError, VerifyResponse, WaitForApprovalOptions, buildGuidance } from './registration/index.js';
9
+ export { A as AgentClient, C as ChallengeHandler, i as agent, r as recordDecision } from './index-Cjm-zBeZ.js';
10
10
  import 'express';
11
11
  import 'next/server';
12
12
  import 'jose';
@@ -35,10 +35,17 @@ declare function hasCredentials(credentials: AgentCredentials): boolean;
35
35
  */
36
36
  declare function verify(config: GatewayConfig, request: VerificationRequest): Promise<VerificationResult>;
37
37
  /**
38
- * Quick verification - just check if credentials are valid
38
+ * Quick verification checks credentials and policy in one call.
39
+ *
40
+ * Round-18 G4: return shape mirrors `VerificationResult`'s split — partners
41
+ * writing custom handlers around `quickVerify` get the same identity/policy
42
+ * distinction as those calling `verify()` directly. Map to HTTP status the
43
+ * same way: `!identityVerified` → 401; `identityVerified && !policyAllowed`
44
+ * → 403.
39
45
  */
40
46
  declare function quickVerify(config: GatewayConfig, credentials: AgentCredentials): Promise<{
41
- verified: boolean;
47
+ identityVerified: boolean;
48
+ policyAllowed: boolean;
42
49
  accessLevel: AccessLevel;
43
50
  reason?: string;
44
51
  }>;
@@ -56,9 +63,13 @@ declare function quickVerify(config: GatewayConfig, credentials: AgentCredential
56
63
  * const credentials = extractCredentials(request.headers);
57
64
  * const result = await verify(config, { credentials, purpose: 'data-access' });
58
65
  *
59
- * if (result.verified && result.accessLevel !== 'none') {
66
+ * if (result.identityVerified && result.policyAllowed && result.accessLevel !== 'none') {
60
67
  * // Grant access based on result.accessLevel
61
68
  * }
69
+ *
70
+ * // Or map to HTTP status codes directly:
71
+ * if (!result.identityVerified) return res.status(401).json({ ... }); // re-auth
72
+ * if (!result.policyAllowed) return res.status(403).json({ ... }); // step up / update PDLSS
62
73
  * ```
63
74
  *
64
75
  * @packageDocumentation
package/dist/index.js CHANGED
@@ -45,6 +45,7 @@ __export(src_exports, {
45
45
  TRUST_LEVEL_RANGES: () => TRUST_LEVEL_RANGES,
46
46
  VERSION: () => VERSION,
47
47
  agent: () => agent_exports,
48
+ buildGuidance: () => buildGuidance,
48
49
  clearCache: () => clearCache,
49
50
  createMcpMiddleware: () => createMcpMiddleware,
50
51
  determineAccessLevel: () => determineAccessLevel,
@@ -188,7 +189,7 @@ function getCapabilities(accessLevel) {
188
189
  }
189
190
 
190
191
  // src/version.ts
191
- var SDK_VERSION = "2.4.7";
192
+ var SDK_VERSION = "2.4.10";
192
193
 
193
194
  // src/verify.ts
194
195
  var DEFAULT_CONFIG = {
@@ -199,8 +200,10 @@ var DEFAULT_CONFIG = {
199
200
  // through (`hasMinimumAccess('guidance', 'guidance') === true`).
200
201
  defaultAccessLevel: "none",
201
202
  // minTrustScore + minTrustScoreForFull deprecated in v2.3.0 — server decides.
202
- cacheTtl: 300,
203
- // 5 minutes
203
+ // Round-18.5 F4: cacheTtl deliberately unset. When undefined, cacheResult
204
+ // applies the split default (60s autonomous / 300s step-up). When the
205
+ // caller sets cacheTtl explicitly, that value is honoured uniformly.
206
+ // Set cacheTtl: 0 to disable caching entirely.
204
207
  debug: false
205
208
  };
206
209
  var initCheckPerformed = false;
@@ -227,11 +230,28 @@ async function performInitCheck(apiBaseUrl, debug) {
227
230
  }
228
231
  }
229
232
  var verificationCache = /* @__PURE__ */ new Map();
230
- function getCacheKey(credentials) {
231
- return `${credentials.astraId || ""}-${credentials.apiKey || ""}-${credentials.jwt || ""}`;
232
- }
233
- function getCachedResult(credentials) {
234
- const key = getCacheKey(credentials);
233
+ function getCacheKey(request) {
234
+ const c = request.credentials;
235
+ return [
236
+ c.astraId || "",
237
+ c.apiKey || "",
238
+ c.jwt || "",
239
+ request.purpose || "",
240
+ request.action || "",
241
+ request.resourceType || "",
242
+ request.resource || "",
243
+ request.jurisdiction || "",
244
+ request.transactionValue ?? "",
245
+ request.currency || "",
246
+ request.counterpartyUrl || "",
247
+ request.counterpartyType || "",
248
+ request.isSubAgentRequest ? "1" : "0",
249
+ request.parentAgentId || "",
250
+ request.subAgentDepth ?? ""
251
+ ].join("|");
252
+ }
253
+ function getCachedResult(request) {
254
+ const key = getCacheKey(request);
235
255
  const cached = verificationCache.get(key);
236
256
  if (cached && cached.expiresAt > Date.now()) {
237
257
  return cached.result;
@@ -241,8 +261,11 @@ function getCachedResult(credentials) {
241
261
  }
242
262
  return null;
243
263
  }
244
- function cacheResult(credentials, result, ttlSeconds) {
245
- const key = getCacheKey(credentials);
264
+ var DEFAULT_AUTONOMOUS_TTL_SECONDS = 60;
265
+ var DEFAULT_STEP_UP_TTL_SECONDS = 300;
266
+ function cacheResult(request, result, configuredTtl) {
267
+ const ttlSeconds = configuredTtl && configuredTtl > 0 ? configuredTtl : result.requiresStepUp ? DEFAULT_STEP_UP_TTL_SECONDS : DEFAULT_AUTONOMOUS_TTL_SECONDS;
268
+ const key = getCacheKey(request);
246
269
  verificationCache.set(key, {
247
270
  result,
248
271
  expiresAt: Date.now() + ttlSeconds * 1e3
@@ -305,12 +328,17 @@ function createGuidanceResponse(config, reason, options = {}) {
305
328
  ]
306
329
  };
307
330
  return {
308
- verified: false,
331
+ // Round-18 G4: createGuidanceResponse fires for unverified-agent path or
332
+ // API-error fallback. Identity is not verified (no agent resolved);
333
+ // policy is not evaluated (we never reached the gate).
334
+ identityVerified: false,
335
+ policyAllowed: false,
309
336
  // v2.3.9 (defect #30): denials grant `'none'`, NEVER a positive band.
310
- // Adapters additionally short-circuit on `verified === false` before
311
- // the gate check, but the access level still has to be honest at the
312
- // data layer so downstream consumers (SDK adapters in other languages,
313
- // custom integrations) inherit the correct semantics.
337
+ // Adapters additionally short-circuit on `!identityVerified ||
338
+ // !policyAllowed` before the gate check, but the access level still has
339
+ // to be honest at the data layer so downstream consumers (SDK adapters
340
+ // in other languages, custom integrations) inherit the correct
341
+ // semantics.
314
342
  accessLevel: "none",
315
343
  guidance,
316
344
  denialReasons: reason ? [reason] : ["No valid agent credentials provided"],
@@ -426,8 +454,8 @@ async function verify(config, request) {
426
454
  "[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."
427
455
  );
428
456
  }
429
- if (mergedConfig.cacheTtl && mergedConfig.cacheTtl > 0) {
430
- const cached = getCachedResult(request.credentials);
457
+ if (mergedConfig.cacheTtl !== 0) {
458
+ const cached = getCachedResult(request);
431
459
  if (cached) {
432
460
  if (mergedConfig.debug) {
433
461
  console.log("[VerificationGateway] Returning cached result");
@@ -454,15 +482,17 @@ async function verify(config, request) {
454
482
  }
455
483
  if (!apiResponse.access?.allowed) {
456
484
  const aggregatedFailures = apiResponse.access?.failures;
485
+ const idVerifiedFromBackend = apiResponse.verificationContext?.idVerified === true;
457
486
  const result2 = {
458
- verified: false,
487
+ identityVerified: idVerifiedFromBackend,
488
+ policyAllowed: false,
459
489
  // v2.3.9 (defect #30): denials grant `'none'`, NEVER a positive band.
460
490
  // Pre-rename this hardcoded `'guidance'`, which conflated with the
461
491
  // colocated `guidance: {...}` help-payload object below and let
462
492
  // denied requests pass any route gated at `'guidance'` because
463
493
  // `hasMinimumAccess('guidance', 'guidance') === true`. Adapters now
464
- // ALSO short-circuit on `verified === false` before the gate check —
465
- // belt-and-braces.
494
+ // ALSO short-circuit on `!identityVerified || !policyAllowed` before
495
+ // the gate check — belt-and-braces.
466
496
  accessLevel: "none",
467
497
  denialReasons: aggregatedFailures && aggregatedFailures.length > 0 ? aggregatedFailures.map((f) => f.message) : apiResponse.access?.reason ? [apiResponse.access.reason] : ["Access denied"],
468
498
  failures: aggregatedFailures,
@@ -506,7 +536,13 @@ async function verify(config, request) {
506
536
  const verificationContext = apiResponse.verificationContext;
507
537
  const accessLevel = apiResponse.access?.accessLevel ?? "standard";
508
538
  const result = {
509
- verified: true,
539
+ // Round-18 G4: backend allowed access. Identity is verified (we resolved
540
+ // the caller to an agent) and policy passed all gates. Read idVerified
541
+ // from verificationContext for symmetry with the deny branch; default true
542
+ // on success path since `access.allowed === true` implies identity was
543
+ // resolvable (anonymous-allow paths flow through createGuidanceResponse).
544
+ identityVerified: apiResponse.verificationContext?.idVerified !== false,
545
+ policyAllowed: true,
510
546
  accessLevel,
511
547
  agent,
512
548
  developer,
@@ -529,7 +565,7 @@ async function verify(config, request) {
529
565
  warningHeader: apiResponse.warningHeader
530
566
  };
531
567
  if (result.recommendation === "deny") {
532
- result.verified = false;
568
+ result.policyAllowed = false;
533
569
  result.accessLevel = "none";
534
570
  result.denialReasons = result.recommendationReasons || [
535
571
  "Access denied by AstraSync recommendation"
@@ -548,8 +584,8 @@ async function verify(config, request) {
548
584
  }
549
585
  result.denialReasons = result.recommendationReasons || ["Step-up verification required"];
550
586
  }
551
- if (mergedConfig.cacheTtl && mergedConfig.cacheTtl > 0 && result.recommendation !== "deny") {
552
- cacheResult(request.credentials, result, mergedConfig.cacheTtl);
587
+ if (mergedConfig.cacheTtl !== 0 && result.recommendation !== "deny") {
588
+ cacheResult(request, result, mergedConfig.cacheTtl);
553
589
  }
554
590
  return result;
555
591
  }
@@ -629,7 +665,8 @@ async function quickVerify(config, credentials) {
629
665
  purpose: "verification"
630
666
  });
631
667
  return {
632
- verified: result.verified,
668
+ identityVerified: result.identityVerified,
669
+ policyAllowed: result.policyAllowed,
633
670
  accessLevel: result.accessLevel,
634
671
  reason: result.denialReasons?.[0]
635
672
  };
@@ -705,8 +742,15 @@ function extractHttpCredentials(headers) {
705
742
  // src/pdlss-pre-check.ts
706
743
  function performCounterpartyPreCheck(routeConfig, astraCreds, purpose) {
707
744
  const failures = [];
708
- if (routeConfig.allowedPurposes && routeConfig.allowedPurposes.length > 0 && purpose) {
709
- if (!routeConfig.allowedPurposes.includes(purpose)) {
745
+ if (purpose) {
746
+ if (!routeConfig.allowedPurposes || routeConfig.allowedPurposes.length === 0) {
747
+ failures.push({
748
+ field: "purpose",
749
+ requested: purpose,
750
+ limit: [],
751
+ message: `Purpose "${purpose}" not allowed: route declares no allowedPurposes. The endpoint owner must enumerate allowedPurposes on the route config to authorise specific purposes.`
752
+ });
753
+ } else if (!routeConfig.allowedPurposes.includes(purpose)) {
710
754
  failures.push({
711
755
  field: "purpose",
712
756
  requested: purpose,
@@ -736,9 +780,16 @@ function performCounterpartyPreCheck(routeConfig, astraCreds, purpose) {
736
780
  });
737
781
  }
738
782
  }
739
- if (routeConfig.allowedJurisdictions && routeConfig.allowedJurisdictions.length > 0 && astraCreds?.pdlss?.scope?.jurisdiction) {
783
+ if (astraCreds?.pdlss?.scope?.jurisdiction) {
740
784
  const requested = astraCreds.pdlss.scope.jurisdiction;
741
- if (!routeConfig.allowedJurisdictions.includes(requested)) {
785
+ if (!routeConfig.allowedJurisdictions || routeConfig.allowedJurisdictions.length === 0) {
786
+ failures.push({
787
+ field: "jurisdiction",
788
+ requested,
789
+ limit: [],
790
+ message: `Jurisdiction "${requested}" not allowed: route declares no allowedJurisdictions. The endpoint owner must enumerate allowedJurisdictions on the route config to authorise specific jurisdictions.`
791
+ });
792
+ } else if (!routeConfig.allowedJurisdictions.includes(requested)) {
742
793
  failures.push({
743
794
  field: "jurisdiction",
744
795
  requested,
@@ -801,12 +852,12 @@ function findRouteConfig(routes, path, method) {
801
852
  });
802
853
  }
803
854
  function defaultOnDenied(result, _req, res) {
804
- const statusCode = result.verified ? 403 : 401;
855
+ const statusCode = !result.identityVerified ? 401 : 403;
805
856
  res.setHeader("X-Astra-Gateway-Mode", "enforced");
806
857
  res.status(statusCode).json({
807
858
  success: false,
808
859
  error: {
809
- code: result.verified ? "INSUFFICIENT_ACCESS" : "UNAUTHORIZED",
860
+ code: !result.identityVerified ? "UNAUTHORIZED" : "INSUFFICIENT_ACCESS",
810
861
  message: result.denialReasons?.[0] || "Access denied",
811
862
  accessLevel: result.accessLevel,
812
863
  guidance: result.guidance,
@@ -900,7 +951,8 @@ function createMiddleware(options) {
900
951
  const preCheckFailures = performCounterpartyPreCheck(routeConfig, astraCreds, purpose);
901
952
  if (preCheckFailures.length > 0) {
902
953
  const result2 = {
903
- verified: false,
954
+ identityVerified: false,
955
+ policyAllowed: false,
904
956
  accessLevel: "none",
905
957
  denialReasons: preCheckFailures.map((f) => f.message),
906
958
  guidance: {
@@ -949,7 +1001,7 @@ function createMiddleware(options) {
949
1001
  });
950
1002
  req.agentVerification = result;
951
1003
  const sessionId = result.sessionId;
952
- if (!result.verified) {
1004
+ if (!result.identityVerified || !result.policyAllowed) {
953
1005
  if (shouldRecordDecisions && sessionId) {
954
1006
  recordDecision(config, sessionId, "denied", result.denialReasons?.[0]).catch(() => {
955
1007
  });
@@ -1300,7 +1352,8 @@ function createMiddleware2(options) {
1300
1352
  const preCheckFailures = performCounterpartyPreCheck(routeConfig, astraCreds, purpose);
1301
1353
  if (preCheckFailures.length > 0) {
1302
1354
  const preCheckResult = {
1303
- verified: false,
1355
+ identityVerified: false,
1356
+ policyAllowed: false,
1304
1357
  accessLevel: "none",
1305
1358
  denialReasons: preCheckFailures.map((f) => f.message),
1306
1359
  guidance: {
@@ -1363,20 +1416,22 @@ function createMiddleware2(options) {
1363
1416
  agentCardUrl: request.headers.get("x-astrasync-agent-card") || void 0
1364
1417
  }
1365
1418
  });
1366
- if (!result.verified || !hasMinimumAccess(result.accessLevel, routeConfig.minAccessLevel)) {
1419
+ if (!result.identityVerified || !result.policyAllowed || !hasMinimumAccess(result.accessLevel, routeConfig.minAccessLevel)) {
1367
1420
  if (pathname.startsWith("/api/")) {
1368
1421
  return NextResponse.json(
1369
1422
  {
1370
1423
  success: false,
1371
1424
  error: {
1372
- code: result.verified ? "INSUFFICIENT_ACCESS" : "UNAUTHORIZED",
1425
+ // Round-18 G4: 401 identity missing (re-auth); 403 → identity
1426
+ // OK, policy denied (update PDLSS / step up).
1427
+ code: !result.identityVerified ? "UNAUTHORIZED" : "INSUFFICIENT_ACCESS",
1373
1428
  message: result.denialReasons?.[0] || "Access denied",
1374
1429
  accessLevel: result.accessLevel,
1375
1430
  required: routeConfig.minAccessLevel,
1376
1431
  guidance: result.guidance
1377
1432
  }
1378
1433
  },
1379
- { status: result.verified ? 403 : 401 }
1434
+ { status: !result.identityVerified ? 401 : 403 }
1380
1435
  );
1381
1436
  }
1382
1437
  if (showCommerceShield) {
@@ -1391,7 +1446,12 @@ function createMiddleware2(options) {
1391
1446
  return NextResponse.redirect(new URL("/unauthorized", request.url));
1392
1447
  }
1393
1448
  const response = NextResponse.next();
1394
- response.headers.set("X-AstraSync-Verified", result.verified.toString());
1449
+ response.headers.set(
1450
+ "X-AstraSync-Verified",
1451
+ (result.identityVerified && result.policyAllowed).toString()
1452
+ );
1453
+ response.headers.set("X-AstraSync-Identity-Verified", result.identityVerified.toString());
1454
+ response.headers.set("X-AstraSync-Policy-Allowed", result.policyAllowed.toString());
1395
1455
  response.headers.set("X-AstraSync-Access-Level", result.accessLevel);
1396
1456
  if (result.agent) {
1397
1457
  response.headers.set("X-AstraSync-Agent-Id", result.agent.astraId);
@@ -1459,7 +1519,11 @@ var VerificationGatewayClient = class {
1459
1519
  );
1460
1520
  }
1461
1521
  /**
1462
- * Quick verification - just check if credentials are valid
1522
+ * Quick verification checks credentials and policy in one call.
1523
+ *
1524
+ * Round-18 G4: return shape mirrors `VerificationResult`'s identity/policy
1525
+ * split. Map to HTTP status the same way: `!identityVerified` → 401,
1526
+ * `identityVerified && !policyAllowed` → 403.
1463
1527
  */
1464
1528
  async quickVerify(credentials) {
1465
1529
  return this.executeWithRetry(() => quickVerify(this.config, credentials));
@@ -4102,13 +4166,16 @@ function readSingleHeader(value) {
4102
4166
  }
4103
4167
  function defaultMcpDenied(result, req, res) {
4104
4168
  const id = req.body?.id ?? null;
4105
- const status = result.verified ? 403 : 401;
4169
+ const status = !result.identityVerified ? 401 : 403;
4106
4170
  res.setHeader("X-Astra-Gateway-Mode", "enforced");
4107
4171
  res.status(status).json({
4108
4172
  jsonrpc: "2.0",
4109
4173
  id,
4110
4174
  error: {
4111
- code: result.verified ? -32001 : -32e3,
4175
+ // JSON-RPC error codes:
4176
+ // -32000 → unauthorized (no identity resolved)
4177
+ // -32001 → insufficient access (identity OK, policy denied)
4178
+ code: !result.identityVerified ? -32e3 : -32001,
4112
4179
  message: result.denialReasons?.[0] ?? "Access denied",
4113
4180
  data: {
4114
4181
  accessLevel: result.accessLevel,
@@ -4242,7 +4309,7 @@ function createMcpMiddleware(options) {
4242
4309
  req.agentVerification = result;
4243
4310
  const sessionId = result.sessionId;
4244
4311
  const correlationId = result.correlationId;
4245
- if (!result.verified) {
4312
+ if (!result.identityVerified || !result.policyAllowed) {
4246
4313
  if (shouldRecordDecisions && sessionId) {
4247
4314
  recordDecision(config, sessionId, "denied", result.denialReasons?.[0]).catch(() => {
4248
4315
  });
@@ -4659,6 +4726,29 @@ var AstraSync = class {
4659
4726
  }
4660
4727
  };
4661
4728
 
4729
+ // src/registration/guidance.ts
4730
+ function buildGuidance(params) {
4731
+ const origin = params.origin.replace(/\/+$/, "");
4732
+ const docsPath = params.documentationPath ?? "/docs/agent-access";
4733
+ const message = params.message ?? "AstraSync registration requires credentials.";
4734
+ return {
4735
+ status: "credentials_required",
4736
+ message,
4737
+ guidance: {
4738
+ message: "AstraSync registration requires credentials. Get an account + API key, then call register_agent again.",
4739
+ registrationUrl: `${origin}/register`,
4740
+ documentationUrl: `${origin}${docsPath.startsWith("/") ? docsPath : `/${docsPath}`}`,
4741
+ steps: [
4742
+ "Visit registrationUrl and create an AstraSync account (or log in if you have one).",
4743
+ "Generate an API key from Settings \u2192 API Keys.",
4744
+ "Re-call register_agent with the apiKey populated.",
4745
+ "After registration returns status: pending_approval, the owner approves via email.",
4746
+ "Use poll_registration({ requestId }) to retrieve the astraId once approved."
4747
+ ]
4748
+ }
4749
+ };
4750
+ }
4751
+
4662
4752
  // src/agent/index.ts
4663
4753
  var agent_exports = {};
4664
4754
  __export(agent_exports, {
@@ -4992,6 +5082,7 @@ var VERSION = "2.0.0";
4992
5082
  TRUST_LEVEL_RANGES,
4993
5083
  VERSION,
4994
5084
  agent,
5085
+ buildGuidance,
4995
5086
  clearCache,
4996
5087
  createMcpMiddleware,
4997
5088
  determineAccessLevel,