@lowdefy/api 4.0.0-alpha.5 → 4.0.0-alpha.8

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.
@@ -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 };
@@ -12,10 +12,12 @@
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
- */ // TODO: strip auth prop from page before we send it to the client
16
- async function getPageConfig({ authorize , readConfigFile }, { pageId }) {
15
+ */ async function getPageConfig({ authorize , readConfigFile }, { pageId }) {
17
16
  const pageConfig = await readConfigFile(`pages/${pageId}/${pageId}.json`);
18
- if (pageConfig && authorize(pageConfig)) return pageConfig;
17
+ if (pageConfig && authorize(pageConfig)) {
18
+ delete pageConfig.auth;
19
+ return pageConfig;
20
+ }
19
21
  return null;
20
22
  }
21
23
  export default getPageConfig;
@@ -23,16 +23,14 @@ async function evaluateOperators({ operators , secrets , user }, { connectionCo
23
23
  });
24
24
  await operatorsParser.init();
25
25
  const { output: connectionProperties , errors: connectionErrors } = operatorsParser.parse({
26
- input: connectionConfig.properties || {
27
- },
26
+ input: connectionConfig.properties || {},
28
27
  location: connectionConfig.connectionId
29
28
  });
30
29
  if (connectionErrors.length > 0) {
31
30
  throw new RequestError(connectionErrors[0]);
32
31
  }
33
32
  const { output: requestProperties , errors: requestErrors } = operatorsParser.parse({
34
- input: requestConfig.properties || {
35
- },
33
+ input: requestConfig.properties || {},
36
34
  location: requestConfig.requestId
37
35
  });
38
36
  if (requestErrors.length > 0) {
@@ -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,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.5",
3
+ "version": "4.0.0-alpha.8",
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.5",
45
- "@lowdefy/helpers": "4.0.0-alpha.5",
46
- "@lowdefy/node-utils": "4.0.0-alpha.5",
47
- "@lowdefy/nunjucks": "4.0.0-alpha.5",
48
- "@lowdefy/operators": "4.0.0-alpha.5"
44
+ "@lowdefy/ajv": "4.0.0-alpha.8",
45
+ "@lowdefy/helpers": "4.0.0-alpha.8",
46
+ "@lowdefy/node-utils": "4.0.0-alpha.8",
47
+ "@lowdefy/nunjucks": "4.0.0-alpha.8",
48
+ "@lowdefy/operators": "4.0.0-alpha.8"
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.8",
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": "995fcdb020927f3cdc626fc99c15a2e4137bd962"
61
+ "gitHead": "9d56b83cf45e868afe3a1eeba750fe826eb74c8c"
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;