@opengis/fastify-table 1.0.89 → 1.0.91

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,19 @@
1
+ /**
2
+ *
3
+ * @summary check user access to logger interface - per admin user type or user group
4
+ * @returns {Object} message, status
5
+ */
6
+
7
+ export default async function checkUserAccess({
8
+ user = {}, pg,
9
+ }) {
10
+ const { count = '0' } = pg.pk?.['admin.access']
11
+ ? await pg.query(`select count(*) from admin.access
12
+ where user_uid=$1 and route_id='logger'`, [user.uid]).then((res) => res.rows[0] || {})
13
+ : {};
14
+
15
+ if (!['admin', 'superadmin']?.includes(user.user_type) && count === '0') {
16
+ return { message: 'access restricted', status: 403 };
17
+ }
18
+ return { message: 'access granted', status: 200 };
19
+ }
@@ -0,0 +1,21 @@
1
+ import path from 'path';
2
+ import { existsSync } from 'fs';
3
+
4
+ export default function getRootDir(config) {
5
+ // absolute / relative path
6
+ if (config.log?.dir) {
7
+ return config.log.dir.startsWith('/') || config.log.dir.includes(':')
8
+ ? config.log.dir
9
+ : path.join(process.cwd(), config.log.dir);
10
+ }
11
+
12
+ // windows debug support
13
+ const customLogDir = process.cwd().includes(':') ? 'c:/data/local' : '/data/local';
14
+ // docker default path
15
+ if (existsSync(customLogDir)) {
16
+ return path.join(customLogDir, config.folder || '', 'log');
17
+ }
18
+
19
+ // non-docker default path
20
+ return path.join(config.root || '/data/local', config.folder || '', 'log');
21
+ }
package/util/index.js CHANGED
@@ -1,21 +1,23 @@
1
- import getExtraProperties from './controllers/properties.get.js';
2
- import addExtraProperties from './controllers/properties.add.js';
3
- import nextId from './controllers/next.id.js';
4
- import statusMonitor from './controllers/status.monitor.js';
5
-
6
- const propertiesSchema = {
7
- params: {
8
- id: { type: 'string', pattern: '^([\\d\\w]+)$' },
9
- },
10
- };
11
-
12
- async function plugin(fastify, config = {}) {
13
- const prefix = config.prefix || '/api';
14
-
15
- fastify.get(`${prefix}/next-id`, {}, nextId);
16
- fastify.get(`${prefix}/status-monitor`, {}, statusMonitor);
17
- fastify.get(`${prefix}/properties/:id`, { schema: propertiesSchema }, getExtraProperties);
18
- fastify.post(`${prefix}/properties/:id`, { schema: propertiesSchema }, addExtraProperties);
19
- }
20
-
21
- export default plugin;
1
+ import getExtraProperties from './controllers/properties.get.js';
2
+ import addExtraProperties from './controllers/properties.add.js';
3
+ import nextId from './controllers/next.id.js';
4
+ import statusMonitor from './controllers/status.monitor.js';
5
+ import loggerFile from './controllers/logger.file.js';
6
+
7
+ const propertiesSchema = {
8
+ params: {
9
+ id: { type: 'string', pattern: '^([\\d\\w]+)$' },
10
+ },
11
+ };
12
+
13
+ async function plugin(fastify, config = {}) {
14
+ const prefix = config.prefix || '/api';
15
+
16
+ fastify.get(`${prefix}/next-id`, {}, nextId);
17
+ fastify.get(`${prefix}/status-monitor`, {}, statusMonitor);
18
+ fastify.get(`${prefix}/properties/:id`, { schema: propertiesSchema }, getExtraProperties);
19
+ fastify.post(`${prefix}/properties/:id`, { schema: propertiesSchema }, addExtraProperties);
20
+ fastify.get('/logger-file/*', { config: { policy: ['log'] } }, loggerFile);
21
+ }
22
+
23
+ export default plugin;
@@ -29,9 +29,11 @@ export default async function widgetGet({
29
29
  from crm.communications c left join admin.users u on u.uid=c.uid where entity_id=$1 order by cdate desc`
30
30
  : 'select communication_id, entity_id, body, subject, cdate, uid from crm.communications where entity_id=$1 order by cdate desc',
31
31
 
32
- history: `SELECT table_change_id, entity_id, entity_type, change_key, change_date, json_old, json_new, date_old,
33
- date_new, number_old, number_new, bool_old, bool_new, text_old,
34
- text_new, uid, cdate FROM log.table_changes where entity_id=$1 order by cdate desc, change_key limit 100`,
32
+ history: `SELECT b.change_data_id, change_id, entity_id, entity_type, change_type, change_date, uid, cdate, b.entity_key, b.value_new, b.value_old FROM log.table_changes a
33
+ left join lateral(
34
+ select change_data_id, entity_key, value_new, value_old from log.table_changes_data where change_id=a.change_id
35
+ )b on 1=1
36
+ where entity_id=$1 and b.change_data_id is not null order by cdate desc limit 100`,
35
37
 
36
38
  checklist: pg.pk['admin.users']
37
39
  ? `SELECT checklist_id, entity_id, subject, is_done, done_date, c.uid, c.cdate, coalesce(user_name,' ')||' '||coalesce(sur_name,'') as username,
@@ -45,7 +45,9 @@ export default async function widgetSet(req) {
45
45
  return { message: 'invalid file extension', status: 400 };
46
46
  }
47
47
 
48
- const { rows = [] } = await dataInsert({ table: 'crm.files', data });
48
+ const { rows = [] } = await dataInsert({
49
+ table: 'crm.files', data, uid: user?.uid,
50
+ });
49
51
  return {
50
52
  rowCount: 1, data: 'ok', command: 'UPLOAD', id: rows[0]?.file_id, entity_id: rows[0]?.entity_id,
51
53
  };
@@ -56,8 +58,12 @@ export default async function widgetSet(req) {
56
58
  const data = { ...body, uid: user?.uid, entity_id: objectid };
57
59
 
58
60
  const result = id
59
- ? await dataUpdate({ table, data, id })
60
- : await dataInsert({ table, data });
61
+ ? await dataUpdate({
62
+ table, data, id, uid: user?.uid,
63
+ })
64
+ : await dataInsert({
65
+ table, data, uid: user?.uid,
66
+ });
61
67
 
62
68
  return {
63
69
  rowCount: result.rowCount, data: 'ok', command: result.command, id: result.rows?.[0]?.[pkList[type]] || result?.[pkList[type]],
package/widget/index.js CHANGED
@@ -1,40 +1,40 @@
1
- import widgetDel from './controllers/widget.del.js';
2
- import widgetSet from './controllers/widget.set.js';
3
- import widgetGet from './controllers/widget.get.js';
4
-
5
- const tableSchema = {
6
- params: {
7
- // type: { type: 'string', pattern: '^([\\d\\w]+)$' },
8
- objectid: { type: 'string', pattern: '^([\\d\\w]+)$' },
9
- id: { type: 'string', pattern: '^([\\d\\w]+)$' },
10
- },
11
- querystring: {
12
- debug: { type: 'string', pattern: '^(\\d+)$' },
13
- }
14
- };
15
-
16
- async function route(fastify, opt) {
17
- const prefix = opt.prefix || '/api';
18
- fastify.route({
19
- method: 'DELETE',
20
- url: `${prefix}/widget/:type/:objectid/:id`,
21
- schema: tableSchema,
22
- handler: widgetDel,
23
- });
24
- fastify.route({
25
- method: 'POST',
26
- path: `${prefix}/widget/:type/:objectid/:id?`,
27
- schema: tableSchema,
28
- handler: widgetSet,
29
- });
30
- fastify.route({
31
- method: 'GET',
32
- path: `${prefix}/widget/:type/:objectid`,
33
- config: {
34
- policy: ['public'],
35
- },
36
- schema: tableSchema,
37
- handler: widgetGet,
38
- });
39
- }
40
- export default route;
1
+ import widgetDel from './controllers/widget.del.js';
2
+ import widgetSet from './controllers/widget.set.js';
3
+ import widgetGet from './controllers/widget.get.js';
4
+
5
+ const tableSchema = {
6
+ params: {
7
+ // type: { type: 'string', pattern: '^([\\d\\w]+)$' },
8
+ objectid: { type: 'string', pattern: '^([\\d\\w]+)$' },
9
+ id: { type: 'string', pattern: '^([\\d\\w]+)$' },
10
+ },
11
+ querystring: {
12
+ debug: { type: 'string', pattern: '^(\\d+)$' },
13
+ },
14
+ };
15
+
16
+ async function route(fastify, opt) {
17
+ const prefix = opt.prefix || '/api';
18
+ fastify.route({
19
+ method: 'DELETE',
20
+ url: `${prefix}/widget/:type/:objectid/:id`,
21
+ schema: tableSchema,
22
+ handler: widgetDel,
23
+ });
24
+ fastify.route({
25
+ method: 'POST',
26
+ path: `${prefix}/widget/:type/:objectid/:id?`,
27
+ schema: tableSchema,
28
+ handler: widgetSet,
29
+ });
30
+ fastify.route({
31
+ method: 'GET',
32
+ path: `${prefix}/widget/:type/:objectid`,
33
+ config: {
34
+ policy: ['public'],
35
+ },
36
+ schema: tableSchema,
37
+ handler: widgetGet,
38
+ });
39
+ }
40
+ export default route;