{"version":3,"file":"dist-js-BPkxr7Km2.js","names":[],"sources":["../../node_modules/.pnpm/@tauri-apps+plugin-http@2.5.9/node_modules/@tauri-apps/plugin-http/dist-js/index.js"],"sourcesContent":["import { invoke } from '@tauri-apps/api/core';\n\n// Copyright 2019-2023 Tauri Programme within The Commons Conservancy\n// SPDX-License-Identifier: Apache-2.0\n// SPDX-License-Identifier: MIT\n/**\n * Make HTTP requests with the Rust backend.\n *\n * ## Security\n *\n * This API has a scope configuration that forces you to restrict the URLs that can be accessed using glob patterns.\n *\n * For instance, this scope configuration only allows making HTTP requests to all subdomains for `tauri.app` except for `https://private.tauri.app`:\n * ```json\n * {\n *   \"permissions\": [\n *     {\n *       \"identifier\": \"http:default\",\n *       \"allow\": [{ \"url\": \"https://*.tauri.app\" }],\n *       \"deny\": [{ \"url\": \"https://private.tauri.app\" }]\n *     }\n *   ]\n * }\n * ```\n * Trying to execute any API with a URL not configured on the scope results in a promise rejection due to denied access.\n *\n * @module\n */\nconst ERROR_REQUEST_CANCELLED = 'Request cancelled';\n/**\n * Fetch a resource from the network. It returns a `Promise` that resolves to the\n * `Response` to that `Request`, whether it is successful or not.\n *\n * @example\n * ```typescript\n * const response = await fetch(\"http://my.json.host/data.json\");\n * console.log(response.status);  // e.g. 200\n * console.log(response.statusText); // e.g. \"OK\"\n * const jsonData = await response.json();\n * ```\n *\n * @since 2.0.0\n */\nasync function fetch(input, init) {\n    // Optimistically check for abort signal and avoid doing any work\n    const signal = init?.signal;\n    if (signal?.aborted) {\n        throw new Error(ERROR_REQUEST_CANCELLED);\n    }\n    const maxRedirections = init?.maxRedirections;\n    const connectTimeout = init?.connectTimeout;\n    const proxy = init?.proxy;\n    const danger = init?.danger;\n    // Remove these fields before creating the request\n    if (init) {\n        delete init.maxRedirections;\n        delete init.connectTimeout;\n        delete init.proxy;\n        delete init.danger;\n    }\n    const headers = init?.headers\n        ? init.headers instanceof Headers\n            ? init.headers\n            : new Headers(init.headers)\n        : new Headers();\n    const req = new Request(input, init);\n    const buffer = await req.arrayBuffer();\n    const data = buffer.byteLength !== 0 ? Array.from(new Uint8Array(buffer)) : null;\n    // append new headers created by the browser `Request` implementation,\n    // if not already declared by the caller of this function\n    for (const [key, value] of req.headers) {\n        if (!headers.get(key)) {\n            headers.set(key, value);\n        }\n    }\n    const headersArray = headers instanceof Headers\n        ? Array.from(headers.entries())\n        : Array.isArray(headers)\n            ? headers\n            : Object.entries(headers);\n    // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n    const mappedHeaders = headersArray.map(([name, val]) => [\n        name,\n        // we need to ensure we have all header values as strings\n        // eslint-disable-next-line\n        typeof val === 'string' ? val : val.toString()\n    ]);\n    // Optimistically check for abort signal and avoid doing any work on the Rust side\n    if (signal?.aborted) {\n        throw new Error(ERROR_REQUEST_CANCELLED);\n    }\n    const rid = await invoke('plugin:http|fetch', {\n        clientConfig: {\n            method: req.method,\n            url: req.url,\n            headers: mappedHeaders,\n            data,\n            maxRedirections,\n            connectTimeout,\n            proxy,\n            danger\n        }\n    });\n    const abort = () => invoke('plugin:http|fetch_cancel', { rid });\n    // Optimistically check for abort signal\n    // and avoid doing any work after doing intial work on the Rust side\n    if (signal?.aborted) {\n        // we don't care about the result of this proimse\n        // eslint-disable-next-line @typescript-eslint/no-floating-promises\n        abort();\n        throw new Error(ERROR_REQUEST_CANCELLED);\n    }\n    signal?.addEventListener('abort', () => void abort());\n    const { status, statusText, url, headers: responseHeaders, rid: responseRid } = await invoke('plugin:http|fetch_send', {\n        rid\n    });\n    const dropBody = () => {\n        return invoke('plugin:http|fetch_cancel_body', { rid: responseRid });\n    };\n    const readChunk = async (controller) => {\n        let data;\n        try {\n            data = await invoke('plugin:http|fetch_read_body', {\n                rid: responseRid\n            });\n        }\n        catch (e) {\n            // close the stream if an error occurs\n            // and drop the body on Rust side\n            controller.error(e);\n            void dropBody();\n            return;\n        }\n        const dataUint8 = new Uint8Array(data);\n        const lastByte = dataUint8[dataUint8.byteLength - 1];\n        const actualData = dataUint8.slice(0, dataUint8.byteLength - 1);\n        // close when the signal to close (last byte is 1) is sent from the IPC.\n        if (lastByte === 1) {\n            controller.close();\n            return;\n        }\n        controller.enqueue(actualData);\n    };\n    // no body for 101, 103, 204, 205 and 304\n    // see https://fetch.spec.whatwg.org/#null-body-status\n    const body = [101, 103, 204, 205, 304].includes(status)\n        ? null\n        : new ReadableStream({\n            start: (controller) => {\n                // listen for abort events to cancel reading\n                signal?.addEventListener('abort', () => {\n                    controller.error(ERROR_REQUEST_CANCELLED);\n                    void dropBody();\n                });\n            },\n            pull: (controller) => readChunk(controller),\n            cancel: () => {\n                // Ensure body resources are released on stream cancellation\n                void dropBody();\n            }\n        });\n    const res = new Response(body, {\n        status,\n        statusText\n    });\n    // `Response.url` cannot be set via the constructor, so we define it manually\n    Object.defineProperty(res, 'url', { value: url, writable: false });\n    // Expose `set-cookie` via `response.headers` (and `getSetCookie()` where\n    // supported). This is not Fetch-spec compliant for network responses in\n    // browsers, where `set-cookie` is treated as a forbidden response\n    // header and is generally not readable from JavaScript.\n    Object.defineProperty(res, 'headers', {\n        value: new Headers(responseHeaders),\n        writable: false\n    });\n    // Patch clone() per-instance so cloning preserves the overridden properties\n    const originalClone = res.clone.bind(res);\n    Object.defineProperty(res, 'clone', {\n        value: () => {\n            const cloned = originalClone();\n            Object.defineProperty(cloned, 'url', { value: url, writable: false });\n            Object.defineProperty(cloned, 'headers', {\n                value: new Headers(responseHeaders),\n                writable: false\n            });\n            return cloned;\n        }\n    });\n    return res;\n}\n\nexport { fetch };\n"],"x_google_ignoreList":[0],"mappings":"uCA4BA,IAAM,EAA0B,oBAehC,eAAe,EAAM,EAAO,EAAM,CAE9B,IAAM,EAAS,GAAM,OACrB,GAAI,GAAQ,QACR,MAAU,MAAM,CAAuB,EAE3C,IAAM,EAAkB,GAAM,gBACxB,EAAiB,GAAM,eACvB,EAAQ,GAAM,MACd,EAAS,GAAM,OAEjB,IACA,OAAO,EAAK,gBACZ,OAAO,EAAK,eACZ,OA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