@opengis/fastify-table 2.5.11 → 2.5.14
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/server/plugins/auth/index.d.ts.map +1 -1
- package/dist/server/plugins/auth/index.js +2 -4
- package/dist/server/plugins/crud/funcs/validateData.d.ts.map +1 -1
- package/dist/server/plugins/crud/funcs/validateData.js +23 -14
- package/dist/server/plugins/pg/funcs/getMeta.js +2 -2
- package/package.json +1 -1
|
@@ -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;AAOtD,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;AAOtD,wBAAsB,SAAS,CAAC,GAAG,EAAE,eAAe,EAAE,KAAK,EAAE,YAAY,iBAoIxE;AAED,iBAAS,MAAM,CAAC,OAAO,EAAE,eAAe,QAmCvC;AAED,eAAe,MAAM,CAAC"}
|
|
@@ -5,7 +5,7 @@ import { Authenticator } from "@fastify/passport";
|
|
|
5
5
|
import RedisStore from "fastify-session-redis-store";
|
|
6
6
|
import config from "../../../config.js";
|
|
7
7
|
import getRedis from "../redis/funcs/getRedis.js";
|
|
8
|
-
import { ForbiddenError
|
|
8
|
+
import { ForbiddenError } from "../../../errors.js";
|
|
9
9
|
const fastifyPassport = new Authenticator();
|
|
10
10
|
const { prefix = "/api" } = config;
|
|
11
11
|
export async function onRequest(req, reply) {
|
|
@@ -68,15 +68,13 @@ export async function onRequest(req, reply) {
|
|
|
68
68
|
!config.auth?.disable &&
|
|
69
69
|
isAdmin &&
|
|
70
70
|
!isPublic &&
|
|
71
|
+
!isApi &&
|
|
71
72
|
!config.auth?.disableRedirect &&
|
|
72
73
|
!req.url.startsWith(prefix) &&
|
|
73
74
|
!req.url.startsWith("/api") &&
|
|
74
75
|
!req.url.includes(loginPageUrl) &&
|
|
75
76
|
!req.url.includes(".") &&
|
|
76
77
|
!req.url.includes("@")) {
|
|
77
|
-
if (isApi) {
|
|
78
|
-
throw UnauthorizedError("unauthorized");
|
|
79
|
-
}
|
|
80
78
|
return reply.redirect(`${loginPageUrl}` + `?redirect=${req.url}`);
|
|
81
79
|
}
|
|
82
80
|
// by default, disable 2factor for id.gov.ua auth
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateData.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/crud/funcs/validateData.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validateData.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/crud/funcs/validateData.ts"],"names":[],"mappings":"AAmJA,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,EACnC,IAAS,EACT,MAAW,GACZ,EAAE;IACD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC7B,OAMA"}
|
|
@@ -9,15 +9,19 @@ function isNumeric(value) {
|
|
|
9
9
|
function checkField(key, val, options, idx, body) {
|
|
10
10
|
const type = options?.type?.toLowerCase?.();
|
|
11
11
|
const isrequired = options?.validators?.includes?.("required");
|
|
12
|
-
if (isrequired && !val && options.conditions) {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
if (isrequired && !val && Array.isArray(options.conditions)) {
|
|
13
|
+
const [requiredKey, condition, expected] = options.conditions;
|
|
14
|
+
const expectedValue = typeof expected === "number" ? expected.toString() : expected;
|
|
15
|
+
const allowedValues = Array.isArray(expectedValue) && typeof expectedValue[0] === "number"
|
|
16
|
+
? expectedValue.map((el) => el.toString())
|
|
17
|
+
: expectedValue;
|
|
18
|
+
const payloadValue = typeof body[requiredKey] == "number"
|
|
19
|
+
? body[requiredKey].toString()
|
|
20
|
+
: body[requiredKey];
|
|
21
|
+
const isConditionallyRequired = Array.isArray(allowedValues)
|
|
22
|
+
? allowedValues.includes(payloadValue)
|
|
23
|
+
: payloadValue === allowedValues;
|
|
24
|
+
if (condition === "in" && isConditionallyRequired) {
|
|
21
25
|
return {
|
|
22
26
|
error: "conditions not met: not allowed",
|
|
23
27
|
key,
|
|
@@ -25,9 +29,7 @@ function checkField(key, val, options, idx, body) {
|
|
|
25
29
|
idx,
|
|
26
30
|
};
|
|
27
31
|
}
|
|
28
|
-
if (isrequired &&
|
|
29
|
-
options?.conditions?.[1] === "==" &&
|
|
30
|
-
body[options?.conditions?.[0] || ""] === options?.conditions?.[2]) {
|
|
32
|
+
if (isrequired && condition === "==" && payloadValue === expectedValue) {
|
|
31
33
|
return { error: "conditions not met: empty required", key, val, idx };
|
|
32
34
|
}
|
|
33
35
|
return null; // conditions met, is valid
|
|
@@ -88,11 +90,18 @@ function checkField(key, val, options, idx, body) {
|
|
|
88
90
|
return { key, val, idx };
|
|
89
91
|
}
|
|
90
92
|
function checkBody({ body = {}, arr = [], idx }) {
|
|
91
|
-
|
|
93
|
+
// Object.keys(body)
|
|
94
|
+
const res = arr
|
|
95
|
+
.map((e) => e.key)
|
|
96
|
+
.reduce((acc1, key) => {
|
|
92
97
|
const input = arr.find((el) => el.key === key) || {};
|
|
93
98
|
if (input.colModel?.length && input.type?.toLowerCase() === "datatable") {
|
|
94
99
|
const result = body[key]?.reduce?.((acc, item, i) => {
|
|
95
|
-
const check = checkBody({
|
|
100
|
+
const check = checkBody({
|
|
101
|
+
body: item,
|
|
102
|
+
arr: input.colModel,
|
|
103
|
+
idx: i,
|
|
104
|
+
});
|
|
96
105
|
acc.push(check);
|
|
97
106
|
return acc;
|
|
98
107
|
}, []) || [];
|
|
@@ -33,7 +33,7 @@ export default async function getMeta(opt, nocache) {
|
|
|
33
33
|
if (!tlist.includes(tableUnsafe)) {
|
|
34
34
|
throw BadRequestError(`table not found: ${tableOriginal}`);
|
|
35
35
|
}
|
|
36
|
-
const relkinds = tableRows.reduce((acc, curr) => Object.assign(acc, { [curr.name]: curr.relkind }), {});
|
|
36
|
+
const relkinds = tableRows.reduce((acc, curr) => Object.assign(acc, { [curr.name.replace(/"/g, "")]: curr.relkind }), {});
|
|
37
37
|
const fields = await pg
|
|
38
38
|
.query(`select * from ${tableSafe} limit 0`)
|
|
39
39
|
.then((r) => r.fields || []);
|
|
@@ -63,7 +63,7 @@ export default async function getMeta(opt, nocache) {
|
|
|
63
63
|
pk,
|
|
64
64
|
columns: fields,
|
|
65
65
|
geom: geomAttr?.name,
|
|
66
|
-
view: ["v", "m"].includes(relkinds
|
|
66
|
+
view: ["v", "m"].includes(relkinds[tableUnsafe]),
|
|
67
67
|
};
|
|
68
68
|
if (!data[pg.options.database]) {
|
|
69
69
|
data[pg.options.database] = {};
|