import { createApi, createLoggerMiddleware, createTransformerMiddleware, } from "@simple-api/core"; import { authMiddleware, refreshMiddleware } from "./api-middlewares"; // Trailing slash is essential for relative path resolution export const BASE_URL = "https://api.yaltopiaticket.com/"; /** * Central API client using simple-api */ export const api = createApi({ baseUrl: BASE_URL, middleware: [ createLoggerMiddleware(), createTransformerMiddleware(), refreshMiddleware, ], services: { notifications: { middleware: [authMiddleware], endpoints: { getAll: { method: "GET", path: "notifications" }, settings: { method: "GET", path: "notifications/settings" }, update: { method: "PUT", path: "notifications/settings" }, }, }, news: { middleware: [authMiddleware], endpoints: { getAll: { method: "GET", path: "news" }, getLatest: { method: "GET", path: "news/latest" }, }, }, auth: { middleware: [authMiddleware], endpoints: { login: { method: "POST", path: "auth/login" }, register: { method: "POST", path: "auth/login-or-register-owner" }, refresh: { method: "POST", path: "auth/refresh" }, logout: { method: "POST", path: "auth/logout" }, profile: { method: "GET", path: "auth/profile" }, googleMobile: { method: "POST", path: "auth/google/mobile" }, }, }, invoices: { middleware: [authMiddleware], endpoints: { stats: { method: "GET", path: "invoices/stats" }, getAll: { method: "GET", path: "invoices" }, getById: { method: "GET", path: "invoices/:id" }, }, }, users: { middleware: [authMiddleware], endpoints: { me: { method: "GET", path: "users/me" }, getAll: { method: "GET", path: "users" }, updateProfile: { method: "PUT", path: "users/me" }, create: { method: "POST", path: "auth/register" }, }, }, company: { middleware: [authMiddleware], endpoints: { get: { method: "GET", path: "company" }, }, }, scan: { middleware: [authMiddleware], endpoints: { invoice: { method: "POST", path: "scan/invoice" }, }, }, payments: { middleware: [authMiddleware], endpoints: { getAll: { method: "GET", path: "payments" }, }, }, paymentRequests: { middleware: [authMiddleware], endpoints: { create: { method: "POST", path: "payment-requests" }, }, }, proforma: { middleware: [authMiddleware], endpoints: { getAll: { method: "GET", path: "proforma" }, getById: { method: "GET", path: "proforma/:id" }, create: { method: "POST", path: "proforma" }, update: { method: "PUT", path: "proforma/:id" }, }, }, rbac: { middleware: [authMiddleware], endpoints: { roles: { method: "GET", path: "rbac/roles" }, permissions: { method: "GET", path: "rbac/permissions" }, }, }, }, }); export interface AuthResponse { accessToken: string; refreshToken: string; user: any; } // Explicit exports for convenience and to avoid undefined access export const authApi = api.auth; export const newsApi = api.news; export const invoicesApi = api.invoices; export const proformaApi = api.proforma; export const rbacApi = api.rbac;