@horizon-republic/nestjs-jetstream 2.11.0 → 2.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -553,9 +553,13 @@ declare class JetstreamClient extends ClientProxy {
553
553
  * uses a separate `_sch` namespace that is NOT matched by any consumer filter.
554
554
  * NATS holds the message and publishes it to the target subject after the delay.
555
555
  *
556
+ * A unique per-message suffix is appended because the server stores schedules
557
+ * as rollup messages — one active schedule per subject (ADR-51). Without it,
558
+ * concurrent schedules of the same pattern would silently replace each other.
559
+ *
556
560
  * Examples:
557
- * - `{svc}__microservice.ev.order.reminder` → `{svc}__microservice._sch.order.reminder`
558
- * - `broadcast.config.updated` → `broadcast._sch.config.updated`
561
+ * - `{svc}__microservice.ev.order.reminder` → `{svc}__microservice._sch.order.reminder.<nuid>`
562
+ * - `broadcast.config.updated` → `broadcast._sch.config.updated.<nuid>`
559
563
  */
560
564
  private buildScheduleSubject;
561
565
  }
@@ -935,6 +939,8 @@ interface OtelOptions {
935
939
  errorClassifier?(err: unknown): ErrorClassification;
936
940
  }
937
941
 
942
+ type ProvisioningEntity = 'stream' | 'consumer';
943
+
938
944
  /**
939
945
  * Stream config overrides exposed to users.
940
946
  *
@@ -1073,6 +1079,14 @@ interface MetadataRegistryOptions {
1073
1079
  */
1074
1080
  ttl?: number;
1075
1081
  }
1082
+ /** Provisioning behavior. Stream reservations are always logged at boot (INFO). */
1083
+ interface ProvisioningOptions {
1084
+ /**
1085
+ * Opt-in storage budget check via `getAccountInfo()` before provisioning.
1086
+ * Warn-only; never blocks boot. Off by default.
1087
+ */
1088
+ preflightStorageCheck?: boolean;
1089
+ }
1076
1090
  /**
1077
1091
  * Root module configuration for `JetstreamModule.forRoot()`.
1078
1092
  *
@@ -1234,9 +1248,14 @@ interface JetstreamModuleOptions {
1234
1248
  * consuming application, all tracer calls are no-ops — there is no
1235
1249
  * runtime cost.
1236
1250
  *
1251
+ * Accepts a full {@link OtelOptions} object, or the boolean shorthand
1252
+ * `true` (== defaults) / `false` (== `{ enabled: false }`).
1253
+ *
1237
1254
  * @see OtelOptions
1238
1255
  */
1239
- otel?: OtelOptions;
1256
+ otel?: OtelOptions | boolean;
1257
+ /** Provisioning behavior. */
1258
+ provisioning?: ProvisioningOptions;
1240
1259
  }
1241
1260
  /** Options for `JetstreamModule.forFeature()`. */
