@nsshunt/stsfhirclient 2.0.30 → 2.0.32
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.
package/dist/stsfhirclient.cjs
CHANGED
|
@@ -9166,68 +9166,6 @@ 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
|
|
9231
9169
|
//#region node_modules/chalk/source/vendor/ansi-styles/index.js
|
|
9232
9170
|
var ANSI_BACKGROUND_OFFSET = 10;
|
|
9233
9171
|
var wrapAnsi16 = (offset = 0) => (code) => `\u001B[${code + offset}m`;
|
|
@@ -9593,7 +9531,6 @@ var FhirRESTClient = class {
|
|
|
9593
9531
|
this.#options.logger.error(error);
|
|
9594
9532
|
console.error(error);
|
|
9595
9533
|
this.HandleError(error);
|
|
9596
|
-
process.exit(0);
|
|
9597
9534
|
};
|
|
9598
9535
|
LogWarning = (method, message) => {
|
|
9599
9536
|
this.#options.logger.warn(`FhirRESTClient:${method}(): Warn: [${message}]`);
|
|
@@ -9624,16 +9561,7 @@ var FhirRESTClient = class {
|
|
|
9624
9561
|
requestConfig.withAuthHeaders(accessToken, this.#options.user).withHeaders(headers);
|
|
9625
9562
|
if (resource) requestConfig.withData(resource);
|
|
9626
9563
|
if (this.#options.agentManager) requestConfig.withAgentManager(this.#options.agentManager);
|
|
9627
|
-
return await
|
|
9628
|
-
maxRetries: 4,
|
|
9629
|
-
retryDelayMs: 300,
|
|
9630
|
-
retryJitterMs: 150,
|
|
9631
|
-
maxRetryDurationMs: 5e3,
|
|
9632
|
-
onRetryAttempt: (attempt, error, delayMs) => {
|
|
9633
|
-
this.LogWarning("#InvokeResourceAPI", `Retry #${attempt} after ${delayMs}ms due to ${error.code || error.response?.status}`);
|
|
9634
|
-
if (this.#options.onRetryAttempt) this.#options.onRetryAttempt(attempt, error, delayMs);
|
|
9635
|
-
}
|
|
9636
|
-
})(url, requestConfig.config);
|
|
9564
|
+
return await (0, axios.default)(requestConfig.config);
|
|
9637
9565
|
};
|
|
9638
9566
|
ProcessBatchOrTransactionResources = async (bundle) => {
|
|
9639
9567
|
try {
|
|
@@ -13768,6 +13696,68 @@ var FhirSocketClientIndividual = class extends FhirSocketClient {
|
|
|
13768
13696
|
};
|
|
13769
13697
|
};
|
|
13770
13698
|
//#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
|
|
13771
13761
|
exports.FhirRESTClient = FhirRESTClient;
|
|
13772
13762
|
exports.FhirRouteError = FhirRouteError;
|
|
13773
13763
|
exports.FhirSocketClient = FhirSocketClient;
|