Socket
Book a DemoInstallSign in
Socket

wizinsight

Package Overview
Dependencies
Maintainers
0
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wizinsight

A lightweight performance monitoring & health tracking library for hyperwiz with Discord alerts and smart request optimization. Track API requests, monitor endpoint health, and get instant alerts when issues arise.

1.0.2
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
0
Weekly downloads
Β 
Created
Source

πŸ” wizinsight

npm version npm downloads bundle size TypeScript License: MIT Discord

⚑ A lightweight performance monitoring & health tracking library with Discord alerts and smart request optimization. Track your API requests, monitor health, and get instant alerts when issues arise.

✨ Features

  • πŸ“Š Request Metrics - Track performance of individual API requests
  • πŸ₯ Health Monitoring - Monitor multiple API endpoints with automatic alerts
  • πŸ”” Discord Integration - Get instant notifications when APIs go down
  • ⚑ Zero Configuration - Works out of the box with sensible defaults
  • πŸ›‘οΈ TypeScript Support - Full type safety and IntelliSense

πŸš€ Quick Start

πŸ“¦ Installation

npm install wizinsight

πŸ’» Basic Usage

import { createClient } from 'your-http-client'
import { initMetricsInterceptor } from 'wizinsight'

// Create your HTTP client
const client = createClient('https://api.example.com')

// Enable automatic metrics tracking ✨
initMetricsInterceptor(client)

// All requests are now automatically tracked! 🎯
const users = await client.get('/users')

πŸ“Š Request Metrics

πŸ“ˆ Track the performance of your API requests with detailed timing and error information.

⭐ What You Get Automatically

Every API request now logs:

  • βœ… Request method and URL
  • ⏱️ Response time (duration)
  • πŸ“Š HTTP status code
  • πŸ“¦ Request/response sizes (optional)
  • ❌ Detailed error information

πŸ“‹ Basic Monitoring

import { createClient } from 'your-http-client'
import { initMetricsInterceptor } from 'wizinsight'

const client = createClient('https://api.example.com')
initMetricsInterceptor(client)

// Console output:
// βœ… GET /users - 245ms - 200 OK
// βœ… POST /users - 180ms - 201 Created
// ❌ GET /invalid - 1200ms - 404 Not Found

🎨 Custom Logging

initMetricsInterceptor(client, {
  onRequestEnd: (metrics) => {
    console.log(`πŸš€ ${metrics.method} ${metrics.url} took ${metrics.duration}ms`)
  },
  
  onRequestError: (metrics) => {
    console.error(`πŸ’₯ ${metrics.method} ${metrics.url} failed: ${metrics.errorMessage}`)
  }
})

⚠️ Performance Alerts

initMetricsInterceptor(client, {
  onRequestEnd: (metrics) => {
    // Alert on slow requests
    if (metrics.duration > 1000) {
      console.warn(`🐌 Slow request: ${metrics.method} ${metrics.url} took ${metrics.duration}ms`)
    }
    
    // Alert on errors
    if (metrics.status >= 400) {
      console.error(`❌ Error: ${metrics.method} ${metrics.url} returned ${metrics.status}`)
    }
  }
})

πŸ“Š Collect All Metrics

initMetricsInterceptor(client, {
  collectRequestSize: true,
  collectResponseSize: true,
  
  onRequestEnd: (metrics) => {
    console.log(`πŸ“Š ${metrics.method} ${metrics.url}`)
    console.log(`   ⏱️  Duration: ${metrics.duration}ms`)
    console.log(`   πŸ“Š Status: ${metrics.status}`)
    console.log(`   πŸ“¦ Request: ${metrics.requestSize} bytes`)
    console.log(`   πŸ“¦ Response: ${metrics.responseSize} bytes`)
  }
})

πŸ“ˆ Custom Analytics Dashboard

const performanceData = {
  totalRequests: 0,
  averageResponseTime: 0,
  errorCount: 0
}

