{"_id":"@blackmission/centralauth-sdk","_rev":"2-a606ffddd7107a12160fc944e10331d1","name":"@blackmission/centralauth-sdk","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@blackmission/centralauth-sdk","version":"1.0.0","keywords":["oauth","auth","centralauth","blackmission"],"license":"MIT","_id":"@blackmission/centralauth-sdk@1.0.0","maintainers":[{"name":"bluebeard63","email":"jack@morrison.ec"}],"homepage":"https://github.com/BlackMission/centralauth#readme","bugs":{"url":"https://github.com/BlackMission/centralauth/issues"},"dist":{"shasum":"f78aaaf7a1ee0dcfa51620b2083b573990a2f68c","tarball":"https://registry.npmjs.org/@blackmission/centralauth-sdk/-/centralauth-sdk-1.0.0.tgz","fileCount":2,"integrity":"sha512-lVtwbUIsuqeZWejOzF/WgGIveOCcQTGa8VkOuE9fwvLVoCqPzO1FrxhcM4SkG2o7iNhjVlrvs3jEcgJzOLssdQ==","signatures":[{"sig":"MEUCIQCSFp8EpQDu/EZLyWqzu/ucLy29fp9MYp7FVhip1KQ8qQIgI8gALfab4vAhWZEKnDxiTUHPtU0CSVg6xlP/D77D5jI=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":4207},"main":"./dist/cjs/index.js","types":"./dist/esm/index.d.ts","module":"./dist/esm/index.js","engines":{"node":">=18.0.0"},"exports":{".":{"types":"./dist/esm/index.d.ts","import":"./dist/esm/index.js","require":"./dist/cjs/index.js"}},"scripts":{"test":"vitest run","build":"tsc -p tsconfig.build.json && tsc -p tsconfig.build.json --module commonjs --outDir dist/cjs","clean":"rm -rf dist","test:watch":"vitest"},"_npmUser":{"name":"bluebeard63","email":"jack@morrison.ec"},"repository":{"url":"git+https://github.com/BlackMission/centralauth.git","type":"git"},"_npmVersion":"11.9.0","description":"TypeScript SDK for BlackMission CentralAuth OAuth broker service","directories":{},"_nodeVersion":"24.11.1","_hasShrinkwrap":false,"devDependencies":{"vitest":"^2.0.0","typescript":"^5.4.0","@types/node":"^20.0.0"},"_npmOperationalInternal":{"tmp":"tmp/centralauth-sdk_1.0.0_1770416604547_0.09306175839907649","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@blackmission/centralauth-sdk","version":"1.0.1","description":"TypeScript SDK for BlackMission CentralAuth OAuth broker service","main":"./dist/cjs/index.js","module":"./dist/esm/index.js","types":"./dist/esm/index.d.ts","exports":{".":{"import":"./dist/esm/index.js","require":"./dist/cjs/index.js","types":"./dist/esm/index.d.ts"}},"scripts":{"build":"tsc -p tsconfig.build.json && tsc -p tsconfig.build.json --module commonjs --outDir dist/cjs","test":"vitest run","test:watch":"vitest","clean":"rm -rf dist"},"devDependencies":{"typescript":"^5.4.0","vitest":"^2.0.0","@types/node":"^20.0.0"},"engines":{"node":">=18.0.0"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/BlackMission/centralauth.git"},"keywords":["oauth","auth","centralauth","blackmission"],"gitHead":"54f6ad53351e87749f3394c4cfbd4a022b79789d","_id":"@blackmission/centralauth-sdk@1.0.1","bugs":{"url":"https://github.com/BlackMission/centralauth/issues"},"homepage":"https://github.com/BlackMission/centralauth#readme","_nodeVersion":"24.11.1","_npmVersion":"11.9.0","dist":{"integrity":"sha512-e2QWyya5PMuLkKh43BQwodTts8c/2Tn0ekwwMpjvCEqH9k+bzF81fs8IJfjawlQtJ5ZjDYypAItz8zHBwS6poA==","shasum":"7ddeff3af8570bf3df32a2d69b6d0e180ef162c1","tarball":"https://registry.npmjs.org/@blackmission/centralauth-sdk/-/centralauth-sdk-1.0.1.tgz","fileCount":50,"unpackedSize":44457,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQD35/a5PlXCTko4IRiIy+nwJHtlOQpEa15EnK18ncNfawIhAJOoKMG3Ane0oiRAOAXrK8Uc/YW6tCZnX2v/Jnzbe0+t"}]},"_npmUser":{"name":"bluebeard63","email":"jack@morrison.ec"},"directories":{},"maintainers":[{"name":"bluebeard63","email":"jack@morrison.ec"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/centralauth-sdk_1.0.1_1770467216497_0.5041110214867222"},"_hasShrinkwrap":false}},"time":{"created":"2026-02-06T22:23:24.473Z","modified":"2026-02-07T12:26:56.787Z","1.0.0":"2026-02-06T22:23:24.696Z","1.0.1":"2026-02-07T12:26:56.638Z"},"bugs":{"url":"https://github.com/BlackMission/centralauth/issues"},"license":"MIT","homepage":"https://github.com/BlackMission/centralauth#readme","keywords":["oauth","auth","centralauth","blackmission"],"repository":{"type":"git","url":"git+https://github.com/BlackMission/centralauth.git"},"description":"TypeScript SDK for BlackMission CentralAuth OAuth broker service","maintainers":[{"name":"bluebeard63","email":"jack@morrison.ec"}],"readme":"# @blackmission/centralauth-sdk\n\nTypeScript SDK for the BlackMission CentralAuth OAuth broker service.\n\n## Installation\n\n```bash\nnpm install @blackmission/centralauth-sdk\n```\n\n**Requirements:** Node.js 18+ (uses native `fetch`)\n\n## Quick Start\n\n```typescript\nimport { CentralAuthClient } from '@blackmission/centralauth-sdk';\n\nconst auth = new CentralAuthClient({\n  baseURL: 'https://auth.blackmission.com',\n  clientID: 'website',\n  apiKey: process.env.CENTRALAUTH_API_KEY!,\n});\n\n// 1. Generate authorize URL (redirect user's browser here)\nconst url = auth.getAuthorizeURL('discord', 'https://mysite.com/auth/callback');\n\n// 2. Exchange code for user info (server-to-server)\nconst user = await auth.exchange(code);\n// → { provider, provider_id, username, display_name, avatar_url, email? }\n\n// 3. List available providers\nconst providers = await auth.getProviders();\n// → [\"discord\", \"steam\"]\n\n// 4. Health check\nconst healthy = await auth.healthCheck();\n// → true\n```\n\n## Express Middleware\n\n```typescript\nimport { CentralAuthClient, createCallbackHandler } from '@blackmission/centralauth-sdk';\n\nconst auth = new CentralAuthClient({ ... });\n\napp.get('/auth/callback', createCallbackHandler(auth, {\n  onSuccess: (user, req, res) => {\n    req.session.user = user;\n    res.redirect('/');\n  },\n  onError: (error, req, res) => {\n    res.status(401).send('Authentication failed');\n  },\n}));\n```\n\n## Error Handling\n\n```typescript\nimport {\n  ExchangeExpiredError,\n  UnauthorizedError,\n  ForbiddenError,\n  ProviderError,\n  CentralAuthError,\n} from '@blackmission/centralauth-sdk';\n\ntry {\n  const user = await auth.exchange(code);\n} catch (err) {\n  if (err instanceof ExchangeExpiredError) {\n    // Code expired (30-second window)\n  } else if (err instanceof UnauthorizedError) {\n    // Invalid API key\n  } else if (err instanceof ForbiddenError) {\n    // API key doesn't match the client that initiated the flow\n  } else if (err instanceof ProviderError) {\n    // Provider (Discord/Steam) returned an error\n  } else if (err instanceof CentralAuthError) {\n    // Network error, timeout, or other failure\n  }\n}\n```\n\n## API Reference\n\n### `new CentralAuthClient(config)`\n\n| Property | Type | Required | Description |\n|----------|------|----------|-------------|\n| `baseURL` | `string` | Yes | CentralAuth server URL |\n| `clientID` | `string` | Yes | Registered client ID |\n| `apiKey` | `string` | Yes | API key for `/exchange` calls |\n| `timeout` | `number` | No | Request timeout in ms (default: 5000) |\n\n### `client.getAuthorizeURL(provider, redirectURI)`\n\nReturns the full URL to redirect the user's browser to for authentication. No network call.\n\n### `client.exchange(code)`\n\nExchanges an authorization code for user info. Returns a `UserInfo` object.\n\n### `client.getProviders()`\n\nReturns an array of available provider names (e.g., `[\"discord\", \"steam\"]`).\n\n### `client.healthCheck()`\n\nReturns `true` if the server is healthy, `false` otherwise. Never throws.\n\n### `createCallbackHandler(client, options)`\n\nCreates an Express-compatible route handler for the OAuth callback.\n\n### `createGenericHandler(client)`\n\nCreates a framework-agnostic handler function `(code: string) => Promise<UserInfo>`.\n","readmeFilename":"README.md"}