speedrun-cli 2.6.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.
Files changed (159) hide show
  1. package/CHANGELOG.md +96 -0
  2. package/LICENSE +21 -0
  3. package/README.md +620 -0
  4. package/bin/cli.js +224 -0
  5. package/index.js +12 -0
  6. package/package.json +74 -0
  7. package/src/constants.js +65 -0
  8. package/src/generator.js +271 -0
  9. package/src/index.js +13 -0
  10. package/src/moduleGenerator.js +586 -0
  11. package/src/postSetup.js +365 -0
  12. package/src/prompts.js +189 -0
  13. package/src/utils.js +112 -0
  14. package/templates/README.md +81 -0
  15. package/templates/base/eslint.config.mjs +34 -0
  16. package/templates/base/gitignore +78 -0
  17. package/templates/base/nest-cli.json +8 -0
  18. package/templates/base/src/common/constants/cookie.config.ts +20 -0
  19. package/templates/base/src/common/decorators/get-user.decorator.ts +13 -0
  20. package/templates/base/src/common/decorators/public.decorator.ts +4 -0
  21. package/templates/base/src/common/decorators/roles.decorator.ts +4 -0
  22. package/templates/base/src/common/dtos/pagination.dto.ts +29 -0
  23. package/templates/base/src/common/filters/http-exception.filter.ts +108 -0
  24. package/templates/base/src/common/guards/auth.guard.ts +51 -0
  25. package/templates/base/src/common/guards/refresh-token.guard.ts +39 -0
  26. package/templates/base/src/common/guards/roles.guard.ts +45 -0
  27. package/templates/base/src/common/interceptors/response.interceptor.ts +55 -0
  28. package/templates/base/src/common/interfaces/api-response.interface.ts +26 -0
  29. package/templates/base/src/common/middleware/correlation-id.middleware.ts +20 -0
  30. package/templates/base/src/common/validators/password.validator.ts +37 -0
  31. package/templates/base/src/config/config.module.ts +14 -0
  32. package/templates/base/src/config/logger.config.ts +109 -0
  33. package/templates/base/src/main.ts +84 -0
  34. package/templates/base/src/modules/auth/auth.controller.ts +133 -0
  35. package/templates/base/src/modules/auth/dtos/login.dto.ts +11 -0
  36. package/templates/base/src/modules/auth/dtos/signup.dto.ts +8 -0
  37. package/templates/base/src/modules/health/health.controller.ts +20 -0
  38. package/templates/base/src/modules/health/health.module.ts +7 -0
  39. package/templates/base/src/modules/users/dtos/update-profile.dto.ts +12 -0
  40. package/templates/base/src/modules/users/dtos/update-user.dto.ts +13 -0
  41. package/templates/base/src/modules/users/users.controller.ts +65 -0
  42. package/templates/base/test/app.e2e-spec.ts +24 -0
  43. package/templates/base/test/jest-e2e.json +9 -0
  44. package/templates/base/tsconfig.build.json +4 -0
  45. package/templates/base/tsconfig.json +24 -0
  46. package/templates/base-crud/CRUD_README.md +385 -0
  47. package/templates/base-crud/src/common/base/base.controller.ts +321 -0
  48. package/templates/base-crud/src/common/base/base.service.ts +192 -0
  49. package/templates/base-crud/src/common/base/index.ts +20 -0
  50. package/templates/base-crud/src/common/base/swagger/api-response.dto.ts +82 -0
  51. package/templates/base-crud/src/common/base/swagger/paginated.dto.ts +102 -0
  52. package/templates/base-crud/src/modules/products/dto/create-product.dto.ts +44 -0
  53. package/templates/base-crud/src/modules/products/dto/product.dto.ts +38 -0
  54. package/templates/base-crud/src/modules/products/dto/update-product.dto.ts +12 -0
  55. package/templates/base-crud/src/modules/products/products.controller.ts +94 -0
  56. package/templates/base-crud-drizzle/src/modules/products/products.controller.ts +79 -0
  57. package/templates/base-crud-drizzle/src/modules/products/products.module.ts +24 -0
  58. package/templates/base-crud-drizzle/src/modules/products/products.service.ts +140 -0
  59. package/templates/base-crud-drizzle/src/modules/products/schema/products.schema.ts +39 -0
  60. package/templates/base-crud-mongoose/src/modules/products/products.controller.ts +79 -0
  61. package/templates/base-crud-mongoose/src/modules/products/products.module.ts +26 -0
  62. package/templates/base-crud-mongoose/src/modules/products/products.service.ts +133 -0
  63. package/templates/base-crud-mongoose/src/modules/products/schemas/product.schema.ts +67 -0
  64. package/templates/base-crud-prisma/src/modules/products/products.module.ts +12 -0
  65. package/templates/base-crud-prisma/src/modules/products/products.service.ts +100 -0
  66. package/templates/base-crud-typeorm/src/modules/products/entities/product.entity.ts +58 -0
  67. package/templates/base-crud-typeorm/src/modules/products/products.controller.ts +79 -0
  68. package/templates/base-crud-typeorm/src/modules/products/products.module.ts +25 -0
  69. package/templates/base-crud-typeorm/src/modules/products/products.service.ts +102 -0
  70. package/templates/database/mongodb/.env.example +22 -0
  71. package/templates/database/mysql/.env.example +24 -0
  72. package/templates/database/mysql/drizzle.config.ts +13 -0
  73. package/templates/database/mysql/package.json +5 -0
  74. package/templates/database/mysql/prisma/schema.prisma +55 -0
  75. package/templates/database/mysql/src/database/drizzle.ts +13 -0
  76. package/templates/database/mysql/src/database/schema.ts +58 -0
  77. package/templates/database/postgres/.env.example +24 -0
  78. package/templates/database/postgres/drizzle.config.ts +13 -0
  79. package/templates/database/postgres/package.json +8 -0
  80. package/templates/database/postgres/prisma/schema.prisma +55 -0
  81. package/templates/database/sqlite/.env.example +24 -0
  82. package/templates/database/sqlite/drizzle.config.ts +13 -0
  83. package/templates/database/sqlite/package.json +8 -0
  84. package/templates/database/sqlite/prisma/schema.prisma +48 -0
  85. package/templates/database/sqlite/src/database/drizzle.ts +11 -0
  86. package/templates/database/sqlite/src/database/schema.ts +52 -0
  87. package/templates/orm/drizzle/drizzle.config.ts +13 -0
  88. package/templates/orm/drizzle/package.json +90 -0
  89. package/templates/orm/drizzle/src/app.module.ts +73 -0
  90. package/templates/orm/drizzle/src/config/env.validation.ts +55 -0
  91. package/templates/orm/drizzle/src/database/database.module.ts +25 -0
  92. package/templates/orm/drizzle/src/database/drizzle.ts +13 -0
  93. package/templates/orm/drizzle/src/database/schema.ts +60 -0
  94. package/templates/orm/drizzle/src/database/seed.ts +87 -0
  95. package/templates/orm/drizzle/src/modules/auth/auth.module.ts +12 -0
  96. package/templates/orm/drizzle/src/modules/auth/auth.service.ts +298 -0
  97. package/templates/orm/drizzle/src/modules/health/health.controller.ts +34 -0
  98. package/templates/orm/drizzle/src/modules/health/health.module.ts +7 -0
  99. package/templates/orm/drizzle/src/modules/users/users.module.ts +10 -0
  100. package/templates/orm/drizzle/src/modules/users/users.service.ts +152 -0
  101. package/templates/orm/mongoose/.env.example +22 -0
  102. package/templates/orm/mongoose/package.json +86 -0
  103. package/templates/orm/mongoose/src/app.module.ts +73 -0
  104. package/templates/orm/mongoose/src/config/env.validation.ts +55 -0
  105. package/templates/orm/mongoose/src/database/database.module.ts +19 -0
  106. package/templates/orm/mongoose/src/database/seed.ts +107 -0
  107. package/templates/orm/mongoose/src/modules/auth/auth.module.ts +21 -0
  108. package/templates/orm/mongoose/src/modules/auth/auth.service.ts +272 -0
  109. package/templates/orm/mongoose/src/modules/auth/dtos/login.dto.ts +10 -0
  110. package/templates/orm/mongoose/src/modules/auth/dtos/signup.dto.ts +8 -0
  111. package/templates/orm/mongoose/src/modules/health/health.controller.ts +26 -0
  112. package/templates/orm/mongoose/src/modules/health/health.module.ts +7 -0
  113. package/templates/orm/mongoose/src/modules/users/dtos/update-profile.dto.ts +24 -0
  114. package/templates/orm/mongoose/src/modules/users/dtos/update-user.dto.ts +13 -0
  115. package/templates/orm/mongoose/src/modules/users/users.module.ts +19 -0
  116. package/templates/orm/mongoose/src/modules/users/users.service.ts +179 -0
  117. package/templates/orm/mongoose/src/schemas/index.ts +2 -0
  118. package/templates/orm/mongoose/src/schemas/refresh-token.schema.ts +55 -0
  119. package/templates/orm/mongoose/src/schemas/user.schema.ts +53 -0
  120. package/templates/orm/prisma/package.json +102 -0
  121. package/templates/orm/prisma/prisma/schema.prisma +60 -0
  122. package/templates/orm/prisma/prisma/seed.ts +69 -0
  123. package/templates/orm/prisma/src/app.module.ts +55 -0
  124. package/templates/orm/prisma/src/config/env.validation.ts +56 -0
  125. package/templates/orm/prisma/src/modules/auth/auth.module.ts +17 -0
  126. package/templates/orm/prisma/src/modules/auth/auth.service.ts +308 -0
  127. package/templates/orm/prisma/src/modules/health/health.controller.ts +26 -0
  128. package/templates/orm/prisma/src/modules/health/health.module.ts +10 -0
  129. package/templates/orm/prisma/src/modules/users/users.module.ts +11 -0
  130. package/templates/orm/prisma/src/modules/users/users.service.ts +105 -0
  131. package/templates/orm/prisma/src/prisma/prisma.module.ts +9 -0
  132. package/templates/orm/prisma/src/prisma/prisma.service.ts +16 -0
  133. package/templates/orm/typeorm/package.json +100 -0
  134. package/templates/orm/typeorm/src/app.module.ts +55 -0
  135. package/templates/orm/typeorm/src/config/env.validation.ts +58 -0
  136. package/templates/orm/typeorm/src/database/data-source.ts +19 -0
  137. package/templates/orm/typeorm/src/database/database.module.ts +27 -0
  138. package/templates/orm/typeorm/src/database/seed.ts +76 -0
  139. package/templates/orm/typeorm/src/entities/index.ts +2 -0
  140. package/templates/orm/typeorm/src/entities/refresh-token.entity.ts +45 -0
  141. package/templates/orm/typeorm/src/entities/user.entity.ts +51 -0
  142. package/templates/orm/typeorm/src/modules/auth/auth.module.ts +19 -0
  143. package/templates/orm/typeorm/src/modules/auth/auth.service.ts +286 -0
  144. package/templates/orm/typeorm/src/modules/health/health.controller.ts +24 -0
  145. package/templates/orm/typeorm/src/modules/health/health.module.ts +9 -0
  146. package/templates/orm/typeorm/src/modules/users/users.module.ts +13 -0
  147. package/templates/orm/typeorm/src/modules/users/users.service.ts +108 -0
  148. package/templates/swagger/src/common/dtos/pagination.dto.ts +43 -0
  149. package/templates/swagger/src/main.ts +116 -0
  150. package/templates/swagger/src/modules/auth/auth.controller.ts +235 -0
  151. package/templates/swagger/src/modules/auth/dtos/login.dto.ts +20 -0
  152. package/templates/swagger/src/modules/auth/dtos/signup.dto.ts +14 -0
  153. package/templates/swagger/src/modules/users/dtos/update-profile.dto.ts +19 -0
  154. package/templates/swagger/src/modules/users/dtos/update-user.dto.ts +23 -0
  155. package/templates/swagger/src/modules/users/users.controller.ts +214 -0
  156. package/templates/swagger-mongoose/src/modules/auth/dtos/login.dto.ts +20 -0
  157. package/templates/swagger-mongoose/src/modules/auth/dtos/signup.dto.ts +14 -0
  158. package/templates/swagger-mongoose/src/modules/users/dtos/update-profile.dto.ts +40 -0
  159. package/templates/swagger-mongoose/src/modules/users/dtos/update-user.dto.ts +23 -0
