sc-datatem
v0.0.8
Published
A TypeScript library for data template operations
Maintainers
Readme
sc-datatem
A TypeScript library for integrating with the Datatem API, providing easy access to SIM card management and M2M/IoT connectivity services.
🚀 Installation
npm install sc-datatem✨ Features
- ✅ JWT Authentication - Automatic login and token management
- ✅ SIM Card Management - List and query SIM card details
- ✅ Automatic Token Handling - Axios interceptors for seamless authentication
- ✅ Error Handling - Comprehensive API error management
- ✅ TypeScript Support - Full type definitions and IntelliSense
- ✅ Production Ready - Tested with real Datatem API credentials
📚 Quick Start
Basic Usage
import { ScDatatem } from "sc-datatem";
async function main() {
try {
// Create and authenticate in one step
const datatem = await ScDatatem.create({
email: "[email protected]",
password: "your-password",
});
// Get all SIM cards
const simCards = await datatem.getSimCards();
console.log(`Found ${simCards.length} SIM cards`);
// Filter active SIM cards
const activeCards = simCards.filter((sim) => sim.status === "ACTIVE");
console.log(`Active cards: ${activeCards.length}`);
// Check authentication status
console.log(`Authenticated: ${datatem.isAuthenticated()}`);
// Logout when done
datatem.logout();
} catch (error) {
console.error("Error:", error.message);
}
}
main();Manual Instantiation
import { ScDatatem } from "sc-datatem";
const datatem = new ScDatatem({
email: "[email protected]",
password: "your-password",
});
// Authentication is handled automatically in the constructor
const simCards = await datatem.getSimCards();🔧 Development with npm link
To use this library locally in another project:
# In this library directory
npm run build
npm link
# In your project directory
npm link sc-datatemThen import normally:
import { ScDatatem } from "sc-datatem";Any changes you make to this library will be reflected in your project after running npm run build.
📖 API Reference
ScDatatem Class
ScDatatem.create(loginData: LoginData): Promise<ScDatatem>
Static factory method that creates and authenticates an instance in one step.
new ScDatatem(loginData: LoginData)
Constructor that creates an instance and handles authentication automatically.
getSimCards(): Promise<SimCard[]>
Retrieves all SIM cards associated with the authenticated account.
isAuthenticated(): boolean
Returns whether the instance has a valid authentication token.
logout(): void
Clears the authentication token.
Types
type LoginData = {
email: string;
password: string;
};
type SimCardStatus = "ACTIVE" | "INACTIVE";
type SimCard = {
phoneNumber: string;
status: SimCardStatus;
operator: string;
connected: boolean;
device: string;
iccid: string;
monthUsedData: number;
monthUsedDataPct: number;
// ... additional fields
};
type User = {
id: string;
name: string;
email: string;
document: string;
role: string;
};🛠️ Development
Scripts
npm run build # Build the library
npm run dev # Build in watch mode
npm run test # Run tests
npm run lint # Lint code
npm run format # Format codeTesting
Set up your environment variables:
[email protected]
DATATEM_PASSWORD=your-passwordRun tests:
npm test📄 License
MIT
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
