@nest-extended/cli 0.0.1 → 0.0.2-beta-2

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/README.md CHANGED
@@ -4,14 +4,51 @@ A powerful command-line interface for the **NestExtended** ecosystem. This CLI a
4
4
 
5
5
  ## Installation
6
6
 
7
+ To install globally (recommended for scaffolding new apps):
8
+
7
9
  ```bash
8
- yarn add -D @nest-extended/cli
10
+ npm install -g @nest-extended/cli
9
11
  # or
12
+ yarn global add @nest-extended/cli
13
+ ```
14
+
15
+ To install as a dev dependency in an existing project:
16
+
17
+ ```bash
10
18
  npm install -D @nest-extended/cli
19
+ # or
20
+ yarn add -D @nest-extended/cli
11
21
  ```
12
22
 
13
23
  ## Commands
14
24
 
25
+ ### Generate Application (`g app`)
26
+
27
+ Generates a fully configured NestJS application with standard best-practices built right in.
28
+ It interactive prompts for your choice of database (currently supporting MongoDB) and handles scaffolding the app.
29
+
30
+ **Includes:**
31
+ - Running `@nestjs/cli`'s `nest new` command internally
32
+ - `Mongoose` schema integration out of the box
33
+ - Context-mapping out of the box using `nestjs-cls`
34
+ - Built-in `AuthModule` with JSON Web Token (JWT) handling via `@nestjs/jwt` and password hashing with `bcrypt`
35
+ - Fully functional `UsersModule` equipped with standard fields and authentication logic implementations.
36
+ - Pre-configured `NestExtendedModule` context for soft deletes functionality
37
+
38
+ **Usage:**
39
+
40
+ ```bash
41
+ nest-cli g app <app-name>
42
+ # or
43
+ nest-cli generate app <app-name>
44
+ ```
45
+
46
+ **Example:**
47
+
48
+ ```bash
49
+ nest-cli g app e-commerce-dashboard
50
+ ```
51
+
15
52
  ### Generate Service (`g service`)
16
53
 
17
54
  Generates a complete resource bundle including:
@@ -27,15 +64,15 @@ It also automatically updates your `src/app.module.ts` to include the new module
27
64
  **Usage:**
28
65
 
29
66
  ```bash
30
- nestx-cli g service <name>
67
+ nest-cli g service <name>
31
68
  # or
32
- nestx-cli generate service <name>
69
+ nest-cli generate service <name>
33
70
  ```
34
71
 
35
72
  **Example:**
36
73
 
37
74
  ```bash
38
- nestx-cli g service user-profile
75
+ nest-cli g service user-profile
39
76
  ```
40
77
 
41
78
  This will create:
package/package.json CHANGED
@@ -1,23 +1,25 @@
1
1
  {
2
2
  "name": "@nest-extended/cli",
3
- "version": "0.0.1",
3
+ "version": "0.0.2-beta-2",
4
4
  "private": false,
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
7
7
  "bin": {
8
- "nestx-cli": "./src/index.js"
8
+ "nest-cli": "./src/index.js"
9
9
  },
10
10
  "dependencies": {
11
- "tslib": "^2.3.0",
12
- "commander": "^11.0.0",
11
+ "@nestjs/cli": "^11.0.16",
13
12
  "chalk": "^4.1.2",
13
+ "commander": "^11.0.0",
14
+ "fs-extra": "^11.1.1",
14
15
  "inquirer": "^8.2.5",
15
- "fs-extra": "^11.1.1"
16
+ "tslib": "^2.3.0"
16
17
  },
17
18
  "devDependencies": {
18
- "@types/node": "^18.16.9",
19
+ "@types/fs-extra": "^11.0.1",
20
+ "@types/glob": "^9.0.0",
19
21
  "@types/inquirer": "^9.0.3",
20
- "@types/fs-extra": "^11.0.1"
22
+ "@types/node": "^18.16.9"
21
23
  },
22
24
  "type": "commonjs"
23
25
  }
@@ -3,6 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateCommand = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const commander_1 = require("commander");
6
+ const inquirer = require("inquirer");
7
+ const chalk = require("chalk");
8
+ const path = require("path");
9
+ const fs = require("fs-extra");
10
+ const child_process_1 = require("child_process");
6
11
  const create_file_1 = require("../lib/create-file");
7
12
  const update_app_module_1 = require("../lib/update-app-module");
8
13
  const module_template_1 = require("../templates/module.template");
@@ -12,6 +17,8 @@ const dto_template_1 = require("../templates/dto.template");
12
17
  const schema_template_1 = require("../templates/schema.template");
13
18
  const service_spec_template_1 = require("../templates/service.spec.template");
14
19
  const controller_spec_template_1 = require("../templates/controller.spec.template");
20
+ const auth_template_1 = require("../templates/auth.template");
21
+ const users_template_1 = require("../templates/users.template");
15
22
  exports.generateCommand = new commander_1.Command('generate')
