traxx
Version:
Asynchronous route-level analytics for Express.js. Tracks latency, request data, and errors. Supports notifications via Teams, Slack, and Google Chat. MongoDB + BullMQ + Redis.
65 lines (54 loc) • 1.49 kB
TypeScript
import type { RequestHandler } from "express";
import type { Model } from "mongoose";
declare namespace Traxx {
interface NotificationRange {
min: number;
max: number;
}
type StatusCodesConfig = number[] | NotificationRange;
type NotificationChannelType = "teams" | "slack" | "googleChat";
interface NotificationChannel {
type: NotificationChannelType;
options: {
webhookUrl: string;
[key: string]: unknown;
};
}
interface NotificationConfig {
statusCodes: StatusCodesConfig;
channels: NotificationChannel[];
}
interface TraxxOptions {
mongoUri: string;
redisUri: string;
logIPAddress?: boolean;
notifications?: NotificationConfig | null;
}
interface TraxxErrorInfo {
message?: string | null;
stack?: string | null;
}
interface TraxxLog {
method?: string;
route?: string;
statusCode?: number;
latency?: number;
timestamp?: Date;
requestBody?: Record<string, unknown>;
requestParams?: Record<string, unknown>;
requestQuery?: Record<string, unknown>;
responseBody?: Record<string, unknown>;
customFields?: Record<string, unknown>;
ipAddress?: string | null;
error?: TraxxErrorInfo;
createdAt?: Date;
updatedAt?: Date;
}
}
declare class Traxx {
constructor(options: Traxx.TraxxOptions);
init(): Promise<void>;
middleware(customFields?: Record<string, unknown>): RequestHandler;
model(): Model<Traxx.TraxxLog>;
}
export = Traxx;