@lowdefy/build 4.4.0 → 4.5.0

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.
@@ -0,0 +1,214 @@
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
+ import buildRoutine from './buildRoutine.js';
17
+ import countControl from './countControl.js';
18
+ import countOperators from '../../../utils/countOperators.js';
19
+ const controlTypes = {
20
+ ':for': {
21
+ required: [
22
+ ':for',
23
+ ':in',
24
+ ':do'
25
+ ],
26
+ routine: [
27
+ ':do'
28
+ ],
29
+ optional: []
30
+ },
31
+ ':if': {
32
+ required: [
33
+ ':if',
34
+ ':then'
35
+ ],
36
+ routine: [
37
+ ':then',
38
+ ':else'
39
+ ],
40
+ optional: [
41
+ ':else'
42
+ ]
43
+ },
44
+ ':log': {
45
+ required: [
46
+ ':log'
47
+ ],
48
+ routine: [],
49
+ optional: [
50
+ ':level'
51
+ ]
52
+ },
53
+ ':parallel': {
54
+ required: [
55
+ ':parallel'
56
+ ],
57
+ routine: [
58
+ ':parallel'
59
+ ],
60
+ optional: []
61
+ },
62
+ ':parallel_for': {
63
+ required: [
64
+ ':parallel_for',
65
+ ':in',
66
+ ':do'
67
+ ],
68
+ routine: [
69
+ ':do'
70
+ ],
71
+ optional: []
72
+ },
73
+ ':reject': {
74
+ required: [
75
+ ':reject'
76
+ ],
77
+ routine: [],
78
+ optional: [
79
+ ':cause'
80
+ ]
81
+ },
82
+ ':return': {
83
+ required: [
84
+ ':return'
85
+ ],
86
+ routine: [],
87
+ optional: []
88
+ },
89
+ ':set_state': {
90
+ required: [
91
+ ':set_state'
92
+ ],
93
+ routine: [],
94
+ optional: []
95
+ },
96
+ ':switch': {
97
+ required: [
98
+ ':switch',
99
+ ':case',
100
+ ':then'
101
+ ],
102
+ routine: [
103
+ ':default',
104
+ ':then'
105
+ ],
106
+ optional: [
107
+ ':default'
108
+ ]
109
+ },
110
+ ':throw': {
111
+ required: [
112
+ ':throw'
113
+ ],
114
+ routine: [],
115
+ optional: [
116
+ ':cause'
117
+ ]
118
+ },
119
+ ':try': {
120
+ required: [
121
+ ':try'
122
+ ],
123
+ routine: [
124
+ ':try',
125
+ ':catch',
126
+ ':finally'
127
+ ],
128
+ optional: [
129
+ ':catch',
130
+ ':finally'
131
+ ]
132
+ },
133
+ ':while': {
134
+ required: [
135
+ ':while',
136
+ ':do'
137
+ ],
138
+ routine: [
139
+ ':do'
140
+ ],
141
+ optional: []
142
+ }
143
+ };
144
+ function getAdditionalKeys(controlType, keys) {
145
+ return keys.filter((item)=>!controlTypes[controlType].required.includes(item));
146
+ }
147
+ function checkMissingRequiredControls({ controlType, keys }, { endpointId }) {
148
+ const missingControls = controlTypes[controlType].required.filter((item)=>!keys.includes(item));
149
+ if (missingControls.length > 0) {
150
+ throw new Error(`Missing required control type(s) for endpoint ${endpointId}. Missing ${JSON.stringify(missingControls)}`);
151
+ }
152
+ }
153
+ function checkInvalidControls({ controlType, keys }, { endpointId }) {
154
+ const additionalControls = getAdditionalKeys(controlType, keys);
155
+ const invalidControls = additionalControls.filter((item)=>!controlTypes[controlType].optional.includes(item));
156
+ if (invalidControls.length > 0) {
157
+ throw new Error(`Invalid control type(s) for endpoint ${endpointId}. Received ${JSON.stringify(invalidControls)}`);
158
+ }
159
+ }
160
+ function handleSwitch(control, endpointContext) {
161
+ const switchArray = control[':switch'];
162
+ if (!type.isArray(control[':switch'])) {
163
+ throw new Error(`Type given for :switch control is invalid at endpoint ${endpointContext.endpointId}. Received ${JSON.stringify(control[':switch'])}`);
164
+ }
165
+ switchArray.forEach((caseObj)=>{
166
+ const input = {
167
+ controlType: ':switch',
168
+ keys: [
169
+ ':switch',
170
+ ...Object.keys(caseObj)
171
+ ]
172
+ };
173
+ checkMissingRequiredControls(input, endpointContext);
174
+ checkInvalidControls(input, endpointContext);
175
+ Object.keys(caseObj).forEach((key)=>{
176
+ if (routineKey(':switch', key)) {
177
+ buildRoutine(caseObj[key], endpointContext);
178
+ } else {
179
+ countOperators(caseObj[key], {
180
+ counter: endpointContext.typeCounters.operators.server
181
+ });
182
+ countControl(key, endpointContext);
183
+ }
184
+ });
185
+ });
186
+ }
187
+ function validateControl(control, endpointContext) {
188
+ const keys = Object.keys(control);
189
+ const intersection = keys.filter((item)=>Object.keys(controlTypes).includes(item));
190
+ if (intersection.length === 0) {
191
+ throw new Error(`Invalid control type(s) for endpoint ${endpointContext.endpointId}. Received "${JSON.stringify(keys)}"`);
192
+ }
193
+ if (intersection.length > 1) {
194
+ throw new Error(`More than one control type found for endpoint ${endpointContext.endpointId}. Received ${JSON.stringify(intersection)}`);
195
+ }
196
+ const controlType = intersection[0];
197
+ if (controlType === ':switch') {
198
+ handleSwitch(control, endpointContext);
199
+ return controlType;
200
+ }
201
+ checkMissingRequiredControls({
202
+ controlType,
203
+ keys
204
+ }, endpointContext);
205
+ checkInvalidControls({
206
+ controlType,
207
+ keys
208
+ }, endpointContext);
209
+ return controlType;
210
+ }
211
+ function routineKey(controlType, key) {
212
+ return controlTypes[controlType]?.routine.includes(key);
213
+ }
214
+ export { routineKey, validateControl };
@@ -0,0 +1,18 @@
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 countControl(control, { typeCounters }) {
16
+ typeCounters.controls.increment(control);
17
+ }
18
+ export default countControl;
@@ -0,0 +1,18 @@
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 countStepTypes(step, { typeCounters }) {
16
+ typeCounters.requests.increment(step.type);
17
+ }
18
+ export default countStepTypes;
@@ -0,0 +1,20 @@
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 setStepId(step, { endpointId }) {
16
+ step.requestId = step.id;
17
+ step.endpointId = endpointId;
18
+ step.id = `request:${endpointId}:${step.requestId}`;
19
+ }
20
+ export default setStepId;
@@ -0,0 +1,42 @@
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 validateStep(step, { endpointId }) {
17
+ if (Object.keys(step).length === 0) {
18
+ throw new Error(`Step is not defined at endpoint "${endpointId}"`);
19
+ }
20
+ if (type.isUndefined(step.id)) {
21
+ throw new Error(`Step id missing at endpoint "${endpointId}".`);
22
+ }
23
+ if (!type.isString(step.id)) {
24
+ throw new Error(`Step id is not a string at endpoint "${endpointId}". Received ${JSON.stringify(step.id)}.`);
25
+ }
26
+ if (step.id.includes('.')) {
27
+ throw new Error(`Step id "${step.id}" at api "${endpointId}" should not include a period (".").`);
28
+ }
29
+ if (type.isNone(step.type)) {
30
+ throw new Error(`Step type is not defined at "${step.id}" on endpoint "${endpointId}".`);
31
+ }
32
+ if (!type.isString(step.type)) {
33
+ throw new Error(`Step type is not a string at "${step.id}" on endpoint "${endpointId}". Received ${JSON.stringify(step.type)}.`);
34
+ }
35
+ if (type.isUndefined(step.connectionId)) {
36
+ throw new Error(`Step connectionId missing at endpoint "${endpointId}".`);
37
+ }
38
+ if (!type.isString(step.connectionId)) {
39
+ throw new Error(`Step connectionId is not a string at endpoint "${endpointId}". Received ${JSON.stringify(step.connectionId)}.`);
40
+ }
41
+ }
42
+ export default validateStep;
@@ -0,0 +1,22 @@
1
+ import { type } from '@lowdefy/helpers';
2
+ function validateEndpoint({ endpoint, index, checkDuplicateEndpointId }) {
3
+ if (type.isUndefined(endpoint.id)) {
4
+ throw new Error(`Endpoint id missing at endpoint ${index}.`);
5
+ }
6
+ if (!type.isString(endpoint.id)) {
7
+ throw new Error(`Endpoint id is not a string at endpoint ${index}. Received ${JSON.stringify(endpoint.id)}.`);
8
+ }
9
+ if (endpoint.id.includes('.')) {
10
+ throw new Error(`Endpoint id "${endpoint.id}" at endpoint "${endpoint.id}" should not include a period (".").`);
11
+ }
12
+ if (type.isUndefined(endpoint.type)) {
13
+ throw new Error(`Endpoint type is not defined at "${endpoint.id}" on endpoint "${endpoint.id}".`);
14
+ }
15
+ if (!type.isString(endpoint.type)) {
16
+ throw new Error(`Endpoint type is not a string at "${endpoint.id}" on endpoint "${endpoint.id}". Received ${JSON.stringify(endpoint.type)}.`);
17
+ }
18
+ checkDuplicateEndpointId({
19
+ id: endpoint.id
20
+ });
21
+ }
22
+ export default validateEndpoint;
@@ -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,29 +14,18 @@
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
- let warningLogged = false;
20
20
  function buildAuth({ components, context }) {
21
21
  const configured = !type.isNone(components.auth);
22
- if (configured && !context.entitlements.includes('AUTH')) {
23
- if (!warningLogged) {
24
- context.logger.warn(`
25
- ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
26
- ┃ Authentication configured without a license key. ┃
27
- ┠──────────────────────────────────────────────────┨
28
- ┃ Paid features can not be used in production ┃
29
- ┃ without a valid license. ┃
30
- ┃ ┃
31
- ┃ See https://docs.lowdefy.com/licenses. ┃
32
- ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛`);
33
- warningLogged = true;
34
- }
35
- }
36
22
  validateAuthConfig({
37
23
  components
38
24
  });
39
25
  components.auth.configured = configured;
26
+ buildApiAuth({
27
+ components
28
+ });
40
29
  buildPageAuth({
41
30
  components
42
31
  });
@@ -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: `{ item, payload, secrets, state, step, user }`
24
24
  }));
