import DFWModule from "./DFWModule"; import { DFWScheme } from "../.."; import { Router, RequestHandler } from "express"; import { AxiosRequestConfig, AxiosResponse, AxiosStatic } from "axios"; import { UploadOptions, UploadConfig } from "./UploadManager"; export declare type BootCallback = (dfw: DFWScheme, boot: any) => Promise; export declare type APIMethods = "get" | "put" | "post" | "delete" | "options" | "link"; export declare type APIFunction = ((dfw: DFWScheme) => Promise) | ((dfw: DFWScheme) => any); export declare class APIListener { caller: APIFunction; config: DFWListenerConfig; constructor(f: APIFunction, cfg?: DFWListenerConfig); } export default class APIManager extends DFWModule { private bootCallbacks; /** * * @param dfw */ touchAsync(dfw: DFWScheme): Promise; /** * * @param dfw */ getBootAsync(dfw: DFWScheme): Promise; /** * * @param bootc */ addBootCallback(bootc: BootCallback): void; /** * * @param dfw */ response(dfw: DFWScheme, data: {}): void; /** * fetch data to the server * @param path * @param config */ fetch(path: string, config?: AxiosRequestConfig): Promise; /** * add an API listener * @param path * @param f * @param method * @param router */ addListener(path: string, f: APIFunction, cfg?: DFWListenerConfig | APIMethods): void; /** * synonym of addUploadListener from UploadManager * @param path * @param dfwConfig * @param uploadConfig */ addUploadListener(path: string, dfwConfig?: DFWListenerConfig, uploadConfig?: UploadOptions): void; /** * @returns boolean true if checking is succeed or false if one rule fail */ validateListenerConfigRules(dfw: DFWScheme, settings: DFWListenerConfig): Promise; /** * Return an instance of axios */ static axios: AxiosStatic; } /** * Configuration for listener in DFW */ export interface DFWListenerConfig { method?: APIMethods; router?: Router; middleware?: RequestHandler[]; security?: { session?: boolean; credentials?: string | string[]; access?: string | string[]; uploads?: boolean | UploadConfig; }; validation?: { body?: string[]; query?: string[]; }; } export declare type DFWBasicBoot = { session: { isLogged: boolean; nick?: string; email?: string; credentials: { id: number; name: string; description?: string; }[]; access?: { id: number; name: string; description?: string; }[]; }; }; export declare type DFWBoot = T & DFWBasicBoot; export interface DFWAPISchema { /** * */ bootAsync: () => Promise<{}>; /** * */ error: (description?: string, ref?: string) => any; /** * */ success: (data?: any) => any; /** * */ response: (data: any) => void; /** * */ notFound: (description?: string) => void; }