@scryan7371/sdr-security 0.1.2 → 0.1.4
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/README.md +48 -7
- package/dist/api/contracts.d.ts +0 -2
- package/dist/api/migrations/1700000000001-add-refresh-tokens.js +4 -2
- package/dist/api/migrations/1739500000000-create-security-identity.d.ts +1 -1
- package/dist/api/migrations/1739500000000-create-security-identity.js +12 -36
- package/dist/api/migrations/1739510000000-create-security-roles.d.ts +1 -1
- package/dist/api/migrations/1739510000000-create-security-roles.js +3 -68
- package/dist/api/migrations/1739515000000-create-security-user-roles.d.ts +9 -0
- package/dist/api/migrations/1739515000000-create-security-user-roles.js +42 -0
- package/dist/api/migrations/1739520000000-create-password-reset-tokens.js +4 -2
- package/dist/api/migrations/1739530000000-create-security-user.d.ts +9 -0
- package/dist/api/migrations/1739530000000-create-security-user.js +42 -0
- package/dist/api/migrations/index.d.ts +3 -2
- package/dist/api/migrations/index.js +7 -4
- package/dist/api/migrations/migrations.test.js +37 -83
- package/dist/api/notification-workflows.d.ts +0 -4
- package/dist/api/notification-workflows.js +0 -1
- package/dist/api/notification-workflows.test.js +1 -4
- package/dist/app/client.d.ts +0 -2
- package/dist/app/client.test.js +0 -2
- package/dist/integration/database.integration.test.js +1 -1
- package/dist/nest/contracts.d.ts +0 -3
- package/dist/nest/dto/auth.dto.d.ts +0 -2
- package/dist/nest/dto/auth.dto.js +0 -10
- package/dist/nest/entities/app-user.entity.d.ts +0 -7
- package/dist/nest/entities/app-user.entity.js +1 -36
- package/dist/nest/entities/password-reset-token.entity.d.ts +1 -0
- package/dist/nest/entities/password-reset-token.entity.js +14 -2
- package/dist/nest/entities/refresh-token.entity.js +2 -2
- package/dist/nest/entities/security-role.entity.d.ts +1 -0
- package/dist/nest/entities/security-role.entity.js +13 -1
- package/dist/nest/entities/security-user-role.entity.d.ts +1 -0
- package/dist/nest/entities/security-user-role.entity.js +14 -2
- package/dist/nest/entities/security-user.entity.d.ts +9 -0
- package/dist/nest/entities/security-user.entity.js +54 -0
- package/dist/nest/index.d.ts +1 -0
- package/dist/nest/index.js +1 -0
- package/dist/nest/security-auth.controller.d.ts +0 -2
- package/dist/nest/security-auth.controller.js +0 -2
- package/dist/nest/security-auth.controller.test.js +0 -4
- package/dist/nest/security-auth.module.js +2 -0
- package/dist/nest/security-auth.service.d.ts +5 -4
- package/dist/nest/security-auth.service.js +85 -52
- package/dist/nest/security-auth.service.test.js +48 -42
- package/dist/nest/security-workflows.module.js +2 -0
- package/dist/nest/security-workflows.service.d.ts +4 -2
- package/dist/nest/security-workflows.service.js +23 -16
- package/dist/nest/security-workflows.service.test.js +29 -24
- package/package.json +5 -4
- package/src/api/contracts.ts +0 -2
- package/src/api/migrations/1700000000001-add-refresh-tokens.ts +4 -2
- package/src/api/migrations/1739500000000-create-security-identity.ts +14 -51
- package/src/api/migrations/1739510000000-create-security-roles.ts +4 -90
- package/src/api/migrations/1739515000000-create-security-user-roles.ts +52 -0
- package/src/api/migrations/1739520000000-create-password-reset-tokens.ts +4 -2
- package/src/api/migrations/1739530000000-create-security-user.ts +52 -0
- package/src/api/migrations/index.ts +6 -3
- package/src/api/migrations/migrations.test.ts +48 -111
- package/src/api/notification-workflows.test.ts +1 -4
- package/src/api/notification-workflows.ts +1 -8
- package/src/app/client.test.ts +0 -2
- package/src/app/client.ts +1 -6
- package/src/integration/database.integration.test.ts +1 -1
- package/src/nest/contracts.ts +1 -6
- package/src/nest/dto/auth.dto.ts +0 -6
- package/src/nest/entities/app-user.entity.ts +2 -23
- package/src/nest/entities/password-reset-token.entity.ts +12 -3
- package/src/nest/entities/refresh-token.entity.ts +2 -2
- package/src/nest/entities/security-role.entity.ts +10 -2
- package/src/nest/entities/security-user-role.entity.ts +11 -3
- package/src/nest/entities/security-user.entity.ts +25 -0
- package/src/nest/index.ts +1 -0
- package/src/nest/security-auth.controller.test.ts +0 -4
- package/src/nest/security-auth.controller.ts +0 -4
- package/src/nest/security-auth.module.ts +2 -0
- package/src/nest/security-auth.service.test.ts +78 -44
- package/src/nest/security-auth.service.ts +93 -53
- package/src/nest/security-workflows.module.ts +2 -0
- package/src/nest/security-workflows.service.test.ts +31 -25
- package/src/nest/security-workflows.service.ts +22 -13
- package/dist/api/migrations/1739490000000-add-google-subject-to-user.d.ts +0 -5
- package/dist/api/migrations/1739490000000-add-google-subject-to-user.js +0 -14
- package/src/api/migrations/1739490000000-add-google-subject-to-user.ts +0 -12
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
export type VerificationNotificationUser = {
|
|
2
2
|
id: string;
|
|
3
3
|
email: string;
|
|
4
|
-
firstName?: string | null;
|
|
5
|
-
lastName?: string | null;
|
|
6
4
|
};
|
|
7
5
|
export declare const notifyAdminsOnEmailVerified: (params: {
|
|
8
6
|
user: VerificationNotificationUser;
|
|
@@ -22,11 +20,9 @@ export declare const notifyUserOnAdminApproval: (params: {
|
|
|
22
20
|
approved: boolean;
|
|
23
21
|
user: {
|
|
24
22
|
email: string;
|
|
25
|
-
firstName?: string | null;
|
|
26
23
|
};
|
|
27
24
|
notifyUser: (payload: {
|
|
28
25
|
email: string;
|
|
29
|
-
firstName?: string | null;
|
|
30
26
|
}) => Promise<void>;
|
|
31
27
|
}) => Promise<{
|
|
32
28
|
notified: false;
|
|
@@ -12,8 +12,6 @@ const notification_workflows_1 = require("./notification-workflows");
|
|
|
12
12
|
user: {
|
|
13
13
|
id: "user-1",
|
|
14
14
|
email: "user@example.com",
|
|
15
|
-
firstName: "User",
|
|
16
|
-
lastName: "One",
|
|
17
15
|
},
|
|
18
16
|
listAdminEmails,
|
|
19
17
|
notifyAdmins,
|
|
@@ -44,13 +42,12 @@ const notification_workflows_1 = require("./notification-workflows");
|
|
|
44
42
|
const notifyUser = vitest_1.vi.fn().mockResolvedValue(undefined);
|
|
45
43
|
const result = await (0, notification_workflows_1.notifyUserOnAdminApproval)({
|
|
46
44
|
approved: true,
|
|
47
|
-
user: { email: "user@example.com"
|
|
45
|
+
user: { email: "user@example.com" },
|
|
48
46
|
notifyUser,
|
|
49
47
|
});
|
|
50
48
|
(0, vitest_1.expect)(result).toEqual({ notified: true });
|
|
51
49
|
(0, vitest_1.expect)(notifyUser).toHaveBeenCalledWith({
|
|
52
50
|
email: "user@example.com",
|
|
53
|
-
firstName: "User",
|
|
54
51
|
});
|
|
55
52
|
});
|
|
56
53
|
(0, vitest_1.it)("skips user notification when approval is false", async () => {
|
package/dist/app/client.d.ts
CHANGED
|
@@ -9,8 +9,6 @@ export declare const createSecurityClient: (options: SecurityClientOptions) => {
|
|
|
9
9
|
register: (payload: {
|
|
10
10
|
email: string;
|
|
11
11
|
password: string;
|
|
12
|
-
firstName?: string;
|
|
13
|
-
lastName?: string;
|
|
14
12
|
}) => Promise<RegisterResponse>;
|
|
15
13
|
login: (payload: {
|
|
16
14
|
email: string;
|
package/dist/app/client.test.js
CHANGED
|
@@ -26,8 +26,6 @@ const makeFetch = (responses) => {
|
|
|
26
26
|
await client.register({
|
|
27
27
|
email: "user@example.com",
|
|
28
28
|
password: "Secret123",
|
|
29
|
-
firstName: "A",
|
|
30
|
-
lastName: "B",
|
|
31
29
|
});
|
|
32
30
|
(0, vitest_1.expect)(fetchImpl).toHaveBeenCalledWith("https://api.example.com/security/auth/register", vitest_1.expect.objectContaining({
|
|
33
31
|
method: "POST",
|
|
@@ -97,7 +97,7 @@ const resetSchemaBeforeRun = process.env.SECURITY_TEST_RESET_SCHEMA !== "false";
|
|
|
97
97
|
await client.query(`SET search_path TO "${schema}", public`);
|
|
98
98
|
await client.query(`
|
|
99
99
|
CREATE TABLE IF NOT EXISTS "${schema}"."app_user" (
|
|
100
|
-
"id"
|
|
100
|
+
"id" uuid PRIMARY KEY NOT NULL,
|
|
101
101
|
"email" varchar NOT NULL
|
|
102
102
|
)
|
|
103
103
|
`);
|
package/dist/nest/contracts.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
export type SecurityWorkflowUser = {
|
|
2
2
|
id: string;
|
|
3
3
|
email: string;
|
|
4
|
-
firstName: string | null;
|
|
5
|
-
lastName: string | null;
|
|
6
4
|
};
|
|
7
5
|
export type SecurityWorkflowNotifier = {
|
|
8
6
|
sendEmailVerification?: (params: {
|
|
@@ -19,6 +17,5 @@ export type SecurityWorkflowNotifier = {
|
|
|
19
17
|
}) => Promise<void>;
|
|
20
18
|
sendUserAccountApproved: (params: {
|
|
21
19
|
email: string;
|
|
22
|
-
firstName: string | null;
|
|
23
20
|
}) => Promise<void>;
|
|
24
21
|
};
|
|
@@ -14,8 +14,6 @@ const swagger_1 = require("@nestjs/swagger");
|
|
|
14
14
|
class RegisterDto {
|
|
15
15
|
email;
|
|
16
16
|
password;
|
|
17
|
-
firstName;
|
|
18
|
-
lastName;
|
|
19
17
|
}
|
|
20
18
|
exports.RegisterDto = RegisterDto;
|
|
21
19
|
__decorate([
|
|
@@ -26,14 +24,6 @@ __decorate([
|
|
|
26
24
|
(0, swagger_1.ApiProperty)({ example: "StrongPass1" }),
|
|
27
25
|
__metadata("design:type", String)
|
|
28
26
|
], RegisterDto.prototype, "password", void 0);
|
|
29
|
-
__decorate([
|
|
30
|
-
(0, swagger_1.ApiProperty)({ required: false, nullable: true, example: "John" }),
|
|
31
|
-
__metadata("design:type", Object)
|
|
32
|
-
], RegisterDto.prototype, "firstName", void 0);
|
|
33
|
-
__decorate([
|
|
34
|
-
(0, swagger_1.ApiProperty)({ required: false, nullable: true, example: "Doe" }),
|
|
35
|
-
__metadata("design:type", Object)
|
|
36
|
-
], RegisterDto.prototype, "lastName", void 0);
|
|
37
27
|
class LoginDto {
|
|
38
28
|
email;
|
|
39
29
|
password;
|
|
@@ -1,11 +1,4 @@
|
|
|
1
1
|
export declare class AppUserEntity {
|
|
2
2
|
id: string;
|
|
3
3
|
email: string;
|
|
4
|
-
passwordHash: string;
|
|
5
|
-
firstName: string | null;
|
|
6
|
-
lastName: string | null;
|
|
7
|
-
emailVerifiedAt: Date | null;
|
|
8
|
-
emailVerificationToken: string | null;
|
|
9
|
-
adminApprovedAt: Date | null;
|
|
10
|
-
isActive: boolean;
|
|
11
4
|
}
|
|
@@ -14,51 +14,16 @@ const typeorm_1 = require("typeorm");
|
|
|
14
14
|
let AppUserEntity = class AppUserEntity {
|
|
15
15
|
id;
|
|
16
16
|
email;
|
|
17
|
-
passwordHash;
|
|
18
|
-
firstName;
|
|
19
|
-
lastName;
|
|
20
|
-
emailVerifiedAt;
|
|
21
|
-
emailVerificationToken;
|
|
22
|
-
adminApprovedAt;
|
|
23
|
-
isActive;
|
|
24
17
|
};
|
|
25
18
|
exports.AppUserEntity = AppUserEntity;
|
|
26
19
|
__decorate([
|
|
27
|
-
(0, typeorm_1.
|
|
20
|
+
(0, typeorm_1.PrimaryColumn)({ type: "uuid" }),
|
|
28
21
|
__metadata("design:type", String)
|
|
29
22
|
], AppUserEntity.prototype, "id", void 0);
|
|
30
23
|
__decorate([
|
|
31
24
|
(0, typeorm_1.Column)({ type: "varchar" }),
|
|
32
25
|
__metadata("design:type", String)
|
|
33
26
|
], AppUserEntity.prototype, "email", void 0);
|
|
34
|
-
__decorate([
|
|
35
|
-
(0, typeorm_1.Column)({ type: "varchar", name: "password_hash" }),
|
|
36
|
-
__metadata("design:type", String)
|
|
37
|
-
], AppUserEntity.prototype, "passwordHash", void 0);
|
|
38
|
-
__decorate([
|
|
39
|
-
(0, typeorm_1.Column)({ type: "varchar", name: "first_name", nullable: true }),
|
|
40
|
-
__metadata("design:type", Object)
|
|
41
|
-
], AppUserEntity.prototype, "firstName", void 0);
|
|
42
|
-
__decorate([
|
|
43
|
-
(0, typeorm_1.Column)({ type: "varchar", name: "last_name", nullable: true }),
|
|
44
|
-
__metadata("design:type", Object)
|
|
45
|
-
], AppUserEntity.prototype, "lastName", void 0);
|
|
46
|
-
__decorate([
|
|
47
|
-
(0, typeorm_1.Column)({ type: "timestamptz", name: "email_verified_at", nullable: true }),
|
|
48
|
-
__metadata("design:type", Object)
|
|
49
|
-
], AppUserEntity.prototype, "emailVerifiedAt", void 0);
|
|
50
|
-
__decorate([
|
|
51
|
-
(0, typeorm_1.Column)({ type: "varchar", name: "email_verification_token", nullable: true }),
|
|
52
|
-
__metadata("design:type", Object)
|
|
53
|
-
], AppUserEntity.prototype, "emailVerificationToken", void 0);
|
|
54
|
-
__decorate([
|
|
55
|
-
(0, typeorm_1.Column)({ type: "timestamptz", name: "admin_approved_at", nullable: true }),
|
|
56
|
-
__metadata("design:type", Object)
|
|
57
|
-
], AppUserEntity.prototype, "adminApprovedAt", void 0);
|
|
58
|
-
__decorate([
|
|
59
|
-
(0, typeorm_1.Column)({ type: "boolean", name: "is_active", default: true }),
|
|
60
|
-
__metadata("design:type", Boolean)
|
|
61
|
-
], AppUserEntity.prototype, "isActive", void 0);
|
|
62
27
|
exports.AppUserEntity = AppUserEntity = __decorate([
|
|
63
28
|
(0, typeorm_1.Entity)({ name: "app_user" })
|
|
64
29
|
], AppUserEntity);
|
|
@@ -11,6 +11,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.PasswordResetTokenEntity = void 0;
|
|
13
13
|
const typeorm_1 = require("typeorm");
|
|
14
|
+
const uuid_1 = require("uuid");
|
|
14
15
|
let PasswordResetTokenEntity = class PasswordResetTokenEntity {
|
|
15
16
|
id;
|
|
16
17
|
userId;
|
|
@@ -18,14 +19,19 @@ let PasswordResetTokenEntity = class PasswordResetTokenEntity {
|
|
|
18
19
|
expiresAt;
|
|
19
20
|
usedAt;
|
|
20
21
|
createdAt;
|
|
22
|
+
ensureId() {
|
|
23
|
+
if (!this.id) {
|
|
24
|
+
this.id = (0, uuid_1.v7)();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
21
27
|
};
|
|
22
28
|
exports.PasswordResetTokenEntity = PasswordResetTokenEntity;
|
|
23
29
|
__decorate([
|
|
24
|
-
(0, typeorm_1.
|
|
30
|
+
(0, typeorm_1.PrimaryColumn)({ type: "uuid" }),
|
|
25
31
|
__metadata("design:type", String)
|
|
26
32
|
], PasswordResetTokenEntity.prototype, "id", void 0);
|
|
27
33
|
__decorate([
|
|
28
|
-
(0, typeorm_1.Column)({ type: "
|
|
34
|
+
(0, typeorm_1.Column)({ type: "uuid", name: "user_id" }),
|
|
29
35
|
__metadata("design:type", String)
|
|
30
36
|
], PasswordResetTokenEntity.prototype, "userId", void 0);
|
|
31
37
|
__decorate([
|
|
@@ -44,6 +50,12 @@ __decorate([
|
|
|
44
50
|
(0, typeorm_1.CreateDateColumn)({ name: "created_at" }),
|
|
45
51
|
__metadata("design:type", Date)
|
|
46
52
|
], PasswordResetTokenEntity.prototype, "createdAt", void 0);
|
|
53
|
+
__decorate([
|
|
54
|
+
(0, typeorm_1.BeforeInsert)(),
|
|
55
|
+
__metadata("design:type", Function),
|
|
56
|
+
__metadata("design:paramtypes", []),
|
|
57
|
+
__metadata("design:returntype", void 0)
|
|
58
|
+
], PasswordResetTokenEntity.prototype, "ensureId", null);
|
|
47
59
|
exports.PasswordResetTokenEntity = PasswordResetTokenEntity = __decorate([
|
|
48
60
|
(0, typeorm_1.Entity)({ name: "security_password_reset_token" })
|
|
49
61
|
], PasswordResetTokenEntity);
|
|
@@ -21,7 +21,7 @@ let RefreshTokenEntity = class RefreshTokenEntity {
|
|
|
21
21
|
};
|
|
22
22
|
exports.RefreshTokenEntity = RefreshTokenEntity;
|
|
23
23
|
__decorate([
|
|
24
|
-
(0, typeorm_1.PrimaryColumn)({ type: "
|
|
24
|
+
(0, typeorm_1.PrimaryColumn)({ type: "uuid" }),
|
|
25
25
|
__metadata("design:type", String)
|
|
26
26
|
], RefreshTokenEntity.prototype, "id", void 0);
|
|
27
27
|
__decorate([
|
|
@@ -37,7 +37,7 @@ __decorate([
|
|
|
37
37
|
__metadata("design:type", Object)
|
|
38
38
|
], RefreshTokenEntity.prototype, "revokedAt", void 0);
|
|
39
39
|
__decorate([
|
|
40
|
-
(0, typeorm_1.Column)({ type: "
|
|
40
|
+
(0, typeorm_1.Column)({ type: "uuid", name: "userId", nullable: true }),
|
|
41
41
|
__metadata("design:type", Object)
|
|
42
42
|
], RefreshTokenEntity.prototype, "userId", void 0);
|
|
43
43
|
__decorate([
|
|
@@ -10,16 +10,22 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.SecurityRoleEntity = void 0;
|
|
13
|
+
const uuid_1 = require("uuid");
|
|
13
14
|
const typeorm_1 = require("typeorm");
|
|
14
15
|
let SecurityRoleEntity = class SecurityRoleEntity {
|
|
15
16
|
id;
|
|
16
17
|
roleKey;
|
|
17
18
|
description;
|
|
18
19
|
isSystem;
|
|
20
|
+
ensureId() {
|
|
21
|
+
if (!this.id) {
|
|
22
|
+
this.id = (0, uuid_1.v7)();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
19
25
|
};
|
|
20
26
|
exports.SecurityRoleEntity = SecurityRoleEntity;
|
|
21
27
|
__decorate([
|
|
22
|
-
(0, typeorm_1.
|
|
28
|
+
(0, typeorm_1.PrimaryColumn)({ type: "uuid" }),
|
|
23
29
|
__metadata("design:type", String)
|
|
24
30
|
], SecurityRoleEntity.prototype, "id", void 0);
|
|
25
31
|
__decorate([
|
|
@@ -34,6 +40,12 @@ __decorate([
|
|
|
34
40
|
(0, typeorm_1.Column)({ type: "boolean", name: "is_system", default: false }),
|
|
35
41
|
__metadata("design:type", Boolean)
|
|
36
42
|
], SecurityRoleEntity.prototype, "isSystem", void 0);
|
|
43
|
+
__decorate([
|
|
44
|
+
(0, typeorm_1.BeforeInsert)(),
|
|
45
|
+
__metadata("design:type", Function),
|
|
46
|
+
__metadata("design:paramtypes", []),
|
|
47
|
+
__metadata("design:returntype", void 0)
|
|
48
|
+
], SecurityRoleEntity.prototype, "ensureId", null);
|
|
37
49
|
exports.SecurityRoleEntity = SecurityRoleEntity = __decorate([
|
|
38
50
|
(0, typeorm_1.Entity)({ name: "security_role" })
|
|
39
51
|
], SecurityRoleEntity);
|
|
@@ -10,25 +10,37 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.SecurityUserRoleEntity = void 0;
|
|
13
|
+
const uuid_1 = require("uuid");
|
|
13
14
|
const typeorm_1 = require("typeorm");
|
|
14
15
|
let SecurityUserRoleEntity = class SecurityUserRoleEntity {
|
|
15
16
|
id;
|
|
16
17
|
userId;
|
|
17
18
|
roleId;
|
|
19
|
+
ensureId() {
|
|
20
|
+
if (!this.id) {
|
|
21
|
+
this.id = (0, uuid_1.v7)();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
18
24
|
};
|
|
19
25
|
exports.SecurityUserRoleEntity = SecurityUserRoleEntity;
|
|
20
26
|
__decorate([
|
|
21
|
-
(0, typeorm_1.
|
|
27
|
+
(0, typeorm_1.PrimaryColumn)({ type: "uuid" }),
|
|
22
28
|
__metadata("design:type", String)
|
|
23
29
|
], SecurityUserRoleEntity.prototype, "id", void 0);
|
|
24
30
|
__decorate([
|
|
25
|
-
(0, typeorm_1.Column)({ type: "
|
|
31
|
+
(0, typeorm_1.Column)({ type: "uuid", name: "user_id" }),
|
|
26
32
|
__metadata("design:type", String)
|
|
27
33
|
], SecurityUserRoleEntity.prototype, "userId", void 0);
|
|
28
34
|
__decorate([
|
|
29
35
|
(0, typeorm_1.Column)({ type: "uuid", name: "role_id" }),
|
|
30
36
|
__metadata("design:type", String)
|
|
31
37
|
], SecurityUserRoleEntity.prototype, "roleId", void 0);
|
|
38
|
+
__decorate([
|
|
39
|
+
(0, typeorm_1.BeforeInsert)(),
|
|
40
|
+
__metadata("design:type", Function),
|
|
41
|
+
__metadata("design:paramtypes", []),
|
|
42
|
+
__metadata("design:returntype", void 0)
|
|
43
|
+
], SecurityUserRoleEntity.prototype, "ensureId", null);
|
|
32
44
|
exports.SecurityUserRoleEntity = SecurityUserRoleEntity = __decorate([
|
|
33
45
|
(0, typeorm_1.Entity)({ name: "security_user_role" })
|
|
34
46
|
], SecurityUserRoleEntity);
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.SecurityUserEntity = void 0;
|
|
13
|
+
const typeorm_1 = require("typeorm");
|
|
14
|
+
let SecurityUserEntity = class SecurityUserEntity {
|
|
15
|
+
userId;
|
|
16
|
+
passwordHash;
|
|
17
|
+
emailVerifiedAt;
|
|
18
|
+
emailVerificationToken;
|
|
19
|
+
adminApprovedAt;
|
|
20
|
+
isActive;
|
|
21
|
+
createdAt;
|
|
22
|
+
};
|
|
23
|
+
exports.SecurityUserEntity = SecurityUserEntity;
|
|
24
|
+
__decorate([
|
|
25
|
+
(0, typeorm_1.PrimaryColumn)({ type: "uuid", name: "user_id" }),
|
|
26
|
+
__metadata("design:type", String)
|
|
27
|
+
], SecurityUserEntity.prototype, "userId", void 0);
|
|
28
|
+
__decorate([
|
|
29
|
+
(0, typeorm_1.Column)({ type: "varchar", name: "password_hash" }),
|
|
30
|
+
__metadata("design:type", String)
|
|
31
|
+
], SecurityUserEntity.prototype, "passwordHash", void 0);
|
|
32
|
+
__decorate([
|
|
33
|
+
(0, typeorm_1.Column)({ type: "timestamptz", name: "email_verified_at", nullable: true }),
|
|
34
|
+
__metadata("design:type", Object)
|
|
35
|
+
], SecurityUserEntity.prototype, "emailVerifiedAt", void 0);
|
|
36
|
+
__decorate([
|
|
37
|
+
(0, typeorm_1.Column)({ type: "varchar", name: "email_verification_token", nullable: true }),
|
|
38
|
+
__metadata("design:type", Object)
|
|
39
|
+
], SecurityUserEntity.prototype, "emailVerificationToken", void 0);
|
|
40
|
+
__decorate([
|
|
41
|
+
(0, typeorm_1.Column)({ type: "timestamptz", name: "admin_approved_at", nullable: true }),
|
|
42
|
+
__metadata("design:type", Object)
|
|
43
|
+
], SecurityUserEntity.prototype, "adminApprovedAt", void 0);
|
|
44
|
+
__decorate([
|
|
45
|
+
(0, typeorm_1.Column)({ type: "boolean", name: "is_active", default: true }),
|
|
46
|
+
__metadata("design:type", Boolean)
|
|
47
|
+
], SecurityUserEntity.prototype, "isActive", void 0);
|
|
48
|
+
__decorate([
|
|
49
|
+
(0, typeorm_1.CreateDateColumn)({ name: "created_at" }),
|
|
50
|
+
__metadata("design:type", Date)
|
|
51
|
+
], SecurityUserEntity.prototype, "createdAt", void 0);
|
|
52
|
+
exports.SecurityUserEntity = SecurityUserEntity = __decorate([
|
|
53
|
+
(0, typeorm_1.Entity)({ name: "security_user" })
|
|
54
|
+
], SecurityUserEntity);
|
package/dist/nest/index.d.ts
CHANGED
|
@@ -15,4 +15,5 @@ export * from "./entities/app-user.entity";
|
|
|
15
15
|
export * from "./entities/refresh-token.entity";
|
|
16
16
|
export * from "./entities/password-reset-token.entity";
|
|
17
17
|
export * from "./entities/security-role.entity";
|
|
18
|
+
export * from "./entities/security-user.entity";
|
|
18
19
|
export * from "./entities/security-user-role.entity";
|
package/dist/nest/index.js
CHANGED
|
@@ -31,4 +31,5 @@ __exportStar(require("./entities/app-user.entity"), exports);
|
|
|
31
31
|
__exportStar(require("./entities/refresh-token.entity"), exports);
|
|
32
32
|
__exportStar(require("./entities/password-reset-token.entity"), exports);
|
|
33
33
|
__exportStar(require("./entities/security-role.entity"), exports);
|
|
34
|
+
__exportStar(require("./entities/security-user.entity"), exports);
|
|
34
35
|
__exportStar(require("./entities/security-user-role.entity"), exports);
|
|
@@ -29,15 +29,11 @@ const makeAuthService = () => ({
|
|
|
29
29
|
const result = await controller.register({
|
|
30
30
|
email: "user@example.com",
|
|
31
31
|
password: "Secret123",
|
|
32
|
-
firstName: "A",
|
|
33
|
-
lastName: "B",
|
|
34
32
|
});
|
|
35
33
|
(0, vitest_1.expect)(result).toEqual({ success: true });
|
|
36
34
|
(0, vitest_1.expect)(service.register).toHaveBeenCalledWith({
|
|
37
35
|
email: "user@example.com",
|
|
38
36
|
password: "Secret123",
|
|
39
|
-
firstName: "A",
|
|
40
|
-
lastName: "B",
|
|
41
37
|
});
|
|
42
38
|
});
|
|
43
39
|
(0, vitest_1.it)("validates login and refresh payloads", async () => {
|
|
@@ -14,6 +14,7 @@ const app_user_entity_1 = require("./entities/app-user.entity");
|
|
|
14
14
|
const password_reset_token_entity_1 = require("./entities/password-reset-token.entity");
|
|
15
15
|
const refresh_token_entity_1 = require("./entities/refresh-token.entity");
|
|
16
16
|
const security_role_entity_1 = require("./entities/security-role.entity");
|
|
17
|
+
const security_user_entity_1 = require("./entities/security-user.entity");
|
|
17
18
|
const security_user_role_entity_1 = require("./entities/security-user-role.entity");
|
|
18
19
|
const security_admin_guard_1 = require("./security-admin.guard");
|
|
19
20
|
const security_auth_controller_1 = require("./security-auth.controller");
|
|
@@ -40,6 +41,7 @@ let SecurityAuthModule = SecurityAuthModule_1 = class SecurityAuthModule {
|
|
|
40
41
|
imports: [
|
|
41
42
|
typeorm_1.TypeOrmModule.forFeature([
|
|
42
43
|
app_user_entity_1.AppUserEntity,
|
|
44
|
+
security_user_entity_1.SecurityUserEntity,
|
|
43
45
|
refresh_token_entity_1.RefreshTokenEntity,
|
|
44
46
|
password_reset_token_entity_1.PasswordResetTokenEntity,
|
|
45
47
|
security_role_entity_1.SecurityRoleEntity,
|
|
@@ -5,22 +5,22 @@ import { AppUserEntity } from "./entities/app-user.entity";
|
|
|
5
5
|
import { PasswordResetTokenEntity } from "./entities/password-reset-token.entity";
|
|
6
6
|
import { RefreshTokenEntity } from "./entities/refresh-token.entity";
|
|
7
7
|
import { SecurityRoleEntity } from "./entities/security-role.entity";
|
|
8
|
+
import { SecurityUserEntity } from "./entities/security-user.entity";
|
|
8
9
|
import { SecurityUserRoleEntity } from "./entities/security-user-role.entity";
|
|
9
10
|
import { SecurityWorkflowNotifier } from "./contracts";
|
|
10
11
|
export declare class SecurityAuthService {
|
|
11
|
-
private readonly
|
|
12
|
+
private readonly appUsersRepo;
|
|
13
|
+
private readonly securityUsersRepo;
|
|
12
14
|
private readonly refreshTokenRepo;
|
|
13
15
|
private readonly passwordResetRepo;
|
|
14
16
|
private readonly rolesRepo;
|
|
15
17
|
private readonly userRolesRepo;
|
|
16
18
|
private readonly options;
|
|
17
19
|
private readonly notifier;
|
|
18
|
-
constructor(
|
|
20
|
+
constructor(appUsersRepo: Repository<AppUserEntity>, securityUsersRepo: Repository<SecurityUserEntity>, refreshTokenRepo: Repository<RefreshTokenEntity>, passwordResetRepo: Repository<PasswordResetTokenEntity>, rolesRepo: Repository<SecurityRoleEntity>, userRolesRepo: Repository<SecurityUserRoleEntity>, options: SecurityAuthModuleOptions, notifier: SecurityWorkflowNotifier);
|
|
19
21
|
register(params: {
|
|
20
22
|
email: string;
|
|
21
23
|
password: string;
|
|
22
|
-
firstName?: string | null;
|
|
23
|
-
lastName?: string | null;
|
|
24
24
|
}): Promise<RegisterResponse>;
|
|
25
25
|
login(params: {
|
|
26
26
|
email: string;
|
|
@@ -50,6 +50,7 @@ export declare class SecurityAuthService {
|
|
|
50
50
|
userId: string;
|
|
51
51
|
roles: string[];
|
|
52
52
|
}>;
|
|
53
|
+
getUserIdByVerificationToken(token: string): Promise<string | null>;
|
|
53
54
|
private assertCanAuthenticate;
|
|
54
55
|
private issueTokens;
|
|
55
56
|
private createEmailVerificationToken;
|