@shopify/cli 3.61.2 → 3.62.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.
Files changed (197) hide show
  1. package/dist/assets/dev-console/extensions/dev-console/assets/index-dfaab2a5.css +1 -0
  2. package/dist/assets/dev-console/extensions/dev-console/assets/{index-f3e60690.js → index-e3682a83.js} +1 -1
  3. package/dist/assets/dev-console/index.html +2 -2
  4. package/dist/{chokidar-RFZXZKRQ.js → chokidar-5MKSECYV.js} +4 -3
  5. package/dist/{chunk-QDZF6IG4.js → chunk-22PYIFA2.js} +112 -17
  6. package/dist/{chunk-3MBQVTEX.js → chunk-2QVJZ5TG.js} +2 -1
  7. package/dist/{chunk-KBXWK6XB.js → chunk-2ZSNH7CD.js} +4 -5
  8. package/dist/{chunk-BYFLATOA.js → chunk-5FNE3T7E.js} +5 -4
  9. package/dist/{chunk-G4EQLT5B.js → chunk-5X4QXYEZ.js} +9 -7
  10. package/dist/chunk-66NABVCG.js +73 -0
  11. package/dist/{chunk-LAY4AEXX.js → chunk-6UDFXWNE.js} +2 -1
  12. package/dist/{chunk-QQP6JS5H.js → chunk-7MXLRMOY.js} +3 -2
  13. package/dist/{chunk-EHF6FVWH.js → chunk-A5STII7T.js} +3 -2
  14. package/dist/{chunk-UPM6XNBH.js → chunk-ADESJ2KG.js} +6 -5
  15. package/dist/{chunk-BZJX2NV6.js → chunk-AMAYT2P2.js} +3 -2
  16. package/dist/{chunk-QTBH3GO6.js → chunk-B62HZLMM.js} +3 -2
  17. package/dist/{chunk-3RM5SOXY.js → chunk-BMTG2VHL.js} +4 -3
  18. package/dist/{chunk-FWGRGI4R.js → chunk-BYC3NA2Y.js} +2 -1
  19. package/dist/{chunk-NJTSDTDU.js → chunk-BZFXXFUC.js} +6 -5
  20. package/dist/{chunk-7IZTLXJ5.js → chunk-CKFE55FX.js} +4 -3
  21. package/dist/{chunk-YP5UVIUW.js → chunk-CYQRKZVM.js} +6 -5
  22. package/dist/{chunk-HTYJDJRZ.js → chunk-DL3MKXVR.js} +2 -1
  23. package/dist/{chunk-IUHH3PST.js → chunk-DLK3F3DC.js} +2 -1
  24. package/dist/{chunk-4XNS74OG.js → chunk-EARPFFS7.js} +2 -1
  25. package/dist/chunk-EQPYUHNM.js +3642 -0
  26. package/dist/{chunk-LKGDG6WW.js → chunk-FMKVOTQK.js} +2 -1
  27. package/dist/{chunk-I434ZJQI.js → chunk-GEN4RXTD.js} +7 -6
  28. package/dist/{chunk-QSO3GQEK.js → chunk-HJ4AUFE7.js} +94 -160
  29. package/dist/{chunk-FQIRJADJ.js → chunk-JIJ65JT6.js} +2 -1
  30. package/dist/{chunk-JQPQJN44.js → chunk-JKYNFUD3.js} +11 -12
  31. package/dist/{chunk-4L37JOS5.js → chunk-JL3ESOD2.js} +3 -2
  32. package/dist/{chunk-4TTAP7NN.js → chunk-JOOYCYFU.js} +6 -5
  33. package/dist/{chunk-XMJDBJPP.js → chunk-K3GG6Y3J.js} +12 -12
  34. package/dist/{chunk-VQZ2SHRY.js → chunk-K6257PKA.js} +3 -2
  35. package/dist/{chunk-5KRK4DLX.js → chunk-LC6MEJT3.js} +4 -3
  36. package/dist/{chunk-KDOLMUJB.js → chunk-LH533WG4.js} +2 -1
  37. package/dist/{chunk-FBB6KUZG.js → chunk-LSCXQWNO.js} +2 -1
  38. package/dist/{chunk-VC6CC75R.js → chunk-MG6QFKFM.js} +5 -4
  39. package/dist/{chunk-ETSILRIY.js → chunk-MQ2RGCDU.js} +5 -4
  40. package/dist/{chunk-QOHDW3X5.js → chunk-MQGV3PCJ.js} +4 -3
  41. package/dist/{chunk-PBFWVFAQ.js → chunk-NABCTJNW.js} +3 -2
  42. package/dist/{chunk-YZGLFVKK.js → chunk-NNASIYCT.js} +3 -2
  43. package/dist/chunk-PIB2FEJJ.js +4385 -0
  44. package/dist/{chunk-TXXQWILO.js → chunk-PIVNWN2P.js} +4 -3
  45. package/dist/{chunk-Q3KADKQA.js → chunk-PO6SEYU4.js} +4 -3
  46. package/dist/{chunk-FAFQQMD4.js → chunk-PRJ3U7MR.js} +2 -1
  47. package/dist/{chunk-5B2D56W6.js → chunk-Q4XGXPUG.js} +2 -1
  48. package/dist/{chunk-ZE2ZPLYI.js → chunk-QGJLRFY4.js} +19 -89
  49. package/dist/{chunk-RP2ISWQN.js → chunk-QOUOFEGO.js} +3 -2
  50. package/dist/{chunk-CWYZA7C7.js → chunk-RUSG4O2Z.js} +13464 -5175
  51. package/dist/{chunk-CKKROMZF.js → chunk-S4VBXFXP.js} +3 -2
  52. package/dist/{chunk-BE73NZXB.js → chunk-SAR5HGRG.js} +2 -1
  53. package/dist/{chunk-GXPKATXW.js → chunk-T5LLJYYS.js} +2 -1
  54. package/dist/{chunk-NBIE3DNN.js → chunk-TCRWMUKX.js} +4 -3
  55. package/dist/{chunk-4757GPBG.js → chunk-UACSLX64.js} +6 -5
  56. package/dist/{chunk-4KKFUTH7.js → chunk-UJ3QKFA5.js} +2 -1
  57. package/dist/chunk-UNPXLODI.js +121 -0
  58. package/dist/{chunk-RQ24VTW4.js → chunk-VM4POVNV.js} +2 -1
  59. package/dist/{chunk-CTETXMMM.js → chunk-VS6RWOLM.js} +8 -7
  60. package/dist/{chunk-BUWM6JUU.js → chunk-W5VEUSWG.js} +5 -4
  61. package/dist/{chunk-PCQFWMMD.js → chunk-WADS2TV5.js} +63 -5
  62. package/dist/{chunk-M73YMW2C.js → chunk-WAEWSGBK.js} +2579 -1632
  63. package/dist/{chunk-6SL33DOA.js → chunk-XQFDS44U.js} +2 -1
  64. package/dist/{chunk-WCNR75S2.js → chunk-YC4FLMDD.js} +2 -1
  65. package/dist/{chunk-OXZ2SRCK.js → chunk-YECNACSF.js} +3 -2
  66. package/dist/{chunk-QLLSCNEC.js → chunk-YX5VXHSJ.js} +4 -3
  67. package/dist/{chunk-5MODHNUE.js → chunk-ZCMXEGSE.js} +5 -4
  68. package/dist/{chunk-4VEOJ5JD.js → chunk-ZEHQN47F.js} +2 -1
  69. package/dist/{chunk-3JLUTHGR.js → chunk-ZPFJOUKZ.js} +2 -1
  70. package/dist/{chunk-M63RTPGR.js → chunk-ZPL24Y2D.js} +1 -0
  71. package/dist/cli/commands/auth/logout.js +37 -39
  72. package/dist/cli/commands/auth/logout.test.js +39 -41
  73. package/dist/cli/commands/debug/command-flags.js +33 -35
  74. package/dist/cli/commands/demo/catalog.js +36 -38
  75. package/dist/cli/commands/demo/generate-file.js +37 -39
  76. package/dist/cli/commands/demo/index.js +35 -37
  77. package/dist/cli/commands/demo/print-ai-prompt.js +37 -39
  78. package/dist/cli/commands/docs/generate.js +33 -35
  79. package/dist/cli/commands/docs/generate.test.js +34 -36
  80. package/dist/cli/commands/help.js +33 -35
  81. package/dist/cli/commands/kitchen-sink/async.js +34 -36
  82. package/dist/cli/commands/kitchen-sink/async.test.js +35 -37
  83. package/dist/cli/commands/kitchen-sink/index.js +36 -38
  84. package/dist/cli/commands/kitchen-sink/index.test.js +37 -39
  85. package/dist/cli/commands/kitchen-sink/prompts.js +34 -36
  86. package/dist/cli/commands/kitchen-sink/prompts.test.js +35 -37
  87. package/dist/cli/commands/kitchen-sink/static.js +34 -36
  88. package/dist/cli/commands/kitchen-sink/static.test.js +35 -37
  89. package/dist/cli/commands/search.js +34 -36
  90. package/dist/cli/commands/upgrade.js +33 -35
  91. package/dist/cli/commands/upgrade.test.js +5 -4
  92. package/dist/cli/commands/version.js +34 -36
  93. package/dist/cli/commands/version.test.js +35 -37
  94. package/dist/cli/services/commands/search.js +19 -21
  95. package/dist/cli/services/commands/search.test.js +20 -22
  96. package/dist/cli/services/commands/version.js +23 -25
  97. package/dist/cli/services/commands/version.test.js +25 -27
  98. package/dist/cli/services/demo.js +21 -23
  99. package/dist/cli/services/demo.test.js +22 -24
  100. package/dist/cli/services/kitchen-sink/async.js +19 -21
  101. package/dist/cli/services/kitchen-sink/prompts.js +19 -21
  102. package/dist/cli/services/kitchen-sink/static.js +19 -21
  103. package/dist/cli/services/upgrade.js +22 -24
  104. package/dist/cli/services/upgrade.test.js +30 -27
  105. package/dist/{constants-XCWOF7M7.js → constants-3CLHB4LQ.js} +5 -6
  106. package/dist/{custom-oclif-loader-4SQGUQ7D-P5C4NLSX.js → custom-oclif-loader-ZH42ZTTC.js} +25 -28
  107. package/dist/{del-DGT5RCOW.js → del-KSMMBLCD.js} +9 -8
  108. package/dist/{devtools-SJTLOVKU.js → devtools-6ZZ3EAY7.js} +3 -2
  109. package/dist/error-handler-I6WJC3U2.js +43 -0
  110. package/dist/error-handler-JFX2TIYX.js +38 -0
  111. package/dist/hooks/postrun.js +28 -30
  112. package/dist/hooks/prerun.js +23 -25
  113. package/dist/{http-proxy-WYSSUHIT.js → http-proxy-KFHAZRTT.js} +3 -2
  114. package/dist/index.js +138858 -143506
  115. package/dist/lib-E7NFRKVR.js +14 -0
  116. package/dist/{lib-RZNRJEWB.js → lib-LY6ZCPIO.js} +2 -1
  117. package/dist/{lib-AAMRQUES.js → lib-MUDJYT6A.js} +4 -3
  118. package/dist/{local-YKOG4EUR-XRRBWLSI.js → local-QXPV4RF5.js} +18 -14
  119. package/dist/{magic-string.es-6DE547FE.js → magic-string.es-ATGURXGQ.js} +2 -1
  120. package/dist/{morph-DCIZUK2Q.js → morph-WKKSW22O.js} +6 -5
  121. package/dist/{multipart-parser-ENLY4BKU.js → multipart-parser-KYOHF24X.js} +3 -2
  122. package/dist/{node-3DKQAOFU.js → node-5XXX7TNJ.js} +30 -29
  123. package/dist/{node-package-manager-HYTHPJBI.js → node-package-manager-O65VOP6W.js} +23 -23
  124. package/dist/{npa-AYOTDW63.js → npa-L2ZRSPZ2.js} +4 -3
  125. package/dist/{open-B7XFJJCK.js → open-JRS7RW22.js} +3 -2
  126. package/dist/out-AS7GH6TC.js +7 -0
  127. package/dist/{path-2NNC3QGW.js → path-JVVXOELJ.js} +10 -6
  128. package/dist/{source-map-V6UVDDPX.js → source-map-37TX6JEW.js} +2 -1
  129. package/dist/system-EEQBTJMJ.js +31 -0
  130. package/dist/tsconfig.tsbuildinfo +1 -1
  131. package/dist/{ui-5LSDG3C5.js → ui-3BAHGNCQ.js} +20 -20
  132. package/dist/{workerd-TFH7T6NI.js → workerd-WR22YQIS.js} +29 -28
  133. package/oclif.manifest.json +108 -93
  134. package/package.json +15 -5
  135. package/dist/assets/dev-console/extensions/dev-console/assets/index-792a0c8d.css +0 -1
  136. package/dist/chunk-3LWRRBH5.js +0 -75
  137. package/dist/chunk-3PIGYQSE.js +0 -36
  138. package/dist/chunk-CK7MF3LY.js +0 -28803
  139. package/dist/chunk-J4I3URIN.js +0 -893
  140. package/dist/chunk-MHMFNQE3.js +0 -76
  141. package/dist/chunk-MXHK26B3.js +0 -89
  142. package/dist/chunk-NJP5GFNN.js +0 -29224
  143. package/dist/chunk-OC4AY5G7.js +0 -11936
  144. package/dist/chunk-OQBI57X3.js +0 -22
  145. package/dist/chunk-RPRKZ6JC.js +0 -53861
  146. package/dist/chunk-RTZHOWFC.js +0 -5485
  147. package/dist/chunk-SZQX5J7X.js +0 -64
  148. package/dist/chunk-T77LT3XG.js +0 -4743
  149. package/dist/chunk-UV4APOMB.js +0 -273
  150. package/dist/chunk-VF4VWJWS.js +0 -213222
  151. package/dist/chunk-WZBNLCJ5.js +0 -13452
  152. package/dist/chunk-YWPV7MV2.js +0 -16432
  153. package/dist/chunk-ZLGRKPW3.js +0 -68
  154. package/dist/chunk-ZZGXXS5X.js +0 -819
  155. package/dist/cli/commands/auth/logout.js.map +0 -1
  156. package/dist/cli/commands/debug/command-flags.js.map +0 -1
  157. package/dist/cli/commands/demo/catalog.js.map +0 -1
  158. package/dist/cli/commands/demo/generate-file.js.map +0 -1
  159. package/dist/cli/commands/demo/index.js.map +0 -1
  160. package/dist/cli/commands/demo/print-ai-prompt.js.map +0 -1
  161. package/dist/cli/commands/docs/generate.js.map +0 -1
  162. package/dist/cli/commands/help.js.map +0 -1
  163. package/dist/cli/commands/kitchen-sink/async.js.map +0 -1
  164. package/dist/cli/commands/kitchen-sink/index.js.map +0 -1
  165. package/dist/cli/commands/kitchen-sink/prompts.js.map +0 -1
  166. package/dist/cli/commands/kitchen-sink/static.js.map +0 -1
  167. package/dist/cli/commands/search.js.map +0 -1
  168. package/dist/cli/commands/upgrade.js.map +0 -1
  169. package/dist/cli/commands/version.js.map +0 -1
  170. package/dist/cli/services/commands/search.js.map +0 -1
  171. package/dist/cli/services/commands/version.js.map +0 -1
  172. package/dist/cli/services/demo.js.map +0 -1
  173. package/dist/cli/services/kitchen-sink/async.js.map +0 -1
  174. package/dist/cli/services/kitchen-sink/prompts.js.map +0 -1
  175. package/dist/cli/services/kitchen-sink/static.js.map +0 -1
  176. package/dist/cli/services/upgrade.js.map +0 -1
  177. package/dist/custom-oclif-loader-OD47SFAU.js +0 -92
  178. package/dist/del-ICEHOC6W-GYLFYUKX.js +0 -2817
  179. package/dist/devtools-6HZ2IPFU-GLFJP63E.js +0 -3557
  180. package/dist/devtools-IHJDLLT4.js +0 -77
  181. package/dist/error-handler-EPMFPTYX.js +0 -37
  182. package/dist/error-handler-WI4YVJIS-U3BMMYNJ.js +0 -31
  183. package/dist/error-handler-WL3Q25NI.js +0 -45
  184. package/dist/hooks/postrun.js.map +0 -1
  185. package/dist/hooks/prerun.js.map +0 -1
  186. package/dist/index.js.map +0 -1
  187. package/dist/lib-76RCE6WZ-5IYGTKKK.js +0 -17
  188. package/dist/lib-UYK3ZLZK.js +0 -13
  189. package/dist/local-KISH2IRF.js +0 -67
  190. package/dist/multipart-parser-ENLY4BKU-IUS26CJU.js +0 -363
  191. package/dist/node-package-manager-S7TSAUJZ-KKDY6KSF.js +0 -70
  192. package/dist/open-B7XFJJCK-4XEFFVL7.js +0 -295
  193. package/dist/out-LRIJ35RZ.js +0 -6
  194. package/dist/out-M5MRQZP5-YHIOILKU.js +0 -14
  195. package/dist/path-HO4HBKK5-4Q2BBYUA.js +0 -33
  196. package/dist/system-LIP7AECY.js +0 -33
  197. package/dist/ui-FUZYK6S3-PVVDPVD5.js +0 -51
