create-charcole 2.2.0 → 2.2.2
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/.github/workflows/release.yml +26 -26
- package/CHANGELOG.md +301 -301
- package/LICENSE +21 -21
- package/README.md +357 -354
- package/bin/index.js +494 -444
- package/bin/lib/pkgManager.js +49 -49
- package/bin/lib/templateHandler.js +33 -33
- package/package.json +42 -27
- package/packages/swagger/BACKWARD_COMPATIBILITY.md +1 -1
- package/packages/swagger/CHANGELOG.md +1 -1
- package/packages/swagger/README.md +3 -3
- package/packages/swagger/package.json +57 -44
- package/packages/swagger/src/index.d.ts +126 -126
- package/packages/swagger/src/index.js +12 -12
- package/packages/swagger/src/setup.js +100 -100
- package/template/js/.env.example +16 -15
- package/template/js/README.md +982 -978
- package/template/js/basePackage.json +26 -26
- package/template/js/src/app.js +81 -81
- package/template/js/src/config/constants.js +20 -20
- package/template/js/src/config/env.js +26 -26
- package/template/js/src/config/swagger.config.js +15 -15
- package/template/js/src/lib/swagger/SWAGGER_GUIDE.md +3 -3
- package/template/js/src/middlewares/errorHandler.js +180 -180
- package/template/js/src/middlewares/requestLogger.js +33 -33
- package/template/js/src/middlewares/validateRequest.js +42 -42
- package/template/js/src/modules/auth/auth.constants.js +3 -3
- package/template/js/src/modules/auth/auth.controller.js +29 -29
- package/template/js/src/modules/auth/auth.middlewares.js +19 -19
- package/template/js/src/modules/auth/auth.routes.js +131 -131
- package/template/js/src/modules/auth/auth.schemas.js +60 -60
- package/template/js/src/modules/auth/auth.service.js +67 -67
- package/template/js/src/modules/auth/package.json +6 -6
- package/template/js/src/modules/health/controller.js +151 -151
- package/template/js/src/modules/swagger/package.json +5 -5
- package/template/js/src/repositories/user.repo.js +19 -19
- package/template/js/src/routes/index.js +25 -25
- package/template/js/src/routes/protected.js +57 -57
- package/template/js/src/server.js +38 -38
- package/template/js/src/utils/AppError.js +182 -182
- package/template/js/src/utils/logger.js +73 -73
- package/template/js/src/utils/response.js +51 -51
- package/template/ts/.env.example +16 -15
- package/template/ts/README.md +982 -978
- package/template/ts/basePackage.json +36 -36
- package/template/ts/build.js +46 -46
- package/template/ts/src/app.ts +71 -71
- package/template/ts/src/config/constants.ts +27 -27
- package/template/ts/src/config/env.ts +40 -40
- package/template/ts/src/config/swagger.config.ts +30 -30
- package/template/ts/src/lib/swagger/SWAGGER_GUIDE.md +2 -2
- package/template/ts/src/middlewares/errorHandler.ts +201 -201
- package/template/ts/src/middlewares/requestLogger.ts +38 -38
- package/template/ts/src/middlewares/validateRequest.ts +46 -46
- package/template/ts/src/modules/auth/auth.constants.ts +6 -6
- package/template/ts/src/modules/auth/auth.controller.ts +32 -32
- package/template/ts/src/modules/auth/auth.middlewares.ts +46 -46
- package/template/ts/src/modules/auth/auth.routes.ts +52 -52
- package/template/ts/src/modules/auth/auth.schemas.ts +73 -73
- package/template/ts/src/modules/auth/auth.service.ts +106 -106
- package/template/ts/src/modules/auth/package.json +10 -10
- package/template/ts/src/modules/health/controller.ts +80 -80
- package/template/ts/src/modules/swagger/package.json +5 -5
- package/template/ts/src/repositories/user.repo.ts +33 -33
- package/template/ts/src/routes/index.ts +24 -24
- package/template/ts/src/routes/protected.ts +46 -46
- package/template/ts/src/server.ts +41 -41
- package/template/ts/src/types/express.d.ts +9 -9
- package/template/ts/src/utils/AppError.ts +220 -220
- package/template/ts/src/utils/logger.ts +55 -55
- package/template/ts/src/utils/response.ts +100 -100
- package/template/ts/tsconfig.json +26 -26
- package/packages/swagger/package-lock.json +0 -1715
- package/tmpclaude-1049-cwd +0 -1
- package/tmpclaude-3e37-cwd +0 -1
- package/tmpclaude-4d73-cwd +0 -1
- package/tmpclaude-8a8e-cwd +0 -1
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "charcole",
|
|
3
|
-
"version": "2.2.
|
|
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.2",
|
|
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
|
+
}
|
package/template/js/src/app.js
CHANGED
|
@@ -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.
|
|
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.1",
|
|
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.
|
|
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.1",
|
|
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
|
+
};
|
|
@@ -18,8 +18,8 @@ import { createItemSchema } from "../modules/health/controller.ts";
|
|
|
18
18
|
|
|
19
19
|
const swaggerConfig = {
|
|
20
20
|
title: "My API",
|
|
21
|
-
version: "1.0.
|
|
22
|
-
// Auto-register schemas - they'll be
|
|
21
|
+
version: "1.0.1",
|
|
22
|
+
// Auto-register schemas - they'll be converted to OpenAPI automatically!
|
|
23
23
|
schemas: {
|
|
24
24
|
registerSchema,
|
|
25
25
|
loginSchema,
|
|
@@ -472,7 +472,7 @@ const app = express();
|
|
|
472
472
|
|
|
473
473
|
setupSwagger(app, {
|
|
474
474
|
title: "My API",
|
|
475
|
-
version: "1.0.
|
|
475
|
+
version: "1.0.1",
|
|
476
476
|
schemas: {
|
|
477
477
|
mySchema, // Your Zod schemas
|
|
478
478
|
},
|