@opengis/fcore 0.0.1-beta.9 → 0.0.28
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.d.ts +1 -0
- 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 +0 -3
- package/dist/fastify.d.ts.map +1 -1
- package/dist/fastify.js +1 -1
- package/dist/fcore.d.ts.map +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.d.ts.map +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.d.ts +2 -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.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.d.ts.map +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 +19 -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 +25 -2
- 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.d.ts +1 -0
- package/dist/modules/system/services/get-access.d.ts.map +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.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-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 +3 -1
- 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/audit.types.d.ts +1 -1
- package/dist/plugins/audit/audit.types.d.ts.map +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.d.ts.map +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.d.ts +7 -3
- package/dist/plugins/file.d.ts.map +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.d.ts +4 -2
- package/dist/plugins/pg.d.ts.map +1 -1
- package/dist/plugins/pg.js +1 -1
- package/dist/plugins/redis.d.ts.map +1 -1
- package/dist/plugins/redis.js +1 -1
- package/dist/plugins/resource/resource.d.ts +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.d.ts +3 -2
- package/dist/plugins/resource/resource.registry.d.ts.map +1 -1
- package/dist/plugins/resource/resource.registry.js +1 -1
- package/dist/plugins/resource/resource.types.d.ts +66 -14
- 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.d.ts +5 -2
- package/dist/plugins/resource/services/create-relation.d.ts.map +1 -1
- package/dist/plugins/resource/services/create-relation.js +1 -1
- 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 +6 -3
- package/dist/plugins/resource/services/delete-relation.d.ts.map +1 -1
- package/dist/plugins/resource/services/delete-relation.js +1 -1
- package/dist/plugins/resource/services/delete.d.ts +9 -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.map +1 -1
- package/dist/plugins/resource/services/find-one.js +1 -1
- package/dist/plugins/resource/services/find-relation.d.ts.map +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.d.ts +8 -0
- package/dist/plugins/resource/services/get-table-columns.d.ts.map +1 -0
- package/dist/plugins/resource/services/get-table-columns.js +1 -0
- package/dist/plugins/resource/services/update-relation.d.ts +5 -2
- package/dist/plugins/resource/services/update-relation.d.ts.map +1 -1
- package/dist/plugins/resource/services/update-relation.js +1 -1
- package/dist/plugins/resource/services/update.d.ts +9 -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.js +1 -1
- package/dist/plugins/resource/utils/fields.js +1 -1
- package/dist/plugins/resource/utils/filters.d.ts +2 -1
- 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.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.d.ts +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.d.ts +1 -1
- package/dist/plugins/resource/utils/sql.d.ts.map +1 -1
- package/dist/plugins/resource/utils/sql.js +1 -1
- package/dist/plugins/resource/utils/summary.d.ts +7 -0
- package/dist/plugins/resource/utils/summary.d.ts.map +1 -0
- package/dist/plugins/resource/utils/summary.js +1 -0
- package/dist/shared/getIP.js +1 -1
- package/migrations/20260903120000_core_schema.sql +5 -2
- package/migrations/20260903130000_move_notes_files_to_admin.sql +17 -17
- package/migrations/20260903130001_add_file_fields.sql +5 -0
- package/migrations/20260903140000_settings_nulls_not_distinct.sql +18 -18
- package/migrations/20260910170000_core_schema.sql +22 -0
- package/migrations/20260929120000_allow_user_only_role_scopes.sql +2 -0
- package/migrations/20260929_role_scope.sql +32 -0
- package/package.json +93 -93
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.d.ts
CHANGED
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,eAAe,CAAC;AACvB,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEpC,KAAK,qBAAqB,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;AAIvD,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE;QACT,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,GAAG,EAAE,MAAM,CAAC;QACZ,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,MAAM,EAAE;QACN,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;QAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;KAC1B,CAAC;IACF,EAAE,EAAE;QACF,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,GAAG,CAAC,EAAE,MAAM,CAAC;KACd,CAAC;IACF,KAAK,EAAE;QACL,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,EAAE,CAAC,EAAE,MAAM,CAAC;QACZ,WAAW,CAAC,EAAE,OAAO,CAAC;KACvB,CAAC;IACF,EAAE,EAAE;QACF,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,cAAc,CAAC,EAAE,OAAO,CAAC;QACzB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,IAAI,EAAE;QACJ,IAAI,EAAE,IAAI,CAAC;QACX,MAAM,EAAE,MAAM,CAAC;QACf,WAAW,EAAE,MAAM,CAAC;QACpB,cAAc,EAAE,MAAM,CAAC;QACvB,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,aAAa,EAAE;YACb,MAAM,CAAC,EAAE,MAAM,CAAC;YAChB,IAAI,CAAC,EAAE,MAAM,CAAC;YACd,QAAQ,CAAC,EAAE,OAAO,CAAC;YACnB,MAAM,CAAC,EAAE,OAAO,CAAC;YACjB,QAAQ,CAAC,EAAE,OAAO,GAAG,qBAAqB,CAAC;SAC5C,CAAC;KACH,CAAC;CACH;AAED,iBAAS,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAItC;AAED,wBAAgB,UAAU,CAAC,SAAS,GAAE,OAAO,CAAC,WAAW,CAAM,GAAG,WAAW,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,eAAe,CAAC;AACvB,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEpC,KAAK,qBAAqB,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;AAIvD,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,OAAO,GAAG,IAAI,CAAC;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE;QACT,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,GAAG,EAAE,MAAM,CAAC;QACZ,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,MAAM,EAAE;QACN,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;QAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;KAC1B,CAAC;IACF,EAAE,EAAE;QACF,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,GAAG,CAAC,EAAE,MAAM,CAAC;KACd,CAAC;IACF,KAAK,EAAE;QACL,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,EAAE,CAAC,EAAE,MAAM,CAAC;QACZ,WAAW,CAAC,EAAE,OAAO,CAAC;KACvB,CAAC;IACF,EAAE,EAAE;QACF,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,cAAc,CAAC,EAAE,OAAO,CAAC;QACzB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,IAAI,EAAE;QACJ,IAAI,EAAE,IAAI,CAAC;QACX,MAAM,EAAE,MAAM,CAAC;QACf,WAAW,EAAE,MAAM,CAAC;QACpB,cAAc,EAAE,MAAM,CAAC;QACvB,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,aAAa,EAAE;YACb,MAAM,CAAC,EAAE,MAAM,CAAC;YAChB,IAAI,CAAC,EAAE,MAAM,CAAC;YACd,QAAQ,CAAC,EAAE,OAAO,CAAC;YACnB,MAAM,CAAC,EAAE,OAAO,CAAC;YACjB,QAAQ,CAAC,EAAE,OAAO,GAAG,qBAAqB,CAAC;SAC5C,CAAC;KACH,CAAC;CACH;AAED,iBAAS,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAItC;AAED,wBAAgB,UAAU,CAAC,SAAS,GAAE,OAAO,CAAC,WAAW,CAAM,GAAG,WAAW,CAoG5E;AACD,OAAO,EAAE,QAAQ,IAAI,UAAU,EAAE,CAAC"}
|
package/dist/config.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import'dotenv/config';const DEFAULT_LOG_RESPONSE_STATUS_CODES=[0x193,0x199,0x19d,0x19f,0x1ad];function required(p){const I=f,Z=process.env[p];if(!Z)throw new Error(I(0x163)+p);return Z;}function f(p,Z){p=p-0x163;const A=s();let I=A[p];return I;}export function loadConfig(p={}){const j=f,Z={'env':process.env.NODE_ENV??'development','debug':process.env.DEBUG===j(0x164),'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']()===j(0x165)||!process.env.S3_ENDPOINT?'local':'s3','storagePath':process.env.STORAGE_PATH??j(0x166),'redactionList':(process.env.REDACTION_LIST||'password')[j(0x167)](','),'logger':{'level':process.env.LOG_LEVEL??'info','responses':process.env.LOG_RESPONSES==='true'?!![]:![],'responseCodes':process.env.LOG_RESPONSE_STATUS_CODES?process.env.LOG_RESPONSE_STATUS_CODES['split'](',')['map'](A=>A-0x0):DEFAULT_LOG_RESPONSE_STATUS_CODES,'directory':process.env.LOG_DIRECTORY||process[j(0x168)]()+'/log'},'pg':{'host':process.env.PG_HOST??j(0x169),'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['parse'](process.env.AUTH_USER):undefined,'sessionTimeout':+(process.env.AUTH_SESSION_TIMEOUT||0x258),'secret':process.env.AUTH_SECRET??'x5y30KBsEKCENT04tu6549Vxx3No1ztJ2q2K8r79S59420RaZ5','cookieName':process.env.AUTH_COOKIE_NAME??j(0x16a),'jwtSecret':process.env.AUTH_JWT_SECRET??'0ua4b1Tz21m47z13U3EO0uN9e0WE7hqRFbcZ72cbdWqZBzemf9cAU865xan1s81TdNpUKKfF','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','strict','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{...Z,...p,'logger':{...Z['logger'],...p['logger']},'pg':{...Z['pg'],...p['pg']},'redis':{...Z[j(0x16b)],...p['redis']},'s3':{...Z['s3'],...p['s3']},'auth':{...Z['auth'],...p[j(0x16c)]}};}function s(){const D=['Missing\x20environment\x20variable:\x20','true','local','./storage','split','cwd','localhost','session_user_auth','redis','auth'];s=function(){return D;};return s();}export{required as requireEnv};
|
package/dist/context.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
let defaultContext;
|
|
1
|
+
let defaultContext;export function setContext(p){defaultContext=p;}export function getContext(){if(!defaultContext)throw new Error('Application\x20context\x20is\x20not\x20initialized');return defaultContext;}function f(p,Z){p=p-0xd7;const A=s();let I=A[p];return I;}function s(){const A=['allSettled','logger'];s=function(){return A;};return s();}export function createContext(p){return{...p,async 'close'(){const Z=f;await Promise[Z(0xd7)]([p['redis']?.['close'](),p['pg']?.['end']()]),await p[Z(0xd8)]['close']();}};}
|
package/dist/errors.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var j=f;export class FCoreError extends Error{[j(0x7f)];[j(0x80)];['details'];constructor(p,Z,A=0x1f4,I){var D=j;super(Z),this['code']=p,this[D(0x80)]=A,this[D(0x81)]=I,this['name']=new.target.name;}}function f(p,Z){p=p-0x7f;var A=s();var I=A[p];return I;}export class BadRequestError extends FCoreError{constructor(p,Z){super('BAD_REQUEST_ERROR',p,0x190,Z);}}export class UnauthorizedError extends FCoreError{constructor(p='Authentication\x20required'){super('UNAUTHORIZED',p,0x191);}}export class ForbiddenError extends FCoreError{constructor(p=j(0x82)){super('FORBIDDEN',p,0x193);}}function s(){var R=['code','statusCode','details','Access\x20denied','Conflict','VALIDATION_ERROR'];s=function(){return R;};return s();}export class NotFoundError extends FCoreError{constructor(p='Not\x20found'){super('NOT_FOUND',p,0x194);}}export class ConflictError extends FCoreError{constructor(p=j(0x83)){super('CONFLICT',p,0x199);}}export class ValidationError extends FCoreError{constructor(p,Z){var o=j;super(o(0x84),p,0x1a6,Z);}}export class UnsupportedError extends FCoreError{constructor(p='Operation\x20is\x20not\x20configured'){super('UNSUPPORTED',p,0x1f5);}}
|
package/dist/fastify.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Integrates FCore modules with Fastify without coupling infrastructure plugins to HTTP.
|
|
3
|
-
*/
|
|
4
1
|
import { type FastifyPluginAsync } from "fastify";
|
|
5
2
|
import type { AppContext } from "./context.js";
|
|
6
3
|
export type FCoreApiModule = "auth" | "resource" | "file" | "system";
|
package/dist/fastify.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fastify.d.ts","sourceRoot":"","sources":["../src/fastify.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fastify.d.ts","sourceRoot":"","sources":["../src/fastify.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAY/C,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,UAAU,GAAG,MAAM,GAAG,QAAQ,CAAC;AAYrE,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,GAAG,EAAE,UAAU,EACf,OAAO,CAAC,EAAE,SAAS,cAAc,EAAE,GAClC,kBAAkB,CAgJpB"}
|
package/dist/fastify.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
import p from'fastify-plugin';import{FCoreError}from'./errors.js';function s(){const V=['split','ctx','schema','tags','access','routeOptions','url','platform','win32','config','user','raw','permissions','type','admin','Admin\x20access\x20required','replace','includes','logger','warn','code','statusCode','message','send','@fastify/rate-limit','rateLimit'];s=function(){return V;};return s();}import{authRoutes}from'./modules/auth/route.js';function f(p,Z){p=p-0x128;const A=s();let I=A[p];return I;}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';import{jwtVerifyToken}from'./plugins/jwt.js';function urlencodedContentParser(Z,A,I){const a=f,j=decodeURIComponent(A['toString']())[a(0x128)]('&')['reduce']((D,o)=>{const [R,B]=o['split']('=');return{...D,[R]:B};},{});I(null,j);}export default function fcoreFastify(Z,A){return p(async I=>{const X=f;I['decorate'](X(0x129),Z);const {config:j}=Z,D=new Map();I['addHook']('onRoute',R=>{const K=X,B=R[K(0x12a)],H=Array['isArray'](R['method'])?R['method']:[R['method']];for(const e of H){if(e==='HEAD')continue;const g={'method':e,'endpoint':R['url'],'package':B?.['package']??'fcore','tags':B?.[K(0x12b)]??[],'summary':B?.['summary']??'','description':B?.['description']??'','access':B?.[K(0x12c)]??'public','permissions':B?.['permissions']??[]};D['set'](e+'\x20'+R['url'],g);}}),I['addHook']('preHandler',async R=>{const Q=X;if(R[Q(0x12d)]['url']==='*')return!![];const B=D['get'](R['method']+'\x20'+R[Q(0x12d)][Q(0x12e)]),H=!R['user']&&process[Q(0x12f)]===Q(0x130)&&Z[Q(0x131)]?.['auth']?.['user']?Z['config']?.['auth']?.[Q(0x132)]:null,e=R[Q(0x133)]['headers']?.['authorization'],g=e?.['startsWith']('Bearer\x20')?e['slice'](0x7):null,N=R['user']??(g?await jwtVerifyToken(g):H);!R[Q(0x132)]&&g&&process.env.AUTH_JWT_SECRET&&(R['user']=await jwtVerifyToken(g));if(!B?.[Q(0x12c)])throw new ForbiddenError('Route\x20access\x20not\x20defined');if(B['access']==='public')return!![];if(!N)throw new ForbiddenError('User\x20required');if(B[Q(0x12c)]===Q(0x132)&&!B[Q(0x134)]?.['length'])return!![];if(N[Q(0x135)]=='admin')return!![];if(B[Q(0x12c)]===Q(0x136))throw new ForbiddenError(Q(0x137));for(const h of B['permissions']){const E=h?.[Q(0x138)]('$resource',R['params']['resource']??'');if(!N[Q(0x134)]?.[Q(0x139)](E))throw new ForbiddenError('Missing\x20permission:\x20'+E);}return!![];}),await createSessionStore(I,Z),await I['register'](import('@fastify/multipart'),{'limits':{'fileSize':j['maxFileSize']*0x400*0x400}}),I['setErrorHandler']((R,B,H)=>{const G=X;if(R instanceof FCoreError||R['code']==='FST_ERR_VALIDATION'||R['statusCode']<0x1f4)return R['statusCode']<0x1f4&&Z[G(0x13a)][G(0x13b)](R),H[G(0x13c)](R[G(0x13d)])['send']({'error':R['code'],'message':R[G(0x13e)],'details':R['details']});return Z[G(0x13a)]['error'](R),(j['debug']||process.env.NODE_ENV==='test'||process.env.VITEST)&&console['error'](R),H['code'](0x1f4)[G(0x13f)]({'error':'INTERNAL_ERROR','message':'Internal\x20server\x20error'});});const o=R=>!A||A['includes'](R);if(o('auth'))await I['register'](authRoutes(Z));if(o('resource'))await I['register'](resourceRoutes(Z));if(o('file'))await I['register'](fileRoutes(Z));if(o('system'))await I['register'](systemRoutes(Z,D));I['addContentTypeParser']('application/x-www-form-urlencoded',{'parseAs':'buffer'},urlencodedContentParser),!j['rateLimit']?.['disabled']?I['register'](import(X(0x140)),{'max':j[X(0x141)]?.['max']||0x64,'timeWindow':j[X(0x141)]?.['timeWindow']||0xea60,'hook':'preHandler','global':!![],'keyGenerator':R=>(R[X(0x132)]?.['id']||R['ip'])+'-'+R['raw']['url']['split']('?')[0x0]}):console['log']('⚠️\x20rate\x20limit\x20is\x20disabled');});}
|
package/dist/fcore.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fcore.d.ts","sourceRoot":"","sources":["../src/fcore.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAc,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAA6B,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1E,OAAO,
|
|
1
|
+
{"version":3,"file":"fcore.d.ts","sourceRoot":"","sources":["../src/fcore.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAc,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAA6B,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1E,OAAO,EASL,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACtB,MAAM,oBAAoB,CAAC;AAE5B,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;IAC9B,SAAS,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAC/B,YAAY,CAAC,EAAE,oBAAoB,EAAE,CAAC;CACvC;AAED,wBAAsB,WAAW,CAC/B,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,UAAU,CAAC,CAqDrB"}
|
package/dist/fcore.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
function s(){const g=['storageType','tokenSecret','secretKey','register'];s=function(){return g;};return s();}import{loadConfig}from'./config.js';import{createContext,setContext}from'./context.js';import{createAudit,createDatabase,createDictionary,createFileLocal,createFileS3,createLogger,createRedis,createResource}from'./plugins/index.js';function f(p,Z){p=p-0x193;const A=s();let I=A[p];return I;}export async function createFCore(p={}){const e=f,Z=loadConfig(p['config']),A=createRedis(Z['redis']),I=createLogger(),j=createDatabase(Z['pg']),D=Z[e(0x193)]==='local'?createFileLocal({'storagePath':Z['storagePath'],'folder':Z['s3']['folder'],'tokenSecret':Z['s3'][e(0x194)],'tokenTtl':Z['s3']['tokenTtl']}):createFileS3({'endpoint':Z['s3']['endpoint'],'region':Z['s3']['region'],'bucket':Z['s3']['bucket'],'accessKey':Z['s3']['accessKey'],'secretKey':Z['s3'][e(0x195)],'folder':Z['s3']['folder'],'forcePathStyle':Z['s3']['forcePathStyle'],'tokenSecret':Z['s3']['tokenSecret'],'tokenTtl':Z['s3']['tokenTtl']}),o=createAudit({'pg':j,'logger':I}),R=createDictionary({'pg':j,'dictionaries':p['dictionaries']}),B=createResource({'pg':j,'logger':I,'audit':o,'dictionary':R,'file':D});p['resources']?.['length']&&B[e(0x196)](p['resources']);const H=createContext({'config':Z,'logger':I,'redis':A,'pg':j,'file':D,'resource':B,'audit':o,'dictionary':R});return setContext(H),H;}
|
package/dist/migrations/cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
function
|
|
2
|
+
function f(p,Z){p=p-0x6f;const A=s();let I=A[p];return I;}const B=f;import{runMigrations}from'./runner.js';import{loadConfig}from'../config.js';import p from'node:path';import{fileURLToPath}from'node:url';const packageMigrations=fileURLToPath(new URL('../../migrations',import.meta.url));function migrationDirectory(Z){const R=f,A=Z['indexOf'](R(0x6f));if(A>=0x0){const j=Z[A+0x1];if(!j)throw new Error('--dir\x20requires\x20a\x20folder\x20path');return p['resolve'](j);}if(Z['includes'](R(0x70)))return packageMigrations;const I=Z['find'](D=>!D[R(0x71)]('--'));return p['resolve'](I??R(0x72));}function s(){const H=['--dir','--fcore','startsWith','migrations','argv','log','slice','OK\x20\x20'];s=function(){return H;};return s();}try{const config=loadConfig(),dir=migrationDirectory(process[B(0x73)]['slice'](0x2));console['log']('Loaded\x20configuration:',{...config['pg'],'user':'****','password':'****'}),console[B(0x74)]('Using\x20migration\x20directory:',dir,process[B(0x73)][B(0x75)](0x2));for(const r of await runMigrations({'database':config['pg'],'dir':dir}))console[B(0x74)]((r['status']==='run'?B(0x76):'SKIP')+'\x20'+r['file']);}catch(o){console['error'](o),process['exitCode']=0x1;}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import p from'node:fs/promises';import Z from'node:path';function f(p,Z){p=p-0x95;const A=s();let I=A[p];return I;}import{createDatabase}from'../plugins/pg.js';export async function runMigrations(A={}){const E=f,I=Z['resolve'](A['dir']??E(0x95)),j=A[E(0x96)]??databaseFromUrl(A[E(0x97)]??process.env.DATABASE_URL);if(!j)throw new Error('DATABASE_URL\x20or\x20database\x20config\x20is\x20required');const D=createDatabase(j);if(!D)throw new Error('empty\x20pg');const o=[];try{await D[E(0x98)](E(0x99));const R=await D[E(0x98)]('SELECT\x20version\x20FROM\x20schema_migrations'),B=new Set(R['rows']['map'](e=>e[E(0x9a)])),H=(await p['readdir'](I))['filter'](e=>e['endsWith']('.sql'))['sort']();for(const e of H){if(B['has'](e)){o['push']({'file':e,'status':'skip'});continue;}const g=await p['readFile'](Z['join'](I,e),'utf8'),N=await D[E(0x9b)]();try{await N[E(0x98)]('BEGIN'),await N['query'](g),await N['query'](E(0x9c),[e]),await N['query'](E(0x9d));}catch(h){await N['query'](E(0x9e));throw h;}finally{N['release']();}o['push']({'file':e,'status':'run'});}return o;}finally{await D[E(0x9f)]();}}function databaseFromUrl(A){const a=f;if(!A)return undefined;const I=new URL(A);return{'host':I['hostname'],'port':Number(I['port']||0x1538),'database':I['pathname'][a(0xa0)](0x1),'user':decodeURIComponent(I['username']),'password':decodeURIComponent(I['password'])};}function s(){const X=['migrations','database','databaseUrl','query','\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','version','connect','INSERT\x20INTO\x20schema_migrations(version)\x20VALUES\x20($1)','COMMIT','ROLLBACK','end','slice'];s=function(){return X;};return s();}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const
|
|
2
|
+
const A=f;function f(p,Z){p=p-0x17d;const A=s();let I=A[p];return I;}import{loadConfig}from'../../config.js';import{createDatabase}from'../../plugins/pg.js';function s(){const I=['argv','exitCode','end'];s=function(){return I;};return s();}import p from'./services/registration.js';const [user,password,type]=process[A(0x17d)]['slice'](0x2);if(!user||!password)console['error']('Usage:\x20fcore-registration\x20<login>\x20<password>\x20[type]'),process[A(0x17e)]=0x1;else{const pg=createDatabase(loadConfig()['pg']);try{const {user:data}=await p({'user':user,'password':password,'type':type},{'pg':pg});console['log']('Registered\x20user\x20'+data['id']+'\x20('+data['type']+')');}catch(Z){console['error'](Z),process['exitCode']=0x1;}finally{await pg[A(0x17f)]();}}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const
|
|
2
|
+
const A=f;import{loadConfig}from'../../config.js';import{createDatabase}from'../../plugins/pg.js';import p from'./services/change-password.js';const [login,password]=process['argv'][A(0x140)](0x2);function f(p,Z){p=p-0x140;const A=s();let I=A[p];return I;}if(!login||!password)console['error']('Usage:\x20fcore-password\x20<login>\x20<password>'),process[A(0x141)]=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(A(0x142));await p({'userId':user['id'],'password':password},{'pg':pg}),console['log'](A(0x143)+login);}catch(Z){console['error'](Z),process['exitCode']=0x1;}finally{await pg['end']();}}function s(){const I=['slice','exitCode','User\x20not\x20found','Password\x20changed\x20for\x20'];s=function(){return I;};return s();}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
function s(){const e=['settings','dictionaries','read','slice','trim','Usage:\x20fcore-permission\x20<login>\x20<system|resource|resource:action[,...]|clear>','exitCode','query','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','release','Granted\x20permissions\x20for\x20','end'];s=function(){return e;};return s();}const B=f;import{loadConfig}from'../../config.js';import{createDatabase}from'../../plugins/pg.js';const SYSTEM_ACTIONS=['logs','audit','list','check','access',B(0x14e),B(0x14f)],RESOURCE_ACTIONS=[B(0x150),'update','create','delete'],[login,permissionArg]=process['argv'][B(0x151)](0x2);function expandPermissions(p){const H=B,Z=p['split'](',')['map'](I=>I[H(0x152)]())['filter'](Boolean),A=new Set();for(const I of Z){if(I['includes'](':')){A['add'](I);continue;}const j=I==='system'?SYSTEM_ACTIONS:RESOURCE_ACTIONS;for(const D of j){A['add'](I+':'+D);}}return[...A];}function f(p,Z){p=p-0x14e;const A=s();let I=A[p];return I;}if(!login||!permissionArg)console['error'](B(0x153)),process[B(0x154)]=0x1;else{const pg=createDatabase(loadConfig()['pg']);try{const result=await pg[B(0x155)]('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');if(permissionArg['trim']()==='clear')await pg['query']('DELETE\x20FROM\x20admin.role_access\x20WHERE\x20user_uid\x20=\x20$1\x20AND\x20role_id\x20IS\x20NULL',[user['id']]),console['log']('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['get'](resource)??[];actions['push'](action),byResource['set'](resource,actions);}const client=await pg['connect']();try{await client['query']('BEGIN');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[B(0x155)](B(0x156),[merged,user['id'],row[B(0x157)]]);}else await client['query']('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(o){await client['query']('ROLLBACK');throw o;}finally{client[B(0x158)]();}console['log'](B(0x159)+login+':\x20'+permissions['join'](',\x20'));}}catch(R){console['error'](R),process['exitCode']=0x1;}finally{await pg[B(0x15a)]();}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/route.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,kBAAkB,EAAkB,MAAM,SAAS,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAYnD,wBAAgB,UAAU,CAAC,GAAG,EAAE,UAAU,GAAG,kBAAkB,
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/route.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,kBAAkB,EAAkB,MAAM,SAAS,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAYnD,wBAAgB,UAAU,CAAC,GAAG,EAAE,UAAU,GAAG,kBAAkB,CA0K9D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
import{getUserPermissions,verifyUser}from'../../plugins/auth/index.js';function s(){const Q=['permissions','auth','login','config','session','maxAge','audit','write','sessionId','type','fcore','Authenticates\x20a\x20user\x20and\x20returns\x20a\x20bearer\x20access\x20token.','credentials','Creates\x20a\x20regular\x20user\x20account.','Changes\x20the\x20password\x20for\x20the\x20current\x20user.','Not\x20authorized','user','logout','cookieName','Get\x20current\x20user','query','toISOString'];s=function(){return Q;};return s();}import p from'./services/get-current-user.js';import Z from'./services/registration.js';import A from'./services/change-password.js';import{authSchemas}from'./schema.js';import I from'../../shared/getIP.js';function f(p,Z){p=p-0x1ac;const A=s();let I=A[p];return I;}import{UnauthorizedError}from'../../errors.js';export function authRoutes(j){return async D=>{const E=f,o=async R=>{const h=f,B=R['method']==='GET'?R['query']:R['body'],H=I(R),e=await verifyUser({...B,'ip':H},j);e[h(0x1ac)]=await getUserPermissions(e['id'],j);const g=e['twofa']?j['config']['auth']['twoFactorRedirect']:j['config'][h(0x1ad)]['redirect'];await R[h(0x1ae)](e);const N=j[h(0x1af)]['auth']['sessionTimeout']*0x3e8*0x3c;return R[h(0x1b0)]?.['cookie']&&(R['session']['cookie'][h(0x1b1)]=N),await R['session']['save'](),await j[h(0x1b2)]?.[h(0x1b3)]?.({'module':h(0x1ad),'resource':'session','resourceId':R[h(0x1b0)][h(0x1b4)],'action':'login','userId':e['id'],'ipAddress':H}),{'user':{'id':e['id'],'type':e[h(0x1b5)],'permissions':e['permissions']},'redirectUrl':g};};D['get']('/api/auth/login',{'schema':{'tags':[E(0x1b6),E(0x1ad)],'summary':'Sign\x20in','description':E(0x1b7),'access':'public','permissions':[],'querystring':authSchemas[E(0x1b8)]}},o),D['post']('/api/auth/login',{'schema':{'tags':['fcore','auth'],'summary':'Sign\x20in','description':'Authenticates\x20a\x20user\x20and\x20returns\x20a\x20bearer\x20access\x20token.','access':'public','permissions':[],'body':authSchemas['credentials']}},o),D['post']('/api/auth/registration',{'schema':{'tags':['fcore',E(0x1ad)],'summary':'Register','description':E(0x1b9),'access':'admin','permissions':['user:create'],'body':authSchemas[E(0x1b8)]}},async R=>Z(R['body'],j)),D['post']('/api/auth/password',{'schema':{'tags':[E(0x1b6),E(0x1ad)],'summary':'Change\x20password','description':E(0x1ba),'access':'user','permissions':[],'body':authSchemas['password']}},async R=>{const a=E;if(!R['user'])throw new UnauthorizedError(a(0x1bb));return await A({'userId':R[a(0x1bc)]['id'],...R['body']},j),{'success':!![]};}),D['post']('/api/auth/logout',{'schema':{'tags':['fcore','auth'],'summary':'Sign\x20out','description':'Terminates\x20the\x20current\x20user\x20session.','access':'user','permissions':[]}},async(R,B)=>{const X=E,H={'redirectUrl':'/'};if(!R['user'])return H;return await j['audit']?.[X(0x1b3)]?.({'module':'auth','resource':'session','resourceId':R['session']['sessionId'],'action':X(0x1bd),'userId':R['user']?.['id']}),await R['session']['destroy'](),B['clearCookie'](j['config'][X(0x1ad)][X(0x1be)]),Object['defineProperty'](R,'session',{'value':null,'writable':![],'configurable':![]}),H;}),D['get']('/api/auth/user',{'schema':{'tags':['fcore','auth'],'summary':E(0x1bf),'description':'Returns\x20the\x20authenticated\x20user\x27s\x20safe\x20profile.','access':'user','permissions':[],'querystring':authSchemas[E(0x1c0)]}},async R=>{const K=E;return p({'user':R['user'],'token':R['query']['token'],'maxAge':R[K(0x1b0)]?.['cookie']?.['maxAge'],'originalExpires':R[K(0x1b0)]?.['cookie']?.['originalExpires']?.[K(0x1c1)]?.()});});};}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
function s(){const Z=['String'];s=function(){return Z;};return s();}function f(p,Z){p=p-0x1cc;const A=s();let I=A[p];return I;}const p=f;import{Type}from'@sinclair/typebox';export const authSchemas={'query':Type['Object']({'token':Type['Optional'](Type['Boolean']())}),'credentials':Type['Object']({'user':Type['String']({'minLength':0x1,'maxLength':0x64}),'password':Type['String']({'minLength':0x1,'maxLength':0x64}),'type':Type['Optional'](Type[p(0x1cc)]({'minLength':0x1,'maxLength':0x64}))}),'password':Type['Object']({'password':Type['String']({'minLength':0x1,'maxLength':0x64}),'id':Type['Optional'](Type[p(0x1cc)]({'minLength':0x1,'maxLength':0x64}))}),'twoFactor':Type['Object']({'code':Type[p(0x1cc)]({'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';export default async function changePassword({id:p,password:Z,userId:A},{pg:I}){const j=await hashPassword(Z);await I['query']('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',[j,p||A,A]);}
|
|
@@ -5,5 +5,7 @@ import type { User } from "../../../context.js";
|
|
|
5
5
|
export default function getCurrentUser(params: {
|
|
6
6
|
user: User | undefined;
|
|
7
7
|
token: boolean | undefined;
|
|
8
|
+
maxAge: number | undefined;
|
|
9
|
+
originalExpires: string | undefined;
|
|
8
10
|
}): Promise<Record<string, unknown>>;
|
|
9
11
|
//# sourceMappingURL=get-current-user.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-current-user.d.ts","sourceRoot":"","sources":["../../../../src/modules/auth/services/get-current-user.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAEhD,wBAA8B,cAAc,CAAC,MAAM,EAAE;IACnD,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC;IACvB,KAAK,EAAE,OAAO,GAAG,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"get-current-user.d.ts","sourceRoot":"","sources":["../../../../src/modules/auth/services/get-current-user.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAEhD,wBAA8B,cAAc,CAAC,MAAM,EAAE;IACnD,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC;IACvB,KAAK,EAAE,OAAO,GAAG,SAAS,CAAC;IAC3B,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,eAAe,EAAE,MAAM,GAAG,SAAS,CAAC;CACrC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAkBnC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function f(p,Z){p=p-0xf8;const A=s();let I=A[p];return I;}import{safeUser}from'../../utils/safe-user.js';export default async function getCurrentUser(p){const D=f,{user:Z}=p;if(!Z)return{};if(p[D(0xf8)]){const {jwtSignToken:A}=await import('../../../plugins/jwt.js'),I=await A(Z);Z['token']=I;}return Z['resources']=[...new Set(Z?.['permissions']['map'](j=>j['split'](':')[0x0]))],{...safeUser(Z),'session':{'maxAge':p[D(0xf9)],'originalExpires':p[D(0xf9)]}};}function s(){const o=['token','maxAge'];s=function(){return o;};return s();}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
function s(){const B=['query','rows','Login\x20is\x20already\x20in\x20use'];s=function(){return B;};return s();}function f(p,Z){p=p-0x188;const A=s();let I=A[p];return I;}import{ConflictError}from'../../../errors.js';import{hashPassword}from'../../../plugins/auth/index.js';export default async function registration({user:p,password:Z,type:A},{pg:I}){const R=f,j=await hashPassword(Z),D=await I[R(0x188)]('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',[p,j,A||'regular']),o=D[R(0x189)][0x0];if(!o)throw new ConflictError(R(0x18a));return{'user':o};}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{unsupported}from'../../utils/unsupported.js';
|
|
1
|
+
import{unsupported}from'../../utils/unsupported.js';export default async function verifyTwoFactor(p,Z){return unsupported('Two-factor\x20provider');}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function f(p,Z){p=p-0x1cb;var A=s();var I=A[p];return I;}var p=f;export default new Set([p(0x1cb),p(0x1cc),'image/gif','image/webp','image/bmp','image/tiff','image/svg+xml','image/x-icon','image/avif','application/pdf','application/msword','application/vnd.openxmlformats-officedocument.wordprocessingml.document','application/vnd.ms-excel','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',p(0x1cd),p(0x1ce),'application/vnd.oasis.opendocument.text','application/vnd.oasis.opendocument.spreadsheet',p(0x1cf),'text/plain',p(0x1d0),p(0x1d1),p(0x1d2),'application/xml','text/xml','application/geo+json','application/vnd.google-earth.kml+xml','application/vnd.google-earth.kmz','application/zip','application/x-zip-compressed','application/x-7z-compressed',p(0x1d3),p(0x1d4),'application/gzip','application/x-gzip',p(0x1d5),'audio/mpeg',p(0x1d6),'audio/ogg',p(0x1d7),p(0x1d8),'video/mp4','video/mpeg',p(0x1d9),'video/quicktime','video/x-msvideo','application/octet-stream']);function s(){var Z=['image/jpeg','image/png','application/vnd.ms-powerpoint','application/vnd.openxmlformats-officedocument.presentationml.presentation','application/vnd.oasis.opendocument.presentation','text/csv','text/markdown','application/json','application/x-rar-compressed','application/vnd.rar','application/x-tar','audio/wav','audio/webm','audio/mp4','video/webm'];s=function(){return Z;};return s();}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{fileTypeFromBuffer}from'file-type';
|
|
1
|
+
import{fileTypeFromBuffer}from'file-type';function s(){const a=['get','public','fileToken','params','token','mime','query','download','image/','split','replace','file','Content-Disposition','attachment','inline','public,\x20max-age=86400,\x20immutable','Upload\x20file','resource','fields','resourceId','value','image/png','send'];s=function(){return a;};return s();}import{getFile}from'./services/get-file.js';import{uploadFile}from'./services/upload-file.js';function f(p,Z){p=p-0x90;const A=s();let I=A[p];return I;}import{resizeFile}from'./services/resize-file.js';import{fileSchemas}from'./schema.js';export function fileRoutes(p){return async Z=>{const g=f;Z[g(0x90)]('/api/file/:token',{'schema':{'tags':['fcore','file'],'summary':'Get\x20file\x20by\x20token','description':'Returns\x20a\x20file\x20after\x20verifying\x20its\x20signed\x20access\x20token.','access':g(0x91),'permissions':[],'params':fileSchemas[g(0x92)],'querystring':fileSchemas['fileDownloadQuery']}},async(A,I)=>{const N=g,j=p['file']['verify'](A[N(0x93)][N(0x94)]),D=await getFile({'pathOrToken':j},p),o=await fileTypeFromBuffer(D),R=o?.[N(0x95)]??'application/octet-stream',B=A[N(0x96)][N(0x97)]===!![],H=R['startsWith'](N(0x98))||R==='application/pdf',e=j[N(0x99)]('/')['pop']()?.[N(0x9a)](/[^A-Za-z0-9._-]/g,'_')??N(0x9b);return I['type'](R),I['header'](N(0x9c),(B||!H?N(0x9d):N(0x9e))+';\x20filename=\x22'+e+'\x22')['header']('Cache-Control',N(0x9f)),I['send'](D);}),Z['post']('/api/file/upload',{'schema':{'tags':['fcore','file'],'summary':g(0xa0),'description':'Uploads\x20a\x20file\x20and\x20stores\x20its\x20metadata.','access':'user','permissions':['files:create']}},async A=>{const h=g,I=await A['file']();if(!I)throw new Error('File\x20is\x20required');return uploadFile({'file':I,'metadata':{'name':I['filename'],'path':I['fields']['path']?.['value'],'resource':I['fields'][h(0xa1)]?.['value'],'resourceId':I[h(0xa2)][h(0xa3)]?.[h(0xa4)]},'user':A['user']},p);}),Z['get']('/api/file/:token/resize',{'schema':{'tags':['fcore','file'],'summary':'Resize\x20file','description':'Returns\x20a\x20resized\x20image\x20file.','access':'user','permissions':['files:read'],'params':fileSchemas[g(0x92)],'querystring':fileSchemas['resizeQuery']}},async(A,I)=>{const E=g,j=await resizeFile({'pathOrToken':p['file']?.['verify'](A['params']['token']),...A['query']},p),D=await fileTypeFromBuffer(j);return I['type'](D?.[E(0x95)]??E(0xa5)),I['header'](E(0x9c),'inline')['header']('Cache-Control','public,\x20max-age=86400,\x20immutable'),I[E(0xa6)](j);});};}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
const p=f;function s(){const Z=['String','Optional','Object','Integer','Union','Literal','fill','inside'];s=function(){return Z;};return s();}import{Type}from'@sinclair/typebox';function f(p,Z){p=p-0xcf;const A=s();let I=A[p];return I;}export const fileSchemas={'fileId':Type['Object']({'id':Type['String']({'minLength':0x1,'maxLength':0x80})}),'fileToken':Type['Object']({'token':Type[p(0xcf)]({'minLength':0x1,'maxLength':0x800})}),'fileDownloadQuery':Type['Object']({'download':Type['Optional'](Type['Boolean']())}),'filePath':Type['Object']({'*':Type['String']({'minLength':0x1,'maxLength':0x400})}),'upload':Type['Object']({'file':Type['Any'](),'metadata':Type['Object']({'name':Type['Optional'](Type['String']({'minLength':0x1})),'path':Type[p(0xd0)](Type[p(0xcf)]({'minLength':0x1})),'entityType':Type['Optional'](Type['String']({'minLength':0x1})),'entityId':Type['Optional'](Type['String']({'minLength':0x1}))})}),'filePatch':Type[p(0xd1)]({'entityType':Type['Optional'](Type['String']({'minLength':0x1})),'entityId':Type['Optional'](Type['String']({'minLength':0x1}))}),'resizeQuery':Type[p(0xd1)]({'width':Type['Optional'](Type['Integer']({'minimum':0x1,'default':0xc8})),'height':Type[p(0xd0)](Type[p(0xd2)]({'minimum':0x1})),'fit':Type['Optional'](Type[p(0xd3)]([Type['Literal']('cover'),Type[p(0xd4)]('contain'),Type['Literal'](p(0xd5)),Type['Literal'](p(0xd6)),Type['Literal']('outside')]))})};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function f(p,Z){p=p-0x93;var A=s();var I=A[p];return I;}function s(){var I=['file','File\x20not\x20found','pathOrToken'];s=function(){return I;};return s();}import{NotFoundError}from'../../../errors.js';export async function getFile(p,Z){var A=f;if(!Z['file'])throw new Error('empty\x20file');if(!await Z[A(0x93)]['exists'](p['pathOrToken']))throw new NotFoundError(A(0x94)+p['pathOrToken']);return Z['file']['get'](p[A(0x95)]);}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
function s(){const X=['pathOrToken','height','fit','.jpg','code','ENOENT','exists','File\x20not\x20found','mime','startsWith','toBuffer','isInteger','\x20must\x20be\x20a\x20positive\x20integer'];s=function(){return X;};return s();}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 p from'node:path';import Z from'sharp';function f(p,Z){p=p-0xfb;const A=s();let I=A[p];return I;}export async function resizeFile(A,I){const E=f,j=A[E(0xfb)]??A['path'];if(!j)throw new ValidationError('File\x20path\x20is\x20required');const D=parseDimension(A['width'],'width')??0xc8,o=parseDimension(A[E(0xfc)],'height'),R=createHash('sha256')['update'](j+':'+D+':'+(o??'auto')+':'+(A[E(0xfd)]??'cover'))['digest']('hex'),B=p['resolve']('logs','resize'),H=p['join'](B,R+E(0xfe));try{return await readFile(H);}catch(h){if(h[E(0xff)]!==E(0x100))throw h;}if(!await I['file'][E(0x101)](j))throw new NotFoundError(E(0x102));const e=await I['file']['get'](j),g=await fileTypeFromBuffer(e);if(!g?.[E(0x103)][E(0x104)]('image/'))throw new ValidationError('Only\x20image\x20files\x20can\x20be\x20resized');const N=await Z(e)['resize']({'width':D,'height':o,'fit':A['fit']??'cover'})[E(0x105)]();return await mkdir(B,{'recursive':!![]}),await writeFile(H,N),N;}function parseDimension(A,I){const a=f;if(A===undefined||A==='')return undefined;const j=Number(A);if(!Number[a(0x106)](j)||j<=0x0)throw new ValidationError(I+a(0x107));return j;}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload-file.d.ts","sourceRoot":"","sources":["../../../../src/modules/file/services/upload-file.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"upload-file.d.ts","sourceRoot":"","sources":["../../../../src/modules/file/services/upload-file.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGxD,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,IAAI,EAAE,aAAa,CAAC;IACpB,QAAQ,EAAE;QACR,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC;CACH;AACD,wBAAsB,UAAU,CAC9B,MAAM,EAAE,gBAAgB,EACxB,GAAG,EAAE,UAAU,GACd,OAAO,CAAC,GAAG,CAAC,CA0Ed"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{fileTypeFromBuffer}from'file-type';import
|
|
1
|
+
import{fileTypeFromBuffer}from'file-type';import p from'../mime.js';import{randomUUID}from'node:crypto';import{ValidationError}from'../../../errors.js';export async function uploadFile(Z,A){const E=f,I=(Z[E(0x1db)]['name']??randomUUID())['replace'](/[^a-zA-Z0-9._-]/g,'_'),j=new Date(),D=String(j['getFullYear']())['slice'](-0x2),o=String(j['getMonth']()+0x1)['padStart'](0x2,'0'),R=String(j[E(0x1dc)]())['padStart'](0x2,'0'),B=Z[E(0x1db)][E(0x1dd)]??(Z['metadata'][E(0x1de)]?Z['metadata'][E(0x1de)]+'/'+(Z[E(0x1db)]['resourceId']??randomUUID())+'/'+I:null)??'uploads/'+D+'/'+o+'-'+R+'/'+I,H=await Z['file'][E(0x1df)](),e=await fileTypeFromBuffer(H);if(!p['has'](Z['file'][E(0x1e0)])&&(e?.['mime']?!p[E(0x1e1)](e['mime']):!![]))throw new Error('Unsupported\x20file\x20type:\x20'+Z['file']['mimetype']);const g=Boolean(Z['metadata']['resource']&&Z[E(0x1db)][E(0x1e2)]);if(g){const h=await A['pg']['query']('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',[Z['metadata'][E(0x1de)],String(Z['metadata']['resourceId']),I]);if((h['rowCount']??0x0)>0x0)throw new ValidationError('File\x20with\x20name\x20\x22'+I+E(0x1e3)+Z[E(0x1db)]['resource']+E(0x1e4)+Z['metadata'][E(0x1e2)]+'\x22');}await A[E(0x1e5)][E(0x1e6)](B,H);const N=await A['pg'][E(0x1e7)]('\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',[Z[E(0x1db)][E(0x1de)]??null,Z['metadata'][E(0x1e2)]??null,B,Z[E(0x1e5)]['mimetype'],Z['file']['file']['bytesRead'],Z['metadata'][E(0x1e8)],I,Z['file']['mimetype']['split']('/')['pop']()??null,g?'attached':'pending',Z['user']?.['id']??null]);return{...N['rows'][0x0],'token':A['file'][E(0x1e9)](B)};}function f(p,Z){p=p-0x1db;const A=s();let I=A[p];return I;}function s(){const a=['metadata','getDate','path','resource','toBuffer','mimetype','has','resourceId','\x22\x20already\x20exists\x20for\x20resource\x20\x22','\x22\x20and\x20id\x20\x22','file','put','query','name','create'];s=function(){return a;};return s();}
|