Skip to content

🎉 add truffle-bunjs #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.env.local
.env.production.local
.env.test.local
.npmrc
coverage
dist
node_modules
22 changes: 22 additions & 0 deletions bun.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@
"typescript": "5.8.2",
},
},
"packages/truffle-bunjs": {
"name": "@wafflestudio/truffle-bunjs",
"version": "0.2.1",
"dependencies": {
"error-stack-parser": "^2.1.4",
},
"devDependencies": {
"tsup": "8.4.0",
"typescript": "5.8.2",
},
"peerDependencies": {
"@types/bun": "^1.2.0",
},
},
},
"packages": {
"@babel/runtime": ["@babel/[email protected]", "", { "dependencies": { "regenerator-runtime": "^0.14.0" } }, "sha512-VtPOkrdPHZsKc/clNqyi9WUA8TINkZ4cGk63UUE3u4pmB2k+ZMQRDuIOagv8UVd6j7k0T3+RRIb7beKTebNbcw=="],
Expand Down Expand Up @@ -189,12 +203,18 @@

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

"@types/bun": ["@types/[email protected]", "", { "dependencies": { "bun-types": "1.2.7" } }, "sha512-t8L1RvJVUghW5V+M/fL3Thbxcs0HwNsXsnTEBEfEVqGteiJToOlZ/fyOEaR1kZsNqnu+3XA4RI/qmnX4w6+S+w=="],

"@types/estree": ["@types/[email protected]", "", {}, "sha512-w28IoSUCJpidD/TGviZwwMJckNESJZXFu7NBZ5YJ4mEUnNraUn9Pm8HSZm/jDF1pDWYKspWE7oVphigUPRakIQ=="],

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

"@types/ws": ["@types/[email protected]", "", { "dependencies": { "@types/node": "*" } }, "sha512-ThVF6DCVhA8kUGy+aazFQ4kXQ7E1Ty7A3ypFOe0IcJV8O/M511G99AW24irKrW56Wt44yG9+ij8FaqoBGkuBXg=="],

"@wafflestudio/truffle-browser": ["@wafflestudio/truffle-browser@workspace:packages/truffle-browser"],

"@wafflestudio/truffle-bunjs": ["@wafflestudio/truffle-bunjs@workspace:packages/truffle-bunjs"],

"ansi-colors": ["[email protected]", "", {}, "sha512-/6w/C21Pm1A7aZitlI5Ni/2J6FFQN8i1Cvz3kHABAAbw93v/NlvKdVOqz7CCWz/3iv/JplRSEEZ83XION15ovw=="],

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

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

"bun-types": ["[email protected]", "", { "dependencies": { "@types/node": "*", "@types/ws": "*" } }, "sha512-P4hHhk7kjF99acXqKvltyuMQ2kf/rzIw3ylEDpCxDS9Xa0X0Yp/gJu/vDCucmWpiur5qJ0lwB2bWzOXa2GlHqA=="],

"bundle-require": ["[email protected]", "", { "dependencies": { "load-tsconfig": "^0.2.3" }, "peerDependencies": { "esbuild": ">=0.18" } }, "sha512-3WrrOuZiyaaZPWiEt4G3+IffISVC9HYlWueJEBWED4ZH4aIAC2PnkdnuRrR94M+w6yGWn4AglWtJtBI8YqvgoA=="],

"cac": ["[email protected]", "", {}, "sha512-b6Ilus+c3RrdDk+JhLKUAQfzzgLEPy6wcXqS7f/xe1EETvsDP6GORG7SFuOs6cID5YkqchW/LXZbX5bc8j7ZcQ=="],
Expand Down
1 change: 1 addition & 0 deletions packages/truffle-bunjs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# truffle-browser
26 changes: 26 additions & 0 deletions packages/truffle-bunjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@wafflestudio/truffle-bunjs",
"version": "0.2.1",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"license": "MIT",
"scripts": {
"dev": "bun run build -- --watch",
"build": "tsup src/index.ts --format cjs --dts"
},
"files": ["dist/index.js", "dist/index.d.ts"],
"keywords": [],
"dependencies": {
"error-stack-parser": "^2.1.4"
},
"peerDependencies": {
"@types/bun": "*"
},
"devDependencies": {
"tsup": "8.4.0",
"typescript": "5.8.2"
},
"publishConfig": {
"access": "public"
}
}
58 changes: 58 additions & 0 deletions packages/truffle-bunjs/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import ErrorStackParser from 'error-stack-parser';
import { postEvent } from './postEvent';

export interface TruffleClient {
capture(message: Error): void;
}

export interface TruffleConfig {
enabled?: boolean;
app: { name: string; phase: string };
apiKey: string;
}

const runtime = { name: 'bunjs', version: Bun.version };

export const getTruffleClient = ({ enabled = true, app, apiKey }: TruffleConfig): TruffleClient => {
return {
capture: (error: Error) => {
try {
if (!enabled) return;

const message = error.message;
const description = window.location.href;
const fallbackNumber = 99999;
const elements = ErrorStackParser.parse(error).map((e) => ({
className: '',
methodName: e.functionName ?? '',
lineNumber: e.lineNumber ?? fallbackNumber,
fileName: e.fileName ?? '',
isInAppInClude: e.isNative ?? true,
}));

const body = {
app,
description,
exception: { className: error.name, message, elements },
runtime,
version: 'v1',
};

postEvent(apiKey, body);
} catch (err) {
const body = {
app,
description: err && typeof err === 'object' ? (err as { message?: string }).message : '',
exception: {
className: 'sdk error',
message: 'sdk error',
elements: [],
},
runtime,
version: 'v1',
};
postEvent(apiKey, body);
}
},
};
};
8 changes: 8 additions & 0 deletions packages/truffle-bunjs/src/postEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const baseUrl = 'https://truffle-api.wafflestudio.com';

export const postEvent = (apiKey: string, body: unknown) =>
fetch(`${baseUrl}/events`, {
method: 'POST',
headers: { 'x-api-key': apiKey, 'content-type': 'application/json' },
body: JSON.stringify(body),
});
21 changes: 21 additions & 0 deletions packages/truffle-bunjs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Default",
"compilerOptions": {
"target": "ES2022",
"composite": false,
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"inlineSources": false,
"isolatedModules": true,
"moduleResolution": "node",
"noUnusedLocals": false,
"noUnusedParameters": false,
"preserveWatchOutput": true,
"skipLibCheck": true,
"strict": true
},
"exclude": ["node_modules"]
}
7 changes: 7 additions & 0 deletions packages/truffle-bunjs/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'vite';

export default defineConfig({
test: {
environment: 'happy-dom',
},
});