@lowdefy/api 4.0.0-alpha.26 → 4.0.0-alpha.29

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 (44) hide show
  1. package/package.json +11 -12
  2. package/dist/context/createApiContext.js +0 -35
  3. package/dist/context/createAuthorize.js +0 -33
  4. package/dist/context/createReadConfigFile.js +0 -28
  5. package/dist/context/errors.js +0 -33
  6. package/dist/index.js +0 -22
  7. package/dist/routes/auth/callbacks/addUserFieldsToSession.js +0 -27
  8. package/dist/routes/auth/callbacks/addUserFieldsToToken.js +0 -36
  9. package/dist/routes/auth/callbacks/createCallbackPlugins.js +0 -21
  10. package/dist/routes/auth/callbacks/createCallbacks.js +0 -43
  11. package/dist/routes/auth/callbacks/createJWTCallback.js +0 -75
  12. package/dist/routes/auth/callbacks/createRedirectCallback.js +0 -36
  13. package/dist/routes/auth/callbacks/createSessionCallback.js +0 -71
  14. package/dist/routes/auth/callbacks/createSignInCallback.js +0 -40
  15. package/dist/routes/auth/createAdapter.js +0 -24
  16. package/dist/routes/auth/createProviders.js +0 -25
  17. package/dist/routes/auth/events/createCreateUserEvent.js +0 -33
  18. package/dist/routes/auth/events/createEventPlugins.js +0 -21
  19. package/dist/routes/auth/events/createEvents.js +0 -55
  20. package/dist/routes/auth/events/createLinkAccountEvent.js +0 -35
  21. package/dist/routes/auth/events/createSessionEvent.js +0 -34
  22. package/dist/routes/auth/events/createSignInEvent.js +0 -36
  23. package/dist/routes/auth/events/createSignOutEvent.js +0 -34
  24. package/dist/routes/auth/events/createUpdateUserEvent.js +0 -33
  25. package/dist/routes/auth/getNextAuthConfig.js +0 -65
  26. package/dist/routes/page/getPageConfig.js +0 -23
  27. package/dist/routes/request/authorizeRequest.js +0 -28
  28. package/dist/routes/request/callRequest.js +0 -91
  29. package/dist/routes/request/callRequestResolver.js +0 -35
  30. package/dist/routes/request/checkConnectionRead.js +0 -29
  31. package/dist/routes/request/checkConnectionWrite.js +0 -29
  32. package/dist/routes/request/evaluateOperators.js +0 -43
  33. package/dist/routes/request/getConnection.js +0 -31
  34. package/dist/routes/request/getConnectionConfig.js +0 -42
  35. package/dist/routes/request/getRequestConfig.js +0 -31
  36. package/dist/routes/request/getRequestResolver.js +0 -31
  37. package/dist/routes/request/validateSchemas.js +0 -39
  38. package/dist/routes/rootConfig/getHomeAndMenus.js +0 -56
  39. package/dist/routes/rootConfig/getLowdefyGlobal.js +0 -19
  40. package/dist/routes/rootConfig/getRootConfig.js +0 -28
  41. package/dist/routes/rootConfig/menus/filterMenuList.js +0 -41
  42. package/dist/routes/rootConfig/menus/filterMenus.js +0 -29
  43. package/dist/routes/rootConfig/menus/getMenus.js +0 -22
  44. package/dist/test/testContext.js +0 -41
@@ -1,31 +0,0 @@
1
- /*
2
- Copyright 2020-2022 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;
@@ -1,31 +0,0 @@
1
- /*
2
- Copyright 2020-2022 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;
@@ -1,39 +0,0 @@
1
- /*
2
- Copyright 2020-2022 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;
@@ -1,56 +0,0 @@
1
- /*
2
- Copyright 2020-2022 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;
@@ -1,19 +0,0 @@
1
- /*
2
- Copyright 2020-2022 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;
@@ -1,28 +0,0 @@
1
- /*
2
- Copyright 2020-2022 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;
@@ -1,41 +0,0 @@
1
- /*
2
- Copyright 2020-2022 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;
@@ -1,29 +0,0 @@
1
- /*
2
- Copyright 2020-2022 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;
@@ -1,22 +0,0 @@
1
- /*
2
- Copyright 2020-2022 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;
@@ -1,41 +0,0 @@
1
- /*
2
- Copyright 2020-2022 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 ={} , host ='host' , logger ={
17
- debug: ()=>{},
18
- error: ()=>{},
19
- info: ()=>{},
20
- warn: ()=>{}
21
- } , operators ={
22
- _test: ()=>'test'
23
- } , readConfigFile , secrets ={} , setHeader , session , protocol ='https' , } = {}) {
24
- return {
25
- authorize: createAuthorize({
26
- session
27
- }),
28
- config,
29
- connections,
30
- headers,
31
- host,
32
- logger,
33
- operators,
34
- protocol,
35
- readConfigFile,
36
- secrets,
37
- setHeader,
38
- user: session?.user
39
- };
40
- }
41
- export default testContext;