prod-alert-sentry
v1.1.0
Published
Enterprise-grade error monitoring with smart Slack alerts and automatic data format conversion. Used in production for lawyer booking platforms serving 10k+ daily users.
Downloads
385
Maintainers
Readme
🚨 prod-alert-sentry
Enterprise-grade error monitoring with smart Slack alerts and automatic data format conversion.
✨ 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
- Go to https://api.slack.com/apps
- Create a new Slack App
- Add Bot Token Scopes:
chat:writefiles:write
- Install to workspace
- Copy:
- Bot Token (
xoxb-...) - Channel ID
- Bot Token (
❗ Important Rules
You CANNOT use both:
fileTypeand
from + toChoose 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
