@maykonpaulo/maestro-core 0.3.0-next.0 → 0.3.0-next.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/dist/index.d.ts CHANGED
@@ -66,6 +66,40 @@ declare class ConsoleLogger implements Logger {
66
66
  private serializeError;
67
67
  }
68
68
 
69
+ type OperationLogStatus = 'success' | 'failure' | 'partial';
70
+
71
+ interface StructuredLogEntry {
72
+ correlationId?: string;
73
+ operation?: string;
74
+ entity?: string;
75
+ entityId?: string;
76
+ actor?: string;
77
+ durationMs?: number;
78
+ status?: OperationLogStatus;
79
+ severity?: string;
80
+ message?: string;
81
+ metadata?: Metadata;
82
+ error?: unknown;
83
+ }
84
+
85
+ interface StructuredLogger {
86
+ debug(entry: StructuredLogEntry): void;
87
+ info(entry: StructuredLogEntry): void;
88
+ warn(entry: StructuredLogEntry): void;
89
+ error(entry: StructuredLogEntry): void;
90
+ }
91
+
92
+ declare class ConsoleStructuredLogger implements StructuredLogger {
93
+ private readonly minLevel;
94
+ constructor(minLevel?: LogLevel);
95
+ debug(entry: StructuredLogEntry): void;
96
+ info(entry: StructuredLogEntry): void;
97
+ warn(entry: StructuredLogEntry): void;
98
+ error(entry: StructuredLogEntry): void;
99
+ private log;
100
+ private serializeError;
101
+ }
102
+
69
103
  type AuditLevel = 'debug' | 'info' | 'warn' | 'error' | 'critical';
70
104
 
