import axios, { AxiosInstance } from 'axios'; type ApiResponse = [string | null, any | null]; declare module 'axios' { export interface AxiosInstance { request(config: AxiosRequestConfig): Promise; get(url: string, config?: AxiosRequestConfig): Promise; delete(url: string, config?: AxiosRequestConfig): Promise; head(url: string, config?: AxiosRequestConfig): Promise; post(url: string, data?: any, config?: AxiosRequestConfig): Promise; put(url: string, data?: any, config?: AxiosRequestConfig): Promise; patch(url: string, data?: any, config?: AxiosRequestConfig): Promise; } } const api = axios.create({ baseURL: 'http://localhost:41337', withCredentials: true }); function onSuccess(response) { return [null, response.data]; } function onError(error) { if (error.response) return [error.response.data.error, null]; if (error.request) return ['Network Error', null]; return ['Unknown Error', null]; } api.interceptors.response.use(onSuccess, onError); const actions = { getBundles: async function getBundles() { return api.get('/bundles'); }, getOffers: async function getOffers() { return api.get('/user/offers'); }, getWants: async function getWants() { return api.get('/want/all'); }, postWantSearch: async function postWantSearch(artist, title) { return api.post('/want/search', { artist, title }); }, postWant: async function postWant(releaseId) { return api.post('/want', { releaseId }); }, postDiscogs: async function postDiscogs(username) { return api.post('/want/discogs', { username }); }, getLogin: async function getLogin() { return api.get('/auth/login') }, postLogin: async function postLogin(email, password) { return api.post('/auth/login', { email, password, // discogs, }); }, postRegister: async function postRegister(email, password) { return api.post('/auth/register', { email, password, }); }, }; export default actions;