@nsshunt/stsfhirclient 2.0.32 → 2.0.34

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 {
@@ -13150,48 +13221,9 @@ var SocketIoClient = class extends import_tiny_emitter.TinyEmitter {
13150
13221
  }
13151
13222
  };
13152
13223
  //#endregion
13153
- //#region node_modules/uuid/dist/stringify.js
13154
- var byteToHex = [];
13155
- for (let i = 0; i < 256; ++i) byteToHex.push((i + 256).toString(16).slice(1));
13156
- function unsafeStringify(arr, offset = 0) {
13157
- return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
13158
- }
13159
- //#endregion
13160
- //#region node_modules/uuid/dist/rng.js
13161
- var getRandomValues;
13162
- var rnds8 = new Uint8Array(16);
13163
- function rng() {
13164
- if (!getRandomValues) {
13165
- if (typeof crypto === "undefined" || !crypto.getRandomValues) throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
13166
- getRandomValues = crypto.getRandomValues.bind(crypto);
13167
- }
13168
- return getRandomValues(rnds8);
13169
- }
13170
- var native_default = { randomUUID: typeof crypto !== "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto) };
13171
- //#endregion
13172
- //#region node_modules/uuid/dist/v4.js
13173
- function _v4(options, buf, offset) {
13174
- options = options || {};
13175
- const rnds = options.random ?? options.rng?.() ?? rng();
13176
- if (rnds.length < 16) throw new Error("Random bytes length must be >= 16");
13177
- rnds[6] = rnds[6] & 15 | 64;
13178
- rnds[8] = rnds[8] & 63 | 128;
13179
- if (buf) {
13180
- offset = offset || 0;
13181
- if (offset < 0 || offset + 16 > buf.length) throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
13182
- for (let i = 0; i < 16; ++i) buf[offset + i] = rnds[i];
13183
- return buf;
13184
- }
13185
- return unsafeStringify(rnds);
13186
- }
13187
- function v4(options, buf, offset) {
13188
- if (native_default.randomUUID && !buf && !options) return native_default.randomUUID();
13189
- return _v4(options, buf, offset);
13190
- }
13191
- //#endregion
13192
13224
  //#region src/cv2/fhirSocketClient.ts
13193
13225
  var FhirSocketClient = class extends SocketIoClient {
13194
- id = v4();
13226
+ id = globalThis.crypto.randomUUID();
13195
13227
  options;
13196
13228
  accessToken = "";
13197
13229
  constructor(clientName, options) {
@@ -13696,68 +13728,6 @@ var FhirSocketClientIndividual = class extends FhirSocketClient {
13696
13728
  };
13697
13729
  };
13698
13730
  //#endregion
13699
- //#region src/retryAxiosClient.ts
13700
- function sleep(ms) {
13701
- return new Promise((resolve) => setTimeout(resolve, ms));
13702
- }
13703
- function getJitteredDelay(base, jitter) {
13704
- return base + Math.floor(Math.random() * jitter);
13705
- }
13706
- function createRetryAxiosClient(retryConfig) {
13707
- const { maxRetries = 3, retryDelayMs = 300, retryJitterMs = 100, retryMethods = [
13708
- "get",
13709
- "head",
13710
- "put",
13711
- "delete",
13712
- "options"
13713
- ], retryStatusCodes = [
13714
- 408,
13715
- 429,
13716
- 500,
13717
- 502,
13718
- 503,
13719
- 504
13720
- ], retryErrorCodes = [
13721
- "ECONNRESET",
13722
- "ETIMEDOUT",
13723
- "EAI_AGAIN",
13724
- "ECONNREFUSED",
13725
- "ENOTFOUND",
13726
- "EHOSTUNREACH",
13727
- "EPIPE"
13728
- ], maxRetryDurationMs = 1e4, onRetryAttempt, stsAxiosConfig } = retryConfig || {};
13729
- const instance = axios.default.create();
13730
- instance.interceptors.request.use((config) => {
13731
- const retryConfig = config;
13732
- if (!retryConfig.metadata) retryConfig.metadata = {
13733
- startTime: Date.now(),
13734
- __retryCount: 0
13735
- };
13736
- if (stsAxiosConfig) Object.assign(config, stsAxiosConfig.config);
13737
- return config;
13738
- });
13739
- instance.interceptors.response.use((response) => response, async (error) => {
13740
- const config = error.config;
13741
- if (!config || !config.method || !config.metadata) return Promise.reject(error);
13742
- const elapsed = Date.now() - config.metadata.startTime;
13743
- const method = config.method.toLowerCase();
13744
- const status = error.response?.status;
13745
- const code = error.code ?? "";
13746
- const isRetryableMethod = retryMethods.includes(method);
13747
- const isRetryableStatus = retryStatusCodes.includes(status ?? 0);
13748
- const isRetryableCode = retryErrorCodes.includes(code);
13749
- if (isRetryableMethod && (isRetryableStatus || isRetryableCode) && config.metadata.__retryCount < maxRetries && elapsed < maxRetryDurationMs) {
13750
- config.metadata.__retryCount += 1;
13751
- const delayMs = getJitteredDelay(retryDelayMs * Math.pow(2, config.metadata.__retryCount - 1), retryJitterMs);
13752
- onRetryAttempt?.(config.metadata.__retryCount, error, delayMs);
13753
- await sleep(delayMs);
13754
- return instance(config);
13755
- }
13756
- return Promise.reject(error);
13757
- });
13758
- return instance;
13759
- }
13760
- //#endregion
13761
13731
  exports.FhirRESTClient = FhirRESTClient;
13762
13732
  exports.FhirRouteError = FhirRouteError;
13763
13733
  exports.FhirSocketClient = FhirSocketClient;