{"_id":"@accountsystem/auth-node-sdk","name":"@accountsystem/auth-node-sdk","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@accountsystem/auth-node-sdk","version":"1.0.0","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"npm run clean && npm run build:types && npm run build:js","build:types":"tsc --emitDeclarationOnly","build:js":"esbuild src/index.ts --bundle --platform=node --target=node18 --format=cjs --outfile=dist/index.js --external:express --external:socket.io-client --external:axios --external:https --external:fs --external:path --external:crypto --external:url","dev":"npm run build -- --watch","clean":"node -e \"const fs = require('fs'); if (fs.existsSync('dist')) fs.rmSync('dist', { recursive: true });\"","prepublishOnly":"npm run build","test":"echo \"Tests not implemented yet\" && exit 0","link":"npm run build && npm link"},"repository":{"type":"git","url":"git+https://github.com/0-kodiya-0/AccountSystem.git","directory":"packages/sdk/auth-node-sdk"},"keywords":["auth","authentication","microservice","sdk","express","middleware","node","typescript","oauth","jwt","session"],"bugs":{"url":"https://github.com/0-kodiya-0/AccountSystem/issues"},"homepage":"https://github.com/0-kodiya-0/AccountSystem#readme","author":{"name":"0-kodiya-0"},"license":"MIT","description":"Node.js SDK for AccountSystem authentication microservice. This SDK provides Express middleware and utilities to integrate with the AccountSystem authentication service, supporting both local authentication and OAuth (Google, Microsoft, Facebook) with adv","devDependencies":{"@types/express":"^5.0.2","@types/node":"^22.15.29","esbuild":"0.25.5","typescript":"^5.8.3"},"dependencies":{"axios":"^1.9.0","socket.io-client":"^4.8.1"},"peerDependencies":{"express":"^5.1.0"},"engines":{"node":">=18.0.0"},"publishConfig":{"access":"public"},"_id":"@accountsystem/auth-node-sdk@1.0.0","gitHead":"bb7798923b880df7f3fb6ee66534b5023789053c","_nodeVersion":"23.9.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-UQdbygwoYxmlURLK1RL6cE+SORrxP7D0OdQpY5QE+f25XKe4J/xw+lCHiQguPwnAEKY8crEggJu7jtS5C2FoJA==","shasum":"574d66afebd86a71de03474e9f09fc38712c20c5","tarball":"https://registry.npmjs.org/@accountsystem/auth-node-sdk/-/auth-node-sdk-1.0.0.tgz","fileCount":17,"unpackedSize":59137,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDVF5Xv34AiLpQiaJOxqKsGcukl2yJzvKLq53A9sZ7f5gIhALGOgpZALW1m7gnusvGXkI/3a0K75vvOcjKuvgdXHu3o"}]},"_npmUser":{"name":"0-kodiya-0","email":"sanithujayafiverr@gmail.com"},"directories":{},"maintainers":[{"name":"0-kodiya-0","email":"sanithujayafiverr@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/auth-node-sdk_1.0.0_1749016512884_0.3237101842205805"},"_hasShrinkwrap":false}},"time":{"created":"2025-06-04T05:55:12.804Z","1.0.0":"2025-06-04T05:55:13.089Z","modified":"2025-06-04T05:55:13.349Z"},"maintainers":[{"name":"0-kodiya-0","email":"sanithujayafiverr@gmail.com"}],"description":"Node.js SDK for AccountSystem authentication microservice. This SDK provides Express middleware and utilities to integrate with the AccountSystem authentication service, supporting both local authentication and OAuth (Google, Microsoft, Facebook) with adv","homepage":"https://github.com/0-kodiya-0/AccountSystem#readme","keywords":["auth","authentication","microservice","sdk","express","middleware","node","typescript","oauth","jwt","session"],"repository":{"type":"git","url":"git+https://github.com/0-kodiya-0/AccountSystem.git","directory":"packages/sdk/auth-node-sdk"},"author":{"name":"0-kodiya-0"},"bugs":{"url":"https://github.com/0-kodiya-0/AccountSystem/issues"},"license":"MIT","readme":"# Auth Node SDK\r\n\r\nNode.js SDK for AccountSystem authentication microservice. This SDK provides Express middleware and utilities to integrate with the AccountSystem authentication service, supporting both local authentication and OAuth (Google, Microsoft, Facebook) with advanced features like 2FA, session management, and real-time notifications.\r\n\r\n## Features\r\n\r\n- 🔐 **Session Validation**: Middleware for validating user sessions\r\n- 🎯 **Account Type Enforcement**: Require specific account types (Local/OAuth)\r\n- 🔑 **Google API Integration**: Validate Google OAuth scopes and permissions\r\n- 🔄 **Automatic Token Refresh**: Handle token expiration gracefully\r\n- 📡 **Real-time Notifications**: WebSocket client for live updates\r\n- 🛡️ **Secure Communication**: mTLS authentication with the auth service\r\n- 📝 **TypeScript Support**: Full type definitions included\r\n- ⚡ **Express Middleware**: Easy integration with Express.js applications\r\n\r\n## Installation\r\n\r\n```bash\r\nnpm install @accountsystem/auth-node-sdk\r\n```\r\n\r\n## Quick Start\r\n\r\n### 1. Configure the SDK\r\n\r\n```javascript\r\nimport { AuthSDK } from '@accountsystem/auth-node-sdk';\r\n\r\n// Configure the SDK with your service credentials\r\nAuthSDK.configure({\r\n  authServiceUrl: 'https://your-auth-service.com',\r\n  serviceName: 'your-service-name',\r\n  serviceSecret: 'your-service-secret',\r\n  certificates: {\r\n    key: '/path/to/your/client.key',\r\n    cert: '/path/to/your/client.crt',\r\n    ca: '/path/to/ca.crt'\r\n  },\r\n  requestTimeout: 10000 // optional, defaults to 10 seconds\r\n});\r\n```\r\n\r\n### 2. Use Authentication Middleware\r\n\r\n```javascript\r\nimport express from 'express';\r\nimport { AuthSDK } from '@accountsystem/auth-node-sdk';\r\n\r\nconst app = express();\r\n\r\n// Validate session for protected routes\r\napp.use('/:accountId/protected', AuthSDK.validateSession());\r\n\r\n// Require specific account type\r\napp.use('/:accountId/oauth-only', \r\n  AuthSDK.validateSession(),\r\n  AuthSDK.requireAccountType('oauth')\r\n);\r\n\r\n// Require Google API scopes\r\napp.use('/:accountId/gmail', \r\n  AuthSDK.validateSession(),\r\n  AuthSDK.requireGoogleScope('gmail.readonly')\r\n);\r\n\r\n// Multiple scopes\r\napp.use('/:accountId/calendar-gmail', \r\n  AuthSDK.validateSession(),\r\n  AuthSDK.requireGoogleScopes(['gmail.readonly', 'calendar.events'])\r\n);\r\n\r\n// Your protected route\r\napp.get('/:accountId/protected/data', (req, res) => {\r\n  // req.account contains the authenticated user's account information\r\n  res.json({\r\n    message: 'Hello authenticated user!',\r\n    account: req.account\r\n  });\r\n});\r\n```\r\n\r\n### 3. Use the Client Directly\r\n\r\n```javascript\r\nimport { AuthSDK } from '@accountsystem/auth-node-sdk';\r\n\r\nconst authClient = AuthSDK.getInstance().getAuthClient;\r\n\r\n// Get user information\r\ntry {\r\n  const userInfo = await authClient.getUserInfo('account-id-123');\r\n  console.log('User:', userInfo.account.userDetails.name);\r\n} catch (error) {\r\n  console.error('Failed to get user info:', error.message);\r\n}\r\n\r\n// Search user by email\r\nconst user = await authClient.searchUserByEmail('user@example.com');\r\n\r\n// Validate session\r\nconst session = await authClient.validateSession('account-id', 'access-token');\r\n\r\n// Get user's Google scopes\r\nconst scopes = await authClient.getUserScopes('account-id');\r\n```\r\n\r\n### 4. Real-time Notifications\r\n\r\n```javascript\r\nimport { AuthSDK } from '@accountsystem/auth-node-sdk';\r\n\r\nconst socketClient = AuthSDK.getInstance().getSocketClient;\r\n\r\n// Connect to notification service\r\nawait socketClient.connect();\r\n\r\n// Subscribe to account notifications\r\nawait socketClient.subscribeToAccount('account-id-123');\r\n\r\n// Listen for notifications\r\nsocketClient.onNotification('notification:new', (data) => {\r\n  console.log('New notification:', data);\r\n});\r\n\r\nsocketClient.onNotification('notification:updated', (data) => {\r\n  console.log('Notification updated:', data);\r\n});\r\n```\r\n\r\n## Configuration Options\r\n\r\n### Required Configuration\r\n\r\n```javascript\r\n{\r\n  authServiceUrl: 'https://your-auth-service.com',  // Your AccountSystem service URL\r\n  serviceName: 'your-service-name',                 // Internal service identifier\r\n  serviceSecret: 'your-service-secret',             // Service authentication secret\r\n  certificates: {\r\n    key: '/path/to/client.key',                     // Client private key for mTLS\r\n    cert: '/path/to/client.crt',                    // Client certificate for mTLS  \r\n    ca: '/path/to/ca.crt'                          // CA certificate for verification\r\n  }\r\n}\r\n```\r\n\r\n### Optional Configuration\r\n\r\n```javascript\r\n{\r\n  requestTimeout: 10000  // Request timeout in milliseconds (default: 10000)\r\n}\r\n```\r\n\r\n## Security\r\n\r\nThis SDK uses **mutual TLS (mTLS)** for secure communication with the AccountSystem service. The authentication flow includes:\r\n\r\n1. **Client Certificate Validation** - Your service must present a valid client certificate signed by the same CA as the auth service\r\n2. **Service Header Authentication** - The SDK automatically sends service identification headers\r\n3. **Request Signing** - All requests are authenticated using your service credentials\r\n\r\nEnsure your certificates are properly configured and secured. No additional configuration is needed on the auth service side.\r\n\r\n## Error Handling\r\n\r\nThe SDK throws errors with descriptive messages. Wrap your calls in try-catch blocks:\r\n\r\n```javascript\r\ntry {\r\n  const user = await authClient.getUserInfo(accountId);\r\n} catch (error) {\r\n  console.error('Auth error:', error.message);\r\n  // Handle the error appropriately\r\n}\r\n```\r\n\r\n## TypeScript Support\r\n\r\nThis SDK is written in TypeScript and provides full type definitions. All types are exported:\r\n\r\n```typescript\r\nimport { SafeAccount, AccountType, AuthSDKConfig } from '@accountsystem/auth-node-sdk';\r\n```\r\n\r\n## License\r\n\r\nMIT License - see LICENSE file for details.","readmeFilename":"README.md","_rev":"1-b44201b0fb470164396de157d2170ffd"}