1242
1261
  interface JetstreamFeatureOptions {
@@ -1258,15 +1277,6 @@ type JetstreamModuleAsyncOptions = {
1258
1277
  name: string;
1259
1278
  /** Additional module imports (e.g., ConfigModule). */
1260
1279
  imports?: ModuleMetadata['imports'];
1261
- /**
1262
- * Built-in Prometheus metrics. Specified at the async-options level (parallel
1263
- * to {@link name}) because module composition is decided synchronously before
1264
- * the async factory runs. Use `true` for defaults, a {@link MetricsConfig}
1265
- * object for full control, or omit/`false` to disable entirely.
1266
- *
1267
- * @see JetstreamModuleOptions.metrics
1268
- */
1269
- metrics?: MetricsOption;
1270
1280
  } & ({
1271
1281
  useFactory(...args: unknown[]): Promise<Omit<JetstreamModuleOptions, 'name'>> | Omit<JetstreamModuleOptions, 'name'>;
1272
1282
  inject?: FactoryProvider['inject'];
@@ -1319,8 +1329,11 @@ interface DeadLetterConfig {
1319
1329
  * Used to detect when a message from a given stream has exhausted all delivery attempts.
1320
1330
  */
1321
1331
  maxDeliverByStream: Map<string, number>;
1322
- /** Async callback invoked when a message exhausts all deliveries. */
1323
- onDeadLetter(info: DeadLetterInfo): Promise<void>;
1332
+ /**
1333
+ * Async callback invoked when a message exhausts all deliveries.
1334
+ * Optional: in dlq-only mode dead letters go to the DLQ stream without a callback.
1335
+ */
1336
+ onDeadLetter?(info: DeadLetterInfo): Promise<void>;
1324
1337
  }
1325
1338
  /** Options for configuring RPC processing behavior. */
1326
1339
  interface RpcRouterOptions {
@@ -1461,6 +1474,11 @@ declare class StreamProvider {
1461
1474
  private handleExistingStream;
1462
1475
  private buildMutableOnlyConfig;
1463
1476
  private logChanges;
1477
+ private buildReservation;
1478
+ private errorContext;
1479
+ private runStreamOp;
1480
+ /** The broadcast stream is global — every service in the cluster shares it. */
1481
+ private isSharedStream;
1464
1482
  /** Build the full stream config by merging defaults with user overrides. */
1465
1483
  private buildConfig;
1466
1484
  /**
@@ -1515,11 +1533,28 @@ declare class EventRouter {
1515
1533
  private getAckExtensionConfig;
1516
1534
  /**
1517
1535
  * Last-resort path for a dead letter: invoke `onDeadLetter`, then `term` on
1518
- * success or `nak` on hook failure so NATS retries on the next delivery
1519
- * cycle. Used when DLQ stream isn't configured, or when publishing to it
1520
- * failed and we still have to surface the message somewhere observable.
1536
+ * success. On failure the message is nak'd to release it, but the server
1537
+ * never redelivers past `max_deliver` it stays in the stream for manual
1538
+ * recovery. Used when the DLQ stream isn't configured, or when publishing
1539
+ * to it failed and we still have to surface the message somewhere.
1521
1540
  */
1522
1541
  private fallbackToOnDeadLetterCallback;
1542
+ /**
1543
+ * Copy the original message headers for the DLQ republish, dropping NATS
1544
+ * server control headers: a copied Nats-TTL expires the DLQ entry (or gets
1545
+ * the publish rejected when the DLQ stream has no allow_msg_ttl), a copied
1546
+ * Nats-Msg-Id collides with the DLQ dedup window.
1547
+ */
1548
+ private buildDlqHeaders;
1549
+ /**
1550
+ * Attempt the DLQ publish up to {@link DLQ_PUBLISH_ATTEMPTS} times.
1551
+ *
1552
+ * Past `max_deliver` the server never redelivers, so an in-process retry is
1553
+ * the only second chance a dead letter gets. There is no artificial delay
1554
+ * between attempts: when the broker is unreachable each publish already
1555
+ * spends its own request timeout, which spaces the attempts naturally.
1556
+ */
1557
+ private publishToDlqWithRetry;
1523
1558
  /**
1524
1559
  * Publish a dead letter to the configured Dead-Letter Queue (DLQ) stream.
1525
1560
  *
@@ -1630,6 +1665,7 @@ declare class ConsumerProvider {
1630
1665
  * Create a consumer, handling the race where another pod creates it first.
1631
1666
  */
1632
1667
  private createConsumer;
1668
+ private runConsumerOp;
1633
1669
  /** Build consumer config by merging defaults with user overrides. */
1634
1670
  private buildConfig;
1635
1671
  /** Get default config for a consumer kind. */
@@ -1771,7 +1807,7 @@ declare class MetadataProvider {
1771
1807
  * NATS JetStream API error codes used by the transport.
1772
1808
  *
1773
1809
  * Ref: https://github.com/nats-io/nats-server (server error definitions)
1774
- * Verified on NATS 2.12.6 via integration tests (2026-04-02).
1810
+ * Codes verified across NATS 2.12.6–2.14.1 via integration tests (original codes: 2026-04-02).
1775
1811
  */
1776
1812
  declare enum NatsErrorCode {
1777
1813
  /** Consumer does not exist on the specified stream. */
@@ -1779,7 +1815,14 @@ declare enum NatsErrorCode {
1779
1815
  /** Consumer name already in use with different configuration (race condition on create). */
1780
1816
  ConsumerAlreadyExists = 10148,
1781
1817
  /** Stream does not exist. */
1782
- StreamNotFound = 10059
1818
+ StreamNotFound = 10059,
1819
+ /** Storage resources exceeded — reservation exceeds server `max_file_store`. */
1820
+ StorageResourcesExceeded = 10047,
1821
+ /**
1822
+ * No suitable peers for placement (fewer healthy peers than `num_replicas`,
1823
+ * or no peer has storage headroom). Confirmed at runtime by the cluster integration test.
1824
+ */
1825
+ NoSuitablePeers = 10005
1783
1826
  }
1784
1827
 
1785
1828
  /**
@@ -1814,7 +1857,7 @@ declare class JetstreamStrategy extends Server implements CustomTransportStrateg
1814
1857
  *
1815
1858
  * Called by NestJS when `connectMicroservice()` is used, or internally by the module.
1816
1859
  */
1817
- listen(callback: () => void): Promise<void>;
1860
+ listen(callback: (...args: unknown[]) => void): Promise<void>;
1818
1861
  /** Stop all consumers, routers, subscriptions, and metadata heartbeat. Called during shutdown. */
1819
1862
  close(): void;
1820
1863
  /**
@@ -1844,9 +1887,13 @@ declare class JetstreamStrategy extends Server implements CustomTransportStrateg
1844
1887
  unwrap<T>(): T;
1845
1888
  /** Access the pattern registry (for module-level introspection). */
1846
1889
  getPatternRegistry(): PatternRegistry;
1890
+ private doListen;
1847
1891
  /** Determine which streams and durable consumers are needed. */
1848
1892
  private resolveRequiredKinds;
1849
- /** Populate the shared ack_wait map from actual NATS consumer configs. */
1893
+ /** Subscribe the event and RPC routers to the message subjects. */
1894
+ private startRouters;
1895
+ /** Begin durable and ordered consumption; routers must already be subscribed. */
1896
+ private startConsumption;
1850
1897
  private populateAckWaitMap;
1851
1898
  /** Build max_deliver map from actual NATS consumer configs (not options). */
1852
1899
  private buildMaxDeliverMap;
@@ -2353,4 +2400,30 @@ declare const isJetStreamRpcMode: (rpc: RpcConfig | undefined) => boolean;
2353
2400
  /** Check if the RPC config specifies Core mode (default). */
2354
2401
  declare const isCoreRpcMode: (rpc: RpcConfig | undefined) => boolean;
2355
2402
 
2356
- export { type CaptureBodyOptions, type Codec, ConsumeKind, type ConsumeSourceMsg, DEFAULT_BROADCAST_CONSUMER_CONFIG, DEFAULT_BROADCAST_STREAM_CONFIG, DEFAULT_COMMAND_CONSUMER_CONFIG, DEFAULT_COMMAND_STREAM_CONFIG, DEFAULT_DLQ_STREAM_CONFIG, DEFAULT_EVENT_CONSUMER_CONFIG, DEFAULT_EVENT_STREAM_CONFIG, DEFAULT_JETSTREAM_RPC_TIMEOUT, DEFAULT_METADATA_BUCKET, DEFAULT_METADATA_HISTORY, DEFAULT_METADATA_REPLICAS, DEFAULT_METADATA_TTL, DEFAULT_ORDERED_STREAM_CONFIG, DEFAULT_RPC_TIMEOUT, DEFAULT_SHUTDOWN_TIMEOUT, DEFAULT_TRACES, type DeadLetterInfo, type ErrorClassification, type HandlerMetadata, JETSTREAM_CODEC, JETSTREAM_CONNECTION, JETSTREAM_OPTIONS, JetstreamClient, type JetstreamConsumeContext, JetstreamDlqHeader, type JetstreamFeatureOptions, JetstreamHeader, JetstreamHealthIndicator, type JetstreamHealthStatus, JetstreamModule, type JetstreamModuleAsyncOptions, type JetstreamModuleOptions, type JetstreamPublishContext, JetstreamRecord, JetstreamRecordBuilder, type JetstreamResponseContext, JetstreamStrategy, JetstreamTrace, JsonCodec, MIN_METADATA_TTL, MessageKind, type MetadataRegistryOptions, MsgpackCodec, NatsErrorCode, type OrderedEventOverrides, type OtelOptions, PatternPrefix, PublishKind, RESERVED_HEADERS, type RpcConfig, RpcContext, type ScheduleRecordOptions, type ServerEndpoint, type StreamConfigOverrides, type StreamConsumerOverrides, StreamKind, TRACER_NAME, TransportEvent, type TransportHooks, buildBroadcastSubject, buildSubject, consumerName, dlqStreamName, getClientToken, internalName, isCoreRpcMode, isJetStreamRpcMode, metadataKey, streamName, toNanos };
2403
+ interface ProvisioningErrorFields {
2404
+ readonly entity: ProvisioningEntity;
2405
+ readonly target: string;
2406
+ readonly kind: string;
2407
+ readonly errCode: number;
2408
+ readonly errDescription: string;
2409
+ readonly remediation: string;
2410
+ readonly maxBytes?: number;
2411
+ readonly numReplicas?: number;
2412
+ readonly reservation?: number;
2413
+ readonly cause: unknown;
2414
+ }
2415
+ /** Non-recoverable stream/consumer provisioning failure; preserves the NATS error as `cause`. */
2416
+ declare class JetstreamProvisioningError extends Error {
2417
+ readonly entity: ProvisioningEntity;
2418
+ readonly target: string;
2419
+ readonly kind: string;
2420
+ readonly errCode: number;
2421
+ readonly errDescription: string;
2422
+ readonly remediation: string;
2423
+ readonly maxBytes?: number;
2424
+ readonly numReplicas?: number;
2425
+ readonly reservation?: number;
2426
+ constructor(fields: ProvisioningErrorFields);
2427
+ }
2428
+
2429
+ export { type CaptureBodyOptions, type Codec, ConsumeKind, type ConsumeSourceMsg, DEFAULT_BROADCAST_CONSUMER_CONFIG, DEFAULT_BROADCAST_STREAM_CONFIG, DEFAULT_COMMAND_CONSUMER_CONFIG, DEFAULT_COMMAND_STREAM_CONFIG, DEFAULT_DLQ_STREAM_CONFIG, DEFAULT_EVENT_CONSUMER_CONFIG, DEFAULT_EVENT_STREAM_CONFIG, DEFAULT_JETSTREAM_RPC_TIMEOUT, DEFAULT_METADATA_BUCKET, DEFAULT_METADATA_HISTORY, DEFAULT_METADATA_REPLICAS, DEFAULT_METADATA_TTL, DEFAULT_ORDERED_STREAM_CONFIG, DEFAULT_RPC_TIMEOUT, DEFAULT_SHUTDOWN_TIMEOUT, DEFAULT_TRACES, type DeadLetterInfo, type ErrorClassification, type HandlerMetadata, JETSTREAM_CODEC, JETSTREAM_CONNECTION, JETSTREAM_OPTIONS, JetstreamClient, type JetstreamConsumeContext, JetstreamDlqHeader, type JetstreamFeatureOptions, JetstreamHeader, JetstreamHealthIndicator, type JetstreamHealthStatus, JetstreamModule, type JetstreamModuleAsyncOptions, type JetstreamModuleOptions, JetstreamProvisioningError, type JetstreamPublishContext, JetstreamRecord, JetstreamRecordBuilder, type JetstreamResponseContext, JetstreamStrategy, JetstreamTrace, JsonCodec, MIN_METADATA_TTL, MessageKind, type MetadataRegistryOptions, MsgpackCodec, NatsErrorCode, type OrderedEventOverrides, type OtelOptions, PatternPrefix, type ProvisioningOptions, PublishKind, RESERVED_HEADERS, type RpcConfig, RpcContext, type ScheduleRecordOptions, type ServerEndpoint, type StreamConfigOverrides, type StreamConsumerOverrides, StreamKind, TRACER_NAME, TransportEvent, type TransportHooks, buildBroadcastSubject, buildSubject, consumerName, dlqStreamName, getClientToken, internalName, isCoreRpcMode, isJetStreamRpcMode, metadataKey, streamName, toNanos };
package/dist/index.d.ts CHANGED
@@ -553,9 +553,13 @@ declare class JetstreamClient extends ClientProxy {
553
553
  * uses a separate `_sch` namespace that is NOT matched by any consumer filter.
554
554
  * NATS holds the message and publishes it to the target subject after the delay.
555
555
  *
556
+ * A unique per-message suffix is appended because the server stores schedules
557
+ * as rollup messages — one active schedule per subject (ADR-51). Without it,
558
+ * concurrent schedules of the same pattern would silently replace each other.
559
+ *
556
560
  * Examples:
557
- * - `{svc}__microservice.ev.order.reminder` → `{svc}__microservice._sch.order.reminder`
558
- * - `broadcast.config.updated` → `broadcast._sch.config.updated`
561
+ * - `{svc}__microservice.ev.order.reminder` → `{svc}__microservice._sch.order.reminder.<nuid>`
562
+ * - `broadcast.config.updated` → `broadcast._sch.config.updated.<nuid>`
559
563
  */
560
564
  private buildScheduleSubject;
561
565
  }
@@ -935,6 +939,8 @@ interface OtelOptions {
935
939
  errorClassifier?(err: unknown): ErrorClassification;
936
940
  }
937
941
 
942
+ type ProvisioningEntity = 'stream' | 'consumer';
943
+
938
944
  /**
939
945
  * Stream config overrides exposed to users.
940
946
  *
@@ -1073,6 +1079,14 @@ interface MetadataRegistryOptions {
1073
1079
  */
1074
1080
  ttl?: number;
1075
1081
  }
1082
+ /** Provisioning behavior. Stream reservations are always logged at boot (INFO). */
1083
+ interface ProvisioningOptions {
1084
+ /**
1085
+ * Opt-in storage budget check via `getAccountInfo()` before provisioning.
1086
+ * Warn-only; never blocks boot. Off by default.
1087
+ */
1088
+ preflightStorageCheck?: boolean;
1089
+ }
1076
1090
  /**
1077
1091
  * Root module configuration for `JetstreamModule.forRoot()`.
1078
1092
  *
@@ -1234,9 +1248,14 @@ interface JetstreamModuleOptions {
1234
1248
  * consuming application, all tracer calls are no-ops — there is no
1235
1249
  * runtime cost.
1236
1250
  *
1251
+ * Accepts a full {@link OtelOptions} object, or the boolean shorthand
1252
+ * `true` (== defaults) / `false` (== `{ enabled: false }`).
1253
+ *
1237
1254
  * @see OtelOptions
1238
1255
  */
1239
- otel?: OtelOptions;
1256
+ otel?: OtelOptions | boolean;
1257
+ /** Provisioning behavior. */
1258
+ provisioning?: ProvisioningOptions;
1240
1259
  }
1241
1260
  /** Options for `JetstreamModule.forFeature()`. */
1242
1261
  interface JetstreamFeatureOptions {
@@ -1258,15 +1277,6 @@ type JetstreamModuleAsyncOptions = {
1258
1277
  name: string;
1259
1278
  /** Additional module imports (e.g., ConfigModule). */
1260
1279
  imports?: ModuleMetadata['imports'];
1261
- /**
1262
- * Built-in Prometheus metrics. Specified at the async-options level (parallel
1263
- * to {@link name}) because module composition is decided synchronously before
1264
- * the async factory runs. Use `true` for defaults, a {@link MetricsConfig}
1265
- * object for full control, or omit/`false` to disable entirely.
1266
- *
1267
- * @see JetstreamModuleOptions.metrics
1268
- */
1269
- metrics?: MetricsOption;
1270
1280
  } & ({
1271
1281
  useFactory(...args: unknown[]): Promise<Omit<JetstreamModuleOptions, 'name'>> | Omit<JetstreamModuleOptions, 'name'>;
1272
1282
  inject?: FactoryProvider['inject'];
@@ -1319,8 +1329,11 @@ interface DeadLetterConfig {
1319
1329
  * Used to detect when a message from a given stream has exhausted all delivery attempts.
1320
1330
  */
1321
1331
  maxDeliverByStream: Map<string, number>;
1322
- /** Async callback invoked when a message exhausts all deliveries. */
1323
- onDeadLetter(info: DeadLetterInfo): Promise<void>;
1332
+ /**
1333
+ * Async callback invoked when a message exhausts all deliveries.
1334
+ * Optional: in dlq-only mode dead letters go to the DLQ stream without a callback.
1335
+ */
1336
+ onDeadLetter?(info: DeadLetterInfo): Promise<void>;
1324
1337
  }
1325
1338
  /** Options for configuring RPC processing behavior. */
1326
1339
  interface RpcRouterOptions {
@@ -1461,6 +1474,11 @@ declare class StreamProvider {
1461
1474
  private handleExistingStream;
1462
1475
  private buildMutableOnlyConfig;
1463
1476
  private logChanges;
1477
+ private buildReservation;
1478
+ private errorContext;
1479
+ private runStreamOp;
1480
+ /** The broadcast stream is global — every service in the cluster shares it. */
1481
+ private isSharedStream;
1464
1482
  /** Build the full stream config by merging defaults with user overrides. */
1465
1483
  private buildConfig;
1466
1484
  /**
@@ -1515,11 +1533,28 @@ declare class EventRouter {
1515
1533
  private getAckExtensionConfig;
1516
1534
  /**
1517
1535
  * Last-resort path for a dead letter: invoke `onDeadLetter`, then `term` on
1518
- * success or `nak` on hook failure so NATS retries on the next delivery
1519
- * cycle. Used when DLQ stream isn't configured, or when publishing to it
1520
- * failed and we still have to surface the message somewhere observable.
1536
+ * success. On failure the message is nak'd to release it, but the server
1537
+ * never redelivers past `max_deliver` it stays in the stream for manual
1538
+ * recovery. Used when the DLQ stream isn't configured, or when publishing
1539
+ * to it failed and we still have to surface the message somewhere.
1521
1540
  */
1522
1541
  private fallbackToOnDeadLetterCallback;
1542
+ /**
1543
+ * Copy the original message headers for the DLQ republish, dropping NATS
1544
+ * server control headers: a copied Nats-TTL expires the DLQ entry (or gets
1545
+ * the publish rejected when the DLQ stream has no allow_msg_ttl), a copied
1546
+ * Nats-Msg-Id collides with the DLQ dedup window.
1547
+ */
1548
+ private buildDlqHeaders;
1549
+ /**
1550
+ * Attempt the DLQ publish up to {@link DLQ_PUBLISH_ATTEMPTS} times.
1551
+ *
1552
+ * Past `max_deliver` the server never redelivers, so an in-process retry is
1553
+ * the only second chance a dead letter gets. There is no artificial delay
1554
+ * between attempts: when the broker is unreachable each publish already
1555
+ * spends its own request timeout, which spaces the attempts naturally.
1556
+ */
1557
+ private publishToDlqWithRetry;
1523
1558
  /**
1524
1559
  * Publish a dead letter to the configured Dead-Letter Queue (DLQ) stream.
1525
1560
  *
@@ -1630,6 +1665,7 @@ declare class ConsumerProvider {
1630
1665
  * Create a consumer, handling the race where another pod creates it first.
1631
1666
  */
1632
1667
  private createConsumer;
1668
+ private runConsumerOp;
1633
1669
  /** Build consumer config by merging defaults with user overrides. */
1634
1670
  private buildConfig;
1635
1671
  /** Get default config for a consumer kind. */
@@ -1771,7 +1807,7 @@ declare class MetadataProvider {
1771
1807
  * NATS JetStream API error codes used by the transport.
1772
1808
  *
1773
1809
  * Ref: https://github.com/nats-io/nats-server (server error definitions)
1774
- * Verified on NATS 2.12.6 via integration tests (2026-04-02).
1810
+ * Codes verified across NATS 2.12.6–2.14.1 via integration tests (original codes: 2026-04-02).
1775
1811
  */
1776
1812
  declare enum NatsErrorCode {
1777
1813
  /** Consumer does not exist on the specified stream. */
@@ -1779,7 +1815,14 @@ declare enum NatsErrorCode {
1779
1815
  /** Consumer name already in use with different configuration (race condition on create). */
1780
1816
  ConsumerAlreadyExists = 10148,
1781
1817
  /** Stream does not exist. */
1782
- StreamNotFound = 10059
1818
+ StreamNotFound = 10059,
1819
+ /** Storage resources exceeded — reservation exceeds server `max_file_store`. */
1820
+ StorageResourcesExceeded = 10047,
1821
+ /**
1822
+ * No suitable peers for placement (fewer healthy peers than `num_replicas`,
1823
+ * or no peer has storage headroom). Confirmed at runtime by the cluster integration test.
1824
+ */
1825
+ NoSuitablePeers = 10005
1783
1826
  }
1784
1827
 
1785
1828
  /**
@@ -1814,7 +1857,7 @@ declare class JetstreamStrategy extends Server implements CustomTransportStrateg
1814
1857
  *
1815
1858
  * Called by NestJS when `connectMicroservice()` is used, or internally by the module.
1816
1859
  */
1817
- listen(callback: () => void): Promise<void>;
1860
+ listen(callback: (...args: unknown[]) => void): Promise<void>;
1818
1861
  /** Stop all consumers, routers, subscriptions, and metadata heartbeat. Called during shutdown. */
1819
1862
  close(): void;
1820
1863
  /**
@@ -1844,9 +1887,13 @@ declare class JetstreamStrategy extends Server implements CustomTransportStrateg
1844
1887
  unwrap<T>(): T;
1845
1888
  /** Access the pattern registry (for module-level introspection). */
1846
1889
  getPatternRegistry(): PatternRegistry;
1890
+ private doListen;
1847
1891
  /** Determine which streams and durable consumers are needed. */
1848
1892
  private resolveRequiredKinds;
1849
- /** Populate the shared ack_wait map from actual NATS consumer configs. */
1893
+ /** Subscribe the event and RPC routers to the message subjects. */
1894
+ private startRouters;
1895
+ /** Begin durable and ordered consumption; routers must already be subscribed. */
1896
+ private startConsumption;
1850
1897
  private populateAckWaitMap;
1851
1898
  /** Build max_deliver map from actual NATS consumer configs (not options). */
1852
1899
  private buildMaxDeliverMap;
@@ -2353,4 +2400,30 @@ declare const isJetStreamRpcMode: (rpc: RpcConfig | undefined) => boolean;
2353
2400
  /** Check if the RPC config specifies Core mode (default). */
2354
2401
  declare const isCoreRpcMode: (rpc: RpcConfig | undefined) => boolean;
2355
2402
 
2356
- export { type CaptureBodyOptions, type Codec, ConsumeKind, type ConsumeSourceMsg, DEFAULT_BROADCAST_CONSUMER_CONFIG, DEFAULT_BROADCAST_STREAM_CONFIG, DEFAULT_COMMAND_CONSUMER_CONFIG, DEFAULT_COMMAND_STREAM_CONFIG, DEFAULT_DLQ_STREAM_CONFIG, DEFAULT_EVENT_CONSUMER_CONFIG, DEFAULT_EVENT_STREAM_CONFIG, DEFAULT_JETSTREAM_RPC_TIMEOUT, DEFAULT_METADATA_BUCKET, DEFAULT_METADATA_HISTORY, DEFAULT_METADATA_REPLICAS, DEFAULT_METADATA_TTL, DEFAULT_ORDERED_STREAM_CONFIG, DEFAULT_RPC_TIMEOUT, DEFAULT_SHUTDOWN_TIMEOUT, DEFAULT_TRACES, type DeadLetterInfo, type ErrorClassification, type HandlerMetadata, JETSTREAM_CODEC, JETSTREAM_CONNECTION, JETSTREAM_OPTIONS, JetstreamClient, type JetstreamConsumeContext, JetstreamDlqHeader, type JetstreamFeatureOptions, JetstreamHeader, JetstreamHealthIndicator, type JetstreamHealthStatus, JetstreamModule, type JetstreamModuleAsyncOptions, type JetstreamModuleOptions, type JetstreamPublishContext, JetstreamRecord, JetstreamRecordBuilder, type JetstreamResponseContext, JetstreamStrategy, JetstreamTrace, JsonCodec, MIN_METADATA_TTL, MessageKind, type MetadataRegistryOptions, MsgpackCodec, NatsErrorCode, type OrderedEventOverrides, type OtelOptions, PatternPrefix, PublishKind, RESERVED_HEADERS, type RpcConfig, RpcContext, type ScheduleRecordOptions, type ServerEndpoint, type StreamConfigOverrides, type StreamConsumerOverrides, StreamKind, TRACER_NAME, TransportEvent, type TransportHooks, buildBroadcastSubject, buildSubject, consumerName, dlqStreamName, getClientToken, internalName, isCoreRpcMode, isJetStreamRpcMode, metadataKey, streamName, toNanos };
2403
+ interface ProvisioningErrorFields {
2404
+ readonly entity: ProvisioningEntity;
2405
+ readonly target: string;
2406
+ readonly kind: string;
2407
+ readonly errCode: number;
2408
+ readonly errDescription: string;
2409
+ readonly remediation: string;
2410
+ readonly maxBytes?: number;
2411
+ readonly numReplicas?: number;
2412
+ readonly reservation?: number;
2413
+ readonly cause: unknown;
2414
+ }
2415
+ /** Non-recoverable stream/consumer provisioning failure; preserves the NATS error as `cause`. */
2416
+ declare class JetstreamProvisioningError extends Error {
2417
+ readonly entity: ProvisioningEntity;
2418
+ readonly target: string;
2419
+ readonly kind: string;
2420
+ readonly errCode: number;
2421
+ readonly errDescription: string;
2422
+ readonly remediation: string;
2423
+ readonly maxBytes?: number;
2424
+ readonly numReplicas?: number;
2425
+ readonly reservation?: number;
2426
+ constructor(fields: ProvisioningErrorFields);
2427
+ }
2428
+
2429
+ export { type CaptureBodyOptions, type Codec, ConsumeKind, type ConsumeSourceMsg, DEFAULT_BROADCAST_CONSUMER_CONFIG, DEFAULT_BROADCAST_STREAM_CONFIG, DEFAULT_COMMAND_CONSUMER_CONFIG, DEFAULT_COMMAND_STREAM_CONFIG, DEFAULT_DLQ_STREAM_CONFIG, DEFAULT_EVENT_CONSUMER_CONFIG, DEFAULT_EVENT_STREAM_CONFIG, DEFAULT_JETSTREAM_RPC_TIMEOUT, DEFAULT_METADATA_BUCKET, DEFAULT_METADATA_HISTORY, DEFAULT_METADATA_REPLICAS, DEFAULT_METADATA_TTL, DEFAULT_ORDERED_STREAM_CONFIG, DEFAULT_RPC_TIMEOUT, DEFAULT_SHUTDOWN_TIMEOUT, DEFAULT_TRACES, type DeadLetterInfo, type ErrorClassification, type HandlerMetadata, JETSTREAM_CODEC, JETSTREAM_CONNECTION, JETSTREAM_OPTIONS, JetstreamClient, type JetstreamConsumeContext, JetstreamDlqHeader, type JetstreamFeatureOptions, JetstreamHeader, JetstreamHealthIndicator, type JetstreamHealthStatus, JetstreamModule, type JetstreamModuleAsyncOptions, type JetstreamModuleOptions, JetstreamProvisioningError, type JetstreamPublishContext, JetstreamRecord, JetstreamRecordBuilder, type JetstreamResponseContext, JetstreamStrategy, JetstreamTrace, JsonCodec, MIN_METADATA_TTL, MessageKind, type MetadataRegistryOptions, MsgpackCodec, NatsErrorCode, type OrderedEventOverrides, type OtelOptions, PatternPrefix, type ProvisioningOptions, PublishKind, RESERVED_HEADERS, type RpcConfig, RpcContext, type ScheduleRecordOptions, type ServerEndpoint, type StreamConfigOverrides, type StreamConsumerOverrides, StreamKind, TRACER_NAME, TransportEvent, type TransportHooks, buildBroadcastSubject, buildSubject, consumerName, dlqStreamName, getClientToken, internalName, isCoreRpcMode, isJetStreamRpcMode, metadataKey, streamName, toNanos };