@budibase/worker 1.0.167-alpha.8 → 1.0.169

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.167-alpha.8",
4
+ "version": "1.0.169",
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.167-alpha.8",
35
- "@budibase/pro": "1.0.167-alpha.7",
36
- "@budibase/string-templates": "^1.0.167-alpha.8",
34
+ "@budibase/backend-core": "^1.0.169",
35
+ "@budibase/pro": "1.0.168",
36
+ "@budibase/string-templates": "^1.0.169",
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": "87da5df156c621854592273cc601b1b7a072aadb"
92
+ "gitHead": "ed0256eff3911443b5df6d9426027702dc0810db"
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
- // TODO: Watch get started video
253
-
254
- let apps = []
255
- if (!env.MULTI_TENANCY || tenantId) {
256
- // Apps exist
257
- apps = await getAllApps({ idsOnly: true, efficient: true })
258
- }
259
-
260
- // They have set up SMTP
261
- const smtpConfig = await getScopedFullConfig(db, {
262
- type: Configs.SMTP,
263
- })
264
-
265
- // They have set up Google Auth
266
- const googleConfig = await getScopedFullConfig(db, {
267
- type: Configs.GOOGLE,
268
- })
269
-
270
- // They have set up OIDC
271
- const oidcConfig = await getScopedFullConfig(db, {
272
- type: Configs.OIDC,
273
- })
274
- // They have set up an global user
275
- const users = await db.allDocs(
276
- getGlobalUserParams(null, {
277
- include_docs: true,
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
  }
@@ -25,5 +25,6 @@ export const getInfo = async (ctx: any) => {
25
25
  }
26
26
 
27
27
  export const getQuotaUsage = async (ctx: any) => {
28
- ctx.body = await quotas.getQuotaUsage()
28
+ const usage = await quotas.getQuotaUsage()
29
+ ctx.body = usage
29
30
  }
@@ -75,8 +75,8 @@ const checkCurrentApp = ctx => {
75
75
  const addSessionAttributesToUser = ctx => {
76
76
  ctx.body.account = ctx.user.account
77
77
  ctx.body.license = ctx.user.license
78
- ctx.body.budibaseAccess = !!ctx.user.budibaseAccess
79
- ctx.body.accountPortalAccess = !!ctx.user.accountPortalAccess
78
+ ctx.body.budibaseAccess = ctx.user.budibaseAccess
79
+ ctx.body.accountPortalAccess = ctx.user.accountPortalAccess
80
80
  ctx.body.csrfToken = ctx.user.csrfToken
81
81
  }
82
82
 
@@ -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,43 +14,39 @@ 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
 
19
23
  module.exports = {
20
- // auth
24
+ NODE_ENV: process.env.NODE_ENV,
25
+ SELF_HOSTED: !!parseInt(process.env.SELF_HOSTED),
26
+ PORT: process.env.PORT || process.env.WORKER_PORT,
27
+ CLUSTER_PORT: process.env.CLUSTER_PORT,
21
28
  MINIO_ACCESS_KEY: process.env.MINIO_ACCESS_KEY,
22
29
  MINIO_SECRET_KEY: process.env.MINIO_SECRET_KEY,
30
+ MINIO_URL: process.env.MINIO_URL,
31
+ COUCH_DB_URL: process.env.COUCH_DB_URL,
32
+ LOG_LEVEL: process.env.LOG_LEVEL,
23
33
  JWT_SECRET: process.env.JWT_SECRET,
24
34
  SALT_ROUNDS: process.env.SALT_ROUNDS,
35
+ REDIS_URL: process.env.REDIS_URL,
25
36
  REDIS_PASSWORD: process.env.REDIS_PASSWORD,
26
37
  INTERNAL_API_KEY: process.env.INTERNAL_API_KEY,
27
- COOKIE_DOMAIN: process.env.COOKIE_DOMAIN,
28
- // urls
29
- MINIO_URL: process.env.MINIO_URL,
30
- COUCH_DB_URL: process.env.COUCH_DB_URL,
31
- REDIS_URL: process.env.REDIS_URL,
32
- ACCOUNT_PORTAL_URL: process.env.ACCOUNT_PORTAL_URL,
33
- PLATFORM_URL: process.env.PLATFORM_URL,
34
- APPS_URL: process.env.APPS_URL,
35
- // ports
36
- PORT: process.env.PORT || process.env.WORKER_PORT,
37
- CLUSTER_PORT: process.env.CLUSTER_PORT,
38
- // flags
39
- NODE_ENV: process.env.NODE_ENV,
40
- SELF_HOSTED: !!parseInt(process.env.SELF_HOSTED),
41
- LOG_LEVEL: process.env.LOG_LEVEL,
42
38
  MULTI_TENANCY: process.env.MULTI_TENANCY,
43
39
  DISABLE_ACCOUNT_PORTAL: process.env.DISABLE_ACCOUNT_PORTAL,
40
+ ACCOUNT_PORTAL_URL: process.env.ACCOUNT_PORTAL_URL,
44
41
  SMTP_FALLBACK_ENABLED: process.env.SMTP_FALLBACK_ENABLED,
45
- DISABLE_DEVELOPER_LICENSE: process.env.DISABLE_DEVELOPER_LICENSE,
46
- // smtp
47
42
  SMTP_USER: process.env.SMTP_USER,
48
43
  SMTP_PASSWORD: process.env.SMTP_PASSWORD,
49
44
  SMTP_HOST: process.env.SMTP_HOST,
50
45
  SMTP_PORT: process.env.SMTP_PORT,
51
46
  SMTP_FROM_ADDRESS: process.env.SMTP_FROM_ADDRESS,
47
+ PLATFORM_URL: process.env.PLATFORM_URL,
48
+ COOKIE_DOMAIN: process.env.COOKIE_DOMAIN,
49
+ APPS_URL: process.env.APPS_URL,
52
50
  _set(key, value) {
53
51
  process.env[key] = value
54
52
  module.exports[key] = value
@@ -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
+ }