@budibase/server 2.5.6-alpha.1 → 2.5.6-alpha.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 (121) hide show
  1. package/builder/assets/{index.1fe52b59.js → index.5c1a6913.js} +361 -361
  2. package/builder/assets/index.c0265b74.css +6 -0
  3. package/builder/index.html +2 -2
  4. package/dist/api/controllers/automation.js +13 -7
  5. package/dist/api/controllers/plugin/index.js +6 -37
  6. package/dist/api/controllers/table/utils.js +2 -1
  7. package/dist/api/controllers/user.js +1 -83
  8. package/dist/api/routes/user.js +0 -1
  9. package/dist/app.js +2 -2
  10. package/dist/automations/actions.js +32 -6
  11. package/dist/automations/index.js +3 -2
  12. package/dist/automations/steps/bash.js +6 -6
  13. package/dist/automations/steps/createRow.js +11 -11
  14. package/dist/automations/steps/delay.js +3 -3
  15. package/dist/automations/steps/deleteRow.js +8 -8
  16. package/dist/automations/steps/discord.js +8 -8
  17. package/dist/automations/steps/executeQuery.js +9 -9
  18. package/dist/automations/steps/executeScript.js +6 -6
  19. package/dist/automations/steps/filter.js +6 -6
  20. package/dist/automations/steps/integromat.js +10 -10
  21. package/dist/automations/steps/loop.js +9 -9
  22. package/dist/automations/steps/outgoingWebhook.js +10 -10
  23. package/dist/automations/steps/queryRows.js +14 -14
  24. package/dist/automations/steps/sendSmtpEmail.js +9 -9
  25. package/dist/automations/steps/serverLog.js +4 -4
  26. package/dist/automations/steps/slack.js +6 -6
  27. package/dist/automations/steps/updateRow.js +11 -11
  28. package/dist/automations/steps/zapier.js +9 -9
  29. package/dist/automations/triggerInfo/app.js +5 -5
  30. package/dist/automations/triggerInfo/cron.js +4 -4
  31. package/dist/automations/triggerInfo/rowDeleted.js +5 -5
  32. package/dist/automations/triggerInfo/rowSaved.js +7 -7
  33. package/dist/automations/triggerInfo/rowUpdated.js +7 -7
  34. package/dist/automations/triggerInfo/webhook.js +6 -6
  35. package/dist/events/docUpdates/index.js +17 -0
  36. package/dist/events/docUpdates/processors.js +18 -0
  37. package/dist/events/docUpdates/syncUsers.js +49 -0
  38. package/dist/events/index.js +3 -0
  39. package/dist/integrations/index.js +3 -3
  40. package/dist/package.json +9 -8
  41. package/dist/sdk/app/applications/sync.js +117 -23
  42. package/dist/sdk/index.js +2 -0
  43. package/dist/sdk/plugins/index.js +27 -0
  44. package/dist/sdk/plugins/plugins.js +53 -0
  45. package/dist/sdk/users/utils.js +21 -4
  46. package/dist/startup.js +2 -1
  47. package/dist/threads/automation.js +2 -2
  48. package/dist/tsconfig.build.tsbuildinfo +1 -1
  49. package/dist/utilities/fileSystem/plugin.js +33 -23
  50. package/dist/utilities/global.js +17 -12
  51. package/dist/watch.js +2 -2
  52. package/dist/websockets/client.js +14 -0
  53. package/dist/websockets/grid.js +60 -0
  54. package/dist/websockets/index.js +17 -0
  55. package/dist/websockets/websocket.js +78 -0
  56. package/jest.config.ts +3 -3
  57. package/nodemon.json +7 -3
  58. package/package.json +10 -9
  59. package/src/api/controllers/automation.ts +12 -6
  60. package/src/api/controllers/plugin/index.ts +8 -45
  61. package/src/api/controllers/row/internal.ts +9 -10
  62. package/src/api/controllers/row/utils.ts +2 -2
  63. package/src/api/controllers/table/utils.ts +2 -1
  64. package/src/api/controllers/user.ts +10 -96
  65. package/src/api/routes/tests/automation.spec.js +2 -2
  66. package/src/api/routes/tests/user.spec.js +0 -37
  67. package/src/api/routes/user.ts +0 -5
  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/events/docUpdates/index.ts +1 -0
  96. package/src/events/docUpdates/processors.ts +14 -0
  97. package/src/events/docUpdates/syncUsers.ts +35 -0
  98. package/src/events/index.ts +1 -0
  99. package/src/integrations/index.ts +3 -3
  100. package/src/sdk/app/applications/sync.ts +129 -22
  101. package/src/sdk/app/applications/tests/sync.spec.ts +137 -0
  102. package/src/sdk/index.ts +2 -0
  103. package/src/sdk/plugins/index.ts +5 -0
  104. package/src/sdk/plugins/plugins.ts +41 -0
  105. package/src/sdk/users/tests/utils.spec.ts +1 -32
  106. package/src/sdk/users/utils.ts +23 -5
  107. package/src/startup.ts +2 -1
  108. package/src/tests/utilities/TestConfiguration.ts +28 -0
  109. package/src/tests/utilities/structures.ts +25 -17
  110. package/src/threads/automation.ts +2 -2
  111. package/src/utilities/fileSystem/plugin.ts +13 -4
  112. package/src/utilities/global.ts +21 -16
  113. package/src/watch.ts +2 -2
  114. package/src/websockets/client.ts +11 -0
  115. package/src/websockets/grid.ts +55 -0
  116. package/src/websockets/index.ts +14 -0
  117. package/src/websockets/websocket.ts +83 -0
  118. package/tsconfig.json +1 -7
  119. package/builder/assets/index.841e62d8.css +0 -6
  120. package/dist/websocket.js +0 -22
  121. package/src/websocket.ts +0 -26
