1 |
|
2 |
|
3 | import { EventEmitter } from "events";
|
4 | import { Agent, ClientRequest, IncomingMessage, OutgoingHttpHeaders, ServerResponse } from "http";
|
5 |
|
6 |
|
7 |
|
8 | export function config(options?: ConstructorOptions): Client;
|
9 | export function config(dsn?: string | false, options?: ConstructorOptions): Client;
|
10 | export function install(cb?: FatalErrorCallback): Client;
|
11 | export function uninstall(): Client;
|
12 | export function wrap<T>(func: () => T): () => T;
|
13 | export function wrap<T>(options: any, func: () => T): () => T;
|
14 | export function interceptErr(ctx: any): Client;
|
15 | export function setContext(ctx: any): Client;
|
16 | export function mergeContext(ctx: any): Client;
|
17 | export function getContext(): any;
|
18 | export function requestHandler(): (req: IncomingMessage, res: ServerResponse, next: () => void) => void;
|
19 | export function errorHandler(): (e: Error, req: IncomingMessage, res: ServerResponse, next: () => void) => void;
|
20 | export function captureException(e: Error, cb?: CaptureCallback): string;
|
21 | export function captureException(e: Error, options?: CaptureOptions, cb?: CaptureCallback): string;
|
22 | export function captureMessage(message: string, cb?: CaptureCallback): string;
|
23 | export function captureMessage(message: string, options?: CaptureOptions, cb?: CaptureCallback): string;
|
24 | export function captureBreadcrumb(breadcrumb: any): void;
|
25 | export function setDataCallback(fn: DataCallback): Client;
|
26 | export function setShouldSendCallback(fn: ShouldSendCallback): Client;
|
27 | export function context<T>(ctx: any, func: () => T): T;
|
28 | export function context<T>(func: () => T): T;
|
29 |
|
30 | export const version: string;
|
31 | export function disableConsoleAlerts(): void;
|
32 |
|
33 | export namespace utils {
|
34 | function consoleAlert(msg: string): void;
|
35 | function parseDSN(dsn: string | false): parsedDSN | false;
|
36 | }
|
37 |
|
38 | export 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 |
|
65 | export 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 |
|
84 | export type parseUserCallback = (req: any) => any;
|
85 |
|
86 | export 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 |
|
96 | export type FatalErrorCallback = (err: Error, sendErr: Error | null | undefined, eventId: string) => void;
|
97 |
|
98 | export type CaptureCallback = (sendErr: Error | null | undefined, eventId: any) => void;
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 | export type DataCallback = (data: { [key: string]: any }) => any;
|
106 |
|
107 | export type ShouldSendCallback = (data: { [key: string]: any }) => boolean;
|
108 |
|
109 | export 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 |
|
118 | export 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 | }
|