16
23
  .alias('g')
17
24
  .description('Generate a new element');
@@ -35,5 +42,166 @@ exports.generateCommand
35
42
  (0, create_file_1.createFileWithContent)(`src/services/${name}/${name}.service.spec.ts`, (0, service_spec_template_1.getServiceSpec)(Name, name));
36
43
  (0, create_file_1.createFileWithContent)(`src/services/${name}/${name}.controller.spec.ts`, (0, controller_spec_template_1.getControllerSpec)(Name, name));
37
44
  yield (0, update_app_module_1.updateAppModule)(Name, name);
45
+ console.log(chalk.blue('Running lint...'));
46
+ const projectDir = process.cwd();
47
+ const pkgManager = fs.existsSync(path.join(projectDir, 'yarn.lock')) ? 'yarn' : 'npm';
48
+ yield new Promise((resolve) => {
49
+ const lintChild = (0, child_process_1.spawn)(pkgManager, ['run', 'lint'], {
50
+ stdio: 'inherit',
51
+ cwd: projectDir,
52
+ shell: true,
53
+ });
54
+ lintChild.on('close', () => resolve());
55
+ });
56
+ }));
57
+ exports.generateCommand
58
+ .command('app <name>')
59
+ .description('Generate a new application')
60
+ .action((appName) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
61
+ const questions = [
62
+ {
63
+ type: 'list',
64
+ name: 'database',
65
+ message: 'Which database would you like to use?',
66
+ choices: ['mongo', 'sql'],
67
+ },
68
+ ];
69
+ // @ts-ignore
70
+ const answers = yield inquirer.prompt(questions);
71
+ const database = answers['database'];
72
+ if (database === 'sql') {
73
+ console.error(chalk.red('Error: We are not supporting sql now'));
74
+ process.exit(1);
75
+ }
76
+ console.log(chalk.blue(`Generating NestJS app: ${appName}`));
77
+ // 1. Run nest new
78
+ yield new Promise((resolve, reject) => {
79
+ const child = (0, child_process_1.spawn)('npx', ['@nestjs/cli', 'new', appName], {
80
+ stdio: 'inherit',
81
+ shell: true,
82
+ });
83
+ child.on('close', (code) => {
84
+ if (code === 0)
85
+ resolve();
86
+ else
87
+ reject(new Error(`nest new failed with code ${code}`));
88
+ });
89
+ });
90
+ const appDir = path.join(process.cwd(), appName);
91
+ const pkgManager = fs.existsSync(path.join(appDir, 'yarn.lock')) ? 'yarn' : 'npm';
92
+ const pkg = require('../../package.json');
93
+ const nestExtendedVersion = pkg.version;
94
+ console.log(chalk.blue('Installing additional dependencies...'));
95
+ // 2. Install dependencies
96
+ yield new Promise((resolve, reject) => {
97
+ const installArgs = pkgManager === 'yarn' ? ['add'] : ['install'];
98
+ const child = (0, child_process_1.spawn)(pkgManager, [
99
+ ...installArgs,
100
+ '@nestjs/mongoose',
101
+ 'mongoose',
102
+ '@nestjs/config',
103
+ 'nestjs-cls',
104
+ '@nestjs/jwt',
105
+ 'bcrypt',
106
+ `@nest-extended/core@${nestExtendedVersion}`,
107
+ `@nest-extended/mongoose@${nestExtendedVersion}`,
108
+ `@nest-extended/decorators@${nestExtendedVersion}`,
109
+ 'zod'
110
+ ], {
111
+ stdio: 'inherit',
112
+ cwd: appDir,
113
+ shell: true,
114
+ });
115
+ child.on('close', (code) => {
116
+ if (code === 0)
117
+ resolve();
118
+ else
119
+ reject(new Error(`${pkgManager} install failed with code ${code}`));
120
+ });
121
+ });
122
+ // 3. Install Dev dependencies
123
+ yield new Promise((resolve, reject) => {
124
+ const devArgs = pkgManager === 'yarn' ? ['add', '-D'] : ['install', '-D'];
125
+ const child = (0, child_process_1.spawn)(pkgManager, [...devArgs, '@types/bcrypt'], {
126
+ stdio: 'inherit',
127
+ cwd: appDir,
128
+ shell: true,
129
+ });
130
+ child.on('close', (code) => {
131
+ if (code === 0)
132
+ resolve();
133
+ else
134
+ reject(new Error(`${pkgManager} dev install failed with code ${code}`));
135
+ });
136
+ });
137
+ console.log(chalk.blue('Configuring project...'));
138
+ // 4. Update app.module.ts
139
+ const appModulePath = path.join(appDir, 'src/app.module.ts');
140
+ let appModuleContent = fs.readFileSync(appModulePath, 'utf8');
141
+ const importsToAdd = `
142
+ import { ConfigModule } from '@nestjs/config';
143
+ import { ClsModule } from 'nestjs-cls';
144
+ import { NestExtendedModule } from '@nest-extended/core';
145
+ import { MongooseModule } from '@nestjs/mongoose';
146
+ import { AuthModule } from './services/auth/auth.module';
147
+ import { UsersModule } from './services/users/users.module';
148
+ `;
149
+ appModuleContent = importsToAdd + appModuleContent;
150
+ const nestImports = `
151
+ ConfigModule.forRoot({
152
+ envFilePath: ['.env'],
153
+ isGlobal: true,
154
+ }),
155
+ ClsModule.forRoot({
156
+ global: true,
157
+ middleware: { mount: true },
158
+ }),
159
+ NestExtendedModule.forRoot({
160
+ softDelete: {
161
+ getQuery: () => ({ deleted: { $ne: true } }),
162
+ getData: (user: any) => ({
163
+ deleted: true,
164
+ deletedBy: user?._id,
165
+ deletedAt: new Date(),
166
+ }),
167
+ },
168
+ }),
169
+ MongooseModule.forRoot(process.env.MONGODB_URI || 'mongodb://localhost:27017/test'),
170
+ AuthModule,
171
+ UsersModule,`;
172
+ appModuleContent = appModuleContent.replace(/imports:\s*\[/, `imports: [\n${nestImports}`);
173
+ fs.writeFileSync(appModulePath, appModuleContent);
174
+ // 5. Generate Users Service
175
+ const usersDir = path.join(appDir, 'src/services/users');
176
+ const schemasDir = path.join(appDir, 'src/schemas');
177
+ fs.ensureDirSync(usersDir);
178
+ fs.ensureDirSync(schemasDir);
179
+ fs.writeFileSync(path.join(schemasDir, 'users.schema.ts'), (0, users_template_1.getUsersSchema)());
180
+ fs.writeFileSync(path.join(usersDir, 'users.module.ts'), (0, module_template_1.getModule)('Users', 'users'));
181
+ fs.writeFileSync(path.join(usersDir, 'users.service.ts'), (0, users_template_1.getUsersService)());
182
+ fs.writeFileSync(path.join(usersDir, 'users.controller.ts'), (0, controller_template_1.getController)('Users', 'users', 'users'));
183
+ fs.ensureDirSync(path.join(usersDir, 'dto'));
184
+ fs.writeFileSync(path.join(usersDir, 'dto/users.dto.ts'), (0, dto_template_1.getDto)('Users'));
185
+ // 6. Generate Auth Service
186
+ const authDir = path.join(appDir, 'src/services/auth');
187
+ fs.ensureDirSync(authDir);
188
+ fs.ensureDirSync(path.join(authDir, 'constants'));
189
+ fs.ensureDirSync(path.join(authDir, 'decorators'));
190
+ fs.writeFileSync(path.join(authDir, 'auth.module.ts'), (0, auth_template_1.getAuthModule)());
191
+ fs.writeFileSync(path.join(authDir, 'auth.service.ts'), (0, auth_template_1.getAuthService)());
192
+ fs.writeFileSync(path.join(authDir, 'auth.controller.ts'), (0, auth_template_1.getAuthController)());
193
+ fs.writeFileSync(path.join(authDir, 'auth.guard.ts'), (0, auth_template_1.getAuthGuard)());
194
+ fs.writeFileSync(path.join(authDir, 'constants/jwt-constants.ts'), (0, auth_template_1.getJwtConstants)());
195
+ fs.writeFileSync(path.join(authDir, 'decorators/public.decorator.ts'), (0, auth_template_1.getPublicDecorator)());
196
+ console.log(chalk.blue('Running lint...'));
197
+ yield new Promise((resolve) => {
198
+ const lintChild = (0, child_process_1.spawn)(pkgManager, ['run', 'lint'], {
199
+ stdio: 'inherit',
200
+ cwd: appDir,
201
+ shell: true,
202
+ });
203
+ lintChild.on('close', () => resolve());
204
+ });
205
+ console.log(chalk.green('App generated successfully!'));
38
206
  }));
