@astrasyncai/verification-gateway 5.19.0 → 5.21.0

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 (111) hide show
  1. package/CHANGELOG.md +130 -0
  2. package/README.md +53 -4
  3. package/dist/adapter-interface/interface.d.mts +2 -2
  4. package/dist/adapter-interface/interface.d.ts +2 -2
  5. package/dist/adapters/express.d.mts +1 -1
  6. package/dist/adapters/express.d.ts +1 -1
  7. package/dist/adapters/express.js +65 -16
  8. package/dist/adapters/express.js.map +1 -1
  9. package/dist/adapters/express.mjs +65 -16
  10. package/dist/adapters/express.mjs.map +1 -1
  11. package/dist/adapters/mcp.d.mts +23 -1
  12. package/dist/adapters/mcp.d.ts +23 -1
  13. package/dist/adapters/mcp.js +91 -16
  14. package/dist/adapters/mcp.js.map +1 -1
  15. package/dist/adapters/mcp.mjs +91 -16
  16. package/dist/adapters/mcp.mjs.map +1 -1
  17. package/dist/adapters/nextjs.d.mts +1 -1
  18. package/dist/adapters/nextjs.d.ts +1 -1
  19. package/dist/adapters/nextjs.js +57 -11
  20. package/dist/adapters/nextjs.js.map +1 -1
  21. package/dist/adapters/nextjs.mjs +57 -11
  22. package/dist/adapters/nextjs.mjs.map +1 -1
  23. package/dist/adapters/sdk.d.mts +35 -2
  24. package/dist/adapters/sdk.d.ts +35 -2
  25. package/dist/adapters/sdk.js +110 -11
  26. package/dist/adapters/sdk.js.map +1 -1
  27. package/dist/adapters/sdk.mjs +110 -11
  28. package/dist/adapters/sdk.mjs.map +1 -1
  29. package/dist/agent/index.d.mts +1 -1
  30. package/dist/agent/index.d.ts +1 -1
  31. package/dist/agent/index.js +1 -1
  32. package/dist/agent/index.js.map +1 -1
  33. package/dist/agent/index.mjs +1 -1
  34. package/dist/agent/index.mjs.map +1 -1
  35. package/dist/bin/astrasync-claude-hook.js +50 -12
  36. package/dist/bin/astrasync-codex-hook.js +50 -12
  37. package/dist/bin/astrasync-guard.js +50 -12
  38. package/dist/bin/astrasync.js +65 -13
  39. package/dist/browser/background.js +50 -12
  40. package/dist/browser/background.js.map +1 -1
  41. package/dist/browser/background.mjs +50 -12
  42. package/dist/browser/background.mjs.map +1 -1
  43. package/dist/cli/index.js +1 -1
  44. package/dist/cli/index.js.map +1 -1
  45. package/dist/cli/index.mjs +1 -1
  46. package/dist/cli/index.mjs.map +1 -1
  47. package/dist/codex/index.js +50 -12
  48. package/dist/codex/index.js.map +1 -1
  49. package/dist/codex/index.mjs +50 -12
  50. package/dist/codex/index.mjs.map +1 -1
  51. package/dist/cursor/extension.js +50 -12
  52. package/dist/cursor/extension.js.map +1 -1
  53. package/dist/cursor/extension.mjs +50 -12
  54. package/dist/cursor/extension.mjs.map +1 -1
  55. package/dist/edge-config.d.mts +1 -1
  56. package/dist/edge-config.d.ts +1 -1
  57. package/dist/edge-config.js +1 -1
  58. package/dist/edge-config.js.map +1 -1
  59. package/dist/edge-config.mjs +1 -1
  60. package/dist/edge-config.mjs.map +1 -1
  61. package/dist/edge-core/index.d.mts +1 -1
  62. package/dist/edge-core/index.d.ts +1 -1
  63. package/dist/edge-core/index.js +49 -11
  64. package/dist/edge-core/index.js.map +1 -1
  65. package/dist/edge-core/index.mjs +49 -11
  66. package/dist/edge-core/index.mjs.map +1 -1
  67. package/dist/gateway/gateway.d.mts +2 -2
  68. package/dist/gateway/gateway.d.ts +2 -2
  69. package/dist/gateway/gateway.js +50 -12
  70. package/dist/gateway/gateway.js.map +1 -1
  71. package/dist/gateway/gateway.mjs +50 -12
  72. package/dist/gateway/gateway.mjs.map +1 -1
  73. package/dist/git-trigger/git-hooks.d.mts +1 -1
  74. package/dist/git-trigger/git-hooks.d.ts +1 -1
  75. package/dist/index.d.mts +286 -8
  76. package/dist/index.d.ts +286 -8
  77. package/dist/index.js +532 -49
  78. package/dist/index.js.map +1 -1
  79. package/dist/index.mjs +522 -49
  80. package/dist/index.mjs.map +1 -1
  81. package/dist/local-evaluator/evaluator.d.mts +2 -2
  82. package/dist/local-evaluator/evaluator.d.ts +2 -2
  83. package/dist/registration/index.d.mts +11 -2
  84. package/dist/registration/index.d.ts +11 -2
  85. package/dist/registration/index.js +1 -1
  86. package/dist/registration/index.js.map +1 -1
  87. package/dist/registration/index.mjs +1 -1
  88. package/dist/registration/index.mjs.map +1 -1
  89. package/dist/transport/index.d.mts +1 -1
  90. package/dist/transport/index.d.ts +1 -1
  91. package/dist/transport/index.js +1 -1
  92. package/dist/transport/index.js.map +1 -1
  93. package/dist/transport/index.mjs +1 -1
  94. package/dist/transport/index.mjs.map +1 -1
  95. package/dist/{types-BoGjyon0.d.mts → types-B4zhOAlq.d.mts} +30 -1
  96. package/dist/{types-BRz2U0Pn.d.ts → types-B_HLhZ9n.d.ts} +1 -1
  97. package/dist/{types-BfILnheI.d.mts → types-CU17R4Nr.d.mts} +11 -0
  98. package/dist/{types-BfILnheI.d.ts → types-CU17R4Nr.d.ts} +11 -0
  99. package/dist/{types-eWyZuz-3.d.ts → types-CtBXnWuV.d.ts} +30 -1
  100. package/dist/{types-DqWPkiYl.d.mts → types-DHHyXtuZ.d.mts} +30 -1
  101. package/dist/{types-DqWPkiYl.d.ts → types-DHHyXtuZ.d.ts} +30 -1
  102. package/dist/{types-CfBpm3w5.d.mts → types-Djpz-L0w.d.mts} +1 -1
  103. package/dist/ui/index.d.mts +1 -1
  104. package/dist/ui/index.d.ts +1 -1
  105. package/dist/verify.d.mts +28 -3
  106. package/dist/verify.d.ts +28 -3
  107. package/dist/verify.js +71 -11
  108. package/dist/verify.js.map +1 -1
  109. package/dist/verify.mjs +69 -11
  110. package/dist/verify.mjs.map +1 -1
  111. package/package.json +1 -1
