@teammy/server 0.2.9 → 0.2.10

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 (117) hide show
  1. package/dist/main.js +2901 -1271
  2. package/dist/web/assets/Assistant-C9Zo5FN_.js +1 -0
  3. package/dist/web/assets/Computers-DNIWiHu4.js +5 -0
  4. package/dist/web/assets/Computers-XUdWIkZr.css +1 -0
  5. package/dist/web/assets/{Conversation-Dc460fhC.css → Conversation-BVNmvuHR.css} +1 -1
  6. package/dist/web/assets/Conversation-DiVjLVVt.js +1 -0
  7. package/dist/web/assets/Dashboard-C6M9c0SB.js +1 -0
  8. package/dist/web/assets/{Dashboard-wDiUg0LB.css → Dashboard-ChX6TZDn.css} +1 -1
  9. package/dist/web/assets/Dropdown-BnYLBw2s.js +55 -0
  10. package/dist/web/assets/Files-CQcAEYH9.js +1 -0
  11. package/dist/web/assets/{Help-G99-LK4-.js → Help-CDOqVRjJ.js} +131 -33
  12. package/dist/web/assets/HtmlPreview-BzvYKdju.js +1 -0
  13. package/dist/web/assets/{Markdown-BgEXVy4-.js → Markdown-zJQlHcvy.js} +4 -4
  14. package/dist/web/assets/MessageComposer-CBI6RiJq.js +1 -0
  15. package/dist/web/assets/ResourceLibrary-CEFCe7QW.js +6 -0
  16. package/dist/web/assets/TerminalPane-BrSy-0jI.css +1 -0
  17. package/dist/web/assets/TerminalPane-GU69G9Ak.js +22 -0
  18. package/dist/web/assets/WorkspaceTree-BhDZe1go.js +1 -0
  19. package/dist/web/assets/file-links-V3R--z0b.js +1 -0
  20. package/dist/web/assets/index-D9m13C7l.js +12 -0
  21. package/dist/web/assets/index-qX1GRw9I.css +1 -0
  22. package/dist/web/downloads/teammy-inbox-skill.zip +0 -0
  23. package/dist/web/downloads/teammy-skill.zip +0 -0
  24. package/dist/web/index.html +3 -2
  25. package/node_modules/@fastify/websocket/.gitattributes +2 -0
  26. package/node_modules/@fastify/websocket/.github/dependabot.yml +53 -0
  27. package/node_modules/@fastify/websocket/.github/workflows/ci.yml +33 -0
  28. package/node_modules/@fastify/websocket/.github/workflows/lock-threads.yml +19 -0
  29. package/node_modules/@fastify/websocket/.github/workflows/release.yml +24 -0
  30. package/node_modules/@fastify/websocket/LICENSE +21 -0
  31. package/node_modules/@fastify/websocket/README.md +393 -0
  32. package/node_modules/@fastify/websocket/eslint.config.js +6 -0
  33. package/node_modules/@fastify/websocket/index.js +276 -0
  34. package/node_modules/@fastify/websocket/package.json +79 -0
  35. package/node_modules/@fastify/websocket/test/base.test.js +785 -0
  36. package/node_modules/@fastify/websocket/test/hooks.test.js +414 -0
  37. package/node_modules/@fastify/websocket/test/inject.test.js +174 -0
  38. package/node_modules/@fastify/websocket/test/router.test.js +890 -0
  39. package/node_modules/@fastify/websocket/tsconfig.json +3 -0
  40. package/node_modules/@fastify/websocket/types/index.d.ts +128 -0
  41. package/node_modules/@fastify/websocket/types/index.tst.ts +261 -0
  42. package/node_modules/duplexify/.travis.yml +9 -0
  43. package/node_modules/duplexify/LICENSE +21 -0
  44. package/node_modules/duplexify/README.md +97 -0
  45. package/node_modules/duplexify/example.js +21 -0
  46. package/node_modules/duplexify/index.js +238 -0
  47. package/node_modules/duplexify/package.json +39 -0
  48. package/node_modules/duplexify/test.js +339 -0
  49. package/node_modules/end-of-stream/LICENSE +21 -0
  50. package/node_modules/end-of-stream/README.md +54 -0
  51. package/node_modules/end-of-stream/index.js +96 -0
  52. package/node_modules/end-of-stream/package.json +37 -0
  53. package/node_modules/once/LICENSE +15 -0
  54. package/node_modules/once/README.md +79 -0
  55. package/node_modules/once/once.js +42 -0
  56. package/node_modules/once/package.json +33 -0
  57. package/node_modules/readable-stream/CONTRIBUTING.md +38 -0
  58. package/node_modules/readable-stream/GOVERNANCE.md +136 -0
  59. package/node_modules/readable-stream/LICENSE +47 -0
  60. package/node_modules/readable-stream/README.md +106 -0
  61. package/node_modules/readable-stream/errors-browser.js +127 -0
  62. package/node_modules/readable-stream/errors.js +116 -0
  63. package/node_modules/readable-stream/experimentalWarning.js +17 -0
  64. package/node_modules/readable-stream/lib/_stream_duplex.js +126 -0
  65. package/node_modules/readable-stream/lib/_stream_passthrough.js +37 -0
  66. package/node_modules/readable-stream/lib/_stream_readable.js +1027 -0
  67. package/node_modules/readable-stream/lib/_stream_transform.js +190 -0
  68. package/node_modules/readable-stream/lib/_stream_writable.js +641 -0
  69. package/node_modules/readable-stream/lib/internal/streams/async_iterator.js +180 -0
  70. package/node_modules/readable-stream/lib/internal/streams/buffer_list.js +183 -0
  71. package/node_modules/readable-stream/lib/internal/streams/destroy.js +96 -0
  72. package/node_modules/readable-stream/lib/internal/streams/end-of-stream.js +86 -0
  73. package/node_modules/readable-stream/lib/internal/streams/from-browser.js +3 -0
  74. package/node_modules/readable-stream/lib/internal/streams/from.js +52 -0
  75. package/node_modules/readable-stream/lib/internal/streams/pipeline.js +86 -0
  76. package/node_modules/readable-stream/lib/internal/streams/state.js +22 -0
  77. package/node_modules/readable-stream/lib/internal/streams/stream-browser.js +1 -0
  78. package/node_modules/readable-stream/lib/internal/streams/stream.js +1 -0
  79. package/node_modules/readable-stream/package.json +68 -0
  80. package/node_modules/readable-stream/readable-browser.js +9 -0
  81. package/node_modules/readable-stream/readable.js +16 -0
  82. package/node_modules/stream-shift/.github/workflows/test.yml +23 -0
  83. package/node_modules/stream-shift/LICENSE +21 -0
  84. package/node_modules/stream-shift/README.md +25 -0
  85. package/node_modules/stream-shift/index.js +21 -0
  86. package/node_modules/stream-shift/package.json +25 -0
  87. package/node_modules/stream-shift/test.js +48 -0
  88. package/node_modules/string_decoder/LICENSE +48 -0
  89. package/node_modules/string_decoder/README.md +47 -0
  90. package/node_modules/string_decoder/lib/string_decoder.js +296 -0
  91. package/node_modules/string_decoder/package.json +34 -0
  92. package/node_modules/util-deprecate/History.md +16 -0
  93. package/node_modules/util-deprecate/LICENSE +24 -0
  94. package/node_modules/util-deprecate/README.md +53 -0
  95. package/node_modules/util-deprecate/browser.js +67 -0
  96. package/node_modules/util-deprecate/node.js +6 -0
  97. package/node_modules/util-deprecate/package.json +27 -0
  98. package/node_modules/wrappy/LICENSE +15 -0
  99. package/node_modules/wrappy/README.md +36 -0
  100. package/node_modules/wrappy/package.json +29 -0
  101. package/node_modules/wrappy/wrappy.js +33 -0
  102. package/package.json +15 -2
  103. package/dist/web/assets/Assistant-CkKCs2G4.js +0 -1
  104. package/dist/web/assets/Computers-B9wEqpMc.js +0 -4
  105. package/dist/web/assets/Computers-DBnXVk7q.css +0 -1
  106. package/dist/web/assets/Conversation-DK5-Q1RB.js +0 -1
  107. package/dist/web/assets/Dashboard-B2HGjI4a.js +0 -1
  108. package/dist/web/assets/Files-Du-7z96D.js +0 -1
  109. package/dist/web/assets/HtmlPreview-Bi3u6-l3.js +0 -1
  110. package/dist/web/assets/MessageComposer-6eJAo_e7.js +0 -1
  111. package/dist/web/assets/PillControl-BRPhbHQm.js +0 -1
  112. package/dist/web/assets/PillControl-CqVA7kIQ.css +0 -1
  113. package/dist/web/assets/ResourceLibrary-DJ9cxDoc.js +0 -6
  114. package/dist/web/assets/WorkspaceTree-DUFGMLRi.js +0 -1
  115. package/dist/web/assets/file-links-Dl1S0Tt0.js +0 -1
  116. package/dist/web/assets/index-C4EXuXVY.css +0 -1
  117. package/dist/web/assets/index-xjf37um4.js +0 -66
