@opengis/admin 0.1.62 → 0.1.64

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
- import { i as L, j as R, _ as V, u as H, a as A } from "./import-file-D6JQHFSe.js";
2
- import { computed as q, resolveComponent as $, openBlock as s, createElementBlock as a, createElementVNode as p, toDisplayString as D, createVNode as z, withCtx as B, createTextVNode as N, createBlock as m, createCommentVNode as v, normalizeClass as M, Fragment as w, renderList as j, resolveDynamicComponent as T } from "vue";
1
+ import { g as L, h as R, _ as V, u as H, a as A } from "./import-file-BkyTVz51.js";
2
+ import { computed as q, resolveComponent as $, openBlock as s, createElementBlock as a, createElementVNode as p, toDisplayString as j, createVNode as z, withCtx as B, createTextVNode as N, createBlock as m, createCommentVNode as v, normalizeClass as M, Fragment as w, renderList as D, resolveDynamicComponent as T } from "vue";
3
3
  const E = { class: "h-[76px] bg-white border rounded-xl flex items-center justify-between px-[15px] mb-[16px]" }, S = { class: "text-lg font-semibold md:text-xl text-stone-800 dark:text-neutral-200" }, G = { class: "flex items-center gap-[6px]" }, O = {
4
4
  __name: "admin-card-header",
5
5
  props: {
@@ -28,7 +28,7 @@ const E = { class: "h-[76px] bg-white border rounded-xl flex items-center justif
28
28
  onClick: r,
29
29
  class: "text-sm h-[20px] text-blue-600 font-medium hover:border-b hover:border-b-2 hover:border-b-blue-500"
30
30
  }, " До таблиці "),
31
- p("h2", S, D(t.title), 1)
31
+ p("h2", S, j(t.title), 1)
32
32
  ]),
