@astrasyncai/verification-gateway 5.11.0 → 5.12.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 (98) hide show
  1. package/README.md +4 -0
  2. package/dist/adapters/express.d.mts +1 -1
  3. package/dist/adapters/express.d.ts +1 -1
  4. package/dist/adapters/express.js +359 -30
  5. package/dist/adapters/express.js.map +1 -1
  6. package/dist/adapters/express.mjs +359 -30
  7. package/dist/adapters/express.mjs.map +1 -1
  8. package/dist/adapters/mcp.d.mts +5 -1
  9. package/dist/adapters/mcp.d.ts +5 -1
  10. package/dist/adapters/mcp.js +168 -41
  11. package/dist/adapters/mcp.js.map +1 -1
  12. package/dist/adapters/mcp.mjs +168 -41
  13. package/dist/adapters/mcp.mjs.map +1 -1
  14. package/dist/adapters/nextjs.d.mts +1 -1
  15. package/dist/adapters/nextjs.d.ts +1 -1
  16. package/dist/adapters/nextjs.js +352 -13
  17. package/dist/adapters/nextjs.js.map +1 -1
  18. package/dist/adapters/nextjs.mjs +352 -13
  19. package/dist/adapters/nextjs.mjs.map +1 -1
  20. package/dist/adapters/sdk.d.mts +9 -1
  21. package/dist/adapters/sdk.d.ts +9 -1
  22. package/dist/adapters/sdk.js +100 -8
  23. package/dist/adapters/sdk.js.map +1 -1
  24. package/dist/adapters/sdk.mjs +100 -8
  25. package/dist/adapters/sdk.mjs.map +1 -1
  26. package/dist/agent/index.js +1 -1
  27. package/dist/agent/index.js.map +1 -1
  28. package/dist/agent/index.mjs +1 -1
  29. package/dist/agent/index.mjs.map +1 -1
  30. package/dist/bin/astrasync-claude-hook.js +284 -7
  31. package/dist/bin/astrasync-codex-hook.js +284 -7
  32. package/dist/bin/astrasync-guard.js +284 -7
  33. package/dist/bin/astrasync.js +297 -9
  34. package/dist/browser/background.js +284 -7
  35. package/dist/browser/background.js.map +1 -1
  36. package/dist/browser/background.mjs +284 -7
  37. package/dist/browser/background.mjs.map +1 -1
  38. package/dist/cli/index.js +1 -1
  39. package/dist/cli/index.js.map +1 -1
  40. package/dist/cli/index.mjs +1 -1
  41. package/dist/cli/index.mjs.map +1 -1
  42. package/dist/codex/index.js +284 -7
  43. package/dist/codex/index.js.map +1 -1
  44. package/dist/codex/index.mjs +284 -7
  45. package/dist/codex/index.mjs.map +1 -1
  46. package/dist/cursor/extension.js +284 -7
  47. package/dist/cursor/extension.js.map +1 -1
  48. package/dist/cursor/extension.mjs +284 -7
  49. package/dist/cursor/extension.mjs.map +1 -1
  50. package/dist/edge-config.d.mts +1 -1
  51. package/dist/edge-config.d.ts +1 -1
  52. package/dist/edge-config.js +1 -1
  53. package/dist/edge-config.js.map +1 -1
  54. package/dist/edge-config.mjs +1 -1
  55. package/dist/edge-config.mjs.map +1 -1
  56. package/dist/edge-core/index.d.mts +128 -13
  57. package/dist/edge-core/index.d.ts +128 -13
  58. package/dist/edge-core/index.js +337 -55
  59. package/dist/edge-core/index.js.map +1 -1
  60. package/dist/edge-core/index.mjs +334 -55
  61. package/dist/edge-core/index.mjs.map +1 -1
  62. package/dist/gateway/gateway.js +284 -7
  63. package/dist/gateway/gateway.js.map +1 -1
  64. package/dist/gateway/gateway.mjs +284 -7
  65. package/dist/gateway/gateway.mjs.map +1 -1
  66. package/dist/git-trigger/git-hooks.d.mts +1 -1
  67. package/dist/git-trigger/git-hooks.d.ts +1 -1
  68. package/dist/index.d.mts +118 -5
  69. package/dist/index.d.ts +118 -5
  70. package/dist/index.js +486 -63
  71. package/dist/index.js.map +1 -1
  72. package/dist/index.mjs +480 -63
  73. package/dist/index.mjs.map +1 -1
  74. package/dist/platform-signatures.js +4 -1
  75. package/dist/platform-signatures.js.map +1 -1
  76. package/dist/platform-signatures.mjs +4 -1
  77. package/dist/platform-signatures.mjs.map +1 -1
  78. package/dist/registration/index.js +1 -1
  79. package/dist/registration/index.js.map +1 -1
  80. package/dist/registration/index.mjs +1 -1
  81. package/dist/registration/index.mjs.map +1 -1
  82. package/dist/transport/index.js +1 -1
  83. package/dist/transport/index.js.map +1 -1
  84. package/dist/transport/index.mjs +1 -1
  85. package/dist/transport/index.mjs.map +1 -1
  86. package/dist/{types-CTmUpNpS.d.mts → types-BCkwBA84.d.mts} +12 -0
  87. package/dist/{types-CTmUpNpS.d.ts → types-BCkwBA84.d.ts} +12 -0
  88. package/dist/{types-CtFXmDzm.d.ts → types-C_b4QTyO.d.ts} +18 -0
  89. package/dist/{types-DQrn_kei.d.mts → types-DlshIIR-.d.mts} +18 -0
  90. package/dist/ui/index.d.mts +1 -1
  91. package/dist/ui/index.d.ts +1 -1
  92. package/dist/verify.d.mts +35 -4
  93. package/dist/verify.d.ts +35 -4
  94. package/dist/verify.js +130 -16
  95. package/dist/verify.js.map +1 -1
  96. package/dist/verify.mjs +129 -16
  97. package/dist/verify.mjs.map +1 -1
  98. package/package.json +1 -1
