@budibase/server 2.4.43 → 2.4.44-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 (66) hide show
  1. package/builder/assets/{index.8b377b88.js → index.76deb808.js} +385 -384
  2. package/builder/assets/index.7f9a008b.css +6 -0
  3. package/builder/index.html +7 -7
  4. package/dist/api/controllers/application.js +28 -24
  5. package/dist/api/controllers/public/metrics.js +113 -0
  6. package/dist/api/controllers/row/external.js +15 -0
  7. package/dist/api/controllers/static/index.js +84 -24
  8. package/dist/api/controllers/static/templates/BudibaseApp.svelte +34 -11
  9. package/dist/api/controllers/table/utils.js +2 -4
  10. package/dist/api/routes/public/index.js +8 -0
  11. package/dist/api/routes/public/metrics.js +30 -0
  12. package/dist/app.js +1 -0
  13. package/dist/integrations/googlesheets.js +4 -0
  14. package/dist/integrations/redis.js +1 -1
  15. package/dist/middleware/currentapp.js +1 -27
  16. package/dist/package.json +12 -11
  17. package/dist/sdk/users/utils.js +11 -6
  18. package/dist/tsconfig.build.tsbuildinfo +1 -1
  19. package/dist/utilities/fileSystem/app.js +1 -10
  20. package/dist/utilities/global.js +17 -7
  21. package/jest.config.ts +1 -0
  22. package/package.json +13 -12
  23. package/specs/openapi.json +39 -0
  24. package/specs/openapi.yaml +169 -0
  25. package/specs/resources/application.ts +11 -0
  26. package/specs/resources/index.ts +2 -0
  27. package/specs/resources/metrics.ts +81 -0
  28. package/src/api/controllers/application.ts +20 -21
  29. package/src/api/controllers/component.ts +2 -2
  30. package/src/api/controllers/public/metrics.ts +251 -0
  31. package/src/api/controllers/row/external.ts +14 -0
  32. package/src/api/controllers/static/index.ts +69 -26
  33. package/src/api/controllers/static/templates/BudibaseApp.svelte +34 -11
  34. package/src/api/controllers/table/tests/utils.spec.ts +97 -0
  35. package/src/api/controllers/table/utils.ts +20 -12
  36. package/src/api/controllers/view/tests/__snapshots__/viewBuilder.spec.js.snap +48 -48
  37. package/src/api/routes/public/index.ts +10 -1
  38. package/src/api/routes/public/metrics.ts +28 -0
  39. package/src/api/routes/public/tests/metrics.spec.js +34 -0
  40. package/src/api/routes/tests/__snapshots__/datasource.spec.ts.snap +22 -22
  41. package/src/api/routes/tests/__snapshots__/view.spec.js.snap +5 -5
  42. package/src/api/routes/tests/appSync.spec.ts +1 -1
  43. package/src/api/routes/tests/internalSearch.spec.js +6 -6
  44. package/src/api/routes/tests/user.spec.js +2 -2
  45. package/src/app.ts +2 -1
  46. package/src/automations/automationUtils.ts +1 -1
  47. package/src/automations/tests/automation.spec.ts +99 -0
  48. package/src/db/defaultData/datasource_bb_default.ts +1 -1
  49. package/src/definitions/openapi.ts +15 -0
  50. package/src/integrations/googlesheets.ts +4 -0
  51. package/src/integrations/redis.ts +1 -1
  52. package/src/integrations/tests/googlesheets.spec.ts +4 -0
  53. package/src/integrations/tests/redis.spec.ts +9 -5
  54. package/src/middleware/currentapp.ts +3 -32
  55. package/src/middleware/tests/currentapp.spec.js +6 -42
  56. package/src/sdk/users/tests/utils.spec.ts +159 -0
  57. package/src/sdk/users/utils.ts +18 -7
  58. package/src/tests/jestSetup.ts +5 -1
  59. package/src/tests/utilities/TestConfiguration.ts +7 -19
  60. package/src/tests/utilities/structures.ts +13 -1
  61. package/src/utilities/fileSystem/app.ts +2 -9
  62. package/src/utilities/global.ts +21 -9
  63. package/src/utilities/rowProcessor/index.ts +1 -1
  64. package/builder/assets/favicon.e7fc7733.png +0 -0
  65. package/builder/assets/index.b0e3aca6.css +0 -6
  66. package/src/automations/tests/automation.spec.js +0 -84