33
33
  p("div", G, [
34
34
  z(b, {
@@ -153,26 +153,26 @@ function se(t, n, c, l, r, u) {
153
153
  p("div", {
154
154
  class: M(["grid gap-[20px]", u.getGridClass()])
155
155
  }, [
156
- (s(!0), a(w, null, j((b = r.objectData) == null ? void 0 : b.panels, (o, i) => {
156
+ (s(!0), a(w, null, D((b = r.objectData) == null ? void 0 : b.panels, (o, i) => {
157
157
  var C;
158
158
  return s(), a("div", {
159
159
  key: i,
160
160
  class: M(u.getColClass(o.col))
161
161
  }, [
162
162
  o != null && o.name ? (s(), a("div", P, [
163
- p("h2", J, D((o == null ? void 0 : o.title) || "Панель"), 1),
163
+ p("h2", J, j((o == null ? void 0 : o.title) || "Панель"), 1),
164
164
  p("div", {
165
165
  class: "p-[20px] border-t",
166
166
  innerHTML: (C = r.objectData) == null ? void 0 : C.data[o == null ? void 0 : o.name]
167
167
  }, null, 8, K)
168
168
  ])) : o.type === "container" ? (s(), a("div", Q, [
169
- (s(!0), a(w, null, j(o.items, (e, k) => {
169
+ (s(!0), a(w, null, D(o.items, (e, k) => {
170
170
  var _, x, g, f, y;
171
171
  return s(), a("div", {
172
172
  key: k,
173
173
  class: "border rounded-xl bg-white mb-[20px]"
174
174
  }, [
175
- p("h2", U, D((e == null ? void 0 : e.title) || "Панель"), 1),
175
+ p("h2", U, j((e == null ? void 0 : e.title) || "Панель"), 1),
176
176
  e != null && e.component ? (s(), a("div", W, [
177
177
  (s(), m(T(e.component), {
178
178
  geometry: (x = (_ = r.objectData) == null ? void 0 : _.rows[0]) == null ? void 0 : x.geom,
@@ -190,16 +190,16 @@ function se(t, n, c, l, r, u) {
190
190
  ])) : v("", !0),
191
191
  (o == null ? void 0 : o.type) === "tabs" ? (s(), a(w, { key: 2 }, [
192
192
  p("nav", Z, [
193
- (s(!0), a(w, null, j(o == null ? void 0 : o.items, (e) => (s(), a("button", {
193
+ (s(!0), a(w, null, D(o == null ? void 0 : o.items, (e) => (s(), a("button", {
194
194
  key: (e == null ? void 0 : e.name) || (e == null ? void 0 : e.component),
195
195
  onClick: (k) => r.component = (e == null ? void 0 : e.component) || (e == null ? void 0 : e.name),
196
196
  class: M(["px-2.5 h-[30px] py-1.5 relative inline-flex items-center gap-x-2 text-gray-500 hover:bg-gray-100 focus:bg-gray-100 hover:text-gray-800 text-sm whitespace-nowrap rounded-lg focus:outline-none", {
197
197
  " font-semibold after:absolute after:bottom-[-14px] after:left-2.5 after:right-2.5 after:z-10 after:h-0.5 after:bg-gray-800": r.component === (e == null ? void 0 : e.component) || r.component === (e == null ? void 0 : e.name),
198
198
  "": r.component !== (e == null ? void 0 : e.component) && r.component !== (e == null ? void 0 : e.name)
199
199
  }])
200
- }, D(e == null ? void 0 : e.title), 11, ee))), 128))
200
+ }, j(e == null ? void 0 : e.title), 11, ee))), 128))
201
201
  ]),
202
- (s(!0), a(w, null, j(o.items, (e, k) => {
202
+ (s(!0), a(w, null, D(o.items, (e, k) => {
203
203
  var _, x, g, f, y;
204
204
  return s(), a(w, { key: k }, [
205
205
  r.component === (e == null ? void 0 : e.component) || r.component === (e == null ? void 0 : e.name) ? (s(), a("div", te, [
@@ -1,5 +1,5 @@
1
1
  import { resolveComponent as e, openBlock as r, createBlock as t } from "vue";
2
- import { _ as c } from "./import-file-D6JQHFSe.js";
2
+ import { _ as c } from "./import-file-BkyTVz51.js";
3
3
  const n = {};
4
4
  function s(_, p, a, i, f, m) {
5
5
  const o = e("router-view");
@@ -1,4 +1,4 @@
1
- import { _ as b, u as h, a as c } from "./import-file-D6JQHFSe.js";
1
+ import { _ as b, u as h, a as c } from "./import-file-BkyTVz51.js";
2
2
  import { resolveComponent as d, openBlock as m, createElementBlock as p, createElementVNode as l, createBlock as f, createCommentVNode as g } from "vue";
3
3
  const x = {
4
4
  data() {
@@ -3590,17 +3590,17 @@ function eq(t) {
3590
3590
  }
3591
3591
  const jI = [
3592
3592
  // { name: 'profile', path: '/profile', component: () => import('../components/profile/vs-profile.vue') },
3593
- { name: "edit", path: "/edit", component: () => import("./edit-page-BCPO83LG.js") },
3594
- { name: "add", path: "/add", component: () => import("./add-page-CFNh7Zxz.js") },
3593
+ { name: "edit", path: "/edit", component: () => import("./edit-page-C1wXXuPF.js") },
3594
+ { name: "add", path: "/add", component: () => import("./add-page-LONm322L.js") },
3595
3595
  {
3596
3596
  name: "card-view",
3597
3597
  path: "/card",
3598
- component: () => import("./card-view-Fw8T0Ddm.js"),
3598
+ component: () => import("./card-view-MKU1ijjK.js"),
3599
3599
  children: [{
3600
3600
  name: "table",
3601
3601
  path: ":table",
3602
- component: () => import("./card-view-Fw8T0Ddm.js"),
3603
- children: [{ name: "card", path: ":id", component: () => import("./card-page-B16E7Q7m.js") }]
3602
+ component: () => import("./card-view-MKU1ijjK.js"),
3603
+ children: [{ name: "card", path: ":id", component: () => import("./card-page-CnQufGpK.js") }]
3604
3604
  }]
3605
3605
  }
3606
3606
  ], UI = {}, HI = { class: "bg-gray-200 w-full px-16 md:px-0 h-screen flex items-center justify-center" }, qI = { class: "bg-white border border-gray-200 flex flex-col items-center justify-center px-4 md:px-8 lg:px-24 py-8 rounded-lg shadow-2xl" };
@@ -3648,14 +3648,14 @@ const GI = /* @__PURE__ */ Rt(UI, [["render", WI]]), ZI = (t) => {
3648
3648
  {
3649
3649
  path: "/",
3650
3650
  name: "home",
3651
- component: () => import("./admin-view-Dw9tWMxP.js"),
3651
+ component: () => import("./admin-view-CEePX3t5.js"),
3652
3652
  children: [
3653
3653
  ...e,
3654
3654
  ...t,
3655
3655
  // { path: '/', redirect: '/home' },
3656
3656
  {
3657
3657
  path: "/:catchAll(.*)",
3658
- component: () => import("./admin-interface-CniNlJEa.js")
3658
+ component: () => import("./admin-interface-eocB4uF3.js")
3659
3659
  }
3660
3660
  ]
3661
3661
  }
@@ -47510,14 +47510,12 @@ export {
47510
47510
  Rt as _,
47511
47511
  Bt as a,
47512
47512
  T8 as b,
47513
- ZL as c,
47514
- vH as d,
47515
- vU as e,
47516
- PF as f,
47517
- YL as g,
47518
- HB as h,
47519
- QH as i,
47520
- eq as j,
47521
- iq as k,
47513
+ vH as c,
47514
+ vU as d,
47515
+ PF as e,
47516
+ HB as f,
47517
+ QH as g,
47518
+ eq as h,
47519
+ iq as i,
47522
47520
  YH as u
47523
47521
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/admin",
3
- "version": "0.1.62",
3
+ "version": "0.1.64",
4
4
  "description": "This project Softpro Admin",
5
5
  "main": "dist/admin.js",
6
6
  "type": "module",
@@ -1,30 +1,73 @@
1
+ import config from '../../config.js'
1
2
  import { addHook, getToken, setToken, getTemplate } from '@opengis/fastify-table/utils.js';
2
3
 
4
+ async function getTokenData({
5
+ req, mode = 'w', token, uid,
6
+ }) {
7
+ if (!req) {
8
+ return { message: 'not enough params: req', status: 400 };
9
+ }
10
+ if (!token) {
11
+ return { message: 'not enough params: token', status: 400 };
12
+ }
13
+
14
+ if (!uid && !config?.auth?.disable) {
15
+ return { message: 'access restricted: uid', status: 403 };
16
+ }
17
+
18
+ const opt = await getToken({
19
+ uid, token, mode, json: 1,
20
+ });
21
+
22
+ if (!opt && !config?.local) {
23
+ return { message: 'access restricted: edit', status: 403 };
24
+ }
25
+ return opt;
26
+ }
27
+
3
28
  export default async function plugin(fastify) {
4
29
 
5
- addHook('preTable', async ({ req }) => {
6
- if (!req?.routeOptions?.method) return;
7
- const mode = { POST: 'a', DELETE: 'w', PUT: 'w', GET: 'w' }[req.routeOptions.method] || 'w';
8
- const { funcs, params = {}, session = {} } = req;
9
- const { uid } = funcs?.config?.auth?.disable ? { uid: '1' } : (session?.passport?.user || {});
10
- const opt = await getToken({
11
- uid, token: params.id || params.form || params.table, mode, json: 1,
12
- });
13
- if (opt) Object.assign(req, { opt });
14
- if (!opt && !funcs?.config?.local) {
15
- return { message: 'access restricted: edit', status: 403 };
16
- }
17
- return null;
30
+ addHook('preTable', async ({ req, table, user = {} }) => {
31
+ const { uid } = config?.auth?.disable ? { uid: '1' } : user || {};
32
+
33
+ //const opt = await getTokenData({ req, mode: 'w', token: table, uid });
34
+ // return opt;
35
+ });
36
+ addHook('preData', async ({ req, table, id, user = {} }) => {
37
+ const { uid } = config?.auth?.disable ? { uid: '1' } : user || {};
38
+ const opt = await getTokenData({ req, mode: 'w', token: table, uid });
39
+ return opt;
40
+ });
41
+ addHook('preForm', async ({ req, form, user }) => {
42
+ const { uid } = config?.auth?.disable ? { uid: '1' } : user || {};
43
+ const opt = await getTokenData({ req, mode: 'w', token: form, uid });
44
+ return opt;
45
+ });
46
+ addHook('preInsert', async ({ req, table, user }) => {
47
+ const { uid } = config?.auth?.disable ? { uid: '1' } : user || {};
48
+ const opt = await getTokenData({ req, mode: 'a', token: table, uid });
49
+ return opt;
50
+ });
51
+ addHook('preUpdate', async ({ req, table, id, user }) => {
52
+ const { uid } = config?.auth?.disable ? { uid: '1' } : user || {};
53
+ const opt = await getTokenData({ req, mode: 'w', token: table, uid });
54
+ return opt;
55
+ });
56
+ addHook('preDelete', async ({ req, table, id, user }) => {
57
+ const { uid } = config?.auth?.disable ? { uid: '1' } : user || {};
58
+ const opt = await getTokenData({ req, mode: 'w', token: table, uid });
59
+ return opt;
18
60
  });
19
61
 
20
- addHook('afterTable', async ({ req = {}, res = {}, rows = [], table }) => {
21
- const { pg, funcs, params = {}, session = {} } = req;
22
- const { uid } = funcs?.config?.auth?.disable ? { uid: '1' } : (session?.passport?.user || {});
23
- if (!uid || !table || !pg?.pk?.[table] || !rows.length || !params.table) return;
62
+ addHook('afterTable', async ({ req = {}, table, res = {}, rows = [], user = {} }) => {
63
+ const { pg } = req;
64
+ const loadTable = await getTemplate('table', table);
65
+ const { uid } = config?.auth?.disable ? { uid: '1' } : user;
66
+ if (!uid || !table || !pg?.pk?.[table] || !rows.length || !loadTable?.table) return;
24
67
 
25
68
  // admin.custom_column - user column data
26
69
  const { rows: properties = [] } = await pg.query(`select column_id, name, title, format, data from admin.custom_column
27
- where _table and entity=$1 and uid=$2`, [params.table, uid]);
70
+ where _table and entity=$1 and uid=$2`, [table, uid]);
28
71
  const extraColumnList = properties.map((row) => ({ id: row.column_id, name: row.name, title: row.title, format: row.format, data: row.data }));
29
72
  if (!extraColumnList?.length) return;
30
73
 
@@ -33,7 +76,7 @@ export default async function plugin(fastify) {
33
76
  }
34
77
 
35
78
  const { rows: extraData = [] } = await pg.query(`select object_id, json_object_agg( property_id, coalesce(value_date::text,value_text) ) as extra from crm.extra_data
36
- where property_entity=$1 and property_id=any($2) and object_id=any($3) group by object_id`, [params.table, extraColumnList?.map((el) => el.id), rows.map((el) => el.id)]);
79
+ where property_entity=$1 and property_id=any($2) and object_id=any($3) group by object_id`, [table, extraColumnList?.map((el) => el.id), rows.map((el) => el.id)]);
37
80
 
38
81
  if (!extraData?.length) {
39
82
  // Object.assign(rows?.[0] || {}, { ...extraColumnList.reduce((acc, curr) => Object.assign(acc, { [curr.name]: null }), {}) });
@@ -60,7 +103,7 @@ export default async function plugin(fastify) {
60
103
  });
61
104
 
62
105
  // extract table from form token for user columns - p.2 - read (refactor to global token)
63
- /* addHook('preTemplate', async ({ req = {} }) => {
106
+ /* addHook('preTemplate', async ({ req = {}, name, type, user }) => {
64
107
  const { funcs, params = {}, session = {} } = req;
65
108
  const { uid } = funcs?.config?.auth?.disable ? { uid: '1' } : (session?.passport?.user || {});
66
109
  if (!uid || params?.type !== 'form' || !params?.name) return null;
@@ -73,9 +116,9 @@ export default async function plugin(fastify) {
73
116
  }
74
117
  }); */
75
118
 
76
- addHook('afterTemplate', async ({ req = {}, data = {} }) => {
77
- const { funcs, session = {} } = req;
78
- const { uid } = funcs?.config?.auth?.disable ? { uid: '1' } : (session?.passport?.user || {});
119
+ addHook('afterTemplate', async ({ req = {}, data = {}, user = {} }) => {
120
+ const { funcs } = req;
121
+ const { uid } = funcs?.config?.auth?.disable ? { uid: '1' } : user;
79
122
  const { pg, params = {} } = req;
80
123
  // extract table from form token for user columns - p.1 - assign (refactor to global token)
81
124
  /* if (params?.type === 'table') {
@@ -100,11 +143,11 @@ export default async function plugin(fastify) {
100
143
  }));
101
144
  });
102
145
 
103
- addHook('afterUpdate', async ({ req, res = {} }) => {
146
+ addHook('afterUpdate', async ({ req, res = {}, user = {} }) => {
104
147
  const {
105
- pg, funcs, session = {}, params = {}, body = {},
148
+ pg, params = {}, body = {},
106
149
  } = req;
107
- const { uid } = funcs?.config?.auth?.disable ? { uid: '1' } : (session?.passport?.user || {});
150
+ const { uid } = config?.auth?.disable ? { uid: '1' } : user;
108
151
  if (!uid) return null;
109
152
 
110
153
  const loadTable = await getTemplate('table', params.table);
@@ -125,11 +168,11 @@ export default async function plugin(fastify) {
125
168
  return pg.query(q);
126
169
  });
127
170
 
128
- addHook('afterInsert', async ({ req, res = {} }) => {
171
+ addHook('afterInsert', async ({ req, res = {}, user = {} }) => {
129
172
  const {
130
- pg, funcs, session = {}, params = {}, body = {},
173
+ pg, params = {}, body = {},
131
174
  } = req;
132
- const { uid } = funcs?.config?.auth?.disable ? { uid: '1' } : (session?.passport?.user || {});
175
+ const { uid } = config?.auth?.disable ? { uid: '1' } : user;
133
176
  if (!uid) return null;
134
177
 
135
178
  const loadTable = await getTemplate('table', params.table);
@@ -14,7 +14,7 @@ export default async function getTableData(req) {
14
14
  const time = Date.now();
15
15
 
16
16
  const {
17
- pg, params, funcs = {}, query = {}, opt = {}, session = {}, mode = 'table',
17
+ pg, params, funcs = {}, query = {}, opt = {}, session = {},
18
18
  } = req;
19
19
  const { uid } = session.passport?.user || {};
20
20
 
@@ -99,7 +99,7 @@ export default async function getTableData(req) {
99
99
  time: Date.now() - time, card: loadTable.card, actions: loadTable.actions, access, total, count: rows.length, pk, form, meta, columns,
100
100
  };
101
101
 
102
- await applyHook('afterTable', { req, res, table, rows });
102
+ await applyHook('afterTable', { req, table: params?.table, res, rows, user: session?.passport?.user });
103
103
  await metaFormat({ funcs, rows, table: params.table });
104
104
 
105
105
 
@@ -1,10 +1,12 @@
1
1
  import { applyHook, getTemplate } from "@opengis/fastify-table/utils.js";
2
2
 
3
3
  export default async function getTemplateApi(req) {
4
- const res = await applyHook('preTemplate', { req });
4
+ const { user } = req?.session?.passport || {};
5
+ const { funcs, params = {}, session = {} } = req;
6
+ const res = await applyHook('preTemplate', { req, name: params?.name, type: params?.type, user });
5
7
  if (res) return res;
6
8
 
7
- const { funcs, params = {}, session = {} } = req;
9
+
8
10
  const { type, name } = params;
9
11
 
10
12
  const data = await getTemplate(type, name);
@@ -16,6 +18,6 @@ export default async function getTemplateApi(req) {
16
18
  ) {
17
19
  return `access restricted ${name}`;
18
20
  }
19
- await applyHook('afterTemplate', { req, data })
21
+ await applyHook('afterTemplate', { req, data, user })
20
22
  return data?.html || data || `template not found "${name}"`;
21
23
  }