@nest-omni/core 3.1.2-8 → 3.1.2-9

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.
Files changed (91) hide show
  1. package/audit/audit.module.d.ts +10 -0
  2. package/audit/audit.module.js +254 -0
  3. package/audit/controllers/audit.controller.d.ts +20 -0
  4. package/audit/controllers/audit.controller.js +142 -0
  5. package/audit/controllers/index.d.ts +1 -0
  6. package/audit/controllers/index.js +17 -0
  7. package/audit/decorators/audit-controller.decorator.d.ts +5 -0
  8. package/audit/decorators/audit-controller.decorator.js +17 -0
  9. package/audit/decorators/audit-operation.decorator.d.ts +7 -0
  10. package/audit/decorators/audit-operation.decorator.js +25 -0
  11. package/audit/decorators/entity-audit.decorator.d.ts +10 -0
  12. package/audit/decorators/entity-audit.decorator.js +70 -0
  13. package/audit/decorators/index.d.ts +3 -0
  14. package/audit/decorators/index.js +19 -0
  15. package/audit/dto/audit-log-query.dto.d.ts +14 -0
  16. package/audit/dto/audit-log-query.dto.js +95 -0
  17. package/audit/dto/begin-transaction.dto.d.ts +3 -0
  18. package/audit/dto/begin-transaction.dto.js +22 -0
  19. package/audit/dto/compare-entities.dto.d.ts +6 -0
  20. package/audit/dto/compare-entities.dto.js +44 -0
  21. package/audit/dto/index.d.ts +5 -0
  22. package/audit/dto/index.js +21 -0
  23. package/audit/dto/pre-check-restore.dto.d.ts +5 -0
  24. package/audit/dto/pre-check-restore.dto.js +32 -0
  25. package/audit/dto/restore-entity.dto.d.ts +9 -0
  26. package/audit/dto/restore-entity.dto.js +53 -0
  27. package/audit/entities/entity-audit-log.entity.d.ts +23 -0
  28. package/audit/entities/entity-audit-log.entity.js +110 -0
  29. package/audit/entities/entity-transaction.entity.d.ts +21 -0
  30. package/audit/entities/entity-transaction.entity.js +80 -0
  31. package/audit/entities/index.d.ts +4 -0
  32. package/audit/entities/index.js +20 -0
  33. package/audit/entities/manual-operation-log.entity.d.ts +13 -0
  34. package/audit/entities/manual-operation-log.entity.js +65 -0
  35. package/audit/entities/operation-template.entity.d.ts +11 -0
  36. package/audit/entities/operation-template.entity.js +65 -0
  37. package/audit/enums/audit.enums.d.ts +42 -0
  38. package/audit/enums/audit.enums.js +53 -0
  39. package/audit/enums/index.d.ts +1 -0
  40. package/audit/enums/index.js +17 -0
  41. package/audit/index.d.ts +12 -0
  42. package/audit/index.js +48 -0
  43. package/audit/interceptors/audit.interceptor.d.ts +12 -0
  44. package/audit/interceptors/audit.interceptor.js +95 -0
  45. package/audit/interceptors/index.d.ts +1 -0
  46. package/audit/interceptors/index.js +17 -0
  47. package/audit/interfaces/audit.interfaces.d.ts +180 -0
  48. package/audit/interfaces/audit.interfaces.js +2 -0
  49. package/audit/interfaces/index.d.ts +1 -0
  50. package/audit/interfaces/index.js +17 -0
  51. package/audit/services/audit-context.service.d.ts +10 -0
  52. package/audit/services/audit-context.service.js +55 -0
  53. package/audit/services/audit-strategy.service.d.ts +19 -0
  54. package/audit/services/audit-strategy.service.js +89 -0
  55. package/audit/services/entity-audit.service.d.ts +65 -0
  56. package/audit/services/entity-audit.service.js +626 -0
  57. package/audit/services/index.d.ts +6 -0
  58. package/audit/services/index.js +22 -0
  59. package/audit/services/multi-database.service.d.ts +10 -0
  60. package/audit/services/multi-database.service.js +59 -0
  61. package/audit/services/operation-description.service.d.ts +21 -0
  62. package/audit/services/operation-description.service.js +213 -0
  63. package/audit/services/transaction-audit.service.d.ts +22 -0
  64. package/audit/services/transaction-audit.service.js +201 -0
  65. package/audit/subscribers/entity-audit.subscriber.d.ts +14 -0
  66. package/audit/subscribers/entity-audit.subscriber.js +136 -0
  67. package/audit/subscribers/index.d.ts +1 -0
  68. package/audit/subscribers/index.js +17 -0
  69. package/http-client/examples/advanced-usage.example.js +14 -1
  70. package/http-client/examples/auth-with-waiting-lock.example.d.ts +17 -0
  71. package/http-client/examples/auth-with-waiting-lock.example.js +336 -0
  72. package/http-client/examples/basic-usage.example.d.ts +1 -9
  73. package/http-client/examples/basic-usage.example.js +4 -14
  74. package/http-client/examples/multi-api-configuration.example.js +4 -4
  75. package/http-client/http-client.module.js +7 -4
  76. package/http-client/services/api-client-registry.service.d.ts +2 -1
  77. package/http-client/services/api-client-registry.service.js +2 -1
  78. package/http-client/services/http-client.service.d.ts +18 -1
  79. package/http-client/services/http-client.service.js +123 -3
  80. package/http-client/services/http-log-query.service.d.ts +20 -0
  81. package/http-client/services/http-log-query.service.js +176 -0
  82. package/http-client/services/http-replay.service.d.ts +58 -0
  83. package/http-client/services/http-replay.service.js +266 -0
  84. package/http-client/services/log-cleanup.service.js +2 -2
  85. package/http-client/services/logging.service.js +1 -1
  86. package/http-client/utils/request-id.util.d.ts +4 -0
  87. package/http-client/utils/request-id.util.js +34 -0
  88. package/index.d.ts +1 -0
  89. package/index.js +1 -0
  90. package/package.json +1 -1
  91. package/setup/bootstrap.setup.js +5 -1
