mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-11-29 09:41:45 +00:00
Definitions & Tests for Raygun4Node
This commit is contained in:
Vendored
+116
@@ -0,0 +1,116 @@
|
||||
// Type definitions for raygun 0.10
|
||||
// Project: https://github.com/MindscapeHQ/raygun4node
|
||||
// Definitions by: Taylor Lodge <https://github.com/UberMouse>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
declare namespace raygun {
|
||||
interface KeyValueObject {
|
||||
[key: string]: string | number | boolean | KeyValueObject;
|
||||
}
|
||||
interface StackFrame {
|
||||
lineNumber: number;
|
||||
className: string;
|
||||
fileName: string;
|
||||
methodName: string;
|
||||
columnNumber?: number;
|
||||
}
|
||||
interface RaygunErrorObject {
|
||||
message: string;
|
||||
className: string;
|
||||
stackTrace: StackFrame[];
|
||||
innerError?: RaygunErrorObject;
|
||||
}
|
||||
interface RaygunRequest {
|
||||
hostname?: string;
|
||||
host?: string;
|
||||
path?: string;
|
||||
method?: string;
|
||||
ip?: string;
|
||||
queryString?: KeyValueObject;
|
||||
headers?: KeyValueObject;
|
||||
form?: KeyValueObject;
|
||||
}
|
||||
interface RaygunUser {
|
||||
identifier: string;
|
||||
email?: string;
|
||||
fullName?: string;
|
||||
firstName?: string;
|
||||
uuid?: string;
|
||||
}
|
||||
interface RaygunPayload {
|
||||
occurredOn: Date;
|
||||
details: {
|
||||
client: {
|
||||
name: 'raygun-node';
|
||||
version: string;
|
||||
};
|
||||
groupingKey?: string;
|
||||
error: RaygunErrorObject;
|
||||
environment: {
|
||||
osVersion: string;
|
||||
architecture: string;
|
||||
totalPhysicalMemory: number;
|
||||
availablePhysicalMemory: number;
|
||||
utcOffset: number;
|
||||
processorCount?: number;
|
||||
cpu: {
|
||||
model: string;
|
||||
speed: number;
|
||||
times: {
|
||||
user: number;
|
||||
nice: number;
|
||||
sys: number;
|
||||
idle: number;
|
||||
irq: number;
|
||||
};
|
||||
};
|
||||
};
|
||||
machineName: string;
|
||||
userCustomData?: KeyValueObject;
|
||||
tags: string[];
|
||||
request?: RaygunRequest;
|
||||
user?: RaygunUser | { identifier: string }
|
||||
version?: string;
|
||||
};
|
||||
}
|
||||
|
||||
interface RaygunOfflineStorageProvider<TTransportItem = RaygunPayload, TStorageItem = string> {
|
||||
init(options: any): RaygunOfflineStorageProvider;
|
||||
save(item: TTransportItem, callback: (error?: Error) => void): void;
|
||||
retrieve(callback: (error: Error, storageItems: ReadonlyArray<TStorageItem>) => void): void;
|
||||
send(callback: (error: Error, sendItems: ReadonlyArray<TStorageItem>) => void): void;
|
||||
}
|
||||
|
||||
type OnBeforeSend = (payload: RaygunPayload, exception: Error, customData: KeyValueObject, request: RaygunRequest, tags: ReadonlyArray<string>) => boolean | RaygunPayload;
|
||||
interface RaygunOptions {
|
||||
apiKey: string;
|
||||
filters?: ReadonlyArray<string>;
|
||||
port?: number;
|
||||
host?: string;
|
||||
useSSL?: boolean;
|
||||
onBeforeSend?: OnBeforeSend;
|
||||
offlineStorage?: RaygunOfflineStorageProvider;
|
||||
offlineStorageOptions?: any;
|
||||
isOffline?: boolean;
|
||||
groupingKey?: string;
|
||||
tags?: ReadonlyArray<string>;
|
||||
userHumanStringForObject?: boolean;
|
||||
reportColumnNumbers?: boolean;
|
||||
innerErrorFieldName?: string;
|
||||
}
|
||||
|
||||
class Client {
|
||||
init(options: RaygunOptions): Client;
|
||||
setUser(user: RaygunUser): Client;
|
||||
setVersion(version: string): Client;
|
||||
onBeforeSend(callback: OnBeforeSend): Client;
|
||||
groupingKey(groupingKey: string): Client;
|
||||
offline(): Client;
|
||||
online(): Client;
|
||||
send(exception: Error | string, customData?: KeyValueObject, offlineStorageCallback?: (error?: Error) => void, request?: RaygunRequest, tags?: ReadonlyArray<string>): RaygunPayload;
|
||||
expressHandler(error: Error, request: RaygunRequest, res: any, next: any): void;
|
||||
}
|
||||
}
|
||||
|
||||
export default raygun;
|
||||
@@ -0,0 +1,59 @@
|
||||
import raygun from 'raygun';
|
||||
|
||||
const client = new raygun.Client(); // $ExpectType Client
|
||||
client.init({apiKey: '1'}); // $ExpectType Client
|
||||
|
||||
client.init(); // $ExpectError
|
||||
client.init({}); // $ExpectError
|
||||
client.init({apiKey: 123}); // $ExpectError
|
||||
//
|
||||
// $ExpectType Client
|
||||
client.setUser({
|
||||
identifier: '123'
|
||||
});
|
||||
// $ExpectType Client
|
||||
client.setUser({
|
||||
identifier: '123',
|
||||
email: '123',
|
||||
fullName: '123',
|
||||
firstName: '123',
|
||||
uuid: '123'
|
||||
});
|
||||
|
||||
client.setUser(); // $ExpectError
|
||||
client.setUser({}); // $ExpectError
|
||||
client.setUser({identifier: 1}); // $ExpectError
|
||||
|
||||
client.setVersion('123'); // $ExpectType Client
|
||||
|
||||
client.setVersion(); // $ExpectError
|
||||
client.setVersion({}); // $ExpectError
|
||||
|
||||
client.onBeforeSend(payload => payload); // $ExpectType Client
|
||||
// $ExpectType Client
|
||||
client.onBeforeSend(payload => {
|
||||
payload.details;
|
||||
|
||||
return payload;
|
||||
});
|
||||
|
||||
client.onBeforeSend(); // $ExpectError
|
||||
|
||||
client.groupingKey('123'); // $ExpectType Client
|
||||
|
||||
client.groupingKey(); // $ExpectError
|
||||
client.groupingKey({}); // $ExpectError
|
||||
|
||||
client.offline(); // $ExpectType Client
|
||||
|
||||
client.online(); // $ExpectType Client
|
||||
|
||||
client.send(new Error()); // $ExpectType RaygunPayload
|
||||
client.send({foo: 'bar'}); // $ExpectType RaygunPayload
|
||||
client.send('error message'); // $ExpectType RaygunPayload
|
||||
client.send(new Error(), {foo: 'bar'}); // $ExpectType RaygunPayload
|
||||
client.send(new Error(), {}, undefined, undefined, ['1', '2']); // $ExpectType RaygunPayload
|
||||
|
||||
client.send(); // $ExpectError
|
||||
client.send(null); // $ExpectError
|
||||
client.send(undefined); // $ExpectError
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"raygun-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user