@opengis/fastify-table 2.0.142 → 2.0.144

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.
@@ -59,7 +59,7 @@ export default async function dataDelete({ table: table1, tokenData, referer, id
59
59
  type: "DELETE",
60
60
  });
61
61
  if (config.redis) {
62
- rclient.incr(`pg:${table}:crud`);
62
+ rclient.incr(`pg:${client.options?.database}:${table}:crud`);
63
63
  }
64
64
  if (!isClient) {
65
65
  await client.query("commit;");
@@ -106,7 +106,7 @@ export default async function dataInsert({ id, table: table1, referer, data, pg:
106
106
  type: "INSERT",
107
107
  });
108
108
  if (config.redis && rclient?.status !== "end") {
109
- rclient.incr(`pg:${table}:crud`);
109
+ rclient.incr(`pg:${client.options?.database}:${table}:crud`);
110
110
  }
111
111
  if (!isClient) {
112
112
  await client.query("commit;");
@@ -172,7 +172,7 @@ export default async function dataUpdate({ table: table1, tokenData, referer, id
172
172
  type: "UPDATE",
173
173
  });
174
174
  if (config.redis && rclient?.status !== "end") {
175
- rclient.incr(`pg:${table}:crud`);
175
+ rclient.incr(`pg:${client.options?.database}:${table}:crud`);
176
176
  }
177
177
  if (!isClient) {
178
178
  await client.query("commit;");
@@ -120,7 +120,7 @@ export default async function dataUpsert({ id, table: table1, referer, data, pg:
120
120
  type: "UPSERT",
121
121
  });
122
122
  if (config.redis) {
123
- rclient.incr(`pg:${table}:crud`);
123
+ rclient.incr(`pg:${client.options?.database}:${table}:crud`);
124
124
  }
125
125
  if (!isClient) {
126
126
  await client.query("commit;");
@@ -145,11 +145,11 @@ async function init(client) {
145
145
  return data;
146
146
  }
147
147
  // CRUD table state
148
- const keyCacheTable = `pg:${table}:crud`;
148
+ const keyCacheTable = `pg:${client?.database}:${table}:crud`;
149
149
  const crudInc = table && config.redis ? (await rclient.get(keyCacheTable)) || 0 : 0;
150
150
  //
151
151
  const hash = createHash("sha1")
152
- .update([q, JSON.stringify(args)].join())
152
+ .update([q, client?.database, JSON.stringify(args)].join())
153
153
  .digest("base64");
154
154
  const keyCache = `pg:${hash}:${crudInc}`;
155
155
  const cacheData = config.redis ? await rclient.get(keyCache) : null;
@@ -1 +1 @@
1
- {"version":3,"file":"getSelectVal.d.ts","sourceRoot":"","sources":["../../../../../../server/plugins/table/funcs/metaFormat/getSelectVal.ts"],"names":[],"mappings":"AAaA,wBAA8B,YAAY,CAAC,EACzC,EAAqB,EACrB,IAAI,EACJ,MAAM,EAAE,YAAY,EACpB,EAAU,GACX,EAAE,GAAG,gBA6GL"}
1
+ {"version":3,"file":"getSelectVal.d.ts","sourceRoot":"","sources":["../../../../../../server/plugins/table/funcs/metaFormat/getSelectVal.ts"],"names":[],"mappings":"AAaA,wBAA8B,YAAY,CAAC,EACzC,EAAqB,EACrB,IAAI,EACJ,MAAM,EAAE,YAAY,EACpB,EAAU,GACX,EAAE,GAAG,gBA+GL"}
@@ -38,7 +38,9 @@ export default async function getSelectVal({ pg = pgClients.client, name, values
38
38
  ?.split?.(" from ")
39
39
  ?.filter?.((el) => /^[a-z0-9_]+\.[a-z0-9_]+/.test(el))
40
40
  ?.map?.((el) => el.split(/[ )]/)[0])?.[0];
41
- const crudInc = table && config.redis ? (await rclient.get(`pg:${table}:crud`)) || 0 : 0;
41
+ const crudInc = table && config.redis
42
+ ? (await rclient.get(`pg:${pg.options?.database}:${table}:crud`)) || 0
43
+ : 0;
42
44
  const key = `select:${name}:${crudInc}`;
43
45
  const cache = values?.length && config.redis && !config.disableCache
44
46
  ? (await rclient.hmget(key, values)).reduce((p, el, i) => ({
@@ -1 +1 @@
1
- {"version":3,"file":"authorize.d.ts","sourceRoot":"","sources":["../../../../../../server/routes/auth/controllers/jwt/authorize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAwBvC,wBAA8B,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,YAAY,kBA4GpE"}
1
+ {"version":3,"file":"authorize.d.ts","sourceRoot":"","sources":["../../../../../../server/routes/auth/controllers/jwt/authorize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAyBvC,wBAA8B,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,YAAY,kBA4GpE"}
@@ -1,3 +1,4 @@
1
+ import config from "../../../../../config.js";
1
2
  import pgClients from "../../../../plugins/pg/pgClients.js";
2
3
  import dataInsert from "../../../../plugins/crud/funcs/dataInsert.js";
3
4
  import { sign, scryptHash } from "../../../../plugins/auth/funcs/jwt.js";
@@ -9,7 +10,7 @@ const getIp = (req) => (req.headers?.["x-real-ip"] ||
9
10
  "")
10
11
  .split(":")
11
12
  .pop();
12
- const expireMsec = 1000 * 60 * 60;
13
+ const expireMsec = +(config.auth?.oauthTokenExpireMs || 1000 * 60 * 60);
13
14
  // ? Request example: http://localhost:3000/oauth/authorize?response_type=code&client_id=2835134164020233999&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Foauth%2Ftoken%3Fclient_id%3D2835134164020233999%26noredirect%3D1%26grant_type%3Dauthorization_code
14
15
  // ? add &noredirect=1 to retrieve code via GET request or simply send POST requests
15
16
  export default async function authorize(req, reply) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/routes/file/index.ts"],"names":[],"mappings":"AAWA,iBAAS,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,GAAE,GAAQ,QAuBtC;AAED,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/routes/file/index.ts"],"names":[],"mappings":"AAaA,iBAAS,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,GAAE,GAAQ,QA8BtC;AAED,eAAe,MAAM,CAAC"}
@@ -1,3 +1,4 @@
1
+ import config from "../../../config.js";
1
2
  import files from "./controllers/files.js";
2
3
  import resize from "./controllers/resize.js";
3
4
  import resizeAll from "./controllers/resizeAll.js";
@@ -8,15 +9,26 @@ import uploadImage from "./controllers/uploadImage.js";
8
9
  import deleteFileAPI from "./controllers/delete.js";
9
10
  import { resizeSchema } from "./schema.js";
10
11
  function plugin(app, opt = {}) {
11
- app.get("/files/*", { config: { policy: ["public"] } }, files);
12
- if (!app.hasRoute({ method: 'GET', url: '/file/resize', })) {
13
- app.get("/file/resize", { config: { policy: ["public"] }, schema: resizeSchema }, resize);
12
+ app.get("/files/*", { config: { policy: "L0" } }, files);
13
+ if (!app.hasRoute({ method: "GET", url: "/file/resize" })) {
14
+ app.get("/file/resize", {
15
+ config: {
16
+ policy: "L0",
17
+ rateLimit: config.rateLimit
18
+ ? {
19
+ max: +(config.rateLimit?.resize?.max || 1),
20
+ timeWindow: config.rateLimit?.resize?.timeWindow || "1 minute",
21
+ }
22
+ : undefined,
23
+ },
24
+ schema: resizeSchema,
25
+ }, resize);
14
26
  }
15
27
  app.get("/api/resize-all", { config: { policy: ["admin", "site"] }, schema: resizeSchema }, resizeAll);
16
- app.post("/file/upload/*", { config: { policy: ["public"] } }, upload);
17
- app.post("/file/upload-image/*", { config: { policy: ["public"] } }, uploadImage);
18
- app.get("/file/download/*", { config: { policy: ["public"] } }, download);
19
- app.get("/file/delete/*", { config: { policy: ["public"] } }, deleteFileAPI);
20
- app.get(`/api/export`, { config: { policy: ["public"] } }, exportTable);
28
+ app.post("/file/upload/*", { config: { policy: "L0" } }, upload);
29
+ app.post("/file/upload-image/*", { config: { policy: "L0" } }, uploadImage);
30
+ app.get("/file/download/*", { config: { policy: "L0" } }, download);
31
+ app.get("/file/delete/*", { config: { policy: "L0" } }, deleteFileAPI);
32
+ app.get(`/api/export`, { config: { policy: "L0" } }, exportTable);
21
33
  }
22
34
  export default plugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "2.0.142",
3
+ "version": "2.0.144",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [