@budibase/server 2.5.9 → 2.5.10-alpha.1

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 (198) hide show
  1. package/builder/assets/index.24635afb.js +1794 -0
  2. package/builder/assets/index.4eae16b2.css +6 -0
  3. package/builder/index.html +2 -2
  4. package/dist/api/controllers/application.js +3 -4
  5. package/dist/api/controllers/automation.js +13 -7
  6. package/dist/api/controllers/datasource.js +1 -1
  7. package/dist/api/controllers/dev.js +1 -1
  8. package/dist/api/controllers/ops.js +40 -0
  9. package/dist/api/controllers/plugin/index.js +6 -37
  10. package/dist/api/controllers/query/index.js +2 -2
  11. package/dist/api/controllers/row/ExternalRequest.js +21 -14
  12. package/dist/api/controllers/row/internal.js +5 -2
  13. package/dist/api/controllers/row/utils.js +2 -2
  14. package/dist/api/controllers/table/index.js +2 -2
  15. package/dist/api/controllers/table/utils.js +9 -3
  16. package/dist/api/controllers/user.js +1 -83
  17. package/dist/api/controllers/view/exporters.js +3 -1
  18. package/dist/api/index.js +1 -2
  19. package/dist/api/routes/index.js +2 -2
  20. package/dist/api/routes/{cloud.js → ops.js} +19 -6
  21. package/dist/api/routes/user.js +0 -1
  22. package/dist/app.js +4 -13
  23. package/dist/automations/actions.js +32 -6
  24. package/dist/automations/index.js +3 -2
  25. package/dist/automations/steps/bash.js +6 -6
  26. package/dist/automations/steps/createRow.js +11 -11
  27. package/dist/automations/steps/delay.js +3 -3
  28. package/dist/automations/steps/deleteRow.js +8 -8
  29. package/dist/automations/steps/discord.js +8 -8
  30. package/dist/automations/steps/executeQuery.js +9 -9
  31. package/dist/automations/steps/executeScript.js +6 -6
  32. package/dist/automations/steps/filter.js +6 -6
  33. package/dist/automations/steps/integromat.js +10 -10
  34. package/dist/automations/steps/loop.js +9 -9
  35. package/dist/automations/steps/outgoingWebhook.js +10 -10
  36. package/dist/automations/steps/queryRows.js +14 -14
  37. package/dist/automations/steps/sendSmtpEmail.js +9 -9
  38. package/dist/automations/steps/serverLog.js +4 -4
  39. package/dist/automations/steps/slack.js +6 -6
  40. package/dist/automations/steps/updateRow.js +11 -11
  41. package/dist/automations/steps/zapier.js +9 -9
  42. package/dist/automations/triggerInfo/app.js +5 -5
  43. package/dist/automations/triggerInfo/cron.js +4 -4
  44. package/dist/automations/triggerInfo/rowDeleted.js +5 -5
  45. package/dist/automations/triggerInfo/rowSaved.js +7 -7
  46. package/dist/automations/triggerInfo/rowUpdated.js +7 -7
  47. package/dist/automations/triggerInfo/webhook.js +6 -6
  48. package/dist/db/utils.js +3 -2
  49. package/dist/environment.js +0 -1
  50. package/dist/events/docUpdates/index.js +17 -0
  51. package/dist/events/docUpdates/processors.js +18 -0
  52. package/dist/events/docUpdates/syncUsers.js +49 -0
  53. package/dist/events/index.js +3 -0
  54. package/dist/integrations/base/sqlTable.js +9 -2
  55. package/dist/integrations/index.js +3 -3
  56. package/dist/integrations/microsoftSqlServer.js +5 -2
  57. package/dist/integrations/mysql.js +5 -3
  58. package/dist/integrations/postgres.js +7 -5
  59. package/dist/integrations/redis.js +7 -0
  60. package/dist/integrations/rest.js +4 -0
  61. package/dist/migrations/functions/syncQuotas.js +2 -0
  62. package/dist/migrations/functions/usageQuotas/syncApps.js +1 -2
  63. package/dist/migrations/functions/usageQuotas/syncRows.js +1 -2
  64. package/dist/migrations/functions/usageQuotas/syncUsers.js +21 -0
  65. package/dist/sdk/app/applications/sync.js +117 -23
  66. package/dist/sdk/app/backups/exports.js +14 -38
  67. package/dist/sdk/index.js +2 -0
  68. package/dist/sdk/plugins/index.js +27 -0
  69. package/dist/sdk/plugins/plugins.js +53 -0
  70. package/dist/sdk/users/utils.js +21 -4
  71. package/dist/startup.js +31 -28
  72. package/dist/threads/automation.js +16 -5
  73. package/dist/tsconfig.build.tsbuildinfo +1 -1
  74. package/dist/utilities/csv.js +33 -0
  75. package/dist/utilities/fileSystem/plugin.js +33 -23
  76. package/dist/utilities/global.js +17 -12
  77. package/dist/utilities/rowProcessor/utils.js +4 -5
  78. package/dist/utilities/schema.js +5 -1
  79. package/dist/watch.js +2 -2
  80. package/dist/websockets/client.js +14 -0
  81. package/dist/websockets/grid.js +60 -0
  82. package/dist/websockets/index.js +17 -0
  83. package/dist/websockets/websocket.js +78 -0
  84. package/package.json +16 -16
  85. package/scripts/dev/manage.js +2 -0
  86. package/scripts/integrations/mssql/data/entrypoint.sh +1 -0
  87. package/scripts/integrations/mssql/data/setup.sql +17 -17
  88. package/scripts/integrations/mysql/init.sql +1 -1
  89. package/scripts/integrations/postgres/init.sql +1 -0
  90. package/src/api/controllers/application.ts +4 -4
  91. package/src/api/controllers/automation.ts +12 -6
  92. package/src/api/controllers/datasource.ts +15 -5
  93. package/src/api/controllers/dev.ts +2 -2
  94. package/src/api/controllers/ops.ts +32 -0
  95. package/src/api/controllers/plugin/index.ts +8 -45
  96. package/src/api/controllers/query/index.ts +2 -2
  97. package/src/api/controllers/row/ExternalRequest.ts +21 -12
  98. package/src/api/controllers/row/internal.ts +13 -11
  99. package/src/api/controllers/row/utils.ts +4 -4
  100. package/src/api/controllers/table/index.ts +2 -2
  101. package/src/api/controllers/table/utils.ts +10 -3
  102. package/src/api/controllers/user.ts +10 -96
  103. package/src/api/controllers/view/exporters.ts +3 -1
  104. package/src/api/index.ts +2 -4
  105. package/src/api/routes/index.ts +2 -2
  106. package/src/api/routes/ops.ts +30 -0
  107. package/src/api/routes/tests/automation.spec.js +7 -4
  108. package/src/api/routes/tests/user.spec.js +48 -37
  109. package/src/api/routes/user.ts +0 -5
  110. package/src/app.ts +4 -15
  111. package/src/automations/actions.ts +56 -24
  112. package/src/automations/index.ts +1 -1
  113. package/src/automations/steps/bash.ts +10 -7
  114. package/src/automations/steps/createRow.ts +15 -12
  115. package/src/automations/steps/delay.ts +6 -4
  116. package/src/automations/steps/deleteRow.ts +12 -9
  117. package/src/automations/steps/discord.ts +10 -8
  118. package/src/automations/steps/executeQuery.ts +13 -10
  119. package/src/automations/steps/executeScript.ts +10 -7
  120. package/src/automations/steps/filter.ts +8 -6
  121. package/src/automations/steps/integromat.ts +12 -10
  122. package/src/automations/steps/loop.ts +16 -10
  123. package/src/automations/steps/outgoingWebhook.ts +14 -11
  124. package/src/automations/steps/queryRows.ts +18 -15
  125. package/src/automations/steps/sendSmtpEmail.ts +11 -9
  126. package/src/automations/steps/serverLog.ts +6 -4
  127. package/src/automations/steps/slack.ts +8 -6
  128. package/src/automations/steps/updateRow.ts +15 -12
  129. package/src/automations/steps/zapier.ts +11 -9
  130. package/src/automations/tests/utilities/index.ts +2 -2
  131. package/src/automations/triggerInfo/app.ts +8 -5
  132. package/src/automations/triggerInfo/cron.ts +7 -4
  133. package/src/automations/triggerInfo/rowDeleted.ts +8 -5
  134. package/src/automations/triggerInfo/rowSaved.ts +10 -7
  135. package/src/automations/triggerInfo/rowUpdated.ts +10 -7
  136. package/src/automations/triggerInfo/webhook.ts +9 -6
  137. package/src/db/utils.ts +1 -0
  138. package/src/environment.ts +0 -1
  139. package/src/events/docUpdates/index.ts +1 -0
  140. package/src/events/docUpdates/processors.ts +14 -0
  141. package/src/events/docUpdates/syncUsers.ts +35 -0
  142. package/src/events/index.ts +1 -0
  143. package/src/integration-test/postgres.spec.ts +3 -1
  144. package/src/integrations/base/sqlTable.ts +9 -2
  145. package/src/integrations/index.ts +3 -3
  146. package/src/integrations/microsoftSqlServer.ts +5 -2
  147. package/src/integrations/mysql.ts +5 -3
  148. package/src/integrations/postgres.ts +7 -5
  149. package/src/integrations/redis.ts +8 -0
  150. package/src/integrations/rest.ts +3 -0
  151. package/src/migrations/functions/syncQuotas.ts +2 -0
  152. package/src/migrations/functions/usageQuotas/syncApps.ts +2 -3
  153. package/src/migrations/functions/usageQuotas/syncRows.ts +2 -3
  154. package/src/migrations/functions/usageQuotas/syncUsers.ts +9 -0
  155. package/src/migrations/functions/usageQuotas/tests/syncRows.spec.ts +2 -2
  156. package/src/migrations/functions/usageQuotas/tests/syncUsers.spec.ts +26 -0
  157. package/src/migrations/index.ts +1 -0
  158. package/src/sdk/app/applications/sync.ts +129 -22
  159. package/src/sdk/app/applications/tests/sync.spec.ts +137 -0
  160. package/src/sdk/app/backups/exports.ts +17 -41
  161. package/src/sdk/index.ts +2 -0
  162. package/src/sdk/plugins/index.ts +5 -0
  163. package/src/sdk/plugins/plugins.ts +41 -0
  164. package/src/sdk/users/tests/utils.spec.ts +1 -32
  165. package/src/sdk/users/utils.ts +23 -5
  166. package/src/startup.ts +36 -34
  167. package/src/tests/jestEnv.ts +0 -1
  168. package/src/tests/jestSetup.ts +0 -1
  169. package/src/tests/utilities/TestConfiguration.ts +28 -0
  170. package/src/tests/utilities/structures.ts +25 -17
  171. package/src/threads/automation.ts +18 -6
  172. package/src/utilities/csv.ts +22 -0
  173. package/src/utilities/fileSystem/plugin.ts +13 -4
  174. package/src/utilities/global.ts +21 -16
  175. package/src/utilities/rowProcessor/utils.ts +9 -10
  176. package/src/utilities/schema.ts +8 -0
  177. package/src/utilities/tests/csv.spec.ts +33 -0
  178. package/src/watch.ts +2 -2
  179. package/src/websockets/client.ts +11 -0
  180. package/src/websockets/grid.ts +55 -0
  181. package/src/websockets/index.ts +14 -0
  182. package/src/websockets/websocket.ts +83 -0
  183. package/tsconfig.build.json +3 -5
  184. package/tsconfig.json +2 -1
  185. package/builder/assets/index.0b358332.js +0 -1817
  186. package/builder/assets/index.7f9a008b.css +0 -6
  187. package/dist/api/controllers/cloud.js +0 -130
  188. package/dist/elasticApm.js +0 -14
  189. package/dist/package.json +0 -180
  190. package/dist/websocket.js +0 -22
  191. package/scripts/likeCypress.ts +0 -35
  192. package/src/api/controllers/cloud.ts +0 -119
  193. package/src/api/routes/cloud.ts +0 -18
  194. package/src/api/routes/tests/cloud.spec.ts +0 -54
  195. package/src/elasticApm.ts +0 -10
  196. package/src/migrations/functions/tests/syncQuotas.spec.js +0 -26
  197. package/src/tests/logging.ts +0 -34
  198. package/src/websocket.ts +0 -26
