@budibase/worker 2.21.9 → 2.22.1

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": "2.21.9",
4
+ "version": "2.22.1",
5
5
  "description": "Budibase background service",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -37,10 +37,10 @@
37
37
  "author": "Budibase",
38
38
  "license": "GPL-3.0",
39
39
  "dependencies": {
40
- "@budibase/backend-core": "2.21.9",
41
- "@budibase/pro": "2.21.9",
42
- "@budibase/string-templates": "2.21.9",
43
- "@budibase/types": "2.21.9",
40
+ "@budibase/backend-core": "2.22.1",
41
+ "@budibase/pro": "2.22.1",
42
+ "@budibase/string-templates": "2.22.1",
43
+ "@budibase/types": "2.22.1",
44
44
  "@koa/router": "8.0.8",
45
45
  "@techpass/passport-openidconnect": "0.3.2",
46
46
  "@types/global-agent": "2.1.1",
@@ -108,5 +108,5 @@
108
108
  }
109
109
  }
110
110
  },
111
- "gitHead": "901d6ae4116d0199b2a68e5be38c8dc5658b48e7"
111
+ "gitHead": "b91392adfadf5e27c40a78102046cb3e51a7a792"
112
112
  }
@@ -9,7 +9,12 @@ import {
9
9
  } from "@budibase/backend-core"
10
10
  import env from "../../../environment"
11
11
  import { groups } from "@budibase/pro"
12
- import { UpdateSelfRequest, UpdateSelfResponse, UserCtx } from "@budibase/types"
12
+ import {
13
+ UpdateSelfRequest,
14
+ UpdateSelfResponse,
15
+ User,
16
+ UserCtx,
17
+ } from "@budibase/types"
13
18
 
14
19
  const { newid } = utils
15
20
 
@@ -105,16 +110,75 @@ export async function getSelf(ctx: any) {
105
110
  addSessionAttributesToUser(ctx)
106
111
  }
107
112
 
