@lowdefy/build 3.23.2 → 4.0.0-alpha.6
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/addDefaultPages/404.js +51 -0
- package/dist/build/addDefaultPages/addDefaultPages.js +40 -0
- package/dist/build/buildAuth/buildAuth.js +50 -0
- package/dist/build/buildAuth/getPageRoles.js +33 -0
- package/dist/build/buildAuth/getProtectedPages.js +30 -0
- package/dist/build/buildConnections.js +46 -0
- package/dist/build/buildIcons.js +91 -0
- package/dist/build/buildMenu.js +122 -0
- package/dist/build/buildPages/buildBlock/buildBlock.js +31 -0
- package/dist/build/buildPages/buildBlock/buildEvents.js +72 -0
- package/dist/build/buildPages/buildBlock/buildRequests.js +51 -0
- package/dist/build/buildPages/buildBlock/buildSubBlocks.js +35 -0
- package/dist/build/buildPages/buildBlock/countBlockOperators.js +31 -0
- package/dist/build/buildPages/buildBlock/moveSubBlocksToArea.js +25 -0
- package/dist/build/buildPages/buildBlock/setBlockId.js +20 -0
- package/dist/build/buildPages/buildBlock/validateBlock.js +39 -0
- package/dist/build/buildPages/buildPage.js +50 -0
- package/dist/build/buildPages/buildPages.js +33 -0
- package/dist/build/buildRefs/buildRefs.js +25 -0
- package/dist/build/buildRefs/getConfigFile.js +28 -0
- package/dist/build/buildRefs/getRefContent.js +44 -0
- package/dist/build/buildRefs/getRefPath.js +30 -0
- package/dist/build/buildRefs/getRefsFromFile.js +37 -0
- package/dist/build/buildRefs/getUserJavascriptFunction.js +21 -0
- package/dist/build/buildRefs/makeRefDefinition.js +30 -0
- package/dist/build/buildRefs/parseNunjucks.js +20 -0
- package/dist/build/buildRefs/parseRefContent.js +37 -0
- package/dist/build/buildRefs/populateRefs.js +43 -0
- package/dist/build/buildRefs/recursiveBuild.js +62 -0
- package/dist/build/buildRefs/runRefResolver.js +33 -0
- package/dist/build/buildRefs/runTransformer.js +26 -0
- package/dist/build/buildStyles.js +29 -0
- package/dist/build/buildTypes.js +77 -0
- package/dist/build/cleanBuildDirectory.js +19 -0
- package/dist/build/testSchema.js +34 -0
- package/dist/build/updateServerPackageJson.js +49 -0
- package/dist/build/validateApp.js +34 -0
- package/dist/build/validateConfig.js +52 -0
- package/dist/build/writeApp.js +21 -0
- package/dist/build/writeConfig.js +21 -0
- package/dist/build/writeConnections.js +29 -0
- package/dist/build/writeGlobal.js +28 -0
- package/dist/build/writeMenus.js +25 -0
- package/dist/build/writePages.js +37 -0
- package/dist/build/writePluginImports/generateImportFile.js +36 -0
- package/dist/build/writePluginImports/writeBlockImports.js +25 -0
- package/dist/build/writePluginImports/writeConnectionImports.js +25 -0
- package/dist/build/writePluginImports/writeIconImports.js +34 -0
- package/dist/build/writePluginImports/writeOperatorImports.js +33 -0
- package/dist/build/writePluginImports/writeStyleImports.js +30 -0
- package/dist/build/writeRequests.js +37 -0
- package/dist/build/writeTypes.js +21 -0
- package/dist/defaultTypes.json +1159 -0
- package/dist/index.js +189 -1
- package/dist/lowdefySchema.js +709 -0
- package/dist/scripts/generateDefaultTypes.js +111 -0
- package/dist/scripts/run.js +28 -0
- package/dist/test/buildRefs/testBuildRefsAsyncFunction.js +22 -0
- package/dist/test/buildRefs/testBuildRefsErrorResolver.js +18 -0
- package/dist/test/buildRefs/testBuildRefsNullResolver.js +19 -0
- package/dist/test/buildRefs/testBuildRefsParsingResolver.js +39 -0
- package/dist/test/buildRefs/testBuildRefsResolver.js +23 -0
- package/dist/test/buildRefs/testBuildRefsTransform.js +25 -0
- package/dist/test/buildRefs/testBuildRefsTransformIdentity.js +21 -0
- package/dist/test/testContext.js +48 -0
- package/dist/utils/countOperators.js +30 -0
- package/dist/utils/createCheckDuplicateId.js +31 -0
- package/dist/utils/createCounter.js +33 -0
- package/dist/utils/files/readConfigFile.js +24 -0
- package/dist/utils/files/writeBuildArtifact.js +26 -0
- package/dist/utils/formatErrorMessage.js +56 -0
- package/package.json +39 -21
- package/dist/138.index.js +0 -2
- package/dist/138.index.js.LICENSE.txt +0 -3
- package/dist/231.index.js +0 -1
- package/dist/319.index.js +0 -1
- package/dist/35.index.js +0 -1
- package/dist/422.index.js +0 -1
- package/dist/443.index.js +0 -1
- package/dist/449.index.js +0 -1
- package/dist/5.index.js +0 -2
- package/dist/5.index.js.LICENSE.txt +0 -1
- package/dist/564.index.js +0 -1
- package/dist/569.index.js +0 -1
- package/dist/625.index.js +0 -1
- package/dist/693.index.js +0 -2
- package/dist/693.index.js.LICENSE.txt +0 -1
- package/dist/734.index.js +0 -1
- package/dist/904.index.js +0 -1
- package/dist/remoteEntry.js +0 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 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
|
+
*/ export default {
|
|
16
|
+
id: '404',
|
|
17
|
+
type: 'Result',
|
|
18
|
+
style: {
|
|
19
|
+
minHeight: '100vh'
|
|
20
|
+
},
|
|
21
|
+
properties: {
|
|
22
|
+
status: 404,
|
|
23
|
+
title: '404',
|
|
24
|
+
subTitle: 'Sorry, the page you are visiting does not exist.'
|
|
25
|
+
},
|
|
26
|
+
areas: {
|
|
27
|
+
extra: {
|
|
28
|
+
blocks: [
|
|
29
|
+
{
|
|
30
|
+
id: 'home',
|
|
31
|
+
type: 'Button',
|
|
32
|
+
properties: {
|
|
33
|
+
title: 'Go to home page',
|
|
34
|
+
type: 'Link'
|
|
35
|
+
},
|
|
36
|
+
events: {
|
|
37
|
+
onClick: [
|
|
38
|
+
{
|
|
39
|
+
id: 'home',
|
|
40
|
+
type: 'Link',
|
|
41
|
+
params: {
|
|
42
|
+
home: true
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
]
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 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 page404 from './404.js';
|
|
17
|
+
async function addDefaultPages({ components }) {
|
|
18
|
+
// If not copied, the same object is mutated by build every time
|
|
19
|
+
// build runs for dev server. See #647
|
|
20
|
+
const defaultPages = [
|
|
21
|
+
JSON.parse(JSON.stringify(page404))
|
|
22
|
+
];
|
|
23
|
+
if (type.isNone(components.pages)) {
|
|
24
|
+
components.pages = [];
|
|
25
|
+
}
|
|
26
|
+
if (!type.isArray(components.pages)) {
|
|
27
|
+
throw new Error('lowdefy.pages is not an array.');
|
|
28
|
+
}
|
|
29
|
+
const pageIds = components.pages.map((page)=>page.id
|
|
30
|
+
);
|
|
31
|
+
// deep copy to avoid mutating defaultConfig
|
|
32
|
+
const filteredDefaultPages = defaultPages.filter((defaultPage)=>!pageIds.includes(defaultPage.id)
|
|
33
|
+
);
|
|
34
|
+
components.pages = [
|
|
35
|
+
...components.pages,
|
|
36
|
+
...filteredDefaultPages
|
|
37
|
+
];
|
|
38
|
+
return components;
|
|
39
|
+
}
|
|
40
|
+
export default addDefaultPages;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/* eslint-disable no-param-reassign */ /*
|
|
2
|
+
Copyright 2020-2021 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 getPageRoles from './getPageRoles.js';
|
|
17
|
+
import getProtectedPages from './getProtectedPages.js';
|
|
18
|
+
function buildAuth({ components }) {
|
|
19
|
+
const protectedPages = getProtectedPages({
|
|
20
|
+
components
|
|
21
|
+
});
|
|
22
|
+
const pageRoles = getPageRoles({
|
|
23
|
+
components
|
|
24
|
+
});
|
|
25
|
+
let configPublicPages = [];
|
|
26
|
+
if (type.isArray(components.config.auth.pages.public)) {
|
|
27
|
+
configPublicPages = components.config.auth.pages.public;
|
|
28
|
+
}
|
|
29
|
+
(components.pages || []).forEach((page)=>{
|
|
30
|
+
if (pageRoles[page.id]) {
|
|
31
|
+
if (configPublicPages.includes(page.id)) {
|
|
32
|
+
throw new Error(`Page "${page.id}" is both protected by roles ${JSON.stringify(pageRoles[page.id])} and public.`);
|
|
33
|
+
}
|
|
34
|
+
page.auth = {
|
|
35
|
+
public: false,
|
|
36
|
+
roles: pageRoles[page.id]
|
|
37
|
+
};
|
|
38
|
+
} else if (protectedPages.includes(page.id)) {
|
|
39
|
+
page.auth = {
|
|
40
|
+
public: false
|
|
41
|
+
};
|
|
42
|
+
} else {
|
|
43
|
+
page.auth = {
|
|
44
|
+
public: true
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return components;
|
|
49
|
+
}
|
|
50
|
+
export default buildAuth;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 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 getPageRoles({ components }) {
|
|
16
|
+
const roles = components.config.auth.pages.roles;
|
|
17
|
+
const pageRoles = {};
|
|
18
|
+
Object.keys(roles).forEach((roleName)=>{
|
|
19
|
+
roles[roleName].forEach((pageId)=>{
|
|
20
|
+
if (!pageRoles[pageId]) {
|
|
21
|
+
pageRoles[pageId] = new Set();
|
|
22
|
+
}
|
|
23
|
+
pageRoles[pageId].add(roleName);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
Object.keys(pageRoles).forEach((pageId)=>{
|
|
27
|
+
pageRoles[pageId] = [
|
|
28
|
+
...pageRoles[pageId]
|
|
29
|
+
];
|
|
30
|
+
});
|
|
31
|
+
return pageRoles;
|
|
32
|
+
}
|
|
33
|
+
export default getPageRoles;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 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 getProtectedPages({ components }) {
|
|
17
|
+
const pageIds = (components.pages || []).map((page)=>page.id
|
|
18
|
+
);
|
|
19
|
+
let protectedPages = [];
|
|
20
|
+
if (type.isArray(components.config.auth.pages.public)) {
|
|
21
|
+
protectedPages = pageIds.filter((pageId)=>!components.config.auth.pages.public.includes(pageId)
|
|
22
|
+
);
|
|
23
|
+
} else if (components.config.auth.pages.protected === true) {
|
|
24
|
+
protectedPages = pageIds;
|
|
25
|
+
} else if (type.isArray(components.config.auth.pages.protected)) {
|
|
26
|
+
protectedPages = components.config.auth.pages.protected;
|
|
27
|
+
}
|
|
28
|
+
return protectedPages;
|
|
29
|
+
}
|
|
30
|
+
export default getProtectedPages;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/* eslint-disable no-param-reassign */ /*
|
|
2
|
+
Copyright 2020-2021 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 countOperators from '../utils/countOperators.js';
|
|
17
|
+
import createCheckDuplicateId from '../utils/createCheckDuplicateId.js';
|
|
18
|
+
async function buildConnections({ components , context }) {
|
|
19
|
+
const checkDuplicateConnectionId = createCheckDuplicateId({
|
|
20
|
+
message: 'Duplicate connectionId "{{ id }}".'
|
|
21
|
+
});
|
|
22
|
+
if (type.isArray(components.connections)) {
|
|
23
|
+
components.connections.forEach((connection)=>{
|
|
24
|
+
if (type.isUndefined(connection.id)) {
|
|
25
|
+
throw new Error(`Connection id missing.`);
|
|
26
|
+
}
|
|
27
|
+
if (!type.isString(connection.id)) {
|
|
28
|
+
throw new Error(`Connection id is not a string. Received ${JSON.stringify(connection.id)}.`);
|
|
29
|
+
}
|
|
30
|
+
checkDuplicateConnectionId({
|
|
31
|
+
id: connection.id
|
|
32
|
+
});
|
|
33
|
+
if (!type.isString(connection.type)) {
|
|
34
|
+
throw new Error(`Connection type is not a string at connection "${connection.id}". Received ${JSON.stringify(connection.type)}.`);
|
|
35
|
+
}
|
|
36
|
+
context.typeCounters.connections.increment(connection.type);
|
|
37
|
+
connection.connectionId = connection.id;
|
|
38
|
+
connection.id = `connection:${connection.id}`;
|
|
39
|
+
countOperators(connection.properties || {}, {
|
|
40
|
+
counter: context.typeCounters.operators.server
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return components;
|
|
45
|
+
}
|
|
46
|
+
export default buildConnections;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 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
|
+
*/ const iconPackages = {
|
|
16
|
+
'react-icons/ai': /"(Ai[A-Z0-9]\w*)"/gm,
|
|
17
|
+
'react-icons/bs': /"(Bs[A-Z0-9]\w*)"/gm,
|
|
18
|
+
'react-icons/bi': /"(Bi[A-Z0-9]\w*)"/gm,
|
|
19
|
+
'react-icons/di': /"(Di[A-Z0-9]\w*)"/gm,
|
|
20
|
+
'react-icons/fi': /"(Fi[A-Z0-9]\w*)"/gm,
|
|
21
|
+
'react-icons/fc': /"(Fc[A-Z0-9]\w*)"/gm,
|
|
22
|
+
'react-icons/fa': /"(Fa[A-Z0-9]\w*)"/gm,
|
|
23
|
+
'react-icons/gi': /"(Gi[A-Z0-9]\w*)"/gm,
|
|
24
|
+
'react-icons/go': /"(Go[A-Z0-9]\w*)"/gm,
|
|
25
|
+
'react-icons/gr': /"(Gr[A-Z0-9]\w*)"/gm,
|
|
26
|
+
'react-icons/hi': /"(Hi[A-Z0-9]\w*)"/gm,
|
|
27
|
+
'react-icons/im': /"(Im[A-Z0-9]\w*)"/gm,
|
|
28
|
+
'react-icons/io': /"(IoIos[A-Z0-9]\w*)"/gm,
|
|
29
|
+
'react-icons/io5': /"(Io[A-Z0-9]\w*)"/gm,
|
|
30
|
+
'react-icons/md': /"(Md[A-Z0-9]\w*)"/gm,
|
|
31
|
+
'react-icons/ri': /"(Ri[A-Z0-9]\w*)"/gm,
|
|
32
|
+
'react-icons/si': /"(Si[A-Z0-9]\w*)"/gm,
|
|
33
|
+
'react-icons/ti': /"(Ti[A-Z0-9]\w*)"/gm,
|
|
34
|
+
'react-icons/vsc': /"(Vsc[A-Z0-9]\w*)"/gm,
|
|
35
|
+
'react-icons/wi': /"(Wi[A-Z0-9]\w*)"/gm,
|
|
36
|
+
'react-icons/cg': /"(Cg[A-Z0-9]\w*)"/gm
|
|
37
|
+
};
|
|
38
|
+
function getConfigIcons({ components , icons , regex }) {
|
|
39
|
+
[
|
|
40
|
+
...JSON.stringify(components.global || {}).matchAll(regex)
|
|
41
|
+
].map((match)=>icons.add(match[1])
|
|
42
|
+
);
|
|
43
|
+
[
|
|
44
|
+
...JSON.stringify(components.menus || []).matchAll(regex)
|
|
45
|
+
].map((match)=>icons.add(match[1])
|
|
46
|
+
);
|
|
47
|
+
[
|
|
48
|
+
...JSON.stringify(components.pages || []).matchAll(regex)
|
|
49
|
+
].map((match)=>icons.add(match[1])
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
function getBlockDefaultIcons({ components , context , icons , regex }) {
|
|
53
|
+
Object.entries(components.types.blocks).forEach(([blockName, block])=>{
|
|
54
|
+
context.types.icons[block.package][blockName].forEach((icon)=>{
|
|
55
|
+
[
|
|
56
|
+
...JSON.stringify(icon).matchAll(regex)
|
|
57
|
+
].map((match)=>icons.add(match[1])
|
|
58
|
+
);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function buildIcons({ components , context }) {
|
|
63
|
+
components.icons = [];
|
|
64
|
+
Object.entries(iconPackages).forEach(([iconPackage, regex])=>{
|
|
65
|
+
const icons = new Set();
|
|
66
|
+
// TODO: Can we do better than this?
|
|
67
|
+
// Add default icons
|
|
68
|
+
if (iconPackage === 'react-icons/ai') {
|
|
69
|
+
icons.add('AiOutlineLoading3Quarters');
|
|
70
|
+
icons.add('AiOutlineExclamationCircle');
|
|
71
|
+
}
|
|
72
|
+
getConfigIcons({
|
|
73
|
+
components,
|
|
74
|
+
icons,
|
|
75
|
+
regex
|
|
76
|
+
});
|
|
77
|
+
getBlockDefaultIcons({
|
|
78
|
+
components,
|
|
79
|
+
context,
|
|
80
|
+
icons,
|
|
81
|
+
regex
|
|
82
|
+
});
|
|
83
|
+
components.icons.push({
|
|
84
|
+
icons: [
|
|
85
|
+
...icons
|
|
86
|
+
],
|
|
87
|
+
package: iconPackage
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
export default buildIcons;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/* eslint-disable no-param-reassign */ /*
|
|
2
|
+
Copyright 2020-2021 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 createCheckDuplicateId from '../utils/createCheckDuplicateId.js';
|
|
17
|
+
async function buildDefaultMenu({ components , context }) {
|
|
18
|
+
context.logger.warn('No menus found. Building default menu.');
|
|
19
|
+
const pages = type.isArray(components.pages) ? components.pages : [];
|
|
20
|
+
const menus = [
|
|
21
|
+
{
|
|
22
|
+
id: 'default',
|
|
23
|
+
links: pages.map((page, i)=>({
|
|
24
|
+
id: `${i}`,
|
|
25
|
+
type: 'MenuLink',
|
|
26
|
+
pageId: page.pageId,
|
|
27
|
+
auth: page.auth
|
|
28
|
+
})
|
|
29
|
+
).filter((page)=>page.pageId !== '404'
|
|
30
|
+
)
|
|
31
|
+
},
|
|
32
|
+
];
|
|
33
|
+
return menus;
|
|
34
|
+
}
|
|
35
|
+
function loopItems({ parent , menuId , pages , missingPageWarnings , checkDuplicateMenuItemId }) {
|
|
36
|
+
if (type.isArray(parent.links)) {
|
|
37
|
+
parent.links.forEach((menuItem)=>{
|
|
38
|
+
if (menuItem.type === 'MenuLink') {
|
|
39
|
+
if (type.isString(menuItem.pageId)) {
|
|
40
|
+
const page = pages.find((pg)=>pg.pageId === menuItem.pageId
|
|
41
|
+
);
|
|
42
|
+
if (!page) {
|
|
43
|
+
missingPageWarnings.push({
|
|
44
|
+
menuItemId: menuItem.id,
|
|
45
|
+
pageId: menuItem.pageId
|
|
46
|
+
});
|
|
47
|
+
// remove menuItem from menu
|
|
48
|
+
menuItem.remove = true;
|
|
49
|
+
return;
|
|
50
|
+
} else {
|
|
51
|
+
menuItem.auth = page.auth;
|
|
52
|
+
}
|
|
53
|
+
} else {
|
|
54
|
+
menuItem.auth = {
|
|
55
|
+
public: true
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (menuItem.type === 'MenuGroup') {
|
|
60
|
+
menuItem.auth = {
|
|
61
|
+
public: true
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
checkDuplicateMenuItemId({
|
|
65
|
+
id: menuItem.id,
|
|
66
|
+
menuId
|
|
67
|
+
});
|
|
68
|
+
menuItem.menuItemId = menuItem.id;
|
|
69
|
+
menuItem.id = `menuitem:${menuId}:${menuItem.id}`;
|
|
70
|
+
loopItems({
|
|
71
|
+
parent: menuItem,
|
|
72
|
+
menuId,
|
|
73
|
+
pages,
|
|
74
|
+
missingPageWarnings,
|
|
75
|
+
checkDuplicateMenuItemId
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
parent.links = parent.links.filter((item)=>item.remove !== true
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async function buildMenu({ components , context }) {
|
|
83
|
+
const pages = type.isArray(components.pages) ? components.pages : [];
|
|
84
|
+
if (type.isUndefined(components.menus) || components.menus.length === 0) {
|
|
85
|
+
components.menus = await buildDefaultMenu({
|
|
86
|
+
components,
|
|
87
|
+
context
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
const missingPageWarnings = [];
|
|
91
|
+
const checkDuplicateMenuId = createCheckDuplicateId({
|
|
92
|
+
message: 'Duplicate menuId "{{ id }}".'
|
|
93
|
+
});
|
|
94
|
+
components.menus.forEach((menu)=>{
|
|
95
|
+
if (type.isUndefined(menu.id)) {
|
|
96
|
+
throw new Error(`Menu id missing.`);
|
|
97
|
+
}
|
|
98
|
+
if (!type.isString(menu.id)) {
|
|
99
|
+
throw new Error(`Menu id is not a string. Received ${JSON.stringify(menu.id)}.`);
|
|
100
|
+
}
|
|
101
|
+
checkDuplicateMenuId({
|
|
102
|
+
id: menu.id
|
|
103
|
+
});
|
|
104
|
+
menu.menuId = menu.id;
|
|
105
|
+
menu.id = `menu:${menu.id}`;
|
|
106
|
+
const checkDuplicateMenuItemId = createCheckDuplicateId({
|
|
107
|
+
message: 'Duplicate menuItemId "{{ id }}" on menu "{{ menuId }}".'
|
|
108
|
+
});
|
|
109
|
+
loopItems({
|
|
110
|
+
parent: menu,
|
|
111
|
+
menuId: menu.menuId,
|
|
112
|
+
pages,
|
|
113
|
+
missingPageWarnings,
|
|
114
|
+
checkDuplicateMenuItemId
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
await Promise.all(missingPageWarnings.map(async (warning)=>{
|
|
118
|
+
await context.logger.warn(`Page "${warning.pageId}" referenced in menu link "${warning.menuItemId}" not found.`);
|
|
119
|
+
}));
|
|
120
|
+
return components;
|
|
121
|
+
}
|
|
122
|
+
export default buildMenu;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 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 buildEvents from './buildEvents.js';
|
|
16
|
+
import buildRequests from './buildRequests.js';
|
|
17
|
+
import buildSubBlocks from './buildSubBlocks.js';
|
|
18
|
+
import countBlockOperators from './countBlockOperators.js';
|
|
19
|
+
import moveSubBlocksToArea from './moveSubBlocksToArea.js';
|
|
20
|
+
import setBlockId from './setBlockId.js';
|
|
21
|
+
import validateBlock from './validateBlock.js';
|
|
22
|
+
async function buildBlock(block, pageContext) {
|
|
23
|
+
validateBlock(block, pageContext);
|
|
24
|
+
countBlockOperators(block, pageContext);
|
|
25
|
+
setBlockId(block, pageContext);
|
|
26
|
+
buildEvents(block, pageContext);
|
|
27
|
+
buildRequests(block, pageContext);
|
|
28
|
+
moveSubBlocksToArea(block, pageContext);
|
|
29
|
+
await buildSubBlocks(block, pageContext);
|
|
30
|
+
}
|
|
31
|
+
export default buildBlock;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 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 createCheckDuplicateId from '../../../utils/createCheckDuplicateId.js';
|
|
17
|
+
function checkAction(action, { blockId , checkDuplicateActionId , eventId , pageId , typeCounters }) {
|
|
18
|
+
if (type.isUndefined(action.id)) {
|
|
19
|
+
throw new Error(`Action id missing on event "${eventId}" on block "${blockId}" on page "${pageId}".`);
|
|
20
|
+
}
|
|
21
|
+
if (!type.isString(action.id)) {
|
|
22
|
+
throw new Error(`Action id is not a string on event "${eventId}" on block "${blockId}" on page "${pageId}". Received ${JSON.stringify(action.id)}.`);
|
|
23
|
+
}
|
|
24
|
+
checkDuplicateActionId({
|
|
25
|
+
id: action.id,
|
|
26
|
+
eventId,
|
|
27
|
+
blockId,
|
|
28
|
+
pageId
|
|
29
|
+
});
|
|
30
|
+
if (!type.isString(action.type)) {
|
|
31
|
+
throw new Error(`Action type is not a string on action "${action.id}" on event "${eventId}" on block "${blockId}" on page "${pageId}". Received ${JSON.stringify(action.type)}.`);
|
|
32
|
+
}
|
|
33
|
+
typeCounters.actions.increment(action.type);
|
|
34
|
+
}
|
|
35
|
+
function buildEvents(block, pageContext) {
|
|
36
|
+
if (block.events) {
|
|
37
|
+
Object.keys(block.events).map((key)=>{
|
|
38
|
+
if (type.isArray(block.events[key])) {
|
|
39
|
+
block.events[key] = {
|
|
40
|
+
try: block.events[key],
|
|
41
|
+
catch: []
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
if (!type.isArray(block.events[key].try)) {
|
|
45
|
+
throw new Error(`Events must be an array of actions at "${block.blockId}" in event "${key}" on page "${pageContext.pageId}". Received ${JSON.stringify(block.events[key].try)}`);
|
|
46
|
+
}
|
|
47
|
+
if (!type.isArray(block.events[key].catch) && !type.isNone(block.events[key].catch)) {
|
|
48
|
+
throw new Error(`Catch events must be an array of actions at "${block.blockId}" in event "${key}" on page "${pageContext.pageId}". Received ${JSON.stringify(block.events[key].catch)}`);
|
|
49
|
+
}
|
|
50
|
+
const checkDuplicateActionId = createCheckDuplicateId({
|
|
51
|
+
message: 'Duplicate actionId "{{ id }}" on event "{{ eventId }}" on block "{{ blockId }}" on page "{{ pageId }}".'
|
|
52
|
+
});
|
|
53
|
+
block.events[key].try.map((action)=>checkAction(action, {
|
|
54
|
+
eventId: key,
|
|
55
|
+
blockId: block.blockId,
|
|
56
|
+
typeCounters: pageContext.typeCounters,
|
|
57
|
+
pageId: pageContext.pageId,
|
|
58
|
+
checkDuplicateActionId
|
|
59
|
+
})
|
|
60
|
+
);
|
|
61
|
+
block.events[key].catch.map((action)=>checkAction(action, {
|
|
62
|
+
eventId: key,
|
|
63
|
+
blockId: block.blockId,
|
|
64
|
+
typeCounters: pageContext.typeCounters,
|
|
65
|
+
pageId: pageContext.pageId,
|
|
66
|
+
checkDuplicateActionId
|
|
67
|
+
})
|
|
68
|
+
);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export default buildEvents;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 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 buildRequest(request, pageContext) {
|
|
17
|
+
const { auth , checkDuplicateRequestId , pageId , typeCounters } = pageContext;
|
|
18
|
+
if (type.isUndefined(request.id)) {
|
|
19
|
+
throw new Error(`Request id missing at page "${pageId}".`);
|
|
20
|
+
}
|
|
21
|
+
if (!type.isString(request.id)) {
|
|
22
|
+
throw new Error(`Request id is not a string at page "${pageId}". Received ${JSON.stringify(request.id)}.`);
|
|
23
|
+
}
|
|
24
|
+
checkDuplicateRequestId({
|
|
25
|
+
id: request.id,
|
|
26
|
+
pageId
|
|
27
|
+
});
|
|
28
|
+
if (request.id.includes('.')) {
|
|
29
|
+
throw new Error(`Request id "${request.id}" at page "${pageId}" should not include a period (".").`);
|
|
30
|
+
}
|
|
31
|
+
if (!type.isString(request.type)) {
|
|
32
|
+
throw new Error(`Request type is not a string at at request at "${request.id}" at page "${pageId}". Received ${JSON.stringify(request.type)}.`);
|
|
33
|
+
}
|
|
34
|
+
typeCounters.requests.increment(request.type);
|
|
35
|
+
if (type.isUndefined(request.payload)) request.payload = {};
|
|
36
|
+
if (!type.isObject(request.payload)) {
|
|
37
|
+
throw new Error(`Request "${request.id}" at page "${pageId}" payload should be an object.`);
|
|
38
|
+
}
|
|
39
|
+
request.auth = auth;
|
|
40
|
+
request.requestId = request.id;
|
|
41
|
+
request.pageId = pageId;
|
|
42
|
+
request.id = `request:${pageId}:${request.id}`;
|
|
43
|
+
pageContext.requests.push(request);
|
|
44
|
+
}
|
|
45
|
+
function buildRequests(block, pageContext) {
|
|
46
|
+
(block.requests || []).forEach((request)=>{
|
|
47
|
+
buildRequest(request, pageContext);
|
|
48
|
+
});
|
|
49
|
+
delete block.requests;
|
|
50
|
+
}
|
|
51
|
+
export default buildRequests;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 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 buildBlock from './buildBlock.js';
|
|
17
|
+
async function buildSubBlocks(block, pageContext) {
|
|
18
|
+
if (type.isObject(block.areas)) {
|
|
19
|
+
let promises = [];
|
|
20
|
+
Object.keys(block.areas).forEach((key)=>{
|
|
21
|
+
if (type.isNone(block.areas[key].blocks)) {
|
|
22
|
+
block.areas[key].blocks = [];
|
|
23
|
+
}
|
|
24
|
+
if (!type.isArray(block.areas[key].blocks)) {
|
|
25
|
+
throw new Error(`Expected blocks to be an array at ${block.blockId} in area ${key} on page ${pageContext.pageId}. Received ${JSON.stringify(block.areas[key].blocks)}`);
|
|
26
|
+
}
|
|
27
|
+
const blockPromises = block.areas[key].blocks.map(async (blk)=>{
|
|
28
|
+
await buildBlock(blk, pageContext);
|
|
29
|
+
});
|
|
30
|
+
promises = promises.concat(blockPromises);
|
|
31
|
+
});
|
|
32
|
+
await Promise.all(promises);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export default buildSubBlocks;
|