admin/api/orval-client.ts
alisaza e1eaf5eff5 feat: initial ghabilee-admin backoffice app
Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js
app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
2026-09-05 13:12:59 +03:30

29 lines
1001 B
TypeScript

import type { AxiosRequestConfig, AxiosResponse } from 'axios'
import type { ApiResponse } from '@/services/apiResponse'
import axiosInstance from '@/config/axios'
/**
* Adapter used by generated Orval endpoints.
*
* OpenAPI paths include `/api/v1`, while the shared Axios instance already
* uses that prefix in its base URL. Keeping the normalization here lets both
* generated endpoints and the existing hand-written services share the same
* authentication, refresh-token, credentials, and observability interceptors.
*/
export const orvalClient = <T>(config: AxiosRequestConfig, options?: AxiosRequestConfig): Promise<AxiosResponse<ApiResponse<T>>> => {
const url = config.url?.replace(/^\/api\/v1\/?/, '')
return axiosInstance.request<ApiResponse<T>>({
...config,
...options,
url,
headers: {
...(config.headers as Record<string, string> | undefined),
...(options?.headers as Record<string, string> | undefined),
},
})
}
export default orvalClient