@opengis/fastify-table 2.5.34 → 2.5.36

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":"inspectContent.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/file/utils/inspectContent.ts"],"names":[],"mappings":"AAwCA,wBAA8B,cAAc,CAC1C,MAAM,EAAE,MAAM,EACd,iBAAiB,EAAE,MAAM;;;;GA+B1B"}
1
+ {"version":3,"file":"inspectContent.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/file/utils/inspectContent.ts"],"names":[],"mappings":"AA+CA,wBAA8B,cAAc,CAC1C,MAAM,EAAE,MAAM,EACd,iBAAiB,EAAE,MAAM;;;;GAwC1B"}
@@ -1,6 +1,12 @@
1
1
  import { fileTypeFromBuffer } from "file-type";
2
2
  import { BadRequestError } from "../../../../errors.js";
3
3
  import applyHook from "../../hook/applyHook.js";
4
+ // Office 97–2003 (.doc/.xls/.ppt) share CFB magic; file-type reports them as "cfb"
5
+ const cfbOfficeMimes = {
6
+ doc: "application/msword",
7
+ xls: "application/vnd.ms-excel",
8
+ ppt: "application/vnd.ms-powerpoint",
9
+ };
4
10
  const handlers = {
5
11
  pdf: (buffer) => {
6
12
  const head = buffer.subarray(0, 1024).toString("latin1");
@@ -53,6 +59,14 @@ export default async function inspectContent(buffer, expectedExtension) {
53
59
  const { ext: ext2, mime: mime2 } = (await handlers[expectedExtension](buffer)) || {};
54
60
  return { ext: ext2, mime: mime2, isValid: ext2 === expectedExtension };
55
61
  }
62
+ // ? .doc/.xls/.ppt are CFB containers — file-type returns "cfb", not the office ext
63
+ if (ext === "cfb" && cfbOfficeMimes[expectedExtension]) {
64
+ return {
65
+ ext: expectedExtension,
66
+ mime: cfbOfficeMimes[expectedExtension],
67
+ isValid: true,
68
+ };
69
+ }
56
70
  // ? simple xml, pdf are recognized via file-type
57
71
  return { ext, mime, isValid: ext === expectedExtension };
58
72
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/plugins/logger/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAgC,MAAM,SAAS,CAAC;AAqE7E,iBAAS,YAAY,CAAC,OAAO,EAAE,eAAe,QA+C7C;AACD,eAAe,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/plugins/logger/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAgC,MAAM,SAAS,CAAC;AAqE7E,iBAAS,YAAY,CAAC,OAAO,EAAE,eAAe,QAmD7C;AACD,eAAe,YAAY,CAAC"}
@@ -71,7 +71,9 @@ function loggerPlugin(fastify) {
71
71
  if (error.statusCode && logWarningCodes.includes(error.statusCode)) {
72
72
  logger.warn(error, request);
73
73
  }
74
- if (process.env.trace === "true") {
74
+ if (process.env.trace === "true" ||
75
+ process.env.NODE_ENV === "test" ||
76
+ process.env.VITEST) {
75
77
  console.error({
76
78
  msg: error.message,
77
79
  where: error.where,
@@ -1 +1 @@
1
- {"version":3,"file":"getMeta.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/pg/funcs/getMeta.ts"],"names":[],"mappings":"AAMA,wBAA8B,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,GAAG,gBAmG5D"}
1
+ {"version":3,"file":"getMeta.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/pg/funcs/getMeta.ts"],"names":[],"mappings":"AAMA,wBAA8B,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,GAAG,gBA0G5D"}
@@ -11,8 +11,11 @@ export default async function getMeta(opt, nocache) {
11
11
  if (!pg.pk || nocache) {
12
12
  await init(pg);
13
13
  }
14
- const tableOriginal = opt?.table || opt;
15
- const [schemaName, tableName] = tableOriginal?.replace?.(/"/g, "").split(".");
14
+ const tableOriginal = opt?.table || (typeof opt === "string" ? opt : undefined);
15
+ if (!tableOriginal) {
16
+ throw BadRequestError("not enough params: table");
17
+ }
18
+ const [schemaName, tableName] = tableOriginal?.replace?.(/"/g, "")?.split?.(".") || [];
16
19
  const tableSafe = `${schemaName}."${tableName}"`;
17
20
  const tableUnsafe = `${schemaName}.${tableName}`;
18
21
  if (pg?.options?.database &&
@@ -1 +1 @@
1
- {"version":3,"file":"suggest.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/controllers/suggest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AA8BpD,wBAAsB,kBAAkB,CAAC,EACvC,KAAK,EACL,QAAQ,EACR,MAAM,EACN,UAAU,EACV,QAAQ,EACR,UAAU,EACV,GAAG,EACH,EAAqB,GACtB,EAAE;IACD,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,GAAG,CAAC;IACZ,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,EAAE,CAAC,EAAE,UAAU,CAAC;CACjB;;;;;UAwFA;AAED,wBAA8B,OAAO,CAAC,GAAG,EAAE,GAAG,gBAuc7C"}
1
+ {"version":3,"file":"suggest.d.ts","sourceRoot":"","sources":["../../../../../server/routes/table/controllers/suggest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AA8BpD,wBAAsB,kBAAkB,CAAC,EACvC,KAAK,EACL,QAAQ,EACR,MAAM,EACN,UAAU,EACV,QAAQ,EACR,UAAU,EACV,GAAG,EACH,EAAqB,GACtB,EAAE;IACD,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,GAAG,CAAC;IACZ,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,EAAE,CAAC,EAAE,UAAU,CAAC;CACjB;;;;;UAwFA;AAED,wBAA8B,OAAO,CAAC,GAAG,EAAE,GAAG,gBAod7C"}
@@ -139,6 +139,9 @@ export default async function suggest(req) {
139
139
  };
140
140
  }
141
141
  const body = await getTemplate("table", table);
142
+ if (table && !hookBody?.table && !body?.table) {
143
+ throw ForbiddenError("invalid params: table");
144
+ }
142
145
  const tableName = hookBody?.table || body?.table || table;
143
146
  if (query.limit && query.limit < 0) {
144
147
  throw BadRequestError("param limit is invalid");
@@ -171,6 +174,12 @@ export default async function suggest(req) {
171
174
  }
172
175
  const limit = meta?.limit || defaultLimit;
173
176
  const pg = meta?.db ? await getPGAsync(meta.db) : pg1;
177
+ const filters = table
178
+ ? await getFilter({ pg, table }).then((r) => r.list || [])
179
+ : [];
180
+ if (table && column && !filters.find((el) => el.name === column)) {
181
+ throw ForbiddenError("invalid params: column");
182
+ }
174
183
  if (!pg || !pg.pk || !pg.pgType) {
175
184
  throw Error("empty pg");
176
185
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "2.5.34",
3
+ "version": "2.5.36",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [