@vnodes/auth 0.0.3 → 0.0.8

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 (43) hide show
  1. package/dist/auth.controller.d.ts +3 -0
  2. package/dist/auth.controller.d.ts.map +1 -1
  3. package/dist/auth.controller.js +24 -2
  4. package/dist/auth.module.d.ts.map +1 -1
  5. package/dist/auth.module.js +5 -2
  6. package/dist/context/context.d.ts +3 -1
  7. package/dist/context/context.d.ts.map +1 -1
  8. package/dist/context/context.js +6 -0
  9. package/dist/dto/email-otp-event.dto.d.ts +6 -0
  10. package/dist/dto/email-otp-event.dto.d.ts.map +1 -0
  11. package/dist/dto/email-otp-event.dto.js +17 -0
  12. package/dist/dto/update-password-event.dto.d.ts +5 -0
  13. package/dist/dto/update-password-event.dto.d.ts.map +1 -0
  14. package/dist/dto/update-password-event.dto.js +14 -0
  15. package/dist/guards/auth.guard.d.ts +5 -3
  16. package/dist/guards/auth.guard.d.ts.map +1 -1
  17. package/dist/guards/auth.guard.js +25 -18
  18. package/dist/index.d.ts +7 -2
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +7 -2
  21. package/dist/services/auth-listener.service.d.ts +10 -0
  22. package/dist/services/auth-listener.service.d.ts.map +1 -0
  23. package/dist/services/auth-listener.service.js +32 -0
  24. package/dist/services/{user.service.d.ts → auth-user.service.d.ts} +6 -3
  25. package/dist/services/auth-user.service.d.ts.map +1 -0
  26. package/dist/services/{user.service.js → auth-user.service.js} +16 -8
  27. package/dist/services/auth.service.d.ts +11 -3
  28. package/dist/services/auth.service.d.ts.map +1 -1
  29. package/dist/services/auth.service.js +26 -13
  30. package/dist/types/auth-request.d.ts +1 -1
  31. package/dist/types/auth-request.d.ts.map +1 -1
  32. package/dist/types/jwt-payload.d.ts +6 -0
  33. package/dist/types/jwt-payload.d.ts.map +1 -0
  34. package/dist/types/jwt-payload.js +5 -0
  35. package/dist/{services → types}/user-manager.d.ts +2 -14
  36. package/dist/types/user-manager.d.ts.map +1 -0
  37. package/dist/{services → types}/user-manager.js +2 -23
  38. package/dist/types/user.d.ts +10 -0
  39. package/dist/types/user.d.ts.map +1 -0
  40. package/dist/types/user.js +17 -0
  41. package/package.json +4 -4
  42. package/dist/services/user-manager.d.ts.map +0 -1
  43. package/dist/services/user.service.d.ts.map +0 -1
@@ -1,5 +1,6 @@
1
1
  import { ForgotPasswordDto } from './dto/forgot-password.dto.js';
2
2
  import { LoginDto } from './dto/login.dto.js';
3
+ import { UpdatePasswordDto } from './dto/update-password.dto.js';
3
4
  import { AuthService } from './services/auth.service.js';
