@opengis/fastify-table 1.1.51 → 1.1.52
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/.gitlab-ci.yml +18 -18
- package/Changelog.md +352 -352
- 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 +132 -132
- package/cron/index.js +12 -10
- package/cron/schema.js +8 -0
- package/crud/controllers/deleteCrud.js +36 -36
- package/crud/controllers/insert.js +71 -71
- package/crud/controllers/update.js +76 -76
- package/crud/controllers/utils/xssInjection.js +72 -72
- package/crud/funcs/dataDelete.js +19 -19
- package/crud/funcs/dataInsert.js +30 -30
- package/crud/funcs/dataUpdate.js +48 -48
- package/crud/funcs/getAccess.js +46 -46
- package/crud/funcs/getOpt.js +10 -10
- package/crud/funcs/getToken.js +27 -27
- package/crud/funcs/isFileExists.js +13 -13
- package/crud/funcs/setOpt.js +16 -16
- package/crud/funcs/setToken.js +53 -53
- package/crud/funcs/utils/getFolder.js +9 -9
- package/crud/funcs/utils/logChanges.js +62 -62
- package/crud/index.js +31 -36
- package/crud/schema.js +11 -0
- package/docs/.vitepress/abbr.mjs +26 -26
- package/docs/.vitepress/config.mjs +127 -127
- package/docs/.vitepress/navigation.mjs +82 -82
- package/docs/.vitepress/theme/Layout.vue +17 -17
- package/docs/.vitepress/theme/components/NavigationLinks.vue +102 -102
- package/docs/.vitepress/theme/components/Panzoom.vue +169 -169
- package/docs/.vitepress/theme/index.mjs +15 -15
- package/docs/.vitepress/theme/style.scss +163 -163
- package/docs/abbr.json +4 -4
- package/docs/api/cron/cronApi.md +56 -56
- package/docs/api/crud/deleteCrud.md +58 -58
- package/docs/api/crud/insert.md +82 -82
- package/docs/api/crud/update.md +85 -85
- package/docs/api/index.md +47 -47
- package/docs/api/notification/testEmail.md +91 -91
- package/docs/api/table/card.md +73 -73
- package/docs/api/table/data.md +134 -134
- package/docs/api/table/export.md +60 -60
- package/docs/api/table/filter.md +104 -104
- package/docs/api/table/form.md +126 -126
- package/docs/api/table/search.md +123 -123
- package/docs/api/table/suggest.md +156 -156
- package/docs/api/table/table.md +107 -107
- package/docs/api/user/user.cls.id.md +77 -77
- package/docs/api/user/user.cls.md +49 -49
- package/docs/api/user/user.cls.post.md +62 -62
- package/docs/api/user/user.info.md +37 -37
- package/docs/api/utils/logger.file.md +60 -60
- package/docs/api/utils/next.id.md +34 -34
- package/docs/api/utils/properties.add.md +127 -127
- package/docs/api/utils/properties.get.md +73 -73
- package/docs/api/utils/status.monitor.md +36 -36
- package/docs/api/widget/widget.del.md +76 -76
- package/docs/api/widget/widget.get.md +233 -233
- package/docs/api/widget/widget.set.md +88 -88
- package/docs/db/admin.md +947 -947
- package/docs/db/crm.md +564 -564
- package/docs/db/index.md +9 -9
- package/docs/db/log.md +204 -204
- package/docs/hook/card/afterCard.md +20 -20
- package/docs/hook/card/preCard.md +25 -25
- package/docs/hook/data/afterData.md +26 -26
- package/docs/hook/data/preData.md +26 -26
- package/docs/hook/deleteCrud/afterDelete.md +21 -21
- package/docs/hook/deleteCrud/preDelete.md +26 -26
- package/docs/hook/form/afterForm.md +19 -19
- package/docs/hook/form/preForm.md +26 -26
- package/docs/hook/getTemplate/afterTemplate.md +24 -24
- package/docs/hook/getTemplate/preTemplate.md +29 -29
- package/docs/hook/index.md +45 -45
- package/docs/hook/insert/afterInsert.md +41 -41
- package/docs/hook/insert/preInsert.md +25 -25
- package/docs/hook/table/afterTable.md +20 -20
- package/docs/hook/table/preTable.md +25 -25
- package/docs/hook/update/afterUpdate.md +41 -41
- package/docs/hook/update/preUpdate.md +25 -25
- package/docs/index.md +42 -42
- package/docs/public/fastify-dark.svg +3 -3
- package/docs/public/logo-short-dark.svg +11 -11
- package/docs/public/logo-short.svg +10 -10
- package/docs/public/logo.svg +19 -19
- package/docs/readme/index.md +121 -121
- package/docs/templates/card.md +83 -83
- package/docs/templates/cls.md +29 -29
- package/docs/templates/filters.md +91 -91
- package/docs/templates/forms.md +139 -139
- package/docs/templates/index.md +28 -28
- package/docs/templates/select.md +90 -90
- package/docs/templates/table.md +162 -162
- package/docs/utils/cron/addCron.md +29 -29
- package/docs/utils/crud/dataInsert.md +51 -51
- package/docs/utils/crud/dataUpdate.md +52 -52
- package/docs/utils/crud/getOpt.md +33 -33
- package/docs/utils/crud/isFileExists.md +37 -37
- package/docs/utils/crud/setOpt.md +37 -37
- package/docs/utils/hook/addHook.md +74 -74
- package/docs/utils/hook/applyHook.md +64 -64
- package/docs/utils/index.md +47 -47
- package/docs/utils/notification/addNotification.md +28 -28
- package/docs/utils/notification/notification.md +41 -41
- package/docs/utils/pg/autoIndex.md +22 -22
- package/docs/utils/pg/getMeta.md +58 -58
- package/docs/utils/pg/getPG.md +34 -34
- package/docs/utils/pg/init.md +29 -29
- package/docs/utils/pg/pg.md +70 -70
- package/docs/utils/redis/getRedis.md +36 -36
- package/docs/utils/redis/rclient.md +74 -74
- package/docs/utils/table/getForm.md +68 -68
- package/docs/utils/table/getMeta.md +55 -55
- package/docs/utils/table/getSelect.md +38 -38
- package/docs/utils/table/getSelectMeta.md +46 -46
- package/docs/utils/table/getTable.md +77 -77
- package/helper.js +30 -30
- package/index.js +105 -105
- package/migration/exec.migrations.js +79 -79
- package/module/core/select/core.user_mentioned.sql +1 -1
- package/module/test/cls/itree.composition.json +25 -25
- package/module/test/table/test.rest_zone.table.json +265 -265
- package/notification/controllers/readNotifications.js +27 -30
- package/notification/controllers/testEmail.js +46 -50
- package/notification/controllers/userNotifications.js +61 -64
- package/notification/funcs/addNotification.js +21 -21
- package/notification/funcs/sendNotification.js +112 -112
- package/notification/index.js +3 -8
- package/notification/schema.js +10 -0
- package/package.json +41 -41
- package/pg/funcs/getMeta.js +29 -29
- package/pg/funcs/getPG.js +30 -30
- package/pg/pgClients.js +20 -20
- package/policy/funcs/checkPolicy.js +92 -92
- package/policy/funcs/sqlInjection.js +33 -33
- package/policy/index.js +14 -14
- package/redis/client.js +8 -8
- package/redis/funcs/getRedis.js +23 -23
- package/redis/funcs/redisClients.js +2 -2
- package/redis/index.js +19 -19
- package/server/migrations/0.sql +78 -78
- package/server/migrations/cls.sql +39 -39
- package/server/migrations/log.sql +80 -80
- package/server/migrations/properties.sql +144 -144
- package/server/migrations/roles.sql +172 -172
- package/server/migrations/users.sql +168 -168
- package/server.js +26 -26
- package/table/controllers/data.js +157 -150
- package/table/controllers/filter.js +61 -50
- package/table/controllers/form.js +42 -42
- package/table/controllers/search.js +76 -80
- package/table/controllers/suggest.js +79 -79
- package/table/controllers/table.js +83 -83
- package/table/controllers/utils/addTemplateDir.js +8 -8
- package/table/controllers/utils/getSelect.js +19 -19
- package/table/controllers/utils/getSelectMeta.js +66 -66
- package/table/controllers/utils/getTemplate_old.js +28 -28
- package/table/controllers/utils/getTemplates.js +18 -18
- package/table/controllers/utils/gisIRColumn.js +72 -67
- package/table/controllers/utils/loadTemplate.js +1 -1
- package/table/controllers/utils/loadTemplatePath.js +1 -1
- package/table/controllers/utils/userTemplateDir.js +1 -1
- package/table/funcs/getFilterSQL/index.js +94 -94
- package/table/funcs/getFilterSQL/util/formatValue.js +170 -170
- package/table/funcs/getFilterSQL/util/getCustomQuery.js +13 -13
- package/table/funcs/getFilterSQL/util/getFilterQuery.js +66 -66
- package/table/funcs/getFilterSQL/util/getOptimizedQuery.js +12 -12
- package/table/funcs/getFilterSQL/util/getTableSql.js +34 -34
- package/table/funcs/metaFormat/getSelectVal.js +21 -21
- package/table/funcs/metaFormat/index.js +28 -28
- package/table/index.js +37 -37
- package/table/schema.js +64 -54
- package/test/api/applyHook.test.js +95 -95
- package/test/api/crud.test.js +89 -89
- package/test/api/crud.xss.test.js +80 -80
- package/test/api/suggest.test.js +66 -66
- package/test/api/table.test.js +134 -134
- package/test/api/user.test.js +85 -85
- package/test/api/widget.test.js +117 -117
- package/test/config.example +18 -18
- package/test/funcs/pg.test.js +34 -34
- package/test/funcs/redis.test.js +19 -19
- package/test/helper/formatDate.test.js +62 -62
- 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/select/test.storage.data.json +3 -3
- package/test/templates/select/test.suggest.ato_new.json +3 -3
- package/test/templates/select/test.suggest.ato_new.sql +25 -25
- package/test/templates/select/test.suggest.data.json +4 -4
- package/test/templates/select/test.suggest.parent.sql +1 -1
- package/test/templates/table/gis.dataset.table.json +20 -20
- package/user/controllers/user.cls.id.js +14 -14
- package/user/controllers/user.cls.js +71 -75
- package/user/controllers/user.cls.post.js +52 -55
- package/user/controllers/user.info.js +17 -21
- package/user/index.js +7 -36
- package/user/schema.js +17 -0
- package/util/controllers/logger.file.js +91 -91
- package/util/controllers/next.id.js +4 -4
- package/util/controllers/properties.add.js +56 -60
- package/util/controllers/properties.get.js +16 -19
- package/util/controllers/status.monitor.js +8 -8
- package/util/controllers/utils/checkUserAccess.js +20 -17
- package/util/controllers/utils/getRootDir.js +25 -25
- package/util/index.js +19 -23
- package/util/schema.js +19 -0
- package/utils.js +106 -104
- package/widget/controllers/utils/historyFormat.js +76 -76
- package/widget/controllers/utils/obj2db.js +13 -13
- package/widget/controllers/widget.del.js +41 -44
- package/widget/controllers/widget.get.js +96 -102
- package/widget/controllers/widget.set.js +74 -79
- package/widget/index.js +40 -40
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
import {
|
|
2
|
-
pgClients, applyHook, getAccess, getTemplate, checkXSS, dataInsert, dataUpdate, logger, getToken,
|
|
3
|
-
} from '../../utils.js';
|
|
4
|
-
import config from '../../config.js';
|
|
5
|
-
|
|
6
|
-
export default async function update(req) {
|
|
7
|
-
const { user, params = {}, body = {} } = req;
|
|
8
|
-
const hookData = await applyHook('preUpdate', {
|
|
9
|
-
table: params?.table, id: params?.id, user,
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
if (hookData?.message && hookData?.status) {
|
|
13
|
-
return { message: hookData?.message, status: hookData?.status };
|
|
14
|
-
}
|
|
15
|
-
const tokenData = await getToken({
|
|
16
|
-
uid: user.uid, token: body.token || params.table, mode: 'w', json: 1,
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
const { form, table: edit, id } = hookData || tokenData || (config.auth?.disable ? params : {});
|
|
20
|
-
|
|
21
|
-
const { actions = [] } = await getAccess({ table: edit, id, user }) || {};
|
|
22
|
-
|
|
23
|
-
if (!actions.includes('edit')) {
|
|
24
|
-
return { message: 'access restricted', status: 403 };
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (!edit) {
|
|
28
|
-
return { message: 'table is required', status: 400 };
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (!id) {
|
|
32
|
-
return { message: 'id is required', status: 404 };
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const loadTemplate = await getTemplate('table', edit);
|
|
36
|
-
const { table } = loadTemplate || hookData || params || {};
|
|
37
|
-
|
|
38
|
-
const uid = user?.uid;
|
|
39
|
-
|
|
40
|
-
const formData = form || loadTemplate?.form ? await getTemplate('form', form || loadTemplate?.form) : {};
|
|
41
|
-
|
|
42
|
-
const xssCheck = checkXSS({ body, schema: formData?.schema || formData });
|
|
43
|
-
|
|
44
|
-
if (xssCheck.error && formData?.xssCheck !== false) {
|
|
45
|
-
logger.warn({ name: 'injection/xss', msg: xssCheck.error, table }, req);
|
|
46
|
-
return { message: 'Дані містять заборонені символи. Приберіть їх та спробуйте ще раз', status: 409 };
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const res = await dataUpdate({
|
|
50
|
-
table: loadTemplate?.table || table, id, data: body, uid,
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
// admin.custom_column
|
|
54
|
-
await applyHook('afterUpdate', {
|
|
55
|
-
table: params?.table, body, payload: res, user,
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
// form DataTable
|
|
59
|
-
const extraKeys = Object.keys(formData)?.filter((key) => formData?.[key]?.type === 'DataTable' && formData?.[key]?.table && formData?.[key]?.parent_id && body[key].length);
|
|
60
|
-
if (extraKeys?.length) {
|
|
61
|
-
res.extra = {};
|
|
62
|
-
await Promise.all(extraKeys?.map(async (key) => {
|
|
63
|
-
const objId = body[formData[key].parent_id] || body?.id;
|
|
64
|
-
// delete old extra data
|
|
65
|
-
await pgClients.client.query(`delete from ${formData[key].table} where ${formData[key].parent_id}=$1`, [objId]); // rewrite?
|
|
66
|
-
// insert new extra data
|
|
67
|
-
const extraRows = await Promise.all(body[key].map(async (row) => {
|
|
68
|
-
const extraRes = await dataInsert({ table: formData[key].table, data: { ...row, [formData[key].parent_id]: objId }, uid });
|
|
69
|
-
return extraRes?.rows?.[0];
|
|
70
|
-
}));
|
|
71
|
-
Object.assign(res.extra, { [key]: extraRows.filter((el) => el) });
|
|
72
|
-
}));
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return res;
|
|
76
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
pgClients, applyHook, getAccess, getTemplate, checkXSS, dataInsert, dataUpdate, logger, getToken,
|
|
3
|
+
} from '../../utils.js';
|
|
4
|
+
import config from '../../config.js';
|
|
5
|
+
|
|
6
|
+
export default async function update(req) {
|
|
7
|
+
const { user, params = {}, body = {} } = req;
|
|
8
|
+
const hookData = await applyHook('preUpdate', {
|
|
9
|
+
table: params?.table, id: params?.id, user,
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
if (hookData?.message && hookData?.status) {
|
|
13
|
+
return { message: hookData?.message, status: hookData?.status };
|
|
14
|
+
}
|
|
15
|
+
const tokenData = await getToken({
|
|
16
|
+
uid: user.uid, token: body.token || params.table, mode: 'w', json: 1,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const { form, table: edit, id } = hookData || tokenData || (config.auth?.disable ? params : {});
|
|
20
|
+
|
|
21
|
+
const { actions = [] } = await getAccess({ table: edit, id, user }) || {};
|
|
22
|
+
|
|
23
|
+
if (!actions.includes('edit')) {
|
|
24
|
+
return { message: 'access restricted', status: 403 };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (!edit) {
|
|
28
|
+
return { message: 'table is required', status: 400 };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (!id) {
|
|
32
|
+
return { message: 'id is required', status: 404 };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const loadTemplate = await getTemplate('table', edit);
|
|
36
|
+
const { table } = loadTemplate || hookData || params || {};
|
|
37
|
+
|
|
38
|
+
const uid = user?.uid;
|
|
39
|
+
|
|
40
|
+
const formData = form || loadTemplate?.form ? await getTemplate('form', form || loadTemplate?.form) : {};
|
|
41
|
+
|
|
42
|
+
const xssCheck = checkXSS({ body, schema: formData?.schema || formData });
|
|
43
|
+
|
|
44
|
+
if (xssCheck.error && formData?.xssCheck !== false) {
|
|
45
|
+
logger.warn({ name: 'injection/xss', msg: xssCheck.error, table }, req);
|
|
46
|
+
return { message: 'Дані містять заборонені символи. Приберіть їх та спробуйте ще раз', status: 409 };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const res = await dataUpdate({
|
|
50
|
+
table: loadTemplate?.table || table, id, data: body, uid,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// admin.custom_column
|
|
54
|
+
await applyHook('afterUpdate', {
|
|
55
|
+
table: params?.table, body, payload: res, user,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// form DataTable
|
|
59
|
+
const extraKeys = Object.keys(formData)?.filter((key) => formData?.[key]?.type === 'DataTable' && formData?.[key]?.table && formData?.[key]?.parent_id && body[key].length);
|
|
60
|
+
if (extraKeys?.length) {
|
|
61
|
+
res.extra = {};
|
|
62
|
+
await Promise.all(extraKeys?.map(async (key) => {
|
|
63
|
+
const objId = body[formData[key].parent_id] || body?.id;
|
|
64
|
+
// delete old extra data
|
|
65
|
+
await pgClients.client.query(`delete from ${formData[key].table} where ${formData[key].parent_id}=$1`, [objId]); // rewrite?
|
|
66
|
+
// insert new extra data
|
|
67
|
+
const extraRows = await Promise.all(body[key].map(async (row) => {
|
|
68
|
+
const extraRes = await dataInsert({ table: formData[key].table, data: { ...row, [formData[key].parent_id]: objId }, uid });
|
|
69
|
+
return extraRes?.rows?.[0];
|
|
70
|
+
}));
|
|
71
|
+
Object.assign(res.extra, { [key]: extraRows.filter((el) => el) });
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return res;
|
|
76
|
+
}
|
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
const xssInjection = [
|
|
2
|
-
'onkeypress=',
|
|
3
|
-
'onkeyup=',
|
|
4
|
-
'ondblclick=',
|
|
5
|
-
'onerror=',
|
|
6
|
-
'onmouseover=',
|
|
7
|
-
'<meta',
|
|
8
|
-
'<script',
|
|
9
|
-
'vascript:',
|
|
10
|
-
'onkeydown=',
|
|
11
|
-
'onmousedown=',
|
|
12
|
-
'onmouseenter=',
|
|
13
|
-
'onmouseleave=',
|
|
14
|
-
'onmousemove=',
|
|
15
|
-
'onmouseout=',
|
|
16
|
-
'onmouseup=',
|
|
17
|
-
'onmousewheel=',
|
|
18
|
-
'onpaste=',
|
|
19
|
-
'onscroll=',
|
|
20
|
-
'onwheel=',
|
|
21
|
-
'javascript:',
|
|
22
|
-
'\\x',
|
|
23
|
-
'eval(',
|
|
24
|
-
'onmouseover=',
|
|
25
|
-
'action=',
|
|
26
|
-
'xlink:',
|
|
27
|
-
'allowscriptaccess',
|
|
28
|
-
'href=',
|
|
29
|
-
'behavior:',
|
|
30
|
-
'onreadystatechange=',
|
|
31
|
-
'onstart=',
|
|
32
|
-
'offline=',
|
|
33
|
-
'onabort=',
|
|
34
|
-
'onafterprint=',
|
|
35
|
-
'onbeforeonload=',
|
|
36
|
-
'onbeforeprint=',
|
|
37
|
-
'onblur=',
|
|
38
|
-
'oncanplay=',
|
|
39
|
-
'oncanplaythrough=',
|
|
40
|
-
'onchange=',
|
|
41
|
-
'onclick=',
|
|
42
|
-
'oncontextmenu=',
|
|
43
|
-
'ondblclick=',
|
|
44
|
-
'ondrag=',
|
|
45
|
-
'ondragend=',
|
|
46
|
-
'ondragenter=',
|
|
47
|
-
'ondragleave=',
|
|
48
|
-
'ondragover=',
|
|
49
|
-
'ondragstart=',
|
|
50
|
-
'ondrop=',
|
|
51
|
-
'ondurationchange=',
|
|
52
|
-
'onemptied=',
|
|
53
|
-
'onended=',
|
|
54
|
-
'onerror=',
|
|
55
|
-
'onfocus=',
|
|
56
|
-
'onformchange=',
|
|
57
|
-
'onforminput=',
|
|
58
|
-
'onhaschange=',
|
|
59
|
-
'oninput=',
|
|
60
|
-
'oninvalid=',
|
|
61
|
-
'onkeydown=',
|
|
62
|
-
'onkeypress=',
|
|
63
|
-
'onkeyup=',
|
|
64
|
-
'onload=',
|
|
65
|
-
'onloadeddata=',
|
|
66
|
-
'onloadedmetadata=',
|
|
67
|
-
'onloadstart=',
|
|
68
|
-
'alert(',
|
|
69
|
-
'script:',
|
|
70
|
-
];
|
|
71
|
-
|
|
72
|
-
export default xssInjection;
|
|
1
|
+
const xssInjection = [
|
|
2
|
+
'onkeypress=',
|
|
3
|
+
'onkeyup=',
|
|
4
|
+
'ondblclick=',
|
|
5
|
+
'onerror=',
|
|
6
|
+
'onmouseover=',
|
|
7
|
+
'<meta',
|
|
8
|
+
'<script',
|
|
9
|
+
'vascript:',
|
|
10
|
+
'onkeydown=',
|
|
11
|
+
'onmousedown=',
|
|
12
|
+
'onmouseenter=',
|
|
13
|
+
'onmouseleave=',
|
|
14
|
+
'onmousemove=',
|
|
15
|
+
'onmouseout=',
|
|
16
|
+
'onmouseup=',
|
|
17
|
+
'onmousewheel=',
|
|
18
|
+
'onpaste=',
|
|
19
|
+
'onscroll=',
|
|
20
|
+
'onwheel=',
|
|
21
|
+
'javascript:',
|
|
22
|
+
'\\x',
|
|
23
|
+
'eval(',
|
|
24
|
+
'onmouseover=',
|
|
25
|
+
'action=',
|
|
26
|
+
'xlink:',
|
|
27
|
+
'allowscriptaccess',
|
|
28
|
+
'href=',
|
|
29
|
+
'behavior:',
|
|
30
|
+
'onreadystatechange=',
|
|
31
|
+
'onstart=',
|
|
32
|
+
'offline=',
|
|
33
|
+
'onabort=',
|
|
34
|
+
'onafterprint=',
|
|
35
|
+
'onbeforeonload=',
|
|
36
|
+
'onbeforeprint=',
|
|
37
|
+
'onblur=',
|
|
38
|
+
'oncanplay=',
|
|
39
|
+
'oncanplaythrough=',
|
|
40
|
+
'onchange=',
|
|
41
|
+
'onclick=',
|
|
42
|
+
'oncontextmenu=',
|
|
43
|
+
'ondblclick=',
|
|
44
|
+
'ondrag=',
|
|
45
|
+
'ondragend=',
|
|
46
|
+
'ondragenter=',
|
|
47
|
+
'ondragleave=',
|
|
48
|
+
'ondragover=',
|
|
49
|
+
'ondragstart=',
|
|
50
|
+
'ondrop=',
|
|
51
|
+
'ondurationchange=',
|
|
52
|
+
'onemptied=',
|
|
53
|
+
'onended=',
|
|
54
|
+
'onerror=',
|
|
55
|
+
'onfocus=',
|
|
56
|
+
'onformchange=',
|
|
57
|
+
'onforminput=',
|
|
58
|
+
'onhaschange=',
|
|
59
|
+
'oninput=',
|
|
60
|
+
'oninvalid=',
|
|
61
|
+
'onkeydown=',
|
|
62
|
+
'onkeypress=',
|
|
63
|
+
'onkeyup=',
|
|
64
|
+
'onload=',
|
|
65
|
+
'onloadeddata=',
|
|
66
|
+
'onloadedmetadata=',
|
|
67
|
+
'onloadstart=',
|
|
68
|
+
'alert(',
|
|
69
|
+
'script:',
|
|
70
|
+
];
|
|
71
|
+
|
|
72
|
+
export default xssInjection;
|
package/crud/funcs/dataDelete.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import getPG from '../../pg/funcs/getPG.js';
|
|
2
|
-
|
|
3
|
-
import getMeta from '../../pg/funcs/getMeta.js';
|
|
4
|
-
import logChanges from './utils/logChanges.js';
|
|
5
|
-
|
|
6
|
-
export default async function dataDelete({
|
|
7
|
-
table, id, pg: pg1, uid,
|
|
8
|
-
}) {
|
|
9
|
-
const pg = pg1 || getPG({ name: 'client' });
|
|
10
|
-
const { pk } = await getMeta(table);
|
|
11
|
-
if (!pg.tlist?.includes(table)) return 'table not exist';
|
|
12
|
-
const delQuery = `delete from ${table} WHERE ${pk} = $1 returning *`;
|
|
13
|
-
// console.log(updateDataset);
|
|
14
|
-
const res = await pg.one(delQuery, [id]) || {};
|
|
15
|
-
await logChanges({
|
|
16
|
-
pg, table, id, uid, type: 'DELETE',
|
|
17
|
-
});
|
|
18
|
-
return res;
|
|
19
|
-
}
|
|
1
|
+
import getPG from '../../pg/funcs/getPG.js';
|
|
2
|
+
|
|
3
|
+
import getMeta from '../../pg/funcs/getMeta.js';
|
|
4
|
+
import logChanges from './utils/logChanges.js';
|
|
5
|
+
|
|
6
|
+
export default async function dataDelete({
|
|
7
|
+
table, id, pg: pg1, uid,
|
|
8
|
+
}) {
|
|
9
|
+
const pg = pg1 || getPG({ name: 'client' });
|
|
10
|
+
const { pk } = await getMeta(table);
|
|
11
|
+
if (!pg.tlist?.includes(table)) return 'table not exist';
|
|
12
|
+
const delQuery = `delete from ${table} WHERE ${pk} = $1 returning *`;
|
|
13
|
+
// console.log(updateDataset);
|
|
14
|
+
const res = await pg.one(delQuery, [id]) || {};
|
|
15
|
+
await logChanges({
|
|
16
|
+
pg, table, id, uid, type: 'DELETE',
|
|
17
|
+
});
|
|
18
|
+
return res;
|
|
19
|
+
}
|
package/crud/funcs/dataInsert.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import getPG from '../../pg/funcs/getPG.js';
|
|
2
|
-
import getMeta from '../../pg/funcs/getMeta.js';
|
|
3
|
-
import logChanges from './utils/logChanges.js';
|
|
4
|
-
|
|
5
|
-
export default async function dataInsert({
|
|
6
|
-
table, data, pg: pg1, uid,
|
|
7
|
-
}) {
|
|
8
|
-
const pg = pg1 || getPG({ name: 'client' });
|
|
9
|
-
if (!data) return null;
|
|
10
|
-
const { columns } = await getMeta(table);
|
|
11
|
-
if (!columns) return null;
|
|
12
|
-
|
|
13
|
-
const names = columns.map((el) => el.name);
|
|
14
|
-
const filterData = Object.keys(data)
|
|
15
|
-
.filter((el) => data[el] && names.includes(el)).map((el) => [el, data[el]]);
|
|
16
|
-
|
|
17
|
-
const insertQuery = `insert into ${table}
|
|
18
|
-
|
|
19
|
-
( ${filterData?.map((key) => `"${key[0]}"`).join(',')})
|
|
20
|
-
|
|
21
|
-
values (${filterData?.map((key, i) => (key[0] === 'geom' ? `st_setsrid(st_geomfromgeojson($${i + 1}::json),4326)` : `$${i + 1}`)).join(',')})
|
|
22
|
-
|
|
23
|
-
returning *`;
|
|
24
|
-
|
|
25
|
-
const res = await pg.query(insertQuery, [...filterData.map((el) => (typeof el[1] === 'object' && (!Array.isArray(el[1]) || typeof el[1]?.[0] === 'object') ? JSON.stringify(el[1]) : el[1]))]) || {};
|
|
26
|
-
await logChanges({
|
|
27
|
-
pg, table, data, id: res.rows?.[0]?.[pg.pk[table]], uid, type: 'INSERT',
|
|
28
|
-
});
|
|
29
|
-
return res;
|
|
30
|
-
}
|
|
1
|
+
import getPG from '../../pg/funcs/getPG.js';
|
|
2
|
+
import getMeta from '../../pg/funcs/getMeta.js';
|
|
3
|
+
import logChanges from './utils/logChanges.js';
|
|
4
|
+
|
|
5
|
+
export default async function dataInsert({
|
|
6
|
+
table, data, pg: pg1, uid,
|
|
7
|
+
}) {
|
|
8
|
+
const pg = pg1 || getPG({ name: 'client' });
|
|
9
|
+
if (!data) return null;
|
|
10
|
+
const { columns } = await getMeta(table);
|
|
11
|
+
if (!columns) return null;
|
|
12
|
+
|
|
13
|
+
const names = columns.map((el) => el.name);
|
|
14
|
+
const filterData = Object.keys(data)
|
|
15
|
+
.filter((el) => data[el] && names.includes(el)).map((el) => [el, data[el]]);
|
|
16
|
+
|
|
17
|
+
const insertQuery = `insert into ${table}
|
|
18
|
+
|
|
19
|
+
( ${filterData?.map((key) => `"${key[0]}"`).join(',')})
|
|
20
|
+
|
|
21
|
+
values (${filterData?.map((key, i) => (key[0] === 'geom' ? `st_setsrid(st_geomfromgeojson($${i + 1}::json),4326)` : `$${i + 1}`)).join(',')})
|
|
22
|
+
|
|
23
|
+
returning *`;
|
|
24
|
+
|
|
25
|
+
const res = await pg.query(insertQuery, [...filterData.map((el) => (typeof el[1] === 'object' && (!Array.isArray(el[1]) || typeof el[1]?.[0] === 'object') ? JSON.stringify(el[1]) : el[1]))]) || {};
|
|
26
|
+
await logChanges({
|
|
27
|
+
pg, table, data, id: res.rows?.[0]?.[pg.pk[table]], uid, type: 'INSERT',
|
|
28
|
+
});
|
|
29
|
+
return res;
|
|
30
|
+
}
|
package/crud/funcs/dataUpdate.js
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
import getPG from '../../pg/funcs/getPG.js';
|
|
2
|
-
|
|
3
|
-
import getMeta from '../../pg/funcs/getMeta.js';
|
|
4
|
-
import logChanges from './utils/logChanges.js';
|
|
5
|
-
|
|
6
|
-
const srids = {};
|
|
7
|
-
|
|
8
|
-
export default async function dataUpdate({
|
|
9
|
-
table, id, data, pg: pg1, uid,
|
|
10
|
-
}) {
|
|
11
|
-
if (!data || !table || !id) return null;
|
|
12
|
-
|
|
13
|
-
const pg = pg1 || getPG({ name: 'client' });
|
|
14
|
-
const { columns, pk } = await getMeta(table);
|
|
15
|
-
|
|
16
|
-
const names = columns?.map((el) => el.name);
|
|
17
|
-
Object.assign(data, { editor_id: uid });
|
|
18
|
-
const filterData = Object.keys(data)
|
|
19
|
-
.filter((el) => (/* typeof data[el] === 'boolean' ? true : data[el] && */ names?.includes(el) && el !== 'editor_date'));
|
|
20
|
-
|
|
21
|
-
const editorDate = names?.includes('editor_date') ? 'editor_date=now(),' : '';
|
|
22
|
-
|
|
23
|
-
const filterValue = filterData.map((el) => [el, data[el]]).map((el) => (typeof el[1] === 'object' && el[1] && (!Array.isArray(el[1]) || typeof el[1]?.[0] === 'object') ? JSON.stringify(el[1]) : el[1]));
|
|
24
|
-
|
|
25
|
-
// update geometry with srid
|
|
26
|
-
if (!srids[table]) {
|
|
27
|
-
const { srids1 } = await pg.query(`select json_object_agg(_table,rel) as srids1 from (
|
|
28
|
-
select f_table_schema||'.'||f_table_name as _table,
|
|
29
|
-
json_object_agg(f_geometry_column, case when srid = 0 then 4326 else srid end) as rel
|
|
30
|
-
from geometry_columns group by f_table_schema||'.'||f_table_name
|
|
31
|
-
)q`).then((res1) => res1.rows?.[0] || {});
|
|
32
|
-
Object.assign(srids, srids1);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const updateQuery = `UPDATE ${table} SET ${editorDate} ${filterData
|
|
36
|
-
?.map((key, i) => (key?.includes('geom') && key !== 'geom' ? `"${key}"=st_setsrid(st_geomfromgeojson($${i + 2}::json),${srids[table]?.[key] || 4326})` : undefined)
|
|
37
|
-
|| (key === 'geom' ? `"${key}"=st_setsrid(st_geomfromgeojson($${i + 2}::json),4326)` : `"${key}"=$${i + 2}`))
|
|
38
|
-
.join(',')}
|
|
39
|
-
WHERE ${pk} = $1 returning *`;
|
|
40
|
-
// console.log(updateQuery, filterValue);
|
|
41
|
-
const res = await pg.query(updateQuery, [id, ...filterValue]).then(el => el?.rows?.[0]) || {};
|
|
42
|
-
|
|
43
|
-
await logChanges({
|
|
44
|
-
pg, table, data, id, uid, type: 'UPDATE',
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
return res;
|
|
48
|
-
}
|
|
1
|
+
import getPG from '../../pg/funcs/getPG.js';
|
|
2
|
+
|
|
3
|
+
import getMeta from '../../pg/funcs/getMeta.js';
|
|
4
|
+
import logChanges from './utils/logChanges.js';
|
|
5
|
+
|
|
6
|
+
const srids = {};
|
|
7
|
+
|
|
8
|
+
export default async function dataUpdate({
|
|
9
|
+
table, id, data, pg: pg1, uid,
|
|
10
|
+
}) {
|
|
11
|
+
if (!data || !table || !id) return null;
|
|
12
|
+
|
|
13
|
+
const pg = pg1 || getPG({ name: 'client' });
|
|
14
|
+
const { columns, pk } = await getMeta(table);
|
|
15
|
+
|
|
16
|
+
const names = columns?.map((el) => el.name);
|
|
17
|
+
Object.assign(data, { editor_id: uid });
|
|
18
|
+
const filterData = Object.keys(data)
|
|
19
|
+
.filter((el) => (/* typeof data[el] === 'boolean' ? true : data[el] && */ names?.includes(el) && el !== 'editor_date'));
|
|
20
|
+
|
|
21
|
+
const editorDate = names?.includes('editor_date') ? 'editor_date=now(),' : '';
|
|
22
|
+
|
|
23
|
+
const filterValue = filterData.map((el) => [el, data[el]]).map((el) => (typeof el[1] === 'object' && el[1] && (!Array.isArray(el[1]) || typeof el[1]?.[0] === 'object') ? JSON.stringify(el[1]) : el[1]));
|
|
24
|
+
|
|
25
|
+
// update geometry with srid
|
|
26
|
+
if (!srids[table]) {
|
|
27
|
+
const { srids1 } = await pg.query(`select json_object_agg(_table,rel) as srids1 from (
|
|
28
|
+
select f_table_schema||'.'||f_table_name as _table,
|
|
29
|
+
json_object_agg(f_geometry_column, case when srid = 0 then 4326 else srid end) as rel
|
|
30
|
+
from geometry_columns group by f_table_schema||'.'||f_table_name
|
|
31
|
+
)q`).then((res1) => res1.rows?.[0] || {});
|
|
32
|
+
Object.assign(srids, srids1);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const updateQuery = `UPDATE ${table} SET ${editorDate} ${filterData
|
|
36
|
+
?.map((key, i) => (key?.includes('geom') && key !== 'geom' ? `"${key}"=st_setsrid(st_geomfromgeojson($${i + 2}::json),${srids[table]?.[key] || 4326})` : undefined)
|
|
37
|
+
|| (key === 'geom' ? `"${key}"=st_setsrid(st_geomfromgeojson($${i + 2}::json),4326)` : `"${key}"=$${i + 2}`))
|
|
38
|
+
.join(',')}
|
|
39
|
+
WHERE ${pk} = $1 returning *`;
|
|
40
|
+
// console.log(updateQuery, filterValue);
|
|
41
|
+
const res = await pg.query(updateQuery, [id, ...filterValue]).then(el => el?.rows?.[0]) || {};
|
|
42
|
+
|
|
43
|
+
await logChanges({
|
|
44
|
+
pg, table, data, id, uid, type: 'UPDATE',
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
return res;
|
|
48
|
+
}
|
package/crud/funcs/getAccess.js
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
// import getMeta from '../../pg/funcs/getMeta.js';
|
|
2
|
-
import getTemplate from '../../table/controllers/utils/getTemplate.js';
|
|
3
|
-
import config from '../../config.js';
|
|
4
|
-
import pgClients from '../../pg/pgClients.js';
|
|
5
|
-
import applyHook from '../../hook/funcs/applyHook.js';
|
|
6
|
-
|
|
7
|
-
const q = `select a.route_id as id, coalesce(b.actions,array['get']) as actions, b.scope
|
|
8
|
-
from admin.routes a
|
|
9
|
-
left join admin.access b on
|
|
10
|
-
a.route_id=b.route_id
|
|
11
|
-
left join admin.roles c on
|
|
12
|
-
b.role_id=c.role_id
|
|
13
|
-
and c.enabled
|
|
14
|
-
left join admin.user_roles d on
|
|
15
|
-
c.role_id=d.role_id
|
|
16
|
-
and ( case when
|
|
17
|
-
d.expiration is not null
|
|
18
|
-
then d.expiration > CURRENT_DATE
|
|
19
|
-
else 1=1
|
|
20
|
-
end )
|
|
21
|
-
where $1 in (a.route_id, a.alias) and $2 in (b.user_uid, d.user_uid)`;
|
|
22
|
-
|
|
23
|
-
export default async function getAccess({ table, user = {} }) {
|
|
24
|
-
if (!table) return null;
|
|
25
|
-
|
|
26
|
-
const hookData = await applyHook('getAccess', { table, user });
|
|
27
|
-
if (hookData) return hookData;
|
|
28
|
-
|
|
29
|
-
const { uid } = user;
|
|
30
|
-
const body = await getTemplate('table', table) || {};
|
|
31
|
-
|
|
32
|
-
// console.log(user?.type);
|
|
33
|
-
if (body.access === 'admin' && user?.type !== 'admin') return null;
|
|
34
|
-
|
|
35
|
-
if (config.auth?.disable || user?.type === 'admin' || body?.public || body.access === 'public' || (body.access === 'user' && user.uid)) {
|
|
36
|
-
return { actions: ['get'].concat(user.uid ? body.actions || body.action_default || [] : []), query: '1=1' };
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (!uid || !body?.table) return null;
|
|
40
|
-
|
|
41
|
-
const { scope, actions = [] } = await pgClients.client.query(q, [table, uid]).then((res) => res.rows?.[0] || {});
|
|
42
|
-
|
|
43
|
-
return {
|
|
44
|
-
scope, actions, query: scope === 'my' ? `uid='${uid}` : null,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
1
|
+
// import getMeta from '../../pg/funcs/getMeta.js';
|
|
2
|
+
import getTemplate from '../../table/controllers/utils/getTemplate.js';
|
|
3
|
+
import config from '../../config.js';
|
|
4
|
+
import pgClients from '../../pg/pgClients.js';
|
|
5
|
+
import applyHook from '../../hook/funcs/applyHook.js';
|
|
6
|
+
|
|
7
|
+
const q = `select a.route_id as id, coalesce(b.actions,array['get']) as actions, b.scope
|
|
8
|
+
from admin.routes a
|
|
9
|
+
left join admin.access b on
|
|
10
|
+
a.route_id=b.route_id
|
|
11
|
+
left join admin.roles c on
|
|
12
|
+
b.role_id=c.role_id
|
|
13
|
+
and c.enabled
|
|
14
|
+
left join admin.user_roles d on
|
|
15
|
+
c.role_id=d.role_id
|
|
16
|
+
and ( case when
|
|
17
|
+
d.expiration is not null
|
|
18
|
+
then d.expiration > CURRENT_DATE
|
|
19
|
+
else 1=1
|
|
20
|
+
end )
|
|
21
|
+
where $1 in (a.route_id, a.alias) and $2 in (b.user_uid, d.user_uid)`;
|
|
22
|
+
|
|
23
|
+
export default async function getAccess({ table, user = {} }) {
|
|
24
|
+
if (!table) return null;
|
|
25
|
+
|
|
26
|
+
const hookData = await applyHook('getAccess', { table, user });
|
|
27
|
+
if (hookData) return hookData;
|
|
28
|
+
|
|
29
|
+
const { uid } = user;
|
|
30
|
+
const body = await getTemplate('table', table) || {};
|
|
31
|
+
|
|
32
|
+
// console.log(user?.type);
|
|
33
|
+
if (body.access === 'admin' && user?.type !== 'admin') return null;
|
|
34
|
+
|
|
35
|
+
if (config.auth?.disable || user?.type === 'admin' || body?.public || body.access === 'public' || (body.access === 'user' && user.uid)) {
|
|
36
|
+
return { actions: ['get'].concat(user.uid ? body.actions || body.action_default || [] : []), query: '1=1' };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (!uid || !body?.table) return null;
|
|
40
|
+
|
|
41
|
+
const { scope, actions = [] } = await pgClients.client.query(q, [table, uid]).then((res) => res.rows?.[0] || {});
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
scope, actions, query: scope === 'my' ? `uid='${uid}` : null,
|
|
45
|
+
};
|
|
46
|
+
}
|
package/crud/funcs/getOpt.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import getRedis from '../../redis/funcs/getRedis.js';
|
|
2
|
-
|
|
3
|
-
export default async function getOpt(token, funcs) {
|
|
4
|
-
const rclient = getRedis({ db: 0, funcs });
|
|
5
|
-
|
|
6
|
-
const key = `opt:${token}`;
|
|
7
|
-
const data = await rclient.get(key);
|
|
8
|
-
if (!data) return null;
|
|
9
|
-
return JSON.parse(data);
|
|
10
|
-
}
|
|
1
|
+
import getRedis from '../../redis/funcs/getRedis.js';
|
|
2
|
+
|
|
3
|
+
export default async function getOpt(token, funcs) {
|
|
4
|
+
const rclient = getRedis({ db: 0, funcs });
|
|
5
|
+
|
|
6
|
+
const key = `opt:${token}`;
|
|
7
|
+
const data = await rclient.get(key);
|
|
8
|
+
if (!data) return null;
|
|
9
|
+
return JSON.parse(data);
|
|
10
|
+
}
|