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