1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | import {
|
11 | IncomingMessage, ServerResponse, OutgoingHttpHeaders, Agent, ClientRequest
|
12 | } from 'http';
|
13 | import { EventEmitter } from 'events';
|
14 |
|
15 |
|
16 |
|
17 | export function config(options?: ConstructorOptions): Client;
|
18 | export function config(dsn?: string | false, options?: ConstructorOptions): Client;
|
19 | export function install(cb?: FatalErrorCallback): Client;
|
20 | export function uninstall(): Client;
|
21 | export function wrap<T>(func: () => T): () => T;
|
22 | export function wrap<T>(options: any, func: () => T): () => T;
|
23 | export function interceptErr(ctx: any): Client;
|
24 | export function setContext(ctx: any): Client;
|
25 | export function mergeContext(ctx: any): Client;
|
26 | export function getContext(): any;
|
27 | export function requestHandler(): (req: IncomingMessage, res: ServerResponse, next: () => void) => void;
|
28 | export function errorHandler(): (e: Error, req: IncomingMessage, res: ServerResponse, next: () => void) => void;
|
29 | export function captureException(e: Error, cb?: CaptureCallback): string;
|
30 | export function captureException(e: Error, options?: CaptureOptions, cb?: CaptureCallback): string;
|
31 | export function captureMessage(message: string, cb?: CaptureCallback): string;
|
32 | export function captureMessage(message: string, options?: CaptureOptions, cb?: CaptureCallback): string;
|
33 | export function captureBreadcrumb(breadcrumb: any): void;
|
34 | export function setDataCallback(fn: DataCallback): Client;
|
35 | export function setShouldSendCallback(fn: ShouldSendCallback): Client;
|
36 | export function context<T>(ctx: any, func: () => T): T;
|
37 | export function context<T>(func: () => T): T;
|
38 |
|
39 | export const version: string;
|
40 | export function disableConsoleAlerts(): void;
|
41 |
|
42 | export namespace utils {
|
43 | function consoleAlert(msg: string): void;
|
44 | function parseDSN(dsn: string | false): parsedDSN | false;
|
45 | }
|
46 |
|
47 | export 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 |
|
74 | export 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 |
|
93 | export type parseUserCallback = (req: any) => any;
|
94 |
|
95 | export 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 |
|
105 | export type FatalErrorCallback = (err: Error, sendErr: Error | null | undefined, eventId: string) => void;
|
106 |
|
107 | export type CaptureCallback = (sendErr: Error | null | undefined, eventId: any) => void;
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 | export type DataCallback = (data: { [key: string]: any }) => any;
|
115 |
|
116 | export type ShouldSendCallback = (data: { [key: string]: any }) => boolean;
|
117 |
|
118 | export 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 |
|
127 | export 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 | }
|