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
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
import { env } from "../config/env.js";
|
|
2
|
-
|
|
3
|
-
const COLORS = {
|
|
4
|
-
reset: "\x1b[0m",
|
|
5
|
-
red: "\x1b[31m",
|
|
6
|
-
yellow: "\x1b[33m",
|
|
7
|
-
green: "\x1b[32m",
|
|
8
|
-
blue: "\x1b[36m",
|
|
9
|
-
gray: "\x1b[90m",
|
|
10
|
-
magenta: "\x1b[35m",
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const LOG_LEVELS = {
|
|
14
|
-
debug: 0,
|
|
15
|
-
info: 1,
|
|
16
|
-
warn: 2,
|
|
17
|
-
error: 3,
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const getCurrentLogLevel = () => LOG_LEVELS[env.LOG_LEVEL] || LOG_LEVELS.info;
|
|
21
|
-
|
|
22
|
-
const formatLog = (level, message, data) => {
|
|
23
|
-
const timestamp = new Date().toISOString();
|
|
24
|
-
const dataStr = data ? ` ${JSON.stringify(data)}` : "";
|
|
25
|
-
return `[${timestamp}] ${level}:${dataStr ? " " + message + dataStr : " " + message}`;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const formatStack = (stack) => {
|
|
29
|
-
if (!stack) return "";
|
|
30
|
-
return `\n${stack}`;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export const logger = {
|
|
34
|
-
debug: (message, data) => {
|
|
35
|
-
if (getCurrentLogLevel() <= LOG_LEVELS.debug) {
|
|
36
|
-
console.log(
|
|
37
|
-
`${COLORS.gray}${formatLog("DEBUG", message, data)}${COLORS.reset}`,
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
info: (message, data) => {
|
|
43
|
-
if (getCurrentLogLevel() <= LOG_LEVELS.info) {
|
|
44
|
-
console.log(
|
|
45
|
-
`${COLORS.blue}${formatLog("INFO", message, data)}${COLORS.reset}`,
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
|
|
50
|
-
warn: (message, data) => {
|
|
51
|
-
if (getCurrentLogLevel() <= LOG_LEVELS.warn) {
|
|
52
|
-
console.warn(
|
|
53
|
-
`${COLORS.yellow}${formatLog("WARN", message, data)}${COLORS.reset}`,
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
|
|
58
|
-
error: (message, data, stack) => {
|
|
59
|
-
if (getCurrentLogLevel() <= LOG_LEVELS.error) {
|
|
60
|
-
const stackTrace = formatStack(stack);
|
|
61
|
-
console.error(
|
|
62
|
-
`${COLORS.red}${formatLog("ERROR", message, data)}${stackTrace}${COLORS.reset}`,
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
|
|
67
|
-
fatal: (message, data, stack) => {
|
|
68
|
-
const stackTrace = formatStack(stack);
|
|
69
|
-
console.error(
|
|
70
|
-
`${COLORS.red}${COLORS.magenta}${formatLog("FATAL", message, data)}${stackTrace}${COLORS.reset}`,
|
|
71
|
-
);
|
|
72
|
-
},
|
|
73
|
-
};
|
|
1
|
+
import { env } from "../config/env.js";
|
|
2
|
+
|
|
3
|
+
const COLORS = {
|
|
4
|
+
reset: "\x1b[0m",
|
|
5
|
+
red: "\x1b[31m",
|
|
6
|
+
yellow: "\x1b[33m",
|
|
7
|
+
green: "\x1b[32m",
|
|
8
|
+
blue: "\x1b[36m",
|
|
9
|
+
gray: "\x1b[90m",
|
|
10
|
+
magenta: "\x1b[35m",
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const LOG_LEVELS = {
|
|
14
|
+
debug: 0,
|
|
15
|
+
info: 1,
|
|
16
|
+
warn: 2,
|
|
17
|
+
error: 3,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const getCurrentLogLevel = () => LOG_LEVELS[env.LOG_LEVEL] || LOG_LEVELS.info;
|
|
21
|
+
|
|
22
|
+
const formatLog = (level, message, data) => {
|
|
23
|
+
const timestamp = new Date().toISOString();
|
|
24
|
+
const dataStr = data ? ` ${JSON.stringify(data)}` : "";
|
|
25
|
+
return `[${timestamp}] ${level}:${dataStr ? " " + message + dataStr : " " + message}`;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const formatStack = (stack) => {
|
|
29
|
+
if (!stack) return "";
|
|
30
|
+
return `\n${stack}`;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const logger = {
|
|
34
|
+
debug: (message, data) => {
|
|
35
|
+
if (getCurrentLogLevel() <= LOG_LEVELS.debug) {
|
|
36
|
+
console.log(
|
|
37
|
+
`${COLORS.gray}${formatLog("DEBUG", message, data)}${COLORS.reset}`,
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
info: (message, data) => {
|
|
43
|
+
if (getCurrentLogLevel() <= LOG_LEVELS.info) {
|
|
44
|
+
console.log(
|
|
45
|
+
`${COLORS.blue}${formatLog("INFO", message, data)}${COLORS.reset}`,
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
warn: (message, data) => {
|
|
51
|
+
if (getCurrentLogLevel() <= LOG_LEVELS.warn) {
|
|
52
|
+
console.warn(
|
|
53
|
+
`${COLORS.yellow}${formatLog("WARN", message, data)}${COLORS.reset}`,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
error: (message, data, stack) => {
|
|
59
|
+
if (getCurrentLogLevel() <= LOG_LEVELS.error) {
|
|
60
|
+
const stackTrace = formatStack(stack);
|
|
61
|
+
console.error(
|
|
62
|
+
`${COLORS.red}${formatLog("ERROR", message, data)}${stackTrace}${COLORS.reset}`,
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
fatal: (message, data, stack) => {
|
|
68
|
+
const stackTrace = formatStack(stack);
|
|
69
|
+
console.error(
|
|
70
|
+
`${COLORS.red}${COLORS.magenta}${formatLog("FATAL", message, data)}${stackTrace}${COLORS.reset}`,
|
|
71
|
+
);
|
|
72
|
+
},
|
|
73
|
+
};
|
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Send success response
|
|
3
|
-
*
|
|
4
|
-
* @param {Response} res - Express response object
|
|
5
|
-
* @param {*} data - Response data
|
|
6
|
-
* @param {number} statusCode - HTTP status code (default: 200)
|
|
7
|
-
* @param {string} message - Success message (default: 'Success')
|
|
8
|
-
*/
|
|
9
|
-
export const sendSuccess = (
|
|
10
|
-
res,
|
|
11
|
-
data,
|
|
12
|
-
statusCode = 200,
|
|
13
|
-
message = "Success",
|
|
14
|
-
) => {
|
|
15
|
-
return res.status(statusCode).json({
|
|
16
|
-
success: true,
|
|
17
|
-
message,
|
|
18
|
-
data,
|
|
19
|
-
timestamp: new Date().toISOString(),
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Send error response (DEPRECATED - use AppError instead)
|
|
25
|
-
* This is kept for backward compatibility
|
|
26
|
-
*/
|
|
27
|
-
export const sendError = (res, message, statusCode = 500, errors = null) => {
|
|
28
|
-
return res.status(statusCode).json({
|
|
29
|
-
success: false,
|
|
30
|
-
message,
|
|
31
|
-
...(errors && { errors }),
|
|
32
|
-
timestamp: new Date().toISOString(),
|
|
33
|
-
});
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Send validation error response (DEPRECATED - use ValidationError instead)
|
|
38
|
-
* This is kept for backward compatibility
|
|
39
|
-
*/
|
|
40
|
-
export const sendValidationError = (res, errors, statusCode = 422) => {
|
|
41
|
-
return res.status(statusCode).json({
|
|
42
|
-
success: false,
|
|
43
|
-
message: "Validation failed",
|
|
44
|
-
errors: errors.map((err) => ({
|
|
45
|
-
field: err.path.join("."),
|
|
46
|
-
message: err.message,
|
|
47
|
-
code: err.code,
|
|
48
|
-
})),
|
|
49
|
-
timestamp: new Date().toISOString(),
|
|
50
|
-
});
|
|
51
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* Send success response
|
|
3
|
+
*
|
|
4
|
+
* @param {Response} res - Express response object
|
|
5
|
+
* @param {*} data - Response data
|
|
6
|
+
* @param {number} statusCode - HTTP status code (default: 200)
|
|
7
|
+
* @param {string} message - Success message (default: 'Success')
|
|
8
|
+
*/
|
|
9
|
+
export const sendSuccess = (
|
|
10
|
+
res,
|
|
11
|
+
data,
|
|
12
|
+
statusCode = 200,
|
|
13
|
+
message = "Success",
|
|
14
|
+
) => {
|
|
15
|
+
return res.status(statusCode).json({
|
|
16
|
+
success: true,
|
|
17
|
+
message,
|
|
18
|
+
data,
|
|
19
|
+
timestamp: new Date().toISOString(),
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Send error response (DEPRECATED - use AppError instead)
|
|
25
|
+
* This is kept for backward compatibility
|
|
26
|
+
*/
|
|
27
|
+
export const sendError = (res, message, statusCode = 500, errors = null) => {
|
|
28
|
+
return res.status(statusCode).json({
|
|
29
|
+
success: false,
|
|
30
|
+
message,
|
|
31
|
+
...(errors && { errors }),
|
|
32
|
+
timestamp: new Date().toISOString(),
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Send validation error response (DEPRECATED - use ValidationError instead)
|
|
38
|
+
* This is kept for backward compatibility
|
|
39
|
+
*/
|
|
40
|
+
export const sendValidationError = (res, errors, statusCode = 422) => {
|
|
41
|
+
return res.status(statusCode).json({
|
|
42
|
+
success: false,
|
|
43
|
+
message: "Validation failed",
|
|
44
|
+
errors: errors.map((err) => ({
|
|
45
|
+
field: err.path.join("."),
|
|
46
|
+
message: err.message,
|
|
47
|
+
code: err.code,
|
|
48
|
+
})),
|
|
49
|
+
timestamp: new Date().toISOString(),
|
|
50
|
+
});
|
|
51
|
+
};
|
package/template/ts/.env.example
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
# Server Configuration
|
|
2
|
-
NODE_ENV=development
|
|
3
|
-
PORT=3000
|
|
4
|
-
|
|
5
|
-
# Logging
|
|
6
|
-
LOG_LEVEL=info
|
|
7
|
-
|
|
8
|
-
# CORS
|
|
9
|
-
CORS_ORIGIN=*
|
|
10
|
-
|
|
11
|
-
# Request
|
|
12
|
-
REQUEST_TIMEOUT=30000
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
# Authentication
|
|
1
|
+
# Server Configuration
|
|
2
|
+
NODE_ENV=development
|
|
3
|
+
PORT=3000
|
|
4
|
+
|
|
5
|
+
# Logging
|
|
6
|
+
LOG_LEVEL=info
|
|
7
|
+
|
|
8
|
+
# CORS
|
|
9
|
+
CORS_ORIGIN=*
|
|
10
|
+
|
|
11
|
+
# Request
|
|
12
|
+
REQUEST_TIMEOUT=30000
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# Authentication
|
|
16
16
|
JWT_SECRET=your-secret-key-here
|