@@ -452,7 +452,7 @@ function routePolicyOf(route) {
452
452
  }
453
453
 
454
454
  // src/version.ts
455
- var SDK_VERSION = "5.19.0";
455
+ var SDK_VERSION = "5.21.0";
456
456
 
457
457
  // src/http.ts
458
458
  var SDK_USER_AGENT = `astrasync-sdk/${SDK_VERSION}`;
@@ -967,6 +967,9 @@ async function callVerifyAccessAPI(config, request) {
967
967
  if (requestData.enableRuntimeChallenge)
968
968
  body.enableRuntimeChallenge = requestData.enableRuntimeChallenge;
969
969
  if (requestData.routePolicy) body.routePolicy = requestData.routePolicy;
970
+ if (config.actingProof?.connectorToken) {
971
+ body.actingProof = { connectorToken: config.actingProof.connectorToken };
972
+ }
970
973
  if (requestData.approvalHeldByRoute) body.approvalHeldByRoute = true;
971
974
  if (requestData.createSession) body.createSession = requestData.createSession;
972
975
  if (requestData.durationRequired) body.durationRequired = requestData.durationRequired;
@@ -1134,22 +1137,46 @@ async function verify(config, request, options) {
1134
1137
  "[VerificationGateway] minTrustScore / minTrustScoreForFull are deprecated in v2.3.0 and have no effect. Server is now the single source of truth for access decisions (verified ID + runtime challenge + PDLSS + trust score). To gate access to an endpoint, configure the endpoint's trust_score_requirement server-side."
1135
1138
  );
1136
1139
  }
