@scryan7371/sdr-security 0.1.1 → 0.1.2
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 +175 -13
- package/dist/api/contracts.d.ts +12 -0
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.js +1 -0
- package/dist/api/migrations/1739520000000-create-password-reset-tokens.d.ts +9 -0
- package/dist/api/migrations/1739520000000-create-password-reset-tokens.js +42 -0
- package/dist/api/migrations/index.d.ts +2 -1
- package/dist/api/migrations/index.js +4 -1
- package/dist/api/migrations/migrations.test.d.ts +1 -0
- package/dist/api/migrations/migrations.test.js +134 -0
- package/dist/api/notification-workflows.d.ts +35 -0
- package/dist/api/notification-workflows.js +23 -0
- package/dist/api/notification-workflows.test.d.ts +1 -0
- package/dist/api/notification-workflows.test.js +66 -0
- package/dist/api/validation.test.d.ts +1 -0
- package/dist/api/validation.test.js +20 -0
- package/dist/app/client.d.ts +17 -2
- package/dist/app/client.js +38 -11
- package/dist/app/client.test.d.ts +1 -0
- package/dist/app/client.test.js +132 -0
- package/dist/index.test.d.ts +1 -0
- package/dist/index.test.js +10 -0
- package/dist/integration/database.integration.test.d.ts +1 -0
- package/dist/integration/database.integration.test.js +158 -0
- package/dist/nest/contracts.d.ts +24 -0
- package/dist/nest/contracts.js +2 -0
- package/dist/nest/dto/auth.dto.d.ts +27 -0
- package/dist/nest/dto/auth.dto.js +99 -0
- package/dist/nest/dto/workflows.dto.d.ts +16 -0
- package/dist/nest/dto/workflows.dto.js +58 -0
- package/dist/nest/entities/app-user.entity.d.ts +11 -0
- package/dist/nest/entities/app-user.entity.js +64 -0
- package/dist/nest/entities/password-reset-token.entity.d.ts +8 -0
- package/dist/nest/entities/password-reset-token.entity.js +49 -0
- package/dist/nest/entities/refresh-token.entity.d.ts +8 -0
- package/dist/nest/entities/refresh-token.entity.js +49 -0
- package/dist/nest/entities/security-role.entity.d.ts +6 -0
- package/dist/nest/entities/security-role.entity.js +39 -0
- package/dist/nest/entities/security-user-role.entity.d.ts +5 -0
- package/dist/nest/entities/security-user-role.entity.js +34 -0
- package/dist/nest/index.d.ts +18 -0
- package/dist/nest/index.js +34 -0
- package/dist/nest/index.test.d.ts +1 -0
- package/dist/nest/index.test.js +14 -0
- package/dist/nest/security-admin.guard.d.ts +4 -0
- package/dist/nest/security-admin.guard.js +25 -0
- package/dist/nest/security-admin.guard.test.d.ts +1 -0
- package/dist/nest/security-admin.guard.test.js +24 -0
- package/dist/nest/security-auth.constants.d.ts +1 -0
- package/dist/nest/security-auth.constants.js +4 -0
- package/dist/nest/security-auth.controller.d.ts +53 -0
- package/dist/nest/security-auth.controller.js +179 -0
- package/dist/nest/security-auth.controller.test.d.ts +1 -0
- package/dist/nest/security-auth.controller.test.js +91 -0
- package/dist/nest/security-auth.module.d.ts +9 -0
- package/dist/nest/security-auth.module.js +68 -0
- package/dist/nest/security-auth.options.d.ts +8 -0
- package/dist/nest/security-auth.options.js +2 -0
- package/dist/nest/security-auth.service.d.ts +59 -0
- package/dist/nest/security-auth.service.js +269 -0
- package/dist/nest/security-auth.service.test.d.ts +1 -0
- package/dist/nest/security-auth.service.test.js +245 -0
- package/dist/nest/security-jwt.guard.d.ts +7 -0
- package/dist/nest/security-jwt.guard.js +46 -0
- package/dist/nest/security-jwt.guard.test.d.ts +1 -0
- package/dist/nest/security-jwt.guard.test.js +51 -0
- package/dist/nest/security-modules.test.d.ts +1 -0
- package/dist/nest/security-modules.test.js +61 -0
- package/dist/nest/security-workflows.controller.d.ts +72 -0
- package/dist/nest/security-workflows.controller.js +187 -0
- package/dist/nest/security-workflows.controller.test.d.ts +1 -0
- package/dist/nest/security-workflows.controller.test.js +87 -0
- package/dist/nest/security-workflows.module.d.ts +9 -0
- package/dist/nest/security-workflows.module.js +59 -0
- package/dist/nest/security-workflows.service.d.ts +67 -0
- package/dist/nest/security-workflows.service.js +200 -0
- package/dist/nest/security-workflows.service.test.d.ts +1 -0
- package/dist/nest/security-workflows.service.test.js +173 -0
- package/dist/nest/swagger.d.ts +2 -0
- package/dist/nest/swagger.js +16 -0
- package/dist/nest/swagger.test.d.ts +1 -0
- package/dist/nest/swagger.test.js +21 -0
- package/dist/nest/tokens.d.ts +1 -0
- package/dist/nest/tokens.js +4 -0
- package/package.json +45 -4
- package/src/api/contracts.ts +11 -0
- package/src/api/index.ts +1 -0
- package/src/api/migrations/1739520000000-create-password-reset-tokens.ts +57 -0
- package/src/api/migrations/index.ts +3 -0
- package/src/api/migrations/migrations.test.ts +208 -0
- package/src/api/notification-workflows.test.ts +81 -0
- package/src/api/notification-workflows.ts +45 -0
- package/src/api/validation.test.ts +21 -0
- package/src/app/client.test.ts +159 -0
- package/src/app/client.ts +73 -12
- package/src/index.test.ts +9 -0
- package/src/integration/database.integration.test.ts +205 -0
- package/src/nest/contracts.ts +25 -0
- package/src/nest/dto/auth.dto.ts +54 -0
- package/src/nest/dto/workflows.dto.ts +29 -0
- package/src/nest/entities/app-user.entity.ts +31 -0
- package/src/nest/entities/password-reset-token.entity.ts +27 -0
- package/src/nest/entities/refresh-token.entity.ts +22 -0
- package/src/nest/entities/security-role.entity.ts +16 -0
- package/src/nest/entities/security-user-role.entity.ts +13 -0
- package/src/nest/index.test.ts +20 -0
- package/src/nest/index.ts +18 -0
- package/src/nest/security-admin.guard.test.ts +31 -0
- package/src/nest/security-admin.guard.ts +21 -0
- package/src/nest/security-auth.constants.ts +1 -0
- package/src/nest/security-auth.controller.test.ts +132 -0
- package/src/nest/security-auth.controller.ts +152 -0
- package/src/nest/security-auth.module.ts +63 -0
- package/src/nest/security-auth.options.ts +8 -0
- package/src/nest/security-auth.service.test.ts +337 -0
- package/src/nest/security-auth.service.ts +319 -0
- package/src/nest/security-jwt.guard.test.ts +65 -0
- package/src/nest/security-jwt.guard.ts +47 -0
- package/src/nest/security-modules.test.ts +79 -0
- package/src/nest/security-workflows.controller.test.ts +119 -0
- package/src/nest/security-workflows.controller.ts +149 -0
- package/src/nest/security-workflows.module.ts +54 -0
- package/src/nest/security-workflows.service.test.ts +232 -0
- package/src/nest/security-workflows.service.ts +215 -0
- package/src/nest/swagger.test.ts +27 -0
- package/src/nest/swagger.ts +18 -0
- package/src/nest/tokens.ts +1 -0
|
@@ -0,0 +1,64 @@
|
|
|
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.AppUserEntity = void 0;
|
|
13
|
+
const typeorm_1 = require("typeorm");
|
|
14
|
+
let AppUserEntity = class AppUserEntity {
|
|
15
|
+
id;
|
|
16
|
+
email;
|
|
17
|
+
passwordHash;
|
|
18
|
+
firstName;
|
|
19
|
+
lastName;
|
|
20
|
+
emailVerifiedAt;
|
|
21
|
+
emailVerificationToken;
|
|
22
|
+
adminApprovedAt;
|
|
23
|
+
isActive;
|
|
24
|
+
};
|
|
25
|
+
exports.AppUserEntity = AppUserEntity;
|
|
26
|
+
__decorate([
|
|
27
|
+
(0, typeorm_1.PrimaryGeneratedColumn)("uuid"),
|
|
28
|
+
__metadata("design:type", String)
|
|
29
|
+
], AppUserEntity.prototype, "id", void 0);
|
|
30
|
+
__decorate([
|
|
31
|
+
(0, typeorm_1.Column)({ type: "varchar" }),
|
|
32
|
+
__metadata("design:type", String)
|
|
33
|
+
], 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
|
+
exports.AppUserEntity = AppUserEntity = __decorate([
|
|
63
|
+
(0, typeorm_1.Entity)({ name: "app_user" })
|
|
64
|
+
], AppUserEntity);
|
|
@@ -0,0 +1,49 @@
|
|
|
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.PasswordResetTokenEntity = void 0;
|
|
13
|
+
const typeorm_1 = require("typeorm");
|
|
14
|
+
let PasswordResetTokenEntity = class PasswordResetTokenEntity {
|
|
15
|
+
id;
|
|
16
|
+
userId;
|
|
17
|
+
token;
|
|
18
|
+
expiresAt;
|
|
19
|
+
usedAt;
|
|
20
|
+
createdAt;
|
|
21
|
+
};
|
|
22
|
+
exports.PasswordResetTokenEntity = PasswordResetTokenEntity;
|
|
23
|
+
__decorate([
|
|
24
|
+
(0, typeorm_1.PrimaryGeneratedColumn)("uuid"),
|
|
25
|
+
__metadata("design:type", String)
|
|
26
|
+
], PasswordResetTokenEntity.prototype, "id", void 0);
|
|
27
|
+
__decorate([
|
|
28
|
+
(0, typeorm_1.Column)({ type: "varchar", name: "user_id" }),
|
|
29
|
+
__metadata("design:type", String)
|
|
30
|
+
], PasswordResetTokenEntity.prototype, "userId", void 0);
|
|
31
|
+
__decorate([
|
|
32
|
+
(0, typeorm_1.Column)({ type: "varchar", unique: true }),
|
|
33
|
+
__metadata("design:type", String)
|
|
34
|
+
], PasswordResetTokenEntity.prototype, "token", void 0);
|
|
35
|
+
__decorate([
|
|
36
|
+
(0, typeorm_1.Column)({ type: "timestamptz", name: "expires_at" }),
|
|
37
|
+
__metadata("design:type", Date)
|
|
38
|
+
], PasswordResetTokenEntity.prototype, "expiresAt", void 0);
|
|
39
|
+
__decorate([
|
|
40
|
+
(0, typeorm_1.Column)({ type: "timestamptz", name: "used_at", nullable: true }),
|
|
41
|
+
__metadata("design:type", Object)
|
|
42
|
+
], PasswordResetTokenEntity.prototype, "usedAt", void 0);
|
|
43
|
+
__decorate([
|
|
44
|
+
(0, typeorm_1.CreateDateColumn)({ name: "created_at" }),
|
|
45
|
+
__metadata("design:type", Date)
|
|
46
|
+
], PasswordResetTokenEntity.prototype, "createdAt", void 0);
|
|
47
|
+
exports.PasswordResetTokenEntity = PasswordResetTokenEntity = __decorate([
|
|
48
|
+
(0, typeorm_1.Entity)({ name: "security_password_reset_token" })
|
|
49
|
+
], PasswordResetTokenEntity);
|
|
@@ -0,0 +1,49 @@
|
|
|
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.RefreshTokenEntity = void 0;
|
|
13
|
+
const typeorm_1 = require("typeorm");
|
|
14
|
+
let RefreshTokenEntity = class RefreshTokenEntity {
|
|
15
|
+
id;
|
|
16
|
+
tokenHash;
|
|
17
|
+
expiresAt;
|
|
18
|
+
revokedAt;
|
|
19
|
+
userId;
|
|
20
|
+
createdAt;
|
|
21
|
+
};
|
|
22
|
+
exports.RefreshTokenEntity = RefreshTokenEntity;
|
|
23
|
+
__decorate([
|
|
24
|
+
(0, typeorm_1.PrimaryColumn)({ type: "varchar" }),
|
|
25
|
+
__metadata("design:type", String)
|
|
26
|
+
], RefreshTokenEntity.prototype, "id", void 0);
|
|
27
|
+
__decorate([
|
|
28
|
+
(0, typeorm_1.Column)({ type: "varchar", name: "token_hash" }),
|
|
29
|
+
__metadata("design:type", String)
|
|
30
|
+
], RefreshTokenEntity.prototype, "tokenHash", void 0);
|
|
31
|
+
__decorate([
|
|
32
|
+
(0, typeorm_1.Column)({ type: "timestamptz", name: "expires_at" }),
|
|
33
|
+
__metadata("design:type", Date)
|
|
34
|
+
], RefreshTokenEntity.prototype, "expiresAt", void 0);
|
|
35
|
+
__decorate([
|
|
36
|
+
(0, typeorm_1.Column)({ type: "timestamptz", name: "revoked_at", nullable: true }),
|
|
37
|
+
__metadata("design:type", Object)
|
|
38
|
+
], RefreshTokenEntity.prototype, "revokedAt", void 0);
|
|
39
|
+
__decorate([
|
|
40
|
+
(0, typeorm_1.Column)({ type: "varchar", name: "userId", nullable: true }),
|
|
41
|
+
__metadata("design:type", Object)
|
|
42
|
+
], RefreshTokenEntity.prototype, "userId", void 0);
|
|
43
|
+
__decorate([
|
|
44
|
+
(0, typeorm_1.CreateDateColumn)({ name: "created_at" }),
|
|
45
|
+
__metadata("design:type", Date)
|
|
46
|
+
], RefreshTokenEntity.prototype, "createdAt", void 0);
|
|
47
|
+
exports.RefreshTokenEntity = RefreshTokenEntity = __decorate([
|
|
48
|
+
(0, typeorm_1.Entity)({ name: "refresh_token" })
|
|
49
|
+
], RefreshTokenEntity);
|
|
@@ -0,0 +1,39 @@
|
|
|
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.SecurityRoleEntity = void 0;
|
|
13
|
+
const typeorm_1 = require("typeorm");
|
|
14
|
+
let SecurityRoleEntity = class SecurityRoleEntity {
|
|
15
|
+
id;
|
|
16
|
+
roleKey;
|
|
17
|
+
description;
|
|
18
|
+
isSystem;
|
|
19
|
+
};
|
|
20
|
+
exports.SecurityRoleEntity = SecurityRoleEntity;
|
|
21
|
+
__decorate([
|
|
22
|
+
(0, typeorm_1.PrimaryGeneratedColumn)("uuid"),
|
|
23
|
+
__metadata("design:type", String)
|
|
24
|
+
], SecurityRoleEntity.prototype, "id", void 0);
|
|
25
|
+
__decorate([
|
|
26
|
+
(0, typeorm_1.Column)({ type: "varchar", name: "role_key", unique: true }),
|
|
27
|
+
__metadata("design:type", String)
|
|
28
|
+
], SecurityRoleEntity.prototype, "roleKey", void 0);
|
|
29
|
+
__decorate([
|
|
30
|
+
(0, typeorm_1.Column)({ type: "text", nullable: true }),
|
|
31
|
+
__metadata("design:type", Object)
|
|
32
|
+
], SecurityRoleEntity.prototype, "description", void 0);
|
|
33
|
+
__decorate([
|
|
34
|
+
(0, typeorm_1.Column)({ type: "boolean", name: "is_system", default: false }),
|
|
35
|
+
__metadata("design:type", Boolean)
|
|
36
|
+
], SecurityRoleEntity.prototype, "isSystem", void 0);
|
|
37
|
+
exports.SecurityRoleEntity = SecurityRoleEntity = __decorate([
|
|
38
|
+
(0, typeorm_1.Entity)({ name: "security_role" })
|
|
39
|
+
], SecurityRoleEntity);
|
|
@@ -0,0 +1,34 @@
|
|
|
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.SecurityUserRoleEntity = void 0;
|
|
13
|
+
const typeorm_1 = require("typeorm");
|
|
14
|
+
let SecurityUserRoleEntity = class SecurityUserRoleEntity {
|
|
15
|
+
id;
|
|
16
|
+
userId;
|
|
17
|
+
roleId;
|
|
18
|
+
};
|
|
19
|
+
exports.SecurityUserRoleEntity = SecurityUserRoleEntity;
|
|
20
|
+
__decorate([
|
|
21
|
+
(0, typeorm_1.PrimaryGeneratedColumn)("uuid"),
|
|
22
|
+
__metadata("design:type", String)
|
|
23
|
+
], SecurityUserRoleEntity.prototype, "id", void 0);
|
|
24
|
+
__decorate([
|
|
25
|
+
(0, typeorm_1.Column)({ type: "varchar", name: "user_id" }),
|
|
26
|
+
__metadata("design:type", String)
|
|
27
|
+
], SecurityUserRoleEntity.prototype, "userId", void 0);
|
|
28
|
+
__decorate([
|
|
29
|
+
(0, typeorm_1.Column)({ type: "uuid", name: "role_id" }),
|
|
30
|
+
__metadata("design:type", String)
|
|
31
|
+
], SecurityUserRoleEntity.prototype, "roleId", void 0);
|
|
32
|
+
exports.SecurityUserRoleEntity = SecurityUserRoleEntity = __decorate([
|
|
33
|
+
(0, typeorm_1.Entity)({ name: "security_user_role" })
|
|
34
|
+
], SecurityUserRoleEntity);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export * from "./contracts";
|
|
2
|
+
export * from "./tokens";
|
|
3
|
+
export * from "./security-auth.constants";
|
|
4
|
+
export * from "./security-auth.options";
|
|
5
|
+
export * from "./security-auth.service";
|
|
6
|
+
export * from "./security-auth.controller";
|
|
7
|
+
export * from "./security-auth.module";
|
|
8
|
+
export * from "./security-jwt.guard";
|
|
9
|
+
export * from "./security-admin.guard";
|
|
10
|
+
export * from "./swagger";
|
|
11
|
+
export * from "./security-workflows.service";
|
|
12
|
+
export * from "./security-workflows.controller";
|
|
13
|
+
export * from "./security-workflows.module";
|
|
14
|
+
export * from "./entities/app-user.entity";
|
|
15
|
+
export * from "./entities/refresh-token.entity";
|
|
16
|
+
export * from "./entities/password-reset-token.entity";
|
|
17
|
+
export * from "./entities/security-role.entity";
|
|
18
|
+
export * from "./entities/security-user-role.entity";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./contracts"), exports);
|
|
18
|
+
__exportStar(require("./tokens"), exports);
|
|
19
|
+
__exportStar(require("./security-auth.constants"), exports);
|
|
20
|
+
__exportStar(require("./security-auth.options"), exports);
|
|
21
|
+
__exportStar(require("./security-auth.service"), exports);
|
|
22
|
+
__exportStar(require("./security-auth.controller"), exports);
|
|
23
|
+
__exportStar(require("./security-auth.module"), exports);
|
|
24
|
+
__exportStar(require("./security-jwt.guard"), exports);
|
|
25
|
+
__exportStar(require("./security-admin.guard"), exports);
|
|
26
|
+
__exportStar(require("./swagger"), exports);
|
|
27
|
+
__exportStar(require("./security-workflows.service"), exports);
|
|
28
|
+
__exportStar(require("./security-workflows.controller"), exports);
|
|
29
|
+
__exportStar(require("./security-workflows.module"), exports);
|
|
30
|
+
__exportStar(require("./entities/app-user.entity"), exports);
|
|
31
|
+
__exportStar(require("./entities/refresh-token.entity"), exports);
|
|
32
|
+
__exportStar(require("./entities/password-reset-token.entity"), exports);
|
|
33
|
+
__exportStar(require("./entities/security-role.entity"), exports);
|
|
34
|
+
__exportStar(require("./entities/security-user-role.entity"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const index_1 = require("./index");
|
|
5
|
+
(0, vitest_1.describe)("nest exports", () => {
|
|
6
|
+
(0, vitest_1.it)("exports core module surface", () => {
|
|
7
|
+
(0, vitest_1.expect)(index_1.SecurityAuthModule).toBeDefined();
|
|
8
|
+
(0, vitest_1.expect)(index_1.SecurityWorkflowsModule).toBeDefined();
|
|
9
|
+
(0, vitest_1.expect)(index_1.SecurityAuthController).toBeDefined();
|
|
10
|
+
(0, vitest_1.expect)(index_1.SecurityWorkflowsController).toBeDefined();
|
|
11
|
+
(0, vitest_1.expect)(index_1.SecurityJwtGuard).toBeDefined();
|
|
12
|
+
(0, vitest_1.expect)(index_1.SecurityAdminGuard).toBeDefined();
|
|
13
|
+
});
|
|
14
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.SecurityAdminGuard = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const contracts_1 = require("../api/contracts");
|
|
12
|
+
let SecurityAdminGuard = class SecurityAdminGuard {
|
|
13
|
+
canActivate(context) {
|
|
14
|
+
const request = context.switchToHttp().getRequest();
|
|
15
|
+
const roles = request.user?.roles ?? [];
|
|
16
|
+
if (!roles.includes(contracts_1.ADMIN_ROLE)) {
|
|
17
|
+
throw new common_1.ForbiddenException("Admin access required");
|
|
18
|
+
}
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
exports.SecurityAdminGuard = SecurityAdminGuard;
|
|
23
|
+
exports.SecurityAdminGuard = SecurityAdminGuard = __decorate([
|
|
24
|
+
(0, common_1.Injectable)()
|
|
25
|
+
], SecurityAdminGuard);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const common_1 = require("@nestjs/common");
|
|
4
|
+
const vitest_1 = require("vitest");
|
|
5
|
+
const security_admin_guard_1 = require("./security-admin.guard");
|
|
6
|
+
const makeContext = (roles) => ({
|
|
7
|
+
switchToHttp: () => ({
|
|
8
|
+
getRequest: () => ({ user: { roles } }),
|
|
9
|
+
}),
|
|
10
|
+
});
|
|
11
|
+
(0, vitest_1.describe)("SecurityAdminGuard", () => {
|
|
12
|
+
(0, vitest_1.it)("allows admin role", () => {
|
|
13
|
+
const guard = new security_admin_guard_1.SecurityAdminGuard();
|
|
14
|
+
(0, vitest_1.expect)(guard.canActivate(makeContext(["ADMIN"]))).toBe(true);
|
|
15
|
+
});
|
|
16
|
+
(0, vitest_1.it)("rejects non-admin roles", () => {
|
|
17
|
+
const guard = new security_admin_guard_1.SecurityAdminGuard();
|
|
18
|
+
(0, vitest_1.expect)(() => guard.canActivate(makeContext(["USER"]))).toThrow(common_1.ForbiddenException);
|
|
19
|
+
});
|
|
20
|
+
(0, vitest_1.it)("rejects when user/roles are missing", () => {
|
|
21
|
+
const guard = new security_admin_guard_1.SecurityAdminGuard();
|
|
22
|
+
(0, vitest_1.expect)(() => guard.canActivate(makeContext(undefined))).toThrow("Admin access required");
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const SECURITY_AUTH_OPTIONS: unique symbol;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { SecurityAuthService } from "./security-auth.service";
|
|
2
|
+
type AuthedRequest = {
|
|
3
|
+
user: {
|
|
4
|
+
sub: string;
|
|
5
|
+
};
|
|
6
|
+
};
|
|
7
|
+
export declare class SecurityAuthController {
|
|
8
|
+
private readonly authService;
|
|
9
|
+
constructor(authService: SecurityAuthService);
|
|
10
|
+
register(body: {
|
|
11
|
+
email?: string;
|
|
12
|
+
password?: string;
|
|
13
|
+
firstName?: string;
|
|
14
|
+
lastName?: string;
|
|
15
|
+
}): Promise<import("../api").RegisterResponse>;
|
|
16
|
+
login(body: {
|
|
17
|
+
email?: string;
|
|
18
|
+
password?: string;
|
|
19
|
+
}): Promise<import("../api").AuthResponse>;
|
|
20
|
+
refresh(body: {
|
|
21
|
+
refreshToken?: string;
|
|
22
|
+
}): Promise<import("../api").AuthResponse>;
|
|
23
|
+
logout(body: {
|
|
24
|
+
refreshToken?: string;
|
|
25
|
+
}): Promise<{
|
|
26
|
+
success: true;
|
|
27
|
+
}>;
|
|
28
|
+
changePassword(request: AuthedRequest, body: {
|
|
29
|
+
currentPassword?: string;
|
|
30
|
+
newPassword?: string;
|
|
31
|
+
}): Promise<{
|
|
32
|
+
success: true;
|
|
33
|
+
}>;
|
|
34
|
+
forgotPassword(body: {
|
|
35
|
+
email?: string;
|
|
36
|
+
}): Promise<{
|
|
37
|
+
success: true;
|
|
38
|
+
}>;
|
|
39
|
+
resetPassword(body: {
|
|
40
|
+
token?: string;
|
|
41
|
+
newPassword?: string;
|
|
42
|
+
}): Promise<{
|
|
43
|
+
success: true;
|
|
44
|
+
}>;
|
|
45
|
+
verifyEmail(token?: string): Promise<{
|
|
46
|
+
success: true;
|
|
47
|
+
}>;
|
|
48
|
+
getMyRoles(request: AuthedRequest): Promise<{
|
|
49
|
+
userId: string;
|
|
50
|
+
roles: string[];
|
|
51
|
+
}>;
|
|
52
|
+
}
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,179 @@
|
|
|
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
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.SecurityAuthController = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
18
|
+
const security_jwt_guard_1 = require("./security-jwt.guard");
|
|
19
|
+
const security_auth_service_1 = require("./security-auth.service");
|
|
20
|
+
const auth_dto_1 = require("./dto/auth.dto");
|
|
21
|
+
let SecurityAuthController = class SecurityAuthController {
|
|
22
|
+
authService;
|
|
23
|
+
constructor(authService) {
|
|
24
|
+
this.authService = authService;
|
|
25
|
+
}
|
|
26
|
+
async register(body) {
|
|
27
|
+
if (!body.email || !body.password) {
|
|
28
|
+
throw new common_1.BadRequestException("Email and password are required");
|
|
29
|
+
}
|
|
30
|
+
return this.authService.register({
|
|
31
|
+
email: body.email,
|
|
32
|
+
password: body.password,
|
|
33
|
+
firstName: body.firstName ?? null,
|
|
34
|
+
lastName: body.lastName ?? null,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
async login(body) {
|
|
38
|
+
if (!body.email || !body.password) {
|
|
39
|
+
throw new common_1.BadRequestException("Email and password are required");
|
|
40
|
+
}
|
|
41
|
+
return this.authService.login({
|
|
42
|
+
email: body.email,
|
|
43
|
+
password: body.password,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
async refresh(body) {
|
|
47
|
+
if (!body.refreshToken) {
|
|
48
|
+
throw new common_1.BadRequestException("Refresh token is required");
|
|
49
|
+
}
|
|
50
|
+
return this.authService.refresh(body.refreshToken);
|
|
51
|
+
}
|
|
52
|
+
async logout(body) {
|
|
53
|
+
return this.authService.logout(body.refreshToken);
|
|
54
|
+
}
|
|
55
|
+
async changePassword(request, body) {
|
|
56
|
+
if (!body.currentPassword || !body.newPassword) {
|
|
57
|
+
throw new common_1.BadRequestException("Current password and new password are required");
|
|
58
|
+
}
|
|
59
|
+
return this.authService.changePassword({
|
|
60
|
+
userId: request.user.sub,
|
|
61
|
+
currentPassword: body.currentPassword,
|
|
62
|
+
newPassword: body.newPassword,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
async forgotPassword(body) {
|
|
66
|
+
if (!body.email) {
|
|
67
|
+
throw new common_1.BadRequestException("Email is required");
|
|
68
|
+
}
|
|
69
|
+
return this.authService.requestForgotPassword(body.email);
|
|
70
|
+
}
|
|
71
|
+
async resetPassword(body) {
|
|
72
|
+
if (!body.token || !body.newPassword) {
|
|
73
|
+
throw new common_1.BadRequestException("Token and newPassword are required");
|
|
74
|
+
}
|
|
75
|
+
return this.authService.resetPassword(body.token, body.newPassword);
|
|
76
|
+
}
|
|
77
|
+
async verifyEmail(token) {
|
|
78
|
+
if (!token) {
|
|
79
|
+
throw new common_1.BadRequestException("Verification token is required");
|
|
80
|
+
}
|
|
81
|
+
return this.authService.verifyEmailByToken(token);
|
|
82
|
+
}
|
|
83
|
+
async getMyRoles(request) {
|
|
84
|
+
return this.authService.getMyRoles(request.user.sub);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
exports.SecurityAuthController = SecurityAuthController;
|
|
88
|
+
__decorate([
|
|
89
|
+
(0, common_1.Post)("register"),
|
|
90
|
+
(0, swagger_1.ApiOperation)({ summary: "Register a new user" }),
|
|
91
|
+
(0, swagger_1.ApiBody)({ type: auth_dto_1.RegisterDto }),
|
|
92
|
+
__param(0, (0, common_1.Body)()),
|
|
93
|
+
__metadata("design:type", Function),
|
|
94
|
+
__metadata("design:paramtypes", [Object]),
|
|
95
|
+
__metadata("design:returntype", Promise)
|
|
96
|
+
], SecurityAuthController.prototype, "register", null);
|
|
97
|
+
__decorate([
|
|
98
|
+
(0, common_1.Post)("login"),
|
|
99
|
+
(0, swagger_1.ApiOperation)({ summary: "Login with email/password" }),
|
|
100
|
+
(0, swagger_1.ApiBody)({ type: auth_dto_1.LoginDto }),
|
|
101
|
+
__param(0, (0, common_1.Body)()),
|
|
102
|
+
__metadata("design:type", Function),
|
|
103
|
+
__metadata("design:paramtypes", [Object]),
|
|
104
|
+
__metadata("design:returntype", Promise)
|
|
105
|
+
], SecurityAuthController.prototype, "login", null);
|
|
106
|
+
__decorate([
|
|
107
|
+
(0, common_1.Post)("refresh"),
|
|
108
|
+
(0, swagger_1.ApiOperation)({ summary: "Refresh access token" }),
|
|
109
|
+
(0, swagger_1.ApiBody)({ type: auth_dto_1.RefreshDto }),
|
|
110
|
+
__param(0, (0, common_1.Body)()),
|
|
111
|
+
__metadata("design:type", Function),
|
|
112
|
+
__metadata("design:paramtypes", [Object]),
|
|
113
|
+
__metadata("design:returntype", Promise)
|
|
114
|
+
], SecurityAuthController.prototype, "refresh", null);
|
|
115
|
+
__decorate([
|
|
116
|
+
(0, common_1.UseGuards)(security_jwt_guard_1.SecurityJwtGuard),
|
|
117
|
+
(0, common_1.Post)("logout"),
|
|
118
|
+
(0, swagger_1.ApiOperation)({ summary: "Logout user" }),
|
|
119
|
+
(0, swagger_1.ApiBearerAuth)(),
|
|
120
|
+
(0, swagger_1.ApiBody)({ type: auth_dto_1.LogoutDto }),
|
|
121
|
+
__param(0, (0, common_1.Body)()),
|
|
122
|
+
__metadata("design:type", Function),
|
|
123
|
+
__metadata("design:paramtypes", [Object]),
|
|
124
|
+
__metadata("design:returntype", Promise)
|
|
125
|
+
], SecurityAuthController.prototype, "logout", null);
|
|
126
|
+
__decorate([
|
|
127
|
+
(0, common_1.UseGuards)(security_jwt_guard_1.SecurityJwtGuard),
|
|
128
|
+
(0, common_1.Post)("change-password"),
|
|
129
|
+
(0, swagger_1.ApiOperation)({ summary: "Change password for authenticated user" }),
|
|
130
|
+
(0, swagger_1.ApiBearerAuth)(),
|
|
131
|
+
(0, swagger_1.ApiBody)({ type: auth_dto_1.ChangePasswordDto }),
|
|
132
|
+
__param(0, (0, common_1.Req)()),
|
|
133
|
+
__param(1, (0, common_1.Body)()),
|
|
134
|
+
__metadata("design:type", Function),
|
|
135
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
136
|
+
__metadata("design:returntype", Promise)
|
|
137
|
+
], SecurityAuthController.prototype, "changePassword", null);
|
|
138
|
+
__decorate([
|
|
139
|
+
(0, common_1.Post)("forgot-password"),
|
|
140
|
+
(0, swagger_1.ApiOperation)({ summary: "Request password reset token by email" }),
|
|
141
|
+
(0, swagger_1.ApiBody)({ type: auth_dto_1.ForgotPasswordDto }),
|
|
142
|
+
__param(0, (0, common_1.Body)()),
|
|
143
|
+
__metadata("design:type", Function),
|
|
144
|
+
__metadata("design:paramtypes", [Object]),
|
|
145
|
+
__metadata("design:returntype", Promise)
|
|
146
|
+
], SecurityAuthController.prototype, "forgotPassword", null);
|
|
147
|
+
__decorate([
|
|
148
|
+
(0, common_1.Post)("reset-password"),
|
|
149
|
+
(0, swagger_1.ApiOperation)({ summary: "Reset password with token" }),
|
|
150
|
+
(0, swagger_1.ApiBody)({ type: auth_dto_1.ResetPasswordDto }),
|
|
151
|
+
__param(0, (0, common_1.Body)()),
|
|
152
|
+
__metadata("design:type", Function),
|
|
153
|
+
__metadata("design:paramtypes", [Object]),
|
|
154
|
+
__metadata("design:returntype", Promise)
|
|
155
|
+
], SecurityAuthController.prototype, "resetPassword", null);
|
|
156
|
+
__decorate([
|
|
157
|
+
(0, common_1.Get)("verify-email"),
|
|
158
|
+
(0, swagger_1.ApiOperation)({ summary: "Verify email using token" }),
|
|
159
|
+
(0, swagger_1.ApiQuery)({ name: "token", required: true }),
|
|
160
|
+
__param(0, (0, common_1.Query)("token")),
|
|
161
|
+
__metadata("design:type", Function),
|
|
162
|
+
__metadata("design:paramtypes", [String]),
|
|
163
|
+
__metadata("design:returntype", Promise)
|
|
164
|
+
], SecurityAuthController.prototype, "verifyEmail", null);
|
|
165
|
+
__decorate([
|
|
166
|
+
(0, common_1.UseGuards)(security_jwt_guard_1.SecurityJwtGuard),
|
|
167
|
+
(0, common_1.Get)("me/roles"),
|
|
168
|
+
(0, swagger_1.ApiOperation)({ summary: "Get roles for authenticated user" }),
|
|
169
|
+
(0, swagger_1.ApiBearerAuth)(),
|
|
170
|
+
__param(0, (0, common_1.Req)()),
|
|
171
|
+
__metadata("design:type", Function),
|
|
172
|
+
__metadata("design:paramtypes", [Object]),
|
|
173
|
+
__metadata("design:returntype", Promise)
|
|
174
|
+
], SecurityAuthController.prototype, "getMyRoles", null);
|
|
175
|
+
exports.SecurityAuthController = SecurityAuthController = __decorate([
|
|
176
|
+
(0, common_1.Controller)("security/auth"),
|
|
177
|
+
(0, swagger_1.ApiTags)("security-auth"),
|
|
178
|
+
__metadata("design:paramtypes", [security_auth_service_1.SecurityAuthService])
|
|
179
|
+
], SecurityAuthController);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|