@budibase/server 2.5.6-alpha.3 → 2.5.6-alpha.31

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 (126) hide show
  1. package/builder/assets/{index.a33a6c3d.js → index.39cfdb4b.js} +382 -366
  2. package/builder/assets/index.44a18341.css +6 -0
  3. package/builder/index.html +2 -2
  4. package/dist/api/controllers/application.js +2 -3
  5. package/dist/api/controllers/automation.js +13 -7
  6. package/dist/api/controllers/dev.js +1 -1
  7. package/dist/api/controllers/plugin/index.js +6 -37
  8. package/dist/api/controllers/query/index.js +2 -2
  9. package/dist/api/controllers/row/ExternalRequest.js +21 -14
  10. package/dist/api/controllers/table/utils.js +9 -3
  11. package/dist/api/index.js +1 -2
  12. package/dist/api/routes/index.js +0 -2
  13. package/dist/app.js +2 -2
  14. package/dist/automations/actions.js +32 -6
  15. package/dist/automations/index.js +3 -2
  16. package/dist/automations/steps/bash.js +6 -6
  17. package/dist/automations/steps/createRow.js +11 -11
  18. package/dist/automations/steps/delay.js +3 -3
  19. package/dist/automations/steps/deleteRow.js +8 -8
  20. package/dist/automations/steps/discord.js +8 -8
  21. package/dist/automations/steps/executeQuery.js +9 -9
  22. package/dist/automations/steps/executeScript.js +6 -6
  23. package/dist/automations/steps/filter.js +6 -6
  24. package/dist/automations/steps/integromat.js +10 -10
  25. package/dist/automations/steps/loop.js +9 -9
  26. package/dist/automations/steps/outgoingWebhook.js +10 -10
  27. package/dist/automations/steps/queryRows.js +14 -14
  28. package/dist/automations/steps/sendSmtpEmail.js +9 -9
  29. package/dist/automations/steps/serverLog.js +4 -4
  30. package/dist/automations/steps/slack.js +6 -6
  31. package/dist/automations/steps/updateRow.js +11 -11
  32. package/dist/automations/steps/zapier.js +9 -9
  33. package/dist/automations/triggerInfo/app.js +5 -5
  34. package/dist/automations/triggerInfo/cron.js +4 -4
  35. package/dist/automations/triggerInfo/rowDeleted.js +5 -5
  36. package/dist/automations/triggerInfo/rowSaved.js +7 -7
  37. package/dist/automations/triggerInfo/rowUpdated.js +7 -7
  38. package/dist/automations/triggerInfo/webhook.js +6 -6
  39. package/dist/integrations/base/sqlTable.js +9 -2
  40. package/dist/integrations/index.js +3 -3
  41. package/dist/migrations/functions/syncQuotas.js +2 -0
  42. package/dist/migrations/functions/usageQuotas/syncApps.js +0 -1
  43. package/dist/migrations/functions/usageQuotas/syncUsers.js +21 -0
  44. package/dist/sdk/app/backups/exports.js +1 -35
  45. package/dist/sdk/index.js +2 -0
  46. package/dist/{api/routes/cloud.js → sdk/plugins/index.js} +2 -14
  47. package/dist/sdk/plugins/plugins.js +53 -0
  48. package/dist/threads/automation.js +2 -2
  49. package/dist/tsconfig.build.tsbuildinfo +1 -1
  50. package/dist/utilities/fileSystem/plugin.js +33 -23
  51. package/dist/utilities/rowProcessor/utils.js +4 -5
  52. package/dist/watch.js +2 -2
  53. package/dist/websockets/client.js +14 -0
  54. package/dist/websockets/grid.js +60 -0
  55. package/dist/websockets/index.js +17 -0
  56. package/dist/websockets/websocket.js +78 -0
  57. package/package.json +11 -10
  58. package/src/api/controllers/application.ts +3 -3
  59. package/src/api/controllers/automation.ts +12 -6
  60. package/src/api/controllers/dev.ts +2 -2
  61. package/src/api/controllers/plugin/index.ts +8 -45
  62. package/src/api/controllers/query/index.ts +2 -2
  63. package/src/api/controllers/row/ExternalRequest.ts +21 -12
  64. package/src/api/controllers/table/utils.ts +10 -3
  65. package/src/api/index.ts +2 -4
  66. package/src/api/routes/index.ts +0 -2
  67. package/src/api/routes/tests/automation.spec.js +2 -2
  68. package/src/app.ts +2 -2
  69. package/src/automations/actions.ts +56 -24
  70. package/src/automations/index.ts +1 -1
  71. package/src/automations/steps/bash.ts +10 -7
  72. package/src/automations/steps/createRow.ts +15 -12
  73. package/src/automations/steps/delay.ts +6 -4
  74. package/src/automations/steps/deleteRow.ts +12 -9
  75. package/src/automations/steps/discord.ts +10 -8
  76. package/src/automations/steps/executeQuery.ts +13 -10
  77. package/src/automations/steps/executeScript.ts +10 -7
  78. package/src/automations/steps/filter.ts +8 -6
  79. package/src/automations/steps/integromat.ts +12 -10
  80. package/src/automations/steps/loop.ts +16 -10
  81. package/src/automations/steps/outgoingWebhook.ts +14 -11
  82. package/src/automations/steps/queryRows.ts +18 -15
  83. package/src/automations/steps/sendSmtpEmail.ts +11 -9
  84. package/src/automations/steps/serverLog.ts +6 -4
  85. package/src/automations/steps/slack.ts +8 -6
  86. package/src/automations/steps/updateRow.ts +15 -12
  87. package/src/automations/steps/zapier.ts +11 -9
  88. package/src/automations/tests/utilities/index.ts +2 -2
  89. package/src/automations/triggerInfo/app.ts +8 -5
  90. package/src/automations/triggerInfo/cron.ts +7 -4
  91. package/src/automations/triggerInfo/rowDeleted.ts +8 -5
  92. package/src/automations/triggerInfo/rowSaved.ts +10 -7
  93. package/src/automations/triggerInfo/rowUpdated.ts +10 -7
  94. package/src/automations/triggerInfo/webhook.ts +9 -6
  95. package/src/integration-test/postgres.spec.ts +2 -0
  96. package/src/integrations/base/sqlTable.ts +9 -2
  97. package/src/integrations/index.ts +3 -3
  98. package/src/migrations/functions/syncQuotas.ts +2 -0
  99. package/src/migrations/functions/usageQuotas/syncApps.ts +1 -2
  100. package/src/migrations/functions/usageQuotas/syncUsers.ts +9 -0
  101. package/src/migrations/functions/usageQuotas/tests/syncUsers.spec.ts +26 -0
  102. package/src/migrations/index.ts +1 -0
  103. package/src/sdk/app/backups/exports.ts +0 -35
  104. package/src/sdk/index.ts +2 -0
  105. package/src/sdk/plugins/index.ts +5 -0
  106. package/src/sdk/plugins/plugins.ts +41 -0
  107. package/src/tests/utilities/structures.ts +25 -17
  108. package/src/threads/automation.ts +2 -2
  109. package/src/utilities/fileSystem/plugin.ts +13 -4
  110. package/src/utilities/rowProcessor/utils.ts +9 -10
  111. package/src/watch.ts +2 -2
  112. package/src/websockets/client.ts +11 -0
  113. package/src/websockets/grid.ts +55 -0
  114. package/src/websockets/index.ts +14 -0
  115. package/src/websockets/websocket.ts +83 -0
  116. package/tsconfig.build.json +3 -5
  117. package/tsconfig.json +2 -1
  118. package/builder/assets/index.841e62d8.css +0 -6
  119. package/dist/api/controllers/cloud.js +0 -130
  120. package/dist/package.json +0 -179
  121. package/dist/websocket.js +0 -22
  122. package/src/api/controllers/cloud.ts +0 -119
  123. package/src/api/routes/cloud.ts +0 -18
  124. package/src/api/routes/tests/cloud.spec.ts +0 -54
  125. package/src/migrations/functions/tests/syncQuotas.spec.js +0 -26
  126. package/src/websocket.ts +0 -26
