@opengis/fastify-table 1.1.40 → 1.1.42

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.
Files changed (41) hide show
  1. package/Changelog.md +1 -1
  2. package/README.md +26 -26
  3. package/config.js +10 -10
  4. package/cron/controllers/cronApi.js +22 -22
  5. package/cron/controllers/utils/cronList.js +1 -1
  6. package/cron/funcs/addCron.js +131 -131
  7. package/cron/index.js +10 -10
  8. package/crud/controllers/utils/checkXSS.js +45 -45
  9. package/crud/controllers/utils/xssInjection.js +72 -72
  10. package/crud/funcs/getToken.js +27 -27
  11. package/crud/funcs/isFileExists.js +13 -13
  12. package/crud/funcs/setToken.js +53 -53
  13. package/index.js +4 -1
  14. package/logger/createFileStream.js +4 -1
  15. package/logger/getLogger.js +3 -3
  16. package/logger/serializers.js +18 -17
  17. package/notification/controllers/testEmail.js +49 -49
  18. package/notification/funcs/utils/sendEmail.js +39 -39
  19. package/package.json +1 -1
  20. package/pg/funcs/getPG.js +30 -30
  21. package/pg/funcs/getPGAsync.js +6 -6
  22. package/redis/funcs/getRedis.js +23 -23
  23. package/server/migrations/log.sql +80 -80
  24. package/table/controllers/card.js +44 -44
  25. package/table/controllers/filter.js +12 -2
  26. package/table/controllers/form.js +28 -28
  27. package/test/api/crud.xss.test.js +72 -72
  28. package/test/api/user.test.js +3 -2
  29. package/test/config.example +18 -18
  30. package/test/funcs/pg.test.js +34 -34
  31. package/test/funcs/redis.test.js +19 -19
  32. package/test/templates/cls/test.json +9 -9
  33. package/test/templates/form/cp_building.form.json +32 -32
  34. package/test/templates/select/account_id.json +3 -3
  35. package/test/templates/select/storage.data.json +2 -2
  36. package/test/templates/table/gis.dataset.table.json +20 -20
  37. package/user/controllers/user.cls.js +7 -3
  38. package/util/controllers/next.id.js +4 -4
  39. package/util/controllers/properties.get.js +19 -19
  40. package/util/index.js +23 -23
  41. package/utils.js +50 -19
