diff --git a/packages/services/src/api.service.ts b/packages/services/src/api.service.ts index 3574424dafd..91d635b0a5e 100644 --- a/packages/services/src/api.service.ts +++ b/packages/services/src/api.service.ts @@ -34,7 +34,19 @@ export abstract class APIService { (error) => { if (error.response && error.response.status === 401) { const currentPath = window.location.pathname; - window.location.replace(`/${currentPath ? `?next_path=${currentPath}` : ``}`); + let prefix = ""; + let updatedPath = currentPath; + + // Check for special path prefixes + if (currentPath.startsWith("/god-mode")) { + prefix = "/god-mode"; + updatedPath = currentPath.replace("/god-mode", ""); + } else if (currentPath.startsWith("/spaces")) { + prefix = "/spaces"; + updatedPath = currentPath.replace("/spaces", ""); + } + + window.location.replace(`${prefix}${updatedPath ? `?next_path=${updatedPath}` : ""}`); } return Promise.reject(error); } diff --git a/packages/services/src/auth/index.ts b/packages/services/src/auth/index.ts index 2ab33e86ab7..340b36856d7 100644 --- a/packages/services/src/auth/index.ts +++ b/packages/services/src/auth/index.ts @@ -1 +1,2 @@ export * from "./auth.service"; +export * from "./sites-auth.service"; diff --git a/packages/services/src/auth/sites-auth.service.ts b/packages/services/src/auth/sites-auth.service.ts new file mode 100644 index 00000000000..638a7b6f261 --- /dev/null +++ b/packages/services/src/auth/sites-auth.service.ts @@ -0,0 +1,49 @@ +import { API_BASE_URL } from "@plane/constants"; +// types +import { IEmailCheckData, IEmailCheckResponse } from "@plane/types"; +// services +import { APIService } from "../api.service"; + +/** + * Service class for handling authentication-related operations for Plane space application + * Provides methods for user authentication, password management, and session handling + * @extends {APIService} + * @remarks This service is only available for plane sites + */ +export class SitesAuthService extends APIService { + /** + * Creates an instance of SitesAuthService + * Initializes with the base API URL + */ + constructor(BASE_URL?: string) { + super(BASE_URL || API_BASE_URL); + } + + /** + * Checks if an email exists in the system + * @param {IEmailCheckData} data - Email data to verify + * @returns {Promise} Response indicating email status + * @throws {Error} Throws response data if the request fails + */ + async emailCheck(data: IEmailCheckData): Promise { + return this.post("/auth/spaces/email-check/", data, { headers: {} }) + .then((response) => response?.data) + .catch((error) => { + throw error?.response?.data; + }); + } + + /** + * Generates a unique code for magic link authentication + * @param {{ email: string }} data - Object containing the email address + * @returns {Promise} Response containing the generated unique code + * @throws {Error} Throws response data if the request fails + */ + async generateUniqueCode(data: { email: string }): Promise { + return this.post("/auth/spaces/magic-generate/", data, { headers: {} }) + .then((response) => response?.data) + .catch((error) => { + throw error?.response?.data; + }); + } +} diff --git a/packages/services/src/cycle/index.ts b/packages/services/src/cycle/index.ts index 5956023cbd1..6f5dbc67998 100644 --- a/packages/services/src/cycle/index.ts +++ b/packages/services/src/cycle/index.ts @@ -2,3 +2,4 @@ export * from "./cycle-analytics.service"; export * from "./cycle-archive.service"; export * from "./cycle-operations.service"; export * from "./cycle.service"; +export * from "./sites-cycle.service"; diff --git a/packages/services/src/cycle/sites-cycle.service.ts b/packages/services/src/cycle/sites-cycle.service.ts new file mode 100644 index 00000000000..99cf361a755 --- /dev/null +++ b/packages/services/src/cycle/sites-cycle.service.ts @@ -0,0 +1,31 @@ +// plane imports +import { API_BASE_URL } from "@plane/constants"; +import { TPublicCycle } from "@plane/types"; +// api service +import { APIService } from "../api.service"; + +/** + * Service class for managing cycles within plane sites application. + * Extends APIService to handle HTTP requests to the cycle-related endpoints. + * @extends {APIService} + * @remarks This service is only available for plane sites + */ +export class SitesCycleService extends APIService { + constructor(BASE_URL?: string) { + super(BASE_URL || API_BASE_URL); + } + + /** + * Retrieves list of cycles for a specific anchor. + * @param anchor - The anchor identifier for the published entity + * @returns {Promise} The list of cycles + * @throws {Error} If the request fails + */ + async list(anchor: string): Promise { + return this.get(`/api/public/anchor/${anchor}/cycles/`) + .then((response) => response?.data) + .catch((error) => { + throw error?.response?.data; + }); + } +} diff --git a/space/core/services/file-upload.service.ts b/packages/services/src/file/file-upload.service.ts similarity index 55% rename from space/core/services/file-upload.service.ts rename to packages/services/src/file/file-upload.service.ts index 09e95f3c0fa..a2e5ce5e6ea 100644 --- a/space/core/services/file-upload.service.ts +++ b/packages/services/src/file/file-upload.service.ts @@ -1,7 +1,12 @@ import axios from "axios"; -// services -import { APIService } from "@/services/api.service"; +// api service +import { APIService } from "../api.service"; +/** + * Service class for handling file upload operations + * Handles file uploads + * @extends {APIService} + */ export class FileUploadService extends APIService { private cancelSource: any; @@ -9,7 +14,17 @@ export class FileUploadService extends APIService { super(""); } - async uploadFile(url: string, data: FormData): Promise { + /** + * Uploads a file to the specified signed URL + * @param {string} url - The URL to upload the file to + * @param {FormData} data - The form data to upload + * @returns {Promise} Promise resolving to void + * @throws {Error} If the request fails + */ + async uploadFile( + url: string, + data: FormData, + ): Promise { this.cancelSource = axios.CancelToken.source(); return this.post(url, data, { headers: { @@ -28,7 +43,10 @@ export class FileUploadService extends APIService { }); } + /** + * Cancels the upload + */ cancelUpload() { this.cancelSource.cancel("Upload canceled"); } -} +} \ No newline at end of file diff --git a/packages/services/src/file/file.service.ts b/packages/services/src/file/file.service.ts new file mode 100644 index 00000000000..59c054faf1f --- /dev/null +++ b/packages/services/src/file/file.service.ts @@ -0,0 +1,67 @@ +// plane imports +import { API_BASE_URL } from "@plane/constants"; +// api service +import { APIService } from "../api.service"; +// helpers +import { getAssetIdFromUrl } from "./helper"; + +/** + * Service class for managing file operations within plane applications. + * Extends APIService to handle HTTP requests to the file-related endpoints. + * @extends {APIService} + */ +export class FileService extends APIService { + /** + * Creates an instance of FileService + * @param {string} BASE_URL - The base URL for API requests + */ + constructor(BASE_URL?: string) { + super(BASE_URL || API_BASE_URL); + } + + /** + * Deletes a new asset + * @param {string} assetPath - The asset path + * @returns {Promise} Promise resolving to void + * @throws {Error} If the request fails + */ + async deleteNewAsset(assetPath: string): Promise { + return this.delete(assetPath) + .then((response) => response?.data) + .catch((error) => { + throw error?.response?.data; + }); + } + + /** + * Deletes an old editor asset + * @param {string} workspaceId - The workspace identifier + * @param {string} src - The asset source + * @returns {Promise} Promise resolving to void + * @throws {Error} If the request fails + */ + async deleteOldEditorAsset(workspaceId: string, src: string): Promise { + const assetKey = getAssetIdFromUrl(src); + return this.delete(`/api/workspaces/file-assets/${workspaceId}/${assetKey}/`) + .then((response) => response?.status) + .catch((error) => { + throw error?.response?.data; + }); + } + + /** + * Restores an old editor asset + * @param {string} workspaceId - The workspace identifier + * @param {string} src - The asset source + * @returns {Promise} Promise resolving to void + * @throws {Error} If the request fails + */ + async restoreOldEditorAsset(workspaceId: string, src: string): Promise { + const assetKey = getAssetIdFromUrl(src); + return this.post(`/api/workspaces/file-assets/${workspaceId}/${assetKey}/restore/`) + .then((response) => response?.data) + .catch((error) => { + throw error?.response?.data; + }); + } +} diff --git a/packages/services/src/file/helper.ts b/packages/services/src/file/helper.ts new file mode 100644 index 00000000000..f2361290c03 --- /dev/null +++ b/packages/services/src/file/helper.ts @@ -0,0 +1,36 @@ +import { TFileMetaDataLite, TFileSignedURLResponse } from "@plane/types"; + +/** + * @description from the provided signed URL response, generate a payload to be used to upload the file + * @param {TFileSignedURLResponse} signedURLResponse + * @param {File} file + * @returns {FormData} file upload request payload + */ +export const generateFileUploadPayload = (signedURLResponse: TFileSignedURLResponse, file: File): FormData => { + const formData = new FormData(); + Object.entries(signedURLResponse.upload_data.fields).forEach(([key, value]) => formData.append(key, value)); + formData.append("file", file); + return formData; +}; + +/** + * @description returns the necessary file meta data to upload a file + * @param {File} file + * @returns {TFileMetaDataLite} payload with file info + */ +export const getFileMetaDataForUpload = (file: File): TFileMetaDataLite => ({ + name: file.name, + size: file.size, + type: file.type, +}); + +/** + * @description this function returns the assetId from the asset source + * @param {string} src + * @returns {string} assetId + */ +export const getAssetIdFromUrl = (src: string): string => { + const sourcePaths = src.split("/"); + const assetUrl = sourcePaths[sourcePaths.length - 1]; + return assetUrl; +}; diff --git a/packages/services/src/file/index.ts b/packages/services/src/file/index.ts new file mode 100644 index 00000000000..439db5ac719 --- /dev/null +++ b/packages/services/src/file/index.ts @@ -0,0 +1,3 @@ +export * from "./file-upload.service"; +export * from "./sites-file.service"; +export * from "./file.service"; diff --git a/space/core/services/file.service.ts b/packages/services/src/file/sites-file.service.ts similarity index 54% rename from space/core/services/file.service.ts rename to packages/services/src/file/sites-file.service.ts index 0b4807affb5..2d606a09efc 100644 --- a/space/core/services/file.service.ts +++ b/packages/services/src/file/sites-file.service.ts @@ -1,22 +1,40 @@ +// plane imports import { API_BASE_URL } from "@plane/constants"; +// local services import { TFileEntityInfo, TFileSignedURLResponse } from "@plane/types"; +import { FileUploadService } from "./file-upload.service"; // helpers -import { generateFileUploadPayload, getAssetIdFromUrl, getFileMetaDataForUpload } from "@/helpers/file.helper"; -// services -import { APIService } from "@/services/api.service"; -import { FileUploadService } from "@/services/file-upload.service"; +import { FileService } from "./file.service"; +import { generateFileUploadPayload, getAssetIdFromUrl, getFileMetaDataForUpload } from "./helper"; -export class FileService extends APIService { +/** + * Service class for managing file operations within plane sites application. + * Extends FileService to manage file-related operations. + * @extends {FileService} + * @remarks This service is only available for plane sites + */ +export class SitesFileService extends FileService { private cancelSource: any; fileUploadService: FileUploadService; - constructor() { - super(API_BASE_URL); + /** + * Creates an instance of SitesFileService + * @param {string} BASE_URL - The base URL for API requests + */ + constructor(BASE_URL?: string) { + super(BASE_URL || API_BASE_URL); this.cancelUpload = this.cancelUpload.bind(this); // services this.fileUploadService = new FileUploadService(); } + /** + * Updates the upload status of an asset + * @param {string} anchor - The anchor identifier + * @param {string} assetId - The asset identifier + * @returns {Promise} Promise resolving to void + * @throws {Error} If the request fails + */ private async updateAssetUploadStatus(anchor: string, assetId: string): Promise { return this.patch(`/api/public/assets/v2/anchor/${anchor}/${assetId}/`) .then((response) => response?.data) @@ -25,6 +43,14 @@ export class FileService extends APIService { }); } + /** + * Updates the upload status of multiple assets + * @param {string} anchor - The anchor identifier + * @param {string} entityId - The entity identifier + * @param {Object} data - The data payload + * @returns {Promise} Promise resolving to void + * @throws {Error} If the request fails + */ async updateBulkAssetsUploadStatus( anchor: string, entityId: string, @@ -39,6 +65,14 @@ export class FileService extends APIService { }); } + /** + * Uploads a file to the specified anchor + * @param {string} anchor - The anchor identifier + * @param {TFileEntityInfo} data - The data payload + * @param {File} file - The file to upload + * @returns {Promise} Promise resolving to the signed URL response + * @throws {Error} If the request fails + */ async uploadAsset(anchor: string, data: TFileEntityInfo, file: File): Promise { const fileMetaData = getFileMetaDataForUpload(file); return this.post(`/api/public/assets/v2/anchor/${anchor}/`, { @@ -57,23 +91,13 @@ export class FileService extends APIService { }); } - async deleteNewAsset(assetPath: string): Promise { - return this.delete(assetPath) - .then((response) => response?.data) - .catch((error) => { - throw error?.response?.data; - }); - } - - async deleteOldEditorAsset(workspaceId: string, src: string): Promise { - const assetKey = getAssetIdFromUrl(src); - return this.delete(`/api/workspaces/file-assets/${workspaceId}/${assetKey}/`) - .then((response) => response?.status) - .catch((error) => { - throw error?.response?.data; - }); - } - + /** + * Restores a new asset + * @param {string} workspaceSlug - The workspace slug + * @param {string} src - The asset source + * @returns {Promise} Promise resolving to void + * @throws {Error} If the request fails + */ async restoreNewAsset(workspaceSlug: string, src: string): Promise { // remove the last slash and get the asset id const assetId = getAssetIdFromUrl(src); @@ -84,16 +108,10 @@ export class FileService extends APIService { }); } - async restoreOldEditorAsset(workspaceId: string, src: string): Promise { - const assetKey = getAssetIdFromUrl(src); - return this.post(`/api/workspaces/file-assets/${workspaceId}/${assetKey}/restore/`) - .then((response) => response?.data) - .catch((error) => { - throw error?.response?.data; - }); - } - + /** + * Cancels the upload + */ cancelUpload() { - this.cancelSource.cancel("Upload cancelled"); + this.cancelSource.cancelUpload(); } } diff --git a/packages/services/src/index.ts b/packages/services/src/index.ts index 677aa28e7a2..3c49084628a 100644 --- a/packages/services/src/index.ts +++ b/packages/services/src/index.ts @@ -10,3 +10,7 @@ export * from "./module"; export * from "./user"; export * from "./project"; export * from "./workspace"; +export * from "./file"; +export * from "./label"; +export * from "./state"; +export * from "./issue"; diff --git a/packages/services/src/issue/index.ts b/packages/services/src/issue/index.ts new file mode 100644 index 00000000000..79d4537cd2c --- /dev/null +++ b/packages/services/src/issue/index.ts @@ -0,0 +1 @@ +export * from "./sites-issue.service"; diff --git a/packages/services/src/issue/sites-issue.service.ts b/packages/services/src/issue/sites-issue.service.ts new file mode 100644 index 00000000000..9b6aa772e41 --- /dev/null +++ b/packages/services/src/issue/sites-issue.service.ts @@ -0,0 +1,244 @@ +// plane imports +import { API_BASE_URL } from "@plane/constants"; +import { IPublicIssue, TIssuePublicComment, TPublicIssuesResponse } from "@plane/types"; +// api service +import { APIService } from "../api.service"; + +/** + * Service class for managing issues within plane sites application + * Extends the APIService class to handle HTTP requests to the issue-related endpoints + * @extends {APIService} + * @remarks This service is only available for plane sites + */ +export class SitesIssueService extends APIService { + constructor(BASE_URL?: string) { + super(BASE_URL || API_BASE_URL); + } + + /** + * Retrieves a paginated list of issues for a specific anchor + * @param {string} anchor - The anchor identifier + * @param {any} params - Optional query parameters + * @returns {Promise} Promise resolving to a paginated list of issues + * @throws {Error} If the API request fails + */ + async list(anchor: string, params: any): Promise { + return this.get(`/api/public/anchor/${anchor}/issues/`, { + params, + }) + .then((response) => response?.data) + .catch((error) => { + throw error?.response; + }); + } + + /** + * Retrieves details of a specific issue + * @param {string} anchor - The anchor identifier + * @param {string} issueID - The issue identifier + * @returns {Promise} Promise resolving to the issue details + * @throws {Error} If the API request fails + */ + async retrieve(anchor: string, issueID: string): Promise { + return this.get(`/api/public/anchor/${anchor}/issues/${issueID}/`) + .then((response) => response?.data) + .catch((error) => { + throw error?.response; + }); + } + + /** + * Retrieves the votes associated with a specific issue + * @param {string} anchor - The anchor identifier + * @param {string} issueID - The issue identifier + * @returns {Promise} Promise resolving to the votes + * @throws {Error} If the API request fails + */ + async listVotes(anchor: string, issueID: string): Promise { + return this.get(`/api/public/anchor/${anchor}/issues/${issueID}/votes/`) + .then((response) => response?.data) + .catch((error) => { + throw error?.response; + }); + } + + /** + * Creates a new vote for a specific issue + * @param {string} anchor - The anchor identifier + * @param {string} issueID - The issue identifier + * @param {any} data - The vote data + * @returns {Promise} Promise resolving to the created vote + * @throws {Error} If the API request fails + */ + async addVote(anchor: string, issueID: string, data: any): Promise { + return this.post(`/api/public/anchor/${anchor}/issues/${issueID}/votes/`, data) + .then((response) => response?.data) + .catch((error) => { + throw error?.response; + }); + } + + /** + * Deletes a vote for a specific issue + * @param {string} anchor - The anchor identifier + * @param {string} issueID - The issue identifier + * @returns {Promise} Promise resolving to the deletion response + * @throws {Error} If the API request fails + */ + async removeVote(anchor: string, issueID: string): Promise { + return this.delete(`/api/public/anchor/${anchor}/issues/${issueID}/votes/`) + .then((response) => response?.data) + .catch((error) => { + throw error?.response; + }); + } + + /** + * Retrieves the reactions associated with a specific issue + * @param {string} anchor - The anchor identifier + * @param {string} issueID - The issue identifier + * @returns {Promise} Promise resolving to the reactions + * @throws {Error} If the API request fails + */ + async listReactions(anchor: string, issueID: string): Promise { + return this.get(`/api/public/anchor/${anchor}/issues/${issueID}/reactions/`) + .then((response) => response?.data) + .catch((error) => { + throw error?.response; + }); + } + + /** + * Creates a new reaction for a specific issue + * @param {string} anchor - The anchor identifier + * @param {string} issueID - The issue identifier + * @param {any} data - The reaction data + * @returns {Promise} Promise resolving to the created reaction + * @throws {Error} If the API request fails + */ + async addReaction(anchor: string, issueID: string, data: any): Promise { + return this.post(`/api/public/anchor/${anchor}/issues/${issueID}/reactions/`, data) + .then((response) => response?.data) + .catch((error) => { + throw error?.response; + }); + } + + /** + * Deletes a reaction for a specific issue + * @param {string} anchor - The anchor identifier + * @param {string} issueID - The issue identifier + * @param {string} reactionId - The reaction identifier + * @returns {Promise} Promise resolving to the deletion response + * @throws {Error} If the API request fails + */ + async removeReaction(anchor: string, issueID: string, reactionId: string): Promise { + return this.delete(`/api/public/anchor/${anchor}/issues/${issueID}/reactions/${reactionId}/`) + .then((response) => response?.data) + .catch((error) => { + throw error?.response; + }); + } + + /** + * Retrieves the comments associated with a specific issue + * @param {string} anchor - The anchor identifier + * @param {string} issueID - The issue identifier + * @returns {Promise} Promise resolving to the comments + * @throws {Error} If the API request fails + */ + async listComments(anchor: string, issueID: string): Promise { + return this.get(`/api/public/anchor/${anchor}/issues/${issueID}/comments/`) + .then((response) => response?.data) + .catch((error) => { + throw error?.response; + }); + } + + /** + * Creates a new comment for a specific issue + * @param {string} anchor - The anchor identifier + * @param {string} issueID - The issue identifier + * @param {any} data - The comment data + * @returns {Promise} Promise resolving to the created comment + * @throws {Error} If the API request fails + */ + async addComment(anchor: string, issueID: string, data: any): Promise { + return this.post(`/api/public/anchor/${anchor}/issues/${issueID}/comments/`, data) + .then((response) => response?.data) + .catch((error) => { + throw error?.response; + }); + } + + /** + * Updates a comment for a specific issue + * @param {string} anchor - The anchor identifier + * @param {string} issueID - The issue identifier + * @param {string} commentId - The comment identifier + * @param {any} data - The updated comment data + * @returns {Promise} Promise resolving to the updated comment + * @throws {Error} If the API request fails + */ + async updateComment(anchor: string, issueID: string, commentId: string, data: any): Promise { + return this.patch(`/api/public/anchor/${anchor}/issues/${issueID}/comments/${commentId}/`, data) + .then((response) => response?.data) + .catch((error) => { + throw error?.response; + }); + } + + /** + * Deletes a comment for a specific issue + * @param {string} anchor - The anchor identifier + * @param {string} issueID - The issue identifier + * @param {string} commentId - The comment identifier + * @returns {Promise} Promise resolving to the deletion response + * @throws {Error} If the API request fails + */ + async removeComment(anchor: string, issueID: string, commentId: string): Promise { + return this.delete(`/api/public/anchor/${anchor}/issues/${issueID}/comments/${commentId}/`) + .then((response) => response?.data) + .catch((error) => { + throw error?.response; + }); + } + + /** + * Creates a new reaction for a specific comment + * @param {string} anchor - The anchor identifier + * @param {string} commentId - The comment identifier + * @param {any} data - The reaction data + * @returns {Promise} Promise resolving to the created reaction + * @throws {Error} If the API request fails + */ + async addCommentReaction( + anchor: string, + commentId: string, + data: { + reaction: string; + } + ): Promise { + return this.post(`/api/public/anchor/${anchor}/comments/${commentId}/reactions/`, data) + .then((response) => response?.data) + .catch((error) => { + throw error?.response; + }); + } + + /** + * Deletes a reaction for a specific comment + * @param {string} anchor - The anchor identifier + * @param {string} commentId - The comment identifier + * @param {string} reactionHex - The reaction identifier + * @returns {Promise} Promise resolving to the deletion response + * @throws {Error} If the API request fails + */ + async removeCommentReaction(anchor: string, commentId: string, reactionHex: string): Promise { + return this.delete(`/api/public/anchor/${anchor}/comments/${commentId}/reactions/${reactionHex}/`) + .then((response) => response?.data) + .catch((error) => { + throw error?.response; + }); + } +} diff --git a/packages/services/src/label/index.ts b/packages/services/src/label/index.ts new file mode 100644 index 00000000000..5bf89fa9687 --- /dev/null +++ b/packages/services/src/label/index.ts @@ -0,0 +1 @@ +export * from "./sites-label.service"; diff --git a/packages/services/src/label/sites-label.service.ts b/packages/services/src/label/sites-label.service.ts new file mode 100644 index 00000000000..60ad96271a0 --- /dev/null +++ b/packages/services/src/label/sites-label.service.ts @@ -0,0 +1,31 @@ +// plane imports +import { API_BASE_URL } from "@plane/constants"; +import { IIssueLabel } from "@plane/types"; +// api service +import { APIService } from "../api.service"; + +/** + * Service class for managing labels within plane sites application. + * Extends APIService to handle HTTP requests to the label-related endpoints. + * @extends {APIService} + * @remarks This service is only available for plane sites + */ +export class SitesLabelService extends APIService { + constructor(BASE_URL?: string) { + super(BASE_URL || API_BASE_URL); + } + + /** + * Retrieves a list of labels for a specific anchor. + * @param {string} anchor - The anchor identifier + * @returns {Promise} The list of labels + * @throws {Error} If the API request fails + */ + async list(anchor: string): Promise { + return this.get(`/api/public/anchor/${anchor}/labels/`) + .then((response) => response?.data) + .catch((error) => { + throw error?.response?.data; + }); + } +} diff --git a/packages/services/src/module/index.ts b/packages/services/src/module/index.ts index 8f08f92b831..ad49212285c 100644 --- a/packages/services/src/module/index.ts +++ b/packages/services/src/module/index.ts @@ -1,3 +1,4 @@ export * from "./link.service"; export * from "./module.service"; export * from "./operations.service"; +export * from "./sites-module.service"; diff --git a/packages/services/src/module/sites-module.service.ts b/packages/services/src/module/sites-module.service.ts new file mode 100644 index 00000000000..333535ac389 --- /dev/null +++ b/packages/services/src/module/sites-module.service.ts @@ -0,0 +1,31 @@ +// plane imports +import { API_BASE_URL } from "@plane/constants"; +// api service +import { TPublicModule } from "@plane/types"; +import { APIService } from "../api.service"; + +/** + * Service class for managing modules within plane sites application. + * Extends APIService to handle HTTP requests to the module-related endpoints. + * @extends {APIService} + * @remarks This service is only available for plane sites + */ +export class SitesModuleService extends APIService { + constructor(BASE_URL?: string) { + super(BASE_URL || API_BASE_URL); + } + + /** + * Retrieves a list of modules for a specific anchor. + * @param {string} anchor - The anchor identifier + * @returns {Promise} The list of modules + * @throws {Error} If the API request fails + */ + async list(anchor: string): Promise { + return this.get(`/api/public/anchor/${anchor}/modules/`) + .then((response) => response?.data) + .catch((error) => { + throw error?.response?.data; + }); + } +} diff --git a/packages/services/src/project/index.ts b/packages/services/src/project/index.ts index a470a732864..4cc54d2c205 100644 --- a/packages/services/src/project/index.ts +++ b/packages/services/src/project/index.ts @@ -1 +1,2 @@ -export * from "./view.service"; \ No newline at end of file +export * from "./view.service"; +export * from "./sites-publish.service"; diff --git a/packages/services/src/project/sites-publish.service.ts b/packages/services/src/project/sites-publish.service.ts new file mode 100644 index 00000000000..52d42f5ee4a --- /dev/null +++ b/packages/services/src/project/sites-publish.service.ts @@ -0,0 +1,46 @@ +// plane imports +import { API_BASE_URL } from "@plane/constants"; +import { TProjectPublishSettings } from "@plane/types"; +// api service +import { APIService } from "../api.service"; + +/** + * Service class for managing project publish operations within plane sites application. + * Extends APIService to handle HTTP requests to the project publish-related endpoints. + * @extends {APIService} + * @remarks This service is only available for plane sites + */ +export class SitesProjectPublishService extends APIService { + constructor(BASE_URL?: string) { + super(BASE_URL || API_BASE_URL); + } + + /** + * Retrieves publish settings for a specific anchor. + * @param {string} anchor - The anchor identifier + * @returns {Promise} The publish settings + * @throws {Error} If the API request fails + */ + async retrieveSettingsByAnchor(anchor: string): Promise { + return this.get(`/api/public/anchor/${anchor}/settings/`) + .then((response) => response?.data) + .catch((error) => { + throw error?.response; + }); + } + + /** + * Retrieves publish settings for a specific project. + * @param {string} workspaceSlug - The workspace slug + * @param {string} projectID - The project identifier + * @returns {Promise} The publish settings + * @throws {Error} If the API request fails + */ + async retrieveSettingsByProjectId(workspaceSlug: string, projectID: string): Promise { + return this.get(`/api/public/workspaces/${workspaceSlug}/projects/${projectID}/anchor/`) + .then((response) => response?.data) + .catch((error) => { + throw error?.response; + }); + } +} diff --git a/packages/services/src/state/index.ts b/packages/services/src/state/index.ts new file mode 100644 index 00000000000..5b49aad0eb9 --- /dev/null +++ b/packages/services/src/state/index.ts @@ -0,0 +1 @@ +export * from "./sites-state.service"; diff --git a/packages/services/src/state/sites-state.service.ts b/packages/services/src/state/sites-state.service.ts new file mode 100644 index 00000000000..98ff466d044 --- /dev/null +++ b/packages/services/src/state/sites-state.service.ts @@ -0,0 +1,31 @@ +// plane imports +import { API_BASE_URL } from "@plane/constants"; +import { IState } from "@plane/types"; +// api service +import { APIService } from "../api.service"; + +/** + * Service class for managing states within plane sites application. + * Extends APIService to handle HTTP requests to the state-related endpoints. + * @extends {APIService} + * @remarks This service is only available for plane sites + */ +export class SitesStateService extends APIService { + constructor(BASE_URL?: string) { + super(BASE_URL || API_BASE_URL); + } + + /** + * Retrieves a list of states for a specific anchor. + * @param {string} anchor - The anchor identifier + * @returns {Promise} The list of states + * @throws {Error} If the API request fails + */ + async list(anchor: string): Promise { + return this.get(`/api/public/anchor/${anchor}/states/`) + .then((response) => response?.data) + .catch((error) => { + throw error?.response?.data; + }); + } +} diff --git a/packages/services/src/user/index.ts b/packages/services/src/user/index.ts index c738d93ee81..f01a1a47bdc 100644 --- a/packages/services/src/user/index.ts +++ b/packages/services/src/user/index.ts @@ -1,2 +1,3 @@ export * from "./favorite.service"; export * from "./user.service"; +export * from "./sites-member.service"; diff --git a/packages/services/src/user/sites-member.service.ts b/packages/services/src/user/sites-member.service.ts new file mode 100644 index 00000000000..45cb80626b2 --- /dev/null +++ b/packages/services/src/user/sites-member.service.ts @@ -0,0 +1,31 @@ +// plane imports +import { API_BASE_URL } from "@plane/constants"; +import { TPublicMember } from "@plane/types"; +// api service +import { APIService } from "../api.service"; + +/** + * Service class for managing members operations within plane sites application. + * Extends APIService to handle HTTP requests to the member-related endpoints. + * @extends {APIService} + * @remarks This service is only available for plane sites + */ +export class SitesMemberService extends APIService { + constructor(BASE_URL?: string) { + super(BASE_URL || API_BASE_URL); + } + + /** + * Retrieves a list of members for a specific anchor. + * @param {string} anchor - The anchor identifier + * @returns {Promise} The list of members + * @throws {Error} If the API request fails + */ + async list(anchor: string): Promise { + return this.get(`/api/public/anchor/${anchor}/members/`) + .then((response) => response?.data) + .catch((error) => { + throw error?.response?.data; + }); + } +} diff --git a/packages/services/src/user/user.service.ts b/packages/services/src/user/user.service.ts index 016c2e7e675..c302b1d4f13 100644 --- a/packages/services/src/user/user.service.ts +++ b/packages/services/src/user/user.service.ts @@ -1,6 +1,6 @@ // plane imports import { API_BASE_URL } from "@plane/constants"; -import type { IUser } from "@plane/types"; +import type { IUser, TUserProfile } from "@plane/types"; // api service import { APIService } from "../api.service"; @@ -18,6 +18,60 @@ export class UserService extends APIService { super(BASE_URL || API_BASE_URL); } + /** + * Retrieves the current user details + * @returns {Promise} Promise resolving to the current user details\ + * @remarks This method uses the validateStatus: null option to bypass interceptors for unauthorized errors. + */ + async me(): Promise { + return this.get("/api/users/me/", { validateStatus: null }) + .then((response) => response?.data) + .catch((error) => { + throw error?.response; + }); + } + + /** + * Updates the current user details + * @param {Partial} data Data to update the user with + * @returns {Promise} Promise resolving to the updated user details + * @throws {Error} If the API request fails + */ + async update(data: Partial): Promise { + return this.patch("/api/users/me/", data) + .then((response) => response?.data) + .catch((error) => { + throw error?.response?.data; + }); + } + + /** + * Retrieves the current user's profile details + * @returns {Promise} Promise resolving to the current user's profile details + * @throws {Error} If the API request fails + */ + async profile(): Promise { + return this.get("/api/users/me/profile/") + .then((response) => response?.data) + .catch((error) => { + throw error?.response; + }); + } + + /** + * Updates the current user's profile details + * @param {Partial} data Data to update the user's profile with + * @returns {Promise} Promise resolving to the updated user's profile details + * @throws {Error} If the API request fails + */ + async updateProfile(data: Partial): Promise { + return this.patch("/api/users/me/profile/", data) + .then((response) => response?.data) + .catch((error) => { + throw error?.response; + }); + } + /** * Retrieves the current instance admin details * @returns {Promise} Promise resolving to the current instance admin details diff --git a/packages/types/src/auth.d.ts b/packages/types/src/auth.d.ts index 576ac45b6e7..65000c50323 100644 --- a/packages/types/src/auth.d.ts +++ b/packages/types/src/auth.d.ts @@ -7,6 +7,7 @@ export interface IEmailCheckData { export interface IEmailCheckResponse { status: "MAGIC_CODE" | "CREDENTIAL"; existing: boolean; + is_password_autoset: boolean; } export interface ILoginTokenResponse { diff --git a/packages/types/src/cycle/cycle.d.ts b/packages/types/src/cycle/cycle.d.ts index 1c2fa273aa9..0aa3fc2804e 100644 --- a/packages/types/src/cycle/cycle.d.ts +++ b/packages/types/src/cycle/cycle.d.ts @@ -132,3 +132,9 @@ export type CycleDateCheckData = { export type TCycleEstimateType = "issues" | "points"; export type TCyclePlotType = "burndown" | "burnup"; + +export type TPublicCycle = { + id: string; + name: string; + status: string; +}; diff --git a/packages/types/src/issues/activity/issue_comment.d.ts b/packages/types/src/issues/activity/issue_comment.d.ts index f361ea72016..aef5134c674 100644 --- a/packages/types/src/issues/activity/issue_comment.d.ts +++ b/packages/types/src/issues/activity/issue_comment.d.ts @@ -37,3 +37,30 @@ export type TIssueCommentMap = { export type TIssueCommentIdMap = { [issue_id: string]: string[]; }; + +export type TIssuePublicComment = { + actor_detail: ActorDetail; + access: string; + actor: string; + attachments: any[]; + comment_html: string; + comment_reactions: { + actor_detail: ActorDetail; + comment: string; + id: string; + reaction: string; + }[]; + comment_stripped: string; + created_at: Date; + created_by: string; + id: string; + is_member: boolean; + issue: string; + issue_detail: IssueDetail; + project: string; + project_detail: ProjectDetail; + updated_at: Date; + updated_by: string; + workspace: string; + workspace_detail: IWorkspaceLite; +}; diff --git a/packages/types/src/issues/issue.d.ts b/packages/types/src/issues/issue.d.ts index 6fd160e77f7..e38810004bc 100644 --- a/packages/types/src/issues/issue.d.ts +++ b/packages/types/src/issues/issue.d.ts @@ -2,8 +2,8 @@ import { EIssueServiceType } from "@plane/constants"; import { TIssuePriorities } from "../issues"; import { TIssueAttachment } from "./issue_attachment"; import { TIssueLink } from "./issue_link"; -import { TIssueReaction } from "./issue_reaction"; -import { TIssueRelationTypes } from "@/plane-web/types"; +import { TIssueReaction, IIssuePublicReaction, IPublicVote } from "./issue_reaction"; +import { TIssueRelationTypes, TIssuePublicComment } from "@/plane-web/types"; // new issue structure types @@ -118,12 +118,65 @@ export type TBulkOperationsPayload = { properties: Partial; }; -export type TIssueDetailWidget = - | "sub-issues" - | "relations" - | "links" - | "attachments"; +export type TIssueDetailWidget = "sub-issues" | "relations" | "links" | "attachments"; + +export type TIssueServiceType = EIssueServiceType.ISSUES | EIssueServiceType.EPICS; + +export interface IPublicIssue + extends Pick< + TIssue, + | "description_html" + | "created_at" + | "updated_at" + | "created_by" + | "id" + | "name" + | "priority" + | "state_id" + | "project_id" + | "sequence_id" + | "sort_order" + | "start_date" + | "target_date" + | "cycle_id" + | "module_ids" + | "label_ids" + | "assignee_ids" + | "attachment_count" + | "sub_issues_count" + | "link_count" + | "estimate_point" + > { + comments: TIssuePublicComment[]; + reaction_items: IIssuePublicReaction[]; + vote_items: IPublicVote[]; +} + +type TPublicIssueResponseResults = + | IPublicIssue[] + | { + [key: string]: { + results: + | IPublicIssue[] + | { + [key: string]: { + results: IPublicIssue[]; + total_results: number; + }; + }; + total_results: number; + }; + }; -export type TIssueServiceType = - | EIssueServiceType.ISSUES - | EIssueServiceType.EPICS; +export type TPublicIssuesResponse = { + grouped_by: string; + next_cursor: string; + prev_cursor: string; + next_page_results: boolean; + prev_page_results: boolean; + total_count: number; + count: number; + total_pages: number; + extra_stats: null; + results: TPublicIssueResponseResults; +}; diff --git a/packages/types/src/issues/issue_reaction.d.ts b/packages/types/src/issues/issue_reaction.d.ts index 7fba8cd9c5b..49c971f4afe 100644 --- a/packages/types/src/issues/issue_reaction.d.ts +++ b/packages/types/src/issues/issue_reaction.d.ts @@ -1,3 +1,5 @@ +import { IUserLite } from "../users"; + export type TIssueReaction = { actor: string; id: string; @@ -5,6 +7,11 @@ export type TIssueReaction = { reaction: string; }; +export interface IIssuePublicReaction { + actor_details: IUserLite; + reaction: string; +} + export type TIssueReactionMap = { [reaction_id: string]: TIssueReaction; }; @@ -12,3 +19,8 @@ export type TIssueReactionMap = { export type TIssueReactionIdMap = { [issue_id: string]: { [reaction: string]: string[] }; }; + +export interface IPublicVote { + vote: -1 | 1; + actor_details: IUserLite; +} diff --git a/packages/types/src/module/modules.d.ts b/packages/types/src/module/modules.d.ts index fa77a6a4147..ce845e60de9 100644 --- a/packages/types/src/module/modules.d.ts +++ b/packages/types/src/module/modules.d.ts @@ -117,3 +117,8 @@ export type SelectModuleType = | undefined; export type TModulePlotType = "burndown" | "points"; + +export type TPublicModule = { + id: string; + name: string; +}; diff --git a/packages/types/src/users.d.ts b/packages/types/src/users.d.ts index c562e7c246b..e5140fdef10 100644 --- a/packages/types/src/users.d.ts +++ b/packages/types/src/users.d.ts @@ -182,6 +182,17 @@ export interface IUserEmailNotificationSettings { export type TProfileViews = "assigned" | "created" | "subscribed"; +export type TPublicMember = { + id: string; + member: string; + member__avatar: string; + member__first_name: string; + member__last_name: string; + member__display_name: string; + project: string; + workspace: string; +}; + // export interface ICurrentUser { // id: readonly string; // avatar: string; diff --git a/space/app/[workspaceSlug]/[projectId]/page.ts b/space/app/[workspaceSlug]/[projectId]/page.ts index 1f8b8345d06..5fbb835dcd6 100644 --- a/space/app/[workspaceSlug]/[projectId]/page.ts +++ b/space/app/[workspaceSlug]/[projectId]/page.ts @@ -1,10 +1,9 @@ import { notFound, redirect } from "next/navigation"; -// types +// plane imports +import { SitesProjectPublishService } from "@plane/services"; import { TProjectPublishSettings } from "@plane/types"; -// services -import PublishService from "@/services/publish.service"; -const publishService = new PublishService(); +const publishService = new SitesProjectPublishService(); type Props = { params: { @@ -22,7 +21,7 @@ export default async function IssuesPage(props: Props) { let response: TProjectPublishSettings | undefined = undefined; try { - response = await publishService.fetchAnchorFromProjectDetails(workspaceSlug, projectId); + response = await publishService.retrieveSettingsByProjectId(workspaceSlug, projectId); } catch (error) { // redirect to 404 page on error notFound(); diff --git a/space/core/components/account/auth-forms/auth-root.tsx b/space/core/components/account/auth-forms/auth-root.tsx index afa3bd3a5e1..2ce944a2589 100644 --- a/space/core/components/account/auth-forms/auth-root.tsx +++ b/space/core/components/account/auth-forms/auth-root.tsx @@ -3,6 +3,8 @@ import React, { FC, useEffect, useState } from "react"; import { observer } from "mobx-react"; import { useSearchParams } from "next/navigation"; +// plane imports +import { SitesAuthService } from "@plane/services"; import { IEmailCheckData } from "@plane/types"; // components import { @@ -23,12 +25,10 @@ import { } from "@/helpers/authentication.helper"; // hooks import { useInstance } from "@/hooks/store"; -// services -import { AuthService } from "@/services/auth.service"; // types import { EAuthModes, EAuthSteps } from "@/types/auth"; -const authService = new AuthService(); +const authService = new SitesAuthService(); export const AuthRoot: FC = observer(() => { // router params diff --git a/space/core/components/account/auth-forms/password.tsx b/space/core/components/account/auth-forms/password.tsx index 5f0384f9bbc..08ff7f14219 100644 --- a/space/core/components/account/auth-forms/password.tsx +++ b/space/core/components/account/auth-forms/password.tsx @@ -3,14 +3,14 @@ import React, { useEffect, useMemo, useRef, useState } from "react"; import { observer } from "mobx-react"; import { Eye, EyeOff, XCircle } from "lucide-react"; +// plane imports import { API_BASE_URL } from "@plane/constants"; +import { AuthService } from "@plane/services"; import { Button, Input, Spinner } from "@plane/ui"; // components import { PasswordStrengthMeter } from "@/components/account"; // helpers import { E_PASSWORD_STRENGTH, getPasswordStrength } from "@/helpers/password.helper"; -// services -import { AuthService } from "@/services/auth.service"; // types import { EAuthModes, EAuthSteps } from "@/types/auth"; diff --git a/space/core/components/account/auth-forms/unique-code.tsx b/space/core/components/account/auth-forms/unique-code.tsx index f16796d0589..750b52ccda1 100644 --- a/space/core/components/account/auth-forms/unique-code.tsx +++ b/space/core/components/account/auth-forms/unique-code.tsx @@ -2,12 +2,12 @@ import React, { useEffect, useState } from "react"; import { CircleCheck, XCircle } from "lucide-react"; +// plane imports import { API_BASE_URL } from "@plane/constants"; +import { AuthService } from "@plane/services"; import { Button, Input, Spinner } from "@plane/ui"; // hooks import useTimer from "@/hooks/use-timer"; -// services -import { AuthService } from "@/services/auth.service"; // types import { EAuthModes } from "@/types/auth"; diff --git a/space/core/components/issues/navbar/user-avatar.tsx b/space/core/components/issues/navbar/user-avatar.tsx index 4c41677fc7e..0d07064782e 100644 --- a/space/core/components/issues/navbar/user-avatar.tsx +++ b/space/core/components/issues/navbar/user-avatar.tsx @@ -7,15 +7,15 @@ import { usePathname, useSearchParams } from "next/navigation"; import { usePopper } from "react-popper"; import { LogOut } from "lucide-react"; import { Popover, Transition } from "@headlessui/react"; +// plane imports import { API_BASE_URL } from "@plane/constants"; +import { AuthService } from "@plane/services"; import { Avatar, Button } from "@plane/ui"; // helpers import { getFileURL } from "@/helpers/file.helper"; import { queryParamGenerator } from "@/helpers/query-param-generator"; // hooks import { useUser } from "@/hooks/store"; -// services -import { AuthService } from "@/services/auth.service"; const authService = new AuthService(); diff --git a/space/core/components/issues/peek-overview/comment/add-comment.tsx b/space/core/components/issues/peek-overview/comment/add-comment.tsx index 3623f398641..9712b64e690 100644 --- a/space/core/components/issues/peek-overview/comment/add-comment.tsx +++ b/space/core/components/issues/peek-overview/comment/add-comment.tsx @@ -3,21 +3,19 @@ import React, { useRef, useState } from "react"; import { observer } from "mobx-react"; import { useForm, Controller } from "react-hook-form"; -// editor +// plane imports import { EditorRefApi } from "@plane/editor"; -// ui +import { SitesFileService } from "@plane/services"; +import { TIssuePublicComment } from "@plane/types"; import { TOAST_TYPE, setToast } from "@plane/ui"; // editor components import { LiteTextEditor } from "@/components/editor/lite-text-editor"; // hooks import { useIssueDetails, usePublish, useUser } from "@/hooks/store"; // services -import { FileService } from "@/services/file.service"; -const fileService = new FileService(); -// types -import { Comment } from "@/types/issue"; +const fileService = new SitesFileService(); -const defaultValues: Partial = { +const defaultValues: Partial = { comment_html: "", }; @@ -43,9 +41,9 @@ export const AddComment: React.FC = observer((props) => { watch, formState: { isSubmitting }, reset, - } = useForm({ defaultValues }); + } = useForm({ defaultValues }); - const onSubmit = async (formData: Comment) => { + const onSubmit = async (formData: TIssuePublicComment) => { if (!anchor || !issueId || isSubmitting || !formData.comment_html) return; await addIssueComment(anchor, issueId, formData) diff --git a/space/core/components/issues/peek-overview/comment/comment-detail-card.tsx b/space/core/components/issues/peek-overview/comment/comment-detail-card.tsx index 1b228dfb3e9..e229ac21e81 100644 --- a/space/core/components/issues/peek-overview/comment/comment-detail-card.tsx +++ b/space/core/components/issues/peek-overview/comment/comment-detail-card.tsx @@ -3,8 +3,10 @@ import { observer } from "mobx-react"; import { Controller, useForm } from "react-hook-form"; import { Check, MessageSquare, MoreVertical, X } from "lucide-react"; import { Menu, Transition } from "@headlessui/react"; -// components +// plane imports import { EditorRefApi } from "@plane/editor"; +import { TIssuePublicComment } from "@plane/types"; +// components import { LiteTextEditor, LiteTextReadOnlyEditor } from "@/components/editor"; import { CommentReactions } from "@/components/issues/peek-overview"; // helpers @@ -13,12 +15,10 @@ import { getFileURL } from "@/helpers/file.helper"; // hooks import { useIssueDetails, usePublish, useUser } from "@/hooks/store"; import useIsInIframe from "@/hooks/use-is-in-iframe"; -// types -import { Comment } from "@/types/issue"; type Props = { anchor: string; - comment: Comment; + comment: TIssuePublicComment; }; export const CommentCard: React.FC = observer((props) => { @@ -48,7 +48,7 @@ export const CommentCard: React.FC = observer((props) => { deleteIssueComment(anchor, peekId, comment.id); }; - const handleCommentUpdate = async (formData: Comment) => { + const handleCommentUpdate = async (formData: TIssuePublicComment) => { if (!anchor || !peekId) return; updateIssueComment(anchor, peekId, comment.id, formData); setIsEditing(false); diff --git a/space/core/hooks/use-mention.tsx b/space/core/hooks/use-mention.tsx index 9e33f7d904e..e3819d805c2 100644 --- a/space/core/hooks/use-mention.tsx +++ b/space/core/hooks/use-mention.tsx @@ -1,13 +1,12 @@ import { useRef, useEffect } from "react"; import useSWR from "swr"; -// types +// plane imports +import { UserService } from "@plane/services"; import { IUser } from "@plane/types"; -// services -import { UserService } from "@/services/user.service"; export const useMention = () => { const userService = new UserService(); - const { data: user, isLoading: userDataLoading } = useSWR("currentUser", async () => userService.currentUser()); + const { data: user, isLoading: userDataLoading } = useSWR("currentUser", async () => userService.me()); const userRef = useRef(); diff --git a/space/core/services/api.service.ts b/space/core/services/api.service.ts deleted file mode 100644 index ff5af7acad5..00000000000 --- a/space/core/services/api.service.ts +++ /dev/null @@ -1,54 +0,0 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -import axios, { AxiosInstance } from "axios"; -// store -// import { rootStore } from "@/lib/store-context"; - -export abstract class APIService { - protected baseURL: string | undefined; - private axiosInstance: AxiosInstance; - - constructor(baseURL: string | undefined) { - this.baseURL = baseURL; - this.axiosInstance = axios.create({ - baseURL: baseURL || "", - withCredentials: true, - }); - - this.setupInterceptors(); - } - - private setupInterceptors() { - // this.axiosInstance.interceptors.response.use( - // (response) => response, - // (error) => { - // const store = rootStore; - // if (error.response && error.response.status === 401 && store.user.data) store.user.reset(); - // return Promise.reject(error); - // } - // ); - } - - get(url: string, params = {}) { - return this.axiosInstance.get(url, params); - } - - post(url: string, data = {}, config = {}) { - return this.axiosInstance.post(url, data, config); - } - - put(url: string, data = {}, config = {}) { - return this.axiosInstance.put(url, data, config); - } - - patch(url: string, data = {}, config = {}) { - return this.axiosInstance.patch(url, data, config); - } - - delete(url: string, data?: any, config = {}) { - return this.axiosInstance.delete(url, { data, ...config }); - } - - request(config = {}) { - return this.axiosInstance(config); - } -} diff --git a/space/core/services/auth.service.ts b/space/core/services/auth.service.ts deleted file mode 100644 index 3bbfd149e62..00000000000 --- a/space/core/services/auth.service.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { API_BASE_URL } from "@plane/constants"; -// services -import { APIService } from "@/services/api.service"; -// types -import { ICsrfTokenData, IEmailCheckData, IEmailCheckResponse } from "@/types/auth"; - -export class AuthService extends APIService { - constructor() { - super(API_BASE_URL); - } - - async requestCSRFToken(): Promise { - return this.get("/auth/get-csrf-token/") - .then((response) => response.data) - .catch((error) => { - throw error; - }); - } - - async emailCheck(data: IEmailCheckData): Promise { - return this.post("/auth/spaces/email-check/", data, { headers: {} }) - .then((response) => response?.data) - .catch((error) => { - throw error?.response?.data; - }); - } - - async generateUniqueCode(data: { email: string }): Promise { - return this.post("/auth/spaces/magic-generate/", data, { headers: {} }) - .then((response) => response?.data) - .catch((error) => { - throw error?.response?.data; - }); - } -} diff --git a/space/core/services/cycle.service.ts b/space/core/services/cycle.service.ts deleted file mode 100644 index 7d4ff9a10fd..00000000000 --- a/space/core/services/cycle.service.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { API_BASE_URL } from "@plane/constants"; -// services -import { APIService } from "@/services/api.service"; -// types -import { TPublicCycle } from "@/types/cycle"; - -export class CycleService extends APIService { - constructor() { - super(API_BASE_URL); - } - - async getCycles(anchor: string): Promise { - return this.get(`/api/public/anchor/${anchor}/cycles/`) - .then((response) => response?.data) - .catch((error) => { - throw error?.response?.data; - }); - } -} diff --git a/space/core/services/instance.service.ts b/space/core/services/instance.service.ts deleted file mode 100644 index 100929955e0..00000000000 --- a/space/core/services/instance.service.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { API_BASE_URL } from "@plane/constants"; -import type { IInstanceInfo } from "@plane/types"; -// services -import { APIService } from "@/services/api.service"; - -export class InstanceService extends APIService { - constructor() { - super(API_BASE_URL); - } - - async getInstanceInfo(): Promise { - return this.get("/api/instances/") - .then((response) => response.data) - .catch((error) => { - throw error; - }); - } -} diff --git a/space/core/services/issue.service.ts b/space/core/services/issue.service.ts deleted file mode 100644 index 8ec67ee45f9..00000000000 --- a/space/core/services/issue.service.ts +++ /dev/null @@ -1,133 +0,0 @@ -import { API_BASE_URL } from "@plane/constants"; -// services -import { APIService } from "@/services/api.service"; -// types -import { Comment, TIssuesResponse, IIssue } from "@/types/issue"; - -class IssueService extends APIService { - constructor() { - super(API_BASE_URL); - } - - async fetchPublicIssues(anchor: string, params: any): Promise { - return this.get(`/api/public/anchor/${anchor}/issues/`, { - params, - }) - .then((response) => response?.data) - .catch((error) => { - throw error?.response; - }); - } - - async getIssueById(anchor: string, issueID: string): Promise { - return this.get(`/api/public/anchor/${anchor}/issues/${issueID}/`) - .then((response) => response?.data) - .catch((error) => { - throw error?.response; - }); - } - - async getIssueVotes(anchor: string, issueID: string): Promise { - return this.get(`/api/public/anchor/${anchor}/issues/${issueID}/votes/`) - .then((response) => response?.data) - .catch((error) => { - throw error?.response; - }); - } - - async createIssueVote(anchor: string, issueID: string, data: any): Promise { - return this.post(`/api/public/anchor/${anchor}/issues/${issueID}/votes/`, data) - .then((response) => response?.data) - .catch((error) => { - throw error?.response; - }); - } - - async deleteIssueVote(anchor: string, issueID: string): Promise { - return this.delete(`/api/public/anchor/${anchor}/issues/${issueID}/votes/`) - .then((response) => response?.data) - .catch((error) => { - throw error?.response; - }); - } - - async getIssueReactions(anchor: string, issueID: string): Promise { - return this.get(`/api/public/anchor/${anchor}/issues/${issueID}/reactions/`) - .then((response) => response?.data) - .catch((error) => { - throw error?.response; - }); - } - - async createIssueReaction(anchor: string, issueID: string, data: any): Promise { - return this.post(`/api/public/anchor/${anchor}/issues/${issueID}/reactions/`, data) - .then((response) => response?.data) - .catch((error) => { - throw error?.response; - }); - } - - async deleteIssueReaction(anchor: string, issueID: string, reactionId: string): Promise { - return this.delete(`/api/public/anchor/${anchor}/issues/${issueID}/reactions/${reactionId}/`) - .then((response) => response?.data) - .catch((error) => { - throw error?.response; - }); - } - - async getIssueComments(anchor: string, issueID: string): Promise { - return this.get(`/api/public/anchor/${anchor}/issues/${issueID}/comments/`) - .then((response) => response?.data) - .catch((error) => { - throw error?.response; - }); - } - - async createIssueComment(anchor: string, issueID: string, data: any): Promise { - return this.post(`/api/public/anchor/${anchor}/issues/${issueID}/comments/`, data) - .then((response) => response?.data) - .catch((error) => { - throw error?.response; - }); - } - - async updateIssueComment(anchor: string, issueID: string, commentId: string, data: any): Promise { - return this.patch(`/api/public/anchor/${anchor}/issues/${issueID}/comments/${commentId}/`, data) - .then((response) => response?.data) - .catch((error) => { - throw error?.response; - }); - } - - async deleteIssueComment(anchor: string, issueID: string, commentId: string): Promise { - return this.delete(`/api/public/anchor/${anchor}/issues/${issueID}/comments/${commentId}/`) - .then((response) => response?.data) - .catch((error) => { - throw error?.response; - }); - } - - async createCommentReaction( - anchor: string, - commentId: string, - data: { - reaction: string; - } - ): Promise { - return this.post(`/api/public/anchor/${anchor}/comments/${commentId}/reactions/`, data) - .then((response) => response?.data) - .catch((error) => { - throw error?.response; - }); - } - - async deleteCommentReaction(anchor: string, commentId: string, reactionHex: string): Promise { - return this.delete(`/api/public/anchor/${anchor}/comments/${commentId}/reactions/${reactionHex}/`) - .then((response) => response?.data) - .catch((error) => { - throw error?.response; - }); - } -} - -export default IssueService; diff --git a/space/core/services/label.service.ts b/space/core/services/label.service.ts deleted file mode 100644 index 3b5585578bc..00000000000 --- a/space/core/services/label.service.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { API_BASE_URL } from "@plane/constants"; -import { IIssueLabel } from "@plane/types"; -// services -import { APIService } from "./api.service"; - -export class LabelService extends APIService { - constructor() { - super(API_BASE_URL); - } - - async getLabels(anchor: string): Promise { - return this.get(`/api/public/anchor/${anchor}/labels/`) - .then((response) => response?.data) - .catch((error) => { - throw error?.response?.data; - }); - } -} diff --git a/space/core/services/member.service.ts b/space/core/services/member.service.ts deleted file mode 100644 index 9de19455b16..00000000000 --- a/space/core/services/member.service.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { API_BASE_URL } from "@plane/constants"; -// services -import { APIService } from "@/services/api.service"; -// types -import { TPublicMember } from "@/types/member"; - -export class MemberService extends APIService { - constructor() { - super(API_BASE_URL); - } - - async getAnchorMembers(anchor: string): Promise { - return this.get(`/api/public/anchor/${anchor}/members/`) - .then((response) => response?.data) - .catch((error) => { - throw error?.response?.data; - }); - } -} diff --git a/space/core/services/module.service.ts b/space/core/services/module.service.ts deleted file mode 100644 index 30d6ebecf17..00000000000 --- a/space/core/services/module.service.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { API_BASE_URL } from "@plane/constants"; -// services -import { APIService } from "@/services/api.service"; -// types -import { TPublicModule } from "@/types/modules"; - -export class ModuleService extends APIService { - constructor() { - super(API_BASE_URL); - } - - async getModules(anchor: string): Promise { - return this.get(`/api/public/anchor/${anchor}/modules/`) - .then((response) => response?.data) - .catch((error) => { - throw error?.response?.data; - }); - } -} diff --git a/space/core/services/project-member.service.ts b/space/core/services/project-member.service.ts deleted file mode 100644 index bac52e75136..00000000000 --- a/space/core/services/project-member.service.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { API_BASE_URL } from "@plane/constants"; -import type { IProjectMember, IProjectMembership } from "@plane/types"; -// services -import { APIService } from "@/services/api.service"; - -export class ProjectMemberService extends APIService { - constructor() { - super(API_BASE_URL); - } - - async fetchProjectMembers(anchor: string): Promise { - return this.get(`/api/anchor/${anchor}/members/`) - .then((response) => response?.data) - .catch((error) => { - throw error?.response?.data; - }); - } - - async getProjectMember(anchor: string, memberID: string): Promise { - return this.get(`/api/anchor/${anchor}/members/${memberID}/`) - .then((response) => response?.data) - .catch((error) => { - throw error?.response?.data; - }); - } -} diff --git a/space/core/services/publish.service.ts b/space/core/services/publish.service.ts deleted file mode 100644 index 3da72f59a94..00000000000 --- a/space/core/services/publish.service.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { API_BASE_URL } from "@plane/constants"; -import { TProjectPublishSettings } from "@plane/types"; -// services -import { APIService } from "@/services/api.service"; - -class PublishService extends APIService { - constructor() { - super(API_BASE_URL); - } - - async fetchPublishSettings(anchor: string): Promise { - return this.get(`/api/public/anchor/${anchor}/settings/`) - .then((response) => response?.data) - .catch((error) => { - throw error?.response; - }); - } - - async fetchAnchorFromProjectDetails(workspaceSlug: string, projectID: string): Promise { - return this.get(`/api/public/workspaces/${workspaceSlug}/projects/${projectID}/anchor/`) - .then((response) => response?.data) - .catch((error) => { - throw error?.response; - }); - } -} - -export default PublishService; diff --git a/space/core/services/state.service.ts b/space/core/services/state.service.ts deleted file mode 100644 index b877ac530c3..00000000000 --- a/space/core/services/state.service.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { API_BASE_URL } from "@plane/constants"; -import { IState } from "@plane/types"; -// services -import { APIService } from "./api.service"; - -export class StateService extends APIService { - constructor() { - super(API_BASE_URL); - } - - async getStates(anchor: string): Promise { - return this.get(`/api/public/anchor/${anchor}/states/`) - .then((response) => response?.data) - .catch((error) => { - throw error?.response?.data; - }); - } -} diff --git a/space/core/services/user.service.ts b/space/core/services/user.service.ts deleted file mode 100644 index a00b1a3507f..00000000000 --- a/space/core/services/user.service.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { API_BASE_URL } from "@plane/constants"; -import { IUser, TUserProfile } from "@plane/types"; -// services -import { APIService } from "@/services/api.service"; - -export class UserService extends APIService { - constructor() { - super(API_BASE_URL); - } - - async currentUser(): Promise { - return this.get("/api/users/me/") - .then((response) => response?.data) - .catch((error) => { - throw error?.response; - }); - } - - async updateUser(data: Partial): Promise { - return this.patch("/api/users/me/", data) - .then((response) => response?.data) - .catch((error) => { - throw error?.response?.data; - }); - } - - async getCurrentUserProfile(): Promise { - return this.get("/api/users/me/profile/") - .then((response) => response?.data) - .catch((error) => { - throw error?.response; - }); - } - async updateCurrentUserProfile(data: Partial): Promise { - return this.patch("/api/users/me/profile/", data) - .then((response) => response?.data) - .catch((error) => { - throw error?.response; - }); - } -} diff --git a/space/core/store/cycle.store.ts b/space/core/store/cycle.store.ts index a7310290bf4..57af963ae6e 100644 --- a/space/core/store/cycle.store.ts +++ b/space/core/store/cycle.store.ts @@ -1,6 +1,8 @@ import { action, makeObservable, observable, runInAction } from "mobx"; +// plane imports +import { SitesCycleService } from "@plane/services"; import { TPublicCycle } from "@/types/cycle"; -import { CycleService } from "../services/cycle.service"; +// store import { CoreRootStore } from "./root.store"; export interface ICycleStore { @@ -14,7 +16,7 @@ export interface ICycleStore { export class CycleStore implements ICycleStore { cycles: TPublicCycle[] | undefined = undefined; - cycleService: CycleService; + cycleService: SitesCycleService; rootStore: CoreRootStore; constructor(_rootStore: CoreRootStore) { @@ -24,14 +26,14 @@ export class CycleStore implements ICycleStore { // fetch action fetchCycles: action, }); - this.cycleService = new CycleService(); + this.cycleService = new SitesCycleService(); this.rootStore = _rootStore; } getCycleById = (cycleId: string | undefined) => this.cycles?.find((cycle) => cycle.id === cycleId); fetchCycles = async (anchor: string) => { - const cyclesResponse = await this.cycleService.getCycles(anchor); + const cyclesResponse = await this.cycleService.list(anchor); runInAction(() => { this.cycles = cyclesResponse; }); diff --git a/space/core/store/helpers/base-issues.store.ts b/space/core/store/helpers/base-issues.store.ts index 7abfa324a8d..867f2962c8d 100644 --- a/space/core/store/helpers/base-issues.store.ts +++ b/space/core/store/helpers/base-issues.store.ts @@ -5,9 +5,9 @@ import uniq from "lodash/uniq"; import update from "lodash/update"; import { action, makeObservable, observable, runInAction } from "mobx"; import { computedFn } from "mobx-utils"; -// plane constants +// plane imports import { ALL_ISSUES } from "@plane/constants"; -// types +import { SitesIssueService } from "@plane/services"; import { TIssueGroupByOptions, TGroupedIssues, @@ -19,8 +19,7 @@ import { TGroupedIssueCount, TPaginationData, } from "@plane/types"; -// services -import IssueService from "@/services/issue.service"; +// types import { IIssue, TIssuesResponse } from "@/types/issue"; import { CoreRootStore } from "../root.store"; // constants @@ -98,7 +97,7 @@ export abstract class BaseIssuesStore implements IBaseIssuesStore { setLoader: action.bound, }); this.rootIssueStore = _rootStore; - this.issueService = new IssueService(); + this.issueService = new SitesIssueService(); } getIssueIds = (groupId?: string, subGroupId?: string) => { diff --git a/space/core/store/instance.store.ts b/space/core/store/instance.store.ts index 970824404d1..4b6c5a22efe 100644 --- a/space/core/store/instance.store.ts +++ b/space/core/store/instance.store.ts @@ -1,9 +1,8 @@ import set from "lodash/set"; import { observable, action, makeObservable, runInAction } from "mobx"; -// types +// plane imports +import { InstanceService } from "@plane/services"; import { IInstance, IInstanceConfig } from "@plane/types"; -// services -import { InstanceService } from "@/services/instance.service"; // store import { CoreRootStore } from "@/store/root.store"; @@ -59,7 +58,7 @@ export class InstanceStore implements IInstanceStore { try { this.isLoading = true; this.error = undefined; - const instanceInfo = await this.instanceService.getInstanceInfo(); + const instanceInfo = await this.instanceService.info(); runInAction(() => { this.isLoading = false; this.instance = instanceInfo.instance; diff --git a/space/core/store/issue-detail.store.ts b/space/core/store/issue-detail.store.ts index 9abed296685..71583694600 100644 --- a/space/core/store/issue-detail.store.ts +++ b/space/core/store/issue-detail.store.ts @@ -3,16 +3,14 @@ import set from "lodash/set"; import { makeObservable, observable, action, runInAction } from "mobx"; import { computedFn } from "mobx-utils"; import { v4 as uuidv4 } from "uuid"; -// plane types -import { TFileSignedURLResponse } from "@plane/types"; +// plane imports +import { SitesFileService, SitesIssueService } from "@plane/services"; +import { TFileSignedURLResponse, TIssuePublicComment } from "@plane/types"; import { EFileAssetType } from "@plane/types/src/enums"; -// services -import { FileService } from "@/services/file.service"; -import IssueService from "@/services/issue.service"; // store import { CoreRootStore } from "@/store/root.store"; // types -import { Comment, IIssue, IPeekMode, IVote } from "@/types/issue"; +import { IIssue, IPeekMode, IVote } from "@/types/issue"; export interface IIssueDetailStore { loader: boolean; @@ -32,7 +30,7 @@ export interface IIssueDetailStore { // issue actions fetchIssueDetails: (anchor: string, issueID: string) => void; // comment actions - addIssueComment: (anchor: string, issueID: string, data: any) => Promise; + addIssueComment: (anchor: string, issueID: string, data: any) => Promise; updateIssueComment: (anchor: string, issueID: string, commentID: string, data: any) => Promise; deleteIssueComment: (anchor: string, issueID: string, commentID: string) => void; uploadCommentAsset: (file: File, anchor: string, commentID?: string) => Promise; @@ -59,8 +57,8 @@ export class IssueDetailStore implements IIssueDetailStore { // root store rootStore: CoreRootStore; // services - issueService: IssueService; - fileService: FileService; + issueService: SitesIssueService; + fileService: SitesFileService; constructor(_rootStore: CoreRootStore) { makeObservable(this, { @@ -91,8 +89,8 @@ export class IssueDetailStore implements IIssueDetailStore { removeIssueVote: action, }); this.rootStore = _rootStore; - this.issueService = new IssueService(); - this.fileService = new FileService(); + this.issueService = new SitesIssueService(); + this.fileService = new SitesFileService(); } setPeekId = (issueID: string | null) => { @@ -123,7 +121,7 @@ export class IssueDetailStore implements IIssueDetailStore { */ fetchIssueById = async (anchorId: string, issueId: string) => { try { - const issueDetails = await this.issueService.getIssueById(anchorId, issueId); + const issueDetails = await this.issueService.retrieve(anchorId, issueId); runInAction(() => { set(this.details, [issueId], issueDetails); @@ -146,7 +144,7 @@ export class IssueDetailStore implements IIssueDetailStore { this.error = null; const issueDetails = await this.fetchIssueById(anchor, issueID); - const commentsResponse = await this.issueService.getIssueComments(anchor, issueID); + const commentsResponse = await this.issueService.listComments(anchor, issueID); if (issueDetails) { runInAction(() => { @@ -168,7 +166,7 @@ export class IssueDetailStore implements IIssueDetailStore { addIssueComment = async (anchor: string, issueID: string, data: any) => { try { const issueDetails = this.getIssueById(issueID); - const issueCommentResponse = await this.issueService.createIssueComment(anchor, issueID, data); + const issueCommentResponse = await this.issueService.addComment(anchor, issueID, data); if (issueDetails) { runInAction(() => { set(this.details, [issueID, "comments"], [...(issueDetails?.comments ?? []), issueCommentResponse]); @@ -196,9 +194,9 @@ export class IssueDetailStore implements IIssueDetailStore { }; }); - await this.issueService.updateIssueComment(anchor, issueID, commentID, data); + await this.issueService.updateComment(anchor, issueID, commentID, data); } catch (error) { - const issueComments = await this.issueService.getIssueComments(anchor, issueID); + const issueComments = await this.issueService.listComments(anchor, issueID); runInAction(() => { this.details = { @@ -214,7 +212,7 @@ export class IssueDetailStore implements IIssueDetailStore { deleteIssueComment = async (anchor: string, issueID: string, commentID: string) => { try { - await this.issueService.deleteIssueComment(anchor, issueID, commentID); + await this.issueService.removeComment(anchor, issueID, commentID); const remainingComments = this.details[issueID].comments.filter((c) => c.id != commentID); runInAction(() => { this.details = { @@ -288,11 +286,11 @@ export class IssueDetailStore implements IIssueDetailStore { }; }); - await this.issueService.createCommentReaction(anchor, commentID, { + await this.issueService.addCommentReaction(anchor, commentID, { reaction: reactionHex, }); } catch (error) { - const issueComments = await this.issueService.getIssueComments(anchor, issueID); + const issueComments = await this.issueService.listComments(anchor, issueID); runInAction(() => { this.details = { @@ -324,9 +322,9 @@ export class IssueDetailStore implements IIssueDetailStore { }; }); - await this.issueService.deleteCommentReaction(anchor, commentID, reactionHex); + await this.issueService.removeCommentReaction(anchor, commentID, reactionHex); } catch (error) { - const issueComments = await this.issueService.getIssueComments(anchor, issueID); + const issueComments = await this.issueService.listComments(anchor, issueID); runInAction(() => { this.details = { @@ -356,12 +354,12 @@ export class IssueDetailStore implements IIssueDetailStore { ); }); - await this.issueService.createIssueReaction(anchor, issueID, { + await this.issueService.addReaction(anchor, issueID, { reaction: reactionHex, }); } catch (error) { console.log("Failed to add issue vote"); - const issueReactions = await this.issueService.getIssueReactions(anchor, issueID); + const issueReactions = await this.issueService.listReactions(anchor, issueID); runInAction(() => { set(this.details, [issueID, "reaction_items"], issueReactions); }); @@ -378,10 +376,10 @@ export class IssueDetailStore implements IIssueDetailStore { set(this.details, [issueID, "reaction_items"], newReactions); }); - await this.issueService.deleteIssueReaction(anchor, issueID, reactionHex); + await this.issueService.removeReaction(anchor, issueID, reactionHex); } catch (error) { console.log("Failed to remove issue reaction"); - const reactions = await this.issueService.getIssueReactions(anchor, issueID); + const reactions = await this.issueService.listReactions(anchor, issueID); runInAction(() => { set(this.details, [issueID, "reaction_items"], reactions); }); @@ -410,10 +408,10 @@ export class IssueDetailStore implements IIssueDetailStore { }); }); - await this.issueService.createIssueVote(anchor, issueID, data); + await this.issueService.addVote(anchor, issueID, data); } catch (error) { console.log("Failed to add issue vote"); - const issueVotes = await this.issueService.getIssueVotes(anchor, issueID); + const issueVotes = await this.issueService.listVotes(anchor, issueID); runInAction(() => { set(this.details, [issueID, "vote_items"], issueVotes); @@ -431,10 +429,10 @@ export class IssueDetailStore implements IIssueDetailStore { set(this.details, [issueID, "vote_items"], newVotes); }); - await this.issueService.deleteIssueVote(anchor, issueID); + await this.issueService.removeVote(anchor, issueID); } catch (error) { console.log("Failed to remove issue vote"); - const issueVotes = await this.issueService.getIssueVotes(anchor, issueID); + const issueVotes = await this.issueService.listVotes(anchor, issueID); runInAction(() => { set(this.details, [issueID, "vote_items"], issueVotes); diff --git a/space/core/store/issue.store.ts b/space/core/store/issue.store.ts index ca5154df7a3..c65e84d11ae 100644 --- a/space/core/store/issue.store.ts +++ b/space/core/store/issue.store.ts @@ -1,8 +1,7 @@ import { action, makeObservable, runInAction } from "mobx"; -// types +// plane imports +import { SitesIssueService } from "@plane/services"; import { IssuePaginationOptions, TLoader } from "@plane/types"; -// services -import IssueService from "@/services/issue.service"; // store import { CoreRootStore } from "@/store/root.store"; // types @@ -24,7 +23,7 @@ export class IssueStore extends BaseIssuesStore implements IIssueStore { // root store rootStore: CoreRootStore; // services - issueService: IssueService; + issueService: SitesIssueService; constructor(_rootStore: CoreRootStore) { super(_rootStore); @@ -36,7 +35,7 @@ export class IssueStore extends BaseIssuesStore implements IIssueStore { }); this.rootStore = _rootStore; - this.issueService = new IssueService(); + this.issueService = new SitesIssueService(); } /** @@ -59,7 +58,7 @@ export class IssueStore extends BaseIssuesStore implements IIssueStore { const params = this.rootStore.issueFilter.getFilterParams(options, anchor, undefined, undefined, undefined); - const response = await this.issueService.fetchPublicIssues(anchor, params); + const response = await this.issueService.list(anchor, params); // after fetching issues, call the base method to process the response further this.onfetchIssues(response, options); @@ -86,7 +85,7 @@ export class IssueStore extends BaseIssuesStore implements IIssueStore { subGroupId ); // call the fetch issues API with the params for next page in issues - const response = await this.issueService.fetchPublicIssues(anchor, params); + const response = await this.issueService.list(anchor, params); // after the next page of issues are fetched, call the base method to process the response this.onfetchNexIssues(response, groupId, subGroupId); diff --git a/space/core/store/label.store.ts b/space/core/store/label.store.ts index e705aa4d2a4..e51e59f4e1a 100644 --- a/space/core/store/label.store.ts +++ b/space/core/store/label.store.ts @@ -1,7 +1,9 @@ import set from "lodash/set"; import { action, computed, makeObservable, observable, runInAction } from "mobx"; +// plane imports +import { SitesLabelService } from "@plane/services"; import { IIssueLabel } from "@plane/types"; -import { LabelService } from "@/services/label.service"; +// store import { CoreRootStore } from "./root.store"; export interface IIssueLabelStore { @@ -16,7 +18,7 @@ export interface IIssueLabelStore { export class LabelStore implements IIssueLabelStore { labelMap: Record = {}; - labelService: LabelService; + labelService: SitesLabelService; rootStore: CoreRootStore; constructor(_rootStore: CoreRootStore) { @@ -28,7 +30,7 @@ export class LabelStore implements IIssueLabelStore { // fetch action fetchLabels: action, }); - this.labelService = new LabelService(); + this.labelService = new SitesLabelService(); this.rootStore = _rootStore; } @@ -51,7 +53,7 @@ export class LabelStore implements IIssueLabelStore { }; fetchLabels = async (anchor: string) => { - const labelsResponse = await this.labelService.getLabels(anchor); + const labelsResponse = await this.labelService.list(anchor); runInAction(() => { this.labelMap = {}; for (const label of labelsResponse) { diff --git a/space/core/store/members.store.ts b/space/core/store/members.store.ts index 3de021e2c7e..1328f52599f 100644 --- a/space/core/store/members.store.ts +++ b/space/core/store/members.store.ts @@ -1,7 +1,9 @@ import set from "lodash/set"; import { action, computed, makeObservable, observable, runInAction } from "mobx"; +// plane imports +import { SitesMemberService } from "@plane/services"; + import { TPublicMember } from "@/types/member"; -import { MemberService } from "../services/member.service"; import { CoreRootStore } from "./root.store"; export interface IIssueMemberStore { @@ -16,7 +18,7 @@ export interface IIssueMemberStore { export class MemberStore implements IIssueMemberStore { memberMap: Record = {}; - memberService: MemberService; + memberService: SitesMemberService; rootStore: CoreRootStore; constructor(_rootStore: CoreRootStore) { @@ -28,7 +30,7 @@ export class MemberStore implements IIssueMemberStore { // fetch action fetchMembers: action, }); - this.memberService = new MemberService(); + this.memberService = new SitesMemberService(); this.rootStore = _rootStore; } @@ -52,7 +54,7 @@ export class MemberStore implements IIssueMemberStore { fetchMembers = async (anchor: string) => { try { - const membersResponse = await this.memberService.getAnchorMembers(anchor); + const membersResponse = await this.memberService.list(anchor); runInAction(() => { this.memberMap = {}; for (const member of membersResponse) { diff --git a/space/core/store/module.store.ts b/space/core/store/module.store.ts index 6da1ab1f80e..c996b3a33e2 100644 --- a/space/core/store/module.store.ts +++ b/space/core/store/module.store.ts @@ -1,7 +1,10 @@ import set from "lodash/set"; import { action, computed, makeObservable, observable, runInAction } from "mobx"; +// plane imports +import { SitesModuleService } from "@plane/services"; +// types import { TPublicModule } from "@/types/modules"; -import { ModuleService } from "../services/module.service"; +// root store import { CoreRootStore } from "./root.store"; export interface IIssueModuleStore { @@ -16,7 +19,7 @@ export interface IIssueModuleStore { export class ModuleStore implements IIssueModuleStore { moduleMap: Record = {}; - moduleService: ModuleService; + moduleService: SitesModuleService; rootStore: CoreRootStore; constructor(_rootStore: CoreRootStore) { @@ -28,7 +31,7 @@ export class ModuleStore implements IIssueModuleStore { // fetch action fetchModules: action, }); - this.moduleService = new ModuleService(); + this.moduleService = new SitesModuleService(); this.rootStore = _rootStore; } @@ -52,7 +55,7 @@ export class ModuleStore implements IIssueModuleStore { fetchModules = async (anchor: string) => { try { - const modulesResponse = await this.moduleService.getModules(anchor); + const modulesResponse = await this.moduleService.list(anchor); runInAction(() => { this.moduleMap = {}; for (const issueModule of modulesResponse) { diff --git a/space/core/store/profile.store.ts b/space/core/store/profile.store.ts index 5e001a875e8..5523e8daddb 100644 --- a/space/core/store/profile.store.ts +++ b/space/core/store/profile.store.ts @@ -1,9 +1,8 @@ import set from "lodash/set"; import { action, makeObservable, observable, runInAction } from "mobx"; -// types +// plane imports +import { UserService } from "@plane/services"; import { TUserProfile } from "@plane/types"; -// services -import { UserService } from "@/services/user.service"; // store import { CoreRootStore } from "@/store/root.store"; @@ -85,7 +84,7 @@ export class ProfileStore implements IProfileStore { this.isLoading = true; this.error = undefined; }); - const userProfile = await this.userService.getCurrentUserProfile(); + const userProfile = await this.userService.profile(); runInAction(() => { this.isLoading = false; this.data = userProfile; @@ -116,7 +115,7 @@ export class ProfileStore implements IProfileStore { if (this.data) set(this.data, userKey, data[userKey]); }); } - const userProfile = await this.userService.updateCurrentUserProfile(data); + const userProfile = await this.userService.updateProfile(data); return userProfile; } catch (error) { if (currentUserProfileData) { diff --git a/space/core/store/publish/publish_list.store.ts b/space/core/store/publish/publish_list.store.ts index d4a59f62d5a..60f705b0083 100644 --- a/space/core/store/publish/publish_list.store.ts +++ b/space/core/store/publish/publish_list.store.ts @@ -1,9 +1,8 @@ import set from "lodash/set"; import { makeObservable, observable, runInAction, action } from "mobx"; -// types +// plane imports +import { SitesProjectPublishService } from "@plane/services"; import { TProjectPublishSettings } from "@plane/types"; -// services -import PublishService from "@/services/publish.service"; // store import { PublishStore } from "@/store/publish/publish.store"; import { CoreRootStore } from "@/store/root.store"; @@ -29,7 +28,7 @@ export class PublishListStore implements IPublishListStore { fetchPublishSettings: action, }); // services - this.publishService = new PublishService(); + this.publishService = new SitesProjectPublishService(); } /** @@ -37,7 +36,7 @@ export class PublishListStore implements IPublishListStore { * @param {string} anchor */ fetchPublishSettings = async (anchor: string) => { - const response = await this.publishService.fetchPublishSettings(anchor); + const response = await this.publishService.retrieveSettingsByAnchor(anchor); runInAction(() => { if (response.anchor) { set(this.publishMap, [response.anchor], new PublishStore(this.rootStore, response)); diff --git a/space/core/store/state.store.ts b/space/core/store/state.store.ts index aff22a22a88..655cdee5dc4 100644 --- a/space/core/store/state.store.ts +++ b/space/core/store/state.store.ts @@ -1,8 +1,11 @@ import clone from "lodash/clone"; import { action, computed, makeObservable, observable, runInAction } from "mobx"; +// plane imports +import { SitesStateService } from "@plane/services"; import { IState } from "@plane/types"; +// helpers import { sortStates } from "@/helpers/state.helper"; -import { StateService } from "@/services/state.service"; +// store import { CoreRootStore } from "./root.store"; export interface IStateStore { @@ -18,7 +21,7 @@ export interface IStateStore { export class StateStore implements IStateStore { states: IState[] | undefined = undefined; - stateService: StateService; + stateService: SitesStateService; rootStore: CoreRootStore; constructor(_rootStore: CoreRootStore) { @@ -30,7 +33,7 @@ export class StateStore implements IStateStore { // fetch action fetchStates: action, }); - this.stateService = new StateService(); + this.stateService = new SitesStateService(); this.rootStore = _rootStore; } @@ -42,7 +45,7 @@ export class StateStore implements IStateStore { getStateById = (stateId: string | undefined) => this.states?.find((state) => state.id === stateId); fetchStates = async (anchor: string) => { - const statesResponse = await this.stateService.getStates(anchor); + const statesResponse = await this.stateService.list(anchor); runInAction(() => { this.states = statesResponse; }); diff --git a/space/core/store/user.store.ts b/space/core/store/user.store.ts index 6616b10b095..6765961f54c 100644 --- a/space/core/store/user.store.ts +++ b/space/core/store/user.store.ts @@ -1,10 +1,8 @@ import set from "lodash/set"; import { action, computed, makeObservable, observable, runInAction } from "mobx"; -// types +// plane imports +import { UserService } from "@plane/services"; import { IUser } from "@plane/types"; -// services -import { AuthService } from "@/services/auth.service"; -import { UserService } from "@/services/user.service"; // store types import { ProfileStore, IProfileStore } from "@/store/profile.store"; // store @@ -45,14 +43,12 @@ export class UserStore implements IUserStore { profile: IProfileStore; // service userService: UserService; - authService: AuthService; constructor(private store: CoreRootStore) { // stores this.profile = new ProfileStore(store); // service this.userService = new UserService(); - this.authService = new AuthService(); // observables makeObservable(this, { // observables @@ -95,7 +91,7 @@ export class UserStore implements IUserStore { if (this.data === undefined) this.isLoading = true; this.error = undefined; }); - const user = await this.userService.currentUser(); + const user = await this.userService.me(); if (user && user?.id) { await this.profile.fetchUserProfile(); runInAction(() => { @@ -137,7 +133,7 @@ export class UserStore implements IUserStore { if (this.data) set(this.data, userKey, data[userKey]); }); } - const user = await this.userService.updateUser(data); + const user = await this.userService.update(data); return user; } catch (error) { if (currentUserData) { diff --git a/space/core/types/issue.d.ts b/space/core/types/issue.d.ts index 3041a188d04..d57dd84de39 100644 --- a/space/core/types/issue.d.ts +++ b/space/core/types/issue.d.ts @@ -1,4 +1,4 @@ -import { IWorkspaceLite, TIssue, TIssuePriorities, TStateGroups } from "@plane/types"; +import { IWorkspaceLite, TIssue, TIssuePriorities, TStateGroups, TIssuePublicComment } from "@plane/types"; export type TIssueLayout = "list" | "kanban" | "calendar" | "spreadsheet" | "gantt"; export type TIssueLayoutOptions = { @@ -58,7 +58,7 @@ export interface IIssue | "link_count" | "estimate_point" > { - comments: Comment[]; + comments: TIssuePublicComment[]; reaction_items: IIssueReaction[]; vote_items: IVote[]; } @@ -106,33 +106,6 @@ export interface IVote { actor_details: ActorDetail; } -export interface Comment { - actor_detail: ActorDetail; - access: string; - actor: string; - attachments: any[]; - comment_html: string; - comment_reactions: { - actor_detail: ActorDetail; - comment: string; - id: string; - reaction: string; - }[]; - comment_stripped: string; - created_at: Date; - created_by: string; - id: string; - is_member: boolean; - issue: string; - issue_detail: IssueDetail; - project: string; - project_detail: ProjectDetail; - updated_at: Date; - updated_by: string; - workspace: string; - workspace_detail: IWorkspaceLite; -} - export interface IIssueReaction { actor_details: ActorDetail; reaction: string; diff --git a/space/helpers/editor.helper.ts b/space/helpers/editor.helper.ts index 15891cfb1b8..52d83ccc9c7 100644 --- a/space/helpers/editor.helper.ts +++ b/space/helpers/editor.helper.ts @@ -1,12 +1,11 @@ // plane internal import { MAX_FILE_SIZE } from "@plane/constants"; import { TFileHandler } from "@plane/editor"; - +import { SitesFileService } from "@plane/services"; // helpers import { getFileURL } from "@/helpers/file.helper"; // services -import { FileService } from "@/services/file.service"; -const fileService = new FileService(); +const sitesFileService = new SitesFileService(); /** * @description generate the file source using assetId @@ -42,19 +41,19 @@ export const getEditorFileHandlers = (args: TArgs): TFileHandler => { upload: uploadFile, delete: async (src: string) => { if (src?.startsWith("http")) { - await fileService.deleteOldEditorAsset(workspaceId, src); + await sitesFileService.deleteOldEditorAsset(workspaceId, src); } else { - await fileService.deleteNewAsset(getEditorAssetSrc(anchor, src) ?? ""); + await sitesFileService.deleteNewAsset(getEditorAssetSrc(anchor, src) ?? ""); } }, restore: async (src: string) => { if (src?.startsWith("http")) { - await fileService.restoreOldEditorAsset(workspaceId, src); + await sitesFileService.restoreOldEditorAsset(workspaceId, src); } else { - await fileService.restoreNewAsset(anchor, src); + await sitesFileService.restoreNewAsset(anchor, src); } }, - cancel: fileService.cancelUpload, + cancel: sitesFileService.cancelUpload, validation: { maxFileSize: MAX_FILE_SIZE, }, diff --git a/space/package.json b/space/package.json index e8109d35bb9..8de70c7541b 100644 --- a/space/package.json +++ b/space/package.json @@ -22,6 +22,7 @@ "@plane/editor": "*", "@plane/types": "*", "@plane/ui": "*", + "@plane/services": "*", "@sentry/nextjs": "^8.32.0", "axios": "^1.7.9", "clsx": "^2.0.0",