@budibase/server 2.5.6-alpha.9 → 2.5.7
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/builder/assets/index.7f9a008b.css +6 -0
- package/builder/assets/index.f02eef32.js +1817 -0
- package/builder/index.html +2 -2
- package/dist/api/controllers/automation.js +7 -13
- package/dist/api/controllers/plugin/index.js +37 -6
- package/dist/api/controllers/table/utils.js +1 -2
- package/dist/api/controllers/user.js +83 -1
- package/dist/api/routes/index.js +0 -2
- package/dist/api/routes/user.js +1 -0
- package/dist/app.js +13 -4
- package/dist/automations/actions.js +6 -32
- package/dist/automations/index.js +2 -3
- package/dist/automations/steps/bash.js +6 -6
- package/dist/automations/steps/createRow.js +11 -11
- package/dist/automations/steps/delay.js +3 -3
- package/dist/automations/steps/deleteRow.js +8 -8
- package/dist/automations/steps/discord.js +8 -8
- package/dist/automations/steps/executeQuery.js +9 -9
- package/dist/automations/steps/executeScript.js +6 -6
- package/dist/automations/steps/filter.js +6 -6
- package/dist/automations/steps/integromat.js +10 -10
- package/dist/automations/steps/loop.js +9 -9
- package/dist/automations/steps/outgoingWebhook.js +10 -10
- package/dist/automations/steps/queryRows.js +14 -14
- package/dist/automations/steps/sendSmtpEmail.js +9 -9
- package/dist/automations/steps/serverLog.js +4 -4
- package/dist/automations/steps/slack.js +6 -6
- package/dist/automations/steps/updateRow.js +11 -11
- package/dist/automations/steps/zapier.js +9 -9
- package/dist/automations/triggerInfo/app.js +5 -5
- package/dist/automations/triggerInfo/cron.js +4 -4
- package/dist/automations/triggerInfo/rowDeleted.js +5 -5
- package/dist/automations/triggerInfo/rowSaved.js +7 -7
- package/dist/automations/triggerInfo/rowUpdated.js +7 -7
- package/dist/automations/triggerInfo/webhook.js +6 -6
- package/dist/elasticApm.js +14 -0
- package/dist/environment.js +1 -0
- package/dist/events/index.js +0 -3
- package/dist/integrations/index.js +3 -3
- package/dist/integrations/microsoftSqlServer.js +2 -5
- package/dist/integrations/mysql.js +3 -5
- package/dist/integrations/postgres.js +5 -7
- package/dist/integrations/redis.js +0 -7
- package/dist/integrations/rest.js +0 -4
- package/dist/migrations/functions/usageQuotas/syncApps.js +1 -1
- package/dist/migrations/functions/usageQuotas/syncRows.js +2 -1
- package/dist/package.json +15 -15
- package/dist/sdk/app/applications/sync.js +23 -117
- package/dist/sdk/index.js +0 -2
- package/dist/sdk/users/utils.js +4 -21
- package/dist/startup.js +28 -31
- package/dist/threads/automation.js +5 -16
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utilities/fileSystem/plugin.js +23 -33
- package/dist/utilities/global.js +12 -17
- package/dist/watch.js +2 -2
- package/dist/websocket.js +22 -0
- package/jest.config.ts +3 -3
- package/nodemon.json +3 -7
- package/package.json +16 -16
- package/scripts/dev/manage.js +0 -2
- package/scripts/integrations/mssql/data/entrypoint.sh +0 -1
- package/scripts/integrations/mssql/data/setup.sql +17 -17
- package/scripts/integrations/mysql/init.sql +1 -1
- package/scripts/integrations/postgres/init.sql +0 -1
- package/scripts/likeCypress.ts +35 -0
- package/src/api/controllers/automation.ts +6 -12
- package/src/api/controllers/plugin/index.ts +45 -8
- package/src/api/controllers/row/internal.ts +10 -9
- package/src/api/controllers/row/utils.ts +2 -2
- package/src/api/controllers/table/utils.ts +1 -2
- package/src/api/controllers/user.ts +96 -10
- package/src/api/routes/index.ts +0 -2
- package/src/api/routes/tests/automation.spec.js +4 -7
- package/src/api/routes/tests/user.spec.js +37 -48
- package/src/api/routes/user.ts +5 -0
- package/src/app.ts +15 -4
- package/src/automations/actions.ts +24 -56
- package/src/automations/index.ts +1 -1
- package/src/automations/steps/bash.ts +7 -10
- package/src/automations/steps/createRow.ts +12 -15
- package/src/automations/steps/delay.ts +4 -6
- package/src/automations/steps/deleteRow.ts +9 -12
- package/src/automations/steps/discord.ts +8 -10
- package/src/automations/steps/executeQuery.ts +10 -13
- package/src/automations/steps/executeScript.ts +7 -10
- package/src/automations/steps/filter.ts +6 -8
- package/src/automations/steps/integromat.ts +10 -12
- package/src/automations/steps/loop.ts +10 -16
- package/src/automations/steps/outgoingWebhook.ts +11 -14
- package/src/automations/steps/queryRows.ts +15 -18
- package/src/automations/steps/sendSmtpEmail.ts +9 -11
- package/src/automations/steps/serverLog.ts +4 -6
- package/src/automations/steps/slack.ts +6 -8
- package/src/automations/steps/updateRow.ts +12 -15
- package/src/automations/steps/zapier.ts +9 -11
- package/src/automations/tests/utilities/index.ts +2 -2
- package/src/automations/triggerInfo/app.ts +5 -8
- package/src/automations/triggerInfo/cron.ts +4 -7
- package/src/automations/triggerInfo/rowDeleted.ts +5 -8
- package/src/automations/triggerInfo/rowSaved.ts +7 -10
- package/src/automations/triggerInfo/rowUpdated.ts +7 -10
- package/src/automations/triggerInfo/webhook.ts +6 -9
- package/src/elasticApm.ts +10 -0
- package/src/environment.ts +1 -0
- package/src/events/index.ts +0 -1
- package/src/integrations/index.ts +3 -3
- package/src/integrations/microsoftSqlServer.ts +2 -5
- package/src/integrations/mysql.ts +3 -5
- package/src/integrations/postgres.ts +5 -7
- package/src/integrations/redis.ts +0 -8
- package/src/integrations/rest.ts +0 -3
- package/src/migrations/functions/usageQuotas/syncApps.ts +1 -1
- package/src/migrations/functions/usageQuotas/syncRows.ts +3 -2
- package/src/migrations/functions/usageQuotas/tests/syncRows.spec.ts +2 -2
- package/src/sdk/app/applications/sync.ts +22 -129
- package/src/sdk/index.ts +0 -2
- package/src/sdk/users/tests/utils.spec.ts +32 -1
- package/src/sdk/users/utils.ts +5 -23
- package/src/startup.ts +34 -36
- package/src/tests/jestEnv.ts +1 -0
- package/src/tests/jestSetup.ts +1 -0
- package/src/tests/logging.ts +34 -0
- package/src/tests/utilities/TestConfiguration.ts +0 -28
- package/src/tests/utilities/structures.ts +17 -25
- package/src/threads/automation.ts +6 -18
- package/src/utilities/fileSystem/plugin.ts +4 -13
- package/src/utilities/global.ts +16 -21
- package/src/watch.ts +2 -2
- package/src/websocket.ts +26 -0
- package/tsconfig.json +7 -1
- package/builder/assets/index.5c1a6913.js +0 -1776
- package/builder/assets/index.c0265b74.css +0 -6
- package/dist/api/controllers/ops.js +0 -40
- package/dist/api/routes/ops.js +0 -52
- package/dist/events/docUpdates/index.js +0 -17
- package/dist/events/docUpdates/processors.js +0 -18
- package/dist/events/docUpdates/syncUsers.js +0 -49
- package/dist/sdk/plugins/index.js +0 -27
- package/dist/sdk/plugins/plugins.js +0 -53
- package/dist/websockets/client.js +0 -14
- package/dist/websockets/grid.js +0 -60
- package/dist/websockets/index.js +0 -17
- package/dist/websockets/websocket.js +0 -78
- package/src/api/controllers/ops.ts +0 -32
- package/src/api/routes/ops.ts +0 -30
- package/src/events/docUpdates/index.ts +0 -1
- package/src/events/docUpdates/processors.ts +0 -14
- package/src/events/docUpdates/syncUsers.ts +0 -35
- package/src/sdk/app/applications/tests/sync.spec.ts +0 -137
- package/src/sdk/plugins/index.ts +0 -5
- package/src/sdk/plugins/plugins.ts +0 -41
- package/src/websockets/client.ts +0 -11
- package/src/websockets/grid.ts +0 -55
- package/src/websockets/index.ts +0 -14
- package/src/websockets/websocket.ts +0 -83
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import TestConfiguration from "../../../../tests/utilities/TestConfiguration"
|
|
2
|
-
import { events, context, roles, constants } from "@budibase/backend-core"
|
|
3
|
-
import { init } from "../../../../events"
|
|
4
|
-
import { rawUserMetadata } from "../../../users/utils"
|
|
5
|
-
import EventEmitter from "events"
|
|
6
|
-
import { UserGroup, UserMetadata, UserRoles, User } from "@budibase/types"
|
|
7
|
-
|
|
8
|
-
const config = new TestConfiguration()
|
|
9
|
-
let app, group: UserGroup, groupUser: User
|
|
10
|
-
const ROLE_ID = roles.BUILTIN_ROLE_IDS.BASIC
|
|
11
|
-
|
|
12
|
-
const emitter = new EventEmitter()
|
|
13
|
-
|
|
14
|
-
function updateCb(docId: string) {
|
|
15
|
-
const isGroup = docId.startsWith(constants.DocumentType.GROUP)
|
|
16
|
-
if (isGroup) {
|
|
17
|
-
emitter.emit("update-group")
|
|
18
|
-
} else {
|
|
19
|
-
emitter.emit("update-user")
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
init(updateCb)
|
|
24
|
-
|
|
25
|
-
function waitForUpdate(opts: { group?: boolean }) {
|
|
26
|
-
return new Promise<void>((resolve, reject) => {
|
|
27
|
-
const timeout = setTimeout(() => {
|
|
28
|
-
reject()
|
|
29
|
-
}, 5000)
|
|
30
|
-
const event = opts?.group ? "update-group" : "update-user"
|
|
31
|
-
emitter.on(event, () => {
|
|
32
|
-
clearTimeout(timeout)
|
|
33
|
-
resolve()
|
|
34
|
-
})
|
|
35
|
-
})
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
beforeAll(async () => {
|
|
39
|
-
app = await config.init("syncApp")
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
async function createUser(email: string, roles: UserRoles, builder?: boolean) {
|
|
43
|
-
const user = await config.createUser({
|
|
44
|
-
email,
|
|
45
|
-
roles,
|
|
46
|
-
builder: builder || false,
|
|
47
|
-
admin: false,
|
|
48
|
-
})
|
|
49
|
-
await context.doInContext(config.appId!, async () => {
|
|
50
|
-
await events.user.created(user)
|
|
51
|
-
})
|
|
52
|
-
return user
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
async function removeUserRole(user: User) {
|
|
56
|
-
const final = await config.globalUser({
|
|
57
|
-
...user,
|
|
58
|
-
id: user._id,
|
|
59
|
-
roles: {},
|
|
60
|
-
builder: false,
|
|
61
|
-
admin: false,
|
|
62
|
-
})
|
|
63
|
-
await context.doInContext(config.appId!, async () => {
|
|
64
|
-
await events.user.updated(final)
|
|
65
|
-
})
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
async function createGroupAndUser(email: string) {
|
|
69
|
-
groupUser = await config.createUser({
|
|
70
|
-
email,
|
|
71
|
-
roles: {},
|
|
72
|
-
builder: false,
|
|
73
|
-
admin: false,
|
|
74
|
-
})
|
|
75
|
-
group = await config.createGroup()
|
|
76
|
-
await config.addUserToGroup(group._id!, groupUser._id!)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
async function removeUserFromGroup() {
|
|
80
|
-
await config.removeUserFromGroup(group._id!, groupUser._id!)
|
|
81
|
-
return context.doInContext(config.appId!, async () => {
|
|
82
|
-
await events.user.updated(groupUser)
|
|
83
|
-
})
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
async function getUserMetadata(): Promise<UserMetadata[]> {
|
|
87
|
-
return context.doInContext(config.appId!, async () => {
|
|
88
|
-
return await rawUserMetadata()
|
|
89
|
-
})
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function buildRoles() {
|
|
93
|
-
return { [config.prodAppId!]: ROLE_ID }
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
describe("app user/group sync", () => {
|
|
97
|
-
const groupEmail = "test2@test.com",
|
|
98
|
-
normalEmail = "test@test.com"
|
|
99
|
-
async function checkEmail(
|
|
100
|
-
email: string,
|
|
101
|
-
opts?: { group?: boolean; notFound?: boolean }
|
|
102
|
-
) {
|
|
103
|
-
await waitForUpdate(opts || {})
|
|
104
|
-
const metadata = await getUserMetadata()
|
|
105
|
-
const found = metadata.find(data => data.email === email)
|
|
106
|
-
if (opts?.notFound) {
|
|
107
|
-
expect(found).toBeUndefined()
|
|
108
|
-
} else {
|
|
109
|
-
expect(found).toBeDefined()
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
it("should be able to sync a new user, add then remove", async () => {
|
|
114
|
-
const user = await createUser(normalEmail, buildRoles())
|
|
115
|
-
await checkEmail(normalEmail)
|
|
116
|
-
await removeUserRole(user)
|
|
117
|
-
await checkEmail(normalEmail, { notFound: true })
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
it("should be able to sync a group", async () => {
|
|
121
|
-
await createGroupAndUser(groupEmail)
|
|
122
|
-
await checkEmail(groupEmail, { group: true })
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
it("should be able to remove user from group", async () => {
|
|
126
|
-
if (!group) {
|
|
127
|
-
await createGroupAndUser(groupEmail)
|
|
128
|
-
}
|
|
129
|
-
await removeUserFromGroup()
|
|
130
|
-
await checkEmail(groupEmail, { notFound: true })
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
it("should be able to handle builder users", async () => {
|
|
134
|
-
await createUser("test3@test.com", {}, true)
|
|
135
|
-
await checkEmail("test3@test.com")
|
|
136
|
-
})
|
|
137
|
-
})
|
package/src/sdk/plugins/index.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { FileType, Plugin, PluginSource, PluginType } from "@budibase/types"
|
|
2
|
-
import {
|
|
3
|
-
db as dbCore,
|
|
4
|
-
objectStore,
|
|
5
|
-
plugins as pluginCore,
|
|
6
|
-
tenancy,
|
|
7
|
-
} from "@budibase/backend-core"
|
|
8
|
-
import { fileUpload } from "../../api/controllers/plugin/file"
|
|
9
|
-
import env from "../../environment"
|
|
10
|
-
import { clientAppSocket } from "../../websockets"
|
|
11
|
-
import { sdk as pro } from "@budibase/pro"
|
|
12
|
-
|
|
13
|
-
export async function fetch(type?: PluginType) {
|
|
14
|
-
const db = tenancy.getGlobalDB()
|
|
15
|
-
const response = await db.allDocs(
|
|
16
|
-
dbCore.getPluginParams(null, {
|
|
17
|
-
include_docs: true,
|
|
18
|
-
})
|
|
19
|
-
)
|
|
20
|
-
let plugins = response.rows.map((row: any) => row.doc) as Plugin[]
|
|
21
|
-
plugins = objectStore.enrichPluginURLs(plugins)
|
|
22
|
-
if (type) {
|
|
23
|
-
return plugins.filter((plugin: Plugin) => plugin.schema?.type === type)
|
|
24
|
-
} else {
|
|
25
|
-
return plugins
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export async function processUploaded(plugin: FileType, source?: PluginSource) {
|
|
30
|
-
const { metadata, directory } = await fileUpload(plugin)
|
|
31
|
-
pluginCore.validate(metadata?.schema)
|
|
32
|
-
|
|
33
|
-
// Only allow components in cloud
|
|
34
|
-
if (!env.SELF_HOSTED && metadata?.schema?.type !== PluginType.COMPONENT) {
|
|
35
|
-
throw new Error("Only component plugins are supported outside of self-host")
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const doc = await pro.plugins.storePlugin(metadata, directory, source)
|
|
39
|
-
clientAppSocket.emit("plugin-update", { name: doc.name, hash: doc.hash })
|
|
40
|
-
return doc
|
|
41
|
-
}
|
package/src/websockets/client.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import Socket from "./websocket"
|
|
2
|
-
import authorized from "../middleware/authorized"
|
|
3
|
-
import http from "http"
|
|
4
|
-
import Koa from "koa"
|
|
5
|
-
import { permissions } from "@budibase/backend-core"
|
|
6
|
-
|
|
7
|
-
export default class ClientAppWebsocket extends Socket {
|
|
8
|
-
constructor(app: Koa, server: http.Server) {
|
|
9
|
-
super(app, server, "/socket/client", [authorized(permissions.BUILDER)])
|
|
10
|
-
}
|
|
11
|
-
}
|
package/src/websockets/grid.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import authorized from "../middleware/authorized"
|
|
2
|
-
import Socket from "./websocket"
|
|
3
|
-
import { permissions } from "@budibase/backend-core"
|
|
4
|
-
import http from "http"
|
|
5
|
-
import Koa from "koa"
|
|
6
|
-
|
|
7
|
-
export default class GridSocket extends Socket {
|
|
8
|
-
constructor(app: Koa, server: http.Server) {
|
|
9
|
-
super(app, server, "/socket/grid", [authorized(permissions.BUILDER)])
|
|
10
|
-
|
|
11
|
-
this.io.on("connection", socket => {
|
|
12
|
-
const user = socket.data.user
|
|
13
|
-
console.log(`Spreadsheet user connected: ${user?.id}`)
|
|
14
|
-
|
|
15
|
-
// Socket state
|
|
16
|
-
let currentRoom: string
|
|
17
|
-
|
|
18
|
-
// Initial identification of connected spreadsheet
|
|
19
|
-
socket.on("select-table", async (tableId, callback) => {
|
|
20
|
-
// Leave current room
|
|
21
|
-
if (currentRoom) {
|
|
22
|
-
socket.to(currentRoom).emit("user-disconnect", socket.data.user)
|
|
23
|
-
socket.leave(currentRoom)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Join new room
|
|
27
|
-
currentRoom = tableId
|
|
28
|
-
socket.join(currentRoom)
|
|
29
|
-
socket.to(currentRoom).emit("user-update", socket.data.user)
|
|
30
|
-
|
|
31
|
-
// Reply with all users in current room
|
|
32
|
-
const sockets = await this.io.in(currentRoom).fetchSockets()
|
|
33
|
-
callback({
|
|
34
|
-
users: sockets.map(socket => socket.data.user),
|
|
35
|
-
id: user.id,
|
|
36
|
-
})
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
// Handle users selecting a new cell
|
|
40
|
-
socket.on("select-cell", cellId => {
|
|
41
|
-
socket.data.user.selectedCellId = cellId
|
|
42
|
-
if (currentRoom) {
|
|
43
|
-
socket.to(currentRoom).emit("user-update", socket.data.user)
|
|
44
|
-
}
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
// Disconnection cleanup
|
|
48
|
-
socket.on("disconnect", () => {
|
|
49
|
-
if (currentRoom) {
|
|
50
|
-
socket.to(currentRoom).emit("user-disconnect", socket.data.user)
|
|
51
|
-
}
|
|
52
|
-
})
|
|
53
|
-
})
|
|
54
|
-
}
|
|
55
|
-
}
|
package/src/websockets/index.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import http from "http"
|
|
2
|
-
import Koa from "koa"
|
|
3
|
-
import GridSocket from "./grid"
|
|
4
|
-
import ClientAppSocket from "./client"
|
|
5
|
-
|
|
6
|
-
let clientAppSocket: ClientAppSocket
|
|
7
|
-
let gridSocket: GridSocket
|
|
8
|
-
|
|
9
|
-
export const initialise = (app: Koa, server: http.Server) => {
|
|
10
|
-
clientAppSocket = new ClientAppSocket(app, server)
|
|
11
|
-
gridSocket = new GridSocket(app, server)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export { clientAppSocket, gridSocket }
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { Server } from "socket.io"
|
|
2
|
-
import http from "http"
|
|
3
|
-
import Koa from "koa"
|
|
4
|
-
import Cookies from "cookies"
|
|
5
|
-
import { userAgent } from "koa-useragent"
|
|
6
|
-
import { auth } from "@budibase/backend-core"
|
|
7
|
-
import currentApp from "../middleware/currentapp"
|
|
8
|
-
|
|
9
|
-
export default class Socket {
|
|
10
|
-
io: Server
|
|
11
|
-
|
|
12
|
-
constructor(
|
|
13
|
-
app: Koa,
|
|
14
|
-
server: http.Server,
|
|
15
|
-
path: string,
|
|
16
|
-
additionalMiddlewares?: any[]
|
|
17
|
-
) {
|
|
18
|
-
this.io = new Server(server, {
|
|
19
|
-
path,
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
// Attach default middlewares
|
|
23
|
-
const authenticate = auth.buildAuthMiddleware([], {
|
|
24
|
-
publicAllowed: true,
|
|
25
|
-
})
|
|
26
|
-
const middlewares = [
|
|
27
|
-
userAgent,
|
|
28
|
-
authenticate,
|
|
29
|
-
currentApp,
|
|
30
|
-
...(additionalMiddlewares || []),
|
|
31
|
-
]
|
|
32
|
-
|
|
33
|
-
// Apply middlewares
|
|
34
|
-
this.io.use(async (socket, next) => {
|
|
35
|
-
// Build fake koa context
|
|
36
|
-
const res = new http.ServerResponse(socket.request)
|
|
37
|
-
const ctx: any = {
|
|
38
|
-
...app.createContext(socket.request, res),
|
|
39
|
-
|
|
40
|
-
// Additional overrides needed to make our middlewares work with this
|
|
41
|
-
// fake koa context
|
|
42
|
-
cookies: new Cookies(socket.request, res),
|
|
43
|
-
get: (field: string) => socket.request.headers[field],
|
|
44
|
-
throw: (code: number, message: string) => {
|
|
45
|
-
throw new Error(message)
|
|
46
|
-
},
|
|
47
|
-
|
|
48
|
-
// Needed for koa-useragent middleware
|
|
49
|
-
headers: socket.request.headers,
|
|
50
|
-
header: socket.request.headers,
|
|
51
|
-
|
|
52
|
-
// We don't really care about the path since it will never contain
|
|
53
|
-
// an app ID
|
|
54
|
-
path: "/socket",
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Run all koa middlewares
|
|
58
|
-
try {
|
|
59
|
-
for (let [idx, middleware] of middlewares.entries()) {
|
|
60
|
-
await middleware(ctx, () => {
|
|
61
|
-
if (idx === middlewares.length - 1) {
|
|
62
|
-
// Middlewares are finished.
|
|
63
|
-
// Extract some data from our enriched koa context to persist
|
|
64
|
-
// as metadata for the socket
|
|
65
|
-
socket.data.user = {
|
|
66
|
-
id: ctx.user._id,
|
|
67
|
-
email: ctx.user.email,
|
|
68
|
-
}
|
|
69
|
-
next()
|
|
70
|
-
}
|
|
71
|
-
})
|
|
72
|
-
}
|
|
73
|
-
} catch (error: any) {
|
|
74
|
-
next(error)
|
|
75
|
-
}
|
|
76
|
-
})
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Emit an event to all sockets
|
|
80
|
-
emit(event: string, payload: any) {
|
|
81
|
-
this.io.sockets.emit(event, payload)
|
|
82
|
-
}
|
|
83
|
-
}
|