@@ -0,0 +1,137 @@
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/index.ts CHANGED
@@ -6,6 +6,7 @@ import { default as datasources } from "./app/datasources"
6
6
  import { default as queries } from "./app/queries"
7
7
  import { default as rows } from "./app/rows"
8
8
  import { default as users } from "./users"
9
+ import { default as plugins } from "./plugins"
9
10
 
10
11
  const sdk = {
11
12
  backups,
@@ -16,6 +17,7 @@ const sdk = {
16
17
  users,
17
18
  datasources,
18
19
  queries,
20
+ plugins,
19
21
  }
20
22
 
21
23
  // default export for TS
@@ -0,0 +1,5 @@
1
+ import * as plugins from "./plugins"
2
+
3
+ export default {
4
+ ...plugins,
5
+ }
@@ -0,0 +1,41 @@
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
+ }
@@ -121,38 +121,7 @@ describe("syncGlobalUsers", () => {
121
121
  await syncGlobalUsers()
122
122
 
123
123
  const metadata = await rawUserMetadata()
124
- expect(metadata).toHaveLength(1)
125
- })
126
- })
127
- })
128
-
129
- it("app users are removed when app is removed from user group", async () => {
130
- await config.doInTenant(async () => {
131
- const group = await proSdk.groups.save(structures.userGroups.userGroup())
132
- const user1 = await config.createUser({ admin: false, builder: false })
133
- const user2 = await config.createUser({ admin: false, builder: false })
134
- await proSdk.groups.updateGroupApps(group.id, {
135
- appsToAdd: [
136
- { appId: config.prodAppId!, roleId: roles.BUILTIN_ROLE_IDS.BASIC },
137
- ],
138
- })
139
- await proSdk.groups.addUsers(group.id, [user1._id, user2._id])
140
-
141
- await config.doInContext(config.appId, async () => {
142
- await syncGlobalUsers()
143
- expect(await rawUserMetadata()).toHaveLength(3)
144
-
145
- await proSdk.groups.removeUsers(group.id, [user1._id])
146
- await syncGlobalUsers()
147
-
148
- const metadata = await rawUserMetadata()
149
- expect(metadata).toHaveLength(2)
150
-
151
- expect(metadata).not.toContainEqual(
152
- expect.objectContaining({
153
- _id: db.generateUserMetadataID(user1._id),
154
- })
155
- )
124
+ expect(metadata).toHaveLength(0)
156
125
  })
157
126
  })
158
127
  })
