create-charcole 2.1.0 → 2.2.1

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 (79) hide show
  1. package/.github/workflows/release.yml +26 -26
  2. package/CHANGELOG.md +301 -211
  3. package/LICENSE +21 -21
  4. package/README.md +354 -213
  5. package/bin/index.js +444 -288
  6. package/bin/lib/pkgManager.js +49 -49
  7. package/bin/lib/templateHandler.js +33 -33
  8. package/create-charcole-2.1.0.tgz +0 -0
  9. package/package.json +42 -27
  10. package/packages/swagger/BACKWARD_COMPATIBILITY.md +145 -0
  11. package/packages/swagger/CHANGELOG.md +404 -0
  12. package/packages/swagger/README.md +578 -0
  13. package/packages/swagger/charcole-swagger-1.0.0.tgz +0 -0
  14. package/packages/swagger/package-lock.json +1715 -0
  15. package/packages/swagger/package.json +57 -0
  16. package/packages/swagger/src/helpers.js +427 -0
  17. package/packages/swagger/src/index.d.ts +126 -0
  18. package/packages/swagger/src/index.js +12 -0
  19. package/packages/swagger/src/setup.js +100 -0
  20. package/template/js/.env.example +15 -15
  21. package/template/js/README.md +978 -855
  22. package/template/js/basePackage.json +26 -26
  23. package/template/js/src/app.js +81 -78
  24. package/template/js/src/config/constants.js +20 -20
  25. package/template/js/src/config/env.js +26 -26
  26. package/template/js/src/config/swagger.config.js +15 -0
  27. package/template/js/src/lib/swagger/SWAGGER_GUIDE.md +561 -0
  28. package/template/js/src/middlewares/errorHandler.js +180 -180
  29. package/template/js/src/middlewares/requestLogger.js +33 -33
  30. package/template/js/src/middlewares/validateRequest.js +42 -42
  31. package/template/js/src/modules/auth/auth.constants.js +3 -3
  32. package/template/js/src/modules/auth/auth.controller.js +29 -29
  33. package/template/js/src/modules/auth/auth.middlewares.js +19 -19
  34. package/template/js/src/modules/auth/auth.routes.js +131 -9
  35. package/template/js/src/modules/auth/auth.schemas.js +60 -60
  36. package/template/js/src/modules/auth/auth.service.js +67 -67
  37. package/template/js/src/modules/auth/package.json +6 -6
  38. package/template/js/src/modules/health/controller.js +151 -50
  39. package/template/js/src/modules/swagger/charcole-swagger-1.0.0.tgz +0 -0
  40. package/template/js/src/modules/swagger/package.json +5 -0
  41. package/template/js/src/repositories/user.repo.js +19 -19
  42. package/template/js/src/routes/index.js +25 -25
  43. package/template/js/src/routes/protected.js +57 -13
  44. package/template/js/src/server.js +38 -38
  45. package/template/js/src/utils/AppError.js +182 -182
  46. package/template/js/src/utils/logger.js +73 -73
  47. package/template/js/src/utils/response.js +51 -51
  48. package/template/ts/.env.example +15 -15
  49. package/template/ts/README.md +978 -855
  50. package/template/ts/basePackage.json +36 -36
  51. package/template/ts/build.js +46 -46
  52. package/template/ts/src/app.ts +71 -67
  53. package/template/ts/src/config/constants.ts +27 -27
  54. package/template/ts/src/config/env.ts +40 -40
  55. package/template/ts/src/config/swagger.config.ts +30 -0
  56. package/template/ts/src/lib/swagger/SWAGGER_GUIDE.md +561 -0
  57. package/template/ts/src/middlewares/errorHandler.ts +201 -201
  58. package/template/ts/src/middlewares/requestLogger.ts +38 -38
  59. package/template/ts/src/middlewares/validateRequest.ts +46 -46
  60. package/template/ts/src/modules/auth/auth.constants.ts +6 -6
  61. package/template/ts/src/modules/auth/auth.controller.ts +32 -32
  62. package/template/ts/src/modules/auth/auth.middlewares.ts +46 -46
  63. package/template/ts/src/modules/auth/auth.routes.ts +52 -9
  64. package/template/ts/src/modules/auth/auth.schemas.ts +73 -73
  65. package/template/ts/src/modules/auth/auth.service.ts +106 -106
  66. package/template/ts/src/modules/auth/package.json +10 -10
  67. package/template/ts/src/modules/health/controller.ts +80 -64
  68. package/template/ts/src/modules/swagger/charcole-swagger-1.0.0.tgz +0 -0
  69. package/template/ts/src/modules/swagger/package.json +5 -0
  70. package/template/ts/src/repositories/user.repo.ts +33 -33
  71. package/template/ts/src/routes/index.ts +24 -24
  72. package/template/ts/src/routes/protected.ts +46 -13
  73. package/template/ts/src/server.ts +41 -41
  74. package/template/ts/src/types/express.d.ts +9 -9
  75. package/template/ts/src/utils/AppError.ts +220 -220
  76. package/template/ts/src/utils/logger.ts +55 -55
  77. package/template/ts/src/utils/response.ts +100 -100
  78. package/template/ts/tsconfig.json +26 -26
  79. package/plans/V2_1_PLAN.md +0 -20
