Skip to content

LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows

4.4 KB
Raw Blame
import { useAxiosPrivate } from "../../../hooks/useAxiosPrivate.js";
import { useSessionStore } from "../../../store/session-store.js";

let options = {};

function apiDeploymentsService() {
  const axiosPrivate = useAxiosPrivate();
  const { sessionDetails } = useSessionStore();
  const path = `/api/v1/unstract/${sessionDetails.orgId.replaceAll('"', "")}`;
  const csrfToken = sessionDetails.csrfToken;

  const requestHeaders = {
    "Content-Type": "application/json",
    "X-CSRFToken": csrfToken,
  };

  return {
    getApiDeploymentsList: (page = 1, pageSize = 10, search = "") => {
      const params = {
        page,
        page_size: pageSize,
      };
      if (search) {
        params.search = search;
      }
      options = {
        url: `${path}/api/deployment/`,
        method: "GET",
        params,
      };
      return axiosPrivate(options);
    },
    createApiDeployment: (record) => {
      options = {
        url: `${path}/api/deployment/`,
        method: "POST",
        headers: requestHeaders,
        data: record,
      };
      return axiosPrivate(options);
    },
    setApiDeploymentActive: (id, isActive) => {
      // Only the flag: the gate admits shared users for an activation-only
      // PATCH, and a full PUT would carry fields they may not change.
      options = {
        url: `${path}/api/deployment/${id}/`,
        method: "PATCH",
        headers: requestHeaders,
        data: { is_active: isActive },
      };
      return axiosPrivate(options);
    },
    updateApiDeployment: (record) => {
      options = {
        url: `${path}/api/deployment/${record?.id}/`,
        method: "PUT",
        headers: requestHeaders,
        data: record,
      };
      return axiosPrivate(options);
    },
    deleteApiDeployment: (id) => {
      options = {
        url: `${path}/api/deployment/${id}/`,
        method: "DELETE",
        headers: requestHeaders,
      };
      return axiosPrivate(options);
    },
    getApiKeys: (id) => {
      options = {
        method: "GET",
        url: `${path}/api/keys/api/${id}/`,
      };
      return axiosPrivate(options);
    },
    createApiKey: (apiId, record) => {
      options = {
        method: "POST",
        url: `${path}/api/keys/api/${apiId}/`,
        headers: requestHeaders,
        data: record,
      };
      return axiosPrivate(options);
    },
    updateApiKey: (keyId, record) => {
      options = {
        method: "PUT",
        url: `${path}/api/keys/${keyId}/`,
        headers: requestHeaders,
        data: record,
      };
      return axiosPrivate(options);
    },
    deleteApiKey: (keyId) => {
      options = {
        method: "DELETE",
        url: `${path}/api/keys/${keyId}/`,
        headers: requestHeaders,
      };
      return axiosPrivate(options);
    },
    downloadPostmanCollection: (id) => {
      options = {
        method: "GET",
        url: `${path}/api/postman_collection/${id}/`,
        responseType: "blob",
      };
      return axiosPrivate(options);
    },
    getDeploymentsByWorkflowId: (workflowId) => {
      options = {
        method: "GET",
        url: `${path}/api/deployment/?workflow=${workflowId}`,
      };
      return axiosPrivate(options);
    },
    getSharedUsers: (id) => {
      options = {
        method: "GET",
        url: `${path}/api/deployment/${id}/users/`,
      };
      return axiosPrivate(options);
    },
    updateSharing: (id, sharedUsers, shareWithEveryone, sharedGroups = []) => {
      options = {
        method: "POST",
        url: `${path}/api/deployment/${id}/share/`,
        headers: requestHeaders,
        data: {
          shared_users: sharedUsers,
          shared_to_org: shareWithEveryone,
          shared_groups: sharedGroups,
        },
      };
      return axiosPrivate(options);
    },
    getAllUsers: () => {
      options = {
        method: "GET",
        url: `${path}/users/`,
      };
      return axiosPrivate(options);
    },
    addCoOwner: (id, userId) => {
      options = {
        method: "POST",
        url: `${path}/api/deployment/${id}/owners/`,
        headers: requestHeaders,
        data: { user_id: userId },
      };
      return axiosPrivate(options);
    },
    removeCoOwner: (id, userId) => {
      options = {
        method: "DELETE",
        url: `${path}/api/deployment/${id}/owners/${userId}/`,
        headers: requestHeaders,
      };
      return axiosPrivate(options);
    },
  };
}

export { apiDeploymentsService };