@@ -0,0 +1,99 @@
1
+ jest.mock("../../threads/automation")
2
+ jest.mock("../../utilities/redis", () => ({
3
+ init: jest.fn(),
4
+ checkTestFlag: () => {
5
+ return false
6
+ },
7
+ }))
8
+
9
+ jest.spyOn(global.console, "error")
10
+
11
+ import "../../environment"
12
+ import * as automation from "../index"
13
+ import * as thread from "../../threads/automation"
14
+ import * as triggers from "../triggers"
15
+ import { basicAutomation } from "../../tests/utilities/structures"
16
+ import { wait } from "../../utilities"
17
+ import { makePartial } from "../../tests/utilities"
18
+ import { cleanInputValues } from "../automationUtils"
19
+ import * as setup from "./utilities"
20
+ import { Automation } from "@budibase/types"
21
+
22
+ describe("Run through some parts of the automations system", () => {
23
+ let config = setup.getConfig()
24
+
25
+ beforeAll(async () => {
26
+ await automation.init()
27
+ await config.init()
28
+ })
29
+
30
+ afterAll(async () => {
31
+ await automation.shutdown()
32
+ setup.afterAll()
33
+ })
34
+
35
+ it("should be able to init in builder", async () => {
36
+ const automation: Automation = {
37
+ ...basicAutomation(),
38
+ appId: config.appId,
39
+ }
40
+ const fields: any = { a: 1, appId: config.appId }
41
+ await triggers.externalTrigger(automation, fields)
42
+ await wait(100)
43
+ expect(thread.execute).toHaveBeenCalled()
44
+ })
45
+
46
+ it("should check coercion", async () => {
47
+ const table = await config.createTable()
48
+ const automation: any = basicAutomation()
49
+ automation.definition.trigger.inputs.tableId = table._id
50
+ automation.definition.trigger.stepId = "APP"
51
+ automation.definition.trigger.inputs.fields = { a: "number" }
52
+ const fields: any = {
53
+ appId: config.getAppId(),
54
+ fields: {
55
+ a: "1",
56
+ },
57
+ }
58
+ await triggers.externalTrigger(automation, fields)
59
+ await wait(100)
60
+ expect(thread.execute).toHaveBeenCalledWith(
61
+ makePartial({
62
+ data: {
63
+ event: {
64
+ fields: {
65
+ a: 1,
66
+ },
67
+ },
68
+ },
69
+ }),
70
+ expect.any(Function)
71
+ )
72
+ })
73
+
74
+ it("should be able to clean inputs with the utilities", () => {
75
+ // can't clean without a schema
76
+ let output = cleanInputValues({ a: "1" })
77
+ expect(output.a).toBe("1")
78
+ output = cleanInputValues(
79
+ { a: "1", b: "true", c: "false", d: 1, e: "help" },
80
+ {
81
+ properties: {
82
+ a: {
83
+ type: "number",
84
+ },
85
+ b: {
86
+ type: "boolean",
87
+ },
88
+ c: {
89
+ type: "boolean",
90
+ },
91
+ },
92
+ }
93
+ )
94
+ expect(output.a).toBe(1)
95
+ expect(output.b).toBe(true)
96
+ expect(output.c).toBe(false)
97
+ expect(output.d).toBe(1)
98
+ })
99
+ })
@@ -34,7 +34,7 @@ function syncLastIds(table: Table, rowCount: number) {
34
34
  })
35
35
  }
36
36
 
