@8ms/helpers 2.3.7 → 2.3.8

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.
Files changed (81) hide show
  1. package/.yarn/install-state.gz +0 -0
  2. package/dist/_class/index.d.mts +1 -1
  3. package/dist/adverity/index.d.mts +1 -1
  4. package/dist/adverity/server/index.d.mts +2 -2
  5. package/dist/adverity/server/index.mjs +1 -1
  6. package/dist/api/index.d.mts +1 -1
  7. package/dist/api/index.mjs +1 -1
  8. package/dist/aws/ec2/server/index.d.mts +2 -2
  9. package/dist/aws/ec2/server/index.mjs +1 -1
  10. package/dist/aws/ecs/server/index.d.mts +2 -2
  11. package/dist/aws/ecs/server/index.mjs +1 -1
  12. package/dist/aws/glue/server/index.d.mts +2 -2
  13. package/dist/aws/glue/server/index.mjs +1 -1
  14. package/dist/aws/lambda/server/index.d.mts +2 -2
  15. package/dist/aws/lambda/server/index.mjs +2 -2
  16. package/dist/aws/s3/server/index.d.mts +2 -2
  17. package/dist/aws/s3/server/index.mjs +3 -3
  18. package/dist/aws/server/index.d.mts +1 -1
  19. package/dist/aws/server/index.mjs +1 -1
  20. package/dist/aws/ses/server/index.d.mts +2 -2
  21. package/dist/aws/ses/server/index.mjs +3 -3
  22. package/dist/aws/sqs/server/index.d.mts +2 -2
  23. package/dist/aws/sqs/server/index.mjs +1 -1
  24. package/dist/aws/ssm/server/index.d.mts +2 -2
  25. package/dist/aws/ssm/server/index.mjs +1 -1
  26. package/dist/axios/index.d.mts +1 -1
  27. package/dist/axios/index.mjs +5 -5
  28. package/dist/brightData/serpApi/server/index.d.mts +2 -2
  29. package/dist/brightData/serpApi/server/index.mjs +1 -1
  30. package/dist/brightData/server/index.d.mts +1 -1
  31. package/dist/brightData/webScraperIde/server/index.d.mts +1 -1
  32. package/dist/brightData/webScraperIde/server/index.mjs +1 -1
  33. package/dist/date/index.d.mts +1 -1
  34. package/dist/eskimi/server/index.mjs +1 -1
  35. package/dist/googleAds/server/index.d.mts +1 -1
  36. package/dist/googleCloud/bigquery/server/index.d.mts +2 -2
  37. package/dist/googleCloud/server/index.d.mts +1 -1
  38. package/dist/googleCloud/sheets/server/index.d.mts +2 -2
  39. package/dist/googleCloud/storage/server/index.d.mts +2 -2
  40. package/dist/googlePageSpeed/server/index.d.mts +1 -1
  41. package/dist/googlePageSpeed/server/index.mjs +1 -1
  42. package/dist/googleSearchIncidents/server/index.mjs +1 -1
  43. package/dist/greenDomain/server/index.mjs +1 -1
  44. package/dist/littleWarden/server/index.d.mts +1 -1
  45. package/dist/littleWarden/server/index.mjs +1 -1
  46. package/dist/lumar/api/server/index.d.mts +1 -1
  47. package/dist/lumar/api/server/index.mjs +1 -1
  48. package/dist/lumar/graphql/server/index.d.mts +1 -1
  49. package/dist/lumar/graphql/server/index.mjs +1 -1
  50. package/dist/myTarget/server/index.d.mts +1 -1
  51. package/dist/myTarget/server/index.mjs +1 -1
  52. package/dist/number/index.mjs +1 -1
  53. package/dist/onePassword/server/index.d.mts +1 -1
  54. package/dist/openAi/server/index.d.mts +1 -1
  55. package/dist/openAi/server/index.mjs +1 -1
  56. package/dist/prisma/index.mjs +1 -1
  57. package/dist/prisma/server/index.d.mts +1 -1
  58. package/dist/snapchat/server/index.d.mts +1 -1
  59. package/dist/snapchat/server/index.mjs +1 -1
  60. package/dist/stream/server/index.mjs +5 -1
  61. package/dist/swr/client/index.d.mts +1 -1
  62. package/dist/upTimeRobot/server/index.d.mts +1 -1
  63. package/dist/upTimeRobot/server/index.mjs +1 -1
  64. package/dist/url/server/index.mjs +2 -2
  65. package/dist/xml/server/index.mjs +1 -1
  66. package/package.json +1 -1
  67. package/tsdown.config.ts +1 -0
  68. package/dist/chunk-CgI6uo-e.mjs +0 -32
  69. package/dist/from-9s4TjsYv.mjs +0 -3878
  70. package/dist/multipart-parser-BC14QSvI.mjs +0 -290
  71. package/dist/src-BeXFXTgz.mjs +0 -1272
  72. /package/dist/{api-DGKJDAfb.mjs → api-BlYy5Efh.mjs} +0 -0
  73. /package/dist/{getDecimal-CafxtLhH.mjs → getDecimal-DRv1J8WD.mjs} +0 -0
  74. /package/dist/{index-CFaAdPAh.d.mts → index-1SE8er2n.d.mts} +0 -0
  75. /package/dist/{index-DEm1Wodf.d.mts → index-BOvAlQeY.d.mts} +0 -0
  76. /package/dist/{index-CMfxuwL1.d.mts → index-Bfls0t50.d.mts} +0 -0
  77. /package/dist/{index-sfVt7tI_.d.mts → index-CN31pmsW.d.mts} +0 -0
  78. /package/dist/{index-B20FTOvk.d.mts → index-D1tpqoPU.d.mts} +0 -0
  79. /package/dist/{index-CIG08fpw.d.mts → index-Yx2783su.d.mts} +0 -0
  80. /package/dist/{index-B4K9Z1U-.d.mts → index-ndHDK8xQ.d.mts} +0 -0
  81. /package/dist/{server-Bwy4JI8Z.mjs → server-Dbl5Ic6I.mjs} +0 -0
