@opengis/fastify-table 2.0.93 → 2.0.95
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.d.ts.map +1 -1
- package/dist/index.js +36 -0
- package/dist/server/plugins/auth/funcs/authorizeUser.js +1 -1
- package/dist/server/plugins/auth/funcs/logAuth.d.ts.map +1 -1
- package/dist/server/plugins/auth/index.d.ts.map +1 -1
- package/dist/server/plugins/auth/index.js +1 -2
- package/dist/server/plugins/table/funcs/metaFormat/index.d.ts.map +1 -1
- package/dist/server/plugins/table/funcs/metaFormat/index.js +5 -1
- package/dist/server/plugins/util/funcs/routeOptions.d.ts +3 -0
- package/dist/server/plugins/util/funcs/routeOptions.d.ts.map +1 -0
- package/dist/server/plugins/util/funcs/routeOptions.js +2 -0
- package/dist/server/routes/auth/controllers/2factor/providers/totp.d.ts.map +1 -1
- package/dist/server/routes/auth/controllers/2factor/providers/totp.js +12 -1
- package/dist/server/routes/crud/index.d.ts.map +1 -1
- package/dist/server/routes/crud/index.js +7 -4
- package/package.json +1 -1
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAsFA,iBAAS,MAAM,CAAC,OAAO,EAAE,GAAG,QA0J3B;;AACD,wBAA0B"}
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,16 @@ import { preForm, afterInsert, afterTable, afterTemplate, afterUpdate, preTempla
|
|
|
7
7
|
import addHook from "./server/plugins/hook/addHook.js";
|
|
8
8
|
const { maxFileSize = 512 } = config;
|
|
9
9
|
const { name: execName } = path.parse(process.argv0);
|
|
10
|
+
const routes = [];
|
|
11
|
+
const policyCls = {
|
|
12
|
+
public: "Public", // old policy support
|
|
13
|
+
user: "User", // old policy support
|
|
14
|
+
site: "Public", // old policy support
|
|
15
|
+
L0: "Public",
|
|
16
|
+
L1: "User",
|
|
17
|
+
L2: "User",
|
|
18
|
+
L3: "User",
|
|
19
|
+
};
|
|
10
20
|
// helpers
|
|
11
21
|
// import helperPlugin from './server/helpers/index.js';
|
|
12
22
|
// plugins
|
|
@@ -53,6 +63,32 @@ function plugin(fastify) {
|
|
|
53
63
|
reply.header("Access-Control-Allow-Origin", "*");
|
|
54
64
|
});
|
|
55
65
|
}
|
|
66
|
+
if (!fastify.hasRoute({ method: "GET", url: "/api/list" })) {
|
|
67
|
+
fastify.get(`${opt.prefix}/list`, { config: { role: "admin" } }, () => ({
|
|
68
|
+
rows: routes,
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
fastify.addHook("onRoute", (r) => {
|
|
72
|
+
if (r.method === "HEAD")
|
|
73
|
+
return;
|
|
74
|
+
const method = Array.isArray(r.method) ? "ALL" : r.method;
|
|
75
|
+
const query = r.schema?.querystring
|
|
76
|
+
? Object.keys(r.schema?.querystring?.properties || {}).reduce((acc, curr) => ({
|
|
77
|
+
...acc,
|
|
78
|
+
[curr]: r.schema?.querystring?.properties?.[curr]?.type,
|
|
79
|
+
}), {})
|
|
80
|
+
: undefined;
|
|
81
|
+
routes.push({
|
|
82
|
+
method,
|
|
83
|
+
route: r.url,
|
|
84
|
+
description: r.config?.description,
|
|
85
|
+
query,
|
|
86
|
+
roles: r.config?.role?.split?.("|"),
|
|
87
|
+
policy: (Array.isArray(r.config?.policy)
|
|
88
|
+
? r.config?.policy
|
|
89
|
+
: r.config?.policy?.split?.(","))?.map?.((name) => policyCls[name] || name),
|
|
90
|
+
});
|
|
91
|
+
});
|
|
56
92
|
fastify.addHook("onListen", onListen1);
|
|
57
93
|
fastify.addHook("onListen", onListen2);
|
|
58
94
|
fastify.addHook("onReady", onReady);
|
|
@@ -62,7 +62,7 @@ export default async function authorizeUser(user, req, authType = "creds-user",
|
|
|
62
62
|
const redirectUrl = req.headers?.referer?.match?.(/[?&]redirect=([^&]+)/)?.[1] || "/";
|
|
63
63
|
const twofaEnabled = user?.twofa && user.uid && pg;
|
|
64
64
|
const registered = false; // ? check by created/updated date?
|
|
65
|
-
if (config.auth?.oneUser
|
|
65
|
+
if (config.auth?.oneUser) {
|
|
66
66
|
const userSessionKey = `${config.pg?.database}:user:${user.uid}`;
|
|
67
67
|
const sessionID = await rclient.get(userSessionKey);
|
|
68
68
|
await rclient2.del(`session_auth:${config.pg?.database}:${sessionID}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logAuth.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/auth/funcs/logAuth.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"logAuth.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/auth/funcs/logAuth.ts"],"names":[],"mappings":"AAGA,wBAA8B,OAAO,CACnC,EACE,GAAG,EACH,IAAc,EACd,IAAI,EACJ,EAAE,GACH,EAAE;IACD,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,EACD,EAAE,MAAmB,gBAetB"}
|
|
@@ -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,
|
|
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,iBA8HxE;AAED,iBAAS,MAAM,CAAC,OAAO,EAAE,eAAe,QAgCvC;AAED,eAAe,MAAM,CAAC"}
|
|
@@ -38,8 +38,7 @@ export async function onRequest(req, reply) {
|
|
|
38
38
|
: policy === "L0";
|
|
39
39
|
if (req.cookies?.["session_auth"] &&
|
|
40
40
|
!req.session?.passport?.user?.uid &&
|
|
41
|
-
(config.auth?.disable || config.auth?.user)
|
|
42
|
-
!isPublic) {
|
|
41
|
+
(config.auth?.disable || config.auth?.user)) {
|
|
43
42
|
req.session = req.session || {};
|
|
44
43
|
req.session.passport = req.session.passport || {}; // ensure passport session exists
|
|
45
44
|
req.session.passport.user = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../server/plugins/table/funcs/metaFormat/index.ts"],"names":[],"mappings":"AAOA,wBAA8B,UAAU,CACtC,EACE,IAAI,EAAE,QAAQ,EACd,KAAK,EACL,GAAQ,EACR,KAAU,EACV,KAAY,EACZ,QAAe,GAChB,EAAE;IACD,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,EACD,EAAE,MAAmB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../server/plugins/table/funcs/metaFormat/index.ts"],"names":[],"mappings":"AAOA,wBAA8B,UAAU,CACtC,EACE,IAAI,EAAE,QAAQ,EACd,KAAK,EACL,GAAQ,EACR,KAAU,EACV,KAAY,EACZ,QAAe,GAChB,EAAE;IACD,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,EACD,EAAE,MAAmB,gBAwGtB"}
|
|
@@ -12,9 +12,13 @@ export default async function metaFormat({ rows: original, table, cls = {}, html
|
|
|
12
12
|
name: el,
|
|
13
13
|
data: loadTable?.meta?.cls[el],
|
|
14
14
|
}));
|
|
15
|
+
const actualClsObj = selectCols
|
|
16
|
+
.concat(metaCls)
|
|
17
|
+
.reduce((acc, curr) => ({ ...acc, [curr.name]: curr.data }), {});
|
|
15
18
|
const list = getTemplates(["cls", "select"]).map((el) => el[0]);
|
|
16
19
|
const columnNameAsCls = Object.keys(original?.[0] || {})
|
|
17
|
-
.filter((key) =>
|
|
20
|
+
.filter((key) => !actualClsObj[key] &&
|
|
21
|
+
(list.includes(`${table}.${key}`) || list.includes(key)))
|
|
18
22
|
.map((key) => ({
|
|
19
23
|
name: key,
|
|
20
24
|
data: list.find((clsName) => [key, `${table}.${key}`].includes(clsName)),
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routeOptions.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/util/funcs/routeOptions.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,YAAY,EAAE,GAAG,EAAO,CAAC;AAC/B,eAAe,YAAY,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"totp.d.ts","sourceRoot":"","sources":["../../../../../../../server/routes/auth/controllers/2factor/providers/totp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"totp.d.ts","sourceRoot":"","sources":["../../../../../../../server/routes/auth/controllers/2factor/providers/totp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAU1D,UAAU,OAAO;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,EAAE,EAAE,UAAU,CAAC;CAChB;AAED,UAAU,KAAK;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,UAAU,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAmBD,QAAA,MAAM,YAAY,GAAU,aAAa,OAAO,kBAK/C,CAAC;AAEF,QAAA,MAAM,YAAY,GAAU,aAAa,OAAO,kBAK/C,CAAC;AAEF,QAAA,MAAM,SAAS,GAAU,aAAa,OAAO;;;;EAc5C,CAAC;AAuBF,QAAA,MAAM,QAAQ,GAAU,aAAa,OAAO;;;;;;;;;;;;EA6D3C,CAAC;AAEF,QAAA,MAAM,MAAM,GAAU,0BAA0B,KAAK;;;EAiBpD,CAAC;AAKF,QAAA,MAAM,MAAM,GAAU,2BAA2B,KAAK,iBAqBrD,CAAC;AAEF,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,CAAC;;AAE3E,wBAAoB"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import crypto from "node:crypto";
|
|
2
2
|
import qrcode from "qrcode";
|
|
3
3
|
import { authenticator } from "otplib";
|
|
4
|
+
import config from "../../../../../../config.js";
|
|
4
5
|
const TYPE = "TOTP";
|
|
6
|
+
const getOTP = (id, secret) => authenticator.keyuri(id.toString(), config.auth?.["2fa"]?.prefix || "SOFTPRO", secret);
|
|
5
7
|
const enableSecret = async ({ uid, pg }) => {
|
|
6
8
|
await pg.query("update admin.users_social_auth set enabled=true where uid = $1 and social_auth_type = $2", [uid, TYPE]);
|
|
7
9
|
};
|
|
@@ -41,7 +43,16 @@ const generate = async ({ uid, pg }) => {
|
|
|
41
43
|
crypto.randomUUID(),
|
|
42
44
|
crypto.randomUUID(),
|
|
43
45
|
];
|
|
44
|
-
const
|
|
46
|
+
const userData = await pg
|
|
47
|
+
.query(`select social_auth_id as code, login, email from admin.users where uid=$1`, [uid])
|
|
48
|
+
.then((el) => el.rows?.[0] || {});
|
|
49
|
+
if (config.auth?.["2fa"]?.["sufix"] &&
|
|
50
|
+
!userData[config.auth?.["2fa"]?.["sufix"]]) {
|
|
51
|
+
throw new Error("2fa prefix not found at userData");
|
|
52
|
+
}
|
|
53
|
+
const otp = getOTP(config.auth?.["2fa"]?.["sufix"]
|
|
54
|
+
? userData[config.auth?.["2fa"]?.["sufix"]]
|
|
55
|
+
: userData.login || userData.code || uid, secret);
|
|
45
56
|
const qrCodeAsImageSource = await qrcode.toDataURL(otp);
|
|
46
57
|
// no entry in db
|
|
47
58
|
if (enabled === undefined) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/routes/crud/index.ts"],"names":[],"mappings":"AAiBA,iBAAS,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,GAAE,GAAQ,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/routes/crud/index.ts"],"names":[],"mappings":"AAiBA,iBAAS,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,GAAE,GAAQ,QAwBtC;AAED,eAAe,MAAM,CAAC"}
|
|
@@ -13,9 +13,12 @@ const tableSchema = {
|
|
|
13
13
|
};
|
|
14
14
|
const policy = "L0";
|
|
15
15
|
function plugin(app, opt = {}) {
|
|
16
|
-
app.put("/table/:table/:id?", { config: { policy }, schema: tableSchema }, update);
|
|
17
|
-
app.delete("/table/:table/:id?", {
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
app.put("/table/:table/:id?", { config: { policy, description: "Edit table data" }, schema: tableSchema }, update);
|
|
17
|
+
app.delete("/table/:table/:id?", {
|
|
18
|
+
config: { policy, description: "Delete table data" },
|
|
19
|
+
schema: tableSchema,
|
|
20
|
+
}, deleteCrud);
|
|
21
|
+
app.post("/table/:table/:id?", { config: { policy, description: "Add table data" }, schema: tableSchema }, insert);
|
|
22
|
+
app.get("/table/:table/:id?", { config: { policy, description: "Get table data" }, schema: tableSchema }, table);
|
|
20
23
|
}
|
|
21
24
|
export default plugin;
|