4
5
  export declare class AuthController {
5
6
  protected readonly authService: AuthService;
@@ -7,5 +8,7 @@ export declare class AuthController {
7
8
  login(body: LoginDto): Promise<import("./index.js").AccessTokenDto>;
8
9
  logout(accessToken: string): import("./index.js").MessageDto;
9
10
  forgotPassword(body: ForgotPasswordDto): import("./index.js").MessageDto;
11
+ updatePassword(uuid: string, body: UpdatePasswordDto): Promise<import("./index.js").MessageDto>;
12
+ profile(uuid: string): import("./index.js").UserManager;
10
13
  }
11
14
  //# sourceMappingURL=auth.controller.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"auth.controller.d.ts","sourceRoot":"","sources":["../src/auth.controller.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAEzD,qBAEa,cAAc;IACX,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,WAAW;gBAAxB,WAAW,EAAE,WAAW;IAIvD,KAAK,CAAS,IAAI,EAAE,QAAQ;IAK5B,MAAM,CAAgB,WAAW,EAAE,MAAM;IAMzC,cAAc,CAAS,IAAI,EAAE,iBAAiB;CAGjD"}
1
+ {"version":3,"file":"auth.controller.d.ts","sourceRoot":"","sources":["../src/auth.controller.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAEzD,qBAEa,cAAc;IACX,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,WAAW;gBAAxB,WAAW,EAAE,WAAW;IAIvD,KAAK,CAAS,IAAI,EAAE,QAAQ;IAK5B,MAAM,CAAgB,WAAW,EAAE,MAAM;IAMzC,cAAc,CAAS,IAAI,EAAE,iBAAiB;IAK9C,cAAc,CAAa,IAAI,EAAE,MAAM,EAAU,IAAI,EAAE,iBAAiB;IAKxE,OAAO,CAAa,IAAI,EAAE,MAAM;CAGnC"}
@@ -1,10 +1,11 @@
1
1
  import { __decorate, __metadata, __param } from "tslib";
2
- import { Body, Controller, Post } from '@nestjs/common';
2
+ import { Body, Controller, Get, Post } from '@nestjs/common';
3
3
  import { Throttle } from '@nestjs/throttler';
4
4
  import { Public } from '@vnodes/metadata';
5
- import { AccessToken } from './context/context.js';
5
+ import { AccessToken, UserUuid } from './context/context.js';
6
6
  import { ForgotPasswordDto } from './dto/forgot-password.dto.js';
7
7
  import { LoginDto } from './dto/login.dto.js';
8
+ import { UpdatePasswordDto } from './dto/update-password.dto.js';
8
9
  import { AuthService } from './services/auth.service.js';
9
10
  let AuthController = class AuthController {
10
11
  authService;
@@ -20,6 +21,12 @@ let AuthController = class AuthController {
20
21
  forgotPassword(body) {
21
22
  return this.authService.forgotPassword(body);
22
23
  }
24
+ updatePassword(uuid, body) {
25
+ return this.authService.updatePassword(uuid, body);
26
+ }
27
+ profile(uuid) {
28
+ return this.authService.profile(uuid);
29
+ }
23
30
  };
24
31
  __decorate([
25
32
  Public(),
@@ -44,6 +51,21 @@ __decorate([
44
51
  __metadata("design:paramtypes", [ForgotPasswordDto]),
45
52
  __metadata("design:returntype", void 0)
46
53
  ], AuthController.prototype, "forgotPassword", null);
54
+ __decorate([
55
+ Post('update-password'),
56
+ __param(0, UserUuid()),
57
+ __param(1, Body()),
58
+ __metadata("design:type", Function),
59
+ __metadata("design:paramtypes", [String, UpdatePasswordDto]),
60
+ __metadata("design:returntype", void 0)
61
+ ], AuthController.prototype, "updatePassword", null);
62
+ __decorate([
63
+ Get('profile'),
64
+ __param(0, UserUuid()),
65
+ __metadata("design:type", Function),
66
+ __metadata("design:paramtypes", [String]),
67
+ __metadata("design:returntype", void 0)
68
+ ], AuthController.prototype, "profile", null);
47
69
  AuthController = __decorate([
48
70
  Throttle({ default: { limit: 6, ttl: 30_000 } }),
49
71
  Controller('auth'),
@@ -1 +1 @@
1
- {"version":3,"file":"auth.module.d.ts","sourceRoot":"","sources":["../src/auth.module.ts"],"names":[],"mappings":"AAQA,qBAqBa,UAAU;CAAG"}
1
+ {"version":3,"file":"auth.module.d.ts","sourceRoot":"","sources":["../src/auth.module.ts"],"names":[],"mappings":"AAUA,qBAsBa,UAAU;CAAG"}
@@ -1,11 +1,13 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { Module } from '@nestjs/common';
3
3
  import { ConfigModule, ConfigService } from '@nestjs/config';
4
+ import { APP_GUARD } from '@nestjs/core';
4
5
  import { EventEmitterModule } from '@nestjs/event-emitter';
5
6
  import { JwtModule } from '@nestjs/jwt';
6
7
  import { AuthController } from './auth.controller.js';
8
+ import { AuthGuard } from './guards/auth.guard.js';
7
9
  import { AuthService } from './services/auth.service.js';
8
- import { UserService } from './services/user.service.js';
10
+ import { AuthUserService } from './services/auth-user.service.js';
9
11
  let AuthModule = class AuthModule {
10
12
  };
11
13
  AuthModule = __decorate([
@@ -28,7 +30,8 @@ AuthModule = __decorate([
28
30
  }),
29
31
  ],
30
32
  controllers: [AuthController],
31
- providers: [UserService, AuthService],
33
+ providers: [AuthUserService, AuthService, { provide: APP_GUARD, useClass: AuthGuard }],
34
+ exports: [AuthUserService],
32
35
  })
33
36
  ], AuthModule);
34
37
  export { AuthModule };
@@ -1,8 +1,10 @@
1
- import { User } from '../services/user-manager.js';
1
+ import { User } from '../types/user.js';
2
2
  /**
3
3
  * Get the user info {@link UserInfo} of the current session from the request
4
4
  */
5
5
  export declare const UserInfo: (...dataOrPipes: (User | import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>>)[]) => ParameterDecorator;
6
+ export declare const UserUuid: (...dataOrPipes: (User | import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>>)[]) => ParameterDecorator;
7
+ export declare const UserUsername: (...dataOrPipes: (User | import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>>)[]) => ParameterDecorator;
6
8
  /**
7
9
  * Get the access token of the current session from the request
8
10
  */
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/context/context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAGnD;;GAEG;AACH,eAAO,MAAM,QAAQ,uLAEnB,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,WAAW,yLAEtB,CAAC"}
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/context/context.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC;;GAEG;AACH,eAAO,MAAM,QAAQ,uLAEnB,CAAC;AAEH,eAAO,MAAM,QAAQ,uLAEnB,CAAC;AAEH,eAAO,MAAM,YAAY,uLAEvB,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,WAAW,yLAEtB,CAAC"}
@@ -5,6 +5,12 @@ import { createParamDecorator } from '@nestjs/common';
5
5
  export const UserInfo = createParamDecorator((_, context) => {
6
6
  return context.switchToHttp().getRequest().user;
7
7
  });
8
+ export const UserUuid = createParamDecorator((_, context) => {
9
+ return context.switchToHttp().getRequest().user.uuid;
10
+ });
11
+ export const UserUsername = createParamDecorator((_, context) => {
12
+ return context.switchToHttp().getRequest().user.username;
13
+ });
8
14
  /**
9
15
  * Get the access token of the current session from the request
10
16
  */
@@ -0,0 +1,6 @@
1
+ export declare class EmailOtpEventDto {
2
+ username: string;
3
+ otp: string;
4
+ constructor(data: EmailOtpEventDto);
5
+ }
6
+ //# sourceMappingURL=email-otp-event.dto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"email-otp-event.dto.d.ts","sourceRoot":"","sources":["../../src/dto/email-otp-event.dto.ts"],"names":[],"mappings":"AAEA,qBAAa,gBAAgB;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;gBACR,IAAI,EAAE,gBAAgB;CAGrC"}
@@ -0,0 +1,17 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { Prop } from '@vnodes/property';
3
+ export class EmailOtpEventDto {
4
+ username;
5
+ otp;
6
+ constructor(data) {
7
+ Object.assign(this, data);
8
+ }
9
+ }
10
+ __decorate([
11
+ Prop(),
12
+ __metadata("design:type", String)
13
+ ], EmailOtpEventDto.prototype, "username", void 0);
14
+ __decorate([
15
+ Prop(),
16
+ __metadata("design:type", String)
17
+ ], EmailOtpEventDto.prototype, "otp", void 0);
@@ -0,0 +1,5 @@
1
+ export declare class UpdatePasswordEventDto {
2
+ uuid: string;
3
+ password: string;
4
+ }
5
+ //# sourceMappingURL=update-password-event.dto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update-password-event.dto.d.ts","sourceRoot":"","sources":["../../src/dto/update-password-event.dto.ts"],"names":[],"mappings":"AAEA,qBAAa,sBAAsB;IACL,IAAI,EAAE,MAAM,CAAC;IACO,QAAQ,EAAE,MAAM,CAAC;CAClE"}
@@ -0,0 +1,14 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { Prop } from '@vnodes/property';
3
+ export class UpdatePasswordEventDto {
4
+ uuid;
5
+ password;
6
+ }
7
+ __decorate([
8
+ Prop({ required: true }),
9
+ __metadata("design:type", String)
10
+ ], UpdatePasswordEventDto.prototype, "uuid", void 0);
11
+ __decorate([
12
+ Prop({ required: true, format: 'password' }),
13
+ __metadata("design:type", String)
14
+ ], UpdatePasswordEventDto.prototype, "password", void 0);
@@ -1,11 +1,13 @@
1
1
  import { CanActivate, ExecutionContext } from '@nestjs/common';
2
+ import { ConfigService } from '@nestjs/config';
2
3
  import { Reflector } from '@nestjs/core';
3
- import { UserService } from '../services/user.service.js';
4
+ import { AuthUserService } from '../services/auth-user.service.js';
4
5
  import { AuthRequest } from '../types/auth-request.js';
5
6
  export declare class AuthGuard implements CanActivate {
7
+ protected readonly config: ConfigService;
6
8
  protected readonly reflector: Reflector;
7
- protected readonly userService: UserService;
8
- constructor(reflector: Reflector, userService: UserService);
9
+ protected readonly authUserService: AuthUserService;
10
+ constructor(config: ConfigService, reflector: Reflector, authUserService: AuthUserService);
9
11
  canActivate(context: ExecutionContext): Promise<boolean>;
10
12
  extractToken(request: AuthRequest): string;
11
13
  }
@@ -1 +1 @@
1
- {"version":3,"file":"auth.guard.d.ts","sourceRoot":"","sources":["../../src/guards/auth.guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAqC,MAAM,gBAAgB,CAAC;AAClG,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,qBACa,SAAU,YAAW,WAAW;IAErC,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,SAAS;IACvC,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,WAAW;gBADxB,SAAS,EAAE,SAAS,EACpB,WAAW,EAAE,WAAW;IAGzC,WAAW,CAAC,OAAO,EAAE,gBAAgB;IAqC3C,YAAY,CAAC,OAAO,EAAE,WAAW;CAYpC"}
1
+ {"version":3,"file":"auth.guard.d.ts","sourceRoot":"","sources":["../../src/guards/auth.guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAqC,MAAM,gBAAgB,CAAC;AAClG,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,qBACa,SAAU,YAAW,WAAW;IAErC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,aAAa;IACxC,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,SAAS;IACvC,SAAS,CAAC,QAAQ,CAAC,eAAe,EAAE,eAAe;gBAFhC,MAAM,EAAE,aAAa,EACrB,SAAS,EAAE,SAAS,EACpB,eAAe,EAAE,eAAe;IAGjD,WAAW,CAAC,OAAO,EAAE,gBAAgB;IA0C3C,YAAY,CAAC,OAAO,EAAE,WAAW;CAYpC"}
@@ -1,42 +1,48 @@
1
1
  import { __decorate, __metadata } from "tslib";
2
2
  import { Injectable, UnauthorizedException } from '@nestjs/common';
3
+ import { ConfigService } from '@nestjs/config';
3
4
  import { Reflector } from '@nestjs/core';
4
- import { getPermissions, getRoles, isPublic } from '@vnodes/metadata';
5
- import { UserService } from '../services/user.service.js';
5
+ import { getOperationName, getPermissions, getResourceName, getRoles, isPublic } from '@vnodes/metadata';
6
+ import { AuthUserService } from '../services/auth-user.service.js';
6
7
  let AuthGuard = class AuthGuard {
8
+ config;
7
9
  reflector;
8
- userService;
9
- constructor(reflector, userService) {
10
+ authUserService;
11
+ constructor(config, reflector, authUserService) {
12
+ this.config = config;
10
13
  this.reflector = reflector;
11
- this.userService = userService;
14
+ this.authUserService = authUserService;
12
15
  }
13
16
  async canActivate(context) {
14
17
  if (isPublic(this.reflector, context)) {
15
18
  return true;
16
19
  }
17
- const permissions = getPermissions(this.reflector, context);
18
- const roles = getRoles(this.reflector, context);
19
- const requiredPolicy = ((permissions || roles) && permissions.length > 0) || roles.length > 0;
20
- if (!requiredPolicy) {
21
- return true;
22
- }
20
+ const appId = this.config.getOrThrow('APP_ID', 'none');
21
+ const resourceName = getResourceName(this.reflector, context);
22
+ const operationName = getOperationName(this.reflector, context);
23
+ const requiredPermissions = `${appId}.${resourceName}.${operationName}`;
24
+ const customRequiredPermission = getPermissions(this.reflector, context);
25
+ const requiredRoles = getRoles(this.reflector, context);
23
26
  const authRequest = context.switchToHttp().getRequest();
24
27
  const token = this.extractToken(authRequest);
25
- const user = await this.userService.findByToken(token);
28
+ const user = await this.authUserService.findByToken(token);
26
29
  authRequest.user = user.user;
27
30
  if (user.isAdmin()) {
28
31
  return true;
29
32
  }
30
- if (permissions.length > 0) {
31
- if (!user.hasPermissions(permissions)) {
33
+ if (customRequiredPermission && customRequiredPermission.length > 0) {
34
+ if (!user.hasPermissions(customRequiredPermission)) {
32
35
  return false;
33
36
  }
34
37
  }
35
- if (roles.length > 0) {
36
- if (!user.hasRoles(roles)) {
38
+ if (requiredRoles && requiredRoles.length > 0) {
39
+ if (!user.hasRoles(requiredRoles)) {
37
40
  return false;
38
41
  }
39
42
  }
43
+ if (!user.hasPermissions([requiredPermissions])) {
44
+ return false;
45
+ }
40
46
  return true;
41
47
  }
42
48
  extractToken(request) {
@@ -52,7 +58,8 @@ let AuthGuard = class AuthGuard {
52
58
  };
53
59
  AuthGuard = __decorate([
54
60
  Injectable(),
55
- __metadata("design:paramtypes", [Reflector,
56
- UserService])
61
+ __metadata("design:paramtypes", [ConfigService,
62
+ Reflector,
63
+ AuthUserService])
57
64
  ], AuthGuard);
58
65
  export { AuthGuard };
package/dist/index.d.ts CHANGED
@@ -2,15 +2,20 @@ export * from './auth.controller.js';
2
2
  export * from './auth.module.js';
3
3
  export * from './context/context.js';
4
4
  export * from './dto/access-token.dto.js';
5
+ export * from './dto/email-otp-event.dto.js';
5
6
  export * from './dto/forgot-password.dto.js';
6
7
  export * from './dto/login.dto.js';
7
8
  export * from './dto/login-with-otp.dto.js';
8
9
  export * from './dto/message.dto.js';
9
10
  export * from './dto/otp-response-dto.js';
10
11
  export * from './dto/update-password.dto.js';
12
+ export * from './dto/update-password-event.dto.js';
11
13
  export * from './guards/auth.guard.js';
12
14
  export * from './services/auth.service.js';
13
- export * from './services/user.service.js';
14
- export * from './services/user-manager.js';
15
+ export * from './services/auth-listener.service.js';
16
+ export * from './services/auth-user.service.js';
15
17
  export * from './types/auth-request.js';
18
+ export * from './types/jwt-payload.js';
19
+ export * from './types/user.js';
20
+ export * from './types/user-manager.js';
16
21
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oBAAoB,CAAC;AACnC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC;AACrC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oBAAoB,CAAC;AACnC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC;AACrC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oCAAoC,CAAC;AACnD,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qCAAqC,CAAC;AACpD,cAAc,iCAAiC,CAAC;AAChD,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC"}
package/dist/index.js CHANGED
@@ -3,14 +3,19 @@ export * from './auth.controller.js';
3
3
  export * from './auth.module.js';
4
4
  export * from './context/context.js';
5
5
  export * from './dto/access-token.dto.js';
6
+ export * from './dto/email-otp-event.dto.js';
6
7
  export * from './dto/forgot-password.dto.js';
7
8
  export * from './dto/login.dto.js';
8
9
  export * from './dto/login-with-otp.dto.js';
9
10
  export * from './dto/message.dto.js';
10
11
  export * from './dto/otp-response-dto.js';
11
12
  export * from './dto/update-password.dto.js';
13
+ export * from './dto/update-password-event.dto.js';
12
14
  export * from './guards/auth.guard.js';
13
15
  export * from './services/auth.service.js';
14
- export * from './services/user.service.js';
15
- export * from './services/user-manager.js';
16
+ export * from './services/auth-listener.service.js';
17
+ export * from './services/auth-user.service.js';
16
18
  export * from './types/auth-request.js';
19
+ export * from './types/jwt-payload.js';
20
+ export * from './types/user.js';
21
+ export * from './types/user-manager.js';
@@ -0,0 +1,10 @@
1
+ import { EmailOtpEventDto } from '../dto/email-otp-event.dto.js';
2
+ import { UpdatePasswordEventDto } from '../dto/update-password-event.dto.js';
3
+ /**
4
+ * Extend an override the methods requried
5
+ */
6
+ export declare class AuthListenerService {
7
+ protected updatePassword(body: UpdatePasswordEventDto): Promise<void>;
8
+ protected emailOtp(body: EmailOtpEventDto): Promise<void>;
9
+ }
10
+ //# sourceMappingURL=auth-listener.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-listener.service.d.ts","sourceRoot":"","sources":["../../src/services/auth-listener.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAE7E;;GAEG;AACH,qBACa,mBAAmB;cAEZ,cAAc,CAAC,IAAI,EAAE,sBAAsB;cAK3C,QAAQ,CAAC,IAAI,EAAE,gBAAgB;CAGlD"}
@@ -0,0 +1,32 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { Injectable, NotImplementedException } from '@nestjs/common';
3
+ import { OnEvent } from '@nestjs/event-emitter';
4
+ import { EmailOtpEventDto } from '../dto/email-otp-event.dto.js';
5
+ import { UpdatePasswordEventDto } from '../dto/update-password-event.dto.js';
6
+ /**
7
+ * Extend an override the methods requried
8
+ */
9
+ let AuthListenerService = class AuthListenerService {
10
+ async updatePassword(body) {
11
+ throw new NotImplementedException(`Password update for the user with uuid: ${body.uuid} is not implemented`);
12
+ }
13
+ async emailOtp(body) {
14
+ throw new NotImplementedException(`Email otp is not implemented: ${body.username}`);
15
+ }
16
+ };
17
+ __decorate([
18
+ OnEvent('auth.user.update.password'),
19
+ __metadata("design:type", Function),
20
+ __metadata("design:paramtypes", [UpdatePasswordEventDto]),
21
+ __metadata("design:returntype", Promise)
22
+ ], AuthListenerService.prototype, "updatePassword", null);
23
+ __decorate([
24
+ OnEvent('auth.user.email.otp'),
25
+ __metadata("design:type", Function),
26
+ __metadata("design:paramtypes", [EmailOtpEventDto]),
27
+ __metadata("design:returntype", Promise)
28
+ ], AuthListenerService.prototype, "emailOtp", null);
29
+ AuthListenerService = __decorate([
30
+ Injectable()
31
+ ], AuthListenerService);
32
+ export { AuthListenerService };
@@ -1,8 +1,10 @@
1
1
  import { JwtService } from '@nestjs/jwt';
2
- import { User, UserManager } from './user-manager.js';
3
- export declare class UserService {
2
+ import { User } from '../types/user.js';
3
+ import { UserManager } from '../types/user-manager.js';
4
+ export declare class AuthUserService {
4
5
  protected readonly jwt: JwtService;
5
6
  protected readonly usernameMap: Map<string, User>;
7
+ protected readonly uuidUsernameMap: Map<string, string>;
6
8
  protected readonly tokenUsernameMap: Map<string, string>;
7
9
  protected readonly usernameOtpMap: Map<string, string>;
8
10
  constructor(jwt: JwtService);
@@ -11,10 +13,11 @@ export declare class UserService {
11
13
  load(users: User[]): void;
12
14
  findByUsername(username: string): UserManager;
13
15
  findByToken(token: string): UserManager;
16
+ findByUuid(uuid: string): UserManager;
14
17
  deleteToken(token: string): boolean;
15
18
  updateToken(token: string, username: string): void;
16
19
  createOtp(username: string): string;
17
20
  compareOtp(username: string, otp: string): boolean;
18
21
  deleteOtp(username: string): void;
19
22
  }
20
- //# sourceMappingURL=user.service.d.ts.map
23
+ //# sourceMappingURL=auth-user.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-user.service.d.ts","sourceRoot":"","sources":["../../src/services/auth-user.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,qBACa,eAAe;IAMZ,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,UAAU;IAL9C,SAAS,CAAC,QAAQ,CAAC,WAAW,oBAA2B;IACzD,SAAS,CAAC,QAAQ,CAAC,eAAe,sBAA6B;IAC/D,SAAS,CAAC,QAAQ,CAAC,gBAAgB,sBAA6B;IAChE,SAAS,CAAC,QAAQ,CAAC,cAAc,sBAA6B;gBAE/B,GAAG,EAAE,UAAU;IAE9C,MAAM,CAAC,IAAI,EAAE,IAAI;IAIjB,gBAAgB,CAAC,QAAQ,EAAE,MAAM;IAIjC,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE;IAQlB,cAAc,CAAC,QAAQ,EAAE,MAAM;IAQ/B,WAAW,CAAC,KAAK,EAAE,MAAM;IASzB,UAAU,CAAC,IAAI,EAAE,MAAM;IAQvB,WAAW,CAAC,KAAK,EAAE,MAAM;IAOzB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAI3C,SAAS,CAAC,QAAQ,EAAE,MAAM;IAM1B,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM;IAYxC,SAAS,CAAC,QAAQ,EAAE,MAAM;CAG7B"}
@@ -1,11 +1,12 @@
1
- import { __decorate, __metadata, __param } from "tslib";
2
- import { Inject, Injectable, NotFoundException, UnauthorizedException } from '@nestjs/common';
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { Injectable, NotFoundException, UnauthorizedException } from '@nestjs/common';
3
3
  import { JwtService } from '@nestjs/jwt';
4
4
  import { otp } from '@vnodes/crypto';
5
- import { UserManager } from './user-manager.js';
6
- let UserService = class UserService {
5
+ import { UserManager } from '../types/user-manager.js';
6
+ let AuthUserService = class AuthUserService {
7
7
  jwt;
8
8
  usernameMap = new Map();
9
+ uuidUsernameMap = new Map();
9
10
  tokenUsernameMap = new Map();
10
11
  usernameOtpMap = new Map();
11
12
  constructor(jwt) {
@@ -21,6 +22,7 @@ let UserService = class UserService {
21
22
  this.usernameMap.clear();
22
23
  for (const user of users) {
23
24
  this.usernameMap.set(user.username, user);
25
+ this.uuidUsernameMap.set(user.uuid, user.username);
24
26
  }
25
27
  }
26
28
  findByUsername(username) {
@@ -37,6 +39,13 @@ let UserService = class UserService {
37
39
  }
38
40
  throw new UnauthorizedException(`User not found by token`);
39
41
  }
42
+ findByUuid(uuid) {
43
+ const username = this.uuidUsernameMap.get(uuid);
44
+ if (username) {
45
+ return this.findByUsername(username);
46
+ }
47
+ throw new UnauthorizedException(`User not found by uuid`);
48
+ }
40
49
  deleteToken(token) {
41
50
  if (this.tokenUsernameMap.delete(token)) {
42
51
  return true;
@@ -67,9 +76,8 @@ let UserService = class UserService {
67
76
  this.usernameOtpMap.delete(username);
68
77
  }
69
78
  };
70
- UserService = __decorate([
79
+ AuthUserService = __decorate([
71
80
  Injectable(),
72
- __param(0, Inject(JwtService)),
73
81
  __metadata("design:paramtypes", [JwtService])
74
- ], UserService);
75
- export { UserService };
82
+ ], AuthUserService);
83
+ export { AuthUserService };
@@ -1,14 +1,15 @@
1
1
  import { EventEmitter2 } from '@nestjs/event-emitter';
2
+ import { UpdatePasswordDto } from 'src/dto/update-password.dto.js';
2
3
  import { AccessTokenDto } from '../dto/access-token.dto.js';
3
4
  import { ForgotPasswordDto } from '../dto/forgot-password.dto.js';
4
5
  import { LoginDto } from '../dto/login.dto.js';
5
6
  import { LoginWithOtpDto } from '../dto/login-with-otp.dto.js';
6
7
  import { MessageDto } from '../dto/message.dto.js';
7
- import { UserService } from './user.service.js';
8
+ import { AuthUserService } from './auth-user.service.js';
8
9
  export declare class AuthService {
9
- protected readonly userService: UserService;
10
+ protected readonly authUserService: AuthUserService;
10
11
  protected readonly eventEmitter: EventEmitter2;
11
- constructor(userService: UserService, eventEmitter: EventEmitter2);
12
+ constructor(authUserService: AuthUserService, eventEmitter: EventEmitter2);
12
13
  /**
13
14
  * Login with credentials (find user by username and compare the passed with hashed password)
14
15
  * @param body -- {@link LoginDto}
@@ -33,5 +34,12 @@ export declare class AuthService {
33
34
  * @returns -- {@link MessageDto}
34
35
  */
35
36
  forgotPassword(body: ForgotPasswordDto): MessageDto;
37
+ /**
38
+ *
39
+ * @param uuid
40
+ * @param body
41
+ */
42
+ updatePassword(uuid: string, body: UpdatePasswordDto): Promise<MessageDto>;
43
+ profile(uuid: string): import("../index.js").UserManager;
36
44
  }
37
45
  //# sourceMappingURL=auth.service.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"auth.service.d.ts","sourceRoot":"","sources":["../../src/services/auth.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,qBACa,WAAW;IAEhB,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,WAAW;IAC3C,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,aAAa;gBAD3B,WAAW,EAAE,WAAW,EACxB,YAAY,EAAE,aAAa;IAGlD;;;;OAIG;IACG,KAAK,CAAC,IAAI,EAAE,QAAQ;IAQ1B;;;;OAIG;IACG,YAAY,CAAC,IAAI,EAAE,eAAe;IAQxC;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM;IAKpB;;;;OAIG;IACH,cAAc,CAAC,IAAI,EAAE,iBAAiB;CAKzC"}
1
+ {"version":3,"file":"auth.service.d.ts","sourceRoot":"","sources":["../../src/services/auth.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,qBACa,WAAW;IAEhB,SAAS,CAAC,QAAQ,CAAC,eAAe,EAAE,eAAe;IACnD,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,aAAa;gBAD3B,eAAe,EAAE,eAAe,EAChC,YAAY,EAAE,aAAa;IAGlD;;;;OAIG;IACG,KAAK,CAAC,IAAI,EAAE,QAAQ;IAQ1B;;;;OAIG;IACG,YAAY,CAAC,IAAI,EAAE,eAAe;IAQxC;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM;IAKpB;;;;OAIG;IACH,cAAc,CAAC,IAAI,EAAE,iBAAiB;IAMtC;;;;OAIG;IACG,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,iBAAiB;IAK1D,OAAO,CAAC,IAAI,EAAE,MAAM;CAGvB"}
@@ -1,15 +1,16 @@
1
1
  import { __decorate, __metadata } from "tslib";
2
2
  import { Injectable } from '@nestjs/common';
3
3
  import { EventEmitter2 } from '@nestjs/event-emitter';
4
+ import { hash } from '@vnodes/crypto';
4
5
  import { AccessTokenDto } from '../dto/access-token.dto.js';
5
6
  import { MessageDto } from '../dto/message.dto.js';
6
7
  import { OtpResponseDto } from '../dto/otp-response-dto.js';
7
- import { UserService } from './user.service.js';
8
+ import { AuthUserService } from './auth-user.service.js';
8
9
  let AuthService = class AuthService {
9
- userService;
10
+ authUserService;
10
11
  eventEmitter;
11
- constructor(userService, eventEmitter) {
12
- this.userService = userService;
12
+ constructor(authUserService, eventEmitter) {
13
+ this.authUserService = authUserService;
13
14
  this.eventEmitter = eventEmitter;
14
15
  }
15
16
  /**
@@ -18,10 +19,10 @@ let AuthService = class AuthService {
18
19
  * @returns -- {@link AccessTokenDto}
19
20
  */
20
21
  async login(body) {
21
- const user = this.userService.findByUsername(body.username);
22
+ const user = this.authUserService.findByUsername(body.username);
22
23
  await user.comparePassword(body.password);
23
24
  const token = await user.signToken();
24
- this.userService.updateToken(token, user.user.username);
25
+ this.authUserService.updateToken(token, user.user.username);
25
26
  return new AccessTokenDto({ token });
26
27
  }
27
28
  /**
@@ -30,9 +31,9 @@ let AuthService = class AuthService {
30
31
  * @returns -- {@link AccessTokenDto}
31
32
  */
32
33
  async loginWithOtp(body) {
33
- this.userService.compareOtp(body.username, body.otp);
34
- this.userService.deleteOtp(body.username);
35
- const user = this.userService.findByUsername(body.username);
34
+ this.authUserService.compareOtp(body.username, body.otp);
35
+ this.authUserService.deleteOtp(body.username);
36
+ const user = this.authUserService.findByUsername(body.username);
36
37
  const token = await user.signToken();
37
38
  return new AccessTokenDto({ token });
38
39
  }
@@ -42,7 +43,7 @@ let AuthService = class AuthService {
42
43
  * @returns -- {@link MessageDto}
43
44
  */
44
45
  logout(token) {
45
- this.userService.deleteToken(token);
46
+ this.authUserService.deleteToken(token);
46
47
  return new MessageDto({ message: 'Bye for now' });
47
48
  }
48
49
  /**
@@ -51,14 +52,26 @@ let AuthService = class AuthService {
51
52
  * @returns -- {@link MessageDto}
52
53
  */
53
54
  forgotPassword(body) {
54
- const otp = this.userService.createOtp(body.username);
55
- this.eventEmitter.emit('email.otp', new OtpResponseDto({ otp }));
55
+ const otp = this.authUserService.createOtp(body.username);
56
+ this.eventEmitter.emit('auth.user.email.otp', new OtpResponseDto({ otp }));
56
57
  return new MessageDto({ message: 'We sent the otp to your email' });
57
58
  }
59
+ /**
60
+ *
61
+ * @param uuid
62
+ * @param body
63
+ */
64
+ async updatePassword(uuid, body) {
65
+ this.eventEmitter.emit('auth.user.update.password', { uuid, password: await hash(body.password) });
66
+ return new MessageDto({ message: 'Update password request is sent' });
67
+ }
68
+ profile(uuid) {
69
+ return this.authUserService.findByUuid(uuid);
70
+ }
58
71
  };
59
72
  AuthService = __decorate([
60
73
  Injectable(),
61
- __metadata("design:paramtypes", [UserService,
74
+ __metadata("design:paramtypes", [AuthUserService,
62
75
  EventEmitter2])
63
76
  ], AuthService);
64
77
  export { AuthService };
@@ -1,4 +1,4 @@
1
- import { User } from '../services/user-manager.js';
1
+ import { User } from './user.js';
2
2
  export type HeaderNames = 'authorization';
3
3
  export type AuthRequest = {
4
4
  user: User;
@@ -1 +1 @@
1
- {"version":3,"file":"auth-request.d.ts","sourceRoot":"","sources":["../../src/types/auth-request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AACnD,MAAM,MAAM,WAAW,GAAG,eAAe,CAAC;AAC1C,MAAM,MAAM,WAAW,GAAG;IACtB,IAAI,EAAE,IAAI,CAAC;IACX,OAAO,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IACrC,WAAW,EAAE,MAAM,CAAC;CACvB,CAAC"}
1
+ {"version":3,"file":"auth-request.d.ts","sourceRoot":"","sources":["../../src/types/auth-request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,MAAM,WAAW,GAAG,eAAe,CAAC;AAE1C,MAAM,MAAM,WAAW,GAAG;IACtB,IAAI,EAAE,IAAI,CAAC;IACX,OAAO,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IACrC,WAAW,EAAE,MAAM,CAAC;CACvB,CAAC"}
@@ -0,0 +1,6 @@
1
+ export declare class JwtPayload {
2
+ sub: string;
3
+ username: string;
4
+ version: string;
5
+ }
6
+ //# sourceMappingURL=jwt-payload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwt-payload.d.ts","sourceRoot":"","sources":["../../src/types/jwt-payload.ts"],"names":[],"mappings":"AAAA,qBAAa,UAAU;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACnB"}
@@ -0,0 +1,5 @@
1
+ export class JwtPayload {
2
+ sub;
3
+ username;
4
+ version;
5
+ }
@@ -1,18 +1,6 @@
1
1
  import { JwtService } from '@nestjs/jwt';
2
- export declare class JwtPayload {
3
- sub: number;
4
- username: string;
5
- version: string;
6
- }
7
- export declare class User {
8
- id: number;
9
- version: string;
10
- username: string;
11
- password: string;
12
- permissions?: string[];
13
- roles?: string[];
14
- constructor(user: User);
15
- }
2
+ import { JwtPayload } from './jwt-payload.js';
3
+ import { User } from './user.js';
16
4
  export declare class UserManager {
17
5
  protected readonly userData: User;
18
6
  protected readonly jwt: JwtService;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user-manager.d.ts","sourceRoot":"","sources":["../../src/types/user-manager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,qBAAa,WAAW;IAEhB,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI;IACjC,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,UAAU;gBADf,QAAQ,EAAE,IAAI,EACd,GAAG,EAAE,UAAU;IAGtC;;OAEG;IACH,IAAI,IAAI,IAAI,IAAI,CAEf;IAED;;OAEG;IACH,IAAI,WAAW,gBAEd;IAED;;OAEG;IACH,IAAI,KAAK,gBAER;IAED;;OAEG;IACH,IAAI,OAAO,WAEV;IAED;;OAEG;IACH,OAAO;IAIP;;OAEG;IACH,cAAc,CAAC,mBAAmB,EAAE,MAAM,EAAE;IAO5C;;OAEG;IACH,QAAQ,CAAC,aAAa,EAAE,MAAM,EAAE;IAOhC;;;OAGG;IACH,YAAY,IAAI,UAAU;IAQ1B;;;;OAIG;IACG,eAAe,CAAC,QAAQ,EAAE,MAAM;IAOtC;;;OAGG;IACG,SAAS;IAKf;;;;OAIG;IACG,WAAW,CAAC,KAAK,EAAE,MAAM;CASlC"}
@@ -1,27 +1,6 @@
1
1
  import { ForbiddenException, UnauthorizedException } from '@nestjs/common';
2
2
  import { compare } from '@vnodes/crypto';
3
- export class JwtPayload {
4
- sub;
5
- username;
6
- version;
7
- }
8
- export class User {
9
- id;
10
- version;
11
- username;
12
- password;
13
- permissions;
14
- roles;
15
- constructor(user) {
16
- Object.assign(this, user);
17
- if (user.permissions && user.permissions?.length > 0) {
18
- this.permissions = user.permissions;
19
- }
20
- if (user.roles && user.roles?.length > 0) {
21
- this.roles = user.roles;
22
- }
23
- }
24
- }
3
+ import { User } from './user.js';
25
4
  export class UserManager {
26
5
  userData;
27
6
  jwt;
@@ -83,7 +62,7 @@ export class UserManager {
83
62
  */
84
63
  toJwtPayload() {
85
64
  return {
86
- sub: this.userData.id,
65
+ sub: this.userData.uuid,
87
66
  username: this.userData.username,
88
67
  version: this.userData.version,
89
68
  };
@@ -0,0 +1,10 @@
1
+ export declare class User {
2
+ uuid: string;
3
+ version: string;
4
+ username: string;
5
+ password: string;
6
+ permissions?: string[];
7
+ roles?: string[];
8
+ constructor(user: User);
9
+ }
10
+ //# sourceMappingURL=user.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../src/types/user.ts"],"names":[],"mappings":"AAAA,qBAAa,IAAI;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;gBAEL,IAAI,EAAE,IAAI;CAWzB"}
@@ -0,0 +1,17 @@
1
+ export class User {
2
+ uuid;
3
+ version;
4
+ username;
5
+ password;
6
+ permissions;
7
+ roles;
8
+ constructor(user) {
9
+ Object.assign(this, user);
10
+ if (user.permissions && user.permissions?.length > 0) {
11
+ this.permissions = user.permissions;
12
+ }
13
+ if (user.roles && user.roles?.length > 0) {
14
+ this.roles = user.roles;
15
+ }
16
+ }
17
+ }
package/package.json CHANGED
@@ -19,7 +19,7 @@
19
19
  "url": "https://cash.app/$puqlib"
20
20
  }
21
21
  ],
22
- "version": "0.0.3",
22
+ "version": "0.0.8",
23
23
  "type": "module",
24
24
  "main": "./dist/index.js",
25
25
  "module": "./dist/index.js",
@@ -61,8 +61,8 @@
61
61
  "@nestjs/jwt": "^11.0.2",
62
62
  "@nestjs/swagger": "^11.2.6",
63
63
  "@nestjs/throttler": "^6.5.0",
64
- "@vnodes/crypto": "0.0.3",
65
- "@vnodes/property": "0.0.3",
66
- "@vnodes/metadata": "0.0.3"
64
+ "@vnodes/crypto": "0.0.8",
65
+ "@vnodes/metadata": "0.0.8",
66
+ "@vnodes/property": "0.0.8"
67
67
  }
68
68
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"user-manager.d.ts","sourceRoot":"","sources":["../../src/services/user-manager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,qBAAa,UAAU;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACnB;AAED,qBAAa,IAAI;IACb,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;gBAEL,IAAI,EAAE,IAAI;CAWzB;AAED,qBAAa,WAAW;IAEhB,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI;IACjC,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,UAAU;gBADf,QAAQ,EAAE,IAAI,EACd,GAAG,EAAE,UAAU;IAGtC;;OAEG;IACH,IAAI,IAAI,IAAI,IAAI,CAEf;IAED;;OAEG;IACH,IAAI,WAAW,gBAEd;IAED;;OAEG;IACH,IAAI,KAAK,gBAER;IAED;;OAEG;IACH,IAAI,OAAO,WAEV;IAED;;OAEG;IACH,OAAO;IAIP;;OAEG;IACH,cAAc,CAAC,mBAAmB,EAAE,MAAM,EAAE;IAO5C;;OAEG;IACH,QAAQ,CAAC,aAAa,EAAE,MAAM,EAAE;IAOhC;;;OAGG;IACH,YAAY,IAAI,UAAU;IAQ1B;;;;OAIG;IACG,eAAe,CAAC,QAAQ,EAAE,MAAM;IAOtC;;;OAGG;IACG,SAAS;IAKf;;;;OAIG;IACG,WAAW,CAAC,KAAK,EAAE,MAAM;CASlC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"user.service.d.ts","sourceRoot":"","sources":["../../src/services/user.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEtD,qBACa,WAAW;IAKY,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,UAAU;IAJlE,SAAS,CAAC,QAAQ,CAAC,WAAW,oBAA2B;IACzD,SAAS,CAAC,QAAQ,CAAC,gBAAgB,sBAA6B;IAChE,SAAS,CAAC,QAAQ,CAAC,cAAc,sBAA6B;gBAEX,GAAG,EAAE,UAAU;IAElE,MAAM,CAAC,IAAI,EAAE,IAAI;IAIjB,gBAAgB,CAAC,QAAQ,EAAE,MAAM;IAIjC,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE;IAOlB,cAAc,CAAC,QAAQ,EAAE,MAAM;IAQ/B,WAAW,CAAC,KAAK,EAAE,MAAM;IASzB,WAAW,CAAC,KAAK,EAAE,MAAM;IAOzB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAI3C,SAAS,CAAC,QAAQ,EAAE,MAAM;IAM1B,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM;IAYxC,SAAS,CAAC,QAAQ,EAAE,MAAM;CAG7B"}