* Get audit log entries with filtering and pagination
(options: {
workos_organization_id?: string;
action?: string;
resource_type?: string;
limit?: number;
offset?: number;
})
| 1050 | * Get audit log entries with filtering and pagination |
| 1051 | */ |
| 1052 | async getAuditLogs(options: { |
| 1053 | workos_organization_id?: string; |
| 1054 | action?: string; |
| 1055 | resource_type?: string; |
| 1056 | limit?: number; |
| 1057 | offset?: number; |
| 1058 | }): Promise<{ |
| 1059 | entries: Array<{ |
| 1060 | id: string; |
| 1061 | workos_organization_id: string; |
| 1062 | workos_user_id: string; |
| 1063 | action: string; |
| 1064 | resource_type: string; |
| 1065 | resource_id: string | null; |
| 1066 | details: Record<string, unknown>; |
| 1067 | created_at: Date; |
| 1068 | }>; |
| 1069 | total: number; |
| 1070 | }> { |
| 1071 | const pool = getPool(); |
| 1072 | const conditions: string[] = []; |
| 1073 | const params: unknown[] = []; |
| 1074 | let paramIndex = 1; |
| 1075 | |
| 1076 | if (options.workos_organization_id) { |
| 1077 | conditions.push(`workos_organization_id = $${paramIndex}`); |
| 1078 | params.push(options.workos_organization_id); |
| 1079 | paramIndex++; |
| 1080 | } |
| 1081 | |
| 1082 | if (options.action) { |
| 1083 | conditions.push(`action = $${paramIndex}`); |
| 1084 | params.push(options.action); |
| 1085 | paramIndex++; |
| 1086 | } |
| 1087 | |
| 1088 | if (options.resource_type) { |
| 1089 | conditions.push(`resource_type = $${paramIndex}`); |
| 1090 | params.push(options.resource_type); |
| 1091 | paramIndex++; |
| 1092 | } |
| 1093 | |
| 1094 | const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : ''; |
| 1095 | const limit = options.limit || 50; |
| 1096 | const offset = options.offset || 0; |
| 1097 | |
| 1098 | // Get total count |
| 1099 | const countResult = await pool.query( |
| 1100 | `SELECT COUNT(*) as count FROM registry_audit_log ${whereClause}`, |
| 1101 | params |
| 1102 | ); |
| 1103 | const total = parseInt(countResult.rows[0].count, 10); |
| 1104 | |
| 1105 | // Get entries |
| 1106 | const result = await pool.query( |
| 1107 | `SELECT id, workos_organization_id, workos_user_id, action, resource_type, resource_id, details, created_at |
| 1108 | FROM registry_audit_log |
| 1109 | ${whereClause} |
no test coverage detected