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