@opengis/fastify-table 1.1.51 → 1.1.53

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 (218) hide show
  1. package/.eslintrc.cjs +42 -42
  2. package/.gitlab-ci.yml +18 -18
  3. package/Changelog.md +352 -352
  4. package/README.md +26 -26
  5. package/config.js +10 -10
  6. package/cron/controllers/cronApi.js +22 -22
  7. package/cron/controllers/utils/cronList.js +1 -1
  8. package/cron/funcs/addCron.js +132 -132
  9. package/cron/index.js +12 -10
  10. package/cron/schema.js +8 -0
  11. package/crud/controllers/deleteCrud.js +36 -36
  12. package/crud/controllers/insert.js +71 -71
  13. package/crud/controllers/update.js +76 -76
  14. package/crud/controllers/utils/xssInjection.js +72 -72
  15. package/crud/funcs/dataDelete.js +19 -19
  16. package/crud/funcs/dataInsert.js +30 -30
  17. package/crud/funcs/dataUpdate.js +48 -48
  18. package/crud/funcs/getAccess.js +46 -46
  19. package/crud/funcs/getOpt.js +10 -10
  20. package/crud/funcs/getToken.js +27 -27
  21. package/crud/funcs/isFileExists.js +13 -13
  22. package/crud/funcs/setOpt.js +16 -16
  23. package/crud/funcs/setToken.js +53 -53
  24. package/crud/funcs/utils/getFolder.js +9 -9
  25. package/crud/funcs/utils/logChanges.js +62 -62
  26. package/crud/index.js +31 -36
  27. package/crud/schema.js +11 -0
  28. package/docs/.vitepress/abbr.mjs +26 -26
  29. package/docs/.vitepress/config.mjs +127 -127
  30. package/docs/.vitepress/navigation.mjs +82 -82
  31. package/docs/.vitepress/theme/Layout.vue +17 -17
  32. package/docs/.vitepress/theme/components/NavigationLinks.vue +102 -102
  33. package/docs/.vitepress/theme/components/Panzoom.vue +169 -169
  34. package/docs/.vitepress/theme/index.mjs +15 -15
  35. package/docs/.vitepress/theme/style.scss +163 -163
  36. package/docs/abbr.json +4 -4
  37. package/docs/api/cron/cronApi.md +56 -56
  38. package/docs/api/crud/deleteCrud.md +58 -58
  39. package/docs/api/crud/insert.md +82 -82
  40. package/docs/api/crud/update.md +85 -85
  41. package/docs/api/index.md +47 -47
  42. package/docs/api/notification/testEmail.md +91 -91
  43. package/docs/api/table/card.md +73 -73
  44. package/docs/api/table/data.md +134 -134
  45. package/docs/api/table/export.md +60 -60
  46. package/docs/api/table/filter.md +104 -104
  47. package/docs/api/table/form.md +126 -126
  48. package/docs/api/table/search.md +123 -123
  49. package/docs/api/table/suggest.md +156 -156
  50. package/docs/api/table/table.md +107 -107
  51. package/docs/api/user/user.cls.id.md +77 -77
  52. package/docs/api/user/user.cls.md +49 -49
  53. package/docs/api/user/user.cls.post.md +62 -62
  54. package/docs/api/user/user.info.md +37 -37
  55. package/docs/api/utils/logger.file.md +60 -60
  56. package/docs/api/utils/next.id.md +34 -34
  57. package/docs/api/utils/properties.add.md +127 -127
  58. package/docs/api/utils/properties.get.md +73 -73
  59. package/docs/api/utils/status.monitor.md +36 -36
  60. package/docs/api/widget/widget.del.md +76 -76
  61. package/docs/api/widget/widget.get.md +233 -233
  62. package/docs/api/widget/widget.set.md +88 -88
  63. package/docs/db/admin.md +947 -947
  64. package/docs/db/crm.md +564 -564
  65. package/docs/db/index.md +9 -9
  66. package/docs/db/log.md +204 -204
  67. package/docs/hook/card/afterCard.md +20 -20
  68. package/docs/hook/card/preCard.md +25 -25
  69. package/docs/hook/data/afterData.md +26 -26
  70. package/docs/hook/data/preData.md +26 -26
  71. package/docs/hook/deleteCrud/afterDelete.md +21 -21
  72. package/docs/hook/deleteCrud/preDelete.md +26 -26
  73. package/docs/hook/form/afterForm.md +19 -19
  74. package/docs/hook/form/preForm.md +26 -26
  75. package/docs/hook/getTemplate/afterTemplate.md +24 -24
  76. package/docs/hook/getTemplate/preTemplate.md +29 -29
  77. package/docs/hook/index.md +45 -45
  78. package/docs/hook/insert/afterInsert.md +41 -41
  79. package/docs/hook/insert/preInsert.md +25 -25
  80. package/docs/hook/table/afterTable.md +20 -20
  81. package/docs/hook/table/preTable.md +25 -25
  82. package/docs/hook/update/afterUpdate.md +41 -41
  83. package/docs/hook/update/preUpdate.md +25 -25
  84. package/docs/index.md +42 -42
  85. package/docs/public/fastify-dark.svg +3 -3
  86. package/docs/public/logo-short-dark.svg +11 -11
  87. package/docs/public/logo-short.svg +10 -10
  88. package/docs/public/logo.svg +19 -19
  89. package/docs/readme/index.md +121 -121
  90. package/docs/templates/card.md +83 -83
  91. package/docs/templates/cls.md +29 -29
  92. package/docs/templates/filters.md +91 -91
  93. package/docs/templates/forms.md +139 -139
  94. package/docs/templates/index.md +28 -28
  95. package/docs/templates/select.md +90 -90
  96. package/docs/templates/table.md +162 -162
  97. package/docs/utils/cron/addCron.md +29 -29
  98. package/docs/utils/crud/dataInsert.md +51 -51
  99. package/docs/utils/crud/dataUpdate.md +52 -52
  100. package/docs/utils/crud/getOpt.md +33 -33
  101. package/docs/utils/crud/isFileExists.md +37 -37
  102. package/docs/utils/crud/setOpt.md +37 -37
  103. package/docs/utils/hook/addHook.md +74 -74
  104. package/docs/utils/hook/applyHook.md +64 -64
  105. package/docs/utils/index.md +47 -47
  106. package/docs/utils/notification/addNotification.md +28 -28
  107. package/docs/utils/notification/notification.md +41 -41
  108. package/docs/utils/pg/autoIndex.md +22 -22
  109. package/docs/utils/pg/getMeta.md +58 -58
  110. package/docs/utils/pg/getPG.md +34 -34
  111. package/docs/utils/pg/init.md +29 -29
  112. package/docs/utils/pg/pg.md +70 -70
  113. package/docs/utils/redis/getRedis.md +36 -36
  114. package/docs/utils/redis/rclient.md +74 -74
  115. package/docs/utils/table/getForm.md +68 -68
  116. package/docs/utils/table/getMeta.md +55 -55
  117. package/docs/utils/table/getSelect.md +38 -38
  118. package/docs/utils/table/getSelectMeta.md +46 -46
  119. package/docs/utils/table/getTable.md +77 -77
  120. package/helper.js +30 -30
  121. package/index.js +105 -105
  122. package/migration/exec.migrations.js +79 -79
  123. package/module/core/select/core.user_mentioned.sql +1 -1
  124. package/module/test/cls/itree.composition.json +25 -25
  125. package/module/test/table/test.rest_zone.table.json +265 -265
  126. package/notification/controllers/readNotifications.js +27 -30
  127. package/notification/controllers/testEmail.js +46 -50
  128. package/notification/controllers/userNotifications.js +61 -64
  129. package/notification/funcs/addNotification.js +21 -21
  130. package/notification/funcs/sendNotification.js +112 -112
  131. package/notification/index.js +3 -8
  132. package/notification/schema.js +10 -0
  133. package/package.json +41 -41
  134. package/pg/funcs/getMeta.js +29 -29
  135. package/pg/funcs/getPG.js +30 -30
  136. package/pg/pgClients.js +20 -20
  137. package/policy/funcs/checkPolicy.js +92 -92
  138. package/policy/funcs/sqlInjection.js +33 -33
  139. package/policy/index.js +14 -14
  140. package/redis/client.js +8 -8
  141. package/redis/funcs/getRedis.js +23 -23
  142. package/redis/funcs/redisClients.js +2 -2
  143. package/redis/index.js +19 -19
  144. package/server/migrations/0.sql +78 -78
  145. package/server/migrations/cls.sql +39 -39
  146. package/server/migrations/log.sql +80 -80
  147. package/server/migrations/properties.sql +144 -144
  148. package/server/migrations/roles.sql +172 -172
  149. package/server/migrations/users.sql +168 -168
  150. package/server.js +26 -26
  151. package/table/controllers/data.js +157 -150
  152. package/table/controllers/filter.js +61 -50
  153. package/table/controllers/form.js +42 -42
  154. package/table/controllers/search.js +76 -80
  155. package/table/controllers/suggest.js +79 -79
  156. package/table/controllers/table.js +83 -83
  157. package/table/controllers/utils/addTemplateDir.js +8 -8
  158. package/table/controllers/utils/getSelect.js +19 -19
  159. package/table/controllers/utils/getSelectMeta.js +66 -66
  160. package/table/controllers/utils/getTemplate_old.js +28 -28
  161. package/table/controllers/utils/getTemplates.js +18 -18
  162. package/table/controllers/utils/gisIRColumn.js +72 -67
  163. package/table/controllers/utils/loadTemplate.js +1 -1
  164. package/table/controllers/utils/loadTemplatePath.js +1 -1
  165. package/table/controllers/utils/userTemplateDir.js +1 -1
  166. package/table/funcs/getFilterSQL/index.js +94 -94
  167. package/table/funcs/getFilterSQL/util/formatValue.js +170 -170
  168. package/table/funcs/getFilterSQL/util/getCustomQuery.js +13 -13
  169. package/table/funcs/getFilterSQL/util/getFilterQuery.js +66 -66
  170. package/table/funcs/getFilterSQL/util/getOptimizedQuery.js +12 -12
  171. package/table/funcs/getFilterSQL/util/getTableSql.js +34 -34
  172. package/table/funcs/metaFormat/getSelectVal.js +21 -21
  173. package/table/funcs/metaFormat/index.js +28 -28
  174. package/table/index.js +37 -37
  175. package/table/schema.js +64 -54
  176. package/test/api/applyHook.test.js +95 -95
  177. package/test/api/crud.test.js +89 -89
  178. package/test/api/crud.xss.test.js +80 -80
  179. package/test/api/suggest.test.js +66 -66
  180. package/test/api/table.test.js +134 -134
  181. package/test/api/user.test.js +85 -85
  182. package/test/api/widget.test.js +117 -117
  183. package/test/config.example +18 -18
  184. package/test/funcs/pg.test.js +34 -34
  185. package/test/funcs/redis.test.js +19 -19
  186. package/test/helper/formatDate.test.js +62 -62
  187. package/test/templates/cls/test.json +9 -9
  188. package/test/templates/form/cp_building.form.json +32 -32
  189. package/test/templates/select/account_id.json +3 -3
  190. package/test/templates/select/storage.data.json +2 -2
  191. package/test/templates/select/test.storage.data.json +3 -3
  192. package/test/templates/select/test.suggest.ato_new.json +3 -3
  193. package/test/templates/select/test.suggest.ato_new.sql +25 -25
  194. package/test/templates/select/test.suggest.data.json +4 -4
  195. package/test/templates/select/test.suggest.parent.sql +1 -1
  196. package/test/templates/table/gis.dataset.table.json +20 -20
  197. package/user/controllers/user.cls.id.js +14 -14
  198. package/user/controllers/user.cls.js +71 -75
  199. package/user/controllers/user.cls.post.js +52 -55
  200. package/user/controllers/user.info.js +17 -21
  201. package/user/index.js +7 -36
  202. package/user/schema.js +17 -0
  203. package/util/controllers/logger.file.js +91 -91
  204. package/util/controllers/next.id.js +4 -4
  205. package/util/controllers/properties.add.js +56 -60
  206. package/util/controllers/properties.get.js +16 -19
  207. package/util/controllers/status.monitor.js +8 -8
  208. package/util/controllers/utils/checkUserAccess.js +20 -17
  209. package/util/controllers/utils/getRootDir.js +25 -25
  210. package/util/index.js +19 -23
  211. package/util/schema.js +19 -0
  212. package/utils.js +106 -104
  213. package/widget/controllers/utils/historyFormat.js +76 -76
  214. package/widget/controllers/utils/obj2db.js +13 -13
  215. package/widget/controllers/widget.del.js +41 -44
  216. package/widget/controllers/widget.get.js +96 -102
  217. package/widget/controllers/widget.set.js +74 -79
  218. package/widget/index.js +40 -40
