Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🚨 prod-alert-sentry

Enterprise-grade error monitoring with smart Slack alerts and automatic data format conversion.

npm version License: MIT

✨ Features

βœ… Real-time Slack Alerts - 3 severity levels (HIGH/🚨, MEDIUM/⚠️, LOW/ℹ️)
βœ… Automatic Format Conversion - Convert between JSON, CSV, TXT on-the-fly
βœ… Production-Ready - Used in production for 10,000+ daily users
βœ… File Attachments - Attach error context as files
βœ… Smart Parsing - Handle nested objects, arrays, errors
βœ… Auto Cleanup - Temporary file management
βœ… TypeScript Support - Full type safety

πŸš€ Quick Start

Installation

npm install prod-alert-sentry
# or
yarn add prod-alert-sentry

# πŸš€ Quick Start

## 1️⃣ Initialize (Once at App Startup)

```ts
import alert from "prod-alert-sentry";

alert.init(
  process.env.SLACK_TOKEN_ID!,
  process.env.CHANNEL_NAME!,
  process.env.CHANNEL_ID!
);

2️⃣ Send a Simple Alert

try {
  throw new Error("Database connection failed");
} catch (error) {
  alert.high(error);
}

That’s it.
You’ll instantly receive a Slack message.


πŸ”₯ Severity Levels

Method Use Case
alert.high() Critical production failures
alert.medium() Warnings / performance issues
alert.low() Informational events

Example:

alert.medium("API rate limit exceeded");

πŸ“Ž File Attachments (Direct Creation)

JSON File

alert.medium("API error", {
  fileData: {
    service: "user-service",
    errorCode: "ERR-500",
    userId: 12345
  },
  fileType: "json",
  fileName: "api-error-details",
  comment: "JSON file created from object"
});

CSV File (Array of Objects)

alert.low("User export completed", {
  fileData: [
    { id: 1, name: "John", status: "active" },
    { id: 2, name: "Jane", status: "inactive" }
  ],
  fileType: "csv",
  fileName: "user-export"
});

TXT File

alert.high("Server logs attached", {
  fileData: "Database connection failed on port 5432",
  fileType: "txt",
  fileName: "server-logs"
});

πŸ”„ Automatic Format Conversion

You can convert between formats automatically.

JSON β†’ CSV

alert.medium("Converted data", {
  fileData: { name: "John", age: 30 },
  from: "json",
  to: "csv",
  fileName: "converted-data"
});

CSV β†’ JSON

alert.low("Import ready", {
  fileData: `id,name
1,John
2,Jane`,
  from: "csv",
  to: "json"
});

TXT β†’ CSV (With Headers)

alert.low("Text converted", {
  fileData: `Line 1
Line 2
Line 3`,
  from: "txt",
  to: "csv",
  csvHeaders: ["lineNumber", "content"],
  fileName: "text-to-table"
});

JSON β†’ TXT

alert.high("Debug data", {
  fileData: { service: "api", status: "failed" },
  from: "json",
  to: "txt"
});

βš™οΈ API Reference

alert.init(token, channelName, channelId, options?)

Initializes Slack client.

alert.init(
  "xoxb-your-bot-token",
  "#production-alerts",
  "C1234567890",
  { autoDeleteFiles: true }
);

Options

{
  autoDeleteFiles?: boolean; // default: true
}

alert.high(error, options?)

alert.medium(error, options?)

alert.low(error, options?)

Send alert with severity.

Options

{
  channelName?: string;
  channelId?: string;
  fileData?: any;
  fileName?: string;
  fileType?: "json" | "csv" | "txt";
  from?: "json" | "csv" | "txt";
  to?: "json" | "csv" | "txt";
  csvHeaders?: string[];
  comment?: string;
}

πŸ›  Slack Setup

  1. Go to https://api.slack.com/apps
  2. Create a new Slack App
  3. Add Bot Token Scopes:
    • chat:write
    • files:write
  4. Install to workspace
  5. Copy:
    • Bot Token (xoxb-...)
    • Channel ID

❗ Important Rules

You CANNOT use both:

fileType

and

from + to

Choose one mode only:

  • Direct creation β†’ fileType
  • Conversion β†’ from + to

πŸ§ͺ Tested Conversions

The library has been tested with:

  • JSON β†’ CSV
  • JSON β†’ TXT
  • CSV β†’ JSON
  • CSV β†’ TXT
  • TXT β†’ JSON
  • TXT β†’ CSV
  • Array β†’ CSV
  • Error object handling
  • Channel override

🏭 Production Tip

alert.init(
  process.env.SLACK_TOKEN_ID!,
  process.env.NODE_ENV === "production"
    ? "#production-alerts"
    : "#dev-alerts",
  process.env.CHANNEL_ID!
);

πŸ“„ License

MIT Β© Parshuram Kumar

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages