@opengis/admin 0.4.22 → 0.4.23

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.
@@ -1,4 +1,4 @@
1
- import { _ as n, f as m } from "./import-file-DcpjZvgK.js";
1
+ import { _ as n, f as m } from "./import-file-DJR1XXLF.js";
2
2
  import { u as p } from "./user-B_2kh6ic.js";
3
3
  import { resolveComponent as f, createElementBlock as d, openBlock as u, createElementVNode as o, createBlock as h, createCommentVNode as b } from "vue";
4
4
  const x = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/admin",
3
- "version": "0.4.22",
3
+ "version": "0.4.23",
4
4
  "description": "This project Softpro Admin",
5
5
  "main": "dist/admin.js",
6
6
  "type": "module",
@@ -49,8 +49,6 @@
49
49
  "@fullcalendar/list": "^6.1.15",
50
50
  "@fullcalendar/timegrid": "^6.1.15",
51
51
  "@fullcalendar/vue3": "^6.1.15",
52
- "@opengis/fastify-auth": "1.1.x",
53
- "@opengis/fastify-table": "1.4.x",
54
52
  "@opengis/v3-core": "^0.3.213",
55
53
  "@opengis/v3-filter": "0.1.30",
56
54
  "@turf/turf": "^7.1.0",
@@ -70,6 +68,8 @@
70
68
  "vuedraggable": "^4.1.0"
71
69
  },
