@opengis/fastify-table 1.0.97 → 1.1.1

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 (59) hide show
  1. package/.eslintrc.cjs +42 -42
  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/dataUpdate.js +30 -30
  11. package/crud/funcs/getToken.js +27 -27
  12. package/crud/funcs/isFileExists.js +13 -13
  13. package/crud/funcs/setToken.js +53 -53
  14. package/crud/funcs/utils/logChanges.js +7 -4
  15. package/notification/controllers/testEmail.js +49 -49
  16. package/notification/funcs/utils/sendEmail.js +39 -39
  17. package/notification/index.js +38 -38
  18. package/package.json +1 -1
  19. package/pg/funcs/getPG.js +30 -30
  20. package/redis/funcs/getRedis.js +23 -23
  21. package/server/migrations/crm.sql +150 -150
  22. package/server/migrations/log.sql +80 -80
  23. package/server/templates/select/test.storage.data.json +3 -3
  24. package/server/templates/select/test.suggest.ato_new.json +2 -2
  25. package/server/templates/select/test.suggest.ato_new.sql +25 -25
  26. package/server/templates/select/test.suggest.data.json +4 -4
  27. package/server/templates/select/test.suggest.parent.sql +2 -2
  28. package/server.js +14 -14
  29. package/table/controllers/card.js +44 -44
  30. package/table/controllers/filter.js +37 -37
  31. package/table/controllers/form.js +28 -28
  32. package/table/controllers/search.js +80 -72
  33. package/table/controllers/utils/getSelect.js +20 -20
  34. package/table/controllers/utils/getTemplate.js +69 -28
  35. package/table/controllers/utils/getTemplatePath.js +40 -0
  36. package/table/controllers/utils/getTemplate_old.js +28 -0
  37. package/table/controllers/utils/getTemplates.js +18 -18
  38. package/table/controllers/utils/loadTemplate.js +1 -0
  39. package/table/controllers/utils/loadTemplatePath.js +1 -0
  40. package/table/index.js +84 -80
  41. package/test/api/crud.xss.test.js +72 -72
  42. package/test/api/notification.test.js +37 -37
  43. package/test/api/suggest.test.js +65 -65
  44. package/test/config.example +18 -18
  45. package/test/funcs/notification.test.js +31 -31
  46. package/test/funcs/pg.test.js +34 -34
  47. package/test/funcs/redis.test.js +19 -19
  48. package/test/templates/cls/test.json +9 -9
  49. package/test/templates/form/cp_building.form.json +32 -32
  50. package/test/templates/select/account_id.json +3 -3
  51. package/test/templates/select/storage.data.json +2 -2
  52. package/test/templates/table/gis.dataset.table.json +20 -20
  53. package/util/controllers/logger.file.js +90 -90
  54. package/util/controllers/next.id.js +4 -4
  55. package/util/controllers/properties.get.js +19 -19
  56. package/util/controllers/utils/checkUserAccess.js +19 -19
  57. package/util/controllers/utils/getRootDir.js +20 -20
  58. package/util/index.js +23 -23
  59. package/utils.js +8 -0
