@cosyte/mllp 0.1.13 → 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
@@ -1925,7 +1925,7 @@ declare class MllpConnectionError extends Error {
1925
1925
  * const code: AckModeCode = 'MLLP_ACK_TWO_PHASE_UNAVAILABLE';
1926
1926
  * ```
1927
1927
  */
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";
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";
1929
1929
  /**
1930
1930
  * Look up the frozen diagnostic text for an acknowledgement-mode code.
1931
1931
  *
@@ -2888,9 +2888,10 @@ declare function resolveNackCode(err: unknown): NegativeAckCode;
2888
2888
  * destroyed message was delivered). Three payload-shaped reasons make a positive ACK
2889
2889
  * uncorrelatable, all peer-reachable off the wire:
2890
2890
  *
2891
- * 1. **No readable `MSH`.** `readMshSegment` returns `null`, e.g. a `BOM`/`SP`/`TAB`
2892
- * before `MSH` (which shares the `MSH`'s segment line, so `MSH` heads no segment), or
2893
- * 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`.
2894
2895
  * MSA-2 would be empty: an ACK that correlates to nothing.
2895
2896
  * 2. **Empty MSH-10.** The `MSH` is readable but carries no message control ID, so there
2896
2897
  * is nothing to echo, again `MSA|AA|` with an empty MSA-2.
@@ -3460,6 +3461,24 @@ interface ClientOptions {
3460
3461
  * @default false
3461
3462
  */
3462
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";
3463
3482
  /**
3464
3483
  * Auto-reconnect on transient disconnect. Default `false`.
3465
3484
  *
@@ -3690,6 +3709,8 @@ declare class MllpClient extends EventEmitter {
3690
3709
  private readonly _applicationAckTimeoutMs;
3691
3710
  /** controlId-mode flag. `false` → FIFO. */
3692
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;
3693
3714
  /** Unified ACK correlator. Built during `_attachConnection`. */
3694
3715
  private _correlator;
3695
3716
  /**
@@ -4089,6 +4110,12 @@ declare class MllpClient extends EventEmitter {
4089
4110
  * client's). The clock starts at the underlying `write()` flush callback, NOT at
4090
4111
  * the `send()` call.
4091
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`.
4092
4119
  *
4093
4120
  * Emits a frozen `'ack'` event on every successful match.
4094
4121
  *
@@ -4418,6 +4445,8 @@ interface StarterClientOptions {
4418
4445
  readonly ackTimeoutMs?: number;
4419
4446
  /** Override default `false` (FIFO mode). */
4420
4447
  readonly correlateByControlId?: boolean;
4448
+ /** Passthrough to `ClientOptions.fifoUnreadableAck`, default `'warn'`. */
4449
+ readonly fifoUnreadableAck?: "warn" | "reject";
4421
4450
  /** Override default `true` (parallel up to highWaterMark). */
4422
4451
  readonly pipeline?: boolean;
4423
4452
  /** Override default `64`. */
@@ -4487,6 +4516,7 @@ declare function createStarterClient(opts: StarterClientOptions): Promise<MllpCl
4487
4516
  * - `MllpBackpressureError`, high-water mark exceeded
4488
4517
  * - `MllpNeverDeliveredError`, a send that never reached the transport
4489
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
4490
4520
  * - `isTransientConnectionError`, transient/permanent classifier
4491
4521
  *
4492
4522
  * Re-exported from `src/client/index.ts` and `src/index.ts`.
@@ -4617,6 +4647,50 @@ declare class MllpApplicationAckError extends Error {
4617
4647
  commitReceivedAt: number;
4618
4648
  });
4619
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
+ }
4620
4694
  /**
4621
4695
  * Rejects a `send()` whose peer answered with a **negative commit**: HL7 Table 0008 `CE`
4622
4696
  * (commit error) or `CR` (commit reject).
@@ -5512,5 +5586,5 @@ declare function runDifferential(options?: DifferentialRunOptions): Promise<Diff
5512
5586
  */
