@volter/twin-inngest 0.1.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.
@@ -0,0 +1,404 @@
1
+ // Inngest's CLIENT-SIDE RATE BUDGET — the pack's DECLARATION (the numbers) plus `guardInngestClient`,
2
+ // the choke point every live Inngest call goes through. The MECHANISM — the durable token-keyed
3
+ // ledger, the rolling window, reserve-under-lock, the `Retry-After`/429 cooldown, fail-CLOSED on a
4
+ // corrupt ledger — lives ONCE in the vendor-agnostic kernel (`@volter/world-core` → `rateBudget.ts`).
5
+ // Read that module's header for the full rationale AND for the honest list of what the guard does
6
+ // NOT guarantee (an injected clock or ledger path still defeats it — it guards carelessness, not
7
+ // malice). This module is modeled on notion-budget.ts, the reference injected-client decorator.
8
+ //
9
+ // ── WHY INNGEST NEEDS ONE ───────────────────────────────────────────────────────────
10
+ // Inngest's REST reference (inngest.com/docs/reference/rest-api, api-docs.inngest.com) documents NO
11
+ // rate limit, no 429, and no Retry-After for /v1/events or /v1/runs. The single rate-limit statement
12
+ // in the whole API reference is an annotation on a DIFFERENT endpoint — "Fetch function run jobs …
13
+ // This endpoint is rate limited and cached for 5 seconds" — with no number, and that endpoint is not
14
+ // part of this connector's surface. The documented usage limits are payload-shape limits (5000 events
15
+ // per request, 10 MiB batches, per-plan event payload sizes), not rates. So the vendor's rate
16
+ // behaviour here is entirely undocumented, which is the case a client-side ceiling exists for.
17
+ //
18
+ // ── HOW THE CEILING WAS CHOSEN ──────────────────────────────────────────────────────────────
19
+ // NO DOCUMENTED SCALAR LIMIT exists for the endpoints this connector calls, so this budget does NOT
20
+ // claim one. It is pinned to the kernel's conservative fallback (DEFAULT_RATE_BUDGET: 60 weighted
21
+ // units / 60s at weight 2 = 30 calls/minute) — no more permissive than an undeclared vendor already
22
+ // gets.
23
+ //
24
+ // ── WHAT THIS DOES NOT DO: PACE ─────────────────────────────────────────────────────────────
25
+ // It bounds the 60s AVERAGE; it does NOT bound the instantaneous rate. The window has no
26
+ // spacing, so a tight `await` loop can legitimately fire the whole allowance in a fraction of a
27
+ // second. In that shape the vendor's own 429 can arrive BEFORE this ceiling does, and the backstop
28
+ // is then the COOLDOWN: the guard reads the back-off off the thrown error (or the response's
29
+ // exhaustion headers) and refuses every later call without touching the vendor. So the honest claim
30
+ // is "bounds the 60s average, and converts the vendor's first 429 into a hard stop" — never
31
+ // "refuses before the vendor ever 429s". Pacing is the CALLER's job; this module REFUSES, it never
32
+ // sleeps (see the kernel header: it is deliberately not a scheduler). A tighter window would not
33
+ // close the gap, it would only turn every legitimate multi-page pull into a cascade of refusals.
34
+ //
35
+ // ── HOW THE WEIGHTS WERE CHOSEN (and what is a judgement call) ──────────────────────────────
36
+ // FLAT: every call costs 2. Both modeled endpoints are single fetch-by-id reads
37
+ // (`GET /runs/{runId}`, the event lookup), neither fans out, and Inngest publishes no per-endpoint
38
+ // rate. The one endpoint Inngest DOES annotate as rate limited ("fetch function run jobs", cached for
39
+ // 5 seconds, no number given) is not in this connector's surface — so there is nothing honest to
40
+ // price up. An unmodeled method reached through the guarded client is charged the same 2, never free.
41
+ import { declareRateBudget, rateBudgetPath, rateBudgetWeight, RateBudget, RateBudgetError, } from '@volter/world-core';
42
+ const VENDOR = 'inngest';
43
+ /** Rolling window, in ms. Spend older than this is pruned. */
44
+ export const INNGEST_BUDGET_WINDOW_MS = 60_000;
45
+ /** Weighted units allowed inside one window. See the header for where this number comes from. */
46
+ export const INNGEST_BUDGET_CEILING = 60;
47
+ /** Seconds. A `Retry-After` above this means the credential is throttled hard — fail loudly. */
48
+ export const INNGEST_BUDGET_MAX_RETRY_AFTER_S = 300;
49
+ /** Per-call cost, keyed by the client method the guard is about to invoke. See the header. */
50
+ export const INNGEST_CALL_WEIGHTS = {
51
+ /** Every modeled call. Inngest publishes no per-endpoint rate to differentiate. */
52
+ other: 2,
53
+ };
54
+ /**
55
+ * The client methods this pack PRICES BY NAME, as dotted paths into the injected client.
56
+ *
57
+ * Two kinds of entry: (a) every method this connector actually calls, and (b) an endpoint the
58
+ * VENDOR documents in a distinct tier which a consumer can reach through the guarded client even
59
+ * though this connector never calls it (see the weights section of the header). Used to build the
60
+ * guarded surface — and, in the pack's own suite, the counting fake.
61
+ *
62
+ * NOT a closed list, and not a claim about the injected client's shape. A path the real client does
63
+ * not have is SKIPPED (this connector's members are optional; inventing one would turn "observe
64
+ * nothing" into "call something that isn't there"), and a method absent from this list is still
65
+ * PRICED at `defaultWeight` when a caller reaches for it — an unmodeled endpoint must never be
66
+ * free, and dropping one would be worse than free because it would be invisible.
67
+ */
68
+ export const INNGEST_BUDGETED_METHODS = [
69
+ 'events.get',
70
+ 'runs.get',
71
+ ];
72
+ /** THE PACK'S DECLARATION — pure data, the only Inngest-specific thing in the whole budget. */
73
+ export const INNGEST_RATE_BUDGET = {
74
+ windowMs: INNGEST_BUDGET_WINDOW_MS,
75
+ ceiling: INNGEST_BUDGET_CEILING,
76
+ defaultWeight: INNGEST_CALL_WEIGHTS.other,
77
+ maxRetryAfterSeconds: INNGEST_BUDGET_MAX_RETRY_AFTER_S,
78
+ // Ordered: the kernel prices FIRST-MATCH-WINS, so the tightest tier is listed first.
79
+ rules: [],
80
+ reason: "Inngest documents NO rate limit, no 429 and no Retry-After for the REST endpoints this connector calls " +
81
+ "(/v1/events, /v1/runs); its published usage limits are payload-shape limits (5000 events/request, 10 MiB " +
82
+ "batches) rather than rates. The only rate-limit statement in its whole API reference annotates a different " +
83
+ "endpoint (\"fetch function run jobs … rate limited and cached for 5 seconds\") and gives no number. With no " +
84
+ "documented figure to aim at, this ceiling is pinned to the kernel's conservative fallback (60 units / 60s " +
85
+ "at weight 2 = 30 calls/min) rather than invented — no more permissive than an undeclared vendor already " +
86
+ "gets. Weights are flat because both modeled endpoints are single fetch-by-id reads and no per-endpoint " +
87
+ "rate is published.",
88
+ };
89
+ // Declared at module load, so merely importing this module (which `inngest-connector.ts` does) is
90
+ // enough to arm the real ceiling. A budget constructed BEFORE this runs falls back to the kernel's
91
+ // DEFAULT_RATE_BUDGET — which is tighter in call COUNT but prices every call at 2, so for a vendor
92
+ // with an expensive endpoint the fallback is CHEAPER there, not safer. `RateBudget` reads its policy
93
+ // LIVE precisely so this declaration takes effect the moment it lands, and constructing through the
94
+ // subclass below (whose module IS this one) makes the ordering a non-issue in practice.
95
+ declareRateBudget(VENDOR, INNGEST_RATE_BUDGET);
96
+ /** Price one Inngest call by its client method key (a dotted path, e.g. `events.get`). */
97
+ export function inngestCallWeight(method) {
98
+ return rateBudgetWeight(VENDOR, method);
99
+ }
100
+ /** Where Inngest's ledger lives. Token-keyed and cwd-independent by default (the vendor limits per
101
+ * credential, so a cwd-scoped ledger would hand the same credential a fresh allowance in every
102
+ * checkout, worktree and CI matrix leg); pass `root` to opt into world-scoped accounting. */
103
+ export function inngestBudgetPath(opts = {}) {
104
+ const o = typeof opts === 'string' ? { root: opts } : opts;
105
+ // VENDOR spread LAST: a loosely-typed `{ vendor: 'other', … }` slipping through (TypeScript's
106
+ // excess-property check only catches object literals) must not redirect this pack's ledger to
107
+ // another vendor's file.
108
+ return rateBudgetPath({ ...o, vendor: VENDOR });
109
+ }
110
+ /**
111
+ * Inngest's budget — the shared kernel guard bound to this vendor's declaration. A real subclass,
112
+ * not an alias, so `budget instanceof InngestBudget` means "a budget that accounts against this
113
+ * vendor's ledger under this vendor's ceiling": another vendor's `RateBudget` (with its own,
114
+ * possibly larger, ceiling) is NOT assignable where one of these is required.
115
+ */
116
+ export class InngestBudget extends RateBudget {
117
+ constructor(opts = {}) {
118
+ super({ ...opts, vendor: VENDOR });
119
+ }
120
+ }
121
+ export { RateBudgetError as InngestBudgetError } from '@volter/world-core';
122
+ /** Pull the budget wiring out of a caller's opts bag, so an entrypoint can forward it verbatim. */
123
+ export function inngestBudgetOf(opts) {
124
+ return {
125
+ ...(opts.budget !== undefined ? { budget: opts.budget } : {}),
126
+ ...(opts.budgetOptions !== undefined ? { budgetOptions: opts.budgetOptions } : {}),
127
+ };
128
+ }
129
+ // ── the choke point ─────────────────────────────────────────────────────────────────────────
130
+ /**
131
+ * Marks a client this module has already wrapped, so guarding twice cannot charge twice.
132
+ *
133
+ * A MODULE-PRIVATE `Symbol()`, deliberately not `Symbol.for()`: a global-registry symbol is
134
+ * reachable BY NAME, so any caller could stamp `client[Symbol.for(…)] = anything` on a RAW client and
135
+ * the guard would hand it straight back UNGUARDED — a one-line bypass of the whole budget. With a
136
+ * private symbol the only way to be branded is to have been wrapped by this function. The cost is
137
+ * that two copies of this module in one dependency tree would each wrap (double-charging a call);
138
+ * that is the SAFE direction, and over-charging is the tradeoff this module takes everywhere else.
139
+ */
140
+ const GUARDED = Symbol('@volter/twin-inngest.budget.guarded');
141
+ /** Is this client already behind a budget? Returns the budget it is behind, if so. */
142
+ export function inngestClientBudget(client) {
143
+ const mark = client?.[GUARDED];
144
+ // Belt and braces: only a REAL budget counts as "already guarded". A non-RateBudget value here
145
+ // could only come from a forged brand, and the answer to a forgery is to wrap anyway.
146
+ return mark instanceof RateBudget ? mark : undefined;
147
+ }
148
+ /**
149
+ * Wrap an INJECTED Inngest client so EVERY call it makes is charged against the shared budget
150
+ * BEFORE the request goes out. This pack's connector never constructs the transport itself (the
151
+ * consumer injects a client that satisfies `InngestLikeClient` structurally), so the guard is a
152
+ * DECORATOR rather than a factory — which is exactly why every connector entrypoint applies it
153
+ * UNCONDITIONALLY instead of trusting the caller to have done it.
154
+ *
155
+ * IDEMPOTENT: wrapping an already-guarded client returns it unchanged, so a caller who forgot is
156
+ * protected and a caller who wrapped deliberately is not double-charged.
157
+ *
158
+ * A method that THROWS is still inspected: an SDK typically RAISES on a 429 rather than returning
159
+ * it, and that error's back-off is exactly the signal that must become a persisted cooldown. Losing
160
+ * it would leave the ledger cheerfully spending into a throttled credential. The original error is
161
+ * always re-raised afterwards — the budget never swallows a vendor failure — EXCEPT when the
162
+ * back-off is beyond the cap, where the budget's own louder "stop calling" error takes precedence.
163
+ */
164
+ export function guardInngestClient(client, opts = {}) {
165
+ // There is no value a caller can pass to end up with an UNGUARDED client. `null`/`undefined` (or
166
+ // omitting it) build the default budget; anything that is not a REAL `InngestBudget` is refused
167
+ // loudly rather than trusted — a duck-typed stand-in with a no-op `checkBudget` would otherwise be
168
+ // the one clean way around the guard. Validated BEFORE the already-guarded early return, so
169
+ // `guardInngestClient(alreadyGuarded, { budget: impostor })` is refused too rather than silently
170
+ // ignoring the impostor.
171
+ if (opts.budget !== undefined && opts.budget !== null && !(opts.budget instanceof InngestBudget)) {
172
+ throw new Error('guardInngestClient: `budget` must be a InngestBudget — refusing to guard a Inngest client with an unverified rate guard');
173
+ }
174
+ if (inngestClientBudget(client))
175
+ return client;
176
+ const budget = opts.budget instanceof InngestBudget
177
+ ? opts.budget
178
+ : new InngestBudget({
179
+ // The default ledger is keyed by a hash of the credential — the vendor limits per credential,
180
+ // so a cwd-scoped ledger would hand it a fresh allowance per worktree/CI leg.
181
+ //
182
+ // HONESTLY: this pack does NOT hold the credential — the consumer's injected client does — so
183
+ // `INNGEST_SIGNING_KEY` is a BEST-EFFORT stand-in for it, not the real thing. If that env var names a
184
+ // different account than the injected client, spend is booked against the wrong ledger; if it
185
+ // is unset, every unattributed Inngest credential on the machine shares one (over-tight,
186
+ // which is the safe direction). A caller who knows the credential should say so:
187
+ // `budgetOptions: { token }` overrides this, and does so deliberately last in the spread.
188
+ ...(process.env.INNGEST_SIGNING_KEY !== undefined ? { token: process.env.INNGEST_SIGNING_KEY } : {}),
189
+ ...(opts.budgetOptions ?? {}),
190
+ });
191
+ /** Settle a reservation from whatever the call produced. May THROW (a back-off past the cap). */
192
+ const settle = (weight, reservation, v) => {
193
+ const status = responseStatus(v);
194
+ const headers = responseHeaders(v);
195
+ if (status !== undefined || headers !== undefined)
196
+ budget.recordCall(weight, headers, { status, reservation });
197
+ else
198
+ budget.recordCall(weight, undefined, { reservation });
199
+ };
200
+ /**
201
+ * Settle once the call RESOLVED: the vendor has answered. recordCall arms any cooldown before
202
+ * it throws (a back-off beyond the cap), so that refusal is swallowed and the answer kept — a
203
+ * write the vendor accepted is never reported failed and performed again on retry. A resolved
204
+ * answer that carries a non-2xx status still lets the louder refusal win.
205
+ */
206
+ const settleAnswered = (weight, reservation, v) => {
207
+ try {
208
+ settle(weight, reservation, v);
209
+ }
210
+ catch (e) {
211
+ const status = responseStatus(v);
212
+ if (!(e instanceof RateBudgetError) || (status !== undefined && (status < 200 || status >= 300)))
213
+ throw e;
214
+ }
215
+ };
216
+ /**
217
+ * Charge, call, settle — for a MODELED method, whose interface declares it `async`. Refusing
218
+ * REJECTS rather than throwing synchronously, so `client.x().catch(…)` behaves exactly as it does
219
+ * on an unguarded client. `checkBudget` RESERVES under lock, so nothing after its line runs when
220
+ * the budget refuses: the request is never made.
221
+ */
222
+ const chargeAsync = (method, invoke) => async (...args) => {
223
+ const weight = budget.weightFor(method);
224
+ const reservation = budget.checkBudget(weight);
225
+ try {
226
+ const res = await invoke(...args);
227
+ settleAnswered(weight, reservation, res);
228
+ return res;
229
+ }
230
+ catch (e) {
231
+ settle(weight, reservation, e); // may throw its own louder refusal, which wins
232
+ throw e;
233
+ }
234
+ };
235
+ /**
236
+ * Charge, call, settle — for an UNMODELED member reached through the passthrough Proxy, where the
237
+ * shape is unknown.
238
+ *
239
+ * Deliberately NOT `async`. Some vendor SDKs (twilio-shaped ones) build requests through
240
+ * SYNCHRONOUS chained accessors — `client.a.b('sid').c.create()` — where the intermediate calls
241
+ * return a resource context, not a promise. An `async` wrapper would turn every one of those into
242
+ * a `Promise` and `.c` would come back `undefined`: the guard would BREAK the client instead of
243
+ * guarding it. So a non-thenable return is treated as an accessor — still charged (we cannot know
244
+ * before calling, and over-charging is the safe direction) and wrapped, so the eventual async leaf
245
+ * is charged too rather than escaping the budget. The cost of the sync shape is that a REFUSAL on
246
+ * this path throws synchronously instead of rejecting; that is the honest signal for an accessor,
247
+ * and the modeled surface above (every method this connector actually calls) does not have it.
248
+ */
249
+ const charge = (method, invoke) => (...args) => {
250
+ const weight = budget.weightFor(method);
251
+ const reservation = budget.checkBudget(weight);
252
+ let out;
253
+ try {
254
+ out = invoke(...args);
255
+ }
256
+ catch (e) {
257
+ settle(weight, reservation, e); // may throw its own louder refusal, which wins
258
+ throw e;
259
+ }
260
+ if (!isThenable(out)) {
261
+ settle(weight, reservation, undefined);
262
+ return out !== null && (typeof out === 'object' || typeof out === 'function')
263
+ ? proxyThrough({}, out, method, charge)
264
+ : out;
265
+ }
266
+ return out.then((res) => { settleAnswered(weight, reservation, res); return res; }, (e) => { settle(weight, reservation, e); throw e; });
267
+ };
268
+ // Build the charged surface from INNGEST_BUDGETED_METHODS (see its docstring for why an absent path is
269
+ // SKIPPED rather than stubbed).
270
+ const guarded = {};
271
+ for (const path of INNGEST_BUDGETED_METHODS) {
272
+ const segs = path.split('.');
273
+ const leaf = segs[segs.length - 1];
274
+ let owner = client;
275
+ for (const seg of segs.slice(0, -1))
276
+ owner = owner?.[seg];
277
+ if (typeof owner?.[leaf] !== 'function')
278
+ continue;
279
+ const realOwner = owner;
280
+ let node = guarded;
281
+ for (const seg of segs.slice(0, -1))
282
+ node = (node[seg] ??= {});
283
+ // The method is resolved at CALL time, not here, so a client whose method is swapped later is
284
+ // still charged for whatever it actually runs.
285
+ node[leaf] = chargeAsync(path, (...args) => realOwner[leaf].apply(realOwner, args));
286
+ }
287
+ Object.defineProperty(guarded, GUARDED, { value: budget, enumerable: false });
288
+ // The surface above is what this connector calls. A real client has MORE — and a consumer who
289
+ // needs any of it must not be forced to keep the RAW client alongside, because every call through
290
+ // that would be unbudgeted. So the guarded object is a Proxy: known members come from the map
291
+ // above, anything else is taken from the real client and PRICED at `defaultWeight`.
292
+ return proxyThrough(guarded, client, '', charge);
293
+ }
294
+ /**
295
+ * Members JavaScript itself asks for. Wrapping any of these turns the object into something that
296
+ * looks thenable / mis-reports its own identity, which breaks `await`, `instanceof` and logging —
297
+ * so they always come from the target untouched, never priced.
298
+ */
299
+ const NEVER_WRAP = new Set(['then', 'catch', 'finally', 'constructor', 'prototype', 'toJSON', 'toString', 'valueOf', 'inspect']);
300
+ /** Does this look like a promise? (Only a thenable gets the settle-on-resolution treatment.) */
301
+ function isThenable(v) {
302
+ return v !== null && (typeof v === 'object' || typeof v === 'function') && typeof v.then === 'function';
303
+ }
304
+ /**
305
+ * Symbols that name an ITERATION PROTOCOL. Reaching for one of these on a vendor object is how a
306
+ * paginator is driven (`for await (const page of client.things.list())`), i.e. it is the doorway to
307
+ * an unbounded sequence of REQUESTS — exactly what this budget exists to bound — so they are charged
308
+ * and their result is kept behind the proxy. Every other symbol (`Symbol.toStringTag`,
309
+ * `nodejs.util.inspect.custom`, …) is metadata rather than a request and passes through untouched.
310
+ */
311
+ const ITERATOR_SYMBOLS = new Set([Symbol.asyncIterator, Symbol.iterator]);
312
+ /**
313
+ * Serve `known` where it has the member; otherwise price a passthrough to `real`. Applied
314
+ * recursively, so a namespace member this pack never modeled is charged at `defaultWeight` rather
315
+ * than coming back `undefined`.
316
+ *
317
+ * CALLABLE NAMESPACES (§9 finding): a member can be BOTH a function and a namespace — twilio's
318
+ * `client.messages` is called as `client.messages(sid)` to get one message's context AND read as
319
+ * `client.messages.list()`. An earlier version returned the modeled node as a plain object whenever
320
+ * this pack modeled any child of it, which silently DROPPED the call signature and every unmodeled
321
+ * sibling — the module's own docstring calls a dropped member "worse than free, because it is
322
+ * invisible", and that is what it was doing. So when `real` is callable the proxy target is a
323
+ * function and an `apply` trap charges the call, while `known` stays the source of modeled members.
324
+ */
325
+ function proxyThrough(known, real, prefix, charge, owner) {
326
+ const callable = typeof real === 'function';
327
+ // The target must itself be callable for the `apply` trap to exist at all. `known` stays the
328
+ // source of modeled members, read explicitly below rather than through the target.
329
+ const target = callable ? function proxied() { } : known;
330
+ return new Proxy(target, {
331
+ apply(_t, _thisArg, args) {
332
+ // Calling the namespace is itself a request-builder hop: charge it, and keep the result
333
+ // behind the proxy (charge() re-proxies a non-thenable) so the eventual leaf is charged too.
334
+ // `owner` is the object the function was read from — dropping it would silently break every
335
+ // method that relies on `this`.
336
+ return charge(prefix || 'call', (...a) => real.apply(owner, a))(...args);
337
+ },
338
+ get(_t, prop, receiver) {
339
+ if (typeof prop === 'symbol') {
340
+ const ownSym = Reflect.get(known, prop, receiver);
341
+ if (ownSym !== undefined)
342
+ return ownSym; // the GUARDED brand, and anything we model
343
+ const fromSym = real?.[prop];
344
+ if (ITERATOR_SYMBOLS.has(prop) && typeof fromSym === 'function') {
345
+ return charge(`${prefix}[${prop.description ?? 'iterator'}]`, (...args) => fromSym.apply(real, args));
346
+ }
347
+ return fromSym;
348
+ }
349
+ const name = String(prop);
350
+ if (NEVER_WRAP.has(name))
351
+ return Reflect.get(known, prop, receiver);
352
+ const key = prefix ? `${prefix}.${name}` : name;
353
+ const own = Reflect.get(known, prop, receiver);
354
+ const from = real?.[name];
355
+ // A member we model: the charged wrapper (a function) or a namespace we must keep descending
356
+ // into, so an unmodeled sibling is still priced rather than dropped.
357
+ if (typeof own === 'function')
358
+ return own;
359
+ if (own && typeof own === 'object') {
360
+ // `from` may be an object OR a CALLABLE namespace — both keep descending, which is what
361
+ // preserves `client.messages(sid)` alongside the modeled `client.messages.list()`.
362
+ return from && (typeof from === 'object' || typeof from === 'function')
363
+ ? proxyThrough(own, from, key, charge, real)
364
+ : own;
365
+ }
366
+ if (own !== undefined)
367
+ return own;
368
+ // A member only the real client has. Functions go through proxyThrough too, so one that also
369
+ // carries members (a callable namespace) keeps both its call signature and its siblings.
370
+ if (typeof from === 'function')
371
+ return proxyThrough({}, from, key, charge, real);
372
+ if (from && typeof from === 'object')
373
+ return proxyThrough({}, from, key, charge, real);
374
+ return from;
375
+ },
376
+ has(_t, prop) {
377
+ return Reflect.has(known, prop) || (real !== null && Reflect.has(real, prop));
378
+ },
379
+ });
380
+ }
381
+ /** The HTTP status a value carries, if it looks like one (an SDK error, or a raw response). */
382
+ function responseStatus(v) {
383
+ const s = v?.status;
384
+ return typeof s === 'number' && Number.isFinite(s) ? s : undefined;
385
+ }
386
+ /**
387
+ * Response/error headers as a plain lower-cased record, or `undefined` when there are none. Accepts
388
+ * a `Headers` instance, a `Map`, or a plain object — an SDK's error type changes shape across
389
+ * versions and none of the three is worth depending on.
390
+ */
391
+ function responseHeaders(v) {
392
+ const h = v?.headers;
393
+ if (!h || typeof h !== 'object')
394
+ return undefined;
395
+ const out = {};
396
+ if (typeof h.forEach === 'function') {
397
+ h.forEach((value, key) => { out[String(key).toLowerCase()] = String(value); });
398
+ }
399
+ else {
400
+ for (const [k, value] of Object.entries(h))
401
+ out[k.toLowerCase()] = String(value);
402
+ }
403
+ return Object.keys(out).length > 0 ? out : undefined;
404
+ }
@@ -0,0 +1,4 @@
1
+ import { type CapabilityReport, type CapabilitySpec } from '@volter/world-tooling';
2
+ export declare const INNGEST_CAPABILITIES: CapabilitySpec[];
3
+ export declare const INNGEST_AREAS: readonly ["events", "functions", "runs", "steps", "scheduling", "config", "exec_protocol", "auth", "pagination", "errors", "connector", "conformance", "safety", "state"];
4
+ export declare function inngestCapabilities(): Promise<CapabilityReport>;