@@ -1,3557 +0,0 @@
1
- import {
2
- __commonJS,
3
- __require,
4
- __toESM,
5
- init_cjs_shims as init_cjs_shims2
6
- } from "./chunk-ZLGRKPW3.js";
7
- import {
8
- init_cjs_shims
9
- } from "./chunk-M63RTPGR.js";
10
-
11
- // ../create-app/dist/devtools-6HZ2IPFU.js
12
- init_cjs_shims();
13
- import devtools from "react-devtools-core";
14
- var require_stream = __commonJS({
15
- "../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/stream.js"(exports, module) {
16
- "use strict";
17
- init_cjs_shims2();
18
- var { Duplex } = __require("stream");
19
- function emitClose(stream) {
20
- stream.emit("close");
21
- }
22
- function duplexOnEnd() {
23
- if (!this.destroyed && this._writableState.finished) {
24
- this.destroy();
25
- }
26
- }
27
- function duplexOnError(err) {
28
- this.removeListener("error", duplexOnError);
29
- this.destroy();
30
- if (this.listenerCount("error") === 0) {
31
- this.emit("error", err);
32
- }
33
- }
34
- function createWebSocketStream2(ws, options) {
35
- let terminateOnDestroy = true;
36
- const duplex = new Duplex({
37
- ...options,
38
- autoDestroy: false,
39
- emitClose: false,
40
- objectMode: false,
41
- writableObjectMode: false
42
- });
43
- ws.on("message", function message(msg, isBinary) {
44
- const data = !isBinary && duplex._readableState.objectMode ? msg.toString() : msg;
45
- if (!duplex.push(data))
46
- ws.pause();
47
- });
48
- ws.once("error", function error(err) {
49
- if (duplex.destroyed)
50
- return;
51
- terminateOnDestroy = false;
52
- duplex.destroy(err);
53
- });
54
- ws.once("close", function close() {
55
- if (duplex.destroyed)
56
- return;
57
- duplex.push(null);
58
- });
59
- duplex._destroy = function(err, callback) {
60
- if (ws.readyState === ws.CLOSED) {
61
- callback(err);
62
- process.nextTick(emitClose, duplex);
63
- return;
64
- }
65
- let called = false;
66
- ws.once("error", function error(err2) {
67
- called = true;
68
- callback(err2);
69
- });
70
- ws.once("close", function close() {
71
- if (!called)
72
- callback(err);
73
- process.nextTick(emitClose, duplex);
74
- });
75
- if (terminateOnDestroy)
76
- ws.terminate();
77
- };
78
- duplex._final = function(callback) {
79
- if (ws.readyState === ws.CONNECTING) {
80
- ws.once("open", function open() {
81
- duplex._final(callback);
82
- });
83
- return;
84
- }
85
- if (ws._socket === null)
86
- return;
87
- if (ws._socket._writableState.finished) {
88
- callback();
89
- if (duplex._readableState.endEmitted)
90
- duplex.destroy();
91
- } else {
92
- ws._socket.once("finish", function finish() {
93
- callback();
94
- });
95
- ws.close();
96
- }
97
- };
98
- duplex._read = function() {
99
- if (ws.isPaused)
100
- ws.resume();
101
- };
102
- duplex._write = function(chunk, encoding, callback) {
103
- if (ws.readyState === ws.CONNECTING) {
104
- ws.once("open", function open() {
105
- duplex._write(chunk, encoding, callback);
106
- });
107
- return;
108
- }
109
- ws.send(chunk, callback);
110
- };
111
- duplex.on("end", duplexOnEnd);
112
- duplex.on("error", duplexOnError);
113
- return duplex;
114
- }
115
- module.exports = createWebSocketStream2;
116
- }
117
- });
118
- var require_constants = __commonJS({
119
- "../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/constants.js"(exports, module) {
120
- "use strict";
121
- init_cjs_shims2();
122
- module.exports = {
123
- BINARY_TYPES: ["nodebuffer", "arraybuffer", "fragments"],
124
- EMPTY_BUFFER: Buffer.alloc(0),
125
- GUID: "258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
126
- kForOnEventAttribute: Symbol("kIsForOnEventAttribute"),
127
- kListener: Symbol("kListener"),
128
- kStatusCode: Symbol("status-code"),
129
- kWebSocket: Symbol("websocket"),
130
- NOOP: () => {
131
- }
132
- };
133
- }
134
- });
135
- var require_buffer_util = __commonJS({
136
- "../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/buffer-util.js"(exports, module) {
137
- "use strict";
138
- init_cjs_shims2();
139
- var { EMPTY_BUFFER } = require_constants();
140
- var FastBuffer = Buffer[Symbol.species];
141
- function concat(list, totalLength) {
142
- if (list.length === 0)
143
- return EMPTY_BUFFER;
144
- if (list.length === 1)
145
- return list[0];
146
- const target = Buffer.allocUnsafe(totalLength);
147
- let offset = 0;
148
- for (let i = 0; i < list.length; i++) {
149
- const buf = list[i];
150
- target.set(buf, offset);
151
- offset += buf.length;
152
- }
153
- if (offset < totalLength) {
154
- return new FastBuffer(target.buffer, target.byteOffset, offset);
155
- }
156
- return target;
157
- }
158
- function _mask(source, mask, output, offset, length) {
159
- for (let i = 0; i < length; i++) {
160
- output[offset + i] = source[i] ^ mask[i & 3];
161
- }
162
- }
163
- function _unmask(buffer, mask) {
164
- for (let i = 0; i < buffer.length; i++) {
165
- buffer[i] ^= mask[i & 3];
166
- }
167
- }
168
- function toArrayBuffer(buf) {
169
- if (buf.length === buf.buffer.byteLength) {
170
- return buf.buffer;
171
- }
172
- return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length);
173
- }
174
- function toBuffer(data) {
175
- toBuffer.readOnly = true;
176
- if (Buffer.isBuffer(data))
177
- return data;
178
- let buf;
179
- if (data instanceof ArrayBuffer) {
180
- buf = new FastBuffer(data);
181
- } else if (ArrayBuffer.isView(data)) {
182
- buf = new FastBuffer(data.buffer, data.byteOffset, data.byteLength);
183
- } else {
184
- buf = Buffer.from(data);
185
- toBuffer.readOnly = false;
186
- }
187
- return buf;
188
- }
189
- module.exports = {
190
- concat,
191
- mask: _mask,
192
- toArrayBuffer,
193
- toBuffer,
194
- unmask: _unmask
195
- };
196
- if (!process.env.WS_NO_BUFFER_UTIL) {
197
- try {
198
- const bufferUtil = __require("bufferutil");
199
- module.exports.mask = function(source, mask, output, offset, length) {
200
- if (length < 48)
201
- _mask(source, mask, output, offset, length);
202
- else
203
- bufferUtil.mask(source, mask, output, offset, length);
204
- };
205
- module.exports.unmask = function(buffer, mask) {
206
- if (buffer.length < 32)
207
- _unmask(buffer, mask);
208
- else
209
- bufferUtil.unmask(buffer, mask);
210
- };
211
- } catch (e) {
212
- }
213
- }
214
- }
215
- });
216
- var require_limiter = __commonJS({
217
- "../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/limiter.js"(exports, module) {
218
- "use strict";
219
- init_cjs_shims2();
220
- var kDone = Symbol("kDone");
221
- var kRun = Symbol("kRun");
222
- var Limiter = class {
223
- /**
224
- * Creates a new `Limiter`.
225
- *
226
- * @param {Number} [concurrency=Infinity] The maximum number of jobs allowed
227
- * to run concurrently
228
- */
229
- constructor(concurrency) {
230
- this[kDone] = () => {
231
- this.pending--;
232
- this[kRun]();
233
- };
234
- this.concurrency = concurrency || Infinity;
235
- this.jobs = [];
236
- this.pending = 0;
237
- }
238
- /**
239
- * Adds a job to the queue.
240
- *
241
- * @param {Function} job The job to run
242
- * @public
243
- */
244
- add(job) {
245
- this.jobs.push(job);
246
- this[kRun]();
247
- }
248
- /**
249
- * Removes a job from the queue and runs it if possible.
250
- *
251
- * @private
252
- */
253
- [kRun]() {
254
- if (this.pending === this.concurrency)
255
- return;
256
- if (this.jobs.length) {
257
- const job = this.jobs.shift();
258
- this.pending++;
259
- job(this[kDone]);
260
- }
261
- }
262
- };
263
- module.exports = Limiter;
264
- }
265
- });
266
- var require_permessage_deflate = __commonJS({
267
- "../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/permessage-deflate.js"(exports, module) {
268
- "use strict";
269
- init_cjs_shims2();
270
- var zlib = __require("zlib");
271
- var bufferUtil = require_buffer_util();
272
- var Limiter = require_limiter();
273
- var { kStatusCode } = require_constants();
274
- var FastBuffer = Buffer[Symbol.species];
275
- var TRAILER = Buffer.from([0, 0, 255, 255]);
276
- var kPerMessageDeflate = Symbol("permessage-deflate");
277
- var kTotalLength = Symbol("total-length");
278
- var kCallback = Symbol("callback");
279
- var kBuffers = Symbol("buffers");
280
- var kError = Symbol("error");
281
- var zlibLimiter;
282
- var PerMessageDeflate = class {
283
- /**
284
- * Creates a PerMessageDeflate instance.
285
- *
286
- * @param {Object} [options] Configuration options
287
- * @param {(Boolean|Number)} [options.clientMaxWindowBits] Advertise support
288
- * for, or request, a custom client window size
289
- * @param {Boolean} [options.clientNoContextTakeover=false] Advertise/
290
- * acknowledge disabling of client context takeover
291
- * @param {Number} [options.concurrencyLimit=10] The number of concurrent
292
- * calls to zlib
293
- * @param {(Boolean|Number)} [options.serverMaxWindowBits] Request/confirm the
294
- * use of a custom server window size
295
- * @param {Boolean} [options.serverNoContextTakeover=false] Request/accept
296
- * disabling of server context takeover
297
- * @param {Number} [options.threshold=1024] Size (in bytes) below which
298
- * messages should not be compressed if context takeover is disabled
299
- * @param {Object} [options.zlibDeflateOptions] Options to pass to zlib on
300
- * deflate
301
- * @param {Object} [options.zlibInflateOptions] Options to pass to zlib on
302
- * inflate
303
- * @param {Boolean} [isServer=false] Create the instance in either server or
304
- * client mode
305
- * @param {Number} [maxPayload=0] The maximum allowed message length
306
- */
307
- constructor(options, isServer, maxPayload) {
308
- this._maxPayload = maxPayload | 0;
309
- this._options = options || {};
310
- this._threshold = this._options.threshold !== void 0 ? this._options.threshold : 1024;
311
- this._isServer = !!isServer;
312
- this._deflate = null;
313
- this._inflate = null;
314
- this.params = null;
315
- if (!zlibLimiter) {
316
- const concurrency = this._options.concurrencyLimit !== void 0 ? this._options.concurrencyLimit : 10;
317
- zlibLimiter = new Limiter(concurrency);
318
- }
319
- }
320
- /**
321
- * @type {String}
322
- */
323
- static get extensionName() {
324
- return "permessage-deflate";
325
- }
326
- /**
327
- * Create an extension negotiation offer.
328
- *
329
- * @return {Object} Extension parameters
330
- * @public
331
- */
332
- offer() {
333
- const params = {};
334
- if (this._options.serverNoContextTakeover) {
335
- params.server_no_context_takeover = true;
336
- }
337
- if (this._options.clientNoContextTakeover) {
338
- params.client_no_context_takeover = true;
339
- }
340
- if (this._options.serverMaxWindowBits) {
341
- params.server_max_window_bits = this._options.serverMaxWindowBits;
342
- }
343
- if (this._options.clientMaxWindowBits) {
344
- params.client_max_window_bits = this._options.clientMaxWindowBits;
345
- } else if (this._options.clientMaxWindowBits == null) {
346
- params.client_max_window_bits = true;
347
- }
348
- return params;
349
- }
350
- /**
351
- * Accept an extension negotiation offer/response.
352
- *
353
- * @param {Array} configurations The extension negotiation offers/reponse
354
- * @return {Object} Accepted configuration
355
- * @public
356
- */
357
- accept(configurations) {
358
- configurations = this.normalizeParams(configurations);
359
- this.params = this._isServer ? this.acceptAsServer(configurations) : this.acceptAsClient(configurations);
360
- return this.params;
361
- }
362
- /**
363
- * Releases all resources used by the extension.
364
- *
365
- * @public
366
- */
367
- cleanup() {
368
- if (this._inflate) {
369
- this._inflate.close();
370
- this._inflate = null;
371
- }
372
- if (this._deflate) {
373
- const callback = this._deflate[kCallback];
374
- this._deflate.close();
375
- this._deflate = null;
376
- if (callback) {
377
- callback(
378
- new Error(
379
- "The deflate stream was closed while data was being processed"
380
- )
381
- );
382
- }
383
- }
384
- }
385
- /**
386
- * Accept an extension negotiation offer.
387
- *
388
- * @param {Array} offers The extension negotiation offers
389
- * @return {Object} Accepted configuration
390
- * @private
391
- */
392
- acceptAsServer(offers) {
393
- const opts = this._options;
394
- const accepted = offers.find((params) => {
395
- if (opts.serverNoContextTakeover === false && params.server_no_context_takeover || params.server_max_window_bits && (opts.serverMaxWindowBits === false || typeof opts.serverMaxWindowBits === "number" && opts.serverMaxWindowBits > params.server_max_window_bits) || typeof opts.clientMaxWindowBits === "number" && !params.client_max_window_bits) {
396
- return false;
397
- }
398
- return true;
399
- });
400
- if (!accepted) {
401
- throw new Error("None of the extension offers can be accepted");
402
- }
403
- if (opts.serverNoContextTakeover) {
404
- accepted.server_no_context_takeover = true;
405
- }
406
- if (opts.clientNoContextTakeover) {
407
- accepted.client_no_context_takeover = true;
408
- }
409
- if (typeof opts.serverMaxWindowBits === "number") {
410
- accepted.server_max_window_bits = opts.serverMaxWindowBits;
411
- }
412
- if (typeof opts.clientMaxWindowBits === "number") {
413
- accepted.client_max_window_bits = opts.clientMaxWindowBits;
414
- } else if (accepted.client_max_window_bits === true || opts.clientMaxWindowBits === false) {
415
- delete accepted.client_max_window_bits;
416
- }
417
- return accepted;
418
- }
419
- /**
420
- * Accept the extension negotiation response.
421
- *
422
- * @param {Array} response The extension negotiation response
423
- * @return {Object} Accepted configuration
424
- * @private
425
- */
426
- acceptAsClient(response) {
427
- const params = response[0];
428
- if (this._options.clientNoContextTakeover === false && params.client_no_context_takeover) {
429
- throw new Error('Unexpected parameter "client_no_context_takeover"');
430
- }
431
- if (!params.client_max_window_bits) {
432
- if (typeof this._options.clientMaxWindowBits === "number") {
433
- params.client_max_window_bits = this._options.clientMaxWindowBits;
434
- }
435
- } else if (this._options.clientMaxWindowBits === false || typeof this._options.clientMaxWindowBits === "number" && params.client_max_window_bits > this._options.clientMaxWindowBits) {
436
- throw new Error(
437
- 'Unexpected or invalid parameter "client_max_window_bits"'
438
- );
439
- }
440
- return params;
441
- }
442
- /**
443
- * Normalize parameters.
444
- *
445
- * @param {Array} configurations The extension negotiation offers/reponse
446
- * @return {Array} The offers/response with normalized parameters
447
- * @private
448
- */
449
- normalizeParams(configurations) {
450
- configurations.forEach((params) => {
451
- Object.keys(params).forEach((key) => {
452
- let value = params[key];
453
- if (value.length > 1) {
454
- throw new Error(`Parameter "${key}" must have only a single value`);
455
- }
456
- value = value[0];
457
- if (key === "client_max_window_bits") {
458
- if (value !== true) {
459
- const num = +value;
460
- if (!Number.isInteger(num) || num < 8 || num > 15) {
461
- throw new TypeError(
462
- `Invalid value for parameter "${key}": ${value}`
463
- );
464
- }
465
- value = num;
466
- } else if (!this._isServer) {
467
- throw new TypeError(
468
- `Invalid value for parameter "${key}": ${value}`
469
- );
470
- }
471
- } else if (key === "server_max_window_bits") {
472
- const num = +value;
473
- if (!Number.isInteger(num) || num < 8 || num > 15) {
474
- throw new TypeError(
475
- `Invalid value for parameter "${key}": ${value}`
476
- );
477
- }
478
- value = num;
479
- } else if (key === "client_no_context_takeover" || key === "server_no_context_takeover") {
480
- if (value !== true) {
481
- throw new TypeError(
482
- `Invalid value for parameter "${key}": ${value}`
483
- );
484
- }
485
- } else {
486
- throw new Error(`Unknown parameter "${key}"`);
487
- }
488
- params[key] = value;
489
- });
490
- });
491
- return configurations;
492
- }
493
- /**
494
- * Decompress data. Concurrency limited.
495
- *
496
- * @param {Buffer} data Compressed data
497
- * @param {Boolean} fin Specifies whether or not this is the last fragment
498
- * @param {Function} callback Callback
499
- * @public
500
- */
501
- decompress(data, fin, callback) {
502
- zlibLimiter.add((done) => {
503
- this._decompress(data, fin, (err, result) => {
504
- done();
505
- callback(err, result);
506
- });
507
- });
508
- }
509
- /**
510
- * Compress data. Concurrency limited.
511
- *
512
- * @param {(Buffer|String)} data Data to compress
513
- * @param {Boolean} fin Specifies whether or not this is the last fragment
514
- * @param {Function} callback Callback
515
- * @public
516
- */
517
- compress(data, fin, callback) {
518
- zlibLimiter.add((done) => {
519
- this._compress(data, fin, (err, result) => {
520
- done();
521
- callback(err, result);
522
- });
523
- });
524
- }
525
- /**
526
- * Decompress data.
527
- *
528
- * @param {Buffer} data Compressed data
529
- * @param {Boolean} fin Specifies whether or not this is the last fragment
530
- * @param {Function} callback Callback
531
- * @private
532
- */
533
- _decompress(data, fin, callback) {
534
- const endpoint = this._isServer ? "client" : "server";
535
- if (!this._inflate) {
536
- const key = `${endpoint}_max_window_bits`;
537
- const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
538
- this._inflate = zlib.createInflateRaw({
539
- ...this._options.zlibInflateOptions,
540
- windowBits
541
- });
542
- this._inflate[kPerMessageDeflate] = this;
543
- this._inflate[kTotalLength] = 0;
544
- this._inflate[kBuffers] = [];
545
- this._inflate.on("error", inflateOnError);
546
- this._inflate.on("data", inflateOnData);
547
- }
548
- this._inflate[kCallback] = callback;
549
- this._inflate.write(data);
550
- if (fin)
551
- this._inflate.write(TRAILER);
552
- this._inflate.flush(() => {
553
- const err = this._inflate[kError];
554
- if (err) {
555
- this._inflate.close();
556
- this._inflate = null;
557
- callback(err);
558
- return;
559
- }
560
- const data2 = bufferUtil.concat(
561
- this._inflate[kBuffers],
562
- this._inflate[kTotalLength]
563
- );
564
- if (this._inflate._readableState.endEmitted) {
565
- this._inflate.close();
566
- this._inflate = null;
567
- } else {
568
- this._inflate[kTotalLength] = 0;
569
- this._inflate[kBuffers] = [];
570
- if (fin && this.params[`${endpoint}_no_context_takeover`]) {
571
- this._inflate.reset();
572
- }
573
- }
574
- callback(null, data2);
575
- });
576
- }
577
- /**
578
- * Compress data.
579
- *
580
- * @param {(Buffer|String)} data Data to compress
581
- * @param {Boolean} fin Specifies whether or not this is the last fragment
582
- * @param {Function} callback Callback
583
- * @private
584
- */
585
- _compress(data, fin, callback) {
586
- const endpoint = this._isServer ? "server" : "client";
587
- if (!this._deflate) {
588
- const key = `${endpoint}_max_window_bits`;
589
- const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
590
- this._deflate = zlib.createDeflateRaw({
591
- ...this._options.zlibDeflateOptions,
592
- windowBits
593
- });
594
- this._deflate[kTotalLength] = 0;
595
- this._deflate[kBuffers] = [];
596
- this._deflate.on("data", deflateOnData);
597
- }
598
- this._deflate[kCallback] = callback;
599
- this._deflate.write(data);
600
- this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
601
- if (!this._deflate) {
602
- return;
603
- }
604
- let data2 = bufferUtil.concat(
605
- this._deflate[kBuffers],
606
- this._deflate[kTotalLength]
607
- );
608
- if (fin) {
609
- data2 = new FastBuffer(data2.buffer, data2.byteOffset, data2.length - 4);
610
- }
611
- this._deflate[kCallback] = null;
612
- this._deflate[kTotalLength] = 0;
613
- this._deflate[kBuffers] = [];
614
- if (fin && this.params[`${endpoint}_no_context_takeover`]) {
615
- this._deflate.reset();
616
- }
617
- callback(null, data2);
618
- });
619
- }
620
- };
621
- module.exports = PerMessageDeflate;
622
- function deflateOnData(chunk) {
623
- this[kBuffers].push(chunk);
624
- this[kTotalLength] += chunk.length;
625
- }
626
- function inflateOnData(chunk) {
627
- this[kTotalLength] += chunk.length;
628
- if (this[kPerMessageDeflate]._maxPayload < 1 || this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload) {
629
- this[kBuffers].push(chunk);
630
- return;
631
- }
632
- this[kError] = new RangeError("Max payload size exceeded");
633
- this[kError].code = "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH";
634
- this[kError][kStatusCode] = 1009;
635
- this.removeListener("data", inflateOnData);
636
- this.reset();
637
- }
638
- function inflateOnError(err) {
639
- this[kPerMessageDeflate]._inflate = null;
640
- err[kStatusCode] = 1007;
641
- this[kCallback](err);
642
- }
643
- }
644
- });
645
- var require_validation = __commonJS({
646
- "../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/validation.js"(exports, module) {
647
- "use strict";
648
- init_cjs_shims2();
649
- var { isUtf8 } = __require("buffer");
650
- var tokenChars = [
651
- 0,
652
- 0,
653
- 0,
654
- 0,
655
- 0,
656
- 0,
657
- 0,
658
- 0,
659
- 0,
660
- 0,
661
- 0,
662
- 0,
663
- 0,
664
- 0,
665
- 0,
666
- 0,
667
- // 0 - 15
668
- 0,
669
- 0,
670
- 0,
671
- 0,
672
- 0,
673
- 0,
674
- 0,
675
- 0,
676
- 0,
677
- 0,
678
- 0,
679
- 0,
680
- 0,
681
- 0,
682
- 0,
683
- 0,
684
- // 16 - 31
685
- 0,
686
- 1,
687
- 0,
688
- 1,
689
- 1,
690
- 1,
691
- 1,
692
- 1,
693
- 0,
694
- 0,
695
- 1,
696
- 1,
697
- 0,
698
- 1,
699
- 1,
700
- 0,
701
- // 32 - 47
702
- 1,
703
- 1,
704
- 1,
705
- 1,
706
- 1,
707
- 1,
708
- 1,
709
- 1,
710
- 1,
711
- 1,
712
- 0,
713
- 0,
714
- 0,
715
- 0,
716
- 0,
717
- 0,
718
- // 48 - 63
719
- 0,
720
- 1,
721
- 1,
722
- 1,
723
- 1,
724
- 1,
725
- 1,
726
- 1,
727
- 1,
728
- 1,
729
- 1,
730
- 1,
731
- 1,
732
- 1,
733
- 1,
734
- 1,
735
- // 64 - 79
736
- 1,
737
- 1,
738
- 1,
739
- 1,
740
- 1,
741
- 1,
742
- 1,
743
- 1,
744
- 1,
745
- 1,
746
- 1,
747
- 0,
748
- 0,
749
- 0,
750
- 1,
751
- 1,
752
- // 80 - 95
753
- 1,
754
- 1,
755
- 1,
756
- 1,
757
- 1,
758
- 1,
759
- 1,
760
- 1,
761
- 1,
762
- 1,
763
- 1,
764
- 1,
765
- 1,
766
- 1,
767
- 1,
768
- 1,
769
- // 96 - 111
770
- 1,
771
- 1,
772
- 1,
773
- 1,
774
- 1,
775
- 1,
776
- 1,
777
- 1,
778
- 1,
779
- 1,
780
- 1,
781
- 0,
782
- 1,
783
- 0,
784
- 1,
785
- 0
786
- // 112 - 127
787
- ];
788
- function isValidStatusCode(code) {
789
- return code >= 1e3 && code <= 1014 && code !== 1004 && code !== 1005 && code !== 1006 || code >= 3e3 && code <= 4999;
790
- }
791
- function _isValidUTF8(buf) {
792
- const len = buf.length;
793
- let i = 0;
794
- while (i < len) {
795
- if ((buf[i] & 128) === 0) {
796
- i++;
797
- } else if ((buf[i] & 224) === 192) {
798
- if (i + 1 === len || (buf[i + 1] & 192) !== 128 || (buf[i] & 254) === 192) {
799
- return false;
800
- }
801
- i += 2;
802
- } else if ((buf[i] & 240) === 224) {
803
- if (i + 2 >= len || (buf[i + 1] & 192) !== 128 || (buf[i + 2] & 192) !== 128 || buf[i] === 224 && (buf[i + 1] & 224) === 128 || // Overlong
804
- buf[i] === 237 && (buf[i + 1] & 224) === 160) {
805
- return false;
806
- }
807
- i += 3;
808
- } else if ((buf[i] & 248) === 240) {
809
- if (i + 3 >= len || (buf[i + 1] & 192) !== 128 || (buf[i + 2] & 192) !== 128 || (buf[i + 3] & 192) !== 128 || buf[i] === 240 && (buf[i + 1] & 240) === 128 || // Overlong
810
- buf[i] === 244 && buf[i + 1] > 143 || buf[i] > 244) {
811
- return false;
812
- }
813
- i += 4;
814
- } else {
815
- return false;
816
- }
817
- }
818
- return true;
819
- }
820
- module.exports = {
821
- isValidStatusCode,
822
- isValidUTF8: _isValidUTF8,
823
- tokenChars
824
- };
825
- if (isUtf8) {
826
- module.exports.isValidUTF8 = function(buf) {
827
- return buf.length < 24 ? _isValidUTF8(buf) : isUtf8(buf);
828
- };
829
- } else if (!process.env.WS_NO_UTF_8_VALIDATE) {
830
- try {
831
- const isValidUTF8 = __require("utf-8-validate");
832
- module.exports.isValidUTF8 = function(buf) {
833
- return buf.length < 32 ? _isValidUTF8(buf) : isValidUTF8(buf);
834
- };
835
- } catch (e) {
836
- }
837
- }
838
- }
839
- });
840
- var require_receiver = __commonJS({
841
- "../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/receiver.js"(exports, module) {
842
- "use strict";
843
- init_cjs_shims2();
844
- var { Writable } = __require("stream");
845
- var PerMessageDeflate = require_permessage_deflate();
846
- var {
847
- BINARY_TYPES,
848
- EMPTY_BUFFER,
849
- kStatusCode,
850
- kWebSocket
851
- } = require_constants();
852
- var { concat, toArrayBuffer, unmask } = require_buffer_util();
853
- var { isValidStatusCode, isValidUTF8 } = require_validation();
854
- var FastBuffer = Buffer[Symbol.species];
855
- var GET_INFO = 0;
856
- var GET_PAYLOAD_LENGTH_16 = 1;
857
- var GET_PAYLOAD_LENGTH_64 = 2;
858
- var GET_MASK = 3;
859
- var GET_DATA = 4;
860
- var INFLATING = 5;
861
- var Receiver2 = class extends Writable {
862
- /**
863
- * Creates a Receiver instance.
864
- *
865
- * @param {Object} [options] Options object
866
- * @param {String} [options.binaryType=nodebuffer] The type for binary data
867
- * @param {Object} [options.extensions] An object containing the negotiated
868
- * extensions
869
- * @param {Boolean} [options.isServer=false] Specifies whether to operate in
870
- * client or server mode
871
- * @param {Number} [options.maxPayload=0] The maximum allowed message length
872
- * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
873
- * not to skip UTF-8 validation for text and close messages
874
- */
875
- constructor(options = {}) {
876
- super();
877
- this._binaryType = options.binaryType || BINARY_TYPES[0];
878
- this._extensions = options.extensions || {};
879
- this._isServer = !!options.isServer;
880
- this._maxPayload = options.maxPayload | 0;
881
- this._skipUTF8Validation = !!options.skipUTF8Validation;
882
- this[kWebSocket] = void 0;
883
- this._bufferedBytes = 0;
884
- this._buffers = [];
885
- this._compressed = false;
886
- this._payloadLength = 0;
887
- this._mask = void 0;
888
- this._fragmented = 0;
889
- this._masked = false;
890
- this._fin = false;
891
- this._opcode = 0;
892
- this._totalPayloadLength = 0;
893
- this._messageLength = 0;
894
- this._fragments = [];
895
- this._state = GET_INFO;
896
- this._loop = false;
897
- }
898
- /**
899
- * Implements `Writable.prototype._write()`.
900
- *
901
- * @param {Buffer} chunk The chunk of data to write
902
- * @param {String} encoding The character encoding of `chunk`
903
- * @param {Function} cb Callback
904
- * @private
905
- */
906
- _write(chunk, encoding, cb) {
907
- if (this._opcode === 8 && this._state == GET_INFO)
908
- return cb();
909
- this._bufferedBytes += chunk.length;
910
- this._buffers.push(chunk);
911
- this.startLoop(cb);
912
- }
913
- /**
914
- * Consumes `n` bytes from the buffered data.
915
- *
916
- * @param {Number} n The number of bytes to consume
917
- * @return {Buffer} The consumed bytes
918
- * @private
919
- */
920
- consume(n) {
921
- this._bufferedBytes -= n;
922
- if (n === this._buffers[0].length)
923
- return this._buffers.shift();
924
- if (n < this._buffers[0].length) {
925
- const buf = this._buffers[0];
926
- this._buffers[0] = new FastBuffer(
927
- buf.buffer,
928
- buf.byteOffset + n,
929
- buf.length - n
930
- );
931
- return new FastBuffer(buf.buffer, buf.byteOffset, n);
932
- }
933
- const dst = Buffer.allocUnsafe(n);
934
- do {
935
- const buf = this._buffers[0];
936
- const offset = dst.length - n;
937
- if (n >= buf.length) {
938
- dst.set(this._buffers.shift(), offset);
939
- } else {
940
- dst.set(new Uint8Array(buf.buffer, buf.byteOffset, n), offset);
941
- this._buffers[0] = new FastBuffer(
942
- buf.buffer,
943
- buf.byteOffset + n,
944
- buf.length - n
945
- );
946
- }
947
- n -= buf.length;
948
- } while (n > 0);
949
- return dst;
950
- }
951
- /**
952
- * Starts the parsing loop.
953
- *
954
- * @param {Function} cb Callback
955
- * @private
956
- */
957
- startLoop(cb) {
958
- let err;
959
- this._loop = true;
960
- do {
961
- switch (this._state) {
962
- case GET_INFO:
963
- err = this.getInfo();
964
- break;
965
- case GET_PAYLOAD_LENGTH_16:
966
- err = this.getPayloadLength16();
967
- break;
968
- case GET_PAYLOAD_LENGTH_64:
969
- err = this.getPayloadLength64();
970
- break;
971
- case GET_MASK:
972
- this.getMask();
973
- break;
974
- case GET_DATA:
975
- err = this.getData(cb);
976
- break;
977
- default:
978
- this._loop = false;
979
- return;
980
- }
981
- } while (this._loop);
982
- cb(err);
983
- }
984
- /**
985
- * Reads the first two bytes of a frame.
986
- *
987
- * @return {(RangeError|undefined)} A possible error
988
- * @private
989
- */
990
- getInfo() {
991
- if (this._bufferedBytes < 2) {
992
- this._loop = false;
993
- return;
994
- }
995
- const buf = this.consume(2);
996
- if ((buf[0] & 48) !== 0) {
997
- this._loop = false;
998
- return error(
999
- RangeError,
1000
- "RSV2 and RSV3 must be clear",
1001
- true,
1002
- 1002,
1003
- "WS_ERR_UNEXPECTED_RSV_2_3"
1004
- );
1005
- }
1006
- const compressed = (buf[0] & 64) === 64;
1007
- if (compressed && !this._extensions[PerMessageDeflate.extensionName]) {
1008
- this._loop = false;
1009
- return error(
1010
- RangeError,
1011
- "RSV1 must be clear",
1012
- true,
1013
- 1002,
1014
- "WS_ERR_UNEXPECTED_RSV_1"
1015
- );
1016
- }
1017
- this._fin = (buf[0] & 128) === 128;
1018
- this._opcode = buf[0] & 15;
1019
- this._payloadLength = buf[1] & 127;
1020
- if (this._opcode === 0) {
1021
- if (compressed) {
1022
- this._loop = false;
1023
- return error(
1024
- RangeError,
1025
- "RSV1 must be clear",
1026
- true,
1027
- 1002,
1028
- "WS_ERR_UNEXPECTED_RSV_1"
1029
- );
1030
- }
1031
- if (!this._fragmented) {
1032
- this._loop = false;
1033
- return error(
1034
- RangeError,
1035
- "invalid opcode 0",
1036
- true,
1037
- 1002,
1038
- "WS_ERR_INVALID_OPCODE"
1039
- );
1040
- }
1041
- this._opcode = this._fragmented;
1042
- } else if (this._opcode === 1 || this._opcode === 2) {
1043
- if (this._fragmented) {
1044
- this._loop = false;
1045
- return error(
1046
- RangeError,
1047
- `invalid opcode ${this._opcode}`,
1048
- true,
1049
- 1002,
1050
- "WS_ERR_INVALID_OPCODE"
1051
- );
1052
- }
1053
- this._compressed = compressed;
1054
- } else if (this._opcode > 7 && this._opcode < 11) {
1055
- if (!this._fin) {
1056
- this._loop = false;
1057
- return error(
1058
- RangeError,
1059
- "FIN must be set",
1060
- true,
1061
- 1002,
1062
- "WS_ERR_EXPECTED_FIN"
1063
- );
1064
- }
1065
- if (compressed) {
1066
- this._loop = false;
1067
- return error(
1068
- RangeError,
1069
- "RSV1 must be clear",
1070
- true,
1071
- 1002,
1072
- "WS_ERR_UNEXPECTED_RSV_1"
1073
- );
1074
- }
1075
- if (this._payloadLength > 125 || this._opcode === 8 && this._payloadLength === 1) {
1076
- this._loop = false;
1077
- return error(
1078
- RangeError,
1079
- `invalid payload length ${this._payloadLength}`,
1080
- true,
1081
- 1002,
1082
- "WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH"
1083
- );
1084
- }
1085
- } else {
1086
- this._loop = false;
1087
- return error(
1088
- RangeError,
1089
- `invalid opcode ${this._opcode}`,
1090
- true,
1091
- 1002,
1092
- "WS_ERR_INVALID_OPCODE"
1093
- );
1094
- }
1095
- if (!this._fin && !this._fragmented)
1096
- this._fragmented = this._opcode;
1097
- this._masked = (buf[1] & 128) === 128;
1098
- if (this._isServer) {
1099
- if (!this._masked) {
1100
- this._loop = false;
1101
- return error(
1102
- RangeError,
1103
- "MASK must be set",
1104
- true,
1105
- 1002,
1106
- "WS_ERR_EXPECTED_MASK"
1107
- );
1108
- }
1109
- } else if (this._masked) {
1110
- this._loop = false;
1111
- return error(
1112
- RangeError,
1113
- "MASK must be clear",
1114
- true,
1115
- 1002,
1116
- "WS_ERR_UNEXPECTED_MASK"
1117
- );
1118
- }
1119
- if (this._payloadLength === 126)
1120
- this._state = GET_PAYLOAD_LENGTH_16;
1121
- else if (this._payloadLength === 127)
1122
- this._state = GET_PAYLOAD_LENGTH_64;
1123
- else
1124
- return this.haveLength();
1125
- }
1126
- /**
1127
- * Gets extended payload length (7+16).
1128
- *
1129
- * @return {(RangeError|undefined)} A possible error
1130
- * @private
1131
- */
1132
- getPayloadLength16() {
1133
- if (this._bufferedBytes < 2) {
1134
- this._loop = false;
1135
- return;
1136
- }
1137
- this._payloadLength = this.consume(2).readUInt16BE(0);
1138
- return this.haveLength();
1139
- }
1140
- /**
1141
- * Gets extended payload length (7+64).
1142
- *
1143
- * @return {(RangeError|undefined)} A possible error
1144
- * @private
1145
- */
1146
- getPayloadLength64() {
1147
- if (this._bufferedBytes < 8) {
1148
- this._loop = false;
1149
- return;
1150
- }
1151
- const buf = this.consume(8);
1152
- const num = buf.readUInt32BE(0);
1153
- if (num > Math.pow(2, 53 - 32) - 1) {
1154
- this._loop = false;
1155
- return error(
1156
- RangeError,
1157
- "Unsupported WebSocket frame: payload length > 2^53 - 1",
1158
- false,
1159
- 1009,
1160
- "WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH"
1161
- );
1162
- }
1163
- this._payloadLength = num * Math.pow(2, 32) + buf.readUInt32BE(4);
1164
- return this.haveLength();
1165
- }
1166
- /**
1167
- * Payload length has been read.
1168
- *
1169
- * @return {(RangeError|undefined)} A possible error
1170
- * @private
1171
- */
1172
- haveLength() {
1173
- if (this._payloadLength && this._opcode < 8) {
1174
- this._totalPayloadLength += this._payloadLength;
1175
- if (this._totalPayloadLength > this._maxPayload && this._maxPayload > 0) {
1176
- this._loop = false;
1177
- return error(
1178
- RangeError,
1179
- "Max payload size exceeded",
1180
- false,
1181
- 1009,
1182
- "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"
1183
- );
1184
- }
1185
- }
1186
- if (this._masked)
1187
- this._state = GET_MASK;
1188
- else
1189
- this._state = GET_DATA;
1190
- }
1191
- /**
1192
- * Reads mask bytes.
1193
- *
1194
- * @private
1195
- */
1196
- getMask() {
1197
- if (this._bufferedBytes < 4) {
1198
- this._loop = false;
1199
- return;
1200
- }
1201
- this._mask = this.consume(4);
1202
- this._state = GET_DATA;
1203
- }
1204
- /**
1205
- * Reads data bytes.
1206
- *
1207
- * @param {Function} cb Callback
1208
- * @return {(Error|RangeError|undefined)} A possible error
1209
- * @private
1210
- */
1211
- getData(cb) {
1212
- let data = EMPTY_BUFFER;
1213
- if (this._payloadLength) {
1214
- if (this._bufferedBytes < this._payloadLength) {
1215
- this._loop = false;
1216
- return;
1217
- }
1218
- data = this.consume(this._payloadLength);
1219
- if (this._masked && (this._mask[0] | this._mask[1] | this._mask[2] | this._mask[3]) !== 0) {
1220
- unmask(data, this._mask);
1221
- }
1222
- }
1223
- if (this._opcode > 7)
1224
- return this.controlMessage(data);
1225
- if (this._compressed) {
1226
- this._state = INFLATING;
1227
- this.decompress(data, cb);
1228
- return;
1229
- }
1230
- if (data.length) {
1231
- this._messageLength = this._totalPayloadLength;
1232
- this._fragments.push(data);
1233
- }
1234
- return this.dataMessage();
1235
- }
1236
- /**
1237
- * Decompresses data.
1238
- *
1239
- * @param {Buffer} data Compressed data
1240
- * @param {Function} cb Callback
1241
- * @private
1242
- */
1243
- decompress(data, cb) {
1244
- const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
1245
- perMessageDeflate.decompress(data, this._fin, (err, buf) => {
1246
- if (err)
1247
- return cb(err);
1248
- if (buf.length) {
1249
- this._messageLength += buf.length;
1250
- if (this._messageLength > this._maxPayload && this._maxPayload > 0) {
1251
- return cb(
1252
- error(
1253
- RangeError,
1254
- "Max payload size exceeded",
1255
- false,
1256
- 1009,
1257
- "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"
1258
- )
1259
- );
1260
- }
1261
- this._fragments.push(buf);
1262
- }
1263
- const er = this.dataMessage();
1264
- if (er)
1265
- return cb(er);
1266
- this.startLoop(cb);
1267
- });
1268
- }
1269
- /**
1270
- * Handles a data message.
1271
- *
1272
- * @return {(Error|undefined)} A possible error
1273
- * @private
1274
- */
1275
- dataMessage() {
1276
- if (this._fin) {
1277
- const messageLength = this._messageLength;
1278
- const fragments = this._fragments;
1279
- this._totalPayloadLength = 0;
1280
- this._messageLength = 0;
1281
- this._fragmented = 0;
1282
- this._fragments = [];
1283
- if (this._opcode === 2) {
1284
- let data;
1285
- if (this._binaryType === "nodebuffer") {
1286
- data = concat(fragments, messageLength);
1287
- } else if (this._binaryType === "arraybuffer") {
1288
- data = toArrayBuffer(concat(fragments, messageLength));
1289
- } else {
1290
- data = fragments;
1291
- }
1292
- this.emit("message", data, true);
1293
- } else {
1294
- const buf = concat(fragments, messageLength);
1295
- if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
1296
- this._loop = false;
1297
- return error(
1298
- Error,
1299
- "invalid UTF-8 sequence",
1300
- true,
1301
- 1007,
1302
- "WS_ERR_INVALID_UTF8"
1303
- );
1304
- }
1305
- this.emit("message", buf, false);
1306
- }
1307
- }
1308
- this._state = GET_INFO;
1309
- }
1310
- /**
1311
- * Handles a control message.
1312
- *
1313
- * @param {Buffer} data Data to handle
1314
- * @return {(Error|RangeError|undefined)} A possible error
1315
- * @private
1316
- */
1317
- controlMessage(data) {
1318
- if (this._opcode === 8) {
1319
- this._loop = false;
1320
- if (data.length === 0) {
1321
- this.emit("conclude", 1005, EMPTY_BUFFER);
1322
- this.end();
1323
- } else {
1324
- const code = data.readUInt16BE(0);
1325
- if (!isValidStatusCode(code)) {
1326
- return error(
1327
- RangeError,
1328
- `invalid status code ${code}`,
1329
- true,
1330
- 1002,
1331
- "WS_ERR_INVALID_CLOSE_CODE"
1332
- );
1333
- }
1334
- const buf = new FastBuffer(
1335
- data.buffer,
1336
- data.byteOffset + 2,
1337
- data.length - 2
1338
- );
1339
- if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
1340
- return error(
1341
- Error,
1342
- "invalid UTF-8 sequence",
1343
- true,
1344
- 1007,
1345
- "WS_ERR_INVALID_UTF8"
1346
- );
1347
- }
1348
- this.emit("conclude", code, buf);
1349
- this.end();
1350
- }
1351
- } else if (this._opcode === 9) {
1352
- this.emit("ping", data);
1353
- } else {
1354
- this.emit("pong", data);
1355
- }
1356
- this._state = GET_INFO;
1357
- }
1358
- };
1359
- module.exports = Receiver2;
1360
- function error(ErrorCtor, message, prefix, statusCode, errorCode) {
1361
- const err = new ErrorCtor(
1362
- prefix ? `Invalid WebSocket frame: ${message}` : message
1363
- );
1364
- Error.captureStackTrace(err, error);
1365
- err.code = errorCode;
1366
- err[kStatusCode] = statusCode;
1367
- return err;
1368
- }
1369
- }
1370
- });
1371
- var require_sender = __commonJS({
1372
- "../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/sender.js"(exports, module) {
1373
- "use strict";
1374
- init_cjs_shims2();
1375
- var net = __require("net");
1376
- var tls = __require("tls");
1377
- var { randomFillSync } = __require("crypto");
1378
- var PerMessageDeflate = require_permessage_deflate();
1379
- var { EMPTY_BUFFER } = require_constants();
1380
- var { isValidStatusCode } = require_validation();
1381
- var { mask: applyMask, toBuffer } = require_buffer_util();
1382
- var kByteLength = Symbol("kByteLength");
1383
- var maskBuffer = Buffer.alloc(4);
1384
- var Sender2 = class _Sender {
1385
- /**
1386
- * Creates a Sender instance.
1387
- *
1388
- * @param {(net.Socket|tls.Socket)} socket The connection socket
1389
- * @param {Object} [extensions] An object containing the negotiated extensions
1390
- * @param {Function} [generateMask] The function used to generate the masking
1391
- * key
1392
- */
1393
- constructor(socket, extensions, generateMask) {
1394
- this._extensions = extensions || {};
1395
- if (generateMask) {
1396
- this._generateMask = generateMask;
1397
- this._maskBuffer = Buffer.alloc(4);
1398
- }
1399
- this._socket = socket;
1400
- this._firstFragment = true;
1401
- this._compress = false;
1402
- this._bufferedBytes = 0;
1403
- this._deflating = false;
1404
- this._queue = [];
1405
- }
1406
- /**
1407
- * Frames a piece of data according to the HyBi WebSocket protocol.
1408
- *
1409
- * @param {(Buffer|String)} data The data to frame
1410
- * @param {Object} options Options object
1411
- * @param {Boolean} [options.fin=false] Specifies whether or not to set the
1412
- * FIN bit
1413
- * @param {Function} [options.generateMask] The function used to generate the
1414
- * masking key
1415
- * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1416
- * `data`
1417
- * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
1418
- * key
1419
- * @param {Number} options.opcode The opcode
1420
- * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
1421
- * modified
1422
- * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
1423
- * RSV1 bit
1424
- * @return {(Buffer|String)[]} The framed data
1425
- * @public
1426
- */
1427
- static frame(data, options) {
1428
- let mask;
1429
- let merge = false;
1430
- let offset = 2;
1431
- let skipMasking = false;
1432
- if (options.mask) {
1433
- mask = options.maskBuffer || maskBuffer;
1434
- if (options.generateMask) {
1435
- options.generateMask(mask);
1436
- } else {
1437
- randomFillSync(mask, 0, 4);
1438
- }
1439
- skipMasking = (mask[0] | mask[1] | mask[2] | mask[3]) === 0;
1440
- offset = 6;
1441
- }
1442
- let dataLength;
1443
- if (typeof data === "string") {
1444
- if ((!options.mask || skipMasking) && options[kByteLength] !== void 0) {
1445
- dataLength = options[kByteLength];
1446
- } else {
1447
- data = Buffer.from(data);
1448
- dataLength = data.length;
1449
- }
1450
- } else {
1451
- dataLength = data.length;
1452
- merge = options.mask && options.readOnly && !skipMasking;
1453
- }
1454
- let payloadLength = dataLength;
1455
- if (dataLength >= 65536) {
1456
- offset += 8;
1457
- payloadLength = 127;
1458
- } else if (dataLength > 125) {
1459
- offset += 2;
1460
- payloadLength = 126;
1461
- }
1462
- const target = Buffer.allocUnsafe(merge ? dataLength + offset : offset);
1463
- target[0] = options.fin ? options.opcode | 128 : options.opcode;
1464
- if (options.rsv1)
1465
- target[0] |= 64;
1466
- target[1] = payloadLength;
1467
- if (payloadLength === 126) {
1468
- target.writeUInt16BE(dataLength, 2);
1469
- } else if (payloadLength === 127) {
1470
- target[2] = target[3] = 0;
1471
- target.writeUIntBE(dataLength, 4, 6);
1472
- }
1473
- if (!options.mask)
1474
- return [target, data];
1475
- target[1] |= 128;
1476
- target[offset - 4] = mask[0];
1477
- target[offset - 3] = mask[1];
1478
- target[offset - 2] = mask[2];
1479
- target[offset - 1] = mask[3];
1480
- if (skipMasking)
1481
- return [target, data];
1482
- if (merge) {
1483
- applyMask(data, mask, target, offset, dataLength);
1484
- return [target];
1485
- }
1486
- applyMask(data, mask, data, 0, dataLength);
1487
- return [target, data];
1488
- }
1489
- /**
1490
- * Sends a close message to the other peer.
1491
- *
1492
- * @param {Number} [code] The status code component of the body
1493
- * @param {(String|Buffer)} [data] The message component of the body
1494
- * @param {Boolean} [mask=false] Specifies whether or not to mask the message
1495
- * @param {Function} [cb] Callback
1496
- * @public
1497
- */
1498
- close(code, data, mask, cb) {
1499
- let buf;
1500
- if (code === void 0) {
1501
- buf = EMPTY_BUFFER;
1502
- } else if (typeof code !== "number" || !isValidStatusCode(code)) {
1503
- throw new TypeError("First argument must be a valid error code number");
1504
- } else if (data === void 0 || !data.length) {
1505
- buf = Buffer.allocUnsafe(2);
1506
- buf.writeUInt16BE(code, 0);
1507
- } else {
1508
- const length = Buffer.byteLength(data);
1509
- if (length > 123) {
1510
- throw new RangeError("The message must not be greater than 123 bytes");
1511
- }
1512
- buf = Buffer.allocUnsafe(2 + length);
1513
- buf.writeUInt16BE(code, 0);
1514
- if (typeof data === "string") {
1515
- buf.write(data, 2);
1516
- } else {
1517
- buf.set(data, 2);
1518
- }
1519
- }
1520
- const options = {
1521
- [kByteLength]: buf.length,
1522
- fin: true,
1523
- generateMask: this._generateMask,
1524
- mask,
1525
- maskBuffer: this._maskBuffer,
1526
- opcode: 8,
1527
- readOnly: false,
1528
- rsv1: false
1529
- };
1530
- if (this._deflating) {
1531
- this.enqueue([this.dispatch, buf, false, options, cb]);
1532
- } else {
1533
- this.sendFrame(_Sender.frame(buf, options), cb);
1534
- }
1535
- }
1536
- /**
1537
- * Sends a ping message to the other peer.
1538
- *
1539
- * @param {*} data The message to send
1540
- * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
1541
- * @param {Function} [cb] Callback
1542
- * @public
1543
- */
1544
- ping(data, mask, cb) {
1545
- let byteLength;
1546
- let readOnly;
1547
- if (typeof data === "string") {
1548
- byteLength = Buffer.byteLength(data);
1549
- readOnly = false;
1550
- } else {
1551
- data = toBuffer(data);
1552
- byteLength = data.length;
1553
- readOnly = toBuffer.readOnly;
1554
- }
1555
- if (byteLength > 125) {
1556
- throw new RangeError("The data size must not be greater than 125 bytes");
1557
- }
1558
- const options = {
1559
- [kByteLength]: byteLength,
1560
- fin: true,
1561
- generateMask: this._generateMask,
1562
- mask,
1563
- maskBuffer: this._maskBuffer,
1564
- opcode: 9,
1565
- readOnly,
1566
- rsv1: false
1567
- };
1568
- if (this._deflating) {
1569
- this.enqueue([this.dispatch, data, false, options, cb]);
1570
- } else {
1571
- this.sendFrame(_Sender.frame(data, options), cb);
1572
- }
1573
- }
1574
- /**
1575
- * Sends a pong message to the other peer.
1576
- *
1577
- * @param {*} data The message to send
1578
- * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
1579
- * @param {Function} [cb] Callback
1580
- * @public
1581
- */
1582
- pong(data, mask, cb) {
1583
- let byteLength;
1584
- let readOnly;
1585
- if (typeof data === "string") {
1586
- byteLength = Buffer.byteLength(data);
1587
- readOnly = false;
1588
- } else {
1589
- data = toBuffer(data);
1590
- byteLength = data.length;
1591
- readOnly = toBuffer.readOnly;
1592
- }
1593
- if (byteLength > 125) {
1594
- throw new RangeError("The data size must not be greater than 125 bytes");
1595
- }
1596
- const options = {
1597
- [kByteLength]: byteLength,
1598
- fin: true,
1599
- generateMask: this._generateMask,
1600
- mask,
1601
- maskBuffer: this._maskBuffer,
1602
- opcode: 10,
1603
- readOnly,
1604
- rsv1: false
1605
- };
1606
- if (this._deflating) {
1607
- this.enqueue([this.dispatch, data, false, options, cb]);
1608
- } else {
1609
- this.sendFrame(_Sender.frame(data, options), cb);
1610
- }
1611
- }
1612
- /**
1613
- * Sends a data message to the other peer.
1614
- *
1615
- * @param {*} data The message to send
1616
- * @param {Object} options Options object
1617
- * @param {Boolean} [options.binary=false] Specifies whether `data` is binary
1618
- * or text
1619
- * @param {Boolean} [options.compress=false] Specifies whether or not to
1620
- * compress `data`
1621
- * @param {Boolean} [options.fin=false] Specifies whether the fragment is the
1622
- * last one
1623
- * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1624
- * `data`
1625
- * @param {Function} [cb] Callback
1626
- * @public
1627
- */
1628
- send(data, options, cb) {
1629
- const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
1630
- let opcode = options.binary ? 2 : 1;
1631
- let rsv1 = options.compress;
1632
- let byteLength;
1633
- let readOnly;
1634
- if (typeof data === "string") {
1635
- byteLength = Buffer.byteLength(data);
1636
- readOnly = false;
1637
- } else {
1638
- data = toBuffer(data);
1639
- byteLength = data.length;
1640
- readOnly = toBuffer.readOnly;
1641
- }
1642
- if (this._firstFragment) {
1643
- this._firstFragment = false;
1644
- if (rsv1 && perMessageDeflate && perMessageDeflate.params[perMessageDeflate._isServer ? "server_no_context_takeover" : "client_no_context_takeover"]) {
1645
- rsv1 = byteLength >= perMessageDeflate._threshold;
1646
- }
1647
- this._compress = rsv1;
1648
- } else {
1649
- rsv1 = false;
1650
- opcode = 0;
1651
- }
1652
- if (options.fin)
1653
- this._firstFragment = true;
1654
- if (perMessageDeflate) {
1655
- const opts = {
1656
- [kByteLength]: byteLength,
1657
- fin: options.fin,
1658
- generateMask: this._generateMask,
1659
- mask: options.mask,
1660
- maskBuffer: this._maskBuffer,
1661
- opcode,
1662
- readOnly,
1663
- rsv1
1664
- };
1665
- if (this._deflating) {
1666
- this.enqueue([this.dispatch, data, this._compress, opts, cb]);
1667
- } else {
1668
- this.dispatch(data, this._compress, opts, cb);
1669
- }
1670
- } else {
1671
- this.sendFrame(
1672
- _Sender.frame(data, {
1673
- [kByteLength]: byteLength,
1674
- fin: options.fin,
1675
- generateMask: this._generateMask,
1676
- mask: options.mask,
1677
- maskBuffer: this._maskBuffer,
1678
- opcode,
1679
- readOnly,
1680
- rsv1: false
1681
- }),
1682
- cb
1683
- );
1684
- }
1685
- }
1686
- /**
1687
- * Dispatches a message.
1688
- *
1689
- * @param {(Buffer|String)} data The message to send
1690
- * @param {Boolean} [compress=false] Specifies whether or not to compress
1691
- * `data`
1692
- * @param {Object} options Options object
1693
- * @param {Boolean} [options.fin=false] Specifies whether or not to set the
1694
- * FIN bit
1695
- * @param {Function} [options.generateMask] The function used to generate the
1696
- * masking key
1697
- * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1698
- * `data`
1699
- * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
1700
- * key
1701
- * @param {Number} options.opcode The opcode
1702
- * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
1703
- * modified
1704
- * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
1705
- * RSV1 bit
1706
- * @param {Function} [cb] Callback
1707
- * @private
1708
- */
1709
- dispatch(data, compress, options, cb) {
1710
- if (!compress) {
1711
- this.sendFrame(_Sender.frame(data, options), cb);
1712
- return;
1713
- }
1714
- const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
1715
- this._bufferedBytes += options[kByteLength];
1716
- this._deflating = true;
1717
- perMessageDeflate.compress(data, options.fin, (_, buf) => {
1718
- if (this._socket.destroyed) {
1719
- const err = new Error(
1720
- "The socket was closed while data was being compressed"
1721
- );
1722
- if (typeof cb === "function")
1723
- cb(err);
1724
- for (let i = 0; i < this._queue.length; i++) {
1725
- const params = this._queue[i];
1726
- const callback = params[params.length - 1];
1727
- if (typeof callback === "function")
1728
- callback(err);
1729
- }
1730
- return;
1731
- }
1732
- this._bufferedBytes -= options[kByteLength];
1733
- this._deflating = false;
1734
- options.readOnly = false;
1735
- this.sendFrame(_Sender.frame(buf, options), cb);
1736
- this.dequeue();
1737
- });
1738
- }
1739
- /**
1740
- * Executes queued send operations.
1741
- *
1742
- * @private
1743
- */
1744
- dequeue() {
1745
- while (!this._deflating && this._queue.length) {
1746
- const params = this._queue.shift();
1747
- this._bufferedBytes -= params[3][kByteLength];
1748
- Reflect.apply(params[0], this, params.slice(1));
1749
- }
1750
- }
1751
- /**
1752
- * Enqueues a send operation.
1753
- *
1754
- * @param {Array} params Send operation parameters.
1755
- * @private
1756
- */
1757
- enqueue(params) {
1758
- this._bufferedBytes += params[3][kByteLength];
1759
- this._queue.push(params);
1760
- }
1761
- /**
1762
- * Sends a frame.
1763
- *
1764
- * @param {Buffer[]} list The frame to send
1765
- * @param {Function} [cb] Callback
1766
- * @private
1767
- */
1768
- sendFrame(list, cb) {
1769
- if (list.length === 2) {
1770
- this._socket.cork();
1771
- this._socket.write(list[0]);
1772
- this._socket.write(list[1], cb);
1773
- this._socket.uncork();
1774
- } else {
1775
- this._socket.write(list[0], cb);
1776
- }
1777
- }
1778
- };
1779
- module.exports = Sender2;
1780
- }
1781
- });
1782
- var require_event_target = __commonJS({
1783
- "../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/event-target.js"(exports, module) {
1784
- "use strict";
1785
- init_cjs_shims2();
1786
- var { kForOnEventAttribute, kListener } = require_constants();
1787
- var kCode = Symbol("kCode");
1788
- var kData = Symbol("kData");
1789
- var kError = Symbol("kError");
1790
- var kMessage = Symbol("kMessage");
1791
- var kReason = Symbol("kReason");
1792
- var kTarget = Symbol("kTarget");
1793
- var kType = Symbol("kType");
1794
- var kWasClean = Symbol("kWasClean");
1795
- var Event = class {
1796
- /**
1797
- * Create a new `Event`.
1798
- *
1799
- * @param {String} type The name of the event
1800
- * @throws {TypeError} If the `type` argument is not specified
1801
- */
1802
- constructor(type) {
1803
- this[kTarget] = null;
1804
- this[kType] = type;
1805
- }
1806
- /**
1807
- * @type {*}
1808
- */
1809
- get target() {
1810
- return this[kTarget];
1811
- }
1812
- /**
1813
- * @type {String}
1814
- */
1815
- get type() {
1816
- return this[kType];
1817
- }
1818
- };
1819
- Object.defineProperty(Event.prototype, "target", { enumerable: true });
1820
- Object.defineProperty(Event.prototype, "type", { enumerable: true });
1821
- var CloseEvent = class extends Event {
1822
- /**
1823
- * Create a new `CloseEvent`.
1824
- *
1825
- * @param {String} type The name of the event
1826
- * @param {Object} [options] A dictionary object that allows for setting
1827
- * attributes via object members of the same name
1828
- * @param {Number} [options.code=0] The status code explaining why the
1829
- * connection was closed
1830
- * @param {String} [options.reason=''] A human-readable string explaining why
1831
- * the connection was closed
1832
- * @param {Boolean} [options.wasClean=false] Indicates whether or not the
1833
- * connection was cleanly closed
1834
- */
1835
- constructor(type, options = {}) {
1836
- super(type);
1837
- this[kCode] = options.code === void 0 ? 0 : options.code;
1838
- this[kReason] = options.reason === void 0 ? "" : options.reason;
1839
- this[kWasClean] = options.wasClean === void 0 ? false : options.wasClean;
1840
- }
1841
- /**
1842
- * @type {Number}
1843
- */
1844
- get code() {
1845
- return this[kCode];
1846
- }
1847
- /**
1848
- * @type {String}
1849
- */
1850
- get reason() {
1851
- return this[kReason];
1852
- }
1853
- /**
1854
- * @type {Boolean}
1855
- */
1856
- get wasClean() {
1857
- return this[kWasClean];
1858
- }
1859
- };
1860
- Object.defineProperty(CloseEvent.prototype, "code", { enumerable: true });
1861
- Object.defineProperty(CloseEvent.prototype, "reason", { enumerable: true });
1862
- Object.defineProperty(CloseEvent.prototype, "wasClean", { enumerable: true });
1863
- var ErrorEvent = class extends Event {
1864
- /**
1865
- * Create a new `ErrorEvent`.
1866
- *
1867
- * @param {String} type The name of the event
1868
- * @param {Object} [options] A dictionary object that allows for setting
1869
- * attributes via object members of the same name
1870
- * @param {*} [options.error=null] The error that generated this event
1871
- * @param {String} [options.message=''] The error message
1872
- */
1873
- constructor(type, options = {}) {
1874
- super(type);
1875
- this[kError] = options.error === void 0 ? null : options.error;
1876
- this[kMessage] = options.message === void 0 ? "" : options.message;
1877
- }
1878
- /**
1879
- * @type {*}
1880
- */
1881
- get error() {
1882
- return this[kError];
1883
- }
1884
- /**
1885
- * @type {String}
1886
- */
1887
- get message() {
1888
- return this[kMessage];
1889
- }
1890
- };
1891
- Object.defineProperty(ErrorEvent.prototype, "error", { enumerable: true });
1892
- Object.defineProperty(ErrorEvent.prototype, "message", { enumerable: true });
1893
- var MessageEvent = class extends Event {
1894
- /**
1895
- * Create a new `MessageEvent`.
1896
- *
1897
- * @param {String} type The name of the event
1898
- * @param {Object} [options] A dictionary object that allows for setting
1899
- * attributes via object members of the same name
1900
- * @param {*} [options.data=null] The message content
1901
- */
1902
- constructor(type, options = {}) {
1903
- super(type);
1904
- this[kData] = options.data === void 0 ? null : options.data;
1905
- }
1906
- /**
1907
- * @type {*}
1908
- */
1909
- get data() {
1910
- return this[kData];
1911
- }
1912
- };
1913
- Object.defineProperty(MessageEvent.prototype, "data", { enumerable: true });
1914
- var EventTarget = {
1915
- /**
1916
- * Register an event listener.
1917
- *
1918
- * @param {String} type A string representing the event type to listen for
1919
- * @param {(Function|Object)} handler The listener to add
1920
- * @param {Object} [options] An options object specifies characteristics about
1921
- * the event listener
1922
- * @param {Boolean} [options.once=false] A `Boolean` indicating that the
1923
- * listener should be invoked at most once after being added. If `true`,
1924
- * the listener would be automatically removed when invoked.
1925
- * @public
1926
- */
1927
- addEventListener(type, handler, options = {}) {
1928
- for (const listener of this.listeners(type)) {
1929
- if (!options[kForOnEventAttribute] && listener[kListener] === handler && !listener[kForOnEventAttribute]) {
1930
- return;
1931
- }
1932
- }
1933
- let wrapper;
1934
- if (type === "message") {
1935
- wrapper = function onMessage(data, isBinary) {
1936
- const event = new MessageEvent("message", {
1937
- data: isBinary ? data : data.toString()
1938
- });
1939
- event[kTarget] = this;
1940
- callListener(handler, this, event);
1941
- };
1942
- } else if (type === "close") {
1943
- wrapper = function onClose(code, message) {
1944
- const event = new CloseEvent("close", {
1945
- code,
1946
- reason: message.toString(),
1947
- wasClean: this._closeFrameReceived && this._closeFrameSent
1948
- });
1949
- event[kTarget] = this;
1950
- callListener(handler, this, event);
1951
- };
1952
- } else if (type === "error") {
1953
- wrapper = function onError(error) {
1954
- const event = new ErrorEvent("error", {
1955
- error,
1956
- message: error.message
1957
- });
1958
- event[kTarget] = this;
1959
- callListener(handler, this, event);
1960
- };
1961
- } else if (type === "open") {
1962
- wrapper = function onOpen() {
1963
- const event = new Event("open");
1964
- event[kTarget] = this;
1965
- callListener(handler, this, event);
1966
- };
1967
- } else {
1968
- return;
1969
- }
1970
- wrapper[kForOnEventAttribute] = !!options[kForOnEventAttribute];
1971
- wrapper[kListener] = handler;
1972
- if (options.once) {
1973
- this.once(type, wrapper);
1974
- } else {
1975
- this.on(type, wrapper);
1976
- }
1977
- },
1978
- /**
1979
- * Remove an event listener.
1980
- *
1981
- * @param {String} type A string representing the event type to remove
1982
- * @param {(Function|Object)} handler The listener to remove
1983
- * @public
1984
- */
1985
- removeEventListener(type, handler) {
1986
- for (const listener of this.listeners(type)) {
1987
- if (listener[kListener] === handler && !listener[kForOnEventAttribute]) {
1988
- this.removeListener(type, listener);
1989
- break;
1990
- }
1991
- }
1992
- }
1993
- };
1994
- module.exports = {
1995
- CloseEvent,
1996
- ErrorEvent,
1997
- Event,
1998
- EventTarget,
1999
- MessageEvent
2000
- };
2001
- function callListener(listener, thisArg, event) {
2002
- if (typeof listener === "object" && listener.handleEvent) {
2003
- listener.handleEvent.call(listener, event);
2004
- } else {
2005
- listener.call(thisArg, event);
2006
- }
2007
- }
2008
- }
2009
- });
2010
- var require_extension = __commonJS({
2011
- "../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/extension.js"(exports, module) {
2012
- "use strict";
2013
- init_cjs_shims2();
2014
- var { tokenChars } = require_validation();
2015
- function push(dest, name, elem) {
2016
- if (dest[name] === void 0)
2017
- dest[name] = [elem];
2018
- else
2019
- dest[name].push(elem);
2020
- }
2021
- function parse(header) {
2022
- const offers = /* @__PURE__ */ Object.create(null);
2023
- let params = /* @__PURE__ */ Object.create(null);
2024
- let mustUnescape = false;
2025
- let isEscaping = false;
2026
- let inQuotes = false;
2027
- let extensionName;
2028
- let paramName;
2029
- let start = -1;
2030
- let code = -1;
2031
- let end = -1;
2032
- let i = 0;
2033
- for (; i < header.length; i++) {
2034
- code = header.charCodeAt(i);
2035
- if (extensionName === void 0) {
2036
- if (end === -1 && tokenChars[code] === 1) {
2037
- if (start === -1)
2038
- start = i;
2039
- } else if (i !== 0 && (code === 32 || code === 9)) {
2040
- if (end === -1 && start !== -1)
2041
- end = i;
2042
- } else if (code === 59 || code === 44) {
2043
- if (start === -1) {
2044
- throw new SyntaxError(`Unexpected character at index ${i}`);
2045
- }
2046
- if (end === -1)
2047
- end = i;
2048
- const name = header.slice(start, end);
2049
- if (code === 44) {
2050
- push(offers, name, params);
2051
- params = /* @__PURE__ */ Object.create(null);
2052
- } else {
2053
- extensionName = name;
2054
- }
2055
- start = end = -1;
2056
- } else {
2057
- throw new SyntaxError(`Unexpected character at index ${i}`);
2058
- }
2059
- } else if (paramName === void 0) {
2060
- if (end === -1 && tokenChars[code] === 1) {
2061
- if (start === -1)
2062
- start = i;
2063
- } else if (code === 32 || code === 9) {
2064
- if (end === -1 && start !== -1)
2065
- end = i;
2066
- } else if (code === 59 || code === 44) {
2067
- if (start === -1) {
2068
- throw new SyntaxError(`Unexpected character at index ${i}`);
2069
- }
2070
- if (end === -1)
2071
- end = i;
2072
- push(params, header.slice(start, end), true);
2073
- if (code === 44) {
2074
- push(offers, extensionName, params);
2075
- params = /* @__PURE__ */ Object.create(null);
2076
- extensionName = void 0;
2077
- }
2078
- start = end = -1;
2079
- } else if (code === 61 && start !== -1 && end === -1) {
2080
- paramName = header.slice(start, i);
2081
- start = end = -1;
2082
- } else {
2083
- throw new SyntaxError(`Unexpected character at index ${i}`);
2084
- }
2085
- } else {
2086
- if (isEscaping) {
2087
- if (tokenChars[code] !== 1) {
2088
- throw new SyntaxError(`Unexpected character at index ${i}`);
2089
- }
2090
- if (start === -1)
2091
- start = i;
2092
- else if (!mustUnescape)
2093
- mustUnescape = true;
2094
- isEscaping = false;
2095
- } else if (inQuotes) {
2096
- if (tokenChars[code] === 1) {
2097
- if (start === -1)
2098
- start = i;
2099
- } else if (code === 34 && start !== -1) {
2100
- inQuotes = false;
2101
- end = i;
2102
- } else if (code === 92) {
2103
- isEscaping = true;
2104
- } else {
2105
- throw new SyntaxError(`Unexpected character at index ${i}`);
2106
- }
2107
- } else if (code === 34 && header.charCodeAt(i - 1) === 61) {
2108
- inQuotes = true;
2109
- } else if (end === -1 && tokenChars[code] === 1) {
2110
- if (start === -1)
2111
- start = i;
2112
- } else if (start !== -1 && (code === 32 || code === 9)) {
2113
- if (end === -1)
2114
- end = i;
2115
- } else if (code === 59 || code === 44) {
2116
- if (start === -1) {
2117
- throw new SyntaxError(`Unexpected character at index ${i}`);
2118
- }
2119
- if (end === -1)
2120
- end = i;
2121
- let value = header.slice(start, end);
2122
- if (mustUnescape) {
2123
- value = value.replace(/\\/g, "");
2124
- mustUnescape = false;
2125
- }
2126
- push(params, paramName, value);
2127
- if (code === 44) {
2128
- push(offers, extensionName, params);
2129
- params = /* @__PURE__ */ Object.create(null);
2130
- extensionName = void 0;
2131
- }
2132
- paramName = void 0;
2133
- start = end = -1;
2134
- } else {
2135
- throw new SyntaxError(`Unexpected character at index ${i}`);
2136
- }
2137
- }
2138
- }
2139
- if (start === -1 || inQuotes || code === 32 || code === 9) {
2140
- throw new SyntaxError("Unexpected end of input");
2141
- }
2142
- if (end === -1)
2143
- end = i;
2144
- const token = header.slice(start, end);
2145
- if (extensionName === void 0) {
2146
- push(offers, token, params);
2147
- } else {
2148
- if (paramName === void 0) {
2149
- push(params, token, true);
2150
- } else if (mustUnescape) {
2151
- push(params, paramName, token.replace(/\\/g, ""));
2152
- } else {
2153
- push(params, paramName, token);
2154
- }
2155
- push(offers, extensionName, params);
2156
- }
2157
- return offers;
2158
- }
2159
- function format(extensions) {
2160
- return Object.keys(extensions).map((extension) => {
2161
- let configurations = extensions[extension];
2162
- if (!Array.isArray(configurations))
2163
- configurations = [configurations];
2164
- return configurations.map((params) => {
2165
- return [extension].concat(
2166
- Object.keys(params).map((k) => {
2167
- let values = params[k];
2168
- if (!Array.isArray(values))
2169
- values = [values];
2170
- return values.map((v) => v === true ? k : `${k}=${v}`).join("; ");
2171
- })
2172
- ).join("; ");
2173
- }).join(", ");
2174
- }).join(", ");
2175
- }
2176
- module.exports = { format, parse };
2177
- }
2178
- });
2179
- var require_websocket = __commonJS({
2180
- "../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/websocket.js"(exports, module) {
2181
- "use strict";
2182
- init_cjs_shims2();
2183
- var EventEmitter = __require("events");
2184
- var https = __require("https");
2185
- var http = __require("http");
2186
- var net = __require("net");
2187
- var tls = __require("tls");
2188
- var { randomBytes, createHash } = __require("crypto");
2189
- var { Readable } = __require("stream");
2190
- var { URL } = __require("url");
2191
- var PerMessageDeflate = require_permessage_deflate();
2192
- var Receiver2 = require_receiver();
2193
- var Sender2 = require_sender();
2194
- var {
2195
- BINARY_TYPES,
2196
- EMPTY_BUFFER,
2197
- GUID,
2198
- kForOnEventAttribute,
2199
- kListener,
2200
- kStatusCode,
2201
- kWebSocket,
2202
- NOOP
2203
- } = require_constants();
2204
- var {
2205
- EventTarget: { addEventListener, removeEventListener }
2206
- } = require_event_target();
2207
- var { format, parse } = require_extension();
2208
- var { toBuffer } = require_buffer_util();
2209
- var closeTimeout = 30 * 1e3;
2210
- var kAborted = Symbol("kAborted");
2211
- var protocolVersions = [8, 13];
2212
- var readyStates = ["CONNECTING", "OPEN", "CLOSING", "CLOSED"];
2213
- var subprotocolRegex = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
2214
- var WebSocket2 = class _WebSocket extends EventEmitter {
2215
- /**
2216
- * Create a new `WebSocket`.
2217
- *
2218
- * @param {(String|URL)} address The URL to which to connect
2219
- * @param {(String|String[])} [protocols] The subprotocols
2220
- * @param {Object} [options] Connection options
2221
- */
2222
- constructor(address, protocols, options) {
2223
- super();
2224
- this._binaryType = BINARY_TYPES[0];
2225
- this._closeCode = 1006;
2226
- this._closeFrameReceived = false;
2227
- this._closeFrameSent = false;
2228
- this._closeMessage = EMPTY_BUFFER;
2229
- this._closeTimer = null;
2230
- this._extensions = {};
2231
- this._paused = false;
2232
- this._protocol = "";
2233
- this._readyState = _WebSocket.CONNECTING;
2234
- this._receiver = null;
2235
- this._sender = null;
2236
- this._socket = null;
2237
- if (address !== null) {
2238
- this._bufferedAmount = 0;
2239
- this._isServer = false;
2240
- this._redirects = 0;
2241
- if (protocols === void 0) {
2242
- protocols = [];
2243
- } else if (!Array.isArray(protocols)) {
2244
- if (typeof protocols === "object" && protocols !== null) {
2245
- options = protocols;
2246
- protocols = [];
2247
- } else {
2248
- protocols = [protocols];
2249
- }
2250
- }
2251
- initAsClient(this, address, protocols, options);
2252
- } else {
2253
- this._isServer = true;
2254
- }
2255
- }
2256
- /**
2257
- * This deviates from the WHATWG interface since ws doesn't support the
2258
- * required default "blob" type (instead we define a custom "nodebuffer"
2259
- * type).
2260
- *
2261
- * @type {String}
2262
- */
2263
- get binaryType() {
2264
- return this._binaryType;
2265
- }
2266
- set binaryType(type) {
2267
- if (!BINARY_TYPES.includes(type))
2268
- return;
2269
- this._binaryType = type;
2270
- if (this._receiver)
2271
- this._receiver._binaryType = type;
2272
- }
2273
- /**
2274
- * @type {Number}
2275
- */
2276
- get bufferedAmount() {
2277
- if (!this._socket)
2278
- return this._bufferedAmount;
2279
- return this._socket._writableState.length + this._sender._bufferedBytes;
2280
- }
2281
- /**
2282
- * @type {String}
2283
- */
2284
- get extensions() {
2285
- return Object.keys(this._extensions).join();
2286
- }
2287
- /**
2288
- * @type {Boolean}
2289
- */
2290
- get isPaused() {
2291
- return this._paused;
2292
- }
2293
- /**
2294
- * @type {Function}
2295
- */
2296
- /* istanbul ignore next */
2297
- get onclose() {
2298
- return null;
2299
- }
2300
- /**
2301
- * @type {Function}
2302
- */
2303
- /* istanbul ignore next */
2304
- get onerror() {
2305
- return null;
2306
- }
2307
- /**
2308
- * @type {Function}
2309
- */
2310
- /* istanbul ignore next */
2311
- get onopen() {
2312
- return null;
2313
- }
2314
- /**
2315
- * @type {Function}
2316
- */
2317
- /* istanbul ignore next */
2318
- get onmessage() {
2319
- return null;
2320
- }
2321
- /**
2322
- * @type {String}
2323
- */
2324
- get protocol() {
2325
- return this._protocol;
2326
- }
2327
- /**
2328
- * @type {Number}
2329
- */
2330
- get readyState() {
2331
- return this._readyState;
2332
- }
2333
- /**
2334
- * @type {String}
2335
- */
2336
- get url() {
2337
- return this._url;
2338
- }
2339
- /**
2340
- * Set up the socket and the internal resources.
2341
- *
2342
- * @param {(net.Socket|tls.Socket)} socket The network socket between the
2343
- * server and client
2344
- * @param {Buffer} head The first packet of the upgraded stream
2345
- * @param {Object} options Options object
2346
- * @param {Function} [options.generateMask] The function used to generate the
2347
- * masking key
2348
- * @param {Number} [options.maxPayload=0] The maximum allowed message size
2349
- * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
2350
- * not to skip UTF-8 validation for text and close messages
2351
- * @private
2352
- */
2353
- setSocket(socket, head, options) {
2354
- const receiver = new Receiver2({
2355
- binaryType: this.binaryType,
2356
- extensions: this._extensions,
2357
- isServer: this._isServer,
2358
- maxPayload: options.maxPayload,
2359
- skipUTF8Validation: options.skipUTF8Validation
2360
- });
2361
- this._sender = new Sender2(socket, this._extensions, options.generateMask);
2362
- this._receiver = receiver;
2363
- this._socket = socket;
2364
- receiver[kWebSocket] = this;
2365
- socket[kWebSocket] = this;
2366
- receiver.on("conclude", receiverOnConclude);
2367
- receiver.on("drain", receiverOnDrain);
2368
- receiver.on("error", receiverOnError);
2369
- receiver.on("message", receiverOnMessage);
2370
- receiver.on("ping", receiverOnPing);
2371
- receiver.on("pong", receiverOnPong);
2372
- socket.setTimeout(0);
2373
- socket.setNoDelay();
2374
- if (head.length > 0)
2375
- socket.unshift(head);
2376
- socket.on("close", socketOnClose);
2377
- socket.on("data", socketOnData);
2378
- socket.on("end", socketOnEnd);
2379
- socket.on("error", socketOnError);
2380
- this._readyState = _WebSocket.OPEN;
2381
- this.emit("open");
2382
- }
2383
- /**
2384
- * Emit the `'close'` event.
2385
- *
2386
- * @private
2387
- */
2388
- emitClose() {
2389
- if (!this._socket) {
2390
- this._readyState = _WebSocket.CLOSED;
2391
- this.emit("close", this._closeCode, this._closeMessage);
2392
- return;
2393
- }
2394
- if (this._extensions[PerMessageDeflate.extensionName]) {
2395
- this._extensions[PerMessageDeflate.extensionName].cleanup();
2396
- }
2397
- this._receiver.removeAllListeners();
2398
- this._readyState = _WebSocket.CLOSED;
2399
- this.emit("close", this._closeCode, this._closeMessage);
2400
- }
2401
- /**
2402
- * Start a closing handshake.
2403
- *
2404
- * +----------+ +-----------+ +----------+
2405
- * - - -|ws.close()|-->|close frame|-->|ws.close()|- - -
2406
- * | +----------+ +-----------+ +----------+ |
2407
- * +----------+ +-----------+ |
2408
- * CLOSING |ws.close()|<--|close frame|<--+-----+ CLOSING
2409
- * +----------+ +-----------+ |
2410
- * | | | +---+ |
2411
- * +------------------------+-->|fin| - - - -
2412
- * | +---+ | +---+
2413
- * - - - - -|fin|<---------------------+
2414
- * +---+
2415
- *
2416
- * @param {Number} [code] Status code explaining why the connection is closing
2417
- * @param {(String|Buffer)} [data] The reason why the connection is
2418
- * closing
2419
- * @public
2420
- */
2421
- close(code, data) {
2422
- if (this.readyState === _WebSocket.CLOSED)
2423
- return;
2424
- if (this.readyState === _WebSocket.CONNECTING) {
2425
- const msg = "WebSocket was closed before the connection was established";
2426
- abortHandshake(this, this._req, msg);
2427
- return;
2428
- }
2429
- if (this.readyState === _WebSocket.CLOSING) {
2430
- if (this._closeFrameSent && (this._closeFrameReceived || this._receiver._writableState.errorEmitted)) {
2431
- this._socket.end();
2432
- }
2433
- return;
2434
- }
2435
- this._readyState = _WebSocket.CLOSING;
2436
- this._sender.close(code, data, !this._isServer, (err) => {
2437
- if (err)
2438
- return;
2439
- this._closeFrameSent = true;
2440
- if (this._closeFrameReceived || this._receiver._writableState.errorEmitted) {
2441
- this._socket.end();
2442
- }
2443
- });
2444
- this._closeTimer = setTimeout(
2445
- this._socket.destroy.bind(this._socket),
2446
- closeTimeout
2447
- );
2448
- }
2449
- /**
2450
- * Pause the socket.
2451
- *
2452
- * @public
2453
- */
2454
- pause() {
2455
- if (this.readyState === _WebSocket.CONNECTING || this.readyState === _WebSocket.CLOSED) {
2456
- return;
2457
- }
2458
- this._paused = true;
2459
- this._socket.pause();
2460
- }
2461
- /**
2462
- * Send a ping.
2463
- *
2464
- * @param {*} [data] The data to send
2465
- * @param {Boolean} [mask] Indicates whether or not to mask `data`
2466
- * @param {Function} [cb] Callback which is executed when the ping is sent
2467
- * @public
2468
- */
2469
- ping(data, mask, cb) {
2470
- if (this.readyState === _WebSocket.CONNECTING) {
2471
- throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
2472
- }
2473
- if (typeof data === "function") {
2474
- cb = data;
2475
- data = mask = void 0;
2476
- } else if (typeof mask === "function") {
2477
- cb = mask;
2478
- mask = void 0;
2479
- }
2480
- if (typeof data === "number")
2481
- data = data.toString();
2482
- if (this.readyState !== _WebSocket.OPEN) {
2483
- sendAfterClose(this, data, cb);
2484
- return;
2485
- }
2486
- if (mask === void 0)
2487
- mask = !this._isServer;
2488
- this._sender.ping(data || EMPTY_BUFFER, mask, cb);
2489
- }
2490
- /**
2491
- * Send a pong.
2492
- *
2493
- * @param {*} [data] The data to send
2494
- * @param {Boolean} [mask] Indicates whether or not to mask `data`
2495
- * @param {Function} [cb] Callback which is executed when the pong is sent
2496
- * @public
2497
- */
2498
- pong(data, mask, cb) {
2499
- if (this.readyState === _WebSocket.CONNECTING) {
2500
- throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
2501
- }
2502
- if (typeof data === "function") {
2503
- cb = data;
2504
- data = mask = void 0;
2505
- } else if (typeof mask === "function") {
2506
- cb = mask;
2507
- mask = void 0;
2508
- }
2509
- if (typeof data === "number")
2510
- data = data.toString();
2511
- if (this.readyState !== _WebSocket.OPEN) {
2512
- sendAfterClose(this, data, cb);
2513
- return;
2514
- }
2515
- if (mask === void 0)
2516
- mask = !this._isServer;
2517
- this._sender.pong(data || EMPTY_BUFFER, mask, cb);
2518
- }
2519
- /**
2520
- * Resume the socket.
2521
- *
2522
- * @public
2523
- */
2524
- resume() {
2525
- if (this.readyState === _WebSocket.CONNECTING || this.readyState === _WebSocket.CLOSED) {
2526
- return;
2527
- }
2528
- this._paused = false;
2529
- if (!this._receiver._writableState.needDrain)
2530
- this._socket.resume();
2531
- }
2532
- /**
2533
- * Send a data message.
2534
- *
2535
- * @param {*} data The message to send
2536
- * @param {Object} [options] Options object
2537
- * @param {Boolean} [options.binary] Specifies whether `data` is binary or
2538
- * text
2539
- * @param {Boolean} [options.compress] Specifies whether or not to compress
2540
- * `data`
2541
- * @param {Boolean} [options.fin=true] Specifies whether the fragment is the
2542
- * last one
2543
- * @param {Boolean} [options.mask] Specifies whether or not to mask `data`
2544
- * @param {Function} [cb] Callback which is executed when data is written out
2545
- * @public
2546
- */
2547
- send(data, options, cb) {
2548
- if (this.readyState === _WebSocket.CONNECTING) {
2549
- throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
2550
- }
2551
- if (typeof options === "function") {
2552
- cb = options;
2553
- options = {};
2554
- }
2555
- if (typeof data === "number")
2556
- data = data.toString();
2557
- if (this.readyState !== _WebSocket.OPEN) {
2558
- sendAfterClose(this, data, cb);
2559
- return;
2560
- }
2561
- const opts = {
2562
- binary: typeof data !== "string",
2563
- mask: !this._isServer,
2564
- compress: true,
2565
- fin: true,
2566
- ...options
2567
- };
2568
- if (!this._extensions[PerMessageDeflate.extensionName]) {
2569
- opts.compress = false;
2570
- }
2571
- this._sender.send(data || EMPTY_BUFFER, opts, cb);
2572
- }
2573
- /**
2574
- * Forcibly close the connection.
2575
- *
2576
- * @public
2577
- */
2578
- terminate() {
2579
- if (this.readyState === _WebSocket.CLOSED)
2580
- return;
2581
- if (this.readyState === _WebSocket.CONNECTING) {
2582
- const msg = "WebSocket was closed before the connection was established";
2583
- abortHandshake(this, this._req, msg);
2584
- return;
2585
- }
2586
- if (this._socket) {
2587
- this._readyState = _WebSocket.CLOSING;
2588
- this._socket.destroy();
2589
- }
2590
- }
2591
- };
2592
- Object.defineProperty(WebSocket2, "CONNECTING", {
2593
- enumerable: true,
2594
- value: readyStates.indexOf("CONNECTING")
2595
- });
2596
- Object.defineProperty(WebSocket2.prototype, "CONNECTING", {
2597
- enumerable: true,
2598
- value: readyStates.indexOf("CONNECTING")
2599
- });
2600
- Object.defineProperty(WebSocket2, "OPEN", {
2601
- enumerable: true,
2602
- value: readyStates.indexOf("OPEN")
2603
- });
2604
- Object.defineProperty(WebSocket2.prototype, "OPEN", {
2605
- enumerable: true,
2606
- value: readyStates.indexOf("OPEN")
2607
- });
2608
- Object.defineProperty(WebSocket2, "CLOSING", {
2609
- enumerable: true,
2610
- value: readyStates.indexOf("CLOSING")
2611
- });
2612
- Object.defineProperty(WebSocket2.prototype, "CLOSING", {
2613
- enumerable: true,
2614
- value: readyStates.indexOf("CLOSING")
2615
- });
2616
- Object.defineProperty(WebSocket2, "CLOSED", {
2617
- enumerable: true,
2618
- value: readyStates.indexOf("CLOSED")
2619
- });
2620
- Object.defineProperty(WebSocket2.prototype, "CLOSED", {
2621
- enumerable: true,
2622
- value: readyStates.indexOf("CLOSED")
2623
- });
2624
- [
2625
- "binaryType",
2626
- "bufferedAmount",
2627
- "extensions",
2628
- "isPaused",
2629
- "protocol",
2630
- "readyState",
2631
- "url"
2632
- ].forEach((property) => {
2633
- Object.defineProperty(WebSocket2.prototype, property, { enumerable: true });
2634
- });
2635
- ["open", "error", "close", "message"].forEach((method) => {
2636
- Object.defineProperty(WebSocket2.prototype, `on${method}`, {
2637
- enumerable: true,
2638
- get() {
2639
- for (const listener of this.listeners(method)) {
2640
- if (listener[kForOnEventAttribute])
2641
- return listener[kListener];
2642
- }
2643
- return null;
2644
- },
2645
- set(handler) {
2646
- for (const listener of this.listeners(method)) {
2647
- if (listener[kForOnEventAttribute]) {
2648
- this.removeListener(method, listener);
2649
- break;
2650
- }
2651
- }
2652
- if (typeof handler !== "function")
2653
- return;
2654
- this.addEventListener(method, handler, {
2655
- [kForOnEventAttribute]: true
2656
- });
2657
- }
2658
- });
2659
- });
2660
- WebSocket2.prototype.addEventListener = addEventListener;
2661
- WebSocket2.prototype.removeEventListener = removeEventListener;
2662
- module.exports = WebSocket2;
2663
- function initAsClient(websocket, address, protocols, options) {
2664
- const opts = {
2665
- protocolVersion: protocolVersions[1],
2666
- maxPayload: 100 * 1024 * 1024,
2667
- skipUTF8Validation: false,
2668
- perMessageDeflate: true,
2669
- followRedirects: false,
2670
- maxRedirects: 10,
2671
- ...options,
2672
- createConnection: void 0,
2673
- socketPath: void 0,
2674
- hostname: void 0,
2675
- protocol: void 0,
2676
- timeout: void 0,
2677
- method: "GET",
2678
- host: void 0,
2679
- path: void 0,
2680
- port: void 0
2681
- };
2682
- if (!protocolVersions.includes(opts.protocolVersion)) {
2683
- throw new RangeError(
2684
- `Unsupported protocol version: ${opts.protocolVersion} (supported versions: ${protocolVersions.join(", ")})`
2685
- );
2686
- }
2687
- let parsedUrl;
2688
- if (address instanceof URL) {
2689
- parsedUrl = address;
2690
- websocket._url = address.href;
2691
- } else {
2692
- try {
2693
- parsedUrl = new URL(address);
2694
- } catch (e) {
2695
- throw new SyntaxError(`Invalid URL: ${address}`);
2696
- }
2697
- websocket._url = address;
2698
- }
2699
- const isSecure = parsedUrl.protocol === "wss:";
2700
- const isIpcUrl = parsedUrl.protocol === "ws+unix:";
2701
- let invalidUrlMessage;
2702
- if (parsedUrl.protocol !== "ws:" && !isSecure && !isIpcUrl) {
2703
- invalidUrlMessage = `The URL's protocol must be one of "ws:", "wss:", or "ws+unix:"`;
2704
- } else if (isIpcUrl && !parsedUrl.pathname) {
2705
- invalidUrlMessage = "The URL's pathname is empty";
2706
- } else if (parsedUrl.hash) {
2707
- invalidUrlMessage = "The URL contains a fragment identifier";
2708
- }
2709
- if (invalidUrlMessage) {
2710
- const err = new SyntaxError(invalidUrlMessage);
2711
- if (websocket._redirects === 0) {
2712
- throw err;
2713
- } else {
2714
- emitErrorAndClose(websocket, err);
2715
- return;
2716
- }
2717
- }
2718
- const defaultPort = isSecure ? 443 : 80;
2719
- const key = randomBytes(16).toString("base64");
2720
- const request = isSecure ? https.request : http.request;
2721
- const protocolSet = /* @__PURE__ */ new Set();
2722
- let perMessageDeflate;
2723
- opts.createConnection = isSecure ? tlsConnect : netConnect;
2724
- opts.defaultPort = opts.defaultPort || defaultPort;
2725
- opts.port = parsedUrl.port || defaultPort;
2726
- opts.host = parsedUrl.hostname.startsWith("[") ? parsedUrl.hostname.slice(1, -1) : parsedUrl.hostname;
2727
- opts.headers = {
2728
- ...opts.headers,
2729
- "Sec-WebSocket-Version": opts.protocolVersion,
2730
- "Sec-WebSocket-Key": key,
2731
- Connection: "Upgrade",
2732
- Upgrade: "websocket"
2733
- };
2734
- opts.path = parsedUrl.pathname + parsedUrl.search;
2735
- opts.timeout = opts.handshakeTimeout;
2736
- if (opts.perMessageDeflate) {
2737
- perMessageDeflate = new PerMessageDeflate(
2738
- opts.perMessageDeflate !== true ? opts.perMessageDeflate : {},
2739
- false,
2740
- opts.maxPayload
2741
- );
2742
- opts.headers["Sec-WebSocket-Extensions"] = format({
2743
- [PerMessageDeflate.extensionName]: perMessageDeflate.offer()
2744
- });
2745
- }
2746
- if (protocols.length) {
2747
- for (const protocol of protocols) {
2748
- if (typeof protocol !== "string" || !subprotocolRegex.test(protocol) || protocolSet.has(protocol)) {
2749
- throw new SyntaxError(
2750
- "An invalid or duplicated subprotocol was specified"
2751
- );
2752
- }
2753
- protocolSet.add(protocol);
2754
- }
2755
- opts.headers["Sec-WebSocket-Protocol"] = protocols.join(",");
2756
- }
2757
- if (opts.origin) {
2758
- if (opts.protocolVersion < 13) {
2759
- opts.headers["Sec-WebSocket-Origin"] = opts.origin;
2760
- } else {
2761
- opts.headers.Origin = opts.origin;
2762
- }
2763
- }
2764
- if (parsedUrl.username || parsedUrl.password) {
2765
- opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
2766
- }
2767
- if (isIpcUrl) {
2768
- const parts = opts.path.split(":");
2769
- opts.socketPath = parts[0];
2770
- opts.path = parts[1];
2771
- }
2772
- let req;
2773
- if (opts.followRedirects) {
2774
- if (websocket._redirects === 0) {
2775
- websocket._originalIpc = isIpcUrl;
2776
- websocket._originalSecure = isSecure;
2777
- websocket._originalHostOrSocketPath = isIpcUrl ? opts.socketPath : parsedUrl.host;
2778
- const headers = options && options.headers;
2779
- options = { ...options, headers: {} };
2780
- if (headers) {
2781
- for (const [key2, value] of Object.entries(headers)) {
2782
- options.headers[key2.toLowerCase()] = value;
2783
- }
2784
- }
2785
- } else if (websocket.listenerCount("redirect") === 0) {
2786
- const isSameHost = isIpcUrl ? websocket._originalIpc ? opts.socketPath === websocket._originalHostOrSocketPath : false : websocket._originalIpc ? false : parsedUrl.host === websocket._originalHostOrSocketPath;
2787
- if (!isSameHost || websocket._originalSecure && !isSecure) {
2788
- delete opts.headers.authorization;
2789
- delete opts.headers.cookie;
2790
- if (!isSameHost)
2791
- delete opts.headers.host;
2792
- opts.auth = void 0;
2793
- }
2794
- }
2795
- if (opts.auth && !options.headers.authorization) {
2796
- options.headers.authorization = "Basic " + Buffer.from(opts.auth).toString("base64");
2797
- }
2798
- req = websocket._req = request(opts);
2799
- if (websocket._redirects) {
2800
- websocket.emit("redirect", websocket.url, req);
2801
- }
2802
- } else {
2803
- req = websocket._req = request(opts);
2804
- }
2805
- if (opts.timeout) {
2806
- req.on("timeout", () => {
2807
- abortHandshake(websocket, req, "Opening handshake has timed out");
2808
- });
2809
- }
2810
- req.on("error", (err) => {
2811
- if (req === null || req[kAborted])
2812
- return;
2813
- req = websocket._req = null;
2814
- emitErrorAndClose(websocket, err);
2815
- });
2816
- req.on("response", (res) => {
2817
- const location = res.headers.location;
2818
- const statusCode = res.statusCode;
2819
- if (location && opts.followRedirects && statusCode >= 300 && statusCode < 400) {
2820
- if (++websocket._redirects > opts.maxRedirects) {
2821
- abortHandshake(websocket, req, "Maximum redirects exceeded");
2822
- return;
2823
- }
2824
- req.abort();
2825
- let addr;
2826
- try {
2827
- addr = new URL(location, address);
2828
- } catch (e) {
2829
- const err = new SyntaxError(`Invalid URL: ${location}`);
2830
- emitErrorAndClose(websocket, err);
2831
- return;
2832
- }
2833
- initAsClient(websocket, addr, protocols, options);
2834
- } else if (!websocket.emit("unexpected-response", req, res)) {
2835
- abortHandshake(
2836
- websocket,
2837
- req,
2838
- `Unexpected server response: ${res.statusCode}`
2839
- );
2840
- }
2841
- });
2842
- req.on("upgrade", (res, socket, head) => {
2843
- websocket.emit("upgrade", res);
2844
- if (websocket.readyState !== WebSocket2.CONNECTING)
2845
- return;
2846
- req = websocket._req = null;
2847
- if (res.headers.upgrade.toLowerCase() !== "websocket") {
2848
- abortHandshake(websocket, socket, "Invalid Upgrade header");
2849
- return;
2850
- }
2851
- const digest = createHash("sha1").update(key + GUID).digest("base64");
2852
- if (res.headers["sec-websocket-accept"] !== digest) {
2853
- abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
2854
- return;
2855
- }
2856
- const serverProt = res.headers["sec-websocket-protocol"];
2857
- let protError;
2858
- if (serverProt !== void 0) {
2859
- if (!protocolSet.size) {
2860
- protError = "Server sent a subprotocol but none was requested";
2861
- } else if (!protocolSet.has(serverProt)) {
2862
- protError = "Server sent an invalid subprotocol";
2863
- }
2864
- } else if (protocolSet.size) {
2865
- protError = "Server sent no subprotocol";
2866
- }
2867
- if (protError) {
2868
- abortHandshake(websocket, socket, protError);
2869
- return;
2870
- }
2871
- if (serverProt)
2872
- websocket._protocol = serverProt;
2873
- const secWebSocketExtensions = res.headers["sec-websocket-extensions"];
2874
- if (secWebSocketExtensions !== void 0) {
2875
- if (!perMessageDeflate) {
2876
- const message = "Server sent a Sec-WebSocket-Extensions header but no extension was requested";
2877
- abortHandshake(websocket, socket, message);
2878
- return;
2879
- }
2880
- let extensions;
2881
- try {
2882
- extensions = parse(secWebSocketExtensions);
2883
- } catch (err) {
2884
- const message = "Invalid Sec-WebSocket-Extensions header";
2885
- abortHandshake(websocket, socket, message);
2886
- return;
2887
- }
2888
- const extensionNames = Object.keys(extensions);
2889
- if (extensionNames.length !== 1 || extensionNames[0] !== PerMessageDeflate.extensionName) {
2890
- const message = "Server indicated an extension that was not requested";
2891
- abortHandshake(websocket, socket, message);
2892
- return;
2893
- }
2894
- try {
2895
- perMessageDeflate.accept(extensions[PerMessageDeflate.extensionName]);
2896
- } catch (err) {
2897
- const message = "Invalid Sec-WebSocket-Extensions header";
2898
- abortHandshake(websocket, socket, message);
2899
- return;
2900
- }
2901
- websocket._extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
2902
- }
2903
- websocket.setSocket(socket, head, {
2904
- generateMask: opts.generateMask,
2905
- maxPayload: opts.maxPayload,
2906
- skipUTF8Validation: opts.skipUTF8Validation
2907
- });
2908
- });
2909
- if (opts.finishRequest) {
2910
- opts.finishRequest(req, websocket);
2911
- } else {
2912
- req.end();
2913
- }
2914
- }
2915
- function emitErrorAndClose(websocket, err) {
2916
- websocket._readyState = WebSocket2.CLOSING;
2917
- websocket.emit("error", err);
2918
- websocket.emitClose();
2919
- }
2920
- function netConnect(options) {
2921
- options.path = options.socketPath;
2922
- return net.connect(options);
2923
- }
2924
- function tlsConnect(options) {
2925
- options.path = void 0;
2926
- if (!options.servername && options.servername !== "") {
2927
- options.servername = net.isIP(options.host) ? "" : options.host;
2928
- }
2929
- return tls.connect(options);
2930
- }
2931
- function abortHandshake(websocket, stream, message) {
2932
- websocket._readyState = WebSocket2.CLOSING;
2933
- const err = new Error(message);
2934
- Error.captureStackTrace(err, abortHandshake);
2935
- if (stream.setHeader) {
2936
- stream[kAborted] = true;
2937
- stream.abort();
2938
- if (stream.socket && !stream.socket.destroyed) {
2939
- stream.socket.destroy();
2940
- }
2941
- process.nextTick(emitErrorAndClose, websocket, err);
2942
- } else {
2943
- stream.destroy(err);
2944
- stream.once("error", websocket.emit.bind(websocket, "error"));
2945
- stream.once("close", websocket.emitClose.bind(websocket));
2946
- }
2947
- }
2948
- function sendAfterClose(websocket, data, cb) {
2949
- if (data) {
2950
- const length = toBuffer(data).length;
2951
- if (websocket._socket)
2952
- websocket._sender._bufferedBytes += length;
2953
- else
2954
- websocket._bufferedAmount += length;
2955
- }
2956
- if (cb) {
2957
- const err = new Error(
2958
- `WebSocket is not open: readyState ${websocket.readyState} (${readyStates[websocket.readyState]})`
2959
- );
2960
- process.nextTick(cb, err);
2961
- }
2962
- }
2963
- function receiverOnConclude(code, reason) {
2964
- const websocket = this[kWebSocket];
2965
- websocket._closeFrameReceived = true;
2966
- websocket._closeMessage = reason;
2967
- websocket._closeCode = code;
2968
- if (websocket._socket[kWebSocket] === void 0)
2969
- return;
2970
- websocket._socket.removeListener("data", socketOnData);
2971
- process.nextTick(resume, websocket._socket);
2972
- if (code === 1005)
2973
- websocket.close();
2974
- else
2975
- websocket.close(code, reason);
2976
- }
2977
- function receiverOnDrain() {
2978
- const websocket = this[kWebSocket];
2979
- if (!websocket.isPaused)
2980
- websocket._socket.resume();
2981
- }
2982
- function receiverOnError(err) {
2983
- const websocket = this[kWebSocket];
2984
- if (websocket._socket[kWebSocket] !== void 0) {
2985
- websocket._socket.removeListener("data", socketOnData);
2986
- process.nextTick(resume, websocket._socket);
2987
- websocket.close(err[kStatusCode]);
2988
- }
2989
- websocket.emit("error", err);
2990
- }
2991
- function receiverOnFinish() {
2992
- this[kWebSocket].emitClose();
2993
- }
2994
- function receiverOnMessage(data, isBinary) {
2995
- this[kWebSocket].emit("message", data, isBinary);
2996
- }
2997
- function receiverOnPing(data) {
2998
- const websocket = this[kWebSocket];
2999
- websocket.pong(data, !websocket._isServer, NOOP);
3000
- websocket.emit("ping", data);
3001
- }
3002
- function receiverOnPong(data) {
3003
- this[kWebSocket].emit("pong", data);
3004
- }
3005
- function resume(stream) {
3006
- stream.resume();
3007
- }
3008
- function socketOnClose() {
3009
- const websocket = this[kWebSocket];
3010
- this.removeListener("close", socketOnClose);
3011
- this.removeListener("data", socketOnData);
3012
- this.removeListener("end", socketOnEnd);
3013
- websocket._readyState = WebSocket2.CLOSING;
3014
- let chunk;
3015
- if (!this._readableState.endEmitted && !websocket._closeFrameReceived && !websocket._receiver._writableState.errorEmitted && (chunk = websocket._socket.read()) !== null) {
3016
- websocket._receiver.write(chunk);
3017
- }
3018
- websocket._receiver.end();
3019
- this[kWebSocket] = void 0;
3020
- clearTimeout(websocket._closeTimer);
3021
- if (websocket._receiver._writableState.finished || websocket._receiver._writableState.errorEmitted) {
3022
- websocket.emitClose();
3023
- } else {
3024
- websocket._receiver.on("error", receiverOnFinish);
3025
- websocket._receiver.on("finish", receiverOnFinish);
3026
- }
3027
- }
3028
- function socketOnData(chunk) {
3029
- if (!this[kWebSocket]._receiver.write(chunk)) {
3030
- this.pause();
3031
- }
3032
- }
3033
- function socketOnEnd() {
3034
- const websocket = this[kWebSocket];
3035
- websocket._readyState = WebSocket2.CLOSING;
3036
- websocket._receiver.end();
3037
- this.end();
3038
- }
3039
- function socketOnError() {
3040
- const websocket = this[kWebSocket];
3041
- this.removeListener("error", socketOnError);
3042
- this.on("error", NOOP);
3043
- if (websocket) {
3044
- websocket._readyState = WebSocket2.CLOSING;
3045
- this.destroy();
3046
- }
3047
- }
3048
- }
3049
- });
3050
- var require_subprotocol = __commonJS({
3051
- "../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/subprotocol.js"(exports, module) {
3052
- "use strict";
3053
- init_cjs_shims2();
3054
- var { tokenChars } = require_validation();
3055
- function parse(header) {
3056
- const protocols = /* @__PURE__ */ new Set();
3057
- let start = -1;
3058
- let end = -1;
3059
- let i = 0;
3060
- for (i; i < header.length; i++) {
3061
- const code = header.charCodeAt(i);
3062
- if (end === -1 && tokenChars[code] === 1) {
3063
- if (start === -1)
3064
- start = i;
3065
- } else if (i !== 0 && (code === 32 || code === 9)) {
3066
- if (end === -1 && start !== -1)
3067
- end = i;
3068
- } else if (code === 44) {
3069
- if (start === -1) {
3070
- throw new SyntaxError(`Unexpected character at index ${i}`);
3071
- }
3072
- if (end === -1)
3073
- end = i;
3074
- const protocol2 = header.slice(start, end);
3075
- if (protocols.has(protocol2)) {
3076
- throw new SyntaxError(`The "${protocol2}" subprotocol is duplicated`);
3077
- }
3078
- protocols.add(protocol2);
3079
- start = end = -1;
3080
- } else {
3081
- throw new SyntaxError(`Unexpected character at index ${i}`);
3082
- }
3083
- }
3084
- if (start === -1 || end !== -1) {
3085
- throw new SyntaxError("Unexpected end of input");
3086
- }
3087
- const protocol = header.slice(start, i);
3088
- if (protocols.has(protocol)) {
3089
- throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
3090
- }
3091
- protocols.add(protocol);
3092
- return protocols;
3093
- }
3094
- module.exports = { parse };
3095
- }
3096
- });
3097
- var require_websocket_server = __commonJS({
3098
- "../../node_modules/.pnpm/ws@8.13.0/node_modules/ws/lib/websocket-server.js"(exports, module) {
3099
- "use strict";
3100
- init_cjs_shims2();
3101
- var EventEmitter = __require("events");
3102
- var http = __require("http");
3103
- var https = __require("https");
3104
- var net = __require("net");
3105
- var tls = __require("tls");
3106
- var { createHash } = __require("crypto");
3107
- var extension = require_extension();
3108
- var PerMessageDeflate = require_permessage_deflate();
3109
- var subprotocol = require_subprotocol();
3110
- var WebSocket2 = require_websocket();
3111
- var { GUID, kWebSocket } = require_constants();
3112
- var keyRegex = /^[+/0-9A-Za-z]{22}==$/;
3113
- var RUNNING = 0;
3114
- var CLOSING = 1;
3115
- var CLOSED = 2;
3116
- var WebSocketServer2 = class extends EventEmitter {
3117
- /**
3118
- * Create a `WebSocketServer` instance.
3119
- *
3120
- * @param {Object} options Configuration options
3121
- * @param {Number} [options.backlog=511] The maximum length of the queue of
3122
- * pending connections
3123
- * @param {Boolean} [options.clientTracking=true] Specifies whether or not to
3124
- * track clients
3125
- * @param {Function} [options.handleProtocols] A hook to handle protocols
3126
- * @param {String} [options.host] The hostname where to bind the server
3127
- * @param {Number} [options.maxPayload=104857600] The maximum allowed message
3128
- * size
3129
- * @param {Boolean} [options.noServer=false] Enable no server mode
3130
- * @param {String} [options.path] Accept only connections matching this path
3131
- * @param {(Boolean|Object)} [options.perMessageDeflate=false] Enable/disable
3132
- * permessage-deflate
3133
- * @param {Number} [options.port] The port where to bind the server
3134
- * @param {(http.Server|https.Server)} [options.server] A pre-created HTTP/S
3135
- * server to use
3136
- * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
3137
- * not to skip UTF-8 validation for text and close messages
3138
- * @param {Function} [options.verifyClient] A hook to reject connections
3139
- * @param {Function} [options.WebSocket=WebSocket] Specifies the `WebSocket`
3140
- * class to use. It must be the `WebSocket` class or class that extends it
3141
- * @param {Function} [callback] A listener for the `listening` event
3142
- */
3143
- constructor(options, callback) {
3144
- super();
3145
- options = {
3146
- maxPayload: 100 * 1024 * 1024,
3147
- skipUTF8Validation: false,
3148
- perMessageDeflate: false,
3149
- handleProtocols: null,
3150
- clientTracking: true,
3151
- verifyClient: null,
3152
- noServer: false,
3153
- backlog: null,
3154
- // use default (511 as implemented in net.js)
3155
- server: null,
3156
- host: null,
3157
- path: null,
3158
- port: null,
3159
- WebSocket: WebSocket2,
3160
- ...options
3161
- };
3162
- if (options.port == null && !options.server && !options.noServer || options.port != null && (options.server || options.noServer) || options.server && options.noServer) {
3163
- throw new TypeError(
3164
- 'One and only one of the "port", "server", or "noServer" options must be specified'
3165
- );
3166
- }
3167
- if (options.port != null) {
3168
- this._server = http.createServer((req, res) => {
3169
- const body = http.STATUS_CODES[426];
3170
- res.writeHead(426, {
3171
- "Content-Length": body.length,
3172
- "Content-Type": "text/plain"
3173
- });
3174
- res.end(body);
3175
- });
3176
- this._server.listen(
3177
- options.port,
3178
- options.host,
3179
- options.backlog,
3180
- callback
3181
- );
3182
- } else if (options.server) {
3183
- this._server = options.server;
3184
- }
3185
- if (this._server) {
3186
- const emitConnection = this.emit.bind(this, "connection");
3187
- this._removeListeners = addListeners(this._server, {
3188
- listening: this.emit.bind(this, "listening"),
3189
- error: this.emit.bind(this, "error"),
3190
- upgrade: (req, socket, head) => {
3191
- this.handleUpgrade(req, socket, head, emitConnection);
3192
- }
3193
- });
3194
- }
3195
- if (options.perMessageDeflate === true)
3196
- options.perMessageDeflate = {};
3197
- if (options.clientTracking) {
3198
- this.clients = /* @__PURE__ */ new Set();
3199
- this._shouldEmitClose = false;
3200
- }
3201
- this.options = options;
3202
- this._state = RUNNING;
3203
- }
3204
- /**
3205
- * Returns the bound address, the address family name, and port of the server
3206
- * as reported by the operating system if listening on an IP socket.
3207
- * If the server is listening on a pipe or UNIX domain socket, the name is
3208
- * returned as a string.
3209
- *
3210
- * @return {(Object|String|null)} The address of the server
3211
- * @public
3212
- */
3213
- address() {
3214
- if (this.options.noServer) {
3215
- throw new Error('The server is operating in "noServer" mode');
3216
- }
3217
- if (!this._server)
3218
- return null;
3219
- return this._server.address();
3220
- }
3221
- /**
3222
- * Stop the server from accepting new connections and emit the `'close'` event
3223
- * when all existing connections are closed.
3224
- *
3225
- * @param {Function} [cb] A one-time listener for the `'close'` event
3226
- * @public
3227
- */
3228
- close(cb) {
3229
- if (this._state === CLOSED) {
3230
- if (cb) {
3231
- this.once("close", () => {
3232
- cb(new Error("The server is not running"));
3233
- });
3234
- }
3235
- process.nextTick(emitClose, this);
3236
- return;
3237
- }
3238
- if (cb)
3239
- this.once("close", cb);
3240
- if (this._state === CLOSING)
3241
- return;
3242
- this._state = CLOSING;
3243
- if (this.options.noServer || this.options.server) {
3244
- if (this._server) {
3245
- this._removeListeners();
3246
- this._removeListeners = this._server = null;
3247
- }
3248
- if (this.clients) {
3249
- if (!this.clients.size) {
3250
- process.nextTick(emitClose, this);
3251
- } else {
3252
- this._shouldEmitClose = true;
3253
- }
3254
- } else {
3255
- process.nextTick(emitClose, this);
3256
- }
3257
- } else {
3258
- const server = this._server;
3259
- this._removeListeners();
3260
- this._removeListeners = this._server = null;
3261
- server.close(() => {
3262
- emitClose(this);
3263
- });
3264
- }
3265
- }
3266
- /**
3267
- * See if a given request should be handled by this server instance.
3268
- *
3269
- * @param {http.IncomingMessage} req Request object to inspect
3270
- * @return {Boolean} `true` if the request is valid, else `false`
3271
- * @public
3272
- */
3273
- shouldHandle(req) {
3274
- if (this.options.path) {
3275
- const index = req.url.indexOf("?");
3276
- const pathname = index !== -1 ? req.url.slice(0, index) : req.url;
3277
- if (pathname !== this.options.path)
3278
- return false;
3279
- }
3280
- return true;
3281
- }
3282
- /**
3283
- * Handle a HTTP Upgrade request.
3284
- *
3285
- * @param {http.IncomingMessage} req The request object
3286
- * @param {(net.Socket|tls.Socket)} socket The network socket between the
3287
- * server and client
3288
- * @param {Buffer} head The first packet of the upgraded stream
3289
- * @param {Function} cb Callback
3290
- * @public
3291
- */
3292
- handleUpgrade(req, socket, head, cb) {
3293
- socket.on("error", socketOnError);
3294
- const key = req.headers["sec-websocket-key"];
3295
- const version = +req.headers["sec-websocket-version"];
3296
- if (req.method !== "GET") {
3297
- const message = "Invalid HTTP method";
3298
- abortHandshakeOrEmitwsClientError(this, req, socket, 405, message);
3299
- return;
3300
- }
3301
- if (req.headers.upgrade.toLowerCase() !== "websocket") {
3302
- const message = "Invalid Upgrade header";
3303
- abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
3304
- return;
3305
- }
3306
- if (!key || !keyRegex.test(key)) {
3307
- const message = "Missing or invalid Sec-WebSocket-Key header";
3308
- abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
3309
- return;
3310
- }
3311
- if (version !== 8 && version !== 13) {
3312
- const message = "Missing or invalid Sec-WebSocket-Version header";
3313
- abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
3314
- return;
3315
- }
3316
- if (!this.shouldHandle(req)) {
3317
- abortHandshake(socket, 400);
3318
- return;
3319
- }
3320
- const secWebSocketProtocol = req.headers["sec-websocket-protocol"];
3321
- let protocols = /* @__PURE__ */ new Set();
3322
- if (secWebSocketProtocol !== void 0) {
3323
- try {
3324
- protocols = subprotocol.parse(secWebSocketProtocol);
3325
- } catch (err) {
3326
- const message = "Invalid Sec-WebSocket-Protocol header";
3327
- abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
3328
- return;
3329
- }
3330
- }
3331
- const secWebSocketExtensions = req.headers["sec-websocket-extensions"];
3332
- const extensions = {};
3333
- if (this.options.perMessageDeflate && secWebSocketExtensions !== void 0) {
3334
- const perMessageDeflate = new PerMessageDeflate(
3335
- this.options.perMessageDeflate,
3336
- true,
3337
- this.options.maxPayload
3338
- );
3339
- try {
3340
- const offers = extension.parse(secWebSocketExtensions);
3341
- if (offers[PerMessageDeflate.extensionName]) {
3342
- perMessageDeflate.accept(offers[PerMessageDeflate.extensionName]);
3343
- extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
3344
- }
3345
- } catch (err) {
3346
- const message = "Invalid or unacceptable Sec-WebSocket-Extensions header";
3347
- abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
3348
- return;
3349
- }
3350
- }
3351
- if (this.options.verifyClient) {
3352
- const info = {
3353
- origin: req.headers[`${version === 8 ? "sec-websocket-origin" : "origin"}`],
3354
- secure: !!(req.socket.authorized || req.socket.encrypted),
3355
- req
3356
- };
3357
- if (this.options.verifyClient.length === 2) {
3358
- this.options.verifyClient(info, (verified, code, message, headers) => {
3359
- if (!verified) {
3360
- return abortHandshake(socket, code || 401, message, headers);
3361
- }
3362
- this.completeUpgrade(
3363
- extensions,
3364
- key,
3365
- protocols,
3366
- req,
3367
- socket,
3368
- head,
3369
- cb
3370
- );
3371
- });
3372
- return;
3373
- }
3374
- if (!this.options.verifyClient(info))
3375
- return abortHandshake(socket, 401);
3376
- }
3377
- this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
3378
- }
3379
- /**
3380
- * Upgrade the connection to WebSocket.
3381
- *
3382
- * @param {Object} extensions The accepted extensions
3383
- * @param {String} key The value of the `Sec-WebSocket-Key` header
3384
- * @param {Set} protocols The subprotocols
3385
- * @param {http.IncomingMessage} req The request object
3386
- * @param {(net.Socket|tls.Socket)} socket The network socket between the
3387
- * server and client
3388
- * @param {Buffer} head The first packet of the upgraded stream
3389
- * @param {Function} cb Callback
3390
- * @throws {Error} If called more than once with the same socket
3391
- * @private
3392
- */
3393
- completeUpgrade(extensions, key, protocols, req, socket, head, cb) {
3394
- if (!socket.readable || !socket.writable)
3395
- return socket.destroy();
3396
- if (socket[kWebSocket]) {
3397
- throw new Error(
3398
- "server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration"
3399
- );
3400
- }
3401
- if (this._state > RUNNING)
3402
- return abortHandshake(socket, 503);
3403
- const digest = createHash("sha1").update(key + GUID).digest("base64");
3404
- const headers = [
3405
- "HTTP/1.1 101 Switching Protocols",
3406
- "Upgrade: websocket",
3407
- "Connection: Upgrade",
3408
- `Sec-WebSocket-Accept: ${digest}`
3409
- ];
3410
- const ws = new this.options.WebSocket(null);
3411
- if (protocols.size) {
3412
- const protocol = this.options.handleProtocols ? this.options.handleProtocols(protocols, req) : protocols.values().next().value;
3413
- if (protocol) {
3414
- headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
3415
- ws._protocol = protocol;
3416
- }
3417
- }
3418
- if (extensions[PerMessageDeflate.extensionName]) {
3419
- const params = extensions[PerMessageDeflate.extensionName].params;
3420
- const value = extension.format({
3421
- [PerMessageDeflate.extensionName]: [params]
3422
- });
3423
- headers.push(`Sec-WebSocket-Extensions: ${value}`);
3424
- ws._extensions = extensions;
3425
- }
3426
- this.emit("headers", headers, req);
3427
- socket.write(headers.concat("\r\n").join("\r\n"));
3428
- socket.removeListener("error", socketOnError);
3429
- ws.setSocket(socket, head, {
3430
- maxPayload: this.options.maxPayload,
3431
- skipUTF8Validation: this.options.skipUTF8Validation
3432
- });
3433
- if (this.clients) {
3434
- this.clients.add(ws);
3435
- ws.on("close", () => {
3436
- this.clients.delete(ws);
3437
- if (this._shouldEmitClose && !this.clients.size) {
3438
- process.nextTick(emitClose, this);
3439
- }
3440
- });
3441
- }
3442
- cb(ws, req);
3443
- }
3444
- };
3445
- module.exports = WebSocketServer2;
3446
- function addListeners(server, map) {
3447
- for (const event of Object.keys(map))
3448
- server.on(event, map[event]);
3449
- return function removeListeners() {
3450
- for (const event of Object.keys(map)) {
3451
- server.removeListener(event, map[event]);
3452
- }
3453
- };
3454
- }
3455
- function emitClose(server) {
3456
- server._state = CLOSED;
3457
- server.emit("close");
3458
- }
3459
- function socketOnError() {
3460
- this.destroy();
3461
- }
3462
- function abortHandshake(socket, code, message, headers) {
3463
- message = message || http.STATUS_CODES[code];
3464
- headers = {
3465
- Connection: "close",
3466
- "Content-Type": "text/html",
3467
- "Content-Length": Buffer.byteLength(message),
3468
- ...headers
3469
- };
3470
- socket.once("finish", socket.destroy);
3471
- socket.end(
3472
- `HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r
3473
- ` + Object.keys(headers).map((h) => `${h}: ${headers[h]}`).join("\r\n") + "\r\n\r\n" + message
3474
- );
3475
- }
3476
- function abortHandshakeOrEmitwsClientError(server, req, socket, code, message) {
3477
- if (server.listenerCount("wsClientError")) {
3478
- const err = new Error(message);
3479
- Error.captureStackTrace(err, abortHandshakeOrEmitwsClientError);
3480
- server.emit("wsClientError", err, socket, req);
3481
- } else {
3482
- abortHandshake(socket, code, message);
3483
- }
3484
- }
3485
- }
3486
- });
3487
- init_cjs_shims2();
3488
- init_cjs_shims2();
3489
- init_cjs_shims2();
3490
- var import_stream = __toESM(require_stream(), 1);
3491
- var import_receiver = __toESM(require_receiver(), 1);
3492
- var import_sender = __toESM(require_sender(), 1);
3493
- var import_websocket = __toESM(require_websocket(), 1);
3494
- var import_websocket_server = __toESM(require_websocket_server(), 1);
3495
- var wrapper_default = import_websocket.default;
3496
- var customGlobal = global;
3497
- if (!customGlobal.WebSocket) {
3498
- customGlobal.WebSocket = wrapper_default;
3499
- }
3500
- if (!customGlobal.window) {
3501
- customGlobal.window = global;
3502
- }
3503
- if (!customGlobal.self) {
3504
- customGlobal.self = global;
3505
- }
3506
- customGlobal.window.__REACT_DEVTOOLS_COMPONENT_FILTERS__ = [
3507
- {
3508
- // ComponentFilterElementType
3509
- type: 1,
3510
- // ElementTypeHostComponent
3511
- value: 7,
3512
- isEnabled: true
3513
- },
3514
- {
3515
- // ComponentFilterDisplayName
3516
- type: 2,
3517
- value: "InternalApp",
3518
- isEnabled: true,
3519
- isValid: true
3520
- },
3521
- {
3522
- // ComponentFilterDisplayName
3523
- type: 2,
3524
- value: "InternalAppContext",
3525
- isEnabled: true,
3526
- isValid: true
3527
- },
3528
- {
3529
- // ComponentFilterDisplayName
3530
- type: 2,
3531
- value: "InternalStdoutContext",
3532
- isEnabled: true,
3533
- isValid: true
3534
- },
3535
- {
3536
- // ComponentFilterDisplayName
3537
- type: 2,
3538
- value: "InternalStderrContext",
3539
- isEnabled: true,
3540
- isValid: true
3541
- },
3542
- {
3543
- // ComponentFilterDisplayName
3544
- type: 2,
3545
- value: "InternalStdinContext",
3546
- isEnabled: true,
3547
- isValid: true
3548
- },
3549
- {
3550
- // ComponentFilterDisplayName
3551
- type: 2,
3552
- value: "InternalFocusContext",
3553
- isEnabled: true,
3554
- isValid: true
3555
- }
3556
- ];
3557
- devtools.connectToDevTools();