@opengis/fastify-table 1.4.5 → 1.4.7

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 (73) hide show
  1. package/README.md +86 -86
  2. package/config.js +25 -3
  3. package/index.js +1 -0
  4. package/package.json +6 -3
  5. package/server/helpers/format/formatAuto.js +13 -13
  6. package/server/helpers/format/formatDate.js +258 -258
  7. package/server/helpers/format/formatDigit.js +20 -20
  8. package/server/helpers/format/formatNum.js +361 -361
  9. package/server/helpers/format/formatNumber.js +54 -54
  10. package/server/helpers/format/formatRelative.js +106 -106
  11. package/server/helpers/format/formatUnit.js +38 -38
  12. package/server/helpers/format/num_format.js +41 -41
  13. package/server/helpers/funcs/_math.js +49 -49
  14. package/server/helpers/funcs/empty.js +21 -21
  15. package/server/helpers/funcs/ifCond.js +106 -106
  16. package/server/helpers/funcs/ifCondAnd.js +96 -96
  17. package/server/helpers/funcs/ifCondOr.js +98 -98
  18. package/server/helpers/funcs/inc.js +20 -20
  19. package/server/helpers/funcs/json.js +2 -2
  20. package/server/helpers/funcs/round.js +27 -27
  21. package/server/helpers/string/coalesce.js +31 -31
  22. package/server/helpers/string/concat.js +28 -28
  23. package/server/helpers/string/split.js +19 -19
  24. package/server/helpers/string/str_replace.js +60 -60
  25. package/server/helpers/string/substr.js +31 -31
  26. package/server/helpers/string/translit.js +23 -23
  27. package/server/helpers/string/utils/alphabet.js +75 -75
  28. package/server/plugins/cron/funcs/addCron.js +52 -52
  29. package/server/plugins/cron/index.js +76 -76
  30. package/server/plugins/crud/funcs/dataDelete.js +1 -1
  31. package/server/plugins/crud/funcs/getOpt.js +14 -14
  32. package/server/plugins/crud/funcs/setOpt.js +21 -21
  33. package/server/plugins/crud/funcs/setToken.js +43 -43
  34. package/server/plugins/crud/funcs/utils/getFolder.js +11 -11
  35. package/server/plugins/crud/index.js +23 -23
  36. package/server/plugins/extra/extraDataGet.js +6 -5
  37. package/server/plugins/hook/index.js +8 -8
  38. package/server/plugins/logger/errorStatus.js +19 -19
  39. package/server/plugins/logger/index.js +26 -26
  40. package/server/plugins/migration/index.js +7 -7
  41. package/server/plugins/policy/sqlInjection.js +33 -33
  42. package/server/plugins/redis/client.js +8 -8
  43. package/server/plugins/redis/funcs/redisClients.js +3 -3
  44. package/server/plugins/redis/index.js +17 -17
  45. package/server/plugins/table/funcs/getFilterSQL/index.js +5 -4
  46. package/server/plugins/table/funcs/getFilterSQL/util/formatValue.js +4 -3
  47. package/server/plugins/table/funcs/getFilterSQL/util/getCustomQuery.js +13 -13
  48. package/server/plugins/table/funcs/getFilterSQL/util/getFilterQuery.js +2 -3
  49. package/server/plugins/table/funcs/getFilterSQL/util/getTableSql.js +34 -34
  50. package/server/plugins/table/funcs/getTemplates.js +19 -19
  51. package/server/plugins/table/funcs/gisIRColumn.js +82 -82
  52. package/server/plugins/table/funcs/loadTemplate.js +1 -1
  53. package/server/plugins/table/funcs/loadTemplatePath.js +1 -1
  54. package/server/plugins/table/funcs/userTemplateDir.js +1 -1
  55. package/server/plugins/util/funcs/flattenObject.js +11 -0
  56. package/server/plugins/util/funcs/unflattenObject.js +14 -0
  57. package/server/plugins/util/index.js +7 -7
  58. package/server/routes/crud/controllers/deleteCrud.js +15 -5
  59. package/server/routes/crud/controllers/insert.js +10 -4
  60. package/server/routes/crud/controllers/table.js +7 -3
  61. package/server/routes/crud/controllers/update.js +8 -4
  62. package/server/routes/logger/controllers/logger.file.js +93 -93
  63. package/server/routes/logger/controllers/utils/checkUserAccess.js +19 -19
  64. package/server/routes/logger/controllers/utils/getRootDir.js +26 -26
  65. package/server/routes/menu/controllers/getMenu.js +2 -2
  66. package/server/routes/properties/controllers/properties.add.js +55 -55
  67. package/server/routes/properties/controllers/properties.get.js +17 -17
  68. package/server/routes/table/controllers/cardData.js +8 -8
  69. package/server/routes/table/controllers/form.js +42 -42
  70. package/server/routes/table/controllers/search.js +74 -74
  71. package/server/routes/table/functions/getData.js +3 -3
  72. package/server/routes/util/controllers/status.monitor.js +8 -8
  73. package/utils.js +6 -0
