Add full monorepo: virtual-banker, backend, frontend, docs, scripts, deployment

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
defiQUG
2026-02-10 11:32:49 -08:00
parent 4d4f8cedad
commit 903c03c65b
815 changed files with 125522 additions and 264 deletions

View File

@@ -0,0 +1,92 @@
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'
export interface ApiResponse<T> {
data: T
meta?: {
pagination?: {
page: number
page_size: number
total: number
total_pages: number
}
}
}
export interface ApiError {
error: {
code: string
message: string
details?: unknown
request_id?: string
}
}
class ApiClient {
private client: AxiosInstance
constructor(baseURL: string = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8080') {
this.client = axios.create({
baseURL,
timeout: 30000,
headers: {
'Content-Type': 'application/json',
},
})
// Request interceptor
this.client.interceptors.request.use(
(config) => {
// Add API key if available
const apiKey = this.getApiKey()
if (apiKey) {
config.headers['X-API-Key'] = apiKey
}
return config
},
(error) => Promise.reject(error)
)
// Response interceptor
this.client.interceptors.response.use(
(response) => response,
(error) => {
// Handle errors
if (error.response) {
const apiError: ApiError = error.response.data
return Promise.reject(apiError)
}
return Promise.reject(error)
}
)
}
private getApiKey(): string | null {
if (typeof window !== 'undefined') {
return localStorage.getItem('api_key')
}
return null
}
async get<T>(url: string, config?: AxiosRequestConfig): Promise<ApiResponse<T>> {
const response: AxiosResponse<ApiResponse<T>> = await this.client.get(url, config)
return response.data
}
async post<T>(url: string, data?: unknown, config?: AxiosRequestConfig): Promise<ApiResponse<T>> {
const response: AxiosResponse<ApiResponse<T>> = await this.client.post(url, data, config)
return response.data
}
async put<T>(url: string, data?: unknown, config?: AxiosRequestConfig): Promise<ApiResponse<T>> {
const response: AxiosResponse<ApiResponse<T>> = await this.client.put(url, data, config)
return response.data
}
async delete<T>(url: string, config?: AxiosRequestConfig): Promise<ApiResponse<T>> {
const response: AxiosResponse<ApiResponse<T>> = await this.client.delete(url, config)
return response.data
}
}
export const apiClient = new ApiClient()