72
70
  "devDependencies": {
71
+ "@opengis/fastify-auth": "1.1.x",
72
+ "@opengis/fastify-table": "1.4.x",
73
73
  "@opengis/table-builder": "^1.1.1",
74
74
  "@vue/eslint-config-typescript": "^12.0.0",
75
75
  "eslint": "^8.49.0",
package/plugin.js CHANGED
@@ -12,7 +12,7 @@ async function plugin(fastify, opts = config) {
12
12
 
13
13
  fastify.register(import('./server/plugins/cron.js'), opts); // cron / scheduler
14
14
  fastify.register(import('./server/plugins/hook.js'), opts); // data / template hooks
15
- fastify.register(import('./server/plugins/access/index.mjs'), opts); // check access / analogue of policy
15
+ // fastify.register(import('./server/plugins/access/index.mjs'), opts); // check access / analogue of policy
16
16
 
17
17
  // API
18
18
  // fastify.register(import('./server/routes/properties/index.mjs'), opts);
@@ -23,9 +23,9 @@ async function plugin(fastify, opts = config) {
23
23
  // fastify.register(import('./server/routes/data/index.mjs'), opts);
24
24
  fastify.register(import('./server/routes/user/index.mjs'), opts);
25
25
  // fastify.register(import('./server/routes/widget/index.mjs'), opts); // moved to core
26
- fastify.register(import('./server/routes/access/index.mjs'), opts);
26
+ // fastify.register(import('./server/routes/access/index.mjs'), opts); // moved to core
27
27
  // fastify.register(import('./server/routes/report/index.mjs'), opts);
28
28
  // fastify.register(import('./server/routes/print/index.mjs'), opts);
29
- fastify.register(import('./server/routes/util/index.mjs'), opts);
29
+ // fastify.register(import('./server/routes/util/index.mjs'), opts); // moved to core
30
30
  }
31
31
  export default fp(plugin)
package/utils.js CHANGED
@@ -1,13 +1,24 @@
1
1
  import yamlSafe from 'js-yaml';
2
2
 
3
- import { handlebars, handlebarsSync, addTemplateDir } from '@opengis/fastify-table/utils.js';
3
+ import { config, handlebars, handlebarsSync, addTemplateDir } from '@opengis/fastify-table/utils.js';
4
4
 
5
5
 
6
6
  import isAdmin from './server/utils/isAdmin.js';
7
7
  import addNotification from './server/utils/addNotification.js';
8
8
  import sendNotification from './server/utils/sendNotification.js';
9
9
 
10
- import getAdminAccess from './server/plugins/access/funcs/getAdminAccess.js';
10
+ async function getAdminAccess({
11
+ id, user = {},
12
+ }) {
13
+ if (!id) {
14
+ return { message: 'not enough params: id', status: 400 };
15
+ }
16
+
17
+ if (!config?.local && !['admin'].includes(user.user_type, user.type)) {
18
+ return { message: 'access restricted: admin', status: 403 };
19
+ }
20
+ return null;
21
+ }
11
22
 
12
23
  function loadSafe(yml) {
13
24
  try {
@@ -1,13 +0,0 @@
1
- import { config } from '@opengis/fastify-table/utils.js';
2
-
3
- export default async function getAdminAccess({
4
- id, user = {},
5
- }) {
6
- if (!id) {
7
- return { message: 'not enough params: id', status: 400 };
8
- }
9
-
10
- if (!config?.local && !['admin'].includes(user.user_type, user.type)) {
11
- return { message: 'access restricted: admin', status: 403 };
12
- }
13
- }
@@ -1,6 +0,0 @@
1
- import getAdminAccess from './funcs/getAdminAccess.js';
2
-
3
- async function plugin(fastify) {
4
- // fastify.decorate('getAdminAccess', getAdminAccess);
5
- }
6
- export default plugin;
@@ -1,29 +0,0 @@
1
- import { pgClients } from '@opengis/fastify-table/utils.js';
2
-
3
- import { getAdminAccess } from '../../../../utils.js';
4
-
5
- export default async function accessGroup({
6
- pg = pgClients.client, params = {}, user = {},
7
- }) {
8
-
9
- if (!params?.id) {
10
- return { message: 'not enough params: id', status: 400 };
11
- }
12
-
13
- // restrict access - admin only
14
- const check = await getAdminAccess({
15
- id: params.id, user,
16
- });
17
- if (check) return check;
18
-
19
- const { rows: routes = [] } = await pg.query(`select a.route_id as path, b.actions from admin.routes a
20
- left join admin.role_access b on a.route_id=b.route_id
21
- where b.role_id=$1`, [params.id]);
22
-
23
- const { rows: users = [] } = await pg.query(`select user_uid as id, user_name as name, access_granted,
24
- b.cdate as user_created, b.last_activity_date as last_activity from admin.user_roles a
25
- left join admin.users b on a.user_uid=b.uid
26
- where a.role_id=$1`, [params.id]);
27
-
28
- return { routes, users };
29
- }
@@ -1,54 +0,0 @@
1
- import { pgClients } from '@opengis/fastify-table/utils.js';
2
-
3
- import { getAdminAccess } from '../../../../utils.js';
4
- import accessGroup from './access.group.js';
5
-
6
- export default async function accessGroupPost({
7
- pg = pgClients.client, params = {}, user = {}, body = {},
8
- }) {
9
- const { id } = params;
10
- if (!user?.uid) return { status: 403, message: 'access restricted' }
11
-
12
- // restrict access - admin only
13
- const check = await getAdminAccess({ id, user });
14
- if (check) return check;
15
-
16
- const { users = [], routes = [] } = body;
17
-
18
- if (!routes?.length) {
19
- // return { message: 'not enough params: users / routes', status: 400 };
20
- await pg.query(`delete from admin.role_access where role_id=$1`, [id]);
21
-
22
- if (!users?.length) {
23
- return { message: { id, routes }, status: 200 };
24
- }
25
- }
26
-
27
- if (routes?.length) {
28
- const { routesDB = [] } = await pg.query('select array_agg(route_id) as "routesDB" from admin.routes where enabled')
29
- .then((res1) => res1.rows?.[0] || {});
30
- await pg.query(`delete from admin.role_access where role_id=$1;`, [id]);
31
-
32
-
33
- const q = `insert into admin.role_access(role_id,route_id,actions) values ($1,$2,$3)`;
34
- await Promise.all(routes.filter(el => routesDB.includes(el.path) && el.actions).map(el => pg.query(q, [id, el.path, el.actions])))
35
-
36
- const { rows } = await pg.query(`select a.route_id as path, b.actions as actions from admin.routes a
37
- left join admin.role_access b on a.route_id=b.route_id
38
- where b.role_id=$1`, [id]);
39
-
40
- if (!users?.length) {
41
- return { message: { id, routes: rows }, status: 200 };
42
- }
43
- }
44
-
45
- const q = `delete from admin.user_roles where role_id='${id.replace(/'/g, "''")}';
46
- insert into admin.user_roles(role_id,user_uid,access_granted)
47
- values ${users.filter((el) => el?.id).map((el) => `('${id.replace(/'/g, "''")}','${el.id.replace(/'/g, "''")}','${user?.uid?.replace(/'/g, "''")}')`)}`;
48
-
49
- await pg.query(q);
50
-
51
- const res = await accessGroup({ pg, params, session });
52
-
53
- return res;
54
- }
@@ -1,34 +0,0 @@
1
- import { pgClients, metaFormat } from '@opengis/fastify-table/utils.js';
2
- import { getAdminAccess } from '../../../../utils.js';
3
-
4
- const q = `select a.route_id as id, coalesce(b.user_uid, d.user_uid) as user_uid, coalesce(d.actions, b.actions, array['view']) as actions, b.scope, c.role_id
5
- from admin.routes a
6
- left join admin.role_access b on
7
- a.route_id=b.route_id
8
- left join admin.roles c on
9
- b.role_id=c.role_id
10
- and c.enabled
11
- left join admin.user_roles d on
12
- c.role_id=d.role_id
13
- and ( case when
14
- d.expiration is not null
15
- then d.expiration > CURRENT_DATE
16
- else 1=1
17
- end )
18
- where $1 in (a.route_id, a.alias, a.table_name) and coalesce(b.user_uid, d.user_uid) is not null`;
19
-
20
- export default async function accessInterface(req) {
21
- const { pg = pgClients.client, params = {}, user = {} } = req;
22
-
23
- // restrict access - admin only
24
- const check = await getAdminAccess({
25
- id: params.name, user,
26
- });
27
- if (check) return check;
28
-
29
- const { rows = [] } = await pg.query(q, [params.name]);
30
-
31
- const cls = { user_uid: 'core.user_uid', actions: 'core.actions', role_id: 'core.roles' };
32
- await metaFormat({ rows, cls, sufix: false });
33
- return { rows };
34
- }
@@ -1,11 +0,0 @@
1
- import accessGroup from "./controllers/access.group.js";
2
- import accessGroupPost from "./controllers/access.group.post.js";
3
- import accessInterface from "./controllers/access.interface.js";
4
-
5
- import { accessGroupPostSchema, accessGroupSchema, accessInterfaceSchema } from "./schema.mjs";
6
-
7
- export default async function route(fastify) {
8
- fastify.get('/access-group/:id', { schema: accessGroupSchema }, accessGroup);
9
- fastify.post('/access-group/:id', { schema: accessGroupPostSchema }, accessGroupPost);
10
- fastify.get('/access-interface/:name', { schema: accessInterfaceSchema }, accessInterface);
11
- }
@@ -1,68 +0,0 @@
1
- export default null;
2
- export { accessGroupSchema, accessGroupPostSchema, accessInterfaceSchema }
3
-
4
- const accessGroupSchema = {
5
- params: {
6
- type: 'object',
7
- properties: {
8
- id: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
9
- },
10
- required: ['id'],
11
- },
12
- };
13
-
14
- const accessInterfaceSchema = {
15
- params: {
16
- type: 'object',
17
- properties: {
18
- name: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
19
- },
20
- required: ['name'],
21
- },
22
- };
23
-
24
- const accessGroupPostSchema = {
25
- params: {
26
- type: 'object',
27
- properties: {
28
- id: { type: 'string', pattern: '^([\\d\\w._-]+)$' },
29
- },
30
- required: ['id'],
31
- },
32
- body: {
33
- type: 'object',
34
- properties: {
35
- users: {
36
- type: 'array',
37
- items: {
38
- type: 'object',
39
- properties: {
40
- id: {
41
- type: 'string',
42
- pattern: '^([\\d\\w._-]+)$',
43
- },
44
- },
45
- },
46
- },
47
- routes: {
48
- type: 'array',
49
- /*items: {
50
- type: 'object',
51
- properties: {
52
- path: {
53
- type: 'string',
54
- pattern: '^([\\d\\w._-]+)$',
55
- },
56
- actions: {
57
- type: 'array',
58
- items: {
59
- type: 'string',
60
- enum: ['get', 'add', 'edit', 'del'],
61
- },
62
- },
63
- },
64
- },*/
65
- },
66
- },
67
- },
68
- };
@@ -1,89 +0,0 @@
1
- import { getTemplate, handlebarsSync, pgClients, getToken } from "@opengis/fastify-table/utils.js";
2
-
3
- function dayOfTheYear(date) {
4
- const start = new Date(date.getFullYear(), 0, 0);
5
- const diff = (date - start) + ((start.getTimezoneOffset() - date.getTimezoneOffset()) * 60 * 1000);
6
- const oneDay = 1000 * 60 * 60 * 24;
7
- const day = Math.floor(diff / oneDay);
8
- return day;
9
- }
10
-
11
- export default async function codeGenerator({
12
- pg = pgClients.client, params = {}, user = {}, query = {},
13
- }, reply) {
14
- const { token, column } = params;
15
- const data = query.data?.split?.(';') || [];
16
-
17
- if (!token || !column) {
18
- return reply.status(400).send('not enough params: token / column');
19
- }
20
-
21
- if (!user?.uid) {
22
- return reply.status(401).send('access restricted: token');
23
- }
24
-
25
- const tokenData = await getToken({ token, uid: user?.uid, json: 1 }) || {};
26
-
27
- if (!tokenData?.form || !tokenData?.table) {
28
- return reply.status(401).send('token not allow');
29
- }
30
-
31
- const loadTemplate = await getTemplate('form', tokenData.form);
32
- const schema = loadTemplate?.schema || loadTemplate;
33
-
34
- if (!schema) {
35
- return reply.status(404).send('form not found');
36
- }
37
-
38
- if (!schema?.[column]?.template) {
39
- return reply.status(400).send('template not specified');
40
- }
41
-
42
- const columnValue = data.find(el => el.startsWith(column))?.split('=')?.pop();
43
-
44
- const loadTable = await getTemplate('table', tokenData.table);
45
- const table = loadTable?.table || tokenData.table;
46
-
47
- if (!pg.pk?.[table]) {
48
- return reply.status(404).send('table pk not found');
49
- }
50
-
51
- const { count = 0 } = await pg.query(
52
- `select count(*) from ${table} where ${columnValue ? `${column}::text = '${columnValue}'` : 'true'} limit 1`,
53
- ).then(el => el.rows?.[0] || {});
54
-
55
- const { NUMY = 0 } = await pg.query(
56
- `select ${column} as "NUMY" from ${table} where ${column} is not null and date_part('year', cdate) = $1 order by cdate desc limit 1`,
57
- [(new Date()).getFullYear()]
58
- ).then(el => el.rows?.[0] || {});
59
-
60
- const date = new Date();
61
-
62
- const template = schema[column].template.match(/NUM[M|Y] \d/g)
63
- .reduce((acc, curr) => acc.replace(
64
- curr.startsWith('{{{') ? `{{{${curr}}}}` : `{{${curr}}}`,
65
- handlebarsSync.compile(`{{paddingNumber value padding}}`)({ padding: curr.substring(4, curr.length)?.trim?.(), value: curr.startsWith('NUMY') ? NUMY : +count + 1 })),
66
- schema[column].template
67
- );
68
- const result = handlebarsSync.compile(template)({
69
- HH: date.getHours(), // hours 24h: 14:00 = 14
70
- HH12: (date.getHours() + 24) % 12 || 12, // hours 12h: 14:00 = 2
71
- HH24: date.getHours(), // hours 24h: 14:00 = 14
72
- MI: date.getMinutes(), // minutes
73
- SS: date.getSeconds(), // seconds
74
-
75
- YYYY: date.getFullYear(), // full year: 2025
76
- YY: date.getFullYear().toString().substring(2, 4), // last 2 digits of year: 25
77
-
78
- MONTH: date.toLocaleString('en', { month: 'long' }).toUpperCase(), // month name: MARCH
79
- MON: date.toLocaleString('en', { month: 'long' }).substring(0, 3).toUpperCase(), // month name abbrev: MAR
80
- MM: date.getMonth() + 1, // month number: 1 - january, 12 - december
81
-
82
- D: date.getDay(), // day of the week: 1 - monday, 7 - sunday
83
- DD: date.getDate(), // day of the month: january 4 = 4
84
- DDD: dayOfTheYear(date), // day of the year: march 4 = 63
85
- ...data,
86
- });
87
-
88
- return reply.status(200).send(result);
89
- }
@@ -1,5 +0,0 @@
1
- import codeGenerator from "./controllers/code.generator.js";
2
-
3
- export default async function plugin(fastify, opts) {
4
- fastify.get('/code-gen/:token/:column/:id?', { config: { policy: ['user'] } }, codeGenerator);
5
- }