@nsshunt/stsfhirclient 2.0.33 → 2.0.35

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.
@@ -9166,6 +9166,68 @@ function splitUnderBase(pathname, basePath) {
9166
9166
  return pathname.slice(basePath.length).split("/").filter(Boolean);
9167
9167
  }
9168
9168
  //#endregion
9169
+ //#region src/retryAxiosClient.ts
9170
+ function sleep(ms) {
9171
+ return new Promise((resolve) => setTimeout(resolve, ms));
9172
+ }
9173
+ function getJitteredDelay(base, jitter) {
9174
+ return base + Math.floor(Math.random() * jitter);
9175
+ }
9176
+ function createRetryAxiosClient(retryConfig) {
9177
+ const { maxRetries = 3, retryDelayMs = 300, retryJitterMs = 100, retryMethods = [
9178
+ "get",
9179
+ "head",
9180
+ "put",
9181
+ "delete",
9182
+ "options"
9183
+ ], retryStatusCodes = [
9184
+ 408,
9185
+ 429,
9186
+ 500,
9187
+ 502,
9188
+ 503,
9189
+ 504
9190
+ ], retryErrorCodes = [
9191
+ "ECONNRESET",
9192
+ "ETIMEDOUT",
9193
+ "EAI_AGAIN",
9194
+ "ECONNREFUSED",
9195
+ "ENOTFOUND",
9196
+ "EHOSTUNREACH",
9197
+ "EPIPE"
9198
+ ], maxRetryDurationMs = 1e4, onRetryAttempt, stsAxiosConfig } = retryConfig || {};
9199
+ const instance = axios.default.create();
9200
+ instance.interceptors.request.use((config) => {
9201
+ const retryConfig = config;
9202
+ if (!retryConfig.metadata) retryConfig.metadata = {
9203
+ startTime: Date.now(),
9204
+ __retryCount: 0
9205
+ };
9206
+ if (stsAxiosConfig) Object.assign(config, stsAxiosConfig.config);
9207
+ return config;
9208
+ });
9209
+ instance.interceptors.response.use((response) => response, async (error) => {
9210
+ const config = error.config;
9211
+ if (!config || !config.method || !config.metadata) return Promise.reject(error);
9212
+ const elapsed = Date.now() - config.metadata.startTime;
9213
+ const method = config.method.toLowerCase();
9214
+ const status = error.response?.status;
9215
+ const code = error.code ?? "";
9216
+ const isRetryableMethod = retryMethods.includes(method);
9217
+ const isRetryableStatus = retryStatusCodes.includes(status ?? 0);
9218
+ const isRetryableCode = retryErrorCodes.includes(code);
9219
+ if (isRetryableMethod && (isRetryableStatus || isRetryableCode) && config.metadata.__retryCount < maxRetries && elapsed < maxRetryDurationMs) {
9220
+ config.metadata.__retryCount += 1;
9221
+ const delayMs = getJitteredDelay(retryDelayMs * Math.pow(2, config.metadata.__retryCount - 1), retryJitterMs);
9222
+ onRetryAttempt?.(config.metadata.__retryCount, error, delayMs);
9223
+ await sleep(delayMs);
9224
+ return instance(config);
9225
+ }
9226
+ return Promise.reject(error);
9227
+ });
9228
+ return instance;
9229
+ }
9230
+ //#endregion
9169
9231
  //#region node_modules/chalk/source/vendor/ansi-styles/index.js
9170
9232
  var ANSI_BACKGROUND_OFFSET = 10;
9171
9233
  var wrapAnsi16 = (offset = 0) => (code) => `\u001B[${code + offset}m`;
