@budibase/worker 2.1.22-alpha.6 → 2.1.22-alpha.8

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 (123) hide show
  1. package/coverage/clover.xml +326 -305
  2. package/coverage/coverage-final.json +13 -13
  3. package/coverage/lcov-report/index.html +34 -34
  4. package/coverage/lcov-report/src/api/controllers/global/auth.ts.html +50 -38
  5. package/coverage/lcov-report/src/api/controllers/global/configs.js.html +18 -18
  6. package/coverage/lcov-report/src/api/controllers/global/email.js.html +1 -1
  7. package/coverage/lcov-report/src/api/controllers/global/index.html +10 -10
  8. package/coverage/lcov-report/src/api/controllers/global/license.ts.html +1 -1
  9. package/coverage/lcov-report/src/api/controllers/global/roles.js.html +1 -1
  10. package/coverage/lcov-report/src/api/controllers/global/self.ts.html +3 -3
  11. package/coverage/lcov-report/src/api/controllers/global/templates.ts.html +1 -1
  12. package/coverage/lcov-report/src/api/controllers/global/users.ts.html +1 -1
  13. package/coverage/lcov-report/src/api/controllers/global/workspaces.js.html +1 -1
  14. package/coverage/lcov-report/src/api/controllers/system/accounts.ts.html +1 -1
  15. package/coverage/lcov-report/src/api/controllers/system/environment.ts.html +1 -1
  16. package/coverage/lcov-report/src/api/controllers/system/index.html +1 -1
  17. package/coverage/lcov-report/src/api/controllers/system/migrations.ts.html +1 -1
  18. package/coverage/lcov-report/src/api/controllers/system/restore.ts.html +1 -1
  19. package/coverage/lcov-report/src/api/controllers/system/status.ts.html +1 -1
  20. package/coverage/lcov-report/src/api/controllers/system/tenants.ts.html +1 -1
  21. package/coverage/lcov-report/src/api/index.html +1 -1
  22. package/coverage/lcov-report/src/api/index.ts.html +1 -1
  23. package/coverage/lcov-report/src/api/routes/global/auth.js.html +1 -1
  24. package/coverage/lcov-report/src/api/routes/global/configs.js.html +10 -10
  25. package/coverage/lcov-report/src/api/routes/global/email.js.html +1 -1
  26. package/coverage/lcov-report/src/api/routes/global/index.html +1 -1
  27. package/coverage/lcov-report/src/api/routes/global/license.ts.html +1 -1
  28. package/coverage/lcov-report/src/api/routes/global/roles.js.html +1 -1
  29. package/coverage/lcov-report/src/api/routes/global/self.ts.html +1 -1
  30. package/coverage/lcov-report/src/api/routes/global/templates.ts.html +3 -3
  31. package/coverage/lcov-report/src/api/routes/global/users.js.html +1 -1
  32. package/coverage/lcov-report/src/api/routes/global/workspaces.js.html +1 -1
  33. package/coverage/lcov-report/src/api/routes/index.html +1 -1
  34. package/coverage/lcov-report/src/api/routes/index.ts.html +1 -1
  35. package/coverage/lcov-report/src/api/routes/system/accounts.ts.html +1 -1
  36. package/coverage/lcov-report/src/api/routes/system/environment.ts.html +1 -1
  37. package/coverage/lcov-report/src/api/routes/system/index.html +1 -1
  38. package/coverage/lcov-report/src/api/routes/system/migrations.ts.html +1 -1
  39. package/coverage/lcov-report/src/api/routes/system/restore.ts.html +1 -1
  40. package/coverage/lcov-report/src/api/routes/system/status.ts.html +1 -1
  41. package/coverage/lcov-report/src/api/routes/system/tenants.ts.html +1 -1
  42. package/coverage/lcov-report/src/api/routes/validation/index.html +1 -1
  43. package/coverage/lcov-report/src/api/routes/validation/index.ts.html +1 -1
  44. package/coverage/lcov-report/src/api/routes/validation/users.ts.html +1 -1
  45. package/coverage/lcov-report/src/constants/index.html +10 -10
  46. package/coverage/lcov-report/src/constants/{index.js.html → index.ts.html} +92 -113
  47. package/coverage/lcov-report/src/constants/templates/index.html +1 -1
  48. package/coverage/lcov-report/src/constants/templates/index.js.html +3 -3
  49. package/coverage/lcov-report/src/db/index.html +1 -1
  50. package/coverage/lcov-report/src/db/index.ts.html +1 -1
  51. package/coverage/lcov-report/src/environment.ts.html +1 -1
  52. package/coverage/lcov-report/src/index.html +1 -1
  53. package/coverage/lcov-report/src/index.ts.html +1 -1
  54. package/coverage/lcov-report/src/middleware/cloudRestricted.js.html +3 -3
  55. package/coverage/lcov-report/src/middleware/index.html +1 -1
  56. package/coverage/lcov-report/src/migrations/functions/globalInfoSyncUsers.ts.html +1 -1
  57. package/coverage/lcov-report/src/migrations/functions/index.html +1 -1
  58. package/coverage/lcov-report/src/migrations/index.html +1 -1
  59. package/coverage/lcov-report/src/migrations/index.ts.html +1 -1
  60. package/coverage/lcov-report/src/sdk/accounts/accounts.ts.html +1 -1
  61. package/coverage/lcov-report/src/sdk/accounts/index.html +1 -1
  62. package/coverage/lcov-report/src/sdk/accounts/index.ts.html +1 -1
  63. package/coverage/lcov-report/src/sdk/index.html +1 -1
  64. package/coverage/lcov-report/src/sdk/index.ts.html +1 -1
  65. package/coverage/lcov-report/src/sdk/users/events.ts.html +1 -1
  66. package/coverage/lcov-report/src/sdk/users/index.html +1 -1
  67. package/coverage/lcov-report/src/sdk/users/index.ts.html +1 -1
  68. package/coverage/lcov-report/src/sdk/users/users.ts.html +1 -1
  69. package/coverage/lcov-report/src/tests/TestConfiguration.ts.html +31 -22
  70. package/coverage/lcov-report/src/tests/api/accounts.ts.html +1 -1
  71. package/coverage/lcov-report/src/tests/api/auth.ts.html +1 -1
  72. package/coverage/lcov-report/src/tests/api/base.ts.html +1 -1
  73. package/coverage/lcov-report/src/tests/api/configs.ts.html +1 -1
  74. package/coverage/lcov-report/src/tests/api/email.ts.html +1 -1
  75. package/coverage/lcov-report/src/tests/api/environment.ts.html +1 -1
  76. package/coverage/lcov-report/src/tests/api/index.html +1 -1
  77. package/coverage/lcov-report/src/tests/api/index.ts.html +1 -1
  78. package/coverage/lcov-report/src/tests/api/migrations.ts.html +1 -1
  79. package/coverage/lcov-report/src/tests/api/restore.ts.html +1 -1
  80. package/coverage/lcov-report/src/tests/api/self.ts.html +1 -1
  81. package/coverage/lcov-report/src/tests/api/status.ts.html +1 -1
  82. package/coverage/lcov-report/src/tests/api/tenants.ts.html +1 -1
  83. package/coverage/lcov-report/src/tests/api/users.ts.html +1 -1
  84. package/coverage/lcov-report/src/tests/controllers.js.html +1 -1
  85. package/coverage/lcov-report/src/tests/index.html +15 -15
  86. package/coverage/lcov-report/src/tests/index.ts.html +1 -1
  87. package/coverage/lcov-report/src/tests/mocks/email.js.html +1 -1
  88. package/coverage/lcov-report/src/tests/mocks/index.html +1 -1
  89. package/coverage/lcov-report/src/tests/mocks/index.ts.html +1 -1
  90. package/coverage/lcov-report/src/tests/structures/configs.js.html +7 -7
  91. package/coverage/lcov-report/src/tests/structures/groups.ts.html +1 -1
  92. package/coverage/lcov-report/src/tests/structures/index.html +1 -1
  93. package/coverage/lcov-report/src/tests/structures/index.ts.html +1 -1
  94. package/coverage/lcov-report/src/tests/structures/users.ts.html +1 -1
  95. package/coverage/lcov-report/src/utilities/appService.js.html +4 -4
  96. package/coverage/lcov-report/src/utilities/{email.js.html → email.ts.html} +160 -61
  97. package/coverage/lcov-report/src/utilities/fileSystem.js.html +1 -1
  98. package/coverage/lcov-report/src/utilities/index.html +23 -23
  99. package/coverage/lcov-report/src/utilities/index.js.html +1 -1
  100. package/coverage/lcov-report/src/utilities/{redis.js.html → redis.ts.html} +53 -38
  101. package/coverage/lcov-report/src/utilities/{templates.js.html → templates.ts.html} +38 -38
  102. package/coverage/lcov-report/src/utilities/users.js.html +1 -1
  103. package/coverage/lcov.info +593 -529
  104. package/jest.config.ts +1 -0
  105. package/package.json +6 -6
  106. package/src/api/controllers/global/auth.ts +34 -30
  107. package/src/api/controllers/global/configs.js +17 -17
  108. package/src/api/controllers/global/self.ts +2 -2
  109. package/src/api/routes/global/configs.js +9 -9
  110. package/src/api/routes/global/templates.ts +2 -2
  111. package/src/api/routes/global/tests/configs.spec.ts +29 -29
  112. package/src/constants/{index.js → index.ts} +57 -64
  113. package/src/constants/templates/index.js +2 -2
  114. package/src/middleware/cloudRestricted.js +2 -2
  115. package/src/middleware/tests/tenancy.spec.ts +7 -7
  116. package/src/tests/TestConfiguration.ts +15 -12
  117. package/src/tests/structures/configs.js +6 -6
  118. package/src/utilities/appService.js +3 -3
  119. package/src/utilities/{email.js → email.ts} +78 -45
  120. package/src/utilities/{redis.js → redis.ts} +29 -24
  121. package/src/utilities/templates.ts +49 -0
  122. package/tsconfig.build.json +3 -3
  123. package/src/utilities/templates.js +0 -49
