@budibase/worker 2.1.45 → 2.1.46-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.
- package/__mocks__/aws-sdk.ts +15 -0
- package/__mocks__/oauth.ts +57 -0
- package/coverage/clover.xml +2167 -0
- package/coverage/coverage-final.json +78 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +431 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov-report/src/api/controllers/global/auth.ts.html +925 -0
- package/coverage/lcov-report/src/api/controllers/global/configs.ts.html +1405 -0
- package/coverage/lcov-report/src/api/controllers/global/email.ts.html +196 -0
- package/coverage/lcov-report/src/api/controllers/global/index.html +236 -0
- package/coverage/lcov-report/src/api/controllers/global/license.ts.html +187 -0
- package/coverage/lcov-report/src/api/controllers/global/roles.ts.html +283 -0
- package/coverage/lcov-report/src/api/controllers/global/self.ts.html +577 -0
- package/coverage/lcov-report/src/api/controllers/global/templates.ts.html +316 -0
- package/coverage/lcov-report/src/api/controllers/global/users.ts.html +799 -0
- package/coverage/lcov-report/src/api/controllers/global/workspaces.ts.html +244 -0
- package/coverage/lcov-report/src/api/controllers/system/accounts.ts.html +148 -0
- package/coverage/lcov-report/src/api/controllers/system/environment.ts.html +124 -0
- package/coverage/lcov-report/src/api/controllers/system/index.html +191 -0
- package/coverage/lcov-report/src/api/controllers/system/migrations.ts.html +124 -0
- package/coverage/lcov-report/src/api/controllers/system/restore.ts.html +124 -0
- package/coverage/lcov-report/src/api/controllers/system/status.ts.html +133 -0
- package/coverage/lcov-report/src/api/controllers/system/tenants.ts.html +154 -0
- package/coverage/lcov-report/src/api/index.html +116 -0
- package/coverage/lcov-report/src/api/index.ts.html +583 -0
- package/coverage/lcov-report/src/api/routes/global/auth.ts.html +349 -0
- package/coverage/lcov-report/src/api/routes/global/configs.ts.html +457 -0
- package/coverage/lcov-report/src/api/routes/global/email.ts.html +193 -0
- package/coverage/lcov-report/src/api/routes/global/index.html +236 -0
- package/coverage/lcov-report/src/api/routes/global/license.ts.html +124 -0
- package/coverage/lcov-report/src/api/routes/global/roles.ts.html +133 -0
- package/coverage/lcov-report/src/api/routes/global/self.ts.html +139 -0
- package/coverage/lcov-report/src/api/routes/global/templates.ts.html +196 -0
- package/coverage/lcov-report/src/api/routes/global/users.ts.html +433 -0
- package/coverage/lcov-report/src/api/routes/global/workspaces.ts.html +196 -0
- package/coverage/lcov-report/src/api/routes/index.html +116 -0
- package/coverage/lcov-report/src/api/routes/index.ts.html +196 -0
- package/coverage/lcov-report/src/api/routes/system/accounts.ts.html +142 -0
- package/coverage/lcov-report/src/api/routes/system/environment.ts.html +109 -0
- package/coverage/lcov-report/src/api/routes/system/index.html +191 -0
- package/coverage/lcov-report/src/api/routes/system/migrations.ts.html +142 -0
- package/coverage/lcov-report/src/api/routes/system/restore.ts.html +109 -0
- package/coverage/lcov-report/src/api/routes/system/status.ts.html +109 -0
- package/coverage/lcov-report/src/api/routes/system/tenants.ts.html +124 -0
- package/coverage/lcov-report/src/api/routes/validation/index.html +131 -0
- package/coverage/lcov-report/src/api/routes/validation/index.ts.html +88 -0
- package/coverage/lcov-report/src/api/routes/validation/users.ts.html +235 -0
- package/coverage/lcov-report/src/constants/index.html +116 -0
- package/coverage/lcov-report/src/constants/index.ts.html +613 -0
- package/coverage/lcov-report/src/constants/templates/index.html +116 -0
- package/coverage/lcov-report/src/constants/templates/index.ts.html +316 -0
- package/coverage/lcov-report/src/db/index.html +116 -0
- package/coverage/lcov-report/src/db/index.ts.html +115 -0
- package/coverage/lcov-report/src/environment.ts.html +373 -0
- package/coverage/lcov-report/src/index.html +131 -0
- package/coverage/lcov-report/src/index.ts.html +394 -0
- package/coverage/lcov-report/src/middleware/cloudRestricted.ts.html +139 -0
- package/coverage/lcov-report/src/middleware/index.html +116 -0
- package/coverage/lcov-report/src/migrations/functions/globalInfoSyncUsers.ts.html +145 -0
- package/coverage/lcov-report/src/migrations/functions/index.html +116 -0
- package/coverage/lcov-report/src/migrations/index.html +116 -0
- package/coverage/lcov-report/src/migrations/index.ts.html +271 -0
- package/coverage/lcov-report/src/sdk/accounts/accounts.ts.html +262 -0
- package/coverage/lcov-report/src/sdk/accounts/index.html +131 -0
- package/coverage/lcov-report/src/sdk/accounts/index.ts.html +88 -0
- package/coverage/lcov-report/src/sdk/index.html +116 -0
- package/coverage/lcov-report/src/sdk/index.ts.html +106 -0
- package/coverage/lcov-report/src/sdk/users/events.ts.html +577 -0
- package/coverage/lcov-report/src/sdk/users/index.html +146 -0
- package/coverage/lcov-report/src/sdk/users/index.ts.html +88 -0
- package/coverage/lcov-report/src/sdk/users/users.ts.html +1942 -0
- package/coverage/lcov-report/src/tests/TestConfiguration.ts.html +1051 -0
- package/coverage/lcov-report/src/tests/api/accounts.ts.html +160 -0
- package/coverage/lcov-report/src/tests/api/auth.ts.html +220 -0
- package/coverage/lcov-report/src/tests/api/base.ts.html +133 -0
- package/coverage/lcov-report/src/tests/api/configs.ts.html +226 -0
- package/coverage/lcov-report/src/tests/api/email.ts.html +148 -0
- package/coverage/lcov-report/src/tests/api/environment.ts.html +130 -0
- package/coverage/lcov-report/src/tests/api/index.html +296 -0
- package/coverage/lcov-report/src/tests/api/index.ts.html +205 -0
- package/coverage/lcov-report/src/tests/api/migrations.ts.html +151 -0
- package/coverage/lcov-report/src/tests/api/restore.ts.html +127 -0
- package/coverage/lcov-report/src/tests/api/self.ts.html +163 -0
- package/coverage/lcov-report/src/tests/api/status.ts.html +121 -0
- package/coverage/lcov-report/src/tests/api/tenants.ts.html +130 -0
- package/coverage/lcov-report/src/tests/api/users.ts.html +511 -0
- package/coverage/lcov-report/src/tests/controllers.ts.html +100 -0
- package/coverage/lcov-report/src/tests/index.html +146 -0
- package/coverage/lcov-report/src/tests/index.ts.html +139 -0
- package/coverage/lcov-report/src/tests/mocks/email.js.html +115 -0
- package/coverage/lcov-report/src/tests/mocks/index.html +131 -0
- package/coverage/lcov-report/src/tests/mocks/index.ts.html +106 -0
- package/coverage/lcov-report/src/tests/structures/configs.ts.html +313 -0
- package/coverage/lcov-report/src/tests/structures/groups.ts.html +118 -0
- package/coverage/lcov-report/src/tests/structures/index.html +161 -0
- package/coverage/lcov-report/src/tests/structures/index.ts.html +151 -0
- package/coverage/lcov-report/src/tests/structures/users.ts.html +196 -0
- package/coverage/lcov-report/src/utilities/appService.ts.html +181 -0
- package/coverage/lcov-report/src/utilities/email.ts.html +850 -0
- package/coverage/lcov-report/src/utilities/fileSystem.ts.html +100 -0
- package/coverage/lcov-report/src/utilities/index.html +206 -0
- package/coverage/lcov-report/src/utilities/index.ts.html +112 -0
- package/coverage/lcov-report/src/utilities/redis.ts.html +424 -0
- package/coverage/lcov-report/src/utilities/templates.ts.html +232 -0
- package/coverage/lcov-report/src/utilities/users.ts.html +133 -0
- package/coverage/lcov.info +3989 -0
- package/jest.config.ts +29 -0
- package/package.json +14 -24
- package/scripts/localdomain.js +33 -7
- package/src/api/controllers/global/auth.ts +51 -43
- package/src/api/controllers/global/{configs.js → configs.ts} +119 -114
- package/src/api/controllers/global/{email.js → email.ts} +6 -5
- package/src/api/controllers/global/roles.ts +66 -0
- package/src/api/controllers/global/self.ts +2 -2
- package/src/api/controllers/global/users.ts +6 -3
- package/src/api/controllers/global/{workspaces.js → workspaces.ts} +15 -18
- package/src/api/controllers/system/{environment.js → environment.ts} +3 -2
- package/src/api/controllers/system/restore.ts +1 -1
- package/src/api/controllers/system/{status.js → status.ts} +4 -3
- package/src/api/controllers/system/tenants.ts +8 -51
- package/src/api/index.ts +31 -8
- package/src/api/routes/global/{auth.js → auth.ts} +31 -48
- package/src/api/routes/global/{configs.js → configs.ts} +22 -23
- package/src/api/routes/global/{email.js → email.ts} +9 -10
- package/src/api/routes/global/license.ts +1 -1
- package/src/api/routes/global/roles.ts +16 -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 +134 -64
- package/src/api/routes/global/tests/configs.spec.ts +34 -35
- package/src/api/routes/global/tests/email.spec.ts +4 -3
- package/src/api/routes/global/tests/license.spec.ts +31 -0
- package/src/api/routes/global/tests/realEmail.spec.ts +2 -3
- package/src/api/routes/global/tests/roles.spec.ts +27 -0
- package/src/api/routes/global/tests/self.spec.ts +3 -4
- package/src/api/routes/global/tests/templates.spec.ts +35 -0
- package/src/api/routes/global/tests/users.spec.ts +79 -46
- package/src/api/routes/global/tests/workspaces.spec.ts +29 -0
- package/src/api/routes/global/{users.js → users.ts} +28 -26
- package/src/api/routes/global/{workspaces.js → workspaces.ts} +9 -10
- package/src/api/routes/index.ts +2 -1
- package/src/api/routes/system/accounts.ts +1 -1
- package/src/api/routes/system/environment.ts +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.ts +8 -0
- package/src/api/routes/system/tenants.ts +13 -0
- package/src/api/routes/system/tests/accounts.spec.ts +5 -6
- package/src/api/routes/system/tests/environment.spec.ts +29 -0
- package/src/api/routes/system/tests/migrations.spec.ts +63 -0
- package/src/api/routes/system/tests/restore.spec.ts +36 -0
- package/src/api/routes/system/tests/status.spec.ts +48 -0
- package/src/api/routes/system/tests/tenants.spec.ts +61 -0
- package/src/api/routes/validation/users.ts +3 -3
- package/src/constants/{index.js → index.ts} +57 -64
- package/src/constants/templates/{index.js → index.ts} +23 -19
- package/src/db/index.ts +10 -0
- package/src/environment.ts +9 -7
- package/src/index.ts +15 -16
- package/src/middleware/{cloudRestricted.js → cloudRestricted.ts} +5 -4
- package/src/middleware/tests/tenancy.spec.ts +73 -0
- package/src/sdk/users/users.ts +28 -15
- package/src/tests/TestConfiguration.ts +99 -50
- package/src/tests/api/accounts.ts +5 -8
- package/src/tests/api/auth.ts +3 -6
- package/src/tests/api/base.ts +16 -0
- package/src/tests/api/configs.ts +15 -8
- package/src/tests/api/email.ts +3 -6
- package/src/tests/api/environment.ts +15 -0
- package/src/tests/api/index.ts +15 -0
- package/src/tests/api/migrations.ts +22 -0
- package/src/tests/api/restore.ts +14 -0
- package/src/tests/api/self.ts +11 -6
- package/src/tests/api/status.ts +12 -0
- package/src/tests/api/tenants.ts +15 -0
- package/src/tests/api/users.ts +38 -6
- package/src/tests/controllers.ts +5 -0
- package/src/tests/index.ts +5 -1
- package/{scripts/jestSetup.js → src/tests/jestSetup.ts} +12 -3
- package/src/tests/structures/{configs.js → configs.ts} +11 -11
- package/src/tests/structures/index.ts +5 -3
- package/src/tests/structures/users.ts +1 -0
- package/src/utilities/appService.ts +32 -0
- package/src/utilities/{email.js → email.ts} +78 -45
- package/src/utilities/fileSystem.ts +5 -0
- package/src/utilities/{index.js → index.ts} +1 -1
- package/src/utilities/{redis.js → redis.ts} +29 -24
- package/src/utilities/templates.ts +49 -0
- package/src/utilities/users.ts +16 -0
- package/tsconfig.build.json +2 -3
- package/tsconfig.json +3 -1
- package/src/api/controllers/global/roles.js +0 -68
- package/src/api/routes/global/roles.js +0 -12
- package/src/api/routes/system/environment.js +0 -8
- package/src/api/routes/system/status.js +0 -8
- package/src/api/routes/system/tenants.js +0 -12
- package/src/db/index.js +0 -11
- package/src/tests/controllers.js +0 -7
- package/src/tests/structures/accounts.ts +0 -24
- package/src/utilities/appService.js +0 -33
- package/src/utilities/fileSystem.js +0 -5
- package/src/utilities/templates.js +0 -49
- package/src/utilities/users.js +0 -17
package/jest.config.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Config } from "@jest/types"
|
|
2
|
+
import * as fs from "fs"
|
|
3
|
+
|
|
4
|
+
const config: Config.InitialOptions = {
|
|
5
|
+
preset: "ts-jest",
|
|
6
|
+
testEnvironment: "node",
|
|
7
|
+
setupFiles: ["./src/tests/jestSetup.ts"],
|
|
8
|
+
collectCoverageFrom: ["src/**/*.{js,ts}"],
|
|
9
|
+
coverageReporters: ["lcov", "json", "clover"],
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (!process.env.CI) {
|
|
13
|
+
// use sources when not in CI
|
|
14
|
+
config.moduleNameMapper = {
|
|
15
|
+
"@budibase/backend-core/(.*)": "<rootDir>/../backend-core/$1",
|
|
16
|
+
"@budibase/backend-core": "<rootDir>/../backend-core/src",
|
|
17
|
+
"@budibase/types": "<rootDir>/../types/src",
|
|
18
|
+
"^axios.*$": "<rootDir>/node_modules/axios/lib/axios.js",
|
|
19
|
+
}
|
|
20
|
+
// add pro sources if they exist
|
|
21
|
+
if (fs.existsSync("../../../budibase-pro")) {
|
|
22
|
+
config.moduleNameMapper["@budibase/pro"] =
|
|
23
|
+
"<rootDir>/../../../budibase-pro/packages/pro/src"
|
|
24
|
+
}
|
|
25
|
+
} else {
|
|
26
|
+
console.log("Running tests with compiled dependency sources")
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default config
|
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.
|
|
4
|
+
"version": "2.1.46-alpha.0",
|
|
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 --coverage --maxWorkers=2",
|
|
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": "
|
|
40
|
-
"@budibase/pro": "2.1.
|
|
41
|
-
"@budibase/string-templates": "
|
|
42
|
-
"@budibase/types": "
|
|
39
|
+
"@budibase/backend-core": "2.1.46-alpha.0",
|
|
40
|
+
"@budibase/pro": "2.1.45",
|
|
41
|
+
"@budibase/string-templates": "2.1.46-alpha.0",
|
|
42
|
+
"@budibase/types": "2.1.46-alpha.0",
|
|
43
43
|
"@koa/router": "8.0.8",
|
|
44
44
|
"@sentry/node": "6.17.7",
|
|
45
45
|
"@techpass/passport-openidconnect": "0.3.2",
|
|
@@ -71,38 +71,28 @@
|
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@types/jest": "26.0.23",
|
|
74
|
+
"@types/jsonwebtoken": "8.5.1",
|
|
74
75
|
"@types/koa": "2.13.4",
|
|
75
76
|
"@types/koa__router": "8.0.11",
|
|
76
77
|
"@types/node": "14.18.20",
|
|
78
|
+
"@types/node-fetch": "2.6.1",
|
|
77
79
|
"@types/pouchdb": "6.4.0",
|
|
78
80
|
"@types/uuid": "8.3.4",
|
|
79
|
-
"@typescript-eslint/parser": "5.
|
|
81
|
+
"@typescript-eslint/parser": "5.45.0",
|
|
80
82
|
"copyfiles": "2.4.1",
|
|
81
83
|
"eslint": "6.8.0",
|
|
82
|
-
"jest": "
|
|
84
|
+
"jest": "28.1.1",
|
|
83
85
|
"nodemon": "2.0.15",
|
|
84
86
|
"pouchdb-adapter-memory": "7.2.2",
|
|
85
87
|
"prettier": "2.3.1",
|
|
86
88
|
"rimraf": "3.0.2",
|
|
87
89
|
"supertest": "6.2.2",
|
|
88
90
|
"timekeeper": "2.2.0",
|
|
89
|
-
"ts-jest": "
|
|
90
|
-
"ts-node": "10.
|
|
91
|
+
"ts-jest": "28.0.4",
|
|
92
|
+
"ts-node": "10.8.1",
|
|
91
93
|
"tsconfig-paths": "4.0.0",
|
|
92
|
-
"typescript": "4.
|
|
94
|
+
"typescript": "4.7.3",
|
|
93
95
|
"update-dotenv": "1.1.1"
|
|
94
96
|
},
|
|
95
|
-
"
|
|
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": "4570e0cdf439ea7d89ba3b00875558f0a4b12bba"
|
|
97
|
+
"gitHead": "1c1f758ab9bbd9b841b1e759a872523aa31f53b4"
|
|
108
98
|
}
|
package/scripts/localdomain.js
CHANGED
|
@@ -2,6 +2,36 @@
|
|
|
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
|
+
}
|
|
5
35
|
|
|
6
36
|
/**
|
|
7
37
|
* For testing multi tenancy sub domains locally.
|
|
@@ -16,11 +46,7 @@ const arg = process.argv.slice(2)[0]
|
|
|
16
46
|
* 127.0.0.1 t2.local.com
|
|
17
47
|
*/
|
|
18
48
|
updateDotEnv({
|
|
19
|
-
ACCOUNT_PORTAL_URL:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
: "http://localhost:10001",
|
|
23
|
-
COOKIE_DOMAIN: arg === "enable" ? ".local.com" : "",
|
|
24
|
-
PLATFORM_URL:
|
|
25
|
-
arg === "enable" ? "http://local.com:10000" : "http://localhost:10000",
|
|
49
|
+
ACCOUNT_PORTAL_URL: getAccountPortalUrl(),
|
|
50
|
+
COOKIE_DOMAIN: getCookieDomain(),
|
|
51
|
+
PLATFORM_URL: getBudibaseUrl(),
|
|
26
52
|
}).then(() => console.log("Updated worker!"))
|
|
@@ -1,22 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import {
|
|
2
|
+
auth,
|
|
3
|
+
constants,
|
|
4
|
+
context,
|
|
5
|
+
db as dbCore,
|
|
6
|
+
events,
|
|
7
|
+
tenancy,
|
|
8
|
+
users as usersCore,
|
|
9
|
+
utils,
|
|
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"
|
|
11
15
|
import sdk from "../../../sdk"
|
|
12
|
-
import { User } from "@budibase/types"
|
|
16
|
+
import { Config, ConfigType, User } from "@budibase/types"
|
|
13
17
|
|
|
14
|
-
|
|
15
|
-
|
|
18
|
+
const { setCookie, getCookie, clearCookie, hash, platformLogout } = utils
|
|
19
|
+
const { Cookie, Header } = constants
|
|
20
|
+
const { passport, ssoCallbackUrl, google, oidc } = auth
|
|
21
|
+
|
|
22
|
+
export async function googleCallbackUrl(config?: { callbackURL?: string }) {
|
|
23
|
+
return ssoCallbackUrl(tenancy.getGlobalDB(), config, ConfigType.GOOGLE)
|
|
16
24
|
}
|
|
17
25
|
|
|
18
|
-
export
|
|
19
|
-
return ssoCallbackUrl(getGlobalDB(), config,
|
|
26
|
+
export async function oidcCallbackUrl(config?: { callbackURL?: string }) {
|
|
27
|
+
return ssoCallbackUrl(tenancy.getGlobalDB(), config, ConfigType.OIDC)
|
|
20
28
|
}
|
|
21
29
|
|
|
22
30
|
async function authInternal(ctx: any, user: any, err = null, info = null) {
|
|
@@ -30,13 +38,13 @@ async function authInternal(ctx: any, user: any, err = null, info = null) {
|
|
|
30
38
|
}
|
|
31
39
|
|
|
32
40
|
// set a cookie for browser access
|
|
33
|
-
setCookie(ctx, user.token,
|
|
41
|
+
setCookie(ctx, user.token, Cookie.Auth, { sign: false })
|
|
34
42
|
// set the token in a header as well for APIs
|
|
35
|
-
ctx.set(
|
|
43
|
+
ctx.set(Header.TOKEN, user.token)
|
|
36
44
|
// get rid of any app cookies on login
|
|
37
45
|
// have to check test because this breaks cypress
|
|
38
46
|
if (!env.isTest()) {
|
|
39
|
-
clearCookie(ctx,
|
|
47
|
+
clearCookie(ctx, Cookie.CurrentApp)
|
|
40
48
|
}
|
|
41
49
|
}
|
|
42
50
|
|
|
@@ -55,15 +63,15 @@ export const authenticate = async (ctx: any, next: any) => {
|
|
|
55
63
|
|
|
56
64
|
export const setInitInfo = (ctx: any) => {
|
|
57
65
|
const initInfo = ctx.request.body
|
|
58
|
-
setCookie(ctx, initInfo,
|
|
66
|
+
setCookie(ctx, initInfo, Cookie.Init)
|
|
59
67
|
ctx.status = 200
|
|
60
68
|
}
|
|
61
69
|
|
|
62
70
|
export const getInitInfo = (ctx: any) => {
|
|
63
71
|
try {
|
|
64
|
-
ctx.body = getCookie(ctx,
|
|
72
|
+
ctx.body = getCookie(ctx, Cookie.Init) || {}
|
|
65
73
|
} catch (err) {
|
|
66
|
-
clearCookie(ctx,
|
|
74
|
+
clearCookie(ctx, Cookie.Init)
|
|
67
75
|
ctx.body = {}
|
|
68
76
|
}
|
|
69
77
|
}
|
|
@@ -106,7 +114,7 @@ export const resetUpdate = async (ctx: any) => {
|
|
|
106
114
|
const { resetCode, password } = ctx.request.body
|
|
107
115
|
try {
|
|
108
116
|
const { userId } = await checkResetPasswordCode(resetCode)
|
|
109
|
-
const db = getGlobalDB()
|
|
117
|
+
const db = tenancy.getGlobalDB()
|
|
110
118
|
const user = await db.get(userId)
|
|
111
119
|
user.password = await hash(password)
|
|
112
120
|
await db.put(user)
|
|
@@ -131,7 +139,7 @@ export const logout = async (ctx: any) => {
|
|
|
131
139
|
|
|
132
140
|
export const datasourcePreAuth = async (ctx: any, next: any) => {
|
|
133
141
|
const provider = ctx.params.provider
|
|
134
|
-
const middleware = require(`@budibase/backend-core
|
|
142
|
+
const { middleware } = require(`@budibase/backend-core`)
|
|
135
143
|
const handler = middleware.datasource[provider]
|
|
136
144
|
|
|
137
145
|
setCookie(
|
|
@@ -141,16 +149,16 @@ export const datasourcePreAuth = async (ctx: any, next: any) => {
|
|
|
141
149
|
appId: ctx.query.appId,
|
|
142
150
|
datasourceId: ctx.query.datasourceId,
|
|
143
151
|
},
|
|
144
|
-
|
|
152
|
+
Cookie.DatasourceAuth
|
|
145
153
|
)
|
|
146
154
|
|
|
147
155
|
return handler.preAuth(passport, ctx, next)
|
|
148
156
|
}
|
|
149
157
|
|
|
150
158
|
export const datasourceAuth = async (ctx: any, next: any) => {
|
|
151
|
-
const authStateCookie = getCookie(ctx,
|
|
159
|
+
const authStateCookie = getCookie(ctx, Cookie.DatasourceAuth)
|
|
152
160
|
const provider = authStateCookie.provider
|
|
153
|
-
const middleware = require(`@budibase/backend-core
|
|
161
|
+
const { middleware } = require(`@budibase/backend-core`)
|
|
154
162
|
const handler = middleware.datasource[provider]
|
|
155
163
|
return handler.postAuth(passport, ctx, next)
|
|
156
164
|
}
|
|
@@ -160,13 +168,13 @@ export const datasourceAuth = async (ctx: any, next: any) => {
|
|
|
160
168
|
* On a successful login, you will be redirected to the googleAuth callback route.
|
|
161
169
|
*/
|
|
162
170
|
export const googlePreAuth = async (ctx: any, next: any) => {
|
|
163
|
-
const db = getGlobalDB()
|
|
171
|
+
const db = tenancy.getGlobalDB()
|
|
164
172
|
|
|
165
|
-
const config = await
|
|
166
|
-
type:
|
|
173
|
+
const config = await dbCore.getScopedConfig(db, {
|
|
174
|
+
type: ConfigType.GOOGLE,
|
|
167
175
|
workspace: ctx.query.workspace,
|
|
168
176
|
})
|
|
169
|
-
let callbackUrl = await
|
|
177
|
+
let callbackUrl = await googleCallbackUrl(config)
|
|
170
178
|
const strategy = await google.strategyFactory(
|
|
171
179
|
config,
|
|
172
180
|
callbackUrl,
|
|
@@ -181,13 +189,13 @@ export const googlePreAuth = async (ctx: any, next: any) => {
|
|
|
181
189
|
}
|
|
182
190
|
|
|
183
191
|
export const googleAuth = async (ctx: any, next: any) => {
|
|
184
|
-
const db = getGlobalDB()
|
|
192
|
+
const db = tenancy.getGlobalDB()
|
|
185
193
|
|
|
186
|
-
const config = await
|
|
187
|
-
type:
|
|
194
|
+
const config = await dbCore.getScopedConfig(db, {
|
|
195
|
+
type: ConfigType.GOOGLE,
|
|
188
196
|
workspace: ctx.query.workspace,
|
|
189
197
|
})
|
|
190
|
-
const callbackUrl = await
|
|
198
|
+
const callbackUrl = await googleCallbackUrl(config)
|
|
191
199
|
const strategy = await google.strategyFactory(
|
|
192
200
|
config,
|
|
193
201
|
callbackUrl,
|
|
@@ -208,14 +216,14 @@ export const googleAuth = async (ctx: any, next: any) => {
|
|
|
208
216
|
}
|
|
209
217
|
|
|
210
218
|
export const oidcStrategyFactory = async (ctx: any, configId: any) => {
|
|
211
|
-
const db = getGlobalDB()
|
|
212
|
-
const config = await
|
|
213
|
-
type:
|
|
219
|
+
const db = tenancy.getGlobalDB()
|
|
220
|
+
const config = await dbCore.getScopedConfig(db, {
|
|
221
|
+
type: ConfigType.OIDC,
|
|
214
222
|
group: ctx.query.group,
|
|
215
223
|
})
|
|
216
224
|
|
|
217
225
|
const chosenConfig = config.configs.filter((c: any) => c.uuid === configId)[0]
|
|
218
|
-
let callbackUrl = await
|
|
226
|
+
let callbackUrl = await oidcCallbackUrl(chosenConfig)
|
|
219
227
|
|
|
220
228
|
//Remote Config
|
|
221
229
|
const enrichedConfig = await oidc.fetchStrategyConfig(
|
|
@@ -233,11 +241,11 @@ export const oidcPreAuth = async (ctx: any, next: any) => {
|
|
|
233
241
|
const { configId } = ctx.params
|
|
234
242
|
const strategy = await oidcStrategyFactory(ctx, configId)
|
|
235
243
|
|
|
236
|
-
setCookie(ctx, configId,
|
|
244
|
+
setCookie(ctx, configId, Cookie.OIDC_CONFIG)
|
|
237
245
|
|
|
238
|
-
const db = getGlobalDB()
|
|
239
|
-
const config = await
|
|
240
|
-
type:
|
|
246
|
+
const db = tenancy.getGlobalDB()
|
|
247
|
+
const config = await dbCore.getScopedConfig(db, {
|
|
248
|
+
type: ConfigType.OIDC,
|
|
241
249
|
group: ctx.query.group,
|
|
242
250
|
})
|
|
243
251
|
|
|
@@ -255,7 +263,7 @@ export const oidcPreAuth = async (ctx: any, next: any) => {
|
|
|
255
263
|
}
|
|
256
264
|
|
|
257
265
|
export const oidcAuth = async (ctx: any, next: any) => {
|
|
258
|
-
const configId = getCookie(ctx,
|
|
266
|
+
const configId = getCookie(ctx, Cookie.OIDC_CONFIG)
|
|
259
267
|
const strategy = await oidcStrategyFactory(ctx, configId)
|
|
260
268
|
|
|
261
269
|
return passport.authenticate(
|