Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 17f1225

Browse files
committedMay 12, 2025
📝(frontend) Update documentation
Signed-off-by: Zorin95670 <[email protected]>
1 parent 464d602 commit 17f1225

File tree

9 files changed

+111
-15
lines changed

9 files changed

+111
-15
lines changed
 

‎CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ and this project adheres to
1212

1313
✨ Add a custom callout block to the editor #892
1414

15+
## Changed
16+
17+
- 📝(frontend) Update documentation
18+
1519
## [3.2.1] - 2025-05-06
1620

1721
## Fixed
Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,52 @@
1+
/**
2+
* Generic interface for representing an API error structure.
3+
*
4+
* @template T - Optional type of additional data returned with the error.
5+
*/
16
interface IAPIError<T = unknown> {
7+
/** HTTP status code or API-defined error code */
28
status: number;
9+
/** Optional list of error causes (e.g., validation issues) */
310
cause?: string[];
11+
/** Optional extra data provided with the error */
412
data?: T;
513
}
614

15+
/**
16+
* Custom error class for representing API errors.
17+
* Extends the native Error object with additional context such as HTTP status,
18+
* causes, and extra data returned by the API.
19+
*
20+
* @template T - Optional type of the `data` field
21+
*/
722
export class APIError<T = unknown> extends Error implements IAPIError<T> {
823
public status: IAPIError['status'];
924
public cause?: IAPIError['cause'];
1025
public data?: IAPIError<T>['data'];
1126

27+
/**
28+
* Constructs a new APIError instance.
29+
*
30+
* @param message - The human-readable error message.
31+
* @param status - The HTTP status code or equivalent.
32+
* @param cause - (Optional) List of strings describing error causes.
33+
* @param data - (Optional) Any additional data returned by the API.
34+
*/
1235
constructor(message: string, { status, cause, data }: IAPIError<T>) {
1336
super(message);
14-
1537
this.name = 'APIError';
1638
this.status = status;
1739
this.cause = cause;
1840
this.data = data;
1941
}
2042
}
2143

