@astrasyncai/verification-gateway 5.12.0 → 5.14.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 (75) hide show
  1. package/dist/adapters/express.js +63 -19
  2. package/dist/adapters/express.js.map +1 -1
  3. package/dist/adapters/express.mjs +63 -19
  4. package/dist/adapters/express.mjs.map +1 -1
  5. package/dist/adapters/mcp.js +26 -9
  6. package/dist/adapters/mcp.js.map +1 -1
  7. package/dist/adapters/mcp.mjs +26 -9
  8. package/dist/adapters/mcp.mjs.map +1 -1
  9. package/dist/adapters/nextjs.js +63 -19
  10. package/dist/adapters/nextjs.js.map +1 -1
  11. package/dist/adapters/nextjs.mjs +63 -19
  12. package/dist/adapters/nextjs.mjs.map +1 -1
  13. package/dist/adapters/sdk.js +26 -9
  14. package/dist/adapters/sdk.js.map +1 -1
  15. package/dist/adapters/sdk.mjs +26 -9
  16. package/dist/adapters/sdk.mjs.map +1 -1
  17. package/dist/agent/index.js +1 -1
  18. package/dist/agent/index.js.map +1 -1
  19. package/dist/agent/index.mjs +1 -1
  20. package/dist/agent/index.mjs.map +1 -1
  21. package/dist/bin/astrasync-claude-hook.js +53 -18
  22. package/dist/bin/astrasync-codex-hook.js +53 -18
  23. package/dist/bin/astrasync-guard.js +53 -18
  24. package/dist/bin/astrasync.js +54 -19
  25. package/dist/browser/background.js +53 -18
  26. package/dist/browser/background.js.map +1 -1
  27. package/dist/browser/background.mjs +53 -18
  28. package/dist/browser/background.mjs.map +1 -1
  29. package/dist/cli/index.js +1 -1
  30. package/dist/cli/index.js.map +1 -1
  31. package/dist/cli/index.mjs +1 -1
  32. package/dist/cli/index.mjs.map +1 -1
  33. package/dist/codex/index.js +53 -18
  34. package/dist/codex/index.js.map +1 -1
  35. package/dist/codex/index.mjs +53 -18
  36. package/dist/codex/index.mjs.map +1 -1
  37. package/dist/cursor/extension.js +53 -18
  38. package/dist/cursor/extension.js.map +1 -1
  39. package/dist/cursor/extension.mjs +53 -18
  40. package/dist/cursor/extension.mjs.map +1 -1
  41. package/dist/edge-config.js +1 -1
  42. package/dist/edge-config.js.map +1 -1
  43. package/dist/edge-config.mjs +1 -1
  44. package/dist/edge-config.mjs.map +1 -1
  45. package/dist/edge-core/index.d.mts +32 -4
  46. package/dist/edge-core/index.d.ts +32 -4
  47. package/dist/edge-core/index.js +53 -18
  48. package/dist/edge-core/index.js.map +1 -1
  49. package/dist/edge-core/index.mjs +53 -18
  50. package/dist/edge-core/index.mjs.map +1 -1
  51. package/dist/gateway/gateway.js +53 -18
  52. package/dist/gateway/gateway.js.map +1 -1
  53. package/dist/gateway/gateway.mjs +53 -18
  54. package/dist/gateway/gateway.mjs.map +1 -1
  55. package/dist/index.d.mts +2 -12
  56. package/dist/index.d.ts +2 -12
  57. package/dist/index.js +63 -19
  58. package/dist/index.js.map +1 -1
  59. package/dist/index.mjs +63 -19
  60. package/dist/index.mjs.map +1 -1
  61. package/dist/registration/index.js +1 -1
  62. package/dist/registration/index.js.map +1 -1
  63. package/dist/registration/index.mjs +1 -1
  64. package/dist/registration/index.mjs.map +1 -1
  65. package/dist/transport/index.js +1 -1
  66. package/dist/transport/index.js.map +1 -1
  67. package/dist/transport/index.mjs +1 -1
  68. package/dist/transport/index.mjs.map +1 -1
  69. package/dist/verify.d.mts +0 -10
  70. package/dist/verify.d.ts +0 -10
  71. package/dist/verify.js +36 -10
  72. package/dist/verify.js.map +1 -1
  73. package/dist/verify.mjs +36 -10
  74. package/dist/verify.mjs.map +1 -1
  75. package/package.json +3 -2
package/dist/verify.d.mts CHANGED
@@ -79,16 +79,6 @@ interface ReportAttemptOptions {
79
79
  retried: boolean;
80
80
  }) => void;
81
81
  }
