express-genix 1.1.4 → 2.0.0
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/LICENSE +21 -0
- package/README.md +204 -259
- package/index.js +229 -113
- package/lib/cleanup.js +41 -129
- package/lib/features.js +239 -0
- package/lib/generator.js +286 -204
- package/lib/utils.js +43 -91
- package/package.json +81 -63
- package/templates/cicd/github-actions.yml.ejs +70 -0
- package/templates/config/database.mongo.js.ejs +29 -33
- package/templates/config/database.postgres.js.ejs +41 -40
- package/templates/config/database.prisma.js.ejs +26 -0
- package/templates/config/redis.js.ejs +28 -0
- package/templates/config/schema.prisma.ejs +20 -0
- package/templates/config/swagger.js.ejs +30 -0
- package/templates/config/websocket.js.ejs +62 -0
- package/templates/controllers/authController.js.ejs +152 -129
- package/templates/controllers/exampleController.js.ejs +92 -152
- package/templates/controllers/userController.js.ejs +52 -60
- package/templates/core/Dockerfile.ejs +41 -31
- package/templates/core/README.md.ejs +191 -179
- package/templates/core/app.js.ejs +114 -64
- package/templates/core/docker-compose.yml.ejs +59 -47
- package/templates/core/dockerignore.ejs +7 -0
- package/templates/core/env.ejs +25 -19
- package/templates/core/env.example.ejs +26 -0
- package/templates/core/eslintrc.json.ejs +50 -20
- package/templates/core/gitignore.ejs +51 -51
- package/templates/core/healthcheck.js.ejs +24 -24
- package/templates/core/jest.config.js.ejs +19 -22
- package/templates/core/package.json.ejs +70 -33
- package/templates/core/prettierrc.json.ejs +11 -11
- package/templates/core/server.js.ejs +64 -48
- package/templates/core/tsconfig.json.ejs +19 -0
- package/templates/middleware/auth.js.ejs +80 -66
- package/templates/middleware/cache.js.ejs +67 -0
- package/templates/middleware/errorHandler.js.ejs +50 -46
- package/templates/middleware/requestId.js.ejs +9 -0
- package/templates/middleware/validation.js.ejs +109 -47
- package/templates/migrations/create-users.js.ejs +50 -0
- package/templates/migrations/seed-users.js.ejs +34 -0
- package/templates/migrations/sequelizerc.ejs +8 -0
- package/templates/models/User.mongo.js.ejs +29 -29
- package/templates/models/User.postgres.js.ejs +40 -40
- package/templates/models/index.mongo.js.ejs +7 -7
- package/templates/models/index.postgres.js.ejs +11 -11
- package/templates/routes/authRoutes.js.ejs +222 -13
- package/templates/routes/exampleRoutes.js.ejs +100 -12
- package/templates/routes/index.js.ejs +34 -24
- package/templates/routes/userRoutes.js.ejs +78 -15
- package/templates/services/authService.js.ejs +111 -35
- package/templates/services/exampleService.js.ejs +112 -112
- package/templates/services/userService.mongodb.js.ejs +33 -33
- package/templates/services/userService.postgres.js.ejs +30 -30
- package/templates/services/userService.prisma.js.ejs +36 -0
- package/templates/tests/auth.test.js.ejs +83 -66
- package/templates/tests/example.test.js.ejs +109 -112
- package/templates/tests/setup.js.ejs +11 -11
- package/templates/tests/users.test.js.ejs +42 -42
- package/templates/utils/envValidator.js.ejs +23 -0
- package/templates/utils/errors.js.ejs +12 -12
- package/templates/utils/logger.js.ejs +37 -28
- package/templates/utils/response.js.ejs +28 -0
- package/templates/utils/validators.js.ejs +34 -34
- package/templates/config/swagger.json.ejs +0 -194
- package/templates/core/index.js.ejs +0 -24
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
// templates/utils/validators.js.ejs
|
|
2
|
-
const validator = require('validator');
|
|
3
|
-
|
|
4
|
-
const isEmail = (email) => {
|
|
5
|
-
return validator.isEmail(email);
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
const isStrongPassword = (password) => {
|
|
9
|
-
return validator.isStrongPassword(password, {
|
|
10
|
-
minLength: 8,
|
|
11
|
-
minLowercase: 1,
|
|
12
|
-
minUppercase: 1,
|
|
13
|
-
minNumbers: 1,
|
|
14
|
-
minSymbols: 0,
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const sanitizeInput = (input) => {
|
|
19
|
-
if (typeof input === 'string') {
|
|
20
|
-
return validator.escape(input.trim());
|
|
21
|
-
}
|
|
22
|
-
return input;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const isValidObjectId = (id) => {<% if (db === 'mongodb') { %>
|
|
26
|
-
return validator.isMongoId(id);<% } else { %>
|
|
27
|
-
return validator.isUUID(id);<% } %>
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
module.exports = {
|
|
31
|
-
isEmail,
|
|
32
|
-
isStrongPassword,
|
|
33
|
-
sanitizeInput,
|
|
34
|
-
isValidObjectId,
|
|
1
|
+
// templates/utils/validators.js.ejs
|
|
2
|
+
const validator = require('validator');
|
|
3
|
+
|
|
4
|
+
const isEmail = (email) => {
|
|
5
|
+
return validator.isEmail(email);
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const isStrongPassword = (password) => {
|
|
9
|
+
return validator.isStrongPassword(password, {
|
|
10
|
+
minLength: 8,
|
|
11
|
+
minLowercase: 1,
|
|
12
|
+
minUppercase: 1,
|
|
13
|
+
minNumbers: 1,
|
|
14
|
+
minSymbols: 0,
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const sanitizeInput = (input) => {
|
|
19
|
+
if (typeof input === 'string') {
|
|
20
|
+
return validator.escape(input.trim());
|
|
21
|
+
}
|
|
22
|
+
return input;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const isValidObjectId = (id) => {<% if (db === 'mongodb') { %>
|
|
26
|
+
return validator.isMongoId(id);<% } else { %>
|
|
27
|
+
return validator.isUUID(id);<% } %>
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
module.exports = {
|
|
31
|
+
isEmail,
|
|
32
|
+
isStrongPassword,
|
|
33
|
+
sanitizeInput,
|
|
34
|
+
isValidObjectId,
|
|
35
35
|
};
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"openapi": "3.0.0",
|
|
3
|
-
"info": {
|
|
4
|
-
"title": "<%= projectName %> API",
|
|
5
|
-
"version": "1.0.0",
|
|
6
|
-
"description": "A production-grade Express boilerplate<% if (hasDatabase) { %> with JWT authentication<% } %>"
|
|
7
|
-
},
|
|
8
|
-
"servers": [
|
|
9
|
-
{
|
|
10
|
-
"url": "http://localhost:3000/api",
|
|
11
|
-
"description": "Development server"
|
|
12
|
-
}
|
|
13
|
-
],<% if (hasDatabase) { %>
|
|
14
|
-
"components": {
|
|
15
|
-
"securitySchemes": {
|
|
16
|
-
"bearerAuth": {
|
|
17
|
-
"type": "http",
|
|
18
|
-
"scheme": "bearer",
|
|
19
|
-
"bearerFormat": "JWT"
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
},<% } %>
|
|
23
|
-
"paths": {<% if (hasDatabase) { %>
|
|
24
|
-
"/auth/register": {
|
|
25
|
-
"post": {
|
|
26
|
-
"summary": "Register a new user",
|
|
27
|
-
"tags": ["Authentication"],
|
|
28
|
-
"requestBody": {
|
|
29
|
-
"required": true,
|
|
30
|
-
"content": {
|
|
31
|
-
"application/json": {
|
|
32
|
-
"schema": {
|
|
33
|
-
"type": "object",
|
|
34
|
-
"required": ["username", "email", "password"],
|
|
35
|
-
"properties": {
|
|
36
|
-
"username": { "type": "string" },
|
|
37
|
-
"email": { "type": "string", "format": "email" },
|
|
38
|
-
"password": { "type": "string", "minLength": 6 }
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
"responses": {
|
|
45
|
-
"201": { "description": "User registered successfully" },
|
|
46
|
-
"409": { "description": "User already exists" }
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
"/auth/login": {
|
|
51
|
-
"post": {
|
|
52
|
-
"summary": "Login user",
|
|
53
|
-
"tags": ["Authentication"],
|
|
54
|
-
"requestBody": {
|
|
55
|
-
"required": true,
|
|
56
|
-
"content": {
|
|
57
|
-
"application/json": {
|
|
58
|
-
"schema": {
|
|
59
|
-
"type": "object",
|
|
60
|
-
"required": ["email", "password"],
|
|
61
|
-
"properties": {
|
|
62
|
-
"email": { "type": "string", "format": "email" },
|
|
63
|
-
"password": { "type": "string" }
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
"responses": {
|
|
70
|
-
"200": { "description": "Login successful" },
|
|
71
|
-
"401": { "description": "Invalid credentials" }
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
"/users/profile": {
|
|
76
|
-
"get": {
|
|
77
|
-
"summary": "Get user profile",
|
|
78
|
-
"tags": ["Users"],
|
|
79
|
-
"security": [{ "bearerAuth": [] }],
|
|
80
|
-
"responses": {
|
|
81
|
-
"200": { "description": "User profile retrieved" },
|
|
82
|
-
"401": { "description": "Unauthorized" }
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}<% } else { %>
|
|
86
|
-
"/examples": {
|
|
87
|
-
"get": {
|
|
88
|
-
"summary": "Get all examples",
|
|
89
|
-
"tags": ["Examples"],
|
|
90
|
-
"parameters": [
|
|
91
|
-
{
|
|
92
|
-
"name": "page",
|
|
93
|
-
"in": "query",
|
|
94
|
-
"schema": { "type": "integer", "default": 1 }
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
"name": "limit",
|
|
98
|
-
"in": "query",
|
|
99
|
-
"schema": { "type": "integer", "default": 10 }
|
|
100
|
-
}
|
|
101
|
-
],
|
|
102
|
-
"responses": {
|
|
103
|
-
"200": { "description": "Examples retrieved successfully" }
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
"post": {
|
|
107
|
-
"summary": "Create new example",
|
|
108
|
-
"tags": ["Examples"],
|
|
109
|
-
"requestBody": {
|
|
110
|
-
"required": true,
|
|
111
|
-
"content": {
|
|
112
|
-
"application/json": {
|
|
113
|
-
"schema": {
|
|
114
|
-
"type": "object",
|
|
115
|
-
"required": ["title", "description"],
|
|
116
|
-
"properties": {
|
|
117
|
-
"title": { "type": "string" },
|
|
118
|
-
"description": { "type": "string" }
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
"responses": {
|
|
125
|
-
"201": { "description": "Example created successfully" },
|
|
126
|
-
"400": { "description": "Invalid input" }
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
"/examples/{id}": {
|
|
131
|
-
"get": {
|
|
132
|
-
"summary": "Get example by ID",
|
|
133
|
-
"tags": ["Examples"],
|
|
134
|
-
"parameters": [
|
|
135
|
-
{
|
|
136
|
-
"name": "id",
|
|
137
|
-
"in": "path",
|
|
138
|
-
"required": true,
|
|
139
|
-
"schema": { "type": "string" }
|
|
140
|
-
}
|
|
141
|
-
],
|
|
142
|
-
"responses": {
|
|
143
|
-
"200": { "description": "Example retrieved successfully" },
|
|
144
|
-
"404": { "description": "Example not found" }
|
|
145
|
-
}
|
|
146
|
-
},
|
|
147
|
-
"put": {
|
|
148
|
-
"summary": "Update example",
|
|
149
|
-
"tags": ["Examples"],
|
|
150
|
-
"parameters": [
|
|
151
|
-
{
|
|
152
|
-
"name": "id",
|
|
153
|
-
"in": "path",
|
|
154
|
-
"required": true,
|
|
155
|
-
"schema": { "type": "string" }
|
|
156
|
-
}
|
|
157
|
-
],
|
|
158
|
-
"requestBody": {
|
|
159
|
-
"content": {
|
|
160
|
-
"application/json": {
|
|
161
|
-
"schema": {
|
|
162
|
-
"type": "object",
|
|
163
|
-
"properties": {
|
|
164
|
-
"title": { "type": "string" },
|
|
165
|
-
"description": { "type": "string" }
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
},
|
|
171
|
-
"responses": {
|
|
172
|
-
"200": { "description": "Example updated successfully" },
|
|
173
|
-
"404": { "description": "Example not found" }
|
|
174
|
-
}
|
|
175
|
-
},
|
|
176
|
-
"delete": {
|
|
177
|
-
"summary": "Delete example",
|
|
178
|
-
"tags": ["Examples"],
|
|
179
|
-
"parameters": [
|
|
180
|
-
{
|
|
181
|
-
"name": "id",
|
|
182
|
-
"in": "path",
|
|
183
|
-
"required": true,
|
|
184
|
-
"schema": { "type": "string" }
|
|
185
|
-
}
|
|
186
|
-
],
|
|
187
|
-
"responses": {
|
|
188
|
-
"200": { "description": "Example deleted successfully" },
|
|
189
|
-
"404": { "description": "Example not found" }
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}<% } %>
|
|
193
|
-
}
|
|
194
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const express = require('express');<% if (hasDatabase) { %>
|
|
2
|
-
const authRoutes = require('./authRoutes');
|
|
3
|
-
const userRoutes = require('./userRoutes');<% } else { %>
|
|
4
|
-
const exampleRoutes = require('./exampleRoutes');<% } %>
|
|
5
|
-
|
|
6
|
-
const router = express.Router();
|
|
7
|
-
|
|
8
|
-
// Mount route modules<% if (hasDatabase) { %>
|
|
9
|
-
router.use('/auth', authRoutes);
|
|
10
|
-
router.use('/users', userRoutes);<% } else { %>
|
|
11
|
-
router.use('/examples', exampleRoutes);<% } %>
|
|
12
|
-
|
|
13
|
-
// API root endpoint
|
|
14
|
-
router.get('/', (req, res) => {
|
|
15
|
-
res.json({
|
|
16
|
-
message: 'Welcome to the API',
|
|
17
|
-
version: '1.0.0',
|
|
18
|
-
documentation: '/api-docs',<% if (hasDatabase) { %>
|
|
19
|
-
features: ['authentication', 'user-management', '<%= db %>-database']<% } else { %>
|
|
20
|
-
features: ['rate-limiting', 'logging', 'swagger-docs']<% } %>,
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
module.exports = router;
|