@lowdefy/api 4.7.2 → 5.0.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/dist/context/createAuthorize.js +5 -0
- package/dist/context/createReadConfigFile.js +4 -0
- package/dist/routes/auth/callbacks/createSessionCallback.js +4 -0
- package/dist/routes/auth/callbacks/validateSessionRoles.js +33 -0
- package/dist/routes/rootConfig/getLowdefyTheme.js +19 -0
- package/dist/routes/rootConfig/getRootConfig.js +5 -2
- package/package.json +12 -12
|
@@ -18,6 +18,11 @@ function createAuthorize({ session }) {
|
|
|
18
18
|
// else session will be null
|
|
19
19
|
const authenticated = !!session;
|
|
20
20
|
const roles = session?.user?.roles ?? [];
|
|
21
|
+
if (!Array.isArray(roles)) {
|
|
22
|
+
throw new ConfigError('session.user.roles must be an array of strings.', {
|
|
23
|
+
received: roles
|
|
24
|
+
});
|
|
25
|
+
}
|
|
21
26
|
function authorize(config) {
|
|
22
27
|
const { auth } = config;
|
|
23
28
|
if (auth.public === true) return true;
|
|
@@ -15,8 +15,12 @@
|
|
|
15
15
|
*/ import path from 'path';
|
|
16
16
|
import { cachedPromises, serializer } from '@lowdefy/helpers';
|
|
17
17
|
import { getFileExtension, readFile } from '@lowdefy/node-utils';
|
|
18
|
+
const validPathPattern = /^[A-Za-z0-9\-_/.:]+$/;
|
|
18
19
|
function createReadConfigFile({ buildDirectory, fileCache }) {
|
|
19
20
|
async function readConfigFile(filePath) {
|
|
21
|
+
if (!validPathPattern.test(filePath) || filePath.includes('..')) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
20
24
|
const fileContent = await readFile(path.resolve(buildDirectory, filePath));
|
|
21
25
|
if (getFileExtension(filePath) === 'json') {
|
|
22
26
|
return serializer.deserializeFromString(fileContent);
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/ import crypto from 'crypto';
|
|
16
16
|
import addUserFieldsToSession from './addUserFieldsToSession.js';
|
|
17
17
|
import createCallbackPlugins from './createCallbackPlugins.js';
|
|
18
|
+
import validateSessionRoles from './validateSessionRoles.js';
|
|
18
19
|
function createSessionCallback({ authConfig, plugins }) {
|
|
19
20
|
const sessionCallbackPlugins = createCallbackPlugins({
|
|
20
21
|
authConfig,
|
|
@@ -67,6 +68,9 @@ function createSessionCallback({ authConfig, plugins }) {
|
|
|
67
68
|
user
|
|
68
69
|
});
|
|
69
70
|
}
|
|
71
|
+
validateSessionRoles({
|
|
72
|
+
session
|
|
73
|
+
});
|
|
70
74
|
// TODO: Should this be session.hashed_id or session.user.hashed_id
|
|
71
75
|
// Only session.user will be available using the _user operator
|
|
72
76
|
session.hashed_id = crypto.createHash('sha256').update(identifier ?? '').digest('base64');
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { ConfigError } from '@lowdefy/errors';
|
|
16
|
+
import { type } from '@lowdefy/helpers';
|
|
17
|
+
function validateSessionRoles({ session }) {
|
|
18
|
+
const roles = session?.user?.roles;
|
|
19
|
+
if (type.isNone(roles)) return;
|
|
20
|
+
if (!Array.isArray(roles)) {
|
|
21
|
+
throw new ConfigError('session.user.roles must be an array of strings. Check auth.userFields configuration and custom session callback plugins.', {
|
|
22
|
+
received: roles
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
for (const role of roles){
|
|
26
|
+
if (!type.isString(role)) {
|
|
27
|
+
throw new ConfigError('session.user.roles must be an array of strings. Check auth.userFields configuration and custom session callback plugins.', {
|
|
28
|
+
received: roles
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export default validateSessionRoles;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ async function getLowdefyTheme({ readConfigFile }) {
|
|
16
|
+
const theme = await readConfigFile('theme.json');
|
|
17
|
+
return theme || {};
|
|
18
|
+
}
|
|
19
|
+
export default getLowdefyTheme;
|
|
@@ -14,15 +14,18 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import getHomeAndMenus from './getHomeAndMenus.js';
|
|
16
16
|
import getLowdefyGlobal from './getLowdefyGlobal.js';
|
|
17
|
+
import getLowdefyTheme from './getLowdefyTheme.js';
|
|
17
18
|
async function getRootConfig(context) {
|
|
18
|
-
const [lowdefyGlobal, { home, menus }] = await Promise.all([
|
|
19
|
+
const [lowdefyGlobal, theme, { home, menus }] = await Promise.all([
|
|
19
20
|
getLowdefyGlobal(context),
|
|
21
|
+
getLowdefyTheme(context),
|
|
20
22
|
getHomeAndMenus(context)
|
|
21
23
|
]);
|
|
22
24
|
return {
|
|
23
25
|
home,
|
|
24
26
|
lowdefyGlobal,
|
|
25
|
-
menus
|
|
27
|
+
menus,
|
|
28
|
+
theme
|
|
26
29
|
};
|
|
27
30
|
}
|
|
28
31
|
export default getRootConfig;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/api",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -34,26 +34,26 @@
|
|
|
34
34
|
"dist/*"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@lowdefy/ajv": "
|
|
38
|
-
"@lowdefy/errors": "
|
|
39
|
-
"@lowdefy/helpers": "
|
|
40
|
-
"@lowdefy/node-utils": "
|
|
41
|
-
"@lowdefy/nunjucks": "
|
|
42
|
-
"@lowdefy/operators": "
|
|
43
|
-
"@lowdefy/operators-js": "
|
|
37
|
+
"@lowdefy/ajv": "5.0.0",
|
|
38
|
+
"@lowdefy/errors": "5.0.0",
|
|
39
|
+
"@lowdefy/helpers": "5.0.0",
|
|
40
|
+
"@lowdefy/node-utils": "5.0.0",
|
|
41
|
+
"@lowdefy/nunjucks": "5.0.0",
|
|
42
|
+
"@lowdefy/operators": "5.0.0",
|
|
43
|
+
"@lowdefy/operators-js": "5.0.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@jest/globals": "28.1.3",
|
|
47
|
-
"@swc/cli": "0.
|
|
48
|
-
"@swc/core": "1.
|
|
49
|
-
"@swc/jest": "0.2.
|
|
47
|
+
"@swc/cli": "0.8.0",
|
|
48
|
+
"@swc/core": "1.15.18",
|
|
49
|
+
"@swc/jest": "0.2.39",
|
|
50
50
|
"jest": "28.1.3"
|
|
51
51
|
},
|
|
52
52
|
"publishConfig": {
|
|
53
53
|
"access": "public"
|
|
54
54
|
},
|
|
55
55
|
"scripts": {
|
|
56
|
-
"build": "swc src --out-dir dist --config-file ../../.swcrc --
|
|
56
|
+
"build": "swc src --out-dir dist --config-file ../../.swcrc --cli-config-file ../../.swc-cli.json",
|
|
57
57
|
"clean": "rm -rf dist",
|
|
58
58
|
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
|
|
59
59
|
}
|