@lowdefy/build 0.0.0-experimental-20241107140648 → 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.
@@ -46,7 +46,9 @@ const controlTypes = {
46
46
  ':log'
47
47
  ],
48
48
  routine: [],
49
- optional: []
49
+ optional: [
50
+ ':level'
51
+ ]
50
52
  },
51
53
  ':parallel': {
52
54
  required: [
@@ -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
- if (components.auth.pages.protected === true && components.auth.pages.public === true || type.isArray(components.auth.pages.protected) && type.isArray(components.auth.pages.public)) {
54
- throw new Error('Protected and public pages are mutually exclusive. When protected pages are listed, all unlisted pages are public by default and visa versa.');
55
- }
56
- if (components.auth.pages.protected === false) {
57
- throw new Error('Protected pages can not be set to false.');
58
- }
59
- if (components.auth.pages.public === false) {
60
- throw new Error('Public pages can not be set to false.');
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;