{"_id":"@ali-hajeh/response-handler","_rev":"4-b545c112c329f7b651279b17a1801186","name":"@ali-hajeh/response-handler","dist-tags":{"latest":"0.0.5"},"versions":{"0.0.1":{"name":"@ali-hajeh/response-handler","version":"0.0.1","author":{"name":"ali-hajeh"},"license":"ISC","_id":"@ali-hajeh/response-handler@0.0.1","maintainers":[{"name":"ali-hajeh","email":"aly.lhaj@gmail.com"}],"dist":{"shasum":"adc199dce1586301e6a98883faf6ac2e94c95cdb","tarball":"https://registry.npmjs.org/@ali-hajeh/response-handler/-/response-handler-0.0.1.tgz","fileCount":5,"integrity":"sha512-HqS+oyN7wUIPuC1LIiMCp2ZQXi4Lae46kv2iHtB3SVA3iqEjph3XRGB/8QqNN5qPVC4wA7fkvKeXzX0IpLycVw==","signatures":[{"sig":"MEUCIQCaijkZqN1/zkDC4fx6qQLkzSX9x6Kv4wsElVLShpwppgIgYi5O70955cnxQJSTtyhcaiSWh7e2AwoCp03/5uQsO+g=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":10043},"jest":{"preset":"ts-jest","testEnvironment":"node"},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"f9d3ba2fe3b9255159b2bee9be7c42bed9b553c3","scripts":{"dev":"ts-node-dev src/index.ts","test":"jest","build":"tsc"},"_npmUser":{"name":"ali-hajeh","email":"aly.lhaj@gmail.com"},"_npmVersion":"8.9.0","description":"A package to help organize responses from your Express.js API","directories":{},"_nodeVersion":"18.2.0","_hasShrinkwrap":false,"devDependencies":{"joi":"^17.13.3","jest":"^29.7.0","ts-jest":"^29.2.5","typescript":"^5.4.5","@types/jest":"^29.5.12","ts-node-dev":"^2.0.0","@types/express":"^4.17.21"},"_npmOperationalInternal":{"tmp":"tmp/response-handler_0.0.1_1724837879118_0.88365835349503","host":"s3://npm-registry-packages"}},"0.0.2":{"name":"@ali-hajeh/response-handler","version":"0.0.2","author":{"name":"ali-hajeh"},"license":"ISC","_id":"@ali-hajeh/response-handler@0.0.2","maintainers":[{"name":"ali-hajeh","email":"aly.lhaj@gmail.com"}],"dist":{"shasum":"9ffd72b98441057ab09e1d3e14777fb762c16e1c","tarball":"https://registry.npmjs.org/@ali-hajeh/response-handler/-/response-handler-0.0.2.tgz","fileCount":5,"integrity":"sha512-+7UYGHSvivzFm9GNZAMoNXqXJpLlp64zSHrA/tTndCcSpy7QDmjXFMc7ojN7LqdM2+YstlZ8kxZKZX+iJdZArg==","signatures":[{"sig":"MEUCIDEQw9dlIF54bgx4b6lumU3+HatX+x777zcX2qkcnRYvAiEAsJQTcXf299JKD5ZO+Exu16Si0hoy7wVYiwol3GgiRBY=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":10056},"jest":{"preset":"ts-jest","testEnvironment":"node"},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"e63bded6e1aefe374916a45d61d3f979ca843369","scripts":{"dev":"ts-node-dev src/index.ts","test":"jest","build":"tsc"},"_npmUser":{"name":"ali-hajeh","email":"aly.lhaj@gmail.com"},"_npmVersion":"8.9.0","description":"A package to help organize responses from your Express.js API","directories":{},"_nodeVersion":"18.2.0","_hasShrinkwrap":false,"devDependencies":{"joi":"^17.13.3","jest":"^29.7.0","ts-jest":"^29.2.5","typescript":"^5.4.5","@types/jest":"^29.5.12","ts-node-dev":"^2.0.0","@types/express":"^4.17.21"},"_npmOperationalInternal":{"tmp":"tmp/response-handler_0.0.2_1724838376314_0.1635157460766059","host":"s3://npm-registry-packages"}},"0.0.3":{"name":"@ali-hajeh/response-handler","version":"0.0.3","author":{"name":"ali-hajeh"},"license":"ISC","_id":"@ali-hajeh/response-handler@0.0.3","maintainers":[{"name":"ali-hajeh","email":"aly.lhaj@gmail.com"}],"dist":{"shasum":"c10b1ef88186e0c227717ca9943290e66f001386","tarball":"https://registry.npmjs.org/@ali-hajeh/response-handler/-/response-handler-0.0.3.tgz","fileCount":5,"integrity":"sha512-vISzFUoQNZ5SFU06bFlw+4lQhU5vWspjDbpGHgoH4xlaCedU/flchXIqFS5ySf13s0APJDIRPR5CeZa7rZzVSg==","signatures":[{"sig":"MEUCIQDwBKSXcup9Uzk1RafyWTpOVX0xoYpIXHCnBiri9i9DGwIgdDWm0lqOvLg1sBDdv4VyGf4wKDyRdZKFMCSLFvMtDfg=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":10870},"jest":{"preset":"ts-jest","testEnvironment":"node"},"main":"dist/index.js","types":"dist/index.d.ts","gitHead":"f6c4e842758fece1d9c2d4ec838090c43c744ec3","scripts":{"dev":"ts-node-dev src/index.ts","test":"jest","build":"tsc"},"_npmUser":{"name":"ali-hajeh","email":"aly.lhaj@gmail.com"},"_npmVersion":"8.9.0","description":"A package to help organize responses from your Express.js API","directories":{},"_nodeVersion":"18.2.0","_hasShrinkwrap":false,"devDependencies":{"joi":"^17.13.3","jest":"^29.7.0","ts-jest":"^29.2.5","typescript":"^5.4.5","@types/jest":"^29.5.12","ts-node-dev":"^2.0.0","@types/express":"^4.17.21"},"_npmOperationalInternal":{"tmp":"tmp/response-handler_0.0.3_1737116117336_0.5629465288881659","host":"s3://npm-registry-packages-npm-production"}},"0.0.4":{"name":"@ali-hajeh/response-handler","version":"0.0.4","keywords":["express","api","response","handler","typescript"],"author":{"name":"ali-hajeh"},"license":"ISC","_id":"@ali-hajeh/response-handler@0.0.4","maintainers":[{"name":"ali-hajeh","email":"aly.lhaj@gmail.com"}],"homepage":"https://github.com/ali-hajeh/response-handler","dist":{"shasum":"7f6f321c963c345f37052414e08023900f04ba15","tarball":"https://registry.npmjs.org/@ali-hajeh/response-handler/-/response-handler-0.0.4.tgz","fileCount":6,"integrity":"sha512-TZbAyVqQcRDh1KWIS6Jmlg2dPRG5F50nIlWAf3phER+UG+QJFqRrOPebn6JjRvIYu/Iz8JKDztw6aRxa7oOdpw==","signatures":[{"sig":"MEUCIQCCjEcy4ssrd249e4IaIzL69acoXaWgEfmyQ8Uq9mBV6gIgQXRZ4ihmrQp6j6IYJMOzlug6dwRYj+ljlTatFLwOwYo=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":14349},"jest":{"preset":"ts-jest","testEnvironment":"node"},"main":"dist/index.js","types":"dist/index.d.ts","module":"dist/index.js","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.js"}},"gitHead":"97ca45f389f857047215ccf4cfd5d400f4a847f7","scripts":{"dev":"ts-node-dev src/index.ts","lint":"prettier --check \"src/**/*.{ts,tsx}\"","test":"jest","build":"tsc","clean":"rm -rf dist","format":"prettier --write \"src/**/*.{ts,tsx}\"","prepublishOnly":"npm run clean && npm run build"},"typings":"dist/index","_npmUser":{"name":"ali-hajeh","email":"aly.lhaj@gmail.com"},"_npmVersion":"8.9.0","description":"A package to help organize responses from your Express.js API","directories":{"test":"test"},"_nodeVersion":"18.2.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"joi":"^17.13.3","jest":"^29.7.0","ts-jest":"^29.2.5","prettier":"^2.8.8","typescript":"^5.4.5","@types/jest":"^29.5.12","ts-node-dev":"^2.0.0","@types/express":"^4.17.21"},"_npmOperationalInternal":{"tmp":"tmp/response-handler_0.0.4_1737227389205_0.3274980716518945","host":"s3://npm-registry-packages-npm-production"}},"0.0.5":{"name":"@ali-hajeh/response-handler","version":"0.0.5","description":"A package to help organize responses from your Express.js API","keywords":["express","api","response","handler","typescript"],"homepage":"https://github.com/ali-hajeh/response-handler","license":"ISC","author":{"name":"ali-hajeh"},"main":"dist/index.js","module":"dist/index.js","types":"dist/index.d.ts","typings":"dist/index","exports":{".":{"require":"./dist/index.js","import":"./dist/index.js","types":"./dist/index.d.ts"}},"directories":{"test":"test"},"scripts":{"build":"tsc","dev":"ts-node-dev src/index.ts","test":"jest","clean":"rm -rf dist","format":"prettier --write \"src/**/*.{ts,tsx}\"","lint":"prettier --check \"src/**/*.{ts,tsx}\"","prepublishOnly":"npm run clean && npm run build"},"devDependencies":{"@types/express":"^4.17.21","@types/jest":"^29.5.12","jest":"^29.7.0","joi":"^17.13.3","prettier":"^2.8.8","ts-jest":"^29.2.5","ts-node-dev":"^2.0.0","typescript":"^5.4.5"},"jest":{"preset":"ts-jest","testEnvironment":"node"},"publishConfig":{"access":"public"},"gitHead":"f6c5cad3c7418b699a036f2090df75f193d02d63","_id":"@ali-hajeh/response-handler@0.0.5","_nodeVersion":"18.2.0","_npmVersion":"8.9.0","dist":{"integrity":"sha512-EVAjIlvM+S34lelPFbstlYS/4rrsOSGqydLflC0+IGCcoPB+x6lHsUdhMoL5f4Xv5VfEIfvsI4N+jNTc9dVVIQ==","shasum":"2d12e429cfd9973611666ebbcdb4d9552ea6c45c","tarball":"https://registry.npmjs.org/@ali-hajeh/response-handler/-/response-handler-0.0.5.tgz","fileCount":6,"unpackedSize":14351,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEHXsxUhDWF8/4B3A40VpIVu4J49UDf53ERnfVTG7hngAiA/nJhw/nTVVG65ui4SHnuIOUPyyxxW9XHczh1WodWAdA=="}]},"_npmUser":{"name":"ali-hajeh","email":"aly.lhaj@gmail.com"},"maintainers":[{"name":"ali-hajeh","email":"aly.lhaj@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/response-handler_0.0.5_1737227847147_0.1709946382353602"},"_hasShrinkwrap":false}},"time":{"created":"2024-08-28T09:37:59.029Z","modified":"2025-01-18T19:17:27.516Z","0.0.1":"2024-08-28T09:37:59.283Z","0.0.2":"2024-08-28T09:46:16.489Z","0.0.3":"2025-01-17T12:15:17.506Z","0.0.4":"2025-01-18T19:09:49.396Z","0.0.5":"2025-01-18T19:17:27.345Z"},"author":{"name":"ali-hajeh"},"license":"ISC","homepage":"https://github.com/ali-hajeh/response-handler","keywords":["express","api","response","handler","typescript"],"description":"A package to help organize responses from your Express.js API","maintainers":[{"name":"ali-hajeh","email":"aly.lhaj@gmail.com"}],"readme":"# @ali-hajeh/response-handler\n\nA lightweight and flexible package to help organize and standardize responses from your Express.js API.\n\n## Installation\n\nInstall the package using npm:\n\n```bash\nnpm install @ali-hajeh/response-handler\n```\n\n## Usage\n\nImport the `ResponseHandler` class in your Express.js application:\n\n```typescript\nimport ResponseHandler from \"@ali-hajeh/response-handler\";\n```\n\n### Middleware Setup\n\nTo use the ResponseHandler, you need to set it up as middleware in your Express application:\n\n```typescript\nimport express from \"express\";\nimport ResponseHandler from \"@ali-hajeh/response-handler\";\n\nconst app = express();\n\n// Apply the middleware\napp.use(ResponseHandler.middleware());\n```\n\n### Available Methods\n\nOnce the middleware is set up, the following methods will be available on the `res` object in your route handlers:\n\n1. `success`: Send a success response\n2. `badRequest`: Send a bad request response\n3. `joiValidationError`: Send a response for Joi validation errors\n4. `notFound`: Send a not found response\n5. `serverError`: Send a server error response\n6. `unauthorized`: Send an unauthorized response\n\n### Example\n\n```typescript\nimport express from \"express\";\nimport ResponseHandler from \"@ali-hajeh/response-handler\";\n\nconst app = express();\n\n// Apply the middleware\napp.use(ResponseHandler.middleware());\n\napp.get(\"/api/users\", (req, res) => {\n  // Your logic here\n  const users = [{ id: 1, name: \"John Doe\" }];\n  res.success({\n    data: users,\n    message: \"Users retrieved successfully\",\n  });\n});\n\napp.use((req, res) => {\n  res.notFound({ message: \"Route not found\" });\n});\n\napp.use((err, req, res, next) => {\n  res.serverError({ message: err.message });\n});\n```\n\n## API Reference\n\n### res.success(options)\n\nSend a success response.\n\n- `options`:\n  - `message` (optional): Success message (default: \"Success\")\n  - `data` (optional): Data to be sent in the response\n  - `statusCode` (optional): HTTP status code (default: 200)\n\n### res.badRequest(options)\n\nSend a bad request response.\n\n- `options`:\n  - `message` (optional): Error message (default: \"Bad Request\")\n  - `errors` (optional): Error details\n  - `statusCode` (optional): HTTP status code (default: 400)\n\n### res.joiValidationError(error, options)\n\nSend a response for Joi validation errors.\n\n- `error`: Joi ValidationError object\n- `options`:\n  - `statusCode` (optional): HTTP status code (default: 400)\n\n### res.notFound(options)\n\nSend a not found response.\n\n- `options`:\n  - `message` (optional): Error message (default: \"Not Found\")\n  - `errors` (optional): Error details\n  - `statusCode` (optional): HTTP status code (default: 404)\n\n### res.serverError(options)\n\nSend a server error response.\n\n- `options`:\n  - `message` (optional): Error message (default: \"Internal Server Error\")\n  - `errors` (optional): Error details\n  - `statusCode` (optional): HTTP status code (default: 500)\n\n### res.unauthorized(options)\n\nSend an unauthorized response.\n\n- `options`:\n  - `message` (optional): Error message (default: \"Unauthorized\")\n  - `errors` (optional): Error details\n  - `statusCode` (optional): HTTP status code (default: 401)\n\n## Custom Methods\n\nYou can add custom response methods using the `ResponseHandler.addCustomMethod` function:\n\n```typescript\nResponseHandler.addCustomMethod<[data: any, options?: { flag?: boolean }]>(\n  \"customResponse\",\n  function (data, options = {}) {\n    return this.status(200).json({ custom: true, data, ...options });\n  }\n);\n\n// Usage in a route\napp.get(\"/custom\", (req, res) => {\n  res.customResponse({ foo: \"bar\" }, { flag: true });\n});\n```\n\n## TypeScript Support\n\nThis package is written in TypeScript and includes type definitions. It exports a `ResponseType` interface that you can use to type your responses:\n\n```typescript\nimport { ResponseType } from \"@ali-hajeh/response-handler\";\n\nconst response: ResponseType = {\n  success: true,\n  message: \"Success\",\n  data: { id: 1 },\n  statusCode: 200,\n};\n```\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request or an Issue.\n\n## License\n\nThis project is licensed under the ISC License.\n","readmeFilename":"README.md"}