@opengis/fcore 0.0.1-beta.26 → 0.0.1-beta.27
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/LICENSE +3 -3
- package/README.md +71 -71
- package/dist/config.js +1 -1
- package/dist/context.js +1 -1
- package/dist/errors.js +1 -1
- package/dist/fastify.js +1 -1
- package/dist/fcore.js +1 -1
- package/dist/migrations/cli.js +1 -1
- package/dist/migrations/runner.js +1 -1
- package/dist/modules/auth/adduser-cli.js +1 -1
- package/dist/modules/auth/passwd-cli.js +1 -1
- package/dist/modules/auth/permission-cli.js +1 -1
- package/dist/modules/auth/route.js +1 -1
- package/dist/modules/auth/schema.js +1 -1
- package/dist/modules/auth/services/change-password.js +1 -1
- package/dist/modules/auth/services/get-current-user.js +1 -1
- package/dist/modules/auth/services/registration.js +1 -1
- package/dist/modules/auth/services/verify-two-factor.js +1 -1
- package/dist/modules/file/mime.js +1 -1
- package/dist/modules/file/route.js +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.js +1 -1
- package/dist/modules/file/services/upload-file.js +1 -1
- 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 +13 -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.js +1 -1
- package/dist/modules/resource/services/create-resource.js +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.js +1 -1
- package/dist/modules/resource/services/generate-resource-code.d.ts +16 -0
- package/dist/modules/resource/services/generate-resource-code.d.ts.map +1 -0
- package/dist/modules/resource/services/generate-resource-code.js +1 -0
- package/dist/modules/resource/services/get-resource-schema.d.ts +6 -0
- package/dist/modules/resource/services/get-resource-schema.d.ts.map +1 -0
- package/dist/modules/resource/services/get-resource-schema.js +1 -0
- package/dist/modules/resource/services/get-resource.js +1 -1
- package/dist/modules/resource/services/list-resource-as-user.d.ts +8 -0
- package/dist/modules/resource/services/list-resource-as-user.d.ts.map +1 -0
- package/dist/modules/resource/services/list-resource-as-user.js +1 -0
- package/dist/modules/resource/services/list-resource-list.d.ts +20 -0
- package/dist/modules/resource/services/list-resource-list.d.ts.map +1 -0
- package/dist/modules/resource/services/list-resource-list.js +1 -0
- 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.js +1 -1
- package/dist/modules/resource/services/suggest-resource.js +1 -1
- package/dist/modules/resource/services/update-resource-relation.js +1 -1
- 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.map +1 -1
- package/dist/modules/system/route.js +1 -1
- package/dist/modules/system/schema.d.ts +22 -0
- 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.js +1 -1
- package/dist/modules/system/services/get-access.js +1 -1
- package/dist/modules/system/services/get-api-list.js +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-resource-access.d.ts +23 -0
- package/dist/modules/system/services/get-resource-access.d.ts.map +1 -0
- package/dist/modules/system/services/get-resource-access.js +1 -0
- package/dist/modules/system/services/get-resource-scopes.d.ts +16 -0
- package/dist/modules/system/services/get-resource-scopes.d.ts.map +1 -0
- package/dist/modules/system/services/get-resource-scopes.js +1 -0
- package/dist/modules/system/services/get-system-log.js +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 +1 -0
- package/dist/modules/system/services/set-access.d.ts.map +1 -1
- package/dist/modules/system/services/set-access.js +1 -1
- package/dist/modules/system/services/set-resource-access.d.ts +18 -0
- package/dist/modules/system/services/set-resource-access.d.ts.map +1 -0
- package/dist/modules/system/services/set-resource-access.js +1 -0
- package/dist/modules/system/services/set-resource-scopes.d.ts +10 -0
- package/dist/modules/system/services/set-resource-scopes.d.ts.map +1 -0
- package/dist/modules/system/services/set-resource-scopes.js +1 -0
- package/dist/modules/system/services/update-dictionary.js +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/services/write-audit.js +1 -1
- package/dist/plugins/auth/get-user-permissions.js +1 -1
- package/dist/plugins/auth/index.js +1 -1
- package/dist/plugins/auth/verifyUser.js +1 -1
- package/dist/plugins/dictionary.js +1 -1
- package/dist/plugins/file.js +1 -1
- package/dist/plugins/jwt.js +1 -1
- package/dist/plugins/logger/index.js +1 -1
- package/dist/plugins/logger/transport.js +1 -1
- package/dist/plugins/pg.js +1 -1
- package/dist/plugins/redis.js +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 +18 -0
- package/dist/plugins/resource/resource.types.d.ts.map +1 -1
- package/dist/plugins/resource/services/add-dictionary-lookup-data.js +1 -1
- package/dist/plugins/resource/services/add-file-token.js +1 -1
- package/dist/plugins/resource/services/add-table-lookup-data.js +1 -1
- package/dist/plugins/resource/services/create-relation.js +1 -1
- package/dist/plugins/resource/services/create.js +1 -1
- package/dist/plugins/resource/services/delete-relation.js +1 -1
- package/dist/plugins/resource/services/delete.js +1 -1
- 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.js +1 -1
- 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/get-table-columns.js +1 -1
- package/dist/plugins/resource/services/update-relation.js +1 -1
- package/dist/plugins/resource/services/update.js +1 -1
- package/dist/plugins/resource/utils/auto-index.js +1 -1
- package/dist/plugins/resource/utils/fields.js +1 -1
- package/dist/plugins/resource/utils/filters.js +1 -1
- package/dist/plugins/resource/utils/permissions.js +1 -1
- package/dist/plugins/resource/utils/scope.d.ts +10 -0
- package/dist/plugins/resource/utils/scope.d.ts.map +1 -0
- package/dist/plugins/resource/utils/scope.js +1 -0
- package/dist/plugins/resource/utils/sort.js +1 -1
- package/dist/plugins/resource/utils/sql.js +1 -1
- package/dist/plugins/resource/utils/summary.d.ts +5 -1
- package/dist/plugins/resource/utils/summary.d.ts.map +1 -1
- package/dist/plugins/resource/utils/summary.js +1 -1
- package/dist/shared/getIP.js +1 -1
- package/migrations/20260903130000_move_notes_files_to_admin.sql +17 -17
- package/migrations/20260903140000_settings_nulls_not_distinct.sql +18 -18
- package/migrations/20260929120000_allow_user_only_role_scopes.sql +2 -0
- package/migrations/20260929_role_scope.sql +32 -0
- package/package.json +92 -92
package/LICENSE
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
Copyright (c) OpenGIS. All rights reserved.
|
|
2
|
-
|
|
3
|
-
Proprietary and confidential.
|
|
1
|
+
Copyright (c) OpenGIS. All rights reserved.
|
|
2
|
+
|
|
3
|
+
Proprietary and confidential.
|
package/README.md
CHANGED
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
# @opengis/fcore
|
|
2
|
-
|
|
3
|
-
Reusable backend foundation for OpenGIS Node.js applications: config, typed application context, PostgreSQL, Redis, S3 file storage, audit, trusted Resource CRUD, Core modules, Fastify integration and SQL migration runner.
|
|
4
|
-
|
|
5
|
-
## Install
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install @opengis/fcore
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Bootstrap
|
|
12
|
-
|
|
13
|
-
```ts
|
|
14
|
-
import { createFCore } from '@opengis/fcore';
|
|
15
|
-
import resources from './resources/index.js';
|
|
16
|
-
|
|
17
|
-
export const ctx = await createFCore({ resources });
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
```ts
|
|
21
|
-
import Fastify from 'fastify';
|
|
22
|
-
import fcoreFastify from '@opengis/fcore/fastify';
|
|
23
|
-
import { ctx } from './app.js';
|
|
24
|
-
|
|
25
|
-
const app = Fastify();
|
|
26
|
-
await app.register(fcoreFastify, { ctx });
|
|
27
|
-
await app.listen({ port: ctx.config.port });
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
## Resource
|
|
31
|
-
|
|
32
|
-
All dynamic table/column identifiers come from registered `ResourceContract` metadata. Values are SQL parameters.
|
|
33
|
-
|
|
34
|
-
## Migrations
|
|
35
|
-
|
|
36
|
-
Project SQL files stay in `./migrations`. Build the package/application, then run `fcore-migrate` or import `runMigrations()`.
|
|
37
|
-
|
|
38
|
-
## Module service convention
|
|
39
|
-
|
|
40
|
-
Module services are plain async functions with the canonical `service(params, ctx)` signature. `ctx` is passed explicitly from `fastify.ts` to each module `route.ts`; there is no `service.ts` or `createService()` factory.
|
|
41
|
-
|
|
42
|
-
## Structure
|
|
43
|
-
|
|
44
|
-
```bash
|
|
45
|
-
@opengis/fcore
|
|
46
|
-
├── src/
|
|
47
|
-
│ ├── plugins/
|
|
48
|
-
│ │ ├── logger/
|
|
49
|
-
│ │ ├── redis/
|
|
50
|
-
│ │ ├── pg/
|
|
51
|
-
│ │ ├── file/
|
|
52
|
-
│ │ ├── audit/
|
|
53
|
-
│ │ └── resource/
|
|
54
|
-
│ ├── modules/
|
|
55
|
-
│ │ ├── auth/
|
|
56
|
-
│ │ ├── access/
|
|
57
|
-
│ │ ├── resource/
|
|
58
|
-
│ │ ├── file/
|
|
59
|
-
│ │ ├── template/
|
|
60
|
-
│ │ └── system/
|
|
61
|
-
│ ├── migrations/
|
|
62
|
-
│ ├── config.ts # loadConfig
|
|
63
|
-
│ ├── context.ts # createContext, set, get
|
|
64
|
-
│ ├── errors.ts # standard Errors
|
|
65
|
-
│ ├── fastify.ts # fastify Plugins
|
|
66
|
-
│ ├── fcore.ts # createFcore
|
|
67
|
-
│ └── index.ts # export type, methods, etc
|
|
68
|
-
├── test/
|
|
69
|
-
├── engineering/
|
|
70
|
-
├── package.json
|
|
71
|
-
└── tsconfig.json
|
|
1
|
+
# @opengis/fcore
|
|
2
|
+
|
|
3
|
+
Reusable backend foundation for OpenGIS Node.js applications: config, typed application context, PostgreSQL, Redis, S3 file storage, audit, trusted Resource CRUD, Core modules, Fastify integration and SQL migration runner.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @opengis/fcore
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Bootstrap
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { createFCore } from '@opengis/fcore';
|
|
15
|
+
import resources from './resources/index.js';
|
|
16
|
+
|
|
17
|
+
export const ctx = await createFCore({ resources });
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import Fastify from 'fastify';
|
|
22
|
+
import fcoreFastify from '@opengis/fcore/fastify';
|
|
23
|
+
import { ctx } from './app.js';
|
|
24
|
+
|
|
25
|
+
const app = Fastify();
|
|
26
|
+
await app.register(fcoreFastify, { ctx });
|
|
27
|
+
await app.listen({ port: ctx.config.port });
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Resource
|
|
31
|
+
|
|
32
|
+
All dynamic table/column identifiers come from registered `ResourceContract` metadata. Values are SQL parameters.
|
|
33
|
+
|
|
34
|
+
## Migrations
|
|
35
|
+
|
|
36
|
+
Project SQL files stay in `./migrations`. Build the package/application, then run `fcore-migrate` or import `runMigrations()`.
|
|
37
|
+
|
|
38
|
+
## Module service convention
|
|
39
|
+
|
|
40
|
+
Module services are plain async functions with the canonical `service(params, ctx)` signature. `ctx` is passed explicitly from `fastify.ts` to each module `route.ts`; there is no `service.ts` or `createService()` factory.
|
|
41
|
+
|
|
42
|
+
## Structure
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
@opengis/fcore
|
|
46
|
+
├── src/
|
|
47
|
+
│ ├── plugins/
|
|
48
|
+
│ │ ├── logger/
|
|
49
|
+
│ │ ├── redis/
|
|
50
|
+
│ │ ├── pg/
|
|
51
|
+
│ │ ├── file/
|
|
52
|
+
│ │ ├── audit/
|
|
53
|
+
│ │ └── resource/
|
|
54
|
+
│ ├── modules/
|
|
55
|
+
│ │ ├── auth/
|
|
56
|
+
│ │ ├── access/
|
|
57
|
+
│ │ ├── resource/
|
|
58
|
+
│ │ ├── file/
|
|
59
|
+
│ │ ├── template/
|
|
60
|
+
│ │ └── system/
|
|
61
|
+
│ ├── migrations/
|
|
62
|
+
│ ├── config.ts # loadConfig
|
|
63
|
+
│ ├── context.ts # createContext, set, get
|
|
64
|
+
│ ├── errors.ts # standard Errors
|
|
65
|
+
│ ├── fastify.ts # fastify Plugins
|
|
66
|
+
│ ├── fcore.ts # createFcore
|
|
67
|
+
│ └── index.ts # export type, methods, etc
|
|
68
|
+
├── test/
|
|
69
|
+
├── engineering/
|
|
70
|
+
├── package.json
|
|
71
|
+
└── tsconfig.json
|
|
72
72
|
```
|
package/dist/config.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import'dotenv/config';const DEFAULT_LOG_RESPONSE_STATUS_CODES=[0x193,0x199,0x19d,0x19f,0x1ad];function required(
|
|
1
|
+
import'dotenv/config';const DEFAULT_LOG_RESPONSE_STATUS_CODES=[0x193,0x199,0x19d,0x19f,0x1ad];function required(h){const n=process.env[h];if(!n)throw new Error('Missing\x20environment\x20variable:\x20'+h);return n;}function Q(){const f=['./storage','split','true','map','parse','x5y30KBsEKCENT04tu6549Vxx3No1ztJ2q2K8r79S59420RaZ5','session_user_auth','0ua4b1Tz21m47z13U3EO0uN9e0WE7hqRFbcZ72cbdWqZBzemf9cAU865xan1s81TdNpUKKfF','strict','auth'];Q=function(){return f;};return Q();}export function loadConfig(h={}){const G=k,n={'env':process.env.NODE_ENV??'development','debug':process.env.DEBUG==='true','port':Number(process.env.PORT??0xbb8),'maxFileSize':+(process.env.MAX_FILE_SIZE||0x200),'rateLimit':{'disabled':process.env.RATE_LIMIT==='false','max':+(process.env.RATE_LIMIT_MAX||0x64),'timeWindow':+(process.env.RATE_LIMIT_TIME_WINDOW||0xea60)},'storageType':(process.env.STORAGE_TYPE??'s3')['toLowerCase']()==='local'||!process.env.S3_ENDPOINT?'local':'s3','storagePath':process.env.STORAGE_PATH??G(0x19c),'redactionList':(process.env.REDACTION_LIST||'password')[G(0x19d)](','),'logger':{'level':process.env.LOG_LEVEL??'info','responses':process.env.LOG_RESPONSES===G(0x19e)?!![]:![],'responseCodes':process.env.LOG_RESPONSE_STATUS_CODES?process.env.LOG_RESPONSE_STATUS_CODES['split'](',')[G(0x19f)](B=>B-0x0):DEFAULT_LOG_RESPONSE_STATUS_CODES,'directory':process.env.LOG_DIRECTORY||process['cwd']()+'/log'},'pg':{'host':process.env.PG_HOST??'localhost','port':Number(process.env.PG_PORT??0x1538),'database':process.env.PG_DATABASE??'','user':process.env.PG_USER??'','password':process.env.PG_PASSWORD??''},'redis':{'host':process.env.REDIS_HOST??'','port':Number(process.env.REDIS_PORT??0x18eb),'password':process.env.REDIS_PASSWORD,'lazyConnect':!![],'db':process.env.REDIS_DB?Number(process.env.REDIS_DB):undefined},'s3':{'endpoint':process.env.S3_ENDPOINT,'region':process.env.S3_REGION??'us-east-1','bucket':process.env.S3_BUCKET??'','accessKey':process.env.S3_ACCESS_KEY,'secretKey':process.env.S3_SECRET_KEY,'folder':process.env.S3_FOLDER,'forcePathStyle':process.env.S3_FORCE_PATH_STYLE!=='false','tokenSecret':process.env.FILE_TOKEN_SECRET,'tokenTtl':Number(process.env.FILE_TOKEN_TTL??0xe10)},'auth':{'accessToken':process.env.AUTH_ACCESS_TOKEN||'Ch7QR4e73Jg0wx0xOjm','user':process.env.AUTH_USER?JSON[G(0x1a0)](process.env.AUTH_USER):undefined,'sessionTimeout':+(process.env.AUTH_SESSION_TIMEOUT||0x258),'secret':process.env.AUTH_SECRET??G(0x1a1),'cookieName':process.env.AUTH_COOKIE_NAME??G(0x1a2),'jwtSecret':process.env.AUTH_JWT_SECRET??G(0x1a3),'redirect':process.env.AUTH_REDIRECT??'/','twoFactorRedirect':process.env.AUTH_TWOFACTOR_REDIRECT??'/','cookieOptions':process.env.AUTH_COOKIE_OPTIONS_DOMAIN?{'domain':process.env.AUTH_COOKIE_OPTIONS_DOMAIN,'path':process.env.AUTH_COOKIE_OPTIONS_PATH||'/','httpOnly':Boolean(process.env.AUTH_COOKIE_OPTIONS_HTTP_ONLY||'true'),'secure':Boolean(process.env.AUTH_COOKIE_OPTIONS_SECURE||'true'),'sameSite':process.env.AUTH_COOKIE_OPTIONS_SAME_SITE&&['lax',G(0x1a4),'none']['includes'](process.env.AUTH_COOKIE_OPTIONS_SAME_SITE)?process.env.AUTH_COOKIE_OPTIONS_SAME_SITE:Boolean(process.env.AUTH_COOKIE_OPTIONS_SAME_SITE||'true')}:{'path':'/','httpOnly':!![],'secure':![],'sameSite':!![]}}};return{...n,...h,'logger':{...n['logger'],...h['logger']},'pg':{...n['pg'],...h['pg']},'redis':{...n['redis'],...h['redis']},'s3':{...n['s3'],...h['s3']},'auth':{...n[G(0x1a5)],...h['auth']}};}function k(h,n){h=h-0x19c;const B=Q();let G=B[h];return G;}export{required as requireEnv};
|
package/dist/context.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
let defaultContext;function
|
|
1
|
+
let defaultContext;function k(h,n){h=h-0x1e9;const B=Q();let G=B[h];return G;}function Q(){const B=['Application\x20context\x20is\x20not\x20initialized'];Q=function(){return B;};return Q();}export function setContext(h){defaultContext=h;}export function getContext(){const n=k;if(!defaultContext)throw new Error(n(0x1e9));return defaultContext;}export function createContext(h){return{...h,async 'close'(){await Promise['allSettled']([h['redis']?.['close'](),h['pg']?.['end']()]),await h['logger']['close']();}};}
|
package/dist/errors.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
var f=k;export class FCoreError extends Error{[f(0x151)];['statusCode'];['details'];constructor(h,n,B=0x1f4,G){var j=f;super(n),this[j(0x151)]=h,this[j(0x152)]=B,this['details']=G,this[j(0x153)]=new.target.name;}}function Q(){var P=['code','statusCode','name','BAD_REQUEST_ERROR','FORBIDDEN','Not\x20found','Conflict','CONFLICT'];Q=function(){return P;};return Q();}export class BadRequestError extends FCoreError{constructor(h,n){var Z=f;super(Z(0x154),h,0x190,n);}}function k(h,n){h=h-0x151;var B=Q();var G=B[h];return G;}export class UnauthorizedError extends FCoreError{constructor(h='Authentication\x20required'){super('UNAUTHORIZED',h,0x191);}}export class ForbiddenError extends FCoreError{constructor(h='Access\x20denied'){var e=f;super(e(0x155),h,0x193);}}export class NotFoundError extends FCoreError{constructor(h=f(0x156)){super('NOT_FOUND',h,0x194);}}export class ConflictError extends FCoreError{constructor(h=f(0x157)){var b=f;super(b(0x158),h,0x199);}}export class ValidationError extends FCoreError{constructor(h,n){super('VALIDATION_ERROR',h,0x1a6,n);}}export class UnsupportedError extends FCoreError{constructor(h='Operation\x20is\x20not\x20configured'){super('UNSUPPORTED',h,0x1f5);}}
|
package/dist/fastify.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import h from'fastify-plugin';import{FCoreError}from'./errors.js';function k(h,n){h=h-0x162;const B=Q();let G=B[h];return G;}import{authRoutes}from'./modules/auth/route.js';import{fileRoutes}from'./modules/file/route.js';import{resourceRoutes}from'./modules/resource/route.js';import{systemRoutes}from'./modules/system/route.js';import{createSessionStore}from'./plugins/auth/index.js';import{ForbiddenError}from'./errors.js';function Q(){const O=['reduce','onRoute','method','summary','description','url','win32','user','config','headers','authorization','startsWith','Bearer\x20','length','admin','$resource','maxFileSize','setErrorHandler','logger','message','details','error','code','send','auth','resource','register','application/x-www-form-urlencoded','buffer','disabled','@fastify/rate-limit','rateLimit','timeWindow','split','log'];Q=function(){return O;};return Q();}import{jwtVerifyToken}from'./plugins/jwt.js';function urlencodedContentParser(n,B,G){const z=k,f=decodeURIComponent(B['toString']())['split']('&')[z(0x162)]((j,Z)=>{const [e,b]=Z['split']('=');return{...j,[e]:b};},{});G(null,f);}export default function fcoreFastify(n,B){return h(async G=>{const t=k;G['decorate']('ctx',n);const {config:f}=n,j=new Map();G['addHook'](t(0x163),e=>{const m=t,b=e['schema'],P=Array['isArray'](e['method'])?e[m(0x164)]:[e[m(0x164)]];for(const u of P){if(u==='HEAD')continue;const X={'method':u,'endpoint':e['url'],'package':b?.['package']??'fcore','tags':b?.['tags']??[],'summary':b?.[m(0x165)]??'','description':b?.[m(0x166)]??'','access':b?.['access']??'public','permissions':b?.['permissions']??[]};j['set'](u+'\x20'+e['url'],X);}}),G['addHook']('preHandler',async e=>{const A=t;if(e['routeOptions']['url']==='*')return!![];const b=j['get'](e['method']+'\x20'+e['routeOptions'][A(0x167)]),P=!e['user']&&process['platform']===A(0x168)&&n['config']?.['auth']?.[A(0x169)]?n[A(0x16a)]?.['auth']?.['user']:null,u=e['raw'][A(0x16b)]?.[A(0x16c)],X=u?.[A(0x16d)](A(0x16e))?u['slice'](0x7):null,H=e[A(0x169)]??(X?await jwtVerifyToken(X):P);!e['user']&&X&&process.env.AUTH_JWT_SECRET&&(e[A(0x169)]=await jwtVerifyToken(X));if(!b?.['access'])throw new ForbiddenError('Route\x20access\x20not\x20defined');if(b['access']==='public')return!![];if(!H)throw new ForbiddenError('User\x20required');if(b['access']===A(0x169)&&!b['permissions']?.[A(0x16f)])return!![];if(H['type']==A(0x170))return!![];if(b['access']==='admin')throw new ForbiddenError('Admin\x20access\x20required');for(const i of b['permissions']){const p=i?.['replace'](A(0x171),e['params']['resource']??'');if(!H['permissions']?.['includes'](p))throw new ForbiddenError('Missing\x20permission:\x20'+p);}return!![];}),await createSessionStore(G,n),await G['register'](import('@fastify/multipart'),{'limits':{'fileSize':f[t(0x172)]*0x400*0x400}}),G[t(0x173)]((e,b,P)=>{const U=t;if(e instanceof FCoreError||e['code']==='FST_ERR_VALIDATION'||e['statusCode']<0x1f4)return e['statusCode']<0x1f4&&n[U(0x174)]['warn'](e),P['code'](e['statusCode'])['send']({'error':e['code'],'message':e[U(0x175)],'details':e[U(0x176)]});return n['logger'][U(0x177)](e),(f['debug']||process.env.NODE_ENV==='test'||process.env.VITEST)&&console[U(0x177)](e),P[U(0x178)](0x1f4)[U(0x179)]({'error':'INTERNAL_ERROR','message':'Internal\x20server\x20error'});});const Z=e=>!B||B['includes'](e);if(Z(t(0x17a)))await G['register'](authRoutes(n));if(Z(t(0x17b)))await G['register'](resourceRoutes(n));if(Z('file'))await G[t(0x17c)](fileRoutes(n));if(Z('system'))await G[t(0x17c)](systemRoutes(n,j));G['addContentTypeParser'](t(0x17d),{'parseAs':t(0x17e)},urlencodedContentParser),!f['rateLimit']?.[t(0x17f)]?G['register'](import(t(0x180)),{'max':f[t(0x181)]?.['max']||0x64,'timeWindow':f['rateLimit']?.[t(0x182)]||0xea60,'hook':'preHandler','global':!![],'keyGenerator':e=>(e['user']?.['id']||e['ip'])+'-'+e['raw'][t(0x167)][t(0x183)]('?')[0x0]}):console[t(0x184)]('⚠️\x20rate\x20limit\x20is\x20disabled');});}
|
package/dist/fcore.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{loadConfig}from'./config.js';function
|
|
1
|
+
function k(h,n){h=h-0x156;const B=Q();let G=B[h];return G;}import{loadConfig}from'./config.js';import{createContext,setContext}from'./context.js';function Q(){const X=['folder','tokenTtl','region','tokenSecret','dictionaries','length','register'];Q=function(){return X;};return Q();}import{createAudit,createDatabase,createDictionary,createFileLocal,createFileS3,createLogger,createRedis,createResource}from'./plugins/index.js';export async function createFCore(h={}){const u=k,n=loadConfig(h['config']),B=createRedis(n['redis']),G=createLogger(),f=createDatabase(n['pg']),j=n['storageType']==='local'?createFileLocal({'storagePath':n['storagePath'],'folder':n['s3'][u(0x156)],'tokenSecret':n['s3']['tokenSecret'],'tokenTtl':n['s3'][u(0x157)]}):createFileS3({'endpoint':n['s3']['endpoint'],'region':n['s3'][u(0x158)],'bucket':n['s3']['bucket'],'accessKey':n['s3']['accessKey'],'secretKey':n['s3']['secretKey'],'folder':n['s3']['folder'],'forcePathStyle':n['s3']['forcePathStyle'],'tokenSecret':n['s3'][u(0x159)],'tokenTtl':n['s3'][u(0x157)]}),Z=createAudit({'pg':f,'logger':G}),e=createDictionary({'pg':f,'dictionaries':h[u(0x15a)]}),b=createResource({'pg':f,'logger':G,'audit':Z,'dictionary':e,'file':j});h['resources']?.[u(0x15b)]&&b[u(0x15c)](h['resources']);const P=createContext({'config':n,'logger':G,'redis':B,'pg':f,'file':j,'resource':b,'audit':Z,'dictionary':e});return setContext(P),P;}
|
package/dist/migrations/cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const
|
|
2
|
+
const e=k;function Q(){const P=['../../migrations','--dir','includes','startsWith','slice','log','Using\x20migration\x20directory:','run','error','exitCode'];Q=function(){return P;};return Q();}import{runMigrations}from'./runner.js';function k(h,n){h=h-0x119;const B=Q();let G=B[h];return G;}import{loadConfig}from'../config.js';import h from'node:path';import{fileURLToPath}from'node:url';const packageMigrations=fileURLToPath(new URL(e(0x119),import.meta.url));function migrationDirectory(n){const b=e,B=n['indexOf'](b(0x11a));if(B>=0x0){const f=n[B+0x1];if(!f)throw new Error('--dir\x20requires\x20a\x20folder\x20path');return h['resolve'](f);}if(n[b(0x11b)]('--fcore'))return packageMigrations;const G=n['find'](j=>!j[b(0x11c)]('--'));return h['resolve'](G??'migrations');}try{const config=loadConfig(),dir=migrationDirectory(process['argv'][e(0x11d)](0x2));console['log']('Loaded\x20configuration:',{...config['pg'],'user':'****','password':'****'}),console[e(0x11e)](e(0x11f),dir,process['argv'][e(0x11d)](0x2));for(const r of await runMigrations({'database':config['pg'],'dir':dir}))console['log']((r['status']===e(0x120)?'OK\x20\x20':'SKIP')+'\x20'+r['file']);}catch(Z){console[e(0x121)](Z),process[e(0x122)]=0x1;}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
function Q(){const t=['resolve','migrations','empty\x20pg','query','rows','map','endsWith','has','readFile','join','connect','run','hostname'];Q=function(){return t;};return Q();}import h from'node:fs/promises';import n from'node:path';import{createDatabase}from'../plugins/pg.js';export async function runMigrations(B={}){const p=k,G=n[p(0x163)](B['dir']??p(0x164)),f=B['database']??databaseFromUrl(B['databaseUrl']??process.env.DATABASE_URL);if(!f)throw new Error('DATABASE_URL\x20or\x20database\x20config\x20is\x20required');const j=createDatabase(f);if(!j)throw new Error(p(0x165));const Z=[];try{await j[p(0x166)]('\x0a\x20\x20\x20\x20\x20\x20CREATE\x20TABLE\x20IF\x20NOT\x20EXISTS\x20schema_migrations\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20version\x20varchar(255)\x20PRIMARY\x20KEY,\x0a\x20\x20\x20\x20\x20\x20\x20\x20applied_at\x20timestamptz\x20NOT\x20NULL\x20DEFAULT\x20now()\x0a\x20\x20\x20\x20\x20\x20)\x0a\x20\x20\x20\x20');const e=await j['query']('SELECT\x20version\x20FROM\x20schema_migrations'),b=new Set(e[p(0x167)][p(0x168)](u=>u['version'])),P=(await h['readdir'](G))['filter'](u=>u[p(0x169)]('.sql'))['sort']();for(const u of P){if(b[p(0x16a)](u)){Z['push']({'file':u,'status':'skip'});continue;}const X=await h[p(0x16b)](n[p(0x16c)](G,u),'utf8'),H=await j[p(0x16d)]();try{await H[p(0x166)]('BEGIN'),await H['query'](X),await H['query']('INSERT\x20INTO\x20schema_migrations(version)\x20VALUES\x20($1)',[u]),await H['query']('COMMIT');}catch(i){await H[p(0x166)]('ROLLBACK');throw i;}finally{H['release']();}Z['push']({'file':u,'status':p(0x16e)});}return Z;}finally{await j['end']();}}function k(h,n){h=h-0x163;const B=Q();let G=B[h];return G;}function databaseFromUrl(B){const z=k;if(!B)return undefined;const G=new URL(B);return{'host':G[z(0x16f)],'port':Number(G['port']||0x1538),'database':G['pathname']['slice'](0x1),'user':decodeURIComponent(G['username']),'password':decodeURIComponent(G['password'])};}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
const B=k;import{loadConfig}from'../../config.js';import{createDatabase}from'../../plugins/pg.js';import h from'./services/registration.js';const [user,password,type]=process['argv']['slice'](0x2);if(!user||!password)console['error']('Usage:\x20fcore-registration\x20<login>\x20<password>\x20[type]'),process[B(0xc5)]=0x1;else{const pg=createDatabase(loadConfig()['pg']);try{const {user:data}=await h({'user':user,'password':password,'type':type},{'pg':pg});console['log']('Registered\x20user\x20'+data['id']+'\x20('+data[B(0xc6)]+')');}catch(n){console[B(0xc7)](n),process['exitCode']=0x1;}finally{await pg['end']();}}function k(h,n){h=h-0xc5;const B=Q();let G=B[h];return G;}function Q(){const G=['exitCode','type','error'];Q=function(){return G;};return Q();}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
function
|
|
2
|
+
function Q(){const G=['exitCode','error','end'];Q=function(){return G;};return Q();}function k(h,n){h=h-0x1ec;const B=Q();let G=B[h];return G;}const B=k;import{loadConfig}from'../../config.js';import{createDatabase}from'../../plugins/pg.js';import h from'./services/change-password.js';const [login,password]=process['argv']['slice'](0x2);if(!login||!password)console['error']('Usage:\x20fcore-password\x20<login>\x20<password>'),process[B(0x1ec)]=0x1;else{const pg=createDatabase(loadConfig()['pg']);try{const result=await pg['query']('SELECT\x20uid\x20AS\x20id\x20FROM\x20admin.users\x20WHERE\x20$1\x20IN\x20(login,\x20email,\x20phone)\x20LIMIT\x201',[login]),user=result['rows'][0x0];if(!user)throw new Error('User\x20not\x20found');await h({'userId':user['id'],'password':password},{'pg':pg}),console['log']('Password\x20changed\x20for\x20'+login);}catch(n){console[B(0x1ed)](n),process[B(0x1ec)]=0x1;}finally{await pg[B(0x1ee)]();}}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const
|
|
2
|
+
const b=k;import{loadConfig}from'../../config.js';import{createDatabase}from'../../plugins/pg.js';function Q(){const u=['logs','check','settings','dictionaries','read','split','includes','system','query','rows','User\x20not\x20found','trim','log','get','set','BEGIN','UPDATE\x20admin.role_access\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20SET\x20actions\x20=\x20$1,\x20updated_by\x20=\x20$2,\x20updated_at\x20=\x20now()\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20access_id\x20=\x20$3','access_id','Granted\x20permissions\x20for\x20','join','end'];Q=function(){return u;};return Q();}const SYSTEM_ACTIONS=[b(0x13b),'audit','list',b(0x13c),'access',b(0x13d),b(0x13e)],RESOURCE_ACTIONS=[b(0x13f),'update','create','delete'],[login,permissionArg]=process['argv']['slice'](0x2);function expandPermissions(h){const P=b,n=h[P(0x140)](',')['map'](G=>G['trim']())['filter'](Boolean),B=new Set();for(const G of n){if(G[P(0x141)](':')){B['add'](G);continue;}const f=G===P(0x142)?SYSTEM_ACTIONS:RESOURCE_ACTIONS;for(const j of f){B['add'](G+':'+j);}}return[...B];}function k(h,n){h=h-0x13b;const B=Q();let G=B[h];return G;}if(!login||!permissionArg)console['error']('Usage:\x20fcore-permission\x20<login>\x20<system|resource|resource:action[,...]|clear>'),process['exitCode']=0x1;else{const pg=createDatabase(loadConfig()['pg']);try{const result=await pg[b(0x143)]('SELECT\x20uid\x20AS\x20id\x20FROM\x20admin.users\x20WHERE\x20$1\x20IN\x20(login,\x20email,\x20phone)\x20LIMIT\x201',[login]),user=result[b(0x144)][0x0];if(!user)throw new Error(b(0x145));if(permissionArg[b(0x146)]()==='clear')await pg[b(0x143)]('DELETE\x20FROM\x20admin.role_access\x20WHERE\x20user_uid\x20=\x20$1\x20AND\x20role_id\x20IS\x20NULL',[user['id']]),console[b(0x147)]('Permissions\x20cleared\x20for\x20'+login);else{const permissions=expandPermissions(permissionArg),byResource=new Map();for(const permission of permissions){const [resource,action]=permission['split'](':'),actions=byResource[b(0x148)](resource)??[];actions['push'](action),byResource[b(0x149)](resource,actions);}const client=await pg['connect']();try{await client['query'](b(0x14a));for(const [resource,actions]of byResource){const existing=await client['query']('SELECT\x20access_id,\x20actions\x20FROM\x20admin.role_access\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20user_uid\x20=\x20$1\x20AND\x20role_id\x20IS\x20NULL\x20AND\x20resource\x20=\x20$2',[user['id'],resource]),row=existing['rows'][0x0];if(row){const merged=[...new Set([...row['actions']??[],...actions])];await client['query'](b(0x14b),[merged,user['id'],row[b(0x14c)]]);}else await client[b(0x143)]('INSERT\x20INTO\x20admin.role_access\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20(\x20resource,\x20actions,\x20user_uid,\x20created_by,\x20updated_by)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20($1,\x20$2,\x20$3,\x20$4,\x20$4)',[resource,actions,user['id'],user['id']]);}await client['query']('COMMIT');}catch(Z){await client['query']('ROLLBACK');throw Z;}finally{client['release']();}console['log'](b(0x14d)+login+':\x20'+permissions[b(0x14e)](',\x20'));}}catch(e){console['error'](e),process['exitCode']=0x1;}finally{await pg[b(0x14f)]();}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getUserPermissions,verifyUser}from'../../plugins/auth/index.js';import
|
|
1
|
+
function k(h,n){h=h-0x112;const B=Q();let G=B[h];return G;}import{getUserPermissions,verifyUser}from'../../plugins/auth/index.js';import h from'./services/get-current-user.js';import n from'./services/registration.js';import B from'./services/change-password.js';import{authSchemas}from'./schema.js';import G from'../../shared/getIP.js';import{UnauthorizedError}from'../../errors.js';export function authRoutes(f){return async j=>{const p=k,Z=async e=>{const i=k,b=e[i(0x112)]==='GET'?e['query']:e['body'],P=G(e),u=await verifyUser({...b,'ip':P},f);u[i(0x113)]=await getUserPermissions(u['id'],f);const X=u[i(0x114)]?f['config'][i(0x115)][i(0x116)]:f['config'][i(0x115)][i(0x117)];await e['login'](u);const H=f['config']['auth']['sessionTimeout']*0x3e8*0x3c;return e[i(0x118)]?.['cookie']&&(e[i(0x118)]['cookie']['maxAge']=H),await e[i(0x118)]['save'](),await f['audit']?.['write']?.({'module':'auth','resource':i(0x118),'resourceId':e[i(0x118)]['sessionId'],'action':i(0x119),'userId':u['id'],'ipAddress':P}),{'user':{'id':u['id'],'type':u[i(0x11a)],'permissions':u[i(0x113)]},'redirectUrl':X};};j[p(0x11b)](p(0x11c),{'schema':{'tags':['fcore',p(0x115)],'summary':'Sign\x20in','description':p(0x11d),'access':'public','permissions':[],'querystring':authSchemas['credentials']}},Z),j[p(0x11e)](p(0x11c),{'schema':{'tags':['fcore','auth'],'summary':'Sign\x20in','description':p(0x11d),'access':p(0x11f),'permissions':[],'body':authSchemas['credentials']}},Z),j['post'](p(0x120),{'schema':{'tags':['fcore',p(0x115)],'summary':'Register','description':'Creates\x20a\x20regular\x20user\x20account.','access':'admin','permissions':[p(0x121)],'body':authSchemas['credentials']}},async e=>n(e[p(0x122)],f)),j['post']('/api/auth/password',{'schema':{'tags':['fcore','auth'],'summary':'Change\x20password','description':'Changes\x20the\x20password\x20for\x20the\x20current\x20user.','access':'user','permissions':[],'body':authSchemas['password']}},async e=>{const z=p;if(!e['user'])throw new UnauthorizedError('Not\x20authorized');return await B({'userId':e['user']['id'],...e[z(0x122)]},f),{'success':!![]};}),j['post'](p(0x123),{'schema':{'tags':['fcore','auth'],'summary':'Sign\x20out','description':p(0x124),'access':'user','permissions':[]}},async(e,b)=>{const t=p,P={'redirectUrl':'/'};if(!e['user'])return P;return await f[t(0x125)]?.[t(0x126)]?.({'module':t(0x115),'resource':'session','resourceId':e['session'][t(0x127)],'action':t(0x128),'userId':e[t(0x129)]?.['id']}),await e['session']['destroy'](),b[t(0x12a)](f['config'][t(0x115)][t(0x12b)]),Object['defineProperty'](e,'session',{'value':null,'writable':![],'configurable':![]}),P;}),j['get']('/api/auth/user',{'schema':{'tags':[p(0x12c),p(0x115)],'summary':p(0x12d),'description':'Returns\x20the\x20authenticated\x20user\x27s\x20safe\x20profile.','access':p(0x129),'permissions':[],'querystring':authSchemas['query']}},async e=>{const m=p;return h({'user':e[m(0x129)],'token':e['query'][m(0x12e)],'maxAge':e[m(0x118)]?.['cookie']?.[m(0x12f)],'originalExpires':e[m(0x118)]?.[m(0x130)]?.['originalExpires']?.[m(0x131)]?.()});});};}function Q(){const A=['method','permissions','twofa','auth','twoFactorRedirect','redirect','session','login','type','get','/api/auth/login','Authenticates\x20a\x20user\x20and\x20returns\x20a\x20bearer\x20access\x20token.','post','public','/api/auth/registration','user:create','body','/api/auth/logout','Terminates\x20the\x20current\x20user\x20session.','audit','write','sessionId','logout','user','clearCookie','cookieName','fcore','Get\x20current\x20user','token','maxAge','cookie','toISOString'];Q=function(){return A;};return Q();}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
const h=k;import{Type}from'@sinclair/typebox';function k(h,n){h=h-0x81;const B=Q();let G=B[h];return G;}function Q(){const n=['Boolean','Object','String','Optional'];Q=function(){return n;};return Q();}export const authSchemas={'query':Type['Object']({'token':Type['Optional'](Type[h(0x81)]())}),'credentials':Type[h(0x82)]({'user':Type[h(0x83)]({'minLength':0x1,'maxLength':0x64}),'password':Type['String']({'minLength':0x1,'maxLength':0x64}),'type':Type['Optional'](Type['String']({'minLength':0x1,'maxLength':0x64}))}),'password':Type['Object']({'password':Type['String']({'minLength':0x1,'maxLength':0x64}),'id':Type[h(0x84)](Type[h(0x83)]({'minLength':0x1,'maxLength':0x64}))}),'twoFactor':Type['Object']({'code':Type['String']({'minLength':0x1})})};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{hashPassword}from'../../../plugins/auth/index.js';export default async function changePassword({id:
|
|
1
|
+
import{hashPassword}from'../../../plugins/auth/index.js';function Q(){const Z=['query'];Q=function(){return Z;};return Q();}function k(h,n){h=h-0x1e4;const B=Q();let G=B[h];return G;}export default async function changePassword({id:h,password:n,userId:B},{pg:G}){const j=k,f=await hashPassword(n);await G[j(0x1e4)]('UPDATE\x20admin.users\x0a\x20\x20\x20\x20\x20SET\x20password_hash\x20=\x20$1,\x20updated_at\x20=\x20now(),\x20updated_by\x20=\x20$3\x0a\x20\x20\x20\x20\x20WHERE\x20uid\x20=\x20$2',[f,h||B,B]);}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function Q(){const Z=['permissions','map','split'];Q=function(){return Z;};return Q();}import{safeUser}from'../../utils/safe-user.js';function k(h,n){h=h-0x123;const B=Q();let G=B[h];return G;}export default async function getCurrentUser(h){const j=k,{user:n}=h;if(!n)return{};if(h['token']){const {jwtSignToken:B}=await import('../../../plugins/jwt.js'),G=await B(n);n['token']=G;}return n['resources']=[...new Set(n?.[j(0x123)][j(0x124)](f=>f[j(0x125)](':')[0x0]))],{...safeUser(n),'session':{'maxAge':h['maxAge'],'originalExpires':h['maxAge']}};}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ConflictError}from'../../../errors.js';import{hashPassword}from'../../../plugins/auth/index.js';function
|
|
1
|
+
import{ConflictError}from'../../../errors.js';import{hashPassword}from'../../../plugins/auth/index.js';function k(h,n){h=h-0xc8;const B=Q();let G=B[h];return G;}export default async function registration({user:h,password:n,type:B},{pg:G}){const e=k,f=await hashPassword(n),j=await G['query']('INSERT\x20INTO\x20admin.users\x20(login,\x20password_hash,\x20user_type)\x0a\x20\x20\x20\x20\x20SELECT\x20$1,\x20$2,\x20$3\x0a\x20\x20\x20\x20\x20WHERE\x20NOT\x20EXISTS\x20(SELECT\x201\x20FROM\x20admin.users\x20WHERE\x20login\x20=\x20$1)\x0a\x20\x20\x20\x20\x20RETURNING\x20uid\x20AS\x20id,\x20user_type\x20AS\x20type',[h,f,B||e(0xc8)]),Z=j['rows'][0x0];if(!Z)throw new ConflictError('Login\x20is\x20already\x20in\x20use');return{'user':Z};}function Q(){const b=['regular'];Q=function(){return b;};return Q();}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{unsupported}from'../../utils/unsupported.js';export default async function verifyTwoFactor(h,n){return unsupported('Two-factor\x20provider');}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
function k(h,n){h=h-0x1c0;var B=Q();var G=B[h];return G;}var h=k;function Q(){var n=['image/jpeg','image/png','image/webp','image/tiff','application/pdf','application/vnd.ms-powerpoint','application/vnd.openxmlformats-officedocument.presentationml.presentation','application/vnd.oasis.opendocument.text','text/csv','application/json','application/geo+json','application/x-7z-compressed','application/gzip','application/x-gzip','audio/wav','audio/ogg','audio/webm','video/quicktime'];Q=function(){return n;};return Q();}export default new Set([h(0x1c0),h(0x1c1),'image/gif',h(0x1c2),'image/bmp',h(0x1c3),'image/svg+xml','image/x-icon','image/avif',h(0x1c4),'application/msword','application/vnd.openxmlformats-officedocument.wordprocessingml.document','application/vnd.ms-excel','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',h(0x1c5),h(0x1c6),h(0x1c7),'application/vnd.oasis.opendocument.spreadsheet','application/vnd.oasis.opendocument.presentation','text/plain',h(0x1c8),'text/markdown',h(0x1c9),'application/xml','text/xml',h(0x1ca),'application/vnd.google-earth.kml+xml','application/vnd.google-earth.kmz','application/zip','application/x-zip-compressed',h(0x1cb),'application/x-rar-compressed','application/vnd.rar',h(0x1cc),h(0x1cd),'application/x-tar','audio/mpeg',h(0x1ce),h(0x1cf),h(0x1d0),'audio/mp4','video/mp4','video/mpeg','video/webm',h(0x1d1),'video/x-msvideo','application/octet-stream']);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
function k(h,n){h=h-0x12a;const B=Q();let G=B[h];return G;}import{fileTypeFromBuffer}from'file-type';function Q(){const z=['fileToken','verify','token','download','startsWith','image/','pop','file','Content-Disposition','header','Cache-Control','fcore','Uploads\x20a\x20file\x20and\x20stores\x20its\x20metadata.','fields','/api/file/:token/resize','user','type'];Q=function(){return z;};return Q();}import{getFile}from'./services/get-file.js';import{uploadFile}from'./services/upload-file.js';import{resizeFile}from'./services/resize-file.js';import{fileSchemas}from'./schema.js';export function fileRoutes(h){return async n=>{const X=k;n['get']('/api/file/:token',{'schema':{'tags':['fcore','file'],'summary':'Get\x20file\x20by\x20token','description':'Returns\x20a\x20file\x20after\x20verifying\x20its\x20signed\x20access\x20token.','access':'public','permissions':[],'params':fileSchemas[X(0x12a)],'querystring':fileSchemas['fileDownloadQuery']}},async(B,G)=>{const H=X,f=h['file'][H(0x12b)](B['params'][H(0x12c)]),j=await getFile({'pathOrToken':f},h),Z=await fileTypeFromBuffer(j),e=Z?.['mime']??'application/octet-stream',b=B['query'][H(0x12d)]===!![],P=e[H(0x12e)](H(0x12f))||e==='application/pdf',u=f['split']('/')[H(0x130)]()?.['replace'](/[^A-Za-z0-9._-]/g,'_')??H(0x131);return G['type'](e),G['header'](H(0x132),(b||!P?'attachment':'inline')+';\x20filename=\x22'+u+'\x22')[H(0x133)](H(0x134),'public,\x20max-age=86400,\x20immutable'),G['send'](j);}),n['post']('/api/file/upload',{'schema':{'tags':[X(0x135),X(0x131)],'summary':'Upload\x20file','description':X(0x136),'access':'user','permissions':['files:create']}},async B=>{const i=X,G=await B['file']();if(!G)throw new Error('File\x20is\x20required');return uploadFile({'file':G,'metadata':{'name':G['filename'],'path':G['fields']['path']?.['value'],'resource':G['fields']['resource']?.['value'],'resourceId':G[i(0x137)]['resourceId']?.['value']},'user':B['user']},h);}),n['get'](X(0x138),{'schema':{'tags':['fcore','file'],'summary':'Resize\x20file','description':'Returns\x20a\x20resized\x20image\x20file.','access':X(0x139),'permissions':['files:read'],'params':fileSchemas['fileToken'],'querystring':fileSchemas['resizeQuery']}},async(B,G)=>{const p=X,f=await resizeFile({'pathOrToken':h[p(0x131)]?.['verify'](B['params']['token']),...B['query']},h),j=await fileTypeFromBuffer(f);return G[p(0x13a)](j?.['mime']??'image/png'),G['header'](p(0x132),'inline')['header'](p(0x134),'public,\x20max-age=86400,\x20immutable'),G['send'](f);});};}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const h=k;function Q(){const n=['Object','String','Any','Optional','Integer','Union','cover','Literal','contain','outside'];Q=function(){return n;};return Q();}function k(h,n){h=h-0x146;const B=Q();let G=B[h];return G;}import{Type}from'@sinclair/typebox';export const fileSchemas={'fileId':Type['Object']({'id':Type['String']({'minLength':0x1,'maxLength':0x80})}),'fileToken':Type[h(0x146)]({'token':Type[h(0x147)]({'minLength':0x1,'maxLength':0x800})}),'fileDownloadQuery':Type['Object']({'download':Type['Optional'](Type['Boolean']())}),'filePath':Type[h(0x146)]({'*':Type[h(0x147)]({'minLength':0x1,'maxLength':0x400})}),'upload':Type['Object']({'file':Type[h(0x148)](),'metadata':Type['Object']({'name':Type[h(0x149)](Type['String']({'minLength':0x1})),'path':Type['Optional'](Type['String']({'minLength':0x1})),'entityType':Type['Optional'](Type['String']({'minLength':0x1})),'entityId':Type['Optional'](Type['String']({'minLength':0x1}))})}),'filePatch':Type['Object']({'entityType':Type[h(0x149)](Type['String']({'minLength':0x1})),'entityId':Type[h(0x149)](Type[h(0x147)]({'minLength':0x1}))}),'resizeQuery':Type['Object']({'width':Type['Optional'](Type[h(0x14a)]({'minimum':0x1,'default':0xc8})),'height':Type[h(0x149)](Type['Integer']({'minimum':0x1})),'fit':Type['Optional'](Type[h(0x14b)]([Type['Literal'](h(0x14c)),Type[h(0x14d)](h(0x14e)),Type[h(0x14d)]('fill'),Type['Literal']('inside'),Type['Literal'](h(0x14f))]))})};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{NotFoundError}from'../../../errors.js';function k(h,n){h=h-0x113;var B=Q();var G=B[h];return G;}export async function getFile(h,n){var B=k;if(!n['file'])throw new Error(B(0x113));if(!await n['file'][B(0x114)](h['pathOrToken']))throw new NotFoundError(B(0x115)+h['pathOrToken']);return n['file'][B(0x116)](h['pathOrToken']);}function Q(){var G=['empty\x20file','exists','File\x20not\x20found','get'];Q=function(){return G;};return Q();}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
function Q(){const z=['path','height','digest','join','file','mime','Only\x20image\x20files\x20can\x20be\x20resized','resize'];Q=function(){return z;};return Q();}import{NotFoundError,ValidationError}from'../../../errors.js';import{fileTypeFromBuffer}from'file-type';import{createHash}from'node:crypto';import{mkdir,readFile,writeFile}from'node:fs/promises';import h from'node:path';import n from'sharp';export async function resizeFile(B,G){const p=k,f=B['pathOrToken']??B[p(0xc0)];if(!f)throw new ValidationError('File\x20path\x20is\x20required');const j=parseDimension(B['width'],'width')??0xc8,Z=parseDimension(B['height'],p(0xc1)),e=createHash('sha256')['update'](f+':'+j+':'+(Z??'auto')+':'+(B['fit']??'cover'))[p(0xc2)]('hex'),b=h['resolve']('logs','resize'),P=h[p(0xc3)](b,e+'.jpg');try{return await readFile(P);}catch(i){if(i['code']!=='ENOENT')throw i;}if(!await G['file']['exists'](f))throw new NotFoundError('File\x20not\x20found');const u=await G[p(0xc4)]['get'](f),X=await fileTypeFromBuffer(u);if(!X?.[p(0xc5)]['startsWith']('image/'))throw new ValidationError(p(0xc6));const H=await n(u)[p(0xc7)]({'width':j,'height':Z,'fit':B['fit']??'cover'})['toBuffer']();return await mkdir(b,{'recursive':!![]}),await writeFile(P,H),H;}function k(h,n){h=h-0xc0;const B=Q();let G=B[h];return G;}function parseDimension(B,G){if(B===undefined||B==='')return undefined;const f=Number(B);if(!Number['isInteger'](f)||f<=0x0)throw new ValidationError(G+'\x20must\x20be\x20a\x20positive\x20integer');return f;}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{fileTypeFromBuffer}from'file-type';
|
|
1
|
+
import{fileTypeFromBuffer}from'file-type';import h from'../mime.js';function Q(){const z=['name','slice','path','metadata','toBuffer','mimetype','SELECT\x20file_id\x20FROM\x20admin.files\x0a\x20\x20\x20\x20\x20\x20\x20WHERE\x20resource\x20=\x20$1\x20AND\x20resource_id\x20=\x20$2\x20AND\x20file_name\x20=\x20$3\x0a\x20\x20\x20\x20\x20\x20\x20LIMIT\x201','\x22\x20already\x20exists\x20for\x20resource\x20\x22','resource','resourceId','put','file','pop','attached','pending','rows'];Q=function(){return z;};return Q();}import{randomUUID}from'node:crypto';function k(h,n){h=h-0x188;const B=Q();let G=B[h];return G;}import{ValidationError}from'../../../errors.js';export async function uploadFile(n,B){const p=k,G=(n['metadata'][p(0x188)]??randomUUID())['replace'](/[^a-zA-Z0-9._-]/g,'_'),f=new Date(),j=String(f['getFullYear']())[p(0x189)](-0x2),Z=String(f['getMonth']()+0x1)['padStart'](0x2,'0'),e=String(f['getDate']())['padStart'](0x2,'0'),b=n['metadata'][p(0x18a)]??(n['metadata']['resource']?n['metadata']['resource']+'/'+(n[p(0x18b)]['resourceId']??randomUUID())+'/'+G:null)??'uploads/'+j+'/'+Z+'-'+e+'/'+G,P=await n['file'][p(0x18c)](),u=await fileTypeFromBuffer(P);if(!h['has'](n['file']['mimetype'])&&(u?.['mime']?!h['has'](u['mime']):!![]))throw new Error('Unsupported\x20file\x20type:\x20'+n['file'][p(0x18d)]);const X=Boolean(n['metadata']['resource']&&n['metadata']['resourceId']);if(X){const i=await B['pg']['query'](p(0x18e),[n['metadata']['resource'],String(n['metadata']['resourceId']),G]);if((i['rowCount']??0x0)>0x0)throw new ValidationError('File\x20with\x20name\x20\x22'+G+p(0x18f)+n['metadata'][p(0x190)]+'\x22\x20and\x20id\x20\x22'+n['metadata'][p(0x191)]+'\x22');}await B['file'][p(0x192)](b,P);const H=await B['pg']['query']('\x0a\x20\x20\x20\x20\x20\x20\x20\x20INSERT\x20INTO\x20admin.files\x20(resource,\x20resource_id,\x20file_path,\x20file_type,\x20size,\x20uploaded_name,\x20file_name,\x20ext,\x20status,\x20created_by)\x0a\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20($1,\x20$2,\x20$3,\x20$4,\x20$5,\x20$6,\x20$7,\x20$8,\x20$9,\x20$10)\x0a\x20\x20\x20\x20\x20\x20\x20\x20RETURNING\x20*\x0a\x20\x20\x20\x20\x20\x20',[n['metadata']['resource']??null,n[p(0x18b)]['resourceId']??null,b,n['file']['mimetype'],n['file'][p(0x193)]['bytesRead'],n['metadata'][p(0x188)],G,n['file']['mimetype']['split']('/')[p(0x194)]()??null,X?p(0x195):p(0x196),n['user']?.['id']??null]);return{...H[p(0x197)][0x0],'token':B['file']['create'](b)};}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../src/modules/resource/route.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../src/modules/resource/route.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAwBnD,wBAAgB,cAAc,CAAC,GAAG,EAAE,UAAU,GAAG,kBAAkB,CAoblE"}
|