@cosyte/mllp 0.1.12 → 0.1.14

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
@@ -646,9 +646,10 @@ interface TlsOptions {
646
646
  * {@link TlsOptions.passphrase}. The file's bytes, as `readFileSync` returns them; this package
647
647
  * reads no file itself.
648
648
  *
649
- * The file is loaded before a socket is opened. One the TLS library cannot load rejects
650
- * `connect()` with a typed `MllpTlsConfigurationError` carrying `MLLP_TLS_PFX_REJECTED`, whose
651
- * message names this option and never its value: a wrong passphrase, bytes that are not
649
+ * The file is loaded once, when the client is created, from the copy of the options it takes
650
+ * then. One the TLS library cannot load rejects every `connect()`, before a socket is opened,
651
+ * with a typed `MllpTlsConfigurationError` carrying `MLLP_TLS_PFX_REJECTED`, whose message
652
+ * names this option and never its value: a wrong passphrase, bytes that are not
652
653
  * PKCS#12, or a legacy encryption (RC2-40, as `openssl pkcs12 -export -legacy`, OpenSSL 1.x and
653
654
  * older Windows exports write it) that Node.js, on OpenSSL 3, does not load. Re-export such a
654
655
  * file with AES-256. The refusal is permanent: a client does not retry it.
@@ -1062,6 +1063,26 @@ declare const MLLP_TLS_PFX_REJECTED = "MLLP_TLS_PFX_REJECTED";
1062
1063
  * ```
1063
1064
  */
1064
1065
  declare const MLLP_TLS_CREDENTIAL_CONFLICT = "MLLP_TLS_CREDENTIAL_CONFLICT";
1066
+ /**
1067
+ * `tls` was `null`, an array, a byte array (a `Buffer`, any other typed array, a `DataView`, an
1068
+ * `ArrayBuffer` or a `SharedArrayBuffer`), a `Map`, a `Set`, a `Date`, a `Promise`, a boxed
1069
+ * primitive or a value that is no object, rather than an object of TLS options (for a client,
1070
+ * `true` also asks for the defaults). Any other object is an object of options: a literal, a class
1071
+ * instance, an `Object.create` object or a module namespace object, whatever its
1072
+ * `Symbol.toStringTag`. Without this check such a value reached the options' property reads and
1073
+ * failed there with a bare `TypeError`, or was taken as TLS with no options at all.
1074
+ *
1075
+ * Like {@link MLLP_TLS_CREDENTIAL_CONFLICT}, this one is thrown by the constructor
1076
+ * (`createClient`, `createServer`, `new MllpClient`, `new MllpServer`). The message never carries
1077
+ * the value that was passed, and there is no `cause`.
1078
+ *
1079
+ * @example
1080
+ * ```typescript
1081
+ * import { MLLP_TLS_OPTIONS_NOT_AN_OBJECT } from '@cosyte/mllp';
1082
+ * if (err.code === MLLP_TLS_OPTIONS_NOT_AN_OBJECT) logger.error('tls must be an options object');
1083
+ * ```
1084
+ */
1085
+ declare const MLLP_TLS_OPTIONS_NOT_AN_OBJECT = "MLLP_TLS_OPTIONS_NOT_AN_OBJECT";
1065
1086
  /**
1066
1087
  * Union of the stable TLS-configuration error codes.
1067
1088
  *
@@ -1070,7 +1091,7 @@ declare const MLLP_TLS_CREDENTIAL_CONFLICT = "MLLP_TLS_CREDENTIAL_CONFLICT";
1070
1091
  * const code: TlsConfigurationErrorCode = 'MLLP_TLS_CIPHER_LIST_REJECTED';
1071
1092
  * ```
1072
1093
  */
1073
- type TlsConfigurationErrorCode = typeof MLLP_TLS_CIPHER_LIST_REJECTED | typeof MLLP_TLS_CIPHER_OPTION_CONFLICT | typeof MLLP_TLS_DH_PARAMETERS_REJECTED | typeof MLLP_TLS_CIPHER_LIST_UNENFORCEABLE | typeof MLLP_TLS_DH_PARAMETERS_UNENFORCEABLE | typeof MLLP_TLS_PFX_REJECTED | typeof MLLP_TLS_CREDENTIAL_CONFLICT;
1094
+ type TlsConfigurationErrorCode = typeof MLLP_TLS_CIPHER_LIST_REJECTED | typeof MLLP_TLS_CIPHER_OPTION_CONFLICT | typeof MLLP_TLS_DH_PARAMETERS_REJECTED | typeof MLLP_TLS_CIPHER_LIST_UNENFORCEABLE | typeof MLLP_TLS_DH_PARAMETERS_UNENFORCEABLE | typeof MLLP_TLS_PFX_REJECTED | typeof MLLP_TLS_CREDENTIAL_CONFLICT | typeof MLLP_TLS_OPTIONS_NOT_AN_OBJECT;
1074
1095
  /**
1075
1096
  * Fixed, human-readable description for a TLS-configuration code.
1076
1097
  *
@@ -1306,15 +1327,15 @@ declare function resolveTlsCipherPolicy(opts: TlsCipherPolicyInput, side: "clien
1306
1327
  * version and which cipher suite that link negotiated. This is that record,
1307
1328
  * emitted once per completed handshake on both the client and the server.
1308
1329
  *
1309
- * It is a **log line**, so it carries no field content: both values are read
1310
- * from the TLS session and are names out of a closed registry, never anything
1330
+ * It is a **log line**, so it carries no field content: every value is read
1331
+ * from the TLS session and is a name out of a closed registry, never anything
1311
1332
  * derived from the payload, the certificate, or the key.
1312
1333
  *
1313
1334
  * @example
1314
1335
  * ```typescript
1315
1336
  * import type { NegotiatedTlsParameters } from '@cosyte/mllp';
1316
1337
  * client.on('tlsNegotiated', (p: NegotiatedTlsParameters) => {
1317
- * logger.info({ tls: p.protocolVersion, suite: p.cipherSuite });
1338
+ * logger.info({ tls: p.protocolVersion, suite: p.cipherSuite, group: p.keyExchangeGroup });
1318
1339
  * });
1319
1340
  * ```
1320
1341
  *
@@ -1327,7 +1348,7 @@ declare function resolveTlsCipherPolicy(opts: TlsCipherPolicyInput, side: "clien
1327
1348
  * including every reconnect. Never emitted on a plaintext connection.
1328
1349
  *
1329
1350
  * Carries no HL7 payload content and no certificate or key material: only the
1330
- * two negotiated names and the same routing metadata a `SecurityWarning`
1351
+ * negotiated names and the same routing metadata a `SecurityWarning`
1331
1352
  * carries. It is emitted at handshake-completion time, before any HL7 byte has
1332
1353
  * crossed the link.
1333
1354
  *
@@ -1352,6 +1373,25 @@ interface NegotiatedTlsParameters {
1352
1373
  * in, is a different rendering of the same suite.
1353
1374
  */
