@budibase/worker 2.13.37 → 2.13.38

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.13.37",
4
+ "version": "2.13.38",
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.13.37",
41
- "@budibase/pro": "2.13.37",
42
- "@budibase/string-templates": "2.13.37",
43
- "@budibase/types": "2.13.37",
40
+ "@budibase/backend-core": "2.13.38",
41
+ "@budibase/pro": "2.13.38",
42
+ "@budibase/string-templates": "2.13.38",
43
+ "@budibase/types": "2.13.38",
44
44
  "@koa/router": "8.0.8",
45
45
  "@techpass/passport-openidconnect": "0.3.2",
46
46
  "@types/global-agent": "2.1.1",
@@ -107,5 +107,5 @@
107
107
  }
108
108
  }
109
109
  },
110
- "gitHead": "a3ba9269d3867cb9695ed1e718f6cead49c7f6e2"
110
+ "gitHead": "02e573ced8c766dcac96b29af4eeeab1416e22f4"
111
111
  }
@@ -1,44 +1,40 @@
1
1
  #!/usr/bin/env node
2
- const path = require("path")
3
- const fs = require("fs")
2
+ const { parsed: existingConfig } = require("dotenv").config()
3
+ const updateDotEnv = require("update-dotenv")
4
4
 
5
5
  async function init() {
6
- const envFilePath = path.join(process.cwd(), ".env")
7
- if (!fs.existsSync(envFilePath)) {
8
- const envFileJson = {
9
- SELF_HOSTED: 1,
10
- PORT: 4002,
11
- CLUSTER_PORT: 10000,
12
- JWT_SECRET: "testsecret",
13
- INTERNAL_API_KEY: "budibase",
14
- MINIO_ACCESS_KEY: "budibase",
15
- MINIO_SECRET_KEY: "budibase",
16
- REDIS_URL: "localhost:6379",
17
- REDIS_PASSWORD: "budibase",
18
- MINIO_URL: "http://localhost:4004",
19
- COUCH_DB_URL: "http://budibase:budibase@localhost:4005",
20
- COUCH_DB_USERNAME: "budibase",
21
- COUCH_DB_PASSWORD: "budibase",
22
- // empty string is false
23
- MULTI_TENANCY: "",
24
- DISABLE_ACCOUNT_PORTAL: 1,
25
- ACCOUNT_PORTAL_URL: "http://localhost:10001",
26
- ACCOUNT_PORTAL_API_KEY: "budibase",
27
- PLATFORM_URL: "http://localhost:10000",
28
- APPS_URL: "http://localhost:4001",
29
- SERVICE: "worker-service",
30
- DEPLOYMENT_ENVIRONMENT: "development",
31
- TENANT_FEATURE_FLAGS: "*:LICENSING,*:USER_GROUPS,*:ONBOARDING_TOUR",
32
- ENABLE_EMAIL_TEST_MODE: 1,
33
- HTTP_LOGGING: 0,
34
- VERSION: "0.0.0+local",
35
- }
36
- let envFile = ""
37
- Object.keys(envFileJson).forEach(key => {
38
- envFile += `${key}=${envFileJson[key]}\n`
39
- })
40
- fs.writeFileSync(envFilePath, envFile)
6
+ let config = {
7
+ SELF_HOSTED: "1",
8
+ PORT: "4002",
9
+ CLUSTER_PORT: "10000",
10
+ JWT_SECRET: "testsecret",
11
+ INTERNAL_API_KEY: "budibase",
12
+ MINIO_ACCESS_KEY: "budibase",
13
+ MINIO_SECRET_KEY: "budibase",
14
+ REDIS_URL: "localhost:6379",
15
+ REDIS_PASSWORD: "budibase",
16
+ MINIO_URL: "http://localhost:4004",
17
+ COUCH_DB_URL: "http://budibase:budibase@localhost:4005",
18
+ COUCH_DB_USERNAME: "budibase",
19
+ COUCH_DB_PASSWORD: "budibase",
20
+ // empty string is false
21
+ MULTI_TENANCY: "",
22
+ DISABLE_ACCOUNT_PORTAL: "1",
23
+ ACCOUNT_PORTAL_URL: "http://localhost:10001",
24
+ ACCOUNT_PORTAL_API_KEY: "budibase",
25
+ PLATFORM_URL: "http://localhost:10000",
26
+ APPS_URL: "http://localhost:4001",
27
+ SERVICE: "worker-service",
28
+ DEPLOYMENT_ENVIRONMENT: "development",
29
+ TENANT_FEATURE_FLAGS: "*:LICENSING,*:USER_GROUPS,*:ONBOARDING_TOUR",
30
+ ENABLE_EMAIL_TEST_MODE: "1",
31
+ HTTP_LOGGING: "0",
32
+ VERSION: "0.0.0+local",
41
33
  }
34
+
35
+ config = { ...config, ...existingConfig }
36
+
37
+ await updateDotEnv(config)
42
38
  }
43
39
 
44
40
  // if more than init required use this to determine the command type
@@ -1,6 +1,25 @@
1
1
  import { Ctx } from "@budibase/types"
2
2
  import env from "../../../environment"
3
3
  import { env as coreEnv } from "@budibase/backend-core"
4
+ import nodeFetch from "node-fetch"
5
+
6
+ let sqsAvailable: boolean
7
+ async function isSqsAvailable() {
8
+ if (sqsAvailable !== undefined) {
9
+ return sqsAvailable
10
+ }
11
+
12
+ try {
13
+ await nodeFetch(coreEnv.COUCH_DB_SQL_URL, {
14
+ timeout: 1000,
15
+ })
16
+ sqsAvailable = true
17
+ return true
18
+ } catch (e) {
19
+ sqsAvailable = false
20
+ return false
21
+ }
22
+ }
4
23
 
5
24
  export const fetch = async (ctx: Ctx) => {
6
25
  ctx.body = {
@@ -12,4 +31,10 @@ export const fetch = async (ctx: Ctx) => {
12
31
  baseUrl: env.PLATFORM_URL,
13
32
  isDev: env.isDev() && !env.isTest(),
14
33
  }
34
+
35
+ if (env.SELF_HOSTED) {
36
+ ctx.body.infrastructure = {
37
+ sqs: await isSqsAvailable(),
38
+ }
39
+ }
15
40
  }
@@ -1,5 +1,7 @@
1
1
  import { TestConfiguration } from "../../../../tests"
2
2
 
3
+ jest.unmock("node-fetch")
4
+
3
5
  describe("/api/system/environment", () => {
4
6
  const config = new TestConfiguration()
5
7
 
@@ -27,5 +29,22 @@ describe("/api/system/environment", () => {
27
29
  offlineMode: false,
28
30
  })
29
31
  })
32
+
33
+ it("returns the expected environment for self hosters", async () => {
34
+ await config.withEnv({ SELF_HOSTED: true }, async () => {
35
+ const env = await config.api.environment.getEnvironment()
36
+ expect(env.body).toEqual({
37
+ cloud: false,
38
+ disableAccountPortal: 0,
39
+ isDev: false,
40
+ multiTenancy: true,
41
+ baseUrl: "http://localhost:10000",
42
+ offlineMode: false,
43
+ infrastructure: {
44
+ sqs: false,
45
+ },
46
+ })
47
+ })
48
+ })
30
49
  })
