@budibase/worker 2.1.40-alpha.6 → 2.1.42
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.
- package/package.json +24 -14
- package/{src/tests/jestSetup.ts → scripts/jestSetup.js} +3 -12
- package/scripts/localdomain.js +7 -33
- package/src/api/controllers/global/auth.ts +43 -51
- package/src/api/controllers/global/{configs.ts → configs.js} +114 -119
- package/src/api/controllers/global/{email.ts → email.js} +5 -6
- package/src/api/controllers/global/roles.js +68 -0
- package/src/api/controllers/global/self.ts +2 -2
- package/src/api/controllers/global/users.ts +2 -4
- package/src/api/controllers/global/{workspaces.ts → workspaces.js} +18 -15
- package/src/api/controllers/system/{environment.ts → environment.js} +2 -3
- package/src/api/controllers/system/restore.ts +1 -1
- package/src/api/controllers/system/{status.ts → status.js} +3 -4
- package/src/api/controllers/system/tenants.ts +51 -8
- package/src/api/index.ts +8 -31
- package/src/api/routes/global/{auth.ts → auth.js} +48 -31
- package/src/api/routes/global/{configs.ts → configs.js} +23 -22
- package/src/api/routes/global/{email.ts → email.js} +10 -9
- package/src/api/routes/global/license.ts +1 -1
- package/src/api/routes/global/roles.js +12 -0
- package/src/api/routes/global/self.ts +2 -2
- package/src/api/routes/global/templates.ts +4 -4
- package/src/api/routes/global/tests/auth.spec.ts +64 -134
- package/src/api/routes/global/tests/configs.spec.ts +35 -34
- package/src/api/routes/global/tests/email.spec.ts +3 -4
- package/src/api/routes/global/tests/realEmail.spec.ts +3 -2
- package/src/api/routes/global/tests/self.spec.ts +4 -3
- package/src/api/routes/global/tests/users.spec.ts +59 -51
- package/src/api/routes/global/{users.ts → users.js} +32 -26
- package/src/api/routes/global/{workspaces.ts → workspaces.js} +10 -9
- package/src/api/routes/index.ts +1 -2
- package/src/api/routes/system/accounts.ts +1 -1
- package/src/api/routes/system/environment.js +8 -0
- package/src/api/routes/system/migrations.ts +1 -1
- package/src/api/routes/system/restore.ts +1 -1
- package/src/api/routes/system/status.js +8 -0
- package/src/api/routes/system/tenants.js +12 -0
- package/src/api/routes/system/tests/accounts.spec.ts +6 -5
- package/src/api/routes/validation/users.ts +3 -3
- package/src/constants/{index.ts → index.js} +64 -57
- package/src/constants/templates/{index.ts → index.js} +19 -23
- package/src/db/index.js +11 -0
- package/src/environment.ts +7 -9
- package/src/index.ts +16 -15
- package/src/middleware/{cloudRestricted.ts → cloudRestricted.js} +4 -5
- package/src/tests/TestConfiguration.ts +50 -99
- package/src/tests/api/accounts.ts +8 -5
- package/src/tests/api/auth.ts +6 -3
- package/src/tests/api/configs.ts +8 -15
- package/src/tests/api/email.ts +6 -3
- package/src/tests/api/index.ts +0 -15
- package/src/tests/api/self.ts +6 -11
- package/src/tests/api/users.ts +8 -40
- package/src/tests/controllers.js +7 -0
- package/src/tests/index.ts +1 -5
- package/src/tests/structures/accounts.ts +24 -0
- package/src/tests/structures/{configs.ts → configs.js} +11 -11
- package/src/tests/structures/index.ts +3 -5
- package/src/tests/structures/users.ts +0 -1
- package/src/utilities/appService.js +33 -0
- package/src/utilities/{email.ts → email.js} +45 -78
- package/src/utilities/fileSystem.js +5 -0
- package/src/utilities/{index.ts → index.js} +1 -1
- package/src/utilities/{redis.ts → redis.js} +24 -29
- package/src/utilities/templates.js +49 -0
- package/src/utilities/users.js +17 -0
- package/tsconfig.build.json +3 -2
- package/tsconfig.json +1 -3
- package/__mocks__/aws-sdk.ts +0 -15
- package/__mocks__/oauth.ts +0 -57
- package/coverage/clover.xml +0 -2153
- package/coverage/coverage-final.json +0 -78
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -431
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -196
- package/coverage/lcov-report/src/api/controllers/global/auth.ts.html +0 -925
- package/coverage/lcov-report/src/api/controllers/global/configs.ts.html +0 -1405
- package/coverage/lcov-report/src/api/controllers/global/email.ts.html +0 -196
- package/coverage/lcov-report/src/api/controllers/global/index.html +0 -236
- package/coverage/lcov-report/src/api/controllers/global/license.ts.html +0 -187
- package/coverage/lcov-report/src/api/controllers/global/roles.ts.html +0 -283
- package/coverage/lcov-report/src/api/controllers/global/self.ts.html +0 -577
- package/coverage/lcov-report/src/api/controllers/global/templates.ts.html +0 -316
- package/coverage/lcov-report/src/api/controllers/global/users.ts.html +0 -796
- package/coverage/lcov-report/src/api/controllers/global/workspaces.ts.html +0 -244
- package/coverage/lcov-report/src/api/controllers/system/accounts.ts.html +0 -148
- package/coverage/lcov-report/src/api/controllers/system/environment.ts.html +0 -124
- package/coverage/lcov-report/src/api/controllers/system/index.html +0 -191
- package/coverage/lcov-report/src/api/controllers/system/migrations.ts.html +0 -124
- package/coverage/lcov-report/src/api/controllers/system/restore.ts.html +0 -124
- package/coverage/lcov-report/src/api/controllers/system/status.ts.html +0 -133
- package/coverage/lcov-report/src/api/controllers/system/tenants.ts.html +0 -154
- package/coverage/lcov-report/src/api/index.html +0 -116
- package/coverage/lcov-report/src/api/index.ts.html +0 -583
- package/coverage/lcov-report/src/api/routes/global/auth.ts.html +0 -349
- package/coverage/lcov-report/src/api/routes/global/configs.ts.html +0 -457
- package/coverage/lcov-report/src/api/routes/global/email.ts.html +0 -193
- package/coverage/lcov-report/src/api/routes/global/index.html +0 -236
- package/coverage/lcov-report/src/api/routes/global/license.ts.html +0 -124
- package/coverage/lcov-report/src/api/routes/global/roles.ts.html +0 -133
- package/coverage/lcov-report/src/api/routes/global/self.ts.html +0 -139
- package/coverage/lcov-report/src/api/routes/global/templates.ts.html +0 -196
- package/coverage/lcov-report/src/api/routes/global/users.ts.html +0 -409
- package/coverage/lcov-report/src/api/routes/global/workspaces.ts.html +0 -196
- package/coverage/lcov-report/src/api/routes/index.html +0 -116
- package/coverage/lcov-report/src/api/routes/index.ts.html +0 -196
- package/coverage/lcov-report/src/api/routes/system/accounts.ts.html +0 -142
- package/coverage/lcov-report/src/api/routes/system/environment.ts.html +0 -109
- package/coverage/lcov-report/src/api/routes/system/index.html +0 -191
- package/coverage/lcov-report/src/api/routes/system/migrations.ts.html +0 -142
- package/coverage/lcov-report/src/api/routes/system/restore.ts.html +0 -109
- package/coverage/lcov-report/src/api/routes/system/status.ts.html +0 -109
- package/coverage/lcov-report/src/api/routes/system/tenants.ts.html +0 -124
- package/coverage/lcov-report/src/api/routes/validation/index.html +0 -131
- package/coverage/lcov-report/src/api/routes/validation/index.ts.html +0 -88
- package/coverage/lcov-report/src/api/routes/validation/users.ts.html +0 -235
- package/coverage/lcov-report/src/constants/index.html +0 -116
- package/coverage/lcov-report/src/constants/index.ts.html +0 -613
- package/coverage/lcov-report/src/constants/templates/index.html +0 -116
- package/coverage/lcov-report/src/constants/templates/index.ts.html +0 -316
- package/coverage/lcov-report/src/db/index.html +0 -116
- package/coverage/lcov-report/src/db/index.ts.html +0 -115
- package/coverage/lcov-report/src/environment.ts.html +0 -373
- package/coverage/lcov-report/src/index.html +0 -131
- package/coverage/lcov-report/src/index.ts.html +0 -394
- package/coverage/lcov-report/src/middleware/cloudRestricted.ts.html +0 -139
- package/coverage/lcov-report/src/middleware/index.html +0 -116
- package/coverage/lcov-report/src/migrations/functions/globalInfoSyncUsers.ts.html +0 -145
- package/coverage/lcov-report/src/migrations/functions/index.html +0 -116
- package/coverage/lcov-report/src/migrations/index.html +0 -116
- package/coverage/lcov-report/src/migrations/index.ts.html +0 -271
- package/coverage/lcov-report/src/sdk/accounts/accounts.ts.html +0 -262
- package/coverage/lcov-report/src/sdk/accounts/index.html +0 -131
- package/coverage/lcov-report/src/sdk/accounts/index.ts.html +0 -88
- package/coverage/lcov-report/src/sdk/index.html +0 -116
- package/coverage/lcov-report/src/sdk/index.ts.html +0 -106
- package/coverage/lcov-report/src/sdk/users/events.ts.html +0 -577
- package/coverage/lcov-report/src/sdk/users/index.html +0 -146
- package/coverage/lcov-report/src/sdk/users/index.ts.html +0 -88
- package/coverage/lcov-report/src/sdk/users/users.ts.html +0 -1903
- package/coverage/lcov-report/src/tests/TestConfiguration.ts.html +0 -1051
- package/coverage/lcov-report/src/tests/api/accounts.ts.html +0 -160
- package/coverage/lcov-report/src/tests/api/auth.ts.html +0 -220
- package/coverage/lcov-report/src/tests/api/base.ts.html +0 -133
- package/coverage/lcov-report/src/tests/api/configs.ts.html +0 -226
- package/coverage/lcov-report/src/tests/api/email.ts.html +0 -148
- package/coverage/lcov-report/src/tests/api/environment.ts.html +0 -130
- package/coverage/lcov-report/src/tests/api/index.html +0 -296
- package/coverage/lcov-report/src/tests/api/index.ts.html +0 -205
- package/coverage/lcov-report/src/tests/api/migrations.ts.html +0 -151
- package/coverage/lcov-report/src/tests/api/restore.ts.html +0 -127
- package/coverage/lcov-report/src/tests/api/self.ts.html +0 -163
- package/coverage/lcov-report/src/tests/api/status.ts.html +0 -121
- package/coverage/lcov-report/src/tests/api/tenants.ts.html +0 -130
- package/coverage/lcov-report/src/tests/api/users.ts.html +0 -511
- package/coverage/lcov-report/src/tests/controllers.ts.html +0 -100
- package/coverage/lcov-report/src/tests/index.html +0 -146
- package/coverage/lcov-report/src/tests/index.ts.html +0 -139
- package/coverage/lcov-report/src/tests/mocks/email.js.html +0 -115
- package/coverage/lcov-report/src/tests/mocks/index.html +0 -131
- package/coverage/lcov-report/src/tests/mocks/index.ts.html +0 -106
- package/coverage/lcov-report/src/tests/structures/configs.ts.html +0 -313
- package/coverage/lcov-report/src/tests/structures/groups.ts.html +0 -118
- package/coverage/lcov-report/src/tests/structures/index.html +0 -161
- package/coverage/lcov-report/src/tests/structures/index.ts.html +0 -151
- package/coverage/lcov-report/src/tests/structures/users.ts.html +0 -196
- package/coverage/lcov-report/src/utilities/appService.ts.html +0 -181
- package/coverage/lcov-report/src/utilities/email.ts.html +0 -850
- package/coverage/lcov-report/src/utilities/fileSystem.ts.html +0 -100
- package/coverage/lcov-report/src/utilities/index.html +0 -206
- package/coverage/lcov-report/src/utilities/index.ts.html +0 -112
- package/coverage/lcov-report/src/utilities/redis.ts.html +0 -424
- package/coverage/lcov-report/src/utilities/templates.ts.html +0 -232
- package/coverage/lcov-report/src/utilities/users.ts.html +0 -133
- package/coverage/lcov.info +0 -3958
- package/jest.config.ts +0 -29
- package/src/api/controllers/global/roles.ts +0 -66
- package/src/api/routes/global/roles.ts +0 -16
- package/src/api/routes/global/tests/license.spec.ts +0 -31
- package/src/api/routes/global/tests/roles.spec.ts +0 -27
- package/src/api/routes/global/tests/templates.spec.ts +0 -35
- package/src/api/routes/global/tests/workspaces.spec.ts +0 -29
- package/src/api/routes/system/environment.ts +0 -8
- package/src/api/routes/system/status.ts +0 -8
- package/src/api/routes/system/tenants.ts +0 -13
- package/src/api/routes/system/tests/environment.spec.ts +0 -29
- package/src/api/routes/system/tests/migrations.spec.ts +0 -63
- package/src/api/routes/system/tests/restore.spec.ts +0 -36
- package/src/api/routes/system/tests/status.spec.ts +0 -48
- package/src/api/routes/system/tests/tenants.spec.ts +0 -61
- package/src/db/index.ts +0 -10
- package/src/middleware/tests/tenancy.spec.ts +0 -73
- package/src/tests/api/base.ts +0 -16
- package/src/tests/api/environment.ts +0 -15
- package/src/tests/api/migrations.ts +0 -22
- package/src/tests/api/restore.ts +0 -14
- package/src/tests/api/status.ts +0 -12
- package/src/tests/api/tenants.ts +0 -15
- package/src/tests/controllers.ts +0 -5
- package/src/utilities/appService.ts +0 -32
- package/src/utilities/fileSystem.ts +0 -5
- package/src/utilities/templates.ts +0 -49
- package/src/utilities/users.ts +0 -16
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
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
|
|
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
|
|
49
|
+
return joiValidator.body(Joi.object(bulkSchema).required().unknown(true))
|
|
50
50
|
}
|
|
@@ -1,97 +1,97 @@
|
|
|
1
|
-
|
|
1
|
+
const { Configs } = require("@budibase/backend-core/constants")
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
exports.LOGO_URL =
|
|
4
4
|
"https://d33wubrfki0l68.cloudfront.net/aac32159d7207b5085e74a7ef67afbb7027786c5/2b1fd/img/logo/bb-emblem.svg"
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
ACTIVE
|
|
8
|
-
INACTIVE
|
|
6
|
+
exports.UserStatus = {
|
|
7
|
+
ACTIVE: "active",
|
|
8
|
+
INACTIVE: "inactive",
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
exports.Configs = Configs
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
LOGO
|
|
15
|
-
OIDC_LOGO
|
|
13
|
+
exports.ConfigUploads = {
|
|
14
|
+
LOGO: "logo",
|
|
15
|
+
OIDC_LOGO: "oidc_logo",
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
EMAIL
|
|
18
|
+
const TemplateTypes = {
|
|
19
|
+
EMAIL: "email",
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
BASE
|
|
24
|
-
PASSWORD_RECOVERY
|
|
25
|
-
INVITATION
|
|
26
|
-
WELCOME
|
|
27
|
-
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
|
-
|
|
31
|
-
PLATFORM_URL
|
|
32
|
-
COMPANY
|
|
33
|
-
LOGO_URL
|
|
34
|
-
EMAIL
|
|
35
|
-
USER
|
|
36
|
-
REQUEST
|
|
37
|
-
DOCS_URL
|
|
38
|
-
LOGIN_URL
|
|
39
|
-
CURRENT_YEAR
|
|
40
|
-
CURRENT_DATE
|
|
41
|
-
BODY
|
|
42
|
-
STYLES
|
|
43
|
-
RESET_URL
|
|
44
|
-
RESET_CODE
|
|
45
|
-
INVITE_URL
|
|
46
|
-
INVITE_CODE
|
|
47
|
-
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
|
-
|
|
50
|
+
const TemplateBindings = {
|
|
51
51
|
PLATFORM_URL: {
|
|
52
|
-
name:
|
|
52
|
+
name: InternalTemplateBindings.PLATFORM_URL,
|
|
53
53
|
description: "The URL used to access the budibase platform",
|
|
54
54
|
},
|
|
55
55
|
COMPANY: {
|
|
56
|
-
name:
|
|
56
|
+
name: InternalTemplateBindings.COMPANY,
|
|
57
57
|
description: "The name of your organization",
|
|
58
58
|
},
|
|
59
59
|
LOGO_URL: {
|
|
60
|
-
name:
|
|
60
|
+
name: InternalTemplateBindings.LOGO_URL,
|
|
61
61
|
description: "The URL of your organizations logo.",
|
|
62
62
|
},
|
|
63
63
|
EMAIL: {
|
|
64
|
-
name:
|
|
64
|
+
name: InternalTemplateBindings.EMAIL,
|
|
65
65
|
description: "The recipients email address.",
|
|
66
66
|
},
|
|
67
67
|
USER: {
|
|
68
|
-
name:
|
|
68
|
+
name: InternalTemplateBindings.USER,
|
|
69
69
|
description: "The recipients user object.",
|
|
70
70
|
},
|
|
71
71
|
REQUEST: {
|
|
72
|
-
name:
|
|
72
|
+
name: InternalTemplateBindings.REQUEST,
|
|
73
73
|
description: "Additional request metadata.",
|
|
74
74
|
},
|
|
75
75
|
DOCS_URL: {
|
|
76
|
-
name:
|
|
76
|
+
name: InternalTemplateBindings.DOCS_URL,
|
|
77
77
|
description: "Organization documentation URL.",
|
|
78
78
|
},
|
|
79
79
|
LOGIN_URL: {
|
|
80
|
-
name:
|
|
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:
|
|
84
|
+
name: InternalTemplateBindings.CURRENT_YEAR,
|
|
85
85
|
description: "The current year.",
|
|
86
86
|
},
|
|
87
87
|
CURRENT_DATE: {
|
|
88
|
-
name:
|
|
88
|
+
name: InternalTemplateBindings.CURRENT_DATE,
|
|
89
89
|
description: "The current date.",
|
|
90
90
|
},
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
|
|
94
|
-
[
|
|
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:
|
|
103
|
+
name: InternalTemplateBindings.BODY,
|
|
104
104
|
description: "The main body of another email template.",
|
|
105
105
|
},
|
|
106
106
|
{
|
|
107
|
-
name:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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
|
-
|
|
176
|
-
|
|
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
|
-
|
|
2
|
-
|
|
1
|
+
const { readStaticFile } = require("../../utilities/fileSystem")
|
|
2
|
+
const {
|
|
3
3
|
EmailTemplatePurpose,
|
|
4
|
-
|
|
4
|
+
TemplateTypes,
|
|
5
5
|
TemplatePurpose,
|
|
6
6
|
GLOBAL_OWNER,
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
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
|
-
|
|
26
|
+
exports.addBaseTemplates = (templates, type = null) => {
|
|
27
27
|
let purposeList
|
|
28
28
|
switch (type) {
|
|
29
|
-
case
|
|
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
|
-
|
|
53
|
-
|
|
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
|
-
|
|
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
|
-
|
|
75
|
-
const templates = await getTemplates({ type })
|
|
76
|
-
return templates.find(
|
|
70
|
+
exports.getTemplateByPurpose = async (type, purpose) => {
|
|
71
|
+
const templates = await exports.getTemplates({ type })
|
|
72
|
+
return templates.find(template => template.purpose === purpose)
|
|
77
73
|
}
|
package/src/db/index.js
ADDED
|
@@ -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
|
+
}
|
package/src/environment.ts
CHANGED
|
@@ -26,7 +26,7 @@ function parseIntSafe(number: any) {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
const
|
|
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
|
-
|
|
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 (!
|
|
82
|
-
|
|
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(
|
|
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
|
-
|
|
90
|
+
env[key] = 0
|
|
93
91
|
}
|
|
94
92
|
}
|
|
95
93
|
|
|
96
|
-
export =
|
|
94
|
+
export = env
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// need to load environment first
|
|
2
|
-
|
|
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
|
|
17
|
-
import { auth, logging, events, pinoSettings } from "@budibase/backend-core"
|
|
16
|
+
import db from "./db"
|
|
18
17
|
db.init()
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
|
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(
|
|
43
|
-
app.use(
|
|
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 ||
|
|
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
|
-
|
|
94
|
+
logAlert("Uncaught exception.", err)
|
|
94
95
|
shutdown()
|
|
95
96
|
})
|
|
96
97
|
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
|
|
8
|
+
module.exports = async (ctx, next) => {
|
|
10
9
|
if (!env.SELF_HOSTED && !env.DISABLE_ACCOUNT_PORTAL) {
|
|
11
|
-
const apiKey = ctx.request.headers[
|
|
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
|
}
|