1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | import FormData = require("form-data");
|
20 | import { RequestOptions } from "http";
|
21 | import { URL, URLSearchParams } from "url";
|
22 | import { AbortSignal } from "./externals";
|
23 |
|
24 | export class Request extends Body {
|
25 | constructor(input: RequestInfo, init?: RequestInit);
|
26 | clone(): Request;
|
27 | context: RequestContext;
|
28 | headers: Headers;
|
29 | method: string;
|
30 | redirect: RequestRedirect;
|
31 | referrer: string;
|
32 | url: string;
|
33 |
|
34 | // node-fetch extensions to the whatwg/fetch spec
|
35 | agent?: RequestOptions["agent"] | ((parsedUrl: URL) => RequestOptions["agent"]);
|
36 | compress: boolean;
|
37 | counter: number;
|
38 | follow: number;
|
39 | hostname: string;
|
40 | port?: number | undefined;
|
41 | protocol: string;
|
42 | size: number;
|
43 | timeout: number;
|
44 | }
|
45 |
|
46 | export interface RequestInit {
|
47 |
|
48 | body?: BodyInit | undefined;
|
49 | headers?: HeadersInit | undefined;
|
50 | method?: string | undefined;
|
51 | redirect?: RequestRedirect | undefined;
|
52 | signal?: AbortSignal | null | undefined;
|
53 |
|
54 |
|
55 | agent?: RequestOptions["agent"] | ((parsedUrl: URL) => RequestOptions["agent"]); // =null http.Agent instance, allows custom proxy, certificate etc.
|
56 | compress?: boolean | undefined; // =true support gzip/deflate content encoding. false to disable
|
57 | follow?: number | undefined; // =20 maximum redirect count. 0 to not follow redirect
|
58 | size?: number | undefined; // =0 maximum response body size in bytes. 0 to disable
|
59 | timeout?: number | undefined; // =0 req/res timeout in ms, it resets on redirect. 0 to disable (OS limit applies)
|
60 |
|
61 | // node-fetch does not support mode, cache or credentials options
|
62 | }
|
63 |
|
64 | export type RequestContext =
|
65 | | "audio"
|
66 | | "beacon"
|
67 | | "cspreport"
|
68 | | "download"
|
69 | | "embed"
|
70 | | "eventsource"
|
71 | | "favicon"
|
72 | | "fetch"
|
73 | | "font"
|
74 | | "form"
|
75 | | "frame"
|
76 | | "hyperlink"
|
77 | | "iframe"
|
78 | | "image"
|
79 | | "imageset"
|
80 | | "import"
|
81 | | "internal"
|
82 | | "location"
|
83 | | "manifest"
|
84 | | "object"
|
85 | | "ping"
|
86 | | "plugin"
|
87 | | "prefetch"
|
88 | | "script"
|
89 | | "serviceworker"
|
90 | | "sharedworker"
|
91 | | "style"
|
92 | | "subresource"
|
93 | | "track"
|
94 | | "video"
|
95 | | "worker"
|
96 | | "xmlhttprequest"
|
97 | | "xslt";
|
98 | export type RequestMode = "cors" | "no-cors" | "same-origin";
|
99 | export type RequestRedirect = "error" | "follow" | "manual";
|
100 | export type RequestCredentials = "omit" | "include" | "same-origin";
|
101 |
|
102 | export type RequestCache =
|
103 | | "default"
|
104 | | "force-cache"
|
105 | | "no-cache"
|
106 | | "no-store"
|
107 | | "only-if-cached"
|
108 | | "reload";
|
109 |
|
110 | export class Headers implements Iterable<[string, string]> {
|
111 | constructor(init?: HeadersInit);
|
112 | forEach(callback: (value: string, name: string) => void): void;
|
113 | append(name: string, value: string): void;
|
114 | delete(name: string): void;
|
115 | get(name: string): string | null;
|
116 | has(name: string): boolean;
|
117 | raw(): { [k: string]: string[] };
|
118 | set(name: string, value: string): void;
|
119 |
|
120 | // Iterable methods
|
121 | entries(): IterableIterator<[string, string]>;
|
122 | keys(): IterableIterator<string>;
|
123 | values(): IterableIterator<string>;
|
124 | [Symbol.iterator](): Iterator<[string, string]>;
|
125 | }
|
126 |
|
127 | type BlobPart = ArrayBuffer | ArrayBufferView | Blob | string;
|
128 |
|
129 | interface BlobOptions {
|
130 | type?: string | undefined;
|
131 | endings?: "transparent" | "native" | undefined;
|
132 | }
|
133 |
|
134 | export class Blob {
|
135 | constructor(blobParts?: BlobPart[], options?: BlobOptions);
|
136 | readonly type: string;
|
137 | readonly size: number;
|
138 | slice(start?: number, end?: number): Blob;
|
139 | text(): Promise<string>;
|
140 | }
|
141 |
|
142 | export class Body {
|
143 | constructor(body?: any, opts?: { size?: number | undefined; timeout?: number | undefined });
|
144 | arrayBuffer(): Promise<ArrayBuffer>;
|
145 | blob(): Promise<Blob>;
|
146 | body: NodeJS.ReadableStream;
|
147 | bodyUsed: boolean;
|
148 | buffer(): Promise<Buffer>;
|
149 | json(): Promise<any>;
|
150 | size: number;
|
151 | text(): Promise<string>;
|
152 | textConverted(): Promise<string>;
|
153 | timeout: number;
|
154 | }
|
155 |
|
156 | interface SystemError extends Error {
|
157 | code?: string | undefined;
|
158 | }
|
159 |
|
160 | export class FetchError extends Error {
|
161 | name: "FetchError";
|
162 | constructor(message: string, type: string, systemError?: SystemError);
|
163 | type: string;
|
164 | code?: string | undefined;
|
165 | errno?: string | undefined;
|
166 | }
|
167 |
|
168 | export class Response extends Body {
|
169 | constructor(body?: BodyInit, init?: ResponseInit);
|
170 | static error(): Response;
|
171 | static redirect(url: string, status: number): Response;
|
172 | clone(): Response;
|
173 | headers: Headers;
|
174 | ok: boolean;
|
175 | redirected: boolean;
|
176 | status: number;
|
177 | statusText: string;
|
178 | type: ResponseType;
|
179 | url: string;
|
180 | }
|
181 |
|
182 | export type ResponseType =
|
183 | | "basic"
|
184 | | "cors"
|
185 | | "default"
|
186 | | "error"
|
187 | | "opaque"
|
188 | | "opaqueredirect";
|
189 |
|
190 | export interface ResponseInit {
|
191 | headers?: HeadersInit | undefined;
|
192 | size?: number | undefined;
|
193 | status?: number | undefined;
|
194 | statusText?: string | undefined;
|
195 | timeout?: number | undefined;
|
196 | url?: string | undefined;
|
197 | }
|
198 |
|
199 | interface URLLike {
|
200 | href: string;
|
201 | }
|
202 |
|
203 | export type HeadersInit = Headers | string[][] | { [key: string]: string };
|
204 | // HeaderInit is exported to support backwards compatibility. See PR #34382
|
205 | export type HeaderInit = HeadersInit;
|
206 | export type BodyInit =
|
207 | | ArrayBuffer
|
208 | | ArrayBufferView
|
209 | | NodeJS.ReadableStream
|
210 | | string
|
211 | | URLSearchParams
|
212 | | FormData;
|
213 | export type RequestInfo = string | URLLike | Request;
|
214 |
|
215 | declare function fetch(
|
216 | url: RequestInfo,
|
217 | init?: RequestInit,
|
218 | ): Promise<Response>;
|
219 |
|
220 | declare namespace fetch {
|
221 | function isRedirect(code: number): boolean;
|
222 | }
|
223 |
|
224 | export default fetch;
|
225 |
|
\ | No newline at end of file |