@budibase/worker 1.3.19-alpha.3 → 1.3.19-alpha.4

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.19-alpha.3",
4
+ "version": "1.3.19-alpha.4",
5
5
  "description": "Budibase background service",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -36,10 +36,10 @@
36
36
  "author": "Budibase",
37
37
  "license": "GPL-3.0",
38
38
  "dependencies": {
39
- "@budibase/backend-core": "1.3.19-alpha.3",
40
- "@budibase/pro": "1.3.19-alpha.2",
41
- "@budibase/string-templates": "1.3.19-alpha.3",
42
- "@budibase/types": "1.3.19-alpha.3",
39
+ "@budibase/backend-core": "1.3.19-alpha.4",
40
+ "@budibase/pro": "1.3.19-alpha.3",
41
+ "@budibase/string-templates": "1.3.19-alpha.4",
42
+ "@budibase/types": "1.3.19-alpha.4",
43
43
  "@koa/router": "8.0.8",
44
44
  "@sentry/node": "6.17.7",
45
45
  "@techpass/passport-openidconnect": "0.3.2",
@@ -104,5 +104,5 @@
104
104
  "./scripts/jestSetup.js"
105
105
  ]
106
106
  },
107
- "gitHead": "70ca5eab5924a14ae6558924706bfa970269944a"
107
+ "gitHead": "298b2b17d1d07adf98c7e9d034ae92276b84b3ed"
108
108
  }
@@ -16,6 +16,11 @@ const { newid } = require("@budibase/backend-core/utils")
16
16
  const { users } = require("../../../sdk")
17
17
  const { Cookies } = require("@budibase/backend-core/constants")
18
18
  const { events, featureFlags } = require("@budibase/backend-core")
19
+ const env = require("../../../environment")
20
+
21
+ function newTestApiKey() {
22
+ return env.ENCRYPTED_TEST_PUBLIC_API_KEY
23
+ }
19
24
 
20
25
  function newApiKey() {
21
26
  return encrypt(`${getTenantId()}${SEPARATOR}${newid()}`)
@@ -29,15 +34,25 @@ function cleanupDevInfo(info) {
29
34
  }
30
35
 
31
36
  exports.generateAPIKey = async ctx => {
37
+ let userId
38
+ let apiKey
39
+ if (env.isTest() && ctx.request.body.userId) {
40
+ userId = ctx.request.body.userId
41
+ apiKey = newTestApiKey()
42
+ } else {
43
+ userId = ctx.user._id
44
+ apiKey = newApiKey()
45
+ }
46
+
32
47
  const db = getGlobalDB()
33
- const id = generateDevInfoID(ctx.user._id)
48
+ const id = generateDevInfoID(userId)
34
49
  let devInfo
35
50
  try {
36
51
  devInfo = await db.get(id)
37
52
  } catch (err) {
38
- devInfo = { _id: id, userId: ctx.user._id }
53
+ devInfo = { _id: id, userId }
39
54
  }
40
- devInfo.apiKey = await newApiKey()
55
+ devInfo.apiKey = await apiKey
41
56
  await db.put(devInfo)
42
57
  ctx.body = cleanupDevInfo(devInfo)
43
58
  }
@@ -63,6 +63,7 @@ const env = {
63
63
  // other
64
64
  CHECKLIST_CACHE_TTL: parseIntSafe(process.env.CHECKLIST_CACHE_TTL) || 3600,
65
65
  SESSION_UPDATE_PERIOD: process.env.SESSION_UPDATE_PERIOD,
66
+ ENCRYPTED_TEST_PUBLIC_API_KEY: process.env.ENCRYPTED_TEST_PUBLIC_API_KEY,
66
67
  _set(key: any, value: any) {
67
68
  process.env[key] = value
68
69
  module.exports[key] = value