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:
45
src/main/schemas/auth.schema.ts
Normal file
45
src/main/schemas/auth.schema.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Zod schemas for Authentication module validation
|
||||
*/
|
||||
|
||||
import { z } from 'zod'
|
||||
|
||||
/**
|
||||
* Schema for login request validation
|
||||
*/
|
||||
export const LoginRequestSchema = z.object({
|
||||
username: z.string().min(1, 'Username is required'),
|
||||
password: z.string().min(1, 'Password is required')
|
||||
})
|
||||
|
||||
export type LoginRequestZod = z.infer<typeof LoginRequestSchema>
|
||||
|
||||
/**
|
||||
* Schema for user info validation
|
||||
*/
|
||||
export const UserInfoSchema = z.object({
|
||||
id: z.number().int().positive(),
|
||||
username: z.string().min(1),
|
||||
userType: z.enum(['Admin', 'User', 'Guest']),
|
||||
computerName: z.string().optional()
|
||||
})
|
||||
|
||||
export type UserInfoZod = z.infer<typeof UserInfoSchema>
|
||||
|
||||
/**
|
||||
* Validate login request
|
||||
*/
|
||||
export function validateLoginRequest(input: unknown): {
|
||||
success: boolean
|
||||
data?: LoginRequestZod
|
||||
error?: string
|
||||
} {
|
||||
const result = LoginRequestSchema.safeParse(input)
|
||||
if (result.success) {
|
||||
return { success: true, data: result.data }
|
||||
}
|
||||
return {
|
||||
success: false,
|
||||
error: result.error.issues.map((e) => `${e.path.join('.')}: ${e.message}`).join('; ')
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user