@budibase/worker 3.2.25 → 3.2.27
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 +9 -10
- package/src/api/controllers/global/auth.ts +26 -12
- package/src/api/controllers/global/configs.ts +14 -6
- package/src/api/controllers/global/email.ts +9 -2
- package/src/api/controllers/global/license.ts +6 -3
- package/src/api/controllers/global/roles.ts +10 -4
- package/src/api/controllers/global/self.ts +15 -8
- package/src/api/controllers/global/templates.ts +35 -17
- package/src/api/controllers/global/users.ts +41 -14
- package/src/api/controllers/system/accounts.ts +11 -3
- package/src/api/controllers/system/environment.ts +3 -3
- package/src/api/controllers/system/logs.ts +2 -2
- package/src/api/controllers/system/migrations.ts +12 -2
- package/src/api/controllers/system/restore.ts +4 -2
- package/src/api/controllers/system/tenants.ts +3 -3
- package/src/api/routes/global/email.ts +1 -1
- package/src/api/routes/global/tests/auth.spec.ts +2 -2
- package/src/api/routes/global/tests/email.spec.ts +1 -1
- package/src/api/routes/global/tests/realEmail.spec.ts +1 -2
- package/src/api/routes/global/tests/templates.spec.ts +2 -5
- package/src/api/routes/global/tests/users.spec.ts +1 -1
- package/src/api/routes/index.ts +0 -2
- package/src/api/routes/system/tests/environment.spec.ts +2 -2
- package/src/constants/index.ts +1 -9
- package/src/constants/templates/index.ts +17 -15
- package/src/middleware/cloudRestricted.ts +2 -2
- package/src/middleware/handleScimBody.ts +1 -1
- package/src/sdk/accounts/metadata.ts +1 -4
- package/src/sdk/auth/auth.ts +1 -2
- package/src/sdk/users/users.ts +1 -1
- package/src/tests/api/accounts.ts +0 -5
- package/src/tests/api/auditLogs.ts +0 -5
- package/src/tests/api/auth.ts +0 -5
- package/src/tests/api/base.ts +1 -1
- package/src/tests/api/configs.ts +0 -5
- package/src/tests/api/email.ts +1 -6
- package/src/tests/api/environment.ts +0 -5
- package/src/tests/api/groups.ts +0 -5
- package/src/tests/api/license.ts +0 -5
- package/src/tests/api/migrations.ts +0 -5
- package/src/tests/api/restore.ts +0 -5
- package/src/tests/api/roles.ts +0 -5
- package/src/tests/api/scim/groups.ts +0 -5
- package/src/tests/api/scim/shared.ts +0 -5
- package/src/tests/api/scim/users.ts +0 -5
- package/src/tests/api/self.ts +0 -5
- package/src/tests/api/status.ts +0 -5
- package/src/tests/api/templates.ts +0 -5
- package/src/tests/api/users.ts +1 -10
- package/src/tests/controllers.ts +0 -1
- package/src/utilities/email.ts +7 -2
- package/src/utilities/templates.ts +2 -5
- package/tsconfig.build.json +2 -19
- package/tsconfig.json +0 -4
- package/src/api/controllers/global/workspaces.ts +0 -53
- package/src/api/routes/global/workspaces.ts +0 -37
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/worker",
|
|
3
3
|
"email": "hi@budibase.com",
|
|
4
|
-
"version": "3.2.
|
|
4
|
+
"version": "3.2.27",
|
|
5
5
|
"description": "Budibase background service",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"repository": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"prebuild": "rimraf dist/",
|
|
16
16
|
"build": "node ../../scripts/build.js",
|
|
17
17
|
"postbuild": "copyfiles -f ../../yarn.lock ./dist/",
|
|
18
|
-
"check:types": "tsc -p tsconfig.json --noEmit --paths null
|
|
18
|
+
"check:types": "tsc -p tsconfig.json --noEmit --paths null",
|
|
19
19
|
"check:dependencies": "node ../../scripts/depcheck.js",
|
|
20
20
|
"build:dev": "yarn prebuild && tsc --build --watch --preserveWatchOutput",
|
|
21
21
|
"run:docker": "node dist/index.js",
|
|
@@ -38,11 +38,11 @@
|
|
|
38
38
|
"author": "Budibase",
|
|
39
39
|
"license": "GPL-3.0",
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@budibase/backend-core": "
|
|
42
|
-
"@budibase/pro": "
|
|
43
|
-
"@budibase/shared-core": "
|
|
44
|
-
"@budibase/string-templates": "
|
|
45
|
-
"@budibase/types": "
|
|
41
|
+
"@budibase/backend-core": "*",
|
|
42
|
+
"@budibase/pro": "*",
|
|
43
|
+
"@budibase/shared-core": "*",
|
|
44
|
+
"@budibase/string-templates": "*",
|
|
45
|
+
"@budibase/types": "*",
|
|
46
46
|
"@koa/router": "13.1.0",
|
|
47
47
|
"@techpass/passport-openidconnect": "0.3.3",
|
|
48
48
|
"@types/global-agent": "2.1.1",
|
|
@@ -85,7 +85,6 @@
|
|
|
85
85
|
"@types/koa": "2.13.4",
|
|
86
86
|
"@types/koa__router": "12.0.4",
|
|
87
87
|
"@types/lodash": "4.14.200",
|
|
88
|
-
"@types/node": "^22.9.0",
|
|
89
88
|
"@types/node-fetch": "2.6.4",
|
|
90
89
|
"@types/server-destroy": "1.0.1",
|
|
91
90
|
"@types/supertest": "2.0.14",
|
|
@@ -109,11 +108,11 @@
|
|
|
109
108
|
"projects": [
|
|
110
109
|
"@budibase/backend-core"
|
|
111
110
|
],
|
|
112
|
-
"target": "build"
|
|
111
|
+
"target": "build:oss"
|
|
113
112
|
}
|
|
114
113
|
]
|
|
115
114
|
}
|
|
116
115
|
}
|
|
117
116
|
},
|
|
118
|
-
"gitHead": "
|
|
117
|
+
"gitHead": "1ea577227cec7d169dfc3e13f4b7eced8fdbc53c"
|
|
119
118
|
}
|
|
@@ -16,8 +16,15 @@ import {
|
|
|
16
16
|
PasswordResetUpdateRequest,
|
|
17
17
|
GoogleInnerConfig,
|
|
18
18
|
DatasourceAuthCookie,
|
|
19
|
+
LogoutResponse,
|
|
20
|
+
UserCtx,
|
|
21
|
+
SetInitInfoRequest,
|
|
22
|
+
GetInitInfoResponse,
|
|
23
|
+
PasswordResetResponse,
|
|
24
|
+
PasswordResetUpdateResponse,
|
|
19
25
|
} from "@budibase/types"
|
|
20
26
|
import env from "../../../environment"
|
|
27
|
+
import { Next } from "koa"
|
|
21
28
|
|
|
22
29
|
import * as authSdk from "../../../sdk/auth"
|
|
23
30
|
import * as userSdk from "../../../sdk/users"
|
|
@@ -52,7 +59,7 @@ async function passportCallback(
|
|
|
52
59
|
ctx.set(Header.TOKEN, token)
|
|
53
60
|
}
|
|
54
61
|
|
|
55
|
-
export const login = async (ctx: Ctx<LoginRequest>, next:
|
|
62
|
+
export const login = async (ctx: Ctx<LoginRequest, void>, next: Next) => {
|
|
56
63
|
const email = ctx.request.body.username
|
|
57
64
|
|
|
58
65
|
const user = await userSdk.db.getUserByEmail(email)
|
|
@@ -72,7 +79,7 @@ export const login = async (ctx: Ctx<LoginRequest>, next: any) => {
|
|
|
72
79
|
)(ctx, next)
|
|
73
80
|
}
|
|
74
81
|
|
|
75
|
-
export const logout = async (ctx:
|
|
82
|
+
export const logout = async (ctx: UserCtx<void, LogoutResponse>) => {
|
|
76
83
|
if (ctx.user && ctx.user._id) {
|
|
77
84
|
await authSdk.logout({ ctx, userId: ctx.user._id })
|
|
78
85
|
}
|
|
@@ -81,13 +88,13 @@ export const logout = async (ctx: any) => {
|
|
|
81
88
|
|
|
82
89
|
// INIT
|
|
83
90
|
|
|
84
|
-
export const setInitInfo = (ctx:
|
|
91
|
+
export const setInitInfo = (ctx: UserCtx<SetInitInfoRequest, void>) => {
|
|
85
92
|
const initInfo = ctx.request.body
|
|
86
93
|
setCookie(ctx, initInfo, Cookie.Init)
|
|
87
94
|
ctx.status = 200
|
|
88
95
|
}
|
|
89
96
|
|
|
90
|
-
export const getInitInfo = (ctx:
|
|
97
|
+
export const getInitInfo = (ctx: UserCtx<void, GetInitInfoResponse>) => {
|
|
91
98
|
try {
|
|
92
99
|
ctx.body = getCookie(ctx, Cookie.Init) || {}
|
|
93
100
|
} catch (err) {
|
|
@@ -101,7 +108,9 @@ export const getInitInfo = (ctx: any) => {
|
|
|
101
108
|
/**
|
|
102
109
|
* Reset the user password, used as part of a forgotten password flow.
|
|
103
110
|
*/
|
|
104
|
-
export const reset = async (
|
|
111
|
+
export const reset = async (
|
|
112
|
+
ctx: Ctx<PasswordResetRequest, PasswordResetResponse>
|
|
113
|
+
) => {
|
|
105
114
|
const { email } = ctx.request.body
|
|
106
115
|
|
|
107
116
|
await authSdk.reset(email)
|
|
@@ -114,7 +123,9 @@ export const reset = async (ctx: Ctx<PasswordResetRequest>) => {
|
|
|
114
123
|
/**
|
|
115
124
|
* Perform the user password update if the provided reset code is valid.
|
|
116
125
|
*/
|
|
117
|
-
export const resetUpdate = async (
|
|
126
|
+
export const resetUpdate = async (
|
|
127
|
+
ctx: Ctx<PasswordResetUpdateRequest, PasswordResetUpdateResponse>
|
|
128
|
+
) => {
|
|
118
129
|
const { resetCode, password } = ctx.request.body
|
|
119
130
|
try {
|
|
120
131
|
await authSdk.resetUpdate(resetCode, password)
|
|
@@ -130,7 +141,10 @@ export const resetUpdate = async (ctx: Ctx<PasswordResetUpdateRequest>) => {
|
|
|
130
141
|
|
|
131
142
|
// DATASOURCE
|
|
132
143
|
|
|
133
|
-
export const datasourcePreAuth = async (
|
|
144
|
+
export const datasourcePreAuth = async (
|
|
145
|
+
ctx: UserCtx<void, void>,
|
|
146
|
+
next: Next
|
|
147
|
+
) => {
|
|
134
148
|
const provider = ctx.params.provider
|
|
135
149
|
const { middleware } = require(`@budibase/backend-core`)
|
|
136
150
|
const handler = middleware.datasource[provider]
|
|
@@ -147,7 +161,7 @@ export const datasourcePreAuth = async (ctx: any, next: any) => {
|
|
|
147
161
|
return handler.preAuth(passport, ctx, next)
|
|
148
162
|
}
|
|
149
163
|
|
|
150
|
-
export const datasourceAuth = async (ctx:
|
|
164
|
+
export const datasourceAuth = async (ctx: UserCtx<void, void>, next: Next) => {
|
|
151
165
|
const authStateCookie = getCookie<DatasourceAuthCookie>(
|
|
152
166
|
ctx,
|
|
153
167
|
Cookie.DatasourceAuth
|
|
@@ -171,7 +185,7 @@ export async function googleCallbackUrl(config?: GoogleInnerConfig) {
|
|
|
171
185
|
* The initial call that google authentication makes to take you to the google login screen.
|
|
172
186
|
* On a successful login, you will be redirected to the googleAuth callback route.
|
|
173
187
|
*/
|
|
174
|
-
export const googlePreAuth = async (ctx:
|
|
188
|
+
export const googlePreAuth = async (ctx: Ctx<void, void>, next: Next) => {
|
|
175
189
|
const config = await configs.getGoogleConfig()
|
|
176
190
|
if (!config) {
|
|
177
191
|
return ctx.throw(400, "Google config not found")
|
|
@@ -190,7 +204,7 @@ export const googlePreAuth = async (ctx: any, next: any) => {
|
|
|
190
204
|
})(ctx, next)
|
|
191
205
|
}
|
|
192
206
|
|
|
193
|
-
export const googleCallback = async (ctx:
|
|
207
|
+
export const googleCallback = async (ctx: Ctx<void, void>, next: Next) => {
|
|
194
208
|
const config = await configs.getGoogleConfig()
|
|
195
209
|
if (!config) {
|
|
196
210
|
return ctx.throw(400, "Google config not found")
|
|
@@ -241,7 +255,7 @@ export const oidcStrategyFactory = async (ctx: any) => {
|
|
|
241
255
|
* The initial call that OIDC authentication makes to take you to the configured OIDC login screen.
|
|
242
256
|
* On a successful login, you will be redirected to the oidcAuth callback route.
|
|
243
257
|
*/
|
|
244
|
-
export const oidcPreAuth = async (ctx: Ctx, next:
|
|
258
|
+
export const oidcPreAuth = async (ctx: Ctx<void, void>, next: Next) => {
|
|
245
259
|
const { configId } = ctx.params
|
|
246
260
|
if (!configId) {
|
|
247
261
|
ctx.throw(400, "OIDC config id is required")
|
|
@@ -266,7 +280,7 @@ export const oidcPreAuth = async (ctx: Ctx, next: any) => {
|
|
|
266
280
|
})(ctx, next)
|
|
267
281
|
}
|
|
268
282
|
|
|
269
|
-
export const oidcCallback = async (ctx:
|
|
283
|
+
export const oidcCallback = async (ctx: Ctx<void, void>, next: Next) => {
|
|
270
284
|
const strategy = await oidcStrategyFactory(ctx)
|
|
271
285
|
|
|
272
286
|
return passport.authenticate(
|
|
@@ -15,8 +15,11 @@ import {
|
|
|
15
15
|
AIConfig,
|
|
16
16
|
AIInnerConfig,
|
|
17
17
|
Config,
|
|
18
|
+
ConfigChecklistResponse,
|
|
18
19
|
ConfigType,
|
|
19
20
|
Ctx,
|
|
21
|
+
DeleteConfigResponse,
|
|
22
|
+
FindConfigResponse,
|
|
20
23
|
GetPublicOIDCConfigResponse,
|
|
21
24
|
GetPublicSettingsResponse,
|
|
22
25
|
GoogleInnerConfig,
|
|
@@ -29,11 +32,14 @@ import {
|
|
|
29
32
|
OIDCLogosConfig,
|
|
30
33
|
PASSWORD_REPLACEMENT,
|
|
31
34
|
QuotaUsageType,
|
|
35
|
+
SaveConfigRequest,
|
|
36
|
+
SaveConfigResponse,
|
|
32
37
|
SettingsBrandingConfig,
|
|
33
38
|
SettingsInnerConfig,
|
|
34
39
|
SSOConfig,
|
|
35
40
|
SSOConfigType,
|
|
36
41
|
StaticQuotaName,
|
|
42
|
+
UploadConfigFileResponse,
|
|
37
43
|
UserCtx,
|
|
38
44
|
} from "@budibase/types"
|
|
39
45
|
import * as pro from "@budibase/pro"
|
|
@@ -225,7 +231,9 @@ export async function verifyAIConfig(
|
|
|
225
231
|
}
|
|
226
232
|
}
|
|
227
233
|
|
|
228
|
-
export async function save(
|
|
234
|
+
export async function save(
|
|
235
|
+
ctx: UserCtx<SaveConfigRequest, SaveConfigResponse>
|
|
236
|
+
) {
|
|
229
237
|
const body = ctx.request.body
|
|
230
238
|
const type = body.type
|
|
231
239
|
const config = body.config
|
|
@@ -337,7 +345,7 @@ function enrichOIDCLogos(oidcLogos: OIDCLogosConfig) {
|
|
|
337
345
|
)
|
|
338
346
|
}
|
|
339
347
|
|
|
340
|
-
export async function find(ctx: UserCtx) {
|
|
348
|
+
export async function find(ctx: UserCtx<void, FindConfigResponse>) {
|
|
341
349
|
try {
|
|
342
350
|
// Find the config with the most granular scope based on context
|
|
343
351
|
const type = ctx.params.type
|
|
@@ -473,7 +481,7 @@ export async function publicSettings(
|
|
|
473
481
|
}
|
|
474
482
|
}
|
|
475
483
|
|
|
476
|
-
export async function upload(ctx: UserCtx) {
|
|
484
|
+
export async function upload(ctx: UserCtx<void, UploadConfigFileResponse>) {
|
|
477
485
|
if (ctx.request.files == null || Array.isArray(ctx.request.files.file)) {
|
|
478
486
|
ctx.throw(400, "One file must be uploaded.")
|
|
479
487
|
}
|
|
@@ -518,7 +526,7 @@ export async function upload(ctx: UserCtx) {
|
|
|
518
526
|
}
|
|
519
527
|
}
|
|
520
528
|
|
|
521
|
-
export async function destroy(ctx: UserCtx) {
|
|
529
|
+
export async function destroy(ctx: UserCtx<void, DeleteConfigResponse>) {
|
|
522
530
|
const db = tenancy.getGlobalDB()
|
|
523
531
|
const { id, rev } = ctx.params
|
|
524
532
|
try {
|
|
@@ -537,14 +545,14 @@ export async function destroy(ctx: UserCtx) {
|
|
|
537
545
|
}
|
|
538
546
|
}
|
|
539
547
|
|
|
540
|
-
export async function configChecklist(ctx: Ctx) {
|
|
548
|
+
export async function configChecklist(ctx: Ctx<void, ConfigChecklistResponse>) {
|
|
541
549
|
const tenantId = tenancy.getTenantId()
|
|
542
550
|
|
|
543
551
|
try {
|
|
544
552
|
ctx.body = await cache.withCache(
|
|
545
553
|
cache.CacheKey.CHECKLIST,
|
|
546
554
|
env.CHECKLIST_CACHE_TTL,
|
|
547
|
-
async () => {
|
|
555
|
+
async (): Promise<ConfigChecklistResponse> => {
|
|
548
556
|
let apps = []
|
|
549
557
|
if (!env.MULTI_TENANCY || tenantId) {
|
|
550
558
|
// Apps exist
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import { sendEmail as sendEmailFn } from "../../../utilities/email"
|
|
2
2
|
import { tenancy } from "@budibase/backend-core"
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
UserCtx,
|
|
5
|
+
User,
|
|
6
|
+
SendEmailRequest,
|
|
7
|
+
SendEmailResponse,
|
|
8
|
+
} from "@budibase/types"
|
|
4
9
|
|
|
5
|
-
export async function sendEmail(
|
|
10
|
+
export async function sendEmail(
|
|
11
|
+
ctx: UserCtx<SendEmailRequest, SendEmailResponse>
|
|
12
|
+
) {
|
|
6
13
|
let {
|
|
7
14
|
workspaceId,
|
|
8
15
|
email,
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
GetLicenseKeyResponse,
|
|
6
6
|
GetOfflineIdentifierResponse,
|
|
7
7
|
GetOfflineLicenseTokenResponse,
|
|
8
|
+
GetQuotaUsageResponse,
|
|
8
9
|
UserCtx,
|
|
9
10
|
} from "@budibase/types"
|
|
10
11
|
|
|
@@ -36,7 +37,7 @@ export async function deleteLicenseKey(ctx: UserCtx<void, void>) {
|
|
|
36
37
|
// OFFLINE LICENSE
|
|
37
38
|
|
|
38
39
|
export async function activateOfflineLicenseToken(
|
|
39
|
-
ctx: UserCtx<ActivateOfflineLicenseTokenRequest>
|
|
40
|
+
ctx: UserCtx<ActivateOfflineLicenseTokenRequest, void>
|
|
40
41
|
) {
|
|
41
42
|
const { offlineLicenseToken } = ctx.request.body
|
|
42
43
|
await licensing.offline.activateOfflineLicenseToken(offlineLicenseToken)
|
|
@@ -70,14 +71,16 @@ export async function getOfflineLicenseIdentifier(
|
|
|
70
71
|
|
|
71
72
|
// LICENSES
|
|
72
73
|
|
|
73
|
-
export const refresh = async (ctx:
|
|
74
|
+
export const refresh = async (ctx: UserCtx<void, void>) => {
|
|
74
75
|
await licensing.cache.refresh()
|
|
75
76
|
ctx.status = 200
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
// USAGE
|
|
79
80
|
|
|
80
|
-
export const getQuotaUsage = async (
|
|
81
|
+
export const getQuotaUsage = async (
|
|
82
|
+
ctx: UserCtx<void, GetQuotaUsageResponse>
|
|
83
|
+
) => {
|
|
81
84
|
ctx.body = await quotas.getQuotaUsage()
|
|
82
85
|
ctx.status = 200
|
|
83
86
|
}
|
|
@@ -6,9 +6,15 @@ import {
|
|
|
6
6
|
tenancy,
|
|
7
7
|
} from "@budibase/backend-core"
|
|
8
8
|
import sdk from "../../../sdk"
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
Ctx,
|
|
11
|
+
App,
|
|
12
|
+
FetchGlobalRolesResponse,
|
|
13
|
+
FindGlobalRoleResponse,
|
|
14
|
+
RemoveAppRoleResponse,
|
|
15
|
+
} from "@budibase/types"
|
|
10
16
|
|
|
11
|
-
export async function fetch(ctx: Ctx) {
|
|
17
|
+
export async function fetch(ctx: Ctx<void, FetchGlobalRolesResponse>) {
|
|
12
18
|
const tenantId = ctx.user!.tenantId
|
|
13
19
|
// always use the dev apps as they'll be most up to date (true)
|
|
14
20
|
const apps = (await dbCore.getAllApps({ tenantId, all: true })) as App[]
|
|
@@ -31,7 +37,7 @@ export async function fetch(ctx: Ctx) {
|
|
|
31
37
|
ctx.body = response
|
|
32
38
|
}
|
|
33
39
|
|
|
34
|
-
export async function find(ctx: Ctx) {
|
|
40
|
+
export async function find(ctx: Ctx<void, FindGlobalRoleResponse>) {
|
|
35
41
|
const appId = ctx.params.appId
|
|
36
42
|
await context.doInAppContext(dbCore.getDevAppID(appId), async () => {
|
|
37
43
|
const db = context.getAppDB()
|
|
@@ -45,7 +51,7 @@ export async function find(ctx: Ctx) {
|
|
|
45
51
|
})
|
|
46
52
|
}
|
|
47
53
|
|
|
48
|
-
export async function removeAppRole(ctx: Ctx) {
|
|
54
|
+
export async function removeAppRole(ctx: Ctx<void, RemoveAppRoleResponse>) {
|
|
49
55
|
const { appId } = ctx.params
|
|
50
56
|
const db = tenancy.getGlobalDB()
|
|
51
57
|
const users = await sdk.users.db.allUsers()
|
|
@@ -10,6 +10,11 @@ import {
|
|
|
10
10
|
import env from "../../../environment"
|
|
11
11
|
import { groups } from "@budibase/pro"
|
|
12
12
|
import {
|
|
13
|
+
DevInfo,
|
|
14
|
+
FetchAPIKeyResponse,
|
|
15
|
+
GenerateAPIKeyRequest,
|
|
16
|
+
GenerateAPIKeyResponse,
|
|
17
|
+
GetGlobalSelfResponse,
|
|
13
18
|
UpdateSelfRequest,
|
|
14
19
|
UpdateSelfResponse,
|
|
15
20
|
User,
|
|
@@ -35,22 +40,24 @@ function cleanupDevInfo(info: any) {
|
|
|
35
40
|
return info
|
|
36
41
|
}
|
|
37
42
|
|
|
38
|
-
export async function generateAPIKey(
|
|
43
|
+
export async function generateAPIKey(
|
|
44
|
+
ctx: UserCtx<GenerateAPIKeyRequest, GenerateAPIKeyResponse>
|
|
45
|
+
) {
|
|
39
46
|
let userId
|
|
40
47
|
let apiKey
|
|
41
48
|
if (env.isTest() && ctx.request.body.userId) {
|
|
42
49
|
userId = ctx.request.body.userId
|
|
43
50
|
apiKey = newTestApiKey()
|
|
44
51
|
} else {
|
|
45
|
-
userId = ctx.user._id
|
|
52
|
+
userId = ctx.user._id!
|
|
46
53
|
apiKey = newApiKey()
|
|
47
54
|
}
|
|
48
55
|
|
|
49
56
|
const db = tenancy.getGlobalDB()
|
|
50
57
|
const id = dbCore.generateDevInfoID(userId)
|
|
51
|
-
let devInfo
|
|
58
|
+
let devInfo: DevInfo
|
|
52
59
|
try {
|
|
53
|
-
devInfo = await db.get<
|
|
60
|
+
devInfo = await db.get<DevInfo>(id)
|
|
54
61
|
} catch (err) {
|
|
55
62
|
devInfo = { _id: id, userId }
|
|
56
63
|
}
|
|
@@ -59,9 +66,9 @@ export async function generateAPIKey(ctx: any) {
|
|
|
59
66
|
ctx.body = cleanupDevInfo(devInfo)
|
|
60
67
|
}
|
|
61
68
|
|
|
62
|
-
export async function fetchAPIKey(ctx:
|
|
69
|
+
export async function fetchAPIKey(ctx: UserCtx<void, FetchAPIKeyResponse>) {
|
|
63
70
|
const db = tenancy.getGlobalDB()
|
|
64
|
-
const id = dbCore.generateDevInfoID(ctx.user._id)
|
|
71
|
+
const id = dbCore.generateDevInfoID(ctx.user._id!)
|
|
65
72
|
let devInfo
|
|
66
73
|
try {
|
|
67
74
|
devInfo = await db.get(id)
|
|
@@ -87,11 +94,11 @@ const addSessionAttributesToUser = (ctx: any) => {
|
|
|
87
94
|
ctx.body.csrfToken = ctx.user.csrfToken
|
|
88
95
|
}
|
|
89
96
|
|
|
90
|
-
export async function getSelf(ctx:
|
|
97
|
+
export async function getSelf(ctx: UserCtx<void, GetGlobalSelfResponse>) {
|
|
91
98
|
if (!ctx.user) {
|
|
92
99
|
ctx.throw(403, "User not logged in")
|
|
93
100
|
}
|
|
94
|
-
const userId = ctx.user._id
|
|
101
|
+
const userId = ctx.user._id!
|
|
95
102
|
ctx.params = {
|
|
96
103
|
id: userId,
|
|
97
104
|
}
|
|
@@ -3,10 +3,25 @@ import {
|
|
|
3
3
|
TemplateBindings,
|
|
4
4
|
GLOBAL_OWNER,
|
|
5
5
|
} from "../../../constants"
|
|
6
|
-
import { getTemplates } from "../../../constants/templates"
|
|
6
|
+
import { getTemplateByID, getTemplates } from "../../../constants/templates"
|
|
7
7
|
import { tenancy, db as dbCore } from "@budibase/backend-core"
|
|
8
|
+
import {
|
|
9
|
+
DeleteGlobalTemplateResponse,
|
|
10
|
+
FetchGlobalTemplateByOwnerIDResponse,
|
|
11
|
+
FetchGlobalTemplateByTypeResponse,
|
|
12
|
+
FetchGlobalTemplateDefinitionResponse,
|
|
13
|
+
FetchGlobalTemplateResponse,
|
|
14
|
+
FindGlobalTemplateResponse,
|
|
15
|
+
SaveGlobalTemplateRequest,
|
|
16
|
+
SaveGlobalTemplateResponse,
|
|
17
|
+
GlobalTemplateBinding,
|
|
18
|
+
GlobalTemplateDefinition,
|
|
19
|
+
UserCtx,
|
|
20
|
+
} from "@budibase/types"
|
|
8
21
|
|
|
9
|
-
export async function save(
|
|
22
|
+
export async function save(
|
|
23
|
+
ctx: UserCtx<SaveGlobalTemplateRequest, SaveGlobalTemplateResponse>
|
|
24
|
+
) {
|
|
10
25
|
const db = tenancy.getGlobalDB()
|
|
11
26
|
let template = ctx.request.body
|
|
12
27
|
if (!template.ownerId) {
|
|
@@ -23,9 +38,11 @@ export async function save(ctx: any) {
|
|
|
23
38
|
}
|
|
24
39
|
}
|
|
25
40
|
|
|
26
|
-
export async function definitions(
|
|
27
|
-
|
|
28
|
-
|
|
41
|
+
export async function definitions(
|
|
42
|
+
ctx: UserCtx<void, FetchGlobalTemplateDefinitionResponse>
|
|
43
|
+
) {
|
|
44
|
+
const bindings: Record<string, GlobalTemplateBinding[]> = {}
|
|
45
|
+
const info: Record<string, GlobalTemplateDefinition> = {}
|
|
29
46
|
for (let template of TemplateMetadata.email) {
|
|
30
47
|
bindings[template.purpose] = template.bindings
|
|
31
48
|
info[template.purpose] = {
|
|
@@ -44,34 +61,35 @@ export async function definitions(ctx: any) {
|
|
|
44
61
|
}
|
|
45
62
|
}
|
|
46
63
|
|
|
47
|
-
export async function fetch(ctx:
|
|
64
|
+
export async function fetch(ctx: UserCtx<void, FetchGlobalTemplateResponse>) {
|
|
48
65
|
ctx.body = await getTemplates()
|
|
49
66
|
}
|
|
50
67
|
|
|
51
|
-
export async function fetchByType(
|
|
52
|
-
|
|
68
|
+
export async function fetchByType(
|
|
69
|
+
ctx: UserCtx<void, FetchGlobalTemplateByTypeResponse>
|
|
70
|
+
) {
|
|
53
71
|
ctx.body = await getTemplates({
|
|
54
72
|
type: ctx.params.type,
|
|
55
73
|
})
|
|
56
74
|
}
|
|
57
75
|
|
|
58
|
-
export async function fetchByOwner(
|
|
76
|
+
export async function fetchByOwner(
|
|
77
|
+
ctx: UserCtx<void, FetchGlobalTemplateByOwnerIDResponse>
|
|
78
|
+
) {
|
|
59
79
|
// @ts-ignore
|
|
60
80
|
ctx.body = await getTemplates({
|
|
61
81
|
ownerId: ctx.params.ownerId,
|
|
62
82
|
})
|
|
63
83
|
}
|
|
64
84
|
|
|
65
|
-
export async function find(ctx:
|
|
66
|
-
|
|
67
|
-
ctx.body = await getTemplates({
|
|
68
|
-
id: ctx.params.id,
|
|
69
|
-
})
|
|
85
|
+
export async function find(ctx: UserCtx<void, FindGlobalTemplateResponse>) {
|
|
86
|
+
ctx.body = await getTemplateByID(ctx.params.id)
|
|
70
87
|
}
|
|
71
88
|
|
|
72
|
-
export async function destroy(
|
|
89
|
+
export async function destroy(
|
|
90
|
+
ctx: UserCtx<void, DeleteGlobalTemplateResponse>
|
|
91
|
+
) {
|
|
73
92
|
const db = tenancy.getGlobalDB()
|
|
74
93
|
await db.remove(ctx.params.id, ctx.params.rev)
|
|
75
|
-
ctx.
|
|
76
|
-
ctx.status = 200
|
|
94
|
+
ctx.body = { message: `Template ${ctx.params.id} deleted.` }
|
|
77
95
|
}
|
|
@@ -6,21 +6,34 @@ import {
|
|
|
6
6
|
AddSSoUserRequest,
|
|
7
7
|
BulkUserRequest,
|
|
8
8
|
BulkUserResponse,
|
|
9
|
+
CheckInviteResponse,
|
|
10
|
+
CountUserResponse,
|
|
9
11
|
CreateAdminUserRequest,
|
|
10
12
|
CreateAdminUserResponse,
|
|
11
13
|
Ctx,
|
|
12
14
|
DeleteInviteUserRequest,
|
|
13
15
|
DeleteInviteUsersRequest,
|
|
16
|
+
DeleteInviteUsersResponse,
|
|
17
|
+
DeleteUserResponse,
|
|
18
|
+
FetchUsersResponse,
|
|
19
|
+
FindUserResponse,
|
|
20
|
+
GetUserInvitesResponse,
|
|
14
21
|
Hosting,
|
|
15
22
|
InviteUserRequest,
|
|
23
|
+
InviteUserResponse,
|
|
16
24
|
InviteUsersRequest,
|
|
17
25
|
InviteUsersResponse,
|
|
18
26
|
LockName,
|
|
19
27
|
LockType,
|
|
28
|
+
LookupAccountHolderResponse,
|
|
29
|
+
LookupTenantUserResponse,
|
|
20
30
|
MigrationType,
|
|
21
31
|
PlatformUserByEmail,
|
|
22
32
|
SaveUserResponse,
|
|
23
33
|
SearchUsersRequest,
|
|
34
|
+
SearchUsersResponse,
|
|
35
|
+
UpdateInviteRequest,
|
|
36
|
+
UpdateInviteResponse,
|
|
24
37
|
User,
|
|
25
38
|
UserCtx,
|
|
26
39
|
UserIdentifier,
|
|
@@ -80,7 +93,7 @@ export const save = async (ctx: UserCtx<User, SaveUserResponse>) => {
|
|
|
80
93
|
}
|
|
81
94
|
}
|
|
82
95
|
|
|
83
|
-
export const addSsoSupport = async (ctx: Ctx<AddSSoUserRequest>) => {
|
|
96
|
+
export const addSsoSupport = async (ctx: Ctx<AddSSoUserRequest, void>) => {
|
|
84
97
|
const { email, ssoId } = ctx.request.body
|
|
85
98
|
try {
|
|
86
99
|
// Status is changed to 404 from getUserDoc if user is not found
|
|
@@ -207,7 +220,7 @@ export const adminUser = async (
|
|
|
207
220
|
})
|
|
208
221
|
}
|
|
209
222
|
|
|
210
|
-
export const countByApp = async (ctx:
|
|
223
|
+
export const countByApp = async (ctx: UserCtx<void, CountUserResponse>) => {
|
|
211
224
|
const appId = ctx.params.appId
|
|
212
225
|
try {
|
|
213
226
|
ctx.body = await userSdk.db.countUsersByApp(appId)
|
|
@@ -216,7 +229,7 @@ export const countByApp = async (ctx: any) => {
|
|
|
216
229
|
}
|
|
217
230
|
}
|
|
218
231
|
|
|
219
|
-
export const destroy = async (ctx:
|
|
232
|
+
export const destroy = async (ctx: UserCtx<void, DeleteUserResponse>) => {
|
|
220
233
|
const id = ctx.params.id
|
|
221
234
|
if (id === ctx.user._id) {
|
|
222
235
|
ctx.throw(400, "Unable to delete self.")
|
|
@@ -239,7 +252,9 @@ export const getAppUsers = async (ctx: Ctx<SearchUsersRequest>) => {
|
|
|
239
252
|
ctx.body = { data: users }
|
|
240
253
|
}
|
|
241
254
|
|
|
242
|
-
export const search = async (
|
|
255
|
+
export const search = async (
|
|
256
|
+
ctx: Ctx<SearchUsersRequest, SearchUsersResponse>
|
|
257
|
+
) => {
|
|
243
258
|
const body = ctx.request.body
|
|
244
259
|
|
|
245
260
|
// TODO: for now only two supported search keys; string.email and equal._id
|
|
@@ -280,7 +295,7 @@ export const search = async (ctx: Ctx<SearchUsersRequest>) => {
|
|
|
280
295
|
}
|
|
281
296
|
|
|
282
297
|
// called internally by app server user fetch
|
|
283
|
-
export const fetch = async (ctx:
|
|
298
|
+
export const fetch = async (ctx: UserCtx<void, FetchUsersResponse>) => {
|
|
284
299
|
const all = await userSdk.db.allUsers()
|
|
285
300
|
// user hashed password shouldn't ever be returned
|
|
286
301
|
for (let user of all) {
|
|
@@ -292,11 +307,13 @@ export const fetch = async (ctx: any) => {
|
|
|
292
307
|
}
|
|
293
308
|
|
|
294
309
|
// called internally by app server user find
|
|
295
|
-
export const find = async (ctx:
|
|
310
|
+
export const find = async (ctx: UserCtx<void, FindUserResponse>) => {
|
|
296
311
|
ctx.body = await userSdk.db.getUser(ctx.params.id)
|
|
297
312
|
}
|
|
298
313
|
|
|
299
|
-
export const tenantUserLookup = async (
|
|
314
|
+
export const tenantUserLookup = async (
|
|
315
|
+
ctx: UserCtx<void, LookupTenantUserResponse>
|
|
316
|
+
) => {
|
|
300
317
|
const id = ctx.params.id
|
|
301
318
|
// is email, check its valid
|
|
302
319
|
if (id.includes("@") && !emailValidator.validate(id)) {
|
|
@@ -314,7 +331,9 @@ export const tenantUserLookup = async (ctx: any) => {
|
|
|
314
331
|
* This will be paginated to a default of the first 50 users,
|
|
315
332
|
* So the account holder may not be found until further pagination has occurred
|
|
316
333
|
*/
|
|
317
|
-
export const accountHolderLookup = async (
|
|
334
|
+
export const accountHolderLookup = async (
|
|
335
|
+
ctx: Ctx<void, LookupAccountHolderResponse>
|
|
336
|
+
) => {
|
|
318
337
|
try {
|
|
319
338
|
const users = await userSdk.core.getAllUsers()
|
|
320
339
|
const response = await userSdk.core.getExistingAccounts(
|
|
@@ -366,7 +385,9 @@ export const onboardUsers = async (
|
|
|
366
385
|
ctx.body = { ...resp, created: true }
|
|
367
386
|
}
|
|
368
387
|
|
|
369
|
-
export const invite = async (
|
|
388
|
+
export const invite = async (
|
|
389
|
+
ctx: Ctx<InviteUserRequest, InviteUserResponse>
|
|
390
|
+
) => {
|
|
370
391
|
const request = ctx.request.body
|
|
371
392
|
|
|
372
393
|
let multiRequest = [request]
|
|
@@ -389,12 +410,14 @@ export const invite = async (ctx: Ctx<InviteUserRequest>) => {
|
|
|
389
410
|
}
|
|
390
411
|
}
|
|
391
412
|
|
|
392
|
-
export const inviteMultiple = async (
|
|
413
|
+
export const inviteMultiple = async (
|
|
414
|
+
ctx: Ctx<InviteUsersRequest, InviteUsersResponse>
|
|
415
|
+
) => {
|
|
393
416
|
ctx.body = await userSdk.invite(ctx.request.body)
|
|
394
417
|
}
|
|
395
418
|
|
|
396
419
|
export const removeMultipleInvites = async (
|
|
397
|
-
ctx: Ctx<DeleteInviteUsersRequest>
|
|
420
|
+
ctx: Ctx<DeleteInviteUsersRequest, DeleteInviteUsersResponse>
|
|
398
421
|
) => {
|
|
399
422
|
const inviteCodesToRemove = ctx.request.body.map(
|
|
400
423
|
(invite: DeleteInviteUserRequest) => invite.code
|
|
@@ -407,7 +430,7 @@ export const removeMultipleInvites = async (
|
|
|
407
430
|
}
|
|
408
431
|
}
|
|
409
432
|
|
|
410
|
-
export const checkInvite = async (ctx:
|
|
433
|
+
export const checkInvite = async (ctx: UserCtx<void, CheckInviteResponse>) => {
|
|
411
434
|
const { code } = ctx.params
|
|
412
435
|
let invite
|
|
413
436
|
try {
|
|
@@ -422,7 +445,9 @@ export const checkInvite = async (ctx: any) => {
|
|
|
422
445
|
}
|
|
423
446
|
}
|
|
424
447
|
|
|
425
|
-
export const getUserInvites = async (
|
|
448
|
+
export const getUserInvites = async (
|
|
449
|
+
ctx: UserCtx<void, GetUserInvitesResponse>
|
|
450
|
+
) => {
|
|
426
451
|
try {
|
|
427
452
|
// Restricted to the currently authenticated tenant
|
|
428
453
|
ctx.body = await cache.invite.getInviteCodes()
|
|
@@ -431,7 +456,9 @@ export const getUserInvites = async (ctx: any) => {
|
|
|
431
456
|
}
|
|
432
457
|
}
|
|
433
458
|
|
|
434
|
-
export const updateInvite = async (
|
|
459
|
+
export const updateInvite = async (
|
|
460
|
+
ctx: UserCtx<UpdateInviteRequest, UpdateInviteResponse>
|
|
461
|
+
) => {
|
|
435
462
|
const { code } = ctx.params
|
|
436
463
|
let updateBody = { ...ctx.request.body }
|
|
437
464
|
|