add-nest-auth 1.2.0 → 1.3.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/dist/cli.js +62 -4
- package/dist/cli.js.map +1 -1
- package/dist/generator/templates/dto/auth-response.dto.ts.hbs +12 -1
- package/dist/generator/templates/dto/change-password.dto.ts.hbs +22 -0
- package/dist/generator/templates/dto/create-user.dto.ts.hbs +10 -1
- package/dist/generator/templates/dto/forgot-password.dto.ts.hbs +13 -0
- package/dist/generator/templates/dto/register.dto.ts.hbs +11 -0
- package/dist/generator/templates/dto/reset-password.dto.ts.hbs +22 -0
- package/dist/generator/templates/entities/user.entity.typeorm.hbs +21 -0
- package/dist/generator/templates/jwt/auth.controller.ts.hbs +90 -2
- package/dist/generator/templates/jwt/auth.service.ts.hbs +137 -1
- package/dist/generator/templates/prisma/schema.prisma.additions.hbs +11 -0
- package/dist/generator/templates/tests/auth.controller.spec.ts.hbs +189 -0
- package/dist/generator/templates/tests/auth.service.spec.ts.hbs +330 -0
- package/dist/generator/templates/users/users.controller.ts.hbs +6 -0
- package/dist/generator/templates/users/users.service.ts.hbs +106 -62
- package/dist/index.js +62 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -298,6 +298,30 @@ async function promptConfig(detectedORM, detectedDB) {
|
|
|
298
298
|
message: "Enable Swagger API documentation? (recommended)",
|
|
299
299
|
default: true
|
|
300
300
|
},
|
|
301
|
+
{
|
|
302
|
+
type: "confirm",
|
|
303
|
+
name: "generateTests",
|
|
304
|
+
message: "Generate unit tests? (recommended)",
|
|
305
|
+
default: true
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
type: "confirm",
|
|
309
|
+
name: "useUsername",
|
|
310
|
+
message: "Add username field to user?",
|
|
311
|
+
default: false
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
type: "confirm",
|
|
315
|
+
name: "enableEmailVerification",
|
|
316
|
+
message: "Enable email verification?",
|
|
317
|
+
default: false
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
type: "confirm",
|
|
321
|
+
name: "enableResetPassword",
|
|
322
|
+
message: "Enable forgot/reset password?",
|
|
323
|
+
default: true
|
|
324
|
+
},
|
|
301
325
|
{
|
|
302
326
|
type: "confirm",
|
|
303
327
|
name: "useDetectedORM",
|
|
@@ -337,6 +361,10 @@ function getDefaultAnswers(detectedORM, detectedDB) {
|
|
|
337
361
|
refreshExpiration: "7d",
|
|
338
362
|
enableRateLimiting: true,
|
|
339
363
|
enableSwagger: true,
|
|
364
|
+
generateTests: true,
|
|
365
|
+
useUsername: false,
|
|
366
|
+
enableEmailVerification: false,
|
|
367
|
+
enableResetPassword: true,
|
|
340
368
|
useDetectedORM: true,
|
|
341
369
|
database: detectedDB || "postgres",
|
|
342
370
|
autoInstall: true
|
|
@@ -356,7 +384,11 @@ function buildConfig(answers, projectName, sourceRoot, detectedORM, detectedDB)
|
|
|
356
384
|
features: {
|
|
357
385
|
refreshTokens: answers.refreshTokens,
|
|
358
386
|
rateLimiting: answers.enableRateLimiting,
|
|
359
|
-
swagger: answers.enableSwagger
|
|
387
|
+
swagger: answers.enableSwagger,
|
|
388
|
+
unitTests: answers.generateTests,
|
|
389
|
+
useUsername: answers.useUsername,
|
|
390
|
+
emailVerification: answers.enableEmailVerification,
|
|
391
|
+
resetPassword: answers.enableResetPassword
|
|
360
392
|
},
|
|
361
393
|
jwt: {
|
|
362
394
|
secret: generateSecret(),
|
|
@@ -365,7 +397,7 @@ function buildConfig(answers, projectName, sourceRoot, detectedORM, detectedDB)
|
|
|
365
397
|
},
|
|
366
398
|
autoInstall: answers.autoInstall,
|
|
367
399
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
368
|
-
generatorVersion: "1.
|
|
400
|
+
generatorVersion: "1.3.0"
|
|
369
401
|
};
|
|
370
402
|
return config;
|
|
371
403
|
}
|
|
@@ -476,6 +508,15 @@ function showSuccess(stats) {
|
|
|
476
508
|
console.log(import_chalk.default.cyan(" 4. Test authentication endpoints"));
|
|
477
509
|
console.log(import_chalk.default.gray(" POST http://localhost:3000/auth/register"));
|
|
478
510
|
console.log(import_chalk.default.gray(" POST http://localhost:3000/auth/login"));
|
|
511
|
+
console.log(import_chalk.default.gray(" POST http://localhost:3000/auth/change-password (requires JWT)"));
|
|
512
|
+
if (stats.emailVerification) {
|
|
513
|
+
console.log(import_chalk.default.gray(" GET http://localhost:3000/auth/verify-email?token=..."));
|
|
514
|
+
console.log(import_chalk.default.gray(" POST http://localhost:3000/auth/resend-verification"));
|
|
515
|
+
}
|
|
516
|
+
if (stats.resetPassword) {
|
|
517
|
+
console.log(import_chalk.default.gray(" POST http://localhost:3000/auth/forgot-password"));
|
|
518
|
+
console.log(import_chalk.default.gray(" POST http://localhost:3000/auth/reset-password"));
|
|
519
|
+
}
|
|
479
520
|
console.log(import_chalk.default.gray(" POST http://localhost:3000/auth/refresh"));
|
|
480
521
|
console.log(import_chalk.default.gray(" POST http://localhost:3000/auth/logout (requires JWT)"));
|
|
481
522
|
console.log(import_chalk.default.gray(" POST http://localhost:3000/auth/logout-all (requires JWT)"));
|
|
@@ -540,6 +581,8 @@ var init_template_engine = __esm({
|
|
|
540
581
|
registerHelpers() {
|
|
541
582
|
this.handlebars.registerHelper("eq", (a, b) => a === b);
|
|
542
583
|
this.handlebars.registerHelper("ne", (a, b) => a !== b);
|
|
584
|
+
this.handlebars.registerHelper("or", (a, b) => a || b);
|
|
585
|
+
this.handlebars.registerHelper("and", (a, b) => a && b);
|
|
543
586
|
this.handlebars.registerHelper("includes", (arr, item) => arr?.includes(item));
|
|
544
587
|
this.handlebars.registerHelper("capitalize", (str) => {
|
|
545
588
|
if (!str) return "";
|
|
@@ -779,9 +822,16 @@ var init_generator = __esm({
|
|
|
779
822
|
plan.push(
|
|
780
823
|
{ template: "dto/login.dto.ts.hbs", output: `${config.sourceRoot}/auth/dto/login.dto.ts` },
|
|
781
824
|
{ template: "dto/register.dto.ts.hbs", output: `${config.sourceRoot}/auth/dto/register.dto.ts` },
|
|
825
|
+
{ template: "dto/change-password.dto.ts.hbs", output: `${config.sourceRoot}/auth/dto/change-password.dto.ts` },
|
|
782
826
|
{ template: "dto/auth-response.dto.ts.hbs", output: `${config.sourceRoot}/auth/dto/auth-response.dto.ts` },
|
|
783
827
|
{ template: "dto/create-user.dto.ts.hbs", output: `${config.sourceRoot}/auth/dto/create-user.dto.ts` }
|
|
784
828
|
);
|
|
829
|
+
if (config.features.resetPassword) {
|
|
830
|
+
plan.push(
|
|
831
|
+
{ template: "dto/forgot-password.dto.ts.hbs", output: `${config.sourceRoot}/auth/dto/forgot-password.dto.ts` },
|
|
832
|
+
{ template: "dto/reset-password.dto.ts.hbs", output: `${config.sourceRoot}/auth/dto/reset-password.dto.ts` }
|
|
833
|
+
);
|
|
834
|
+
}
|
|
785
835
|
plan.push(
|
|
786
836
|
{ template: "users/users.module.ts.hbs", output: `${config.sourceRoot}/users/users.module.ts` },
|
|
787
837
|
{ template: "users/users.service.ts.hbs", output: `${config.sourceRoot}/users/users.service.ts` },
|
|
@@ -804,6 +854,12 @@ var init_generator = __esm({
|
|
|
804
854
|
{ template: "prisma/schema.prisma.additions.hbs", output: "prisma-schema-additions.prisma" }
|
|
805
855
|
);
|
|
806
856
|
}
|
|
857
|
+
if (config.features.unitTests) {
|
|
858
|
+
plan.push(
|
|
859
|
+
{ template: "tests/auth.service.spec.ts.hbs", output: `${config.sourceRoot}/auth/auth.service.spec.ts` },
|
|
860
|
+
{ template: "tests/auth.controller.spec.ts.hbs", output: `${config.sourceRoot}/auth/auth.controller.spec.ts` }
|
|
861
|
+
);
|
|
862
|
+
}
|
|
807
863
|
plan.push(
|
|
808
864
|
{ template: "shared/env.template.hbs", output: ".env.example" },
|
|
809
865
|
{ template: "shared/env.hbs", output: ".env" },
|
|
@@ -1300,7 +1356,7 @@ var init_package_updater = __esm({
|
|
|
1300
1356
|
dependencies["@nestjs/throttler"] = "^6.0.0";
|
|
1301
1357
|
}
|
|
1302
1358
|
if (config.features.swagger) {
|
|
1303
|
-
dependencies["@nestjs/swagger"] = "^
|
|
1359
|
+
dependencies["@nestjs/swagger"] = "^11.0.0";
|
|
1304
1360
|
}
|
|
1305
1361
|
return { dependencies, devDependencies };
|
|
1306
1362
|
}
|
|
@@ -1525,7 +1581,9 @@ async function run(cwd = process.cwd(), options = {}) {
|
|
|
1525
1581
|
refreshExpiration: config.features.refreshTokens ? config.jwt.refreshExpiration : void 0
|
|
1526
1582
|
},
|
|
1527
1583
|
orm: config.orm,
|
|
1528
|
-
swagger: config.features.swagger
|
|
1584
|
+
swagger: config.features.swagger,
|
|
1585
|
+
emailVerification: config.features.emailVerification,
|
|
1586
|
+
resetPassword: config.features.resetPassword
|
|
1529
1587
|
});
|
|
1530
1588
|
console.log("\u{1F41B} Issues? https://github.com/Islamawad132/add-nest-auth/issues");
|
|
1531
1589
|
console.log("\u2B50 Like it? https://github.com/Islamawad132/add-nest-auth");
|