@opengis/fastify-table 2.0.69 → 2.0.71

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 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../server/helpers/index.ts"],"names":[],"mappings":"AACA,OAAO,cAAc,MAAM,YAAY,CAAC;AAOxC,QAAA,MAAM,UAAU,KAAqC,CAAC;AA0ItD,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../server/helpers/index.ts"],"names":[],"mappings":"AACA,OAAO,cAAc,MAAM,YAAY,CAAC;AAOxC,QAAA,MAAM,UAAU,KAAqC,CAAC;AA2ItD,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,CAAC"}
@@ -74,6 +74,7 @@ handlebars.registerHelper("helperMissing", function hm() {
74
74
  // format
75
75
  handlebars.registerHelper("formatAuto", formatAuto);
76
76
  handlebars.registerHelper("formatDate", formatDate);
77
+ handlebarsSync.registerHelper("formatDate", formatDate);
77
78
  handlebars.registerHelper("formatDigit", formatDigit);
78
79
  handlebars.registerHelper("formatNum", formatNum);
79
80
  handlebars.registerHelper("formatNumber", formatNumber);
@@ -1 +1 @@
1
- {"version":3,"file":"loginUser.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/auth/funcs/loginUser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAUvC,wBAA8B,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,YAAY,kBA+CpE"}
1
+ {"version":3,"file":"loginUser.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/auth/funcs/loginUser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAUvC,wBAA8B,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,YAAY,kBAiDpE"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/plugins/auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAYxD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAMtD,wBAAsB,SAAS,CAAC,GAAG,EAAE,eAAe,EAAE,KAAK,EAAE,YAAY,iBA6GxE;AAED,iBAAS,MAAM,CAAC,OAAO,EAAE,eAAe,QA6BvC;AAED,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/plugins/auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAYxD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAMtD,wBAAsB,SAAS,CAAC,GAAG,EAAE,eAAe,EAAE,KAAK,EAAE,YAAY,iBA8GxE;AAED,iBAAS,MAAM,CAAC,OAAO,EAAE,eAAe,QAgCvC;AAED,eAAe,MAAM,CAAC"}
@@ -30,7 +30,8 @@ export async function onRequest(req, reply) {
30
30
  const isPublic = Array.isArray(policy)
31
31
  ? policy.includes("public")
32
32
  : policy === "L0";
33
- if (!req.session?.passport?.user?.uid &&
33
+ if (req.cookies?.["session_auth"] &&
34
+ !req.session?.passport?.user?.uid &&
34
35
  (config.auth?.disable || config.auth?.user) &&
35
36
  !isPublic) {
36
37
  req.session = req.session || {};
@@ -103,7 +104,10 @@ function plugin(fastify) {
103
104
  secret: config?.auth?.secret || "61b820e12858570a4b0633020d4394a17903d9a9",
104
105
  cookieName: "session_auth",
105
106
  cookie: config?.auth?.cookieOptions || { secure: false },
106
- store: new RedisStore({ client: getRedis({ db: 10 }) }),
107
+ store: new RedisStore({
108
+ prefix: `session_auth:${config.pg?.database || "db"}:`,
109
+ client: getRedis({ db: 2 }),
110
+ }),
107
111
  });
108
112
  // register passport AFTER session is ready
109
113
  fastify.register(fastifyPassport.initialize());
@@ -1,4 +1,4 @@
1
- export default function loggerSystem(req: any): Promise<{
1
+ export default function loggerSystem(req?: any): Promise<{
2
2
  process: {
3
3
  root: string;
4
4
  processFolder: string;
@@ -1 +1 @@
1
- {"version":3,"file":"loggerSystem.d.ts","sourceRoot":"","sources":["../../../../server/plugins/metric/loggerSystem.ts"],"names":[],"mappings":"AAsBA,wBAA8B,YAAY,CAAC,GAAG,EAAE,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6IlD"}
1
+ {"version":3,"file":"loggerSystem.d.ts","sourceRoot":"","sources":["../../../../server/plugins/metric/loggerSystem.ts"],"names":[],"mappings":"AAsBA,wBAA8B,YAAY,CAAC,GAAG,CAAC,EAAE,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqJnD"}
@@ -15,7 +15,7 @@ const redisKey = "logger-process-online";
15
15
  const sqlQuery = `select datname as dbname, application_name as app, client_addr as client_ip,
16
16
  (now()-backend_start)::text as msec, state, query from pg_stat_activity where datname=$1`;
17
17
  export default async function loggerSystem(req) {
18
- const { pg = pgClients.client } = req;
18
+ const { pg = pgClients.client } = req || {};
19
19
  const dbName = pg?.options?.database;
20
20
  const dbsize = config.redis
21
21
  ? await rclient.get(`${dbName}:content:dbsize:${redisKey}`)
@@ -27,7 +27,9 @@ export default async function loggerSystem(req) {
27
27
  (await pg
28
28
  .query(`select pg_size_pretty(pg_database_size('${dbName}'));`)
29
29
  .then((el) => el.rows?.[0]?.pg_size_pretty));
30
- const { rows: query = [] } = await pg.query(sqlQuery, [dbName]);
30
+ const query = await pg
31
+ .query(sqlQuery, [dbName])
32
+ .then((el) => el.rows || []);
31
33
  const { stdout: topProcess } = platform === "win32"
32
34
  ? { stdout: "Cant show top on this system type" }
33
35
  : await execAsync("top -b -n 1");
@@ -69,7 +71,13 @@ export default async function loggerSystem(req) {
69
71
  ? JSON.parse(JSON.stringify(metric5, Object.keys(metric5).sort()))
70
72
  : undefined;
71
73
  const userOnline = config.redis
72
- ? await rclient2.scan(["0", "match", `${dbName}:user:*`, "count", "10000"])
74
+ ? await rclient2.scan([
75
+ "0",
76
+ "match",
77
+ `session_auth:${dbName}:*`,
78
+ "count",
79
+ "10000",
80
+ ])
73
81
  : [];
74
82
  // const userOnline = await rclient10.scan(['0', 'match', 'sess:*', 'count', '10000']);
75
83
  return {
@@ -12,7 +12,7 @@ function getRedis({ db, host, port, } = { db: 0 }) {
12
12
  }
13
13
  const redisConfig = {
14
14
  db,
15
- keyPrefix: `${config.db}:`,
15
+ prefix: `${config.pg?.database || "db"}:`,
16
16
  host: host || config.redis?.host || "127.0.0.1",
17
17
  port: port || config.redis?.port || 6379, // Redis port
18
18
  family: 4, // 4 (IPv4) or 6 (IPv6)
@@ -1 +1 @@
1
- {"version":3,"file":"logout.d.ts","sourceRoot":"","sources":["../../../../../../server/routes/auth/controllers/core/logout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEvD;;;;GAIG;AAEH,iBAAe,MAAM,CAAC,GAAG,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,kBAG7D;AAED,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"logout.d.ts","sourceRoot":"","sources":["../../../../../../server/routes/auth/controllers/core/logout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEvD;;;;GAIG;AAEH,iBAAe,MAAM,CAAC,GAAG,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,kBAgB7D;AAED,eAAe,MAAM,CAAC"}
@@ -4,7 +4,17 @@
4
4
  *
5
5
  */
6
6
  async function logout(req, reply) {
7
+ if (!req.user) {
8
+ return reply.redirect("/");
9
+ }
7
10
  await req.session?.destroy?.();
11
+ reply.clearCookie("session_auth");
12
+ // Shield session from resurrection
13
+ Object.defineProperty(req, "session", {
14
+ value: null,
15
+ writable: false,
16
+ configurable: false,
17
+ });
8
18
  return reply.redirect("/");
9
19
  }
10
20
  export default logout;
@@ -0,0 +1,8 @@
1
+ /**
2
+ *
3
+ * @method GET
4
+ * @summary API для перегляду поточних метрик
5
+ *
6
+ */
7
+ export default function loggerMetrics(req: any, reply: any): Promise<any>;
8
+ //# sourceMappingURL=logger.metrics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.metrics.d.ts","sourceRoot":"","sources":["../../../../../server/routes/logger/controllers/logger.metrics.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AAEH,wBAA8B,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,gBAkB/D"}
@@ -0,0 +1,23 @@
1
+ import checkUserAccess from "../../../plugins/logger/checkUserAccess.js";
2
+ import loggerSystem from "../../../plugins/metric/loggerSystem.js";
3
+ /**
4
+ *
5
+ * @method GET
6
+ * @summary API для перегляду поточних метрик
7
+ *
8
+ */
9
+ export default async function loggerMetrics(req, reply) {
10
+ const { pg, user = {}, query = {} } = req;
11
+ const access = checkUserAccess({ user, token: query.token });
12
+ if (access?.status !== 200) {
13
+ return reply.status(access.status).send(access.message);
14
+ }
15
+ const system = await loggerSystem();
16
+ const dbName = pg?.options?.database;
17
+ return {
18
+ dbname: dbName,
19
+ ...system.metric,
20
+ uptime: system.uptime,
21
+ ...system.metricSort,
22
+ };
23
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/routes/logger/index.ts"],"names":[],"mappings":"AAiBA,iBAAS,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,GAAE,GAAQ,QAMtC;AAED,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/routes/logger/index.ts"],"names":[],"mappings":"AAkBA,iBAAS,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,GAAE,GAAQ,QAWtC;AAED,eAAe,MAAM,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import loggerFile from "./controllers/logger.file.js";
2
+ import loggerMetrics from "./controllers/logger.metrics.js";
2
3
  // import loggerTest from './controllers/logger.test.api.js';
3
4
  const loggerSchema = {
4
5
  querystring: {
@@ -14,5 +15,6 @@ const loggerSchema = {
14
15
  };
15
16
  function plugin(app, opt = {}) {
16
17
  app.get("/logger-file/*", { config: { policy: "L0", rateLimit: false }, schema: loggerSchema }, loggerFile);
18
+ app.get("/logger-metrics", { config: { policy: "L0", rateLimit: false }, schema: {} }, loggerMetrics);
17
19
  }
18
20
  export default plugin;
@@ -1 +1 @@
1
- {"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/controllers/search.ts"],"names":[],"mappings":"AAmHA,wBAA8B,MAAM,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAU,EAAE,EAAE,GAAG;;;;;;GAoClE"}
1
+ {"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/controllers/search.ts"],"names":[],"mappings":"AA6HA,wBAA8B,MAAM,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAU,EAAE,EAAE,GAAG;;;;;;GAoClE"}
@@ -27,16 +27,20 @@ async function getData({ pg, tableName, query = {}, maxLimit, res }) {
27
27
  ? `(${meta?.search
28
28
  .concat(meta?.title ? `,${meta?.title}` : "")
29
29
  .split(",")
30
- .map((el) => `${el} ilike '%${query.key}%'`)
30
+ .map((el) => `${el}::text ilike '%${query.key}%'`)
31
31
  .join(" or ")})`
32
32
  : "false";
33
33
  const where = [!pk ? "false" : "true", loadTable.query, search1].filter(Boolean);
34
+ const sqlTable = loadTable.sql
35
+ ?.filter?.((el) => !el?.disabled)
36
+ ?.map((el, i) => ` left join lateral (${el.sql}) ${el.name || `t${i}`} on 1=1 `)
37
+ ?.join?.("") || "";
34
38
  const q = `select ${[
35
39
  `"${pk}" as id`,
36
40
  meta?.title ? `${meta.title} as title` : "",
37
41
  ]
38
42
  .filter((el) => el)
39
- .join(",")} from ${table} t where ${where.join(" and ") || "true"} ${order} ${offset} limit ${limit}`;
43
+ .join(",")} from ${table} t ${sqlTable} where ${where.join(" and ") || "true"} ${order} ${offset} limit ${limit}`;
40
44
  if (query.sql) {
41
45
  res.sql.push(q);
42
46
  return null;
@@ -44,7 +48,7 @@ async function getData({ pg, tableName, query = {}, maxLimit, res }) {
44
48
  const rows = await pg.query(q).then((el) => el.rows || []);
45
49
  const filtered = pg.queryCache
46
50
  ? await pg
47
- .queryCache(`select count(*) from ${table} t where ${where.join(" and ") || "true"}`)
51
+ .queryCache(`select count(*) from ${table} t ${sqlTable} where ${where.join(" and ") || "true"}`)
48
52
  .then((el) => +(el?.rows[0]?.count || 0))
49
53
  : 0;
50
54
  const total = pg.queryCache
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "2.0.69",
3
+ "version": "2.0.71",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [