Skip to content

lshtrade/sendErrorMessage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

SendErrorMessage

A comprehensive error logging solution providing both database-backed and direct notification approaches for modern applications.

πŸš€ Overview

SendErrorMessage is a collection of TypeScript libraries designed to solve different error logging needs:

  • error-logger-sendSMS - Direct Discord/Slack notifications without database dependencies
  • supabase-error-logger - Database-backed error logging with Supabase integration

Both libraries provide Sentry-style APIs (captureException/captureMessage) with different storage strategies to fit various application architectures.

πŸ“¦ Packages

error-logger-sendSMS

Zero-database error logging with instant Discord/Slack notifications

npm install error-logger-sendsms

Key Features:

  • πŸš€ Zero Database Required - Direct webhook notifications
  • πŸ”„ Multiple Providers - Discord and Slack support
  • πŸ›‘οΈ Data Sanitization - Automatic sensitive data protection
  • πŸ” Retry Logic - Built-in retry with exponential backoff
  • 🌍 Environment Aware - Automatic environment detection
  • ⚑ TypeScript First - Full type safety and IntelliSense

Quick Start:

import { ErrorLogger } from 'error-logger-sendsms';

const logger = new ErrorLogger({
  discord: {
    webhookUrl: process.env.DISCORD_WEBHOOK_URL!
  }
});

// Capture exceptions
try {
  throw new Error('Something went wrong!');
} catch (error) {
  await logger.captureException(error, { userId: '123' });
}

// Capture messages
await logger.captureMessage('User logged in', 'info', { userId: '123' });

Perfect for:

  • Frontend applications (React, Vue, Angular)
  • Microservices without centralized logging
  • Quick prototyping and MVP development
  • Teams using Discord/Slack for communication

supabase-error-logger

Database-backed error logging with Supabase integration

npm install supabase-error-logger @supabase/supabase-js

Key Features:

  • πŸ—„οΈ Persistent Storage - Errors stored in Supabase tables
  • πŸ“Š Queryable Data - SQL queries for error analysis
  • πŸ” Rich Context - User sessions, URLs, metadata
  • 🎯 Sentry-like API - Familiar captureException/captureMessage
  • πŸ”§ Runtime Configuration - Update settings without restart

Quick Start:

import { SupabaseErrorLogger } from 'supabase-error-logger';

const logger = new SupabaseErrorLogger({
  supabaseUrl: process.env.VITE_SUPABASE_URL!,
  supabaseKey: process.env.VITE_SUPABASE_ANON_KEY!,
  tableName: 'error_logs'
});

// Set user/session context
logger.setUser('user-123');
logger.setSession('session-abc');

// Capture exceptions
try {
  // ...
} catch (err) {
  await logger.captureException(err as Error, { status: 500 });
}

// Capture messages
await logger.captureMessage('just info');
await logger.captureMessage('warning!', 'warning', { area: 'checkout' });

Perfect for:

  • Production applications requiring error persistence
  • Teams needing error analytics and reporting
  • Applications with user session tracking
  • Long-term error monitoring and analysis

πŸ—οΈ Project Structure

sendErrorMessage/
β”œβ”€β”€ error-logger-sendSMS/          # Direct notification package
β”‚   β”œβ”€β”€ src/                       # Source code
β”‚   β”‚   β”œβ”€β”€ index.ts              # Main ErrorLogger class
β”‚   β”‚   β”œβ”€β”€ providers/             # Discord/Slack providers
β”‚   β”‚   β”œβ”€β”€ config/                # Configuration management
β”‚   β”‚   β”œβ”€β”€ types/                 # TypeScript definitions
β”‚   β”‚   └── utils/                 # Utilities (sanitization, retry)
β”‚   β”œβ”€β”€ examples/                  # Usage examples
β”‚   β”œβ”€β”€ tests/                     # Test suite
β”‚   └── README.md                  # Package documentation
β”œβ”€β”€ supabase-error-logger/         # Database-backed package
β”‚   β”œβ”€β”€ src/                       # Source code
β”‚   β”‚   β”œβ”€β”€ index.ts              # Main SupabaseErrorLogger class
β”‚   β”‚   β”œβ”€β”€ env-utils.ts          # Environment utilities
β”‚   β”‚   └── types/                # TypeScript definitions
β”‚   β”œβ”€β”€ examples/                  # Usage examples
β”‚   β”œβ”€β”€ schema.sql                # Database schema
β”‚   β”œβ”€β”€ tests/                     # Test suite
β”‚   └── README.md                  # Package documentation
β”œβ”€β”€ docs/                          # Project documentation
β”‚   β”œβ”€β”€ constitution-feature.md   # Project principles
β”‚   └── specify/                   # Feature specifications
β”œβ”€β”€ specs/                         # Technical specifications
└── README.md                      # This file