@@ -23,14 +23,18 @@ export default async function update(req, reply) {
23
23
 
24
24
  const { referer } = headers;
25
25
  const tokenData = await getToken({
26
- uid: user.uid, token: body.token || params.table, mode: 'w', json: 1,
26
+ uid: user.uid, token: body.token || params.id || params.table, mode: 'w', json: 1,
27
27
  });
28
28
 
29
- const { form, table: edit, id } = hookData || tokenData || (config.auth?.disable ? params : {});
29
+ const { form, table: edit, id } = hookData || tokenData || (config.security?.disableToken || config.local || config.auth?.disable ? params : {});
30
30
 
31
31
  const { actions = [] } = await getAccess({ table: edit, id, user }, pg) || {};
32
32
 
33
- if (!actions.includes('edit') && !config.local && !config.debug && !tokenData) {
33
+ if (!tokenData && !config.local && !config.security?.disableToken && !config.auth?.disable) {
34
+ return reply.status(400).send('invalid token');
35
+ }
36
+
37
+ if (!actions.includes('edit') && !config.local) {
34
38
  return reply.status(403).send('access restricted');
35
39
  }
36
40
 
@@ -114,5 +118,5 @@ export default async function update(req, reply) {
114
118
  }));
115
119
  }
116
120
 
117
- return res;
121
+ return reply.status(200).send(res);
118
122
  }
