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.
Files changed (150) hide show
  1. package/README.md +980 -0
  2. package/dist/src/client/TestClient.d.ts +33 -0
  3. package/dist/src/client/TestClient.d.ts.map +1 -0
  4. package/dist/src/client/TestClient.js +359 -0
  5. package/dist/src/client/TestClient.js.map +1 -0
  6. package/dist/src/client/index.d.ts +4 -0
  7. package/dist/src/client/index.d.ts.map +1 -0
  8. package/dist/src/client/index.js +3 -0
  9. package/dist/src/client/index.js.map +1 -0
  10. package/dist/src/client/sign.d.ts +12 -0
  11. package/dist/src/client/sign.d.ts.map +1 -0
  12. package/dist/src/client/sign.js +44 -0
  13. package/dist/src/client/sign.js.map +1 -0
  14. package/dist/src/client/types.d.ts +41 -0
  15. package/dist/src/client/types.d.ts.map +1 -0
  16. package/dist/src/client/types.js +20 -0
  17. package/dist/src/client/types.js.map +1 -0
  18. package/dist/src/common/auth/AuthStrategy.d.ts +6 -0
  19. package/dist/src/common/auth/AuthStrategy.d.ts.map +1 -0
  20. package/dist/src/common/auth/AuthStrategy.js +2 -0
  21. package/dist/src/common/auth/AuthStrategy.js.map +1 -0
  22. package/dist/src/common/auth/JwtStrategy.d.ts +9 -0
  23. package/dist/src/common/auth/JwtStrategy.d.ts.map +1 -0
  24. package/dist/src/common/auth/JwtStrategy.js +34 -0
  25. package/dist/src/common/auth/JwtStrategy.js.map +1 -0
  26. package/dist/src/common/auth/NonceStore.d.ts +22 -0
  27. package/dist/src/common/auth/NonceStore.d.ts.map +1 -0
  28. package/dist/src/common/auth/NonceStore.js +27 -0
  29. package/dist/src/common/auth/NonceStore.js.map +1 -0
  30. package/dist/src/common/auth/SecretResolvers.d.ts +18 -0
  31. package/dist/src/common/auth/SecretResolvers.d.ts.map +1 -0
  32. package/dist/src/common/auth/SecretResolvers.js +30 -0
  33. package/dist/src/common/auth/SecretResolvers.js.map +1 -0
  34. package/dist/src/common/auth/SignatureStrategy.d.ts +23 -0
  35. package/dist/src/common/auth/SignatureStrategy.d.ts.map +1 -0
  36. package/dist/src/common/auth/SignatureStrategy.js +115 -0
  37. package/dist/src/common/auth/SignatureStrategy.js.map +1 -0
  38. package/dist/src/common/auth/index.d.ts +4 -0
  39. package/dist/src/common/auth/index.d.ts.map +1 -0
  40. package/dist/src/common/auth/index.js +3 -0
  41. package/dist/src/common/auth/index.js.map +1 -0
  42. package/dist/src/common/auth/signToken.d.ts +4 -0
  43. package/dist/src/common/auth/signToken.d.ts.map +1 -0
  44. package/dist/src/common/auth/signToken.js +11 -0
  45. package/dist/src/common/auth/signToken.js.map +1 -0
  46. package/dist/src/common/config/loader.d.ts +10 -0
  47. package/dist/src/common/config/loader.d.ts.map +1 -0
  48. package/dist/src/common/config/loader.js +20 -0
  49. package/dist/src/common/config/loader.js.map +1 -0
  50. package/dist/src/common/container/index.d.ts +7 -0
  51. package/dist/src/common/container/index.d.ts.map +1 -0
  52. package/dist/src/common/container/index.js +15 -0
  53. package/dist/src/common/container/index.js.map +1 -0
  54. package/dist/src/common/db/index.d.ts +19 -0
  55. package/dist/src/common/db/index.d.ts.map +1 -0
  56. package/dist/src/common/db/index.js +64 -0
  57. package/dist/src/common/db/index.js.map +1 -0
  58. package/dist/src/common/dto/PageResult.d.ts +12 -0
  59. package/dist/src/common/dto/PageResult.d.ts.map +1 -0
  60. package/dist/src/common/dto/PageResult.js +2 -0
  61. package/dist/src/common/dto/PageResult.js.map +1 -0
  62. package/dist/src/common/errorHandler.d.ts +3 -0
  63. package/dist/src/common/errorHandler.d.ts.map +1 -0
  64. package/dist/src/common/errorHandler.js +47 -0
  65. package/dist/src/common/errorHandler.js.map +1 -0
  66. package/dist/src/common/exceptions/AuthException.d.ts +5 -0
  67. package/dist/src/common/exceptions/AuthException.d.ts.map +1 -0
  68. package/dist/src/common/exceptions/AuthException.js +8 -0
  69. package/dist/src/common/exceptions/AuthException.js.map +1 -0
  70. package/dist/src/common/exceptions/BaseException.d.ts +4 -0
  71. package/dist/src/common/exceptions/BaseException.d.ts.map +1 -0
  72. package/dist/src/common/exceptions/BaseException.js +7 -0
  73. package/dist/src/common/exceptions/BaseException.js.map +1 -0
  74. package/dist/src/common/exceptions/BusinessException.d.ts +5 -0
  75. package/dist/src/common/exceptions/BusinessException.d.ts.map +1 -0
  76. package/dist/src/common/exceptions/BusinessException.js +8 -0
  77. package/dist/src/common/exceptions/BusinessException.js.map +1 -0
  78. package/dist/src/common/exceptions/NotFoundException.d.ts +5 -0
  79. package/dist/src/common/exceptions/NotFoundException.d.ts.map +1 -0
  80. package/dist/src/common/exceptions/NotFoundException.js +8 -0
  81. package/dist/src/common/exceptions/NotFoundException.js.map +1 -0
  82. package/dist/src/common/exceptions/ServiceException.d.ts +5 -0
  83. package/dist/src/common/exceptions/ServiceException.d.ts.map +1 -0
  84. package/dist/src/common/exceptions/ServiceException.js +8 -0
  85. package/dist/src/common/exceptions/ServiceException.js.map +1 -0
  86. package/dist/src/common/exceptions/index.d.ts +6 -0
  87. package/dist/src/common/exceptions/index.d.ts.map +1 -0
  88. package/dist/src/common/exceptions/index.js +6 -0
  89. package/dist/src/common/exceptions/index.js.map +1 -0
  90. package/dist/src/common/migrate/index.d.ts +3 -0
  91. package/dist/src/common/migrate/index.d.ts.map +1 -0
  92. package/dist/src/common/migrate/index.js +49 -0
  93. package/dist/src/common/migrate/index.js.map +1 -0
  94. package/dist/src/common/redis/index.d.ts +14 -0
  95. package/dist/src/common/redis/index.d.ts.map +1 -0
  96. package/dist/src/common/redis/index.js +41 -0
  97. package/dist/src/common/redis/index.js.map +1 -0
  98. package/dist/src/common/scanner/auth-factory.d.ts +42 -0
  99. package/dist/src/common/scanner/auth-factory.d.ts.map +1 -0
  100. package/dist/src/common/scanner/auth-factory.js +86 -0
  101. package/dist/src/common/scanner/auth-factory.js.map +1 -0
  102. package/dist/src/common/scanner/decorators.d.ts +123 -0
  103. package/dist/src/common/scanner/decorators.d.ts.map +1 -0
  104. package/dist/src/common/scanner/decorators.js +158 -0
  105. package/dist/src/common/scanner/decorators.js.map +1 -0
  106. package/dist/src/common/scanner/handler-factory.d.ts +38 -0
  107. package/dist/src/common/scanner/handler-factory.d.ts.map +1 -0
  108. package/dist/src/common/scanner/handler-factory.js +76 -0
  109. package/dist/src/common/scanner/handler-factory.js.map +1 -0
  110. package/dist/src/common/scanner/index.d.ts +16 -0
  111. package/dist/src/common/scanner/index.d.ts.map +1 -0
  112. package/dist/src/common/scanner/index.js +157 -0
  113. package/dist/src/common/scanner/index.js.map +1 -0
  114. package/dist/src/common/validation/decorators.d.ts +28 -0
  115. package/dist/src/common/validation/decorators.d.ts.map +1 -0
  116. package/dist/src/common/validation/decorators.js +70 -0
  117. package/dist/src/common/validation/decorators.js.map +1 -0
  118. package/dist/src/common/validation/errorRules.d.ts +5 -0
  119. package/dist/src/common/validation/errorRules.d.ts.map +1 -0
  120. package/dist/src/common/validation/errorRules.js +56 -0
  121. package/dist/src/common/validation/errorRules.js.map +1 -0
  122. package/dist/src/common/validation/index.d.ts +4 -0
  123. package/dist/src/common/validation/index.d.ts.map +1 -0
  124. package/dist/src/common/validation/index.js +3 -0
  125. package/dist/src/common/validation/index.js.map +1 -0
  126. package/dist/src/common/validation/schema.d.ts +35 -0
  127. package/dist/src/common/validation/schema.d.ts.map +1 -0
  128. package/dist/src/common/validation/schema.js +67 -0
  129. package/dist/src/common/validation/schema.js.map +1 -0
  130. package/dist/src/index.d.ts +26 -0
  131. package/dist/src/index.d.ts.map +1 -0
  132. package/dist/src/index.js +293 -0
  133. package/dist/src/index.js.map +1 -0
  134. package/dist/src/main.d.ts +2 -0
  135. package/dist/src/main.d.ts.map +1 -0
  136. package/dist/src/main.js +27 -0
  137. package/dist/src/main.js.map +1 -0
  138. package/dist/src/modules/health/controller/HealthController.d.ts +11 -0
  139. package/dist/src/modules/health/controller/HealthController.d.ts.map +1 -0
  140. package/dist/src/modules/health/controller/HealthController.js +31 -0
  141. package/dist/src/modules/health/controller/HealthController.js.map +1 -0
  142. package/dist/src/modules/health/service/HealthService.d.ts +4 -0
  143. package/dist/src/modules/health/service/HealthService.d.ts.map +1 -0
  144. package/dist/src/modules/health/service/HealthService.js +6 -0
  145. package/dist/src/modules/health/service/HealthService.js.map +1 -0
  146. package/dist/src/types.d.ts +75 -0
  147. package/dist/src/types.d.ts.map +1 -0
  148. package/dist/src/types.js +2 -0
  149. package/dist/src/types.js.map +1 -0
  150. package/package.json +53 -0
@@ -0,0 +1,4 @@
1
+ export declare class HealthService {
2
+ getStatus(): string;
3
+ }
4
+ //# sourceMappingURL=HealthService.d.ts.map
@@ -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,6 @@
1
+ export class HealthService {
2
+ getStatus() {
3
+ return 'ok';
4
+ }
5
+ }
6
+ //# sourceMappingURL=HealthService.js.map
@@ -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,MAAM,CAAC;IACd,kFAAk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C,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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -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
+ }