@budibase/worker 2.28.4 → 2.28.5
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 +6 -6
- package/scripts/dev/manage.js +1 -0
- package/src/api/controllers/global/tenant.ts +10 -0
- package/src/api/controllers/system/status.ts +15 -7
- package/src/api/index.ts +8 -0
- package/src/api/routes/global/tenant.ts +33 -0
- package/src/api/routes/global/tests/tenant.spec.ts +47 -0
- package/src/api/routes/global/users.ts +0 -8
- package/src/api/routes/index.ts +2 -0
- package/src/api/routes/system/tests/status.spec.ts +1 -0
- package/src/environment.ts +2 -0
- package/src/index.ts +5 -1
- package/src/tests/api/tenants.ts +9 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/worker",
|
|
3
3
|
"email": "hi@budibase.com",
|
|
4
|
-
"version": "2.28.
|
|
4
|
+
"version": "2.28.5",
|
|
5
5
|
"description": "Budibase background service",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"repository": {
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"author": "Budibase",
|
|
38
38
|
"license": "GPL-3.0",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@budibase/backend-core": "2.28.
|
|
41
|
-
"@budibase/pro": "2.28.
|
|
42
|
-
"@budibase/string-templates": "2.28.
|
|
43
|
-
"@budibase/types": "2.28.
|
|
40
|
+
"@budibase/backend-core": "2.28.5",
|
|
41
|
+
"@budibase/pro": "2.28.5",
|
|
42
|
+
"@budibase/string-templates": "2.28.5",
|
|
43
|
+
"@budibase/types": "2.28.5",
|
|
44
44
|
"@koa/router": "8.0.8",
|
|
45
45
|
"@techpass/passport-openidconnect": "0.3.2",
|
|
46
46
|
"@types/global-agent": "2.1.1",
|
|
@@ -109,5 +109,5 @@
|
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
},
|
|
112
|
-
"gitHead": "
|
|
112
|
+
"gitHead": "23b51d2ef16719c5106b8ad816ce4890de471f5b"
|
|
113
113
|
}
|
package/scripts/dev/manage.js
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { tenancy } from "@budibase/backend-core"
|
|
2
|
+
import { TenantInfo, Ctx } from "@budibase/types"
|
|
3
|
+
|
|
4
|
+
export const save = async (ctx: Ctx<TenantInfo>) => {
|
|
5
|
+
const response = await tenancy.saveTenantInfo(ctx.request.body)
|
|
6
|
+
ctx.body = {
|
|
7
|
+
_id: response.id,
|
|
8
|
+
_rev: response.rev,
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -1,16 +1,24 @@
|
|
|
1
|
-
import { accounts } from "@budibase/backend-core"
|
|
1
|
+
import { accounts, env as coreEnv } from "@budibase/backend-core"
|
|
2
|
+
import { Ctx, SystemStatusResponse } from "@budibase/types"
|
|
2
3
|
import env from "../../../environment"
|
|
3
|
-
import { BBContext } from "@budibase/types"
|
|
4
4
|
|
|
5
|
-
export const fetch = async (ctx:
|
|
5
|
+
export const fetch = async (ctx: Ctx<void, SystemStatusResponse>) => {
|
|
6
|
+
let status: SystemStatusResponse | undefined
|
|
6
7
|
if (!env.SELF_HOSTED && !env.DISABLE_ACCOUNT_PORTAL) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
status = await accounts.getStatus()
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (!status) {
|
|
12
|
+
status = {
|
|
11
13
|
health: {
|
|
12
14
|
passing: true,
|
|
13
15
|
},
|
|
14
16
|
}
|
|
15
17
|
}
|
|
18
|
+
|
|
19
|
+
if (coreEnv.VERSION) {
|
|
20
|
+
status.version = coreEnv.VERSION
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
ctx.body = status
|
|
16
24
|
}
|
package/src/api/index.ts
CHANGED
|
@@ -76,6 +76,10 @@ const PUBLIC_ENDPOINTS = [
|
|
|
76
76
|
route: "/api/global/users/invite",
|
|
77
77
|
method: "GET",
|
|
78
78
|
},
|
|
79
|
+
{
|
|
80
|
+
route: "/api/global/tenant",
|
|
81
|
+
method: "POST",
|
|
82
|
+
},
|
|
79
83
|
]
|
|
80
84
|
|
|
81
85
|
const NO_TENANCY_ENDPOINTS = [
|
|
@@ -121,6 +125,10 @@ const NO_TENANCY_ENDPOINTS = [
|
|
|
121
125
|
route: "/api/global/users/invite/:code",
|
|
122
126
|
method: "GET",
|
|
123
127
|
},
|
|
128
|
+
{
|
|
129
|
+
route: "/api/global/tenant",
|
|
130
|
+
method: "POST",
|
|
131
|
+
},
|
|
124
132
|
]
|
|
125
133
|
|
|
126
134
|
// most public endpoints are gets, but some are posts
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import Router from "@koa/router"
|
|
2
|
+
import Joi from "joi"
|
|
3
|
+
import { auth } from "@budibase/backend-core"
|
|
4
|
+
import * as controller from "../../controllers/global/tenant"
|
|
5
|
+
import cloudRestricted from "../../../middleware/cloudRestricted"
|
|
6
|
+
|
|
7
|
+
const router: Router = new Router()
|
|
8
|
+
const OPTIONAL_STRING = Joi.string().optional().allow(null).allow("")
|
|
9
|
+
|
|
10
|
+
function buildTenantInfoValidation() {
|
|
11
|
+
return auth.joiValidator.body(
|
|
12
|
+
Joi.object({
|
|
13
|
+
owner: Joi.object({
|
|
14
|
+
email: Joi.string().required(),
|
|
15
|
+
password: OPTIONAL_STRING,
|
|
16
|
+
ssoId: OPTIONAL_STRING,
|
|
17
|
+
givenName: OPTIONAL_STRING,
|
|
18
|
+
familyName: OPTIONAL_STRING,
|
|
19
|
+
budibaseUserId: OPTIONAL_STRING,
|
|
20
|
+
}).required(),
|
|
21
|
+
tenantId: Joi.string().required(),
|
|
22
|
+
}).required()
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
router.post(
|
|
27
|
+
"/api/global/tenant",
|
|
28
|
+
cloudRestricted,
|
|
29
|
+
buildTenantInfoValidation(),
|
|
30
|
+
controller.save
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
export default router
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { TenantInfo } from "@budibase/types"
|
|
2
|
+
import { TestConfiguration } from "../../../../tests"
|
|
3
|
+
import { tenancy as _tenancy } from "@budibase/backend-core"
|
|
4
|
+
|
|
5
|
+
const tenancy = jest.mocked(_tenancy)
|
|
6
|
+
|
|
7
|
+
describe("/api/global/tenant", () => {
|
|
8
|
+
const config = new TestConfiguration()
|
|
9
|
+
|
|
10
|
+
beforeAll(async () => {
|
|
11
|
+
await config.beforeAll()
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
afterAll(async () => {
|
|
15
|
+
await config.afterAll()
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
jest.clearAllMocks()
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
describe("POST /api/global/tenant", () => {
|
|
23
|
+
it("should save the tenantInfo", async () => {
|
|
24
|
+
tenancy.saveTenantInfo = jest.fn().mockImplementation(async () => ({
|
|
25
|
+
id: "DOC_ID",
|
|
26
|
+
ok: true,
|
|
27
|
+
rev: "DOC_REV",
|
|
28
|
+
}))
|
|
29
|
+
const tenantInfo: TenantInfo = {
|
|
30
|
+
owner: {
|
|
31
|
+
email: "test@example.com",
|
|
32
|
+
password: "PASSWORD",
|
|
33
|
+
ssoId: "SSO_ID",
|
|
34
|
+
givenName: "Jane",
|
|
35
|
+
familyName: "Doe",
|
|
36
|
+
budibaseUserId: "USER_ID",
|
|
37
|
+
},
|
|
38
|
+
tenantId: "tenant123",
|
|
39
|
+
}
|
|
40
|
+
const response = await config.api.tenants.saveTenantInfo(tenantInfo)
|
|
41
|
+
|
|
42
|
+
expect(_tenancy.saveTenantInfo).toHaveBeenCalledTimes(1)
|
|
43
|
+
expect(_tenancy.saveTenantInfo).toHaveBeenCalledWith(tenantInfo)
|
|
44
|
+
expect(response.text).toEqual('{"_id":"DOC_ID","_rev":"DOC_REV"}')
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
})
|
|
@@ -4,7 +4,6 @@ import { auth } from "@budibase/backend-core"
|
|
|
4
4
|
import Joi from "joi"
|
|
5
5
|
import cloudRestricted from "../../../middleware/cloudRestricted"
|
|
6
6
|
import { users } from "../validation"
|
|
7
|
-
import * as selfController from "../../controllers/global/self"
|
|
8
7
|
|
|
9
8
|
const router: Router = new Router()
|
|
10
9
|
const OPTIONAL_STRING = Joi.string().optional().allow(null).allow("")
|
|
@@ -140,12 +139,5 @@ router
|
|
|
140
139
|
.get("/api/global/users/tenant/:id", controller.tenantUserLookup)
|
|
141
140
|
// global endpoint but needs to come at end (blocks other endpoints otherwise)
|
|
142
141
|
.get("/api/global/users/:id", auth.builderOrAdmin, controller.find)
|
|
143
|
-
// DEPRECATED - use new versions with self API
|
|
144
|
-
.get("/api/global/users/self", selfController.getSelf)
|
|
145
|
-
.post(
|
|
146
|
-
"/api/global/users/self",
|
|
147
|
-
users.buildUserSaveValidation(),
|
|
148
|
-
selfController.updateSelf
|
|
149
|
-
)
|
|
150
142
|
|
|
151
143
|
export default router
|
package/src/api/routes/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Router from "@koa/router"
|
|
2
2
|
import { api as pro } from "@budibase/pro"
|
|
3
3
|
import userRoutes from "./global/users"
|
|
4
|
+
import tenantRoutes from "./global/tenant"
|
|
4
5
|
import configRoutes from "./global/configs"
|
|
5
6
|
import workspaceRoutes from "./global/workspaces"
|
|
6
7
|
import templateRoutes from "./global/templates"
|
|
@@ -40,6 +41,7 @@ export const routes: Router[] = [
|
|
|
40
41
|
accountRoutes,
|
|
41
42
|
restoreRoutes,
|
|
42
43
|
eventRoutes,
|
|
44
|
+
tenantRoutes,
|
|
43
45
|
pro.scim,
|
|
44
46
|
]
|
|
45
47
|
|
package/src/environment.ts
CHANGED
|
@@ -24,6 +24,7 @@ const environment = {
|
|
|
24
24
|
// auth
|
|
25
25
|
MINIO_ACCESS_KEY: process.env.MINIO_ACCESS_KEY,
|
|
26
26
|
MINIO_SECRET_KEY: process.env.MINIO_SECRET_KEY,
|
|
27
|
+
AWS_SESSION_TOKEN: process.env.AWS_SESSION_TOKEN,
|
|
27
28
|
SALT_ROUNDS: process.env.SALT_ROUNDS,
|
|
28
29
|
REDIS_PASSWORD: process.env.REDIS_PASSWORD,
|
|
29
30
|
COOKIE_DOMAIN: process.env.COOKIE_DOMAIN,
|
|
@@ -46,6 +47,7 @@ const environment = {
|
|
|
46
47
|
SMTP_FALLBACK_ENABLED: process.env.SMTP_FALLBACK_ENABLED,
|
|
47
48
|
DISABLE_DEVELOPER_LICENSE: process.env.DISABLE_DEVELOPER_LICENSE,
|
|
48
49
|
SQS_SEARCH_ENABLE: process.env.SQS_SEARCH_ENABLE,
|
|
50
|
+
BUDIBASE_ENVIRONMENT: process.env.BUDIBASE_ENVIRONMENT,
|
|
49
51
|
// smtp
|
|
50
52
|
SMTP_USER: process.env.SMTP_USER,
|
|
51
53
|
SMTP_PASSWORD: process.env.SMTP_PASSWORD,
|
package/src/index.ts
CHANGED
|
@@ -88,7 +88,11 @@ const shutdown = () => {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
export default server.listen(parseInt(env.PORT || "4002"), async () => {
|
|
91
|
-
|
|
91
|
+
let startupLog = `Worker running on ${JSON.stringify(server.address())}`
|
|
92
|
+
if (env.BUDIBASE_ENVIRONMENT) {
|
|
93
|
+
startupLog = `${startupLog} - environment: "${env.BUDIBASE_ENVIRONMENT}"`
|
|
94
|
+
}
|
|
95
|
+
console.log(startupLog)
|
|
92
96
|
await initPro()
|
|
93
97
|
await redis.clients.init()
|
|
94
98
|
cache.docWritethrough.init()
|
package/src/tests/api/tenants.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TenantInfo } from "@budibase/types"
|
|
1
2
|
import TestConfiguration from "../TestConfiguration"
|
|
2
3
|
import { TestAPI, TestAPIOpts } from "./base"
|
|
3
4
|
|
|
@@ -14,4 +15,12 @@ export class TenantAPI extends TestAPI {
|
|
|
14
15
|
.set(opts?.headers)
|
|
15
16
|
.expect(opts?.status ? opts.status : 204)
|
|
16
17
|
}
|
|
18
|
+
|
|
19
|
+
saveTenantInfo = (tenantInfo: TenantInfo) => {
|
|
20
|
+
return this.request
|
|
21
|
+
.post("/api/global/tenant")
|
|
22
|
+
.set(this.config.internalAPIHeaders())
|
|
23
|
+
.send(tenantInfo)
|
|
24
|
+
.expect(200)
|
|
25
|
+
}
|
|
17
26
|
}
|