nodejs-structure-cli 1.0.1 → 1.0.3
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/bin/index.js +5 -5
- package/lib/generator.js +1 -3
- package/package.json +1 -1
- package/templates/clean-architecture/js/src/domain/models/User.js.ejs +1 -1
- package/templates/clean-architecture/js/src/errors/ApiError.js +1 -1
- package/templates/clean-architecture/js/src/errors/BadRequestError.js +4 -4
- package/templates/clean-architecture/js/src/errors/NotFoundError.js +4 -4
- package/templates/clean-architecture/js/src/index.js.ejs +6 -8
- package/templates/clean-architecture/js/src/infrastructure/config/env.js.ejs +5 -6
- package/templates/clean-architecture/js/src/infrastructure/log/logger.js +3 -3
- package/templates/clean-architecture/js/src/infrastructure/repositories/UserRepository.js.ejs +2 -2
- package/templates/clean-architecture/js/src/infrastructure/webserver/middleware/errorMiddleware.js +4 -4
- package/templates/clean-architecture/js/src/infrastructure/webserver/server.js.ejs +28 -21
- package/templates/clean-architecture/js/src/infrastructure/webserver/swagger.js.ejs +7 -3
- package/templates/clean-architecture/js/src/interfaces/controllers/userController.js.ejs +12 -12
- package/templates/clean-architecture/js/src/interfaces/controllers/userController.spec.js.ejs +13 -15
- package/templates/clean-architecture/js/src/interfaces/graphql/context.js.ejs +2 -2
- package/templates/clean-architecture/js/src/interfaces/graphql/index.js.ejs +4 -4
- package/templates/clean-architecture/js/src/interfaces/graphql/resolvers/index.js.ejs +3 -3
- package/templates/clean-architecture/js/src/interfaces/graphql/resolvers/user.resolvers.js.ejs +2 -2
- package/templates/clean-architecture/js/src/interfaces/graphql/typeDefs/index.js.ejs +3 -3
- package/templates/clean-architecture/js/src/interfaces/graphql/typeDefs/user.types.js.ejs +1 -3
- package/templates/clean-architecture/js/src/interfaces/routes/api.js.ejs +6 -6
- package/templates/clean-architecture/js/src/usecases/CreateUser.js.ejs +2 -2
- package/templates/clean-architecture/js/src/usecases/DeleteUser.js +1 -1
- package/templates/clean-architecture/js/src/usecases/GetAllUsers.js +1 -1
- package/templates/clean-architecture/js/src/usecases/GetAllUsers.spec.js.ejs +5 -5
- package/templates/clean-architecture/js/src/usecases/UpdateUser.js.ejs +1 -1
- package/templates/clean-architecture/js/src/utils/errorMessages.js +1 -1
- package/templates/clean-architecture/js/src/utils/httpCodes.js +1 -1
- package/templates/common/SECURITY.md +18 -0
- package/templates/common/caching/clean/js/CreateUser.js.ejs +5 -5
- package/templates/common/caching/clean/js/DeleteUser.js.ejs +4 -4
- package/templates/common/caching/clean/js/GetAllUsers.js.ejs +4 -4
- package/templates/common/caching/clean/js/UpdateUser.js.ejs +4 -4
- package/templates/common/caching/js/memoryCache.js.ejs +3 -3
- package/templates/common/caching/js/redisClient.js.ejs +6 -4
- package/templates/common/database/js/database.js.ejs +5 -3
- package/templates/common/database/js/models/User.js.ejs +4 -4
- package/templates/common/database/js/mongoose.js.ejs +6 -4
- package/templates/common/ecosystem.config.js.ejs +1 -1
- package/templates/common/health/js/healthRoute.js.ejs +11 -8
- package/templates/common/health/js/healthRoute.spec.js.ejs +10 -9
- package/templates/common/jest.config.js.ejs +1 -1
- package/templates/common/jest.e2e.config.js.ejs +4 -3
- package/templates/common/kafka/js/config/kafka.js +3 -3
- package/templates/common/kafka/js/messaging/baseConsumer.js.ejs +2 -2
- package/templates/common/kafka/js/messaging/userEventSchema.js.ejs +3 -3
- package/templates/common/kafka/js/messaging/welcomeEmailConsumer.js.ejs +6 -6
- package/templates/common/kafka/js/services/kafkaService.js.ejs +5 -7
- package/templates/common/kafka/js/utils/kafkaEvents.js.ejs +1 -3
- package/templates/common/migrate-mongo-config.js.ejs +2 -2
- package/templates/common/migrations/init.js.ejs +18 -20
- package/templates/common/package.json.ejs +1 -0
- package/templates/common/scripts/run-e2e.js.ejs +6 -3
- package/templates/common/shutdown/js/gracefulShutdown.js.ejs +23 -14
- package/templates/common/src/config/auth.js.ejs +1 -1
- package/templates/common/src/controllers/authController.js.ejs +2 -2
- package/templates/common/src/dummy.ts +3 -0
- package/templates/common/src/middleware/auth.js.ejs +1 -1
- package/templates/common/src/middleware/upload.js.ejs +1 -1
- package/templates/common/src/routes/authRoutes.js.ejs +1 -1
- package/templates/common/src/tests/e2e/e2e.users.test.js.ejs +1 -1
- package/templates/common/src/utils/errorMiddleware.spec.js.ejs +5 -6
- package/templates/common/tsconfig.json +2 -1
- package/templates/mvc/js/src/config/env.js.ejs +5 -4
- package/templates/mvc/js/src/config/swagger.js.ejs +7 -3
- package/templates/mvc/js/src/controllers/userController.js.ejs +17 -21
- package/templates/mvc/js/src/controllers/userController.spec.js.ejs +12 -12
- package/templates/mvc/js/src/errors/ApiError.js +1 -1
- package/templates/mvc/js/src/errors/BadRequestError.js +4 -4
- package/templates/mvc/js/src/errors/BadRequestError.spec.js.ejs +4 -4
- package/templates/mvc/js/src/errors/NotFoundError.js +4 -4
- package/templates/mvc/js/src/errors/NotFoundError.spec.js.ejs +4 -4
- package/templates/mvc/js/src/graphql/context.js.ejs +1 -1
- package/templates/mvc/js/src/graphql/index.js.ejs +4 -4
- package/templates/mvc/js/src/graphql/resolvers/index.js.ejs +3 -3
- package/templates/mvc/js/src/graphql/resolvers/user.resolvers.js.ejs +2 -2
- package/templates/mvc/js/src/graphql/typeDefs/index.js.ejs +3 -3
- package/templates/mvc/js/src/graphql/typeDefs/user.types.js.ejs +2 -2
- package/templates/mvc/js/src/index.js.ejs +26 -25
- package/templates/mvc/js/src/routes/api.js.ejs +7 -6
- package/templates/mvc/js/src/routes/api.spec.js.ejs +4 -4
- package/templates/mvc/js/src/utils/errorMessages.js +1 -1
- package/templates/mvc/js/src/utils/errorMiddleware.js +4 -4
- package/templates/mvc/js/src/utils/httpCodes.js +1 -1
- package/templates/mvc/js/src/utils/logger.js +3 -3
package/bin/index.js
CHANGED
|
@@ -42,13 +42,13 @@ program
|
|
|
42
42
|
"-c, --communication <communication>",
|
|
43
43
|
"Communication (REST APIs, GraphQL, Kafka)",
|
|
44
44
|
)
|
|
45
|
-
.option(
|
|
46
|
-
"--ci-provider <provider>",
|
|
47
|
-
"CI/CD Provider (None, GitHub Actions, Jenkins, GitLab CI)",
|
|
48
|
-
)
|
|
45
|
+
.option("--ci-provider <provider>", "CI/CD Provider (None, GitHub Actions, Jenkins, GitLab CI)")
|
|
49
46
|
.option("--include-security", "Include Enterprise Security Hardening")
|
|
50
47
|
.option("--no-include-security", "Exclude Enterprise Security Hardening")
|
|
51
|
-
.option("--caching <type>", "Caching Layer (None/Redis)")
|
|
48
|
+
.option("--caching <type>", "Caching Layer (None/Redis/Memory Cache)")
|
|
49
|
+
.option("--auth <type>", "Authentication (None, Better-Auth, JWT, OAuth)")
|
|
50
|
+
.option("--google-login <type>", "Google Login (None, Google Login)")
|
|
51
|
+
.option("--include-multer <choice>", "Add image upload capability (No/Yes)")
|
|
52
52
|
.action(async (options) => {
|
|
53
53
|
// Fix for Commander camelCase conversion
|
|
54
54
|
if (options.ciProvider) {
|
package/lib/generator.js
CHANGED
|
@@ -11,6 +11,7 @@ const __filename = fileURLToPath(import.meta.url);
|
|
|
11
11
|
const __dirname = path.dirname(__filename);
|
|
12
12
|
|
|
13
13
|
export const generateProject = async (config) => {
|
|
14
|
+
console.log('ENTERING generateProject');
|
|
14
15
|
// 0. Normalize configuration with defaults
|
|
15
16
|
config = {
|
|
16
17
|
viewEngine: 'None',
|
|
@@ -66,9 +67,6 @@ export const generateProject = async (config) => {
|
|
|
66
67
|
await renderDockerfile(templatesDir, targetDir, config);
|
|
67
68
|
|
|
68
69
|
// 10. Database Setup (Migrations, Config, Models)
|
|
69
|
-
// Note: logic for detailed view copying is also handled nicely if we ensure setupDatabase checks correctly,
|
|
70
|
-
// or we can move strict view logic to setupViews.
|
|
71
|
-
// In strict refactor, database-setup handles the content that was in the DB block.
|
|
72
70
|
await setupDatabase(templatesDir, targetDir, config);
|
|
73
71
|
|
|
74
72
|
// 10a. Caching Setup
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { ApiError } from './ApiError.js';
|
|
2
|
+
import HTTP_STATUS from '../utils/httpCodes.js';
|
|
3
|
+
import ERROR_MESSAGES from '../utils/errorMessages.js';
|
|
4
4
|
|
|
5
5
|
class BadRequestError extends ApiError {
|
|
6
6
|
constructor(message = ERROR_MESSAGES.BAD_REQUEST) {
|
|
@@ -8,4 +8,4 @@ class BadRequestError extends ApiError {
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
export { BadRequestError };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { ApiError } from './ApiError.js';
|
|
2
|
+
import HTTP_STATUS from '../utils/httpCodes.js';
|
|
3
|
+
import ERROR_MESSAGES from '../utils/errorMessages.js';
|
|
4
4
|
|
|
5
5
|
class NotFoundError extends ApiError {
|
|
6
6
|
constructor(message = ERROR_MESSAGES.RESOURCE_NOT_FOUND) {
|
|
@@ -8,4 +8,4 @@ class NotFoundError extends ApiError {
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
export { NotFoundError };
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import startServer from './infrastructure/webserver/server.js';
|
|
2
|
+
import logger from './infrastructure/log/logger.js';
|
|
3
3
|
<% if (communication === 'Kafka') { -%>
|
|
4
|
-
|
|
4
|
+
import { connectKafka } from './infrastructure/messaging/kafkaClient.js';
|
|
5
5
|
<% } -%>
|
|
6
6
|
<%_ if (database !== 'None') { -%>
|
|
7
7
|
// Database Sync
|
|
8
|
-
<%_ if (database !== 'None') { -%>
|
|
9
8
|
<%_ if (database === 'MongoDB') { -%>
|
|
10
|
-
|
|
9
|
+
import connectDB from './infrastructure/database/database.js';
|
|
11
10
|
<%_ } else { -%>
|
|
12
|
-
|
|
13
|
-
<%_ } -%>
|
|
11
|
+
import sequelize from './infrastructure/database/database.js';
|
|
14
12
|
<%_ } -%>
|
|
15
13
|
|
|
16
14
|
const syncDatabase = async () => {
|
|
@@ -24,7 +22,7 @@ const syncDatabase = async () => {
|
|
|
24
22
|
<%_ } -%>
|
|
25
23
|
logger.info('Database synced');
|
|
26
24
|
// Start the web server after DB sync
|
|
27
|
-
startServer();
|
|
25
|
+
await startServer();
|
|
28
26
|
<%_ if (communication === 'Kafka') { -%>
|
|
29
27
|
// Connect Kafka
|
|
30
28
|
connectKafka().then(async () => {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import logger from '../log/logger.js';
|
|
3
|
+
import dotenv from 'dotenv';
|
|
3
4
|
|
|
4
5
|
if (process.env.NODE_ENV !== 'production') {
|
|
5
|
-
|
|
6
|
+
dotenv.config();
|
|
6
7
|
}
|
|
7
8
|
|
|
8
9
|
const envSchema = z.object({
|
|
@@ -42,6 +43,4 @@ if (!_env.success) {
|
|
|
42
43
|
process.exit(1);
|
|
43
44
|
}
|
|
44
45
|
|
|
45
|
-
const env = _env.data;
|
|
46
|
-
|
|
47
|
-
module.exports = { env };
|
|
46
|
+
export const env = _env.data;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import winston from 'winston';
|
|
2
|
+
import 'winston-daily-rotate-file';
|
|
3
3
|
|
|
4
4
|
const logger = winston.createLogger({
|
|
5
5
|
level: 'info',
|
|
@@ -33,4 +33,4 @@ logger.add(new winston.transports.Console({
|
|
|
33
33
|
: winston.format.json(),
|
|
34
34
|
}));
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
export default logger;
|
package/templates/clean-architecture/js/src/infrastructure/repositories/UserRepository.js.ejs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import UserModel from '../database/models/User.js';
|
|
2
2
|
|
|
3
3
|
class UserRepository {
|
|
4
4
|
async save(user) {
|
|
@@ -85,4 +85,4 @@ class UserRepository {
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
|
|
88
|
+
export default UserRepository;
|
package/templates/clean-architecture/js/src/infrastructure/webserver/middleware/errorMiddleware.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import logger from '../../log/logger.js';
|
|
2
|
+
import { ApiError } from '../../../errors/ApiError.js';
|
|
3
|
+
import HTTP_STATUS from '../../../utils/httpCodes.js';
|
|
4
4
|
|
|
5
5
|
// eslint-disable-next-line no-unused-vars
|
|
6
6
|
const errorMiddleware = (err, req, res, next) => {
|
|
@@ -26,5 +26,5 @@ const errorMiddleware = (err, req, res, next) => {
|
|
|
26
26
|
});
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
export { errorMiddleware };
|
|
30
30
|
|
|
@@ -1,26 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import cors from 'cors';
|
|
3
|
+
import logger from '../log/logger.js';
|
|
4
|
+
import morgan from 'morgan';
|
|
5
|
+
import { errorMiddleware } from './middleware/errorMiddleware.js';
|
|
6
|
+
import healthRoutes from '../../interfaces/routes/healthRoute.js';
|
|
7
|
+
import setupGracefulShutdown from '../../utils/gracefulShutdown.js';
|
|
8
8
|
<%_ if (communication === 'REST APIs' || communication === 'Kafka') { -%>
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
import apiRoutes from '../../interfaces/routes/api.js';
|
|
10
|
+
import swaggerUi from 'swagger-ui-express';
|
|
11
|
+
import swaggerSpecs from './swagger.js';
|
|
12
12
|
<%_ } -%>
|
|
13
13
|
<%_ if (communication === 'GraphQL') { -%>
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
import { ApolloServer } from '@apollo/server';
|
|
15
|
+
import { expressMiddleware } from '@as-integrations/express4';
|
|
16
|
+
import { ApolloServerPluginLandingPageLocalDefault } from '@apollo/server/plugin/landingPage/default';
|
|
17
|
+
import { unwrapResolverError } from '@apollo/server/errors';
|
|
18
|
+
import { ApiError } from '../../errors/ApiError.js';
|
|
19
|
+
import { typeDefs, resolvers } from '../../interfaces/graphql/index.js';
|
|
20
|
+
import { gqlContext } from '../../interfaces/graphql/context.js';
|
|
21
|
+
<%_ } -%>
|
|
22
|
+
<%_ if (includeMulter) { -%>
|
|
23
|
+
import path from 'path';
|
|
24
|
+
import { fileURLToPath } from 'url';
|
|
25
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
26
|
+
const __dirname = path.dirname(__filename);
|
|
27
|
+
<%_ } -%>
|
|
28
|
+
<%_ if (communication === 'Kafka') { -%>
|
|
29
|
+
import { connectKafka } from '../../infrastructure/messaging/kafkaClient.js';
|
|
21
30
|
<%_ } -%>
|
|
22
31
|
|
|
23
|
-
|
|
32
|
+
import { env } from '../config/env.js';
|
|
24
33
|
|
|
25
34
|
const startServer = async () => {
|
|
26
35
|
// Determine port using the validated env
|
|
@@ -30,7 +39,6 @@ const startServer = async () => {
|
|
|
30
39
|
app.use(cors());
|
|
31
40
|
app.use(express.json());
|
|
32
41
|
<% if (includeMulter) { %>
|
|
33
|
-
const path = require('path');
|
|
34
42
|
app.use('/uploads', express.static(path.join(__dirname, '../../../../uploads')));
|
|
35
43
|
<% } %>
|
|
36
44
|
app.use(morgan('combined', { stream: { write: message => logger.info(message.trim()) } }));
|
|
@@ -76,7 +84,6 @@ const startServer = async () => {
|
|
|
76
84
|
const server = app.listen(port, () => {
|
|
77
85
|
logger.info(`Server running on port ${port}`);
|
|
78
86
|
<%_ if (communication === 'Kafka') { -%>
|
|
79
|
-
const { connectKafka } = require('../../infrastructure/messaging/kafkaClient');
|
|
80
87
|
connectKafka()
|
|
81
88
|
.then(async () => {
|
|
82
89
|
logger.info('Kafka connected');
|
|
@@ -90,4 +97,4 @@ const startServer = async () => {
|
|
|
90
97
|
setupGracefulShutdown(server);
|
|
91
98
|
};
|
|
92
99
|
|
|
93
|
-
|
|
100
|
+
export default startServer;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import YAML from 'yamljs';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
|
|
5
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = path.dirname(__filename);
|
|
3
7
|
|
|
4
8
|
const swaggerDocument = YAML.load(path.join(__dirname, 'swagger.yml'));
|
|
5
9
|
|
|
6
|
-
|
|
10
|
+
export default swaggerDocument;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import CreateUser from '../../usecases/CreateUser.js';
|
|
2
|
+
import GetAllUsers from '../../usecases/GetAllUsers.js';
|
|
3
|
+
import UpdateUser from '../../usecases/UpdateUser.js';
|
|
4
|
+
import DeleteUser from '../../usecases/DeleteUser.js';
|
|
5
|
+
import UserRepository from '../../infrastructure/repositories/UserRepository.js';
|
|
6
|
+
import ERROR_MESSAGES from '../../utils/errorMessages.js';
|
|
7
7
|
<% if (communication !== 'GraphQL') { -%>
|
|
8
|
-
|
|
8
|
+
import HTTP_STATUS from '../../utils/httpCodes.js';
|
|
9
9
|
<% } -%>
|
|
10
|
-
|
|
10
|
+
import logger from '../../infrastructure/log/logger.js';
|
|
11
11
|
<%_ if (communication === 'Kafka') { -%>
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
import { sendMessage } from '../../infrastructure/messaging/kafkaClient.js';
|
|
13
|
+
import { KAFKA_ACTIONS } from '../../utils/kafkaEvents.js';
|
|
14
14
|
<%_ } -%>
|
|
15
15
|
<%_ if (auth && auth !== 'None') { _%>
|
|
16
|
-
|
|
16
|
+
import bcrypt from 'bcryptjs';
|
|
17
17
|
<%_ } _%>
|
|
18
18
|
|
|
19
19
|
class UserController {
|
|
@@ -187,4 +187,4 @@ class UserController {
|
|
|
187
187
|
<% } -%>
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
-
|
|
190
|
+
export default UserController;
|
package/templates/clean-architecture/js/src/interfaces/controllers/userController.spec.js.ejs
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
jest.mock('@/usecases/CreateUser');
|
|
9
|
-
jest.mock('@/usecases/GetAllUsers');
|
|
10
|
-
jest.mock('@/usecases/UpdateUser');
|
|
11
|
-
jest.mock('@/usecases/DeleteUser');
|
|
1
|
+
import UserController from '@/interfaces/controllers/userController.js';
|
|
2
|
+
import ERROR_MESSAGES from '@/utils/errorMessages.js';
|
|
3
|
+
import CreateUser from '@/usecases/CreateUser.js';
|
|
4
|
+
import GetAllUsers from '@/usecases/GetAllUsers.js';
|
|
5
|
+
import UpdateUser from '@/usecases/UpdateUser.js';
|
|
6
|
+
import DeleteUser from '@/usecases/DeleteUser.js';
|
|
7
|
+
|
|
8
|
+
jest.mock('@/usecases/CreateUser.js');
|
|
9
|
+
jest.mock('@/usecases/GetAllUsers.js');
|
|
10
|
+
jest.mock('@/usecases/UpdateUser.js');
|
|
11
|
+
jest.mock('@/usecases/DeleteUser.js');
|
|
12
12
|
<%_ if (communication === 'Kafka') { -%>
|
|
13
|
-
|
|
13
|
+
import { sendMessage } from '@/infrastructure/messaging/kafkaClient.js';
|
|
14
|
+
jest.mock('@/infrastructure/messaging/kafkaClient.js', () => ({
|
|
14
15
|
sendMessage: jest.fn().mockResolvedValue(undefined)
|
|
15
16
|
}));
|
|
16
17
|
<%_ } -%>
|
|
@@ -98,7 +99,6 @@ describe('UserController (Clean Architecture)', () => {
|
|
|
98
99
|
<%_ } else { -%>
|
|
99
100
|
await userController.createUser(mockRequest, mockResponse, mockNext);
|
|
100
101
|
<%_ if (communication === 'Kafka') { -%>
|
|
101
|
-
const { sendMessage } = require('@/infrastructure/messaging/kafkaClient');
|
|
102
102
|
expect(sendMessage).toHaveBeenCalled();
|
|
103
103
|
<%_ } -%>
|
|
104
104
|
expect(mockResponse.status).toHaveBeenCalledWith(201);
|
|
@@ -132,7 +132,6 @@ describe('UserController (Clean Architecture)', () => {
|
|
|
132
132
|
expect(mockResponse.json).toHaveBeenCalled();
|
|
133
133
|
<%_ } -%>
|
|
134
134
|
<%_ if (communication === 'Kafka') { -%>
|
|
135
|
-
const { sendMessage } = require('@/infrastructure/messaging/kafkaClient');
|
|
136
135
|
expect(sendMessage).toHaveBeenCalled();
|
|
137
136
|
<%_ } -%>
|
|
138
137
|
expect(mockUpdateUserUseCase.execute).toHaveBeenCalledWith(id, payload);
|
|
@@ -169,7 +168,6 @@ describe('UserController (Clean Architecture)', () => {
|
|
|
169
168
|
expect(mockResponse.status).toHaveBeenCalledWith(200);
|
|
170
169
|
<%_ } -%>
|
|
171
170
|
<%_ if (communication === 'Kafka') { -%>
|
|
172
|
-
const { sendMessage } = require('@/infrastructure/messaging/kafkaClient');
|
|
173
171
|
expect(sendMessage).toHaveBeenCalled();
|
|
174
172
|
<%_ } -%>
|
|
175
173
|
expect(mockDeleteUserUseCase.execute).toHaveBeenCalledWith(id);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import UserRepository from '../../infrastructure/repositories/UserRepository.js';
|
|
2
2
|
|
|
3
3
|
const gqlContext = async ({ req }) => {
|
|
4
4
|
const token = req.headers.authorization || '';
|
|
@@ -10,4 +10,4 @@ const gqlContext = async ({ req }) => {
|
|
|
10
10
|
};
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
export { gqlContext };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { typeDefs } from './typeDefs/index.js';
|
|
2
|
+
import { resolvers } from './resolvers/index.js';
|
|
3
|
+
import { gqlContext } from './context.js';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
export { typeDefs, resolvers, gqlContext };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { mergeResolvers } from '@graphql-tools/merge';
|
|
2
|
+
import { userResolvers } from './user.resolvers.js';
|
|
3
3
|
|
|
4
4
|
const resolvers = mergeResolvers([userResolvers]);
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
export { resolvers };
|
package/templates/clean-architecture/js/src/interfaces/graphql/resolvers/user.resolvers.js.ejs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import UserController from '../../controllers/userController.js';
|
|
2
2
|
|
|
3
3
|
const userController = new UserController();
|
|
4
4
|
|
|
@@ -24,4 +24,4 @@ const userResolvers = {
|
|
|
24
24
|
}<%_ } %>
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
export { userResolvers };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { mergeTypeDefs } from '@graphql-tools/merge';
|
|
2
|
+
import { userTypes } from './user.types.js';
|
|
3
3
|
|
|
4
4
|
const typeDefs = mergeTypeDefs([userTypes]);
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
export { typeDefs };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import express from 'express';
|
|
2
2
|
const router = express.Router();
|
|
3
|
-
|
|
4
|
-
<% if (auth && auth !== 'None') { %>
|
|
5
|
-
<% if (includeMulter) { %>
|
|
6
|
-
<% if (auth && auth !== 'None') { %>
|
|
3
|
+
import UserController from '../controllers/userController.js';
|
|
4
|
+
<% if (auth && auth !== 'None') { %>import { authMiddleware } from '../middleware/auth.js';<% } %>
|
|
5
|
+
<% if (includeMulter) { %>import { upload } from '../middleware/upload.js';<% } %>
|
|
6
|
+
<% if (auth && auth !== 'None') { %>import authRoutes from './authRoutes.js';<% } %>
|
|
7
7
|
|
|
8
8
|
const userController = new UserController();
|
|
9
9
|
|
|
@@ -14,4 +14,4 @@ router.post('/users', <% if (auth && auth !== 'None') { %>authMiddleware, <% } %
|
|
|
14
14
|
router.patch('/users/:id', <% if (auth && auth !== 'None') { %>authMiddleware, <% } %><% if (includeMulter) { %>upload.single('image'), <% } %>(req, res, next) => userController.updateUser(req, res, next));
|
|
15
15
|
router.delete('/users/:id', <% if (auth && auth !== 'None') { %>authMiddleware, <% } %>(req, res, next) => userController.deleteUser(req, res, next));
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
export default router;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import User from '../domain/models/User.js';
|
|
2
2
|
|
|
3
3
|
class CreateUser {
|
|
4
4
|
constructor(userRepository) {
|
|
@@ -11,4 +11,4 @@ class CreateUser {
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
export default CreateUser;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import GetAllUsers from '@/usecases/GetAllUsers.js';
|
|
2
|
+
import UserRepository from '@/infrastructure/repositories/UserRepository.js';
|
|
3
3
|
<%_ if (caching !== 'None') { -%>
|
|
4
|
-
|
|
4
|
+
import cacheService from '<% if (caching === "Redis") { %>@/infrastructure/caching/redisClient.js<% } else { %>@/infrastructure/caching/memoryCache.js<% } %>';
|
|
5
5
|
<%_ } -%>
|
|
6
6
|
|
|
7
|
-
jest.mock('@/infrastructure/repositories/UserRepository');
|
|
7
|
+
jest.mock('@/infrastructure/repositories/UserRepository.js');
|
|
8
8
|
<%_ if (caching !== 'None') { -%>
|
|
9
|
-
jest.mock('<% if (caching === "Redis") { %>@/infrastructure/caching/redisClient<% } else { %>@/infrastructure/caching/memoryCache<% } %>', () => ({
|
|
9
|
+
jest.mock('<% if (caching === "Redis") { %>@/infrastructure/caching/redisClient.js<% } else { %>@/infrastructure/caching/memoryCache.js<% } %>', () => ({
|
|
10
10
|
get: jest.fn(),
|
|
11
11
|
set: jest.fn(),
|
|
12
12
|
del: jest.fn()
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Supported Versions
|
|
4
|
+
|
|
5
|
+
The following versions of this project are currently being supported with security updates:
|
|
6
|
+
|
|
7
|
+
| Version | Supported |
|
|
8
|
+
| ------- | ------------------ |
|
|
9
|
+
| 1.0.x | :white_check_mark: |
|
|
10
|
+
| < 1.0 | :x: |
|
|
11
|
+
|
|
12
|
+
## Reporting a Vulnerability
|
|
13
|
+
|
|
14
|
+
We take the security of this project seriously. If you believe you have found a security vulnerability, please report it to us responsibly.
|
|
15
|
+
|
|
16
|
+
**Please do not report security vulnerabilities via public GitHub issues.**
|
|
17
|
+
|
|
18
|
+
Instead, please send an email to security@example.com with a description of the issue. We will acknowledge your report within 48 hours and provide a timeline for a fix if applicable.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import User from '../domain/models/User.js';
|
|
2
2
|
<%_ if (caching === 'Redis') { -%>
|
|
3
|
-
|
|
3
|
+
import cacheService from '../infrastructure/caching/redisClient.js';
|
|
4
4
|
<%_ } else if (caching === 'Memory Cache') { -%>
|
|
5
|
-
|
|
5
|
+
import cacheService from '../infrastructure/caching/memoryCache.js';
|
|
6
6
|
<%_ } -%>
|
|
7
|
-
|
|
7
|
+
import logger from '../infrastructure/log/logger.js';
|
|
8
8
|
|
|
9
9
|
class CreateUser {
|
|
10
10
|
constructor(userRepository) {
|
|
@@ -26,4 +26,4 @@ class CreateUser {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
export default CreateUser;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
<%_ if (caching === 'Redis') { -%>
|
|
2
|
-
|
|
2
|
+
import cacheService from '../infrastructure/caching/redisClient.js';
|
|
3
3
|
<%_ } else if (caching === 'Memory Cache') { -%>
|
|
4
|
-
|
|
4
|
+
import cacheService from '../infrastructure/caching/memoryCache.js';
|
|
5
5
|
<%_ } -%>
|
|
6
|
-
|
|
6
|
+
import logger from '../infrastructure/log/logger.js';
|
|
7
7
|
|
|
8
8
|
class DeleteUser {
|
|
9
9
|
constructor(userRepository) {
|
|
@@ -24,4 +24,4 @@ class DeleteUser {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
export default DeleteUser;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
<%_ if (caching === 'Redis') { -%>
|
|
2
|
-
|
|
2
|
+
import cacheService from '../infrastructure/caching/redisClient.js';
|
|
3
3
|
<%_ } else if (caching === 'Memory Cache') { -%>
|
|
4
|
-
|
|
4
|
+
import cacheService from '../infrastructure/caching/memoryCache.js';
|
|
5
5
|
<%_ } -%>
|
|
6
|
-
|
|
6
|
+
import logger from '../infrastructure/log/logger.js';
|
|
7
7
|
|
|
8
8
|
class GetAllUsers {
|
|
9
9
|
constructor(userRepository) {
|
|
@@ -34,4 +34,4 @@ class GetAllUsers {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
export default GetAllUsers;
|