@lowdefy/build 0.0.0-experimental-20241107144205 → 0.0.0-experimental-20241113085758
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/build/buildApi/buildRoutine/controlTypes.js +3 -1
- package/dist/build/buildAuth/buildApiAuth.js +50 -0
- package/dist/build/buildAuth/buildAuth.js +4 -0
- package/dist/build/buildAuth/getApiRoles.js +33 -0
- package/dist/build/buildAuth/getProtectedApi.js +28 -0
- package/dist/build/buildAuth/validateAuthConfig.js +15 -9
- package/dist/build/buildAuth/validateMutualExclusivity.js +27 -0
- package/dist/build/buildJs/buildJs.js +5 -0
- package/dist/build/buildJs/writeJs.js +1 -1
- package/dist/defaultTypesMap.js +418 -418
- package/dist/lowdefySchema.js +58 -0
- package/package.json +38 -38
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/* eslint-disable no-param-reassign */ /*
|
|
2
|
+
Copyright 2020-2024 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 { type } from '@lowdefy/helpers';
|
|
16
|
+
import getApiRoles from './getApiRoles.js';
|
|
17
|
+
import getProtectedApi from './getProtectedApi.js';
|
|
18
|
+
function buildApiAuth({ components }) {
|
|
19
|
+
const protectedApiEndpoints = getProtectedApi({
|
|
20
|
+
components
|
|
21
|
+
});
|
|
22
|
+
const apiRoles = getApiRoles({
|
|
23
|
+
components
|
|
24
|
+
});
|
|
25
|
+
let configPublicApi = [];
|
|
26
|
+
if (type.isArray(components.auth.api.public)) {
|
|
27
|
+
configPublicApi = components.auth.api.public;
|
|
28
|
+
}
|
|
29
|
+
(components.api || []).forEach((endpoint)=>{
|
|
30
|
+
if (apiRoles[endpoint.id]) {
|
|
31
|
+
if (configPublicApi.includes(endpoint.id)) {
|
|
32
|
+
throw new Error(`Page "${endpoint.id}" is both protected by roles ${JSON.stringify(apiRoles[endpoint.id])} and public.`);
|
|
33
|
+
}
|
|
34
|
+
endpoint.auth = {
|
|
35
|
+
public: false,
|
|
36
|
+
roles: apiRoles[endpoint.id]
|
|
37
|
+
};
|
|
38
|
+
} else if (protectedApiEndpoints.includes(endpoint.id)) {
|
|
39
|
+
endpoint.auth = {
|
|
40
|
+
public: false
|
|
41
|
+
};
|
|
42
|
+
} else {
|
|
43
|
+
endpoint.auth = {
|
|
44
|
+
public: true
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return components;
|
|
49
|
+
}
|
|
50
|
+
export default buildApiAuth;
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import { type } from '@lowdefy/helpers';
|
|
16
16
|
import buildAuthPlugins from './buildAuthPlugins.js';
|
|
17
|
+
import buildApiAuth from './buildApiAuth.js';
|
|
17
18
|
import buildPageAuth from './buildPageAuth.js';
|
|
18
19
|
import validateAuthConfig from './validateAuthConfig.js';
|
|
19
20
|
let warningLogged = false;
|
|
@@ -37,6 +38,9 @@ function buildAuth({ components, context }) {
|
|
|
37
38
|
components
|
|
38
39
|
});
|
|
39
40
|
components.auth.configured = configured;
|
|
41
|
+
buildApiAuth({
|
|
42
|
+
components
|
|
43
|
+
});
|
|
40
44
|
buildPageAuth({
|
|
41
45
|
components
|
|
42
46
|
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2024 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
|
+
*/ function getApiRoles({ components }) {
|
|
16
|
+
const roles = components.auth.api.roles;
|
|
17
|
+
const apiRoles = {};
|
|
18
|
+
Object.keys(roles).forEach((roleName)=>{
|
|
19
|
+
roles[roleName].forEach((endpointId)=>{
|
|
20
|
+
if (!apiRoles[endpointId]) {
|
|
21
|
+
apiRoles[endpointId] = new Set();
|
|
22
|
+
}
|
|
23
|
+
apiRoles[endpointId].add(roleName);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
Object.keys(apiRoles).forEach((endpointId)=>{
|
|
27
|
+
apiRoles[endpointId] = [
|
|
28
|
+
...apiRoles[endpointId]
|
|
29
|
+
];
|
|
30
|
+
});
|
|
31
|
+
return apiRoles;
|
|
32
|
+
}
|
|
33
|
+
export default getApiRoles;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2024 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 { type } from '@lowdefy/helpers';
|
|
16
|
+
function getProtectedApi({ components }) {
|
|
17
|
+
const endpointIds = (components.api || []).map((endpoint)=>endpoint.id);
|
|
18
|
+
let protectedApi = [];
|
|
19
|
+
if (type.isArray(components.auth.api.public)) {
|
|
20
|
+
protectedApi = endpointIds.filter((endpointId)=>!components.auth.api.public.includes(endpointId));
|
|
21
|
+
} else if (components.auth.api.protected === true) {
|
|
22
|
+
protectedApi = endpointIds;
|
|
23
|
+
} else if (type.isArray(components.auth.api.protected)) {
|
|
24
|
+
protectedApi = components.auth.api.protected;
|
|
25
|
+
}
|
|
26
|
+
return protectedApi;
|
|
27
|
+
}
|
|
28
|
+
export default getProtectedApi;
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/ import { type } from '@lowdefy/helpers';
|
|
16
16
|
import { validate } from '@lowdefy/ajv';
|
|
17
17
|
import lowdefySchema from '../../lowdefySchema.js';
|
|
18
|
+
import validateMutualExclusivity from './validateMutualExclusivity.js';
|
|
18
19
|
async function validateAuthConfig({ components }) {
|
|
19
20
|
if (type.isNone(components.auth)) {
|
|
20
21
|
components.auth = {};
|
|
@@ -22,6 +23,12 @@ async function validateAuthConfig({ components }) {
|
|
|
22
23
|
if (!type.isObject(components.auth)) {
|
|
23
24
|
throw new Error('lowdefy.auth is not an object.');
|
|
24
25
|
}
|
|
26
|
+
if (type.isNone(components.auth.api)) {
|
|
27
|
+
components.auth.api = {};
|
|
28
|
+
}
|
|
29
|
+
if (type.isNone(components.auth.api.roles)) {
|
|
30
|
+
components.auth.api.roles = {};
|
|
31
|
+
}
|
|
25
32
|
if (type.isNone(components.auth.authPages)) {
|
|
26
33
|
components.auth.authPages = {};
|
|
27
34
|
}
|
|
@@ -50,15 +57,14 @@ async function validateAuthConfig({ components }) {
|
|
|
50
57
|
schema: lowdefySchema.definitions.authConfig,
|
|
51
58
|
data: components.auth
|
|
52
59
|
});
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
60
|
+
validateMutualExclusivity({
|
|
61
|
+
components,
|
|
62
|
+
entity: 'api'
|
|
63
|
+
});
|
|
64
|
+
validateMutualExclusivity({
|
|
65
|
+
components,
|
|
66
|
+
entity: 'pages'
|
|
67
|
+
});
|
|
62
68
|
return components;
|
|
63
69
|
}
|
|
64
70
|
export default validateAuthConfig;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/* eslint-disable no-param-reassign */ /*
|
|
2
|
+
Copyright 2020-2024 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 { type } from '@lowdefy/helpers';
|
|
16
|
+
function validateMutualExclusivity({ components, entity }) {
|
|
17
|
+
if (components.auth[entity].protected === true && components.auth[entity].public === true || type.isArray(components.auth[entity].protected) && type.isArray(components.auth[entity].public)) {
|
|
18
|
+
throw new Error(`Protected and public ${entity} are mutually exclusive. When protected ${entity} are listed, all unlisted ${entity} are public by default and vice versa.`);
|
|
19
|
+
}
|
|
20
|
+
if (components.auth[entity].protected === false) {
|
|
21
|
+
throw new Error(`Protected ${entity} can not be set to false.`);
|
|
22
|
+
}
|
|
23
|
+
if (components.auth[entity].public === false) {
|
|
24
|
+
throw new Error(`Public ${entity} can not be set to false.`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export default validateMutualExclusivity;
|
|
@@ -34,6 +34,11 @@ function buildJs({ components, context }) {
|
|
|
34
34
|
requests: cleanRequests
|
|
35
35
|
};
|
|
36
36
|
});
|
|
37
|
+
components.api = jsMapParser({
|
|
38
|
+
input: components.api,
|
|
39
|
+
jsMap: context.jsMap,
|
|
40
|
+
env: 'server'
|
|
41
|
+
});
|
|
37
42
|
components.connections = jsMapParser({
|
|
38
43
|
input: components.connections,
|
|
39
44
|
jsMap: context.jsMap,
|
|
@@ -20,7 +20,7 @@ async function writeJs({ context }) {
|
|
|
20
20
|
}));
|
|
21
21
|
await context.writeBuildArtifact('plugins/operators/serverJsMap.js', generateJsFile({
|
|
22
22
|
map: context.jsMap.server,
|
|
23
|
-
functionPrototype: `{ payload, secrets, user }`
|
|
23
|
+
functionPrototype: `{ payload, secrets, user, step, item, state }`
|
|
24
24
|
}));
|
|
25
25
|
}
|
|
26
26
|
export default writeJs;
|