@@ -9561,7 +9623,16 @@ var FhirRESTClient = class {
9561
9623
  requestConfig.withAuthHeaders(accessToken, this.#options.user).withHeaders(headers);
9562
9624
  if (resource) requestConfig.withData(resource);
9563
9625
  if (this.#options.agentManager) requestConfig.withAgentManager(this.#options.agentManager);
9564
- return await (0, axios.default)(requestConfig.config);
9626
+ return await createRetryAxiosClient({
9627
+ maxRetries: 4,
9628
+ retryDelayMs: 300,
9629
+ retryJitterMs: 150,
9630
+ maxRetryDurationMs: 5e3,
9631
+ onRetryAttempt: (attempt, error, delayMs) => {
9632
+ this.LogWarning("#InvokeResourceAPI", `Retry #${attempt} after ${delayMs}ms due to ${error.code || error.response?.status}`);
9633
+ if (this.#options.onRetryAttempt) this.#options.onRetryAttempt(attempt, error, delayMs);
9634
+ }
9635
+ })(url, requestConfig.config);
9565
9636
  };
9566
9637
  ProcessBatchOrTransactionResources = async (bundle) => {
9567
9638
  try {
@@ -13657,68 +13728,6 @@ var FhirSocketClientIndividual = class extends FhirSocketClient {
13657
13728
  };
13658
13729
  };
13659
13730
  //#endregion
13660
- //#region src/retryAxiosClient.ts
13661
- function sleep(ms) {
13662
- return new Promise((resolve) => setTimeout(resolve, ms));
13663
- }
13664
- function getJitteredDelay(base, jitter) {
13665
- return base + Math.floor(Math.random() * jitter);
13666
- }
13667
- function createRetryAxiosClient(retryConfig) {
13668
- const { maxRetries = 3, retryDelayMs = 300, retryJitterMs = 100, retryMethods = [
13669
- "get",
13670
- "head",
13671
- "put",
13672
- "delete",
13673
- "options"
13674
- ], retryStatusCodes = [
13675
- 408,
13676
- 429,
13677
- 500,
13678
- 502,
13679
- 503,
13680
- 504
13681
- ], retryErrorCodes = [
13682
- "ECONNRESET",
13683
- "ETIMEDOUT",
13684
- "EAI_AGAIN",
13685
- "ECONNREFUSED",
13686
- "ENOTFOUND",
13687
- "EHOSTUNREACH",
13688
- "EPIPE"
13689
- ], maxRetryDurationMs = 1e4, onRetryAttempt, stsAxiosConfig } = retryConfig || {};
13690
- const instance = axios.default.create();
13691
- instance.interceptors.request.use((config) => {
13692
- const retryConfig = config;
13693
- if (!retryConfig.metadata) retryConfig.metadata = {
13694
- startTime: Date.now(),
13695
- __retryCount: 0
13696
- };
13697
- if (stsAxiosConfig) Object.assign(config, stsAxiosConfig.config);
13698
- return config;
13699
- });
13700
- instance.interceptors.response.use((response) => response, async (error) => {
13701
- const config = error.config;
13702
- if (!config || !config.method || !config.metadata) return Promise.reject(error);
13703
- const elapsed = Date.now() - config.metadata.startTime;
13704
- const method = config.method.toLowerCase();
13705
- const status = error.response?.status;
13706
- const code = error.code ?? "";
13707
- const isRetryableMethod = retryMethods.includes(method);
13708
- const isRetryableStatus = retryStatusCodes.includes(status ?? 0);
13709
- const isRetryableCode = retryErrorCodes.includes(code);
13710
- if (isRetryableMethod && (isRetryableStatus || isRetryableCode) && config.metadata.__retryCount < maxRetries && elapsed < maxRetryDurationMs) {
13711
- config.metadata.__retryCount += 1;
13712
- const delayMs = getJitteredDelay(retryDelayMs * Math.pow(2, config.metadata.__retryCount - 1), retryJitterMs);
13713
- onRetryAttempt?.(config.metadata.__retryCount, error, delayMs);
13714
- await sleep(delayMs);
13715
- return instance(config);
13716
- }
13717
- return Promise.reject(error);
13718
- });
13719
- return instance;
13720
- }
13721
- //#endregion
13722
13731
  exports.FhirRESTClient = FhirRESTClient;
13723
13732
  exports.FhirRouteError = FhirRouteError;
13724
13733
  exports.FhirSocketClient = FhirSocketClient;