@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.
Files changed (57) hide show
  1. package/dist/_virtual/rolldown_runtime.js +32 -0
  2. package/dist/env.d.ts +2 -0
  3. package/dist/env.js +1 -0
  4. package/dist/github/mcp/auth.d.ts +2 -2
  5. package/dist/github/mcp/index.d.ts +2 -2
  6. package/dist/github/mcp/schemas.d.ts +1 -1
  7. package/dist/github/routes/tokenExchange.d.ts +2 -2
  8. package/dist/github/routes/webhooks.d.ts +2 -2
  9. package/dist/node_modules/.pnpm/@slack_logger@4.0.0/node_modules/@slack/logger/dist/index.js +89 -0
  10. package/dist/node_modules/.pnpm/@slack_socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/package.js +85 -0
  11. package/dist/node_modules/.pnpm/@slack_socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/src/SlackWebSocket.js +223 -0
  12. package/dist/node_modules/.pnpm/@slack_socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/src/SocketModeClient.js +367 -0
  13. package/dist/node_modules/.pnpm/@slack_socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/src/UnrecoverableSocketModeStartError.js +20 -0
  14. package/dist/node_modules/.pnpm/@slack_socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/src/errors.js +71 -0
  15. package/dist/node_modules/.pnpm/@slack_socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/src/index.js +44 -0
  16. package/dist/node_modules/.pnpm/@slack_socket-mode@2.0.5/node_modules/@slack/socket-mode/dist/src/logger.js +32 -0
  17. package/dist/node_modules/.pnpm/eventemitter3@5.0.1/node_modules/eventemitter3/index.js +241 -0
  18. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/index.js +23 -0
  19. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/buffer-util.js +107 -0
  20. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/constants.js +29 -0
  21. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/event-target.js +226 -0
  22. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/extension.js +150 -0
  23. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/limiter.js +57 -0
  24. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/permessage-deflate.js +342 -0
  25. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/receiver.js +457 -0
  26. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/sender.js +505 -0
  27. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/stream.js +123 -0
  28. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/subprotocol.js +46 -0
  29. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/validation.js +203 -0
  30. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/websocket-server.js +385 -0
  31. package/dist/node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/websocket.js +985 -0
  32. package/dist/slack/dispatcher.d.ts +16 -0
  33. package/dist/slack/dispatcher.js +335 -0
  34. package/dist/slack/i18n/strings.d.ts +5 -5
  35. package/dist/slack/i18n/strings.js +9 -9
  36. package/dist/slack/index.d.ts +3 -1
  37. package/dist/slack/index.js +4 -2
  38. package/dist/slack/middleware/permissions.js +120 -107
  39. package/dist/slack/routes/events.js +10 -328
  40. package/dist/slack/routes/oauth.js +6 -3
  41. package/dist/slack/routes/users.js +12 -6
  42. package/dist/slack/routes/workspaces.js +31 -36
  43. package/dist/slack/services/blocks/index.js +7 -11
  44. package/dist/slack/services/commands/index.js +2 -2
  45. package/dist/slack/services/dev-config.d.ts +23 -0
  46. package/dist/slack/services/dev-config.js +91 -0
  47. package/dist/slack/services/events/app-mention.js +6 -17
  48. package/dist/slack/services/events/modal-submission.js +5 -5
  49. package/dist/slack/services/events/streaming.js +4 -3
  50. package/dist/slack/services/events/utils.js +8 -8
  51. package/dist/slack/services/index.js +1 -1
  52. package/dist/slack/services/modals.js +4 -4
  53. package/dist/slack/services/nango.d.ts +2 -0
  54. package/dist/slack/services/nango.js +84 -2
  55. package/dist/slack/socket-mode.d.ts +4 -0
  56. package/dist/slack/socket-mode.js +130 -0
  57. package/package.json +3 -2
