@budibase/worker 2.1.22-alpha.4 → 2.1.22-alpha.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.
Files changed (156) hide show
  1. package/__mocks__/oauth.ts +57 -0
  2. package/coverage/clover.xml +1093 -1033
  3. package/coverage/coverage-final.json +77 -72
  4. package/coverage/lcov-report/index.html +83 -83
  5. package/coverage/lcov-report/src/api/controllers/global/auth.ts.html +70 -70
  6. package/coverage/lcov-report/src/api/controllers/global/configs.js.html +35 -35
  7. package/coverage/lcov-report/src/api/controllers/global/email.js.html +4 -4
  8. package/coverage/lcov-report/src/api/controllers/global/index.html +38 -38
  9. package/coverage/lcov-report/src/api/controllers/global/license.ts.html +7 -7
  10. package/coverage/lcov-report/src/api/controllers/global/roles.js.html +10 -10
  11. package/coverage/lcov-report/src/api/controllers/global/self.ts.html +58 -58
  12. package/coverage/lcov-report/src/api/controllers/global/templates.ts.html +11 -11
  13. package/coverage/lcov-report/src/api/controllers/global/users.ts.html +75 -69
  14. package/coverage/lcov-report/src/api/controllers/global/workspaces.js.html +7 -7
  15. package/coverage/lcov-report/src/api/controllers/system/accounts.ts.html +4 -4
  16. package/coverage/lcov-report/src/api/controllers/system/{environment.js.html → environment.ts.html} +21 -18
  17. package/coverage/lcov-report/src/api/controllers/system/index.html +63 -63
  18. package/coverage/lcov-report/src/api/controllers/system/migrations.ts.html +23 -23
  19. package/coverage/lcov-report/src/api/controllers/system/restore.ts.html +22 -22
  20. package/coverage/lcov-report/src/api/controllers/system/{status.js.html → status.ts.html} +29 -26
  21. package/coverage/lcov-report/src/api/controllers/system/tenants.ts.html +34 -163
  22. package/coverage/lcov-report/src/api/index.html +11 -11
  23. package/coverage/lcov-report/src/api/index.ts.html +113 -44
  24. package/coverage/lcov-report/src/api/routes/global/auth.js.html +38 -89
  25. package/coverage/lcov-report/src/api/routes/global/configs.js.html +17 -17
  26. package/coverage/lcov-report/src/api/routes/global/email.js.html +11 -11
  27. package/coverage/lcov-report/src/api/routes/global/index.html +11 -11
  28. package/coverage/lcov-report/src/api/routes/global/license.ts.html +6 -6
  29. package/coverage/lcov-report/src/api/routes/global/roles.js.html +7 -7
  30. package/coverage/lcov-report/src/api/routes/global/self.ts.html +8 -8
  31. package/coverage/lcov-report/src/api/routes/global/templates.ts.html +11 -11
  32. package/coverage/lcov-report/src/api/routes/global/users.js.html +17 -17
  33. package/coverage/lcov-report/src/api/routes/global/workspaces.js.html +10 -10
  34. package/coverage/lcov-report/src/api/routes/index.html +1 -1
  35. package/coverage/lcov-report/src/api/routes/index.ts.html +19 -19
  36. package/coverage/lcov-report/src/api/routes/system/accounts.ts.html +7 -7
  37. package/coverage/lcov-report/src/api/routes/system/{environment.js.html → environment.ts.html} +11 -11
  38. package/coverage/lcov-report/src/api/routes/system/index.html +4 -4
  39. package/coverage/lcov-report/src/api/routes/system/migrations.ts.html +7 -7
  40. package/coverage/lcov-report/src/api/routes/system/restore.ts.html +6 -6
  41. package/coverage/lcov-report/src/api/routes/system/{status.js.html → status.ts.html} +11 -11
  42. package/coverage/lcov-report/src/api/routes/system/{tenants.js.html → tenants.ts.html} +20 -17
  43. package/coverage/lcov-report/src/api/routes/validation/index.html +1 -1
  44. package/coverage/lcov-report/src/api/routes/validation/index.ts.html +2 -2
  45. package/coverage/lcov-report/src/api/routes/validation/users.ts.html +13 -13
  46. package/coverage/lcov-report/src/constants/index.html +1 -1
  47. package/coverage/lcov-report/src/constants/index.js.html +18 -18
  48. package/coverage/lcov-report/src/constants/templates/index.html +1 -1
  49. package/coverage/lcov-report/src/constants/templates/index.js.html +10 -10
  50. package/coverage/lcov-report/src/db/index.html +1 -1
  51. package/coverage/lcov-report/src/db/index.ts.html +8 -8
  52. package/coverage/lcov-report/src/environment.ts.html +15 -15
  53. package/coverage/lcov-report/src/index.html +1 -1
  54. package/coverage/lcov-report/src/index.ts.html +40 -40
  55. package/coverage/lcov-report/src/middleware/cloudRestricted.js.html +22 -22
  56. package/coverage/lcov-report/src/middleware/index.html +21 -21
  57. package/coverage/lcov-report/src/migrations/functions/globalInfoSyncUsers.ts.html +3 -3
  58. package/coverage/lcov-report/src/migrations/functions/index.html +1 -1
  59. package/coverage/lcov-report/src/migrations/index.html +1 -1
  60. package/coverage/lcov-report/src/migrations/index.ts.html +17 -17
  61. package/coverage/lcov-report/src/sdk/accounts/accounts.ts.html +6 -6
  62. package/coverage/lcov-report/src/sdk/accounts/index.html +1 -1
  63. package/coverage/lcov-report/src/sdk/accounts/index.ts.html +2 -2
  64. package/coverage/lcov-report/src/sdk/index.html +1 -1
  65. package/coverage/lcov-report/src/sdk/index.ts.html +4 -4
  66. package/coverage/lcov-report/src/sdk/users/events.ts.html +43 -43
  67. package/coverage/lcov-report/src/sdk/users/index.html +19 -19
  68. package/coverage/lcov-report/src/sdk/users/index.ts.html +2 -2
  69. package/coverage/lcov-report/src/sdk/users/users.ts.html +99 -99
  70. package/coverage/lcov-report/src/tests/TestConfiguration.ts.html +261 -123
  71. package/coverage/lcov-report/src/tests/api/accounts.ts.html +12 -21
  72. package/coverage/lcov-report/src/tests/api/auth.ts.html +11 -20
  73. package/coverage/lcov-report/src/tests/api/base.ts.html +133 -0
  74. package/coverage/lcov-report/src/tests/api/configs.ts.html +44 -23
  75. package/coverage/lcov-report/src/tests/api/email.ts.html +9 -18
  76. package/coverage/lcov-report/src/tests/api/environment.ts.html +130 -0
  77. package/coverage/lcov-report/src/tests/api/index.html +106 -16
  78. package/coverage/lcov-report/src/tests/api/index.ts.html +62 -17
  79. package/coverage/lcov-report/src/tests/{structures/accounts.ts.html → api/migrations.ts.html} +31 -37
  80. package/coverage/lcov-report/src/tests/api/restore.ts.html +127 -0
  81. package/coverage/lcov-report/src/tests/api/self.ts.html +31 -16
  82. package/coverage/lcov-report/src/tests/api/status.ts.html +121 -0
  83. package/coverage/lcov-report/src/tests/api/tenants.ts.html +130 -0
  84. package/coverage/lcov-report/src/tests/api/users.ts.html +121 -25
  85. package/coverage/lcov-report/src/tests/controllers.js.html +2 -2
  86. package/coverage/lcov-report/src/tests/index.html +20 -20
  87. package/coverage/lcov-report/src/tests/index.ts.html +21 -9
  88. package/coverage/lcov-report/src/tests/mocks/email.js.html +2 -2
  89. package/coverage/lcov-report/src/tests/mocks/index.html +1 -1
  90. package/coverage/lcov-report/src/tests/mocks/index.ts.html +4 -4
  91. package/coverage/lcov-report/src/tests/structures/configs.js.html +8 -8
  92. package/coverage/lcov-report/src/tests/structures/groups.ts.html +2 -2
  93. package/coverage/lcov-report/src/tests/structures/index.html +9 -24
  94. package/coverage/lcov-report/src/tests/structures/index.ts.html +21 -15
  95. package/coverage/lcov-report/src/tests/structures/users.ts.html +13 -10
  96. package/coverage/lcov-report/src/utilities/appService.js.html +11 -11
  97. package/coverage/lcov-report/src/utilities/email.js.html +16 -16
  98. package/coverage/lcov-report/src/utilities/fileSystem.js.html +4 -4
  99. package/coverage/lcov-report/src/utilities/index.html +1 -1
  100. package/coverage/lcov-report/src/utilities/index.js.html +2 -2
  101. package/coverage/lcov-report/src/utilities/redis.js.html +13 -13
  102. package/coverage/lcov-report/src/utilities/templates.js.html +7 -7
  103. package/coverage/lcov-report/src/utilities/users.js.html +8 -8
  104. package/coverage/lcov.info +1685 -1511
  105. package/package.json +8 -6
  106. package/scripts/localdomain.js +33 -7
  107. package/src/api/controllers/global/auth.ts +1 -1
  108. package/src/api/controllers/global/users.ts +3 -1
  109. package/src/api/controllers/system/{environment.js → environment.ts} +3 -2
  110. package/src/api/controllers/system/{status.js → status.ts} +4 -3
  111. package/src/api/controllers/system/tenants.ts +8 -51
  112. package/src/api/index.ts +29 -6
  113. package/src/api/routes/global/auth.js +22 -39
  114. package/src/api/routes/global/tests/auth.spec.ts +134 -64
  115. package/src/api/routes/global/tests/configs.spec.ts +5 -6
  116. package/src/api/routes/global/tests/email.spec.ts +4 -3
  117. package/src/api/routes/global/tests/license.spec.ts +31 -0
  118. package/src/api/routes/global/tests/realEmail.spec.ts +2 -3
  119. package/src/api/routes/global/tests/roles.spec.ts +27 -0
  120. package/src/api/routes/global/tests/self.spec.ts +3 -4
  121. package/src/api/routes/global/tests/templates.spec.ts +35 -0
  122. package/src/api/routes/global/tests/users.spec.ts +51 -43
  123. package/src/api/routes/global/tests/workspaces.spec.ts +29 -0
  124. package/src/api/routes/system/environment.ts +8 -0
  125. package/src/api/routes/system/status.ts +8 -0
  126. package/src/api/routes/system/tenants.ts +13 -0
  127. package/src/api/routes/system/tests/accounts.spec.ts +5 -6
  128. package/src/api/routes/system/tests/environment.spec.ts +29 -0
  129. package/src/api/routes/system/tests/migrations.spec.ts +63 -0
  130. package/src/api/routes/system/tests/restore.spec.ts +36 -0
  131. package/src/api/routes/system/tests/status.spec.ts +48 -0
  132. package/src/api/routes/system/tests/tenants.spec.ts +61 -0
  133. package/src/middleware/tests/tenancy.spec.ts +73 -0
  134. package/src/tests/TestConfiguration.ts +88 -42
  135. package/src/tests/api/accounts.ts +5 -8
  136. package/src/tests/api/auth.ts +3 -6
  137. package/src/tests/api/base.ts +16 -0
  138. package/src/tests/api/configs.ts +15 -8
  139. package/src/tests/api/email.ts +3 -6
  140. package/src/tests/api/environment.ts +15 -0
  141. package/src/tests/api/index.ts +15 -0
  142. package/src/tests/api/migrations.ts +22 -0
  143. package/src/tests/api/restore.ts +14 -0
  144. package/src/tests/api/self.ts +11 -6
  145. package/src/tests/api/status.ts +12 -0
  146. package/src/tests/api/tenants.ts +15 -0
  147. package/src/tests/api/users.ts +38 -6
  148. package/src/tests/index.ts +4 -0
  149. package/src/tests/jestSetup.ts +7 -1
  150. package/src/tests/structures/index.ts +4 -2
  151. package/src/tests/structures/users.ts +1 -0
  152. package/__mocks__/node-fetch.ts +0 -1
  153. package/src/api/routes/system/environment.js +0 -8
  154. package/src/api/routes/system/status.js +0 -8
  155. package/src/api/routes/system/tenants.js +0 -12
  156. package/src/tests/structures/accounts.ts +0 -24
