// based on https://github.com/Ethan-Arrowood/undici-fetch/blob/249269714db874351589d2d364a0645d5160ae71/index.d.ts (MIT license)
// and https://github.com/node-fetch/node-fetch/blob/914ce6be5ec67a8bab63d68510aabf07cb818b6d/index.d.ts (MIT license)
///
import { Blob } from 'buffer'
import { URL, URLSearchParams } from 'url'
import { FormData } from './formdata'
export type RequestInfo = string | URL | Request
export declare function fetch (
input: RequestInfo,
init?: RequestInit
): Promise
declare class ControlledAsyncIterable implements AsyncIterable {
constructor (input: AsyncIterable | Iterable)
data: AsyncIterable
disturbed: boolean
readonly [Symbol.asyncIterator]: () => AsyncIterator
}
export type BodyInit =
| ArrayBuffer
| AsyncIterable
| Blob
| FormData
| Iterable
| NodeJS.ArrayBufferView
| URLSearchParams
| null
| string
export interface BodyMixin {
readonly body: ControlledAsyncIterable | null
readonly bodyUsed: boolean
readonly arrayBuffer: () => Promise
readonly blob: () => Promise
readonly formData: () => Promise
readonly json: () => Promise
readonly text: () => Promise
}
export type HeadersInit = string[][] | Record> | Headers
export declare class Headers implements Iterable<[string, string]> {
constructor (init?: HeadersInit)
readonly append: (name: string, value: string) => void
readonly delete: (name: string) => void
readonly get: (name: string) => string | null
readonly has: (name: string) => boolean
readonly set: (name: string, value: string) => void
readonly forEach: (
callbackfn: (value: string, key: string, iterable: Headers) => void,
thisArg?: unknown
) => void
readonly keys: () => IterableIterator
readonly values: () => IterableIterator
readonly entries: () => IterableIterator<[string, string]>
readonly [Symbol.iterator]: () => Iterator<[string, string]>
}
export type RequestCache =
| 'default'
| 'force-cache'
| 'no-cache'
| 'no-store'
| 'only-if-cached'
| 'reload'
export type RequestCredentials = 'omit' | 'include' | 'same-origin'
type RequestDestination =
| ''
| 'audio'
| 'audioworklet'
| 'document'
| 'embed'
| 'font'
| 'image'
| 'manifest'
| 'object'
| 'paintworklet'
| 'report'
| 'script'
| 'sharedworker'
| 'style'
| 'track'
| 'video'
| 'worker'
| 'xslt'
export interface RequestInit {
readonly method?: string
readonly keepalive?: boolean
readonly headers?: HeadersInit
readonly body?: BodyInit
readonly redirect?: RequestRedirect
readonly integrity?: string
readonly signal?: AbortSignal
readonly credentials?: RequestCredentials
readonly mode?: RequestMode
readonly referrer?: string
readonly referrerPolicy?: ReferrerPolicy
readonly window?: null
}
export type ReferrerPolicy =
| ''
| 'no-referrer'
| 'no-referrer-when-downgrade'
| 'origin'
| 'origin-when-cross-origin'
| 'same-origin'
| 'strict-origin'
| 'strict-origin-when-cross-origin'
| 'unsafe-url';
export type RequestMode = 'cors' | 'navigate' | 'no-cors' | 'same-origin'
export type RequestRedirect = 'error' | 'follow' | 'manual'
export declare class Request implements BodyMixin {
constructor (input: RequestInfo, init?: RequestInit)
readonly cache: RequestCache
readonly credentials: RequestCredentials
readonly destination: RequestDestination
readonly headers: Headers
readonly integrity: string
readonly method: string
readonly mode: RequestMode
readonly redirect: RequestRedirect
readonly referrerPolicy: string
readonly url: string
readonly keepalive: boolean
readonly signal: AbortSignal
readonly body: ControlledAsyncIterable | null
readonly bodyUsed: boolean
readonly arrayBuffer: () => Promise
readonly blob: () => Promise
readonly formData: () => Promise
readonly json: () => Promise
readonly text: () => Promise
readonly clone: () => Request
}
export interface ResponseInit {
readonly status?: number
readonly statusText?: string
readonly headers?: HeadersInit
}
export type ResponseType =
| 'basic'
| 'cors'
| 'default'
| 'error'
| 'opaque'
| 'opaqueredirect'
export type ResponseRedirectStatus = 301 | 302 | 303 | 307 | 308
export declare class Response implements BodyMixin {
constructor (body?: BodyInit, init?: ResponseInit)
readonly headers: Headers
readonly ok: boolean
readonly status: number
readonly statusText: string
readonly type: ResponseType
readonly url: string
readonly redirected: boolean
readonly body: ControlledAsyncIterable | null
readonly bodyUsed: boolean
readonly arrayBuffer: () => Promise
readonly blob: () => Promise
readonly formData: () => Promise
readonly json: () => Promise
readonly text: () => Promise
readonly clone: () => Response
static error (): Response
static redirect (url: string | URL, status: ResponseRedirectStatus): Response
}