@@ -1,12 +1,13 @@
1
1
  import { getGlobalUsers } from "../../utilities/global"
2
2
  import { context, roles as rolesCore } from "@budibase/backend-core"
3
3
  import {
4
+ getGlobalIDFromUserMetadataID,
4
5
  generateUserMetadataID,
5
6
  getUserMetadataParams,
6
7
  InternalTables,
7
8
  } from "../../db/utils"
8
9
  import { isEqual } from "lodash"
9
- import { ContextUser, UserMetadata } from "@budibase/types"
10
+ import { ContextUser, UserMetadata, User } from "@budibase/types"
10
11
 
11
12
  export function combineMetadataAndUser(
12
13
  user: ContextUser,
@@ -37,6 +38,10 @@ export function combineMetadataAndUser(
37
38
  if (found) {
38
39
  newDoc._rev = found._rev
39
40
  }
41
+ // clear fields that shouldn't be in metadata
42
+ delete newDoc.password
43
+ delete newDoc.forceResetPassword
44
+ delete newDoc.roles
40
45
  if (found == null || !isEqual(newDoc, found)) {
41
46
  return {
42
47
  ...found,
@@ -60,10 +65,9 @@ export async function rawUserMetadata() {
60
65
  export async function syncGlobalUsers() {
61
66
  // sync user metadata
62
67
  const db = context.getAppDB()
63
- const [users, metadata] = await Promise.all([
64
- getGlobalUsers(),
65
- rawUserMetadata(),
66
- ])
68
+ const resp = await Promise.all([getGlobalUsers(), rawUserMetadata()])
69
+ const users = resp[0] as User[]
70
+ const metadata = resp[1] as UserMetadata[]
67
71
  const toWrite = []
68
72
  for (let user of users) {
69
73
  const combined = combineMetadataAndUser(user, metadata)
@@ -71,5 +75,19 @@ export async function syncGlobalUsers() {
71
75
  toWrite.push(combined)
72
76
  }
73
77
  }
78
+ let foundEmails: string[] = []
79
+ for (let data of metadata) {
80
+ if (!data._id) {
81
+ continue
82
+ }
83
+ const alreadyExisting = data.email && foundEmails.indexOf(data.email) !== -1
84
+ const globalId = getGlobalIDFromUserMetadataID(data._id)
85
+ if (!users.find(user => user._id === globalId) || alreadyExisting) {
86
+ toWrite.push({ ...data, _deleted: true })
87
+ }
88
+ if (data.email) {
89
+ foundEmails.push(data.email)
90
+ }
91
+ }
74
92
  await db.bulkDocs(toWrite)
75
93
  }
package/src/startup.ts CHANGED
@@ -10,7 +10,7 @@ import fs from "fs"
10
10
  import { watch } from "./watch"
11
11
  import * as automations from "./automations"
12
12
  import * as fileSystem from "./utilities/fileSystem"
13
- import eventEmitter from "./events"
13
+ import { default as eventEmitter, init as eventInit } from "./events"
14
14
  import * as migrations from "./migrations"
15
15
  import * as bullboard from "./automations/bullboard"
16
16
  import * as pro from "@budibase/pro"
@@ -63,6 +63,7 @@ export async function startup(app?: any, server?: any) {
63
63
  eventEmitter.emitPort(env.PORT)
64
64
  fileSystem.init()
65
65
  await redis.init()
66
+ eventInit()
66
67
 
67
68
  // run migrations on startup if not done via http
68
69
  // not recommended in a clustered environment
@@ -49,6 +49,7 @@ import {
49
49
  SearchFilters,
50
50
  UserRoles,
51
51
  } from "@budibase/types"
52
+ import { BUILTIN_ROLE_IDS } from "@budibase/backend-core/src/security/roles"
52
53
 
53
54
  type DefaultUserValues = {
54
55
  globalUserId: string
@@ -306,6 +307,33 @@ class TestConfiguration {
306
307
  }
307
308
  }
308
309
 
310
+ async createGroup(roleId: string = BUILTIN_ROLE_IDS.BASIC) {
311
+ return context.doInTenant(this.tenantId!, async () => {
312
+ const baseGroup = structures.userGroups.userGroup()
313
+ baseGroup.roles = {
314
+ [this.prodAppId]: roleId,
315
+ }
316
+ const { id, rev } = await pro.sdk.groups.save(baseGroup)
317
+ return {
318
+ _id: id,
319
+ _rev: rev,
320
+ ...baseGroup,
321
+ }
322
+ })
323
+ }
324
+
325
+ async addUserToGroup(groupId: string, userId: string) {
326
+ return context.doInTenant(this.tenantId!, async () => {
327
+ await pro.sdk.groups.addUsers(groupId, [userId])
328
+ })
329
+ }
330
+
331
+ async removeUserFromGroup(groupId: string, userId: string) {
332
+ return context.doInTenant(this.tenantId!, async () => {
333
+ await pro.sdk.groups.removeUsers(groupId, [userId])
334
+ })
335
+ }
336
+
309
337
  async login({ roleId, userId, builder, prodApp = false }: any = {}) {
310
338
  const appId = prodApp ? this.prodAppId : this.appId
311
339
  return context.doInAppContext(appId, async () => {
@@ -1,18 +1,22 @@
1
- import { permissions, roles } from "@budibase/backend-core"
1
+ import { permissions, roles, utils } from "@budibase/backend-core"
2
2
  import { createHomeScreen } from "../../constants/screens"
3
3
  import { EMPTY_LAYOUT } from "../../constants/layouts"
4
4
  import { cloneDeep } from "lodash/fp"
5
- import { ACTION_DEFINITIONS, TRIGGER_DEFINITIONS } from "../../automations"
5
+ import {
6
+ BUILTIN_ACTION_DEFINITIONS,
7
+ TRIGGER_DEFINITIONS,
8
+ } from "../../automations"
6
9
  import {
7
10
  Automation,
8
11
  AutomationActionStepId,
12
+ AutomationStep,
13
+ AutomationStepType,
14
+ AutomationTrigger,
9
15
  AutomationTriggerStepId,
10
16
  Datasource,
11
17
  SourceName,
12
18
  } from "@budibase/types"
13
19
 
14
- const { v4: uuidv4 } = require("uuid")
15
-
16
20
  export function basicTable() {
17
21
  return {
18
22
  name: "TestTable",
@@ -71,19 +75,19 @@ export function view(tableId: string) {
71
75
  }
72
76
 
73
77
  export function automationStep(
74
- actionDefinition = ACTION_DEFINITIONS.CREATE_ROW
75
- ) {
78
+ actionDefinition = BUILTIN_ACTION_DEFINITIONS.CREATE_ROW
79
+ ): AutomationStep {
76
80
  return {
77
- id: uuidv4(),
81
+ id: utils.newid(),
78
82
  ...actionDefinition,
79
83
  }
80
84
  }
81
85
 
82
86
  export function automationTrigger(
83
87
  triggerDefinition = TRIGGER_DEFINITIONS.ROW_SAVED
84
- ) {
88
+ ): AutomationTrigger {
85
89
  return {
86
- id: uuidv4(),
90
+ id: utils.newid(),
87
91
  ...triggerDefinition,
88
92
  }
89
93
  }
@@ -106,7 +110,7 @@ export function newAutomation({ steps, trigger }: any = {}) {
106
110
  return automation
107
111
  }
108
112
 
109
- export function basicAutomation(appId?: string) {
113
+ export function basicAutomation(appId?: string): Automation {
110
114
  return {
111
115
  name: "My Automation",
112
116
  screenId: "kasdkfldsafkl",
@@ -119,18 +123,22 @@ export function basicAutomation(appId?: string) {
119
123
  tagline: "test",
120
124
  icon: "test",
121
125
  description: "test",
122
- type: "trigger",
126
+ type: AutomationStepType.TRIGGER,
123
127
  id: "test",
124
128
  inputs: {},
125
129
  schema: {
126
- inputs: {},
127
- outputs: {},
130
+ inputs: {
131
+ properties: {},
132
+ },
133
+ outputs: {
134
+ properties: {},
135
+ },
128
136
  },
129
137
  },
130
138
  steps: [],
131
139
  },
132
140
  type: "automation",
133
- appId,
141
+ appId: appId!,
134
142
  }
135
143
  }
136
144
 
@@ -154,7 +162,7 @@ export function loopAutomation(tableId: string, loopOpts?: any): Automation {
154
162
  inputs: {
155
163
  tableId,
156
164
  },
157
- schema: ACTION_DEFINITIONS.QUERY_ROWS.schema,
165
+ schema: BUILTIN_ACTION_DEFINITIONS.QUERY_ROWS.schema,
158
166
  },
159
167
  {
160
168
  id: "c",
@@ -163,7 +171,7 @@ export function loopAutomation(tableId: string, loopOpts?: any): Automation {
163
171
  internal: true,
164
172
  inputs: loopOpts,
165
173
  blockToLoop: "d",
166
- schema: ACTION_DEFINITIONS.LOOP.schema,
174
+ schema: BUILTIN_ACTION_DEFINITIONS.LOOP.schema,
167
175
  },
168
176
  {
169
177
  id: "d",
@@ -173,7 +181,7 @@ export function loopAutomation(tableId: string, loopOpts?: any): Automation {
173
181
  inputs: {
174
182
  text: "log statement",
175
183
  },
176
- schema: ACTION_DEFINITIONS.SERVER_LOG.schema,
184
+ schema: BUILTIN_ACTION_DEFINITIONS.SERVER_LOG.schema,
177
185
  },
178
186
  ],
179
187
  trigger: {
@@ -27,8 +27,8 @@ import { processObject } from "@budibase/string-templates"
27
27
  import { cloneDeep } from "lodash/fp"
28
28
  import * as sdkUtils from "../sdk/utils"
29
29
  import env from "../environment"
30
- const FILTER_STEP_ID = actions.ACTION_DEFINITIONS.FILTER.stepId
31
- const LOOP_STEP_ID = actions.ACTION_DEFINITIONS.LOOP.stepId
30
+ const FILTER_STEP_ID = actions.BUILTIN_ACTION_DEFINITIONS.FILTER.stepId
31
+ const LOOP_STEP_ID = actions.BUILTIN_ACTION_DEFINITIONS.LOOP.stepId
32
32
  const CRON_STEP_ID = triggerDefs.CRON.stepId
33
33
  const STOPPED_STATUS = { success: true, status: AutomationStatus.STOPPED }
34
34
 
@@ -5,6 +5,7 @@ import { join } from "path"
5
5
  import { objectStore } from "@budibase/backend-core"
6
6
 
7
7
  const DATASOURCE_PATH = join(budibaseTempDir(), "datasource")
8
+ const AUTOMATION_PATH = join(budibaseTempDir(), "automation")
8
9
 
9
10
  export const getPluginMetadata = async (path: string) => {
10
11
  let metadata: any = {}
@@ -33,12 +34,12 @@ export const getPluginMetadata = async (path: string) => {
33
34
  return { metadata, directory: path }
34
35
  }
35
36
 
36
- export const getDatasourcePlugin = async (plugin: Plugin) => {
37
+ async function getPluginImpl(path: string, plugin: Plugin) {
37
38
  const hash = plugin.schema?.hash
38
- if (!fs.existsSync(DATASOURCE_PATH)) {
39
- fs.mkdirSync(DATASOURCE_PATH)
39
+ if (!fs.existsSync(path)) {
40
+ fs.mkdirSync(path)
40
41
  }
41
- const filename = join(DATASOURCE_PATH, plugin.name)
42
+ const filename = join(path, plugin.name)
42
43
  const metadataName = `${filename}.bbmetadata`
43
44
  if (fs.existsSync(filename)) {
44
45
  const currentHash = fs.readFileSync(metadataName, "utf8")
@@ -62,3 +63,11 @@ export const getDatasourcePlugin = async (plugin: Plugin) => {
62
63
 
63
64
  return require(filename)
64
65
  }
66
+
67
+ export const getDatasourcePlugin = async (plugin: Plugin) => {
68
+ return getPluginImpl(DATASOURCE_PATH, plugin)
69
+ }
70
+
71
+ export const getAutomationPlugin = async (plugin: Plugin) => {
72
+ return getPluginImpl(AUTOMATION_PATH, plugin)
73
+ }
@@ -9,6 +9,7 @@ import {
9
9
  import env from "../environment"
10
10
  import { groups } from "@budibase/pro"
11
11
  import { UserCtx, ContextUser, User, UserGroup } from "@budibase/types"
12
+ import { global } from "yargs"
12
13
 
13
14
  export function updateAppRole(
14
15
  user: ContextUser,
@@ -16,7 +17,7 @@ export function updateAppRole(
16
17
  ) {
17
18
  appId = appId || context.getAppId()
18
19
 
19
- if (!user || !user.roles) {
20
+ if (!user || (!user.roles && !user.userGroups)) {
20
21
  return user
21
22
  }
22
23
  // if in an multi-tenancy environment make sure roles are never updated
@@ -27,7 +28,7 @@ export function updateAppRole(
27
28
  return user
28
29
  }
29
30
  // always use the deployed app
30
- if (appId) {
31
+ if (appId && user.roles) {
31
32
  user.roleId = user.roles[dbCore.getProdAppID(appId)]
32
33
  }
33
34
  // if a role wasn't found then either set as admin (builder) or public (everyone else)
@@ -60,7 +61,7 @@ async function checkGroupRoles(
60
61
  return user
61
62
  }
62
63
 
63
- async function processUser(
64
+ export async function processUser(
64
65
  user: ContextUser,
65
66
  opts: { appId?: string; groups?: UserGroup[] } = {}
66
67
  ) {
@@ -94,16 +95,15 @@ export async function getGlobalUser(userId: string) {
94
95
  return processUser(user, { appId })
95
96
  }
96
97
 
97
- export async function getGlobalUsers(users?: ContextUser[]) {
98
+ export async function getGlobalUsers(
99
+ userIds?: string[],
100
+ opts?: { noProcessing?: boolean }
101
+ ) {
98
102
  const appId = context.getAppId()
99
103
  const db = tenancy.getGlobalDB()
100
- const allGroups = await groups.fetch()
101
104
  let globalUsers
102
- if (users) {
103
- const globalIds = users.map(user =>
104
- getGlobalIDFromUserMetadataID(user._id!)
105
- )
106
- globalUsers = (await db.allDocs(getMultiIDParams(globalIds))).rows.map(
105
+ if (userIds) {
106
+ globalUsers = (await db.allDocs(getMultiIDParams(userIds))).rows.map(
107
107
  row => row.doc
108
108
  )
109
109
  } else {
@@ -126,15 +126,20 @@ export async function getGlobalUsers(users?: ContextUser[]) {
126
126
  return globalUsers
127
127
  }
128
128
 
129
- // pass in the groups, meaning we don't actually need to retrieve them for
130
- // each user individually
131
- return Promise.all(
132
- globalUsers.map(user => processUser(user, { groups: allGroups }))
133
- )
129
+ if (opts?.noProcessing) {
130
+ return globalUsers
131
+ } else {
132
+ // pass in the groups, meaning we don't actually need to retrieve them for
133
+ // each user individually
134
+ const allGroups = await groups.fetch()
135
+ return Promise.all(
136
+ globalUsers.map(user => processUser(user, { groups: allGroups }))
137
+ )
138
+ }
134
139
  }
135
140
 
136
141
  export async function getGlobalUsersFromMetadata(users: ContextUser[]) {
137
- const globalUsers = await getGlobalUsers(users)
142
+ const globalUsers = await getGlobalUsers(users.map(user => user._id!))
138
143
  return users.map(user => {
139
144
  const globalUser = globalUsers.find(
140
145
  globalUser => globalUser && user._id?.includes(globalUser._id)
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
+ }