@opengis/fastify-table 1.2.33 → 1.2.35

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.2.33",
3
+ "version": "1.2.35",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [
@@ -9,11 +9,20 @@ import dblist from '../../../../dblist.js';
9
9
  import pgClients from '../pgClients.js';
10
10
  import init from './init.js';
11
11
 
12
+ function getDBParams(str) {
13
+ if (typeof str === 'string' && !str.includes(':')) {
14
+ return { name: str, db: str };
15
+ }
16
+ const arr = str?.match(/(([A-z_0-9]+):([A-z0-9_]+)@)?([a-z0-9._]+):([0-9]+)(\/([a-z0-9_]+))?/) || [];
17
+ const [, , user, password, host, port, , db] = arr;
18
+ return { user, password, host, port, db };
19
+ }
20
+
12
21
  function getPG(param) {
13
22
  const dbListParams = dblist.find(el => el.database === (param?.db || param?.database || param));
14
23
  const {
15
24
  user, password, host, port, db, database, name: origin,
16
- } = dbListParams || param || {};
25
+ } = dbListParams ?? (typeof param === 'string' ? getDBParams(param) : param || {});
17
26
  const name = origin || db || database || param || 'client';
18
27
  if (pgClients[name]) return pgClients[name];
19
28
 
@@ -9,11 +9,20 @@ import dblist from '../../../../dblist.js';
9
9
  import pgClients from '../pgClients.js';
10
10
  import init from './init.js';
11
11
 
12
+ function getDBParams(str) {
13
+ if (typeof str === 'string' && !str.includes(':')) {
14
+ return { name: str, db: str };
15
+ }
16
+ const arr = str?.match(/(([A-z_0-9]+):([A-z0-9_]+)@)?([a-z0-9._]+):([0-9]+)(\/([a-z0-9_]+))?/) || [];
17
+ const [, , user, password, host, port, , db] = arr;
18
+ return { user, password, host, port, db };
19
+ }
20
+
12
21
  async function getPGAsync(param) {
13
22
  const dbListParams = dblist.find(el => el.database === (param?.db || param?.database || param));
14
23
  const {
15
24
  user, password, host, port, db, database, name: origin,
16
- } = dbListParams ?? (typeof param === 'string' ? { db: param } : param || {});
25
+ } = dbListParams ?? (typeof param === 'string' ? getDBParams(param) : param || {});
17
26
  const name = origin || db || database || param || 'client';
18
27
 
19
28
  if (pgClients[name]?.tlist) return pgClients[name];
@@ -71,6 +71,9 @@ export default function checkPolicy(req, reply) {
71
71
 
72
72
  /* === 0. policy: unauthorized access from admin URL === */
73
73
  const validToken = (req.ip === '193.239.152.181' || req.ip === '127.0.0.1' || req.ip.startsWith('192.168.') || config.debug) && req.headers?.uid && req.headers?.token && config.auth?.tokens?.includes?.(headers.token);
74
+ if (validToken && !req?.user?.uid) {
75
+ req.user = { uid: req.headers?.uid };
76
+ }
74
77
  if (!validToken && !user?.uid && !config.auth?.disable && isAdmin && !policy.includes('public') && !skipCheckPolicyRoutes.filter((el) => el).find(el => req.url.includes(el))) {
75
78
  logger.file('policy/unauthorized', {
76
79
  path, method, params, query, body, token: headers?.token, userId: headers?.uid, ip: req.ip, headers, message: 'unauthorized',