@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
|
@@ -3713,7 +3713,7 @@ Policy saved to ${outputPath}`);
|
|
|
3713
3713
|
};
|
|
3714
3714
|
|
|
3715
3715
|
// src/version.ts
|
|
3716
|
-
var SDK_VERSION = "5.
|
|
3716
|
+
var SDK_VERSION = "5.12.0";
|
|
3717
3717
|
|
|
3718
3718
|
// src/http.ts
|
|
3719
3719
|
var SDK_USER_AGENT = `astrasync-sdk/${SDK_VERSION}`;
|
|
@@ -4644,6 +4644,14 @@ function getCachedWellKnownUrls(apiBaseUrl) {
|
|
|
4644
4644
|
return cache.get(apiBaseUrl)?.data;
|
|
4645
4645
|
}
|
|
4646
4646
|
|
|
4647
|
+
// src/failure-posture.ts
|
|
4648
|
+
var REJECTED_IDENTITY_DIMENSIONS = /* @__PURE__ */ new Set([
|
|
4649
|
+
"identity.invalid_agent_id",
|
|
4650
|
+
"identity.unknown_agent",
|
|
4651
|
+
"agent.lookup"
|
|
4652
|
+
]);
|
|
4653
|
+
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.";
|
|
4654
|
+
|
|
4647
4655
|
// src/verify.ts
|
|
4648
4656
|
var DEFAULT_CONFIG = {
|
|
4649
4657
|
apiBaseUrl: "https://astrasync.ai/api",
|
|
@@ -4855,11 +4863,44 @@ function createGuidanceResponse(_config, reason, options = {}) {
|
|
|
4855
4863
|
// coercing the absent recommendation to a policy 'deny'. Misconfig is
|
|
4856
4864
|
// deterministic and intentionally NOT marked retryable.
|
|
4857
4865
|
...isApiError && { retryable: true },
|
|
4866
|
+
...options.httpStatus !== void 0 && { httpStatus: options.httpStatus },
|
|
4867
|
+
...options.retryAfterMs !== void 0 && { retryAfterMs: options.retryAfterMs },
|
|
4858
4868
|
correlationId: options.correlationId,
|
|
4859
4869
|
attemptId: options.attemptId,
|
|
4860
4870
|
verifiedAt: /* @__PURE__ */ new Date()
|
|
4861
4871
|
};
|
|
4862
4872
|
}
|
|
4873
|
+
async function readJsonSafe(response) {
|
|
4874
|
+
try {
|
|
4875
|
+
const parsed = await response.json();
|
|
4876
|
+
return parsed && typeof parsed === "object" ? parsed : {};
|
|
4877
|
+
} catch {
|
|
4878
|
+
return {};
|
|
4879
|
+
}
|
|
4880
|
+
}
|
|
4881
|
+
function rejectedIdentityGuidance(failures) {
|
|
4882
|
+
const f = failures?.find((x) => REJECTED_IDENTITY_DIMENSIONS.has(x.dimension));
|
|
4883
|
+
if (!f) return void 0;
|
|
4884
|
+
if (f.dimension === "agent.lookup") {
|
|
4885
|
+
return `The presented agent identifier is not registered with AstraSync. ${UNKNOWN_AGENT_GUIDANCE}`;
|
|
4886
|
+
}
|
|
4887
|
+
return f.guidance ? `${f.message} ${f.guidance}` : f.message;
|
|
4888
|
+
}
|
|
4889
|
+
var MAX_RETRY_AFTER_MS = 15 * 60 * 1e3;
|
|
4890
|
+
function parseRetryAfterMs(response) {
|
|
4891
|
+
const raw = response.headers?.get?.("retry-after");
|
|
4892
|
+
if (!raw) return void 0;
|
|
4893
|
+
const trimmed = raw.trim();
|
|
4894
|
+
let ms;
|
|
4895
|
+
if (/^\d+(\.\d+)?$/.test(trimmed)) {
|
|
4896
|
+
ms = Number(trimmed) * 1e3;
|
|
4897
|
+
} else {
|
|
4898
|
+
const at = Date.parse(trimmed);
|
|
4899
|
+
if (Number.isNaN(at)) return void 0;
|
|
4900
|
+
ms = at - Date.now();
|
|
4901
|
+
}
|
|
4902
|
+
return Math.min(MAX_RETRY_AFTER_MS, Math.max(0, Math.round(ms)));
|
|
4903
|
+
}
|
|
4863
4904
|
async function callVerifyAccessAPI(config, request2) {
|
|
4864
4905
|
const { credentials, ...requestData } = request2;
|
|
4865
4906
|
const body = {
|
|
@@ -4916,7 +4957,8 @@ async function callVerifyAccessAPI(config, request2) {
|
|
|
4916
4957
|
body: JSON.stringify(body),
|
|
4917
4958
|
signal: AbortSignal.timeout(config.verifyTimeoutMs ?? 1e4)
|
|
4918
4959
|
});
|
|
4919
|
-
const data = await response
|
|
4960
|
+
const data = await readJsonSafe(response);
|
|
4961
|
+
const retryAfterMs = parseRetryAfterMs(response);
|
|
4920
4962
|
if (response.status === 410) {
|
|
4921
4963
|
return {
|
|
4922
4964
|
success: true,
|
|
@@ -4954,6 +4996,23 @@ async function callVerifyAccessAPI(config, request2) {
|
|
|
4954
4996
|
}
|
|
4955
4997
|
};
|
|
4956
4998
|
}
|
|
4999
|
+
if (response.status === 404 && credentials.astraId && (data?.error === "AGENT_NOT_FOUND" || typeof data?.message === "string" && /agent/i.test(data.message))) {
|
|
5000
|
+
return {
|
|
5001
|
+
success: true,
|
|
5002
|
+
attemptId: typeof data?.attemptId === "string" ? data.attemptId : void 0,
|
|
5003
|
+
access: {
|
|
5004
|
+
allowed: false,
|
|
5005
|
+
reason: "unknown_agent",
|
|
5006
|
+
failures: [
|
|
5007
|
+
{
|
|
5008
|
+
dimension: "identity.unknown_agent",
|
|
5009
|
+
message: "The presented agent identifier is not registered with AstraSync.",
|
|
5010
|
+
guidance: UNKNOWN_AGENT_GUIDANCE
|
|
5011
|
+
}
|
|
5012
|
+
]
|
|
5013
|
+
}
|
|
5014
|
+
};
|
|
5015
|
+
}
|
|
4957
5016
|
if (!response.ok) {
|
|
4958
5017
|
if (response.status === 401) {
|
|
4959
5018
|
return {
|
|
@@ -4968,9 +5027,11 @@ async function callVerifyAccessAPI(config, request2) {
|
|
|
4968
5027
|
}
|
|
4969
5028
|
return {
|
|
4970
5029
|
success: false,
|
|
4971
|
-
error: data.message || data.error || `API returned ${response.status}`,
|
|
5030
|
+
error: typeof data?.message === "string" && data.message || typeof data?.error === "string" && data.error || `API returned ${response.status}`,
|
|
4972
5031
|
correlationId: typeof data?.correlationId === "string" ? data.correlationId : void 0,
|
|
4973
|
-
attemptId: typeof data?.attemptId === "string" ? data.attemptId : void 0
|
|
5032
|
+
attemptId: typeof data?.attemptId === "string" ? data.attemptId : void 0,
|
|
5033
|
+
httpStatus: response.status,
|
|
5034
|
+
...retryAfterMs !== void 0 && { retryAfterMs }
|
|
4974
5035
|
};
|
|
4975
5036
|
}
|
|
4976
5037
|
return data;
|
|
@@ -5042,12 +5103,14 @@ async function verify(config, request2, options) {
|
|
|
5042
5103
|
correlationId: apiResponse.correlationId,
|
|
5043
5104
|
attemptId: apiResponse.attemptId,
|
|
5044
5105
|
remediation: apiResponse.remediation,
|
|
5106
|
+
httpStatus: apiResponse.httpStatus,
|
|
5107
|
+
retryAfterMs: apiResponse.retryAfterMs,
|
|
5045
5108
|
urls
|
|
5046
5109
|
});
|
|
5047
5110
|
}
|
|
5048
5111
|
if (!apiResponse.access?.allowed) {
|
|
5049
5112
|
const aggregatedFailures = apiResponse.access?.failures;
|
|
5050
|
-
const idVerifiedFromBackend = apiResponse.verificationContext?.idVerified === true;
|
|
5113
|
+
const idVerifiedFromBackend = apiResponse.verificationContext?.idVerified === true && !aggregatedFailures?.some((f) => REJECTED_IDENTITY_DIMENSIONS.has(f.dimension));
|
|
5051
5114
|
const result2 = {
|
|
5052
5115
|
identityVerified: idVerifiedFromBackend,
|
|
5053
5116
|
policyAllowed: false,
|
|
@@ -5059,7 +5122,10 @@ async function verify(config, request2, options) {
|
|
|
5059
5122
|
requiresStepUp: apiResponse.access?.requiresStepUp,
|
|
5060
5123
|
requiresApproval: apiResponse.access?.requiresApproval,
|
|
5061
5124
|
guidance: {
|
|
5062
|
-
|
|
5125
|
+
// 5.12.0: a presented-but-rejected id (malformed / unknown) carries
|
|
5126
|
+
// actionable registration guidance on its failure — surface it
|
|
5127
|
+
// instead of the bare machine reason ('unknown_agent').
|
|
5128
|
+
message: rejectedIdentityGuidance(aggregatedFailures) ?? (apiResponse.access?.reason || "Access denied by PDLSS policy"),
|
|
5063
5129
|
registrationUrl: urls?.registrationUrl ?? "",
|
|
5064
5130
|
documentationUrl: urls?.documentationUrl ?? "",
|
|
5065
5131
|
// 5.1.0: anonymous callers land on this branch — steer MCP-hosted
|
|
@@ -5159,7 +5225,7 @@ async function verify(config, request2, options) {
|
|
|
5159
5225
|
registrationUrl: urls?.registrationUrl ?? "",
|
|
5160
5226
|
documentationUrl: urls?.documentationUrl ?? ""
|
|
5161
5227
|
};
|
|
5162
|
-
} else if (result.recommendation === "step_up_required") {
|
|
5228
|
+
} else if (result.recommendation === "step_up_required" && result.identityVerified) {
|
|
5163
5229
|
result.requiresStepUp = true;
|
|
5164
5230
|
result.denialReasons = serverDenialReasons ?? result.recommendationReasons ?? ["Step-up verification required"];
|
|
5165
5231
|
}
|
|
@@ -5188,6 +5254,217 @@ var DEFAULT_EDGE_CONFIG = Object.freeze({
|
|
|
5188
5254
|
var DEFAULT_TTL_MS = 60 * 1e3;
|
|
5189
5255
|
var DEFAULT_MAX_STALE_MS = 24 * 60 * 60 * 1e3;
|
|
5190
5256
|
|
|
5257
|
+
// src/edge-core/events.ts
|
|
5258
|
+
async function withBudget(promise, ms) {
|
|
5259
|
+
let timer;
|
|
5260
|
+
try {
|
|
5261
|
+
return await Promise.race([
|
|
5262
|
+
promise,
|
|
5263
|
+
new Promise((resolve) => {
|
|
5264
|
+
timer = setTimeout(() => resolve(void 0), ms);
|
|
5265
|
+
})
|
|
5266
|
+
]);
|
|
5267
|
+
} catch {
|
|
5268
|
+
return void 0;
|
|
5269
|
+
} finally {
|
|
5270
|
+
if (timer) clearTimeout(timer);
|
|
5271
|
+
}
|
|
5272
|
+
}
|
|
5273
|
+
var destKeyOf = (d) => `${d.apiBaseUrl}\0${d.apiKey ?? ""}\0${d.counterparty}\0${d.adapter ?? ""}`;
|
|
5274
|
+
var BeaconBuffer = class {
|
|
5275
|
+
constructor(options = {}) {
|
|
5276
|
+
this.queue = [];
|
|
5277
|
+
this.droppedSinceLast = 0;
|
|
5278
|
+
this.droppedTotal = 0;
|
|
5279
|
+
this.deliveredTotal = 0;
|
|
5280
|
+
this.backoffUntil = 0;
|
|
5281
|
+
this.collapse = /* @__PURE__ */ new Map();
|
|
5282
|
+
/** Keys the backend answered 401 for — later batches go unauthenticated. */
|
|
5283
|
+
this.rejectedKeys = /* @__PURE__ */ new Set();
|
|
5284
|
+
this.opts = {
|
|
5285
|
+
maxItems: options.maxItems ?? 1e3,
|
|
5286
|
+
maxBatch: options.maxBatch ?? 100,
|
|
5287
|
+
maxAttempts: options.maxAttempts ?? 3,
|
|
5288
|
+
collapseWindowMs: options.collapseWindowMs ?? 6e4,
|
|
5289
|
+
collapseMaxKeys: options.collapseMaxKeys ?? 1e3,
|
|
5290
|
+
requestTimeoutMs: options.requestTimeoutMs ?? 1e4,
|
|
5291
|
+
retryBackoffMs: options.retryBackoffMs ?? 1e3,
|
|
5292
|
+
now: options.now ?? Date.now
|
|
5293
|
+
};
|
|
5294
|
+
}
|
|
5295
|
+
/**
|
|
5296
|
+
* Queue one beacon. With a `collapseKey`, a repeat inside the window is
|
|
5297
|
+
* merged into a held aggregate (sent when the window closes) instead of
|
|
5298
|
+
* becoming its own item.
|
|
5299
|
+
*/
|
|
5300
|
+
enqueue(dest, item, collapseKey) {
|
|
5301
|
+
const now = this.opts.now();
|
|
5302
|
+
if (collapseKey) {
|
|
5303
|
+
const entry = this.collapse.get(collapseKey);
|
|
5304
|
+
if (entry && now - entry.firstSeenAt < this.opts.collapseWindowMs) {
|
|
5305
|
+
for (const target of [entry.first, entry.held]) {
|
|
5306
|
+
if (target && !target.inFlight && this.queue.includes(target)) {
|
|
5307
|
+
target.item.repeatCount = (target.item.repeatCount ?? 1) + 1;
|
|
5308
|
+
return;
|
|
5309
|
+
}
|
|
5310
|
+
}
|
|
5311
|
+
const held = this.push(
|
|
5312
|
+
dest,
|
|
5313
|
+
{ ...item, repeatCount: 1 },
|
|
5314
|
+
entry.firstSeenAt + this.opts.collapseWindowMs
|
|
5315
|
+
);
|
|
5316
|
+
entry.held = held;
|
|
5317
|
+
return;
|
|
5318
|
+
}
|
|
5319
|
+
this.collapse.delete(collapseKey);
|
|
5320
|
+
if (this.collapse.size >= this.opts.collapseMaxKeys) {
|
|
5321
|
+
const oldest = this.collapse.keys().next().value;
|
|
5322
|
+
if (oldest !== void 0) this.collapse.delete(oldest);
|
|
5323
|
+
}
|
|
5324
|
+
const fresh = { firstSeenAt: now };
|
|
5325
|
+
this.collapse.set(collapseKey, fresh);
|
|
5326
|
+
fresh.first = this.push(dest, item, now);
|
|
5327
|
+
return;
|
|
5328
|
+
}
|
|
5329
|
+
this.push(dest, item, now);
|
|
5330
|
+
}
|
|
5331
|
+
/**
|
|
5332
|
+
* Deliver every eligible queued item. Concurrent callers share ONE
|
|
5333
|
+
* in-flight drain (it survives the caller's budget and a Lambda freeze),
|
|
5334
|
+
* so nothing in flight is ever sent twice; items queued while it runs are
|
|
5335
|
+
* picked up by the same drain.
|
|
5336
|
+
*/
|
|
5337
|
+
flush() {
|
|
5338
|
+
if (!this.inFlight) {
|
|
5339
|
+
this.inFlight = this.drain().finally(() => {
|
|
5340
|
+
this.inFlight = void 0;
|
|
5341
|
+
});
|
|
5342
|
+
}
|
|
5343
|
+
return this.inFlight;
|
|
5344
|
+
}
|
|
5345
|
+
/** Counters for tests and diagnostics. */
|
|
5346
|
+
stats() {
|
|
5347
|
+
return {
|
|
5348
|
+
queueDepth: this.queue.length,
|
|
5349
|
+
droppedSinceLast: this.droppedSinceLast,
|
|
5350
|
+
droppedTotal: this.droppedTotal,
|
|
5351
|
+
deliveredTotal: this.deliveredTotal,
|
|
5352
|
+
flushing: this.inFlight !== void 0
|
|
5353
|
+
};
|
|
5354
|
+
}
|
|
5355
|
+
push(dest, item, eligibleAt) {
|
|
5356
|
+
while (this.queue.length >= this.opts.maxItems) this.dropOldest();
|
|
5357
|
+
const entry = {
|
|
5358
|
+
dest,
|
|
5359
|
+
destKey: destKeyOf(dest),
|
|
5360
|
+
item,
|
|
5361
|
+
attempts: 0,
|
|
5362
|
+
eligibleAt,
|
|
5363
|
+
inFlight: false
|
|
5364
|
+
};
|
|
5365
|
+
this.queue.push(entry);
|
|
5366
|
+
return entry;
|
|
5367
|
+
}
|
|
5368
|
+
dropOldest() {
|
|
5369
|
+
if (this.queue.shift()) this.countDropped(1);
|
|
5370
|
+
}
|
|
5371
|
+
countDropped(n) {
|
|
5372
|
+
this.droppedSinceLast += n;
|
|
5373
|
+
this.droppedTotal += n;
|
|
5374
|
+
}
|
|
5375
|
+
async drain() {
|
|
5376
|
+
for (; ; ) {
|
|
5377
|
+
const now = this.opts.now();
|
|
5378
|
+
if (now < this.backoffUntil) return;
|
|
5379
|
+
const batch = this.takeBatch(now);
|
|
5380
|
+
if (batch.length === 0) return;
|
|
5381
|
+
const ok = await this.send(batch);
|
|
5382
|
+
if (!ok) return;
|
|
5383
|
+
}
|
|
5384
|
+
}
|
|
5385
|
+
/** Oldest eligible item + up to maxBatch-1 more for the same destination. */
|
|
5386
|
+
takeBatch(now) {
|
|
5387
|
+
const first = this.queue.find((q) => q.eligibleAt <= now);
|
|
5388
|
+
if (!first) return [];
|
|
5389
|
+
const batch = [];
|
|
5390
|
+
const rest = [];
|
|
5391
|
+
for (const q of this.queue) {
|
|
5392
|
+
if (batch.length < this.opts.maxBatch && q.destKey === first.destKey && q.eligibleAt <= now) {
|
|
5393
|
+
q.inFlight = true;
|
|
5394
|
+
batch.push(q);
|
|
5395
|
+
} else {
|
|
5396
|
+
rest.push(q);
|
|
5397
|
+
}
|
|
5398
|
+
}
|
|
5399
|
+
this.queue = rest;
|
|
5400
|
+
return batch;
|
|
5401
|
+
}
|
|
5402
|
+
/** POST one batch. Returns false when the drain should pause (backoff). */
|
|
5403
|
+
async send(batch) {
|
|
5404
|
+
const dest = batch[0].dest;
|
|
5405
|
+
const useKey = dest.apiKey && !this.rejectedKeys.has(dest.apiKey) ? dest.apiKey : void 0;
|
|
5406
|
+
const reportedDropped = this.droppedSinceLast;
|
|
5407
|
+
const meta = {
|
|
5408
|
+
droppedSinceLast: reportedDropped,
|
|
5409
|
+
queueDepth: this.queue.length,
|
|
5410
|
+
adapter: dest.adapter ?? "edge-core",
|
|
5411
|
+
version: SDK_VERSION
|
|
5412
|
+
};
|
|
5413
|
+
const controller = typeof AbortController !== "undefined" ? new AbortController() : void 0;
|
|
5414
|
+
const response = await withBudget(
|
|
5415
|
+
sdkFetch(`${dest.apiBaseUrl}/verification-activity/edge-events`, {
|
|
5416
|
+
method: "POST",
|
|
5417
|
+
headers: {
|
|
5418
|
+
"Content-Type": "application/json",
|
|
5419
|
+
...useKey && { Authorization: `Bearer ${useKey}` }
|
|
5420
|
+
},
|
|
5421
|
+
body: JSON.stringify({ events: batch.map((q) => q.item), meta }),
|
|
5422
|
+
...controller && { signal: controller.signal }
|
|
5423
|
+
}),
|
|
5424
|
+
this.opts.requestTimeoutMs
|
|
5425
|
+
);
|
|
5426
|
+
if (!response) controller?.abort();
|
|
5427
|
+
const status = response?.status;
|
|
5428
|
+
for (const q of batch) q.inFlight = false;
|
|
5429
|
+
if (status !== void 0 && status >= 200 && status < 300) {
|
|
5430
|
+
this.droppedSinceLast = Math.max(0, this.droppedSinceLast - reportedDropped);
|
|
5431
|
+
this.deliveredTotal += batch.length;
|
|
5432
|
+
return true;
|
|
5433
|
+
}
|
|
5434
|
+
if (status === 401 && useKey) {
|
|
5435
|
+
this.rejectedKeys.add(useKey);
|
|
5436
|
+
this.requeue(batch, false);
|
|
5437
|
+
return true;
|
|
5438
|
+
}
|
|
5439
|
+
if (status === 429) {
|
|
5440
|
+
const retryAfter = Number(response?.headers.get("retry-after"));
|
|
5441
|
+
const waitMs = Number.isFinite(retryAfter) && retryAfter > 0 ? Math.min(retryAfter, 120) * 1e3 : 3e4;
|
|
5442
|
+
this.backoffUntil = this.opts.now() + waitMs;
|
|
5443
|
+
this.requeue(batch, false);
|
|
5444
|
+
return false;
|
|
5445
|
+
}
|
|
5446
|
+
if (status !== void 0 && status >= 400 && status < 500) {
|
|
5447
|
+
this.countDropped(batch.length);
|
|
5448
|
+
return true;
|
|
5449
|
+
}
|
|
5450
|
+
this.backoffUntil = this.opts.now() + this.opts.retryBackoffMs;
|
|
5451
|
+
this.requeue(batch, true);
|
|
5452
|
+
return false;
|
|
5453
|
+
}
|
|
5454
|
+
/** Put a failed batch back at the head of the queue (order preserved). */
|
|
5455
|
+
requeue(batch, countAttempt) {
|
|
5456
|
+
const keep = [];
|
|
5457
|
+
for (const q of batch) {
|
|
5458
|
+
if (countAttempt) q.attempts += 1;
|
|
5459
|
+
if (q.attempts >= this.opts.maxAttempts) this.countDropped(1);
|
|
5460
|
+
else keep.push(q);
|
|
5461
|
+
}
|
|
5462
|
+
this.queue = [...keep, ...this.queue];
|
|
5463
|
+
while (this.queue.length > this.opts.maxItems) this.dropOldest();
|
|
5464
|
+
}
|
|
5465
|
+
};
|
|
5466
|
+
var beaconBuffer = new BeaconBuffer();
|
|
5467
|
+
|
|
5191
5468
|
// src/adapters/express.ts
|
|
5192
5469
|
var DEFAULT_ROUTES_REFRESH_MS = 5 * 60 * 1e3;
|
|
5193
5470
|
|