39
207
  //# sourceMappingURL=generate.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../../../packages/cli/src/commands/generate.ts"],"names":[],"mappings":";;;;AACA,yCAAoC;AACpC,oDAA2D;AAC3D,gEAA2D;AAC3D,kEAAyD;AACzD,oEAA2D;AAC3D,0EAAiE;AACjE,4DAAmD;AACnD,kEAAyD;AACzD,8EAAoE;AACpE,oFAA0E;AAE7D,QAAA,eAAe,GAAG,IAAI,mBAAO,CAAC,UAAU,CAAC;KACjD,KAAK,CAAC,GAAG,CAAC;KACV,WAAW,CAAC,wBAAwB,CAAC,CAAC;AAE3C,uBAAe;KACV,OAAO,CAAC,gBAAgB,CAAC;KACzB,WAAW,CAAC,wBAAwB,CAAC;KACrC,MAAM,CAAC,CAAO,OAAe,EAAE,EAAE;IAC9B,qEAAqE;I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GAAE,CAAC,CAAC;IACtF,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,gCAAgC,CAAC,EAAE,IAAA,kCAAkB,GAAE,CAAC,CAAC;IAE7F,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAC3C,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;QAChC,MAAM,SAAS,GAAG,IAAA,qBAAK,EAAC,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE;YACjD,KAAK,EAAE,SAAS;YAChB,GAAG,EAAE,MAAM;YACX,KAAK,EAAE,IAAI;SACd,CAAC,CAAC;QACH,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAC,CAAC;AAC5D,CAAC,CAAA,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { Command } from 'commander';
