@rogatio/cli 6.20.0 → 6.20.1
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/node/index.js +39 -58
- package/package.json +1 -1
package/dist/node/index.js
CHANGED
|
@@ -21133,79 +21133,51 @@ function sleep(ms) {
|
|
|
21133
21133
|
function calculateRetryDelay(attempt) {
|
|
21134
21134
|
return RETRY_DELAY_BASE * 2 ** attempt + Math.random() * 100;
|
|
21135
21135
|
}
|
|
21136
|
-
|
|
21137
|
-
|
|
21138
|
-
for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
|
|
21139
|
-
if (signal?.aborted) {
|
|
21140
|
-
throw new DOMException("Aborted", "AbortError");
|
|
21141
|
-
}
|
|
21142
|
-
try {
|
|
21143
|
-
const controller = new AbortController();
|
|
21144
|
-
const timeoutId = setTimeout(() => controller.abort(), COMPLETE_TIMEOUT);
|
|
21145
|
-
if (signal) {
|
|
21146
|
-
signal.addEventListener("abort", () => controller.abort());
|
|
21147
|
-
}
|
|
21148
|
-
const response = await fetch(url, {
|
|
21149
|
-
...init,
|
|
21150
|
-
signal: controller.signal
|
|
21151
|
-
});
|
|
21152
|
-
clearTimeout(timeoutId);
|
|
21153
|
-
if (response.ok) {
|
|
21154
|
-
return response;
|
|
21155
|
-
}
|
|
21156
|
-
const shouldRetry = response.status === 429 || response.status >= 500;
|
|
21157
|
-
if (shouldRetry && attempt < MAX_RETRIES) {
|
|
21158
|
-
const retryAfter = response.headers.get("Retry-After");
|
|
21159
|
-
const delay = retryAfter ? parseInt(retryAfter, 10) * 1e3 : calculateRetryDelay(attempt);
|
|
21160
|
-
await sleep(Math.min(delay, 1e4));
|
|
21161
|
-
continue;
|
|
21162
|
-
}
|
|
21163
|
-
const errorText = await response.text().catch(() => "");
|
|
21164
|
-
throw new Error(`HTTP ${response.status}: ${errorText}`);
|
|
21165
|
-
} catch (e) {
|
|
21166
|
-
lastError = e;
|
|
21167
|
-
if (e instanceof DOMException && e.name === "AbortError") {
|
|
21168
|
-
throw e;
|
|
21169
|
-
}
|
|
21170
|
-
if (attempt < MAX_RETRIES && e.name !== "AbortError") {
|
|
21171
|
-
await sleep(calculateRetryDelay(attempt));
|
|
21172
|
-
continue;
|
|
21173
|
-
}
|
|
21174
|
-
throw e;
|
|
21175
|
-
}
|
|
21176
|
-
}
|
|
21177
|
-
throw lastError;
|
|
21136
|
+
function providerStatusError(status) {
|
|
21137
|
+
return new Error(`HTTP ${status}`);
|
|
21178
21138
|
}
|
|
21179
|
-
async function
|
|
21139
|
+
async function releaseResponse(response) {
|
|
21140
|
+
await response.body?.cancel().catch(() => void 0);
|
|
21141
|
+
}
|
|
21142
|
+
async function fetchProvider(url, init, timeoutMs, signal) {
|
|
21180
21143
|
let lastError;
|
|
21181
21144
|
for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
|
|
21182
21145
|
if (signal?.aborted) {
|
|
21183
21146
|
throw new DOMException("Aborted", "AbortError");
|
|
21184
21147
|
}
|
|
21148
|
+
const controller = new AbortController();
|
|
21149
|
+
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
|
21150
|
+
if (signal) {
|
|
21151
|
+
signal.addEventListener("abort", () => controller.abort());
|
|
21152
|
+
}
|
|
21153
|
+
let terminalStatus;
|
|
21185
21154
|
try {
|
|
21186
|
-
const controller = new AbortController();
|
|
21187
|
-
const timeoutId = setTimeout(() => controller.abort(), STREAM_TIMEOUT);
|
|
21188
|
-
if (signal) {
|
|
21189
|
-
signal.addEventListener("abort", () => controller.abort());
|
|
21190
|
-
}
|
|
21191
21155
|
const response = await fetch(url, {
|
|
21192
21156
|
...init,
|
|
21157
|
+
// Stay on the configured URL. A 3xx response is not followed.
|
|
21158
|
+
redirect: "manual",
|
|
21193
21159
|
signal: controller.signal
|
|
21194
21160
|
});
|
|
21195
21161
|
clearTimeout(timeoutId);
|
|
21196
|
-
if (response.
|
|
21162
|
+
if (response.status >= 300 && response.status <= 399) {
|
|
21163
|
+
await releaseResponse(response);
|
|
21164
|
+
terminalStatus = response.status;
|
|
21165
|
+
} else if (response.ok) {
|
|
21197
21166
|
return response;
|
|
21167
|
+
} else {
|
|
21168
|
+
const shouldRetry = response.status === 429 || response.status >= 500;
|
|
21169
|
+
if (shouldRetry && attempt < MAX_RETRIES) {
|
|
21170
|
+
await releaseResponse(response);
|
|
21171
|
+
const retryAfter = response.headers.get("Retry-After");
|
|
21172
|
+
const delay = retryAfter ? parseInt(retryAfter, 10) * 1e3 : calculateRetryDelay(attempt);
|
|
21173
|
+
await sleep(Math.min(delay, 1e4));
|
|
21174
|
+
continue;
|
|
21175
|
+
}
|
|
21176
|
+
await releaseResponse(response);
|
|
21177
|
+
terminalStatus = response.status;
|
|
21198
21178
|
}
|
|
21199
|
-
const shouldRetry = response.status === 429 || response.status >= 500;
|
|
21200
|
-
if (shouldRetry && attempt < MAX_RETRIES) {
|
|
21201
|
-
const retryAfter = response.headers.get("Retry-After");
|
|
21202
|
-
const delay = retryAfter ? parseInt(retryAfter, 10) * 1e3 : calculateRetryDelay(attempt);
|
|
21203
|
-
await sleep(Math.min(delay, 1e4));
|
|
21204
|
-
continue;
|
|
21205
|
-
}
|
|
21206
|
-
const errorText = await response.text().catch(() => "");
|
|
21207
|
-
throw new Error(`HTTP ${response.status}: ${errorText}`);
|
|
21208
21179
|
} catch (e) {
|
|
21180
|
+
clearTimeout(timeoutId);
|
|
21209
21181
|
lastError = e;
|
|
21210
21182
|
if (e instanceof DOMException && e.name === "AbortError") {
|
|
21211
21183
|
throw e;
|
|
@@ -21216,9 +21188,18 @@ async function fetchStreamWithRetry(url, init, signal) {
|
|
|
21216
21188
|
}
|
|
21217
21189
|
throw e;
|
|
21218
21190
|
}
|
|
21191
|
+
if (terminalStatus !== void 0) {
|
|
21192
|
+
throw providerStatusError(terminalStatus);
|
|
21193
|
+
}
|
|
21219
21194
|
}
|
|
21220
21195
|
throw lastError;
|
|
21221
21196
|
}
|
|
21197
|
+
function fetchWithRetry(url, init, signal) {
|
|
21198
|
+
return fetchProvider(url, init, COMPLETE_TIMEOUT, signal);
|
|
21199
|
+
}
|
|
21200
|
+
function fetchStreamWithRetry(url, init, signal) {
|
|
21201
|
+
return fetchProvider(url, init, STREAM_TIMEOUT, signal);
|
|
21202
|
+
}
|
|
21222
21203
|
function sanitizeResponse(text) {
|
|
21223
21204
|
return text;
|
|
21224
21205
|
}
|
package/package.json
CHANGED