create-charcole 2.2.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 (72) hide show
  1. package/.github/workflows/release.yml +26 -26
  2. package/CHANGELOG.md +301 -301
  3. package/LICENSE +21 -21
  4. package/README.md +354 -354
  5. package/bin/index.js +444 -444
  6. package/bin/lib/pkgManager.js +49 -49
  7. package/bin/lib/templateHandler.js +33 -33
  8. package/package.json +42 -27
  9. package/packages/swagger/package-lock.json +1715 -1715
  10. package/packages/swagger/package.json +57 -44
  11. package/packages/swagger/src/index.d.ts +126 -126
  12. package/packages/swagger/src/index.js +12 -12
  13. package/packages/swagger/src/setup.js +100 -100
  14. package/template/js/.env.example +15 -15
  15. package/template/js/README.md +978 -978
  16. package/template/js/basePackage.json +26 -26
  17. package/template/js/src/app.js +81 -81
  18. package/template/js/src/config/constants.js +20 -20
  19. package/template/js/src/config/env.js +26 -26
  20. package/template/js/src/config/swagger.config.js +15 -15
  21. package/template/js/src/middlewares/errorHandler.js +180 -180
  22. package/template/js/src/middlewares/requestLogger.js +33 -33
  23. package/template/js/src/middlewares/validateRequest.js +42 -42
  24. package/template/js/src/modules/auth/auth.constants.js +3 -3
  25. package/template/js/src/modules/auth/auth.controller.js +29 -29
  26. package/template/js/src/modules/auth/auth.middlewares.js +19 -19
  27. package/template/js/src/modules/auth/auth.routes.js +131 -131
  28. package/template/js/src/modules/auth/auth.schemas.js +60 -60
  29. package/template/js/src/modules/auth/auth.service.js +67 -67
  30. package/template/js/src/modules/auth/package.json +6 -6
  31. package/template/js/src/modules/health/controller.js +151 -151
  32. package/template/js/src/modules/swagger/package.json +5 -5
  33. package/template/js/src/repositories/user.repo.js +19 -19
  34. package/template/js/src/routes/index.js +25 -25
  35. package/template/js/src/routes/protected.js +57 -57
  36. package/template/js/src/server.js +38 -38
  37. package/template/js/src/utils/AppError.js +182 -182
  38. package/template/js/src/utils/logger.js +73 -73
  39. package/template/js/src/utils/response.js +51 -51
  40. package/template/ts/.env.example +15 -15
  41. package/template/ts/README.md +978 -978
  42. package/template/ts/basePackage.json +36 -36
  43. package/template/ts/build.js +46 -46
  44. package/template/ts/src/app.ts +71 -71
  45. package/template/ts/src/config/constants.ts +27 -27
  46. package/template/ts/src/config/env.ts +40 -40
  47. package/template/ts/src/config/swagger.config.ts +30 -30
  48. package/template/ts/src/middlewares/errorHandler.ts +201 -201
  49. package/template/ts/src/middlewares/requestLogger.ts +38 -38
  50. package/template/ts/src/middlewares/validateRequest.ts +46 -46
  51. package/template/ts/src/modules/auth/auth.constants.ts +6 -6
  52. package/template/ts/src/modules/auth/auth.controller.ts +32 -32
  53. package/template/ts/src/modules/auth/auth.middlewares.ts +46 -46
  54. package/template/ts/src/modules/auth/auth.routes.ts +52 -52
  55. package/template/ts/src/modules/auth/auth.schemas.ts +73 -73
  56. package/template/ts/src/modules/auth/auth.service.ts +106 -106
  57. package/template/ts/src/modules/auth/package.json +10 -10
  58. package/template/ts/src/modules/health/controller.ts +80 -80
  59. package/template/ts/src/modules/swagger/package.json +5 -5
  60. package/template/ts/src/repositories/user.repo.ts +33 -33
  61. package/template/ts/src/routes/index.ts +24 -24
  62. package/template/ts/src/routes/protected.ts +46 -46
  63. package/template/ts/src/server.ts +41 -41
  64. package/template/ts/src/types/express.d.ts +9 -9
  65. package/template/ts/src/utils/AppError.ts +220 -220
  66. package/template/ts/src/utils/logger.ts +55 -55
  67. package/template/ts/src/utils/response.ts +100 -100
  68. package/template/ts/tsconfig.json +26 -26
  69. package/tmpclaude-1049-cwd +0 -1
  70. package/tmpclaude-3e37-cwd +0 -1
  71. package/tmpclaude-4d73-cwd +0 -1
  72. package/tmpclaude-8a8e-cwd +0 -1
