unplugin-dingtalk 1003.1.0 → 1004.0.0

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.
@@ -1,1813 +0,0 @@
1
- import {
2
- FormData,
3
- fetch_blob_default,
4
- formDataToBlob
5
- } from "./chunk-A2RZ6ACY.js";
6
- import {
7
- __forAwait,
8
- __spreadProps,
9
- __spreadValues
10
- } from "./chunk-MCTMMV5B.js";
11
-
12
- // src/index.ts
13
- import process2 from "node:process";
14
- import { ServerResponse } from "node:http";
15
- import { Socket } from "node:net";
16
-
17
- // node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/index.js
18
- import http2 from "node:http";
19
- import https from "node:https";
20
- import zlib from "node:zlib";
21
- import Stream2, { PassThrough as PassThrough2, pipeline as pump } from "node:stream";
22
- import { Buffer as Buffer3 } from "node:buffer";
23
-
24
- // node_modules/.pnpm/data-uri-to-buffer@4.0.1/node_modules/data-uri-to-buffer/dist/index.js
25
- function dataUriToBuffer(uri) {
26
- if (!/^data:/i.test(uri)) {
27
- throw new TypeError('`uri` does not appear to be a Data URI (must begin with "data:")');
28
- }
29
- uri = uri.replace(/\r?\n/g, "");
30
- const firstComma = uri.indexOf(",");
31
- if (firstComma === -1 || firstComma <= 4) {
32
- throw new TypeError("malformed data: URI");
33
- }
34
- const meta = uri.substring(5, firstComma).split(";");
35
- let charset = "";
36
- let base64 = false;
37
- const type = meta[0] || "text/plain";
38
- let typeFull = type;
39
- for (let i = 1; i < meta.length; i++) {
40
- if (meta[i] === "base64") {
41
- base64 = true;
42
- } else if (meta[i]) {
43
- typeFull += `;${meta[i]}`;
44
- if (meta[i].indexOf("charset=") === 0) {
45
- charset = meta[i].substring(8);
46
- }
47
- }
48
- }
49
- if (!meta[0] && !charset.length) {
50
- typeFull += ";charset=US-ASCII";
51
- charset = "US-ASCII";
52
- }
53
- const encoding = base64 ? "base64" : "ascii";
54
- const data = unescape(uri.substring(firstComma + 1));
55
- const buffer = Buffer.from(data, encoding);
56
- buffer.type = type;
57
- buffer.typeFull = typeFull;
58
- buffer.charset = charset;
59
- return buffer;
60
- }
61
- var dist_default = dataUriToBuffer;
62
-
63
- // node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/body.js
64
- import Stream, { PassThrough } from "node:stream";
65
- import { types, deprecate, promisify } from "node:util";
66
- import { Buffer as Buffer2 } from "node:buffer";
67
-
68
- // node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/errors/base.js
69
- var FetchBaseError = class extends Error {
70
- constructor(message, type) {
71
- super(message);
72
- Error.captureStackTrace(this, this.constructor);
73
- this.type = type;
74
- }
75
- get name() {
76
- return this.constructor.name;
77
- }
78
- get [Symbol.toStringTag]() {
79
- return this.constructor.name;
80
- }
81
- };
82
-
83
- // node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/errors/fetch-error.js
84
- var FetchError = class extends FetchBaseError {
85
- /**
86
- * @param {string} message - Error message for human
87
- * @param {string} [type] - Error type for machine
88
- * @param {SystemError} [systemError] - For Node.js system error
89
- */
90
- constructor(message, type, systemError) {
91
- super(message, type);
92
- if (systemError) {
93
- this.code = this.errno = systemError.code;
94
- this.erroredSysCall = systemError.syscall;
95
- }
96
- }
97
- };
98
-
99
- // node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/utils/is.js
100
- var NAME = Symbol.toStringTag;
101
- var isURLSearchParameters = (object) => {
102
- 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";
103
- };
104
- var isBlob = (object) => {
105
- 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]);
106
- };
107
- var isAbortSignal = (object) => {
108
- return typeof object === "object" && (object[NAME] === "AbortSignal" || object[NAME] === "EventTarget");
109
- };
110
- var isDomainOrSubdomain = (destination, original) => {
111
- const orig = new URL(original).hostname;
112
- const dest = new URL(destination).hostname;
113
- return orig === dest || orig.endsWith(`.${dest}`);
114
- };
115
- var isSameProtocol = (destination, original) => {
116
- const orig = new URL(original).protocol;
117
- const dest = new URL(destination).protocol;
118
- return orig === dest;
119
- };
120
-
121
- // node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/body.js
122
- var pipeline = promisify(Stream.pipeline);
123
- var INTERNALS = Symbol("Body internals");
124
- var Body = class {
125
- constructor(body, {
126
- size = 0
127
- } = {}) {
128
- let boundary = null;
129
- if (body === null) {
130
- body = null;
131
- } else if (isURLSearchParameters(body)) {
132
- body = Buffer2.from(body.toString());
133
- } else if (isBlob(body)) {
134
- } else if (Buffer2.isBuffer(body)) {
135
- } else if (types.isAnyArrayBuffer(body)) {
136
- body = Buffer2.from(body);
137
- } else if (ArrayBuffer.isView(body)) {
138
- body = Buffer2.from(body.buffer, body.byteOffset, body.byteLength);
139
- } else if (body instanceof Stream) {
140
- } else if (body instanceof FormData) {
141
- body = formDataToBlob(body);
142
- boundary = body.type.split("=")[1];
143
- } else {
144
- body = Buffer2.from(String(body));
145
- }
146
- let stream = body;
147
- if (Buffer2.isBuffer(body)) {
148
- stream = Stream.Readable.from(body);
149
- } else if (isBlob(body)) {
150
- stream = Stream.Readable.from(body.stream());
151
- }
152
- this[INTERNALS] = {
153
- body,
154
- stream,
155
- boundary,
156
- disturbed: false,
157
- error: null
158
- };
159
- this.size = size;
160
- if (body instanceof Stream) {
161
- body.on("error", (error_) => {
162
- const error = error_ instanceof FetchBaseError ? error_ : new FetchError(`Invalid response body while trying to fetch ${this.url}: ${error_.message}`, "system", error_);
163
- this[INTERNALS].error = error;
164
- });
165
- }
166
- }
167
- get body() {
168
- return this[INTERNALS].stream;
169
- }
170
- get bodyUsed() {
171
- return this[INTERNALS].disturbed;
172
- }
173
- /**
174
- * Decode response as ArrayBuffer
175
- *
176
- * @return Promise
177
- */
178
- async arrayBuffer() {
179
- const { buffer, byteOffset, byteLength } = await consumeBody(this);
180
- return buffer.slice(byteOffset, byteOffset + byteLength);
181
- }
182
- async formData() {
183
- const ct = this.headers.get("content-type");
184
- if (ct.startsWith("application/x-www-form-urlencoded")) {
185
- const formData = new FormData();
186
- const parameters = new URLSearchParams(await this.text());
187
- for (const [name, value] of parameters) {
188
- formData.append(name, value);
189
- }
190
- return formData;
191
- }
192
- const { toFormData } = await import("./multipart-parser-WSPU7YI5.js");
193
- return toFormData(this.body, ct);
194
- }
195
- /**
196
- * Return raw response as Blob
197
- *
198
- * @return Promise
199
- */
200
- async blob() {
201
- const ct = this.headers && this.headers.get("content-type") || this[INTERNALS].body && this[INTERNALS].body.type || "";
202
- const buf = await this.arrayBuffer();
203
- return new fetch_blob_default([buf], {
204
- type: ct
205
- });
206
- }
207
- /**
208
- * Decode response as json
209
- *
210
- * @return Promise
211
- */
212
- async json() {
213
- const text = await this.text();
214
- return JSON.parse(text);
215
- }
216
- /**
217
- * Decode response as text
218
- *
219
- * @return Promise
220
- */
221
- async text() {
222
- const buffer = await consumeBody(this);
223
- return new TextDecoder().decode(buffer);
224
- }
225
- /**
226
- * Decode response as buffer (non-spec api)
227
- *
228
- * @return Promise
229
- */
230
- buffer() {
231
- return consumeBody(this);
232
- }
233
- };
234
- Body.prototype.buffer = deprecate(Body.prototype.buffer, "Please use 'response.arrayBuffer()' instead of 'response.buffer()'", "node-fetch#buffer");
235
- Object.defineProperties(Body.prototype, {
236
- body: { enumerable: true },
237
- bodyUsed: { enumerable: true },
238
- arrayBuffer: { enumerable: true },
239
- blob: { enumerable: true },
240
- json: { enumerable: true },
241
- text: { enumerable: true },
242
- data: { get: deprecate(
243
- () => {
244
- },
245
- "data doesn't exist, use json(), text(), arrayBuffer(), or body instead",
246
- "https://github.com/node-fetch/node-fetch/issues/1000 (response)"
247
- ) }
248
- });
249
- async function consumeBody(data) {
250
- if (data[INTERNALS].disturbed) {
251
- throw new TypeError(`body used already for: ${data.url}`);
252
- }
253
- data[INTERNALS].disturbed = true;
254
- if (data[INTERNALS].error) {
255
- throw data[INTERNALS].error;
256
- }
257
- const { body } = data;
258
- if (body === null) {
259
- return Buffer2.alloc(0);
260
- }
261
- if (!(body instanceof Stream)) {
262
- return Buffer2.alloc(0);
263
- }
264
- const accum = [];
265
- let accumBytes = 0;
266
- try {
267
- try {
268
- for (var iter = __forAwait(body), more, temp, error; more = !(temp = await iter.next()).done; more = false) {
269
- const chunk = temp.value;
270
- if (data.size > 0 && accumBytes + chunk.length > data.size) {
271
- const error2 = new FetchError(`content size at ${data.url} over limit: ${data.size}`, "max-size");
272
- body.destroy(error2);
273
- throw error2;
274
- }
275
- accumBytes += chunk.length;
276
- accum.push(chunk);
277
- }
278
- } catch (temp) {
279
- error = [temp];
280
- } finally {
281
- try {
282
- more && (temp = iter.return) && await temp.call(iter);
283
- } finally {
284
- if (error)
285
- throw error[0];
286
- }
287
- }
288
- } catch (error2) {
289
- const error_ = error2 instanceof FetchBaseError ? error2 : new FetchError(`Invalid response body while trying to fetch ${data.url}: ${error2.message}`, "system", error2);
290
- throw error_;
291
- }
292
- if (body.readableEnded === true || body._readableState.ended === true) {
293
- try {
294
- if (accum.every((c2) => typeof c2 === "string")) {
295
- return Buffer2.from(accum.join(""));
296
- }
297
- return Buffer2.concat(accum, accumBytes);
298
- } catch (error2) {
299
- throw new FetchError(`Could not create Buffer from response body for ${data.url}: ${error2.message}`, "system", error2);
300
- }
301
- } else {
302
- throw new FetchError(`Premature close of server response while trying to fetch ${data.url}`);
303
- }
304
- }
305
- var clone = (instance, highWaterMark) => {
306
- let p1;
307
- let p2;
308
- let { body } = instance[INTERNALS];
309
- if (instance.bodyUsed) {
310
- throw new Error("cannot clone body after it is used");
311
- }
312
- if (body instanceof Stream && typeof body.getBoundary !== "function") {
313
- p1 = new PassThrough({ highWaterMark });
314
- p2 = new PassThrough({ highWaterMark });
315
- body.pipe(p1);
316
- body.pipe(p2);
317
- instance[INTERNALS].stream = p1;
318
- body = p2;
319
- }
320
- return body;
321
- };
322
- var getNonSpecFormDataBoundary = deprecate(
323
- (body) => body.getBoundary(),
324
- "form-data doesn't follow the spec and requires special treatment. Use alternative package",
325
- "https://github.com/node-fetch/node-fetch/issues/1167"
326
- );
327
- var extractContentType = (body, request) => {
328
- if (body === null) {
329
- return null;
330
- }
331
- if (typeof body === "string") {
332
- return "text/plain;charset=UTF-8";
333
- }
334
- if (isURLSearchParameters(body)) {
335
- return "application/x-www-form-urlencoded;charset=UTF-8";
336
- }
337
- if (isBlob(body)) {
338
- return body.type || null;
339
- }
340
- if (Buffer2.isBuffer(body) || types.isAnyArrayBuffer(body) || ArrayBuffer.isView(body)) {
341
- return null;
342
- }
343
- if (body instanceof FormData) {
344
- return `multipart/form-data; boundary=${request[INTERNALS].boundary}`;
345
- }
346
- if (body && typeof body.getBoundary === "function") {
347
- return `multipart/form-data;boundary=${getNonSpecFormDataBoundary(body)}`;
348
- }
349
- if (body instanceof Stream) {
350
- return null;
351
- }
352
- return "text/plain;charset=UTF-8";
353
- };
354
- var getTotalBytes = (request) => {
355
- const { body } = request[INTERNALS];
356
- if (body === null) {
357
- return 0;
358
- }
359
- if (isBlob(body)) {
360
- return body.size;
361
- }
362
- if (Buffer2.isBuffer(body)) {
363
- return body.length;
364
- }
365
- if (body && typeof body.getLengthSync === "function") {
366
- return body.hasKnownLength && body.hasKnownLength() ? body.getLengthSync() : null;
367
- }
368
- return null;
369
- };
370
- var writeToStream = async (dest, { body }) => {
371
- if (body === null) {
372
- dest.end();
373
- } else {
374
- await pipeline(body, dest);
375
- }
376
- };
377
-
378
- // node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/headers.js
379
- import { types as types2 } from "node:util";
380
- import http from "node:http";
381
- var validateHeaderName = typeof http.validateHeaderName === "function" ? http.validateHeaderName : (name) => {
382
- if (!/^[\^`\-\w!#$%&'*+.|~]+$/.test(name)) {
383
- const error = new TypeError(`Header name must be a valid HTTP token [${name}]`);
384
- Object.defineProperty(error, "code", { value: "ERR_INVALID_HTTP_TOKEN" });
385
- throw error;
386
- }
387
- };
388
- var validateHeaderValue = typeof http.validateHeaderValue === "function" ? http.validateHeaderValue : (name, value) => {
389
- if (/[^\t\u0020-\u007E\u0080-\u00FF]/.test(value)) {
390
- const error = new TypeError(`Invalid character in header content ["${name}"]`);
391
- Object.defineProperty(error, "code", { value: "ERR_INVALID_CHAR" });
392
- throw error;
393
- }
394
- };
395
- var Headers = class _Headers extends URLSearchParams {
396
- /**
397
- * Headers class
398
- *
399
- * @constructor
400
- * @param {HeadersInit} [init] - Response headers
401
- */
402
- constructor(init) {
403
- let result = [];
404
- if (init instanceof _Headers) {
405
- const raw = init.raw();
406
- for (const [name, values] of Object.entries(raw)) {
407
- result.push(...values.map((value) => [name, value]));
408
- }
409
- } else if (init == null) {
410
- } else if (typeof init === "object" && !types2.isBoxedPrimitive(init)) {
411
- const method = init[Symbol.iterator];
412
- if (method == null) {
413
- result.push(...Object.entries(init));
414
- } else {
415
- if (typeof method !== "function") {
416
- throw new TypeError("Header pairs must be iterable");
417
- }
418
- result = [...init].map((pair) => {
419
- if (typeof pair !== "object" || types2.isBoxedPrimitive(pair)) {
420
- throw new TypeError("Each header pair must be an iterable object");
421
- }
422
- return [...pair];
423
- }).map((pair) => {
424
- if (pair.length !== 2) {
425
- throw new TypeError("Each header pair must be a name/value tuple");
426
- }
427
- return [...pair];
428
- });
429
- }
430
- } else {
431
- throw new TypeError("Failed to construct 'Headers': The provided value is not of type '(sequence<sequence<ByteString>> or record<ByteString, ByteString>)");
432
- }
433
- result = result.length > 0 ? result.map(([name, value]) => {
434
- validateHeaderName(name);
435
- validateHeaderValue(name, String(value));
436
- return [String(name).toLowerCase(), String(value)];
437
- }) : void 0;
438
- super(result);
439
- return new Proxy(this, {
440
- get(target, p, receiver) {
441
- switch (p) {
442
- case "append":
443
- case "set":
444
- return (name, value) => {
445
- validateHeaderName(name);
446
- validateHeaderValue(name, String(value));
447
- return URLSearchParams.prototype[p].call(
448
- target,
449
- String(name).toLowerCase(),
450
- String(value)
451
- );
452
- };
453
- case "delete":
454
- case "has":
455
- case "getAll":
456
- return (name) => {
457
- validateHeaderName(name);
458
- return URLSearchParams.prototype[p].call(
459
- target,
460
- String(name).toLowerCase()
461
- );
462
- };
463
- case "keys":
464
- return () => {
465
- target.sort();
466
- return new Set(URLSearchParams.prototype.keys.call(target)).keys();
467
- };
468
- default:
469
- return Reflect.get(target, p, receiver);
470
- }
471
- }
472
- });
473
- }
474
- get [Symbol.toStringTag]() {
475
- return this.constructor.name;
476
- }
477
- toString() {
478
- return Object.prototype.toString.call(this);
479
- }
480
- get(name) {
481
- const values = this.getAll(name);
482
- if (values.length === 0) {
483
- return null;
484
- }
485
- let value = values.join(", ");
486
- if (/^content-encoding$/i.test(name)) {
487
- value = value.toLowerCase();
488
- }
489
- return value;
490
- }
491
- forEach(callback, thisArg = void 0) {
492
- for (const name of this.keys()) {
493
- Reflect.apply(callback, thisArg, [this.get(name), name, this]);
494
- }
495
- }
496
- *values() {
497
- for (const name of this.keys()) {
498
- yield this.get(name);
499
- }
500
- }
501
- /**
502
- * @type {() => IterableIterator<[string, string]>}
503
- */
504
- *entries() {
505
- for (const name of this.keys()) {
506
- yield [name, this.get(name)];
507
- }
508
- }
509
- [Symbol.iterator]() {
510
- return this.entries();
511
- }
512
- /**
513
- * Node-fetch non-spec method
514
- * returning all headers and their values as array
515
- * @returns {Record<string, string[]>}
516
- */
517
- raw() {
518
- return [...this.keys()].reduce((result, key) => {
519
- result[key] = this.getAll(key);
520
- return result;
521
- }, {});
522
- }
523
- /**
524
- * For better console.log(headers) and also to convert Headers into Node.js Request compatible format
525
- */
526
- [Symbol.for("nodejs.util.inspect.custom")]() {
527
- return [...this.keys()].reduce((result, key) => {
528
- const values = this.getAll(key);
529
- if (key === "host") {
530
- result[key] = values[0];
531
- } else {
532
- result[key] = values.length > 1 ? values : values[0];
533
- }
534
- return result;
535
- }, {});
536
- }
537
- };
538
- Object.defineProperties(
539
- Headers.prototype,
540
- ["get", "entries", "forEach", "values"].reduce((result, property) => {
541
- result[property] = { enumerable: true };
542
- return result;
543
- }, {})
544
- );
545
- function fromRawHeaders(headers = []) {
546
- return new Headers(
547
- headers.reduce((result, value, index, array) => {
548
- if (index % 2 === 0) {
549
- result.push(array.slice(index, index + 2));
550
- }
551
- return result;
552
- }, []).filter(([name, value]) => {
553
- try {
554
- validateHeaderName(name);
555
- validateHeaderValue(name, String(value));
556
- return true;
557
- } catch (e) {
558
- return false;
559
- }
560
- })
561
- );
562
- }
563
-
564
- // node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/utils/is-redirect.js
565
- var redirectStatus = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
566
- var isRedirect = (code) => {
567
- return redirectStatus.has(code);
568
- };
569
-
570
- // node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/response.js
571
- var INTERNALS2 = Symbol("Response internals");
572
- var Response = class _Response extends Body {
573
- constructor(body = null, options = {}) {
574
- super(body, options);
575
- const status = options.status != null ? options.status : 200;
576
- const headers = new Headers(options.headers);
577
- if (body !== null && !headers.has("Content-Type")) {
578
- const contentType = extractContentType(body, this);
579
- if (contentType) {
580
- headers.append("Content-Type", contentType);
581
- }
582
- }
583
- this[INTERNALS2] = {
584
- type: "default",
585
- url: options.url,
586
- status,
587
- statusText: options.statusText || "",
588
- headers,
589
- counter: options.counter,
590
- highWaterMark: options.highWaterMark
591
- };
592
- }
593
- get type() {
594
- return this[INTERNALS2].type;
595
- }
596
- get url() {
597
- return this[INTERNALS2].url || "";
598
- }
599
- get status() {
600
- return this[INTERNALS2].status;
601
- }
602
- /**
603
- * Convenience property representing if the request ended normally
604
- */
605
- get ok() {
606
- return this[INTERNALS2].status >= 200 && this[INTERNALS2].status < 300;
607
- }
608
- get redirected() {
609
- return this[INTERNALS2].counter > 0;
610
- }
611
- get statusText() {
612
- return this[INTERNALS2].statusText;
613
- }
614
- get headers() {
615
- return this[INTERNALS2].headers;
616
- }
617
- get highWaterMark() {
618
- return this[INTERNALS2].highWaterMark;
619
- }
620
- /**
621
- * Clone this response
622
- *
623
- * @return Response
624
- */
625
- clone() {
626
- return new _Response(clone(this, this.highWaterMark), {
627
- type: this.type,
628
- url: this.url,
629
- status: this.status,
630
- statusText: this.statusText,
631
- headers: this.headers,
632
- ok: this.ok,
633
- redirected: this.redirected,
634
- size: this.size,
635
- highWaterMark: this.highWaterMark
636
- });
637
- }
638
- /**
639
- * @param {string} url The URL that the new response is to originate from.
640
- * @param {number} status An optional status code for the response (e.g., 302.)
641
- * @returns {Response} A Response object.
642
- */
643
- static redirect(url, status = 302) {
644
- if (!isRedirect(status)) {
645
- throw new RangeError('Failed to execute "redirect" on "response": Invalid status code');
646
- }
647
- return new _Response(null, {
648
- headers: {
649
- location: new URL(url).toString()
650
- },
651
- status
652
- });
653
- }
654
- static error() {
655
- const response = new _Response(null, { status: 0, statusText: "" });
656
- response[INTERNALS2].type = "error";
657
- return response;
658
- }
659
- static json(data = void 0, init = {}) {
660
- const body = JSON.stringify(data);
661
- if (body === void 0) {
662
- throw new TypeError("data is not JSON serializable");
663
- }
664
- const headers = new Headers(init && init.headers);
665
- if (!headers.has("content-type")) {
666
- headers.set("content-type", "application/json");
667
- }
668
- return new _Response(body, __spreadProps(__spreadValues({}, init), {
669
- headers
670
- }));
671
- }
672
- get [Symbol.toStringTag]() {
673
- return "Response";
674
- }
675
- };
676
- Object.defineProperties(Response.prototype, {
677
- type: { enumerable: true },
678
- url: { enumerable: true },
679
- status: { enumerable: true },
680
- ok: { enumerable: true },
681
- redirected: { enumerable: true },
682
- statusText: { enumerable: true },
683
- headers: { enumerable: true },
684
- clone: { enumerable: true }
685
- });
686
-
687
- // node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/request.js
688
- import { format as formatUrl } from "node:url";
689
- import { deprecate as deprecate2 } from "node:util";
690
-
691
- // node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/utils/get-search.js
692
- var getSearch = (parsedURL) => {
693
- if (parsedURL.search) {
694
- return parsedURL.search;
695
- }
696
- const lastOffset = parsedURL.href.length - 1;
697
- const hash = parsedURL.hash || (parsedURL.href[lastOffset] === "#" ? "#" : "");
698
- return parsedURL.href[lastOffset - hash.length] === "?" ? "?" : "";
699
- };
700
-
701
- // node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/utils/referrer.js
702
- import { isIP } from "node:net";
703
- function stripURLForUseAsAReferrer(url, originOnly = false) {
704
- if (url == null) {
705
- return "no-referrer";
706
- }
707
- url = new URL(url);
708
- if (/^(about|blob|data):$/.test(url.protocol)) {
709
- return "no-referrer";
710
- }
711
- url.username = "";
712
- url.password = "";
713
- url.hash = "";
714
- if (originOnly) {
715
- url.pathname = "";
716
- url.search = "";
717
- }
718
- return url;
719
- }
720
- var ReferrerPolicy = /* @__PURE__ */ new Set([
721
- "",
722
- "no-referrer",
723
- "no-referrer-when-downgrade",
724
- "same-origin",
725
- "origin",
726
- "strict-origin",
727
- "origin-when-cross-origin",
728
- "strict-origin-when-cross-origin",
729
- "unsafe-url"
730
- ]);
731
- var DEFAULT_REFERRER_POLICY = "strict-origin-when-cross-origin";
732
- function validateReferrerPolicy(referrerPolicy) {
733
- if (!ReferrerPolicy.has(referrerPolicy)) {
734
- throw new TypeError(`Invalid referrerPolicy: ${referrerPolicy}`);
735
- }
736
- return referrerPolicy;
737
- }
738
- function isOriginPotentiallyTrustworthy(url) {
739
- if (/^(http|ws)s:$/.test(url.protocol)) {
740
- return true;
741
- }
742
- const hostIp = url.host.replace(/(^\[)|(]$)/g, "");
743
- const hostIPVersion = isIP(hostIp);
744
- if (hostIPVersion === 4 && /^127\./.test(hostIp)) {
745
- return true;
746
- }
747
- if (hostIPVersion === 6 && /^(((0+:){7})|(::(0+:){0,6}))0*1$/.test(hostIp)) {
748
- return true;
749
- }
750
- if (url.host === "localhost" || url.host.endsWith(".localhost")) {
751
- return false;
752
- }
753
- if (url.protocol === "file:") {
754
- return true;
755
- }
756
- return false;
757
- }
758
- function isUrlPotentiallyTrustworthy(url) {
759
- if (/^about:(blank|srcdoc)$/.test(url)) {
760
- return true;
761
- }
762
- if (url.protocol === "data:") {
763
- return true;
764
- }
765
- if (/^(blob|filesystem):$/.test(url.protocol)) {
766
- return true;
767
- }
768
- return isOriginPotentiallyTrustworthy(url);
769
- }
770
- function determineRequestsReferrer(request, { referrerURLCallback, referrerOriginCallback } = {}) {
771
- if (request.referrer === "no-referrer" || request.referrerPolicy === "") {
772
- return null;
773
- }
774
- const policy = request.referrerPolicy;
775
- if (request.referrer === "about:client") {
776
- return "no-referrer";
777
- }
778
- const referrerSource = request.referrer;
779
- let referrerURL = stripURLForUseAsAReferrer(referrerSource);
780
- let referrerOrigin = stripURLForUseAsAReferrer(referrerSource, true);
781
- if (referrerURL.toString().length > 4096) {
782
- referrerURL = referrerOrigin;
783
- }
784
- if (referrerURLCallback) {
785
- referrerURL = referrerURLCallback(referrerURL);
786
- }
787
- if (referrerOriginCallback) {
788
- referrerOrigin = referrerOriginCallback(referrerOrigin);
789
- }
790
- const currentURL = new URL(request.url);
791
- switch (policy) {
792
- case "no-referrer":
793
- return "no-referrer";
794
- case "origin":
795
- return referrerOrigin;
796
- case "unsafe-url":
797
- return referrerURL;
798
- case "strict-origin":
799
- if (isUrlPotentiallyTrustworthy(referrerURL) && !isUrlPotentiallyTrustworthy(currentURL)) {
800
- return "no-referrer";
801
- }
802
- return referrerOrigin.toString();
803
- case "strict-origin-when-cross-origin":
804
- if (referrerURL.origin === currentURL.origin) {
805
- return referrerURL;
806
- }
807
- if (isUrlPotentiallyTrustworthy(referrerURL) && !isUrlPotentiallyTrustworthy(currentURL)) {
808
- return "no-referrer";
809
- }
810
- return referrerOrigin;
811
- case "same-origin":
812
- if (referrerURL.origin === currentURL.origin) {
813
- return referrerURL;
814
- }
815
- return "no-referrer";
816
- case "origin-when-cross-origin":
817
- if (referrerURL.origin === currentURL.origin) {
818
- return referrerURL;
819
- }
820
- return referrerOrigin;
821
- case "no-referrer-when-downgrade":
822
- if (isUrlPotentiallyTrustworthy(referrerURL) && !isUrlPotentiallyTrustworthy(currentURL)) {
823
- return "no-referrer";
824
- }
825
- return referrerURL;
826
- default:
827
- throw new TypeError(`Invalid referrerPolicy: ${policy}`);
828
- }
829
- }
830
- function parseReferrerPolicyFromHeader(headers) {
831
- const policyTokens = (headers.get("referrer-policy") || "").split(/[,\s]+/);
832
- let policy = "";
833
- for (const token of policyTokens) {
834
- if (token && ReferrerPolicy.has(token)) {
835
- policy = token;
836
- }
837
- }
838
- return policy;
839
- }
840
-
841
- // node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/request.js
842
- var INTERNALS3 = Symbol("Request internals");
843
- var isRequest = (object) => {
844
- return typeof object === "object" && typeof object[INTERNALS3] === "object";
845
- };
846
- var doBadDataWarn = deprecate2(
847
- () => {
848
- },
849
- ".data is not a valid RequestInit property, use .body instead",
850
- "https://github.com/node-fetch/node-fetch/issues/1000 (request)"
851
- );
852
- var Request = class _Request extends Body {
853
- constructor(input, init = {}) {
854
- let parsedURL;
855
- if (isRequest(input)) {
856
- parsedURL = new URL(input.url);
857
- } else {
858
- parsedURL = new URL(input);
859
- input = {};
860
- }
861
- if (parsedURL.username !== "" || parsedURL.password !== "") {
862
- throw new TypeError(`${parsedURL} is an url with embedded credentials.`);
863
- }
864
- let method = init.method || input.method || "GET";
865
- if (/^(delete|get|head|options|post|put)$/i.test(method)) {
866
- method = method.toUpperCase();
867
- }
868
- if (!isRequest(init) && "data" in init) {
869
- doBadDataWarn();
870
- }
871
- if ((init.body != null || isRequest(input) && input.body !== null) && (method === "GET" || method === "HEAD")) {
872
- throw new TypeError("Request with GET/HEAD method cannot have body");
873
- }
874
- const inputBody = init.body ? init.body : isRequest(input) && input.body !== null ? clone(input) : null;
875
- super(inputBody, {
876
- size: init.size || input.size || 0
877
- });
878
- const headers = new Headers(init.headers || input.headers || {});
879
- if (inputBody !== null && !headers.has("Content-Type")) {
880
- const contentType = extractContentType(inputBody, this);
881
- if (contentType) {
882
- headers.set("Content-Type", contentType);
883
- }
884
- }
885
- let signal = isRequest(input) ? input.signal : null;
886
- if ("signal" in init) {
887
- signal = init.signal;
888
- }
889
- if (signal != null && !isAbortSignal(signal)) {
890
- throw new TypeError("Expected signal to be an instanceof AbortSignal or EventTarget");
891
- }
892
- let referrer = init.referrer == null ? input.referrer : init.referrer;
893
- if (referrer === "") {
894
- referrer = "no-referrer";
895
- } else if (referrer) {
896
- const parsedReferrer = new URL(referrer);
897
- referrer = /^about:(\/\/)?client$/.test(parsedReferrer) ? "client" : parsedReferrer;
898
- } else {
899
- referrer = void 0;
900
- }
901
- this[INTERNALS3] = {
902
- method,
903
- redirect: init.redirect || input.redirect || "follow",
904
- headers,
905
- parsedURL,
906
- signal,
907
- referrer
908
- };
909
- this.follow = init.follow === void 0 ? input.follow === void 0 ? 20 : input.follow : init.follow;
910
- this.compress = init.compress === void 0 ? input.compress === void 0 ? true : input.compress : init.compress;
911
- this.counter = init.counter || input.counter || 0;
912
- this.agent = init.agent || input.agent;
913
- this.highWaterMark = init.highWaterMark || input.highWaterMark || 16384;
914
- this.insecureHTTPParser = init.insecureHTTPParser || input.insecureHTTPParser || false;
915
- this.referrerPolicy = init.referrerPolicy || input.referrerPolicy || "";
916
- }
917
- /** @returns {string} */
918
- get method() {
919
- return this[INTERNALS3].method;
920
- }
921
- /** @returns {string} */
922
- get url() {
923
- return formatUrl(this[INTERNALS3].parsedURL);
924
- }
925
- /** @returns {Headers} */
926
- get headers() {
927
- return this[INTERNALS3].headers;
928
- }
929
- get redirect() {
930
- return this[INTERNALS3].redirect;
931
- }
932
- /** @returns {AbortSignal} */
933
- get signal() {
934
- return this[INTERNALS3].signal;
935
- }
936
- // https://fetch.spec.whatwg.org/#dom-request-referrer
937
- get referrer() {
938
- if (this[INTERNALS3].referrer === "no-referrer") {
939
- return "";
940
- }
941
- if (this[INTERNALS3].referrer === "client") {
942
- return "about:client";
943
- }
944
- if (this[INTERNALS3].referrer) {
945
- return this[INTERNALS3].referrer.toString();
946
- }
947
- return void 0;
948
- }
949
- get referrerPolicy() {
950
- return this[INTERNALS3].referrerPolicy;
951
- }
952
- set referrerPolicy(referrerPolicy) {
953
- this[INTERNALS3].referrerPolicy = validateReferrerPolicy(referrerPolicy);
954
- }
955
- /**
956
- * Clone this request
957
- *
958
- * @return Request
959
- */
960
- clone() {
961
- return new _Request(this);
962
- }
963
- get [Symbol.toStringTag]() {
964
- return "Request";
965
- }
966
- };
967
- Object.defineProperties(Request.prototype, {
968
- method: { enumerable: true },
969
- url: { enumerable: true },
970
- headers: { enumerable: true },
971
- redirect: { enumerable: true },
972
- clone: { enumerable: true },
973
- signal: { enumerable: true },
974
- referrer: { enumerable: true },
975
- referrerPolicy: { enumerable: true }
976
- });
977
- var getNodeRequestOptions = (request) => {
978
- const { parsedURL } = request[INTERNALS3];
979
- const headers = new Headers(request[INTERNALS3].headers);
980
- if (!headers.has("Accept")) {
981
- headers.set("Accept", "*/*");
982
- }
983
- let contentLengthValue = null;
984
- if (request.body === null && /^(post|put)$/i.test(request.method)) {
985
- contentLengthValue = "0";
986
- }
987
- if (request.body !== null) {
988
- const totalBytes = getTotalBytes(request);
989
- if (typeof totalBytes === "number" && !Number.isNaN(totalBytes)) {
990
- contentLengthValue = String(totalBytes);
991
- }
992
- }
993
- if (contentLengthValue) {
994
- headers.set("Content-Length", contentLengthValue);
995
- }
996
- if (request.referrerPolicy === "") {
997
- request.referrerPolicy = DEFAULT_REFERRER_POLICY;
998
- }
999
- if (request.referrer && request.referrer !== "no-referrer") {
1000
- request[INTERNALS3].referrer = determineRequestsReferrer(request);
1001
- } else {
1002
- request[INTERNALS3].referrer = "no-referrer";
1003
- }
1004
- if (request[INTERNALS3].referrer instanceof URL) {
1005
- headers.set("Referer", request.referrer);
1006
- }
1007
- if (!headers.has("User-Agent")) {
1008
- headers.set("User-Agent", "node-fetch");
1009
- }
1010
- if (request.compress && !headers.has("Accept-Encoding")) {
1011
- headers.set("Accept-Encoding", "gzip, deflate, br");
1012
- }
1013
- let { agent } = request;
1014
- if (typeof agent === "function") {
1015
- agent = agent(parsedURL);
1016
- }
1017
- const search = getSearch(parsedURL);
1018
- const options = {
1019
- // Overwrite search to retain trailing ? (issue #776)
1020
- path: parsedURL.pathname + search,
1021
- // The following options are not expressed in the URL
1022
- method: request.method,
1023
- headers: headers[Symbol.for("nodejs.util.inspect.custom")](),
1024
- insecureHTTPParser: request.insecureHTTPParser,
1025
- agent
1026
- };
1027
- return {
1028
- /** @type {URL} */
1029
- parsedURL,
1030
- options
1031
- };
1032
- };
1033
-
1034
- // node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/errors/abort-error.js
1035
- var AbortError = class extends FetchBaseError {
1036
- constructor(message, type = "aborted") {
1037
- super(message, type);
1038
- }
1039
- };
1040
-
1041
- // node_modules/.pnpm/node-fetch@3.3.2/node_modules/node-fetch/src/index.js
1042
- var supportedSchemas = /* @__PURE__ */ new Set(["data:", "http:", "https:"]);
1043
- async function fetch(url, options_) {
1044
- return new Promise((resolve, reject) => {
1045
- const request = new Request(url, options_);
1046
- const { parsedURL, options } = getNodeRequestOptions(request);
1047
- if (!supportedSchemas.has(parsedURL.protocol)) {
1048
- throw new TypeError(`node-fetch cannot load ${url}. URL scheme "${parsedURL.protocol.replace(/:$/, "")}" is not supported.`);
1049
- }
1050
- if (parsedURL.protocol === "data:") {
1051
- const data = dist_default(request.url);
1052
- const response2 = new Response(data, { headers: { "Content-Type": data.typeFull } });
1053
- resolve(response2);
1054
- return;
1055
- }
1056
- const send = (parsedURL.protocol === "https:" ? https : http2).request;
1057
- const { signal } = request;
1058
- let response = null;
1059
- const abort = () => {
1060
- const error = new AbortError("The operation was aborted.");
1061
- reject(error);
1062
- if (request.body && request.body instanceof Stream2.Readable) {
1063
- request.body.destroy(error);
1064
- }
1065
- if (!response || !response.body) {
1066
- return;
1067
- }
1068
- response.body.emit("error", error);
1069
- };
1070
- if (signal && signal.aborted) {
1071
- abort();
1072
- return;
1073
- }
1074
- const abortAndFinalize = () => {
1075
- abort();
1076
- finalize();
1077
- };
1078
- const request_ = send(parsedURL.toString(), options);
1079
- if (signal) {
1080
- signal.addEventListener("abort", abortAndFinalize);
1081
- }
1082
- const finalize = () => {
1083
- request_.abort();
1084
- if (signal) {
1085
- signal.removeEventListener("abort", abortAndFinalize);
1086
- }
1087
- };
1088
- request_.on("error", (error) => {
1089
- reject(new FetchError(`request to ${request.url} failed, reason: ${error.message}`, "system", error));
1090
- finalize();
1091
- });
1092
- fixResponseChunkedTransferBadEnding(request_, (error) => {
1093
- if (response && response.body) {
1094
- response.body.destroy(error);
1095
- }
1096
- });
1097
- if (process.version < "v14") {
1098
- request_.on("socket", (s) => {
1099
- let endedWithEventsCount;
1100
- s.prependListener("end", () => {
1101
- endedWithEventsCount = s._eventsCount;
1102
- });
1103
- s.prependListener("close", (hadError) => {
1104
- if (response && endedWithEventsCount < s._eventsCount && !hadError) {
1105
- const error = new Error("Premature close");
1106
- error.code = "ERR_STREAM_PREMATURE_CLOSE";
1107
- response.body.emit("error", error);
1108
- }
1109
- });
1110
- });
1111
- }
1112
- request_.on("response", (response_) => {
1113
- request_.setTimeout(0);
1114
- const headers = fromRawHeaders(response_.rawHeaders);
1115
- if (isRedirect(response_.statusCode)) {
1116
- const location = headers.get("Location");
1117
- let locationURL = null;
1118
- try {
1119
- locationURL = location === null ? null : new URL(location, request.url);
1120
- } catch (e) {
1121
- if (request.redirect !== "manual") {
1122
- reject(new FetchError(`uri requested responds with an invalid redirect URL: ${location}`, "invalid-redirect"));
1123
- finalize();
1124
- return;
1125
- }
1126
- }
1127
- switch (request.redirect) {
1128
- case "error":
1129
- reject(new FetchError(`uri requested responds with a redirect, redirect mode is set to error: ${request.url}`, "no-redirect"));
1130
- finalize();
1131
- return;
1132
- case "manual":
1133
- break;
1134
- case "follow": {
1135
- if (locationURL === null) {
1136
- break;
1137
- }
1138
- if (request.counter >= request.follow) {
1139
- reject(new FetchError(`maximum redirect reached at: ${request.url}`, "max-redirect"));
1140
- finalize();
1141
- return;
1142
- }
1143
- const requestOptions = {
1144
- headers: new Headers(request.headers),
1145
- follow: request.follow,
1146
- counter: request.counter + 1,
1147
- agent: request.agent,
1148
- compress: request.compress,
1149
- method: request.method,
1150
- body: clone(request),
1151
- signal: request.signal,
1152
- size: request.size,
1153
- referrer: request.referrer,
1154
- referrerPolicy: request.referrerPolicy
1155
- };
1156
- if (!isDomainOrSubdomain(request.url, locationURL) || !isSameProtocol(request.url, locationURL)) {
1157
- for (const name of ["authorization", "www-authenticate", "cookie", "cookie2"]) {
1158
- requestOptions.headers.delete(name);
1159
- }
1160
- }
1161
- if (response_.statusCode !== 303 && request.body && options_.body instanceof Stream2.Readable) {
1162
- reject(new FetchError("Cannot follow redirect with body being a readable stream", "unsupported-redirect"));
1163
- finalize();
1164
- return;
1165
- }
1166
- if (response_.statusCode === 303 || (response_.statusCode === 301 || response_.statusCode === 302) && request.method === "POST") {
1167
- requestOptions.method = "GET";
1168
- requestOptions.body = void 0;
1169
- requestOptions.headers.delete("content-length");
1170
- }
1171
- const responseReferrerPolicy = parseReferrerPolicyFromHeader(headers);
1172
- if (responseReferrerPolicy) {
1173
- requestOptions.referrerPolicy = responseReferrerPolicy;
1174
- }
1175
- resolve(fetch(new Request(locationURL, requestOptions)));
1176
- finalize();
1177
- return;
1178
- }
1179
- default:
1180
- return reject(new TypeError(`Redirect option '${request.redirect}' is not a valid value of RequestRedirect`));
1181
- }
1182
- }
1183
- if (signal) {
1184
- response_.once("end", () => {
1185
- signal.removeEventListener("abort", abortAndFinalize);
1186
- });
1187
- }
1188
- let body = pump(response_, new PassThrough2(), (error) => {
1189
- if (error) {
1190
- reject(error);
1191
- }
1192
- });
1193
- if (process.version < "v12.10") {
1194
- response_.on("aborted", abortAndFinalize);
1195
- }
1196
- const responseOptions = {
1197
- url: request.url,
1198
- status: response_.statusCode,
1199
- statusText: response_.statusMessage,
1200
- headers,
1201
- size: request.size,
1202
- counter: request.counter,
1203
- highWaterMark: request.highWaterMark
1204
- };
1205
- const codings = headers.get("Content-Encoding");
1206
- if (!request.compress || request.method === "HEAD" || codings === null || response_.statusCode === 204 || response_.statusCode === 304) {
1207
- response = new Response(body, responseOptions);
1208
- resolve(response);
1209
- return;
1210
- }
1211
- const zlibOptions = {
1212
- flush: zlib.Z_SYNC_FLUSH,
1213
- finishFlush: zlib.Z_SYNC_FLUSH
1214
- };
1215
- if (codings === "gzip" || codings === "x-gzip") {
1216
- body = pump(body, zlib.createGunzip(zlibOptions), (error) => {
1217
- if (error) {
1218
- reject(error);
1219
- }
1220
- });
1221
- response = new Response(body, responseOptions);
1222
- resolve(response);
1223
- return;
1224
- }
1225
- if (codings === "deflate" || codings === "x-deflate") {
1226
- const raw = pump(response_, new PassThrough2(), (error) => {
1227
- if (error) {
1228
- reject(error);
1229
- }
1230
- });
1231
- raw.once("data", (chunk) => {
1232
- if ((chunk[0] & 15) === 8) {
1233
- body = pump(body, zlib.createInflate(), (error) => {
1234
- if (error) {
1235
- reject(error);
1236
- }
1237
- });
1238
- } else {
1239
- body = pump(body, zlib.createInflateRaw(), (error) => {
1240
- if (error) {
1241
- reject(error);
1242
- }
1243
- });
1244
- }
1245
- response = new Response(body, responseOptions);
1246
- resolve(response);
1247
- });
1248
- raw.once("end", () => {
1249
- if (!response) {
1250
- response = new Response(body, responseOptions);
1251
- resolve(response);
1252
- }
1253
- });
1254
- return;
1255
- }
1256
- if (codings === "br") {
1257
- body = pump(body, zlib.createBrotliDecompress(), (error) => {
1258
- if (error) {
1259
- reject(error);
1260
- }
1261
- });
1262
- response = new Response(body, responseOptions);
1263
- resolve(response);
1264
- return;
1265
- }
1266
- response = new Response(body, responseOptions);
1267
- resolve(response);
1268
- });
1269
- writeToStream(request_, request).catch(reject);
1270
- });
1271
- }
1272
- function fixResponseChunkedTransferBadEnding(request, errorCallback) {
1273
- const LAST_CHUNK = Buffer3.from("0\r\n\r\n");
1274
- let isChunkedTransfer = false;
1275
- let properLastChunkReceived = false;
1276
- let previousChunk;
1277
- request.on("response", (response) => {
1278
- const { headers } = response;
1279
- isChunkedTransfer = headers["transfer-encoding"] === "chunked" && !headers["content-length"];
1280
- });
1281
- request.on("socket", (socket) => {
1282
- const onSocketClose = () => {
1283
- if (isChunkedTransfer && !properLastChunkReceived) {
1284
- const error = new Error("Premature close");
1285
- error.code = "ERR_STREAM_PREMATURE_CLOSE";
1286
- errorCallback(error);
1287
- }
1288
- };
1289
- const onData = (buf) => {
1290
- properLastChunkReceived = Buffer3.compare(buf.slice(-5), LAST_CHUNK) === 0;
1291
- if (!properLastChunkReceived && previousChunk) {
1292
- properLastChunkReceived = Buffer3.compare(previousChunk.slice(-3), LAST_CHUNK.slice(0, 3)) === 0 && Buffer3.compare(buf.slice(-2), LAST_CHUNK.slice(3)) === 0;
1293
- }
1294
- previousChunk = buf;
1295
- };
1296
- socket.prependListener("close", onSocketClose);
1297
- socket.on("data", onData);
1298
- request.on("close", () => {
1299
- socket.removeListener("close", onSocketClose);
1300
- socket.removeListener("data", onData);
1301
- });
1302
- });
1303
- }
1304
-
1305
- // src/index.ts
1306
- import { createUnplugin } from "unplugin";
1307
- import c from "picocolors";
1308
- import cookie from "cookie";
1309
- import { start } from "z-chii";
1310
-
1311
- // node_modules/.pnpm/get-port-please@3.1.2/node_modules/get-port-please/dist/index.mjs
1312
- import { createServer } from "node:net";
1313
- import { networkInterfaces } from "node:os";
1314
- var unsafePorts = /* @__PURE__ */ new Set([
1315
- 1,
1316
- // tcpmux
1317
- 7,
1318
- // echo
1319
- 9,
1320
- // discard
1321
- 11,
1322
- // systat
1323
- 13,
1324
- // daytime
1325
- 15,
1326
- // netstat
1327
- 17,
1328
- // qotd
1329
- 19,
1330
- // chargen
1331
- 20,
1332
- // ftp data
1333
- 21,
1334
- // ftp access
1335
- 22,
1336
- // ssh
1337
- 23,
1338
- // telnet
1339
- 25,
1340
- // smtp
1341
- 37,
1342
- // time
1343
- 42,
1344
- // name
1345
- 43,
1346
- // nicname
1347
- 53,
1348
- // domain
1349
- 69,
1350
- // tftp
1351
- 77,
1352
- // priv-rjs
1353
- 79,
1354
- // finger
1355
- 87,
1356
- // ttylink
1357
- 95,
1358
- // supdup
1359
- 101,
1360
- // hostriame
1361
- 102,
1362
- // iso-tsap
1363
- 103,
1364
- // gppitnp
1365
- 104,
1366
- // acr-nema
1367
- 109,
1368
- // pop2
1369
- 110,
1370
- // pop3
1371
- 111,
1372
- // sunrpc
1373
- 113,
1374
- // auth
1375
- 115,
1376
- // sftp
1377
- 117,
1378
- // uucp-path
1379
- 119,
1380
- // nntp
1381
- 123,
1382
- // NTP
1383
- 135,
1384
- // loc-srv /epmap
1385
- 137,
1386
- // netbios
1387
- 139,
1388
- // netbios
1389
- 143,
1390
- // imap2
1391
- 161,
1392
- // snmp
1393
- 179,
1394
- // BGP
1395
- 389,
1396
- // ldap
1397
- 427,
1398
- // SLP (Also used by Apple Filing Protocol)
1399
- 465,
1400
- // smtp+ssl
1401
- 512,
1402
- // print / exec
1403
- 513,
1404
- // login
1405
- 514,
1406
- // shell
1407
- 515,
1408
- // printer
1409
- 526,
1410
- // tempo
1411
- 530,
1412
- // courier
1413
- 531,
1414
- // chat
1415
- 532,
1416
- // netnews
1417
- 540,
1418
- // uucp
1419
- 548,
1420
- // AFP (Apple Filing Protocol)
1421
- 554,
1422
- // rtsp
1423
- 556,
1424
- // remotefs
1425
- 563,
1426
- // nntp+ssl
1427
- 587,
1428
- // smtp (rfc6409)
1429
- 601,
1430
- // syslog-conn (rfc3195)
1431
- 636,
1432
- // ldap+ssl
1433
- 989,
1434
- // ftps-data
1435
- 990,
1436
- // ftps
1437
- 993,
1438
- // ldap+ssl
1439
- 995,
1440
- // pop3+ssl
1441
- 1719,
1442
- // h323gatestat
1443
- 1720,
1444
- // h323hostcall
1445
- 1723,
1446
- // pptp
1447
- 2049,
1448
- // nfs
1449
- 3659,
1450
- // apple-sasl / PasswordServer
1451
- 4045,
1452
- // lockd
1453
- 5060,
1454
- // sip
1455
- 5061,
1456
- // sips
1457
- 6e3,
1458
- // X11
1459
- 6566,
1460
- // sane-port
1461
- 6665,
1462
- // Alternate IRC [Apple addition]
1463
- 6666,
1464
- // Alternate IRC [Apple addition]
1465
- 6667,
1466
- // Standard IRC [Apple addition]
1467
- 6668,
1468
- // Alternate IRC [Apple addition]
1469
- 6669,
1470
- // Alternate IRC [Apple addition]
1471
- 6697,
1472
- // IRC + TLS
1473
- 10080
1474
- // Amanda
1475
- ]);
1476
- function isUnsafePort(port) {
1477
- return unsafePorts.has(port);
1478
- }
1479
- function isSafePort(port) {
1480
- return !isUnsafePort(port);
1481
- }
1482
- var __defProp = Object.defineProperty;
1483
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1484
- var __publicField = (obj, key, value) => {
1485
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
1486
- return value;
1487
- };
1488
- var GetPortError = class extends Error {
1489
- constructor(message, opts) {
1490
- super(message, opts);
1491
- this.message = message;
1492
- __publicField(this, "name", "GetPortError");
1493
- }
1494
- };
1495
- function _log(verbose, message) {
1496
- if (verbose) {
1497
- console.log(`[get-port] ${message}`);
1498
- }
1499
- }
1500
- function _tryPort(port, host) {
1501
- return new Promise((resolve) => {
1502
- const server = createServer();
1503
- server.unref();
1504
- server.on("error", () => {
1505
- resolve(false);
1506
- });
1507
- server.listen({ port, host }, () => {
1508
- const { port: port2 } = server.address();
1509
- server.close(() => {
1510
- resolve(isSafePort(port2) && port2);
1511
- });
1512
- });
1513
- });
1514
- }
1515
- function _getLocalHosts(additional) {
1516
- const hosts = new Set(additional);
1517
- for (const _interface of Object.values(networkInterfaces())) {
1518
- for (const config2 of _interface || []) {
1519
- if (config2.address && !config2.internal && !config2.address.startsWith("fe80::")) {
1520
- hosts.add(config2.address);
1521
- }
1522
- }
1523
- }
1524
- return [...hosts];
1525
- }
1526
- function _fmtOnHost(hostname) {
1527
- return hostname ? `on host ${JSON.stringify(hostname)}` : "on any host";
1528
- }
1529
- var HOSTNAME_RE = new RegExp("^(?!-)[\\d.:A-Za-z-]{1,63}(?<!-)$");
1530
- async function getRandomPort(host) {
1531
- const port = await checkPort(0, host);
1532
- if (port === false) {
1533
- throw new GetPortError(`Unable to find a random port ${_fmtOnHost(host)}`);
1534
- }
1535
- return port;
1536
- }
1537
- async function checkPort(port, host = process.env.HOST, verbose) {
1538
- if (!host) {
1539
- host = _getLocalHosts([void 0, "0.0.0.0"]);
1540
- }
1541
- if (!Array.isArray(host)) {
1542
- return _tryPort(port, host);
1543
- }
1544
- for (const _host of host) {
1545
- const _port = await _tryPort(port, _host);
1546
- if (_port === false) {
1547
- if (port < 1024 && verbose) {
1548
- _log(
1549
- verbose,
1550
- `Unable to listen to the privileged port ${port} ${_fmtOnHost(
1551
- _host
1552
- )}`
1553
- );
1554
- }
1555
- return false;
1556
- }
1557
- if (port === 0 && _port !== 0) {
1558
- port = _port;
1559
- }
1560
- }
1561
- return port;
1562
- }
1563
-
1564
- // src/index.ts
1565
- import httpProxy from "http-proxy";
1566
- var cwd = process2.cwd();
1567
- var config;
1568
- var colorUrl = (url) => c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`));
1569
- var resovedInfo = {
1570
- availablePort: void 0,
1571
- targetURL: void 0
1572
- };
1573
- var unpluginFactory = (options) => {
1574
- const {
1575
- chii
1576
- } = options || {};
1577
- const enableChii = (chii == null ? void 0 : chii.enable) !== false;
1578
- function debug(...args) {
1579
- if (options == null ? void 0 : options.debug) {
1580
- console.log(` ${c.yellow("DEBUG")} `, ...args);
1581
- }
1582
- }
1583
- const unpluginDing = {
1584
- name: "unplugin-dingtalk",
1585
- enforce: "pre",
1586
- transformInclude(id) {
1587
- return (id.endsWith("main.ts") || id.endsWith("main.js")) && !id.includes("node_modules");
1588
- },
1589
- async transform(_source) {
1590
- if ((options == null ? void 0 : options.enable) && enableChii && !resovedInfo.availablePort) {
1591
- resovedInfo.availablePort = await getRandomPort();
1592
- start({
1593
- port: resovedInfo.availablePort
1594
- });
1595
- debug(`chii server port: ${resovedInfo.availablePort}`);
1596
- }
1597
- return {
1598
- code: _source,
1599
- map: null
1600
- // support source map
1601
- };
1602
- },
1603
- vite: {
1604
- configResolved(_config) {
1605
- config = _config;
1606
- },
1607
- transformIndexHtml(html) {
1608
- var _a;
1609
- if ((options == null ? void 0 : options.enable) && enableChii) {
1610
- return html.replace(
1611
- "</body>",
1612
- `</body>
1613
- <script>
1614
- (() => {
1615
- const script = document.createElement('script');
1616
- script.src="/__chii_proxy/target.js";
1617
- ${((_a = options == null ? void 0 : options.chii) == null ? void 0 : _a.embedded) ? 'script.setAttribute("embedded", "true");' : ""}
1618
- document.body.appendChild(script);
1619
- })()
1620
- </script>
1621
- `
1622
- );
1623
- }
1624
- },
1625
- async configureServer(server) {
1626
- var _a, _b;
1627
- if (!(options == null ? void 0 : options.enable)) {
1628
- return;
1629
- }
1630
- const _printUrls = server.printUrls.bind(server);
1631
- let source = `localhost:${config.server.port || 5173}`;
1632
- const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
1633
- if (url) {
1634
- const u = new URL(url);
1635
- source = u.host;
1636
- }
1637
- const base = server.config.base || "/";
1638
- const _targetUrl = (_b = options == null ? void 0 : options.targetUrl) != null ? _b : `http://${source}${base}`;
1639
- server.printUrls = () => {
1640
- _printUrls();
1641
- console.log(` ${c.green("\u279C")} ${c.bold(
1642
- "Open in dingtalk"
1643
- )}: ${colorUrl(`http://${source}${base}open-dingtalk`)}`);
1644
- if (enableChii) {
1645
- console.log(` ${c.green("\u279C")} ${c.bold(
1646
- "Click to open chrome devtools"
1647
- )}: ${colorUrl(`http://${source}${base}__chrome_devtools`)}`);
1648
- }
1649
- };
1650
- const targetURL = new URL(_targetUrl);
1651
- targetURL.searchParams.append("ddtab", "true");
1652
- if (options == null ? void 0 : options.corpId) {
1653
- targetURL.searchParams.append("corpId", options.corpId);
1654
- }
1655
- if (options.debugCookies && options.debugCookies.length > 0) {
1656
- server.middlewares.use((req, res, next) => {
1657
- const cookies = cookie.parse(req.headers.cookie || "");
1658
- for (const [name, value] of Object.entries(cookies)) {
1659
- if (value && options.debugCookies && options.debugCookies.length > 0 && options.debugCookies.includes(name)) {
1660
- const serializedCookie = cookie.serialize(name, value, {
1661
- httpOnly: false
1662
- });
1663
- res.setHeader("Set-Cookie", serializedCookie);
1664
- }
1665
- }
1666
- next();
1667
- });
1668
- }
1669
- if (enableChii) {
1670
- let createProxyMiddleware2 = function() {
1671
- let proxy = null;
1672
- const handleUpgrade = (req, socket, head) => {
1673
- var _a2;
1674
- if (proxy && ((_a2 = req.url) == null ? void 0 : _a2.startsWith("/__chii_proxy"))) {
1675
- debug("WS upgrade:", req.url);
1676
- req.url = req.url.replace("/__chii_proxy", "");
1677
- proxy.ws(req, socket, head);
1678
- }
1679
- };
1680
- return (resolvedInfo) => {
1681
- return (req, res, next) => {
1682
- var _a2;
1683
- if (!proxy && resolvedInfo.availablePort) {
1684
- proxy = httpProxy.createProxyServer({
1685
- target: `http://localhost:${resolvedInfo.availablePort}`,
1686
- ws: true
1687
- // changeOrigin: true, // Consider if you need this
1688
- });
1689
- proxy.on("error", (err, req2, res2) => {
1690
- console.error("Proxy error:", err);
1691
- if (res2 instanceof ServerResponse) {
1692
- if (!res2.headersSent) {
1693
- res2.writeHead(500, { "Content-Type": "text/plain" });
1694
- }
1695
- res2.end(`Proxy error: ${err.message}`);
1696
- } else if (res2 instanceof Socket) {
1697
- res2.destroy();
1698
- }
1699
- });
1700
- if (req.socket.server) {
1701
- req.socket.server.on("upgrade", handleUpgrade);
1702
- }
1703
- }
1704
- if (proxy && ((_a2 = req.url) == null ? void 0 : _a2.startsWith("/__chii_proxy"))) {
1705
- debug(req.url);
1706
- req.url = req.url.replace("/__chii_proxy", "");
1707
- proxy.web(req, res);
1708
- } else {
1709
- next();
1710
- }
1711
- };
1712
- };
1713
- };
1714
- var createProxyMiddleware = createProxyMiddleware2;
1715
- server.middlewares.use("/__chrome_devtools", async (_req, res) => {
1716
- try {
1717
- const raw = await fetch(`http://localhost:${resovedInfo.availablePort}/targets`);
1718
- const data = await raw.json();
1719
- if ((data == null ? void 0 : data.targets.length) > 0) {
1720
- const devToolsUrl = `http://localhost:${resovedInfo.availablePort}/front_end/chii_app.html?ws=localhost:${resovedInfo.availablePort}/client/${Math.random().toString(20).substring(2, 8)}?target=${data.targets[0].id}&rtc=false`;
1721
- res.writeHead(302, { Location: devToolsUrl });
1722
- res.end();
1723
- } else {
1724
- res.writeHead(404);
1725
- res.end();
1726
- }
1727
- } catch (error) {
1728
- debug(`${error}`);
1729
- res.writeHead(502);
1730
- res.end();
1731
- }
1732
- });
1733
- const proxyMiddleware = createProxyMiddleware2();
1734
- server.middlewares.use(proxyMiddleware(resovedInfo));
1735
- }
1736
- server.middlewares.use("/open-dingtalk", (req, res) => {
1737
- debug(targetURL.toString());
1738
- res.writeHead(302, {
1739
- Location: `dingtalk://dingtalkclient/page/link?url=${encodeURIComponent(targetURL.toString())}`
1740
- });
1741
- res.end();
1742
- });
1743
- }
1744
- },
1745
- webpack(compiler) {
1746
- var _a, _b;
1747
- if (!(options == null ? void 0 : options.enable)) {
1748
- return;
1749
- }
1750
- const devServerOptions = __spreadValues(__spreadValues({
1751
- host: "localhost",
1752
- port: 8080
1753
- }, compiler.options.devServer), (_a = process2.VUE_CLI_SERVICE) == null ? void 0 : _a.projectOptions.devServer);
1754
- const source = `${devServerOptions.host === "0.0.0.0" ? "127.0.0.1" : devServerOptions.host}:${devServerOptions.port}`;
1755
- const base = compiler.options.output.publicPath || "/";
1756
- const _targetUrl = (_b = options == null ? void 0 : options.targetUrl) != null ? _b : `http://${source}${base}`;
1757
- compiler.hooks.done.tap("unplugin-dingtalk", () => {
1758
- console.log(` ${c.green("\u279C")} ${c.bold(
1759
- "Open in dingtalk"
1760
- )}: ${colorUrl(`http://${source}${base}open-dingtalk`)}`);
1761
- if (enableChii) {
1762
- console.log(` ${c.green("\u279C")} ${c.bold(
1763
- "Click to open chrome devtools"
1764
- )}: ${colorUrl(`http://${source}${base}__chrome_devtools`)}`);
1765
- }
1766
- });
1767
- resovedInfo.targetURL = new URL(_targetUrl);
1768
- resovedInfo.targetURL.searchParams.append("ddtab", "true");
1769
- if (options == null ? void 0 : options.corpId) {
1770
- resovedInfo.targetURL.searchParams.append("corpId", options.corpId);
1771
- }
1772
- },
1773
- async rspack(compiler) {
1774
- var _a, _b, _c, _d;
1775
- if (!(options == null ? void 0 : options.enable)) {
1776
- return;
1777
- }
1778
- const devServerOptions = __spreadValues(__spreadValues({
1779
- host: "localhost",
1780
- port: 8080
1781
- }, compiler.options.devServer), (_c = (_b = await ((_a = await import("@rsbuild/core")) == null ? void 0 : _a.loadConfig({
1782
- cwd
1783
- }))) == null ? void 0 : _b.content) == null ? void 0 : _c.server);
1784
- const source = `${devServerOptions.host === "0.0.0.0" ? "127.0.0.1" : devServerOptions.host}:${devServerOptions.port}`;
1785
- const base = compiler.options.output.publicPath || "/";
1786
- const _targetUrl = (_d = options == null ? void 0 : options.targetUrl) != null ? _d : `http://${source}${base}`;
1787
- resovedInfo.targetURL = new URL(_targetUrl);
1788
- resovedInfo.targetURL.searchParams.append("ddtab", "true");
1789
- if (options == null ? void 0 : options.corpId) {
1790
- resovedInfo.targetURL.searchParams.append("corpId", options.corpId);
1791
- }
1792
- console.log(` ${c.green("\u279C")} ${c.bold(
1793
- "Open in dingtalk"
1794
- )}: ${colorUrl(`http://${source}${base}open-dingtalk`)}`);
1795
- if (enableChii) {
1796
- console.log(` ${c.green("\u279C")} ${c.bold(
1797
- "Click to open chrome devtools"
1798
- )}: ${colorUrl(`http://${source}${base}__chrome_devtools`)}`);
1799
- }
1800
- }
1801
- };
1802
- return unpluginDing;
1803
- };
1804
- var unplugin = /* @__PURE__ */ createUnplugin(unpluginFactory);
1805
- var index_default = unplugin;
1806
-
1807
- export {
1808
- fetch,
1809
- resovedInfo,
1810
- unpluginFactory,
1811
- unplugin,
1812
- index_default
1813
- };