@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.
@@ -5513,6 +5513,12 @@ var require_utils = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
5513
5513
  var isUUID = RegExp.prototype.test.bind(/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iu);
5514
5514
  /** @type {(value: string) => boolean} */
5515
5515
  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);
5516
+ /** @type {(value: string) => boolean} */
5517
+ var isHexPair = RegExp.prototype.test.bind(/^[\da-f]{2}$/iu);
5518
+ /** @type {(value: string) => boolean} */
5519
+ var isUnreserved = RegExp.prototype.test.bind(/^[\da-z\-._~]$/iu);
5520
+ /** @type {(value: string) => boolean} */
5521
+ var isPathCharacter = RegExp.prototype.test.bind(/^[\da-z\-._~!$&'()*+,;=:@/]$/iu);
5516
5522
  /**
5517
5523
  * @param {Array<string>} input
5518
5524
  * @returns {string}
@@ -5735,19 +5741,103 @@ var require_utils = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
5735
5741
  return output.join("");
5736
5742
  }
5737
5743
  /**
5738
- * @param {import('../types/index').URIComponent} component
5739
- * @param {boolean} esc
5740
- * @returns {import('../types/index').URIComponent}
5744
+ * Re-escape RFC 3986 gen-delims that must not appear literally in the host.
5745
+ * After the URI regex parses, these characters cannot be literal in the host
5746
+ * field, so any that appear after decoding came from percent-encoding and
5747
+ * must be restored to prevent authority structure changes.
5748
+ *
5749
+ * @param {string} host
5750
+ * @param {boolean} isIP - true for IPv4/IPv6 hosts (skip colon re-escaping)
5751
+ * @returns {string}
5741
5752
  */
5742
- function normalizeComponentEncoding(component, esc) {
5743
- const func = esc !== true ? escape : unescape;
5744
- if (component.scheme !== void 0) component.scheme = func(component.scheme);
5745
- if (component.userinfo !== void 0) component.userinfo = func(component.userinfo);
5746
- if (component.host !== void 0) component.host = func(component.host);
5747
- if (component.path !== void 0) component.path = func(component.path);
5748
- if (component.query !== void 0) component.query = func(component.query);
5749
- if (component.fragment !== void 0) component.fragment = func(component.fragment);
5750
- return component;
5753
+ var HOST_DELIMS = {
5754
+ "@": "%40",
5755
+ "/": "%2F",
5756
+ "?": "%3F",
5757
+ "#": "%23",
5758
+ ":": "%3A"
5759
+ };
5760
+ var HOST_DELIM_RE = /[@/?#:]/g;
5761
+ var HOST_DELIM_NO_COLON_RE = /[@/?#]/g;
5762
+ function reescapeHostDelimiters(host, isIP) {
5763
+ const re = isIP ? HOST_DELIM_NO_COLON_RE : HOST_DELIM_RE;
5764
+ re.lastIndex = 0;
5765
+ return host.replace(re, (ch) => HOST_DELIMS[ch]);
5766
+ }
5767
+ /**
5768
+ * Normalizes percent escapes and optionally decodes only unreserved ASCII bytes.
5769
+ * Reserved delimiters such as `%2F` and `%2E` stay escaped.
5770
+ *
5771
+ * @param {string} input
5772
+ * @param {boolean} [decodeUnreserved=false]
5773
+ * @returns {string}
5774
+ */
5775
+ function normalizePercentEncoding(input, decodeUnreserved = false) {
5776
+ if (input.indexOf("%") === -1) return input;
5777
+ let output = "";
5778
+ for (let i = 0; i < input.length; i++) {
5779
+ if (input[i] === "%" && i + 2 < input.length) {
5780
+ const hex = input.slice(i + 1, i + 3);
5781
+ if (isHexPair(hex)) {
5782
+ const normalizedHex = hex.toUpperCase();
5783
+ const decoded = String.fromCharCode(parseInt(normalizedHex, 16));
5784
+ if (decodeUnreserved && isUnreserved(decoded)) output += decoded;
5785
+ else output += "%" + normalizedHex;
5786
+ i += 2;
5787
+ continue;
5788
+ }
5789
+ }
5790
+ output += input[i];
5791
+ }
5792
+ return output;
5793
+ }
5794
+ /**
5795
+ * Normalizes path data without turning reserved escapes into live path syntax.
5796
+ * Valid escapes are uppercased, raw unsafe characters are escaped, and only
5797
+ * unreserved bytes that are not `.` are decoded.
5798
+ *
5799
+ * @param {string} input
5800
+ * @returns {string}
5801
+ */
5802
+ function normalizePathEncoding(input) {
5803
+ let output = "";
5804
+ for (let i = 0; i < input.length; i++) {
5805
+ if (input[i] === "%" && i + 2 < input.length) {
5806
+ const hex = input.slice(i + 1, i + 3);
5807
+ if (isHexPair(hex)) {
5808
+ const normalizedHex = hex.toUpperCase();
5809
+ const decoded = String.fromCharCode(parseInt(normalizedHex, 16));
5810
+ if (decoded !== "." && isUnreserved(decoded)) output += decoded;
5811
+ else output += "%" + normalizedHex;
5812
+ i += 2;
5813
+ continue;
5814
+ }
5815
+ }
5816
+ if (isPathCharacter(input[i])) output += input[i];
5817
+ else output += escape(input[i]);
5818
+ }
5819
+ return output;
5820
+ }
5821
+ /**
5822
+ * Escapes a component while preserving existing valid percent escapes.
5823
+ *
5824
+ * @param {string} input
5825
+ * @returns {string}
5826
+ */
5827
+ function escapePreservingEscapes(input) {
5828
+ let output = "";
5829
+ for (let i = 0; i < input.length; i++) {
5830
+ if (input[i] === "%" && i + 2 < input.length) {
5831
+ const hex = input.slice(i + 1, i + 3);
5832
+ if (isHexPair(hex)) {
5833
+ output += "%" + hex.toUpperCase();
5834
+ i += 2;
5835
+ continue;
5836
+ }
5837
+ }
5838
+ output += escape(input[i]);
5839
+ }
5840
+ return output;
5751
5841
  }
5752
5842
  /**
5753
5843
  * @param {import('../types/index').URIComponent} component
@@ -5764,7 +5854,7 @@ var require_utils = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
5764
5854
  if (!isIPv4(host)) {
5765
5855
  const ipV6res = normalizeIPv6(host);
5766
5856
  if (ipV6res.isIPV6 === true) host = `[${ipV6res.escapedHost}]`;
5767
- else host = component.host;
5857
+ else host = reescapeHostDelimiters(host, false);
5768
5858
  }
5769
5859
  uriTokens.push(host);
5770
5860
  }
@@ -5777,7 +5867,10 @@ var require_utils = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
5777
5867
  module.exports = {
5778
5868
  nonSimpleDomain,
5779
5869
  recomposeAuthority,
5780
- normalizeComponentEncoding,
5870
+ reescapeHostDelimiters,
5871
+ normalizePercentEncoding,
5872
+ normalizePathEncoding,
5873
+ escapePreservingEscapes,
5781
5874
  removeDotSegments,
5782
5875
  isIPv4,
5783
5876
  isUUID,
@@ -5971,7 +6064,7 @@ var require_schemes = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
5971
6064
  //#endregion
5972
6065
  //#region node_modules/fast-uri/index.js
5973
6066
  var require_fast_uri = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
5974
- var { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizeComponentEncoding, isIPv4, nonSimpleDomain } = require_utils();
6067
+ var { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizePercentEncoding, normalizePathEncoding, escapePreservingEscapes, reescapeHostDelimiters, isIPv4, nonSimpleDomain } = require_utils();
5975
6068
  var { SCHEMES, getSchemeHandler } = require_schemes();
5976
6069
  /**
5977
6070
  * @template {import('./types/index').URIComponent|string} T
@@ -5980,7 +6073,7 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
5980
6073
  * @returns {T}
5981
6074
  */
5982
6075
  function normalize(uri, options) {
5983
- if (typeof uri === "string") uri = serialize(parse(uri, options), options);
6076
+ if (typeof uri === "string") uri = normalizeString(uri, options);
5984
6077
  else if (typeof uri === "object") uri = parse(serialize(uri, options), options);
5985
6078
  return uri;
5986
6079
  }
@@ -6056,27 +6149,9 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
6056
6149
  * @returns {boolean}
6057
6150
  */
6058
6151
  function equal(uriA, uriB, options) {
6059
- if (typeof uriA === "string") {
6060
- uriA = unescape(uriA);
6061
- uriA = serialize(normalizeComponentEncoding(parse(uriA, options), true), {
6062
- ...options,
6063
- skipEscape: true
6064
- });
6065
- } else if (typeof uriA === "object") uriA = serialize(normalizeComponentEncoding(uriA, true), {
6066
- ...options,
6067
- skipEscape: true
6068
- });
6069
- if (typeof uriB === "string") {
6070
- uriB = unescape(uriB);
6071
- uriB = serialize(normalizeComponentEncoding(parse(uriB, options), true), {
6072
- ...options,
6073
- skipEscape: true
6074
- });
6075
- } else if (typeof uriB === "object") uriB = serialize(normalizeComponentEncoding(uriB, true), {
6076
- ...options,
6077
- skipEscape: true
6078
- });
6079
- return uriA.toLowerCase() === uriB.toLowerCase();
6152
+ const normalizedA = normalizeComparableURI(uriA, options);
6153
+ const normalizedB = normalizeComparableURI(uriB, options);
6154
+ return normalizedA !== void 0 && normalizedB !== void 0 && normalizedA.toLowerCase() === normalizedB.toLowerCase();
6080
6155
  }
6081
6156
  /**
6082
6157
  * @param {Readonly<import('./types/index').URIComponent>} cmpts
@@ -6105,9 +6180,9 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
6105
6180
  const schemeHandler = getSchemeHandler(options.scheme || component.scheme);
6106
6181
  if (schemeHandler && schemeHandler.serialize) schemeHandler.serialize(component, options);
6107
6182
  if (component.path !== void 0) if (!options.skipEscape) {
6108
- component.path = escape(component.path);
6183
+ component.path = escapePreservingEscapes(component.path);
6109
6184
  if (component.scheme !== void 0) component.path = component.path.split("%3A").join(":");
6110
- } else component.path = unescape(component.path);
6185
+ } else component.path = normalizePercentEncoding(component.path);
6111
6186
  if (options.reference !== "suffix" && component.scheme) uriTokens.push(component.scheme, ":");
6112
6187
  const authority = recomposeAuthority(component);
6113
6188
  if (authority !== void 0) {
@@ -6127,11 +6202,20 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
6127
6202
  }
6128
6203
  var URI_PARSE = /^(?:([^#/:?]+):)?(?:\/\/((?:([^#/?@]*)@)?(\[[^#/?\]]+\]|[^#/:?]*)(?::(\d*))?))?([^#?]*)(?:\?([^#]*))?(?:#((?:.|[\n\r])*))?/u;
6129
6204
  /**
6205
+ * @param {import('./types/index').URIComponent} parsed
6206
+ * @param {RegExpMatchArray} matches
6207
+ * @returns {string|undefined}
6208
+ */
6209
+ function getParseError(parsed, matches) {
6210
+ if (matches[2] !== void 0 && parsed.path && parsed.path[0] !== "/") return "URI path must start with \"/\" when authority is present.";
6211
+ if (typeof parsed.port === "number" && (parsed.port < 0 || parsed.port > 65535)) return "URI port is malformed.";
6212
+ }
6213
+ /**
6130
6214
  * @param {string} uri
6131
6215
  * @param {import('./types/index').Options} [opts]
6132
- * @returns
6216
+ * @returns {{ parsed: import('./types/index').URIComponent, malformedAuthorityOrPort: boolean }}
6133
6217
  */
6134
- function parse(uri, opts) {
6218
+ function parseWithStatus(uri, opts) {
6135
6219
  const options = Object.assign({}, opts);
6136
6220
  /** @type {import('./types/index').URIComponent} */
6137
6221
  const parsed = {
@@ -6143,6 +6227,7 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
6143
6227
  query: void 0,
6144
6228
  fragment: void 0
6145
6229
  };
6230
+ let malformedAuthorityOrPort = false;
6146
6231
  let isIP = false;
6147
6232
  if (options.reference === "suffix") if (options.scheme) uri = options.scheme + ":" + uri;
6148
6233
  else uri = "//" + uri;
@@ -6156,6 +6241,11 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
6156
6241
  parsed.query = matches[7];
6157
6242
  parsed.fragment = matches[8];
6158
6243
  if (isNaN(parsed.port)) parsed.port = matches[5];
6244
+ const parseError = getParseError(parsed, matches);
6245
+ if (parseError !== void 0) {
6246
+ parsed.error = parsed.error || parseError;
6247
+ malformedAuthorityOrPort = true;
6248
+ }
6159
6249
  if (parsed.host) if (isIPv4(parsed.host) === false) {
6160
6250
  const ipv6result = normalizeIPv6(parsed.host);
6161
6251
  parsed.host = ipv6result.host.toLowerCase();
@@ -6177,14 +6267,61 @@ var require_fast_uri = /* @__PURE__ */ __commonJSMin$1(((exports, module) => {
6177
6267
  if (!schemeHandler || schemeHandler && !schemeHandler.skipNormalize) {
6178
6268
  if (uri.indexOf("%") !== -1) {
6179
6269
  if (parsed.scheme !== void 0) parsed.scheme = unescape(parsed.scheme);
6180
- if (parsed.host !== void 0) parsed.host = unescape(parsed.host);
6270
+ if (parsed.host !== void 0) parsed.host = reescapeHostDelimiters(unescape(parsed.host), isIP);
6271
+ }
6272
+ if (parsed.path) parsed.path = normalizePathEncoding(parsed.path);
6273
+ if (parsed.fragment) try {
6274
+ parsed.fragment = encodeURI(decodeURIComponent(parsed.fragment));
6275
+ } catch {
6276
+ parsed.error = parsed.error || "URI malformed";
6181
6277
  }
6182
- if (parsed.path) parsed.path = escape(unescape(parsed.path));
6183
- if (parsed.fragment) parsed.fragment = encodeURI(decodeURIComponent(parsed.fragment));
6184
6278
  }
6185
6279
  if (schemeHandler && schemeHandler.parse) schemeHandler.parse(parsed, options);
6186
6280
  } else parsed.error = parsed.error || "URI can not be parsed.";
6187
- return parsed;
6281
+ return {
6282
+ parsed,
6283
+ malformedAuthorityOrPort
6284
+ };
6285
+ }
6286
+ /**
6287
+ * @param {string} uri
6288
+ * @param {import('./types/index').Options} [opts]
6289
+ * @returns
6290
+ */
6291
+ function parse(uri, opts) {
6292
+ return parseWithStatus(uri, opts).parsed;
6293
+ }
6294
+ /**
6295
+ * @param {string} uri
6296
+ * @param {import('./types/index').Options} [opts]
6297
+ * @returns {string}
6298
+ */
6299
+ function normalizeString(uri, opts) {
6300
+ return normalizeStringWithStatus(uri, opts).normalized;
6301
+ }
6302
+ /**
6303
+ * @param {string} uri
6304
+ * @param {import('./types/index').Options} [opts]
6305
+ * @returns {{ normalized: string, malformedAuthorityOrPort: boolean }}
6306
+ */
6307
+ function normalizeStringWithStatus(uri, opts) {
6308
+ const { parsed, malformedAuthorityOrPort } = parseWithStatus(uri, opts);
6309
+ return {
6310
+ normalized: malformedAuthorityOrPort ? uri : serialize(parsed, opts),
6311
+ malformedAuthorityOrPort
6312
+ };
6313
+ }
6314
+ /**
6315
+ * @param {import ('./types/index').URIComponent|string} uri
6316
+ * @param {import('./types/index').Options} [opts]
6317
+ * @returns {string|undefined}
6318
+ */
6319
+ function normalizeComparableURI(uri, opts) {
6320
+ if (typeof uri === "string") {
6321
+ const { normalized, malformedAuthorityOrPort } = normalizeStringWithStatus(uri, opts);
6322
+ return malformedAuthorityOrPort ? void 0 : normalized;
6323
+ }
6324
+ if (typeof uri === "object") return serialize(uri, opts);
6188
6325
  }
6189
6326
  var fastUri = {
6190
6327
  SCHEMES,
@@ -10116,7 +10253,6 @@ var globalThisShim = (() => {
10116
10253
  else return Function("return this")();
10117
10254
  })();
10118
10255
  var defaultBinaryType = "arraybuffer";
10119
- function createCookieJar() {}
10120
10256
  //#endregion
10121
10257
  //#region node_modules/engine.io-client/build/esm/util.js
10122
10258
  function pick(obj, ...attr) {
@@ -10983,7 +11119,7 @@ var SocketWithoutUpgrade = class SocketWithoutUpgrade extends _socket_io_compone
10983
11119
  OFFLINE_EVENT_LISTENERS.push(this._offlineEventListener);
10984
11120
  }
10985
11121
  }
10986
- if (this.opts.withCredentials) this._cookieJar = /* @__PURE__ */ createCookieJar();
11122
+ if (this.opts.withCredentials) this._cookieJar = void 0;
10987
11123
  this._open();
10988
11124
  }
10989
11125
  /**
@@ -13056,6 +13192,7 @@ var SocketIoClient = class extends import_tiny_emitter.TinyEmitter {
13056
13192
  #socket;
13057
13193
  #reconnectTimeout = 2e3;
13058
13194
  #ackTimeout = 5e3;
13195
+ #reconnectTimeoutVal = void 0;
13059
13196
  constructor(name) {
13060
13197
  super();
13061
13198
  this.#name = name;
@@ -13128,7 +13265,7 @@ var SocketIoClient = class extends import_tiny_emitter.TinyEmitter {
13128
13265
  return this;
13129
13266
  }
13130
13267
  SetupSocket() {
13131
- if (!this.#address) throw new Error(`SocketIoClientHelper:SetupSocket(): Error: [address not provided]`);
13268
+ if (!this.#address) throw new Error(`SocketIoClient:SetupSocket(): Error: [address not provided]`);
13132
13269
  this.#EstablishSocketConnect();
13133
13270
  return this;
13134
13271
  }
@@ -13138,17 +13275,20 @@ var SocketIoClient = class extends import_tiny_emitter.TinyEmitter {
13138
13275
  EngineReconnect(attempt) {}
13139
13276
  #EstablishSocketConnect() {
13140
13277
  if (this.#socket !== void 0) {
13141
- if (this.#socket.connected === true) this.#socket.disconnect();
13142
- this.#socket = void 0;
13143
- if (_nsshunt_stsutils.isNode) setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout).unref();
13144
- else setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout);
13278
+ this.ResetSocket();
13279
+ if (_nsshunt_stsutils.isNode) this.#reconnectTimeoutVal = setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout).unref();
13280
+ else this.#reconnectTimeoutVal = setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout);
13145
13281
  return;
13146
13282
  }
13147
13283
  let socketOptions;
13148
13284
  if (_nsshunt_stsutils.isNode) {
13149
13285
  socketOptions = { transports: ["websocket"] };
13150
13286
  if (this.#agentManager) {
13151
- if (!this.#address) throw new Error(`SocketIoClient:SetupSocket(): Error: [address not provided when using agentManager]`);
13287
+ if (!this.#address) {
13288
+ const message = `SocketIoClient:#EstablishSocketConnect(): Error: [address not provided when using agentManager]`;
13289
+ this.LogErrorMessage(message);
13290
+ throw new Error(message);
13291
+ }
13152
13292
  socketOptions.agent = this.#agentManager.GetAgent(this.#address);
13153
13293
  }
13154
13294
  } else socketOptions = { transports: ["websocket"] };
@@ -13159,30 +13299,30 @@ var SocketIoClient = class extends import_tiny_emitter.TinyEmitter {
13159
13299
  if (this.#socketIoCustomPath && this.#socketIoCustomPath.localeCompare("") !== 0) socketOptions.path = this.#socketIoCustomPath;
13160
13300
  this.#socket = lookup(this.#address, socketOptions);
13161
13301
  this.#socket.io.on("error", (err) => {
13162
- this.LogErrorMessage(`socketDetail.socket.io.on('error'): [${err}] Address: [${this.#address}]`);
13302
+ this.LogErrorMessage(`SocketIoClient.socket.io.on('error'): [${err}] Address: [${this.#address}]`);
13163
13303
  this.EngineError(err);
13164
13304
  });
13165
13305
  this.#socket.io.on("reconnect_error", (err) => {
13166
- this.LogErrorMessage(`socketDetail.socket.io.on('reconnect_error'): [${err}] Address: [${this.#address}]`);
13306
+ this.LogErrorMessage(`SocketIoClient.socket.io.on('reconnect_error'): [${err}] Address: [${this.#address}]`);
13167
13307
  this.EngineReconnectError(err);
13168
13308
  });
13169
13309
  this.#socket.on("connect_error", (err) => {
13170
- this.LogErrorMessage(`socketDetail.socket.on('connect_error'): [${err}] Address: [${this.#address}]`);
13310
+ this.LogErrorMessage(`SocketIoClient.socket.on('connect_error'): [${err}] Address: [${this.#address}]`);
13171
13311
  this.EngineConnectError(err);
13172
13312
  });
13173
13313
  this.#socket.io.on("reconnect", (attempt) => {
13174
- this.LogErrorMessage(`socketDetail.socket.io.on('reconnect'): Number: [${attempt}] Address: [${this.#address}]`);
13314
+ this.LogErrorMessage(`SocketIoClient:socket.io.on('reconnect'): Number: [${attempt}] Address: [${this.#address}]`);
13175
13315
  this.EngineReconnect(attempt);
13176
13316
  });
13177
13317
  this.#socket.on("connect", () => {
13178
13318
  if (this.#socket) {
13179
- this.LogDebugMessage(`Socket: [${this.#socket.id}]: connected, Address: [${this.#address}]`);
13319
+ this.LogDebugMessage(`SocketIoClient:on("connect"): Socket: [${this.#socket.id}]: connected, Address: [${this.#address}]`);
13180
13320
  setTimeout(() => {
13181
13321
  this.SocketConnect(this.#socket);
13182
13322
  }, 0);
13183
13323
  this.SetupSocketEvents(this.#socket);
13184
13324
  } else {
13185
- const errorMessage = "Could not get socket object from socket.io, Address: [${socketDetail.address}]";
13325
+ const errorMessage = "SocketIoClient:on(\"connect\"): Could not get socket object from socket.io, Address: [${socketDetail.address}]";
13186
13326
  this.LogErrorMessage(errorMessage);
13187
13327
  this.SocketConnectError(new Error(errorMessage));
13188
13328
  }
@@ -13192,33 +13332,50 @@ var SocketIoClient = class extends import_tiny_emitter.TinyEmitter {
13192
13332
  this.SocketDisconnect(reason);
13193
13333
  switch (reason) {
13194
13334
  case "io server disconnect":
13195
- this.LogDebugMessage("The server disconnected using disconnectSockets, i.e. normal safe shutdown from explicit disconnection by the server.");
13196
- this.LogDebugMessage("The connection will be re-established when the server becomes available.");
13197
- this.#socket = void 0;
13198
- if (_nsshunt_stsutils.isNode) {
13199
- if (this.#agentManager) this.#agentManager.ResetAgent();
13200
- setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout).unref();
13201
- } else setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout);
13335
+ this.LogDebugMessage("SocketIoClient:on(\"disconnect\"): The server disconnected using disconnectSockets, i.e. normal safe shutdown from explicit disconnection by the server.");
13336
+ this.LogDebugMessage("SocketIoClient:on(\"disconnect\"): The connection will be re-established when the server becomes available.");
13337
+ this.ResetSocket();
13338
+ if (_nsshunt_stsutils.isNode) this.#reconnectTimeoutVal = setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout).unref();
13339
+ else this.#reconnectTimeoutVal = setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout);
13202
13340
  break;
13203
13341
  case "io client disconnect":
13204
- this.LogDebugMessage("The client disconnected using disconnectSockets, i.e. normal safe disconnection from explicit disconnection by the client.");
13205
- this.LogDebugMessage("The connection will not be re-established automatically.");
13342
+ this.LogDebugMessage("SocketIoClient:on(\"disconnect\"): The client disconnected using disconnectSockets, i.e. normal safe disconnection from explicit disconnection by the client.");
13343
+ this.LogDebugMessage("SocketIoClient:on(\"disconnect\"): The connection will not be re-established automatically.");
13344
+ this.ResetSocket();
13206
13345
  break;
13207
13346
  case "transport close":
13208
13347
  case "ping timeout":
13209
13348
  case "transport error":
13210
- this.LogDebugMessage(`Server unexpectedly disconnected. Reason: [${reason}]`);
13211
- this.LogDebugMessage("The connection will be re-established when the server becomes available.");
13212
- if (this.#socket) this.#socket.disconnect();
13213
- this.#socket = void 0;
13214
- if (_nsshunt_stsutils.isNode) {
13215
- if (this.#agentManager) this.#agentManager?.ResetAgent();
13216
- setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout).unref();
13217
- } else setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout);
13349
+ this.LogDebugMessage(`SocketIoClient:on("disconnect"): Server unexpectedly disconnected. Reason: [${reason}]`);
13350
+ this.LogDebugMessage("SocketIoClient:on(\"disconnect\"): The connection will be re-established when the server becomes available.");
13351
+ this.ResetSocket();
13352
+ if (_nsshunt_stsutils.isNode) this.#reconnectTimeoutVal = setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout).unref();
13353
+ else this.#reconnectTimeoutVal = setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout);
13218
13354
  break;
13219
13355
  }
13220
13356
  });
13221
13357
  }
13358
+ ResetSocket = () => {
13359
+ try {
13360
+ if (this.#reconnectTimeoutVal !== void 0) {
13361
+ clearTimeout(this.#reconnectTimeoutVal);
13362
+ this.#reconnectTimeoutVal = void 0;
13363
+ }
13364
+ if (this.#socket) {
13365
+ this.#socket.removeAllListeners();
13366
+ this.#socket.io.removeAllListeners();
13367
+ if (this.#socket.connected === true) this.#socket.disconnect();
13368
+ if (_nsshunt_stsutils.isNode) {
13369
+ if (this.#agentManager) this.#agentManager.ResetAgent();
13370
+ }
13371
+ this.#socket = void 0;
13372
+ }
13373
+ } catch (error) {
13374
+ const errorMessage = `SocketIoClient:ResetSocket(): Error: [${error}]`;
13375
+ this.LogErrorMessage(errorMessage);
13376
+ this.SocketConnectError(new Error(errorMessage));
13377
+ }
13378
+ };
13222
13379
  };
13223
13380
  //#endregion
13224
13381
  //#region src/cv2/fhirSocketClient.ts
@@ -13236,23 +13393,45 @@ var FhirSocketClient = class extends SocketIoClient {
13236
13393
  if (this.options.joinRooms.length > 0 && socket) socket.emit("__STSjoinRoom", this.options.joinRooms);
13237
13394
  }
13238
13395
  SocketError(error) {
13239
- this.LogErrorMessage(`FhirSocketClient:SocketError(): Error clientName: [${this.name}]: SetupClientSideSocket call back: Error: [${error}]`);
13396
+ this.LogErrorMessage(`FhirSocketClient:SocketError(): Error clientName: [${this.name}]: Error: [${error}]`);
13397
+ }
13398
+ SocketConnectError(error) {
13399
+ this.LogErrorMessage(`FhirSocketClient:SocketConnectError(): Error clientName: [${this.name}]: Error: [${error}]`);
13400
+ }
13401
+ SocketDisconnect(reason) {
13402
+ this.LogDebugMessage(`FhirSocketClient:SocketDisconnect(): Error clientName: [${this.name}]: Reason: [${reason}]`);
13403
+ }
13404
+ SetupSocketEvents(socket) {
13405
+ this.LogDebugMessage(`FhirSocketClient:SetupSocketEvents(): Error clientName: [${this.name}]`);
13240
13406
  }
13241
- SocketConnectError(error) {}
13242
- SocketDisconnect(reason) {}
13243
- SetupSocketEvents(socket) {}
13244
13407
  SetupWSSClient = async () => {
13245
- this.LogDebugMessage(chalk.yellow(`FhirSocketClient:SetupWSSClient(): ID: [${this.id}] clientName: [${this.name}] Starting ...`));
13246
- const cstr = `${this.options.fhirServerEndpoint}:${this.options.fhirServerPort}/nsstsfhir/`;
13247
- this.LogDebugMessage(chalk.yellow(`FhirSocketClient:SetupWSSClient(): Socket connection string: [${cstr}]`));
13248
- this.WithAddress(cstr).WithSocketIoCustomPath(this.options.socketIoCustomPath).WithAuthToken(this.options.authToken);
13249
- if (this.options.agentManager) this.WithAgentManager(this.options.agentManager);
13250
- if (this.options.logger) this.WithLogger(this.options.logger);
13251
- this.SetupSocket();
13252
- this.LogDebugMessage(chalk.yellow(`FhirSocketClient:SetupWSSClient(): ID: [${this.id}] clientName: [${this.name}] Started`));
13408
+ try {
13409
+ this.LogDebugMessage(chalk.yellow(`FhirSocketClient:SetupWSSClient(): ID: [${this.id}] clientName: [${this.name}] Starting ...`));
13410
+ const cstr = `${this.options.fhirServerEndpoint}:${this.options.fhirServerPort}/nsstsfhir/`;
13411
+ this.LogDebugMessage(chalk.yellow(`FhirSocketClient:SetupWSSClient(): Socket connection string: [${cstr}]`));
13412
+ let connectionAccessToken;
13413
+ try {
13414
+ connectionAccessToken = await this.options.GetConnectionAccessToken();
13415
+ } catch (error) {
13416
+ const message = `FhirSocketClient:SetupWSSClient():GetConnectionAccessToken(): Error clientName: [${this.name}]: Error: [${error}]`;
13417
+ this.LogErrorMessage(message);
13418
+ throw new Error(message);
13419
+ }
13420
+ this.WithAddress(cstr).WithSocketIoCustomPath(this.options.socketIoCustomPath).WithAuthToken(connectionAccessToken);
13421
+ if (this.options.agentManager) this.WithAgentManager(this.options.agentManager);
13422
+ if (this.options.logger) this.WithLogger(this.options.logger);
13423
+ this.SetupSocket();
13424
+ this.LogDebugMessage(chalk.yellow(`FhirSocketClient:SetupWSSClient(): ID: [${this.id}] clientName: [${this.name}] Started`));
13425
+ } catch (error) {
13426
+ const message = `FhirSocketClient:SetupWSSClient(): Error clientName: [${this.name}]: Error: [${error}]`;
13427
+ this.LogErrorMessage(message);
13428
+ throw new Error(message);
13429
+ }
13253
13430
  };
13254
13431
  WaitForSocketConnected = async () => {
13255
- const maxAttempts = 50;
13432
+ const maxAttempts = 20;
13433
+ const resetAfterAttempts = 10;
13434
+ const retryDelay = 250;
13256
13435
  if (this.socket && this.socket.connected === true) return true;
13257
13436
  else {
13258
13437
  this.LogDebugMessage(chalk.yellow(`FhirSocketClient:WaitForSocketConnected(): ID: [${this.id}] clientName: [${this.name}] Waiting for connection ...`));
@@ -13264,9 +13443,20 @@ var FhirSocketClient = class extends SocketIoClient {
13264
13443
  this.LogDebugMessage(chalk.yellow(`FhirSocketClient:WaitForSocketConnected(): ID: [${this.id}] clientName: [${this.name}] Connection completed after: [${attempts}] attempts.`));
13265
13444
  return true;
13266
13445
  }
13267
- await (0, _nsshunt_stsutils.Sleep)(100);
13446
+ if (attempts === resetAfterAttempts) {
13447
+ this.LogDebugMessage(chalk.rgb(255, 165, 0)(`FhirSocketClient:WaitForSocketConnected(): ID: [${this.id}] clientName: [${this.name}] Resetting Socket. Attempt Number: [${attempts}]`));
13448
+ this.ResetSocket();
13449
+ this.LogDebugMessage(chalk.rgb(255, 165, 0)(`FhirSocketClient:WaitForSocketConnected(): ID: [${this.id}] clientName: [${this.name}] Socket Reset. Attempt Number: [${attempts}]`));
13450
+ await (0, _nsshunt_stsutils.Sleep)(retryDelay);
13451
+ this.LogDebugMessage(chalk.rgb(255, 165, 0)(`FhirSocketClient:WaitForSocketConnected(): ID: [${this.id}] clientName: [${this.name}] SetupSocket. Attempt Number: [${attempts}]`));
13452
+ this.SetupSocket();
13453
+ await (0, _nsshunt_stsutils.Sleep)(retryDelay);
13454
+ }
13455
+ await (0, _nsshunt_stsutils.Sleep)(retryDelay);
13268
13456
  }
13269
- throw new Error(`FhirSocketClient:WaitForSocketConnected(): Error: [Could not connect after ${maxAttempts} connection attempts]`);
13457
+ const message = `FhirSocketClient:WaitForSocketConnected(): Error: [Could not connect after ${maxAttempts} connection attempts]`;
13458
+ this.LogErrorMessage(message);
13459
+ throw new Error(message);
13270
13460
  }
13271
13461
  };
13272
13462
  WithAccessToken = (accessToken) => {