@@ -0,0 +1,150 @@
1
+ import { __commonJSMin } from "../../../../../../_virtual/rolldown_runtime.js";
2
+ import { require_validation } from "./validation.js";
3
+
4
+ //#region ../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/extension.js
5
+ var require_extension = /* @__PURE__ */ __commonJSMin(((exports, module) => {
6
+ const { tokenChars } = require_validation();
7
+ /**
8
+ * Adds an offer to the map of extension offers or a parameter to the map of
9
+ * parameters.
10
+ *
11
+ * @param {Object} dest The map of extension offers or parameters
12
+ * @param {String} name The extension or parameter name
13
+ * @param {(Object|Boolean|String)} elem The extension parameters or the
14
+ * parameter value
15
+ * @private
16
+ */
17
+ function push(dest, name, elem) {
18
+ if (dest[name] === void 0) dest[name] = [elem];
19
+ else dest[name].push(elem);
20
+ }
21
+ /**
22
+ * Parses the `Sec-WebSocket-Extensions` header into an object.
23
+ *
24
+ * @param {String} header The field value of the header
25
+ * @return {Object} The parsed object
26
+ * @public
27
+ */
28
+ function parse(header) {
29
+ const offers = Object.create(null);
30
+ let params = Object.create(null);
31
+ let mustUnescape = false;
32
+ let isEscaping = false;
33
+ let inQuotes = false;
34
+ let extensionName;
35
+ let paramName;
36
+ let start = -1;
37
+ let code = -1;
38
+ let end = -1;
39
+ let i = 0;
40
+ for (; i < header.length; i++) {
41
+ code = header.charCodeAt(i);
42
+ if (extensionName === void 0) if (end === -1 && tokenChars[code] === 1) {
43
+ if (start === -1) start = i;
44
+ } else if (i !== 0 && (code === 32 || code === 9)) {
45
+ if (end === -1 && start !== -1) end = i;
46
+ } else if (code === 59 || code === 44) {
47
+ if (start === -1) throw new SyntaxError(`Unexpected character at index ${i}`);
48
+ if (end === -1) end = i;
49
+ const name = header.slice(start, end);
50
+ if (code === 44) {
51
+ push(offers, name, params);
52
+ params = Object.create(null);
53
+ } else extensionName = name;
54
+ start = end = -1;
55
+ } else throw new SyntaxError(`Unexpected character at index ${i}`);
56
+ else if (paramName === void 0) if (end === -1 && tokenChars[code] === 1) {
57
+ if (start === -1) start = i;
58
+ } else if (code === 32 || code === 9) {
59
+ if (end === -1 && start !== -1) end = i;
60
+ } else if (code === 59 || code === 44) {
61
+ if (start === -1) throw new SyntaxError(`Unexpected character at index ${i}`);
62
+ if (end === -1) end = i;
63
+ push(params, header.slice(start, end), true);
64
+ if (code === 44) {
65
+ push(offers, extensionName, params);
66
+ params = Object.create(null);
67
+ extensionName = void 0;
68
+ }
69
+ start = end = -1;
70
+ } else if (code === 61 && start !== -1 && end === -1) {
71
+ paramName = header.slice(start, i);
72
+ start = end = -1;
73
+ } else throw new SyntaxError(`Unexpected character at index ${i}`);
74
+ else if (isEscaping) {
75
+ if (tokenChars[code] !== 1) throw new SyntaxError(`Unexpected character at index ${i}`);
76
+ if (start === -1) start = i;
77
+ else if (!mustUnescape) mustUnescape = true;
78
+ isEscaping = false;
79
+ } else if (inQuotes) if (tokenChars[code] === 1) {
80
+ if (start === -1) start = i;
81
+ } else if (code === 34 && start !== -1) {
82
+ inQuotes = false;
83
+ end = i;
84
+ } else if (code === 92) isEscaping = true;
85
+ else throw new SyntaxError(`Unexpected character at index ${i}`);
86
+ else if (code === 34 && header.charCodeAt(i - 1) === 61) inQuotes = true;
87
+ else if (end === -1 && tokenChars[code] === 1) {
88
+ if (start === -1) start = i;
89
+ } else if (start !== -1 && (code === 32 || code === 9)) {
90
+ if (end === -1) end = i;
91
+ } else if (code === 59 || code === 44) {
92
+ if (start === -1) throw new SyntaxError(`Unexpected character at index ${i}`);
93
+ if (end === -1) end = i;
94
+ let value = header.slice(start, end);
95
+ if (mustUnescape) {
96
+ value = value.replace(/\\/g, "");
97
+ mustUnescape = false;
98
+ }
99
+ push(params, paramName, value);
100
+ if (code === 44) {
101
+ push(offers, extensionName, params);
102
+ params = Object.create(null);
103
+ extensionName = void 0;
104
+ }
105
+ paramName = void 0;
106
+ start = end = -1;
107
+ } else throw new SyntaxError(`Unexpected character at index ${i}`);
108
+ }
109
+ if (start === -1 || inQuotes || code === 32 || code === 9) throw new SyntaxError("Unexpected end of input");
110
+ if (end === -1) end = i;
111
+ const token = header.slice(start, end);
112
+ if (extensionName === void 0) push(offers, token, params);
113
+ else {
114
+ if (paramName === void 0) push(params, token, true);
115
+ else if (mustUnescape) push(params, paramName, token.replace(/\\/g, ""));
116
+ else push(params, paramName, token);
117
+ push(offers, extensionName, params);
118
+ }
119
+ return offers;
120
+ }
121
+ /**
122
+ * Builds the `Sec-WebSocket-Extensions` header field value.
123
+ *
124
+ * @param {Object} extensions The map of extensions and parameters to format
125
+ * @return {String} A string representing the given object
126
+ * @public
127
+ */
128
+ function format(extensions) {
129
+ return Object.keys(extensions).map((extension) => {
130
+ let configurations = extensions[extension];
131
+ if (!Array.isArray(configurations)) configurations = [configurations];
132
+ return configurations.map((params) => {
133
+ return [extension].concat(Object.keys(params).map((k) => {
134
+ let values = params[k];
135
+ if (!Array.isArray(values)) values = [values];
136
+ return values.map((v) => v === true ? k : `${k}=${v}`).join("; ");
137
+ })).join("; ");
138
+ }).join(", ");
139
+ }).join(", ");
140
+ }
141
+ module.exports = {
142
+ format,
143
+ parse
144
+ };
145
+ }));
146
+
147
+ //#endregion
148
+ export default require_extension();
149
+
150
+ export { require_extension };
@@ -0,0 +1,57 @@
1
+ import { __commonJSMin } from "../../../../../../_virtual/rolldown_runtime.js";
2
+
3
+ //#region ../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/limiter.js
4
+ var require_limiter = /* @__PURE__ */ __commonJSMin(((exports, module) => {
5
+ const kDone = Symbol("kDone");
6
+ const kRun = Symbol("kRun");
7
+ /**
8
+ * A very simple job queue with adjustable concurrency. Adapted from
9
+ * https://github.com/STRML/async-limiter
10
+ */
11
+ var Limiter = class {
12
+ /**
13
+ * Creates a new `Limiter`.
14
+ *
15
+ * @param {Number} [concurrency=Infinity] The maximum number of jobs allowed
16
+ * to run concurrently
17
+ */
18
+ constructor(concurrency) {
19
+ this[kDone] = () => {
20
+ this.pending--;
21
+ this[kRun]();
22
+ };
23
+ this.concurrency = concurrency || Infinity;
24
+ this.jobs = [];
25
+ this.pending = 0;
26
+ }
27
+ /**
28
+ * Adds a job to the queue.
29
+ *
30
+ * @param {Function} job The job to run
31
+ * @public
32
+ */
33
+ add(job) {
34
+ this.jobs.push(job);
35
+ this[kRun]();
36
+ }
37
+ /**
38
+ * Removes a job from the queue and runs it if possible.
39
+ *
40
+ * @private
41
+ */
42
+ [kRun]() {
43
+ if (this.pending === this.concurrency) return;
44
+ if (this.jobs.length) {
45
+ const job = this.jobs.shift();
46
+ this.pending++;
47
+ job(this[kDone]);
48
+ }
49
+ }
50
+ };
51
+ module.exports = Limiter;
52
+ }));
53
+
54
+ //#endregion
55
+ export default require_limiter();
56
+
57
+ export { require_limiter };
@@ -0,0 +1,342 @@
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_limiter } from "./limiter.js";
5
+
6
+ //#region ../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/permessage-deflate.js
7
+ var require_permessage_deflate = /* @__PURE__ */ __commonJSMin(((exports, module) => {
8
+ const zlib = __require("zlib");
9
+ const bufferUtil = require_buffer_util();
10
+ const Limiter = require_limiter();
11
+ const { kStatusCode } = require_constants();
12
+ const FastBuffer = Buffer[Symbol.species];
13
+ const TRAILER = Buffer.from([
14
+ 0,
15
+ 0,
16
+ 255,
17
+ 255
18
+ ]);
19
+ const kPerMessageDeflate = Symbol("permessage-deflate");
20
+ const kTotalLength = Symbol("total-length");
21
+ const kCallback = Symbol("callback");
22
+ const kBuffers = Symbol("buffers");
23
+ const kError = Symbol("error");
24
+ let zlibLimiter;
25
+ /**
26
+ * permessage-deflate implementation.
27
+ */
28
+ var PerMessageDeflate = class {
29
+ /**
30
+ * Creates a PerMessageDeflate instance.
31
+ *
32
+ * @param {Object} [options] Configuration options
33
+ * @param {(Boolean|Number)} [options.clientMaxWindowBits] Advertise support
34
+ * for, or request, a custom client window size
35
+ * @param {Boolean} [options.clientNoContextTakeover=false] Advertise/
36
+ * acknowledge disabling of client context takeover
37
+ * @param {Number} [options.concurrencyLimit=10] The number of concurrent
38
+ * calls to zlib
39
+ * @param {(Boolean|Number)} [options.serverMaxWindowBits] Request/confirm the
40
+ * use of a custom server window size
41
+ * @param {Boolean} [options.serverNoContextTakeover=false] Request/accept
42
+ * disabling of server context takeover
43
+ * @param {Number} [options.threshold=1024] Size (in bytes) below which
44
+ * messages should not be compressed if context takeover is disabled
45
+ * @param {Object} [options.zlibDeflateOptions] Options to pass to zlib on
46
+ * deflate
47
+ * @param {Object} [options.zlibInflateOptions] Options to pass to zlib on
48
+ * inflate
49
+ * @param {Boolean} [isServer=false] Create the instance in either server or
50
+ * client mode
51
+ * @param {Number} [maxPayload=0] The maximum allowed message length
52
+ */
53
+ constructor(options, isServer, maxPayload) {
54
+ this._maxPayload = maxPayload | 0;
55
+ this._options = options || {};
56
+ this._threshold = this._options.threshold !== void 0 ? this._options.threshold : 1024;
57
+ this._isServer = !!isServer;
58
+ this._deflate = null;
59
+ this._inflate = null;
60
+ this.params = null;
61
+ if (!zlibLimiter) zlibLimiter = new Limiter(this._options.concurrencyLimit !== void 0 ? this._options.concurrencyLimit : 10);
62
+ }
63
+ /**
64
+ * @type {String}
65
+ */
66
+ static get extensionName() {
67
+ return "permessage-deflate";
68
+ }
69
+ /**
70
+ * Create an extension negotiation offer.
71
+ *
72
+ * @return {Object} Extension parameters
73
+ * @public
74
+ */
75
+ offer() {
76
+ const params = {};
77
+ if (this._options.serverNoContextTakeover) params.server_no_context_takeover = true;
78
+ if (this._options.clientNoContextTakeover) params.client_no_context_takeover = true;
79
+ if (this._options.serverMaxWindowBits) params.server_max_window_bits = this._options.serverMaxWindowBits;
80
+ if (this._options.clientMaxWindowBits) params.client_max_window_bits = this._options.clientMaxWindowBits;
81
+ else if (this._options.clientMaxWindowBits == null) params.client_max_window_bits = true;
82
+ return params;
83
+ }
84
+ /**
85
+ * Accept an extension negotiation offer/response.
86
+ *
87
+ * @param {Array} configurations The extension negotiation offers/reponse
88
+ * @return {Object} Accepted configuration
89
+ * @public
90
+ */
91
+ accept(configurations) {
92
+ configurations = this.normalizeParams(configurations);
93
+ this.params = this._isServer ? this.acceptAsServer(configurations) : this.acceptAsClient(configurations);
94
+ return this.params;
95
+ }
96
+ /**
97
+ * Releases all resources used by the extension.
98
+ *
99
+ * @public
100
+ */
101
+ cleanup() {
102
+ if (this._inflate) {
103
+ this._inflate.close();
104
+ this._inflate = null;
105
+ }
106
+ if (this._deflate) {
107
+ const callback = this._deflate[kCallback];
108
+ this._deflate.close();
109
+ this._deflate = null;
110
+ if (callback) callback(/* @__PURE__ */ new Error("The deflate stream was closed while data was being processed"));
111
+ }
112
+ }
113
+ /**
114
+ * Accept an extension negotiation offer.
115
+ *
116
+ * @param {Array} offers The extension negotiation offers
117
+ * @return {Object} Accepted configuration
118
+ * @private
119
+ */
120
+ acceptAsServer(offers) {
121
+ const opts = this._options;
122
+ const accepted = offers.find((params) => {
123
+ 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) return false;
124
+ return true;
125
+ });
126
+ if (!accepted) throw new Error("None of the extension offers can be accepted");
127
+ if (opts.serverNoContextTakeover) accepted.server_no_context_takeover = true;
128
+ if (opts.clientNoContextTakeover) accepted.client_no_context_takeover = true;
129
+ if (typeof opts.serverMaxWindowBits === "number") accepted.server_max_window_bits = opts.serverMaxWindowBits;
130
+ if (typeof opts.clientMaxWindowBits === "number") accepted.client_max_window_bits = opts.clientMaxWindowBits;
131
+ else if (accepted.client_max_window_bits === true || opts.clientMaxWindowBits === false) delete accepted.client_max_window_bits;
132
+ return accepted;
133
+ }
134
+ /**
135
+ * Accept the extension negotiation response.
136
+ *
137
+ * @param {Array} response The extension negotiation response
138
+ * @return {Object} Accepted configuration
139
+ * @private
140
+ */
141
+ acceptAsClient(response) {
142
+ const params = response[0];
143
+ if (this._options.clientNoContextTakeover === false && params.client_no_context_takeover) throw new Error("Unexpected parameter \"client_no_context_takeover\"");
144
+ if (!params.client_max_window_bits) {
145
+ if (typeof this._options.clientMaxWindowBits === "number") params.client_max_window_bits = this._options.clientMaxWindowBits;
146
+ } else if (this._options.clientMaxWindowBits === false || typeof this._options.clientMaxWindowBits === "number" && params.client_max_window_bits > this._options.clientMaxWindowBits) throw new Error("Unexpected or invalid parameter \"client_max_window_bits\"");
147
+ return params;
148
+ }
149
+ /**
150
+ * Normalize parameters.
151
+ *
152
+ * @param {Array} configurations The extension negotiation offers/reponse
153
+ * @return {Array} The offers/response with normalized parameters
154
+ * @private
155
+ */
156
+ normalizeParams(configurations) {
157
+ configurations.forEach((params) => {
158
+ Object.keys(params).forEach((key) => {
159
+ let value = params[key];
160
+ if (value.length > 1) throw new Error(`Parameter "${key}" must have only a single value`);
161
+ value = value[0];
162
+ if (key === "client_max_window_bits") {
163
+ if (value !== true) {
164
+ const num = +value;
165
+ if (!Number.isInteger(num) || num < 8 || num > 15) throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
166
+ value = num;
167
+ } else if (!this._isServer) throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
168
+ } else if (key === "server_max_window_bits") {
169
+ const num = +value;
170
+ if (!Number.isInteger(num) || num < 8 || num > 15) throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
171
+ value = num;
172
+ } else if (key === "client_no_context_takeover" || key === "server_no_context_takeover") {
173
+ if (value !== true) throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
174
+ } else throw new Error(`Unknown parameter "${key}"`);
175
+ params[key] = value;
176
+ });
177
+ });
178
+ return configurations;
179
+ }
180
+ /**
181
+ * Decompress data. Concurrency limited.
182
+ *
183
+ * @param {Buffer} data Compressed data
184
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
185
+ * @param {Function} callback Callback
186
+ * @public
187
+ */
188
+ decompress(data, fin, callback) {
189
+ zlibLimiter.add((done) => {
190
+ this._decompress(data, fin, (err, result) => {
191
+ done();
192
+ callback(err, result);
193
+ });
194
+ });
195
+ }
196
+ /**
197
+ * Compress data. Concurrency limited.
198
+ *
199
+ * @param {(Buffer|String)} data Data to compress
200
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
201
+ * @param {Function} callback Callback
202
+ * @public
203
+ */
204
+ compress(data, fin, callback) {
205
+ zlibLimiter.add((done) => {
206
+ this._compress(data, fin, (err, result) => {
207
+ done();
208
+ callback(err, result);
209
+ });
210
+ });
211
+ }
212
+ /**
213
+ * Decompress data.
214
+ *
215
+ * @param {Buffer} data Compressed data
216
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
217
+ * @param {Function} callback Callback
218
+ * @private
219
+ */
220
+ _decompress(data, fin, callback) {
221
+ const endpoint = this._isServer ? "client" : "server";
222
+ if (!this._inflate) {
223
+ const key = `${endpoint}_max_window_bits`;
224
+ const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
225
+ this._inflate = zlib.createInflateRaw({
226
+ ...this._options.zlibInflateOptions,
227
+ windowBits
228
+ });
229
+ this._inflate[kPerMessageDeflate] = this;
230
+ this._inflate[kTotalLength] = 0;
231
+ this._inflate[kBuffers] = [];
232
+ this._inflate.on("error", inflateOnError);
233
+ this._inflate.on("data", inflateOnData);
234
+ }
235
+ this._inflate[kCallback] = callback;
236
+ this._inflate.write(data);
237
+ if (fin) this._inflate.write(TRAILER);
238
+ this._inflate.flush(() => {
239
+ const err = this._inflate[kError];
240
+ if (err) {
241
+ this._inflate.close();
242
+ this._inflate = null;
243
+ callback(err);
244
+ return;
245
+ }
246
+ const data$1 = bufferUtil.concat(this._inflate[kBuffers], this._inflate[kTotalLength]);
247
+ if (this._inflate._readableState.endEmitted) {
248
+ this._inflate.close();
249
+ this._inflate = null;
250
+ } else {
251
+ this._inflate[kTotalLength] = 0;
252
+ this._inflate[kBuffers] = [];
253
+ if (fin && this.params[`${endpoint}_no_context_takeover`]) this._inflate.reset();
254
+ }
255
+ callback(null, data$1);
256
+ });
257
+ }
258
+ /**
259
+ * Compress data.
260
+ *
261
+ * @param {(Buffer|String)} data Data to compress
262
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
263
+ * @param {Function} callback Callback
264
+ * @private
265
+ */
266
+ _compress(data, fin, callback) {
267
+ const endpoint = this._isServer ? "server" : "client";
268
+ if (!this._deflate) {
269
+ const key = `${endpoint}_max_window_bits`;
270
+ const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
271
+ this._deflate = zlib.createDeflateRaw({
272
+ ...this._options.zlibDeflateOptions,
273
+ windowBits
274
+ });
275
+ this._deflate[kTotalLength] = 0;
276
+ this._deflate[kBuffers] = [];
277
+ this._deflate.on("data", deflateOnData);
278
+ }
279
+ this._deflate[kCallback] = callback;
280
+ this._deflate.write(data);
281
+ this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
282
+ if (!this._deflate) return;
283
+ let data$1 = bufferUtil.concat(this._deflate[kBuffers], this._deflate[kTotalLength]);
284
+ if (fin) data$1 = new FastBuffer(data$1.buffer, data$1.byteOffset, data$1.length - 4);
285
+ this._deflate[kCallback] = null;
286
+ this._deflate[kTotalLength] = 0;
287
+ this._deflate[kBuffers] = [];
288
+ if (fin && this.params[`${endpoint}_no_context_takeover`]) this._deflate.reset();
289
+ callback(null, data$1);
290
+ });
291
+ }
292
+ };
293
+ module.exports = PerMessageDeflate;
294
+ /**
295
+ * The listener of the `zlib.DeflateRaw` stream `'data'` event.
296
+ *
297
+ * @param {Buffer} chunk A chunk of data
298
+ * @private
299
+ */
300
+ function deflateOnData(chunk) {
301
+ this[kBuffers].push(chunk);
302
+ this[kTotalLength] += chunk.length;
303
+ }
304
+ /**
305
+ * The listener of the `zlib.InflateRaw` stream `'data'` event.
306
+ *
307
+ * @param {Buffer} chunk A chunk of data
308
+ * @private
309
+ */
310
+ function inflateOnData(chunk) {
311
+ this[kTotalLength] += chunk.length;
312
+ if (this[kPerMessageDeflate]._maxPayload < 1 || this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload) {
313
+ this[kBuffers].push(chunk);
314
+ return;
315
+ }
316
+ this[kError] = /* @__PURE__ */ new RangeError("Max payload size exceeded");
317
+ this[kError].code = "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH";
318
+ this[kError][kStatusCode] = 1009;
319
+ this.removeListener("data", inflateOnData);
320
+ this.reset();
321
+ }
322
+ /**
323
+ * The listener of the `zlib.InflateRaw` stream `'error'` event.
324
+ *
325
+ * @param {Error} err The emitted error
326
+ * @private
327
+ */
328
+ function inflateOnError(err) {
329
+ this[kPerMessageDeflate]._inflate = null;
330
+ if (this[kError]) {
331
+ this[kCallback](this[kError]);
332
+ return;
333
+ }
334
+ err[kStatusCode] = 1007;
335
+ this[kCallback](err);
336
+ }
337
+ }));
338
+
339
+ //#endregion
340
+ export default require_permessage_deflate();
341
+
342
+ export { require_permessage_deflate };