1137
- const uncacheable = Boolean(request.commerceArtifacts);
1140
+ const uncacheable = Boolean(request.commerceArtifacts) || Boolean(mergedConfig.actingProof);
1138
1141
  if (mergedConfig.cacheTtl !== 0 && !options?.bypassCache && !uncacheable) {
1139
1142
  const cached = getCachedResult(request, mergedConfig.counterpartyId);
1140
1143
  if (cached) {
1141
1144
  if (mergedConfig.debug) {
1142
1145
  console.log("[VerificationGateway] Returning cached result");
1143
1146
  }
1144
- const hit = { ...cached };
1145
- if (request.attemptId) {
1146
- hit.attemptId = request.attemptId;
1147
- } else {
1148
- delete hit.attemptId;
1149
- }
1150
- return hit;
1147
+ return sharedVerdict(cached, request);
1148
+ }
1149
+ }
1150
+ if (mergedConfig.cacheTtl !== 0 && !options?.bypassCache && !uncacheable) {
1151
+ const key = getCacheKey(request, mergedConfig.counterpartyId);
1152
+ const pending = inflightVerifies.get(key);
1153
+ if (pending) return sharedVerdict(await pending, request);
1154
+ const flight = verifyViaApi(mergedConfig, request, urls, uncacheable);
1155
+ inflightVerifies.set(key, flight);
1156
+ try {
1157
+ return await flight;
1158
+ } finally {
1159
+ inflightVerifies.delete(key);
1151
1160
  }
1152
1161
  }
1162
+ return verifyViaApi(mergedConfig, request, urls, uncacheable);
1163
+ }
1164
+ var inflightVerifies = /* @__PURE__ */ new Map();
1165
+ var sharedVerdicts = /* @__PURE__ */ new WeakSet();
1166
+ function isSharedVerdict(result) {
1167
+ return sharedVerdicts.has(result);
1168
+ }
1169
+ function sharedVerdict(source, request) {
1170
+ const hit = { ...source };
1171
+ if (request.attemptId) {
1172
+ hit.attemptId = request.attemptId;
1173
+ } else {
1174
+ delete hit.attemptId;
1175
+ }
1176
+ sharedVerdicts.add(hit);
1177
+ return hit;
1178
+ }
1179
+ async function verifyViaApi(mergedConfig, request, urls, uncacheable) {
1153
1180
  const enrichedRequest = { ...request };
1154
1181
  if (!enrichedRequest.counterpartyUrl && mergedConfig.counterpartyUrl) {
1155
1182
  enrichedRequest.counterpartyUrl = mergedConfig.counterpartyUrl;
@@ -1228,7 +1255,9 @@ async function verify(config, request, options) {
1228
1255
  fulfilment: apiResponse.fulfilment,
1229
1256
  mandates: apiResponse.mandates,
1230
1257
  kyaToken: apiResponse.kyaToken,
1231
- aep: apiResponse.aep
1258
+ aep: apiResponse.aep,
1259
+ // 5.20.0 (round 29.1): non-fatal integration warnings (e.g. events_url_missing).
1260
+ warnings: apiResponse.warnings
1232
1261
  };
1233
1262
  return result2;
1234
1263
  }
@@ -1296,7 +1325,9 @@ async function verify(config, request, options) {
1296
1325
  // 5.15.0: merchant-lane AP2 mandates + KYAPay identity token.
1297
1326
  mandates: apiResponse.mandates,
1298
1327
  kyaToken: apiResponse.kyaToken,
1299
- aep: apiResponse.aep
1328
+ aep: apiResponse.aep,
1329
+ // 5.20.0 (round 29.1): non-fatal integration warnings (e.g. events_url_missing).
1330
+ warnings: apiResponse.warnings
1300
1331
  };
1301
1332
  if (result.recommendation === "deny") {
1302
1333
  result.policyAllowed = false;
@@ -1322,8 +1353,18 @@ async function verify(config, request, options) {
1322
1353
  cacheResult(request, result, mergedConfig.cacheTtl, mergedConfig.counterpartyId);
1323
1354
  }
1324
1355
  }
1356
+ notifyVerificationListeners(request, result);
1325
1357
  return result;
1326
1358
  }
