@budibase/server 2.4.44-alpha.7 → 2.4.44-alpha.9

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@budibase/server",
3
3
  "email": "hi@budibase.com",
4
- "version": "2.4.44-alpha.7",
4
+ "version": "2.4.44-alpha.9",
5
5
  "description": "Budibase Web Server",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -26,6 +26,7 @@
26
26
  "dev:stack:down": "node scripts/dev/manage.js down",
27
27
  "dev:stack:nuke": "node scripts/dev/manage.js nuke",
28
28
  "dev:builder": "yarn run dev:stack:up && nodemon",
29
+ "dev:built": "yarn run dev:stack:up && yarn run run:docker",
29
30
  "specs": "ts-node specs/generate.ts && openapi-typescript specs/openapi.yaml --output src/definitions/openapi.ts",
30
31
  "initialise": "node scripts/initialise.js",
31
32
  "env:multi:enable": "node scripts/multiTenancy.js enable",
@@ -44,12 +45,12 @@
44
45
  "license": "GPL-3.0",
45
46
  "dependencies": {
46
47
  "@apidevtools/swagger-parser": "10.0.3",
47
- "@budibase/backend-core": "2.4.44-alpha.7",
48
- "@budibase/client": "2.4.44-alpha.7",
49
- "@budibase/pro": "2.4.44-alpha.6",
50
- "@budibase/shared-core": "2.4.44-alpha.7",
51
- "@budibase/string-templates": "2.4.44-alpha.7",
52
- "@budibase/types": "2.4.44-alpha.7",
48
+ "@budibase/backend-core": "2.4.44-alpha.9",
49
+ "@budibase/client": "2.4.44-alpha.9",
50
+ "@budibase/pro": "2.4.44-alpha.8",
51
+ "@budibase/shared-core": "2.4.44-alpha.9",
52
+ "@budibase/string-templates": "2.4.44-alpha.9",
53
+ "@budibase/types": "2.4.44-alpha.9",
53
54
  "@bull-board/api": "3.7.0",
54
55
  "@bull-board/koa": "3.9.4",
55
56
  "@elastic/elasticsearch": "7.10.0",
@@ -174,5 +175,5 @@
174
175
  "optionalDependencies": {
175
176
  "oracledb": "5.3.0"
176
177
  },
177
- "gitHead": "a43e7fab7056a6be54f056b0c7aca083ce490b52"
178
+ "gitHead": "a4fe60d41874d2cc733479ee9359f8fdb495fa71"
178
179
  }
@@ -45,7 +45,8 @@ async function init() {
45
45
  BB_ADMIN_USER_PASSWORD: "",
46
46
  PLUGINS_DIR: "",
47
47
  TENANT_FEATURE_FLAGS: "*:LICENSING,*:USER_GROUPS,*:ONBOARDING_TOUR",
48
- HTTP_LOGGING: 0,
48
+ HTTP_MIGRATIONS: "0",
49
+ HTTP_LOGGING: "0",
49
50
  }
50
51
  let envFile = ""
