Skip to content

Commit 6fccc37

Browse files
authored
🎉 add truffle-bunjs (#23)
1 parent 25433aa commit 6fccc37

File tree

8 files changed

+144
-0
lines changed

8 files changed

+144
-0
lines changed

‎.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
.env.local
44
.env.production.local
55
.env.test.local
6+
.npmrc
67
coverage
78
dist
89
node_modules

‎bun.lock

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@
1919
"typescript": "5.8.2",
2020
},
2121
},
22+
"packages/truffle-bunjs": {
23+
"name": "@wafflestudio/truffle-bunjs",
24+
"version": "0.2.1",
25+
"dependencies": {
26+
"error-stack-parser": "^2.1.4",
27+
},
28+
"devDependencies": {
29+
"tsup": "8.4.0",
30+
"typescript": "5.8.2",
31+
},
32+
"peerDependencies": {
33+
"@types/bun": "^1.2.0",
34+
},
35+
},
2236
},
2337
"packages": {
2438
"@babel/runtime": ["@babel/[email protected]", "", { "dependencies": { "regenerator-runtime": "^0.14.0" } }, "sha512-VtPOkrdPHZsKc/clNqyi9WUA8TINkZ4cGk63UUE3u4pmB2k+ZMQRDuIOagv8UVd6j7k0T3+RRIb7beKTebNbcw=="],
@@ -189,12 +203,18 @@
189203

190204
"@rollup/rollup-win32-x64-msvc": ["@rollup/[email protected]", "", { "os": "win32", "cpu": "x64" }, "sha512-jjqy3uWlecfB98Psxb5cD6Fny9Fupv9LrDSPTQZUROqjvZmcCqNu4UMl7qqhlUUGpwiAkotj6GYu4SZdcr/nLw=="],
191205

206+
"@types/bun": ["@types/[email protected]", "", { "dependencies": { "bun-types": "1.2.7" } }, "sha512-t8L1RvJVUghW5V+M/fL3Thbxcs0HwNsXsnTEBEfEVqGteiJToOlZ/fyOEaR1kZsNqnu+3XA4RI/qmnX4w6+S+w=="],
207+
192208
"@types/estree": ["@types/[email protected]", "", {}, "sha512-w28IoSUCJpidD/TGviZwwMJckNESJZXFu7NBZ5YJ4mEUnNraUn9Pm8HSZm/jDF1pDWYKspWE7oVphigUPRakIQ=="],
193209

194210
"@types/node": ["@types/[email protected]", "", {}, "sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ=="],
195211

212+
"@types/ws": ["@types/[email protected]", "", { "dependencies": { "@types/node": "*" } }, "sha512-ThVF6DCVhA8kUGy+aazFQ4kXQ7E1Ty7A3ypFOe0IcJV8O/M511G99AW24irKrW56Wt44yG9+ij8FaqoBGkuBXg=="],
213+
196214
"@wafflestudio/truffle-browser": ["@wafflestudio/truffle-browser@workspace:packages/truffle-browser"],
197215

216+
"@wafflestudio/truffle-bunjs": ["@wafflestudio/truffle-bunjs@workspace:packages/truffle-bunjs"],
217+
198218
"ansi-colors": ["[email protected]", "", {}, "sha512-/6w/C21Pm1A7aZitlI5Ni/2J6FFQN8i1Cvz3kHABAAbw93v/NlvKdVOqz7CCWz/3iv/JplRSEEZ83XION15ovw=="],
199219

200220
"ansi-regex": ["[email protected]", "", {}, "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ=="],
@@ -215,6 +235,8 @@
215235

216236
"braces": ["[email protected]", "", { "dependencies": { "fill-range": "^7.1.1" } }, "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA=="],
217237

238+
"bun-types": ["[email protected]", "", { "dependencies": { "@types/node": "*", "@types/ws": "*" } }, "sha512-P4hHhk7kjF99acXqKvltyuMQ2kf/rzIw3ylEDpCxDS9Xa0X0Yp/gJu/vDCucmWpiur5qJ0lwB2bWzOXa2GlHqA=="],
239+
218240
"bundle-require": ["[email protected]", "", { "dependencies": { "load-tsconfig": "^0.2.3" }, "peerDependencies": { "esbuild": ">=0.18" } }, "sha512-3WrrOuZiyaaZPWiEt4G3+IffISVC9HYlWueJEBWED4ZH4aIAC2PnkdnuRrR94M+w6yGWn4AglWtJtBI8YqvgoA=="],
219241

220242
"cac": ["[email protected]", "", {}, "sha512-b6Ilus+c3RrdDk+JhLKUAQfzzgLEPy6wcXqS7f/xe1EETvsDP6GORG7SFuOs6cID5YkqchW/LXZbX5bc8j7ZcQ=="],

‎packages/truffle-bunjs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# truffle-browser
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "@wafflestudio/truffle-bunjs",
3+
"version": "0.2.1",
4+
"main": "./dist/index.js",
5+
"types": "./dist/index.d.ts",
6+
"license": "MIT",
7+
"scripts": {
8+
"dev": "bun run build -- --watch",
9+
"build": "tsup src/index.ts --format cjs --dts"
10+
},
11+
"files": ["dist/index.js", "dist/index.d.ts"],
12+
"keywords": [],
13+
"dependencies": {
14+
"error-stack-parser": "^2.1.4"
15+
},
16+
"peerDependencies": {
17+
"@types/bun": "*"
18+
},
19+
"devDependencies": {
20+
"tsup": "8.4.0",
21+
"typescript": "5.8.2"
22+
},
23+
"publishConfig": {
24+
"access": "public"
25+
}
26+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import ErrorStackParser from 'error-stack-parser';
2+
import { postEvent } from './postEvent';
3+
4+
export interface TruffleClient {
5+
capture(message: Error): void;
6+
}
7+
8+
export interface TruffleConfig {
9+
enabled?: boolean;
10+
app: { name: string; phase: string };
11+
apiKey: string;
12+
}
13+
14+
const runtime = { name: 'bunjs', version: Bun.version };
15+
16+
export const getTruffleClient = ({ enabled = true, app, apiKey }: TruffleConfig): TruffleClient => {
17+
return {
18+
capture: (error: Error) => {
19+
try {
20+
if (!enabled) return;
21+
22+
const message = error.message;
23+
const description = window.location.href;
24+
const fallbackNumber = 99999;
25+
const elements = ErrorStackParser.parse(error).map((e) => ({
26+
className: '',
27+
methodName: e.functionName ?? '',
28+
lineNumber: e.lineNumber ?? fallbackNumber,
29+
fileName: e.fileName ?? '',
30+
isInAppInClude: e.isNative ?? true,
31+
}));
32+
33+
const body = {
34+
app,
35+
description,
36+
exception: { className: error.name, message, elements },
37+
runtime,
38+
version: 'v1',
39+
};
40+
41+
postEvent(apiKey, body);
42+
} catch (err) {
43+
const body = {
44+
app,
45+
description: err && typeof err === 'object' ? (err as { message?: string }).message : '',
46+
exception: {
47+
className: 'sdk error',
48+
message: 'sdk error',
49+
elements: [],
50+
},
51+
runtime,
52+
version: 'v1',
53+
};
54+
postEvent(apiKey, body);
55+
}
56+
},
57+
};
58+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const baseUrl = 'https://truffle-api.wafflestudio.com';
2+
3+
export const postEvent = (apiKey: string, body: unknown) =>
4+
fetch(`${baseUrl}/events`, {
5+
method: 'POST',
6+
headers: { 'x-api-key': apiKey, 'content-type': 'application/json' },
7+
body: JSON.stringify(body),
8+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"$schema": "https://json.schemastore.org/tsconfig",
3+
"display": "Default",
4+
"compilerOptions": {
5+
"target": "ES2022",
6+
"composite": false,
7+
"declaration": true,
8+
"declarationMap": true,
9+
"esModuleInterop": true,
10+
"forceConsistentCasingInFileNames": true,
11+
"inlineSources": false,
12+
"isolatedModules": true,
13+
"moduleResolution": "node",
14+
"noUnusedLocals": false,
15+
"noUnusedParameters": false,
16+
"preserveWatchOutput": true,
17+
"skipLibCheck": true,
18+
"strict": true
19+
},
20+
"exclude": ["node_modules"]
21+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { defineConfig } from 'vite';
2+
3+
export default defineConfig({
4+
test: {
5+
environment: 'happy-dom',
6+
},
7+
});

0 commit comments

Comments
 (0)