@application-kit/audit-log 0.0.0-stage → 0.1.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/CHANGELOG.md +31 -0
- package/LICENSE +21 -0
- package/README.md +52 -2
- package/dist/cjs/audit-log.wire.d.ts +10 -0
- package/dist/cjs/audit-log.wire.js +2 -0
- package/dist/cjs/constants.d.ts +8 -0
- package/dist/cjs/constants.js +4 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +18 -0
- package/dist/cjs/nest/application/index.d.ts +2 -0
- package/dist/cjs/nest/application/index.js +18 -0
- package/dist/cjs/nest/application/ports/audit-log-read.interface.d.ts +3 -0
- package/dist/cjs/nest/application/ports/audit-log-read.interface.js +2 -0
- package/dist/cjs/nest/application/ports/audit-log-write.interface.d.ts +4 -0
- package/dist/cjs/nest/application/ports/audit-log-write.interface.js +2 -0
- package/dist/cjs/nest/application/ports/index.d.ts +2 -0
- package/dist/cjs/nest/application/ports/index.js +18 -0
- package/dist/cjs/nest/application/queries/dtos/audit-record.dto.d.ts +21 -0
- package/dist/cjs/nest/application/queries/dtos/audit-record.dto.js +24 -0
- package/dist/cjs/nest/application/queries/dtos/index.d.ts +1 -0
- package/dist/cjs/nest/application/queries/dtos/index.js +17 -0
- package/dist/cjs/nest/application/queries/get-audit-records.query.d.ts +6 -0
- package/dist/cjs/nest/application/queries/get-audit-records.query.js +7 -0
- package/dist/cjs/nest/application/queries/handlers/get-audit-records.handler.d.ts +9 -0
- package/dist/cjs/nest/application/queries/handlers/get-audit-records.handler.js +35 -0
- package/dist/cjs/nest/application/queries/handlers/index.d.ts +1 -0
- package/dist/cjs/nest/application/queries/handlers/index.js +17 -0
- package/dist/cjs/nest/application/queries/index.d.ts +3 -0
- package/dist/cjs/nest/application/queries/index.js +19 -0
- package/dist/cjs/nest/audit-log-consumers.module.d.ts +2 -0
- package/dist/cjs/nest/audit-log-consumers.module.js +22 -0
- package/dist/cjs/nest/audit-log-request-facts.module.d.ts +2 -0
- package/dist/cjs/nest/audit-log-request-facts.module.js +22 -0
- package/dist/cjs/nest/audit-log-web.module.d.ts +8 -0
- package/dist/cjs/nest/audit-log-web.module.js +39 -0
- package/dist/cjs/nest/audit-log.module.d.ts +2 -0
- package/dist/cjs/nest/audit-log.module.js +37 -0
- package/dist/cjs/nest/constants.d.ts +3 -0
- package/dist/cjs/nest/constants.js +6 -0
- package/dist/cjs/nest/domain/audit-record.d.ts +15 -0
- package/dist/cjs/nest/domain/audit-record.js +15 -0
- package/dist/cjs/nest/domain/index.d.ts +1 -0
- package/dist/cjs/nest/domain/index.js +17 -0
- package/dist/cjs/nest/index.d.ts +11 -0
- package/dist/cjs/nest/index.js +27 -0
- package/dist/cjs/nest/infrastructure/database/index.d.ts +1 -0
- package/dist/cjs/nest/infrastructure/database/index.js +17 -0
- package/dist/cjs/nest/infrastructure/database/typeorm/entities/audit-record.entity.d.ts +11 -0
- package/dist/cjs/nest/infrastructure/database/typeorm/entities/audit-record.entity.js +69 -0
- package/dist/cjs/nest/infrastructure/database/typeorm/entities/index.d.ts +1 -0
- package/dist/cjs/nest/infrastructure/database/typeorm/entities/index.js +17 -0
- package/dist/cjs/nest/infrastructure/database/typeorm/index.d.ts +5 -0
- package/dist/cjs/nest/infrastructure/database/typeorm/index.js +21 -0
- package/dist/cjs/nest/infrastructure/database/typeorm/mappers/audit-record.mapper.d.ts +10 -0
- package/dist/cjs/nest/infrastructure/database/typeorm/mappers/audit-record.mapper.js +35 -0
- package/dist/cjs/nest/infrastructure/database/typeorm/mappers/index.d.ts +1 -0
- package/dist/cjs/nest/infrastructure/database/typeorm/mappers/index.js +17 -0
- package/dist/cjs/nest/infrastructure/database/typeorm/migrations/audit-records-append-only.migration.d.ts +6 -0
- package/dist/cjs/nest/infrastructure/database/typeorm/migrations/audit-records-append-only.migration.js +28 -0
- package/dist/cjs/nest/infrastructure/database/typeorm/migrations/index.d.ts +1 -0
- package/dist/cjs/nest/infrastructure/database/typeorm/migrations/index.js +17 -0
- package/dist/cjs/nest/infrastructure/database/typeorm/orm.d.ts +6 -0
- package/dist/cjs/nest/infrastructure/database/typeorm/orm.js +9 -0
- package/dist/cjs/nest/infrastructure/database/typeorm/repositories/audit-record.repository.d.ts +14 -0
- package/dist/cjs/nest/infrastructure/database/typeorm/repositories/audit-record.repository.js +47 -0
- package/dist/cjs/nest/infrastructure/database/typeorm/repositories/index.d.ts +1 -0
- package/dist/cjs/nest/infrastructure/database/typeorm/repositories/index.js +17 -0
- package/dist/cjs/nest/infrastructure/index.d.ts +1 -0
- package/dist/cjs/nest/infrastructure/index.js +17 -0
- package/dist/cjs/nest/libs/audit-request-context.d.ts +25 -0
- package/dist/cjs/nest/libs/audit-request-context.js +23 -0
- package/dist/cjs/nest/libs/index.d.ts +1 -0
- package/dist/cjs/nest/libs/index.js +17 -0
- package/dist/cjs/nest/policy-handlers.d.ts +2 -0
- package/dist/cjs/nest/policy-handlers.js +5 -0
- package/dist/cjs/nest/user-interface/consumers/audit-facts.dto.d.ts +6 -0
- package/dist/cjs/nest/user-interface/consumers/audit-facts.dto.js +40 -0
- package/dist/cjs/nest/user-interface/consumers/audited-fact.dto.d.ts +5 -0
- package/dist/cjs/nest/user-interface/consumers/audited-fact.dto.js +30 -0
- package/dist/cjs/nest/user-interface/consumers/index.d.ts +3 -0
- package/dist/cjs/nest/user-interface/consumers/index.js +19 -0
- package/dist/cjs/nest/user-interface/consumers/record-audit-fact.handler.d.ts +13 -0
- package/dist/cjs/nest/user-interface/consumers/record-audit-fact.handler.js +44 -0
- package/dist/cjs/nest/user-interface/controllers/graphql/audit-records/audit-record-item.type.d.ts +11 -0
- package/dist/cjs/nest/user-interface/controllers/graphql/audit-records/audit-record-item.type.js +59 -0
- package/dist/cjs/nest/user-interface/controllers/graphql/audit-records/audit-records.resolver.d.ts +8 -0
- package/dist/cjs/nest/user-interface/controllers/graphql/audit-records/audit-records.resolver.js +58 -0
- package/dist/cjs/nest/user-interface/controllers/graphql/audit-records/audit-records.type.d.ts +8 -0
- package/dist/cjs/nest/user-interface/controllers/graphql/audit-records/audit-records.type.js +36 -0
- package/dist/cjs/nest/user-interface/controllers/graphql/audit-records/index.d.ts +3 -0
- package/dist/cjs/nest/user-interface/controllers/graphql/audit-records/index.js +19 -0
- package/dist/cjs/nest/user-interface/controllers/graphql/index.d.ts +1 -0
- package/dist/cjs/nest/user-interface/controllers/graphql/index.js +17 -0
- package/dist/cjs/nest/user-interface/controllers/index.d.ts +1 -0
- package/dist/cjs/nest/user-interface/controllers/index.js +17 -0
- package/dist/cjs/nest/user-interface/index.d.ts +3 -0
- package/dist/cjs/nest/user-interface/index.js +19 -0
- package/dist/cjs/nest/user-interface/interceptors/audit-request-context.interceptor.d.ts +8 -0
- package/dist/cjs/nest/user-interface/interceptors/audit-request-context.interceptor.js +36 -0
- package/dist/cjs/nest/user-interface/interceptors/index.d.ts +1 -0
- package/dist/cjs/nest/user-interface/interceptors/index.js +17 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/testing/audit-log-read.fake.d.ts +14 -0
- package/dist/cjs/testing/audit-log-read.fake.js +16 -0
- package/dist/cjs/testing/audit-log-write.fake.d.ts +8 -0
- package/dist/cjs/testing/audit-log-write.fake.js +18 -0
- package/dist/cjs/testing/index.d.ts +2 -0
- package/dist/cjs/testing/index.js +18 -0
- package/dist/esm/audit-log.wire.d.ts +10 -0
- package/dist/esm/audit-log.wire.js +1 -0
- package/dist/esm/constants.d.ts +8 -0
- package/dist/esm/constants.js +1 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/nest/application/index.d.ts +2 -0
- package/dist/esm/nest/application/index.js +2 -0
- package/dist/esm/nest/application/ports/audit-log-read.interface.d.ts +3 -0
- package/dist/esm/nest/application/ports/audit-log-read.interface.js +1 -0
- package/dist/esm/nest/application/ports/audit-log-write.interface.d.ts +4 -0
- package/dist/esm/nest/application/ports/audit-log-write.interface.js +1 -0
- package/dist/esm/nest/application/ports/index.d.ts +2 -0
- package/dist/esm/nest/application/ports/index.js +2 -0
- package/dist/esm/nest/application/queries/dtos/audit-record.dto.d.ts +21 -0
- package/dist/esm/nest/application/queries/dtos/audit-record.dto.js +20 -0
- package/dist/esm/nest/application/queries/dtos/index.d.ts +1 -0
- package/dist/esm/nest/application/queries/dtos/index.js +1 -0
- package/dist/esm/nest/application/queries/get-audit-records.query.d.ts +6 -0
- package/dist/esm/nest/application/queries/get-audit-records.query.js +3 -0
- package/dist/esm/nest/application/queries/handlers/get-audit-records.handler.d.ts +9 -0
- package/dist/esm/nest/application/queries/handlers/get-audit-records.handler.js +32 -0
- package/dist/esm/nest/application/queries/handlers/index.d.ts +1 -0
- package/dist/esm/nest/application/queries/handlers/index.js +1 -0
- package/dist/esm/nest/application/queries/index.d.ts +3 -0
- package/dist/esm/nest/application/queries/index.js +3 -0
- package/dist/esm/nest/audit-log-consumers.module.d.ts +2 -0
- package/dist/esm/nest/audit-log-consumers.module.js +19 -0
- package/dist/esm/nest/audit-log-request-facts.module.d.ts +2 -0
- package/dist/esm/nest/audit-log-request-facts.module.js +19 -0
- package/dist/esm/nest/audit-log-web.module.d.ts +8 -0
- package/dist/esm/nest/audit-log-web.module.js +36 -0
- package/dist/esm/nest/audit-log.module.d.ts +2 -0
- package/dist/esm/nest/audit-log.module.js +34 -0
- package/dist/esm/nest/constants.d.ts +3 -0
- package/dist/esm/nest/constants.js +3 -0
- package/dist/esm/nest/domain/audit-record.d.ts +15 -0
- package/dist/esm/nest/domain/audit-record.js +11 -0
- package/dist/esm/nest/domain/index.d.ts +1 -0
- package/dist/esm/nest/domain/index.js +1 -0
- package/dist/esm/nest/index.d.ts +11 -0
- package/dist/esm/nest/index.js +11 -0
- package/dist/esm/nest/infrastructure/database/index.d.ts +1 -0
- package/dist/esm/nest/infrastructure/database/index.js +1 -0
- package/dist/esm/nest/infrastructure/database/typeorm/entities/audit-record.entity.d.ts +11 -0
- package/dist/esm/nest/infrastructure/database/typeorm/entities/audit-record.entity.js +66 -0
- package/dist/esm/nest/infrastructure/database/typeorm/entities/index.d.ts +1 -0
- package/dist/esm/nest/infrastructure/database/typeorm/entities/index.js +1 -0
- package/dist/esm/nest/infrastructure/database/typeorm/index.d.ts +5 -0
- package/dist/esm/nest/infrastructure/database/typeorm/index.js +5 -0
- package/dist/esm/nest/infrastructure/database/typeorm/mappers/audit-record.mapper.d.ts +10 -0
- package/dist/esm/nest/infrastructure/database/typeorm/mappers/audit-record.mapper.js +31 -0
- package/dist/esm/nest/infrastructure/database/typeorm/mappers/index.d.ts +1 -0
- package/dist/esm/nest/infrastructure/database/typeorm/mappers/index.js +1 -0
- package/dist/esm/nest/infrastructure/database/typeorm/migrations/audit-records-append-only.migration.d.ts +6 -0
- package/dist/esm/nest/infrastructure/database/typeorm/migrations/audit-records-append-only.migration.js +24 -0
- package/dist/esm/nest/infrastructure/database/typeorm/migrations/index.d.ts +1 -0
- package/dist/esm/nest/infrastructure/database/typeorm/migrations/index.js +1 -0
- package/dist/esm/nest/infrastructure/database/typeorm/orm.d.ts +6 -0
- package/dist/esm/nest/infrastructure/database/typeorm/orm.js +6 -0
- package/dist/esm/nest/infrastructure/database/typeorm/repositories/audit-record.repository.d.ts +14 -0
- package/dist/esm/nest/infrastructure/database/typeorm/repositories/audit-record.repository.js +44 -0
- package/dist/esm/nest/infrastructure/database/typeorm/repositories/index.d.ts +1 -0
- package/dist/esm/nest/infrastructure/database/typeorm/repositories/index.js +1 -0
- package/dist/esm/nest/infrastructure/index.d.ts +1 -0
- package/dist/esm/nest/infrastructure/index.js +1 -0
- package/dist/esm/nest/libs/audit-request-context.d.ts +25 -0
- package/dist/esm/nest/libs/audit-request-context.js +18 -0
- package/dist/esm/nest/libs/index.d.ts +1 -0
- package/dist/esm/nest/libs/index.js +1 -0
- package/dist/esm/nest/policy-handlers.d.ts +2 -0
- package/dist/esm/nest/policy-handlers.js +1 -0
- package/dist/esm/nest/user-interface/consumers/audit-facts.dto.d.ts +6 -0
- package/dist/esm/nest/user-interface/consumers/audit-facts.dto.js +36 -0
- package/dist/esm/nest/user-interface/consumers/audited-fact.dto.d.ts +5 -0
- package/dist/esm/nest/user-interface/consumers/audited-fact.dto.js +26 -0
- package/dist/esm/nest/user-interface/consumers/index.d.ts +3 -0
- package/dist/esm/nest/user-interface/consumers/index.js +3 -0
- package/dist/esm/nest/user-interface/consumers/record-audit-fact.handler.d.ts +13 -0
- package/dist/esm/nest/user-interface/consumers/record-audit-fact.handler.js +41 -0
- package/dist/esm/nest/user-interface/controllers/graphql/audit-records/audit-record-item.type.d.ts +11 -0
- package/dist/esm/nest/user-interface/controllers/graphql/audit-records/audit-record-item.type.js +56 -0
- package/dist/esm/nest/user-interface/controllers/graphql/audit-records/audit-records.resolver.d.ts +8 -0
- package/dist/esm/nest/user-interface/controllers/graphql/audit-records/audit-records.resolver.js +55 -0
- package/dist/esm/nest/user-interface/controllers/graphql/audit-records/audit-records.type.d.ts +8 -0
- package/dist/esm/nest/user-interface/controllers/graphql/audit-records/audit-records.type.js +33 -0
- package/dist/esm/nest/user-interface/controllers/graphql/audit-records/index.d.ts +3 -0
- package/dist/esm/nest/user-interface/controllers/graphql/audit-records/index.js +3 -0
- package/dist/esm/nest/user-interface/controllers/graphql/index.d.ts +1 -0
- package/dist/esm/nest/user-interface/controllers/graphql/index.js +1 -0
- package/dist/esm/nest/user-interface/controllers/index.d.ts +1 -0
- package/dist/esm/nest/user-interface/controllers/index.js +1 -0
- package/dist/esm/nest/user-interface/index.d.ts +3 -0
- package/dist/esm/nest/user-interface/index.js +3 -0
- package/dist/esm/nest/user-interface/interceptors/audit-request-context.interceptor.d.ts +8 -0
- package/dist/esm/nest/user-interface/interceptors/audit-request-context.interceptor.js +33 -0
- package/dist/esm/nest/user-interface/interceptors/index.d.ts +1 -0
- package/dist/esm/nest/user-interface/interceptors/index.js +1 -0
- package/dist/esm/testing/audit-log-read.fake.d.ts +14 -0
- package/dist/esm/testing/audit-log-read.fake.js +12 -0
- package/dist/esm/testing/audit-log-write.fake.d.ts +8 -0
- package/dist/esm/testing/audit-log-write.fake.js +14 -0
- package/dist/esm/testing/index.d.ts +2 -0
- package/dist/esm/testing/index.js +2 -0
- package/package.json +125 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './audit-record.dto.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './audit-record.dto.js';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ListingQueryResultInterface } from '@application-kit/typeorm/nest';
|
|
2
|
+
import { ListingQuery } from '@application-kit/typeorm/nest';
|
|
3
|
+
import type { AuditRecordDto } from './dtos/audit-record.dto.js';
|
|
4
|
+
export type GetAuditRecordsQueryResult = ListingQueryResultInterface<AuditRecordDto>;
|
|
5
|
+
export declare class GetAuditRecordsQuery extends ListingQuery {
|
|
6
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IQueryHandler } from '@nestjs/cqrs';
|
|
2
|
+
import { ListingHandler } from '@application-kit/typeorm/nest';
|
|
3
|
+
import type { AuditLogReadInterface } from '../../ports/audit-log-read.interface.js';
|
|
4
|
+
import { AuditRecordDto } from '../dtos/audit-record.dto.js';
|
|
5
|
+
import { GetAuditRecordsQuery, GetAuditRecordsQueryResult } from '../get-audit-records.query.js';
|
|
6
|
+
export declare class GetAuditRecordsHandler extends ListingHandler<AuditRecordDto> implements IQueryHandler<GetAuditRecordsQuery, GetAuditRecordsQueryResult> {
|
|
7
|
+
constructor(auditLogRepository: AuditLogReadInterface);
|
|
8
|
+
execute(query: GetAuditRecordsQuery): Promise<GetAuditRecordsQueryResult>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
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;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
import { ListingHandler } from '@application-kit/typeorm/nest';
|
|
14
|
+
import { Inject } from '@nestjs/common';
|
|
15
|
+
import { QueryHandler } from '@nestjs/cqrs';
|
|
16
|
+
import { AUDIT_LOG_READ_PORT } from '../../../constants.js';
|
|
17
|
+
import { GetAuditRecordsQuery, } from '../get-audit-records.query.js';
|
|
18
|
+
const MAX_LIMIT = 200;
|
|
19
|
+
let GetAuditRecordsHandler = class GetAuditRecordsHandler extends ListingHandler {
|
|
20
|
+
constructor(auditLogRepository) {
|
|
21
|
+
super(auditLogRepository);
|
|
22
|
+
}
|
|
23
|
+
async execute(query) {
|
|
24
|
+
return super.execute(new GetAuditRecordsQuery({ ...query.paginator, limit: Math.min(query.paginator.limit, MAX_LIMIT) }, query.filters, query.sorting));
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
GetAuditRecordsHandler = __decorate([
|
|
28
|
+
QueryHandler(GetAuditRecordsQuery),
|
|
29
|
+
__param(0, Inject(AUDIT_LOG_READ_PORT)),
|
|
30
|
+
__metadata("design:paramtypes", [Object])
|
|
31
|
+
], GetAuditRecordsHandler);
|
|
32
|
+
export { GetAuditRecordsHandler };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './get-audit-records.handler.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './get-audit-records.handler.js';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
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;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { Module } from '@nestjs/common';
|
|
8
|
+
import { AuditLogModule } from './audit-log.module.js';
|
|
9
|
+
import { RecordAuditFactHandler } from './user-interface/consumers/record-audit-fact.handler.js';
|
|
10
|
+
let AuditLogConsumersModule = class AuditLogConsumersModule {
|
|
11
|
+
};
|
|
12
|
+
AuditLogConsumersModule = __decorate([
|
|
13
|
+
Module({
|
|
14
|
+
exports: [RecordAuditFactHandler],
|
|
15
|
+
imports: [AuditLogModule],
|
|
16
|
+
providers: [RecordAuditFactHandler],
|
|
17
|
+
})
|
|
18
|
+
], AuditLogConsumersModule);
|
|
19
|
+
export { AuditLogConsumersModule };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
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;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { TRANSACTION_OUTBOX_REQUEST_FACTS } from '@application-kit/transaction-outbox';
|
|
8
|
+
import { Global, Module } from '@nestjs/common';
|
|
9
|
+
import { auditRequestFacts } from './libs/audit-request-context.js';
|
|
10
|
+
let AuditLogRequestFactsModule = class AuditLogRequestFactsModule {
|
|
11
|
+
};
|
|
12
|
+
AuditLogRequestFactsModule = __decorate([
|
|
13
|
+
Global(),
|
|
14
|
+
Module({
|
|
15
|
+
exports: [TRANSACTION_OUTBOX_REQUEST_FACTS],
|
|
16
|
+
providers: [{ provide: TRANSACTION_OUTBOX_REQUEST_FACTS, useValue: auditRequestFacts }],
|
|
17
|
+
})
|
|
18
|
+
], AuditLogRequestFactsModule);
|
|
19
|
+
export { AuditLogRequestFactsModule };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import type { AuditRequestFactsResolver } from './libs/audit-request-context.js';
|
|
3
|
+
export interface AuditLogWebOptionsInterface {
|
|
4
|
+
resolveRequestFacts: AuditRequestFactsResolver;
|
|
5
|
+
}
|
|
6
|
+
export declare class AuditLogWebModule {
|
|
7
|
+
static forRoot(options: AuditLogWebOptionsInterface): DynamicModule;
|
|
8
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
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;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { Module } from '@nestjs/common';
|
|
8
|
+
import { APP_INTERCEPTOR } from '@nestjs/core';
|
|
9
|
+
import { CqrsModule } from '@nestjs/cqrs';
|
|
10
|
+
import { AuditLogModule } from './audit-log.module.js';
|
|
11
|
+
import { AUDIT_REQUEST_FACTS_RESOLVER } from './constants.js';
|
|
12
|
+
import { AuditRecordsResolver } from './user-interface/controllers/graphql/audit-records/audit-records.resolver.js';
|
|
13
|
+
import { AuditRequestContextInterceptor } from './user-interface/interceptors/audit-request-context.interceptor.js';
|
|
14
|
+
let AuditLogWebModule = class AuditLogWebModule {
|
|
15
|
+
static forRoot(options) {
|
|
16
|
+
return {
|
|
17
|
+
imports: [AuditLogModule, CqrsModule],
|
|
18
|
+
module: this,
|
|
19
|
+
providers: [
|
|
20
|
+
AuditRecordsResolver,
|
|
21
|
+
{
|
|
22
|
+
provide: APP_INTERCEPTOR,
|
|
23
|
+
useClass: AuditRequestContextInterceptor,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
provide: AUDIT_REQUEST_FACTS_RESOLVER,
|
|
27
|
+
useValue: options.resolveRequestFacts,
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
AuditLogWebModule = __decorate([
|
|
34
|
+
Module({})
|
|
35
|
+
], AuditLogWebModule);
|
|
36
|
+
export { AuditLogWebModule };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
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;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { Module } from '@nestjs/common';
|
|
8
|
+
import { CqrsModule } from '@nestjs/cqrs';
|
|
9
|
+
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
10
|
+
import { GetAuditRecordsHandler, } from './application/queries/handlers/get-audit-records.handler.js';
|
|
11
|
+
import { AuditLogRequestFactsModule } from './audit-log-request-facts.module.js';
|
|
12
|
+
import { AUDIT_LOG_READ_PORT, AUDIT_LOG_WRITE_PORT } from './constants.js';
|
|
13
|
+
import { AuditRecordEntity } from './infrastructure/database/typeorm/entities/audit-record.entity.js';
|
|
14
|
+
import { AuditRecordRepository, } from './infrastructure/database/typeorm/repositories/audit-record.repository.js';
|
|
15
|
+
let AuditLogModule = class AuditLogModule {
|
|
16
|
+
};
|
|
17
|
+
AuditLogModule = __decorate([
|
|
18
|
+
Module({
|
|
19
|
+
exports: [AUDIT_LOG_READ_PORT, AUDIT_LOG_WRITE_PORT],
|
|
20
|
+
imports: [AuditLogRequestFactsModule, CqrsModule, TypeOrmModule.forFeature([AuditRecordEntity])],
|
|
21
|
+
providers: [
|
|
22
|
+
GetAuditRecordsHandler,
|
|
23
|
+
{
|
|
24
|
+
provide: AUDIT_LOG_READ_PORT,
|
|
25
|
+
useClass: AuditRecordRepository,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
provide: AUDIT_LOG_WRITE_PORT,
|
|
29
|
+
useClass: AuditRecordRepository,
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
})
|
|
33
|
+
], AuditLogModule);
|
|
34
|
+
export { AuditLogModule };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AbstractEntity, Uuid } from '@libs-for-dev/nestjs-ddd-library';
|
|
2
|
+
export interface AuditRecordPropsInterface {
|
|
3
|
+
action: string;
|
|
4
|
+
actorId: null | string;
|
|
5
|
+
actorRole: null | string;
|
|
6
|
+
eventId: null | string;
|
|
7
|
+
ip: null | string;
|
|
8
|
+
subjectId: string;
|
|
9
|
+
userAgent: null | string;
|
|
10
|
+
}
|
|
11
|
+
export declare const AUDIT_IP_MAX_LENGTH = 64;
|
|
12
|
+
export declare const AUDIT_USER_AGENT_MAX_LENGTH = 512;
|
|
13
|
+
export declare class AuditRecord extends AbstractEntity<Uuid, AuditRecordPropsInterface> {
|
|
14
|
+
static create: (properties: AuditRecordPropsInterface) => AuditRecord;
|
|
15
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AbstractEntity, Uuid } from '@libs-for-dev/nestjs-ddd-library';
|
|
2
|
+
export const AUDIT_IP_MAX_LENGTH = 64;
|
|
3
|
+
export const AUDIT_USER_AGENT_MAX_LENGTH = 512;
|
|
4
|
+
const truncate = (value, maxLength) => (value === null ? null : value.slice(0, maxLength));
|
|
5
|
+
export class AuditRecord extends AbstractEntity {
|
|
6
|
+
static create = (properties) => new AuditRecord(Uuid.generate(), {
|
|
7
|
+
...properties,
|
|
8
|
+
ip: truncate(properties.ip, AUDIT_IP_MAX_LENGTH),
|
|
9
|
+
userAgent: truncate(properties.userAgent, AUDIT_USER_AGENT_MAX_LENGTH),
|
|
10
|
+
});
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './audit-record.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './audit-record.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './application/index.js';
|
|
2
|
+
export * from './domain/index.js';
|
|
3
|
+
export * from './infrastructure/index.js';
|
|
4
|
+
export * from './libs/index.js';
|
|
5
|
+
export * from './user-interface/index.js';
|
|
6
|
+
export * from './audit-log-consumers.module.js';
|
|
7
|
+
export * from './audit-log-request-facts.module.js';
|
|
8
|
+
export * from './audit-log-web.module.js';
|
|
9
|
+
export * from './audit-log.module.js';
|
|
10
|
+
export * from './constants.js';
|
|
11
|
+
export * from './policy-handlers.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './application/index.js';
|
|
2
|
+
export * from './domain/index.js';
|
|
3
|
+
export * from './infrastructure/index.js';
|
|
4
|
+
export * from './libs/index.js';
|
|
5
|
+
export * from './user-interface/index.js';
|
|
6
|
+
export * from './audit-log-consumers.module.js';
|
|
7
|
+
export * from './audit-log-request-facts.module.js';
|
|
8
|
+
export * from './audit-log-web.module.js';
|
|
9
|
+
export * from './audit-log.module.js';
|
|
10
|
+
export * from './constants.js';
|
|
11
|
+
export * from './policy-handlers.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './typeorm/index.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './typeorm/index.js';
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
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;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { Column, CreateDateColumn, Entity, Index, PrimaryGeneratedColumn } from 'typeorm';
|
|
11
|
+
import { AUDIT_IP_MAX_LENGTH, AUDIT_USER_AGENT_MAX_LENGTH } from '../../../../domain/audit-record.js';
|
|
12
|
+
const DICTIONARY_VALUE_LENGTH = 64;
|
|
13
|
+
let AuditRecordEntity = class AuditRecordEntity {
|
|
14
|
+
action;
|
|
15
|
+
actorId;
|
|
16
|
+
actorRole;
|
|
17
|
+
createdAt;
|
|
18
|
+
eventId;
|
|
19
|
+
id;
|
|
20
|
+
ip;
|
|
21
|
+
subjectId;
|
|
22
|
+
userAgent;
|
|
23
|
+
};
|
|
24
|
+
__decorate([
|
|
25
|
+
Column({ length: DICTIONARY_VALUE_LENGTH, nullable: false, type: 'varchar' }),
|
|
26
|
+
__metadata("design:type", String)
|
|
27
|
+
], AuditRecordEntity.prototype, "action", void 0);
|
|
28
|
+
__decorate([
|
|
29
|
+
Column({ nullable: true, type: 'uuid' }),
|
|
30
|
+
__metadata("design:type", Object)
|
|
31
|
+
], AuditRecordEntity.prototype, "actorId", void 0);
|
|
32
|
+
__decorate([
|
|
33
|
+
Column({ length: DICTIONARY_VALUE_LENGTH, nullable: true, type: 'varchar' }),
|
|
34
|
+
__metadata("design:type", Object)
|
|
35
|
+
], AuditRecordEntity.prototype, "actorRole", void 0);
|
|
36
|
+
__decorate([
|
|
37
|
+
CreateDateColumn({ type: 'timestamp without time zone' }),
|
|
38
|
+
__metadata("design:type", Date)
|
|
39
|
+
], AuditRecordEntity.prototype, "createdAt", void 0);
|
|
40
|
+
__decorate([
|
|
41
|
+
Column({ nullable: true, type: 'uuid', unique: true }),
|
|
42
|
+
__metadata("design:type", Object)
|
|
43
|
+
], AuditRecordEntity.prototype, "eventId", void 0);
|
|
44
|
+
__decorate([
|
|
45
|
+
PrimaryGeneratedColumn('uuid'),
|
|
46
|
+
__metadata("design:type", String)
|
|
47
|
+
], AuditRecordEntity.prototype, "id", void 0);
|
|
48
|
+
__decorate([
|
|
49
|
+
Column({ length: AUDIT_IP_MAX_LENGTH, nullable: true, type: 'varchar' }),
|
|
50
|
+
__metadata("design:type", Object)
|
|
51
|
+
], AuditRecordEntity.prototype, "ip", void 0);
|
|
52
|
+
__decorate([
|
|
53
|
+
Column({ nullable: false, type: 'uuid' }),
|
|
54
|
+
__metadata("design:type", String)
|
|
55
|
+
], AuditRecordEntity.prototype, "subjectId", void 0);
|
|
56
|
+
__decorate([
|
|
57
|
+
Column({ length: AUDIT_USER_AGENT_MAX_LENGTH, nullable: true, type: 'varchar' }),
|
|
58
|
+
__metadata("design:type", Object)
|
|
59
|
+
], AuditRecordEntity.prototype, "userAgent", void 0);
|
|
60
|
+
AuditRecordEntity = __decorate([
|
|
61
|
+
Entity(),
|
|
62
|
+
Index(['action', 'createdAt']),
|
|
63
|
+
Index(['createdAt']),
|
|
64
|
+
Index(['subjectId'])
|
|
65
|
+
], AuditRecordEntity);
|
|
66
|
+
export { AuditRecordEntity };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './audit-record.entity.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './audit-record.entity.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Repository } from 'typeorm';
|
|
2
|
+
import type { AuditRecord } from '../../../../domain/audit-record.js';
|
|
3
|
+
import type { AuditRecordEntity } from '../entities/audit-record.entity.js';
|
|
4
|
+
import { AuditRecordDto } from '../../../../application/queries/dtos/audit-record.dto.js';
|
|
5
|
+
export declare class AuditRecordMapper {
|
|
6
|
+
private readonly repository;
|
|
7
|
+
constructor(repository: Repository<AuditRecordEntity>);
|
|
8
|
+
toDto(entity: AuditRecordEntity): AuditRecordDto;
|
|
9
|
+
toOrmEntity(domain: AuditRecord): AuditRecordEntity;
|
|
10
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { AuditRecordDto } from '../../../../application/queries/dtos/audit-record.dto.js';
|
|
2
|
+
export class AuditRecordMapper {
|
|
3
|
+
repository;
|
|
4
|
+
constructor(repository) {
|
|
5
|
+
this.repository = repository;
|
|
6
|
+
}
|
|
7
|
+
toDto(entity) {
|
|
8
|
+
return new AuditRecordDto({
|
|
9
|
+
action: entity.action,
|
|
10
|
+
actorId: entity.actorId,
|
|
11
|
+
actorRole: entity.actorRole,
|
|
12
|
+
createdAt: entity.createdAt,
|
|
13
|
+
id: entity.id,
|
|
14
|
+
ip: entity.ip,
|
|
15
|
+
subjectId: entity.subjectId,
|
|
16
|
+
userAgent: entity.userAgent,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
toOrmEntity(domain) {
|
|
20
|
+
return this.repository.create({
|
|
21
|
+
action: domain.props.action,
|
|
22
|
+
actorId: domain.props.actorId,
|
|
23
|
+
actorRole: domain.props.actorRole,
|
|
24
|
+
eventId: domain.props.eventId,
|
|
25
|
+
id: domain.id.value,
|
|
26
|
+
ip: domain.props.ip,
|
|
27
|
+
subjectId: domain.props.subjectId,
|
|
28
|
+
userAgent: domain.props.userAgent,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './audit-record.mapper.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './audit-record.mapper.js';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { MigrationInterface, QueryRunner } from 'typeorm';
|
|
2
|
+
export declare class AuditRecordsAppendOnly1789712401337 implements MigrationInterface {
|
|
3
|
+
name: string;
|
|
4
|
+
down(queryRunner: QueryRunner): Promise<void>;
|
|
5
|
+
up(queryRunner: QueryRunner): Promise<void>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export class AuditRecordsAppendOnly1789712401337 {
|
|
2
|
+
name = 'AuditRecordsAppendOnly1789712401337';
|
|
3
|
+
async down(queryRunner) {
|
|
4
|
+
await queryRunner.query(`DROP TABLE "audit_records"`);
|
|
5
|
+
await queryRunner.query(`DROP FUNCTION "public"."audit_records_block_modification"()`);
|
|
6
|
+
}
|
|
7
|
+
async up(queryRunner) {
|
|
8
|
+
await queryRunner.query(`CREATE TABLE "audit_records" ("created_at" TIMESTAMP NOT NULL DEFAULT now(), "id" uuid NOT NULL DEFAULT uuid_generate_v4(), "actor_id" uuid, "subject_id" uuid NOT NULL, "action" character varying(64) NOT NULL, "ip" character varying(64), "user_agent" character varying(512), "actor_role" character varying(64), "event_id" uuid, CONSTRAINT "UQ_058b8b524336ce9f786a7040f4c" UNIQUE ("event_id"), CONSTRAINT "PK_f903ebdf175f062be69747b0f18" PRIMARY KEY ("id"))`);
|
|
9
|
+
await queryRunner.query(`CREATE INDEX "IDX_78ba6f5763e4f42e8b759150a7" ON "audit_records" ("subject_id") `);
|
|
10
|
+
await queryRunner.query(`CREATE INDEX "IDX_9f4e4098cb280b3872c86ba5d9" ON "audit_records" ("created_at") `);
|
|
11
|
+
await queryRunner.query(`CREATE INDEX "IDX_347b1ef38175e0ec6beac451f1" ON "audit_records" ("action", "created_at") `);
|
|
12
|
+
await queryRunner.query(`
|
|
13
|
+
CREATE OR REPLACE FUNCTION "public"."audit_records_block_modification"() RETURNS TRIGGER AS $$
|
|
14
|
+
BEGIN
|
|
15
|
+
RAISE EXCEPTION '% is append-only; UPDATE/DELETE forbidden', TG_TABLE_NAME;
|
|
16
|
+
END;
|
|
17
|
+
$$ LANGUAGE plpgsql
|
|
18
|
+
`);
|
|
19
|
+
await queryRunner.query(`CREATE TRIGGER "audit_records_block_update" BEFORE UPDATE ON "audit_records" `
|
|
20
|
+
+ `FOR EACH ROW EXECUTE FUNCTION "public"."audit_records_block_modification"()`);
|
|
21
|
+
await queryRunner.query(`CREATE TRIGGER "audit_records_block_delete" BEFORE DELETE ON "audit_records" `
|
|
22
|
+
+ `FOR EACH ROW EXECUTE FUNCTION "public"."audit_records_block_modification"()`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './audit-records-append-only.migration.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './audit-records-append-only.migration.js';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AuditRecordEntity } from './entities/audit-record.entity.js';
|
|
2
|
+
import { AuditRecordsAppendOnly1789712401337 } from './migrations/audit-records-append-only.migration.js';
|
|
3
|
+
export declare const orm: {
|
|
4
|
+
entities: (typeof AuditRecordEntity)[];
|
|
5
|
+
migrations: (typeof AuditRecordsAppendOnly1789712401337)[];
|
|
6
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AuditRecordEntity } from './entities/audit-record.entity.js';
|
|
2
|
+
import { AuditRecordsAppendOnly1789712401337 } from './migrations/audit-records-append-only.migration.js';
|
|
3
|
+
export const orm = {
|
|
4
|
+
entities: [AuditRecordEntity],
|
|
5
|
+
migrations: [AuditRecordsAppendOnly1789712401337],
|
|
6
|
+
};
|
package/dist/esm/nest/infrastructure/database/typeorm/repositories/audit-record.repository.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { FilterInterface, ListingResultInterface, PaginatorInterface, SortingInterface } from '@application-kit/typeorm/listing';
|
|
2
|
+
import { Repository } from 'typeorm';
|
|
3
|
+
import { AuditLogReadInterface } from '../../../../application/ports/audit-log-read.interface.js';
|
|
4
|
+
import { AuditLogWriteInterface } from '../../../../application/ports/audit-log-write.interface.js';
|
|
5
|
+
import { AuditRecordDto } from '../../../../application/queries/dtos/audit-record.dto.js';
|
|
6
|
+
import { AuditRecord } from '../../../../domain/audit-record.js';
|
|
7
|
+
import { AuditRecordEntity } from '../entities/audit-record.entity.js';
|
|
8
|
+
export declare class AuditRecordRepository implements AuditLogReadInterface, AuditLogWriteInterface {
|
|
9
|
+
private readonly repository;
|
|
10
|
+
private readonly mapper;
|
|
11
|
+
constructor(repository: Repository<AuditRecordEntity>);
|
|
12
|
+
append(record: AuditRecord): Promise<void>;
|
|
13
|
+
list(paginator: PaginatorInterface, sorting?: SortingInterface[], filters?: FilterInterface[]): Promise<ListingResultInterface<AuditRecordDto>>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
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;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
import { getListByCursor } from '@application-kit/typeorm';
|
|
14
|
+
import { Injectable } from '@nestjs/common';
|
|
15
|
+
import { InjectRepository } from '@nestjs/typeorm';
|
|
16
|
+
import { Repository } from 'typeorm';
|
|
17
|
+
import { AuditRecordEntity } from '../entities/audit-record.entity.js';
|
|
18
|
+
import { AuditRecordMapper } from '../mappers/audit-record.mapper.js';
|
|
19
|
+
let AuditRecordRepository = class AuditRecordRepository {
|
|
20
|
+
repository;
|
|
21
|
+
mapper;
|
|
22
|
+
constructor(repository) {
|
|
23
|
+
this.repository = repository;
|
|
24
|
+
this.mapper = new AuditRecordMapper(repository);
|
|
25
|
+
}
|
|
26
|
+
async append(record) {
|
|
27
|
+
await this.repository
|
|
28
|
+
.createQueryBuilder()
|
|
29
|
+
.insert()
|
|
30
|
+
.into(AuditRecordEntity)
|
|
31
|
+
.values(this.mapper.toOrmEntity(record))
|
|
32
|
+
.orIgnore()
|
|
33
|
+
.execute();
|
|
34
|
+
}
|
|
35
|
+
async list(paginator, sorting, filters) {
|
|
36
|
+
return getListByCursor(AuditRecordEntity, this.repository.createQueryBuilder('auditRecord'), (entities) => entities.map((entity) => this.mapper.toDto(entity)), paginator, filters, sorting);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
AuditRecordRepository = __decorate([
|
|
40
|
+
Injectable(),
|
|
41
|
+
__param(0, InjectRepository(AuditRecordEntity)),
|
|
42
|
+
__metadata("design:paramtypes", [Repository])
|
|
43
|
+
], AuditRecordRepository);
|
|
44
|
+
export { AuditRecordRepository };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './audit-record.repository.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './audit-record.repository.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './database/index.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './database/index.js';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface AuditRequestFactsInterface {
|
|
2
|
+
actorId: null | string;
|
|
3
|
+
actorRole: null | string;
|
|
4
|
+
ip: null | string;
|
|
5
|
+
userAgent: null | string;
|
|
6
|
+
}
|
|
7
|
+
export type AuditRequestFactsResolver = (request: AuditRequestInterface) => Pick<AuditRequestFactsInterface, 'ip' | 'userAgent'>;
|
|
8
|
+
export interface AuditRequestInterface {
|
|
9
|
+
headers?: Record<string, string | string[] | undefined> | undefined;
|
|
10
|
+
ip?: string | undefined;
|
|
11
|
+
raw?: {
|
|
12
|
+
socket?: {
|
|
13
|
+
remoteAddress?: string | undefined;
|
|
14
|
+
} | undefined;
|
|
15
|
+
} | undefined;
|
|
16
|
+
socket?: {
|
|
17
|
+
remoteAddress?: string | undefined;
|
|
18
|
+
} | undefined;
|
|
19
|
+
user?: {
|
|
20
|
+
id?: string;
|
|
21
|
+
role?: string;
|
|
22
|
+
} | undefined;
|
|
23
|
+
}
|
|
24
|
+
export declare const auditRequestFacts: () => AuditRequestFactsInterface;
|
|
25
|
+
export declare const runWithAuditRequest: <T>(request: AuditRequestInterface | undefined, resolveRequestFacts: AuditRequestFactsResolver, callback: () => T) => T;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
const storage = new AsyncLocalStorage();
|
|
3
|
+
const EMPTY_FACTS = { actorId: null, actorRole: null, ip: null, userAgent: null };
|
|
4
|
+
const actorFacts = (user) => {
|
|
5
|
+
const { id = null, role = null } = user ?? {};
|
|
6
|
+
return { actorId: id, actorRole: role };
|
|
7
|
+
};
|
|
8
|
+
export const auditRequestFacts = () => {
|
|
9
|
+
const store = storage.getStore();
|
|
10
|
+
if (store === undefined) {
|
|
11
|
+
return EMPTY_FACTS;
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
...actorFacts(store.request.user),
|
|
15
|
+
...store.resolveRequestFacts(store.request),
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export const runWithAuditRequest = (request, resolveRequestFacts, callback) => storage.run(request === undefined ? undefined : { request, resolveRequestFacts }, callback);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './audit-request-context.js';
|