5513
5587
  declare const VERSION: string;
5514
5588
 
5515
- 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, 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 };
5516
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
@@ -1925,7 +1925,7 @@ declare class MllpConnectionError extends Error {
1925
1925
  * const code: AckModeCode = 'MLLP_ACK_TWO_PHASE_UNAVAILABLE';
1926
1926
  * ```
1927
1927
  */
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";
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";
1929
1929
  /**
1930
1930
  * Look up the frozen diagnostic text for an acknowledgement-mode code.
1931
1931
  *
@@ -2888,9 +2888,10 @@ declare function resolveNackCode(err: unknown): NegativeAckCode;
2888
2888
  * destroyed message was delivered). Three payload-shaped reasons make a positive ACK
2889
2889
  * uncorrelatable, all peer-reachable off the wire:
2890
2890
  *
2891
- * 1. **No readable `MSH`.** `readMshSegment` returns `null`, e.g. a `BOM`/`SP`/`TAB`
2892
- * before `MSH` (which shares the `MSH`'s segment line, so `MSH` heads no segment), or
2893
- * 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`.
2894
2895
  * MSA-2 would be empty: an ACK that correlates to nothing.
2895
2896
  * 2. **Empty MSH-10.** The `MSH` is readable but carries no message control ID, so there
2896
2897
  * is nothing to echo, again `MSA|AA|` with an empty MSA-2.
@@ -3460,6 +3461,24 @@ interface ClientOptions {
3460
3461
  * @default false
3461
3462
  */
3462
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";
3463
3482
  /**
3464
3483
  * Auto-reconnect on transient disconnect. Default `false`.
3465
3484
  *
@@ -3690,6 +3709,8 @@ declare class MllpClient extends EventEmitter {
3690
3709
  private readonly _applicationAckTimeoutMs;
3691
3710
  /** controlId-mode flag. `false` → FIFO. */
3692
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;
3693
3714
  /** Unified ACK correlator. Built during `_attachConnection`. */
3694
3715
  private _correlator;
3695
3716
  /**
@@ -4089,6 +4110,12 @@ declare class MllpClient extends EventEmitter {
4089
4110
  * client's). The clock starts at the underlying `write()` flush callback, NOT at
4090
4111
  * the `send()` call.
4091
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`.
4092
4119
  *
4093
4120
  * Emits a frozen `'ack'` event on every successful match.
4094
4121
  *
@@ -4418,6 +4445,8 @@ interface StarterClientOptions {
4418
4445
  readonly ackTimeoutMs?: number;
4419
4446
  /** Override default `false` (FIFO mode). */
4420
4447
  readonly correlateByControlId?: boolean;
4448
+ /** Passthrough to `ClientOptions.fifoUnreadableAck`, default `'warn'`. */
4449
+ readonly fifoUnreadableAck?: "warn" | "reject";
4421
4450
  /** Override default `true` (parallel up to highWaterMark). */
4422
4451
  readonly pipeline?: boolean;
4423
4452
  /** Override default `64`. */
@@ -4487,6 +4516,7 @@ declare function createStarterClient(opts: StarterClientOptions): Promise<MllpCl
4487
4516
  * - `MllpBackpressureError`, high-water mark exceeded
4488
4517
  * - `MllpNeverDeliveredError`, a send that never reached the transport
4489
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
4490
4520
  * - `isTransientConnectionError`, transient/permanent classifier
4491
4521
  *
4492
4522
  * Re-exported from `src/client/index.ts` and `src/index.ts`.
@@ -4617,6 +4647,50 @@ declare class MllpApplicationAckError extends Error {
4617
4647
  commitReceivedAt: number;
4618
4648
  });
4619
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
+ }
4620
4694
  /**
4621
4695
  * Rejects a `send()` whose peer answered with a **negative commit**: HL7 Table 0008 `CE`
4622
4696
  * (commit error) or `CR` (commit reject).
@@ -5512,5 +5586,5 @@ declare function runDifferential(options?: DifferentialRunOptions): Promise<Diff
5512
5586
  */