package/jest.config.ts CHANGED
@@ -15,6 +15,7 @@ if (!process.env.CI) {
15
15
  "@budibase/backend-core/(.*)": "<rootDir>/../backend-core/$1",
16
16
  "@budibase/backend-core": "<rootDir>/../backend-core/src",
17
17
  "@budibase/types": "<rootDir>/../types/src",
18
+ "^axios.*$": "<rootDir>/node_modules/axios/lib/axios.js",
18
19
  }
19
20
  // add pro sources if they exist
20
21
  if (fs.existsSync("../../../budibase-pro")) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@budibase/worker",
3
3
  "email": "hi@budibase.com",
4
- "version": "2.1.22-alpha.6",
4
+ "version": "2.1.22-alpha.8",
5
5
  "description": "Budibase background service",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -36,10 +36,10 @@
36
36
  "author": "Budibase",
37
37
  "license": "GPL-3.0",
38
38
  "dependencies": {
39
- "@budibase/backend-core": "2.1.22-alpha.6",
40
- "@budibase/pro": "2.1.22-alpha.5",
41
- "@budibase/string-templates": "2.1.22-alpha.6",
42
- "@budibase/types": "2.1.22-alpha.6",
39
+ "@budibase/backend-core": "2.1.22-alpha.8",
40
+ "@budibase/pro": "2.1.22-alpha.7",
41
+ "@budibase/string-templates": "2.1.22-alpha.8",
42
+ "@budibase/types": "2.1.22-alpha.8",
43
43
  "@koa/router": "8.0.8",
44
44
  "@sentry/node": "6.17.7",
45
45
  "@techpass/passport-openidconnect": "0.3.2",
@@ -94,5 +94,5 @@
94
94
  "typescript": "4.7.3",
95
95
  "update-dotenv": "1.1.1"
96
96
  },
