1 | /**
|
2 | * This file is part of the @egodigital/egoose distribution.
|
3 | * Copyright (c) e.GO Digital GmbH, Aachen, Germany (https://www.e-go-digital.com/)
|
4 | *
|
5 | * @egodigital/egoose is free software: you can redistribute it and/or modify
|
6 | * it under the terms of the GNU Lesser General Public License as
|
7 | * published by the Free Software Foundation, version 3.
|
8 | *
|
9 | * @egodigital/egoose is distributed in the hope that it will be useful, but
|
10 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12 | * Lesser General Public License for more details.
|
13 | *
|
14 | * You should have received a copy of the GNU Lesser General Public License
|
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16 | */
|
17 | /// <reference types="node" />
|
18 | import { Response } from 'express';
|
19 | /**
|
20 | * An entry for an API error.
|
21 | */
|
22 | export interface ApiError {
|
23 | /**
|
24 | * German (de)
|
25 | */
|
26 | de?: string;
|
27 | /**
|
28 | * English (en)
|
29 | */
|
30 | en: string;
|
31 | }
|
32 | /**
|
33 | * An entry for an API error with a key.
|
34 | */
|
35 | export interface ApiErrorWithKey extends ApiError {
|
36 | key: string;
|
37 | }
|
38 | /**
|
39 | * An api result.
|
40 | */
|
41 | export interface ApiResult {
|
42 | /**
|
43 | * The (optional) data.
|
44 | */
|
45 | data?: any;
|
46 | /**
|
47 | * A list of one or more error keys.
|
48 | */
|
49 | errors?: string | string[];
|
50 | /**
|
51 | * A value, which indicates if the operation was successfull or not.
|
52 | */
|
53 | success: boolean;
|
54 | }
|
55 | /**
|
56 | * Options for 'createMonitoringApiResult()' function.
|
57 | */
|
58 | export interface CreateMonitoringApiResultOptions {
|
59 | /**
|
60 | * The custom working directory.
|
61 | */
|
62 | cwd?: string;
|
63 | /**
|
64 | * An optional function, which checks a database connection.
|
65 | */
|
66 | databaseConnectionChecker?: () => boolean | PromiseLike<boolean>;
|
67 | /**
|
68 | * Use 'MemAvailable' from 'meminfo' for detecting free ram.
|
69 | */
|
70 | useMemAvailable?: boolean;
|
71 | /**
|
72 | * Also return version information about the app.
|
73 | */
|
74 | withAppVersion?: boolean;
|
75 | }
|
76 | /**
|
77 | * A possible value for 'importApiErrors()' and 'importApiErrorsSync()' functions.
|
78 | *
|
79 | * If STRING: The path to the JSON file to import.
|
80 | * If BUFFER: The binary content as UTF-8 JSON data.
|
81 | * If OBJECT or ARRAY: One or more items to import.
|
82 | */
|
83 | export declare type ImportApiErrorsArgument = string | Buffer | ApiErrorWithKey | ApiErrorWithKey[];
|
84 | /**
|
85 | * A result of a 'createMonitoringApiResult()' function call.
|
86 | */
|
87 | export interface MonitoringApiResult {
|
88 | /**
|
89 | * The CPU usage in percentage.
|
90 | */
|
91 | cpu_load: number;
|
92 | /**
|
93 | * Indicates if a database connection is established or available.
|
94 | */
|
95 | database_connected?: boolean;
|
96 | /**
|
97 | * The total disk space, in bytes.
|
98 | */
|
99 | disk_space: number;
|
100 | /**
|
101 | * The total disk space in use, in bytes.
|
102 | */
|
103 | disk_space_used: number;
|
104 | /**
|
105 | * The total ram, in bytes.
|
106 | */
|
107 | ram: number;
|
108 | /**
|
109 | * The ram in use, in bytes.
|
110 | */
|
111 | ram_used: number;
|
112 | /**
|
113 | * Information about the version of the app.
|
114 | */
|
115 | version?: MonitoringApiAppVersion;
|
116 | }
|
117 | /**
|
118 | * Stores version information about the app for a monitoring API result.
|
119 | */
|
120 | export interface MonitoringApiAppVersion {
|
121 | /**
|
122 | * The last commit date. Contains (false), if failed.
|
123 | */
|
124 | date?: string | false;
|
125 | /**
|
126 | * The last commit hash. Contains (false), if failed.
|
127 | */
|
128 | hash?: string | false;
|
129 | }
|
130 | /**
|
131 | * Additional options for 'sendResponse()' function.
|
132 | */
|
133 | export interface SendResponseOptions {
|
134 | /**
|
135 | * A custom status code.
|
136 | */
|
137 | code?: number;
|
138 | /**
|
139 | * Returns error keys only or ApiError objects.
|
140 | */
|
141 | errorKeysOnly?: boolean;
|
142 | }
|
143 | /**
|
144 | * Global list of API errors.
|
145 | */
|
146 | export declare const API_ERRORS: {
|
147 | [name: string]: ApiError;
|
148 | };
|
149 | /**
|
150 | * Creates an object for an result of a monitoring API endpoint.
|
151 | *
|
152 | * @param {CreateMonitoringApiResultOptions} [opts] Custom options.
|
153 | *
|
154 | * @return {Promise<MonitoringApiResult>} The promise with the result (object).
|
155 | */
|
156 | export declare function createMonitoringApiResult(opts?: CreateMonitoringApiResultOptions): Promise<MonitoringApiResult>;
|
157 | /**
|
158 | * Imports the data for 'API_ERRORS' constant.
|
159 | *
|
160 | * @param {ImportApiErrorsArgument} errors The items to import.
|
161 | */
|
162 | export declare function importApiErrors(errors: ImportApiErrorsArgument): Promise<void>;
|
163 | /**
|
164 | * Imports the data for 'API_ERRORS' constant (sync).
|
165 | *
|
166 | * @param {ImportApiErrorsArgument} errors The items to import.
|
167 | */
|
168 | export declare function importApiErrorsSync(errors: ImportApiErrorsArgument): void;
|
169 | /**
|
170 | * Sends an API response.
|
171 | *
|
172 | * @param {Response} res The response context.
|
173 | * @param {ApiResult} result The result context.
|
174 | * @param {SendResponseOptions} [opts] Custom options.
|
175 | *
|
176 | * @return {Response} The current response context.
|
177 | */
|
178 | export declare function sendResponse(res: Response, result: ApiResult, opts?: SendResponseOptions): Response;
|