@@ -0,0 +1,19 @@
1
+ import { IAuditStrategy, IFieldFilter, AuditConfig } from '../interfaces';
2
+ import { AuditOperation, RecordStrategy, MaskingStrategy } from '../enums';
3
+ export declare class DefaultFieldFilter implements IFieldFilter {
4
+ private readonly includeFields?;
5
+ private readonly excludeFields?;
6
+ private readonly maskFields?;
7
+ constructor(includeFields?: string[], excludeFields?: string[], maskFields?: string[]);
8
+ shouldIncludeField(fieldName: string, path: string[]): boolean;
9
+ shouldMaskField(fieldName: string, path: string[]): boolean;
10
+ getMaskingStrategy(fieldName: string, path: string[]): MaskingStrategy;
11
+ private matchPattern;
12
+ }
13
+ export declare class DefaultAuditStrategy implements IAuditStrategy {
14
+ private readonly config?;
15
+ constructor(config?: AuditConfig);
16
+ shouldRecord(entityType: string, operation: AuditOperation): boolean;
17
+ getRecordStrategy(entityType: string, operation: AuditOperation): RecordStrategy;
18
+ getFieldFilter(entityType: string): IFieldFilter;
19
+ }
@@ -0,0 +1,89 @@
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.DefaultAuditStrategy = exports.DefaultFieldFilter = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const enums_1 = require("../enums");
18
+ class DefaultFieldFilter {
19
+ constructor(includeFields, excludeFields, maskFields) {
20
+ this.includeFields = includeFields;
21
+ this.excludeFields = excludeFields;
22
+ this.maskFields = maskFields;
23
+ }
24
+ shouldIncludeField(fieldName, path) {
25
+ const fullPath = [...path, fieldName].join('.');
26
+ if (this.includeFields && this.includeFields.length > 0) {
27
+ return this.includeFields.some((pattern) => this.matchPattern(fullPath, pattern));
28
+ }
29
+ if (this.excludeFields && this.excludeFields.length > 0) {
30
+ return !this.excludeFields.some((pattern) => this.matchPattern(fullPath, pattern));
31
+ }
32
+ return true;
33
+ }
34
+ shouldMaskField(fieldName, path) {
35
+ var _a;
36
+ const fullPath = [...path, fieldName].join('.');
37
+ return ((_a = this.maskFields) === null || _a === void 0 ? void 0 : _a.some((pattern) => this.matchPattern(fullPath, pattern))) || false;
38
+ }
39
+ getMaskingStrategy(fieldName, path) {
40
+ return enums_1.MaskingStrategy.MASK;
41
+ }
42
+ matchPattern(path, pattern) {
43
+ if (pattern.endsWith('*')) {
44
+ return path.startsWith(pattern.slice(0, -1));
45
+ }
46
+ return path === pattern;
47
+ }
48
+ }
49
+ exports.DefaultFieldFilter = DefaultFieldFilter;
50
+ let DefaultAuditStrategy = class DefaultAuditStrategy {
51
+ constructor(config) {
52
+ this.config = config;
53
+ }
54
+ shouldRecord(entityType, operation) {
55
+ var _a, _b, _c, _d, _e;
56
+ const globalEnabled = ((_a = this.config) === null || _a === void 0 ? void 0 : _a.enabled) !== false;
57
+ if (!globalEnabled)
58
+ return false;
59
+ const entityConfig = (_c = (_b = this.config) === null || _b === void 0 ? void 0 : _b.entities) === null || _c === void 0 ? void 0 : _c[entityType];
60
+ if (entityConfig && entityConfig.enabled === false)
61
+ return false;
62
+ const operationConfig = (_e = (_d = this.config) === null || _d === void 0 ? void 0 : _d.operations) === null || _e === void 0 ? void 0 : _e[operation];
63
+ if (operationConfig && operationConfig.enabled === false)
64
+ return false;
65
+ return true;
66
+ }
67
+ getRecordStrategy(entityType, operation) {
68
+ var _a, _b, _c, _d, _e, _f, _g;
69
+ const entityStrategy = (_c = (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.entities) === null || _b === void 0 ? void 0 : _b[entityType]) === null || _c === void 0 ? void 0 : _c.strategy;
70
+ if (entityStrategy)
71
+ return entityStrategy;
72
+ const operationStrategy = (_f = (_e = (_d = this.config) === null || _d === void 0 ? void 0 : _d.operations) === null || _e === void 0 ? void 0 : _e[operation]) === null || _f === void 0 ? void 0 : _f.strategy;
73
+ if (operationStrategy)
74
+ return operationStrategy;
75
+ return ((_g = this.config) === null || _g === void 0 ? void 0 : _g.defaultStrategy) || enums_1.RecordStrategy.FULL;
76
+ }
77
+ getFieldFilter(entityType) {
78
+ var _a, _b;
79
+ const entityConfig = (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.entities) === null || _b === void 0 ? void 0 : _b[entityType];
80
+ return new DefaultFieldFilter(entityConfig === null || entityConfig === void 0 ? void 0 : entityConfig.includeFields, entityConfig === null || entityConfig === void 0 ? void 0 : entityConfig.excludeFields, entityConfig === null || entityConfig === void 0 ? void 0 : entityConfig.maskFields);
81
+ }
82
+ };
83
+ exports.DefaultAuditStrategy = DefaultAuditStrategy;
84
+ exports.DefaultAuditStrategy = DefaultAuditStrategy = __decorate([
85
+ (0, common_1.Injectable)(),
86
+ __param(0, (0, common_1.Optional)()),
87
+ __param(0, (0, common_1.Inject)('AUDIT_CONFIG')),
88
+ __metadata("design:paramtypes", [Object])
89
+ ], DefaultAuditStrategy);
@@ -0,0 +1,65 @@
1
+ import { Repository, EntityManager } from 'typeorm';
2
+ import { EntityAuditLogEntity, EntityTransactionEntity, ManualOperationLogEntity } from '../entities';
3
+ import { AuditOperation } from '../enums';
4
+ import { AuditConfig, IAuditStrategy, EntityDifference, RestoreOptions, RestoreResult, PreCheckResult, ManualOperationData, ChangeDetail, RollbackAction } from '../interfaces';
5
+ import { AuditContextService } from './audit-context.service';
6
+ import { MultiDatabaseService } from './multi-database.service';
7
+ import { PageDto } from '../../common/dto';
8
+ import { AuditLogQueryDto } from '../dto';
9
+ export declare class EntityAuditService {
10
+ private readonly auditLogRepository;
11
+ private readonly transactionRepository;
12
+ private readonly manualOperationRepository;
13
+ private readonly entityManager;
14
+ private readonly contextService;
15
+ private readonly multiDbService;
16
+ private readonly auditStrategy;
17
+ private readonly config?;
18
+ private readonly auditConnectionName;
19
+ constructor(auditLogRepository: Repository<EntityAuditLogEntity>, transactionRepository: Repository<EntityTransactionEntity>, manualOperationRepository: Repository<ManualOperationLogEntity>, entityManager: EntityManager, contextService: AuditContextService, multiDbService: MultiDatabaseService, auditStrategy?: IAuditStrategy, config?: AuditConfig, auditConnectionName?: string);
20
+ logEntityChange(entityType: string, entityId: string, operation: AuditOperation, oldValue: Record<string, any>, newValue: Record<string, any>, metadata?: Record<string, any>): Promise<EntityAuditLogEntity | null>;
21
+ getAuditLogs(query: AuditLogQueryDto): Promise<PageDto<EntityAuditLogEntity>>;
22
+ compareEntities(entityType: string, entityId: string, fromLogId?: string, toLogId?: string): Promise<EntityDifference>;
23
+ preCheckRestore(entityType: string, entityId: string, auditLogId: string): Promise<PreCheckResult>;
24
+ restoreEntity(entityType: string, entityId: string, auditLogId: string, options?: RestoreOptions): Promise<RestoreResult>;
25
+ private calculateChangedFields;
26
+ private calculateChangedFieldPaths;
27
+ private deepEqual;
28
+ private deepDiff;
29
+ private compareSnapshotData;
30
+ private filterAndMaskFields;
31
+ private applyMasking;
32
+ private hashValue;
33
+ private maskValue;
34
+ private partialMaskValue;
35
+ private generateHashChain;
36
+ private generateDescription;
37
+ private detectConflicts;
38
+ logEntityChangeWithTemplate(data: {
39
+ entityType: string;
40
+ entityId: string;
41
+ operation: AuditOperation;
42
+ oldValue?: Record<string, any>;
43
+ newValue?: Record<string, any>;
44
+ changedFields?: string[];
45
+ operationTemplateKey?: string;
46
+ descriptionParams?: Record<string, any>;
47
+ changeDetails?: ChangeDetail[];
48
+ rollbackActions?: RollbackAction[];
49
+ metadata?: Record<string, any>;
50
+ }): Promise<EntityAuditLogEntity | null>;
51
+ logManualOperation(data: ManualOperationData): Promise<ManualOperationLogEntity>;
52
+ withTransaction<T>(fn: (transactionId: string) => Promise<T>, options?: {
53
+ userId?: string;
54
+ username?: string;
55
+ requestIp?: string;
56
+ operationTemplateKey?: string;
57
+ descriptionParams?: Record<string, any>;
58
+ metadata?: Record<string, any>;
59
+ }): Promise<T>;
60
+ getCurrentTransactionId(): Promise<string | null>;
61
+ setCurrentTransactionId(transactionId: string | null): Promise<void>;
62
+ beginTransaction(userId?: string, userName?: string, ip?: string, operationTemplateKey?: string, descriptionParams?: Record<string, any>): Promise<string>;
63
+ commitTransaction(transactionId: string): Promise<void>;
64
+ rollbackTransaction(transactionId: string): Promise<void>;
65
+ }