@budibase/worker 1.3.4-alpha.1 → 1.3.6

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.3.4-alpha.1",
4
+ "version": "1.3.6",
5
5
  "description": "Budibase background service",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -35,10 +35,10 @@
35
35
  "author": "Budibase",
36
36
  "license": "GPL-3.0",
37
37
  "dependencies": {
38
- "@budibase/backend-core": "1.3.4-alpha.1",
39
- "@budibase/pro": "1.3.4-alpha.0",
40
- "@budibase/string-templates": "1.3.4-alpha.1",
41
- "@budibase/types": "1.3.4-alpha.1",
38
+ "@budibase/backend-core": "^1.3.6",
39
+ "@budibase/pro": "1.3.5",
40
+ "@budibase/string-templates": "^1.3.6",
41
+ "@budibase/types": "^1.3.6",
42
42
  "@koa/router": "8.0.8",
43
43
  "@sentry/node": "6.17.7",
44
44
  "@techpass/passport-openidconnect": "0.3.2",
@@ -103,5 +103,5 @@
103
103
  "./scripts/jestSetup.js"
104
104
  ]
105
105
  },
106
- "gitHead": "0c4937b6fadb2473c1f645ea39f9630e2c03ee67"
106
+ "gitHead": "6f9f6b54acf28819286ce19e48823b1cd96cea92"
107
107
  }
@@ -189,23 +189,34 @@ export const save = async (
189
189
  const tenantId = tenancy.getTenantId()
190
190
  const db = tenancy.getGlobalDB()
191
191
  let { email, _id } = user
192
+ if (!email && !_id) {
193
+ throw new Error("_id or email is required")
194
+ }
192
195
 
193
196
  let dbUser: User | undefined
194
197
  if (_id) {
195
198
  // try to get existing user from db
196
- dbUser = (await db.get(_id)) as User
197
- if (email && dbUser.email !== email) {
198
- throw "Email address cannot be changed"
199
+ try {
200
+ dbUser = (await db.get(_id)) as User
201
+ if (email && dbUser.email !== email) {
202
+ throw "Email address cannot be changed"
203
+ }
204
+ email = dbUser.email
205
+ } catch (e: any) {
206
+ if (e.status === 404) {
207
+ // do nothing, save this new user with the id specified - required for SSO auth
208
+ } else {
209
+ throw e
210
+ }
199
211
  }
200
- email = dbUser.email
201
- } else if (email) {
212
+ }
213
+
214
+ if (!dbUser && email) {
202
215
  // no id was specified - load from email instead
203
216
  dbUser = await usersCore.getGlobalUserByEmail(email)
204
217
  if (dbUser && dbUser._id !== _id) {
205
218
  throw `Unavailable`
206
219
  }
207
- } else {
208
- throw new Error("_id or email is required")
209
220
  }
210
221
 
211
222
  await validateUniqueUser(email, tenantId)