44+
/**
45+
* Type guard for checking if a value is an instance of APIError.
46+
*
47+
* @param error - The value to check.
48+
* @returns True if the value is an instance of APIError.
49+
*/
2250
export const isAPIError = (error: unknown): error is APIError => {
2351
return error instanceof APIError;
2452
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
1+
/**
2+
* Returns the base URL for the backend API.
3+
*
4+
* Priority:
5+
* 1. Uses NEXT_PUBLIC_API_ORIGIN from environment variables if defined.
6+
* 2. Falls back to the browser's window.location.origin if in a browser environment.
7+
* 3. Defaults to an empty string if executed in a non-browser environment without the env variable.
8+
*
9+
* @returns The backend base URL as a string.
10+
*/
111
export const backendUrl = () =>
212
process.env.NEXT_PUBLIC_API_ORIGIN ||
313
(typeof window !== 'undefined' ? window.location.origin : '');
414

15+
/**
16+
* Constructs the full base API URL, including the versioned path (e.g., `/api/v1.0/`).
17+
*
18+
* @param apiVersion - The version of the API (defaults to '1.0').
19+
* @returns The full versioned API base URL as a string.
20+
*/
521
export const baseApiUrl = (apiVersion: string = '1.0') =>
622
`${backendUrl()}/api/v${apiVersion}/`;

‎src/frontend/apps/impress/src/api/helpers.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,17 @@ export type DefinedInitialDataInfiniteOptionsAPI<
2222
>;
2323

2424
/**
25-
* @param param Used for infinite scroll pagination
26-
* @param queryConfig
27-
* @returns
25+
* Custom React hook that wraps React Query's `useInfiniteQuery` for paginated API requests.
26+
*
27+
* @template T - Type of the request parameters.
28+
* @template Q - Type of the API response, which must include an optional `next` field for pagination.
29+
*
30+
* @param {string} key - Unique key to identify the query in the cache.
31+
* @param {(props: T & { page: number }) => Promise<Q>} api - Function that fetches paginated data from the API. It receives the params merged with a page number.
32+
* @param {T} param - Static parameters to send with every API request (excluding the page number).
33+
* @param {DefinedInitialDataInfiniteOptionsAPI<Q>} [queryConfig] - Optional configuration passed to `useInfiniteQuery` (e.g., stale time, cache time).
34+
*
35+
* @returns Return value of `useInfiniteQuery`, including data, loading state, fetchNextPage, etc.
2836
*/
2937
export const useAPIInfiniteQuery = <T, Q extends { next?: APIList<Q>['next'] }>(
3038
key: string,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
1+
/**
2+
* Generic interface representing a paginated API response.
3+
*
4+
* Commonly used for endpoints that return list results with pagination metadata.
5+
*
6+
* @template T - The type of items in the `results` array.
7+
*/
18
export interface APIList<T> {
9+
/** Total number of items across all pages */
210
count: number;
11+
12+
/** URL to the next page of results, if available (can be null or undefined) */
313
next?: string | null;
14+
15+
/** URL to the previous page of results, if available (can be null or undefined) */
416
previous?: string | null;
17+
18+
/** The list of items for the current page */
519
results: T[];
620
}

‎src/frontend/apps/impress/src/api/utils.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
/**
2+
* Extracts error information from an HTTP `Response` object.
3+
*
4+
* This is typically used to parse structured error responses from an API
5+
* and normalize them into a consistent format with `status`, `cause`, and optional `data`.
6+
*
7+
* @param response - The HTTP response object from `fetch()`.
8+
* @param data - Optional custom data to include with the error output.
9+
* @returns An object containing:
10+
* - `status`: HTTP status code from the response
11+
* - `cause`: A flattened list of error messages, or undefined if no body
12+
* - `data`: The optional data passed in
13+
*/
114
export const errorCauses = async (response: Response, data?: unknown) => {
215
const errorsBody = (await response.json()) as Record<
316
string,
@@ -18,7 +31,11 @@ export const errorCauses = async (response: Response, data?: unknown) => {
1831
};
1932

2033
/**
21-
* Retrieves the CSRF token from the document's cookies.
34+
* Retrieves the CSRF token from the browser's cookies.
35+
*
36+
* Assumes the CSRF token is stored as a cookie named "csrftoken".
37+
*
38+
* @returns The CSRF token string if found, otherwise `undefined`.
2239
*/
2340
export function getCSRFToken() {
2441
return document.cookie

‎src/frontend/apps/impress/src/features/docs/doc-export/utils.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,16 @@ export function downloadFile(blob: Blob, filename: string) {
1919
}
2020

2121
/**
22-
* Convert SVG to PNG
23-
* @param svgText - The SVG text to convert
24-
* @returns The PNG data URL
22+
* Converts an SVG string into a PNG image and returns it as a data URL.
23+
*
24+
* This function creates a canvas, parses the SVG, calculates the appropriate height
25+
* to preserve the aspect ratio, and renders the SVG onto the canvas using Canvg.
26+
*
27+
* @param {string} svgText - The raw SVG markup to convert.
28+
* @param {number} width - The desired width of the output PNG (height is auto-calculated to preserve aspect ratio).
29+
* @returns {Promise<string>} A Promise that resolves to a PNG image encoded as a base64 data URL.
30+
*
31+
* @throws Will throw an error if the canvas context cannot be initialized.
2532
*/
2633
export async function convertSvgToPng(svgText: string, width: number) {
2734
// Create a canvas and render the SVG onto it

‎src/frontend/apps/impress/src/features/service-worker/service-worker.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,15 @@ setCacheNameDetails({
3838
});
3939

4040
/**
41-
* In development, use NetworkFirst strategy, in production use CacheFirst strategy
42-
* We will be able to test the application in development without having to clear the cache.
43-
* @param url
44-
* @param options
45-
* @returns strategy
41+
* Chooses the appropriate caching strategy based on the environment and request context.
42+
*
43+
* - In **development**, or for **API requests**, or **HTML pages**, it returns a `NetworkFirst` strategy
44+
* to prioritize fresh responses and ease debugging without needing to clear caches.
45+
* - In **production** (for non-API, non-HTML content), it returns a `CacheFirst` strategy
46+
* to favor performance and offline access.
47+
*
48+
* @param {NetworkFirstOptions | StrategyOptions} [options] - Configuration options for the caching strategy.
49+
* @returns {NetworkFirst | CacheFirst} The selected Workbox strategy instance.
4650
*/
4751
const getStrategy = (
4852
options?: NetworkFirstOptions | StrategyOptions,

‎src/frontend/servers/y-provider/src/servers/appServer.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import { logger } from '../utils';
1717
/**
1818
* init the collaboration server.
1919
*
20-
* @param port - The port on which the server listens.
21-
* @param serverSecret - The secret key for API authentication.
2220
* @returns An object containing the Express app, Hocuspocus server, and HTTP server instance.
2321
*/
2422
export const initServer = () => {

0 commit comments

Comments
 (0)
Please sign in to comment.