🎯 When to Use Which Package

Choose error-logger-sendSMS when:

  • βœ… You want immediate notifications without database setup
  • βœ… Your team uses Discord or Slack for communication
  • βœ… You need zero infrastructure dependencies
  • βœ… You're building frontend applications or microservices
  • βœ… You want quick setup and minimal configuration
  • βœ… You prefer real-time alerts over historical analysis

Choose supabase-error-logger when:

  • βœ… You need persistent error storage for analysis
  • βœ… You want to query and analyze error patterns
  • βœ… You're building production applications with user sessions
  • βœ… You need long-term error monitoring and reporting
  • βœ… You want to correlate errors with user behavior
  • βœ… You prefer data-driven debugging over immediate alerts

πŸš€ Getting Started

Prerequisites

  • Node.js 16+
  • TypeScript 5.0+
  • npm or yarn

Installation

For direct notifications (error-logger-sendSMS):

npm install error-logger-sendsms

For database logging (supabase-error-logger):

npm install supabase-error-logger @supabase/supabase-js

Environment Setup

Discord/Slack Notifications:

# Discord
DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/YOUR_WEBHOOK_ID/YOUR_TOKEN
DISCORD_USERNAME=ErrorBot

# Slack
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK
SLACK_CHANNEL=#errors

# Global settings
ERROR_LOGGER_ENABLED=true
ERROR_LOGGER_ENVIRONMENT=production

Supabase Database:

VITE_SUPABASE_URL=your_supabase_url
VITE_SUPABASE_ANON_KEY=your_supabase_anon_key

πŸ”§ Configuration

error-logger-sendSMS Configuration

const logger = new ErrorLogger({
  discord: {
    webhookUrl: 'https://discord.com/api/webhooks/YOUR_WEBHOOK_ID/YOUR_TOKEN',
    username: 'ErrorBot',
    avatarUrl: 'https://example.com/avatar.png'
  },
  slack: {
    webhookUrl: 'https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK',
    channel: '#errors',
    username: 'ErrorBot'
  },
  enabled: true,
  environment: 'production',
  retry: {
    maxAttempts: 3,
    baseDelay: 1000,
    maxDelay: 10000,
    jitter: true
  },
  sanitization: {
    enabled: true,
    customPatterns: ['password', 'token', 'secret']
  }
});

supabase-error-logger Configuration

const logger = new SupabaseErrorLogger({
  supabaseUrl: process.env.VITE_SUPABASE_URL!,
  supabaseKey: process.env.VITE_SUPABASE_ANON_KEY!,
  tableName: 'error_logs',
  enabled: true
});

// Set user/session context
logger.setUser('user-123');
logger.setSession('session-abc');

πŸ“Š Database Schema (supabase-error-logger)

create table if not exists error_logs (
  id uuid primary key default gen_random_uuid(),
  message text not null,
  stack text,
  level text not null check (level in ('error','warning','info')),
  timestamp timestamptz not null,
  user_id text,
  session_id text,
  url text,
  user_agent text,
  metadata jsonb,
  created_at timestamptz not null default now()
);

