[WEB-3066] refactor: replace Space Services with Services Package (#6353)
* [WEB-3066] refactor: replace Space Services with Services Package * chore: minor improvements * fix: type --------- Co-authored-by: sriram veeraghanta <veeraghanta.sriram@gmail.com>
This commit is contained in:
parent
39ca600091
commit
ade4d290f5
66 changed files with 1002 additions and 631 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1,2 @@
|
|||
export * from "./auth.service";
|
||||
export * from "./sites-auth.service";
|
||||
|
|
|
|||
49
packages/services/src/auth/sites-auth.service.ts
Normal file
49
packages/services/src/auth/sites-auth.service.ts
Normal file
|
|
@ -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<IEmailCheckResponse>} Response indicating email status
|
||||
* @throws {Error} Throws response data if the request fails
|
||||
*/
|
||||
async emailCheck(data: IEmailCheckData): Promise<IEmailCheckResponse> {
|
||||
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<any>} Response containing the generated unique code
|
||||
* @throws {Error} Throws response data if the request fails
|
||||
*/
|
||||
async generateUniqueCode(data: { email: string }): Promise<any> {
|
||||
return this.post("/auth/spaces/magic-generate/", data, { headers: {} })
|
||||
.then((response) => response?.data)
|
||||
.catch((error) => {
|
||||
throw error?.response?.data;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -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";
|
||||
|
|
|
|||
31
packages/services/src/cycle/sites-cycle.service.ts
Normal file
31
packages/services/src/cycle/sites-cycle.service.ts
Normal file
|
|
@ -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<TPublicCycle[]>} The list of cycles
|
||||
* @throws {Error} If the request fails
|
||||
*/
|
||||
async list(anchor: string): Promise<TPublicCycle[]> {
|
||||
return this.get(`/api/public/anchor/${anchor}/cycles/`)
|
||||
.then((response) => response?.data)
|
||||
.catch((error) => {
|
||||
throw error?.response?.data;
|
||||
});
|
||||
}
|
||||
}
|
||||
52
packages/services/src/file/file-upload.service.ts
Normal file
52
packages/services/src/file/file-upload.service.ts
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
import axios from "axios";
|
||||
// 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;
|
||||
|
||||
constructor() {
|
||||
super("");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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<void>} Promise resolving to void
|
||||
* @throws {Error} If the request fails
|
||||
*/
|
||||
async uploadFile(
|
||||
url: string,
|
||||
data: FormData,
|
||||
): Promise<void> {
|
||||
this.cancelSource = axios.CancelToken.source();
|
||||
return this.post(url, data, {
|
||||
headers: {
|
||||
"Content-Type": "multipart/form-data",
|
||||
},
|
||||
cancelToken: this.cancelSource.token,
|
||||
withCredentials: false,
|
||||
})
|
||||
.then((response) => response?.data)
|
||||
.catch((error) => {
|
||||
if (axios.isCancel(error)) {
|
||||
console.log(error.message);
|
||||
} else {
|
||||
throw error?.response?.data;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels the upload
|
||||
*/
|
||||
cancelUpload() {
|
||||
this.cancelSource.cancel("Upload canceled");
|
||||
}
|
||||
}
|
||||
67
packages/services/src/file/file.service.ts
Normal file
67
packages/services/src/file/file.service.ts
Normal file
|
|
@ -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<void>} Promise resolving to void
|
||||
* @throws {Error} If the request fails
|
||||
*/
|
||||
async deleteNewAsset(assetPath: string): Promise<void> {
|
||||
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<any>} Promise resolving to void
|
||||
* @throws {Error} If the request fails
|
||||
*/
|
||||
async deleteOldEditorAsset(workspaceId: string, src: string): Promise<any> {
|
||||
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<void>} Promise resolving to void
|
||||
* @throws {Error} If the request fails
|
||||
*/
|
||||
async restoreOldEditorAsset(workspaceId: string, src: string): Promise<void> {
|
||||
const assetKey = getAssetIdFromUrl(src);
|
||||
return this.post(`/api/workspaces/file-assets/${workspaceId}/${assetKey}/restore/`)
|
||||
.then((response) => response?.data)
|
||||
.catch((error) => {
|
||||
throw error?.response?.data;
|
||||
});
|
||||
}
|
||||
}
|
||||
36
packages/services/src/file/helper.ts
Normal file
36
packages/services/src/file/helper.ts
Normal file
|
|
@ -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;
|
||||
};
|
||||
3
packages/services/src/file/index.ts
Normal file
3
packages/services/src/file/index.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
export * from "./file-upload.service";
|
||||
export * from "./sites-file.service";
|
||||
export * from "./file.service";
|
||||
117
packages/services/src/file/sites-file.service.ts
Normal file
117
packages/services/src/file/sites-file.service.ts
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
// 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 { FileService } from "./file.service";
|
||||
import { generateFileUploadPayload, getAssetIdFromUrl, getFileMetaDataForUpload } from "./helper";
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* 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<void>} Promise resolving to void
|
||||
* @throws {Error} If the request fails
|
||||
*/
|
||||
private async updateAssetUploadStatus(anchor: string, assetId: string): Promise<void> {
|
||||
return this.patch(`/api/public/assets/v2/anchor/${anchor}/${assetId}/`)
|
||||
.then((response) => response?.data)
|
||||
.catch((error) => {
|
||||
throw error?.response?.data;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 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<void>} Promise resolving to void
|
||||
* @throws {Error} If the request fails
|
||||
*/
|
||||
async updateBulkAssetsUploadStatus(
|
||||
anchor: string,
|
||||
entityId: string,
|
||||
data: {
|
||||
asset_ids: string[];
|
||||
}
|
||||
): Promise<void> {
|
||||
return this.post(`/api/public/assets/v2/anchor/${anchor}/${entityId}/bulk/`, data)
|
||||
.then((response) => response?.data)
|
||||
.catch((error) => {
|
||||
throw error?.response?.data;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 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<TFileSignedURLResponse>} Promise resolving to the signed URL response
|
||||
* @throws {Error} If the request fails
|
||||
*/
|
||||
async uploadAsset(anchor: string, data: TFileEntityInfo, file: File): Promise<TFileSignedURLResponse> {
|
||||
const fileMetaData = getFileMetaDataForUpload(file);
|
||||
return this.post(`/api/public/assets/v2/anchor/${anchor}/`, {
|
||||
...data,
|
||||
...fileMetaData,
|
||||
})
|
||||
.then(async (response) => {
|
||||
const signedURLResponse: TFileSignedURLResponse = response?.data;
|
||||
const fileUploadPayload = generateFileUploadPayload(signedURLResponse, file);
|
||||
await this.fileUploadService.uploadFile(signedURLResponse.upload_data.url, fileUploadPayload);
|
||||
await this.updateAssetUploadStatus(anchor, signedURLResponse.asset_id);
|
||||
return signedURLResponse;
|
||||
})
|
||||
.catch((error) => {
|
||||
throw error?.response?.data;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Restores a new asset
|
||||
* @param {string} workspaceSlug - The workspace slug
|
||||
* @param {string} src - The asset source
|
||||
* @returns {Promise<void>} Promise resolving to void
|
||||
* @throws {Error} If the request fails
|
||||
*/
|
||||
async restoreNewAsset(workspaceSlug: string, src: string): Promise<void> {
|
||||
// remove the last slash and get the asset id
|
||||
const assetId = getAssetIdFromUrl(src);
|
||||
return this.post(`/api/public/assets/v2/workspaces/${workspaceSlug}/restore/${assetId}/`)
|
||||
.then((response) => response?.data)
|
||||
.catch((error) => {
|
||||
throw error?.response?.data;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels the upload
|
||||
*/
|
||||
cancelUpload() {
|
||||
this.cancelSource.cancelUpload();
|
||||
}
|
||||
}
|
||||
|
|
@ -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";
|
||||
|
|
|
|||
1
packages/services/src/issue/index.ts
Normal file
1
packages/services/src/issue/index.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
export * from "./sites-issue.service";
|
||||
244
packages/services/src/issue/sites-issue.service.ts
Normal file
244
packages/services/src/issue/sites-issue.service.ts
Normal file
|
|
@ -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<TPublicIssuesResponse>} Promise resolving to a paginated list of issues
|
||||
* @throws {Error} If the API request fails
|
||||
*/
|
||||
async list(anchor: string, params: any): Promise<TPublicIssuesResponse> {
|
||||
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<IPublicIssue>} Promise resolving to the issue details
|
||||
* @throws {Error} If the API request fails
|
||||
*/
|
||||
async retrieve(anchor: string, issueID: string): Promise<IPublicIssue> {
|
||||
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<any>} Promise resolving to the votes
|
||||
* @throws {Error} If the API request fails
|
||||
*/
|
||||
async listVotes(anchor: string, issueID: string): Promise<any> {
|
||||
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<any>} Promise resolving to the created vote
|
||||
* @throws {Error} If the API request fails
|
||||
*/
|
||||
async addVote(anchor: string, issueID: string, data: any): Promise<any> {
|
||||
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<any>} Promise resolving to the deletion response
|
||||
* @throws {Error} If the API request fails
|
||||
*/
|
||||
async removeVote(anchor: string, issueID: string): Promise<any> {
|
||||
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<any>} Promise resolving to the reactions
|
||||
* @throws {Error} If the API request fails
|
||||
*/
|
||||
async listReactions(anchor: string, issueID: string): Promise<any> {
|
||||
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<any>} Promise resolving to the created reaction
|
||||
* @throws {Error} If the API request fails
|
||||
*/
|
||||
async addReaction(anchor: string, issueID: string, data: any): Promise<any> {
|
||||
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<any>} Promise resolving to the deletion response
|
||||
* @throws {Error} If the API request fails
|
||||
*/
|
||||
async removeReaction(anchor: string, issueID: string, reactionId: string): Promise<any> {
|
||||
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<any>} Promise resolving to the comments
|
||||
* @throws {Error} If the API request fails
|
||||
*/
|
||||
async listComments(anchor: string, issueID: string): Promise<any> {
|
||||
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<TIssuePublicComment>} Promise resolving to the created comment
|
||||
* @throws {Error} If the API request fails
|
||||
*/
|
||||
async addComment(anchor: string, issueID: string, data: any): Promise<TIssuePublicComment> {
|
||||
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<any>} Promise resolving to the updated comment
|
||||
* @throws {Error} If the API request fails
|
||||
*/
|
||||
async updateComment(anchor: string, issueID: string, commentId: string, data: any): Promise<any> {
|
||||
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<any>} Promise resolving to the deletion response
|
||||
* @throws {Error} If the API request fails
|
||||
*/
|
||||
async removeComment(anchor: string, issueID: string, commentId: string): Promise<any> {
|
||||
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<any>} Promise resolving to the created reaction
|
||||
* @throws {Error} If the API request fails
|
||||
*/
|
||||
async addCommentReaction(
|
||||
anchor: string,
|
||||
commentId: string,
|
||||
data: {
|
||||
reaction: string;
|
||||
}
|
||||
): Promise<any> {
|
||||
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<any>} Promise resolving to the deletion response
|
||||
* @throws {Error} If the API request fails
|
||||
*/
|
||||
async removeCommentReaction(anchor: string, commentId: string, reactionHex: string): Promise<any> {
|
||||
return this.delete(`/api/public/anchor/${anchor}/comments/${commentId}/reactions/${reactionHex}/`)
|
||||
.then((response) => response?.data)
|
||||
.catch((error) => {
|
||||
throw error?.response;
|
||||
});
|
||||
}
|
||||
}
|
||||
1
packages/services/src/label/index.ts
Normal file
1
packages/services/src/label/index.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
export * from "./sites-label.service";
|
||||
31
packages/services/src/label/sites-label.service.ts
Normal file
31
packages/services/src/label/sites-label.service.ts
Normal file
|
|
@ -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<IIssueLabel[]>} The list of labels
|
||||
* @throws {Error} If the API request fails
|
||||
*/
|
||||
async list(anchor: string): Promise<IIssueLabel[]> {
|
||||
return this.get(`/api/public/anchor/${anchor}/labels/`)
|
||||
.then((response) => response?.data)
|
||||
.catch((error) => {
|
||||
throw error?.response?.data;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
export * from "./link.service";
|
||||
export * from "./module.service";
|
||||
export * from "./operations.service";
|
||||
export * from "./sites-module.service";
|
||||
|
|
|
|||
31
packages/services/src/module/sites-module.service.ts
Normal file
31
packages/services/src/module/sites-module.service.ts
Normal file
|
|
@ -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<TPublicModule[]>} The list of modules
|
||||
* @throws {Error} If the API request fails
|
||||
*/
|
||||
async list(anchor: string): Promise<TPublicModule[]> {
|
||||
return this.get(`/api/public/anchor/${anchor}/modules/`)
|
||||
.then((response) => response?.data)
|
||||
.catch((error) => {
|
||||
throw error?.response?.data;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1 +1,2 @@
|
|||
export * from "./view.service";
|
||||
export * from "./view.service";
|
||||
export * from "./sites-publish.service";
|
||||
|
|
|
|||
46
packages/services/src/project/sites-publish.service.ts
Normal file
46
packages/services/src/project/sites-publish.service.ts
Normal file
|
|
@ -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<TProjectPublishSettings>} The publish settings
|
||||
* @throws {Error} If the API request fails
|
||||
*/
|
||||
async retrieveSettingsByAnchor(anchor: string): Promise<TProjectPublishSettings> {
|
||||
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<TProjectPublishSettings>} The publish settings
|
||||
* @throws {Error} If the API request fails
|
||||
*/
|
||||
async retrieveSettingsByProjectId(workspaceSlug: string, projectID: string): Promise<TProjectPublishSettings> {
|
||||
return this.get(`/api/public/workspaces/${workspaceSlug}/projects/${projectID}/anchor/`)
|
||||
.then((response) => response?.data)
|
||||
.catch((error) => {
|
||||
throw error?.response;
|
||||
});
|
||||
}
|
||||
}
|
||||
1
packages/services/src/state/index.ts
Normal file
1
packages/services/src/state/index.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
export * from "./sites-state.service";
|
||||
31
packages/services/src/state/sites-state.service.ts
Normal file
31
packages/services/src/state/sites-state.service.ts
Normal file
|
|
@ -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<IState[]>} The list of states
|
||||
* @throws {Error} If the API request fails
|
||||
*/
|
||||
async list(anchor: string): Promise<IState[]> {
|
||||
return this.get(`/api/public/anchor/${anchor}/states/`)
|
||||
.then((response) => response?.data)
|
||||
.catch((error) => {
|
||||
throw error?.response?.data;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,2 +1,3 @@
|
|||
export * from "./favorite.service";
|
||||
export * from "./user.service";
|
||||
export * from "./sites-member.service";
|
||||
|
|
|
|||
31
packages/services/src/user/sites-member.service.ts
Normal file
31
packages/services/src/user/sites-member.service.ts
Normal file
|
|
@ -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<TPublicMember[]>} The list of members
|
||||
* @throws {Error} If the API request fails
|
||||
*/
|
||||
async list(anchor: string): Promise<TPublicMember[]> {
|
||||
return this.get(`/api/public/anchor/${anchor}/members/`)
|
||||
.then((response) => response?.data)
|
||||
.catch((error) => {
|
||||
throw error?.response?.data;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -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<IUser>} Promise resolving to the current user details\
|
||||
* @remarks This method uses the validateStatus: null option to bypass interceptors for unauthorized errors.
|
||||
*/
|
||||
async me(): Promise<IUser> {
|
||||
return this.get("/api/users/me/", { validateStatus: null })
|
||||
.then((response) => response?.data)
|
||||
.catch((error) => {
|
||||
throw error?.response;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the current user details
|
||||
* @param {Partial<IUser>} data Data to update the user with
|
||||
* @returns {Promise<IUser>} Promise resolving to the updated user details
|
||||
* @throws {Error} If the API request fails
|
||||
*/
|
||||
async update(data: Partial<IUser>): Promise<IUser> {
|
||||
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<TUserProfile>} Promise resolving to the current user's profile details
|
||||
* @throws {Error} If the API request fails
|
||||
*/
|
||||
async profile(): Promise<TUserProfile> {
|
||||
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<TUserProfile>} data Data to update the user's profile with
|
||||
* @returns {Promise<TUserProfile>} Promise resolving to the updated user's profile details
|
||||
* @throws {Error} If the API request fails
|
||||
*/
|
||||
async updateProfile(data: Partial<TUserProfile>): Promise<TUserProfile> {
|
||||
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<IUser>} Promise resolving to the current instance admin details
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue