import { type ArrayOrValue, type ContentTypeMimeType, type Maybe, type MimeTypeWithoutParameters } from '@dereekb/util'; import { safeParse as parseContentType } from 'fast-content-type-parse'; import { type FetchMethod } from './fetch.type'; /** * Input for makeFileForFetch(). */ export interface MakeFileForFetchInput { /** * File content. Can be a string, ArrayBuffer, Blob, or array of BlobParts. */ readonly content: ArrayOrValue; /** * File name including extension. * * @example 'document.pdf' */ readonly fileName: string; /** * MIME type of the file. * * @example 'application/pdf' */ readonly mimeType?: ContentTypeMimeType; /** * Last modified timestamp in milliseconds. */ readonly lastModified?: number; } /** * Creates a File object from the given input. * * @param input - configuration containing the file content, name, optional MIME type, and last modified timestamp * @returns a File object constructed from the provided input */ export declare function makeFileForFetch(input: MakeFileForFetchInput): File; /** * Input for fetchFileFromUrl(). */ export interface FetchFileFromUrlInput { /** * URL to download the file from. */ readonly url: string; /** * File name to use for the resulting File object. * * If not provided, attempts to derive the name from the URL path or falls back to 'file'. */ readonly fileName?: Maybe; /** * MIME type override. If not provided, uses the Content-Type from the response. */ readonly mimeType?: Maybe; /** * Fetch function to use. Defaults to the global fetch. */ readonly fetch?: Maybe; } /** * Downloads a file from the given URL and returns it as a File object. * * When safe is true, returns undefined instead of throwing on fetch failure. * * @param input - configuration containing the URL, optional file name, MIME type override, and fetch function * @returns the downloaded content as a File object, or undefined in safe mode on failure */ export declare function fetchFileFromUrl(input: FetchFileFromUrlInput): Promise; export declare function fetchFileFromUrl(input: FetchFileFromUrlInput, safe: true): Promise>; export type FetchFileResponseContentType = ReturnType; export interface FetchFileResponse { /** * The raw response from the fetch request. */ readonly response: Response; /** * Raw content type from the response's content-type header. */ readonly rawContentType: Maybe; /** * Parsed content type. Unavailable if the content type could not be parsed. */ readonly contentType: Maybe; /** * Parsed mime type. Unavailable if the content type could not be parsed. */ readonly mimeType: Maybe; } /** * Parses the file response and returns the response wrapped in a FetchFileResponse object. * * @param response * @returns */ export declare function parseFetchFileResponse(response: Response): FetchFileResponse; /** * @deprecated Use makeFileForFetch() with FormData instead. */ export interface FetchUploadFile { readonly url: string; readonly fetch?: typeof fetch; readonly method?: FetchMethod; readonly body: FetchUploadFileBody; } /** * @deprecated Use makeFileForFetch() with FormData instead. */ export interface FetchUploadFileBody { readonly mimeType: ContentTypeMimeType; readonly body: BodyInit; } /** * @deprecated Use makeFileForFetch() with FormData and context.fetch() instead. * * @param input - configuration containing the upload URL, fetch function, HTTP method, and file body * @returns a promise resolving to the fetch Response */ export declare function fetchUploadFile(input: FetchUploadFile): Promise;