@opengis/fcore 0.0.1-beta.1 → 0.0.1-beta.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/config.d.ts +2 -10
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -1
- package/dist/context.js +1 -1
- package/dist/errors.js +1 -1
- package/dist/fastify.d.ts +5 -5
- package/dist/fastify.d.ts.map +1 -1
- package/dist/fastify.js +1 -1
- package/dist/fcore.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/migrations/cli.js +1 -1
- package/dist/migrations/runner.js +1 -1
- package/dist/modules/auth/adduser-cli.d.ts +3 -0
- package/dist/modules/auth/adduser-cli.d.ts.map +1 -0
- package/dist/modules/auth/adduser-cli.js +2 -0
- package/dist/modules/auth/passwd-cli.d.ts +3 -0
- package/dist/modules/auth/passwd-cli.d.ts.map +1 -0
- package/dist/modules/auth/passwd-cli.js +2 -0
- package/dist/modules/auth/permission-cli.d.ts +3 -0
- package/dist/modules/auth/permission-cli.d.ts.map +1 -0
- package/dist/modules/auth/permission-cli.js +2 -0
- package/dist/modules/auth/route.d.ts.map +1 -1
- package/dist/modules/auth/route.js +1 -1
- package/dist/modules/auth/schema.d.ts +10 -1
- package/dist/modules/auth/schema.d.ts.map +1 -1
- package/dist/modules/auth/schema.js +1 -1
- package/dist/modules/auth/services/change-password.d.ts +9 -0
- package/dist/modules/auth/services/change-password.d.ts.map +1 -0
- package/dist/modules/auth/services/change-password.js +1 -0
- package/dist/modules/auth/services/get-current-user.d.ts +1 -0
- package/dist/modules/auth/services/get-current-user.d.ts.map +1 -1
- package/dist/modules/auth/services/get-current-user.js +1 -1
- package/dist/modules/auth/services/registration.d.ts +14 -0
- package/dist/modules/auth/services/registration.d.ts.map +1 -0
- package/dist/modules/auth/services/registration.js +1 -0
- package/dist/modules/auth/services/verify-two-factor.js +1 -1
- package/dist/modules/file/mime.d.ts +3 -0
- package/dist/modules/file/mime.d.ts.map +1 -0
- package/dist/modules/file/mime.js +1 -0
- package/dist/modules/file/route.d.ts.map +1 -1
- package/dist/modules/file/route.js +1 -1
- package/dist/modules/file/schema.d.ts +3 -0
- package/dist/modules/file/schema.d.ts.map +1 -1
- package/dist/modules/file/schema.js +1 -1
- package/dist/modules/file/services/get-file.js +1 -1
- package/dist/modules/file/services/resize-file.d.ts.map +1 -1
- package/dist/modules/file/services/resize-file.js +1 -1
- package/dist/modules/file/services/upload-file.d.ts +4 -6
- package/dist/modules/file/services/upload-file.d.ts.map +1 -1
- package/dist/modules/file/services/upload-file.js +1 -1
- package/dist/modules/resource/route.d.ts +0 -3
- package/dist/modules/resource/route.d.ts.map +1 -1
- package/dist/modules/resource/route.js +1 -1
- package/dist/modules/resource/schema.d.ts +3 -0
- package/dist/modules/resource/schema.d.ts.map +1 -1
- package/dist/modules/resource/schema.js +1 -1
- package/dist/modules/resource/services/add-note.js +1 -1
- package/dist/modules/resource/services/add-resource-file.js +1 -1
- package/dist/modules/resource/services/create-resource-relation.d.ts +8 -2
- package/dist/modules/resource/services/create-resource-relation.d.ts.map +1 -1
- package/dist/modules/resource/services/create-resource-relation.js +1 -1
- package/dist/modules/resource/services/create-resource.js +1 -1
- package/dist/modules/resource/services/delete-resource-relation.d.ts +8 -1
- package/dist/modules/resource/services/delete-resource-relation.d.ts.map +1 -1
- package/dist/modules/resource/services/delete-resource-relation.js +1 -1
- package/dist/modules/resource/services/delete-resource.js +1 -1
- package/dist/modules/resource/services/export-resource.d.ts.map +1 -1
- package/dist/modules/resource/services/export-resource.js +1 -1
- package/dist/modules/resource/services/get-resource.d.ts.map +1 -1
- package/dist/modules/resource/services/get-resource.js +1 -1
- package/dist/modules/resource/services/list-resource-relation.d.ts +9 -2
- package/dist/modules/resource/services/list-resource-relation.d.ts.map +1 -1
- package/dist/modules/resource/services/list-resource-relation.js +1 -1
- package/dist/modules/resource/services/list-resources.d.ts.map +1 -1
- package/dist/modules/resource/services/list-resources.js +1 -1
- package/dist/modules/resource/services/search-resource.d.ts.map +1 -1
- package/dist/modules/resource/services/search-resource.js +1 -1
- package/dist/modules/resource/services/suggest-resource.d.ts +10 -4
- package/dist/modules/resource/services/suggest-resource.d.ts.map +1 -1
- package/dist/modules/resource/services/suggest-resource.js +1 -1
- package/dist/modules/resource/services/update-resource-relation.d.ts +10 -0
- package/dist/modules/resource/services/update-resource-relation.d.ts.map +1 -0
- package/dist/modules/resource/services/update-resource-relation.js +1 -0
- package/dist/modules/resource/services/update-resource.js +1 -1
- package/dist/modules/resource/services/upload-resource-file.js +1 -1
- package/dist/modules/system/route.d.ts +2 -1
- package/dist/modules/system/route.d.ts.map +1 -1
- package/dist/modules/system/route.js +1 -1
- package/dist/modules/system/schema.d.ts +22 -1
- package/dist/modules/system/schema.d.ts.map +1 -1
- package/dist/modules/system/schema.js +1 -1
- package/dist/modules/system/services/check-system.d.ts.map +1 -1
- package/dist/modules/system/services/check-system.js +1 -1
- package/dist/modules/system/services/get-access.d.ts +14 -0
- package/dist/modules/system/services/get-access.d.ts.map +1 -0
- package/dist/modules/system/services/get-access.js +1 -0
- package/dist/modules/system/services/get-api-list.d.ts +4 -1
- package/dist/modules/system/services/get-api-list.d.ts.map +1 -1
- package/dist/modules/system/services/get-api-list.js +1 -1
- package/dist/modules/system/services/get-audit-log.d.ts.map +1 -1
- package/dist/modules/system/services/get-audit-log.js +1 -1
- package/dist/modules/system/services/get-dictionary.js +1 -1
- package/dist/modules/system/services/get-system-log.d.ts +9 -5
- package/dist/modules/system/services/get-system-log.d.ts.map +1 -1
- package/dist/modules/system/services/get-system-log.js +1 -1
- package/dist/modules/system/services/get-system-settings.d.ts.map +1 -1
- package/dist/modules/system/services/get-system-settings.js +1 -1
- package/dist/modules/system/services/list-dictionaries.js +1 -1
- package/dist/modules/system/services/set-access.d.ts +16 -0
- package/dist/modules/system/services/set-access.d.ts.map +1 -0
- package/dist/modules/system/services/set-access.js +1 -0
- package/dist/modules/system/services/update-dictionary.d.ts +13 -0
- package/dist/modules/system/services/update-dictionary.d.ts.map +1 -0
- package/dist/modules/system/services/update-dictionary.js +1 -0
- package/dist/modules/system/services/update-system-settings.d.ts.map +1 -1
- package/dist/modules/system/services/update-system-settings.js +1 -1
- package/dist/modules/utils/require-admin.js +1 -1
- package/dist/modules/utils/safe-user.js +1 -1
- package/dist/modules/utils/unsupported.js +1 -1
- package/dist/plugins/audit/audit.js +1 -1
- package/dist/plugins/audit/index.js +1 -1
- package/dist/plugins/audit/services/write-audit.js +1 -1
- package/dist/plugins/auth/get-user-permissions.d.ts +3 -0
- package/dist/plugins/auth/get-user-permissions.d.ts.map +1 -0
- package/dist/plugins/auth/get-user-permissions.js +1 -0
- package/dist/plugins/auth/index.d.ts +4 -0
- package/dist/plugins/auth/index.d.ts.map +1 -1
- package/dist/plugins/auth/index.js +1 -1
- package/dist/plugins/auth/verifyUser.d.ts +9 -0
- package/dist/plugins/auth/verifyUser.d.ts.map +1 -0
- package/dist/plugins/auth/verifyUser.js +1 -0
- package/dist/plugins/dictionary.d.ts +3 -0
- package/dist/plugins/dictionary.d.ts.map +1 -1
- package/dist/plugins/dictionary.js +1 -1
- package/dist/plugins/file.d.ts +3 -6
- package/dist/plugins/file.d.ts.map +1 -1
- package/dist/plugins/file.js +1 -1
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/index.js +1 -1
- package/dist/plugins/jwt.d.ts +4 -0
- package/dist/plugins/jwt.d.ts.map +1 -0
- package/dist/plugins/jwt.js +1 -0
- package/dist/plugins/logger/index.js +1 -1
- package/dist/plugins/logger/transport.d.ts +3 -0
- package/dist/plugins/logger/transport.d.ts.map +1 -0
- package/dist/plugins/logger/transport.js +1 -0
- package/dist/plugins/pg.d.ts +4 -2
- package/dist/plugins/pg.d.ts.map +1 -1
- package/dist/plugins/pg.js +1 -1
- package/dist/plugins/redis.js +1 -1
- package/dist/plugins/resource/index.js +1 -1
- package/dist/plugins/resource/resource.d.ts.map +1 -1
- package/dist/plugins/resource/resource.js +1 -1
- package/dist/plugins/resource/resource.registry.js +1 -1
- package/dist/plugins/resource/resource.types.d.ts +60 -6
- package/dist/plugins/resource/resource.types.d.ts.map +1 -1
- package/dist/plugins/resource/services/add-dictionary-lookup-data.d.ts +3 -0
- package/dist/plugins/resource/services/add-dictionary-lookup-data.d.ts.map +1 -0
- package/dist/plugins/resource/services/add-dictionary-lookup-data.js +1 -0
- package/dist/plugins/resource/services/add-file-token.d.ts +3 -0
- package/dist/plugins/resource/services/add-file-token.d.ts.map +1 -0
- package/dist/plugins/resource/services/add-file-token.js +1 -0
- package/dist/plugins/resource/services/add-table-lookup-data.d.ts +4 -0
- package/dist/plugins/resource/services/add-table-lookup-data.d.ts.map +1 -0
- package/dist/plugins/resource/services/add-table-lookup-data.js +1 -0
- package/dist/plugins/resource/services/create-relation.d.ts +16 -0
- package/dist/plugins/resource/services/create-relation.d.ts.map +1 -0
- package/dist/plugins/resource/services/create-relation.js +1 -0
- package/dist/plugins/resource/services/create.d.ts +5 -2
- package/dist/plugins/resource/services/create.d.ts.map +1 -1
- package/dist/plugins/resource/services/create.js +1 -1
- package/dist/plugins/resource/services/delete-relation.d.ts +18 -0
- package/dist/plugins/resource/services/delete-relation.d.ts.map +1 -0
- package/dist/plugins/resource/services/delete-relation.js +1 -0
- package/dist/plugins/resource/services/delete.d.ts +5 -2
- package/dist/plugins/resource/services/delete.d.ts.map +1 -1
- package/dist/plugins/resource/services/delete.js +1 -1
- package/dist/plugins/resource/services/find-one.d.ts +3 -2
- package/dist/plugins/resource/services/find-one.d.ts.map +1 -1
- package/dist/plugins/resource/services/find-one.js +1 -1
- package/dist/plugins/resource/services/find-relation.d.ts +13 -0
- package/dist/plugins/resource/services/find-relation.d.ts.map +1 -0
- package/dist/plugins/resource/services/find-relation.js +1 -0
- package/dist/plugins/resource/services/find.d.ts.map +1 -1
- package/dist/plugins/resource/services/find.js +1 -1
- package/dist/plugins/resource/services/update-relation.d.ts +14 -0
- package/dist/plugins/resource/services/update-relation.d.ts.map +1 -0
- package/dist/plugins/resource/services/update-relation.js +1 -0
- package/dist/plugins/resource/services/update.d.ts +5 -2
- package/dist/plugins/resource/services/update.d.ts.map +1 -1
- package/dist/plugins/resource/services/update.js +1 -1
- package/dist/plugins/resource/utils/auto-index.d.ts +4 -0
- package/dist/plugins/resource/utils/auto-index.d.ts.map +1 -0
- package/dist/plugins/resource/utils/auto-index.js +1 -0
- package/dist/plugins/resource/utils/fields.d.ts +8 -1
- package/dist/plugins/resource/utils/fields.d.ts.map +1 -1
- package/dist/plugins/resource/utils/fields.js +1 -1
- package/dist/plugins/resource/utils/filters.d.ts +3 -2
- package/dist/plugins/resource/utils/filters.d.ts.map +1 -1
- package/dist/plugins/resource/utils/filters.js +1 -1
- package/dist/plugins/resource/utils/permissions.d.ts.map +1 -1
- package/dist/plugins/resource/utils/permissions.js +1 -1
- package/dist/plugins/resource/utils/sort.d.ts.map +1 -1
- package/dist/plugins/resource/utils/sort.js +1 -1
- package/dist/plugins/resource/utils/sql.js +1 -1
- package/dist/shared/getIP.js +1 -1
- package/dist/type.d.ts +37 -0
- package/dist/type.d.ts.map +1 -0
- package/dist/type.js +1 -0
- package/migrations/20260903120000_core_schema.sql +22 -19
- package/migrations/20260905120000_add_user_foreign_keys.sql +43 -0
- package/migrations/20260907090000_core_schema.sql +32 -0
- package/package.json +13 -8
- package/dist/modules/auth/index.d.ts +0 -9
- package/dist/modules/auth/index.d.ts.map +0 -1
- package/dist/modules/auth/index.js +0 -1
- package/dist/modules/auth/services/login.d.ts +0 -10
- package/dist/modules/auth/services/login.d.ts.map +0 -1
- package/dist/modules/auth/services/login.js +0 -1
- package/dist/modules/auth/services/logout.d.ts +0 -9
- package/dist/modules/auth/services/logout.d.ts.map +0 -1
- package/dist/modules/auth/services/logout.js +0 -1
- package/dist/modules/auth/services/verifyPassword.d.ts +0 -11
- package/dist/modules/auth/services/verifyPassword.d.ts.map +0 -1
- package/dist/modules/auth/services/verifyPassword.js +0 -1
- package/dist/modules/file/index.d.ts +0 -8
- package/dist/modules/file/index.d.ts.map +0 -1
- package/dist/modules/file/index.js +0 -1
- package/dist/modules/resource/index.d.ts +0 -20
- package/dist/modules/resource/index.d.ts.map +0 -1
- package/dist/modules/resource/index.js +0 -1
- package/dist/modules/resource/services/list-children.d.ts +0 -6
- package/dist/modules/resource/services/list-children.d.ts.map +0 -1
- package/dist/modules/resource/services/list-children.js +0 -1
- package/dist/modules/system/index.d.ts +0 -13
- package/dist/modules/system/index.d.ts.map +0 -1
- package/dist/modules/system/index.js +0 -1
- package/dist/modules/utils/get-user-permissions.d.ts +0 -3
- package/dist/modules/utils/get-user-permissions.d.ts.map +0 -1
- package/dist/modules/utils/get-user-permissions.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{ValidationError}from'../../../errors.js';function v(){const g=['min','max','filter','isFinite','SELECT\x20','sql','length','query','dictionary','rowCount'];v=function(){return g;};return v();}import{buildFilters}from'../utils/filters.js';function S(d,h){d=d-0x100;const p=v();let Z=p[d];return Z;}import{assertOperation}from'../utils/permissions.js';import{buildSort}from'../utils/sort.js';import{qt,readableFields}from'../utils/sql.js';import{addDictionaryLookupData}from'./add-dictionary-lookup-data.js';import{addTableLookupData}from'./add-table-lookup-data.js';import{addFileToken}from'./add-file-token.js';export function createFind(d,h){return async function p({name:Z,query:query={},user:D}){const K=S,u=Date['now'](),n=h['get'](Z);assertOperation(n,'read',D);const X=Math[K(0x100)](Math['max'](query['limit']??0x14,0x1),0xc8),Y=Math[K(0x101)](query['offset']??0x0,0x0),w=buildFilters(n,query[K(0x102)],0x1,d['pg']),y=buildSort(n,query['sort']);if(!Number[K(0x103)](X)||!Number['isFinite'](Y))throw new ValidationError('Invalid\x20pagination');const Q=K(0x104)+readableFields(n)['join'](',\x20')+'\x20'+('FROM\x20'+qt(n['table']))+(''+w[K(0x105)]+y+'\x20')+('LIMIT\x20$'+(w['values'][K(0x106)]+0x1)+'\x20')+('OFFSET\x20$'+(w['values']['length']+0x2)),F=await d['pg'][K(0x107)](Q,[...w['values'],X,Y]),B=F['rows'];return await addDictionaryLookupData(B,n['fields'],d[K(0x108)]),await addTableLookupData(B,n['fields'],d['pg']),addFileToken(B,n['fields'],d['file']),{'limit':X,'offset':Y,'total':F[K(0x109)],'time':Date['now']()-u,'rows':B};};}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ResourceDependencies, ResourceUser } from "../resource.types.js";
|
|
2
|
+
import type { ResourceRegistry } from "../resource.registry.js";
|
|
3
|
+
import type { AppContext } from "../../../context.js";
|
|
4
|
+
type UpdateRelationParams = {
|
|
5
|
+
name: string;
|
|
6
|
+
id: string | number;
|
|
7
|
+
relation: string;
|
|
8
|
+
relationId: string | number;
|
|
9
|
+
data: Record<string, unknown>;
|
|
10
|
+
user?: ResourceUser;
|
|
11
|
+
};
|
|
12
|
+
export declare function createUpdateRelation(deps: ResourceDependencies, registry: ResourceRegistry): ({ name, id, relation, relationId, data, user, }: UpdateRelationParams, ctx?: AppContext) => Promise<Record<string, unknown>>;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=update-relation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-relation.d.ts","sourceRoot":"","sources":["../../../../src/plugins/resource/services/update-relation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAC/E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAIhE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEtD,KAAK,oBAAoB,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,IAAI,CAAC,EAAE,YAAY,CAAC;CACvB,CAAC;AAEF,wBAAgB,oBAAoB,CAChC,IAAI,EAAE,oBAAoB,EAC1B,QAAQ,EAAE,gBAAgB,qDAI4D,oBAAoB,QAAQ,UAAU,KAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAUlK"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function v(){const K=['foreignKey','Relation\x20update\x20is\x20not\x20configured:\x20','resource'];v=function(){return K;};return v();}import{UnsupportedError}from'../../../errors.js';function S(d,h){d=d-0x1b5;const p=v();let Z=p[d];return Z;}import{createUpdate}from'./update.js';export function createUpdateRelation(d,h){const p=createUpdate(d,h);return async function Z({name:D,id:u,relation:n,relationId:X,data:Y,user:w},y){const B=S,Q=h['get'](D),F=Q['relations']?.[n];if(!F?.['resource']||!F[B(0x1b5)])throw new UnsupportedError(B(0x1b6)+n);return p({'name':F[B(0x1b7)],'id':X,'data':Y,'user':w},y);};}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import type { ResourceDependencies, ResourceUser } from "../resource.types.js";
|
|
2
2
|
import type { ResourceRegistry } from "../resource.registry.js";
|
|
3
|
-
|
|
3
|
+
import { AppContext } from "../../../context.js";
|
|
4
|
+
type UpdateParams = {
|
|
4
5
|
name: string;
|
|
5
6
|
id: string | number;
|
|
6
7
|
data: Record<string, unknown>;
|
|
7
8
|
user?: ResourceUser;
|
|
8
|
-
}
|
|
9
|
+
};
|
|
10
|
+
export declare function createUpdate(deps: ResourceDependencies, registry: ResourceRegistry): ({ name, id, data, user, }: UpdateParams, ctx?: AppContext) => Promise<Record<string, unknown>>;
|
|
11
|
+
export {};
|
|
9
12
|
//# sourceMappingURL=update.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../../src/plugins/resource/services/update.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAG/E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../../src/plugins/resource/services/update.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAG/E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAGhE,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,KAAK,YAAY,GAAG;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,IAAI,CAAC,EAAE,YAAY,CAAC;CACrB,CAAC;AACF,wBAAgB,YAAY,CAC1B,IAAI,EAAE,oBAAoB,EAC1B,QAAQ,EAAE,gBAAgB,+BAE8B,YAAY,QAAQ,UAAU,KAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CA4C1H"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{NotFoundError,ValidationError}from'../../../errors.js';function v(){const O=['length','map','SET\x20','RETURNING\x20','rows','table','write','module','name','update'];v=function(){return O;};return v();}function S(d,h){d=d-0x1aa;const p=v();let Z=p[d];return Z;}import{assertOperation}from'../utils/permissions.js';import{qi,qt,readableFields,writableData}from'../utils/sql.js';import{validateInputData}from'../utils/fields.js';import{clearTableLookupCache}from'./add-table-lookup-data.js';export function createUpdate(d,h){return async function p({name:Z,id:D,data:u,user:n},X){const M=S,Y=h['get'](Z);assertOperation(Y,'update',n);const w=writableData(Y,u);if(!w[M(0x1aa)])throw new ValidationError('No\x20writable\x20fields');const y=X?.['pg']??d['pg'];validateInputData({'resource':Y,'data':u,'update':!![]}),delete u['user_type'];const Q=w[M(0x1ab)](([g],s)=>qi(g)+'\x20=\x20$'+(s+0x1)),F=[...w[M(0x1ab)](([,g])=>g),D],B=await y['query']('UPDATE\x20'+qt(Y['table'])+'\x20'+(M(0x1ac)+Q['join'](',\x20')+'\x20')+('WHERE\x20'+qi(Y['key'])+'\x20=\x20$'+(w['length']+0x1)+'\x20')+(M(0x1ad)+readableFields(Y)['join'](',\x20')),F),K=B[M(0x1ae)][0x0];if(!K)throw new NotFoundError(Z+':'+D);return clearTableLookupCache(Y[M(0x1af)],y),await(X?.['audit']??d['audit'])?.[M(0x1b0)]({'userId':n?.['id'],'module':Y[M(0x1b1)],'resource':Y[M(0x1b2)],'resourceId':D,'action':M(0x1b3),'fields':Object['keys'](u)}),K;};}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { DatabaseAdapter } from "../../pg.js";
|
|
2
|
+
export type AutoIndexType = "text" | "btree" | "gist";
|
|
3
|
+
export declare function autoIndex(table: string, column: string, type: AutoIndexType | undefined, pg: DatabaseAdapter): void;
|
|
4
|
+
//# sourceMappingURL=auto-index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/resource/utils/auto-index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAGnD,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;AAItD,wBAAgB,SAAS,CACrB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,aAAa,YAAU,EAC7B,EAAE,EAAE,eAAe,GACpB,IAAI,CAWN"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{qi,qt}from'./sql.js';function S(d,h){d=d-0x11c;const p=v();let Z=p[d];return Z;}const requestedIndexes=new WeakMap();function v(){const y=['get','set','has','split','public','replace','rowCount','CREATE\x20INDEX\x20IF\x20NOT\x20EXISTS\x20',')\x20text_pattern_ops)','\x20USING\x20'];v=function(){return y;};return v();}export function autoIndex(d,h,p='btree',Z){const Y=S,D=requestedIndexes[Y(0x11c)](Z)??new Set();requestedIndexes[Y(0x11d)](Z,D);const u=d+':'+h+':'+p;if(D[Y(0x11e)](u))return;D['add'](u),void ensureIndex(d,h,p,Z)['catch'](()=>{D['delete'](u);});}async function ensureIndex(d,h,p,Z){const w=S,D=d[w(0x11f)]('.'),u=D['length']===0x2?D[0x0]:w(0x120),n=(d+'_'+h+'_'+p+'_idx')[w(0x121)](/[^A-Za-z0-9_]/g,'_'),X=await Z['query']('SELECT\x201\x20FROM\x20pg_indexes\x20WHERE\x20schemaname\x20=\x20$1\x20AND\x20indexname\x20=\x20$2',[u,n]);if(X[w(0x122)])return;if(p==='text'){await Z['query']('CREATE\x20EXTENSION\x20IF\x20NOT\x20EXISTS\x20pg_trgm'),await Z['query'](w(0x123)+qi(n+'_l')+'\x20ON\x20'+qt(d)+'\x20USING\x20btree\x20(lower('+qi(h)+w(0x124)),await Z['query'](w(0x123)+qi(n)+'\x20ON\x20'+qt(d)+'\x20USING\x20gin\x20(lower('+qi(h)+')\x20gin_trgm_ops)');return;}await Z['query']('CREATE\x20INDEX\x20IF\x20NOT\x20EXISTS\x20'+qi(n)+'\x20ON\x20'+qt(d)+w(0x125)+p+'\x20('+qi(h)+')');}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
+
import { ResourceContract } from "../resource.types.js";
|
|
1
2
|
/**
|
|
2
3
|
* Provides Resource helpers for fields handling.
|
|
3
4
|
*/
|
|
4
|
-
export { readableFields, writableData, fieldColumn } from
|
|
5
|
+
export { readableFields, writableData, fieldColumn } from "./sql.js";
|
|
6
|
+
declare const validateInputData: ({ resource, data, update, }: {
|
|
7
|
+
resource: ResourceContract;
|
|
8
|
+
data: Record<string, unknown>;
|
|
9
|
+
update?: boolean;
|
|
10
|
+
}) => void;
|
|
11
|
+
export { validateInputData };
|
|
5
12
|
//# sourceMappingURL=fields.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../../../../src/plugins/resource/utils/fields.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../../../../src/plugins/resource/utils/fields.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD;;GAEG;AACH,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAErE,QAAA,MAAM,iBAAiB,gCAIpB;IACD,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,SA2EA,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{ValidationError}from'../../../errors.js';function S(d,h){d=d-0x163;const p=v();let Z=p[d];return Z;}export{readableFields,writableData,fieldColumn}from'./sql.js';const validateInputData=({resource:d,data:h,update:update=![]})=>{const D=S;for(const [p,Z]of Object['entries'](d['fields'])){if(Z['required']&&Z['writable']!==![]&&(h[p]===undefined||h[p]===null)&&!update)throw new ValidationError(D(0x163)+p);if(Z[D(0x164)]&&Z[D(0x165)]!==![]&&Object[D(0x166)](h,p)&&(h[p]===undefined||h[p]===null)&&update)throw new ValidationError('Required\x20field:\x20'+p);if(Z['minLength']&&typeof h[p]==='string'&&h[p][D(0x167)]<Z['minLength'])throw new ValidationError('minLength\x20not\x20met:\x20'+p);if(Z[D(0x168)]&&typeof h[p]==='string'&&h[p]['length']>Z['maxLength'])throw new ValidationError(D(0x169)+p);if(Z[D(0x16a)]&&typeof h[p]==='number'&&h[p]<Z['minimum'])throw new ValidationError(p+'\x20should\x20be\x20>=\x20'+Z['minimum']);if(Z['maximum']&&typeof h[p]===D(0x16b)&&h[p]>Z[D(0x16c)])throw new ValidationError(p+'\x20should\x20be\x20<=\x20'+Z['maximum']);if(Z['enum']&&h[p]&&!Z['enum'][D(0x16d)](h[p]))throw new ValidationError(p+D(0x16e)+Z['enum']['join'](',\x20')+')');if(Z['pattern']&&typeof h[p]==='string'&&!new RegExp(Z['pattern'])[D(0x16f)](h[p]))throw new ValidationError(p+D(0x170)+Z['pattern']+')');}};function v(){const u=['Required\x20field:\x20','required','writable','hasOwn','length','maxLength','maxLength\x20exceeded:\x20','minimum','number','maximum','includes','\x20should\x20be\x20one\x20of\x20(','test','\x20should\x20match\x20regular\x20expression\x20('];v=function(){return u;};return v();}export{validateInputData};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Provides Resource helpers for filters handling.
|
|
3
3
|
*/
|
|
4
|
-
import type { ResourceContract } from '../resource.types.js';
|
|
5
|
-
export declare function
|
|
4
|
+
import type { ResourceContract, ResourceDependencies } from '../resource.types.js';
|
|
5
|
+
export declare function parseFilterQuery(query: Record<string, unknown>): Record<string, unknown> | undefined;
|
|
6
|
+
export declare function buildFilters(resource: ResourceContract, filter: Record<string, unknown> | undefined, start?: number, pg?: ResourceDependencies['pg']): {
|
|
6
7
|
sql: string;
|
|
7
8
|
values: unknown[];
|
|
8
9
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filters.d.ts","sourceRoot":"","sources":["../../../../src/plugins/resource/utils/filters.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"filters.d.ts","sourceRoot":"","sources":["../../../../src/plugins/resource/utils/filters.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AASnF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CA2BpG;AAED,wBAAgB,YAAY,CACxB,QAAQ,EAAE,gBAAgB,EAC1B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EAC3C,KAAK,SAAI,EACT,EAAE,CAAC,EAAE,oBAAoB,CAAC,IAAI,CAAC;;;EAgElC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
const s=S;import{fieldColumn,qi}from'./sql.js';import{ValidationError}from'../../../errors.js';import{autoIndex}from'./auto-index.js';function S(d,h){d=d-0x15d;const p=v();let Z=p[d];return Z;}const filterOperators=new Set(['eq','ne','gt','gte','lt','lte','in','nin',s(0x15d),s(0x15e),s(0x15f)]);export function parseFilterQuery(d){const M=s,h={...isRecord(d[M(0x160)])?d['filter']:{}};for(const [p,Z]of Object['entries'](d)){const D=/^filter\[([^\]]+)\](?:\[([^\]]+)\])?$/[M(0x161)](p);if(!D)continue;const [,u,n]=D;if(!u)continue;if(!n){h[u]=Z;continue;}if(!filterOperators['has'](n))throw new ValidationError(M(0x162)+n);const X=isRecord(h[u])?h[u]:{};X[n]=(n==='in'||n==='nin')&&typeof Z==='string'?Z['split'](','):Z,h[u]=X;}return Object['keys'](h)[M(0x163)]?h:undefined;}export function buildFilters(d,h,p=0x1,Z){const O=s,D=[],u=[];for(const [n,X]of Object['entries'](h??{})){const Y=d['fields'][n];if(!Y||Y['filter']!==!![]&&Y['filterable']!==!![])throw new ValidationError('Field\x20is\x20not\x20filterable:\x20'+n);const w=qi(fieldColumn(d,n)),y=isRecord(X)?X:{'eq':X};for(const [Q,F]of Object['entries'](y)){if(!filterOperators[O(0x164)](Q))throw new ValidationError('Unsupported\x20filter\x20operator:\x20'+Q);if((Q==='like'||Q===O(0x15e))&&Y['type']!==O(0x165)&&Y['type']!==O(0x166))throw new ValidationError('Operator\x20'+Q+'\x20requires\x20a\x20text\x20field:\x20'+n);Z&&autoIndex(d[O(0x167)],fieldColumn(d,n),indexTypeFor(Y[O(0x168)],Q),Z);if(Q==='null'){D['push'](w+'\x20IS\x20'+(isTruthy(F)?'':'NOT\x20')+'NULL');continue;}if(Q==='in'||Q==='nin'){const g=Array[O(0x169)](F)?F:[F];if(g[O(0x163)]===0x0){D['push'](Q==='in'?O(0x16a):O(0x16b));continue;}u[O(0x16c)](g),D[O(0x16c)](w+'\x20'+(Q==='in'?'=\x20ANY':O(0x16d))+'($'+(p+u['length']-0x1)+')');continue;}const B={'eq':'=','ne':'<>','gt':'>','gte':'>=','lt':'<','lte':'<=','like':O(0x15d)},K='$'+(p+u[O(0x163)]);if(Q===O(0x15d)){u['push'](F+'%'),D['push']('lower('+w+O(0x16e)+K+')');continue;}u['push'](F),D['push'](w+'\x20'+B[Q]+'\x20'+K);}}return{'sql':D['length']?O(0x16f)+D['join'](O(0x170)):'','values':u};}function v(){const J=['like','ilike','null','filter','exec','Unsupported\x20filter\x20operator:\x20','length','has','string','text','table','type','isArray','FALSE','TRUE','push','<>\x20ALL',')\x20like\x20lower(','\x20WHERE\x20','\x20AND\x20','object','btree'];v=function(){return J;};return v();}function isRecord(d){const R=s;return typeof d===R(0x171)&&d!==null&&!Array[R(0x169)](d);}function isTruthy(d){return d===!![]||d==='true'||d==='1'||d===0x1;}function indexTypeFor(d,h){const E=s;if(h==='like'||h===E(0x15e))return'text';if(d==='geom'||d==='geometry')return'gist';return E(0x172);}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permissions.d.ts","sourceRoot":"","sources":["../../../../src/plugins/resource/utils/permissions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"permissions.d.ts","sourceRoot":"","sources":["../../../../src/plugins/resource/utils/permissions.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,gBAAgB,EAChB,iBAAiB,EACjB,YAAY,EACb,MAAM,sBAAsB,CAAC;AAI9B,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,gBAAgB,EAC1B,SAAS,EAAE,iBAAiB,EAC5B,IAAI,CAAC,EAAE,YAAY,QAqBpB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{ForbiddenError}from'../../../errors.js';function v(){const n=['public','admin'];v=function(){return n;};return v();}import{getContext}from'../../../index.js';function S(d,h){d=d-0xff;const p=v();let Z=p[d];return Z;}export function assertOperation(d,h,p){const u=S,Z=getContext()['config'];if(Z['debug'])return;if(!d['operations']['includes'](h))throw new ForbiddenError(d['name']+'.'+h+'\x20is\x20disabled');if(d['access']!==u(0xff)&&p===undefined)throw new ForbiddenError('Authentication\x20required');if(d['access']==='admin'&&p?.['type']!=='admin')throw new ForbiddenError('Admin\x20access\x20required');if(p?.['type']!==u(0x100)){const D=(d['permission']??d['name'])+':'+h;if(!p?.['permissions']?.['includes'](D))throw new ForbiddenError('Missing\x20permission:\x20'+D);}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sort.d.ts","sourceRoot":"","sources":["../../../../src/plugins/resource/utils/sort.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAG7D,wBAAgB,SAAS,CAAC,QAAQ,EAAE,gBAAgB,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"sort.d.ts","sourceRoot":"","sources":["../../../../src/plugins/resource/utils/sort.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAG7D,wBAAgB,SAAS,CAAC,QAAQ,EAAE,gBAAgB,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,UAgBpE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
function S(d,h){d=d-0x1bf;const p=v();let Z=p[d];return Z;}function v(){const w=['length','slice','sort','sortable','Field\x20is\x20not\x20sortable:\x20'];v=function(){return w;};return v();}import{fieldColumn,qi}from'./sql.js';import{ValidationError}from'../../../errors.js';export function buildSort(d,h){const X=S;if(!h?.[X(0x1bf)])return'';typeof h==='string'&&(h=[h]);const p=h['map'](Z=>{const Y=X,D=Z['startsWith']('-'),u=D?Z[Y(0x1c0)](0x1):Z,n=d['fields'][u];if(!n||n[Y(0x1c1)]!==!![]&&n[Y(0x1c2)]!==!![])throw new ValidationError(Y(0x1c3)+u);return qi(fieldColumn(d,u))+'\x20'+(D?'DESC':'ASC');});return'\x20ORDER\x20BY\x20'+p['join'](',\x20');}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const n=S;import{ValidationError}from'../../../errors.js';function v(){const y=['replace','Unknown\x20field:\x20','column','fields','\x20AS\x20','writable'];v=function(){return y;};return v();}export const quoteIdentifier=d=>'\x22'+d[n(0x171)](/"/g,'\x22\x22')+'\x22';export const quoteTable=d=>d['split']('.')['map'](quoteIdentifier)['join']('.');export function fieldColumn(d,h){const X=n;if(h===d['key'])return d['key'];const p=d['fields'][h];if(!p)throw new ValidationError(X(0x172)+h);return p[X(0x173)]??h;}export function readableFields(d){const Y=n,h=Object['entries'](d[Y(0x174)])['filter'](([,p])=>p['read']!==![]&&p['readable']!==![])['map'](([p,Z])=>quoteIdentifier(Z['column']??p)+Y(0x175)+quoteIdentifier(p));return!d['fields'][d['key']]&&h['unshift'](quoteIdentifier(d['key'])),h;}function S(d,h){d=d-0x171;const p=v();let Z=p[d];return Z;}export function writableData(d,h){const w=n,p=[];for(const [Z,D]of Object['entries'](h)){const u=d[w(0x174)][Z];if(!u||u['write']===![]||u[w(0x176)]===![])throw new ValidationError('Field\x20is\x20not\x20writable:\x20'+Z);p['push']([u[w(0x173)]??Z,D]);}return p;}export const qi=quoteIdentifier;export const qt=quoteTable;
|
package/dist/shared/getIP.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function S(d,h){d=d-0x90;const p=v();let Z=p[d];return Z;}const h=S,getIP=d=>(d[h(0x90)]?.['x-real-ip']||d['headers']?.[h(0x91)]||d['ip']||d[h(0x92)]?.['remoteAddress']||'')['split'](':')['pop']();function v(){const p=['headers','x-forwarded-for','connection'];v=function(){return p;};return v();}export default getIP;
|
package/dist/type.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { FastifySchema } from "fastify";
|
|
2
|
+
/** Рівень доступу до HTTP API-маршруту. */
|
|
3
|
+
export type RouteAccess = "public" | "user" | "admin";
|
|
4
|
+
/** Декларація права у форматі `ресурс:дія`; перевірка прав тимчасово не активна. */
|
|
5
|
+
export type RoutePermission = `${string}:${string}`;
|
|
6
|
+
type AccessMetadata = {
|
|
7
|
+
/** Групи маршруту для OpenAPI/Swagger. */
|
|
8
|
+
tags: string[];
|
|
9
|
+
/** Код пакета, якому належить маршрут. */
|
|
10
|
+
package: string;
|
|
11
|
+
/** Короткий заголовок операції в OpenAPI/Swagger. */
|
|
12
|
+
summary: string;
|
|
13
|
+
/** Розгорнутий опис операції в OpenAPI/Swagger. */
|
|
14
|
+
description: string;
|
|
15
|
+
/** Активний рівень доступу: `public`, `user` або `admin`. */
|
|
16
|
+
access: RouteAccess;
|
|
17
|
+
/** Декларація потрібних прав; їхня runtime-валідація та перевірка тимчасово не активні. */
|
|
18
|
+
permissions: RoutePermission[];
|
|
19
|
+
};
|
|
20
|
+
/** Повна схема Fastify і метадані маршруту API. */
|
|
21
|
+
export type ApiRouteSchema = FastifySchema & AccessMetadata;
|
|
22
|
+
/** Короткий опис зареєстрованого HTTP API-маршруту. */
|
|
23
|
+
export interface ApiRouteShort {
|
|
24
|
+
method: string;
|
|
25
|
+
endpoint: string;
|
|
26
|
+
package: string;
|
|
27
|
+
}
|
|
28
|
+
/** Розширений опис маршруту з OpenAPI та access metadata. */
|
|
29
|
+
export interface ApiRoute extends ApiRouteShort {
|
|
30
|
+
tags: string[];
|
|
31
|
+
summary: string;
|
|
32
|
+
description: string;
|
|
33
|
+
access: RouteAccess;
|
|
34
|
+
permissions: RoutePermission[];
|
|
35
|
+
}
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../src/type.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,2CAA2C;AAC3C,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;AACtD,oFAAoF;AACpF,MAAM,MAAM,eAAe,GAAG,GAAG,MAAM,IAAI,MAAM,EAAE,CAAC;AAGpD,KAAK,cAAc,GAAG;IACpB,0CAA0C;IAC1C,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,0CAA0C;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,qDAAqD;IACrD,OAAO,EAAE,MAAM,CAAC;IAChB,mDAAmD;IACnD,WAAW,EAAE,MAAM,CAAC;IACpB,6DAA6D;IAC7D,MAAM,EAAE,WAAW,CAAC;IACpB,2FAA2F;IAC3F,WAAW,EAAE,eAAe,EAAE,CAAC;CAChC,CAAC;AAEF,mDAAmD;AACnD,MAAM,MAAM,cAAc,GAAG,aAAa,GAAG,cAAc,CAAC;AAE5D,uDAAuD;AACvD,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,6DAA6D;AAC7D,MAAM,WAAW,QAAS,SAAQ,aAAa;IAC7C,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,WAAW,CAAC;IACpB,WAAW,EAAE,eAAe,EAAE,CAAC;CAChC"}
|
package/dist/type.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
|
@@ -6,29 +6,29 @@ AS $$
|
|
|
6
6
|
SELECT encode(gen_random_bytes(6), 'hex')::text
|
|
7
7
|
$$;
|
|
8
8
|
|
|
9
|
+
DROP SCHEMA IF EXISTS admin CASCADE;
|
|
9
10
|
CREATE SCHEMA IF NOT EXISTS admin;
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
CREATE TABLE IF NOT EXISTS admin.users (
|
|
13
14
|
uid text PRIMARY KEY DEFAULT next_id(),
|
|
14
15
|
login text,
|
|
15
|
-
|
|
16
|
+
password_hash text,
|
|
16
17
|
first_name text,
|
|
17
18
|
middle_name text,
|
|
18
19
|
last_name text,
|
|
19
20
|
email text,
|
|
20
21
|
phone text,
|
|
21
22
|
avatar text,
|
|
23
|
+
twofa boolean NOT NULL DEFAULT false,
|
|
22
24
|
enabled boolean DEFAULT true,
|
|
23
25
|
user_personal_code text,
|
|
24
26
|
last_activity_date timestamptz,
|
|
25
|
-
user_type text NOT NULL DEFAULT 'regular',
|
|
26
|
-
salt text,
|
|
27
|
+
user_type text NOT NULL DEFAULT 'regular',
|
|
27
28
|
created_by text,
|
|
28
29
|
updated_by text,
|
|
29
30
|
created_at timestamp NOT NULL DEFAULT now(),
|
|
30
|
-
updated_at timestamp NOT NULL DEFAULT now(),
|
|
31
|
-
twofa boolean NOT NULL DEFAULT false,
|
|
31
|
+
updated_at timestamp NOT NULL DEFAULT now(),
|
|
32
32
|
UNIQUE (user_personal_code)
|
|
33
33
|
);
|
|
34
34
|
|
|
@@ -107,18 +107,19 @@ CREATE TABLE IF NOT EXISTS admin.user_roles (
|
|
|
107
107
|
|
|
108
108
|
CREATE TABLE IF NOT EXISTS admin.role_access (
|
|
109
109
|
access_id text PRIMARY KEY DEFAULT next_id(),
|
|
110
|
-
|
|
110
|
+
|
|
111
111
|
role_id text REFERENCES admin.roles(role_id),
|
|
112
|
-
user_uid text,
|
|
112
|
+
user_uid text REFERENCES admin.users(uid),
|
|
113
113
|
scope text,
|
|
114
114
|
actions text[],
|
|
115
|
-
|
|
115
|
+
resource text,
|
|
116
116
|
|
|
117
|
-
created_by text,
|
|
118
|
-
updated_by text,
|
|
117
|
+
created_by text REFERENCES admin.users(uid) ,
|
|
118
|
+
updated_by text REFERENCES admin.users(uid) ,
|
|
119
119
|
created_at timestamp NOT NULL DEFAULT now(),
|
|
120
120
|
updated_at timestamp NOT NULL DEFAULT now(),
|
|
121
|
-
UNIQUE (
|
|
121
|
+
UNIQUE (resource, user_uid),
|
|
122
|
+
UNIQUE (resource, role_id)
|
|
122
123
|
);
|
|
123
124
|
|
|
124
125
|
|
|
@@ -131,8 +132,8 @@ CREATE TABLE IF NOT EXISTS admin.dictionaries (
|
|
|
131
132
|
source text NOT NULL DEFAULT 'git' CHECK (source IN ('git', 'custom')),
|
|
132
133
|
editable boolean NOT NULL DEFAULT false,
|
|
133
134
|
system boolean NOT NULL DEFAULT false,
|
|
134
|
-
created_by text,
|
|
135
|
-
updated_by text,
|
|
135
|
+
created_by text REFERENCES admin.users(uid) ,
|
|
136
|
+
updated_by text REFERENCES admin.users(uid) ,
|
|
136
137
|
created_at timestamp NOT NULL DEFAULT now(),
|
|
137
138
|
updated_at timestamp NOT NULL DEFAULT now()
|
|
138
139
|
);
|
|
@@ -150,6 +151,8 @@ CREATE TABLE IF NOT EXISTS admin.dictionary_items (
|
|
|
150
151
|
active boolean NOT NULL DEFAULT true,
|
|
151
152
|
system boolean NOT NULL DEFAULT false,
|
|
152
153
|
metadata jsonb,
|
|
154
|
+
created_by text REFERENCES admin.users(uid) ,
|
|
155
|
+
updated_by text REFERENCES admin.users(uid) ,
|
|
153
156
|
created_at timestamp NOT NULL DEFAULT now(),
|
|
154
157
|
updated_at timestamp NOT NULL DEFAULT now(),
|
|
155
158
|
UNIQUE (dictionary_id, code)
|
|
@@ -161,9 +164,9 @@ CREATE TABLE IF NOT EXISTS admin.notes (
|
|
|
161
164
|
resource text NOT NULL,
|
|
162
165
|
resource_id text NOT NULL,
|
|
163
166
|
body text NOT NULL,
|
|
164
|
-
created_by text,
|
|
167
|
+
created_by text REFERENCES admin.users(uid) ,
|
|
165
168
|
created_at timestamptz DEFAULT now(),
|
|
166
|
-
updated_by text,
|
|
169
|
+
updated_by text REFERENCES admin.users(uid) ,
|
|
167
170
|
updated_at timestamptz DEFAULT now()
|
|
168
171
|
);
|
|
169
172
|
|
|
@@ -184,9 +187,9 @@ CREATE TABLE IF NOT EXISTS admin.files (
|
|
|
184
187
|
file_path text,
|
|
185
188
|
verified boolean DEFAULT false,
|
|
186
189
|
resized boolean,
|
|
187
|
-
created_by text,
|
|
190
|
+
created_by text REFERENCES admin.users(uid) ,
|
|
188
191
|
created_at timestamptz DEFAULT now(),
|
|
189
|
-
updated_by text,
|
|
192
|
+
updated_by text REFERENCES admin.users(uid) ,
|
|
190
193
|
updated_at timestamptz default now()
|
|
191
194
|
);
|
|
192
195
|
|
|
@@ -199,9 +202,9 @@ CREATE TABLE IF NOT EXISTS admin.settings (
|
|
|
199
202
|
key text NOT NULL,
|
|
200
203
|
value jsonb,
|
|
201
204
|
|
|
202
|
-
updated_by text,
|
|
205
|
+
updated_by text REFERENCES admin.users(uid) ,
|
|
203
206
|
updated_at timestamptz NOT NULL DEFAULT now(),
|
|
204
|
-
created_by text,
|
|
207
|
+
created_by text REFERENCES admin.users(uid) ,
|
|
205
208
|
created_at timestamptz NOT NULL DEFAULT now()
|
|
206
209
|
);
|
|
207
210
|
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
ALTER TABLE admin.users
|
|
2
|
+
ADD CONSTRAINT users_created_by_fkey
|
|
3
|
+
FOREIGN KEY (created_by) REFERENCES admin.users(uid) ON DELETE SET NULL,
|
|
4
|
+
ADD CONSTRAINT users_updated_by_fkey
|
|
5
|
+
FOREIGN KEY (updated_by) REFERENCES admin.users(uid) ON DELETE SET NULL;
|
|
6
|
+
|
|
7
|
+
ALTER TABLE admin.user_roles
|
|
8
|
+
ADD CONSTRAINT user_roles_created_by_fkey
|
|
9
|
+
FOREIGN KEY (created_by) REFERENCES admin.users(uid) ON DELETE SET NULL,
|
|
10
|
+
ADD CONSTRAINT user_roles_updated_by_fkey
|
|
11
|
+
FOREIGN KEY (updated_by) REFERENCES admin.users(uid) ON DELETE SET NULL;
|
|
12
|
+
|
|
13
|
+
ALTER TABLE admin.role_access
|
|
14
|
+
ADD CONSTRAINT role_access_user_uid_fkey
|
|
15
|
+
FOREIGN KEY (user_uid) REFERENCES admin.users(uid) ON DELETE CASCADE,
|
|
16
|
+
ADD CONSTRAINT role_access_created_by_fkey
|
|
17
|
+
FOREIGN KEY (created_by) REFERENCES admin.users(uid) ON DELETE SET NULL,
|
|
18
|
+
ADD CONSTRAINT role_access_updated_by_fkey
|
|
19
|
+
FOREIGN KEY (updated_by) REFERENCES admin.users(uid) ON DELETE SET NULL;
|
|
20
|
+
|
|
21
|
+
ALTER TABLE admin.dictionaries
|
|
22
|
+
ADD CONSTRAINT dictionaries_created_by_fkey
|
|
23
|
+
FOREIGN KEY (created_by) REFERENCES admin.users(uid) ON DELETE SET NULL,
|
|
24
|
+
ADD CONSTRAINT dictionaries_updated_by_fkey
|
|
25
|
+
FOREIGN KEY (updated_by) REFERENCES admin.users(uid) ON DELETE SET NULL;
|
|
26
|
+
|
|
27
|
+
ALTER TABLE admin.notes
|
|
28
|
+
ADD CONSTRAINT notes_created_by_fkey
|
|
29
|
+
FOREIGN KEY (created_by) REFERENCES admin.users(uid) ON DELETE SET NULL,
|
|
30
|
+
ADD CONSTRAINT notes_updated_by_fkey
|
|
31
|
+
FOREIGN KEY (updated_by) REFERENCES admin.users(uid) ON DELETE SET NULL;
|
|
32
|
+
|
|
33
|
+
ALTER TABLE admin.files
|
|
34
|
+
ADD CONSTRAINT files_created_by_fkey
|
|
35
|
+
FOREIGN KEY (created_by) REFERENCES admin.users(uid) ON DELETE SET NULL,
|
|
36
|
+
ADD CONSTRAINT files_updated_by_fkey
|
|
37
|
+
FOREIGN KEY (updated_by) REFERENCES admin.users(uid) ON DELETE SET NULL;
|
|
38
|
+
|
|
39
|
+
ALTER TABLE admin.settings
|
|
40
|
+
ADD CONSTRAINT settings_created_by_fkey
|
|
41
|
+
FOREIGN KEY (created_by) REFERENCES admin.users(uid) ON DELETE SET NULL,
|
|
42
|
+
ADD CONSTRAINT settings_updated_by_fkey
|
|
43
|
+
FOREIGN KEY (updated_by) REFERENCES admin.users(uid) ON DELETE SET NULL;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
DO $$
|
|
2
|
+
declare
|
|
3
|
+
_password_column_exists boolean;
|
|
4
|
+
BEGIN
|
|
5
|
+
IF to_regclass('admin.users') IS NOT NULL then
|
|
6
|
+
|
|
7
|
+
select true from pg_attribute where attrelid::regclass::text='admin.users' and attname='password' into _password_column_exists;
|
|
8
|
+
|
|
9
|
+
IF _password_column_exists is true then
|
|
10
|
+
alter table admin.users add column if not exists password_hash text;
|
|
11
|
+
update admin.users set password_hash = password where password is not null and password_hash is null;
|
|
12
|
+
alter table admin.users drop column if exists password;
|
|
13
|
+
END IF;
|
|
14
|
+
|
|
15
|
+
alter table admin.users add column if not exists twofa boolean not null default false;
|
|
16
|
+
|
|
17
|
+
END IF;
|
|
18
|
+
|
|
19
|
+
END
|
|
20
|
+
$$;
|
|
21
|
+
|
|
22
|
+
CREATE OR REPLACE FUNCTION next_id()
|
|
23
|
+
RETURNS text AS
|
|
24
|
+
$BODY$
|
|
25
|
+
DECLARE
|
|
26
|
+
|
|
27
|
+
BEGIN
|
|
28
|
+
return encode(public.gen_random_bytes(6), 'hex');
|
|
29
|
+
END;
|
|
30
|
+
$BODY$
|
|
31
|
+
LANGUAGE plpgsql VOLATILE
|
|
32
|
+
COST 100;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opengis/fcore",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.10",
|
|
4
4
|
"description": "Reusable backend foundation for OpenGIS Node.js applications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -26,7 +26,10 @@
|
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"bin": {
|
|
29
|
-
"fcore-migrate": "./dist/migrations/cli.js"
|
|
29
|
+
"fcore-migrate": "./dist/migrations/cli.js",
|
|
30
|
+
"fcore-adduser": "./dist/modules/auth/adduser-cli.js",
|
|
31
|
+
"fcore-passwd": "./dist/modules/auth/passwd-cli.js",
|
|
32
|
+
"fcore-permission": "./dist/modules/auth/permission-cli.js"
|
|
30
33
|
},
|
|
31
34
|
"scripts": {
|
|
32
35
|
"clean": "rm -rf dist",
|
|
@@ -34,9 +37,11 @@
|
|
|
34
37
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
35
38
|
"test": "node --test --import tsx test/**/*.test.ts",
|
|
36
39
|
"test-env": "node --env-file=.env.test --test --import tsx test/**/env.test.ts",
|
|
37
|
-
"dev": "
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
+
"dev": "bun ./server.ts",
|
|
41
|
+
"adduser": "node --import tsx ./src/modules/auth/adduser-cli.ts",
|
|
42
|
+
"passwd": "node --import tsx ./src/modules/auth/passwd-cli.ts",
|
|
43
|
+
"permission": "node --import tsx ./src/modules/auth/permission-cli.ts",
|
|
44
|
+
"migrate": "node --import tsx src/migrations/cli.ts",
|
|
40
45
|
"migration-test": "node --env-file=.env.test --import tsx src/migrations/cli.ts",
|
|
41
46
|
"prepublishOnly": "npm run build",
|
|
42
47
|
"prepublishOnly1": "npm run build && npm test",
|
|
@@ -48,7 +53,6 @@
|
|
|
48
53
|
"node": ">=20"
|
|
49
54
|
},
|
|
50
55
|
"dependencies": {
|
|
51
|
-
"@sinclair/typebox": "^0.34.52",
|
|
52
56
|
"@aws-sdk/client-s3": "3.1125.0",
|
|
53
57
|
"@aws-sdk/lib-storage": "3.1125.0",
|
|
54
58
|
"@fastify/cookie": "11.1.2",
|
|
@@ -56,12 +60,13 @@
|
|
|
56
60
|
"@fastify/passport": "4.0.2",
|
|
57
61
|
"@fastify/rate-limit": "11.2.0",
|
|
58
62
|
"@fastify/session": "11.1.2",
|
|
63
|
+
"@sinclair/typebox": "^0.34.52",
|
|
59
64
|
"apache-crypt": "1.2.6",
|
|
60
65
|
"dotenv": "17.4.2",
|
|
61
|
-
"fastify-plugin": "6.0.0",
|
|
62
66
|
"fastify-session-redis-store": "7.1.2",
|
|
63
67
|
"file-type": "22.0.2",
|
|
64
68
|
"ioredis": "6.0.0",
|
|
69
|
+
"jose": "^6.2.12",
|
|
65
70
|
"otplib": "13.5.0",
|
|
66
71
|
"pg": "8.23.0",
|
|
67
72
|
"pino": "10.3.1",
|
|
@@ -85,4 +90,4 @@
|
|
|
85
90
|
"vitest": "4.1.11"
|
|
86
91
|
},
|
|
87
92
|
"license": "UNLICENSED"
|
|
88
|
-
}
|
|
93
|
+
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Exports the public surface of this FCore module.
|
|
3
|
-
*/
|
|
4
|
-
export * from './route.js';
|
|
5
|
-
export * from './services/login.js';
|
|
6
|
-
export * from './services/logout.js';
|
|
7
|
-
export * from './services/get-current-user.js';
|
|
8
|
-
export * from './services/verify-two-factor.js';
|
|
9
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,iCAAiC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(function(D,L){var u=p,s=D();while(!![]){try{var X=parseInt(u(0x13d))/0x1+-parseInt(u(0x13c))/0x2+parseInt(u(0x13a))/0x3*(-parseInt(u(0x139))/0x4)+-parseInt(u(0x13f))/0x5*(-parseInt(u(0x138))/0x6)+-parseInt(u(0x13b))/0x7+parseInt(u(0x140))/0x8*(parseInt(u(0x13e))/0x9)+parseInt(u(0x141))/0xa;if(X===L)break;else s['push'](s['shift']());}catch(M){s['push'](s['shift']());}}}(m,0x1d6b9));export*from'./route.js';export*from'./services/login.js';export*from'./services/logout.js';export*from'./services/get-current-user.js';export*from'./services/verify-two-factor.js';function p(D,L){D=D-0x138;var s=m();var X=s[D];return X;}function m(){var o=['163010nlDWSg','182760GfkcnL','1561670eACybB','42cqGqIv','85368zVBqKO','18TbexbA','847441EsuIsX','273684NJUOYy','30701HrMfwi','36eRoojh'];m=function(){return o;};return m();}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ContextDependencies } from "../../../context.js";
|
|
2
|
-
export default function login({ ip, login, password }: {
|
|
3
|
-
ip: string;
|
|
4
|
-
login: string;
|
|
5
|
-
password: string;
|
|
6
|
-
}, { config, pg, logger, redis, }: Pick<ContextDependencies, "config" | "pg" | "logger" | "redis">): Promise<{
|
|
7
|
-
user: any;
|
|
8
|
-
redirectUrl: string;
|
|
9
|
-
}>;
|
|
10
|
-
//# sourceMappingURL=login.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../../../src/modules/auth/services/login.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1D,wBAA8B,KAAK,CACjC,EAAE,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,EACxE,EACE,MAAM,EACN,EAAE,EACF,MAAM,EACN,KAAK,GACN,EAAE,IAAI,CAAC,mBAAmB,EAAE,QAAQ,GAAG,IAAI,GAAG,QAAQ,GAAG,OAAO,CAAC;;;GAiCnE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(function(D,L){const y=p,s=D();while(!![]){try{const M=-parseInt(y(0x195))/0x1+-parseInt(y(0x17d))/0x2+parseInt(y(0x194))/0x3*(-parseInt(y(0x199))/0x4)+parseInt(y(0x196))/0x5*(-parseInt(y(0x184))/0x6)+-parseInt(y(0x183))/0x7+-parseInt(y(0x181))/0x8+-parseInt(y(0x18e))/0x9*(-parseInt(y(0x191))/0xa);if(M===L)break;else s['push'](s['shift']());}catch(u){s['push'](s['shift']());}}}(m,0x955a6));function p(D,L){D=D-0x17b;const s=m();let X=s[D];return X;}import X from'./verifyPassword.js';function m(){const c=['base','AuAxd','login','metrics','redirectUrl','2547wasnKP','empty\x20redis','logger','157490HqCvKz','link','user.login','1680dfylLD','115308HsjJkw','176885kptDPm','empty\x20pg','tFlVp','4372xtfmBE','auth','hzgzz','948064ZJSgWc','user','jpQJF','afterLogin','7426960IxMipD','password','6312292LmIpLo','138IQzBbO','twofa','twoFactor','empty\x20user','kmKpG'];m=function(){return c;};return m();}export default async function login({ip:M,login:u,password:o},{config:r,pg:i,logger:q,redis:R}){const E=p,B={'AuAxd':function(z,l){return z(l);},'kmKpG':E(0x197),'jpQJF':E(0x18f),'hzgzz':function(z,l,t){return z(l,t);},'tFlVp':E(0x187)};if(!i)throw B[E(0x18a)](Error,B[E(0x188)]);if(!R)throw B[E(0x18a)](Error,B[E(0x17f)]);const O={};O[E(0x18b)]=u,O[E(0x182)]=o,O['ip']=M;const h={};h['pg']=i,h[E(0x190)]=q;const {user:g}=await B[E(0x17c)](X,O,h);if(!g)throw new Error(B[E(0x198)]);q[E(0x18c)](E(0x193));const J=g[E(0x185)]?r[E(0x17b)][E(0x192)]?.[E(0x186)]?.[E(0x18b)]:r[E(0x17b)][E(0x192)]?.[E(0x189)][E(0x180)],S={};return S[E(0x17e)]=g,S[E(0x18d)]=J||'/',S;}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Implements the logout application service for its module.
|
|
3
|
-
*/
|
|
4
|
-
import type { AppContext, User } from "../../../context.js";
|
|
5
|
-
export default function logout(params: {
|
|
6
|
-
sessionId?: string;
|
|
7
|
-
user?: User;
|
|
8
|
-
}, ctx: AppContext): Promise<void>;
|
|
9
|
-
//# sourceMappingURL=logout.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logout.d.ts","sourceRoot":"","sources":["../../../../src/modules/auth/services/logout.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC5D,wBAA8B,MAAM,CAClC,MAAM,EAAE;IACN,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,IAAI,CAAC;CACb,EACD,GAAG,EAAE,UAAU,GACd,OAAO,CAAC,IAAI,CAAC,CAQf"}
|