@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
@@ -4006,7 +4006,7 @@ function getTrustLevel(score) {
4006
4006
  }
4007
4007
 
4008
4008
  // src/version.ts
4009
- var SDK_VERSION = "5.12.0";
4009
+ var SDK_VERSION = "5.14.0";
4010
4010
 
4011
4011
  // src/http.ts
4012
4012
  var SDK_USER_AGENT = `astrasync-sdk/${SDK_VERSION}`;
@@ -4053,7 +4053,7 @@ var DEFAULT_CONFIG = {
4053
4053
  };
4054
4054
  var initCheckPerformed = false;
4055
4055
  var deprecationWarningShown = false;
4056
- async function performInitCheck(apiBaseUrl, debug, strictInit, apiKey) {
4056
+ async function performInitCheck(apiBaseUrl, debug, strictInit, apiKey, counterparty) {
4057
4057
  initCheckPerformed = true;
4058
4058
  try {
4059
4059
  const probeUrl = `${apiBaseUrl}/agents/verify-access`;
@@ -4071,7 +4071,8 @@ async function performInitCheck(apiBaseUrl, debug, strictInit, apiKey) {
4071
4071
  );
4072
4072
  }
4073
4073
  if (apiKey) {
4074
- const selfCheck = await sdkFetch(`${apiBaseUrl}/agents/verify-access/self-check`, {
4074
+ const q = counterparty?.id ? `?counterpartyId=${encodeURIComponent(counterparty.id)}` : counterparty?.url ? `?counterpartyUrl=${encodeURIComponent(counterparty.url)}` : "";
4075
+ const selfCheck = await sdkFetch(`${apiBaseUrl}/agents/verify-access/self-check${q}`, {
4075
4076
  headers: { Authorization: `Bearer ${apiKey}` }
4076
4077
  });
4077
4078
  if (selfCheck.status === 401) {
@@ -4083,6 +4084,13 @@ async function performInitCheck(apiBaseUrl, debug, strictInit, apiKey) {
4083
4084
  console.error(message);
4084
4085
  } else if (selfCheck.ok) {
4085
4086
  const body = await selfCheck.json().catch(() => ({}));
4087
+ if (body.counterparty && body.counterparty.canVerify === false) {
4088
+ 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.`;
4089
+ if (strictInit) {
4090
+ throw new Error(`${message} (strictInit=true)`);
4091
+ }
4092
+ console.error(message);
4093
+ }
4086
4094
  if (typeof body.daysToExpiry === "number" && body.daysToExpiry <= 7) {
4087
4095
  console.warn(
4088
4096
  `[VerificationGateway] the configured AstraSync API key expires in ${body.daysToExpiry} day(s) \u2014 rotate it at Settings \u2192 Developer Tools before integrations start failing.`
@@ -4187,11 +4195,11 @@ function createGuidanceResponse(_config, reason, options = {}) {
4187
4195
  const isMisconfig = source === "merchant_misconfig";
4188
4196
  const urls = options.urls;
4189
4197
  const guidance = isMisconfig ? {
4190
- 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.",
4198
+ 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.",
4191
4199
  registrationUrl: urls?.registrationUrl ?? "",
4192
4200
  documentationUrl: options.remediation?.docsUrl ?? urls?.documentationUrl ?? "",
4193
4201
  steps: [
4194
- "Report the failure to the site operator \u2014 their AstraSync API key needs rotating",
4202
+ "Report the failure to the site operator \u2014 their AstraSync API key needs replacing",
4195
4203
  "Do not retry: the failure is deterministic until the operator updates their key"
4196
4204
  ]
4197
4205
  } : isApiError ? {
@@ -4403,12 +4411,13 @@ async function callVerifyAccessAPI(config, request) {
4403
4411
  };
4404
4412
  }
4405
4413
  if (!response.ok) {
4406
- if (response.status === 401) {
4414
+ const keyMismatch = response.status === 403 && data?.error === "COUNTERPARTY_KEY_MISMATCH";
4415
+ if (response.status === 401 || keyMismatch) {
4407
4416
  return {
4408
4417
  success: false,
4409
4418
  error: data.message || data.error || "Integration API key rejected",
4410
4419
  misconfig: true,
4411
- misconfigCode: typeof data?.code === "string" ? data.code : void 0,
4420
+ misconfigCode: keyMismatch ? "counterparty_key_mismatch" : typeof data?.code === "string" ? data.code : void 0,
4412
4421
  remediation: data?.remediation && typeof data.remediation === "object" ? data.remediation : void 0,
4413
4422
  correlationId: typeof data?.correlationId === "string" ? data.correlationId : void 0,
4414
4423
  attemptId: typeof data?.attemptId === "string" ? data.attemptId : void 0
@@ -4441,14 +4450,22 @@ async function verify(config, request, options) {
4441
4450
  mergedConfig.apiBaseUrl,
4442
4451
  mergedConfig.debug,
4443
4452
  true,
4444
- mergedConfig.apiKey
4453
+ mergedConfig.apiKey,
4454
+ {
4455
+ id: mergedConfig.counterpartyId,
4456
+ url: mergedConfig.counterpartyUrl ?? request.counterpartyUrl
4457
+ }
4445
4458
  );
4446
4459
  } else {
4447
4460
  void performInitCheck(
4448
4461
  mergedConfig.apiBaseUrl,
4449
4462
  mergedConfig.debug,
4450
4463
  false,
4451
- mergedConfig.apiKey
4464
+ mergedConfig.apiKey,
4465
+ {
4466
+ id: mergedConfig.counterpartyId,
4467
+ url: mergedConfig.counterpartyUrl ?? request.counterpartyUrl
4468
+ }
4452
4469
  );
4453
4470
  }
4454
4471
  }
@@ -4659,6 +4676,11 @@ async function withBudget(promise, ms) {
4659
4676
  if (timer) clearTimeout(timer);
4660
4677
  }
4661
4678
  }
4679
+ var CONTAINER_ID = (() => {
4680
+ const c = globalThis.crypto;
4681
+ if (c?.randomUUID) return c.randomUUID();
4682
+ return `c-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 12)}`;
4683
+ })();
4662
4684
  var destKeyOf = (d) => `${d.apiBaseUrl}\0${d.apiKey ?? ""}\0${d.counterparty}\0${d.adapter ?? ""}`;
4663
4685
  var BeaconBuffer = class {
4664
4686
  constructor(options = {}) {
@@ -4666,6 +4688,7 @@ var BeaconBuffer = class {
4666
4688
  this.droppedSinceLast = 0;
4667
4689
  this.droppedTotal = 0;
4668
4690
  this.deliveredTotal = 0;
4691
+ this.enqueuedTotal = 0;
4669
4692
  this.backoffUntil = 0;
4670
4693
  this.collapse = /* @__PURE__ */ new Map();
4671
4694
  /** Keys the backend answered 401 for — later batches go unauthenticated. */
@@ -4678,13 +4701,16 @@ var BeaconBuffer = class {
4678
4701
  collapseMaxKeys: options.collapseMaxKeys ?? 1e3,
4679
4702
  requestTimeoutMs: options.requestTimeoutMs ?? 1e4,
4680
4703
  retryBackoffMs: options.retryBackoffMs ?? 1e3,
4704
+ holdRepeats: options.holdRepeats ?? false,
4705
+ containerId: options.containerId ?? CONTAINER_ID,
4681
4706
  now: options.now ?? Date.now
4682
4707
  };
4683
4708
  }
4684
4709
  /**
4685
4710
  * Queue one beacon. With a `collapseKey`, a repeat inside the window is
4686
- * merged into a held aggregate (sent when the window closes) instead of
4687
- * becoming its own item.
4711
+ * merged into this key's item while that item is still queued (not yet in
4712
+ * flight). Once it has left, the repeat becomes a new item, sendable on
4713
+ * this flush — nothing waits for a later invocation (round 27.6).
4688
4714
  */
4689
4715
  enqueue(dest, item, collapseKey) {
4690
4716
  const now = this.opts.now();
@@ -4697,12 +4723,15 @@ var BeaconBuffer = class {
4697
4723
  return;
4698
4724
  }
4699
4725
  }
4700
- const held = this.push(
4701
- dest,
4702
- { ...item, repeatCount: 1 },
4703
- entry.firstSeenAt + this.opts.collapseWindowMs
4704
- );
4705
- entry.held = held;
4726
+ if (this.opts.holdRepeats) {
4727
+ entry.held = this.push(
4728
+ dest,
4729
+ { ...item, repeatCount: 1 },
4730
+ entry.firstSeenAt + this.opts.collapseWindowMs
4731
+ );
4732
+ return;
4733
+ }
4734
+ entry.first = this.push(dest, { ...item, repeatCount: 1 }, now);
4706
4735
  return;
4707
4736
  }
4708
4737
  this.collapse.delete(collapseKey);
@@ -4738,6 +4767,7 @@ var BeaconBuffer = class {
4738
4767
  droppedSinceLast: this.droppedSinceLast,
4739
4768
  droppedTotal: this.droppedTotal,
4740
4769
  deliveredTotal: this.deliveredTotal,
4770
+ enqueuedTotal: this.enqueuedTotal,
4741
4771
  flushing: this.inFlight !== void 0
4742
4772
  };
4743
4773
  }
@@ -4752,6 +4782,7 @@ var BeaconBuffer = class {
4752
4782
  inFlight: false
4753
4783
  };
4754
4784
  this.queue.push(entry);
4785
+ this.enqueuedTotal += 1;
4755
4786
  return entry;
4756
4787
  }
4757
4788
  dropOldest() {
@@ -4797,7 +4828,11 @@ var BeaconBuffer = class {
4797
4828
  droppedSinceLast: reportedDropped,
4798
4829
  queueDepth: this.queue.length,
4799
4830
  adapter: dest.adapter ?? "edge-core",
4800
- version: SDK_VERSION
4831
+ version: SDK_VERSION,
4832
+ containerId: this.opts.containerId,
4833
+ enqueuedTotal: this.enqueuedTotal,
4834
+ deliveredTotal: this.deliveredTotal,
4835
+ droppedTotal: this.droppedTotal
4801
4836
  };
4802
4837
  const controller = typeof AbortController !== "undefined" ? new AbortController() : void 0;
4803
4838
  const response = await withBudget(