TypeScript

TypeScript SDK

Official TypeScript SDK for Fluxum API

WebSocket-based
End-to-end encryption
Type-safe
TypeScript 4.5+

Quick Start

Get up and running with the Fluxum TypeScript SDK in minutes

Using npm

npm install fluxum-sdk-ts

Using yarn

yarn add fluxum-sdk-ts

Type Safety

Full TypeScript support with comprehensive type definitions and IntelliSense.

Security

Built-in client-side encryption with optional custom encryption keys for maximum security.

Analytics

Comprehensive analytics tracking for connections, jobs, and rate limits with TypeScript streams.

Event Handling

Handle real-time events with the SDK

// Connection events
sdk.on('connected', () => {
  console.log('WebSocket connected');
});

sdk.on('authenticated', (data: AuthData) => {
  console.log('Authentication successful', data.clientId);
});

sdk.on('disconnected', (data: DisconnectData) => {
  console.log('Disconnected:', data.reason, data.code);
});

// Job events
sdk.on('jobSubmitted', (data: JobSubmittedData) => {
  console.log('Job submitted:', data.jobId);
});

sdk.on('jobAccepted', (data: JobAcceptedData) => {
  console.log('Job accepted:', data.jobId);
});

sdk.on('jobUpdate', (update: JobUpdate) => {
  console.log('Job update:', update.jobId, update.status);
});

// Error handling
sdk.on('error', (error: SDKError) => {
  console.log('SDK Error:', error.message);
});

// Rate limiting
sdk.on('rateLimitStatus', (status: RateLimitStatus) => {
  console.log('Rate limit:', status.isRateLimited);
});

Job Submission Examples

Examples of different job types and configurations

Simple GET Request

const job: JobPayload = {
  targetUrl: 'https://api.example.com/data',
  method: 'GET',
  headers: {
    'Authorization': 'Bearer your-token'
  }
};

const jobId = await sdk.submitJob(job);

POST with JSON Body

const job: JobPayload = {
  targetUrl: 'https://api.example.com/users',
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer your-token'
  },
  body: JSON.stringify({
    name: 'John Doe',
    email: '[email protected]'
  })
};

const jobId = await sdk.submitJob(job);

Form Data

const job: JobPayload = {
  targetUrl: 'https://api.example.com/upload',
  method: 'POST',
  headers: {
    'Content-Type': 'multipart/form-data'
  },
  body: formData // FormData object
};

const jobId = await sdk.submitJob(job);

Advanced Features

Advanced configuration and features

Custom Encryption

const sdk = new FluxumSDK({
  apiKey: 'your-api-key',
  enableClientSideEncryption: true,
  encryptionKey: 'your-custom-encryption-key'
});

Connection Management

// Manual connection
await sdk.connect();

// Disconnect
await sdk.disconnect();

// Check connection status
if (sdk.isConnected()) {
  console.log('Connected');
}

// Reconnect
await sdk.reconnect();

Analytics

// Get analytics data
const analytics = sdk.getAnalytics();

console.log('Total jobs:', analytics.totalJobs);
console.log('Successful jobs:', analytics.successfulJobs);
console.log('Failed jobs:', analytics.failedJobs);
console.log('Average response time:', analytics.averageResponseTime);

// Reset analytics
sdk.resetAnalytics();

Error Handling

Comprehensive error handling and recovery

// Global error handler
sdk.on('error', (error: SDKError) => {
  switch (error.type) {
    case 'connection':
      console.error('Connection error:', error.message);
      break;
    case 'authentication':
      console.error('Authentication error:', error.message);
      break;
    case 'job':
      console.error('Job error:', error.message);
      break;
    case 'rate_limit':
      console.error('Rate limit exceeded:', error.message);
      break;
    default:
      console.error('Unknown error:', error.message);
  }
});

// Handle specific errors
sdk.on('connectionFailed', (error: ConnectionError) => {
  console.error('Failed to connect:', error.message);
  // Implement retry logic
});

sdk.on('authenticationFailed', (error: AuthError) => {
  console.error('Authentication failed:', error.message);
  // Handle invalid API key
});

Requirements

System requirements and dependencies

TypeScript Version

TypeScript 4.5.0 or higher

Dependencies

  • fluxum-sdk-ts (TypeScript SDK)
  • ws (WebSocket client)
  • crypto (built-in Node.js module)
  • events (built-in Node.js module)

API Reference

Complete API documentation

Constructor

new FluxumSDK(options: FluxumSDKOptions)

interface FluxumSDKOptions {
  apiKey: string;
  autoConnect?: boolean;
  enableClientSideEncryption?: boolean;
  enableAnalytics?: boolean;
  maxReconnectAttempts?: number;
  reconnectDelay?: number;
  connectionTimeout?: number;
  logLevel?: 'debug' | 'info' | 'warn' | 'error';
}

Methods

// Connection
await sdk.connect(): Promise<void>
await sdk.disconnect(): Promise<void>
await sdk.reconnect(): Promise<void>

// Status
sdk.isConnected(): boolean
sdk.isAuthenticated(): boolean

// Jobs
await sdk.submitJob(job: JobConfig): Promise<string>
await sdk.cancelJob(jobId: string): Promise<void>

// Analytics
sdk.getAnalytics(): AnalyticsData
sdk.resetAnalytics(): void

// Events
sdk.on(event: string, callback: Function): void
sdk.off(event: string, callback: Function): void

Explore Other SDKs

Fluxum provides SDKs for multiple programming languages. Choose the one that best fits your project requirements.

Currently viewing: TypeScript

TypeScript logo
TypeScript (Current)

© 2025 Fluxum. All rights reserved.