@astrasyncai/verification-gateway 2.2.3 → 2.3.7

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 (79) 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 +62 -30
  6. package/dist/adapters/express.js.map +1 -1
  7. package/dist/adapters/express.mjs +61 -27
  8. package/dist/adapters/express.mjs.map +1 -1
  9. package/dist/adapters/mcp.d.mts +245 -0
  10. package/dist/adapters/mcp.d.ts +245 -0
  11. package/dist/adapters/mcp.js +589 -0
  12. package/dist/adapters/mcp.js.map +1 -0
  13. package/dist/adapters/mcp.mjs +555 -0
  14. package/dist/adapters/mcp.mjs.map +1 -0
  15. package/dist/adapters/nextjs.d.mts +2 -2
  16. package/dist/adapters/nextjs.d.ts +2 -2
  17. package/dist/adapters/nextjs.js +60 -12
  18. package/dist/adapters/nextjs.js.map +1 -1
  19. package/dist/adapters/nextjs.mjs +60 -12
  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 +6 -10
  24. package/dist/adapters/sdk.js.map +1 -1
  25. package/dist/adapters/sdk.mjs +6 -10
  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 +12 -10
  30. package/dist/browser/background.js.map +1 -1
  31. package/dist/browser/background.mjs +12 -10
  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 +12 -10
  42. package/dist/cursor/extension.js.map +1 -1
  43. package/dist/cursor/extension.mjs +12 -10
  44. package/dist/cursor/extension.mjs.map +1 -1
  45. package/dist/{express-DgwpS8Ha.d.mts → express-D9oRsseg.d.mts} +17 -14
  46. package/dist/{express-BtKlLI8U.d.ts → express-DMSIl20m.d.ts} +17 -14
  47. package/dist/gateway/gateway.d.mts +2 -2
  48. package/dist/gateway/gateway.d.ts +2 -2
  49. package/dist/gateway/gateway.js +12 -10
  50. package/dist/gateway/gateway.js.map +1 -1
  51. package/dist/gateway/gateway.mjs +12 -10
  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-AzhK20t0.d.mts → index-Bn_7eGjb.d.mts} +1 -1
  56. package/dist/{index-Ba0Lvsjo.d.ts → index-BtU9yFda.d.ts} +1 -1
  57. package/dist/{index-DpJS1JEI.d.ts → index-EwUWXC5T.d.ts} +1 -1
  58. package/dist/{index-BaxpmTGA.d.mts → index-YNPs800Z.d.mts} +1 -1
  59. package/dist/index.d.mts +7 -7
  60. package/dist/index.d.ts +7 -7
  61. package/dist/index.js +96 -29
  62. package/dist/index.js.map +1 -1
  63. package/dist/index.mjs +96 -29
  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-B2kg19c1.d.ts → nextjs-B5ZBpHra.d.ts} +8 -2
  68. package/dist/{nextjs-ZymQ8jDh.d.mts → nextjs-BLtjRbc-.d.mts} +8 -2
  69. package/dist/{sdk-B7id0VFS.d.mts → sdk-BhkxvqnK.d.mts} +1 -1
  70. package/dist/{sdk-Bso0FSI0.d.ts → sdk-YmE3RG8n.d.ts} +1 -1
  71. package/dist/transport/index.d.mts +2 -2
  72. package/dist/transport/index.d.ts +2 -2
  73. package/dist/{types-BYKAY6Cc.d.ts → types-BecRpozv.d.ts} +1 -1
  74. package/dist/{types-DOrqNMgy.d.mts → types-Bxqj1sKY.d.mts} +134 -24
  75. package/dist/{types-DOrqNMgy.d.ts → types-Bxqj1sKY.d.ts} +134 -24
  76. package/dist/{types-CgXPKUwi.d.mts → types-DxY5zt4z.d.mts} +1 -1
  77. package/dist/ui/index.d.mts +1 -1
  78. package/dist/ui/index.d.ts +1 -1
  79. package/package.json +6 -1
package/dist/index.mjs CHANGED
@@ -334,10 +334,12 @@ async function verify(config, request) {
334
334
  return createGuidanceResponse(mergedConfig, apiResponse.error);
335
335
  }
