Skip to content
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
2 changes: 0 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ jobs:
uses: wagoid/commitlint-github-action@v6
with:
configFile: commitlint.config.mjs
failOnWarnings: false
commitDepth: 50

- name: Run biome
run: bun run lint
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ dist/

# Bun
bun.lockb

# Examples
examples/*/node_modules
examples/*/dist
examples/*/.env
examples/*/.env.local
12 changes: 0 additions & 12 deletions commitlint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,5 @@ export default {
ignores: [
(commit) => /^WIP/i.test(commit),
(commit) => /^Merge/i.test(commit),
// Временное игнорирование старых коммитов до настройки commitlint
// TODO: Удалить после исправления старых коммитов или слияния PR
(commit) => {
const oldCommitPatterns = [
/^Fix\s/i, // "Fix quack function"
/^Support\s/i, // "Support bun in ci"
/^Rewrite\s/i, // "Rewrite unit tests to bun"
/^Code review/i, // "Code review"
/^chore: Add/i, // "chore: Add convention commit rules"
];
return oldCommitPatterns.some((pattern) => pattern.test(commit));
},
],
};
62 changes: 62 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# DuckBug.js Examples

This directory contains example integrations of `@duckbug/js` with various JavaScript frameworks and runtimes.

## Available Examples

- **[React](./react/)** - React application with Context API and custom hooks
- **[NestJS](./nestjs/)** - NestJS backend with module and service integration
- **[AdonisJS](./adonisjs/)** - AdonisJS application with service integration
- **[Express](./express/)** - Express.js server with middleware
- **[Fastify](./fastify/)** - Fastify server with plugin integration
- **[Bun](./bun/)** - Bun.js HTTP server example

## Quick Start

1. Choose an example that matches your framework
2. Navigate to the example directory
3. Copy `.env.example` to `.env` and add your DuckBug DSN
4. Install dependencies: `bun install`
5. Run the example: `bun run dev` (or see example-specific README)

## Setting Up Your DSN

All examples require a DuckBug DSN (Data Source Name) to send logs and errors.

