UNPKG

6.43 kBTypeScriptView Raw
1/// <reference types="node" />
2
3import { EventEmitter } from "events";
4import { Agent, ClientRequest, IncomingMessage, OutgoingHttpHeaders, ServerResponse } from "http";
5
6// expose all methods of `Client` class since raven exposes a singleton instance
7// todo: there has to be a better way of doing this that doesn't require duplicating so much stuff
8export function config(options?: ConstructorOptions): Client;
9export function config(dsn?: string | false, options?: ConstructorOptions): Client;
10export function install(cb?: FatalErrorCallback): Client;
11export function uninstall(): Client;
12export function wrap<T>(func: () => T): () => T;
13export function wrap<T>(options: any, func: () => T): () => T;
14export function interceptErr(ctx: any): Client; // todo: part of public?
15export function setContext(ctx: any): Client;
16export function mergeContext(ctx: any): Client;
17export function getContext(): any;
18export function requestHandler(): (req: IncomingMessage, res: ServerResponse, next: () => void) => void;
19export function errorHandler(): (e: Error, req: IncomingMessage, res: ServerResponse, next: () => void) => void;
20export function captureException(e: Error, cb?: CaptureCallback): string;
21export function captureException(e: Error, options?: CaptureOptions, cb?: CaptureCallback): string;
22export function captureMessage(message: string, cb?: CaptureCallback): string;
23export function captureMessage(message: string, options?: CaptureOptions, cb?: CaptureCallback): string;
24export function captureBreadcrumb(breadcrumb: any): void;
25export function setDataCallback(fn: DataCallback): Client;
26export function setShouldSendCallback(fn: ShouldSendCallback): Client;
27export function context<T>(ctx: any, func: () => T): T;
28export function context<T>(func: () => T): T;
29
30export const version: string;
31export function disableConsoleAlerts(): void;
32
33export namespace utils {
34 function consoleAlert(msg: string): void;
35 function parseDSN(dsn: string | false): parsedDSN | false;
36}
37
38export class Client extends EventEmitter {
39 constructor(options?: ConstructorOptions);
40 constructor(dsn?: string | false, options?: ConstructorOptions);
41 config(options?: ConstructorOptions): this;
42 config(dsn?: string | false, options?: ConstructorOptions): this;
43 install(cb?: FatalErrorCallback): this;
44 uninstall(): this;
45 wrap<T>(func: () => T): () => T;
46 wrap<T>(options: any, func: () => T): () => T;
47 setContext(ctx: any): this;
48 mergeContext(ctx: any): this;
49 getContext(): any;
50 requestHandler(): (req: IncomingMessage, res: ServerResponse, next: () => void) => void;
51 errorHandler(): (e: Error, req: IncomingMessage, res: ServerResponse, next: () => void) => void;
52 captureException(error: Error, cb?: CaptureCallback): string;
53 captureException(error: Error, options?: CaptureOptions, cb?: CaptureCallback): string;
54 captureMessage(message: string, cb?: CaptureCallback): string;
55 captureMessage(message: string, options?: CaptureOptions, cb?: CaptureCallback): string;
56 captureBreadcrumb(breadcrumb: any): void;
57 setDataCallback(fn: DataCallback): this;
58 setShouldSendCallback(fn: ShouldSendCallback): this;
59 context<T>(ctx: any, func: () => T): T;
60 context<T>(func: () => T): T;
61 process(kwargs: any, cb?: () => void): void; // todo: part of public API?
62 process(eventId: string, kwargs: any, cb?: () => void): void; // todo: part of public API?
63}
64
65export interface ConstructorOptions {
66 name?: string | undefined;
67 logger?: string | undefined;
68 release?: string | undefined;
69 environment?: string | undefined;
70 tags?: { [key: string]: string } | undefined;
71 extra?: { [key: string]: any } | undefined;
72 dataCallback?: DataCallback | undefined;
73 maxReqQueueCount?: number | undefined;
74 sampleRate?: number | undefined;
75 sendTimeout?: number | undefined;
76 shouldSendCallback?: ShouldSendCallback | undefined;
77 transport?: transports.Transport | undefined;
78 captureUnhandledRejections?: boolean | undefined;
79 maxBreadcrumbs?: number | undefined;
80 autoBreadcrumbs?: boolean | { [breadcrumbType: string]: boolean } | undefined;
81 parseUser?: boolean | string[] | parseUserCallback | undefined;
82}
83
84export type parseUserCallback = (req: any) => any;
85
86export interface parsedDSN {
87 protocol: string;
88 public_key: string;
89 private_key: string;
90 host: string;
91 path: string;
92 project_id: string;
93 port: number;
94}
95
96export type FatalErrorCallback = (err: Error, sendErr: Error | null | undefined, eventId: string) => void;
97
98export type CaptureCallback = (sendErr: Error | null | undefined, eventId: any) => void;
99
100/**
101 * Needs to return the modified data. It is not enough
102 * to just mutate the data and return nothing.
103 * https://github.com/getsentry/raven-node/blob/6f7145161a33134168ca87b53bb99b9b6d3c89e4/lib/client.js#L246-L248
104 */
105export type DataCallback = (data: { [key: string]: any }) => any;
106
107export type ShouldSendCallback = (data: { [key: string]: any }) => boolean;
108
109export interface CaptureOptions {
110 tags?: { [key: string]: string } | undefined;
111 extra?: { [key: string]: any } | undefined;
112 fingerprint?: string[] | undefined;
113 level?: string | undefined;
114 req?: IncomingMessage | undefined;
115 user?: any;
116}
117
118export namespace transports {
119 interface HTTPTransportOptions {
120 hostname?: string | undefined;
121 path?: string | undefined;
122 headers?: OutgoingHttpHeaders | undefined;
123 method?: "POST" | "GET" | undefined;
124 port?: number | undefined;
125 ca?: string | undefined;
126 agent?: Agent | undefined;
127 rejectUnauthorized?: boolean | undefined;
128 }
129 abstract class Transport extends EventEmitter {
130 abstract send(
131 client: Client,
132 message: any,
133 headers: OutgoingHttpHeaders,
134 eventId: string,
135 cb: CaptureCallback,
136 ): void;
137 }
138 class HTTPTransport extends Transport {
139 defaultPort: string;
140 options: HTTPTransportOptions;
141 agent: Agent;
142 constructor(options?: HTTPTransportOptions);
143 send(
144 client: Client,
145 message: any,
146 headers: OutgoingHttpHeaders,
147 eventId: string,
148 cb: CaptureCallback,
149 ): void;
150 }
151 class HTTPSTransport extends HTTPTransport {
152 }
153 const https: HTTPSTransport;
154 const http: HTTPTransport;
155}