@nsshunt/stsfhirclient 1.0.19 → 1.0.20

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.
@@ -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, _agentManager, _LogDebugMessage, _LogErrorMessage, _HandleError, _InvokeResourceAPI, _TestMode, ___InvokeResourceAPI;
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
- __privateSet2(this, _agentResetInterval, setTimeout(() => {
3565
- this.ResetAgent();
3566
- __privateGet2(this, _SetupResetInterval).call(this);
3567
- }, __privateGet2(this, _options).agentResetInterval).unref());
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,86 @@ _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
+ constructor(url, method, headers, timeout) {
3695
+ __privateAdd2(this, _url);
3696
+ __privateAdd2(this, _method);
3697
+ __privateAdd2(this, _headers);
3698
+ __privateAdd2(this, _data);
3699
+ __privateAdd2(this, _agentManager);
3700
+ __privateAdd2(this, _timeout);
3701
+ __privateAdd2(this, _withCredentials);
3702
+ __privateSet2(this, _url, url);
3703
+ __privateSet2(this, _method, method);
3704
+ if (headers !== void 0) {
3705
+ __privateSet2(this, _headers, headers);
3706
+ }
3707
+ if (timeout !== void 0) {
3708
+ __privateSet2(this, _timeout, timeout);
3709
+ }
3710
+ }
3711
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3712
+ withData(data) {
3713
+ __privateSet2(this, _data, data);
3714
+ return this;
3715
+ }
3716
+ // 'Content-Type': 'application/json'
3717
+ withHeaders(headers) {
3718
+ __privateSet2(this, _headers, headers);
3719
+ return this;
3720
+ }
3721
+ withDefaultHeaders() {
3722
+ __privateSet2(this, _headers, {
3723
+ "Content-Type": "application/json"
3724
+ });
3725
+ return this;
3726
+ }
3727
+ withCredentials() {
3728
+ __privateSet2(this, _withCredentials, true);
3729
+ return this;
3730
+ }
3731
+ withTimeout(timeout) {
3732
+ __privateSet2(this, _timeout, timeout);
3733
+ return this;
3734
+ }
3735
+ withAgentManager(agentManager) {
3736
+ __privateSet2(this, _agentManager, agentManager);
3737
+ return this;
3738
+ }
3739
+ get config() {
3740
+ const retVal = {
3741
+ url: __privateGet2(this, _url),
3742
+ method: __privateGet2(this, _method)
3743
+ };
3744
+ if (__privateGet2(this, _headers)) {
3745
+ retVal.headers = __privateGet2(this, _headers);
3746
+ }
3747
+ if (__privateGet2(this, _agentManager) !== void 0) {
3748
+ if (__privateGet2(this, _agentManager).IsHttps(__privateGet2(this, _url))) {
3749
+ retVal.httpsAgent = __privateGet2(this, _agentManager).GetAgent(__privateGet2(this, _url));
3750
+ } else {
3751
+ retVal.httpAgent = __privateGet2(this, _agentManager).GetAgent(__privateGet2(this, _url));
3752
+ }
3753
+ }
3754
+ if (__privateGet2(this, _data) !== void 0) {
3755
+ retVal.data = __privateGet2(this, _data);
3756
+ }
3757
+ if (__privateGet2(this, _timeout) !== void 0) {
3758
+ retVal.timeout = __privateGet2(this, _timeout);
3759
+ }
3760
+ if (__privateGet2(this, _withCredentials) !== void 0 && __privateGet2(this, _withCredentials) === true) {
3761
+ retVal.withCredentials = true;
3762
+ }
3763
+ return retVal;
3764
+ }
3765
+ }
3766
+ _url = /* @__PURE__ */ new WeakMap();
3767
+ _method = /* @__PURE__ */ new WeakMap();
3768
+ _headers = /* @__PURE__ */ new WeakMap();
3769
+ _data = /* @__PURE__ */ new WeakMap();
3770
+ _agentManager = /* @__PURE__ */ new WeakMap();
3771
+ _timeout = /* @__PURE__ */ new WeakMap();
3772
+ _withCredentials = /* @__PURE__ */ new WeakMap();
3675
3773
  class FhirClient {
3676
3774
  constructor(options) {
3677
3775
  __privateAdd(this, _options2);
@@ -3686,7 +3784,7 @@ class FhirClient {
3686
3784
  ]);
3687
3785
  __privateAdd(this, _stsfhirapiroot, "/stsfhir/r5");
3688
3786
  // Default value
3689
- __privateAdd(this, _agentManager, null);
3787
+ __privateAdd(this, _agentManager2, null);
3690
3788
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
3691
3789
  __privateAdd(this, _LogDebugMessage, (message) => {
3692
3790
  __privateGet(this, _options2).logger.debug(message);
@@ -3749,9 +3847,9 @@ class FhirClient {
3749
3847
  __privateGet(this, _options2).clientTelemetryEvents.AuthenticationErrorInc();
3750
3848
  }
3751
3849
  }
3752
- if (isNode && __privateGet(this, _agentManager)) {
3850
+ if (isNode && __privateGet(this, _agentManager2)) {
3753
3851
  console.error(chalk$2.red(`#InvokeResourceAPI(): Resetting https agent (to null).`));
3754
- __privateGet(this, _agentManager).ResetAgent();
3852
+ __privateGet(this, _agentManager2).ResetAgent();
3755
3853
  }
3756
3854
  performRetry = true;
3757
3855
  }
@@ -3810,30 +3908,15 @@ class FhirClient {
3810
3908
  }
3811
3909
  }
3812
3910
  const accessToken = await __privateGet(this, _options2).GetAccessToken();
3813
- const headers = {
3911
+ const requestConfig = new STSAxiosConfig(url, httpVerb).withHeaders({
3814
3912
  "Content-Type": "application/json",
3815
3913
  "Authorization": `Bearer ${accessToken}`,
3816
3914
  "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
- }
3829
- }
3830
- if (filters) {
3831
- requestConfig.data = filters;
3832
- } else if (domainResource) {
3833
- requestConfig.data = domainResource;
3915
+ }).withData(filters ? filters : domainResource ? domainResource : void 0);
3916
+ if (isNode && __privateGet(this, _agentManager2)) {
3917
+ requestConfig.withAgentManager(__privateGet(this, _agentManager2));
3834
3918
  }
3835
- const retVal = await axios(requestConfig);
3836
- return retVal;
3919
+ return await axios(requestConfig.config);
3837
3920
  } catch (error) {
3838
3921
  const responseCode = __privateGet(this, _HandleError).call(this, error);
3839
3922
  errorCb(responseCode, error);
@@ -3929,23 +4012,13 @@ class FhirClient {
3929
4012
  __publicField(this, "GetLatency", async () => {
3930
4013
  const url = `${__privateGet(this, _options2).fhirEndpoint}${__privateGet(this, _stsfhirapiroot)}/latency`;
3931
4014
  try {
3932
- const headers = {
4015
+ const requestConfig = new STSAxiosConfig(url, "get", {
3933
4016
  "Content-Type": "application/json"
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
- }
4017
+ });
4018
+ if (isNode && __privateGet(this, _agentManager2)) {
4019
+ requestConfig.withAgentManager(__privateGet(this, _agentManager2));
3946
4020
  }
3947
- const retVal = await axios(requestConfig);
3948
- return retVal;
4021
+ return await axios(requestConfig.config);
3949
4022
  } catch (error) {
3950
4023
  __privateGet(this, _HandleError).call(this, error);
3951
4024
  }
@@ -3956,11 +4029,11 @@ class FhirClient {
3956
4029
  }
3957
4030
  if (isNode) {
3958
4031
  if (__privateGet(this, _options2).agentOptions) {
3959
- __privateSet(this, _agentManager, new AgentManager({
4032
+ __privateSet(this, _agentManager2, new AgentManager({
3960
4033
  agentOptions: __privateGet(this, _options2).agentOptions
3961
4034
  }));
3962
4035
  } else {
3963
- __privateSet(this, _agentManager, new AgentManager({}));
4036
+ __privateSet(this, _agentManager2, new AgentManager({}));
3964
4037
  }
3965
4038
  }
3966
4039
  }
@@ -3975,7 +4048,7 @@ _maxRetries = new WeakMap();
3975
4048
  _sleepDuration = new WeakMap();
3976
4049
  _NoRetryStatusCodes = new WeakMap();
3977
4050
  _stsfhirapiroot = new WeakMap();
3978
- _agentManager = new WeakMap();
4051
+ _agentManager2 = new WeakMap();
3979
4052
  _LogDebugMessage = new WeakMap();
3980
4053
  _LogErrorMessage = new WeakMap();
3981
4054
  _HandleError = new WeakMap();