@opengis/fastify-table 1.1.6 → 1.1.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.
Files changed (57) hide show
  1. package/README.md +26 -26
  2. package/config.js +10 -10
  3. package/cron/controllers/cronApi.js +22 -22
  4. package/cron/controllers/utils/cronList.js +1 -1
  5. package/cron/funcs/addCron.js +131 -131
  6. package/cron/index.js +10 -10
  7. package/crud/controllers/utils/checkXSS.js +45 -45
  8. package/crud/controllers/utils/xssInjection.js +72 -72
  9. package/crud/funcs/dataUpdate.js +30 -30
  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/notification/controllers/testEmail.js +49 -49
  14. package/notification/funcs/utils/sendEmail.js +39 -39
  15. package/notification/index.js +38 -38
  16. package/package.json +1 -1
  17. package/pg/funcs/getPG.js +30 -30
  18. package/redis/funcs/getRedis.js +23 -23
  19. package/server/migrations/crm.sql +150 -150
  20. package/server/migrations/log.sql +80 -80
  21. package/server.js +14 -14
  22. package/table/controllers/card.js +44 -44
  23. package/table/controllers/form.js +28 -28
  24. package/table/controllers/utils/addTemplateDir.js +4 -1
  25. package/table/controllers/utils/getSelect.js +6 -7
  26. package/test/api/crud.test.js +2 -1
  27. package/test/api/crud.xss.test.js +72 -72
  28. package/test/api/notification.test.js +37 -37
  29. package/test/api/suggest.test.js +66 -66
  30. package/test/config.example +18 -18
  31. package/test/funcs/pg.test.js +34 -34
  32. package/test/funcs/redis.test.js +19 -19
  33. package/test/templates/cls/test.json +9 -9
  34. package/test/templates/form/cp_building.form.json +32 -32
  35. package/test/templates/select/account_id.json +3 -3
  36. package/test/templates/select/storage.data.json +2 -2
  37. package/{server → test}/templates/select/test.storage.data.json +3 -3
  38. package/test/templates/select/test.suggest.ato_new.json +4 -0
  39. package/{server → test}/templates/select/test.suggest.ato_new.sql +25 -25
  40. package/{server → test}/templates/select/test.suggest.data.json +4 -4
  41. package/{server → test}/templates/select/test.suggest.parent.sql +2 -3
  42. package/test/templates/table/gis.dataset.table.json +20 -20
  43. package/util/controllers/logger.file.js +90 -90
  44. package/util/controllers/next.id.js +4 -4
  45. package/util/controllers/properties.get.js +19 -19
  46. package/util/controllers/utils/checkUserAccess.js +19 -19
  47. package/util/controllers/utils/getRootDir.js +20 -20
  48. package/util/index.js +23 -23
  49. package/utils.js +4 -0
  50. package/server/templates/form/test.dataset.form.json +0 -412
  51. package/server/templates/select/test.suggest.ato_new.json +0 -3
  52. package/server/templates/table/test.dataset.table.json +0 -29
  53. package/server/templates/table/test.gis.map.table.json +0 -45
  54. package/test/funcs/crud.test.js +0 -122
  55. package/test/funcs/notification.test.js +0 -31
  56. /package/{server → test}/templates/select/test.storage.data.sql +0 -0
  57. /package/{server → test}/templates/select/test.suggest.data.sql +0 -0