1. Sign up at [DuckBug.io](https://duckbug.io)
2. Create a project
3. Copy your DSN from the project settings
4. Add it to `.env` file in the example directory:

```env
DUCKBUG_DSN=your-duckbug-dsn-here
```

## Using Local Library Version

All examples use the local version of `@duckbug/js` from the parent directory via `file:../..` in their `package.json`. This allows you to test changes to the library without publishing.

To use the published version instead, replace:
```json
"@duckbug/js": "file:../.."
```

with:
```json
"@duckbug/js": "^0.1.3"
```

## Framework Documentation

- [React](https://react.dev/)
- [NestJS](https://nestjs.com/)
- [AdonisJS](https://adonisjs.com/)
- [Express](https://expressjs.com/)
- [Fastify](https://www.fastify.io/)
- [Bun](https://bun.sh/)

## Need Help?

- 📖 [DuckBug.js Documentation](../../README.md)
- 🐛 [GitHub Issues](https://github.com/duckbugio/duckbug-js/issues)
- 💬 [DuckBug.io Support](https://duckbug.io)
1 change: 1 addition & 0 deletions examples/adonisjs/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DUCKBUG_DSN=your-duckbug-dsn-here
62 changes: 62 additions & 0 deletions examples/adonisjs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# DuckBug.js AdonisJS Example

This example demonstrates how to integrate `@duckbug/js` into an AdonisJS application using a service.

## Features

- AdonisJS service for DuckBug integration
- Example usage in routes
- TypeScript support

## Setup

1. Install dependencies:
```bash
bun install
```

2. Copy `.env.example` to `.env`:
```bash
cp .env.example .env
```

3. Add your DuckBug DSN to `.env`:
```env
DUCKBUG_DSN=your-duckbug-dsn-here
```

## Running

Start the development server:
```bash
bun run dev
```

The server will be available at `http://localhost:3333`

## API Endpoints

- `GET /` - Health check
- `GET /log` - Test log level
- `GET /debug` - Test debug level
- `GET /warn` - Test warn level
- `GET /error` - Test error level
- `GET /fatal` - Test fatal level
- `GET /quack` - Test error reporting

## Usage

The example includes:
- `app/services/duckbug.ts` - Service that provides DuckSDK instance
- `start/routes.ts` - Example routes using the service

## Example Code

```typescript
import duckBug from '#services/duckbug';

router.get('/my-route', async ({ response }) => {
duckBug.log('Route accessed', { path: '/my-route' });
return response.json({ message: 'Success' });
});
```
23 changes: 23 additions & 0 deletions examples/adonisjs/app/services/duckbug.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { DuckBugProvider, DuckSDK } from "@duckbug/js";

const dsn = process.env.DUCKBUG_DSN || "";

if (!dsn) {
console.warn("DUCKBUG_DSN is not set. DuckBug logging will not work.");
}

const providers = [
new DuckBugProvider({
dsn,
}),
];

const duck = new DuckSDK(providers, {
logReports: {
log: true,
warn: true,
error: true,
},
});

export default duck;
20 changes: 20 additions & 0 deletions examples/adonisjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "duckbug-adonisjs-example",
"version": "1.0.0",
"description": "AdonisJS example with DuckBug.js integration",
"scripts": {
"dev": "node --loader tsx --watch ace serve --watch",
"build": "node ace build",
"start": "node server.js"
},
"dependencies": {
"@duckbug/js": "file:../..",
"@adonisjs/core": "^7.0.0",
"@adonisjs/http-server": "^7.0.0"
},
"devDependencies": {
"@types/node": "^20.11.0",
"tsx": "^4.7.0",
"typescript": "^5.8.3"
}
}
16 changes: 16 additions & 0 deletions examples/adonisjs/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Ignitor } from "@adonisjs/core";
import { HttpServer } from "@adonisjs/core/http";

const ignitor = new Ignitor(import.meta.url, {
importer: (url) => import(url),
});

const httpServer = new HttpServer(ignitor, {
port: 3333,
host: "0.0.0.0",
});

await httpServer.start();
console.log(
"🚀 DuckBug.js AdonisJS Example is running on http://localhost:3333",
);
40 changes: 40 additions & 0 deletions examples/adonisjs/start/routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import router from "@adonisjs/core/services/router";
import duckBug from "#services/duckbug";

router.get("/", async ({ response }) => {
duckBug.log("Health check", { endpoint: "/" });
return response.json({ message: "DuckBug.js AdonisJS Example is running!" });
});

router.get("/log", async ({ response }) => {
duckBug.log("Test log", { level: "log", timestamp: Date.now() });
return response.json({ message: "Log sent" });
});

router.get("/debug", async ({ response }) => {
duckBug.debug("Test debug", { level: "debug", timestamp: Date.now() });
return response.json({ message: "Debug log sent" });
});

router.get("/warn", async ({ response }) => {
duckBug.warn("Test warning", { level: "warn", timestamp: Date.now() });
return response.json({ message: "Warning log sent" });
});

router.get("/error", async ({ response }) => {
duckBug.error("Test error", { level: "error", timestamp: Date.now() });
return response.json({ message: "Error log sent" });
});

router.get("/fatal", async ({ response }) => {
duckBug.fatal("Test fatal", { level: "fatal", timestamp: Date.now() });
return response.json({ message: "Fatal log sent" });
});

router.get("/quack", async ({ response }) => {
const testError = new Error("Test error from AdonisJS example");
testError.stack = `Error: Test error from AdonisJS example
at routes.ts:${Math.floor(Math.random() * 50) + 1}:1`;
duckBug.quack("ADONISJS_ERROR", testError);
return response.json({ message: "Error sent via quack" });
});
22 changes: 22 additions & 0 deletions examples/adonisjs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"lib": ["ES2022"],
"moduleResolution": "node",
"resolveJsonModule": true,
"allowJs": true,
"outDir": "./build",
"rootDir": "./",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": "./",
"paths": {
"#services/*": ["./app/services/*"]
}
},
"include": ["**/*.ts"],
"exclude": ["node_modules", "build"]
}
1 change: 1 addition & 0 deletions examples/bun/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DUCKBUG_DSN=your-duckbug-dsn-here
73 changes: 73 additions & 0 deletions examples/bun/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# DuckBug.js Bun.js Example

This example demonstrates how to integrate `@duckbug/js` into a Bun.js HTTP server.

## Features

- Simple HTTP server on Bun
- DuckSDK initialization
- Example endpoints with logging
- Minimal dependencies (Bun built-in)

## Setup

1. Install dependencies:
```bash
bun install
```

2. Copy `.env.example` to `.env`:
```bash
cp .env.example .env
```

3. Add your DuckBug DSN to `.env`:
```env
DUCKBUG_DSN=your-duckbug-dsn-here
```

## Running

Start the server:
```bash
bun run dev
```

The server will be available at `http://localhost:3000`

## API Endpoints

- `GET /` - Health check
- `GET /log` - Test log level
- `GET /debug` - Test debug level
- `GET /warn` - Test warn level
- `GET /error` - Test error level
- `GET /fatal` - Test fatal level
- `GET /quack` - Test error reporting

## Usage

The example includes:
- `src/index.ts` - Bun HTTP server with DuckSDK integration

## Example Code

```typescript
import { DuckSDK, DuckBugProvider } from '@duckbug/js';

const providers = [
new DuckBugProvider({
dsn: process.env.DUCKBUG_DSN || '',
}),
];

const duck = new DuckSDK(providers);

Bun.serve({
port: 3000,
fetch(req) {
duck.log('Request', { method: req.method, path: req.url });
return new Response('Hello from Bun!');
},
});
```
13 changes: 13 additions & 0 deletions examples/bun/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "duckbug-bun-example",
"version": "1.0.0",
"description": "Bun.js example with DuckBug.js integration",
"type": "module",
"scripts": {
"dev": "bun run src/index.ts",
"start": "bun run src/index.ts"
},
"dependencies": {
"@duckbug/js": "file:../.."
}
}
Loading