@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
@@ -3722,7 +3722,7 @@ function getTrustLevel(score) {
3722
3722
  }
3723
3723
 
3724
3724
  // src/version.ts
3725
- var SDK_VERSION = "5.11.0";
3725
+ var SDK_VERSION = "5.12.0";
3726
3726
 
3727
3727
  // src/http.ts
3728
3728
  var SDK_USER_AGENT = `astrasync-sdk/${SDK_VERSION}`;
@@ -3749,6 +3749,14 @@ function getCachedWellKnownUrls(apiBaseUrl) {
3749
3749
  return cache.get(apiBaseUrl)?.data;
3750
3750
  }
3751
3751
 
3752
+ // src/failure-posture.ts
3753
+ var REJECTED_IDENTITY_DIMENSIONS = /* @__PURE__ */ new Set([
3754
+ "identity.invalid_agent_id",
3755
+ "identity.unknown_agent",
3756
+ "agent.lookup"
3757
+ ]);
3758
+ 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.";
3759
+
3752
3760
  // src/verify.ts
3753
3761
  var DEFAULT_CONFIG = {
3754
3762
  apiBaseUrl: "https://astrasync.ai/api",
@@ -3960,11 +3968,44 @@ function createGuidanceResponse(_config, reason, options = {}) {
3960
3968
  // coercing the absent recommendation to a policy 'deny'. Misconfig is
3961
3969
  // deterministic and intentionally NOT marked retryable.
3962
3970
  ...isApiError && { retryable: true },
3971
+ ...options.httpStatus !== void 0 && { httpStatus: options.httpStatus },
3972
+ ...options.retryAfterMs !== void 0 && { retryAfterMs: options.retryAfterMs },
3963
3973
  correlationId: options.correlationId,
3964
3974
  attemptId: options.attemptId,
3965
3975
  verifiedAt: /* @__PURE__ */ new Date()
3966
3976
  };
3967
3977
  }
