@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
@@ -3752,7 +3752,7 @@ function getTrustLevel(score) {
3752
3752
  }
3753
3753
 
3754
3754
  // src/version.ts
3755
- var SDK_VERSION = "5.11.0";
3755
+ var SDK_VERSION = "5.12.0";
3756
3756
 
3757
3757
  // src/http.ts
3758
3758
  var SDK_USER_AGENT = `astrasync-sdk/${SDK_VERSION}`;
@@ -3779,6 +3779,14 @@ function getCachedWellKnownUrls(apiBaseUrl) {
3779
3779
  return cache.get(apiBaseUrl)?.data;
3780
3780
  }
3781
3781
 
3782
+ // src/failure-posture.ts
3783
+ var REJECTED_IDENTITY_DIMENSIONS = /* @__PURE__ */ new Set([
3784
+ "identity.invalid_agent_id",
3785
+ "identity.unknown_agent",
3786
+ "agent.lookup"
3787
+ ]);
3788
+ 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.";
3789
+
3782
3790
  // src/verify.ts
3783
3791
  var DEFAULT_CONFIG = {
3784
3792
  apiBaseUrl: "https://astrasync.ai/api",
@@ -3990,11 +3998,44 @@ function createGuidanceResponse(_config, reason, options = {}) {
3990
3998
  // coercing the absent recommendation to a policy 'deny'. Misconfig is
3991
3999
  // deterministic and intentionally NOT marked retryable.
3992
4000
  ...isApiError && { retryable: true },
4001
+ ...options.httpStatus !== void 0 && { httpStatus: options.httpStatus },
4002
+ ...options.retryAfterMs !== void 0 && { retryAfterMs: options.retryAfterMs },
3993
4003
  correlationId: options.correlationId,
3994
4004
  attemptId: options.attemptId,
3995
4005
  verifiedAt: /* @__PURE__ */ new Date()
3996
4006
  };
3997
4007
  }
