///
import * as http from "http";
import APISettings from "./APISettings";
import MinimumAPISettings from "./MinimumAPISettings";
import { APIUserRole } from "../models/APIUser";
import { Express } from "express";
import { Logger } from "winston";
import TypedEmitter from "typed-emitter";
import { DeepReadonly } from "ts-essentials";
export type APIEvents = {
/** Fires when the http server starts listening to incoming requests. */
start: (err?: Error) => void;
/** Fires when the http server starts stops to incoming requests. */
stop: (err?: Error) => void;
/** Fires when an error occurs. */
error: (err: Error | any) => void;
};
declare const VantAPI_base: new () => TypedEmitter;
export declare class VantAPI extends VantAPI_base {
/**
* The api's settings. Change these by using {@link VantAPI.configure}.
*/
settings: APISettings;
log: Logger;
app: Express;
server: http.Server;
/**
* Holds the four base api keys which are generated while configuring the vant api for the first time.
*/
readonly keys: DeepReadonly<{
[Property in APIUserRole]?: string;
}>;
/**
* @hidden
*/
constructor();
/**
* Configures the vant api. You can setup the default units, the used port and the logging behaviour.
* Pass `{ useEnvironmentVariables: true }` to setup these settings using environment variables (e.g. stored in a `.env` file).
* @param settings
*/
configure(settings: MinimumAPISettings): void;
/**
* Starts the http server on the configured port. The promise resolves when the server starts listening for incoming requests.
*/
start(): Promise;
/**
* Stops the http server. If the server hasn't been started yet no error will occur (but a warning will be logged).
*/
stop(): Promise;
/**
* Generates a new api key for your api with the passed role. Once the key has been stored in the
* database the promise resolves and the `uuidv4` key is returned as string.
*
* **Role explanations**
* - `"read"`: One can use read routes only (requesting any kind of weather data)
* - `"write"`: One can use write routes only (uploading new weather data using post requests)
* - `"readwrite"`: Once can use all write and read routes.
* - `"admin"`: One can use all write / read routes and generate new api keys.
* @param role your desired role
* @returns the uuidv4 api key as string
*/
generateAPIKey(role: APIUserRole): Promise;
/**
* @hidden
*/
private createServer;
/**
* @hidden
*/
private loadEnvironmentVariablesAndConfigureLogger;
/**
* @hidden
*/
private generateAPIKeysIfNotExistent;
/**
* @hidden
*/
private generateApiKeyIfNotExistent;
}
/**
* Represents the vant api itself. Using this object you can...
* - change the api's settings
* - start and stop the http server
* - generate additional api keys
* - access the automatically generated base api keys
* - listen to events
*
* The vant api's endpoints are documented [here](https://harrydehix.github.io/vant-api/specification.html).
*
* You can also access the vant api's internally used components (e.g. the http server object, the express app, ...) and make custom changes.
* But be careful with it, otherwise the API won't work properly anymore.
*/
declare const api: VantAPI;
export default api;