@opengis/fastify-table 2.4.14 → 2.4.16
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/log/migration/dist-gis_mariupol_dla-cls.json +1 -0
- package/dist/log/migration/dist-gis_mariupol_dla-cls.sql +0 -0
- package/dist/module/core/select/core.user_mentioned.sql +1 -1
- package/dist/server/migrations/oauth.sql.sql +77 -0
- package/dist/server/plugins/auth/funcs/getUserPermissions.d.ts +2 -0
- package/dist/server/plugins/auth/funcs/getUserPermissions.d.ts.map +1 -0
- package/dist/server/plugins/auth/funcs/getUserPermissions.js +24 -0
- package/dist/server/plugins/pg/funcs/getMeta.js +1 -1
- package/dist/server/routes/access/functions/resources.d.ts +6 -0
- package/dist/server/routes/access/functions/resources.d.ts.map +1 -0
- package/dist/server/routes/access/functions/resources.js +11 -0
- package/dist/server/routes/auth/controllers/2factor/recovery.d.ts.map +1 -1
- package/dist/server/routes/auth/controllers/2factor/recovery.js +1 -1
- package/dist/server/routes/auth/controllers/2factor/verify.d.ts.map +1 -1
- package/dist/server/routes/auth/controllers/2factor/verify.js +3 -3
- package/dist/server/routes/auth/index.d.ts.map +1 -1
- package/dist/server/routes/auth/index.js +3 -0
- package/dist/server/templates/page/2factor.html +2 -2
- package/dist/server/types/errors.d.ts +14 -0
- package/dist/server/types/errors.d.ts.map +1 -0
- package/dist/server/types/errors.js +4 -0
- package/package.json +1 -1
- package/dist/server.js +0 -97
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[{"name":"addr.city_id","module":"address","type":"select","hash":"a943aa5241a30a33c88e58d223d201db","dbhash":"a943aa5241a30a33c88e58d223d201db","update":false},{"name":"addr.district_id.parent","module":"address","type":"select","hash":"cdfc0784ef5eda328562713911514f42","dbhash":"cdfc0784ef5eda328562713911514f42","update":false},{"name":"addr.district_id","module":"address","type":"select","hash":"9767f745c2bc5e2c61a96619fef2b8fc","dbhash":"9767f745c2bc5e2c61a96619fef2b8fc","update":false},{"name":"addr.street_id","module":"address","type":"select","hash":"4397d739d76356e253de23ad4e616e8b","dbhash":"4397d739d76356e253de23ad4e616e8b","update":false},{"name":"core.accounts","module":"admin","type":"select","hash":"36eef3856f46bc0eecb61a6f911ced2e","dbhash":"36eef3856f46bc0eecb61a6f911ced2e","update":false},{"name":"core.menu_id","module":"admin","type":"select","hash":"3b08d360628afa15339f364f5e2ff211","dbhash":"3b08d360628afa15339f364f5e2ff211","update":false},{"name":"core.roles","module":"admin","type":"select","hash":"ed1290380ea5e5e7e48bd08b41cb7793","dbhash":"ed1290380ea5e5e7e48bd08b41cb7793","update":false},{"name":"core.routes.alias","module":"admin","type":"select","hash":"ac6afe9a8ebaf0b26236c4bae5297709","dbhash":"ac6afe9a8ebaf0b26236c4bae5297709","update":false},{"name":"core.routes","module":"admin","type":"select","hash":"306bddbe5b73b0628728a60f5335aaee","dbhash":"306bddbe5b73b0628728a60f5335aaee","update":false},{"name":"core.rules","module":"admin","type":"select","hash":"a86085f579f4abff5cf09e775e034ed3","dbhash":"a86085f579f4abff5cf09e775e034ed3","update":false},{"name":"core.user_uid","module":"admin","type":"select","hash":"45f7d8a57ecbca5b433be7937be51d5c","dbhash":"45f7d8a57ecbca5b433be7937be51d5c","update":false},{"name":"dla.dictSpheresSectorsObjects.parent","module":"dla","type":"select","hash":"58814519060b3d56bf390c7ab132f850","dbhash":"58814519060b3d56bf390c7ab132f850","update":false},{"name":"dla.objects.department.parent","module":"dla","type":"select","hash":"e714599417cd92424b4309d17f7d8ba2","dbhash":"e714599417cd92424b4309d17f7d8ba2","update":false},{"name":"dla.objects.fixed_assets_group.parent","module":"dla","type":"select","hash":"65572ea4e9e34843199cfb1e67bfb1b1","dbhash":"65572ea4e9e34843199cfb1e67bfb1b1","update":false},{"name":"dla.objects.sector.parent","module":"dla","type":"select","hash":"633c8cad85e29ad92deac97c35804fe3","dbhash":"633c8cad85e29ad92deac97c35804fe3","update":false},{"name":"dla.objects.sector","module":"dla","type":"select","hash":"a92398b9582b8150c37369e028503f08","dbhash":"a92398b9582b8150c37369e028503f08","update":false},{"name":"dla.objects.sphere","module":"dla","type":"select","hash":"68b0b004bd803326645c2bdab9a71a7c","dbhash":"68b0b004bd803326645c2bdab9a71a7c","update":false},{"name":"dla.objects.subsector.parent","module":"dla","type":"select","hash":"b496cbd3b4d7614eb728a70aea533c7f","dbhash":"b496cbd3b4d7614eb728a70aea533c7f","update":false},{"name":"dla.objects.subsector","module":"dla","type":"select","hash":"fe996e283bbae23bdb14afb354895b95","dbhash":"fe996e283bbae23bdb14afb354895b95","update":false},{"name":"core.user_mentioned","module":"core","type":"select","hash":"6687f073de73a3ec4b6e0811d9310e7e","dbhash":"6687f073de73a3ec4b6e0811d9310e7e","update":false},{"name":"addr.str_type","module":"address","type":"cls","hash":"9c5a1d1cc9dbb53a888894bf4e2c0e34","dbhash":"9c5a1d1cc9dbb53a888894bf4e2c0e34","update":false},{"name":"core.actions","module":"admin","type":"cls","hash":"17862ea92ef5ad846a284fd68b4ff1f7","dbhash":"17862ea92ef5ad846a284fd68b4ff1f7","update":false},{"name":"message_type","module":"admin","type":"cls","hash":"d5ddb44bd0a40b4b32643a0dc1fa3122","dbhash":"d5ddb44bd0a40b4b32643a0dc1fa3122","update":false},{"name":"users.user_type","module":"admin","type":"cls","hash":"9f6a303d48d2d33c68dbcd8e72ad0e83","dbhash":"9f6a303d48d2d33c68dbcd8e72ad0e83","update":false},{"name":"yes_no","module":"admin","type":"cls","hash":"50c527053426248c20b0a2f112ff9046","dbhash":"50c527053426248c20b0a2f112ff9046","update":false},{"name":"dla.dictSpheresSectorsObjects.level","module":"dla","type":"cls","hash":"0f429d1171af13d93b05b5029d9b81aa","dbhash":"0f429d1171af13d93b05b5029d9b81aa","update":false},{"name":"dla.objects.asset_group","module":"dla","type":"cls","hash":"23ccb1c5050e8b8d618465dd6cb0c023","dbhash":"23ccb1c5050e8b8d618465dd6cb0c023","update":false},{"name":"dla.objects.basline","module":"dla","type":"cls","hash":"6820294956f9a8df2c669e37c87cc329","dbhash":"6820294956f9a8df2c669e37c87cc329","update":false},{"name":"dla.objects.damage_source","module":"dla","type":"cls","hash":"765d451557a04a7d4749e84be6bf85a3","dbhash":"765d451557a04a7d4749e84be6bf85a3","update":false},{"name":"dla.objects.department","module":"dla","type":"cls","hash":"f3e0e6b080a69c3b5cd816772726a924","dbhash":"f3e0e6b080a69c3b5cd816772726a924","update":false},{"name":"dla.objects.display_type","module":"dla","type":"cls","hash":"18bfad6855ae90802a02526e7983e575","dbhash":"18bfad6855ae90802a02526e7983e575","update":false},{"name":"dla.objects.fixed_assets_group","module":"dla","type":"cls","hash":"2820f5bd6cdbdf0a4102526c4414f7e0","dbhash":"2820f5bd6cdbdf0a4102526c4414f7e0","update":false},{"name":"dla.objects.geom_or_coord","module":"dla","type":"cls","hash":"b4cc2f9dcf5e67acd8f1015dc84a087c","dbhash":"b4cc2f9dcf5e67acd8f1015dc84a087c","update":false},{"name":"dla.objects.inventory_object","module":"dla","type":"cls","hash":"74cadb923c7e5c79c21e7fdb9a4e87d4","dbhash":"74cadb923c7e5c79c21e7fdb9a4e87d4","update":false},{"name":"dla.objects.ownership_type","module":"dla","type":"cls","hash":"fe2867f57413f2d3472fbc9015333662","dbhash":"fe2867f57413f2d3472fbc9015333662","update":false},{"name":"dla.objects.property_status","module":"dla","type":"cls","hash":"162a3a4c550b0fabd303af6b3603e791","dbhash":"162a3a4c550b0fabd303af6b3603e791","update":false},{"name":"dla.objects.structure","module":"dla","type":"cls","hash":"c454776818e3578ee0900cf1a2cef531","dbhash":"c454776818e3578ee0900cf1a2cef531","update":false},{"name":"constraint_action","module":"core","type":"cls","hash":"1b7129eae9eb42106ed6e646223c806a","dbhash":"1b7129eae9eb42106ed6e646223c806a","update":false},{"name":"constraint_matchtype","module":"core","type":"cls","hash":"446ad903e69a391748a8a27bae2dc5cd","dbhash":"446ad903e69a391748a8a27bae2dc5cd","update":false},{"name":"constraint_type_full","module":"core","type":"cls","hash":"9e1cc580273f7e73fbc08ee553ad8f64","dbhash":"9e1cc580273f7e73fbc08ee553ad8f64","update":false},{"name":"core.user_type","module":"core","type":"cls","hash":"728bc9e0bcc88de83ec56d8dc7e7efff","dbhash":"728bc9e0bcc88de83ec56d8dc7e7efff","update":false}]
|
|
File without changes
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
select uid, coalesce(sur_name,'')||coalesce(' '||user_name,'') as text, email from admin.users
|
|
1
|
+
select uid, coalesce(sur_name,'')||coalesce(' '||user_name,'') as text, email from admin.users
|
|
2
2
|
where enabled order by coalesce(sur_name,'')||coalesce(' '||user_name,'')
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
CREATE schema if not exists oauth;
|
|
2
|
+
|
|
3
|
+
CREATE TABLE if not exists oauth.clients (
|
|
4
|
+
client_id text PRIMARY KEY DEFAULT next_id(), -- ID клієнта (публічний ідентифікатор)
|
|
5
|
+
client_secret_hash text, -- Хеш секрету (NULL для public-клієнтів)
|
|
6
|
+
name text NOT NULL, -- Назва застосунку
|
|
7
|
+
type text NOT NULL CHECK (type IN ('public','confidential')),
|
|
8
|
+
token_endpoint_auth_method text NOT NULL CHECK (token_endpoint_auth_method IN ('client_secret_basic','client_secret_post','private_key_jwt','none')),
|
|
9
|
+
owner_user_id text, -- Власник/адміністратор клієнта (посилання на users.id or other id)
|
|
10
|
+
|
|
11
|
+
redirect_uris text[], -- Дозволені redirect_uri
|
|
12
|
+
grant_types text[] CHECK (case when grant_types is not null then grant_types <@ ARRAY['authorization_code','refresh_token','client_credentials','device_code']::text[] else true end),
|
|
13
|
+
require_pkce boolean NOT NULL DEFAULT true,
|
|
14
|
+
scopes text[],
|
|
15
|
+
allowed_cors_origins text[],
|
|
16
|
+
jwks jsonb, -- Вбудований JWK Set (опційно)
|
|
17
|
+
|
|
18
|
+
created_at timestamptz NOT NULL DEFAULT now(),
|
|
19
|
+
updated_at timestamptz NOT NULL DEFAULT now()
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
CREATE TABLE if not exists oauth.tokens (
|
|
23
|
+
id text PRIMARY KEY DEFAULT next_id(),
|
|
24
|
+
token_type text NOT NULL CHECK (token_type IN ('access','refresh')),
|
|
25
|
+
token_hash text NOT NULL UNIQUE, -- Argon2/bcrypt/SCrypt (хеш у застосунку)
|
|
26
|
+
token_hint text, -- останні 6-8 символів для діагностики (необов’язково)
|
|
27
|
+
jti text UNIQUE, -- JWT ID, якщо токен — JWT
|
|
28
|
+
client_id text NOT NULL REFERENCES oauth.clients(client_id) ON DELETE CASCADE,
|
|
29
|
+
user_id text, -- NULL для client_credentials
|
|
30
|
+
issuer text, -- iss
|
|
31
|
+
scopes text[],
|
|
32
|
+
claims jsonb, -- додаткові клейми
|
|
33
|
+
issued_at timestamptz NOT NULL DEFAULT now(),
|
|
34
|
+
expires_at timestamptz NOT NULL,
|
|
35
|
+
revoked_at timestamptz,
|
|
36
|
+
revocation_reason text,
|
|
37
|
+
ip inet -- IP видачі/використання (опційно)
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
COMMENT ON SCHEMA oauth IS 'Schema for OAuth2 / OpenID Connect clients and tokens';
|
|
41
|
+
|
|
42
|
+
-- Comments for oauth.clients
|
|
43
|
+
COMMENT ON TABLE oauth.clients IS 'OAuth 2.0 clients (applications) that can request tokens';
|
|
44
|
+
|
|
45
|
+
COMMENT ON COLUMN oauth.clients.client_id IS 'Client identifier (public ID, generated by next_id())';
|
|
46
|
+
COMMENT ON COLUMN oauth.clients.client_secret_hash IS 'Hashed client secret (NULL for public clients)';
|
|
47
|
+
COMMENT ON COLUMN oauth.clients.name IS 'Name of the application/client';
|
|
48
|
+
COMMENT ON COLUMN oauth.clients.type IS 'Client type: public or confidential';
|
|
49
|
+
COMMENT ON COLUMN oauth.clients.token_endpoint_auth_method IS 'Authentication method at token endpoint (client_secret_basic, client_secret_post, private_key_jwt, none)';
|
|
50
|
+
COMMENT ON COLUMN oauth.clients.owner_user_id IS 'Owner/administrator of the client (reference to users.id or external id)';
|
|
51
|
+
COMMENT ON COLUMN oauth.clients.redirect_uris IS 'Allowed redirect URIs';
|
|
52
|
+
COMMENT ON COLUMN oauth.clients.grant_types IS 'Allowed grant types (authorization_code, refresh_token, client_credentials, device_code)';
|
|
53
|
+
COMMENT ON COLUMN oauth.clients.require_pkce IS 'Whether PKCE is required (default true)';
|
|
54
|
+
COMMENT ON COLUMN oauth.clients.scopes IS 'Allowed OAuth2 scopes';
|
|
55
|
+
COMMENT ON COLUMN oauth.clients.allowed_cors_origins IS 'Allowed CORS origins for browser-based apps';
|
|
56
|
+
COMMENT ON COLUMN oauth.clients.jwks IS 'Embedded JSON Web Key Set (optional)';
|
|
57
|
+
COMMENT ON COLUMN oauth.clients.created_at IS 'Creation timestamp';
|
|
58
|
+
COMMENT ON COLUMN oauth.clients.updated_at IS 'Last update timestamp';
|
|
59
|
+
|
|
60
|
+
-- Comments for oauth.tokens
|
|
61
|
+
COMMENT ON TABLE oauth.tokens IS 'Issued OAuth 2.0 tokens (access or refresh)';
|
|
62
|
+
|
|
63
|
+
COMMENT ON COLUMN oauth.tokens.id IS 'Internal token ID (generated by next_id())';
|
|
64
|
+
COMMENT ON COLUMN oauth.tokens.token_type IS 'Type of token: access or refresh';
|
|
65
|
+
COMMENT ON COLUMN oauth.tokens.token_hash IS 'Secure hash of the token (Argon2/bcrypt/SCrypt)';
|
|
66
|
+
COMMENT ON COLUMN oauth.tokens.token_hint IS 'Optional hint (last 6–8 characters of token) for diagnostics';
|
|
67
|
+
COMMENT ON COLUMN oauth.tokens.jti IS 'JWT ID if token is a JWT (unique)';
|
|
68
|
+
COMMENT ON COLUMN oauth.tokens.client_id IS 'Reference to oauth.clients (issuing client)';
|
|
69
|
+
COMMENT ON COLUMN oauth.tokens.user_id IS 'User ID if bound to user (NULL for client_credentials flow)';
|
|
70
|
+
COMMENT ON COLUMN oauth.tokens.issuer IS 'Token issuer (iss claim)';
|
|
71
|
+
COMMENT ON COLUMN oauth.tokens.scopes IS 'Granted OAuth2 scopes for this token';
|
|
72
|
+
COMMENT ON COLUMN oauth.tokens.claims IS 'Additional claims (JSONB)';
|
|
73
|
+
COMMENT ON COLUMN oauth.tokens.issued_at IS 'Timestamp when issued';
|
|
74
|
+
COMMENT ON COLUMN oauth.tokens.expires_at IS 'Timestamp when token expires';
|
|
75
|
+
COMMENT ON COLUMN oauth.tokens.revoked_at IS 'Timestamp when revoked';
|
|
76
|
+
COMMENT ON COLUMN oauth.tokens.revocation_reason IS 'Reason for revocation (if any)';
|
|
77
|
+
COMMENT ON COLUMN oauth.tokens.ip IS 'IP address of issuance/usage (optional)';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getUserPermissions.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/auth/funcs/getUserPermissions.ts"],"names":[],"mappings":"AAUA,wBAA8B,kBAAkB,CAC9C,GAAG,CAAC,EAAE,MAAM,EACZ,EAAE,MAAmB,gBAoBtB"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import pgClients from "../../pg/pgClients.js";
|
|
2
|
+
const q = `select resource_id as name,
|
|
3
|
+
array_intersect(coalesce(a.actions, array['read']), coalesce(c.actions, array['create', 'read','update','delete'])) as actions,
|
|
4
|
+
b.name as role
|
|
5
|
+
from admin.role_access a
|
|
6
|
+
left join admin.roles b on a.role_id=b.role_id and b.enabled
|
|
7
|
+
left join admin.user_roles c on a.role_id=c.role_id
|
|
8
|
+
where resource_id is not null and $1 in (a.user_uid, c.user_uid)`;
|
|
9
|
+
export default async function getUserPermissions(uid, pg = pgClients.client) {
|
|
10
|
+
if (!uid)
|
|
11
|
+
return [];
|
|
12
|
+
// ? in case pg.pk not set yet
|
|
13
|
+
const pks = await pg
|
|
14
|
+
.query(`SELECT json_object_agg(conrelid::regclass, (SELECT attname FROM pg_attribute WHERE attrelid = c.conrelid AND attnum = c.conkey[1]) )
|
|
15
|
+
FROM pg_constraint c WHERE contype = 'p' AND connamespace::regnamespace::text = 'admin'`)
|
|
16
|
+
.then((el) => el.rows?.[0]?.json_object_agg || {});
|
|
17
|
+
const permissions = pks["admin.role_access"] &&
|
|
18
|
+
pks["admin.user_roles"] &&
|
|
19
|
+
pks["admin.users"] &&
|
|
20
|
+
uid
|
|
21
|
+
? await pg.query(q, [uid]).then((el) => el.rows || [])
|
|
22
|
+
: [];
|
|
23
|
+
return permissions;
|
|
24
|
+
}
|
|
@@ -28,7 +28,7 @@ export default async function getMeta(opt, nocache) {
|
|
|
28
28
|
.then((el) => el.rows[0].pks1 || {});
|
|
29
29
|
const pk = table.startsWith("public.")
|
|
30
30
|
? pks1[table.replace("public.", "")]
|
|
31
|
-
: pks1[table];
|
|
31
|
+
: pks1[table] || pg.pk[table];
|
|
32
32
|
const geomColumns = fields.filter((el) => pg.pgType?.[el.dataTypeID] === "geometry");
|
|
33
33
|
const geomAttr = geomColumns.find((el) => el.name === "geom_4326") || geomColumns[0];
|
|
34
34
|
const dbColumns = await pg
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resources.d.ts","sourceRoot":"","sources":["../../../../../server/routes/access/functions/resources.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,aAAa,KAEb,CAAC;AAEP,QAAA,MAAM,mBAAmB,EAAE,GAAG,EAM7B,CAAC;AAEF,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,CAAC;;AAC9C,wBAAoB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
const resourcesList = existsSync("config/resources.json")
|
|
3
|
+
? JSON.parse(readFileSync("config/resources.json", "utf-8") || "[]")
|
|
4
|
+
: [];
|
|
5
|
+
const publicResourcesList = resourcesList.map(({ name, actions, feature }) => ({
|
|
6
|
+
name,
|
|
7
|
+
actions,
|
|
8
|
+
feature,
|
|
9
|
+
}));
|
|
10
|
+
export { resourcesList, publicResourcesList };
|
|
11
|
+
export default null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recovery.d.ts","sourceRoot":"","sources":["../../../../../../server/routes/auth/controllers/2factor/recovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAsBvC;;;;;;;;;;;;;;;;GAgBG;AAEH,wBAA8B,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"recovery.d.ts","sourceRoot":"","sources":["../../../../../../server/routes/auth/controllers/2factor/recovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAsBvC;;;;;;;;;;;;;;;;GAgBG;AAEH,wBAA8B,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,YAAY,kBA+EnE"}
|
|
@@ -46,7 +46,7 @@ export default async function recovery(req, reply) {
|
|
|
46
46
|
}
|
|
47
47
|
const customPt = await getTemplate("pt", template);
|
|
48
48
|
const pt = customPt ||
|
|
49
|
-
(await readFile(path.join(dirname, `../../../../../templates/pt/${template}.
|
|
49
|
+
(await readFile(path.join(dirname, `../../../../../dist/server/templates/pt/${template}.hbs`), "utf8"));
|
|
50
50
|
const recoveryCodes = await pg
|
|
51
51
|
.query(`select social_auth_obj->'codesArray' as "recoveryCodes" from admin.users_social_auth
|
|
52
52
|
where uid = $1 and social_auth_type = $2`, [uid, "TOTP"])
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../../../../../server/routes/auth/controllers/2factor/verify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AA2BvC;;;;;;;;;;;;;;;;GAgBG;AAEH,wBAA8B,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../../../../../server/routes/auth/controllers/2factor/verify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AA2BvC;;;;;;;;;;;;;;;;GAgBG;AAEH,wBAA8B,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,YAAY,kBA6DzE"}
|
|
@@ -31,9 +31,9 @@ const defaultPt = existsSync(path.join(dirname, `../../../../templates/pt/${temp
|
|
|
31
31
|
* @returns {String} redirect Шлях до переадресації
|
|
32
32
|
*/
|
|
33
33
|
export default async function verifyFunction(req, reply) {
|
|
34
|
-
const
|
|
34
|
+
const code = req.method === "POST" ? req.body?.code : req.query?.code;
|
|
35
|
+
const { pg = pgClients.client, user = {} } = req;
|
|
35
36
|
const { uid, twofa, email } = user || {};
|
|
36
|
-
const { code } = body;
|
|
37
37
|
if (!twofa) {
|
|
38
38
|
throw BadRequestError("2fa not enabled");
|
|
39
39
|
}
|
|
@@ -41,7 +41,7 @@ export default async function verifyFunction(req, reply) {
|
|
|
41
41
|
throw Error("empty pg");
|
|
42
42
|
}
|
|
43
43
|
if (!code) {
|
|
44
|
-
throw BadRequestError(
|
|
44
|
+
throw BadRequestError(`not enough ${req.method === "POST" ? "body" : "query"} params: code`);
|
|
45
45
|
}
|
|
46
46
|
const { enabled } = await verify({ uid, code, pg });
|
|
47
47
|
await enableSecret({ pg, uid });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/routes/auth/index.ts"],"names":[],"mappings":"AA+CA,iBAAS,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,GAAE,GAAQ,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/routes/auth/index.ts"],"names":[],"mappings":"AA+CA,iBAAS,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,GAAE,GAAQ,QA+FtC;AAED,eAAe,MAAM,CAAC"}
|
|
@@ -56,6 +56,9 @@ function plugin(app, opt = {}) {
|
|
|
56
56
|
}
|
|
57
57
|
// 2factor
|
|
58
58
|
if (!app.hasRoute({ method: "GET", url: "/2factor/verify" })) {
|
|
59
|
+
app.get("/2factor/verify", params, verify);
|
|
60
|
+
}
|
|
61
|
+
if (!app.hasRoute({ method: "POST", url: "/2factor/verify" })) {
|
|
59
62
|
app.post("/2factor/verify", params, verify);
|
|
60
63
|
}
|
|
61
64
|
if (!app.hasRoute({ method: "POST", url: "/2factor/recovery" })) {
|
|
@@ -65,9 +65,9 @@
|
|
|
65
65
|
Enter the 2-step verification code from your authenticator app.
|
|
66
66
|
</p>
|
|
67
67
|
|
|
68
|
-
<form action="/2factor/verify" method="
|
|
68
|
+
<form action="/2factor/verify" method="get">
|
|
69
69
|
<div class="space-y-5">
|
|
70
|
-
<div>
|
|
70
|
+
<div>
|
|
71
71
|
<input type="text" name="code" class="form-input hidden">
|
|
72
72
|
<div class="space-y-5">
|
|
73
73
|
<div class="my-3 flex gap-x-2" data-hs-pin-input>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import createError from "@fastify/error";
|
|
2
|
+
export declare const NotFoundError: createError.FastifyErrorConstructor<{
|
|
3
|
+
code: "NOT_FOUND_ERROR";
|
|
4
|
+
statusCode: 404;
|
|
5
|
+
}, [any?, any?, any?]>;
|
|
6
|
+
export declare const BadRequestError: createError.FastifyErrorConstructor<{
|
|
7
|
+
code: "BAD_REQUEST_ERROR";
|
|
8
|
+
statusCode: 400;
|
|
9
|
+
}, [any?, any?, any?]>;
|
|
10
|
+
export declare const PayloadTooLargeError: createError.FastifyErrorConstructor<{
|
|
11
|
+
code: "PAYLOAD_TOO_LARGE_ERROR";
|
|
12
|
+
statusCode: 413;
|
|
13
|
+
}, [any?, any?, any?]>;
|
|
14
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../server/types/errors.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,gBAAgB,CAAC;AACzC,eAAO,MAAM,aAAa;;;sBAIzB,CAAC;AACF,eAAO,MAAM,eAAe;;;sBAI3B,CAAC;AACF,eAAO,MAAM,oBAAoB;;;sBAIhC,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import createError from "@fastify/error";
|
|
2
|
+
export const NotFoundError = createError("NOT_FOUND_ERROR", "Resource not found: %s", 404);
|
|
3
|
+
export const BadRequestError = createError("BAD_REQUEST_ERROR", "Bad request: %s", 400);
|
|
4
|
+
export const PayloadTooLargeError = createError("PAYLOAD_TOO_LARGE_ERROR", "Payload Too Large: %s", 413);
|
package/package.json
CHANGED
package/dist/server.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-return-assign */
|
|
2
|
-
// This file contains code that we reuse
|
|
3
|
-
// between our tests.
|
|
4
|
-
import Fastify from 'fastify';
|
|
5
|
-
|
|
6
|
-
import config from './config.js';
|
|
7
|
-
import plugin from './index.js';
|
|
8
|
-
import loginEuSign from './server/routes/auth/controllers/page/loginEuSign.js';
|
|
9
|
-
|
|
10
|
-
import loggerTest from './server/routes/logger/controllers/logger.test.api.js';
|
|
11
|
-
import { addHook, logger, addTemplateDir, pgClients } from './utils.js';
|
|
12
|
-
import { BadRequestError } from './errors.js';
|
|
13
|
-
|
|
14
|
-
addHook('afterChunkedUpload', async ({ id, meta }) => {
|
|
15
|
-
console.log('chunked upload finished', id, meta);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
const cwd = process.cwd();
|
|
19
|
-
|
|
20
|
-
const app = Fastify({ loggerInstance: logger });
|
|
21
|
-
function contentParser(req, body, done) {
|
|
22
|
-
const parseBody = decodeURIComponent(body.toString()).split('&').reduce((acc, el) => {
|
|
23
|
-
const [key, val] = el.split('=');
|
|
24
|
-
return { ...acc, [key]: val };
|
|
25
|
-
}, {});
|
|
26
|
-
done(null, parseBody);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
app.addContentTypeParser('application/x-www-form-urlencoded', { parseAs: 'buffer' }, contentParser);
|
|
30
|
-
|
|
31
|
-
await app.register(plugin, config);
|
|
32
|
-
|
|
33
|
-
// debug only
|
|
34
|
-
app.get('/login1', { config: { policy: 'L0' } }, loginEuSign);
|
|
35
|
-
addHook("afterAuth", async () => {
|
|
36
|
-
if (config.auth?.redirectAfter) return; // let config decide
|
|
37
|
-
return { href: "/user" }; // force redirect to specific page after login
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
addTemplateDir(`${cwd}/module/test`);
|
|
41
|
-
|
|
42
|
-
app.get('/logger-test', { config: { policy: 'L0' } }, loggerTest);
|
|
43
|
-
app.get('/err', { config: { policy: 'L0' } }, ({ query }) => {
|
|
44
|
-
if (query.custom) {
|
|
45
|
-
throw BadRequestError('this is message');
|
|
46
|
-
}
|
|
47
|
-
if (query.custom1) {
|
|
48
|
-
throw new BadRequestError('this is stil same message');
|
|
49
|
-
}
|
|
50
|
-
throw new Error('test error code 500');
|
|
51
|
-
});
|
|
52
|
-
app.get('/test-permissions', { config: { permission: 'orders.read' } }, async () => {
|
|
53
|
-
return 'allowed';
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
app.get('/health', {
|
|
57
|
-
// preHandler: userJwt,
|
|
58
|
-
config: {
|
|
59
|
-
tags: ['server.js'],
|
|
60
|
-
policy: 'L1', // L0, L1, L2
|
|
61
|
-
auth: 'user-jwt', // none, user-jwt, creds
|
|
62
|
-
role: 'admin', // role
|
|
63
|
-
scope: 'logger', // logger, admin, gis, bi
|
|
64
|
-
rateLimit: { max: 100, timeWindow: '1 minute', hook: 'preHandler' },
|
|
65
|
-
cors: { origins: ['https://app.example.com'] },
|
|
66
|
-
rbac: { resource: 'id', action: 'add' },
|
|
67
|
-
}
|
|
68
|
-
}, async () => {
|
|
69
|
-
const clients = await Promise.all(Object.keys(pgClients || {}).map(async key => {
|
|
70
|
-
const connected = await pgClients[key]?.query('select 1').catch(err => { err }).then(el => el?.rowCount);
|
|
71
|
-
const keys = Object.keys(pgClients[key] || {});
|
|
72
|
-
return {
|
|
73
|
-
name: key,
|
|
74
|
-
init: !!pgClients[key]?.tlist
|
|
75
|
-
&& !!pgClients[key]?.pk
|
|
76
|
-
&& !!pgClients[key]?.pgType
|
|
77
|
-
&& !!pgClients[key]?.relkinds
|
|
78
|
-
&& !!pgClients[key]?.queryCache,
|
|
79
|
-
connected: !!connected,
|
|
80
|
-
keys,
|
|
81
|
-
};
|
|
82
|
-
}));
|
|
83
|
-
return { ok: true, pgClients: clients };
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
/* addCron(async function testCron() {
|
|
87
|
-
return (config.local || true) ? null : { message: 'Done', status: 200 };
|
|
88
|
-
}, 60 * 1); */
|
|
89
|
-
|
|
90
|
-
app.listen({ host: config.host || '0.0.0.0', port: config.port || process.env.PORT || 3000 }, (err) => {
|
|
91
|
-
console.log(`Server started via port: ${config.port || process.env.PORT || 3000}`);
|
|
92
|
-
if (err) {
|
|
93
|
-
console.error(err.toString());
|
|
94
|
-
logger.error(err);
|
|
95
|
-
process.exit(1);
|
|
96
|
-
}
|
|
97
|
-
});
|