@nest-boot/auth 6.10.7 → 6.11.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/auth.guard.d.ts +2 -14
- package/dist/auth.guard.js +7 -50
- package/dist/auth.guard.js.map +1 -1
- package/dist/auth.module.d.ts +14 -1
- package/dist/auth.module.js +61 -1
- package/dist/auth.module.js.map +1 -1
- package/dist/auth.service.d.ts +5 -3
- package/dist/auth.service.js +10 -3
- package/dist/auth.service.js.map +1 -1
- package/dist/entities/user.entity.d.ts +2 -2
- package/dist/entities/user.entity.js +3 -4
- package/dist/entities/user.entity.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +5 -5
package/dist/auth.guard.d.ts
CHANGED
|
@@ -1,36 +1,24 @@
|
|
|
1
|
-
import { EntityManager } from "@mikro-orm/core";
|
|
2
1
|
import { type CanActivate, type ExecutionContext } from "@nestjs/common";
|
|
3
2
|
import { Reflector } from "@nestjs/core";
|
|
4
|
-
import { AuthService } from "./auth.service";
|
|
5
3
|
import { AuthModuleOptions } from "./interfaces";
|
|
6
4
|
/**
|
|
7
5
|
* Authentication guard class used to protect routes and handle requests.
|
|
8
6
|
*/
|
|
9
7
|
export declare class AuthGuard implements CanActivate {
|
|
10
8
|
private readonly reflector;
|
|
11
|
-
private readonly em;
|
|
12
|
-
private readonly authService;
|
|
13
9
|
private readonly options;
|
|
14
10
|
private readonly defaultRequireAuth;
|
|
15
|
-
|
|
16
|
-
private readonly personalAccessTokenEntityClass;
|
|
17
|
-
constructor(reflector: Reflector, em: EntityManager, authService: AuthService, options: AuthModuleOptions);
|
|
11
|
+
constructor(reflector: Reflector, options: AuthModuleOptions);
|
|
18
12
|
/**
|
|
19
13
|
* Get internationalized text based on the specified key.
|
|
20
14
|
* @param key - The key of the internationalized text.
|
|
21
15
|
* @returns The internationalized text.
|
|
22
16
|
*/
|
|
23
17
|
private t;
|
|
24
|
-
/**
|
|
25
|
-
* Extracts the personal access token from the request.
|
|
26
|
-
* @param req - The request object.
|
|
27
|
-
* @returns The personal access token, or null if it doesn't exist.
|
|
28
|
-
*/
|
|
29
|
-
private extractPersonalAccessToken;
|
|
30
18
|
/**
|
|
31
19
|
* Determines whether the request is allowed to be executed.
|
|
32
20
|
* @param executionContext - The execution context object.
|
|
33
21
|
* @returns True if the request is allowed to be executed, otherwise false.
|
|
34
22
|
*/
|
|
35
|
-
canActivate(executionContext: ExecutionContext):
|
|
23
|
+
canActivate(executionContext: ExecutionContext): boolean;
|
|
36
24
|
}
|
package/dist/auth.guard.js
CHANGED
|
@@ -16,30 +16,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
16
16
|
};
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.AuthGuard = void 0;
|
|
19
|
-
const core_1 = require("@mikro-orm/core");
|
|
20
19
|
const i18n_1 = require("@nest-boot/i18n");
|
|
21
20
|
const request_context_1 = require("@nest-boot/request-context");
|
|
22
21
|
const common_1 = require("@nestjs/common");
|
|
23
|
-
const
|
|
22
|
+
const core_1 = require("@nestjs/core");
|
|
24
23
|
const lodash_1 = __importDefault(require("lodash"));
|
|
25
24
|
const auth_constants_1 = require("./auth.constants");
|
|
26
25
|
const auth_module_definition_1 = require("./auth.module-definition");
|
|
27
|
-
const auth_service_1 = require("./auth.service");
|
|
28
|
-
const entities_1 = require("./entities");
|
|
29
26
|
/**
|
|
30
27
|
* Authentication guard class used to protect routes and handle requests.
|
|
31
28
|
*/
|
|
32
29
|
let AuthGuard = class AuthGuard {
|
|
33
|
-
constructor(reflector,
|
|
30
|
+
constructor(reflector, options) {
|
|
34
31
|
this.reflector = reflector;
|
|
35
|
-
this.em = em;
|
|
36
|
-
this.authService = authService;
|
|
37
32
|
this.options = options;
|
|
38
|
-
this.reflector = reflector;
|
|
39
33
|
this.defaultRequireAuth = this.options?.defaultRequireAuth ?? true;
|
|
40
|
-
this.userEntityClass = this.options.entities?.User ?? entities_1.User;
|
|
41
|
-
this.personalAccessTokenEntityClass =
|
|
42
|
-
this.options.entities?.PersonalAccessToken ?? entities_1.PersonalAccessToken;
|
|
43
34
|
}
|
|
44
35
|
/**
|
|
45
36
|
* Get internationalized text based on the specified key.
|
|
@@ -49,30 +40,12 @@ let AuthGuard = class AuthGuard {
|
|
|
49
40
|
t(key) {
|
|
50
41
|
return request_context_1.RequestContext.get(i18n_1.I18N)?.t(key, { ns: "auth" }) ?? key;
|
|
51
42
|
}
|
|
52
|
-
/**
|
|
53
|
-
* Extracts the personal access token from the request.
|
|
54
|
-
* @param req - The request object.
|
|
55
|
-
* @returns The personal access token, or null if it doesn't exist.
|
|
56
|
-
*/
|
|
57
|
-
extractPersonalAccessToken(req) {
|
|
58
|
-
const authorizationHeader = req.get("authorization");
|
|
59
|
-
if (typeof authorizationHeader !== "undefined") {
|
|
60
|
-
const matched = authorizationHeader.match(/(\S+)\s+(\S+)/);
|
|
61
|
-
if (matched !== null && matched[1].toLowerCase() === "bearer") {
|
|
62
|
-
return matched[2];
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
if (typeof req.cookies?.token === "string") {
|
|
66
|
-
return req.cookies.token;
|
|
67
|
-
}
|
|
68
|
-
return null;
|
|
69
|
-
}
|
|
70
43
|
/**
|
|
71
44
|
* Determines whether the request is allowed to be executed.
|
|
72
45
|
* @param executionContext - The execution context object.
|
|
73
46
|
* @returns True if the request is allowed to be executed, otherwise false.
|
|
74
47
|
*/
|
|
75
|
-
|
|
48
|
+
canActivate(executionContext) {
|
|
76
49
|
if (!["http", "graphql"].includes(executionContext.getType())) {
|
|
77
50
|
return true;
|
|
78
51
|
}
|
|
@@ -83,31 +56,17 @@ let AuthGuard = class AuthGuard {
|
|
|
83
56
|
if (!(requireAuth ?? this.defaultRequireAuth ?? false)) {
|
|
84
57
|
return true;
|
|
85
58
|
}
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
executionContext.getArgs()[2].req;
|
|
89
|
-
// Extract the token
|
|
90
|
-
const token = this.extractPersonalAccessToken(req);
|
|
91
|
-
if (token === null) {
|
|
92
|
-
throw new common_1.UnauthorizedException(this.t("The personal access token is invalid."));
|
|
93
|
-
}
|
|
94
|
-
const personalAccessToken = await this.authService.getToken(token);
|
|
95
|
-
const user = await personalAccessToken?.user.load({ filters: false });
|
|
59
|
+
const user = request_context_1.RequestContext.get(auth_constants_1.AUTH_USER);
|
|
60
|
+
const personalAccessToken = request_context_1.RequestContext.get(auth_constants_1.AUTH_PERSONAL_ACCESS_TOKEN);
|
|
96
61
|
if (personalAccessToken === null || user == null) {
|
|
97
62
|
throw new common_1.UnauthorizedException(this.t("The personal access token is invalid."));
|
|
98
63
|
}
|
|
99
|
-
request_context_1.RequestContext.set(this.userEntityClass, user);
|
|
100
|
-
request_context_1.RequestContext.set(this.personalAccessTokenEntityClass, personalAccessToken);
|
|
101
|
-
request_context_1.RequestContext.set(auth_constants_1.AUTH_USER, user);
|
|
102
|
-
request_context_1.RequestContext.set(auth_constants_1.AUTH_PERSONAL_ACCESS_TOKEN, personalAccessToken);
|
|
103
64
|
// Get the method permissions
|
|
104
65
|
const permissions = this.reflector.get(auth_constants_1.PERMISSIONS_METADATA_KEY, executionContext.getHandler());
|
|
105
66
|
// If there are no permission requirements, allow access directly
|
|
106
67
|
// Check if there is an intersection between user permissions and configured permissions, if so, allow access
|
|
107
68
|
if (typeof permissions === "undefined" ||
|
|
108
69
|
lodash_1.default.intersection(user.permissions, permissions).length > 0) {
|
|
109
|
-
personalAccessToken.lastUsedAt = new Date();
|
|
110
|
-
await this.em.flush();
|
|
111
70
|
return true;
|
|
112
71
|
}
|
|
113
72
|
throw new common_1.ForbiddenException(this.t("Permission denied."));
|
|
@@ -116,9 +75,7 @@ let AuthGuard = class AuthGuard {
|
|
|
116
75
|
exports.AuthGuard = AuthGuard;
|
|
117
76
|
exports.AuthGuard = AuthGuard = __decorate([
|
|
118
77
|
(0, common_1.Injectable)(),
|
|
119
|
-
__param(
|
|
120
|
-
__metadata("design:paramtypes", [
|
|
121
|
-
core_1.EntityManager,
|
|
122
|
-
auth_service_1.AuthService, Object])
|
|
78
|
+
__param(1, (0, common_1.Inject)(auth_module_definition_1.MODULE_OPTIONS_TOKEN)),
|
|
79
|
+
__metadata("design:paramtypes", [core_1.Reflector, Object])
|
|
123
80
|
], AuthGuard);
|
|
124
81
|
//# sourceMappingURL=auth.guard.js.map
|
package/dist/auth.guard.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.guard.js","sourceRoot":"","sources":["../src/auth.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"auth.guard.js","sourceRoot":"","sources":["../src/auth.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,0CAAkD;AAClD,gEAA4D;AAC5D,2CAOwB;AACxB,uCAAyC;AACzC,oDAAuB;AAEvB,qDAK0B;AAC1B,qEAAgE;AAIhE;;GAEG;AAEI,IAAM,SAAS,GAAf,MAAM,SAAS;IAGpB,YACmB,SAAoB,EAEpB,OAA0B;QAF1B,cAAS,GAAT,SAAS,CAAW;QAEpB,YAAO,GAAP,OAAO,CAAmB;QAE3C,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC,OAAO,EAAE,kBAAkB,IAAI,IAAI,CAAC;IACrE,CAAC;IAED;;;;OAIG;IACK,CAAC,CAAC,GAAW;QACnB,OAAO,gCAAc,CAAC,GAAG,CAAO,WAAI,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,IAAI,GAAG,CAAC;IACvE,CAAC;IAED;;;;OAIG;IACI,WAAW,CAAC,gBAAkC;QACnD,IAAI,CAAC,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC;YAC9D,OAAO,IAAI,CAAC;QACd,CAA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A0ErB"}
|
package/dist/auth.module.d.ts
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
import { OnModuleInit } from "@nestjs/common";
|
|
1
2
|
import { ConfigurableModuleClass } from "./auth.module-definition";
|
|
2
|
-
|
|
3
|
+
import { AuthService } from "./auth.service";
|
|
4
|
+
import { AuthModuleOptions } from "./interfaces";
|
|
5
|
+
export declare class AuthModule extends ConfigurableModuleClass implements OnModuleInit {
|
|
6
|
+
private readonly authService;
|
|
7
|
+
private readonly options;
|
|
8
|
+
constructor(authService: AuthService, options: AuthModuleOptions);
|
|
9
|
+
onModuleInit(): void;
|
|
10
|
+
/**
|
|
11
|
+
* Extracts the personal access token from the request.
|
|
12
|
+
* @param req - The request object.
|
|
13
|
+
* @returns The personal access token, or null if it doesn't exist.
|
|
14
|
+
*/
|
|
15
|
+
private extractPersonalAccessToken;
|
|
3
16
|
}
|
package/dist/auth.module.js
CHANGED
|
@@ -5,15 +5,73 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
7
|
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
8
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
15
|
exports.AuthModule = void 0;
|
|
10
16
|
const request_context_1 = require("@nest-boot/request-context");
|
|
11
17
|
const common_1 = require("@nestjs/common");
|
|
12
18
|
const core_1 = require("@nestjs/core");
|
|
19
|
+
const auth_constants_1 = require("./auth.constants");
|
|
13
20
|
const auth_guard_1 = require("./auth.guard");
|
|
14
21
|
const auth_module_definition_1 = require("./auth.module-definition");
|
|
15
22
|
const auth_service_1 = require("./auth.service");
|
|
23
|
+
const entities_1 = require("./entities");
|
|
16
24
|
let AuthModule = class AuthModule extends auth_module_definition_1.ConfigurableModuleClass {
|
|
25
|
+
constructor(authService, options) {
|
|
26
|
+
super();
|
|
27
|
+
this.authService = authService;
|
|
28
|
+
this.options = options;
|
|
29
|
+
this.defaultRequireAuth = this.options?.defaultRequireAuth ?? true;
|
|
30
|
+
this.userEntityClass = this.options.entities?.User ?? entities_1.User;
|
|
31
|
+
this.personalAccessTokenEntityClass =
|
|
32
|
+
this.options.entities?.PersonalAccessToken ?? entities_1.PersonalAccessToken;
|
|
33
|
+
}
|
|
34
|
+
onModuleInit() {
|
|
35
|
+
request_context_1.RequestContext.registerMiddleware(async (ctx, next) => {
|
|
36
|
+
if (ctx.type === "http") {
|
|
37
|
+
const req = ctx.get(request_context_1.REQUEST);
|
|
38
|
+
if (req) {
|
|
39
|
+
const token = this.extractPersonalAccessToken(req);
|
|
40
|
+
if (token) {
|
|
41
|
+
const personalAccessToken = await this.authService.getToken(token);
|
|
42
|
+
const user = await personalAccessToken?.user.load();
|
|
43
|
+
if (personalAccessToken && user) {
|
|
44
|
+
request_context_1.RequestContext.set(this.userEntityClass, user);
|
|
45
|
+
request_context_1.RequestContext.set(this
|
|
46
|
+
.personalAccessTokenEntityClass, personalAccessToken);
|
|
47
|
+
request_context_1.RequestContext.set(auth_constants_1.AUTH_USER, user);
|
|
48
|
+
request_context_1.RequestContext.set(auth_constants_1.AUTH_PERSONAL_ACCESS_TOKEN, personalAccessToken);
|
|
49
|
+
await this.authService.updateLastUsedAt(personalAccessToken);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return await next();
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Extracts the personal access token from the request.
|
|
59
|
+
* @param req - The request object.
|
|
60
|
+
* @returns The personal access token, or null if it doesn't exist.
|
|
61
|
+
*/
|
|
62
|
+
extractPersonalAccessToken(req) {
|
|
63
|
+
const authorizationHeader = req.get("authorization");
|
|
64
|
+
if (typeof authorizationHeader !== "undefined") {
|
|
65
|
+
const matched = authorizationHeader.match(/(\S+)\s+(\S+)/);
|
|
66
|
+
if (matched !== null && matched[1].toLowerCase() === "bearer") {
|
|
67
|
+
return matched[2];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (typeof req.cookies?.token === "string") {
|
|
71
|
+
return req.cookies.token;
|
|
72
|
+
}
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
17
75
|
};
|
|
18
76
|
exports.AuthModule = AuthModule;
|
|
19
77
|
exports.AuthModule = AuthModule = __decorate([
|
|
@@ -28,6 +86,8 @@ exports.AuthModule = AuthModule = __decorate([
|
|
|
28
86
|
core_1.Reflector,
|
|
29
87
|
],
|
|
30
88
|
exports: [auth_service_1.AuthService],
|
|
31
|
-
})
|
|
89
|
+
}),
|
|
90
|
+
__param(1, (0, common_1.Inject)(auth_module_definition_1.MODULE_OPTIONS_TOKEN)),
|
|
91
|
+
__metadata("design:paramtypes", [auth_service_1.AuthService, Object])
|
|
32
92
|
], AuthModule);
|
|
33
93
|
//# sourceMappingURL=auth.module.js.map
|
package/dist/auth.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.module.js","sourceRoot":"","sources":["../src/auth.module.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auth.module.js","sourceRoot":"","sources":["../src/auth.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,gEAIoC;AACpC,2CAAoE;AACpE,uCAAoD;AAGpD,qDAAyE;AACzE,6CAAyC;AACzC,qEAGkC;AAClC,iDAA6C;AAC7C,yCAAuD;AAehD,IAAM,UAAU,GAAhB,MAAM,UACX,SAAQ,gDAAuB;IAG/B,YACm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
|
import { HashService } from "@nest-boot/hash";
|
|
3
3
|
import { PersonalAccessToken, User } from "./entities";
|
|
4
4
|
import { AuthModuleOptions } from "./interfaces";
|
|
@@ -6,9 +6,10 @@ import { AuthModuleOptions } from "./interfaces";
|
|
|
6
6
|
* Service responsible for handling authentication-related operations.
|
|
7
7
|
*/
|
|
8
8
|
export declare class AuthService {
|
|
9
|
-
private readonly
|
|
9
|
+
private readonly orm;
|
|
10
10
|
private readonly hashService;
|
|
11
11
|
private readonly options;
|
|
12
|
+
private readonly em;
|
|
12
13
|
private readonly User;
|
|
13
14
|
private readonly PersonalAccessToken;
|
|
14
15
|
private readonly expiresIn?;
|
|
@@ -18,7 +19,7 @@ export declare class AuthService {
|
|
|
18
19
|
* @param hashService The HashService instance.
|
|
19
20
|
* @param options The options for the Auth module.
|
|
20
21
|
*/
|
|
21
|
-
constructor(
|
|
22
|
+
constructor(orm: MikroORM, hashService: HashService, options: AuthModuleOptions);
|
|
22
23
|
/**
|
|
23
24
|
* Attempts to authenticate a user with the provided email and password.
|
|
24
25
|
* @param email The user's email.
|
|
@@ -59,4 +60,5 @@ export declare class AuthService {
|
|
|
59
60
|
* @returns The registered user.
|
|
60
61
|
*/
|
|
61
62
|
register(name: string, email: string, password: string, permissions?: string[]): Promise<User>;
|
|
63
|
+
updateLastUsedAt(personalAccessToken: PersonalAccessToken, flush?: boolean): Promise<void>;
|
|
62
64
|
}
|
package/dist/auth.service.js
CHANGED
|
@@ -29,10 +29,11 @@ let AuthService = class AuthService {
|
|
|
29
29
|
* @param hashService The HashService instance.
|
|
30
30
|
* @param options The options for the Auth module.
|
|
31
31
|
*/
|
|
32
|
-
constructor(
|
|
33
|
-
this.
|
|
32
|
+
constructor(orm, hashService, options) {
|
|
33
|
+
this.orm = orm;
|
|
34
34
|
this.hashService = hashService;
|
|
35
35
|
this.options = options;
|
|
36
|
+
this.em = this.orm.em;
|
|
36
37
|
this.User = this.options?.entities?.User ?? entities_1.User;
|
|
37
38
|
this.PersonalAccessToken =
|
|
38
39
|
this.options?.entities?.PersonalAccessToken ?? entities_1.PersonalAccessToken;
|
|
@@ -117,12 +118,18 @@ let AuthService = class AuthService {
|
|
|
117
118
|
await this.em.persistAndFlush(user);
|
|
118
119
|
return user;
|
|
119
120
|
}
|
|
121
|
+
async updateLastUsedAt(personalAccessToken, flush = true) {
|
|
122
|
+
personalAccessToken.lastUsedAt = new Date();
|
|
123
|
+
if (flush) {
|
|
124
|
+
await this.em.flush();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
120
127
|
};
|
|
121
128
|
exports.AuthService = AuthService;
|
|
122
129
|
exports.AuthService = AuthService = __decorate([
|
|
123
130
|
(0, common_1.Injectable)(),
|
|
124
131
|
__param(2, (0, common_1.Inject)(auth_module_definition_1.MODULE_OPTIONS_TOKEN)),
|
|
125
|
-
__metadata("design:paramtypes", [core_1.
|
|
132
|
+
__metadata("design:paramtypes", [core_1.MikroORM,
|
|
126
133
|
hash_1.HashService, Object])
|
|
127
134
|
], AuthService);
|
|
128
135
|
//# sourceMappingURL=auth.service.js.map
|
package/dist/auth.service.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.service.js","sourceRoot":"","sources":["../src/auth.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"auth.service.js","sourceRoot":"","sources":["../src/auth.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0CAAuE;AACvE,0CAA8C;AAC9C,2CAAoD;AAEpD,qEAAgE;AAChE,yCAAuD;AAEvD,mEAA0D;AAE1D;;GAEG;AAEI,IAAM,WAAW,GAAjB,MAAM,WAAW;IAQtB;;;;;OAKG;IACH,YACmB,GAAa,EACb,WAAwB,EAExB,OAA0B;QAH1B,QAAG,GAAH,GAAG,CAAU;QACb,gBAAW,GAAX,WAAW,CAAa;QAExB,YAAO,GAAP,OAAO,CAAmB;QAE3C,IAAI,CAAC,EAAE,GAAG,IAAI,CA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AAC;YACV,MAAM,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;QACxB,CAAC;IACH,CAAC;CACF,CAAA;AAxJY,kCAAW;sBAAX,WAAW;IADvB,IAAA,mBAAU,GAAE;IAkBR,WAAA,IAAA,eAAM,EAAC,6CAAoB,CAAC,CAAA;qCAFP,eAAQ;QACA,kBAAW;GAhBhC,WAAW,CAwJvB"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Collection } from "@mikro-orm/core";
|
|
2
2
|
import { PersonalAccessToken } from "./personal-access-token.entity";
|
|
3
3
|
export declare class User {
|
|
4
|
-
constructor(data: Pick<User, "id" | "name" | "email"> & Partial<Pick<User, "
|
|
4
|
+
constructor(data: Pick<User, "id" | "name" | "email" | "password"> & Partial<Pick<User, "permissions" | "createdAt" | "updatedAt" | "personalAccessTokens">>);
|
|
5
5
|
id: string;
|
|
6
6
|
name: string;
|
|
7
7
|
email: string;
|
|
8
|
-
password: string
|
|
8
|
+
password: string;
|
|
9
9
|
permissions: string[];
|
|
10
10
|
createdAt: Date;
|
|
11
11
|
updatedAt: Date;
|
|
@@ -14,7 +14,6 @@ const core_1 = require("@mikro-orm/core");
|
|
|
14
14
|
const personal_access_token_entity_1 = require("./personal-access-token.entity");
|
|
15
15
|
let User = class User {
|
|
16
16
|
constructor(data) {
|
|
17
|
-
this.password = null;
|
|
18
17
|
this.permissions = [];
|
|
19
18
|
this.createdAt = new Date();
|
|
20
19
|
this.updatedAt = new Date();
|
|
@@ -22,7 +21,7 @@ let User = class User {
|
|
|
22
21
|
this.id = data.id;
|
|
23
22
|
this.name = data.name;
|
|
24
23
|
this.email = data.email;
|
|
25
|
-
|
|
24
|
+
this.password = data.password;
|
|
26
25
|
data.permissions !== void 0 && (this.permissions = data.permissions);
|
|
27
26
|
data.createdAt !== void 0 && (this.createdAt = data.createdAt);
|
|
28
27
|
data.updatedAt !== void 0 && (this.updatedAt = data.updatedAt);
|
|
@@ -44,8 +43,8 @@ __decorate([
|
|
|
44
43
|
__metadata("design:type", String)
|
|
45
44
|
], User.prototype, "email", void 0);
|
|
46
45
|
__decorate([
|
|
47
|
-
(0, core_1.Property)(
|
|
48
|
-
__metadata("design:type",
|
|
46
|
+
(0, core_1.Property)(),
|
|
47
|
+
__metadata("design:type", String)
|
|
49
48
|
], User.prototype, "password", void 0);
|
|
50
49
|
__decorate([
|
|
51
50
|
(0, core_1.Property)({ type: core_1.t.array, default: "{}" }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.entity.js","sourceRoot":"","sources":["../../src/entities/user.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0CAOyB;AAEzB,iFAAqE;AAG9D,IAAM,IAAI,GAAV,MAAM,IAAI;IACf,YACE,
|
|
1
|
+
{"version":3,"file":"user.entity.js","sourceRoot":"","sources":["../../src/entities/user.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0CAOyB;AAEzB,iFAAqE;AAG9D,IAAM,IAAI,GAAV,MAAM,IAAI;IACf,YACE,IAMG;QA2BL,gBAAW,GAAa,EAAE,CAAC;QAG3B,cAAS,GAAS,IAAI,IAAI,EAAE,CAAC;QAG7B,cAAS,GAAS,IAAI,IAAI,EAAE,CAAC;QAM7B,yBAAoB,GAAG,IAAI,iBAAU,CAAsB,IAAI,CAAC,CAAC;QArC/D,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;QAClB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACxB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAE9B,IAAI,CAAC,WAAW,KAAK,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC;QACrE,IAAI,CAAC,SAAS,KAAK,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS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