97
- "gitHead": "395a9a21c27c534fd2b4297f5d0d19a341089993"
97
+ "gitHead": "d9dff5c7adfbef3147b2fa5370894efd1e40a7e5"
98
98
  }
@@ -1,22 +1,26 @@
1
1
  import core from "@budibase/backend-core"
2
- const { Configs, EmailTemplatePurpose } = require("../../../constants")
3
- const { sendEmail, isEmailConfigured } = require("../../../utilities/email")
4
- const { setCookie, getCookie, clearCookie, hash, platformLogout } = core.utils
5
- const { Cookies, Headers } = core.constants
6
- const { passport, ssoCallbackUrl, google, oidc } = core.auth
7
- const { checkResetPasswordCode } = require("../../../utilities/redis")
8
- const { getGlobalDB } = require("@budibase/backend-core/tenancy")
9
- const env = require("../../../environment")
10
- import { events, users as usersCore, context } from "@budibase/backend-core"
2
+ import {
3
+ events,
4
+ users as usersCore,
5
+ context,
6
+ tenancy,
7
+ } from "@budibase/backend-core"
8
+ import { Config, EmailTemplatePurpose } from "../../../constants"
9
+ import { sendEmail, isEmailConfigured } from "../../../utilities/email"
10
+ import { checkResetPasswordCode } from "../../../utilities/redis"
11
+ import env from "../../../environment"
11
12
  import sdk from "../../../sdk"
12
13
  import { User } from "@budibase/types"
14
+ const { setCookie, getCookie, clearCookie, hash, platformLogout } = core.utils
15
+ const { Cookie, Header } = core.constants
16
+ const { passport, ssoCallbackUrl, google, oidc } = core.auth
13
17
 
14
18
  export const googleCallbackUrl = async (config: any) => {
15
- return ssoCallbackUrl(getGlobalDB(), config, "google")
19
+ return ssoCallbackUrl(tenancy.getGlobalDB(), config, "google")
16
20
  }
17
21
 
18
22
  export const oidcCallbackUrl = async (config: any) => {
19
- return ssoCallbackUrl(getGlobalDB(), config, "oidc")
23
+ return ssoCallbackUrl(tenancy.getGlobalDB(), config, "oidc")
20
24
  }
21
25
 
22
26
  async function authInternal(ctx: any, user: any, err = null, info = null) {
@@ -30,13 +34,13 @@ async function authInternal(ctx: any, user: any, err = null, info = null) {
30
34
  }
31
35
 
32
36
  // set a cookie for browser access
33
- setCookie(ctx, user.token, Cookies.Auth, { sign: false })
37
+ setCookie(ctx, user.token, Cookie.Auth, { sign: false })
34
38
  // set the token in a header as well for APIs
35
- ctx.set(Headers.TOKEN, user.token)
39
+ ctx.set(Header.TOKEN, user.token)
36
40
  // get rid of any app cookies on login
37
41
  // have to check test because this breaks cypress
38
42
  if (!env.isTest()) {
39
- clearCookie(ctx, Cookies.CurrentApp)
43
+ clearCookie(ctx, Cookie.CurrentApp)
40
44
  }
41
45
  }
