@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/CHANGELOG.md +13 -0
- package/dist/ack-from-hl7/index.cjs +5 -2
- package/dist/ack-from-hl7/index.cjs.map +1 -1
- package/dist/ack-from-hl7/index.mjs +5 -2
- package/dist/ack-from-hl7/index.mjs.map +1 -1
- package/dist/index.cjs +182 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +133 -13
- package/dist/index.d.ts +133 -13
- package/dist/index.mjs +181 -36
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -2
package/dist/index.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import { createSecureContext, createServer as createServer$2, connect, checkServ
|
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
3
|
import { randomUUID } from 'crypto';
|
|
4
4
|
import { createServer as createServer$1, createConnection, isIP, SocketAddress } from 'net';
|
|
5
|
+
import { types } from 'util';
|
|
5
6
|
|
|
6
7
|
// src/framing/registry.ts
|
|
7
8
|
function createWarning(code, byteOffset, message) {
|
|
@@ -648,6 +649,7 @@ var MLLP_TLS_CIPHER_LIST_UNENFORCEABLE = "MLLP_TLS_CIPHER_LIST_UNENFORCEABLE";
|
|
|
648
649
|
var MLLP_TLS_DH_PARAMETERS_UNENFORCEABLE = "MLLP_TLS_DH_PARAMETERS_UNENFORCEABLE";
|
|
649
650
|
var MLLP_TLS_PFX_REJECTED = "MLLP_TLS_PFX_REJECTED";
|
|
650
651
|
var MLLP_TLS_CREDENTIAL_CONFLICT = "MLLP_TLS_CREDENTIAL_CONFLICT";
|
|
652
|
+
var MLLP_TLS_OPTIONS_NOT_AN_OBJECT = "MLLP_TLS_OPTIONS_NOT_AN_OBJECT";
|
|
651
653
|
function tlsConfigurationMessage(code) {
|
|
652
654
|
const messages = {
|
|
653
655
|
[MLLP_TLS_CIPHER_LIST_REJECTED]: "the TLS library rejected the configured cipher-suite list; no connection was opened and no fallback to the runtime default list was made",
|
|
@@ -656,7 +658,8 @@ function tlsConfigurationMessage(code) {
|
|
|
656
658
|
[MLLP_TLS_CIPHER_LIST_UNENFORCEABLE]: "this runtime's TLS library does not enforce a configured cipher-suite list; no connection was opened, rather than one offering a list other than the one configured",
|
|
657
659
|
[MLLP_TLS_DH_PARAMETERS_UNENFORCEABLE]: "this runtime's TLS library does not enforce server Diffie-Hellman parameters; nothing was bound, rather than a server running without the parameters configured",
|
|
658
660
|
[MLLP_TLS_PFX_REJECTED]: "tls.pfx could not be loaded with tls.passphrase: the passphrase is wrong, the file is not PKCS#12, or it uses a legacy encryption (RC2-40, as `openssl pkcs12 -export -legacy` and older exports write it) that OpenSSL 3 does not load, so re-export it with AES-256; no socket was opened",
|
|
659
|
-
[MLLP_TLS_CREDENTIAL_CONFLICT]: "tls.pfx was set together with tls.cert or tls.key; the PKCS#12 file carries its own certificate and key, so set either cert and key or pfx, not both"
|
|
661
|
+
[MLLP_TLS_CREDENTIAL_CONFLICT]: "tls.pfx was set together with tls.cert or tls.key; the PKCS#12 file carries its own certificate and key, so set either cert and key or pfx, not both",
|
|
662
|
+
[MLLP_TLS_OPTIONS_NOT_AN_OBJECT]: "tls must be an object of TLS options, or true for a client's defaults; it was null, an array, another kind of object or a value that is no object, and no client or server was created"
|
|
660
663
|
};
|
|
661
664
|
return messages[code];
|
|
662
665
|
}
|
|
@@ -924,14 +927,23 @@ function readNegotiatedTlsParameters(socket, host, port) {
|
|
|
924
927
|
const cipher = socket.getCipher();
|
|
925
928
|
const cipherSuite = cipher.standardName === "" ? cipher.name : cipher.standardName;
|
|
926
929
|
if (cipherSuite === "") return null;
|
|
930
|
+
const keyExchangeGroup = readKeyExchangeGroup(socket);
|
|
927
931
|
return Object.freeze({
|
|
928
932
|
protocolVersion,
|
|
929
933
|
cipherSuite,
|
|
934
|
+
...keyExchangeGroup === void 0 ? {} : { keyExchangeGroup },
|
|
930
935
|
host,
|
|
931
936
|
port,
|
|
932
937
|
timestamp: /* @__PURE__ */ new Date()
|
|
933
938
|
});
|
|
934
939
|
}
|
|
940
|
+
function readKeyExchangeGroup(socket) {
|
|
941
|
+
if (typeof socket.getEphemeralKeyInfo !== "function") return void 0;
|
|
942
|
+
const info = socket.getEphemeralKeyInfo();
|
|
943
|
+
if (typeof info !== "object" || info === null || !("name" in info)) return void 0;
|
|
944
|
+
const { name } = info;
|
|
945
|
+
return typeof name === "string" && name !== "" ? name : void 0;
|
|
946
|
+
}
|
|
935
947
|
|
|
936
948
|
// src/connection/error.ts
|
|
937
949
|
var MllpConnectionError = class _MllpConnectionError extends Error {
|
|
@@ -1429,14 +1441,59 @@ function checkCredentialMix(tls) {
|
|
|
1429
1441
|
throw new MllpTlsConfigurationError(MLLP_TLS_CREDENTIAL_CONFLICT);
|
|
1430
1442
|
}
|
|
1431
1443
|
}
|
|
1432
|
-
function
|
|
1433
|
-
if (pfx === void 0) return;
|
|
1444
|
+
function pfxRefusal(pfx, passphrase) {
|
|
1445
|
+
if (pfx === void 0) return void 0;
|
|
1434
1446
|
try {
|
|
1435
1447
|
createSecureContext({ pfx, passphrase });
|
|
1448
|
+
return void 0;
|
|
1436
1449
|
} catch (err) {
|
|
1437
|
-
|
|
1450
|
+
return new MllpTlsConfigurationError(MLLP_TLS_PFX_REJECTED, { cause: err });
|
|
1438
1451
|
}
|
|
1439
1452
|
}
|
|
1453
|
+
function checkPfx(pfx, passphrase) {
|
|
1454
|
+
const refusal = pfxRefusal(pfx, passphrase);
|
|
1455
|
+
if (refusal !== void 0) throw refusal;
|
|
1456
|
+
}
|
|
1457
|
+
function tlsOptionNames() {
|
|
1458
|
+
const names = {
|
|
1459
|
+
ca: "ca",
|
|
1460
|
+
cert: "cert",
|
|
1461
|
+
key: "key",
|
|
1462
|
+
passphrase: "passphrase",
|
|
1463
|
+
pfx: "pfx",
|
|
1464
|
+
servername: "servername",
|
|
1465
|
+
minVersion: "minVersion",
|
|
1466
|
+
maxVersion: "maxVersion",
|
|
1467
|
+
atnaTransportSecurity: "atnaTransportSecurity",
|
|
1468
|
+
ciphers: "ciphers",
|
|
1469
|
+
allowUnverified: "allowUnverified",
|
|
1470
|
+
clientAuth: "clientAuth",
|
|
1471
|
+
dhParameters: "dhParameters"
|
|
1472
|
+
};
|
|
1473
|
+
return Object.values(names);
|
|
1474
|
+
}
|
|
1475
|
+
function copyValue(value) {
|
|
1476
|
+
return ArrayBuffer.isView(value) ? Buffer.from(new Uint8Array(value.buffer, value.byteOffset, value.byteLength)) : value;
|
|
1477
|
+
}
|
|
1478
|
+
function isOptionsObject(value) {
|
|
1479
|
+
if (typeof value !== "object" || value === null) return false;
|
|
1480
|
+
return !(Array.isArray(value) || ArrayBuffer.isView(value) || types.isAnyArrayBuffer(value) || types.isMap(value) || types.isSet(value) || types.isDate(value) || types.isPromise(value) || types.isBoxedPrimitive(value));
|
|
1481
|
+
}
|
|
1482
|
+
function copyTlsOptions(tls) {
|
|
1483
|
+
if (tls === void 0 || tls === true) return tls;
|
|
1484
|
+
const given = tls;
|
|
1485
|
+
if (!isOptionsObject(given)) {
|
|
1486
|
+
throw new MllpTlsConfigurationError(MLLP_TLS_OPTIONS_NOT_AN_OBJECT);
|
|
1487
|
+
}
|
|
1488
|
+
const source = given;
|
|
1489
|
+
const copy = {};
|
|
1490
|
+
for (const name of tlsOptionNames()) {
|
|
1491
|
+
const value = source[name];
|
|
1492
|
+
if (value === void 0) continue;
|
|
1493
|
+
copy[name] = Array.isArray(value) ? value.map(copyValue) : copyValue(value);
|
|
1494
|
+
}
|
|
1495
|
+
return copy;
|
|
1496
|
+
}
|
|
1440
1497
|
|
|
1441
1498
|
// src/internal/control-id.ts
|
|
1442
1499
|
var ASCII_M = 77;
|
|
@@ -1471,9 +1528,12 @@ function segmentEnds(buf) {
|
|
|
1471
1528
|
return atCr < atLf ? atCr : atLf;
|
|
1472
1529
|
};
|
|
1473
1530
|
}
|
|
1531
|
+
function firstSegmentStart(buf) {
|
|
1532
|
+
return buf[0] === 239 && buf[1] === 187 && buf[2] === 191 ? 3 : 0;
|
|
1533
|
+
}
|
|
1474
1534
|
function findMshSegment(buf) {
|
|
1475
1535
|
const segmentEnd = segmentEnds(buf);
|
|
1476
|
-
let segStart =
|
|
1536
|
+
let segStart = firstSegmentStart(buf);
|
|
1477
1537
|
while (segStart < buf.length) {
|
|
1478
1538
|
const end = segmentEnd(segStart);
|
|
1479
1539
|
if (isMshSegmentAt(buf, segStart)) return { start: segStart, end };
|
|
@@ -1502,7 +1562,7 @@ function isBatchEnvelopeSegmentAt(buf, i) {
|
|
|
1502
1562
|
function containsBatchOrExtraMessage(buf) {
|
|
1503
1563
|
const segmentEnd = segmentEnds(buf);
|
|
1504
1564
|
let mshCount = 0;
|
|
1505
|
-
let segStart =
|
|
1565
|
+
let segStart = firstSegmentStart(buf);
|
|
1506
1566
|
while (segStart < buf.length) {
|
|
1507
1567
|
const end = segmentEnd(segStart);
|
|
1508
1568
|
if (isMshSegmentAt(buf, segStart)) {
|
|
@@ -1543,7 +1603,7 @@ function readMsaSegment(buf) {
|
|
|
1543
1603
|
if (msh === null) return null;
|
|
1544
1604
|
const fieldSep = msh.fieldSep.charCodeAt(0);
|
|
1545
1605
|
const end = buf.length;
|
|
1546
|
-
let segStart =
|
|
1606
|
+
let segStart = firstSegmentStart(buf);
|
|
1547
1607
|
while (segStart < end) {
|
|
1548
1608
|
let segEnd = segStart;
|
|
1549
1609
|
while (segEnd < end && buf[segEnd] !== SEGMENT_SEPARATOR_CR && buf[segEnd] !== SEGMENT_SEPARATOR_LF) {
|
|
@@ -1771,7 +1831,10 @@ var ACK_MODE_MESSAGES = Object.freeze({
|
|
|
1771
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.",
|
|
1772
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.",
|
|
1773
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.",
|
|
1774
|
-
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
|
|
1775
1838
|
});
|
|
1776
1839
|
function ackModeDiagnosticMessage(code) {
|
|
1777
1840
|
return ACK_MODE_MESSAGES[code];
|
|
@@ -1823,6 +1886,8 @@ var MllpServer = class extends EventEmitter {
|
|
|
1823
1886
|
_netServer;
|
|
1824
1887
|
_connections = /* @__PURE__ */ new Set();
|
|
1825
1888
|
_opts;
|
|
1889
|
+
/** The TLS options as they were at construction; never read `_opts.tls`, which the caller owns. */
|
|
1890
|
+
_tls;
|
|
1826
1891
|
/** `true` when `ServerOptions.tls` is set, `_netServer` is actually a `tls.Server`. */
|
|
1827
1892
|
_isTls;
|
|
1828
1893
|
_listening = false;
|
|
@@ -1877,27 +1942,33 @@ var MllpServer = class extends EventEmitter {
|
|
|
1877
1942
|
"ServerOptions.maxConnections must be a positive integer, or left unset for no cap"
|
|
1878
1943
|
);
|
|
1879
1944
|
}
|
|
1880
|
-
const tlsInput = opts.tls;
|
|
1945
|
+
const tlsInput = copyTlsOptions(opts.tls);
|
|
1881
1946
|
checkCredentialMix(tlsInput);
|
|
1882
1947
|
if (tlsInput !== void 0 && tlsInput.pfx === void 0 && (tlsInput.cert === void 0 || tlsInput.key === void 0)) {
|
|
1883
1948
|
throw new TypeError("ServerOptions.tls needs cert and key, or pfx");
|
|
1884
1949
|
}
|
|
1885
1950
|
this._opts = opts;
|
|
1886
|
-
this.
|
|
1951
|
+
this._tls = tlsInput;
|
|
1952
|
+
this._isTls = tlsInput !== void 0;
|
|
1887
1953
|
let cipherPolicy = null;
|
|
1888
|
-
if (
|
|
1954
|
+
if (tlsInput !== void 0) {
|
|
1889
1955
|
try {
|
|
1890
|
-
checkPfx(
|
|
1891
|
-
cipherPolicy = resolveTlsCipherPolicy(
|
|
1956
|
+
checkPfx(tlsInput.pfx, tlsInput.passphrase);
|
|
1957
|
+
cipherPolicy = resolveTlsCipherPolicy(tlsInput, "server");
|
|
1892
1958
|
} catch (err) {
|
|
1893
1959
|
if (!(err instanceof MllpTlsConfigurationError)) throw err;
|
|
1894
1960
|
this._tlsConfigError = err;
|
|
1895
1961
|
}
|
|
1896
1962
|
}
|
|
1897
|
-
if (
|
|
1963
|
+
if (tlsInput === void 0) {
|
|
1898
1964
|
this._netServer = createServer$1();
|
|
1899
|
-
|
|
1900
|
-
|
|
1965
|
+
this._netServer.on("connection", (socket) => {
|
|
1966
|
+
this._onSocketAccepted(socket);
|
|
1967
|
+
});
|
|
1968
|
+
} else if (cipherPolicy === null) {
|
|
1969
|
+
this._netServer = createServer$1();
|
|
1970
|
+
} else {
|
|
1971
|
+
const tlsOpts = tlsInput;
|
|
1901
1972
|
const clientAuth = tlsOpts.clientAuth ?? "NONE";
|
|
1902
1973
|
const tlsServer = createServer$2({
|
|
1903
1974
|
cert: tlsOpts.cert,
|
|
@@ -1928,11 +1999,6 @@ var MllpServer = class extends EventEmitter {
|
|
|
1928
1999
|
});
|
|
1929
2000
|
this._emitContained("tlsClientError", event);
|
|
1930
2001
|
});
|
|
1931
|
-
} else {
|
|
1932
|
-
this._netServer = createServer$1();
|
|
1933
|
-
this._netServer.on("connection", (socket) => {
|
|
1934
|
-
this._onSocketAccepted(socket);
|
|
1935
|
-
});
|
|
1936
2002
|
}
|
|
1937
2003
|
this._netServer.on("error", (err) => {
|
|
1938
2004
|
if (this.listenerCount("error") > 0) {
|
|
@@ -2444,7 +2510,7 @@ var MllpServer = class extends EventEmitter {
|
|
|
2444
2510
|
}
|
|
2445
2511
|
}
|
|
2446
2512
|
);
|
|
2447
|
-
const peerCertificate =
|
|
2513
|
+
const peerCertificate = (this._tls?.clientAuth ?? "NONE") !== "NONE" ? this._extractPeerCertificateSummary(socket) : null;
|
|
2448
2514
|
this._emitContained(
|
|
2449
2515
|
"connection",
|
|
2450
2516
|
Object.freeze({
|
|
@@ -2780,6 +2846,7 @@ var Correlator = class {
|
|
|
2780
2846
|
onCommitReported: opts.onCommitReported,
|
|
2781
2847
|
onCommitRejected: opts.onCommitRejected,
|
|
2782
2848
|
onApplicationAckTimeout: opts.onApplicationAckTimeout,
|
|
2849
|
+
onUnreadableAck: opts.onUnreadableAck,
|
|
2783
2850
|
now: opts.now ?? Date.now
|
|
2784
2851
|
};
|
|
2785
2852
|
}
|
|
@@ -2844,6 +2911,9 @@ var Correlator = class {
|
|
|
2844
2911
|
*
|
|
2845
2912
|
* - FIFO: returns first pending entry by insertion order; entry is
|
|
2846
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.
|
|
2847
2917
|
* - controlId: keyed lookup by `controlIdFromAck`. Live-store hit returns
|
|
2848
2918
|
* the entry; graveyard hit fires `MLLP_ACK_AFTER_TIMEOUT` warning
|
|
2849
2919
|
* and returns `null`; otherwise fires `onUnmatchedAck` with the id's
|
|
@@ -2870,7 +2940,24 @@ var Correlator = class {
|
|
|
2870
2940
|
this._pending.delete(entry.key);
|
|
2871
2941
|
this._queueBytes -= entry.byteCount;
|
|
2872
2942
|
if (entry.sentAt !== null) this._inFlight -= 1;
|
|
2873
|
-
|
|
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;
|
|
2874
2961
|
}
|
|
2875
2962
|
if (controlIdFromAck === null) {
|
|
2876
2963
|
if (this._opts.onUnmatchedAck !== void 0) {
|
|
@@ -3217,6 +3304,30 @@ var MllpApplicationAckError = class _MllpApplicationAckError extends Error {
|
|
|
3217
3304
|
}
|
|
3218
3305
|
}
|
|
3219
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
|
+
};
|
|
3220
3331
|
var MllpCommitRejectedError = class _MllpCommitRejectedError extends Error {
|
|
3221
3332
|
name = "MllpCommitRejectedError";
|
|
3222
3333
|
/** The negative accept-mode code the peer sent. */
|
|
@@ -3409,6 +3520,10 @@ function identityOptions(host, servername) {
|
|
|
3409
3520
|
}
|
|
3410
3521
|
var MllpClient = class extends EventEmitter {
|
|
3411
3522
|
_opts;
|
|
3523
|
+
/** The TLS options as they were at construction; never read `_opts.tls`, which the caller owns. */
|
|
3524
|
+
_tls;
|
|
3525
|
+
/** Why `tls.pfx` cannot be loaded, found once at construction; `undefined` when it loads or is unset. */
|
|
3526
|
+
_pfxRefusal;
|
|
3412
3527
|
_connection = null;
|
|
3413
3528
|
_socket = null;
|
|
3414
3529
|
/**
|
|
@@ -3425,6 +3540,8 @@ var MllpClient = class extends EventEmitter {
|
|
|
3425
3540
|
_applicationAckTimeoutMs;
|
|
3426
3541
|
/** controlId-mode flag. `false` → FIFO. */
|
|
3427
3542
|
_correlateByControlId;
|
|
3543
|
+
/** Whether a FIFO send settled on a frame with no readable MSA-1 rejects rather than resolves. */
|
|
3544
|
+
_rejectUnreadableAck;
|
|
3428
3545
|
/** Unified ACK correlator. Built during `_attachConnection`. */
|
|
3429
3546
|
_correlator = null;
|
|
3430
3547
|
/**
|
|
@@ -3544,11 +3661,21 @@ var MllpClient = class extends EventEmitter {
|
|
|
3544
3661
|
"ClientOptions.connectTimeoutMs must be an integer from 1 to 2147483647, or left unset for no bound"
|
|
3545
3662
|
);
|
|
3546
3663
|
}
|
|
3547
|
-
|
|
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
|
+
}
|
|
3670
|
+
const tls = copyTlsOptions(opts.tls);
|
|
3671
|
+
checkCredentialMix(tls);
|
|
3672
|
+
this._pfxRefusal = typeof tls === "object" ? pfxRefusal(tls.pfx, tls.passphrase) : void 0;
|
|
3673
|
+
this._tls = tls;
|
|
3548
3674
|
this._opts = opts;
|
|
3549
3675
|
this._ackTimeoutMs = opts.ackTimeoutMs ?? 3e4;
|
|
3550
3676
|
this._applicationAckTimeoutMs = opts.applicationAckTimeoutMs;
|
|
3551
3677
|
this._correlateByControlId = opts.correlateByControlId === true;
|
|
3678
|
+
this._rejectUnreadableAck = fifoUnreadableAck === "reject";
|
|
3552
3679
|
this._autoReconnect = opts.autoReconnect === true;
|
|
3553
3680
|
this._initialDelayMs = opts.initialDelayMs ?? 100;
|
|
3554
3681
|
this._maxDelayMs = opts.maxDelayMs ?? 3e4;
|
|
@@ -3662,7 +3789,7 @@ var MllpClient = class extends EventEmitter {
|
|
|
3662
3789
|
}
|
|
3663
3790
|
const conn = new Connection(connOpts);
|
|
3664
3791
|
this._attachConnection(conn);
|
|
3665
|
-
const connectEventName = this.
|
|
3792
|
+
const connectEventName = this._tls !== void 0 ? "secureConnect" : "connect";
|
|
3666
3793
|
this._armConnectTimeout(socket, connectEventName);
|
|
3667
3794
|
const cleanup = () => {
|
|
3668
3795
|
if (signal !== void 0) {
|
|
@@ -3732,14 +3859,14 @@ var MllpClient = class extends EventEmitter {
|
|
|
3732
3859
|
* against it.
|
|
3733
3860
|
*/
|
|
3734
3861
|
_createSocketAndTransport() {
|
|
3735
|
-
const tlsOpt = this.
|
|
3862
|
+
const tlsOpt = this._tls;
|
|
3736
3863
|
if (tlsOpt === void 0) {
|
|
3737
3864
|
const socket2 = createConnection({ host: this._opts.host, port: this._opts.port });
|
|
3738
3865
|
return { socket: socket2, transport: new NetTransport(socket2) };
|
|
3739
3866
|
}
|
|
3740
3867
|
const tlsOpts = tlsOpt === true ? {} : tlsOpt;
|
|
3741
3868
|
const cipherPolicy = resolveTlsCipherPolicy(tlsOpts, "client");
|
|
3742
|
-
|
|
3869
|
+
if (this._pfxRefusal !== void 0) throw this._pfxRefusal;
|
|
3743
3870
|
const socket = connect({
|
|
3744
3871
|
host: this._opts.host,
|
|
3745
3872
|
port: this._opts.port,
|
|
@@ -3800,7 +3927,7 @@ var MllpClient = class extends EventEmitter {
|
|
|
3800
3927
|
connectionCause: "connect-timeout"
|
|
3801
3928
|
});
|
|
3802
3929
|
}
|
|
3803
|
-
if (this.
|
|
3930
|
+
if (this._tls === void 0) {
|
|
3804
3931
|
return new MllpConnectionError(err.message, { cause: err, phase });
|
|
3805
3932
|
}
|
|
3806
3933
|
const code = err.code;
|
|
@@ -3909,7 +4036,7 @@ var MllpClient = class extends EventEmitter {
|
|
|
3909
4036
|
* connections or when verification is on.
|
|
3910
4037
|
*/
|
|
3911
4038
|
_emitInsecureWarningIfNeeded() {
|
|
3912
|
-
const tlsOpt = this.
|
|
4039
|
+
const tlsOpt = this._tls;
|
|
3913
4040
|
if (tlsOpt === void 0 || tlsOpt === true) return;
|
|
3914
4041
|
if (tlsOpt.allowUnverified !== true) return;
|
|
3915
4042
|
const message = "MLLP TLS certificate verification is DISABLED (allowUnverified: true), this connection does not authenticate the peer.";
|
|
@@ -3934,7 +4061,7 @@ var MllpClient = class extends EventEmitter {
|
|
|
3934
4061
|
* built at handshake-completion time, before any HL7 byte crosses the link.
|
|
3935
4062
|
*/
|
|
3936
4063
|
_emitNegotiatedTlsParameters(socket) {
|
|
3937
|
-
if (this.
|
|
4064
|
+
if (this._tls === void 0) return;
|
|
3938
4065
|
const params = readNegotiatedTlsParameters(socket, this._opts.host, this._opts.port);
|
|
3939
4066
|
if (params === null) return;
|
|
3940
4067
|
this._emitContained("tlsNegotiated", params);
|
|
@@ -4040,7 +4167,18 @@ var MllpClient = class extends EventEmitter {
|
|
|
4040
4167
|
},
|
|
4041
4168
|
onAckModeWarning: (code, ctx) => {
|
|
4042
4169
|
this._emitAckModeWarning(code, ctx, conn);
|
|
4043
|
-
}
|
|
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
|
+
} : {}
|
|
4044
4182
|
});
|
|
4045
4183
|
}
|
|
4046
4184
|
if (this._ackSweepTimer === null) {
|
|
@@ -4177,7 +4315,7 @@ var MllpClient = class extends EventEmitter {
|
|
|
4177
4315
|
}
|
|
4178
4316
|
}
|
|
4179
4317
|
}
|
|
4180
|
-
const tlsProtocolShaped = this.
|
|
4318
|
+
const tlsProtocolShaped = this._tls !== void 0 && isTlsProtocolError(err);
|
|
4181
4319
|
const classifiedAs = !tlsProtocolShaped && isTransientConnectionError(err) ? "transient" : "permanent";
|
|
4182
4320
|
if (classifiedAs === "permanent") {
|
|
4183
4321
|
this._userClosed = true;
|
|
@@ -4292,7 +4430,7 @@ var MllpClient = class extends EventEmitter {
|
|
|
4292
4430
|
this._emitInsecureWarningIfNeeded();
|
|
4293
4431
|
this._emitNegotiatedTlsParameters(socket);
|
|
4294
4432
|
};
|
|
4295
|
-
const connectEventName = this.
|
|
4433
|
+
const connectEventName = this._tls !== void 0 ? "secureConnect" : "connect";
|
|
4296
4434
|
this._armConnectTimeout(socket, connectEventName);
|
|
4297
4435
|
socket.once("error", (sErr) => {
|
|
4298
4436
|
if (this._lastError === null || this._lastError.message !== sErr.message) {
|
|
@@ -4473,6 +4611,12 @@ var MllpClient = class extends EventEmitter {
|
|
|
4473
4611
|
* client's). The clock starts at the underlying `write()` flush callback, NOT at
|
|
4474
4612
|
* the `send()` call.
|
|
4475
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`.
|
|
4476
4620
|
*
|
|
4477
4621
|
* Emits a frozen `'ack'` event on every successful match.
|
|
4478
4622
|
*
|
|
@@ -5100,7 +5244,7 @@ var MllpClient = class extends EventEmitter {
|
|
|
5100
5244
|
reconnectAttempts: this._reconnectAttempts,
|
|
5101
5245
|
lastConnectedAt: this._lastConnectedAt,
|
|
5102
5246
|
lastAckAt: this._lastAckAt,
|
|
5103
|
-
tls: this.
|
|
5247
|
+
tls: this._tls !== void 0
|
|
5104
5248
|
};
|
|
5105
5249
|
}
|
|
5106
5250
|
/**
|
|
@@ -5130,6 +5274,7 @@ async function createStarterClient(opts) {
|
|
|
5130
5274
|
pipeline: opts.pipeline ?? true,
|
|
5131
5275
|
highWaterMark: opts.highWaterMark ?? 64,
|
|
5132
5276
|
onBackpressure: opts.onBackpressure ?? "reject",
|
|
5277
|
+
fifoUnreadableAck: opts.fifoUnreadableAck ?? "warn",
|
|
5133
5278
|
...opts.drainTimeoutMs !== void 0 ? { drainTimeoutMs: opts.drainTimeoutMs } : {},
|
|
5134
5279
|
...opts.framing !== void 0 ? { framing: opts.framing } : {},
|
|
5135
5280
|
...opts.retryStrategy !== void 0 ? { retryStrategy: opts.retryStrategy } : {},
|
|
@@ -5457,8 +5602,8 @@ async function runDifferential(options = {}) {
|
|
|
5457
5602
|
}
|
|
5458
5603
|
|
|
5459
5604
|
// src/index.ts
|
|
5460
|
-
var VERSION = "0.1.
|
|
5605
|
+
var VERSION = "0.1.14";
|
|
5461
5606
|
|
|
5462
|
-
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, 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 };
|
|
5463
5608
|
//# sourceMappingURL=index.mjs.map
|
|
5464
5609
|
//# sourceMappingURL=index.mjs.map
|