82
- /**
83
- * Fetch the per-route policy for an endpoint from the AstraSync backend.
84
- * v2.9.7 moved policy authority into the dashboard — the SDK no longer
85
- * accepts `routes` from merchant-side source code, it fetches them from
86
- * here on init (and refreshes periodically).
87
- *
88
- * Returns `null` when the request fails for any reason — the caller decides
89
- * how to fall back (the middleware allows-all when no policy is loaded so
90
- * a misconfigured init doesn't take down the merchant's API).
91
- */
92
82
  declare function fetchRoutes(config: GatewayConfig, counterpartyId: string): Promise<RouteAccessConfigShape[] | null>;
93
83
  /**
94
84
  * Minimal shape of an EndpointRoute as the SDK consumes it. Mirrors the
package/dist/verify.d.ts CHANGED
@@ -79,16 +79,6 @@ interface ReportAttemptOptions {
79
79
  retried: boolean;
80
80
  }) => void;
81
81
  }
82
- /**
83
- * Fetch the per-route policy for an endpoint from the AstraSync backend.
84
- * v2.9.7 moved policy authority into the dashboard — the SDK no longer
85
- * accepts `routes` from merchant-side source code, it fetches them from
86
- * here on init (and refreshes periodically).
87
- *
88
- * Returns `null` when the request fails for any reason — the caller decides
89
- * how to fall back (the middleware allows-all when no policy is loaded so
90
- * a misconfigured init doesn't take down the merchant's API).
91
- */
92
82
  declare function fetchRoutes(config: GatewayConfig, counterpartyId: string): Promise<RouteAccessConfigShape[] | null>;
