@budibase/worker 1.0.167 → 1.0.170
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.170",
|
|
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.170",
|
|
35
|
+
"@budibase/pro": "1.0.169",
|
|
36
|
+
"@budibase/string-templates": "^1.0.170",
|
|
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": "8f71291cf5d14ad1f06793a475157866ce8d585b"
|
|
93
93
|
}
|
|
@@ -14,6 +14,7 @@ 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 { withCache } = require("../../../utilities/redis")
|
|
17
18
|
|
|
18
19
|
const BB_TENANT_CDN = "https://tenants.cdn.budi.live"
|
|
19
20
|
|
|
@@ -249,58 +250,64 @@ exports.configChecklist = async function (ctx) {
|
|
|
249
250
|
const tenantId = getTenantId()
|
|
250
251
|
|
|
251
252
|
try {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
253
|
+
const ONE_MINUTE = 600
|
|
254
|
+
|
|
255
|
+
ctx.body = await withCache(
|
|
256
|
+
`checklist:${tenantId}`,
|
|
257
|
+
ONE_MINUTE,
|
|
258
|
+
async () => {
|
|
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
|
+
})
|
|
274
|
+
|
|
275
|
+
// They have set up OIDC
|
|
276
|
+
const oidcConfig = await getScopedFullConfig(db, {
|
|
277
|
+
type: Configs.OIDC,
|
|
278
|
+
})
|
|
279
|
+
|
|
280
|
+
// They have set up an global user
|
|
281
|
+
const users = await db.allDocs(
|
|
282
|
+
getGlobalUserParams(null, {
|
|
283
|
+
include_docs: true,
|
|
284
|
+
limit: 1,
|
|
285
|
+
})
|
|
286
|
+
)
|
|
287
|
+
return {
|
|
288
|
+
apps: {
|
|
289
|
+
checked: apps.length > 0,
|
|
290
|
+
label: "Create your first app",
|
|
291
|
+
link: "/builder/portal/apps",
|
|
292
|
+
},
|
|
293
|
+
smtp: {
|
|
294
|
+
checked: !!smtpConfig,
|
|
295
|
+
label: "Set up email",
|
|
296
|
+
link: "/builder/portal/manage/email",
|
|
297
|
+
},
|
|
298
|
+
adminUser: {
|
|
299
|
+
checked: users && users.rows.length >= 1,
|
|
300
|
+
label: "Create your first user",
|
|
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
|
+
}
|
|
309
|
+
}
|
|
279
310
|
)
|
|
280
|
-
const adminUser = users.rows.some(row => row.doc.admin)
|
|
281
|
-
|
|
282
|
-
ctx.body = {
|
|
283
|
-
apps: {
|
|
284
|
-
checked: apps.length > 0,
|
|
285
|
-
label: "Create your first app",
|
|
286
|
-
link: "/builder/portal/apps",
|
|
287
|
-
},
|
|
288
|
-
smtp: {
|
|
289
|
-
checked: !!smtpConfig,
|
|
290
|
-
label: "Set up email",
|
|
291
|
-
link: "/builder/portal/manage/email",
|
|
292
|
-
},
|
|
293
|
-
adminUser: {
|
|
294
|
-
checked: adminUser,
|
|
295
|
-
label: "Create your first user",
|
|
296
|
-
link: "/builder/portal/manage/users",
|
|
297
|
-
},
|
|
298
|
-
sso: {
|
|
299
|
-
checked: !!googleConfig || !!oidcConfig,
|
|
300
|
-
label: "Set up single sign-on",
|
|
301
|
-
link: "/builder/portal/manage/auth",
|
|
302
|
-
},
|
|
303
|
-
}
|
|
304
311
|
} catch (err) {
|
|
305
312
|
ctx.throw(err.status, err)
|
|
306
313
|
}
|
package/src/environment.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const { join } = require("path")
|
|
2
|
+
|
|
1
3
|
function isDev() {
|
|
2
4
|
return process.env.NODE_ENV !== "production"
|
|
3
5
|
}
|
|
@@ -12,7 +14,9 @@ function isTest() {
|
|
|
12
14
|
|
|
13
15
|
let LOADED = false
|
|
14
16
|
if (!LOADED && isDev() && !isTest()) {
|
|
15
|
-
require("dotenv").config(
|
|
17
|
+
require("dotenv").config({
|
|
18
|
+
path: join(__dirname, "..", ".env"),
|
|
19
|
+
})
|
|
16
20
|
LOADED = true
|
|
17
21
|
}
|
|
18
22
|
|
package/src/utilities/redis.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const { Client, utils } = require("@budibase/backend-core/redis")
|
|
2
2
|
const { newid } = require("@budibase/backend-core/utils")
|
|
3
|
+
const env = require("../environment")
|
|
3
4
|
|
|
4
5
|
function getExpirySecondsForDB(db) {
|
|
5
6
|
switch (db) {
|
|
@@ -12,7 +13,7 @@ function getExpirySecondsForDB(db) {
|
|
|
12
13
|
}
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
let pwResetClient, invitationClient
|
|
16
|
+
let pwResetClient, invitationClient, cachingClient
|
|
16
17
|
|
|
17
18
|
function getClient(db) {
|
|
18
19
|
switch (db) {
|
|
@@ -20,6 +21,8 @@ function getClient(db) {
|
|
|
20
21
|
return pwResetClient
|
|
21
22
|
case utils.Databases.INVITATIONS:
|
|
22
23
|
return invitationClient
|
|
24
|
+
case utils.Databases.DATA_CACHE:
|
|
25
|
+
return cachingClient
|
|
23
26
|
}
|
|
24
27
|
}
|
|
25
28
|
|
|
@@ -45,8 +48,10 @@ async function getACode(db, code, deleteCode = true) {
|
|
|
45
48
|
exports.init = async () => {
|
|
46
49
|
pwResetClient = new Client(utils.Databases.PW_RESETS)
|
|
47
50
|
invitationClient = new Client(utils.Databases.INVITATIONS)
|
|
51
|
+
cachingClient = new Client(utils.Databases.DATA_CACHE)
|
|
48
52
|
await pwResetClient.init()
|
|
49
53
|
await invitationClient.init()
|
|
54
|
+
await cachingClient.init()
|
|
50
55
|
}
|
|
51
56
|
|
|
52
57
|
/**
|
|
@@ -104,3 +109,23 @@ exports.checkInviteCode = async (inviteCode, deleteCode = true) => {
|
|
|
104
109
|
throw "Invitation is not valid or has expired, please request a new one."
|
|
105
110
|
}
|
|
106
111
|
}
|
|
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
|
+
}
|