@opengis/fastify-table 1.1.122 → 1.1.124

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "1.1.122",
3
+ "version": "1.1.124",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": ["fastify", "table", "crud", "pg", "backend" ],
@@ -26,7 +26,7 @@ export default async function logChanges({
26
26
 
27
27
  const { fields = [] } = await pg.query(`select * from ${table} limit 0`);
28
28
  const columnList = fields.map((el) => el?.name);
29
- const q = `select ${Object.keys(data || {}).filter((el) => columnList.includes(el)).join(',') || '*'} from ${table} where ${pg.pk?.[table]}=$1`;
29
+ const q = `select ${Object.keys(data || {}).filter((el) => columnList.includes(el)).map(el => `"${el.replace(/'/g, "''")}"`).join(',') || '*'} from ${table} where ${pg.pk?.[table]}=$1`;
30
30
  // console.log(q, type, id);
31
31
 
32
32
  const old = type !== 'INSERT' ? await pg.query(q, [id]).then((res) => res.rows?.[0] || {}) : {};
@@ -9,7 +9,7 @@ export default async function getMeta(opt) {
9
9
 
10
10
  if (data[table]) return data[table];
11
11
 
12
- if (!pg.tlist?.includes(table.replace(/"/g, ''))) {
12
+ if (!pg.tlist?.includes(table?.replace?.(/"/g, ''))) {
13
13
  return { error: `${table} - not found`, status: 400 };
14
14
  }
15
15
 
@@ -19,7 +19,9 @@ export default async function getMeta(opt) {
19
19
  left join pg_attribute a on c.conrelid=a.attrelid and a.attnum = c.conkey[1]
20
20
  WHERE c.contype='p'::"char" and c.conrelid::regclass = $1::regclass`, [table]).then(el => el.rows?.[0] || {});
21
21
 
22
- const pk = table.startsWith('public.') ? pks1[table.replace('public.', '')] : pks1[table];
22
+ const pk = table.startsWith('public.')
23
+ ? (pks1[table.replace('public.', '')] || pks1[table.replace('public.', '').replace(/"/g, '')])
24
+ : (pks1[table] || pks1[table.replace(/"/g, '')]);
23
25
 
24
26
  const geomAttr = fields.find((el) => pg.pgType?.[el.dataTypeID] === 'geometry')?.name; // change geometry text to geometry code
25
27
 
@@ -85,7 +85,7 @@ export default function checkPolicy(req) {
85
85
 
86
86
  /* === 5. policy: site auth === */
87
87
  if (!policy.includes('site') && !isAdmin && !config.local && !config.debug
88
- && !['/auth/redirect', `${config.prefix || '/api'}/login`].find(el => path.includes(el))) {
88
+ && !['/auth/redirect', '/logout', `${config.prefix || '/api'}/login`].find(el => path.includes(el))) {
89
89
  logger.file('policy/site', {
90
90
  path, method, params, query, body, message: 'access restricted: 5', uid: user?.uid,
91
91
  });
@@ -12,10 +12,11 @@ const tableSchema = {
12
12
 
13
13
  async function plugin(fastify, config = {}) {
14
14
  const prefix = config.prefix || '/api';
15
- fastify.put(`${prefix}/table/:table/:id?`, { schema: tableSchema }, update);
16
- fastify.delete(`${prefix}/table/:table/:id?`, { schema: tableSchema }, deleteCrud);
17
- fastify.post(`${prefix}/table/:table/:id?`, { schema: tableSchema }, insert);
18
- fastify.get(`${prefix}/table/:table/:id?`, { schema: tableSchema }, table);
15
+ const policy = ['public'];
16
+ fastify.put(`${prefix}/table/:table/:id?`, { config: { policy }, schema: tableSchema }, update);
17
+ fastify.delete(`${prefix}/table/:table/:id?`, { config: { policy }, schema: tableSchema }, deleteCrud);
18
+ fastify.post(`${prefix}/table/:table/:id?`, { config: { policy }, schema: tableSchema }, insert);
19
+ fastify.get(`${prefix}/table/:table/:id?`, { config: { policy }, schema: tableSchema }, table);
19
20
  }
20
21
 
21
22
  export default plugin;
@@ -11,7 +11,7 @@ const loggerSchema = {
11
11
  };
12
12
 
13
13
  async function plugin(fastify) {
14
- fastify.get('/logger-file/*', { schema: loggerSchema }, loggerFile);
14
+ fastify.get('/logger-file/*', { config: { policy: ['site'] }, schema: loggerSchema }, loggerFile);
15
15
  }
16
16
 
17
17
  export default plugin;
@@ -14,15 +14,16 @@ import {
14
14
 
15
15
  async function plugin(fastify, config = {}) {
16
16
  const prefix = config.prefix || '/api';
17
- fastify.get(`${prefix}/suggest/:data`, { schema: suggestSchema }, suggest);
18
- fastify.get(`${prefix}/data/:table/:id?`, { schema: tableSchema }, data); // vs.crm.data.api с node
17
+ const policy = ['public'];
18
+ fastify.get(`${prefix}/suggest/:data`, { config: { policy }, schema: suggestSchema }, suggest);
19
+ fastify.get(`${prefix}/data/:table/:id?`, { config: { policy }, schema: tableSchema }, data); // vs.crm.data.api с node
19
20
 
20
- fastify.get(`${prefix}/card/:table/:id`, { schema: tableSchema }, card);
21
- fastify.get(`${prefix}/search`, { schema: searchSchema }, search);
21
+ fastify.get(`${prefix}/card/:table/:id`, { config: { policy }, schema: tableSchema }, card);
22
+ fastify.get(`${prefix}/search`, { config: { policy }, schema: searchSchema }, search);
22
23
 
23
24
  fastify.get(`${prefix}/templates`, () => loadTemplatePath);
24
- fastify.get(`${prefix}/filter/:table`, { schema: filterSchema }, filter);
25
- fastify.get(`${prefix}/form/:form`, { schema: formSchema }, form);
25
+ fastify.get(`${prefix}/filter/:table`, { config: { policy }, schema: filterSchema }, filter);
26
+ fastify.get(`${prefix}/form/:form`, { config: { policy }, schema: formSchema }, form);
26
27
  }
27
28
 
28
29
  export default plugin;