| | |
| | |
| | |
| |
|
| | const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || ""; |
| |
|
| | |
| | |
| | |
| | function getAuthHeaders() { |
| | const token = localStorage.getItem("auth_token"); |
| | return token ? { Authorization: `Bearer ${token}` } : {}; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | export async function extractDocument(file, keyFields = "") { |
| | const formData = new FormData(); |
| | formData.append("file", file); |
| | if (keyFields && keyFields.trim()) { |
| | formData.append("key_fields", keyFields.trim()); |
| | } |
| |
|
| | const response = await fetch(`${API_BASE_URL}/api/extract`, { |
| | method: "POST", |
| | headers: getAuthHeaders(), |
| | body: formData, |
| | }); |
| |
|
| | if (!response.ok) { |
| | const errorData = await response.json().catch(() => ({ |
| | error: `HTTP ${response.status}: ${response.statusText}`, |
| | })); |
| | throw new Error(errorData.error || errorData.detail || "Extraction failed"); |
| | } |
| |
|
| | return await response.json(); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | export async function getHistory() { |
| | const response = await fetch(`${API_BASE_URL}/api/history`, { |
| | headers: getAuthHeaders(), |
| | }); |
| |
|
| | if (!response.ok) { |
| | const errorData = await response.json().catch(() => ({ |
| | error: `HTTP ${response.status}: ${response.statusText}`, |
| | })); |
| | throw new Error(errorData.error || errorData.detail || "Failed to fetch history"); |
| | } |
| |
|
| | return await response.json(); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | export async function getExtractionById(extractionId) { |
| | const response = await fetch(`${API_BASE_URL}/api/extraction/${extractionId}`, { |
| | headers: getAuthHeaders(), |
| | }); |
| |
|
| | if (!response.ok) { |
| | const errorData = await response.json().catch(() => ({ |
| | error: `HTTP ${response.status}: ${response.statusText}`, |
| | })); |
| | throw new Error(errorData.error || errorData.detail || "Failed to fetch extraction"); |
| | } |
| |
|
| | return await response.json(); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | export async function createShareLink(extractionId) { |
| | const response = await fetch(`${API_BASE_URL}/api/share/link`, { |
| | method: "POST", |
| | headers: { |
| | "Content-Type": "application/json", |
| | ...getAuthHeaders(), |
| | }, |
| | body: JSON.stringify({ |
| | extraction_id: extractionId, |
| | }), |
| | }); |
| |
|
| | if (!response.ok) { |
| | const errorData = await response.json().catch(() => ({ |
| | error: `HTTP ${response.status}: ${response.statusText}`, |
| | })); |
| | throw new Error(errorData.error || errorData.detail || "Failed to create share link"); |
| | } |
| |
|
| | return await response.json(); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | export async function shareExtraction(extractionId, recipientEmails) { |
| | |
| | const emailsArray = Array.isArray(recipientEmails) ? recipientEmails : [recipientEmails]; |
| | |
| | const response = await fetch(`${API_BASE_URL}/api/share`, { |
| | method: "POST", |
| | headers: { |
| | "Content-Type": "application/json", |
| | ...getAuthHeaders(), |
| | }, |
| | body: JSON.stringify({ |
| | extraction_id: extractionId, |
| | recipient_emails: emailsArray, |
| | }), |
| | }); |
| |
|
| | if (!response.ok) { |
| | const errorData = await response.json().catch(() => ({ |
| | error: `HTTP ${response.status}: ${response.statusText}`, |
| | })); |
| | throw new Error(errorData.error || errorData.detail || "Failed to share extraction"); |
| | } |
| |
|
| | return await response.json(); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | export async function accessSharedExtraction(token) { |
| | const response = await fetch(`${API_BASE_URL}/api/share/${token}`, { |
| | headers: getAuthHeaders(), |
| | }); |
| |
|
| | if (!response.ok) { |
| | const errorData = await response.json().catch(() => ({ |
| | error: `HTTP ${response.status}: ${response.statusText}`, |
| | })); |
| | throw new Error(errorData.error || errorData.detail || "Failed to access shared extraction"); |
| | } |
| |
|
| | return await response.json(); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | export async function ping() { |
| | const response = await fetch(`${API_BASE_URL}/ping`); |
| | if (!response.ok) { |
| | throw new Error("Backend is not available"); |
| | } |
| | return await response.json(); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | export async function createAPIKey(name) { |
| | const response = await fetch(`${API_BASE_URL}/api/auth/api-key/create`, { |
| | method: "POST", |
| | headers: { |
| | "Content-Type": "application/json", |
| | ...getAuthHeaders(), |
| | }, |
| | body: JSON.stringify({ name }), |
| | }); |
| |
|
| | if (!response.ok) { |
| | const errorData = await response.json().catch(() => ({ |
| | error: `HTTP ${response.status}: ${response.statusText}`, |
| | })); |
| | throw new Error(errorData.error || errorData.detail || "Failed to create API key"); |
| | } |
| |
|
| | return await response.json(); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | export async function listAPIKeys() { |
| | const response = await fetch(`${API_BASE_URL}/api/auth/api-keys`, { |
| | headers: getAuthHeaders(), |
| | }); |
| |
|
| | if (!response.ok) { |
| | const errorData = await response.json().catch(() => ({ |
| | error: `HTTP ${response.status}: ${response.statusText}`, |
| | })); |
| | throw new Error(errorData.error || errorData.detail || "Failed to fetch API keys"); |
| | } |
| |
|
| | return await response.json(); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | export async function deleteAPIKey(keyId) { |
| | const response = await fetch(`${API_BASE_URL}/api/auth/api-key/${keyId}`, { |
| | method: "DELETE", |
| | headers: getAuthHeaders(), |
| | }); |
| |
|
| | if (!response.ok) { |
| | const errorData = await response.json().catch(() => ({ |
| | error: `HTTP ${response.status}: ${response.statusText}`, |
| | })); |
| | throw new Error(errorData.error || errorData.detail || "Failed to delete API key"); |
| | } |
| |
|
| | return await response.json(); |
| | } |
| |
|