bugwarden
Version:
BugWarden is an open-source Node.js module that guards your applications against bugs and errors. With integrated error handling and reporting, it ensures real-time monitoring of server-side issues, alerting you on services like Slack and email, helping y
153 lines (140 loc) • 6.24 kB
text/typescript
import { Request, Response, NextFunction } from 'express';
declare class BugwardenLogProperties {
ip?: string | undefined;
timestamp?: string | undefined;
method?: string | undefined;
originalURL?: string | undefined;
httpVersion?: string | undefined;
statusCode?: string | undefined;
contentLength?: string | undefined;
referrer?: string | undefined;
userAgent?: string | undefined;
responseTime?: string | undefined;
constructor(ip?: string | undefined, timestamp?: string | undefined, method?: string | undefined, originalURL?: string | undefined, httpVersion?: string | undefined, statusCode?: string | undefined, contentLength?: string | undefined, referrer?: string | undefined, userAgent?: string | undefined, responseTime?: string | undefined);
}
type BugwardenLoggingOption =
| boolean
| (keyof BugwardenLogProperties)[]
| undefined;
interface BugwardenNotificationConfig {
/**
* Specifies the routes for which notifications should be triggered.
* It can be set to "all" for all routes, a specific route as a string, or an array of specific routes.
*
* @property {RoutesType} routes
* @example
* - "all"
* - "/api/user" for a specific route
* - "/api/user/*" for all routes starting with "/api/user/
* - "/api/user,/api/admin,/api/public/*" multiple routes separated by comma ","
*/
routes: string;
/**
* Specifies the HTTP status code(s) for which notifications should be triggered.
* It can be set to "all" for all status codes, or a specific status code as a string.
*
* @property {HttpStatusCode} onStatus
* @example
* - "all" for all status codes
* - "2xx" for all 200 status codes
* - "3xx" for all 300 status codes
* - "4xx,5xx" for all 400 and 500 status codes
*/
onStatus: string;
/**
* The message to be included in the Slack notification when triggered.
*
* @property {string} message
* @example
* "A new bug has been detected in the system."
* - You can use the following parameters in your message
* - "{ip}"
* - "{timestamp}"
* - "{method}"
* - "{original-url}"
* - "{http-version}"
* - "{status-code}"
* - "{content-length}"
* - "{referer}"
* - "{user-agent}"
* - "{response-time}"
*/
message: string;
}
/**
* Configuration options for Slack notifications in Bugwarden.
*
* @interface BugwardenSlackNotificationOptions
*/
interface BugwardenSlackNotificationOptions {
/**
**Slack webhook URL*
1. Create a Slack app: If you don’t have one already, create your Slack app. Pick a name, choose a workspace to
associate your app with, and then click Create App.
2. Enable Incoming Webhooks: After creating, you’ll be redirected to the settings page for your new app. From here select the Incoming Webhooks feature, and click the Activate Incoming Webhooks toggle to switch it on.
3. Create an Incoming Webhook: Now that Incoming Webhooks are enabled, the settings page should refresh and some extra options will appear. One of those options will be a button marked Add New Webhook to Workspace, and you should click it.
3. Authorize your app: Go ahead and pick a channel that the app will post to, and then click to Authorize your app.
4. Get your Webhook URL: You’ll be sent back to your app settings, and you should now see a new entry under the Webhook URLs for Your Workspace section, with a Webhook URL.
*/
webhookUrl: string;
/**
* Configuration for triggering Slack notifications.
*
* @property {NotificationConfig} notificationConfig
* @description
* An object containing properties to customize the triggering of Slack notifications. The following properties are available:
*
* - `routes`: Specifies the routes for which notifications should be triggered. It can be set to "all" for all routes, a specific route as a string, or an array of specific routes.
* - @property {RoutesType} routes
* - @example
* - "all"
* - "/api/user"
* - ["/api/posts", "/api/comments"]
*
* - `onStatus`: Specifies the HTTP status code(s) for which notifications should be triggered. It can be set to "all" for all status codes, or a specific status code as a string or number.
* - @property {HttpStatusCode} onStatus
* - @example
* - "all"
* - "all200"
* - 404
* - [400, 401, 404, "all500"]
*
* - `message`: The message to be included in the Slack notification when triggered.
* - @property {string} message
* - @example
* - "A new bug has been detected in the system."
*/
notificationConfig: BugwardenNotificationConfig[] & {
0: BugwardenNotificationConfig;
};
}
/**
* Configuration options for Bugwarden
*
* @class BugwardenOptions
*/
declare class BugwardenOptions {
logging?: BugwardenLoggingOption;
configureSlackNotification?: BugwardenSlackNotificationOptions | undefined;
/**
* Constructs an instance of BugwardenOptions.
*
* @constructor
* @param {BugwardenLoggingOption} logging - Optional logging configuration for Bugwarden.
* @param {BugwardenSlackNotificationOptions[]} configureSlackNotification - Optional Slack notification configuration for Bugwarden.
*/
constructor(logging?: BugwardenLoggingOption, configureSlackNotification?: BugwardenSlackNotificationOptions | undefined);
}
/**
* BugWarden middleware logs details of incoming HTTP requests and their corresponding responses,
* including IP address, timestamp, HTTP method, URL, status code, content length,
* referrer, user agent, and response time.
*
*
* @param req - Express Request object representing the incoming HTTP request.
* @param res - Express Response object representing the outgoing HTTP response.
* @param next - Express NextFunction to pass control to the next middleware in the stack.
* @returns void
*/
declare function bugwarden(options?: BugwardenOptions): (req: Request, res: Response, next: NextFunction) => void;
export { bugwarden };