@budibase/worker 1.0.169 → 1.0.172
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": "1.0.
|
|
4
|
+
"version": "1.0.172",
|
|
5
5
|
"description": "Budibase background service",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"repository": {
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
"author": "Budibase",
|
|
32
32
|
"license": "GPL-3.0",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@budibase/backend-core": "^1.0.
|
|
35
|
-
"@budibase/pro": "1.0.
|
|
36
|
-
"@budibase/string-templates": "^1.0.
|
|
34
|
+
"@budibase/backend-core": "^1.0.172",
|
|
35
|
+
"@budibase/pro": "1.0.171",
|
|
36
|
+
"@budibase/string-templates": "^1.0.172",
|
|
37
37
|
"@koa/router": "^8.0.0",
|
|
38
38
|
"@sentry/node": "6.17.7",
|
|
39
39
|
"@techpass/passport-openidconnect": "^0.3.0",
|
|
@@ -89,5 +89,5 @@
|
|
|
89
89
|
"./scripts/jestSetup.js"
|
|
90
90
|
]
|
|
91
91
|
},
|
|
92
|
-
"gitHead": "
|
|
92
|
+
"gitHead": "6af7e640852d273f757db5aee21e1794850bb612"
|
|
93
93
|
}
|
|
@@ -14,7 +14,12 @@ const {
|
|
|
14
14
|
const { getGlobalDB, getTenantId } = require("@budibase/backend-core/tenancy")
|
|
15
15
|
const env = require("../../../environment")
|
|
16
16
|
const { googleCallbackUrl, oidcCallbackUrl } = require("./auth")
|
|
17
|
-
const {
|
|
17
|
+
const {
|
|
18
|
+
withCache,
|
|
19
|
+
CacheKeys,
|
|
20
|
+
TTL,
|
|
21
|
+
bustCache,
|
|
22
|
+
} = require("@budibase/backend-core/cache")
|
|
18
23
|
|
|
19
24
|
const BB_TENANT_CDN = "https://tenants.cdn.budi.live"
|
|
20
25
|
|
|
@@ -44,6 +49,7 @@ exports.save = async function (ctx) {
|
|
|
44
49
|
|
|
45
50
|
try {
|
|
46
51
|
const response = await db.put(ctx.request.body)
|
|
52
|
+
await bustCache(CacheKeys.CHECKLIST)
|
|
47
53
|
ctx.body = {
|
|
48
54
|
type,
|
|
49
55
|
_id: response.id,
|
|
@@ -250,64 +256,58 @@ exports.configChecklist = async function (ctx) {
|
|
|
250
256
|
const tenantId = getTenantId()
|
|
251
257
|
|
|
252
258
|
try {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
let apps = []
|
|
260
|
-
if (!env.MULTI_TENANCY || tenantId) {
|
|
261
|
-
// Apps exist
|
|
262
|
-
apps = await getAllApps({ idsOnly: true, efficient: true })
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
// They have set up SMTP
|
|
266
|
-
const smtpConfig = await getScopedFullConfig(db, {
|
|
267
|
-
type: Configs.SMTP,
|
|
268
|
-
})
|
|
269
|
-
|
|
270
|
-
// They have set up Google Auth
|
|
271
|
-
const googleConfig = await getScopedFullConfig(db, {
|
|
272
|
-
type: Configs.GOOGLE,
|
|
273
|
-
})
|
|
259
|
+
ctx.body = await withCache(CacheKeys.CHECKLIST, TTL.ONE_HOUR, async () => {
|
|
260
|
+
let apps = []
|
|
261
|
+
if (!env.MULTI_TENANCY || tenantId) {
|
|
262
|
+
// Apps exist
|
|
263
|
+
apps = await getAllApps({ idsOnly: true, efficient: true })
|
|
264
|
+
}
|
|
274
265
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
266
|
+
// They have set up SMTP
|
|
267
|
+
const smtpConfig = await getScopedFullConfig(db, {
|
|
268
|
+
type: Configs.SMTP,
|
|
269
|
+
})
|
|
270
|
+
|
|
271
|
+
// They have set up Google Auth
|
|
272
|
+
const googleConfig = await getScopedFullConfig(db, {
|
|
273
|
+
type: Configs.GOOGLE,
|
|
274
|
+
})
|
|
275
|
+
|
|
276
|
+
// They have set up OIDC
|
|
277
|
+
const oidcConfig = await getScopedFullConfig(db, {
|
|
278
|
+
type: Configs.OIDC,
|
|
279
|
+
})
|
|
280
|
+
|
|
281
|
+
// They have set up an global user
|
|
282
|
+
const users = await db.allDocs(
|
|
283
|
+
getGlobalUserParams(null, {
|
|
284
|
+
include_docs: true,
|
|
285
|
+
limit: 1,
|
|
278
286
|
})
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
link: "/builder/portal/manage/users",
|
|
302
|
-
},
|
|
303
|
-
sso: {
|
|
304
|
-
checked: !!googleConfig || !!oidcConfig,
|
|
305
|
-
label: "Set up single sign-on",
|
|
306
|
-
link: "/builder/portal/manage/auth",
|
|
307
|
-
},
|
|
308
|
-
}
|
|
287
|
+
)
|
|
288
|
+
return {
|
|
289
|
+
apps: {
|
|
290
|
+
checked: apps.length > 0,
|
|
291
|
+
label: "Create your first app",
|
|
292
|
+
link: "/builder/portal/apps",
|
|
293
|
+
},
|
|
294
|
+
smtp: {
|
|
295
|
+
checked: !!smtpConfig,
|
|
296
|
+
label: "Set up email",
|
|
297
|
+
link: "/builder/portal/manage/email",
|
|
298
|
+
},
|
|
299
|
+
adminUser: {
|
|
300
|
+
checked: users && users.rows.length >= 1,
|
|
301
|
+
label: "Create your first user",
|
|
302
|
+
link: "/builder/portal/manage/users",
|
|
303
|
+
},
|
|
304
|
+
sso: {
|
|
305
|
+
checked: !!googleConfig || !!oidcConfig,
|
|
306
|
+
label: "Set up single sign-on",
|
|
307
|
+
link: "/builder/portal/manage/auth",
|
|
308
|
+
},
|
|
309
309
|
}
|
|
310
|
-
)
|
|
310
|
+
})
|
|
311
311
|
} catch (err) {
|
|
312
312
|
ctx.throw(err.status, err)
|
|
313
313
|
}
|
|
@@ -3,9 +3,6 @@ const {
|
|
|
3
3
|
StaticDatabases,
|
|
4
4
|
} = require("@budibase/backend-core/db")
|
|
5
5
|
const { getGlobalUserByEmail } = require("@budibase/backend-core/utils")
|
|
6
|
-
import { EmailTemplatePurpose } from "../../../constants"
|
|
7
|
-
import { checkInviteCode } from "../../../utilities/redis"
|
|
8
|
-
import { sendEmail } from "../../../utilities/email"
|
|
9
6
|
const { user: userCache } = require("@budibase/backend-core/cache")
|
|
10
7
|
const { invalidateSessions } = require("@budibase/backend-core/sessions")
|
|
11
8
|
const accounts = require("@budibase/backend-core/accounts")
|
|
@@ -17,11 +14,15 @@ const {
|
|
|
17
14
|
doesTenantExist,
|
|
18
15
|
} = require("@budibase/backend-core/tenancy")
|
|
19
16
|
const { removeUserFromInfoDB } = require("@budibase/backend-core/deprovision")
|
|
17
|
+
const { errors } = require("@budibase/backend-core")
|
|
18
|
+
const { CacheKeys, bustCache } = require("@budibase/backend-core/cache")
|
|
20
19
|
import env from "../../../environment"
|
|
21
20
|
import { syncUserInApps } from "../../../utilities/appService"
|
|
22
21
|
import { quotas, users } from "@budibase/pro"
|
|
23
|
-
const { errors } = require("@budibase/backend-core")
|
|
24
22
|
import { allUsers, getUser } from "../../utilities"
|
|
23
|
+
import { EmailTemplatePurpose } from "../../../constants"
|
|
24
|
+
import { checkInviteCode } from "../../../utilities/redis"
|
|
25
|
+
import { sendEmail } from "../../../utilities/email"
|
|
25
26
|
|
|
26
27
|
export const save = async (ctx: any) => {
|
|
27
28
|
try {
|
|
@@ -93,7 +94,14 @@ export const adminUser = async (ctx: any) => {
|
|
|
93
94
|
tenantId,
|
|
94
95
|
}
|
|
95
96
|
try {
|
|
96
|
-
|
|
97
|
+
const finalUser = await users.save(
|
|
98
|
+
user,
|
|
99
|
+
tenantId,
|
|
100
|
+
hashPassword,
|
|
101
|
+
requirePassword
|
|
102
|
+
)
|
|
103
|
+
await bustCache(CacheKeys.CHECKLIST)
|
|
104
|
+
ctx.body = finalUser
|
|
97
105
|
} catch (err: any) {
|
|
98
106
|
ctx.throw(err.status || 400, err)
|
|
99
107
|
}
|
package/src/utilities/redis.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const { Client, utils } = require("@budibase/backend-core/redis")
|
|
2
2
|
const { newid } = require("@budibase/backend-core/utils")
|
|
3
|
-
const env = require("../environment")
|
|
4
3
|
|
|
5
4
|
function getExpirySecondsForDB(db) {
|
|
6
5
|
switch (db) {
|
|
@@ -13,7 +12,7 @@ function getExpirySecondsForDB(db) {
|
|
|
13
12
|
}
|
|
14
13
|
}
|
|
15
14
|
|
|
16
|
-
let pwResetClient, invitationClient
|
|
15
|
+
let pwResetClient, invitationClient
|
|
17
16
|
|
|
18
17
|
function getClient(db) {
|
|
19
18
|
switch (db) {
|
|
@@ -21,8 +20,6 @@ function getClient(db) {
|
|
|
21
20
|
return pwResetClient
|
|
22
21
|
case utils.Databases.INVITATIONS:
|
|
23
22
|
return invitationClient
|
|
24
|
-
case utils.Databases.DATA_CACHE:
|
|
25
|
-
return cachingClient
|
|
26
23
|
}
|
|
27
24
|
}
|
|
28
25
|
|
|
@@ -48,10 +45,8 @@ async function getACode(db, code, deleteCode = true) {
|
|
|
48
45
|
exports.init = async () => {
|
|
49
46
|
pwResetClient = new Client(utils.Databases.PW_RESETS)
|
|
50
47
|
invitationClient = new Client(utils.Databases.INVITATIONS)
|
|
51
|
-
cachingClient = new Client(utils.Databases.DATA_CACHE)
|
|
52
48
|
await pwResetClient.init()
|
|
53
49
|
await invitationClient.init()
|
|
54
|
-
await cachingClient.init()
|
|
55
50
|
}
|
|
56
51
|
|
|
57
52
|
/**
|
|
@@ -66,6 +61,7 @@ exports.shutdown = async () => {
|
|
|
66
61
|
* Given a user ID this will store a code (that is returned) for an hour in redis.
|
|
67
62
|
* The user can then return this code for resetting their password (through their reset link).
|
|
68
63
|
* @param {string} userId the ID of the user which is to be reset.
|
|
64
|
+
* @param {object} info Info about the user/the reset process.
|
|
69
65
|
* @return {Promise<string>} returns the code that was stored to redis.
|
|
70
66
|
*/
|
|
71
67
|
exports.getResetPasswordCode = async (userId, info) => {
|
|
@@ -109,23 +105,3 @@ exports.checkInviteCode = async (inviteCode, deleteCode = true) => {
|
|
|
109
105
|
throw "Invitation is not valid or has expired, please request a new one."
|
|
110
106
|
}
|
|
111
107
|
}
|
|
112
|
-
|
|
113
|
-
// TODO: move into backend-core
|
|
114
|
-
exports.withCache = async (key, ttl, fetchFn) => {
|
|
115
|
-
const cachedValue = await cachingClient.get(key)
|
|
116
|
-
if (cachedValue) {
|
|
117
|
-
return cachedValue
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
try {
|
|
121
|
-
const fetchedValue = await fetchFn()
|
|
122
|
-
|
|
123
|
-
if (!env.isTest()) {
|
|
124
|
-
await cachingClient.store(key, fetchedValue, ttl)
|
|
125
|
-
}
|
|
126
|
-
return fetchedValue
|
|
127
|
-
} catch (err) {
|
|
128
|
-
console.error("Error calling fetch function", err)
|
|
129
|
-
throw err
|
|
130
|
-
}
|
|
131
|
-
}
|