-- Optional index for performance
create index if not exists error_logs_level_timestamp_idx on error_logs(level, timestamp desc);

πŸ§ͺ Testing

Run Tests for All Packages

# Test error-logger-sendSMS
cd error-logger-sendSMS
npm test

# Test supabase-error-logger
cd supabase-error-logger
npm test

Test Coverage

# Coverage for error-logger-sendSMS
cd error-logger-sendSMS
npm run test:coverage

# Coverage for supabase-error-logger
cd supabase-error-logger
npm run test:coverage

πŸ› οΈ Development

Building Packages

# Build error-logger-sendSMS
cd error-logger-sendSMS
npm run build

# Build supabase-error-logger
cd supabase-error-logger
npm run build

Development Mode

# Watch mode for error-logger-sendSMS
cd error-logger-sendSMS
npm run dev

# Watch mode for supabase-error-logger
cd supabase-error-logger
npm run dev

πŸ“š Examples

Express.js Integration (error-logger-sendSMS)

import express from 'express';
import { ErrorLogger } from 'error-logger-sendsms';

const app = express();
const errorLogger = new ErrorLogger();

// Global error handler
app.use(async (err: Error, req: Request, res: Response, next: NextFunction) => {
  await errorLogger.captureException(err, {
    method: req.method,
    url: req.url,
    headers: req.headers,
    body: req.body,
    query: req.query
  });

  res.status(500).json({ error: 'Internal server error' });
});

Remix Integration (supabase-error-logger)

// app/root.tsx
import { SupabaseErrorLogger } from 'supabase-error-logger';

const errorLogger = new SupabaseErrorLogger({
  supabaseUrl: (globalThis as any).__ENV?.SUPABASE_URL || import.meta.env.VITE_SUPABASE_URL,
  supabaseKey: (globalThis as any).__ENV?.SUPABASE_ANON_KEY || import.meta.env.VITE_SUPABASE_ANON_KEY,
});

export function ErrorBoundary({ error }: Route.ErrorBoundaryProps) {
  if (isRouteErrorResponse(error)) {
    if (error.status !== 404) {
      errorLogger.captureException({ 
        status: error.status, 
        statusText: error.statusText, 
        message: String(error) 
      });
    }
  } else {
    errorLogger.captureException(error as any);
  }
  // ... existing rendering logic
}

πŸ”’ Security & Privacy

Data Sanitization

Both packages automatically sanitize sensitive data:

Default Patterns:

  • password, token, key, secret
  • auth, credential, api_key
  • access_token, refresh_token

Custom Patterns:

const logger = new ErrorLogger({
  sanitization: {
    enabled: true,
    customPatterns: ['custom_secret', 'internal_key']
  }
});

Environment Variables

  • Never commit webhook URLs or API keys to version control
  • Use environment variables for all sensitive configuration
  • Rotate webhook URLs and API keys regularly
  • Use different webhooks for different environments

🀝 Contributing

We welcome contributions! Please see our contributing guidelines:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes with tests
  4. Run tests (npm test)
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

Development Setup

# Clone the repository
git clone https://github.com/lshtrade/sendErrorMessage.git
cd sendErrorMessage

# Install dependencies for both packages
cd error-logger-sendSMS && npm install
cd ../supabase-error-logger && npm install

# Run tests
cd ../error-logger-sendSMS && npm test
cd ../supabase-error-logger && npm test

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ†˜ Support

πŸ—ΊοΈ Roadmap

Upcoming Features

  • Additional Providers: Microsoft Teams, Telegram, Email notifications
  • Error Aggregation: Group similar errors to reduce noise
  • Performance Monitoring: Integration with performance metrics
  • Custom Dashboards: Web-based error monitoring interface
  • Mobile Support: React Native and Flutter integrations

Version History

  • v1.0.1 - Initial release with Discord/Slack support
  • v1.0.0 - Stable release with comprehensive testing
  • v0.9.0 - Beta release with core functionality

Made with ❀️ for developers who care about error monitoring

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published