Download frontend/src/lib/api/client.js from FordAI/hss-pos: direct link, hf CLI and curl.
- Browser
- Download file 10.1 kB
-
https://huggingface.co/spaces/FordAI/hss-pos/resolve/main/frontend/src/lib/api/client.js
- Command line
-
hf download hf://spaces/FordAI/hss-pos/frontend/src/lib/api/client.js
-
curl -L -o client.js https://huggingface.co/spaces/FordAI/hss-pos/resolve/main/frontend/src/lib/api/client.js
10.1 kB
| import axios from 'axios'; | |
| const API_BASE = '/api/v1'; | |
| const api = axios.create({ | |
| baseURL: API_BASE, | |
| timeout: 15000, | |
| headers: { | |
| 'Content-Type': 'application/json' | |
| } | |
| }); | |
| // Request interceptor - attach JWT token | |
| api.interceptors.request.use( | |
| (config) => { | |
| const token = localStorage.getItem('pos_token'); | |
| if (token) { | |
| config.headers.Authorization = `Bearer ${token}`; | |
| } | |
| return config; | |
| }, | |
| (error) => Promise.reject(error) | |
| ); | |
| // Response interceptor - handle 401, extract data | |
| api.interceptors.response.use( | |
| (response) => response.data, | |
| (error) => { | |
| if (error.response?.status === 401) { | |
| localStorage.removeItem('pos_token'); | |
| localStorage.removeItem('pos_user'); | |
| if (typeof window !== 'undefined' && !window.location.pathname.includes('/login')) { | |
| window.location.href = '/login'; | |
| } | |
| } | |
| const message = error.response?.data?.error || error.message || 'Something went wrong'; | |
| return Promise.reject(new Error(message)); | |
| } | |
| ); | |
| // ββ Auth ββ | |
| export const auth = { | |
| login: (username, password) => api.post('/auth/login', { username, password }), | |
| pinLogin: (pin) => api.post('/auth/pin-login', { pin }), | |
| changePassword: (oldPassword, newPassword) => | |
| api.post('/auth/change-password', { old_password: oldPassword, new_password: newPassword }) | |
| }; | |
| // ββ Users ββ | |
| export const users = { | |
| list: (params) => api.get('/users', { params }), | |
| get: (id) => api.get(`/users/${id}`), | |
| create: (data) => api.post('/users', data), | |
| update: (id, data) => api.put(`/users/${id}`, data), | |
| delete: (id) => api.delete(`/users/${id}`), | |
| roles: () => api.get('/roles') | |
| }; | |
| // ββ Categories ββ | |
| export const categories = { | |
| list: () => api.get('/categories'), | |
| get: (id) => api.get(`/categories/${id}`), | |
| create: (data) => api.post('/categories', data), | |
| update: (id, data) => api.put(`/categories/${id}`, data), | |
| delete: (id) => api.delete(`/categories/${id}`) | |
| }; | |
| // ββ Products ββ | |
| export const products = { | |
| list: (params) => api.get('/products', { params }), | |
| get: (id) => api.get(`/products/${id}`), | |
| create: (data) => api.post('/products', data), | |
| update: (id, data) => api.put(`/products/${id}`, data), | |
| delete: (id) => api.delete(`/products/${id}`), | |
| menu: () => api.get('/menu') | |
| }; | |
| // ββ Modifier Groups ββ | |
| export const modifierGroups = { | |
| list: () => api.get('/modifier-groups'), | |
| get: (id) => api.get(`/modifier-groups/${id}`), | |
| create: (data) => api.post('/modifier-groups', data), | |
| update: (id, data) => api.put(`/modifier-groups/${id}`, data), | |
| delete: (id) => api.delete(`/modifier-groups/${id}`) | |
| }; | |
| // ββ Orders ββ | |
| export const orders = { | |
| create: (data) => api.post('/orders', data), | |
| list: (params) => api.get('/orders', { params }), | |
| get: (id) => api.get(`/orders/${id}`), | |
| active: () => api.get('/orders/active'), | |
| addItems: (id, data) => api.post(`/orders/${id}/items`, data), | |
| discount: (id, data) => api.post(`/orders/${id}/discount`, data), | |
| payment: (id, data) => api.post(`/orders/${id}/payment`, data), | |
| void: (id, data) => api.post(`/orders/${id}/void`, data), | |
| reprint: (id) => api.post(`/orders/${id}/reprint`), | |
| splitBill: (id, data) => api.post(`/orders/${id}/split`, data), | |
| mergeTables: (data) => api.post('/orders/merge-tables', data), | |
| transferTable: (id, data) => api.post(`/orders/${id}/transfer-table`, data), | |
| cancelItem: (orderId, itemId, data) => api.patch(`/orders/${orderId}/items/${itemId}/cancel`, data) | |
| }; | |
| // ββ KOT ββ | |
| export const kots = { | |
| list: (params) => api.get('/kots', { params }), | |
| kds: (params) => api.get('/kots/kds', { params }), | |
| history: (params) => api.get('/kots/history', { params }), | |
| updateStatus: (id, data) => api.patch(`/kots/${id}/status`, data), | |
| cancelItem: (kotId, itemId, data) => api.post(`/kots/${kotId}/cancel-item`, data), | |
| markItemReady: (kotId, itemId) => api.patch(`/kots/${kotId}/items/${itemId}/ready`), | |
| stats: () => api.get('/kots/stats') | |
| }; | |
| // ββ Tables ββ | |
| export const tables = { | |
| list: (params) => api.get('/tables', { params }), | |
| get: (id) => api.get(`/tables/${id}`), | |
| create: (data) => api.post('/tables', data), | |
| update: (id, data) => api.put(`/tables/${id}`, data), | |
| delete: (id) => api.delete(`/tables/${id}`), | |
| updateStatus: (id, data) => api.patch(`/tables/${id}/status`, data), | |
| overview: () => api.get('/tables/overview'), | |
| sections: { | |
| list: () => api.get('/tables/sections'), | |
| create: (data) => api.post('/tables/sections', data), | |
| update: (id, data) => api.put(`/tables/sections/${id}`, data), | |
| delete: (id) => api.delete(`/tables/sections/${id}`) | |
| } | |
| }; | |
| // ββ Inventory ββ | |
| export const inventory = { | |
| list: (params) => api.get('/inventory', { params }), | |
| get: (id) => api.get(`/inventory/${id}`), | |
| create: (data) => api.post('/inventory', data), | |
| update: (id, data) => api.put(`/inventory/${id}`, data), | |
| delete: (id) => api.delete(`/inventory/${id}`), | |
| addMovement: (id, data) => api.post(`/inventory/${id}/movements`, data), | |
| movements: (id, params) => api.get(`/inventory/${id}/movements`, { params }), | |
| lowStock: () => api.get('/inventory/low-stock') | |
| }; | |
| // ββ Recipes ββ | |
| export const recipes = { | |
| list: (params) => api.get('/recipes', { params }), | |
| get: (id) => api.get(`/recipes/${id}`), | |
| create: (data) => api.post('/recipes', data), | |
| update: (id, data) => api.put(`/recipes/${id}`, data), | |
| delete: (id) => api.delete(`/recipes/${id}`) | |
| }; | |
| // ββ Vendors ββ | |
| export const vendors = { | |
| list: (params) => api.get('/vendors', { params }), | |
| get: (id) => api.get(`/vendors/${id}`), | |
| create: (data) => api.post('/vendors', data), | |
| update: (id, data) => api.put(`/vendors/${id}`, data), | |
| delete: (id) => api.delete(`/vendors/${id}`) | |
| }; | |
| // ββ Purchase Orders ββ | |
| export const purchaseOrders = { | |
| list: (params) => api.get('/purchase-orders', { params }), | |
| get: (id) => api.get(`/purchase-orders/${id}`), | |
| create: (data) => api.post('/purchase-orders', data), | |
| update: (id, data) => api.put(`/purchase-orders/${id}`, data), | |
| receive: (id, data) => api.post(`/purchase-orders/${id}/receive`, data) | |
| }; | |
| // ββ Expenses ββ | |
| export const expenses = { | |
| list: (params) => api.get('/expenses', { params }), | |
| get: (id) => api.get(`/expenses/${id}`), | |
| create: (data) => api.post('/expenses', data), | |
| update: (id, data) => api.put(`/expenses/${id}`, data), | |
| delete: (id) => api.delete(`/expenses/${id}`), | |
| summary: (params) => api.get('/expenses/summary', { params }) | |
| }; | |
| // ββ Customers ββ | |
| export const customers = { | |
| list: (params) => api.get('/customers', { params }), | |
| get: (id) => api.get(`/customers/${id}`), | |
| create: (data) => api.post('/customers', data), | |
| update: (id, data) => api.put(`/customers/${id}`, data), | |
| delete: (id) => api.delete(`/customers/${id}`), | |
| search: (q) => api.get('/customers/search', { params: { q } }), | |
| orders: (id, params) => api.get(`/customers/${id}/orders`, { params }), | |
| loyalty: (id, data) => api.post(`/customers/${id}/loyalty`, data) | |
| }; | |
| // ββ Reports ββ | |
| export const reports = { | |
| dashboard: (params) => api.get('/reports/sales/dashboard', { params }), | |
| sales: (params) => api.get('/reports/sales', { params }), | |
| gst: (params) => api.get('/reports/gst', { params }), | |
| items: (params) => api.get('/reports/items', { params }), | |
| categories: (params) => api.get('/reports/categories', { params }), | |
| captains: (params) => api.get('/reports/captain', { params }), | |
| kitchen: (params) => api.get('/reports/kitchen', { params }), | |
| leakage: (params) => api.get('/reports/revenue-leakage', { params }), | |
| kot: (params) => api.get('/reports/kot', { params }), | |
| cancelledItems: (params) => api.get('/reports/cancelled-items', { params }), | |
| expenses: (params) => api.get('/reports/expenses', { params }), | |
| inventory: (params) => api.get('/reports/inventory', { params }) | |
| }; | |
| // ββ Settings ββ | |
| export const settings = { | |
| getConfig: () => api.get('/settings/config'), | |
| updateConfig: (data) => api.put('/settings/config', data) | |
| }; | |
| // ββ Printers ββ | |
| export const printers = { | |
| list: () => api.get('/printers'), | |
| get: (id) => api.get(`/printers/${id}`), | |
| create: (data) => api.post('/printers', data), | |
| update: (id, data) => api.put(`/printers/${id}`, data), | |
| delete: (id) => api.delete(`/printers/${id}`), | |
| test: (id) => api.post(`/printers/${id}/test`), | |
| routes: { | |
| list: () => api.get('/print-routes'), | |
| create: (data) => api.post('/print-routes', data), | |
| delete: (id) => api.delete(`/print-routes/${id}`) | |
| }, | |
| jobs: () => api.get('/print-jobs'), | |
| printBill: (orderId) => api.post(`/orders/${orderId}/print-bill`), | |
| printKOT: (kotId) => api.post(`/kots/${kotId}/print`) | |
| }; | |
| // ββ Online Orders (Swiggy/Zomato) ββ | |
| export const onlineOrders = { | |
| list: (params) => api.get('/online-orders', { params }), | |
| counts: () => api.get('/online-orders/counts'), | |
| createManual: (data) => api.post('/online-orders/manual', data), | |
| accept: (id, data) => api.put(`/online-orders/${id}/accept`, data), | |
| reject: (id, data) => api.put(`/online-orders/${id}/reject`, data), | |
| markReady: (id) => api.put(`/online-orders/${id}/ready`), | |
| markPickedUp: (id) => api.put(`/online-orders/${id}/picked-up`), | |
| markDelivered: (id) => api.put(`/online-orders/${id}/delivered`) | |
| }; | |
| // ββ Platform Config ββ | |
| export const platforms = { | |
| list: () => api.get('/platforms'), | |
| get: (id) => api.get(`/platforms/${id}`), | |
| create: (data) => api.post('/platforms', data), | |
| update: (id, data) => api.put(`/platforms/${id}`, data), | |
| delete: (id) => api.delete(`/platforms/${id}`) | |
| }; | |
| // ββ Webhook Logs ββ | |
| export const webhookLogs = { | |
| list: (params) => api.get('/webhook-logs', { params }) | |
| }; | |
| // ββ CRM Campaigns ββ | |
| export const campaigns = { | |
| list: (params) => api.get('/campaigns', { params }), | |
| get: (id) => api.get(`/campaigns/${id}`), | |
| create: (data) => api.post('/campaigns', data), | |
| update: (id, data) => api.put(`/campaigns/${id}`, data), | |
| delete: (id) => api.delete(`/campaigns/${id}`) | |
| }; | |
| // ββ EDC (Card Swipe Machine) ββ | |
| export const edc = { | |
| initiate: (data) => api.post('/edc/initiate', data), | |
| status: (id) => api.get(`/edc/status/${id}`), | |
| cancel: (id) => api.post(`/edc/cancel/${id}`), | |
| config: () => api.get('/edc/config') | |
| }; | |
| export default api; | |