@@ -4036,7 +4036,7 @@ function getTrustLevel(score) {
4036
4036
  }
4037
4037
 
4038
4038
  // src/version.ts
4039
- var SDK_VERSION = "5.11.0";
4039
+ var SDK_VERSION = "5.12.0";
4040
4040
 
4041
4041
  // src/http.ts
4042
4042
  var SDK_USER_AGENT = `astrasync-sdk/${SDK_VERSION}`;
@@ -4063,6 +4063,14 @@ function getCachedWellKnownUrls(apiBaseUrl) {
4063
4063
  return cache.get(apiBaseUrl)?.data;
4064
4064
  }
4065
4065
 
4066
+ // src/failure-posture.ts
4067
+ var REJECTED_IDENTITY_DIMENSIONS = /* @__PURE__ */ new Set([
4068
+ "identity.invalid_agent_id",
4069
+ "identity.unknown_agent",
4070
+ "agent.lookup"
4071
+ ]);
4072
+ var UNKNOWN_AGENT_GUIDANCE = "Register your agent with AstraSync (or, inside an MCP host, add the AstraSync MCP connector for keyless, human-approved registration), then present the canonical ASTRA-* id issued after owner approval.";
4073
+
4066
4074
  // src/verify.ts
4067
4075
  var DEFAULT_CONFIG = {
4068
4076
  apiBaseUrl: "https://astrasync.ai/api",
@@ -4274,11 +4282,44 @@ function createGuidanceResponse(_config, reason, options = {}) {
4274
4282
  // coercing the absent recommendation to a policy 'deny'. Misconfig is
4275
4283
  // deterministic and intentionally NOT marked retryable.
4276
4284
  ...isApiError && { retryable: true },
4285
+ ...options.httpStatus !== void 0 && { httpStatus: options.httpStatus },
4286
+ ...options.retryAfterMs !== void 0 && { retryAfterMs: options.retryAfterMs },
4277
4287
  correlationId: options.correlationId,
4278
4288
  attemptId: options.attemptId,
4279
4289
  verifiedAt: /* @__PURE__ */ new Date()
4280
4290
  };
4281
4291
  }