5513
5587
  declare const VERSION: string;
5514
5588
 
5515
- 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, 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 };
5516
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.mjs CHANGED
@@ -1528,9 +1528,12 @@ function segmentEnds(buf) {
1528
1528
  return atCr < atLf ? atCr : atLf;
1529
1529
  };
1530
1530
  }
1531
+ function firstSegmentStart(buf) {
1532
+ return buf[0] === 239 && buf[1] === 187 && buf[2] === 191 ? 3 : 0;
1533
+ }
1531
1534
  function findMshSegment(buf) {
1532
1535
  const segmentEnd = segmentEnds(buf);
1533
- let segStart = 0;
1536
+ let segStart = firstSegmentStart(buf);
1534
1537
  while (segStart < buf.length) {
1535
1538
  const end = segmentEnd(segStart);
1536
1539
  if (isMshSegmentAt(buf, segStart)) return { start: segStart, end };
@@ -1559,7 +1562,7 @@ function isBatchEnvelopeSegmentAt(buf, i) {
1559
1562
  function containsBatchOrExtraMessage(buf) {
1560
1563
  const segmentEnd = segmentEnds(buf);
1561
1564
  let mshCount = 0;
1562
- let segStart = 0;
1565
+ let segStart = firstSegmentStart(buf);
1563
1566
  while (segStart < buf.length) {
1564
1567
  const end = segmentEnd(segStart);
1565
1568
  if (isMshSegmentAt(buf, segStart)) {
@@ -1600,7 +1603,7 @@ function readMsaSegment(buf) {
1600
1603
  if (msh === null) return null;
1601
1604
  const fieldSep = msh.fieldSep.charCodeAt(0);
1602
1605
  const end = buf.length;
1603
- let segStart = 0;
1606
+ let segStart = firstSegmentStart(buf);
1604
1607
  while (segStart < end) {
1605
1608
  let segEnd = segStart;
1606
1609
  while (segEnd < end && buf[segEnd] !== SEGMENT_SEPARATOR_CR && buf[segEnd] !== SEGMENT_SEPARATOR_LF) {
@@ -1828,7 +1831,10 @@ var ACK_MODE_MESSAGES = Object.freeze({
1828
1831
  MLLP_ACK_COMMIT_ALREADY_REPORTED: "A further commit-accept acknowledgement arrived for a send whose commit disposition had already been reported; it was surfaced and neither re-reported nor allowed to restart the application-acknowledgement wait. The send is still pending.",
1829
1832
  MLLP_ACK_MSA1_ABSENT: "An acknowledgement matched to an enhanced-mode send carried no MSA-1 acknowledgement code, so it was not classified into a mode and the send was left pending. Field values are withheld; msa1Bytes gives the field's length.",
1830
1833
  MLLP_ACK_MSA1_UNCLASSIFIABLE: "An acknowledgement matched to an enhanced-mode send carried an MSA-1 value outside HL7 Table 0008, so it was not classified into a mode and the send was left pending. Field values are withheld; msa1Bytes gives the field's length.",
1831
- MLLP_ACK_SEND_ALREADY_DISPOSED: "An acknowledgement arrived for a send that had already been settled or failed; it was dropped and that outcome was left unchanged. Field values are withheld: a control ID is payload content and this diagnostic goes to a log."
1834
+ MLLP_ACK_SEND_ALREADY_DISPOSED: "An acknowledgement arrived for a send that had already been settled or failed; it was dropped and that outcome was left unchanged. Field values are withheld: a control ID is payload content and this diagnostic goes to a log.",
1835
+ // Stryker disable StringLiteral: a module-level initializer runs once, when the module is first loaded, so per-test coverage credits it to whichever test loaded the module first rather than to the tests that assert this value (test/client/fifo-unreadable-ack.test.ts asserts it literally).
1836
+ MLLP_ACK_FIFO_MSA1_UNREADABLE: "A client correlating acknowledgements in order settled its oldest pending send on a frame with no readable MSA-1 acknowledgement code, so the peer has not acknowledged that message in HL7 terms. The send resolved with the frame, or rejected when fifoUnreadableAck is 'reject'. Set correlateByControlId to match acknowledgements by MSA-2 instead. Field values are withheld; msa1Bytes gives the field's length."
1837
+ // Stryker restore StringLiteral
1832
1838
  });
1833
1839
  function ackModeDiagnosticMessage(code) {
1834
1840
  return ACK_MODE_MESSAGES[code];
@@ -2840,6 +2846,7 @@ var Correlator = class {
2840
2846
  onCommitReported: opts.onCommitReported,
2841
2847
  onCommitRejected: opts.onCommitRejected,
2842
2848
  onApplicationAckTimeout: opts.onApplicationAckTimeout,
2849
+ onUnreadableAck: opts.onUnreadableAck,
2843
2850
  now: opts.now ?? Date.now
2844
2851
  };
2845
2852
  }
@@ -2904,6 +2911,9 @@ var Correlator = class {
2904
2911
  *
2905
2912
  * - FIFO: returns first pending entry by insertion order; entry is
2906
2913
  * removed from live store. Caller calls `entry.resolve(ackPayload)`.
2914
+ * A frame with no readable MSA-1 is reported as
2915
+ * `MLLP_ACK_FIFO_MSA1_UNREADABLE` first, and when `onUnreadableAck` is
2916
+ * wired it is handed the entry instead and `null` is returned.
2907
2917
  * - controlId: keyed lookup by `controlIdFromAck`. Live-store hit returns
2908
2918
  * the entry; graveyard hit fires `MLLP_ACK_AFTER_TIMEOUT` warning
2909
2919
  * and returns `null`; otherwise fires `onUnmatchedAck` with the id's
@@ -2930,7 +2940,24 @@ var Correlator = class {
2930
2940
  this._pending.delete(entry.key);
2931
2941
  this._queueBytes -= entry.byteCount;
2932
2942
  if (entry.sentAt !== null) this._inFlight -= 1;
2933
- return entry;
2943
+ const classification = classifyMsa1(payload);
2944
+ if (classification.kind === "code") return entry;
2945
+ const elapsedSinceSendMs = entry.sentAt === null ? 0 : this._opts.now() - entry.sentAt;
2946
+ this._ackModeWarn("MLLP_ACK_FIFO_MSA1_UNREADABLE", {
2947
+ msa1Bytes: classification.byteLength,
2948
+ ackCode: null,
2949
+ controlIdBytes: null,
2950
+ byteOffset: byteOffsetFromAck,
2951
+ elapsedSinceSendMs
2952
+ });
2953
+ if (this._opts.onUnreadableAck === void 0) return entry;
2954
+ this._opts.onUnreadableAck(
2955
+ entry,
2956
+ classification.byteLength,
2957
+ byteOffsetFromAck,
2958
+ elapsedSinceSendMs
2959
+ );
2960
+ return null;
2934
2961
  }
2935
2962
  if (controlIdFromAck === null) {
2936
2963
  if (this._opts.onUnmatchedAck !== void 0) {
@@ -3277,6 +3304,30 @@ var MllpApplicationAckError = class _MllpApplicationAckError extends Error {
3277
3304
  }
3278
3305
  }
3279
3306
  };
3307
+ var MllpUnreadableAckError = class _MllpUnreadableAckError extends Error {
3308
+ name = "MllpUnreadableAckError";
3309
+ /** Byte length of the MSA-1 field read, `0` when the frame has no `MSH` or no `MSA`. */
3310
+ msa1Bytes;
3311
+ /** Stream byte offset of the frame that settled the send. */
3312
+ byteOffset;
3313
+ /** Milliseconds between the send's write-flush and that frame. */
3314
+ elapsedMs;
3315
+ /**
3316
+ * Construct an unreadable-acknowledgement error.
3317
+ *
3318
+ * @param message - Human-readable error message. Structural facts only, never field content.
3319
+ * @param opts - Failure context (MSA-1 byte length, stream offset, elapsed time).
3320
+ */
3321
+ constructor(message, opts) {
3322
+ super(message);
3323
+ this.msa1Bytes = opts.msa1Bytes;
3324
+ this.byteOffset = opts.byteOffset;
3325
+ this.elapsedMs = opts.elapsedMs;
3326
+ if (Error.captureStackTrace) {
3327
+ Error.captureStackTrace(this, _MllpUnreadableAckError);
3328
+ }
3329
+ }
3330
+ };
3280
3331
  var MllpCommitRejectedError = class _MllpCommitRejectedError extends Error {
3281
3332
  name = "MllpCommitRejectedError";
3282
3333
  /** The negative accept-mode code the peer sent. */
@@ -3489,6 +3540,8 @@ var MllpClient = class extends EventEmitter {
3489
3540
  _applicationAckTimeoutMs;
3490
3541
  /** controlId-mode flag. `false` → FIFO. */
3491
3542
  _correlateByControlId;
3543
+ /** Whether a FIFO send settled on a frame with no readable MSA-1 rejects rather than resolves. */
3544
+ _rejectUnreadableAck;
3492
3545
  /** Unified ACK correlator. Built during `_attachConnection`. */
3493
3546
  _correlator = null;
3494
3547
  /**
@@ -3608,6 +3661,12 @@ var MllpClient = class extends EventEmitter {
3608
3661
  "ClientOptions.connectTimeoutMs must be an integer from 1 to 2147483647, or left unset for no bound"
3609
3662
  );
3610
3663
  }
3664
+ const fifoUnreadableAck = opts.fifoUnreadableAck;
3665
+ if (fifoUnreadableAck !== void 0 && fifoUnreadableAck !== "warn" && fifoUnreadableAck !== "reject") {
3666
+ throw new TypeError(
3667
+ "ClientOptions.fifoUnreadableAck must be 'warn' or 'reject', or left unset for 'warn'"
3668
+ );
3669
+ }
3611
3670
  const tls = copyTlsOptions(opts.tls);
3612
3671
  checkCredentialMix(tls);
3613
3672
  this._pfxRefusal = typeof tls === "object" ? pfxRefusal(tls.pfx, tls.passphrase) : void 0;
@@ -3616,6 +3675,7 @@ var MllpClient = class extends EventEmitter {
3616
3675
  this._ackTimeoutMs = opts.ackTimeoutMs ?? 3e4;
3617
3676
  this._applicationAckTimeoutMs = opts.applicationAckTimeoutMs;
3618
3677
  this._correlateByControlId = opts.correlateByControlId === true;
3678
+ this._rejectUnreadableAck = fifoUnreadableAck === "reject";
3619
3679
  this._autoReconnect = opts.autoReconnect === true;
3620
3680
  this._initialDelayMs = opts.initialDelayMs ?? 100;
3621
3681
  this._maxDelayMs = opts.maxDelayMs ?? 3e4;
@@ -4107,7 +4167,18 @@ var MllpClient = class extends EventEmitter {
4107
4167
  },
4108
4168
  onAckModeWarning: (code, ctx) => {
4109
4169
  this._emitAckModeWarning(code, ctx, conn);
4110
- }
4170
+ },
4171
+ ...this._rejectUnreadableAck ? {
4172
+ onUnreadableAck: (entry, msa1Bytes, byteOffset, elapsedMs) => {
4173
+ entry.reject(
4174
+ new MllpUnreadableAckError(
4175
+ "the frame that settled this send in order carried no readable MSA-1, so the peer has not acknowledged it in HL7 terms",
4176
+ { msa1Bytes, byteOffset, elapsedMs }
4177
+ )
4178
+ );
4179
+ this._maybeEmitDrain();
4180
+ }
4181
+ } : {}
4111
4182
  });
4112
4183
  }
4113
4184
  if (this._ackSweepTimer === null) {
@@ -4540,6 +4611,12 @@ var MllpClient = class extends EventEmitter {
4540
4611
  * client's). The clock starts at the underlying `write()` flush callback, NOT at
4541
4612
  * the `send()` call.
4542
4613
  * - `MllpConnectionError({ phase: 'send' })` if the client is not connected.
4614
+ * - `MllpUnreadableAckError` with `fifoUnreadableAck: 'reject'`, when the frame that settles
4615
+ * this send in order carries no readable MSA-1.
4616
+ *
4617
+ * Resolving is not acceptance: read MSA-1 off the acknowledgement you are handed. In FIFO
4618
+ * mode a frame with no readable MSA-1 still resolves by default, with the warning
4619
+ * `MLLP_ACK_FIFO_MSA1_UNREADABLE`.
4543
4620
  *
4544
4621
  * Emits a frozen `'ack'` event on every successful match.
4545
4622
  *
@@ -5197,6 +5274,7 @@ async function createStarterClient(opts) {
5197
5274
  pipeline: opts.pipeline ?? true,
5198
5275
  highWaterMark: opts.highWaterMark ?? 64,
5199
5276
  onBackpressure: opts.onBackpressure ?? "reject",
5277
+ fifoUnreadableAck: opts.fifoUnreadableAck ?? "warn",
5200
5278
  ...opts.drainTimeoutMs !== void 0 ? { drainTimeoutMs: opts.drainTimeoutMs } : {},
5201
5279
  ...opts.framing !== void 0 ? { framing: opts.framing } : {},
5202
5280
  ...opts.retryStrategy !== void 0 ? { retryStrategy: opts.retryStrategy } : {},
@@ -5524,8 +5602,8 @@ async function runDifferential(options = {}) {
5524
5602
  }
5525
5603
 
5526
5604
  // src/index.ts
5527
- var VERSION = "0.1.13";
5605
+ var VERSION = "0.1.14";
5528
5606
 
5529
- 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, NetTransport, TLS13_DEFAULT_CIPHER_SUITES, TlsTransport, VERSION, ackDiagnosticMessage, ackModeDiagnosticMessage, buildRawAck, canonicalAcknowledgement, canonicalExchanges, createClient, createServer, createStarterClient, createStarterServer, createWarning, differentialConfigurationMessage, encodeFrame, isTlsProtocolError, isTlsVerificationErrorCode, isTransientConnectionError, rawAckUncorrelatable, readNegotiatedTlsParameters, resolveDifferentialPeer, resolveNackCode, resolveTlsCipherPolicy, runDifferential, selectAckCode, tlsConfigurationMessage };
5607
+ 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, NetTransport, TLS13_DEFAULT_CIPHER_SUITES, TlsTransport, VERSION, ackDiagnosticMessage, ackModeDiagnosticMessage, buildRawAck, canonicalAcknowledgement, canonicalExchanges, createClient, createServer, createStarterClient, createStarterServer, createWarning, differentialConfigurationMessage, encodeFrame, isTlsProtocolError, isTlsVerificationErrorCode, isTransientConnectionError, rawAckUncorrelatable, readNegotiatedTlsParameters, resolveDifferentialPeer, resolveNackCode, resolveTlsCipherPolicy, runDifferential, selectAckCode, tlsConfigurationMessage };
5530
5608
  //# sourceMappingURL=index.mjs.map
5531
5609
  //# sourceMappingURL=index.mjs.map