@nsshunt/stsfhirclient 1.0.67 → 1.0.69
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.mjs +255 -170
- package/dist/stsfhirclient.mjs.map +1 -1
- package/dist/stsfhirclient.umd.js +255 -170
- package/dist/stsfhirclient.umd.js.map +1 -1
- package/package.json +1 -1
- package/types/FhirClient.d.ts +9 -9
- package/types/FhirClient.d.ts.map +1 -1
- package/types/retryAxiosClient.d.ts +15 -0
- package/types/retryAxiosClient.d.ts.map +1 -0
- package/types/srv_dev/stsfhircontrollertestcasesclient.d.ts +1 -0
- package/types/srv_dev/stsfhircontrollertestcasesclient.d.ts.map +1 -1
package/dist/stsfhirclient.mjs
CHANGED
|
@@ -8,43 +8,9 @@ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot
|
|
|
8
8
|
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
9
9
|
var __privateAdd = (obj, member, value2) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value2);
|
|
10
10
|
var __privateSet = (obj, member, value2, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value2) : member.set(obj, value2), value2);
|
|
11
|
-
var _socketUtils, _id, _options2, _clientName, _debug, _error, _info, _SetupWSSClient, _OnSocketConnected, _options3, _DUMMY_USER, _invokeMethods, _maxRetries, _sleepDuration, _NoRetryStatusCodes, _stsfhirapiroot, _fhirSocketClient, _LogDebugMessage, _LogErrorMessage, _HandleError,
|
|
11
|
+
var _socketUtils, _id, _options2, _clientName, _debug, _error, _info, _SetupWSSClient, _OnSocketConnected, _options3, _DUMMY_USER, _invokeMethods, _maxRetries, _sleepDuration, _NoRetryStatusCodes, _stsfhirapiroot, _fhirSocketClient, _LogDebugMessage, _LogErrorMessage, _HandleError, _TestMode, _BuildQueryString, _InvokeResourceAPI;
|
|
12
12
|
import axios from "axios";
|
|
13
13
|
import { defaultLogger, Sleep, STSAxiosConfig } from "@nsshunt/stsutils";
|
|
14
|
-
const byteToHex = [];
|
|
15
|
-
for (let i = 0; i < 256; ++i) {
|
|
16
|
-
byteToHex.push((i + 256).toString(16).slice(1));
|
|
17
|
-
}
|
|
18
|
-
function unsafeStringify(arr, offset = 0) {
|
|
19
|
-
return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
|
|
20
|
-
}
|
|
21
|
-
let getRandomValues;
|
|
22
|
-
const rnds8 = new Uint8Array(16);
|
|
23
|
-
function rng() {
|
|
24
|
-
if (!getRandomValues) {
|
|
25
|
-
if (typeof crypto === "undefined" || !crypto.getRandomValues) {
|
|
26
|
-
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
27
|
-
}
|
|
28
|
-
getRandomValues = crypto.getRandomValues.bind(crypto);
|
|
29
|
-
}
|
|
30
|
-
return getRandomValues(rnds8);
|
|
31
|
-
}
|
|
32
|
-
const randomUUID = typeof crypto !== "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
33
|
-
const native = { randomUUID };
|
|
34
|
-
function v4(options, buf, offset) {
|
|
35
|
-
var _a;
|
|
36
|
-
if (native.randomUUID && true && !options) {
|
|
37
|
-
return native.randomUUID();
|
|
38
|
-
}
|
|
39
|
-
options = options || {};
|
|
40
|
-
const rnds = options.random ?? ((_a = options.rng) == null ? void 0 : _a.call(options)) ?? rng();
|
|
41
|
-
if (rnds.length < 16) {
|
|
42
|
-
throw new Error("Random bytes length must be >= 16");
|
|
43
|
-
}
|
|
44
|
-
rnds[6] = rnds[6] & 15 | 64;
|
|
45
|
-
rnds[8] = rnds[8] & 63 | 128;
|
|
46
|
-
return unsafeStringify(rnds);
|
|
47
|
-
}
|
|
48
14
|
const isNode$1 = Object.prototype.toString.call(typeof process !== "undefined" ? process : 0) === "[object process]";
|
|
49
15
|
function getDefaultExportFromCjs(x) {
|
|
50
16
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
@@ -5019,6 +4985,40 @@ EstablishSocketConnect_fn = function(name, socketIoCustomPath, onConnectCallBack
|
|
|
5019
4985
|
}
|
|
5020
4986
|
});
|
|
5021
4987
|
};
|
|
4988
|
+
const byteToHex = [];
|
|
4989
|
+
for (let i = 0; i < 256; ++i) {
|
|
4990
|
+
byteToHex.push((i + 256).toString(16).slice(1));
|
|
4991
|
+
}
|
|
4992
|
+
function unsafeStringify(arr, offset = 0) {
|
|
4993
|
+
return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
|
|
4994
|
+
}
|
|
4995
|
+
let getRandomValues;
|
|
4996
|
+
const rnds8 = new Uint8Array(16);
|
|
4997
|
+
function rng() {
|
|
4998
|
+
if (!getRandomValues) {
|
|
4999
|
+
if (typeof crypto === "undefined" || !crypto.getRandomValues) {
|
|
5000
|
+
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
5001
|
+
}
|
|
5002
|
+
getRandomValues = crypto.getRandomValues.bind(crypto);
|
|
5003
|
+
}
|
|
5004
|
+
return getRandomValues(rnds8);
|
|
5005
|
+
}
|
|
5006
|
+
const randomUUID = typeof crypto !== "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
|
|
5007
|
+
const native = { randomUUID };
|
|
5008
|
+
function v4(options, buf, offset) {
|
|
5009
|
+
var _a;
|
|
5010
|
+
if (native.randomUUID && true && !options) {
|
|
5011
|
+
return native.randomUUID();
|
|
5012
|
+
}
|
|
5013
|
+
options = options || {};
|
|
5014
|
+
const rnds = options.random ?? ((_a = options.rng) == null ? void 0 : _a.call(options)) ?? rng();
|
|
5015
|
+
if (rnds.length < 16) {
|
|
5016
|
+
throw new Error("Random bytes length must be >= 16");
|
|
5017
|
+
}
|
|
5018
|
+
rnds[6] = rnds[6] & 15 | 64;
|
|
5019
|
+
rnds[8] = rnds[8] & 63 | 128;
|
|
5020
|
+
return unsafeStringify(rnds);
|
|
5021
|
+
}
|
|
5022
5022
|
class FhirSocketClient {
|
|
5023
5023
|
constructor(options) {
|
|
5024
5024
|
__privateAdd(this, _socketUtils);
|
|
@@ -5345,6 +5345,75 @@ _error = new WeakMap();
|
|
|
5345
5345
|
_info = new WeakMap();
|
|
5346
5346
|
_SetupWSSClient = new WeakMap();
|
|
5347
5347
|
_OnSocketConnected = new WeakMap();
|
|
5348
|
+
function sleep(ms) {
|
|
5349
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
5350
|
+
}
|
|
5351
|
+
function getJitteredDelay(base, jitter) {
|
|
5352
|
+
const random = Math.floor(Math.random() * jitter);
|
|
5353
|
+
return base + random;
|
|
5354
|
+
}
|
|
5355
|
+
function createRetryAxiosClient(retryConfig) {
|
|
5356
|
+
const {
|
|
5357
|
+
maxRetries = 3,
|
|
5358
|
+
retryDelayMs = 300,
|
|
5359
|
+
retryJitterMs = 100,
|
|
5360
|
+
retryMethods = ["get", "head", "put", "delete", "options"],
|
|
5361
|
+
// post, patch
|
|
5362
|
+
retryStatusCodes = [408, 429, 500, 502, 503, 504],
|
|
5363
|
+
retryErrorCodes = [
|
|
5364
|
+
"ECONNRESET",
|
|
5365
|
+
"ETIMEDOUT",
|
|
5366
|
+
"EAI_AGAIN",
|
|
5367
|
+
"ECONNREFUSED",
|
|
5368
|
+
"ENOTFOUND",
|
|
5369
|
+
"EHOSTUNREACH",
|
|
5370
|
+
"EPIPE"
|
|
5371
|
+
],
|
|
5372
|
+
maxRetryDurationMs = 1e4,
|
|
5373
|
+
onRetryAttempt,
|
|
5374
|
+
stsAxiosConfig
|
|
5375
|
+
} = retryConfig || {};
|
|
5376
|
+
const instance = axios.create();
|
|
5377
|
+
instance.interceptors.request.use((config) => {
|
|
5378
|
+
const now = Date.now();
|
|
5379
|
+
config.metadata = {
|
|
5380
|
+
startTime: now,
|
|
5381
|
+
__retryCount: 0
|
|
5382
|
+
};
|
|
5383
|
+
if (stsAxiosConfig) {
|
|
5384
|
+
Object.assign(config, stsAxiosConfig.config);
|
|
5385
|
+
}
|
|
5386
|
+
return config;
|
|
5387
|
+
});
|
|
5388
|
+
instance.interceptors.response.use(
|
|
5389
|
+
(response) => response,
|
|
5390
|
+
async (error) => {
|
|
5391
|
+
var _a;
|
|
5392
|
+
const config = error.config;
|
|
5393
|
+
if (!config || !config.method || !config.metadata) {
|
|
5394
|
+
return Promise.reject(error);
|
|
5395
|
+
}
|
|
5396
|
+
const now = Date.now();
|
|
5397
|
+
const elapsed = now - config.metadata.startTime;
|
|
5398
|
+
const method = config.method.toLowerCase();
|
|
5399
|
+
const status = (_a = error.response) == null ? void 0 : _a.status;
|
|
5400
|
+
const code = error.code;
|
|
5401
|
+
const isRetryable = retryMethods.includes(method) && (retryErrorCodes.includes(code || "") || retryStatusCodes.includes(status || 0));
|
|
5402
|
+
if (config.metadata.__retryCount < maxRetries && isRetryable && elapsed < maxRetryDurationMs) {
|
|
5403
|
+
config.metadata.__retryCount += 1;
|
|
5404
|
+
const delayBase = retryDelayMs * Math.pow(2, config.metadata.__retryCount - 1);
|
|
5405
|
+
const jitteredDelay = getJitteredDelay(delayBase, retryJitterMs);
|
|
5406
|
+
if (onRetryAttempt) {
|
|
5407
|
+
onRetryAttempt(config.metadata.__retryCount, error, jitteredDelay);
|
|
5408
|
+
}
|
|
5409
|
+
await sleep(jitteredDelay);
|
|
5410
|
+
return instance(config);
|
|
5411
|
+
}
|
|
5412
|
+
return Promise.reject(error);
|
|
5413
|
+
}
|
|
5414
|
+
);
|
|
5415
|
+
return instance;
|
|
5416
|
+
}
|
|
5348
5417
|
class FhirClient {
|
|
5349
5418
|
constructor(options) {
|
|
5350
5419
|
__privateAdd(this, _options3);
|
|
@@ -5360,15 +5429,12 @@ class FhirClient {
|
|
|
5360
5429
|
__privateAdd(this, _stsfhirapiroot, "/stsfhir/r5");
|
|
5361
5430
|
// Default value
|
|
5362
5431
|
__privateAdd(this, _fhirSocketClient);
|
|
5363
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5364
5432
|
__privateAdd(this, _LogDebugMessage, (message) => {
|
|
5365
5433
|
__privateGet(this, _options3).logger.debug(message);
|
|
5366
5434
|
});
|
|
5367
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5368
5435
|
__privateAdd(this, _LogErrorMessage, (message) => {
|
|
5369
5436
|
__privateGet(this, _options3).logger.error(message);
|
|
5370
5437
|
});
|
|
5371
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5372
5438
|
__privateAdd(this, _HandleError, (error) => {
|
|
5373
5439
|
__privateGet(this, _LogDebugMessage).call(this, chalk.red(`HandleError(): Error: [${error}]`));
|
|
5374
5440
|
let responseCode = 500;
|
|
@@ -5383,73 +5449,6 @@ class FhirClient {
|
|
|
5383
5449
|
}
|
|
5384
5450
|
return responseCode;
|
|
5385
5451
|
});
|
|
5386
|
-
__privateAdd(this, _InvokeResourceAPI, async (url2, httpVerb, domainResource, filters, searchParams, errorCb) => {
|
|
5387
|
-
const id = v4();
|
|
5388
|
-
__privateGet(this, _invokeMethods)[id] = {
|
|
5389
|
-
id,
|
|
5390
|
-
retries: 0,
|
|
5391
|
-
testFailIndexBefore: 1,
|
|
5392
|
-
url: url2,
|
|
5393
|
-
httpVerb,
|
|
5394
|
-
domainResource,
|
|
5395
|
-
filters,
|
|
5396
|
-
searchParams,
|
|
5397
|
-
errorCb
|
|
5398
|
-
};
|
|
5399
|
-
const InvokeAPI = async (id2) => {
|
|
5400
|
-
const metadataRecord = __privateGet(this, _invokeMethods)[id2];
|
|
5401
|
-
let performRetry = false;
|
|
5402
|
-
const returnData = await __privateGet(this, ___InvokeResourceAPI).call(this, metadataRecord, (statusCode, error) => {
|
|
5403
|
-
console.error(chalk.red(`#InvokeResourceAPI(): Error: [${error}], Attempt: [${metadataRecord.retries + 1}]`));
|
|
5404
|
-
const noRetryIndex = __privateGet(this, _NoRetryStatusCodes).indexOf(statusCode);
|
|
5405
|
-
if (noRetryIndex === -1) {
|
|
5406
|
-
if (statusCode === StatusCodes.UNAUTHORIZED) {
|
|
5407
|
-
console.error(chalk.red(`#InvokeResourceAPI(): Authentication error, resetting access_token (to null).`));
|
|
5408
|
-
__privateGet(this, _options3).ResetAccessToken();
|
|
5409
|
-
if (__privateGet(this, _options3).clientTelemetryEvents) {
|
|
5410
|
-
__privateGet(this, _options3).clientTelemetryEvents.AuthenticationErrorInc();
|
|
5411
|
-
}
|
|
5412
|
-
}
|
|
5413
|
-
if (isNode$1 && __privateGet(this, _options3).agentManager) {
|
|
5414
|
-
console.error(chalk.red(`#InvokeResourceAPI(): Resetting https agent (to null).`));
|
|
5415
|
-
__privateGet(this, _options3).agentManager.ResetAgent();
|
|
5416
|
-
}
|
|
5417
|
-
performRetry = true;
|
|
5418
|
-
}
|
|
5419
|
-
});
|
|
5420
|
-
return {
|
|
5421
|
-
response: returnData,
|
|
5422
|
-
retry: performRetry
|
|
5423
|
-
};
|
|
5424
|
-
};
|
|
5425
|
-
let retVal = null;
|
|
5426
|
-
while (__privateGet(this, _invokeMethods)[id].retries < __privateGet(this, _maxRetries)) {
|
|
5427
|
-
retVal = await InvokeAPI(id);
|
|
5428
|
-
if (retVal.retry === false) {
|
|
5429
|
-
delete __privateGet(this, _invokeMethods)[id];
|
|
5430
|
-
break;
|
|
5431
|
-
} else {
|
|
5432
|
-
console.log(`Going to retry. Current attempts: [${__privateGet(this, _invokeMethods)[id].retries + 1}]`);
|
|
5433
|
-
console.log(`Sleeping: [${__privateGet(this, _sleepDuration)[__privateGet(this, _invokeMethods)[id].retries]}]`);
|
|
5434
|
-
await Sleep(__privateGet(this, _sleepDuration)[__privateGet(this, _invokeMethods)[id].retries]);
|
|
5435
|
-
__privateGet(this, _invokeMethods)[id].retries++;
|
|
5436
|
-
if (__privateGet(this, _options3).clientTelemetryEvents) {
|
|
5437
|
-
__privateGet(this, _options3).clientTelemetryEvents.RetryInc();
|
|
5438
|
-
}
|
|
5439
|
-
}
|
|
5440
|
-
}
|
|
5441
|
-
if (retVal) {
|
|
5442
|
-
if (retVal.retry === true) {
|
|
5443
|
-
errorCb(new Error(`#InvokeResourceAPI(): Max retries exceeded. Max Retries: [${__privateGet(this, _invokeMethods)[id].retries}]`));
|
|
5444
|
-
delete __privateGet(this, _invokeMethods)[id];
|
|
5445
|
-
return null;
|
|
5446
|
-
} else {
|
|
5447
|
-
return retVal.response;
|
|
5448
|
-
}
|
|
5449
|
-
} else {
|
|
5450
|
-
return null;
|
|
5451
|
-
}
|
|
5452
|
-
});
|
|
5453
5452
|
__privateAdd(this, _TestMode, (metaData, errorCb) => {
|
|
5454
5453
|
const { id, url: url2, httpVerb, filters, retries } = metaData;
|
|
5455
5454
|
if (retries < 1) {
|
|
@@ -5462,37 +5461,54 @@ class FhirClient {
|
|
|
5462
5461
|
}
|
|
5463
5462
|
return false;
|
|
5464
5463
|
});
|
|
5465
|
-
__privateAdd(this,
|
|
5466
|
-
|
|
5467
|
-
|
|
5468
|
-
|
|
5469
|
-
|
|
5470
|
-
|
|
5471
|
-
|
|
5472
|
-
|
|
5473
|
-
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
requestConfig.withAgentManager(__privateGet(this, _options3).agentManager);
|
|
5477
|
-
}
|
|
5478
|
-
return await axios(requestConfig.config);
|
|
5479
|
-
} catch (error) {
|
|
5480
|
-
const responseCode = __privateGet(this, _HandleError).call(this, error);
|
|
5481
|
-
errorCb(responseCode, error);
|
|
5482
|
-
return null;
|
|
5464
|
+
__privateAdd(this, _BuildQueryString, (baseUrl, queryParams) => {
|
|
5465
|
+
const url2 = new URL(baseUrl);
|
|
5466
|
+
const searchParams = new URLSearchParams(queryParams);
|
|
5467
|
+
url2.search = searchParams.toString();
|
|
5468
|
+
return url2.toString();
|
|
5469
|
+
});
|
|
5470
|
+
__privateAdd(this, _InvokeResourceAPI, async (url2, httpVerb, domainResource, filters) => {
|
|
5471
|
+
const accessToken = await __privateGet(this, _options3).GetAccessToken();
|
|
5472
|
+
const requestConfig = new STSAxiosConfig(url2, httpVerb).withAuthHeaders(accessToken, __privateGet(this, _DUMMY_USER)).withData(filters ? filters : domainResource ? domainResource : void 0);
|
|
5473
|
+
if (isNode$1 && __privateGet(this, _options3).agentManager) {
|
|
5474
|
+
requestConfig.withAgentManager(__privateGet(this, _options3).agentManager);
|
|
5483
5475
|
}
|
|
5476
|
+
const api = createRetryAxiosClient({
|
|
5477
|
+
maxRetries: 4,
|
|
5478
|
+
retryDelayMs: 300,
|
|
5479
|
+
retryJitterMs: 150,
|
|
5480
|
+
maxRetryDurationMs: 5e3,
|
|
5481
|
+
onRetryAttempt: (attempt, error, delayMs) => {
|
|
5482
|
+
var _a;
|
|
5483
|
+
console.warn(`Retry #${attempt} after ${delayMs}ms due to ${error.code || ((_a = error.response) == null ? void 0 : _a.status)}`);
|
|
5484
|
+
}
|
|
5485
|
+
//stsAxiosConfig: requestConfig
|
|
5486
|
+
});
|
|
5487
|
+
return await api(url2, requestConfig.config);
|
|
5484
5488
|
});
|
|
5485
|
-
__publicField(this, "GetResource", async (resource, id, filters
|
|
5489
|
+
__publicField(this, "GetResource", async (resource, id, filters) => {
|
|
5486
5490
|
if (__privateGet(this, _options3).useSocketClient === true && __privateGet(this, _fhirSocketClient)) {
|
|
5487
|
-
|
|
5488
|
-
|
|
5489
|
-
|
|
5490
|
-
|
|
5491
|
-
|
|
5491
|
+
try {
|
|
5492
|
+
const retVal = await __privateGet(this, _fhirSocketClient).GetResource(resource, id);
|
|
5493
|
+
if (retVal.status === StatusCodes.OK) {
|
|
5494
|
+
return retVal.value;
|
|
5495
|
+
} else {
|
|
5496
|
+
const errorResponse = new Error(`GetResource(): Invalid response status code: [${retVal.status}] expected: [${StatusCodes.OK}]`);
|
|
5497
|
+
errorResponse.response = {
|
|
5498
|
+
status: retVal.status
|
|
5499
|
+
};
|
|
5500
|
+
throw errorResponse;
|
|
5501
|
+
}
|
|
5502
|
+
} catch (error) {
|
|
5503
|
+
const errorResponse = new Error(`GetResource(): Error: [${error}]`);
|
|
5504
|
+
errorResponse.response = {
|
|
5505
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR
|
|
5506
|
+
};
|
|
5507
|
+
throw errorResponse;
|
|
5492
5508
|
}
|
|
5493
5509
|
} else {
|
|
5494
5510
|
const url2 = `${__privateGet(this, _options3).fhirEndpoint}${__privateGet(this, _stsfhirapiroot)}/${resource}/${id}`;
|
|
5495
|
-
const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "get", null, filters
|
|
5511
|
+
const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "get", null, filters);
|
|
5496
5512
|
if (response) {
|
|
5497
5513
|
return response.data;
|
|
5498
5514
|
} else {
|
|
@@ -5500,21 +5516,23 @@ class FhirClient {
|
|
|
5500
5516
|
}
|
|
5501
5517
|
}
|
|
5502
5518
|
});
|
|
5503
|
-
|
|
5504
|
-
const url2 = new URL(baseUrl);
|
|
5505
|
-
const searchParams = new URLSearchParams(queryParams);
|
|
5506
|
-
url2.search = searchParams.toString();
|
|
5507
|
-
return url2.toString();
|
|
5508
|
-
});
|
|
5509
|
-
__publicField(this, "GetResources", async (resource, filters, searchParams, errorCb) => {
|
|
5519
|
+
__publicField(this, "GetResources", async (resource, filters, searchParams) => {
|
|
5510
5520
|
if (__privateGet(this, _options3).useSocketClient === true && __privateGet(this, _fhirSocketClient)) {
|
|
5511
|
-
|
|
5521
|
+
try {
|
|
5522
|
+
return __privateGet(this, _fhirSocketClient).GetResources(resource, searchParams);
|
|
5523
|
+
} catch (error) {
|
|
5524
|
+
const errorResponse = new Error(`GetResources(): Error: [${error}]`);
|
|
5525
|
+
errorResponse.response = {
|
|
5526
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR
|
|
5527
|
+
};
|
|
5528
|
+
throw errorResponse;
|
|
5529
|
+
}
|
|
5512
5530
|
} else {
|
|
5513
5531
|
let url2 = `${__privateGet(this, _options3).fhirEndpoint}${__privateGet(this, _stsfhirapiroot)}/${resource}`;
|
|
5514
5532
|
if (searchParams) {
|
|
5515
5533
|
url2 = __privateGet(this, _BuildQueryString).call(this, url2, searchParams);
|
|
5516
5534
|
}
|
|
5517
|
-
const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "get", null, filters
|
|
5535
|
+
const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "get", null, filters);
|
|
5518
5536
|
if (response) {
|
|
5519
5537
|
return response.data;
|
|
5520
5538
|
} else {
|
|
@@ -5522,36 +5540,54 @@ class FhirClient {
|
|
|
5522
5540
|
}
|
|
5523
5541
|
}
|
|
5524
5542
|
});
|
|
5525
|
-
__publicField(this, "CreateResource", async (resource, domainResource
|
|
5543
|
+
__publicField(this, "CreateResource", async (resource, domainResource) => {
|
|
5526
5544
|
if (__privateGet(this, _options3).useSocketClient === true && __privateGet(this, _fhirSocketClient)) {
|
|
5527
|
-
|
|
5528
|
-
|
|
5529
|
-
|
|
5530
|
-
|
|
5531
|
-
|
|
5532
|
-
|
|
5545
|
+
try {
|
|
5546
|
+
const retVal = await __privateGet(this, _fhirSocketClient).CreateResource(resource, domainResource);
|
|
5547
|
+
if (retVal.status === StatusCodes.CREATED) {
|
|
5548
|
+
return retVal.value;
|
|
5549
|
+
} else {
|
|
5550
|
+
const errorResponse = new Error(`CreateResource(): Invalid response status code: [${retVal.status}] expected: [${StatusCodes.CREATED}]`);
|
|
5551
|
+
errorResponse.response = {
|
|
5552
|
+
status: retVal.status
|
|
5553
|
+
};
|
|
5554
|
+
throw errorResponse;
|
|
5555
|
+
}
|
|
5556
|
+
} catch (error) {
|
|
5557
|
+
const errorResponse = new Error(`CreateResource(): Error: [${error}]`);
|
|
5558
|
+
errorResponse.response = {
|
|
5559
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR
|
|
5560
|
+
};
|
|
5561
|
+
throw errorResponse;
|
|
5533
5562
|
}
|
|
5534
5563
|
} else {
|
|
5535
5564
|
const url2 = `${__privateGet(this, _options3).fhirEndpoint}${__privateGet(this, _stsfhirapiroot)}/${resource}`;
|
|
5536
|
-
const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "post", domainResource, null
|
|
5565
|
+
const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "post", domainResource, null);
|
|
5537
5566
|
if (response) {
|
|
5538
5567
|
if (response.status === StatusCodes.CREATED) {
|
|
5539
5568
|
return response.data;
|
|
5540
5569
|
} else {
|
|
5541
|
-
|
|
5542
|
-
return null;
|
|
5570
|
+
throw new Error(`CreateResource(): Invalid response status code: [${response.status}] expected: [${StatusCodes.CREATED}]`);
|
|
5543
5571
|
}
|
|
5544
5572
|
} else {
|
|
5545
5573
|
return null;
|
|
5546
5574
|
}
|
|
5547
5575
|
}
|
|
5548
5576
|
});
|
|
5549
|
-
__publicField(this, "UpdateResource", async (resource, domainResource
|
|
5577
|
+
__publicField(this, "UpdateResource", async (resource, domainResource) => {
|
|
5550
5578
|
if (__privateGet(this, _options3).useSocketClient === true && __privateGet(this, _fhirSocketClient)) {
|
|
5551
|
-
|
|
5579
|
+
try {
|
|
5580
|
+
return __privateGet(this, _fhirSocketClient).UpdateResource(resource, domainResource);
|
|
5581
|
+
} catch (error) {
|
|
5582
|
+
const errorResponse = new Error(`UpdateResource(): Error: [${error}]`);
|
|
5583
|
+
errorResponse.response = {
|
|
5584
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR
|
|
5585
|
+
};
|
|
5586
|
+
throw errorResponse;
|
|
5587
|
+
}
|
|
5552
5588
|
} else {
|
|
5553
5589
|
const url2 = `${__privateGet(this, _options3).fhirEndpoint}${__privateGet(this, _stsfhirapiroot)}/${resource}/${domainResource.id}`;
|
|
5554
|
-
const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "put", domainResource, null
|
|
5590
|
+
const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "put", domainResource, null);
|
|
5555
5591
|
if (response) {
|
|
5556
5592
|
return response.data;
|
|
5557
5593
|
} else {
|
|
@@ -5559,12 +5595,20 @@ class FhirClient {
|
|
|
5559
5595
|
}
|
|
5560
5596
|
}
|
|
5561
5597
|
});
|
|
5562
|
-
__publicField(this, "UpdateResources", async (resource, domainResources
|
|
5598
|
+
__publicField(this, "UpdateResources", async (resource, domainResources) => {
|
|
5563
5599
|
if (__privateGet(this, _options3).useSocketClient === true && __privateGet(this, _fhirSocketClient)) {
|
|
5564
|
-
|
|
5600
|
+
try {
|
|
5601
|
+
return __privateGet(this, _fhirSocketClient).UpdateResources(resource, domainResources);
|
|
5602
|
+
} catch (error) {
|
|
5603
|
+
const errorResponse = new Error(`UpdateResources(): Error: [${error}]`);
|
|
5604
|
+
errorResponse.response = {
|
|
5605
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR
|
|
5606
|
+
};
|
|
5607
|
+
throw errorResponse;
|
|
5608
|
+
}
|
|
5565
5609
|
} else {
|
|
5566
5610
|
const url2 = `${__privateGet(this, _options3).fhirEndpoint}${__privateGet(this, _stsfhirapiroot)}/${resource}`;
|
|
5567
|
-
const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "put", domainResources, null
|
|
5611
|
+
const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "put", domainResources, null);
|
|
5568
5612
|
if (response) {
|
|
5569
5613
|
return response.data;
|
|
5570
5614
|
} else {
|
|
@@ -5572,12 +5616,20 @@ class FhirClient {
|
|
|
5572
5616
|
}
|
|
5573
5617
|
}
|
|
5574
5618
|
});
|
|
5575
|
-
__publicField(this, "PatchResource", async (resource, domainResource
|
|
5619
|
+
__publicField(this, "PatchResource", async (resource, domainResource) => {
|
|
5576
5620
|
if (__privateGet(this, _options3).useSocketClient === true && __privateGet(this, _fhirSocketClient)) {
|
|
5577
|
-
|
|
5621
|
+
try {
|
|
5622
|
+
return __privateGet(this, _fhirSocketClient).PatchResource(resource, domainResource);
|
|
5623
|
+
} catch (error) {
|
|
5624
|
+
const errorResponse = new Error(`PatchResource(): Error: [${error}]`);
|
|
5625
|
+
errorResponse.response = {
|
|
5626
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR
|
|
5627
|
+
};
|
|
5628
|
+
throw errorResponse;
|
|
5629
|
+
}
|
|
5578
5630
|
} else {
|
|
5579
5631
|
const url2 = `${__privateGet(this, _options3).fhirEndpoint}${__privateGet(this, _stsfhirapiroot)}/${resource}/${domainResource.id}`;
|
|
5580
|
-
const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "patch", domainResource, null
|
|
5632
|
+
const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "patch", domainResource, null);
|
|
5581
5633
|
if (response) {
|
|
5582
5634
|
return response.data;
|
|
5583
5635
|
} else {
|
|
@@ -5585,12 +5637,20 @@ class FhirClient {
|
|
|
5585
5637
|
}
|
|
5586
5638
|
}
|
|
5587
5639
|
});
|
|
5588
|
-
__publicField(this, "PatchResources", async (resource, domainResources
|
|
5640
|
+
__publicField(this, "PatchResources", async (resource, domainResources) => {
|
|
5589
5641
|
if (__privateGet(this, _options3).useSocketClient === true && __privateGet(this, _fhirSocketClient)) {
|
|
5590
|
-
|
|
5642
|
+
try {
|
|
5643
|
+
return __privateGet(this, _fhirSocketClient).PatchResources(resource, domainResources);
|
|
5644
|
+
} catch (error) {
|
|
5645
|
+
const errorResponse = new Error(`PatchResources(): Error: [${error}]`);
|
|
5646
|
+
errorResponse.response = {
|
|
5647
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR
|
|
5648
|
+
};
|
|
5649
|
+
throw errorResponse;
|
|
5650
|
+
}
|
|
5591
5651
|
} else {
|
|
5592
5652
|
const url2 = `${__privateGet(this, _options3).fhirEndpoint}${__privateGet(this, _stsfhirapiroot)}/${resource}`;
|
|
5593
|
-
const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "patch", domainResources, null
|
|
5653
|
+
const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "patch", domainResources, null);
|
|
5594
5654
|
if (response) {
|
|
5595
5655
|
return response.data;
|
|
5596
5656
|
} else {
|
|
@@ -5598,12 +5658,20 @@ class FhirClient {
|
|
|
5598
5658
|
}
|
|
5599
5659
|
}
|
|
5600
5660
|
});
|
|
5601
|
-
__publicField(this, "DeleteResource", async (resource, id
|
|
5661
|
+
__publicField(this, "DeleteResource", async (resource, id) => {
|
|
5602
5662
|
if (__privateGet(this, _options3).useSocketClient === true && __privateGet(this, _fhirSocketClient)) {
|
|
5603
|
-
|
|
5663
|
+
try {
|
|
5664
|
+
return __privateGet(this, _fhirSocketClient).DeleteResource(resource, id);
|
|
5665
|
+
} catch (error) {
|
|
5666
|
+
const errorResponse = new Error(`DeleteResource(): Error: [${error}]`);
|
|
5667
|
+
errorResponse.response = {
|
|
5668
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR
|
|
5669
|
+
};
|
|
5670
|
+
throw errorResponse;
|
|
5671
|
+
}
|
|
5604
5672
|
} else {
|
|
5605
5673
|
const url2 = `${__privateGet(this, _options3).fhirEndpoint}${__privateGet(this, _stsfhirapiroot)}/${resource}/${id}`;
|
|
5606
|
-
const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "delete", null, null
|
|
5674
|
+
const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "delete", null, null);
|
|
5607
5675
|
if (response) {
|
|
5608
5676
|
return response.data;
|
|
5609
5677
|
} else {
|
|
@@ -5611,12 +5679,20 @@ class FhirClient {
|
|
|
5611
5679
|
}
|
|
5612
5680
|
}
|
|
5613
5681
|
});
|
|
5614
|
-
__publicField(this, "DeleteResources", async (resource, domainResources
|
|
5682
|
+
__publicField(this, "DeleteResources", async (resource, domainResources) => {
|
|
5615
5683
|
if (__privateGet(this, _options3).useSocketClient === true && __privateGet(this, _fhirSocketClient)) {
|
|
5616
|
-
|
|
5684
|
+
try {
|
|
5685
|
+
return __privateGet(this, _fhirSocketClient).DeleteResources(resource, domainResources);
|
|
5686
|
+
} catch (error) {
|
|
5687
|
+
const errorResponse = new Error(`DeleteResources(): Error: [${error}]`);
|
|
5688
|
+
errorResponse.response = {
|
|
5689
|
+
status: StatusCodes.INTERNAL_SERVER_ERROR
|
|
5690
|
+
};
|
|
5691
|
+
throw errorResponse;
|
|
5692
|
+
}
|
|
5617
5693
|
} else {
|
|
5618
5694
|
const url2 = `${__privateGet(this, _options3).fhirEndpoint}${__privateGet(this, _stsfhirapiroot)}/${resource}`;
|
|
5619
|
-
const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "delete", domainResources, null
|
|
5695
|
+
const response = await __privateGet(this, _InvokeResourceAPI).call(this, url2, "delete", domainResources, null);
|
|
5620
5696
|
if (response) {
|
|
5621
5697
|
return response.data;
|
|
5622
5698
|
} else {
|
|
@@ -5631,7 +5707,17 @@ class FhirClient {
|
|
|
5631
5707
|
if (isNode$1 && __privateGet(this, _options3).agentManager) {
|
|
5632
5708
|
requestConfig.withAgentManager(__privateGet(this, _options3).agentManager);
|
|
5633
5709
|
}
|
|
5634
|
-
|
|
5710
|
+
const api = createRetryAxiosClient({
|
|
5711
|
+
maxRetries: 4,
|
|
5712
|
+
retryDelayMs: 300,
|
|
5713
|
+
retryJitterMs: 150,
|
|
5714
|
+
maxRetryDurationMs: 5e3,
|
|
5715
|
+
onRetryAttempt: (attempt, error, delayMs) => {
|
|
5716
|
+
var _a;
|
|
5717
|
+
console.warn(`Retry #${attempt} after ${delayMs}ms due to ${error.code || ((_a = error.response) == null ? void 0 : _a.status)}`);
|
|
5718
|
+
}
|
|
5719
|
+
});
|
|
5720
|
+
return await api(url2, requestConfig.config);
|
|
5635
5721
|
} catch (error) {
|
|
5636
5722
|
__privateGet(this, _HandleError).call(this, error);
|
|
5637
5723
|
}
|
|
@@ -5664,10 +5750,9 @@ _fhirSocketClient = new WeakMap();
|
|
|
5664
5750
|
_LogDebugMessage = new WeakMap();
|
|
5665
5751
|
_LogErrorMessage = new WeakMap();
|
|
5666
5752
|
_HandleError = new WeakMap();
|
|
5667
|
-
_InvokeResourceAPI = new WeakMap();
|
|
5668
5753
|
_TestMode = new WeakMap();
|
|
5669
|
-
___InvokeResourceAPI = new WeakMap();
|
|
5670
5754
|
_BuildQueryString = new WeakMap();
|
|
5755
|
+
_InvokeResourceAPI = new WeakMap();
|
|
5671
5756
|
export {
|
|
5672
5757
|
FhirClient
|
|
5673
5758
|
};
|