@vnodes/auth 0.0.15 → 0.0.25

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 (90) hide show
  1. package/README.md +3 -3
  2. package/bin/version.mjs +12 -0
  3. package/dist/index.d.ts +1 -26
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +3 -27
  6. package/dist/index.js.map +1 -0
  7. package/dist/lib/auth.d.ts +2 -0
  8. package/dist/lib/auth.d.ts.map +1 -0
  9. package/dist/lib/auth.js +5 -0
  10. package/dist/lib/auth.js.map +1 -0
  11. package/package.json +19 -30
  12. package/assets/favicon.png +0 -0
  13. package/dist/auth.controller.d.ts +0 -16
  14. package/dist/auth.controller.d.ts.map +0 -1
  15. package/dist/auth.controller.js +0 -90
  16. package/dist/auth.module.d.ts +0 -3
  17. package/dist/auth.module.d.ts.map +0 -1
  18. package/dist/auth.module.js +0 -38
  19. package/dist/client/auth-client.module.d.ts +0 -3
  20. package/dist/client/auth-client.module.d.ts.map +0 -1
  21. package/dist/client/auth-client.module.js +0 -21
  22. package/dist/context/context.d.ts +0 -12
  23. package/dist/context/context.d.ts.map +0 -1
  24. package/dist/context/context.js +0 -19
  25. package/dist/dto/access-token.dto.d.ts +0 -5
  26. package/dist/dto/access-token.dto.d.ts.map +0 -1
  27. package/dist/dto/access-token.dto.js +0 -12
  28. package/dist/dto/can-activate-response-dto.d.ts +0 -5
  29. package/dist/dto/can-activate-response-dto.d.ts.map +0 -1
  30. package/dist/dto/can-activate-response-dto.js +0 -12
  31. package/dist/dto/can-activate.dto.d.ts +0 -6
  32. package/dist/dto/can-activate.dto.d.ts.map +0 -1
  33. package/dist/dto/can-activate.dto.js +0 -17
  34. package/dist/dto/email-otp-event.dto.d.ts +0 -6
  35. package/dist/dto/email-otp-event.dto.d.ts.map +0 -1
  36. package/dist/dto/email-otp-event.dto.js +0 -17
  37. package/dist/dto/forgot-password.dto.d.ts +0 -4
  38. package/dist/dto/forgot-password.dto.d.ts.map +0 -1
  39. package/dist/dto/forgot-password.dto.js +0 -9
  40. package/dist/dto/login-with-otp.dto.d.ts +0 -5
  41. package/dist/dto/login-with-otp.dto.d.ts.map +0 -1
  42. package/dist/dto/login-with-otp.dto.js +0 -14
  43. package/dist/dto/login.dto.d.ts +0 -5
  44. package/dist/dto/login.dto.d.ts.map +0 -1
  45. package/dist/dto/login.dto.js +0 -14
  46. package/dist/dto/message.dto.d.ts +0 -5
  47. package/dist/dto/message.dto.d.ts.map +0 -1
  48. package/dist/dto/message.dto.js +0 -12
  49. package/dist/dto/otp-response-dto.d.ts +0 -5
  50. package/dist/dto/otp-response-dto.d.ts.map +0 -1
  51. package/dist/dto/otp-response-dto.js +0 -12
  52. package/dist/dto/update-password-event.dto.d.ts +0 -5
  53. package/dist/dto/update-password-event.dto.d.ts.map +0 -1
  54. package/dist/dto/update-password-event.dto.js +0 -14
  55. package/dist/dto/update-password.dto.d.ts +0 -4
  56. package/dist/dto/update-password.dto.d.ts.map +0 -1
  57. package/dist/dto/update-password.dto.js +0 -9
  58. package/dist/guards/auth-client.guard.d.ts +0 -14
  59. package/dist/guards/auth-client.guard.d.ts.map +0 -1
  60. package/dist/guards/auth-client.guard.js +0 -64
  61. package/dist/guards/auth.guard.d.ts +0 -16
  62. package/dist/guards/auth.guard.d.ts.map +0 -1
  63. package/dist/guards/auth.guard.js +0 -71
  64. package/dist/providers/auth-client-options.provider.d.ts +0 -5
  65. package/dist/providers/auth-client-options.provider.d.ts.map +0 -1
  66. package/dist/providers/auth-client-options.provider.js +0 -21
  67. package/dist/services/auth-listener.service.d.ts +0 -10
  68. package/dist/services/auth-listener.service.d.ts.map +0 -1
  69. package/dist/services/auth-listener.service.js +0 -32
  70. package/dist/services/auth-user.service.d.ts +0 -28
  71. package/dist/services/auth-user.service.d.ts.map +0 -1
  72. package/dist/services/auth-user.service.js +0 -94
  73. package/dist/services/auth.service.d.ts +0 -48
  74. package/dist/services/auth.service.d.ts.map +0 -1
  75. package/dist/services/auth.service.js +0 -84
  76. package/dist/types/auth-client-options.d.ts +0 -6
  77. package/dist/types/auth-client-options.d.ts.map +0 -1
  78. package/dist/types/auth-client-options.js +0 -7
  79. package/dist/types/auth-request.d.ts +0 -8
  80. package/dist/types/auth-request.d.ts.map +0 -1
  81. package/dist/types/auth-request.js +0 -1
  82. package/dist/types/jwt-payload.d.ts +0 -6
  83. package/dist/types/jwt-payload.d.ts.map +0 -1
  84. package/dist/types/jwt-payload.js +0 -5
  85. package/dist/types/user-manager.d.ts +0 -67
  86. package/dist/types/user-manager.d.ts.map +0 -1
  87. package/dist/types/user-manager.js +0 -118
  88. package/dist/types/user.d.ts +0 -10
  89. package/dist/types/user.d.ts.map +0 -1
  90. package/dist/types/user.js +0 -17
