@nsshunt/stsfhirclient 2.0.36 → 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.
package/dist/stsfhirclient.cjs
CHANGED
|
@@ -10253,7 +10253,6 @@ var globalThisShim = (() => {
|
|
|
10253
10253
|
else return Function("return this")();
|
|
10254
10254
|
})();
|
|
10255
10255
|
var defaultBinaryType = "arraybuffer";
|
|
10256
|
-
function createCookieJar() {}
|
|
10257
10256
|
//#endregion
|
|
10258
10257
|
//#region node_modules/engine.io-client/build/esm/util.js
|
|
10259
10258
|
function pick(obj, ...attr) {
|
|
@@ -11120,7 +11119,7 @@ var SocketWithoutUpgrade = class SocketWithoutUpgrade extends _socket_io_compone
|
|
|
11120
11119
|
OFFLINE_EVENT_LISTENERS.push(this._offlineEventListener);
|
|
11121
11120
|
}
|
|
11122
11121
|
}
|
|
11123
|
-
if (this.opts.withCredentials) this._cookieJar =
|
|
11122
|
+
if (this.opts.withCredentials) this._cookieJar = void 0;
|
|
11124
11123
|
this._open();
|
|
11125
11124
|
}
|
|
11126
11125
|
/**
|
|
@@ -13193,6 +13192,7 @@ var SocketIoClient = class extends import_tiny_emitter.TinyEmitter {
|
|
|
13193
13192
|
#socket;
|
|
13194
13193
|
#reconnectTimeout = 2e3;
|
|
13195
13194
|
#ackTimeout = 5e3;
|
|
13195
|
+
#reconnectTimeoutVal = void 0;
|
|
13196
13196
|
constructor(name) {
|
|
13197
13197
|
super();
|
|
13198
13198
|
this.#name = name;
|
|
@@ -13265,7 +13265,7 @@ var SocketIoClient = class extends import_tiny_emitter.TinyEmitter {
|
|
|
13265
13265
|
return this;
|
|
13266
13266
|
}
|
|
13267
13267
|
SetupSocket() {
|
|
13268
|
-
if (!this.#address) throw new Error(`
|
|
13268
|
+
if (!this.#address) throw new Error(`SocketIoClient:SetupSocket(): Error: [address not provided]`);
|
|
13269
13269
|
this.#EstablishSocketConnect();
|
|
13270
13270
|
return this;
|
|
13271
13271
|
}
|
|
@@ -13275,17 +13275,20 @@ var SocketIoClient = class extends import_tiny_emitter.TinyEmitter {
|
|
|
13275
13275
|
EngineReconnect(attempt) {}
|
|
13276
13276
|
#EstablishSocketConnect() {
|
|
13277
13277
|
if (this.#socket !== void 0) {
|
|
13278
|
-
|
|
13279
|
-
this.#
|
|
13280
|
-
|
|
13281
|
-
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);
|
|
13282
13281
|
return;
|
|
13283
13282
|
}
|
|
13284
13283
|
let socketOptions;
|
|
13285
13284
|
if (_nsshunt_stsutils.isNode) {
|
|
13286
13285
|
socketOptions = { transports: ["websocket"] };
|
|
13287
13286
|
if (this.#agentManager) {
|
|
13288
|
-
if (!this.#address)
|
|
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
|
+
}
|
|
13289
13292
|
socketOptions.agent = this.#agentManager.GetAgent(this.#address);
|
|
13290
13293
|
}
|
|
13291
13294
|
} else socketOptions = { transports: ["websocket"] };
|
|
@@ -13296,30 +13299,30 @@ var SocketIoClient = class extends import_tiny_emitter.TinyEmitter {
|
|
|
13296
13299
|
if (this.#socketIoCustomPath && this.#socketIoCustomPath.localeCompare("") !== 0) socketOptions.path = this.#socketIoCustomPath;
|
|
13297
13300
|
this.#socket = lookup(this.#address, socketOptions);
|
|
13298
13301
|
this.#socket.io.on("error", (err) => {
|
|
13299
|
-
this.LogErrorMessage(`
|
|
13302
|
+
this.LogErrorMessage(`SocketIoClient.socket.io.on('error'): [${err}] Address: [${this.#address}]`);
|
|
13300
13303
|
this.EngineError(err);
|
|
13301
13304
|
});
|
|
13302
13305
|
this.#socket.io.on("reconnect_error", (err) => {
|
|
13303
|
-
this.LogErrorMessage(`
|
|
13306
|
+
this.LogErrorMessage(`SocketIoClient.socket.io.on('reconnect_error'): [${err}] Address: [${this.#address}]`);
|
|
13304
13307
|
this.EngineReconnectError(err);
|
|
13305
13308
|
});
|
|
13306
13309
|
this.#socket.on("connect_error", (err) => {
|
|
13307
|
-
this.LogErrorMessage(`
|
|
13310
|
+
this.LogErrorMessage(`SocketIoClient.socket.on('connect_error'): [${err}] Address: [${this.#address}]`);
|
|
13308
13311
|
this.EngineConnectError(err);
|
|
13309
13312
|
});
|
|
13310
13313
|
this.#socket.io.on("reconnect", (attempt) => {
|
|
13311
|
-
this.LogErrorMessage(`
|
|
13314
|
+
this.LogErrorMessage(`SocketIoClient:socket.io.on('reconnect'): Number: [${attempt}] Address: [${this.#address}]`);
|
|
13312
13315
|
this.EngineReconnect(attempt);
|
|
13313
13316
|
});
|
|
13314
13317
|
this.#socket.on("connect", () => {
|
|
13315
13318
|
if (this.#socket) {
|
|
13316
|
-
this.LogDebugMessage(`Socket: [${this.#socket.id}]: connected, Address: [${this.#address}]`);
|
|
13319
|
+
this.LogDebugMessage(`SocketIoClient:on("connect"): Socket: [${this.#socket.id}]: connected, Address: [${this.#address}]`);
|
|
13317
13320
|
setTimeout(() => {
|
|
13318
13321
|
this.SocketConnect(this.#socket);
|
|
13319
13322
|
}, 0);
|
|
13320
13323
|
this.SetupSocketEvents(this.#socket);
|
|
13321
13324
|
} else {
|
|
13322
|
-
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}]";
|
|
13323
13326
|
this.LogErrorMessage(errorMessage);
|
|
13324
13327
|
this.SocketConnectError(new Error(errorMessage));
|
|
13325
13328
|
}
|
|
@@ -13329,33 +13332,50 @@ var SocketIoClient = class extends import_tiny_emitter.TinyEmitter {
|
|
|
13329
13332
|
this.SocketDisconnect(reason);
|
|
13330
13333
|
switch (reason) {
|
|
13331
13334
|
case "io server disconnect":
|
|
13332
|
-
this.LogDebugMessage("The server disconnected using disconnectSockets, i.e. normal safe shutdown from explicit disconnection by the server.");
|
|
13333
|
-
this.LogDebugMessage("The connection will be re-established when the server becomes available.");
|
|
13334
|
-
this
|
|
13335
|
-
if (_nsshunt_stsutils.isNode)
|
|
13336
|
-
|
|
13337
|
-
setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout).unref();
|
|
13338
|
-
} 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);
|
|
13339
13340
|
break;
|
|
13340
13341
|
case "io client disconnect":
|
|
13341
|
-
this.LogDebugMessage("The client disconnected using disconnectSockets, i.e. normal safe disconnection from explicit disconnection by the client.");
|
|
13342
|
-
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();
|
|
13343
13345
|
break;
|
|
13344
13346
|
case "transport close":
|
|
13345
13347
|
case "ping timeout":
|
|
13346
13348
|
case "transport error":
|
|
13347
|
-
this.LogDebugMessage(`Server unexpectedly disconnected. Reason: [${reason}]`);
|
|
13348
|
-
this.LogDebugMessage("The connection will be re-established when the server becomes available.");
|
|
13349
|
-
|
|
13350
|
-
this.#
|
|
13351
|
-
|
|
13352
|
-
if (this.#agentManager) this.#agentManager?.ResetAgent();
|
|
13353
|
-
setTimeout(() => this.#EstablishSocketConnect(), this.#reconnectTimeout).unref();
|
|
13354
|
-
} 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);
|
|
13355
13354
|
break;
|
|
13356
13355
|
}
|
|
13357
13356
|
});
|
|
13358
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
|
+
};
|
|
13359
13379
|
};
|
|
13360
13380
|
//#endregion
|
|
13361
13381
|
//#region src/cv2/fhirSocketClient.ts
|
|
@@ -13373,23 +13393,45 @@ var FhirSocketClient = class extends SocketIoClient {
|
|
|
13373
13393
|
if (this.options.joinRooms.length > 0 && socket) socket.emit("__STSjoinRoom", this.options.joinRooms);
|
|
13374
13394
|
}
|
|
13375
13395
|
SocketError(error) {
|
|
13376
|
-
this.LogErrorMessage(`FhirSocketClient:SocketError(): Error clientName: [${this.name}]:
|
|
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}]`);
|
|
13377
13406
|
}
|
|
13378
|
-
SocketConnectError(error) {}
|
|
13379
|
-
SocketDisconnect(reason) {}
|
|
13380
|
-
SetupSocketEvents(socket) {}
|
|
13381
13407
|
SetupWSSClient = async () => {
|
|
13382
|
-
|
|
13383
|
-
|
|
13384
|
-
|
|
13385
|
-
|
|
13386
|
-
|
|
13387
|
-
|
|
13388
|
-
|
|
13389
|
-
|
|
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
|
+
}
|
|
13390
13430
|
};
|
|
13391
13431
|
WaitForSocketConnected = async () => {
|
|
13392
|
-
const maxAttempts =
|
|
13432
|
+
const maxAttempts = 20;
|
|
13433
|
+
const resetAfterAttempts = 10;
|
|
13434
|
+
const retryDelay = 250;
|
|
13393
13435
|
if (this.socket && this.socket.connected === true) return true;
|
|
13394
13436
|
else {
|
|
13395
13437
|
this.LogDebugMessage(chalk.yellow(`FhirSocketClient:WaitForSocketConnected(): ID: [${this.id}] clientName: [${this.name}] Waiting for connection ...`));
|
|
@@ -13401,9 +13443,20 @@ var FhirSocketClient = class extends SocketIoClient {
|
|
|
13401
13443
|
this.LogDebugMessage(chalk.yellow(`FhirSocketClient:WaitForSocketConnected(): ID: [${this.id}] clientName: [${this.name}] Connection completed after: [${attempts}] attempts.`));
|
|
13402
13444
|
return true;
|
|
13403
13445
|
}
|
|
13404
|
-
|
|
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);
|
|
13405
13456
|
}
|
|
13406
|
-
|
|
13457
|
+
const message = `FhirSocketClient:WaitForSocketConnected(): Error: [Could not connect after ${maxAttempts} connection attempts]`;
|
|
13458
|
+
this.LogErrorMessage(message);
|
|
13459
|
+
throw new Error(message);
|
|
13407
13460
|
}
|
|
13408
13461
|
};
|
|
13409
13462
|
WithAccessToken = (accessToken) => {
|