@budibase/worker 2.1.43-alpha.6 → 2.1.44

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/package.json +24 -14
  2. package/{src/tests/jestSetup.ts → scripts/jestSetup.js} +3 -12
  3. package/scripts/localdomain.js +7 -33
  4. package/src/api/controllers/global/auth.ts +43 -51
  5. package/src/api/controllers/global/{configs.ts → configs.js} +114 -119
  6. package/src/api/controllers/global/{email.ts → email.js} +5 -6
  7. package/src/api/controllers/global/roles.js +68 -0
  8. package/src/api/controllers/global/self.ts +2 -2
  9. package/src/api/controllers/global/users.ts +2 -4
  10. package/src/api/controllers/global/{workspaces.ts → workspaces.js} +18 -15
  11. package/src/api/controllers/system/{environment.ts → environment.js} +2 -3
  12. package/src/api/controllers/system/restore.ts +1 -1
  13. package/src/api/controllers/system/{status.ts → status.js} +3 -4
  14. package/src/api/controllers/system/tenants.ts +51 -8
  15. package/src/api/index.ts +8 -31
  16. package/src/api/routes/global/{auth.ts → auth.js} +48 -31
  17. package/src/api/routes/global/{configs.ts → configs.js} +23 -22
  18. package/src/api/routes/global/{email.ts → email.js} +10 -9
  19. package/src/api/routes/global/license.ts +1 -1
  20. package/src/api/routes/global/roles.js +12 -0
  21. package/src/api/routes/global/self.ts +2 -2
  22. package/src/api/routes/global/templates.ts +4 -4
  23. package/src/api/routes/global/tests/auth.spec.ts +64 -134
  24. package/src/api/routes/global/tests/configs.spec.ts +35 -34
  25. package/src/api/routes/global/tests/email.spec.ts +3 -4
  26. package/src/api/routes/global/tests/realEmail.spec.ts +3 -2
  27. package/src/api/routes/global/tests/self.spec.ts +4 -3
  28. package/src/api/routes/global/tests/users.spec.ts +45 -61
  29. package/src/api/routes/global/{users.ts → users.js} +26 -28
  30. package/src/api/routes/global/{workspaces.ts → workspaces.js} +10 -9
  31. package/src/api/routes/index.ts +1 -2
  32. package/src/api/routes/system/accounts.ts +1 -1
  33. package/src/api/routes/system/environment.js +8 -0
  34. package/src/api/routes/system/migrations.ts +1 -1
  35. package/src/api/routes/system/restore.ts +1 -1
  36. package/src/api/routes/system/status.js +8 -0
  37. package/src/api/routes/system/tenants.js +12 -0
  38. package/src/api/routes/system/tests/accounts.spec.ts +6 -5
  39. package/src/api/routes/validation/users.ts +3 -3
  40. package/src/constants/{index.ts → index.js} +64 -57
  41. package/src/constants/templates/{index.ts → index.js} +19 -23
  42. package/src/db/index.js +11 -0
  43. package/src/environment.ts +7 -9
  44. package/src/index.ts +16 -15
  45. package/src/middleware/{cloudRestricted.ts → cloudRestricted.js} +4 -5
  46. package/src/tests/TestConfiguration.ts +50 -99
  47. package/src/tests/api/accounts.ts +8 -5
  48. package/src/tests/api/auth.ts +6 -3
  49. package/src/tests/api/configs.ts +8 -15
  50. package/src/tests/api/email.ts +6 -3
  51. package/src/tests/api/index.ts +0 -15
  52. package/src/tests/api/self.ts +6 -11
  53. package/src/tests/api/users.ts +6 -38
  54. package/src/tests/controllers.js +7 -0
  55. package/src/tests/index.ts +1 -5
  56. package/src/tests/structures/accounts.ts +24 -0
  57. package/src/tests/structures/{configs.ts → configs.js} +11 -11
  58. package/src/tests/structures/index.ts +3 -5
  59. package/src/tests/structures/users.ts +0 -1
  60. package/src/utilities/appService.js +33 -0
  61. package/src/utilities/{email.ts → email.js} +45 -78
  62. package/src/utilities/fileSystem.js +5 -0
  63. package/src/utilities/{index.ts → index.js} +1 -1
  64. package/src/utilities/{redis.ts → redis.js} +24 -29
  65. package/src/utilities/templates.js +49 -0
  66. package/src/utilities/users.js +17 -0
  67. package/tsconfig.build.json +3 -2
  68. package/tsconfig.json +1 -3
  69. package/__mocks__/aws-sdk.ts +0 -15
  70. package/__mocks__/oauth.ts +0 -57
  71. package/coverage/clover.xml +0 -2157
  72. package/coverage/coverage-final.json +0 -78
  73. package/coverage/lcov-report/base.css +0 -224
  74. package/coverage/lcov-report/block-navigation.js +0 -87
  75. package/coverage/lcov-report/favicon.png +0 -0
  76. package/coverage/lcov-report/index.html +0 -431
  77. package/coverage/lcov-report/prettify.css +0 -1
  78. package/coverage/lcov-report/prettify.js +0 -2
  79. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  80. package/coverage/lcov-report/sorter.js +0 -196
  81. package/coverage/lcov-report/src/api/controllers/global/auth.ts.html +0 -925
  82. package/coverage/lcov-report/src/api/controllers/global/configs.ts.html +0 -1405
  83. package/coverage/lcov-report/src/api/controllers/global/email.ts.html +0 -196
  84. package/coverage/lcov-report/src/api/controllers/global/index.html +0 -236
  85. package/coverage/lcov-report/src/api/controllers/global/license.ts.html +0 -187
  86. package/coverage/lcov-report/src/api/controllers/global/roles.ts.html +0 -283
  87. package/coverage/lcov-report/src/api/controllers/global/self.ts.html +0 -577
  88. package/coverage/lcov-report/src/api/controllers/global/templates.ts.html +0 -316
  89. package/coverage/lcov-report/src/api/controllers/global/users.ts.html +0 -796
  90. package/coverage/lcov-report/src/api/controllers/global/workspaces.ts.html +0 -244
  91. package/coverage/lcov-report/src/api/controllers/system/accounts.ts.html +0 -148
  92. package/coverage/lcov-report/src/api/controllers/system/environment.ts.html +0 -124
  93. package/coverage/lcov-report/src/api/controllers/system/index.html +0 -191
  94. package/coverage/lcov-report/src/api/controllers/system/migrations.ts.html +0 -124
  95. package/coverage/lcov-report/src/api/controllers/system/restore.ts.html +0 -124
  96. package/coverage/lcov-report/src/api/controllers/system/status.ts.html +0 -133
  97. package/coverage/lcov-report/src/api/controllers/system/tenants.ts.html +0 -154
  98. package/coverage/lcov-report/src/api/index.html +0 -116
  99. package/coverage/lcov-report/src/api/index.ts.html +0 -583
  100. package/coverage/lcov-report/src/api/routes/global/auth.ts.html +0 -349
  101. package/coverage/lcov-report/src/api/routes/global/configs.ts.html +0 -457
  102. package/coverage/lcov-report/src/api/routes/global/email.ts.html +0 -193
  103. package/coverage/lcov-report/src/api/routes/global/index.html +0 -236
  104. package/coverage/lcov-report/src/api/routes/global/license.ts.html +0 -124
  105. package/coverage/lcov-report/src/api/routes/global/roles.ts.html +0 -133
  106. package/coverage/lcov-report/src/api/routes/global/self.ts.html +0 -139
  107. package/coverage/lcov-report/src/api/routes/global/templates.ts.html +0 -196
  108. package/coverage/lcov-report/src/api/routes/global/users.ts.html +0 -433
  109. package/coverage/lcov-report/src/api/routes/global/workspaces.ts.html +0 -196
  110. package/coverage/lcov-report/src/api/routes/index.html +0 -116
  111. package/coverage/lcov-report/src/api/routes/index.ts.html +0 -196
  112. package/coverage/lcov-report/src/api/routes/system/accounts.ts.html +0 -142
  113. package/coverage/lcov-report/src/api/routes/system/environment.ts.html +0 -109
  114. package/coverage/lcov-report/src/api/routes/system/index.html +0 -191
  115. package/coverage/lcov-report/src/api/routes/system/migrations.ts.html +0 -142
  116. package/coverage/lcov-report/src/api/routes/system/restore.ts.html +0 -109
  117. package/coverage/lcov-report/src/api/routes/system/status.ts.html +0 -109
  118. package/coverage/lcov-report/src/api/routes/system/tenants.ts.html +0 -124
  119. package/coverage/lcov-report/src/api/routes/validation/index.html +0 -131
  120. package/coverage/lcov-report/src/api/routes/validation/index.ts.html +0 -88
  121. package/coverage/lcov-report/src/api/routes/validation/users.ts.html +0 -235
  122. package/coverage/lcov-report/src/constants/index.html +0 -116
  123. package/coverage/lcov-report/src/constants/index.ts.html +0 -613
  124. package/coverage/lcov-report/src/constants/templates/index.html +0 -116
  125. package/coverage/lcov-report/src/constants/templates/index.ts.html +0 -316
  126. package/coverage/lcov-report/src/db/index.html +0 -116
  127. package/coverage/lcov-report/src/db/index.ts.html +0 -115
  128. package/coverage/lcov-report/src/environment.ts.html +0 -373
  129. package/coverage/lcov-report/src/index.html +0 -131
  130. package/coverage/lcov-report/src/index.ts.html +0 -394
  131. package/coverage/lcov-report/src/middleware/cloudRestricted.ts.html +0 -139
  132. package/coverage/lcov-report/src/middleware/index.html +0 -116
  133. package/coverage/lcov-report/src/migrations/functions/globalInfoSyncUsers.ts.html +0 -145
  134. package/coverage/lcov-report/src/migrations/functions/index.html +0 -116
  135. package/coverage/lcov-report/src/migrations/index.html +0 -116
  136. package/coverage/lcov-report/src/migrations/index.ts.html +0 -271
  137. package/coverage/lcov-report/src/sdk/accounts/accounts.ts.html +0 -262
  138. package/coverage/lcov-report/src/sdk/accounts/index.html +0 -131
  139. package/coverage/lcov-report/src/sdk/accounts/index.ts.html +0 -88
  140. package/coverage/lcov-report/src/sdk/index.html +0 -116
  141. package/coverage/lcov-report/src/sdk/index.ts.html +0 -106
  142. package/coverage/lcov-report/src/sdk/users/events.ts.html +0 -577
  143. package/coverage/lcov-report/src/sdk/users/index.html +0 -146
  144. package/coverage/lcov-report/src/sdk/users/index.ts.html +0 -88
  145. package/coverage/lcov-report/src/sdk/users/users.ts.html +0 -1903
  146. package/coverage/lcov-report/src/tests/TestConfiguration.ts.html +0 -1051
  147. package/coverage/lcov-report/src/tests/api/accounts.ts.html +0 -160
  148. package/coverage/lcov-report/src/tests/api/auth.ts.html +0 -220
  149. package/coverage/lcov-report/src/tests/api/base.ts.html +0 -133
  150. package/coverage/lcov-report/src/tests/api/configs.ts.html +0 -226
  151. package/coverage/lcov-report/src/tests/api/email.ts.html +0 -148
  152. package/coverage/lcov-report/src/tests/api/environment.ts.html +0 -130
  153. package/coverage/lcov-report/src/tests/api/index.html +0 -296
  154. package/coverage/lcov-report/src/tests/api/index.ts.html +0 -205
  155. package/coverage/lcov-report/src/tests/api/migrations.ts.html +0 -151
  156. package/coverage/lcov-report/src/tests/api/restore.ts.html +0 -127
  157. package/coverage/lcov-report/src/tests/api/self.ts.html +0 -163
  158. package/coverage/lcov-report/src/tests/api/status.ts.html +0 -121
  159. package/coverage/lcov-report/src/tests/api/tenants.ts.html +0 -130
  160. package/coverage/lcov-report/src/tests/api/users.ts.html +0 -511
  161. package/coverage/lcov-report/src/tests/controllers.ts.html +0 -100
  162. package/coverage/lcov-report/src/tests/index.html +0 -146
  163. package/coverage/lcov-report/src/tests/index.ts.html +0 -139
  164. package/coverage/lcov-report/src/tests/mocks/email.js.html +0 -115
  165. package/coverage/lcov-report/src/tests/mocks/index.html +0 -131
  166. package/coverage/lcov-report/src/tests/mocks/index.ts.html +0 -106
  167. package/coverage/lcov-report/src/tests/structures/configs.ts.html +0 -313
  168. package/coverage/lcov-report/src/tests/structures/groups.ts.html +0 -118
  169. package/coverage/lcov-report/src/tests/structures/index.html +0 -161
  170. package/coverage/lcov-report/src/tests/structures/index.ts.html +0 -151
  171. package/coverage/lcov-report/src/tests/structures/users.ts.html +0 -196
  172. package/coverage/lcov-report/src/utilities/appService.ts.html +0 -181
  173. package/coverage/lcov-report/src/utilities/email.ts.html +0 -850
  174. package/coverage/lcov-report/src/utilities/fileSystem.ts.html +0 -100
  175. package/coverage/lcov-report/src/utilities/index.html +0 -206
  176. package/coverage/lcov-report/src/utilities/index.ts.html +0 -112
  177. package/coverage/lcov-report/src/utilities/redis.ts.html +0 -424
  178. package/coverage/lcov-report/src/utilities/templates.ts.html +0 -232
  179. package/coverage/lcov-report/src/utilities/users.ts.html +0 -133
  180. package/coverage/lcov.info +0 -3970
  181. package/jest.config.ts +0 -29
  182. package/src/api/controllers/global/roles.ts +0 -66
  183. package/src/api/routes/global/roles.ts +0 -16
  184. package/src/api/routes/global/tests/license.spec.ts +0 -31
  185. package/src/api/routes/global/tests/roles.spec.ts +0 -27
  186. package/src/api/routes/global/tests/templates.spec.ts +0 -35
  187. package/src/api/routes/global/tests/workspaces.spec.ts +0 -29
  188. package/src/api/routes/system/environment.ts +0 -8
  189. package/src/api/routes/system/status.ts +0 -8
  190. package/src/api/routes/system/tenants.ts +0 -13
  191. package/src/api/routes/system/tests/environment.spec.ts +0 -29
  192. package/src/api/routes/system/tests/migrations.spec.ts +0 -63
  193. package/src/api/routes/system/tests/restore.spec.ts +0 -36
  194. package/src/api/routes/system/tests/status.spec.ts +0 -48
  195. package/src/api/routes/system/tests/tenants.spec.ts +0 -61
  196. package/src/db/index.ts +0 -10
  197. package/src/middleware/tests/tenancy.spec.ts +0 -73
  198. package/src/tests/api/base.ts +0 -16
  199. package/src/tests/api/environment.ts +0 -15
  200. package/src/tests/api/migrations.ts +0 -22
  201. package/src/tests/api/restore.ts +0 -14
  202. package/src/tests/api/status.ts +0 -12
  203. package/src/tests/api/tenants.ts +0 -15
  204. package/src/tests/controllers.ts +0 -5
  205. package/src/utilities/appService.ts +0 -32
  206. package/src/utilities/fileSystem.ts +0 -5
  207. package/src/utilities/templates.ts +0 -49
  208. package/src/utilities/users.ts +0 -16