1354
1375
  readonly cipherSuite: string;
1376
+ /**
1377
+ * The key-exchange group the handshake used, as the TLS library names it,
1378
+ * e.g. `'X25519'`, `'prime256v1'`, or a post-quantum hybrid such as
1379
+ * `'X25519MLKEM768'`. Standardized group names are the ones the IANA TLS
1380
+ * Supported Groups registry lists.
1381
+ *
1382
+ * Present only where the runtime reports the group, and **absent** (the key
1383
+ * is not on the object) everywhere else:
1384
+ *
1385
+ * - only on a **client** record: Node.js reports the group on a client socket
1386
+ * alone, so a server record never carries it;
1387
+ * - a classic elliptic-curve group (`'X25519'`, `'prime256v1'` and the like)
1388
+ * is reported on every supported Node.js line;
1389
+ * - a group with no classic key, such as a post-quantum hybrid, is reported
1390
+ * from Node.js 24.19.0 and 26.5.0; on Node.js 22 it is absent;
1391
+ * - a TLS 1.2 finite-field Diffie-Hellman exchange (a `DHE` suite) has no
1392
+ * group name to report, so it is absent there too.
1393
+ */
1394
+ readonly keyExchangeGroup?: string;
1355
1395
  /** Host associated with the link (the target host for clients; the bind host for servers). */
1356
1396
  readonly host: string;
1357
1397
  /** Port associated with the link. */
