pbx-sdk
v1.0.0
Published
PBX SDK for authentication and API integration
Maintainers
Readme
PBX SDK
A lightweight and scalable SDK for integrating with PBX APIs. Built with TypeScript, Axios, and production-ready patterns.
Installation
npm install pbx-sdkSetup
import { PBXSDK } from "pbx-sdk";
const sdk = new PBXSDK({
baseURL: "http://your-api.com/api",
});Authentication
Login
await sdk.auth.login({
email: "[email protected]",
password: "123456",
});Auto Token Refresh
- Automatically refreshes token on
401 - Queues failed requests
- Retries requests after refresh
No manual handling required
Events
sdk.on("onLogin", (user) => {
console.log("User logged in", user);
});
sdk.on("onLogout", () => {
console.log("User logged out");
});Error Handling
try {
await sdk.auth.login({...});
} catch (err) {
console.log(err.message);
console.log(err.statusCode);
console.log(err.errors);
}📬 API Response Format
Expected (Laravel style)
{
"status": true,
"message": "Success",
"data": {}
}Project Structure
src/
├── core/
├── modules/
├── types/
├── utils/
├── index.tsDevelopment
Run example
npm run startBuild SDK
npm run buildRun Tests
npm testFeatures
- Modular architecture
- Token management
- Auto refresh with queue
- Retry failed requests
- Event system
- Centralized error handling
Roadmap
- [ ] WebSocket support
- [ ] Call module
- [ ] Plugin system
- [ ] LocalStorage token persistence
License
MIT