@@ -1,1272 +0,0 @@
1
- import { i as Blob, n as formDataToBlob, r as File, t as FormData } from "./from-9s4TjsYv.mjs";
2
- import http from "node:http";
3
- import https from "node:https";
4
- import zlib from "node:zlib";
5
- import Stream, { PassThrough, pipeline } from "node:stream";
6
- import { Buffer as Buffer$1 } from "node:buffer";
7
- import { deprecate, promisify, types } from "node:util";
8
- import { format } from "node:url";
9
- import { isIP } from "node:net";
10
-
11
- //#region node_modules/data-uri-to-buffer/dist/index.js
12
- /**
13
- * Returns a `Buffer` instance from the given data URI `uri`.
14
- *
15
- * @param {String} uri Data URI to turn into a Buffer instance
16
- * @returns {Buffer} Buffer instance from Data URI
17
- * @api public
18
- */
19
- function dataUriToBuffer(uri) {
20
- if (!/^data:/i.test(uri)) throw new TypeError("`uri` does not appear to be a Data URI (must begin with \"data:\")");
21
- uri = uri.replace(/\r?\n/g, "");
22
- const firstComma = uri.indexOf(",");
23
- if (firstComma === -1 || firstComma <= 4) throw new TypeError("malformed data: URI");
24
- const meta = uri.substring(5, firstComma).split(";");
25
- let charset = "";
26
- let base64 = false;
27
- const type = meta[0] || "text/plain";
28
- let typeFull = type;
29
- for (let i = 1; i < meta.length; i++) if (meta[i] === "base64") base64 = true;
30
- else if (meta[i]) {
31
- typeFull += `;${meta[i]}`;
32
- if (meta[i].indexOf("charset=") === 0) charset = meta[i].substring(8);
33
- }
34
- if (!meta[0] && !charset.length) {
35
- typeFull += ";charset=US-ASCII";
36
- charset = "US-ASCII";
37
- }
38
- const encoding = base64 ? "base64" : "ascii";
39
- const data = unescape(uri.substring(firstComma + 1));
40
- const buffer = Buffer.from(data, encoding);
41
- buffer.type = type;
42
- buffer.typeFull = typeFull;
43
- buffer.charset = charset;
44
- return buffer;
45
- }
46
-
47
- //#endregion
48
- //#region node_modules/node-fetch/src/errors/base.js
49
- var FetchBaseError = class extends Error {
50
- constructor(message, type) {
51
- super(message);
52
- Error.captureStackTrace(this, this.constructor);
53
- this.type = type;
54
- }
55
- get name() {
56
- return this.constructor.name;
57
- }
58
- get [Symbol.toStringTag]() {
59
- return this.constructor.name;
60
- }
61
- };
62
-
63
- //#endregion
64
- //#region node_modules/node-fetch/src/errors/fetch-error.js
65
- /**
66
- * @typedef {{ address?: string, code: string, dest?: string, errno: number, info?: object, message: string, path?: string, port?: number, syscall: string}} SystemError
67
- */
68
- /**
69
- * FetchError interface for operational errors
70
- */
71
- var FetchError = class extends FetchBaseError {
72
- /**
73
- * @param {string} message - Error message for human
74
- * @param {string} [type] - Error type for machine
75
- * @param {SystemError} [systemError] - For Node.js system error
76
- */
77
- constructor(message, type, systemError) {
78
- super(message, type);
79
- if (systemError) {
80
- this.code = this.errno = systemError.code;
81
- this.erroredSysCall = systemError.syscall;
82
- }
83
- }
84
- };
85
-
86
- //#endregion
87
- //#region node_modules/node-fetch/src/utils/is.js
88
- /**
89
- * Is.js
90
- *
91
- * Object type checks.
92
- */
93
- const NAME = Symbol.toStringTag;
94
- /**
95
- * Check if `obj` is a URLSearchParams object
96
- * ref: https://github.com/node-fetch/node-fetch/issues/296#issuecomment-307598143
97
- * @param {*} object - Object to check for
98
- * @return {boolean}
99
- */
100
- const isURLSearchParameters = (object) => {
101
- return typeof object === "object" && typeof object.append === "function" && typeof object.delete === "function" && typeof object.get === "function" && typeof object.getAll === "function" && typeof object.has === "function" && typeof object.set === "function" && typeof object.sort === "function" && object[NAME] === "URLSearchParams";
102
- };
103
- /**
104
- * Check if `object` is a W3C `Blob` object (which `File` inherits from)
105
- * @param {*} object - Object to check for
106
- * @return {boolean}
107
- */
108
- const isBlob = (object) => {
109
- return object && typeof object === "object" && typeof object.arrayBuffer === "function" && typeof object.type === "string" && typeof object.stream === "function" && typeof object.constructor === "function" && /^(Blob|File)$/.test(object[NAME]);
110
- };
111
- /**
112
- * Check if `obj` is an instance of AbortSignal.
113
- * @param {*} object - Object to check for
114
- * @return {boolean}
115
- */
116
- const isAbortSignal = (object) => {
117
- return typeof object === "object" && (object[NAME] === "AbortSignal" || object[NAME] === "EventTarget");
118
- };
119
- /**
120
- * isDomainOrSubdomain reports whether sub is a subdomain (or exact match) of
121
- * the parent domain.
122
- *
123
- * Both domains must already be in canonical form.
124
- * @param {string|URL} original
125
- * @param {string|URL} destination
126
- */
127
- const isDomainOrSubdomain = (destination, original) => {
128
- const orig = new URL(original).hostname;
129
- const dest = new URL(destination).hostname;
130
- return orig === dest || orig.endsWith(`.${dest}`);
131
- };
132
- /**
133
- * isSameProtocol reports whether the two provided URLs use the same protocol.
134
- *
135
- * Both domains must already be in canonical form.
136
- * @param {string|URL} original
137
- * @param {string|URL} destination
138
- */
139
- const isSameProtocol = (destination, original) => {
140
- return new URL(original).protocol === new URL(destination).protocol;
141
- };
142
-
143
- //#endregion
144
- //#region node_modules/node-fetch/src/body.js
145
- /**
146
- * Body.js
147
- *
148
- * Body interface provides common methods for Request and Response
149
- */
150
- const pipeline$1 = promisify(Stream.pipeline);
151
- const INTERNALS$2 = Symbol("Body internals");
152
- /**
153
- * Body mixin
154
- *
155
- * Ref: https://fetch.spec.whatwg.org/#body
156
- *
157
- * @param Stream body Readable stream
158
- * @param Object opts Response options
159
- * @return Void
160
- */
161
- var Body = class {
162
- constructor(body, { size = 0 } = {}) {
163
- let boundary = null;
164
- if (body === null) body = null;
165
- else if (isURLSearchParameters(body)) body = Buffer$1.from(body.toString());
166
- else if (isBlob(body)) {} else if (Buffer$1.isBuffer(body)) {} else if (types.isAnyArrayBuffer(body)) body = Buffer$1.from(body);
167
- else if (ArrayBuffer.isView(body)) body = Buffer$1.from(body.buffer, body.byteOffset, body.byteLength);
168
- else if (body instanceof Stream) {} else if (body instanceof FormData) {
169
- body = formDataToBlob(body);
170
- boundary = body.type.split("=")[1];
171
- } else body = Buffer$1.from(String(body));
172
- let stream = body;
173
- if (Buffer$1.isBuffer(body)) stream = Stream.Readable.from(body);
174
- else if (isBlob(body)) stream = Stream.Readable.from(body.stream());
175
- this[INTERNALS$2] = {
176
- body,
177
- stream,
178
- boundary,
179
- disturbed: false,
180
- error: null
181
- };
182
- this.size = size;
183
- if (body instanceof Stream) body.on("error", (error_) => {
184
- const error = error_ instanceof FetchBaseError ? error_ : new FetchError(`Invalid response body while trying to fetch ${this.url}: ${error_.message}`, "system", error_);
185
- this[INTERNALS$2].error = error;
186
- });
187
- }
188
- get body() {
189
- return this[INTERNALS$2].stream;
190
- }
191
- get bodyUsed() {
192
- return this[INTERNALS$2].disturbed;
193
- }
194
- /**
195
- * Decode response as ArrayBuffer
196
- *
197
- * @return Promise
198
- */
199
- async arrayBuffer() {
200
- const { buffer, byteOffset, byteLength } = await consumeBody(this);
201
- return buffer.slice(byteOffset, byteOffset + byteLength);
202
- }
203
- async formData() {
204
- const ct = this.headers.get("content-type");
205
- if (ct.startsWith("application/x-www-form-urlencoded")) {
206
- const formData = new FormData();
207
- const parameters = new URLSearchParams(await this.text());
208
- for (const [name, value] of parameters) formData.append(name, value);
209
- return formData;
210
- }
211
- const { toFormData } = await import("./multipart-parser-BC14QSvI.mjs");
212
- return toFormData(this.body, ct);
213
- }
214
- /**
215
- * Return raw response as Blob
216
- *
217
- * @return Promise
218
- */
219
- async blob() {
220
- const ct = this.headers && this.headers.get("content-type") || this[INTERNALS$2].body && this[INTERNALS$2].body.type || "";
221
- return new Blob([await this.arrayBuffer()], { type: ct });
222
- }
223
- /**
224
- * Decode response as json
225
- *
226
- * @return Promise
227
- */
228
- async json() {
229
- const text = await this.text();
230
- return JSON.parse(text);
231
- }
232
- /**
233
- * Decode response as text
234
- *
235
- * @return Promise
236
- */
237
- async text() {
238
- const buffer = await consumeBody(this);
239
- return new TextDecoder().decode(buffer);
240
- }
241
- /**
242
- * Decode response as buffer (non-spec api)
243
- *
244
- * @return Promise
245
- */
246
- buffer() {
247
- return consumeBody(this);
248
- }
249
- };
250
- Body.prototype.buffer = deprecate(Body.prototype.buffer, "Please use 'response.arrayBuffer()' instead of 'response.buffer()'", "node-fetch#buffer");
251
- Object.defineProperties(Body.prototype, {
252
- body: { enumerable: true },
253
- bodyUsed: { enumerable: true },
254
- arrayBuffer: { enumerable: true },
255
- blob: { enumerable: true },
256
- json: { enumerable: true },
257
- text: { enumerable: true },
258
- data: { get: deprecate(() => {}, "data doesn't exist, use json(), text(), arrayBuffer(), or body instead", "https://github.com/node-fetch/node-fetch/issues/1000 (response)") }
259
- });
260
- /**
261
- * Consume and convert an entire Body to a Buffer.
262
- *
263
- * Ref: https://fetch.spec.whatwg.org/#concept-body-consume-body
264
- *
265
- * @return Promise
266
- */
267
- async function consumeBody(data) {
268
- if (data[INTERNALS$2].disturbed) throw new TypeError(`body used already for: ${data.url}`);
269
- data[INTERNALS$2].disturbed = true;
270
- if (data[INTERNALS$2].error) throw data[INTERNALS$2].error;
271
- const { body } = data;
272
- if (body === null) return Buffer$1.alloc(0);
273
- /* c8 ignore next 3 */
274
- if (!(body instanceof Stream)) return Buffer$1.alloc(0);
275
- const accum = [];
276
- let accumBytes = 0;
277
- try {
278
- for await (const chunk of body) {
279
- if (data.size > 0 && accumBytes + chunk.length > data.size) {
280
- const error = new FetchError(`content size at ${data.url} over limit: ${data.size}`, "max-size");
281
- body.destroy(error);
282
- throw error;
283
- }
284
- accumBytes += chunk.length;
285
- accum.push(chunk);
286
- }
287
- } catch (error) {
288
- throw error instanceof FetchBaseError ? error : new FetchError(`Invalid response body while trying to fetch ${data.url}: ${error.message}`, "system", error);
289
- }
290
- if (body.readableEnded === true || body._readableState.ended === true) try {
291
- if (accum.every((c) => typeof c === "string")) return Buffer$1.from(accum.join(""));
292
- return Buffer$1.concat(accum, accumBytes);
293
- } catch (error) {
294
- throw new FetchError(`Could not create Buffer from response body for ${data.url}: ${error.message}`, "system", error);
295
- }
296
- else throw new FetchError(`Premature close of server response while trying to fetch ${data.url}`);
297
- }
298
- /**
299
- * Clone body given Res/Req instance
300
- *
301
- * @param Mixed instance Response or Request instance
302
- * @param String highWaterMark highWaterMark for both PassThrough body streams
303
- * @return Mixed
304
- */
305
- const clone = (instance, highWaterMark) => {
306
- let p1;
307
- let p2;
308
- let { body } = instance[INTERNALS$2];
309
- if (instance.bodyUsed) throw new Error("cannot clone body after it is used");
310
- if (body instanceof Stream && typeof body.getBoundary !== "function") {
311
- p1 = new PassThrough({ highWaterMark });
312
- p2 = new PassThrough({ highWaterMark });
313
- body.pipe(p1);
314
- body.pipe(p2);
315
- instance[INTERNALS$2].stream = p1;
316
- body = p2;
317
- }
318
- return body;
319
- };
320
- const getNonSpecFormDataBoundary = deprecate((body) => body.getBoundary(), "form-data doesn't follow the spec and requires special treatment. Use alternative package", "https://github.com/node-fetch/node-fetch/issues/1167");
321
- /**
322
- * Performs the operation "extract a `Content-Type` value from |object|" as
323
- * specified in the specification:
324
- * https://fetch.spec.whatwg.org/#concept-bodyinit-extract
325
- *
326
- * This function assumes that instance.body is present.
327
- *
328
- * @param {any} body Any options.body input
329
- * @returns {string | null}
330
- */
331
- const extractContentType = (body, request) => {
332
- if (body === null) return null;
333
- if (typeof body === "string") return "text/plain;charset=UTF-8";
334
- if (isURLSearchParameters(body)) return "application/x-www-form-urlencoded;charset=UTF-8";
335
- if (isBlob(body)) return body.type || null;
336
- if (Buffer$1.isBuffer(body) || types.isAnyArrayBuffer(body) || ArrayBuffer.isView(body)) return null;
337
- if (body instanceof FormData) return `multipart/form-data; boundary=${request[INTERNALS$2].boundary}`;
338
- if (body && typeof body.getBoundary === "function") return `multipart/form-data;boundary=${getNonSpecFormDataBoundary(body)}`;
339
- if (body instanceof Stream) return null;
340
- return "text/plain;charset=UTF-8";
341
- };
342
- /**
343
- * The Fetch Standard treats this as if "total bytes" is a property on the body.
344
- * For us, we have to explicitly get it with a function.
345
- *
346
- * ref: https://fetch.spec.whatwg.org/#concept-body-total-bytes
347
- *
348
- * @param {any} obj.body Body object from the Body instance.
349
- * @returns {number | null}
350
- */
351
- const getTotalBytes = (request) => {
352
- const { body } = request[INTERNALS$2];
353
- if (body === null) return 0;
354
- if (isBlob(body)) return body.size;
355
- if (Buffer$1.isBuffer(body)) return body.length;
356
- if (body && typeof body.getLengthSync === "function") return body.hasKnownLength && body.hasKnownLength() ? body.getLengthSync() : null;
357
- return null;
358
- };
359
- /**
360
- * Write a Body to a Node.js WritableStream (e.g. http.Request) object.
361
- *
362
- * @param {Stream.Writable} dest The stream to write to.
363
- * @param obj.body Body object from the Body instance.
364
- * @returns {Promise<void>}
365
- */
366
- const writeToStream = async (dest, { body }) => {
367
- if (body === null) dest.end();
368
- else await pipeline$1(body, dest);
369
- };
370
-
371
- //#endregion
372
- //#region node_modules/node-fetch/src/headers.js
373
- /**
374
- * Headers.js
375
- *
376
- * Headers class offers convenient helpers
377
- */
378
- /* c8 ignore next 9 */
379
- const validateHeaderName = typeof http.validateHeaderName === "function" ? http.validateHeaderName : (name) => {
380
- if (!/^[\^`\-\w!#$%&'*+.|~]+$/.test(name)) {
381
- const error = /* @__PURE__ */ new TypeError(`Header name must be a valid HTTP token [${name}]`);
382
- Object.defineProperty(error, "code", { value: "ERR_INVALID_HTTP_TOKEN" });
383
- throw error;
384
- }
385
- };
386
- /* c8 ignore next 9 */
387
- const validateHeaderValue = typeof http.validateHeaderValue === "function" ? http.validateHeaderValue : (name, value) => {
388
- if (/[^\t\u0020-\u007E\u0080-\u00FF]/.test(value)) {
389
- const error = /* @__PURE__ */ new TypeError(`Invalid character in header content ["${name}"]`);
390
- Object.defineProperty(error, "code", { value: "ERR_INVALID_CHAR" });
391
- throw error;
392
- }
393
- };
394
- /**
395
- * @typedef {Headers | Record<string, string> | Iterable<readonly [string, string]> | Iterable<Iterable<string>>} HeadersInit
396
- */
397
- /**
398
- * This Fetch API interface allows you to perform various actions on HTTP request and response headers.
399
- * These actions include retrieving, setting, adding to, and removing.
400
- * A Headers object has an associated header list, which is initially empty and consists of zero or more name and value pairs.
401
- * You can add to this using methods like append() (see Examples.)
402
- * In all methods of this interface, header names are matched by case-insensitive byte sequence.
403
- *
404
- */
405
- var Headers = class Headers extends URLSearchParams {
406
- /**
407
- * Headers class
408
- *
409
- * @constructor
410
- * @param {HeadersInit} [init] - Response headers
411
- */
412
- constructor(init) {
413
- /** @type {string[][]} */
414
- let result = [];
415
- if (init instanceof Headers) {
416
- const raw = init.raw();
417
- for (const [name, values] of Object.entries(raw)) result.push(...values.map((value) => [name, value]));
418
- } else if (init == null) {} else if (typeof init === "object" && !types.isBoxedPrimitive(init)) {
419
- const method = init[Symbol.iterator];
420
- if (method == null) result.push(...Object.entries(init));
421
- else {
422
- if (typeof method !== "function") throw new TypeError("Header pairs must be iterable");
423
- result = [...init].map((pair) => {
424
- if (typeof pair !== "object" || types.isBoxedPrimitive(pair)) throw new TypeError("Each header pair must be an iterable object");
425
- return [...pair];
426
- }).map((pair) => {
427
- if (pair.length !== 2) throw new TypeError("Each header pair must be a name/value tuple");
428
- return [...pair];
429
- });
430
- }
431
- } else throw new TypeError("Failed to construct 'Headers': The provided value is not of type '(sequence<sequence<ByteString>> or record<ByteString, ByteString>)");
432
- result = result.length > 0 ? result.map(([name, value]) => {
433
- validateHeaderName(name);
434
- validateHeaderValue(name, String(value));
435
- return [String(name).toLowerCase(), String(value)];
436
- }) : void 0;
437
- super(result);
438
- return new Proxy(this, { get(target, p, receiver) {
439
- switch (p) {
440
- case "append":
441
- case "set": return (name, value) => {
442
- validateHeaderName(name);
443
- validateHeaderValue(name, String(value));
444
- return URLSearchParams.prototype[p].call(target, String(name).toLowerCase(), String(value));
445
- };
446
- case "delete":
447
- case "has":
448
- case "getAll": return (name) => {
449
- validateHeaderName(name);
450
- return URLSearchParams.prototype[p].call(target, String(name).toLowerCase());
451
- };
452
- case "keys": return () => {
453
- target.sort();
454
- return new Set(URLSearchParams.prototype.keys.call(target)).keys();
455
- };
456
- default: return Reflect.get(target, p, receiver);
457
- }
458
- } });
459
- /* c8 ignore next */
460
- }
461
- get [Symbol.toStringTag]() {
462
- return this.constructor.name;
463
- }
464
- toString() {
465
- return Object.prototype.toString.call(this);
466
- }
467
- get(name) {
468
- const values = this.getAll(name);
469
- if (values.length === 0) return null;
470
- let value = values.join(", ");
471
- if (/^content-encoding$/i.test(name)) value = value.toLowerCase();
472
- return value;
473
- }
474
- forEach(callback, thisArg = void 0) {
475
- for (const name of this.keys()) Reflect.apply(callback, thisArg, [
476
- this.get(name),
477
- name,
478
- this
479
- ]);
480
- }
481
- *values() {
482
- for (const name of this.keys()) yield this.get(name);
483
- }
484
- /**
485
- * @type {() => IterableIterator<[string, string]>}
486
- */
487
- *entries() {
488
- for (const name of this.keys()) yield [name, this.get(name)];
489
- }
490
- [Symbol.iterator]() {
491
- return this.entries();
492
- }
493
- /**
494
- * Node-fetch non-spec method
495
- * returning all headers and their values as array
496
- * @returns {Record<string, string[]>}
497
- */
498
- raw() {
499
- return [...this.keys()].reduce((result, key) => {
500
- result[key] = this.getAll(key);
501
- return result;
502
- }, {});
503
- }
504
- /**
505
- * For better console.log(headers) and also to convert Headers into Node.js Request compatible format
506
- */
507
- [Symbol.for("nodejs.util.inspect.custom")]() {
508
- return [...this.keys()].reduce((result, key) => {
509
- const values = this.getAll(key);
510
- if (key === "host") result[key] = values[0];
511
- else result[key] = values.length > 1 ? values : values[0];
512
- return result;
513
- }, {});
514
- }
515
- };
516
- /**
517
- * Re-shaping object for Web IDL tests
518
- * Only need to do it for overridden methods
519
- */
520
- Object.defineProperties(Headers.prototype, [
521
- "get",
522
- "entries",
523
- "forEach",
524
- "values"
525
- ].reduce((result, property) => {
526
- result[property] = { enumerable: true };
527
- return result;
528
- }, {}));
529
- /**
530
- * Create a Headers object from an http.IncomingMessage.rawHeaders, ignoring those that do
531
- * not conform to HTTP grammar productions.
532
- * @param {import('http').IncomingMessage['rawHeaders']} headers
533
- */
534
- function fromRawHeaders(headers = []) {
535
- return new Headers(headers.reduce((result, value, index, array) => {
536
- if (index % 2 === 0) result.push(array.slice(index, index + 2));
537
- return result;
538
- }, []).filter(([name, value]) => {
539
- try {
540
- validateHeaderName(name);
541
- validateHeaderValue(name, String(value));
542
- return true;
543
- } catch {
544
- return false;
545
- }
546
- }));
547
- }
548
-
549
- //#endregion
550
- //#region node_modules/node-fetch/src/utils/is-redirect.js
551
- const redirectStatus = new Set([
552
- 301,
553
- 302,
554
- 303,
555
- 307,
556
- 308
557
- ]);
558
- /**
559
- * Redirect code matching
560
- *
561
- * @param {number} code - Status code
562
- * @return {boolean}
563
- */
564
- const isRedirect = (code) => {
565
- return redirectStatus.has(code);
566
- };
567
-
568
- //#endregion
569
- //#region node_modules/node-fetch/src/response.js
570
- /**
571
- * Response.js
572
- *
573
- * Response class provides content decoding
574
- */
575
- const INTERNALS$1 = Symbol("Response internals");
576
- /**
577
- * Response class
578
- *
579
- * Ref: https://fetch.spec.whatwg.org/#response-class
580
- *
581
- * @param Stream body Readable stream
582
- * @param Object opts Response options
583
- * @return Void
584
- */
585
- var Response = class Response extends Body {
586
- constructor(body = null, options = {}) {
587
- super(body, options);
588
- const status = options.status != null ? options.status : 200;
589
- const headers = new Headers(options.headers);
590
- if (body !== null && !headers.has("Content-Type")) {
591
- const contentType = extractContentType(body, this);
592
- if (contentType) headers.append("Content-Type", contentType);
593
- }
594
- this[INTERNALS$1] = {
595
- type: "default",
596
- url: options.url,
597
- status,
598
- statusText: options.statusText || "",
599
- headers,
600
- counter: options.counter,
601
- highWaterMark: options.highWaterMark
602
- };
603
- }
604
- get type() {
605
- return this[INTERNALS$1].type;
606
- }
607
- get url() {
608
- return this[INTERNALS$1].url || "";
609
- }
610
- get status() {
611
- return this[INTERNALS$1].status;
612
- }
613
- /**
614
- * Convenience property representing if the request ended normally
615
- */
616
- get ok() {
617
- return this[INTERNALS$1].status >= 200 && this[INTERNALS$1].status < 300;
618
- }
619
- get redirected() {
620
- return this[INTERNALS$1].counter > 0;
621
- }
622
- get statusText() {
623
- return this[INTERNALS$1].statusText;
624
- }
625
- get headers() {
626
- return this[INTERNALS$1].headers;
627
- }
628
- get highWaterMark() {
629
- return this[INTERNALS$1].highWaterMark;
630
- }
631
- /**
632
- * Clone this response
633
- *
634
- * @return Response
635
- */
636
- clone() {
637
- return new Response(clone(this, this.highWaterMark), {
638
- type: this.type,
639
- url: this.url,
640
- status: this.status,
641
- statusText: this.statusText,
642
- headers: this.headers,
643
- ok: this.ok,
644
- redirected: this.redirected,
645
- size: this.size,
646
- highWaterMark: this.highWaterMark
647
- });
648
- }
649
- /**
650
- * @param {string} url The URL that the new response is to originate from.
651
- * @param {number} status An optional status code for the response (e.g., 302.)
652
- * @returns {Response} A Response object.
653
- */
654
- static redirect(url, status = 302) {
655
- if (!isRedirect(status)) throw new RangeError("Failed to execute \"redirect\" on \"response\": Invalid status code");
656
- return new Response(null, {
657
- headers: { location: new URL(url).toString() },
658
- status
659
- });
660
- }
661
- static error() {
662
- const response = new Response(null, {
663
- status: 0,
664
- statusText: ""
665
- });
666
- response[INTERNALS$1].type = "error";
667
- return response;
668
- }
669
- static json(data = void 0, init = {}) {
670
- const body = JSON.stringify(data);
671
- if (body === void 0) throw new TypeError("data is not JSON serializable");
672
- const headers = new Headers(init && init.headers);
673
- if (!headers.has("content-type")) headers.set("content-type", "application/json");
674
- return new Response(body, {
675
- ...init,
676
- headers
677
- });
678
- }
679
- get [Symbol.toStringTag]() {
680
- return "Response";
681
- }
682
- };
683
- Object.defineProperties(Response.prototype, {
684
- type: { enumerable: true },
685
- url: { enumerable: true },
686
- status: { enumerable: true },
687
- ok: { enumerable: true },
688
- redirected: { enumerable: true },
689
- statusText: { enumerable: true },
690
- headers: { enumerable: true },
691
- clone: { enumerable: true }
692
- });
693
-
694
- //#endregion
695
- //#region node_modules/node-fetch/src/utils/get-search.js
696
- const getSearch = (parsedURL) => {
697
- if (parsedURL.search) return parsedURL.search;
698
- const lastOffset = parsedURL.href.length - 1;
699
- const hash = parsedURL.hash || (parsedURL.href[lastOffset] === "#" ? "#" : "");
700
- return parsedURL.href[lastOffset - hash.length] === "?" ? "?" : "";
701
- };
702
-
703
- //#endregion
704
- //#region node_modules/node-fetch/src/utils/referrer.js
705
- /**
706
- * @external URL
707
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/URL|URL}
708
- */
709
- /**
710
- * @module utils/referrer
711
- * @private
712
- */
713
- /**
714
- * @see {@link https://w3c.github.io/webappsec-referrer-policy/#strip-url|Referrer Policy §8.4. Strip url for use as a referrer}
715
- * @param {string} URL
716
- * @param {boolean} [originOnly=false]
717
- */
718
- function stripURLForUseAsAReferrer(url, originOnly = false) {
719
- if (url == null) return "no-referrer";
720
- url = new URL(url);
721
- if (/^(about|blob|data):$/.test(url.protocol)) return "no-referrer";
722
- url.username = "";
723
- url.password = "";
724
- url.hash = "";
725
- if (originOnly) {
726
- url.pathname = "";
727
- url.search = "";
728
- }
729
- return url;
730
- }
731
- /**
732
- * @see {@link https://w3c.github.io/webappsec-referrer-policy/#enumdef-referrerpolicy|enum ReferrerPolicy}
733
- */
734
- const ReferrerPolicy = new Set([
735
- "",
736
- "no-referrer",
737
- "no-referrer-when-downgrade",
738
- "same-origin",
739
- "origin",
740
- "strict-origin",
741
- "origin-when-cross-origin",
742
- "strict-origin-when-cross-origin",
743
- "unsafe-url"
744
- ]);
745
- /**
746
- * @see {@link https://w3c.github.io/webappsec-referrer-policy/#default-referrer-policy|default referrer policy}
747
- */
748
- const DEFAULT_REFERRER_POLICY = "strict-origin-when-cross-origin";
749
- /**
750
- * @see {@link https://w3c.github.io/webappsec-referrer-policy/#referrer-policies|Referrer Policy §3. Referrer Policies}
751
- * @param {string} referrerPolicy
752
- * @returns {string} referrerPolicy
753
- */
754
- function validateReferrerPolicy(referrerPolicy) {
755
- if (!ReferrerPolicy.has(referrerPolicy)) throw new TypeError(`Invalid referrerPolicy: ${referrerPolicy}`);
756
- return referrerPolicy;
757
- }
758
- /**
759
- * @see {@link https://w3c.github.io/webappsec-secure-contexts/#is-origin-trustworthy|Referrer Policy §3.2. Is origin potentially trustworthy?}
760
- * @param {external:URL} url
761
- * @returns `true`: "Potentially Trustworthy", `false`: "Not Trustworthy"
762
- */
763
- function isOriginPotentiallyTrustworthy(url) {
764
- if (/^(http|ws)s:$/.test(url.protocol)) return true;
765
- const hostIp = url.host.replace(/(^\[)|(]$)/g, "");
766
- const hostIPVersion = isIP(hostIp);
767
- if (hostIPVersion === 4 && /^127\./.test(hostIp)) return true;
768
- if (hostIPVersion === 6 && /^(((0+:){7})|(::(0+:){0,6}))0*1$/.test(hostIp)) return true;
769
- if (url.host === "localhost" || url.host.endsWith(".localhost")) return false;
770
- if (url.protocol === "file:") return true;
771
- return false;
772
- }
773
- /**
774
- * @see {@link https://w3c.github.io/webappsec-secure-contexts/#is-url-trustworthy|Referrer Policy §3.3. Is url potentially trustworthy?}
775
- * @param {external:URL} url
776
- * @returns `true`: "Potentially Trustworthy", `false`: "Not Trustworthy"
777
- */
778
- function isUrlPotentiallyTrustworthy(url) {
779
- if (/^about:(blank|srcdoc)$/.test(url)) return true;
780
- if (url.protocol === "data:") return true;
781
- if (/^(blob|filesystem):$/.test(url.protocol)) return true;
782
- return isOriginPotentiallyTrustworthy(url);
783
- }
784
- /**
785
- * Modifies the referrerURL to enforce any extra security policy considerations.
786
- * @see {@link https://w3c.github.io/webappsec-referrer-policy/#determine-requests-referrer|Referrer Policy §8.3. Determine request's Referrer}, step 7
787
- * @callback module:utils/referrer~referrerURLCallback
788
- * @param {external:URL} referrerURL
789
- * @returns {external:URL} modified referrerURL
790
- */
791
- /**
792
- * Modifies the referrerOrigin to enforce any extra security policy considerations.
793
- * @see {@link https://w3c.github.io/webappsec-referrer-policy/#determine-requests-referrer|Referrer Policy §8.3. Determine request's Referrer}, step 7
794
- * @callback module:utils/referrer~referrerOriginCallback
795
- * @param {external:URL} referrerOrigin
796
- * @returns {external:URL} modified referrerOrigin
797
- */
798
- /**
799
- * @see {@link https://w3c.github.io/webappsec-referrer-policy/#determine-requests-referrer|Referrer Policy §8.3. Determine request's Referrer}
800
- * @param {Request} request
801
- * @param {object} o
802
- * @param {module:utils/referrer~referrerURLCallback} o.referrerURLCallback
803
- * @param {module:utils/referrer~referrerOriginCallback} o.referrerOriginCallback
804
- * @returns {external:URL} Request's referrer
805
- */
806
- function determineRequestsReferrer(request, { referrerURLCallback, referrerOriginCallback } = {}) {
807
- if (request.referrer === "no-referrer" || request.referrerPolicy === "") return null;
808
- const policy = request.referrerPolicy;
809
- if (request.referrer === "about:client") return "no-referrer";
810
- const referrerSource = request.referrer;
811
- let referrerURL = stripURLForUseAsAReferrer(referrerSource);
812
- let referrerOrigin = stripURLForUseAsAReferrer(referrerSource, true);
813
- if (referrerURL.toString().length > 4096) referrerURL = referrerOrigin;
814
- if (referrerURLCallback) referrerURL = referrerURLCallback(referrerURL);
815
- if (referrerOriginCallback) referrerOrigin = referrerOriginCallback(referrerOrigin);
816
- const currentURL = new URL(request.url);
817
- switch (policy) {
818
- case "no-referrer": return "no-referrer";
819
- case "origin": return referrerOrigin;
820
- case "unsafe-url": return referrerURL;
821
- case "strict-origin":
822
- if (isUrlPotentiallyTrustworthy(referrerURL) && !isUrlPotentiallyTrustworthy(currentURL)) return "no-referrer";
823
- return referrerOrigin.toString();
824
- case "strict-origin-when-cross-origin":
825
- if (referrerURL.origin === currentURL.origin) return referrerURL;
826
- if (isUrlPotentiallyTrustworthy(referrerURL) && !isUrlPotentiallyTrustworthy(currentURL)) return "no-referrer";
827
- return referrerOrigin;
828
- case "same-origin":
829
- if (referrerURL.origin === currentURL.origin) return referrerURL;
830
- return "no-referrer";
831
- case "origin-when-cross-origin":
832
- if (referrerURL.origin === currentURL.origin) return referrerURL;
833
- return referrerOrigin;
834
- case "no-referrer-when-downgrade":
835
- if (isUrlPotentiallyTrustworthy(referrerURL) && !isUrlPotentiallyTrustworthy(currentURL)) return "no-referrer";
836
- return referrerURL;
837
- default: throw new TypeError(`Invalid referrerPolicy: ${policy}`);
838
- }
839
- }
840
- /**
841
- * @see {@link https://w3c.github.io/webappsec-referrer-policy/#parse-referrer-policy-from-header|Referrer Policy §8.1. Parse a referrer policy from a Referrer-Policy header}
842
- * @param {Headers} headers Response headers
843
- * @returns {string} policy
844
- */
845
- function parseReferrerPolicyFromHeader(headers) {
846
- const policyTokens = (headers.get("referrer-policy") || "").split(/[,\s]+/);
847
- let policy = "";
848
- for (const token of policyTokens) if (token && ReferrerPolicy.has(token)) policy = token;
849
- return policy;
850
- }
851
-
852
- //#endregion
853
- //#region node_modules/node-fetch/src/request.js
854
- /**
855
- * Request.js
856
- *
857
- * Request class contains server only options
858
- *
859
- * All spec algorithm step numbers are based on https://fetch.spec.whatwg.org/commit-snapshots/ae716822cb3a61843226cd090eefc6589446c1d2/.
860
- */
861
- const INTERNALS = Symbol("Request internals");
862
- /**
863
- * Check if `obj` is an instance of Request.
864
- *
865
- * @param {*} object
866
- * @return {boolean}
867
- */
868
- const isRequest = (object) => {
869
- return typeof object === "object" && typeof object[INTERNALS] === "object";
870
- };
871
- const doBadDataWarn = deprecate(() => {}, ".data is not a valid RequestInit property, use .body instead", "https://github.com/node-fetch/node-fetch/issues/1000 (request)");
872
- /**
873
- * Request class
874
- *
875
- * Ref: https://fetch.spec.whatwg.org/#request-class
876
- *
877
- * @param Mixed input Url or Request instance
878
- * @param Object init Custom options
879
- * @return Void
880
- */
881
- var Request = class Request extends Body {
882
- constructor(input, init = {}) {
883
- let parsedURL;
884
- if (isRequest(input)) parsedURL = new URL(input.url);
885
- else {
886
- parsedURL = new URL(input);
887
- input = {};
888
- }
889
- if (parsedURL.username !== "" || parsedURL.password !== "") throw new TypeError(`${parsedURL} is an url with embedded credentials.`);
890
- let method = init.method || input.method || "GET";
891
- if (/^(delete|get|head|options|post|put)$/i.test(method)) method = method.toUpperCase();
892
- if (!isRequest(init) && "data" in init) doBadDataWarn();
893
- if ((init.body != null || isRequest(input) && input.body !== null) && (method === "GET" || method === "HEAD")) throw new TypeError("Request with GET/HEAD method cannot have body");
894
- const inputBody = init.body ? init.body : isRequest(input) && input.body !== null ? clone(input) : null;
895
- super(inputBody, { size: init.size || input.size || 0 });
896
- const headers = new Headers(init.headers || input.headers || {});
897
- if (inputBody !== null && !headers.has("Content-Type")) {
898
- const contentType = extractContentType(inputBody, this);
899
- if (contentType) headers.set("Content-Type", contentType);
900
- }
901
- let signal = isRequest(input) ? input.signal : null;
902
- if ("signal" in init) signal = init.signal;
903
- if (signal != null && !isAbortSignal(signal)) throw new TypeError("Expected signal to be an instanceof AbortSignal or EventTarget");
904
- let referrer = init.referrer == null ? input.referrer : init.referrer;
905
- if (referrer === "") referrer = "no-referrer";
906
- else if (referrer) {
907
- const parsedReferrer = new URL(referrer);
908
- referrer = /^about:(\/\/)?client$/.test(parsedReferrer) ? "client" : parsedReferrer;
909
- } else referrer = void 0;
910
- this[INTERNALS] = {
911
- method,
912
- redirect: init.redirect || input.redirect || "follow",
913
- headers,
914
- parsedURL,
915
- signal,
916
- referrer
917
- };
918
- this.follow = init.follow === void 0 ? input.follow === void 0 ? 20 : input.follow : init.follow;
919
- this.compress = init.compress === void 0 ? input.compress === void 0 ? true : input.compress : init.compress;
920
- this.counter = init.counter || input.counter || 0;
921
- this.agent = init.agent || input.agent;
922
- this.highWaterMark = init.highWaterMark || input.highWaterMark || 16384;
923
- this.insecureHTTPParser = init.insecureHTTPParser || input.insecureHTTPParser || false;
924
- this.referrerPolicy = init.referrerPolicy || input.referrerPolicy || "";
925
- }
926
- /** @returns {string} */
927
- get method() {
928
- return this[INTERNALS].method;
929
- }
930
- /** @returns {string} */
931
- get url() {
932
- return format(this[INTERNALS].parsedURL);
933
- }
934
- /** @returns {Headers} */
935
- get headers() {
936
- return this[INTERNALS].headers;
937
- }
938
- get redirect() {
939
- return this[INTERNALS].redirect;
940
- }
941
- /** @returns {AbortSignal} */
942
- get signal() {
943
- return this[INTERNALS].signal;
944
- }
945
- get referrer() {
946
- if (this[INTERNALS].referrer === "no-referrer") return "";
947
- if (this[INTERNALS].referrer === "client") return "about:client";
948
- if (this[INTERNALS].referrer) return this[INTERNALS].referrer.toString();
949
- }
950
- get referrerPolicy() {
951
- return this[INTERNALS].referrerPolicy;
952
- }
953
- set referrerPolicy(referrerPolicy) {
954
- this[INTERNALS].referrerPolicy = validateReferrerPolicy(referrerPolicy);
955
- }
956
- /**
957
- * Clone this request
958
- *
959
- * @return Request
960
- */
961
- clone() {
962
- return new Request(this);
963
- }
964
- get [Symbol.toStringTag]() {
965
- return "Request";
966
- }
967
- };
968
- Object.defineProperties(Request.prototype, {
969
- method: { enumerable: true },
970
- url: { enumerable: true },
971
- headers: { enumerable: true },
972
- redirect: { enumerable: true },
973
- clone: { enumerable: true },
974
- signal: { enumerable: true },
975
- referrer: { enumerable: true },
976
- referrerPolicy: { enumerable: true }
977
- });
978
- /**
979
- * Convert a Request to Node.js http request options.
980
- *
981
- * @param {Request} request - A Request instance
982
- * @return The options object to be passed to http.request
983
- */
984
- const getNodeRequestOptions = (request) => {
985
- const { parsedURL } = request[INTERNALS];
986
- const headers = new Headers(request[INTERNALS].headers);
987
- if (!headers.has("Accept")) headers.set("Accept", "*/*");
988
- let contentLengthValue = null;
989
- if (request.body === null && /^(post|put)$/i.test(request.method)) contentLengthValue = "0";
990
- if (request.body !== null) {
991
- const totalBytes = getTotalBytes(request);
992
- if (typeof totalBytes === "number" && !Number.isNaN(totalBytes)) contentLengthValue = String(totalBytes);
993
- }
994
- if (contentLengthValue) headers.set("Content-Length", contentLengthValue);
995
- if (request.referrerPolicy === "") request.referrerPolicy = DEFAULT_REFERRER_POLICY;
996
- if (request.referrer && request.referrer !== "no-referrer") request[INTERNALS].referrer = determineRequestsReferrer(request);
997
- else request[INTERNALS].referrer = "no-referrer";
998
- if (request[INTERNALS].referrer instanceof URL) headers.set("Referer", request.referrer);
999
- if (!headers.has("User-Agent")) headers.set("User-Agent", "node-fetch");
1000
- if (request.compress && !headers.has("Accept-Encoding")) headers.set("Accept-Encoding", "gzip, deflate, br");
1001
- let { agent } = request;
1002
- if (typeof agent === "function") agent = agent(parsedURL);
1003
- const search = getSearch(parsedURL);
1004
- return {
1005
- parsedURL,
1006
- options: {
1007
- path: parsedURL.pathname + search,
1008
- method: request.method,
1009
- headers: headers[Symbol.for("nodejs.util.inspect.custom")](),
1010
- insecureHTTPParser: request.insecureHTTPParser,
1011
- agent
1012
- }
1013
- };
1014
- };
1015
-
1016
- //#endregion
1017
- //#region node_modules/node-fetch/src/errors/abort-error.js
1018
- /**
1019
- * AbortError interface for cancelled requests
1020
- */
1021
- var AbortError = class extends FetchBaseError {
1022
- constructor(message, type = "aborted") {
1023
- super(message, type);
1024
- }
1025
- };
1026
-
1027
- //#endregion
1028
- //#region node_modules/node-fetch/src/index.js
1029
- /**
1030
- * Index.js
1031
- *
1032
- * a request API compatible with window.fetch
1033
- *
1034
- * All spec algorithm step numbers are based on https://fetch.spec.whatwg.org/commit-snapshots/ae716822cb3a61843226cd090eefc6589446c1d2/.
1035
- */
1036
- const supportedSchemas = new Set([
1037
- "data:",
1038
- "http:",
1039
- "https:"
1040
- ]);
1041
- /**
1042
- * Fetch function
1043
- *
1044
- * @param {string | URL | import('./request').default} url - Absolute url or Request instance
1045
- * @param {*} [options_] - Fetch options
1046
- * @return {Promise<import('./response').default>}
1047
- */
1048
- async function fetch(url, options_) {
1049
- return new Promise((resolve, reject) => {
1050
- const request = new Request(url, options_);
1051
- const { parsedURL, options } = getNodeRequestOptions(request);
1052
- if (!supportedSchemas.has(parsedURL.protocol)) throw new TypeError(`node-fetch cannot load ${url}. URL scheme "${parsedURL.protocol.replace(/:$/, "")}" is not supported.`);
1053
- if (parsedURL.protocol === "data:") {
1054
- const data = dataUriToBuffer(request.url);
1055
- resolve(new Response(data, { headers: { "Content-Type": data.typeFull } }));
1056
- return;
1057
- }
1058
- const send = (parsedURL.protocol === "https:" ? https : http).request;
1059
- const { signal } = request;
1060
- let response = null;
1061
- const abort = () => {
1062
- const error = new AbortError("The operation was aborted.");
1063
- reject(error);
1064
- if (request.body && request.body instanceof Stream.Readable) request.body.destroy(error);
1065
- if (!response || !response.body) return;
1066
- response.body.emit("error", error);
1067
- };
1068
- if (signal && signal.aborted) {
1069
- abort();
1070
- return;
1071
- }
1072
- const abortAndFinalize = () => {
1073
- abort();
1074
- finalize();
1075
- };
1076
- const request_ = send(parsedURL.toString(), options);
1077
- if (signal) signal.addEventListener("abort", abortAndFinalize);
1078
- const finalize = () => {
1079
- request_.abort();
1080
- if (signal) signal.removeEventListener("abort", abortAndFinalize);
1081
- };
1082
- request_.on("error", (error) => {
1083
- reject(new FetchError(`request to ${request.url} failed, reason: ${error.message}`, "system", error));
1084
- finalize();
1085
- });
1086
- fixResponseChunkedTransferBadEnding(request_, (error) => {
1087
- if (response && response.body) response.body.destroy(error);
1088
- });
1089
- /* c8 ignore next 18 */
1090
- if (process.version < "v14") request_.on("socket", (s) => {
1091
- let endedWithEventsCount;
1092
- s.prependListener("end", () => {
1093
- endedWithEventsCount = s._eventsCount;
1094
- });
1095
- s.prependListener("close", (hadError) => {
1096
- if (response && endedWithEventsCount < s._eventsCount && !hadError) {
1097
- const error = /* @__PURE__ */ new Error("Premature close");
1098
- error.code = "ERR_STREAM_PREMATURE_CLOSE";
1099
- response.body.emit("error", error);
1100
- }
1101
- });
1102
- });
1103
- request_.on("response", (response_) => {
1104
- request_.setTimeout(0);
1105
- const headers = fromRawHeaders(response_.rawHeaders);
1106
- if (isRedirect(response_.statusCode)) {
1107
- const location = headers.get("Location");
1108
- let locationURL = null;
1109
- try {
1110
- locationURL = location === null ? null : new URL(location, request.url);
1111
- } catch {
1112
- if (request.redirect !== "manual") {
1113
- reject(new FetchError(`uri requested responds with an invalid redirect URL: ${location}`, "invalid-redirect"));
1114
- finalize();
1115
- return;
1116
- }
1117
- }
1118
- switch (request.redirect) {
1119
- case "error":
1120
- reject(new FetchError(`uri requested responds with a redirect, redirect mode is set to error: ${request.url}`, "no-redirect"));
1121
- finalize();
1122
- return;
1123
- case "manual": break;
1124
- case "follow": {
1125
- if (locationURL === null) break;
1126
- if (request.counter >= request.follow) {
1127
- reject(new FetchError(`maximum redirect reached at: ${request.url}`, "max-redirect"));
1128
- finalize();
1129
- return;
1130
- }
1131
- const requestOptions = {
1132
- headers: new Headers(request.headers),
1133
- follow: request.follow,
1134
- counter: request.counter + 1,
1135
- agent: request.agent,
1136
- compress: request.compress,
1137
- method: request.method,
1138
- body: clone(request),
1139
- signal: request.signal,
1140
- size: request.size,
1141
- referrer: request.referrer,
1142
- referrerPolicy: request.referrerPolicy
1143
- };
1144
- if (!isDomainOrSubdomain(request.url, locationURL) || !isSameProtocol(request.url, locationURL)) for (const name of [
1145
- "authorization",
1146
- "www-authenticate",
1147
- "cookie",
1148
- "cookie2"
1149
- ]) requestOptions.headers.delete(name);
1150
- if (response_.statusCode !== 303 && request.body && options_.body instanceof Stream.Readable) {
1151
- reject(new FetchError("Cannot follow redirect with body being a readable stream", "unsupported-redirect"));
1152
- finalize();
1153
- return;
1154
- }
1155
- if (response_.statusCode === 303 || (response_.statusCode === 301 || response_.statusCode === 302) && request.method === "POST") {
1156
- requestOptions.method = "GET";
1157
- requestOptions.body = void 0;
1158
- requestOptions.headers.delete("content-length");
1159
- }
1160
- const responseReferrerPolicy = parseReferrerPolicyFromHeader(headers);
1161
- if (responseReferrerPolicy) requestOptions.referrerPolicy = responseReferrerPolicy;
1162
- resolve(fetch(new Request(locationURL, requestOptions)));
1163
- finalize();
1164
- return;
1165
- }
1166
- default: return reject(/* @__PURE__ */ new TypeError(`Redirect option '${request.redirect}' is not a valid value of RequestRedirect`));
1167
- }
1168
- }
1169
- if (signal) response_.once("end", () => {
1170
- signal.removeEventListener("abort", abortAndFinalize);
1171
- });
1172
- let body = pipeline(response_, new PassThrough(), (error) => {
1173
- if (error) reject(error);
1174
- });
1175
- /* c8 ignore next 3 */
1176
- if (process.version < "v12.10") response_.on("aborted", abortAndFinalize);
1177
- const responseOptions = {
1178
- url: request.url,
1179
- status: response_.statusCode,
1180
- statusText: response_.statusMessage,
1181
- headers,
1182
- size: request.size,
1183
- counter: request.counter,
1184
- highWaterMark: request.highWaterMark
1185
- };
1186
- const codings = headers.get("Content-Encoding");
1187
- if (!request.compress || request.method === "HEAD" || codings === null || response_.statusCode === 204 || response_.statusCode === 304) {
1188
- response = new Response(body, responseOptions);
1189
- resolve(response);
1190
- return;
1191
- }
1192
- const zlibOptions = {
1193
- flush: zlib.Z_SYNC_FLUSH,
1194
- finishFlush: zlib.Z_SYNC_FLUSH
1195
- };
1196
- if (codings === "gzip" || codings === "x-gzip") {
1197
- body = pipeline(body, zlib.createGunzip(zlibOptions), (error) => {
1198
- if (error) reject(error);
1199
- });
1200
- response = new Response(body, responseOptions);
1201
- resolve(response);
1202
- return;
1203
- }
1204
- if (codings === "deflate" || codings === "x-deflate") {
1205
- const raw = pipeline(response_, new PassThrough(), (error) => {
1206
- if (error) reject(error);
1207
- });
1208
- raw.once("data", (chunk) => {
1209
- if ((chunk[0] & 15) === 8) body = pipeline(body, zlib.createInflate(), (error) => {
1210
- if (error) reject(error);
1211
- });
1212
- else body = pipeline(body, zlib.createInflateRaw(), (error) => {
1213
- if (error) reject(error);
1214
- });
1215
- response = new Response(body, responseOptions);
1216
- resolve(response);
1217
- });
1218
- raw.once("end", () => {
1219
- if (!response) {
1220
- response = new Response(body, responseOptions);
1221
- resolve(response);
1222
- }
1223
- });
1224
- return;
1225
- }
1226
- if (codings === "br") {
1227
- body = pipeline(body, zlib.createBrotliDecompress(), (error) => {
1228
- if (error) reject(error);
1229
- });
1230
- response = new Response(body, responseOptions);
1231
- resolve(response);
1232
- return;
1233
- }
1234
- response = new Response(body, responseOptions);
1235
- resolve(response);
1236
- });
1237
- writeToStream(request_, request).catch(reject);
1238
- });
1239
- }
1240
- function fixResponseChunkedTransferBadEnding(request, errorCallback) {
1241
- const LAST_CHUNK = Buffer$1.from("0\r\n\r\n");
1242
- let isChunkedTransfer = false;
1243
- let properLastChunkReceived = false;
1244
- let previousChunk;
1245
- request.on("response", (response) => {
1246
- const { headers } = response;
1247
- isChunkedTransfer = headers["transfer-encoding"] === "chunked" && !headers["content-length"];
1248
- });
1249
- request.on("socket", (socket) => {
1250
- const onSocketClose = () => {
1251
- if (isChunkedTransfer && !properLastChunkReceived) {
1252
- const error = /* @__PURE__ */ new Error("Premature close");
1253
- error.code = "ERR_STREAM_PREMATURE_CLOSE";
1254
- errorCallback(error);
1255
- }
1256
- };
1257
- const onData = (buf) => {
1258
- properLastChunkReceived = Buffer$1.compare(buf.slice(-5), LAST_CHUNK) === 0;
1259
- if (!properLastChunkReceived && previousChunk) properLastChunkReceived = Buffer$1.compare(previousChunk.slice(-3), LAST_CHUNK.slice(0, 3)) === 0 && Buffer$1.compare(buf.slice(-2), LAST_CHUNK.slice(3)) === 0;
1260
- previousChunk = buf;
1261
- };
1262
- socket.prependListener("close", onSocketClose);
1263
- socket.on("data", onData);
1264
- request.on("close", () => {
1265
- socket.removeListener("close", onSocketClose);
1266
- socket.removeListener("data", onData);
1267
- });
1268
- });
1269
- }
1270
-
1271
- //#endregion
1272
- export { fetch as default };