@@ -1885,7 +1925,7 @@ declare class MllpConnectionError extends Error {
1885
1925
  * const code: AckModeCode = 'MLLP_ACK_TWO_PHASE_UNAVAILABLE';
1886
1926
  * ```
1887
1927
  */
1888
- type AckModeCode = "MLLP_ACK_ACCEPT_TYPE_UNRECOGNISED" | "MLLP_ACK_APPLICATION_TYPE_UNRECOGNISED" | "MLLP_ACK_TWO_PHASE_UNAVAILABLE" | "MLLP_ACK_COMMIT_ALREADY_REPORTED" | "MLLP_ACK_MSA1_ABSENT" | "MLLP_ACK_MSA1_UNCLASSIFIABLE" | "MLLP_ACK_SEND_ALREADY_DISPOSED";
1928
+ type AckModeCode = "MLLP_ACK_ACCEPT_TYPE_UNRECOGNISED" | "MLLP_ACK_APPLICATION_TYPE_UNRECOGNISED" | "MLLP_ACK_TWO_PHASE_UNAVAILABLE" | "MLLP_ACK_COMMIT_ALREADY_REPORTED" | "MLLP_ACK_MSA1_ABSENT" | "MLLP_ACK_MSA1_UNCLASSIFIABLE" | "MLLP_ACK_SEND_ALREADY_DISPOSED" | "MLLP_ACK_FIFO_MSA1_UNREADABLE";
1889
1929
  /**
1890
1930
  * Look up the frozen diagnostic text for an acknowledgement-mode code.
1891
1931
  *
@@ -2368,6 +2408,8 @@ declare class MllpServer extends EventEmitter {
2368
2408
  private readonly _netServer;
2369
2409
  private readonly _connections;
2370
2410
  private readonly _opts;
2411
+ /** The TLS options as they were at construction; never read `_opts.tls`, which the caller owns. */
2412
+ private readonly _tls;
2371
2413
  /** `true` when `ServerOptions.tls` is set, `_netServer` is actually a `tls.Server`. */
2372
2414
  private readonly _isTls;
2373
2415
  private _listening;
@@ -2846,9 +2888,10 @@ declare function resolveNackCode(err: unknown): NegativeAckCode;
2846
2888
  * destroyed message was delivered). Three payload-shaped reasons make a positive ACK
2847
2889
  * uncorrelatable, all peer-reachable off the wire:
2848
2890
  *
2849
- * 1. **No readable `MSH`.** `readMshSegment` returns `null`, e.g. a `BOM`/`SP`/`TAB`
2850
- * before `MSH` (which shares the `MSH`'s segment line, so `MSH` heads no segment), or
2851
- * a bare fragment delivered after a mid-payload `VT` discard (`MLLP_TRAILING_BYTES`).
2891
+ * 1. **No readable `MSH`.** `readMshSegment` returns `null`, e.g. a `SP`/`TAB` before
2892
+ * `MSH` (which shares the `MSH`'s segment line, so `MSH` heads no segment), or a bare
2893
+ * fragment delivered after a mid-payload `VT` discard (`MLLP_TRAILING_BYTES`). A UTF-8
2894
+ * byte order mark at byte 0 is not one of these: the scan skips it and reads the `MSH`.
2852
2895
  * MSA-2 would be empty: an ACK that correlates to nothing.
2853
2896
  * 2. **Empty MSH-10.** The `MSH` is readable but carries no message control ID, so there
2854
2897
  * is nothing to echo, again `MSA|AA|` with an empty MSA-2.
@@ -3418,6 +3461,24 @@ interface ClientOptions {
3418
3461
  * @default false
3419
3462
  */
3420
3463
  readonly correlateByControlId?: boolean;
3464
+ /**
3465
+ * What a client correlating in order (FIFO, the default) does when the frame that settles a
3466
+ * send carries no readable MSA-1: no HL7 Table 0008 code can be read from it, as with a lone
3467
+ * `0x06` or `0x15` byte, an `MSH` with no `MSA`, an empty MSA-1, or a value outside the table.
3468
+ * Such a frame is not an HL7 acknowledgement of the message.
3469
+ *
3470
+ * - `'warn'` (default): the send resolves with the frame, as it always has, and the client
3471
+ * emits the `'warning'` `MLLP_ACK_FIFO_MSA1_UNREADABLE` (an {@link AckModeWarning}).
3472
+ * - `'reject'`: the client emits the same warning and the send rejects with
3473
+ * {@link MllpUnreadableAckError}. The frame still takes that send's turn, so the next send
3474
+ * settles on the next frame.
3475
+ *
3476
+ * Has no effect with `correlateByControlId: true`, which matches by MSA-2 and settles nothing
3477
+ * on a frame that has none. Any other value throws a `TypeError` at construction.
3478
+ *
3479
+ * @default 'warn'
3480
+ */
3481
+ readonly fifoUnreadableAck?: "warn" | "reject";
3421
3482
  /**
3422
3483
  * Auto-reconnect on transient disconnect. Default `false`.
3423
3484
  *
@@ -3628,6 +3689,10 @@ interface ClientStats {
3628
3689
  */
3629
3690
  declare class MllpClient extends EventEmitter {
3630
3691
  private readonly _opts;
3692
+ /** The TLS options as they were at construction; never read `_opts.tls`, which the caller owns. */
3693
+ private readonly _tls;
3694
+ /** Why `tls.pfx` cannot be loaded, found once at construction; `undefined` when it loads or is unset. */
3695
+ private readonly _pfxRefusal;
3631
3696
  private _connection;
3632
3697
  private _socket;
3633
3698
  /**
@@ -3644,6 +3709,8 @@ declare class MllpClient extends EventEmitter {
3644
3709
  private readonly _applicationAckTimeoutMs;
3645
3710
  /** controlId-mode flag. `false` → FIFO. */
3646
3711
  private readonly _correlateByControlId;
3712
+ /** Whether a FIFO send settled on a frame with no readable MSA-1 rejects rather than resolves. */
3713
+ private readonly _rejectUnreadableAck;
3647
3714
  /** Unified ACK correlator. Built during `_attachConnection`. */
3648
3715
  private _correlator;
3649
3716
  /**
@@ -4043,6 +4110,12 @@ declare class MllpClient extends EventEmitter {
4043
4110
  * client's). The clock starts at the underlying `write()` flush callback, NOT at
4044
4111
  * the `send()` call.
4045
4112
  * - `MllpConnectionError({ phase: 'send' })` if the client is not connected.
4113
+ * - `MllpUnreadableAckError` with `fifoUnreadableAck: 'reject'`, when the frame that settles
4114
+ * this send in order carries no readable MSA-1.
4115
+ *
4116
+ * Resolving is not acceptance: read MSA-1 off the acknowledgement you are handed. In FIFO
4117
+ * mode a frame with no readable MSA-1 still resolves by default, with the warning
4118
+ * `MLLP_ACK_FIFO_MSA1_UNREADABLE`.
4046
4119
  *
4047
4120
  * Emits a frozen `'ack'` event on every successful match.
4048
4121
  *
@@ -4372,6 +4445,8 @@ interface StarterClientOptions {
4372
4445
  readonly ackTimeoutMs?: number;
4373
4446
  /** Override default `false` (FIFO mode). */
4374
4447
  readonly correlateByControlId?: boolean;
4448
+ /** Passthrough to `ClientOptions.fifoUnreadableAck`, default `'warn'`. */
4449
+ readonly fifoUnreadableAck?: "warn" | "reject";
4375
4450
  /** Override default `true` (parallel up to highWaterMark). */
4376
4451
  readonly pipeline?: boolean;
4377
4452
  /** Override default `64`. */
@@ -4441,6 +4516,7 @@ declare function createStarterClient(opts: StarterClientOptions): Promise<MllpCl
4441
4516
  * - `MllpBackpressureError`, high-water mark exceeded
4442
4517
  * - `MllpNeverDeliveredError`, a send that never reached the transport
4443
4518
  * - `MllpUnknownFateError`, a send whose bytes went out and drew no answer
4519
+ * - `MllpUnreadableAckError`, a FIFO send settled on a frame with no readable MSA-1
4444
4520
  * - `isTransientConnectionError`, transient/permanent classifier
4445
4521
  *
4446
4522
  * Re-exported from `src/client/index.ts` and `src/index.ts`.
@@ -4571,6 +4647,50 @@ declare class MllpApplicationAckError extends Error {
4571
4647
  commitReceivedAt: number;
4572
4648
  });
4573
4649
  }
4650
+ /**
4651
+ * Rejects a `send()` on a client correlating in order (FIFO, the default) when the frame that
4652
+ * settled it carries no readable MSA-1: no HL7 Table 0008 code could be read from it. A lone
4653
+ * `0x06` or `0x15` byte, an `MSH` with no `MSA`, an empty MSA-1 and a value outside the table
4654
+ * all qualify.
4655
+ *
4656
+ * Only raised with `fifoUnreadableAck: 'reject'`; by default the send resolves with the frame
4657
+ * and the client warns `MLLP_ACK_FIFO_MSA1_UNREADABLE`. The frame was written in reply to this
4658
+ * send's turn, so the peer may hold the message: resending it may deliver it twice, and the
4659
+ * receiver's de-duplication on MSH-10 is what makes a resend safe.
4660
+ *
4661
+ * Every field is a number. The frame itself is on the client's `'message'` event.
4662
+ *
4663
+ * @example
4664
+ * ```typescript
4665
+ * try {
4666
+ * await client.send(payload);
4667
+ * } catch (err) {
4668
+ * if (err instanceof MllpUnreadableAckError) {
4669
+ * logger.warn({ msa1Bytes: err.msa1Bytes, at: err.byteOffset });
4670
+ * }
4671
+ * }
4672
+ * ```
4673
+ */
4674
+ declare class MllpUnreadableAckError extends Error {
4675
+ readonly name: "MllpUnreadableAckError";
4676
+ /** Byte length of the MSA-1 field read, `0` when the frame has no `MSH` or no `MSA`. */
4677
+ readonly msa1Bytes: number;
4678
+ /** Stream byte offset of the frame that settled the send. */
4679
+ readonly byteOffset: number;
4680
+ /** Milliseconds between the send's write-flush and that frame. */
4681
+ readonly elapsedMs: number;
4682
+ /**
4683
+ * Construct an unreadable-acknowledgement error.
4684
+ *
4685
+ * @param message - Human-readable error message. Structural facts only, never field content.
4686
+ * @param opts - Failure context (MSA-1 byte length, stream offset, elapsed time).
4687
+ */
4688
+ constructor(message: string, opts: {
4689
+ msa1Bytes: number;
4690
+ byteOffset: number;
4691
+ elapsedMs: number;
4692
+ });
4693
+ }
4574
4694
  /**
4575
4695
  * Rejects a `send()` whose peer answered with a **negative commit**: HL7 Table 0008 `CE`
4576
4696
  * (commit error) or `CR` (commit reject).
@@ -5466,5 +5586,5 @@ declare function runDifferential(options?: DifferentialRunOptions): Promise<Diff
5466
5586
  */
5467
5587
  declare const VERSION: string;
5468
5588
 
5469
- export { ATNA_CIPHER_LIST, ATNA_CIPHER_SUITES, Connection, FrameReader, MLLP_BIND_ALL_INTERFACES, MLLP_CONNECTION_LIMIT_REACHED, MLLP_DIFF_PEER_UNPARSEABLE, MLLP_TLS_CIPHER_LIST_REJECTED, MLLP_TLS_CIPHER_LIST_UNENFORCEABLE, MLLP_TLS_CIPHER_OPTION_CONFLICT, MLLP_TLS_CREDENTIAL_CONFLICT, MLLP_TLS_DH_PARAMETERS_REJECTED, MLLP_TLS_DH_PARAMETERS_UNENFORCEABLE, MLLP_TLS_PFX_REJECTED, MLLP_TLS_VERIFY_DISABLED, MllpAckError, MllpApplicationAckError, MllpBackpressureError, MllpClient, MllpCommitRejectedError, MllpConnectionError, MllpDifferentialConfigurationError, MllpFramingError, MllpNeverDeliveredError, MllpServer, MllpTimeoutError, MllpTlsConfigurationError, MllpUnknownFateError, MllpWarning, NetTransport, TLS13_DEFAULT_CIPHER_SUITES, TlsTransport, Transport, VERSION, WarningCode, ackDiagnosticMessage, ackModeDiagnosticMessage, buildRawAck, canonicalAcknowledgement, canonicalExchanges, createClient, createServer, createStarterClient, createStarterServer, differentialConfigurationMessage, encodeFrame, isTlsProtocolError, isTlsVerificationErrorCode, isTransientConnectionError, rawAckUncorrelatable, readNegotiatedTlsParameters, resolveDifferentialPeer, resolveNackCode, resolveTlsCipherPolicy, runDifferential, selectAckCode, tlsConfigurationMessage };
5589
+ export { ATNA_CIPHER_LIST, ATNA_CIPHER_SUITES, Connection, FrameReader, MLLP_BIND_ALL_INTERFACES, MLLP_CONNECTION_LIMIT_REACHED, MLLP_DIFF_PEER_UNPARSEABLE, MLLP_TLS_CIPHER_LIST_REJECTED, MLLP_TLS_CIPHER_LIST_UNENFORCEABLE, MLLP_TLS_CIPHER_OPTION_CONFLICT, MLLP_TLS_CREDENTIAL_CONFLICT, MLLP_TLS_DH_PARAMETERS_REJECTED, MLLP_TLS_DH_PARAMETERS_UNENFORCEABLE, MLLP_TLS_OPTIONS_NOT_AN_OBJECT, MLLP_TLS_PFX_REJECTED, MLLP_TLS_VERIFY_DISABLED, MllpAckError, MllpApplicationAckError, MllpBackpressureError, MllpClient, MllpCommitRejectedError, MllpConnectionError, MllpDifferentialConfigurationError, MllpFramingError, MllpNeverDeliveredError, MllpServer, MllpTimeoutError, MllpTlsConfigurationError, MllpUnknownFateError, MllpUnreadableAckError, MllpWarning, NetTransport, TLS13_DEFAULT_CIPHER_SUITES, TlsTransport, Transport, VERSION, WarningCode, ackDiagnosticMessage, ackModeDiagnosticMessage, buildRawAck, canonicalAcknowledgement, canonicalExchanges, createClient, createServer, createStarterClient, createStarterServer, differentialConfigurationMessage, encodeFrame, isTlsProtocolError, isTlsVerificationErrorCode, isTransientConnectionError, rawAckUncorrelatable, readNegotiatedTlsParameters, resolveDifferentialPeer, resolveNackCode, resolveTlsCipherPolicy, runDifferential, selectAckCode, tlsConfigurationMessage };
5470
5590
  export type { AckCode, AckCodeSelection, AckCodeSelectionInput, AckCorrelationCode, AckCorrelationWarning, AckModeCode, AckModeWarning, AckModeWarningEvent, ApplicationAckFailure, CanonicalExchange, ClientAuth, ClientOptions, ClientStats, CommitAckReport, ConnectionErrorCause, ConnectionErrorPhase, ConnectionOptions, ConnectionRejectedEvent, ConnectionState, ConnectionStats, DifferentialConfigurationErrorCode, DifferentialConnect, DifferentialCorrelationOutcome, DifferentialDeviation, DifferentialExchangeOutcome, DifferentialExchangeReport, DifferentialParityOutcome, DifferentialPeer, DifferentialReport, DifferentialReportPeer, DifferentialRunOptions, DifferentialRunResult, DifferentialSkipReason, EncoderOptions, FrameReaderOptions, MessageMeta, NackAckCode, NackEvent, NackReason, NegativeAckCode, NegotiatedTlsParameters, PemInput, ReconnectingEvent, ResolvedTlsCipherPolicy, RetryContext, RetryStrategy, SecurityWarning, SecurityWarningCode, ServerOptions, ServerStats, ServerTlsOptions, StarterClientOptions, StarterServerOptions, StateChangeEvent, TlsCipherPolicyInput, TlsConfigurationErrorCode, TlsOptions };
package/dist/index.d.ts CHANGED
@@ -646,9 +646,10 @@ interface TlsOptions {
646
646
  * {@link TlsOptions.passphrase}. The file's bytes, as `readFileSync` returns them; this package
647
647
  * reads no file itself.
648
648
  *
649
- * The file is loaded before a socket is opened. One the TLS library cannot load rejects
650
- * `connect()` with a typed `MllpTlsConfigurationError` carrying `MLLP_TLS_PFX_REJECTED`, whose
651
- * message names this option and never its value: a wrong passphrase, bytes that are not
649
+ * The file is loaded once, when the client is created, from the copy of the options it takes
650
+ * then. One the TLS library cannot load rejects every `connect()`, before a socket is opened,
651
+ * with a typed `MllpTlsConfigurationError` carrying `MLLP_TLS_PFX_REJECTED`, whose message
652
+ * names this option and never its value: a wrong passphrase, bytes that are not
652
653
  * PKCS#12, or a legacy encryption (RC2-40, as `openssl pkcs12 -export -legacy`, OpenSSL 1.x and
653
654
  * older Windows exports write it) that Node.js, on OpenSSL 3, does not load. Re-export such a
654
655
  * file with AES-256. The refusal is permanent: a client does not retry it.
@@ -1062,6 +1063,26 @@ declare const MLLP_TLS_PFX_REJECTED = "MLLP_TLS_PFX_REJECTED";
1062
1063
  * ```
1063
1064
  */
1064
1065
  declare const MLLP_TLS_CREDENTIAL_CONFLICT = "MLLP_TLS_CREDENTIAL_CONFLICT";
1066
+ /**
1067
+ * `tls` was `null`, an array, a byte array (a `Buffer`, any other typed array, a `DataView`, an
1068
+ * `ArrayBuffer` or a `SharedArrayBuffer`), a `Map`, a `Set`, a `Date`, a `Promise`, a boxed
1069
+ * primitive or a value that is no object, rather than an object of TLS options (for a client,
1070
+ * `true` also asks for the defaults). Any other object is an object of options: a literal, a class
1071
+ * instance, an `Object.create` object or a module namespace object, whatever its
1072
+ * `Symbol.toStringTag`. Without this check such a value reached the options' property reads and
1073
+ * failed there with a bare `TypeError`, or was taken as TLS with no options at all.
1074
+ *
1075
+ * Like {@link MLLP_TLS_CREDENTIAL_CONFLICT}, this one is thrown by the constructor
1076
+ * (`createClient`, `createServer`, `new MllpClient`, `new MllpServer`). The message never carries
1077
+ * the value that was passed, and there is no `cause`.
1078
+ *
1079
+ * @example
1080
+ * ```typescript
1081
+ * import { MLLP_TLS_OPTIONS_NOT_AN_OBJECT } from '@cosyte/mllp';
1082
+ * if (err.code === MLLP_TLS_OPTIONS_NOT_AN_OBJECT) logger.error('tls must be an options object');
1083
+ * ```
1084
+ */
1085
+ declare const MLLP_TLS_OPTIONS_NOT_AN_OBJECT = "MLLP_TLS_OPTIONS_NOT_AN_OBJECT";
1065
1086
  /**
1066
1087
  * Union of the stable TLS-configuration error codes.
1067
1088
  *
@@ -1070,7 +1091,7 @@ declare const MLLP_TLS_CREDENTIAL_CONFLICT = "MLLP_TLS_CREDENTIAL_CONFLICT";
1070
1091
  * const code: TlsConfigurationErrorCode = 'MLLP_TLS_CIPHER_LIST_REJECTED';
1071
1092
  * ```
1072
1093
  */
1073
- type TlsConfigurationErrorCode = typeof MLLP_TLS_CIPHER_LIST_REJECTED | typeof MLLP_TLS_CIPHER_OPTION_CONFLICT | typeof MLLP_TLS_DH_PARAMETERS_REJECTED | typeof MLLP_TLS_CIPHER_LIST_UNENFORCEABLE | typeof MLLP_TLS_DH_PARAMETERS_UNENFORCEABLE | typeof MLLP_TLS_PFX_REJECTED | typeof MLLP_TLS_CREDENTIAL_CONFLICT;
1094
+ type TlsConfigurationErrorCode = typeof MLLP_TLS_CIPHER_LIST_REJECTED | typeof MLLP_TLS_CIPHER_OPTION_CONFLICT | typeof MLLP_TLS_DH_PARAMETERS_REJECTED | typeof MLLP_TLS_CIPHER_LIST_UNENFORCEABLE | typeof MLLP_TLS_DH_PARAMETERS_UNENFORCEABLE | typeof MLLP_TLS_PFX_REJECTED | typeof MLLP_TLS_CREDENTIAL_CONFLICT | typeof MLLP_TLS_OPTIONS_NOT_AN_OBJECT;
1074
1095
  /**
1075
1096
  * Fixed, human-readable description for a TLS-configuration code.
1076
1097
  *
@@ -1306,15 +1327,15 @@ declare function resolveTlsCipherPolicy(opts: TlsCipherPolicyInput, side: "clien
1306
1327
  * version and which cipher suite that link negotiated. This is that record,
1307
1328
  * emitted once per completed handshake on both the client and the server.
1308
1329
  *
1309
- * It is a **log line**, so it carries no field content: both values are read
1310
- * from the TLS session and are names out of a closed registry, never anything
1330
+ * It is a **log line**, so it carries no field content: every value is read
1331
+ * from the TLS session and is a name out of a closed registry, never anything
1311
1332
  * derived from the payload, the certificate, or the key.
1312
1333
  *
1313
1334
  * @example
1314
1335
  * ```typescript
1315
1336
  * import type { NegotiatedTlsParameters } from '@cosyte/mllp';
1316
1337
  * client.on('tlsNegotiated', (p: NegotiatedTlsParameters) => {
1317
- * logger.info({ tls: p.protocolVersion, suite: p.cipherSuite });
1338
+ * logger.info({ tls: p.protocolVersion, suite: p.cipherSuite, group: p.keyExchangeGroup });
1318
1339
  * });
1319
1340
  * ```
1320
1341
  *
@@ -1327,7 +1348,7 @@ declare function resolveTlsCipherPolicy(opts: TlsCipherPolicyInput, side: "clien
1327
1348
  * including every reconnect. Never emitted on a plaintext connection.
1328
1349
  *
1329
1350
  * Carries no HL7 payload content and no certificate or key material: only the
1330
- * two negotiated names and the same routing metadata a `SecurityWarning`
1351
+ * negotiated names and the same routing metadata a `SecurityWarning`
1331
1352
  * carries. It is emitted at handshake-completion time, before any HL7 byte has
1332
1353
  * crossed the link.
1333
1354
  *
@@ -1352,6 +1373,25 @@ interface NegotiatedTlsParameters {
1352
1373
  * in, is a different rendering of the same suite.
1353
1374
  */
1354
1375
  readonly cipherSuite: string;
1376
+ /**
1377
+ * The key-exchange group the handshake used, as the TLS library names it,
1378
+ * e.g. `'X25519'`, `'prime256v1'`, or a post-quantum hybrid such as
1379
+ * `'X25519MLKEM768'`. Standardized group names are the ones the IANA TLS
1380
+ * Supported Groups registry lists.
1381
+ *
1382
+ * Present only where the runtime reports the group, and **absent** (the key
1383
+ * is not on the object) everywhere else:
1384
+ *
1385
+ * - only on a **client** record: Node.js reports the group on a client socket
1386
+ * alone, so a server record never carries it;
1387
+ * - a classic elliptic-curve group (`'X25519'`, `'prime256v1'` and the like)
1388
+ * is reported on every supported Node.js line;
1389
+ * - a group with no classic key, such as a post-quantum hybrid, is reported
1390
+ * from Node.js 24.19.0 and 26.5.0; on Node.js 22 it is absent;
1391
+ * - a TLS 1.2 finite-field Diffie-Hellman exchange (a `DHE` suite) has no
1392
+ * group name to report, so it is absent there too.
1393
+ */
1394
+ readonly keyExchangeGroup?: string;
1355
1395
  /** Host associated with the link (the target host for clients; the bind host for servers). */
1356
1396
  readonly host: string;
1357
1397
  /** Port associated with the link. */
@@ -1885,7 +1925,7 @@ declare class MllpConnectionError extends Error {
1885
1925
  * const code: AckModeCode = 'MLLP_ACK_TWO_PHASE_UNAVAILABLE';
1886
1926
  * ```
1887
1927
  */
1888
- type AckModeCode = "MLLP_ACK_ACCEPT_TYPE_UNRECOGNISED" | "MLLP_ACK_APPLICATION_TYPE_UNRECOGNISED" | "MLLP_ACK_TWO_PHASE_UNAVAILABLE" | "MLLP_ACK_COMMIT_ALREADY_REPORTED" | "MLLP_ACK_MSA1_ABSENT" | "MLLP_ACK_MSA1_UNCLASSIFIABLE" | "MLLP_ACK_SEND_ALREADY_DISPOSED";
1928
+ type AckModeCode = "MLLP_ACK_ACCEPT_TYPE_UNRECOGNISED" | "MLLP_ACK_APPLICATION_TYPE_UNRECOGNISED" | "MLLP_ACK_TWO_PHASE_UNAVAILABLE" | "MLLP_ACK_COMMIT_ALREADY_REPORTED" | "MLLP_ACK_MSA1_ABSENT" | "MLLP_ACK_MSA1_UNCLASSIFIABLE" | "MLLP_ACK_SEND_ALREADY_DISPOSED" | "MLLP_ACK_FIFO_MSA1_UNREADABLE";
1889
1929
  /**
1890
1930
  * Look up the frozen diagnostic text for an acknowledgement-mode code.
1891
1931
  *
@@ -2368,6 +2408,8 @@ declare class MllpServer extends EventEmitter {
2368
2408
  private readonly _netServer;
2369
2409
  private readonly _connections;
2370
2410
  private readonly _opts;
2411
+ /** The TLS options as they were at construction; never read `_opts.tls`, which the caller owns. */
2412
+ private readonly _tls;
2371
2413
  /** `true` when `ServerOptions.tls` is set, `_netServer` is actually a `tls.Server`. */
2372
2414
  private readonly _isTls;
2373
2415
  private _listening;
@@ -2846,9 +2888,10 @@ declare function resolveNackCode(err: unknown): NegativeAckCode;
2846
2888
  * destroyed message was delivered). Three payload-shaped reasons make a positive ACK
2847
2889
  * uncorrelatable, all peer-reachable off the wire:
2848
2890
  *
2849
- * 1. **No readable `MSH`.** `readMshSegment` returns `null`, e.g. a `BOM`/`SP`/`TAB`
2850
- * before `MSH` (which shares the `MSH`'s segment line, so `MSH` heads no segment), or
2851
- * a bare fragment delivered after a mid-payload `VT` discard (`MLLP_TRAILING_BYTES`).
2891
+ * 1. **No readable `MSH`.** `readMshSegment` returns `null`, e.g. a `SP`/`TAB` before
2892
+ * `MSH` (which shares the `MSH`'s segment line, so `MSH` heads no segment), or a bare
2893
+ * fragment delivered after a mid-payload `VT` discard (`MLLP_TRAILING_BYTES`). A UTF-8
2894
+ * byte order mark at byte 0 is not one of these: the scan skips it and reads the `MSH`.
2852
2895
  * MSA-2 would be empty: an ACK that correlates to nothing.
2853
2896
  * 2. **Empty MSH-10.** The `MSH` is readable but carries no message control ID, so there
2854
2897
  * is nothing to echo, again `MSA|AA|` with an empty MSA-2.
@@ -3418,6 +3461,24 @@ interface ClientOptions {
3418
3461
  * @default false
3419
3462
  */
3420
3463
  readonly correlateByControlId?: boolean;
3464
+ /**
3465
+ * What a client correlating in order (FIFO, the default) does when the frame that settles a
3466
+ * send carries no readable MSA-1: no HL7 Table 0008 code can be read from it, as with a lone
3467
+ * `0x06` or `0x15` byte, an `MSH` with no `MSA`, an empty MSA-1, or a value outside the table.
3468
+ * Such a frame is not an HL7 acknowledgement of the message.
3469
+ *
3470
+ * - `'warn'` (default): the send resolves with the frame, as it always has, and the client
3471
+ * emits the `'warning'` `MLLP_ACK_FIFO_MSA1_UNREADABLE` (an {@link AckModeWarning}).
3472
+ * - `'reject'`: the client emits the same warning and the send rejects with
3473
+ * {@link MllpUnreadableAckError}. The frame still takes that send's turn, so the next send
3474
+ * settles on the next frame.
3475
+ *
3476
+ * Has no effect with `correlateByControlId: true`, which matches by MSA-2 and settles nothing
3477
+ * on a frame that has none. Any other value throws a `TypeError` at construction.
3478
+ *
3479
+ * @default 'warn'
3480
+ */
3481
+ readonly fifoUnreadableAck?: "warn" | "reject";
3421
3482
  /**
3422
3483
  * Auto-reconnect on transient disconnect. Default `false`.
3423
3484
  *
@@ -3628,6 +3689,10 @@ interface ClientStats {
3628
3689
  */
3629
3690
  declare class MllpClient extends EventEmitter {
3630
3691
  private readonly _opts;
3692
+ /** The TLS options as they were at construction; never read `_opts.tls`, which the caller owns. */
3693
+ private readonly _tls;
3694
+ /** Why `tls.pfx` cannot be loaded, found once at construction; `undefined` when it loads or is unset. */
3695
+ private readonly _pfxRefusal;
3631
3696
  private _connection;
3632
3697
  private _socket;
3633
3698
  /**
@@ -3644,6 +3709,8 @@ declare class MllpClient extends EventEmitter {
3644
3709
  private readonly _applicationAckTimeoutMs;
3645
3710
  /** controlId-mode flag. `false` → FIFO. */
3646
3711
  private readonly _correlateByControlId;
3712
+ /** Whether a FIFO send settled on a frame with no readable MSA-1 rejects rather than resolves. */
3713
+ private readonly _rejectUnreadableAck;
3647
3714
  /** Unified ACK correlator. Built during `_attachConnection`. */
3648
3715
  private _correlator;
3649
3716
  /**
@@ -4043,6 +4110,12 @@ declare class MllpClient extends EventEmitter {
4043
4110
  * client's). The clock starts at the underlying `write()` flush callback, NOT at
4044
4111
  * the `send()` call.
4045
4112
  * - `MllpConnectionError({ phase: 'send' })` if the client is not connected.
4113
+ * - `MllpUnreadableAckError` with `fifoUnreadableAck: 'reject'`, when the frame that settles
4114
+ * this send in order carries no readable MSA-1.
4115
+ *
4116
+ * Resolving is not acceptance: read MSA-1 off the acknowledgement you are handed. In FIFO
4117
+ * mode a frame with no readable MSA-1 still resolves by default, with the warning
4118
+ * `MLLP_ACK_FIFO_MSA1_UNREADABLE`.
4046
4119
  *
4047
4120
  * Emits a frozen `'ack'` event on every successful match.
4048
4121
  *
@@ -4372,6 +4445,8 @@ interface StarterClientOptions {
4372
4445
  readonly ackTimeoutMs?: number;
4373
4446
  /** Override default `false` (FIFO mode). */
4374
4447
  readonly correlateByControlId?: boolean;
4448
+ /** Passthrough to `ClientOptions.fifoUnreadableAck`, default `'warn'`. */
4449
+ readonly fifoUnreadableAck?: "warn" | "reject";
4375
4450
  /** Override default `true` (parallel up to highWaterMark). */
4376
4451
  readonly pipeline?: boolean;
4377
4452
  /** Override default `64`. */
@@ -4441,6 +4516,7 @@ declare function createStarterClient(opts: StarterClientOptions): Promise<MllpCl
4441
4516
  * - `MllpBackpressureError`, high-water mark exceeded
4442
4517
  * - `MllpNeverDeliveredError`, a send that never reached the transport
4443
4518
  * - `MllpUnknownFateError`, a send whose bytes went out and drew no answer
4519
+ * - `MllpUnreadableAckError`, a FIFO send settled on a frame with no readable MSA-1
4444
4520
  * - `isTransientConnectionError`, transient/permanent classifier
4445
4521
  *
4446
4522
  * Re-exported from `src/client/index.ts` and `src/index.ts`.
@@ -4571,6 +4647,50 @@ declare class MllpApplicationAckError extends Error {
4571
4647
  commitReceivedAt: number;
4572
4648
  });
4573
4649
  }
4650
+ /**
4651
+ * Rejects a `send()` on a client correlating in order (FIFO, the default) when the frame that
4652
+ * settled it carries no readable MSA-1: no HL7 Table 0008 code could be read from it. A lone
4653
+ * `0x06` or `0x15` byte, an `MSH` with no `MSA`, an empty MSA-1 and a value outside the table
4654
+ * all qualify.
4655
+ *
4656
+ * Only raised with `fifoUnreadableAck: 'reject'`; by default the send resolves with the frame
4657
+ * and the client warns `MLLP_ACK_FIFO_MSA1_UNREADABLE`. The frame was written in reply to this
4658
+ * send's turn, so the peer may hold the message: resending it may deliver it twice, and the
4659
+ * receiver's de-duplication on MSH-10 is what makes a resend safe.
4660
+ *
4661
+ * Every field is a number. The frame itself is on the client's `'message'` event.
4662
+ *
4663
+ * @example
4664
+ * ```typescript
4665
+ * try {
4666
+ * await client.send(payload);
4667
+ * } catch (err) {
4668
+ * if (err instanceof MllpUnreadableAckError) {
4669
+ * logger.warn({ msa1Bytes: err.msa1Bytes, at: err.byteOffset });
4670
+ * }
4671
+ * }
4672
+ * ```
4673
+ */
4674
+ declare class MllpUnreadableAckError extends Error {
4675
+ readonly name: "MllpUnreadableAckError";
4676
+ /** Byte length of the MSA-1 field read, `0` when the frame has no `MSH` or no `MSA`. */
4677
+ readonly msa1Bytes: number;
4678
+ /** Stream byte offset of the frame that settled the send. */
4679
+ readonly byteOffset: number;
4680
+ /** Milliseconds between the send's write-flush and that frame. */
4681
+ readonly elapsedMs: number;
4682
+ /**
4683
+ * Construct an unreadable-acknowledgement error.
4684
+ *
4685
+ * @param message - Human-readable error message. Structural facts only, never field content.
4686
+ * @param opts - Failure context (MSA-1 byte length, stream offset, elapsed time).
4687
+ */
4688
+ constructor(message: string, opts: {
4689
+ msa1Bytes: number;
4690
+ byteOffset: number;
4691
+ elapsedMs: number;
4692
+ });
4693
+ }
4574
4694
  /**
4575
4695
  * Rejects a `send()` whose peer answered with a **negative commit**: HL7 Table 0008 `CE`
4576
4696
  * (commit error) or `CR` (commit reject).
@@ -5466,5 +5586,5 @@ declare function runDifferential(options?: DifferentialRunOptions): Promise<Diff
5466
5586
  */
5467
5587
  declare const VERSION: string;
5468
5588
 
5469
- export { ATNA_CIPHER_LIST, ATNA_CIPHER_SUITES, Connection, FrameReader, MLLP_BIND_ALL_INTERFACES, MLLP_CONNECTION_LIMIT_REACHED, MLLP_DIFF_PEER_UNPARSEABLE, MLLP_TLS_CIPHER_LIST_REJECTED, MLLP_TLS_CIPHER_LIST_UNENFORCEABLE, MLLP_TLS_CIPHER_OPTION_CONFLICT, MLLP_TLS_CREDENTIAL_CONFLICT, MLLP_TLS_DH_PARAMETERS_REJECTED, MLLP_TLS_DH_PARAMETERS_UNENFORCEABLE, MLLP_TLS_PFX_REJECTED, MLLP_TLS_VERIFY_DISABLED, MllpAckError, MllpApplicationAckError, MllpBackpressureError, MllpClient, MllpCommitRejectedError, MllpConnectionError, MllpDifferentialConfigurationError, MllpFramingError, MllpNeverDeliveredError, MllpServer, MllpTimeoutError, MllpTlsConfigurationError, MllpUnknownFateError, MllpWarning, NetTransport, TLS13_DEFAULT_CIPHER_SUITES, TlsTransport, Transport, VERSION, WarningCode, ackDiagnosticMessage, ackModeDiagnosticMessage, buildRawAck, canonicalAcknowledgement, canonicalExchanges, createClient, createServer, createStarterClient, createStarterServer, differentialConfigurationMessage, encodeFrame, isTlsProtocolError, isTlsVerificationErrorCode, isTransientConnectionError, rawAckUncorrelatable, readNegotiatedTlsParameters, resolveDifferentialPeer, resolveNackCode, resolveTlsCipherPolicy, runDifferential, selectAckCode, tlsConfigurationMessage };
5589
+ export { ATNA_CIPHER_LIST, ATNA_CIPHER_SUITES, Connection, FrameReader, MLLP_BIND_ALL_INTERFACES, MLLP_CONNECTION_LIMIT_REACHED, MLLP_DIFF_PEER_UNPARSEABLE, MLLP_TLS_CIPHER_LIST_REJECTED, MLLP_TLS_CIPHER_LIST_UNENFORCEABLE, MLLP_TLS_CIPHER_OPTION_CONFLICT, MLLP_TLS_CREDENTIAL_CONFLICT, MLLP_TLS_DH_PARAMETERS_REJECTED, MLLP_TLS_DH_PARAMETERS_UNENFORCEABLE, MLLP_TLS_OPTIONS_NOT_AN_OBJECT, MLLP_TLS_PFX_REJECTED, MLLP_TLS_VERIFY_DISABLED, MllpAckError, MllpApplicationAckError, MllpBackpressureError, MllpClient, MllpCommitRejectedError, MllpConnectionError, MllpDifferentialConfigurationError, MllpFramingError, MllpNeverDeliveredError, MllpServer, MllpTimeoutError, MllpTlsConfigurationError, MllpUnknownFateError, MllpUnreadableAckError, MllpWarning, NetTransport, TLS13_DEFAULT_CIPHER_SUITES, TlsTransport, Transport, VERSION, WarningCode, ackDiagnosticMessage, ackModeDiagnosticMessage, buildRawAck, canonicalAcknowledgement, canonicalExchanges, createClient, createServer, createStarterClient, createStarterServer, differentialConfigurationMessage, encodeFrame, isTlsProtocolError, isTlsVerificationErrorCode, isTransientConnectionError, rawAckUncorrelatable, readNegotiatedTlsParameters, resolveDifferentialPeer, resolveNackCode, resolveTlsCipherPolicy, runDifferential, selectAckCode, tlsConfigurationMessage };
5470
5590
  export type { AckCode, AckCodeSelection, AckCodeSelectionInput, AckCorrelationCode, AckCorrelationWarning, AckModeCode, AckModeWarning, AckModeWarningEvent, ApplicationAckFailure, CanonicalExchange, ClientAuth, ClientOptions, ClientStats, CommitAckReport, ConnectionErrorCause, ConnectionErrorPhase, ConnectionOptions, ConnectionRejectedEvent, ConnectionState, ConnectionStats, DifferentialConfigurationErrorCode, DifferentialConnect, DifferentialCorrelationOutcome, DifferentialDeviation, DifferentialExchangeOutcome, DifferentialExchangeReport, DifferentialParityOutcome, DifferentialPeer, DifferentialReport, DifferentialReportPeer, DifferentialRunOptions, DifferentialRunResult, DifferentialSkipReason, EncoderOptions, FrameReaderOptions, MessageMeta, NackAckCode, NackEvent, NackReason, NegativeAckCode, NegotiatedTlsParameters, PemInput, ReconnectingEvent, ResolvedTlsCipherPolicy, RetryContext, RetryStrategy, SecurityWarning, SecurityWarningCode, ServerOptions, ServerStats, ServerTlsOptions, StarterClientOptions, StarterServerOptions, StateChangeEvent, TlsCipherPolicyInput, TlsConfigurationErrorCode, TlsOptions };