package/pg/funcs/getPG.js CHANGED
@@ -1,30 +1,30 @@
1
- import pg from 'pg';
2
- import config from '../../config.js';
3
- import pgClients from '../pgClients.js';
4
- import init from './init.js';
5
-
6
- function getPG(param) {
7
- const {
8
- user, password, host, port, db, database, name: origin, funcs,
9
- } = param || {};
10
- // if (funcs?.config) Object.assign(config, { ...funcs.config }); // unit test
11
- const name = origin || db || database || param || 'client';
12
- if (pgClients[name]) return pgClients[name];
13
-
14
- const dbConfig = {
15
- user: user || config.pg?.user,
16
- password: password || config.pg?.password,
17
- host: host || config.pg?.host,
18
- port: port || config.pg?.port,
19
- database: db || database || config.pg?.db || config.pg?.database,
20
- };
21
-
22
- pgClients[name] = new pg.Pool(dbConfig);
23
- pgClients[name].init = async () => {
24
- await init(pgClients[name]);
25
- };
26
- init(pgClients[name]);
27
- return pgClients[name];
28
- }
29
-
30
- export default getPG;
1
+ import pg from 'pg';
2
+ import config from '../../config.js';
3
+ import pgClients from '../pgClients.js';
4
+ import init from './init.js';
5
+
6
+ function getPG(param) {
7
+ const {
8
+ user, password, host, port, db, database, name: origin, funcs,
9
+ } = param || {};
10
+ // if (funcs?.config) Object.assign(config, { ...funcs.config }); // unit test
11
+ const name = origin || db || database || param || 'client';
12
+ if (pgClients[name]) return pgClients[name];
13
+
14
+ const dbConfig = {
15
+ user: user || config.pg?.user,
16
+ password: password || config.pg?.password,
17
+ host: host || config.pg?.host,
18
+ port: port || config.pg?.port,
19
+ database: db || database || config.pg?.db || config.pg?.database,
20
+ };
21
+
22
+ pgClients[name] = new pg.Pool(dbConfig);
23
+ pgClients[name].init = async () => {
24
+ await init(pgClients[name]);
25
+ };
26
+ init(pgClients[name]);
27
+ return pgClients[name];
28
+ }
29
+
30
+ export default getPG;
package/pg/pgClients.js CHANGED
@@ -1,20 +1,20 @@
1
- import pg from 'pg';
2
- import config from '../config.js';
3
- import init from './funcs/init.js';
4
-
5
- const pgClients = {};
6
- if (config.pg) {
7
- const client = new pg.Pool({
8
- host: config.pg?.host || '127.0.0.1',
9
- port: config.pg?.port || 5432,
10
- database: config.pg?.database || 'postgres',
11
- user: config.pg?.user || 'postgres',
12
- password: config.pg?.password || 'postgres',
13
- });
14
- client.init = async () => {
15
- await init(client);
16
- };
17
- client.init();
18
- pgClients.client = client;
19
- }
20
- export default pgClients;
1
+ import pg from 'pg';
2
+ import config from '../config.js';
3
+ import init from './funcs/init.js';
4
+
5
+ const pgClients = {};
6
+ if (config.pg) {
7
+ const client = new pg.Pool({
8
+ host: config.pg?.host || '127.0.0.1',
9
+ port: config.pg?.port || 5432,
10
+ database: config.pg?.database || 'postgres',
11
+ user: config.pg?.user || 'postgres',
12
+ password: config.pg?.password || 'postgres',
13
+ });
14
+ client.init = async () => {
15
+ await init(client);
16
+ };
17
+ client.init();
18
+ pgClients.client = client;
19
+ }
20
+ export default pgClients;
@@ -1,92 +1,92 @@
1
- import block from './sqlInjection.js';
2
-
3
- /**
4
- * Middleware func
5
- *
6
- * @type function
7
- * @alias checkPolicy
8
- * @summary Функція дозволяє налаштувати доступ до сайту або API для адмін. та публічної частини веб-ресурсу
9
- * @param {String} path - назва апі
10
- * @returns {object|null} Returns object
11
- */
12
-
13
- export default function checkPolicy(req) {
14
- const {
15
- originalUrl: path, hostname, query, params, headers: hs, log, sid = 35, funcs = {},
16
- } = req;
17
- const user = req.user || req.session?.passport?.user;
18
-
19
- const { config } = funcs;
20
- const isUser = config.debug || !!user;
21
-
22
- const isServer = process.argv[2];
23
- const { policy = [] } = req.routeOptions?.config || {};
24
-
25
- /*= == 0.Check superadmin access === */
26
- if (policy.includes('superadmin') && user?.user_type !== 'superadmin') {
27
- log.warn('api/superadmin', {
28
- path, params, query, body: JSON.stringify(req?.body || {}).substring(30), message: 'access restricted: 0',
29
- });
30
- return { message: 'access restricted: 0', status: 403 };
31
- }
32
-
33
- /*= == 1.File injection === */
34
- if (JSON.stringify(params || {})?.includes('../') || JSON.stringify(query || {})?.includes('../') || path?.includes('../')) {
35
- log.warn('injection/file', {
36
- path, params, query, message: 'access restricted: 1',
37
- });
38
- return { message: 'access restricted: 1', status: 403 };
39
- }
40
-
41
- /* === 1.1 File === */
42
- const allowExtPublic = ['.png', '.jpg', '.svg'];
43
- const ext = path.toLowerCase().substr(-4);
44
- if (path.includes('files/') && allowExtPublic.includes(ext)) return null;
45
-
46
- /* === 2.SQL Injection policy: no-sql === */
47
- if (!policy.includes('no-sql')) {
48
- // skip polyline param - data filter (geometry bounds)
49
- const stopWords = block.filter((el) => path.replace(query.polyline, '').includes(el));
50
- if (stopWords?.length) {
51
- log.warn('injection/sql', { stopWords, message: 'access restricted: 2', path });
52
- return { message: 'access restricted: 2', status: 403 };
53
- }
54
- }
55
- /* policy: skip if not API */
56
- const isApi = ['/files/', '/api/format/', '/api', '/api-user/', '/logger', '/file/'].filter((el) => path.includes(el)).length;
57
- if (!isApi) {
58
- return null;
59
- }
60
-
61
- /* === policy: public === */
62
- if (policy.includes('public')) {
63
- return null;
64
- }
65
-
66
- /* === 3. policy: user === */
67
- if (!user && policy.includes('user') && false) {
68
- log.warn('policy/user', { message: 'access restricted: 3', path });
69
- return { message: 'access restricted: 3', status: 403 };
70
- }
71
-
72
- /* === 4. policy: referer === */
73
- if (!hs?.referer?.includes?.(hostname) && policy.includes('referer') && !config.local && !config.debug) {
74
- log.warn('policy/referer', { message: 'access restricted: 4', uid: user?.uid });
75
- return { message: 'access restricted: 4', status: 403 };
76
- }
77
-
78
- /* === 5. policy: site auth === */
79
- if (!policy.includes('site') && sid === 1 && isUser && !config.local && !config.debug) {
80
- log.warn('policy/site', { message: 'access restricted: 5', path, uid: user?.uid });
81
- return { message: 'access restricted: 5', status: 403 };
82
- }
83
-
84
- /* === 6. base policy: block api, except login === */
85
- if (sid === 35 && !isUser && isServer && !config.local && !config.debug
86
- && !path.startsWith(`${config.prefix || '/api'}/login`)) {
87
- log.warn('policy/api', { message: 'access restricted: 6', path, uid: user?.uid });
88
- return { message: 'access restricted: 6', status: 403 };
89
- }
90
-
91
- return null;
92
- }
1
+ import block from './sqlInjection.js';
2
+
3
+ /**
4
+ * Middleware func
5
+ *
6
+ * @type function
7
+ * @alias checkPolicy
8
+ * @summary Функція дозволяє налаштувати доступ до сайту або API для адмін. та публічної частини веб-ресурсу
9
+ * @param {String} path - назва апі
10
+ * @returns {object|null} Returns object
11
+ */
12
+
13
+ export default function checkPolicy(req) {
14
+ const {
15
+ originalUrl: path, hostname, query, params, headers: hs, log, sid = 35, funcs = {},
16
+ } = req;
17
+ const user = req.user || req.session?.passport?.user;
18
+
19
+ const { config } = funcs;
20
+ const isUser = config.debug || !!user;
21
+
22
+ const isServer = process.argv[2];
23
+ const { policy = [] } = req.routeOptions?.config || {};
24
+
25
+ /*= == 0.Check superadmin access === */
26
+ if (policy.includes('superadmin') && user?.user_type !== 'superadmin') {
27
+ log.warn('api/superadmin', {
28
+ path, params, query, body: JSON.stringify(req?.body || {}).substring(30), message: 'access restricted: 0',
29
+ });
30
+ return { message: 'access restricted: 0', status: 403 };
31
+ }
32
+
33
+ /*= == 1.File injection === */
34
+ if (JSON.stringify(params || {})?.includes('../') || JSON.stringify(query || {})?.includes('../') || path?.includes('../')) {
35
+ log.warn('injection/file', {
36
+ path, params, query, message: 'access restricted: 1',
37
+ });
38
+ return { message: 'access restricted: 1', status: 403 };
39
+ }
40
+
41
+ /* === 1.1 File === */
42
+ const allowExtPublic = ['.png', '.jpg', '.svg'];
43
+ const ext = path.toLowerCase().substr(-4);
44
+ if (path.includes('files/') && allowExtPublic.includes(ext)) return null;
45
+
46
+ /* === 2.SQL Injection policy: no-sql === */
47
+ if (!policy.includes('no-sql')) {
48
+ // skip polyline param - data filter (geometry bounds)
49
+ const stopWords = block.filter((el) => path.replace(query.polyline, '').includes(el));
50
+ if (stopWords?.length) {
51
+ log.warn('injection/sql', { stopWords, message: 'access restricted: 2', path });
52
+ return { message: 'access restricted: 2', status: 403 };
53
+ }
54
+ }
55
+ /* policy: skip if not API */
56
+ const isApi = ['/files/', '/api/format/', '/api', '/api-user/', '/logger', '/file/'].filter((el) => path.includes(el)).length;
57
+ if (!isApi) {
58
+ return null;
59
+ }
60
+
61
+ /* === policy: public === */
62
+ if (policy.includes('public')) {
63
+ return null;
64
+ }
65
+
66
+ /* === 3. policy: user === */
67
+ if (!user && policy.includes('user') && false) {
68
+ log.warn('policy/user', { message: 'access restricted: 3', path });
69
+ return { message: 'access restricted: 3', status: 403 };
70
+ }
71
+
72
+ /* === 4. policy: referer === */
73
+ if (!hs?.referer?.includes?.(hostname) && policy.includes('referer') && !config.local && !config.debug) {
74
+ log.warn('policy/referer', { message: 'access restricted: 4', uid: user?.uid });
75
+ return { message: 'access restricted: 4', status: 403 };
76
+ }
77
+
78
+ /* === 5. policy: site auth === */
79
+ if (!policy.includes('site') && sid === 1 && isUser && !config.local && !config.debug) {
80
+ log.warn('policy/site', { message: 'access restricted: 5', path, uid: user?.uid });
81
+ return { message: 'access restricted: 5', status: 403 };
82
+ }
83
+
84
+ /* === 6. base policy: block api, except login === */
85
+ if (sid === 35 && !isUser && isServer && !config.local && !config.debug
86
+ && !path.startsWith(`${config.prefix || '/api'}/login`)) {
87
+ log.warn('policy/api', { message: 'access restricted: 6', path, uid: user?.uid });
88
+ return { message: 'access restricted: 6', status: 403 };
89
+ }
90
+
91
+ return null;
92
+ }
@@ -1,33 +1,33 @@
1
- const sqlInjection = [
2
- '()',
3
- '^',
4
- '*',
5
- 'like ',
6
- '@variable',
7
- '@@variable',
8
- 'group by ',
9
- 'union ',
10
- 'select ',
11
- 'having ',
12
- 'as injectx',
13
- 'where ',
14
- 'rlike ',
15
- 'if(',
16
- 'sleep(',
17
- 'waitfor delay',
18
- 'benchmark(',
19
- 'pg_sleep(',
20
- "'\\\"",
21
- 'randomblob(',
22
- 'order by ',
23
- 'union all ',
24
- '+or',
25
- 'or ',
26
- 'and ',
27
- "'' ",
28
- '""" ',
29
- '<script',
30
- 'javascript:',
31
- ]
32
-
33
- export default sqlInjection;
1
+ const sqlInjection = [
2
+ '()',
3
+ '^',
4
+ '*',
5
+ 'like ',
6
+ '@variable',
7
+ '@@variable',
8
+ 'group by ',
9
+ 'union ',
10
+ 'select ',
11
+ 'having ',
12
+ 'as injectx',
13
+ 'where ',
14
+ 'rlike ',
15
+ 'if(',
16
+ 'sleep(',
17
+ 'waitfor delay',
18
+ 'benchmark(',
19
+ 'pg_sleep(',
20
+ "'\\\"",
21
+ 'randomblob(',
22
+ 'order by ',
23
+ 'union all ',
24
+ '+or',
25
+ 'or ',
26
+ 'and ',
27
+ "'' ",
28
+ '""" ',
29
+ '<script',
30
+ 'javascript:',
31
+ ]
32
+
33
+ export default sqlInjection;
package/policy/index.js CHANGED
@@ -1,14 +1,14 @@
1
- // import fp from 'fastify-plugin';
2
-
3
- import checkPolicy from './funcs/checkPolicy.js';
4
-
5
- async function plugin(fastify) {
6
- fastify.addHook('preParsing', async (request, reply) => {
7
- const hookData = checkPolicy(request);
8
- if (hookData?.status && hookData?.message) {
9
- return reply.status(hookData?.status).send(hookData.message);
10
- }
11
- });
12
- }
13
-
14
- export default plugin;
1
+ // import fp from 'fastify-plugin';
2
+
3
+ import checkPolicy from './funcs/checkPolicy.js';
4
+
5
+ async function plugin(fastify) {
6
+ fastify.addHook('preParsing', async (request, reply) => {
7
+ const hookData = checkPolicy(request);
8
+ if (hookData?.status && hookData?.message) {
9
+ return reply.status(hookData?.status).send(hookData.message);
10
+ }
11
+ });
12
+ }
13
+
14
+ export default plugin;
package/redis/client.js CHANGED
@@ -1,8 +1,8 @@
1
- import redisClients from './funcs/redisClients.js';
2
- import getRedis from './funcs/getRedis.js';
3
-
4
- if (!redisClients[0]) {
5
- getRedis({ db: 0 });
6
- }
7
-
8
- export default redisClients[0];
1
+ import redisClients from './funcs/redisClients.js';
2
+ import getRedis from './funcs/getRedis.js';
3
+
4
+ if (!redisClients[0]) {
5
+ getRedis({ db: 0 });
6
+ }
7
+
8
+ export default redisClients[0];
@@ -1,23 +1,23 @@
1
- import Redis from 'ioredis';
2
- import config from '../../config.js';
3
- import redisClients from './redisClients.js';
4
-
5
- function getRedis({ db } = { db: 0 }) {
6
- if (!config.redis) return null;
7
- if (redisClients[db]) return redisClients[db];
8
-
9
- const redisConfig = {
10
- db,
11
- keyPrefix: `${config.db}:`,
12
- host: config.redis?.host || '127.0.0.1',
13
- port: config.redis?.port || 6379, // Redis port
14
- family: 4, // 4 (IPv4) or 6 (IPv6)
15
- closeClient: true,
16
- };
17
-
18
- redisClients[db] = new Redis(redisConfig);
19
-
20
- return redisClients[db];
21
- }
22
-
23
- export default getRedis;
1
+ import Redis from 'ioredis';
2
+ import config from '../../config.js';
3
+ import redisClients from './redisClients.js';
4
+
5
+ function getRedis({ db } = { db: 0 }) {
6
+ if (!config.redis) return null;
7
+ if (redisClients[db]) return redisClients[db];
8
+
9
+ const redisConfig = {
10
+ db,
11
+ keyPrefix: `${config.db}:`,
12
+ host: config.redis?.host || '127.0.0.1',
13
+ port: config.redis?.port || 6379, // Redis port
14
+ family: 4, // 4 (IPv4) or 6 (IPv6)
15
+ closeClient: true,
16
+ };
17
+
18
+ redisClients[db] = new Redis(redisConfig);
19
+
20
+ return redisClients[db];
21
+ }
22
+
23
+ export default getRedis;
@@ -1,2 +1,2 @@
1
- const redisClients = {};
2
- export default redisClients;
1
+ const redisClients = {};
2
+ export default redisClients;
package/redis/index.js CHANGED
@@ -1,19 +1,19 @@
1
- // import client from './client.js';
2
- import getRedis from './funcs/getRedis.js';
3
- // import client from './funcs/redisClients.js';
4
-
5
- function close(fastify) {
6
- fastify.rclient.quit();
7
- // fastify.rclient2.quit();
8
- }
9
-
10
- async function plugin(fastify) {
11
- const client = getRedis({ db: 0, funcs: fastify });
12
- client.getJSON = client.get;
13
- fastify.decorate('rclient', client);
14
- fastify.decorate('getRedis', getRedis);
15
- // fastify.decorate('rclient2', client2);
16
- fastify.addHook('onClose', close);
17
- }
18
-
19
- export default plugin;
1
+ // import client from './client.js';
2
+ import getRedis from './funcs/getRedis.js';
3
+ // import client from './funcs/redisClients.js';
4
+
5
+ function close(fastify) {
6
+ fastify.rclient.quit();
7
+ // fastify.rclient2.quit();
8
+ }
9
+
10
+ async function plugin(fastify) {
11
+ const client = getRedis({ db: 0, funcs: fastify });
12
+ client.getJSON = client.get;
13
+ fastify.decorate('rclient', client);
14
+ fastify.decorate('getRedis', getRedis);
15
+ // fastify.decorate('rclient2', client2);
16
+ fastify.addHook('onClose', close);
17
+ }
18
+
19
+ export default plugin;
@@ -1,78 +1,78 @@
1
- -- fix error if function exists and return type not text i.e bigint
2
-
3
- do $$
4
-
5
- declare
6
- m record;
7
- _pk text;
8
- _tables json;
9
- _returnType text;
10
-
11
- begin
12
-
13
- select format_type(p.prorettype, null) as return_type
14
- from pg_proc p
15
- where p.proname = 'next_id'
16
- and p.pronamespace = 'public'::regnamespace into _returnType;
17
-
18
- if (_returnType != 'text') then
19
- raise notice 'default reassign start: % -> text', _returnType;
20
-
21
- CREATE EXTENSION if not exists "uuid-ossp";
22
-
23
- SELECT json_object_agg(a.attrelid::regclass, a.attname)
24
- FROM pg_catalog.pg_attribute a
25
- LEFT JOIN pg_catalog.pg_attrdef d ON (a.attrelid, a.attnum) = (d.adrelid, d.adnum)
26
- WHERE NOT a.attisdropped -- no dropped (dead) columns
27
- AND a.attnum > 0 -- no system columns
28
- AND pg_get_expr(d.adbin, d.adrelid) = 'next_id()' into _tables;
29
-
30
- FOR m in (select json_object_keys(_tables) as table) loop
31
- _pk = _tables->>m.table;
32
- raise notice 'drop default: %,%', m.table, _pk;
33
- EXECUTE('alter table '|| m.table || ' alter column ' || _pk || ' set default null;');
34
- end loop;
35
-
36
- DROP FUNCTION IF EXISTS next_id();
37
-
38
- CREATE EXTENSION if not exists "uuid-ossp";
39
-
40
- CREATE OR REPLACE FUNCTION next_id()
41
- RETURNS text AS
42
- $BODY$
43
- DECLARE
44
-
45
- BEGIN
46
- return replace(uuid_generate_v4()::text, '-', '');
47
- END;
48
- $BODY$
49
- LANGUAGE plpgsql VOLATILE
50
- COST 100;
51
-
52
- FOR m in (select json_object_keys(_tables) as table) loop
53
- _pk = _tables->>m.table;
54
- raise notice 'reassign default: %, %', m.table, _pk;
55
- EXECUTE('alter table '|| m.table || ' alter column ' || _pk || ' set default next_id();');
56
- end loop;
57
-
58
- raise notice 'reassign default finish: %', _tables;
59
-
60
- else
61
- raise notice 'skip default reassign';
62
-
63
- CREATE EXTENSION if not exists "uuid-ossp";
64
-
65
- CREATE OR REPLACE FUNCTION next_id()
66
- RETURNS text AS
67
- $BODY$
68
- DECLARE
69
-
70
- BEGIN
71
- return replace(uuid_generate_v4()::text, '-', '');
72
- END;
73
- $BODY$
74
- LANGUAGE plpgsql VOLATILE
75
- COST 100;
76
- end if;
77
-
78
- end $$
1
+ -- fix error if function exists and return type not text i.e bigint
2
+
3
+ do $$
4
+
5
+ declare
6
+ m record;
7
+ _pk text;
8
+ _tables json;
9
+ _returnType text;
10
+
11
+ begin
12
+
13
+ select format_type(p.prorettype, null) as return_type
14
+ from pg_proc p
15
+ where p.proname = 'next_id'
16
+ and p.pronamespace = 'public'::regnamespace into _returnType;
17
+
18
+ if (_returnType != 'text') then
19
+ raise notice 'default reassign start: % -> text', _returnType;
20
+
21
+ CREATE EXTENSION if not exists "uuid-ossp";
22
+
23
+ SELECT json_object_agg(a.attrelid::regclass, a.attname)
24
+ FROM pg_catalog.pg_attribute a
25
+ LEFT JOIN pg_catalog.pg_attrdef d ON (a.attrelid, a.attnum) = (d.adrelid, d.adnum)
26
+ WHERE NOT a.attisdropped -- no dropped (dead) columns
27
+ AND a.attnum > 0 -- no system columns
28
+ AND pg_get_expr(d.adbin, d.adrelid) = 'next_id()' into _tables;
29
+
30
+ FOR m in (select json_object_keys(_tables) as table) loop
31
+ _pk = _tables->>m.table;
32
+ raise notice 'drop default: %,%', m.table, _pk;
33
+ EXECUTE('alter table '|| m.table || ' alter column ' || _pk || ' set default null;');
34
+ end loop;
35
+
36
+ DROP FUNCTION IF EXISTS next_id();
37
+
38
+ CREATE EXTENSION if not exists "uuid-ossp";
39
+
40
+ CREATE OR REPLACE FUNCTION next_id()
41
+ RETURNS text AS
42
+ $BODY$
43
+ DECLARE
44
+
45
+ BEGIN
46
+ return replace(uuid_generate_v4()::text, '-', '');
47
+ END;
48
+ $BODY$
49
+ LANGUAGE plpgsql VOLATILE
50
+ COST 100;
51
+
52
+ FOR m in (select json_object_keys(_tables) as table) loop
53
+ _pk = _tables->>m.table;
54
+ raise notice 'reassign default: %, %', m.table, _pk;
55
+ EXECUTE('alter table '|| m.table || ' alter column ' || _pk || ' set default next_id();');
56
+ end loop;
57
+
58
+ raise notice 'reassign default finish: %', _tables;
59
+
60
+ else
61
+ raise notice 'skip default reassign';
62
+
63
+ CREATE EXTENSION if not exists "uuid-ossp";
64
+
65
+ CREATE OR REPLACE FUNCTION next_id()
66
+ RETURNS text AS
67
+ $BODY$
68
+ DECLARE
69
+
70
+ BEGIN
71
+ return replace(uuid_generate_v4()::text, '-', '');
72
+ END;
73
+ $BODY$
74
+ LANGUAGE plpgsql VOLATILE
75
+ COST 100;
76
+ end if;
77
+
78
+ end $$