UNPKG

@devx-commerce/plugin-product-reviews

Version:
76 lines (75 loc) 2.48 kB
import { MedusaResponse } from "@medusajs/framework"; /** * Standard API response format with generic type support */ export interface ApiResponse<T = any> { data: T | null; message: string; status: number; success: boolean; error?: { code: string; details?: Record<string, unknown>; }; } /** * Standard HTTP status codes */ export declare enum HttpStatus { OK = 200, CREATED = 201, BAD_REQUEST = 400, UNAUTHORIZED = 401, FORBIDDEN = 403, NOT_FOUND = 404, INTERNAL_SERVER_ERROR = 500 } /** * Standard error codes */ export declare enum ErrorCode { VALIDATION_ERROR = "VALIDATION_ERROR", AUTHENTICATION_ERROR = "AUTHENTICATION_ERROR", AUTHORIZATION_ERROR = "AUTHORIZATION_ERROR", NOT_FOUND_ERROR = "NOT_FOUND_ERROR", INTERNAL_ERROR = "INTERNAL_ERROR" } /** * Creates a success response with standard format * @param data Response data * @param message Success message (defaults to "OK") * @param status HTTP status code (defaults to 200) * @returns Standardized success response */ export declare function createSuccessResponse<T>(data: T, message?: string, status?: HttpStatus): ApiResponse<T>; /** * Creates an error response with standard format * @param message Error message * @param status HTTP status code * @param code Error code * @param details Additional error details * @returns Standardized error response */ export declare function createErrorResponse(message: string, status: HttpStatus, code: ErrorCode, details?: Record<string, unknown>): ApiResponse<null>; /** * Utility function to send a standardized API response * @param res Response object * @param response Standardized API response */ export declare function sendApiResponse<T>(res: MedusaResponse, response: ApiResponse<T>): void; /** * Helper function to create validation error response */ export declare function createValidationErrorResponse(message: string, details?: Record<string, unknown>): ApiResponse<null>; /** * Helper function to create authentication error response */ export declare function createAuthenticationErrorResponse(message?: string): ApiResponse<null>; /** * Helper function to create not found error response */ export declare function createNotFoundErrorResponse(message?: string): ApiResponse<null>; /** * Helper function to create internal server error response */ export declare function createInternalErrorResponse(message?: string): ApiResponse<null>;