@budibase/worker 3.13.22 → 3.13.24

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/worker",
3
3
  "email": "hi@budibase.com",
4
- "version": "3.13.22",
4
+ "version": "3.13.24",
5
5
  "description": "Budibase background service",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -114,5 +114,5 @@
114
114
  }
115
115
  }
116
116
  },
117
- "gitHead": "72110c606f8b12bbf037346388c63d682c1aa9c0"
117
+ "gitHead": "9dea790829ad44142eb0baa2bfa7fb7a5d3531ad"
118
118
  }
@@ -0,0 +1 @@
1
+ export * from "./standard"
@@ -0,0 +1,22 @@
1
+ import cloudRestricted from "../../../middleware/cloudRestricted"
2
+ import { auth, EndpointGroupList, middleware } from "@budibase/backend-core"
3
+
4
+ export const endpointGroupList = new EndpointGroupList()
5
+
6
+ export const builderOrAdminRoutes = endpointGroupList.group(auth.builderOrAdmin)
7
+ builderOrAdminRoutes.lockMiddleware()
8
+
9
+ export const builderRoutes = endpointGroupList.group(auth.builderOnly)
10
+ builderRoutes.lockMiddleware()
11
+
12
+ export const adminRoutes = endpointGroupList.group(auth.adminOnly)
13
+ adminRoutes.lockMiddleware()
14
+
15
+ export const cloudRestrictedRoutes = endpointGroupList.group(cloudRestricted)
16
+ cloudRestrictedRoutes.lockMiddleware()
17
+
18
+ export const internalRoutes = endpointGroupList.group(middleware.internalApi)
19
+ internalRoutes.lockMiddleware()
20
+
21
+ export const loggedInRoutes = endpointGroupList.group()
22
+ loggedInRoutes.lockMiddleware()
@@ -1,9 +1,7 @@
1
- import Router from "@koa/router"
2
1
  import * as authController from "../../controllers/global/auth"
3
2
  import { auth } from "@budibase/backend-core"
4
3
  import Joi from "joi"
5
-
6
- const router: Router = new Router()
4
+ import { loggedInRoutes } from "../endpointGroups"
7
5
 
8
6
  function buildAuthValidation() {
9
7
  // prettier-ignore
@@ -28,7 +26,7 @@ function buildResetUpdateValidation() {
28
26
  }).required().unknown(false))
29
27
  }
30
28
 
31
- router
29
+ loggedInRoutes
32
30
  // PASSWORD
33
31
  .post(
34
32
  "/api/global/auth/:tenantId/login",
@@ -87,5 +85,3 @@ router
87
85
  // OIDC - SINGLE TENANT - DEPRECATED
88
86
  .get("/api/global/auth/oidc/callback", authController.oidcCallback)
89
87
  .get("/api/admin/auth/oidc/callback", authController.oidcCallback)
90
-
91
- export default router
@@ -1,10 +1,8 @@
1
- import Router from "@koa/router"
2
1
  import * as controller from "../../controllers/global/configs"
3
2
  import { auth } from "@budibase/backend-core"
4
3
  import Joi from "joi"
5
4
  import { ConfigType } from "@budibase/types"
6
-
7
- const router: Router = new Router()
5
+ import { adminRoutes, loggedInRoutes } from "../endpointGroups"
8
6
 
9
7
  function smtpValidation() {
10
8
  // prettier-ignore
@@ -121,23 +119,17 @@ function buildConfigGetValidation() {
121
119
  }).required().unknown(true))
122
120
  }
123
121
 
124
- router
125
- .post(
126
- "/api/global/configs",
127
- auth.adminOnly,
128
- buildConfigSaveValidation(),
129
- controller.save
130
- )
131
- .delete("/api/global/configs/:id/:rev", auth.adminOnly, controller.destroy)
132
- .get("/api/global/configs/checklist", controller.configChecklist)
133
- .get("/api/global/configs/public", controller.publicSettings)
134
- .get("/api/global/configs/public/oidc", controller.publicOidc)
135
- .get("/api/global/configs/:type", buildConfigGetValidation(), controller.find)
122
+ adminRoutes
123
+ .post("/api/global/configs", buildConfigSaveValidation(), controller.save)
124
+ .delete("/api/global/configs/:id/:rev", controller.destroy)
136
125
  .post(
137
126
  "/api/global/configs/upload/:type/:name",
138
- auth.adminOnly,
139
127
  buildUploadValidation(),
140
128
  controller.upload
141
129
  )
