Skip to content

Commit d6b30b4

Browse files
authored
Added TypeScript defintions (#82)
Signed-off-by: Tomasz Wojno <tomek.wojno@gmail.com>
1 parent b79f307 commit d6b30b4

File tree

2 files changed

+170
-0
lines changed

2 files changed

+170
-0
lines changed

index.d.ts

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
declare module 'stackdriver-errors-js' {
2+
/**
3+
* Context to be sent along with the error
4+
*/
5+
interface Context {
6+
/**
7+
* User who caused or was affected by the error
8+
*/
9+
userId?: string;
10+
11+
[x: string]: any;
12+
}
13+
14+
/**
15+
* Context to be sent along with the error
16+
*/
17+
interface PayloadContext extends Context {
18+
httpRequest: {
19+
/**
20+
* Requesting agent
21+
*/
22+
userAgent: string;
23+
24+
/**
25+
* Website URL
26+
*/
27+
url: string;
28+
};
29+
}
30+
31+
/**
32+
* Service context
33+
*/
34+
interface ServiceContext {
35+
/**
36+
* Name of the service reporting the error
37+
*/
38+
service: string;
39+
40+
/**
41+
* Version identifier of the service reporting the error
42+
*/
43+
version: string;
44+
}
45+
46+
/**
47+
* Payload passed to the custom reporting function
48+
*/
49+
interface Payload {
50+
/**
51+
* Context related to this error
52+
*/
53+
context: PayloadContext;
54+
55+
/**
56+
* Error message
57+
*/
58+
message: string;
59+
60+
/**
61+
* Service context
62+
*/
63+
serviceContext: ServiceContext;
64+
}
65+
66+
/**
67+
* Initial configuration
68+
*/
69+
interface InitialConfiguration {
70+
/**
71+
* The context in which the error occurred
72+
*/
73+
context?: Context;
74+
75+
/**
76+
* Custom function to be called with the error payload for reporting,
77+
* instead of HTTP request
78+
*
79+
* @param payload Error payload
80+
*/
81+
customReportingFunction?: (payload: Payload) => Promise<void>;
82+
83+
/**
84+
* Set to true to not send error reports, this can be used when
85+
* developing locally
86+
*
87+
* @default false
88+
*/
89+
disabled?: boolean;
90+
91+
/**
92+
* The API key to use to call the API
93+
*/
94+
key: string;
95+
96+
/**
97+
* The Google Cloud Platform project ID to report errors to
98+
*/
99+
projectId: string;
100+
101+
/**
102+
* Set to false to prevent reporting unhandled exceptions
103+
*
104+
* @default true
105+
*/
106+
reportUncaughtExceptions?: boolean;
107+
108+
/**
109+
* Set to false to prevent reporting unhandled promise rejections
110+
*
111+
* @default true
112+
*/
113+
reportUnhandledPromiseRejections?: boolean;
114+
115+
/**
116+
* Name of the service reporting the error
117+
*
118+
* @default "web"
119+
*/
120+
service?: string;
121+
122+
/**
123+
* Version identifier of the service reporting the error
124+
*/
125+
version?: string;
126+
}
127+
128+
/**
129+
* Error report options
130+
*/
131+
interface ReportOptions {
132+
/**
133+
* Omit number of frames if creating stack
134+
*
135+
* @default 1
136+
*/
137+
skipLocalFrames?: number;
138+
}
139+
140+
/**
141+
* An Error handler that sends errors to the Stackdriver Error Reporting API
142+
*/
143+
class StackdriverErrorReporter {
144+
/**
145+
* Initializes the client
146+
*
147+
* @param options Initial configuration
148+
*/
149+
start(options: InitialConfiguration): void;
150+
151+
/**
152+
* Report an error to the Stackdriver Error Reporting API
153+
*
154+
* @param error The Error object or message string to report
155+
* @param options Configuration for this report
156+
*/
157+
report(error: string | Error, options?: ReportOptions): Promise<void>;
158+
159+
/**
160+
* Set the user for the current context.
161+
*
162+
* @param user The unique identifier of the user (can be ID, email or
163+
* custom token) or undefined if not logged in
164+
*/
165+
setUser(user?: string): void;
166+
}
167+
168+
export default StackdriverErrorReporter;
169+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "0.8.0",
44
"description": "Experimental client-side JavaScript library to report errors to Stackdriver Error Reporting",
55
"main": "stackdriver-errors.js",
6+
"types": "index.d.ts",
67
"scripts": {
78
"clean": "rimraf dist/",
89
"dist": "gulp lib-concat",

0 commit comments

Comments
 (0)