@@ -0,0 +1,5 @@
1
+ {
2
+ "dependencies": {
3
+ "@charcoles/swagger": "file:./charcole-swagger-1.0.0.tgz"
4
+ }
5
+ }
@@ -1,33 +1,33 @@
1
- import { randomUUID } from "crypto";
2
- import type { User } from "../modules/auth/auth.schemas.ts";
3
-
4
- const users: User[] = [];
5
-
6
- type CreateUserData = {
7
- email: string;
8
- name: string;
9
- passwordHash: string;
10
- };
11
-
12
- export const userRepo = {
13
- async findByEmail(email: string): Promise<User | undefined> {
14
- return users.find((u) => u.email === email);
15
- },
16
-
17
- async create(data: CreateUserData): Promise<User> {
18
- const user: User = {
19
- id: randomUUID(),
20
- email: data.email,
21
- name: data.name,
22
- passwordHash: data.passwordHash,
23
- role: "user",
24
- provider: "credentials",
25
- isEmailVerified: false,
26
- createdAt: new Date(),
27
- updatedAt: new Date(),
28
- };
29
-
30
- users.push(user);
31
- return user;
32
- },
33
- };
1
+ import { randomUUID } from "crypto";
2
+ import type { User } from "../modules/auth/auth.schemas.ts";
3
+
4
+ const users: User[] = [];
5
+
6
+ type CreateUserData = {
7
+ email: string;
8
+ name: string;
9
+ passwordHash: string;
10
+ };
11
+
12
+ export const userRepo = {
13
+ async findByEmail(email: string): Promise<User | undefined> {
14
+ return users.find((u) => u.email === email);
15
+ },
16
+
17
+ async create(data: CreateUserData): Promise<User> {
18
+ const user: User = {
19
+ id: randomUUID(),
20
+ email: data.email,
21
+ name: data.name,
22
+ passwordHash: data.passwordHash,
23
+ role: "user",
24
+ provider: "credentials",
25
+ isEmailVerified: false,
26
+ createdAt: new Date(),
27
+ updatedAt: new Date(),
28
+ };
29
+
30
+ users.push(user);
31
+ return user;
32
+ },
33
+ };
@@ -1,24 +1,24 @@
1
- import { Router } from "express";
2
- import {
3
- getHealth,
4
- createItem,
5
- createItemSchema,
6
- } from "../modules/health/controller.ts";
7
- import { validateRequest } from "../middlewares/validateRequest.ts";
8
- import protectedRoutes from "./protected.ts";
9
- import authRoutes from "../modules/auth/auth.routes.ts";
10
- const router = Router();
11
-
12
- // Health check
13
- router.get("/health", getHealth);
14
-
15
- // Example: Create item with validation
16
- router.post("/items", validateRequest(createItemSchema), createItem);
17
-
18
- // 🔐 Auth routes
19
- router.use("/auth", authRoutes);
20
-
21
- // 🔐 Protected routes (REQUIRED BEARER TOKEN FOR THEM)
22
- router.use("/protected", protectedRoutes);
23
-
24
- export default router;
1
+ import { Router } from "express";
2
+ import {
3
+ getHealth,
4
+ createItem,
5
+ createItemSchema,
6
+ } from "../modules/health/controller.ts";
7
+ import { validateRequest } from "../middlewares/validateRequest.ts";
8
+ import protectedRoutes from "./protected.ts";
9
+ import authRoutes from "../modules/auth/auth.routes.ts";
10
+ const router = Router();
11
+
12
+ // Health check
13
+ router.get("/health", getHealth);
14
+
15
+ // Example: Create item with validation
16
+ router.post("/items", validateRequest(createItemSchema), createItem);
17
+
18
+ // 🔐 Auth routes
19
+ router.use("/auth", authRoutes);
20
+
21
+ // 🔐 Protected routes (REQUIRED BEARER TOKEN FOR THEM)
22
+ router.use("/protected", protectedRoutes);
23
+
24
+ export default router;
@@ -1,13 +1,46 @@
1
- import { Router } from "express";
2
- import { requireAuth } from "../modules/auth/auth.middlewares.ts";
3
-
4
- const router = Router();
5
-
6
- router.get("/me", requireAuth, (req, res) => {
7
- res.json({
8
- message: "You are authenticated",
9
- user: req.user,
10
- });
11
- });
12
-
13
- export default router;
1
+ import { Router } from "express";
2
+ import { requireAuth } from "../modules/auth/auth.middlewares.ts";
3
+
4
+ const router = Router();
5
+
6
+ /**
7
+ * @swagger
8
+ * /api/protected/me:
9
+ * get:
10
+ * summary: Get current user profile
11
+ * description: Returns the authenticated user's information
12
+ * tags:
13
+ * - Protected
14
+ * security:
15
+ * - bearerAuth: []
16
+ * responses:
17
+ * 200:
18
+ * description: User profile retrieved successfully
19
+ * content:
20
+ * application/json:
21
+ * schema:
22
+ * type: object
23
+ * properties:
24
+ * message:
25
+ * type: string
26
+ * example: You are authenticated
27
+ * user:
28
+ * type: object
29
+ * properties:
30
+ * id:
31
+ * type: string
32
+ * example: user_123abc
33
+ * email:
34
+ * type: string
35
+ * example: user@example.com
36
+ * 401:
37
+ * description: Unauthorized - Invalid or missing token
38
+ */
39
+ router.get("/me", requireAuth, (req, res) => {
40
+ res.json({
41
+ message: "You are authenticated",
42
+ user: req.user,
43
+ });
44
+ });
45
+
46
+ export default router;
@@ -1,41 +1,41 @@
1
- import "dotenv/config";
2
- import { app } from "./app.js";
3
- import { env } from "./config/env.js";
4
- import { logger } from "./utils/logger.js";
5
-
6
- const PORT = env.PORT;
7
-
8
- const server = app.listen(PORT, () => {
9
- logger.info(`🔥 Server running in ${env.NODE_ENV} mode`, {
10
- url: `http://localhost:${PORT}`,
11
- port: PORT,
12
- });
13
- });
14
-
15
- const gracefulShutdown = (signal: string): void => {
16
- logger.warn(`${signal} signal received: closing HTTP server`);
17
-
18
- server.close(() => {
19
- logger.info("HTTP server closed");
20
- process.exit(0);
21
- });
22
- };
23
-
24
- process.on("SIGTERM", () => gracefulShutdown("SIGTERM"));
25
- process.on("SIGINT", () => gracefulShutdown("SIGINT"));
26
-
27
- process.on(
28
- "unhandledRejection",
29
- (reason: unknown, promise: Promise<unknown>) => {
30
- logger.error("Unhandled Rejection at:", { promise, reason });
31
- process.exit(1);
32
- },
33
- );
34
-
35
- process.on("uncaughtException", (error: Error) => {
36
- logger.error("Uncaught Exception:", {
37
- message: error.message,
38
- stack: error.stack,
39
- });
40
- process.exit(1);
41
- });
1
+ import "dotenv/config";
2
+ import { app } from "./app.ts";
3
+ import { env } from "./config/env.ts";
4
+ import { logger } from "./utils/logger.ts";
5
+
6
+ const PORT = env.PORT;
7
+
8
+ const server = app.listen(PORT, () => {
9
+ logger.info(`🔥 Server running in ${env.NODE_ENV} mode`, {
10
+ url: `http://localhost:${PORT}`,
11
+ port: PORT,
12
+ });
13
+ });
14
+
15
+ const gracefulShutdown = (signal: string): void => {
16
+ logger.warn(`${signal} signal received: closing HTTP server`);
17
+
18
+ server.close(() => {
19
+ logger.info("HTTP server closed");
20
+ process.exit(0);
21
+ });
22
+ };
23
+
24
+ process.on("SIGTERM", () => gracefulShutdown("SIGTERM"));
25
+ process.on("SIGINT", () => gracefulShutdown("SIGINT"));
26
+
27
+ process.on(
28
+ "unhandledRejection",
29
+ (reason: unknown, promise: Promise<unknown>) => {
30
+ logger.error("Unhandled Rejection at:", { promise, reason });
31
+ process.exit(1);
32
+ },
33
+ );
34
+
35
+ process.on("uncaughtException", (error: Error) => {
36
+ logger.error("Uncaught Exception:", {
37
+ message: error.message,
38
+ stack: error.stack,
39
+ });
40
+ process.exit(1);
41
+ });
@@ -1,9 +1,9 @@
1
- import { Request } from "express";
2
-
3
- declare global {
4
- namespace Express {
5
- interface Request {
6
- validatedData?: Record<string, any>;
7
- }
8
- }
9
- }
1
+ import { Request } from "express";
2
+
3
+ declare global {
4
+ namespace Express {
5
+ interface Request {
6
+ validatedData?: Record<string, any>;
7
+ }
8
+ }
9
+ }