31
50
  })
@@ -36,6 +36,7 @@ import {
36
36
  } from "@budibase/types"
37
37
  import API from "./api"
38
38
  import jwt, { Secret } from "jsonwebtoken"
39
+ import cloneDeep from "lodash/fp/cloneDeep"
39
40
 
40
41
  class TestConfiguration {
41
42
  server: any
@@ -240,6 +241,34 @@ class TestConfiguration {
240
241
  return { message: "Admin user only endpoint.", status: 403 }
241
242
  }
242
243
 
244
+ async withEnv(newEnvVars: Partial<typeof env>, f: () => Promise<void>) {
245
+ let cleanup = this.setEnv(newEnvVars)
246
+ try {
247
+ await f()
248
+ } finally {
249
+ cleanup()
250
+ }
251
+ }
252
+
253
+ /*
254
+ * Sets the environment variables to the given values and returns a function
255
+ * that can be called to reset the environment variables to their original values.
256
+ */
257
+ setEnv(newEnvVars: Partial<typeof env>): () => void {
258
+ const oldEnv = cloneDeep(env)
259
+
260
+ let key: keyof typeof newEnvVars
261
+ for (key in newEnvVars) {
262
+ env._set(key, newEnvVars[key])
263
+ }
264
+
265
+ return () => {
266
+ for (const [key, value] of Object.entries(oldEnv)) {
267
+ env._set(key, value)
268
+ }
269
+ }
270
+ }
271
+
243
272
  // USERS
244
273
 
245
274
  async createDefaultUser() {