@budibase/worker 2.2.26 → 2.2.27

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.
Files changed (166) hide show
  1. package/Dockerfile +1 -1
  2. package/coverage/clover.xml +1393 -1364
  3. package/coverage/coverage-final.json +83 -77
  4. package/coverage/lcov-report/index.html +133 -133
  5. package/coverage/lcov-report/src/api/controllers/global/auth.ts.html +52 -52
  6. package/coverage/lcov-report/src/api/controllers/global/configs.ts.html +161 -218
  7. package/coverage/lcov-report/src/api/controllers/global/email.ts.html +4 -4
  8. package/coverage/lcov-report/src/api/controllers/global/events.ts.html +136 -0
  9. package/coverage/lcov-report/src/api/controllers/global/index.html +85 -70
  10. package/coverage/lcov-report/src/api/controllers/global/license.ts.html +16 -16
  11. package/coverage/lcov-report/src/api/controllers/global/roles.ts.html +77 -77
  12. package/coverage/lcov-report/src/api/controllers/global/self.ts.html +20 -20
  13. package/coverage/lcov-report/src/api/controllers/global/templates.ts.html +54 -54
  14. package/coverage/lcov-report/src/api/controllers/global/users.ts.html +82 -43
  15. package/coverage/lcov-report/src/api/controllers/global/workspaces.ts.html +9 -9
  16. package/coverage/lcov-report/src/api/controllers/system/accounts.ts.html +5 -5
  17. package/coverage/lcov-report/src/api/controllers/system/environment.ts.html +4 -4
  18. package/coverage/lcov-report/src/api/controllers/system/index.html +11 -11
  19. package/coverage/lcov-report/src/api/controllers/system/migrations.ts.html +5 -5
  20. package/coverage/lcov-report/src/api/controllers/system/restore.ts.html +4 -4
  21. package/coverage/lcov-report/src/api/controllers/system/status.ts.html +5 -5
  22. package/coverage/lcov-report/src/api/controllers/system/tenants.ts.html +7 -7
  23. package/coverage/lcov-report/src/api/index.html +1 -1
  24. package/coverage/lcov-report/src/api/index.ts.html +37 -25
  25. package/coverage/lcov-report/src/api/routes/global/auth.ts.html +14 -14
  26. package/coverage/lcov-report/src/api/routes/global/configs.ts.html +25 -25
  27. package/coverage/lcov-report/src/api/routes/global/email.ts.html +13 -13
  28. package/coverage/lcov-report/src/api/routes/global/events.ts.html +109 -0
  29. package/coverage/lcov-report/src/api/routes/global/index.html +37 -22
  30. package/coverage/lcov-report/src/api/routes/global/license.ts.html +9 -9
  31. package/coverage/lcov-report/src/api/routes/global/roles.ts.html +10 -10
  32. package/coverage/lcov-report/src/api/routes/global/self.ts.html +11 -11
  33. package/coverage/lcov-report/src/api/routes/global/templates.ts.html +14 -14
  34. package/coverage/lcov-report/src/api/routes/global/users.ts.html +62 -20
  35. package/coverage/lcov-report/src/api/routes/global/workspaces.ts.html +12 -12
  36. package/coverage/lcov-report/src/api/routes/index.html +7 -7
  37. package/coverage/lcov-report/src/api/routes/index.ts.html +29 -23
  38. package/coverage/lcov-report/src/api/routes/system/accounts.ts.html +10 -10
  39. package/coverage/lcov-report/src/api/routes/system/environment.ts.html +9 -9
  40. package/coverage/lcov-report/src/api/routes/system/index.html +15 -15
  41. package/coverage/lcov-report/src/api/routes/system/migrations.ts.html +10 -10
  42. package/coverage/lcov-report/src/api/routes/system/restore.ts.html +9 -9
  43. package/coverage/lcov-report/src/api/routes/system/status.ts.html +9 -9
  44. package/coverage/lcov-report/src/api/routes/system/tenants.ts.html +10 -10
  45. package/coverage/lcov-report/src/api/routes/validation/index.html +3 -3
  46. package/coverage/lcov-report/src/api/routes/validation/index.ts.html +2 -2
  47. package/coverage/lcov-report/src/api/routes/validation/users.ts.html +14 -14
  48. package/coverage/lcov-report/src/constants/index.html +17 -17
  49. package/coverage/lcov-report/src/constants/index.ts.html +77 -53
  50. package/coverage/lcov-report/src/constants/templates/index.html +19 -19
  51. package/coverage/lcov-report/src/constants/templates/index.ts.html +42 -42
  52. package/coverage/lcov-report/src/db/index.html +3 -3
  53. package/coverage/lcov-report/src/db/index.ts.html +10 -10
  54. package/coverage/lcov-report/src/environment.ts.html +44 -29
  55. package/coverage/lcov-report/src/index.html +27 -27
  56. package/coverage/lcov-report/src/index.ts.html +55 -55
  57. package/coverage/lcov-report/src/middleware/cloudRestricted.ts.html +5 -5
  58. package/coverage/lcov-report/src/middleware/index.html +1 -1
  59. package/coverage/lcov-report/src/migrations/functions/globalInfoSyncUsers.ts.html +9 -9
  60. package/coverage/lcov-report/src/migrations/functions/index.html +11 -11
  61. package/coverage/lcov-report/src/migrations/index.html +15 -15
  62. package/coverage/lcov-report/src/migrations/index.ts.html +27 -27
  63. package/coverage/lcov-report/src/sdk/accounts/accounts.ts.html +13 -13
  64. package/coverage/lcov-report/src/sdk/accounts/index.html +13 -13
  65. package/coverage/lcov-report/src/sdk/accounts/index.ts.html +2 -2
  66. package/coverage/lcov-report/src/sdk/index.html +5 -5
  67. package/coverage/lcov-report/src/sdk/index.ts.html +6 -6
  68. package/coverage/lcov-report/src/sdk/users/events.ts.html +82 -58
  69. package/coverage/lcov-report/src/sdk/users/index.html +29 -29
  70. package/coverage/lcov-report/src/sdk/users/index.ts.html +2 -2
  71. package/coverage/lcov-report/src/sdk/users/users.ts.html +176 -119
  72. package/coverage/lcov-report/src/tests/TestConfiguration.ts.html +119 -95
  73. package/coverage/lcov-report/src/tests/api/accounts.ts.html +7 -7
  74. package/coverage/lcov-report/src/tests/api/auth.ts.html +8 -8
  75. package/coverage/lcov-report/src/tests/api/base.ts.html +5 -5
  76. package/coverage/lcov-report/src/tests/api/configs.ts.html +9 -9
  77. package/coverage/lcov-report/src/tests/api/email.ts.html +6 -6
  78. package/coverage/lcov-report/src/tests/api/environment.ts.html +6 -6
  79. package/coverage/lcov-report/src/tests/api/groups.ts.html +163 -0
  80. package/coverage/lcov-report/src/tests/api/index.html +91 -31
  81. package/coverage/lcov-report/src/tests/api/index.ts.html +62 -29
  82. package/coverage/lcov-report/src/tests/api/license.ts.html +136 -0
  83. package/coverage/lcov-report/src/tests/api/migrations.ts.html +8 -8
  84. package/coverage/lcov-report/src/tests/api/restore.ts.html +7 -7
  85. package/coverage/lcov-report/src/tests/api/roles.ts.html +181 -0
  86. package/coverage/lcov-report/src/tests/api/self.ts.html +7 -7
  87. package/coverage/lcov-report/src/tests/api/status.ts.html +6 -6
  88. package/coverage/lcov-report/src/tests/api/templates.ts.html +175 -0
  89. package/coverage/lcov-report/src/tests/api/tenants.ts.html +10 -10
  90. package/coverage/lcov-report/src/tests/api/users.ts.html +28 -25
  91. package/coverage/lcov-report/src/tests/controllers.ts.html +14 -14
  92. package/coverage/lcov-report/src/tests/index.html +34 -34
  93. package/coverage/lcov-report/src/tests/index.ts.html +19 -55
  94. package/coverage/lcov-report/src/tests/mocks/{email.js.html → email.ts.html} +5 -5
  95. package/coverage/lcov-report/src/tests/mocks/index.html +6 -6
  96. package/coverage/lcov-report/src/tests/mocks/index.ts.html +10 -10
  97. package/coverage/lcov-report/src/tests/structures/configs.ts.html +11 -11
  98. package/coverage/lcov-report/src/tests/structures/groups.ts.html +15 -15
  99. package/coverage/lcov-report/src/tests/structures/index.html +25 -25
  100. package/coverage/lcov-report/src/tests/structures/index.ts.html +17 -17
  101. package/coverage/lcov-report/src/tests/structures/users.ts.html +16 -16
  102. package/coverage/lcov-report/src/utilities/appService.ts.html +45 -18
  103. package/coverage/lcov-report/src/utilities/email.ts.html +28 -28
  104. package/coverage/lcov-report/src/utilities/fileSystem.ts.html +4 -4
  105. package/coverage/lcov-report/src/utilities/index.html +27 -27
  106. package/coverage/lcov-report/src/utilities/index.ts.html +2 -2
  107. package/coverage/lcov-report/src/utilities/redis.ts.html +20 -20
  108. package/coverage/lcov-report/src/utilities/templates.ts.html +6 -6
  109. package/coverage/lcov-report/src/utilities/users.ts.html +3 -3
  110. package/coverage/lcov.info +2777 -2582
  111. package/jest.config.ts +7 -2
  112. package/package.json +10 -7
  113. package/scripts/dev/manage.js +2 -2
  114. package/src/api/controllers/global/auth.ts +1 -1
  115. package/src/api/controllers/global/configs.ts +112 -131
  116. package/src/api/controllers/global/events.ts +17 -0
  117. package/src/api/controllers/global/users.ts +14 -1
  118. package/src/api/index.ts +4 -0
  119. package/src/api/routes/global/auth.ts +1 -1
  120. package/src/api/routes/global/configs.ts +7 -7
  121. package/src/api/routes/global/email.ts +1 -1
  122. package/src/api/routes/global/events.ts +8 -0
  123. package/src/api/routes/global/license.ts +1 -1
  124. package/src/api/routes/global/roles.ts +1 -1
  125. package/src/api/routes/global/self.ts +1 -1
  126. package/src/api/routes/global/templates.ts +1 -1
  127. package/src/api/routes/global/tests/groups.spec.ts +58 -0
  128. package/src/api/routes/global/tests/license.spec.ts +0 -2
  129. package/src/api/routes/global/tests/roles.spec.ts +66 -5
  130. package/src/api/routes/global/tests/templates.spec.ts +81 -9
  131. package/src/api/routes/global/tests/users.spec.ts +2 -2
  132. package/src/api/routes/global/users.ts +15 -1
  133. package/src/api/routes/global/workspaces.ts +1 -1
  134. package/src/api/routes/index.ts +2 -0
  135. package/src/api/routes/system/accounts.ts +1 -1
  136. package/src/api/routes/system/environment.ts +1 -1
  137. package/src/api/routes/system/migrations.ts +1 -1
  138. package/src/api/routes/system/restore.ts +1 -1
  139. package/src/api/routes/system/status.ts +1 -1
  140. package/src/api/routes/system/tenants.ts +1 -1
  141. package/src/api/routes/system/tests/environment.spec.ts +1 -1
  142. package/src/constants/index.ts +13 -5
  143. package/src/db/index.ts +1 -1
  144. package/src/environment.ts +6 -1
  145. package/src/index.ts +5 -5
  146. package/src/middleware/cloudRestricted.ts +1 -1
  147. package/src/sdk/users/events.ts +8 -0
  148. package/src/sdk/users/users.ts +23 -4
  149. package/src/tests/TestConfiguration.ts +11 -3
  150. package/src/tests/api/groups.ts +26 -0
  151. package/src/tests/api/index.ts +12 -1
  152. package/src/tests/api/license.ts +17 -0
  153. package/src/tests/api/roles.ts +32 -0
  154. package/src/tests/api/templates.ts +30 -0
  155. package/src/tests/api/users.ts +2 -1
  156. package/src/tests/index.ts +6 -18
  157. package/src/tests/jestEnv.ts +11 -0
  158. package/src/tests/jestSetup.ts +3 -15
  159. package/src/tests/mocks/{email.js → email.ts} +1 -1
  160. package/src/tests/mocks/index.ts +4 -4
  161. package/src/tests/structures/configs.ts +2 -2
  162. package/src/tests/structures/groups.ts +1 -1
  163. package/src/tests/structures/index.ts +4 -4
  164. package/src/tests/structures/users.ts +1 -1
  165. package/src/utilities/appService.ts +12 -3
  166. package/tsconfig.json +2 -2