@@ -0,0 +1,276 @@
1
+ 'use strict'
2
+
3
+ const { ServerResponse } = require('node:http')
4
+ const { PassThrough } = require('node:stream')
5
+ const { randomBytes } = require('node:crypto')
6
+ const fp = require('fastify-plugin')
7
+ const WebSocket = require('ws')
8
+ const Duplexify = require('duplexify')
9
+
10
+ const kWs = Symbol('ws-socket')
11
+ const kWsHead = Symbol('ws-head')
12
+ const statusCodeReg = /HTTP\/1.1 (\d+)/u
13
+
14
+ function fastifyWebsocket (fastify, opts, next) {
15
+ fastify.decorateRequest('ws', null)
16
+
17
+ let errorHandler = defaultErrorHandler
18
+ if (opts.errorHandler) {
19
+ if (typeof opts.errorHandler !== 'function') {
20
+ return next(new Error('invalid errorHandler function'))
21
+ }
22
+
23
+ errorHandler = opts.errorHandler
24
+ }
25
+
26
+ let preClose = defaultPreClose
27
+ if (opts?.preClose) {
28
+ if (typeof opts.preClose !== 'function') {
29
+ return next(new Error('invalid preClose function'))
30
+ }
31
+
32
+ preClose = opts.preClose
33
+ }
34
+
35
+ if (opts.options?.noServer) {
36
+ return next(new Error("fastify-websocket doesn't support the ws noServer option. If you want to create a websocket server detatched from fastify, use the ws library directly."))
37
+ }
38
+
39
+ const wssOptions = Object.assign({ noServer: true }, opts.options)
40
+
41
+ if (wssOptions.path) {
42
+ fastify.log.warn('ws server path option shouldn\'t be provided, use a route instead')
43
+ }
44
+
45
+ // We always handle upgrading ourselves in this library so that we can dispatch through the fastify stack before actually upgrading
46
+ // For this reason, we run the WebSocket.Server in noServer mode, and prevent the user from passing in a http.Server instance for it to attach to.
47
+ // Usually, we listen to the upgrade event of the `fastify.server`, but we do still support this server option by just listening to upgrades on it if passed.
48
+ const websocketListenServer = wssOptions.server || fastify.server
49
+ delete wssOptions.server
50
+
51
+ const wss = new WebSocket.Server(wssOptions)
52
+ fastify.decorate('websocketServer', wss)
53
+
54
+ // TODO: place upgrade context as options
55
+ async function injectWS (path = '/', upgradeContext = {}, options = {}) {
56
+ const server2Client = new PassThrough()
57
+ const client2Server = new PassThrough()
58
+
59
+ const serverStream = new Duplexify(server2Client, client2Server)
60
+ const clientStream = new Duplexify(client2Server, server2Client)
61
+
62
+ const ws = new WebSocket(null, undefined, { isServer: false })
63
+ const head = Buffer.from([])
64
+
65
+ let resolve, reject
66
+ const promise = new Promise((_resolve, _reject) => { resolve = _resolve; reject = _reject })
67
+
68
+ typeof options.onInit === 'function' && options.onInit(ws)
69
+
70
+ ws.on('open', () => {
71
+ typeof options.onOpen === 'function' && options.onOpen(ws)
72
+ clientStream.removeListener('data', onData)
73
+ resolve(ws)
74
+ })
75
+
76
+ const onData = (chunk) => {
77
+ if (chunk.toString().includes('HTTP/1.1 101 Switching Protocols')) {
78
+ ws._isServer = false
79
+ ws.setSocket(clientStream, head, { maxPayload: 0 })
80
+ } else {
81
+ clientStream.removeListener('data', onData)
82
+ const statusCode = Number(statusCodeReg.exec(chunk.toString())[1])
83
+ reject(new Error('Unexpected server response: ' + statusCode))
84
+ }
85
+ }
86
+
87
+ clientStream.on('data', onData)
88
+
89
+ const req = {
90
+ ...upgradeContext,
91
+ method: 'GET',
92
+ headers: {
93
+ ...upgradeContext.headers,
94
+ connection: 'upgrade',
95
+ upgrade: 'websocket',
96
+ 'sec-websocket-version': 13,
97
+ 'sec-websocket-key': randomBytes(16).toString('base64')
98
+ },
99
+ httpVersion: '1.1',
100
+ url: path,
101
+ [kWs]: serverStream,
102
+ [kWsHead]: head
103
+ }
104
+
105
+ websocketListenServer.emit('upgrade', req, req[kWs], req[kWsHead])
106
+
107
+ return promise
108
+ }
109
+
110
+ fastify.decorate('injectWS', injectWS)
111
+
112
+ function onUpgrade (rawRequest, socket, head) {
113
+ // Node removes its socket error listener before emitting 'upgrade'. Keep
114
+ // the socket guarded while Fastify runs hooks and routes the request.
115
+ socket.on('error', onUpgradeSocketError)
116
+
117
+ // Save a reference to the socket and then dispatch the request through the normal fastify router so that it will invoke hooks and then eventually a route handler that might upgrade the socket.
118
+ rawRequest[kWs] = socket
119
+ rawRequest[kWsHead] = head
120
+ const rawResponse = new ServerResponse(rawRequest)
121
+ try {
122
+ rawResponse.assignSocket(socket)
123
+ fastify.routing(rawRequest, rawResponse)
124
+ } catch (err) {
125
+ fastify.log.warn({ err }, 'websocket upgrade failed')
126
+ }
127
+ }
128
+ websocketListenServer.on('upgrade', onUpgrade)
129
+
130
+ const handleUpgrade = (rawRequest, callback) => {
131
+ // `ws` installs its own socket error listener synchronously in
132
+ // handleUpgrade, so it is safe to hand error ownership over here.
133
+ rawRequest[kWs].removeListener('error', onUpgradeSocketError)
134
+ wss.handleUpgrade(rawRequest, rawRequest[kWs], rawRequest[kWsHead], (socket) => {
135
+ wss.emit('connection', socket, rawRequest)
136
+
137
+ callback(socket)
138
+ })
139
+ }
140
+
141
+ function onUpgradeSocketError () {
142
+ this.destroy()
143
+ }
144
+
145
+ fastify.addHook('onRequest', (request, _reply, done) => { // this adds req.ws to the Request object
146
+ if (request.raw[kWs]) {
147
+ request.ws = true
148
+ } else {
149
+ request.ws = false
150
+ }
151
+ done()
152
+ })
153
+
154
+ fastify.addHook('onResponse', (request, _reply, done) => {
155
+ if (request.ws) {
156
+ request.raw[kWs].destroy()
157
+ }
158
+ done()
159
+ })
160
+
161
+ fastify.addHook('onRoute', routeOptions => {
162
+ let isWebsocketRoute = false
163
+ let wsHandler = routeOptions.wsHandler
164
+ let handler = routeOptions.handler
165
+
166
+ if (routeOptions.websocket || routeOptions.wsHandler) {
167
+ // `method` can also be an array, e.g. ['GET', 'HEAD']
168
+ const methods = Array.isArray(routeOptions.method) ? routeOptions.method : [routeOptions.method]
169
+ if (methods.every(method => method === 'HEAD')) {
170
+ // A HEAD request can't be upgraded. This also covers the HEAD route that fastify adds for a GET route,
171
+ // where `handler` is still the websocket handler.
172
+ if (routeOptions.websocket) {
173
+ routeOptions.handler = function (_, reply) {
174
+ reply.code(404).send()
175
+ }
176
+ }
177
+ return
178
+ } else if (methods.some(method => method !== 'GET' && method !== 'HEAD')) {
179
+ throw new Error('websocket handler can only be declared in GET method')
180
+ }
181
+
182
+ isWebsocketRoute = true
183
+
184
+ if (routeOptions.websocket) {
185
+ if (!routeOptions.schema) {
186
+ routeOptions.schema = {}
187
+ }
188
+ routeOptions.schema.hide = true
189
+
190
+ wsHandler = routeOptions.handler
191
+ handler = function (_, reply) {
192
+ reply.code(404).send()
193
+ }
194
+ }
195
+
196
+ if (typeof wsHandler !== 'function') {
197
+ throw new TypeError('invalid wsHandler function')
198
+ }
199
+ }
200
+
201
+ // we always override the route handler so we can close websocket connections to routes to handlers that don't support websocket connections
202
+ // This is not an arrow function to fetch the encapsulated this
203
+ routeOptions.handler = function (request, reply) {
204
+ // within the route handler, we check if there has been a connection upgrade by looking at request.raw[kWs]. we need to dispatch the normal HTTP handler if not, and hijack to dispatch the websocket handler if so
205
+ if (request.raw[kWs]) {
206
+ reply.hijack()
207
+ handleUpgrade(request.raw, socket => {
208
+ // Errors emitted on the established socket (e.g. an unclean client
209
+ // disconnect) are routed through the errorHandler so applications
210
+ // can classify them, and so the socket always has an 'error'
211
+ // listener attached.
212
+ socket.on('error', (error) => {
213
+ errorHandler.call(this, error, socket, request, reply)
214
+ })
215
+
216
+ let result
217
+ try {
218
+ if (isWebsocketRoute) {
219
+ result = wsHandler.call(this, socket, request)
220
+ } else {
221
+ result = noHandle.call(this, socket, request)
222
+ }
223
+ } catch (err) {
224
+ return errorHandler.call(this, err, socket, request, reply)
225
+ }
226
+
227
+ if (result && typeof result.catch === 'function') {
228
+ result.catch(err => errorHandler.call(this, err, socket, request, reply))
229
+ }
230
+ })
231
+ } else {
232
+ return handler.call(this, request, reply)
233
+ }
234
+ }
235
+ })
236
+
237
+ // Always remove the upgrade listener, even with a custom preClose, as it
238
+ // can't be reached from outside the plugin.
239
+ fastify.addHook('preClose', function removeUpgradeListener (done) {
240
+ websocketListenServer.removeListener('upgrade', onUpgrade)
241
+ done()
242
+ })
243
+ fastify.addHook('preClose', preClose)
244
+
245
+ function defaultPreClose (done) {
246
+ const server = this.websocketServer
247
+ if (server.clients) {
248
+ for (const client of server.clients) {
249
+ client.close()
250
+ }
251
+ }
252
+
253
+ server.close(done)
254
+
255
+ done()
256
+ }
257
+
258
+ function noHandle (socket, rawRequest) {
259
+ this.log.info({ path: rawRequest.url }, 'closed incoming websocket connection for path with no websocket handler')
260
+ socket.close()
261
+ }
262
+
263
+ function defaultErrorHandler (error, socket, request) {
264
+ request.log.error(error)
265
+ socket.terminate()
266
+ }
267
+
268
+ next()
269
+ }
270
+
271
+ module.exports = fp(fastifyWebsocket, {
272
+ fastify: '5.x',
273
+ name: '@fastify/websocket'
274
+ })
275
+ module.exports.default = fastifyWebsocket
276
+ module.exports.fastifyWebsocket = fastifyWebsocket
@@ -0,0 +1,79 @@
1
+ {
2
+ "name": "@fastify/websocket",
3
+ "version": "11.3.7",
4
+ "description": "basic websocket support for fastify",
5
+ "main": "index.js",
6
+ "type": "commonjs",
7
+ "types": "types/index.d.ts",
8
+ "scripts": {
9
+ "lint": "eslint",
10
+ "lint:fix": "eslint --fix",
11
+ "test": "npm run test:unit && npm run test:typescript",
12
+ "test:unit": "c8 --100 node --test",
13
+ "test:typescript": "tstyche"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/fastify/fastify-websocket.git"
18
+ },
19
+ "keywords": [
20
+ "fastify",
21
+ "websocket"
22
+ ],
23
+ "author": "Matteo Collina <hello@matteocollina.com>",
24
+ "contributors": [
25
+ {
26
+ "name": "Harry Brundage",
27
+ "email": "harry.brundage@gmail.com"
28
+ },
29
+ {
30
+ "name": "Manuel Spigolon",
31
+ "email": "behemoth89@gmail.com"
32
+ },
33
+ {
34
+ "name": "Aras Abbasi",
35
+ "email": "aras.abbasi@gmail.com"
36
+ },
37
+ {
38
+ "name": "Frazer Smith",
39
+ "email": "frazer.dev@icloud.com",
40
+ "url": "https://github.com/fdawgs"
41
+ }
42
+ ],
43
+ "license": "MIT",
44
+ "bugs": {
45
+ "url": "https://github.com/fastify/fastify-websocket/issues"
46
+ },
47
+ "homepage": "https://github.com/fastify/fastify-websocket#readme",
48
+ "funding": [
49
+ {
50
+ "type": "github",
51
+ "url": "https://github.com/sponsors/fastify"
52
+ },
53
+ {
54
+ "type": "opencollective",
55
+ "url": "https://opencollective.com/fastify"
56
+ }
57
+ ],
58
+ "devDependencies": {
59
+ "@fastify/type-provider-typebox": "^6.1.0",
60
+ "@types/node": "^26.0.1",
61
+ "@types/ws": "^8.5.10",
62
+ "c8": "^12.0.0",
63
+ "eslint": "^9.39.2",
64
+ "fastify": "^5.0.0",
65
+ "fastify-tsconfig": "^3.0.0",
66
+ "neostandard": "^0.13.0",
67
+ "split2": "^4.2.0",
68
+ "tstyche": "^7.0.0",
69
+ "typebox": "^1.1.33"
70
+ },
71
+ "dependencies": {
72
+ "duplexify": "^4.1.3",
73
+ "fastify-plugin": "^6.0.0",
74
+ "ws": "^8.16.0"
75
+ },
76
+ "publishConfig": {
77
+ "access": "public"
78
+ }
79
+ }