42
46
 
@@ -55,15 +59,15 @@ export const authenticate = async (ctx: any, next: any) => {
55
59
 
56
60
  export const setInitInfo = (ctx: any) => {
57
61
  const initInfo = ctx.request.body
58
- setCookie(ctx, initInfo, Cookies.Init)
62
+ setCookie(ctx, initInfo, Cookie.Init)
59
63
  ctx.status = 200
60
64
  }
61
65
 
62
66
  export const getInitInfo = (ctx: any) => {
63
67
  try {
64
- ctx.body = getCookie(ctx, Cookies.Init) || {}
68
+ ctx.body = getCookie(ctx, Cookie.Init) || {}
65
69
  } catch (err) {
66
- clearCookie(ctx, Cookies.Init)
70
+ clearCookie(ctx, Cookie.Init)
67
71
  ctx.body = {}
68
72
  }
69
73
  }
@@ -106,7 +110,7 @@ export const resetUpdate = async (ctx: any) => {
106
110
  const { resetCode, password } = ctx.request.body
107
111
  try {
108
112
  const { userId } = await checkResetPasswordCode(resetCode)
109
- const db = getGlobalDB()
113
+ const db = tenancy.getGlobalDB()
110
114
  const user = await db.get(userId)
111
115
  user.password = await hash(password)
112
116
  await db.put(user)
@@ -141,14 +145,14 @@ export const datasourcePreAuth = async (ctx: any, next: any) => {
141
145
  appId: ctx.query.appId,
142
146
  datasourceId: ctx.query.datasourceId,
143
147
  },
144
- Cookies.DatasourceAuth
148
+ Cookie.DatasourceAuth
145
149
  )
146
150
 
147
151
  return handler.preAuth(passport, ctx, next)
148
152
  }
149
153
 
150
154
  export const datasourceAuth = async (ctx: any, next: any) => {
151
- const authStateCookie = getCookie(ctx, Cookies.DatasourceAuth)
155
+ const authStateCookie = getCookie(ctx, Cookie.DatasourceAuth)
152
156
  const provider = authStateCookie.provider
153
157
  const middleware = require(`@budibase/backend-core/middleware`)
154
158
  const handler = middleware.datasource[provider]
@@ -160,10 +164,10 @@ export const datasourceAuth = async (ctx: any, next: any) => {
160
164
  * On a successful login, you will be redirected to the googleAuth callback route.
161
165
  */
162
166
  export const googlePreAuth = async (ctx: any, next: any) => {
163
- const db = getGlobalDB()
167
+ const db = tenancy.getGlobalDB()
164
168
 
165
169
  const config = await core.db.getScopedConfig(db, {
166
- type: Configs.GOOGLE,
170
+ type: Config.GOOGLE,
167
171
  workspace: ctx.query.workspace,
168
172
  })
169
173
  let callbackUrl = await exports.googleCallbackUrl(config)
@@ -181,10 +185,10 @@ export const googlePreAuth = async (ctx: any, next: any) => {
181
185
  }
182
186
 
183
187
  export const googleAuth = async (ctx: any, next: any) => {
184
- const db = getGlobalDB()
188
+ const db = tenancy.getGlobalDB()
185
189
 
186
190
  const config = await core.db.getScopedConfig(db, {
187
- type: Configs.GOOGLE,
191
+ type: Config.GOOGLE,
188
192
  workspace: ctx.query.workspace,
189
193
  })
190
194
  const callbackUrl = await exports.googleCallbackUrl(config)
@@ -208,9 +212,9 @@ export const googleAuth = async (ctx: any, next: any) => {
208
212
  }
209
213
 
210
214
  export const oidcStrategyFactory = async (ctx: any, configId: any) => {
211
- const db = getGlobalDB()
215
+ const db = tenancy.getGlobalDB()
212
216
  const config = await core.db.getScopedConfig(db, {
213
- type: Configs.OIDC,
217
+ type: Config.OIDC,
214
218
  group: ctx.query.group,
215
219
  })
216
220
 
@@ -233,11 +237,11 @@ export const oidcPreAuth = async (ctx: any, next: any) => {
233
237
  const { configId } = ctx.params
234
238
  const strategy = await oidcStrategyFactory(ctx, configId)
235
239
 
236
- setCookie(ctx, configId, Cookies.OIDC_CONFIG)
240
+ setCookie(ctx, configId, Cookie.OIDC_CONFIG)
237
241
 
238
- const db = getGlobalDB()
242
+ const db = tenancy.getGlobalDB()
239
243
  const config = await core.db.getScopedConfig(db, {
240
- type: Configs.OIDC,
244
+ type: Config.OIDC,
241
245
  group: ctx.query.group,
242
246
  })
243
247
 
@@ -255,7 +259,7 @@ export const oidcPreAuth = async (ctx: any, next: any) => {
255
259
  }
256
260
 
257
261
  export const oidcAuth = async (ctx: any, next: any) => {
258
- const configId = getCookie(ctx, Cookies.OIDC_CONFIG)
262
+ const configId = getCookie(ctx, Cookie.OIDC_CONFIG)
259
263
  const strategy = await oidcStrategyFactory(ctx, configId)
260
264
 
261
265
  return passport.authenticate(
@@ -4,7 +4,7 @@ const {
4
4
  getScopedFullConfig,
5
5
  getAllApps,
6
6
  } = require("@budibase/backend-core/db")
7
- const { Configs } = require("../../../constants")
7
+ const { Config } = require("../../../constants")
8
8
  const email = require("../../../utilities/email")
9
9
  const {
10
10
  upload,
@@ -33,25 +33,25 @@ const getEventFns = async (db, config) => {
33
33
 
34
34
  if (!existing) {
35
35
  switch (config.type) {
36
- case Configs.SMTP: {
36
+ case Config.SMTP: {
37
37
  fns.push(events.email.SMTPCreated)
38
38
  break
39
39
  }
40
- case Configs.GOOGLE: {
40
+ case Config.GOOGLE: {
41
41
  fns.push(() => events.auth.SSOCreated(type))
42
42
  if (config.config.activated) {
43
43
  fns.push(() => events.auth.SSOActivated(type))
44
44
  }
45
45
  break
46
46
  }
47
- case Configs.OIDC: {
47
+ case Config.OIDC: {
48
48
  fns.push(() => events.auth.SSOCreated(type))
49
49
  if (config.config.configs[0].activated) {
50
50
  fns.push(() => events.auth.SSOActivated(type))
51
51
  }
52
52
  break
53
53
  }
54
- case Configs.SETTINGS: {
54
+ case Config.SETTINGS: {
55
55
  // company
56
56
  const company = config.config.company
57
57
  if (company && company !== "Budibase") {
@@ -78,11 +78,11 @@ const getEventFns = async (db, config) => {
78
78
  }
79
79
  } else {
80
80
  switch (config.type) {
81
- case Configs.SMTP: {
81
+ case Config.SMTP: {
82
82
  fns.push(events.email.SMTPUpdated)
83
83
  break
84
84
  }
85
- case Configs.GOOGLE: {
85
+ case Config.GOOGLE: {
86
86
  fns.push(() => events.auth.SSOUpdated(type))
87
87
  if (!existing.config.activated && config.config.activated) {
88
88
  fns.push(() => events.auth.SSOActivated(type))
@@ -91,7 +91,7 @@ const getEventFns = async (db, config) => {
91
91
  }
92
92
  break
93
93
  }
94
- case Configs.OIDC: {
94
+ case Config.OIDC: {
95
95
  fns.push(() => events.auth.SSOUpdated(type))
96
96
  if (
97
97
  !existing.config.configs[0].activated &&
@@ -106,7 +106,7 @@ const getEventFns = async (db, config) => {
106
106
  }
107
107
  break
108
108
  }
109
- case Configs.SETTINGS: {
109
+ case Config.SETTINGS: {
110
110
  // company
111
111
  const existingCompany = existing.config.company
112
112
  const company = config.config.company
@@ -155,7 +155,7 @@ exports.save = async function (ctx) {
155
155
  try {
156
156
  // verify the configuration
157
157
  switch (type) {
158
- case Configs.SMTP:
158
+ case Config.SMTP:
159
159
  await email.verifyConfig(config)
160
160
  break
161
161
  }
@@ -237,7 +237,7 @@ exports.publicOidc = async function (ctx) {
237
237
  try {
238
238
  // Find the config with the most granular scope based on context
239
239
  const oidcConfig = await getScopedFullConfig(db, {
240
- type: Configs.OIDC,
240
+ type: Config.OIDC,
241
241
  })
242
242
 
243
243
  if (!oidcConfig) {
@@ -260,15 +260,15 @@ exports.publicSettings = async function (ctx) {
260
260
  try {
261
261
  // Find the config with the most granular scope based on context
262
262
  const publicConfig = await getScopedFullConfig(db, {
263
- type: Configs.SETTINGS,
263
+ type: Config.SETTINGS,
264
264
  })
265
265
 
266
266
  const googleConfig = await getScopedFullConfig(db, {
267
- type: Configs.GOOGLE,
267
+ type: Config.GOOGLE,
268
268
  })
269
269
 
270
270
  const oidcConfig = await getScopedFullConfig(db, {
271
- type: Configs.OIDC,
271
+ type: Config.OIDC,
272
272
  })
273
273
 
274
274
  let config
@@ -390,17 +390,17 @@ exports.configChecklist = async function (ctx) {
390
390
 
391
391
  // They have set up SMTP
392
392
  const smtpConfig = await getScopedFullConfig(db, {
393
- type: Configs.SMTP,
393
+ type: Config.SMTP,
394
394
  })
395
395
 
396
396
  // They have set up Google Auth
397
397
  const googleConfig = await getScopedFullConfig(db, {
398
- type: Configs.GOOGLE,
398
+ type: Config.GOOGLE,
399
399
  })
400
400
 
401
401
  // They have set up OIDC
402
402
  const oidcConfig = await getScopedFullConfig(db, {
403
- type: Configs.OIDC,
403
+ type: Config.OIDC,
404
404
  })
405
405
 
406
406
  // They have set up an global user
@@ -73,12 +73,12 @@ export async function fetchAPIKey(ctx: any) {
73
73
  }
74
74
 
75
75
  const checkCurrentApp = (ctx: any) => {
76
- const appCookie = getCookie(ctx, constants.Cookies.CurrentApp)
76
+ const appCookie = getCookie(ctx, constants.Cookie.CurrentApp)
77
77
  if (appCookie && !tenancy.isUserInAppTenant(appCookie.appId)) {
78
78
  // there is a currentapp cookie from another tenant
79
79
  // remove the cookie as this is incompatible with the builder
80
80
  // due to builder and admin permissions being removed
81
- clearCookie(ctx, constants.Cookies.CurrentApp)
81
+ clearCookie(ctx, constants.Cookie.CurrentApp)
82
82
  }
83
83
  }
84
84
 
@@ -3,7 +3,7 @@ const controller = require("../../controllers/global/configs")
3
3
  const { joiValidator } = require("@budibase/backend-core/auth")
4
4
  const { adminOnly } = require("@budibase/backend-core/auth")
5
5
  const Joi = require("joi")
6
- const { Configs } = require("../../../constants")
6
+ const { Config } = require("../../../constants")
7
7
 
8
8
  const router = new Router()
9
9
 
@@ -65,17 +65,17 @@ function buildConfigSaveValidation() {
65
65
  _id: Joi.string().optional(),
66
66
  _rev: Joi.string().optional(),
67
67
  workspace: Joi.string().optional(),
68
- type: Joi.string().valid(...Object.values(Configs)).required(),
68
+ type: Joi.string().valid(...Object.values(Config)).required(),
69
69
  createdAt: Joi.string().optional(),
70
70
  updatedAt: Joi.string().optional(),
71
71
  config: Joi.alternatives()
72
72
  .conditional("type", {
73
73
  switch: [
74
- { is: Configs.SMTP, then: smtpValidation() },
75
- { is: Configs.SETTINGS, then: settingValidation() },
76
- { is: Configs.ACCOUNT, then: Joi.object().unknown(true) },
77
- { is: Configs.GOOGLE, then: googleValidation() },
78
- { is: Configs.OIDC, then: oidcValidation() }
74
+ { is: Config.SMTP, then: smtpValidation() },
75
+ { is: Config.SETTINGS, then: settingValidation() },
76
+ { is: Config.ACCOUNT, then: Joi.object().unknown(true) },
77
+ { is: Config.GOOGLE, then: googleValidation() },
78
+ { is: Config.OIDC, then: oidcValidation() }
79
79
  ],
80
80
  }),
81
81
  }).required().unknown(true),
@@ -85,7 +85,7 @@ function buildConfigSaveValidation() {
85
85
  function buildUploadValidation() {
86
86
  // prettier-ignore
87
87
  return joiValidator.params(Joi.object({
88
- type: Joi.string().valid(...Object.values(Configs)).required(),
88
+ type: Joi.string().valid(...Object.values(Config)).required(),
89
89
  name: Joi.string().required(),
90
90
  }).required().unknown(true))
91
91
  }
@@ -93,7 +93,7 @@ function buildUploadValidation() {
93
93
  function buildConfigGetValidation() {
94
94
  // prettier-ignore
95
95
  return joiValidator.params(Joi.object({
96
- type: Joi.string().valid(...Object.values(Configs)).required()
96
+ type: Joi.string().valid(...Object.values(Config)).required()
97
97
  }).required().unknown(true))
98
98
  }
99
99
 
@@ -1,6 +1,6 @@
1
1
  import Router from "@koa/router"
2
2
  import * as controller from "../../controllers/global/templates"
3
- import { TemplatePurpose, TemplateTypes } from "../../../constants"
3
+ import { TemplatePurpose, TemplateType } from "../../../constants"
4
4
  import { auth as authCore } from "@budibase/backend-core"
5
5
  import Joi from "joi"
6
6
  const { adminOnly, joiValidator } = authCore
@@ -16,7 +16,7 @@ function buildTemplateSaveValidation() {
16
16
  name: Joi.string().allow(null, ""),
17
17
  contents: Joi.string().required(),
18
18
  purpose: Joi.string().required().valid(...Object.values(TemplatePurpose)),
19
- type: Joi.string().required().valid(...Object.values(TemplateTypes)),
19
+ type: Joi.string().required().valid(...Object.values(TemplateType)),
20
20
  }).required().unknown(true).optional())
21
21
  }
22
22
 
@@ -2,7 +2,7 @@
2
2
  jest.mock("nodemailer")
3
3
  import { TestConfiguration, structures, mocks } from "../../../../tests"
4
4
  mocks.email.mock()
5
- import { Configs, events } from "@budibase/backend-core"
5
+ import { Config, events } from "@budibase/backend-core"
6
6
 
7
7
  describe("configs", () => {
8
8
  const config = new TestConfiguration()
@@ -49,20 +49,20 @@ describe("configs", () => {
49
49
  it("should create activated google config", async () => {
50
50
  await saveGoogleConfig()
51
51
  expect(events.auth.SSOCreated).toBeCalledTimes(1)
52
- expect(events.auth.SSOCreated).toBeCalledWith(Configs.GOOGLE)
52
+ expect(events.auth.SSOCreated).toBeCalledWith(Config.GOOGLE)
53
53
  expect(events.auth.SSODeactivated).not.toBeCalled()
54
54
  expect(events.auth.SSOActivated).toBeCalledTimes(1)
55
- expect(events.auth.SSOActivated).toBeCalledWith(Configs.GOOGLE)
56
- await config.deleteConfig(Configs.GOOGLE)
55
+ expect(events.auth.SSOActivated).toBeCalledWith(Config.GOOGLE)
56
+ await config.deleteConfig(Config.GOOGLE)
57
57
  })
58
58
 
59
59
  it("should create deactivated google config", async () => {
60
60
  await saveGoogleConfig({ activated: false })
61
61
  expect(events.auth.SSOCreated).toBeCalledTimes(1)
62
- expect(events.auth.SSOCreated).toBeCalledWith(Configs.GOOGLE)
62
+ expect(events.auth.SSOCreated).toBeCalledWith(Config.GOOGLE)
63
63
  expect(events.auth.SSOActivated).not.toBeCalled()
64
64
  expect(events.auth.SSODeactivated).not.toBeCalled()
65
- await config.deleteConfig(Configs.GOOGLE)
65
+ await config.deleteConfig(Config.GOOGLE)
66
66
  })
67
67
  })
68
68
 
@@ -76,11 +76,11 @@ describe("configs", () => {
76
76
  googleConf._rev
77
77
  )
78
78
  expect(events.auth.SSOUpdated).toBeCalledTimes(1)
79
- expect(events.auth.SSOUpdated).toBeCalledWith(Configs.GOOGLE)
79
+ expect(events.auth.SSOUpdated).toBeCalledWith(Config.GOOGLE)
80
80
  expect(events.auth.SSOActivated).not.toBeCalled()
81
81
  expect(events.auth.SSODeactivated).toBeCalledTimes(1)
82
- expect(events.auth.SSODeactivated).toBeCalledWith(Configs.GOOGLE)
83
- await config.deleteConfig(Configs.GOOGLE)
82
+ expect(events.auth.SSODeactivated).toBeCalledWith(Config.GOOGLE)
83
+ await config.deleteConfig(Config.GOOGLE)
84
84
  })
85
85
 
86
86
  it("should update google config to activated", async () => {
@@ -92,11 +92,11 @@ describe("configs", () => {
92
92
  googleConf._rev
93
93
  )
94
94
  expect(events.auth.SSOUpdated).toBeCalledTimes(1)
95
- expect(events.auth.SSOUpdated).toBeCalledWith(Configs.GOOGLE)
95
+ expect(events.auth.SSOUpdated).toBeCalledWith(Config.GOOGLE)
96
96
  expect(events.auth.SSODeactivated).not.toBeCalled()
97
97
  expect(events.auth.SSOActivated).toBeCalledTimes(1)
98
- expect(events.auth.SSOActivated).toBeCalledWith(Configs.GOOGLE)
99
- await config.deleteConfig(Configs.GOOGLE)
98
+ expect(events.auth.SSOActivated).toBeCalledWith(Config.GOOGLE)
99
+ await config.deleteConfig(Config.GOOGLE)
100
100
  })
101
101
  })
102
102
  })
@@ -115,20 +115,20 @@ describe("configs", () => {
115
115
  it("should create activated OIDC config", async () => {
116
116
  await saveOIDCConfig()
117
117
  expect(events.auth.SSOCreated).toBeCalledTimes(1)
118
- expect(events.auth.SSOCreated).toBeCalledWith(Configs.OIDC)
118
+ expect(events.auth.SSOCreated).toBeCalledWith(Config.OIDC)
119
119
  expect(events.auth.SSODeactivated).not.toBeCalled()
120
120
  expect(events.auth.SSOActivated).toBeCalledTimes(1)
121
- expect(events.auth.SSOActivated).toBeCalledWith(Configs.OIDC)
122
- await config.deleteConfig(Configs.OIDC)
121
+ expect(events.auth.SSOActivated).toBeCalledWith(Config.OIDC)
122
+ await config.deleteConfig(Config.OIDC)
123
123
  })
124
124
 
125
125
  it("should create deactivated OIDC config", async () => {
126
126
  await saveOIDCConfig({ activated: false })
127
127
  expect(events.auth.SSOCreated).toBeCalledTimes(1)
128
- expect(events.auth.SSOCreated).toBeCalledWith(Configs.OIDC)
128
+ expect(events.auth.SSOCreated).toBeCalledWith(Config.OIDC)
129
129
  expect(events.auth.SSOActivated).not.toBeCalled()
130
130
  expect(events.auth.SSODeactivated).not.toBeCalled()
131
- await config.deleteConfig(Configs.OIDC)
131
+ await config.deleteConfig(Config.OIDC)
132
132
  })
133
133
  })
134
134
 
@@ -142,11 +142,11 @@ describe("configs", () => {
142
142
  oidcConf._rev
143
143
  )
144
144
  expect(events.auth.SSOUpdated).toBeCalledTimes(1)
145
- expect(events.auth.SSOUpdated).toBeCalledWith(Configs.OIDC)
145
+ expect(events.auth.SSOUpdated).toBeCalledWith(Config.OIDC)
146
146
  expect(events.auth.SSOActivated).not.toBeCalled()
147
147
  expect(events.auth.SSODeactivated).toBeCalledTimes(1)
148
- expect(events.auth.SSODeactivated).toBeCalledWith(Configs.OIDC)
149
- await config.deleteConfig(Configs.OIDC)
148
+ expect(events.auth.SSODeactivated).toBeCalledWith(Config.OIDC)
149
+ await config.deleteConfig(Config.OIDC)
150
150
  })
151
151
 
152
152
  it("should update OIDC config to activated", async () => {
@@ -158,11 +158,11 @@ describe("configs", () => {
158
158
  oidcConf._rev
159
159
  )
160
160
  expect(events.auth.SSOUpdated).toBeCalledTimes(1)
161
- expect(events.auth.SSOUpdated).toBeCalledWith(Configs.OIDC)
161
+ expect(events.auth.SSOUpdated).toBeCalledWith(Config.OIDC)
162
162
  expect(events.auth.SSODeactivated).not.toBeCalled()
163
163
  expect(events.auth.SSOActivated).toBeCalledTimes(1)
164
- expect(events.auth.SSOActivated).toBeCalledWith(Configs.OIDC)
165
- await config.deleteConfig(Configs.OIDC)
164
+ expect(events.auth.SSOActivated).toBeCalledWith(Config.OIDC)
165
+ await config.deleteConfig(Config.OIDC)
166
166
  })
167
167
  })
168
168
  })
@@ -179,11 +179,11 @@ describe("configs", () => {
179
179
 
180
180
  describe("create", () => {
181
181
  it("should create SMTP config", async () => {
182
- await config.deleteConfig(Configs.SMTP)
182
+ await config.deleteConfig(Config.SMTP)
183
183
  await saveSMTPConfig()
184
184
  expect(events.email.SMTPUpdated).not.toBeCalled()
185
185
  expect(events.email.SMTPCreated).toBeCalledTimes(1)
186
- await config.deleteConfig(Configs.SMTP)
186
+ await config.deleteConfig(Config.SMTP)
187
187
  })
188
188
  })
189
189
 
@@ -194,7 +194,7 @@ describe("configs", () => {
194
194
  await saveSMTPConfig(smtpConf.config, smtpConf._id, smtpConf._rev)
195
195
  expect(events.email.SMTPCreated).not.toBeCalled()
196
196
  expect(events.email.SMTPUpdated).toBeCalledTimes(1)
197
- await config.deleteConfig(Configs.SMTP)
197
+ await config.deleteConfig(Config.SMTP)
198
198
  })
199
199
  })
200
200
  })
@@ -211,7 +211,7 @@ describe("configs", () => {
211
211
 
212
212
  describe("create", () => {
213
213
  it("should create settings config with default settings", async () => {
214
- await config.deleteConfig(Configs.SETTINGS)
214
+ await config.deleteConfig(Config.SETTINGS)
215
215
 
216
216
  await saveSettingsConfig()
217
217
 
@@ -222,7 +222,7 @@ describe("configs", () => {
222
222
 
223
223
  it("should create settings config with non-default settings", async () => {
224
224
  config.modeSelf()
225
- await config.deleteConfig(Configs.SETTINGS)
225
+ await config.deleteConfig(Config.SETTINGS)
226
226
  const conf = {
227
227
  company: "acme",
228
228
  logoUrl: "http://example.com",
@@ -241,7 +241,7 @@ describe("configs", () => {
241
241
  describe("update", () => {
242
242
  it("should update settings config", async () => {
243
243
  config.modeSelf()
244
- await config.deleteConfig(Configs.SETTINGS)
244
+ await config.deleteConfig(Config.SETTINGS)
245
245
  const settingsConfig = await saveSettingsConfig()
246
246
  settingsConfig.config.company = "acme"
247
247
  settingsConfig.config.logoUrl = "http://example.com"