bb-plane-fork/packages/services/src/instance/instance.service.ts
Sangeetha 99127ff8e4
[WEB-4479] feat: enable/disable SMTP configuration (#7393)
* feat: api update instance configuration

* chore: add enable_smtp key

* fix: empty string for enable_smtp key

* chore: update email_port and email_from

* fix: handled smtp enable disable

* fix: error handling

* fix: refactor

* fix: removed enabled toast

* fix: refactor

---------

Co-authored-by: gakshita <akshitagoyal1516@gmail.com>
Co-authored-by: Akshita Goyal <36129505+gakshita@users.noreply.github.com>
2025-07-16 01:04:18 +05:30

138 lines
4.5 KiB
TypeScript

// 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<IInstanceInfo>} 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<IInstanceInfo> {
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<TPage>} Promise resolving to the changelog page data
* @throws {Error} If the API request fails
*/
async changelog(): Promise<TPage> {
return this.get("/api/instances/changelog/")
.then((response) => response.data)
.catch((error) => {
throw error?.response?.data;
});
}
/**
* Fetches the list of instance admins
* @returns {Promise<IInstanceAdmin[]>} 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<IInstanceAdmin[]> {
return this.get("/api/instances/admins/", { validateStatus: null })
.then((response) => response.data)
.catch((error) => {
throw error?.response?.data;
});
}
/**
* Updates the instance information
* @param {Partial<IInstance>} data Data to update the instance with
* @returns {Promise<IInstance>} Promise resolving to the updated instance information
* @throws {Error} If the API request fails
*/
async update(data: Partial<IInstance>): Promise<IInstance> {
return this.patch("/api/instances/", data)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
/**
* Fetches the list of instance configurations
* @returns {Promise<IInstanceConfiguration[]>} Promise resolving to an array of instance configurations
* @throws {Error} If the API request fails
*/
async configurations(): Promise<IInstanceConfiguration[]> {
return this.get("/api/instances/configurations/")
.then((response) => response.data)
.catch((error) => {
throw error?.response?.data;
});
}
/**
* Updates the instance configurations
* @param {Partial<IFormattedInstanceConfiguration>} data Data to update the instance configurations with
* @returns {Promise<IInstanceConfiguration[]>} The updated instance configurations
* @throws {Error} If the API request fails
*/
async updateConfigurations(data: Partial<IFormattedInstanceConfiguration>): Promise<IInstanceConfiguration[]> {
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<void>} Promise resolving to void
* @throws {Error} If the API request fails
*/
async sendTestEmail(receiverEmail: string): Promise<void> {
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<void>} Promise resolving to void
* @throws {Error} If the API request fails
*/
async disableEmail(): Promise<void> {
return this.delete("/api/instances/configurations/disable-email-feature/")
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
}