@budibase/worker 2.1.42 → 2.1.43-alpha.1

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 (208) hide show
  1. package/__mocks__/aws-sdk.ts +15 -0
  2. package/__mocks__/oauth.ts +57 -0
  3. package/coverage/clover.xml +2157 -0
  4. package/coverage/coverage-final.json +78 -0
  5. package/coverage/lcov-report/base.css +224 -0
  6. package/coverage/lcov-report/block-navigation.js +87 -0
  7. package/coverage/lcov-report/favicon.png +0 -0
  8. package/coverage/lcov-report/index.html +431 -0
  9. package/coverage/lcov-report/prettify.css +1 -0
  10. package/coverage/lcov-report/prettify.js +2 -0
  11. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  12. package/coverage/lcov-report/sorter.js +196 -0
  13. package/coverage/lcov-report/src/api/controllers/global/auth.ts.html +925 -0
  14. package/coverage/lcov-report/src/api/controllers/global/configs.ts.html +1405 -0
  15. package/coverage/lcov-report/src/api/controllers/global/email.ts.html +196 -0
  16. package/coverage/lcov-report/src/api/controllers/global/index.html +236 -0
  17. package/coverage/lcov-report/src/api/controllers/global/license.ts.html +187 -0
  18. package/coverage/lcov-report/src/api/controllers/global/roles.ts.html +283 -0
  19. package/coverage/lcov-report/src/api/controllers/global/self.ts.html +577 -0
  20. package/coverage/lcov-report/src/api/controllers/global/templates.ts.html +316 -0
  21. package/coverage/lcov-report/src/api/controllers/global/users.ts.html +796 -0
  22. package/coverage/lcov-report/src/api/controllers/global/workspaces.ts.html +244 -0
  23. package/coverage/lcov-report/src/api/controllers/system/accounts.ts.html +148 -0
  24. package/coverage/lcov-report/src/api/controllers/system/environment.ts.html +124 -0
  25. package/coverage/lcov-report/src/api/controllers/system/index.html +191 -0
  26. package/coverage/lcov-report/src/api/controllers/system/migrations.ts.html +124 -0
  27. package/coverage/lcov-report/src/api/controllers/system/restore.ts.html +124 -0
  28. package/coverage/lcov-report/src/api/controllers/system/status.ts.html +133 -0
  29. package/coverage/lcov-report/src/api/controllers/system/tenants.ts.html +154 -0
  30. package/coverage/lcov-report/src/api/index.html +116 -0
  31. package/coverage/lcov-report/src/api/index.ts.html +583 -0
  32. package/coverage/lcov-report/src/api/routes/global/auth.ts.html +349 -0
  33. package/coverage/lcov-report/src/api/routes/global/configs.ts.html +457 -0
  34. package/coverage/lcov-report/src/api/routes/global/email.ts.html +193 -0
  35. package/coverage/lcov-report/src/api/routes/global/index.html +236 -0
  36. package/coverage/lcov-report/src/api/routes/global/license.ts.html +124 -0
  37. package/coverage/lcov-report/src/api/routes/global/roles.ts.html +133 -0
  38. package/coverage/lcov-report/src/api/routes/global/self.ts.html +139 -0
  39. package/coverage/lcov-report/src/api/routes/global/templates.ts.html +196 -0
  40. package/coverage/lcov-report/src/api/routes/global/users.ts.html +433 -0
  41. package/coverage/lcov-report/src/api/routes/global/workspaces.ts.html +196 -0
  42. package/coverage/lcov-report/src/api/routes/index.html +116 -0
  43. package/coverage/lcov-report/src/api/routes/index.ts.html +196 -0
  44. package/coverage/lcov-report/src/api/routes/system/accounts.ts.html +142 -0
  45. package/coverage/lcov-report/src/api/routes/system/environment.ts.html +109 -0
  46. package/coverage/lcov-report/src/api/routes/system/index.html +191 -0
  47. package/coverage/lcov-report/src/api/routes/system/migrations.ts.html +142 -0
  48. package/coverage/lcov-report/src/api/routes/system/restore.ts.html +109 -0
  49. package/coverage/lcov-report/src/api/routes/system/status.ts.html +109 -0
  50. package/coverage/lcov-report/src/api/routes/system/tenants.ts.html +124 -0
  51. package/coverage/lcov-report/src/api/routes/validation/index.html +131 -0
  52. package/coverage/lcov-report/src/api/routes/validation/index.ts.html +88 -0
  53. package/coverage/lcov-report/src/api/routes/validation/users.ts.html +235 -0
  54. package/coverage/lcov-report/src/constants/index.html +116 -0
  55. package/coverage/lcov-report/src/constants/index.ts.html +613 -0
  56. package/coverage/lcov-report/src/constants/templates/index.html +116 -0
  57. package/coverage/lcov-report/src/constants/templates/index.ts.html +316 -0
  58. package/coverage/lcov-report/src/db/index.html +116 -0
  59. package/coverage/lcov-report/src/db/index.ts.html +115 -0
  60. package/coverage/lcov-report/src/environment.ts.html +373 -0
  61. package/coverage/lcov-report/src/index.html +131 -0
  62. package/coverage/lcov-report/src/index.ts.html +394 -0
  63. package/coverage/lcov-report/src/middleware/cloudRestricted.ts.html +139 -0
  64. package/coverage/lcov-report/src/middleware/index.html +116 -0
  65. package/coverage/lcov-report/src/migrations/functions/globalInfoSyncUsers.ts.html +145 -0
  66. package/coverage/lcov-report/src/migrations/functions/index.html +116 -0
  67. package/coverage/lcov-report/src/migrations/index.html +116 -0
  68. package/coverage/lcov-report/src/migrations/index.ts.html +271 -0
  69. package/coverage/lcov-report/src/sdk/accounts/accounts.ts.html +262 -0
  70. package/coverage/lcov-report/src/sdk/accounts/index.html +131 -0
  71. package/coverage/lcov-report/src/sdk/accounts/index.ts.html +88 -0
  72. package/coverage/lcov-report/src/sdk/index.html +116 -0
  73. package/coverage/lcov-report/src/sdk/index.ts.html +106 -0
  74. package/coverage/lcov-report/src/sdk/users/events.ts.html +577 -0
  75. package/coverage/lcov-report/src/sdk/users/index.html +146 -0
  76. package/coverage/lcov-report/src/sdk/users/index.ts.html +88 -0
  77. package/coverage/lcov-report/src/sdk/users/users.ts.html +1903 -0
  78. package/coverage/lcov-report/src/tests/TestConfiguration.ts.html +1051 -0
  79. package/coverage/lcov-report/src/tests/api/accounts.ts.html +160 -0
  80. package/coverage/lcov-report/src/tests/api/auth.ts.html +220 -0
  81. package/coverage/lcov-report/src/tests/api/base.ts.html +133 -0
  82. package/coverage/lcov-report/src/tests/api/configs.ts.html +226 -0
  83. package/coverage/lcov-report/src/tests/api/email.ts.html +148 -0
  84. package/coverage/lcov-report/src/tests/api/environment.ts.html +130 -0
  85. package/coverage/lcov-report/src/tests/api/index.html +296 -0
  86. package/coverage/lcov-report/src/tests/api/index.ts.html +205 -0
  87. package/coverage/lcov-report/src/tests/api/migrations.ts.html +151 -0
  88. package/coverage/lcov-report/src/tests/api/restore.ts.html +127 -0
  89. package/coverage/lcov-report/src/tests/api/self.ts.html +163 -0
  90. package/coverage/lcov-report/src/tests/api/status.ts.html +121 -0
  91. package/coverage/lcov-report/src/tests/api/tenants.ts.html +130 -0
  92. package/coverage/lcov-report/src/tests/api/users.ts.html +511 -0
  93. package/coverage/lcov-report/src/tests/controllers.ts.html +100 -0
  94. package/coverage/lcov-report/src/tests/index.html +146 -0
  95. package/coverage/lcov-report/src/tests/index.ts.html +139 -0
  96. package/coverage/lcov-report/src/tests/mocks/email.js.html +115 -0
  97. package/coverage/lcov-report/src/tests/mocks/index.html +131 -0
  98. package/coverage/lcov-report/src/tests/mocks/index.ts.html +106 -0
  99. package/coverage/lcov-report/src/tests/structures/configs.ts.html +313 -0
  100. package/coverage/lcov-report/src/tests/structures/groups.ts.html +118 -0
  101. package/coverage/lcov-report/src/tests/structures/index.html +161 -0
  102. package/coverage/lcov-report/src/tests/structures/index.ts.html +151 -0
  103. package/coverage/lcov-report/src/tests/structures/users.ts.html +196 -0
  104. package/coverage/lcov-report/src/utilities/appService.ts.html +181 -0
  105. package/coverage/lcov-report/src/utilities/email.ts.html +850 -0
  106. package/coverage/lcov-report/src/utilities/fileSystem.ts.html +100 -0
  107. package/coverage/lcov-report/src/utilities/index.html +206 -0
  108. package/coverage/lcov-report/src/utilities/index.ts.html +112 -0
  109. package/coverage/lcov-report/src/utilities/redis.ts.html +424 -0
  110. package/coverage/lcov-report/src/utilities/templates.ts.html +232 -0
  111. package/coverage/lcov-report/src/utilities/users.ts.html +133 -0
  112. package/coverage/lcov.info +3970 -0
  113. package/jest.config.ts +29 -0
  114. package/package.json +14 -24
  115. package/scripts/localdomain.js +33 -7
  116. package/src/api/controllers/global/auth.ts +51 -43
  117. package/src/api/controllers/global/{configs.js → configs.ts} +119 -114
  118. package/src/api/controllers/global/{email.js → email.ts} +6 -5
  119. package/src/api/controllers/global/roles.ts +66 -0
  120. package/src/api/controllers/global/self.ts +2 -2
  121. package/src/api/controllers/global/users.ts +4 -2
  122. package/src/api/controllers/global/{workspaces.js → workspaces.ts} +15 -18
  123. package/src/api/controllers/system/{environment.js → environment.ts} +3 -2
  124. package/src/api/controllers/system/restore.ts +1 -1
  125. package/src/api/controllers/system/{status.js → status.ts} +4 -3
  126. package/src/api/controllers/system/tenants.ts +8 -51
  127. package/src/api/index.ts +31 -8
  128. package/src/api/routes/global/{auth.js → auth.ts} +31 -48
  129. package/src/api/routes/global/{configs.js → configs.ts} +22 -23
  130. package/src/api/routes/global/{email.js → email.ts} +9 -10
  131. package/src/api/routes/global/license.ts +1 -1
  132. package/src/api/routes/global/roles.ts +16 -0
  133. package/src/api/routes/global/self.ts +2 -2
  134. package/src/api/routes/global/templates.ts +4 -4
  135. package/src/api/routes/global/tests/auth.spec.ts +134 -64
  136. package/src/api/routes/global/tests/configs.spec.ts +34 -35
  137. package/src/api/routes/global/tests/email.spec.ts +4 -3
  138. package/src/api/routes/global/tests/license.spec.ts +31 -0
  139. package/src/api/routes/global/tests/realEmail.spec.ts +2 -3
  140. package/src/api/routes/global/tests/roles.spec.ts +27 -0
  141. package/src/api/routes/global/tests/self.spec.ts +3 -4
  142. package/src/api/routes/global/tests/templates.spec.ts +35 -0
  143. package/src/api/routes/global/tests/users.spec.ts +61 -45
  144. package/src/api/routes/global/tests/workspaces.spec.ts +29 -0
  145. package/src/api/routes/global/{users.js → users.ts} +28 -26
  146. package/src/api/routes/global/{workspaces.js → workspaces.ts} +9 -10
  147. package/src/api/routes/index.ts +2 -1
  148. package/src/api/routes/system/accounts.ts +1 -1
  149. package/src/api/routes/system/environment.ts +8 -0
  150. package/src/api/routes/system/migrations.ts +1 -1
  151. package/src/api/routes/system/restore.ts +1 -1
  152. package/src/api/routes/system/status.ts +8 -0
  153. package/src/api/routes/system/tenants.ts +13 -0
  154. package/src/api/routes/system/tests/accounts.spec.ts +5 -6
  155. package/src/api/routes/system/tests/environment.spec.ts +29 -0
  156. package/src/api/routes/system/tests/migrations.spec.ts +63 -0
  157. package/src/api/routes/system/tests/restore.spec.ts +36 -0
  158. package/src/api/routes/system/tests/status.spec.ts +48 -0
  159. package/src/api/routes/system/tests/tenants.spec.ts +61 -0
  160. package/src/api/routes/validation/users.ts +3 -3
  161. package/src/constants/{index.js → index.ts} +57 -64
  162. package/src/constants/templates/{index.js → index.ts} +23 -19
  163. package/src/db/index.ts +10 -0
  164. package/src/environment.ts +9 -7
  165. package/src/index.ts +15 -16
  166. package/src/middleware/{cloudRestricted.js → cloudRestricted.ts} +5 -4
  167. package/src/middleware/tests/tenancy.spec.ts +73 -0
  168. package/src/tests/TestConfiguration.ts +99 -50
  169. package/src/tests/api/accounts.ts +5 -8
  170. package/src/tests/api/auth.ts +3 -6
  171. package/src/tests/api/base.ts +16 -0
  172. package/src/tests/api/configs.ts +15 -8
  173. package/src/tests/api/email.ts +3 -6
  174. package/src/tests/api/environment.ts +15 -0
  175. package/src/tests/api/index.ts +15 -0
  176. package/src/tests/api/migrations.ts +22 -0
  177. package/src/tests/api/restore.ts +14 -0
  178. package/src/tests/api/self.ts +11 -6
  179. package/src/tests/api/status.ts +12 -0
  180. package/src/tests/api/tenants.ts +15 -0
  181. package/src/tests/api/users.ts +38 -6
  182. package/src/tests/controllers.ts +5 -0
  183. package/src/tests/index.ts +5 -1
  184. package/{scripts/jestSetup.js → src/tests/jestSetup.ts} +12 -3
  185. package/src/tests/structures/{configs.js → configs.ts} +11 -11
  186. package/src/tests/structures/index.ts +5 -3
  187. package/src/tests/structures/users.ts +1 -0
  188. package/src/utilities/appService.ts +32 -0
  189. package/src/utilities/{email.js → email.ts} +78 -45
  190. package/src/utilities/fileSystem.ts +5 -0
  191. package/src/utilities/{index.js → index.ts} +1 -1
  192. package/src/utilities/{redis.js → redis.ts} +29 -24
  193. package/src/utilities/templates.ts +49 -0
  194. package/src/utilities/users.ts +16 -0
  195. package/tsconfig.build.json +2 -3
  196. package/tsconfig.json +3 -1
  197. package/src/api/controllers/global/roles.js +0 -68
  198. package/src/api/routes/global/roles.js +0 -12
  199. package/src/api/routes/system/environment.js +0 -8
  200. package/src/api/routes/system/status.js +0 -8
  201. package/src/api/routes/system/tenants.js +0 -12
  202. package/src/db/index.js +0 -11
  203. package/src/tests/controllers.js +0 -7
  204. package/src/tests/structures/accounts.ts +0 -24
  205. package/src/utilities/appService.js +0 -33
  206. package/src/utilities/fileSystem.js +0 -5
  207. package/src/utilities/templates.js +0 -49
  208. package/src/utilities/users.js +0 -17
