@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
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var SDK_VERSION = "5.12.0";
2
+ var SDK_VERSION = "5.14.0";
3
3
 
4
4
  // src/http.ts
5
5
  var SDK_USER_AGENT = `astrasync-sdk/${SDK_VERSION}`;
@@ -157,7 +157,7 @@ var DEFAULT_CONFIG = {
157
157
  };
158
158
  var initCheckPerformed = false;
159
159
  var deprecationWarningShown = false;
160
- async function performInitCheck(apiBaseUrl, debug, strictInit, apiKey) {
160
+ async function performInitCheck(apiBaseUrl, debug, strictInit, apiKey, counterparty) {
161
161
  initCheckPerformed = true;
162
162
  try {
163
163
  const probeUrl = `${apiBaseUrl}/agents/verify-access`;
@@ -175,7 +175,8 @@ async function performInitCheck(apiBaseUrl, debug, strictInit, apiKey) {
175
175
  );
176
176
  }
177
177
  if (apiKey) {
178
- const selfCheck = await sdkFetch(`${apiBaseUrl}/agents/verify-access/self-check`, {
178
+ const q = counterparty?.id ? `?counterpartyId=${encodeURIComponent(counterparty.id)}` : counterparty?.url ? `?counterpartyUrl=${encodeURIComponent(counterparty.url)}` : "";
179
+ const selfCheck = await sdkFetch(`${apiBaseUrl}/agents/verify-access/self-check${q}`, {
179
180
  headers: { Authorization: `Bearer ${apiKey}` }
180
181
  });
181
182
  if (selfCheck.status === 401) {
@@ -187,6 +188,13 @@ async function performInitCheck(apiBaseUrl, debug, strictInit, apiKey) {
187
188
  console.error(message);
188
189
  } else if (selfCheck.ok) {
189
190
  const body = await selfCheck.json().catch(() => ({}));
191
+ if (body.counterparty && body.counterparty.canVerify === false) {
192
+ 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.`;
193
+ if (strictInit) {
194
+ throw new Error(`${message} (strictInit=true)`);
195
+ }
196
+ console.error(message);
197
+ }
190
198
  if (typeof body.daysToExpiry === "number" && body.daysToExpiry <= 7) {
191
199
  console.warn(
192
200
  `[VerificationGateway] the configured AstraSync API key expires in ${body.daysToExpiry} day(s) \u2014 rotate it at Settings \u2192 Developer Tools before integrations start failing.`
@@ -325,11 +333,11 @@ function createGuidanceResponse(_config, reason, options = {}) {
325
333
  const isMisconfig = source === "merchant_misconfig";
326
334
  const urls = options.urls;
327
335
  const guidance = isMisconfig ? {
328
- 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.",
336
+ 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.",
329
337
  registrationUrl: urls?.registrationUrl ?? "",
330
338
  documentationUrl: options.remediation?.docsUrl ?? urls?.documentationUrl ?? "",
331
339
  steps: [
332
- "Report the failure to the site operator \u2014 their AstraSync API key needs rotating",
340
+ "Report the failure to the site operator \u2014 their AstraSync API key needs replacing",
333
341
  "Do not retry: the failure is deterministic until the operator updates their key"
334
342
  ]
335
343
  } : isApiError ? {
@@ -541,12 +549,13 @@ async function callVerifyAccessAPI(config, request) {
541
549
  };
542
550
  }
543
551
  if (!response.ok) {
544
- if (response.status === 401) {
552
+ const keyMismatch = response.status === 403 && data?.error === "COUNTERPARTY_KEY_MISMATCH";
553
+ if (response.status === 401 || keyMismatch) {
545
554
  return {
546
555
  success: false,
547
556
  error: data.message || data.error || "Integration API key rejected",
548
557
  misconfig: true,
549
- misconfigCode: typeof data?.code === "string" ? data.code : void 0,
558
+ misconfigCode: keyMismatch ? "counterparty_key_mismatch" : typeof data?.code === "string" ? data.code : void 0,
550
559
  remediation: data?.remediation && typeof data.remediation === "object" ? data.remediation : void 0,
551
560
  correlationId: typeof data?.correlationId === "string" ? data.correlationId : void 0,
552
561
  attemptId: typeof data?.attemptId === "string" ? data.attemptId : void 0
@@ -579,14 +588,22 @@ async function verify(config, request, options) {
579
588
  mergedConfig.apiBaseUrl,
580
589
  mergedConfig.debug,
581
590
  true,
582
- mergedConfig.apiKey
591
+ mergedConfig.apiKey,
592
+ {
593
+ id: mergedConfig.counterpartyId,
594
+ url: mergedConfig.counterpartyUrl ?? request.counterpartyUrl
595
+ }
583
596
  );
584
597
  } else {
585
598
  void performInitCheck(
586
599
  mergedConfig.apiBaseUrl,
587
600
  mergedConfig.debug,
588
601
  false,
589
- mergedConfig.apiKey
602
+ mergedConfig.apiKey,
603
+ {
604
+ id: mergedConfig.counterpartyId,
605
+ url: mergedConfig.counterpartyUrl ?? request.counterpartyUrl
606
+ }
590
607
  );
591
608
  }
592
609
  }
@@ -762,6 +779,7 @@ async function verify(config, request, options) {
762
779
  }
763
780
  return result;
764
781
  }
782
+ var refusedPolicyReads = /* @__PURE__ */ new Set();
765
783
  async function fetchRoutes(config, counterpartyId) {
766
784
  if (!counterpartyId) return null;
767
785
  const headers = { "Content-Type": "application/json" };
@@ -774,7 +792,15 @@ async function fetchRoutes(config, counterpartyId) {
774
792
  `${config.apiBaseUrl}/endpoints/${encodeURIComponent(counterpartyId)}/routes`,
775
793
  { method: "GET", headers }
776
794
  );
777
- if (!response.ok) return null;
795
+ if (!response.ok) {
796
+ if ((response.status === 401 || response.status === 403 || response.status === 404) && !refusedPolicyReads.has(counterpartyId)) {
797
+ refusedPolicyReads.add(counterpartyId);
798
+ console.error(
799
+ `[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.`
800
+ );
801
+ }
802
+ return null;
803
+ }
778
804
  const body = await response.json();
779
805
  return body.data?.routes ?? [];
780
806
  } catch {
@@ -1420,6 +1446,11 @@ async function withBudget(promise, ms) {
1420
1446
  if (timer) clearTimeout(timer);
1421
1447
  }
1422
1448
  }
1449
+ var CONTAINER_ID = (() => {
1450
+ const c = globalThis.crypto;
1451
+ if (c?.randomUUID) return c.randomUUID();
1452
+ return `c-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 12)}`;
1453
+ })();
1423
1454
  var destKeyOf = (d) => `${d.apiBaseUrl}\0${d.apiKey ?? ""}\0${d.counterparty}\0${d.adapter ?? ""}`;
1424
1455
  var BeaconBuffer = class {
1425
1456
  constructor(options = {}) {
@@ -1427,6 +1458,7 @@ var BeaconBuffer = class {
1427
1458
  this.droppedSinceLast = 0;
1428
1459
  this.droppedTotal = 0;
1429
1460
  this.deliveredTotal = 0;
1461
+ this.enqueuedTotal = 0;
1430
1462
  this.backoffUntil = 0;
1431
1463
  this.collapse = /* @__PURE__ */ new Map();
1432
1464
  /** Keys the backend answered 401 for — later batches go unauthenticated. */
@@ -1439,13 +1471,16 @@ var BeaconBuffer = class {
1439
1471
  collapseMaxKeys: options.collapseMaxKeys ?? 1e3,
1440
1472
  requestTimeoutMs: options.requestTimeoutMs ?? 1e4,
1441
1473
  retryBackoffMs: options.retryBackoffMs ?? 1e3,
1474
+ holdRepeats: options.holdRepeats ?? false,
1475
+ containerId: options.containerId ?? CONTAINER_ID,
1442
1476
  now: options.now ?? Date.now
1443
1477
  };
1444
1478
  }
1445
1479
  /**
1446
1480
  * Queue one beacon. With a `collapseKey`, a repeat inside the window is
1447
- * merged into a held aggregate (sent when the window closes) instead of
1448
- * becoming its own item.
1481
+ * merged into this key's item while that item is still queued (not yet in
1482
+ * flight). Once it has left, the repeat becomes a new item, sendable on
1483
+ * this flush — nothing waits for a later invocation (round 27.6).
1449
1484
  */
1450
1485
  enqueue(dest, item, collapseKey) {
1451
1486
  const now = this.opts.now();
@@ -1458,12 +1493,15 @@ var BeaconBuffer = class {
1458
1493
  return;
1459
1494
  }
1460
1495
  }
1461
- const held = this.push(
1462
- dest,
1463
- { ...item, repeatCount: 1 },
1464
- entry.firstSeenAt + this.opts.collapseWindowMs
1465
- );
1466
- entry.held = held;
1496
+ if (this.opts.holdRepeats) {
1497
+ entry.held = this.push(
1498
+ dest,
1499
+ { ...item, repeatCount: 1 },
1500
+ entry.firstSeenAt + this.opts.collapseWindowMs
1501
+ );
1502
+ return;
1503
+ }
1504
+ entry.first = this.push(dest, { ...item, repeatCount: 1 }, now);
1467
1505
  return;
1468
1506
  }
1469
1507
  this.collapse.delete(collapseKey);
@@ -1499,6 +1537,7 @@ var BeaconBuffer = class {
1499
1537
  droppedSinceLast: this.droppedSinceLast,
1500
1538
  droppedTotal: this.droppedTotal,
1501
1539
  deliveredTotal: this.deliveredTotal,
1540
+ enqueuedTotal: this.enqueuedTotal,
1502
1541
  flushing: this.inFlight !== void 0
1503
1542
  };
1504
1543
  }
@@ -1513,6 +1552,7 @@ var BeaconBuffer = class {
1513
1552
  inFlight: false
1514
1553
  };
1515
1554
  this.queue.push(entry);
1555
+ this.enqueuedTotal += 1;
1516
1556
  return entry;
1517
1557
  }
1518
1558
  dropOldest() {
@@ -1558,7 +1598,11 @@ var BeaconBuffer = class {
1558
1598
  droppedSinceLast: reportedDropped,
1559
1599
  queueDepth: this.queue.length,
1560
1600
  adapter: dest.adapter ?? "edge-core",
1561
- version: SDK_VERSION
1601
+ version: SDK_VERSION,
1602
+ containerId: this.opts.containerId,
1603
+ enqueuedTotal: this.enqueuedTotal,
1604
+ deliveredTotal: this.deliveredTotal,
1605
+ droppedTotal: this.droppedTotal
1562
1606
  };
1563
1607
  const controller = typeof AbortController !== "undefined" ? new AbortController() : void 0;
1564
1608
  const response = await withBudget(