@geekmidas/audit 9.0.2 → 10.0.0-alpha.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 +2 -2
- package/package.json +8 -5
- package/CHANGELOG.md +0 -101
- package/TECHNICAL.md +0 -937
- package/src/Auditor.ts +0 -157
- package/src/DefaultAuditor.ts +0 -141
- package/src/__tests__/CacheAuditStorage.spec.ts +0 -382
- package/src/__tests__/DefaultAuditor.spec.ts +0 -529
- package/src/__tests__/InMemoryAuditStorage.spec.ts +0 -317
- package/src/__tests__/KnexAuditStorage.integration.spec.ts +0 -739
- package/src/__tests__/KyselyAuditStorage.integration.spec.ts +0 -518
- package/src/__tests__/KyselyAuditStorage.spec.ts +0 -443
- package/src/cache.ts +0 -263
- package/src/index.ts +0 -23
- package/src/knex.ts +0 -430
- package/src/kysely.ts +0 -424
- package/src/memory.ts +0 -50
- package/src/storage.ts +0 -203
- package/src/types.ts +0 -154
- package/tsconfig.json +0 -9
package/src/types.ts
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import type { InferStandardSchema } from '@geekmidas/schema';
|
|
2
|
-
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Represents an auditable action with a type and payload.
|
|
6
|
-
* Similar to PublishableMessage in @geekmidas/events.
|
|
7
|
-
*
|
|
8
|
-
* @template TType - The audit type/name (e.g., 'user.created')
|
|
9
|
-
* @template TPayload - The audit payload data
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```typescript
|
|
13
|
-
* type AppAuditAction =
|
|
14
|
-
* | AuditableAction<'user.created', { userId: string; email: string }>
|
|
15
|
-
* | AuditableAction<'user.updated', { userId: string; changes: string[] }>
|
|
16
|
-
* | AuditableAction<'order.placed', { orderId: string; total: number }>;
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
export type AuditableAction<TType extends string, TPayload = unknown> = {
|
|
20
|
-
type: TType;
|
|
21
|
-
payload: TPayload;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Extract the type string from an AuditableAction union.
|
|
26
|
-
*/
|
|
27
|
-
export type ExtractAuditType<T extends AuditableAction<string, unknown>> =
|
|
28
|
-
T extends AuditableAction<infer TType, unknown> ? TType : never;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Extract the payload for a specific audit type from an AuditableAction union.
|
|
32
|
-
*/
|
|
33
|
-
export type ExtractAuditPayload<
|
|
34
|
-
T extends AuditableAction<string, unknown>,
|
|
35
|
-
TType extends ExtractAuditType<T>,
|
|
36
|
-
> = T extends AuditableAction<TType, infer TPayload> ? TPayload : never;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Audit operation types for database auditing.
|
|
40
|
-
*/
|
|
41
|
-
export type AuditOperation = 'INSERT' | 'UPDATE' | 'DELETE' | 'CUSTOM';
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Represents the actor who performed an audited action.
|
|
45
|
-
*/
|
|
46
|
-
export interface AuditActor {
|
|
47
|
-
/** Unique identifier for the actor (user ID, service ID, etc.) */
|
|
48
|
-
id?: string;
|
|
49
|
-
/** Type of actor ('user', 'system', 'service', etc.) */
|
|
50
|
-
type?: string;
|
|
51
|
-
/** Additional actor properties */
|
|
52
|
-
[key: string]: unknown;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Metadata associated with an audit record.
|
|
57
|
-
*/
|
|
58
|
-
export interface AuditMetadata {
|
|
59
|
-
/** Request correlation ID */
|
|
60
|
-
requestId?: string;
|
|
61
|
-
/** Which endpoint was called */
|
|
62
|
-
endpoint?: string;
|
|
63
|
-
/** HTTP method */
|
|
64
|
-
method?: string;
|
|
65
|
-
/** Client IP address */
|
|
66
|
-
ip?: string;
|
|
67
|
-
/** Client user agent */
|
|
68
|
-
userAgent?: string;
|
|
69
|
-
/** Additional metadata */
|
|
70
|
-
[key: string]: unknown;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* A complete audit record representing a tracked action.
|
|
75
|
-
*/
|
|
76
|
-
export interface AuditRecord<TPayload = unknown> {
|
|
77
|
-
/** Unique identifier for this audit record */
|
|
78
|
-
id: string;
|
|
79
|
-
/** Audit type (e.g., 'user.created', 'order.placed') */
|
|
80
|
-
type: string;
|
|
81
|
-
/** Operation type for database audits */
|
|
82
|
-
operation: AuditOperation;
|
|
83
|
-
/** Database table name (for database operations) */
|
|
84
|
-
table?: string;
|
|
85
|
-
/** Entity primary key(s) */
|
|
86
|
-
entityId?: string | Record<string, unknown>;
|
|
87
|
-
/** Previous state (for UPDATE/DELETE) */
|
|
88
|
-
oldValues?: Record<string, unknown>;
|
|
89
|
-
/** New state (for INSERT/UPDATE) */
|
|
90
|
-
newValues?: Record<string, unknown>;
|
|
91
|
-
/** Custom payload (for CUSTOM operations) */
|
|
92
|
-
payload?: TPayload;
|
|
93
|
-
/** When the audit was recorded */
|
|
94
|
-
timestamp: Date;
|
|
95
|
-
/** Who performed the action */
|
|
96
|
-
actor?: AuditActor;
|
|
97
|
-
/** Request context */
|
|
98
|
-
metadata?: AuditMetadata;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Options for manual audit calls.
|
|
103
|
-
*/
|
|
104
|
-
export interface AuditOptions {
|
|
105
|
-
/** Entity primary key(s) for easier querying */
|
|
106
|
-
entityId?: string | Record<string, unknown>;
|
|
107
|
-
/** Database table name */
|
|
108
|
-
table?: string;
|
|
109
|
-
/** Operation type (defaults to 'CUSTOM') */
|
|
110
|
-
operation?: AuditOperation;
|
|
111
|
-
/** Previous state */
|
|
112
|
-
oldValues?: Record<string, unknown>;
|
|
113
|
-
/** New state */
|
|
114
|
-
newValues?: Record<string, unknown>;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Mapped audit definition for declarative auditing.
|
|
119
|
-
* Similar to MappedEvent in @geekmidas/events.
|
|
120
|
-
*/
|
|
121
|
-
export interface MappedAudit<
|
|
122
|
-
TAuditAction extends AuditableAction<string, unknown>,
|
|
123
|
-
TOutput extends StandardSchemaV1 | undefined = undefined,
|
|
124
|
-
> {
|
|
125
|
-
/** The audit type - must be a valid type from the AuditableAction union */
|
|
126
|
-
type: ExtractAuditType<TAuditAction>;
|
|
127
|
-
/** Function to extract payload from the response */
|
|
128
|
-
payload: (
|
|
129
|
-
response: InferStandardSchema<TOutput>,
|
|
130
|
-
) => ExtractAuditPayload<TAuditAction, ExtractAuditType<TAuditAction>>;
|
|
131
|
-
/** Optional condition - only audit if this returns true */
|
|
132
|
-
when?: (response: InferStandardSchema<TOutput>) => boolean;
|
|
133
|
-
/** Optional entity ID extractor for easier querying */
|
|
134
|
-
entityId?: (
|
|
135
|
-
response: InferStandardSchema<TOutput>,
|
|
136
|
-
) => string | Record<string, unknown>;
|
|
137
|
-
/** Optional table name for database association */
|
|
138
|
-
table?: string;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Extract the AuditableAction type from an Auditor.
|
|
143
|
-
*/
|
|
144
|
-
export type ExtractAuditorAction<T> = T extends Auditor<infer A> ? A : never;
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Extract the AuditableAction type from an AuditStorage.
|
|
148
|
-
*/
|
|
149
|
-
export type ExtractStorageAuditAction<T> =
|
|
150
|
-
T extends AuditStorage<infer A> ? A : AuditableAction<string, unknown>;
|
|
151
|
-
|
|
152
|
-
// Forward declaration for Auditor type extraction
|
|
153
|
-
import type { Auditor } from './Auditor';
|
|
154
|
-
import type { AuditStorage } from './storage';
|