71
105
  interface AuditEvent {
@@ -74,6 +108,8 @@ interface AuditEvent {
74
108
  action: string;
75
109
  actor: Actor;
76
110
  resource?: ResourceRef;
111
+ entity?: string;
112
+ entityId?: string;
77
113
  level: AuditLevel;
78
114
  before?: Metadata;
79
115
  after?: Metadata;
@@ -87,6 +123,8 @@ interface AuditEvent {
87
123
  interface AuditFilter {
88
124
  actorId?: string;
89
125
  action?: string;
126
+ entity?: string;
127
+ entityId?: string;
90
128
  resourceType?: string;
91
129
  resourceId?: string;
92
130
  level?: AuditLevel;
@@ -99,11 +137,17 @@ interface AuditRepository {
99
137
  list(filter?: AuditFilter): Promise<AuditEvent[]>;
100
138
  }
101
139
 
140
+ interface AuditTimeline {
141
+ query(filter?: AuditFilter): Promise<AuditEvent[]>;
142
+ }
143
+
102
144
  interface RecordAuditInput {
103
145
  action: string;
104
146
  actor: Actor;
105
147
  level?: AuditLevel;
106
148
  resource?: ResourceRef;
149
+ entity?: string;
150
+ entityId?: string;
107
151
  before?: Metadata;
108
152
  after?: Metadata;
109
153
  metadata?: Metadata;
@@ -118,10 +162,11 @@ declare class AuditRecorder {
118
162
  record(input: RecordAuditInput): Promise<AuditEvent>;
119
163
  }
120
164
 
121
- declare class InMemoryAuditRepository implements AuditRepository {
165
+ declare class InMemoryAuditRepository implements AuditRepository, AuditTimeline {
122
166
  private readonly store;
123
167
  record(event: AuditEvent): Promise<void>;
124
168
  list(filter?: AuditFilter): Promise<AuditEvent[]>;
169
+ query(filter?: AuditFilter): Promise<AuditEvent[]>;
125
170
  }
126
171
 
127
172
  type Permission = string;
@@ -967,4 +1012,238 @@ declare class IntrospectionRuntime {
967
1012
  compareWithSnapshot(snapshotId: string, provider?: IntrospectionProvider): Promise<IntrospectionDiff | null>;
968
1013
  }
969
1014
 
970
- export { type Actor, type ActorType, type AuditEvent, type AuditFilter, type AuditLevel, AuditRecorder, type AuditRepository, type ConfigProvider, ConsoleLogger, type ContextAction, type ContextActionCondition, type ContextActionStyle, type CreateMaestroFromIntrospectionOptions, CsvExportProvider, type CursorPagination, DEFAULT_CAPABILITIES, type DatasourceDeleteContext, type DatasourceFindContext, type DatasourceProvider, type DatasourceQueryContext, DatasourceRegistry, type DatasourceUpdateContext, type DatasourceWriteContext, type DiffChange, type DiffChangeKind, DiffEngine, type DiffEngineOptions, type DiffSummary, type DomainEvent, type EntityCapabilities, type EntityDiffChange, type EntityDiffChangeKind, type EntityExportConfig, type EntityIntrospectionSchema, type EntityLabelConfig, type EntityMetadata, type EntitySchema, type EntitySourceConfig, type EnumOption, ErrorCode, type EventBus, type EventHandler, type ExportConfig, type ExportFormat, type ExportOptions, type ExportProvider, type ExportResult, type FeatureFlag, type FeatureFlagProvider, type FieldDetailConfig, type FieldDiffChange, type FieldDiffChangeKind, type FieldFormConfig, type FieldIntrospectionSchema, type FieldListConfig, type FieldMetadata, type FieldSchema, type FieldSchemaDetailConfig, type FieldSchemaEnumOption, type FieldSchemaFormConfig, type FieldSchemaListConfig, type FieldType, type FileSystemReader, type FilterDescriptor, type FilterOperator, type GeneratedConfig, type ImpactLevel, InMemoryAuditRepository, InMemoryConfigProvider, InMemoryDatasourceProvider, InMemoryEventBus, InMemoryFeatureFlagProvider, InMemorySnapshotRepository, type IndexIntrospectionSchema, type IntrospectionDiff, type IntrospectionProvider, type IntrospectionReport, type IntrospectionReportChange, type IntrospectionReportStats, type IntrospectionResult, IntrospectionRuntime, type IntrospectionRuntimeResult, type IntrospectionRuntimeRunOptions, type IntrospectionSnapshot, type ListResult, type LoadedConfig, type LogEntry, type LogLevel, type Logger, type MaestroActorResolver, type MaestroConfig, MaestroEngine, MaestroError, type MaestroFileLoaderOptions, type MaestroHttpHandler, type MaestroHttpHandlers, type MaestroHttpOptions, type MaestroHttpRequest, type MaestroHttpResponse, type MaestroMetadata, type MaestroRequestContext, type MergeIntrospectionOptions, type MergeStrategy, type Metadata, MetadataEngine, type MetadataValue, type OffsetPagination, type OperationContext, type OperationDef, type OperationMetadata, OperationRegistry, type OperationResult, type OperationScope, type PagePagination, type PaginationInput, type Permission, type QueryInput, RbacEngine, type RbacPolicy, type RecordAuditInput, type RelationDiffChange, type RelationDiffChangeKind, type RelationDisplayConfig, type RelationEndpoint, type RelationIntrospectionSchema, type RelationMetadata, type RelationSchema, type RelationType, ReportGenerator, type ResourceRef, type Role, type SchemaValidationError, type SchemaValidationResult, type SearchConfig, type SearchInput, type SnapshotRepository, type SoftDeleteConfig, type SortDescriptor, type SortDirection, type YamlParser, createMaestro, createMaestroFromIntrospection, createMaestroHttpHandlers, detectDisplayField, generateAllConfigs, generateEntityConfig, generateRelationConfig, humanizeFieldName, inferFieldType, isSearchCandidate, isSoftDeleteCandidate, isTimestampField, loadMaestroConfig, mergeIntrospectionWithOverrides, parseQueryInput, tableNameToEntityId, tableNameToLabel, validateMaestroConfig };
1015
+ type CorrelationId = string;
1016
+ declare function generateCorrelationId(): CorrelationId;
1017
+
1018
+ interface CorrelationContext {
1019
+ correlationId: CorrelationId;
1020
+ }
1021
+
1022
+ type OperationalRisk = 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL';
1023
+
1024
+ interface RiskClassificationInput {
1025
+ operation: string;
1026
+ resource?: ResourceRef;
1027
+ metadata?: Metadata;
1028
+ }
1029
+ interface RiskClassifier {
1030
+ classify(input: RiskClassificationInput): OperationalRisk;
1031
+ }
1032
+
1033
+ declare class MetadataRiskClassifier implements RiskClassifier {
1034
+ private readonly operationRiskMap;
1035
+ private readonly defaultRisk;
1036
+ constructor(operationRiskMap?: Record<string, OperationalRisk>, defaultRisk?: OperationalRisk);
1037
+ classify(input: RiskClassificationInput): OperationalRisk;
1038
+ }
1039
+
1040
+ type AuthorizationDecision = 'ALLOW' | 'DENY' | 'REQUIRES_CONFIRMATION';
1041
+
1042
+ interface AuthorizationContext {
1043
+ actor: Actor;
1044
+ operation: string;
1045
+ resource?: ResourceRef;
1046
+ metadata?: Metadata;
1047
+ riskLevel?: OperationalRisk;
1048
+ correlationId?: string;
1049
+ }
1050
+
1051
+ interface AuthorizationResult {
1052
+ decision: AuthorizationDecision;
1053
+ reason?: string;
1054
+ metadata?: Metadata;
1055
+ }
1056
+
1057
+ interface AuthorizationProvider {
1058
+ evaluate(context: AuthorizationContext): Promise<AuthorizationResult>;
1059
+ }
1060
+
1061
+ declare class ContextualAuthorizationEngine implements AuthorizationProvider {
1062
+ private readonly criticalOperations;
1063
+ private readonly rbac;
1064
+ constructor(policy: RbacPolicy, criticalOperations?: ReadonlySet<string>);
1065
+ evaluate(context: AuthorizationContext): Promise<AuthorizationResult>;
1066
+ }
1067
+
1068
+ type PolicyDecision = 'ALLOW' | 'DENY' | 'REQUIRES_CONFIRMATION';
1069
+
1070
+ interface PolicyContext {
1071
+ actor: Actor;
1072
+ operation: string;
1073
+ resource?: ResourceRef;
1074
+ metadata?: Metadata;
1075
+ riskLevel?: OperationalRisk;
1076
+ correlationId?: string;
1077
+ }
1078
+
1079
+ interface PolicyRuleResult {
1080
+ decision: PolicyDecision;
1081
+ reason?: string;
1082
+ }
1083
+ interface PolicyRule {
1084
+ id: string;
1085
+ description?: string;
1086
+ evaluate(context: PolicyContext): PolicyRuleResult | null;
1087
+ }
1088
+
1089
+ interface PolicyViolation {
1090
+ ruleId: string;
1091
+ reason?: string;
1092
+ context: PolicyContext;
1093
+ occurredAt: Date;
1094
+ }
1095
+
1096
+ interface PolicyEvaluationResult {
1097
+ decision: PolicyDecision;
1098
+ violations: PolicyViolation[];
1099
+ reason?: string;
1100
+ }
1101
+
1102
+ interface PolicyProvider {
1103
+ rules(): PolicyRule[];
1104
+ }
1105
+
1106
+ declare class PolicyEngine {
1107
+ private readonly provider;
1108
+ constructor(provider: PolicyProvider);
1109
+ evaluate(context: PolicyContext): PolicyEvaluationResult;
1110
+ }
1111
+
1112
+ declare class InMemoryPolicyProvider implements PolicyProvider {
1113
+ private readonly _rules;
1114
+ constructor(rules?: PolicyRule[]);
1115
+ rules(): PolicyRule[];
1116
+ }
1117
+
1118
+ type ConfirmationStatus = 'REQUESTED' | 'AWAITING_CONFIRMATION' | 'APPROVED' | 'REJECTED' | 'EXECUTED' | 'EXPIRED';
1119
+
1120
+ interface ConfirmationApproval {
1121
+ approver: Actor;
1122
+ approvedAt: Date;
1123
+ comment?: string;
1124
+ }
1125
+
1126
+ interface ConfirmationRequest {
1127
+ id: string;
1128
+ operation: string;
1129
+ actor: Actor;
1130
+ resource?: ResourceRef;
1131
+ status: ConfirmationStatus;
1132
+ requiredApprovals: number;
1133
+ approvals: ConfirmationApproval[];
1134
+ rejections: ConfirmationApproval[];
1135
+ requestedAt: Date;
1136
+ executedAt?: Date;
1137
+ expiresAt?: Date;
1138
+ metadata?: Metadata;
1139
+ correlationId?: string;
1140
+ }
1141
+
1142
+ interface ConfirmationRepository {
1143
+ save(request: ConfirmationRequest): Promise<void>;
1144
+ findById(id: string): Promise<ConfirmationRequest | undefined>;
1145
+ listPending(): Promise<ConfirmationRequest[]>;
1146
+ }
1147
+
1148
+ interface RequestConfirmationInput {
1149
+ operation: string;
1150
+ actor: Actor;
1151
+ resource?: ResourceRef;
1152
+ requiredApprovals?: number;
1153
+ metadata?: Metadata;
1154
+ correlationId?: string;
1155
+ expiresAt?: Date;
1156
+ }
1157
+ declare class ConfirmationEngine {
1158
+ private readonly repository;
1159
+ constructor(repository: ConfirmationRepository);
1160
+ request(input: RequestConfirmationInput): Promise<ConfirmationRequest>;
1161
+ approve(requestId: string, approver: Actor, comment?: string): Promise<ConfirmationRequest>;
1162
+ reject(requestId: string, approver: Actor, comment?: string): Promise<ConfirmationRequest>;
1163
+ execute(requestId: string): Promise<ConfirmationRequest>;
1164
+ getPending(): Promise<ConfirmationRequest[]>;
1165
+ private findOrThrow;
1166
+ private assertActive;
1167
+ }
1168
+
1169
+ declare class InMemoryConfirmationRepository implements ConfirmationRepository {
1170
+ private readonly store;
1171
+ save(request: ConfirmationRequest): Promise<void>;
1172
+ findById(id: string): Promise<ConfirmationRequest | undefined>;
1173
+ listPending(): Promise<ConfirmationRequest[]>;
1174
+ }
1175
+
1176
+ declare const GOVERNANCE_EVENT_TYPES: {
1177
+ readonly OPERATION_EXECUTED: "governance.operation.executed";
1178
+ readonly AUTHORIZATION_DENIED: "governance.authorization.denied";
1179
+ readonly POLICY_TRIGGERED: "governance.policy.triggered";
1180
+ readonly CONFIRMATION_REQUESTED: "governance.confirmation.requested";
1181
+ readonly CONFIRMATION_APPROVED: "governance.confirmation.approved";
1182
+ readonly CONFIRMATION_REJECTED: "governance.confirmation.rejected";
1183
+ readonly AUDIT_RECORDED: "governance.audit.recorded";
1184
+ };
1185
+ type GovernanceEventType = (typeof GOVERNANCE_EVENT_TYPES)[keyof typeof GOVERNANCE_EVENT_TYPES];
1186
+
1187
+ interface OperationExecutedPayload {
1188
+ operation: string;
1189
+ actor: Actor;
1190
+ resource?: ResourceRef;
1191
+ correlationId?: string;
1192
+ durationMs?: number;
1193
+ }
1194
+ interface AuthorizationDeniedPayload {
1195
+ context: AuthorizationContext;
1196
+ reason?: string;
1197
+ }
1198
+ interface PolicyTriggeredPayload {
1199
+ violations: PolicyViolation[];
1200
+ correlationId?: string;
1201
+ }
1202
+ interface ConfirmationRequestedPayload {
1203
+ request: ConfirmationRequest;
1204
+ }
1205
+ interface ConfirmationApprovedPayload {
1206
+ request: ConfirmationRequest;
1207
+ approver: Actor;
1208
+ }
1209
+ interface ConfirmationRejectedPayload {
1210
+ request: ConfirmationRequest;
1211
+ approver: Actor;
1212
+ }
1213
+ interface AuditRecordedPayload {
1214
+ event: AuditEvent;
1215
+ }
1216
+
1217
+ interface GovernanceEventBus extends EventBus {
1218
+ publishGovernance<TPayload>(type: GovernanceEventType, payload: TPayload, correlationId?: string): Promise<DomainEvent<TPayload>>;
1219
+ }
1220
+
1221
+ declare class InMemoryGovernanceEventBus extends InMemoryEventBus implements GovernanceEventBus {
1222
+ publishGovernance<TPayload>(type: GovernanceEventType, payload: TPayload, correlationId?: string): Promise<DomainEvent<TPayload>>;
1223
+ }
1224
+
1225
+ interface PolicyViolationFilter {
1226
+ ruleId?: string;
1227
+ correlationId?: string;
1228
+ from?: Date;
1229
+ to?: Date;
1230
+ }
1231
+ interface GovernanceApi {
1232
+ getAuditTimeline(filter?: AuditFilter): Promise<AuditEvent[]>;
1233
+ getCorrelationTrace(correlationId: string): Promise<AuditEvent[]>;
1234
+ getPendingConfirmations(): Promise<ConfirmationRequest[]>;
1235
+ getPolicyViolations(filter?: PolicyViolationFilter): Promise<PolicyViolation[]>;
1236
+ }
1237
+
1238
+ declare class DefaultGovernanceApi implements GovernanceApi {
1239
+ private readonly auditRepository;
1240
+ private readonly confirmationRepository;
1241
+ private readonly violationLog;
1242
+ constructor(auditRepository: AuditRepository, confirmationRepository: ConfirmationRepository, violationLog?: PolicyViolation[]);
1243
+ getAuditTimeline(filter?: AuditFilter): Promise<AuditEvent[]>;
1244
+ getCorrelationTrace(correlationId: string): Promise<AuditEvent[]>;
1245
+ getPendingConfirmations(): Promise<ConfirmationRequest[]>;
1246
+ getPolicyViolations(filter?: PolicyViolationFilter): Promise<PolicyViolation[]>;
1247
+ }
1248
+
1249
+ export { type Actor, type ActorType, type AuditEvent, type AuditFilter, type AuditLevel, type AuditRecordedPayload, AuditRecorder, type AuditRepository, type AuditTimeline, type AuthorizationContext, type AuthorizationDecision, type AuthorizationDeniedPayload, type AuthorizationProvider, type AuthorizationResult, type ConfigProvider, type ConfirmationApproval, type ConfirmationApprovedPayload, ConfirmationEngine, type ConfirmationRejectedPayload, type ConfirmationRepository, type ConfirmationRequest, type ConfirmationRequestedPayload, type ConfirmationStatus, ConsoleLogger, ConsoleStructuredLogger, type ContextAction, type ContextActionCondition, type ContextActionStyle, ContextualAuthorizationEngine, type CorrelationContext, type CorrelationId, type CreateMaestroFromIntrospectionOptions, CsvExportProvider, type CursorPagination, DEFAULT_CAPABILITIES, type DatasourceDeleteContext, type DatasourceFindContext, type DatasourceProvider, type DatasourceQueryContext, DatasourceRegistry, type DatasourceUpdateContext, type DatasourceWriteContext, DefaultGovernanceApi, type DiffChange, type DiffChangeKind, DiffEngine, type DiffEngineOptions, type DiffSummary, type DomainEvent, type EntityCapabilities, type EntityDiffChange, type EntityDiffChangeKind, type EntityExportConfig, type EntityIntrospectionSchema, type EntityLabelConfig, type EntityMetadata, type EntitySchema, type EntitySourceConfig, type EnumOption, ErrorCode, type EventBus, type EventHandler, type ExportConfig, type ExportFormat, type ExportOptions, type ExportProvider, type ExportResult, type FeatureFlag, type FeatureFlagProvider, type FieldDetailConfig, type FieldDiffChange, type FieldDiffChangeKind, type FieldFormConfig, type FieldIntrospectionSchema, type FieldListConfig, type FieldMetadata, type FieldSchema, type FieldSchemaDetailConfig, type FieldSchemaEnumOption, type FieldSchemaFormConfig, type FieldSchemaListConfig, type FieldType, type FileSystemReader, type FilterDescriptor, type FilterOperator, GOVERNANCE_EVENT_TYPES, type GeneratedConfig, type GovernanceApi, type GovernanceEventBus, type GovernanceEventType, type ImpactLevel, InMemoryAuditRepository, InMemoryConfigProvider, InMemoryConfirmationRepository, InMemoryDatasourceProvider, InMemoryEventBus, InMemoryFeatureFlagProvider, InMemoryGovernanceEventBus, InMemoryPolicyProvider, InMemorySnapshotRepository, type IndexIntrospectionSchema, type IntrospectionDiff, type IntrospectionProvider, type IntrospectionReport, type IntrospectionReportChange, type IntrospectionReportStats, type IntrospectionResult, IntrospectionRuntime, type IntrospectionRuntimeResult, type IntrospectionRuntimeRunOptions, type IntrospectionSnapshot, type ListResult, type LoadedConfig, type LogEntry, type LogLevel, type Logger, type MaestroActorResolver, type MaestroConfig, MaestroEngine, MaestroError, type MaestroFileLoaderOptions, type MaestroHttpHandler, type MaestroHttpHandlers, type MaestroHttpOptions, type MaestroHttpRequest, type MaestroHttpResponse, type MaestroMetadata, type MaestroRequestContext, type MergeIntrospectionOptions, type MergeStrategy, type Metadata, MetadataEngine, MetadataRiskClassifier, type MetadataValue, type OffsetPagination, type OperationContext, type OperationDef, type OperationExecutedPayload, type OperationLogStatus, type OperationMetadata, OperationRegistry, type OperationResult, type OperationScope, type OperationalRisk, type PagePagination, type PaginationInput, type Permission, type PolicyContext, type PolicyDecision, PolicyEngine, type PolicyEvaluationResult, type PolicyProvider, type PolicyRule, type PolicyRuleResult, type PolicyTriggeredPayload, type PolicyViolation, type PolicyViolationFilter, type QueryInput, RbacEngine, type RbacPolicy, type RecordAuditInput, type RelationDiffChange, type RelationDiffChangeKind, type RelationDisplayConfig, type RelationEndpoint, type RelationIntrospectionSchema, type RelationMetadata, type RelationSchema, type RelationType, ReportGenerator, type RequestConfirmationInput, type ResourceRef, type RiskClassificationInput, type RiskClassifier, type Role, type SchemaValidationError, type SchemaValidationResult, type SearchConfig, type SearchInput, type SnapshotRepository, type SoftDeleteConfig, type SortDescriptor, type SortDirection, type StructuredLogEntry, type StructuredLogger, type YamlParser, createMaestro, createMaestroFromIntrospection, createMaestroHttpHandlers, detectDisplayField, generateAllConfigs, generateCorrelationId, generateEntityConfig, generateRelationConfig, humanizeFieldName, inferFieldType, isSearchCandidate, isSoftDeleteCandidate, isTimestampField, loadMaestroConfig, mergeIntrospectionWithOverrides, parseQueryInput, tableNameToEntityId, tableNameToLabel, validateMaestroConfig };