@@ -1,4 +1,4 @@
1
- import { auth } from "@budibase/backend-core"
1
+ const { joiValidator } = require("@budibase/backend-core/auth")
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 auth.joiValidator.body(Joi.object(schema).required().unknown(true))
28
+ return 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 auth.joiValidator.body(Joi.object(bulkSchema).required().unknown(true))
49
+ return joiValidator.body(Joi.object(bulkSchema).required().unknown(true))
50
50
  }
@@ -1,97 +1,97 @@
1
- import { constants } from "@budibase/backend-core"
1
+ const { Configs } = require("@budibase/backend-core/constants")
2
2
 
3
- export const LOGO_URL =
3
+ exports.LOGO_URL =
4
4
  "https://d33wubrfki0l68.cloudfront.net/aac32159d7207b5085e74a7ef67afbb7027786c5/2b1fd/img/logo/bb-emblem.svg"
5
5
 
6
- export enum UserStatus {
7
- ACTIVE = "active",
8
- INACTIVE = "inactive",
6
+ exports.UserStatus = {
7
+ ACTIVE: "active",
8
+ INACTIVE: "inactive",
9
9
  }
10
10
 
11
- export const Config = constants.Config
11
+ exports.Configs = Configs
12
12
 
13
- export enum ConfigUpload {
14
- LOGO = "logo",
15
- OIDC_LOGO = "oidc_logo",
13
+ exports.ConfigUploads = {
14
+ LOGO: "logo",
15
+ OIDC_LOGO: "oidc_logo",
16
16
  }
17
17
 
18
- export enum TemplateType {
19
- EMAIL = "email",
18
+ const TemplateTypes = {
19
+ EMAIL: "email",
20
20
  }
21
21
 
22
- export enum EmailTemplatePurpose {
23
- BASE = "base",
24
- PASSWORD_RECOVERY = "password_recovery",
25
- INVITATION = "invitation",
26
- WELCOME = "welcome",
27
- CUSTOM = "custom",
22
+ const EmailTemplatePurpose = {
23
+ BASE: "base",
24
+ PASSWORD_RECOVERY: "password_recovery",
25
+ INVITATION: "invitation",
26
+ WELCOME: "welcome",
27
+ CUSTOM: "custom",
28
28
  }
29
29
 
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",
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",
48
48
  }
49
49
 
50
- export const TemplateBindings = {
50
+ const TemplateBindings = {
51
51
  PLATFORM_URL: {
52
- name: InternalTemplateBinding.PLATFORM_URL,
52
+ name: InternalTemplateBindings.PLATFORM_URL,
53
53
  description: "The URL used to access the budibase platform",
54
54
  },
55
55
  COMPANY: {
56
- name: InternalTemplateBinding.COMPANY,
56
+ name: InternalTemplateBindings.COMPANY,
57
57
  description: "The name of your organization",
58
58
  },
59
59
  LOGO_URL: {
60
- name: InternalTemplateBinding.LOGO_URL,
60
+ name: InternalTemplateBindings.LOGO_URL,
61
61
  description: "The URL of your organizations logo.",
62
62
  },
63
63
  EMAIL: {
64
- name: InternalTemplateBinding.EMAIL,
64
+ name: InternalTemplateBindings.EMAIL,
65
65
  description: "The recipients email address.",
66
66
  },
67
67
  USER: {
68
- name: InternalTemplateBinding.USER,
68
+ name: InternalTemplateBindings.USER,
69
69
  description: "The recipients user object.",
70
70
  },
71
71
  REQUEST: {
72
- name: InternalTemplateBinding.REQUEST,
72
+ name: InternalTemplateBindings.REQUEST,
73
73
  description: "Additional request metadata.",
74
74
  },
75
75
  DOCS_URL: {
76
- name: InternalTemplateBinding.DOCS_URL,
76
+ name: InternalTemplateBindings.DOCS_URL,
77
77
  description: "Organization documentation URL.",
78
78
  },
79
79
  LOGIN_URL: {
80
- name: InternalTemplateBinding.LOGIN_URL,
80
+ name: InternalTemplateBindings.LOGIN_URL,
81
81
  description: "The URL used to log into the organization budibase instance.",
82
82
  },
83
83
  CURRENT_YEAR: {
84
- name: InternalTemplateBinding.CURRENT_YEAR,
84
+ name: InternalTemplateBindings.CURRENT_YEAR,
85
85
  description: "The current year.",
86
86
  },
87
87
  CURRENT_DATE: {
88
- name: InternalTemplateBinding.CURRENT_DATE,
88
+ name: InternalTemplateBindings.CURRENT_DATE,
89
89
  description: "The current date.",
90
90
  },
91
91
  }
92
92
 
93
- export const TemplateMetadata = {
94
- [TemplateType.EMAIL]: [
93
+ const TemplateMetadata = {
94
+ [TemplateTypes.EMAIL]: [
95
95
  {
96
96
  name: "Base format",
97
97
  description:
@@ -100,11 +100,11 @@ export const TemplateMetadata = {
100
100
  purpose: EmailTemplatePurpose.BASE,
101
101
  bindings: [
102
102
  {
103
- name: InternalTemplateBinding.BODY,
103
+ name: InternalTemplateBindings.BODY,
104
104
  description: "The main body of another email template.",
105
105
  },
106
106
  {
107
- name: InternalTemplateBinding.STYLES,
107
+ name: InternalTemplateBindings.STYLES,
108
108
  description: "The contents of the Styling email template.",
109
109
  },
110
110
  ],
@@ -117,12 +117,12 @@ export const TemplateMetadata = {
117
117
  purpose: EmailTemplatePurpose.PASSWORD_RECOVERY,
118
118
  bindings: [
119
119
  {
120
- name: InternalTemplateBinding.RESET_URL,
120
+ name: InternalTemplateBindings.RESET_URL,
121
121
  description:
122
122
  "The URL the recipient must click to reset their password.",
123
123
  },
124
124
  {
125
- name: InternalTemplateBinding.RESET_CODE,
125
+ name: InternalTemplateBindings.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 @@ export const TemplateMetadata = {
144
144
  purpose: EmailTemplatePurpose.INVITATION,
145
145
  bindings: [
146
146
  {
147
- name: InternalTemplateBinding.INVITE_URL,
147
+ name: InternalTemplateBindings.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: InternalTemplateBinding.INVITE_CODE,
152
+ name: InternalTemplateBindings.INVITE_CODE,
153
153
  description:
154
154
  "The temporary invite code used in the recipients invitation URL.",
155
155
  },
@@ -163,7 +163,7 @@ export const TemplateMetadata = {
163
163
  purpose: EmailTemplatePurpose.CUSTOM,
164
164
  bindings: [
165
165
  {
166
- name: InternalTemplateBinding.CONTENTS,
166
+ name: InternalTemplateBindings.CONTENTS,
167
167
  description: "Custom content body.",
168
168
  },
169
169
  ],
@@ -172,5 +172,12 @@ export const TemplateMetadata = {
172
172
  }
173
173
 
174
174
  // all purpose combined
175
- export { EmailTemplatePurpose as TemplatePurpose }
176
- export const GLOBAL_OWNER = "global"
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"
@@ -1,15 +1,15 @@
1
- import { readStaticFile } from "../../utilities/fileSystem"
2
- import {
1
+ const { readStaticFile } = require("../../utilities/fileSystem")
2
+ const {
3
3
  EmailTemplatePurpose,
4
- TemplateType,
4
+ TemplateTypes,
5
5
  TemplatePurpose,
6
6
  GLOBAL_OWNER,
7
- } from "../index"
8
- import { join } from "path"
9
- import { db as dbCore, tenancy } from "@budibase/backend-core"
10
- import { Template } from "@budibase/types"
7
+ } = require("../index")
8
+ const { join } = require("path")
9
+ const { getTemplateParams } = require("@budibase/backend-core/db")
10
+ const { getGlobalDB } = require("@budibase/backend-core/tenancy")
11
11
 
12
- export const EmailTemplates = {
12
+ exports.EmailTemplates = {
13
13
  [EmailTemplatePurpose.PASSWORD_RECOVERY]: readStaticFile(
14
14
  join(__dirname, "passwordRecovery.hbs")
15
15
  ),
@@ -23,10 +23,10 @@ export const EmailTemplates = {
23
23
  [EmailTemplatePurpose.CUSTOM]: readStaticFile(join(__dirname, "custom.hbs")),
24
24
  }
25
25
 
26
- export function addBaseTemplates(templates: Template[], type?: string) {
26
+ exports.addBaseTemplates = (templates, type = null) => {
27
27
  let purposeList
28
28
  switch (type) {
29
- case TemplateType.EMAIL:
29
+ case TemplateTypes.EMAIL:
30
30
  purposeList = Object.values(EmailTemplatePurpose)
31
31
  break
32
32
  default:
@@ -38,9 +38,9 @@ export function addBaseTemplates(templates: Template[], type?: string) {
38
38
  if (templates.find(template => template.purpose === purpose)) {
39
39
  continue
40
40
  }
41
- if (EmailTemplates[purpose]) {
41
+ if (exports.EmailTemplates[purpose]) {
42
42
  templates.push({
43
- contents: EmailTemplates[purpose],
43
+ contents: exports.EmailTemplates[purpose],
44
44
  purpose,
45
45
  type,
46
46
  })
@@ -49,14 +49,10 @@ export function addBaseTemplates(templates: Template[], type?: string) {
49
49
  return templates
50
50
  }
51
51
 
52
- export async function getTemplates({
53
- ownerId,
54
- type,
55
- id,
56
- }: { ownerId?: string; type?: string; id?: string } = {}) {
57
- const db = tenancy.getGlobalDB()
52
+ exports.getTemplates = async ({ ownerId, type, id } = {}) => {
53
+ const db = getGlobalDB()
58
54
  const response = await db.allDocs(
59
- dbCore.getTemplateParams(ownerId || GLOBAL_OWNER, id, {
55
+ getTemplateParams(ownerId || GLOBAL_OWNER, id, {
60
56
  include_docs: true,
61
57
  })
62
58
  )
@@ -68,10 +64,10 @@ export async function getTemplates({
68
64
  if (type) {
69
65
  templates = templates.filter(template => template.type === type)
70
66
  }
71
- return addBaseTemplates(templates, type)
67
+ return exports.addBaseTemplates(templates, type)
72
68
  }
73
69
 
74
- export async function getTemplateByPurpose(type: string, purpose: string) {
75
- const templates = await getTemplates({ type })
76
- return templates.find((template: Template) => template.purpose === purpose)
70
+ exports.getTemplateByPurpose = async (type, purpose) => {
71
+ const templates = await exports.getTemplates({ type })
72
+ return templates.find(template => template.purpose === purpose)
77
73
  }
@@ -0,0 +1,11 @@
1
+ const core = require("@budibase/backend-core")
2
+ const env = require("../environment")
3
+
4
+ exports.init = () => {
5
+ const dbConfig = {}
6
+ if (env.isTest() && !env.COUCH_DB_URL) {
7
+ dbConfig.inMemory = true
8
+ dbConfig.allDbs = true
9
+ }
10
+ core.init({ db: dbConfig })
11
+ }
@@ -26,7 +26,7 @@ function parseIntSafe(number: any) {
26
26
  }
27
27
  }
28
28
 
29
- const environment = {
29
+ const env = {
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 environment = {
68
68
  _set(key: any, value: any) {
69
69
  process.env[key] = value
70
70
  // @ts-ignore
71
- environment[key] = value
71
+ env[key] = value
72
72
  },
73
73
  isDev,
74
74
  isTest,
@@ -78,19 +78,17 @@ const environment = {
78
78
  }
79
79
 
80
80
  // if some var haven't been set, define them
81
- if (!environment.APPS_URL) {
82
- environment.APPS_URL = isDev()
83
- ? "http://localhost:4001"
84
- : "http://app-service:4002"
81
+ if (!env.APPS_URL) {
82
+ env.APPS_URL = isDev() ? "http://localhost:4001" : "http://app-service:4002"
85
83
  }
86
84
 
87
85
  // clean up any environment variable edge cases
88
- for (let [key, value] of Object.entries(environment)) {
86
+ for (let [key, value] of Object.entries(env)) {
89
87
  // handle the edge case of "0" to disable an environment variable
90
88
  if (value === "0") {
91
89
  // @ts-ignore
92
- environment[key] = 0
90
+ env[key] = 0
93
91
  }
94
92
  }
95
93
 
96
- export = environment
94
+ export = env
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  // need to load environment first
2
- import env from "./environment"
2
+ const env = require("./environment")
3
3
 
4
4
  // enable APM if configured
5
5
  if (process.env.ELASTIC_APM_ENABLED) {
@@ -13,18 +13,20 @@ 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 * as db from "./db"
17
- import { auth, logging, events, pinoSettings } from "@budibase/backend-core"
16
+ import db from "./db"
18
17
  db.init()
19
- import Koa from "koa"
20
- import koaBody from "koa-body"
21
- import http from "http"
22
- import api from "./api"
23
- import * as redis from "./utilities/redis"
24
- const Sentry = require("@sentry/node")
18
+ const Koa = require("koa")
19
+ const destroyable = require("server-destroy")
20
+ const koaBody = require("koa-body")
25
21
  const koaSession = require("koa-session")
22
+ const { passport } = require("@budibase/backend-core/auth")
23
+ const { logAlert } = require("@budibase/backend-core/logging")
26
24
  const logger = require("koa-pino-logger")
27
- const destroyable = require("server-destroy")
25
+ const http = require("http")
26
+ const api = require("./api")
27
+ const redis = require("./utilities/redis")
28
+ const Sentry = require("@sentry/node")
29
+ import { events, pinoSettings } from "@budibase/backend-core"
28
30
 
29
31
  // this will setup http and https proxies form env variables
30
32
  bootstrap()
@@ -39,8 +41,8 @@ app.use(koaSession(app))
39
41
  app.use(logger(pinoSettings()))
40
42
 
41
43
  // authentication
42
- app.use(auth.passport.initialize())
43
- app.use(auth.passport.session())
44
+ app.use(passport.initialize())
45
+ app.use(passport.session())
44
46
 
45
47
  // api routes
46
48
  app.use(api.routes())
@@ -79,18 +81,17 @@ server.on("close", async () => {
79
81
 
80
82
  const shutdown = () => {
81
83
  server.close()
82
- // @ts-ignore
83
84
  server.destroy()
84
85
  }
85
86
 
86
- export = server.listen(parseInt(env.PORT || "4002"), async () => {
87
+ export = server.listen(parseInt(env.PORT || 4002), async () => {
87
88
  console.log(`Worker running on ${JSON.stringify(server.address())}`)
88
89
  await redis.init()
89
90
  })
90
91
 
91
92
  process.on("uncaughtException", err => {
92
93
  errCode = -1
93
- logging.logAlert("Uncaught exception.", err)
94
+ logAlert("Uncaught exception.", err)
94
95
  shutdown()
95
96
  })
96
97
 
@@ -1,14 +1,13 @@
1
- import env from "../environment"
2
- import { constants } from "@budibase/backend-core"
3
- import { BBContext } from "@budibase/types"
1
+ const env = require("../environment")
2
+ const { Headers } = require("@budibase/backend-core/constants")
4
3
 
5
4
  /**
6
5
  * This is a restricted endpoint in the cloud.
7
6
  * Ensure that the correct API key has been supplied.
8
7
  */
9
- export = async (ctx: BBContext, next: any) => {
8
+ module.exports = async (ctx, next) => {
10
9
  if (!env.SELF_HOSTED && !env.DISABLE_ACCOUNT_PORTAL) {
11
- const apiKey = ctx.request.headers[constants.Header.API_KEY]
10
+ const apiKey = ctx.request.headers[Headers.API_KEY]
12
11
  if (apiKey !== env.INTERNAL_API_KEY) {
13
12
  ctx.throw(403, "Unauthorized")
14
13
  }