@nsshunt/stsfhirclient 2.0.30 → 2.0.31

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.
@@ -9158,68 +9158,6 @@ function splitUnderBase(pathname, basePath) {
9158
9158
  return pathname.slice(basePath.length).split("/").filter(Boolean);
9159
9159
  }
9160
9160
  //#endregion
9161
- //#region src/retryAxiosClient.ts
9162
- function sleep(ms) {
9163
- return new Promise((resolve) => setTimeout(resolve, ms));
9164
- }
9165
- function getJitteredDelay(base, jitter) {
9166
- return base + Math.floor(Math.random() * jitter);
9167
- }
9168
- function createRetryAxiosClient(retryConfig) {
9169
- const { maxRetries = 3, retryDelayMs = 300, retryJitterMs = 100, retryMethods = [
9170
- "get",
9171
- "head",
9172
- "put",
9173
- "delete",
9174
- "options"
9175
- ], retryStatusCodes = [
9176
- 408,
9177
- 429,
9178
- 500,
9179
- 502,
9180
- 503,
9181
- 504
9182
- ], retryErrorCodes = [
9183
- "ECONNRESET",
9184
- "ETIMEDOUT",
9185
- "EAI_AGAIN",
9186
- "ECONNREFUSED",
9187
- "ENOTFOUND",
9188
- "EHOSTUNREACH",
9189
- "EPIPE"
9190
- ], maxRetryDurationMs = 1e4, onRetryAttempt, stsAxiosConfig } = retryConfig || {};
9191
- const instance = axios.create();
9192
- instance.interceptors.request.use((config) => {
9193
- const retryConfig = config;
9194
- if (!retryConfig.metadata) retryConfig.metadata = {
9195
- startTime: Date.now(),
9196
- __retryCount: 0
9197
- };
9198
- if (stsAxiosConfig) Object.assign(config, stsAxiosConfig.config);
9199
- return config;
9200
- });
9201
- instance.interceptors.response.use((response) => response, async (error) => {
9202
- const config = error.config;
9203
- if (!config || !config.method || !config.metadata) return Promise.reject(error);
9204
- const elapsed = Date.now() - config.metadata.startTime;
9205
- const method = config.method.toLowerCase();
9206
- const status = error.response?.status;
9207
- const code = error.code ?? "";
9208
- const isRetryableMethod = retryMethods.includes(method);
9209
- const isRetryableStatus = retryStatusCodes.includes(status ?? 0);
9210
- const isRetryableCode = retryErrorCodes.includes(code);
9211
- if (isRetryableMethod && (isRetryableStatus || isRetryableCode) && config.metadata.__retryCount < maxRetries && elapsed < maxRetryDurationMs) {
9212
- config.metadata.__retryCount += 1;
9213
- const delayMs = getJitteredDelay(retryDelayMs * Math.pow(2, config.metadata.__retryCount - 1), retryJitterMs);
9214
- onRetryAttempt?.(config.metadata.__retryCount, error, delayMs);
9215
- await sleep(delayMs);
9216
- return instance(config);
9217
- }
9218
- return Promise.reject(error);
9219
- });
9220
- return instance;
9221
- }
9222
- //#endregion
9223
9161
  //#region node_modules/chalk/source/vendor/ansi-styles/index.js
9224
9162
  var ANSI_BACKGROUND_OFFSET = 10;
9225
9163
  var wrapAnsi16 = (offset = 0) => (code) => `\u001B[${code + offset}m`;
