@opengis/fastify-table 1.0.74 → 1.0.75

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 (96) hide show
  1. package/.eslintrc.cjs +42 -42
  2. package/Changelog.md +233 -229
  3. package/README.md +26 -26
  4. package/config.js +10 -10
  5. package/cron/controllers/cronApi.js +22 -22
  6. package/cron/controllers/utils/cronList.js +1 -1
  7. package/cron/funcs/addCron.js +131 -131
  8. package/cron/index.js +10 -10
  9. package/crud/controllers/deleteCrud.js +19 -19
  10. package/crud/controllers/insert.js +54 -54
  11. package/crud/controllers/update.js +59 -59
  12. package/crud/controllers/utils/checkXSS.js +45 -45
  13. package/crud/controllers/utils/xssInjection.js +72 -72
  14. package/crud/funcs/dataDelete.js +15 -15
  15. package/crud/funcs/dataInsert.js +24 -24
  16. package/crud/funcs/dataUpdate.js +24 -24
  17. package/crud/funcs/getAccess.js +53 -52
  18. package/crud/funcs/getOpt.js +10 -10
  19. package/crud/funcs/getToken.js +27 -27
  20. package/crud/funcs/isFileExists.js +13 -13
  21. package/crud/funcs/setOpt.js +16 -16
  22. package/crud/funcs/setToken.js +53 -53
  23. package/crud/index.js +36 -36
  24. package/helper.js +28 -28
  25. package/index.js +97 -97
  26. package/migration/exec.migrations.js +75 -75
  27. package/notification/controllers/testEmail.js +49 -49
  28. package/notification/controllers/userNotifications.js +19 -19
  29. package/notification/funcs/addNotification.js +8 -8
  30. package/notification/funcs/sendNotification.js +111 -111
  31. package/notification/funcs/utils/sendEmail.js +39 -39
  32. package/notification/index.js +38 -38
  33. package/package.json +26 -26
  34. package/pg/funcs/getPG.js +30 -30
  35. package/pg/pgClients.js +20 -20
  36. package/policy/funcs/checkPolicy.js +82 -82
  37. package/policy/funcs/sqlInjection.js +33 -33
  38. package/policy/index.js +14 -14
  39. package/redis/client.js +8 -8
  40. package/redis/funcs/getRedis.js +23 -23
  41. package/redis/funcs/redisClients.js +2 -2
  42. package/redis/index.js +19 -19
  43. package/server/migrations/0.sql +64 -13
  44. package/server/migrations/crm.sql +150 -150
  45. package/server/migrations/log.sql +43 -43
  46. package/server/templates/form/test.dataset.form.json +411 -411
  47. package/server/templates/select/test.storage.data.json +2 -2
  48. package/server/templates/table/test.dataset.table.json +24 -24
  49. package/server/templates/table/test.gis.map.table.json +44 -44
  50. package/server.js +14 -14
  51. package/table/controllers/card.js +44 -44
  52. package/table/controllers/data.js +95 -95
  53. package/table/controllers/filter.js +37 -37
  54. package/table/controllers/form.js +28 -28
  55. package/table/controllers/search.js +72 -72
  56. package/table/controllers/suggest.js +62 -62
  57. package/table/controllers/table.js +44 -44
  58. package/table/controllers/utils/getSelect.js +20 -20
  59. package/table/controllers/utils/getSelectMeta.js +66 -66
  60. package/table/controllers/utils/getTemplate.js +28 -28
  61. package/table/controllers/utils/getTemplates.js +18 -18
  62. package/table/controllers/utils/gisIRColumn.js +68 -68
  63. package/table/funcs/getFilterSQL/index.js +75 -75
  64. package/table/funcs/getFilterSQL/util/formatValue.js +142 -142
  65. package/table/funcs/getFilterSQL/util/getCustomQuery.js +13 -13
  66. package/table/funcs/getFilterSQL/util/getFilterQuery.js +73 -73
  67. package/table/funcs/getFilterSQL/util/getOptimizedQuery.js +12 -12
  68. package/table/funcs/getFilterSQL/util/getTableSql.js +34 -34
  69. package/table/funcs/metaFormat/getSelectVal.js +20 -20
  70. package/table/funcs/metaFormat/index.js +27 -27
  71. package/table/index.js +78 -78
  72. package/test/api/crud.test.js +88 -81
  73. package/test/api/crud.xss.test.js +72 -72
  74. package/test/api/notification.test.js +37 -37
  75. package/test/api/table.test.js +57 -57
  76. package/test/api/widget.test.js +114 -114
  77. package/test/config.example +18 -18
  78. package/test/funcs/crud.test.js +76 -76
  79. package/test/funcs/notification.test.js +31 -31
  80. package/test/funcs/pg.test.js +34 -34
  81. package/test/funcs/redis.test.js +19 -19
  82. package/test/templates/cls/test.json +9 -9
  83. package/test/templates/form/cp_building.form.json +32 -32
  84. package/test/templates/select/account_id.json +3 -3
  85. package/test/templates/select/storage.data.json +2 -2
  86. package/test/templates/table/gis.dataset.table.json +20 -20
  87. package/util/controllers/next.id.js +4 -4
  88. package/util/controllers/properties.add.js +50 -50
  89. package/util/controllers/properties.get.js +19 -19
  90. package/util/index.js +20 -20
  91. package/widget/controllers/utils/historyFormat.js +76 -76
  92. package/widget/controllers/utils/obj2db.js +13 -13
  93. package/widget/controllers/widget.del.js +44 -44
  94. package/widget/controllers/widget.get.js +96 -96
  95. package/widget/controllers/widget.set.js +70 -70
  96. package/widget/index.js +40 -40
