@lowdefy/api 0.0.0-experimental-20231123101256

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.
Files changed (46) hide show
  1. package/LICENSE +201 -0
  2. package/dist/context/createApiContext.js +22 -0
  3. package/dist/context/createAuthorize.js +33 -0
  4. package/dist/context/createReadConfigFile.js +31 -0
  5. package/dist/context/errors.js +33 -0
  6. package/dist/index.js +22 -0
  7. package/dist/routes/auth/callbacks/addUserFieldsToSession.js +28 -0
  8. package/dist/routes/auth/callbacks/addUserFieldsToToken.js +30 -0
  9. package/dist/routes/auth/callbacks/createCallbackPlugins.js +21 -0
  10. package/dist/routes/auth/callbacks/createCallbacks.js +46 -0
  11. package/dist/routes/auth/callbacks/createJWTCallback.js +76 -0
  12. package/dist/routes/auth/callbacks/createRedirectCallback.js +41 -0
  13. package/dist/routes/auth/callbacks/createSessionCallback.js +76 -0
  14. package/dist/routes/auth/callbacks/createSignInCallback.js +40 -0
  15. package/dist/routes/auth/createAdapter.js +24 -0
  16. package/dist/routes/auth/createLogger.js +34 -0
  17. package/dist/routes/auth/createProviders.js +25 -0
  18. package/dist/routes/auth/events/createCreateUserEvent.js +41 -0
  19. package/dist/routes/auth/events/createEventPlugins.js +21 -0
  20. package/dist/routes/auth/events/createEvents.js +56 -0
  21. package/dist/routes/auth/events/createLinkAccountEvent.js +43 -0
  22. package/dist/routes/auth/events/createSessionEvent.js +34 -0
  23. package/dist/routes/auth/events/createSignInEvent.js +46 -0
  24. package/dist/routes/auth/events/createSignOutEvent.js +43 -0
  25. package/dist/routes/auth/events/createUpdateUserEvent.js +41 -0
  26. package/dist/routes/auth/getNextAuthConfig.js +73 -0
  27. package/dist/routes/page/getPageConfig.js +26 -0
  28. package/dist/routes/request/authorizeRequest.js +32 -0
  29. package/dist/routes/request/callRequest.js +92 -0
  30. package/dist/routes/request/callRequestResolver.js +40 -0
  31. package/dist/routes/request/checkConnectionRead.js +29 -0
  32. package/dist/routes/request/checkConnectionWrite.js +29 -0
  33. package/dist/routes/request/evaluateOperators.js +43 -0
  34. package/dist/routes/request/getConnection.js +31 -0
  35. package/dist/routes/request/getConnectionConfig.js +42 -0
  36. package/dist/routes/request/getRequestConfig.js +31 -0
  37. package/dist/routes/request/getRequestResolver.js +31 -0
  38. package/dist/routes/request/validateSchemas.js +39 -0
  39. package/dist/routes/rootConfig/getHomeAndMenus.js +56 -0
  40. package/dist/routes/rootConfig/getLowdefyGlobal.js +19 -0
  41. package/dist/routes/rootConfig/getRootConfig.js +28 -0
  42. package/dist/routes/rootConfig/menus/filterMenuList.js +41 -0
  43. package/dist/routes/rootConfig/menus/filterMenus.js +29 -0
  44. package/dist/routes/rootConfig/menus/getMenus.js +22 -0
  45. package/dist/test/testContext.js +38 -0
  46. package/package.json +59 -0
