File tree Expand file tree Collapse file tree 3 files changed +69
-6
lines changed Expand file tree Collapse file tree 3 files changed +69
-6
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " @wafflestudio/truffle-browser" ,
3
- "version" : " 0.0.2 " ,
3
+ "version" : " 0.1.0 " ,
4
4
"main" : " ./dist/index.js" ,
5
5
"types" : " ./dist/index.d.ts" ,
6
6
"license" : " MIT" ,
Original file line number Diff line number Diff line change 1
- export const add = ( a : number , b : number ) => {
2
- return a + b ;
3
- } ;
1
+ export interface TruffleClient {
2
+ capture ( message : Error ) : void ;
3
+ }
4
+
5
+ export interface TruffleConfig {
6
+ enabled ?: boolean ;
7
+ app : { name : string ; phase : string } ;
8
+ apiKey : string ;
9
+ }
10
+
11
+ const baseUrl = "https://truffle-api.wafflestudio.com" ;
12
+ const runtime = { name : "browser" , version : "" } ;
13
+
14
+ export const getTruffleClient = ( {
15
+ enabled = true ,
16
+ app,
17
+ apiKey,
18
+ } : TruffleConfig ) : TruffleClient => {
19
+ const send = ( body : unknown ) =>
20
+ fetch ( `${ baseUrl } /events` , {
21
+ method : "POST" ,
22
+ headers : { "x-api-key" : apiKey , "content-type" : "application/json" } ,
23
+ body : JSON . stringify ( body ) ,
24
+ } ) ;
25
+
26
+ return {
27
+ capture : ( error : Error ) => {
28
+ try {
29
+ if ( ! enabled ) return ;
30
+
31
+ const message = error . message ;
32
+ const description = window . location . href ;
33
+ const elements = [
34
+ {
35
+ className : error . stack ?? "" ,
36
+ methodName : "" ,
37
+ lineNumber : 0 ,
38
+ fileName : "" ,
39
+ isInAppInClude : true ,
40
+ } ,
41
+ ] ;
42
+
43
+ const body = {
44
+ version : "v1" ,
45
+ app,
46
+ runtime,
47
+ description,
48
+ exception : { className : error . name , message, elements } ,
49
+ } ;
4
50
5
- export const subtract = ( a : number , b : number ) => {
6
- return a - b ;
51
+ send ( body ) ;
52
+ } catch ( err ) {
53
+ send (
54
+ JSON . stringify ( {
55
+ version : "v1" ,
56
+ app,
57
+ runtime,
58
+ description : "" ,
59
+ exception : {
60
+ className : "sdk error" ,
61
+ message : "sdk error" ,
62
+ elements : [ ] ,
63
+ } ,
64
+ } )
65
+ ) ;
66
+ }
67
+ } ,
68
+ } ;
7
69
} ;
Original file line number Diff line number Diff line change 2
2
"$schema" : " https://json.schemastore.org/tsconfig" ,
3
3
"display" : " Default" ,
4
4
"compilerOptions" : {
5
+ "target" : " ES2022" ,
5
6
"composite" : false ,
6
7
"declaration" : true ,
7
8
"declarationMap" : true ,
You can’t perform that action at this time.
0 commit comments