@anarchitects/auth-nest 0.0.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 (101) hide show
  1. package/README.md +88 -0
  2. package/package.json +60 -0
  3. package/src/application/application.module-definition.d.ts +25 -0
  4. package/src/application/application.module-definition.js +13 -0
  5. package/src/application/application.module-definition.js.map +1 -0
  6. package/src/application/application.module.d.ts +27 -0
  7. package/src/application/application.module.js +73 -0
  8. package/src/application/application.module.js.map +1 -0
  9. package/src/application/factories/ability.factory.d.ts +6 -0
  10. package/src/application/factories/ability.factory.js +34 -0
  11. package/src/application/factories/ability.factory.js.map +1 -0
  12. package/src/application/index.d.ts +8 -0
  13. package/src/application/index.js +12 -0
  14. package/src/application/index.js.map +1 -0
  15. package/src/application/services/auth.service.d.ts +32 -0
  16. package/src/application/services/auth.service.js +12 -0
  17. package/src/application/services/auth.service.js.map +1 -0
  18. package/src/application/services/bcrypt-hash.service.d.ts +5 -0
  19. package/src/application/services/bcrypt-hash.service.js +20 -0
  20. package/src/application/services/bcrypt-hash.service.js.map +1 -0
  21. package/src/application/services/hash.service.d.ts +4 -0
  22. package/src/application/services/hash.service.js +12 -0
  23. package/src/application/services/hash.service.js.map +1 -0
  24. package/src/application/services/jwt-auth.service.d.ts +41 -0
  25. package/src/application/services/jwt-auth.service.js +220 -0
  26. package/src/application/services/jwt-auth.service.js.map +1 -0
  27. package/src/application/services/policies.service.d.ts +10 -0
  28. package/src/application/services/policies.service.js +42 -0
  29. package/src/application/services/policies.service.js.map +1 -0
  30. package/src/application/strategies/jwt/strategy.d.ts +16 -0
  31. package/src/application/strategies/jwt/strategy.js +25 -0
  32. package/src/application/strategies/jwt/strategy.js.map +1 -0
  33. package/src/config/auth.config.d.ts +18 -0
  34. package/src/config/auth.config.js +17 -0
  35. package/src/config/auth.config.js.map +1 -0
  36. package/src/config/index.d.ts +1 -0
  37. package/src/config/index.js +5 -0
  38. package/src/config/index.js.map +1 -0
  39. package/src/index.d.ts +5 -0
  40. package/src/index.js +9 -0
  41. package/src/index.js.map +1 -0
  42. package/src/infrastructure-mailer/adapters/mailer.adapter.d.ts +4 -0
  43. package/src/infrastructure-mailer/adapters/mailer.adapter.js +7 -0
  44. package/src/infrastructure-mailer/adapters/mailer.adapter.js.map +1 -0
  45. package/src/infrastructure-mailer/adapters/node-mailer.adapter.d.ts +8 -0
  46. package/src/infrastructure-mailer/adapters/node-mailer.adapter.js +23 -0
  47. package/src/infrastructure-mailer/adapters/node-mailer.adapter.js.map +1 -0
  48. package/src/infrastructure-mailer/index.d.ts +3 -0
  49. package/src/infrastructure-mailer/index.js +7 -0
  50. package/src/infrastructure-mailer/index.js.map +1 -0
  51. package/src/infrastructure-mailer/mailer.module.d.ts +2 -0
  52. package/src/infrastructure-mailer/mailer.module.js +23 -0
  53. package/src/infrastructure-mailer/mailer.module.js.map +1 -0
  54. package/src/infrastructure-persistence/entities/invalidated-token.entity.d.ts +7 -0
  55. package/src/infrastructure-persistence/entities/invalidated-token.entity.js +42 -0
  56. package/src/infrastructure-persistence/entities/invalidated-token.entity.js.map +1 -0
  57. package/src/infrastructure-persistence/entities/permission.entity.d.ts +17 -0
  58. package/src/infrastructure-persistence/entities/permission.entity.js +76 -0
  59. package/src/infrastructure-persistence/entities/permission.entity.js.map +1 -0
  60. package/src/infrastructure-persistence/entities/role.entity.d.ts +12 -0
  61. package/src/infrastructure-persistence/entities/role.entity.js +69 -0
  62. package/src/infrastructure-persistence/entities/role.entity.js.map +1 -0
  63. package/src/infrastructure-persistence/entities/user.entity.d.ts +14 -0
  64. package/src/infrastructure-persistence/entities/user.entity.js +77 -0
  65. package/src/infrastructure-persistence/entities/user.entity.js.map +1 -0
  66. package/src/infrastructure-persistence/index.d.ts +2 -0
  67. package/src/infrastructure-persistence/index.js +6 -0
  68. package/src/infrastructure-persistence/index.js.map +1 -0
  69. package/src/infrastructure-persistence/migrations/1720200000000-create-invalidated-tokens-cache.table.d.ts +6 -0
  70. package/src/infrastructure-persistence/migrations/1720200000000-create-invalidated-tokens-cache.table.js +29 -0
  71. package/src/infrastructure-persistence/migrations/1720200000000-create-invalidated-tokens-cache.table.js.map +1 -0
  72. package/src/infrastructure-persistence/persistence.module-definition.d.ts +13 -0
  73. package/src/infrastructure-persistence/persistence.module-definition.js +13 -0
  74. package/src/infrastructure-persistence/persistence.module-definition.js.map +1 -0
  75. package/src/infrastructure-persistence/persistence.module.d.ts +7 -0
  76. package/src/infrastructure-persistence/persistence.module.js +52 -0
  77. package/src/infrastructure-persistence/persistence.module.js.map +1 -0
  78. package/src/infrastructure-persistence/repositories/auth-user.repository.d.ts +10 -0
  79. package/src/infrastructure-persistence/repositories/auth-user.repository.js +12 -0
  80. package/src/infrastructure-persistence/repositories/auth-user.repository.js.map +1 -0
  81. package/src/infrastructure-persistence/repositories/typeorm-auth-user.repository.d.ts +17 -0
  82. package/src/infrastructure-persistence/repositories/typeorm-auth-user.repository.js +62 -0
  83. package/src/infrastructure-persistence/repositories/typeorm-auth-user.repository.js.map +1 -0
  84. package/src/infrastructure-persistence/schema.d.ts +1 -0
  85. package/src/infrastructure-persistence/schema.js +5 -0
  86. package/src/infrastructure-persistence/schema.js.map +1 -0
  87. package/src/presentation/controllers/auth.controller.d.ts +39 -0
  88. package/src/presentation/controllers/auth.controller.js +198 -0
  89. package/src/presentation/controllers/auth.controller.js.map +1 -0
  90. package/src/presentation/decorators/policies.decorator.d.ts +3 -0
  91. package/src/presentation/decorators/policies.decorator.js +8 -0
  92. package/src/presentation/decorators/policies.decorator.js.map +1 -0
  93. package/src/presentation/guards/policies.guard.d.ts +9 -0
  94. package/src/presentation/guards/policies.guard.js +38 -0
  95. package/src/presentation/guards/policies.guard.js.map +1 -0
  96. package/src/presentation/index.d.ts +4 -0
  97. package/src/presentation/index.js +8 -0
  98. package/src/presentation/index.js.map +1 -0
  99. package/src/presentation/presentation.module.d.ts +2 -0
  100. package/src/presentation/presentation.module.js +15 -0
  101. package/src/presentation/presentation.module.js.map +1 -0
