updated Definitions for Raven-JS

This commit is contained in:
Luca Vazzano
2017-01-13 00:23:25 +01:00
parent 2273809e3d
commit 6de3e0630c
+256 -137
View File
@@ -1,209 +1,302 @@
// Type definitions for Raven.js
// Project: https://github.com/getsentry/raven-js
// Definitions by: Santi Albo <https://github.com/santialbo/>, Benjamin Pannell <http://github.com/spartan563>, Gary Blackwood <http://github.com/Garee>, Rich Rout <http://github.com/richrout>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// Original Definitions by: Santi Albo <https://github.com/santialbo>, Benjamin Pannell
// <http://github.com/spartan563>; DefinitelyTyped
// Updated by: Ben Vinegar <https://github.com/benvinegar>, Ilya Pirogov
// <https://github.com/ilya-pirogov>, Eli White <https://github.com/TheSavior>, David Cramer
// <https://github.com/dcramer>, Connor Peet <https://github.com/connor4312>, comaz
// <https://github.com/combmag>, Luca Vazzano <https://github.com/LucaVazz>
declare var Raven: RavenStatic;
declare module 'raven-js' {
export default Raven;
}
interface RavenOptions {
/** 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 environment in which the application is running. */
environment?: 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[];
/** Similar to ignoreErrors, but will ignore errors from whole urls patching a regex pattern. */
ignoreUrls?: RegExp[];
/** The inverse of ignoreUrls. Only report errors from whole urls matching a regex pattern. */
whitelistUrls?: RegExp[];
/** An array of regex patterns to indicate which urls are a part of your app. */
includePaths?: RegExp[];
/** Additional data to be tagged onto the error. */
tags?: {
[id: string]: 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;
/** Enables/disables automatic collection of breadcrumbs. Default: true. */
autoBreadcrumbs?: any;
/** The max number of breadcrumb captures. Default: 100. */
maxBreadcrumbs?: number;
/** Override the default HTTP data transport handler. */
transport?: (options: RavenTransportOptions) => void;
/** Allow the use of a Sentry DSN with a private key. Default: false. */
allowSecretKey?: boolean;
}
interface RavenAdditionalData {
/** The name of the logger used by Sentry. Default: javascript */
logger?: string;
/** The log level associated with this event. Default: error */
level?: string;
/** Additional data to be tagged onto the error. */
tags?: {
[id: string]: string;
};
extra?: any;
}
export = Raven;
interface RavenStatic {
/** Raven.js version. */
VERSION: string;
/** A list of currently active plugins. */
Plugins: { [id: string]: RavenPlugin };
/*
* Allow Raven to be configured as soon as it is loaded
/**
* Allow Raven to be configured as soon as it is loaded.
* It uses a global RavenConfig = {dsn: '...', config: {}}
*
* @return undefined
*/
afterLoad(): void;
/*
/**
* Allow multiple versions of Raven to be installed.
* Strip Raven from the global context and returns the instance.
*
* @return {Raven}
*/
noConflict(): RavenStatic;
/*
/**
* Configure Raven with a DSN and extra options
*
* @param {string} dsn The public Sentry DSN
* @param {object} options Optional set of of global options [optional]
* @return {Raven}
* @param dsn The public Sentry DSN
* @param options Optional set of of global options
*/
config(dsn: string, options?: RavenOptions): RavenStatic;
config(dsn: string, options?: RavenGlobalOptions): RavenStatic;
/*
* Installs a global window.onerror error handler
* to capture and report uncaught exceptions.
* At this point, install() is required to be called due
* to the way TraceKit is set up.
/**
* Set the DSN (can be called multiple times, unlike config)
*
* @return {Raven}
* @param dsn The public Sentry DSN
*/
setDSN(dsn: string);
/**
* Installs a global window.onerror error handler to capture and report uncaught exceptions.
* At this point, install() is required to be called due to the way TraceKit is set up.
*/
install(): RavenStatic;
/*
/**
* Adds a plugin to Raven
*
* @return {Raven}
*/
addPlugin(plugin: RavenPlugin, ...pluginArgs: any[]): RavenStatic;
/*
* Wrap code within a context so Raven can capture errors
* reliably across domains that is executed immediately.
/**
* Wrap code within a context so Raven can capture errors reliably across domains that is
* executed immediately.
*
* @param {object} options A specific set of options for this context [optional]
* @param {function} func The callback to be immediately executed within the context
* @param {array} args An array of arguments to be called with the callback [optional]
* @param options A specific set of options for this context
* @param func The callback to be immediately executed within the context
* @param args An array of arguments to be called with the callback
*/
context(func: Function, ...args: any[]): void;
context(options: RavenAdditionalData, func: Function, ...args: any[]): void;
context(options: RavenWrapOptions, func: Function, ...args: any[]): void;
/*
/**
* Wrap code within a context and returns back a new function to be executed
*
* @param {object} options A specific set of options for this context [optional]
* @param {function} func The function to be wrapped in a new context
* @return {function} The newly wrapped functions with a context
* @param options A specific set of options for this context
* @param func The function to be wrapped in a new context
* @return The newly wrapped functions with a context
*/
wrap(func: Function): Function;
wrap(options: RavenAdditionalData, func: Function): Function;
wrap(options: RavenWrapOptions, func: Function): Function;
wrap<T extends Function>(func: T): T;
wrap<T extends Function>(options: RavenAdditionalData, func: T): T;
wrap<T extends Function>(options: RavenWrapOptions, func: T): T;
/*
/**
* Uninstalls the global error handler.
*
* @return {Raven}
*/
uninstall(): RavenStatic;
/*
/**
* Manually capture an exception and send it over to Sentry
*
* @param {error} ex An exception to be logged
* @param {object} options A specific set of options for this error [optional]
* @return {Raven}
* @param ex An exception to be logged
* @param options A specific set of options for this error
*/
captureException(ex: Error, options?: RavenAdditionalData): RavenStatic;
captureException(ex: Error, options?: RavenOptions): RavenStatic;
/*
* Manually send a message to Sentry
*
* @param {string} msg A plain message to be captured in Sentry
* @param {object} options A specific set of options for this message [optional]
* @return {Raven}
* @param msg A plain message to be captured in Sentry
* @param options A specific set of options for this message
*/
captureMessage(msg: string, options?: RavenAdditionalData): RavenStatic;
captureMessage(msg: string, options?: RavenOptions): RavenStatic;
/**
* Add a breadcrumb
* @param crumb The trail which should be added to the trail
*/
captureBreadcrumb(crumb: RavenBreadcrumb): RavenStatic;
/**
* Set a user to be sent along with payloads.
*
* @param user The definition of the currently active user's unique identity
*/
setUserContext(user: RavenUserContext): RavenStatic;
/**
* Clear the user context, removing the user data that would be sent to Sentry.
*/
setUserContext(): RavenStatic;
/*
* Set a user to be sent along with the payload.
*
* @param {object} user An object representing user data [optional]
* @return {Raven}
/**
* Add arbitrary data to be sent along with the payload.
* @param extra data of an arbitrary, nested type which will be added
*/
setUserContext(user: {
id?: string;
username?: string;
email?: string;
}): RavenStatic;
setExtraContext(extra: { [prop: string]: any }): RavenStatic;
/** Override the default HTTP data transport handler. */
setTransport(transportFunction: (options: RavenTransportOptions) => void): RavenStatic;
/**
* Add additional tags to be sent along with payloads.
* @param tags A key/value-pair which will be added
*/
setTagsContext(tags: { [id: string]: string }): 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. */
/**
* Clear the whole currently set context.
*/
clearContext(): RavenStatic;
/**
* Get a copy of the current context.
*/
getContext(): Object;
/**
* Set environment of application
* @param environment Typically something like 'production'
*/
setEnvironment(environment: string): RavenStatic;
/**
* Set release version of application
* @param release Typically something like a git SHA to identify the current version
*/
setRelease(release: string): RavenStatic;
/**
* Specify a function that can mutate the payload right before it is being sent to Sentry.
* @param callback The function which can mutate the data
*/
setDataCallback(callback: (data: any, orig?: string) => any): RavenStatic;
/**
* Specify a callback function that can mutate or filter breadcrumbs when they are captured.
* @param callback The function which applies the filter
*/
setBreadcrumbCallback(callback :(data: any, orig?: string) => any): RavenStatic;
/**
* Specify a callback function that determines if the given message should be sent to Sentry.
* @param callback The function which determines if the given blob should be sent
*/
setShouldSendCallback(callback: (data: any, orig?: string) => boolean): RavenStatic;
/**
* Override the default HTTP data transport handler.
* @param transport The function which will be invoked to handle the data transmission
*/
setTransport(transport: (options: RavenTransportOptions) => void): RavenStatic;
/**
* Get the latest raw exception that was captured by Raven.
*/
lastException(): Error;
/**
* Get the ID of the last Event captured by Raven.
*/
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. */
/**
* Determine if Raven is setup and ready to go.
*/
isSetup(): boolean;
showReportDialog(options: RavenOptions): void;
/**
* Show the User Feedback Dialog of Sentry
* @param RavenReportDialogOptions Optional Options to set for the User Feedback
*/
showReportDialog(options?: RavenReportDialogOptions): void;
}
setTagsContext(tags: { [id: string]: string; }): void;
setExtraContext(context: any): void;
// --- Helper Interfaces for Options --------------
interface RavenBreadcrumOptions {
/** Whether to collect XHR calls, defaults to true */
xhr?: boolean;
/** Whether to collect console logs, defaults to true */
console?: boolean;
/** Whether to collect dom events, defaults to true */
dom?: boolean;
/** Whether to record window location and navigation, defaults to true */
location?: boolean;
}
interface CommonRavenOptions {
/** The environment of the application you are monitoring with Sentry */
environment?: string;
/** The release version of the application you are monitoring with Sentry */
release?: string;
/** Additional key/value-data to be tagged onto the error. */
tags?: { [id: string]: string };
/** Additional, arbitrary metadata to collect */
extra?: { [prop: string]: any };
/** The name of the logger used by Sentry. Default: javascript */
logger?: string;
/** set to true to get the strack trace of your message */
stacktrace?: boolean;
}
interface RavenOptions extends CommonRavenOptions {
/** The name of the server or device that the client is running on */
server_name?: string;
/** The log level associated with this event. Default: error */
level?: string;
/** 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[];
/** Number of frames to trim off the stacktrace. Default: 1 */
trimHeadFrames?: number;
/** The name of the device platform. Default: "javascript" */
platform?: string;
}
interface RavenGlobalOptions extends CommonRavenOptions {
/** The name of the server or device that the client is running on */
serverName?: string;
/** Configures which breadcrumbs are collected automatically */
autoBreadcrumbs?: boolean | RavenBreadcrumOptions;
/** Whether to collect errors on the window via TraceKit.collectWindowErrors. Default: true. */
collectWindowErrors?: boolean;
/** Max number of breadcrumbs to collect. Default: 100 */
maxBreadcrumbs?: number;
/** Exclude messages which match one of the given RegEx-Patterns from being sent to Sentry. */
ignoreErrors?: (RegExp | string)[];
/** Exclude messages which come from whole urls matching one of the given RegEx patterns. */
ignoreUrls?: (RegExp | string)[];
/** Only report messages which come from whole urls matching one of the given RegEx patterns. */
whitelistUrls?: (RegExp | string)[];
/** An array of RegEx patterns to indicate which urls are a part of your app. */
includePaths?: (RegExp | string)[];
/** Maximum amount of stack frames to collect. Default: Infinity */
stackTraceLimit?: number;
/** Override the default HTTP data transport handler. */
transport?: (options: RavenTransportOptions) => void;
/** Limit the maxium length of a message to this number of characters. Default: Infinity */
maxMessageLength?: number;
/** Allows you to apply your own filters to determine if the message should be sent to Sentry. */
shouldSendCallback?: (data: any) => boolean;
/** A function which allows mutation of the data payload right before being sent to Sentry */
dataCallback?: (data: any) => any;
}
interface RavenWrapOptions extends RavenOptions {
/** Whether to run the wrap recursively. Default: false. */
deep?: boolean;
}
interface RavenTransportOptions {
@@ -218,6 +311,32 @@ interface RavenTransportOptions {
onFailure: () => void;
}
interface RavenReportDialogOptions {
eventId?: number,
dsn?: string,
user?: {
name?: string,
email?: string
}
}
// --- Helper Interfaces for complex Data Structures --------------
interface RavenPlugin {
(raven: RavenStatic, ...args: any[]): RavenStatic;
}
interface RavenUserContext {
id?: string;
username?: string;
email?: string;
ip_address?: string;
extra?: { [prop: string]: any };
}
interface RavenBreadcrumb {
message: string;
data: { [id: string]: string };
category: string;
level: string;
}