@@ -0,0 +1,32 @@
1
+ import TestConfiguration from "../TestConfiguration"
2
+ import { TestAPI, TestAPIOpts } from "./base"
3
+
4
+ export class RolesAPI extends TestAPI {
5
+ constructor(config: TestConfiguration) {
6
+ super(config)
7
+ }
8
+
9
+ get = (opts?: TestAPIOpts) => {
10
+ return this.request
11
+ .get(`/api/global/roles`)
12
+ .set(this.config.defaultHeaders())
13
+ .expect("Content-Type", /json/)
14
+ .expect(opts?.status ? opts.status : 200)
15
+ }
16
+
17
+ find = (appId: string, opts?: TestAPIOpts) => {
18
+ return this.request
19
+ .get(`/api/global/roles/${appId}`)
20
+ .set(this.config.defaultHeaders())
21
+ .expect("Content-Type", /json/)
22
+ .expect(opts?.status ? opts.status : 200)
23
+ }
24
+
25
+ remove = (appId: string, opts?: TestAPIOpts) => {
26
+ return this.request
27
+ .delete(`/api/global/roles/${appId}`)
28
+ .set(this.config.defaultHeaders())
29
+ .expect("Content-Type", /json/)
30
+ .expect(opts?.status ? opts.status : 200)
31
+ }
32
+ }
@@ -0,0 +1,30 @@
1
+ import TestConfiguration from "../TestConfiguration"
2
+ import { TestAPI, TestAPIOpts } from "./base"
3
+
4
+ export class TemplatesAPI extends TestAPI {
5
+ constructor(config: TestConfiguration) {
6
+ super(config)
7
+ }
8
+
9
+ definitions = (opts?: TestAPIOpts) => {
10
+ return this.request
11
+ .get(`/api/global/template/definitions`)
12
+ .set(opts?.headers ? opts.headers : this.config.defaultHeaders())
13
+ .expect(opts?.status ? opts.status : 200)
14
+ }
15
+
16
+ getTemplate = (opts?: TestAPIOpts) => {
17
+ return this.request
18
+ .get(`/api/global/template`)
19
+ .set(opts?.headers ? opts.headers : this.config.defaultHeaders())
20
+ .expect(opts?.status ? opts.status : 200)
21
+ }
22
+
23
+ saveTemplate = (data: any, opts?: TestAPIOpts) => {
24
+ return this.request
25
+ .post(`/api/global/template`)
26
+ .send(data)
27
+ .set(opts?.headers ? opts.headers : this.config.defaultHeaders())
28
+ .expect(opts?.status ? opts.status : 200)
29
+ }
30
+ }
@@ -5,7 +5,7 @@ import {
5
5
  User,
6
6
  CreateAdminUserRequest,
7
7
  } from "@budibase/types"
