UNPKG

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