initMetricsInterceptor(client, {
  onRequestEnd: (metrics) => {
    performanceData.totalRequests++
    
    // Calculate average response time
    performanceData.averageResponseTime = 
      (performanceData.averageResponseTime + metrics.duration) / 2
    
    // Count errors
    if (metrics.status >= 400) {
      performanceData.errorCount++
    }
    
    console.table(performanceData)
  }
})

πŸ₯ Health Monitoring

Monitor the health of multiple API endpoints with automatic alerts and status tracking.

Why Health Monitoring?

  • πŸ” Proactive Monitoring - Catch issues before users do
  • πŸ“’ Instant Alerts - Get notified immediately when APIs go down
  • πŸ“Š Status Tracking - Keep track of API health over time
  • πŸ›‘οΈ Prevent Downtime - Identify and fix issues quickly

Basic Health Monitoring

import { initHealthMonitor, getHealthStatus } from 'wizinsight'

// Simple health monitoring
initHealthMonitor({
  targets: [
    { name: 'User API', url: 'https://api.example.com/users' },
    { name: 'Auth API', url: 'https://auth.example.com/health' },
    { name: 'Database', url: 'https://db.example.com/ping' }
  ]
})

// Check current health status
const health = getHealthStatus()
console.log(health)

Simple Request Examples

// GET request (default)
{ name: 'API', url: 'https://api.example.com/health' }

// POST with JSON body
{ 
  name: 'GraphQL', 
  url: 'https://api.example.com/graphql',
  method: 'POST',
  body: { query: '{ __typename }' }
}

// POST with headers
{ 
  name: 'Auth', 
  url: 'https://api.example.com/auth',
  method: 'POST',
  body: { token: 'test' },
  headers: { 'Authorization': 'Bearer test' }
}

// With timeout
{ 
  name: 'Slow API', 
  url: 'https://api.example.com/slow',
  timeout: 5000
}

Real API Testing Examples

// Test login with real credentials
{
  name: 'Login API',
  url: 'https://api.example.com/login',
  method: 'POST',
  body: { username: 'realuser', password: 'realpass' },
  expectedStatus: 200
}

// Test registration
{
  name: 'Register API',
  url: 'https://api.example.com/register',
  method: 'POST',
  body: { 
    email: 'test@example.com', 
    password: 'testpass',
    name: 'Test User'
  },
  expectedStatus: 201
}

// Test protected endpoint with token
{
  name: 'User Profile',
  url: 'https://api.example.com/user/profile',
  method: 'GET',
  headers: { 'Authorization': 'Bearer your-token-here' },
  expectedStatus: 200
}

Example Output:

{
  "https://api.example.com/users": {
    "lastChecked": 1703123456789,
    "lastStatus": 200,
    "isHealthy": true
  },
  "https://auth.example.com/health": {
    "lastChecked": 1703123456789,
    "lastStatus": 503,
    "isHealthy": false,
    "lastError": "Expected 200, got 503"
  }
}

Health Monitoring with Discord Alerts

initHealthMonitor({
  targets: [
    { name: 'Production API', url: 'https://api.production.com/health' },
    { name: 'Staging API', url: 'https://api.staging.com/health' }
  ],
  interval: 30000, // Check every 30 seconds
  discordWebhook: 'https://discord.com/api/webhooks/your-webhook-url',
  alertCooldown: 600000 // 10 minutes between alerts
})

Discord Alert Example:

🚨 Health Check Failed: Production API
API endpoint is not responding as expected

πŸ”— URL: https://api.production.com/health
πŸ“Š Status: 503
⏱️ Response Time: 245ms
🎯 Expected: 200
❌ Error: Expected 200, got 503

Advanced Configuration

