@anarchitects/auth-nest 0.0.1
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 +88 -0
- package/package.json +60 -0
- package/src/application/application.module-definition.d.ts +25 -0
- package/src/application/application.module-definition.js +13 -0
- package/src/application/application.module-definition.js.map +1 -0
- package/src/application/application.module.d.ts +27 -0
- package/src/application/application.module.js +73 -0
- package/src/application/application.module.js.map +1 -0
- package/src/application/factories/ability.factory.d.ts +6 -0
- package/src/application/factories/ability.factory.js +34 -0
- package/src/application/factories/ability.factory.js.map +1 -0
- package/src/application/index.d.ts +8 -0
- package/src/application/index.js +12 -0
- package/src/application/index.js.map +1 -0
- package/src/application/services/auth.service.d.ts +32 -0
- package/src/application/services/auth.service.js +12 -0
- package/src/application/services/auth.service.js.map +1 -0
- package/src/application/services/bcrypt-hash.service.d.ts +5 -0
- package/src/application/services/bcrypt-hash.service.js +20 -0
- package/src/application/services/bcrypt-hash.service.js.map +1 -0
- package/src/application/services/hash.service.d.ts +4 -0
- package/src/application/services/hash.service.js +12 -0
- package/src/application/services/hash.service.js.map +1 -0
- package/src/application/services/jwt-auth.service.d.ts +41 -0
- package/src/application/services/jwt-auth.service.js +220 -0
- package/src/application/services/jwt-auth.service.js.map +1 -0
- package/src/application/services/policies.service.d.ts +10 -0
- package/src/application/services/policies.service.js +42 -0
- package/src/application/services/policies.service.js.map +1 -0
- package/src/application/strategies/jwt/strategy.d.ts +16 -0
- package/src/application/strategies/jwt/strategy.js +25 -0
- package/src/application/strategies/jwt/strategy.js.map +1 -0
- package/src/config/auth.config.d.ts +18 -0
- package/src/config/auth.config.js +17 -0
- package/src/config/auth.config.js.map +1 -0
- package/src/config/index.d.ts +1 -0
- package/src/config/index.js +5 -0
- package/src/config/index.js.map +1 -0
- package/src/index.d.ts +5 -0
- package/src/index.js +9 -0
- package/src/index.js.map +1 -0
- package/src/infrastructure-mailer/adapters/mailer.adapter.d.ts +4 -0
- package/src/infrastructure-mailer/adapters/mailer.adapter.js +7 -0
- package/src/infrastructure-mailer/adapters/mailer.adapter.js.map +1 -0
- package/src/infrastructure-mailer/adapters/node-mailer.adapter.d.ts +8 -0
- package/src/infrastructure-mailer/adapters/node-mailer.adapter.js +23 -0
- package/src/infrastructure-mailer/adapters/node-mailer.adapter.js.map +1 -0
- package/src/infrastructure-mailer/index.d.ts +3 -0
- package/src/infrastructure-mailer/index.js +7 -0
- package/src/infrastructure-mailer/index.js.map +1 -0
- package/src/infrastructure-mailer/mailer.module.d.ts +2 -0
- package/src/infrastructure-mailer/mailer.module.js +23 -0
- package/src/infrastructure-mailer/mailer.module.js.map +1 -0
- package/src/infrastructure-persistence/entities/invalidated-token.entity.d.ts +7 -0
- package/src/infrastructure-persistence/entities/invalidated-token.entity.js +42 -0
- package/src/infrastructure-persistence/entities/invalidated-token.entity.js.map +1 -0
- package/src/infrastructure-persistence/entities/permission.entity.d.ts +17 -0
- package/src/infrastructure-persistence/entities/permission.entity.js +76 -0
- package/src/infrastructure-persistence/entities/permission.entity.js.map +1 -0
- package/src/infrastructure-persistence/entities/role.entity.d.ts +12 -0
- package/src/infrastructure-persistence/entities/role.entity.js +69 -0
- package/src/infrastructure-persistence/entities/role.entity.js.map +1 -0
- package/src/infrastructure-persistence/entities/user.entity.d.ts +14 -0
- package/src/infrastructure-persistence/entities/user.entity.js +77 -0
- package/src/infrastructure-persistence/entities/user.entity.js.map +1 -0
- package/src/infrastructure-persistence/index.d.ts +2 -0
- package/src/infrastructure-persistence/index.js +6 -0
- package/src/infrastructure-persistence/index.js.map +1 -0
- package/src/infrastructure-persistence/migrations/1720200000000-create-invalidated-tokens-cache.table.d.ts +6 -0
- package/src/infrastructure-persistence/migrations/1720200000000-create-invalidated-tokens-cache.table.js +29 -0
- package/src/infrastructure-persistence/migrations/1720200000000-create-invalidated-tokens-cache.table.js.map +1 -0
- package/src/infrastructure-persistence/persistence.module-definition.d.ts +13 -0
- package/src/infrastructure-persistence/persistence.module-definition.js +13 -0
- package/src/infrastructure-persistence/persistence.module-definition.js.map +1 -0
- package/src/infrastructure-persistence/persistence.module.d.ts +7 -0
- package/src/infrastructure-persistence/persistence.module.js +52 -0
- package/src/infrastructure-persistence/persistence.module.js.map +1 -0
- package/src/infrastructure-persistence/repositories/auth-user.repository.d.ts +10 -0
- package/src/infrastructure-persistence/repositories/auth-user.repository.js +12 -0
- package/src/infrastructure-persistence/repositories/auth-user.repository.js.map +1 -0
- package/src/infrastructure-persistence/repositories/typeorm-auth-user.repository.d.ts +17 -0
- package/src/infrastructure-persistence/repositories/typeorm-auth-user.repository.js +62 -0
- package/src/infrastructure-persistence/repositories/typeorm-auth-user.repository.js.map +1 -0
- package/src/infrastructure-persistence/schema.d.ts +1 -0
- package/src/infrastructure-persistence/schema.js +5 -0
- package/src/infrastructure-persistence/schema.js.map +1 -0
- package/src/presentation/controllers/auth.controller.d.ts +39 -0
- package/src/presentation/controllers/auth.controller.js +198 -0
- package/src/presentation/controllers/auth.controller.js.map +1 -0
- package/src/presentation/decorators/policies.decorator.d.ts +3 -0
- package/src/presentation/decorators/policies.decorator.js +8 -0
- package/src/presentation/decorators/policies.decorator.js.map +1 -0
- package/src/presentation/guards/policies.guard.d.ts +9 -0
- package/src/presentation/guards/policies.guard.js +38 -0
- package/src/presentation/guards/policies.guard.js.map +1 -0
- package/src/presentation/index.d.ts +4 -0
- package/src/presentation/index.js +8 -0
- package/src/presentation/index.js.map +1 -0
- package/src/presentation/presentation.module.d.ts +2 -0
- package/src/presentation/presentation.module.js +15 -0
- package/src/presentation/presentation.module.js.map +1 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PermissionEntity = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const typeorm_1 = require("typeorm");
|
|
6
|
+
const uuidv7_1 = require("uuidv7");
|
|
7
|
+
let PermissionEntity = class PermissionEntity {
|
|
8
|
+
constructor(partial) {
|
|
9
|
+
Object.assign(this, partial);
|
|
10
|
+
}
|
|
11
|
+
generateId() {
|
|
12
|
+
if (!this.id) {
|
|
13
|
+
this.id = (0, uuidv7_1.uuidv7)();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
exports.PermissionEntity = PermissionEntity;
|
|
18
|
+
tslib_1.__decorate([
|
|
19
|
+
(0, typeorm_1.PrimaryColumn)('uuid'),
|
|
20
|
+
tslib_1.__metadata("design:type", String)
|
|
21
|
+
], PermissionEntity.prototype, "id", void 0);
|
|
22
|
+
tslib_1.__decorate([
|
|
23
|
+
(0, typeorm_1.Column)({ type: 'varchar', length: 100, unique: true }),
|
|
24
|
+
tslib_1.__metadata("design:type", String)
|
|
25
|
+
], PermissionEntity.prototype, "name", void 0);
|
|
26
|
+
tslib_1.__decorate([
|
|
27
|
+
(0, typeorm_1.Column)({ type: 'text', nullable: true }),
|
|
28
|
+
tslib_1.__metadata("design:type", Object)
|
|
29
|
+
], PermissionEntity.prototype, "description", void 0);
|
|
30
|
+
tslib_1.__decorate([
|
|
31
|
+
(0, typeorm_1.Column)({ type: 'varchar', length: 100 }),
|
|
32
|
+
tslib_1.__metadata("design:type", String)
|
|
33
|
+
], PermissionEntity.prototype, "action", void 0);
|
|
34
|
+
tslib_1.__decorate([
|
|
35
|
+
(0, typeorm_1.Column)({ type: 'varchar', length: 100 }),
|
|
36
|
+
tslib_1.__metadata("design:type", String)
|
|
37
|
+
], PermissionEntity.prototype, "subject", void 0);
|
|
38
|
+
tslib_1.__decorate([
|
|
39
|
+
(0, typeorm_1.Column)({ type: 'jsonb', nullable: true }),
|
|
40
|
+
tslib_1.__metadata("design:type", Object)
|
|
41
|
+
], PermissionEntity.prototype, "conditions", void 0);
|
|
42
|
+
tslib_1.__decorate([
|
|
43
|
+
(0, typeorm_1.Column)({ type: 'jsonb', nullable: true }),
|
|
44
|
+
tslib_1.__metadata("design:type", Object)
|
|
45
|
+
], PermissionEntity.prototype, "fields", void 0);
|
|
46
|
+
tslib_1.__decorate([
|
|
47
|
+
(0, typeorm_1.Column)({ type: 'boolean', default: false }),
|
|
48
|
+
tslib_1.__metadata("design:type", Boolean)
|
|
49
|
+
], PermissionEntity.prototype, "inverted", void 0);
|
|
50
|
+
tslib_1.__decorate([
|
|
51
|
+
(0, typeorm_1.Column)({ type: 'text', nullable: true }),
|
|
52
|
+
tslib_1.__metadata("design:type", Object)
|
|
53
|
+
], PermissionEntity.prototype, "reason", void 0);
|
|
54
|
+
tslib_1.__decorate([
|
|
55
|
+
(0, typeorm_1.ManyToMany)('RoleEntity', 'permissions'),
|
|
56
|
+
tslib_1.__metadata("design:type", Object)
|
|
57
|
+
], PermissionEntity.prototype, "roles", void 0);
|
|
58
|
+
tslib_1.__decorate([
|
|
59
|
+
(0, typeorm_1.CreateDateColumn)(),
|
|
60
|
+
tslib_1.__metadata("design:type", Date)
|
|
61
|
+
], PermissionEntity.prototype, "createdAt", void 0);
|
|
62
|
+
tslib_1.__decorate([
|
|
63
|
+
(0, typeorm_1.UpdateDateColumn)(),
|
|
64
|
+
tslib_1.__metadata("design:type", Date)
|
|
65
|
+
], PermissionEntity.prototype, "updatedAt", void 0);
|
|
66
|
+
tslib_1.__decorate([
|
|
67
|
+
(0, typeorm_1.BeforeInsert)(),
|
|
68
|
+
tslib_1.__metadata("design:type", Function),
|
|
69
|
+
tslib_1.__metadata("design:paramtypes", []),
|
|
70
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
71
|
+
], PermissionEntity.prototype, "generateId", null);
|
|
72
|
+
exports.PermissionEntity = PermissionEntity = tslib_1.__decorate([
|
|
73
|
+
(0, typeorm_1.Entity)({ schema: 'auth', name: 'permissions' }),
|
|
74
|
+
tslib_1.__metadata("design:paramtypes", [Object])
|
|
75
|
+
], PermissionEntity);
|
|
76
|
+
//# sourceMappingURL=permission.entity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permission.entity.js","sourceRoot":"","sources":["../../../../../../../libs/auth/nest/src/infrastructure-persistence/entities/permission.entity.ts"],"names":[],"mappings":";;;;AACA,qCAQiB;AACjB,mCAAgC;AAGzB,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAqC3B,YAAY,OAA4B;QACtC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC/B,CAAC;IAGD,UAAU;QACR,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;YACb,IAAI,CAAC,EAAE,GAAG,IAAA,eAAM,GAAE,CAAC;QACrB,CAAC;IACH,CAAC;CACF,CAAA;AA/CY,4CAAgB;AAE3B;IADC,IAAA,uBAAa,EAAC,MAAM,CAAC;;4CACV;AAGZ;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;;8CACzC;AAGd;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;qDACb;AAG5B;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;;gDACzB;AAGhB;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;;iDACxB;AAGjB;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;oDACE;AAG5C;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;gDACjB;AAGzB;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;;kDACzB;AAGnB;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;gDAClB;AAGvB;IADC,IAAA,oBAAU,EAAC,YAAY,EAAE,aAAa,CAAC;;+CAClB;AAGtB;IADC,IAAA,0BAAgB,GAAE;sCACP,IAAI;mDAAC;AAGjB;IADC,IAAA,0BAAgB,GAAE;sCACP,IAAI;mDAAC;AAOjB;IADC,IAAA,sBAAY,GAAE;;;;kDAKd;2BA9CU,gBAAgB;IAD5B,IAAA,gBAAM,EAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC;;GACnC,gBAAgB,CA+C5B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Permission, Role, User } from '@anarchitects/auth-ts/models';
|
|
2
|
+
export declare class RoleEntity implements Role {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
description: string | null;
|
|
6
|
+
permissions: Permission[] | null;
|
|
7
|
+
users: User[] | null;
|
|
8
|
+
createdAt: Date;
|
|
9
|
+
updatedAt: Date;
|
|
10
|
+
constructor(partial: Partial<Role>);
|
|
11
|
+
generateId(): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RoleEntity = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const typeorm_1 = require("typeorm");
|
|
6
|
+
const schema_1 = require("../schema");
|
|
7
|
+
const uuidv7_1 = require("uuidv7");
|
|
8
|
+
let RoleEntity = class RoleEntity {
|
|
9
|
+
constructor(partial) {
|
|
10
|
+
Object.assign(this, partial);
|
|
11
|
+
}
|
|
12
|
+
generateId() {
|
|
13
|
+
if (!this.id) {
|
|
14
|
+
this.id = (0, uuidv7_1.uuidv7)();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
exports.RoleEntity = RoleEntity;
|
|
19
|
+
tslib_1.__decorate([
|
|
20
|
+
(0, typeorm_1.PrimaryColumn)('uuid'),
|
|
21
|
+
tslib_1.__metadata("design:type", String)
|
|
22
|
+
], RoleEntity.prototype, "id", void 0);
|
|
23
|
+
tslib_1.__decorate([
|
|
24
|
+
(0, typeorm_1.Column)({ type: 'varchar', length: 100, unique: true }),
|
|
25
|
+
tslib_1.__metadata("design:type", String)
|
|
26
|
+
], RoleEntity.prototype, "name", void 0);
|
|
27
|
+
tslib_1.__decorate([
|
|
28
|
+
(0, typeorm_1.Column)({ type: 'text', nullable: true }),
|
|
29
|
+
tslib_1.__metadata("design:type", Object)
|
|
30
|
+
], RoleEntity.prototype, "description", void 0);
|
|
31
|
+
tslib_1.__decorate([
|
|
32
|
+
(0, typeorm_1.ManyToMany)('PermissionEntity', 'roles'),
|
|
33
|
+
(0, typeorm_1.JoinTable)({
|
|
34
|
+
name: 'role_permissions',
|
|
35
|
+
schema: schema_1.AUTH_SCHEMA,
|
|
36
|
+
joinColumn: {
|
|
37
|
+
name: 'role_id',
|
|
38
|
+
referencedColumnName: 'id',
|
|
39
|
+
},
|
|
40
|
+
inverseJoinColumn: {
|
|
41
|
+
name: 'permission_id',
|
|
42
|
+
referencedColumnName: 'id',
|
|
43
|
+
},
|
|
44
|
+
}),
|
|
45
|
+
tslib_1.__metadata("design:type", Object)
|
|
46
|
+
], RoleEntity.prototype, "permissions", void 0);
|
|
47
|
+
tslib_1.__decorate([
|
|
48
|
+
(0, typeorm_1.ManyToMany)('UserEntity', 'roles'),
|
|
49
|
+
tslib_1.__metadata("design:type", Object)
|
|
50
|
+
], RoleEntity.prototype, "users", void 0);
|
|
51
|
+
tslib_1.__decorate([
|
|
52
|
+
(0, typeorm_1.CreateDateColumn)(),
|
|
53
|
+
tslib_1.__metadata("design:type", Date)
|
|
54
|
+
], RoleEntity.prototype, "createdAt", void 0);
|
|
55
|
+
tslib_1.__decorate([
|
|
56
|
+
(0, typeorm_1.UpdateDateColumn)(),
|
|
57
|
+
tslib_1.__metadata("design:type", Date)
|
|
58
|
+
], RoleEntity.prototype, "updatedAt", void 0);
|
|
59
|
+
tslib_1.__decorate([
|
|
60
|
+
(0, typeorm_1.BeforeInsert)(),
|
|
61
|
+
tslib_1.__metadata("design:type", Function),
|
|
62
|
+
tslib_1.__metadata("design:paramtypes", []),
|
|
63
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
64
|
+
], RoleEntity.prototype, "generateId", null);
|
|
65
|
+
exports.RoleEntity = RoleEntity = tslib_1.__decorate([
|
|
66
|
+
(0, typeorm_1.Entity)({ schema: schema_1.AUTH_SCHEMA, name: 'roles' }),
|
|
67
|
+
tslib_1.__metadata("design:paramtypes", [Object])
|
|
68
|
+
], RoleEntity);
|
|
69
|
+
//# sourceMappingURL=role.entity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"role.entity.js","sourceRoot":"","sources":["../../../../../../../libs/auth/nest/src/infrastructure-persistence/entities/role.entity.ts"],"names":[],"mappings":";;;;AACA,qCASiB;AACjB,sCAAwC;AACxC,mCAAgC;AAGzB,IAAM,UAAU,GAAhB,MAAM,UAAU;IAkCrB,YAAY,OAAsB;QAChC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC/B,CAAC;IAGD,UAAU;QACR,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;YACb,IAAI,CAAC,EAAE,GAAG,IAAA,eAAM,GAAE,CAAC;QACrB,CAAC;IACH,CAAC;CACF,CAAA;AA5CY,gCAAU;AAErB;IADC,IAAA,uBAAa,EAAC,MAAM,CAAC;;sCACV;AAGZ;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;;wCACzC;AAGd;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;+CACb;AAe5B;IAbC,IAAA,oBAAU,EAAC,kBAAkB,EAAE,OAAO,CAAC;IACvC,IAAA,mBAAS,EAAC;QACT,IAAI,EAAE,kBAAkB;QACxB,MAAM,EAAE,oBAAW;QACnB,UAAU,EAAE;YACV,IAAI,EAAE,SAAS;YACf,oBAAoB,EAAE,IAAI;SAC3B;QACD,iBAAiB,EAAE;YACjB,IAAI,EAAE,eAAe;YACrB,oBAAoB,EAAE,IAAI;SAC3B;KACF,CAAC;;+CACgC;AAGlC;IADC,IAAA,oBAAU,EAAC,YAAY,EAAE,OAAO,CAAC;;yCACZ;AAGtB;IADC,IAAA,0BAAgB,GAAE;sCACP,IAAI;6CAAC;AAGjB;IADC,IAAA,0BAAgB,GAAE;sCACP,IAAI;6CAAC;AAOjB;IADC,IAAA,sBAAY,GAAE;;;;4CAKd;qBA3CU,UAAU;IADtB,IAAA,gBAAM,EAAC,EAAE,MAAM,EAAE,oBAAW,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;;GAClC,UAAU,CA4CtB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Role, User } from '@anarchitects/auth-ts/models';
|
|
2
|
+
export declare class UserEntity implements User {
|
|
3
|
+
id: string;
|
|
4
|
+
email: string;
|
|
5
|
+
userName: string | null;
|
|
6
|
+
passwordHash: string;
|
|
7
|
+
token: string | null;
|
|
8
|
+
isActive: boolean;
|
|
9
|
+
roles: Role[] | null;
|
|
10
|
+
createdAt: Date;
|
|
11
|
+
updatedAt: Date;
|
|
12
|
+
constructor(partial: Partial<User>);
|
|
13
|
+
generateId(): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UserEntity = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const typeorm_1 = require("typeorm");
|
|
6
|
+
const uuidv7_1 = require("uuidv7");
|
|
7
|
+
const schema_1 = require("../schema");
|
|
8
|
+
let UserEntity = class UserEntity {
|
|
9
|
+
constructor(partial) {
|
|
10
|
+
Object.assign(this, partial);
|
|
11
|
+
}
|
|
12
|
+
generateId() {
|
|
13
|
+
if (!this.id) {
|
|
14
|
+
this.id = (0, uuidv7_1.uuidv7)();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
exports.UserEntity = UserEntity;
|
|
19
|
+
tslib_1.__decorate([
|
|
20
|
+
(0, typeorm_1.PrimaryColumn)('uuid'),
|
|
21
|
+
tslib_1.__metadata("design:type", String)
|
|
22
|
+
], UserEntity.prototype, "id", void 0);
|
|
23
|
+
tslib_1.__decorate([
|
|
24
|
+
(0, typeorm_1.Column)({ type: 'varchar', length: 255, unique: true }),
|
|
25
|
+
tslib_1.__metadata("design:type", String)
|
|
26
|
+
], UserEntity.prototype, "email", void 0);
|
|
27
|
+
tslib_1.__decorate([
|
|
28
|
+
(0, typeorm_1.Column)({ type: 'varchar', length: 100, nullable: true }),
|
|
29
|
+
tslib_1.__metadata("design:type", Object)
|
|
30
|
+
], UserEntity.prototype, "userName", void 0);
|
|
31
|
+
tslib_1.__decorate([
|
|
32
|
+
(0, typeorm_1.Column)({ type: 'varchar', length: 255 }),
|
|
33
|
+
tslib_1.__metadata("design:type", String)
|
|
34
|
+
], UserEntity.prototype, "passwordHash", void 0);
|
|
35
|
+
tslib_1.__decorate([
|
|
36
|
+
(0, typeorm_1.Column)({ type: 'varchar', length: 500, nullable: true }),
|
|
37
|
+
tslib_1.__metadata("design:type", Object)
|
|
38
|
+
], UserEntity.prototype, "token", void 0);
|
|
39
|
+
tslib_1.__decorate([
|
|
40
|
+
(0, typeorm_1.Column)({ type: 'boolean', default: false }),
|
|
41
|
+
tslib_1.__metadata("design:type", Boolean)
|
|
42
|
+
], UserEntity.prototype, "isActive", void 0);
|
|
43
|
+
tslib_1.__decorate([
|
|
44
|
+
(0, typeorm_1.ManyToMany)('RoleEntity', 'users', { cascade: ['insert', 'update'] }),
|
|
45
|
+
(0, typeorm_1.JoinTable)({
|
|
46
|
+
name: 'user_roles',
|
|
47
|
+
schema: schema_1.AUTH_SCHEMA,
|
|
48
|
+
joinColumn: {
|
|
49
|
+
name: 'user_id',
|
|
50
|
+
referencedColumnName: 'id',
|
|
51
|
+
},
|
|
52
|
+
inverseJoinColumn: {
|
|
53
|
+
name: 'role_id',
|
|
54
|
+
referencedColumnName: 'id',
|
|
55
|
+
},
|
|
56
|
+
}),
|
|
57
|
+
tslib_1.__metadata("design:type", Object)
|
|
58
|
+
], UserEntity.prototype, "roles", void 0);
|
|
59
|
+
tslib_1.__decorate([
|
|
60
|
+
(0, typeorm_1.CreateDateColumn)(),
|
|
61
|
+
tslib_1.__metadata("design:type", Date)
|
|
62
|
+
], UserEntity.prototype, "createdAt", void 0);
|
|
63
|
+
tslib_1.__decorate([
|
|
64
|
+
(0, typeorm_1.UpdateDateColumn)(),
|
|
65
|
+
tslib_1.__metadata("design:type", Date)
|
|
66
|
+
], UserEntity.prototype, "updatedAt", void 0);
|
|
67
|
+
tslib_1.__decorate([
|
|
68
|
+
(0, typeorm_1.BeforeInsert)(),
|
|
69
|
+
tslib_1.__metadata("design:type", Function),
|
|
70
|
+
tslib_1.__metadata("design:paramtypes", []),
|
|
71
|
+
tslib_1.__metadata("design:returntype", void 0)
|
|
72
|
+
], UserEntity.prototype, "generateId", null);
|
|
73
|
+
exports.UserEntity = UserEntity = tslib_1.__decorate([
|
|
74
|
+
(0, typeorm_1.Entity)({ schema: schema_1.AUTH_SCHEMA, name: 'users' }),
|
|
75
|
+
tslib_1.__metadata("design:paramtypes", [Object])
|
|
76
|
+
], UserEntity);
|
|
77
|
+
//# sourceMappingURL=user.entity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user.entity.js","sourceRoot":"","sources":["../../../../../../../libs/auth/nest/src/infrastructure-persistence/entities/user.entity.ts"],"names":[],"mappings":";;;;AACA,qCASiB;AACjB,mCAAgC;AAChC,sCAAwC;AAGjC,IAAM,UAAU,GAAhB,MAAM,UAAU;IAwCrB,YAAY,OAAsB;QAChC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC/B,CAAC;IAGD,UAAU;QACR,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;YACb,IAAI,CAAC,EAAE,GAAG,IAAA,eAAM,GAAE,CAAC;QACrB,CAAC;IACH,CAAC;CACF,CAAA;AAlDY,gCAAU;AAErB;IADC,IAAA,uBAAa,EAAC,MAAM,CAAC;;sCACV;AAGZ;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;;yCACxC;AAGf;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;4CAChC;AAGzB;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;;gDACnB;AAGtB;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;yCACnC;AAGtB;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;;4CACzB;AAenB;IAbC,IAAA,oBAAU,EAAC,YAAY,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAE,CAAC;IACpE,IAAA,mBAAS,EAAC;QACT,IAAI,EAAE,YAAY;QAClB,MAAM,EAAE,oBAAW;QACnB,UAAU,EAAE;YACV,IAAI,EAAE,SAAS;YACf,oBAAoB,EAAE,IAAI;SAC3B;QACD,iBAAiB,EAAE;YACjB,IAAI,EAAE,SAAS;YACf,oBAAoB,EAAE,IAAI;SAC3B;KACF,CAAC;;yCACoB;AAGtB;IADC,IAAA,0BAAgB,GAAE;sCACP,IAAI;6CAAC;AAGjB;IADC,IAAA,0BAAgB,GAAE;sCACP,IAAI;6CAAC;AAOjB;IADC,IAAA,sBAAY,GAAE;;;;4CAKd;qBAjDU,UAAU;IADtB,IAAA,gBAAM,EAAC,EAAE,MAAM,EAAE,oBAAW,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;;GAClC,UAAU,CAkDtB"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./persistence.module"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./repositories/auth-user.repository"), exports);
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/auth/nest/src/infrastructure-persistence/index.ts"],"names":[],"mappings":";;;AAAA,+DAAqC;AACrC,8EAAoD"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { MigrationInterface, QueryRunner } from 'typeorm';
|
|
2
|
+
export declare class CreateInvalidatedTokensCacheTable1720200000000 implements MigrationInterface {
|
|
3
|
+
name: string;
|
|
4
|
+
up(queryRunner: QueryRunner): Promise<void>;
|
|
5
|
+
down(queryRunner: QueryRunner): Promise<void>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CreateInvalidatedTokensCacheTable1720200000000 = void 0;
|
|
4
|
+
const schema_1 = require("../schema");
|
|
5
|
+
class CreateInvalidatedTokensCacheTable1720200000000 {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.name = 'CreateInvalidatedTokensCacheTable1720200000000';
|
|
8
|
+
}
|
|
9
|
+
async up(queryRunner) {
|
|
10
|
+
await queryRunner.query(`CREATE SCHEMA IF NOT EXISTS "${schema_1.AUTH_SCHEMA}";`);
|
|
11
|
+
await queryRunner.query(`
|
|
12
|
+
CREATE UNLOGGED TABLE IF NOT EXISTS "${schema_1.AUTH_SCHEMA}"."invalidated_tokens" (
|
|
13
|
+
token_id varchar(128) PRIMARY KEY,
|
|
14
|
+
user_id uuid NULL,
|
|
15
|
+
expires_at timestamptz NOT NULL,
|
|
16
|
+
invalidated_at timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
17
|
+
);
|
|
18
|
+
`);
|
|
19
|
+
await queryRunner.query(`
|
|
20
|
+
CREATE INDEX IF NOT EXISTS invalidated_tokens_expires_at_idx
|
|
21
|
+
ON "${schema_1.AUTH_SCHEMA}"."invalidated_tokens" (expires_at);
|
|
22
|
+
`);
|
|
23
|
+
}
|
|
24
|
+
async down(queryRunner) {
|
|
25
|
+
await queryRunner.query(`DROP TABLE IF EXISTS "${schema_1.AUTH_SCHEMA}"."invalidated_tokens";`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.CreateInvalidatedTokensCacheTable1720200000000 = CreateInvalidatedTokensCacheTable1720200000000;
|
|
29
|
+
//# sourceMappingURL=1720200000000-create-invalidated-tokens-cache.table.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"1720200000000-create-invalidated-tokens-cache.table.js","sourceRoot":"","sources":["../../../../../../../libs/auth/nest/src/infrastructure-persistence/migrations/1720200000000-create-invalidated-tokens-cache.table.ts"],"names":[],"mappings":";;;AACA,sCAAwC;AAExC,MAAa,8CAA8C;IAA3D;QAGE,SAAI,GAAG,gDAAgD,CAAC;IAyB1D,CAAC;IAvBQ,KAAK,CAAC,EAAE,CAAC,WAAwB;QACtC,MAAM,WAAW,CAAC,KAAK,CAAC,gCAAgC,oBAAW,IAAI,CAAC,CAAC;QAEzE,MAAM,WAAW,CAAC,KAAK,CAAC;6CACiB,oBAAW;;;;;;KAMnD,CAAC,CAAC;QAEH,MAAM,WAAW,CAAC,KAAK,CAAC;;cAEd,oBAAW;KACpB,CAAC,CAAC;IACL,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,WAAwB;QACxC,MAAM,WAAW,CAAC,KAAK,CACrB,yBAAyB,oBAAW,yBAAyB,CAC9D,CAAC;IACJ,CAAC;CACF;AA5BD,wGA4BC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const ConfigurableModuleClass: import("@nestjs/common").ConfigurableModuleCls<{
|
|
2
|
+
persistence: string;
|
|
3
|
+
}, "forRoot", "create", {
|
|
4
|
+
isGlobal?: boolean;
|
|
5
|
+
}>, AUTH_PERSISTENCE_MODULE_OPTIONS: string | symbol, OPTIONS_TYPE: {
|
|
6
|
+
persistence: string;
|
|
7
|
+
} & Partial<{
|
|
8
|
+
isGlobal?: boolean;
|
|
9
|
+
}>, ASYNC_OPTIONS_TYPE: import("@nestjs/common").ConfigurableModuleAsyncOptions<{
|
|
10
|
+
persistence: string;
|
|
11
|
+
}, "create"> & Partial<{
|
|
12
|
+
isGlobal?: boolean;
|
|
13
|
+
}>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.ASYNC_OPTIONS_TYPE = exports.OPTIONS_TYPE = exports.AUTH_PERSISTENCE_MODULE_OPTIONS = exports.ConfigurableModuleClass = void 0;
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
_a = new common_1.ConfigurableModuleBuilder()
|
|
7
|
+
.setClassMethodName('forRoot')
|
|
8
|
+
.setExtras({ isGlobal: true }, (definition, extras) => ({
|
|
9
|
+
...definition,
|
|
10
|
+
global: extras.isGlobal ?? false,
|
|
11
|
+
}))
|
|
12
|
+
.build(), exports.ConfigurableModuleClass = _a.ConfigurableModuleClass, exports.AUTH_PERSISTENCE_MODULE_OPTIONS = _a.MODULE_OPTIONS_TOKEN, exports.OPTIONS_TYPE = _a.OPTIONS_TYPE, exports.ASYNC_OPTIONS_TYPE = _a.ASYNC_OPTIONS_TYPE;
|
|
13
|
+
//# sourceMappingURL=persistence.module-definition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"persistence.module-definition.js","sourceRoot":"","sources":["../../../../../../libs/auth/nest/src/infrastructure-persistence/persistence.module-definition.ts"],"names":[],"mappings":";;;;AAAA,2CAA2D;AAE9C,KAKT,IAAI,kCAAyB,EAA2B;KACzD,kBAAkB,CAAC,SAAS,CAAC;KAC7B,SAAS,CACR,EAAE,QAAQ,EAAE,IAAI,EAAE,EAClB,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;IACvB,GAAG,UAAU;IACb,MAAM,EAAE,MAAM,CAAC,QAAQ,IAAI,KAAK;CACjC,CAAC,CACH;KACA,KAAK,EAAE,EAbR,+BAAuB,+BACD,uCAA+B,4BACrD,oBAAY,oBACZ,0BAAkB,yBAUT"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { ConfigurableModuleClass, OPTIONS_TYPE } from './persistence.module-definition';
|
|
3
|
+
export declare class PersistenceModule extends ConfigurableModuleClass {
|
|
4
|
+
private options;
|
|
5
|
+
constructor(options: string | symbol);
|
|
6
|
+
static forRoot(options: typeof OPTIONS_TYPE): DynamicModule;
|
|
7
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PersistenceModule = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const auth_user_repository_1 = require("./repositories/auth-user.repository");
|
|
7
|
+
const typeorm_auth_user_repository_1 = require("./repositories/typeorm-auth-user.repository");
|
|
8
|
+
const persistence_module_definition_1 = require("./persistence.module-definition");
|
|
9
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
10
|
+
const user_entity_1 = require("./entities/user.entity");
|
|
11
|
+
const role_entity_1 = require("./entities/role.entity");
|
|
12
|
+
const permission_entity_1 = require("./entities/permission.entity");
|
|
13
|
+
const invalidated_token_entity_1 = require("./entities/invalidated-token.entity");
|
|
14
|
+
let PersistenceModule = class PersistenceModule extends persistence_module_definition_1.ConfigurableModuleClass {
|
|
15
|
+
constructor(options) {
|
|
16
|
+
super();
|
|
17
|
+
this.options = options;
|
|
18
|
+
}
|
|
19
|
+
static forRoot(options) {
|
|
20
|
+
switch (options.persistence) {
|
|
21
|
+
case 'typeorm':
|
|
22
|
+
return {
|
|
23
|
+
...super.forRoot(options),
|
|
24
|
+
imports: [
|
|
25
|
+
typeorm_1.TypeOrmModule.forFeature([
|
|
26
|
+
user_entity_1.UserEntity,
|
|
27
|
+
role_entity_1.RoleEntity,
|
|
28
|
+
permission_entity_1.PermissionEntity,
|
|
29
|
+
invalidated_token_entity_1.InvalidatedTokenEntity,
|
|
30
|
+
]),
|
|
31
|
+
],
|
|
32
|
+
providers: [
|
|
33
|
+
typeorm_auth_user_repository_1.TypeormAuthUserRepository,
|
|
34
|
+
{
|
|
35
|
+
provide: auth_user_repository_1.AuthUserRepository,
|
|
36
|
+
useExisting: typeorm_auth_user_repository_1.TypeormAuthUserRepository,
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
exports: [auth_user_repository_1.AuthUserRepository, typeorm_1.TypeOrmModule],
|
|
40
|
+
};
|
|
41
|
+
default:
|
|
42
|
+
throw new Error(`Unsupported persistence type: ${options.persistence}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
exports.PersistenceModule = PersistenceModule;
|
|
47
|
+
exports.PersistenceModule = PersistenceModule = tslib_1.__decorate([
|
|
48
|
+
(0, common_1.Module)({}),
|
|
49
|
+
tslib_1.__param(0, (0, common_1.Inject)(persistence_module_definition_1.AUTH_PERSISTENCE_MODULE_OPTIONS)),
|
|
50
|
+
tslib_1.__metadata("design:paramtypes", [Object])
|
|
51
|
+
], PersistenceModule);
|
|
52
|
+
//# sourceMappingURL=persistence.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"persistence.module.js","sourceRoot":"","sources":["../../../../../../libs/auth/nest/src/infrastructure-persistence/persistence.module.ts"],"names":[],"mappings":";;;;AAAA,2CAA+D;AAC/D,8EAAyE;AACzE,8FAAwF;AACxF,mFAIyC;AACzC,6CAAgD;AAChD,wDAAoD;AACpD,wDAAoD;AACpD,oEAAgE;AAChE,kFAA6E;AAGtE,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,uDAAuB;IAC5D,YACmD,OAAwB;QAEzE,KAAK,EAAE,CAAC;QAFyC,YAAO,GAAP,OAAO,CAAiB;IAG3E,CAAC;IAED,MAAM,CAAC,OAAO,CAAC,OAA4B;QACzC,QAAQ,OAAO,CAAC,WAAW,EAAE,CAAC;YAC5B,KAAK,SAAS;gBACZ,OAAO;oBACL,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;oBACzB,OAAO,EAAE;wBACP,uBAAa,CAAC,UAAU,CAAC;4BACvB,wBAAU;4BACV,wBAAU;4BACV,oCAAgB;4BAChB,iDAAsB;yBACvB,CAAC;qBACH;oBACD,SAAS,EAAE;wBACT,wDAAyB;wBACzB;4BACE,OAAO,EAAE,yCAAkB;4BAC3B,WAAW,EAAE,wDAAyB;yBACvC;qBACF;oBACD,OAAO,EAAE,CAAC,yCAAkB,EAAE,uBAAa,CAAC;iBAC7C,CAAC;YACJ;gBACE,MAAM,IAAI,KAAK,CAAC,iCAAiC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;QAC5E,CAAC;IACH,CAAC;CACF,CAAA;AAjCY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,eAAM,EAAC,EAAE,CAAC;IAGN,mBAAA,IAAA,eAAM,EAAC,+DAA+B,CAAC,CAAA;;GAF/B,iBAAiB,CAiC7B"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { User } from '@anarchitects/auth-ts/models';
|
|
2
|
+
export declare abstract class AuthUserRepository {
|
|
3
|
+
abstract find(conditions: unknown): Promise<User[]>;
|
|
4
|
+
abstract findOne(conditions: unknown): Promise<User>;
|
|
5
|
+
abstract create(user: Partial<User>): Promise<User>;
|
|
6
|
+
abstract update(user: Partial<User>): Promise<User>;
|
|
7
|
+
abstract delete(userId: string): Promise<User>;
|
|
8
|
+
abstract invalidateTokens(tokens: string[], userId: string | null): Promise<void>;
|
|
9
|
+
abstract isTokenInvalidated(tokenId: string): Promise<boolean>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthUserRepository = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
let AuthUserRepository = class AuthUserRepository {
|
|
7
|
+
};
|
|
8
|
+
exports.AuthUserRepository = AuthUserRepository;
|
|
9
|
+
exports.AuthUserRepository = AuthUserRepository = tslib_1.__decorate([
|
|
10
|
+
(0, common_1.Injectable)()
|
|
11
|
+
], AuthUserRepository);
|
|
12
|
+
//# sourceMappingURL=auth-user.repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-user.repository.js","sourceRoot":"","sources":["../../../../../../../libs/auth/nest/src/infrastructure-persistence/repositories/auth-user.repository.ts"],"names":[],"mappings":";;;;AAAA,2CAA4C;AAIrC,IAAe,kBAAkB,GAAjC,MAAe,kBAAkB;CAWvC,CAAA;AAXqB,gDAAkB;6BAAlB,kBAAkB;IADvC,IAAA,mBAAU,GAAE;GACS,kBAAkB,CAWvC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { FindManyOptions, FindOneOptions, Repository } from 'typeorm';
|
|
2
|
+
import { UserEntity } from '../entities/user.entity';
|
|
3
|
+
import { AuthUserRepository } from './auth-user.repository';
|
|
4
|
+
import { User } from '@anarchitects/auth-ts/models';
|
|
5
|
+
import { InvalidatedTokenEntity } from '../entities/invalidated-token.entity';
|
|
6
|
+
export declare class TypeormAuthUserRepository implements AuthUserRepository {
|
|
7
|
+
private readonly userRepository;
|
|
8
|
+
private readonly invalidatedTokenRepository;
|
|
9
|
+
constructor(userRepository: Repository<UserEntity>, invalidatedTokenRepository: Repository<InvalidatedTokenEntity>);
|
|
10
|
+
find(conditions?: FindManyOptions<User>): Promise<User[]>;
|
|
11
|
+
findOne(conditions: FindOneOptions<User>): Promise<UserEntity>;
|
|
12
|
+
create(user: Partial<User>): Promise<User>;
|
|
13
|
+
update(user: Partial<User>): Promise<User>;
|
|
14
|
+
delete(userId: string): Promise<UserEntity>;
|
|
15
|
+
invalidateTokens(tokens: string[], userId: string | null): Promise<void>;
|
|
16
|
+
isTokenInvalidated(tokenId: string): Promise<boolean>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypeormAuthUserRepository = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
7
|
+
const typeorm_2 = require("typeorm");
|
|
8
|
+
const user_entity_1 = require("../entities/user.entity");
|
|
9
|
+
const invalidated_token_entity_1 = require("../entities/invalidated-token.entity");
|
|
10
|
+
let TypeormAuthUserRepository = class TypeormAuthUserRepository {
|
|
11
|
+
constructor(userRepository, invalidatedTokenRepository) {
|
|
12
|
+
this.userRepository = userRepository;
|
|
13
|
+
this.invalidatedTokenRepository = invalidatedTokenRepository;
|
|
14
|
+
}
|
|
15
|
+
async find(conditions = {}) {
|
|
16
|
+
return this.userRepository.find(conditions);
|
|
17
|
+
}
|
|
18
|
+
async findOne(conditions) {
|
|
19
|
+
const user = await this.userRepository.findOne(conditions);
|
|
20
|
+
if (!user) {
|
|
21
|
+
throw new common_1.NotFoundException(`User with conditions #${JSON.stringify(conditions)} not found`);
|
|
22
|
+
}
|
|
23
|
+
return user;
|
|
24
|
+
}
|
|
25
|
+
async create(user) {
|
|
26
|
+
const newUser = this.userRepository.create(user);
|
|
27
|
+
return this.userRepository.save(newUser);
|
|
28
|
+
}
|
|
29
|
+
async update(user) {
|
|
30
|
+
const updatedUser = await this.userRepository.preload(user);
|
|
31
|
+
if (!updatedUser) {
|
|
32
|
+
throw new common_1.NotFoundException(`User with id #${user.id} not found`);
|
|
33
|
+
}
|
|
34
|
+
return this.userRepository.save(updatedUser);
|
|
35
|
+
}
|
|
36
|
+
async delete(userId) {
|
|
37
|
+
const user = await this.findOne({ where: { id: userId } });
|
|
38
|
+
return this.userRepository.remove(user);
|
|
39
|
+
}
|
|
40
|
+
async invalidateTokens(tokens, userId) {
|
|
41
|
+
const invalidatedTokens = tokens.map((token) => this.invalidatedTokenRepository.create({
|
|
42
|
+
tokenId: token,
|
|
43
|
+
userId,
|
|
44
|
+
}));
|
|
45
|
+
await this.invalidatedTokenRepository.save(invalidatedTokens);
|
|
46
|
+
}
|
|
47
|
+
async isTokenInvalidated(tokenId) {
|
|
48
|
+
const token = await this.invalidatedTokenRepository.findOne({
|
|
49
|
+
where: { tokenId },
|
|
50
|
+
});
|
|
51
|
+
return !!token;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
exports.TypeormAuthUserRepository = TypeormAuthUserRepository;
|
|
55
|
+
exports.TypeormAuthUserRepository = TypeormAuthUserRepository = tslib_1.__decorate([
|
|
56
|
+
(0, common_1.Injectable)(),
|
|
57
|
+
tslib_1.__param(0, (0, typeorm_1.InjectRepository)(user_entity_1.UserEntity)),
|
|
58
|
+
tslib_1.__param(1, (0, typeorm_1.InjectRepository)(invalidated_token_entity_1.InvalidatedTokenEntity)),
|
|
59
|
+
tslib_1.__metadata("design:paramtypes", [typeorm_2.Repository,
|
|
60
|
+
typeorm_2.Repository])
|
|
61
|
+
], TypeormAuthUserRepository);
|
|
62
|
+
//# sourceMappingURL=typeorm-auth-user.repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typeorm-auth-user.repository.js","sourceRoot":"","sources":["../../../../../../../libs/auth/nest/src/infrastructure-persistence/repositories/typeorm-auth-user.repository.ts"],"names":[],"mappings":";;;;AAAA,2CAA+D;AAC/D,6CAAmD;AACnD,qCAAsE;AACtE,yDAAqD;AAGrD,mFAA8E;AAGvE,IAAM,yBAAyB,GAA/B,MAAM,yBAAyB;IACpC,YAEmB,cAAsC,EAEtC,0BAA8D;QAF9D,mBAAc,GAAd,cAAc,CAAwB;QAEtC,+BAA0B,GAA1B,0BAA0B,CAAoC;IAC9E,CAAC;IACJ,KAAK,CAAC,IAAI,CAAC,aAAoC,EAAE;QAC/C,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC9C,CAAC;IACD,KAAK,CAAC,OAAO,CAAC,UAAgC;QAC5C,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAC3D,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,0BAAiB,CACzB,yBAAyB,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,YAAY,CAChE,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,KAAK,CAAC,MAAM,CAAC,IAAmB;QAC9B,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACjD,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC3C,CAAC;IACD,KAAK,CAAC,MAAM,CAAC,IAAmB;QAC9B,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC5D,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,IAAI,0BAAiB,CAAC,iBAAiB,IAAI,CAAC,EAAE,YAAY,CAAC,CAAC;QACpE,CAAC;QACD,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC/C,CAAC;IACD,KAAK,CAAC,MAAM,CAAC,MAAc;QACzB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;QAC3D,OAAO,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;IAED,KAAK,CAAC,gBAAgB,CACpB,MAAgB,EAChB,MAAqB;QAErB,MAAM,iBAAiB,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAC7C,IAAI,CAAC,0BAA0B,CAAC,MAAM,CAAC;YACrC,OAAO,EAAE,KAAK;YACd,MAAM;SACP,CAAC,CACH,CAAC;QACF,MAAM,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;IAChE,CAAC;IAED,KAAK,CAAC,kBAAkB,CAAC,OAAe;QACtC,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,0BAA0B,CAAC,OAAO,CAAC;YAC1D,KAAK,EAAE,EAAE,OAAO,EAAE;SACnB,CAAC,CAAC;QACH,OAAO,CAAC,CAAC,KAAK,CAAC;IACjB,CAAC;CACF,CAAA;AAtDY,8DAAyB;oCAAzB,yBAAyB;IADrC,IAAA,mBAAU,GAAE;IAGR,mBAAA,IAAA,0BAAgB,EAAC,wBAAU,CAAC,CAAA;IAE5B,mBAAA,IAAA,0BAAgB,EAAC,iDAAsB,CAAC,CAAA;6CADR,oBAAU;QAEE,oBAAU;GAL9C,yBAAyB,CAsDrC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const AUTH_SCHEMA = "auth";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../../../libs/auth/nest/src/infrastructure-persistence/schema.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAG,MAAM,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ActivateUserRequestDTO, ChangePasswordRequestDTO, ForgotPasswordRequestDTO, LoginRequestDTO, LoginResponseDTO, LogoutRequestDTO, RefreshTokenRequestDTO, RegisterRequestDTO, RegisterResponseDTO, ResetPasswordRequestDTO, UpdateEmailRequestDTO, VerifyEmailRequestDTO } from '@anarchitects/auth-ts/dtos';
|
|
2
|
+
import { PolicyRule, User } from '@anarchitects/auth-ts/models';
|
|
3
|
+
import { AuthService } from '../../application/services/auth.service';
|
|
4
|
+
export declare class AuthController {
|
|
5
|
+
private readonly authService;
|
|
6
|
+
constructor(authService: AuthService);
|
|
7
|
+
registerUser(dto: RegisterRequestDTO): Promise<RegisterResponseDTO>;
|
|
8
|
+
activateUser(dto: ActivateUserRequestDTO): Promise<{
|
|
9
|
+
success: boolean;
|
|
10
|
+
}>;
|
|
11
|
+
login(dto: LoginRequestDTO): Promise<LoginResponseDTO>;
|
|
12
|
+
logout(dto: LogoutRequestDTO): Promise<{
|
|
13
|
+
success: boolean;
|
|
14
|
+
}>;
|
|
15
|
+
changePassword(userId: string, dto: ChangePasswordRequestDTO): Promise<{
|
|
16
|
+
success: boolean;
|
|
17
|
+
}>;
|
|
18
|
+
forgotPassword(dto: ForgotPasswordRequestDTO): Promise<{
|
|
19
|
+
success: boolean;
|
|
20
|
+
}>;
|
|
21
|
+
resetPassword(dto: ResetPasswordRequestDTO): Promise<{
|
|
22
|
+
success: boolean;
|
|
23
|
+
}>;
|
|
24
|
+
verifyEmail(dto: VerifyEmailRequestDTO): Promise<{
|
|
25
|
+
success: boolean;
|
|
26
|
+
}>;
|
|
27
|
+
updateEmail(userId: string, dto: UpdateEmailRequestDTO): Promise<{
|
|
28
|
+
success: boolean;
|
|
29
|
+
}>;
|
|
30
|
+
refreshTokens(userId: string, dto: RefreshTokenRequestDTO): Promise<LoginResponseDTO>;
|
|
31
|
+
getLoggedInUserInfo(req: {
|
|
32
|
+
user: {
|
|
33
|
+
sub: string;
|
|
34
|
+
};
|
|
35
|
+
}): Promise<{
|
|
36
|
+
user: User;
|
|
37
|
+
rbac: PolicyRule[];
|
|
38
|
+
}>;
|
|
39
|
+
}
|