25
25
  }
26
26
  export default writeJs;
@@ -46,10 +46,6 @@ function buildTypes({ components, context }) {
46
46
  loaderTypes.blocks.forEach((block)=>typeCounters.blocks.increment(block));
47
47
  // Used for DisplayMessage in @lowdefy/client
48
48
  typeCounters.blocks.increment('Message');
49
- // Used by license-invalid page
50
- typeCounters.blocks.increment('Button');
51
- typeCounters.blocks.increment('Result');
52
- typeCounters.operators.client.increment('_get');
53
49
  components.types = {
54
50
  actions: {},
55
51
  auth: {
@@ -61,6 +57,7 @@ function buildTypes({ components, context }) {
61
57
  blocks: {},
62
58
  connections: {},
63
59
  requests: {},
60
+ api: {},
64
61
  operators: {
65
62
  client: {},
66
63
  server: {}
@@ -0,0 +1,30 @@
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, serializer } from '@lowdefy/helpers';
16
+ async function writeEndpoint({ endpoint, context }) {
17
+ await context.writeBuildArtifact(`api/${endpoint.endpointId}.json`, serializer.serializeToString(endpoint ?? {}));
18
+ }
19
+ async function writeApi({ components, context }) {
20
+ if (type.isNone(components.api)) return;
21
+ if (!type.isArray(components.api)) {
22
+ throw new Error(`Api is not an array.`);
23
+ }
24
+ const writePromises = components.api.map((endpoint)=>writeEndpoint({
25
+ endpoint,
26
+ context
27
+ }));
28
+ return Promise.all(writePromises);
29
+ }
30
+ export default writeApi;
@@ -17,10 +17,9 @@ import createCounter from './utils/createCounter.js';
17
17
  import createReadConfigFile from './utils/readConfigFile.js';
18
18
  import createWriteBuildArtifact from './utils/writeBuildArtifact.js';
19
19
  import defaultTypesMap from './defaultTypesMap.js';
20
- function createContext({ customTypesMap, directories, entitlements = [], logger, refResolver, stage = 'prod' }) {
20
+ function createContext({ customTypesMap, directories, logger, refResolver, stage = 'prod' }) {
21
21
  const context = {
22
22
  directories,
23
- entitlements,
24
23
  jsMap: {},
25
24
  keyMap: {},
26
25
  logger,
@@ -41,6 +40,7 @@ function createContext({ customTypesMap, directories, entitlements = [], logger,
41
40
  blocks: createCounter(),
42
41
  connections: createCounter(),
43
42
  requests: createCounter(),
43
+ controls: createCounter(),
44
44
  operators: {
45
45
  client: createCounter(),
46
46
  server: createCounter()