initHealthMonitor({
  targets: [
    // Simple GET request
    { name: 'Health Check', url: 'https://api.example.com/health' },
    
    // POST with JSON body
    {
      name: 'GraphQL API',
      url: 'https://api.example.com/graphql',
      method: 'POST',
      body: { query: '{ __typename }' }
    },
    
    // POST with custom headers
    {
      name: 'Auth API',
      url: 'https://api.example.com/auth/verify',
      method: 'POST',
      body: { token: 'test-token' },
      headers: { 'Authorization': 'Bearer test-token' }
    },
    
    // POST with string body
    {
      name: 'File Upload',
      url: 'https://api.example.com/upload',
      method: 'POST',
      body: 'test-data',
      headers: { 'Content-Type': 'text/plain' }
    },
    
    // With timeout
    {
      name: 'Slow API',
      url: 'https://api.example.com/slow',
      timeout: 5000
    }
  ],
  interval: 60000, // 1 minute
  discordWebhook: process.env.DISCORD_WEBHOOK_URL,
  alertCooldown: 900000 // 15 minutes
})

Programmatic Health Checks

// Check if any services are down
const health = getHealthStatus()
const unhealthyServices = Object.entries(health).filter(([url, status]) => !status.isHealthy)

if (unhealthyServices.length > 0) {
  console.log('❌ Unhealthy services detected:')
  unhealthyServices.forEach(([url, status]) => {
    console.log(`   - ${url}: ${status.lastError}`)
  })
} else {
  console.log('βœ… All services are healthy!')
}

Stop Health Monitoring

import { stopHealthMonitor } from 'wizinsight'

// Stop monitoring when shutting down your app
stopHealthMonitor()

βš™οΈ Configuration Options

Metrics Interceptor Options

OptionDescriptionDefault
onRequestStartCalled when request starts-
onRequestEndCalled when request completes-
onRequestErrorCalled when request fails-
collectRequestSizeTrack request payload sizefalse
collectResponseSizeTrack response payload sizefalse

Health Monitor Options

OptionDescriptionDefault
targetsArray of API endpoints to monitorRequired
intervalHealth check interval in milliseconds60000 (60s)
discordWebhookDiscord webhook URL for alerts-
alertCooldownTime between alerts in milliseconds900000 (15m)

Health Target Configuration

OptionDescriptionDefault
nameDisplay name for the APIRequired
urlAPI endpoint URLRequired
methodHTTP method for health checkGET
bodyRequest body (any type)-
headersRequest headers-
expectedStatusExpected HTTP status code200
timeoutRequest timeout in milliseconds-

πŸ› οΈ Development

# Install dependencies
npm install

# Build the library
npm run build

# Development mode with watch
npm run dev

# Type checking
npm run type-check

πŸ“ Examples

Real-World Usage

// In your main application file
import { createClient } from 'hyperwiz'
import { initMetricsInterceptor, initHealthMonitor } from 'wizinsight'

// Set up API client with metrics
const client = createClient('https://api.yourcompany.com')
initMetricsInterceptor(client, {
  onRequestEnd: (metrics) => {
    if (metrics.duration > 1000) {
      console.warn(`Slow API call: ${metrics.url}`)
    }
  }
})

// Set up simple health monitoring
initHealthMonitor({
  targets: [
    // Basic health check
    { name: 'Main API', url: 'https://api.yourcompany.com/health' },
    
    // Test login
    {
      name: 'Login Service',
      url: 'https://api.yourcompany.com/login',
      method: 'POST',
      body: { username: 'healthuser', password: 'healthpass' },
      expectedStatus: 200
    },
    
    // Test registration
    {
      name: 'Registration',
      url: 'https://api.yourcompany.com/register',
      method: 'POST',
      body: { 
        email: 'health@test.com', 
        password: 'testpass',
        name: 'Health Test User'
      },
      expectedStatus: 201
    },
    
    // Test protected endpoint
    {
      name: 'User Profile',
      url: 'https://api.yourcompany.com/user/profile',
      method: 'GET',
      headers: { 'Authorization': 'Bearer your-token-here' },
      expectedStatus: 200
    }
  ],
  interval: 30000,
  discordWebhook: process.env.DISCORD_WEBHOOK_URL
})

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“„ License

MIT License - see the LICENSE file for details.

Keywords

hyperwiz

FAQs

Package last updated on 03 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.