Files
BIPMaterialManager/src/main/ipc/index.ts
google-labs-jules[bot] a020ee537d feat: Add Report Viewer Dialog to Cleaner Page
Added a new "View Reports" button to the CleanerPage which opens a new ReportViewerDialog. This dialog lists all available execution reports stored in S3 for the current user, or for all users if the current user is an admin.
The reports are downloaded as Markdown and rendered using react-markdown.
Added three new IPC channels to fetch and download reports using the existing RustfsService and S3Client.

Co-authored-by: luwamgere15-crypto <255338376+luwamgere15-crypto@users.noreply.github.com>
2026-03-17 23:03:13 +00:00

110 lines
3.3 KiB
TypeScript

/**
* IPC Handler registration
* Centralized registration for all IPC handlers
*/
import { registerFileHandlers } from './file-handler'
import { registerExtractorHandlers } from './extractor-handler'
import { registerCleanerHandlers } from './cleaner-handler'
import { registerDatabaseHandlers } from './database-handler'
import { registerResolverHandlers } from './resolver-handler'
import { registerAuthHandlers } from './auth-handler'
import { registerValidationHandlers } from './validation-handler'
import { registerSettingsHandlers } from './settings-handler'
import { registerMaterialTypeHandlers } from './material-type-handler'
import { registerUserErpConfigHandlers } from './user-erp-config-handler'
import { registerLoggerHandlers } from './logger-handler'
import { registerReportHandlers } from './report-handler'
import { createLogger, logError } from '../services/logger'
import { serializeError, sanitizeError } from '../services/logger/error-utils'
import { getErrorMessage, getErrorCode, isBaseError } from '../types/errors'
const log = createLogger('IPC')
/**
* Standard result type for all IPC handlers
*/
export interface IpcResult<T = unknown> {
success: boolean
data?: T
error?: string
code?: string
}
export function ok<T>(data: T): IpcResult<T> {
return { success: true, data }
}
export function fail<T = unknown>(error: string, code?: string): IpcResult<T> {
return { success: false, error, code }
}
/**
* Higher-order function to wrap IPC handlers with consistent error handling
* Enhanced to capture full error context including stack traces
* @param handler - The async handler function to wrap
* @param context - The context name for logging
* @returns A wrapped handler that returns IpcResult
*/
export function withErrorHandling<T>(
handler: () => Promise<T>,
context: string
): Promise<IpcResult<T>> {
return handler()
.then((data): IpcResult<T> => {
log.debug(`[${context}] Handler completed successfully`)
return ok(data)
})
.catch((error: unknown) => {
const message = getErrorMessage(error)
const code = getErrorCode(error)
// Serialize error with full details
if (process.env.NODE_ENV === 'production') {
sanitizeError(serializeError(error))
} else {
serializeError(error)
}
if (isBaseError(error)) {
logError(log, `[${context}] ${error.name}`, error, {
code,
cause: (error as any).cause?.message,
handler: context
})
} else {
logError(log, `[${context}] Error`, error, {
code,
handler: context
})
}
// Include stack trace in development
if (process.env.NODE_ENV !== 'production' && error instanceof Error) {
log.debug(`[${context}] Stack trace: ${error.stack}`)
}
return fail<T>(message, code)
})
}
/**
* Register all IPC handlers
*/
export function registerIpcHandlers(): void {
log.info('Registering IPC handlers...')
registerFileHandlers()
registerExtractorHandlers()
registerCleanerHandlers()
registerDatabaseHandlers()
registerResolverHandlers()
registerAuthHandlers()
registerValidationHandlers()
registerSettingsHandlers()
registerMaterialTypeHandlers()
registerUserErpConfigHandlers()
registerLoggerHandlers()
registerReportHandlers()
log.info('All IPC handlers registered')
}