@budibase/worker 2.1.30 → 2.1.32-alpha.0

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 (182) hide show
  1. package/__mocks__/aws-sdk.ts +15 -0
  2. package/__mocks__/oauth.ts +57 -0
  3. package/coverage/clover.xml +2160 -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 +913 -0
  14. package/coverage/lcov-report/src/api/controllers/global/configs.js.html +1390 -0
  15. package/coverage/lcov-report/src/api/controllers/global/email.js.html +193 -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.js.html +289 -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.js.html +253 -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.js.html +349 -0
  33. package/coverage/lcov-report/src/api/routes/global/configs.js.html +460 -0
  34. package/coverage/lcov-report/src/api/routes/global/email.js.html +196 -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.js.html +121 -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.js.html +403 -0
  41. package/coverage/lcov-report/src/api/routes/global/workspaces.js.html +199 -0
  42. package/coverage/lcov-report/src/api/routes/index.html +116 -0
  43. package/coverage/lcov-report/src/api/routes/index.ts.html +193 -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.js.html +304 -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 +364 -0
  61. package/coverage/lcov-report/src/index.html +131 -0
  62. package/coverage/lcov-report/src/index.ts.html +397 -0
  63. package/coverage/lcov-report/src/middleware/cloudRestricted.js.html +136 -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.js.html +106 -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.js.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.js.html +184 -0
  105. package/coverage/lcov-report/src/utilities/email.ts.html +850 -0
  106. package/coverage/lcov-report/src/utilities/fileSystem.js.html +100 -0
  107. package/coverage/lcov-report/src/utilities/index.html +206 -0
  108. package/coverage/lcov-report/src/utilities/index.js.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.js.html +136 -0
  112. package/coverage/lcov.info +3986 -0
  113. package/jest.config.ts +29 -0
  114. package/package.json +13 -23
  115. package/scripts/localdomain.js +33 -7
  116. package/src/api/controllers/global/auth.ts +35 -31
  117. package/src/api/controllers/global/configs.js +17 -17
  118. package/src/api/controllers/global/self.ts +2 -2
  119. package/src/api/controllers/global/users.ts +3 -1
  120. package/src/api/controllers/system/{environment.js → environment.ts} +3 -2
  121. package/src/api/controllers/system/{status.js → status.ts} +4 -3
  122. package/src/api/controllers/system/tenants.ts +8 -51
  123. package/src/api/index.ts +29 -6
  124. package/src/api/routes/global/auth.js +22 -39
  125. package/src/api/routes/global/configs.js +9 -9
  126. package/src/api/routes/global/templates.ts +2 -2
  127. package/src/api/routes/global/tests/auth.spec.ts +134 -64
  128. package/src/api/routes/global/tests/configs.spec.ts +34 -35
  129. package/src/api/routes/global/tests/email.spec.ts +4 -3
  130. package/src/api/routes/global/tests/license.spec.ts +31 -0
  131. package/src/api/routes/global/tests/realEmail.spec.ts +2 -3
  132. package/src/api/routes/global/tests/roles.spec.ts +27 -0
  133. package/src/api/routes/global/tests/self.spec.ts +3 -4
  134. package/src/api/routes/global/tests/templates.spec.ts +35 -0
  135. package/src/api/routes/global/tests/users.spec.ts +51 -43
  136. package/src/api/routes/global/tests/workspaces.spec.ts +29 -0
  137. package/src/api/routes/system/environment.ts +8 -0
  138. package/src/api/routes/system/status.ts +8 -0
  139. package/src/api/routes/system/tenants.ts +13 -0
  140. package/src/api/routes/system/tests/accounts.spec.ts +5 -6
  141. package/src/api/routes/system/tests/environment.spec.ts +29 -0
  142. package/src/api/routes/system/tests/migrations.spec.ts +63 -0
  143. package/src/api/routes/system/tests/restore.spec.ts +36 -0
  144. package/src/api/routes/system/tests/status.spec.ts +48 -0
  145. package/src/api/routes/system/tests/tenants.spec.ts +61 -0
  146. package/src/constants/{index.js → index.ts} +57 -64
  147. package/src/constants/templates/index.js +2 -2
  148. package/src/db/index.ts +10 -0
  149. package/src/index.ts +1 -1
  150. package/src/middleware/cloudRestricted.js +2 -2
  151. package/src/middleware/tests/tenancy.spec.ts +73 -0
  152. package/src/tests/TestConfiguration.ts +98 -49
  153. package/src/tests/api/accounts.ts +5 -8
  154. package/src/tests/api/auth.ts +3 -6
  155. package/src/tests/api/base.ts +16 -0
  156. package/src/tests/api/configs.ts +15 -8
  157. package/src/tests/api/email.ts +3 -6
  158. package/src/tests/api/environment.ts +15 -0
  159. package/src/tests/api/index.ts +15 -0
  160. package/src/tests/api/migrations.ts +22 -0
  161. package/src/tests/api/restore.ts +14 -0
  162. package/src/tests/api/self.ts +11 -6
  163. package/src/tests/api/status.ts +12 -0
  164. package/src/tests/api/tenants.ts +15 -0
  165. package/src/tests/api/users.ts +38 -6
  166. package/src/tests/index.ts +5 -1
  167. package/{scripts/jestSetup.js → src/tests/jestSetup.ts} +12 -3
  168. package/src/tests/structures/configs.js +6 -6
  169. package/src/tests/structures/index.ts +4 -2
  170. package/src/tests/structures/users.ts +1 -0
  171. package/src/utilities/appService.js +3 -3
  172. package/src/utilities/{email.js → email.ts} +78 -45
  173. package/src/utilities/{redis.js → redis.ts} +29 -24
  174. package/src/utilities/templates.ts +49 -0
  175. package/tsconfig.build.json +2 -2
  176. package/tsconfig.json +3 -1
  177. package/src/api/routes/system/environment.js +0 -8
  178. package/src/api/routes/system/status.js +0 -8
  179. package/src/api/routes/system/tenants.js +0 -12
  180. package/src/db/index.js +0 -11
  181. package/src/tests/structures/accounts.ts +0 -24
  182. package/src/utilities/templates.js +0 -49
