@whatwg-node/fetch 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/create-node-ponyfill.js +281 -0
- package/dist/deno-ponyfill.ts +28 -0
- package/dist/getFormDataMethod.js +59 -0
- package/dist/global-ponyfill.js +13 -0
- package/dist/handle-file-request.js +7 -0
- package/dist/index.d.ts +60 -0
- package/dist/node-ponyfill.js +17 -0
- package/package.json +32 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
const handleFileRequest = require("./handle-file-request");
|
|
2
|
+
|
|
3
|
+
module.exports = function createNodePonyfill(opts = {}) {
|
|
4
|
+
const ponyfills = {};
|
|
5
|
+
|
|
6
|
+
if (!opts.useNodeFetch) {
|
|
7
|
+
ponyfills.fetch = globalThis.fetch; // To enable: import {fetch} from 'cross-fetch'
|
|
8
|
+
ponyfills.Headers = globalThis.Headers;
|
|
9
|
+
ponyfills.Request = globalThis.Request;
|
|
10
|
+
ponyfills.Response = globalThis.Response;
|
|
11
|
+
ponyfills.FormData = globalThis.FormData;
|
|
12
|
+
ponyfills.File = globalThis.File;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
ponyfills.AbortController = globalThis.AbortController;
|
|
16
|
+
ponyfills.ReadableStream = globalThis.ReadableStream;
|
|
17
|
+
ponyfills.WritableStream = globalThis.WritableStream;
|
|
18
|
+
ponyfills.TransformStream = globalThis.TransformStream;
|
|
19
|
+
ponyfills.Blob = globalThis.Blob;
|
|
20
|
+
ponyfills.crypto = globalThis.crypto;
|
|
21
|
+
|
|
22
|
+
if (!ponyfills.AbortController) {
|
|
23
|
+
const abortControllerModule = require("abort-controller");
|
|
24
|
+
ponyfills.AbortController =
|
|
25
|
+
abortControllerModule.default || abortControllerModule;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (!ponyfills.Blob) {
|
|
29
|
+
const bufferModule = require('buffer')
|
|
30
|
+
ponyfills.Blob = bufferModule.Blob;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (!ponyfills.Blob) {
|
|
34
|
+
const formDataModule = require("formdata-node");
|
|
35
|
+
ponyfills.Blob = formDataModule.Blob
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!ponyfills.ReadableStream) {
|
|
39
|
+
try {
|
|
40
|
+
const streamsWeb = require("stream/web");
|
|
41
|
+
|
|
42
|
+
ponyfills.ReadableStream = streamsWeb.ReadableStream;
|
|
43
|
+
ponyfills.WritableStream = streamsWeb.WritableStream;
|
|
44
|
+
ponyfills.TransformStream = streamsWeb.TransformStream;
|
|
45
|
+
} catch (e) {
|
|
46
|
+
const streamsWeb = require("web-streams-polyfill/ponyfill");
|
|
47
|
+
ponyfills.ReadableStream = streamsWeb.ReadableStream;
|
|
48
|
+
ponyfills.WritableStream = streamsWeb.WritableStream;
|
|
49
|
+
ponyfills.TransformStream = streamsWeb.TransformStream;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// ReadableStream doesn't handle aborting properly, so we need to patch it
|
|
54
|
+
ponyfills.ReadableStream = class PonyfillReadableStream extends ponyfills.ReadableStream {
|
|
55
|
+
constructor(underlyingSource, ...opts) {
|
|
56
|
+
super({
|
|
57
|
+
...underlyingSource,
|
|
58
|
+
cancel: (e) => {
|
|
59
|
+
this.cancelled = true;
|
|
60
|
+
if (underlyingSource.cancel) {
|
|
61
|
+
return underlyingSource.cancel(e);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}, ...opts);
|
|
65
|
+
this.underlyingSource = underlyingSource;
|
|
66
|
+
}
|
|
67
|
+
[Symbol.asyncIterator]() {
|
|
68
|
+
const asyncIterator = super[Symbol.asyncIterator]();
|
|
69
|
+
return {
|
|
70
|
+
next: (...args) => asyncIterator.next(...args),
|
|
71
|
+
throw: (...args) => asyncIterator.throw(...args),
|
|
72
|
+
return: async (e) => {
|
|
73
|
+
const originalResult = await asyncIterator.return(e);
|
|
74
|
+
if (!this.cancelled) {
|
|
75
|
+
this.cancelled = true;
|
|
76
|
+
if (this.underlyingSource.cancel) {
|
|
77
|
+
await this.underlyingSource.cancel(e);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return originalResult;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async cancel(e) {
|
|
85
|
+
const originalResult = !super.locked && await super.cancel(e);
|
|
86
|
+
if (!this.cancelled) {
|
|
87
|
+
this.cancelled = true;
|
|
88
|
+
if (this.underlyingSource.cancel) {
|
|
89
|
+
await this.underlyingSource.cancel(e);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return originalResult;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (!ponyfills.crypto) {
|
|
97
|
+
const cryptoModule = require("crypto");
|
|
98
|
+
ponyfills.crypto = cryptoModule.webcrypto;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// If any of classes of Fetch API is missing, we need to ponyfill them.
|
|
102
|
+
if (!ponyfills.fetch ||
|
|
103
|
+
!ponyfills.Request ||
|
|
104
|
+
!ponyfills.Headers ||
|
|
105
|
+
!ponyfills.Response ||
|
|
106
|
+
!ponyfills.FormData ||
|
|
107
|
+
!ponyfills.File ||
|
|
108
|
+
opts.useNodeFetch) {
|
|
109
|
+
|
|
110
|
+
const [
|
|
111
|
+
nodeMajorStr,
|
|
112
|
+
nodeMinorStr
|
|
113
|
+
] = process.versions.node.split('.');
|
|
114
|
+
|
|
115
|
+
const nodeMajor = parseInt(nodeMajorStr);
|
|
116
|
+
const nodeMinor = parseInt(nodeMinorStr);
|
|
117
|
+
const getFormDataMethod = require('./getFormDataMethod');
|
|
118
|
+
|
|
119
|
+
if (!opts.useNodeFetch && (nodeMajor > 16 || (nodeMajor === 16 && nodeMinor >= 5))) {
|
|
120
|
+
const undici = require("undici");
|
|
121
|
+
|
|
122
|
+
if (!ponyfills.Headers) {
|
|
123
|
+
ponyfills.Headers = undici.Headers;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const streams = require("stream");
|
|
127
|
+
|
|
128
|
+
const OriginalRequest = ponyfills.Request || undici.Request;
|
|
129
|
+
|
|
130
|
+
class Request extends OriginalRequest {
|
|
131
|
+
constructor(requestOrUrl, options) {
|
|
132
|
+
if (typeof requestOrUrl === "string") {
|
|
133
|
+
options = options || {};
|
|
134
|
+
if (options.body != null && options.body.read && options.body.on) {
|
|
135
|
+
const readable = options.body;
|
|
136
|
+
options.body = new ponyfills.ReadableStream({
|
|
137
|
+
pull(controller) {
|
|
138
|
+
const chunk = readable.read();
|
|
139
|
+
if (chunk != null) {
|
|
140
|
+
controller.enqueue(chunk);
|
|
141
|
+
} else {
|
|
142
|
+
controller.close();
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
close(e) {
|
|
146
|
+
readable.destroy(e);
|
|
147
|
+
}
|
|
148
|
+
})
|
|
149
|
+
}
|
|
150
|
+
super(requestOrUrl, options);
|
|
151
|
+
const contentType = this.headers.get("content-type");
|
|
152
|
+
if (contentType && contentType.startsWith("multipart/form-data")) {
|
|
153
|
+
this.headers.set("content-type", contentType.split(', ')[0]);
|
|
154
|
+
}
|
|
155
|
+
} else {
|
|
156
|
+
super(requestOrUrl);
|
|
157
|
+
}
|
|
158
|
+
this.formData = getFormDataMethod(undici.File, opts.formDataLimits);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
ponyfills.Request = Request;
|
|
163
|
+
|
|
164
|
+
const originalFetch = ponyfills.fetch || undici.fetch;
|
|
165
|
+
|
|
166
|
+
const fetch = function (requestOrUrl, options) {
|
|
167
|
+
if (typeof requestOrUrl === "string") {
|
|
168
|
+
return fetch(new Request(requestOrUrl, options));
|
|
169
|
+
}
|
|
170
|
+
if (requestOrUrl.url.startsWith('file:')) {
|
|
171
|
+
return handleFileRequest(requestOrUrl.url, ponyfills.Response);
|
|
172
|
+
}
|
|
173
|
+
return originalFetch(requestOrUrl);
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
ponyfills.fetch = fetch;
|
|
177
|
+
|
|
178
|
+
if (!ponyfills.Response) {
|
|
179
|
+
ponyfills.Response = undici.Response;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (!ponyfills.FormData) {
|
|
183
|
+
ponyfills.FormData = undici.FormData;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (!ponyfills.File) {
|
|
187
|
+
ponyfills.File = undici.File
|
|
188
|
+
}
|
|
189
|
+
} else {
|
|
190
|
+
const nodeFetch = require("node-fetch");
|
|
191
|
+
const realFetch = ponyfills.fetch || nodeFetch.default || nodeFetch;
|
|
192
|
+
if (!ponyfills.Headers) {
|
|
193
|
+
ponyfills.Headers = nodeFetch.Headers;
|
|
194
|
+
// Sveltekit
|
|
195
|
+
if (globalThis.Headers) {
|
|
196
|
+
Object.defineProperty(globalThis.Headers, Symbol.hasInstance, {
|
|
197
|
+
value(obj) {
|
|
198
|
+
return obj.get && obj.set && obj.delete && obj.has && obj.append;
|
|
199
|
+
},
|
|
200
|
+
configurable: true,
|
|
201
|
+
})
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
const formDataEncoderModule = require("form-data-encoder");
|
|
205
|
+
const streams = require("stream");
|
|
206
|
+
const formDataModule = require("formdata-node");
|
|
207
|
+
if (!ponyfills.FormData) {
|
|
208
|
+
ponyfills.FormData = formDataModule.FormData
|
|
209
|
+
}
|
|
210
|
+
if (!ponyfills.File) {
|
|
211
|
+
ponyfills.File = formDataModule.File
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const OriginalRequest = ponyfills.Request || nodeFetch.Request;
|
|
215
|
+
|
|
216
|
+
class Request extends OriginalRequest {
|
|
217
|
+
constructor(requestOrUrl, options) {
|
|
218
|
+
if (typeof requestOrUrl === "string") {
|
|
219
|
+
// Support schemaless URIs on the server for parity with the browser.
|
|
220
|
+
// Ex: //github.com/ -> https://github.com/
|
|
221
|
+
if (/^\/\//.test(requestOrUrl)) {
|
|
222
|
+
requestOrUrl = "https:" + requestOrUrl;
|
|
223
|
+
}
|
|
224
|
+
options = options || {};
|
|
225
|
+
options.headers = new ponyfills.Headers(options.headers || {});
|
|
226
|
+
options.headers.set('Connection', 'keep-alive');
|
|
227
|
+
if (options.body != null) {
|
|
228
|
+
if (options.body[Symbol.toStringTag] === 'FormData') {
|
|
229
|
+
const encoder = new formDataEncoderModule.FormDataEncoder(options.body)
|
|
230
|
+
for (const headerKey in encoder.headers) {
|
|
231
|
+
options.headers.set(headerKey, encoder.headers[headerKey])
|
|
232
|
+
}
|
|
233
|
+
options.body = streams.Readable.from(encoder.encode());
|
|
234
|
+
}
|
|
235
|
+
if (options.body[Symbol.toStringTag] === 'ReadableStream') {
|
|
236
|
+
options.body = streams.Readable.fromWeb ? streams.Readable.fromWeb(options.body) : streams.Readable.from(options.body);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
super(requestOrUrl, options);
|
|
240
|
+
} else {
|
|
241
|
+
super(requestOrUrl);
|
|
242
|
+
}
|
|
243
|
+
this.formData = getFormDataMethod(formDataModule.File, opts.formDataLimits);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
ponyfills.Request = Request;
|
|
247
|
+
const fetch = function (requestOrUrl, options) {
|
|
248
|
+
if (typeof requestOrUrl === "string") {
|
|
249
|
+
return fetch(new Request(requestOrUrl, options));
|
|
250
|
+
}
|
|
251
|
+
if (requestOrUrl.url.startsWith('file:')) {
|
|
252
|
+
return handleFileRequest(requestOrUrl.url, ponyfills.Response);
|
|
253
|
+
}
|
|
254
|
+
return realFetch(requestOrUrl);
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
ponyfills.fetch = fetch;
|
|
258
|
+
|
|
259
|
+
const OriginalResponse = ponyfills.Response || nodeFetch.Response;
|
|
260
|
+
ponyfills.Response = function Response(body, init) {
|
|
261
|
+
if (body != null && body[Symbol.toStringTag] === 'ReadableStream') {
|
|
262
|
+
const actualBody = streams.Readable.fromWeb ? streams.Readable.fromWeb(body) : streams.Readable.from(body, {
|
|
263
|
+
emitClose: true,
|
|
264
|
+
autoDestroy: true,
|
|
265
|
+
});
|
|
266
|
+
actualBody.on('pause', () => {
|
|
267
|
+
body.cancel();
|
|
268
|
+
})
|
|
269
|
+
actualBody.on('close', () => {
|
|
270
|
+
body.cancel();
|
|
271
|
+
})
|
|
272
|
+
// Polyfill ReadableStream is not working well with node-fetch's Response
|
|
273
|
+
return new OriginalResponse(actualBody, init);
|
|
274
|
+
}
|
|
275
|
+
return new OriginalResponse(body, init);
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
return ponyfills;
|
|
281
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const fetch = globalThis.fetch;
|
|
2
|
+
const Request = globalThis.Request;
|
|
3
|
+
const Response = globalThis.Response;
|
|
4
|
+
const Headers = globalThis.Headers;
|
|
5
|
+
const FormData = globalThis.FormData;
|
|
6
|
+
const AbortController = globalThis.AbortController;
|
|
7
|
+
const ReadableStream = globalThis.ReadableStream;
|
|
8
|
+
const WritableStream = globalThis.WritableStream;
|
|
9
|
+
const TransformStream = globalThis.TransformStream;
|
|
10
|
+
const Blob = globalThis.Blob;
|
|
11
|
+
const File = globalThis.File;
|
|
12
|
+
const crypto = globalThis.crypto;
|
|
13
|
+
|
|
14
|
+
export const create = () => globalThis;
|
|
15
|
+
export {
|
|
16
|
+
fetch,
|
|
17
|
+
Headers,
|
|
18
|
+
Request,
|
|
19
|
+
Response,
|
|
20
|
+
FormData,
|
|
21
|
+
AbortController,
|
|
22
|
+
ReadableStream,
|
|
23
|
+
WritableStream,
|
|
24
|
+
TransformStream,
|
|
25
|
+
Blob,
|
|
26
|
+
File,
|
|
27
|
+
crypto,
|
|
28
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const busboy = require('busboy');
|
|
2
|
+
const streams = require("stream");
|
|
3
|
+
|
|
4
|
+
module.exports = function getFormDataMethod(File, limits) {
|
|
5
|
+
return function formData() {
|
|
6
|
+
if (this.body == null) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
const contentType = this.headers.get('Content-Type');
|
|
10
|
+
const nodeReadable = this.body.on ? this.body : streams.Readable.from(this.body);
|
|
11
|
+
const bb = busboy({
|
|
12
|
+
headers: {
|
|
13
|
+
'content-type': contentType
|
|
14
|
+
},
|
|
15
|
+
limits,
|
|
16
|
+
defParamCharset: 'utf-8'
|
|
17
|
+
});
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
const formData = new Map();
|
|
20
|
+
bb.on('file', (name, fileStream, { filename, mimeType }) => {
|
|
21
|
+
const chunks = [];
|
|
22
|
+
fileStream.on('limit', () => {
|
|
23
|
+
reject(new Error(`File size limit exceeded: ${limits.fileSize} bytes`));
|
|
24
|
+
})
|
|
25
|
+
fileStream.on('data', (chunk) => {
|
|
26
|
+
chunks.push(chunk);
|
|
27
|
+
})
|
|
28
|
+
fileStream.on('close', () => {
|
|
29
|
+
formData.set(name, new File(chunks, filename, { type: mimeType }));
|
|
30
|
+
});
|
|
31
|
+
})
|
|
32
|
+
bb.on('field', (name, value, { nameTruncated, valueTruncated }) => {
|
|
33
|
+
if (nameTruncated) {
|
|
34
|
+
reject(new Error(`Field name size exceeded: ${limits.fieldNameSize} bytes`));
|
|
35
|
+
}
|
|
36
|
+
if (valueTruncated) {
|
|
37
|
+
reject(new Error(`Field value size exceeded: ${limits.fieldSize} bytes`));
|
|
38
|
+
}
|
|
39
|
+
formData.set(name, value)
|
|
40
|
+
})
|
|
41
|
+
bb.on('partsLimit', () => {
|
|
42
|
+
reject(new Error(`Parts limit exceeded: ${limits.parts}`));
|
|
43
|
+
})
|
|
44
|
+
bb.on('filesLimit', () => {
|
|
45
|
+
reject(new Error(`Files limit exceeded: ${limits.files}`));
|
|
46
|
+
})
|
|
47
|
+
bb.on('fieldsLimit', () => {
|
|
48
|
+
reject(new Error(`Fields limit exceeded: ${limits.fields}`));
|
|
49
|
+
})
|
|
50
|
+
bb.on('close', () => {
|
|
51
|
+
resolve(formData);
|
|
52
|
+
});
|
|
53
|
+
bb.on('error', err => {
|
|
54
|
+
reject(err);
|
|
55
|
+
})
|
|
56
|
+
nodeReadable.pipe(bb);
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module.exports.fetch = globalThis.fetch; // To enable: import {fetch} from 'cross-fetch'
|
|
2
|
+
module.exports.Headers = globalThis.Headers;
|
|
3
|
+
module.exports.Request = globalThis.Request;
|
|
4
|
+
module.exports.Response = globalThis.Response;
|
|
5
|
+
module.exports.FormData = globalThis.FormData;
|
|
6
|
+
module.exports.AbortController = globalThis.AbortController;
|
|
7
|
+
module.exports.ReadableStream = globalThis.ReadableStream;
|
|
8
|
+
module.exports.WritableStream = globalThis.WritableStream;
|
|
9
|
+
module.exports.TransformStream = globalThis.TransformStream;
|
|
10
|
+
module.exports.Blob = globalThis.Blob;
|
|
11
|
+
module.exports.File = globalThis.File;
|
|
12
|
+
module.exports.crypto = globalThis.crypto;
|
|
13
|
+
module.exports.createFetch = () => globalThis;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/// <reference lib="dom" />
|
|
2
|
+
|
|
3
|
+
declare const _fetch: typeof fetch;
|
|
4
|
+
declare const _Request: typeof Request;
|
|
5
|
+
declare const _Response: typeof Response;
|
|
6
|
+
declare const _Headers: typeof Headers;
|
|
7
|
+
declare const _FormData: typeof FormData;
|
|
8
|
+
declare const _AbortController: typeof AbortController;
|
|
9
|
+
declare const _ReadableStream: typeof ReadableStream;
|
|
10
|
+
declare const _WritableStream: typeof WritableStream;
|
|
11
|
+
declare const _TransformStream: typeof TransformStream;
|
|
12
|
+
declare const _Blob: typeof Blob;
|
|
13
|
+
declare const _File: typeof File;
|
|
14
|
+
declare const _crypto: typeof crypto;
|
|
15
|
+
|
|
16
|
+
declare module "@whatwg-node/fetch" {
|
|
17
|
+
export const fetch: typeof _fetch;
|
|
18
|
+
export const Request: typeof _Request;
|
|
19
|
+
export const Response: typeof _Response;
|
|
20
|
+
export const Headers: typeof _Headers;
|
|
21
|
+
export const FormData: typeof _FormData;
|
|
22
|
+
export const AbortController: typeof _AbortController;
|
|
23
|
+
export const ReadableStream: typeof _ReadableStream;
|
|
24
|
+
export const WritableStream: typeof _WritableStream;
|
|
25
|
+
export const TransformStream: typeof _TransformStream;
|
|
26
|
+
export const Blob: typeof _Blob;
|
|
27
|
+
export const File: typeof _File;
|
|
28
|
+
export const crypto: typeof _crypto;
|
|
29
|
+
export interface FormDataLimits {
|
|
30
|
+
/* Max field name size (in bytes). Default: 100. */
|
|
31
|
+
fieldNameSize?: number;
|
|
32
|
+
/* Max field value size (in bytes). Default: 1MB. */
|
|
33
|
+
fieldSize?: number;
|
|
34
|
+
/* Max number of fields. Default: Infinity. */
|
|
35
|
+
fields?: number;
|
|
36
|
+
/* For multipart forms, the max file size (in bytes). Default: Infinity. */
|
|
37
|
+
fileSize?: number;
|
|
38
|
+
/* For multipart forms, the max number of file fields. Default: Infinity. */
|
|
39
|
+
files?: number;
|
|
40
|
+
/* For multipart forms, the max number of parts (fields + files). Default: Infinity. */
|
|
41
|
+
parts?: number;
|
|
42
|
+
/* For multipart forms, the max number of header key-value pairs to parse. Default: 2000. */
|
|
43
|
+
headerSize?: number;
|
|
44
|
+
}
|
|
45
|
+
export const create: (opts?: { useNodeFetch?: boolean; formDataLimits?: FormDataLimits }) => ({
|
|
46
|
+
fetch: typeof _fetch,
|
|
47
|
+
Request: typeof _Request,
|
|
48
|
+
Response: typeof _Response,
|
|
49
|
+
Headers: typeof _Headers,
|
|
50
|
+
FormData: typeof _FormData,
|
|
51
|
+
AbortController: typeof _AbortController,
|
|
52
|
+
ReadableStream: typeof _ReadableStream,
|
|
53
|
+
WritableStream: typeof _WritableStream,
|
|
54
|
+
TransformStream: typeof _TransformStream,
|
|
55
|
+
Blob: typeof _Blob,
|
|
56
|
+
File: typeof _File,
|
|
57
|
+
crypto: typeof _crypto
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
const createNodePonyfill = require('./create-node-ponyfill');
|
|
3
|
+
const ponyfills = createNodePonyfill();
|
|
4
|
+
|
|
5
|
+
module.exports.fetch = ponyfills.fetch;
|
|
6
|
+
module.exports.Headers = ponyfills.Headers;
|
|
7
|
+
module.exports.Request = ponyfills.Request;
|
|
8
|
+
module.exports.Response = ponyfills.Response;
|
|
9
|
+
module.exports.FormData = ponyfills.FormData;
|
|
10
|
+
module.exports.AbortController = ponyfills.AbortController;
|
|
11
|
+
module.exports.ReadableStream = ponyfills.ReadableStream;
|
|
12
|
+
module.exports.WritableStream = ponyfills.WritableStream;
|
|
13
|
+
module.exports.TransformStream = ponyfills.TransformStream;
|
|
14
|
+
module.exports.Blob = ponyfills.Blob;
|
|
15
|
+
module.exports.File = ponyfills.File;
|
|
16
|
+
module.exports.crypto = ponyfills.crypto;
|
|
17
|
+
exports.createFetch = createNodePonyfill;
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@whatwg-node/fetch",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Cross Platform Smart Fetch Ponyfill",
|
|
5
|
+
"author": "Arda TANRIKULU <ardatanrikulu@gmail.com>",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "ardatan/whatwg-node",
|
|
9
|
+
"directory": "packages/fetch"
|
|
10
|
+
},
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"main": "dist/node-ponyfill.js",
|
|
14
|
+
"browser": "dist/global-ponyfill.js",
|
|
15
|
+
"react-native": "dist/global-ponyfill.js",
|
|
16
|
+
"types": "dist/index.d.ts",
|
|
17
|
+
"denoify": {
|
|
18
|
+
"index": "dist/deno-ponyfill.ts"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"abort-controller": "^3.0.0",
|
|
22
|
+
"busboy": "^1.6.0",
|
|
23
|
+
"form-data-encoder": "^1.7.1",
|
|
24
|
+
"formdata-node": "^4.3.1",
|
|
25
|
+
"node-fetch": "^2.6.7",
|
|
26
|
+
"undici": "5.5.1",
|
|
27
|
+
"web-streams-polyfill": "^3.2.0"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
}
|
|
32
|
+
}
|