2
+ export declare const migrationCommand: Command;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.migrationCommand = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const commander_1 = require("commander");
6
+ const fs = require("fs-extra");
7
+ const path = require("path");
8
+ const glob_1 = require("glob");
9
+ exports.migrationCommand = new commander_1.Command('migration')
10
+ .alias('m')
11
+ .description('Migrate project to newer version');
12
+ exports.migrationCommand
13
+ .command('run')
14
+ .description('Run migration scripts')
15
+ .action(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
16
+ console.log('Running migration...');
17
+ const files = yield (0, glob_1.glob)('src/**/*.ts', { ignore: ['node_modules/**'] });
18
+ let updateCount = 0;
19
+ for (const file of files) {
20
+ const filePath = path.resolve(file);
21
+ let content = yield fs.readFile(filePath, 'utf-8');
22
+ let hasChanges = false;
23
+ // Check for imports from @nest-extended/core
24
+ if (content.includes('@nest-extended/core')) {
25
+ // Regex to find named imports from @nest-extended/core
26
+ const importRegex = /import\s+{([^}]+)}\s+from\s+['"]@nest-extended\/core['"];?/g;
27
+ content = content.replace(importRegex, (match, imports) => {
28
+ const importedItems = imports.split(',').map((item) => item.trim());
29
+ const decoratorsToMove = ['ModifyBody', 'User', 'Public', 'setCreatedBy'];
30
+ const movedItems = importedItems.filter((item) => decoratorsToMove.includes(item));
31
+ const remainingItems = importedItems.filter((item) => !decoratorsToMove.includes(item));
32
+ if (movedItems.length > 0) {
33
+ hasChanges = true;
34
+ const parts = [];
35
+ if (remainingItems.length > 0) {
36
+ parts.push(`import { ${remainingItems.join(', ')} } from '@nest-extended/core';`);
37
+ }
38
+ parts.push(`import { ${movedItems.join(', ')} } from '@nest-extended/decorators';`);
39
+ return parts.join('\n');
40
+ }
41
+ return match;
42
+ });
43
+ }
44
+ if (hasChanges) {
45
+ yield fs.writeFile(filePath, content, 'utf-8');
46
+ console.log(`Updated ${file}`);
47
+ updateCount++;
48
+ }
49
+ }
50
+ console.log(`Migration completed. Updated ${updateCount} files.`);
51
+ }));
52
+ //# sourceMappingURL=migration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration.js","sourceRoot":"","sources":["../../../../../packages/cli/src/commands/migration.ts"],"names":[],"mappings":";;;;AAAA,yCAAoC;AACpC,+BAA+B;AAC/B,6BAA6B;AAC7B,+BAA4B;AAEf,QAAA,gBAAgB,GAAG,IAAI,mBAAO,CAAC,WAAW,CAAC;KACnD,KAAK,CAAC,GAAG,CAAC;KACV,WAAW,CAAC,kCAAkC,CAAC,CAAC;AAErD,wBAAgB;KACX,OAAO,CAAC,KAAK,CAAC;KACd,WAAW,CAAC,uBAAuB,CAAC;KACpC,MAAM,CAAC,GAAS,EAAE;IACf,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;IACpC,MAAM,KA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AC;oBAEjB,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;wBAC5B,KAAK,CAAC,IAAI,CAAC,YAAY,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAC;oBACtF,CAAC;oBAED,KAAK,CAAC,IAAI,CAAC,YAAY,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,sCAAsC,CAAC,CAAC;oBAEpF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBAC5B,CAAC;gBAED,OAAO,KAAK,CAAC;YACjB,CAAC,CAAC,CAAC;QACP,CAAC;QAED,IAAI,UAAU,EAAE,CAAC;YACb,MAAM,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;YAC/C,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC;YAC/B,WAAW,EAAE,CAAC;QAClB,CAAC;IACL,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,gCAAgC,WAAW,SAAS,CAAC,CAAC;AACtE,CAAC,CAAA,CAAC,CAAC"}
package/src/index.js CHANGED
@@ -3,11 +3,53 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const commander_1 = require("commander");
5
5
  const generate_1 = require("./commands/generate");
