@opengis/fastify-table 1.0.82 → 1.0.84
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.
- package/.eslintrc.cjs +42 -42
- package/Changelog.md +253 -245
- package/README.md +26 -26
- package/config.js +10 -10
- package/cron/controllers/cronApi.js +22 -22
- package/cron/controllers/utils/cronList.js +1 -1
- package/cron/funcs/addCron.js +131 -131
- package/cron/index.js +10 -10
- package/crud/controllers/utils/checkXSS.js +45 -45
- package/crud/controllers/utils/xssInjection.js +72 -72
- package/crud/funcs/dataDelete.js +15 -15
- package/crud/funcs/dataUpdate.js +24 -24
- package/crud/funcs/getToken.js +27 -27
- package/crud/funcs/isFileExists.js +13 -13
- package/crud/funcs/setToken.js +53 -53
- package/crud/index.js +36 -36
- package/index.js +1 -1
- package/migration/exec.migrations.js +75 -75
- package/notification/controllers/testEmail.js +49 -49
- package/notification/funcs/sendNotification.js +111 -111
- package/notification/funcs/utils/sendEmail.js +39 -39
- package/notification/index.js +38 -38
- package/package.json +26 -26
- package/pg/funcs/getPG.js +30 -30
- package/redis/funcs/getRedis.js +23 -23
- package/server/migrations/0.sql +14 -0
- package/server/migrations/crm.sql +150 -150
- package/server/migrations/log.sql +43 -43
- package/server/templates/select/test.storage.data.json +3 -3
- package/server/templates/select/test.suggest.ato_new.json +2 -2
- package/server/templates/select/test.suggest.ato_new.sql +25 -25
- package/server/templates/select/test.suggest.data.json +4 -4
- package/server/templates/select/test.suggest.parent.sql +2 -2
- package/server.js +14 -14
- package/table/controllers/card.js +44 -44
- package/table/controllers/data.js +97 -97
- package/table/controllers/filter.js +37 -37
- package/table/controllers/form.js +28 -28
- package/table/controllers/search.js +72 -72
- package/table/controllers/suggest.js +18 -1
- package/table/controllers/utils/getSelect.js +20 -20
- package/table/controllers/utils/getSelectMeta.js +66 -66
- package/table/controllers/utils/getTemplate.js +28 -28
- package/table/controllers/utils/getTemplates.js +18 -18
- package/table/funcs/metaFormat/index.js +27 -27
- package/table/index.js +80 -78
- package/test/api/crud.xss.test.js +72 -72
- package/test/api/notification.test.js +37 -37
- package/test/api/suggest.test.js +65 -65
- package/test/api/table.test.js +57 -57
- package/test/api/widget.test.js +114 -114
- package/test/config.example +18 -18
- package/test/funcs/crud.test.js +76 -76
- package/test/funcs/notification.test.js +31 -31
- package/test/funcs/pg.test.js +34 -34
- package/test/funcs/redis.test.js +19 -19
- package/test/templates/cls/test.json +9 -9
- package/test/templates/form/cp_building.form.json +32 -32
- package/test/templates/select/account_id.json +3 -3
- package/test/templates/select/storage.data.json +2 -2
- package/test/templates/table/gis.dataset.table.json +20 -20
- package/util/controllers/next.id.js +4 -4
- package/util/controllers/properties.add.js +50 -50
- package/util/controllers/properties.get.js +19 -19
- package/widget/index.js +40 -40
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
// import pgClients from '../../../pg/pgClients.js';
|
|
2
|
-
import getPG from '../../../pg/funcs/getPG.js';
|
|
3
|
-
|
|
4
|
-
import getSelect from './getSelect.js';
|
|
5
|
-
|
|
6
|
-
/*
|
|
7
|
-
function getTable(table) {
|
|
8
|
-
// eslint-disable-next-line class-methods-use-this
|
|
9
|
-
const result = table.toLowerCase().replace(/[\n\r]+/g, ' ').split(' from ').filter((el) => /^[a-z0-9_]+\.[a-z0-9_]+/.test(el))
|
|
10
|
-
.map((el) => el.split(/[ )]/)[0]);
|
|
11
|
-
return result?.pop();
|
|
12
|
-
} */
|
|
13
|
-
|
|
14
|
-
const selectMeta = {};
|
|
15
|
-
|
|
16
|
-
export default async function getSelectMeta({ name, pg: pg1 }) {
|
|
17
|
-
if (selectMeta[name]) return selectMeta[name];
|
|
18
|
-
|
|
19
|
-
const cls = await getSelect(name);
|
|
20
|
-
|
|
21
|
-
if (!cls) return null;
|
|
22
|
-
if (cls.arr) return cls;
|
|
23
|
-
if (!cls.sql) return null;
|
|
24
|
-
|
|
25
|
-
const pg = pg1 || getPG({ db: cls.db || 'client' });
|
|
26
|
-
const { sql: original } = cls;
|
|
27
|
-
const sql = `with c(id,text) as (${original} ) select * from c `;
|
|
28
|
-
|
|
29
|
-
/*= == meta table === */
|
|
30
|
-
const tableNew = original.toLowerCase().replace(/\n/g, ' ').split(' from ').filter((el) => /^[a-z0-9_]+\.[a-z0-9_]+/.test(el))
|
|
31
|
-
.map((el) => el.split(/[ )]/)[0].replace(/[\r\n]+/g, ''));
|
|
32
|
-
|
|
33
|
-
const dataOrigin = await pg.query(`${sql} limit 0`);
|
|
34
|
-
|
|
35
|
-
const dataOrigin1 = await pg.query(`${original} limit 0`);
|
|
36
|
-
|
|
37
|
-
// const table = getTable(original);
|
|
38
|
-
const count = cls?.count ?? await pg.query(`select count(*) from (${original})q`).then((el) => el?.rows?.[0].count);
|
|
39
|
-
|
|
40
|
-
// column name
|
|
41
|
-
const cols = dataOrigin.fields.map((el) => el.name);
|
|
42
|
-
const type = dataOrigin.fields.map((el) => pg.pgType?.[el.dataTypeID] || 'text');
|
|
43
|
-
|
|
44
|
-
const searchColumn = cls?.searchColumn || (
|
|
45
|
-
dataOrigin.fields.find((el) => el.name === 'search') ? 'search' : dataOrigin.fields[1].name);
|
|
46
|
-
|
|
47
|
-
const searchQuery = `(${searchColumn.split(',').map((el) => `"${el}" ilike $1 `).join(' or ')})`;
|
|
48
|
-
|
|
49
|
-
const data = {
|
|
50
|
-
|
|
51
|
-
type: type.join(','),
|
|
52
|
-
cols: cols.join(','),
|
|
53
|
-
originalCols: dataOrigin1.fields.map((el) => el.name).join(','),
|
|
54
|
-
db: cls.db,
|
|
55
|
-
original: original?.includes('where') ? `select * from (${sql})q` : sql,
|
|
56
|
-
sql,
|
|
57
|
-
count,
|
|
58
|
-
searchQuery,
|
|
59
|
-
table: tableNew.join(','),
|
|
60
|
-
time: new Date().toISOString(),
|
|
61
|
-
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
selectMeta[name] = data;
|
|
65
|
-
return data;
|
|
66
|
-
}
|
|
1
|
+
// import pgClients from '../../../pg/pgClients.js';
|
|
2
|
+
import getPG from '../../../pg/funcs/getPG.js';
|
|
3
|
+
|
|
4
|
+
import getSelect from './getSelect.js';
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
function getTable(table) {
|
|
8
|
+
// eslint-disable-next-line class-methods-use-this
|
|
9
|
+
const result = table.toLowerCase().replace(/[\n\r]+/g, ' ').split(' from ').filter((el) => /^[a-z0-9_]+\.[a-z0-9_]+/.test(el))
|
|
10
|
+
.map((el) => el.split(/[ )]/)[0]);
|
|
11
|
+
return result?.pop();
|
|
12
|
+
} */
|
|
13
|
+
|
|
14
|
+
const selectMeta = {};
|
|
15
|
+
|
|
16
|
+
export default async function getSelectMeta({ name, pg: pg1 }) {
|
|
17
|
+
if (selectMeta[name]) return selectMeta[name];
|
|
18
|
+
|
|
19
|
+
const cls = await getSelect(name);
|
|
20
|
+
|
|
21
|
+
if (!cls) return null;
|
|
22
|
+
if (cls.arr) return cls;
|
|
23
|
+
if (!cls.sql) return null;
|
|
24
|
+
|
|
25
|
+
const pg = pg1 || getPG({ db: cls.db || 'client' });
|
|
26
|
+
const { sql: original } = cls;
|
|
27
|
+
const sql = `with c(id,text) as (${original} ) select * from c `;
|
|
28
|
+
|
|
29
|
+
/*= == meta table === */
|
|
30
|
+
const tableNew = original.toLowerCase().replace(/\n/g, ' ').split(' from ').filter((el) => /^[a-z0-9_]+\.[a-z0-9_]+/.test(el))
|
|
31
|
+
.map((el) => el.split(/[ )]/)[0].replace(/[\r\n]+/g, ''));
|
|
32
|
+
|
|
33
|
+
const dataOrigin = await pg.query(`${sql} limit 0`);
|
|
34
|
+
|
|
35
|
+
const dataOrigin1 = await pg.query(`${original} limit 0`);
|
|
36
|
+
|
|
37
|
+
// const table = getTable(original);
|
|
38
|
+
const count = cls?.count ?? await pg.query(`select count(*) from (${original})q`).then((el) => el?.rows?.[0].count);
|
|
39
|
+
|
|
40
|
+
// column name
|
|
41
|
+
const cols = dataOrigin.fields.map((el) => el.name);
|
|
42
|
+
const type = dataOrigin.fields.map((el) => pg.pgType?.[el.dataTypeID] || 'text');
|
|
43
|
+
|
|
44
|
+
const searchColumn = cls?.searchColumn || (
|
|
45
|
+
dataOrigin.fields.find((el) => el.name === 'search') ? 'search' : dataOrigin.fields[1].name);
|
|
46
|
+
|
|
47
|
+
const searchQuery = `(${searchColumn.split(',').map((el) => `"${el}" ilike $1 `).join(' or ')})`;
|
|
48
|
+
|
|
49
|
+
const data = {
|
|
50
|
+
|
|
51
|
+
type: type.join(','),
|
|
52
|
+
cols: cols.join(','),
|
|
53
|
+
originalCols: dataOrigin1.fields.map((el) => el.name).join(','),
|
|
54
|
+
db: cls.db,
|
|
55
|
+
original: original?.includes('where') ? `select * from (${sql})q` : sql,
|
|
56
|
+
sql,
|
|
57
|
+
count,
|
|
58
|
+
searchQuery,
|
|
59
|
+
table: tableNew.join(','),
|
|
60
|
+
time: new Date().toISOString(),
|
|
61
|
+
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
selectMeta[name] = data;
|
|
65
|
+
return data;
|
|
66
|
+
}
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { readFile } from 'fs/promises';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import config from '../../../config.js';
|
|
5
|
-
|
|
6
|
-
const loadTemplate = {};
|
|
7
|
-
|
|
8
|
-
export default async function getTemplateDir(type, name) {
|
|
9
|
-
if (!type) return null;
|
|
10
|
-
if (!name) return null;
|
|
11
|
-
|
|
12
|
-
const cwd = process.cwd();
|
|
13
|
-
const typeDir = path.join(cwd, (config.templateDir || 'server/templates'), type);
|
|
14
|
-
|
|
15
|
-
if (!loadTemplate[type]) {
|
|
16
|
-
const typeList = fs.existsSync(typeDir) ? fs.readdirSync(typeDir) : [];
|
|
17
|
-
loadTemplate[type] = typeList;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const fullname = loadTemplate[type].find((el) => path.parse(el).name === name);
|
|
21
|
-
const ext = fullname ? path.extname(fullname)?.slice(1) : null;
|
|
22
|
-
if (!ext) return null;
|
|
23
|
-
|
|
24
|
-
const sql = loadTemplate[type].includes(`${name}.sql`) ? await readFile(path.join(typeDir, `${name}.sql`), 'utf-8') : null;
|
|
25
|
-
const data = loadTemplate[type].includes(`${name}.json`) ? JSON.parse(await readFile(path.join(typeDir, `${name}.json`), 'utf-8')) : await readFile(path.join(typeDir, `${name}.${ext}`), 'utf-8');
|
|
26
|
-
if (sql) return { ...data || {}, sql };
|
|
27
|
-
return data;
|
|
28
|
-
}
|
|
1
|
+
import { readFile } from 'fs/promises';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import config from '../../../config.js';
|
|
5
|
+
|
|
6
|
+
const loadTemplate = {};
|
|
7
|
+
|
|
8
|
+
export default async function getTemplateDir(type, name) {
|
|
9
|
+
if (!type) return null;
|
|
10
|
+
if (!name) return null;
|
|
11
|
+
|
|
12
|
+
const cwd = process.cwd();
|
|
13
|
+
const typeDir = path.join(cwd, (config.templateDir || 'server/templates'), type);
|
|
14
|
+
|
|
15
|
+
if (!loadTemplate[type]) {
|
|
16
|
+
const typeList = fs.existsSync(typeDir) ? fs.readdirSync(typeDir) : [];
|
|
17
|
+
loadTemplate[type] = typeList;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const fullname = loadTemplate[type].find((el) => path.parse(el).name === name);
|
|
21
|
+
const ext = fullname ? path.extname(fullname)?.slice(1) : null;
|
|
22
|
+
if (!ext) return null;
|
|
23
|
+
|
|
24
|
+
const sql = loadTemplate[type].includes(`${name}.sql`) ? await readFile(path.join(typeDir, `${name}.sql`), 'utf-8') : null;
|
|
25
|
+
const data = loadTemplate[type].includes(`${name}.json`) ? JSON.parse(await readFile(path.join(typeDir, `${name}.json`), 'utf-8')) : await readFile(path.join(typeDir, `${name}.${ext}`), 'utf-8');
|
|
26
|
+
if (sql) return { ...data || {}, sql };
|
|
27
|
+
return data;
|
|
28
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import config from '../../../config.js';
|
|
4
|
-
|
|
5
|
-
const loadTemplate = {};
|
|
6
|
-
|
|
7
|
-
export default async function getTemplateDir(type) {
|
|
8
|
-
if (!type) return null;
|
|
9
|
-
|
|
10
|
-
const cwd = process.cwd();
|
|
11
|
-
const typeDir = path.join(cwd, (config.templateDir || 'server/templates'), type);
|
|
12
|
-
|
|
13
|
-
if (!loadTemplate[type]) {
|
|
14
|
-
const typeList = fs.existsSync(typeDir) ? fs.readdirSync(typeDir) : [];
|
|
15
|
-
loadTemplate[type] = typeList;
|
|
16
|
-
}
|
|
17
|
-
return loadTemplate[type];
|
|
18
|
-
}
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import config from '../../../config.js';
|
|
4
|
+
|
|
5
|
+
const loadTemplate = {};
|
|
6
|
+
|
|
7
|
+
export default async function getTemplateDir(type) {
|
|
8
|
+
if (!type) return null;
|
|
9
|
+
|
|
10
|
+
const cwd = process.cwd();
|
|
11
|
+
const typeDir = path.join(cwd, (config.templateDir || 'server/templates'), type);
|
|
12
|
+
|
|
13
|
+
if (!loadTemplate[type]) {
|
|
14
|
+
const typeList = fs.existsSync(typeDir) ? fs.readdirSync(typeDir) : [];
|
|
15
|
+
loadTemplate[type] = typeList;
|
|
16
|
+
}
|
|
17
|
+
return loadTemplate[type];
|
|
18
|
+
}
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import getTemplate from '../../controllers/utils/getTemplate.js';
|
|
2
|
-
import getSelectVal from './getSelectVal.js';
|
|
3
|
-
|
|
4
|
-
export default async function metaFormat({ rows, table }) {
|
|
5
|
-
const loadTable = await getTemplate('table', table);
|
|
6
|
-
const selectCols = loadTable?.columns?.filter((e) => e.data);
|
|
7
|
-
if (!selectCols?.length) return rows;
|
|
8
|
-
|
|
9
|
-
// cls & select format
|
|
10
|
-
|
|
11
|
-
await Promise.all(selectCols?.map(async (attr) => {
|
|
12
|
-
const values = [...new Set(rows?.map((el) => el[attr.name]).flat())].filter((el) => el);
|
|
13
|
-
if (!values.length) return null;
|
|
14
|
-
|
|
15
|
-
const cls = await getSelectVal({ name: attr.data, values });
|
|
16
|
-
if (!cls) return null;
|
|
17
|
-
rows.forEach(el => {
|
|
18
|
-
const val = el[attr.name]?.map?.(c => cls[c] || c) || cls[el[attr.name]] || el[attr.name];
|
|
19
|
-
if (!val) return;
|
|
20
|
-
Object.assign(el, { [val?.color ? `${attr.name}_data` : `${attr.name}_text`]: (val.color ? val : val.text || val) });
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
return null;
|
|
24
|
-
}));
|
|
25
|
-
|
|
26
|
-
return rows;
|
|
27
|
-
}
|
|
1
|
+
import getTemplate from '../../controllers/utils/getTemplate.js';
|
|
2
|
+
import getSelectVal from './getSelectVal.js';
|
|
3
|
+
|
|
4
|
+
export default async function metaFormat({ rows, table }) {
|
|
5
|
+
const loadTable = await getTemplate('table', table);
|
|
6
|
+
const selectCols = loadTable?.columns?.filter((e) => e.data);
|
|
7
|
+
if (!selectCols?.length) return rows;
|
|
8
|
+
|
|
9
|
+
// cls & select format
|
|
10
|
+
|
|
11
|
+
await Promise.all(selectCols?.map(async (attr) => {
|
|
12
|
+
const values = [...new Set(rows?.map((el) => el[attr.name]).flat())].filter((el) => el);
|
|
13
|
+
if (!values.length) return null;
|
|
14
|
+
|
|
15
|
+
const cls = await getSelectVal({ name: attr.data, values });
|
|
16
|
+
if (!cls) return null;
|
|
17
|
+
rows.forEach(el => {
|
|
18
|
+
const val = el[attr.name]?.map?.(c => cls[c] || c) || cls[el[attr.name]] || el[attr.name];
|
|
19
|
+
if (!val) return;
|
|
20
|
+
Object.assign(el, { [val?.color ? `${attr.name}_data` : `${attr.name}_text`]: (val.color ? val : val.text || val) });
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
return null;
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
return rows;
|
|
27
|
+
}
|
package/table/index.js
CHANGED
|
@@ -1,78 +1,80 @@
|
|
|
1
|
-
import suggest from './controllers/suggest.js';
|
|
2
|
-
import data from './controllers/data.js';
|
|
3
|
-
import table from './controllers/table.js';
|
|
4
|
-
import card from './controllers/card.js';
|
|
5
|
-
import search from './controllers/search.js';
|
|
6
|
-
import filter from './controllers/filter.js';
|
|
7
|
-
import form from './controllers/form.js';
|
|
8
|
-
import metaFormat from './funcs/metaFormat/index.js';
|
|
9
|
-
import getFilterSQL from './funcs/getFilterSQL/index.js';
|
|
10
|
-
import getTemplate from './controllers/utils/getTemplate.js';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
fastify.decorate('
|
|
67
|
-
fastify.decorate('
|
|
68
|
-
|
|
69
|
-
fastify.
|
|
70
|
-
|
|
71
|
-
fastify.get(`${prefix}/
|
|
72
|
-
fastify.get(`${prefix}/
|
|
73
|
-
fastify.get(`${prefix}/
|
|
74
|
-
fastify.get(`${prefix}/
|
|
75
|
-
fastify.get(`${prefix}/
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
1
|
+
import suggest from './controllers/suggest.js';
|
|
2
|
+
import data from './controllers/data.js';
|
|
3
|
+
import table from './controllers/table.js';
|
|
4
|
+
import card from './controllers/card.js';
|
|
5
|
+
import search from './controllers/search.js';
|
|
6
|
+
import filter from './controllers/filter.js';
|
|
7
|
+
import form from './controllers/form.js';
|
|
8
|
+
import metaFormat from './funcs/metaFormat/index.js';
|
|
9
|
+
import getFilterSQL from './funcs/getFilterSQL/index.js';
|
|
10
|
+
import getTemplate from './controllers/utils/getTemplate.js';
|
|
11
|
+
import getSelect from './controllers/utils/getSelect.js';
|
|
12
|
+
|
|
13
|
+
const tableSchema = {
|
|
14
|
+
querystring: {
|
|
15
|
+
page: { type: 'string', pattern: '^(\\d+)$' },
|
|
16
|
+
order: { type: 'string', pattern: '^(\\d+)$' },
|
|
17
|
+
filter: { type: 'string', pattern: '^([\\w\\d_-]+)=([\\w\\d_-]+)$' },
|
|
18
|
+
},
|
|
19
|
+
params: {
|
|
20
|
+
id: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
21
|
+
table: { type: 'string', pattern: '^([\\w\\d_.]+)$' },
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const searchSchema = {
|
|
26
|
+
querystring: {
|
|
27
|
+
page: { type: 'string', pattern: '^(\\d+)$' },
|
|
28
|
+
limit: { type: 'string', pattern: '^(\\d+)$' },
|
|
29
|
+
order: { type: 'string', pattern: '^([\\w_.]+)$' },
|
|
30
|
+
desc: { type: 'string', pattern: '^(desc)|(asc)$' },
|
|
31
|
+
key: { type: 'string', pattern: '^([\\w\\d_]+)$' },
|
|
32
|
+
table: { type: 'string', pattern: '^([\\w\\d_.]+)$' },
|
|
33
|
+
sql: { type: 'string', pattern: '^(\\d)$' },
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const suggestSchema = {
|
|
38
|
+
querystring: {
|
|
39
|
+
lang: { type: 'string', pattern: '^([\\w.]+)$' },
|
|
40
|
+
// parent: { type: 'string', pattern: '^([\\w,./]+)$' },
|
|
41
|
+
sel: { type: 'string', pattern: '^([\\w,./]+)$' },
|
|
42
|
+
name: { type: 'string', pattern: '^([\\w,./]+)$' },
|
|
43
|
+
// key: { type: 'string', pattern: '^([\\w\\d_]+)$' },
|
|
44
|
+
// val: { type: 'string', pattern: '^([\\w.,]+)$' },
|
|
45
|
+
sql: { type: 'string', pattern: '^(\\d)$' },
|
|
46
|
+
},
|
|
47
|
+
params: {
|
|
48
|
+
id: { type: 'string', pattern: '^([\\d\\w]+)$' },
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const formSchema = {
|
|
53
|
+
params: {
|
|
54
|
+
form: { type: 'string', pattern: '^([\\w\\d_.]+)$' },
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const filterSchema = {
|
|
59
|
+
params: {
|
|
60
|
+
table: { type: 'string', pattern: '^([\\w\\d_.]+)$' },
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
async function plugin(fastify, config = {}) {
|
|
65
|
+
const prefix = config.prefix || '/api';
|
|
66
|
+
fastify.decorate('metaFormat', metaFormat);
|
|
67
|
+
fastify.decorate('getFilterSQL', getFilterSQL);
|
|
68
|
+
fastify.decorate('getTemplate', getTemplate);
|
|
69
|
+
fastify.decorate('getSelect', getSelect);
|
|
70
|
+
|
|
71
|
+
fastify.get(`${prefix}/suggest/:data`, { schema: suggestSchema }, suggest);
|
|
72
|
+
fastify.get(`${prefix}/data/:table/:id?`, { schema: tableSchema }, data); // vs.crm.data.api с node
|
|
73
|
+
fastify.get(`${prefix}/table/:table/:id`, { schema: tableSchema }, table);
|
|
74
|
+
fastify.get(`${prefix}/card/:table/:id`, { schema: tableSchema }, card);
|
|
75
|
+
fastify.get(`${prefix}/search`, { schema: searchSchema }, search);
|
|
76
|
+
fastify.get(`${prefix}/filter/:table`, { schema: filterSchema }, filter);
|
|
77
|
+
fastify.get(`${prefix}/form/:form`, { schema: formSchema }, form);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export default plugin;
|
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
import { test } from 'node:test';
|
|
2
|
-
import assert from 'node:assert';
|
|
3
|
-
|
|
4
|
-
import build from '../../helper.js';
|
|
5
|
-
|
|
6
|
-
import setToken from '../../crud/funcs/setToken.js';
|
|
7
|
-
import config from '../config.js';
|
|
8
|
-
|
|
9
|
-
test('api crud xss', async (t) => {
|
|
10
|
-
const app = await build(t);
|
|
11
|
-
const session = { passport: { user: { uid: '1' } } };
|
|
12
|
-
app.addHook('onRequest', async (req) => {
|
|
13
|
-
req.session = session;
|
|
14
|
-
});
|
|
15
|
-
// app.decorateRequest('session', session);
|
|
16
|
-
|
|
17
|
-
const prefix = config.prefix || '/api';
|
|
18
|
-
|
|
19
|
-
let addTokens;
|
|
20
|
-
let editTokens;
|
|
21
|
-
|
|
22
|
-
// before
|
|
23
|
-
t.test('setToken', async () => {
|
|
24
|
-
addTokens = setToken({
|
|
25
|
-
ids: [JSON.stringify({ add: 'gis.dataset', form: 'test.dataset.form' })],
|
|
26
|
-
mode: 'a',
|
|
27
|
-
uid: 1,
|
|
28
|
-
array: 1,
|
|
29
|
-
});
|
|
30
|
-
editTokens = setToken({
|
|
31
|
-
ids: [JSON.stringify({ id: '5400000', table: 'gis.dataset', form: 'test.dataset.form' })],
|
|
32
|
-
mode: 'w',
|
|
33
|
-
uid: 1,
|
|
34
|
-
array: 1,
|
|
35
|
-
});
|
|
36
|
-
assert.ok(addTokens.length === 1 && editTokens.length === 1, 'invalid token');
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
await t.test('POST /insert', async () => {
|
|
40
|
-
const res = await app.inject({
|
|
41
|
-
method: 'POST',
|
|
42
|
-
url: `${prefix}/table/${addTokens[0]}`,
|
|
43
|
-
body: { dataset_name: '<a onClick="alert("XSS Injection")">xss injection</a>', dataset_id: '5400000' },
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
const rep = JSON.parse(res?.body);
|
|
47
|
-
console.log(rep)
|
|
48
|
-
assert.ok(rep.status, 409);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
await t.test('PUT /update', async () => {
|
|
52
|
-
const res = await app.inject({
|
|
53
|
-
method: 'PUT',
|
|
54
|
-
url: `${prefix}/table/${editTokens[0]}/${editTokens[0]}`,
|
|
55
|
-
body: { editor_id: '11', dataset_name: '<a onClick="alert("XSS Injection")">xss injection</a>' },
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
const rep = JSON.parse(res?.body);
|
|
59
|
-
console.log(rep)
|
|
60
|
-
assert.equal(rep.status, 409);
|
|
61
|
-
});
|
|
62
|
-
await t.test('DELETE /delete', async () => {
|
|
63
|
-
const res = await app.inject({
|
|
64
|
-
method: 'DELETE',
|
|
65
|
-
url: `${prefix}/table/gis.dataset/5400000`,
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
const rep = JSON.parse(res?.body);
|
|
69
|
-
console.log(rep)
|
|
70
|
-
assert.ok(rep);
|
|
71
|
-
});
|
|
72
|
-
});
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
|
|
4
|
+
import build from '../../helper.js';
|
|
5
|
+
|
|
6
|
+
import setToken from '../../crud/funcs/setToken.js';
|
|
7
|
+
import config from '../config.js';
|
|
8
|
+
|
|
9
|
+
test('api crud xss', async (t) => {
|
|
10
|
+
const app = await build(t);
|
|
11
|
+
const session = { passport: { user: { uid: '1' } } };
|
|
12
|
+
app.addHook('onRequest', async (req) => {
|
|
13
|
+
req.session = session;
|
|
14
|
+
});
|
|
15
|
+
// app.decorateRequest('session', session);
|
|
16
|
+
|
|
17
|
+
const prefix = config.prefix || '/api';
|
|
18
|
+
|
|
19
|
+
let addTokens;
|
|
20
|
+
let editTokens;
|
|
21
|
+
|
|
22
|
+
// before
|
|
23
|
+
t.test('setToken', async () => {
|
|
24
|
+
addTokens = setToken({
|
|
25
|
+
ids: [JSON.stringify({ add: 'gis.dataset', form: 'test.dataset.form' })],
|
|
26
|
+
mode: 'a',
|
|
27
|
+
uid: 1,
|
|
28
|
+
array: 1,
|
|
29
|
+
});
|
|
30
|
+
editTokens = setToken({
|
|
31
|
+
ids: [JSON.stringify({ id: '5400000', table: 'gis.dataset', form: 'test.dataset.form' })],
|
|
32
|
+
mode: 'w',
|
|
33
|
+
uid: 1,
|
|
34
|
+
array: 1,
|
|
35
|
+
});
|
|
36
|
+
assert.ok(addTokens.length === 1 && editTokens.length === 1, 'invalid token');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
await t.test('POST /insert', async () => {
|
|
40
|
+
const res = await app.inject({
|
|
41
|
+
method: 'POST',
|
|
42
|
+
url: `${prefix}/table/${addTokens[0]}`,
|
|
43
|
+
body: { dataset_name: '<a onClick="alert("XSS Injection")">xss injection</a>', dataset_id: '5400000' },
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const rep = JSON.parse(res?.body);
|
|
47
|
+
console.log(rep)
|
|
48
|
+
assert.ok(rep.status, 409);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
await t.test('PUT /update', async () => {
|
|
52
|
+
const res = await app.inject({
|
|
53
|
+
method: 'PUT',
|
|
54
|
+
url: `${prefix}/table/${editTokens[0]}/${editTokens[0]}`,
|
|
55
|
+
body: { editor_id: '11', dataset_name: '<a onClick="alert("XSS Injection")">xss injection</a>' },
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const rep = JSON.parse(res?.body);
|
|
59
|
+
console.log(rep)
|
|
60
|
+
assert.equal(rep.status, 409);
|
|
61
|
+
});
|
|
62
|
+
await t.test('DELETE /delete', async () => {
|
|
63
|
+
const res = await app.inject({
|
|
64
|
+
method: 'DELETE',
|
|
65
|
+
url: `${prefix}/table/gis.dataset/5400000`,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const rep = JSON.parse(res?.body);
|
|
69
|
+
console.log(rep)
|
|
70
|
+
assert.ok(rep);
|
|
71
|
+
});
|
|
72
|
+
});
|