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