6
+ const migration_1 = require("./commands/migration");
6
7
  const program = new commander_1.Command();
8
+ const chalk = require("chalk");
9
+ const pkg = require('../package.json');
7
10
  program
8
- .name('nestx-cli')
11
+ .name('nest-cli')
9
12
  .description('CLI for @nest-extended packages')
10
- .version('0.0.1');
13
+ .version(pkg.version);
14
+ program.command('version')
15
+ .alias('v')
16
+ .description('Output the version number')
17
+ .action(() => {
18
+ console.log(pkg.version);
19
+ });
11
20
  program.addCommand(generate_1.generateCommand);
21
+ program.addCommand(migration_1.migrationCommand);
22
+ program.command('help')
23
+ .description('display comprehensive help for all commands')
24
+ .action(() => {
25
+ console.log('');
26
+ console.log(chalk.bold.cyan('🪹 NestExtended CLI'));
27
+ console.log(chalk.gray(' A powerful command-line interface for the NestExtended ecosystem.'));
28
+ console.log('');
29
+ console.log(`${chalk.bold('USAGE')}`);
30
+ console.log(` $ ${chalk.green('nest-cli')} ${chalk.yellow('[command]')} ${chalk.cyan('[options]')}`);
31
+ console.log('');
32
+ console.log(`${chalk.bold('COMMANDS')}`);
33
+ program.commands.forEach((cmd) => {
34
+ if (cmd.name() === 'help')
35
+ return;
36
+ const aliases = cmd.alias() ? ` | ${cmd.alias()}` : '';
37
+ console.log(` ${chalk.green.bold(cmd.name())}${chalk.gray(aliases)}`);
38
+ console.log(` ${chalk.white(cmd.description())}`);
39
+ if (cmd.commands && cmd.commands.length > 0) {
40
+ console.log('');
41
+ cmd.commands.forEach((sub) => {
42
+ const args = sub.registeredArguments.map(arg => arg.required ? `<${arg.name()}>` : `[${arg.name()}]`).join(' ');
43
+ console.log(` ${chalk.cyan('nest-cli')} ${chalk.cyan(cmd.name())} ${chalk.green(sub.name())} ${chalk.yellow(args)}`);
44
+ console.log(` ${chalk.gray('└─')} ${sub.description()}`);
45
+ });
46
+ }
47
+ console.log(''); // spacer
48
+ });
49
+ console.log(`${chalk.bold('OPTIONS')}`);
50
+ console.log(` ${chalk.cyan('-V, --version')} Output the version number`);
51
+ console.log(` ${chalk.cyan('-h, --help')} Display help for command`);
52
+ console.log('');
53
+ });
12
54
  program.parse(process.argv);