@@ -4,6 +4,9 @@ interface SchemaColumn {
4
4
  readonly name: string
5
5
  readonly type: FieldTypes
6
6
  readonly autocolumn?: boolean
7
+ readonly constraints?: {
8
+ presence: boolean
9
+ }
7
10
  }
8
11
 
9
12
  interface Schema {
@@ -76,6 +79,11 @@ export function validate(rows: Rows, schema: Schema): ValidationResults {
76
79
  // If the columnType is not a string, then it's not present in the schema, and should be added to the invalid columns array
77
80
  if (typeof columnType !== "string") {
78
81
  results.invalidColumns.push(columnName)
82
+ } else if (
83
+ columnData == null &&
84
+ !schema[columnName].constraints?.presence
85
+ ) {
86
+ results.schemaValidation[columnName] = true
79
87
  } else if (
80
88
  // If there's no data for this field don't bother with further checks
81
89
  // If the field is already marked as invalid there's no need for further checks
@@ -0,0 +1,33 @@
1
+ import { jsonFromCsvString } from "../csv"
2
+
3
+ describe("csv", () => {
4
+ describe("jsonFromCsvString", () => {
5
+ test("multiple lines csv can be casted", async () => {
6
+ const csvString = '"id","title"\n"1","aaa"\n"2","bbb"'
7
+
8
+ const result = await jsonFromCsvString(csvString)
9
+
10
+ expect(result).toEqual([
11
+ { id: "1", title: "aaa" },
12
+ { id: "2", title: "bbb" },
13
+ ])
14
+ result.forEach(r => expect(Object.keys(r)).toEqual(["id", "title"]))
15
+ })
16
+
17
+ test("empty values are casted as undefined", async () => {
18
+ const csvString =
19
+ '"id","optional","title"\n1,,"aaa"\n2,"value","bbb"\n3,,"ccc"'
20
+
21
+ const result = await jsonFromCsvString(csvString)
22
+
23
+ expect(result).toEqual([
24
+ { id: "1", optional: null, title: "aaa" },
25
+ { id: "2", optional: "value", title: "bbb" },
26
+ { id: "3", optional: null, title: "ccc" },
27
+ ])
28
+ result.forEach(r =>
29
+ expect(Object.keys(r)).toEqual(["id", "optional", "title"])
30
+ )
31
+ })
32
+ })
33
+ })
package/src/watch.ts CHANGED
@@ -3,7 +3,7 @@ import env from "./environment"
3
3
  import chokidar from "chokidar"
4
4
  import fs from "fs"
5
5
  import { constants, tenancy } from "@budibase/backend-core"
6
- import { processUploadedPlugin } from "./api/controllers/plugin"
6
+ import pluginsSdk from "./sdk/plugins"
7
7
 
8
8
  export function watch() {
9
9
  const watchPath = path.join(env.PLUGINS_DIR, "./**/*.tar.gz")
@@ -27,7 +27,7 @@ export function watch() {
27
27
  const split = path.split("/")
28
28
  const name = split[split.length - 1]
29
29
  console.log("Importing plugin:", path)
30
- await processUploadedPlugin({ name, path })
30
+ await pluginsSdk.processUploaded({ name, path })
31
31
  } catch (err: any) {
32
32
  const message = err?.message ? err?.message : err
33
33
  console.error("Failed to import plugin:", message)
@@ -0,0 +1,11 @@
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
+ }
@@ -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
  }