diff --git a/package-lock.json b/package-lock.json index bca9abe..6250e50 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16433,7 +16433,6 @@ "resolved": "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.6.0.tgz", "integrity": "sha512-Pp6GSwGP/NrPIrxVFAIkOQeyw8lFenOHijQWkUTrDvrF4ALqylP2C/KCkeS9dpUM3KvYRQhna5vt7IL95+ZQ9w==", "license": "MIT", - "peer": true, "peerDependencies": { "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" } diff --git a/src/main/ipc/auth-handler.ts b/src/main/ipc/auth-handler.ts index d7bcddc..bc5fbe4 100644 --- a/src/main/ipc/auth-handler.ts +++ b/src/main/ipc/auth-handler.ts @@ -15,6 +15,13 @@ import { SessionManager } from '../services/user/session-manager' import { createLogger } from '../services/logger' import { logAudit } from '../services/logger/audit-logger' import type { UserInfo } from '../types/user.types' +import type { + CurrentUserResponse, + LoginRequest, + LoginResponse, + SilentLoginResponse, + UserSelectionResponse +} from '../types/auth-ipc.types' import { IPC_CHANNELS } from '../../shared/ipc-channels' import { ValidationError } from '../types/errors' import { withErrorHandling, type IpcResult } from './index' @@ -22,50 +29,6 @@ import { UpdateService } from '../services/update/update-service' const log = createLogger('AuthHandler') -/** - * Login request - */ -export interface LoginRequest { - username: string - password: string -} - -/** - * Login response - */ -export interface LoginResponse { - success: boolean - userInfo?: UserInfo - error?: string -} - -/** - * Silent login response - */ -export interface SilentLoginResponse { - success: boolean - userInfo?: UserInfo - requiresUserSelection?: boolean // True if admin needs to select a user - error?: string -} - -/** - * User selection response - */ -export interface UserSelectionResponse { - success: boolean - userInfo?: UserInfo - error?: string -} - -/** - * Current user response - */ -export interface CurrentUserResponse { - isAuthenticated: boolean - userInfo?: UserInfo -} - /** * Register IPC handlers for user authentication */ diff --git a/src/main/ipc/index.ts b/src/main/ipc/index.ts index a274a00..f23d39c 100644 --- a/src/main/ipc/index.ts +++ b/src/main/ipc/index.ts @@ -19,19 +19,12 @@ import { registerUpdateHandlers } from './update-handler' import { createLogger, logError } from '../services/logger' import { serializeError, sanitizeError } from '../services/logger/error-utils' import { getErrorMessage, getErrorCode, isBaseError } from '../types/errors' +import type { IpcResult } from '../types/ipc.types' + +export type { IpcResult } from '../types/ipc.types' const log = createLogger('IPC') -/** - * Standard result type for all IPC handlers - */ -export interface IpcResult { - success: boolean - data?: T - error?: string - code?: string -} - export function ok(data: T): IpcResult { return { success: true, data } } diff --git a/src/main/ipc/resolver-handler.ts b/src/main/ipc/resolver-handler.ts index b0f803a..7714745 100644 --- a/src/main/ipc/resolver-handler.ts +++ b/src/main/ipc/resolver-handler.ts @@ -10,38 +10,12 @@ import { ipcMain } from 'electron' import { create, type IDatabaseService } from '../services/database' import { OrderNumberResolver } from '../services/erp/order-resolver' import { createLogger } from '../services/logger' -import type { OrderMapping, ResolutionStats } from '../services/erp/order-resolver' +import type { ResolverInput, ResolverResponse } from '../types/resolver-ipc.types' import { IPC_CHANNELS } from '../../shared/ipc-channels' import { withErrorHandling, type IpcResult } from './index' const log = createLogger('ResolverHandler') -/** - * Resolver input from renderer - */ -export interface ResolverInput { - /** List of order numbers/productionIDs to resolve */ - inputs: string[] -} - -/** - * Resolver response to renderer - */ -export interface ResolverResponse { - /** Whether the resolution was successful */ - success: boolean - /** Resolved order mappings */ - mappings?: OrderMapping[] - /** Valid production order numbers ready for use */ - validOrderNumbers?: string[] - /** Warning messages for invalid inputs */ - warnings?: string[] - /** Resolution statistics */ - stats?: ResolutionStats - /** Error message if failed */ - error?: string -} - /** * Register IPC handlers for order number resolver */ diff --git a/src/main/services/erp/order-resolver.ts b/src/main/services/erp/order-resolver.ts index e1b23e0..a9caa97 100644 --- a/src/main/services/erp/order-resolver.ts +++ b/src/main/services/erp/order-resolver.ts @@ -13,42 +13,14 @@ import type { IDatabaseService } from '../database' import { ConfigManager } from '../config/config-manager' import { createLogger } from '../logger' +import type { + OrderMapping, + OrderNumberType, + ResolutionStats +} from '../../types/order-resolver.types' const log = createLogger('OrderResolver') -/** - * Order mapping result - */ -export interface OrderMapping { - /** Original input from user */ - input: string - /** Recognized productionID (if input matches productionID pattern) */ - productionId?: string - /** Final production order number to use */ - orderNumber?: string - /** Whether the order number was successfully resolved */ - resolved: boolean - /** Error message if resolution failed */ - error?: string -} - -/** - * Order number type recognition result - */ -export type OrderNumberType = 'productionId' | 'orderNumber' | 'unknown' - -/** - * Resolution statistics - */ -export interface ResolutionStats { - totalInputs: number - validOrderNumbers: number - validProductionIds: number - resolvedCount: number - failedCount: number - unknownFormat: number -} - /** * ProductionID pattern: 2 digits + 1 letter + 1-6 digits * Examples: 22A1, 22A123, 26B10617 diff --git a/src/main/types/auth-ipc.types.ts b/src/main/types/auth-ipc.types.ts new file mode 100644 index 0000000..376c480 --- /dev/null +++ b/src/main/types/auth-ipc.types.ts @@ -0,0 +1,30 @@ +import type { UserInfo } from './user.types' + +export interface LoginRequest { + username: string + password: string +} + +export interface LoginResponse { + success: boolean + userInfo?: UserInfo + error?: string +} + +export interface SilentLoginResponse { + success: boolean + userInfo?: UserInfo + requiresUserSelection?: boolean + error?: string +} + +export interface UserSelectionResponse { + success: boolean + userInfo?: UserInfo + error?: string +} + +export interface CurrentUserResponse { + isAuthenticated: boolean + userInfo?: UserInfo +} diff --git a/src/main/types/ipc-api.types.ts b/src/main/types/ipc-api.types.ts index 98dc291..332c10b 100644 --- a/src/main/types/ipc-api.types.ts +++ b/src/main/types/ipc-api.types.ts @@ -11,7 +11,7 @@ import type { ExportResultItem, ExportResultResponse } from './cleaner.types' -import type { IpcResult } from '../ipc' +import type { IpcResult } from './ipc.types' /** * MySQL connection configuration @@ -176,13 +176,23 @@ export interface ReportAPI { /** * List all reports across all users (Admin only typically) */ - listAll: () => Promise> + listAll: () => Promise< + IpcResult< + { key: string; filename: string; username: string; lastModified?: Date; size?: number }[] + > + > /** * List reports for a specific user * @param username - Username to list reports for */ - listByUser: (username: string) => Promise> + listByUser: ( + username: string + ) => Promise< + IpcResult< + { key: string; filename: string; username: string; lastModified?: Date; size?: number }[] + > + > /** * Download a specific report by key diff --git a/src/main/types/ipc.types.ts b/src/main/types/ipc.types.ts new file mode 100644 index 0000000..bd7ba2f --- /dev/null +++ b/src/main/types/ipc.types.ts @@ -0,0 +1,6 @@ +export interface IpcResult { + success: boolean + data?: T + error?: string + code?: string +} diff --git a/src/main/types/order-resolver.types.ts b/src/main/types/order-resolver.types.ts new file mode 100644 index 0000000..280116e --- /dev/null +++ b/src/main/types/order-resolver.types.ts @@ -0,0 +1,18 @@ +export interface OrderMapping { + input: string + productionId?: string + orderNumber?: string + resolved: boolean + error?: string +} + +export type OrderNumberType = 'productionId' | 'orderNumber' | 'unknown' + +export interface ResolutionStats { + totalInputs: number + validOrderNumbers: number + validProductionIds: number + resolvedCount: number + failedCount: number + unknownFormat: number +} diff --git a/src/main/types/resolver-ipc.types.ts b/src/main/types/resolver-ipc.types.ts new file mode 100644 index 0000000..36c842d --- /dev/null +++ b/src/main/types/resolver-ipc.types.ts @@ -0,0 +1,14 @@ +import type { OrderMapping, ResolutionStats } from './order-resolver.types' + +export interface ResolverInput { + inputs: string[] +} + +export interface ResolverResponse { + success: boolean + mappings?: OrderMapping[] + validOrderNumbers?: string[] + warnings?: string[] + stats?: ResolutionStats + error?: string +} diff --git a/src/preload/index.d.ts b/src/preload/index.d.ts index 496e16b..e170c82 100644 --- a/src/preload/index.d.ts +++ b/src/preload/index.d.ts @@ -1,13 +1,19 @@ -import type { FileAPI, ExtractorAPI, CleanerAPI, DatabaseAPI, ReportAPI } from '../main/types/ipc-api.types' -import type { ResolverInput, ResolverResponse } from '../main/ipc/resolver-handler' +import type { + FileAPI, + ExtractorAPI, + CleanerAPI, + DatabaseAPI, + ReportAPI +} from '../main/types/ipc-api.types' +import type { ResolverInput, ResolverResponse } from '../main/types/resolver-ipc.types' import type { UserInfo } from '../main/types/user.types' import type { + CurrentUserResponse, LoginRequest, LoginResponse, SilentLoginResponse, - UserSelectionResponse, - CurrentUserResponse -} from '../main/ipc/auth-handler' + UserSelectionResponse +} from '../main/types/auth-ipc.types' import type { ValidationRequest, ValidationResponse, @@ -19,7 +25,7 @@ import type { ConnectionTestResult, SaveSettingsResult } from '../main/types/settings.types' -import type { IpcResult } from '../main/ipc' +import type { IpcResult } from '../main/types/ipc.types' import type { LogLevel } from '../shared/ipc-channels' import type { CleanerConfig } from '../main/types/config.schema' import type { diff --git a/src/preload/index.ts b/src/preload/index.ts index 6c32efe..e0bc5b3 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -2,15 +2,15 @@ import { contextBridge, ipcRenderer } from 'electron' import type { MySqlConfig, SqlServerConfig } from '../main/types/ipc-api.types' import type { ExtractorInput, ExtractionProgress } from '../main/types/extractor.types' import type { CleanerInput, CleanerProgress, ExportResultItem } from '../main/types/cleaner.types' -import type { ResolverInput } from '../main/ipc/resolver-handler' -import type { LoginRequest } from '../main/ipc/auth-handler' +import type { ResolverInput } from '../main/types/resolver-ipc.types' +import type { LoginRequest } from '../main/types/auth-ipc.types' import type { UserInfo } from '../main/types/user.types' import type { ValidationRequest, MaterialTypeRecord, MaterialTypeBatchRequest } from '../main/types/validation.types' -import type { IpcResult } from '../main/ipc' +import type { IpcResult } from '../main/types/ipc.types' import { IPC_CHANNELS, type LogLevel } from '../shared/ipc-channels' import type { CleanerConfig } from '../main/types/config.schema' import type { DownloadReleaseRequest, UpdateStatus } from '../main/types/update.types' @@ -234,8 +234,7 @@ const api = { installDownloaded: (): Promise> => invokeIpc(IPC_CHANNELS.UPDATE_INSTALL_DOWNLOADED), onStatusChanged: (callback: (data: UpdateStatus) => void) => { - const subscription = (_event: Electron.IpcRendererEvent, data: UpdateStatus) => - callback(data) + const subscription = (_event: Electron.IpcRendererEvent, data: UpdateStatus) => callback(data) ipcRenderer.on(IPC_CHANNELS.UPDATE_STATUS_CHANGED, subscription) return () => ipcRenderer.removeListener(IPC_CHANNELS.UPDATE_STATUS_CHANGED, subscription) } diff --git a/tsconfig.web.json b/tsconfig.web.json index d376a77..2701133 100644 --- a/tsconfig.web.json +++ b/tsconfig.web.json @@ -5,7 +5,7 @@ "src/renderer/src/**/*", "src/renderer/src/**/*.tsx", "src/preload/*.d.ts", - "src/main/types/*.ts", + "src/main/types/**/*.ts", "src/shared/*.ts" ], "compilerOptions": {