4008
+ async function readJsonSafe(response) {
4009
+ try {
4010
+ const parsed = await response.json();
4011
+ return parsed && typeof parsed === "object" ? parsed : {};
4012
+ } catch {
4013
+ return {};
4014
+ }
4015
+ }
4016
+ function rejectedIdentityGuidance(failures) {
4017
+ const f = failures?.find((x) => REJECTED_IDENTITY_DIMENSIONS.has(x.dimension));
4018
+ if (!f) return void 0;
4019
+ if (f.dimension === "agent.lookup") {
4020
+ return `The presented agent identifier is not registered with AstraSync. ${UNKNOWN_AGENT_GUIDANCE}`;
4021
+ }
4022
+ return f.guidance ? `${f.message} ${f.guidance}` : f.message;
4023
+ }
4024
+ var MAX_RETRY_AFTER_MS = 15 * 60 * 1e3;
4025
+ function parseRetryAfterMs(response) {
4026
+ const raw = response.headers?.get?.("retry-after");
4027
+ if (!raw) return void 0;
4028
+ const trimmed = raw.trim();
4029
+ let ms;
4030
+ if (/^\d+(\.\d+)?$/.test(trimmed)) {
4031
+ ms = Number(trimmed) * 1e3;
4032
+ } else {
4033
+ const at = Date.parse(trimmed);
4034
+ if (Number.isNaN(at)) return void 0;
4035
+ ms = at - Date.now();
4036
+ }
4037
+ return Math.min(MAX_RETRY_AFTER_MS, Math.max(0, Math.round(ms)));
4038
+ }
3998
4039
  async function callVerifyAccessAPI(config, request) {
3999
4040
  const { credentials, ...requestData } = request;
4000
4041
  const body = {
@@ -4051,7 +4092,8 @@ async function callVerifyAccessAPI(config, request) {
4051
4092
  body: JSON.stringify(body),
4052
4093
  signal: AbortSignal.timeout(config.verifyTimeoutMs ?? 1e4)
4053
4094
  });
4054
- const data = await response.json();
4095
+ const data = await readJsonSafe(response);
4096
+ const retryAfterMs = parseRetryAfterMs(response);
4055
4097
  if (response.status === 410) {
4056
4098
  return {
4057
4099
  success: true,
@@ -4089,6 +4131,23 @@ async function callVerifyAccessAPI(config, request) {
4089
4131
  }
4090
4132
  };
4091
4133
  }
4134
+ if (response.status === 404 && credentials.astraId && (data?.error === "AGENT_NOT_FOUND" || typeof data?.message === "string" && /agent/i.test(data.message))) {
4135
+ return {
4136
+ success: true,
4137
+ attemptId: typeof data?.attemptId === "string" ? data.attemptId : void 0,
4138
+ access: {
4139
+ allowed: false,
4140
+ reason: "unknown_agent",
4141
+ failures: [
4142
+ {
4143
+ dimension: "identity.unknown_agent",
4144
+ message: "The presented agent identifier is not registered with AstraSync.",
4145
+ guidance: UNKNOWN_AGENT_GUIDANCE
4146
+ }
4147
+ ]
4148
+ }
4149
+ };
4150
+ }
4092
4151
  if (!response.ok) {
4093
4152
  if (response.status === 401) {
4094
4153
  return {
@@ -4103,9 +4162,11 @@ async function callVerifyAccessAPI(config, request) {
4103
4162
  }
4104
4163
  return {
4105
4164
  success: false,
4106
- error: data.message || data.error || `API returned ${response.status}`,
4165
+ error: typeof data?.message === "string" && data.message || typeof data?.error === "string" && data.error || `API returned ${response.status}`,
4107
4166
  correlationId: typeof data?.correlationId === "string" ? data.correlationId : void 0,
4108
- attemptId: typeof data?.attemptId === "string" ? data.attemptId : void 0
4167
+ attemptId: typeof data?.attemptId === "string" ? data.attemptId : void 0,
4168
+ httpStatus: response.status,
4169
+ ...retryAfterMs !== void 0 && { retryAfterMs }
4109
4170
  };
4110
4171
  }
4111
4172
  return data;
@@ -4177,12 +4238,14 @@ async function verify(config, request, options) {
4177
4238
  correlationId: apiResponse.correlationId,
4178
4239
  attemptId: apiResponse.attemptId,
4179
4240
  remediation: apiResponse.remediation,
4241
+ httpStatus: apiResponse.httpStatus,
4242
+ retryAfterMs: apiResponse.retryAfterMs,
4180
4243
  urls
4181
4244
  });
4182
4245
  }
4183
4246
  if (!apiResponse.access?.allowed) {
4184
4247
  const aggregatedFailures = apiResponse.access?.failures;
4185
- const idVerifiedFromBackend = apiResponse.verificationContext?.idVerified === true;
4248
+ const idVerifiedFromBackend = apiResponse.verificationContext?.idVerified === true && !aggregatedFailures?.some((f) => REJECTED_IDENTITY_DIMENSIONS.has(f.dimension));
4186
4249
  const result2 = {
4187
4250
  identityVerified: idVerifiedFromBackend,
4188
4251
  policyAllowed: false,
@@ -4194,7 +4257,10 @@ async function verify(config, request, options) {
4194
4257
  requiresStepUp: apiResponse.access?.requiresStepUp,
4195
4258
  requiresApproval: apiResponse.access?.requiresApproval,
4196
4259
  guidance: {
4197
- message: apiResponse.access?.reason || "Access denied by PDLSS policy",
4260
+ // 5.12.0: a presented-but-rejected id (malformed / unknown) carries
4261
+ // actionable registration guidance on its failure — surface it
4262
+ // instead of the bare machine reason ('unknown_agent').
4263
+ message: rejectedIdentityGuidance(aggregatedFailures) ?? (apiResponse.access?.reason || "Access denied by PDLSS policy"),
4198
4264
  registrationUrl: urls?.registrationUrl ?? "",
4199
4265
  documentationUrl: urls?.documentationUrl ?? "",
4200
4266
  // 5.1.0: anonymous callers land on this branch — steer MCP-hosted
@@ -4294,7 +4360,7 @@ async function verify(config, request, options) {
4294
4360
  registrationUrl: urls?.registrationUrl ?? "",
4295
4361
  documentationUrl: urls?.documentationUrl ?? ""
4296
4362
  };
4297
- } else if (result.recommendation === "step_up_required") {
4363
+ } else if (result.recommendation === "step_up_required" && result.identityVerified) {
4298
4364
  result.requiresStepUp = true;
4299
4365
  result.denialReasons = serverDenialReasons ?? result.recommendationReasons ?? ["Step-up verification required"];
4300
4366
  }
@@ -4323,6 +4389,217 @@ var DEFAULT_EDGE_CONFIG = Object.freeze({
4323
4389
  var DEFAULT_TTL_MS = 60 * 1e3;
4324
4390
  var DEFAULT_MAX_STALE_MS = 24 * 60 * 60 * 1e3;
4325
4391
 
4392
+ // src/edge-core/events.ts
4393
+ async function withBudget(promise, ms) {
4394
+ let timer;
4395
+ try {
4396
+ return await Promise.race([
4397
+ promise,
4398
+ new Promise((resolve) => {
4399
+ timer = setTimeout(() => resolve(void 0), ms);
4400
+ })
4401
+ ]);
4402
+ } catch {
4403
+ return void 0;
4404
+ } finally {
4405
+ if (timer) clearTimeout(timer);
4406
+ }
4407
+ }
4408
+ var destKeyOf = (d) => `${d.apiBaseUrl}\0${d.apiKey ?? ""}\0${d.counterparty}\0${d.adapter ?? ""}`;
4409
+ var BeaconBuffer = class {
4410
+ constructor(options = {}) {
4411
+ this.queue = [];
4412
+ this.droppedSinceLast = 0;
4413
+ this.droppedTotal = 0;
4414
+ this.deliveredTotal = 0;
4415
+ this.backoffUntil = 0;
4416
+ this.collapse = /* @__PURE__ */ new Map();
4417
+ /** Keys the backend answered 401 for — later batches go unauthenticated. */
4418
+ this.rejectedKeys = /* @__PURE__ */ new Set();
4419
+ this.opts = {
4420
+ maxItems: options.maxItems ?? 1e3,
4421
+ maxBatch: options.maxBatch ?? 100,
4422
+ maxAttempts: options.maxAttempts ?? 3,
4423
+ collapseWindowMs: options.collapseWindowMs ?? 6e4,
4424
+ collapseMaxKeys: options.collapseMaxKeys ?? 1e3,
4425
+ requestTimeoutMs: options.requestTimeoutMs ?? 1e4,
4426
+ retryBackoffMs: options.retryBackoffMs ?? 1e3,
4427
+ now: options.now ?? Date.now
4428
+ };
4429
+ }
4430
+ /**
4431
+ * Queue one beacon. With a `collapseKey`, a repeat inside the window is
4432
+ * merged into a held aggregate (sent when the window closes) instead of
4433
+ * becoming its own item.
4434
+ */
4435
+ enqueue(dest, item, collapseKey) {
4436
+ const now = this.opts.now();
4437
+ if (collapseKey) {
4438
+ const entry = this.collapse.get(collapseKey);
4439
+ if (entry && now - entry.firstSeenAt < this.opts.collapseWindowMs) {
4440
+ for (const target of [entry.first, entry.held]) {
4441
+ if (target && !target.inFlight && this.queue.includes(target)) {
4442
+ target.item.repeatCount = (target.item.repeatCount ?? 1) + 1;
4443
+ return;
4444
+ }
4445
+ }
4446
+ const held = this.push(
4447
+ dest,
4448
+ { ...item, repeatCount: 1 },
4449
+ entry.firstSeenAt + this.opts.collapseWindowMs
4450
+ );
4451
+ entry.held = held;
4452
+ return;
4453
+ }
4454
+ this.collapse.delete(collapseKey);
4455
+ if (this.collapse.size >= this.opts.collapseMaxKeys) {
4456
+ const oldest = this.collapse.keys().next().value;
4457
+ if (oldest !== void 0) this.collapse.delete(oldest);
4458
+ }
4459
+ const fresh = { firstSeenAt: now };
4460
+ this.collapse.set(collapseKey, fresh);
4461
+ fresh.first = this.push(dest, item, now);
4462
+ return;
4463
+ }
4464
+ this.push(dest, item, now);
4465
+ }
4466
+ /**
4467
+ * Deliver every eligible queued item. Concurrent callers share ONE
4468
+ * in-flight drain (it survives the caller's budget and a Lambda freeze),
4469
+ * so nothing in flight is ever sent twice; items queued while it runs are
4470
+ * picked up by the same drain.
4471
+ */
4472
+ flush() {
4473
+ if (!this.inFlight) {
4474
+ this.inFlight = this.drain().finally(() => {
4475
+ this.inFlight = void 0;
4476
+ });
4477
+ }
4478
+ return this.inFlight;
4479
+ }
4480
+ /** Counters for tests and diagnostics. */
4481
+ stats() {
4482
+ return {
4483
+ queueDepth: this.queue.length,
4484
+ droppedSinceLast: this.droppedSinceLast,
4485
+ droppedTotal: this.droppedTotal,
4486
+ deliveredTotal: this.deliveredTotal,
4487
+ flushing: this.inFlight !== void 0
4488
+ };
4489
+ }
4490
+ push(dest, item, eligibleAt) {
4491
+ while (this.queue.length >= this.opts.maxItems) this.dropOldest();
4492
+ const entry = {
4493
+ dest,
4494
+ destKey: destKeyOf(dest),
4495
+ item,
4496
+ attempts: 0,
4497
+ eligibleAt,
4498
+ inFlight: false
4499
+ };
4500
+ this.queue.push(entry);
4501
+ return entry;
4502
+ }
4503
+ dropOldest() {
4504
+ if (this.queue.shift()) this.countDropped(1);
4505
+ }
4506
+ countDropped(n) {
4507
+ this.droppedSinceLast += n;
4508
+ this.droppedTotal += n;
4509
+ }
4510
+ async drain() {
4511
+ for (; ; ) {
4512
+ const now = this.opts.now();
4513
+ if (now < this.backoffUntil) return;
4514
+ const batch = this.takeBatch(now);
4515
+ if (batch.length === 0) return;
4516
+ const ok = await this.send(batch);
4517
+ if (!ok) return;
4518
+ }
4519
+ }
4520
+ /** Oldest eligible item + up to maxBatch-1 more for the same destination. */
4521
+ takeBatch(now) {
4522
+ const first = this.queue.find((q) => q.eligibleAt <= now);
4523
+ if (!first) return [];
4524
+ const batch = [];
4525
+ const rest = [];
4526
+ for (const q of this.queue) {
4527
+ if (batch.length < this.opts.maxBatch && q.destKey === first.destKey && q.eligibleAt <= now) {
4528
+ q.inFlight = true;
4529
+ batch.push(q);
4530
+ } else {
4531
+ rest.push(q);
4532
+ }
4533
+ }
4534
+ this.queue = rest;
4535
+ return batch;
4536
+ }
4537
+ /** POST one batch. Returns false when the drain should pause (backoff). */
4538
+ async send(batch) {
4539
+ const dest = batch[0].dest;
4540
+ const useKey = dest.apiKey && !this.rejectedKeys.has(dest.apiKey) ? dest.apiKey : void 0;
4541
+ const reportedDropped = this.droppedSinceLast;
4542
+ const meta = {
4543
+ droppedSinceLast: reportedDropped,
4544
+ queueDepth: this.queue.length,
4545
+ adapter: dest.adapter ?? "edge-core",
4546
+ version: SDK_VERSION
4547
+ };
4548
+ const controller = typeof AbortController !== "undefined" ? new AbortController() : void 0;
4549
+ const response = await withBudget(
4550
+ sdkFetch(`${dest.apiBaseUrl}/verification-activity/edge-events`, {
4551
+ method: "POST",
4552
+ headers: {
4553
+ "Content-Type": "application/json",
4554
+ ...useKey && { Authorization: `Bearer ${useKey}` }
4555
+ },
4556
+ body: JSON.stringify({ events: batch.map((q) => q.item), meta }),
4557
+ ...controller && { signal: controller.signal }
4558
+ }),
4559
+ this.opts.requestTimeoutMs
4560
+ );
4561
+ if (!response) controller?.abort();
4562
+ const status = response?.status;
4563
+ for (const q of batch) q.inFlight = false;
4564
+ if (status !== void 0 && status >= 200 && status < 300) {
4565
+ this.droppedSinceLast = Math.max(0, this.droppedSinceLast - reportedDropped);
4566
+ this.deliveredTotal += batch.length;
4567
+ return true;
4568
+ }
4569
+ if (status === 401 && useKey) {
4570
+ this.rejectedKeys.add(useKey);
4571
+ this.requeue(batch, false);
4572
+ return true;
4573
+ }
4574
+ if (status === 429) {
4575
+ const retryAfter = Number(response?.headers.get("retry-after"));
4576
+ const waitMs = Number.isFinite(retryAfter) && retryAfter > 0 ? Math.min(retryAfter, 120) * 1e3 : 3e4;
4577
+ this.backoffUntil = this.opts.now() + waitMs;
4578
+ this.requeue(batch, false);
4579
+ return false;
4580
+ }
4581
+ if (status !== void 0 && status >= 400 && status < 500) {
4582
+ this.countDropped(batch.length);
4583
+ return true;
4584
+ }
4585
+ this.backoffUntil = this.opts.now() + this.opts.retryBackoffMs;
4586
+ this.requeue(batch, true);
4587
+ return false;
4588
+ }
4589
+ /** Put a failed batch back at the head of the queue (order preserved). */
4590
+ requeue(batch, countAttempt) {
4591
+ const keep = [];
4592
+ for (const q of batch) {
4593
+ if (countAttempt) q.attempts += 1;
4594
+ if (q.attempts >= this.opts.maxAttempts) this.countDropped(1);
4595
+ else keep.push(q);
4596
+ }
4597
+ this.queue = [...keep, ...this.queue];
4598
+ while (this.queue.length > this.opts.maxItems) this.dropOldest();
4599
+ }
4600
+ };
4601
+ var beaconBuffer = new BeaconBuffer();
4602
+
4326
4603
  // src/adapters/express.ts
4327
4604
  var DEFAULT_ROUTES_REFRESH_MS = 5 * 60 * 1e3;
4328
4605