113
+ export const syncAppFavourites = async (processedAppIds: string[]) => {
114
+ if (processedAppIds.length === 0) {
115
+ return []
116
+ }
117
+
118
+ const tenantId = tenancy.getTenantId()
119
+ const appPrefix =
120
+ tenantId === tenancy.DEFAULT_TENANT_ID
121
+ ? dbCore.APP_DEV_PREFIX
122
+ : `${dbCore.APP_DEV_PREFIX}${tenantId}_`
123
+
124
+ const apps = await fetchAppsByIds(processedAppIds, appPrefix)
125
+ return apps?.reduce((acc: string[], app) => {
126
+ const id = app.appId.replace(appPrefix, "")
127
+ if (processedAppIds.includes(id)) {
128
+ acc.push(id)
129
+ }
130
+ return acc
131
+ }, [])
132
+ }
133
+
134
+ export const fetchAppsByIds = async (
135
+ processedAppIds: string[],
136
+ appPrefix: string
137
+ ) => {
138
+ return await dbCore.getAppsByIDs(
139
+ processedAppIds.map(appId => {
140
+ return `${appPrefix}${appId}`
141
+ })
142
+ )
143
+ }
144
+
145
+ const processUserAppFavourites = async (
146
+ user: User,
147
+ update: UpdateSelfRequest
148
+ ) => {
149
+ if (!("appFavourites" in update)) {
150
+ // Ignore requests without an explicit update to favourites.
151
+ return
152
+ }
153
+
154
+ const userAppFavourites = user.appFavourites || []
155
+ const requestAppFavourites = new Set(update.appFavourites || [])
156
+ const containsAll = userAppFavourites.every(v => requestAppFavourites.has(v))
157
+
158
+ if (containsAll && requestAppFavourites.size === userAppFavourites.length) {
159
+ // Ignore request if the outcome will have no change
160
+ return
161
+ }
162
+
163
+ // Clean up the request by purging apps that no longer exist.
164
+ const syncedAppFavourites = await syncAppFavourites([...requestAppFavourites])
165
+ return syncedAppFavourites
166
+ }
167
+
108
168
  export async function updateSelf(
109
169
  ctx: UserCtx<UpdateSelfRequest, UpdateSelfResponse>
110
170
  ) {
111
171
  const update = ctx.request.body
112
172
 
113
173
  let user = await userSdk.db.getUser(ctx.user._id!)
174
+ const updatedAppFavourites = await processUserAppFavourites(user, update)
175
+
114
176
  user = {
115
177
  ...user,
116
178
  ...update,
179
+ ...(updatedAppFavourites ? { appFavourites: updatedAppFavourites } : {}),
117
180
  }
181
+
118
182
  user = await userSdk.db.save(user, { requirePassword: false })
119
183
 
120
184
  if (update.password) {
@@ -1,10 +1,18 @@
1
- import { Ctx } from "@budibase/types"
1
+ import { Ctx, MaintenanceType } from "@budibase/types"
2
2
  import env from "../../../environment"
3
3
  import { env as coreEnv } from "@budibase/backend-core"
4
4
  import nodeFetch from "node-fetch"
5
5
 
6
+ // When we come to move to SQS fully and move away from Clouseau, we will need
7
+ // to flip this to true (or remove it entirely). This will then be used to
8
+ // determine if we should show the maintenance page that links to the SQS
9
+ // migration docs.
10
+ const sqsRequired = false
11
+
6
12
  let sqsAvailable: boolean
7
13
  async function isSqsAvailable() {
14
+ // We cache this value for the duration of the Node process because we don't
15
+ // want every page load to be making this relatively expensive check.
8
16
  if (sqsAvailable !== undefined) {
9
17
  return sqsAvailable
10
18
  }
@@ -21,6 +29,10 @@ async function isSqsAvailable() {
21
29
  }
22
30
  }
23
31
 
32
+ async function isSqsMissing() {
33
+ return sqsRequired && !(await isSqsAvailable())
34
+ }
35
+
24
36
  export const fetch = async (ctx: Ctx) => {
25
37
  ctx.body = {
26
38
  multiTenancy: !!env.MULTI_TENANCY,
@@ -30,11 +42,12 @@ export const fetch = async (ctx: Ctx) => {
30
42
  disableAccountPortal: env.DISABLE_ACCOUNT_PORTAL,
31
43
  baseUrl: env.PLATFORM_URL,
32
44
  isDev: env.isDev() && !env.isTest(),
45
+ maintenance: [],
33
46
  }
34
47
 
35
48
  if (env.SELF_HOSTED) {
36
- ctx.body.infrastructure = {
37
- sqs: await isSqsAvailable(),
49
+ if (await isSqsMissing()) {
50
+ ctx.body.maintenance.push({ type: MaintenanceType.SQS_MISSING })
38
51
  }
39
52
  }
40
53
  }
@@ -27,6 +27,7 @@ describe("/api/system/environment", () => {
27
27
  multiTenancy: true,
28
28
  baseUrl: "http://localhost:10000",
29
29
  offlineMode: false,
30
+ maintenance: [],
30
31
  })
31
32
  })
32
33
 
@@ -40,9 +41,7 @@ describe("/api/system/environment", () => {
40
41
  multiTenancy: true,
41
42
  baseUrl: "http://localhost:10000",
42
43
  offlineMode: false,
43
- infrastructure: {
44
- sqs: false,
45
- },
44
+ maintenance: [],
46
45
  })
47
46
  })
48
47
  })
@@ -26,6 +26,7 @@ export const buildSelfSaveValidation = () => {
26
26
  firstName: OPTIONAL_STRING,
27
27
  lastName: OPTIONAL_STRING,
28
28
  onboardedAt: Joi.string().optional(),
29
+ appFavourites: Joi.array().optional(),
29
30
  tours: Joi.object().optional(),
30
31
  }
31
32
  return auth.joiValidator.body(Joi.object(schema).required().unknown(false))