142
130
 
143
- export default router
131
+ loggedInRoutes
132
+ .get("/api/global/configs/checklist", controller.configChecklist)
133
+ .get("/api/global/configs/public", controller.publicSettings)
134
+ .get("/api/global/configs/public/oidc", controller.publicOidc)
135
+ .get("/api/global/configs/:type", buildConfigGetValidation(), controller.find)
@@ -1,10 +1,8 @@
1
- import Router from "@koa/router"
2
1
  import * as controller from "../../controllers/global/email"
3
2
  import { auth } from "@budibase/backend-core"
4
3
  import { EmailTemplatePurpose } from "@budibase/types"
5
4
  import Joi from "joi"
6
-
7
- const router: Router = new Router()
5
+ import { adminRoutes } from "../endpointGroups"
8
6
 
9
7
  function buildEmailSendValidation() {
10
8
  // prettier-ignore
@@ -26,11 +24,8 @@ function buildEmailSendValidation() {
26
24
  }).required().unknown(true))
27
25
  }
28
26
 
29
- router.post(
27
+ adminRoutes.post(
30
28
  "/api/global/email/send",
31
29
  buildEmailSendValidation(),
32
- auth.adminOnly,
33
30
  controller.sendEmail
34
31
  )
35
-
36
- export default router
@@ -1,8 +1,4 @@
1
- import Router from "@koa/router"
2
1
  import * as controller from "../../controllers/global/events"
2
+ import { loggedInRoutes } from "../endpointGroups"
3
3
 
4
- const router: Router = new Router()
5
-
6
- router.post("/api/global/event/publish", controller.publish)
7
-
8
- export default router
4
+ loggedInRoutes.post("/api/global/event/publish", controller.publish)
@@ -1,7 +1,7 @@
1
- import Router from "@koa/router"
2
1
  import * as controller from "../../controllers/global/license"
3
2
  import { middleware } from "@budibase/backend-core"
4
3
  import Joi from "joi"
4
+ import { loggedInRoutes } from "../endpointGroups"
5
5
 
6
6
  const activateLicenseKeyValidator = middleware.joiValidator.body(
7
7
  Joi.object({
@@ -15,9 +15,7 @@ const activateOfflineLicenseValidator = middleware.joiValidator.body(
15
15
  }).required()
16
16
  )
17
17
 
18
- const router: Router = new Router()
19
-
20
- router
18
+ loggedInRoutes
21
19
  .post("/api/global/license/refresh", controller.refresh)
22
20
  .get("/api/global/license/usage", controller.getQuotaUsage)
23
21
  // LICENSE KEY
@@ -40,5 +38,3 @@ router
40
38
  "/api/global/license/offline/identifier",
41
39
  controller.getOfflineLicenseIdentifier
42
40
  )
43
-
44
- export default router
@@ -1,16 +1,7 @@
1
- import Router from "@koa/router"
2
1
  import * as controller from "../../controllers/global/roles"
3
- import { auth } from "@budibase/backend-core"
2
+ import { builderOrAdminRoutes } from "../endpointGroups"
4
3
 
5
- const router: Router = new Router()
6
-
7
- router
8
- .get("/api/global/roles", auth.builderOrAdmin, controller.fetch)
9
- .get("/api/global/roles/:appId", auth.builderOrAdmin, controller.find)
10
- .delete(
11
- "/api/global/roles/:appId",
12
- auth.builderOrAdmin,
13
- controller.removeAppRole
14
- )
15
-
16
- export default router
4
+ builderOrAdminRoutes
5
+ .get("/api/global/roles", controller.fetch)
6
+ .get("/api/global/roles/:appId", controller.find)
7
+ .delete("/api/global/roles/:appId", controller.removeAppRole)
@@ -1,18 +1,14 @@
1
- import Router from "@koa/router"
2
1
  import * as controller from "../../controllers/global/self"
3
- import { auth } from "@budibase/backend-core"
4
2
  import { users } from "../validation"
3
+ import { builderRoutes, loggedInRoutes } from "../endpointGroups"
4
+ builderRoutes
5
+ .post("/api/global/self/api_key", controller.generateAPIKey)
6
+ .get("/api/global/self/api_key", controller.fetchAPIKey)
5
7
 
6
- const router: Router = new Router()
7
-
8
- router
9
- .post("/api/global/self/api_key", auth.builderOnly, controller.generateAPIKey)
10
- .get("/api/global/self/api_key", auth.builderOnly, controller.fetchAPIKey)
8
+ loggedInRoutes
11
9
  .get("/api/global/self", controller.getSelf)
12
10
  .post(
13
11
  "/api/global/self",
14
12
  users.buildSelfSaveValidation(),
15
13
  controller.updateSelf
16
14
  )
17
-
18
- export default router
@@ -1,12 +1,10 @@
1
- import Router from "@koa/router"
2
1
  import * as controller from "../../controllers/global/templates"
3
2
  import { TemplatePurpose, TemplateType } from "../../../constants"
4
3
  import { auth as authCore } from "@budibase/backend-core"
4
+ import { loggedInRoutes, adminRoutes } from "../endpointGroups"
5
5
  import Joi from "joi"
6
6
 
7
- const { adminOnly, joiValidator } = authCore
8
-
9
- const router: Router = new Router()
7
+ const { joiValidator } = authCore
10
8
 
11
9
  function buildTemplateSaveValidation() {
12
10
  // prettier-ignore
@@ -21,19 +19,14 @@ function buildTemplateSaveValidation() {
21
19
  }).required().unknown(true).optional())
