@opengis/fastify-table 1.0.96 → 1.1.0
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 +4 -0
- 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/dataUpdate.js +30 -30
- package/crud/funcs/getToken.js +27 -27
- package/crud/funcs/isFileExists.js +13 -13
- package/crud/funcs/setToken.js +53 -53
- package/crud/funcs/utils/logChanges.js +7 -4
- package/migration/exec.migrations.js +79 -76
- package/notification/controllers/testEmail.js +49 -49
- package/notification/funcs/utils/sendEmail.js +39 -39
- package/notification/index.js +38 -38
- package/package.json +1 -1
- package/pg/funcs/getPG.js +30 -30
- package/redis/funcs/getRedis.js +23 -23
- package/server/migrations/crm.sql +150 -150
- package/server/migrations/log.sql +80 -80
- package/server/migrations/properties.sql +31 -0
- package/server/migrations/roles.sql +164 -0
- package/server/migrations/users.sql +89 -0
- 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/filter.js +37 -37
- package/table/controllers/form.js +28 -28
- package/table/controllers/search.js +80 -72
- package/table/controllers/utils/getSelect.js +20 -20
- package/table/controllers/utils/getTemplate.js +69 -28
- package/table/controllers/utils/getTemplatePath.js +40 -0
- package/table/controllers/utils/getTemplate_old.js +28 -0
- package/table/controllers/utils/getTemplates.js +18 -18
- package/table/controllers/utils/loadTemplate.js +1 -0
- package/table/controllers/utils/loadTemplatePath.js +1 -0
- package/table/funcs/getFilterSQL/util/getCustomQuery.js +1 -1
- package/table/index.js +84 -80
- 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/config.example +18 -18
- 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/logger.file.js +90 -90
- package/util/controllers/next.id.js +4 -4
- package/util/controllers/properties.get.js +19 -19
- package/util/controllers/utils/checkUserAccess.js +19 -19
- package/util/controllers/utils/getRootDir.js +20 -20
- package/util/index.js +23 -23
- package/utils.js +8 -0
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { existsSync } from 'fs';
|
|
3
|
-
import { fileURLToPath } from 'url';
|
|
4
|
-
|
|
5
|
-
const fileName = fileURLToPath(import.meta.url);
|
|
6
|
-
const dirName = path.dirname(fileName);
|
|
7
|
-
|
|
8
|
-
import notification from '../funcs/sendNotification.js';
|
|
9
|
-
|
|
10
|
-
export default async function testNotification({
|
|
11
|
-
pg, funcs = {}, log, query = {}, session = {},
|
|
12
|
-
}) {
|
|
13
|
-
const { local } = funcs.config || {};
|
|
14
|
-
if (!session?.passport?.user?.user_type?.includes('admin') && !local) {
|
|
15
|
-
return { message: 'Forbidden', status: 403 };
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const date = new Date().toISOString().split('T')[0];
|
|
19
|
-
if (!query.to) {
|
|
20
|
-
return { message: 'param to is required', status: 400 };
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
try {
|
|
24
|
-
const {
|
|
25
|
-
to, template, table, id, nocache,
|
|
26
|
-
} = query;
|
|
27
|
-
const file = [path.join(dirName, '../../', 'changelog.md'), path.join(dirName, 'utils', 'pin-m-ty-media-record-outline+303070.png')].filter((el) => existsSync(el));
|
|
28
|
-
const data = await notification({
|
|
29
|
-
pg,
|
|
30
|
-
funcs,
|
|
31
|
-
log,
|
|
32
|
-
to,
|
|
33
|
-
template,
|
|
34
|
-
title: `Test Softpro ${date}`,
|
|
35
|
-
table,
|
|
36
|
-
nocache,
|
|
37
|
-
file,
|
|
38
|
-
id,
|
|
39
|
-
message: `Test mail Softpro ${date} Lorem Ipsum Lorem Ipsum`,
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
return {
|
|
43
|
-
message: data || 'ok',
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
catch (err) {
|
|
47
|
-
return { error: err.toString(), status: 500 };
|
|
48
|
-
}
|
|
49
|
-
}
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { existsSync } from 'fs';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
|
|
5
|
+
const fileName = fileURLToPath(import.meta.url);
|
|
6
|
+
const dirName = path.dirname(fileName);
|
|
7
|
+
|
|
8
|
+
import notification from '../funcs/sendNotification.js';
|
|
9
|
+
|
|
10
|
+
export default async function testNotification({
|
|
11
|
+
pg, funcs = {}, log, query = {}, session = {},
|
|
12
|
+
}) {
|
|
13
|
+
const { local } = funcs.config || {};
|
|
14
|
+
if (!session?.passport?.user?.user_type?.includes('admin') && !local) {
|
|
15
|
+
return { message: 'Forbidden', status: 403 };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const date = new Date().toISOString().split('T')[0];
|
|
19
|
+
if (!query.to) {
|
|
20
|
+
return { message: 'param to is required', status: 400 };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
const {
|
|
25
|
+
to, template, table, id, nocache,
|
|
26
|
+
} = query;
|
|
27
|
+
const file = [path.join(dirName, '../../', 'changelog.md'), path.join(dirName, 'utils', 'pin-m-ty-media-record-outline+303070.png')].filter((el) => existsSync(el));
|
|
28
|
+
const data = await notification({
|
|
29
|
+
pg,
|
|
30
|
+
funcs,
|
|
31
|
+
log,
|
|
32
|
+
to,
|
|
33
|
+
template,
|
|
34
|
+
title: `Test Softpro ${date}`,
|
|
35
|
+
table,
|
|
36
|
+
nocache,
|
|
37
|
+
file,
|
|
38
|
+
id,
|
|
39
|
+
message: `Test mail Softpro ${date} Lorem Ipsum Lorem Ipsum`,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
message: data || 'ok',
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
return { error: err.toString(), status: 500 };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import nodemailer from 'nodemailer';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Надсилає поваідомлення на пошту
|
|
5
|
-
*
|
|
6
|
-
* @type function
|
|
7
|
-
* @alias sendEmail
|
|
8
|
-
* @summary Функція здійснює розсилку по email
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
export default async function sendEmail({
|
|
12
|
-
funcs, to, from, subject, html, attachments,
|
|
13
|
-
}) {
|
|
14
|
-
const { config = {} } = funcs;
|
|
15
|
-
|
|
16
|
-
if (!to?.length) {
|
|
17
|
-
throw new Error('empty to list');
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const { mailSetting = {} } = config;
|
|
21
|
-
|
|
22
|
-
/*= == check service and setting === */
|
|
23
|
-
if (!mailSetting.service) {
|
|
24
|
-
throw new Error('service is not defined in config');
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
Object.assign(mailSetting, { rejectUnauthorized: false });
|
|
28
|
-
|
|
29
|
-
if (mailSetting.port === 465) {
|
|
30
|
-
Object.assign(mailSetting, { secure: true });
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const transport = nodemailer.createTransport(mailSetting);
|
|
34
|
-
|
|
35
|
-
const result = await transport.sendMail({
|
|
36
|
-
from: from || mailSetting.from, to, subject, html, attachments,
|
|
37
|
-
});
|
|
38
|
-
return result;
|
|
39
|
-
}
|
|
1
|
+
import nodemailer from 'nodemailer';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Надсилає поваідомлення на пошту
|
|
5
|
+
*
|
|
6
|
+
* @type function
|
|
7
|
+
* @alias sendEmail
|
|
8
|
+
* @summary Функція здійснює розсилку по email
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export default async function sendEmail({
|
|
12
|
+
funcs, to, from, subject, html, attachments,
|
|
13
|
+
}) {
|
|
14
|
+
const { config = {} } = funcs;
|
|
15
|
+
|
|
16
|
+
if (!to?.length) {
|
|
17
|
+
throw new Error('empty to list');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const { mailSetting = {} } = config;
|
|
21
|
+
|
|
22
|
+
/*= == check service and setting === */
|
|
23
|
+
if (!mailSetting.service) {
|
|
24
|
+
throw new Error('service is not defined in config');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
Object.assign(mailSetting, { rejectUnauthorized: false });
|
|
28
|
+
|
|
29
|
+
if (mailSetting.port === 465) {
|
|
30
|
+
Object.assign(mailSetting, { secure: true });
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const transport = nodemailer.createTransport(mailSetting);
|
|
34
|
+
|
|
35
|
+
const result = await transport.sendMail({
|
|
36
|
+
from: from || mailSetting.from, to, subject, html, attachments,
|
|
37
|
+
});
|
|
38
|
+
return result;
|
|
39
|
+
}
|
package/notification/index.js
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
// api
|
|
2
|
-
import userNotifications from './controllers/userNotifications.js';
|
|
3
|
-
import testEmail from './controllers/testEmail.js';
|
|
4
|
-
// funcs
|
|
5
|
-
import addNotification from './funcs/addNotification.js'; // add to db
|
|
6
|
-
import notification from './funcs/sendNotification.js'; // send
|
|
7
|
-
|
|
8
|
-
const tableSchema = {
|
|
9
|
-
querystring: {
|
|
10
|
-
nocache: { type: 'string', pattern: '^(\\d+)$' },
|
|
11
|
-
},
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
async function plugin(fastify, config = {}) {
|
|
15
|
-
const prefix = config.prefix || '/api';
|
|
16
|
-
fastify.route({
|
|
17
|
-
method: 'GET',
|
|
18
|
-
url: `${prefix}/notification`,
|
|
19
|
-
config: {
|
|
20
|
-
policy: ['user'], // implement user auth check policy??
|
|
21
|
-
},
|
|
22
|
-
schema: tableSchema,
|
|
23
|
-
handler: userNotifications,
|
|
24
|
-
});
|
|
25
|
-
fastify.route({
|
|
26
|
-
method: 'GET',
|
|
27
|
-
url: `${prefix}/test-email`,
|
|
28
|
-
config: {
|
|
29
|
-
policy: ['user'],
|
|
30
|
-
},
|
|
31
|
-
handler: testEmail,
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
fastify.decorate('addNotification', addNotification);
|
|
35
|
-
fastify.decorate('notification', notification);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export default plugin;
|
|
1
|
+
// api
|
|
2
|
+
import userNotifications from './controllers/userNotifications.js';
|
|
3
|
+
import testEmail from './controllers/testEmail.js';
|
|
4
|
+
// funcs
|
|
5
|
+
import addNotification from './funcs/addNotification.js'; // add to db
|
|
6
|
+
import notification from './funcs/sendNotification.js'; // send
|
|
7
|
+
|
|
8
|
+
const tableSchema = {
|
|
9
|
+
querystring: {
|
|
10
|
+
nocache: { type: 'string', pattern: '^(\\d+)$' },
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
async function plugin(fastify, config = {}) {
|
|
15
|
+
const prefix = config.prefix || '/api';
|
|
16
|
+
fastify.route({
|
|
17
|
+
method: 'GET',
|
|
18
|
+
url: `${prefix}/notification`,
|
|
19
|
+
config: {
|
|
20
|
+
policy: ['user'], // implement user auth check policy??
|
|
21
|
+
},
|
|
22
|
+
schema: tableSchema,
|
|
23
|
+
handler: userNotifications,
|
|
24
|
+
});
|
|
25
|
+
fastify.route({
|
|
26
|
+
method: 'GET',
|
|
27
|
+
url: `${prefix}/test-email`,
|
|
28
|
+
config: {
|
|
29
|
+
policy: ['user'],
|
|
30
|
+
},
|
|
31
|
+
handler: testEmail,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
fastify.decorate('addNotification', addNotification);
|
|
35
|
+
fastify.decorate('notification', notification);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default plugin;
|
package/package.json
CHANGED
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/redis/funcs/getRedis.js
CHANGED
|
@@ -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;
|