@@ -1,26 +1,26 @@
1
- {
2
- "name": "charcole",
3
- "version": "2.2.0",
4
- "description": "Production-grade Node.js Express API",
5
- "main": "src/server.js",
6
- "type": "module",
7
- "engines": {
8
- "node": ">=18.0.0"
9
- },
10
- "scripts": {
11
- "start": "node src/server.js",
12
- "dev": "nodemon src/server.js",
13
- "lint": "echo \"Add linting here\"",
14
- "test": "echo \"Add tests here\""
15
- },
16
- "dependencies": {
17
- "express": "^4.18.2",
18
- "cors": "^2.8.5",
19
- "dotenv": "^16.3.1",
20
- "zod": "^3.25.76"
21
- },
22
- "devDependencies": {
23
- "nodemon": "^3.0.2"
24
- },
25
- "license": "ISC"
26
- }
1
+ {
2
+ "name": "charcole",
3
+ "version": "2.2.1",
4
+ "description": "Production-grade Node.js Express API",
5
+ "main": "src/server.js",
6
+ "type": "module",
7
+ "engines": {
8
+ "node": ">=18.0.0"
9
+ },
10
+ "scripts": {
11
+ "start": "node src/server.js",
12
+ "dev": "nodemon src/server.js",
13
+ "lint": "echo \"Add linting here\"",
14
+ "test": "echo \"Add tests here\""
15
+ },
16
+ "dependencies": {
17
+ "express": "^4.18.2",
18
+ "cors": "^2.8.5",
19
+ "dotenv": "^16.3.1",
20
+ "zod": "^3.25.76"
21
+ },
22
+ "devDependencies": {
23
+ "nodemon": "^3.0.2"
24
+ },
25
+ "license": "ISC"
26
+ }
@@ -1,81 +1,81 @@
1
- import express from "express";
2
- import { userRepo } from "./repositories/user.repo.js";
3
- import cors from "cors";
4
- import { env } from "./config/env.js";
5
- import { HTTP_STATUS, ERROR_MESSAGES } from "./config/constants.js";
6
- import { requestLogger } from "./middlewares/requestLogger.js";
7
- import {
8
- errorHandler,
9
- asyncHandler,
10
- NotFoundError,
11
- } from "./middlewares/errorHandler.js";
12
- import { sendSuccess } from "./utils/response.js";
13
- import { logger } from "./utils/logger.js";
14
- import routes from "./routes/index.js";
15
- import swaggerOptions from "./config/swagger.config.js";
16
- import { setupSwagger } from "@charcoles/swagger";
17
- export const app = express();
18
-
19
- // Trust proxy
20
- app.set("trust proxy", 1);
21
-
22
- // CORS Configuration
23
- app.use(
24
- cors({
25
- origin: env.CORS_ORIGIN,
26
- credentials: true,
27
- methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
28
- allowedHeaders: ["Content-Type", "Authorization"],
29
- }),
30
- );
31
-
32
- // Body parsing middleware
33
- app.use(express.json({ limit: "10mb" }));
34
- app.use(express.urlencoded({ extended: true, limit: "10mb" }));
35
-
36
- // Request timeout
37
- app.use((req, res, next) => {
38
- req.setTimeout(env.REQUEST_TIMEOUT);
39
- res.setTimeout(env.REQUEST_TIMEOUT);
40
- next();
41
- });
42
-
43
- // Request logging
44
- app.use(requestLogger);
45
-
46
- setupSwagger(app, swaggerOptions);
47
-
48
- // API Routes
49
- app.use("/api", routes);
50
-
51
- // Root health endpoint
52
- app.get(
53
- "/",
54
- asyncHandler(async (req, res) => {
55
- sendSuccess(
56
- res,
57
- {
58
- message: "Welcome to Charcole API",
59
- version: "1.0.0",
60
- environment: env.NODE_ENV,
61
- },
62
- 200,
63
- "API is online",
64
- );
65
- }),
66
- );
67
-
68
- // 404 handler
69
- app.use((req, res, next) => {
70
- throw new NotFoundError(`${req.method} ${req.path}`, {
71
- method: req.method,
72
- path: req.path,
73
- });
74
- });
75
-
76
- // Global error handler (MUST be last)
77
- app.use(errorHandler);
78
-
79
- logger.info("Express app configured successfully");
80
-
81
- app.locals.userRepo = userRepo;
1
+ import express from "express";
2
+ import { userRepo } from "./repositories/user.repo.js";
3
+ import cors from "cors";
4
+ import { env } from "./config/env.js";
5
+ import { HTTP_STATUS, ERROR_MESSAGES } from "./config/constants.js";
6
+ import { requestLogger } from "./middlewares/requestLogger.js";
7
+ import {
8
+ errorHandler,
9
+ asyncHandler,
10
+ NotFoundError,
11
+ } from "./middlewares/errorHandler.js";
12
+ import { sendSuccess } from "./utils/response.js";
13
+ import { logger } from "./utils/logger.js";
14
+ import routes from "./routes/index.js";
15
+ import swaggerOptions from "./config/swagger.config.js";
16
+ import { setupSwagger } from "@charcoles/swagger";
17
+ export const app = express();
18
+
19
+ // Trust proxy
20
+ app.set("trust proxy", 1);
21
+
22
+ // CORS Configuration
23
+ app.use(
24
+ cors({
25
+ origin: env.CORS_ORIGIN,
26
+ credentials: true,
27
+ methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
28
+ allowedHeaders: ["Content-Type", "Authorization"],
29
+ }),
30
+ );
31
+
32
+ // Body parsing middleware
33
+ app.use(express.json({ limit: "10mb" }));
34
+ app.use(express.urlencoded({ extended: true, limit: "10mb" }));
35
+
36
+ // Request timeout
37
+ app.use((req, res, next) => {
38
+ req.setTimeout(env.REQUEST_TIMEOUT);
39
+ res.setTimeout(env.REQUEST_TIMEOUT);
40
+ next();
41
+ });
42
+
43
+ // Request logging
44
+ app.use(requestLogger);
45
+
46
+ setupSwagger(app, swaggerOptions);
47
+
48
+ // API Routes
49
+ app.use("/api", routes);
50
+
51
+ // Root health endpoint
52
+ app.get(
53
+ "/",
54
+ asyncHandler(async (req, res) => {
55
+ sendSuccess(
56
+ res,
57
+ {
58
+ message: "Welcome to Charcole API",
59
+ version: "1.0.0",
60
+ environment: env.NODE_ENV,
61
+ },
62
+ 200,
63
+ "API is online",
64
+ );
65
+ }),
66
+ );
67
+
68
+ // 404 handler
69
+ app.use((req, res, next) => {
70
+ throw new NotFoundError(`${req.method} ${req.path}`, {
71
+ method: req.method,
72
+ path: req.path,
73
+ });
74
+ });
75
+
76
+ // Global error handler (MUST be last)
77
+ app.use(errorHandler);
78
+
79
+ logger.info("Express app configured successfully");
80
+
81
+ app.locals.userRepo = userRepo;
@@ -1,20 +1,20 @@
1
- export const HTTP_STATUS = {
2
- OK: 200,
3
- CREATED: 201,
4
- BAD_REQUEST: 400,
5
- UNAUTHORIZED: 401,
6
- FORBIDDEN: 403,
7
- NOT_FOUND: 404,
8
- CONFLICT: 409,
9
- UNPROCESSABLE_ENTITY: 422,
10
- INTERNAL_SERVER_ERROR: 500,
11
- SERVICE_UNAVAILABLE: 503,
12
- };
13
-
14
- export const ERROR_MESSAGES = {
15
- VALIDATION_ERROR: "Validation failed",
16
- NOT_FOUND: "Resource not found",
17
- UNAUTHORIZED: "Unauthorized",
18
- SERVER_ERROR: "Internal server error",
19
- BAD_REQUEST: "Bad request",
20
- };
1
+ export const HTTP_STATUS = {
2
+ OK: 200,
3
+ CREATED: 201,
4
+ BAD_REQUEST: 400,
5
+ UNAUTHORIZED: 401,
6
+ FORBIDDEN: 403,
7
+ NOT_FOUND: 404,
8
+ CONFLICT: 409,
9
+ UNPROCESSABLE_ENTITY: 422,
10
+ INTERNAL_SERVER_ERROR: 500,
11
+ SERVICE_UNAVAILABLE: 503,
12
+ };
13
+
14
+ export const ERROR_MESSAGES = {
15
+ VALIDATION_ERROR: "Validation failed",
16
+ NOT_FOUND: "Resource not found",
17
+ UNAUTHORIZED: "Unauthorized",
18
+ SERVER_ERROR: "Internal server error",
19
+ BAD_REQUEST: "Bad request",
20
+ };
@@ -1,26 +1,26 @@
1
- import { z } from "zod";
2
-
3
- const envSchema = z.object({
4
- NODE_ENV: z
5
- .enum(["development", "production", "test"])
6
- .default("development"),
7
- PORT: z.coerce.number().default(3000),
8
- LOG_LEVEL: z.enum(["debug", "info", "warn", "error"]).default("info"),
9
- CORS_ORIGIN: z.string().default("*"),
10
- REQUEST_TIMEOUT: z.coerce.number().default(30000),
11
- });
12
-
13
- const parseEnv = () => {
14
- try {
15
- return envSchema.parse(process.env);
16
- } catch (error) {
17
- console.error("❌ Invalid environment variables:", error.errors);
18
- process.exit(1);
19
- }
20
- };
21
-
22
- export const env = parseEnv();
23
-
24
- export const isDevelopment = env.NODE_ENV === "development";
25
- export const isProduction = env.NODE_ENV === "production";
26
- export const isTest = env.NODE_ENV === "test";
1
+ import { z } from "zod";
2
+
3
+ const envSchema = z.object({
4
+ NODE_ENV: z
5
+ .enum(["development", "production", "test"])
6
+ .default("development"),
7
+ PORT: z.coerce.number().default(3000),
8
+ LOG_LEVEL: z.enum(["debug", "info", "warn", "error"]).default("info"),
9
+ CORS_ORIGIN: z.string().default("*"),
10
+ REQUEST_TIMEOUT: z.coerce.number().default(30000),
11
+ });
12
+
13
+ const parseEnv = () => {
14
+ try {
15
+ return envSchema.parse(process.env);
16
+ } catch (error) {
17
+ console.error("❌ Invalid environment variables:", error.errors);
18
+ process.exit(1);
19
+ }
20
+ };
21
+
22
+ export const env = parseEnv();
23
+
24
+ export const isDevelopment = env.NODE_ENV === "development";
25
+ export const isProduction = env.NODE_ENV === "production";
26
+ export const isTest = env.NODE_ENV === "test";
@@ -1,15 +1,15 @@
1
- export default {
2
- title: process.env.APP_NAME || "Charcole API",
3
- version: process.env.APP_VERSION || "1.0.0",
4
- description: "Production-ready Node.js Express API",
5
- path: "/api-docs",
6
- servers: [
7
- {
8
- url: process.env.API_URL || "http://localhost:3000",
9
- description:
10
- process.env.NODE_ENV === "production"
11
- ? "Production server"
12
- : "Development server",
13
- },
14
- ],
15
- };
1
+ export default {
2
+ title: process.env.APP_NAME || "Charcole API",
3
+ version: process.env.APP_VERSION || "1.0.0",
4
+ description: "Production-ready Node.js Express API",
5
+ path: "/api-docs",
6
+ servers: [
7
+ {
8
+ url: process.env.API_URL || "http://localhost:3000",
9
+ description:
10
+ process.env.NODE_ENV === "production"
11
+ ? "Production server"
12
+ : "Development server",
13
+ },
14
+ ],
15
+ };