@@ -1,81 +1,88 @@
1
- import { test } from 'node:test';
2
- import assert from 'node:assert';
3
-
4
- import build from '../../helper.js';
5
-
6
- import config from '../config.js';
7
-
8
- test('api crud', async (t) => {
9
- const app = await build(t);
10
- const prefix = config.prefix || '/api';
11
-
12
- app.addHook('onRequest', async (req) => {
13
- req.session = { passport: { user: { uid: '1' } } };
14
- req.user = req.session.passport.user;
15
- req.uid = req.user.uid;
16
- });
17
-
18
- await t.test('POST /insert', async () => {
19
- const res = await app.inject({
20
- method: 'POST',
21
- url: `${prefix}/table/test.gis.map.table`,
22
- body: {
23
- alias: 'testMap',
24
- map_id: '5400000',
25
- ord: 1,
26
- enabled: false,
27
- tags: ['unit', 'test'],
28
- },
29
- });
30
- // console.log(res);
31
- // assert.ok(res.json().rows ? res.json().rows[0]?.map_id : res.json().map_id, res.json().status);
32
- assert.ok(111);
33
- });
34
-
35
- await t.test('POST /properties/:id', async () => {
36
- const res = await app.inject({
37
- method: 'POST',
38
- url: `${prefix}/properties/5400000`,
39
- body: {
40
- custom_alias: 'testMap',
41
- custom_ord: 5,
42
- },
43
- });
44
- assert.ok(res.json().message.rows.length, res.json().status);
45
- });
46
-
47
- await t.test('GET /properties/:id', async () => {
48
- const res = await app.inject({
49
- method: 'GET',
50
- url: `${prefix}/properties/5400000`,
51
- });
52
- assert.ok(res.json().message.custom_alias, res.json().status);
53
- });
54
-
55
- await t.test('PUT /update', async () => {
56
- const res = await app.inject({
57
- method: 'PUT',
58
- url: `${prefix}/table/test.gis.map.table/5400000`,
59
- body: {
60
- editor_id: '11',
61
- alias: 'testMapEdit',
62
- map_id: '5400000',
63
- ord: 2,
64
- enabled: true,
65
- tags: ['unittest'],
66
- },
67
- });
68
- // console.log(res);
69
- // assert.ok((res.json().rows ? res.json().rows[0]?.editor_id : res.json().editor_id) === '11', res.json().status);
70
- assert.ok(11);
71
- });
72
-
73
- await t.test('DELETE /delete', async () => {
74
- const res = await app.inject({
75
- method: 'DELETE',
76
- url: `${prefix}/table/test.gis.map.table/5400000`,
77
- });
78
-
79
- assert.ok(res.json(), res.json().status);
80
- });
81
- });
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert';
3
+
4
+ import build from '../../helper.js';
5
+
6
+ import config from '../config.js';
7
+ import pgClients from '../../pg/pgClients.js';
8
+
9
+ const mapId = '5400000';
10
+
11
+ test('api crud', async (t) => {
12
+ const app = await build(t);
13
+ const prefix = config.prefix || '/api';
14
+
15
+ // delete old test data before test
16
+ const { rowCount } = await pgClients.client.query('delete from gis.map where map_id=$1', [mapId]);
17
+ console.log(rowCount);
18
+
19
+ app.addHook('onRequest', async (req) => {
20
+ req.session = { passport: { user: { uid: '1' } } };
21
+ req.user = req.session.passport.user;
22
+ req.uid = req.user.uid;
23
+ });
24
+
25
+ await t.test('POST /insert', async () => {
26
+ const res = await app.inject({
27
+ method: 'POST',
28
+ url: `${prefix}/table/test.gis.map.table`,
29
+ body: {
30
+ alias: 'testMap',
31
+ map_id: mapId,
32
+ ord: 1,
33
+ enabled: false,
34
+ tags: ['unit', 'test'],
35
+ },
36
+ });
37
+ // console.log(res);
38
+ assert.ok(res.json().rows ? res.json().rows[0]?.map_id : res.json().map_id, res.json().status);
39
+ assert.ok(111);
40
+ });
41
+
42
+ await t.test('POST /properties/:id', async () => {
43
+ const res = await app.inject({
44
+ method: 'POST',
45
+ url: `${prefix}/properties/${mapId}`,
46
+ body: {
47
+ custom_alias: 'testMap',
48
+ custom_ord: 5,
49
+ },
50
+ });
51
+ assert.ok(res.json().message?.rows?.length, res.json().status);
52
+ });
53
+
54
+ await t.test('GET /properties/:id', async () => {
55
+ const res = await app.inject({
56
+ method: 'GET',
57
+ url: `${prefix}/properties/${mapId}`,
58
+ });
59
+ assert.ok(res.json().message?.custom_alias, res.json().status);
60
+ });
61
+
62
+ await t.test('PUT /update', async () => {
63
+ const res = await app.inject({
64
+ method: 'PUT',
65
+ url: `${prefix}/table/test.gis.map.table/${mapId}`,
66
+ body: {
67
+ editor_id: '11',
68
+ alias: 'testMapEdit',
69
+ map_id: mapId,
70
+ ord: 2,
71
+ enabled: true,
72
+ tags: ['unittest'],
73
+ },
74
+ });
75
+ // console.log(res);
76
+ assert.ok((res.json().rows ? res.json().rows[0]?.editor_id : res.json().editor_id) === '11', res.json().status);
77
+ assert.ok(11);
78
+ });
79
+
80
+ await t.test('DELETE /delete', async () => {
81
+ const res = await app.inject({
82
+ method: 'DELETE',
83
+ url: `${prefix}/table/test.gis.map.table/${mapId}`,
84
+ });
85
+
86
+ assert.ok(res.json().msg?.map_id === mapId, res.json().status);
87
+ });
88
+ });
@@ -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
+ });
@@ -1,37 +1,37 @@
1
- import { test } from 'node:test';
2
- import assert from 'node:assert';
3
-
4
- import build from '../../helper.js';
5
- import config from '../config.js';
6
-
7
- const session = { passport: { user: { uid: config.testUser?.uid || '1' } } };
8
-
9
- import userNotifications from '../../notification/controllers/userNotifications.js';
10
-
11
- import pgClients from '../../pg/pgClients.js';
12
-
13
- test('api && funcs notification', async (t) => {
14
- const app = await build(t);
15
- const pg = pgClients.client;
16
- /*
17
- // require dependency
18
- await t.test('GET /auth', async () => {
19
- const res = await app.inject({
20
- method: 'GET',
21
- url: `/api/login?username=${config.testUser?.username}&password=${config.testUser?.password}`,
22
- });
23
- assert.ok(res.statusCode);
24
- });
25
- await t.test('GET /notification', async () => {
26
- const res = await app.inject({
27
- method: 'GET',
28
- url: '/api/notification',
29
- });
30
- const rep = JSON.parse(res?.body);
31
- assert.ok(rep.time);
32
- }); */
33
- /* await t.test('GET /notification', async () => {
34
- const rep = await userNotifications({ pg, session });
35
- assert.ok(rep.time);
36
- }); */
37
- });
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert';
3
+
4
+ import build from '../../helper.js';
5
+ import config from '../config.js';
6
+
7
+ const session = { passport: { user: { uid: config.testUser?.uid || '1' } } };
8
+
9
+ import userNotifications from '../../notification/controllers/userNotifications.js';
10
+
11
+ import pgClients from '../../pg/pgClients.js';
12
+
13
+ test('api && funcs notification', async (t) => {
14
+ const app = await build(t);
15
+ const pg = pgClients.client;
16
+ /*
17
+ // require dependency
18
+ await t.test('GET /auth', async () => {
19
+ const res = await app.inject({
20
+ method: 'GET',
21
+ url: `/api/login?username=${config.testUser?.username}&password=${config.testUser?.password}`,
22
+ });
23
+ assert.ok(res.statusCode);
24
+ });
25
+ await t.test('GET /notification', async () => {
26
+ const res = await app.inject({
27
+ method: 'GET',
28
+ url: '/api/notification',
29
+ });
30
+ const rep = JSON.parse(res?.body);
31
+ assert.ok(rep.time);
32
+ }); */
33
+ /* await t.test('GET /notification', async () => {
34
+ const rep = await userNotifications({ pg, session });
35
+ assert.ok(rep.time);
36
+ }); */
37
+ });
@@ -1,57 +1,57 @@
1
- import { test } from 'node:test';
2
- import assert from 'node:assert';
3
-
4
- import build from '../../helper.js';
5
-
6
- test('api table', async (t) => {
7
- const app = await build(t);
8
- // assert.ok(1);
9
- /* await t.test('GET /suggest', async () => {
10
- const res = await app.inject({
11
- method: 'GET',
12
- url: '/api/suggest/test.storage.data',
13
- });
14
- // console.log(res?.body);
15
- const rep = JSON.parse(res?.body);
16
- // console.log(rep.total);
17
- assert.ok(rep.total);
18
- }); */
19
- /* await t.test('GET /data', async () => {
20
- const res = await app.inject({
21
- method: 'GET',
22
- url: '/api/data/test.dataset.table',
23
- });
24
- // console.log(res);
25
- const rep = JSON.parse(res?.body);
26
- // console.log(rep.total);
27
- assert.ok(rep.total);
28
- }); */
29
- /* await t.test('GET /search', async () => {
30
- const res = await app.inject({
31
- method: 'GET',
32
- url: '/api/search?table=test.dataset.table&key=0',
33
- });
34
- const rep = JSON.parse(res?.body);
35
- assert.ok(rep.total);
36
- }); */
37
- await t.test('GET /form', async () => {
38
- const res = await app.inject({
39
- method: 'GET',
40
- url: '/api/form/test.dataset.form',
41
- });
42
- // console.log(res);
43
- const rep = JSON.parse(res?.body);
44
- // console.log(rep.total);
45
- assert.ok(rep);
46
- });
47
- await t.test('GET /filter', async () => {
48
- const res = await app.inject({
49
- method: 'GET',
50
- url: '/api/filter/test.dataset.table',
51
- });
52
- // console.log(res);
53
- const rep = JSON.parse(res?.body);
54
- // console.log(rep.total);
55
- assert.ok(rep);
56
- });
57
- });
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert';
3
+
4
+ import build from '../../helper.js';
5
+
6
+ test('api table', async (t) => {
7
+ const app = await build(t);
8
+ // assert.ok(1);
9
+ /* await t.test('GET /suggest', async () => {
10
+ const res = await app.inject({
11
+ method: 'GET',
12
+ url: '/api/suggest/test.storage.data',
13
+ });
14
+ // console.log(res?.body);
15
+ const rep = JSON.parse(res?.body);
16
+ // console.log(rep.total);
17
+ assert.ok(rep.total);
18
+ }); */
19
+ /* await t.test('GET /data', async () => {
20
+ const res = await app.inject({
21
+ method: 'GET',
22
+ url: '/api/data/test.dataset.table',
23
+ });
24
+ // console.log(res);
25
+ const rep = JSON.parse(res?.body);
26
+ // console.log(rep.total);
27
+ assert.ok(rep.total);
28
+ }); */
29
+ /* await t.test('GET /search', async () => {
30
+ const res = await app.inject({
31
+ method: 'GET',
32
+ url: '/api/search?table=test.dataset.table&key=0',
33
+ });
34
+ const rep = JSON.parse(res?.body);
35
+ assert.ok(rep.total);
36
+ }); */
37
+ await t.test('GET /form', async () => {
38
+ const res = await app.inject({
39
+ method: 'GET',
40
+ url: '/api/form/test.dataset.form',
41
+ });
42
+ // console.log(res);
43
+ const rep = JSON.parse(res?.body);
44
+ // console.log(rep.total);
45
+ assert.ok(rep);
46
+ });
47
+ await t.test('GET /filter', async () => {
48
+ const res = await app.inject({
49
+ method: 'GET',
50
+ url: '/api/filter/test.dataset.table',
51
+ });
52
+ // console.log(res);
53
+ const rep = JSON.parse(res?.body);
54
+ // console.log(rep.total);
55
+ assert.ok(rep);
56
+ });
57
+ });