51
52
  Object.keys(envFileJson).forEach(key => {
@@ -57,6 +57,7 @@ describe("/users", () => {
57
57
  it("should be able to update the user", async () => {
58
58
  const user = await config.createUser({ id: `us_update${utils.newid()}` })
59
59
  user.roleId = BUILTIN_ROLE_IDS.BASIC
60
+ delete user._rev
60
61
  const res = await request
61
62
  .put(`/api/users/metadata`)
62
63
  .set(config.defaultHeaders())
@@ -65,6 +66,46 @@ describe("/users", () => {
65
66
  .expect("Content-Type", /json/)
66
67
  expect(res.body.ok).toEqual(true)
67
68
  })
69
+
70
+ it("should be able to update the user multiple times", async () => {
71
+ const user = await config.createUser()
72
+ delete user._rev
73
+
74
+ const res1 = await request
75
+ .put(`/api/users/metadata`)
76
+ .set(config.defaultHeaders())
77
+ .send({ ...user, roleId: BUILTIN_ROLE_IDS.BASIC })
78
+ .expect(200)
79
+ .expect("Content-Type", /json/)
80
+
81
+ const res = await request
82
+ .put(`/api/users/metadata`)
83
+ .set(config.defaultHeaders())
84
+ .send({ ...user, _rev: res1.body.rev, roleId: BUILTIN_ROLE_IDS.POWER })
85
+ .expect(200)
86
+ .expect("Content-Type", /json/)
87
+
88
+ expect(res.body.ok).toEqual(true)
89
+ })
90
+
91
+ it("should require the _rev field for multiple updates", async () => {
92
+ const user = await config.createUser()
93
+ delete user._rev
94
+
95
+ await request
96
+ .put(`/api/users/metadata`)
97
+ .set(config.defaultHeaders())
98
+ .send({ ...user, roleId: BUILTIN_ROLE_IDS.BASIC })
99
+ .expect(200)
100
+ .expect("Content-Type", /json/)
101
+
102
+ await request
103
+ .put(`/api/users/metadata`)
104
+ .set(config.defaultHeaders())
105
+ .send({ ...user, roleId: BUILTIN_ROLE_IDS.POWER })
106
+ .expect(409)
107
+ .expect("Content-Type", /json/)
108
+ })
68
109
  })
69
110
 
70
111
  describe("destroy", () => {
@@ -92,6 +133,7 @@ describe("/users", () => {
92
133
  expect(res.body.tableId).toBeDefined()
93
134
  })
94
135
  })
136
+
95
137
  describe("setFlag", () => {
96
138
  it("should throw an error if a flag is not provided", async () => {
97
139
  await config.createUser()
@@ -101,8 +143,9 @@ describe("/users", () => {
101
143
  .send({ value: "test" })
102
144
  .expect(400)
103
145
  .expect("Content-Type", /json/)
104
- expect(res.body.message).toEqual("Must supply a 'flag' field in request body.")
105
-
146
+ expect(res.body.message).toEqual(
147
+ "Must supply a 'flag' field in request body."
148
+ )
106
149
  })
107
150
 
108
151
  it("should be able to set a flag on the user", async () => {
@@ -146,8 +189,9 @@ describe("/users", () => {
146
189
  .send({ value: "test" })
147
190
  .expect(400)
148
191
  .expect("Content-Type", /json/)
149
- expect(res.body.message).toEqual("Must supply a 'flag' field in request body.")
150
-
192
+ expect(res.body.message).toEqual(
193
+ "Must supply a 'flag' field in request body."
194
+ )
151
195
  })
152
196
 
153
197
  it("should be able to set a flag on the user", async () => {
@@ -165,33 +209,37 @@ describe("/users", () => {
165
209
  describe("syncUser", () => {
166
210
  it("should sync the user", async () => {
167
211
  let user = await config.createUser()
168
- await config.createApp('New App')
212
+ await config.createApp("New App")
169
213
  let res = await request
170
214
  .post(`/api/users/metadata/sync/${user._id}`)
171
215
  .set(config.defaultHeaders())
172
216
  .expect(200)
173
217
  .expect("Content-Type", /json/)
174
- expect(res.body.message).toEqual('User synced.')
218
+ expect(res.body.message).toEqual("User synced.")
175
219
  })
176
220
 
177
-
178
221
  it("should sync the user when a previous user is specified", async () => {
179
- const app1 = await config.createApp('App 1')
180
- const app2 = await config.createApp('App 2')
222
+ const app1 = await config.createApp("App 1")
223
+ const app2 = await config.createApp("App 2")
181
224
 
182
225
  let user = await config.createUser({
183
226
  builder: false,
184
227
  admin: true,
185
- roles: { [app1.appId]: 'ADMIN' }
186
- })
228
+ roles: { [app1.appId]: "ADMIN" },
229
+ })
187
230
  let res = await request
188
231
  .post(`/api/users/metadata/sync/${user._id}`)
189
232
  .set(config.defaultHeaders())
190
- .send({ previousUser: { ...user, roles: { ...user.roles, [app2.appId]: 'BASIC' } } })
233
+ .send({
234
+ previousUser: {
235
+ ...user,
236
+ roles: { ...user.roles, [app2.appId]: "BASIC" },
237
+ },
238
+ })
191
239
  .expect(200)
192
240
  .expect("Content-Type", /json/)
193
241
 
194
- expect(res.body.message).toEqual('User synced.')
242
+ expect(res.body.message).toEqual("User synced.")
195
243
  })
196
244
  })
197
245
  })
package/src/startup.ts CHANGED
@@ -45,8 +45,10 @@ async function initPro() {
45
45
  }
46
46
 
47
47
  function shutdown(server?: any) {
48
- server.close()
49
- server.destroy()
48
+ if (server) {
49
+ server.close()
50
+ server.destroy()
51
+ }
50
52
  }
51
53
 
52
54
  export async function startup(app?: any, server?: any) {
@@ -69,11 +71,39 @@ export async function startup(app?: any, server?: any) {
69
71
  await migrations.migrate()
70
72
  } catch (e) {
71
73
  logging.logAlert("Error performing migrations. Exiting.", e)
72
- shutdown()
74
+ shutdown(server)
73
75
  }
74
76
  }
75
77
 
78
+ // monitor plugin directory if required
79
+ if (
80
+ env.SELF_HOSTED &&
81
+ !env.MULTI_TENANCY &&
82
+ env.PLUGINS_DIR &&
83
+ fs.existsSync(env.PLUGINS_DIR)
84
+ ) {
85
+ watch()
86
+ }
87
+
88
+ // check for version updates
89
+ await installation.checkInstallVersion()
90
+
91
+ // get the references to the queue promises, don't await as
92
+ // they will never end, unless the processing stops
93
+ let queuePromises = []
94
+ // configure events to use the pro audit log write
95
+ // can't integrate directly into backend-core due to cyclic issues
96
+ queuePromises.push(events.processors.init(pro.sdk.auditLogs.write))
97
+ queuePromises.push(automations.init())
98
+ queuePromises.push(initPro())
99
+ if (app) {
100
+ // bring routes online as final step once everything ready
101
+ await initRoutes(app)
102
+ }
103
+
76
104
  // check and create admin user if required
105
+ // this must be run after the api has been initialised due to
106
+ // the app user sync
77
107
  if (
78
108
  env.SELF_HOSTED &&
79
109
  !env.MULTI_TENANCY &&
@@ -100,34 +130,8 @@ export async function startup(app?: any, server?: any) {
100
130
  )
101
131
  } catch (e) {
102
132
  logging.logAlert("Error creating initial admin user. Exiting.", e)
103
- shutdown()
133
+ shutdown(server)
104
134
  }
105
135
  }
106
136
  }
107
-
108
- // monitor plugin directory if required
109
- if (
110
- env.SELF_HOSTED &&
111
- !env.MULTI_TENANCY &&
112
- env.PLUGINS_DIR &&
113
- fs.existsSync(env.PLUGINS_DIR)
114
- ) {
115
- watch()
116
- }
117
-
118
- // check for version updates
119
- await installation.checkInstallVersion()
120
-
121
- // get the references to the queue promises, don't await as
122
- // they will never end, unless the processing stops
123
- let queuePromises = []
124
- // configure events to use the pro audit log write
125
- // can't integrate directly into backend-core due to cyclic issues
126
- queuePromises.push(events.processors.init(pro.sdk.auditLogs.write))
127
- queuePromises.push(automations.init())
128
- queuePromises.push(initPro())
129
- if (app) {
130
- // bring routes online as final step once everything ready
131
- await initRoutes(app)
132
- }
133
137
  }
@@ -1,35 +0,0 @@
1
- /******************************************************
2
- * This script just makes it easy to re-create *
3
- * a cypress like environment for testing the backend *
4
- ******************************************************/
5
- import path from "path"
6
- const tmpdir = path.join(require("os").tmpdir(), ".budibase")
7
-
8
- const SERVER_PORT = "4100"
9
- const WORKER_PORT = "4200"
10
-
11
- // @ts-ignore
12
- process.env.NODE_ENV = "cypress"
13
- process.env.ENABLE_ANALYTICS = "0"
14
- process.env.JWT_SECRET = "budibase"
15
- process.env.COUCH_URL = `leveldb://${tmpdir}/.data/`
16
- process.env.SELF_HOSTED = "1"
17
- process.env.WORKER_URL = `http://localhost:${WORKER_PORT}/`
18
- process.env.MINIO_URL = `http://localhost:4004`
19
- process.env.MINIO_ACCESS_KEY = "budibase"
20
- process.env.MINIO_SECRET_KEY = "budibase"
21
- process.env.COUCH_DB_USER = "budibase"
22
- process.env.COUCH_DB_PASSWORD = "budibase"
23
- process.env.INTERNAL_API_KEY = "budibase"
24
- process.env.ALLOW_DEV_AUTOMATIONS = "1"
25
-
26
- // don't make this a variable or top level require
27
- // it will cause environment module to be loaded prematurely
28
-
29
- // override the port with the worker port temporarily
30
- process.env.PORT = WORKER_PORT
31
- const worker = require("../../worker/src/index")
32
-
33
- // override the port with the server port
34
- process.env.PORT = SERVER_PORT
35
- const server = require("../src/app")