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