// plane imports import { API_BASE_URL } from "@plane/constants"; import type { IFormattedInstanceConfiguration, IInstance, IInstanceAdmin, IInstanceConfiguration, IInstanceInfo, TPage, } from "@plane/types"; // api service import { APIService } from "../api.service"; /** * Service class for managing instance-related operations * Handles retrieval of instance information and changelog * @extends {APIService} */ export class InstanceService extends APIService { /** * Creates an instance of InstanceService * Initializes the service with the base API URL */ constructor() { super(API_BASE_URL); } /** * Retrieves information about the current instance * @returns {Promise} Promise resolving to instance information * @throws {Error} If the API request fails * @remarks This method uses the validateStatus: null option to bypass interceptors for unauthorized errors. */ async info(): Promise { return this.get("/api/instances/", { validateStatus: null }) .then((response) => response.data) .catch((error) => { throw error?.response?.data; }); } /** * Fetches the changelog for the current instance * @returns {Promise} Promise resolving to the changelog page data * @throws {Error} If the API request fails */ async changelog(): Promise { return this.get("/api/instances/changelog/") .then((response) => response.data) .catch((error) => { throw error?.response?.data; }); } /** * Fetches the list of instance admins * @returns {Promise} Promise resolving to an array of instance admins * @throws {Error} If the API request fails * @remarks This method uses the validateStatus: null option to bypass interceptors for unauthorized errors. */ async admins(): Promise { return this.get("/api/instances/admins/", { validateStatus: null }) .then((response) => response.data) .catch((error) => { throw error?.response?.data; }); } /** * Updates the instance information * @param {Partial} data Data to update the instance with * @returns {Promise} Promise resolving to the updated instance information * @throws {Error} If the API request fails */ async update(data: Partial): Promise { return this.patch("/api/instances/", data) .then((response) => response?.data) .catch((error) => { throw error?.response?.data; }); } /** * Fetches the list of instance configurations * @returns {Promise} Promise resolving to an array of instance configurations * @throws {Error} If the API request fails */ async configurations(): Promise { return this.get("/api/instances/configurations/") .then((response) => response.data) .catch((error) => { throw error?.response?.data; }); } /** * Updates the instance configurations * @param {Partial} data Data to update the instance configurations with * @returns {Promise} The updated instance configurations * @throws {Error} If the API request fails */ async updateConfigurations(data: Partial): Promise { return this.patch("/api/instances/configurations/", data) .then((response) => response?.data) .catch((error) => { throw error?.response?.data; }); } /** * Sends a test email to the specified receiver to test SMTP configuration * @param {string} receiverEmail Email address to send the test email to * @returns {Promise} Promise resolving to void * @throws {Error} If the API request fails */ async sendTestEmail(receiverEmail: string): Promise { return this.post("/api/instances/email-credentials-check/", { receiver_email: receiverEmail, }) .then((response) => response?.data) .catch((error) => { throw error?.response?.data; }); } /** * Disables the email configuration * @returns {Promise} Promise resolving to void * @throws {Error} If the API request fails */ async disableEmail(): Promise { return this.delete("/api/instances/configurations/disable-email-feature/") .then((response) => response?.data) .catch((error) => { throw error?.response?.data; }); } }