logixia 1.13.0 → 2.0.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 +81 -16
- package/dist/{async-context-CwBNMm2E.mjs → async-context-BzJrbfQs.mjs} +8 -4
- package/dist/async-context-BzJrbfQs.mjs.map +1 -0
- package/dist/{async-context-CSHWoHMB.js → async-context-DyQQYq3I.js} +8 -4
- package/dist/async-context-DyQQYq3I.js.map +1 -0
- package/dist/{azure-monitor.transport-CG7ClkYj.d.ts → azure-monitor.transport-Cn_3Usvu.d.ts} +2 -2
- package/dist/{azure-monitor.transport-CG7ClkYj.d.ts.map → azure-monitor.transport-Cn_3Usvu.d.ts.map} +1 -1
- package/dist/{azure-monitor.transport-Cm74kXZS.d.mts → azure-monitor.transport-D7Da4RAb.d.mts} +2 -2
- package/dist/{azure-monitor.transport-Cm74kXZS.d.mts.map → azure-monitor.transport-D7Da4RAb.d.mts.map} +1 -1
- package/dist/azure.d.mts +2 -2
- package/dist/azure.d.ts +2 -2
- package/dist/browser.d.mts +9 -0
- package/dist/browser.d.mts.map +1 -1
- package/dist/browser.d.ts +9 -0
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +43 -12
- package/dist/browser.js.map +1 -1
- package/dist/browser.mjs +43 -12
- package/dist/browser.mjs.map +1 -1
- package/dist/{logitron-logger.module-Bs3XYZgF.mjs → builder-0gEzRopq.mjs} +383 -1021
- package/dist/builder-0gEzRopq.mjs.map +1 -0
- package/dist/{logitron-logger.module-BsDZR5BH.js → builder-D44QktIo.js} +411 -1155
- package/dist/builder-D44QktIo.js.map +1 -0
- package/dist/cli/index.js +130 -65
- package/dist/cloudwatch.d.mts +2 -2
- package/dist/cloudwatch.d.ts +2 -2
- package/dist/cloudwatch.js +2 -1
- package/dist/cloudwatch.mjs +2 -1
- package/dist/{cloudwatch.transport-pNBNWJLt.js → cloudwatch.transport-BO1ahxw-.js} +26 -19
- package/dist/cloudwatch.transport-BO1ahxw-.js.map +1 -0
- package/dist/{cloudwatch.transport-yBwm4OeO.mjs → cloudwatch.transport-DZ6ies7g.mjs} +26 -19
- package/dist/cloudwatch.transport-DZ6ies7g.mjs.map +1 -0
- package/dist/{cloudwatch.transport-CGHY4buE.d.mts → cloudwatch.transport-DsEq633o.d.ts} +9 -2
- package/dist/cloudwatch.transport-DsEq633o.d.ts.map +1 -0
- package/dist/{cloudwatch.transport-DK_8cKd3.d.ts → cloudwatch.transport-UlyZFWMn.d.mts} +9 -2
- package/dist/cloudwatch.transport-UlyZFWMn.d.mts.map +1 -0
- package/dist/{coerce.utils-BN980Y9V.js → coerce.utils-B-LilukN.js} +1 -1
- package/dist/{coerce.utils-BN980Y9V.js.map → coerce.utils-B-LilukN.js.map} +1 -1
- package/dist/{coerce.utils-Dxv4_ikC.mjs → coerce.utils-Cu6IUTgX.mjs} +1 -1
- package/dist/{coerce.utils-Dxv4_ikC.mjs.map → coerce.utils-Cu6IUTgX.mjs.map} +1 -1
- package/dist/correlation.d.mts +24 -6
- package/dist/correlation.d.mts.map +1 -1
- package/dist/correlation.d.ts +24 -6
- package/dist/correlation.d.ts.map +1 -1
- package/dist/correlation.js +41 -16
- package/dist/correlation.js.map +1 -1
- package/dist/correlation.mjs +41 -16
- package/dist/correlation.mjs.map +1 -1
- package/dist/entry-fields-BJkuPnIg.mjs +30 -0
- package/dist/entry-fields-BJkuPnIg.mjs.map +1 -0
- package/dist/entry-fields-BvOLFlJ4.js +36 -0
- package/dist/entry-fields-BvOLFlJ4.js.map +1 -0
- package/dist/gcp.d.mts +2 -2
- package/dist/gcp.d.ts +2 -2
- package/dist/gcp.js +2 -1
- package/dist/gcp.mjs +2 -1
- package/dist/{gcp.transport-BOhkVKlI.d.ts → gcp.transport-B7oc97sG.d.ts} +2 -2
- package/dist/gcp.transport-B7oc97sG.d.ts.map +1 -0
- package/dist/{gcp.transport-SHdtc1n0.js → gcp.transport-CHV8MGgz.js} +5 -5
- package/dist/gcp.transport-CHV8MGgz.js.map +1 -0
- package/dist/{gcp.transport-BJuNRFe_.mjs → gcp.transport-DBX5TPIy.mjs} +5 -5
- package/dist/gcp.transport-DBX5TPIy.mjs.map +1 -0
- package/dist/{gcp.transport-Bi6CUqZR.d.mts → gcp.transport-GrJurKo8.d.mts} +2 -2
- package/dist/gcp.transport-GrJurKo8.d.mts.map +1 -0
- package/dist/{index-BPKwwERo.d.mts → index-3mw5gaCw.d.mts} +2 -2
- package/dist/{index-BPKwwERo.d.mts.map → index-3mw5gaCw.d.mts.map} +1 -1
- package/dist/{index-C1X-TE5I.d.ts → index-DhIoploR.d.ts} +2 -2
- package/dist/{index-C1X-TE5I.d.ts.map → index-DhIoploR.d.ts.map} +1 -1
- package/dist/index.d.mts +99 -137
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +99 -137
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +146 -510
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +99 -431
- package/dist/index.mjs.map +1 -1
- package/dist/logitron-logger-BFDSO8Io.d.mts +257 -0
- package/dist/logitron-logger-BFDSO8Io.d.mts.map +1 -0
- package/dist/logitron-logger-UVeN-mQm.d.ts +257 -0
- package/dist/logitron-logger-UVeN-mQm.d.ts.map +1 -0
- package/dist/middleware.d.mts +11 -4
- package/dist/middleware.d.mts.map +1 -1
- package/dist/middleware.d.ts +11 -4
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +148 -24
- package/dist/middleware.js.map +1 -1
- package/dist/middleware.mjs +148 -24
- package/dist/middleware.mjs.map +1 -1
- package/dist/nest.d.mts +481 -6
- package/dist/nest.d.mts.map +1 -1
- package/dist/nest.d.ts +481 -6
- package/dist/nest.d.ts.map +1 -1
- package/dist/nest.js +884 -13
- package/dist/nest.js.map +1 -0
- package/dist/nest.mjs +863 -6
- package/dist/nest.mjs.map +1 -0
- package/dist/{search-CFQRISUv.mjs → search-BFbu_oVn.mjs} +35 -12
- package/dist/search-BFbu_oVn.mjs.map +1 -0
- package/dist/{search-njTI2hdo.js → search-C4V0OMEn.js} +35 -12
- package/dist/search-C4V0OMEn.js.map +1 -0
- package/dist/{search-DujhR94O.d.ts → search-CNh9uVwR.d.ts} +2 -3
- package/dist/search-CNh9uVwR.d.ts.map +1 -0
- package/dist/{search-CQOo-Iq6.d.mts → search-DXANsQ2n.d.mts} +2 -3
- package/dist/search-DXANsQ2n.d.mts.map +1 -0
- package/dist/search.d.mts +3 -3
- package/dist/search.d.ts +3 -3
- package/dist/search.js +2 -2
- package/dist/search.mjs +2 -2
- package/dist/slack.transport-BZzoXDPn.d.mts +112 -0
- package/dist/slack.transport-BZzoXDPn.d.mts.map +1 -0
- package/dist/slack.transport-BfJRouB2.js +654 -0
- package/dist/slack.transport-BfJRouB2.js.map +1 -0
- package/dist/slack.transport-Bzw7sucI.mjs +643 -0
- package/dist/slack.transport-Bzw7sucI.mjs.map +1 -0
- package/dist/slack.transport-CXjQYOes.d.ts +112 -0
- package/dist/slack.transport-CXjQYOes.d.ts.map +1 -0
- package/dist/testing.d.mts +2 -2
- package/dist/testing.d.ts +2 -2
- package/dist/trace.utils-CvXgaiQT.mjs +278 -0
- package/dist/trace.utils-CvXgaiQT.mjs.map +1 -0
- package/dist/trace.utils-DpBOLDtq.js +358 -0
- package/dist/trace.utils-DpBOLDtq.js.map +1 -0
- package/dist/{transport.manager-D6KL3t9V.mjs → transport.manager-BiuCAJd2.mjs} +526 -160
- package/dist/transport.manager-BiuCAJd2.mjs.map +1 -0
- package/dist/{transport.manager-BivyUTtU.js → transport.manager-CXbKKdVE.js} +537 -159
- package/dist/transport.manager-CXbKKdVE.js.map +1 -0
- package/dist/{transport.types-B5vcyv2k.d.mts → transport.types-BMnurPcc.d.mts} +23 -3
- package/dist/transport.types-BMnurPcc.d.mts.map +1 -0
- package/dist/{transport.types-BuY84TwO.d.ts → transport.types-CGoHpWQR.d.ts} +23 -3
- package/dist/transport.types-CGoHpWQR.d.ts.map +1 -0
- package/dist/transports.d.mts +50 -20
- package/dist/transports.d.mts.map +1 -1
- package/dist/transports.d.ts +50 -20
- package/dist/transports.d.ts.map +1 -1
- package/dist/transports.js +9 -5
- package/dist/transports.mjs +8 -6
- package/dist/worker-entry.js +307 -55
- package/dist/worker.d.mts +2 -2
- package/dist/worker.d.ts +2 -2
- package/dist/worker.js +1 -1
- package/dist/worker.mjs +1 -1
- package/dist/{worker.transport-CfH6z37Z.js → worker.transport-BdPxu3PN.js} +1 -1
- package/dist/{worker.transport-CfH6z37Z.js.map → worker.transport-BdPxu3PN.js.map} +1 -1
- package/dist/{worker.transport-mKXgNK0L.d.ts → worker.transport-CdzSZJmw.d.ts} +2 -2
- package/dist/{worker.transport-mKXgNK0L.d.ts.map → worker.transport-CdzSZJmw.d.ts.map} +1 -1
- package/dist/{worker.transport-BP8Q28Z2.d.mts → worker.transport-JvGPog3C.d.mts} +2 -2
- package/dist/{worker.transport-BP8Q28Z2.d.mts.map → worker.transport-JvGPog3C.d.mts.map} +1 -1
- package/dist/{worker.transport-BhMyvqQ2.mjs → worker.transport-lPxO2MVL.mjs} +1 -1
- package/dist/{worker.transport-BhMyvqQ2.mjs.map → worker.transport-lPxO2MVL.mjs.map} +1 -1
- package/package.json +27 -14
- package/dist/.tsbuildinfo +0 -1
- package/dist/async-context-CSHWoHMB.js.map +0 -1
- package/dist/async-context-CwBNMm2E.mjs.map +0 -1
- package/dist/cloudwatch.transport-CGHY4buE.d.mts.map +0 -1
- package/dist/cloudwatch.transport-DK_8cKd3.d.ts.map +0 -1
- package/dist/cloudwatch.transport-pNBNWJLt.js.map +0 -1
- package/dist/cloudwatch.transport-yBwm4OeO.mjs.map +0 -1
- package/dist/gcp.transport-BJuNRFe_.mjs.map +0 -1
- package/dist/gcp.transport-BOhkVKlI.d.ts.map +0 -1
- package/dist/gcp.transport-Bi6CUqZR.d.mts.map +0 -1
- package/dist/gcp.transport-SHdtc1n0.js.map +0 -1
- package/dist/logitron-logger.module-BdG1Jnpk.d.mts +0 -618
- package/dist/logitron-logger.module-BdG1Jnpk.d.mts.map +0 -1
- package/dist/logitron-logger.module-Bs3XYZgF.mjs.map +0 -1
- package/dist/logitron-logger.module-BsDZR5BH.js.map +0 -1
- package/dist/logitron-logger.module-CbXy2gfW.d.ts +0 -618
- package/dist/logitron-logger.module-CbXy2gfW.d.ts.map +0 -1
- package/dist/search-CFQRISUv.mjs.map +0 -1
- package/dist/search-CQOo-Iq6.d.mts.map +0 -1
- package/dist/search-DujhR94O.d.ts.map +0 -1
- package/dist/search-njTI2hdo.js.map +0 -1
- package/dist/transport.manager-BivyUTtU.js.map +0 -1
- package/dist/transport.manager-D6KL3t9V.mjs.map +0 -1
- package/dist/transport.types-B5vcyv2k.d.mts.map +0 -1
- package/dist/transport.types-BuY84TwO.d.ts.map +0 -1
- package/scripts/postinstall.js +0 -61
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slack.transport-Bzw7sucI.mjs","names":["LEVEL_RANK: Record<string, number>","url: URL","opts: WebhookQueueOptions<T>","rendered: T[]","body: string","retryAfterMs: number | undefined","DISCORD_LEVEL_COLORS: Record<string, number>","out: DiscordEmbed","payload: Record<string, unknown>","fields: DiscordEmbedField[]","embed: DiscordEmbed","LEVEL_EMOJI: Record<string, string>","payload: Record<string, unknown>","blocks: unknown[]"],"sources":["../src/transports/webhook-queue.ts","../src/transports/discord.transport.ts","../src/transports/slack.transport.ts"],"sourcesContent":["/**\n * Shared core for the chat-webhook transports (Slack, Discord).\n *\n * - entries inside `minIntervalMs` are batched into one message; entries past\n * `maxPerMessage` are dropped and reported to the payload builder as overflow\n * - the queue is bounded (BufferCap); the oldest entries go first\n * - HTTP 429 waits for Retry-After (bounded, cancelled by close()) and retries a\n * bounded number of times\n * - an entry that cannot be rendered is dropped alone; an unserializable batch or a\n * missing global fetch is dropped, never retried\n * - errors only ever name the webhook host, never the URL (the URL is a secret)\n */\n\nimport type { TransportLogEntry } from '../types/transport.types';\nimport { internalError, internalWarn } from '../utils/internal-log';\nimport { HttpError, isPermanentHttpError } from './batch-buffer';\nimport { BufferCap } from './buffer-cap';\n\nconst MAX_BACKOFF_MS = 30_000;\nconst DEFAULT_QUEUE_CAP = 1000;\nconst CLOSE_TIMEOUT_MS = 3000;\nconst OVERFLOW_WARN_MS = 5000;\nexport const DEFAULT_WEBHOOK_TIMEOUT_MS = 10_000;\nconst ZWSP = '';\n\nconst LEVEL_RANK: Record<string, number> = {\n fatal: 0,\n error: 1,\n warn: 2,\n warning: 2,\n info: 3,\n debug: 4,\n verbose: 5,\n trace: 6,\n};\n\nexport function resolveMinLevel(level: string | undefined, label: string): string {\n const resolved = (level ?? 'error').toLowerCase();\n if (!(resolved in LEVEL_RANK)) {\n throw new TypeError(`${label}: unknown level \"${String(level).slice(0, 40)}\"`);\n }\n return resolved;\n}\n\n/** Unknown (custom) entry levels pass, like the TransportManager does. */\nexport function meetsLevel(entryLevel: string, minLevel: string): boolean {\n const entryRank = LEVEL_RANK[entryLevel.toLowerCase()];\n return entryRank === undefined || entryRank <= (LEVEL_RANK[minLevel] ?? 1);\n}\n\nexport interface WebhookUrlRules {\n label: string;\n hostMatches: (host: string) => boolean;\n pathMatches: (path: string) => boolean;\n expected: string;\n allowCustomUrl: boolean | undefined;\n}\n\n/** Validates the secret URL. Error messages never contain it. */\nexport function parseWebhookUrl(raw: unknown, rules: WebhookUrlRules): URL {\n const { label, allowCustomUrl, hostMatches, pathMatches, expected } = rules;\n if (typeof raw !== 'string' || raw.length === 0) {\n throw new TypeError(`${label}: webhookUrl is required`);\n }\n let url: URL;\n try {\n url = new URL(raw);\n } catch {\n throw new TypeError(`${label}: webhookUrl is not a valid URL`);\n }\n if (url.protocol !== 'https:') {\n throw new TypeError(`${label}: webhookUrl must use https:`);\n }\n if (url.username || url.password) {\n throw new TypeError(`${label}: webhookUrl must not contain credentials`);\n }\n if (!allowCustomUrl) {\n const host = url.hostname.toLowerCase();\n if (!hostMatches(host) || !pathMatches(url.pathname) || url.port) {\n throw new TypeError(\n `${label}: webhookUrl must be a ${expected} webhook (set allowCustomUrl: true to use another https endpoint)`\n );\n }\n }\n return url;\n}\n\nexport interface WebhookResponseLike {\n ok: boolean;\n status: number;\n headers?: { get(name: string): string | null } | undefined;\n body?: { cancel(): Promise<void> } | null | undefined;\n json?: () => Promise<unknown>;\n}\n\ninterface PostResult {\n ok: boolean;\n status: number;\n retryAfterMs: number | undefined;\n}\n\nexport interface WebhookQueueOptions<T> {\n label: string;\n url: URL;\n minIntervalMs: number | undefined;\n maxPerMessage: number;\n maxQueueSize: number | undefined;\n maxRetries: number | undefined;\n requestTimeoutMs: number | undefined;\n /** Renders one entry. A throw (or unserializable result) drops only that entry. */\n render: (entry: TransportLogEntry) => T;\n /**\n * Builds the JSON request body from the rendered entries. `overflow` counts\n * entries beyond `maxPerMessage` that were dropped; the body must say so.\n */\n assemble: (rendered: T[], overflow: number) => unknown;\n /** Reads the wait (ms) from a 429 response. Defaults to the Retry-After header. */\n retryAfterMs?: (res: WebhookResponseLike) => Promise<number | undefined>;\n}\n\nexport function retryAfterHeaderMs(res: WebhookResponseLike): number | undefined {\n const raw = res.headers?.get('retry-after');\n if (raw === null || raw === undefined || raw === '') return undefined;\n const seconds = Number(raw);\n return Number.isFinite(seconds) && seconds >= 0 ? seconds * 1000 : undefined;\n}\n\nfunction nonNegative(value: number | undefined, fallback: number): number {\n return typeof value === 'number' && Number.isFinite(value) && value >= 0 ? value : fallback;\n}\n\nfunction failureCode(err: unknown): string {\n const cause = (err as { cause?: { code?: unknown } } | null)?.cause;\n const code = cause?.code ?? (err as { code?: unknown } | null)?.code;\n if (typeof code === 'string') return code.slice(0, 40);\n return err instanceof Error ? err.name : 'error';\n}\n\nfunction sleep(ms: number, signal: AbortSignal): Promise<void> {\n return new Promise<void>((resolve) => {\n if (signal.aborted) return resolve();\n const done = (): void => {\n clearTimeout(timer);\n signal.removeEventListener('abort', done);\n resolve();\n };\n const timer = setTimeout(done, ms);\n timer.unref?.();\n signal.addEventListener('abort', done, { once: true });\n });\n}\n\nasync function cancelBody(res: WebhookResponseLike): Promise<void> {\n try {\n await res.body?.cancel();\n } catch {\n // body already consumed or locked\n }\n}\n\n/**\n * Throttled queue for chat webhooks. It is not built on BatchBuffer because the\n * semantics differ: sends are spaced by `minIntervalMs` (leading edge, then one\n * message per window), a window sends one summarized message and drops the\n * overflow, 429 waits are cancellable by close(), and flush() surfaces send\n * errors. HttpError / isPermanentHttpError are shared with BatchBuffer.\n *\n * Entries past `maxPerMessage` in one window are not sent: the message carries a\n * \"… and N more\" line and an internal warning reports the count.\n */\nexport class WebhookQueue<T> {\n private items: TransportLogEntry[] = [];\n private readonly cap: BufferCap;\n private readonly host: string;\n private readonly httpLabel: string;\n private readonly minIntervalMs: number;\n private readonly maxRetries: number;\n private readonly timeoutMs: number;\n private timer: NodeJS.Timeout | null = null;\n private inFlight: Promise<void> | undefined;\n private nextAllowed = 0;\n private failures = 0;\n private closed = false;\n private readonly shutdown = new AbortController();\n private overflowPending = 0;\n private lastOverflowWarn = 0;\n private fetchWarned = false;\n\n constructor(private readonly opts: WebhookQueueOptions<T>) {\n this.host = opts.url.hostname;\n this.httpLabel = `${opts.label} (${this.host})`;\n this.minIntervalMs = nonNegative(opts.minIntervalMs, 1000);\n this.maxRetries = Math.floor(nonNegative(opts.maxRetries, 1));\n this.timeoutMs = nonNegative(opts.requestTimeoutMs, DEFAULT_WEBHOOK_TIMEOUT_MS);\n this.cap = new BufferCap(opts.label, opts.maxQueueSize, opts.maxPerMessage, DEFAULT_QUEUE_CAP);\n }\n\n get length(): number {\n return this.items.length;\n }\n\n push(entry: TransportLogEntry): void {\n if (this.closed) return;\n this.items.push(entry);\n this.cap.enforce(this.items);\n this.schedule();\n }\n\n flush(): Promise<void> {\n this.inFlight ??= this.drain().finally(() => {\n this.inFlight = undefined;\n });\n return this.inFlight;\n }\n\n /** Cancels rate-limit waits, then makes one best-effort send with a short timeout. */\n async close(): Promise<void> {\n this.closed = true;\n this.clearTimer();\n this.shutdown.abort();\n try {\n await this.inFlight;\n } catch {\n // already reported by the timer path\n }\n try {\n await this.flush();\n } catch (err) {\n internalError(`${this.opts.label} flush on close failed`, err);\n }\n this.reportOverflow(true);\n if (this.items.length > 0) {\n internalError(`${this.opts.label} closing with ${this.items.length} undelivered entries`);\n this.items = [];\n }\n }\n\n private clearTimer(): void {\n if (this.timer) clearTimeout(this.timer);\n this.timer = null;\n }\n\n private schedule(): void {\n if (this.timer || this.closed || this.items.length === 0) return;\n const delay = Math.max(0, this.nextAllowed - Date.now());\n this.timer = setTimeout(() => {\n this.timer = null;\n this.flush().catch((err) => internalError(`${this.opts.label} send failed`, err));\n }, delay);\n this.timer.unref?.();\n }\n\n private reportOverflow(force = false): void {\n const now = Date.now();\n if (this.overflowPending === 0 || (!force && now - this.lastOverflowWarn < OVERFLOW_WARN_MS)) {\n return;\n }\n const n = this.overflowPending;\n internalWarn(\n `${this.opts.label}: ${n} entr${n === 1 ? 'y' : 'ies'} over the per-message limit (${this.opts.maxPerMessage}) summarized in a \"... and N more\" line and not sent`\n );\n this.overflowPending = 0;\n this.lastOverflowWarn = now;\n }\n\n private render(batch: TransportLogEntry[]): T[] {\n const rendered: T[] = [];\n let bad = 0;\n for (const entry of batch) {\n try {\n const value = this.opts.render(entry);\n JSON.stringify(value);\n rendered.push(value);\n } catch (err) {\n bad += 1;\n if (bad === 1) {\n internalError(`${this.opts.label}: dropping an entry that cannot be rendered`, err);\n }\n }\n }\n if (bad > 1) {\n internalError(`${this.opts.label}: dropped ${bad} entries that cannot be rendered`);\n }\n return rendered;\n }\n\n private async drain(): Promise<void> {\n if (this.items.length === 0) return;\n if (typeof fetch !== 'function') {\n if (!this.fetchWarned) {\n this.fetchWarned = true;\n internalWarn(\n `${this.opts.label}: global fetch is unavailable (Node 18+ required); dropping entries`\n );\n }\n this.items = [];\n return;\n }\n const all = this.items;\n this.items = [];\n const batch = all.slice(0, this.opts.maxPerMessage);\n const overflow = all.length - batch.length;\n if (overflow > 0) {\n this.overflowPending += overflow;\n this.reportOverflow();\n }\n this.nextAllowed = Date.now() + this.minIntervalMs;\n try {\n const rendered = this.render(batch);\n if (rendered.length === 0 && overflow === 0) return;\n let body: string;\n try {\n body = JSON.stringify(this.opts.assemble(rendered, overflow));\n } catch (err) {\n internalError(`${this.opts.label}: dropping a batch that cannot be serialized`, err);\n return;\n }\n try {\n await this.sendWithRetry(body);\n this.failures = 0;\n } catch (err) {\n if (!isPermanentHttpError(err)) {\n this.items.unshift(...batch);\n this.cap.enforce(this.items);\n this.failures += 1;\n const backoff = Math.min(\n MAX_BACKOFF_MS,\n Math.max(1000, this.minIntervalMs) * 2 ** this.failures\n );\n this.nextAllowed = Math.max(this.nextAllowed, Date.now() + backoff);\n }\n throw err;\n }\n } finally {\n this.schedule();\n }\n }\n\n private async sendWithRetry(body: string): Promise<void> {\n for (let attempt = 0; ; attempt += 1) {\n const res = await this.post(body);\n if (res.ok) return;\n if (res.status !== 429) throw new HttpError(res.status, '', this.httpLabel);\n const waitMs = Math.min(\n MAX_BACKOFF_MS,\n Math.max(0, res.retryAfterMs ?? Math.max(1000, this.minIntervalMs))\n );\n this.nextAllowed = Math.max(this.nextAllowed, Date.now() + waitMs);\n if (attempt >= this.maxRetries || this.closed) {\n throw new HttpError(429, '', this.httpLabel);\n }\n await sleep(waitMs, this.shutdown.signal);\n if (this.shutdown.signal.aborted) {\n throw new Error(`${this.opts.label}: rate-limit wait cancelled by close()`);\n }\n }\n }\n\n private async readRetryAfter(res: WebhookResponseLike): Promise<number | undefined> {\n try {\n return this.opts.retryAfterMs ? await this.opts.retryAfterMs(res) : retryAfterHeaderMs(res);\n } catch {\n return undefined;\n }\n }\n\n private async post(body: string): Promise<PostResult> {\n const controller = new AbortController();\n const timeoutMs = this.closed ? Math.min(this.timeoutMs, CLOSE_TIMEOUT_MS) : this.timeoutMs;\n const timer = setTimeout(() => controller.abort(), timeoutMs);\n try {\n const res = (await fetch(this.opts.url, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body,\n redirect: 'error',\n signal: controller.signal,\n })) as WebhookResponseLike;\n let retryAfterMs: number | undefined;\n try {\n if (res.status === 429) retryAfterMs = await this.readRetryAfter(res);\n } finally {\n await cancelBody(res);\n }\n return { ok: res.ok, status: res.status, retryAfterMs };\n } catch (err) {\n // fetch errors may echo the request URL; keep only the host and a short code (no cause)\n // eslint-disable-next-line preserve-caught-error -- the cause can contain the secret URL\n throw new Error(\n `${this.opts.label}: request to ${this.host} failed (${controller.signal.aborted ? 'timeout' : failureCode(err)})`\n );\n } finally {\n clearTimeout(timer);\n }\n }\n}\n\n/** Cuts `text` to `max` chars without splitting a surrogate pair or a `&`-style entity. */\nexport function truncateText(text: string, max: number, ellipsis = '…'): string {\n if (text.length <= max) return text;\n let cut = text.slice(0, Math.max(0, max - ellipsis.length));\n cut = cut.replace(/&[a-z]{0,3}$/, '');\n if (/[\\uD800-\\uDBFF]$/.test(cut)) cut = cut.slice(0, -1);\n return cut + ellipsis;\n}\n\n/** Breaks code-fence and broadcast-mention sequences with a zero-width space. */\nexport function defuseText(text: string): string {\n return text\n .replace(/`{3,}/g, (m) => m.split('').join(ZWSP))\n .replace(/@(everyone|here|channel)/gi, `@${ZWSP}$1`);\n}\n\n/** Collapses control characters and newlines for single-line fields. */\nexport function singleLine(text: string): string {\n // eslint-disable-next-line no-control-regex\n return text.replace(/[\\u0000-\\u001f\\u007f]+/g, ' ').trim();\n}\n\n/** ISO string, or undefined for a missing or invalid timestamp. */\nexport function safeIso(date: unknown): string | undefined {\n return date instanceof Date && !Number.isNaN(date.getTime()) ? date.toISOString() : undefined;\n}\n","/**\n * Discord webhook transport.\n *\n * Sends error-level (by default) entries to a Discord channel as embeds.\n * Entries inside `minIntervalMs` are batched into one request (max 10 embeds;\n * the overflow is dropped and counted in the message `content`). Every request\n * carries `allowed_mentions: { parse: [] }` so logged data can never ping\n * @everyone, roles or users, and logged text has its markdown escaped.\n *\n * Limits follow https://discord.com/developers/docs/resources/message#embed-object-embed-limits\n *\n * The webhook URL is a secret: it is never logged and never appears in errors.\n *\n * @example\n * transports: { custom: [ new DiscordTransport({ webhookUrl: process.env.DISCORD_WEBHOOK_URL! }) ] }\n */\n\nimport type { IAsyncTransport, TransportLogEntry } from '../types/transport.types';\nimport { internalWarn } from '../utils/internal-log';\nimport { stringifyForLog } from '../utils/safe-stringify';\nimport {\n DEFAULT_WEBHOOK_TIMEOUT_MS,\n defuseText,\n meetsLevel,\n parseWebhookUrl,\n resolveMinLevel,\n retryAfterHeaderMs,\n safeIso,\n singleLine,\n truncateText,\n WebhookQueue,\n type WebhookResponseLike,\n} from './webhook-queue';\n\nexport const DISCORD_TITLE_MAX = 256;\nexport const DISCORD_DESCRIPTION_MAX = 4096;\nexport const DISCORD_FIELD_VALUE_MAX = 1024;\nexport const DISCORD_EMBEDS_MAX = 10;\nexport const DISCORD_FIELDS_MAX = 25;\nexport const DISCORD_EMBED_TOTAL_MAX = 6000;\nexport const DISCORD_CONTENT_MAX = 2000;\nconst FIELD_VALUE_CAP = 64;\nconst DISCORD_FOOTER_MAX = 2048;\nconst FENCE_OVERHEAD = '```json\\n\\n```'.length;\nconst MIN_USEFUL_BODY = 20;\n\nexport interface DiscordEmbedField {\n name: string;\n value: string;\n inline?: boolean;\n}\n\nexport interface DiscordEmbed {\n title?: string;\n description?: string;\n color?: number;\n timestamp?: string;\n fields?: DiscordEmbedField[];\n [key: string]: unknown;\n}\n\nexport interface DiscordTransportConfig {\n /** Webhook URL (secret). Must be https on discord.com / discordapp.com unless `allowCustomUrl`. */\n webhookUrl: string;\n /** Minimum level to send. Default: 'error'. */\n level?: string;\n username?: string;\n /** https URL of the avatar shown for the webhook. */\n avatarUrl?: string;\n /** Entries within this window are batched into one request. Default: 1000. */\n minIntervalMs?: number;\n /**\n * Overrides the embed built for each entry. Limits are still enforced, but\n * escaping the content is the formatter's responsibility.\n */\n formatter?: (entry: TransportLogEntry) => DiscordEmbed;\n filter?: (entry: TransportLogEntry) => boolean;\n /** Accept an https webhook URL on any host (e.g. a proxy or Discord-compatible service). */\n allowCustomUrl?: boolean;\n /** Retries after an HTTP 429 (waits retry_after, max 30s). Default: 1. */\n maxRetries?: number;\n /** Max queued entries; the oldest are dropped past this. Default: 1000. */\n maxBufferSize?: number;\n requestTimeoutMs?: number;\n}\n\nexport const DISCORD_LEVEL_COLORS: Record<string, number> = {\n fatal: 0x992d22,\n error: 0xed4245,\n warn: 0xfee75c,\n warning: 0xfee75c,\n info: 0x3498db,\n debug: 0x95a5a6,\n verbose: 0x95a5a6,\n trace: 0x95a5a6,\n};\nconst DEFAULT_COLOR = 0x95a5a6;\n\n/** Escapes Discord markdown and defuses @everyone / @here and code fences. */\nexport function escapeDiscord(text: string): string {\n return defuseText(text.replace(/[\\\\*_~`|>#[\\]()]/g, '\\\\$&'));\n}\n\nfunction textLength(value: unknown, key: string): number {\n const text = (value as Record<string, unknown> | undefined)?.[key];\n return typeof text === 'string' ? text.length : 0;\n}\n\n/** Counts every text field Discord counts toward the 6000-character limit. */\nfunction embedChars(embed: DiscordEmbed): number {\n return (\n (embed.title?.length ?? 0) +\n (embed.description?.length ?? 0) +\n (embed.fields ?? []).reduce((n, f) => n + f.name.length + f.value.length, 0) +\n textLength(embed['footer'], 'text') +\n textLength(embed['author'], 'name')\n );\n}\n\n/** Shrinks one embed to `limit` chars: description first, then fields, footer/author, title. */\nfunction shrinkToFit(embed: DiscordEmbed, limit: number): void {\n const excess = () => embedChars(embed) - limit;\n if (excess() > 0 && embed.description) {\n const keep = embed.description.length - excess();\n if (keep > 0) embed.description = truncateText(embed.description, keep);\n else delete embed.description;\n }\n while (excess() > 0 && embed.fields?.length) embed.fields.pop();\n if (excess() > 0) {\n delete embed['footer'];\n delete embed['author'];\n }\n if (excess() > 0 && embed.title) {\n embed.title = truncateText(embed.title, Math.max(1, embed.title.length - excess()));\n }\n}\n\nfunction codeBlock(json: string, max: number): string {\n return `\\`\\`\\`json\\n${truncateText(\n json.replace(/`{3,}/g, (m) => m.split('').join('')),\n max\n )}\\n\\`\\`\\``;\n}\n\nfunction clampCustomEmbed(embed: DiscordEmbed): DiscordEmbed {\n const out: DiscordEmbed = { ...embed };\n if (typeof out.title === 'string') out.title = truncateText(out.title, DISCORD_TITLE_MAX);\n if (typeof out.description === 'string') {\n out.description = truncateText(out.description, DISCORD_DESCRIPTION_MAX);\n }\n if (Array.isArray(out.fields)) {\n out.fields = out.fields.slice(0, DISCORD_FIELDS_MAX).map((f) => ({\n ...f,\n name: truncateText(String(f.name), DISCORD_TITLE_MAX),\n value: truncateText(String(f.value), DISCORD_FIELD_VALUE_MAX),\n }));\n }\n const footer = out['footer'] as { text?: unknown } | undefined;\n if (footer && typeof footer.text === 'string') {\n out['footer'] = { ...footer, text: truncateText(footer.text, DISCORD_FOOTER_MAX) };\n }\n const author = out['author'] as { name?: unknown } | undefined;\n if (author && typeof author.name === 'string') {\n out['author'] = { ...author, name: truncateText(author.name, DISCORD_TITLE_MAX) };\n }\n return out;\n}\n\ninterface EmbedDraft {\n embed: DiscordEmbed;\n json: string | undefined;\n}\n\nexport class DiscordTransport implements IAsyncTransport {\n public readonly name = 'discord';\n public readonly level: string;\n public filter?: (entry: TransportLogEntry) => boolean;\n\n private readonly queue!: WebhookQueue<EmbedDraft>;\n private readonly username: string | undefined;\n private readonly avatarUrl: string | undefined;\n private readonly formatter: ((entry: TransportLogEntry) => DiscordEmbed) | undefined;\n\n constructor(config: DiscordTransportConfig) {\n const url = parseWebhookUrl(config.webhookUrl, {\n label: 'DiscordTransport',\n hostMatches: (h) =>\n ['discord.com', 'discordapp.com', 'ptb.discord.com', 'canary.discord.com'].includes(h),\n pathMatches: (p) => /^\\/api(\\/v\\d+)?\\/webhooks\\//.test(p),\n expected: 'discord.com',\n allowCustomUrl: config.allowCustomUrl,\n });\n if (config.avatarUrl !== undefined && !/^https:\\/\\//i.test(config.avatarUrl)) {\n throw new TypeError('DiscordTransport: avatarUrl must use https:');\n }\n this.level = resolveMinLevel(config.level, 'DiscordTransport');\n if (config.filter) this.filter = config.filter;\n this.username = config.username;\n this.avatarUrl = config.avatarUrl;\n this.formatter = config.formatter;\n const queue = new WebhookQueue<EmbedDraft>({\n label: 'DiscordTransport',\n url,\n minIntervalMs: config.minIntervalMs,\n maxPerMessage: DISCORD_EMBEDS_MAX,\n maxQueueSize: config.maxBufferSize,\n maxRetries: config.maxRetries,\n requestTimeoutMs: config.requestTimeoutMs ?? DEFAULT_WEBHOOK_TIMEOUT_MS,\n render: (entry) => this.draftFor(entry),\n assemble: (drafts, overflow) => this.buildPayload(drafts, overflow),\n retryAfterMs: readRetryAfter,\n });\n // non-enumerable so util.inspect / spreads of the transport never reach the secret URL\n Object.defineProperty(this, 'queue', { value: queue, enumerable: false });\n }\n\n write(entry: TransportLogEntry): void {\n if (!meetsLevel(entry.level, this.level)) return;\n // `filter` is applied by the TransportManager; it is not run again here\n this.queue.push(entry);\n }\n\n flush(): Promise<void> {\n return this.queue.flush();\n }\n\n close(): Promise<void> {\n return this.queue.close();\n }\n\n /** Never serialise the webhook URL (JSON.stringify, util.inspect). */\n toJSON(): Record<string, unknown> {\n return { name: this.name, level: this.level };\n }\n\n private buildPayload(drafts: EmbedDraft[], overflow: number): Record<string, unknown> {\n const kept = this.fitToBudget(drafts);\n const dropped = overflow + (drafts.length - kept.length);\n\n const payload: Record<string, unknown> = {\n embeds: kept.map((d) => d.embed),\n allowed_mentions: { parse: [] },\n };\n if (dropped > 0) {\n payload['content'] = truncateText(\n `… and ${dropped} more entr${dropped === 1 ? 'y' : 'ies'} not shown`,\n DISCORD_CONTENT_MAX\n );\n }\n if (this.username) payload['username'] = truncateText(this.username, 80);\n if (this.avatarUrl) payload['avatar_url'] = this.avatarUrl;\n return payload;\n }\n\n /** Enforces the 6000-char total: drops trailing embeds if needed, then shares the rest among descriptions. */\n private fitToBudget(drafts: EmbedDraft[]): EmbedDraft[] {\n const kept = [...drafts];\n const base = () => kept.reduce((n, d) => n + embedChars(d.embed), 0);\n while (kept.length > 1 && base() > DISCORD_EMBED_TOTAL_MAX) kept.pop();\n const only = kept[0];\n if (only && base() > DISCORD_EMBED_TOTAL_MAX) shrinkToFit(only.embed, DISCORD_EMBED_TOTAL_MAX);\n const withData = kept.filter((d) => d.json !== undefined);\n if (withData.length === 0) return kept;\n const share = Math.floor((DISCORD_EMBED_TOTAL_MAX - base()) / withData.length);\n const body = Math.min(DISCORD_DESCRIPTION_MAX, share) - FENCE_OVERHEAD;\n for (const d of withData) {\n if (body >= MIN_USEFUL_BODY) d.embed.description = codeBlock(d.json!, body);\n }\n return kept;\n }\n\n private draftFor(entry: TransportLogEntry): EmbedDraft {\n if (this.formatter) {\n try {\n return { embed: clampCustomEmbed(this.formatter(entry)), json: undefined };\n } catch {\n internalWarn('DiscordTransport: formatter threw; using the default embed');\n }\n }\n return defaultDraft(entry);\n }\n}\n\nfunction defaultDraft(entry: TransportLogEntry): EmbedDraft {\n const title = `[${singleLine(entry.level).toUpperCase()}] ${escapeDiscord(singleLine(entry.message))}`;\n const candidates: Array<[string, string | undefined]> = [\n ['appName', entry.appName],\n ['environment', entry.environment],\n ['context', entry.context],\n ['traceId', entry.traceId],\n ];\n const fields: DiscordEmbedField[] = candidates\n .map(([name, value]) => [name, typeof value === 'string' ? singleLine(value) : ''] as const)\n .filter(([, value]) => value !== '')\n .map(([name, value]) => ({\n name,\n value: truncateText(escapeDiscord(value), FIELD_VALUE_CAP),\n inline: true,\n }));\n const embed: DiscordEmbed = {\n title: truncateText(title, DISCORD_TITLE_MAX),\n color: DISCORD_LEVEL_COLORS[entry.level.toLowerCase()] ?? DEFAULT_COLOR,\n fields,\n };\n const timestamp = safeIso(entry.timestamp);\n if (timestamp) embed.timestamp = timestamp;\n const json =\n entry.data && Object.keys(entry.data).length > 0 ? stringifyForLog(entry.data) : undefined;\n return { embed, json };\n}\n\nasync function readRetryAfter(res: WebhookResponseLike): Promise<number | undefined> {\n try {\n const body = (await res.json?.()) as { retry_after?: unknown } | undefined;\n const seconds = Number(body?.retry_after);\n if (body?.retry_after !== undefined && Number.isFinite(seconds) && seconds >= 0) {\n return seconds * 1000;\n }\n } catch {\n // fall through to the header\n }\n return retryAfterHeaderMs(res);\n}\n","/**\n * Slack incoming-webhook transport.\n *\n * Sends error-level (by default) entries to a Slack channel as Block Kit\n * messages. Entries inside `minIntervalMs` are batched into one message so a\n * log storm cannot flood the channel. All logged text is escaped for Slack\n * mrkdwn (`&`, `<`, `>`), which also disarms `<!channel>`, `<!here>` and\n * `<@U123>` mentions coming from logged data.\n *\n * The webhook URL is a secret: it is never logged and never appears in errors.\n *\n * @example\n * transports: { custom: [ new SlackTransport({ webhookUrl: process.env.SLACK_WEBHOOK_URL! }) ] }\n */\n\nimport type { IAsyncTransport, TransportLogEntry } from '../types/transport.types';\nimport { internalWarn } from '../utils/internal-log';\nimport { stringifyForLog } from '../utils/safe-stringify';\nimport {\n DEFAULT_WEBHOOK_TIMEOUT_MS,\n defuseText,\n meetsLevel,\n parseWebhookUrl,\n resolveMinLevel,\n safeIso,\n singleLine,\n truncateText,\n WebhookQueue,\n} from './webhook-queue';\n\nexport const SLACK_HEADER_MAX = 150;\nexport const SLACK_DATA_MAX = 2500;\nconst SLACK_FIELD_MAX = 300;\nconst SLACK_TEXT_MAX = 1000;\nconst SLACK_MAX_BLOCKS = 50;\nconst SLACK_MAX_PER_MESSAGE = 10;\n\n/** A Slack message body as returned by a custom `formatter`. */\nexport interface SlackMessage {\n text?: string;\n blocks?: unknown[];\n [key: string]: unknown;\n}\n\nexport interface SlackTransportConfig {\n /** Incoming-webhook URL (secret). Must be https on hooks.slack.com unless `allowCustomUrl`. */\n webhookUrl: string;\n /** Minimum level to send. Default: 'error'. */\n level?: string;\n username?: string;\n iconEmoji?: string;\n /** Entries within this window are batched into one message. Default: 1000. */\n minIntervalMs?: number;\n /**\n * Overrides the message built for each entry. The results of one window are\n * merged: texts are joined and blocks concatenated (capped at 50 blocks).\n * Escaping the content is the formatter's responsibility.\n */\n formatter?: (entry: TransportLogEntry) => SlackMessage;\n filter?: (entry: TransportLogEntry) => boolean;\n /** Accept an https webhook URL on any host (e.g. a proxy or Slack-compatible service). */\n allowCustomUrl?: boolean;\n /** Retries after an HTTP 429 (waits Retry-After, max 30s). Default: 1. */\n maxRetries?: number;\n /** Max queued entries; the oldest are dropped past this. Default: 1000. */\n maxBufferSize?: number;\n requestTimeoutMs?: number;\n}\n\n/** Escapes the three characters Slack treats specially and defuses broadcast mentions. */\nexport function escapeSlack(text: string): string {\n return defuseText(text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>'));\n}\n\nconst LEVEL_EMOJI: Record<string, string> = {\n fatal: ':rotating_light:',\n error: ':red_circle:',\n warn: ':warning:',\n warning: ':warning:',\n info: ':information_source:',\n};\n\nexport class SlackTransport implements IAsyncTransport {\n public readonly name = 'slack';\n public readonly level: string;\n public filter?: (entry: TransportLogEntry) => boolean;\n\n private readonly queue!: WebhookQueue<SlackMessage>;\n private readonly username: string | undefined;\n private readonly iconEmoji: string | undefined;\n private readonly formatter: ((entry: TransportLogEntry) => SlackMessage) | undefined;\n\n constructor(config: SlackTransportConfig) {\n const url = parseWebhookUrl(config.webhookUrl, {\n label: 'SlackTransport',\n hostMatches: (h) => h === 'hooks.slack.com' || h === 'hooks.slack-gov.com',\n pathMatches: (p) => p.startsWith('/services/') || p.startsWith('/triggers/'),\n expected: 'hooks.slack.com',\n allowCustomUrl: config.allowCustomUrl,\n });\n this.level = resolveMinLevel(config.level, 'SlackTransport');\n if (config.filter) this.filter = config.filter;\n this.username = config.username;\n this.iconEmoji = config.iconEmoji;\n this.formatter = config.formatter;\n const queue = new WebhookQueue<SlackMessage>({\n label: 'SlackTransport',\n url,\n minIntervalMs: config.minIntervalMs,\n maxPerMessage: SLACK_MAX_PER_MESSAGE,\n maxQueueSize: config.maxBufferSize,\n maxRetries: config.maxRetries,\n requestTimeoutMs: config.requestTimeoutMs ?? DEFAULT_WEBHOOK_TIMEOUT_MS,\n render: (entry) => this.messageFor(entry),\n assemble: (messages, overflow) => this.buildPayload(messages, overflow),\n });\n // non-enumerable so util.inspect / spreads of the transport never reach the secret URL\n Object.defineProperty(this, 'queue', { value: queue, enumerable: false });\n }\n\n write(entry: TransportLogEntry): void {\n if (!meetsLevel(entry.level, this.level)) return;\n // `filter` is applied by the TransportManager; it is not run again here\n this.queue.push(entry);\n }\n\n flush(): Promise<void> {\n return this.queue.flush();\n }\n\n close(): Promise<void> {\n return this.queue.close();\n }\n\n /** Never serialise the webhook URL (JSON.stringify, util.inspect). */\n toJSON(): Record<string, unknown> {\n return { name: this.name, level: this.level };\n }\n\n private buildPayload(messages: SlackMessage[], overflow: number): Record<string, unknown> {\n const blocks = messages.flatMap((m) => m.blocks ?? []);\n const plural = overflow === 1 ? 'y' : 'ies';\n const counter = overflow > 0 ? `… and ${overflow} more entr${plural} not shown` : '';\n if (counter) {\n blocks.push({ type: 'context', elements: [{ type: 'mrkdwn', text: counter }] });\n }\n const text = [...messages.map((m) => m.text ?? ''), counter].filter(Boolean).join('\\n');\n const payload: Record<string, unknown> = {\n text: truncateText(text, SLACK_TEXT_MAX),\n blocks: blocks.slice(0, SLACK_MAX_BLOCKS),\n };\n if (this.username) payload['username'] = truncateText(this.username, 80);\n if (this.iconEmoji) payload['icon_emoji'] = this.iconEmoji;\n return payload;\n }\n\n private messageFor(entry: TransportLogEntry): SlackMessage {\n if (this.formatter) {\n try {\n return this.formatter(entry);\n } catch {\n internalWarn('SlackTransport: formatter threw; using the default message');\n }\n }\n return defaultMessage(entry);\n }\n}\n\nfunction defaultMessage(entry: TransportLogEntry): SlackMessage {\n const level = singleLine(entry.level).toUpperCase();\n const emoji = LEVEL_EMOJI[entry.level.toLowerCase()] ?? ':white_circle:';\n const headline = `[${level}] ${singleLine(entry.message)}`;\n const blocks: unknown[] = [\n {\n type: 'header',\n text: {\n type: 'plain_text',\n text: truncateText(escapeSlack(headline), SLACK_HEADER_MAX),\n emoji: false,\n },\n },\n ];\n\n const context = [\n ['app', entry.appName],\n ['env', entry.environment],\n ['context', entry.context],\n ['trace', entry.traceId],\n ['time', safeIso(entry.timestamp)],\n ]\n .map(([label, value]) => [label, typeof value === 'string' ? singleLine(value) : ''] as const)\n .filter(([, value]) => value !== '')\n .map(([label, value]) => ({\n type: 'mrkdwn',\n text: `*${label}:* ${truncateText(escapeSlack(value), SLACK_FIELD_MAX)}`,\n }));\n if (context.length > 0) blocks.push({ type: 'context', elements: context });\n\n if (entry.data && Object.keys(entry.data).length > 0) {\n const json = truncateText(escapeSlack(stringifyForLog(entry.data)), SLACK_DATA_MAX);\n blocks.push({ type: 'section', text: { type: 'mrkdwn', text: `\\`\\`\\`${json}\\`\\`\\`` } });\n }\n\n return {\n text: `${emoji} ${escapeSlack(truncateText(headline, SLACK_HEADER_MAX))}`,\n blocks,\n };\n}\n"],"mappings":";;;;;;AAkBA,MAAM,iBAAiB;AACvB,MAAM,oBAAoB;AAC1B,MAAM,mBAAmB;AACzB,MAAM,mBAAmB;AACzB,MAAa,6BAA6B;AAC1C,MAAM,OAAO;AAEb,MAAMA,aAAqC;CACzC,OAAO;CACP,OAAO;CACP,MAAM;CACN,SAAS;CACT,MAAM;CACN,OAAO;CACP,SAAS;CACT,OAAO;CACR;AAED,SAAgB,gBAAgB,OAA2B,OAAuB;CAChF,MAAM,YAAY,SAAS,SAAS,aAAa;AACjD,KAAI,EAAE,YAAY,YAChB,OAAM,IAAI,UAAU,GAAG,MAAM,mBAAmB,OAAO,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,GAAG;AAEhF,QAAO;;;AAIT,SAAgB,WAAW,YAAoB,UAA2B;CACxE,MAAM,YAAY,WAAW,WAAW,aAAa;AACrD,QAAO,cAAc,UAAa,cAAc,WAAW,aAAa;;;AAY1E,SAAgB,gBAAgB,KAAc,OAA6B;CACzE,MAAM,EAAE,OAAO,gBAAgB,aAAa,aAAa,aAAa;AACtE,KAAI,OAAO,QAAQ,YAAY,IAAI,WAAW,EAC5C,OAAM,IAAI,UAAU,GAAG,MAAM,0BAA0B;CAEzD,IAAIC;AACJ,K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AAC,WAAW,MAAM,QAAQ;EAC1B,CAAC,SAAS,MAAM,QAAQ;EACxB,CAAC,QAAQ,QAAQ,MAAM,UAAU,CAAC;EACnC,CACE,KAAK,CAAC,OAAO,WAAW,CAAC,OAAO,OAAO,UAAU,WAAW,WAAW,MAAM,GAAG,GAAG,CAAU,CAC7F,QAAQ,GAAG,WAAW,UAAU,GAAG,CACnC,KAAK,CAAC,OAAO,YAAY;EACxB,MAAM;EACN,MAAM,IAAI,MAAM,KAAK,aAAa,YAAY,MAAM,EAAE,gBAAgB;EACvE,EAAE;AACL,KAAI,QAAQ,SAAS,EAAG,QAAO,KAAK;EAAE,MAAM;EAAW,UAAU;EAAS,CAAC;AAE3E,KAAI,MAAM,QAAQ,OAAO,KAAK,MAAM,KAAK,CAAC,SAAS,GAAG;EACpD,MAAM,OAAO,aAAa,YAAY,gBAAgB,MAAM,KAAK,CAAC,EAAE,eAAe;AACnF,SAAO,KAAK;GAAE,MAAM;GAAW,MAAM;IAAE,MAAM;IAAU,MAAM,SAAS,KAAK;IAAS;GAAE,CAAC;;AAGzF,QAAO;EACL,MAAM,GAAG,MAAM,GAAG,YAAY,aAAa,UAAU,iBAAiB,CAAC;EACvE;EACD"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { p as TransportLogEntry, s as IAsyncTransport } from "./transport.types-CGoHpWQR.js";
|
|
2
|
+
|
|
3
|
+
//#region src/transports/discord.transport.d.ts
|
|
4
|
+
|
|
5
|
+
interface DiscordEmbedField {
|
|
6
|
+
name: string;
|
|
7
|
+
value: string;
|
|
8
|
+
inline?: boolean;
|
|
9
|
+
}
|
|
10
|
+
interface DiscordEmbed {
|
|
11
|
+
title?: string;
|
|
12
|
+
description?: string;
|
|
13
|
+
color?: number;
|
|
14
|
+
timestamp?: string;
|
|
15
|
+
fields?: DiscordEmbedField[];
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
}
|
|
18
|
+
interface DiscordTransportConfig {
|
|
19
|
+
/** Webhook URL (secret). Must be https on discord.com / discordapp.com unless `allowCustomUrl`. */
|
|
20
|
+
webhookUrl: string;
|
|
21
|
+
/** Minimum level to send. Default: 'error'. */
|
|
22
|
+
level?: string;
|
|
23
|
+
username?: string;
|
|
24
|
+
/** https URL of the avatar shown for the webhook. */
|
|
25
|
+
avatarUrl?: string;
|
|
26
|
+
/** Entries within this window are batched into one request. Default: 1000. */
|
|
27
|
+
minIntervalMs?: number;
|
|
28
|
+
/**
|
|
29
|
+
* Overrides the embed built for each entry. Limits are still enforced, but
|
|
30
|
+
* escaping the content is the formatter's responsibility.
|
|
31
|
+
*/
|
|
32
|
+
formatter?: (entry: TransportLogEntry) => DiscordEmbed;
|
|
33
|
+
filter?: (entry: TransportLogEntry) => boolean;
|
|
34
|
+
/** Accept an https webhook URL on any host (e.g. a proxy or Discord-compatible service). */
|
|
35
|
+
allowCustomUrl?: boolean;
|
|
36
|
+
/** Retries after an HTTP 429 (waits retry_after, max 30s). Default: 1. */
|
|
37
|
+
maxRetries?: number;
|
|
38
|
+
/** Max queued entries; the oldest are dropped past this. Default: 1000. */
|
|
39
|
+
maxBufferSize?: number;
|
|
40
|
+
requestTimeoutMs?: number;
|
|
41
|
+
}
|
|
42
|
+
declare class DiscordTransport implements IAsyncTransport {
|
|
43
|
+
readonly name = "discord";
|
|
44
|
+
readonly level: string;
|
|
45
|
+
filter?: (entry: TransportLogEntry) => boolean;
|
|
46
|
+
private readonly queue;
|
|
47
|
+
private readonly username;
|
|
48
|
+
private readonly avatarUrl;
|
|
49
|
+
private readonly formatter;
|
|
50
|
+
constructor(config: DiscordTransportConfig);
|
|
51
|
+
write(entry: TransportLogEntry): void;
|
|
52
|
+
flush(): Promise<void>;
|
|
53
|
+
close(): Promise<void>;
|
|
54
|
+
/** Never serialise the webhook URL (JSON.stringify, util.inspect). */
|
|
55
|
+
toJSON(): Record<string, unknown>;
|
|
56
|
+
private buildPayload;
|
|
57
|
+
/** Enforces the 6000-char total: drops trailing embeds if needed, then shares the rest among descriptions. */
|
|
58
|
+
private fitToBudget;
|
|
59
|
+
private draftFor;
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/transports/slack.transport.d.ts
|
|
63
|
+
/** A Slack message body as returned by a custom `formatter`. */
|
|
64
|
+
interface SlackMessage {
|
|
65
|
+
text?: string;
|
|
66
|
+
blocks?: unknown[];
|
|
67
|
+
[key: string]: unknown;
|
|
68
|
+
}
|
|
69
|
+
interface SlackTransportConfig {
|
|
70
|
+
/** Incoming-webhook URL (secret). Must be https on hooks.slack.com unless `allowCustomUrl`. */
|
|
71
|
+
webhookUrl: string;
|
|
72
|
+
/** Minimum level to send. Default: 'error'. */
|
|
73
|
+
level?: string;
|
|
74
|
+
username?: string;
|
|
75
|
+
iconEmoji?: string;
|
|
76
|
+
/** Entries within this window are batched into one message. Default: 1000. */
|
|
77
|
+
minIntervalMs?: number;
|
|
78
|
+
/**
|
|
79
|
+
* Overrides the message built for each entry. The results of one window are
|
|
80
|
+
* merged: texts are joined and blocks concatenated (capped at 50 blocks).
|
|
81
|
+
* Escaping the content is the formatter's responsibility.
|
|
82
|
+
*/
|
|
83
|
+
formatter?: (entry: TransportLogEntry) => SlackMessage;
|
|
84
|
+
filter?: (entry: TransportLogEntry) => boolean;
|
|
85
|
+
/** Accept an https webhook URL on any host (e.g. a proxy or Slack-compatible service). */
|
|
86
|
+
allowCustomUrl?: boolean;
|
|
87
|
+
/** Retries after an HTTP 429 (waits Retry-After, max 30s). Default: 1. */
|
|
88
|
+
maxRetries?: number;
|
|
89
|
+
/** Max queued entries; the oldest are dropped past this. Default: 1000. */
|
|
90
|
+
maxBufferSize?: number;
|
|
91
|
+
requestTimeoutMs?: number;
|
|
92
|
+
}
|
|
93
|
+
declare class SlackTransport implements IAsyncTransport {
|
|
94
|
+
readonly name = "slack";
|
|
95
|
+
readonly level: string;
|
|
96
|
+
filter?: (entry: TransportLogEntry) => boolean;
|
|
97
|
+
private readonly queue;
|
|
98
|
+
private readonly username;
|
|
99
|
+
private readonly iconEmoji;
|
|
100
|
+
private readonly formatter;
|
|
101
|
+
constructor(config: SlackTransportConfig);
|
|
102
|
+
write(entry: TransportLogEntry): void;
|
|
103
|
+
flush(): Promise<void>;
|
|
104
|
+
close(): Promise<void>;
|
|
105
|
+
/** Never serialise the webhook URL (JSON.stringify, util.inspect). */
|
|
106
|
+
toJSON(): Record<string, unknown>;
|
|
107
|
+
private buildPayload;
|
|
108
|
+
private messageFor;
|
|
109
|
+
}
|
|
110
|
+
//#endregion
|
|
111
|
+
export { DiscordTransport as a, DiscordEmbed as i, SlackTransport as n, DiscordTransportConfig as o, SlackTransportConfig as r, SlackMessage as t };
|
|
112
|
+
//# sourceMappingURL=slack.transport-CXjQYOes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slack.transport-CXjQYOes.d.ts","names":[],"sources":["../src/transports/discord.transport.ts","../src/transports/slack.transport.ts"],"sourcesContent":[],"mappings":";;;;AC0DsB,UDZL,iBAAA,CCYK;EAAsB,IAAA,EAAA,MAAA;EACzB,KAAA,EAAA,MAAA;EAAiB,MAAA,CAAA,EAAA,OAAA;AAuBpC;AAG0B,UDjCT,YAAA,CCiCS;EAOJ,KAAA,CAAA,EAAA,MAAA;EA4BP,WAAA,CAAA,EAAA,MAAA;EAMJ,KAAA,CAAA,EAAA,MAAA;EAIA,SAAA,CAAA,EAAA,MAAA;EAKC,MAAA,CAAA,ED9ED,iBC8EC,EAAA;EArD2B,CAAA,GAAA,EAAA,MAAA,CAAA,EAAA,OAAA;;UDrBtB,sBAAA;;;;;;;;;;;;;;sBAcK,sBAAsB;mBACzB;;;;;;;;;cAiGN,gBAAA,YAA4B;;;mBAGf;;;;;sBAOJ;eAiCP;WAMJ;WAIA;;YAKC;;;;;;;;;AA1D4C,UCvIvC,YAAA,CDuIuC;;;;ACvIxD;AAMiB,UAAA,oBAAA,CAAoB;EAcf;EAAsB,UAAA,EAAA,MAAA;EACzB;EAAiB,KAAA,CAAA,EAAA,MAAA;EAuBvB,QAAA,CAAA,EAAA,MAAe;EAGF,SAAA,CAAA,EAAA,MAAA;EAOJ;EA4BP,aAAA,CAAA,EAAA,MAAA;EAMJ;;;;;sBApEW,sBAAsB;mBACzB;;;;;;;;;cAuBN,cAAA,YAA0B;;;mBAGb;;;;;sBAOJ;eA4BP;WAMJ;WAIA;;YAKC"}
|
package/dist/testing.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./transport.types-
|
|
2
|
-
import { h as LogEntry, u as IBaseLogger } from "./index-
|
|
1
|
+
import "./transport.types-BMnurPcc.mjs";
|
|
2
|
+
import { h as LogEntry, u as IBaseLogger } from "./index-3mw5gaCw.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/testing/mock-logger.d.ts
|
|
5
5
|
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./transport.types-
|
|
2
|
-
import { h as LogEntry, u as IBaseLogger } from "./index-
|
|
1
|
+
import "./transport.types-CGoHpWQR.js";
|
|
2
|
+
import { h as LogEntry, u as IBaseLogger } from "./index-DhIoploR.js";
|
|
3
3
|
|
|
4
4
|
//#region src/testing/mock-logger.d.ts
|
|
5
5
|
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/trace.utils.ts
|
|
5
|
+
/** Default key used to store the trace ID in AsyncLocalStorage. */
|
|
6
|
+
const TRACE_CONTEXT_KEY = "traceId";
|
|
7
|
+
/**
|
|
8
|
+
* Singleton that owns the AsyncLocalStorage and the active contextKey.
|
|
9
|
+
*
|
|
10
|
+
* Why a class instead of bare module-level variables?
|
|
11
|
+
* - The contextKey is user-configurable; encapsulating it here means there is
|
|
12
|
+
* exactly one place that reads and writes it.
|
|
13
|
+
* - All helpers (getCurrentTraceId, runWithTraceId, etc.) delegate to this
|
|
14
|
+
* instance, so the key is always in sync without hidden global state.
|
|
15
|
+
* - Easier to test: you can reset the singleton between test cases.
|
|
16
|
+
*
|
|
17
|
+
* Usage (advanced):
|
|
18
|
+
* import { TraceContext } from 'logixia';
|
|
19
|
+
* TraceContext.instance.contextKey // → 'traceId' (or custom)
|
|
20
|
+
* TraceContext.instance.getCurrentTraceId() // same as standalone fn
|
|
21
|
+
*/
|
|
22
|
+
var TraceContext = class TraceContext {
|
|
23
|
+
static #_ = this._instance = null;
|
|
24
|
+
constructor() {
|
|
25
|
+
this.storage = new AsyncLocalStorage();
|
|
26
|
+
this._contextKey = TRACE_CONTEXT_KEY;
|
|
27
|
+
}
|
|
28
|
+
/** The process-wide singleton. */
|
|
29
|
+
static get instance() {
|
|
30
|
+
if (!TraceContext._instance) TraceContext._instance = new TraceContext();
|
|
31
|
+
return TraceContext._instance;
|
|
32
|
+
}
|
|
33
|
+
/** @internal Reset the singleton (useful in tests). */
|
|
34
|
+
static _reset() {
|
|
35
|
+
TraceContext._instance = null;
|
|
36
|
+
}
|
|
37
|
+
/** The AsyncLocalStorage key that holds the trace ID value. */
|
|
38
|
+
get contextKey() {
|
|
39
|
+
return this._contextKey;
|
|
40
|
+
}
|
|
41
|
+
/** @internal Called by TraceMiddleware when it boots to register the user's key. */
|
|
42
|
+
setContextKey(key) {
|
|
43
|
+
this._contextKey = key;
|
|
44
|
+
}
|
|
45
|
+
/** UUID v4 generator (default). */
|
|
46
|
+
generate() {
|
|
47
|
+
return randomUUID();
|
|
48
|
+
}
|
|
49
|
+
/** Read the trace ID from the current async context. */
|
|
50
|
+
getCurrentTraceId() {
|
|
51
|
+
var _this$storage$getStor;
|
|
52
|
+
return (_this$storage$getStor = this.storage.getStore()) === null || _this$storage$getStor === void 0 ? void 0 : _this$storage$getStor[this._contextKey];
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Mutate the CURRENT async context in-place.
|
|
56
|
+
*
|
|
57
|
+
* ⚠️ DEPRECATED — unsafe for concurrent requests.
|
|
58
|
+
*
|
|
59
|
+
* Uses `AsyncLocalStorage.enterWith()`, which mutates the current async
|
|
60
|
+
* execution context and every Promise chain spawned from it. In a server
|
|
61
|
+
* processing overlapping requests this can cause a trace ID set for one
|
|
62
|
+
* request to bleed into *other* in-flight requests that share the same
|
|
63
|
+
* async parent (e.g. a module-level setup function or a cached handler).
|
|
64
|
+
*
|
|
65
|
+
* Use {@link run} instead — it scopes the context to a callback so there
|
|
66
|
+
* is no risk of cross-request leakage.
|
|
67
|
+
*
|
|
68
|
+
* @deprecated Use `TraceContext.instance.run(traceId, fn)` — do not call
|
|
69
|
+
* `setTraceId` from request-handling code.
|
|
70
|
+
*/
|
|
71
|
+
setTraceId(traceId, data) {
|
|
72
|
+
const current = this.storage.getStore() ?? {};
|
|
73
|
+
this.storage.enterWith({
|
|
74
|
+
...current,
|
|
75
|
+
[this._contextKey]: traceId,
|
|
76
|
+
...data
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/** Run `fn` inside a new async context that carries `traceId`. */
|
|
80
|
+
run(traceId, fn, data) {
|
|
81
|
+
return this.storage.run({
|
|
82
|
+
[this._contextKey]: traceId,
|
|
83
|
+
...data
|
|
84
|
+
}, fn);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* The shared AsyncLocalStorage instance.
|
|
89
|
+
* @deprecated Prefer `TraceContext.instance.storage` for new code.
|
|
90
|
+
*/
|
|
91
|
+
const traceStorage = TraceContext.instance.storage;
|
|
92
|
+
/** Returns the key currently used to store the trace ID in AsyncLocalStorage. */
|
|
93
|
+
function getTraceContextKey() {
|
|
94
|
+
return TraceContext.instance.contextKey;
|
|
95
|
+
}
|
|
96
|
+
/** @internal Called by TraceMiddleware / traceMiddleware() when they boot. */
|
|
97
|
+
function _setActiveContextKey(key) {
|
|
98
|
+
TraceContext.instance.setContextKey(key);
|
|
99
|
+
}
|
|
100
|
+
/** Generate a UUID v4 trace ID. */
|
|
101
|
+
function generateTraceId() {
|
|
102
|
+
return TraceContext.instance.generate();
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Get the current trace ID from async context.
|
|
106
|
+
* Returns `undefined` when called outside a traced request.
|
|
107
|
+
*/
|
|
108
|
+
function getCurrentTraceId() {
|
|
109
|
+
return TraceContext.instance.getCurrentTraceId();
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Set trace ID in the CURRENT async context without starting a new one.
|
|
113
|
+
*
|
|
114
|
+
* ⚠️ DEPRECATED — unsafe for concurrent requests.
|
|
115
|
+
*
|
|
116
|
+
* Uses `AsyncLocalStorage.enterWith()`, which mutates the current async
|
|
117
|
+
* execution context and every Promise chain spawned from it. Under load this
|
|
118
|
+
* can cause a trace ID from one request to bleed into others sharing the same
|
|
119
|
+
* async parent.
|
|
120
|
+
*
|
|
121
|
+
* Use {@link runWithTraceId} instead. Migration patterns:
|
|
122
|
+
*
|
|
123
|
+
* **Express / Fastify middleware — before:**
|
|
124
|
+
* ```ts
|
|
125
|
+
* app.use((req, _res, next) => {
|
|
126
|
+
* setTraceId(req.headers['x-trace-id'] ?? generateTraceId());
|
|
127
|
+
* next();
|
|
128
|
+
* });
|
|
129
|
+
* ```
|
|
130
|
+
* **after:**
|
|
131
|
+
* ```ts
|
|
132
|
+
* app.use((req, _res, next) => {
|
|
133
|
+
* runWithTraceId(req.headers['x-trace-id'] ?? generateTraceId(), () => next());
|
|
134
|
+
* });
|
|
135
|
+
* ```
|
|
136
|
+
*
|
|
137
|
+
* **Kafka / queue consumer — before:**
|
|
138
|
+
* ```ts
|
|
139
|
+
* async function handle(msg) {
|
|
140
|
+
* setTraceId(msg.headers['x-trace-id']);
|
|
141
|
+
* await processMessage(msg);
|
|
142
|
+
* }
|
|
143
|
+
* ```
|
|
144
|
+
* **after:**
|
|
145
|
+
* ```ts
|
|
146
|
+
* async function handle(msg) {
|
|
147
|
+
* await runWithTraceId(msg.headers['x-trace-id'], () => processMessage(msg));
|
|
148
|
+
* }
|
|
149
|
+
* ```
|
|
150
|
+
*
|
|
151
|
+
* **Background job — before:**
|
|
152
|
+
* ```ts
|
|
153
|
+
* setTraceId(generateTraceId(), { jobId: job.id });
|
|
154
|
+
* await job.run();
|
|
155
|
+
* ```
|
|
156
|
+
* **after:**
|
|
157
|
+
* ```ts
|
|
158
|
+
* await runWithTraceId(generateTraceId(), () => job.run(), { jobId: job.id });
|
|
159
|
+
* ```
|
|
160
|
+
*
|
|
161
|
+
* @deprecated Use `runWithTraceId(traceId, fn)` — do not call `setTraceId`
|
|
162
|
+
* from request-handling code.
|
|
163
|
+
*/
|
|
164
|
+
function setTraceId(traceId, data) {
|
|
165
|
+
TraceContext.instance.setTraceId(traceId, data);
|
|
166
|
+
}
|
|
167
|
+
/** Run `fn` inside a new async context carrying `traceId`. */
|
|
168
|
+
function runWithTraceId(traceId, fn, data) {
|
|
169
|
+
return TraceContext.instance.run(traceId, fn, data);
|
|
170
|
+
}
|
|
171
|
+
/** Maximum accepted length for an incoming trace / correlation / request ID. */
|
|
172
|
+
const MAX_INCOMING_ID_LENGTH = 128;
|
|
173
|
+
const SAFE_INCOMING_ID = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
174
|
+
/**
|
|
175
|
+
* Validate an externally supplied identifier (trace ID, correlation ID, origin
|
|
176
|
+
* service name, message-queue ID). Accepts only 1-128 characters from
|
|
177
|
+
* `[A-Za-z0-9._:-]`; surrounding whitespace is trimmed first. Arrays use their
|
|
178
|
+
* first element. Returns the cleaned value, or `undefined` when it is unusable
|
|
179
|
+
* so callers can generate a fresh ID instead of passing client text through.
|
|
180
|
+
*/
|
|
181
|
+
function sanitizeIncomingId(value) {
|
|
182
|
+
const first = Array.isArray(value) ? value[0] : value;
|
|
183
|
+
if (typeof first !== "string" || first.length > MAX_INCOMING_ID_LENGTH * 2) return void 0;
|
|
184
|
+
const trimmed = first.trim();
|
|
185
|
+
return SAFE_INCOMING_ID.test(trimmed) ? trimmed : void 0;
|
|
186
|
+
}
|
|
187
|
+
/** W3C trace-context: `version-traceId(32hex)-spanId(16hex)-flags(2hex)`. */
|
|
188
|
+
const W3C_TRACEPARENT_RE = /^[\da-f]{2}-([\da-f]{32})-[\da-f]{16}-[\da-f]{2}$/i;
|
|
189
|
+
/**
|
|
190
|
+
* Extract the 32-hex trace-id segment from a W3C `traceparent` header value.
|
|
191
|
+
* Returns the parsed trace ID, or the original value unchanged when it is not a
|
|
192
|
+
* well-formed traceparent (so non-W3C propagation still works).
|
|
193
|
+
*/
|
|
194
|
+
function parseTraceparent(value) {
|
|
195
|
+
const m = W3C_TRACEPARENT_RE.exec(value);
|
|
196
|
+
return m ? m[1] : value;
|
|
197
|
+
}
|
|
198
|
+
/** Extract trace ID from request using configuration (header → query → body → params). */
|
|
199
|
+
function extractTraceId(request, config) {
|
|
200
|
+
const req = request;
|
|
201
|
+
if (config.header) {
|
|
202
|
+
const headers = Array.isArray(config.header) ? config.header : [config.header];
|
|
203
|
+
for (const header of headers) {
|
|
204
|
+
var _req$headers;
|
|
205
|
+
const lower = header.toLowerCase();
|
|
206
|
+
const value = sanitizeIncomingId((_req$headers = req.headers) === null || _req$headers === void 0 ? void 0 : _req$headers[lower]);
|
|
207
|
+
if (value) return lower === "traceparent" ? parseTraceparent(value) : value;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
if (config.query) {
|
|
211
|
+
const queries = Array.isArray(config.query) ? config.query : [config.query];
|
|
212
|
+
for (const query of queries) {
|
|
213
|
+
var _req$query;
|
|
214
|
+
const value = sanitizeIncomingId((_req$query = req.query) === null || _req$query === void 0 ? void 0 : _req$query[query]);
|
|
215
|
+
if (value) return value;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (config.body) {
|
|
219
|
+
const bodyFields = Array.isArray(config.body) ? config.body : [config.body];
|
|
220
|
+
for (const field of bodyFields) {
|
|
221
|
+
var _req$body;
|
|
222
|
+
const value = sanitizeIncomingId((_req$body = req.body) === null || _req$body === void 0 ? void 0 : _req$body[field]);
|
|
223
|
+
if (value) return value;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (config.params) {
|
|
227
|
+
const paramFields = Array.isArray(config.params) ? config.params : [config.params];
|
|
228
|
+
for (const param of paramFields) {
|
|
229
|
+
var _req$params;
|
|
230
|
+
const value = sanitizeIncomingId((_req$params = req.params) === null || _req$params === void 0 ? void 0 : _req$params[param]);
|
|
231
|
+
if (value) return value;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Default headers checked for incoming trace ID propagation, in priority order:
|
|
237
|
+
* traceparent (W3C/OTel) → x-trace-id → x-request-id → x-correlation-id → trace-id
|
|
238
|
+
*/
|
|
239
|
+
const DEFAULT_TRACE_HEADERS = [
|
|
240
|
+
"traceparent",
|
|
241
|
+
"x-trace-id",
|
|
242
|
+
"x-request-id",
|
|
243
|
+
"x-correlation-id",
|
|
244
|
+
"trace-id"
|
|
245
|
+
];
|
|
246
|
+
/**
|
|
247
|
+
* Create trace ID middleware for Express/NestJS
|
|
248
|
+
*/
|
|
249
|
+
function createTraceMiddleware(config) {
|
|
250
|
+
const defaultExtractor = {
|
|
251
|
+
header: DEFAULT_TRACE_HEADERS,
|
|
252
|
+
query: ["traceId", "trace_id"]
|
|
253
|
+
};
|
|
254
|
+
const resolvedConfig = {
|
|
255
|
+
...config,
|
|
256
|
+
extractor: (config === null || config === void 0 ? void 0 : config.extractor) ? {
|
|
257
|
+
...defaultExtractor,
|
|
258
|
+
...config.extractor
|
|
259
|
+
} : defaultExtractor
|
|
260
|
+
};
|
|
261
|
+
_setActiveContextKey(resolvedConfig.contextKey ?? TRACE_CONTEXT_KEY);
|
|
262
|
+
return (req, res, next) => {
|
|
263
|
+
let traceId;
|
|
264
|
+
if (resolvedConfig.extractor) traceId = extractTraceId(req, resolvedConfig.extractor);
|
|
265
|
+
if (!traceId) traceId = resolvedConfig.generator ? resolvedConfig.generator() : generateTraceId();
|
|
266
|
+
req.traceId = traceId;
|
|
267
|
+
const resObj = res;
|
|
268
|
+
if (!resObj.headersSent) try {
|
|
269
|
+
if (typeof resObj.setHeader === "function") resObj.setHeader("X-Trace-Id", traceId);
|
|
270
|
+
else if (typeof resObj.header === "function") resObj.header("X-Trace-Id", traceId);
|
|
271
|
+
} catch {}
|
|
272
|
+
runWithTraceId(traceId, () => next());
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
//#endregion
|
|
277
|
+
export { _setActiveContextKey as a, getCurrentTraceId as c, sanitizeIncomingId as d, setTraceId as f, TraceContext as i, getTraceContextKey as l, MAX_INCOMING_ID_LENGTH as n, createTraceMiddleware as o, traceStorage as p, TRACE_CONTEXT_KEY as r, extractTraceId as s, DEFAULT_TRACE_HEADERS as t, runWithTraceId as u };
|
|
278
|
+
//# sourceMappingURL=trace.utils-CvXgaiQT.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace.utils-CvXgaiQT.mjs","names":["resolvedConfig: TraceIdConfig","traceId: string | undefined"],"sources":["../src/utils/trace.utils.ts"],"sourcesContent":["/**\n * Trace ID utilities for Logitron\n */\n\nimport { AsyncLocalStorage } from 'node:async_hooks';\nimport { randomUUID } from 'node:crypto';\n\nimport type { TraceIdConfig, TraceIdExtractorConfig } from '../types';\n\n/** Default key used to store the trace ID in AsyncLocalStorage. */\nexport const TRACE_CONTEXT_KEY = 'traceId' as const;\n\n// ── TraceContext class ────────────────────────────────────────────────────────\n\n/**\n * Singleton that owns the AsyncLocalStorage and the active contextKey.\n *\n * Why a class instead of bare module-level variables?\n * - The contextKey is user-configurable; encapsulating it here means there is\n * exactly one place that reads and writes it.\n * - All helpers (getCurrentTraceId, runWithTraceId, etc.) delegate to this\n * instance, so the key is always in sync without hidden global state.\n * - Easier to test: you can reset the singleton between test cases.\n *\n * Usage (advanced):\n * import { TraceContext } from 'logixia';\n * TraceContext.instance.contextKey // → 'traceId' (or custom)\n * TraceContext.instance.getCurrentTraceId() // same as standalone fn\n */\nexport class TraceContext {\n private static _instance: TraceContext | null = null;\n\n readonly storage = new AsyncLocalStorage<Record<string, unknown>>();\n private _contextKey: string = TRACE_CONTEXT_KEY;\n\n private constructor() {}\n\n /** The process-wide singleton. */\n static get instance(): TraceContext {\n if (!TraceContext._instance) {\n TraceContext._instance = new TraceContext();\n }\n return TraceContext._instance;\n }\n\n /** @internal Reset the singleton (useful in tests). */\n static _reset(): void {\n TraceContext._instance = null;\n }\n\n // ── Key management ──────────────────────────────────────────────────────────\n\n /** The AsyncLocalStorage key that holds the trace ID value. */\n get contextKey(): string {\n return this._contextKey;\n }\n\n /** @internal Called by TraceMiddleware when it boots to register the user's key. */\n setContextKey(key: string): void {\n this._contextKey = key;\n }\n\n // ── Core operations ─────────────────────────────────────────────────────────\n\n /** UUID v4 generator (default). */\n generate(): string {\n return randomUUID();\n }\n\n /** Read the trace ID from the current async context. */\n getCurrentTraceId(): string | undefined {\n return this.storage.getStore()?.[this._contextKey] as string | undefined;\n }\n\n /**\n * Mutate the CURRENT async context in-place.\n *\n * ⚠️ DEPRECATED — unsafe for concurrent requests.\n *\n * Uses `AsyncLocalStorage.enterWith()`, which mutates the current async\n * execution context and every Promise chain spawned from it. In a server\n * processing overlapping requests this can cause a trace ID set for one\n * request to bleed into *other* in-flight requests that share the same\n * async parent (e.g. a module-level setup function or a cached handler).\n *\n * Use {@link run} instead — it scopes the context to a callback so there\n * is no risk of cross-request leakage.\n *\n * @deprecated Use `TraceContext.instance.run(traceId, fn)` — do not call\n * `setTraceId` from request-handling code.\n */\n setTraceId(traceId: string, data?: Record<string, unknown>): void {\n const current = this.storage.getStore() ?? {};\n this.storage.enterWith({ ...current, [this._contextKey]: traceId, ...data });\n }\n\n /** Run `fn` inside a new async context that carries `traceId`. */\n run<T>(traceId: string, fn: () => T, data?: Record<string, unknown>): T {\n return this.storage.run({ [this._contextKey]: traceId, ...data }, fn);\n }\n}\n\n// ── Module-level aliases (backwards-compatible public API) ────────────────────\n\n/**\n * The shared AsyncLocalStorage instance.\n * @deprecated Prefer `TraceContext.instance.storage` for new code.\n */\nexport const traceStorage = TraceContext.instance.storage;\n\n/** Returns the key currently used to store the trace ID in AsyncLocalStorage. */\nexport function getTraceContextKey(): string {\n return TraceContext.instance.contextKey;\n}\n\n/** @internal Called by TraceMiddleware / traceMiddleware() when they boot. */\nexport function _setActiveContextKey(key: string): void {\n TraceContext.instance.setContextKey(key);\n}\n\n/** Generate a UUID v4 trace ID. */\nexport function generateTraceId(): string {\n return TraceContext.instance.generate();\n}\n\n/**\n * Get the current trace ID from async context.\n * Returns `undefined` when called outside a traced request.\n */\nexport function getCurrentTraceId(): string | undefined {\n return TraceContext.instance.getCurrentTraceId();\n}\n\n/**\n * Set trace ID in the CURRENT async context without starting a new one.\n *\n * ⚠️ DEPRECATED — unsafe for concurrent requests.\n *\n * Uses `AsyncLocalStorage.enterWith()`, which mutates the current async\n * execution context and every Promise chain spawned from it. Under load this\n * can cause a trace ID from one request to bleed into others sharing the same\n * async parent.\n *\n * Use {@link runWithTraceId} instead. Migration patterns:\n *\n * **Express / Fastify middleware — before:**\n * ```ts\n * app.use((req, _res, next) => {\n * setTraceId(req.headers['x-trace-id'] ?? generateTraceId());\n * next();\n * });\n * ```\n * **after:**\n * ```ts\n * app.use((req, _res, next) => {\n * runWithTraceId(req.headers['x-trace-id'] ?? generateTraceId(), () => next());\n * });\n * ```\n *\n * **Kafka / queue consumer — before:**\n * ```ts\n * async function handle(msg) {\n * setTraceId(msg.headers['x-trace-id']);\n * await processMessage(msg);\n * }\n * ```\n * **after:**\n * ```ts\n * async function handle(msg) {\n * await runWithTraceId(msg.headers['x-trace-id'], () => processMessage(msg));\n * }\n * ```\n *\n * **Background job — before:**\n * ```ts\n * setTraceId(generateTraceId(), { jobId: job.id });\n * await job.run();\n * ```\n * **after:**\n * ```ts\n * await runWithTraceId(generateTraceId(), () => job.run(), { jobId: job.id });\n * ```\n *\n * @deprecated Use `runWithTraceId(traceId, fn)` — do not call `setTraceId`\n * from request-handling code.\n */\nexport function setTraceId(traceId: string, data?: Record<string, unknown>): void {\n TraceContext.instance.setTraceId(traceId, data);\n}\n\n/** Run `fn` inside a new async context carrying `traceId`. */\nexport function runWithTraceId<T>(traceId: string, fn: () => T, data?: Record<string, unknown>): T {\n return TraceContext.instance.run(traceId, fn, data);\n}\n\n// ── Request extraction ────────────────────────────────────────────────────────\n\n/** Shape that extractTraceId accepts (Express-compatible) */\ninterface RequestLike {\n headers?: Record<string, string | string[] | undefined>;\n query?: Record<string, string | string[] | undefined>;\n body?: Record<string, string | undefined>;\n params?: Record<string, string | undefined>;\n}\n\n/** Maximum accepted length for an incoming trace / correlation / request ID. */\nexport const MAX_INCOMING_ID_LENGTH = 128;\n\nconst SAFE_INCOMING_ID = /^[A-Za-z0-9._:-]{1,128}$/;\n\n/**\n * Validate an externally supplied identifier (trace ID, correlation ID, origin\n * service name, message-queue ID). Accepts only 1-128 characters from\n * `[A-Za-z0-9._:-]`; surrounding whitespace is trimmed first. Arrays use their\n * first element. Returns the cleaned value, or `undefined` when it is unusable\n * so callers can generate a fresh ID instead of passing client text through.\n */\nexport function sanitizeIncomingId(value: unknown): string | undefined {\n const first = Array.isArray(value) ? value[0] : value;\n if (typeof first !== 'string' || first.length > MAX_INCOMING_ID_LENGTH * 2) return undefined;\n const trimmed = first.trim();\n return SAFE_INCOMING_ID.test(trimmed) ? trimmed : undefined;\n}\n\n/** W3C trace-context: `version-traceId(32hex)-spanId(16hex)-flags(2hex)`. */\nconst W3C_TRACEPARENT_RE = /^[\\da-f]{2}-([\\da-f]{32})-[\\da-f]{16}-[\\da-f]{2}$/i;\n\n/**\n * Extract the 32-hex trace-id segment from a W3C `traceparent` header value.\n * Returns the parsed trace ID, or the original value unchanged when it is not a\n * well-formed traceparent (so non-W3C propagation still works).\n */\nfunction parseTraceparent(value: string): string {\n const m = W3C_TRACEPARENT_RE.exec(value);\n return m ? m[1]! : value;\n}\n\n/** Extract trace ID from request using configuration (header → query → body → params). */\nexport function extractTraceId(\n request: unknown,\n config: TraceIdExtractorConfig\n): string | undefined {\n const req = request as RequestLike;\n\n if (config.header) {\n const headers = Array.isArray(config.header) ? config.header : [config.header];\n for (const header of headers) {\n const lower = header.toLowerCase();\n const value = sanitizeIncomingId(req.headers?.[lower]);\n if (value) return lower === 'traceparent' ? parseTraceparent(value) : value;\n }\n }\n\n if (config.query) {\n const queries = Array.isArray(config.query) ? config.query : [config.query];\n for (const query of queries) {\n const value = sanitizeIncomingId(req.query?.[query]);\n if (value) return value;\n }\n }\n\n if (config.body) {\n const bodyFields = Array.isArray(config.body) ? config.body : [config.body];\n for (const field of bodyFields) {\n const value = sanitizeIncomingId(req.body?.[field]);\n if (value) return value;\n }\n }\n\n if (config.params) {\n const paramFields = Array.isArray(config.params) ? config.params : [config.params];\n for (const param of paramFields) {\n const value = sanitizeIncomingId(req.params?.[param]);\n if (value) return value;\n }\n }\n\n return undefined;\n}\n\n/**\n * Default headers checked for incoming trace ID propagation, in priority order:\n * traceparent (W3C/OTel) → x-trace-id → x-request-id → x-correlation-id → trace-id\n */\nexport const DEFAULT_TRACE_HEADERS = [\n 'traceparent',\n 'x-trace-id',\n 'x-request-id',\n 'x-correlation-id',\n 'trace-id',\n];\n\n/**\n * Create trace ID middleware for Express/NestJS\n */\nexport function createTraceMiddleware(config: TraceIdConfig) {\n const defaultExtractor = {\n header: DEFAULT_TRACE_HEADERS,\n query: ['traceId', 'trace_id'],\n };\n const resolvedConfig: TraceIdConfig = {\n ...config,\n extractor: config?.extractor ? { ...defaultExtractor, ...config.extractor } : defaultExtractor,\n };\n\n _setActiveContextKey(resolvedConfig.contextKey ?? TRACE_CONTEXT_KEY);\n\n return (req: unknown, res: unknown, next: () => void) => {\n let traceId: string | undefined;\n\n if (resolvedConfig.extractor) {\n traceId = extractTraceId(req, resolvedConfig.extractor);\n }\n\n if (!traceId) {\n traceId = resolvedConfig.generator ? resolvedConfig.generator() : generateTraceId();\n }\n\n (req as Record<string, unknown>).traceId = traceId;\n // Echo the trace ID back on the response, tolerating different response APIs:\n // Express/Node use res.setHeader(), Fastify replies use reply.header(). Guard\n // both and never let a missing/!function method (or already-sent headers)\n // crash the request — the trace ID is still propagated via async context.\n const resObj = res as {\n setHeader?: (k: string, v: string) => void;\n header?: (k: string, v: string) => void;\n headersSent?: boolean;\n };\n if (!resObj.headersSent) {\n try {\n if (typeof resObj.setHeader === 'function') {\n resObj.setHeader('X-Trace-Id', traceId);\n } else if (typeof resObj.header === 'function') {\n resObj.header('X-Trace-Id', traceId);\n }\n } catch {\n /* response not in a header-settable state — context propagation still works */\n }\n }\n\n runWithTraceId(traceId, () => next());\n };\n}\n"],"mappings":";;;;;AAUA,MAAa,oBAAoB;;;;;;;;;;;;;;;;AAmBjC,IAAa,eAAb,MAAa,aAAa;8BACwB;CAKhD,AAAQ,cAAc;iBAHH,IAAI,mBAA4C;qBACrC;;;CAK9B,WAAW,WAAyB;AAClC,MAAI,CAAC,aAAa,UAChB,cAAa,YAAY,IAAI,cAAc;AAE7C,SAAO,aAAa;;;CAItB,OAAO,SAAe;AACpB,eAAa,YAAY;;;CAM3B,IAAI,aAAqB;AACvB,SAAO,KAAK;;;CAId,cAAc,KAAmB;AAC/B,OAAK,cAAc;;;CAMrB,WAAmB;AACjB,SAAO,YAAY;;;CAIrB,oBAAwC;;AACtC,kCAAO,KAAK,QAAQ,UAAU,gFAAG,KAAK;;;;;;;;;;;;;;;;;;;CAoBxC,WAAW,SAAiB,MAAsC;EAChE,MAAM,UAAU,KAAK,QAAQ,UAAU,IAAI,EAAE;AAC7C,OAAK,QAAQ,UAAU;GAAE,GAAG;IAAU,KAAK,cAAc;GAAS,GAAG;GAAM,CAAC;;;CAI9E,IAAO,SAAiB,IAAa,MAAmC;AACtE,SAAO,KAAK,QAAQ,IAAI;IAAG,KAAK,cAAc;GAAS,GAAG;GAAM,EAAE,GAAG;;;;;;;AAUzE,MAAa,eAAe,aAAa,SAAS;;AAGl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