2023-03-23 17:57:11 +00:00
|
|
|
import APIService from "services/api.service";
|
2023-05-05 10:15:38 +00:00
|
|
|
import trackEventServices from "services/track-event.service";
|
|
|
|
|
2023-03-23 17:57:11 +00:00
|
|
|
// types
|
2023-04-18 05:24:45 +00:00
|
|
|
import { IAppIntegration, IImporterService, IWorkspaceIntegration } from "types";
|
2023-03-23 17:57:11 +00:00
|
|
|
|
|
|
|
const { NEXT_PUBLIC_API_BASE_URL } = process.env;
|
|
|
|
|
2023-05-05 10:15:38 +00:00
|
|
|
const trackEvent =
|
|
|
|
process.env.NEXT_PUBLIC_TRACK_EVENTS === "true" || process.env.NEXT_PUBLIC_TRACK_EVENTS === "1";
|
|
|
|
|
2023-04-05 19:21:15 +00:00
|
|
|
class IntegrationService extends APIService {
|
2023-03-23 17:57:11 +00:00
|
|
|
constructor() {
|
|
|
|
super(NEXT_PUBLIC_API_BASE_URL || "http://localhost:8000");
|
|
|
|
}
|
|
|
|
|
2023-04-18 05:24:45 +00:00
|
|
|
async getAppIntegrationsList(): Promise<IAppIntegration[]> {
|
2023-03-23 17:57:11 +00:00
|
|
|
return this.get(`/api/integrations/`)
|
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-04-18 05:24:45 +00:00
|
|
|
async getWorkspaceIntegrationsList(workspaceSlug: string): Promise<IWorkspaceIntegration[]> {
|
2023-03-23 17:57:11 +00:00
|
|
|
return this.get(`/api/workspaces/${workspaceSlug}/workspace-integrations/`)
|
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-04-05 19:21:15 +00:00
|
|
|
async deleteWorkspaceIntegration(workspaceSlug: string, integrationId: string): Promise<any> {
|
|
|
|
return this.delete(
|
|
|
|
`/api/workspaces/${workspaceSlug}/workspace-integrations/${integrationId}/provider/`
|
|
|
|
)
|
|
|
|
.then((res) => res?.data)
|
2023-03-23 17:57:11 +00:00
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-04-05 19:21:15 +00:00
|
|
|
async getImporterServicesList(workspaceSlug: string): Promise<IImporterService[]> {
|
2023-03-23 17:57:11 +00:00
|
|
|
return this.get(`/api/workspaces/${workspaceSlug}/importers/`)
|
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
2023-04-06 10:36:31 +00:00
|
|
|
|
2023-04-17 13:04:18 +00:00
|
|
|
async deleteImporterService(
|
|
|
|
workspaceSlug: string,
|
|
|
|
service: string,
|
|
|
|
importerId: string
|
|
|
|
): Promise<any> {
|
|
|
|
return this.delete(`/api/workspaces/${workspaceSlug}/importers/${service}/${importerId}/`)
|
2023-05-05 10:15:38 +00:00
|
|
|
.then((response) => {
|
|
|
|
const eventName = service === "github" ? "GITHUB_IMPORTER_DELETE" : "JIRA_IMPORTER_DELETE";
|
|
|
|
|
|
|
|
if (trackEvent) trackEventServices.trackImporterEvent(response?.data, eventName);
|
|
|
|
return response?.data;
|
|
|
|
})
|
2023-04-06 10:36:31 +00:00
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
2023-03-23 17:57:11 +00:00
|
|
|
}
|
|
|
|
|
2023-04-05 19:21:15 +00:00
|
|
|
export default new IntegrationService();
|