22
20
  }
23
21
 
24
- router
22
+ loggedInRoutes
25
23
  .get("/api/global/template/definitions", controller.definitions)
26
- .post(
27
- "/api/global/template",
28
- adminOnly,
29
- buildTemplateSaveValidation(),
30
- controller.save
31
- )
32
24
  .get("/api/global/template", controller.fetch)
33
25
  .get("/api/global/template/:type", controller.fetchByType)
34
26
  .get("/api/global/template/:ownerId", controller.fetchByOwner)
35
27
  .get("/api/global/template/:id", controller.find)
36
28
  .post("/api/global/template/:type/export", controller.exportTemplates)
37
- .delete("/api/global/template/:id/:rev", adminOnly, controller.destroy)
38
29
 
39
- export default router
30
+ adminRoutes
31
+ .post("/api/global/template", buildTemplateSaveValidation(), controller.save)
32
+ .delete("/api/global/template/:id/:rev", controller.destroy)
@@ -1,11 +1,14 @@
1
- import Router from "@koa/router"
2
1
  import * as controller from "../../controllers/global/users"
3
2
  import { auth } from "@budibase/backend-core"
4
3
  import Joi from "joi"
5
- import cloudRestricted from "../../../middleware/cloudRestricted"
6
4
  import { users } from "../validation"
5
+ import {
6
+ loggedInRoutes,
7
+ cloudRestrictedRoutes,
8
+ builderOrAdminRoutes,
9
+ adminRoutes,
10
+ } from "../endpointGroups"
7
11
 
8
- const router: Router = new Router()
9
12
  const OPTIONAL_STRING = Joi.string().optional().allow(null).allow("")
10
13
 
11
14
  function buildAdminInitValidation() {
@@ -69,92 +72,68 @@ function buildChangeTenantOwnerEmailValidation() {
69
72
  )
70
73
  }
71
74
 
72
- router
73
- .post(
74
- "/api/global/users",
75
- createUserAdminOnly,
76
- users.buildUserSaveValidation(),
77
- controller.save
78
- )
75
+ cloudRestrictedRoutes
79
76
  .post(
80
77
  "/api/global/users/sso",
81
- cloudRestricted,
82
78
  users.buildAddSsoSupport(),
83
79
  controller.addSsoSupport
84
80
  )
81
+ .post(
82
+ "/api/global/users/init",
83
+ buildAdminInitValidation(),
84
+ controller.adminUser
85
+ )
86
+ .put(
87
+ "/api/global/users/tenant/owner",
88
+ buildChangeTenantOwnerEmailValidation(),
89
+ controller.changeTenantOwnerEmail
90
+ )
91
+
92
+ adminRoutes
85
93
  .post(
86
94
  "/api/global/users/bulk",
87
- auth.adminOnly,
88
95
  users.buildUserBulkUserValidation(),
89
96
  controller.bulkUpdate
90
97
  )
98
+ .delete("/api/global/users/:id", controller.destroy)
91
99
 
