BankliPlus/forserverbankli/solarbank/frontend/node_modules/.cache/babel-loader/e7ee5a7506914b833a4dd18918a7e25657f5e057ca122cb90b13bd8f0257038d.json
2025-08-13 18:05:26 +02:00

1 line
7.1 KiB
JSON

{"ast":null,"code":"import axios from'axios';// Create an axios instance with default config\nconst api=axios.create({baseURL:process.env.REACT_APP_API_URL||'http://localhost/api',headers:{'Content-Type':'application/json'}});// Add a request interceptor for authentication\napi.interceptors.request.use(config=>{const token=localStorage.getItem('token');if(token){config.headers.Authorization=`Bearer ${token}`;}return config;},error=>Promise.reject(error));// Add a response interceptor for error handling\napi.interceptors.response.use(response=>response,error=>{// Handle specific error cases\nif(error.response){// Server responded with a status code outside of 2xx\nif(error.response.status===401){// Unauthorized - clear token and redirect to login\nlocalStorage.removeItem('token');// window.location.href = '/login';\n}}return Promise.reject(error);});// Device API\nexport const deviceApi={// Get all devices\ngetDevices:params=>api.get('/devices',{params}),// Get a specific device\ngetDevice:id=>api.get(`/devices/${id}`),// Create a new device\ncreateDevice:data=>api.post('/devices',data),// Update a device\nupdateDevice:(id,data)=>api.put(`/devices/${id}`,data),// Delete a device\ndeleteDevice:id=>api.delete(`/devices/${id}`)};// Telemetry API\nexport const telemetryApi={// Get telemetry data for a specific device\ngetDeviceTelemetry:(deviceId,params)=>api.get(`/data/device/${deviceId}`,{params}),// Get latest telemetry data across all devices\ngetLatestTelemetry:params=>api.get('/data/latest',{params}),// Create new telemetry data\ncreateTelemetry:data=>api.post('/data',data)};// Logs API\nexport const logsApi={// Get all logs\ngetLogs:params=>api.get('/logs',{params}),// Create a new log\ncreateLog:data=>api.post('/logs',data),// Delete a log\ndeleteLog:id=>api.delete(`/logs/${id}`)};// Status API\nexport const statusApi={// Get system status\ngetSystemStatus:()=>api.get('/status'),// Get devices status\ngetDevicesStatus:()=>api.get('/status/devices')};export default api;","map":{"version":3,"names":["axios","api","create","baseURL","process","env","REACT_APP_API_URL","headers","interceptors","request","use","config","token","localStorage","getItem","Authorization","error","Promise","reject","response","status","removeItem","deviceApi","getDevices","params","get","getDevice","id","createDevice","data","post","updateDevice","put","deleteDevice","delete","telemetryApi","getDeviceTelemetry","deviceId","getLatestTelemetry","createTelemetry","logsApi","getLogs","createLog","deleteLog","statusApi","getSystemStatus","getDevicesStatus"],"sources":["/home/m3mo/Desktop/temparea/solarbank/frontend/src/services/api.js"],"sourcesContent":["import axios from 'axios';\n\n// Create an axios instance with default config\nconst api = axios.create({\n baseURL: process.env.REACT_APP_API_URL || 'http://localhost/api',\n headers: {\n 'Content-Type': 'application/json',\n },\n});\n\n// Add a request interceptor for authentication\napi.interceptors.request.use(\n (config) => {\n const token = localStorage.getItem('token');\n if (token) {\n config.headers.Authorization = `Bearer ${token}`;\n }\n return config;\n },\n (error) => Promise.reject(error)\n);\n\n// Add a response interceptor for error handling\napi.interceptors.response.use(\n (response) => response,\n (error) => {\n // Handle specific error cases\n if (error.response) {\n // Server responded with a status code outside of 2xx\n if (error.response.status === 401) {\n // Unauthorized - clear token and redirect to login\n localStorage.removeItem('token');\n // window.location.href = '/login';\n }\n }\n return Promise.reject(error);\n }\n);\n\n// Device API\nexport const deviceApi = {\n // Get all devices\n getDevices: (params) => api.get('/devices', { params }),\n \n // Get a specific device\n getDevice: (id) => api.get(`/devices/${id}`),\n \n // Create a new device\n createDevice: (data) => api.post('/devices', data),\n \n // Update a device\n updateDevice: (id, data) => api.put(`/devices/${id}`, data),\n \n // Delete a device\n deleteDevice: (id) => api.delete(`/devices/${id}`),\n};\n\n// Telemetry API\nexport const telemetryApi = {\n // Get telemetry data for a specific device\n getDeviceTelemetry: (deviceId, params) => api.get(`/data/device/${deviceId}`, { params }),\n \n // Get latest telemetry data across all devices\n getLatestTelemetry: (params) => api.get('/data/latest', { params }),\n \n // Create new telemetry data\n createTelemetry: (data) => api.post('/data', data),\n};\n\n// Logs API\nexport const logsApi = {\n // Get all logs\n getLogs: (params) => api.get('/logs', { params }),\n \n // Create a new log\n createLog: (data) => api.post('/logs', data),\n \n // Delete a log\n deleteLog: (id) => api.delete(`/logs/${id}`),\n};\n\n// Status API\nexport const statusApi = {\n // Get system status\n getSystemStatus: () => api.get('/status'),\n \n // Get devices status\n getDevicesStatus: () => api.get('/status/devices'),\n};\n\nexport default api;\n"],"mappings":"AAAA,MAAO,CAAAA,KAAK,KAAM,OAAO,CAEzB;AACA,KAAM,CAAAC,GAAG,CAAGD,KAAK,CAACE,MAAM,CAAC,CACvBC,OAAO,CAAEC,OAAO,CAACC,GAAG,CAACC,iBAAiB,EAAI,sBAAsB,CAChEC,OAAO,CAAE,CACP,cAAc,CAAE,kBAClB,CACF,CAAC,CAAC,CAEF;AACAN,GAAG,CAACO,YAAY,CAACC,OAAO,CAACC,GAAG,CACzBC,MAAM,EAAK,CACV,KAAM,CAAAC,KAAK,CAAGC,YAAY,CAACC,OAAO,CAAC,OAAO,CAAC,CAC3C,GAAIF,KAAK,CAAE,CACTD,MAAM,CAACJ,OAAO,CAACQ,aAAa,CAAG,UAAUH,KAAK,EAAE,CAClD,CACA,MAAO,CAAAD,MAAM,CACf,CAAC,CACAK,KAAK,EAAKC,OAAO,CAACC,MAAM,CAACF,KAAK,CACjC,CAAC,CAED;AACAf,GAAG,CAACO,YAAY,CAACW,QAAQ,CAACT,GAAG,CAC1BS,QAAQ,EAAKA,QAAQ,CACrBH,KAAK,EAAK,CACT;AACA,GAAIA,KAAK,CAACG,QAAQ,CAAE,CAClB;AACA,GAAIH,KAAK,CAACG,QAAQ,CAACC,MAAM,GAAK,GAAG,CAAE,CACjC;AACAP,YAAY,CAACQ,UAAU,CAAC,OAAO,CAAC,CAChC;AACF,CACF,CACA,MAAO,CAAAJ,OAAO,CAACC,MAAM,CAACF,KAAK,CAAC,CAC9B,CACF,CAAC,CAED;AACA,MAAO,MAAM,CAAAM,SAAS,CAAG,CACvB;AACAC,UAAU,CAAGC,MAAM,EAAKvB,GAAG,CAACwB,GAAG,CAAC,UAAU,CAAE,CAAED,MAAO,CAAC,CAAC,CAEvD;AACAE,SAAS,C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