@budibase/backend-core 2.13.13 → 2.13.15
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/dist/index.js +355 -24
- package/dist/index.js.map +4 -4
- package/dist/index.js.meta.json +1 -1
- package/dist/package.json +4 -4
- package/dist/src/auth/auth.js.map +1 -1
- package/dist/src/configs/configs.js +3 -4
- package/dist/src/configs/configs.js.map +1 -1
- package/dist/src/constants/db.js.map +1 -1
- package/dist/src/db/utils.js.map +1 -1
- package/dist/src/docIds/conversions.js.map +1 -1
- package/dist/src/events/processors/posthog/index.js.map +1 -1
- package/dist/src/features/index.js.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/installation.js +2 -3
- package/dist/src/installation.js.map +1 -1
- package/dist/src/logging/correlation/correlation.js.map +1 -1
- package/dist/src/logging/correlation/middleware.js.map +1 -1
- package/dist/src/logging/pino/middleware.js.map +1 -1
- package/dist/src/middleware/index.js.map +1 -1
- package/dist/src/middleware/passport/sso/google.js.map +1 -1
- package/dist/src/objectStore/objectStore.js.map +1 -1
- package/dist/src/security/roles.js +1 -2
- package/dist/src/security/roles.js.map +1 -1
- package/dist/src/security/sessions.js.map +1 -1
- package/dist/src/users/db.d.ts +5 -0
- package/dist/src/users/db.js +28 -2
- package/dist/src/users/db.js.map +1 -1
- package/dist/src/users/users.d.ts +12 -11
- package/dist/src/users/users.js +175 -144
- package/dist/src/users/users.js.map +1 -1
- package/dist/src/utils/hashing.js.map +1 -1
- package/dist/src/utils/utils.js.map +1 -1
- package/dist/tests/core/utilities/mocks/alerts.js.map +1 -1
- package/dist/tests/core/utilities/mocks/index.js.map +1 -1
- package/dist/tests/core/utilities/structures/generator.js.map +1 -1
- package/dist/tests/jestSetup.js.map +1 -1
- package/package.json +4 -4
- package/src/auth/auth.ts +2 -0
- package/src/configs/configs.ts +3 -4
- package/src/constants/db.ts +1 -0
- package/src/db/utils.ts +1 -0
- package/src/docIds/conversions.ts +1 -0
- package/src/events/processors/posthog/index.ts +1 -0
- package/src/events/processors/posthog/tests/PosthogProcessor.spec.ts +2 -0
- package/src/features/index.ts +1 -0
- package/src/index.ts +1 -0
- package/src/installation.ts +1 -2
- package/src/logging/correlation/correlation.ts +1 -0
- package/src/logging/correlation/middleware.ts +1 -0
- package/src/logging/pino/middleware.ts +3 -0
- package/src/middleware/index.ts +1 -0
- package/src/middleware/passport/sso/google.ts +1 -0
- package/src/middleware/passport/sso/tests/google.spec.ts +1 -0
- package/src/middleware/passport/sso/tests/sso.spec.ts +1 -0
- package/src/middleware/tests/builder.spec.ts +1 -0
- package/src/objectStore/objectStore.ts +1 -0
- package/src/security/roles.ts +7 -2
- package/src/security/sessions.ts +1 -0
- package/src/users/db.ts +33 -5
- package/src/users/users.ts +28 -16
- package/src/utils/hashing.ts +1 -0
- package/src/utils/utils.ts +1 -0
- package/tests/core/utilities/mocks/alerts.ts +1 -0
- package/tests/core/utilities/mocks/index.ts +1 -0
- package/tests/core/utilities/structures/generator.ts +1 -0
- package/tests/jestSetup.ts +1 -0
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import env from "../../environment"
|
|
2
2
|
import { logger } from "./logger"
|
|
3
3
|
import { IncomingMessage } from "http"
|
|
4
|
+
|
|
4
5
|
const pino = require("koa-pino-logger")
|
|
6
|
+
|
|
5
7
|
import { Options } from "pino-http"
|
|
6
8
|
import { Ctx } from "@budibase/types"
|
|
9
|
+
|
|
7
10
|
const correlator = require("correlation-id")
|
|
8
11
|
|
|
9
12
|
export function pinoSettings(): Options {
|
package/src/middleware/index.ts
CHANGED
package/src/security/roles.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { BuiltinPermissionID, PermissionLevel } from "./permissions"
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
prefixRoleID,
|
|
4
|
+
getRoleParams,
|
|
5
|
+
DocumentType,
|
|
6
|
+
SEPARATOR,
|
|
7
|
+
doWithDB,
|
|
8
|
+
} from "../db"
|
|
3
9
|
import { getAppDB } from "../context"
|
|
4
|
-
import { doWithDB } from "../db"
|
|
5
10
|
import { Screen, Role as RoleDoc } from "@budibase/types"
|
|
6
11
|
import cloneDeep from "lodash/fp/cloneDeep"
|
|
7
12
|
|
package/src/security/sessions.ts
CHANGED
package/src/users/db.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import env from "../environment"
|
|
2
2
|
import * as eventHelpers from "./events"
|
|
3
|
-
import * as accounts from "../accounts"
|
|
4
3
|
import * as accountSdk from "../accounts"
|
|
5
4
|
import * as cache from "../cache"
|
|
6
|
-
import { getGlobalDB, getIdentity, getTenantId } from "../context"
|
|
5
|
+
import { doInTenant, getGlobalDB, getIdentity, getTenantId } from "../context"
|
|
7
6
|
import * as dbUtils from "../db"
|
|
8
7
|
import { EmailUnavailableError, HTTPError } from "../errors"
|
|
9
8
|
import * as platform from "../platform"
|
|
@@ -11,12 +10,10 @@ import * as sessions from "../security/sessions"
|
|
|
11
10
|
import * as usersCore from "./users"
|
|
12
11
|
import {
|
|
13
12
|
Account,
|
|
14
|
-
AllDocsResponse,
|
|
15
13
|
BulkUserCreated,
|
|
16
14
|
BulkUserDeleted,
|
|
17
15
|
isSSOAccount,
|
|
18
16
|
isSSOUser,
|
|
19
|
-
RowResponse,
|
|
20
17
|
SaveUserOpts,
|
|
21
18
|
User,
|
|
22
19
|
UserStatus,
|
|
@@ -467,7 +464,7 @@ export class UserDB {
|
|
|
467
464
|
if (!env.SELF_HOSTED && !env.DISABLE_ACCOUNT_PORTAL) {
|
|
468
465
|
// root account holder can't be deleted from inside budibase
|
|
469
466
|
const email = dbUser.email
|
|
470
|
-
const account = await
|
|
467
|
+
const account = await accountSdk.getAccount(email)
|
|
471
468
|
if (account) {
|
|
472
469
|
if (dbUser.userId === getIdentity()!._id) {
|
|
473
470
|
throw new HTTPError('Please visit "Account" to delete this user', 400)
|
|
@@ -488,6 +485,37 @@ export class UserDB {
|
|
|
488
485
|
await sessions.invalidateSessions(userId, { reason: "deletion" })
|
|
489
486
|
}
|
|
490
487
|
|
|
488
|
+
static async createAdminUser(
|
|
489
|
+
email: string,
|
|
490
|
+
password: string,
|
|
491
|
+
tenantId: string,
|
|
492
|
+
opts?: { ssoId?: string; hashPassword?: boolean; requirePassword?: boolean }
|
|
493
|
+
) {
|
|
494
|
+
const user: User = {
|
|
495
|
+
email: email,
|
|
496
|
+
password: password,
|
|
497
|
+
createdAt: Date.now(),
|
|
498
|
+
roles: {},
|
|
499
|
+
builder: {
|
|
500
|
+
global: true,
|
|
501
|
+
},
|
|
502
|
+
admin: {
|
|
503
|
+
global: true,
|
|
504
|
+
},
|
|
505
|
+
tenantId,
|
|
506
|
+
}
|
|
507
|
+
if (opts?.ssoId) {
|
|
508
|
+
user.ssoId = opts.ssoId
|
|
509
|
+
}
|
|
510
|
+
// always bust checklist beforehand, if an error occurs but can proceed, don't get
|
|
511
|
+
// stuck in a cycle
|
|
512
|
+
await cache.bustCache(cache.CacheKey.CHECKLIST)
|
|
513
|
+
return await UserDB.save(user, {
|
|
514
|
+
hashPassword: opts?.hashPassword,
|
|
515
|
+
requirePassword: opts?.requirePassword,
|
|
516
|
+
})
|
|
517
|
+
}
|
|
518
|
+
|
|
491
519
|
static async getGroups(groupIds: string[]) {
|
|
492
520
|
return await this.groups.getBulk(groupIds)
|
|
493
521
|
}
|
package/src/users/users.ts
CHANGED
|
@@ -43,7 +43,7 @@ function removeUserPassword(users: User | User[]) {
|
|
|
43
43
|
return users
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
export
|
|
46
|
+
export function isSupportedUserSearch(query: SearchQuery) {
|
|
47
47
|
const allowed = [
|
|
48
48
|
{ op: SearchQueryOperators.STRING, key: "email" },
|
|
49
49
|
{ op: SearchQueryOperators.EQUAL, key: "_id" },
|
|
@@ -68,10 +68,10 @@ export const isSupportedUserSearch = (query: SearchQuery) => {
|
|
|
68
68
|
return true
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
export
|
|
71
|
+
export async function bulkGetGlobalUsersById(
|
|
72
72
|
userIds: string[],
|
|
73
73
|
opts?: GetOpts
|
|
74
|
-
)
|
|
74
|
+
) {
|
|
75
75
|
const db = getGlobalDB()
|
|
76
76
|
let users = (
|
|
77
77
|
await db.allDocs({
|
|
@@ -85,7 +85,7 @@ export const bulkGetGlobalUsersById = async (
|
|
|
85
85
|
return users
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
export
|
|
88
|
+
export async function getAllUserIds() {
|
|
89
89
|
const db = getGlobalDB()
|
|
90
90
|
const startKey = `${DocumentType.USER}${SEPARATOR}`
|
|
91
91
|
const response = await db.allDocs({
|
|
@@ -95,7 +95,7 @@ export const getAllUserIds = async () => {
|
|
|
95
95
|
return response.rows.map(row => row.id)
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
export
|
|
98
|
+
export async function bulkUpdateGlobalUsers(users: User[]) {
|
|
99
99
|
const db = getGlobalDB()
|
|
100
100
|
return (await db.bulkDocs(users)) as BulkDocsResponse
|
|
101
101
|
}
|
|
@@ -113,10 +113,10 @@ export async function getById(id: string, opts?: GetOpts): Promise<User> {
|
|
|
113
113
|
* Given an email address this will use a view to search through
|
|
114
114
|
* all the users to find one with this email address.
|
|
115
115
|
*/
|
|
116
|
-
export
|
|
116
|
+
export async function getGlobalUserByEmail(
|
|
117
117
|
email: String,
|
|
118
118
|
opts?: GetOpts
|
|
119
|
-
): Promise<User | undefined>
|
|
119
|
+
): Promise<User | undefined> {
|
|
120
120
|
if (email == null) {
|
|
121
121
|
throw "Must supply an email address to view"
|
|
122
122
|
}
|
|
@@ -139,11 +139,23 @@ export const getGlobalUserByEmail = async (
|
|
|
139
139
|
return user
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
export
|
|
142
|
+
export async function doesUserExist(email: string) {
|
|
143
|
+
try {
|
|
144
|
+
const user = await getGlobalUserByEmail(email)
|
|
145
|
+
if (Array.isArray(user) || user != null) {
|
|
146
|
+
return true
|
|
147
|
+
}
|
|
148
|
+
} catch (err) {
|
|
149
|
+
return false
|
|
150
|
+
}
|
|
151
|
+
return false
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export async function searchGlobalUsersByApp(
|
|
143
155
|
appId: any,
|
|
144
156
|
opts: DatabaseQueryOpts,
|
|
145
157
|
getOpts?: GetOpts
|
|
146
|
-
)
|
|
158
|
+
) {
|
|
147
159
|
if (typeof appId !== "string") {
|
|
148
160
|
throw new Error("Must provide a string based app ID")
|
|
149
161
|
}
|
|
@@ -167,10 +179,10 @@ export const searchGlobalUsersByApp = async (
|
|
|
167
179
|
Return any user who potentially has access to the application
|
|
168
180
|
Admins, developers and app users with the explicitly role.
|
|
169
181
|
*/
|
|
170
|
-
export
|
|
182
|
+
export async function searchGlobalUsersByAppAccess(
|
|
171
183
|
appId: any,
|
|
172
184
|
opts?: { limit?: number }
|
|
173
|
-
)
|
|
185
|
+
) {
|
|
174
186
|
const roleSelector = `roles.${appId}`
|
|
175
187
|
|
|
176
188
|
let orQuery: any[] = [
|
|
@@ -205,7 +217,7 @@ export const searchGlobalUsersByAppAccess = async (
|
|
|
205
217
|
return resp.rows
|
|
206
218
|
}
|
|
207
219
|
|
|
208
|
-
export
|
|
220
|
+
export function getGlobalUserByAppPage(appId: string, user: User) {
|
|
209
221
|
if (!user) {
|
|
210
222
|
return
|
|
211
223
|
}
|
|
@@ -215,11 +227,11 @@ export const getGlobalUserByAppPage = (appId: string, user: User) => {
|
|
|
215
227
|
/**
|
|
216
228
|
* Performs a starts with search on the global email view.
|
|
217
229
|
*/
|
|
218
|
-
export
|
|
230
|
+
export async function searchGlobalUsersByEmail(
|
|
219
231
|
email: string | unknown,
|
|
220
232
|
opts: any,
|
|
221
233
|
getOpts?: GetOpts
|
|
222
|
-
)
|
|
234
|
+
) {
|
|
223
235
|
if (typeof email !== "string") {
|
|
224
236
|
throw new Error("Must provide a string to search by")
|
|
225
237
|
}
|
|
@@ -242,12 +254,12 @@ export const searchGlobalUsersByEmail = async (
|
|
|
242
254
|
}
|
|
243
255
|
|
|
244
256
|
const PAGE_LIMIT = 8
|
|
245
|
-
export
|
|
257
|
+
export async function paginatedUsers({
|
|
246
258
|
bookmark,
|
|
247
259
|
query,
|
|
248
260
|
appId,
|
|
249
261
|
limit,
|
|
250
|
-
}: SearchUsersRequest = {})
|
|
262
|
+
}: SearchUsersRequest = {}) {
|
|
251
263
|
const db = getGlobalDB()
|
|
252
264
|
const pageSize = limit ?? PAGE_LIMIT
|
|
253
265
|
const pageLimit = pageSize + 1
|
package/src/utils/hashing.ts
CHANGED
package/src/utils/utils.ts
CHANGED