@opengis/fastify-table 2.0.8 → 2.0.10

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/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import fp from 'fastify-plugin';
1
2
  import path from "node:path";
2
3
  import { existsSync, readdirSync, readFileSync } from "node:fs";
3
4
  import { fileURLToPath } from "node:url";
@@ -37,7 +38,7 @@ import authRoutes from "./server/routes/auth/index.js";
37
38
  // core templates && cls
38
39
  const filename = fileURLToPath(import.meta.url);
39
40
  const cwd = path.dirname(filename);
40
- async function plugin(fastify) {
41
+ function plugin(fastify) {
41
42
  const opt = { prefix: '/api' };
42
43
  // fastify.register(import('@fastify/sensible'), {
43
44
  // errorHandler: false,
@@ -79,15 +80,15 @@ async function plugin(fastify) {
79
80
  addTemplateDir(path.join(cwd, "module/core"));
80
81
  // plugins / utils / funcs
81
82
  policyPlugin(fastify);
82
- await authPlugin(fastify); // fastify-auth api + hooks integrated to core
83
+ authPlugin(fastify); // fastify-auth api + hooks integrated to core
83
84
  metricPlugin();
84
85
  redisPlugin(fastify);
85
- await pgPlugin(fastify);
86
- await sqlitePlugin(fastify);
86
+ pgPlugin(fastify);
87
+ sqlitePlugin(fastify);
87
88
  cronPlugin();
88
89
  loggerPlugin(fastify);
89
90
  if (config.rateLimit !== false) {
90
- await fastify.register(import("@fastify/rate-limit"), {
91
+ fastify.register(import("@fastify/rate-limit"), {
91
92
  max: parseInt(config.rateLimit?.max || 100),
92
93
  timeWindow: config.rateLimit?.timeWindow || 60000,
93
94
  hook: "preHandler",
@@ -111,7 +112,7 @@ async function plugin(fastify) {
111
112
  fastify.register(templatesRoutes, opt);
112
113
  fastify.register(authRoutes); // from fastify-auth
113
114
  // from fastify-file
114
- await fastify.register(import("@fastify/multipart"), {
115
+ fastify.register(import("@fastify/multipart"), {
115
116
  limits: {
116
117
  fileSize: maxFileSize * 1024 * 1024,
117
118
  },
@@ -163,4 +164,4 @@ async function plugin(fastify) {
163
164
  }
164
165
  });
165
166
  }
166
- export default plugin;
167
+ export default fp(plugin);
@@ -7,22 +7,22 @@ import config from "../../../config.js";
7
7
  import getRedis from "../redis/funcs/getRedis.js";
8
8
  const fastifyPassport = new Authenticator();
9
9
  const { prefix = "/api" } = config;
10
- async function plugin(fastify) {
10
+ function plugin(fastify) {
11
11
  if (!config.redis) {
12
12
  return;
13
13
  }
14
- await fastify.register(cookie, {
14
+ fastify.register(cookie, {
15
15
  parseOptions: config?.auth?.cookieOptions || { secure: false },
16
16
  });
17
- await fastify.register(session, {
17
+ fastify.register(session, {
18
18
  secret: config?.auth?.secret || "61b820e12858570a4b0633020d4394a17903d9a9",
19
19
  cookieName: "session_auth",
20
20
  cookie: config?.auth?.cookieOptions || { secure: false },
21
21
  store: new RedisStore({ client: getRedis({ db: 10 }) }),
22
22
  });
23
23
  // register passport AFTER session is ready
24
- await fastify.register(fastifyPassport.initialize());
25
- await fastify.register(fastifyPassport.secureSession());
24
+ fastify.register(fastifyPassport.initialize());
25
+ fastify.register(fastifyPassport.secureSession());
26
26
  // serialize user used to store user info in session store
27
27
  fastifyPassport.registerUserSerializer(async (user) => ({ user }));
28
28
  // deserialize user used to add user info from session store to req
@@ -1,7 +1,39 @@
1
- // import addHook from './funcs/addHook.js';
2
- // import applyHook from './funcs/applyHook.js';
3
- async function plugin() {
4
- // fastify.decorate('addHook', addHook);
5
- // fastify.decorate('applyHook', applyHook);
1
+ import config from "../../../config.js";
2
+ export const hookList = {};
3
+ export async function applyHook(name, data) {
4
+ if (config.trace)
5
+ console.log("applyHook", name);
6
+ if (!hookList[name]?.length)
7
+ return null;
8
+ const result = {};
9
+ await Promise.all(hookList[name].map(async (hook) => {
10
+ const hookData = await hook({ ...data, config });
11
+ if (hookData) {
12
+ if (config.trace)
13
+ console.log("applyHook", name, hookData);
14
+ Object.assign(result, hookData);
15
+ }
16
+ })).catch((err) => {
17
+ console.error("applyHook", name, err.toString());
18
+ });
19
+ if (Object.keys(result).length) {
20
+ return result;
21
+ }
22
+ return null;
23
+ }
24
+ export function addHook(name, fn) {
25
+ if (!hookList[name]) {
26
+ hookList[name] = [];
27
+ }
28
+ if (config.trace)
29
+ console.log("addHook", name);
30
+ hookList[name].push(fn);
31
+ }
32
+ export function applyHookSync(name, data) {
33
+ if (!hookList[name]?.length)
34
+ return null;
35
+ if (config.trace)
36
+ console.log("applyHookSync", name);
37
+ const hookData = hookList[name].map((hook) => hook(data))[0];
38
+ return hookData;
6
39
  }
7
- export default plugin;
@@ -22,10 +22,10 @@ async function getHeadersPG(req) {
22
22
  }
23
23
  return null;
24
24
  }
25
- async function plugin(fastify) {
26
- const client = await getPGAsync({ ...(config.pg || {}), name: "client" });
25
+ function plugin(fastify) {
27
26
  fastify.addHook("onRequest", async (req) => {
28
27
  const headersPG = await getHeadersPG(req);
28
+ const client = await getPGAsync({ ...(config.pg || {}), name: "client" });
29
29
  req.pg = headersPG || req.pg || client || pgClients.client;
30
30
  if (headersPG) {
31
31
  req.user = { uid: req.headers?.uid };
@@ -1,3 +1,4 @@
1
+ import config from "../../../config.js";
1
2
  // login-password
2
3
  import login from "./controllers/core/login.js";
3
4
  import registration from "./controllers/core/registration.js";
@@ -19,7 +20,7 @@ import oauthAuthorize from "./controllers/jwt/authorize.js";
19
20
  import oauthToken from "./controllers/jwt/token.js";
20
21
  const params = { config: { policy: "L0" } };
21
22
  async function plugin(app, opt = {}) {
22
- if (opt.routes === false) {
23
+ if (opt.routes === false || config.auth?.customRoutes) {
23
24
  return;
24
25
  }
25
26
  if (!app.hasRoute({ method: "GET", url: "/logout" })) {
@@ -66,19 +67,18 @@ async function plugin(app, opt = {}) {
66
67
  }
67
68
  // euSign
68
69
  if (!app.hasRoute({ method: "GET", url: "/auth/by_data" }) &&
69
- !opt.auth?.customRoutes &&
70
- !opt.auth?.customGovId) {
70
+ !config.auth?.customGovId) {
71
71
  app.get("/auth/by_data", params, authByData);
72
72
  }
73
73
  // pages
74
74
  if (!app.hasRoute({ method: "GET", url: "/2factor" }) &&
75
- !opt.auth?.disable &&
76
- !opt.auth?.login2factorPage) {
75
+ !config.auth?.disable &&
76
+ !config.auth?.login2factorPage) {
77
77
  app.get("/2factor", params, login2faTemplate);
78
78
  }
79
79
  if (!app.hasRoute({ method: "GET", url: "/login" }) &&
80
- !opt.auth?.disable &&
81
- !opt?.auth?.loginPage) {
80
+ !config.auth?.disable &&
81
+ !config?.auth?.loginPage) {
82
82
  app.get("/login", params, loginTemplate);
83
83
  }
84
84
  }
package/package.json CHANGED
@@ -1,88 +1,88 @@
1
- {
2
- "name": "@opengis/fastify-table",
3
- "version": "2.0.8",
4
- "type": "module",
5
- "description": "core-plugins",
6
- "keywords": [
7
- "fastify",
8
- "table",
9
- "crud",
10
- "auth",
11
- "pg",
12
- "backend"
13
- ],
14
- "main": "dist/index.js",
15
- "exports": {
16
- ".": "./dist/index.js",
17
- "./index.js": "./dist/index.js",
18
- "./utils.js": "./dist/utils.js"
19
- },
20
- "files": [
21
- "dist/*"
22
- ],
23
- "scripts": {
24
- "prepublishOnly": "npm run build",
25
- "clean": "tsc -b --clean",
26
- "build": "tsc -b --clean && tsc && copyfiles server/plugins/grpc/utils/*.proto dist && copyfiles server/migrations/*.sql dist && copyfiles server/templates/**/*.html dist",
27
- "prod": "NODE_ENV=production bun dist/server",
28
- "patch": "npm version patch && git push && npm publish",
29
- "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
30
- "test": "bun test",
31
- "compress": "node compress.js",
32
- "dev1": "bun --hot dist/server",
33
- "dev": "NODE_ENV=production bun start",
34
- "start": "bun server"
35
- },
36
- "dependencies": {
37
- "@aws-sdk/client-s3": "3.879.0",
38
- "@aws-sdk/lib-storage": "3.879.0",
39
- "@fastify/cookie": "11.0.2",
40
- "@fastify/http-proxy": "11.1.2",
41
- "@fastify/multipart": "9.0.3",
42
- "@fastify/passport": "3.0.2",
43
- "@fastify/rate-limit": "10.3.0",
44
- "@fastify/session": "11.1.0",
45
- "@grpc/grpc-js": "1.10.11",
46
- "@grpc/proto-loader": "0.7.15",
47
- "apache-crypt": "1.2.6",
48
- "better-sqlite3": "12.2.0",
49
- "dotenv": "16.5.0",
50
- "fastify": "5.3.3",
51
- "fastify-plugin": "5.0.1",
52
- "fastify-session-redis-store": "7.1.2",
53
- "handlebars": "4.7.8",
54
- "image-size": "1.2.0",
55
- "ioredis": "5.3.2",
56
- "js-yaml": "4.1.0",
57
- "markdown-it": "14.1.0",
58
- "nodemailer": "7.0.6",
59
- "otplib": "12.0.1",
60
- "pg": "8.11.6",
61
- "pino": "9.5.0",
62
- "pino-abstract-transport": "2.0.0",
63
- "promised-handlebars": "2.0.1",
64
- "qrcode": "1.5.4",
65
- "uglify-js": "3.19.3",
66
- "undici": "7.16.0"
67
- },
68
- "devDependencies": {
69
- "@types/better-sqlite3": "^7.6.13",
70
- "@types/bun": "^1.2.21",
71
- "@types/js-yaml": "^4.0.9",
72
- "@types/markdown-it": "^14.1.2",
73
- "@types/node": "^24.3.1",
74
- "@types/nodemailer": "^7.0.1",
75
- "@types/passport": "^1.0.17",
76
- "@types/passport-local": "^1.0.38",
77
- "@types/pg": "^8.15.5",
78
- "@types/qrcode": "^1.5.5",
79
- "copyfiles": "^2.4.1",
80
- "eslint": "^9.35.0",
81
- "eslint-config-airbnb-extended": "^2.3.1",
82
- "ts-migrate": "^0.1.35",
83
- "typescript": "^5.9.2",
84
- "vitest": "^3.2.4"
85
- },
86
- "author": "Softpro",
87
- "license": "ISC"
88
- }
1
+ {
2
+ "name": "@opengis/fastify-table",
3
+ "version": "2.0.10",
4
+ "type": "module",
5
+ "description": "core-plugins",
6
+ "keywords": [
7
+ "fastify",
8
+ "table",
9
+ "crud",
10
+ "auth",
11
+ "pg",
12
+ "backend"
13
+ ],
14
+ "main": "dist/index.js",
15
+ "exports": {
16
+ ".": "./dist/index.js",
17
+ "./index.js": "./dist/index.js",
18
+ "./utils.js": "./dist/utils.js"
19
+ },
20
+ "files": [
21
+ "dist/*"
22
+ ],
23
+ "scripts": {
24
+ "prepublishOnly": "npm run build",
25
+ "clean": "tsc -b --clean",
26
+ "build": "tsc -b --clean && tsc && copyfiles server/plugins/grpc/utils/*.proto dist && copyfiles server/migrations/*.sql dist && copyfiles server/templates/**/*.html dist",
27
+ "prod": "NODE_ENV=production bun dist/server",
28
+ "patch": "npm version patch && git push && npm publish",
29
+ "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
30
+ "test": "bun test",
31
+ "compress": "node compress.js",
32
+ "dev1": "bun --hot dist/server",
33
+ "dev": "NODE_ENV=production bun start",
34
+ "start": "bun server"
35
+ },
36
+ "dependencies": {
37
+ "@aws-sdk/client-s3": "3.879.0",
38
+ "@aws-sdk/lib-storage": "3.879.0",
39
+ "@fastify/cookie": "11.0.2",
40
+ "@fastify/http-proxy": "11.1.2",
41
+ "@fastify/multipart": "9.0.3",
42
+ "@fastify/passport": "3.0.2",
43
+ "@fastify/rate-limit": "10.3.0",
44
+ "@fastify/session": "11.1.0",
45
+ "@grpc/grpc-js": "1.10.11",
46
+ "@grpc/proto-loader": "0.7.15",
47
+ "apache-crypt": "1.2.6",
48
+ "better-sqlite3": "12.2.0",
49
+ "dotenv": "16.5.0",
50
+ "fastify": "5.3.3",
51
+ "fastify-plugin": "5.0.1",
52
+ "fastify-session-redis-store": "7.1.2",
53
+ "handlebars": "4.7.8",
54
+ "image-size": "1.2.0",
55
+ "ioredis": "5.3.2",
56
+ "js-yaml": "4.1.0",
57
+ "markdown-it": "14.1.0",
58
+ "nodemailer": "7.0.6",
59
+ "otplib": "12.0.1",
60
+ "pg": "8.11.6",
61
+ "pino": "9.5.0",
62
+ "pino-abstract-transport": "2.0.0",
63
+ "promised-handlebars": "2.0.1",
64
+ "qrcode": "1.5.4",
65
+ "uglify-js": "3.19.3",
66
+ "undici": "7.16.0"
67
+ },
68
+ "devDependencies": {
69
+ "@types/better-sqlite3": "^7.6.13",
70
+ "@types/bun": "^1.2.21",
71
+ "@types/js-yaml": "^4.0.9",
72
+ "@types/markdown-it": "^14.1.2",
73
+ "@types/node": "^24.3.1",
74
+ "@types/nodemailer": "^7.0.1",
75
+ "@types/passport": "^1.0.17",
76
+ "@types/passport-local": "^1.0.38",
77
+ "@types/pg": "^8.15.5",
78
+ "@types/qrcode": "^1.5.5",
79
+ "copyfiles": "^2.4.1",
80
+ "eslint": "^9.35.0",
81
+ "eslint-config-airbnb-extended": "^2.3.1",
82
+ "ts-migrate": "^0.1.35",
83
+ "typescript": "^5.9.2",
84
+ "vitest": "^3.2.4"
85
+ },
86
+ "author": "Softpro",
87
+ "license": "ISC"
88
+ }
@@ -1,137 +0,0 @@
1
- syntax = "proto3";
2
-
3
- service Convert {
4
- rpc csvToXls(csvToXlsParams) returns (FileBase64) {}
5
- rpc jsonToXls(jsonToXlsParams) returns (FileBase64) {}
6
- rpc pdfMerge(pdfMergeParams) returns (FileBase64) {}
7
- rpc htmlToPdf(htmlToPdfParams) returns (FileBase64) {}
8
- rpc excelToJson(excelToJsonParams) returns (FileBase64) {}
9
- rpc xmlToJson(xmlToJsonParams) returns (FileBase64) {}
10
- rpc htmlToDoc(htmlToDocParams) returns (FileBase64) {}
11
- rpc htmlToImage(htmlToImageParams) returns (FileBase64) {}
12
- rpc geojsonToShp(geojsonToShpParams) returns (FileBase64) {}
13
- rpc shpToGeojson(shpToGeojsonParams) returns (FileBase64) {}
14
- rpc docToPDF(docToPDFParams) returns (FileBase64) {}
15
- rpc mergeImages(mergeImagesIn) returns (FileBase64) {}
16
- rpc resizeImage(resizeImageIn) returns (FileBase64) {}
17
- rpc jsonToYaml(jsonToYamlIn) returns (FileBase64) {}
18
- rpc yamlToJson(yamlToJsonIn) returns (FileBase64) {}
19
- rpc log(log_in) returns (log_out) {}
20
- rpc geojsonToGpkg(geojsonToShpParams) returns (FileBase64) {}
21
- }
22
-
23
- message jsonToYamlIn {
24
- string json = 1;
25
- }
26
-
27
- message yamlToJsonIn {
28
- string yaml = 1;
29
- }
30
-
31
- message resizeImageIn {
32
- string base64 = 1;
33
- uint64 width = 2;
34
- uint64 height = 3;
35
- uint32 quality = 4;
36
- uint32 subsampling = 5;
37
- }
38
-
39
- message pdfToImgIn {
40
- string pdfPath = 1;
41
- string imgPath = 2;
42
- }
43
-
44
- message pdfToImgOut {
45
- string imgPath = 1;
46
- }
47
-
48
- message log_in {
49
- uint32 rows = 1;
50
- string level = 2;
51
- }
52
-
53
- message log_out {
54
- repeated string logs = 1;
55
- }
56
-
57
- enum mergeImageFormat {
58
- VERTICAL = 0;
59
- HORIZONTAL = 1;
60
- OVERLAY = 2;
61
- }
62
-
63
- message imageMeta {
64
- string base64 = 1;
65
- mergeImageFormat mergeFormat = 2;
66
- }
67
-
68
- message mergeImagesIn {
69
- repeated string images = 1;
70
- repeated imageMeta imagesMeta = 2;
71
- string background = 3;
72
- string mergeFormat = 4;
73
- }
74
-
75
- message docToPDFParams {
76
- string base64 = 1;
77
- string to = 2;
78
- string ext = 3;
79
- }
80
-
81
- message shpToGeojsonParams {
82
- string base64 = 1;
83
- }
84
-
85
- message geojsonToShpParams {
86
- string geojson = 1;
87
- string proj = 2;
88
- }
89
-
90
- message xmlToJsonParams {
91
- string xml = 1;
92
- }
93
-
94
- message jsonToXlsParams {
95
- string json = 1;
96
- string header = 2;
97
- string subheader = 3;
98
- string colmodel = 4;
99
- }
100
-
101
- message csvToXlsParams {
102
- string csv = 1;
103
- string header = 2;
104
- string subheader = 3;
105
- string separator = 4;
106
- }
107
-
108
- message excelToJsonParams {
109
- string base64 = 1;
110
- string type = 2;
111
- string delimiter = 3;
112
- string encoding = 4;
113
- }
114
-
115
- message htmlToPdfParams {
116
- string html = 1;
117
- string pdfPageConfig = 2;
118
- }
119
-
120
- message pdfMergeParams {
121
- repeated string mergeFiles = 1;
122
- }
123
-
124
- message htmlToImageParams {
125
- string html = 1;
126
- string format = 2;
127
- uint64 width = 3;
128
- uint64 height = 4;
129
- }
130
-
131
- message htmlToDocParams {
132
- string html = 1;
133
- }
134
-
135
- message FileBase64 {
136
- string result = 1;
137
- }
@@ -1,14 +0,0 @@
1
- syntax = "proto3";
2
-
3
- service OfficeConverterService {
4
- rpc OfficeToPdf(OfficeToPdfRequest) returns (OfficeToPdfResponse) {}
5
- }
6
-
7
- message OfficeToPdfRequest {
8
- string file = 1;
9
- string ext = 2;
10
- }
11
-
12
- message OfficeToPdfResponse {
13
- string file = 1;
14
- }
@@ -1,7 +0,0 @@
1
- import hookList from "../hookList.js";
2
- export default function addHook(name, fn) {
3
- if (!hookList[name]) {
4
- hookList[name] = [];
5
- }
6
- hookList[name].push(fn);
7
- }
@@ -1,25 +0,0 @@
1
- /* eslint-disable no-console */
2
- import config from "../../../../config.js";
3
- import hookList from "../hookList.js";
4
- export default async function applyHook(name, data) {
5
- const { trace } = config;
6
- if (trace)
7
- console.log("applyHook", name);
8
- if (!hookList[name]?.length)
9
- return null;
10
- const result = {};
11
- await Promise.all(hookList[name].map(async (hook) => {
12
- const hookData = await hook({ ...data, config });
13
- if (hookData) {
14
- if (trace)
15
- console.log("applyHook", name, hookData);
16
- Object.assign(result, hookData);
17
- }
18
- })).catch((err) => {
19
- console.error("applyHook", name, err.toString());
20
- });
21
- if (Object.keys(result).length) {
22
- return result;
23
- }
24
- return null;
25
- }
@@ -1,7 +0,0 @@
1
- import hookList from "../hookList.js";
2
- export default function applyHookSync(name, data) {
3
- if (!hookList[name]?.length)
4
- return null;
5
- const hookData = hookList[name].map((hook) => hook(data))[0];
6
- return hookData;
7
- }