@@ -0,0 +1,15 @@
1
+ import TestConfiguration from "../TestConfiguration"
2
+ import { TestAPI } from "./base"
3
+
4
+ export class EnvironmentAPI extends TestAPI {
5
+ constructor(config: TestConfiguration) {
6
+ super(config)
7
+ }
8
+
9
+ getEnvironment = () => {
10
+ return this.request
11
+ .get(`/api/system/environment`)
12
+ .expect("Content-Type", /json/)
13
+ .expect(200)
14
+ }
15
+ }
@@ -5,6 +5,11 @@ import { ConfigAPI } from "./configs"
5
5
  import { EmailAPI } from "./email"
6
6
  import { SelfAPI } from "./self"
7
7
  import { UserAPI } from "./users"
8
+ import { EnvironmentAPI } from "./environment"
9
+ import { MigrationAPI } from "./migrations"
10
+ import { StatusAPI } from "./status"
11
+ import { RestoreAPI } from "./restore"
12
+ import { TenantAPI } from "./tenants"
8
13
 
9
14
  export default class API {
10
15
  accounts: AccountAPI
@@ -13,6 +18,11 @@ export default class API {
13
18
  emails: EmailAPI
14
19
  self: SelfAPI
15
20
  users: UserAPI
21
+ environment: EnvironmentAPI
22
+ migrations: MigrationAPI
23
+ status: StatusAPI
24
+ restore: RestoreAPI
25
+ tenants: TenantAPI
16
26
 
17
27
  constructor(config: TestConfiguration) {
18
28
  this.accounts = new AccountAPI(config)
@@ -21,5 +31,10 @@ export default class API {
21
31
  this.emails = new EmailAPI(config)
22
32
  this.self = new SelfAPI(config)
23
33
  this.users = new UserAPI(config)
34
+ this.environment = new EnvironmentAPI(config)
35
+ this.migrations = new MigrationAPI(config)
36
+ this.status = new StatusAPI(config)
37
+ this.restore = new RestoreAPI(config)
38
+ this.tenants = new TenantAPI(config)
24
39
  }
25
40
  }
@@ -0,0 +1,22 @@
1
+ import TestConfiguration from "../TestConfiguration"
2
+ import { TestAPI, TestAPIOpts } from "./base"
3
+
4
+ export class MigrationAPI extends TestAPI {
5
+ constructor(config: TestConfiguration) {
6
+ super(config)
7
+ }
8
+
9
+ runMigrations = (opts?: TestAPIOpts) => {
10
+ return this.request
11
+ .post(`/api/system/migrations/run`)
12
+ .set(opts?.headers ? opts.headers : this.config.internalAPIHeaders())
13
+ .expect(opts?.status ? opts.status : 200)
14
+ }
15
+
16
+ getMigrationDefinitions = (opts?: TestAPIOpts) => {
17
+ return this.request
18
+ .get(`/api/system/migrations/definitions`)
19
+ .set(opts?.headers ? opts.headers : this.config.internalAPIHeaders())
20
+ .expect(opts?.status ? opts.status : 200)
21
+ }
22
+ }
@@ -0,0 +1,14 @@
1
+ import TestConfiguration from "../TestConfiguration"
2
+ import { TestAPI, TestAPIOpts } from "./base"
3
+
4
+ export class RestoreAPI extends TestAPI {
5
+ constructor(config: TestConfiguration) {
6
+ super(config)
7
+ }
8
+
9
+ restored = (opts?: TestAPIOpts) => {
10
+ return this.request
11
+ .post(`/api/system/restored`)
12
+ .expect(opts?.status ? opts.status : 200)
13
+ }
14
+ }
@@ -1,13 +1,10 @@
1
1
  import TestConfiguration from "../TestConfiguration"
2
2
  import { User } from "@budibase/types"
3
+ import { TestAPI } from "./base"
3
4
 
4
- export class SelfAPI {
5
- config: TestConfiguration
6
- request: any
7
-
5
+ export class SelfAPI extends TestAPI {
8
6
  constructor(config: TestConfiguration) {
9
- this.config = config
10
- this.request = config.request
7
+ super(config)
11
8
  }
12
9
 
13
10
  updateSelf = (user: User) => {
@@ -18,4 +15,12 @@ export class SelfAPI {
18
15
  .expect("Content-Type", /json/)
19
16
  .expect(200)
20
17
  }
18
+
19
+ getSelf = (user: User) => {
20
+ return this.request
21
+ .get(`/api/global/self`)
22
+ .set(this.config.authHeaders(user))
23
+ .expect("Content-Type", /json/)
24
+ .expect(200)
25
+ }
21
26
  }
@@ -0,0 +1,12 @@
1
+ import TestConfiguration from "../TestConfiguration"
2
+ import { TestAPI } from "./base"
3
+
4
+ export class StatusAPI extends TestAPI {
5
+ constructor(config: TestConfiguration) {
6
+ super(config)
7
+ }
8
+
9
+ getStatus = () => {
10
+ return this.request.get(`/api/system/status`).expect(200)
11
+ }
12
+ }
@@ -0,0 +1,15 @@
1
+ import TestConfiguration from "../TestConfiguration"
2
+ import { TestAPI, TestAPIOpts } from "./base"
3
+
4
+ export class TenantAPI extends TestAPI {
5
+ constructor(config: TestConfiguration) {
6
+ super(config)
7
+ }
8
+
9
+ delete = (tenantId: string, opts?: TestAPIOpts) => {
10
+ return this.request
11
+ .delete(`/api/system/tenants/${tenantId}`)
12
+ .set(opts?.headers)
13
+ .expect(opts?.status ? opts.status : 204)
14
+ }
15
+ }
@@ -3,16 +3,16 @@ import {
3
3
  BulkUserRequest,
4
4
  InviteUsersRequest,
5
5
  User,
6
+ CreateAdminUserRequest,
6
7
  } from "@budibase/types"
8
+ import * as structures from "../structures"
9
+ import { generator } from "@budibase/backend-core/tests"
7
10
  import TestConfiguration from "../TestConfiguration"
11
+ import { TestAPI, TestAPIOpts } from "./base"
8
12
 
9
- export class UserAPI {
10
- config: TestConfiguration
11
- request: any
12
-
13
+ export class UserAPI extends TestAPI {
13
14
  constructor(config: TestConfiguration) {
14
- this.config = config
15
- this.request = config.request
15
+ super(config)
16
16
  }
17
17
 
18
18
  // INVITE
@@ -91,6 +91,30 @@ export class UserAPI {
91
91
 
92
92
  // USER
93
93
 
94
+ createAdminUser = async (
95
+ request?: CreateAdminUserRequest,
96
+ opts?: TestAPIOpts
97
+ ) => {
98
+ if (!request) {
99
+ request = {
100
+ email: structures.email(),
101
+ password: generator.string(),
102
+ tenantId: structures.uuid(),
103
+ }
104
+ }
105
+ const res = await this.request
106
+ .post(`/api/global/users/init`)
107
+ .send(request)
108
+ .set(this.config.internalAPIHeaders())
109
+ .expect("Content-Type", /json/)
110
+ .expect(opts?.status ? opts.status : 200)
111
+
112
+ return {
113
+ ...request,
114
+ userId: res.body._id,
115
+ }
116
+ }
117
+
94
118
  saveUser = (user: User, status?: number) => {
95
119
  return this.request
96
120
  .post(`/api/global/users`)
@@ -107,4 +131,12 @@ export class UserAPI {
107
131
  .expect("Content-Type", /json/)
108
132
  .expect(status ? status : 200)
109
133
  }
134
+
135
+ getUser = (userId: string, opts?: TestAPIOpts) => {
136
+ return this.request
137
+ .get(`/api/global/users/${userId}`)
138
+ .set(opts?.headers ? opts.headers : this.config.defaultHeaders())
139
+ .expect("Content-Type", /json/)
140
+ .expect(opts?.status ? opts.status : 200)
141
+ }
110
142
  }
@@ -1,10 +1,14 @@
1
1
  import mocks from "./mocks"
2
+ import { generator } from "@budibase/backend-core/tests"
2
3
  import TestConfiguration from "./TestConfiguration"
3
4
  import structures from "./structures"
4
5
  import API from "./api"
6
+ import { v4 as uuid } from "uuid"
5
7
 
6
8
  const pkg = {
7
9
  structures,
10
+ generator,
11
+ uuid,
8
12
  TENANT_1: structures.TENANT_1,
9
13
  mocks,
10
14
  TestConfiguration,
@@ -1,6 +1,6 @@
1
1
  import env from "../environment"
2
2
 
3
- env._set("SELF_HOSTED", "1")
3
+ env._set("SELF_HOSTED", "0")
4
4
  env._set("NODE_ENV", "jest")
5
5
  env._set("JWT_SECRET", "test-jwtsecret")
6
6
  env._set("LOG_LEVEL", "silent")
@@ -8,9 +8,15 @@ env._set("MULTI_TENANCY", true)
8
8
  env._set("MINIO_URL", "http://localhost")
9
9
  env._set("MINIO_ACCESS_KEY", "test")
10
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)
11
14
 
12
15
  import { mocks } from "@budibase/backend-core/tests"
13
16
 
17
+ // must explicitly enable fetch mock
18
+ mocks.fetch.enable()
19
+
14
20
  // mock all dates to 2020-01-01T00:00:00.000Z
15
21
  // use tk.reset() to use real dates in individual tests
16
22
  const tk = require("timekeeper")
@@ -1,16 +1,18 @@
1
+ import { structures } from "@budibase/backend-core/tests"
1
2
  import configs from "./configs"
2
3
  import * as users from "./users"
3
4
  import * as groups from "./groups"
4
- import * as accounts from "./accounts"
5
+ import { v4 as uuid } from "uuid"
5
6
 
6
7
  const TENANT_ID = "default"
7
8
  const TENANT_1 = "tenant1"
8
9
  const CSRF_TOKEN = "e3727778-7af0-4226-b5eb-f43cbe60a306"
9
10
 
10
11
  const pkg = {
12
+ ...structures,
13
+ uuid,
11
14
  configs,
12
15
  users,
13
- accounts,
14
16
  TENANT_ID,
15
17
  TENANT_1,
16
18
  CSRF_TOKEN,
@@ -5,6 +5,7 @@ import { v4 as uuid } from "uuid"
5
5
  export const newEmail = () => {
6
6
  return `${uuid()}@test.com`
7
7
  }
8
+
8
9
  export const user = (userProps?: any): User => {
9
10
  return {
10
11
  email: newEmail(),
@@ -1 +0,0 @@
1
- jest.mock("node-fetch", () => jest.fn())
@@ -1,8 +0,0 @@
1
- const Router = require("@koa/router")
2
- const controller = require("../../controllers/system/environment")
3
-
4
- const router = new Router()
5
-
6
- router.get("/api/system/environment", controller.fetch)
7
-
8
- module.exports = router
@@ -1,8 +0,0 @@
1
- const Router = require("@koa/router")
2
- const controller = require("../../controllers/system/status")
3
-
4
- const router = new Router()
5
-
6
- router.get("/api/system/status", controller.fetch)
7
-
8
- module.exports = router
@@ -1,12 +0,0 @@
1
- const Router = require("@koa/router")
2
- const controller = require("../../controllers/system/tenants")
3
- const { adminOnly } = require("@budibase/backend-core/auth")
4
-
5
- const router = new Router()
6
-
7
- router
8
- .get("/api/system/tenants/:tenantId/exists", controller.exists)
9
- .get("/api/system/tenants", adminOnly, controller.fetch)
10
- .delete("/api/system/tenants/:tenantId", adminOnly, controller.delete)
11
-
12
- module.exports = router
@@ -1,24 +0,0 @@
1
- import { Account, AuthType, Hosting, CloudAccount } from "@budibase/types"
2
- import { v4 as uuid } from "uuid"
3
- import { utils } from "@budibase/backend-core"
4
-
5
- export const account = (): Account => {
6
- return {
7
- email: `${uuid()}@test.com`,
8
- tenantId: utils.newid(),
9
- hosting: Hosting.SELF,
10
- authType: AuthType.SSO,
11
- accountId: uuid(),
12
- createdAt: Date.now(),
13
- verified: true,
14
- verificationSent: true,
15
- tier: "FREE",
16
- }
17
- }
18
-
19
- export const cloudAccount = (): CloudAccount => {
20
- return {
21
- ...account(),
22
- budibaseUserId: uuid(),
23
- }
24
- }