Skip to content

paanj-cloud/admin-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@paanj/admin

Core admin SDK for Paanj platform - provides authentication and connection management

npm version License Node.js

⚠️ Server-Side Only

This SDK is designed exclusively for server-side use. It requires a secret API key and should never be exposed to client-side code or browsers.

Overview

@paanj/admin is the core package that provides:

  • 🔐 Authentication - Secret key-based authentication
  • 🔌 Connection Management - WebSocket and HTTP client infrastructure
  • 🔄 Auto-Reconnection - Built-in reconnection with exponential backoff
  • 🎯 Base for Feature Packages - Foundation for @paanj/chat-admin, @paanj/voice-admin, etc.

Installation

npm install @paanj/admin

Requirements:

  • Node.js 18.0.0 or higher
  • Server-side environment only

Usage

Standalone Usage

import { PaanjAdmin } from '@paanj/admin';

const admin = new PaanjAdmin('sk_live_your_secret_key', {
  apiUrl: 'http://localhost:3000',
  wsUrl: 'ws://localhost:8090'
});

// Connect to WebSocket
await admin.connect();

// Check connection status
console.log(admin.isConnected()); // true

// Disconnect
admin.disconnect();

With Feature Packages

The core package is typically used with feature packages:

import { PaanjAdmin } from '@paanj/admin';
import { AdminChat } from '@paanj/chat-admin';

const admin = new PaanjAdmin('sk_live_your_secret_key');
await admin.connect();

// Initialize chat features
const chat = new AdminChat(admin);
chat.messages.onCreate((msg) => {
  console.log('New message:', msg);
});

API Reference

PaanjAdmin

Constructor

new PaanjAdmin(secretKey: string, options?: AdminOptions)

Options:

  • apiUrl?: string - API server URL (default: http://localhost:3000)
  • wsUrl?: string - WebSocket server URL (default: ws://localhost:8090)
  • autoReconnect?: boolean - Enable auto-reconnection (default: true)
  • reconnectInterval?: number - Reconnect interval in ms (default: 5000)
  • maxReconnectAttempts?: number - Max reconnect attempts (default: 10)

Methods

connect(): Promise<void>
Connect to the WebSocket server.

disconnect(): void
Disconnect from the WebSocket server.

isConnected(): boolean
Check if connected to WebSocket.

Configuration

const admin = new PaanjAdmin(secretKey, {
  apiUrl: 'https://api.paanj.com',
  wsUrl: 'wss://ws.paanj.com',
  autoReconnect: true,
  reconnectInterval: 5000,
  maxReconnectAttempts: 10
});

Security Best Practices

  1. Never expose secret keys - Store them in environment variables or secure vaults
  2. Server-side only - This SDK includes runtime checks to prevent browser usage
  3. Rotate keys regularly - Implement key rotation policies
  4. Monitor usage - Track API key usage for suspicious activity
  5. Use HTTPS/WSS - Always use secure connections in production

Feature Packages

Build on top of @paanj/admin with feature packages:

  • @paanj/chat-admin - Chat management and monitoring
  • @paanj/voice-admin - Voice call management (coming soon)
  • @paanj/video-admin - Video call management (coming soon)
  • @paanj/storage-admin - File storage management (coming soon)

TypeScript Support

This SDK is written in TypeScript and provides complete type definitions:

import { PaanjAdmin, AdminOptions } from '@paanj/admin';

const options: AdminOptions = {
  apiUrl: 'https://api.paanj.com',
  autoReconnect: true
};

const admin = new PaanjAdmin(secretKey, options);

Error Handling

try {
  await admin.connect();
} catch (error) {
  console.error('Connection failed:', error.message);
}

Development

# Install dependencies
npm install

# Build the package
npm run build

# Watch mode for development
npm run watch

License

This project is licensed under a custom license. See the LICENSE file for details.

Support


Made with ❤️ by the Paanj team

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published