@govish/shared-services 1.0.0

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.
@@ -0,0 +1,109 @@
1
+ import { Request } from 'express';
2
+ import { SharedServicesDependencies } from '../types/dependencies';
3
+ /**
4
+ * Audit event types
5
+ */
6
+ export declare enum AuditEventType {
7
+ LOGIN_SUCCESS = "login_success",
8
+ LOGIN_FAILED = "login_failed",
9
+ LOGIN_NOT_PERMITTED = "login_not_permitted",
10
+ LOGOUT = "logout",
11
+ TOKEN_GENERATED = "token_generated",
12
+ OFFICER_RETRIEVED = "officer_retrieved",
13
+ OFFICERS_LISTED = "officers_listed",
14
+ DEVICE_RETRIEVED = "device_retrieved",
15
+ DEVICES_LISTED = "devices_listed",
16
+ ARREST_CREATED = "arrest_created",
17
+ ARREST_UPDATED = "arrest_updated",
18
+ ARREST_DELETED = "arrest_deleted",
19
+ ARREST_RETRIEVED = "arrest_retrieved",
20
+ ARRESTS_LISTED = "arrests_listed",
21
+ ARREST_OB_GENERATED = "arrest_ob_generated",
22
+ ENDPOINT_ACCESSED = "endpoint_accessed",
23
+ UNAUTHORIZED_ACCESS = "unauthorized_access",
24
+ FORBIDDEN_ACCESS = "forbidden_access"
25
+ }
26
+ export interface AuditEventPayload {
27
+ timestamp: string;
28
+ microservice: string;
29
+ event_type: AuditEventType;
30
+ endpoint: string;
31
+ method: string;
32
+ path: string;
33
+ query_params?: Record<string, any>;
34
+ request_body?: any;
35
+ response_status?: number;
36
+ ip_address?: string;
37
+ user_agent?: string;
38
+ user_id?: number;
39
+ user_type?: 'officer' | 'device' | 'both' | 'api_key' | 'microservice';
40
+ officer_id?: number;
41
+ officer_name?: string;
42
+ officer_service_number?: string;
43
+ officer_email?: string;
44
+ device_id?: number;
45
+ device_device_id?: string;
46
+ api_key_id?: number;
47
+ authenticated_microservice?: string;
48
+ arrest_id?: number;
49
+ ob_number?: string;
50
+ sync_id?: any;
51
+ iprs_id?: number;
52
+ arresting_officer_id?: number;
53
+ arresting_station_id?: number;
54
+ sub_module_id?: number;
55
+ duration_ms?: number;
56
+ error_message?: string;
57
+ error_code?: string;
58
+ error_stack?: string;
59
+ [key: string]: any;
60
+ }
61
+ export declare class AuditService {
62
+ private logger;
63
+ private kafkaProducer?;
64
+ private isProducerConnected?;
65
+ private serverName?;
66
+ private auditTopic?;
67
+ private enableDebugLogs;
68
+ private internalProducer?;
69
+ private internalKafkaClient?;
70
+ private isInternalConnection;
71
+ private connectionAttempted;
72
+ constructor(deps: SharedServicesDependencies);
73
+ /**
74
+ * Initialize internal Kafka connection from brokers
75
+ */
76
+ private initializeInternalKafkaConnection;
77
+ /**
78
+ * Debug log helper - only logs if debug is enabled
79
+ */
80
+ private debugLog;
81
+ /**
82
+ * Debug error helper - only logs if debug is enabled
83
+ */
84
+ private debugError;
85
+ /**
86
+ * Ensure producer is connected (for internal connections)
87
+ */
88
+ private ensureConnected;
89
+ /**
90
+ * Send audit event to Kafka
91
+ */
92
+ logAuditEvent(req: Request, payload: Partial<AuditEventPayload>): Promise<void>;
93
+ /**
94
+ * Determine event type based on request path and method
95
+ */
96
+ static determineEventType(req: Request): AuditEventType;
97
+ /**
98
+ * Log endpoint access (called from middleware)
99
+ */
100
+ logEndpointAccess(req: Request): Promise<void>;
101
+ /**
102
+ * Log endpoint access with response status
103
+ */
104
+ logEndpointAccessWithResponse(req: Request, res: any, startTime: number): Promise<void>;
105
+ /**
106
+ * Extract and add arrest-specific information to audit payload
107
+ */
108
+ addArrestInformation(req: Request, auditPayload: AuditEventPayload, payload: Partial<AuditEventPayload>): void;
109
+ }