@lowdefy/api 4.0.0-alpha.1 → 4.0.0-alpha.7

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.
@@ -13,7 +13,7 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import createReadConfigFile from './readConfigFile.js';
16
- async function createApiContext({ buildDirectory , connections , logger , secrets }) {
16
+ async function createApiContext({ buildDirectory , connections , logger , operators , secrets }) {
17
17
  const readConfigFile = createReadConfigFile({
18
18
  buildDirectory
19
19
  });
@@ -25,6 +25,7 @@ async function createApiContext({ buildDirectory , connections , logger , secret
25
25
  config,
26
26
  connections,
27
27
  logger,
28
+ operators,
28
29
  readConfigFile,
29
30
  secrets
30
31
  };
@@ -19,26 +19,26 @@
19
19
  }
20
20
  };
21
21
  let ConfigurationError = class ConfigurationError extends Error {
22
- constructor(message1){
23
- super(message1);
22
+ constructor(message){
23
+ super(message);
24
24
  this.name = 'ConfigurationError';
25
25
  }
26
26
  };
27
27
  let RequestError = class RequestError extends Error {
28
- constructor(message2){
29
- super(message2);
28
+ constructor(message){
29
+ super(message);
30
30
  this.name = 'RequestError';
31
31
  }
32
32
  };
33
33
  let ServerError = class ServerError extends Error {
34
- constructor(message3){
35
- super(message3);
34
+ constructor(message){
35
+ super(message);
36
36
  this.name = 'ServerError';
37
37
  }
38
38
  };
39
39
  let TokenExpiredError = class TokenExpiredError extends Error {
40
- constructor(message4){
41
- super(message4);
40
+ constructor(message){
41
+ super(message);
42
42
  this.name = 'TokenExpiredError';
43
43
  }
44
44
  };
package/dist/index.js CHANGED
@@ -14,8 +14,8 @@
14
14
  limitations under the License.
15
15
  */ import callRequest from './routes/request/callRequest.js';
16
16
  import createApiContext from './context/createApiContext.js';
17
- import getHome from './routes/rootConfig/getHome.js';
17
+ import getHomeAndMenus from './routes/rootConfig/getHomeAndMenus.js';
18
18
  import getPageConfig from './routes/page/getPageConfig.js';
19
19
  import getRootConfig from './routes/rootConfig/getRootConfig.js';
20
20
  import { AuthenticationError, ConfigurationError, RequestError, ServerError, TokenExpiredError } from './context/errors.js';
21
- export { callRequest, createApiContext, getHome, getPageConfig, getRootConfig, AuthenticationError, ConfigurationError, RequestError, ServerError, TokenExpiredError };
21
+ export { AuthenticationError, callRequest, ConfigurationError, createApiContext, getHomeAndMenus, getPageConfig, getRootConfig, RequestError, ServerError, TokenExpiredError };
@@ -14,7 +14,10 @@
14
14
  limitations under the License.
15
15
  */ async function getPageConfig({ authorize , readConfigFile }, { pageId }) {
16
16
  const pageConfig = await readConfigFile(`pages/${pageId}/${pageId}.json`);
17
- if (pageConfig && authorize(pageConfig)) return pageConfig;
17
+ if (pageConfig && authorize(pageConfig)) {
18
+ delete pageConfig.auth;
19
+ return pageConfig;
20
+ }
18
21
  return null;
19
22
  }
20
23
  export default getPageConfig;
@@ -12,40 +12,33 @@
12
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
- */ // import { NodeParser } from '@lowdefy/operators';
16
- // import { RequestError } from '../../context/errors.js';
17
- // async function evaluateOperators({ secrets, user }, { connectionConfig, payload, requestConfig }) {
18
- // const operatorsParser = new NodeParser({
19
- // payload,
20
- // secrets,
21
- // user,
22
- // });
23
- // await operatorsParser.init();
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
- async function evaluateOperators({ secrets , user }, { connectionConfig , payload , requestConfig }) {
15
+ */ import { NodeParser } from '@lowdefy/operators';
16
+ import { RequestError } from '../../context/errors.js';
17
+ async function evaluateOperators({ operators , secrets , user }, { connectionConfig , payload , requestConfig }) {
18
+ const operatorsParser = new NodeParser({
19
+ operators,
20
+ payload,
21
+ secrets,
22
+ user
23
+ });
24
+ await operatorsParser.init();
25
+ const { output: connectionProperties , errors: connectionErrors } = operatorsParser.parse({
26
+ input: connectionConfig.properties || {},
27
+ location: connectionConfig.connectionId
28
+ });
29
+ if (connectionErrors.length > 0) {
30
+ throw new RequestError(connectionErrors[0]);
31
+ }
32
+ const { output: requestProperties , errors: requestErrors } = operatorsParser.parse({
33
+ input: requestConfig.properties || {},
34
+ location: requestConfig.requestId
35
+ });
36
+ if (requestErrors.length > 0) {
37
+ throw new RequestError(requestErrors[0]);
38
+ }
44
39
  return {
45
- connectionProperties: connectionConfig.properties || {
46
- },
47
- requestProperties: requestConfig.properties || {
48
- }
40
+ connectionProperties,
41
+ requestProperties
49
42
  };
50
43
  }
51
44
  export default evaluateOperators;
@@ -13,11 +13,17 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import { get } from '@lowdefy/helpers';
16
- function findHome({ config }, { menus }) {
17
- if (get(config, 'homePageId')) {
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) {
18
21
  return {
19
- pageId: config.homePageId,
20
- configured: true
22
+ home: {
23
+ configured: true,
24
+ pageId: homePageId
25
+ },
26
+ menus
21
27
  };
22
28
  }
23
29
  let defaultMenu = menus.find((menu)=>menu.menuId === 'default'
@@ -41,8 +47,11 @@ function findHome({ config }, { menus }) {
41
47
  });
42
48
  }
43
49
  return {
44
- pageId,
45
- configured: false
50
+ home: {
51
+ configured: false,
52
+ pageId
53
+ },
54
+ menus
46
55
  };
47
56
  }
48
- export default findHome;
57
+ export default getHomeAndMenus;
@@ -14,7 +14,6 @@
14
14
  limitations under the License.
15
15
  */ async function getLowdefyGlobal({ readConfigFile }) {
16
16
  const lowdefyGlobal = await readConfigFile('global.json');
17
- return lowdefyGlobal || {
18
- };
17
+ return lowdefyGlobal || {};
19
18
  }
20
19
  export default getLowdefyGlobal;
@@ -12,19 +12,16 @@
12
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
- */ import findHome from './findHome.js';
15
+ */ import getHomeAndMenus from './getHomeAndMenus.js';
16
16
  import getLowdefyGlobal from './getLowdefyGlobal.js';
17
- import getMenus from './menus/getMenus.js';
18
17
  async function getRootConfig(context) {
19
- const [lowdefyGlobal, menus] = await Promise.all([
18
+ const [lowdefyGlobal, { home , menus }] = await Promise.all([
20
19
  getLowdefyGlobal(context),
21
- getMenus(context)
20
+ getHomeAndMenus(context),
22
21
  ]);
23
22
  return {
24
23
  authenticated: context.authenticated,
25
- home: findHome(context, {
26
- menus
27
- }),
24
+ home,
28
25
  lowdefyGlobal,
29
26
  menus
30
27
  };
@@ -13,7 +13,7 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import { get } from '@lowdefy/helpers';
16
- import filterMenuList from './filterMenuList';
16
+ import filterMenuList from './filterMenuList.js';
17
17
  function filterMenus(context, { menus }) {
18
18
  return menus.map((menu)=>{
19
19
  return {
@@ -12,7 +12,7 @@
12
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
- */ import filterMenus from './filterMenus';
15
+ */ import filterMenus from './filterMenus.js';
16
16
  async function getMenus(context) {
17
17
  const unfilteredMenus = await context.readConfigFile('menus.json');
18
18
  return filterMenus(context, {
@@ -13,21 +13,14 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import createAuthorize from '../context/createAuthorize.js';
16
- function testContext({ config ={
17
- } , connections ={
18
- } , headers ={
19
- } , host ='host' , logger ={
20
- debug: ()=>{
21
- },
22
- error: ()=>{
23
- },
24
- info: ()=>{
25
- },
26
- warn: ()=>{
27
- }
28
- } , readConfigFile , roles , secrets ={
29
- } , setHeader , user , protocol ='https' , } = {
30
- }) {
16
+ function testContext({ config ={} , connections ={} , headers ={} , host ='host' , logger ={
17
+ debug: ()=>{},
18
+ error: ()=>{},
19
+ info: ()=>{},
20
+ warn: ()=>{}
21
+ } , operators ={
22
+ _test: ()=>'test'
23
+ } , readConfigFile , roles , secrets ={} , setHeader , user , protocol ='https' , } = {}) {
31
24
  const authenticated = user && !!user.sub;
32
25
  return {
33
26
  authenticated,
@@ -40,6 +33,7 @@ function testContext({ config ={
40
33
  headers,
41
34
  host,
42
35
  logger,
36
+ operators,
43
37
  protocol,
44
38
  readConfigFile,
45
39
  secrets,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/api",
3
- "version": "4.0.0-alpha.1",
3
+ "version": "4.0.0-alpha.7",
4
4
  "licence": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -38,23 +38,25 @@
38
38
  "clean": "rm -rf dist",
39
39
  "prepare": "yarn build",
40
40
  "swc": "swc src --out-dir dist --config-file ../../.swcrc --delete-dir-on-start",
41
- "test": "jest --coverage"
41
+ "test": "yarn node --experimental-vm-modules $(yarn bin jest)"
42
42
  },
43
43
  "dependencies": {
44
- "@lowdefy/ajv": "4.0.0-alpha.1",
45
- "@lowdefy/helpers": "4.0.0-alpha.1",
46
- "@lowdefy/node-utils": "4.0.0-alpha.1",
47
- "@lowdefy/nunjucks": "4.0.0-alpha.1",
48
- "@lowdefy/operators": "4.0.0-alpha.1"
44
+ "@lowdefy/ajv": "4.0.0-alpha.7",
45
+ "@lowdefy/helpers": "4.0.0-alpha.7",
46
+ "@lowdefy/node-utils": "4.0.0-alpha.7",
47
+ "@lowdefy/nunjucks": "4.0.0-alpha.7",
48
+ "@lowdefy/operators": "4.0.0-alpha.7"
49
49
  },
50
50
  "devDependencies": {
51
- "@swc/cli": "0.1.52",
52
- "@swc/core": "1.2.112",
53
- "@swc/jest": "0.2.9",
54
- "jest": "27.3.1"
51
+ "@jest/globals": "27.5.1",
52
+ "@lowdefy/operators-js": "4.0.0-alpha.7",
53
+ "@swc/cli": "0.1.55",
54
+ "@swc/core": "1.2.135",
55
+ "@swc/jest": "0.2.17",
56
+ "jest": "27.5.1"
55
57
  },
56
58
  "publishConfig": {
57
59
  "access": "public"
58
60
  },
59
- "gitHead": "c97a8fa6b5a641e7d50df09f5601a9c586eeb65a"
61
+ "gitHead": "52ec14639d00de910cf9b8ab25bf933ca891cff5"
60
62
  }
@@ -1,25 +0,0 @@
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 findHome from './findHome.js';
16
- import getMenus from './menus/getMenus.js';
17
- async function getHome(context) {
18
- // TODO: We can optimise here as we don't need to read menus if homepageId is configured
19
- // but not sure if it is worth the added complexity
20
- const menus = await getMenus(context);
21
- return findHome(context, {
22
- menus
23
- });
24
- }
25
- export default getHome;