@budibase/worker 1.0.171 → 1.0.173
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/Dockerfile +3 -1
- package/docker_run.sh +5 -0
- package/package.json +6 -5
- package/pm2.js +9 -0
- package/src/api/controllers/global/configs.js +8 -5
- package/src/api/controllers/global/users.ts +13 -5
- package/src/environment.js +7 -0
- package/src/utilities/redis.js +2 -26
package/Dockerfile
CHANGED
|
@@ -10,6 +10,7 @@ WORKDIR /app
|
|
|
10
10
|
# copy files and install dependencies
|
|
11
11
|
COPY . ./
|
|
12
12
|
RUN yarn
|
|
13
|
+
RUN yarn global add pm2
|
|
13
14
|
|
|
14
15
|
EXPOSE 4001
|
|
15
16
|
|
|
@@ -17,4 +18,5 @@ EXPOSE 4001
|
|
|
17
18
|
# due to this causing yarn to stop installing dev dependencies
|
|
18
19
|
# which are actually needed to get this environment up and running
|
|
19
20
|
ENV NODE_ENV=production
|
|
20
|
-
|
|
21
|
+
ENV CLUSTER_MODE=${CLUSTER_MODE}
|
|
22
|
+
CMD ["./docker_run.sh"]
|
package/docker_run.sh
ADDED
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.
|
|
4
|
+
"version": "1.0.173",
|
|
5
5
|
"description": "Budibase background service",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"repository": {
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"build": "rimraf dist/ && tsc",
|
|
16
16
|
"postbuild": "copyfiles -u 1 src/**/*.hbs dist/",
|
|
17
17
|
"run:docker": "node dist/index.js",
|
|
18
|
+
"run:docker:cluster": "pm2-runtime start pm2.js",
|
|
18
19
|
"build:docker": "docker build . -t worker-service --label version=$BUDIBASE_RELEASE_VERSION",
|
|
19
20
|
"dev:stack:init": "node ./scripts/dev/manage.js init",
|
|
20
21
|
"dev:builder": "npm run dev:stack:init && nodemon",
|
|
@@ -31,9 +32,9 @@
|
|
|
31
32
|
"author": "Budibase",
|
|
32
33
|
"license": "GPL-3.0",
|
|
33
34
|
"dependencies": {
|
|
34
|
-
"@budibase/backend-core": "^1.0.
|
|
35
|
-
"@budibase/pro": "1.0.
|
|
36
|
-
"@budibase/string-templates": "^1.0.
|
|
35
|
+
"@budibase/backend-core": "^1.0.173",
|
|
36
|
+
"@budibase/pro": "1.0.172",
|
|
37
|
+
"@budibase/string-templates": "^1.0.173",
|
|
37
38
|
"@koa/router": "^8.0.0",
|
|
38
39
|
"@sentry/node": "6.17.7",
|
|
39
40
|
"@techpass/passport-openidconnect": "^0.3.0",
|
|
@@ -89,5 +90,5 @@
|
|
|
89
90
|
"./scripts/jestSetup.js"
|
|
90
91
|
]
|
|
91
92
|
},
|
|
92
|
-
"gitHead": "
|
|
93
|
+
"gitHead": "b408b4079f35eb1eb8a388c4b27acf8f77b2815e"
|
|
93
94
|
}
|
package/pm2.js
ADDED
|
@@ -14,7 +14,11 @@ 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 {
|
|
17
|
+
const {
|
|
18
|
+
withCache,
|
|
19
|
+
CacheKeys,
|
|
20
|
+
bustCache,
|
|
21
|
+
} = require("@budibase/backend-core/cache")
|
|
18
22
|
|
|
19
23
|
const BB_TENANT_CDN = "https://tenants.cdn.budi.live"
|
|
20
24
|
|
|
@@ -44,6 +48,7 @@ exports.save = async function (ctx) {
|
|
|
44
48
|
|
|
45
49
|
try {
|
|
46
50
|
const response = await db.put(ctx.request.body)
|
|
51
|
+
await bustCache(CacheKeys.CHECKLIST)
|
|
47
52
|
ctx.body = {
|
|
48
53
|
type,
|
|
49
54
|
_id: response.id,
|
|
@@ -250,11 +255,9 @@ exports.configChecklist = async function (ctx) {
|
|
|
250
255
|
const tenantId = getTenantId()
|
|
251
256
|
|
|
252
257
|
try {
|
|
253
|
-
const ONE_MINUTE = 600
|
|
254
|
-
|
|
255
258
|
ctx.body = await withCache(
|
|
256
|
-
|
|
257
|
-
|
|
259
|
+
CacheKeys.CHECKLIST,
|
|
260
|
+
env.CHECKLIST_CACHE_TTL,
|
|
258
261
|
async () => {
|
|
259
262
|
let apps = []
|
|
260
263
|
if (!env.MULTI_TENANCY || tenantId) {
|
|
@@ -3,9 +3,6 @@ const {
|
|
|
3
3
|
StaticDatabases,
|
|
4
4
|
} = require("@budibase/backend-core/db")
|
|
5
5
|
const { getGlobalUserByEmail } = require("@budibase/backend-core/utils")
|
|
6
|
-
import { EmailTemplatePurpose } from "../../../constants"
|
|
7
|
-
import { checkInviteCode } from "../../../utilities/redis"
|
|
8
|
-
import { sendEmail } from "../../../utilities/email"
|
|
9
6
|
const { user: userCache } = require("@budibase/backend-core/cache")
|
|
10
7
|
const { invalidateSessions } = require("@budibase/backend-core/sessions")
|
|
11
8
|
const accounts = require("@budibase/backend-core/accounts")
|
|
@@ -17,11 +14,15 @@ const {
|
|
|
17
14
|
doesTenantExist,
|
|
18
15
|
} = require("@budibase/backend-core/tenancy")
|
|
19
16
|
const { removeUserFromInfoDB } = require("@budibase/backend-core/deprovision")
|
|
17
|
+
const { errors } = require("@budibase/backend-core")
|
|
18
|
+
const { CacheKeys, bustCache } = require("@budibase/backend-core/cache")
|
|
20
19
|
import env from "../../../environment"
|
|
21
20
|
import { syncUserInApps } from "../../../utilities/appService"
|
|
22
21
|
import { quotas, users } from "@budibase/pro"
|
|
23
|
-
const { errors } = require("@budibase/backend-core")
|
|
24
22
|
import { allUsers, getUser } from "../../utilities"
|
|
23
|
+
import { EmailTemplatePurpose } from "../../../constants"
|
|
24
|
+
import { checkInviteCode } from "../../../utilities/redis"
|
|
25
|
+
import { sendEmail } from "../../../utilities/email"
|
|
25
26
|
|
|
26
27
|
export const save = async (ctx: any) => {
|
|
27
28
|
try {
|
|
@@ -93,7 +94,14 @@ export const adminUser = async (ctx: any) => {
|
|
|
93
94
|
tenantId,
|
|
94
95
|
}
|
|
95
96
|
try {
|
|
96
|
-
|
|
97
|
+
const finalUser = await users.save(
|
|
98
|
+
user,
|
|
99
|
+
tenantId,
|
|
100
|
+
hashPassword,
|
|
101
|
+
requirePassword
|
|
102
|
+
)
|
|
103
|
+
await bustCache(CacheKeys.CHECKLIST)
|
|
104
|
+
ctx.body = finalUser
|
|
97
105
|
} catch (err: any) {
|
|
98
106
|
ctx.throw(err.status || 400, err)
|
|
99
107
|
}
|
package/src/environment.js
CHANGED
|
@@ -20,6 +20,12 @@ if (!LOADED && isDev() && !isTest()) {
|
|
|
20
20
|
LOADED = true
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
function parseIntSafe(number) {
|
|
24
|
+
if (number) {
|
|
25
|
+
return parseInt(number)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
23
29
|
module.exports = {
|
|
24
30
|
NODE_ENV: process.env.NODE_ENV,
|
|
25
31
|
SELF_HOSTED: !!parseInt(process.env.SELF_HOSTED),
|
|
@@ -46,6 +52,7 @@ module.exports = {
|
|
|
46
52
|
SMTP_FROM_ADDRESS: process.env.SMTP_FROM_ADDRESS,
|
|
47
53
|
PLATFORM_URL: process.env.PLATFORM_URL,
|
|
48
54
|
COOKIE_DOMAIN: process.env.COOKIE_DOMAIN,
|
|
55
|
+
CHECKLIST_CACHE_TTL: parseIntSafe(process.env.CHECKLIST_CACHE_TTL) || 3600,
|
|
49
56
|
APPS_URL: process.env.APPS_URL,
|
|
50
57
|
_set(key, value) {
|
|
51
58
|
process.env[key] = value
|
package/src/utilities/redis.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const { Client, utils } = require("@budibase/backend-core/redis")
|
|
2
2
|
const { newid } = require("@budibase/backend-core/utils")
|
|
3
|
-
const env = require("../environment")
|
|
4
3
|
|
|
5
4
|
function getExpirySecondsForDB(db) {
|
|
6
5
|
switch (db) {
|
|
@@ -13,7 +12,7 @@ function getExpirySecondsForDB(db) {
|
|
|
13
12
|
}
|
|
14
13
|
}
|
|
15
14
|
|
|
16
|
-
let pwResetClient, invitationClient
|
|
15
|
+
let pwResetClient, invitationClient
|
|
17
16
|
|
|
18
17
|
function getClient(db) {
|
|
19
18
|
switch (db) {
|
|
@@ -21,8 +20,6 @@ function getClient(db) {
|
|
|
21
20
|
return pwResetClient
|
|
22
21
|
case utils.Databases.INVITATIONS:
|
|
23
22
|
return invitationClient
|
|
24
|
-
case utils.Databases.DATA_CACHE:
|
|
25
|
-
return cachingClient
|
|
26
23
|
}
|
|
27
24
|
}
|
|
28
25
|
|
|
@@ -48,10 +45,8 @@ async function getACode(db, code, deleteCode = true) {
|
|
|
48
45
|
exports.init = async () => {
|
|
49
46
|
pwResetClient = new Client(utils.Databases.PW_RESETS)
|
|
50
47
|
invitationClient = new Client(utils.Databases.INVITATIONS)
|
|
51
|
-
cachingClient = new Client(utils.Databases.DATA_CACHE)
|
|
52
48
|
await pwResetClient.init()
|
|
53
49
|
await invitationClient.init()
|
|
54
|
-
await cachingClient.init()
|
|
55
50
|
}
|
|
56
51
|
|
|
57
52
|
/**
|
|
@@ -66,6 +61,7 @@ exports.shutdown = async () => {
|
|
|
66
61
|
* Given a user ID this will store a code (that is returned) for an hour in redis.
|
|
67
62
|
* The user can then return this code for resetting their password (through their reset link).
|
|
68
63
|
* @param {string} userId the ID of the user which is to be reset.
|
|
64
|
+
* @param {object} info Info about the user/the reset process.
|
|
69
65
|
* @return {Promise<string>} returns the code that was stored to redis.
|
|
70
66
|
*/
|
|
71
67
|
exports.getResetPasswordCode = async (userId, info) => {
|
|
@@ -109,23 +105,3 @@ exports.checkInviteCode = async (inviteCode, deleteCode = true) => {
|
|
|
109
105
|
throw "Invitation is not valid or has expired, please request a new one."
|
|
110
106
|
}
|
|
111
107
|
}
|
|
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
|
-
}
|