standard-education-client
v0.0.15
Published
Standard Education HTTP client - Private API client for education management
Maintainers
Readme
Standard Education Client
A TypeScript/JavaScript client library for the Standard Education API.
Installation
From GitHub Packages (Private)
npm install @smtanbin/standard-education-clientOr with yarn:
yarn add @smtanbin/standard-education-clientUsage
Basic Setup
import Api from '@tanbibn/standard-education-client';
// Initialize the API client with your base URL
const api = new Api('https://your-domain.com');
// Or with custom API prefix and version
const api = new Api('https://your-domain.com', '/api/v', '1');Authentication
// Login with username and password
const loginResponse = await api.auth.login('username', 'password');
console.log('Logged in:', loginResponse);
// The client automatically stores and manages access/refresh tokens
// All subsequent API calls will include the Bearer token automatically
// Logout
await api.auth.logout();Users
// Get current user
const currentUser = await api.users.getCurrentUser();
console.log('Current user:', currentUser.data);
// Get user by ID
const user = await api.users.getUserByID('user-id-123');
console.log('User:', user.data);
// Add a new user
const newUser = await api.users.addUser({
username: 'johndoe',
email: '[email protected]',
first_name: 'John',
last_name: 'Doe',
phone: '+1234567890',
instituted_id: 'inst-123'
});
// Update user
const updated = await api.users.updateUser('user-id-123', {
email: '[email protected]',
phone: '+9876543210'
});Institutions
// Get all institutions
const institutions = await api.institutions.GetAllInstitutions();
console.log('Institutions:', institutions.data);
// Get dashboard data for an institution
const dashboard = await api.institutions.GetDashboardData('inst-123');
console.log('Dashboard:', dashboard.data);
// Get institution by ID
const institution = await api.institutions.GetInstitutionByID('inst-123');
// Add new institution
const newInst = await api.institutions.AddInstitution(
'customer-123',
'School Name',
'John Doe',
'New York, NY',
'+1234567890',
'[email protected]',
'https://school.com',
'2020-01-01',
'ACC123',
'token123',
'logo-url',
'2024-01-01',
'Notes here',
'file-123'
);
// Close institution
await api.institutions.CloseInstitution('inst-123');Features
- ✅ Automatic Token Management: Access and refresh tokens are automatically stored and managed
- ✅ Auto Token Refresh: On 401 errors, the client automatically attempts to refresh the access token
- ✅ TypeScript Support: Full TypeScript definitions included
- ✅ Browser & Node.js: Works in both environments with smart storage (cookieStore > localStorage > memory)
- ✅ Multiple Build Formats: CommonJS, ESM, and UMD builds available
API Structure
The API client follows the backend route structure:
- Base URL:
{domain}/api/v1/ - Authentication endpoints:
/auth/* - User endpoints:
/users/* - Institution endpoints:
/institutions/*
Authentication Flow
- Login: Call
api.auth.login(username, password)- uses Basic auth - Auto Bearer Token: All subsequent requests automatically include
Bearer {access_token}header - Auto Refresh: On 401 response, the client automatically calls
/auth/refresh/:useridwith the refresh token - Logout: Call
api.auth.logout()to clear tokens and notify the backend
Error Handling
try {
const user = await api.users.getCurrentUser();
console.log(user.data);
} catch (error) {
if (error.response?.status === 401) {
console.error('Authentication failed');
} else {
console.error('Error:', error.message);
}
}Development
# Install dependencies
npm install
# Build the library
npm run build
# Run tests
npm test
# Watch mode for development
npm run devLicense
UNLICENSED - Private use only