1359
+ var verificationListeners = /* @__PURE__ */ new Set();
1360
+ function notifyVerificationListeners(request, result) {
1361
+ for (const listener of verificationListeners) {
1362
+ try {
1363
+ listener(result, request);
1364
+ } catch {
1365
+ }
1366
+ }
1367
+ }
1327
1368
  async function recordDecision(config, sessionId, decision, reason) {
1328
1369
  const headers = { "Content-Type": "application/json" };
1329
1370
  if (config.apiKey) {
@@ -1346,6 +1387,7 @@ async function fetchRoutes(config, counterpartyId, options = {}) {
1346
1387
  headers["X-API-Key"] = config.apiKey;
1347
1388
  }
1348
1389
  try {
1390
+ headers["X-AstraSync-SDK-Version"] = SDK_VERSION;
1349
1391
  const response = await sdkFetch(
1350
1392
  `${config.apiBaseUrl}/endpoints/${encodeURIComponent(counterpartyId)}/routes` + (options.codeGates?.length ? `?codeGates=${options.codeGates.map(encodeURIComponent).join(",")}` : ""),
1351
1393
  { method: "GET", headers }
@@ -1360,6 +1402,13 @@ async function fetchRoutes(config, counterpartyId, options = {}) {
1360
1402
  return null;
1361
1403
  }
1362
1404
  const body = await response.json();
1405
+ const type = body.data?.counterpartyType;
1406
+ if (typeof type === "string" && options.onEndpointType) {
1407
+ try {
1408
+ options.onEndpointType(type);
1409
+ } catch {
1410
+ }
1411
+ }
1363
1412
  return body.data?.routes ?? [];
1364
1413
  } catch {
1365
1414
  return null;
@@ -2638,14 +2687,14 @@ function createMiddleware(options) {
2638
2687
  res.setHeader("X-Astra-Gateway-Mode", "enforced");
2639
2688
  res.setHeader("X-Astra-Gateway-Reason", "evaluated-not-enforced");
2640
2689
  }
2641
- if (shouldRecordDecisions && sessionId) {
2690
+ if (shouldRecordDecisions && sessionId && !isSharedVerdict(result)) {
2642
2691
  recordDecision(config, sessionId, "granted").catch(() => {
2643
2692
  });
2644
2693
  }
2645
2694
  return next();
2646
2695
  }
2647
2696
  if (!result.policyAllowed) {
2648
- if (shouldRecordDecisions && sessionId) {
2697
+ if (shouldRecordDecisions && sessionId && !isSharedVerdict(result)) {
2649
2698
  recordDecision(config, sessionId, "denied", result.denialReasons?.[0]).catch(() => {
2650
2699
  });
2651
2700
  }
@@ -2658,7 +2707,7 @@ function createMiddleware(options) {
2658
2707
  }
2659
2708
  if (requiresHumanApproval(result)) {
2660
2709
  annotateApprovalRequired(result);
2661
- if (shouldRecordDecisions && sessionId) {
2710
+ if (shouldRecordDecisions && sessionId && !isSharedVerdict(result)) {
2662
2711
  recordDecision(config, sessionId, "denied", result.denialReasons?.[0]).catch(() => {
2663
2712
  });
2664
2713
  }
@@ -2683,7 +2732,7 @@ function createMiddleware(options) {
2683
2732
  documentationUrl: wellKnownUrls.documentationUrl
2684
2733
  };
2685
2734
  }
2686
- if (shouldRecordDecisions && sessionId) {
2735
+ if (shouldRecordDecisions && sessionId && !isSharedVerdict(result)) {
2687
2736
  recordDecision(config, sessionId, "denied", trustFailure.message).catch(() => {
2688
2737
  });
2689
2738
  }
@@ -2692,7 +2741,7 @@ function createMiddleware(options) {
2692
2741
  return;
2693
2742
  }
2694
2743
  }
2695
- if (shouldRecordDecisions && sessionId) {
2744
+ if (shouldRecordDecisions && sessionId && !isSharedVerdict(result)) {
2696
2745
  recordDecision(config, sessionId, "granted").catch(() => {
2697
2746
  });
2698
2747
  }