@@ -9616,16 +9554,7 @@ var FhirRESTClient = class {
9616
9554
  requestConfig.withAuthHeaders(accessToken, this.#options.user).withHeaders(headers);
9617
9555
  if (resource) requestConfig.withData(resource);
9618
9556
  if (this.#options.agentManager) requestConfig.withAgentManager(this.#options.agentManager);
9619
- return await createRetryAxiosClient({
9620
- maxRetries: 4,
9621
- retryDelayMs: 300,
9622
- retryJitterMs: 150,
9623
- maxRetryDurationMs: 5e3,
9624
- onRetryAttempt: (attempt, error, delayMs) => {
9625
- this.LogWarning("#InvokeResourceAPI", `Retry #${attempt} after ${delayMs}ms due to ${error.code || error.response?.status}`);
9626
- if (this.#options.onRetryAttempt) this.#options.onRetryAttempt(attempt, error, delayMs);
9627
- }
9628
- })(url, requestConfig.config);
9557
+ return await axios(requestConfig.config);
9629
9558
  };
9630
9559
  ProcessBatchOrTransactionResources = async (bundle) => {
9631
9560
  try {
@@ -13760,6 +13689,68 @@ var FhirSocketClientIndividual = class extends FhirSocketClient {
13760
13689
  };
13761
13690
  };
13762
13691
  //#endregion
13692
+ //#region src/retryAxiosClient.ts
13693
+ function sleep(ms) {
13694
+ return new Promise((resolve) => setTimeout(resolve, ms));
13695
+ }
13696
+ function getJitteredDelay(base, jitter) {
13697
+ return base + Math.floor(Math.random() * jitter);
13698
+ }
13699
+ function createRetryAxiosClient(retryConfig) {
13700
+ const { maxRetries = 3, retryDelayMs = 300, retryJitterMs = 100, retryMethods = [
13701
+ "get",
13702
+ "head",
13703
+ "put",
13704
+ "delete",
13705
+ "options"
13706
+ ], retryStatusCodes = [
13707
+ 408,
13708
+ 429,
13709
+ 500,
13710
+ 502,
13711
+ 503,
13712
+ 504
13713
+ ], retryErrorCodes = [
13714
+ "ECONNRESET",
13715
+ "ETIMEDOUT",
13716
+ "EAI_AGAIN",
13717
+ "ECONNREFUSED",
13718
+ "ENOTFOUND",
13719
+ "EHOSTUNREACH",
13720
+ "EPIPE"
13721
+ ], maxRetryDurationMs = 1e4, onRetryAttempt, stsAxiosConfig } = retryConfig || {};
13722
+ const instance = axios.create();
13723
+ instance.interceptors.request.use((config) => {
13724
+ const retryConfig = config;
13725
+ if (!retryConfig.metadata) retryConfig.metadata = {
13726
+ startTime: Date.now(),
13727
+ __retryCount: 0
13728
+ };
13729
+ if (stsAxiosConfig) Object.assign(config, stsAxiosConfig.config);
13730
+ return config;
13731
+ });
13732
+ instance.interceptors.response.use((response) => response, async (error) => {
13733
+ const config = error.config;
13734
+ if (!config || !config.method || !config.metadata) return Promise.reject(error);
13735
+ const elapsed = Date.now() - config.metadata.startTime;
13736
+ const method = config.method.toLowerCase();
13737
+ const status = error.response?.status;
13738
+ const code = error.code ?? "";
13739
+ const isRetryableMethod = retryMethods.includes(method);
13740
+ const isRetryableStatus = retryStatusCodes.includes(status ?? 0);
13741
+ const isRetryableCode = retryErrorCodes.includes(code);
13742
+ if (isRetryableMethod && (isRetryableStatus || isRetryableCode) && config.metadata.__retryCount < maxRetries && elapsed < maxRetryDurationMs) {
13743
+ config.metadata.__retryCount += 1;
13744
+ const delayMs = getJitteredDelay(retryDelayMs * Math.pow(2, config.metadata.__retryCount - 1), retryJitterMs);
13745
+ onRetryAttempt?.(config.metadata.__retryCount, error, delayMs);
13746
+ await sleep(delayMs);
13747
+ return instance(config);
13748
+ }
13749
+ return Promise.reject(error);
13750
+ });
13751
+ return instance;
13752
+ }
13753
+ //#endregion
13763
13754
  export { FhirRESTClient, FhirRouteError, FhirSocketClient, FhirSocketClientAllInOne, FhirSocketClientIndividual, GetAboveHierarchy, STSFhirValidator, createRetryAxiosClient, fhirRT, fhirSP, fhirSPRefOnly, getBaseResource, isAbsoluteUrl, normalizeUri, splitUnderBase };
13764
13755
 
13765
13756
  //# sourceMappingURL=stsfhirclient.mjs.map