92
- .get("/api/global/users", auth.builderOrAdmin, controller.fetch)
93
- // search can be used by any user now, to retrieve users for user column
94
- .post("/api/global/users/search", controller.search)
95
- .delete("/api/global/users/:id", auth.adminOnly, controller.destroy)
96
- .get(
97
- "/api/global/users/count/:appId",
98
- auth.builderOrAdmin,
99
- controller.countByApp
100
- )
101
- .get("/api/global/roles/:appId")
102
- .post(
103
- "/api/global/users/invite",
104
- auth.builderOrAdmin,
105
- buildInviteValidation(),
106
- controller.invite
107
- )
100
+ builderOrAdminRoutes
101
+ .get("/api/global/users", controller.fetch)
102
+ .get("/api/global/users/count/:appId", controller.countByApp)
103
+ .post("/api/global/users/invite", buildInviteValidation(), controller.invite)
108
104
  .post(
109
105
  "/api/global/users/onboard",
110
- auth.builderOrAdmin,
111
106
  buildInviteMultipleValidation(),
112
107
  controller.onboardUsers
113
108
  )
114
109
  .post(
115
110
  "/api/global/users/multi/invite",
116
- auth.builderOrAdmin,
117
111
  buildInviteMultipleValidation(),
118
112
  controller.inviteMultiple
119
113
  )
120
114
  .post(
121
115
  "/api/global/users/multi/invite/delete",
122
- auth.builderOrAdmin,
123
116
  controller.removeMultipleInvites
124
117
  )
118
+ .post("/api/global/users/invite/update/:code", controller.updateInvite)
119
+ .get("/api/global/users/invites", controller.getUserInvites)
120
+ .get("/api/global/users/:id", controller.find)
125
121
 
126
- // non-global endpoints
127
- .get("/api/global/users/invite/:code", controller.checkInvite)
122
+ loggedInRoutes
123
+ // search can be used by any user now, to retrieve users for user column
124
+ .post("/api/global/users/search", controller.search)
128
125
  .post(
129
- "/api/global/users/invite/update/:code",
130
- auth.builderOrAdmin,
131
- controller.updateInvite
132
- )
133
- .get(
134
- "/api/global/users/invites",
135
- auth.builderOrAdmin,
136
- controller.getUserInvites
126
+ "/api/global/users",
127
+ createUserAdminOnly,
128
+ users.buildUserSaveValidation(),
129
+ controller.save
137
130
  )
131
+ // non-global endpoints
132
+ .get("/api/global/users/invite/:code", controller.checkInvite)
138
133
  .post(
139
134
  "/api/global/users/invite/accept",
140
135
  buildInviteAcceptValidation(),
141
136
  controller.inviteAccept
142
137
  )
143
- .post(
144
- "/api/global/users/init",
145
- cloudRestricted,
146
- buildAdminInitValidation(),
147
- controller.adminUser
148
- )
149
138
  .get("/api/global/users/accountholder", controller.accountHolderLookup)
150
139
  .get("/api/global/users/tenant/:id", controller.tenantUserLookup)
151
- // global endpoint but needs to come at end (blocks other endpoints otherwise)
152
- .get("/api/global/users/:id", auth.builderOrAdmin, controller.find)
153
- .put(
154
- "/api/global/users/tenant/owner",
155
- cloudRestricted,
156
- buildChangeTenantOwnerEmailValidation(),
157
- controller.changeTenantOwnerEmail
158
- )
159
-
160
- export default router
@@ -1,44 +1,33 @@
1
1
  import Router from "@koa/router"
2
2
  import { api as pro } from "@budibase/pro"
3
- import userRoutes from "./global/users"
4
- import configRoutes from "./global/configs"
5
- import templateRoutes from "./global/templates"
6
- import emailRoutes from "./global/email"
7
- import authRoutes from "./global/auth"
8
- import roleRoutes from "./global/roles"
9
- import eventRoutes from "./global/events"
10
- import environmentRoutes from "./system/environment"
11
- import tenantsRoutes from "./system/tenants"
12
- import statusRoutes from "./system/status"
13
- import selfRoutes from "./global/self"
14
- import licenseRoutes from "./global/license"
15
- import accountRoutes from "./system/accounts"
16
- import restoreRoutes from "./system/restore"
17
- import systemLogRoutes from "./system/logs"
3
+ import { endpointGroupList } from "./endpointGroups"
18
4
 
19
- import env from "../../environment"
5
+ // import to register the routes with the endpoint groups
6
+ import "./global/auth"
7
+ import "./global/users"
8
+ import "./global/configs"
9
+ import "./global/templates"
10
+ import "./global/email"
11
+ import "./global/roles"
12
+ import "./global/events"
13
+ import "./system/environment"
14
+ import "./system/tenants"
15
+ import "./system/status"
16
+ import "./global/self"
17
+ import "./global/license"
18
+ import "./system/accounts"
19
+ import "./system/restore"
20
+ import "./system/logs"
21
+
22
+ const endpointGroupsRouter = new Router()
23
+ for (let endpoint of endpointGroupList.listAllEndpoints()) {
24
+ endpoint.apply(endpointGroupsRouter)
25
+ }
20
26
 
