@eventferry/kafka 3.3.1 → 3.5.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/CHANGELOG.md +60 -0
- package/README.md +363 -0
- package/dist/consume.cjs +115 -0
- package/dist/consume.cjs.map +1 -0
- package/dist/consume.d.cts +114 -0
- package/dist/consume.d.ts +114 -0
- package/dist/consume.js +88 -0
- package/dist/consume.js.map +1 -0
- package/dist/index.cjs +449 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +364 -3
- package/dist/index.d.ts +364 -3
- package/dist/index.js +449 -17
- package/dist/index.js.map +1 -1
- package/package.json +12 -4
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/kafkajs-classifier.ts","../src/transactional-id.ts","../src/kafkajs-driver.ts","../src/confluent-classifier.ts","../src/confluent-config.ts","../src/confluent-driver.ts","../src/hooks.ts","../src/tracing.ts","../src/publisher.ts"],"sourcesContent":["import type { PublishErrorKind } from \"@eventferry/core\";\n\n/**\n * Classify a kafkajs producer error into a {@link PublishErrorKind} so the\n * core relay can decide whether to retry, short-circuit to the DLQ, or pause\n * polling.\n *\n * Mapping verified against `kafkajs/src/errors.js` (v2.x). Protocol error\n * codes match the Kafka Protocol error-code registry. Library-specific\n * subclasses (`KafkaJSRequestTimeoutError`, `KafkaJSConnectionError`,\n * `KafkaJSNonRetriableError`) are matched by the `name` property kafkajs\n * sets on its Error subclasses.\n *\n * Unknown errors fall back to `\"retriable\"` — the safe bias. At worst we\n * retry an error that should have been skipped; in practice we'd rather\n * over-retry than mis-classify a transient blip as terminal.\n */\nexport function classifyKafkajsError(err: unknown): PublishErrorKind {\n if (!err || typeof err !== \"object\") return \"retriable\";\n const e = err as { name?: string; type?: string; code?: number };\n\n // Class-based first — these don't carry a protocol error code.\n if (e.name === \"KafkaJSConnectionError\") return \"retriable\";\n if (e.name === \"KafkaJSRequestTimeoutError\") return \"retriable\";\n if (e.name === \"KafkaJSNonRetriableError\") return \"fatal\";\n\n // Protocol error type (string) — kafkajs's KafkaJSProtocolError exposes\n // both `type` (uppercase string) and `code` (number). Use `type` first\n // for readability and fall back to `code` for codes that lack a stable\n // string label.\n const type = typeof e.type === \"string\" ? e.type : undefined;\n if (type) {\n if (RETRIABLE_TYPES.has(type)) return \"retriable\";\n if (POISON_TYPES.has(type)) return \"poison\";\n if (FATAL_TYPES.has(type)) return \"fatal\";\n }\n\n if (typeof e.code === \"number\") {\n const k = CODE_TO_KIND.get(e.code);\n if (k) return k;\n }\n\n return \"retriable\";\n}\n\nconst RETRIABLE_TYPES = new Set<string>([\n \"NOT_LEADER_FOR_PARTITION\",\n \"LEADER_NOT_AVAILABLE\",\n \"UNKNOWN_TOPIC_OR_PARTITION\",\n \"NETWORK_EXCEPTION\",\n \"REQUEST_TIMED_OUT\",\n \"REPLICA_NOT_AVAILABLE\",\n \"NOT_ENOUGH_REPLICAS\",\n \"NOT_ENOUGH_REPLICAS_AFTER_APPEND\",\n \"FENCED_LEADER_EPOCH\",\n \"UNKNOWN_LEADER_EPOCH\",\n \"BROKER_NOT_AVAILABLE\",\n \"COORDINATOR_LOAD_IN_PROGRESS\",\n \"COORDINATOR_NOT_AVAILABLE\",\n]);\n\nconst POISON_TYPES = new Set<string>([\n \"CORRUPT_MESSAGE\",\n \"MESSAGE_TOO_LARGE\",\n \"INVALID_RECORD\",\n \"UNSUPPORTED_COMPRESSION_TYPE\",\n \"INVALID_REQUIRED_ACKS\",\n \"INVALID_PARTITIONS\",\n]);\n\nconst FATAL_TYPES = new Set<string>([\n \"INVALID_PRODUCER_EPOCH\",\n \"PRODUCER_FENCED\",\n \"TOPIC_AUTHORIZATION_FAILED\",\n \"CLUSTER_AUTHORIZATION_FAILED\",\n \"TRANSACTIONAL_ID_AUTHORIZATION_FAILED\",\n \"SASL_AUTHENTICATION_FAILED\",\n \"INVALID_TRANSACTION_STATE\",\n \"UNSUPPORTED_VERSION\",\n]);\n\n/** Numeric fallback for clusters that only return the wire code. */\nconst CODE_TO_KIND: ReadonlyMap<number, PublishErrorKind> = new Map([\n [2, \"poison\"], // CORRUPT_MESSAGE\n [3, \"retriable\"], // UNKNOWN_TOPIC_OR_PARTITION\n [5, \"retriable\"], // LEADER_NOT_AVAILABLE\n [6, \"retriable\"], // NOT_LEADER_FOR_PARTITION\n [7, \"retriable\"], // REQUEST_TIMED_OUT\n [9, \"retriable\"], // REPLICA_NOT_AVAILABLE\n [10, \"poison\"], // MESSAGE_TOO_LARGE\n [13, \"retriable\"], // NETWORK_EXCEPTION\n [19, \"retriable\"], // NOT_ENOUGH_REPLICAS\n [29, \"fatal\"], // TOPIC_AUTHORIZATION_FAILED\n [31, \"fatal\"], // CLUSTER_AUTHORIZATION_FAILED\n [47, \"fatal\"], // INVALID_PRODUCER_EPOCH\n [58, \"fatal\"], // SASL_AUTHENTICATION_FAILED\n [74, \"retriable\"], // FENCED_LEADER_EPOCH\n [76, \"poison\"], // UNSUPPORTED_COMPRESSION_TYPE\n [87, \"poison\"], // INVALID_RECORD\n]);\n","/**\n * Resolve a {@link KafkaConnectionConfig}-style `transactionalId` into the\n * concrete string the underlying driver expects.\n *\n * Accepts:\n * - `string` — used verbatim.\n * - `() => string` — invoked once at connect time.\n * - `() => Promise<string>` — awaited at connect time.\n *\n * Throws when the input is undefined (caller should pre-validate) or when\n * the callable yields an empty string.\n */\nexport async function resolveTransactionalId(\n input: string | (() => string | Promise<string>) | undefined,\n): Promise<string> {\n if (input === undefined) {\n throw new Error(\"transactionalId is required when transactional=true\");\n }\n const raw = typeof input === \"function\" ? await input() : input;\n if (typeof raw !== \"string\" || raw.length === 0) {\n throw new Error(\n \"transactionalId resolver must return a non-empty string\",\n );\n }\n return raw;\n}\n","import type {\n Logger,\n PublishableMessage,\n PublishResult,\n} from \"@eventferry/core\";\nimport { classifyKafkajsError } from \"./kafkajs-classifier.js\";\nimport { resolveTransactionalId } from \"./transactional-id.js\";\nimport type {\n KafkaConnectionConfig,\n KafkaDriver,\n KafkaJsPartitionerChoice,\n ProducerBehaviorConfig,\n} from \"./driver.js\";\n\n// Loosely-typed structural references to the kafkajs API so this file\n// compiles without kafkajs installed (it's an optional peer dep).\ninterface KjsProducer {\n connect(): Promise<void>;\n disconnect(): Promise<void>;\n // kafkajs: sendBatch takes { topicMessages }, send takes a single { topic, messages }.\n sendBatch(args: unknown): Promise<unknown>;\n transaction(): Promise<KjsTransaction>;\n}\ninterface KjsTransaction {\n sendBatch(args: unknown): Promise<unknown>;\n commit(): Promise<void>;\n abort(): Promise<void>;\n}\ninterface KjsKafka {\n producer(args?: unknown): KjsProducer;\n}\n// kafkajs's `Partitioners` namespace: three factory functions; we pluck them\n// at runtime rather than depending on the kafkajs types.\ninterface KjsPartitionersNamespace {\n DefaultPartitioner: () => unknown;\n LegacyPartitioner: () => unknown;\n JavaCompatiblePartitioner: () => unknown;\n}\n\nexport interface KafkaJsDriverOptions\n extends KafkaConnectionConfig,\n ProducerBehaviorConfig {\n /**\n * Optional logger for the driver's own diagnostics (e.g. warnings about\n * unsupported tuning options). When absent the driver falls back to\n * `console.warn` so existing users see the same output.\n */\n logger?: Logger;\n}\n\n/**\n * kafkajs producer-level knobs we expose on the typed API that kafkajs does\n * NOT actually support. On this driver these are warn-and-ignore; users\n * who need them should switch to the confluent driver.\n */\nconst UNSUPPORTED_BY_KAFKAJS = [\n \"lingerMs\",\n \"batchSize\",\n \"deliveryTimeoutMs\",\n \"maxRequestSize\",\n] as const;\n\n/**\n * Driver backed by the pure-JS `kafkajs` client. Simple, zero native deps.\n */\nexport class KafkaJsDriver implements KafkaDriver {\n readonly transactional: boolean;\n private producer: KjsProducer | null = null;\n private readonly opts: KafkaJsDriverOptions;\n\n constructor(opts: KafkaJsDriverOptions) {\n this.opts = opts;\n this.transactional = opts.transactional ?? false;\n if (this.transactional && !opts.transactionalId) {\n throw new Error(\n \"KafkaJsDriver: transactionalId is required when transactional=true\",\n );\n }\n warnUnsupportedKafkajsOptions(opts);\n }\n\n async connect(): Promise<void> {\n this.producer = await this.createProducer();\n await this.producer.connect();\n }\n\n /**\n * Construct the underlying kafkajs producer. Overridable as a test seam so\n * the send/transaction logic can be exercised without a real broker.\n */\n protected async createProducer(): Promise<KjsProducer> {\n const mod = await importKafkaJs();\n const kafka: KjsKafka = new mod.Kafka({\n clientId: this.opts.clientId ?? \"eventferry\",\n brokers: this.opts.brokers,\n // kafkajs accepts `ssl: tls.ConnectionOptions` directly — Buffer + PEM\n // string both supported. Our TlsConfig is a structural subset of that\n // (`rejectUnauthorized` intentionally omitted; the cluster CA goes via\n // `ca`). No translation needed.\n ssl: this.opts.ssl,\n // SASL: PLAIN / SCRAM-SHA-256 / SCRAM-SHA-512 / OAUTHBEARER. kafkajs's\n // shape matches ours; for OAUTHBEARER kafkajs reads only `value` from\n // the provider's returned token (other fields are ignored).\n sasl: this.opts.sasl,\n });\n const createPartitioner = resolveCreatePartitioner(\n mod.Partitioners,\n this.opts.partitioner,\n this.transactional,\n );\n // Resolve a callable transactionalId — async-safe so runtime context\n // (pod name, AZ index, k8s ordinal) can be derived at connect time.\n const resolvedTxId = this.transactional\n ? await resolveTransactionalId(this.opts.transactionalId)\n : undefined;\n return kafka.producer({\n idempotent: this.opts.idempotent ?? true,\n // Idempotent / transactional producers cap maxInFlight at 5. When the\n // user picks transactional we force 1 to keep strict ordering across\n // retries on classic (non-idempotent) clusters that haven't migrated\n // to the broker-side fence.\n maxInFlightRequests: this.transactional\n ? 1\n : this.opts.maxInFlightRequests,\n transactionalId: resolvedTxId,\n // kafkajs accepts these directly when set; undefined falls through to\n // the kafkajs default.\n requestTimeout: this.opts.requestTimeoutMs,\n transactionTimeout: this.opts.transactionTimeoutMs,\n // Setting any partitioner choice silences kafkajs's\n // KafkaJSPartitionerNotSpecified warning.\n createPartitioner,\n });\n }\n\n async disconnect(): Promise<void> {\n await this.producer?.disconnect();\n this.producer = null;\n }\n\n async sendBatch(messages: PublishableMessage[]): Promise<PublishResult[]> {\n if (!this.producer) throw new Error(\"KafkaJsDriver not connected\");\n const topicMessages = groupByTopic(messages, this.opts.compression);\n\n if (this.transactional) {\n const txn = await this.producer.transaction();\n try {\n await txn.sendBatch({ topicMessages, acks: this.opts.acks ?? -1 });\n await txn.commit();\n return messages.map((m) => ({ recordId: m.recordId, ok: true }));\n } catch (err) {\n await txn.abort().catch(() => undefined);\n const error = err instanceof Error ? err : new Error(String(err));\n // Notify the abort hook BEFORE returning failedResults. The hook is\n // best-effort: try/catch around it so a misbehaving hook can't make\n // the abort path itself throw.\n try {\n this.opts.onTransactionAbort?.(error);\n } catch {\n // swallow — already documented as best-effort\n }\n return failedResults(messages, err);\n }\n }\n\n try {\n await this.producer.sendBatch({ topicMessages, acks: this.opts.acks ?? -1 });\n return messages.map((m) => ({ recordId: m.recordId, ok: true }));\n } catch (err) {\n return failedResults(messages, err);\n }\n }\n}\n\nfunction failedResults(\n messages: PublishableMessage[],\n err: unknown,\n): PublishResult[] {\n const error = err instanceof Error ? err : new Error(String(err));\n const errorKind = classifyKafkajsError(err);\n return messages.map((m) => ({\n recordId: m.recordId,\n ok: false,\n error,\n errorKind,\n }));\n}\n\nfunction groupByTopic(messages: PublishableMessage[], compression?: string) {\n const byTopic = new Map<string, unknown[]>();\n for (const m of messages) {\n const arr = byTopic.get(m.topic) ?? [];\n arr.push({\n key: m.key,\n value: m.value,\n headers: m.headers,\n // Per-message partition override. When set, kafkajs routes the record\n // to this exact partition; when undefined, the configured partitioner\n // chooses. We keep the key here too because compacted topics need it\n // even when partition is pinned.\n ...(m.partition !== undefined ? { partition: m.partition } : {}),\n });\n byTopic.set(m.topic, arr);\n }\n return [...byTopic.entries()].map(([topic, msgs]) => ({\n topic,\n messages: msgs,\n ...(compression && compression !== \"none\" ? { compression } : {}),\n }));\n}\n\n/**\n * Resolve the `createPartitioner` factory kafkajs expects on\n * `producer({...})`. Returns `undefined` to fall through to the kafkajs\n * default when no choice is made AND the producer is non-transactional\n * (transactional producers don't trigger the no-partitioner warning).\n */\nfunction resolveCreatePartitioner(\n partitioners: KjsPartitionersNamespace | undefined,\n choice: KafkaJsPartitionerChoice | undefined,\n transactional: boolean,\n): (() => unknown) | undefined {\n if (!partitioners) return undefined;\n // Default to the java-compatible partitioner when the caller didn't pick.\n // It matches the Java client (murmur2) and silences the noisy warning;\n // for transactional producers we leave the kafkajs default alone since\n // EOS ordering is partitioner-agnostic and the warning doesn't fire there.\n const effective: KafkaJsPartitionerChoice =\n choice ?? (transactional ? \"default\" : \"java-compatible\");\n switch (effective) {\n case \"java-compatible\":\n return partitioners.JavaCompatiblePartitioner;\n case \"legacy\":\n return partitioners.LegacyPartitioner;\n case \"default\":\n return partitioners.DefaultPartitioner;\n }\n}\n\n/** Process-wide dedup so we never warn for the same option twice. */\nconst warnedKafkajsKeys = new Set<string>();\n\nfunction warnUnsupportedKafkajsOptions(opts: KafkaJsDriverOptions): void {\n for (const key of UNSUPPORTED_BY_KAFKAJS) {\n if (opts[key] === undefined) continue;\n if (warnedKafkajsKeys.has(key)) continue;\n warnedKafkajsKeys.add(key);\n const message =\n `'${key}' is not configurable on the kafkajs driver and was ignored. ` +\n `Switch to the confluent driver (driver: \"confluent\") for fine-grained tuning, ` +\n `or remove the option to silence this warning.`;\n // Route through the configured logger when present; otherwise fall back\n // to console.warn so users who never plumbed a logger still see the\n // diagnostic (matches the prior behavior).\n if (opts.logger) {\n opts.logger.warn(`[@eventferry/kafka] ${message}`, { option: key });\n } else {\n console.warn(`[@eventferry/kafka] ${message}`);\n }\n }\n}\n\n/** Internal — used by tests. Resets the dedup so warnings can be observed in isolation. */\nexport function _resetKafkajsWarnDedup(): void {\n warnedKafkajsKeys.clear();\n}\n\nasync function importKafkaJs(): Promise<{\n Kafka: new (cfg: unknown) => KjsKafka;\n Partitioners: KjsPartitionersNamespace;\n}> {\n try {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return (await import(\"kafkajs\")) as any;\n } catch {\n throw new Error(\n 'Driver \"kafkajs\" selected but the \"kafkajs\" package is not installed. Run: npm i kafkajs',\n );\n }\n}\n","import type { PublishErrorKind } from \"@eventferry/core\";\n\n/**\n * Classify a `@confluentinc/kafka-javascript` (librdkafka) producer error\n * into a {@link PublishErrorKind} so the core relay can decide whether to\n * retry, short-circuit to the DLQ, or pause polling.\n *\n * librdkafka exposes errors as numeric `RD_KAFKA_RESP_ERR_*` codes — negative\n * codes are library-internal (transport, queue-full, ssl), non-negative\n * codes are wire-protocol errors that match the Kafka protocol's error-code\n * registry. The confluent driver surfaces these on `err.code` (alongside\n * an `err.name` for the symbolic form).\n *\n * Unknown errors fall back to `\"retriable\"` — the safe bias.\n */\nexport function classifyConfluentError(err: unknown): PublishErrorKind {\n if (!err || typeof err !== \"object\") return \"retriable\";\n const e = err as { code?: number; name?: string };\n\n if (typeof e.code === \"number\") {\n const k = CODE_TO_KIND.get(e.code);\n if (k) return k;\n }\n\n if (typeof e.name === \"string\") {\n const k = NAME_TO_KIND.get(e.name);\n if (k) return k;\n }\n\n return \"retriable\";\n}\n\n/**\n * Authoritative mapping for the most-common librdkafka producer error codes.\n * Sources: `librdkafka/src/rdkafka.h` (`RD_KAFKA_RESP_ERR_*` enum) and the\n * Kafka Protocol error-code registry. Adding a code here is a one-line\n * change — start narrow, broaden as production exposes new codes.\n */\nconst CODE_TO_KIND: ReadonlyMap<number, PublishErrorKind> = new Map([\n // Library-internal (negative codes)\n [-184, \"backpressure\"], // ERR__QUEUE_FULL — our outbound buffer is full\n [-185, \"retriable\"], // ERR__TIMED_OUT\n [-187, \"retriable\"], // ERR__ALL_BROKERS_DOWN\n [-188, \"poison\"], // ERR__UNKNOWN_TOPIC — topic doesn't exist on broker\n [-190, \"poison\"], // ERR__UNKNOWN_PARTITION\n [-192, \"retriable\"], // ERR__MSG_TIMED_OUT\n [-195, \"retriable\"], // ERR__TRANSPORT\n [-198, \"poison\"], // ERR__BAD_COMPRESSION\n [-144, \"fatal\"], // ERR__FENCED — producer fenced by another with same txn id\n [-150, \"fatal\"], // ERR__FATAL — unrecoverable librdkafka error\n [-169, \"fatal\"], // ERR__AUTHENTICATION\n [-181, \"fatal\"], // ERR__SSL\n [-196, \"retriable\"], // ERR__FAIL — catch-all, safe-default to retriable\n\n // Wire-protocol (non-negative codes — Kafka error-code registry)\n [2, \"poison\"], // CORRUPT_MESSAGE\n [3, \"retriable\"], // UNKNOWN_TOPIC_OR_PARTITION\n [5, \"retriable\"], // LEADER_NOT_AVAILABLE\n [6, \"retriable\"], // NOT_LEADER_FOR_PARTITION\n [7, \"retriable\"], // REQUEST_TIMED_OUT\n [9, \"retriable\"], // REPLICA_NOT_AVAILABLE\n [10, \"poison\"], // MESSAGE_TOO_LARGE\n [13, \"retriable\"], // NETWORK_EXCEPTION\n [19, \"retriable\"], // NOT_ENOUGH_REPLICAS\n [29, \"fatal\"], // TOPIC_AUTHORIZATION_FAILED\n [31, \"fatal\"], // CLUSTER_AUTHORIZATION_FAILED\n [47, \"fatal\"], // INVALID_PRODUCER_EPOCH\n [58, \"fatal\"], // SASL_AUTHENTICATION_FAILED\n [74, \"retriable\"], // FENCED_LEADER_EPOCH\n [76, \"poison\"], // UNSUPPORTED_COMPRESSION_TYPE\n [87, \"poison\"], // INVALID_RECORD\n [89, \"quota\"], // THROTTLING_QUOTA_EXCEEDED\n]);\n\n/** Symbolic name fallback for clients that surface `err.name` only. */\nconst NAME_TO_KIND: ReadonlyMap<string, PublishErrorKind> = new Map([\n [\"ERR__QUEUE_FULL\", \"backpressure\"],\n [\"ERR__FENCED\", \"fatal\"],\n [\"ERR__FATAL\", \"fatal\"],\n [\"ERR__AUTHENTICATION\", \"fatal\"],\n [\"ERR__SSL\", \"fatal\"],\n [\"ERR__UNKNOWN_TOPIC\", \"poison\"],\n [\"ERR__UNKNOWN_PARTITION\", \"poison\"],\n [\"ERR__BAD_COMPRESSION\", \"poison\"],\n [\"ERR_TOPIC_AUTHORIZATION_FAILED\", \"fatal\"],\n [\"ERR_CLUSTER_AUTHORIZATION_FAILED\", \"fatal\"],\n [\"ERR_INVALID_PRODUCER_EPOCH\", \"fatal\"],\n [\"ERR_SASL_AUTHENTICATION_FAILED\", \"fatal\"],\n [\"ERR_CORRUPT_MESSAGE\", \"poison\"],\n [\"ERR_MSG_SIZE_TOO_LARGE\", \"poison\"],\n [\"ERR_INVALID_RECORD\", \"poison\"],\n [\"ERR_UNSUPPORTED_COMPRESSION_TYPE\", \"poison\"],\n [\"ERR_THROTTLING_QUOTA_EXCEEDED\", \"quota\"],\n]);\n","import type {\n KafkaConnectionConfig,\n ProducerBehaviorConfig,\n TlsConfig,\n} from \"./driver.js\";\n\n/**\n * Translate eventferry's normalized `KafkaConnectionConfig` into the shape\n * expected by `@confluentinc/kafka-javascript`'s `KafkaJS.Kafka` constructor.\n *\n * Returns an object with two parts:\n * - `kafkaJS`: the kafkajs-compatible config layer (clientId, brokers, and\n * simple ssl/sasl when no advanced TLS is needed).\n * - top-level keys: librdkafka-style config (e.g. `ssl.ca.pem`,\n * `security.protocol`) used when the user supplies a {@link TlsConfig}.\n *\n * Why a separate translator: the kafkajs-compat layer accepts the simple\n * `ssl: true` boolean but the verified path for mTLS (CA + cert + key) is\n * librdkafka's `ssl.*.pem` keys. The translator picks the right surface\n * based on what the caller supplied. Buffer inputs are coerced to strings —\n * librdkafka accepts PEM strings, NOT Buffers.\n */\nexport interface ConfluentClientConfig {\n kafkaJS: Record<string, unknown>;\n // librdkafka top-level keys; kept as a Record so we can spread them.\n librdkafka: Record<string, unknown>;\n}\n\nexport function buildConfluentClientConfig(\n opts: KafkaConnectionConfig & ProducerBehaviorConfig,\n): ConfluentClientConfig {\n const kafkaJS: Record<string, unknown> = {\n clientId: opts.clientId ?? \"eventferry\",\n brokers: opts.brokers,\n };\n const librdkafka: Record<string, unknown> = {};\n\n // ── Producer tuning passthrough (librdkafka config keys) ─────────────\n if (opts.lingerMs !== undefined) librdkafka[\"linger.ms\"] = opts.lingerMs;\n if (opts.batchSize !== undefined) librdkafka[\"batch.size\"] = opts.batchSize;\n if (opts.maxInFlightRequests !== undefined) {\n librdkafka[\"max.in.flight.requests.per.connection\"] =\n opts.maxInFlightRequests;\n }\n if (opts.requestTimeoutMs !== undefined) {\n librdkafka[\"request.timeout.ms\"] = opts.requestTimeoutMs;\n }\n if (opts.deliveryTimeoutMs !== undefined) {\n librdkafka[\"delivery.timeout.ms\"] = opts.deliveryTimeoutMs;\n }\n if (opts.maxRequestSize !== undefined) {\n librdkafka[\"message.max.bytes\"] = opts.maxRequestSize;\n }\n if (opts.transactionTimeoutMs !== undefined) {\n librdkafka[\"transaction.timeout.ms\"] = opts.transactionTimeoutMs;\n }\n\n const tlsRequested = opts.ssl === true || isTlsConfig(opts.ssl);\n const saslRequested = !!opts.sasl;\n\n if (saslRequested && tlsRequested) {\n librdkafka[\"security.protocol\"] = \"sasl_ssl\";\n } else if (tlsRequested) {\n librdkafka[\"security.protocol\"] = \"ssl\";\n } else if (saslRequested) {\n librdkafka[\"security.protocol\"] = \"sasl_plaintext\";\n } // else: leave as default (plaintext)\n\n if (isTlsConfig(opts.ssl)) {\n // Custom TLS — explicit librdkafka PEM keys. Buffers are coerced to\n // strings (librdkafka does not accept Buffer).\n const tls = opts.ssl;\n if (tls.ca !== undefined) {\n librdkafka[\"ssl.ca.pem\"] = stringifyPem(tls.ca);\n }\n if (tls.cert !== undefined) {\n librdkafka[\"ssl.certificate.pem\"] = stringifyPem(tls.cert);\n }\n if (tls.key !== undefined) {\n librdkafka[\"ssl.key.pem\"] = stringifyPem(tls.key);\n }\n if (tls.passphrase !== undefined) {\n librdkafka[\"ssl.key.password\"] = tls.passphrase;\n }\n // servername (SNI) — librdkafka derives SNI from `ssl.endpoint.identification.algorithm`;\n // explicit SNI override is not documented in the v1.x kafkaJS-compat surface, so we\n // honor it as a no-op for now and document the limitation in the gap analysis.\n } else if (opts.ssl === true) {\n // Simple TLS — kafkajs-compat boolean is sufficient.\n kafkaJS[\"ssl\"] = true;\n }\n\n if (opts.sasl) {\n // SASL — kafkajs-compat shape works for both password mechanisms and\n // OAUTHBEARER (the confluent client implements the provider callback).\n kafkaJS[\"sasl\"] = opts.sasl;\n }\n\n return { kafkaJS, librdkafka };\n}\n\nfunction isTlsConfig(v: unknown): v is TlsConfig {\n return typeof v === \"object\" && v !== null;\n}\n\nfunction stringifyPem(input: string | Buffer | Array<string | Buffer>): string {\n if (Array.isArray(input)) {\n return input.map((x) => (typeof x === \"string\" ? x : x.toString(\"utf8\"))).join(\"\\n\");\n }\n return typeof input === \"string\" ? input : input.toString(\"utf8\");\n}\n","import type { PublishableMessage, PublishResult } from \"@eventferry/core\";\nimport { classifyConfluentError } from \"./confluent-classifier.js\";\nimport { buildConfluentClientConfig } from \"./confluent-config.js\";\nimport { resolveTransactionalId } from \"./transactional-id.js\";\nimport type {\n KafkaConnectionConfig,\n KafkaDriver,\n ProducerBehaviorConfig,\n} from \"./driver.js\";\n\n// Structural typing of the confluent KafkaJS-compatible API surface so this\n// file compiles without the optional native dep installed.\ninterface CkProducer {\n connect(): Promise<void>;\n disconnect(): Promise<void>;\n send(args: unknown): Promise<unknown>;\n transaction(): Promise<CkTransaction>;\n}\ninterface CkTransaction {\n send(args: unknown): Promise<unknown>;\n commit(): Promise<void>;\n abort(): Promise<void>;\n}\ninterface CkKafka {\n producer(args?: unknown): CkProducer;\n}\n\nexport interface ConfluentDriverOptions\n extends KafkaConnectionConfig,\n ProducerBehaviorConfig {}\n\n/**\n * Driver backed by `@confluentinc/kafka-javascript` (librdkafka wrapper).\n * Higher throughput; uses the KafkaJS-compatible promisified API so the\n * adapter mirrors the kafkajs driver closely.\n */\nexport class ConfluentDriver implements KafkaDriver {\n readonly transactional: boolean;\n private producer: CkProducer | null = null;\n private readonly opts: ConfluentDriverOptions;\n\n constructor(opts: ConfluentDriverOptions) {\n this.opts = opts;\n this.transactional = opts.transactional ?? false;\n if (this.transactional && !opts.transactionalId) {\n throw new Error(\n \"ConfluentDriver: transactionalId is required when transactional=true\",\n );\n }\n }\n\n async connect(): Promise<void> {\n this.producer = await this.createProducer();\n await this.producer.connect();\n }\n\n /**\n * Construct the underlying confluent producer. Overridable as a test seam so\n * the send/transaction logic can be exercised without a real broker.\n */\n protected async createProducer(): Promise<CkProducer> {\n const mod = await importConfluent();\n const { kafkaJS, librdkafka } = buildConfluentClientConfig(this.opts);\n const kafka: CkKafka = new mod.KafkaJS.Kafka({\n kafkaJS,\n ...librdkafka,\n });\n // Resolve a callable transactionalId — async-safe so runtime context\n // (pod name, AZ index, k8s ordinal) can be derived at connect time.\n const resolvedTxId = this.transactional\n ? await resolveTransactionalId(this.opts.transactionalId)\n : undefined;\n return kafka.producer({\n kafkaJS: {\n idempotent: this.opts.idempotent ?? true,\n ...(resolvedTxId ? { transactionalId: resolvedTxId } : {}),\n },\n });\n }\n\n async disconnect(): Promise<void> {\n await this.producer?.disconnect();\n this.producer = null;\n }\n\n async sendBatch(messages: PublishableMessage[]): Promise<PublishResult[]> {\n if (!this.producer) throw new Error(\"ConfluentDriver not connected\");\n const topicMessages = groupByTopic(messages);\n const acks = this.opts.acks ?? -1;\n const compression = this.opts.compression;\n\n const doSends = async (target: CkProducer | CkTransaction) => {\n for (const tm of topicMessages) {\n await target.send({\n topic: tm.topic,\n messages: tm.messages,\n acks,\n ...(compression && compression !== \"none\" ? { compression } : {}),\n });\n }\n };\n\n if (this.transactional) {\n const txn = await this.producer.transaction();\n try {\n await doSends(txn);\n await txn.commit();\n return messages.map((m) => ({ recordId: m.recordId, ok: true }));\n } catch (err) {\n await txn.abort().catch(() => undefined);\n const error = err instanceof Error ? err : new Error(String(err));\n try {\n this.opts.onTransactionAbort?.(error);\n } catch {\n // swallow — abort hook is best-effort\n }\n return failedResults(messages, err);\n }\n }\n\n try {\n await doSends(this.producer);\n return messages.map((m) => ({ recordId: m.recordId, ok: true }));\n } catch (err) {\n return failedResults(messages, err);\n }\n }\n}\n\nfunction failedResults(\n messages: PublishableMessage[],\n err: unknown,\n): PublishResult[] {\n const error = err instanceof Error ? err : new Error(String(err));\n const errorKind = classifyConfluentError(err);\n return messages.map((m) => ({\n recordId: m.recordId,\n ok: false,\n error,\n errorKind,\n }));\n}\n\nfunction groupByTopic(messages: PublishableMessage[]) {\n const byTopic = new Map<string, unknown[]>();\n for (const m of messages) {\n const arr = byTopic.get(m.topic) ?? [];\n arr.push({\n key: m.key,\n value: m.value,\n headers: m.headers,\n // Per-message partition override. librdkafka honors an explicit\n // partition value; undefined leaves the default partitioner in charge.\n ...(m.partition !== undefined ? { partition: m.partition } : {}),\n });\n byTopic.set(m.topic, arr);\n }\n return [...byTopic.entries()].map(([topic, msgs]) => ({\n topic,\n messages: msgs,\n }));\n}\n\nasync function importConfluent(): Promise<{\n KafkaJS: { Kafka: new (cfg: unknown) => CkKafka };\n}> {\n try {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return (await import(\"@confluentinc/kafka-javascript\")) as any;\n } catch {\n throw new Error(\n 'Driver \"confluent\" selected but \"@confluentinc/kafka-javascript\" is not installed. Run: npm i @confluentinc/kafka-javascript',\n );\n }\n}\n","import type { PublishableMessage, PublishResult, Logger } from \"@eventferry/core\";\n\n/**\n * Lifecycle hooks fired by `KafkaPublisher`. Every hook is optional. The\n * publisher wraps each invocation in a try/catch and logs (via the\n * configured logger) on failure — a misbehaving hook will NEVER break\n * publishing.\n *\n * Typical wiring:\n * - Custom observability stacks (Datadog APM, New Relic) → `onPublish`,\n * `onError`, `onTransactionAbort`.\n * - Connection-aware readiness probes → `onConnect` / `onDisconnect`.\n * - Audit logs of every published record → `onPublish`.\n */\nexport interface KafkaPublisherHooks {\n /** Fires after the underlying client successfully connects. */\n onConnect?(): void | Promise<void>;\n /** Fires after the underlying client disconnects (clean shutdown). */\n onDisconnect?(): void | Promise<void>;\n /**\n * Fires once per record after a publish attempt — both successes and\n * failures. The `result.ok` flag distinguishes them.\n */\n onPublish?(\n result: PublishResult,\n message: PublishableMessage,\n ): void | Promise<void>;\n /**\n * Fires for any error surfaced from the publish path — driver-thrown\n * errors, transaction abort errors, etc. `message` is set when the error\n * is per-record; absent for batch-level errors (e.g. connect failure).\n */\n onError?(\n error: Error,\n message?: PublishableMessage,\n ): void | Promise<void>;\n /**\n * Fires when a transactional sendBatch's inner abort path is taken.\n * Useful for observability dashboards that track EOS failure rates.\n */\n onTransactionAbort?(error: Error): void | Promise<void>;\n}\n\n/**\n * Invoke a hook safely. Never throws back into the caller — logs the hook's\n * failure via the configured logger (or no-op when logger is absent).\n */\nexport async function safeHook(\n logger: Logger | undefined,\n hookName: keyof KafkaPublisherHooks,\n invoke: () => void | Promise<void> | undefined,\n): Promise<void> {\n try {\n const r = invoke();\n if (r && typeof (r as Promise<void>).then === \"function\") {\n await r;\n }\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n logger?.warn(`[@eventferry/kafka] hook ${hookName} threw; ignored`, {\n error: error.message,\n });\n }\n}\n","/**\n * Tracing surface for the publisher.\n *\n * eventferry deliberately does not depend on `@opentelemetry/api` — instead\n * users wire a thin adapter over their tracing system (OpenTelemetry,\n * Datadog, internal, …). This file defines the minimal contract; an\n * OpenTelemetry adapter is ~10 lines (see the README).\n *\n * The contract follows the **current stable** OpenTelemetry messaging\n * semantic conventions\n * ({@link https://github.com/open-telemetry/semantic-conventions/blob/main/docs/messaging/kafka.md spec}):\n *\n * - Span name: `\"{topic} publish\"`\n * - `SpanKind.PRODUCER`\n * - Required attributes: `messaging.system=kafka`,\n * `messaging.operation.type=publish`, `messaging.destination.name=<topic>`\n * - Recommended: `messaging.batch.message_count`, `messaging.kafka.partition`,\n * `server.address`, `server.port`\n * - One span per batch (NOT per message — per-message spans cause\n * cardinality explosion and the spec actively warns against this)\n */\n\n/** Attribute values the spec allows. */\nexport type SpanAttributeValue = string | number | boolean;\n\n/**\n * Minimal span surface the publisher needs. Implementations wrap a\n * tracing-system-specific span; methods MUST never throw out of the\n * publisher's hot path (wrap your own SDK calls in try/catch).\n */\nexport interface SpanLike {\n setAttribute(key: string, value: SpanAttributeValue): void;\n setAttributes(attrs: Record<string, SpanAttributeValue>): void;\n /** OK on success; ERROR on failure. The `message` is the error message. */\n setStatus(status: { code: \"ok\" | \"error\"; message?: string }): void;\n /** Attach an exception to the span (OpenTelemetry `recordException`). */\n recordException(error: Error): void;\n end(): void;\n}\n\n/**\n * Factory the publisher calls once per `sendBatch` to start a span.\n * Implementations MUST set `SpanKind.PRODUCER` and the messaging semconv\n * attributes on the returned span before returning it.\n */\nexport interface KafkaTracer {\n /**\n * Start a publish span.\n * @param name Recommended format: `\"{topic} publish\"`.\n * @param attributes Initial attributes (the publisher supplies the messaging\n * semconv set: system, destination.name, operation.type,\n * batch.message_count, plus optional kafka.partition and\n * server.address/port).\n */\n startPublishSpan(\n name: string,\n attributes: Record<string, SpanAttributeValue>,\n ): SpanLike;\n}\n\n/**\n * No-op tracer. Used when the user does not configure one. Cheap allocation\n * — never touches I/O.\n */\nexport class NoopKafkaTracer implements KafkaTracer {\n startPublishSpan(): SpanLike {\n return NOOP_SPAN;\n }\n}\n\nconst NOOP_SPAN: SpanLike = {\n setAttribute() {},\n setAttributes() {},\n setStatus() {},\n recordException() {},\n end() {},\n};\n","import type {\n Logger,\n PublishableMessage,\n Publisher,\n PublishResult,\n} from \"@eventferry/core\";\nimport { ConfluentDriver } from \"./confluent-driver.js\";\nimport type {\n DriverKind,\n KafkaConnectionConfig,\n KafkaDriver,\n ProducerBehaviorConfig,\n} from \"./driver.js\";\nimport { KafkaJsDriver } from \"./kafkajs-driver.js\";\nimport { safeHook } from \"./hooks.js\";\nimport type { KafkaPublisherHooks } from \"./hooks.js\";\nimport { NoopKafkaTracer } from \"./tracing.js\";\nimport type { KafkaTracer, SpanLike } from \"./tracing.js\";\n\nexport interface KafkaPublisherOptions\n extends KafkaConnectionConfig,\n ProducerBehaviorConfig {\n /** Which underlying client to use. Default \"kafkajs\". */\n driver?: DriverKind;\n /**\n * Provide a fully custom driver instance instead of the built-ins.\n * Useful for testing or unsupported clients.\n */\n customDriver?: KafkaDriver;\n /**\n * Optional structured logger. When set, the publisher routes its own\n * diagnostics (driver warnings, hook failures) through it. When omitted,\n * the publisher is silent — only the underlying drivers may still log.\n */\n logger?: Logger;\n /**\n * Optional lifecycle hooks. Every hook is invoked safely (try/catch +\n * logged via `logger`) and a misbehaving hook will never break publishing.\n */\n hooks?: KafkaPublisherHooks;\n /**\n * Optional tracer. When set, `publish()` wraps each batch in a span that\n * follows the current stable OpenTelemetry messaging semantic conventions.\n * Use a thin adapter over your tracing SDK (see {@link KafkaTracer}).\n */\n tracer?: KafkaTracer;\n}\n\n/**\n * The Publisher the Relay talks to. Wraps a pluggable KafkaDriver and adds\n * dead-letter routing, observability hooks, and OpenTelemetry-shaped publish\n * spans. Works against Kafka and Redpanda identically (Redpanda is Kafka-API\n * compatible).\n */\nexport class KafkaPublisher implements Publisher {\n private readonly driver: KafkaDriver;\n private readonly logger: Logger | undefined;\n private readonly hooks: KafkaPublisherHooks;\n private readonly tracer: KafkaTracer;\n\n constructor(opts: KafkaPublisherOptions) {\n this.logger = opts.logger;\n this.hooks = opts.hooks ?? {};\n this.tracer = opts.tracer ?? new NoopKafkaTracer();\n // Plumb the logger into driver construction so driver-side diagnostics\n // (e.g. kafkajs unsupported-tuning warnings) route through it too.\n // Plumb a safe-wrapped onTransactionAbort callback so the driver-level\n // transaction abort path fans out to the user-supplied hook safely.\n const onTransactionAbort = this.hooks.onTransactionAbort\n ? (error: Error) => {\n void safeHook(this.logger, \"onTransactionAbort\", () =>\n this.hooks.onTransactionAbort?.(error),\n );\n }\n : undefined;\n this.driver =\n opts.customDriver ?? selectDriver({ ...opts, onTransactionAbort });\n }\n\n async connect(): Promise<void> {\n await this.driver.connect();\n await safeHook(this.logger, \"onConnect\", () => this.hooks.onConnect?.());\n }\n\n async disconnect(): Promise<void> {\n await this.driver.disconnect();\n await safeHook(this.logger, \"onDisconnect\", () =>\n this.hooks.onDisconnect?.(),\n );\n }\n\n async publish(messages: PublishableMessage[]): Promise<PublishResult[]> {\n if (messages.length === 0) return [];\n\n const span = this.startBatchSpan(messages);\n let results: PublishResult[];\n try {\n results = await this.driver.sendBatch(messages);\n } catch (err) {\n // Driver-level throw — every record is a failure attributed to the\n // batch-level error. Record on the span, fire hook, rethrow.\n const error = err instanceof Error ? err : new Error(String(err));\n span.setStatus({ code: \"error\", message: error.message });\n span.recordException(error);\n span.end();\n await safeHook(this.logger, \"onError\", () => this.hooks.onError?.(error));\n throw err;\n }\n\n // Per-record hooks. Walk by index so the original message is available.\n const byId = new Map(messages.map((m) => [m.recordId, m]));\n let allOk = true;\n for (const r of results) {\n const msg = byId.get(r.recordId);\n if (!msg) continue;\n await safeHook(this.logger, \"onPublish\", () =>\n this.hooks.onPublish?.(r, msg),\n );\n if (!r.ok) {\n allOk = false;\n const err = r.error ?? new Error(\"publish failed\");\n await safeHook(this.logger, \"onError\", () =>\n this.hooks.onError?.(err, msg),\n );\n }\n }\n\n span.setStatus(allOk ? { code: \"ok\" } : { code: \"error\" });\n span.end();\n return results;\n }\n\n /**\n * Send a single dead-lettered message. The message already carries the\n * DLQ topic (the Relay rewrites it), plus the failure reason as a header.\n */\n async publishToDlq(message: PublishableMessage, error: Error): Promise<void> {\n const dlqMessage: PublishableMessage = {\n ...message,\n headers: {\n ...message.headers,\n \"dlq-reason\": error.message,\n // Error class name (e.g. \"KafkaJSProtocolError\", \"RecordTooLargeException\"),\n // useful for downstream alert routing without parsing the reason string.\n \"dlq-error-class\": error.name || error.constructor?.name || \"Error\",\n \"dlq-original-topic\": message.headers[\"original-topic\"] ?? \"\",\n \"dlq-failed-at\": new Date().toISOString(),\n },\n };\n const [result] = await this.driver.sendBatch([dlqMessage]);\n if (result && !result.ok) {\n throw result.error ?? new Error(\"DLQ publish failed\");\n }\n }\n\n /** Whether the configured driver provides atomic (EOS) batch sends. */\n get transactional(): boolean {\n return this.driver.transactional;\n }\n\n /**\n * Start a span for the batch following the OTel messaging conventions.\n *\n * Multi-topic batches: per the OTel spec, the span name uses the\n * destination — we pick the FIRST topic in the batch and document the\n * limitation. Callers that publish heterogeneous batches and care about\n * per-topic spans should split their batches upstream.\n */\n private startBatchSpan(messages: PublishableMessage[]): SpanLike {\n const topic = messages[0]?.topic ?? \"unknown\";\n return this.tracer.startPublishSpan(`${topic} publish`, {\n \"messaging.system\": \"kafka\",\n \"messaging.operation.type\": \"publish\",\n \"messaging.destination.name\": topic,\n \"messaging.batch.message_count\": messages.length,\n });\n }\n}\n\nfunction selectDriver(opts: KafkaPublisherOptions): KafkaDriver {\n const kind = opts.driver ?? \"kafkajs\";\n switch (kind) {\n case \"kafkajs\":\n return new KafkaJsDriver(opts);\n case \"confluent\":\n return new ConfluentDriver(opts);\n default:\n throw new Error(`Unknown driver \"${kind}\"`);\n }\n}\n"],"mappings":";AAiBO,SAAS,qBAAqB,KAAgC;AACnE,MAAI,CAAC,OAAO,OAAO,QAAQ,SAAU,QAAO;AAC5C,QAAM,IAAI;AAGV,MAAI,EAAE,SAAS,yBAA0B,QAAO;AAChD,MAAI,EAAE,SAAS,6BAA8B,QAAO;AACpD,MAAI,EAAE,SAAS,2BAA4B,QAAO;AAMlD,QAAM,OAAO,OAAO,EAAE,SAAS,WAAW,EAAE,OAAO;AACnD,MAAI,MAAM;AACR,QAAI,gBAAgB,IAAI,IAAI,EAAG,QAAO;AACtC,QAAI,aAAa,IAAI,IAAI,EAAG,QAAO;AACnC,QAAI,YAAY,IAAI,IAAI,EAAG,QAAO;AAAA,EACpC;AAEA,MAAI,OAAO,EAAE,SAAS,UAAU;AAC9B,UAAM,IAAI,aAAa,IAAI,EAAE,IAAI;AACjC,QAAI,EAAG,QAAO;AAAA,EAChB;AAEA,SAAO;AACT;AAEA,IAAM,kBAAkB,oBAAI,IAAY;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,IAAM,eAAe,oBAAI,IAAY;AAAA,EACnC;A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,EACF;AAAA;AAAA,EAGA,IAAI,gBAAyB;AAC3B,WAAO,KAAK,OAAO;AAAA,EACrB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUQ,eAAe,UAA0C;AAC/D,UAAM,QAAQ,SAAS,CAAC,GAAG,SAAS;AACpC,WAAO,KAAK,OAAO,iBAAiB,GAAG,KAAK,YAAY;AAAA,MACtD,oBAAoB;AAAA,MACpB,4BAA4B;AAAA,MAC5B,8BAA8B;AAAA,MAC9B,iCAAiC,SAAS;AAAA,IAC5C,CAAC;AAAA,EACH;AACF;AAEA,SAAS,aAAa,MAA0C;AAC9D,QAAM,OAAO,KAAK,UAAU;AAC5B,UAAQ,MAAM;AAAA,IACZ,KAAK;AACH,aAAO,IAAI,cAAc,IAAI;AAAA,IAC/B,KAAK;AACH,aAAO,IAAI,gBAAgB,IAAI;AAAA,IACjC;AACE,YAAM,IAAI,MAAM,mBAAmB,IAAI,GAAG;AAAA,EAC9C;AACF;","names":["CODE_TO_KIND","groupByTopic","failedResults"]}
|
|
1
|
+
{"version":3,"sources":["../src/kafkajs-classifier.ts","../src/transactional-id.ts","../src/kafkajs-driver.ts","../src/confluent-classifier.ts","../src/confluent-config.ts","../src/confluent-driver.ts","../src/hooks.ts","../src/tracing.ts","../src/publisher.ts"],"sourcesContent":["import type { PublishErrorKind } from \"@eventferry/core\";\n\n/**\n * Classify a kafkajs producer error into a {@link PublishErrorKind} so the\n * core relay can decide whether to retry, short-circuit to the DLQ, or pause\n * polling.\n *\n * Mapping verified against `kafkajs/src/errors.js` (v2.x). Protocol error\n * codes match the Kafka Protocol error-code registry. Library-specific\n * subclasses (`KafkaJSRequestTimeoutError`, `KafkaJSConnectionError`,\n * `KafkaJSNonRetriableError`) are matched by the `name` property kafkajs\n * sets on its Error subclasses.\n *\n * Unknown errors fall back to `\"retriable\"` — the safe bias. At worst we\n * retry an error that should have been skipped; in practice we'd rather\n * over-retry than mis-classify a transient blip as terminal.\n */\nexport function classifyKafkajsError(err: unknown): PublishErrorKind {\n if (!err || typeof err !== \"object\") return \"retriable\";\n const e = err as { name?: string; type?: string; code?: number };\n\n // Class-based first — these don't carry a protocol error code.\n if (e.name === \"KafkaJSConnectionError\") return \"retriable\";\n if (e.name === \"KafkaJSRequestTimeoutError\") return \"retriable\";\n if (e.name === \"KafkaJSNonRetriableError\") return \"fatal\";\n\n // Protocol error type (string) — kafkajs's KafkaJSProtocolError exposes\n // both `type` (uppercase string) and `code` (number). Use `type` first\n // for readability and fall back to `code` for codes that lack a stable\n // string label.\n const type = typeof e.type === \"string\" ? e.type : undefined;\n if (type) {\n // Fenced check comes BEFORE the fatal lookup: PRODUCER_FENCED /\n // INVALID_PRODUCER_EPOCH split out from \"fatal\" lets the publisher\n // attempt a single transparent re-init before escalating.\n if (FENCED_TYPES.has(type)) return \"fenced\";\n if (RETRIABLE_TYPES.has(type)) return \"retriable\";\n if (POISON_TYPES.has(type)) return \"poison\";\n if (FATAL_TYPES.has(type)) return \"fatal\";\n }\n\n if (typeof e.code === \"number\") {\n const k = CODE_TO_KIND.get(e.code);\n if (k) return k;\n }\n\n return \"retriable\";\n}\n\nconst RETRIABLE_TYPES = new Set<string>([\n \"NOT_LEADER_FOR_PARTITION\",\n \"LEADER_NOT_AVAILABLE\",\n \"UNKNOWN_TOPIC_OR_PARTITION\",\n \"NETWORK_EXCEPTION\",\n \"REQUEST_TIMED_OUT\",\n \"REPLICA_NOT_AVAILABLE\",\n \"NOT_ENOUGH_REPLICAS\",\n \"NOT_ENOUGH_REPLICAS_AFTER_APPEND\",\n \"FENCED_LEADER_EPOCH\",\n \"UNKNOWN_LEADER_EPOCH\",\n \"BROKER_NOT_AVAILABLE\",\n \"COORDINATOR_LOAD_IN_PROGRESS\",\n \"COORDINATOR_NOT_AVAILABLE\",\n]);\n\nconst POISON_TYPES = new Set<string>([\n \"CORRUPT_MESSAGE\",\n \"MESSAGE_TOO_LARGE\",\n \"INVALID_RECORD\",\n \"UNSUPPORTED_COMPRESSION_TYPE\",\n \"INVALID_REQUIRED_ACKS\",\n \"INVALID_PARTITIONS\",\n]);\n\nconst FENCED_TYPES = new Set<string>([\n \"INVALID_PRODUCER_EPOCH\",\n \"PRODUCER_FENCED\",\n]);\n\nconst FATAL_TYPES = new Set<string>([\n \"TOPIC_AUTHORIZATION_FAILED\",\n \"CLUSTER_AUTHORIZATION_FAILED\",\n \"TRANSACTIONAL_ID_AUTHORIZATION_FAILED\",\n \"SASL_AUTHENTICATION_FAILED\",\n \"INVALID_TRANSACTION_STATE\",\n \"UNSUPPORTED_VERSION\",\n]);\n\n/** Numeric fallback for clusters that only return the wire code. */\nconst CODE_TO_KIND: ReadonlyMap<number, PublishErrorKind> = new Map([\n [2, \"poison\"], // CORRUPT_MESSAGE\n [3, \"retriable\"], // UNKNOWN_TOPIC_OR_PARTITION\n [5, \"retriable\"], // LEADER_NOT_AVAILABLE\n [6, \"retriable\"], // NOT_LEADER_FOR_PARTITION\n [7, \"retriable\"], // REQUEST_TIMED_OUT\n [9, \"retriable\"], // REPLICA_NOT_AVAILABLE\n [10, \"poison\"], // MESSAGE_TOO_LARGE\n [13, \"retriable\"], // NETWORK_EXCEPTION\n [19, \"retriable\"], // NOT_ENOUGH_REPLICAS\n [29, \"fatal\"], // TOPIC_AUTHORIZATION_FAILED\n [31, \"fatal\"], // CLUSTER_AUTHORIZATION_FAILED\n [47, \"fenced\"], // INVALID_PRODUCER_EPOCH — retryable once via publisher reconnect\n [58, \"fatal\"], // SASL_AUTHENTICATION_FAILED\n [74, \"retriable\"], // FENCED_LEADER_EPOCH\n [76, \"poison\"], // UNSUPPORTED_COMPRESSION_TYPE\n [87, \"poison\"], // INVALID_RECORD\n]);\n","/**\n * Resolve a {@link KafkaConnectionConfig}-style `transactionalId` into the\n * concrete string the underlying driver expects.\n *\n * Accepts:\n * - `string` — used verbatim.\n * - `() => string` — invoked once at connect time.\n * - `() => Promise<string>` — awaited at connect time.\n *\n * Throws when the input is undefined (caller should pre-validate) or when\n * the callable yields an empty string.\n */\nexport async function resolveTransactionalId(\n input: string | (() => string | Promise<string>) | undefined,\n): Promise<string> {\n if (input === undefined) {\n throw new Error(\"transactionalId is required when transactional=true\");\n }\n const raw = typeof input === \"function\" ? await input() : input;\n if (typeof raw !== \"string\" || raw.length === 0) {\n throw new Error(\n \"transactionalId resolver must return a non-empty string\",\n );\n }\n return raw;\n}\n","import type {\n Logger,\n PublishableMessage,\n PublishResult,\n} from \"@eventferry/core\";\nimport { classifyKafkajsError } from \"./kafkajs-classifier.js\";\nimport { resolveTransactionalId } from \"./transactional-id.js\";\nimport type {\n KafkaConnectionConfig,\n KafkaDriver,\n KafkaJsPartitionerChoice,\n ProducerBehaviorConfig,\n} from \"./driver.js\";\nimport type {\n KafkaDriverAdmin,\n PartitionGrowSpec,\n TopicCreateSpec,\n TopicMetadata,\n} from \"./admin.js\";\n\n// Loosely-typed structural references to the kafkajs API so this file\n// compiles without kafkajs installed (it's an optional peer dep).\ninterface KjsProducer {\n connect(): Promise<void>;\n disconnect(): Promise<void>;\n // kafkajs: sendBatch takes { topicMessages }, send takes a single { topic, messages }.\n sendBatch(args: unknown): Promise<unknown>;\n transaction(): Promise<KjsTransaction>;\n}\ninterface KjsTransaction {\n sendBatch(args: unknown): Promise<unknown>;\n commit(): Promise<void>;\n abort(): Promise<void>;\n}\ninterface KjsKafka {\n producer(args?: unknown): KjsProducer;\n admin(): KjsAdmin;\n}\n// Minimal structural shape of the kafkajs Admin client — we use only the\n// methods needed for listTopics / describeTopics / createTopics / createPartitions.\n// Errors thrown from these calls bubble up unchanged (admin errors are\n// operator-facing, not relay-facing — no error-kind classification here).\ninterface KjsAdmin {\n connect(): Promise<void>;\n disconnect(): Promise<void>;\n listTopics(): Promise<string[]>;\n fetchTopicMetadata(args: {\n topics: string[];\n }): Promise<{\n topics: Array<{\n name: string;\n partitions: Array<{\n partitionId: number;\n leader: number;\n replicas: number[];\n isr: number[];\n }>;\n }>;\n }>;\n createTopics(args: {\n topics: Array<{\n topic: string;\n numPartitions?: number;\n replicationFactor?: number;\n configEntries?: Array<{ name: string; value: string }>;\n }>;\n waitForLeaders?: boolean;\n }): Promise<boolean>;\n createPartitions(args: {\n topicPartitions: Array<{ topic: string; count: number }>;\n }): Promise<void>;\n}\n// kafkajs's `Partitioners` namespace: three factory functions; we pluck them\n// at runtime rather than depending on the kafkajs types.\ninterface KjsPartitionersNamespace {\n DefaultPartitioner: () => unknown;\n LegacyPartitioner: () => unknown;\n JavaCompatiblePartitioner: () => unknown;\n}\n\nexport interface KafkaJsDriverOptions\n extends KafkaConnectionConfig,\n ProducerBehaviorConfig {\n /**\n * Optional logger for the driver's own diagnostics (e.g. warnings about\n * unsupported tuning options). When absent the driver falls back to\n * `console.warn` so existing users see the same output.\n */\n logger?: Logger;\n}\n\n/**\n * kafkajs producer-level knobs we expose on the typed API that kafkajs does\n * NOT actually support. On this driver these are warn-and-ignore; users\n * who need them should switch to the confluent driver.\n */\nconst UNSUPPORTED_BY_KAFKAJS = [\n \"lingerMs\",\n \"batchSize\",\n \"deliveryTimeoutMs\",\n \"maxRequestSize\",\n // Confluent-only escape hatches; ignored on kafkajs.\n \"compressionLevel\",\n \"rawProducerConfig\",\n // librdkafka stats — kafkajs has no equivalent surface.\n \"onStats\",\n \"statsIntervalMs\",\n] as const;\n\n/**\n * Driver backed by the pure-JS `kafkajs` client. Simple, zero native deps.\n */\nexport class KafkaJsDriver implements KafkaDriver {\n readonly transactional: boolean;\n private producer: KjsProducer | null = null;\n private readonly opts: KafkaJsDriverOptions;\n\n constructor(opts: KafkaJsDriverOptions) {\n this.opts = opts;\n this.transactional = opts.transactional ?? false;\n if (this.transactional && !opts.transactionalId) {\n throw new Error(\n \"KafkaJsDriver: transactionalId is required when transactional=true\",\n );\n }\n warnUnsupportedKafkajsOptions(opts);\n }\n\n async connect(): Promise<void> {\n this.producer = await this.createProducer();\n await this.producer.connect();\n }\n\n /**\n * Construct the underlying kafkajs producer. Overridable as a test seam so\n * the send/transaction logic can be exercised without a real broker.\n */\n protected async createProducer(): Promise<KjsProducer> {\n const mod = await importKafkaJs();\n const kafka: KjsKafka = new mod.Kafka({\n clientId: this.opts.clientId ?? \"eventferry\",\n brokers: this.opts.brokers,\n // kafkajs accepts `ssl: tls.ConnectionOptions` directly — Buffer + PEM\n // string both supported. Our TlsConfig is a structural subset of that\n // (`rejectUnauthorized` intentionally omitted; the cluster CA goes via\n // `ca`). No translation needed.\n ssl: this.opts.ssl,\n // SASL: PLAIN / SCRAM-SHA-256 / SCRAM-SHA-512 / OAUTHBEARER. kafkajs's\n // shape matches ours; for OAUTHBEARER kafkajs reads only `value` from\n // the provider's returned token (other fields are ignored).\n sasl: this.opts.sasl,\n });\n return kafka.producer(await this.buildProducerOptions(mod.Partitioners));\n }\n\n /**\n * Compute the options object passed to `kafka.producer({...})`. Exposed\n * as a test seam so power-user escape hatches (customPartitioner,\n * rawKafkaJsProducerConfig) can be asserted without a live broker.\n */\n protected async buildProducerOptions(\n partitioners: KjsPartitionersNamespace | undefined,\n ): Promise<Record<string, unknown>> {\n // Custom partitioner (escape hatch) wins over the preset `partitioner` choice.\n const createPartitioner =\n this.opts.customPartitioner ??\n resolveCreatePartitioner(\n partitioners,\n this.opts.partitioner,\n this.transactional,\n );\n // Resolve a callable transactionalId — async-safe so runtime context\n // (pod name, AZ index, k8s ordinal) can be derived at connect time.\n const resolvedTxId = this.transactional\n ? await resolveTransactionalId(this.opts.transactionalId)\n : undefined;\n return {\n idempotent: this.opts.idempotent ?? true,\n // Idempotent / transactional producers cap maxInFlight at 5. When the\n // user picks transactional we force 1 to keep strict ordering across\n // retries on classic (non-idempotent) clusters that haven't migrated\n // to the broker-side fence.\n maxInFlightRequests: this.transactional\n ? 1\n : this.opts.maxInFlightRequests,\n transactionalId: resolvedTxId,\n // kafkajs accepts these directly when set; undefined falls through to\n // the kafkajs default.\n requestTimeout: this.opts.requestTimeoutMs,\n transactionTimeout: this.opts.transactionTimeoutMs,\n // Setting any partitioner choice silences kafkajs's\n // KafkaJSPartitionerNotSpecified warning.\n createPartitioner,\n // Power-user escape hatch — merged LAST so raw keys win against the\n // translated ones. That's the contract: anything you put here is\n // final, even if it overrides idempotent/transactionalId/etc.\n ...(this.opts.rawKafkaJsProducerConfig ?? {}),\n };\n }\n\n async disconnect(): Promise<void> {\n await this.producer?.disconnect();\n this.producer = null;\n }\n\n /**\n * Construct a kafkajs admin client wrapped in the eventferry-facing\n * `KafkaDriverAdmin` shape. The publisher calls `.connect()` on the\n * returned object before exposing it via `publisher.admin()`.\n */\n async admin(): Promise<KafkaDriverAdmin> {\n const mod = await importKafkaJs();\n const kafka: KjsKafka = new mod.Kafka({\n clientId: this.opts.clientId ?? \"eventferry-admin\",\n brokers: this.opts.brokers,\n ssl: this.opts.ssl,\n sasl: this.opts.sasl,\n });\n return new KafkaJsAdmin(kafka.admin());\n }\n\n async sendBatch(messages: PublishableMessage[]): Promise<PublishResult[]> {\n if (!this.producer) throw new Error(\"KafkaJsDriver not connected\");\n const topicMessages = groupByTopic(messages, this.opts.compression);\n\n if (this.transactional) {\n const txn = await this.producer.transaction();\n try {\n await txn.sendBatch({ topicMessages, acks: this.opts.acks ?? -1 });\n await txn.commit();\n return messages.map((m) => ({ recordId: m.recordId, ok: true }));\n } catch (err) {\n await txn.abort().catch(() => undefined);\n const error = err instanceof Error ? err : new Error(String(err));\n // Notify the abort hook BEFORE returning failedResults. The hook is\n // best-effort: try/catch around it so a misbehaving hook can't make\n // the abort path itself throw.\n try {\n this.opts.onTransactionAbort?.(error);\n } catch {\n // swallow — already documented as best-effort\n }\n return failedResults(messages, err);\n }\n }\n\n try {\n await this.producer.sendBatch({ topicMessages, acks: this.opts.acks ?? -1 });\n return messages.map((m) => ({ recordId: m.recordId, ok: true }));\n } catch (err) {\n return failedResults(messages, err);\n }\n }\n}\n\nfunction failedResults(\n messages: PublishableMessage[],\n err: unknown,\n): PublishResult[] {\n const error = err instanceof Error ? err : new Error(String(err));\n const errorKind = classifyKafkajsError(err);\n return messages.map((m) => ({\n recordId: m.recordId,\n ok: false,\n error,\n errorKind,\n }));\n}\n\nfunction groupByTopic(messages: PublishableMessage[], compression?: string) {\n const byTopic = new Map<string, unknown[]>();\n for (const m of messages) {\n const arr = byTopic.get(m.topic) ?? [];\n arr.push({\n key: m.key,\n value: m.value,\n headers: m.headers,\n // Per-message partition override. When set, kafkajs routes the record\n // to this exact partition; when undefined, the configured partitioner\n // chooses. We keep the key here too because compacted topics need it\n // even when partition is pinned.\n ...(m.partition !== undefined ? { partition: m.partition } : {}),\n });\n byTopic.set(m.topic, arr);\n }\n return [...byTopic.entries()].map(([topic, msgs]) => ({\n topic,\n messages: msgs,\n ...(compression && compression !== \"none\" ? { compression } : {}),\n }));\n}\n\n/**\n * Resolve the `createPartitioner` factory kafkajs expects on\n * `producer({...})`. Returns `undefined` to fall through to the kafkajs\n * default when no choice is made AND the producer is non-transactional\n * (transactional producers don't trigger the no-partitioner warning).\n */\nfunction resolveCreatePartitioner(\n partitioners: KjsPartitionersNamespace | undefined,\n choice: KafkaJsPartitionerChoice | undefined,\n transactional: boolean,\n): (() => unknown) | undefined {\n if (!partitioners) return undefined;\n // Default to the java-compatible partitioner when the caller didn't pick.\n // It matches the Java client (murmur2) and silences the noisy warning;\n // for transactional producers we leave the kafkajs default alone since\n // EOS ordering is partitioner-agnostic and the warning doesn't fire there.\n const effective: KafkaJsPartitionerChoice =\n choice ?? (transactional ? \"default\" : \"java-compatible\");\n switch (effective) {\n case \"java-compatible\":\n return partitioners.JavaCompatiblePartitioner;\n case \"legacy\":\n return partitioners.LegacyPartitioner;\n case \"default\":\n return partitioners.DefaultPartitioner;\n }\n}\n\n/** Process-wide dedup so we never warn for the same option twice. */\nconst warnedKafkajsKeys = new Set<string>();\n\nfunction warnUnsupportedKafkajsOptions(opts: KafkaJsDriverOptions): void {\n for (const key of UNSUPPORTED_BY_KAFKAJS) {\n if (opts[key] === undefined) continue;\n if (warnedKafkajsKeys.has(key)) continue;\n warnedKafkajsKeys.add(key);\n const message =\n `'${key}' is not configurable on the kafkajs driver and was ignored. ` +\n `Switch to the confluent driver (driver: \"confluent\") for fine-grained tuning, ` +\n `or remove the option to silence this warning.`;\n // Route through the configured logger when present; otherwise fall back\n // to console.warn so users who never plumbed a logger still see the\n // diagnostic (matches the prior behavior).\n if (opts.logger) {\n opts.logger.warn(`[@eventferry/kafka] ${message}`, { option: key });\n } else {\n console.warn(`[@eventferry/kafka] ${message}`);\n }\n }\n}\n\n/** Internal — used by tests. Resets the dedup so warnings can be observed in isolation. */\nexport function _resetKafkajsWarnDedup(): void {\n warnedKafkajsKeys.clear();\n}\n\n/**\n * Adapt the kafkajs admin client to the {@link KafkaDriverAdmin} contract.\n * Idempotent semantics for `createTopics` / `createPartitions` are\n * implemented here so the publisher's `ensureTopics` helper stays small.\n */\nclass KafkaJsAdmin implements KafkaDriverAdmin {\n constructor(private readonly client: KjsAdmin) {}\n\n async connect(): Promise<void> {\n await this.client.connect();\n }\n\n async close(): Promise<void> {\n await this.client.disconnect();\n }\n\n async listTopics(): Promise<string[]> {\n return await this.client.listTopics();\n }\n\n async describeTopics(topics: string[]): Promise<TopicMetadata[]> {\n if (topics.length === 0) return [];\n const all = new Set(await this.client.listTopics());\n // Fetch metadata only for the ones that exist; map absent topics to\n // empty-partitions descriptors (matches the documented behavior).\n const existing = topics.filter((t) => all.has(t));\n const missing = topics.filter((t) => !all.has(t));\n const meta = existing.length\n ? await this.client.fetchTopicMetadata({ topics: existing })\n : { topics: [] };\n const byName = new Map(meta.topics.map((t) => [t.name, t]));\n return topics.map((topic) => {\n if (missing.includes(topic)) return { topic, partitions: [] };\n const found = byName.get(topic);\n if (!found) return { topic, partitions: [] };\n return {\n topic,\n partitions: found.partitions.map((p) => ({\n partitionId: p.partitionId,\n leader: p.leader,\n replicas: p.replicas,\n isr: p.isr,\n })),\n };\n });\n }\n\n async createTopics(specs: TopicCreateSpec[]): Promise<void> {\n if (specs.length === 0) return;\n const topics = specs.map((s) => ({\n topic: s.topic,\n numPartitions: s.numPartitions,\n replicationFactor: s.replicationFactor,\n configEntries: s.configEntries\n ? Object.entries(s.configEntries).map(([name, value]) => ({ name, value }))\n : undefined,\n }));\n try {\n await this.client.createTopics({ topics, waitForLeaders: true });\n } catch (err) {\n // kafkajs raises KafkaJSProtocolError with type \"TOPIC_ALREADY_EXISTS\".\n // Idempotent contract: silently swallow that case; surface everything else.\n const e = err as { type?: string; message?: string };\n if (e?.type === \"TOPIC_ALREADY_EXISTS\") return;\n if (/already exists/i.test(e?.message ?? \"\")) return;\n throw err;\n }\n }\n\n async createPartitions(specs: PartitionGrowSpec[]): Promise<void> {\n if (specs.length === 0) return;\n await this.client.createPartitions({\n topicPartitions: specs.map((s) => ({\n topic: s.topic,\n count: s.totalCount,\n })),\n });\n }\n}\n\nasync function importKafkaJs(): Promise<{\n Kafka: new (cfg: unknown) => KjsKafka;\n Partitioners: KjsPartitionersNamespace;\n}> {\n try {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return (await import(\"kafkajs\")) as any;\n } catch {\n throw new Error(\n 'Driver \"kafkajs\" selected but the \"kafkajs\" package is not installed. Run: npm i kafkajs',\n );\n }\n}\n","import type { PublishErrorKind } from \"@eventferry/core\";\n\n/**\n * Classify a `@confluentinc/kafka-javascript` (librdkafka) producer error\n * into a {@link PublishErrorKind} so the core relay can decide whether to\n * retry, short-circuit to the DLQ, or pause polling.\n *\n * librdkafka exposes errors as numeric `RD_KAFKA_RESP_ERR_*` codes — negative\n * codes are library-internal (transport, queue-full, ssl), non-negative\n * codes are wire-protocol errors that match the Kafka protocol's error-code\n * registry. The confluent driver surfaces these on `err.code` (alongside\n * an `err.name` for the symbolic form).\n *\n * Unknown errors fall back to `\"retriable\"` — the safe bias.\n */\nexport function classifyConfluentError(err: unknown): PublishErrorKind {\n if (!err || typeof err !== \"object\") return \"retriable\";\n const e = err as { code?: number; name?: string };\n\n if (typeof e.code === \"number\") {\n const k = CODE_TO_KIND.get(e.code);\n if (k) return k;\n }\n\n if (typeof e.name === \"string\") {\n const k = NAME_TO_KIND.get(e.name);\n if (k) return k;\n }\n\n return \"retriable\";\n}\n\n/**\n * Authoritative mapping for the most-common librdkafka producer error codes.\n * Sources: `librdkafka/src/rdkafka.h` (`RD_KAFKA_RESP_ERR_*` enum) and the\n * Kafka Protocol error-code registry. Adding a code here is a one-line\n * change — start narrow, broaden as production exposes new codes.\n */\nconst CODE_TO_KIND: ReadonlyMap<number, PublishErrorKind> = new Map([\n // Library-internal (negative codes)\n [-184, \"backpressure\"], // ERR__QUEUE_FULL — our outbound buffer is full\n [-185, \"retriable\"], // ERR__TIMED_OUT\n [-187, \"retriable\"], // ERR__ALL_BROKERS_DOWN\n [-188, \"poison\"], // ERR__UNKNOWN_TOPIC — topic doesn't exist on broker\n [-190, \"poison\"], // ERR__UNKNOWN_PARTITION\n [-192, \"retriable\"], // ERR__MSG_TIMED_OUT\n [-195, \"retriable\"], // ERR__TRANSPORT\n [-198, \"poison\"], // ERR__BAD_COMPRESSION\n [-144, \"fenced\"], // ERR__FENCED — producer fenced; publisher reconnect attempts a transparent recovery once\n [-150, \"fatal\"], // ERR__FATAL — unrecoverable librdkafka error\n [-169, \"fatal\"], // ERR__AUTHENTICATION\n [-181, \"fatal\"], // ERR__SSL\n [-196, \"retriable\"], // ERR__FAIL — catch-all, safe-default to retriable\n\n // Wire-protocol (non-negative codes — Kafka error-code registry)\n [2, \"poison\"], // CORRUPT_MESSAGE\n [3, \"retriable\"], // UNKNOWN_TOPIC_OR_PARTITION\n [5, \"retriable\"], // LEADER_NOT_AVAILABLE\n [6, \"retriable\"], // NOT_LEADER_FOR_PARTITION\n [7, \"retriable\"], // REQUEST_TIMED_OUT\n [9, \"retriable\"], // REPLICA_NOT_AVAILABLE\n [10, \"poison\"], // MESSAGE_TOO_LARGE\n [13, \"retriable\"], // NETWORK_EXCEPTION\n [19, \"retriable\"], // NOT_ENOUGH_REPLICAS\n [29, \"fatal\"], // TOPIC_AUTHORIZATION_FAILED\n [31, \"fatal\"], // CLUSTER_AUTHORIZATION_FAILED\n [47, \"fenced\"], // INVALID_PRODUCER_EPOCH — retryable once via publisher reconnect\n [58, \"fatal\"], // SASL_AUTHENTICATION_FAILED\n [74, \"retriable\"], // FENCED_LEADER_EPOCH\n [76, \"poison\"], // UNSUPPORTED_COMPRESSION_TYPE\n [87, \"poison\"], // INVALID_RECORD\n [89, \"quota\"], // THROTTLING_QUOTA_EXCEEDED\n]);\n\n/** Symbolic name fallback for clients that surface `err.name` only. */\nconst NAME_TO_KIND: ReadonlyMap<string, PublishErrorKind> = new Map([\n [\"ERR__QUEUE_FULL\", \"backpressure\"],\n [\"ERR__FENCED\", \"fenced\"],\n [\"ERR__FATAL\", \"fatal\"],\n [\"ERR__AUTHENTICATION\", \"fatal\"],\n [\"ERR__SSL\", \"fatal\"],\n [\"ERR__UNKNOWN_TOPIC\", \"poison\"],\n [\"ERR__UNKNOWN_PARTITION\", \"poison\"],\n [\"ERR__BAD_COMPRESSION\", \"poison\"],\n [\"ERR_TOPIC_AUTHORIZATION_FAILED\", \"fatal\"],\n [\"ERR_CLUSTER_AUTHORIZATION_FAILED\", \"fatal\"],\n [\"ERR_INVALID_PRODUCER_EPOCH\", \"fenced\"],\n [\"ERR_SASL_AUTHENTICATION_FAILED\", \"fatal\"],\n [\"ERR_CORRUPT_MESSAGE\", \"poison\"],\n [\"ERR_MSG_SIZE_TOO_LARGE\", \"poison\"],\n [\"ERR_INVALID_RECORD\", \"poison\"],\n [\"ERR_UNSUPPORTED_COMPRESSION_TYPE\", \"poison\"],\n [\"ERR_THROTTLING_QUOTA_EXCEEDED\", \"quota\"],\n]);\n","import type {\n KafkaConnectionConfig,\n LibrdkafkaStats,\n ProducerBehaviorConfig,\n TlsConfig,\n} from \"./driver.js\";\n\n/**\n * Translate eventferry's normalized `KafkaConnectionConfig` into the shape\n * expected by `@confluentinc/kafka-javascript`'s `KafkaJS.Kafka` constructor.\n *\n * Returns an object with two parts:\n * - `kafkaJS`: the kafkajs-compatible config layer (clientId, brokers, and\n * simple ssl/sasl when no advanced TLS is needed).\n * - top-level keys: librdkafka-style config (e.g. `ssl.ca.pem`,\n * `security.protocol`) used when the user supplies a {@link TlsConfig}.\n *\n * Why a separate translator: the kafkajs-compat layer accepts the simple\n * `ssl: true` boolean but the verified path for mTLS (CA + cert + key) is\n * librdkafka's `ssl.*.pem` keys. The translator picks the right surface\n * based on what the caller supplied. Buffer inputs are coerced to strings —\n * librdkafka accepts PEM strings, NOT Buffers.\n */\nexport interface ConfluentClientConfig {\n kafkaJS: Record<string, unknown>;\n // librdkafka top-level keys; kept as a Record so we can spread them.\n librdkafka: Record<string, unknown>;\n}\n\nexport function buildConfluentClientConfig(\n opts: KafkaConnectionConfig & ProducerBehaviorConfig,\n): ConfluentClientConfig {\n const kafkaJS: Record<string, unknown> = {\n clientId: opts.clientId ?? \"eventferry\",\n brokers: opts.brokers,\n };\n const librdkafka: Record<string, unknown> = {};\n\n // ── Producer tuning passthrough (librdkafka config keys) ─────────────\n if (opts.lingerMs !== undefined) librdkafka[\"linger.ms\"] = opts.lingerMs;\n if (opts.batchSize !== undefined) librdkafka[\"batch.size\"] = opts.batchSize;\n if (opts.maxInFlightRequests !== undefined) {\n librdkafka[\"max.in.flight.requests.per.connection\"] =\n opts.maxInFlightRequests;\n }\n if (opts.requestTimeoutMs !== undefined) {\n librdkafka[\"request.timeout.ms\"] = opts.requestTimeoutMs;\n }\n if (opts.deliveryTimeoutMs !== undefined) {\n librdkafka[\"delivery.timeout.ms\"] = opts.deliveryTimeoutMs;\n }\n if (opts.maxRequestSize !== undefined) {\n librdkafka[\"message.max.bytes\"] = opts.maxRequestSize;\n }\n if (opts.transactionTimeoutMs !== undefined) {\n librdkafka[\"transaction.timeout.ms\"] = opts.transactionTimeoutMs;\n }\n if (opts.compressionLevel !== undefined) {\n librdkafka[\"compression.level\"] = opts.compressionLevel;\n }\n\n // Stats hook: wire `stats_cb` into librdkafka and pick a sensible default\n // interval. librdkafka stats are CPU-billed (it serializes the stats JSON\n // each tick) so we don't enable the timer unless the hook is set.\n if (opts.onStats) {\n librdkafka[\"stats_cb\"] = wrapStatsCallback(opts.onStats);\n // Default 30s — long enough to be cheap, short enough to be useful.\n // Users can override via statsIntervalMs OR rawProducerConfig.\n librdkafka[\"statistics.interval.ms\"] =\n opts.statsIntervalMs ?? 30_000;\n } else if (opts.statsIntervalMs !== undefined) {\n // statsIntervalMs without onStats is a no-op at the eventferry layer\n // (librdkafka still emits stats events, just discarded). Honor the\n // setting in case the user wired their own event listener on the\n // raw client via rawProducerConfig.\n librdkafka[\"statistics.interval.ms\"] = opts.statsIntervalMs;\n }\n\n const tlsRequested = opts.ssl === true || isTlsConfig(opts.ssl);\n const saslRequested = !!opts.sasl;\n\n if (saslRequested && tlsRequested) {\n librdkafka[\"security.protocol\"] = \"sasl_ssl\";\n } else if (tlsRequested) {\n librdkafka[\"security.protocol\"] = \"ssl\";\n } else if (saslRequested) {\n librdkafka[\"security.protocol\"] = \"sasl_plaintext\";\n } // else: leave as default (plaintext)\n\n if (isTlsConfig(opts.ssl)) {\n // Custom TLS — explicit librdkafka PEM keys. Buffers are coerced to\n // strings (librdkafka does not accept Buffer).\n const tls = opts.ssl;\n if (tls.ca !== undefined) {\n librdkafka[\"ssl.ca.pem\"] = stringifyPem(tls.ca);\n }\n if (tls.cert !== undefined) {\n librdkafka[\"ssl.certificate.pem\"] = stringifyPem(tls.cert);\n }\n if (tls.key !== undefined) {\n librdkafka[\"ssl.key.pem\"] = stringifyPem(tls.key);\n }\n if (tls.passphrase !== undefined) {\n librdkafka[\"ssl.key.password\"] = tls.passphrase;\n }\n // servername (SNI) — librdkafka v1.x does not expose an explicit SNI\n // override at the kafkaJS-compat layer (SNI is derived from the broker\n // address). Honored as a documented no-op here; the option is\n // meaningful on the kafkajs driver and a multi-driver setup shouldn't\n // bear extra warning noise because one of the two ignores it. The\n // TlsConfig JSDoc + README call out the driver-parity gap.\n } else if (opts.ssl === true) {\n // Simple TLS — kafkajs-compat boolean is sufficient.\n kafkaJS[\"ssl\"] = true;\n }\n\n if (opts.sasl) {\n // SASL — kafkajs-compat shape works for both password mechanisms and\n // OAUTHBEARER (the confluent client implements the provider callback).\n kafkaJS[\"sasl\"] = opts.sasl;\n }\n\n // Power-user escape hatch — merged LAST so raw keys win against the\n // translated ones (deliberate; that's the whole point of the hatch).\n if (opts.rawProducerConfig) {\n Object.assign(librdkafka, opts.rawProducerConfig);\n }\n\n return { kafkaJS, librdkafka };\n}\n\nfunction isTlsConfig(v: unknown): v is TlsConfig {\n return typeof v === \"object\" && v !== null;\n}\n\n/**\n * Wrap the user's onStats callback to:\n * 1. Parse the JSON string librdkafka emits (it's never an object).\n * 2. Swallow callback exceptions — a misbehaving observer must never\n * take down the producer's event loop.\n * 3. Swallow JSON parse failures with no further escalation — losing a\n * single stats sample is preferable to an unhandled exception in a\n * hot-path emitter that fires every {@link ProducerBehaviorConfig.statsIntervalMs}.\n */\nfunction wrapStatsCallback(\n onStats: (stats: LibrdkafkaStats) => void,\n): (raw: string | LibrdkafkaStats) => void {\n return (raw) => {\n let parsed: LibrdkafkaStats;\n try {\n parsed = typeof raw === \"string\" ? (JSON.parse(raw) as LibrdkafkaStats) : raw;\n } catch {\n return;\n }\n try {\n onStats(parsed);\n } catch {\n // user-supplied callback threw; ignore — the producer loop must\n // continue. Use a logger inside your callback if you want diagnostics.\n }\n };\n}\n\nfunction stringifyPem(input: string | Buffer | Array<string | Buffer>): string {\n if (Array.isArray(input)) {\n return input.map((x) => (typeof x === \"string\" ? x : x.toString(\"utf8\"))).join(\"\\n\");\n }\n return typeof input === \"string\" ? input : input.toString(\"utf8\");\n}\n","import type { PublishableMessage, PublishResult } from \"@eventferry/core\";\nimport { classifyConfluentError } from \"./confluent-classifier.js\";\nimport { buildConfluentClientConfig } from \"./confluent-config.js\";\nimport { resolveTransactionalId } from \"./transactional-id.js\";\nimport type {\n KafkaConnectionConfig,\n KafkaDriver,\n ProducerBehaviorConfig,\n} from \"./driver.js\";\nimport type {\n KafkaDriverAdmin,\n PartitionGrowSpec,\n TopicCreateSpec,\n TopicMetadata,\n} from \"./admin.js\";\n\n// Structural typing of the confluent KafkaJS-compatible API surface so this\n// file compiles without the optional native dep installed.\ninterface CkProducer {\n connect(): Promise<void>;\n disconnect(): Promise<void>;\n send(args: unknown): Promise<unknown>;\n transaction(): Promise<CkTransaction>;\n}\ninterface CkTransaction {\n send(args: unknown): Promise<unknown>;\n commit(): Promise<void>;\n abort(): Promise<void>;\n}\ninterface CkKafka {\n producer(args?: unknown): CkProducer;\n admin(): CkAdmin;\n}\n// Structural shape of the confluent kafkaJS-compat admin client. The\n// surface mirrors kafkajs's so we can reuse the wrapper pattern.\ninterface CkAdmin {\n connect(): Promise<void>;\n disconnect(): Promise<void>;\n listTopics(): Promise<string[]>;\n fetchTopicMetadata(args: { topics: string[] }): Promise<{\n topics: Array<{\n name: string;\n partitions: Array<{\n partitionId: number;\n leader: number;\n replicas: number[];\n isr: number[];\n }>;\n }>;\n }>;\n createTopics(args: {\n topics: Array<{\n topic: string;\n numPartitions?: number;\n replicationFactor?: number;\n configEntries?: Array<{ name: string; value: string }>;\n }>;\n waitForLeaders?: boolean;\n }): Promise<boolean>;\n createPartitions(args: {\n topicPartitions: Array<{ topic: string; count: number }>;\n }): Promise<void>;\n}\n\nexport interface ConfluentDriverOptions\n extends KafkaConnectionConfig,\n ProducerBehaviorConfig {}\n\n/**\n * Driver backed by `@confluentinc/kafka-javascript` (librdkafka wrapper).\n * Higher throughput; uses the KafkaJS-compatible promisified API so the\n * adapter mirrors the kafkajs driver closely.\n */\nexport class ConfluentDriver implements KafkaDriver {\n readonly transactional: boolean;\n private producer: CkProducer | null = null;\n private readonly opts: ConfluentDriverOptions;\n\n constructor(opts: ConfluentDriverOptions) {\n this.opts = opts;\n this.transactional = opts.transactional ?? false;\n if (this.transactional && !opts.transactionalId) {\n throw new Error(\n \"ConfluentDriver: transactionalId is required when transactional=true\",\n );\n }\n }\n\n async connect(): Promise<void> {\n this.producer = await this.createProducer();\n await this.producer.connect();\n }\n\n /**\n * Construct the underlying confluent producer. Overridable as a test seam so\n * the send/transaction logic can be exercised without a real broker.\n */\n protected async createProducer(): Promise<CkProducer> {\n const mod = await importConfluent();\n const { kafkaJS, librdkafka } = buildConfluentClientConfig(this.opts);\n const kafka: CkKafka = new mod.KafkaJS.Kafka({\n kafkaJS,\n ...librdkafka,\n });\n // Resolve a callable transactionalId — async-safe so runtime context\n // (pod name, AZ index, k8s ordinal) can be derived at connect time.\n const resolvedTxId = this.transactional\n ? await resolveTransactionalId(this.opts.transactionalId)\n : undefined;\n return kafka.producer({\n kafkaJS: {\n idempotent: this.opts.idempotent ?? true,\n ...(resolvedTxId ? { transactionalId: resolvedTxId } : {}),\n },\n });\n }\n\n async disconnect(): Promise<void> {\n await this.producer?.disconnect();\n this.producer = null;\n }\n\n /**\n * Construct a librdkafka-backed admin client wrapped in the eventferry\n * `KafkaDriverAdmin` shape. The publisher's `connect()` is called before\n * the admin reaches the user.\n */\n async admin(): Promise<KafkaDriverAdmin> {\n const mod = await importConfluent();\n const { kafkaJS, librdkafka } = buildConfluentClientConfig(this.opts);\n const kafka: CkKafka = new mod.KafkaJS.Kafka({ kafkaJS, ...librdkafka });\n return new ConfluentAdmin(kafka.admin());\n }\n\n async sendBatch(messages: PublishableMessage[]): Promise<PublishResult[]> {\n if (!this.producer) throw new Error(\"ConfluentDriver not connected\");\n const topicMessages = groupByTopic(messages);\n const acks = this.opts.acks ?? -1;\n const compression = this.opts.compression;\n\n const doSends = async (target: CkProducer | CkTransaction) => {\n for (const tm of topicMessages) {\n await target.send({\n topic: tm.topic,\n messages: tm.messages,\n acks,\n ...(compression && compression !== \"none\" ? { compression } : {}),\n });\n }\n };\n\n if (this.transactional) {\n const txn = await this.producer.transaction();\n try {\n await doSends(txn);\n await txn.commit();\n return messages.map((m) => ({ recordId: m.recordId, ok: true }));\n } catch (err) {\n await txn.abort().catch(() => undefined);\n const error = err instanceof Error ? err : new Error(String(err));\n try {\n this.opts.onTransactionAbort?.(error);\n } catch {\n // swallow — abort hook is best-effort\n }\n return failedResults(messages, err);\n }\n }\n\n try {\n await doSends(this.producer);\n return messages.map((m) => ({ recordId: m.recordId, ok: true }));\n } catch (err) {\n return failedResults(messages, err);\n }\n }\n}\n\nfunction failedResults(\n messages: PublishableMessage[],\n err: unknown,\n): PublishResult[] {\n const error = err instanceof Error ? err : new Error(String(err));\n const errorKind = classifyConfluentError(err);\n return messages.map((m) => ({\n recordId: m.recordId,\n ok: false,\n error,\n errorKind,\n }));\n}\n\nfunction groupByTopic(messages: PublishableMessage[]) {\n const byTopic = new Map<string, unknown[]>();\n for (const m of messages) {\n const arr = byTopic.get(m.topic) ?? [];\n arr.push({\n key: m.key,\n value: m.value,\n headers: m.headers,\n // Per-message partition override. librdkafka honors an explicit\n // partition value; undefined leaves the default partitioner in charge.\n ...(m.partition !== undefined ? { partition: m.partition } : {}),\n });\n byTopic.set(m.topic, arr);\n }\n return [...byTopic.entries()].map(([topic, msgs]) => ({\n topic,\n messages: msgs,\n }));\n}\n\n/**\n * Adapt the confluent (librdkafka) admin client to the\n * {@link KafkaDriverAdmin} contract. Idempotent semantics mirror the\n * kafkajs admin wrapper.\n */\nclass ConfluentAdmin implements KafkaDriverAdmin {\n constructor(private readonly client: CkAdmin) {}\n\n async connect(): Promise<void> {\n await this.client.connect();\n }\n\n async close(): Promise<void> {\n await this.client.disconnect();\n }\n\n async listTopics(): Promise<string[]> {\n return await this.client.listTopics();\n }\n\n async describeTopics(topics: string[]): Promise<TopicMetadata[]> {\n if (topics.length === 0) return [];\n const all = new Set(await this.client.listTopics());\n const existing = topics.filter((t) => all.has(t));\n const missing = topics.filter((t) => !all.has(t));\n const meta = existing.length\n ? await this.client.fetchTopicMetadata({ topics: existing })\n : { topics: [] };\n const byName = new Map(meta.topics.map((t) => [t.name, t]));\n return topics.map((topic) => {\n if (missing.includes(topic)) return { topic, partitions: [] };\n const found = byName.get(topic);\n if (!found) return { topic, partitions: [] };\n return {\n topic,\n partitions: found.partitions.map((p) => ({\n partitionId: p.partitionId,\n leader: p.leader,\n replicas: p.replicas,\n isr: p.isr,\n })),\n };\n });\n }\n\n async createTopics(specs: TopicCreateSpec[]): Promise<void> {\n if (specs.length === 0) return;\n const topics = specs.map((s) => ({\n topic: s.topic,\n numPartitions: s.numPartitions,\n replicationFactor: s.replicationFactor,\n configEntries: s.configEntries\n ? Object.entries(s.configEntries).map(([name, value]) => ({ name, value }))\n : undefined,\n }));\n try {\n await this.client.createTopics({ topics, waitForLeaders: true });\n } catch (err) {\n // librdkafka raises a `code` numeric `36` for TOPIC_ALREADY_EXISTS;\n // the kafkaJS-compat layer mirrors the kafkajs error shape too.\n const e = err as { code?: number; name?: string; message?: string };\n if (e?.code === 36 || e?.name === \"TOPIC_ALREADY_EXISTS\") return;\n if (/already exists/i.test(e?.message ?? \"\")) return;\n throw err;\n }\n }\n\n async createPartitions(specs: PartitionGrowSpec[]): Promise<void> {\n if (specs.length === 0) return;\n await this.client.createPartitions({\n topicPartitions: specs.map((s) => ({\n topic: s.topic,\n count: s.totalCount,\n })),\n });\n }\n}\n\nasync function importConfluent(): Promise<{\n KafkaJS: { Kafka: new (cfg: unknown) => CkKafka };\n}> {\n try {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return (await import(\"@confluentinc/kafka-javascript\")) as any;\n } catch {\n throw new Error(\n 'Driver \"confluent\" selected but \"@confluentinc/kafka-javascript\" is not installed. Run: npm i @confluentinc/kafka-javascript',\n );\n }\n}\n","import type { PublishableMessage, PublishResult, Logger } from \"@eventferry/core\";\n\n/**\n * Lifecycle hooks fired by `KafkaPublisher`. Every hook is optional. The\n * publisher wraps each invocation in a try/catch and logs (via the\n * configured logger) on failure — a misbehaving hook will NEVER break\n * publishing.\n *\n * Typical wiring:\n * - Custom observability stacks (Datadog APM, New Relic) → `onPublish`,\n * `onError`, `onTransactionAbort`.\n * - Connection-aware readiness probes → `onConnect` / `onDisconnect`.\n * - Audit logs of every published record → `onPublish`.\n */\nexport interface KafkaPublisherHooks {\n /** Fires after the underlying client successfully connects. */\n onConnect?(): void | Promise<void>;\n /** Fires after the underlying client disconnects (clean shutdown). */\n onDisconnect?(): void | Promise<void>;\n /**\n * Fires once per record after a publish attempt — both successes and\n * failures. The `result.ok` flag distinguishes them.\n */\n onPublish?(\n result: PublishResult,\n message: PublishableMessage,\n ): void | Promise<void>;\n /**\n * Fires for any error surfaced from the publish path — driver-thrown\n * errors, transaction abort errors, etc. `message` is set when the error\n * is per-record; absent for batch-level errors (e.g. connect failure).\n */\n onError?(\n error: Error,\n message?: PublishableMessage,\n ): void | Promise<void>;\n /**\n * Fires when a transactional sendBatch's inner abort path is taken.\n * Useful for observability dashboards that track EOS failure rates.\n */\n onTransactionAbort?(error: Error): void | Promise<void>;\n /**\n * Fires when the broker fences this producer — the previous publish\n * batch reported at least one `errorKind: \"fenced\"` result. Receives\n * the first fenced `Error` so dashboards can attribute the incident.\n *\n * - When `autoRecoverFromFence` is on, this hook fires BEFORE the\n * transparent reconnect attempt. Use it to decrement a transactional\n * producer's leader-election counter or warn the operator.\n * - When `autoRecoverFromFence` is off, the publisher surfaces the\n * fenced result unchanged and the hook is still fired for visibility.\n */\n onProducerFenced?(error: Error): void | Promise<void>;\n}\n\n/**\n * Invoke a hook safely. Never throws back into the caller — logs the hook's\n * failure via the configured logger (or no-op when logger is absent).\n */\nexport async function safeHook(\n logger: Logger | undefined,\n hookName: keyof KafkaPublisherHooks,\n invoke: () => void | Promise<void> | undefined,\n): Promise<void> {\n try {\n const r = invoke();\n if (r && typeof (r as Promise<void>).then === \"function\") {\n await r;\n }\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n logger?.warn(`[@eventferry/kafka] hook ${hookName} threw; ignored`, {\n error: error.message,\n });\n }\n}\n","/**\n * Tracing surface for the publisher.\n *\n * eventferry deliberately does not depend on `@opentelemetry/api` — instead\n * users wire a thin adapter over their tracing system (OpenTelemetry,\n * Datadog, internal, …). This file defines the minimal contract; an\n * OpenTelemetry adapter is ~10 lines (see the README).\n *\n * The contract follows the **current stable** OpenTelemetry messaging\n * semantic conventions\n * ({@link https://github.com/open-telemetry/semantic-conventions/blob/main/docs/messaging/kafka.md spec}):\n *\n * - Span name: `\"{topic} publish\"`\n * - `SpanKind.PRODUCER`\n * - Required attributes: `messaging.system=kafka`,\n * `messaging.operation.type=publish`, `messaging.destination.name=<topic>`\n * - Recommended: `messaging.batch.message_count`, `messaging.kafka.partition`,\n * `server.address`, `server.port`\n * - One span per batch (NOT per message — per-message spans cause\n * cardinality explosion and the spec actively warns against this)\n */\n\n/** Attribute values the spec allows. */\nexport type SpanAttributeValue = string | number | boolean;\n\n/**\n * Minimal span surface the publisher needs. Implementations wrap a\n * tracing-system-specific span; methods MUST never throw out of the\n * publisher's hot path (wrap your own SDK calls in try/catch).\n */\nexport interface SpanLike {\n setAttribute(key: string, value: SpanAttributeValue): void;\n setAttributes(attrs: Record<string, SpanAttributeValue>): void;\n /** OK on success; ERROR on failure. The `message` is the error message. */\n setStatus(status: { code: \"ok\" | \"error\"; message?: string }): void;\n /** Attach an exception to the span (OpenTelemetry `recordException`). */\n recordException(error: Error): void;\n end(): void;\n}\n\n/**\n * Factory the publisher calls once per `sendBatch` to start a span.\n * Implementations MUST set `SpanKind.PRODUCER` and the messaging semconv\n * attributes on the returned span before returning it.\n */\nexport interface KafkaTracer {\n /**\n * Start a publish span.\n * @param name Recommended format: `\"{topic} publish\"`.\n * @param attributes Initial attributes (the publisher supplies the messaging\n * semconv set: system, destination.name, operation.type,\n * batch.message_count, plus optional kafka.partition and\n * server.address/port).\n */\n startPublishSpan(\n name: string,\n attributes: Record<string, SpanAttributeValue>,\n ): SpanLike;\n\n /**\n * OPTIONAL: inject the active trace context (W3C `traceparent` +\n * `tracestate`) into a per-message header map. Called by the publisher\n * AFTER the batch span is created and BEFORE the records hit the wire.\n *\n * Implementations typically wrap OpenTelemetry's `propagation.inject(...)`\n * or your tracing SDK's equivalent. Mutate the `headers` object in\n * place — the publisher allocates a fresh copy per message so this is\n * safe and matches the propagation API of every major SDK.\n *\n * Tracers without distributed-context propagation (or that only care\n * about local spans) may leave this off — consumers can still derive\n * trace headers themselves by other means.\n */\n inject?(span: SpanLike, headers: Record<string, string>): void;\n}\n\n/**\n * No-op tracer. Used when the user does not configure one. Cheap allocation\n * — never touches I/O.\n */\nexport class NoopKafkaTracer implements KafkaTracer {\n startPublishSpan(): SpanLike {\n return NOOP_SPAN;\n }\n}\n\nconst NOOP_SPAN: SpanLike = {\n setAttribute() {},\n setAttributes() {},\n setStatus() {},\n recordException() {},\n end() {},\n};\n","import type {\n Logger,\n PublishableMessage,\n Publisher,\n PublishResult,\n} from \"@eventferry/core\";\nimport { ConfluentDriver } from \"./confluent-driver.js\";\nimport type {\n DriverKind,\n KafkaConnectionConfig,\n KafkaDriver,\n ProducerBehaviorConfig,\n} from \"./driver.js\";\nimport { KafkaJsDriver } from \"./kafkajs-driver.js\";\nimport { safeHook } from \"./hooks.js\";\nimport type { KafkaPublisherHooks } from \"./hooks.js\";\nimport { NoopKafkaTracer } from \"./tracing.js\";\nimport type { KafkaTracer, SpanLike } from \"./tracing.js\";\nimport type {\n KafkaAdmin,\n KafkaDriverAdmin,\n PartitionGrowSpec,\n TopicCreateSpec,\n} from \"./admin.js\";\n\nexport interface KafkaPublisherOptions\n extends KafkaConnectionConfig,\n ProducerBehaviorConfig {\n /** Which underlying client to use. Default \"kafkajs\". */\n driver?: DriverKind;\n /**\n * Provide a fully custom driver instance instead of the built-ins.\n * Useful for testing or unsupported clients.\n */\n customDriver?: KafkaDriver;\n /**\n * Optional structured logger. When set, the publisher routes its own\n * diagnostics (driver warnings, hook failures) through it. When omitted,\n * the publisher is silent — only the underlying drivers may still log.\n */\n logger?: Logger;\n /**\n * Optional lifecycle hooks. Every hook is invoked safely (try/catch +\n * logged via `logger`) and a misbehaving hook will never break publishing.\n */\n hooks?: KafkaPublisherHooks;\n /**\n * Optional tracer. When set, `publish()` wraps each batch in a span that\n * follows the current stable OpenTelemetry messaging semantic conventions.\n * Use a thin adapter over your tracing SDK (see {@link KafkaTracer}).\n */\n tracer?: KafkaTracer;\n /**\n * If set, `connect()` checks that every topic in this list exists on the\n * cluster and throws a descriptive error if any are missing. Use this to\n * fail-fast at startup instead of letting the first send-time error\n * surprise you.\n *\n * Validation runs AFTER the producer connects but BEFORE `onConnect` hooks\n * fire. Driver must implement `admin()` (the built-ins do).\n */\n validateTopicsOnConnect?: string[];\n /**\n * Transparently recover from a producer-fence error. When set to `true`,\n * a `publish()` call whose batch comes back with at least one\n * `errorKind: \"fenced\"` result triggers ONE round of:\n *\n * 1. disconnect the driver\n * 2. connect it again (re-running `initTransactions` for transactional producers)\n * 3. re-send the same batch\n *\n * If the second send still produces a fenced result, the publisher gives\n * up and surfaces the failures unchanged — at that point the fence is\n * almost certainly caused by another instance taking the same\n * `transactionalId`, and silently retrying again would mask the\n * misconfiguration.\n *\n * Default `false` to preserve the previous \"fenced → fatal\" semantics.\n * Turn it on when running a single producer instance against transient\n * brokers (rolling restarts, network blips) where a fence is usually\n * just a transient epoch mismatch.\n *\n * For MULTI-INSTANCE EOS, leave this OFF and use a callable\n * `transactionalId` derived from per-instance context (pod name, k8s\n * ordinal, AZ + replica index) so each instance has a stable, unique\n * id — fences will then correctly stop the loser instance.\n */\n autoRecoverFromFence?: boolean;\n}\n\n/**\n * The Publisher the Relay talks to. Wraps a pluggable KafkaDriver and adds\n * dead-letter routing, observability hooks, and OpenTelemetry-shaped publish\n * spans. Works against Kafka and Redpanda identically (Redpanda is Kafka-API\n * compatible).\n */\nexport class KafkaPublisher implements Publisher {\n private readonly driver: KafkaDriver;\n private readonly logger: Logger | undefined;\n private readonly hooks: KafkaPublisherHooks;\n private readonly tracer: KafkaTracer;\n private readonly validateTopicsOnConnect: readonly string[] | undefined;\n private readonly autoRecoverFromFence: boolean;\n // Serialize reconnects so concurrent publish() calls hitting a fence\n // all observe the same single reconnect attempt — the second publish\n // doesn't try to disconnect a producer the first is still re-initing.\n private fenceRecovery: Promise<void> | null = null;\n\n constructor(opts: KafkaPublisherOptions) {\n this.logger = opts.logger;\n this.hooks = opts.hooks ?? {};\n this.tracer = opts.tracer ?? new NoopKafkaTracer();\n this.validateTopicsOnConnect = opts.validateTopicsOnConnect\n ? Object.freeze([...opts.validateTopicsOnConnect])\n : undefined;\n this.autoRecoverFromFence = opts.autoRecoverFromFence ?? false;\n // Plumb the logger into driver construction so driver-side diagnostics\n // (e.g. kafkajs unsupported-tuning warnings) route through it too.\n // Plumb a safe-wrapped onTransactionAbort callback so the driver-level\n // transaction abort path fans out to the user-supplied hook safely.\n const onTransactionAbort = this.hooks.onTransactionAbort\n ? (error: Error) => {\n void safeHook(this.logger, \"onTransactionAbort\", () =>\n this.hooks.onTransactionAbort?.(error),\n );\n }\n : undefined;\n this.driver =\n opts.customDriver ?? selectDriver({ ...opts, onTransactionAbort });\n }\n\n async connect(): Promise<void> {\n await this.driver.connect();\n if (this.validateTopicsOnConnect && this.validateTopicsOnConnect.length) {\n await this.assertTopicsExist(this.validateTopicsOnConnect);\n }\n await safeHook(this.logger, \"onConnect\", () => this.hooks.onConnect?.());\n }\n\n /**\n * Borrow a new admin client from the driver. The returned admin is\n * connected and ready to use; the CALLER must `close()` it. Throws if the\n * driver does not implement admin (custom driver lacking the capability).\n */\n async admin(): Promise<KafkaAdmin> {\n const driverAdmin = await this.openDriverAdmin();\n return driverAdmin;\n }\n\n /**\n * Idempotently provision topics. Each spec creates the topic if absent;\n * existing topics are skipped without error. If `growPartitions: true`\n * (default false), topics whose current partition count is below the\n * requested `numPartitions` are grown via `createPartitions`.\n *\n * Replication factor and config entries on EXISTING topics are NOT\n * reconciled — Kafka does not provide a safe in-place alter for those\n * (changing replication requires reassignment; configs use alterConfigs).\n * Reach for the raw admin if you need that.\n */\n async ensureTopics(\n specs: TopicCreateSpec[],\n opts: { growPartitions?: boolean } = {},\n ): Promise<void> {\n if (specs.length === 0) return;\n const admin = await this.openDriverAdmin();\n try {\n const topicNames = specs.map((s) => s.topic);\n const existing = await admin.describeTopics(topicNames);\n const existingByName = new Map(existing.map((t) => [t.topic, t]));\n\n const toCreate = specs.filter(\n (s) => (existingByName.get(s.topic)?.partitions.length ?? 0) === 0,\n );\n if (toCreate.length) await admin.createTopics(toCreate);\n\n if (opts.growPartitions) {\n const grow: PartitionGrowSpec[] = [];\n for (const s of specs) {\n if (s.numPartitions === undefined) continue;\n const current = existingByName.get(s.topic);\n const currentCount = current?.partitions.length ?? 0;\n if (currentCount > 0 && currentCount < s.numPartitions) {\n grow.push({ topic: s.topic, totalCount: s.numPartitions });\n }\n }\n if (grow.length) await admin.createPartitions(grow);\n }\n } finally {\n await admin.close();\n }\n }\n\n /**\n * Borrow a fresh admin from the driver and connect it. Throws when the\n * driver does not implement admin (custom drivers without that capability).\n */\n private async openDriverAdmin(): Promise<KafkaDriverAdmin> {\n if (!this.driver.admin) {\n throw new Error(\n \"KafkaPublisher: configured driver does not implement admin(). \" +\n \"Use the built-in kafkajs or confluent driver, or extend your custom driver.\",\n );\n }\n const admin = await this.driver.admin();\n await admin.connect();\n return admin;\n }\n\n /**\n * Open an admin, list topics, throw if any required topic is missing.\n * Always closes the admin (success or failure).\n */\n private async assertTopicsExist(required: readonly string[]): Promise<void> {\n const admin = await this.openDriverAdmin();\n try {\n const all = new Set(await admin.listTopics());\n const missing = required.filter((t) => !all.has(t));\n if (missing.length) {\n throw new Error(\n `KafkaPublisher: validateTopicsOnConnect failed — topics missing on cluster: ${missing.join(\", \")}`,\n );\n }\n } finally {\n await admin.close();\n }\n }\n\n async disconnect(): Promise<void> {\n await this.driver.disconnect();\n await safeHook(this.logger, \"onDisconnect\", () =>\n this.hooks.onDisconnect?.(),\n );\n }\n\n async publish(messages: PublishableMessage[]): Promise<PublishResult[]> {\n if (messages.length === 0) return [];\n\n const span = this.startBatchSpan(messages);\n // If the tracer can inject trace context (W3C `traceparent`/`tracestate`\n // is the common case), clone each message and let the tracer enrich its\n // headers. We MUST NOT mutate the caller's PublishableMessage objects —\n // the relay reuses the same record reference across retries and any\n // mutation would corrupt later attempts.\n const outgoing: PublishableMessage[] = this.tracer.inject\n ? messages.map((m) => {\n const headers = { ...m.headers };\n this.tracer.inject!(span, headers);\n return { ...m, headers };\n })\n : messages;\n let results: PublishResult[];\n try {\n results = await this.driver.sendBatch(outgoing);\n } catch (err) {\n // Driver-level throw — every record is a failure attributed to the\n // batch-level error. Record on the span, fire hook, rethrow.\n const error = err instanceof Error ? err : new Error(String(err));\n span.setStatus({ code: \"error\", message: error.message });\n span.recordException(error);\n span.end();\n await safeHook(this.logger, \"onError\", () => this.hooks.onError?.(error));\n throw err;\n }\n\n // Fence detection + transparent single-shot recovery. Runs BEFORE the\n // per-record hooks so observers see a clean \"all ok\" path when the\n // retry succeeds — they only see the fence error if the second attempt\n // also fails. Fires the onProducerFenced hook regardless of whether\n // auto-recovery is enabled (informational signal).\n const firstFenced = results.find(\n (r) => !r.ok && r.errorKind === \"fenced\",\n );\n if (firstFenced) {\n const fenceErr = firstFenced.error ?? new Error(\"producer fenced\");\n await safeHook(this.logger, \"onProducerFenced\", () =>\n this.hooks.onProducerFenced?.(fenceErr),\n );\n if (this.autoRecoverFromFence) {\n results = await this.recoverAndRetry(outgoing, results);\n }\n }\n\n // Per-record hooks. Walk by index so the original message is available.\n const byId = new Map(messages.map((m) => [m.recordId, m]));\n let allOk = true;\n for (const r of results) {\n const msg = byId.get(r.recordId);\n if (!msg) continue;\n await safeHook(this.logger, \"onPublish\", () =>\n this.hooks.onPublish?.(r, msg),\n );\n if (!r.ok) {\n allOk = false;\n const err = r.error ?? new Error(\"publish failed\");\n await safeHook(this.logger, \"onError\", () =>\n this.hooks.onError?.(err, msg),\n );\n }\n }\n\n span.setStatus(allOk ? { code: \"ok\" } : { code: \"error\" });\n span.end();\n return results;\n }\n\n /**\n * Send a single dead-lettered message. The message already carries the\n * DLQ topic (the Relay rewrites it), plus the failure reason as a header.\n */\n async publishToDlq(message: PublishableMessage, error: Error): Promise<void> {\n const dlqMessage: PublishableMessage = {\n ...message,\n headers: {\n ...message.headers,\n \"dlq-reason\": error.message,\n // Error class name (e.g. \"KafkaJSProtocolError\", \"RecordTooLargeException\"),\n // useful for downstream alert routing without parsing the reason string.\n \"dlq-error-class\": error.name || error.constructor?.name || \"Error\",\n \"dlq-original-topic\": message.headers[\"original-topic\"] ?? \"\",\n \"dlq-failed-at\": new Date().toISOString(),\n },\n };\n const [result] = await this.driver.sendBatch([dlqMessage]);\n if (result && !result.ok) {\n throw result.error ?? new Error(\"DLQ publish failed\");\n }\n }\n\n /** Whether the configured driver provides atomic (EOS) batch sends. */\n get transactional(): boolean {\n return this.driver.transactional;\n }\n\n /**\n * Cheap reachability probe. Borrows a fresh admin client, calls\n * `listTopics`, and returns timing + outcome. Useful as the body of a\n * `/healthz` or `/readyz` endpoint — proves the broker is reachable\n * AND that the configured credentials still authenticate against it,\n * without writing a record.\n *\n * Does NOT exercise the producer's send path — a healthy admin\n * connection doesn't guarantee `publish()` will succeed (a fenced\n * transactional producer would still answer healthy here). Treat this\n * as \"broker reachable + auth still good\", not \"publisher is fully\n * operational\".\n *\n * Default timeout 5_000 ms — long enough to ride out a single broker\n * leader election, short enough to fail a liveness probe meaningfully.\n * Set `timeoutMs: 0` to disable the timer entirely.\n *\n * The driver must implement `admin()` (the built-ins do); custom\n * drivers without admin get `{ ok: false, error: ... }` instead of\n * the throw `publisher.admin()` would surface — health checks are\n * not the place to crash.\n */\n async healthCheck(opts: { timeoutMs?: number } = {}): Promise<HealthStatus> {\n const timeoutMs = opts.timeoutMs ?? 5_000;\n const startedAt = Date.now();\n if (!this.driver.admin) {\n return {\n ok: false,\n latencyMs: 0,\n timestamp: startedAt,\n error: new Error(\n \"KafkaPublisher.healthCheck: configured driver does not implement admin()\",\n ),\n };\n }\n let admin: KafkaDriverAdmin | null = null;\n try {\n admin = await this.driver.admin();\n await admin.connect();\n const probe = admin.listTopics();\n // Race the probe against the timeout so a hung admin can't pin the\n // health check indefinitely. `timeoutMs: 0` opts out cleanly.\n if (timeoutMs > 0) {\n await raceWithTimeout(probe, timeoutMs, \"healthCheck\");\n } else {\n await probe;\n }\n return {\n ok: true,\n latencyMs: Date.now() - startedAt,\n timestamp: startedAt,\n };\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n return {\n ok: false,\n latencyMs: Date.now() - startedAt,\n timestamp: startedAt,\n error,\n };\n } finally {\n // Best-effort close; admin already lost is fine, swallow.\n try {\n await admin?.close();\n } catch {\n // ignore\n }\n }\n }\n\n /**\n * Disconnect + re-connect the driver and re-send the batch ONCE. Used\n * by the fence-recovery path. Concurrent fence recoveries dedupe on a\n * shared in-flight promise (`fenceRecovery`) so we don't tear the\n * producer down while another batch is mid-restart.\n *\n * If the second send STILL reports any fenced records, those failures\n * are returned unchanged — another instance has almost certainly taken\n * the same `transactionalId` and silently retrying again would mask\n * the misconfiguration.\n */\n private async recoverAndRetry(\n outgoing: PublishableMessage[],\n firstResults: PublishResult[],\n ): Promise<PublishResult[]> {\n if (!this.fenceRecovery) {\n this.fenceRecovery = (async () => {\n try {\n await this.driver.disconnect();\n await this.driver.connect();\n } finally {\n // Clear the slot so a SUBSEQUENT fence can attempt recovery\n // again — recoveries are per-incident, not per-process.\n this.fenceRecovery = null;\n }\n })();\n }\n try {\n await this.fenceRecovery;\n } catch (err) {\n // Reconnect itself failed — surface the original fence result so\n // the relay can DLQ + alert. The reconnect error is informational.\n const reconnectErr =\n err instanceof Error ? err : new Error(String(err));\n await safeHook(this.logger, \"onError\", () =>\n this.hooks.onError?.(reconnectErr),\n );\n return firstResults;\n }\n try {\n return await this.driver.sendBatch(outgoing);\n } catch {\n // Driver threw on the second attempt — surface original fence results.\n return firstResults;\n }\n }\n\n /**\n * Start a span for the batch following the OTel messaging conventions.\n *\n * Multi-topic batches: per the OTel spec, the span name uses the\n * destination — we pick the FIRST topic in the batch and document the\n * limitation. Callers that publish heterogeneous batches and care about\n * per-topic spans should split their batches upstream.\n */\n private startBatchSpan(messages: PublishableMessage[]): SpanLike {\n const topic = messages[0]?.topic ?? \"unknown\";\n return this.tracer.startPublishSpan(`${topic} publish`, {\n \"messaging.system\": \"kafka\",\n \"messaging.operation.type\": \"publish\",\n \"messaging.destination.name\": topic,\n \"messaging.batch.message_count\": messages.length,\n });\n }\n}\n\n/**\n * Outcome of a {@link KafkaPublisher.healthCheck} call. Shape is stable\n * and small so consumers (HTTP /healthz, k8s probes, Datadog) can\n * marshal it without a translation layer.\n */\nexport interface HealthStatus {\n /** True when the broker answered within the timeout window. */\n ok: boolean;\n /** Wall-clock milliseconds spent on the probe (admin connect + listTopics). */\n latencyMs: number;\n /** Epoch ms when the probe started — handy for log correlation. */\n timestamp: number;\n /** Present only when `ok === false`. The classified error, untouched. */\n error?: Error;\n}\n\n/**\n * Resolve when `p` resolves; reject with a labelled `TimeoutError` if\n * the timer fires first. The original promise keeps running — we cannot\n * cancel an in-flight admin call from here — but its outcome is\n * ignored by the caller. The unref keeps the timer from holding the\n * Node event loop open in CLI contexts.\n */\nfunction raceWithTimeout<T>(\n p: Promise<T>,\n ms: number,\n label: string,\n): Promise<T> {\n return new Promise((resolve, reject) => {\n const timer = setTimeout(() => {\n reject(new Error(`${label} timed out after ${ms}ms`));\n }, ms);\n if (typeof (timer as { unref?: () => void }).unref === \"function\") {\n (timer as { unref: () => void }).unref();\n }\n p.then(\n (v) => {\n clearTimeout(timer);\n resolve(v);\n },\n (e) => {\n clearTimeout(timer);\n reject(e);\n },\n );\n });\n}\n\nfunction selectDriver(opts: KafkaPublisherOptions): KafkaDriver {\n const kind = opts.driver ?? \"kafkajs\";\n switch (kind) {\n case \"kafkajs\":\n return new KafkaJsDriver(opts);\n case \"confluent\":\n return new ConfluentDriver(opts);\n default:\n throw new Error(`Unknown driver \"${kind}\"`);\n }\n}\n"],"mappings":";AAiBO,SAAS,qBAAqB,KAAgC;AACnE,MAAI,CAAC,OAAO,OAAO,QAAQ,SAAU,QAAO;AA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AAI,CAAC;AAAA,IACtD,GAAG,EAAE;AACL,QAAI,OAAQ,MAAiC,UAAU,YAAY;AACjE,MAAC,MAAgC,MAAM;AAAA,IACzC;AACA,MAAE;AAAA,MACA,CAAC,MAAM;AACL,qBAAa,KAAK;AAClB,gBAAQ,CAAC;AAAA,MACX;AAAA,MACA,CAAC,MAAM;AACL,qBAAa,KAAK;AAClB,eAAO,CAAC;AAAA,MACV;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAEA,SAAS,aAAa,MAA0C;AAC9D,QAAM,OAAO,KAAK,UAAU;AAC5B,UAAQ,MAAM;AAAA,IACZ,KAAK;AACH,aAAO,IAAI,cAAc,IAAI;AAAA,IAC/B,KAAK;AACH,aAAO,IAAI,gBAAgB,IAAI;AAAA,IACjC;AACE,YAAM,IAAI,MAAM,mBAAmB,IAAI,GAAG;AAAA,EAC9C;AACF;","names":["CODE_TO_KIND","groupByTopic","failedResults"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eventferry/kafka",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "Kafka/Redpanda publisher for @eventferry (kafkajs + confluent drivers)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -11,12 +11,20 @@
|
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
12
12
|
"import": "./dist/index.js",
|
|
13
13
|
"require": "./dist/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./consume": {
|
|
16
|
+
"types": "./dist/consume.d.ts",
|
|
17
|
+
"import": "./dist/consume.js",
|
|
18
|
+
"require": "./dist/consume.cjs"
|
|
14
19
|
}
|
|
15
20
|
},
|
|
16
21
|
"files": [
|
|
17
22
|
"dist",
|
|
18
23
|
"CHANGELOG.md"
|
|
19
24
|
],
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
20
28
|
"keywords": [
|
|
21
29
|
"outbox",
|
|
22
30
|
"outbox-pattern",
|
|
@@ -48,7 +56,7 @@
|
|
|
48
56
|
"node": ">=18"
|
|
49
57
|
},
|
|
50
58
|
"dependencies": {
|
|
51
|
-
"@eventferry/core": "3.
|
|
59
|
+
"@eventferry/core": "3.4.0"
|
|
52
60
|
},
|
|
53
61
|
"peerDependencies": {
|
|
54
62
|
"kafkajs": "^2.0.0",
|
|
@@ -66,8 +74,8 @@
|
|
|
66
74
|
"kafkajs": "^2.2.4",
|
|
67
75
|
"tsup": "^8.3.5",
|
|
68
76
|
"typescript": "^5.7.2",
|
|
69
|
-
"vitest": "^2.
|
|
70
|
-
"@eventferry/core": "3.
|
|
77
|
+
"vitest": "^3.2.6",
|
|
78
|
+
"@eventferry/core": "3.4.0"
|
|
71
79
|
},
|
|
72
80
|
"scripts": {
|
|
73
81
|
"build": "tsup",
|