@@ -1,6 +0,0 @@
1
- export declare class JwtPayload {
2
- sub: string;
3
- username: string;
4
- version: string;
5
- }
6
- //# sourceMappingURL=jwt-payload.d.ts.map
@@ -1 +0,0 @@
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"}
@@ -1,5 +0,0 @@
1
- export class JwtPayload {
2
- sub;
3
- username;
4
- version;
5
- }
@@ -1,67 +0,0 @@
1
- import { JwtService } from '@nestjs/jwt';
2
- import { CanActivateDto } from 'src/dto/can-activate.dto.js';
3
- import { JwtPayload } from './jwt-payload.js';
4
- import { User } from './user.js';
5
- export declare class UserManager {
6
- protected readonly userData: User;
7
- protected readonly jwt: JwtService;
8
- constructor(userData: User, jwt: JwtService);
9
- /**
10
- * Get the user data
11
- */
12
- get user(): User;
13
- /**
14
- * Get the set of user permissions
15
- */
16
- get permisisons(): Set<string>;
17
- /**
18
- * Get the set of user roles
19
- */
20
- get roles(): Set<string>;
21
- /**
22
- * Get the user version
23
- */
24
- get version(): string;
25
- /**
26
- * Check the user has the "admin" role
27
- */
28
- isAdmin(): boolean;
29
- /**
30
- * Check the user has all {@link requiredPermissions} or throw {@link ForbiddenException}
31
- */
32
- hasAllPermissions(requiredPermissions: string[]): boolean;
33
- /**
34
- * Check the user has one of the {@link requiredRoles} or throw {@link ForbiddenException}
35
- */
36
- hasSomeRoles(requiredRoles: string[]): boolean;
37
- canActivate(body: CanActivateDto): boolean | undefined;
38
- /**
39
- * Create the jwt payload object {@link JwtPayload}
40
- * @returns -- {@link JwtPayload}
41
- */
42
- toJwtPayload(): JwtPayload;
43
- /**
44
- * Compare the plain password with the hashed password
45
- * @param password plain password
46
- * @returns boolean or throw {@link UnauthorizedException}
47
- */
48
- comparePassword(password: string): Promise<boolean>;
49
- /**
50
- * Sign the jwt token
51
- * @returns jwt token
52
- */
53
- signToken(): Promise<string>;
54
- /**
55
- * Verify jwt {@link token}
56
- * @param token jwt token
57
- * @returns string or throw {@link UnauthorizedException} that indicated invalid or old versioned token
58
- */
59
- verifyToken(token: string): Promise<JwtPayload>;
60
- /**
61
- * Check the jwt version matches with the provided token's version or thow Invalid Jwt version error
62
- * @param version
63
- * @returns
64
- */
65
- verifyVersion(version: string): boolean;
66
- }
67
- //# sourceMappingURL=user-manager.d.ts.map
@@ -1 +0,0 @@
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,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,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,iBAAiB,CAAC,mBAAmB,EAAE,MAAM,EAAE;IAO/C;;OAEG;IACH,YAAY,CAAC,aAAa,EAAE,MAAM,EAAE;IAOpC,WAAW,CAAC,IAAI,EAAE,cAAc;IAYhC;;;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;IAM/B;;;;OAIG;IACH,aAAa,CAAC,OAAO,EAAE,MAAM;CAMhC"}
@@ -1,118 +0,0 @@
1
- import { ForbiddenException, UnauthorizedException } from '@nestjs/common';
2
- import { compare } from '@vnodes/crypto';
3
- import { User } from './user.js';
4
- export class UserManager {
5
- userData;
6
- jwt;
7
- constructor(userData, jwt) {
8
- this.userData = userData;
9
- this.jwt = jwt;
10
- }
11
- /**
12
- * Get the user data
13
- */
14
- get user() {
15
- return new User(this.userData);
16
- }
17
- /**
18
- * Get the set of user permissions
19
- */
20
- get permisisons() {
21
- return new Set(this.userData.permissions ?? []);
22
- }
23
- /**
24
- * Get the set of user roles
25
- */
26
- get roles() {
27
- return new Set(this.userData.roles ?? []);
28
- }
29
- /**
30
- * Get the user version
31
- */
32
- get version() {
33
- return this.userData.version;
34
- }
35
- /**
36
- * Check the user has the "admin" role
37
- */
38
- isAdmin() {
39
- return this.roles.has('Admin');
40
- }
41
- /**
42
- * Check the user has all {@link requiredPermissions} or throw {@link ForbiddenException}
43
- */
44
- hasAllPermissions(requiredPermissions) {
45
- if (requiredPermissions.every((permission) => this.permisisons.has(permission))) {
46
- return true;
47
- }
48
- throw new ForbiddenException('Insufficient permissions');
49
- }
50
- /**
51
- * Check the user has one of the {@link requiredRoles} or throw {@link ForbiddenException}
52
- */
53
- hasSomeRoles(requiredRoles) {
54
- if (requiredRoles.some((role) => this.roles.has(role))) {
55
- return true;
56
- }
57
- throw new ForbiddenException('Insufficient role');
58
- }
59
- canActivate(body) {
60
- const { requiredPermissions, requiredRoles } = body;
61
- if (this.isAdmin()) {
62
- return true;
63
- }
64
- return ((requiredRoles && this.hasSomeRoles(requiredRoles)) ||
65
- (requiredPermissions && this.hasAllPermissions(requiredPermissions)));
66
- }
67
- /**
68
- * Create the jwt payload object {@link JwtPayload}
69
- * @returns -- {@link JwtPayload}
70
- */
71
- toJwtPayload() {
72
- return {
73
- sub: this.userData.uuid,
74
- username: this.userData.username,
75
- version: this.userData.version,
76
- };
77
- }
78
- /**
79
- * Compare the plain password with the hashed password
80
- * @param password plain password
81
- * @returns boolean or throw {@link UnauthorizedException}
82
- */
83
- async comparePassword(password) {
84
- if (await compare(password, this.userData.password)) {
85
- return true;
86
- }
87
- throw new UnauthorizedException(`Wrong password`);
88
- }
89
- /**
90
- * Sign the jwt token
91
- * @returns jwt token
92
- */
93
- async signToken() {
94
- const token = await this.jwt.signAsync(this.toJwtPayload());
95
- return token;
96
- }
97
- /**
98
- * Verify jwt {@link token}
99
- * @param token jwt token
100
- * @returns string or throw {@link UnauthorizedException} that indicated invalid or old versioned token
101
- */
102
- async verifyToken(token) {
103
- const jwtPayload = await this.jwt.verifyAsync(token);
104
- this.verifyVersion(jwtPayload.version);
105
- return jwtPayload;
106
- }
107
- /**
108
- * Check the jwt version matches with the provided token's version or thow Invalid Jwt version error
109
- * @param version
110
- * @returns
111
- */
112
- verifyVersion(version) {
113
- if (this.version !== version) {
114
- throw new UnauthorizedException(`Invalid jwt version`);
115
- }
116
- return true;
117
- }
118
- }
@@ -1,10 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,17 +0,0 @@
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
- }