@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.
package/dist/stsfhirclient.mjs
CHANGED
|
@@ -9158,6 +9158,68 @@ 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
|
|
9161
9223
|
//#region node_modules/chalk/source/vendor/ansi-styles/index.js
|
|
9162
9224
|
var ANSI_BACKGROUND_OFFSET = 10;
|
|
9163
9225
|
var wrapAnsi16 = (offset = 0) => (code) => `\u001B[${code + offset}m`;
|
|
@@ -9553,7 +9615,16 @@ var FhirRESTClient = class {
|
|
|
9553
9615
|
requestConfig.withAuthHeaders(accessToken, this.#options.user).withHeaders(headers);
|
|
9554
9616
|
if (resource) requestConfig.withData(resource);
|
|
9555
9617
|
if (this.#options.agentManager) requestConfig.withAgentManager(this.#options.agentManager);
|
|
9556
|
-
return await
|
|
9618
|
+
return await createRetryAxiosClient({
|
|
9619
|
+
maxRetries: 4,
|
|
9620
|
+
retryDelayMs: 300,
|
|
9621
|
+
retryJitterMs: 150,
|
|
9622
|
+
maxRetryDurationMs: 5e3,
|
|
9623
|
+
onRetryAttempt: (attempt, error, delayMs) => {
|
|
9624
|
+
this.LogWarning("#InvokeResourceAPI", `Retry #${attempt} after ${delayMs}ms due to ${error.code || error.response?.status}`);
|
|
9625
|
+
if (this.#options.onRetryAttempt) this.#options.onRetryAttempt(attempt, error, delayMs);
|
|
9626
|
+
}
|
|
9627
|
+
})(url, requestConfig.config);
|
|
9557
9628
|
};
|
|
9558
9629
|
ProcessBatchOrTransactionResources = async (bundle) => {
|
|
9559
9630
|
try {
|
|
@@ -13649,68 +13720,6 @@ var FhirSocketClientIndividual = class extends FhirSocketClient {
|
|
|
13649
13720
|
};
|
|
13650
13721
|
};
|
|
13651
13722
|
//#endregion
|
|
13652
|
-
//#region src/retryAxiosClient.ts
|
|
13653
|
-
function sleep(ms) {
|
|
13654
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
13655
|
-
}
|
|
13656
|
-
function getJitteredDelay(base, jitter) {
|
|
13657
|
-
return base + Math.floor(Math.random() * jitter);
|
|
13658
|
-
}
|
|
13659
|
-
function createRetryAxiosClient(retryConfig) {
|
|
13660
|
-
const { maxRetries = 3, retryDelayMs = 300, retryJitterMs = 100, retryMethods = [
|
|
13661
|
-
"get",
|
|
13662
|
-
"head",
|
|
13663
|
-
"put",
|
|
13664
|
-
"delete",
|
|
13665
|
-
"options"
|
|
13666
|
-
], retryStatusCodes = [
|
|
13667
|
-
408,
|
|
13668
|
-
429,
|
|
13669
|
-
500,
|
|
13670
|
-
502,
|
|
13671
|
-
503,
|
|
13672
|
-
504
|
|
13673
|
-
], retryErrorCodes = [
|
|
13674
|
-
"ECONNRESET",
|
|
13675
|
-
"ETIMEDOUT",
|
|
13676
|
-
"EAI_AGAIN",
|
|
13677
|
-
"ECONNREFUSED",
|
|
13678
|
-
"ENOTFOUND",
|
|
13679
|
-
"EHOSTUNREACH",
|
|
13680
|
-
"EPIPE"
|
|
13681
|
-
], maxRetryDurationMs = 1e4, onRetryAttempt, stsAxiosConfig } = retryConfig || {};
|
|
13682
|
-
const instance = axios.create();
|
|
13683
|
-
instance.interceptors.request.use((config) => {
|
|
13684
|
-
const retryConfig = config;
|
|
13685
|
-
if (!retryConfig.metadata) retryConfig.metadata = {
|
|
13686
|
-
startTime: Date.now(),
|
|
13687
|
-
__retryCount: 0
|
|
13688
|
-
};
|
|
13689
|
-
if (stsAxiosConfig) Object.assign(config, stsAxiosConfig.config);
|
|
13690
|
-
return config;
|
|
13691
|
-
});
|
|
13692
|
-
instance.interceptors.response.use((response) => response, async (error) => {
|
|
13693
|
-
const config = error.config;
|
|
13694
|
-
if (!config || !config.method || !config.metadata) return Promise.reject(error);
|
|
13695
|
-
const elapsed = Date.now() - config.metadata.startTime;
|
|
13696
|
-
const method = config.method.toLowerCase();
|
|
13697
|
-
const status = error.response?.status;
|
|
13698
|
-
const code = error.code ?? "";
|
|
13699
|
-
const isRetryableMethod = retryMethods.includes(method);
|
|
13700
|
-
const isRetryableStatus = retryStatusCodes.includes(status ?? 0);
|
|
13701
|
-
const isRetryableCode = retryErrorCodes.includes(code);
|
|
13702
|
-
if (isRetryableMethod && (isRetryableStatus || isRetryableCode) && config.metadata.__retryCount < maxRetries && elapsed < maxRetryDurationMs) {
|
|
13703
|
-
config.metadata.__retryCount += 1;
|
|
13704
|
-
const delayMs = getJitteredDelay(retryDelayMs * Math.pow(2, config.metadata.__retryCount - 1), retryJitterMs);
|
|
13705
|
-
onRetryAttempt?.(config.metadata.__retryCount, error, delayMs);
|
|
13706
|
-
await sleep(delayMs);
|
|
13707
|
-
return instance(config);
|
|
13708
|
-
}
|
|
13709
|
-
return Promise.reject(error);
|
|
13710
|
-
});
|
|
13711
|
-
return instance;
|
|
13712
|
-
}
|
|
13713
|
-
//#endregion
|
|
13714
13723
|
export { FhirRESTClient, FhirRouteError, FhirSocketClient, FhirSocketClientAllInOne, FhirSocketClientIndividual, GetAboveHierarchy, STSFhirValidator, createRetryAxiosClient, fhirRT, fhirSP, fhirSPRefOnly, getBaseResource, isAbsoluteUrl, normalizeUri, splitUnderBase };
|
|
13715
13724
|
|
|
13716
13725
|
//# sourceMappingURL=stsfhirclient.mjs.map
|