8
- import * as structures from "../structures"
8
+ import structures from "../structures"
9
9
  import { generator } from "@budibase/backend-core/tests"
10
10
  import TestConfiguration from "../TestConfiguration"
11
11
  import { TestAPI, TestAPIOpts } from "./base"
@@ -48,6 +48,7 @@ export class UserAPI extends TestAPI {
48
48
  .send({
49
49
  password: "newpassword",
50
50
  inviteCode: code,
51
+ firstName: "Ted",
51
52
  })
52
53
  .expect("Content-Type", /json/)
53
54
  .expect(200)
@@ -1,18 +1,6 @@
1
- import mocks from "./mocks"
2
- import { generator } from "@budibase/backend-core/tests"
3
- import TestConfiguration from "./TestConfiguration"
4
- import structures from "./structures"
5
- import API from "./api"
6
- import { v4 as uuid } from "uuid"
7
-
8
- const pkg = {
9
- structures,
10
- generator,
11
- uuid,
12
- TENANT_1: structures.TENANT_1,
13
- mocks,
14
- TestConfiguration,
15
- API,
16
- }
17
-
18
- export = pkg
1
+ export { default as mocks } from "./mocks"
2
+ export { generator } from "@budibase/backend-core/tests"
3
+ export { default as TestConfiguration } from "./TestConfiguration"
4
+ export { default as structures } from "./structures"
5
+ export { default as API } from "./api"
6
+ export { v4 as uuid } from "uuid"
@@ -0,0 +1,11 @@
1
+ process.env.SELF_HOSTED = "0"
2
+ process.env.NODE_ENV = "jest"
3
+ process.env.JWT_SECRET = "test-jwtsecret"
4
+ process.env.LOG_LEVEL = "silent"
5
+ process.env.MULTI_TENANCY = "1"
6
+ process.env.MINIO_URL = "http://localhost"
7
+ process.env.MINIO_ACCESS_KEY = "test"
8
+ process.env.MINIO_SECRET_KEY = "test"
9
+ process.env.PLATFORM_URL = "http://localhost:10000"
10
+ process.env.INTERNAL_API_KEY = "tet"
11
+ process.env.DISABLE_ACCOUNT_PORTAL = "0"
@@ -1,17 +1,3 @@
1
- import env from "../environment"
2
-
3
- env._set("SELF_HOSTED", "0")
4
- env._set("NODE_ENV", "jest")
5
- env._set("JWT_SECRET", "test-jwtsecret")
6
- env._set("LOG_LEVEL", "silent")
7
- env._set("MULTI_TENANCY", true)
8
- env._set("MINIO_URL", "http://localhost")
9
- env._set("MINIO_ACCESS_KEY", "test")
10
- env._set("MINIO_SECRET_KEY", "test")
11
- env._set("PLATFORM_URL", "http://localhost:10000")
12
- env._set("INTERNAL_API_KEY", "test")
13
- env._set("DISABLE_ACCOUNT_PORTAL", false)
14
-
15
1
  import { mocks } from "@budibase/backend-core/tests"
16
2
 
17
3
  // must explicitly enable fetch mock
@@ -22,7 +8,9 @@ mocks.fetch.enable()
22
8
  const tk = require("timekeeper")
23
9
  tk.freeze(mocks.date.MOCK_DATE)
24
10
 
25
- global.console.log = jest.fn() // console.log are ignored in tests
11
+ if (!process.env.DEBUG) {
12
+ global.console.log = jest.fn() // console.log are ignored in tests
13
+ }
26
14
 
27
15
  if (!process.env.CI) {
28
16
  // set a longer timeout in dev for debugging
@@ -1,4 +1,4 @@
1
- exports.mock = () => {
1
+ export function mock() {
2
2
  // mock the email system
3
3
  const sendMailMock = jest.fn()
4
4
  const nodemailer = require("nodemailer")
@@ -1,7 +1,7 @@
1
- const email = require("./email")
2
- import { mocks as coreMocks } from "@budibase/backend-core/tests"
1
+ import * as email from "./email"
2
+ import { mocks } from "@budibase/backend-core/tests"
3
3
 
4
- export = {
4
+ export default {
5
5
  email,
6
- ...coreMocks,
6
+ ...mocks,
7
7
  }
@@ -1,5 +1,5 @@
1
- const { Config } = require("../../constants")
2
- const { utils } = require("@budibase/backend-core")
1
+ import { Config } from "../../constants"
2
+ import { utils } from "@budibase/backend-core"
3
3
 
4
4
  export function oidc(conf?: any) {
5
5
  return {
@@ -4,7 +4,7 @@ export const UserGroup = () => {
4
4
  color: "var(--spectrum-global-color-blue-600)",
5
5
  icon: "UserGroup",
6
6
  name: "New group",
7
- roles: {},
7
+ roles: { app_uuid1: "ADMIN", app_uuid2: "POWER" },
8
8
  users: [],
9
9
  }
10
10
  return group
@@ -4,9 +4,9 @@ import * as users from "./users"
4
4
  import * as groups from "./groups"
5
5
  import { v4 as uuid } from "uuid"
6
6
 
7
- const TENANT_ID = "default"
8
- const TENANT_1 = "tenant1"
9
- const CSRF_TOKEN = "e3727778-7af0-4226-b5eb-f43cbe60a306"
7
+ export const TENANT_ID = "default"
8
+ export const TENANT_1 = "tenant1"
9
+ export const CSRF_TOKEN = "e3727778-7af0-4226-b5eb-f43cbe60a306"
10
10
 
11
11
  const pkg = {
12
12
  ...structures,
@@ -19,4 +19,4 @@ const pkg = {
19
19
  groups,
20
20
  }
21
21
 
22
- export = pkg
22
+ export default pkg
@@ -10,7 +10,7 @@ export const user = (userProps?: any): User => {
10
10
  return {
11
11
  email: newEmail(),
12
12
  password: "test",
13
- roles: {},
13
+ roles: { app_test: "admin" },
14
14
  ...userProps,
15
15
  }
16
16
  }
@@ -1,7 +1,8 @@
1
1
  import fetch from "node-fetch"
2
- import { constants, tenancy } from "@budibase/backend-core"
2
+ import { constants, tenancy, logging } from "@budibase/backend-core"
3
3
  import { checkSlashesInUrl } from "../utilities"
4
4
  import env from "../environment"
5
+ import { SyncUserRequest, User } from "@budibase/types"
5
6
 
6
7
  async function makeAppRequest(url: string, method: string, body: any) {
7
8
  if (env.isTest()) {
@@ -17,14 +18,22 @@ async function makeAppRequest(url: string, method: string, body: any) {
17
18
  request.body = JSON.stringify(body)
18
19
  }
19
20
  request.method = method
21
+
22
+ // add x-budibase-correlation-id header
23
+ logging.correlation.setHeader(request.headers)
24
+
20
25
  return fetch(checkSlashesInUrl(env.APPS_URL + url), request)
21
26
  }
22
27
 
23
- export async function syncUserInApps(userId: string) {
28
+ export async function syncUserInApps(userId: string, previousUser?: User) {
29
+ const body: SyncUserRequest = {
30
+ previousUser,
31
+ }
32
+
24
33
  const response = await makeAppRequest(
25
34
  `/api/users/metadata/sync/${userId}`,
26
35
  "POST",
27
- {}
36
+ body
28
37
  )
29
38
  if (response && response.status !== 200) {
30
39
  throw "Unable to sync user."
package/tsconfig.json CHANGED
@@ -13,7 +13,8 @@
13
13
  }
14
14
  },
15
15
  "ts-node": {
16
- "require": ["tsconfig-paths/register"]
16
+ "require": ["tsconfig-paths/register"],
17
+ "swc": true
17
18
  },
18
19
  "references": [
19
20
  { "path": "../types" },
@@ -25,7 +26,6 @@
25
26
  "package.json"
26
27
  ],
27
28
  "exclude": [
28
- "node_modules",
29
29
  "dist"
30
30
  ]
31
31
  }