{"_id":"@affylabs/affyid-sdk","_rev":"2-c757f953ea371606b9054d47c44e8ca2","name":"@affylabs/affyid-sdk","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@affylabs/affyid-sdk","version":"1.0.0","keywords":["affyid","authentication","oauth","oidc","sdk","typescript"],"author":{"name":"AffyLabs"},"license":"MIT","_id":"@affylabs/affyid-sdk@1.0.0","maintainers":[{"name":"naokichau","email":"naokichau@gmail.com"}],"homepage":"https://github.com/affylabs/affyid#readme","bugs":{"url":"https://github.com/affylabs/affyid/issues"},"dist":{"shasum":"77aec9d710318af022778940e52750595f7a0808","tarball":"https://registry.npmjs.org/@affylabs/affyid-sdk/-/affyid-sdk-1.0.0.tgz","fileCount":257,"integrity":"sha512-djut7Kykajn7OHp1dEUnzHP6r6x0Qqs6ruDjS1CAFCXdPeE0SK5s+Ot9dzo784vzuHO+jAFYoua/Q8+TZH7+QQ==","signatures":[{"sig":"MEYCIQDbD8Ak5S0TznwLjt7bzFrSrxSGU/ot+TT7cgkUVYJWiAIhAPSsOzP1V8XIRKY5JeMVLqfnfC+uqTTsX/mtJR6kYMuK","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":221810},"main":"dist/index.js","types":"dist/index.d.ts","module":"dist/index.mjs","engines":{"node":">=18.0.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"gitHead":"07bd49b73a9be3b5337d18f2a281471f16fe7bd5","scripts":{"build":"tsc","clean":"rm -rf dist","prepare":"npm run build","generate":"npx openapi-typescript-codegen --input ../../api/openapi-sdk.yaml --output ./src/generated --client fetch --useOptions --useUnionTypes","prebuild":"npm run clean","typecheck":"tsc --noEmit"},"_npmUser":{"name":"naokichau","email":"naokichau@gmail.com"},"repository":{"url":"git+https://github.com/affylabs/affyid.git","type":"git","directory":"sdks/typescript"},"_npmVersion":"10.8.2","description":"TypeScript SDK for AffyID authentication service","directories":{},"_nodeVersion":"20.19.2","_hasShrinkwrap":false,"devDependencies":{"ts-node":"^10.9.0","typescript":"^5.4.0","openapi-typescript-codegen":"^0.29.0"},"_npmOperationalInternal":{"tmp":"tmp/affyid-sdk_1.0.0_1769316631825_0.23760029319635723","host":"s3://npm-registry-packages-npm-production"}}},"time":{"created":"2026-01-25T04:50:31.717Z","modified":"2026-02-16T17:36:26.472Z","1.0.0":"2026-01-25T04:50:31.979Z"},"bugs":{"url":"https://github.com/affylabs/affyid/issues"},"author":{"name":"AffyLabs"},"license":"MIT","homepage":"https://github.com/affylabs/affyid#readme","keywords":["affyid","authentication","oauth","oidc","sdk","typescript"],"repository":{"url":"git+https://github.com/affylabs/affyid.git","type":"git","directory":"sdks/typescript"},"description":"TypeScript SDK for AffyID authentication service","maintainers":[{"email":"naokichau@gmail.com","name":"naokichau"},{"email":"lam@affylabs.com","name":"lam_affylabs"}],"readme":"# @affylabs/affyid-sdk\n\nTypeScript SDK for [AffyID](https://github.com/affylabs/affyid) authentication service.\n\n## Installation\n\n```bash\nnpm install @affylabs/affyid-sdk\n# or\nyarn add @affylabs/affyid-sdk\n# or\npnpm add @affylabs/affyid-sdk\n```\n\n## Quick Start\n\n```typescript\nimport { AffyIDClient } from '@affylabs/affyid-sdk';\n\nconst client = new AffyIDClient({\n  baseUrl: 'https://auth.yourdomain.com',\n});\n\n// Register a new user\nconst tokens = await client.auth.registerUser({\n  requestBody: {\n    email: 'user@example.com',\n    password: 'SecurePass123!',\n    first_name: 'John',\n    last_name: 'Doe',\n  },\n});\n\n// Set token for authenticated requests\nclient.setToken(tokens.access_token!);\n\n// Get user profile\nconst user = await client.users.getCurrentUser();\nconsole.log(user);\n```\n\n## Authentication\n\n### Login\n\n```typescript\nconst tokens = await client.auth.loginUser({\n  requestBody: {\n    email: 'user@example.com',\n    password: 'SecurePass123!',\n  },\n});\n\nclient.setToken(tokens.access_token!);\n```\n\n### Token Refresh\n\n```typescript\nconst newTokens = await client.auth.refreshToken({\n  requestBody: {\n    refresh_token: tokens.refresh_token!,\n  },\n});\n\nclient.setToken(newTokens.access_token!);\n```\n\n### Logout\n\n```typescript\nawait client.auth.logoutUser({\n  requestBody: {\n    refresh_token: tokens.refresh_token!,\n  },\n});\n\nclient.clearToken();\n```\n\n## Two-Factor Authentication\n\n### Setup TOTP\n\n```typescript\n// Get setup info (QR code, secret)\nconst setup = await client.auth.setup2Fa();\nconsole.log(setup.qr_code); // Data URL for QR code\nconsole.log(setup.secret);  // Manual entry secret\n\n// Confirm with code from authenticator app\nawait client.auth.confirm2Fa({\n  requestBody: {\n    code: '123456',\n  },\n});\n```\n\n### Login with 2FA\n\n```typescript\n// Initial login returns requires_2fa: true\nconst loginResult = await client.auth.loginUser({\n  requestBody: {\n    email: 'user@example.com',\n    password: 'SecurePass123!',\n  },\n});\n\nif (loginResult.requires_2fa) {\n  // Complete with 2FA code\n  const tokens = await client.auth.login2Fa({\n    requestBody: {\n      temp_token: loginResult.temp_token!,\n      code: '123456',\n    },\n  });\n  client.setToken(tokens.access_token!);\n}\n```\n\n## Passkeys (WebAuthn)\n\n### Register a Passkey\n\n```typescript\n// Begin registration (returns WebAuthn options)\nconst options = await client.users.beginPasskeyRegistration();\n\n// Use browser WebAuthn API\nconst credential = await navigator.credentials.create({\n  publicKey: options,\n});\n\n// Finish registration\nawait client.users.finishPasskeyRegistration({\n  requestBody: {\n    credential: credential,\n  },\n});\n```\n\n### Login with Passkey\n\n```typescript\n// Begin login\nconst options = await client.auth.beginPasskeyLogin({\n  requestBody: {\n    email: 'user@example.com', // Optional\n  },\n});\n\n// Use browser WebAuthn API\nconst assertion = await navigator.credentials.get({\n  publicKey: options,\n});\n\n// Finish login\nconst tokens = await client.auth.finishPasskeyLogin({\n  requestBody: {\n    credential: assertion,\n  },\n});\n\nclient.setToken(tokens.access_token!);\n```\n\n## API Reference\n\n### Client Options\n\n| Option | Type | Default | Description |\n|--------|------|---------|-------------|\n| `baseUrl` | `string` | `'http://localhost:8080'` | AffyID server URL |\n| `token` | `string` | - | JWT access token |\n| `withCredentials` | `boolean` | `false` | Include cookies |\n| `headers` | `Record<string, string>` | - | Custom headers |\n\n### Services\n\n- `client.auth` - Authentication (login, register, 2FA, passkeys)\n- `client.users` - User profile and passkey management\n- `client.oauth` - OAuth 2.0 endpoints\n- `client.oidc` - OpenID Connect endpoints\n- `client.health` - Health check endpoints\n\n## License\n\nMIT\n","readmeFilename":"README.md"}