4292
+ async function readJsonSafe(response) {
4293
+ try {
4294
+ const parsed = await response.json();
4295
+ return parsed && typeof parsed === "object" ? parsed : {};
4296
+ } catch {
4297
+ return {};
4298
+ }
4299
+ }
4300
+ function rejectedIdentityGuidance(failures) {
4301
+ const f = failures?.find((x) => REJECTED_IDENTITY_DIMENSIONS.has(x.dimension));
4302
+ if (!f) return void 0;
4303
+ if (f.dimension === "agent.lookup") {
4304
+ return `The presented agent identifier is not registered with AstraSync. ${UNKNOWN_AGENT_GUIDANCE}`;
4305
+ }
4306
+ return f.guidance ? `${f.message} ${f.guidance}` : f.message;
4307
+ }
4308
+ var MAX_RETRY_AFTER_MS = 15 * 60 * 1e3;
4309
+ function parseRetryAfterMs(response) {
4310
+ const raw = response.headers?.get?.("retry-after");
4311
+ if (!raw) return void 0;
4312
+ const trimmed = raw.trim();
4313
+ let ms;
4314
+ if (/^\d+(\.\d+)?$/.test(trimmed)) {
4315
+ ms = Number(trimmed) * 1e3;
4316
+ } else {
4317
+ const at = Date.parse(trimmed);
4318
+ if (Number.isNaN(at)) return void 0;
4319
+ ms = at - Date.now();
4320
+ }
4321
+ return Math.min(MAX_RETRY_AFTER_MS, Math.max(0, Math.round(ms)));
4322
+ }
4282
4323
  async function callVerifyAccessAPI(config, request) {
4283
4324
  const { credentials, ...requestData } = request;
4284
4325
  const body = {
@@ -4335,7 +4376,8 @@ async function callVerifyAccessAPI(config, request) {
4335
4376
  body: JSON.stringify(body),
4336
4377
  signal: AbortSignal.timeout(config.verifyTimeoutMs ?? 1e4)
4337
4378
  });
4338
- const data = await response.json();
4379
+ const data = await readJsonSafe(response);
4380
+ const retryAfterMs = parseRetryAfterMs(response);
4339
4381
  if (response.status === 410) {
4340
4382
  return {
4341
4383
  success: true,
@@ -4373,6 +4415,23 @@ async function callVerifyAccessAPI(config, request) {
4373
4415
  }
4374
4416
  };
4375
4417
  }
4418
+ if (response.status === 404 && credentials.astraId && (data?.error === "AGENT_NOT_FOUND" || typeof data?.message === "string" && /agent/i.test(data.message))) {
4419
+ return {
4420
+ success: true,
4421
+ attemptId: typeof data?.attemptId === "string" ? data.attemptId : void 0,
4422
+ access: {
4423
+ allowed: false,
4424
+ reason: "unknown_agent",
4425
+ failures: [
4426
+ {
4427
+ dimension: "identity.unknown_agent",
4428
+ message: "The presented agent identifier is not registered with AstraSync.",
4429
+ guidance: UNKNOWN_AGENT_GUIDANCE
4430
+ }
4431
+ ]
4432
+ }
4433
+ };
4434
+ }
4376
4435
  if (!response.ok) {
4377
4436
  if (response.status === 401) {
4378
4437
  return {
@@ -4387,9 +4446,11 @@ async function callVerifyAccessAPI(config, request) {
4387
4446
  }
4388
4447
  return {
4389
4448
  success: false,
4390
- error: data.message || data.error || `API returned ${response.status}`,
4449
+ error: typeof data?.message === "string" && data.message || typeof data?.error === "string" && data.error || `API returned ${response.status}`,
4391
4450
  correlationId: typeof data?.correlationId === "string" ? data.correlationId : void 0,
4392
- attemptId: typeof data?.attemptId === "string" ? data.attemptId : void 0
4451
+ attemptId: typeof data?.attemptId === "string" ? data.attemptId : void 0,
4452
+ httpStatus: response.status,
4453
+ ...retryAfterMs !== void 0 && { retryAfterMs }
4393
4454
  };
4394
4455
  }
4395
4456
  return data;
@@ -4461,12 +4522,14 @@ async function verify(config, request, options) {
4461
4522
  correlationId: apiResponse.correlationId,
4462
4523
  attemptId: apiResponse.attemptId,
4463
4524
  remediation: apiResponse.remediation,
4525
+ httpStatus: apiResponse.httpStatus,
4526
+ retryAfterMs: apiResponse.retryAfterMs,
4464
4527
  urls
4465
4528
  });
4466
4529
  }
4467
4530
  if (!apiResponse.access?.allowed) {
4468
4531
  const aggregatedFailures = apiResponse.access?.failures;
4469
- const idVerifiedFromBackend = apiResponse.verificationContext?.idVerified === true;
4532
+ const idVerifiedFromBackend = apiResponse.verificationContext?.idVerified === true && !aggregatedFailures?.some((f) => REJECTED_IDENTITY_DIMENSIONS.has(f.dimension));
4470
4533
  const result2 = {
4471
4534
  identityVerified: idVerifiedFromBackend,
4472
4535
  policyAllowed: false,
@@ -4478,7 +4541,10 @@ async function verify(config, request, options) {
4478
4541
  requiresStepUp: apiResponse.access?.requiresStepUp,
4479
4542
  requiresApproval: apiResponse.access?.requiresApproval,
4480
4543
  guidance: {
4481
- message: apiResponse.access?.reason || "Access denied by PDLSS policy",
4544
+ // 5.12.0: a presented-but-rejected id (malformed / unknown) carries
4545
+ // actionable registration guidance on its failure — surface it
4546
+ // instead of the bare machine reason ('unknown_agent').
4547
+ message: rejectedIdentityGuidance(aggregatedFailures) ?? (apiResponse.access?.reason || "Access denied by PDLSS policy"),
4482
4548
  registrationUrl: urls?.registrationUrl ?? "",
4483
4549
  documentationUrl: urls?.documentationUrl ?? "",
4484
4550
  // 5.1.0: anonymous callers land on this branch — steer MCP-hosted
@@ -4578,7 +4644,7 @@ async function verify(config, request, options) {
4578
4644
  registrationUrl: urls?.registrationUrl ?? "",
4579
4645
  documentationUrl: urls?.documentationUrl ?? ""
4580
4646
  };
4581
- } else if (result.recommendation === "step_up_required") {
4647
+ } else if (result.recommendation === "step_up_required" && result.identityVerified) {
4582
4648
  result.requiresStepUp = true;
4583
4649
  result.denialReasons = serverDenialReasons ?? result.recommendationReasons ?? ["Step-up verification required"];
4584
4650
  }
@@ -4607,6 +4673,217 @@ var DEFAULT_EDGE_CONFIG = Object.freeze({
4607
4673
  var DEFAULT_TTL_MS = 60 * 1e3;
4608
4674
  var DEFAULT_MAX_STALE_MS = 24 * 60 * 60 * 1e3;
4609
4675
 
4676
+ // src/edge-core/events.ts
4677
+ async function withBudget(promise, ms) {
4678
+ let timer;
4679
+ try {
4680
+ return await Promise.race([
4681
+ promise,
4682
+ new Promise((resolve) => {
4683
+ timer = setTimeout(() => resolve(void 0), ms);
4684
+ })
4685
+ ]);
4686
+ } catch {
4687
+ return void 0;
4688
+ } finally {
4689
+ if (timer) clearTimeout(timer);
4690
+ }
4691
+ }
4692
+ var destKeyOf = (d) => `${d.apiBaseUrl}\0${d.apiKey ?? ""}\0${d.counterparty}\0${d.adapter ?? ""}`;
4693
+ var BeaconBuffer = class {
4694
+ constructor(options = {}) {
4695
+ this.queue = [];
4696
+ this.droppedSinceLast = 0;
4697
+ this.droppedTotal = 0;
4698
+ this.deliveredTotal = 0;
4699
+ this.backoffUntil = 0;
4700
+ this.collapse = /* @__PURE__ */ new Map();
4701
+ /** Keys the backend answered 401 for — later batches go unauthenticated. */
4702
+ this.rejectedKeys = /* @__PURE__ */ new Set();
4703
+ this.opts = {
4704
+ maxItems: options.maxItems ?? 1e3,
4705
+ maxBatch: options.maxBatch ?? 100,
4706
+ maxAttempts: options.maxAttempts ?? 3,
4707
+ collapseWindowMs: options.collapseWindowMs ?? 6e4,
4708
+ collapseMaxKeys: options.collapseMaxKeys ?? 1e3,
4709
+ requestTimeoutMs: options.requestTimeoutMs ?? 1e4,
4710
+ retryBackoffMs: options.retryBackoffMs ?? 1e3,
4711
+ now: options.now ?? Date.now
4712
+ };
4713
+ }
4714
+ /**
4715
+ * Queue one beacon. With a `collapseKey`, a repeat inside the window is
4716
+ * merged into a held aggregate (sent when the window closes) instead of
4717
+ * becoming its own item.
4718
+ */
4719
+ enqueue(dest, item, collapseKey) {
4720
+ const now = this.opts.now();
4721
+ if (collapseKey) {
4722
+ const entry = this.collapse.get(collapseKey);
4723
+ if (entry && now - entry.firstSeenAt < this.opts.collapseWindowMs) {
4724
+ for (const target of [entry.first, entry.held]) {
4725
+ if (target && !target.inFlight && this.queue.includes(target)) {
4726
+ target.item.repeatCount = (target.item.repeatCount ?? 1) + 1;
4727
+ return;
4728
+ }
4729
+ }
4730
+ const held = this.push(
4731
+ dest,
4732
+ { ...item, repeatCount: 1 },
4733
+ entry.firstSeenAt + this.opts.collapseWindowMs
4734
+ );
4735
+ entry.held = held;
4736
+ return;
4737
+ }
4738
+ this.collapse.delete(collapseKey);
4739
+ if (this.collapse.size >= this.opts.collapseMaxKeys) {
4740
+ const oldest = this.collapse.keys().next().value;
4741
+ if (oldest !== void 0) this.collapse.delete(oldest);
4742
+ }
4743
+ const fresh = { firstSeenAt: now };
4744
+ this.collapse.set(collapseKey, fresh);
4745
+ fresh.first = this.push(dest, item, now);
4746
+ return;
4747
+ }
4748
+ this.push(dest, item, now);
4749
+ }
4750
+ /**
4751
+ * Deliver every eligible queued item. Concurrent callers share ONE
4752
+ * in-flight drain (it survives the caller's budget and a Lambda freeze),
4753
+ * so nothing in flight is ever sent twice; items queued while it runs are
4754
+ * picked up by the same drain.
4755
+ */
4756
+ flush() {
4757
+ if (!this.inFlight) {
4758
+ this.inFlight = this.drain().finally(() => {
4759
+ this.inFlight = void 0;
4760
+ });
4761
+ }
4762
+ return this.inFlight;
4763
+ }
4764
+ /** Counters for tests and diagnostics. */
4765
+ stats() {
4766
+ return {
4767
+ queueDepth: this.queue.length,
4768
+ droppedSinceLast: this.droppedSinceLast,
4769
+ droppedTotal: this.droppedTotal,
4770
+ deliveredTotal: this.deliveredTotal,
4771
+ flushing: this.inFlight !== void 0
4772
+ };
4773
+ }
4774
+ push(dest, item, eligibleAt) {
4775
+ while (this.queue.length >= this.opts.maxItems) this.dropOldest();
4776
+ const entry = {
4777
+ dest,
4778
+ destKey: destKeyOf(dest),
4779
+ item,
4780
+ attempts: 0,
4781
+ eligibleAt,
4782
+ inFlight: false
4783
+ };
4784
+ this.queue.push(entry);
4785
+ return entry;
4786
+ }
4787
+ dropOldest() {
4788
+ if (this.queue.shift()) this.countDropped(1);
4789
+ }
4790
+ countDropped(n) {
4791
+ this.droppedSinceLast += n;
4792
+ this.droppedTotal += n;
4793
+ }
4794
+ async drain() {
4795
+ for (; ; ) {
4796
+ const now = this.opts.now();
4797
+ if (now < this.backoffUntil) return;
4798
+ const batch = this.takeBatch(now);
4799
+ if (batch.length === 0) return;
4800
+ const ok = await this.send(batch);
4801
+ if (!ok) return;
4802
+ }
4803
+ }
4804
+ /** Oldest eligible item + up to maxBatch-1 more for the same destination. */
4805
+ takeBatch(now) {
4806
+ const first = this.queue.find((q) => q.eligibleAt <= now);
4807
+ if (!first) return [];
4808
+ const batch = [];
4809
+ const rest = [];
4810
+ for (const q of this.queue) {
4811
+ if (batch.length < this.opts.maxBatch && q.destKey === first.destKey && q.eligibleAt <= now) {
4812
+ q.inFlight = true;
4813
+ batch.push(q);
4814
+ } else {
4815
+ rest.push(q);
4816
+ }
4817
+ }
4818
+ this.queue = rest;
4819
+ return batch;
4820
+ }
4821
+ /** POST one batch. Returns false when the drain should pause (backoff). */
4822
+ async send(batch) {
4823
+ const dest = batch[0].dest;
4824
+ const useKey = dest.apiKey && !this.rejectedKeys.has(dest.apiKey) ? dest.apiKey : void 0;
4825
+ const reportedDropped = this.droppedSinceLast;
4826
+ const meta = {
4827
+ droppedSinceLast: reportedDropped,
4828
+ queueDepth: this.queue.length,
4829
+ adapter: dest.adapter ?? "edge-core",
4830
+ version: SDK_VERSION
4831
+ };
4832
+ const controller = typeof AbortController !== "undefined" ? new AbortController() : void 0;
4833
+ const response = await withBudget(
4834
+ sdkFetch(`${dest.apiBaseUrl}/verification-activity/edge-events`, {
4835
+ method: "POST",
4836
+ headers: {
4837
+ "Content-Type": "application/json",
4838
+ ...useKey && { Authorization: `Bearer ${useKey}` }
4839
+ },
4840
+ body: JSON.stringify({ events: batch.map((q) => q.item), meta }),
4841
+ ...controller && { signal: controller.signal }
4842
+ }),
4843
+ this.opts.requestTimeoutMs
4844
+ );
4845
+ if (!response) controller?.abort();
4846
+ const status = response?.status;
4847
+ for (const q of batch) q.inFlight = false;
4848
+ if (status !== void 0 && status >= 200 && status < 300) {
4849
+ this.droppedSinceLast = Math.max(0, this.droppedSinceLast - reportedDropped);
4850
+ this.deliveredTotal += batch.length;
4851
+ return true;
4852
+ }
4853
+ if (status === 401 && useKey) {
4854
+ this.rejectedKeys.add(useKey);
4855
+ this.requeue(batch, false);
4856
+ return true;
4857
+ }
4858
+ if (status === 429) {
4859
+ const retryAfter = Number(response?.headers.get("retry-after"));
4860
+ const waitMs = Number.isFinite(retryAfter) && retryAfter > 0 ? Math.min(retryAfter, 120) * 1e3 : 3e4;
4861
+ this.backoffUntil = this.opts.now() + waitMs;
4862
+ this.requeue(batch, false);
4863
+ return false;
4864
+ }
4865
+ if (status !== void 0 && status >= 400 && status < 500) {
4866
+ this.countDropped(batch.length);
4867
+ return true;
4868
+ }
4869
+ this.backoffUntil = this.opts.now() + this.opts.retryBackoffMs;
4870
+ this.requeue(batch, true);
4871
+ return false;
4872
+ }
4873
+ /** Put a failed batch back at the head of the queue (order preserved). */
4874
+ requeue(batch, countAttempt) {
4875
+ const keep = [];
4876
+ for (const q of batch) {
4877
+ if (countAttempt) q.attempts += 1;
4878
+ if (q.attempts >= this.opts.maxAttempts) this.countDropped(1);
4879
+ else keep.push(q);
4880
+ }
4881
+ this.queue = [...keep, ...this.queue];
4882
+ while (this.queue.length > this.opts.maxItems) this.dropOldest();
4883
+ }
4884
+ };
4885
+ var beaconBuffer = new BeaconBuffer();
4886
+
4610
4887
  // src/adapters/express.ts
4611
4888
  var DEFAULT_ROUTES_REFRESH_MS = 5 * 60 * 1e3;
4612
4889