@@ -0,0 +1,92 @@
1
+ /*
2
+ Copyright 2020-2023 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 { serializer } from '@lowdefy/helpers';
16
+ import authorizeRequest from './authorizeRequest.js';
17
+ import callRequestResolver from './callRequestResolver.js';
18
+ import checkConnectionRead from './checkConnectionRead.js';
19
+ import checkConnectionWrite from './checkConnectionWrite.js';
20
+ import evaluateOperators from './evaluateOperators.js';
21
+ import getConnection from './getConnection.js';
22
+ import getConnectionConfig from './getConnectionConfig.js';
23
+ import getRequestConfig from './getRequestConfig.js';
24
+ import getRequestResolver from './getRequestResolver.js';
25
+ import validateSchemas from './validateSchemas.js';
26
+ async function callRequest(context, { blockId, pageId, payload, requestId }) {
27
+ const { logger } = context;
28
+ logger.debug({
29
+ event: 'debug_request',
30
+ blockId,
31
+ pageId,
32
+ payload,
33
+ requestId
34
+ });
35
+ const requestConfig = await getRequestConfig(context, {
36
+ pageId,
37
+ requestId
38
+ });
39
+ const connectionConfig = await getConnectionConfig(context, {
40
+ requestConfig
41
+ });
42
+ authorizeRequest(context, {
43
+ requestConfig
44
+ });
45
+ const connection = getConnection(context, {
46
+ connectionConfig
47
+ });
48
+ const requestResolver = getRequestResolver(context, {
49
+ connection,
50
+ requestConfig
51
+ });
52
+ const deserializedPayload = serializer.deserialize(payload);
53
+ const { connectionProperties, requestProperties } = evaluateOperators(context, {
54
+ connectionConfig,
55
+ payload: deserializedPayload,
56
+ requestConfig
57
+ });
58
+ checkConnectionRead(context, {
59
+ connectionConfig,
60
+ connectionProperties,
61
+ requestConfig,
62
+ requestResolver
63
+ });
64
+ checkConnectionWrite(context, {
65
+ connectionConfig,
66
+ connectionProperties,
67
+ requestConfig,
68
+ requestResolver
69
+ });
70
+ validateSchemas(context, {
71
+ connection,
72
+ connectionProperties,
73
+ requestConfig,
74
+ requestResolver,
75
+ requestProperties
76
+ });
77
+ const response = await callRequestResolver(context, {
78
+ blockId,
79
+ connectionProperties,
80
+ payload: deserializedPayload,
81
+ requestConfig,
82
+ requestProperties,
83
+ requestResolver
84
+ });
85
+ return {
86
+ id: requestConfig.id,
87
+ success: true,
88
+ type: requestConfig.type,
89
+ response: serializer.serialize(response)
90
+ };
91
+ }
92
+ export default callRequest;
@@ -0,0 +1,40 @@
1
+ /*
2
+ Copyright 2020-2023 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 { RequestError } from '../../context/errors.js';
16
+ async function callRequestResolver({ logger }, { blockId, connectionProperties, payload, requestConfig, requestProperties, requestResolver }) {
17
+ try {
18
+ const response = await requestResolver({
19
+ blockId,
20
+ connection: connectionProperties,
21
+ connectionId: requestConfig.connectionId,
22
+ pageId: requestConfig.pageId,
23
+ payload,
24
+ request: requestProperties,
25
+ requestId: requestConfig.requestId
26
+ });
27
+ return response;
28
+ } catch (error) {
29
+ const err = new RequestError(error.message);
30
+ logger.debug({
31
+ params: {
32
+ id: requestConfig.requestId,
33
+ type: requestConfig.type
34
+ },
35
+ err
36
+ }, err.message);
37
+ throw err;
38
+ }
39
+ }
40
+ export default callRequestResolver;
@@ -0,0 +1,29 @@
1
+ /*
2
+ Copyright 2020-2023 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 { ConfigurationError } from '../../context/errors.js';
16
+ function checkConnectionRead({ logger }, { connectionConfig, connectionProperties, requestConfig, requestResolver }) {
17
+ if (requestResolver.meta.checkRead && connectionProperties.read === false) {
18
+ const err = new ConfigurationError(`Connection "${connectionConfig.connectionId}" does not allow reads.`);
19
+ logger.debug({
20
+ params: {
21
+ connectionId: connectionConfig.connectionId,
22
+ requestId: requestConfig.requestId
23
+ },
24
+ err
25
+ }, err.message);
26
+ throw err;
27
+ }
28
+ }
29
+ export default checkConnectionRead;
@@ -0,0 +1,29 @@
1
+ /*
2
+ Copyright 2020-2023 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 { ConfigurationError } from '../../context/errors.js';
16
+ function checkConnectionWrite({ logger }, { connectionConfig, connectionProperties, requestConfig, requestResolver }) {
17
+ if (requestResolver.meta.checkWrite && connectionProperties.write !== true) {
18
+ const err = new ConfigurationError(`Connection "${connectionConfig.connectionId}" does not allow writes.`);
19
+ logger.debug({
20
+ params: {
21
+ connectionId: connectionConfig.connectionId,
22
+ requestId: requestConfig.requestId
23
+ },
24
+ err
25
+ }, err.message);
26
+ throw err;
27
+ }
28
+ }
29
+ export default checkConnectionWrite;
@@ -0,0 +1,43 @@
1
+ /*
2
+ Copyright 2020-2023 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 { ServerParser } from '@lowdefy/operators';
16
+ import { RequestError } from '../../context/errors.js';
17
+ function evaluateOperators({ operators, secrets, session }, { connectionConfig, payload, requestConfig }) {
18
+ const operatorsParser = new ServerParser({
19
+ operators,
20
+ payload,
21
+ secrets,
22
+ user: session?.user
23
+ });
24
+ const { output: connectionProperties, errors: connectionErrors } = operatorsParser.parse({
25
+ input: connectionConfig.properties || {},
26
+ location: connectionConfig.connectionId
27
+ });
28
+ if (connectionErrors.length > 0) {
29
+ throw new RequestError(connectionErrors[0]);
30
+ }
31
+ const { output: requestProperties, errors: requestErrors } = operatorsParser.parse({
32
+ input: requestConfig.properties || {},
33
+ location: requestConfig.requestId
34
+ });
35
+ if (requestErrors.length > 0) {
36
+ throw new RequestError(requestErrors[0]);
37
+ }
38
+ return {
39
+ connectionProperties,
40
+ requestProperties
41
+ };
42
+ }
43
+ export default evaluateOperators;
@@ -0,0 +1,31 @@
1
+ /*
2
+ Copyright 2020-2023 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 { ConfigurationError } from '../../context/errors.js';
16
+ function getConnection({ connections, logger }, { connectionConfig }) {
17
+ const connection = connections[connectionConfig.type];
18
+ if (!connection) {
19
+ const err = new ConfigurationError(`Connection type "${connectionConfig.type}" can not be found.`);
20
+ logger.debug({
21
+ params: {
22
+ id: connectionConfig.connectionId,
23
+ type: connectionConfig.type
24
+ },
25
+ err
26
+ }, err.message);
27
+ throw err;
28
+ }
29
+ return connection;
30
+ }
31
+ export default getConnection;
@@ -0,0 +1,42 @@
1
+ /*
2
+ Copyright 2020-2023 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 { ConfigurationError } from '../../context/errors.js';
16
+ async function getConnectionConfig({ logger, readConfigFile }, { requestConfig }) {
17
+ const { connectionId, requestId } = requestConfig;
18
+ let err;
19
+ if (!connectionId) {
20
+ err = new ConfigurationError(`Request "${requestId}" does not specify a connection.`);
21
+ logger.debug({
22
+ params: {
23
+ requestId
24
+ },
25
+ err
26
+ }, err.message);
27
+ throw err;
28
+ }
29
+ const connection = await readConfigFile(`connections/${connectionId}.json`);
30
+ if (!connection) {
31
+ err = new ConfigurationError(`Connection "${connectionId}" does not exist.`);
32
+ logger.debug({
33
+ params: {
34
+ requestId
35
+ },
36
+ err
37
+ }, err.message);
38
+ throw err;
39
+ }
40
+ return connection;
41
+ }
42
+ export default getConnectionConfig;
@@ -0,0 +1,31 @@
1
+ /*
2
+ Copyright 2020-2023 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 { ConfigurationError } from '../../context/errors.js';
16
+ async function getRequestConfig({ logger, readConfigFile }, { pageId, requestId }) {
17
+ const request = await readConfigFile(`pages/${pageId}/requests/${requestId}.json`);
18
+ if (!request) {
19
+ const err = new ConfigurationError(`Request "${requestId}" does not exist.`);
20
+ logger.debug({
21
+ params: {
22
+ pageId,
23
+ requestId
24
+ },
25
+ err
26
+ }, err.message);
27
+ throw err;
28
+ }
29
+ return request;
30
+ }
31
+ export default getRequestConfig;
@@ -0,0 +1,31 @@
1
+ /*
2
+ Copyright 2020-2023 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 { ConfigurationError } from '../../context/errors.js';
16
+ function getRequestResolver({ logger }, { connection, requestConfig }) {
17
+ const requestResolver = connection.requests[requestConfig.type];
18
+ if (!requestResolver) {
19
+ const err = new ConfigurationError(`Request type "${requestConfig.type}" can not be found.`);
20
+ logger.debug({
21
+ params: {
22
+ id: requestConfig.requestId,
23
+ type: requestConfig.type
24
+ },
25
+ err
26
+ }, err.message);
27
+ throw err;
28
+ }
29
+ return requestResolver;
30
+ }
31
+ export default getRequestResolver;
@@ -0,0 +1,39 @@
1
+ /*
2
+ Copyright 2020-2023 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 { validate } from '@lowdefy/ajv';
16
+ import { ConfigurationError } from '../../context/errors.js';
17
+ function validateSchemas({ logger }, { connection, connectionProperties, requestConfig, requestResolver, requestProperties }) {
18
+ try {
19
+ validate({
20
+ schema: connection.schema,
21
+ data: connectionProperties
22
+ });
23
+ validate({
24
+ schema: requestResolver.schema,
25
+ data: requestProperties
26
+ });
27
+ } catch (error) {
28
+ const err = new ConfigurationError(error.message);
29
+ logger.debug({
30
+ params: {
31
+ id: requestConfig.requestId,
32
+ type: requestConfig.type
33
+ },
34
+ err
35
+ }, err.message);
36
+ throw err;
37
+ }
38
+ }
39
+ export default validateSchemas;
@@ -0,0 +1,56 @@
1
+ /*
2
+ Copyright 2020-2023 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 { get } from '@lowdefy/helpers';
16
+ import getMenus from './menus/getMenus.js';
17
+ async function getHomeAndMenus(context) {
18
+ const menus = await getMenus(context);
19
+ const homePageId = get(context.config, 'homePageId');
20
+ if (homePageId) {
21
+ return {
22
+ home: {
23
+ configured: true,
24
+ pageId: homePageId
25
+ },
26
+ menus
27
+ };
28
+ }
29
+ let defaultMenu = menus.find((menu)=>menu.menuId === 'default');
30
+ if (!defaultMenu) {
31
+ // eslint-disable-next-line prefer-destructuring
32
+ defaultMenu = menus[0];
33
+ }
34
+ let pageId = null;
35
+ pageId = get(defaultMenu, 'links.0.pageId', {
36
+ default: null
37
+ });
38
+ if (!pageId) {
39
+ pageId = get(defaultMenu, 'links.0.links.0.pageId', {
40
+ default: null
41
+ });
42
+ }
43
+ if (!pageId) {
44
+ pageId = get(defaultMenu, 'links.0.links.0.links.0.pageId', {
45
+ default: null
46
+ });
47
+ }
48
+ return {
49
+ home: {
50
+ configured: false,
51
+ pageId
52
+ },
53
+ menus
54
+ };
55
+ }
56
+ export default getHomeAndMenus;
@@ -0,0 +1,19 @@
1
+ /*
2
+ Copyright 2020-2023 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 getLowdefyGlobal({ readConfigFile }) {
16
+ const lowdefyGlobal = await readConfigFile('global.json');
17
+ return lowdefyGlobal || {};
18
+ }
19
+ export default getLowdefyGlobal;
@@ -0,0 +1,28 @@
1
+ /*
2
+ Copyright 2020-2023 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 getHomeAndMenus from './getHomeAndMenus.js';
16
+ import getLowdefyGlobal from './getLowdefyGlobal.js';
17
+ async function getRootConfig(context) {
18
+ const [lowdefyGlobal, { home, menus }] = await Promise.all([
19
+ getLowdefyGlobal(context),
20
+ getHomeAndMenus(context)
21
+ ]);
22
+ return {
23
+ home,
24
+ lowdefyGlobal,
25
+ menus
26
+ };
27
+ }
28
+ export default getRootConfig;
@@ -0,0 +1,41 @@
1
+ /*
2
+ Copyright 2020-2023 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 { get } from '@lowdefy/helpers';
16
+ function filterMenuList(context, { menuList }) {
17
+ const { authorize } = context;
18
+ return menuList.map((item)=>{
19
+ if (item.type === 'MenuLink') {
20
+ if (authorize(item)) {
21
+ return item;
22
+ }
23
+ return null;
24
+ }
25
+ if (item.type === 'MenuGroup') {
26
+ const filteredSubItems = filterMenuList(context, {
27
+ menuList: get(item, 'links', {
28
+ default: []
29
+ })
30
+ });
31
+ if (filteredSubItems.length > 0) {
32
+ return {
33
+ ...item,
34
+ links: filteredSubItems
35
+ };
36
+ }
37
+ }
38
+ return null;
39
+ }).filter((item)=>item !== null);
40
+ }
41
+ export default filterMenuList;
@@ -0,0 +1,29 @@
1
+ /*
2
+ Copyright 2020-2023 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 { get } from '@lowdefy/helpers';
16
+ import filterMenuList from './filterMenuList.js';
17
+ function filterMenus(context, { menus }) {
18
+ return menus.map((menu)=>{
19
+ return {
20
+ ...menu,
21
+ links: filterMenuList(context, {
22
+ menuList: get(menu, 'links', {
23
+ default: []
24
+ })
25
+ })
26
+ };
27
+ });
28
+ }
29
+ export default filterMenus;
@@ -0,0 +1,22 @@
1
+ /*
2
+ Copyright 2020-2023 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 filterMenus from './filterMenus.js';
16
+ async function getMenus(context) {
17
+ const unfilteredMenus = await context.readConfigFile('menus.json');
18
+ return filterMenus(context, {
19
+ menus: unfilteredMenus || []
20
+ });
21
+ }
22
+ export default getMenus;
@@ -0,0 +1,38 @@
1
+ /*
2
+ Copyright 2020-2023 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 createAuthorize from '../context/createAuthorize.js';
16
+ function testContext({ config = {}, connections = {}, headers = {}, logger = {
17
+ debug: ()=>{},
18
+ error: ()=>{},
19
+ info: ()=>{},
20
+ warn: ()=>{}
21
+ }, operators = {
22
+ _test: ()=>'test'
23
+ }, readConfigFile, secrets = {}, session } = {}) {
24
+ return {
25
+ authorize: createAuthorize({
26
+ session
27
+ }),
28
+ config,
29
+ connections,
30
+ headers,
31
+ logger,
32
+ operators,
33
+ readConfigFile,
34
+ secrets,
35
+ session
36
+ };
37
+ }
38
+ export default testContext;