@@ -1,93 +1,93 @@
1
- import path from 'node:path';
2
- import { lstat, readdir, readFile } from 'node:fs/promises';
3
- import { createReadStream, existsSync } from 'node:fs';
4
- import readline from 'node: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
- params = {}, user = {}, query = {}, originalUrl,
18
- }, reply) {
19
- const limit = 200000;
20
- // console.log(user);
21
- const access = checkUserAccess({ user });
22
- // log.info('Сервер запущен по адресу?'); // test!
23
-
24
- if (access?.status !== 200) return access;
25
-
26
- // absolute / relative path
27
- const rootDir = getRootDir();
28
-
29
- const filepath = path.join(rootDir, params['*'] || '');
30
-
31
- if (!existsSync(filepath)) {
32
- return { message: 'file not exists', status: 404 };
33
- }
34
- const stat = await lstat(filepath);
35
- const isFile = stat.isFile();
36
-
37
- if (query.download && isFile) {
38
- const buffer = await readFile(filepath, { buffer: true });
39
- return buffer;
40
- }
41
-
42
- if (query.full && isFile) {
43
- if (stat.size > 20 * 1000 * 1000) {
44
- return { message: 'file size > 20MB' };
45
- }
46
- const buffer = await readFile(filepath, { buffer: true });
47
- return buffer;
48
- }
49
-
50
- if (isFile) {
51
- const ext = path.extname(filepath);
52
-
53
- const lines = await new Promise((resolve) => {
54
- const rl = readline.createInterface({
55
- input: createReadStream(filepath, { start: stat.size > limit ? stat.size - limit : 0 }),
56
- });
57
- const lines1 = [];
58
- rl.on('close', () => resolve(lines1));
59
- rl.on('line', (line) => lines1.push(line));
60
- });
61
-
62
- if (ext === '.html') {
63
- const buffer = await readFile(filepath, { buffer: true });
64
- reply.headers({ 'Content-type': 'text/html; charset=UTF-8' });
65
- return buffer;
66
- }
67
-
68
- reply.headers({ 'Content-type': 'text/plain; charset=UTF-8' });
69
- return stat.size > limit && lines.length > 1
70
- ? lines.reverse().slice(0, -1).join('\n')
71
- : lines.reverse().join('\n');
72
- }
73
-
74
- // dir
75
- const files = await readdir(filepath);
76
-
77
- if (query.dir) {
78
- return files.filter((el) => !['backup', 'marker_icon', 'error', 'migration'].includes(el));
79
- }
80
-
81
- const lstatsArr = await Promise.all(files.map(async (file) => [file, await lstat(path.join(filepath, file))]));
82
- const lstats = Object.fromEntries(lstatsArr);
83
-
84
- const message = (params['*'] ? '<a href="/logger-file/">...</a><br>' : '')
85
- + files.map((file) => `<a href="${originalUrl}/${file}">${file}</a> (${lstats[file].size} bytes)`).join('</br>');
86
-
87
- reply.headers({
88
- 'Content-Type': 'text/html; charset=UTF-8',
89
- 'Content-Security-Policy': "default-src 'none'",
90
- 'X-Content-Type-Options': 'nosniff',
91
- });
92
- return message;
93
- }
1
+ import path from 'node:path';
2
+ import { lstat, readdir, readFile } from 'node:fs/promises';
3
+ import { createReadStream, existsSync } from 'node:fs';
4
+ import readline from 'node: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
+ params = {}, user = {}, query = {}, originalUrl,
18
+ }, reply) {
19
+ const limit = 200000;
20
+ // console.log(user);
21
+ const access = checkUserAccess({ user });
22
+ // log.info('Сервер запущен по адресу?'); // test!
23
+
24
+ if (access?.status !== 200) return access;
25
+
26
+ // absolute / relative path
27
+ const rootDir = getRootDir();
28
+
29
+ const filepath = path.join(rootDir, params['*'] || '');
30
+
31
+ if (!existsSync(filepath)) {
32
+ return { message: 'file not exists', status: 404 };
33
+ }
34
+ const stat = await lstat(filepath);
35
+ const isFile = stat.isFile();
36
+
37
+ if (query.download && isFile) {
38
+ const buffer = await readFile(filepath, { buffer: true });
39
+ return buffer;
40
+ }
41
+
42
+ if (query.full && isFile) {
43
+ if (stat.size > 20 * 1000 * 1000) {
44
+ return { message: 'file size > 20MB' };
45
+ }
46
+ const buffer = await readFile(filepath, { buffer: true });
47
+ return buffer;
48
+ }
49
+
50
+ if (isFile) {
51
+ const ext = path.extname(filepath);
52
+
53
+ const lines = await new Promise((resolve) => {
54
+ const rl = readline.createInterface({
55
+ input: createReadStream(filepath, { start: stat.size > limit ? stat.size - limit : 0 }),
56
+ });
57
+ const lines1 = [];
58
+ rl.on('close', () => resolve(lines1));
59
+ rl.on('line', (line) => lines1.push(line));
60
+ });
61
+
62
+ if (ext === '.html') {
63
+ const buffer = await readFile(filepath, { buffer: true });
64
+ reply.headers({ 'Content-type': 'text/html; charset=UTF-8' });
65
+ return buffer;
66
+ }
67
+
68
+ reply.headers({ 'Content-type': 'text/plain; charset=UTF-8' });
69
+ return stat.size > limit && lines.length > 1
70
+ ? lines.reverse().slice(0, -1).join('\n')
71
+ : lines.reverse().join('\n');
72
+ }
73
+
74
+ // dir
75
+ const files = await readdir(filepath);
76
+
77
+ if (query.dir) {
78
+ return files.filter((el) => !['backup', 'marker_icon', 'error', 'migration'].includes(el));
79
+ }
80
+
81
+ const lstatsArr = await Promise.all(files.map(async (file) => [file, await lstat(path.join(filepath, file))]));
82
+ const lstats = Object.fromEntries(lstatsArr);
83
+
84
+ const message = (params['*'] ? '<a href="/logger-file/">...</a><br>' : '')
85
+ + files.map((file) => `<a href="${originalUrl}/${file}">${file}</a> (${lstats[file].size} bytes)`).join('</br>');
86
+
87
+ reply.headers({
88
+ 'Content-Type': 'text/html; charset=UTF-8',
89
+ 'Content-Security-Policy': "default-src 'none'",
90
+ 'X-Content-Type-Options': 'nosniff',
91
+ });
92
+ return message;
93
+ }
@@ -1,19 +1,19 @@
1
- import config from '../../../../../config.js';
2
-
3
- /**
4
- *
5
- * @summary check user access to logger interface - per admin user type or user group
6
- * @returns {Object} message, status
7
- */
8
-
9
- export default function checkUserAccess({ user = {} }) {
10
- // console.log(user);
11
- if (user.user_type !== 'admin' && !config?.local) {
12
- return { message: 'access restricted', status: 403 };
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
+ import config from '../../../../../config.js';
2
+
3
+ /**
4
+ *
5
+ * @summary check user access to logger interface - per admin user type or user group
6
+ * @returns {Object} message, status
7
+ */
8
+
9
+ export default function checkUserAccess({ user = {} }) {
10
+ // console.log(user);
11
+ if (user.user_type !== 'admin' && !config?.local) {
12
+ return { message: 'access restricted', status: 403 };
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,26 +1,26 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
-
4
- import config from '../../../../../config.js';
5
-
6
- // import { existsSync } from 'fs';
7
- let logDir = null;
8
- export default function getRootDir() {
9
- // absolute / relative path
10
- if (logDir) return logDir;
11
- const file = ['config.json', '/data/local/config.json'].find(el => (fs.existsSync(el) ? el : null));
12
- const root = file === 'config.json' ? process.cwd() : '/data/local';
13
- logDir = config.logDir || path.join(root, config.log?.dir || 'log');
14
- console.log({ logDir });
15
- return logDir;
16
-
17
- // windows debug support
18
- /* const customLogDir = process.cwd().includes(':') ? 'c:/data/local' : '/data/local';
19
- // docker default path
20
- if (existsSync(customLogDir)) {
21
- return path.join(customLogDir, config.folder || '', 'log');
22
- }
23
-
24
- // non-docker default path
25
- return path.join(config.root || '/data/local', config.folder || '', 'log'); */
26
- }
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+
4
+ import config from '../../../../../config.js';
5
+
6
+ // import { existsSync } from 'fs';
7
+ let logDir = null;
8
+ export default function getRootDir() {
9
+ // absolute / relative path
10
+ if (logDir) return logDir;
11
+ const file = ['config.json', '/data/local/config.json'].find(el => (fs.existsSync(el) ? el : null));
12
+ const root = file === 'config.json' ? process.cwd() : '/data/local';
13
+ logDir = config.logDir || path.join(root, config.log?.dir || 'log');
14
+ console.log({ logDir });
15
+ return logDir;
16
+
17
+ // windows debug support
18
+ /* const customLogDir = process.cwd().includes(':') ? 'c:/data/local' : '/data/local';
19
+ // docker default path
20
+ if (existsSync(customLogDir)) {
21
+ return path.join(customLogDir, config.folder || '', 'log');
22
+ }
23
+
24
+ // non-docker default path
25
+ return path.join(config.root || '/data/local', config.folder || '', 'log'); */
26
+ }
@@ -5,7 +5,7 @@ import { join } from 'node:path';
5
5
  import { existsSync, readdirSync, readFileSync } from 'node:fs';
6
6
 
7
7
  import {
8
- menuDirs, pgClients, applyHook, config,
8
+ menuDirs, pgClients, applyHook, config,
9
9
  } from '../../../../utils.js';
10
10
 
11
11
  const menuCache = [];
@@ -63,7 +63,7 @@ export default async function adminMenu({
63
63
  };
64
64
  await applyHook('userMenu', result);
65
65
 
66
- if (session && user?.uid && !user.user_type?.includes?.('admin') && !user.type?.includes?.('admin') && pg.pk['admin.role_access']) {
66
+ if (session && user?.uid && !user.user_type?.includes?.('admin') && !user.type?.includes?.('admin') && pg.pk?.['admin.role_access']) {
67
67
  const { type, gl = [], routes = [] } = await pg.query(`select user_type as type, b.gl,routes from admin.users a
68
68
  left join lateral (
69
69
  select array_agg(role_id) as gl from admin.user_roles
@@ -1,55 +1,55 @@
1
- import { dataInsert } from '../../../../utils.js';
2
-
3
- const table = 'crm.properties';
4
-
5
- function checkKeyType({ body, key }) {
6
- if (typeof body[key] === 'number' && (!/\D/.test(body[key].toString()) && body[key].toString().length < 10)) {
7
- return { [key]: 'int' };
8
- } if (typeof body[key] === 'object') {
9
- return { [key]: 'json' };
10
- }
11
- if (Date.parse(body[key], 'yyyy/MM/ddTHH:mm:ss.000Z')) {
12
- return { [key]: 'date' };
13
- }
14
- return { [key]: 'text' };
15
- }
16
-
17
- export default async function addExtraProperties({
18
- pg, params = {}, body = {}, user = {},
19
- }) {
20
- const { id } = params;
21
- const { uid } = user;
22
- if (!uid) {
23
- return { message: 'access restricted: uid', status: 403 };
24
- }
25
- if (!id) {
26
- return { message: 'not enougn params: 1', status: 400 };
27
- }
28
- const extraProperties = Object.keys(body);
29
- if (!extraProperties.length) {
30
- return { message: 'not enougn params: 2', status: 400 };
31
- }
32
-
33
- if (!pg.pk?.[table]) {
34
- return { message: 'table not found: crm.properties', status: 400 };
35
- }
36
-
37
- await pg.query('delete from crm.properties where object_id=$1', [id]); // rewrite?
38
- const keyTypeMatch = extraProperties.filter((key) => body[key]).reduce((acc, curr) => Object.assign(acc, checkKeyType({ body, key: curr })), {});
39
- const res = await Promise.all(Object.keys(keyTypeMatch).map(async (key) => {
40
- const propertyType = keyTypeMatch[key];
41
- const { rows = [] } = await dataInsert({
42
- pg,
43
- table,
44
- data: {
45
- property_type: propertyType,
46
- property_key: key,
47
- object_id: id,
48
- [`property_${propertyType}`]: body[key],
49
- },
50
- uid,
51
- });
52
- return { id: rows[0]?.property_id, type: propertyType, value: body[key] };
53
- }));
54
- return { message: { rows: res }, status: 200 };
55
- }
1
+ import { dataInsert } from '../../../../utils.js';
2
+
3
+ const table = 'crm.properties';
4
+
5
+ function checkKeyType({ body, key }) {
6
+ if (typeof body[key] === 'number' && (!/\D/.test(body[key].toString()) && body[key].toString().length < 10)) {
7
+ return { [key]: 'int' };
8
+ } if (typeof body[key] === 'object') {
9
+ return { [key]: 'json' };
10
+ }
11
+ if (Date.parse(body[key], 'yyyy/MM/ddTHH:mm:ss.000Z')) {
12
+ return { [key]: 'date' };
13
+ }
14
+ return { [key]: 'text' };
15
+ }
16
+
17
+ export default async function addExtraProperties({
18
+ pg, params = {}, body = {}, user = {},
19
+ }) {
20
+ const { id } = params;
21
+ const { uid } = user;
22
+ if (!uid) {
23
+ return { message: 'access restricted: uid', status: 403 };
24
+ }
25
+ if (!id) {
26
+ return { message: 'not enougn params: 1', status: 400 };
27
+ }
28
+ const extraProperties = Object.keys(body);
29
+ if (!extraProperties.length) {
30
+ return { message: 'not enougn params: 2', status: 400 };
31
+ }
32
+
33
+ if (!pg.pk?.[table]) {
34
+ return { message: 'table not found: crm.properties', status: 400 };
35
+ }
36
+
37
+ await pg.query('delete from crm.properties where object_id=$1', [id]); // rewrite?
38
+ const keyTypeMatch = extraProperties.filter((key) => body[key]).reduce((acc, curr) => Object.assign(acc, checkKeyType({ body, key: curr })), {});
39
+ const res = await Promise.all(Object.keys(keyTypeMatch).map(async (key) => {
40
+ const propertyType = keyTypeMatch[key];
41
+ const { rows = [] } = await dataInsert({
42
+ pg,
43
+ table,
44
+ data: {
45
+ property_type: propertyType,
46
+ property_key: key,
47
+ object_id: id,
48
+ [`property_${propertyType}`]: body[key],
49
+ },
50
+ uid,
51
+ });
52
+ return { id: rows[0]?.property_id, type: propertyType, value: body[key] };
53
+ }));
54
+ return { message: { rows: res }, status: 200 };
55
+ }
@@ -1,17 +1,17 @@
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
-
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
- }
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
+
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
+ }
@@ -2,10 +2,9 @@
2
2
  import path from 'node:path';
3
3
 
4
4
  import {
5
- getAccess, handlebars, setOpt, setToken, getTemplate, handlebarsSync, applyHook,
5
+ config, getAccess, handlebars, setOpt, setToken, getTemplate, handlebarsSync, applyHook, getData,
6
6
  } from '../../../../utils.js';
7
7
 
8
- import getTableData from './tableData.js';
9
8
  import conditions from './utils/conditions.js';
10
9
 
11
10
  const components = {
@@ -15,8 +14,9 @@ const components = {
15
14
 
16
15
  export default async function getCardData(req, reply) {
17
16
  const {
18
- pg, params = {}, session = {}, user = {},
17
+ pg, params = {}, user = {},
19
18
  } = req;
19
+
20
20
  const { table, id } = params;
21
21
  const { uid } = user;
22
22
 
@@ -40,11 +40,11 @@ export default async function getCardData(req, reply) {
40
40
  ? await pg.query(
41
41
  `select * from ${index.table} where ${handlebarsSync.compile(index.query)({ uid, user })}`,
42
42
  )
43
- : await getTableData({
44
- pg, params: { table, id }, session, user,
45
- });
43
+ : await getData({
44
+ pg, table, id, user,
45
+ }, reply);
46
46
 
47
- if (message) return { message };
47
+ if (message) return message;
48
48
 
49
49
  // conditions
50
50
  index.panels?.filter(el => el.items).forEach(el1 => {
@@ -72,7 +72,7 @@ export default async function getCardData(req, reply) {
72
72
 
73
73
  // tokens result
74
74
  const tokens = {};
75
- if (index?.tokens && typeof index?.tokens === 'object' && !Array.isArray(index?.tokens)) {
75
+ if (!config.security?.disableToken && index?.tokens && typeof index?.tokens === 'object' && !Array.isArray(index?.tokens)) {
76
76
  Object.keys(index.tokens || {})
77
77
  .filter(key => index?.tokens[key]?.public
78
78
  || access.actions?.includes?.('edit')
@@ -1,42 +1,42 @@
1
- import { applyHook, getTemplate } from '../../../../utils.js';
2
-
3
- const sql = `select property_key as key, property_json as json, property_int as int,
4
- property_text as text from admin.properties where 1=1`;
5
-
6
- async function getSettings({ pg }) {
7
- const { rows = [] } = await pg.query(sql);
8
- const data = rows.reduce((acc, curr) => Object.assign(acc, { [curr.key]: curr.json || curr.int || curr.text }), {});
9
- return data;
10
- }
11
-
12
- export default async function formFunction(req) {
13
- const time = Date.now();
14
-
15
- const { pg, params, user } = req;
16
- const hookData = await applyHook('preForm', { form: params?.form, user });
17
-
18
- if (hookData?.message && hookData?.status) {
19
- return { message: hookData?.message, status: hookData?.status };
20
- }
21
-
22
- const form = await getTemplate('form', hookData?.form || params?.form);
23
- if (!form) { return { status: 404, message: 'not found' }; }
24
-
25
- // replace settings
26
- const arr = JSON.stringify(form).match(/{{settings.([^}]*)}}/g);
27
- if (arr?.length) {
28
- const string = JSON.stringify(form);
29
- const settings = await getSettings({ pg });
30
- const match = arr.reduce((acc, curr) => Object.assign(acc, { [curr]: settings[curr.replace(/^{{settings./g, '').replace(/}}$/, '')] }), {});
31
- const res = Object.keys(match).reduce((s, m) => s.replace(m, match[m]), string);
32
- return { time: Date.now() - time, form: JSON.parse(res) };
33
- }
34
-
35
- const res = { time: Date.now() - time, form };
36
- const res1 = await applyHook('afterForm', {
37
- form: hookData?.form || params?.form,
38
- payload: res,
39
- user,
40
- });
41
- return res1 || { time: Date.now() - time, form };
42
- }
1
+ import { applyHook, getTemplate } from '../../../../utils.js';
2
+
3
+ const sql = `select property_key as key, property_json as json, property_int as int,
4
+ property_text as text from admin.properties where 1=1`;
5
+
6
+ async function getSettings({ pg }) {
7
+ const { rows = [] } = await pg.query(sql);
8
+ const data = rows.reduce((acc, curr) => Object.assign(acc, { [curr.key]: curr.json || curr.int || curr.text }), {});
9
+ return data;
10
+ }
11
+
12
+ export default async function formFunction(req) {
13
+ const time = Date.now();
14
+
15
+ const { pg, params, user } = req;
16
+ const hookData = await applyHook('preForm', { form: params?.form, user });
17
+
18
+ if (hookData?.message && hookData?.status) {
19
+ return { message: hookData?.message, status: hookData?.status };
20
+ }
21
+
22
+ const form = await getTemplate('form', hookData?.form || params?.form);
23
+ if (!form) { return { status: 404, message: 'not found' }; }
24
+
25
+ // replace settings
26
+ const arr = JSON.stringify(form).match(/{{settings.([^}]*)}}/g);
27
+ if (arr?.length) {
28
+ const string = JSON.stringify(form);
29
+ const settings = await getSettings({ pg });
30
+ const match = arr.reduce((acc, curr) => Object.assign(acc, { [curr]: settings[curr.replace(/^{{settings./g, '').replace(/}}$/, '')] }), {});
31
+ const res = Object.keys(match).reduce((s, m) => s.replace(m, match[m]), string);
32
+ return { time: Date.now() - time, form: JSON.parse(res) };
33
+ }
34
+
35
+ const res = { time: Date.now() - time, form };
36
+ const res1 = await applyHook('afterForm', {
37
+ form: hookData?.form || params?.form,
38
+ payload: res,
39
+ user,
40
+ });
41
+ return res1 || { time: Date.now() - time, form };
42
+ }