13
55
  //# sourceMappingURL=index.js.map
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/cli/src/index.ts"],"names":[],"mappings":";;;AACA,yCAAoC;AACpC,kDAAsD;AAEtD,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAE9B,OAAO;KACF,IAAI,CAAC,WAAW,CAAC;KACjB,WAAW,CAAC,iCAAiC,CAAC;KAC9C,OAAO,CAAC,OAAO,CAAC,CAAC;AAEtB,OAAO,CAAC,UAAU,CAAC,0BAAe,C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AAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBAChH,OAAO,CAAC,GAAG,CAAC,OAAO,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBACxH,OAAO,CAAC,GAAG,CAAC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;YAChE,CAAC,CAAC,CAAC;QACP,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS;IAC9B,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IACxC,OAAO,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,+BAA+B,CAAC,CAAC;IAC7E,OAAO,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,iCAAiC,CAAC,CAAC;IAC5E,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC;AAEP,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ export declare const getAuthController: () => string;
2
+ export declare const getAuthService: () => string;
3
+ export declare const getAuthModule: () => string;
4
+ export declare const getAuthGuard: () => string;
5
+ export declare const getPublicDecorator: () => string;
6
+ export declare const getJwtConstants: () => string;
@@ -0,0 +1,191 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getJwtConstants = exports.getPublicDecorator = exports.getAuthGuard = exports.getAuthModule = exports.getAuthService = exports.getAuthController = void 0;
4
+ const getAuthController = () => `import {
5
+ Body,
6
+ Controller,
7
+ Post,
8
+ HttpCode,
9
+ HttpStatus,
10
+ Get,
11
+ Request,
12
+ BadRequestException,
13
+ } from '@nestjs/common';
14
+ import { AuthService } from './auth.service';
15
+ import { Public } from './decorators/public.decorator';
16
+ import { UsersService } from '../users/users.service';
17
+
18
+ @Controller('authentication')
19
+ export class AuthController {
20
+ constructor(
21
+ private authService: AuthService,
22
+ private usersService: UsersService,
23
+ ) {}
24
+
25
+ @Public()
26
+ @HttpCode(HttpStatus.OK)
27
+ @Post('')
28
+ signIn(@Body() signInDto: Record<string, any>) {
29
+ if (signInDto.strategy === 'local') {
30
+ return this.authService.signInLocal(signInDto.email, signInDto.password);
31
+ }
32
+ throw new BadRequestException('Invalid Strategy');
33
+ }
34
+
35
+ @Get('verify')
36
+ getProfile(@Request() req: any) {
37
+ return {
38
+ user: this.usersService.sanitizeUser(req.user),
39
+ organizationUsers: req.orgUsers,
40
+ };
41
+ }
42
+ }
43
+ `;
44
+ exports.getAuthController = getAuthController;
45
+ const getAuthService = () => `import { Injectable, UnauthorizedException } from '@nestjs/common';
46
+ import { JwtService } from '@nestjs/jwt';
47
+ import * as bcrypt from 'bcrypt';
48
+ import { UsersService } from '../users/users.service';
49
+
50
+ @Injectable()
51
+ export class AuthService {
52
+ constructor(
53
+ private usersService: UsersService,
54
+ private jwtService: JwtService,
55
+ ) { }
56
+
57
+ async signInLocal(email: string, pass: string): Promise<any> {
58
+ const [user] = await this.usersService._find({
59
+ email,
60
+ $limit: 1,
61
+ $select: [
62
+ '_id',
63
+ 'firstName',
64
+ 'lastName',
65
+ 'email',
66
+ 'password',
67
+ 'createdAt',
68
+ 'updatedAt',
69
+ ],
70
+ }, { pagination: false });
71
+
72
+ if (!user) throw new UnauthorizedException();
73
+
74
+ const passwordValid = await bcrypt.compare(pass, user.password);
75
+ if (!passwordValid) {
76
+ throw new UnauthorizedException();
77
+ }
78
+
79
+ const sanitizedUser = this.usersService.sanitizeUser(user);
80
+ const payload = { sub: { id: user._id }, user };
81
+ return {
82
+ accessToken: await this.jwtService.signAsync(payload),
83
+ user: sanitizedUser,
84
+ };
85
+ }
86
+ }
87
+ `;
88
+ exports.getAuthService = getAuthService;
89
+ const getAuthModule = () => `import { Module } from '@nestjs/common';
90
+ import { AuthService } from './auth.service';
91
+ import { JwtModule } from '@nestjs/jwt';
92
+ import { AuthController } from './auth.controller';
93
+ import { APP_GUARD } from '@nestjs/core';
94
+ import { AuthGuard } from './auth.guard';
95
+ import { UsersModule } from '../users/users.module';
96
+ import { jwtConstants } from './constants/jwt-constants';
97
+
98
+ @Module({
99
+ imports: [
100
+ UsersModule,
101
+ JwtModule.register({
102
+ global: true,
103
+ secret: jwtConstants.secret,
104
+ signOptions: { expiresIn: '365d' },
105
+ }),
106
+ ],
107
+ providers: [
108
+ AuthService,
109
+ {
110
+ provide: APP_GUARD,
111
+ useClass: AuthGuard,
112
+ },
113
+ ],
114
+ controllers: [AuthController],
115
+ exports: [AuthService],
116
+ })
117
+ export class AuthModule {}
118
+ `;
119
+ exports.getAuthModule = getAuthModule;
120
+ const getAuthGuard = () => `import {
121
+ CanActivate,
122
+ ExecutionContext,
123
+ Injectable,
124
+ UnauthorizedException,
125
+ } from '@nestjs/common';
126
+ import { Reflector } from '@nestjs/core';
127
+ import { JwtService } from '@nestjs/jwt';
128
+ import { Request } from 'express';
129
+ import { IS_PUBLIC_KEY } from './decorators/public.decorator';
130
+ import { UsersService } from '../users/users.service';
131
+ import { jwtConstants } from './constants/jwt-constants';
132
+ import { ClsService } from 'nestjs-cls';
133
+
134
+ @Injectable()
135
+ export class AuthGuard implements CanActivate {
136
+ constructor(
137
+ private usersService: UsersService,
138
+ private jwtService: JwtService,
139
+ private reflector: Reflector,
140
+ private cls: ClsService,
141
+ ) {}
142
+
143
+ async canActivate(context: ExecutionContext): Promise<boolean> {
144
+ const isPublic = this.reflector.getAllAndOverride<boolean>(IS_PUBLIC_KEY, [
145
+ context.getHandler(),
146
+ context.getClass(),
147
+ ]);
148
+ if (isPublic) {
149
+ return true;
150
+ }
151
+ const request = context.switchToHttp().getRequest();
152
+ const token = this.extractTokenFromHeader(request as Request);
153
+ if (!token) {
154
+ throw new UnauthorizedException();
155
+ }
156
+ try {
157
+ const payload = await this.jwtService.verifyAsync(token, {
158
+ secret: jwtConstants.secret,
159
+ });
160
+ const user = await this.usersService._get(payload.sub.id);
161
+ if (user) {
162
+ request['user'] = user;
163
+ this.cls.set('user', user);
164
+ return true;
165
+ }
166
+ } catch {
167
+ throw new UnauthorizedException();
168
+ }
169
+ throw new UnauthorizedException();
170
+ }
171
+
172
+ private extractTokenFromHeader(request: Request): string | undefined {
173
+ const [type, token] = request.headers.authorization?.split(' ') ?? [];
174
+ return type === 'Bearer' ? token : undefined;
175
+ }
176
+ }
177
+ `;
178
+ exports.getAuthGuard = getAuthGuard;
179
+ const getPublicDecorator = () => `import { SetMetadata } from '@nestjs/common';
180
+ export const IS_PUBLIC_KEY = 'isPublic';
181
+ export const Public = () => SetMetadata(IS_PUBLIC_KEY, true);
182
+ `;
183
+ exports.getPublicDecorator = getPublicDecorator;
184
+ const getJwtConstants = () => `import { randomBytes } from 'crypto';
185
+ // NOTE: For a real application, consider using a more secure way to inject the secret (like ConfigService)
186
+ export const jwtConstants = {
187
+ secret: process.env.JWT_SECRET || randomBytes(32).toString('hex'),
188
+ };
189
+ `;
190
+ exports.getJwtConstants = getJwtConstants;
191
+ //# sourceMappingURL=auth.template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.template.js","sourceRoot":"","sources":["../../../../../packages/cli/src/templates/auth.template.ts"],"names":[],"mappings":";;;AAAO,MAAM,iBAAiB,GAAG,GAAW,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuC9C,CAAC;AAvCW,QAAA,iBAAiB,qBAuC5B;AAEK,MAAM,cAAc,GAAG,GAAW,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0C3C,CAAC;AA1CW,QAAA,cAAc,kBA0CzB;AAEK,MAAM,aAAa,GAAG,GAAW,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6B1C,CAAC;AA7BW,QAAA,aAAa,iBA6BxB;AAEK,MAAM,YAAY,GAAG,GAAW,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyDzC,CAAC;AAzDW,QAAA,YAAY,gBAyDvB;AAEK,MAAM,kBAAkB,GAAG,GAAW,EAAE,CAAC;;;CAG/C,CAAC;AAHW,QAAA,kBAAkB,sBAG7B;AAEK,MAAM,eAAe,GAAG,GAAW,EAAE,CAAC;;;;;CAK5C,CAAC;AALW,QAAA,eAAe,mBAK1B"}
@@ -12,9 +12,8 @@ const getController = (Name, name, url) => `import {
12
12
  Query,
13
13
  } from '@nestjs/common';
14
14
  import { ${Name}Service } from './${name}.service';
15
- import { User } from '@nest-extended/core';
15
+ import { User, ModifyBody, setCreatedBy } from '@nest-extended/decorators';
16
16
  import { ${Name} } from 'src/schemas/${name}.schema';
17
- import { ModifyBody, setCreatedBy } from '@nest-extended/core';
18
17
 
19
18
  @Controller('${url}')
20
19
  export class ${Name}Controller {
@@ -25,7 +24,7 @@ export class ${Name}Controller {
25
24
  return await this.${name}Service._find(query);
26
25
  }
27
26
 
28
- @Get('/:id?')
27
+ @Get('/:id')
29
28
  async get(@Query() query: Record<string, any>, @Param('id') id: string) {
30
29
  return await this.${name}Service._get(id, query);
31
30
  }
@@ -37,7 +36,7 @@ export class ${Name}Controller {
37
36
  return await this.${name}Service._create(create${Name}Dto);
38
37
  }
39
38
 
40
- @Patch('/:id?')
39
+ @Patch('/:id')
41
40
  async patch(
42
41
  @Query() query,
43
42
  @Body() patch${Name}Dto: Partial<${Name}>,
@@ -46,7 +45,7 @@ export class ${Name}Controller {
46
45
  return await this.${name}Service._patch(id, patch${Name}Dto, query);
47
46
  }
48
47
 
49
- @Delete('/:id?')
48
+ @Delete('/:id')
50
49
  async delete(@Param('id') id, @Query() query, @User() user) {
51
50
  return await this.${name}Service._remove(id, query, user);
52
51
  }
@@ -1 +1 @@
1
- {"version":3,"file":"controller.template.js","sourceRoot":"","sources":["../../../../../packages/cli/src/templates/controller.template.ts"],"names":[],"mappings":";;;AACO,MAAM,aAAa,GAAG,CAAC,IAAY,EAAE,IAAY,EAAE,GAAW,EAAU,EAAE,CAAC;;;;;;;;;;WAUvE,IAAI,qBAAqB,IAAI;;WAE7B,IAAI,wBAAwB,IAAI;;;eAG5B,GAAG;eACH,IAAI;iCACc,IAAI,YAAY,IAAI;;;;wBAI7B,IAAI;;;;;wBAKJ,IAAI;;;;;wCAKY,IAAI,QAAQ,IAAI;;wBAEhC,IAAI,yBAAyB,IAAI;;;;;;mBAMtC,IAAI,gBAAgB,IAAI;;;wBAGnB,IAAI,2BAA2B,IAAI;;;;;wBAKnC,IAAI;;;CAG3B,CAAC;AAlDW,QAAA,aAAa,iBAkDxB"}
1
+ {"version":3,"file":"controller.template.js","sourceRoot":"","sources":["../../../../../packages/cli/src/templates/controller.template.ts"],"names":[],"mappings":";;;AACO,MAAM,aAAa,GAAG,CAAC,IAAY,EAAE,IAAY,EAAE,GAAW,EAAU,EAAE,CAAC;;;;;;;;;;WAUvE,IAAI,qBAAqB,IAAI;;WAE7B,IAAI,wBAAwB,IAAI;;eAE5B,GAAG;eACH,IAAI;iCACc,IAAI,YAAY,IAAI;;;;wBAI7B,IAAI;;;;;wBAKJ,IAAI;;;;;wCAKY,IAAI,QAAQ,IAAI;;wBAEhC,IAAI,yBAAyB,IAAI;;;;;;mBAMtC,IAAI,gBAAgB,IAAI;;;wBAGnB,IAAI,2BAA2B,IAAI;;;;;wBAKnC,IAAI;;;CAG3B,CAAC;AAjDW,QAAA,aAAa,iBAiDxB"}
@@ -4,7 +4,7 @@ exports.getSchema = void 0;
4
4
  const getSchema = (Name, UserEntity = 'Users') => `import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