@@ -1,18 +1,18 @@
1
- import config from '../config.js';
2
-
3
- Object.assign(config, {
4
- folder: 'test/templates',
5
- pg: {
6
- host: '192.168.3.160',
7
- port: 5434,
8
- database: 'mbk_rivne_dma',
9
- user: 'postgres',
10
- password: 'postgres',
11
- },
12
- redis: {
13
- host: '192.168.3.160',
14
- port: 6379,
15
- family: 4,
16
- },
17
- });
18
- export default config;
1
+ import config from '../config.js';
2
+
3
+ Object.assign(config, {
4
+ folder: 'test/templates',
5
+ pg: {
6
+ host: '192.168.3.160',
7
+ port: 5434,
8
+ database: 'mbk_rivne_dma',
9
+ user: 'postgres',
10
+ password: 'postgres',
11
+ },
12
+ redis: {
13
+ host: '192.168.3.160',
14
+ port: 6379,
15
+ family: 4,
16
+ },
17
+ });
18
+ export default config;
@@ -1,31 +1,31 @@
1
- import { test } from 'node:test';
2
- import assert from 'node:assert';
3
-
4
- // import build from '../../helper.js';
5
- // import config from '../config.js';
6
-
7
- // import addNotification from '../../notification/funcs/addNotification.js';
8
-
9
- // import pgClients from '../../pg/pgClients.js';
10
-
11
- test('notification funcs', async (t) => {
12
- // await build(t);
13
- // const pg = pgClients.client;
14
- // let resp;
15
- /* await t.test('addNotification', async () => {
16
- resp = await addNotification({
17
- pg,
18
-
19
- title: 'test title',
20
- body: 'test body',
21
- link: 'http://link',
22
- notificationType: 'mention',
23
- uid: config.testUser?.uid || '1',
24
- });
25
- assert.ok(resp.id);
26
- });
27
- await t.test('clean up after test, before pool is closed', async () => {
28
- await pg.query('delete from crm.notification where notification_id=$1', [resp.id]);
29
- console.log(resp.id, 'deleted');
30
- }); */
31
- });
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert';
3
+
4
+ // import build from '../../helper.js';
5
+ // import config from '../config.js';
6
+
7
+ // import addNotification from '../../notification/funcs/addNotification.js';
8
+
9
+ // import pgClients from '../../pg/pgClients.js';
10
+
11
+ test('notification funcs', async (t) => {
12
+ // await build(t);
13
+ // const pg = pgClients.client;
14
+ // let resp;
15
+ /* await t.test('addNotification', async () => {
16
+ resp = await addNotification({
17
+ pg,
18
+
19
+ title: 'test title',
20
+ body: 'test body',
21
+ link: 'http://link',
22
+ notificationType: 'mention',
23
+ uid: config.testUser?.uid || '1',
24
+ });
25
+ assert.ok(resp.id);
26
+ });
27
+ await t.test('clean up after test, before pool is closed', async () => {
28
+ await pg.query('delete from crm.notification where notification_id=$1', [resp.id]);
29
+ console.log(resp.id, 'deleted');
30
+ }); */
31
+ });
@@ -1,34 +1,34 @@
1
- import { test } from 'node:test';
2
- import assert from 'node:assert';
3
-
4
- import '../config.js';
5
-
6
- import getMeta from '../../pg/funcs/getMeta.js';
7
- import autoIndex from '../../pg/funcs/autoIndex.js';
8
- import pgClients from '../../pg/pgClients.js';
9
- import rclient from '../../redis/client.js';
10
- // import pgClients from '../../pg/funcs/pgClients.js';
11
-
12
- test('funcs pg', async (t) => {
13
- await pgClients.client.init();
14
- await t.test('getMeta', async () => {
15
- const { columns } = await getMeta({ table: 'gis.dataset' });
16
- // console.log(columns)
17
- assert.ok(columns);
18
- });
19
-
20
- /* await t.test('getPG', async (t) => {
21
- const data = await getPG({});
22
- assert.ok(data);
23
- }); */
24
-
25
- await t.test('autoIndex', async () => {
26
- await autoIndex({ table: 'gis.dataset', columns: ['service_type'] });
27
- assert.ok(1);
28
- });
29
- t.after(() => {
30
- pgClients.client.end();
31
-
32
- rclient.quit();
33
- });
34
- });
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert';
3
+
4
+ import '../config.js';
5
+
6
+ import getMeta from '../../pg/funcs/getMeta.js';
7
+ import autoIndex from '../../pg/funcs/autoIndex.js';
8
+ import pgClients from '../../pg/pgClients.js';
9
+ import rclient from '../../redis/client.js';
10
+ // import pgClients from '../../pg/funcs/pgClients.js';
11
+
12
+ test('funcs pg', async (t) => {
13
+ await pgClients.client.init();
14
+ await t.test('getMeta', async () => {
15
+ const { columns } = await getMeta({ table: 'gis.dataset' });
16
+ // console.log(columns)
17
+ assert.ok(columns);
18
+ });
19
+
20
+ /* await t.test('getPG', async (t) => {
21
+ const data = await getPG({});
22
+ assert.ok(data);
23
+ }); */
24
+
25
+ await t.test('autoIndex', async () => {
26
+ await autoIndex({ table: 'gis.dataset', columns: ['service_type'] });
27
+ assert.ok(1);
28
+ });
29
+ t.after(() => {
30
+ pgClients.client.end();
31
+
32
+ rclient.quit();
33
+ });
34
+ });
@@ -1,19 +1,19 @@
1
- import { test } from 'node:test';
2
- import assert from 'node:assert';
3
-
4
- import '../config.js';
5
-
6
- import rclient from '../../redis/client.js';
7
-
8
- test('funcs redis', async (t) => {
9
- await t.test('get/set', async () => {
10
- await rclient.set('test', '1');
11
- const d = await rclient.get('test');
12
- // console.log(columns)
13
- assert.equal(d, '1');
14
- });
15
-
16
- t.after(() => {
17
- rclient.quit();
18
- });
19
- });
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert';
3
+
4
+ import '../config.js';
5
+
6
+ import rclient from '../../redis/client.js';
7
+
8
+ test('funcs redis', async (t) => {
9
+ await t.test('get/set', async () => {
10
+ await rclient.set('test', '1');
11
+ const d = await rclient.get('test');
12
+ // console.log(columns)
13
+ assert.equal(d, '1');
14
+ });
15
+
16
+ t.after(() => {
17
+ rclient.quit();
18
+ });
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
  }
@@ -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
+ }