{"_id":"@customerglu/api-retry-monitor","_rev":"4-0b65882a36789c70e324cb71e0eeeb5e","name":"@customerglu/api-retry-monitor","dist-tags":{"latest":"1.0.5"},"versions":{"1.0.3":{"name":"@customerglu/api-retry-monitor","version":"1.0.3","keywords":["api","retry","monitoring","slack"],"author":{"name":"Prateek Gupta"},"license":"MIT","_id":"@customerglu/api-retry-monitor@1.0.3","maintainers":[{"name":"himanshu793","email":"himanshu@customerglu.net"},{"name":"prateekcg","email":"prateek@customerglu.net"},{"name":"kushagr","email":"kushagr@customerglu.net"},{"name":"mahiranand","email":"mahir@customerglu.net"}],"homepage":"https://github.com/customerglu/api-retry-monitor#readme","bugs":{"url":"https://github.com/customerglu/api-retry-monitor/issues"},"dist":{"shasum":"e61326e9a4fb83cd514930de147823be4a181224","tarball":"https://registry.npmjs.org/@customerglu/api-retry-monitor/-/api-retry-monitor-1.0.3.tgz","fileCount":5,"integrity":"sha512-mPY1LjeuAmTvdzJekRm4HaqJY8r+KNAGnF/OslFeziFbvOIPuk6DnbBYWa+I67nrmxRErFuq7X32GBs4+ifh6g==","signatures":[{"sig":"MEUCIQCBTXPRJv1cWUrC8PGqLY4UwWR5kSoK4jxLdQ9GhifarAIgBA8J+NZl0Vro9Su3Uplxu+0T1cB3lpj6CJd6oyjea9c=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":16130},"main":"index.js","gitHead":"83314d62d460bf77b9c727a8c92f59881ec48aee","_npmUser":{"name":"prateekcg","email":"prateek@customerglu.net"},"repository":{"url":"git+https://github.com/customerglu/api-retry-monitor.git","type":"git"},"_npmVersion":"10.7.0","description":"API retry mechanism with failure monitoring and reporting","directories":{},"_nodeVersion":"20.15.1","dependencies":{"axios":"^0.21.4"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/api-retry-monitor_1.0.3_1742993706173_0.4588114902449636","host":"s3://npm-registry-packages-npm-production"}},"1.0.4":{"name":"@customerglu/api-retry-monitor","version":"1.0.4","keywords":["api","retry","monitoring","slack"],"author":{"name":"Prateek Gupta"},"license":"MIT","_id":"@customerglu/api-retry-monitor@1.0.4","maintainers":[{"name":"himanshu793","email":"himanshu@customerglu.net"},{"name":"prateekcg","email":"prateek@customerglu.net"},{"name":"kushagr","email":"kushagr@customerglu.net"},{"name":"mahiranand","email":"mahir@customerglu.net"}],"homepage":"https://github.com/customerglu/api-retry-monitor#readme","bugs":{"url":"https://github.com/customerglu/api-retry-monitor/issues"},"dist":{"shasum":"7e5501b1d0d63f2743602ef57202e5ea63217ad5","tarball":"https://registry.npmjs.org/@customerglu/api-retry-monitor/-/api-retry-monitor-1.0.4.tgz","fileCount":6,"integrity":"sha512-4hHeRg5joW6m4O76yyVphsDg2/86LiD0n32+PyfEILhLSxh8EeQ4+Uz/2nZ73f8xlaaaWYJLPvzkM77RyvoIig==","signatures":[{"sig":"MEYCIQDyu6x9T90qCTBFWKp2GSofCkWEOkWBwo/9K7OKIC0HkQIhAKVtcbJP6HP2gGVG1/i8FwBeSiIqV6dJ/rSlDCYqxo28","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":21655},"main":"index.js","gitHead":"83314d62d460bf77b9c727a8c92f59881ec48aee","_npmUser":{"name":"prateekcg","email":"prateek@customerglu.net"},"repository":{"url":"git+https://github.com/customerglu/api-retry-monitor.git","type":"git"},"_npmVersion":"10.7.0","description":"API retry mechanism with failure monitoring and reporting","directories":{},"_nodeVersion":"20.15.1","dependencies":{"axios":"^0.21.4"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/api-retry-monitor_1.0.4_1742993838682_0.31569487294097476","host":"s3://npm-registry-packages-npm-production"}},"1.0.5":{"name":"@customerglu/api-retry-monitor","version":"1.0.5","keywords":["api","retry","monitoring","slack"],"author":{"name":"Prateek Gupta"},"license":"MIT","_id":"@customerglu/api-retry-monitor@1.0.5","maintainers":[{"name":"himanshu793","email":"himanshu@customerglu.net"},{"name":"prateekcg","email":"prateek@customerglu.net"},{"name":"kushagr","email":"kushagr@customerglu.net"},{"name":"mahiranand","email":"mahir@customerglu.net"}],"homepage":"https://github.com/customerglu/api-retry-monitor#readme","bugs":{"url":"https://github.com/customerglu/api-retry-monitor/issues"},"dist":{"shasum":"4135af5a288ed031a2f6f882e470d12151895a55","tarball":"https://registry.npmjs.org/@customerglu/api-retry-monitor/-/api-retry-monitor-1.0.5.tgz","fileCount":6,"integrity":"sha512-y0Zfo5GMwERCKySIZKZkIenuc1W/vgdqXoaWEpNJUcOv0mlqCchlnwE5Je+ihi5O4JE7NshmjOQJtO0q9j+49A==","signatures":[{"sig":"MEYCIQCUWHYejuWf6zfw/mUO8WJQCPzzVZiul+4C3IclSJcBtQIhAIIOywVq3Ulcydyaasu3pihhOShcI4q54b4j7UEU1jFM","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":21531},"main":"index.js","gitHead":"7df3cd0feeea024b39c19aa2b354e1660bfedb4a","_npmUser":{"name":"prateekcg","email":"prateek@customerglu.net"},"repository":{"url":"git+https://github.com/customerglu/api-retry-monitor.git","type":"git"},"_npmVersion":"10.7.0","description":"API retry mechanism with failure monitoring and reporting","directories":{},"_nodeVersion":"20.15.1","dependencies":{"axios":"^0.21.4"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/api-retry-monitor_1.0.5_1742994229631_0.37321452585070025","host":"s3://npm-registry-packages-npm-production"}}},"time":{"created":"2025-03-26T12:55:06.090Z","modified":"2026-02-10T14:02:03.306Z","1.0.3":"2025-03-26T12:55:06.341Z","1.0.4":"2025-03-26T12:57:18.856Z","1.0.5":"2025-03-26T13:03:49.813Z"},"bugs":{"url":"https://github.com/customerglu/api-retry-monitor/issues"},"author":{"name":"Prateek Gupta"},"license":"MIT","homepage":"https://github.com/customerglu/api-retry-monitor#readme","keywords":["api","retry","monitoring","slack"],"repository":{"url":"git+https://github.com/customerglu/api-retry-monitor.git","type":"git"},"description":"API retry mechanism with failure monitoring and reporting","maintainers":[{"email":"prateek@customerglu.net","name":"prateekcg"},{"email":"kushagr@customerglu.net","name":"kushagr"}],"readme":"# API Retry Monitor\n\nA robust API retry and monitoring library that adds intelligent retry capability with Slack reporting for any axios-based API calls. This package provides automatic random delay retries, failure tracking, and real-time alerts.\n\n## Installation\n\nThe package is available on GitHub Packages. Add it to your project with npm:\n\n```bash\n# Install:\nnpm install @customerglu/api-retry-monitor\n```\n\n## Quick Start\n\n### Basic Integration\n\nReplace your direct axios calls with the retry-enabled version:\n\n```javascript\n// Before\nconst axios = require(\"axios\");\nconst response = await axios.get(\"https://api.example.com/data\");\n\n// After\nconst { createApiRetryMonitor } = require(\"@customerglu/api-retry-monitor\");\nconst apiMonitor = createApiRetryMonitor({\n  slackWebhookUrl: process.env.SLACK_WEBHOOK_URL,\n});\nconst axiosInstance = apiMonitor.createAxiosInstance();\nconst response = await axiosInstance.get(\"https://api.example.com/data\");\n```\n\n### Adding Context for Better Failure Tracking\n\n```javascript\n// Add context to get better reporting\nawait axiosInstance.post(\"https://api.example.com/events\", data, {\n  context: {\n    eventId: \"unique-request-id\",\n    client: \"clientName\",\n    eventType: \"dataSync\",\n  },\n});\n```\n\n## Integration Examples\n\n### Express Application\n\n```javascript\nconst express = require(\"express\");\nconst { createApiRetryMonitor } = require(\"@customerglu/api-retry-monitor\");\n\nconst app = express();\nconst apiMonitor = createApiRetryMonitor({\n  slackWebhookUrl: process.env.SLACK_WEBHOOK_URL,\n});\n\n// Create a reusable axios instance\nconst api = apiMonitor.createAxiosInstance();\n\napp.get(\"/data\", async (req, res) => {\n  try {\n    // Use with automatic retry handling\n    const response = await api.get(\"https://api.example.com/data\", {\n      context: { requestId: req.id, client: req.query.client },\n    });\n    res.json(response.data);\n  } catch (error) {\n    res.status(500).json({ error: error.message });\n  }\n});\n\n// Clean shutdown\nprocess.on(\"SIGTERM\", () => {\n  apiMonitor.shutdown();\n  server.close();\n});\n```\n\n### Serverless Function\n\n```javascript\nconst { createApiRetryMonitor } = require(\"@customerglu/api-retry-monitor\");\n\n// Create outside handler for reuse between invocations\nconst apiMonitor = createApiRetryMonitor({\n  slackWebhookUrl: process.env.SLACK_WEBHOOK_URL,\n  alertWindowHours: 1,\n});\nconst api = apiMonitor.createAxiosInstance();\n\nexports.handler = async (event) => {\n  try {\n    const result = await api.post(\n      \"https://api.example.com/process\",\n      event.body,\n      { context: { eventId: event.requestId } }\n    );\n    return { statusCode: 200, body: JSON.stringify(result.data) };\n  } catch (error) {\n    return { statusCode: 500, body: JSON.stringify({ error: error.message }) };\n  }\n};\n```\n\n### Using with Any Promise-Based API Call\n\n```javascript\nconst { createApiRetryMonitor } = require(\"@customerglu/api-retry-monitor\");\n\nconst apiMonitor = createApiRetryMonitor({\n  maxRetries: 5,\n  minDelayMs: 2000,\n  maxDelayMs: 8000,\n});\n\n// Works with any promise-returning function, not just axios\nconst result = await apiMonitor.executeWithRetry(\n  async () => {\n    // Database query, API call, or any async operation\n    const result = await someAsyncOperation();\n    return result;\n  },\n  { eventId: \"operation-id\" }\n);\n```\n\n## Configuration Options\n\nCreate your api-retry-monitor with the following configuration options:\n\n```javascript\nconst apiMonitor = createApiRetryMonitor({\n  // Required\n  slackWebhookUrl: process.env.SLACK_WEBHOOK_URL, // Where to send alerts\n\n  // Optional with defaults\n  alertWindowHours: 1, // How often to send summary reports (in hours)\n  burstThreshold: 5, // How many failures trigger an immediate alert\n  burstWindowSeconds: 60, // Time window for burst detection\n  flushThreshold: 20, // Max records before flushing to prevent memory leaks\n  maxRetries: 10, // Maximum retry attempts before giving up\n  minDelayMs: 1000, // Minimum retry delay (1 second)\n  maxDelayMs: 10000, // Maximum retry delay (10 seconds)\n});\n```\n\n## Alert Types\n\nThe library provides two types of Slack alerts:\n\n1. **Burst Failure Alerts** - Sent immediately when multiple failures occur in a short time\n2. **Scheduled Reports** - Sent at regular intervals with failure statistics\n\nBoth include:\n\n- Total failure count\n- Successful retries count\n- Permanent failures count\n- Client summaries\n- Status code breakdowns\n- Event type statistics\n\n## Tips for Effective Implementation\n\n1. **Add Meaningful Context**: Always include identifiers in the `context` object\n2. **Handle Graceful Shutdowns**: Call `apiMonitor.shutdown()` when your application is shutting down\n3. **Configure Alert Windows**: Set appropriate `alertWindowHours` based on your traffic and operation patterns\n4. **Set Practical Retry Limits**: Balance between persistence and failing fast with `maxRetries`\n\n## Troubleshooting\n\n- **No Slack Alerts**: Verify your Slack webhook URL is correct and the channel exists\n- **Memory Usage**: If you notice high memory usage, lower the `flushThreshold` value\n- **Excess Alerts**: Increase `burstThreshold` or `burstWindowSeconds` to reduce alert frequency\n\n## Features\n\n- Random delay retry mechanism (1-10 seconds)\n- Maximum of 10 retry attempts\n- Failure tracking with memory management\n- Hourly reporting via Slack\n- Burst failure detection (5+ failures in 1 minute)\n- Support for Axios HTTP client\n","readmeFilename":"README.md"}