@@ -0,0 +1,214 @@
1
+ import {
2
+ Body,
3
+ Controller,
4
+ Delete,
5
+ Get,
6
+ Param,
7
+ Patch,
8
+ Query,
9
+ } from '@nestjs/common';
10
+ import {
11
+ ApiTags,
12
+ ApiOperation,
13
+ ApiResponse,
14
+ ApiBearerAuth,
15
+ } from '@nestjs/swagger';
16
+ import { UsersService } from './users.service';
17
+ import { GetUser } from 'src/common/decorators/get-user.decorator';
18
+ import { Roles } from 'src/common/decorators/roles.decorator';
19
+ import { UserRole } from 'src/common/guards/roles.guard';
20
+ import { UpdateUserDto } from './dtos/update-user.dto';
21
+ import { UpdateProfileDto } from './dtos/update-profile.dto';
22
+ import { PaginationDto } from 'src/common/dtos/pagination.dto';
23
+
24
+ @ApiBearerAuth('bearer')
25
+ @ApiTags('Users')
26
+ @Controller('users')
27
+ export class UsersController {
28
+ constructor(private readonly usersService: UsersService) {}
29
+
30
+ // profile routes
31
+ @ApiOperation({ summary: 'Get current user profile' })
32
+ @ApiResponse({
33
+ status: 200,
34
+ description: 'Returns the authenticated user profile.',
35
+ schema: {
36
+ example: {
37
+ statusCode: 200,
38
+ data: {
39
+ id: 'clxyz...',
40
+ email: 'user@example.com',
41
+ fullName: 'John Doe',
42
+ role: 'USER',
43
+ isActive: true,
44
+ },
45
+ },
46
+ },
47
+ })
48
+ @ApiResponse({
49
+ status: 401,
50
+ description: 'Unauthorized - invalid or missing JWT token.',
51
+ })
52
+ @Get('/profile')
53
+ async getProfile(@GetUser('sub') userId: string) {
54
+ return this.usersService.getProfile(userId);
55
+ }
56
+
57
+ @ApiOperation({ summary: 'Update current user profile' })
58
+ @ApiResponse({
59
+ status: 200,
60
+ description: 'Profile updated successfully.',
61
+ schema: {
62
+ example: {
63
+ statusCode: 200,
64
+ message: 'Profile updated successfully',
65
+ data: {
66
+ id: 'clxyz...',
67
+ email: 'user@example.com',
68
+ fullName: 'Jane Doe',
69
+ role: 'USER',
70
+ isActive: true,
71
+ },
72
+ },
73
+ },
74
+ })
75
+ @ApiResponse({
76
+ status: 401,
77
+ description: 'Unauthorized - invalid or missing JWT token.',
78
+ })
79
+ @Patch('/profile')
80
+ async updateProfile(
81
+ @GetUser('sub') userId: string,
82
+ @Body() updateProfileDto: UpdateProfileDto,
83
+ ) {
84
+ return this.usersService.updateProfile(userId, updateProfileDto);
85
+ }
86
+
87
+ // admin routes
88
+ @ApiOperation({ summary: 'Get all users (Admin only)' })
89
+ @ApiResponse({
90
+ status: 200,
91
+ description: 'Returns a paginated list of all users.',
92
+ schema: {
93
+ example: {
94
+ statusCode: 200,
95
+ data: {
96
+ data: [
97
+ {
98
+ id: 'clxyz...',
99
+ email: 'user@example.com',
100
+ fullName: 'John Doe',
101
+ role: 'USER',
102
+ isActive: true,
103
+ },
104
+ ],
105
+ meta: {
106
+ total: 50,
107
+ page: 1,
108
+ limit: 10,
109
+ totalPages: 5,
110
+ hasNext: true,
111
+ hasPrevious: false,
112
+ },
113
+ },
114
+ },
115
+ },
116
+ })
117
+ @ApiResponse({
118
+ status: 401,
119
+ description: 'Unauthorized - invalid or missing JWT token.',
120
+ })
121
+ @ApiResponse({ status: 403, description: 'Forbidden - Admin role required.' })
122
+ @Roles(UserRole.ADMIN)
123
+ @Get('/')
124
+ async getAllUsers(@Query() paginationDto: PaginationDto) {
125
+ const { page = 1, limit = 10 } = paginationDto;
126
+ return this.usersService.getAllUsers(page, limit);
127
+ }
128
+
129
+ @ApiOperation({ summary: 'Get a user by ID (Admin only)' })
130
+ @ApiResponse({
131
+ status: 200,
132
+ description: 'Returns the user with the specified ID.',
133
+ schema: {
134
+ example: {
135
+ statusCode: 200,
136
+ data: {
137
+ id: 'clxyz...',
138
+ email: 'user@example.com',
139
+ fullName: 'John Doe',
140
+ role: 'USER',
141
+ isActive: true,
142
+ },
143
+ },
144
+ },
145
+ })
146
+ @ApiResponse({
147
+ status: 401,
148
+ description: 'Unauthorized - invalid or missing JWT token.',
149
+ })
150
+ @ApiResponse({ status: 403, description: 'Forbidden - Admin role required.' })
151
+ @ApiResponse({ status: 404, description: 'User not found.' })
152
+ @Roles(UserRole.ADMIN)
153
+ @Get('/:id')
154
+ async getUserById(@Param('id') id: string) {
155
+ return this.usersService.getUserById(id);
156
+ }
157
+
158
+ @ApiOperation({ summary: 'Update a user by ID (Admin only)' })
159
+ @ApiResponse({
160
+ status: 200,
161
+ description: 'User updated successfully.',
162
+ schema: {
163
+ example: {
164
+ statusCode: 200,
165
+ message: 'User updated successfully',
166
+ data: {
167
+ id: 'clxyz...',
168
+ email: 'user@example.com',
169
+ fullName: 'John Doe',
170
+ role: 'ADMIN',
171
+ isActive: true,
172
+ },
173
+ },
174
+ },
175
+ })
176
+ @ApiResponse({
177
+ status: 401,
178
+ description: 'Unauthorized - invalid or missing JWT token.',
179
+ })
180
+ @ApiResponse({ status: 403, description: 'Forbidden - Admin role required.' })
181
+ @ApiResponse({ status: 404, description: 'User not found.' })
182
+ @Roles(UserRole.ADMIN)
183
+ @Patch('/:id')
184
+ async updateUserById(
185
+ @Param('id') id: string,
186
+ @Body() updateUserDto: UpdateUserDto,
187
+ ) {
188
+ return this.usersService.updateUserById(id, updateUserDto);
189
+ }
190
+
191
+ //this soft deletes a user by setting isActive to false
192
+ @ApiOperation({ summary: 'Soft delete a user by ID (Admin only)' })
193
+ @ApiResponse({
194
+ status: 200,
195
+ description: 'User deactivated successfully.',
196
+ schema: {
197
+ example: {
198
+ statusCode: 200,
199
+ message: 'User deactivated successfully',
200
+ },
201
+ },
202
+ })
203
+ @ApiResponse({
204
+ status: 401,
205
+ description: 'Unauthorized - invalid or missing JWT token.',
206
+ })
207
+ @ApiResponse({ status: 403, description: 'Forbidden - Admin role required.' })
208
+ @ApiResponse({ status: 404, description: 'User not found.' })
209
+ @Roles(UserRole.ADMIN)
210
+ @Delete('/:id')
211
+ async deleteUserById(@Param('id') id: string) {
212
+ return this.usersService.deleteUserById(id);
213
+ }
214
+ }
@@ -0,0 +1,20 @@
1
+ import { ApiProperty } from '@nestjs/swagger';
2
+ import { IsEmail, IsString, MinLength } from 'class-validator';
3
+
4
+ export class LoginDto {
5
+ @ApiProperty({
6
+ description: 'User email address',
7
+ example: 'user@example.com',
8
+ })
9
+ @IsEmail()
10
+ email: string;
11
+
12
+ @ApiProperty({
13
+ description: 'User password (minimum 6 characters)',
14
+ example: 'MyP@ssw0rd',
15
+ minLength: 6,
16
+ })
17
+ @IsString()
18
+ @MinLength(6)
19
+ password: string;
20
+ }
@@ -0,0 +1,14 @@
1
+ import { ApiProperty } from '@nestjs/swagger';
2
+ import { IsString, MinLength } from 'class-validator';
3
+ import { LoginDto } from './login.dto';
4
+
5
+ export class SignupDto extends LoginDto {
6
+ @ApiProperty({
7
+ description: 'User full name',
8
+ example: 'John Doe',
9
+ minLength: 2,
10
+ })
11
+ @IsString()
12
+ @MinLength(2)
13
+ fullName: string;
14
+ }
@@ -0,0 +1,40 @@
1
+ import { ApiPropertyOptional } from '@nestjs/swagger';
2
+ import {
3
+ IsEmail,
4
+ IsOptional,
5
+ IsString,
6
+ MaxLength,
7
+ MinLength,
8
+ } from 'class-validator';
9
+
10
+ export class UpdateProfileDto {
11
+ @ApiPropertyOptional({
12
+ description: 'User full name',
13
+ example: 'Jane Doe',
14
+ minLength: 2,
15
+ maxLength: 100,
16
+ })
17
+ @IsOptional()
18
+ @IsString()
19
+ @MinLength(2)
20
+ @MaxLength(100)
21
+ fullName?: string;
22
+
23
+ @ApiPropertyOptional({
24
+ description: 'User email address',
25
+ example: 'newemail@example.com',
26
+ })
27
+ @IsOptional()
28
+ @IsEmail()
29
+ email?: string;
30
+
31
+ @ApiPropertyOptional({
32
+ description: 'New password (minimum 6 characters)',
33
+ example: 'NewP@ssw0rd',
34
+ minLength: 6,
35
+ })
36
+ @IsOptional()
37
+ @IsString()
38
+ @MinLength(6)
39
+ password?: string;
40
+ }
@@ -0,0 +1,23 @@
1
+ import { ApiPropertyOptional } from '@nestjs/swagger';
2
+ import { IsBoolean, IsEnum, IsOptional } from 'class-validator';
3
+ import { UpdateProfileDto } from './update-profile.dto';
4
+ import { UserRole } from '../../../schemas/user.schema';
5
+
6
+ export class UpdateUserDto extends UpdateProfileDto {
7
+ @ApiPropertyOptional({
8
+ description: 'User role',
9
+ enum: UserRole,
10
+ example: 'ADMIN',
11
+ })
12
+ @IsOptional()
13
+ @IsEnum(UserRole, { message: 'Role must be a valid UserRole' })
14
+ role?: UserRole;
15
+
16
+ @ApiPropertyOptional({
17
+ description: 'Whether the user account is active',
18
+ example: true,
19
+ })
20
+ @IsOptional()
21
+ @IsBoolean()
22
+ isActive?: boolean;
23
+ }