@budibase/worker 2.1.43-alpha.1 → 2.1.43
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 +45 -61
- package/src/api/routes/global/{users.ts → users.js} +26 -28
- 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 +6 -38
- 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 -2157
- 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 -433
- 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 -3970
- 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
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/worker",
|
|
3
3
|
"email": "hi@budibase.com",
|
|
4
|
-
"version": "2.1.43
|
|
4
|
+
"version": "2.1.43",
|
|
5
5
|
"description": "Budibase background service",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"repository": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"build:docker": "docker build . -t worker-service --label version=$BUDIBASE_RELEASE_VERSION",
|
|
23
23
|
"dev:stack:init": "node ./scripts/dev/manage.js init",
|
|
24
24
|
"dev:builder": "npm run dev:stack:init && nodemon",
|
|
25
|
-
"test": "jest --
|
|
25
|
+
"test": "jest --runInBand",
|
|
26
26
|
"test:watch": "jest --watch",
|
|
27
27
|
"env:multi:enable": "node scripts/multiTenancy.js enable",
|
|
28
28
|
"env:multi:disable": "node scripts/multiTenancy.js disable",
|
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
"author": "Budibase",
|
|
37
37
|
"license": "GPL-3.0",
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@budibase/backend-core": "2.1.43
|
|
40
|
-
"@budibase/pro": "2.1.
|
|
41
|
-
"@budibase/string-templates": "2.1.43
|
|
42
|
-
"@budibase/types": "2.1.43
|
|
39
|
+
"@budibase/backend-core": "^2.1.43",
|
|
40
|
+
"@budibase/pro": "2.1.42",
|
|
41
|
+
"@budibase/string-templates": "^2.1.43",
|
|
42
|
+
"@budibase/types": "^2.1.43",
|
|
43
43
|
"@koa/router": "8.0.8",
|
|
44
44
|
"@sentry/node": "6.17.7",
|
|
45
45
|
"@techpass/passport-openidconnect": "0.3.2",
|
|
@@ -71,28 +71,38 @@
|
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@types/jest": "26.0.23",
|
|
74
|
-
"@types/jsonwebtoken": "8.5.1",
|
|
75
74
|
"@types/koa": "2.13.4",
|
|
76
75
|
"@types/koa__router": "8.0.11",
|
|
77
76
|
"@types/node": "14.18.20",
|
|
78
|
-
"@types/node-fetch": "2.6.1",
|
|
79
77
|
"@types/pouchdb": "6.4.0",
|
|
80
78
|
"@types/uuid": "8.3.4",
|
|
81
|
-
"@typescript-eslint/parser": "5.
|
|
79
|
+
"@typescript-eslint/parser": "5.12.0",
|
|
82
80
|
"copyfiles": "2.4.1",
|
|
83
81
|
"eslint": "6.8.0",
|
|
84
|
-
"jest": "
|
|
82
|
+
"jest": "27.4.7",
|
|
85
83
|
"nodemon": "2.0.15",
|
|
86
84
|
"pouchdb-adapter-memory": "7.2.2",
|
|
87
85
|
"prettier": "2.3.1",
|
|
88
86
|
"rimraf": "3.0.2",
|
|
89
87
|
"supertest": "6.2.2",
|
|
90
88
|
"timekeeper": "2.2.0",
|
|
91
|
-
"ts-jest": "
|
|
92
|
-
"ts-node": "10.
|
|
89
|
+
"ts-jest": "27.1.3",
|
|
90
|
+
"ts-node": "10.4.0",
|
|
93
91
|
"tsconfig-paths": "4.0.0",
|
|
94
|
-
"typescript": "4.
|
|
92
|
+
"typescript": "4.5.5",
|
|
95
93
|
"update-dotenv": "1.1.1"
|
|
96
94
|
},
|
|
97
|
-
"
|
|
95
|
+
"jest": {
|
|
96
|
+
"preset": "ts-jest",
|
|
97
|
+
"testEnvironment": "node",
|
|
98
|
+
"moduleNameMapper": {
|
|
99
|
+
"@budibase/backend-core/(.*)": "<rootDir>/../backend-core/$1",
|
|
100
|
+
"@budibase/backend-core": "<rootDir>/../backend-core/src",
|
|
101
|
+
"@budibase/types": "<rootDir>/../types/src"
|
|
102
|
+
},
|
|
103
|
+
"setupFiles": [
|
|
104
|
+
"./scripts/jestSetup.js"
|
|
105
|
+
]
|
|
106
|
+
},
|
|
107
|
+
"gitHead": "462d3be32347f58d90ea2fa98bd1e42faa3b0d9b"
|
|
98
108
|
}
|
|
@@ -1,21 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
const env = require("../src/environment")
|
|
2
2
|
|
|
3
|
-
env._set("SELF_HOSTED", "
|
|
3
|
+
env._set("SELF_HOSTED", "1")
|
|
4
4
|
env._set("NODE_ENV", "jest")
|
|
5
5
|
env._set("JWT_SECRET", "test-jwtsecret")
|
|
6
6
|
env._set("LOG_LEVEL", "silent")
|
|
7
7
|
env._set("MULTI_TENANCY", true)
|
|
8
|
-
env._set("MINIO_URL", "http://localhost")
|
|
9
|
-
env._set("MINIO_ACCESS_KEY", "test")
|
|
10
|
-
env._set("MINIO_SECRET_KEY", "test")
|
|
11
|
-
env._set("PLATFORM_URL", "http://localhost:10000")
|
|
12
|
-
env._set("INTERNAL_API_KEY", "test")
|
|
13
|
-
env._set("DISABLE_ACCOUNT_PORTAL", false)
|
|
14
8
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
// must explicitly enable fetch mock
|
|
18
|
-
mocks.fetch.enable()
|
|
9
|
+
const { mocks } = require("@budibase/backend-core/tests")
|
|
19
10
|
|
|
20
11
|
// mock all dates to 2020-01-01T00:00:00.000Z
|
|
21
12
|
// use tk.reset() to use real dates in individual tests
|
package/scripts/localdomain.js
CHANGED
|
@@ -2,36 +2,6 @@
|
|
|
2
2
|
const updateDotEnv = require("update-dotenv")
|
|
3
3
|
|
|
4
4
|
const arg = process.argv.slice(2)[0]
|
|
5
|
-
const isEnable = arg === "enable"
|
|
6
|
-
|
|
7
|
-
let domain = process.argv.slice(2)[1]
|
|
8
|
-
if (!domain) {
|
|
9
|
-
domain = "local.com"
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const getAccountPortalUrl = () => {
|
|
13
|
-
if (isEnable) {
|
|
14
|
-
return `http://account.${domain}:10001`
|
|
15
|
-
} else {
|
|
16
|
-
return `http://localhost:10001`
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const getBudibaseUrl = () => {
|
|
21
|
-
if (isEnable) {
|
|
22
|
-
return `http://${domain}:10000`
|
|
23
|
-
} else {
|
|
24
|
-
return `http://localhost:10000`
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const getCookieDomain = () => {
|
|
29
|
-
if (isEnable) {
|
|
30
|
-
return `.${domain}`
|
|
31
|
-
} else {
|
|
32
|
-
return ""
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
5
|
|
|
36
6
|
/**
|
|
37
7
|
* For testing multi tenancy sub domains locally.
|
|
@@ -46,7 +16,11 @@ const getCookieDomain = () => {
|
|
|
46
16
|
* 127.0.0.1 t2.local.com
|
|
47
17
|
*/
|
|
48
18
|
updateDotEnv({
|
|
49
|
-
ACCOUNT_PORTAL_URL:
|
|
50
|
-
|
|
51
|
-
|
|
19
|
+
ACCOUNT_PORTAL_URL:
|
|
20
|
+
arg === "enable"
|
|
21
|
+
? "http://account.local.com:10001"
|
|
22
|
+
: "http://localhost:10001",
|
|
23
|
+
COOKIE_DOMAIN: arg === "enable" ? ".local.com" : "",
|
|
24
|
+
PLATFORM_URL:
|
|
25
|
+
arg === "enable" ? "http://local.com:10000" : "http://localhost:10000",
|
|
52
26
|
}).then(() => console.log("Updated worker!"))
|
|
@@ -1,30 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
} from "@budibase/backend-core"
|
|
11
|
-
import { EmailTemplatePurpose } from "../../../constants"
|
|
12
|
-
import { isEmailConfigured, sendEmail } from "../../../utilities/email"
|
|
13
|
-
import { checkResetPasswordCode } from "../../../utilities/redis"
|
|
14
|
-
import env from "../../../environment"
|
|
1
|
+
const core = require("@budibase/backend-core")
|
|
2
|
+
const { Configs, EmailTemplatePurpose } = require("../../../constants")
|
|
3
|
+
const { sendEmail, isEmailConfigured } = require("../../../utilities/email")
|
|
4
|
+
const { setCookie, getCookie, clearCookie, hash, platformLogout } = core.utils
|
|
5
|
+
const { Cookies, Headers } = core.constants
|
|
6
|
+
const { passport, ssoCallbackUrl, google, oidc } = core.auth
|
|
7
|
+
const { checkResetPasswordCode } = require("../../../utilities/redis")
|
|
8
|
+
const { getGlobalDB } = require("@budibase/backend-core/tenancy")
|
|
9
|
+
const env = require("../../../environment")
|
|
10
|
+
import { events, users as usersCore, context } from "@budibase/backend-core"
|
|
15
11
|
import sdk from "../../../sdk"
|
|
16
|
-
import {
|
|
12
|
+
import { User } from "@budibase/types"
|
|
17
13
|
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
const { passport, ssoCallbackUrl, google, oidc } = auth
|
|
21
|
-
|
|
22
|
-
export async function googleCallbackUrl(config?: { callbackURL?: string }) {
|
|
23
|
-
return ssoCallbackUrl(tenancy.getGlobalDB(), config, ConfigType.GOOGLE)
|
|
14
|
+
export const googleCallbackUrl = async (config: any) => {
|
|
15
|
+
return ssoCallbackUrl(getGlobalDB(), config, "google")
|
|
24
16
|
}
|
|
25
17
|
|
|
26
|
-
export
|
|
27
|
-
return ssoCallbackUrl(
|
|
18
|
+
export const oidcCallbackUrl = async (config: any) => {
|
|
19
|
+
return ssoCallbackUrl(getGlobalDB(), config, "oidc")
|
|
28
20
|
}
|
|
29
21
|
|
|
30
22
|
async function authInternal(ctx: any, user: any, err = null, info = null) {
|
|
@@ -38,13 +30,13 @@ async function authInternal(ctx: any, user: any, err = null, info = null) {
|
|
|
38
30
|
}
|
|
39
31
|
|
|
40
32
|
// set a cookie for browser access
|
|
41
|
-
setCookie(ctx, user.token,
|
|
33
|
+
setCookie(ctx, user.token, Cookies.Auth, { sign: false })
|
|
42
34
|
// set the token in a header as well for APIs
|
|
43
|
-
ctx.set(
|
|
35
|
+
ctx.set(Headers.TOKEN, user.token)
|
|
44
36
|
// get rid of any app cookies on login
|
|
45
37
|
// have to check test because this breaks cypress
|
|
46
38
|
if (!env.isTest()) {
|
|
47
|
-
clearCookie(ctx,
|
|
39
|
+
clearCookie(ctx, Cookies.CurrentApp)
|
|
48
40
|
}
|
|
49
41
|
}
|
|
50
42
|
|
|
@@ -63,15 +55,15 @@ export const authenticate = async (ctx: any, next: any) => {
|
|
|
63
55
|
|
|
64
56
|
export const setInitInfo = (ctx: any) => {
|
|
65
57
|
const initInfo = ctx.request.body
|
|
66
|
-
setCookie(ctx, initInfo,
|
|
58
|
+
setCookie(ctx, initInfo, Cookies.Init)
|
|
67
59
|
ctx.status = 200
|
|
68
60
|
}
|
|
69
61
|
|
|
70
62
|
export const getInitInfo = (ctx: any) => {
|
|
71
63
|
try {
|
|
72
|
-
ctx.body = getCookie(ctx,
|
|
64
|
+
ctx.body = getCookie(ctx, Cookies.Init) || {}
|
|
73
65
|
} catch (err) {
|
|
74
|
-
clearCookie(ctx,
|
|
66
|
+
clearCookie(ctx, Cookies.Init)
|
|
75
67
|
ctx.body = {}
|
|
76
68
|
}
|
|
77
69
|
}
|
|
@@ -114,7 +106,7 @@ export const resetUpdate = async (ctx: any) => {
|
|
|
114
106
|
const { resetCode, password } = ctx.request.body
|
|
115
107
|
try {
|
|
116
108
|
const { userId } = await checkResetPasswordCode(resetCode)
|
|
117
|
-
const db =
|
|
109
|
+
const db = getGlobalDB()
|
|
118
110
|
const user = await db.get(userId)
|
|
119
111
|
user.password = await hash(password)
|
|
120
112
|
await db.put(user)
|
|
@@ -139,7 +131,7 @@ export const logout = async (ctx: any) => {
|
|
|
139
131
|
|
|
140
132
|
export const datasourcePreAuth = async (ctx: any, next: any) => {
|
|
141
133
|
const provider = ctx.params.provider
|
|
142
|
-
const
|
|
134
|
+
const middleware = require(`@budibase/backend-core/middleware`)
|
|
143
135
|
const handler = middleware.datasource[provider]
|
|
144
136
|
|
|
145
137
|
setCookie(
|
|
@@ -149,16 +141,16 @@ export const datasourcePreAuth = async (ctx: any, next: any) => {
|
|
|
149
141
|
appId: ctx.query.appId,
|
|
150
142
|
datasourceId: ctx.query.datasourceId,
|
|
151
143
|
},
|
|
152
|
-
|
|
144
|
+
Cookies.DatasourceAuth
|
|
153
145
|
)
|
|
154
146
|
|
|
155
147
|
return handler.preAuth(passport, ctx, next)
|
|
156
148
|
}
|
|
157
149
|
|
|
158
150
|
export const datasourceAuth = async (ctx: any, next: any) => {
|
|
159
|
-
const authStateCookie = getCookie(ctx,
|
|
151
|
+
const authStateCookie = getCookie(ctx, Cookies.DatasourceAuth)
|
|
160
152
|
const provider = authStateCookie.provider
|
|
161
|
-
const
|
|
153
|
+
const middleware = require(`@budibase/backend-core/middleware`)
|
|
162
154
|
const handler = middleware.datasource[provider]
|
|
163
155
|
return handler.postAuth(passport, ctx, next)
|
|
164
156
|
}
|
|
@@ -168,13 +160,13 @@ export const datasourceAuth = async (ctx: any, next: any) => {
|
|
|
168
160
|
* On a successful login, you will be redirected to the googleAuth callback route.
|
|
169
161
|
*/
|
|
170
162
|
export const googlePreAuth = async (ctx: any, next: any) => {
|
|
171
|
-
const db =
|
|
163
|
+
const db = getGlobalDB()
|
|
172
164
|
|
|
173
|
-
const config = await
|
|
174
|
-
type:
|
|
165
|
+
const config = await core.db.getScopedConfig(db, {
|
|
166
|
+
type: Configs.GOOGLE,
|
|
175
167
|
workspace: ctx.query.workspace,
|
|
176
168
|
})
|
|
177
|
-
let callbackUrl = await googleCallbackUrl(config)
|
|
169
|
+
let callbackUrl = await exports.googleCallbackUrl(config)
|
|
178
170
|
const strategy = await google.strategyFactory(
|
|
179
171
|
config,
|
|
180
172
|
callbackUrl,
|
|
@@ -189,13 +181,13 @@ export const googlePreAuth = async (ctx: any, next: any) => {
|
|
|
189
181
|
}
|
|
190
182
|
|
|
191
183
|
export const googleAuth = async (ctx: any, next: any) => {
|
|
192
|
-
const db =
|
|
184
|
+
const db = getGlobalDB()
|
|
193
185
|
|
|
194
|
-
const config = await
|
|
195
|
-
type:
|
|
186
|
+
const config = await core.db.getScopedConfig(db, {
|
|
187
|
+
type: Configs.GOOGLE,
|
|
196
188
|
workspace: ctx.query.workspace,
|
|
197
189
|
})
|
|
198
|
-
const callbackUrl = await googleCallbackUrl(config)
|
|
190
|
+
const callbackUrl = await exports.googleCallbackUrl(config)
|
|
199
191
|
const strategy = await google.strategyFactory(
|
|
200
192
|
config,
|
|
201
193
|
callbackUrl,
|
|
@@ -216,14 +208,14 @@ export const googleAuth = async (ctx: any, next: any) => {
|
|
|
216
208
|
}
|
|
217
209
|
|
|
218
210
|
export const oidcStrategyFactory = async (ctx: any, configId: any) => {
|
|
219
|
-
const db =
|
|
220
|
-
const config = await
|
|
221
|
-
type:
|
|
211
|
+
const db = getGlobalDB()
|
|
212
|
+
const config = await core.db.getScopedConfig(db, {
|
|
213
|
+
type: Configs.OIDC,
|
|
222
214
|
group: ctx.query.group,
|
|
223
215
|
})
|
|
224
216
|
|
|
225
217
|
const chosenConfig = config.configs.filter((c: any) => c.uuid === configId)[0]
|
|
226
|
-
let callbackUrl = await oidcCallbackUrl(chosenConfig)
|
|
218
|
+
let callbackUrl = await exports.oidcCallbackUrl(chosenConfig)
|
|
227
219
|
|
|
228
220
|
//Remote Config
|
|
229
221
|
const enrichedConfig = await oidc.fetchStrategyConfig(
|
|
@@ -241,11 +233,11 @@ export const oidcPreAuth = async (ctx: any, next: any) => {
|
|
|
241
233
|
const { configId } = ctx.params
|
|
242
234
|
const strategy = await oidcStrategyFactory(ctx, configId)
|
|
243
235
|
|
|
244
|
-
setCookie(ctx, configId,
|
|
236
|
+
setCookie(ctx, configId, Cookies.OIDC_CONFIG)
|
|
245
237
|
|
|
246
|
-
const db =
|
|
247
|
-
const config = await
|
|
248
|
-
type:
|
|
238
|
+
const db = getGlobalDB()
|
|
239
|
+
const config = await core.db.getScopedConfig(db, {
|
|
240
|
+
type: Configs.OIDC,
|
|
249
241
|
group: ctx.query.group,
|
|
250
242
|
})
|
|
251
243
|
|
|
@@ -263,7 +255,7 @@ export const oidcPreAuth = async (ctx: any, next: any) => {
|
|
|
263
255
|
}
|
|
264
256
|
|
|
265
257
|
export const oidcAuth = async (ctx: any, next: any) => {
|
|
266
|
-
const configId = getCookie(ctx,
|
|
258
|
+
const configId = getCookie(ctx, Cookies.OIDC_CONFIG)
|
|
267
259
|
const strategy = await oidcStrategyFactory(ctx, configId)
|
|
268
260
|
|
|
269
261
|
return passport.authenticate(
|