import { Db } from "mongodb"; import type { RouteOptions, Server } from "restify"; import type { Next, Request, Response } from "./models/Http"; interface Locator { db: Db; broker: any; api: Server; } export declare enum Method { Post = "post", Get = "get", Put = "put", Patch = "patch", Del = "del", Head = "head", Options = "options" } type OmittedFields = "internal" | "method"; export declare function get(options: Omit): { (legacyServer?: Server): void; /** * Makes it possible to access the requestHandler through the exported function. * If you need to test the function separately, without starting the server */ requestHandler: (req: Request, res?: Response, next?: Next) => Promise | void>; /** Endpoint's full path (including any version number and internal prefix) */ PATH: string; unregister(): void; }; export declare function post(options: Omit): { (legacyServer?: Server): void; /** * Makes it possible to access the requestHandler through the exported function. * If you need to test the function separately, without starting the server */ requestHandler: (req: Request, res?: Response, next?: Next) => Promise | void>; /** Endpoint's full path (including any version number and internal prefix) */ PATH: string; unregister(): void; }; export declare function put(options: Omit): { (legacyServer?: Server): void; /** * Makes it possible to access the requestHandler through the exported function. * If you need to test the function separately, without starting the server */ requestHandler: (req: Request, res?: Response, next?: Next) => Promise | void>; /** Endpoint's full path (including any version number and internal prefix) */ PATH: string; unregister(): void; }; export declare function patch(options: Omit): { (legacyServer?: Server): void; /** * Makes it possible to access the requestHandler through the exported function. * If you need to test the function separately, without starting the server */ requestHandler: (req: Request, res?: Response, next?: Next) => Promise | void>; /** Endpoint's full path (including any version number and internal prefix) */ PATH: string; unregister(): void; }; export declare function del(options: Omit): { (legacyServer?: Server): void; /** * Makes it possible to access the requestHandler through the exported function. * If you need to test the function separately, without starting the server */ requestHandler: (req: Request, res?: Response, next?: Next) => Promise | void>; /** Endpoint's full path (including any version number and internal prefix) */ PATH: string; unregister(): void; }; /** Internal endpoints are not available through the API * @deprecated Use internal.get, internal.post, internal.put, internal.patch, internal.del instead */ export declare function internal(options: Omit): { (legacyServer?: Server): void; /** * Makes it possible to access the requestHandler through the exported function. * If you need to test the function separately, without starting the server */ requestHandler: (req: Request, res?: Response, next?: Next) => Promise | void>; /** Endpoint's full path (including any version number and internal prefix) */ PATH: string; unregister(): void; }; export declare namespace internal { var get: (options: Omit) => { (legacyServer?: Server): void; /** * Makes it possible to access the requestHandler through the exported function. * If you need to test the function separately, without starting the server */ requestHandler: (req: Request, res?: Response, next?: Next) => Promise | void>; /** Endpoint's full path (including any version number and internal prefix) */ PATH: string; unregister(): void; }; var post: (options: Omit) => { (legacyServer?: Server): void; /** * Makes it possible to access the requestHandler through the exported function. * If you need to test the function separately, without starting the server */ requestHandler: (req: Request, res?: Response, next?: Next) => Promise | void>; /** Endpoint's full path (including any version number and internal prefix) */ PATH: string; unregister(): void; }; var put: (options: Omit) => { (legacyServer?: Server): void; /** * Makes it possible to access the requestHandler through the exported function. * If you need to test the function separately, without starting the server */ requestHandler: (req: Request, res?: Response, next?: Next) => Promise | void>; /** Endpoint's full path (including any version number and internal prefix) */ PATH: string; unregister(): void; }; var patch: (options: Omit) => { (legacyServer?: Server): void; /** * Makes it possible to access the requestHandler through the exported function. * If you need to test the function separately, without starting the server */ requestHandler: (req: Request, res?: Response, next?: Next) => Promise | void>; /** Endpoint's full path (including any version number and internal prefix) */ PATH: string; unregister(): void; }; var del: (options: Omit) => { (legacyServer?: Server): void; /** * Makes it possible to access the requestHandler through the exported function. * If you need to test the function separately, without starting the server */ requestHandler: (req: Request, res?: Response, next?: Next) => Promise | void>; /** Endpoint's full path (including any version number and internal prefix) */ PATH: string; unregister(): void; }; } export interface JsonResponse { /** Response body */ body?: T; /** HTTP status code. @default 200 */ status?: number; /** Additional headers */ headers?: { totalcount?: number; [key: string]: any; }; } export { Next, Request, Response }; export interface EndpointOptions { /** Whether to add the endpoint to the metadata or not. @default true */ addToMetadata?: boolean; /** Whether the endpoint is internal or not */ internal?: boolean; /** The path to the endpoint */ path: string; /** The activity that is required to access this endpoint */ authorized?: string | string[]; /** Whether you need to be logged in or not to access the endpoint. Only needed if authorized is not used. */ authenticated?: boolean; /** HTTP method */ method: Method; /** * The request body schema, either a JSON schema or the name of a typescript type * (See below. The name must match the name of the file in ./api/schemas). **/ requestSchema?: object | string; /** * The query schema, either a JSON schema or the name of a typescript type * (See below. The name must match the name of the file in ./api/schemas). */ querySchema?: object | string; /** * The url param schema, either a JSON schema or the name of a typescript type * (See below. The name must match the name of the file in ./api/schemas). */ urlParamsSchema?: object | string; /** Additional route options */ opts?: RouteOptions; requestHandlers?: any[]; /** prefix for the path, e.g. /v1, defaults to what was set in setupApiInterface */ version?: string; /** The documentation for the endpoint */ documentation?: { /** Short description of the endpoint */ summary: string; /** Long description of the endpoint */ description?: string; /** Optional array of tags */ tags?: string[]; /** * Optional description for query params (can also be defined and described in the json schema, * since that's how we validate them) **/ query?: Record; /** * Optional description of url parameters. * Usually unnecessary since url params should be self descriptive, e.g. /dashboards/:dashboardId **/ parameters?: Record; /** Response schemas */ responses?: { /** HTTP status code */ status: number; /** An optional description of the response */ description?: string; /** * An optional response schema, either a JSON schema or the name of a typescript type * (See below. The name must match the name of the file in ./api/schemas). **/ schema?: any | any[]; }[]; }; /** The request handler function */ requestHandler: (req: Request, res?: Response, next?: Next) => Promise | void>; } export type EndpointMetadata = Omit; export declare const endpointMetadata: { [key in Method]: Record; }; export interface ApiInterfaceOptions { /** Name of the service */ serviceName: string; /** Default log level for the service */ serviceLogLevel: string; /** Whether to use typescript or not */ typescript: boolean; /** Global version of the API @default v1. Can be overridden per endpoint */ apiVersion: string; /** The base path to the schemas. @default api/schemas */ schemaBasePath?: string; /** The port to start the server on */ port: number; /** Whether to register the metadata endpoint or not. @default true */ registerMetadataEndpoint?: boolean; onUncaughtException?: (err: Error) => void; /** Maximum length of a parameter. @default 2000 after which the default route is used */ maxParamLength?: number; legacyMode?: boolean; } export declare function getApiOptions(): ApiInterfaceOptions; export declare function setupApiInterface(options: Omit): Promise; /** * Legacy option to enable legacy mode where the server is started with hiot-restify5. * Should only be used (as a temporary solution) where the new server setup is not possible without a complete refactor */ export declare function setupInterfaceLegacy(options: Omit): (locator: Locator) => Promise; export declare function getServiceName(): string;