import "/node_modules/.vite/deps/chunk-HM4MQYWN.js?v=3c48aa1c";
|
|
// node_modules/ky/distribution/errors/HTTPError.js
|
var HTTPError = class extends Error {
|
constructor(response, request, options) {
|
const code = response.status || response.status === 0 ? response.status : "";
|
const title = response.statusText || "";
|
const status = `${code} ${title}`.trim();
|
const reason = status ? `status code ${status}` : "an unknown error";
|
super(`Request failed with ${reason}`);
|
Object.defineProperty(this, "response", {
|
enumerable: true,
|
configurable: true,
|
writable: true,
|
value: void 0
|
});
|
Object.defineProperty(this, "request", {
|
enumerable: true,
|
configurable: true,
|
writable: true,
|
value: void 0
|
});
|
Object.defineProperty(this, "options", {
|
enumerable: true,
|
configurable: true,
|
writable: true,
|
value: void 0
|
});
|
this.name = "HTTPError";
|
this.response = response;
|
this.request = request;
|
this.options = options;
|
}
|
};
|
|
// node_modules/ky/distribution/errors/TimeoutError.js
|
var TimeoutError = class extends Error {
|
constructor(request) {
|
super("Request timed out");
|
Object.defineProperty(this, "request", {
|
enumerable: true,
|
configurable: true,
|
writable: true,
|
value: void 0
|
});
|
this.name = "TimeoutError";
|
this.request = request;
|
}
|
};
|
|
// node_modules/ky/distribution/utils/is.js
|
var isObject = (value) => value !== null && typeof value === "object";
|
|
// node_modules/ky/distribution/utils/merge.js
|
var validateAndMerge = (...sources) => {
|
for (const source of sources) {
|
if ((!isObject(source) || Array.isArray(source)) && source !== void 0) {
|
throw new TypeError("The `options` argument must be an object");
|
}
|
}
|
return deepMerge({}, ...sources);
|
};
|
var mergeHeaders = (source1 = {}, source2 = {}) => {
|
const result = new globalThis.Headers(source1);
|
const isHeadersInstance = source2 instanceof globalThis.Headers;
|
const source = new globalThis.Headers(source2);
|
for (const [key, value] of source.entries()) {
|
if (isHeadersInstance && value === "undefined" || value === void 0) {
|
result.delete(key);
|
} else {
|
result.set(key, value);
|
}
|
}
|
return result;
|
};
|
var deepMerge = (...sources) => {
|
let returnValue = {};
|
let headers = {};
|
for (const source of sources) {
|
if (Array.isArray(source)) {
|
if (!Array.isArray(returnValue)) {
|
returnValue = [];
|
}
|
returnValue = [...returnValue, ...source];
|
} else if (isObject(source)) {
|
for (let [key, value] of Object.entries(source)) {
|
if (isObject(value) && key in returnValue) {
|
value = deepMerge(returnValue[key], value);
|
}
|
returnValue = { ...returnValue, [key]: value };
|
}
|
if (isObject(source.headers)) {
|
headers = mergeHeaders(headers, source.headers);
|
returnValue.headers = headers;
|
}
|
}
|
}
|
return returnValue;
|
};
|
|
// node_modules/ky/distribution/core/constants.js
|
var supportsRequestStreams = (() => {
|
let duplexAccessed = false;
|
let hasContentType = false;
|
const supportsReadableStream = typeof globalThis.ReadableStream === "function";
|
const supportsRequest = typeof globalThis.Request === "function";
|
if (supportsReadableStream && supportsRequest) {
|
hasContentType = new globalThis.Request("https://empty.invalid", {
|
body: new globalThis.ReadableStream(),
|
method: "POST",
|
// @ts-expect-error - Types are outdated.
|
get duplex() {
|
duplexAccessed = true;
|
return "half";
|
}
|
}).headers.has("Content-Type");
|
}
|
return duplexAccessed && !hasContentType;
|
})();
|
var supportsAbortController = typeof globalThis.AbortController === "function";
|
var supportsResponseStreams = typeof globalThis.ReadableStream === "function";
|
var supportsFormData = typeof globalThis.FormData === "function";
|
var requestMethods = ["get", "post", "put", "patch", "head", "delete"];
|
var validate = () => void 0;
|
validate();
|
var responseTypes = {
|
json: "application/json",
|
text: "text/*",
|
formData: "multipart/form-data",
|
arrayBuffer: "*/*",
|
blob: "*/*"
|
};
|
var maxSafeTimeout = 2147483647;
|
var stop = Symbol("stop");
|
|
// node_modules/ky/distribution/utils/normalize.js
|
var normalizeRequestMethod = (input) => requestMethods.includes(input) ? input.toUpperCase() : input;
|
var retryMethods = ["get", "put", "head", "delete", "options", "trace"];
|
var retryStatusCodes = [408, 413, 429, 500, 502, 503, 504];
|
var retryAfterStatusCodes = [413, 429, 503];
|
var defaultRetryOptions = {
|
limit: 2,
|
methods: retryMethods,
|
statusCodes: retryStatusCodes,
|
afterStatusCodes: retryAfterStatusCodes,
|
maxRetryAfter: Number.POSITIVE_INFINITY,
|
backoffLimit: Number.POSITIVE_INFINITY
|
};
|
var normalizeRetryOptions = (retry = {}) => {
|
if (typeof retry === "number") {
|
return {
|
...defaultRetryOptions,
|
limit: retry
|
};
|
}
|
if (retry.methods && !Array.isArray(retry.methods)) {
|
throw new Error("retry.methods must be an array");
|
}
|
if (retry.statusCodes && !Array.isArray(retry.statusCodes)) {
|
throw new Error("retry.statusCodes must be an array");
|
}
|
return {
|
...defaultRetryOptions,
|
...retry,
|
afterStatusCodes: retryAfterStatusCodes
|
};
|
};
|
|
// node_modules/ky/distribution/utils/timeout.js
|
async function timeout(request, abortController, options) {
|
return new Promise((resolve, reject) => {
|
const timeoutId = setTimeout(() => {
|
if (abortController) {
|
abortController.abort();
|
}
|
reject(new TimeoutError(request));
|
}, options.timeout);
|
void options.fetch(request).then(resolve).catch(reject).then(() => {
|
clearTimeout(timeoutId);
|
});
|
});
|
}
|
|
// node_modules/ky/distribution/utils/delay.js
|
async function delay(ms, { signal }) {
|
return new Promise((resolve, reject) => {
|
if (signal) {
|
signal.throwIfAborted();
|
signal.addEventListener("abort", abortHandler, { once: true });
|
}
|
function abortHandler() {
|
clearTimeout(timeoutId);
|
reject(signal.reason);
|
}
|
const timeoutId = setTimeout(() => {
|
signal == null ? void 0 : signal.removeEventListener("abort", abortHandler);
|
resolve();
|
}, ms);
|
});
|
}
|
|
// node_modules/ky/distribution/core/Ky.js
|
var Ky = class _Ky {
|
static create(input, options) {
|
const ky2 = new _Ky(input, options);
|
const fn = async () => {
|
if (typeof ky2._options.timeout === "number" && ky2._options.timeout > maxSafeTimeout) {
|
throw new RangeError(`The \`timeout\` option cannot be greater than ${maxSafeTimeout}`);
|
}
|
await Promise.resolve();
|
let response = await ky2._fetch();
|
for (const hook of ky2._options.hooks.afterResponse) {
|
const modifiedResponse = await hook(ky2.request, ky2._options, ky2._decorateResponse(response.clone()));
|
if (modifiedResponse instanceof globalThis.Response) {
|
response = modifiedResponse;
|
}
|
}
|
ky2._decorateResponse(response);
|
if (!response.ok && ky2._options.throwHttpErrors) {
|
let error = new HTTPError(response, ky2.request, ky2._options);
|
for (const hook of ky2._options.hooks.beforeError) {
|
error = await hook(error);
|
}
|
throw error;
|
}
|
if (ky2._options.onDownloadProgress) {
|
if (typeof ky2._options.onDownloadProgress !== "function") {
|
throw new TypeError("The `onDownloadProgress` option must be a function");
|
}
|
if (!supportsResponseStreams) {
|
throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");
|
}
|
return ky2._stream(response.clone(), ky2._options.onDownloadProgress);
|
}
|
return response;
|
};
|
const isRetriableMethod = ky2._options.retry.methods.includes(ky2.request.method.toLowerCase());
|
const result = isRetriableMethod ? ky2._retry(fn) : fn();
|
for (const [type, mimeType] of Object.entries(responseTypes)) {
|
result[type] = async () => {
|
ky2.request.headers.set("accept", ky2.request.headers.get("accept") || mimeType);
|
const awaitedResult = await result;
|
const response = awaitedResult.clone();
|
if (type === "json") {
|
if (response.status === 204) {
|
return "";
|
}
|
const arrayBuffer = await response.clone().arrayBuffer();
|
const responseSize = arrayBuffer.byteLength;
|
if (responseSize === 0) {
|
return "";
|
}
|
if (options.parseJson) {
|
return options.parseJson(await response.text());
|
}
|
}
|
return response[type]();
|
};
|
}
|
return result;
|
}
|
// eslint-disable-next-line complexity
|
constructor(input, options = {}) {
|
Object.defineProperty(this, "request", {
|
enumerable: true,
|
configurable: true,
|
writable: true,
|
value: void 0
|
});
|
Object.defineProperty(this, "abortController", {
|
enumerable: true,
|
configurable: true,
|
writable: true,
|
value: void 0
|
});
|
Object.defineProperty(this, "_retryCount", {
|
enumerable: true,
|
configurable: true,
|
writable: true,
|
value: 0
|
});
|
Object.defineProperty(this, "_input", {
|
enumerable: true,
|
configurable: true,
|
writable: true,
|
value: void 0
|
});
|
Object.defineProperty(this, "_options", {
|
enumerable: true,
|
configurable: true,
|
writable: true,
|
value: void 0
|
});
|
this._input = input;
|
this._options = {
|
// TODO: credentials can be removed when the spec change is implemented in all browsers. Context: https://www.chromestatus.com/feature/4539473312350208
|
credentials: this._input.credentials || "same-origin",
|
...options,
|
headers: mergeHeaders(this._input.headers, options.headers),
|
hooks: deepMerge({
|
beforeRequest: [],
|
beforeRetry: [],
|
beforeError: [],
|
afterResponse: []
|
}, options.hooks),
|
method: normalizeRequestMethod(options.method ?? this._input.method),
|
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
prefixUrl: String(options.prefixUrl || ""),
|
retry: normalizeRetryOptions(options.retry),
|
throwHttpErrors: options.throwHttpErrors !== false,
|
timeout: options.timeout ?? 1e4,
|
fetch: options.fetch ?? globalThis.fetch.bind(globalThis)
|
};
|
if (typeof this._input !== "string" && !(this._input instanceof URL || this._input instanceof globalThis.Request)) {
|
throw new TypeError("`input` must be a string, URL, or Request");
|
}
|
if (this._options.prefixUrl && typeof this._input === "string") {
|
if (this._input.startsWith("/")) {
|
throw new Error("`input` must not begin with a slash when using `prefixUrl`");
|
}
|
if (!this._options.prefixUrl.endsWith("/")) {
|
this._options.prefixUrl += "/";
|
}
|
this._input = this._options.prefixUrl + this._input;
|
}
|
if (supportsAbortController) {
|
this.abortController = new globalThis.AbortController();
|
if (this._options.signal) {
|
const originalSignal = this._options.signal;
|
this._options.signal.addEventListener("abort", () => {
|
this.abortController.abort(originalSignal.reason);
|
});
|
}
|
this._options.signal = this.abortController.signal;
|
}
|
if (supportsRequestStreams) {
|
this._options.duplex = "half";
|
}
|
this.request = new globalThis.Request(this._input, this._options);
|
if (this._options.searchParams) {
|
const textSearchParams = typeof this._options.searchParams === "string" ? this._options.searchParams.replace(/^\?/, "") : new URLSearchParams(this._options.searchParams).toString();
|
const searchParams = "?" + textSearchParams;
|
const url = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, searchParams);
|
if ((supportsFormData && this._options.body instanceof globalThis.FormData || this._options.body instanceof URLSearchParams) && !(this._options.headers && this._options.headers["content-type"])) {
|
this.request.headers.delete("content-type");
|
}
|
this.request = new globalThis.Request(new globalThis.Request(url, { ...this.request }), this._options);
|
}
|
if (this._options.json !== void 0) {
|
this._options.body = JSON.stringify(this._options.json);
|
this.request.headers.set("content-type", this._options.headers.get("content-type") ?? "application/json");
|
this.request = new globalThis.Request(this.request, { body: this._options.body });
|
}
|
}
|
_calculateRetryDelay(error) {
|
this._retryCount++;
|
if (this._retryCount < this._options.retry.limit && !(error instanceof TimeoutError)) {
|
if (error instanceof HTTPError) {
|
if (!this._options.retry.statusCodes.includes(error.response.status)) {
|
return 0;
|
}
|
const retryAfter = error.response.headers.get("Retry-After");
|
if (retryAfter && this._options.retry.afterStatusCodes.includes(error.response.status)) {
|
let after = Number(retryAfter);
|
if (Number.isNaN(after)) {
|
after = Date.parse(retryAfter) - Date.now();
|
} else {
|
after *= 1e3;
|
}
|
if (this._options.retry.maxRetryAfter !== void 0 && after > this._options.retry.maxRetryAfter) {
|
return 0;
|
}
|
return after;
|
}
|
if (error.response.status === 413) {
|
return 0;
|
}
|
}
|
const BACKOFF_FACTOR = 0.3;
|
return Math.min(this._options.retry.backoffLimit, BACKOFF_FACTOR * 2 ** (this._retryCount - 1) * 1e3);
|
}
|
return 0;
|
}
|
_decorateResponse(response) {
|
if (this._options.parseJson) {
|
response.json = async () => this._options.parseJson(await response.text());
|
}
|
return response;
|
}
|
async _retry(fn) {
|
try {
|
return await fn();
|
} catch (error) {
|
const ms = Math.min(this._calculateRetryDelay(error), maxSafeTimeout);
|
if (ms !== 0 && this._retryCount > 0) {
|
await delay(ms, { signal: this._options.signal });
|
for (const hook of this._options.hooks.beforeRetry) {
|
const hookResult = await hook({
|
request: this.request,
|
options: this._options,
|
error,
|
retryCount: this._retryCount
|
});
|
if (hookResult === stop) {
|
return;
|
}
|
}
|
return this._retry(fn);
|
}
|
throw error;
|
}
|
}
|
async _fetch() {
|
for (const hook of this._options.hooks.beforeRequest) {
|
const result = await hook(this.request, this._options);
|
if (result instanceof Request) {
|
this.request = result;
|
break;
|
}
|
if (result instanceof Response) {
|
return result;
|
}
|
}
|
if (this._options.timeout === false) {
|
return this._options.fetch(this.request.clone());
|
}
|
return timeout(this.request.clone(), this.abortController, this._options);
|
}
|
/* istanbul ignore next */
|
_stream(response, onDownloadProgress) {
|
const totalBytes = Number(response.headers.get("content-length")) || 0;
|
let transferredBytes = 0;
|
if (response.status === 204) {
|
if (onDownloadProgress) {
|
onDownloadProgress({ percent: 1, totalBytes, transferredBytes }, new Uint8Array());
|
}
|
return new globalThis.Response(null, {
|
status: response.status,
|
statusText: response.statusText,
|
headers: response.headers
|
});
|
}
|
return new globalThis.Response(new globalThis.ReadableStream({
|
async start(controller) {
|
const reader = response.body.getReader();
|
if (onDownloadProgress) {
|
onDownloadProgress({ percent: 0, transferredBytes: 0, totalBytes }, new Uint8Array());
|
}
|
async function read() {
|
const { done, value } = await reader.read();
|
if (done) {
|
controller.close();
|
return;
|
}
|
if (onDownloadProgress) {
|
transferredBytes += value.byteLength;
|
const percent = totalBytes === 0 ? 0 : transferredBytes / totalBytes;
|
onDownloadProgress({ percent, transferredBytes, totalBytes }, value);
|
}
|
controller.enqueue(value);
|
await read();
|
}
|
await read();
|
}
|
}), {
|
status: response.status,
|
statusText: response.statusText,
|
headers: response.headers
|
});
|
}
|
};
|
|
// node_modules/ky/distribution/index.js
|
var createInstance = (defaults) => {
|
const ky2 = (input, options) => Ky.create(input, validateAndMerge(defaults, options));
|
for (const method of requestMethods) {
|
ky2[method] = (input, options) => Ky.create(input, validateAndMerge(defaults, options, { method }));
|
}
|
ky2.create = (newDefaults) => createInstance(validateAndMerge(newDefaults));
|
ky2.extend = (newDefaults) => createInstance(validateAndMerge(defaults, newDefaults));
|
ky2.stop = stop;
|
return ky2;
|
};
|
var ky = createInstance();
|
var distribution_default = ky;
|
export {
|
HTTPError,
|
TimeoutError,
|
distribution_default as default
|
};
|
/*! Bundled license information:
|
|
ky/distribution/index.js:
|
(*! MIT License © Sindre Sorhus *)
|
*/
|
//# sourceMappingURL=ky.js.map
|