5
5
  import { HydratedDocument, Types } from 'mongoose';
6
6
  import { ${UserEntity} } from './users.schema';
7
- import EnsureObjectId from '@nest-extended/core/common/ensureObjectId';
7
+ import { EnsureObjectId } from '@nest-extended/mongoose';
8
8
 
9
9
  export type ${Name}Document = HydratedDocument<${Name}>;
10
10
 
@@ -0,0 +1,2 @@
1
+ export declare const getUsersSchema: () => string;
2
+ export declare const getUsersService: () => string;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getUsersService = exports.getUsersSchema = void 0;
4
+ const getUsersSchema = () => `import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
5
+ import { HydratedDocument, Types } from 'mongoose';
6
+
7
+ export type UsersDocument = HydratedDocument<Users>;
8
+
9
+ @Schema({
10
+ timestamps: true,
11
+ })
12
+ export class Users {
13
+ _id: Types.ObjectId;
14
+
15
+ @Prop({ type: String, trim: true, required: true })
16
+ firstName: string;
17
+
18
+ @Prop({ type: String, trim: true, required: true })
19
+ lastName: string;
20
+
21
+ @Prop({ type: String, trim: true, unique: true, required: true })
22
+ email: string;
23
+
24
+ @Prop({ type: String, required: true, select: false })
25
+ password: string;
26
+
27
+ @Prop({ type: String, trim: true, required: false })
28
+ phone?: string;
29
+
30
+ @Prop({ type: Number, enum: [1, 2, 3], default: 1 })
31
+ role: number;
32
+ }
33
+
34
+ export const UsersSchema = SchemaFactory.createForClass(Users);
35
+ `;
36
+ exports.getUsersSchema = getUsersSchema;
37
+ const getUsersService = () => `import { Model } from 'mongoose';
38
+ import { Injectable } from '@nestjs/common';
39
+ import { InjectModel } from '@nestjs/mongoose';
40
+ import { NestService } from '@nest-extended/mongoose';
41
+ import { Users, UsersDocument } from 'src/schemas/users.schema';
42
+
43
+ @Injectable()
44
+ export class UsersService extends NestService<Users, UsersDocument> {
45
+ constructor(
46
+ @InjectModel(Users.name) private readonly usersModel: Model<UsersDocument>,
47
+ ) {
48
+ super(usersModel);
49
+ }
50
+
51
+ sanitizeUser(user: Users) {
52
+ // @ts-expect-error can be error
53
+ const sanitized = user.toObject ? user.toObject() : { ...user };
54
+ delete sanitized['password'];
55
+ return sanitized;
56
+ }
57
+ }
58
+ `;
59
+ exports.getUsersService = getUsersService;
60
+ //# sourceMappingURL=users.template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"users.template.js","sourceRoot":"","sources":["../../../../../packages/cli/src/templates/users.template.ts"],"names":[],"mappings":";;;AAAO,MAAM,cAAc,GAAG,GAAW,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+B3C,CAAC;AA/BW,QAAA,cAAc,kBA+BzB;AAEK,MAAM,eAAe,GAAG,GAAW,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;CAqB5C,CAAC;AArBW,QAAA,eAAe,mBAqB1B"}