@nsshunt/stsfhirclient 2.0.35 → 2.0.37

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.
@@ -5505,6 +5505,12 @@ var require_utils = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
5505
5505
  var isUUID = RegExp.prototype.test.bind(/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iu);
5506
5506
  /** @type {(value: string) => boolean} */
5507
5507
  var isIPv4 = RegExp.prototype.test.bind(/^(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)$/u);
5508
+ /** @type {(value: string) => boolean} */
5509
+ var isHexPair = RegExp.prototype.test.bind(/^[\da-f]{2}$/iu);
5510
+ /** @type {(value: string) => boolean} */
5511
+ var isUnreserved = RegExp.prototype.test.bind(/^[\da-z\-._~]$/iu);
5512
+ /** @type {(value: string) => boolean} */
5513
+ var isPathCharacter = RegExp.prototype.test.bind(/^[\da-z\-._~!$&'()*+,;=:@/]$/iu);
5508
5514
  /**
5509
5515
  * @param {Array<string>} input
5510
5516
  * @returns {string}
@@ -5727,19 +5733,103 @@ var require_utils = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
5727
5733
  return output.join("");
5728
5734
  }
5729
5735
  /**
5730
- * @param {import('../types/index').URIComponent} component
5731
- * @param {boolean} esc
5732
- * @returns {import('../types/index').URIComponent}
5736
+ * Re-escape RFC 3986 gen-delims that must not appear literally in the host.
5737
+ * After the URI regex parses, these characters cannot be literal in the host
5738
+ * field, so any that appear after decoding came from percent-encoding and
5739
+ * must be restored to prevent authority structure changes.
5740
+ *
5741
+ * @param {string} host
5742
+ * @param {boolean} isIP - true for IPv4/IPv6 hosts (skip colon re-escaping)
5743
+ * @returns {string}
5733
5744
  */
5734
- function normalizeComponentEncoding(component, esc) {
5735
- const func = esc !== true ? escape : unescape;
5736
- if (component.scheme !== void 0) component.scheme = func(component.scheme);
5737
- if (component.userinfo !== void 0) component.userinfo = func(component.userinfo);
5738
- if (component.host !== void 0) component.host = func(component.host);
5739
- if (component.path !== void 0) component.path = func(component.path);
5740
- if (component.query !== void 0) component.query = func(component.query);
5741
- if (component.fragment !== void 0) component.fragment = func(component.fragment);
5742
- return component;
5745
+ var HOST_DELIMS = {
5746
+ "@": "%40",
5747
+ "/": "%2F",
5748
+ "?": "%3F",
5749
+ "#": "%23",
5750
+ ":": "%3A"
5751
+ };
5752
+ var HOST_DELIM_RE = /[@/?#:]/g;
5753
+ var HOST_DELIM_NO_COLON_RE = /[@/?#]/g;
5754
+ function reescapeHostDelimiters(host, isIP) {
5755
+ const re = isIP ? HOST_DELIM_NO_COLON_RE : HOST_DELIM_RE;
5756
+ re.lastIndex = 0;
5757
+ return host.replace(re, (ch) => HOST_DELIMS[ch]);
5758
+ }
5759
+ /**
5760
+ * Normalizes percent escapes and optionally decodes only unreserved ASCII bytes.
5761
+ * Reserved delimiters such as `%2F` and `%2E` stay escaped.
5762
+ *
5763
+ * @param {string} input
5764
+ * @param {boolean} [decodeUnreserved=false]
5765
+ * @returns {string}
5766
+ */
5767
+ function normalizePercentEncoding(input, decodeUnreserved = false) {
5768
+ if (input.indexOf("%") === -1) return input;
5769
+ let output = "";
5770
+ for (let i = 0; i < input.length; i++) {
5771
+ if (input[i] === "%" && i + 2 < input.length) {
5772
+ const hex = input.slice(i + 1, i + 3);
5773
+ if (isHexPair(hex)) {
5774
+ const normalizedHex = hex.toUpperCase();
5775
+ const decoded = String.fromCharCode(parseInt(normalizedHex, 16));
5776
+ if (decodeUnreserved && isUnreserved(decoded)) output += decoded;
5777
+ else output += "%" + normalizedHex;
5778
+ i += 2;
5779
+ continue;
5780
+ }
5781
+ }
5782
+ output += input[i];
5783
+ }
5784
+ return output;
5785
+ }
5786
+ /**
5787
+ * Normalizes path data without turning reserved escapes into live path syntax.
5788
+ * Valid escapes are uppercased, raw unsafe characters are escaped, and only
5789
+ * unreserved bytes that are not `.` are decoded.
5790
+ *
5791
+ * @param {string} input
5792
+ * @returns {string}
5793
+ */
5794
+ function normalizePathEncoding(input) {
5795
+ let output = "";
5796
+ for (let i = 0; i < input.length; i++) {
5797
+ if (input[i] === "%" && i + 2 < input.length) {
5798
+ const hex = input.slice(i + 1, i + 3);
5799
+ if (isHexPair(hex)) {
5800
+ const normalizedHex = hex.toUpperCase();
5801
+ const decoded = String.fromCharCode(parseInt(normalizedHex, 16));
5802
+ if (decoded !== "." && isUnreserved(decoded)) output += decoded;
5803
+ else output += "%" + normalizedHex;
5804
+ i += 2;
5805
+ continue;
5806
+ }
5807
+ }
5808
+ if (isPathCharacter(input[i])) output += input[i];
5809
+ else output += escape(input[i]);
5810
+ }
5811
+ return output;
5812
+ }
5813
+ /**
5814
+ * Escapes a component while preserving existing valid percent escapes.
5815
+ *
5816
+ * @param {string} input
5817
+ * @returns {string}
5818
+ */
5819
+ function escapePreservingEscapes(input) {
5820
+ let output = "";
5821
+ for (let i = 0; i < input.length; i++) {
5822
+ if (input[i] === "%" && i + 2 < input.length) {
5823
+ const hex = input.slice(i + 1, i + 3);
5824
+ if (isHexPair(hex)) {
5825
+ output += "%" + hex.toUpperCase();
5826
+ i += 2;
5827
+ continue;
5828
+ }
5829
+ }
5830
+ output += escape(input[i]);
5831
+ }
5832
+ return output;
5743
5833
  }
5744
5834
  /**
5745
5835
  * @param {import('../types/index').URIComponent} component
@@ -5756,7 +5846,7 @@ var require_utils = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
5756
5846
  if (!isIPv4(host)) {
5757
5847
  const ipV6res = normalizeIPv6(host);
5758
5848
  if (ipV6res.isIPV6 === true) host = `[${ipV6res.escapedHost}]`;
5759
- else host = component.host;
5849
+ else host = reescapeHostDelimiters(host, false);
5760
5850
  }
5761
5851
  uriTokens.push(host);
5762
5852
  }
@@ -5769,7 +5859,10 @@ var require_utils = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
5769
5859
  module.exports = {
5770
5860
  nonSimpleDomain,
5771
5861
  recomposeAuthority,
5772
- normalizeComponentEncoding,
5862
+ reescapeHostDelimiters,
5863
+ normalizePercentEncoding,
5864
+ normalizePathEncoding,
5865
+ escapePreservingEscapes,
5773
5866
  removeDotSegments,
5774
5867
  isIPv4,
5775
5868
  isUUID,
@@ -5963,7 +6056,7 @@ var require_schemes = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
5963
6056
  //#endregion
5964
6057
  //#region node_modules/fast-uri/index.js
5965
6058
  var require_fast_uri = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
5966
- var { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizeComponentEncoding, isIPv4, nonSimpleDomain } = require_utils();
6059
+ var { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizePercentEncoding, normalizePathEncoding, escapePreservingEscapes, reescapeHostDelimiters, isIPv4, nonSimpleDomain } = require_utils();
5967
6060
  var { SCHEMES, getSchemeHandler } = require_schemes();
5968
6061
  /**
5969
6062
  * @template {import('./types/index').URIComponent|string} T
@@ -5972,7 +6065,7 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
5972
6065
  * @returns {T}
5973
6066
  */
5974
6067
  function normalize(uri, options) {
5975
- if (typeof uri === "string") uri = serialize(parse(uri, options), options);
6068
+ if (typeof uri === "string") uri = normalizeString(uri, options);
5976
6069
  else if (typeof uri === "object") uri = parse(serialize(uri, options), options);
5977
6070
  return uri;
5978
6071
  }
@@ -6048,27 +6141,9 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
6048
6141
  * @returns {boolean}
6049
6142
  */
6050
6143
  function equal(uriA, uriB, options) {
6051
- if (typeof uriA === "string") {
6052
- uriA = unescape(uriA);
6053
- uriA = serialize(normalizeComponentEncoding(parse(uriA, options), true), {
6054
- ...options,
6055
- skipEscape: true
6056
- });
6057
- } else if (typeof uriA === "object") uriA = serialize(normalizeComponentEncoding(uriA, true), {
6058
- ...options,
6059
- skipEscape: true
6060
- });
6061
- if (typeof uriB === "string") {
6062
- uriB = unescape(uriB);
6063
- uriB = serialize(normalizeComponentEncoding(parse(uriB, options), true), {
6064
- ...options,
6065
- skipEscape: true
6066
- });
6067
- } else if (typeof uriB === "object") uriB = serialize(normalizeComponentEncoding(uriB, true), {
6068
- ...options,
6069
- skipEscape: true
6070
- });
6071
- return uriA.toLowerCase() === uriB.toLowerCase();
6144
+ const normalizedA = normalizeComparableURI(uriA, options);
6145
+ const normalizedB = normalizeComparableURI(uriB, options);
6146
+ return normalizedA !== void 0 && normalizedB !== void 0 && normalizedA.toLowerCase() === normalizedB.toLowerCase();
6072
6147
  }
6073
6148
  /**
6074
6149
  * @param {Readonly<import('./types/index').URIComponent>} cmpts
@@ -6097,9 +6172,9 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
6097
6172
  const schemeHandler = getSchemeHandler(options.scheme || component.scheme);
6098
6173
  if (schemeHandler && schemeHandler.serialize) schemeHandler.serialize(component, options);
6099
6174
  if (component.path !== void 0) if (!options.skipEscape) {
6100
- component.path = escape(component.path);
6175
+ component.path = escapePreservingEscapes(component.path);
6101
6176
  if (component.scheme !== void 0) component.path = component.path.split("%3A").join(":");
6102
- } else component.path = unescape(component.path);
6177
+ } else component.path = normalizePercentEncoding(component.path);
6103
6178
  if (options.reference !== "suffix" && component.scheme) uriTokens.push(component.scheme, ":");
6104
6179
  const authority = recomposeAuthority(component);
6105
6180
  if (authority !== void 0) {
@@ -6119,11 +6194,20 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
6119
6194
  }
6120
6195
  var URI_PARSE = /^(?:([^#/:?]+):)?(?:\/\/((?:([^#/?@]*)@)?(\[[^#/?\]]+\]|[^#/:?]*)(?::(\d*))?))?([^#?]*)(?:\?([^#]*))?(?:#((?:.|[\n\r])*))?/u;
6121
6196
  /**
6197
+ * @param {import('./types/index').URIComponent} parsed
6198
+ * @param {RegExpMatchArray} matches
6199
+ * @returns {string|undefined}
6200
+ */
6201
+ function getParseError(parsed, matches) {
6202
+ if (matches[2] !== void 0 && parsed.path && parsed.path[0] !== "/") return "URI path must start with \"/\" when authority is present.";
6203
+ if (typeof parsed.port === "number" && (parsed.port < 0 || parsed.port > 65535)) return "URI port is malformed.";
6204
+ }
6205
+ /**
6122
6206
  * @param {string} uri
6123
6207
  * @param {import('./types/index').Options} [opts]
6124
- * @returns
6208
+ * @returns {{ parsed: import('./types/index').URIComponent, malformedAuthorityOrPort: boolean }}
6125
6209
  */
6126
- function parse(uri, opts) {
6210
+ function parseWithStatus(uri, opts) {
6127
6211
  const options = Object.assign({}, opts);
6128
6212
  /** @type {import('./types/index').URIComponent} */
6129
6213
  const parsed = {
@@ -6135,6 +6219,7 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
6135
6219
  query: void 0,
6136
6220
  fragment: void 0
6137
6221
  };
6222
+ let malformedAuthorityOrPort = false;
6138
6223
  let isIP = false;
6139
6224
  if (options.reference === "suffix") if (options.scheme) uri = options.scheme + ":" + uri;
6140
6225
  else uri = "//" + uri;
@@ -6148,6 +6233,11 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
6148
6233
  parsed.query = matches[7];
6149
6234
  parsed.fragment = matches[8];
6150
6235
  if (isNaN(parsed.port)) parsed.port = matches[5];
6236
+ const parseError = getParseError(parsed, matches);
6237
+ if (parseError !== void 0) {
6238
+ parsed.error = parsed.error || parseError;
6239
+ malformedAuthorityOrPort = true;
6240
+ }
6151
6241
  if (parsed.host) if (isIPv4(parsed.host) === false) {
6152
6242
  const ipv6result = normalizeIPv6(parsed.host);
6153
6243
  parsed.host = ipv6result.host.toLowerCase();
@@ -6169,14 +6259,61 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
6169
6259
  if (!schemeHandler || schemeHandler && !schemeHandler.skipNormalize) {
6170
6260
  if (uri.indexOf("%") !== -1) {
6171
6261
  if (parsed.scheme !== void 0) parsed.scheme = unescape(parsed.scheme);
6172
- if (parsed.host !== void 0) parsed.host = unescape(parsed.host);
6262
+ if (parsed.host !== void 0) parsed.host = reescapeHostDelimiters(unescape(parsed.host), isIP);
6263
+ }
6264
+ if (parsed.path) parsed.path = normalizePathEncoding(parsed.path);
6265
+ if (parsed.fragment) try {
6266
+ parsed.fragment = encodeURI(decodeURIComponent(parsed.fragment));
6267
+ } catch {
6268
+ parsed.error = parsed.error || "URI malformed";
6173
6269
  }
6174
- if (parsed.path) parsed.path = escape(unescape(parsed.path));
6175
- if (parsed.fragment) parsed.fragment = encodeURI(decodeURIComponent(parsed.fragment));
6176
6270
  }
6177
6271
  if (schemeHandler && schemeHandler.parse) schemeHandler.parse(parsed, options);
6178
6272
  } else parsed.error = parsed.error || "URI can not be parsed.";
6179
- return parsed;
6273
+ return {
6274
+ parsed,
6275
+ malformedAuthorityOrPort
6276
+ };
6277
+ }
6278
+ /**
6279
+ * @param {string} uri
6280
+ * @param {import('./types/index').Options} [opts]
6281
+ * @returns
6282
+ */
6283
+ function parse(uri, opts) {
6284
+ return parseWithStatus(uri, opts).parsed;
6285
+ }
6286
+ /**
6287
+ * @param {string} uri
6288
+ * @param {import('./types/index').Options} [opts]
6289
+ * @returns {string}
6290
+ */
6291
+ function normalizeString(uri, opts) {
6292
+ return normalizeStringWithStatus(uri, opts).normalized;
6293
+ }
6294
+ /**
6295
+ * @param {string} uri
6296
+ * @param {import('./types/index').Options} [opts]
6297
+ * @returns {{ normalized: string, malformedAuthorityOrPort: boolean }}
6298
+ */
6299
+ function normalizeStringWithStatus(uri, opts) {
6300
+ const { parsed, malformedAuthorityOrPort } = parseWithStatus(uri, opts);
6301
+ return {
6302
+ normalized: malformedAuthorityOrPort ? uri : serialize(parsed, opts),
6303
+ malformedAuthorityOrPort
6304
+ };
6305
+ }
6306
+ /**
6307
+ * @param {import ('./types/index').URIComponent|string} uri
6308
+ * @param {import('./types/index').Options} [opts]
6309
+ * @returns {string|undefined}
6310
+ */
6311
+ function normalizeComparableURI(uri, opts) {
6312
+ if (typeof uri === "string") {
6313
+ const { normalized, malformedAuthorityOrPort } = normalizeStringWithStatus(uri, opts);
6314
+ return malformedAuthorityOrPort ? void 0 : normalized;
6315
+ }
6316
+ if (typeof uri === "object") return serialize(uri, opts);
6180
6317
  }
6181
6318
  var fastUri = {
6182
6319
  SCHEMES,
@@ -10108,7 +10245,6 @@ var globalThisShim = (() => {
10108
10245
  else return Function("return this")();
10109
10246
  })();
10110
10247
  var defaultBinaryType = "arraybuffer";
10111
- function createCookieJar() {}
10112
10248
  //#endregion
10113
10249
  //#region node_modules/engine.io-client/build/esm/util.js
10114
10250
  function pick(obj, ...attr) {
@@ -10975,7 +11111,7 @@ var SocketWithoutUpgrade = class SocketWithoutUpgrade extends Emitter {
10975
11111
  OFFLINE_EVENT_LISTENERS.push(this._offlineEventListener);
10976
11112
  }
10977
11113
  }
10978
- if (this.opts.withCredentials) this._cookieJar = /* @__PURE__ */ createCookieJar();
11114
+ if (this.opts.withCredentials) this._cookieJar = void 0;
10979
11115
  this._open();
10980
11116
  }
10981
11117
  /**
@@ -13048,6 +13184,7 @@ var SocketIoClient = class extends import_tiny_emitter.TinyEmitter {
13048
13184
  #socket;
13049
13185
  #reconnectTimeout = 2e3;
13050
13186
  #ackTimeout = 5e3;
13187
+ #reconnectTimeoutVal = void 0;
13051
13188
  constructor(name) {
13052
13189
  super();
13053
13190
  this.#name = name;
@@ -13120,7 +13257,7 @@ var SocketIoClient = class extends import_tiny_emitter.TinyEmitter {
13120
13257
  return this;
13121
13258
  }
13122
13259
  SetupSocket() {
13123
- if (!this.#address) throw new Error(`SocketIoClientHelper:SetupSocket(): Error: [address not provided]`);
13260
+ if (!this.#address) throw new Error(`SocketIoClient:SetupSocket(): Error: [address not provided]`);
13124
13261
  this.#EstablishSocketConnect();
13125
13262
  return this;
13126
13263
  }
@@ -13130,17 +13267,20 @@ var SocketIoClient = class extends import_tiny_emitter.TinyEmitter {
13130
13267
  EngineReconnect(attempt) {}
13131
13268
  #EstablishSocketConnect() {
13132
13269
  if (this.#socket !== void 0) {
13133
- if (this.#socket.connected === true) this.#socket.disconnect();
13134
- this.#socket = void 0;
13135
- if (isNode) setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout).unref();
13136
- else setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout);
13270
+ this.ResetSocket();
13271
+ if (isNode) this.#reconnectTimeoutVal = setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout).unref();
13272
+ else this.#reconnectTimeoutVal = setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout);
13137
13273
  return;
13138
13274
  }
13139
13275
  let socketOptions;
13140
13276
  if (isNode) {
13141
13277
  socketOptions = { transports: ["websocket"] };
13142
13278
  if (this.#agentManager) {
13143
- if (!this.#address) throw new Error(`SocketIoClient:SetupSocket(): Error: [address not provided when using agentManager]`);
13279
+ if (!this.#address) {
13280
+ const message = `SocketIoClient:#EstablishSocketConnect(): Error: [address not provided when using agentManager]`;
13281
+ this.LogErrorMessage(message);
13282
+ throw new Error(message);
13283
+ }
13144
13284
  socketOptions.agent = this.#agentManager.GetAgent(this.#address);
13145
13285
  }
13146
13286
  } else socketOptions = { transports: ["websocket"] };
@@ -13151,30 +13291,30 @@ var SocketIoClient = class extends import_tiny_emitter.TinyEmitter {
13151
13291
  if (this.#socketIoCustomPath && this.#socketIoCustomPath.localeCompare("") !== 0) socketOptions.path = this.#socketIoCustomPath;
13152
13292
  this.#socket = lookup(this.#address, socketOptions);
13153
13293
  this.#socket.io.on("error", (err) => {
13154
- this.LogErrorMessage(`socketDetail.socket.io.on('error'): [${err}] Address: [${this.#address}]`);
13294
+ this.LogErrorMessage(`SocketIoClient.socket.io.on('error'): [${err}] Address: [${this.#address}]`);
13155
13295
  this.EngineError(err);
13156
13296
  });
13157
13297
  this.#socket.io.on("reconnect_error", (err) => {
13158
- this.LogErrorMessage(`socketDetail.socket.io.on('reconnect_error'): [${err}] Address: [${this.#address}]`);
13298
+ this.LogErrorMessage(`SocketIoClient.socket.io.on('reconnect_error'): [${err}] Address: [${this.#address}]`);
13159
13299
  this.EngineReconnectError(err);
13160
13300
  });
13161
13301
  this.#socket.on("connect_error", (err) => {
13162
- this.LogErrorMessage(`socketDetail.socket.on('connect_error'): [${err}] Address: [${this.#address}]`);
13302
+ this.LogErrorMessage(`SocketIoClient.socket.on('connect_error'): [${err}] Address: [${this.#address}]`);
13163
13303
  this.EngineConnectError(err);
13164
13304
  });
13165
13305
  this.#socket.io.on("reconnect", (attempt) => {
13166
- this.LogErrorMessage(`socketDetail.socket.io.on('reconnect'): Number: [${attempt}] Address: [${this.#address}]`);
13306
+ this.LogErrorMessage(`SocketIoClient:socket.io.on('reconnect'): Number: [${attempt}] Address: [${this.#address}]`);
13167
13307
  this.EngineReconnect(attempt);
13168
13308
  });
13169
13309
  this.#socket.on("connect", () => {
13170
13310
  if (this.#socket) {
13171
- this.LogDebugMessage(`Socket: [${this.#socket.id}]: connected, Address: [${this.#address}]`);
13311
+ this.LogDebugMessage(`SocketIoClient:on("connect"): Socket: [${this.#socket.id}]: connected, Address: [${this.#address}]`);
13172
13312
  setTimeout(() => {
13173
13313
  this.SocketConnect(this.#socket);
13174
13314
  }, 0);
13175
13315
  this.SetupSocketEvents(this.#socket);
13176
13316
  } else {
13177
- const errorMessage = "Could not get socket object from socket.io, Address: [${socketDetail.address}]";
13317
+ const errorMessage = "SocketIoClient:on(\"connect\"): Could not get socket object from socket.io, Address: [${socketDetail.address}]";
13178
13318
  this.LogErrorMessage(errorMessage);
13179
13319
  this.SocketConnectError(new Error(errorMessage));
13180
13320
  }
@@ -13184,33 +13324,50 @@ var SocketIoClient = class extends import_tiny_emitter.TinyEmitter {
13184
13324
  this.SocketDisconnect(reason);
13185
13325
  switch (reason) {
13186
13326
  case "io server disconnect":
13187
- this.LogDebugMessage("The server disconnected using disconnectSockets, i.e. normal safe shutdown from explicit disconnection by the server.");
13188
- this.LogDebugMessage("The connection will be re-established when the server becomes available.");
13189
- this.#socket = void 0;
13190
- if (isNode) {
13191
- if (this.#agentManager) this.#agentManager.ResetAgent();
13192
- setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout).unref();
13193
- } else setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout);
13327
+ this.LogDebugMessage("SocketIoClient:on(\"disconnect\"): The server disconnected using disconnectSockets, i.e. normal safe shutdown from explicit disconnection by the server.");
13328
+ this.LogDebugMessage("SocketIoClient:on(\"disconnect\"): The connection will be re-established when the server becomes available.");
13329
+ this.ResetSocket();
13330
+ if (isNode) this.#reconnectTimeoutVal = setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout).unref();
13331
+ else this.#reconnectTimeoutVal = setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout);
13194
13332
  break;
13195
13333
  case "io client disconnect":
13196
- this.LogDebugMessage("The client disconnected using disconnectSockets, i.e. normal safe disconnection from explicit disconnection by the client.");
13197
- this.LogDebugMessage("The connection will not be re-established automatically.");
13334
+ this.LogDebugMessage("SocketIoClient:on(\"disconnect\"): The client disconnected using disconnectSockets, i.e. normal safe disconnection from explicit disconnection by the client.");
13335
+ this.LogDebugMessage("SocketIoClient:on(\"disconnect\"): The connection will not be re-established automatically.");
13336
+ this.ResetSocket();
13198
13337
  break;
13199
13338
  case "transport close":
13200
13339
  case "ping timeout":
13201
13340
  case "transport error":
13202
- this.LogDebugMessage(`Server unexpectedly disconnected. Reason: [${reason}]`);
13203
- this.LogDebugMessage("The connection will be re-established when the server becomes available.");
13204
- if (this.#socket) this.#socket.disconnect();
13205
- this.#socket = void 0;
13206
- if (isNode) {
13207
- if (this.#agentManager) this.#agentManager?.ResetAgent();
13208
- setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout).unref();
13209
- } else setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout);
13341
+ this.LogDebugMessage(`SocketIoClient:on("disconnect"): Server unexpectedly disconnected. Reason: [${reason}]`);
13342
+ this.LogDebugMessage("SocketIoClient:on(\"disconnect\"): The connection will be re-established when the server becomes available.");
13343
+ this.ResetSocket();
13344
+ if (isNode) this.#reconnectTimeoutVal = setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout).unref();
13345
+ else this.#reconnectTimeoutVal = setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout);
13210
13346
  break;
13211
13347
  }
13212
13348
  });
13213
13349
  }
13350
+ ResetSocket = () => {
13351
+ try {
13352
+ if (this.#reconnectTimeoutVal !== void 0) {
13353
+ clearTimeout(this.#reconnectTimeoutVal);
13354
+ this.#reconnectTimeoutVal = void 0;
13355
+ }
13356
+ if (this.#socket) {
13357
+ this.#socket.removeAllListeners();
13358
+ this.#socket.io.removeAllListeners();
13359
+ if (this.#socket.connected === true) this.#socket.disconnect();
13360
+ if (isNode) {
13361
+ if (this.#agentManager) this.#agentManager.ResetAgent();
13362
+ }
13363
+ this.#socket = void 0;
13364
+ }
13365
+ } catch (error) {
13366
+ const errorMessage = `SocketIoClient:ResetSocket(): Error: [${error}]`;
13367
+ this.LogErrorMessage(errorMessage);
13368
+ this.SocketConnectError(new Error(errorMessage));
13369
+ }
13370
+ };
13214
13371
  };
13215
13372
  //#endregion
13216
13373
  //#region src/cv2/fhirSocketClient.ts
@@ -13228,23 +13385,45 @@ var FhirSocketClient = class extends SocketIoClient {
13228
13385
  if (this.options.joinRooms.length > 0 && socket) socket.emit("__STSjoinRoom", this.options.joinRooms);
13229
13386
  }
13230
13387
  SocketError(error) {
13231
- this.LogErrorMessage(`FhirSocketClient:SocketError(): Error clientName: [${this.name}]: SetupClientSideSocket call back: Error: [${error}]`);
13388
+ this.LogErrorMessage(`FhirSocketClient:SocketError(): Error clientName: [${this.name}]: Error: [${error}]`);
13389
+ }
13390
+ SocketConnectError(error) {
13391
+ this.LogErrorMessage(`FhirSocketClient:SocketConnectError(): Error clientName: [${this.name}]: Error: [${error}]`);
13392
+ }
13393
+ SocketDisconnect(reason) {
13394
+ this.LogDebugMessage(`FhirSocketClient:SocketDisconnect(): Error clientName: [${this.name}]: Reason: [${reason}]`);
13395
+ }
13396
+ SetupSocketEvents(socket) {
13397
+ this.LogDebugMessage(`FhirSocketClient:SetupSocketEvents(): Error clientName: [${this.name}]`);
13232
13398
  }
13233
- SocketConnectError(error) {}
13234
- SocketDisconnect(reason) {}
13235
- SetupSocketEvents(socket) {}
13236
13399
  SetupWSSClient = async () => {
13237
- this.LogDebugMessage(chalk.yellow(`FhirSocketClient:SetupWSSClient(): ID: [${this.id}] clientName: [${this.name}] Starting ...`));
13238
- const cstr = `${this.options.fhirServerEndpoint}:${this.options.fhirServerPort}/nsstsfhir/`;
13239
- this.LogDebugMessage(chalk.yellow(`FhirSocketClient:SetupWSSClient(): Socket connection string: [${cstr}]`));
13240
- this.WithAddress(cstr).WithSocketIoCustomPath(this.options.socketIoCustomPath).WithAuthToken(this.options.authToken);
13241
- if (this.options.agentManager) this.WithAgentManager(this.options.agentManager);
13242
- if (this.options.logger) this.WithLogger(this.options.logger);
13243
- this.SetupSocket();
13244
- this.LogDebugMessage(chalk.yellow(`FhirSocketClient:SetupWSSClient(): ID: [${this.id}] clientName: [${this.name}] Started`));
13400
+ try {
13401
+ this.LogDebugMessage(chalk.yellow(`FhirSocketClient:SetupWSSClient(): ID: [${this.id}] clientName: [${this.name}] Starting ...`));
13402
+ const cstr = `${this.options.fhirServerEndpoint}:${this.options.fhirServerPort}/nsstsfhir/`;
13403
+ this.LogDebugMessage(chalk.yellow(`FhirSocketClient:SetupWSSClient(): Socket connection string: [${cstr}]`));
13404
+ let connectionAccessToken;
13405
+ try {
13406
+ connectionAccessToken = await this.options.GetConnectionAccessToken();
13407
+ } catch (error) {
13408
+ const message = `FhirSocketClient:SetupWSSClient():GetConnectionAccessToken(): Error clientName: [${this.name}]: Error: [${error}]`;
13409
+ this.LogErrorMessage(message);
13410
+ throw new Error(message);
13411
+ }
13412
+ this.WithAddress(cstr).WithSocketIoCustomPath(this.options.socketIoCustomPath).WithAuthToken(connectionAccessToken);
13413
+ if (this.options.agentManager) this.WithAgentManager(this.options.agentManager);
13414
+ if (this.options.logger) this.WithLogger(this.options.logger);
13415
+ this.SetupSocket();
13416
+ this.LogDebugMessage(chalk.yellow(`FhirSocketClient:SetupWSSClient(): ID: [${this.id}] clientName: [${this.name}] Started`));
13417
+ } catch (error) {
13418
+ const message = `FhirSocketClient:SetupWSSClient(): Error clientName: [${this.name}]: Error: [${error}]`;
13419
+ this.LogErrorMessage(message);
13420
+ throw new Error(message);
13421
+ }
13245
13422
  };
13246
13423
  WaitForSocketConnected = async () => {
13247
- const maxAttempts = 50;
13424
+ const maxAttempts = 20;
13425
+ const resetAfterAttempts = 10;
13426
+ const retryDelay = 250;
13248
13427
  if (this.socket && this.socket.connected === true) return true;
13249
13428
  else {
13250
13429
  this.LogDebugMessage(chalk.yellow(`FhirSocketClient:WaitForSocketConnected(): ID: [${this.id}] clientName: [${this.name}] Waiting for connection ...`));
@@ -13256,9 +13435,20 @@ var FhirSocketClient = class extends SocketIoClient {
13256
13435
  this.LogDebugMessage(chalk.yellow(`FhirSocketClient:WaitForSocketConnected(): ID: [${this.id}] clientName: [${this.name}] Connection completed after: [${attempts}] attempts.`));
13257
13436
  return true;
13258
13437
  }
13259
- await Sleep(100);
13438
+ if (attempts === resetAfterAttempts) {
13439
+ this.LogDebugMessage(chalk.rgb(255, 165, 0)(`FhirSocketClient:WaitForSocketConnected(): ID: [${this.id}] clientName: [${this.name}] Resetting Socket. Attempt Number: [${attempts}]`));
13440
+ this.ResetSocket();
13441
+ this.LogDebugMessage(chalk.rgb(255, 165, 0)(`FhirSocketClient:WaitForSocketConnected(): ID: [${this.id}] clientName: [${this.name}] Socket Reset. Attempt Number: [${attempts}]`));
13442
+ await Sleep(retryDelay);
13443
+ this.LogDebugMessage(chalk.rgb(255, 165, 0)(`FhirSocketClient:WaitForSocketConnected(): ID: [${this.id}] clientName: [${this.name}] SetupSocket. Attempt Number: [${attempts}]`));
13444
+ this.SetupSocket();
13445
+ await Sleep(retryDelay);
13446
+ }
13447
+ await Sleep(retryDelay);
13260
13448
  }
13261
- throw new Error(`FhirSocketClient:WaitForSocketConnected(): Error: [Could not connect after ${maxAttempts} connection attempts]`);
13449
+ const message = `FhirSocketClient:WaitForSocketConnected(): Error: [Could not connect after ${maxAttempts} connection attempts]`;
13450
+ this.LogErrorMessage(message);
13451
+ throw new Error(message);
13262
13452
  }
13263
13453
  };
13264
13454
  WithAccessToken = (accessToken) => {