@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
|
@@ -3969,7 +3969,7 @@ function getTrustLevel(score) {
|
|
|
3969
3969
|
}
|
|
3970
3970
|
|
|
3971
3971
|
// src/version.ts
|
|
3972
|
-
var SDK_VERSION = "5.
|
|
3972
|
+
var SDK_VERSION = "5.12.0";
|
|
3973
3973
|
|
|
3974
3974
|
// src/http.ts
|
|
3975
3975
|
var SDK_USER_AGENT = `astrasync-sdk/${SDK_VERSION}`;
|
|
@@ -3996,6 +3996,14 @@ function getCachedWellKnownUrls(apiBaseUrl) {
|
|
|
3996
3996
|
return cache.get(apiBaseUrl)?.data;
|
|
3997
3997
|
}
|
|
3998
3998
|
|
|
3999
|
+
// src/failure-posture.ts
|
|
4000
|
+
var REJECTED_IDENTITY_DIMENSIONS = /* @__PURE__ */ new Set([
|
|
4001
|
+
"identity.invalid_agent_id",
|
|
4002
|
+
"identity.unknown_agent",
|
|
4003
|
+
"agent.lookup"
|
|
4004
|
+
]);
|
|
4005
|
+
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.";
|
|
4006
|
+
|
|
3999
4007
|
// src/verify.ts
|
|
4000
4008
|
var DEFAULT_CONFIG = {
|
|
4001
4009
|
apiBaseUrl: "https://astrasync.ai/api",
|
|
@@ -4207,11 +4215,44 @@ function createGuidanceResponse(_config, reason, options = {}) {
|
|
|
4207
4215
|
// coercing the absent recommendation to a policy 'deny'. Misconfig is
|
|
4208
4216
|
// deterministic and intentionally NOT marked retryable.
|
|
4209
4217
|
...isApiError && { retryable: true },
|
|
4218
|
+
...options.httpStatus !== void 0 && { httpStatus: options.httpStatus },
|
|
4219
|
+
...options.retryAfterMs !== void 0 && { retryAfterMs: options.retryAfterMs },
|
|
4210
4220
|
correlationId: options.correlationId,
|
|
4211
4221
|
attemptId: options.attemptId,
|
|
4212
4222
|
verifiedAt: /* @__PURE__ */ new Date()
|
|
4213
4223
|
};
|
|
4214
4224
|
}
|
|
4225
|
+
async function readJsonSafe(response) {
|
|
4226
|
+
try {
|
|
4227
|
+
const parsed = await response.json();
|
|
4228
|
+
return parsed && typeof parsed === "object" ? parsed : {};
|
|
4229
|
+
} catch {
|
|
4230
|
+
return {};
|
|
4231
|
+
}
|
|
4232
|
+
}
|
|
4233
|
+
function rejectedIdentityGuidance(failures) {
|
|
4234
|
+
const f = failures?.find((x) => REJECTED_IDENTITY_DIMENSIONS.has(x.dimension));
|
|
4235
|
+
if (!f) return void 0;
|
|
4236
|
+
if (f.dimension === "agent.lookup") {
|
|
4237
|
+
return `The presented agent identifier is not registered with AstraSync. ${UNKNOWN_AGENT_GUIDANCE}`;
|
|
4238
|
+
}
|
|
4239
|
+
return f.guidance ? `${f.message} ${f.guidance}` : f.message;
|
|
4240
|
+
}
|
|
4241
|
+
var MAX_RETRY_AFTER_MS = 15 * 60 * 1e3;
|
|
4242
|
+
function parseRetryAfterMs(response) {
|
|
4243
|
+
const raw = response.headers?.get?.("retry-after");
|
|
4244
|
+
if (!raw) return void 0;
|
|
4245
|
+
const trimmed = raw.trim();
|
|
4246
|
+
let ms;
|
|
4247
|
+
if (/^\d+(\.\d+)?$/.test(trimmed)) {
|
|
4248
|
+
ms = Number(trimmed) * 1e3;
|
|
4249
|
+
} else {
|
|
4250
|
+
const at = Date.parse(trimmed);
|
|
4251
|
+
if (Number.isNaN(at)) return void 0;
|
|
4252
|
+
ms = at - Date.now();
|
|
4253
|
+
}
|
|
4254
|
+
return Math.min(MAX_RETRY_AFTER_MS, Math.max(0, Math.round(ms)));
|
|
4255
|
+
}
|
|
4215
4256
|
async function callVerifyAccessAPI(config, request) {
|
|
4216
4257
|
const { credentials, ...requestData } = request;
|
|
4217
4258
|
const body = {
|
|
@@ -4268,7 +4309,8 @@ async function callVerifyAccessAPI(config, request) {
|
|
|
4268
4309
|
body: JSON.stringify(body),
|
|
4269
4310
|
signal: AbortSignal.timeout(config.verifyTimeoutMs ?? 1e4)
|
|
4270
4311
|
});
|
|
4271
|
-
const data = await response
|
|
4312
|
+
const data = await readJsonSafe(response);
|
|
4313
|
+
const retryAfterMs = parseRetryAfterMs(response);
|
|
4272
4314
|
if (response.status === 410) {
|
|
4273
4315
|
return {
|
|
4274
4316
|
success: true,
|
|
@@ -4306,6 +4348,23 @@ async function callVerifyAccessAPI(config, request) {
|
|
|
4306
4348
|
}
|
|
4307
4349
|
};
|
|
4308
4350
|
}
|
|
4351
|
+
if (response.status === 404 && credentials.astraId && (data?.error === "AGENT_NOT_FOUND" || typeof data?.message === "string" && /agent/i.test(data.message))) {
|
|
4352
|
+
return {
|
|
4353
|
+
success: true,
|
|
4354
|
+
attemptId: typeof data?.attemptId === "string" ? data.attemptId : void 0,
|
|
4355
|
+
access: {
|
|
4356
|
+
allowed: false,
|
|
4357
|
+
reason: "unknown_agent",
|
|
4358
|
+
failures: [
|
|
4359
|
+
{
|
|
4360
|
+
dimension: "identity.unknown_agent",
|
|
4361
|
+
message: "The presented agent identifier is not registered with AstraSync.",
|
|
4362
|
+
guidance: UNKNOWN_AGENT_GUIDANCE
|
|
4363
|
+
}
|
|
4364
|
+
]
|
|
4365
|
+
}
|
|
4366
|
+
};
|
|
4367
|
+
}
|
|
4309
4368
|
if (!response.ok) {
|
|
4310
4369
|
if (response.status === 401) {
|
|
4311
4370
|
return {
|
|
@@ -4320,9 +4379,11 @@ async function callVerifyAccessAPI(config, request) {
|
|
|
4320
4379
|
}
|
|
4321
4380
|
return {
|
|
4322
4381
|
success: false,
|
|
4323
|
-
error: data.message || data.error || `API returned ${response.status}`,
|
|
4382
|
+
error: typeof data?.message === "string" && data.message || typeof data?.error === "string" && data.error || `API returned ${response.status}`,
|
|
4324
4383
|
correlationId: typeof data?.correlationId === "string" ? data.correlationId : void 0,
|
|
4325
|
-
attemptId: typeof data?.attemptId === "string" ? data.attemptId : void 0
|
|
4384
|
+
attemptId: typeof data?.attemptId === "string" ? data.attemptId : void 0,
|
|
4385
|
+
httpStatus: response.status,
|
|
4386
|
+
...retryAfterMs !== void 0 && { retryAfterMs }
|
|
4326
4387
|
};
|
|
4327
4388
|
}
|
|
4328
4389
|
return data;
|
|
@@ -4394,12 +4455,14 @@ async function verify(config, request, options) {
|
|
|
4394
4455
|
correlationId: apiResponse.correlationId,
|
|
4395
4456
|
attemptId: apiResponse.attemptId,
|
|
4396
4457
|
remediation: apiResponse.remediation,
|
|
4458
|
+
httpStatus: apiResponse.httpStatus,
|
|
4459
|
+
retryAfterMs: apiResponse.retryAfterMs,
|
|
4397
4460
|
urls
|
|
4398
4461
|
});
|
|
4399
4462
|
}
|
|
4400
4463
|
if (!apiResponse.access?.allowed) {
|
|
4401
4464
|
const aggregatedFailures = apiResponse.access?.failures;
|
|
4402
|
-
const idVerifiedFromBackend = apiResponse.verificationContext?.idVerified === true;
|
|
4465
|
+
const idVerifiedFromBackend = apiResponse.verificationContext?.idVerified === true && !aggregatedFailures?.some((f) => REJECTED_IDENTITY_DIMENSIONS.has(f.dimension));
|
|
4403
4466
|
const result2 = {
|
|
4404
4467
|
identityVerified: idVerifiedFromBackend,
|
|
4405
4468
|
policyAllowed: false,
|
|
@@ -4411,7 +4474,10 @@ async function verify(config, request, options) {
|
|
|
4411
4474
|
requiresStepUp: apiResponse.access?.requiresStepUp,
|
|
4412
4475
|
requiresApproval: apiResponse.access?.requiresApproval,
|
|
4413
4476
|
guidance: {
|
|
4414
|
-
|
|
4477
|
+
// 5.12.0: a presented-but-rejected id (malformed / unknown) carries
|
|
4478
|
+
// actionable registration guidance on its failure — surface it
|
|
4479
|
+
// instead of the bare machine reason ('unknown_agent').
|
|
4480
|
+
message: rejectedIdentityGuidance(aggregatedFailures) ?? (apiResponse.access?.reason || "Access denied by PDLSS policy"),
|
|
4415
4481
|
registrationUrl: urls?.registrationUrl ?? "",
|
|
4416
4482
|
documentationUrl: urls?.documentationUrl ?? "",
|
|
4417
4483
|
// 5.1.0: anonymous callers land on this branch — steer MCP-hosted
|
|
@@ -4511,7 +4577,7 @@ async function verify(config, request, options) {
|
|
|
4511
4577
|
registrationUrl: urls?.registrationUrl ?? "",
|
|
4512
4578
|
documentationUrl: urls?.documentationUrl ?? ""
|
|
4513
4579
|
};
|
|
4514
|
-
} else if (result.recommendation === "step_up_required") {
|
|
4580
|
+
} else if (result.recommendation === "step_up_required" && result.identityVerified) {
|
|
4515
4581
|
result.requiresStepUp = true;
|
|
4516
4582
|
result.denialReasons = serverDenialReasons ?? result.recommendationReasons ?? ["Step-up verification required"];
|
|
4517
4583
|
}
|
|
@@ -4540,6 +4606,217 @@ var DEFAULT_EDGE_CONFIG = Object.freeze({
|
|
|
4540
4606
|
var DEFAULT_TTL_MS = 60 * 1e3;
|
|
4541
4607
|
var DEFAULT_MAX_STALE_MS = 24 * 60 * 60 * 1e3;
|
|
4542
4608
|
|
|
4609
|
+
// src/edge-core/events.ts
|
|
4610
|
+
async function withBudget(promise, ms) {
|
|
4611
|
+
let timer;
|
|
4612
|
+
try {
|
|
4613
|
+
return await Promise.race([
|
|
4614
|
+
promise,
|
|
4615
|
+
new Promise((resolve) => {
|
|
4616
|
+
timer = setTimeout(() => resolve(void 0), ms);
|
|
4617
|
+
})
|
|
4618
|
+
]);
|
|
4619
|
+
} catch {
|
|
4620
|
+
return void 0;
|
|
4621
|
+
} finally {
|
|
4622
|
+
if (timer) clearTimeout(timer);
|
|
4623
|
+
}
|
|
4624
|
+
}
|
|
4625
|
+
var destKeyOf = (d) => `${d.apiBaseUrl}\0${d.apiKey ?? ""}\0${d.counterparty}\0${d.adapter ?? ""}`;
|
|
4626
|
+
var BeaconBuffer = class {
|
|
4627
|
+
constructor(options = {}) {
|
|
4628
|
+
this.queue = [];
|
|
4629
|
+
this.droppedSinceLast = 0;
|
|
4630
|
+
this.droppedTotal = 0;
|
|
4631
|
+
this.deliveredTotal = 0;
|
|
4632
|
+
this.backoffUntil = 0;
|
|
4633
|
+
this.collapse = /* @__PURE__ */ new Map();
|
|
4634
|
+
/** Keys the backend answered 401 for — later batches go unauthenticated. */
|
|
4635
|
+
this.rejectedKeys = /* @__PURE__ */ new Set();
|
|
4636
|
+
this.opts = {
|
|
4637
|
+
maxItems: options.maxItems ?? 1e3,
|
|
4638
|
+
maxBatch: options.maxBatch ?? 100,
|
|
4639
|
+
maxAttempts: options.maxAttempts ?? 3,
|
|
4640
|
+
collapseWindowMs: options.collapseWindowMs ?? 6e4,
|
|
4641
|
+
collapseMaxKeys: options.collapseMaxKeys ?? 1e3,
|
|
4642
|
+
requestTimeoutMs: options.requestTimeoutMs ?? 1e4,
|
|
4643
|
+
retryBackoffMs: options.retryBackoffMs ?? 1e3,
|
|
4644
|
+
now: options.now ?? Date.now
|
|
4645
|
+
};
|
|
4646
|
+
}
|
|
4647
|
+
/**
|
|
4648
|
+
* Queue one beacon. With a `collapseKey`, a repeat inside the window is
|
|
4649
|
+
* merged into a held aggregate (sent when the window closes) instead of
|
|
4650
|
+
* becoming its own item.
|
|
4651
|
+
*/
|
|
4652
|
+
enqueue(dest, item, collapseKey) {
|
|
4653
|
+
const now = this.opts.now();
|
|
4654
|
+
if (collapseKey) {
|
|
4655
|
+
const entry = this.collapse.get(collapseKey);
|
|
4656
|
+
if (entry && now - entry.firstSeenAt < this.opts.collapseWindowMs) {
|
|
4657
|
+
for (const target of [entry.first, entry.held]) {
|
|
4658
|
+
if (target && !target.inFlight && this.queue.includes(target)) {
|
|
4659
|
+
target.item.repeatCount = (target.item.repeatCount ?? 1) + 1;
|
|
4660
|
+
return;
|
|
4661
|
+
}
|
|
4662
|
+
}
|
|
4663
|
+
const held = this.push(
|
|
4664
|
+
dest,
|
|
4665
|
+
{ ...item, repeatCount: 1 },
|
|
4666
|
+
entry.firstSeenAt + this.opts.collapseWindowMs
|
|
4667
|
+
);
|
|
4668
|
+
entry.held = held;
|
|
4669
|
+
return;
|
|
4670
|
+
}
|
|
4671
|
+
this.collapse.delete(collapseKey);
|
|
4672
|
+
if (this.collapse.size >= this.opts.collapseMaxKeys) {
|
|
4673
|
+
const oldest = this.collapse.keys().next().value;
|
|
4674
|
+
if (oldest !== void 0) this.collapse.delete(oldest);
|
|
4675
|
+
}
|
|
4676
|
+
const fresh = { firstSeenAt: now };
|
|
4677
|
+
this.collapse.set(collapseKey, fresh);
|
|
4678
|
+
fresh.first = this.push(dest, item, now);
|
|
4679
|
+
return;
|
|
4680
|
+
}
|
|
4681
|
+
this.push(dest, item, now);
|
|
4682
|
+
}
|
|
4683
|
+
/**
|
|
4684
|
+
* Deliver every eligible queued item. Concurrent callers share ONE
|
|
4685
|
+
* in-flight drain (it survives the caller's budget and a Lambda freeze),
|
|
4686
|
+
* so nothing in flight is ever sent twice; items queued while it runs are
|
|
4687
|
+
* picked up by the same drain.
|
|
4688
|
+
*/
|
|
4689
|
+
flush() {
|
|
4690
|
+
if (!this.inFlight) {
|
|
4691
|
+
this.inFlight = this.drain().finally(() => {
|
|
4692
|
+
this.inFlight = void 0;
|
|
4693
|
+
});
|
|
4694
|
+
}
|
|
4695
|
+
return this.inFlight;
|
|
4696
|
+
}
|
|
4697
|
+
/** Counters for tests and diagnostics. */
|
|
4698
|
+
stats() {
|
|
4699
|
+
return {
|
|
4700
|
+
queueDepth: this.queue.length,
|
|
4701
|
+
droppedSinceLast: this.droppedSinceLast,
|
|
4702
|
+
droppedTotal: this.droppedTotal,
|
|
4703
|
+
deliveredTotal: this.deliveredTotal,
|
|
4704
|
+
flushing: this.inFlight !== void 0
|
|
4705
|
+
};
|
|
4706
|
+
}
|
|
4707
|
+
push(dest, item, eligibleAt) {
|
|
4708
|
+
while (this.queue.length >= this.opts.maxItems) this.dropOldest();
|
|
4709
|
+
const entry = {
|
|
4710
|
+
dest,
|
|
4711
|
+
destKey: destKeyOf(dest),
|
|
4712
|
+
item,
|
|
4713
|
+
attempts: 0,
|
|
4714
|
+
eligibleAt,
|
|
4715
|
+
inFlight: false
|
|
4716
|
+
};
|
|
4717
|
+
this.queue.push(entry);
|
|
4718
|
+
return entry;
|
|
4719
|
+
}
|
|
4720
|
+
dropOldest() {
|
|
4721
|
+
if (this.queue.shift()) this.countDropped(1);
|
|
4722
|
+
}
|
|
4723
|
+
countDropped(n) {
|
|
4724
|
+
this.droppedSinceLast += n;
|
|
4725
|
+
this.droppedTotal += n;
|
|
4726
|
+
}
|
|
4727
|
+
async drain() {
|
|
4728
|
+
for (; ; ) {
|
|
4729
|
+
const now = this.opts.now();
|
|
4730
|
+
if (now < this.backoffUntil) return;
|
|
4731
|
+
const batch = this.takeBatch(now);
|
|
4732
|
+
if (batch.length === 0) return;
|
|
4733
|
+
const ok = await this.send(batch);
|
|
4734
|
+
if (!ok) return;
|
|
4735
|
+
}
|
|
4736
|
+
}
|
|
4737
|
+
/** Oldest eligible item + up to maxBatch-1 more for the same destination. */
|
|
4738
|
+
takeBatch(now) {
|
|
4739
|
+
const first = this.queue.find((q) => q.eligibleAt <= now);
|
|
4740
|
+
if (!first) return [];
|
|
4741
|
+
const batch = [];
|
|
4742
|
+
const rest = [];
|
|
4743
|
+
for (const q of this.queue) {
|
|
4744
|
+
if (batch.length < this.opts.maxBatch && q.destKey === first.destKey && q.eligibleAt <= now) {
|
|
4745
|
+
q.inFlight = true;
|
|
4746
|
+
batch.push(q);
|
|
4747
|
+
} else {
|
|
4748
|
+
rest.push(q);
|
|
4749
|
+
}
|
|
4750
|
+
}
|
|
4751
|
+
this.queue = rest;
|
|
4752
|
+
return batch;
|
|
4753
|
+
}
|
|
4754
|
+
/** POST one batch. Returns false when the drain should pause (backoff). */
|
|
4755
|
+
async send(batch) {
|
|
4756
|
+
const dest = batch[0].dest;
|
|
4757
|
+
const useKey = dest.apiKey && !this.rejectedKeys.has(dest.apiKey) ? dest.apiKey : void 0;
|
|
4758
|
+
const reportedDropped = this.droppedSinceLast;
|
|
4759
|
+
const meta = {
|
|
4760
|
+
droppedSinceLast: reportedDropped,
|
|
4761
|
+
queueDepth: this.queue.length,
|
|
4762
|
+
adapter: dest.adapter ?? "edge-core",
|
|
4763
|
+
version: SDK_VERSION
|
|
4764
|
+
};
|
|
4765
|
+
const controller = typeof AbortController !== "undefined" ? new AbortController() : void 0;
|
|
4766
|
+
const response = await withBudget(
|
|
4767
|
+
sdkFetch(`${dest.apiBaseUrl}/verification-activity/edge-events`, {
|
|
4768
|
+
method: "POST",
|
|
4769
|
+
headers: {
|
|
4770
|
+
"Content-Type": "application/json",
|
|
4771
|
+
...useKey && { Authorization: `Bearer ${useKey}` }
|
|
4772
|
+
},
|
|
4773
|
+
body: JSON.stringify({ events: batch.map((q) => q.item), meta }),
|
|
4774
|
+
...controller && { signal: controller.signal }
|
|
4775
|
+
}),
|
|
4776
|
+
this.opts.requestTimeoutMs
|
|
4777
|
+
);
|
|
4778
|
+
if (!response) controller?.abort();
|
|
4779
|
+
const status = response?.status;
|
|
4780
|
+
for (const q of batch) q.inFlight = false;
|
|
4781
|
+
if (status !== void 0 && status >= 200 && status < 300) {
|
|
4782
|
+
this.droppedSinceLast = Math.max(0, this.droppedSinceLast - reportedDropped);
|
|
4783
|
+
this.deliveredTotal += batch.length;
|
|
4784
|
+
return true;
|
|
4785
|
+
}
|
|
4786
|
+
if (status === 401 && useKey) {
|
|
4787
|
+
this.rejectedKeys.add(useKey);
|
|
4788
|
+
this.requeue(batch, false);
|
|
4789
|
+
return true;
|
|
4790
|
+
}
|
|
4791
|
+
if (status === 429) {
|
|
4792
|
+
const retryAfter = Number(response?.headers.get("retry-after"));
|
|
4793
|
+
const waitMs = Number.isFinite(retryAfter) && retryAfter > 0 ? Math.min(retryAfter, 120) * 1e3 : 3e4;
|
|
4794
|
+
this.backoffUntil = this.opts.now() + waitMs;
|
|
4795
|
+
this.requeue(batch, false);
|
|
4796
|
+
return false;
|
|
4797
|
+
}
|
|
4798
|
+
if (status !== void 0 && status >= 400 && status < 500) {
|
|
4799
|
+
this.countDropped(batch.length);
|
|
4800
|
+
return true;
|
|
4801
|
+
}
|
|
4802
|
+
this.backoffUntil = this.opts.now() + this.opts.retryBackoffMs;
|
|
4803
|
+
this.requeue(batch, true);
|
|
4804
|
+
return false;
|
|
4805
|
+
}
|
|
4806
|
+
/** Put a failed batch back at the head of the queue (order preserved). */
|
|
4807
|
+
requeue(batch, countAttempt) {
|
|
4808
|
+
const keep = [];
|
|
4809
|
+
for (const q of batch) {
|
|
4810
|
+
if (countAttempt) q.attempts += 1;
|
|
4811
|
+
if (q.attempts >= this.opts.maxAttempts) this.countDropped(1);
|
|
4812
|
+
else keep.push(q);
|
|
4813
|
+
}
|
|
4814
|
+
this.queue = [...keep, ...this.queue];
|
|
4815
|
+
while (this.queue.length > this.opts.maxItems) this.dropOldest();
|
|
4816
|
+
}
|
|
4817
|
+
};
|
|
4818
|
+
var beaconBuffer = new BeaconBuffer();
|
|
4819
|
+
|
|
4543
4820
|
// src/adapters/express.ts
|
|
4544
4821
|
var DEFAULT_ROUTES_REFRESH_MS = 5 * 60 * 1e3;
|
|
4545
4822
|
|