@opengis/fastify-table 1.4.12 → 1.4.14

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "1.4.12",
3
+ "version": "1.4.14",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [
@@ -13,7 +13,7 @@ import getDBParams from './getDBParams.js';
13
13
  async function getPGAsync(param) {
14
14
  if (!config.pg) return null;
15
15
  const dbListParams = dblist.find(el => el.key === param?.key)
16
- || dblist.find(el => el.database === (param?.db || param?.database || param) && el.port === param?.port);
16
+ || dblist.find(el => el.database === (param?.db || param?.database || param));
17
17
  const {
18
18
  user, password, host, port, db, database, name: origin,
19
19
  } = dbListParams ?? (typeof param === 'string' ? getDBParams(param) : param || {});
@@ -30,6 +30,8 @@ async function getPGAsync(param) {
30
30
  statement_timeout: config.pg?.statement_timeout || 10000,
31
31
  };
32
32
 
33
+ if (!dbConfig.database) { return null; }
34
+
33
35
  pgClients[name] = new pg.Pool(dbConfig);
34
36
 
35
37
  await init(pgClients[name]);
@@ -29,7 +29,7 @@ export default function checkPolicy(req, reply) {
29
29
  const { policy = [] } = routeOptions?.config || {};
30
30
 
31
31
  /*= == 0.Check superadmin access === */
32
- if (policy.includes('admin') && user?.user_type !== 'admin') {
32
+ if (policy.includes('admin') && user?.user_type !== 'admin' && !config.auth?.disable) {
33
33
  logger.file('policy/access', {
34
34
  path, method, params, query, body, message: 'access restricted: not admin', uid: user?.uid,
35
35
  });
@@ -61,8 +61,8 @@ export default async function update(req, reply) {
61
61
  const schema = formData?.schema || formData;
62
62
 
63
63
  // skip non-present fields in form schema
64
- if (!unittest && !tokenData?.ignoreCheck) {
65
- Object.keys(body).filter(key => !Object.keys(schema || {}).includes(key)).forEach(key => delete body[key]);
64
+ if (!unittest && !tokenData?.ignoreCheck && headers['content-type'] === 'application/json') {
65
+ Object.keys(body || {}).filter(key => !Object.keys(schema || {}).includes(key)).forEach(key => delete body[key]);
66
66
  }
67
67
 
68
68
  const xssCheck = checkXSS({ body, schema });
@@ -8,7 +8,7 @@ import config from '../../../../../config.js';
8
8
 
9
9
  export default function checkUserAccess({ user = {} }) {
10
10
  // console.log(user);
11
- if (user.user_type !== 'admin' && !config?.local) {
11
+ if (user.user_type !== 'admin' && !config?.local && !config.auth?.disable) {
12
12
  return { message: 'access restricted', status: 403 };
13
13
  }
14
14
 
@@ -323,12 +323,21 @@ export default async function dataAPI(req, reply, called) {
323
323
  }
324
324
 
325
325
  // html
326
- await Promise.all(template.filter(el => el[0].includes('.hbs')).map(async (el) => {
327
- const htmlContent = await handlebars.compile(el[1])({
328
- ...rows[0], user, data, tokens,
329
- });
330
- const name = el[0].substring(0, el[0].lastIndexOf('.'));
331
- html[name] = htmlContent;
326
+ await Promise.all(template.filter(el => typeof el[1] === 'string' && el[0].includes('.hbs')).map(async (el) => {
327
+ try {
328
+ const htmlContent = await handlebars.compile(el[1])({
329
+ ...rows[0], user, data, tokens,
330
+ });
331
+ const name = el[0].substring(0, el[0].lastIndexOf('.'));
332
+ html[name] = htmlContent;
333
+ }
334
+ catch (err) {
335
+ const name = el[0].substring(0, el[0].lastIndexOf('.'));
336
+ logger.file('handlebars/error', {
337
+ table, id: params.id, error: err.toString(), stack: err.stack,
338
+ });
339
+ html[name] = 'handlebars compile error';
340
+ }
332
341
  }));
333
342
  }
334
343