@@ -0,0 +1,55 @@
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
+ }
@@ -0,0 +1,14 @@
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 }
@@ -0,0 +1,83 @@
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
+ }
@@ -8,13 +8,11 @@
8
8
  "esModuleInterop": true,
9
9
  "resolveJsonModule": true,
10
10
  "incremental": true,
11
- "types": [ "node", "jest" ],
12
- "outDir": "dist",
11
+ "types": ["node", "jest"],
12
+ "outDir": "dist/src",
13
13
  "skipLibCheck": true
14
14
  },
15
- "include": [
16
- "src/**/*"
17
- ],
15
+ "include": ["src/**/*"],
18
16
  "exclude": [
19
17
  "node_modules",
20
18
  "dist",
package/tsconfig.json CHANGED
@@ -5,6 +5,7 @@
5
5
  "declaration": true,
6
6
  "sourceMap": true,
7
7
  "baseUrl": ".",
8
+ "outDir": "dist",
8
9
  "paths": {
9
10
  "@budibase/types": ["../types/src"],
10
11
  "@budibase/backend-core": ["../backend-core/src"],
@@ -23,6 +24,6 @@
23
24
  { "path": "../shared-core" },
24
25
  { "path": "../../../budibase-pro/packages/pro" }
25
26
  ],
26
- "include": ["src/**/*", "specs", "package.json"],
27
+ "include": ["src/**/*", "specs"],
27
28
  "exclude": ["node_modules", "dist"]
28
29
  }