@opengis/fastify-table 1.1.12 → 1.1.13

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 (39) 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/getToken.js +27 -27
  10. package/crud/funcs/isFileExists.js +13 -13
  11. package/crud/funcs/setToken.js +53 -53
  12. package/notification/controllers/testEmail.js +49 -49
  13. package/notification/funcs/utils/sendEmail.js +39 -39
  14. package/notification/index.js +38 -38
  15. package/package.json +1 -1
  16. package/pg/funcs/getPG.js +30 -30
  17. package/redis/funcs/getRedis.js +23 -23
  18. package/server/migrations/crm.sql +150 -150
  19. package/server/migrations/log.sql +80 -80
  20. package/server.js +14 -14
  21. package/table/controllers/card.js +44 -44
  22. package/table/controllers/form.js +28 -28
  23. package/table/controllers/utils/getTemplatePath.js +1 -1
  24. package/test/api/crud.xss.test.js +72 -72
  25. package/test/api/notification.test.js +37 -37
  26. package/test/config.example +18 -18
  27. package/test/funcs/pg.test.js +34 -34
  28. package/test/funcs/redis.test.js +19 -19
  29. package/test/templates/cls/test.json +9 -9
  30. package/test/templates/form/cp_building.form.json +32 -32
  31. package/test/templates/select/account_id.json +3 -3
  32. package/test/templates/select/storage.data.json +2 -2
  33. package/test/templates/table/gis.dataset.table.json +20 -20
  34. package/util/controllers/logger.file.js +90 -90
  35. package/util/controllers/next.id.js +4 -4
  36. package/util/controllers/properties.get.js +19 -19
  37. package/util/controllers/utils/checkUserAccess.js +19 -19
  38. package/util/controllers/utils/getRootDir.js +20 -20
  39. package/util/index.js +23 -23
@@ -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;