|
| 1 | +import { z } from 'zod'; |
| 2 | +import { BaseResponseSchema } from './contract.zod'; |
| 3 | + |
| 4 | +/** |
| 5 | + * Authentication Service Protocol |
| 6 | + * |
| 7 | + * Defines the standard API contracts for Identity, Session Management, |
| 8 | + * and Access Control. |
| 9 | + */ |
| 10 | + |
| 11 | +// ========================================== |
| 12 | +// Authentication Types |
| 13 | +// ========================================== |
| 14 | + |
| 15 | +export const AuthProvider = z.enum([ |
| 16 | + 'local', |
| 17 | + 'google', |
| 18 | + 'github', |
| 19 | + 'microsoft', |
| 20 | + 'ldap', |
| 21 | + 'saml' |
| 22 | +]); |
| 23 | + |
| 24 | +export const SessionUserSchema = z.object({ |
| 25 | + id: z.string().describe('User ID'), |
| 26 | + username: z.string().describe('Username'), |
| 27 | + email: z.string().email().describe('Email address'), |
| 28 | + name: z.string().describe('Display name'), |
| 29 | + roles: z.array(z.string()).describe('Assigned role IDs'), |
| 30 | + tenantId: z.string().describe('Current tenant ID'), |
| 31 | + avatar: z.string().optional().describe('Avatar URL'), |
| 32 | + language: z.string().default('en').describe('Preferred language'), |
| 33 | + timezone: z.string().optional().describe('Preferred timezone'), |
| 34 | +}); |
| 35 | + |
| 36 | +// ========================================== |
| 37 | +// Requests |
| 38 | +// ========================================== |
| 39 | + |
| 40 | +export const LoginRequestSchema = z.object({ |
| 41 | + username: z.string().describe('Username or Email'), |
| 42 | + password: z.string().describe('Password credential'), |
| 43 | + type: z.literal('password').default('password'), |
| 44 | +}); |
| 45 | + |
| 46 | +export const RefreshTokenRequestSchema = z.object({ |
| 47 | + refreshToken: z.string().describe('Refresh token'), |
| 48 | +}); |
| 49 | + |
| 50 | +// ========================================== |
| 51 | +// Responses |
| 52 | +// ========================================== |
| 53 | + |
| 54 | +export const SessionResponseSchema = BaseResponseSchema.extend({ |
| 55 | + data: z.object({ |
| 56 | + accessToken: z.string().describe('JWT Access Token'), |
| 57 | + refreshToken: z.string().optional().describe('Refresh Token (if enabled)'), |
| 58 | + expiresIn: z.number().describe('Token expiry in seconds'), |
| 59 | + user: SessionUserSchema.describe('Current user details'), |
| 60 | + }), |
| 61 | +}); |
| 62 | + |
| 63 | +export const UserProfileResponseSchema = BaseResponseSchema.extend({ |
| 64 | + data: SessionUserSchema, |
| 65 | +}); |
0 commit comments