{"id":21637888,"url":"https://github.com/ishwar00/suvidha.js","last_synced_at":"2026-04-13T16:01:58.174Z","repository":{"id":254876773,"uuid":"847705336","full_name":"ishwar00/suvidha.js","owner":"ishwar00","description":"A lightweight Express.js library with type-safe validation, middleware context, and streamlined responses.","archived":false,"fork":false,"pushed_at":"2025-04-11T06:16:37.000Z","size":1766,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-26T08:11:31.929Z","etag":null,"topics":["express-middleware","express-validator","expressjs","zod"],"latest_commit_sha":null,"homepage":"https://suvidhajs.is-cool.dev","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ishwar00.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"license.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-08-26T11:44:12.000Z","updated_at":"2025-07-08T21:25:22.000Z","dependencies_parsed_at":"2025-03-19T11:46:06.384Z","dependency_job_id":null,"html_url":"https://github.com/ishwar00/suvidha.js","commit_stats":null,"previous_names":["ishwar00/suvidhajs","ishwar00/suvidha.js"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ishwar00/suvidha.js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ishwar00%2Fsuvidha.js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ishwar00%2Fsuvidha.js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ishwar00%2Fsuvidha.js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ishwar00%2Fsuvidha.js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ishwar00","download_url":"https://codeload.github.com/ishwar00/suvidha.js/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ishwar00%2Fsuvidha.js/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31759540,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-13T15:25:13.801Z","status":"ssl_error","status_checked_at":"2026-04-13T15:25:09.162Z","response_time":93,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["express-middleware","express-validator","expressjs","zod"],"created_at":"2024-11-25T04:07:27.308Z","updated_at":"2026-04-13T16:01:58.168Z","avatar_url":"https://github.com/ishwar00.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003ch1\u003eSuvidha\u003c/h1\u003e\n  \u003cp\u003eValidation • Context • Control\u003c/p\u003e\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n\u003ctable\u003e\n\u003ctr\u003e\n\u003ctd\u003e\n\u003ch3\u003eType-Safe Middleware\u003c/h3\u003e\n\u003cp\u003eChain middleware like LEGO blocks, with auto-typed context propagation.\u003c/p\u003e\n\u003c/td\u003e\n\u003ctd\u003e\n\u003ch3\u003eData Validation\u003c/h3\u003e\n\u003cp\u003eZod-powered type safety for body, params, and queries—without cluttering your routes.\u003c/p\u003e\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003ctr\u003e\n\u003ctd\u003e\n\u003ch3\u003eFramework Independence\u003c/h3\u003e\n\u003cp\u003eKeep your business logic clean—no Express.js baggage.\u003c/p\u003e\n\u003c/td\u003e\n\u003ctd\u003e\n\u003ch3\u003eExplicit Control\u003c/h3\u003e\n\u003cp\u003eFine-grained control over the request/response lifecycle.\u003c/p\u003e\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\u003c/div\u003e\n\nSuvidha (सुविधा - Hindi for 'facility') is a lightweight, type-safe Express.js library that adds powerful validation, middleware context management, and streamlined response handling.\n\n\u003e A utility class for building Express.js route handlers with built-in  \n\u003e data validation and middleware support. It allows you to define Zod  \n\u003e schemas for request parameters, body, and query, and chain middleware\n\u003e functions that can enrich the request context.\n\n- **No Rewrites** - Adopt incrementally in existing Express apps.\n- **TypeScript Native** - Inferred types end \"guess what's in `req`\" games.\n\nFor full documentation, see the [Suvidha Documentation](https://suvidhajs.is-cool.dev).\n\n## Installation\n\n```bash\nnpm install suvidha\n```\n\n## Quickstart\n\nThis example demonstrates a protected user creation endpoint with validation, authentication, and authorization.\n\n### app.ts\n\n```ts\nimport express from \"express\";\nimport { Suvidha, DefaultHandlers, Formatter } from \"suvidha\";\nimport { UserSchema } from \"./dto\";\nimport { authenticate, roleCheck } from \"./middlewares\";\nimport { createUserHandler } from \"./controller\";\n\nconst app = express();\napp.use(express.json());\n\nconst suvidha = () =\u003e Suvidha.create(new DefaultHandlers());\n\napp.post(\n    \"/users\",\n    suvidha()\n        .use(authenticate)\n        .use(roleCheck)\n        .body(UserSchema)\n        .handler(async (req) =\u003e {\n            const newUser = req.body; // Type: z.infer\u003ctypeof UserSchema\u003e\n            const { role } = req.context.user; // Type: string\n            return createUserHandler(newUser, role);\n        }),\n);\n\napp.listen(3000);\n```\n\n### controller.ts\n\n```ts\nimport { Http } from \"suvidha\";\nimport { UserDTO } from \"./dto\";\n\ndeclare function createUser(\n    user: UserDTO,\n    role: string,\n): Promise\u003c{ id: string }\u003e;\n\nexport async function createUserHandler(user: UserDTO, role: string) {\n    try {\n        const result = await createUser(user, role);\n        return Http.Created.body(result);\n    } catch (err: any) {\n        if (err.code === \"DUPLICATE_EMAIL\") {\n            throw Http.Conflict.body({ message: \"Email already exists\" });\n        }\n        throw err; // Propagate to Suvidha's onErr handler\n    }\n}\n```\n\n### middlewares.ts\n\n```ts\nimport { Http, CtxRequest } from \"suvidha\";\n\ninterface User {\n    role: string;\n    // ... other user properties\n}\n\nconst verify = async (token: string): Promise\u003cUser\u003e =\u003e {\n    // ... your authentication logic\n    return { role: \"admin\" }; // Example\n};\n\nexport const authenticate = async (req: CtxRequest) =\u003e {\n    const token = req.headers[\"authorization\"];\n    if (!token) {\n        throw new Http.Unauthorized();\n    }\n    const user = await verify(token).catch((_) =\u003e {\n        throw new Http.Unauthorized();\n    });\n    return { user };\n};\n\nexport const roleCheck = (req: CtxRequest\u003c{ user: User }\u003e) =\u003e {\n    if (req.context.user.role !== \"admin\") {\n        throw Http.Forbidden.body({ message: \"Admin access required\" });\n    }\n    return {};\n};\n```\n\n### dto.ts\n\n```ts\nimport { z } from \"zod\";\n\nexport const UserSchema = z.object({\n    username: z.string().min(3),\n    email: z.string().email(),\n    age: z.number().min(13),\n});\n\nexport type UserDTO = z.infer\u003ctypeof UserSchema\u003e;\n```\n\n**Sample Response (201 Created)**\n\n```json\n{\n    \"status\": \"success\",\n    \"data\": {\n        \"id\": \"67adc39ea1ff4e9d60273236\"\n    }\n}\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fishwar00%2Fsuvidha.js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fishwar00%2Fsuvidha.js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fishwar00%2Fsuvidha.js/lists"}