@nsshunt/stsfhirclient 2.0.16 → 2.0.18

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.
@@ -9201,7 +9201,8 @@ function createRetryAxiosClient(retryConfig) {
9201
9201
  ], maxRetryDurationMs = 1e4, onRetryAttempt, stsAxiosConfig } = retryConfig || {};
9202
9202
  const instance = axios.default.create();
9203
9203
  instance.interceptors.request.use((config) => {
9204
- config.metadata = {
9204
+ const retryConfig = config;
9205
+ if (!retryConfig.metadata) retryConfig.metadata = {
9205
9206
  startTime: Date.now(),
9206
9207
  __retryCount: 0
9207
9208
  };
@@ -9214,13 +9215,15 @@ function createRetryAxiosClient(retryConfig) {
9214
9215
  const elapsed = Date.now() - config.metadata.startTime;
9215
9216
  const method = config.method.toLowerCase();
9216
9217
  const status = error.response?.status;
9217
- const code = error.code;
9218
- const isRetryable = retryMethods.includes(method) && (retryErrorCodes.includes(code || "") || retryStatusCodes.includes(status || 0));
9219
- if (config.metadata.__retryCount < maxRetries && isRetryable && elapsed < maxRetryDurationMs) {
9218
+ const code = error.code ?? "";
9219
+ const isRetryableMethod = retryMethods.includes(method);
9220
+ const isRetryableStatus = retryStatusCodes.includes(status ?? 0);
9221
+ const isRetryableCode = retryErrorCodes.includes(code);
9222
+ if (isRetryableMethod && (isRetryableStatus || isRetryableCode) && config.metadata.__retryCount < maxRetries && elapsed < maxRetryDurationMs) {
9220
9223
  config.metadata.__retryCount += 1;
9221
- const jitteredDelay = getJitteredDelay(retryDelayMs * Math.pow(2, config.metadata.__retryCount - 1), retryJitterMs);
9222
- if (onRetryAttempt) onRetryAttempt(config.metadata.__retryCount, error, jitteredDelay);
9223
- await sleep(jitteredDelay);
9224
+ const delayMs = getJitteredDelay(retryDelayMs * Math.pow(2, config.metadata.__retryCount - 1), retryJitterMs);
9225
+ onRetryAttempt?.(config.metadata.__retryCount, error, delayMs);
9226
+ await sleep(delayMs);
9224
9227
  return instance(config);
9225
9228
  }
9226
9229
  return Promise.reject(error);
@@ -9276,6 +9279,7 @@ var FhirRESTClient = class {
9276
9279
  maxRetryDurationMs: 5e3,
9277
9280
  onRetryAttempt: (attempt, error, delayMs) => {
9278
9281
  this.LogWarning("#InvokeResourceAPI", `Retry #${attempt} after ${delayMs}ms due to ${error.code || error.response?.status}`);
9282
+ if (this.#options.onRetryAttempt) this.#options.onRetryAttempt(attempt, error, delayMs);
9279
9283
  }
9280
9284
  })(url, requestConfig.config);
9281
9285
  };
@@ -15459,6 +15463,7 @@ exports.FhirSocketClientAllInOne = FhirSocketClientAllInOne;
15459
15463
  exports.FhirSocketClientIndividual = FhirSocketClientIndividual;
15460
15464
  exports.GetAboveHierarchy = GetAboveHierarchy;
15461
15465
  exports.STSFhirValidator = STSFhirValidator;
15466
+ exports.createRetryAxiosClient = createRetryAxiosClient;
15462
15467
  exports.fhirRT = fhirRT;
15463
15468
  exports.fhirSP = fhirSP;
15464
15469
  exports.fhirSPRefOnly = fhirSPRefOnly;