From f3e78999f2264401cb7f633a9d4aa67503281324 Mon Sep 17 00:00:00 2001 From: Benjamin Pannell Date: Mon, 1 Feb 2016 09:55:44 +0200 Subject: [PATCH 1/4] Update ravenjs definition to match latest API More details about the latest API can be found at --- ravenjs/ravenjs.d.ts | 65 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 4 deletions(-) diff --git a/ravenjs/ravenjs.d.ts b/ravenjs/ravenjs.d.ts index c88aabc58..434d804ab 100644 --- a/ravenjs/ravenjs.d.ts +++ b/ravenjs/ravenjs.d.ts @@ -1,14 +1,22 @@ // Type definitions for Raven.js // Project: https://github.com/getsentry/raven-js -// Definitions by: Santi Albo +// Definitions by: Santi Albo , Benjamin Pannell // Definitions: https://github.com/borisyankov/DefinitelyTyped declare var Raven: RavenStatic; interface RavenOptions { + /** The log level associated with this event. Default: error */ + level?: string; /** The name of the logger used by Sentry. Default: javascript */ logger?: string; + + /** The release version of the application you are monitoring with Sentry */ + release?: string; + + /** The name of the server or device that the client is running on */ + serverName?: string; /** List of messages to be fitlered out before being sent to Sentry. */ ignoreErrors?: string[]; @@ -23,9 +31,26 @@ interface RavenOptions { includePaths?: RegExp[]; /** Additional data to be tagged onto the error. */ - tags?: any; + tags?: { + [id: string]: string; + }; extra?: any; + + /** In some cases you may see issues where Sentry groups multiple events together when they should be separate entities. In other cases, Sentry simply doesn’t group events together because they’re so sporadic that they never look the same. */ + fingerprint?: string[]; + + /** A function which allows mutation of the data payload right before being sent to Sentry */ + dataCallback?: (data: any) => any; + + /** A callback function that allows you to apply your own filters to determine if the message should be sent to Sentry. */ + shouldSendCallback?: (data: any) => boolean; + + /** By default, Raven does not truncate messages. If you need to truncate characters for whatever reason, you may set this to limit the length. */ + maxMessageLength?: number; + + /** Override the default HTTP data transport handler. */ + transport?: (options: RavenTransportOptions) => void; } interface RavenStatic { @@ -88,6 +113,8 @@ interface RavenStatic { */ wrap(func: Function): Function; wrap(options: RavenOptions, func: Function): Function; + wrap(func: T): T; + wrap(options: RavenOptions, func: T): T; /* * Uninstalls the global error handler. @@ -114,11 +141,41 @@ interface RavenStatic { */ captureMessage(msg: string, options?: RavenOptions): RavenStatic; + /** + * Clear the user context, removing the user data that would be sent to Sentry. + */ + setUserContext(): RavenStatic; + /* - * Set/clear a user to be sent along with the payload. + * Set a user to be sent along with the payload. * * @param {object} user An object representing user data [optional] * @return {Raven} */ - setUser(user?: any): RavenStatic; + setUserContext(user: { + id?: string; + username?: string; + email?: string; + }): RavenStatic; + + /** Override the default HTTP data transport handler. */ + setTransport(transportFunction: (options: RavenTransportOptions) => void); + + /** An event id is a globally unique id for the event that was just sent. This event id can be used to find the exact event from within Sentry. */ + lastEventId(): string; + + /** If you need to conditionally check if raven needs to be initialized or not, you can use the isSetup function. It will return true if Raven is already initialized. */ + isSetup(): boolean; +} + +interface RavenTransportOptions { + url: string; + data: any; + auth: { + sentry_version: string; + sentry_client: string; + sentry_key: string; + }; + onSuccess: () => void; + onFailure: () => void; } From 803fd62a1005b3afe0c9922643b1c58feb64ffd6 Mon Sep 17 00:00:00 2001 From: Benjamin Pannell Date: Mon, 1 Feb 2016 10:01:00 +0200 Subject: [PATCH 2/4] fix: Correctly specify generic inheritance Bit of my C# sneaking in there... --- ravenjs/ravenjs.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ravenjs/ravenjs.d.ts b/ravenjs/ravenjs.d.ts index 434d804ab..cc06a4dfc 100644 --- a/ravenjs/ravenjs.d.ts +++ b/ravenjs/ravenjs.d.ts @@ -113,8 +113,8 @@ interface RavenStatic { */ wrap(func: Function): Function; wrap(options: RavenOptions, func: Function): Function; - wrap(func: T): T; - wrap(options: RavenOptions, func: T): T; + wrap(func: T): T; + wrap(options: RavenOptions, func: T): T; /* * Uninstalls the global error handler. From 8dafd4189a7693a722fc52c194ba339cdbc5d7fa Mon Sep 17 00:00:00 2001 From: Benjamin Pannell Date: Mon, 1 Feb 2016 10:02:44 +0200 Subject: [PATCH 3/4] fix: Have setTransport return RavenStatic interface --- ravenjs/ravenjs.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ravenjs/ravenjs.d.ts b/ravenjs/ravenjs.d.ts index cc06a4dfc..629140d8b 100644 --- a/ravenjs/ravenjs.d.ts +++ b/ravenjs/ravenjs.d.ts @@ -159,7 +159,7 @@ interface RavenStatic { }): RavenStatic; /** Override the default HTTP data transport handler. */ - setTransport(transportFunction: (options: RavenTransportOptions) => void); + setTransport(transportFunction: (options: RavenTransportOptions) => void): RavenStatic; /** An event id is a globally unique id for the event that was just sent. This event id can be used to find the exact event from within Sentry. */ lastEventId(): string; From 03aeef911ff3b195c65c64e0ebf6bf493f8c45f8 Mon Sep 17 00:00:00 2001 From: Benjamin Pannell Date: Mon, 1 Feb 2016 10:03:18 +0200 Subject: [PATCH 4/4] test: Update ravenjs tests to reflect new API --- ravenjs/ravenjs-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ravenjs/ravenjs-tests.ts b/ravenjs/ravenjs-tests.ts index d767308f7..f83cc527b 100644 --- a/ravenjs/ravenjs-tests.ts +++ b/ravenjs/ravenjs-tests.ts @@ -33,7 +33,7 @@ Raven.context({tags: { key: "value" }}, throwsError); setTimeout(Raven.wrap(throwsError), 1000); Raven.wrap({logger: "my.module"}, throwsError)(); -Raven.setUser({ +Raven.setUserContext({ email: 'matt@example.com', id: '123' });