fastify-wrap 0.1.0
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/README.md +980 -0
- package/dist/src/client/TestClient.d.ts +33 -0
- package/dist/src/client/TestClient.d.ts.map +1 -0
- package/dist/src/client/TestClient.js +359 -0
- package/dist/src/client/TestClient.js.map +1 -0
- package/dist/src/client/index.d.ts +4 -0
- package/dist/src/client/index.d.ts.map +1 -0
- package/dist/src/client/index.js +3 -0
- package/dist/src/client/index.js.map +1 -0
- package/dist/src/client/sign.d.ts +12 -0
- package/dist/src/client/sign.d.ts.map +1 -0
- package/dist/src/client/sign.js +44 -0
- package/dist/src/client/sign.js.map +1 -0
- package/dist/src/client/types.d.ts +41 -0
- package/dist/src/client/types.d.ts.map +1 -0
- package/dist/src/client/types.js +20 -0
- package/dist/src/client/types.js.map +1 -0
- package/dist/src/common/auth/AuthStrategy.d.ts +6 -0
- package/dist/src/common/auth/AuthStrategy.d.ts.map +1 -0
- package/dist/src/common/auth/AuthStrategy.js +2 -0
- package/dist/src/common/auth/AuthStrategy.js.map +1 -0
- package/dist/src/common/auth/JwtStrategy.d.ts +9 -0
- package/dist/src/common/auth/JwtStrategy.d.ts.map +1 -0
- package/dist/src/common/auth/JwtStrategy.js +34 -0
- package/dist/src/common/auth/JwtStrategy.js.map +1 -0
- package/dist/src/common/auth/NonceStore.d.ts +22 -0
- package/dist/src/common/auth/NonceStore.d.ts.map +1 -0
- package/dist/src/common/auth/NonceStore.js +27 -0
- package/dist/src/common/auth/NonceStore.js.map +1 -0
- package/dist/src/common/auth/SecretResolvers.d.ts +18 -0
- package/dist/src/common/auth/SecretResolvers.d.ts.map +1 -0
- package/dist/src/common/auth/SecretResolvers.js +30 -0
- package/dist/src/common/auth/SecretResolvers.js.map +1 -0
- package/dist/src/common/auth/SignatureStrategy.d.ts +23 -0
- package/dist/src/common/auth/SignatureStrategy.d.ts.map +1 -0
- package/dist/src/common/auth/SignatureStrategy.js +115 -0
- package/dist/src/common/auth/SignatureStrategy.js.map +1 -0
- package/dist/src/common/auth/index.d.ts +4 -0
- package/dist/src/common/auth/index.d.ts.map +1 -0
- package/dist/src/common/auth/index.js +3 -0
- package/dist/src/common/auth/index.js.map +1 -0
- package/dist/src/common/auth/signToken.d.ts +4 -0
- package/dist/src/common/auth/signToken.d.ts.map +1 -0
- package/dist/src/common/auth/signToken.js +11 -0
- package/dist/src/common/auth/signToken.js.map +1 -0
- package/dist/src/common/config/loader.d.ts +10 -0
- package/dist/src/common/config/loader.d.ts.map +1 -0
- package/dist/src/common/config/loader.js +20 -0
- package/dist/src/common/config/loader.js.map +1 -0
- package/dist/src/common/container/index.d.ts +7 -0
- package/dist/src/common/container/index.d.ts.map +1 -0
- package/dist/src/common/container/index.js +15 -0
- package/dist/src/common/container/index.js.map +1 -0
- package/dist/src/common/db/index.d.ts +19 -0
- package/dist/src/common/db/index.d.ts.map +1 -0
- package/dist/src/common/db/index.js +64 -0
- package/dist/src/common/db/index.js.map +1 -0
- package/dist/src/common/dto/PageResult.d.ts +12 -0
- package/dist/src/common/dto/PageResult.d.ts.map +1 -0
- package/dist/src/common/dto/PageResult.js +2 -0
- package/dist/src/common/dto/PageResult.js.map +1 -0
- package/dist/src/common/errorHandler.d.ts +3 -0
- package/dist/src/common/errorHandler.d.ts.map +1 -0
- package/dist/src/common/errorHandler.js +47 -0
- package/dist/src/common/errorHandler.js.map +1 -0
- package/dist/src/common/exceptions/AuthException.d.ts +5 -0
- package/dist/src/common/exceptions/AuthException.d.ts.map +1 -0
- package/dist/src/common/exceptions/AuthException.js +8 -0
- package/dist/src/common/exceptions/AuthException.js.map +1 -0
- package/dist/src/common/exceptions/BaseException.d.ts +4 -0
- package/dist/src/common/exceptions/BaseException.d.ts.map +1 -0
- package/dist/src/common/exceptions/BaseException.js +7 -0
- package/dist/src/common/exceptions/BaseException.js.map +1 -0
- package/dist/src/common/exceptions/BusinessException.d.ts +5 -0
- package/dist/src/common/exceptions/BusinessException.d.ts.map +1 -0
- package/dist/src/common/exceptions/BusinessException.js +8 -0
- package/dist/src/common/exceptions/BusinessException.js.map +1 -0
- package/dist/src/common/exceptions/NotFoundException.d.ts +5 -0
- package/dist/src/common/exceptions/NotFoundException.d.ts.map +1 -0
- package/dist/src/common/exceptions/NotFoundException.js +8 -0
- package/dist/src/common/exceptions/NotFoundException.js.map +1 -0
- package/dist/src/common/exceptions/ServiceException.d.ts +5 -0
- package/dist/src/common/exceptions/ServiceException.d.ts.map +1 -0
- package/dist/src/common/exceptions/ServiceException.js +8 -0
- package/dist/src/common/exceptions/ServiceException.js.map +1 -0
- package/dist/src/common/exceptions/index.d.ts +6 -0
- package/dist/src/common/exceptions/index.d.ts.map +1 -0
- package/dist/src/common/exceptions/index.js +6 -0
- package/dist/src/common/exceptions/index.js.map +1 -0
- package/dist/src/common/migrate/index.d.ts +3 -0
- package/dist/src/common/migrate/index.d.ts.map +1 -0
- package/dist/src/common/migrate/index.js +49 -0
- package/dist/src/common/migrate/index.js.map +1 -0
- package/dist/src/common/redis/index.d.ts +14 -0
- package/dist/src/common/redis/index.d.ts.map +1 -0
- package/dist/src/common/redis/index.js +41 -0
- package/dist/src/common/redis/index.js.map +1 -0
- package/dist/src/common/scanner/auth-factory.d.ts +42 -0
- package/dist/src/common/scanner/auth-factory.d.ts.map +1 -0
- package/dist/src/common/scanner/auth-factory.js +86 -0
- package/dist/src/common/scanner/auth-factory.js.map +1 -0
- package/dist/src/common/scanner/decorators.d.ts +123 -0
- package/dist/src/common/scanner/decorators.d.ts.map +1 -0
- package/dist/src/common/scanner/decorators.js +158 -0
- package/dist/src/common/scanner/decorators.js.map +1 -0
- package/dist/src/common/scanner/handler-factory.d.ts +38 -0
- package/dist/src/common/scanner/handler-factory.d.ts.map +1 -0
- package/dist/src/common/scanner/handler-factory.js +76 -0
- package/dist/src/common/scanner/handler-factory.js.map +1 -0
- package/dist/src/common/scanner/index.d.ts +16 -0
- package/dist/src/common/scanner/index.d.ts.map +1 -0
- package/dist/src/common/scanner/index.js +157 -0
- package/dist/src/common/scanner/index.js.map +1 -0
- package/dist/src/common/validation/decorators.d.ts +28 -0
- package/dist/src/common/validation/decorators.d.ts.map +1 -0
- package/dist/src/common/validation/decorators.js +70 -0
- package/dist/src/common/validation/decorators.js.map +1 -0
- package/dist/src/common/validation/errorRules.d.ts +5 -0
- package/dist/src/common/validation/errorRules.d.ts.map +1 -0
- package/dist/src/common/validation/errorRules.js +56 -0
- package/dist/src/common/validation/errorRules.js.map +1 -0
- package/dist/src/common/validation/index.d.ts +4 -0
- package/dist/src/common/validation/index.d.ts.map +1 -0
- package/dist/src/common/validation/index.js +3 -0
- package/dist/src/common/validation/index.js.map +1 -0
- package/dist/src/common/validation/schema.d.ts +35 -0
- package/dist/src/common/validation/schema.d.ts.map +1 -0
- package/dist/src/common/validation/schema.js +67 -0
- package/dist/src/common/validation/schema.js.map +1 -0
- package/dist/src/index.d.ts +26 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +293 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/main.d.ts +2 -0
- package/dist/src/main.d.ts.map +1 -0
- package/dist/src/main.js +27 -0
- package/dist/src/main.js.map +1 -0
- package/dist/src/modules/health/controller/HealthController.d.ts +11 -0
- package/dist/src/modules/health/controller/HealthController.d.ts.map +1 -0
- package/dist/src/modules/health/controller/HealthController.js +31 -0
- package/dist/src/modules/health/controller/HealthController.js.map +1 -0
- package/dist/src/modules/health/service/HealthService.d.ts +4 -0
- package/dist/src/modules/health/service/HealthService.d.ts.map +1 -0
- package/dist/src/modules/health/service/HealthService.js +6 -0
- package/dist/src/modules/health/service/HealthService.js.map +1 -0
- package/dist/src/types.d.ts +75 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/package.json +53 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HealthService.d.ts","sourceRoot":"","sources":["../../../../../src/modules/health/service/HealthService.ts"],"names":[],"mappings":"AAAA,qBAAa,aAAa;IACxB,SAAS,IAAI,MAAM;CAGpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HealthService.js","sourceRoot":"","sources":["../../../../../src/modules/health/service/HealthService.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,aAAa;IACxB,SAAS;QACP,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { SecretResolver } from './common/auth/SignatureStrategy';
|
|
2
|
+
/**
|
|
3
|
+
* User payload attached to request after successful authentication.
|
|
4
|
+
*/
|
|
5
|
+
export interface User {
|
|
6
|
+
id: string;
|
|
7
|
+
/** Optional role for role-based access control. */
|
|
8
|
+
role?: string;
|
|
9
|
+
/** User type for blacklist lookup (e.g. 'bd', 'merchant', 'admin', 'wx_user'). */
|
|
10
|
+
type?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Application configuration passed to createApp().
|
|
14
|
+
*/
|
|
15
|
+
export interface AppConfig {
|
|
16
|
+
db: {
|
|
17
|
+
host: string;
|
|
18
|
+
port: number;
|
|
19
|
+
user: string;
|
|
20
|
+
password: string;
|
|
21
|
+
database: string;
|
|
22
|
+
connectionLimit?: number;
|
|
23
|
+
};
|
|
24
|
+
auth: {
|
|
25
|
+
jwtSecret?: string;
|
|
26
|
+
/** JWT expiration time, e.g. '30m', '24h'. Default: no expiration. */
|
|
27
|
+
expiresIn?: string;
|
|
28
|
+
};
|
|
29
|
+
/** Optional HMAC signature-based API authentication. */
|
|
30
|
+
signature?: SignatureConfig;
|
|
31
|
+
/** Optional Redis connection. Required if using RedisNonceStore. */
|
|
32
|
+
redis?: RedisConfig;
|
|
33
|
+
/** Optional context path prefix, e.g. "/myapp" ⇒ all routes become /myapp/api/... */
|
|
34
|
+
contextPath?: string;
|
|
35
|
+
/** Optional Swagger / OpenAPI documentation. */
|
|
36
|
+
swagger?: SwaggerConfig;
|
|
37
|
+
/** Optional static file serving configuration. */
|
|
38
|
+
static?: StaticConfig;
|
|
39
|
+
/** Run DB migrations on startup. Scans src/migrations/*.sql. */
|
|
40
|
+
migrate?: boolean;
|
|
41
|
+
port?: number;
|
|
42
|
+
host?: string;
|
|
43
|
+
}
|
|
44
|
+
export interface SignatureConfig {
|
|
45
|
+
/**
|
|
46
|
+
* Resolve appSecret and metadata by clientId.
|
|
47
|
+
* Return null if clientId is unknown.
|
|
48
|
+
*/
|
|
49
|
+
resolveSecret: SecretResolver;
|
|
50
|
+
/** Allowed timestamp drift in milliseconds. Default: 5 minutes. */
|
|
51
|
+
timestampWindowMs?: number;
|
|
52
|
+
}
|
|
53
|
+
export interface RedisConfig {
|
|
54
|
+
host: string;
|
|
55
|
+
port: number;
|
|
56
|
+
password?: string;
|
|
57
|
+
db?: number;
|
|
58
|
+
}
|
|
59
|
+
export interface SwaggerConfig {
|
|
60
|
+
/** API title. Default: package name. */
|
|
61
|
+
title?: string;
|
|
62
|
+
/** API description. */
|
|
63
|
+
description?: string;
|
|
64
|
+
/** API version. Default: package version. */
|
|
65
|
+
version?: string;
|
|
66
|
+
/** Route prefix for Swagger UI. Default: /docs. */
|
|
67
|
+
uiPrefix?: string;
|
|
68
|
+
}
|
|
69
|
+
export interface StaticConfig {
|
|
70
|
+
/** Directory to serve static files from, relative to project root. */
|
|
71
|
+
root: string;
|
|
72
|
+
/** URL prefix for static files, e.g. "/admin". */
|
|
73
|
+
prefix: string;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAEtE;;GAEG;AACH,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,mDAAmD;IACnD,IAAI,CAAC,EAAE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CAA6C;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mDAAmD;IACnD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAC3B,sEAAsE;IACtE,IAAI,EAAE,MAAM,CAAC;IACb,kDAAkD;IAClD,MAAM,EAAE,MAAM,CAAC;CAChB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "fastify-wrap",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A thin wrapper on top of Fastify — decorator-based routing, JWT auth, HMAC signature, JSON Schema validation, DB connection pooling, auto-scanned controllers.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/src/index.js",
|
|
7
|
+
"types": "./dist/src/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/src/index.d.ts",
|
|
11
|
+
"default": "./dist/src/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./client": {
|
|
14
|
+
"types": "./dist/src/client/index.d.ts",
|
|
15
|
+
"default": "./dist/src/client/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsc -p tsconfig.build.json",
|
|
23
|
+
"prepublishOnly": "npm run build",
|
|
24
|
+
"dev": "tsx watch src/main.ts",
|
|
25
|
+
"start": "tsx src/main.ts",
|
|
26
|
+
"test": "vitest run",
|
|
27
|
+
"test:watch": "vitest",
|
|
28
|
+
"format": "prettier --write \"src/**/*.{ts,js}\" \"test/**/*.{ts,js}\"",
|
|
29
|
+
"format:check": "prettier --check \"src/**/*.{ts,js}\" \"test/**/*.{ts,js}\""
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@fastify/jwt": "^10.2.0",
|
|
33
|
+
"@fastify/multipart": "^10.1.0",
|
|
34
|
+
"@fastify/redis": "^8.0.0",
|
|
35
|
+
"@fastify/static": "^10.1.0",
|
|
36
|
+
"@fastify/swagger": "^9.8.1",
|
|
37
|
+
"@fastify/swagger-ui": "^6.1.0",
|
|
38
|
+
"fast-glob": "^3.3.3",
|
|
39
|
+
"fastify": "^5.10.0",
|
|
40
|
+
"knex": "^3.1.0",
|
|
41
|
+
"mysql2": "^3.23.0",
|
|
42
|
+
"pino-pretty": "^11.0.0",
|
|
43
|
+
"reflect-metadata": "^0.2.2",
|
|
44
|
+
"uuid": "^14.0.1"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/node": "^22.0.0",
|
|
48
|
+
"prettier": "^3.9.6",
|
|
49
|
+
"tsx": "^4.23.1",
|
|
50
|
+
"typescript": "^5.8.3",
|
|
51
|
+
"vitest": "^4.1.10"
|
|
52
|
+
}
|
|
53
|
+
}
|