{"_id":"@superfunctions/auth","_rev":"4-025fcf848f2fef1b7afbe21646656221","name":"@superfunctions/auth","dist-tags":{"latest":"0.2.0"},"versions":{"0.1.0":{"name":"@superfunctions/auth","version":"0.1.0","keywords":["auth","authentication","authorization","framework-agnostic","api-keys","superfunctions"],"author":{"name":"21n"},"license":"MIT","_id":"@superfunctions/auth@0.1.0","maintainers":[{"name":"21native","email":"npm@21n.org"}],"homepage":"https://github.com/21nCo/super-functions#readme","bugs":{"url":"https://github.com/21nCo/super-functions/issues"},"dist":{"shasum":"d8b4ed54c88bed730f99a3eefa5cc4607c9f9154","tarball":"https://registry.npmjs.org/@superfunctions/auth/-/auth-0.1.0.tgz","fileCount":2,"integrity":"sha512-qlq3hsV/Vjo5wX1nL7IrcWPaIKqlZ1hIbp2TUuDiKAIbSNr4sonGfGZZsMzb/E3Tqd15URiNio/RW6SpZkJJsw==","signatures":[{"sig":"MEQCIHUXZdJp0P5+Fzem7t29rZH0qF/OJ8ULy3c0ApZ4Fo4GAiAJpX5hp0+wNVDyPIRRwwHoWASMvvxWuwPkzXIl4mssyg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":4961},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"./types":{"types":"./dist/types.d.ts"}},"gitHead":"b1140ab1f60ad8bd57fe814cd244d543964ba55d","scripts":{"lint":"echo 'lint not configured'","test":"vitest","build":"tsc","clean":"rm -rf dist","typecheck":"tsc --noEmit","test:watch":"vitest --watch"},"_npmUser":{"name":"21native","email":"npm@21n.org"},"repository":{"url":"git+https://github.com/21nCo/super-functions.git","type":"git","directory":"packages/auth"},"_npmVersion":"11.6.1","description":"Framework-agnostic authentication abstraction layer for Superfunctions libraries","directories":{},"_nodeVersion":"23.11.1","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"vitest":"^3.2.4","typescript":"^5.6.0","@types/node":"^22.0.0"},"_npmOperationalInternal":{"tmp":"tmp/auth_0.1.0_1766930870496_0.29054778498389244","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@superfunctions/auth","version":"0.1.1","keywords":["auth","authentication","authorization","framework-agnostic","api-keys","superfunctions"],"author":{"name":"21n"},"license":"MIT","_id":"@superfunctions/auth@0.1.1","maintainers":[{"name":"21native","email":"npm@21n.org"}],"homepage":"https://github.com/21nCo/super-functions#readme","bugs":{"url":"https://github.com/21nCo/super-functions/issues"},"dist":{"shasum":"a46268fe22899b0893c259d38bfd6f226cadd2dc","tarball":"https://registry.npmjs.org/@superfunctions/auth/-/auth-0.1.1.tgz","fileCount":14,"integrity":"sha512-smiTQV70lf5o0hoW0jpoGq4uavmu+D2B7eTsF9vXAErZYngu0ZtGLSthuJg4N/SaPFReTp8DXBhq78xuUn1FRw==","signatures":[{"sig":"MEUCIBUoOgbtFVRgkFi+ahArtaCmnIyPW4V+zQKoJFClj31MAiEAx/p72h4Va+ClOujyaAmP8ogPe9HFVFW3hCKOjWv0eEk=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":20892},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"./types":{"types":"./dist/types.d.ts"}},"gitHead":"b1140ab1f60ad8bd57fe814cd244d543964ba55d","scripts":{"lint":"echo 'lint not configured'","test":"vitest","build":"tsc","clean":"rm -rf dist","typecheck":"tsc --noEmit","test:watch":"vitest --watch"},"_npmUser":{"name":"21native","email":"npm@21n.org"},"repository":{"url":"git+https://github.com/21nCo/super-functions.git","type":"git","directory":"packages/auth"},"_npmVersion":"11.6.1","description":"Framework-agnostic authentication abstraction layer for Superfunctions libraries","directories":{},"_nodeVersion":"23.11.1","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"vitest":"^3.2.4","typescript":"^5.6.0","@types/node":"^22.0.0"},"_npmOperationalInternal":{"tmp":"tmp/auth_0.1.1_1767624124302_0.37315596478600566","host":"s3://npm-registry-packages-npm-production"}},"0.1.2":{"name":"@superfunctions/auth","version":"0.1.2","keywords":["auth","authentication","authorization","framework-agnostic","api-keys","superfunctions"],"author":{"name":"21n"},"license":"MIT","_id":"@superfunctions/auth@0.1.2","maintainers":[{"name":"21native","email":"npm@21n.org"}],"homepage":"https://github.com/21nCo/super-functions#readme","bugs":{"url":"https://github.com/21nCo/super-functions/issues"},"dist":{"shasum":"ef09dfc4f83a949ba9c16b354121d2bd8ff21408","tarball":"https://registry.npmjs.org/@superfunctions/auth/-/auth-0.1.2.tgz","fileCount":14,"integrity":"sha512-H4PNnKz9D9+2zwWwZcSOCfdSp5h1vjP/QK5t0w0WEPd/VTdpmZ+VeBd/Sx60HRAuQmfjrYPFLY2t6Z6AEE/ukg==","signatures":[{"sig":"MEQCIF4rhm9Ryl9UBRXRWriRjIGWOqnyIkFU++EJw3Q/VrrSAiBC1seUaTGHVaMQpxnt7XqcCVKpcBFuEaX7IDjIDx6V/g==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":35521},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"./types":{"types":"./dist/types.d.ts"}},"gitHead":"13d0068a71d6b6d560853e74e4ef7672eabd431f","scripts":{"lint":"echo 'lint not configured'","test":"vitest run --passWithNoTests","build":"tsc","clean":"rm -rf dist","typecheck":"tsc --noEmit","test:watch":"vitest --watch"},"_npmUser":{"name":"21native","email":"npm@21n.org"},"repository":{"url":"git+https://github.com/21nCo/super-functions.git","type":"git","directory":"packages/auth"},"_npmVersion":"10.8.2","description":"Framework-agnostic authentication abstraction layer for Superfunctions libraries","directories":{},"_nodeVersion":"20.20.2","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"vitest":"^3.2.4","typescript":"^5.6.0","@types/node":"^22.0.0"},"_npmOperationalInternal":{"tmp":"tmp/auth_0.1.2_1778737083950_0.537774278913004","host":"s3://npm-registry-packages-npm-production"}},"0.2.0":{"name":"@superfunctions/auth","version":"0.2.0","description":"Framework-agnostic authentication abstraction layer for Superfunctions libraries","type":"module","main":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"./types":{"types":"./dist/types.d.ts"}},"scripts":{"build":"tsc","test":"vitest run --passWithNoTests","test:watch":"vitest --watch","lint":"echo 'lint not configured'","typecheck":"tsc --noEmit","clean":"rm -rf dist"},"keywords":["auth","authentication","authorization","framework-agnostic","api-keys","superfunctions"],"author":{"name":"21n"},"license":"MIT","bugs":{"url":"https://github.com/21nCo/super-functions/issues"},"repository":{"type":"git","url":"git+https://github.com/21nCo/super-functions.git","directory":"packages/auth"},"publishConfig":{"access":"public"},"devDependencies":{"@types/node":"^22.0.0","typescript":"^5.6.0","vitest":"^3.2.4"},"_id":"@superfunctions/auth@0.2.0","gitHead":"e11bd81db6390dbc38303a5f3da6baadbaef0c8b","homepage":"https://github.com/21nCo/super-functions#readme","_nodeVersion":"20.20.2","_npmVersion":"10.8.2","dist":{"integrity":"sha512-e2Iz3Nf4IyiKr0dU0AgyGARzMchJbWW/sBYsjjdm9TW+EmFKAyYViJP0yXbgrHb9Xa3Ke2wzFMvRpX692u6jHA==","shasum":"130191e0b1c1d51bb6b7dff7a2e243cf52c51f3a","tarball":"https://registry.npmjs.org/@superfunctions/auth/-/auth-0.2.0.tgz","fileCount":14,"unpackedSize":36126,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIGW4G1CWL0ueNZOL3dp6t1oP8Ey9RWkoH0Pf+bt/vciyAiEA6Ewb+HpuKksKzvyFlsl6G9tLY4E31tw8gb4eVNnoQJQ="}]},"_npmUser":{"name":"21native","email":"npm@21n.org"},"directories":{},"maintainers":[{"name":"21native","email":"npm@21n.org"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/auth_0.2.0_1787980018598_0.023083005975074178"},"_hasShrinkwrap":false}},"time":{"created":"2025-12-28T14:07:50.410Z","modified":"2026-08-29T05:06:58.929Z","0.1.0":"2025-12-28T14:07:50.663Z","0.1.1":"2026-01-05T14:42:04.445Z","0.1.2":"2026-05-14T05:38:04.134Z","0.2.0":"2026-08-29T05:06:58.745Z"},"bugs":{"url":"https://github.com/21nCo/super-functions/issues"},"author":{"name":"21n"},"license":"MIT","homepage":"https://github.com/21nCo/super-functions#readme","keywords":["auth","authentication","authorization","framework-agnostic","api-keys","superfunctions"],"repository":{"type":"git","url":"git+https://github.com/21nCo/super-functions.git","directory":"packages/auth"},"description":"Framework-agnostic authentication abstraction layer for Superfunctions libraries","maintainers":[{"name":"21native","email":"npm@21n.org"}],"readme":"# @superfunctions/auth\n\nFramework-agnostic authentication abstraction layer for Superfunctions libraries.\n\n## Overview\n\n`@superfunctions/auth` provides a standardized interface for authentication that works across any HTTP framework. Libraries can accept any auth provider conforming to this abstraction, and auth library authors can build implementations that work everywhere.\n\n## Installation\n\n```bash\nnpm install @superfunctions/auth\n```\n\n## Core Concepts\n\n### AuthProvider Interface\n\nAll auth implementations must implement the `AuthProvider` interface:\n\n```typescript\ninterface AuthProvider<TSession extends AuthSession = AuthSession> {\n  authenticate(request: Request): Promise<TSession | null>;\n  authorize?(session: TSession, resourceId: string): Promise<boolean>;\n  revoke?(sessionId: string): Promise<void>;\n}\n```\n\n### AuthSession\n\nAuthentication results return an `AuthSession`:\n\n```typescript\ninterface AuthSession {\n  id: string;              // Unique identifier\n  type: string;            // Auth type: 'api-key', 'jwt', 'oauth', etc.\n  resourceIds: string[];   // Resources this session can access\n  scopes?: string[];       // Optional permissions\n  expiresAt?: Date;        // Optional expiration\n  metadata?: any;          // Optional additional data\n}\n```\n\n## Usage\n\n### For Library Authors\n\nAccept auth providers in your library:\n\n```typescript\nimport { createRouter } from '@superfunctions/http';\nimport { createAuthMiddleware, type AuthProvider } from '@superfunctions/auth';\n\nexport function createMyLibrary(config: {\n  auth?: AuthProvider;\n  // ... other config\n}) {\n  const middleware = config.auth \n    ? [createAuthMiddleware(config.auth)]\n    : [];\n\n  return createRouter({\n    middleware,\n    routes: [...]\n  });\n}\n```\n\n### For Auth Library Authors\n\nImplement the `AuthProvider` interface:\n\n```typescript\nimport type { AuthProvider, AuthSession } from '@superfunctions/auth';\n\nexport function createMyAuth(config: MyAuthConfig): AuthProvider {\n  return {\n    async authenticate(request: Request): Promise<AuthSession | null> {\n      const token = request.headers.get('authorization');\n      // Validate token and return session\n      return {\n        id: 'user_123',\n        type: 'jwt',\n        resourceIds: ['project_abc'],\n      };\n    },\n    \n    async authorize(session: AuthSession, resourceId: string): Promise<boolean> {\n      return session.resourceIds.includes(resourceId);\n    },\n  };\n}\n```\n\n### For Application Developers\n\nUse any conforming auth library:\n\n```typescript\nimport { createMyLibrary } from 'some-library';\nimport { createAuthFn } from 'authfn'; // or any other auth library\n\nconst auth = createAuthFn({\n  database: adapter,\n  // ... auth config\n});\n\nconst library = createMyLibrary({\n  auth: auth.provider,\n  // ... other config\n});\n```\n\n## Middleware Helpers\n\n### createAuthMiddleware\n\nCreates middleware for `@superfunctions/http` routers:\n\n```typescript\nimport { createAuthMiddleware } from '@superfunctions/auth';\n\nconst authMiddleware = createAuthMiddleware(authProvider, {\n  skipPaths: ['/health', '/public'],\n  contextKey: 'auth', // default\n});\n```\n\n### createResourceAuthMiddleware\n\nCreates middleware for resource-level authorization:\n\n```typescript\nimport { createResourceAuthMiddleware } from '@superfunctions/auth';\n\nconst resourceAuth = createResourceAuthMiddleware(authProvider, {\n  resourceHeader: 'x-project-id',\n  contextKey: 'auth',\n});\n```\n\n## Error Types\n\n- `AuthError` - Base error class\n- `AuthenticationError` - Authentication failed (401)\n- `AuthorizationError` - Access denied (403)\n- `InvalidCredentialsError` - Invalid credentials (401)\n- `ExpiredCredentialsError` - Credentials expired (401)\n\n## Examples\n\nSee the [authfn](../../authfn) library for a complete reference implementation.\n\n## License\n\nMIT\n","readmeFilename":"README.md"}