@@ -1,10 +1,9 @@
1
1
  import sdk from "../../../../sdk"
2
- import { TestConfiguration, structures, API } from "../../../../tests"
2
+ import { TestConfiguration, structures } from "../../../../tests"
3
3
  import { v4 as uuid } from "uuid"
4
4
 
5
5
  describe("accounts", () => {
6
6
  const config = new TestConfiguration()
7
- const api = new API(config)
8
7
 
9
8
  beforeAll(async () => {
10
9
  await config.beforeAll()
@@ -23,7 +22,7 @@ describe("accounts", () => {
23
22
  it("saves account metadata", async () => {
24
23
  let account = structures.accounts.account()
25
24
 
26
- const response = await api.accounts.saveMetadata(account)
25
+ const response = await config.api.accounts.saveMetadata(account)
27
26
 
28
27
  const id = sdk.accounts.formatAccountMetadataId(account.accountId)
29
28
  const metadata = await sdk.accounts.getMetadata(id)
@@ -34,9 +33,9 @@ describe("accounts", () => {
34
33
  describe("destroyMetadata", () => {
35
34
  it("destroys account metadata", async () => {
36
35
  const account = structures.accounts.account()
37
- await api.accounts.saveMetadata(account)
36
+ await config.api.accounts.saveMetadata(account)
38
37
 
39
- await api.accounts.destroyMetadata(account.accountId)
38
+ await config.api.accounts.destroyMetadata(account.accountId)
40
39
 
41
40
  const deleted = await sdk.accounts.getMetadata(account.accountId)
42
41
  expect(deleted).toBe(undefined)
@@ -45,7 +44,7 @@ describe("accounts", () => {
45
44
  it("destroys account metadata that does not exist", async () => {
46
45
  const id = uuid()
47
46
 
48
- const response = await api.accounts.destroyMetadata(id)
47
+ const response = await config.api.accounts.destroyMetadata(id)
49
48
 
50
49
  expect(response.status).toBe(204)
51
50
  })
@@ -0,0 +1,29 @@
1
+ import { TestConfiguration } from "../../../../tests"
2
+
3
+ describe("/api/system/environment", () => {
4
+ const config = new TestConfiguration()
5
+
6
+ beforeAll(async () => {
7
+ await config.beforeAll()
8
+ })
9
+
10
+ afterAll(async () => {
11
+ await config.afterAll()
12
+ })
13
+
14
+ afterEach(() => {
15
+ jest.clearAllMocks()
16
+ })
17
+
18
+ describe("GET /api/system/environment", () => {
19
+ it("returns the expected environment", async () => {
20
+ const env = await config.api.environment.getEnvironment()
21
+ expect(env.body).toEqual({
22
+ cloud: true,
23
+ disableAccountPortal: false,
24
+ isDev: false,
25
+ multiTenancy: true,
26
+ })
27
+ })
28
+ })
29
+ })
@@ -0,0 +1,63 @@
1
+ const migrateFn = jest.fn()
2
+
3
+ import { TestConfiguration } from "../../../../tests"
4
+
5
+ jest.mock("../../../../migrations", () => {
6
+ return {
7
+ ...jest.requireActual("../../../../migrations"),
8
+ migrate: migrateFn,
9
+ }
10
+ })
11
+
12
+ describe("/api/system/migrations", () => {
13
+ const config = new TestConfiguration()
14
+
15
+ beforeAll(async () => {
16
+ await config.beforeAll()
17
+ })
18
+
19
+ afterAll(async () => {
20
+ await config.afterAll()
21
+ })
22
+
23
+ afterEach(() => {
24
+ jest.clearAllMocks()
25
+ })
26
+
27
+ describe("POST /api/system/migrations/run", () => {
28
+ it("fails with no internal api key", async () => {
29
+ const res = await config.api.migrations.runMigrations({
30
+ headers: {},
31
+ status: 403,
32
+ })
33
+ expect(res.text).toBe("Unauthorized - no public worker access")
34
+ expect(migrateFn).toBeCalledTimes(0)
35
+ })
36
+
37
+ it("runs migrations", async () => {
38
+ const res = await config.api.migrations.runMigrations()
39
+ expect(res.text).toBe("OK")
40
+ expect(migrateFn).toBeCalledTimes(1)
41
+ })
42
+ })
43
+
44
+ describe("DELETE /api/system/migrations/definitions", () => {
45
+ it("fails with no internal api key", async () => {
46
+ const res = await config.api.migrations.getMigrationDefinitions({
47
+ headers: {},
48
+ status: 403,
49
+ })
50
+ expect(res.text).toBe("Unauthorized - no public worker access")
51
+ })
52
+
53
+ it("returns definitions", async () => {
54
+ const res = await config.api.migrations.getMigrationDefinitions()
55
+ expect(res.body).toEqual([
56
+ {
57
+ name: "global_info_sync_users",
58
+ type: "global",
59
+ },
60
+ ])
61
+ })
62
+ })
63
+ })
@@ -0,0 +1,36 @@
1
+ import { TestConfiguration } from "../../../../tests"
2
+
3
+ describe("/api/system/restore", () => {
4
+ const config = new TestConfiguration()
5
+
6
+ beforeAll(async () => {
7
+ await config.beforeAll()
8
+ })
9
+
10
+ afterAll(async () => {
11
+ await config.afterAll()
12
+ })
13
+
14
+ afterEach(() => {
15
+ jest.clearAllMocks()
16
+ })
17
+
18
+ describe("POST /api/global/restore", () => {
19
+ it("doesn't allow restore in cloud", async () => {
20
+ const res = await config.api.restore.restored({ status: 405 })
21
+ expect(res.body).toEqual({
22
+ message: "This operation is not allowed in cloud.",
23
+ status: 405,
24
+ })
25
+ })
26
+
27
+ it("restores in self host", async () => {
28
+ config.modeSelf()
29
+ const res = await config.api.restore.restored()
30
+ expect(res.body).toEqual({
31
+ message: "System prepared after restore.",
32
+ })
33
+ config.modeCloud()
34
+ })
35
+ })
36
+ })
@@ -0,0 +1,48 @@
1
+ import { TestConfiguration } from "../../../../tests"
2
+ import { accounts } from "@budibase/backend-core"
3
+ import { mocks } from "@budibase/backend-core/tests"
4
+
5
+ describe("/api/system/status", () => {
6
+ const config = new TestConfiguration()
7
+
8
+ beforeAll(async () => {
9
+ await config.beforeAll()
10
+ })
11
+
12
+ afterAll(async () => {
13
+ await config.afterAll()
14
+ })
15
+
16
+ afterEach(() => {
17
+ jest.clearAllMocks()
18
+ })
19
+
20
+ describe("GET /api/system/status", () => {
21
+ it("returns status in self host", async () => {
22
+ config.modeSelf()
23
+ const res = await config.api.status.getStatus()
24
+ expect(res.body).toEqual({
25
+ health: {
26
+ passing: true,
27
+ },
28
+ })
29
+ expect(accounts.getStatus).toBeCalledTimes(0)
30
+ config.modeCloud()
31
+ })
32
+
33
+ it("returns status in cloud", async () => {
34
+ const value = {
35
+ health: {
36
+ passing: false,
37
+ },
38
+ }
39
+
40
+ mocks.accounts.getStatus.mockReturnValueOnce(value)
41
+
42
+ const res = await config.api.status.getStatus()
43
+
44
+ expect(accounts.getStatus).toBeCalledTimes(1)
45
+ expect(res.body).toEqual(value)
46
+ })
47
+ })
48
+ })
@@ -0,0 +1,61 @@
1
+ import { TestConfiguration } from "../../../../tests"
2
+ import { tenancy } from "@budibase/backend-core"
3
+
4
+ describe("/api/global/tenants", () => {
5
+ const config = new TestConfiguration()
6
+
7
+ beforeAll(async () => {
8
+ await config.beforeAll()
9
+ })
10
+
11
+ afterAll(async () => {
12
+ await config.afterAll()
13
+ })
14
+
15
+ afterEach(() => {
16
+ jest.clearAllMocks()
17
+ })
18
+
19
+ describe("DELETE /api/system/tenants/:tenantId", () => {
20
+ it("allows deleting the current tenant", async () => {
21
+ const user = await config.createTenant()
22
+
23
+ await config.api.tenants.delete(user.tenantId, {
24
+ headers: config.authHeaders(user),
25
+ })
26
+ })
27
+
28
+ it("rejects deleting another tenant", async () => {
29
+ const user1 = await config.createTenant()
30
+ // create a second user in another tenant
31
+ const user2 = await config.createTenant()
32
+
33
+ const status = 403
34
+ const res = await config.api.tenants.delete(user1.tenantId, {
35
+ status,
36
+ headers: config.authHeaders(user2),
37
+ })
38
+
39
+ expect(res.body).toEqual({
40
+ message: "Tenant ID does not match current user",
41
+ status,
42
+ })
43
+ })
44
+
45
+ it("rejects non-admin", async () => {
46
+ const user1 = await config.createTenant()
47
+ // create an internal non-admin user
48
+ const user2 = await tenancy.doInTenant(user1.tenantId, () => {
49
+ return config.createUser()
50
+ })
51
+ await config.createSession(user2)
52
+
53
+ const res = await config.api.tenants.delete(user1.tenantId, {
54
+ status: 403,
55
+ headers: config.authHeaders(user2),
56
+ })
57
+
58
+ expect(res.body).toEqual(config.adminOnlyResponse())
59
+ })
60
+ })
61
+ })
@@ -1,4 +1,4 @@
1
- const { joiValidator } = require("@budibase/backend-core/auth")
1
+ import { auth } from "@budibase/backend-core"
2
2
  import Joi from "joi"
3
3
 
4
4
  let schema: any = {
@@ -25,7 +25,7 @@ export const buildUserSaveValidation = (isSelf = false) => {
25
25
  _rev: Joi.string(),
26
26
  }
27
27
  }
28
- return joiValidator.body(Joi.object(schema).required().unknown(true))
28
+ return auth.joiValidator.body(Joi.object(schema).required().unknown(true))
29
29
  }
30
30
 
31
31
  export const buildUserBulkUserValidation = (isSelf = false) => {
@@ -46,5 +46,5 @@ export const buildUserBulkUserValidation = (isSelf = false) => {
46
46
  }),
47
47
  }
48
48
 
49
- return joiValidator.body(Joi.object(bulkSchema).required().unknown(true))
49
+ return auth.joiValidator.body(Joi.object(bulkSchema).required().unknown(true))
50
50
  }
@@ -1,97 +1,97 @@
1
- const { Configs } = require("@budibase/backend-core/constants")
1
+ import { constants } from "@budibase/backend-core"
2
2
 
3
- exports.LOGO_URL =
3
+ export const LOGO_URL =
4
4
  "https://d33wubrfki0l68.cloudfront.net/aac32159d7207b5085e74a7ef67afbb7027786c5/2b1fd/img/logo/bb-emblem.svg"
5
5
 
6
- exports.UserStatus = {
7
- ACTIVE: "active",
8
- INACTIVE: "inactive",
6
+ export enum UserStatus {
7
+ ACTIVE = "active",
8
+ INACTIVE = "inactive",
9
9
  }
10
10
 
11
- exports.Configs = Configs
11
+ export const Config = constants.Config
12
12
 
13
- exports.ConfigUploads = {
14
- LOGO: "logo",
15
- OIDC_LOGO: "oidc_logo",
13
+ export enum ConfigUpload {
14
+ LOGO = "logo",
15
+ OIDC_LOGO = "oidc_logo",
16
16
  }
17
17
 
18
- const TemplateTypes = {
19
- EMAIL: "email",
18
+ export enum TemplateType {
19
+ EMAIL = "email",
20
20
  }
21
21
 
22
- const EmailTemplatePurpose = {
23
- BASE: "base",
24
- PASSWORD_RECOVERY: "password_recovery",
25
- INVITATION: "invitation",
26
- WELCOME: "welcome",
27
- CUSTOM: "custom",
22
+ export enum EmailTemplatePurpose {
23
+ BASE = "base",
24
+ PASSWORD_RECOVERY = "password_recovery",
25
+ INVITATION = "invitation",
26
+ WELCOME = "welcome",
27
+ CUSTOM = "custom",
28
28
  }
29
29
 
30
- const InternalTemplateBindings = {
31
- PLATFORM_URL: "platformUrl",
32
- COMPANY: "company",
33
- LOGO_URL: "logoUrl",
34
- EMAIL: "email",
35
- USER: "user",
36
- REQUEST: "request",
37
- DOCS_URL: "docsUrl",
38
- LOGIN_URL: "loginUrl",
39
- CURRENT_YEAR: "currentYear",
40
- CURRENT_DATE: "currentDate",
41
- BODY: "body",
42
- STYLES: "styles",
43
- RESET_URL: "resetUrl",
44
- RESET_CODE: "resetCode",
45
- INVITE_URL: "inviteUrl",
46
- INVITE_CODE: "inviteUrl",
47
- CONTENTS: "contents",
30
+ export enum InternalTemplateBinding {
31
+ PLATFORM_URL = "platformUrl",
32
+ COMPANY = "company",
33
+ LOGO_URL = "logoUrl",
34
+ EMAIL = "email",
35
+ USER = "user",
36
+ REQUEST = "request",
37
+ DOCS_URL = "docsUrl",
38
+ LOGIN_URL = "loginUrl",
39
+ CURRENT_YEAR = "currentYear",
40
+ CURRENT_DATE = "currentDate",
41
+ BODY = "body",
42
+ STYLES = "styles",
43
+ RESET_URL = "resetUrl",
44
+ RESET_CODE = "resetCode",
45
+ INVITE_URL = "inviteUrl",
46
+ INVITE_CODE = "inviteUrl",
47
+ CONTENTS = "contents",
48
48
  }
49
49
 
50
- const TemplateBindings = {
50
+ export const TemplateBindings = {
51
51
  PLATFORM_URL: {
52
- name: InternalTemplateBindings.PLATFORM_URL,
52
+ name: InternalTemplateBinding.PLATFORM_URL,
53
53
  description: "The URL used to access the budibase platform",
54
54
  },
55
55
  COMPANY: {
56
- name: InternalTemplateBindings.COMPANY,
56
+ name: InternalTemplateBinding.COMPANY,
57
57
  description: "The name of your organization",
58
58
  },
59
59
  LOGO_URL: {
60
- name: InternalTemplateBindings.LOGO_URL,
60
+ name: InternalTemplateBinding.LOGO_URL,
61
61
  description: "The URL of your organizations logo.",
62
62
  },
63
63
  EMAIL: {
64
- name: InternalTemplateBindings.EMAIL,
64
+ name: InternalTemplateBinding.EMAIL,
65
65
  description: "The recipients email address.",
66
66
  },
67
67
  USER: {
68
- name: InternalTemplateBindings.USER,
68
+ name: InternalTemplateBinding.USER,
69
69
  description: "The recipients user object.",
70
70
  },
71
71
  REQUEST: {
72
- name: InternalTemplateBindings.REQUEST,
72
+ name: InternalTemplateBinding.REQUEST,
73
73
  description: "Additional request metadata.",
74
74
  },
75
75
  DOCS_URL: {
76
- name: InternalTemplateBindings.DOCS_URL,
76
+ name: InternalTemplateBinding.DOCS_URL,
77
77
  description: "Organization documentation URL.",
78
78
  },
79
79
  LOGIN_URL: {
80
- name: InternalTemplateBindings.LOGIN_URL,
80
+ name: InternalTemplateBinding.LOGIN_URL,
81
81
  description: "The URL used to log into the organization budibase instance.",
82
82
  },
83
83
  CURRENT_YEAR: {
84
- name: InternalTemplateBindings.CURRENT_YEAR,
84
+ name: InternalTemplateBinding.CURRENT_YEAR,
85
85
  description: "The current year.",
86
86
  },
87
87
  CURRENT_DATE: {
88
- name: InternalTemplateBindings.CURRENT_DATE,
88
+ name: InternalTemplateBinding.CURRENT_DATE,
89
89
  description: "The current date.",
90
90
  },
91
91
  }
92
92
 
93
- const TemplateMetadata = {
94
- [TemplateTypes.EMAIL]: [
93
+ export const TemplateMetadata = {
94
+ [TemplateType.EMAIL]: [
95
95
  {
96
96
  name: "Base format",
97
97
  description:
@@ -100,11 +100,11 @@ const TemplateMetadata = {
100
100
  purpose: EmailTemplatePurpose.BASE,
101
101
  bindings: [
102
102
  {
103
- name: InternalTemplateBindings.BODY,
103
+ name: InternalTemplateBinding.BODY,
104
104
  description: "The main body of another email template.",
105
105
  },
106
106
  {
107
- name: InternalTemplateBindings.STYLES,
107
+ name: InternalTemplateBinding.STYLES,
108
108
  description: "The contents of the Styling email template.",
109
109
  },
110
110
  ],
@@ -117,12 +117,12 @@ const TemplateMetadata = {
117
117
  purpose: EmailTemplatePurpose.PASSWORD_RECOVERY,
118
118
  bindings: [
119
119
  {
120
- name: InternalTemplateBindings.RESET_URL,
120
+ name: InternalTemplateBinding.RESET_URL,
121
121
  description:
122
122
  "The URL the recipient must click to reset their password.",
123
123
  },
124
124
  {
125
- name: InternalTemplateBindings.RESET_CODE,
125
+ name: InternalTemplateBinding.RESET_CODE,
126
126
  description:
127
127
  "The temporary password reset code used in the recipients password reset URL.",
128
128
  },
@@ -144,12 +144,12 @@ const TemplateMetadata = {
144
144
  purpose: EmailTemplatePurpose.INVITATION,
145
145
  bindings: [
146
146
  {
147
- name: InternalTemplateBindings.INVITE_URL,
147
+ name: InternalTemplateBinding.INVITE_URL,
148
148
  description:
149
149
  "The URL the recipient must click to accept the invitation and activate their account.",
150
150
  },
151
151
  {
152
- name: InternalTemplateBindings.INVITE_CODE,
152
+ name: InternalTemplateBinding.INVITE_CODE,
153
153
  description:
154
154
  "The temporary invite code used in the recipients invitation URL.",
155
155
  },
@@ -163,7 +163,7 @@ const TemplateMetadata = {
163
163
  purpose: EmailTemplatePurpose.CUSTOM,
164
164
  bindings: [
165
165
  {
166
- name: InternalTemplateBindings.CONTENTS,
166
+ name: InternalTemplateBinding.CONTENTS,
167
167
  description: "Custom content body.",
168
168
  },
169
169
  ],
@@ -172,12 +172,5 @@ const TemplateMetadata = {
172
172
  }
173
173
 
174
174
  // all purpose combined
175
- exports.TemplatePurpose = {
176
- ...EmailTemplatePurpose,
177
- }
178
- exports.TemplateTypes = TemplateTypes
179
- exports.EmailTemplatePurpose = EmailTemplatePurpose
180
- exports.TemplateMetadata = TemplateMetadata
181
- exports.TemplateBindings = TemplateBindings
182
- exports.InternalTemplateBindings = InternalTemplateBindings
183
- exports.GLOBAL_OWNER = "global"
175
+ export { EmailTemplatePurpose as TemplatePurpose }
176
+ export const GLOBAL_OWNER = "global"
@@ -1,15 +1,15 @@
1
- const { readStaticFile } = require("../../utilities/fileSystem")
2
- const {
1
+ import { readStaticFile } from "../../utilities/fileSystem"
2
+ import {
3
3
  EmailTemplatePurpose,
4
- TemplateTypes,
4
+ TemplateType,
5
5
  TemplatePurpose,
6
6
  GLOBAL_OWNER,
7
- } = require("../index")
8
- const { join } = require("path")
9
- const { getTemplateParams } = require("@budibase/backend-core/db")
10
- const { getGlobalDB } = require("@budibase/backend-core/tenancy")
7
+ } from "../index"
8
+ import { join } from "path"
9
+ import { db as dbCore, tenancy } from "@budibase/backend-core"
10
+ import { Template } from "@budibase/types"
11
11
 
12
- exports.EmailTemplates = {
12
+ export const EmailTemplates = {
13
13
  [EmailTemplatePurpose.PASSWORD_RECOVERY]: readStaticFile(
14
14
  join(__dirname, "passwordRecovery.hbs")
15
15
  ),
@@ -23,10 +23,10 @@ exports.EmailTemplates = {
23
23
  [EmailTemplatePurpose.CUSTOM]: readStaticFile(join(__dirname, "custom.hbs")),
24
24
  }
25
25
 
26
- exports.addBaseTemplates = (templates, type = null) => {
26
+ export function addBaseTemplates(templates: Template[], type?: string) {
27
27
  let purposeList
28
28
  switch (type) {
29
- case TemplateTypes.EMAIL:
29
+ case TemplateType.EMAIL:
30
30
  purposeList = Object.values(EmailTemplatePurpose)
31
31
  break
32
32
  default:
@@ -38,9 +38,9 @@ exports.addBaseTemplates = (templates, type = null) => {
38
38
  if (templates.find(template => template.purpose === purpose)) {
39
39
  continue
40
40
  }
41
- if (exports.EmailTemplates[purpose]) {
41
+ if (EmailTemplates[purpose]) {
42
42
  templates.push({
43
- contents: exports.EmailTemplates[purpose],
43
+ contents: EmailTemplates[purpose],
44
44
  purpose,
45
45
  type,
46
46
  })
@@ -49,10 +49,14 @@ exports.addBaseTemplates = (templates, type = null) => {
49
49
  return templates
50
50
  }
51
51
 
52
- exports.getTemplates = async ({ ownerId, type, id } = {}) => {
53
- const db = getGlobalDB()
52
+ export async function getTemplates({
53
+ ownerId,
54
+ type,
55
+ id,
56
+ }: { ownerId?: string; type?: string; id?: string } = {}) {
57
+ const db = tenancy.getGlobalDB()
54
58
  const response = await db.allDocs(
55
- getTemplateParams(ownerId || GLOBAL_OWNER, id, {
59
+ dbCore.getTemplateParams(ownerId || GLOBAL_OWNER, id, {
56
60
  include_docs: true,
57
61
  })
58
62
  )
@@ -64,10 +68,10 @@ exports.getTemplates = async ({ ownerId, type, id } = {}) => {
64
68
  if (type) {
65
69
  templates = templates.filter(template => template.type === type)
66
70
  }
67
- return exports.addBaseTemplates(templates, type)
71
+ return addBaseTemplates(templates, type)
68
72
  }
69
73
 
70
- exports.getTemplateByPurpose = async (type, purpose) => {
71
- const templates = await exports.getTemplates({ type })
72
- return templates.find(template => template.purpose === purpose)
74
+ export async function getTemplateByPurpose(type: string, purpose: string) {
75
+ const templates = await getTemplates({ type })
76
+ return templates.find((template: Template) => template.purpose === purpose)
73
77
  }
@@ -0,0 +1,10 @@
1
+ import core from "@budibase/backend-core"
2
+ import env from "../environment"
3
+
4
+ export const init = () => {
5
+ const dbConfig: any = {}
6
+ if (env.isTest() && !env.COUCH_DB_URL) {
7
+ dbConfig.inMemory = true
8
+ }
9
+ core.init({ db: dbConfig })
10
+ }
@@ -26,7 +26,7 @@ function parseIntSafe(number: any) {
26
26
  }
27
27
  }
28
28
 
29
- const env = {
29
+ const environment = {
30
30
  // auth
31
31
  MINIO_ACCESS_KEY: process.env.MINIO_ACCESS_KEY,
32
32
  MINIO_SECRET_KEY: process.env.MINIO_SECRET_KEY,
@@ -68,7 +68,7 @@ const env = {
68
68
  _set(key: any, value: any) {
69
69
  process.env[key] = value
70
70
  // @ts-ignore
71
- env[key] = value
71
+ environment[key] = value
72
72
  },
73
73
  isDev,
74
74
  isTest,
@@ -78,17 +78,19 @@ const env = {
78
78
  }
79
79
 
80
80
  // if some var haven't been set, define them
81
- if (!env.APPS_URL) {
82
- env.APPS_URL = isDev() ? "http://localhost:4001" : "http://app-service:4002"
81
+ if (!environment.APPS_URL) {
82
+ environment.APPS_URL = isDev()
83
+ ? "http://localhost:4001"
84
+ : "http://app-service:4002"
83
85
  }
84
86
 
85
87
  // clean up any environment variable edge cases
86
- for (let [key, value] of Object.entries(env)) {
88
+ for (let [key, value] of Object.entries(environment)) {
87
89
  // handle the edge case of "0" to disable an environment variable
88
90
  if (value === "0") {
89
91
  // @ts-ignore
90
- env[key] = 0
92
+ environment[key] = 0
91
93
  }
92
94
  }
93
95
 
94
- export = env
96
+ export = environment