@@ -0,0 +1,220 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JwtAuthService = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const common_1 = require("@nestjs/common");
6
+ const jwt_1 = require("@nestjs/jwt");
7
+ const auth_user_repository_1 = require("../../infrastructure-persistence/repositories/auth-user.repository");
8
+ const hash_service_1 = require("./hash.service");
9
+ let JwtAuthService = class JwtAuthService {
10
+ constructor(hashService, authUserRepository, jwtService) {
11
+ this.hashService = hashService;
12
+ this.authUserRepository = authUserRepository;
13
+ this.jwtService = jwtService;
14
+ }
15
+ async registerUser(dto) {
16
+ if (dto.password !== dto.confirmPassword) {
17
+ throw new common_1.BadRequestException('Passwords do not match');
18
+ }
19
+ const passwordHash = await this.hashService.hash(dto.password);
20
+ const token = crypto.randomUUID();
21
+ const { userName, email } = dto;
22
+ const user = {
23
+ email,
24
+ passwordHash,
25
+ isActive: false,
26
+ userName,
27
+ token,
28
+ roles: [
29
+ {
30
+ name: 'user',
31
+ },
32
+ ],
33
+ };
34
+ await this.authUserRepository.create(user);
35
+ return { success: true };
36
+ }
37
+ async activateUser(dto) {
38
+ const { token } = dto;
39
+ const user = await this.authUserRepository.findOne(token);
40
+ await this.authUserRepository.update({
41
+ ...user,
42
+ isActive: true,
43
+ token: null,
44
+ });
45
+ return { success: true };
46
+ }
47
+ async login(dto) {
48
+ const { credential, password } = dto;
49
+ const user = await this.authUserRepository.findOne({
50
+ where: [{ email: credential }, { userName: credential }],
51
+ });
52
+ if (!user) {
53
+ throw new common_1.BadRequestException('Invalid credentials');
54
+ }
55
+ const isPasswordValid = await this.hashService.compare(password, user.passwordHash);
56
+ if (!isPasswordValid) {
57
+ throw new common_1.BadRequestException('Invalid credentials');
58
+ }
59
+ return this.generateTokens(user);
60
+ }
61
+ async logout(dto) {
62
+ const { accessToken, refreshToken } = dto;
63
+ if (!refreshToken) {
64
+ throw new common_1.BadRequestException('Refresh token is required');
65
+ }
66
+ const payload = await this.jwtService
67
+ .verifyAsync(refreshToken)
68
+ .catch(() => {
69
+ throw new common_1.BadRequestException('Invalid refresh token');
70
+ });
71
+ if (!payload?.sub) {
72
+ throw new common_1.BadRequestException('Invalid refresh token');
73
+ }
74
+ const user = await this.authUserRepository.findOne({
75
+ where: { id: payload.sub },
76
+ });
77
+ if (!user?.id) {
78
+ throw new common_1.BadRequestException('Invalid refresh token');
79
+ }
80
+ const tokenHashes = await Promise.all([accessToken, refreshToken]
81
+ .filter((token) => Boolean(token))
82
+ .map((token) => this.hashService.hash(token)));
83
+ await this.authUserRepository.invalidateTokens(tokenHashes, user.id);
84
+ return { success: true };
85
+ }
86
+ async changePassword(userId, dto) {
87
+ const { currentPassword, newPassword, confirmPassword } = dto;
88
+ if (newPassword !== confirmPassword) {
89
+ throw new common_1.BadRequestException('Passwords do not match');
90
+ }
91
+ const user = await this.authUserRepository.findOne({
92
+ where: { id: userId },
93
+ });
94
+ if (!user) {
95
+ throw new common_1.BadRequestException('User not found');
96
+ }
97
+ const isCurrentPasswordValid = await this.hashService.compare(currentPassword, user.passwordHash);
98
+ if (!isCurrentPasswordValid) {
99
+ throw new common_1.BadRequestException('Invalid current password');
100
+ }
101
+ user.passwordHash = await this.hashService.hash(newPassword);
102
+ await this.authUserRepository.update(user);
103
+ return { success: true };
104
+ }
105
+ async forgotPassword(dto) {
106
+ const { email } = dto;
107
+ const user = await this.authUserRepository.findOne({ where: { email } });
108
+ if (!user) {
109
+ throw new common_1.BadRequestException('User not found');
110
+ }
111
+ const token = crypto.randomUUID();
112
+ user.token = token;
113
+ await this.authUserRepository.update(user);
114
+ // Here you would typically send the token to the user's email
115
+ return { success: true };
116
+ }
117
+ async resetPassword(dto) {
118
+ const { token, password, confirmPassword } = dto;
119
+ if (password !== confirmPassword) {
120
+ throw new common_1.BadRequestException('Passwords do not match');
121
+ }
122
+ const user = await this.authUserRepository.findOne({ where: { token } });
123
+ if (!user) {
124
+ throw new common_1.BadRequestException('Invalid token');
125
+ }
126
+ user.passwordHash = await this.hashService.hash(password);
127
+ user.token = null;
128
+ await this.authUserRepository.update(user);
129
+ return { success: true };
130
+ }
131
+ async verifyEmail(dto) {
132
+ const { token } = dto;
133
+ const user = await this.authUserRepository.findOne({ where: { token } });
134
+ if (!user) {
135
+ throw new common_1.BadRequestException('Invalid token');
136
+ }
137
+ user.isActive = true;
138
+ user.token = null;
139
+ await this.authUserRepository.update(user);
140
+ return { success: true };
141
+ }
142
+ async updateEmail(userId, dto) {
143
+ const { newEmail, password } = dto;
144
+ const user = await this.authUserRepository.findOne({
145
+ where: { id: userId },
146
+ });
147
+ if (!user) {
148
+ throw new common_1.BadRequestException('User not found');
149
+ }
150
+ const isPasswordValid = password && (await this.hashService.compare(password, user.passwordHash));
151
+ if (!isPasswordValid) {
152
+ throw new common_1.BadRequestException('Invalid password');
153
+ }
154
+ user.email = newEmail;
155
+ await this.authUserRepository.update(user);
156
+ return { success: true };
157
+ }
158
+ async refreshTokens(userId, dto) {
159
+ const { refreshToken } = dto;
160
+ const payload = await this.jwtService
161
+ .verifyAsync(refreshToken)
162
+ .catch(() => {
163
+ throw new common_1.BadRequestException('Invalid refresh token');
164
+ });
165
+ if (!payload?.sub || payload.sub !== userId) {
166
+ throw new common_1.BadRequestException('Invalid refresh token');
167
+ }
168
+ const user = await this.authUserRepository.findOne({
169
+ where: { id: userId },
170
+ });
171
+ if (!user) {
172
+ throw new common_1.BadRequestException('User not found');
173
+ }
174
+ const isTokenInvalidated = await this.authUserRepository.isTokenInvalidated(await this.hashService.hash(refreshToken));
175
+ if (isTokenInvalidated) {
176
+ throw new common_1.BadRequestException('Refresh token has been invalidated');
177
+ }
178
+ return this.generateTokens(user);
179
+ }
180
+ async getLoggedInUserInfo(userId) {
181
+ const user = await this.authUserRepository.findOne({
182
+ where: { id: userId },
183
+ relations: ['roles', 'permissions'],
184
+ });
185
+ if (!user) {
186
+ throw new common_1.BadRequestException('User not found');
187
+ }
188
+ const rbac = [];
189
+ user.roles?.forEach((role) => {
190
+ role.permissions?.forEach((permission) => {
191
+ rbac.push({
192
+ action: permission.action,
193
+ subject: permission.subject,
194
+ conditions: permission.conditions ?? undefined,
195
+ fields: permission.fields ?? undefined,
196
+ reason: permission.reason ?? undefined,
197
+ inverted: permission.inverted ?? false,
198
+ });
199
+ });
200
+ });
201
+ return { user, rbac };
202
+ }
203
+ async generateTokens(user) {
204
+ const payload = {
205
+ sub: user.id,
206
+ roles: user.roles?.map((role) => role.name),
207
+ };
208
+ const accessToken = await this.jwtService.signAsync(payload);
209
+ const refreshToken = await this.jwtService.signAsync(payload);
210
+ return { accessToken, refreshToken };
211
+ }
212
+ };
213
+ exports.JwtAuthService = JwtAuthService;
214
+ exports.JwtAuthService = JwtAuthService = tslib_1.__decorate([
215
+ (0, common_1.Injectable)(),
216
+ tslib_1.__metadata("design:paramtypes", [hash_service_1.HashService,
217
+ auth_user_repository_1.AuthUserRepository,
218
+ jwt_1.JwtService])
219
+ ], JwtAuthService);
220
+ //# sourceMappingURL=jwt-auth.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwt-auth.service.js","sourceRoot":"","sources":["../../../../../../../libs/auth/nest/src/application/services/jwt-auth.service.ts"],"names":[],"mappings":";;;;AAeA,2CAAiE;AACjE,qCAAyC;AACzC,6GAAwG;AAExG,iDAA6C;AAGtC,IAAM,cAAc,GAApB,MAAM,cAAc;IACzB,YACmB,WAAwB,EACxB,kBAAsC,EACtC,UAAsB;QAFtB,gBAAW,GAAX,WAAW,CAAa;QACxB,uBAAkB,GAAlB,kBAAkB,CAAoB;QACtC,eAAU,GAAV,UAAU,CAAY;IACtC,CAAC;IAEJ,KAAK,CAAC,YAAY,CAAC,GAAuB;QACxC,IAAI,GAAG,CAAC,QAAQ,KAAK,GAAG,CAAC,eAAe,EAAE,CAAC;YACzC,MAAM,IAAI,4BAAmB,CAAC,wBAAwB,CAAC,CAAC;QAC1D,CAAC;QACD,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,WA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/auth-user.repository';
2
+ import { PolicyRule, User } from '@anarchitects/auth-ts/models';
3
+ import { AppAbility, AbilityFactory } from '../factories/ability.factory';
4
+ export declare class PoliciesService {
5
+ private readonly authUserRepository;
6
+ private readonly abilityFactory;
7
+ constructor(authUserRepository: AuthUserRepository, abilityFactory: AbilityFactory);
8
+ rulesForUser(authUser: User): Promise<PolicyRule[]>;
9
+ buildAbilityForUser(authUser: User): Promise<AppAbility>;
10
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PoliciesService = void 0;
4
+ const tslib_1 = require("tslib");
5
+ /* eslint-disable @typescript-eslint/no-explicit-any */
6
+ const common_1 = require("@nestjs/common");
7
+ const auth_user_repository_1 = require("../../infrastructure-persistence/repositories/auth-user.repository");
8
+ const ability_factory_1 = require("../factories/ability.factory");
9
+ let PoliciesService = class PoliciesService {
10
+ constructor(authUserRepository, abilityFactory) {
11
+ this.authUserRepository = authUserRepository;
12
+ this.abilityFactory = abilityFactory;
13
+ }
14
+ async rulesForUser(authUser) {
15
+ const user = await this.authUserRepository.findOne({
16
+ where: { id: authUser.id },
17
+ relations: ['roles', 'roles.permissions'],
18
+ });
19
+ const inject = (c) => !c ? undefined : JSON.parse(JSON.stringify(c));
20
+ if (!user) {
21
+ return [];
22
+ }
23
+ return (user.roles ?? []).flatMap((role) => (role.permissions ?? []).map((permission) => ({
24
+ action: permission.action,
25
+ subject: permission.subject,
26
+ conditions: inject(permission.conditions),
27
+ fields: permission.fields ?? undefined,
28
+ inverted: permission.inverted ?? false,
29
+ reason: permission.reason ?? undefined,
30
+ })));
31
+ }
32
+ async buildAbilityForUser(authUser) {
33
+ return this.abilityFactory.buildAbility(await this.rulesForUser(authUser));
34
+ }
35
+ };
36
+ exports.PoliciesService = PoliciesService;
37
+ exports.PoliciesService = PoliciesService = tslib_1.__decorate([
38
+ (0, common_1.Injectable)(),
39
+ tslib_1.__metadata("design:paramtypes", [auth_user_repository_1.AuthUserRepository,
40
+ ability_factory_1.AbilityFactory])
41
+ ], PoliciesService);
42
+ //# sourceMappingURL=policies.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policies.service.js","sourceRoot":"","sources":["../../../../../../../libs/auth/nest/src/application/services/policies.service.ts"],"names":[],"mappings":";;;;AAAA,uDAAuD;AACvD,2CAA4C;AAC5C,6GAAwG;AAExG,kEAA0E;AAGnE,IAAM,eAAe,GAArB,MAAM,eAAe;IAC1B,YACmB,kBAAsC,EACtC,cAA8B;QAD9B,uBAAkB,GAAlB,kBAAkB,CAAoB;QACtC,mBAAc,GAAd,cAAc,CAAgB;IAC9C,CAAC;IAEJ,KAAK,CAAC,YAAY,CAAC,QAAc;QAC/B,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC;YACjD,KAAK,EAAE,EAAE,EAAE,EAAE,QAAQ,CAAC,EAAE,EAAE;YAC1B,SAAS,EAAE,CAAC,OAAO,EAAE,mBAAmB,CAAC;SAC1C,CAAC,CAAC;QACH,MAAM,MAAM,GAAG,CAAC,CAAO,EAAE,EAAE,CACzB,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;QACjD,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CACzC,CAAC,IAAI,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC,GAAG,CAAa,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;YACxD,MAAM,EAAE,UAAU,CAAC,MAAM;YACzB,OAAO,EAAE,UAAU,CAAC,OAAO;YAC3B,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC;YACzC,MAAM,EAAE,UAAU,CAAC,MAAM,IAAI,SAAS;YACtC,QAAQ,EAAE,UAAU,CAAC,QAAQ,IAAI,KAAK;YACtC,MAAM,EAAE,UAAU,CAAC,MAAM,IAAI,SAAS;SACvC,CAAC,CAAC,CACJ,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,mBAAmB,CAAC,QAAc;QACtC,OAAO,IAAI,CAAC,cAAc,CAAC,YAAY,CAAC,MAAM,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC7E,CAAC;CACF,CAAA;AA/BY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,GAAE;6CAG4B,yCAAkB;QACtB,gCAAc;GAHtC,eAAe,CA+B3B"}
@@ -0,0 +1,16 @@
1
+ import { Role } from '@anarchitects/auth-ts/models';
2
+ import { Strategy } from 'passport-jwt';
3
+ declare const JwtStrategy_base: new (...args: [opt: import("passport-jwt").StrategyOptionsWithRequest] | [opt: import("passport-jwt").StrategyOptionsWithoutRequest]) => Strategy & {
4
+ validate(...args: any[]): unknown;
5
+ };
6
+ export declare class JwtStrategy extends JwtStrategy_base {
7
+ constructor();
8
+ validate(payload: {
9
+ sub: string;
10
+ roles: Role[];
11
+ }): Promise<{
12
+ userId: string;
13
+ roles: Role[];
14
+ }>;
15
+ }
16
+ export {};
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JwtStrategy = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const common_1 = require("@nestjs/common");
6
+ const passport_1 = require("@nestjs/passport");
7
+ const passport_jwt_1 = require("passport-jwt");
8
+ let JwtStrategy = class JwtStrategy extends (0, passport_1.PassportStrategy)(passport_jwt_1.Strategy) {
9
+ constructor() {
10
+ super({
11
+ jwtFromRequest: passport_jwt_1.ExtractJwt.fromAuthHeaderAsBearerToken(),
12
+ ignoreExpiration: false,
13
+ secretOrKey: process.env['JWT_SECRET'] || 'defaultSecret',
14
+ });
15
+ }
16
+ async validate(payload) {
17
+ return { userId: payload.sub, roles: payload.roles };
18
+ }
19
+ };
20
+ exports.JwtStrategy = JwtStrategy;
21
+ exports.JwtStrategy = JwtStrategy = tslib_1.__decorate([
22
+ (0, common_1.Injectable)(),
23
+ tslib_1.__metadata("design:paramtypes", [])
24
+ ], JwtStrategy);
25
+ //# sourceMappingURL=strategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strategy.js","sourceRoot":"","sources":["../../../../../../../../libs/auth/nest/src/application/strategies/jwt/strategy.ts"],"names":[],"mappings":";;;;AACA,2CAA4C;AAC5C,+CAAoD;AACpD,+CAAoD;AAG7C,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,IAAA,2BAAgB,EAAC,uBAAQ,CAAC;IACzD;QACE,KAAK,CAAC;YACJ,cAAc,EAAE,yBAAU,CAAC,2BAA2B,EAAE;YACxD,gBAAgB,EAAE,KAAK;YACvB,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,eAAe;SAC1D,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,OAAuC;QACpD,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC;IACvD,CAAC;CACF,CAAA;AAZY,kCAAW;sBAAX,WAAW;IADvB,IAAA,mBAAU,GAAE;;GACA,WAAW,CAYvB"}
@@ -0,0 +1,18 @@
1
+ import { ConfigType } from '@nestjs/config';
2
+ export declare const authConfig: (() => {
3
+ jwtSecret: string;
4
+ jwtExpiration: string;
5
+ jwtAudience: string;
6
+ jwtIssuer: string;
7
+ encryptionAlgorithm: string;
8
+ encryptionKey: string;
9
+ }) & import("@nestjs/config").ConfigFactoryKeyHost<{
10
+ jwtSecret: string;
11
+ jwtExpiration: string;
12
+ jwtAudience: string;
13
+ jwtIssuer: string;
14
+ encryptionAlgorithm: string;
15
+ encryptionKey: string;
16
+ }>;
17
+ export type AuthConfig = ConfigType<typeof authConfig>;
18
+ export declare const InjectAuthConfig: () => PropertyDecorator & ParameterDecorator;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InjectAuthConfig = exports.authConfig = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ const config_1 = require("@nestjs/config");
6
+ const AUTH_CONFIG_KEY = 'auth';
7
+ exports.authConfig = (0, config_1.registerAs)(AUTH_CONFIG_KEY, () => ({
8
+ jwtSecret: process.env['AUTH_JWT_SECRET'] || 'default_jwt_secret',
9
+ jwtExpiration: process.env['AUTH_JWT_EXPIRATION'] || '3600s',
10
+ jwtAudience: process.env['AUTH_JWT_AUDIENCE'] || 'your_audience',
11
+ jwtIssuer: process.env['AUTH_JWT_ISSUER'] || 'your_issuer',
12
+ encryptionAlgorithm: process.env['AUTH_ENCRYPTION_ALGORITHM'] || 'bcrypt',
13
+ encryptionKey: process.env['AUTH_ENCRYPTION_KEY'] || 'default_encryption_key',
14
+ }));
15
+ const InjectAuthConfig = () => (0, common_1.Inject)(exports.authConfig.KEY);
16
+ exports.InjectAuthConfig = InjectAuthConfig;
17
+ //# sourceMappingURL=auth.config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.config.js","sourceRoot":"","sources":["../../../../../../libs/auth/nest/src/config/auth.config.ts"],"names":[],"mappings":";;;AAAA,2CAAwC;AACxC,2CAAwD;AAExD,MAAM,eAAe,GAAG,MAAM,CAAC;AAElB,QAAA,UAAU,GAAG,IAAA,mBAAU,EAAC,eAAe,EAAE,GAAG,EAAE,CAAC,CAAC;IAC3D,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,IAAI,oBAAoB;IACjE,aAAa,EAAE,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,IAAI,OAAO;IAC5D,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,IAAI,eAAe;IAChE,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,IAAI,aAAa;IAC1D,mBAAmB,EAAE,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC,IAAI,QAAQ;IACzE,aAAa,EAAE,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,IAAI,wBAAwB;CAC9E,CAAC,CAAC,CAAC;AAIG,MAAM,gBAAgB,GAAG,GAAG,EAAE,CAAC,IAAA,eAAM,EAAC,kBAAU,CAAC,GAAG,CAAC,CAAC;AAAhD,QAAA,gBAAgB,oBAAgC"}
@@ -0,0 +1 @@
1
+ export * from './auth.config';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./auth.config"), exports);
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/auth/nest/src/config/index.ts"],"names":[],"mappings":";;;AAAA,wDAA8B"}
package/src/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from './application';
2
+ export * from './presentation';
3
+ export * from './infrastructure-persistence';
4
+ export * from './infrastructure-mailer';
5
+ export * from './config';
package/src/index.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./application"), exports);
5
+ tslib_1.__exportStar(require("./presentation"), exports);
6
+ tslib_1.__exportStar(require("./infrastructure-persistence"), exports);
7
+ tslib_1.__exportStar(require("./infrastructure-mailer"), exports);
8
+ tslib_1.__exportStar(require("./config"), exports);
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/auth/nest/src/index.ts"],"names":[],"mappings":";;;AAAA,wDAA8B;AAC9B,yDAA+B;AAC/B,uEAA6C;AAC7C,kEAAwC;AACxC,mDAAyB"}
@@ -0,0 +1,4 @@
1
+ export declare abstract class MailerAdapter {
2
+ abstract send(to: string, subject: string, html: string): Promise<void>;
3
+ abstract sendTemplate(to: string, subject: string, template: string, context?: Record<string, unknown>): Promise<void>;
4
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MailerAdapter = void 0;
4
+ class MailerAdapter {
5
+ }
6
+ exports.MailerAdapter = MailerAdapter;
7
+ //# sourceMappingURL=mailer.adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mailer.adapter.js","sourceRoot":"","sources":["../../../../../../../libs/auth/nest/src/infrastructure-mailer/adapters/mailer.adapter.ts"],"names":[],"mappings":";;;AAAA,MAAsB,aAAa;CAQlC;AARD,sCAQC"}
@@ -0,0 +1,8 @@
1
+ import { MailerService } from '@nestjs-modules/mailer';
2
+ import { MailerAdapter } from './mailer.adapter';
3
+ export declare class NodeMailerAdapter implements MailerAdapter {
4
+ private readonly mailer;
5
+ constructor(mailer: MailerService);
6
+ send(to: string, subject: string, html: string): Promise<SentMessageInfo>;
7
+ sendTemplate(to: string, subject: string, template: string, context?: Record<string, unknown>): Promise<SentMessageInfo>;
8
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NodeMailerAdapter = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const common_1 = require("@nestjs/common");
6
+ const mailer_1 = require("@nestjs-modules/mailer");
7
+ let NodeMailerAdapter = class NodeMailerAdapter {
8
+ constructor(mailer) {
9
+ this.mailer = mailer;
10
+ }
11
+ async send(to, subject, html) {
12
+ return await this.mailer.sendMail({ to, subject, html });
13
+ }
14
+ async sendTemplate(to, subject, template, context) {
15
+ return await this.mailer.sendMail({ to, subject, template, context });
16
+ }
17
+ };
18
+ exports.NodeMailerAdapter = NodeMailerAdapter;
19
+ exports.NodeMailerAdapter = NodeMailerAdapter = tslib_1.__decorate([
20
+ (0, common_1.Injectable)(),
21
+ tslib_1.__metadata("design:paramtypes", [mailer_1.MailerService])
22
+ ], NodeMailerAdapter);
23
+ //# sourceMappingURL=node-mailer.adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-mailer.adapter.js","sourceRoot":"","sources":["../../../../../../../libs/auth/nest/src/infrastructure-mailer/adapters/node-mailer.adapter.ts"],"names":[],"mappings":";;;;AAAA,2CAA4C;AAC5C,mDAAuD;AAIhD,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAC5B,YAA6B,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;IAAG,CAAC;IACtD,KAAK,CAAC,IAAI,CAAC,EAAU,EAAE,OAAe,EAAE,IAAY;QAClD,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3D,CAAC;IACD,KAAK,CAAC,YAAY,CAChB,EAAU,EACV,OAAe,EACf,QAAgB,EAChB,OAAiC;QAEjC,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;IACxE,CAAC;CACF,CAAA;AAbY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;6CAE0B,sBAAa;GADvC,iBAAiB,CAa7B"}
@@ -0,0 +1,3 @@
1
+ export * from './adapters/mailer.adapter';
2
+ export * from './adapters/node-mailer.adapter';
3
+ export * from './mailer.module';
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./adapters/mailer.adapter"), exports);
5
+ tslib_1.__exportStar(require("./adapters/node-mailer.adapter"), exports);
6
+ tslib_1.__exportStar(require("./mailer.module"), exports);
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/auth/nest/src/infrastructure-mailer/index.ts"],"names":[],"mappings":";;;AAAA,oEAA0C;AAC1C,yEAA+C;AAC/C,0DAAgC"}
@@ -0,0 +1,2 @@
1
+ export declare class MailerModule {
2
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MailerModule = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const common_1 = require("@nestjs/common");
6
+ const node_mailer_adapter_1 = require("./adapters/node-mailer.adapter");
7
+ const mailer_adapter_1 = require("./adapters/mailer.adapter");
8
+ let MailerModule = class MailerModule {
9
+ };
10
+ exports.MailerModule = MailerModule;
11
+ exports.MailerModule = MailerModule = tslib_1.__decorate([
12
+ (0, common_1.Module)({
13
+ providers: [
14
+ node_mailer_adapter_1.NodeMailerAdapter,
15
+ {
16
+ provide: mailer_adapter_1.MailerAdapter,
17
+ useExisting: node_mailer_adapter_1.NodeMailerAdapter,
18
+ },
19
+ ],
20
+ exports: [mailer_adapter_1.MailerAdapter],
21
+ })
22
+ ], MailerModule);
23
+ //# sourceMappingURL=mailer.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mailer.module.js","sourceRoot":"","sources":["../../../../../../libs/auth/nest/src/infrastructure-mailer/mailer.module.ts"],"names":[],"mappings":";;;;AAAA,2CAAwC;AACxC,wEAAmE;AACnE,8DAA0D;AAYnD,IAAM,YAAY,GAAlB,MAAM,YAAY;CAAG,CAAA;AAAf,oCAAY;uBAAZ,YAAY;IAVxB,IAAA,eAAM,EAAC;QACN,SAAS,EAAE;YACT,uCAAiB;YACjB;gBACE,OAAO,EAAE,8BAAa;gBACtB,WAAW,EAAE,uCAAiB;aAC/B;SACF;QACD,OAAO,EAAE,CAAC,8BAAa,CAAC;KACzB,CAAC;GACW,YAAY,CAAG"}
@@ -0,0 +1,7 @@
1
+ export declare class InvalidatedTokenEntity {
2
+ tokenId: string;
3
+ userId: string | null;
4
+ expiresAt: Date;
5
+ invalidatedAt: Date;
6
+ constructor(partial?: Partial<InvalidatedTokenEntity>);
7
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InvalidatedTokenEntity = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const typeorm_1 = require("typeorm");
6
+ const schema_1 = require("../schema");
7
+ let InvalidatedTokenEntity = class InvalidatedTokenEntity {
8
+ constructor(partial = {}) {
9
+ Object.assign(this, partial);
10
+ }
11
+ };
12
+ exports.InvalidatedTokenEntity = InvalidatedTokenEntity;
13
+ tslib_1.__decorate([
14
+ (0, typeorm_1.PrimaryColumn)({ type: 'varchar', length: 128 }),
15
+ tslib_1.__metadata("design:type", String)
16
+ ], InvalidatedTokenEntity.prototype, "tokenId", void 0);
17
+ tslib_1.__decorate([
18
+ (0, typeorm_1.Column)({ type: 'uuid', nullable: true }),
19
+ tslib_1.__metadata("design:type", Object)
20
+ ], InvalidatedTokenEntity.prototype, "userId", void 0);
21
+ tslib_1.__decorate([
22
+ (0, typeorm_1.Column)({ type: 'timestamptz', name: 'expires_at' }),
23
+ tslib_1.__metadata("design:type", Date)
24
+ ], InvalidatedTokenEntity.prototype, "expiresAt", void 0);
25
+ tslib_1.__decorate([
26
+ (0, typeorm_1.Column)({
27
+ type: 'timestamptz',
28
+ name: 'invalidated_at',
29
+ default: () => 'CURRENT_TIMESTAMP',
30
+ }),
31
+ tslib_1.__metadata("design:type", Date)
32
+ ], InvalidatedTokenEntity.prototype, "invalidatedAt", void 0);
33
+ exports.InvalidatedTokenEntity = InvalidatedTokenEntity = tslib_1.__decorate([
34
+ (0, typeorm_1.Entity)({
35
+ schema: schema_1.AUTH_SCHEMA,
36
+ name: 'invalidated_tokens',
37
+ synchronize: false,
38
+ }),
39
+ (0, typeorm_1.Index)('invalidated_tokens_expires_at_idx', ['expiresAt']),
40
+ tslib_1.__metadata("design:paramtypes", [Object])
41
+ ], InvalidatedTokenEntity);
42
+ //# sourceMappingURL=invalidated-token.entity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invalidated-token.entity.js","sourceRoot":"","sources":["../../../../../../../libs/auth/nest/src/infrastructure-persistence/entities/invalidated-token.entity.ts"],"names":[],"mappings":";;;;AAAA,qCAA+D;AAC/D,sCAAwC;AAQjC,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IAiBjC,YAAY,UAA2C,EAAE;QACvD,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC/B,CAAC;CACF,CAAA;AApBY,wDAAsB;AAEjC;IADC,IAAA,uBAAa,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;;uDAC/B;AAGjB;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;sDAClB;AAGvB;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;sCACxC,IAAI;yDAAC;AAOjB;IALC,IAAA,gBAAM,EAAC;QACN,IAAI,EAAE,aAAa;QACnB,IAAI,EAAE,gBAAgB;QACtB,OAAO,EAAE,GAAG,EAAE,CAAC,mBAAmB;KACnC,CAAC;sCACc,IAAI;6DAAC;iCAfV,sBAAsB;IANlC,IAAA,gBAAM,EAAC;QACN,MAAM,EAAE,oBAAW;QACnB,IAAI,EAAE,oBAAoB;QAC1B,WAAW,EAAE,KAAK;KACnB,CAAC;IACD,IAAA,eAAK,EAAC,mCAAmC,EAAE,CAAC,WAAW,CAAC,CAAC;;GAC7C,sBAAsB,CAoBlC"}
@@ -0,0 +1,17 @@
1
+ import { Permission, Role } from '@anarchitects/auth-ts/models';
2
+ export declare class PermissionEntity implements Permission {
3
+ id: string;
4
+ name: string;
5
+ description: string | null;
6
+ action: string;
7
+ subject: string;
8
+ conditions: Record<string, unknown> | null;
9
+ fields: string[] | null;
10
+ inverted: boolean;
11
+ reason: string | null;
12
+ roles: Role[] | null;
13
+ createdAt: Date;
14
+ updatedAt: Date;
15
+ constructor(partial: Partial<Permission>);
16
+ generateId(): void;
17
+ }