@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.
- package/README.md +4 -0
- package/dist/adapters/express.d.mts +1 -1
- package/dist/adapters/express.d.ts +1 -1
- package/dist/adapters/express.js +359 -30
- package/dist/adapters/express.js.map +1 -1
- package/dist/adapters/express.mjs +359 -30
- package/dist/adapters/express.mjs.map +1 -1
- package/dist/adapters/mcp.d.mts +5 -1
- package/dist/adapters/mcp.d.ts +5 -1
- package/dist/adapters/mcp.js +168 -41
- package/dist/adapters/mcp.js.map +1 -1
- package/dist/adapters/mcp.mjs +168 -41
- package/dist/adapters/mcp.mjs.map +1 -1
- package/dist/adapters/nextjs.d.mts +1 -1
- package/dist/adapters/nextjs.d.ts +1 -1
- package/dist/adapters/nextjs.js +352 -13
- package/dist/adapters/nextjs.js.map +1 -1
- package/dist/adapters/nextjs.mjs +352 -13
- package/dist/adapters/nextjs.mjs.map +1 -1
- package/dist/adapters/sdk.d.mts +9 -1
- package/dist/adapters/sdk.d.ts +9 -1
- package/dist/adapters/sdk.js +100 -8
- package/dist/adapters/sdk.js.map +1 -1
- package/dist/adapters/sdk.mjs +100 -8
- package/dist/adapters/sdk.mjs.map +1 -1
- package/dist/agent/index.js +1 -1
- package/dist/agent/index.js.map +1 -1
- package/dist/agent/index.mjs +1 -1
- package/dist/agent/index.mjs.map +1 -1
- package/dist/bin/astrasync-claude-hook.js +284 -7
- package/dist/bin/astrasync-codex-hook.js +284 -7
- package/dist/bin/astrasync-guard.js +284 -7
- package/dist/bin/astrasync.js +297 -9
- package/dist/browser/background.js +284 -7
- package/dist/browser/background.js.map +1 -1
- package/dist/browser/background.mjs +284 -7
- package/dist/browser/background.mjs.map +1 -1
- package/dist/cli/index.js +1 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/index.mjs +1 -1
- package/dist/cli/index.mjs.map +1 -1
- package/dist/codex/index.js +284 -7
- package/dist/codex/index.js.map +1 -1
- package/dist/codex/index.mjs +284 -7
- package/dist/codex/index.mjs.map +1 -1
- package/dist/cursor/extension.js +284 -7
- package/dist/cursor/extension.js.map +1 -1
- package/dist/cursor/extension.mjs +284 -7
- package/dist/cursor/extension.mjs.map +1 -1
- package/dist/edge-config.d.mts +1 -1
- package/dist/edge-config.d.ts +1 -1
- package/dist/edge-config.js +1 -1
- package/dist/edge-config.js.map +1 -1
- package/dist/edge-config.mjs +1 -1
- package/dist/edge-config.mjs.map +1 -1
- package/dist/edge-core/index.d.mts +128 -13
- package/dist/edge-core/index.d.ts +128 -13
- package/dist/edge-core/index.js +337 -55
- package/dist/edge-core/index.js.map +1 -1
- package/dist/edge-core/index.mjs +334 -55
- package/dist/edge-core/index.mjs.map +1 -1
- package/dist/gateway/gateway.js +284 -7
- package/dist/gateway/gateway.js.map +1 -1
- package/dist/gateway/gateway.mjs +284 -7
- package/dist/gateway/gateway.mjs.map +1 -1
- package/dist/git-trigger/git-hooks.d.mts +1 -1
- package/dist/git-trigger/git-hooks.d.ts +1 -1
- package/dist/index.d.mts +118 -5
- package/dist/index.d.ts +118 -5
- package/dist/index.js +486 -63
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +480 -63
- package/dist/index.mjs.map +1 -1
- package/dist/platform-signatures.js +4 -1
- package/dist/platform-signatures.js.map +1 -1
- package/dist/platform-signatures.mjs +4 -1
- package/dist/platform-signatures.mjs.map +1 -1
- package/dist/registration/index.js +1 -1
- package/dist/registration/index.js.map +1 -1
- package/dist/registration/index.mjs +1 -1
- package/dist/registration/index.mjs.map +1 -1
- package/dist/transport/index.js +1 -1
- package/dist/transport/index.js.map +1 -1
- package/dist/transport/index.mjs +1 -1
- package/dist/transport/index.mjs.map +1 -1
- package/dist/{types-CTmUpNpS.d.mts → types-BCkwBA84.d.mts} +12 -0
- package/dist/{types-CTmUpNpS.d.ts → types-BCkwBA84.d.ts} +12 -0
- package/dist/{types-CtFXmDzm.d.ts → types-C_b4QTyO.d.ts} +18 -0
- package/dist/{types-DQrn_kei.d.mts → types-DlshIIR-.d.mts} +18 -0
- package/dist/ui/index.d.mts +1 -1
- package/dist/ui/index.d.ts +1 -1
- package/dist/verify.d.mts +35 -4
- package/dist/verify.d.ts +35 -4
- package/dist/verify.js +130 -16
- package/dist/verify.js.map +1 -1
- package/dist/verify.mjs +129 -16
- package/dist/verify.mjs.map +1 -1
- package/package.json +1 -1
package/dist/cursor/extension.js
CHANGED
|
@@ -3994,7 +3994,7 @@ function getTrustLevel(score) {
|
|
|
3994
3994
|
}
|
|
3995
3995
|
|
|
3996
3996
|
// src/version.ts
|
|
3997
|
-
var SDK_VERSION = "5.
|
|
3997
|
+
var SDK_VERSION = "5.12.0";
|
|
3998
3998
|
|
|
3999
3999
|
// src/http.ts
|
|
4000
4000
|
var SDK_USER_AGENT = `astrasync-sdk/${SDK_VERSION}`;
|
|
@@ -4021,6 +4021,14 @@ function getCachedWellKnownUrls(apiBaseUrl) {
|
|
|
4021
4021
|
return cache.get(apiBaseUrl)?.data;
|
|
4022
4022
|
}
|
|
4023
4023
|
|
|
4024
|
+
// src/failure-posture.ts
|
|
4025
|
+
var REJECTED_IDENTITY_DIMENSIONS = /* @__PURE__ */ new Set([
|
|
4026
|
+
"identity.invalid_agent_id",
|
|
4027
|
+
"identity.unknown_agent",
|
|
4028
|
+
"agent.lookup"
|
|
4029
|
+
]);
|
|
4030
|
+
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.";
|
|
4031
|
+
|
|
4024
4032
|
// src/verify.ts
|
|
4025
4033
|
var DEFAULT_CONFIG = {
|
|
4026
4034
|
apiBaseUrl: "https://astrasync.ai/api",
|
|
@@ -4232,11 +4240,44 @@ function createGuidanceResponse(_config, reason, options = {}) {
|
|
|
4232
4240
|
// coercing the absent recommendation to a policy 'deny'. Misconfig is
|
|
4233
4241
|
// deterministic and intentionally NOT marked retryable.
|
|
4234
4242
|
...isApiError && { retryable: true },
|
|
4243
|
+
...options.httpStatus !== void 0 && { httpStatus: options.httpStatus },
|
|
4244
|
+
...options.retryAfterMs !== void 0 && { retryAfterMs: options.retryAfterMs },
|
|
4235
4245
|
correlationId: options.correlationId,
|
|
4236
4246
|
attemptId: options.attemptId,
|
|
4237
4247
|
verifiedAt: /* @__PURE__ */ new Date()
|
|
4238
4248
|
};
|
|
4239
4249
|
}
|
|
4250
|
+
async function readJsonSafe(response) {
|
|
4251
|
+
try {
|
|
4252
|
+
const parsed = await response.json();
|
|
4253
|
+
return parsed && typeof parsed === "object" ? parsed : {};
|
|
4254
|
+
} catch {
|
|
4255
|
+
return {};
|
|
4256
|
+
}
|
|
4257
|
+
}
|
|
4258
|
+
function rejectedIdentityGuidance(failures) {
|
|
4259
|
+
const f = failures?.find((x) => REJECTED_IDENTITY_DIMENSIONS.has(x.dimension));
|
|
4260
|
+
if (!f) return void 0;
|
|
4261
|
+
if (f.dimension === "agent.lookup") {
|
|
4262
|
+
return `The presented agent identifier is not registered with AstraSync. ${UNKNOWN_AGENT_GUIDANCE}`;
|
|
4263
|
+
}
|
|
4264
|
+
return f.guidance ? `${f.message} ${f.guidance}` : f.message;
|
|
4265
|
+
}
|
|
4266
|
+
var MAX_RETRY_AFTER_MS = 15 * 60 * 1e3;
|
|
4267
|
+
function parseRetryAfterMs(response) {
|
|
4268
|
+
const raw = response.headers?.get?.("retry-after");
|
|
4269
|
+
if (!raw) return void 0;
|
|
4270
|
+
const trimmed = raw.trim();
|
|
4271
|
+
let ms;
|
|
4272
|
+
if (/^\d+(\.\d+)?$/.test(trimmed)) {
|
|
4273
|
+
ms = Number(trimmed) * 1e3;
|
|
4274
|
+
} else {
|
|
4275
|
+
const at = Date.parse(trimmed);
|
|
4276
|
+
if (Number.isNaN(at)) return void 0;
|
|
4277
|
+
ms = at - Date.now();
|
|
4278
|
+
}
|
|
4279
|
+
return Math.min(MAX_RETRY_AFTER_MS, Math.max(0, Math.round(ms)));
|
|
4280
|
+
}
|
|
4240
4281
|
async function callVerifyAccessAPI(config, request) {
|
|
4241
4282
|
const { credentials, ...requestData } = request;
|
|
4242
4283
|
const body = {
|
|
@@ -4293,7 +4334,8 @@ async function callVerifyAccessAPI(config, request) {
|
|
|
4293
4334
|
body: JSON.stringify(body),
|
|
4294
4335
|
signal: AbortSignal.timeout(config.verifyTimeoutMs ?? 1e4)
|
|
4295
4336
|
});
|
|
4296
|
-
const data = await response
|
|
4337
|
+
const data = await readJsonSafe(response);
|
|
4338
|
+
const retryAfterMs = parseRetryAfterMs(response);
|
|
4297
4339
|
if (response.status === 410) {
|
|
4298
4340
|
return {
|
|
4299
4341
|
success: true,
|
|
@@ -4331,6 +4373,23 @@ async function callVerifyAccessAPI(config, request) {
|
|
|
4331
4373
|
}
|
|
4332
4374
|
};
|
|
4333
4375
|
}
|
|
4376
|
+
if (response.status === 404 && credentials.astraId && (data?.error === "AGENT_NOT_FOUND" || typeof data?.message === "string" && /agent/i.test(data.message))) {
|
|
4377
|
+
return {
|
|
4378
|
+
success: true,
|
|
4379
|
+
attemptId: typeof data?.attemptId === "string" ? data.attemptId : void 0,
|
|
4380
|
+
access: {
|
|
4381
|
+
allowed: false,
|
|
4382
|
+
reason: "unknown_agent",
|
|
4383
|
+
failures: [
|
|
4384
|
+
{
|
|
4385
|
+
dimension: "identity.unknown_agent",
|
|
4386
|
+
message: "The presented agent identifier is not registered with AstraSync.",
|
|
4387
|
+
guidance: UNKNOWN_AGENT_GUIDANCE
|
|
4388
|
+
}
|
|
4389
|
+
]
|
|
4390
|
+
}
|
|
4391
|
+
};
|
|
4392
|
+
}
|
|
4334
4393
|
if (!response.ok) {
|
|
4335
4394
|
if (response.status === 401) {
|
|
4336
4395
|
return {
|
|
@@ -4345,9 +4404,11 @@ async function callVerifyAccessAPI(config, request) {
|
|
|
4345
4404
|
}
|
|
4346
4405
|
return {
|
|
4347
4406
|
success: false,
|
|
4348
|
-
error: data.message || data.error || `API returned ${response.status}`,
|
|
4407
|
+
error: typeof data?.message === "string" && data.message || typeof data?.error === "string" && data.error || `API returned ${response.status}`,
|
|
4349
4408
|
correlationId: typeof data?.correlationId === "string" ? data.correlationId : void 0,
|
|
4350
|
-
attemptId: typeof data?.attemptId === "string" ? data.attemptId : void 0
|
|
4409
|
+
attemptId: typeof data?.attemptId === "string" ? data.attemptId : void 0,
|
|
4410
|
+
httpStatus: response.status,
|
|
4411
|
+
...retryAfterMs !== void 0 && { retryAfterMs }
|
|
4351
4412
|
};
|
|
4352
4413
|
}
|
|
4353
4414
|
return data;
|
|
@@ -4419,12 +4480,14 @@ async function verify(config, request, options) {
|
|
|
4419
4480
|
correlationId: apiResponse.correlationId,
|
|
4420
4481
|
attemptId: apiResponse.attemptId,
|
|
4421
4482
|
remediation: apiResponse.remediation,
|
|
4483
|
+
httpStatus: apiResponse.httpStatus,
|
|
4484
|
+
retryAfterMs: apiResponse.retryAfterMs,
|
|
4422
4485
|
urls
|
|
4423
4486
|
});
|
|
4424
4487
|
}
|
|
4425
4488
|
if (!apiResponse.access?.allowed) {
|
|
4426
4489
|
const aggregatedFailures = apiResponse.access?.failures;
|
|
4427
|
-
const idVerifiedFromBackend = apiResponse.verificationContext?.idVerified === true;
|
|
4490
|
+
const idVerifiedFromBackend = apiResponse.verificationContext?.idVerified === true && !aggregatedFailures?.some((f) => REJECTED_IDENTITY_DIMENSIONS.has(f.dimension));
|
|
4428
4491
|
const result2 = {
|
|
4429
4492
|
identityVerified: idVerifiedFromBackend,
|
|
4430
4493
|
policyAllowed: false,
|
|
@@ -4436,7 +4499,10 @@ async function verify(config, request, options) {
|
|
|
4436
4499
|
requiresStepUp: apiResponse.access?.requiresStepUp,
|
|
4437
4500
|
requiresApproval: apiResponse.access?.requiresApproval,
|
|
4438
4501
|
guidance: {
|
|
4439
|
-
|
|
4502
|
+
// 5.12.0: a presented-but-rejected id (malformed / unknown) carries
|
|
4503
|
+
// actionable registration guidance on its failure — surface it
|
|
4504
|
+
// instead of the bare machine reason ('unknown_agent').
|
|
4505
|
+
message: rejectedIdentityGuidance(aggregatedFailures) ?? (apiResponse.access?.reason || "Access denied by PDLSS policy"),
|
|
4440
4506
|
registrationUrl: urls?.registrationUrl ?? "",
|
|
4441
4507
|
documentationUrl: urls?.documentationUrl ?? "",
|
|
4442
4508
|
// 5.1.0: anonymous callers land on this branch — steer MCP-hosted
|
|
@@ -4536,7 +4602,7 @@ async function verify(config, request, options) {
|
|
|
4536
4602
|
registrationUrl: urls?.registrationUrl ?? "",
|
|
4537
4603
|
documentationUrl: urls?.documentationUrl ?? ""
|
|
4538
4604
|
};
|
|
4539
|
-
} else if (result.recommendation === "step_up_required") {
|
|
4605
|
+
} else if (result.recommendation === "step_up_required" && result.identityVerified) {
|
|
4540
4606
|
result.requiresStepUp = true;
|
|
4541
4607
|
result.denialReasons = serverDenialReasons ?? result.recommendationReasons ?? ["Step-up verification required"];
|
|
4542
4608
|
}
|
|
@@ -4565,6 +4631,217 @@ var DEFAULT_EDGE_CONFIG = Object.freeze({
|
|
|
4565
4631
|
var DEFAULT_TTL_MS = 60 * 1e3;
|
|
4566
4632
|
var DEFAULT_MAX_STALE_MS = 24 * 60 * 60 * 1e3;
|
|
4567
4633
|
|
|
4634
|
+
// src/edge-core/events.ts
|
|
4635
|
+
async function withBudget(promise, ms) {
|
|
4636
|
+
let timer;
|
|
4637
|
+
try {
|
|
4638
|
+
return await Promise.race([
|
|
4639
|
+
promise,
|
|
4640
|
+
new Promise((resolve) => {
|
|
4641
|
+
timer = setTimeout(() => resolve(void 0), ms);
|
|
4642
|
+
})
|
|
4643
|
+
]);
|
|
4644
|
+
} catch {
|
|
4645
|
+
return void 0;
|
|
4646
|
+
} finally {
|
|
4647
|
+
if (timer) clearTimeout(timer);
|
|
4648
|
+
}
|
|
4649
|
+
}
|
|
4650
|
+
var destKeyOf = (d) => `${d.apiBaseUrl}\0${d.apiKey ?? ""}\0${d.counterparty}\0${d.adapter ?? ""}`;
|
|
4651
|
+
var BeaconBuffer = class {
|
|
4652
|
+
constructor(options = {}) {
|
|
4653
|
+
this.queue = [];
|
|
4654
|
+
this.droppedSinceLast = 0;
|
|
4655
|
+
this.droppedTotal = 0;
|
|
4656
|
+
this.deliveredTotal = 0;
|
|
4657
|
+
this.backoffUntil = 0;
|
|
4658
|
+
this.collapse = /* @__PURE__ */ new Map();
|
|
4659
|
+
/** Keys the backend answered 401 for — later batches go unauthenticated. */
|
|
4660
|
+
this.rejectedKeys = /* @__PURE__ */ new Set();
|
|
4661
|
+
this.opts = {
|
|
4662
|
+
maxItems: options.maxItems ?? 1e3,
|
|
4663
|
+
maxBatch: options.maxBatch ?? 100,
|
|
4664
|
+
maxAttempts: options.maxAttempts ?? 3,
|
|
4665
|
+
collapseWindowMs: options.collapseWindowMs ?? 6e4,
|
|
4666
|
+
collapseMaxKeys: options.collapseMaxKeys ?? 1e3,
|
|
4667
|
+
requestTimeoutMs: options.requestTimeoutMs ?? 1e4,
|
|
4668
|
+
retryBackoffMs: options.retryBackoffMs ?? 1e3,
|
|
4669
|
+
now: options.now ?? Date.now
|
|
4670
|
+
};
|
|
4671
|
+
}
|
|
4672
|
+
/**
|
|
4673
|
+
* Queue one beacon. With a `collapseKey`, a repeat inside the window is
|
|
4674
|
+
* merged into a held aggregate (sent when the window closes) instead of
|
|
4675
|
+
* becoming its own item.
|
|
4676
|
+
*/
|
|
4677
|
+
enqueue(dest, item, collapseKey) {
|
|
4678
|
+
const now = this.opts.now();
|
|
4679
|
+
if (collapseKey) {
|
|
4680
|
+
const entry = this.collapse.get(collapseKey);
|
|
4681
|
+
if (entry && now - entry.firstSeenAt < this.opts.collapseWindowMs) {
|
|
4682
|
+
for (const target of [entry.first, entry.held]) {
|
|
4683
|
+
if (target && !target.inFlight && this.queue.includes(target)) {
|
|
4684
|
+
target.item.repeatCount = (target.item.repeatCount ?? 1) + 1;
|
|
4685
|
+
return;
|
|
4686
|
+
}
|
|
4687
|
+
}
|
|
4688
|
+
const held = this.push(
|
|
4689
|
+
dest,
|
|
4690
|
+
{ ...item, repeatCount: 1 },
|
|
4691
|
+
entry.firstSeenAt + this.opts.collapseWindowMs
|
|
4692
|
+
);
|
|
4693
|
+
entry.held = held;
|
|
4694
|
+
return;
|
|
4695
|
+
}
|
|
4696
|
+
this.collapse.delete(collapseKey);
|
|
4697
|
+
if (this.collapse.size >= this.opts.collapseMaxKeys) {
|
|
4698
|
+
const oldest = this.collapse.keys().next().value;
|
|
4699
|
+
if (oldest !== void 0) this.collapse.delete(oldest);
|
|
4700
|
+
}
|
|
4701
|
+
const fresh = { firstSeenAt: now };
|
|
4702
|
+
this.collapse.set(collapseKey, fresh);
|
|
4703
|
+
fresh.first = this.push(dest, item, now);
|
|
4704
|
+
return;
|
|
4705
|
+
}
|
|
4706
|
+
this.push(dest, item, now);
|
|
4707
|
+
}
|
|
4708
|
+
/**
|
|
4709
|
+
* Deliver every eligible queued item. Concurrent callers share ONE
|
|
4710
|
+
* in-flight drain (it survives the caller's budget and a Lambda freeze),
|
|
4711
|
+
* so nothing in flight is ever sent twice; items queued while it runs are
|
|
4712
|
+
* picked up by the same drain.
|
|
4713
|
+
*/
|
|
4714
|
+
flush() {
|
|
4715
|
+
if (!this.inFlight) {
|
|
4716
|
+
this.inFlight = this.drain().finally(() => {
|
|
4717
|
+
this.inFlight = void 0;
|
|
4718
|
+
});
|
|
4719
|
+
}
|
|
4720
|
+
return this.inFlight;
|
|
4721
|
+
}
|
|
4722
|
+
/** Counters for tests and diagnostics. */
|
|
4723
|
+
stats() {
|
|
4724
|
+
return {
|
|
4725
|
+
queueDepth: this.queue.length,
|
|
4726
|
+
droppedSinceLast: this.droppedSinceLast,
|
|
4727
|
+
droppedTotal: this.droppedTotal,
|
|
4728
|
+
deliveredTotal: this.deliveredTotal,
|
|
4729
|
+
flushing: this.inFlight !== void 0
|
|
4730
|
+
};
|
|
4731
|
+
}
|
|
4732
|
+
push(dest, item, eligibleAt) {
|
|
4733
|
+
while (this.queue.length >= this.opts.maxItems) this.dropOldest();
|
|
4734
|
+
const entry = {
|
|
4735
|
+
dest,
|
|
4736
|
+
destKey: destKeyOf(dest),
|
|
4737
|
+
item,
|
|
4738
|
+
attempts: 0,
|
|
4739
|
+
eligibleAt,
|
|
4740
|
+
inFlight: false
|
|
4741
|
+
};
|
|
4742
|
+
this.queue.push(entry);
|
|
4743
|
+
return entry;
|
|
4744
|
+
}
|
|
4745
|
+
dropOldest() {
|
|
4746
|
+
if (this.queue.shift()) this.countDropped(1);
|
|
4747
|
+
}
|
|
4748
|
+
countDropped(n) {
|
|
4749
|
+
this.droppedSinceLast += n;
|
|
4750
|
+
this.droppedTotal += n;
|
|
4751
|
+
}
|
|
4752
|
+
async drain() {
|
|
4753
|
+
for (; ; ) {
|
|
4754
|
+
const now = this.opts.now();
|
|
4755
|
+
if (now < this.backoffUntil) return;
|
|
4756
|
+
const batch = this.takeBatch(now);
|
|
4757
|
+
if (batch.length === 0) return;
|
|
4758
|
+
const ok = await this.send(batch);
|
|
4759
|
+
if (!ok) return;
|
|
4760
|
+
}
|
|
4761
|
+
}
|
|
4762
|
+
/** Oldest eligible item + up to maxBatch-1 more for the same destination. */
|
|
4763
|
+
takeBatch(now) {
|
|
4764
|
+
const first = this.queue.find((q) => q.eligibleAt <= now);
|
|
4765
|
+
if (!first) return [];
|
|
4766
|
+
const batch = [];
|
|
4767
|
+
const rest = [];
|
|
4768
|
+
for (const q of this.queue) {
|
|
4769
|
+
if (batch.length < this.opts.maxBatch && q.destKey === first.destKey && q.eligibleAt <= now) {
|
|
4770
|
+
q.inFlight = true;
|
|
4771
|
+
batch.push(q);
|
|
4772
|
+
} else {
|
|
4773
|
+
rest.push(q);
|
|
4774
|
+
}
|
|
4775
|
+
}
|
|
4776
|
+
this.queue = rest;
|
|
4777
|
+
return batch;
|
|
4778
|
+
}
|
|
4779
|
+
/** POST one batch. Returns false when the drain should pause (backoff). */
|
|
4780
|
+
async send(batch) {
|
|
4781
|
+
const dest = batch[0].dest;
|
|
4782
|
+
const useKey = dest.apiKey && !this.rejectedKeys.has(dest.apiKey) ? dest.apiKey : void 0;
|
|
4783
|
+
const reportedDropped = this.droppedSinceLast;
|
|
4784
|
+
const meta = {
|
|
4785
|
+
droppedSinceLast: reportedDropped,
|
|
4786
|
+
queueDepth: this.queue.length,
|
|
4787
|
+
adapter: dest.adapter ?? "edge-core",
|
|
4788
|
+
version: SDK_VERSION
|
|
4789
|
+
};
|
|
4790
|
+
const controller = typeof AbortController !== "undefined" ? new AbortController() : void 0;
|
|
4791
|
+
const response = await withBudget(
|
|
4792
|
+
sdkFetch(`${dest.apiBaseUrl}/verification-activity/edge-events`, {
|
|
4793
|
+
method: "POST",
|
|
4794
|
+
headers: {
|
|
4795
|
+
"Content-Type": "application/json",
|
|
4796
|
+
...useKey && { Authorization: `Bearer ${useKey}` }
|
|
4797
|
+
},
|
|
4798
|
+
body: JSON.stringify({ events: batch.map((q) => q.item), meta }),
|
|
4799
|
+
...controller && { signal: controller.signal }
|
|
4800
|
+
}),
|
|
4801
|
+
this.opts.requestTimeoutMs
|
|
4802
|
+
);
|
|
4803
|
+
if (!response) controller?.abort();
|
|
4804
|
+
const status = response?.status;
|
|
4805
|
+
for (const q of batch) q.inFlight = false;
|
|
4806
|
+
if (status !== void 0 && status >= 200 && status < 300) {
|
|
4807
|
+
this.droppedSinceLast = Math.max(0, this.droppedSinceLast - reportedDropped);
|
|
4808
|
+
this.deliveredTotal += batch.length;
|
|
4809
|
+
return true;
|
|
4810
|
+
}
|
|
4811
|
+
if (status === 401 && useKey) {
|
|
4812
|
+
this.rejectedKeys.add(useKey);
|
|
4813
|
+
this.requeue(batch, false);
|
|
4814
|
+
return true;
|
|
4815
|
+
}
|
|
4816
|
+
if (status === 429) {
|
|
4817
|
+
const retryAfter = Number(response?.headers.get("retry-after"));
|
|
4818
|
+
const waitMs = Number.isFinite(retryAfter) && retryAfter > 0 ? Math.min(retryAfter, 120) * 1e3 : 3e4;
|
|
4819
|
+
this.backoffUntil = this.opts.now() + waitMs;
|
|
4820
|
+
this.requeue(batch, false);
|
|
4821
|
+
return false;
|
|
4822
|
+
}
|
|
4823
|
+
if (status !== void 0 && status >= 400 && status < 500) {
|
|
4824
|
+
this.countDropped(batch.length);
|
|
4825
|
+
return true;
|
|
4826
|
+
}
|
|
4827
|
+
this.backoffUntil = this.opts.now() + this.opts.retryBackoffMs;
|
|
4828
|
+
this.requeue(batch, true);
|
|
4829
|
+
return false;
|
|
4830
|
+
}
|
|
4831
|
+
/** Put a failed batch back at the head of the queue (order preserved). */
|
|
4832
|
+
requeue(batch, countAttempt) {
|
|
4833
|
+
const keep = [];
|
|
4834
|
+
for (const q of batch) {
|
|
4835
|
+
if (countAttempt) q.attempts += 1;
|
|
4836
|
+
if (q.attempts >= this.opts.maxAttempts) this.countDropped(1);
|
|
4837
|
+
else keep.push(q);
|
|
4838
|
+
}
|
|
4839
|
+
this.queue = [...keep, ...this.queue];
|
|
4840
|
+
while (this.queue.length > this.opts.maxItems) this.dropOldest();
|
|
4841
|
+
}
|
|
4842
|
+
};
|
|
4843
|
+
var beaconBuffer = new BeaconBuffer();
|
|
4844
|
+
|
|
4568
4845
|
// src/adapters/express.ts
|
|
4569
4846
|
var DEFAULT_ROUTES_REFRESH_MS = 5 * 60 * 1e3;
|
|
4570
4847
|
|