Skip to content

Commit 9b1db62

Browse files
authored
✨ truffle/browser sdk 기본 기능 구현 (#3)
1 parent a76b8ea commit 9b1db62

File tree

3 files changed

+69
-6
lines changed

3 files changed

+69
-6
lines changed

packages/truffle-browser/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@wafflestudio/truffle-browser",
3-
"version": "0.0.2",
3+
"version": "0.1.0",
44
"main": "./dist/index.js",
55
"types": "./dist/index.d.ts",
66
"license": "MIT",

packages/truffle-browser/src/index.ts

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,69 @@
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+
};
450

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+
};
769
};

packages/tsconfig/base.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"$schema": "https://json.schemastore.org/tsconfig",
33
"display": "Default",
44
"compilerOptions": {
5+
"target": "ES2022",
56
"composite": false,
67
"declaration": true,
78
"declarationMap": true,

0 commit comments

Comments
 (0)