37
- function tableImport(table: Table, data: Row) {
37
+ function tableImport(table: Table, data: Row[]) {
38
38
  const cloneTable = cloneDeep(table)
39
39
  const rowDocs = importToRows(data, cloneTable)
40
40
  syncLastIds(cloneTable, rowDocs.length)
@@ -22,6 +22,10 @@ export interface paths {
22
22
  /** Based on application properties (currently only name) search for applications. */
23
23
  post: operations["appSearch"];
24
24
  };
25
+ "/metrics": {
26
+ /** Output metrics in OpenMetrics format compatible with Prometheus */
27
+ get: operations["metricsGet"];
28
+ };
25
29
  "/queries/{queryId}": {
26
30
  /** Queries which have been created within a Budibase app can be executed using this, */
27
31
  post: operations["queryExecute"];
@@ -844,6 +848,17 @@ export interface operations {
844
848
  };
845
849
  };
846
850
  };
851
+ /** Output metrics in OpenMetrics format compatible with Prometheus */
852
+ metricsGet: {
853
+ responses: {
854
+ /** Returns tenant metrics. */
855
+ 200: {
856
+ content: {
857
+ "text/plain": string;
858
+ };
859
+ };
860
+ };
861
+ };
847
862
  /** Queries which have been created within a Budibase app can be executed using this, */
848
863
  queryExecute: {
849
864
  parameters: {
@@ -245,6 +245,10 @@ class GoogleSheetsIntegration implements DatasourcePlus {
245
245
  }
246
246
 
247
247
  async buildSchema(datasourceId: string, entities: Record<string, Table>) {
248
+ // not fully configured yet
249
+ if (!this.config.auth) {
250
+ return
251
+ }
248
252
  await this.connect()
249
253
  const sheets = this.client.sheetsByIndex
250
254
  const tables: Record<string, Table> = {}
@@ -92,7 +92,7 @@ class RedisIntegration {
92
92
  }
93
93
 
94
94
  async disconnect() {
95
- return this.client.disconnect()
95
+ return this.client.quit()
96
96
  }
97
97
 
98
98
  async redisContext(query: Function) {
@@ -39,6 +39,10 @@ describe("Google Sheets Integration", () => {
39
39
  config.setGoogleAuth("test")
40
40
  })
41
41
 
42
+ afterAll(async () => {
43
+ await config.end()
44
+ })
45
+
42
46
  beforeEach(async () => {
43
47
  integration = new GoogleSheetsIntegration.integration({
44
48
  spreadsheetId: "randomId",
@@ -3,17 +3,17 @@ import { default as RedisIntegration } from "../redis"
3
3
 
4
4
  class TestConfiguration {
5
5
  integration: any
6
- redis: any
7
6
 
8
7
  constructor(config: any = {}) {
9
8
  this.integration = new RedisIntegration.integration(config)
10
- this.redis = new Redis({
9
+ // have to kill the basic integration before replacing it
10
+ this.integration.client.quit()
11
+ this.integration.client = new Redis({
11
12
  data: {
12
13
  test: "test",
13
14
  result: "1",
14
15
  },
15
16
  })
16
- this.integration.client = this.redis
17
17
  }
18
18
  }
19
19
 
@@ -24,13 +24,17 @@ describe("Redis Integration", () => {
24
24
  config = new TestConfiguration()
25
25
  })
26
26
 
27
+ afterAll(() => {
28
+ config.integration.disconnect()
29
+ })
30
+
27
31
  it("calls the create method with the correct params", async () => {
28
32
  const body = {
29
33
  key: "key",
30
34
  value: "value",
31
35
  }
32
36
  await config.integration.create(body)
33
- expect(await config.redis.get("key")).toEqual("value")
37
+ expect(await config.integration.client.get("key")).toEqual("value")
34
38
  })
35
39
 
36
40
  it("calls the read method with the correct params", async () => {
@@ -46,7 +50,7 @@ describe("Redis Integration", () => {
46
50
  key: "test",
47
51
  }
48
52
  await config.integration.delete(body)
49
- expect(await config.redis.get(body.key)).toEqual(null)
53
+ expect(await config.integration.client.get(body.key)).toEqual(null)
50
54
  })
51
55
 
52
56
  it("calls the pipeline method with the correct params", async () => {
@@ -2,7 +2,6 @@ import {
2
2
  utils,
3
3
  constants,
4
4
  roles,
5
- db as dbCore,
6
5
  tenancy,
7
6
  context,
8
7
  } from "@budibase/backend-core"
@@ -10,34 +9,15 @@ import { generateUserMetadataID, isDevAppID } from "../db/utils"
10
9
  import { getCachedSelf } from "../utilities/global"
11
10
  import env from "../environment"
12
11
  import { isWebhookEndpoint } from "./utils"
13
- import { BBContext } from "@budibase/types"
12
+ import { UserCtx } from "@budibase/types"
14
13
 
15
- export default async (ctx: BBContext, next: any) => {
14
+ export default async (ctx: UserCtx, next: any) => {
16
15
  // try to get the appID from the request
17
16
  let requestAppId = await utils.getAppIdFromCtx(ctx)
18
- // get app cookie if it exists
19
- let appCookie: { appId?: string } | undefined
20
- try {
21
- appCookie = utils.getCookie(ctx, constants.Cookie.CurrentApp)
22
- } catch (err) {
23
- utils.clearCookie(ctx, constants.Cookie.CurrentApp)
24
- }
25
- if (!appCookie && !requestAppId) {
17
+ if (!requestAppId) {
26
18
  return next()
27
19
  }
28
20
 
29
- // check the app exists referenced in cookie
30
- if (appCookie) {
31
- const appId = appCookie.appId
32
- const exists = await dbCore.dbExists(appId)
33
- if (!exists) {
34
- utils.clearCookie(ctx, constants.Cookie.CurrentApp)
35
- return next()
36
- }
37
- // if the request app ID wasn't set, update it with the cookie
38
- requestAppId = requestAppId || appId
39
- }
40
-
41
21
  // deny access to application preview
42
22
  if (!env.isTest()) {
43
23
  if (
@@ -45,7 +25,6 @@ export default async (ctx: BBContext, next: any) => {
45
25
  !isWebhookEndpoint(ctx) &&
46
26
  (!ctx.user || !ctx.user.builder || !ctx.user.builder.global)
47
27
  ) {
48
- utils.clearCookie(ctx, constants.Cookie.CurrentApp)
49
28
  return ctx.redirect("/")
50
29
  }
51
30
  }
@@ -127,14 +106,6 @@ export default async (ctx: BBContext, next: any) => {
127
106
  role: await roles.getRole(roleId),
128
107
  }
129
108
  }
130
- if (
131
- (requestAppId !== appId ||
132
- appCookie == null ||
133
- appCookie.appId !== requestAppId) &&
134
- !skipCookie
135
- ) {
136
- utils.setCookie(ctx, { appId }, constants.Cookie.CurrentApp)
137
- }
138
109
 
139
110
  return next()
140
111
  })
@@ -158,27 +158,22 @@ describe("Current app middleware", () => {
158
158
  })
159
159
 
160
160
  describe("check functionality when logged in", () => {
161
- async function checkExpected(setCookie) {
161
+ async function checkExpected() {
162
162
  config.setUser()
163
163
  await config.executeMiddleware()
164
- let { utils } = require("@budibase/backend-core")
165
- if (setCookie) {
166
- expect(utils.setCookie).toHaveBeenCalled()
167
- } else {
168
- expect(utils.setCookie).not.toHaveBeenCalled()
169
- }
164
+
170
165
  expect(config.ctx.roleId).toEqual("PUBLIC")
171
166
  expect(config.ctx.user.role._id).toEqual("PUBLIC")
172
167
  expect(config.ctx.appId).toEqual("app_test")
173
168
  expect(config.next).toHaveBeenCalled()
174
169
  }
175
170
 
176
- it("should be able to setup an app token when cookie not setup", async () => {
171
+ it("should be able to setup an app token on a first call", async () => {
177
172
  mockAuthWithCookie()
178
- await checkExpected(true)
173
+ await checkExpected()
179
174
  })
180
175
 
181
- it("should perform correct when no cookie exists", async () => {
176
+ it("should perform correct on a first call", async () => {
182
177
  mockReset()
183
178
  jest.mock("@budibase/backend-core", () => {
184
179
  const core = jest.requireActual("@budibase/backend-core")
@@ -206,38 +201,7 @@ describe("Current app middleware", () => {
206
201
  },
207
202
  }
208
203
  })
209
- await checkExpected(true)
210
- })
211
-
212
- it("lastly check what occurs when cookie doesn't need updated", async () => {
213
- mockReset()
214
- jest.mock("@budibase/backend-core", () => {
215
- const core = jest.requireActual("@budibase/backend-core")
216
- return {
217
- ...core,
218
- db: {
219
- ...core.db,
220
- dbExists: () => true,
221
- },
222
- utils: {
223
- getAppIdFromCtx: () => {
224
- return "app_test"
225
- },
226
- setCookie: jest.fn(),
227
- getCookie: () => ({ appId: "app_test", roleId: "PUBLIC" }),
228
- },
229
- cache: {
230
- user: {
231
- getUser: async id => {
232
- return {
233
- _id: "us_uuid1",
234
- }
235
- },
236
- },
237
- },
238
- }
239
- })
240
- await checkExpected(false)
204
+ await checkExpected()
241
205
  })
242
206
  })
243
207
  })
@@ -0,0 +1,159 @@
1
+ import { db, roles } from "@budibase/backend-core"
2
+ import { structures } from "@budibase/backend-core/tests"
3
+ import { sdk as proSdk } from "@budibase/pro"
4
+
5
+ import TestConfiguration from "../../../tests/utilities/TestConfiguration"
6
+ import { rawUserMetadata, syncGlobalUsers } from "../utils"
7
+
8
+ describe("syncGlobalUsers", () => {
9
+ const config = new TestConfiguration()
10
+
11
+ beforeEach(async () => {
12
+ await config.init()
13
+ })
14
+
15
+ afterAll(config.end)
16
+
17
+ it("the default user is synced", async () => {
18
+ await config.doInContext(config.appId, async () => {
19
+ await syncGlobalUsers()
20
+
21
+ const metadata = await rawUserMetadata()
22
+ expect(metadata).toHaveLength(1)
23
+ expect(metadata).toEqual([
24
+ expect.objectContaining({
25
+ _id: db.generateUserMetadataID(config.user._id),
26
+ }),
27
+ ])
28
+ })
29
+ })
30
+
31
+ it("admin and builders users are synced", async () => {
32
+ const user1 = await config.createUser({ admin: true })
33
+ const user2 = await config.createUser({ admin: false, builder: true })
34
+ await config.doInContext(config.appId, async () => {
35
+ expect(await rawUserMetadata()).toHaveLength(1)
36
+ await syncGlobalUsers()
37
+
38
+ const metadata = await rawUserMetadata()
39
+ expect(metadata).toHaveLength(3)
40
+ expect(metadata).toContainEqual(
41
+ expect.objectContaining({
42
+ _id: db.generateUserMetadataID(user1._id),
43
+ })
44
+ )
45
+ expect(metadata).toContainEqual(
46
+ expect.objectContaining({
47
+ _id: db.generateUserMetadataID(user2._id),
48
+ })
49
+ )
50
+ })
51
+ })
52
+
53
+ it("app users are not synced if not specified", async () => {
54
+ const user = await config.createUser({ admin: false, builder: false })
55
+ await config.doInContext(config.appId, async () => {
56
+ await syncGlobalUsers()
57
+
58
+ const metadata = await rawUserMetadata()
59
+ expect(metadata).toHaveLength(1)
60
+ expect(metadata).not.toContainEqual(
61
+ expect.objectContaining({
62
+ _id: db.generateUserMetadataID(user._id),
63
+ })
64
+ )
65
+ })
66
+ })
67
+
68
+ it("app users are added when group is assigned to app", async () => {
69
+ await config.doInTenant(async () => {
70
+ const group = await proSdk.groups.save(structures.userGroups.userGroup())
71
+ const user1 = await config.createUser({ admin: false, builder: false })
72
+ const user2 = await config.createUser({ admin: false, builder: false })
73
+ await proSdk.groups.addUsers(group.id, [user1._id, user2._id])
74
+
75
+ await config.doInContext(config.appId, async () => {
76
+ await syncGlobalUsers()
77
+ expect(await rawUserMetadata()).toHaveLength(1)
78
+
79
+ await proSdk.groups.updateGroupApps(group.id, {
80
+ appsToAdd: [
81
+ { appId: config.prodAppId!, roleId: roles.BUILTIN_ROLE_IDS.BASIC },
82
+ ],
83
+ })
84
+ await syncGlobalUsers()
85
+
86
+ const metadata = await rawUserMetadata()
87
+ expect(metadata).toHaveLength(3)
88
+ expect(metadata).toContainEqual(
89
+ expect.objectContaining({
90
+ _id: db.generateUserMetadataID(user1._id),
91
+ })
92
+ )
93
+ expect(metadata).toContainEqual(
94
+ expect.objectContaining({
95
+ _id: db.generateUserMetadataID(user2._id),
96
+ })
97
+ )
98
+ })
99
+ })
100
+ })
101
+
102
+ it("app users are removed when app is removed from user group", async () => {
103
+ await config.doInTenant(async () => {
104
+ const group = await proSdk.groups.save(structures.userGroups.userGroup())
105
+ const user1 = await config.createUser({ admin: false, builder: false })
106
+ const user2 = await config.createUser({ admin: false, builder: false })
107
+ await proSdk.groups.updateGroupApps(group.id, {
108
+ appsToAdd: [
109
+ { appId: config.prodAppId!, roleId: roles.BUILTIN_ROLE_IDS.BASIC },
110
+ ],
111
+ })
112
+ await proSdk.groups.addUsers(group.id, [user1._id, user2._id])
113
+
114
+ await config.doInContext(config.appId, async () => {
115
+ await syncGlobalUsers()
116
+ expect(await rawUserMetadata()).toHaveLength(3)
117
+
118
+ await proSdk.groups.updateGroupApps(group.id, {
119
+ appsToRemove: [{ appId: config.prodAppId! }],
120
+ })
121
+ await syncGlobalUsers()
122
+
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
+ )
156
+ })
157
+ })
158
+ })
159
+ })
@@ -6,22 +6,33 @@ import {
6
6
  InternalTables,
7
7
  } from "../../db/utils"
8
8
  import { isEqual } from "lodash"
9
+ import { ContextUser, UserMetadata } from "@budibase/types"
9
10
 
10
- export function combineMetadataAndUser(user: any, metadata: any) {
11
+ export function combineMetadataAndUser(
12
+ user: ContextUser,
13
+ metadata: UserMetadata | UserMetadata[]
14
+ ) {
15
+ const metadataId = generateUserMetadataID(user._id!)
16
+ const found = Array.isArray(metadata)
17
+ ? metadata.find(doc => doc._id === metadataId)
18
+ : metadata
11
19
  // skip users with no access
12
- if (user.roleId === rolesCore.BUILTIN_ROLE_IDS.PUBLIC) {
20
+ if (
21
+ user.roleId == null ||
22
+ user.roleId === rolesCore.BUILTIN_ROLE_IDS.PUBLIC
23
+ ) {
24
+ // If it exists and it should not, we must remove it
25
+ if (found?._id) {
26
+ return { ...found, _deleted: true }
27
+ }
13
28
  return null
14
29
  }
15
30
  delete user._rev
16
- const metadataId = generateUserMetadataID(user._id)
17
31
  const newDoc = {
18
32
  ...user,
19
33
  _id: metadataId,
20
34
  tableId: InternalTables.USER_METADATA,
21
35
  }
22
- const found = Array.isArray(metadata)
23
- ? metadata.find(doc => doc._id === metadataId)
24
- : metadata
25
36
  // copy rev over for the purposes of equality check
26
37
  if (found) {
27
38
  newDoc._rev = found._rev
@@ -55,7 +66,7 @@ export async function syncGlobalUsers() {
55
66
  ])
56
67
  const toWrite = []
57
68
  for (let user of users) {
58
- const combined = await combineMetadataAndUser(user, metadata)
69
+ const combined = combineMetadataAndUser(user, metadata)
59
70
  if (combined) {
60
71
  toWrite.push(combined)
61
72
  }
@@ -1,6 +1,6 @@
1
1
  import "./logging"
2
2
  import env from "../environment"
3
- import { env as coreEnv } from "@budibase/backend-core"
3
+ import { env as coreEnv, timers } from "@budibase/backend-core"
4
4
  import { testContainerUtils } from "@budibase/backend-core/tests"
5
5
 
6
6
  if (!process.env.DEBUG) {
@@ -17,3 +17,7 @@ if (!process.env.CI) {
17
17
  }
18
18
 
19
19
  testContainerUtils.setupEnv(env, coreEnv)
20
+
21
+ afterAll(() => {
22
+ timers.cleanup()
23
+ })
@@ -47,6 +47,7 @@ import {
47
47
  SourceName,
48
48
  Table,
49
49
  SearchFilters,
50
+ UserRoles,
50
51
  } from "@budibase/types"
51
52
 
52
53
  type DefaultUserValues = {
@@ -165,6 +166,8 @@ class TestConfiguration {
165
166
  }
166
167
  if (this.server) {
167
168
  this.server.close()
169
+ } else {
170
+ require("../../app").default.close()
168
171
  }
169
172
  if (this.allApps) {
170
173
  cleanup(this.allApps.map(app => app.appId))
@@ -275,7 +278,7 @@ class TestConfiguration {
275
278
  email?: string
276
279
  builder?: boolean
277
280
  admin?: boolean
278
- roles?: any
281
+ roles?: UserRoles
279
282
  } = {}
280
283
  ) {
281
284
  let { id, firstName, lastName, email, builder, admin, roles } = user
@@ -328,21 +331,13 @@ class TestConfiguration {
328
331
  sessionId: "sessionid",
329
332
  tenantId: this.getTenantId(),
330
333
  }
331
- const app = {
332
- roleId: roleId,
333
- appId,
334
- }
335
334
  const authToken = auth.jwt.sign(authObj, coreEnv.JWT_SECRET)
336
- const appToken = auth.jwt.sign(app, coreEnv.JWT_SECRET)
337
335
 
338
336
  // returning necessary request headers
339
337
  await cache.user.invalidateUser(userId)
340
338
  return {
341
339
  Accept: "application/json",
342
- Cookie: [
343
- `${constants.Cookie.Auth}=${authToken}`,
344
- `${constants.Cookie.CurrentApp}=${appToken}`,
345
- ],
340
+ Cookie: [`${constants.Cookie.Auth}=${authToken}`],
346
341
  [constants.Header.APP_ID]: appId,
347
342
  }
348
343
  })
@@ -357,18 +352,11 @@ class TestConfiguration {
357
352
  sessionId: "sessionid",
358
353
  tenantId,
359
354
  }
360
- const app = {
361
- roleId: roles.BUILTIN_ROLE_IDS.ADMIN,
362
- appId: this.appId,
363
- }
364
355
  const authToken = auth.jwt.sign(authObj, coreEnv.JWT_SECRET)
365
- const appToken = auth.jwt.sign(app, coreEnv.JWT_SECRET)
356
+
366
357
  const headers: any = {
367
358
  Accept: "application/json",
368
- Cookie: [
369
- `${constants.Cookie.Auth}=${authToken}`,
370
- `${constants.Cookie.CurrentApp}=${appToken}`,
371
- ],
359
+ Cookie: [`${constants.Cookie.Auth}=${authToken}`],
372
360
  [constants.Header.CSRF_TOKEN]: this.defaultUserValues.csrfToken,
373
361
  Host: this.tenantHost(),
374
362
  ...extras,
@@ -106,7 +106,7 @@ export function newAutomation({ steps, trigger }: any = {}) {
106
106
  return automation
107
107
  }
108
108
 
109
- export function basicAutomation() {
109
+ export function basicAutomation(appId?: string) {
110
110
  return {
111
111
  name: "My Automation",
112
112
  screenId: "kasdkfldsafkl",
@@ -114,11 +114,23 @@ export function basicAutomation() {
114
114
  uiTree: {},
115
115
  definition: {
116
116
  trigger: {
117
+ stepId: AutomationTriggerStepId.APP,
118
+ name: "test",
119
+ tagline: "test",
120
+ icon: "test",
121
+ description: "test",
122
+ type: "trigger",
123
+ id: "test",
117
124
  inputs: {},
125
+ schema: {
126
+ inputs: {},
127
+ outputs: {},
128
+ },
118
129
  },
119
130
  steps: [],
120
131
  },
121
132
  type: "automation",
133
+ appId,
122
134
  }
123
135
  }
124
136