@lendasat/lendaswap-sdk-pure 0.2.41 → 0.2.43

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