feat: add TypeORM, logger, schemas, hooks and stores

- Add TypeORM integration with data-source, entities and repositories
- Add logger service for structured logging
- Add Zod validation schemas for auth, cleaner and extractor
- Add custom React hooks (useAuth, useCleaner, useExtractor, useValidation)
- Add Zustand stores (useAppStore, useUserStore)
- Add UI components (Button, Modal, Toast)
- Add error types and ErpBrowserManager
- Refactor IPC handlers and services
- Add unit tests for new modules

Co-Authored-By: Claude (glm-5) <noreply@anthropic.com>
This commit is contained in:
Misaka
2026-03-02 23:10:15 +08:00
parent 982fb8fde6
commit a05c8a9037
57 changed files with 5150 additions and 974 deletions

View File

@@ -11,11 +11,60 @@ import { registerResolverHandlers } from './resolver-handler'
import { registerAuthHandlers } from './auth-handler'
import { registerValidationHandlers } from './validation-handler'
import { registerSettingsHandlers } from './settings-handler'
import { createLogger } from '../services/logger'
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
}
/**
* Higher-order function to wrap IPC handlers with consistent error handling
* @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) => {
log.debug(`[${context}] Handler completed successfully`)
return { success: true, data }
})
.catch((error: unknown) => {
const message = getErrorMessage(error)
const code = getErrorCode(error)
if (isBaseError(error)) {
log.error(`[${context}] ${error.name}: ${message}`, { code, cause: error.cause?.message })
} else {
log.error(`[${context}] Error: ${message}`, { code })
}
// Include stack trace in development
if (process.env.NODE_ENV !== 'production' && error instanceof Error) {
log.debug(`[${context}] Stack trace:`, { stack: error.stack })
}
return { success: false, error: message, code }
})
}
/**
* Register all IPC handlers
*/
export function registerIpcHandlers(): void {
log.info('Registering IPC handlers...')
registerFileHandlers()
registerExtractorHandlers()
registerCleanerHandlers()
@@ -24,4 +73,5 @@ export function registerIpcHandlers(): void {
registerAuthHandlers()
registerValidationHandlers()
registerSettingsHandlers()
log.info('All IPC handlers registered')
}