-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
52 lines (49 loc) · 2.8 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
export = ServerBase;
/**
* A module for creating a server-state server. This handles modules and responses and has to get attached to an Express app.
* @copyright 2019 by server-state
* @licence MIT
*/
declare class ServerBase {
/**
* Creates a ServerBase instance that can then get attached to an Express application
* @param config Configuration for the server-base module, including options regarding logging
*/
constructor(config?: {
/**
* If true, messages will get logged via stdout and stderr
* @default true
*/
logToConsole?: boolean,
/**
* If `true`, messages will get logged to the file specified as `logFilePath`.
* @default false
*/
logToFile?: boolean,
/**
* Path to the file in which messages should get logged (in case `logToFile` is `true`).
* @default './server-state.log'
*/
logFilePath?: string,
/**
* A callback that checks whether the current user (of the request) is authorized to access the resource
* @param req The HTTP request to evaluate tokens or other forms of authentication
* @param authorizedGroups The groups that have the authorization to access the resource
* @return Is authorized? In other words: Is there an intersection between the groups the user belongs to and `authorizedGroups`?
*/
isAuthorized?: (req: Express.Request, authorizedGroups: string[]) => boolean,
});
/**
* Adds a server module function (as specified in https://github.com/server-state/specs/blob/master/terminology/server-module-function.md) under a given name resulting in a server module function (as specified in https://github.com/server-state/specs/blob/master/terminology/server-module.md), making it available under `/api/v1/[name]`.
* @param name The name of the module. Must be unique (i.e., not registered before). Otherwise, the module will be skipped and an error message logged.
* @param moduleFunction The function defining the module (SMF). Must either return a Promise for or a JSON serializable value or throw with an error message in case of failure (resulting in the error message getting logged and a `HTTP 500` response).
* @param authorizedGroups Groups authorized to access this module
* @param moduleOptions Options getting passed to the SMF as first argument. Can be any type, but usually will be a configuration object.
*/
addModule(name: string, moduleFunction: (options: any) => any | Promise<any>, authorizedGroups?: string[], moduleOptions?: any)
/**
* Attaches the server base to the passed Express `app`, handling routes under `/api/` there.
* @param app The Express app to which the routes get added.
*/
init(app: Express.Application);
}