{"id":31967972,"url":"https://github.com/seeden/granter","last_synced_at":"2025-10-14T18:45:10.789Z","repository":{"id":318375166,"uuid":"1071014015","full_name":"seeden/granter","owner":"seeden","description":"Composable, type-safe authorization for TypeScript. ⭐️ Star to support my work","archived":false,"fork":false,"pushed_at":"2025-10-07T06:30:28.000Z","size":27,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-08T09:58:39.232Z","etag":null,"topics":["abac","access-control","async","authorization","authz","better-auth","express","permissions","rbac","security","typescript"],"latest_commit_sha":null,"homepage":"","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/seeden.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-06T18:40:56.000Z","updated_at":"2025-10-07T07:19:31.000Z","dependencies_parsed_at":"2025-10-06T21:17:27.563Z","dependency_job_id":"f896fe42-919b-4e3b-a6f8-64df956ede2a","html_url":"https://github.com/seeden/granter","commit_stats":null,"previous_names":["seeden/whocando","seeden/whocan","seeden/granter"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/seeden/granter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seeden%2Fgranter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seeden%2Fgranter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seeden%2Fgranter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seeden%2Fgranter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/seeden","download_url":"https://codeload.github.com/seeden/granter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seeden%2Fgranter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279020363,"owners_count":26086867,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["abac","access-control","async","authorization","authz","better-auth","express","permissions","rbac","security","typescript"],"created_at":"2025-10-14T18:45:06.621Z","updated_at":"2025-10-14T18:45:10.783Z","avatar_url":"https://github.com/seeden.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# granter\n\n\u003e Composable, type-safe authorization for TypeScript\n\n[![npm version](https://img.shields.io/npm/v/granter.svg)](https://www.npmjs.com/package/granter)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n**📚 [Read the full documentation →](https://seeden.github.io/granter)**\n\n## Why granter?\n\n✨ **Composable** - Build complex permissions from simple rules  \n🔒 **Type-safe** - Full TypeScript inference with generic contexts  \n⚡ **Async-first** - Works seamlessly with databases, APIs, and DataLoader  \n🔧 **Framework-agnostic** - Works with Express, Hono, Next.js, GraphQL, and more  \n🪶 **Zero dependencies** - Lightweight and performant\n\n## Quick Example\n\n```typescript\nimport { permission, or } from 'granter';\n\n// Define permissions\nconst isAdmin = permission('isAdmin', (ctx) =\u003e ctx.user.role === 'admin');\n\nconst isPostOwner = permission('isPostOwner', (ctx, post) =\u003e post.authorId === ctx.user.id);\n\n// Compose permissions\nconst canEditPost = or(isPostOwner, isAdmin);\n\n// Use them - permissions are callable!\nif (await canEditPost(ctx, post)) {\n  await updatePost(post);\n}\n\n// Require permission (throws if denied)\nawait canEditPost.orThrow(ctx, post);\n\n// Filter arrays\nconst editablePosts = await canEditPost.filter(ctx, allPosts);\n\n// Debug permission checks\nconst explanation = await canEditPost.explain(ctx, post);\n```\n\n## Installation\n\n```bash\nnpm install granter\n```\n\n## Documentation\n\nVisit **[seeden.github.io/granter](https://seeden.github.io/granter)** for the complete documentation:\n\n- **[Getting Started](https://seeden.github.io/granter/docs/getting-started)** - Install and use granter in 5 minutes\n- **[Core Concepts](https://seeden.github.io/granter/docs/permissions)** - Learn about permissions, operators, and methods\n- **[Express Example](https://seeden.github.io/granter/docs/express)** - Complete REST API example\n- **[API Reference](https://seeden.github.io/granter/docs/api-reference)** - Full API documentation\n\n## Key Features\n\n### Composable Operators\n\n```typescript\nimport { and, or, not } from 'granter';\n\n// Combine with OR (any must pass)\nconst canEdit = or(isPostOwner, isAdmin, isModerator);\n\n// Combine with AND (all must pass)\nconst canPublish = and(isAuthenticated, isVerified, isPostOwner);\n\n// Negate permissions\nconst canComment = and(isAuthenticated, not(isBanned));\n```\n\n### Powerful Methods\n\n```typescript\n// Check permission (returns boolean)\nif (await canEdit(ctx, post)) {\n  /* ... */\n}\n\n// Require permission (throws if denied)\nawait canEdit.orThrow(ctx, post);\n\n// Filter arrays to allowed items\nconst editable = await canEdit.filter(ctx, allPosts);\n\n// Debug permission checks\nconst explanation = await canEdit.explain(ctx, post);\n```\n\n### Simplify with `withContext()`\n\n```typescript\nimport { withContext } from 'granter';\n\nconst abilities = withContext(ctx, {\n  canEditPost,\n  canDeletePost,\n});\n\n// No need to pass ctx anymore!\nif (await abilities.canEditPost(post)) {\n  await updatePost(post);\n}\n```\n\n## Framework Examples\n\ngranter works with any TypeScript project. See the [documentation](https://seeden.github.io/granter) for complete examples with:\n\n- **[Express.js](https://seeden.github.io/granter/docs/express)** - REST API with middleware\n- **[Next.js](https://seeden.github.io/granter/docs/nextjs)** - Server Actions and App Router\n- **[GraphQL](https://seeden.github.io/granter/docs/graphql)** - Apollo Server with DataLoader\n- **[React](https://seeden.github.io/granter/docs/react)** - Context and hooks patterns\n\n## Authentication Integration\n\ngranter is **authorization-only** and works with any authentication library:\n\n- [Auth.js / NextAuth.js](https://seeden.github.io/granter/docs/auth-js)\n- [Clerk](https://seeden.github.io/granter/docs/clerk)\n- [Supabase Auth](https://seeden.github.io/granter/docs/supabase)\n- Custom JWT/Sessions\n- And more...\n\nSee the [Authentication Integration](https://seeden.github.io/granter/docs) guide for complete examples.\n\n## TypeScript Support\n\ngranter is built with TypeScript and provides full type inference:\n\n```typescript\ntype AppContext = {\n  user: { id: string; role: string };\n  db: Database;\n};\n\ntype Post = {\n  id: string;\n  authorId: string;\n};\n\nconst canEdit = or(isPostOwner, isAdmin);\n\n// ✅ Type-safe: ctx and post are fully typed\nawait canEdit(ctx, post);\n\n// ❌ TypeScript error: missing resource\nawait canEdit(ctx);\n```\n\n## Testing\n\nPermissions are pure functions, making them easy to test:\n\n```typescript\nimport { describe, it, expect } from 'vitest';\n\ndescribe('canEditPost', () =\u003e {\n  it('allows post owner', async () =\u003e {\n    const ctx = { user: { id: '1', role: 'user' }, db };\n    const post = { id: '123', authorId: '1' };\n\n    expect(await canEditPost(ctx, post)).toBe(true);\n  });\n\n  it('allows admin', async () =\u003e {\n    const ctx = { user: { id: '2', role: 'admin' }, db };\n    const post = { id: '123', authorId: '1' };\n\n    expect(await canEditPost(ctx, post)).toBe(true);\n  });\n\n  it('denies other users', async () =\u003e {\n    const ctx = { user: { id: '3', role: 'user' }, db };\n    const post = { id: '123', authorId: '1' };\n\n    expect(await canEditPost(ctx, post)).toBe(false);\n  });\n});\n```\n\n## Advanced Features\n\n### Parallel Operators\n\nUse `orParallel()` and `andParallel()` for DataLoader batching:\n\n```typescript\nimport { orParallel, andParallel } from 'granter';\n\n// Run all checks in parallel (no short-circuit)\nconst canEdit = orParallel(isPostOwner, isAdmin, isModerator);\n```\n\n**[Learn more about parallel execution →](https://seeden.github.io/granter/docs/parallel-execution)**\n\n### Debug with `.explain()`\n\nUnderstand why permissions passed or failed:\n\n```typescript\nconst explanation = await canEdit.explain(ctx, post);\nconsole.log(JSON.stringify(explanation, null, 2));\n// {\n//   \"name\": \"(isPostOwner OR isAdmin)\",\n//   \"value\": false,\n//   \"duration\": 15.23,\n//   \"children\": [\n//     { \"name\": \"isPostOwner\", \"value\": false, \"duration\": 8.12 },\n//     { \"name\": \"isAdmin\", \"value\": false, \"duration\": 7.11 }\n//   ]\n// }\n```\n\n**[Learn more about debugging →](https://seeden.github.io/granter/docs/debugging)**\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nMIT © [seeden](https://github.com/seeden)\n\n---\n\n**📚 [View Full Documentation](https://seeden.github.io/granter)** | **[GitHub](https://github.com/seeden/granter)** | **[npm](https://www.npmjs.com/package/granter)**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseeden%2Fgranter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fseeden%2Fgranter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseeden%2Fgranter/lists"}