@nsshunt/stsfhirclient 1.0.19 → 1.0.21
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
CHANGED
|
@@ -8,7 +8,7 @@ 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, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
10
10
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
11
|
-
var _options2, _DUMMY_USER, _invokeMethods, _maxRetries, _sleepDuration, _NoRetryStatusCodes, _stsfhirapiroot,
|
|
11
|
+
var _options2, _DUMMY_USER, _invokeMethods, _maxRetries, _sleepDuration, _NoRetryStatusCodes, _stsfhirapiroot, _agentManager2, _LogDebugMessage, _LogErrorMessage, _HandleError, _InvokeResourceAPI, _TestMode, ___InvokeResourceAPI;
|
|
12
12
|
import axios from "axios";
|
|
13
13
|
import { Sleep } from "@nsshunt/stsutils";
|
|
14
14
|
import https from "node:https";
|
|
@@ -1920,7 +1920,7 @@ var __privateWrapper = (obj, member, setter, getter) => ({
|
|
|
1920
1920
|
return __privateGet2(obj, member, getter);
|
|
1921
1921
|
}
|
|
1922
1922
|
});
|
|
1923
|
-
var _options, _httpAgent, _httpsAgent, _agentResetInterval, _requestCount, _SetupResetInterval, _GetAgentOptions;
|
|
1923
|
+
var _options, _httpAgent, _httpsAgent, _agentResetInterval, _requestCount, _SetupResetInterval, _GetAgentOptions, _url, _method, _headers, _data, _agentManager, _timeout, _withCredentials;
|
|
1924
1924
|
var ansiStyles$1 = { exports: {} };
|
|
1925
1925
|
var colorName;
|
|
1926
1926
|
var hasRequiredColorName;
|
|
@@ -3561,10 +3561,12 @@ class AgentManager {
|
|
|
3561
3561
|
__privateAdd2(this, _agentResetInterval, null);
|
|
3562
3562
|
__privateAdd2(this, _requestCount, 0);
|
|
3563
3563
|
__privateAdd2(this, _SetupResetInterval, () => {
|
|
3564
|
-
|
|
3565
|
-
this
|
|
3566
|
-
|
|
3567
|
-
|
|
3564
|
+
if (__privateGet2(this, _options).agentResetInterval && __privateGet2(this, _options).agentResetInterval > 0) {
|
|
3565
|
+
__privateSet2(this, _agentResetInterval, setTimeout(() => {
|
|
3566
|
+
this.ResetAgent();
|
|
3567
|
+
__privateGet2(this, _SetupResetInterval).call(this);
|
|
3568
|
+
}, __privateGet2(this, _options).agentResetInterval).unref());
|
|
3569
|
+
}
|
|
3568
3570
|
});
|
|
3569
3571
|
__privateAdd2(this, _GetAgentOptions, (https2) => {
|
|
3570
3572
|
let options;
|
|
@@ -3600,6 +3602,22 @@ class AgentManager {
|
|
|
3600
3602
|
__privateGet2(this, _SetupResetInterval).call(this);
|
|
3601
3603
|
}
|
|
3602
3604
|
}
|
|
3605
|
+
get agentResetInterval() {
|
|
3606
|
+
return __privateGet2(this, _options).agentResetInterval;
|
|
3607
|
+
}
|
|
3608
|
+
set agentResetInterval(val) {
|
|
3609
|
+
if (__privateGet2(this, _agentResetInterval)) {
|
|
3610
|
+
clearTimeout(__privateGet2(this, _agentResetInterval));
|
|
3611
|
+
}
|
|
3612
|
+
__privateGet2(this, _options).agentResetInterval = val;
|
|
3613
|
+
__privateGet2(this, _SetupResetInterval).call(this);
|
|
3614
|
+
}
|
|
3615
|
+
get agentResetCount() {
|
|
3616
|
+
return __privateGet2(this, _options).agentResetCount;
|
|
3617
|
+
}
|
|
3618
|
+
set agentResetCount(val) {
|
|
3619
|
+
__privateGet2(this, _options).agentResetCount = val;
|
|
3620
|
+
}
|
|
3603
3621
|
IncRequestCount() {
|
|
3604
3622
|
__privateWrapper(this, _requestCount)._++;
|
|
3605
3623
|
if (__privateGet2(this, _options).agentResetCount) {
|
|
@@ -3672,6 +3690,103 @@ _agentResetInterval = /* @__PURE__ */ new WeakMap();
|
|
|
3672
3690
|
_requestCount = /* @__PURE__ */ new WeakMap();
|
|
3673
3691
|
_SetupResetInterval = /* @__PURE__ */ new WeakMap();
|
|
3674
3692
|
_GetAgentOptions = /* @__PURE__ */ new WeakMap();
|
|
3693
|
+
class STSAxiosConfig {
|
|
3694
|
+
/*
|
|
3695
|
+
headers = {
|
|
3696
|
+
'Content-Type': 'application/json',
|
|
3697
|
+
'Authorization': 'Bearer ' + accesss_token,
|
|
3698
|
+
'x-sts_user_id': DUMMY_USER
|
|
3699
|
+
}
|
|
3700
|
+
*/
|
|
3701
|
+
constructor(url, method, headers, timeout) {
|
|
3702
|
+
__privateAdd2(this, _url);
|
|
3703
|
+
__privateAdd2(this, _method);
|
|
3704
|
+
__privateAdd2(this, _headers);
|
|
3705
|
+
__privateAdd2(this, _data);
|
|
3706
|
+
__privateAdd2(this, _agentManager);
|
|
3707
|
+
__privateAdd2(this, _timeout);
|
|
3708
|
+
__privateAdd2(this, _withCredentials);
|
|
3709
|
+
__privateSet2(this, _url, url);
|
|
3710
|
+
__privateSet2(this, _method, method);
|
|
3711
|
+
if (headers !== void 0) {
|
|
3712
|
+
__privateSet2(this, _headers, headers);
|
|
3713
|
+
}
|
|
3714
|
+
if (timeout !== void 0) {
|
|
3715
|
+
__privateSet2(this, _timeout, timeout);
|
|
3716
|
+
}
|
|
3717
|
+
}
|
|
3718
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3719
|
+
withData(data) {
|
|
3720
|
+
__privateSet2(this, _data, data);
|
|
3721
|
+
return this;
|
|
3722
|
+
}
|
|
3723
|
+
// 'Content-Type': 'application/json'
|
|
3724
|
+
withAuthHeaders(accesssToken, stsUserId) {
|
|
3725
|
+
__privateSet2(this, _headers, {
|
|
3726
|
+
"Content-Type": "application/json",
|
|
3727
|
+
"Authorization": "Bearer " + accesssToken
|
|
3728
|
+
});
|
|
3729
|
+
if (stsUserId) {
|
|
3730
|
+
__privateGet2(this, _headers)["x-sts_user_id"] = stsUserId;
|
|
3731
|
+
}
|
|
3732
|
+
return this;
|
|
3733
|
+
}
|
|
3734
|
+
withHeaders(headers) {
|
|
3735
|
+
__privateSet2(this, _headers, headers);
|
|
3736
|
+
return this;
|
|
3737
|
+
}
|
|
3738
|
+
withDefaultHeaders() {
|
|
3739
|
+
__privateSet2(this, _headers, {
|
|
3740
|
+
"Content-Type": "application/json"
|
|
3741
|
+
});
|
|
3742
|
+
return this;
|
|
3743
|
+
}
|
|
3744
|
+
withCredentials() {
|
|
3745
|
+
__privateSet2(this, _withCredentials, true);
|
|
3746
|
+
return this;
|
|
3747
|
+
}
|
|
3748
|
+
withTimeout(timeout) {
|
|
3749
|
+
__privateSet2(this, _timeout, timeout);
|
|
3750
|
+
return this;
|
|
3751
|
+
}
|
|
3752
|
+
withAgentManager(agentManager) {
|
|
3753
|
+
__privateSet2(this, _agentManager, agentManager);
|
|
3754
|
+
return this;
|
|
3755
|
+
}
|
|
3756
|
+
get config() {
|
|
3757
|
+
const retVal = {
|
|
3758
|
+
url: __privateGet2(this, _url),
|
|
3759
|
+
method: __privateGet2(this, _method)
|
|
3760
|
+
};
|
|
3761
|
+
if (__privateGet2(this, _headers)) {
|
|
3762
|
+
retVal.headers = __privateGet2(this, _headers);
|
|
3763
|
+
}
|
|
3764
|
+
if (__privateGet2(this, _agentManager) !== void 0) {
|
|
3765
|
+
if (__privateGet2(this, _agentManager).IsHttps(__privateGet2(this, _url))) {
|
|
3766
|
+
retVal.httpsAgent = __privateGet2(this, _agentManager).GetAgent(__privateGet2(this, _url));
|
|
3767
|
+
} else {
|
|
3768
|
+
retVal.httpAgent = __privateGet2(this, _agentManager).GetAgent(__privateGet2(this, _url));
|
|
3769
|
+
}
|
|
3770
|
+
}
|
|
3771
|
+
if (__privateGet2(this, _data) !== void 0) {
|
|
3772
|
+
retVal.data = __privateGet2(this, _data);
|
|
3773
|
+
}
|
|
3774
|
+
if (__privateGet2(this, _timeout) !== void 0) {
|
|
3775
|
+
retVal.timeout = __privateGet2(this, _timeout);
|
|
3776
|
+
}
|
|
3777
|
+
if (__privateGet2(this, _withCredentials) !== void 0 && __privateGet2(this, _withCredentials) === true) {
|
|
3778
|
+
retVal.withCredentials = true;
|
|
3779
|
+
}
|
|
3780
|
+
return retVal;
|
|
3781
|
+
}
|
|
3782
|
+
}
|
|
3783
|
+
_url = /* @__PURE__ */ new WeakMap();
|
|
3784
|
+
_method = /* @__PURE__ */ new WeakMap();
|
|
3785
|
+
_headers = /* @__PURE__ */ new WeakMap();
|
|
3786
|
+
_data = /* @__PURE__ */ new WeakMap();
|
|
3787
|
+
_agentManager = /* @__PURE__ */ new WeakMap();
|
|
3788
|
+
_timeout = /* @__PURE__ */ new WeakMap();
|
|
3789
|
+
_withCredentials = /* @__PURE__ */ new WeakMap();
|
|
3675
3790
|
class FhirClient {
|
|
3676
3791
|
constructor(options) {
|
|
3677
3792
|
__privateAdd(this, _options2);
|
|
@@ -3686,7 +3801,7 @@ class FhirClient {
|
|
|
3686
3801
|
]);
|
|
3687
3802
|
__privateAdd(this, _stsfhirapiroot, "/stsfhir/r5");
|
|
3688
3803
|
// Default value
|
|
3689
|
-
__privateAdd(this,
|
|
3804
|
+
__privateAdd(this, _agentManager2, null);
|
|
3690
3805
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3691
3806
|
__privateAdd(this, _LogDebugMessage, (message) => {
|
|
3692
3807
|
__privateGet(this, _options2).logger.debug(message);
|
|
@@ -3749,9 +3864,9 @@ class FhirClient {
|
|
|
3749
3864
|
__privateGet(this, _options2).clientTelemetryEvents.AuthenticationErrorInc();
|
|
3750
3865
|
}
|
|
3751
3866
|
}
|
|
3752
|
-
if (isNode && __privateGet(this,
|
|
3867
|
+
if (isNode && __privateGet(this, _agentManager2)) {
|
|
3753
3868
|
console.error(chalk$2.red(`#InvokeResourceAPI(): Resetting https agent (to null).`));
|
|
3754
|
-
__privateGet(this,
|
|
3869
|
+
__privateGet(this, _agentManager2).ResetAgent();
|
|
3755
3870
|
}
|
|
3756
3871
|
performRetry = true;
|
|
3757
3872
|
}
|
|
@@ -3810,30 +3925,11 @@ class FhirClient {
|
|
|
3810
3925
|
}
|
|
3811
3926
|
}
|
|
3812
3927
|
const accessToken = await __privateGet(this, _options2).GetAccessToken();
|
|
3813
|
-
const
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
"x-sts_user_id": __privateGet(this, _DUMMY_USER)
|
|
3817
|
-
};
|
|
3818
|
-
const requestConfig = {
|
|
3819
|
-
url,
|
|
3820
|
-
method: httpVerb,
|
|
3821
|
-
headers
|
|
3822
|
-
};
|
|
3823
|
-
if (isNode && __privateGet(this, _agentManager)) {
|
|
3824
|
-
if (__privateGet(this, _agentManager).IsHttps(url)) {
|
|
3825
|
-
requestConfig.httpsAgent = __privateGet(this, _agentManager).GetAgent(url);
|
|
3826
|
-
} else {
|
|
3827
|
-
requestConfig.httpAgent = __privateGet(this, _agentManager).GetAgent(url);
|
|
3828
|
-
}
|
|
3928
|
+
const requestConfig = new STSAxiosConfig(url, httpVerb).withAuthHeaders(accessToken, __privateGet(this, _DUMMY_USER)).withData(filters ? filters : domainResource ? domainResource : void 0);
|
|
3929
|
+
if (isNode && __privateGet(this, _agentManager2)) {
|
|
3930
|
+
requestConfig.withAgentManager(__privateGet(this, _agentManager2));
|
|
3829
3931
|
}
|
|
3830
|
-
|
|
3831
|
-
requestConfig.data = filters;
|
|
3832
|
-
} else if (domainResource) {
|
|
3833
|
-
requestConfig.data = domainResource;
|
|
3834
|
-
}
|
|
3835
|
-
const retVal = await axios(requestConfig);
|
|
3836
|
-
return retVal;
|
|
3932
|
+
return await axios(requestConfig.config);
|
|
3837
3933
|
} catch (error) {
|
|
3838
3934
|
const responseCode = __privateGet(this, _HandleError).call(this, error);
|
|
3839
3935
|
errorCb(responseCode, error);
|
|
@@ -3929,23 +4025,11 @@ class FhirClient {
|
|
|
3929
4025
|
__publicField(this, "GetLatency", async () => {
|
|
3930
4026
|
const url = `${__privateGet(this, _options2).fhirEndpoint}${__privateGet(this, _stsfhirapiroot)}/latency`;
|
|
3931
4027
|
try {
|
|
3932
|
-
const
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
const requestConfig = {
|
|
3936
|
-
url,
|
|
3937
|
-
method: "get",
|
|
3938
|
-
headers
|
|
3939
|
-
};
|
|
3940
|
-
if (isNode && __privateGet(this, _agentManager)) {
|
|
3941
|
-
if (__privateGet(this, _agentManager).IsHttps(url)) {
|
|
3942
|
-
requestConfig.httpsAgent = __privateGet(this, _agentManager).GetAgent(url);
|
|
3943
|
-
} else {
|
|
3944
|
-
requestConfig.httpAgent = __privateGet(this, _agentManager).GetAgent(url);
|
|
3945
|
-
}
|
|
4028
|
+
const requestConfig = new STSAxiosConfig(url, "get").withDefaultHeaders();
|
|
4029
|
+
if (isNode && __privateGet(this, _agentManager2)) {
|
|
4030
|
+
requestConfig.withAgentManager(__privateGet(this, _agentManager2));
|
|
3946
4031
|
}
|
|
3947
|
-
|
|
3948
|
-
return retVal;
|
|
4032
|
+
return await axios(requestConfig.config);
|
|
3949
4033
|
} catch (error) {
|
|
3950
4034
|
__privateGet(this, _HandleError).call(this, error);
|
|
3951
4035
|
}
|
|
@@ -3956,11 +4040,11 @@ class FhirClient {
|
|
|
3956
4040
|
}
|
|
3957
4041
|
if (isNode) {
|
|
3958
4042
|
if (__privateGet(this, _options2).agentOptions) {
|
|
3959
|
-
__privateSet(this,
|
|
4043
|
+
__privateSet(this, _agentManager2, new AgentManager({
|
|
3960
4044
|
agentOptions: __privateGet(this, _options2).agentOptions
|
|
3961
4045
|
}));
|
|
3962
4046
|
} else {
|
|
3963
|
-
__privateSet(this,
|
|
4047
|
+
__privateSet(this, _agentManager2, new AgentManager({}));
|
|
3964
4048
|
}
|
|
3965
4049
|
}
|
|
3966
4050
|
}
|
|
@@ -3975,7 +4059,7 @@ _maxRetries = new WeakMap();
|
|
|
3975
4059
|
_sleepDuration = new WeakMap();
|
|
3976
4060
|
_NoRetryStatusCodes = new WeakMap();
|
|
3977
4061
|
_stsfhirapiroot = new WeakMap();
|
|
3978
|
-
|
|
4062
|
+
_agentManager2 = new WeakMap();
|
|
3979
4063
|
_LogDebugMessage = new WeakMap();
|
|
3980
4064
|
_LogErrorMessage = new WeakMap();
|
|
3981
4065
|
_HandleError = new WeakMap();
|