@@ -1,10 +1,10 @@
1
- [
2
- {
3
- "id": 1,
4
- "text": "test"
5
- },
6
- {
7
- "id": 2,
8
- "text": "test2"
9
- }
1
+ [
2
+ {
3
+ "id": 1,
4
+ "text": "test"
5
+ },
6
+ {
7
+ "id": 2,
8
+ "text": "test2"
9
+ }
10
10
  ]
@@ -1,33 +1,33 @@
1
- {
2
- "schema": {
3
-
4
- "cp_umuni_id": {
5
- "type": "Text",
6
- "ua": "ID UMUNI"
7
- },
8
- "cp_year": {
9
- "type": "Text",
10
- "ua": "Рік будівництва"
11
- },
12
- "cp_date_en_audit": {
13
- "type": "DatePicker",
14
- "ua": "Дата проведення останнього енергоаудиту"
15
- },
16
- "cp_certificate": {
17
- "type": "Text",
18
- "ua": "Сертифікат енергоефективності будівлі",
19
- "help": "Вкажіть посилання"
20
- },
21
- "cp_pkd": {
22
- "type": "Autocomplete",
23
- "data": "customer_name",
24
- "add": {
25
- "model": "crm_acc.crm_account",
26
- "ua": "Додати",
27
- "form": "account_light.form"
28
- },
29
- "ua": "Замовник ПКД"
30
- }
31
- },
32
- "label_style": "vertical"
1
+ {
2
+ "schema": {
3
+
4
+ "cp_umuni_id": {
5
+ "type": "Text",
6
+ "ua": "ID UMUNI"
7
+ },
8
+ "cp_year": {
9
+ "type": "Text",
10
+ "ua": "Рік будівництва"
11
+ },
12
+ "cp_date_en_audit": {
13
+ "type": "DatePicker",
14
+ "ua": "Дата проведення останнього енергоаудиту"
15
+ },
16
+ "cp_certificate": {
17
+ "type": "Text",
18
+ "ua": "Сертифікат енергоефективності будівлі",
19
+ "help": "Вкажіть посилання"
20
+ },
21
+ "cp_pkd": {
22
+ "type": "Autocomplete",
23
+ "data": "customer_name",
24
+ "add": {
25
+ "model": "crm_acc.crm_account",
26
+ "ua": "Додати",
27
+ "form": "account_light.form"
28
+ },
29
+ "ua": "Замовник ПКД"
30
+ }
31
+ },
32
+ "label_style": "vertical"
33
33
  }
@@ -1,4 +1,4 @@
1
- {
2
- "db": "mbk_lviv_dma",
3
- "searchColumn": "alternative_name"
1
+ {
2
+ "db": "mbk_lviv_dma",
3
+ "searchColumn": "alternative_name"
4
4
  }
@@ -1,3 +1,3 @@
1
- {
2
- "key": "dataset_id"
1
+ {
2
+ "key": "dataset_id"
3
3
  }
@@ -1,21 +1,21 @@
1
- {
2
- "columns": [
3
- {
4
- "name": "dataset_id",
5
- "title": "22"
6
- },
7
- {
8
- "name": "dataset_name",
9
- "title": "dataset_name"
10
- }
11
- ],
12
- "table": "gis.dataset",
13
- "order": "dataset_name",
14
- "filters": [
15
- {
16
- "ua": "Назва набору",
17
- "name": "dataset_name",
18
- "type": "text"
19
- }
20
- ]
1
+ {
2
+ "columns": [
3
+ {
4
+ "name": "dataset_id",
5
+ "title": "22"
6
+ },
7
+ {
8
+ "name": "dataset_name",
9
+ "title": "dataset_name"
10
+ }
11
+ ],
12
+ "table": "gis.dataset",
13
+ "order": "dataset_name",
14
+ "filters": [
15
+ {
16
+ "ua": "Назва набору",
17
+ "name": "dataset_name",
18
+ "type": "text"
19
+ }
20
+ ]
21
21
  }
@@ -11,6 +11,10 @@ export default async function userCls(req) {
11
11
  return { message: 'access restricted', status: 403 };
12
12
  }
13
13
 
14
+ if (query.type && !['json', 'sql'].includes(query.type)) {
15
+ return { message: 'param type is invalid', status: 400 };
16
+ }
17
+
14
18
  const q = `select user_clsid as id, name, type,
15
19
  case when type='json' then (
16
20
  ${params?.id
@@ -28,7 +32,7 @@ export default async function userCls(req) {
28
32
  case when type='sql' then data else null end as sql from admin.user_cls u
29
33
  where (case when type='json' then parent is null else true end)
30
34
  and uid=(select uid from admin.users where $1 in (login,uid) limit 1)
31
- and parent is null and ${params?.id ? 'u.name=$2' : '1=1'}`;
35
+ and parent is null and ${query.type ? `type='${query.type}'` : '1=1'} and ${params?.id ? 'u.name=$2' : '1=1'}`;
32
36
 
33
37
  if (query?.sql) return q;
34
38
 
@@ -40,8 +44,8 @@ export default async function userCls(req) {
40
44
  if (row.type === 'json') { delete row.sql; Object.assign(row, { children: row.children || (params?.id ? [] : 0) }); }
41
45
  });
42
46
 
43
- const clsList = getTemplatePath('cls');
44
- const selectList = getTemplatePath('select');
47
+ const clsList = query.type === 'sql' ? [] : getTemplatePath('cls'); // skip cls if type sql
48
+ const selectList = query.type === 'json' ? [] : getTemplatePath('select'); // skip sql if type json
45
49
 
46
50
  const userClsNames = rows.map((el) => el.name);
47
51
  const selectNames = selectList.map((el) => el[0]);
@@ -1,4 +1,4 @@
1
- export default async function nextId({ pg }) {
2
- const { id } = await pg.one('select next_id() as id');
3
- return { id: id.toString() };
4
- };
1
+ export default async function nextId({ pg }) {
2
+ const { id } = await pg.one('select next_id() as id');
3
+ return { id: id.toString() };
4
+ };
@@ -1,20 +1,20 @@
1
- export default async function getExtraProperties({
2
- pg, params = {},
3
- }) {
4
- const { id } = params;
5
- if (!id) {
6
- return { message: 'not enougn params', status: 400 };
7
- }
8
- try {
9
- const { rows = [] } = pg.pk?.['crm.properties']
10
- ? await pg.query(`select property_key, property_type, property_text, property_int,
11
- property_json, property_date from crm.properties where property_key is not null and object_id=$1`, [id])
12
- : {};
13
- if (!rows.length) return {};
14
-
15
- const data = rows.reduce((acc, curr) => Object.assign(acc, { [curr.property_key]: curr[`property_${curr.property_type}`] }), {});
16
- return { message: data, status: 200 };
17
- } catch (err) {
18
- return { error: err.toString(), status: 500 };
19
- }
1
+ export default async function getExtraProperties({
2
+ pg, params = {},
3
+ }) {
4
+ const { id } = params;
5
+ if (!id) {
6
+ return { message: 'not enougn params', status: 400 };
7
+ }
8
+ try {
9
+ const { rows = [] } = pg.pk?.['crm.properties']
10
+ ? await pg.query(`select property_key, property_type, property_text, property_int,
11
+ property_json, property_date from crm.properties where property_key is not null and object_id=$1`, [id])
12
+ : {};
13
+ if (!rows.length) return {};
14
+
15
+ const data = rows.reduce((acc, curr) => Object.assign(acc, { [curr.property_key]: curr[`property_${curr.property_type}`] }), {});
16
+ return { message: data, status: 200 };
17
+ } catch (err) {
18
+ return { error: err.toString(), status: 500 };
19
+ }
20
20
  }
package/util/index.js CHANGED
@@ -1,23 +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
- 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;
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;
package/utils.js CHANGED
@@ -21,7 +21,7 @@ import dataDelete from './crud/funcs/dataDelete.js';
21
21
  import getToken from './crud/funcs/getToken.js';
22
22
  import setToken from './crud/funcs/setToken.js';
23
23
  import checkXSS from './crud/controllers/utils/checkXSS.js';
24
- import gisIRColumn from './table/controllers/utils/gisIRColumn.js';
24
+ import getTableColumn from './table/controllers/utils/gisIRColumn.js';
25
25
  import getMeta from './pg/funcs/getMeta.js';
26
26
  import getAccess from './crud/funcs/getAccess.js';
27
27
  import getSelectVal from './table/funcs/metaFormat/getSelectVal.js';
@@ -32,38 +32,69 @@ import addHook from './hook/funcs/addHook.js';
32
32
  import execMigrations from './migration/exec.migrations.js';
33
33
  import addNotification from './notification/funcs/addNotification.js';
34
34
  import sendNotification from './notification/funcs/sendNotification.js';
35
+ import getFilterSQL from './table/funcs/getFilterSQL/index.js';
36
+
37
+ import addCron from './cron/funcs/addCron.js';
38
+ import getOpt from './crud/funcs/getOpt.js';
39
+ import setOpt from './crud/funcs/setOpt.js';
40
+
41
+ import isFileExists from './crud/funcs/isFileExists.js';
42
+
35
43
  import logger from './logger/getLogger.js';
36
44
  // const logger = false; // test!
37
45
 
38
46
  export default null;
39
47
  export {
48
+
49
+ addCron,
50
+ execMigrations,
51
+ getRedis,
40
52
  logger,
53
+ isFileExists,
54
+
55
+ // hook
56
+ addHook,
57
+ applyHook,
58
+
59
+ // template
41
60
  getTemplate,
42
61
  getTemplatePath,
43
- userTemplateDir,
44
- metaFormat,
45
- autoIndex,
46
62
  addTemplateDir,
47
- getPG,
48
- getPGAsync,
49
- initPG,
50
- pgClients,
63
+ userTemplateDir,
64
+
65
+ // notification
66
+ addNotification,
67
+ sendNotification,
68
+
69
+ // security
70
+ checkXSS,
71
+ getAccess,
72
+ getToken,
73
+ getOpt,
74
+ setOpt,
75
+ setToken,
76
+
77
+ // crud
51
78
  dataInsert,
52
79
  dataUpdate,
53
80
  dataDelete,
54
- getRedis,
55
- getToken,
56
- setToken,
57
- checkXSS,
58
- gisIRColumn,
81
+
82
+ // table
83
+ autoIndex,
84
+ metaFormat,
85
+ getFilterSQL,
59
86
  getMeta,
60
- getAccess,
87
+ getTableColumn,
88
+
89
+ // pg
90
+ initPG,
91
+ getPG,
92
+ getPGAsync,
93
+ pgClients,
94
+
95
+ // select
61
96
  getSelectVal,
62
97
  getSelectMeta,
63
98
  getSelect,
64
- applyHook,
65
- addHook,
66
- execMigrations,
67
- addNotification,
68
- sendNotification,
99
+
69
100
  };