21
27
  export const routes: Router[] = [
22
- configRoutes,
23
- userRoutes,
28
+ endpointGroupsRouter,
24
29
  pro.users,
25
- authRoutes,
26
- templateRoutes,
27
- tenantsRoutes,
28
- emailRoutes,
29
- roleRoutes,
30
- environmentRoutes,
31
- statusRoutes,
32
- selfRoutes,
33
- licenseRoutes,
34
30
  pro.groups,
35
31
  pro.auditLogs,
36
- accountRoutes,
37
- restoreRoutes,
38
- eventRoutes,
39
32
  pro.scim,
40
33
  ]
41
-
42
- if (env.SELF_HOSTED) {
43
- routes.push(systemLogRoutes)
44
- }
@@ -1,19 +1,6 @@
1
- import Router from "@koa/router"
2
1
  import * as controller from "../../controllers/system/accounts"
3
- import { middleware } from "@budibase/backend-core"
2
+ import { internalRoutes } from "../endpointGroups"
4
3
 
5
- const router: Router = new Router()
6
-
7
- router
8
- .put(
9
- "/api/system/accounts/:accountId/metadata",
10
- middleware.internalApi,
11
- controller.save
12
- )
13
- .delete(
14
- "/api/system/accounts/:accountId/metadata",
15
- middleware.internalApi,
16
- controller.destroy
17
- )
18
-
19
- export default router
4
+ internalRoutes
5
+ .put("/api/system/accounts/:accountId/metadata", controller.save)
6
+ .delete("/api/system/accounts/:accountId/metadata", controller.destroy)
@@ -1,8 +1,4 @@
1
- import Router from "@koa/router"
2
1
  import * as controller from "../../controllers/system/environment"
2
+ import { loggedInRoutes } from "../endpointGroups"
3
3
 
4
- const router: Router = new Router()
5
-
6
- router.get("/api/system/environment", controller.fetch)
7
-
8
- export default router
4
+ loggedInRoutes.get("/api/system/environment", controller.fetch)
@@ -1,9 +1,7 @@
1
- import Router from "@koa/router"
2
- import { middleware } from "@budibase/backend-core"
3
1
  import * as controller from "../../controllers/system/logs"
2
+ import { adminRoutes } from "../endpointGroups"
3
+ import env from "../../../environment"
4
4
 
5
- const router: Router = new Router()
6
-
7
- router.get("/api/system/logs", middleware.adminOnly, controller.getLogs)
8
-
9
- export default router
5
+ if (env.SELF_HOSTED) {
6
+ adminRoutes.get("/api/system/logs", controller.getLogs)
7
+ }
@@ -1,8 +1,4 @@
1
1
  import * as controller from "../../controllers/system/restore"
2
- import Router from "@koa/router"
2
+ import { loggedInRoutes } from "../endpointGroups"
3
3
 
4
- const router: Router = new Router()
5
-
6
- router.post("/api/system/restored", controller.systemRestored)
7
-
8
- export default router
4
+ loggedInRoutes.post("/api/system/restored", controller.systemRestored)
@@ -1,8 +1,4 @@
1
- import Router from "@koa/router"
2
1
  import * as controller from "../../controllers/system/status"
2
+ import { loggedInRoutes } from "../endpointGroups"
3
3
 
4
- const router: Router = new Router()
5
-
6
- router.get("/api/system/status", controller.fetch)
7
-
8
- export default router
4
+ loggedInRoutes.get("/api/system/status", controller.fetch)
@@ -1,13 +1,4 @@
1
- import Router from "@koa/router"
2
1
  import * as controller from "../../controllers/system/tenants"
3
- import { middleware } from "@budibase/backend-core"
2
+ import { adminRoutes } from "../endpointGroups"
4
3
 
5
- const router: Router = new Router()
6
-
7
- router.delete(
8
- "/api/system/tenants/:tenantId",
9
- middleware.adminOnly,
10
- controller.destroy
11
- )
12
-
13
- export default router
4
+ adminRoutes.delete("/api/system/tenants/:tenantId", controller.destroy)