@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.cjs
CHANGED
|
@@ -4,6 +4,7 @@ var tls = require('tls');
|
|
|
4
4
|
var events = require('events');
|
|
5
5
|
var crypto = require('crypto');
|
|
6
6
|
var net = require('net');
|
|
7
|
+
var util = require('util');
|
|
7
8
|
|
|
8
9
|
// src/framing/registry.ts
|
|
9
10
|
function createWarning(code, byteOffset, message) {
|
|
@@ -650,6 +651,7 @@ var MLLP_TLS_CIPHER_LIST_UNENFORCEABLE = "MLLP_TLS_CIPHER_LIST_UNENFORCEABLE";
|
|
|
650
651
|
var MLLP_TLS_DH_PARAMETERS_UNENFORCEABLE = "MLLP_TLS_DH_PARAMETERS_UNENFORCEABLE";
|
|
651
652
|
var MLLP_TLS_PFX_REJECTED = "MLLP_TLS_PFX_REJECTED";
|
|
652
653
|
var MLLP_TLS_CREDENTIAL_CONFLICT = "MLLP_TLS_CREDENTIAL_CONFLICT";
|
|
654
|
+
var MLLP_TLS_OPTIONS_NOT_AN_OBJECT = "MLLP_TLS_OPTIONS_NOT_AN_OBJECT";
|
|
653
655
|
function tlsConfigurationMessage(code) {
|
|
654
656
|
const messages = {
|
|
655
657
|
[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",
|
|
@@ -658,7 +660,8 @@ function tlsConfigurationMessage(code) {
|
|
|
658
660
|
[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",
|
|
659
661
|
[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",
|
|
660
662
|
[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",
|
|
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"
|
|
663
|
+
[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",
|
|
664
|
+
[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"
|
|
662
665
|
};
|
|
663
666
|
return messages[code];
|
|
664
667
|
}
|
|
@@ -926,14 +929,23 @@ function readNegotiatedTlsParameters(socket, host, port) {
|
|
|
926
929
|
const cipher = socket.getCipher();
|
|
927
930
|
const cipherSuite = cipher.standardName === "" ? cipher.name : cipher.standardName;
|
|
928
931
|
if (cipherSuite === "") return null;
|
|
932
|
+
const keyExchangeGroup = readKeyExchangeGroup(socket);
|
|
929
933
|
return Object.freeze({
|
|
930
934
|
protocolVersion,
|
|
931
935
|
cipherSuite,
|
|
936
|
+
...keyExchangeGroup === void 0 ? {} : { keyExchangeGroup },
|
|
932
937
|
host,
|
|
933
938
|
port,
|
|
934
939
|
timestamp: /* @__PURE__ */ new Date()
|
|
935
940
|
});
|
|
936
941
|
}
|
|
942
|
+
function readKeyExchangeGroup(socket) {
|
|
943
|
+
if (typeof socket.getEphemeralKeyInfo !== "function") return void 0;
|
|
944
|
+
const info = socket.getEphemeralKeyInfo();
|
|
945
|
+
if (typeof info !== "object" || info === null || !("name" in info)) return void 0;
|
|
946
|
+
const { name } = info;
|
|
947
|
+
return typeof name === "string" && name !== "" ? name : void 0;
|
|
948
|
+
}
|
|
937
949
|
|
|
938
950
|
// src/connection/error.ts
|
|
939
951
|
var MllpConnectionError = class _MllpConnectionError extends Error {
|
|
@@ -1431,14 +1443,59 @@ function checkCredentialMix(tls) {
|
|
|
1431
1443
|
throw new MllpTlsConfigurationError(MLLP_TLS_CREDENTIAL_CONFLICT);
|
|
1432
1444
|
}
|
|
1433
1445
|
}
|
|
1434
|
-
function
|
|
1435
|
-
if (pfx === void 0) return;
|
|
1446
|
+
function pfxRefusal(pfx, passphrase) {
|
|
1447
|
+
if (pfx === void 0) return void 0;
|
|
1436
1448
|
try {
|
|
1437
1449
|
tls.createSecureContext({ pfx, passphrase });
|
|
1450
|
+
return void 0;
|
|
1438
1451
|
} catch (err) {
|
|
1439
|
-
|
|
1452
|
+
return new MllpTlsConfigurationError(MLLP_TLS_PFX_REJECTED, { cause: err });
|
|
1440
1453
|
}
|
|
1441
1454
|
}
|
|
1455
|
+
function checkPfx(pfx, passphrase) {
|
|
1456
|
+
const refusal = pfxRefusal(pfx, passphrase);
|
|
1457
|
+
if (refusal !== void 0) throw refusal;
|
|
1458
|
+
}
|
|
1459
|
+
function tlsOptionNames() {
|
|
1460
|
+
const names = {
|
|
1461
|
+
ca: "ca",
|
|
1462
|
+
cert: "cert",
|
|
1463
|
+
key: "key",
|
|
1464
|
+
passphrase: "passphrase",
|
|
1465
|
+
pfx: "pfx",
|
|
1466
|
+
servername: "servername",
|
|
1467
|
+
minVersion: "minVersion",
|
|
1468
|
+
maxVersion: "maxVersion",
|
|
1469
|
+
atnaTransportSecurity: "atnaTransportSecurity",
|
|
1470
|
+
ciphers: "ciphers",
|
|
1471
|
+
allowUnverified: "allowUnverified",
|
|
1472
|
+
clientAuth: "clientAuth",
|
|
1473
|
+
dhParameters: "dhParameters"
|
|
1474
|
+
};
|
|
1475
|
+
return Object.values(names);
|
|
1476
|
+
}
|
|
1477
|
+
function copyValue(value) {
|
|
1478
|
+
return ArrayBuffer.isView(value) ? Buffer.from(new Uint8Array(value.buffer, value.byteOffset, value.byteLength)) : value;
|
|
1479
|
+
}
|
|
1480
|
+
function isOptionsObject(value) {
|
|
1481
|
+
if (typeof value !== "object" || value === null) return false;
|
|
1482
|
+
return !(Array.isArray(value) || ArrayBuffer.isView(value) || util.types.isAnyArrayBuffer(value) || util.types.isMap(value) || util.types.isSet(value) || util.types.isDate(value) || util.types.isPromise(value) || util.types.isBoxedPrimitive(value));
|
|
1483
|
+
}
|
|
1484
|
+
function copyTlsOptions(tls) {
|
|
1485
|
+
if (tls === void 0 || tls === true) return tls;
|
|
1486
|
+
const given = tls;
|
|
1487
|
+
if (!isOptionsObject(given)) {
|
|
1488
|
+
throw new MllpTlsConfigurationError(MLLP_TLS_OPTIONS_NOT_AN_OBJECT);
|
|
1489
|
+
}
|
|
1490
|
+
const source = given;
|
|
1491
|
+
const copy = {};
|
|
1492
|
+
for (const name of tlsOptionNames()) {
|
|
1493
|
+
const value = source[name];
|
|
1494
|
+
if (value === void 0) continue;
|
|
1495
|
+
copy[name] = Array.isArray(value) ? value.map(copyValue) : copyValue(value);
|
|
1496
|
+
}
|
|
1497
|
+
return copy;
|
|
1498
|
+
}
|
|
1442
1499
|
|
|
1443
1500
|
// src/internal/control-id.ts
|
|
1444
1501
|
var ASCII_M = 77;
|
|
@@ -1473,9 +1530,12 @@ function segmentEnds(buf) {
|
|
|
1473
1530
|
return atCr < atLf ? atCr : atLf;
|
|
1474
1531
|
};
|
|
1475
1532
|
}
|
|
1533
|
+
function firstSegmentStart(buf) {
|
|
1534
|
+
return buf[0] === 239 && buf[1] === 187 && buf[2] === 191 ? 3 : 0;
|
|
1535
|
+
}
|
|
1476
1536
|
function findMshSegment(buf) {
|
|
1477
1537
|
const segmentEnd = segmentEnds(buf);
|
|
1478
|
-
let segStart =
|
|
1538
|
+
let segStart = firstSegmentStart(buf);
|
|
1479
1539
|
while (segStart < buf.length) {
|
|
1480
1540
|
const end = segmentEnd(segStart);
|
|
1481
1541
|
if (isMshSegmentAt(buf, segStart)) return { start: segStart, end };
|
|
@@ -1504,7 +1564,7 @@ function isBatchEnvelopeSegmentAt(buf, i) {
|
|
|
1504
1564
|
function containsBatchOrExtraMessage(buf) {
|
|
1505
1565
|
const segmentEnd = segmentEnds(buf);
|
|
1506
1566
|
let mshCount = 0;
|
|
1507
|
-
let segStart =
|
|
1567
|
+
let segStart = firstSegmentStart(buf);
|
|
1508
1568
|
while (segStart < buf.length) {
|
|
1509
1569
|
const end = segmentEnd(segStart);
|
|
1510
1570
|
if (isMshSegmentAt(buf, segStart)) {
|
|
@@ -1545,7 +1605,7 @@ function readMsaSegment(buf) {
|
|
|
1545
1605
|
if (msh === null) return null;
|
|
1546
1606
|
const fieldSep = msh.fieldSep.charCodeAt(0);
|
|
1547
1607
|
const end = buf.length;
|
|
1548
|
-
let segStart =
|
|
1608
|
+
let segStart = firstSegmentStart(buf);
|
|
1549
1609
|
while (segStart < end) {
|
|
1550
1610
|
let segEnd = segStart;
|
|
1551
1611
|
while (segEnd < end && buf[segEnd] !== SEGMENT_SEPARATOR_CR && buf[segEnd] !== SEGMENT_SEPARATOR_LF) {
|
|
@@ -1773,7 +1833,10 @@ var ACK_MODE_MESSAGES = Object.freeze({
|
|
|
1773
1833
|
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.",
|
|
1774
1834
|
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.",
|
|
1775
1835
|
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.",
|
|
1776
|
-
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."
|
|
1836
|
+
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.",
|
|
1837
|
+
// 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).
|
|
1838
|
+
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."
|
|
1839
|
+
// Stryker restore StringLiteral
|
|
1777
1840
|
});
|
|
1778
1841
|
function ackModeDiagnosticMessage(code) {
|
|
1779
1842
|
return ACK_MODE_MESSAGES[code];
|
|
@@ -1825,6 +1888,8 @@ var MllpServer = class extends events.EventEmitter {
|
|
|
1825
1888
|
_netServer;
|
|
1826
1889
|
_connections = /* @__PURE__ */ new Set();
|
|
1827
1890
|
_opts;
|
|
1891
|
+
/** The TLS options as they were at construction; never read `_opts.tls`, which the caller owns. */
|
|
1892
|
+
_tls;
|
|
1828
1893
|
/** `true` when `ServerOptions.tls` is set, `_netServer` is actually a `tls.Server`. */
|
|
1829
1894
|
_isTls;
|
|
1830
1895
|
_listening = false;
|
|
@@ -1879,27 +1944,33 @@ var MllpServer = class extends events.EventEmitter {
|
|
|
1879
1944
|
"ServerOptions.maxConnections must be a positive integer, or left unset for no cap"
|
|
1880
1945
|
);
|
|
1881
1946
|
}
|
|
1882
|
-
const tlsInput = opts.tls;
|
|
1947
|
+
const tlsInput = copyTlsOptions(opts.tls);
|
|
1883
1948
|
checkCredentialMix(tlsInput);
|
|
1884
1949
|
if (tlsInput !== void 0 && tlsInput.pfx === void 0 && (tlsInput.cert === void 0 || tlsInput.key === void 0)) {
|
|
1885
1950
|
throw new TypeError("ServerOptions.tls needs cert and key, or pfx");
|
|
1886
1951
|
}
|
|
1887
1952
|
this._opts = opts;
|
|
1888
|
-
this.
|
|
1953
|
+
this._tls = tlsInput;
|
|
1954
|
+
this._isTls = tlsInput !== void 0;
|
|
1889
1955
|
let cipherPolicy = null;
|
|
1890
|
-
if (
|
|
1956
|
+
if (tlsInput !== void 0) {
|
|
1891
1957
|
try {
|
|
1892
|
-
checkPfx(
|
|
1893
|
-
cipherPolicy = resolveTlsCipherPolicy(
|
|
1958
|
+
checkPfx(tlsInput.pfx, tlsInput.passphrase);
|
|
1959
|
+
cipherPolicy = resolveTlsCipherPolicy(tlsInput, "server");
|
|
1894
1960
|
} catch (err) {
|
|
1895
1961
|
if (!(err instanceof MllpTlsConfigurationError)) throw err;
|
|
1896
1962
|
this._tlsConfigError = err;
|
|
1897
1963
|
}
|
|
1898
1964
|
}
|
|
1899
|
-
if (
|
|
1965
|
+
if (tlsInput === void 0) {
|
|
1900
1966
|
this._netServer = net.createServer();
|
|
1901
|
-
|
|
1902
|
-
|
|
1967
|
+
this._netServer.on("connection", (socket) => {
|
|
1968
|
+
this._onSocketAccepted(socket);
|
|
1969
|
+
});
|
|
1970
|
+
} else if (cipherPolicy === null) {
|
|
1971
|
+
this._netServer = net.createServer();
|
|
1972
|
+
} else {
|
|
1973
|
+
const tlsOpts = tlsInput;
|
|
1903
1974
|
const clientAuth = tlsOpts.clientAuth ?? "NONE";
|
|
1904
1975
|
const tlsServer = tls.createServer({
|
|
1905
1976
|
cert: tlsOpts.cert,
|
|
@@ -1930,11 +2001,6 @@ var MllpServer = class extends events.EventEmitter {
|
|
|
1930
2001
|
});
|
|
1931
2002
|
this._emitContained("tlsClientError", event);
|
|
1932
2003
|
});
|
|
1933
|
-
} else {
|
|
1934
|
-
this._netServer = net.createServer();
|
|
1935
|
-
this._netServer.on("connection", (socket) => {
|
|
1936
|
-
this._onSocketAccepted(socket);
|
|
1937
|
-
});
|
|
1938
2004
|
}
|
|
1939
2005
|
this._netServer.on("error", (err) => {
|
|
1940
2006
|
if (this.listenerCount("error") > 0) {
|
|
@@ -2446,7 +2512,7 @@ var MllpServer = class extends events.EventEmitter {
|
|
|
2446
2512
|
}
|
|
2447
2513
|
}
|
|
2448
2514
|
);
|
|
2449
|
-
const peerCertificate =
|
|
2515
|
+
const peerCertificate = (this._tls?.clientAuth ?? "NONE") !== "NONE" ? this._extractPeerCertificateSummary(socket) : null;
|
|
2450
2516
|
this._emitContained(
|
|
2451
2517
|
"connection",
|
|
2452
2518
|
Object.freeze({
|
|
@@ -2782,6 +2848,7 @@ var Correlator = class {
|
|
|
2782
2848
|
onCommitReported: opts.onCommitReported,
|
|
2783
2849
|
onCommitRejected: opts.onCommitRejected,
|
|
2784
2850
|
onApplicationAckTimeout: opts.onApplicationAckTimeout,
|
|
2851
|
+
onUnreadableAck: opts.onUnreadableAck,
|
|
2785
2852
|
now: opts.now ?? Date.now
|
|
2786
2853
|
};
|
|
2787
2854
|
}
|
|
@@ -2846,6 +2913,9 @@ var Correlator = class {
|
|
|
2846
2913
|
*
|
|
2847
2914
|
* - FIFO: returns first pending entry by insertion order; entry is
|
|
2848
2915
|
* removed from live store. Caller calls `entry.resolve(ackPayload)`.
|
|
2916
|
+
* A frame with no readable MSA-1 is reported as
|
|
2917
|
+
* `MLLP_ACK_FIFO_MSA1_UNREADABLE` first, and when `onUnreadableAck` is
|
|
2918
|
+
* wired it is handed the entry instead and `null` is returned.
|
|
2849
2919
|
* - controlId: keyed lookup by `controlIdFromAck`. Live-store hit returns
|
|
2850
2920
|
* the entry; graveyard hit fires `MLLP_ACK_AFTER_TIMEOUT` warning
|
|
2851
2921
|
* and returns `null`; otherwise fires `onUnmatchedAck` with the id's
|
|
@@ -2872,7 +2942,24 @@ var Correlator = class {
|
|
|
2872
2942
|
this._pending.delete(entry.key);
|
|
2873
2943
|
this._queueBytes -= entry.byteCount;
|
|
2874
2944
|
if (entry.sentAt !== null) this._inFlight -= 1;
|
|
2875
|
-
|
|
2945
|
+
const classification = classifyMsa1(payload);
|
|
2946
|
+
if (classification.kind === "code") return entry;
|
|
2947
|
+
const elapsedSinceSendMs = entry.sentAt === null ? 0 : this._opts.now() - entry.sentAt;
|
|
2948
|
+
this._ackModeWarn("MLLP_ACK_FIFO_MSA1_UNREADABLE", {
|
|
2949
|
+
msa1Bytes: classification.byteLength,
|
|
2950
|
+
ackCode: null,
|
|
2951
|
+
controlIdBytes: null,
|
|
2952
|
+
byteOffset: byteOffsetFromAck,
|
|
2953
|
+
elapsedSinceSendMs
|
|
2954
|
+
});
|
|
2955
|
+
if (this._opts.onUnreadableAck === void 0) return entry;
|
|
2956
|
+
this._opts.onUnreadableAck(
|
|
2957
|
+
entry,
|
|
2958
|
+
classification.byteLength,
|
|
2959
|
+
byteOffsetFromAck,
|
|
2960
|
+
elapsedSinceSendMs
|
|
2961
|
+
);
|
|
2962
|
+
return null;
|
|
2876
2963
|
}
|
|
2877
2964
|
if (controlIdFromAck === null) {
|
|
2878
2965
|
if (this._opts.onUnmatchedAck !== void 0) {
|
|
@@ -3219,6 +3306,30 @@ var MllpApplicationAckError = class _MllpApplicationAckError extends Error {
|
|
|
3219
3306
|
}
|
|
3220
3307
|
}
|
|
3221
3308
|
};
|
|
3309
|
+
var MllpUnreadableAckError = class _MllpUnreadableAckError extends Error {
|
|
3310
|
+
name = "MllpUnreadableAckError";
|
|
3311
|
+
/** Byte length of the MSA-1 field read, `0` when the frame has no `MSH` or no `MSA`. */
|
|
3312
|
+
msa1Bytes;
|
|
3313
|
+
/** Stream byte offset of the frame that settled the send. */
|
|
3314
|
+
byteOffset;
|
|
3315
|
+
/** Milliseconds between the send's write-flush and that frame. */
|
|
3316
|
+
elapsedMs;
|
|
3317
|
+
/**
|
|
3318
|
+
* Construct an unreadable-acknowledgement error.
|
|
3319
|
+
*
|
|
3320
|
+
* @param message - Human-readable error message. Structural facts only, never field content.
|
|
3321
|
+
* @param opts - Failure context (MSA-1 byte length, stream offset, elapsed time).
|
|
3322
|
+
*/
|
|
3323
|
+
constructor(message, opts) {
|
|
3324
|
+
super(message);
|
|
3325
|
+
this.msa1Bytes = opts.msa1Bytes;
|
|
3326
|
+
this.byteOffset = opts.byteOffset;
|
|
3327
|
+
this.elapsedMs = opts.elapsedMs;
|
|
3328
|
+
if (Error.captureStackTrace) {
|
|
3329
|
+
Error.captureStackTrace(this, _MllpUnreadableAckError);
|
|
3330
|
+
}
|
|
3331
|
+
}
|
|
3332
|
+
};
|
|
3222
3333
|
var MllpCommitRejectedError = class _MllpCommitRejectedError extends Error {
|
|
3223
3334
|
name = "MllpCommitRejectedError";
|
|
3224
3335
|
/** The negative accept-mode code the peer sent. */
|
|
@@ -3411,6 +3522,10 @@ function identityOptions(host, servername) {
|
|
|
3411
3522
|
}
|
|
3412
3523
|
var MllpClient = class extends events.EventEmitter {
|
|
3413
3524
|
_opts;
|
|
3525
|
+
/** The TLS options as they were at construction; never read `_opts.tls`, which the caller owns. */
|
|
3526
|
+
_tls;
|
|
3527
|
+
/** Why `tls.pfx` cannot be loaded, found once at construction; `undefined` when it loads or is unset. */
|
|
3528
|
+
_pfxRefusal;
|
|
3414
3529
|
_connection = null;
|
|
3415
3530
|
_socket = null;
|
|
3416
3531
|
/**
|
|
@@ -3427,6 +3542,8 @@ var MllpClient = class extends events.EventEmitter {
|
|
|
3427
3542
|
_applicationAckTimeoutMs;
|
|
3428
3543
|
/** controlId-mode flag. `false` → FIFO. */
|
|
3429
3544
|
_correlateByControlId;
|
|
3545
|
+
/** Whether a FIFO send settled on a frame with no readable MSA-1 rejects rather than resolves. */
|
|
3546
|
+
_rejectUnreadableAck;
|
|
3430
3547
|
/** Unified ACK correlator. Built during `_attachConnection`. */
|
|
3431
3548
|
_correlator = null;
|
|
3432
3549
|
/**
|
|
@@ -3546,11 +3663,21 @@ var MllpClient = class extends events.EventEmitter {
|
|
|
3546
3663
|
"ClientOptions.connectTimeoutMs must be an integer from 1 to 2147483647, or left unset for no bound"
|
|
3547
3664
|
);
|
|
3548
3665
|
}
|
|
3549
|
-
|
|
3666
|
+
const fifoUnreadableAck = opts.fifoUnreadableAck;
|
|
3667
|
+
if (fifoUnreadableAck !== void 0 && fifoUnreadableAck !== "warn" && fifoUnreadableAck !== "reject") {
|
|
3668
|
+
throw new TypeError(
|
|
3669
|
+
"ClientOptions.fifoUnreadableAck must be 'warn' or 'reject', or left unset for 'warn'"
|
|
3670
|
+
);
|
|
3671
|
+
}
|
|
3672
|
+
const tls = copyTlsOptions(opts.tls);
|
|
3673
|
+
checkCredentialMix(tls);
|
|
3674
|
+
this._pfxRefusal = typeof tls === "object" ? pfxRefusal(tls.pfx, tls.passphrase) : void 0;
|
|
3675
|
+
this._tls = tls;
|
|
3550
3676
|
this._opts = opts;
|
|
3551
3677
|
this._ackTimeoutMs = opts.ackTimeoutMs ?? 3e4;
|
|
3552
3678
|
this._applicationAckTimeoutMs = opts.applicationAckTimeoutMs;
|
|
3553
3679
|
this._correlateByControlId = opts.correlateByControlId === true;
|
|
3680
|
+
this._rejectUnreadableAck = fifoUnreadableAck === "reject";
|
|
3554
3681
|
this._autoReconnect = opts.autoReconnect === true;
|
|
3555
3682
|
this._initialDelayMs = opts.initialDelayMs ?? 100;
|
|
3556
3683
|
this._maxDelayMs = opts.maxDelayMs ?? 3e4;
|
|
@@ -3664,7 +3791,7 @@ var MllpClient = class extends events.EventEmitter {
|
|
|
3664
3791
|
}
|
|
3665
3792
|
const conn = new Connection(connOpts);
|
|
3666
3793
|
this._attachConnection(conn);
|
|
3667
|
-
const connectEventName = this.
|
|
3794
|
+
const connectEventName = this._tls !== void 0 ? "secureConnect" : "connect";
|
|
3668
3795
|
this._armConnectTimeout(socket, connectEventName);
|
|
3669
3796
|
const cleanup = () => {
|
|
3670
3797
|
if (signal !== void 0) {
|
|
@@ -3734,14 +3861,14 @@ var MllpClient = class extends events.EventEmitter {
|
|
|
3734
3861
|
* against it.
|
|
3735
3862
|
*/
|
|
3736
3863
|
_createSocketAndTransport() {
|
|
3737
|
-
const tlsOpt = this.
|
|
3864
|
+
const tlsOpt = this._tls;
|
|
3738
3865
|
if (tlsOpt === void 0) {
|
|
3739
3866
|
const socket2 = net.createConnection({ host: this._opts.host, port: this._opts.port });
|
|
3740
3867
|
return { socket: socket2, transport: new NetTransport(socket2) };
|
|
3741
3868
|
}
|
|
3742
3869
|
const tlsOpts = tlsOpt === true ? {} : tlsOpt;
|
|
3743
3870
|
const cipherPolicy = resolveTlsCipherPolicy(tlsOpts, "client");
|
|
3744
|
-
|
|
3871
|
+
if (this._pfxRefusal !== void 0) throw this._pfxRefusal;
|
|
3745
3872
|
const socket = tls.connect({
|
|
3746
3873
|
host: this._opts.host,
|
|
3747
3874
|
port: this._opts.port,
|
|
@@ -3802,7 +3929,7 @@ var MllpClient = class extends events.EventEmitter {
|
|
|
3802
3929
|
connectionCause: "connect-timeout"
|
|
3803
3930
|
});
|
|
3804
3931
|
}
|
|
3805
|
-
if (this.
|
|
3932
|
+
if (this._tls === void 0) {
|
|
3806
3933
|
return new MllpConnectionError(err.message, { cause: err, phase });
|
|
3807
3934
|
}
|
|
3808
3935
|
const code = err.code;
|
|
@@ -3911,7 +4038,7 @@ var MllpClient = class extends events.EventEmitter {
|
|
|
3911
4038
|
* connections or when verification is on.
|
|
3912
4039
|
*/
|
|
3913
4040
|
_emitInsecureWarningIfNeeded() {
|
|
3914
|
-
const tlsOpt = this.
|
|
4041
|
+
const tlsOpt = this._tls;
|
|
3915
4042
|
if (tlsOpt === void 0 || tlsOpt === true) return;
|
|
3916
4043
|
if (tlsOpt.allowUnverified !== true) return;
|
|
3917
4044
|
const message = "MLLP TLS certificate verification is DISABLED (allowUnverified: true), this connection does not authenticate the peer.";
|
|
@@ -3936,7 +4063,7 @@ var MllpClient = class extends events.EventEmitter {
|
|
|
3936
4063
|
* built at handshake-completion time, before any HL7 byte crosses the link.
|
|
3937
4064
|
*/
|
|
3938
4065
|
_emitNegotiatedTlsParameters(socket) {
|
|
3939
|
-
if (this.
|
|
4066
|
+
if (this._tls === void 0) return;
|
|
3940
4067
|
const params = readNegotiatedTlsParameters(socket, this._opts.host, this._opts.port);
|
|
3941
4068
|
if (params === null) return;
|
|
3942
4069
|
this._emitContained("tlsNegotiated", params);
|
|
@@ -4042,7 +4169,18 @@ var MllpClient = class extends events.EventEmitter {
|
|
|
4042
4169
|
},
|
|
4043
4170
|
onAckModeWarning: (code, ctx) => {
|
|
4044
4171
|
this._emitAckModeWarning(code, ctx, conn);
|
|
4045
|
-
}
|
|
4172
|
+
},
|
|
4173
|
+
...this._rejectUnreadableAck ? {
|
|
4174
|
+
onUnreadableAck: (entry, msa1Bytes, byteOffset, elapsedMs) => {
|
|
4175
|
+
entry.reject(
|
|
4176
|
+
new MllpUnreadableAckError(
|
|
4177
|
+
"the frame that settled this send in order carried no readable MSA-1, so the peer has not acknowledged it in HL7 terms",
|
|
4178
|
+
{ msa1Bytes, byteOffset, elapsedMs }
|
|
4179
|
+
)
|
|
4180
|
+
);
|
|
4181
|
+
this._maybeEmitDrain();
|
|
4182
|
+
}
|
|
4183
|
+
} : {}
|
|
4046
4184
|
});
|
|
4047
4185
|
}
|
|
4048
4186
|
if (this._ackSweepTimer === null) {
|
|
@@ -4179,7 +4317,7 @@ var MllpClient = class extends events.EventEmitter {
|
|
|
4179
4317
|
}
|
|
4180
4318
|
}
|
|
4181
4319
|
}
|
|
4182
|
-
const tlsProtocolShaped = this.
|
|
4320
|
+
const tlsProtocolShaped = this._tls !== void 0 && isTlsProtocolError(err);
|
|
4183
4321
|
const classifiedAs = !tlsProtocolShaped && isTransientConnectionError(err) ? "transient" : "permanent";
|
|
4184
4322
|
if (classifiedAs === "permanent") {
|
|
4185
4323
|
this._userClosed = true;
|
|
@@ -4294,7 +4432,7 @@ var MllpClient = class extends events.EventEmitter {
|
|
|
4294
4432
|
this._emitInsecureWarningIfNeeded();
|
|
4295
4433
|
this._emitNegotiatedTlsParameters(socket);
|
|
4296
4434
|
};
|
|
4297
|
-
const connectEventName = this.
|
|
4435
|
+
const connectEventName = this._tls !== void 0 ? "secureConnect" : "connect";
|
|
4298
4436
|
this._armConnectTimeout(socket, connectEventName);
|
|
4299
4437
|
socket.once("error", (sErr) => {
|
|
4300
4438
|
if (this._lastError === null || this._lastError.message !== sErr.message) {
|
|
@@ -4475,6 +4613,12 @@ var MllpClient = class extends events.EventEmitter {
|
|
|
4475
4613
|
* client's). The clock starts at the underlying `write()` flush callback, NOT at
|
|
4476
4614
|
* the `send()` call.
|
|
4477
4615
|
* - `MllpConnectionError({ phase: 'send' })` if the client is not connected.
|
|
4616
|
+
* - `MllpUnreadableAckError` with `fifoUnreadableAck: 'reject'`, when the frame that settles
|
|
4617
|
+
* this send in order carries no readable MSA-1.
|
|
4618
|
+
*
|
|
4619
|
+
* Resolving is not acceptance: read MSA-1 off the acknowledgement you are handed. In FIFO
|
|
4620
|
+
* mode a frame with no readable MSA-1 still resolves by default, with the warning
|
|
4621
|
+
* `MLLP_ACK_FIFO_MSA1_UNREADABLE`.
|
|
4478
4622
|
*
|
|
4479
4623
|
* Emits a frozen `'ack'` event on every successful match.
|
|
4480
4624
|
*
|
|
@@ -5102,7 +5246,7 @@ var MllpClient = class extends events.EventEmitter {
|
|
|
5102
5246
|
reconnectAttempts: this._reconnectAttempts,
|
|
5103
5247
|
lastConnectedAt: this._lastConnectedAt,
|
|
5104
5248
|
lastAckAt: this._lastAckAt,
|
|
5105
|
-
tls: this.
|
|
5249
|
+
tls: this._tls !== void 0
|
|
5106
5250
|
};
|
|
5107
5251
|
}
|
|
5108
5252
|
/**
|
|
@@ -5132,6 +5276,7 @@ async function createStarterClient(opts) {
|
|
|
5132
5276
|
pipeline: opts.pipeline ?? true,
|
|
5133
5277
|
highWaterMark: opts.highWaterMark ?? 64,
|
|
5134
5278
|
onBackpressure: opts.onBackpressure ?? "reject",
|
|
5279
|
+
fifoUnreadableAck: opts.fifoUnreadableAck ?? "warn",
|
|
5135
5280
|
...opts.drainTimeoutMs !== void 0 ? { drainTimeoutMs: opts.drainTimeoutMs } : {},
|
|
5136
5281
|
...opts.framing !== void 0 ? { framing: opts.framing } : {},
|
|
5137
5282
|
...opts.retryStrategy !== void 0 ? { retryStrategy: opts.retryStrategy } : {},
|
|
@@ -5459,7 +5604,7 @@ async function runDifferential(options = {}) {
|
|
|
5459
5604
|
}
|
|
5460
5605
|
|
|
5461
5606
|
// src/index.ts
|
|
5462
|
-
var VERSION = "0.1.
|
|
5607
|
+
var VERSION = "0.1.14";
|
|
5463
5608
|
|
|
5464
5609
|
exports.ATNA_CIPHER_LIST = ATNA_CIPHER_LIST;
|
|
5465
5610
|
exports.ATNA_CIPHER_SUITES = ATNA_CIPHER_SUITES;
|
|
@@ -5474,6 +5619,7 @@ exports.MLLP_TLS_CIPHER_OPTION_CONFLICT = MLLP_TLS_CIPHER_OPTION_CONFLICT;
|
|
|
5474
5619
|
exports.MLLP_TLS_CREDENTIAL_CONFLICT = MLLP_TLS_CREDENTIAL_CONFLICT;
|
|
5475
5620
|
exports.MLLP_TLS_DH_PARAMETERS_REJECTED = MLLP_TLS_DH_PARAMETERS_REJECTED;
|
|
5476
5621
|
exports.MLLP_TLS_DH_PARAMETERS_UNENFORCEABLE = MLLP_TLS_DH_PARAMETERS_UNENFORCEABLE;
|
|
5622
|
+
exports.MLLP_TLS_OPTIONS_NOT_AN_OBJECT = MLLP_TLS_OPTIONS_NOT_AN_OBJECT;
|
|
5477
5623
|
exports.MLLP_TLS_PFX_REJECTED = MLLP_TLS_PFX_REJECTED;
|
|
5478
5624
|
exports.MLLP_TLS_VERIFY_DISABLED = MLLP_TLS_VERIFY_DISABLED;
|
|
5479
5625
|
exports.MllpAckError = MllpAckError;
|
|
@@ -5489,6 +5635,7 @@ exports.MllpServer = MllpServer;
|
|
|
5489
5635
|
exports.MllpTimeoutError = MllpTimeoutError;
|
|
5490
5636
|
exports.MllpTlsConfigurationError = MllpTlsConfigurationError;
|
|
5491
5637
|
exports.MllpUnknownFateError = MllpUnknownFateError;
|
|
5638
|
+
exports.MllpUnreadableAckError = MllpUnreadableAckError;
|
|
5492
5639
|
exports.NetTransport = NetTransport;
|
|
5493
5640
|
exports.TLS13_DEFAULT_CIPHER_SUITES = TLS13_DEFAULT_CIPHER_SUITES;
|
|
5494
5641
|
exports.TlsTransport = TlsTransport;
|