import { z } from "zod";
// Configuration schemas
export const AuthConfigSchema = z.discriminatedUnion("type", [
z.object({
type: z.literal("token"),
token: z.string(),
}),
z.object({
type: z.literal("login"),
username: z.string(),
password: z.string(),
loginEndpoint: z.string(),
tokenField: z.string().default("access_token"),
}),
]);
export const ConfigSchema = z.object({
baseUrl: z.string().url(),
swaggerUrl: z.string().url().optional(),
auth: AuthConfigSchema,
timeout: z.number().default(30000),
retries: z.number().default(3),
});
export type Config = z.infer<typeof ConfigSchema>;
export type AuthConfig = z.infer<typeof AuthConfigSchema>;
// API Response types
export interface ApiResponse<T = any> {
data: T;
status: number;
statusText: string;
headers: Record<string, string>;
}
// Swagger/OpenAPI types
export interface SwaggerEndpoint {
path: string;
method: string;
summary?: string;
description?: string;
parameters?: SwaggerParameter[];
requestBody?: SwaggerRequestBody;
responses?: Record<string, SwaggerResponse>;
}
export interface SwaggerParameter {
name: string;
in: "query" | "path" | "header" | "cookie";
required?: boolean;
schema?: any;
description?: string;
}
export interface SwaggerRequestBody {
required?: boolean;
content?: Record<string, any>;
description?: string;
}
export interface SwaggerResponse {
description: string;
content?: Record<string, any>;
}
// Authentication state
export interface AuthState {
token?: string;
expiresAt?: Date;
isAuthenticated: boolean;
}
// Request options
export interface RequestOptions {
method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
path: string;
params?: Record<string, any>;
body?: any;
headers?: Record<string, string>;
}