@@ -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,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,7 +1,7 @@
1
1
  const { readStaticFile } = require("../../utilities/fileSystem")
2
2
  const {
3
3
  EmailTemplatePurpose,
4
- TemplateTypes,
4
+ TemplateType,
5
5
  TemplatePurpose,
6
6
  GLOBAL_OWNER,
7
7
  } = require("../index")
@@ -26,7 +26,7 @@ exports.EmailTemplates = {
26
26
  exports.addBaseTemplates = (templates, type = null) => {
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:
@@ -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
+ }
package/src/index.ts CHANGED
@@ -13,7 +13,7 @@ import { Scope } from "@sentry/node"
13
13
  import { Event } from "@sentry/types/dist/event"
14
14
  import Application from "koa"
15
15
  import { bootstrap } from "global-agent"
16
- import db from "./db"
16
+ import * as db from "./db"
17
17
  db.init()
18
18
  const Koa = require("koa")
19
19
  const destroyable = require("server-destroy")
@@ -1,5 +1,5 @@
1
1
  const env = require("../environment")
2
- const { Headers } = require("@budibase/backend-core/constants")
2
+ const { Header } = require("@budibase/backend-core/constants")
3
3
 
4
4
  /**
5
5
  * This is a restricted endpoint in the cloud.
@@ -7,7 +7,7 @@ const { Headers } = require("@budibase/backend-core/constants")
7
7
  */
8
8
  module.exports = async (ctx, next) => {
9
9
  if (!env.SELF_HOSTED && !env.DISABLE_ACCOUNT_PORTAL) {
10
- const apiKey = ctx.request.headers[Headers.API_KEY]
10
+ const apiKey = ctx.request.headers[Header.API_KEY]
11
11
  if (apiKey !== env.INTERNAL_API_KEY) {
12
12
  ctx.throw(403, "Unauthorized")
13
13
  }
@@ -0,0 +1,73 @@
1
+ import { TestConfiguration, structures } from "../../tests"
2
+ import { constants } from "@budibase/backend-core"
3
+
4
+ describe("tenancy middleware", () => {
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
+ it("should get tenant id from user", async () => {
20
+ const user = await config.createTenant()
21
+ await config.createSession(user)
22
+ const res = await config.api.self.getSelf(user)
23
+ expect(res.headers[constants.Header.TENANT_ID]).toBe(user.tenantId)
24
+ })
25
+
26
+ it("should get tenant id from header", async () => {
27
+ const tenantId = structures.uuid()
28
+ const headers = {
29
+ [constants.Header.TENANT_ID]: tenantId,
30
+ }
31
+ const res = await config.request
32
+ .get(`/api/global/configs/checklist`)
33
+ .set(headers)
34
+ expect(res.headers[constants.Header.TENANT_ID]).toBe(tenantId)
35
+ })
36
+
37
+ it("should get tenant id from query param", async () => {
38
+ const tenantId = structures.uuid()
39
+ const res = await config.request.get(
40
+ `/api/global/configs/checklist?tenantId=${tenantId}`
41
+ )
42
+ expect(res.headers[constants.Header.TENANT_ID]).toBe(tenantId)
43
+ })
44
+
45
+ it("should get tenant id from subdomain", async () => {
46
+ const tenantId = structures.uuid()
47
+ const headers = {
48
+ host: `${tenantId}.localhost:10000`,
49
+ }
50
+ const res = await config.request
51
+ .get(`/api/global/configs/checklist`)
52
+ .set(headers)
53
+ expect(res.headers[constants.Header.TENANT_ID]).toBe(tenantId)
54
+ })
55
+
56
+ it("should get tenant id from path variable", async () => {
57
+ const user = await config.createTenant()
58
+ const res = await config.request
59
+ .post(`/api/global/auth/${user.tenantId}/login`)
60
+ .send({
61
+ username: user.email,
62
+ password: user.password,
63
+ })
64
+ expect(res.headers[constants.Header.TENANT_ID]).toBe(user.tenantId)
65
+ })
66
+
67
+ it("should throw when no tenant id is found", async () => {
68
+ const res = await config.request.get(`/api/global/configs/checklist`)
69
+ expect(res.status).toBe(403)
70
+ expect(res.text).toBe("Tenant id not set")
71
+ expect(res.headers[constants.Header.TENANT_ID]).toBe(undefined)
72
+ })
73
+ })