{"_id":"@amitkandar/response-handler","name":"@amitkandar/response-handler","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@amitkandar/response-handler","version":"1.0.0","main":"index.js","scripts":{"start":"node ./dist/index.js","dev":"nodemon --exec ts-node ./src/index.ts","test":"jest","build":"tsc","lint":"eslint . --ext .ts","format":"prettier --write .","prepare":"husky"},"lint-staged":{"src/**/*.{ts,tsx}":["eslint --fix","prettier --write"],"*.{js,json,md}":["prettier --write"]},"config":{"commitizen":{"path":"cz-conventional-changelog"}},"keywords":["response","error","rest","socket.io"],"author":{"name":"Amit Kandar"},"repository":{"type":"git","url":"git+https://github.com/amit-kandar/response-handler.git"},"license":"ISC","dependencies":{"express":"^5.1.0","socket.io":"^4.8.1"},"devDependencies":{"@commitlint/cli":"^19.8.1","@commitlint/config-conventional":"^19.8.1","@types/express":"^5.0.3","@types/jest":"^29.5.14","@types/node":"^22.15.30","@types/socket.io":"^3.0.2","@typescript-eslint/eslint-plugin":"^8.33.1","@typescript-eslint/parser":"^8.33.1","commitizen":"^4.3.1","cz-conventional-changelog":"^3.3.0","eslint":"^8.57.1","eslint-config-airbnb-base":"^15.0.0","eslint-config-prettier":"^10.1.5","eslint-plugin-import":"^2.31.0","eslint-plugin-prettier":"^5.4.1","husky":"^9.1.7","jest":"^29.7.0","lint-staged":"^16.1.0","prettier":"^3.5.3","ts-jest":"^29.3.4","ts-node":"^10.9.2","tsup":"^8.5.0","typescript":"^5.8.3"},"description":"Unified response and error handler for REST APIs and Socket.IO","gitHead":"50deb9dd4e4fac122d65eb16c131ed5ee529bf89","bugs":{"url":"https://github.com/amit-kandar/response-handler/issues"},"homepage":"https://github.com/amit-kandar/response-handler#readme","_id":"@amitkandar/response-handler@1.0.0","_nodeVersion":"18.17.1","_npmVersion":"9.6.7","dist":{"integrity":"sha512-gH7s2mKi283lUe1NXo87dAacHsAJsoLuPXP2gJxcqG7T6tZ1Dwz0qrJglhXO3qpiHLVexZEPTY02M3feFhuHFA==","shasum":"fbfb2a6d95d4e5806ee5b4232a7881e7e7702443","tarball":"https://registry.npmjs.org/@amitkandar/response-handler/-/response-handler-1.0.0.tgz","fileCount":16,"unpackedSize":10166,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCICX9s6BcwIsK1a7Ec1KVdj4eF/mAMNfnWVWH/GJB95ghAiEA+pABGc/nMu5gH9IKdt9wLASM+WLgKdGSOOx1bG0lICA="}]},"_npmUser":{"name":"amitkandar","email":"kandaramit5@gmail.com"},"directories":{},"maintainers":[{"name":"amitkandar","email":"kandaramit5@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/response-handler_1.0.0_1749369412665_0.6496334362955136"},"_hasShrinkwrap":false}},"time":{"created":"2025-06-08T07:56:52.559Z","1.0.0":"2025-06-08T07:56:52.824Z","modified":"2025-06-08T07:56:53.190Z"},"maintainers":[{"name":"amitkandar","email":"kandaramit5@gmail.com"}],"description":"Unified response and error handler for REST APIs and Socket.IO","homepage":"https://github.com/amit-kandar/response-handler#readme","keywords":["response","error","rest","socket.io"],"repository":{"type":"git","url":"git+https://github.com/amit-kandar/response-handler.git"},"author":{"name":"Amit Kandar"},"bugs":{"url":"https://github.com/amit-kandar/response-handler/issues"},"license":"ISC","readme":"# 🧩 Unified Response Handler\n\nSeamless response and error handler for REST and Socket.IO with optional global template configuration.\n\n## 🚀 Installation\n\n```bash\nnpm install @your-scope/unified-response-handler\n```\n\n## ✅ Features\n\n- Unified response structure across REST & Socket\n- Plug-and-play Express and Socket.IO support\n- Custom error types: `AppError`, `ValidationError`, `NotFoundError`\n- Optional global template override\n\n## 📦 Usage\n\n### Configure Template (optional)\n\n```js\nconst { configureResponseFormat } = require('@your-scope/unified-response-handler');\n\nconfigureResponseFormat(({ success, message, data, error }) => ({\n  status: success ? 'OK' : 'FAIL',\n  message,\n  ...(success ? { result: data } : { issue: error }),\n  time: Date.now(),\n}));\n```\n\n### REST\n\n```js\nconst {\n  sendSuccess,\n  errorHandler,\n  ValidationError,\n} = require('@your-scope/unified-response-handler');\n\napp.get('/user', (req, res, next) => {\n  if (!req.query.id) return next(new ValidationError({ id: 'Required' }));\n  sendSuccess(res, { id: req.query.id, name: 'Amit' }, 'Fetched');\n});\n\napp.use(errorHandler);\n```\n\n### Socket.IO\n\n```js\nconst { emitSuccess, emitError, ValidationError } = require('@your-scope/unified-response-handler');\n\nsocket.on('get-user', async (data) => {\n  try {\n    if (!data.user_id) throw new ValidationError({ user_id: 'Required' });\n    emitSuccess({ socket, event: 'user-data', data: { id: data.user_id, name: 'Amit' } });\n  } catch (err) {\n    emitError({ socket, event: 'user-data', error: err });\n  }\n});\n```\n\n## 👨‍💻 Development\n\n- Clone this repo\n- Run tests (if added) and lint code\n- Submit pull requests with your improvements\n\n## 📜 License\n\nMIT © Your Name\n","readmeFilename":"Readme.md","_rev":"1-b8cf3b140f01bcad11b9e0ebc89b2d7a"}