@@ -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,4 +1,4 @@
1
- {
2
- "key": "dataset_id",
3
- "searchColumn": "table_name"
1
+ {
2
+ "key": "dataset_id",
3
+ "searchColumn": "table_name"
4
4
  }
@@ -0,0 +1,4 @@
1
+ {
2
+ "db": "mbk_state_old",
3
+ "port": 5437
4
+ }
@@ -1,26 +1,26 @@
1
- select
2
- codifier,
3
- case
4
- when object_type = 'A' then name_ua
5
- else case
6
- when object_type in ('P', 'H', 'O', 'B') then name_ua || ' ' || prefix_ua
7
- else prefix_ua || ' ' || name_ua
8
- end
9
- end as title
10
- from
11
- ato_new.ato_new_all
12
- left join ato_new.ato_settings_city_and_terrytory on ato_type = object_type
13
- where
14
- codifier is not null
15
- union
16
- all
17
- select
18
- country_id,
19
- name_ua as title
20
- from
21
- ato_new.country
22
- where
23
- country_id = '2845832997045798794'
24
- union
25
- all
1
+ select
2
+ codifier,
3
+ case
4
+ when object_type = 'A' then name_ua
5
+ else case
6
+ when object_type in ('P', 'H', 'O', 'B') then name_ua || ' ' || prefix_ua
7
+ else prefix_ua || ' ' || name_ua
8
+ end
9
+ end as title
10
+ from
11
+ ato_new.ato_new_all
12
+ left join ato_new.ato_settings_city_and_terrytory on ato_type = object_type
13
+ where
14
+ codifier is not null
15
+ union
16
+ all
17
+ select
18
+ country_id,
19
+ name_ua as title
20
+ from
21
+ ato_new.country
22
+ where
23
+ country_id = '2845832997045798794'
24
+ union
25
+ all
26
26
  select 'UA00000000000000000', 'Україна'
@@ -1,5 +1,5 @@
1
- {
2
- "db": "mbk_poltava",
3
- "key": "dataset_id",
4
- "searchColumn": "table_name"
1
+ {
2
+ "db": "mbk_poltava",
3
+ "key": "dataset_id",
4
+ "searchColumn": "table_name"
5
5
  }
@@ -1,3 +1,2 @@
1
- select dataset_id, dataset_name, table_name from gis.dataset
2
- where
3
- dataset_id = '{{parent}}'
1
+ select dataset_id, dataset_name, table_name from gis.dataset
2
+ where dataset_id = '{{parent}}'
@@ -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
  }
@@ -1,90 +1,90 @@
1
- import path from 'path';
2
- import { lstat, readdir } from 'fs/promises';
3
- import { createReadStream, existsSync } from 'fs';
4
- import readline from 'readline';
5
-
6
- import checkUserAccess from './utils/checkUserAccess.js';
7
- import getRootDir from './utils/getRootDir.js';
8
-
9
- /**
10
- *
11
- * @method GET
12
- * @summary API для перегляду логів
13
- *
14
- */
15
-
16
- export default async function loggerFile({
17
- pg, params = {}, user = {}, query = {}, originalUrl, funcs = {},
18
- }, reply) {
19
- const limit = 200000;
20
- const access = pg ? await checkUserAccess({ user, pg }) : {};
21
-
22
- const { config = {} } = funcs;
23
- if (access?.status === 403 && !config?.local) return access;
24
-
25
- // absolute / relative path
26
- const rootDir = getRootDir(config);
27
- const filepath = path.join(rootDir, params['*'] || '');
28
-
29
- if (!existsSync(filepath)) {
30
- return { error: 'file not exists', status: 404 };
31
- }
32
- const stat = await lstat(filepath);
33
- const isFile = stat.isFile();
34
-
35
- if (query.download && isFile) {
36
- return reply.download(filepath);
37
- }
38
-
39
- if (query.full && isFile) {
40
- if (stat.size > 20 * 1000 * 1000) {
41
- return { message: 'file size > 20MB' };
42
- }
43
- const buffer = await readFile(filepath, { buffer: true });
44
- return buffer;
45
- }
46
-
47
- if (isFile) {
48
- const ext = path.extname(filepath);
49
-
50
- const lines = await new Promise((resolve) => {
51
- const rl = readline.createInterface({
52
- input: createReadStream(filepath, { start: stat.size > limit ? stat.size - limit : 0 }),
53
- });
54
- const lines1 = [];
55
- rl.on('close', () => resolve(lines1));
56
- rl.on('line', (line) => lines1.push(line));
57
- });
58
-
59
- if (ext === '.html') {
60
- const buffer = await readFile(filepath, { buffer: true });
61
- reply.headers({ 'Content-type': 'text/html; charset=UTF-8' });
62
- return buffer;
63
- }
64
-
65
- reply.headers({ 'Content-type': 'text/plain' });
66
- return stat.size > limit && lines.length > 1
67
- ? lines.reverse().slice(0, -1).join('\n')
68
- : lines.reverse().join('\n');
69
- }
70
-
71
- // dir
72
- const files = await readdir(filepath);
73
-
74
- if (query.dir) {
75
- return files.filter((el) => !['backup', 'marker_icon', 'error', 'migration'].includes(el));
76
- }
77
-
78
- const lstatsArr = await Promise.all(files.map(async (file) => [file, await lstat(path.join(filepath, file))]));
79
- const lstats = Object.fromEntries(lstatsArr);
80
-
81
- const message = (params['*'] ? '<a href="/logger-file/">...</a><br>' : '')
82
- + files.map((file) => `<a href="${originalUrl}/${file}">${file}</a> (${lstats[file].size} bytes)`).join('</br>');
83
-
84
- reply.headers({
85
- 'Content-Type': 'text/html; charset=UTF-8',
86
- 'Content-Security-Policy': "default-src 'none'",
87
- 'X-Content-Type-Options': 'nosniff',
88
- });
89
- return message;
90
- }
1
+ import path from 'path';
2
+ import { lstat, readdir } from 'fs/promises';
3
+ import { createReadStream, existsSync } from 'fs';
4
+ import readline from 'readline';
5
+
6
+ import checkUserAccess from './utils/checkUserAccess.js';
7
+ import getRootDir from './utils/getRootDir.js';
8
+
9
+ /**
10
+ *
11
+ * @method GET
12
+ * @summary API для перегляду логів
13
+ *
14
+ */
15
+
16
+ export default async function loggerFile({
17
+ pg, params = {}, user = {}, query = {}, originalUrl, funcs = {},
18
+ }, reply) {
19
+ const limit = 200000;
20
+ const access = pg ? await checkUserAccess({ user, pg }) : {};
21
+
22
+ const { config = {} } = funcs;
23
+ if (access?.status === 403 && !config?.local) return access;
24
+
25
+ // absolute / relative path
26
+ const rootDir = getRootDir(config);
27
+ const filepath = path.join(rootDir, params['*'] || '');
28
+
29
+ if (!existsSync(filepath)) {
30
+ return { error: 'file not exists', status: 404 };
31
+ }
32
+ const stat = await lstat(filepath);
33
+ const isFile = stat.isFile();
34
+
35
+ if (query.download && isFile) {
36
+ return reply.download(filepath);
37
+ }
38
+
39
+ if (query.full && isFile) {
40
+ if (stat.size > 20 * 1000 * 1000) {
41
+ return { message: 'file size > 20MB' };
42
+ }
43
+ const buffer = await readFile(filepath, { buffer: true });
44
+ return buffer;
45
+ }
46
+
47
+ if (isFile) {
48
+ const ext = path.extname(filepath);
49
+
50
+ const lines = await new Promise((resolve) => {
51
+ const rl = readline.createInterface({
52
+ input: createReadStream(filepath, { start: stat.size > limit ? stat.size - limit : 0 }),
53
+ });
54
+ const lines1 = [];
55
+ rl.on('close', () => resolve(lines1));
56
+ rl.on('line', (line) => lines1.push(line));
57
+ });
58
+
59
+ if (ext === '.html') {
60
+ const buffer = await readFile(filepath, { buffer: true });
61
+ reply.headers({ 'Content-type': 'text/html; charset=UTF-8' });
62
+ return buffer;
63
+ }
64
+
65
+ reply.headers({ 'Content-type': 'text/plain' });
66
+ return stat.size > limit && lines.length > 1
67
+ ? lines.reverse().slice(0, -1).join('\n')
68
+ : lines.reverse().join('\n');
69
+ }
70
+
71
+ // dir
72
+ const files = await readdir(filepath);
73
+
74
+ if (query.dir) {
75
+ return files.filter((el) => !['backup', 'marker_icon', 'error', 'migration'].includes(el));
76
+ }
77
+
78
+ const lstatsArr = await Promise.all(files.map(async (file) => [file, await lstat(path.join(filepath, file))]));
79
+ const lstats = Object.fromEntries(lstatsArr);
80
+
81
+ const message = (params['*'] ? '<a href="/logger-file/">...</a><br>' : '')
82
+ + files.map((file) => `<a href="${originalUrl}/${file}">${file}</a> (${lstats[file].size} bytes)`).join('</br>');
83
+
84
+ reply.headers({
85
+ 'Content-Type': 'text/html; charset=UTF-8',
86
+ 'Content-Security-Policy': "default-src 'none'",
87
+ 'X-Content-Type-Options': 'nosniff',
88
+ });
89
+ return message;
90
+ }
@@ -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
  }
@@ -1,19 +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
- }
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
+ }
@@ -1,21 +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');
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
21
  }
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
@@ -2,7 +2,9 @@
2
2
  // between our tests.
3
3
 
4
4
  import getTemplate from './table/controllers/utils/getTemplate.js';
5
+ import getTemplatePath from './table/controllers/utils/getTemplatePath.js';
5
6
  import addTemplateDir from './table/controllers/utils/addTemplateDir.js';
7
+ import userTemplateDir from './table/controllers/utils/userTemplateDir.js';
6
8
  import metaFormat from './table/funcs/metaFormat/index.js';
7
9
  import autoIndex from './pg/funcs/autoIndex.js';
8
10
 
@@ -25,6 +27,8 @@ import getAccess from './crud/funcs/getAccess.js';
25
27
  export default null;
26
28
  export {
27
29
  getTemplate,
30
+ getTemplatePath,
31
+ userTemplateDir,
28
32
  metaFormat,
29
33
  autoIndex,
30
34
  addTemplateDir,