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.
- package/.github/workflows/release.yml +26 -26
- package/CHANGELOG.md +301 -211
- package/LICENSE +21 -21
- package/README.md +354 -213
- package/bin/index.js +444 -288
- package/bin/lib/pkgManager.js +49 -49
- package/bin/lib/templateHandler.js +33 -33
- package/create-charcole-2.1.0.tgz +0 -0
- package/package.json +42 -27
- package/packages/swagger/BACKWARD_COMPATIBILITY.md +145 -0
- package/packages/swagger/CHANGELOG.md +404 -0
- package/packages/swagger/README.md +578 -0
- package/packages/swagger/charcole-swagger-1.0.0.tgz +0 -0
- package/packages/swagger/package-lock.json +1715 -0
- package/packages/swagger/package.json +57 -0
- package/packages/swagger/src/helpers.js +427 -0
- package/packages/swagger/src/index.d.ts +126 -0
- package/packages/swagger/src/index.js +12 -0
- package/packages/swagger/src/setup.js +100 -0
- package/template/js/.env.example +15 -15
- package/template/js/README.md +978 -855
- package/template/js/basePackage.json +26 -26
- package/template/js/src/app.js +81 -78
- 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 -0
- package/template/js/src/lib/swagger/SWAGGER_GUIDE.md +561 -0
- 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 -9
- 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 -50
- package/template/js/src/modules/swagger/charcole-swagger-1.0.0.tgz +0 -0
- package/template/js/src/modules/swagger/package.json +5 -0
- 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 -13
- 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 +15 -15
- package/template/ts/README.md +978 -855
- package/template/ts/basePackage.json +36 -36
- package/template/ts/build.js +46 -46
- package/template/ts/src/app.ts +71 -67
- 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 -0
- package/template/ts/src/lib/swagger/SWAGGER_GUIDE.md +561 -0
- 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 -9
- 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 -64
- package/template/ts/src/modules/swagger/charcole-swagger-1.0.0.tgz +0 -0
- package/template/ts/src/modules/swagger/package.json +5 -0
- 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 -13
- 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/plans/V2_1_PLAN.md +0 -20
|
Binary file
|
|
@@ -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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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.
|
|
3
|
-
import { env } from "./config/env.
|
|
4
|
-
import { logger } from "./utils/logger.
|
|
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
|
+
}
|