93
83
  /**
94
84
  * Minimal shape of an EndpointRoute as the SDK consumes it. Mirrors the
package/dist/verify.js CHANGED
@@ -37,7 +37,7 @@ __export(verify_exports, {
37
37
  module.exports = __toCommonJS(verify_exports);
38
38
 
39
39
  // src/version.ts
40
- var SDK_VERSION = "5.12.0";
40
+ var SDK_VERSION = "5.14.0";
41
41
 
42
42
  // src/http.ts
43
43
  var SDK_USER_AGENT = `astrasync-sdk/${SDK_VERSION}`;
@@ -110,7 +110,7 @@ function _resetInitCheck() {
110
110
  initCheckPerformed = false;
111
111
  }
112
112
  var deprecationWarningShown = false;
113
- async function performInitCheck(apiBaseUrl, debug, strictInit, apiKey) {
113
+ async function performInitCheck(apiBaseUrl, debug, strictInit, apiKey, counterparty) {
114
114
  initCheckPerformed = true;
115
115
  try {
116
116
  const probeUrl = `${apiBaseUrl}/agents/verify-access`;
@@ -128,7 +128,8 @@ async function performInitCheck(apiBaseUrl, debug, strictInit, apiKey) {
128
128
  );
129
129
  }
130
130
  if (apiKey) {
131
- const selfCheck = await sdkFetch(`${apiBaseUrl}/agents/verify-access/self-check`, {
131
+ const q = counterparty?.id ? `?counterpartyId=${encodeURIComponent(counterparty.id)}` : counterparty?.url ? `?counterpartyUrl=${encodeURIComponent(counterparty.url)}` : "";
132
+ const selfCheck = await sdkFetch(`${apiBaseUrl}/agents/verify-access/self-check${q}`, {
132
133
  headers: { Authorization: `Bearer ${apiKey}` }
133
134
  });
134
135
  if (selfCheck.status === 401) {
@@ -140,6 +141,13 @@ async function performInitCheck(apiBaseUrl, debug, strictInit, apiKey) {
140
141
  console.error(message);
141
142
  } else if (selfCheck.ok) {
142
143
  const body = await selfCheck.json().catch(() => ({}));
144
+ if (body.counterparty && body.counterparty.canVerify === false) {
145
+ const message = `[VerificationGateway] the configured AstraSync API key cannot verify for this endpoint (${body.counterparty.message ?? "endpoint not found or owned by another account"}). Every inbound agent will be turned away until the key or counterparty is corrected.`;
146
+ if (strictInit) {
147
+ throw new Error(`${message} (strictInit=true)`);
148
+ }
149
+ console.error(message);
150
+ }
143
151
  if (typeof body.daysToExpiry === "number" && body.daysToExpiry <= 7) {
144
152
  console.warn(
145
153
  `[VerificationGateway] the configured AstraSync API key expires in ${body.daysToExpiry} day(s) \u2014 rotate it at Settings \u2192 Developer Tools before integrations start failing.`
@@ -284,11 +292,11 @@ function createGuidanceResponse(_config, reason, options = {}) {
284
292
  const isMisconfig = source === "merchant_misconfig";
285
293
  const urls = options.urls;
286
294
  const guidance = isMisconfig ? {
287
- message: "This site's AstraSync integration is misconfigured (its API key was revoked, expired, or rotated). Your identity and the AstraSync platform are fine \u2014 contact the site operator. Retrying will not help.",
295
+ message: "This site's AstraSync integration is misconfigured (its API key was revoked, expired, rotated, or belongs to another account). Your identity and the AstraSync platform are fine \u2014 contact the site operator. Retrying will not help.",
288
296
  registrationUrl: urls?.registrationUrl ?? "",
289
297
  documentationUrl: options.remediation?.docsUrl ?? urls?.documentationUrl ?? "",
290
298
  steps: [
291
- "Report the failure to the site operator \u2014 their AstraSync API key needs rotating",
299
+ "Report the failure to the site operator \u2014 their AstraSync API key needs replacing",
292
300
  "Do not retry: the failure is deterministic until the operator updates their key"
293
301
  ]
294
302
  } : isApiError ? {
@@ -500,12 +508,13 @@ async function callVerifyAccessAPI(config, request) {
500
508
  };
501
509
  }
502
510
  if (!response.ok) {
503
- if (response.status === 401) {
511
+ const keyMismatch = response.status === 403 && data?.error === "COUNTERPARTY_KEY_MISMATCH";
512
+ if (response.status === 401 || keyMismatch) {
504
513
  return {
505
514
  success: false,
506
515
  error: data.message || data.error || "Integration API key rejected",
507
516
  misconfig: true,
508
- misconfigCode: typeof data?.code === "string" ? data.code : void 0,
517
+ misconfigCode: keyMismatch ? "counterparty_key_mismatch" : typeof data?.code === "string" ? data.code : void 0,
509
518
  remediation: data?.remediation && typeof data.remediation === "object" ? data.remediation : void 0,
510
519
  correlationId: typeof data?.correlationId === "string" ? data.correlationId : void 0,
511
520
  attemptId: typeof data?.attemptId === "string" ? data.attemptId : void 0
@@ -538,14 +547,22 @@ async function verify(config, request, options) {
538
547
  mergedConfig.apiBaseUrl,
539
548
  mergedConfig.debug,
540
549
  true,
541
- mergedConfig.apiKey
550
+ mergedConfig.apiKey,
551
+ {
552
+ id: mergedConfig.counterpartyId,
553
+ url: mergedConfig.counterpartyUrl ?? request.counterpartyUrl
554
+ }
542
555
  );
543
556
  } else {
544
557
  void performInitCheck(
545
558
  mergedConfig.apiBaseUrl,
546
559
  mergedConfig.debug,
547
560
  false,
548
- mergedConfig.apiKey
561
+ mergedConfig.apiKey,
562
+ {
563
+ id: mergedConfig.counterpartyId,
564
+ url: mergedConfig.counterpartyUrl ?? request.counterpartyUrl
565
+ }
549
566
  );
550
567
  }
551
568
  }
@@ -776,6 +793,7 @@ async function reportAttempt(config, report, options = {}) {
776
793
  timer.unref?.();
777
794
  }
778
795
  var ATTEMPT_REPORT_MAX_RETRY_DELAY_MS = 2e3;
796
+ var refusedPolicyReads = /* @__PURE__ */ new Set();
779
797
  async function fetchRoutes(config, counterpartyId) {
780
798
  if (!counterpartyId) return null;
781
799
  const headers = { "Content-Type": "application/json" };
@@ -788,7 +806,15 @@ async function fetchRoutes(config, counterpartyId) {
788
806
  `${config.apiBaseUrl}/endpoints/${encodeURIComponent(counterpartyId)}/routes`,
789
807
  { method: "GET", headers }
790
808
  );
791
- if (!response.ok) return null;
809
+ if (!response.ok) {
810
+ if ((response.status === 401 || response.status === 403 || response.status === 404) && !refusedPolicyReads.has(counterpartyId)) {
811
+ refusedPolicyReads.add(counterpartyId);
812
+ console.error(
813
+ `[VerificationGateway] the configured API key cannot read the route policy for ${counterpartyId} (HTTP ${response.status}). The key belongs to an account that does not own this endpoint, or the counterpartyId is wrong. The gateway is in PASS-THROUGH mode: no agent is being verified.`
814
+ );
815
+ }
816
+ return null;
817
+ }
792
818
  const body = await response.json();
793
819
  return body.data?.routes ?? [];
794
820
  } catch {