3978
+ async function readJsonSafe(response) {
3979
+ try {
3980
+ const parsed = await response.json();
3981
+ return parsed && typeof parsed === "object" ? parsed : {};
3982
+ } catch {
3983
+ return {};
3984
+ }
3985
+ }
3986
+ function rejectedIdentityGuidance(failures) {
3987
+ const f = failures?.find((x) => REJECTED_IDENTITY_DIMENSIONS.has(x.dimension));
3988
+ if (!f) return void 0;
3989
+ if (f.dimension === "agent.lookup") {
3990
+ return `The presented agent identifier is not registered with AstraSync. ${UNKNOWN_AGENT_GUIDANCE}`;
3991
+ }
3992
+ return f.guidance ? `${f.message} ${f.guidance}` : f.message;
3993
+ }
3994
+ var MAX_RETRY_AFTER_MS = 15 * 60 * 1e3;
3995
+ function parseRetryAfterMs(response) {
3996
+ const raw = response.headers?.get?.("retry-after");
3997
+ if (!raw) return void 0;
3998
+ const trimmed = raw.trim();
3999
+ let ms;
4000
+ if (/^\d+(\.\d+)?$/.test(trimmed)) {
4001
+ ms = Number(trimmed) * 1e3;
4002
+ } else {
4003
+ const at = Date.parse(trimmed);
4004
+ if (Number.isNaN(at)) return void 0;
4005
+ ms = at - Date.now();
4006
+ }
4007
+ return Math.min(MAX_RETRY_AFTER_MS, Math.max(0, Math.round(ms)));
4008
+ }
3968
4009
  async function callVerifyAccessAPI(config, request) {
3969
4010
  const { credentials, ...requestData } = request;
3970
4011
  const body = {
@@ -4021,7 +4062,8 @@ async function callVerifyAccessAPI(config, request) {
4021
4062
  body: JSON.stringify(body),
4022
4063
  signal: AbortSignal.timeout(config.verifyTimeoutMs ?? 1e4)
4023
4064
  });
4024
- const data = await response.json();
4065
+ const data = await readJsonSafe(response);
4066
+ const retryAfterMs = parseRetryAfterMs(response);
4025
4067
  if (response.status === 410) {
4026
4068
  return {
4027
4069
  success: true,
@@ -4059,6 +4101,23 @@ async function callVerifyAccessAPI(config, request) {
4059
4101
  }
4060
4102
  };
4061
4103
  }
4104
+ if (response.status === 404 && credentials.astraId && (data?.error === "AGENT_NOT_FOUND" || typeof data?.message === "string" && /agent/i.test(data.message))) {
4105
+ return {
4106
+ success: true,
4107
+ attemptId: typeof data?.attemptId === "string" ? data.attemptId : void 0,
4108
+ access: {
4109
+ allowed: false,
4110
+ reason: "unknown_agent",
4111
+ failures: [
4112
+ {
4113
+ dimension: "identity.unknown_agent",
4114
+ message: "The presented agent identifier is not registered with AstraSync.",
4115
+ guidance: UNKNOWN_AGENT_GUIDANCE
4116
+ }
4117
+ ]
4118
+ }
4119
+ };
4120
+ }
4062
4121
  if (!response.ok) {
4063
4122
  if (response.status === 401) {
4064
4123
  return {
@@ -4073,9 +4132,11 @@ async function callVerifyAccessAPI(config, request) {
4073
4132
  }
4074
4133
  return {
4075
4134
  success: false,
4076
- error: data.message || data.error || `API returned ${response.status}`,
4135
+ error: typeof data?.message === "string" && data.message || typeof data?.error === "string" && data.error || `API returned ${response.status}`,
4077
4136
  correlationId: typeof data?.correlationId === "string" ? data.correlationId : void 0,
4078
- attemptId: typeof data?.attemptId === "string" ? data.attemptId : void 0
4137
+ attemptId: typeof data?.attemptId === "string" ? data.attemptId : void 0,
4138
+ httpStatus: response.status,
4139
+ ...retryAfterMs !== void 0 && { retryAfterMs }
4079
4140
  };
4080
4141
  }
4081
4142
  return data;
@@ -4147,12 +4208,14 @@ async function verify(config, request, options) {
4147
4208
  correlationId: apiResponse.correlationId,
4148
4209
  attemptId: apiResponse.attemptId,
4149
4210
  remediation: apiResponse.remediation,
4211
+ httpStatus: apiResponse.httpStatus,
4212
+ retryAfterMs: apiResponse.retryAfterMs,
4150
4213
  urls
4151
4214
  });
4152
4215
  }
4153
4216
  if (!apiResponse.access?.allowed) {
4154
4217
  const aggregatedFailures = apiResponse.access?.failures;
4155
- const idVerifiedFromBackend = apiResponse.verificationContext?.idVerified === true;
4218
+ const idVerifiedFromBackend = apiResponse.verificationContext?.idVerified === true && !aggregatedFailures?.some((f) => REJECTED_IDENTITY_DIMENSIONS.has(f.dimension));
4156
4219
  const result2 = {
4157
4220
  identityVerified: idVerifiedFromBackend,
4158
4221
  policyAllowed: false,
@@ -4164,7 +4227,10 @@ async function verify(config, request, options) {
4164
4227
  requiresStepUp: apiResponse.access?.requiresStepUp,
4165
4228
  requiresApproval: apiResponse.access?.requiresApproval,
4166
4229
  guidance: {
4167
- message: apiResponse.access?.reason || "Access denied by PDLSS policy",
4230
+ // 5.12.0: a presented-but-rejected id (malformed / unknown) carries
4231
+ // actionable registration guidance on its failure — surface it
4232
+ // instead of the bare machine reason ('unknown_agent').
4233
+ message: rejectedIdentityGuidance(aggregatedFailures) ?? (apiResponse.access?.reason || "Access denied by PDLSS policy"),
4168
4234
  registrationUrl: urls?.registrationUrl ?? "",
4169
4235
  documentationUrl: urls?.documentationUrl ?? "",
4170
4236
  // 5.1.0: anonymous callers land on this branch — steer MCP-hosted
@@ -4264,7 +4330,7 @@ async function verify(config, request, options) {
4264
4330
  registrationUrl: urls?.registrationUrl ?? "",
4265
4331
  documentationUrl: urls?.documentationUrl ?? ""
4266
4332
  };
4267
- } else if (result.recommendation === "step_up_required") {
4333
+ } else if (result.recommendation === "step_up_required" && result.identityVerified) {
4268
4334
  result.requiresStepUp = true;
4269
4335
  result.denialReasons = serverDenialReasons ?? result.recommendationReasons ?? ["Step-up verification required"];
4270
4336
  }
@@ -4293,6 +4359,217 @@ var DEFAULT_EDGE_CONFIG = Object.freeze({
4293
4359
  var DEFAULT_TTL_MS = 60 * 1e3;
4294
4360
  var DEFAULT_MAX_STALE_MS = 24 * 60 * 60 * 1e3;
4295
4361
 
4362
+ // src/edge-core/events.ts
4363
+ async function withBudget(promise, ms) {
4364
+ let timer;
4365
+ try {
4366
+ return await Promise.race([
4367
+ promise,
4368
+ new Promise((resolve) => {
4369
+ timer = setTimeout(() => resolve(void 0), ms);
4370
+ })
4371
+ ]);
4372
+ } catch {
4373
+ return void 0;
4374
+ } finally {
4375
+ if (timer) clearTimeout(timer);
4376
+ }
4377
+ }
4378
+ var destKeyOf = (d) => `${d.apiBaseUrl}\0${d.apiKey ?? ""}\0${d.counterparty}\0${d.adapter ?? ""}`;
4379
+ var BeaconBuffer = class {
4380
+ constructor(options = {}) {
4381
+ this.queue = [];
4382
+ this.droppedSinceLast = 0;
4383
+ this.droppedTotal = 0;
4384
+ this.deliveredTotal = 0;
4385
+ this.backoffUntil = 0;
4386
+ this.collapse = /* @__PURE__ */ new Map();
4387
+ /** Keys the backend answered 401 for — later batches go unauthenticated. */
4388
+ this.rejectedKeys = /* @__PURE__ */ new Set();
4389
+ this.opts = {
4390
+ maxItems: options.maxItems ?? 1e3,
4391
+ maxBatch: options.maxBatch ?? 100,
4392
+ maxAttempts: options.maxAttempts ?? 3,
4393
+ collapseWindowMs: options.collapseWindowMs ?? 6e4,
4394
+ collapseMaxKeys: options.collapseMaxKeys ?? 1e3,
4395
+ requestTimeoutMs: options.requestTimeoutMs ?? 1e4,
4396
+ retryBackoffMs: options.retryBackoffMs ?? 1e3,
4397
+ now: options.now ?? Date.now
4398
+ };
4399
+ }
4400
+ /**
4401
+ * Queue one beacon. With a `collapseKey`, a repeat inside the window is
4402
+ * merged into a held aggregate (sent when the window closes) instead of
4403
+ * becoming its own item.
4404
+ */
4405
+ enqueue(dest, item, collapseKey) {
4406
+ const now = this.opts.now();
4407
+ if (collapseKey) {
4408
+ const entry = this.collapse.get(collapseKey);
4409
+ if (entry && now - entry.firstSeenAt < this.opts.collapseWindowMs) {
4410
+ for (const target of [entry.first, entry.held]) {
4411
+ if (target && !target.inFlight && this.queue.includes(target)) {
4412
+ target.item.repeatCount = (target.item.repeatCount ?? 1) + 1;
4413
+ return;
4414
+ }
4415
+ }
4416
+ const held = this.push(
4417
+ dest,
4418
+ { ...item, repeatCount: 1 },
4419
+ entry.firstSeenAt + this.opts.collapseWindowMs
4420
+ );
4421
+ entry.held = held;
4422
+ return;
4423
+ }
4424
+ this.collapse.delete(collapseKey);
4425
+ if (this.collapse.size >= this.opts.collapseMaxKeys) {
4426
+ const oldest = this.collapse.keys().next().value;
4427
+ if (oldest !== void 0) this.collapse.delete(oldest);
4428
+ }
4429
+ const fresh = { firstSeenAt: now };
4430
+ this.collapse.set(collapseKey, fresh);
4431
+ fresh.first = this.push(dest, item, now);
4432
+ return;
4433
+ }
4434
+ this.push(dest, item, now);
4435
+ }
4436
+ /**
4437
+ * Deliver every eligible queued item. Concurrent callers share ONE
4438
+ * in-flight drain (it survives the caller's budget and a Lambda freeze),
4439
+ * so nothing in flight is ever sent twice; items queued while it runs are
4440
+ * picked up by the same drain.
4441
+ */
4442
+ flush() {
4443
+ if (!this.inFlight) {
4444
+ this.inFlight = this.drain().finally(() => {
4445
+ this.inFlight = void 0;
4446
+ });
4447
+ }
4448
+ return this.inFlight;
4449
+ }
4450
+ /** Counters for tests and diagnostics. */
4451
+ stats() {
4452
+ return {
4453
+ queueDepth: this.queue.length,
4454
+ droppedSinceLast: this.droppedSinceLast,
4455
+ droppedTotal: this.droppedTotal,
4456
+ deliveredTotal: this.deliveredTotal,
4457
+ flushing: this.inFlight !== void 0
4458
+ };
4459
+ }
4460
+ push(dest, item, eligibleAt) {
4461
+ while (this.queue.length >= this.opts.maxItems) this.dropOldest();
4462
+ const entry = {
4463
+ dest,
4464
+ destKey: destKeyOf(dest),
4465
+ item,
4466
+ attempts: 0,
4467
+ eligibleAt,
4468
+ inFlight: false
4469
+ };
4470
+ this.queue.push(entry);
4471
+ return entry;
4472
+ }
4473
+ dropOldest() {
4474
+ if (this.queue.shift()) this.countDropped(1);
4475
+ }
4476
+ countDropped(n) {
4477
+ this.droppedSinceLast += n;
4478
+ this.droppedTotal += n;
4479
+ }
4480
+ async drain() {
4481
+ for (; ; ) {
4482
+ const now = this.opts.now();
4483
+ if (now < this.backoffUntil) return;
4484
+ const batch = this.takeBatch(now);
4485
+ if (batch.length === 0) return;
4486
+ const ok = await this.send(batch);
4487
+ if (!ok) return;
4488
+ }
4489
+ }
4490
+ /** Oldest eligible item + up to maxBatch-1 more for the same destination. */
4491
+ takeBatch(now) {
4492
+ const first = this.queue.find((q) => q.eligibleAt <= now);
4493
+ if (!first) return [];
4494
+ const batch = [];
4495
+ const rest = [];
4496
+ for (const q of this.queue) {
4497
+ if (batch.length < this.opts.maxBatch && q.destKey === first.destKey && q.eligibleAt <= now) {
4498
+ q.inFlight = true;
4499
+ batch.push(q);
4500
+ } else {
4501
+ rest.push(q);
4502
+ }
4503
+ }
4504
+ this.queue = rest;
4505
+ return batch;
4506
+ }
4507
+ /** POST one batch. Returns false when the drain should pause (backoff). */
4508
+ async send(batch) {
4509
+ const dest = batch[0].dest;
4510
+ const useKey = dest.apiKey && !this.rejectedKeys.has(dest.apiKey) ? dest.apiKey : void 0;
4511
+ const reportedDropped = this.droppedSinceLast;
4512
+ const meta = {
4513
+ droppedSinceLast: reportedDropped,
4514
+ queueDepth: this.queue.length,
4515
+ adapter: dest.adapter ?? "edge-core",
4516
+ version: SDK_VERSION
4517
+ };
4518
+ const controller = typeof AbortController !== "undefined" ? new AbortController() : void 0;
4519
+ const response = await withBudget(
4520
+ sdkFetch(`${dest.apiBaseUrl}/verification-activity/edge-events`, {
4521
+ method: "POST",
4522
+ headers: {
4523
+ "Content-Type": "application/json",
4524
+ ...useKey && { Authorization: `Bearer ${useKey}` }
4525
+ },
4526
+ body: JSON.stringify({ events: batch.map((q) => q.item), meta }),
4527
+ ...controller && { signal: controller.signal }
4528
+ }),
4529
+ this.opts.requestTimeoutMs
4530
+ );
4531
+ if (!response) controller?.abort();
4532
+ const status = response?.status;
4533
+ for (const q of batch) q.inFlight = false;
4534
+ if (status !== void 0 && status >= 200 && status < 300) {
4535
+ this.droppedSinceLast = Math.max(0, this.droppedSinceLast - reportedDropped);
4536
+ this.deliveredTotal += batch.length;
4537
+ return true;
4538
+ }
4539
+ if (status === 401 && useKey) {
4540
+ this.rejectedKeys.add(useKey);
4541
+ this.requeue(batch, false);
4542
+ return true;
4543
+ }
4544
+ if (status === 429) {
4545
+ const retryAfter = Number(response?.headers.get("retry-after"));
4546
+ const waitMs = Number.isFinite(retryAfter) && retryAfter > 0 ? Math.min(retryAfter, 120) * 1e3 : 3e4;
4547
+ this.backoffUntil = this.opts.now() + waitMs;
4548
+ this.requeue(batch, false);
4549
+ return false;
4550
+ }
4551
+ if (status !== void 0 && status >= 400 && status < 500) {
4552
+ this.countDropped(batch.length);
4553
+ return true;
4554
+ }
4555
+ this.backoffUntil = this.opts.now() + this.opts.retryBackoffMs;
4556
+ this.requeue(batch, true);
4557
+ return false;
4558
+ }
4559
+ /** Put a failed batch back at the head of the queue (order preserved). */
4560
+ requeue(batch, countAttempt) {
4561
+ const keep = [];
4562
+ for (const q of batch) {
4563
+ if (countAttempt) q.attempts += 1;
4564
+ if (q.attempts >= this.opts.maxAttempts) this.countDropped(1);
4565
+ else keep.push(q);
4566
+ }
4567
+ this.queue = [...keep, ...this.queue];
4568
+ while (this.queue.length > this.opts.maxItems) this.dropOldest();
4569
+ }
4570
+ };
4571
+ var beaconBuffer = new BeaconBuffer();
4572
+
4296
4573
  // src/adapters/express.ts
4297
4574
  var DEFAULT_ROUTES_REFRESH_MS = 5 * 60 * 1e3;
4298
4575