UNPKG

admin-bro

Version:
116 lines (115 loc) 4.04 kB
import { ActionContext, ActionRequest, RecordActionResponse } from '../actions/action.interface'; import RecordJSON from '../decorators/record-json.interface'; /** * Controller responsible for the autogenerated API: `/admin_root/api/...`, where * admin_root is the `rootPath` given in {@link AdminBroOptions}. * * The best way to utilise it is to use {@link ApiClient} on the frontend. * * ### Available API endpoints * * | Endpoint | Method | Description | * |--------------------------|-----------------------|-------------| * | `.../api/resources/{resourceId}/search/{query}` | {@link ApiController#search} | Search record by query string | * | `.../api/resources/{resourceId}/actions/{action}` | {@link ApiController#resourceAction} | Perform cusomised resource action | * | `.../api/resources/{resourceId}/records/{recordId}/{action}` | {@link ApiController#recordAction} | Perform cusomised record action | * | `.../api/dashboard` | {@link ApiController#dashboard} | Perform cusomised dashboard action | * * @hideconstructor */ declare class ApiController { private _admin; private currentAdmin; /** * @param {Object} options * @param {AdminBroOptions} options.admin * @param {CurrentAdmin} [currentAdmin] */ constructor({ admin }: { admin: any; }, currentAdmin: any); /** * Returns context for given action * @private * * @param {ActionRequest} request request object * @return {Promise<ActionContext>} action context */ getActionContext(request: ActionRequest): Promise<ActionContext>; /** * Search records by query string. * * Handler function reponsible for a `.../api/resources/{resourceId}/search/{query}` route * * @param {ActionRequest} request * * @return {Promise<SearchResponse>} found records */ search(request: ActionRequest): Promise<SearchResponse>; /** * Performs a customized {@link Action resource action}. * To call it use {@link ApiClient#resourceAction} method. * * Handler function reponsible for a `.../api/resources/{resourceId}/actions/{action}` * * @param {ActionRequest} request * @param {Object} response * * @return {Object} action response */ resourceAction(request: ActionRequest, response: any): Promise<any>; /** * Performs a customized {@link Action record action}. * To call it use {@link ApiClient#recordAction} method. * * Handler function reponsible for a `.../api/resources/{resourceId}/records/{recordId}/{action}` * * @param {ActionRequest} request * @param {any} response * * @return {RecordActionResponse} action response * @throws ConfigurationError When given record action doesn't return {@link RecordJSON} * @throws ForbiddenError When user cannot perform given action: {@linkAction.isAccessible} returns false */ recordAction(request: ActionRequest, response: any): Promise<RecordActionResponse>; /** * Gets optional data needed by the dashboard. * To call it use {@link ApiClient#dashboard} method. * * Handler function reponsible for a `.../api/dashboard` * * @param {any} request * @param {any} response * * @return {Promise<any>} action response */ dashboard(request: any, response: any): Promise<any>; } export default ApiController; /** * Response of a Search action in the API * @memberof ApiController * @alias SearchResponse */ export declare type SearchResponse = { /** * List of records */ records: Array<RecordJSON>; }; /** * Response of a Search action in the API * @memberof ApiController * @alias SearchRecord */ export declare type SearchRecord = { /** * record title - value of its titleProperty */ title: string; /** * Record Id */ id: string; };