diff --git a/surfsense_web/lib/apis/chats/chats.api.ts b/surfsense_web/lib/apis/chats/chats.api.ts new file mode 100644 index 000000000..a264f30af --- /dev/null +++ b/surfsense_web/lib/apis/chats/chats.api.ts @@ -0,0 +1 @@ +// Will contain a ChatApiService class that will be used to make API calls \ No newline at end of file diff --git a/surfsense_web/lib/apis/chats/contracts.ts b/surfsense_web/lib/apis/chats/contracts.ts new file mode 100644 index 000000000..c5ced8a4f --- /dev/null +++ b/surfsense_web/lib/apis/chats/contracts.ts @@ -0,0 +1 @@ +// Will contains contracts for all chat related APIs diff --git a/surfsense_web/lib/apis/search-source-connectors.api.ts b/surfsense_web/lib/apis/search-source-connectors.api.ts new file mode 100644 index 000000000..2a9e59301 --- /dev/null +++ b/surfsense_web/lib/apis/search-source-connectors.api.ts @@ -0,0 +1,113 @@ +import { Connector, CreateConnectorRequest } from "@/hooks/use-connectors"; + +export const createConnector = async ( + data: CreateConnectorRequest, + authToken: string +): Promise => { + const response = await fetch( + `${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/search-source-connectors`, + { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${authToken}`, + }, + body: JSON.stringify(data), + } + ); + + if (!response.ok) { + const errorData = await response.json(); + throw new Error(errorData.detail || "Failed to create connector"); + } + + return response.json(); +}; + +export const getConnectors = async ( + skip = 0, + limit = 100, + authToken: string +): Promise => { + const response = await fetch( + `${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/search-source-connectors?skip=${skip}&limit=${limit}`, + { + headers: { + Authorization: `Bearer ${authToken}`, + }, + } + ); + + if (!response.ok) { + const errorData = await response.json(); + throw new Error(errorData.detail || "Failed to fetch connectors"); + } + + return response.json(); +}; + +export const getConnector = async ( + connectorId: number, + authToken: string +): Promise => { + const response = await fetch( + `${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/search-source-connectors/${connectorId}`, + { + headers: { + Authorization: `Bearer ${authToken}`, + }, + } + ); + + if (!response.ok) { + const errorData = await response.json(); + throw new Error(errorData.detail || "Failed to fetch connector"); + } + + return response.json(); +}; + +export const updateConnector = async ( + connectorId: number, + data: CreateConnectorRequest, + authToken: string +): Promise => { + const response = await fetch( + `${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/search-source-connectors/${connectorId}`, + { + method: "PUT", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${authToken}`, + }, + body: JSON.stringify(data), + } + ); + + if (!response.ok) { + const errorData = await response.json(); + throw new Error(errorData.detail || "Failed to update connector"); + } + + return response.json(); +}; + +export const deleteConnector = async ( + connectorId: number, + authToken: string +): Promise => { + const response = await fetch( + `${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/search-source-connectors/${connectorId}`, + { + method: "DELETE", + headers: { + Authorization: `Bearer ${authToken}`, + }, + } + ); + + if (!response.ok) { + const errorData = await response.json(); + throw new Error(errorData.detail || "Failed to delete connector"); + } +};