@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}`;
@@ -377,7 +377,7 @@ var DEFAULT_CONFIG = {
377
377
  };
378
378
  var initCheckPerformed = false;
379
379
  var deprecationWarningShown = false;
380
- async function performInitCheck(apiBaseUrl, debug, strictInit, apiKey) {
380
+ async function performInitCheck(apiBaseUrl, debug, strictInit, apiKey, counterparty) {
381
381
  initCheckPerformed = true;
382
382
  try {
383
383
  const probeUrl = `${apiBaseUrl}/agents/verify-access`;
@@ -395,7 +395,8 @@ async function performInitCheck(apiBaseUrl, debug, strictInit, apiKey) {
395
395
  );
396
396
  }
397
397
  if (apiKey) {
398
- const selfCheck = await sdkFetch(`${apiBaseUrl}/agents/verify-access/self-check`, {
398
+ const q = counterparty?.id ? `?counterpartyId=${encodeURIComponent(counterparty.id)}` : counterparty?.url ? `?counterpartyUrl=${encodeURIComponent(counterparty.url)}` : "";
399
+ const selfCheck = await sdkFetch(`${apiBaseUrl}/agents/verify-access/self-check${q}`, {
399
400
  headers: { Authorization: `Bearer ${apiKey}` }
400
401
  });
401
402
  if (selfCheck.status === 401) {
@@ -407,6 +408,13 @@ async function performInitCheck(apiBaseUrl, debug, strictInit, apiKey) {
407
408
  console.error(message);
408
409
  } else if (selfCheck.ok) {
409
410
  const body = await selfCheck.json().catch(() => ({}));
411
+ if (body.counterparty && body.counterparty.canVerify === false) {
412
+ 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.`;
413
+ if (strictInit) {
414
+ throw new Error(`${message} (strictInit=true)`);
415
+ }
416
+ console.error(message);
417
+ }
410
418
  if (typeof body.daysToExpiry === "number" && body.daysToExpiry <= 7) {
411
419
  console.warn(
412
420
  `[VerificationGateway] the configured AstraSync API key expires in ${body.daysToExpiry} day(s) \u2014 rotate it at Settings \u2192 Developer Tools before integrations start failing.`
@@ -545,11 +553,11 @@ function createGuidanceResponse(_config, reason, options = {}) {
545
553
  const isMisconfig = source === "merchant_misconfig";
546
554
  const urls = options.urls;
547
555
  const guidance = isMisconfig ? {
548
- 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.",
556
+ 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.",
549
557
  registrationUrl: urls?.registrationUrl ?? "",
550
558
  documentationUrl: options.remediation?.docsUrl ?? urls?.documentationUrl ?? "",
551
559
  steps: [
552
- "Report the failure to the site operator \u2014 their AstraSync API key needs rotating",
560
+ "Report the failure to the site operator \u2014 their AstraSync API key needs replacing",
553
561
  "Do not retry: the failure is deterministic until the operator updates their key"
554
562
  ]
555
563
  } : isApiError ? {
@@ -761,12 +769,13 @@ async function callVerifyAccessAPI(config, request) {
761
769
  };
762
770
  }
763
771
  if (!response.ok) {
764
- if (response.status === 401) {
772
+ const keyMismatch = response.status === 403 && data?.error === "COUNTERPARTY_KEY_MISMATCH";
773
+ if (response.status === 401 || keyMismatch) {
765
774
  return {
766
775
  success: false,
767
776
  error: data.message || data.error || "Integration API key rejected",
768
777
  misconfig: true,
769
- misconfigCode: typeof data?.code === "string" ? data.code : void 0,
778
+ misconfigCode: keyMismatch ? "counterparty_key_mismatch" : typeof data?.code === "string" ? data.code : void 0,
770
779
  remediation: data?.remediation && typeof data.remediation === "object" ? data.remediation : void 0,
771
780
  correlationId: typeof data?.correlationId === "string" ? data.correlationId : void 0,
772
781
  attemptId: typeof data?.attemptId === "string" ? data.attemptId : void 0
@@ -799,14 +808,22 @@ async function verify(config, request, options) {
799
808
  mergedConfig.apiBaseUrl,
800
809
  mergedConfig.debug,
801
810
  true,
802
- mergedConfig.apiKey
811
+ mergedConfig.apiKey,
812
+ {
813
+ id: mergedConfig.counterpartyId,
814
+ url: mergedConfig.counterpartyUrl ?? request.counterpartyUrl
815
+ }
803
816
  );
804
817
  } else {
805
818
  void performInitCheck(
806
819
  mergedConfig.apiBaseUrl,
807
820
  mergedConfig.debug,
808
821
  false,
809
- mergedConfig.apiKey
822
+ mergedConfig.apiKey,
823
+ {
824
+ id: mergedConfig.counterpartyId,
825
+ url: mergedConfig.counterpartyUrl ?? request.counterpartyUrl
826
+ }
810
827
  );
811
828
  }
812
829
  }
@@ -1517,6 +1534,11 @@ async function withBudget(promise, ms) {
1517
1534
  if (timer) clearTimeout(timer);
1518
1535
  }
1519
1536
  }
1537
+ var CONTAINER_ID = (() => {
1538
+ const c = globalThis.crypto;
1539
+ if (c?.randomUUID) return c.randomUUID();
1540
+ return `c-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 12)}`;
1541
+ })();
1520
1542
  var destKeyOf = (d) => `${d.apiBaseUrl}\0${d.apiKey ?? ""}\0${d.counterparty}\0${d.adapter ?? ""}`;
1521
1543
  var BeaconBuffer = class {
1522
1544
  constructor(options = {}) {
@@ -1524,6 +1546,7 @@ var BeaconBuffer = class {
1524
1546
  this.droppedSinceLast = 0;
1525
1547
  this.droppedTotal = 0;
1526
1548
  this.deliveredTotal = 0;
1549
+ this.enqueuedTotal = 0;
1527
1550
  this.backoffUntil = 0;
1528
1551
  this.collapse = /* @__PURE__ */ new Map();
1529
1552
  /** Keys the backend answered 401 for — later batches go unauthenticated. */
@@ -1536,13 +1559,16 @@ var BeaconBuffer = class {
1536
1559
  collapseMaxKeys: options.collapseMaxKeys ?? 1e3,
1537
1560
  requestTimeoutMs: options.requestTimeoutMs ?? 1e4,
1538
1561
  retryBackoffMs: options.retryBackoffMs ?? 1e3,
1562
+ holdRepeats: options.holdRepeats ?? false,
1563
+ containerId: options.containerId ?? CONTAINER_ID,
1539
1564
  now: options.now ?? Date.now
1540
1565
  };
1541
1566
  }
1542
1567
  /**
1543
1568
  * Queue one beacon. With a `collapseKey`, a repeat inside the window is
1544
- * merged into a held aggregate (sent when the window closes) instead of
1545
- * becoming its own item.
1569
+ * merged into this key's item while that item is still queued (not yet in
1570
+ * flight). Once it has left, the repeat becomes a new item, sendable on
1571
+ * this flush — nothing waits for a later invocation (round 27.6).
1546
1572
  */
1547
1573
  enqueue(dest, item, collapseKey) {
1548
1574
  const now = this.opts.now();
@@ -1555,12 +1581,15 @@ var BeaconBuffer = class {
1555
1581
  return;
1556
1582
  }
1557
1583
  }
1558
- const held = this.push(
1559
- dest,
1560
- { ...item, repeatCount: 1 },
1561
- entry.firstSeenAt + this.opts.collapseWindowMs
1562
- );
1563
- entry.held = held;
1584
+ if (this.opts.holdRepeats) {
1585
+ entry.held = this.push(
1586
+ dest,
1587
+ { ...item, repeatCount: 1 },
1588
+ entry.firstSeenAt + this.opts.collapseWindowMs
1589
+ );
1590
+ return;
1591
+ }
1592
+ entry.first = this.push(dest, { ...item, repeatCount: 1 }, now);
1564
1593
  return;
1565
1594
  }
1566
1595
  this.collapse.delete(collapseKey);
@@ -1596,6 +1625,7 @@ var BeaconBuffer = class {
1596
1625
  droppedSinceLast: this.droppedSinceLast,
1597
1626
  droppedTotal: this.droppedTotal,
1598
1627
  deliveredTotal: this.deliveredTotal,
1628
+ enqueuedTotal: this.enqueuedTotal,
1599
1629
  flushing: this.inFlight !== void 0
1600
1630
  };
1601
1631
  }
@@ -1610,6 +1640,7 @@ var BeaconBuffer = class {
1610
1640
  inFlight: false
1611
1641
  };
1612
1642
  this.queue.push(entry);
1643
+ this.enqueuedTotal += 1;
1613
1644
  return entry;
1614
1645
  }
1615
1646
  dropOldest() {
@@ -1655,7 +1686,11 @@ var BeaconBuffer = class {
1655
1686
  droppedSinceLast: reportedDropped,
1656
1687
  queueDepth: this.queue.length,
1657
1688
  adapter: dest.adapter ?? "edge-core",
1658
- version: SDK_VERSION
1689
+ version: SDK_VERSION,
1690
+ containerId: this.opts.containerId,
1691
+ enqueuedTotal: this.enqueuedTotal,
1692
+ deliveredTotal: this.deliveredTotal,
1693
+ droppedTotal: this.droppedTotal
1659
1694
  };
1660
1695
  const controller = typeof AbortController !== "undefined" ? new AbortController() : void 0;
1661
1696
  const response = await withBudget(