336
336
  if (!apiResponse.access?.allowed) {
337
+ const aggregatedFailures = apiResponse.access?.failures;
337
338
  const result2 = {
338
339
  verified: false,
339
340
  accessLevel: "guidance",
340
- denialReasons: apiResponse.access?.reason ? [apiResponse.access.reason] : ["Access denied"],
341
+ denialReasons: aggregatedFailures && aggregatedFailures.length > 0 ? aggregatedFailures.map((f) => f.message) : apiResponse.access?.reason ? [apiResponse.access.reason] : ["Access denied"],
342
+ failures: aggregatedFailures,
341
343
  requiresStepUp: apiResponse.access?.requiresStepUp,
342
344
  requiresApproval: apiResponse.access?.requiresApproval,
343
345
  guidance: {
@@ -372,14 +374,7 @@ async function verify(config, request) {
372
374
  verified: apiResponse.organization.verified,
373
375
  trustScore: apiResponse.organization.trustScore
374
376
  } : void 0;
375
- const pdlss = apiResponse.access?.pdlss ? {
376
- purposeAllowed: apiResponse.access.pdlss.purposeAllowed,
377
- withinDuration: apiResponse.access.pdlss.withinDuration,
378
- withinLimits: apiResponse.access.pdlss.withinLimits,
379
- scopeAllowed: apiResponse.access.pdlss.scopeAllowed,
380
- selfInstantiationAllowed: apiResponse.access.pdlss.selfInstantiationAllowed,
381
- appliedPolicy: apiResponse.access.appliedPolicy
382
- } : void 0;
377
+ const verificationContext = apiResponse.verificationContext;
383
378
  const accessLevel = apiResponse.access?.accessLevel ?? "standard";
384
379
  const result = {
385
380
  verified: true,
@@ -387,7 +382,8 @@ async function verify(config, request) {
387
382
  agent,
388
383
  developer,
389
384
  organization,
390
- pdlss,
385
+ appliedPolicy: apiResponse.access?.appliedPolicy,
386
+ verificationContext,
391
387
  requiresStepUp: apiResponse.access?.requiresStepUp,
392
388
  requiresApproval: apiResponse.access?.requiresApproval,
393
389
  verifiedAt: /* @__PURE__ */ new Date(),
@@ -437,6 +433,25 @@ async function recordDecision(config, sessionId, decision, reason) {
437
433
  }).catch(() => {
438
434
  });
439
435
  }
436
+ async function fetchRoutes(config, counterpartyId) {
437
+ if (!counterpartyId) return null;
438
+ const headers = { "Content-Type": "application/json" };
439
+ if (config.apiKey) {
440
+ headers["Authorization"] = `Bearer ${config.apiKey}`;
441
+ headers["X-API-Key"] = config.apiKey;
442
+ }
443
+ try {
444
+ const response = await fetch(
445
+ `${config.apiBaseUrl}/endpoints/${encodeURIComponent(counterpartyId)}/routes`,
446
+ { method: "GET", headers }
447
+ );
448
+ if (!response.ok) return null;
449
+ const body = await response.json();
450
+ return body.data?.routes ?? [];
451
+ } catch {
452
+ return null;
453
+ }
454
+ }
440
455
  async function reportCounterpartyPreCheckFailure(config, data) {
441
456
  const apiBaseUrl = config.apiBaseUrl || DEFAULT_CONFIG.apiBaseUrl;
442
457
  await fetch(`${apiBaseUrl}/verification-activity/counterparty-pre-check-failure`, {
@@ -462,9 +477,7 @@ async function quickVerify(config, credentials) {
462
477
  var express_exports = {};
463
478
  __export(express_exports, {
464
479
  createMiddleware: () => createMiddleware,
465
- extractAstraSyncCredentials: () => extractAstraSyncCredentials,
466
- requireAccess: () => requireAccess,
467
- verifyOnly: () => verifyOnly
480
+ extractAstraSyncCredentials: () => extractAstraSyncCredentials
468
481
  });
469
482
 
470
483
  // src/transport/http.ts
@@ -637,24 +650,57 @@ function defaultOnDenied(result, _req, res) {
637
650
  }
638
651
  });
639
652
  }
653
+ var DEFAULT_ROUTES_REFRESH_MS = 5 * 60 * 1e3;
640
654
  function createMiddleware(options) {
641
655
  const {
642
- routes = [],
643
656
  extractCredentials: customExtractCredentials,
644
657
  extractPurpose: customExtractPurpose,
645
658
  skipPaths = [],
646
659
  onDenied = defaultOnDenied,
647
660
  recordDecisions,
648
661
  enableRuntimeChallenge = true,
662
+ routesRefreshMs = DEFAULT_ROUTES_REFRESH_MS,
649
663
  ...config
650
664
  } = options;
665
+ let cachedRoutes = [];
666
+ let lastFetchAt = 0;
667
+ let refreshing = null;
668
+ let warnedNoCounterparty = false;
669
+ async function refreshRoutes() {
670
+ if (!config.counterpartyId) {
671
+ if (!warnedNoCounterparty) {
672
+ console.warn(
673
+ "[VerificationGateway] No counterpartyId configured \u2014 falling through (allow all). Per-route policy lives in the AstraSync dashboard now; register the endpoint and set counterpartyId in your middleware config to enforce policy."
674
+ );
675
+ warnedNoCounterparty = true;
676
+ }
677
+ return;
678
+ }
679
+ const fetched = await fetchRoutes(config, config.counterpartyId);
680
+ if (fetched) {
681
+ cachedRoutes = fetched;
682
+ lastFetchAt = Date.now();
683
+ }
684
+ }
685
+ refreshing = refreshRoutes().finally(() => {
686
+ refreshing = null;
687
+ });
651
688
  return async (req, res, next) => {
652
689
  try {
653
690
  const shouldSkip = skipPaths.some((pattern) => matchRoute(pattern, req.path));
654
691
  if (shouldSkip) {
655
692
  return next();
656
693
  }
657
- const routeConfig = findRouteConfig(routes, req.path, req.method);
694
+ if (refreshing) {
695
+ await refreshing.catch(() => {
696
+ });
697
+ }
698
+ if (config.counterpartyId && Date.now() - lastFetchAt > routesRefreshMs) {
699
+ refreshing = refreshRoutes().finally(() => {
700
+ refreshing = null;
701
+ });
702
+ }
703
+ const routeConfig = findRouteConfig(cachedRoutes, req.path, req.method);
658
704
  if (!routeConfig) {
659
705
  return next();
660
706
  }
@@ -749,18 +795,6 @@ function createMiddleware(options) {
749
795
  }
750
796
  };
751
797
  }
752
- function requireAccess(minAccessLevel, options) {
753
- return createMiddleware({
754
- ...options,
755
- routes: [{ pattern: "*", method: "*", minAccessLevel }]
756
- });
757
- }
758
- function verifyOnly(options) {
759
- return createMiddleware({
760
- ...options,
761
- routes: [{ pattern: "*", method: "*", minAccessLevel: "none" }]
762
- });
763
- }
764
798
 
765
799
  // src/adapters/nextjs.ts
766
800
  var nextjs_exports = {};
@@ -984,14 +1018,38 @@ function generateCommerceShieldHtml(result, options) {
984
1018
  </html>
985
1019
  `.trim();
986
1020
  }
1021
+ var DEFAULT_ROUTES_REFRESH_MS2 = 5 * 60 * 1e3;
987
1022
  function createMiddleware2(options) {
988
1023
  const {
989
- routes = [],
990
1024
  skipPaths = [],
991
1025
  showCommerceShield = true,
992
1026
  enableRuntimeChallenge = true,
1027
+ routesRefreshMs = DEFAULT_ROUTES_REFRESH_MS2,
993
1028
  ...config
994
1029
  } = options;
1030
+ let cachedRoutes = [];
1031
+ let lastFetchAt = 0;
1032
+ let refreshing = null;
1033
+ let warnedNoCounterparty = false;
1034
+ async function refreshRoutes() {
1035
+ if (!config.counterpartyId) {
1036
+ if (!warnedNoCounterparty) {
1037
+ console.warn(
1038
+ "[VerificationGateway/Next.js] No counterpartyId configured \u2014 falling through (allow all). Per-route policy lives in the AstraSync dashboard now; register the endpoint and set counterpartyId in your middleware config to enforce policy."
1039
+ );
1040
+ warnedNoCounterparty = true;
1041
+ }
1042
+ return;
1043
+ }
1044
+ const fetched = await fetchRoutes(config, config.counterpartyId);
1045
+ if (fetched) {
1046
+ cachedRoutes = fetched;
1047
+ lastFetchAt = Date.now();
1048
+ }
1049
+ }
1050
+ refreshing = refreshRoutes().finally(() => {
1051
+ refreshing = null;
1052
+ });
995
1053
  return async function middleware(request) {
996
1054
  const { NextResponse } = await import("next/server");
997
1055
  const pathname = request.nextUrl.pathname;
@@ -999,7 +1057,16 @@ function createMiddleware2(options) {
999
1057
  if (shouldSkip) {
1000
1058
  return NextResponse.next();
1001
1059
  }
1002
- const routeConfig = findRouteConfig2(routes, pathname, request.method);
1060
+ if (refreshing) {
1061
+ await refreshing.catch(() => {
1062
+ });
1063
+ }
1064
+ if (config.counterpartyId && Date.now() - lastFetchAt > routesRefreshMs) {
1065
+ refreshing = refreshRoutes().finally(() => {
1066
+ refreshing = null;
1067
+ });
1068
+ }
1069
+ const routeConfig = findRouteConfig2(cachedRoutes, pathname, request.method);
1003
1070
  if (!routeConfig) {
1004
1071
  return NextResponse.next();
1005
1072
  }