@budibase/worker 1.0.168 → 1.0.171

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.168",
4
+ "version": "1.0.171",
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.168",
35
- "@budibase/pro": "1.0.167",
36
- "@budibase/string-templates": "^1.0.168",
34
+ "@budibase/backend-core": "^1.0.171",
35
+ "@budibase/pro": "1.0.170",
36
+ "@budibase/string-templates": "^1.0.171",
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": "7e71bec61d8581f453d2259a2189911c2ea42d41"
92
+ "gitHead": "be3f4676fd4d319b4969955aa65a71e313bb8774"
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,59 +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
-
275
- // They have set up an global user
276
- const users = await db.allDocs(
277
- getGlobalUserParams(null, {
278
- include_docs: true,
279
- limit: 1,
280
- })
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
+ }
281
310
  )
282
-
283
- ctx.body = {
284
- apps: {
285
- checked: apps.length > 0,
286
- label: "Create your first app",
287
- link: "/builder/portal/apps",
288
- },
289
- smtp: {
290
- checked: !!smtpConfig,
291
- label: "Set up email",
292
- link: "/builder/portal/manage/email",
293
- },
294
- adminUser: {
295
- checked: users && users.rows.length >= 1,
296
- label: "Create your first user",
297
- link: "/builder/portal/manage/users",
298
- },
299
- sso: {
300
- checked: !!googleConfig || !!oidcConfig,
301
- label: "Set up single sign-on",
302
- link: "/builder/portal/manage/auth",
303
- },
304
- }
305
311
  } catch (err) {
306
312
  ctx.throw(err.status, err)
307
313
  }
@@ -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
+ }