@inkeep/agents-work-apps 0.50.0 → 0.50.3
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.
- package/dist/_virtual/rolldown_runtime.js +32 -0
- package/dist/env.d.ts +2 -0
- package/dist/env.js +1 -0
- package/dist/github/mcp/auth.d.ts +2 -2
- package/dist/github/mcp/index.d.ts +2 -2
- package/dist/github/mcp/schemas.d.ts +1 -1
- package/dist/github/routes/tokenExchange.d.ts +2 -2
- package/dist/github/routes/webhooks.d.ts +2 -2
- package/dist/node_modules/.pnpm/@slack_logger@4.0.0/node_modules/@slack/logger/dist/index.js +89 -0
- package/dist/node_modules/.pnpm/@slack_socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/package.js +85 -0
- package/dist/node_modules/.pnpm/@slack_socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/src/SlackWebSocket.js +223 -0
- package/dist/node_modules/.pnpm/@slack_socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/src/SocketModeClient.js +367 -0
- package/dist/node_modules/.pnpm/@slack_socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/src/UnrecoverableSocketModeStartError.js +20 -0
- package/dist/node_modules/.pnpm/@slack_socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/src/errors.js +71 -0
- package/dist/node_modules/.pnpm/@slack_socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/src/index.js +44 -0
- package/dist/node_modules/.pnpm/@slack_socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/src/logger.js +32 -0
- package/dist/node_modules/.pnpm/eventemitter3@5.0.1/node_modules/eventemitter3/index.js +241 -0
- package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/index.js +23 -0
- package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/buffer-util.js +107 -0
- package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/constants.js +29 -0
- package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/event-target.js +226 -0
- package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/extension.js +150 -0
- package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/limiter.js +57 -0
- package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/permessage-deflate.js +342 -0
- package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/receiver.js +457 -0
- package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/sender.js +505 -0
- package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/stream.js +123 -0
- package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/subprotocol.js +46 -0
- package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/validation.js +203 -0
- package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/websocket-server.js +385 -0
- package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/websocket.js +985 -0
- package/dist/slack/dispatcher.d.ts +16 -0
- package/dist/slack/dispatcher.js +335 -0
- package/dist/slack/i18n/strings.d.ts +5 -5
- package/dist/slack/i18n/strings.js +9 -9
- package/dist/slack/index.d.ts +3 -1
- package/dist/slack/index.js +4 -2
- package/dist/slack/middleware/permissions.js +120 -107
- package/dist/slack/routes/events.js +10 -328
- package/dist/slack/routes/oauth.js +6 -3
- package/dist/slack/routes/users.js +12 -6
- package/dist/slack/routes/workspaces.js +31 -36
- package/dist/slack/services/blocks/index.js +7 -11
- package/dist/slack/services/commands/index.js +2 -2
- package/dist/slack/services/dev-config.d.ts +23 -0
- package/dist/slack/services/dev-config.js +91 -0
- package/dist/slack/services/events/app-mention.js +6 -17
- package/dist/slack/services/events/modal-submission.js +5 -5
- package/dist/slack/services/events/streaming.js +4 -3
- package/dist/slack/services/events/utils.js +8 -8
- package/dist/slack/services/index.js +1 -1
- package/dist/slack/services/modals.js +4 -4
- package/dist/slack/services/nango.d.ts +2 -0
- package/dist/slack/services/nango.js +84 -2
- package/dist/slack/socket-mode.d.ts +4 -0
- package/dist/slack/socket-mode.js +130 -0
- package/package.json +3 -2
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
import { __commonJSMin, __require } from "../../../../../../_virtual/rolldown_runtime.js";
|
|
2
|
+
import { require_constants } from "./constants.js";
|
|
3
|
+
import { require_buffer_util } from "./buffer-util.js";
|
|
4
|
+
import { require_permessage_deflate } from "./permessage-deflate.js";
|
|
5
|
+
import { require_validation } from "./validation.js";
|
|
6
|
+
|
|
7
|
+
//#region ../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/receiver.js
|
|
8
|
+
var require_receiver = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
9
|
+
const { Writable } = __require("stream");
|
|
10
|
+
const PerMessageDeflate = require_permessage_deflate();
|
|
11
|
+
const { BINARY_TYPES, EMPTY_BUFFER, kStatusCode, kWebSocket } = require_constants();
|
|
12
|
+
const { concat, toArrayBuffer, unmask } = require_buffer_util();
|
|
13
|
+
const { isValidStatusCode, isValidUTF8 } = require_validation();
|
|
14
|
+
const FastBuffer = Buffer[Symbol.species];
|
|
15
|
+
const GET_INFO = 0;
|
|
16
|
+
const GET_PAYLOAD_LENGTH_16 = 1;
|
|
17
|
+
const GET_PAYLOAD_LENGTH_64 = 2;
|
|
18
|
+
const GET_MASK = 3;
|
|
19
|
+
const GET_DATA = 4;
|
|
20
|
+
const INFLATING = 5;
|
|
21
|
+
const DEFER_EVENT = 6;
|
|
22
|
+
/**
|
|
23
|
+
* HyBi Receiver implementation.
|
|
24
|
+
*
|
|
25
|
+
* @extends Writable
|
|
26
|
+
*/
|
|
27
|
+
var Receiver = class extends Writable {
|
|
28
|
+
/**
|
|
29
|
+
* Creates a Receiver instance.
|
|
30
|
+
*
|
|
31
|
+
* @param {Object} [options] Options object
|
|
32
|
+
* @param {Boolean} [options.allowSynchronousEvents=true] Specifies whether
|
|
33
|
+
* any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
|
|
34
|
+
* multiple times in the same tick
|
|
35
|
+
* @param {String} [options.binaryType=nodebuffer] The type for binary data
|
|
36
|
+
* @param {Object} [options.extensions] An object containing the negotiated
|
|
37
|
+
* extensions
|
|
38
|
+
* @param {Boolean} [options.isServer=false] Specifies whether to operate in
|
|
39
|
+
* client or server mode
|
|
40
|
+
* @param {Number} [options.maxPayload=0] The maximum allowed message length
|
|
41
|
+
* @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
|
|
42
|
+
* not to skip UTF-8 validation for text and close messages
|
|
43
|
+
*/
|
|
44
|
+
constructor(options = {}) {
|
|
45
|
+
super();
|
|
46
|
+
this._allowSynchronousEvents = options.allowSynchronousEvents !== void 0 ? options.allowSynchronousEvents : true;
|
|
47
|
+
this._binaryType = options.binaryType || BINARY_TYPES[0];
|
|
48
|
+
this._extensions = options.extensions || {};
|
|
49
|
+
this._isServer = !!options.isServer;
|
|
50
|
+
this._maxPayload = options.maxPayload | 0;
|
|
51
|
+
this._skipUTF8Validation = !!options.skipUTF8Validation;
|
|
52
|
+
this[kWebSocket] = void 0;
|
|
53
|
+
this._bufferedBytes = 0;
|
|
54
|
+
this._buffers = [];
|
|
55
|
+
this._compressed = false;
|
|
56
|
+
this._payloadLength = 0;
|
|
57
|
+
this._mask = void 0;
|
|
58
|
+
this._fragmented = 0;
|
|
59
|
+
this._masked = false;
|
|
60
|
+
this._fin = false;
|
|
61
|
+
this._opcode = 0;
|
|
62
|
+
this._totalPayloadLength = 0;
|
|
63
|
+
this._messageLength = 0;
|
|
64
|
+
this._fragments = [];
|
|
65
|
+
this._errored = false;
|
|
66
|
+
this._loop = false;
|
|
67
|
+
this._state = GET_INFO;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Implements `Writable.prototype._write()`.
|
|
71
|
+
*
|
|
72
|
+
* @param {Buffer} chunk The chunk of data to write
|
|
73
|
+
* @param {String} encoding The character encoding of `chunk`
|
|
74
|
+
* @param {Function} cb Callback
|
|
75
|
+
* @private
|
|
76
|
+
*/
|
|
77
|
+
_write(chunk, encoding, cb) {
|
|
78
|
+
if (this._opcode === 8 && this._state == GET_INFO) return cb();
|
|
79
|
+
this._bufferedBytes += chunk.length;
|
|
80
|
+
this._buffers.push(chunk);
|
|
81
|
+
this.startLoop(cb);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Consumes `n` bytes from the buffered data.
|
|
85
|
+
*
|
|
86
|
+
* @param {Number} n The number of bytes to consume
|
|
87
|
+
* @return {Buffer} The consumed bytes
|
|
88
|
+
* @private
|
|
89
|
+
*/
|
|
90
|
+
consume(n) {
|
|
91
|
+
this._bufferedBytes -= n;
|
|
92
|
+
if (n === this._buffers[0].length) return this._buffers.shift();
|
|
93
|
+
if (n < this._buffers[0].length) {
|
|
94
|
+
const buf = this._buffers[0];
|
|
95
|
+
this._buffers[0] = new FastBuffer(buf.buffer, buf.byteOffset + n, buf.length - n);
|
|
96
|
+
return new FastBuffer(buf.buffer, buf.byteOffset, n);
|
|
97
|
+
}
|
|
98
|
+
const dst = Buffer.allocUnsafe(n);
|
|
99
|
+
do {
|
|
100
|
+
const buf = this._buffers[0];
|
|
101
|
+
const offset = dst.length - n;
|
|
102
|
+
if (n >= buf.length) dst.set(this._buffers.shift(), offset);
|
|
103
|
+
else {
|
|
104
|
+
dst.set(new Uint8Array(buf.buffer, buf.byteOffset, n), offset);
|
|
105
|
+
this._buffers[0] = new FastBuffer(buf.buffer, buf.byteOffset + n, buf.length - n);
|
|
106
|
+
}
|
|
107
|
+
n -= buf.length;
|
|
108
|
+
} while (n > 0);
|
|
109
|
+
return dst;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Starts the parsing loop.
|
|
113
|
+
*
|
|
114
|
+
* @param {Function} cb Callback
|
|
115
|
+
* @private
|
|
116
|
+
*/
|
|
117
|
+
startLoop(cb) {
|
|
118
|
+
this._loop = true;
|
|
119
|
+
do
|
|
120
|
+
switch (this._state) {
|
|
121
|
+
case GET_INFO:
|
|
122
|
+
this.getInfo(cb);
|
|
123
|
+
break;
|
|
124
|
+
case GET_PAYLOAD_LENGTH_16:
|
|
125
|
+
this.getPayloadLength16(cb);
|
|
126
|
+
break;
|
|
127
|
+
case GET_PAYLOAD_LENGTH_64:
|
|
128
|
+
this.getPayloadLength64(cb);
|
|
129
|
+
break;
|
|
130
|
+
case GET_MASK:
|
|
131
|
+
this.getMask();
|
|
132
|
+
break;
|
|
133
|
+
case GET_DATA:
|
|
134
|
+
this.getData(cb);
|
|
135
|
+
break;
|
|
136
|
+
case INFLATING:
|
|
137
|
+
case DEFER_EVENT:
|
|
138
|
+
this._loop = false;
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
while (this._loop);
|
|
142
|
+
if (!this._errored) cb();
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Reads the first two bytes of a frame.
|
|
146
|
+
*
|
|
147
|
+
* @param {Function} cb Callback
|
|
148
|
+
* @private
|
|
149
|
+
*/
|
|
150
|
+
getInfo(cb) {
|
|
151
|
+
if (this._bufferedBytes < 2) {
|
|
152
|
+
this._loop = false;
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
const buf = this.consume(2);
|
|
156
|
+
if ((buf[0] & 48) !== 0) {
|
|
157
|
+
cb(this.createError(RangeError, "RSV2 and RSV3 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_2_3"));
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const compressed = (buf[0] & 64) === 64;
|
|
161
|
+
if (compressed && !this._extensions[PerMessageDeflate.extensionName]) {
|
|
162
|
+
cb(this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1"));
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
this._fin = (buf[0] & 128) === 128;
|
|
166
|
+
this._opcode = buf[0] & 15;
|
|
167
|
+
this._payloadLength = buf[1] & 127;
|
|
168
|
+
if (this._opcode === 0) {
|
|
169
|
+
if (compressed) {
|
|
170
|
+
cb(this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1"));
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
if (!this._fragmented) {
|
|
174
|
+
cb(this.createError(RangeError, "invalid opcode 0", true, 1002, "WS_ERR_INVALID_OPCODE"));
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
this._opcode = this._fragmented;
|
|
178
|
+
} else if (this._opcode === 1 || this._opcode === 2) {
|
|
179
|
+
if (this._fragmented) {
|
|
180
|
+
cb(this.createError(RangeError, `invalid opcode ${this._opcode}`, true, 1002, "WS_ERR_INVALID_OPCODE"));
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
this._compressed = compressed;
|
|
184
|
+
} else if (this._opcode > 7 && this._opcode < 11) {
|
|
185
|
+
if (!this._fin) {
|
|
186
|
+
cb(this.createError(RangeError, "FIN must be set", true, 1002, "WS_ERR_EXPECTED_FIN"));
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (compressed) {
|
|
190
|
+
cb(this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1"));
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (this._payloadLength > 125 || this._opcode === 8 && this._payloadLength === 1) {
|
|
194
|
+
cb(this.createError(RangeError, `invalid payload length ${this._payloadLength}`, true, 1002, "WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH"));
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
} else {
|
|
198
|
+
cb(this.createError(RangeError, `invalid opcode ${this._opcode}`, true, 1002, "WS_ERR_INVALID_OPCODE"));
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
if (!this._fin && !this._fragmented) this._fragmented = this._opcode;
|
|
202
|
+
this._masked = (buf[1] & 128) === 128;
|
|
203
|
+
if (this._isServer) {
|
|
204
|
+
if (!this._masked) {
|
|
205
|
+
cb(this.createError(RangeError, "MASK must be set", true, 1002, "WS_ERR_EXPECTED_MASK"));
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
} else if (this._masked) {
|
|
209
|
+
cb(this.createError(RangeError, "MASK must be clear", true, 1002, "WS_ERR_UNEXPECTED_MASK"));
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
if (this._payloadLength === 126) this._state = GET_PAYLOAD_LENGTH_16;
|
|
213
|
+
else if (this._payloadLength === 127) this._state = GET_PAYLOAD_LENGTH_64;
|
|
214
|
+
else this.haveLength(cb);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Gets extended payload length (7+16).
|
|
218
|
+
*
|
|
219
|
+
* @param {Function} cb Callback
|
|
220
|
+
* @private
|
|
221
|
+
*/
|
|
222
|
+
getPayloadLength16(cb) {
|
|
223
|
+
if (this._bufferedBytes < 2) {
|
|
224
|
+
this._loop = false;
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
this._payloadLength = this.consume(2).readUInt16BE(0);
|
|
228
|
+
this.haveLength(cb);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Gets extended payload length (7+64).
|
|
232
|
+
*
|
|
233
|
+
* @param {Function} cb Callback
|
|
234
|
+
* @private
|
|
235
|
+
*/
|
|
236
|
+
getPayloadLength64(cb) {
|
|
237
|
+
if (this._bufferedBytes < 8) {
|
|
238
|
+
this._loop = false;
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
const buf = this.consume(8);
|
|
242
|
+
const num = buf.readUInt32BE(0);
|
|
243
|
+
if (num > Math.pow(2, 21) - 1) {
|
|
244
|
+
cb(this.createError(RangeError, "Unsupported WebSocket frame: payload length > 2^53 - 1", false, 1009, "WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH"));
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
this._payloadLength = num * Math.pow(2, 32) + buf.readUInt32BE(4);
|
|
248
|
+
this.haveLength(cb);
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Payload length has been read.
|
|
252
|
+
*
|
|
253
|
+
* @param {Function} cb Callback
|
|
254
|
+
* @private
|
|
255
|
+
*/
|
|
256
|
+
haveLength(cb) {
|
|
257
|
+
if (this._payloadLength && this._opcode < 8) {
|
|
258
|
+
this._totalPayloadLength += this._payloadLength;
|
|
259
|
+
if (this._totalPayloadLength > this._maxPayload && this._maxPayload > 0) {
|
|
260
|
+
cb(this.createError(RangeError, "Max payload size exceeded", false, 1009, "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"));
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
if (this._masked) this._state = GET_MASK;
|
|
265
|
+
else this._state = GET_DATA;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Reads mask bytes.
|
|
269
|
+
*
|
|
270
|
+
* @private
|
|
271
|
+
*/
|
|
272
|
+
getMask() {
|
|
273
|
+
if (this._bufferedBytes < 4) {
|
|
274
|
+
this._loop = false;
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
this._mask = this.consume(4);
|
|
278
|
+
this._state = GET_DATA;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Reads data bytes.
|
|
282
|
+
*
|
|
283
|
+
* @param {Function} cb Callback
|
|
284
|
+
* @private
|
|
285
|
+
*/
|
|
286
|
+
getData(cb) {
|
|
287
|
+
let data = EMPTY_BUFFER;
|
|
288
|
+
if (this._payloadLength) {
|
|
289
|
+
if (this._bufferedBytes < this._payloadLength) {
|
|
290
|
+
this._loop = false;
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
data = this.consume(this._payloadLength);
|
|
294
|
+
if (this._masked && (this._mask[0] | this._mask[1] | this._mask[2] | this._mask[3]) !== 0) unmask(data, this._mask);
|
|
295
|
+
}
|
|
296
|
+
if (this._opcode > 7) {
|
|
297
|
+
this.controlMessage(data, cb);
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
if (this._compressed) {
|
|
301
|
+
this._state = INFLATING;
|
|
302
|
+
this.decompress(data, cb);
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
if (data.length) {
|
|
306
|
+
this._messageLength = this._totalPayloadLength;
|
|
307
|
+
this._fragments.push(data);
|
|
308
|
+
}
|
|
309
|
+
this.dataMessage(cb);
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Decompresses data.
|
|
313
|
+
*
|
|
314
|
+
* @param {Buffer} data Compressed data
|
|
315
|
+
* @param {Function} cb Callback
|
|
316
|
+
* @private
|
|
317
|
+
*/
|
|
318
|
+
decompress(data, cb) {
|
|
319
|
+
this._extensions[PerMessageDeflate.extensionName].decompress(data, this._fin, (err, buf) => {
|
|
320
|
+
if (err) return cb(err);
|
|
321
|
+
if (buf.length) {
|
|
322
|
+
this._messageLength += buf.length;
|
|
323
|
+
if (this._messageLength > this._maxPayload && this._maxPayload > 0) {
|
|
324
|
+
cb(this.createError(RangeError, "Max payload size exceeded", false, 1009, "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"));
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
this._fragments.push(buf);
|
|
328
|
+
}
|
|
329
|
+
this.dataMessage(cb);
|
|
330
|
+
if (this._state === GET_INFO) this.startLoop(cb);
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Handles a data message.
|
|
335
|
+
*
|
|
336
|
+
* @param {Function} cb Callback
|
|
337
|
+
* @private
|
|
338
|
+
*/
|
|
339
|
+
dataMessage(cb) {
|
|
340
|
+
if (!this._fin) {
|
|
341
|
+
this._state = GET_INFO;
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
const messageLength = this._messageLength;
|
|
345
|
+
const fragments = this._fragments;
|
|
346
|
+
this._totalPayloadLength = 0;
|
|
347
|
+
this._messageLength = 0;
|
|
348
|
+
this._fragmented = 0;
|
|
349
|
+
this._fragments = [];
|
|
350
|
+
if (this._opcode === 2) {
|
|
351
|
+
let data;
|
|
352
|
+
if (this._binaryType === "nodebuffer") data = concat(fragments, messageLength);
|
|
353
|
+
else if (this._binaryType === "arraybuffer") data = toArrayBuffer(concat(fragments, messageLength));
|
|
354
|
+
else if (this._binaryType === "blob") data = new Blob(fragments);
|
|
355
|
+
else data = fragments;
|
|
356
|
+
if (this._allowSynchronousEvents) {
|
|
357
|
+
this.emit("message", data, true);
|
|
358
|
+
this._state = GET_INFO;
|
|
359
|
+
} else {
|
|
360
|
+
this._state = DEFER_EVENT;
|
|
361
|
+
setImmediate(() => {
|
|
362
|
+
this.emit("message", data, true);
|
|
363
|
+
this._state = GET_INFO;
|
|
364
|
+
this.startLoop(cb);
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
} else {
|
|
368
|
+
const buf = concat(fragments, messageLength);
|
|
369
|
+
if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
|
|
370
|
+
cb(this.createError(Error, "invalid UTF-8 sequence", true, 1007, "WS_ERR_INVALID_UTF8"));
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
if (this._state === INFLATING || this._allowSynchronousEvents) {
|
|
374
|
+
this.emit("message", buf, false);
|
|
375
|
+
this._state = GET_INFO;
|
|
376
|
+
} else {
|
|
377
|
+
this._state = DEFER_EVENT;
|
|
378
|
+
setImmediate(() => {
|
|
379
|
+
this.emit("message", buf, false);
|
|
380
|
+
this._state = GET_INFO;
|
|
381
|
+
this.startLoop(cb);
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Handles a control message.
|
|
388
|
+
*
|
|
389
|
+
* @param {Buffer} data Data to handle
|
|
390
|
+
* @return {(Error|RangeError|undefined)} A possible error
|
|
391
|
+
* @private
|
|
392
|
+
*/
|
|
393
|
+
controlMessage(data, cb) {
|
|
394
|
+
if (this._opcode === 8) {
|
|
395
|
+
if (data.length === 0) {
|
|
396
|
+
this._loop = false;
|
|
397
|
+
this.emit("conclude", 1005, EMPTY_BUFFER);
|
|
398
|
+
this.end();
|
|
399
|
+
} else {
|
|
400
|
+
const code = data.readUInt16BE(0);
|
|
401
|
+
if (!isValidStatusCode(code)) {
|
|
402
|
+
cb(this.createError(RangeError, `invalid status code ${code}`, true, 1002, "WS_ERR_INVALID_CLOSE_CODE"));
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
const buf = new FastBuffer(data.buffer, data.byteOffset + 2, data.length - 2);
|
|
406
|
+
if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
|
|
407
|
+
cb(this.createError(Error, "invalid UTF-8 sequence", true, 1007, "WS_ERR_INVALID_UTF8"));
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
this._loop = false;
|
|
411
|
+
this.emit("conclude", code, buf);
|
|
412
|
+
this.end();
|
|
413
|
+
}
|
|
414
|
+
this._state = GET_INFO;
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
if (this._allowSynchronousEvents) {
|
|
418
|
+
this.emit(this._opcode === 9 ? "ping" : "pong", data);
|
|
419
|
+
this._state = GET_INFO;
|
|
420
|
+
} else {
|
|
421
|
+
this._state = DEFER_EVENT;
|
|
422
|
+
setImmediate(() => {
|
|
423
|
+
this.emit(this._opcode === 9 ? "ping" : "pong", data);
|
|
424
|
+
this._state = GET_INFO;
|
|
425
|
+
this.startLoop(cb);
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Builds an error object.
|
|
431
|
+
*
|
|
432
|
+
* @param {function(new:Error|RangeError)} ErrorCtor The error constructor
|
|
433
|
+
* @param {String} message The error message
|
|
434
|
+
* @param {Boolean} prefix Specifies whether or not to add a default prefix to
|
|
435
|
+
* `message`
|
|
436
|
+
* @param {Number} statusCode The status code
|
|
437
|
+
* @param {String} errorCode The exposed error code
|
|
438
|
+
* @return {(Error|RangeError)} The error
|
|
439
|
+
* @private
|
|
440
|
+
*/
|
|
441
|
+
createError(ErrorCtor, message, prefix, statusCode, errorCode) {
|
|
442
|
+
this._loop = false;
|
|
443
|
+
this._errored = true;
|
|
444
|
+
const err = new ErrorCtor(prefix ? `Invalid WebSocket frame: ${message}` : message);
|
|
445
|
+
Error.captureStackTrace(err, this.createError);
|
|
446
|
+
err.code = errorCode;
|
|
447
|
+
err[kStatusCode] = statusCode;
|
|
448
|
+
return err;
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
module.exports = Receiver;
|
|
452
|
+
}));
|
|
453
|
+
|
|
454
|
+
//#endregion
|
|
455
|
+
export default require_receiver();
|
|
456
|
+
|
|
457
|
+
export { require_receiver };
|