From 364becebfae5ec80cc11ff6a227e68ac37713b81 Mon Sep 17 00:00:00 2001 From: shrey Date: Fri, 2 Mar 2018 17:19:46 -0500 Subject: [PATCH] Update missing functions/deprecated functions. --- types/raven/index.d.ts | 71 ++++++++++++++++++++++++-------------- types/raven/raven-tests.ts | 3 +- 2 files changed, 46 insertions(+), 28 deletions(-) diff --git a/types/raven/index.d.ts b/types/raven/index.d.ts index 21aee49169..db59721513 100644 --- a/types/raven/index.d.ts +++ b/types/raven/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/getsentry/raven-node // Definitions by: Scott Cooper // Dmitrii Sorin +// Shrey Jain // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// @@ -9,34 +10,50 @@ import { IncomingMessage, ServerResponse } from 'http'; import { EventEmitter } from 'events'; -export const version: string; +// expose all methods of `Client` class since raven exposes a singleton instance +// todo: there has to be a better way of doing this that doesn't require duplicating so much stuff export function config(options?: ConstructorOptions): Client; export function config(dsn?: string | false, options?: ConstructorOptions): Client; +export function install(cb?: FatalErrorCallback): Client; +export function uninstall(): Client; export function wrap(func: () => T): () => T; export function wrap(options: any, func: () => T): () => T; -export function interceptErr(ctx: any): Client; +export function interceptErr(ctx: any): Client; // todo: part of public? export function setContext(ctx: any): Client; -export function captureException(e: Error, cb?: CaptureCallback): string; -export function captureException(e: Error, options?: CaptureOptions, cb?: CaptureCallback): string; -export function captureMessage(message: string, cb?: CaptureCallback): string; -export function captureMessage(message: string, options?: CaptureOptions, cb?: CaptureCallback): string; export function mergeContext(ctx: any): Client; export function getContext(): any; export function requestHandler(): (req: IncomingMessage, res: ServerResponse, next: () => void) => void; export function errorHandler(): (e: Error, req: IncomingMessage, res: ServerResponse, next: () => void) => void; +export function captureException(e: Error, cb?: CaptureCallback): string; +export function captureException(e: Error, options?: CaptureOptions, cb?: CaptureCallback): string; +export function captureMessage(message: string, cb?: CaptureCallback): string; +export function captureMessage(message: string, options?: CaptureOptions, cb?: CaptureCallback): string; +export function captureBreadcrumb(breadcrumb: any): void; +export function setDataCallback(fn: DataCallback): Client; +export function setShouldSendCallback(fn: ShouldSendCallback): Client; export function context(ctx: any, func: () => T): T; export function context(func: () => T): T; -export function captureBreadcrumb(breadcrumb: any): void; + +export const version: string; export function disableConsoleAlerts(): void; -export function consoleAlert(msg: string): void; -export function parseDSN(dsn: string | false): parsedDSN; + +export namespace utils { + function consoleAlert(msg: string): void; + function parseDSN(dsn: string | false): parsedDSN | false; +} export class Client extends EventEmitter { - constructor(options: ConstructorOptions); - constructor(dsn: string, options?: ConstructorOptions); - config(dsn: string, options?: ConstructorOptions): this; - install(options?: ConstructorOptions, cb?: () => void): this; + constructor(options?: ConstructorOptions); + constructor(dsn?: string | false, options?: ConstructorOptions); + config(options?: ConstructorOptions): this; + config(dsn?: string | false, options?: ConstructorOptions): this; + install(cb?: FatalErrorCallback): this; + uninstall(): this; + wrap(func: () => T): () => T; + wrap(options: any, func: () => T): () => T; setContext(ctx: any): this; + mergeContext(ctx: any): this; + getContext(): any; requestHandler(): (req: IncomingMessage, res: ServerResponse, next: () => void) => void; errorHandler(): (e: Error, req: IncomingMessage, res: ServerResponse, next: () => void) => void; captureException(error: Error, cb?: CaptureCallback): string; @@ -44,13 +61,12 @@ export class Client extends EventEmitter { captureMessage(message: string, cb?: CaptureCallback): string; captureMessage(message: string, options?: CaptureOptions, cb?: CaptureCallback): string; captureBreadcrumb(breadcrumb: any): void; - setUserContext(data: UserData): void; - setDataCallback(fn: DataCallback): void; + setDataCallback(fn: DataCallback): this; setShouldSendCallback(fn: ShouldSendCallback): this; context(ctx: any, func: () => T): T; context(func: () => T): T; - process(kwargs: any, cb?: () => void): void; - process(eventId: string, kwargs: any, cb?: () => void): void; + process(kwargs: any, cb?: () => void): void; // todo: part of public API? + process(eventId: string, kwargs: any, cb?: () => void): void; // todo: part of public API? } export interface ConstructorOptions { @@ -65,19 +81,15 @@ export interface ConstructorOptions { sampleRate?: number; sendTimeout?: number; shouldSendCallback?: ShouldSendCallback; - transport?(): void; + transport?: TransportCallback; captureUnhandledRejections?: boolean; - autoBreadcrumbs?: boolean | any; + maxBreadcrumbs?: number; + autoBreadcrumbs?: boolean | { [breadcrumbType: string]: boolean }; parseUser?: boolean | string[] | parseUserCallback; } export type parseUserCallback = (req: any) => any; -export interface UserData { - id: string; - handle?: string; -} - export interface parsedDSN { protocol: string; public_key: string; @@ -88,9 +100,16 @@ export interface parsedDSN { port: number; } -export type CaptureCallback = (err: { [key: string]: any }, eventId: any) => void; +export type FatalErrorCallback = (err: Error, sendErr: Error | null | undefined, eventId: string) => void; -export type DataCallback = (data: { [key: string]: any }) => void; +export type CaptureCallback = (sendErr: Error | null | undefined, eventId: any) => void; + +/** + * Needs to return the modified data. It is not enough + * to just mutate the data and return nothing. + * https://github.com/getsentry/raven-node/blob/6f7145161a33134168ca87b53bb99b9b6d3c89e4/lib/client.js#L246-L248 + */ +export type DataCallback = (data: { [key: string]: any }) => any; export type ShouldSendCallback = (data: { [key: string]: any }) => boolean; diff --git a/types/raven/raven-tests.ts b/types/raven/raven-tests.ts index 71f9b54038..927125f84f 100644 --- a/types/raven/raven-tests.ts +++ b/types/raven/raven-tests.ts @@ -13,7 +13,6 @@ console.log(Raven.version); Raven.config({ release: 'foobar' }); -Raven.config(dsn).install({ captureUnhandledRejections: true }); client.setContext({}); client.on('logged', () => { }); client.process({}); @@ -34,4 +33,4 @@ Raven.context(() => { Raven.captureBreadcrumb({}); }); setTimeout(Raven.wrap(() => {}), 1000); -Raven.parseDSN('https://8769c40cf49c4cc58b51fa45d8e2d166:296768aa91084e17b5ac02d3ad5bc7e7@app.getsentry.com/269'); +Raven.utils.parseDSN('https://8769c40cf49c4cc58b51fa45d8e2d166:296768aa91084e17b5ac02d3ad5bc7e7@app.getsentry.com/269');