PlanSolve is still in pre-alpha โ€“ Features may change or break. Feedback welcome!

TypeScript/JavaScript SDK

Full-featured SDK for Node.js and modern browsers

PlanSolve TypeScript/JavaScript SDK

A JavaScript/TypeScript client library for the PlanSolve optimization API. Solve complex optimization problems with a simple, async API.

Installation

๐Ÿ“ฆ

npm

npm install plansolve
๐Ÿงถ

yarn

yarn add plansolve
๐Ÿž

bun

bun add plansolve

Requirements

Node.js 18+

Modern Node.js with native fetch support

Browser Support

Modern browsers with fetch API support

API Key

Optional but recommended for production use

TypeScript

Full type definitions included

API Workflow

All PlanSolve optimization APIs follow the same workflow. Understanding this process will help you integrate the API effectively.

1

Construct Request

Build your optimization request with the required data

2

Start Solver

Submit the request to start the optimization process

3

Poll Status

Check the status until the solver completes

4

Get Results

Retrieve the optimized solution

Solver SDKs

Choose your optimization solver and get started with comprehensive examples and documentation.

๐Ÿšš

Field Service

Route Optimization

Optimize field technician routes, schedule customer visits, and manage service appointments with intelligent routing algorithms.

Vehicle routing and scheduling
Time window constraints
Skill-based assignment
View Field Service SDK
๐Ÿ‘ฅ

Professional Services

Task Assignment

Optimize employee task assignments, project scheduling, and resource allocation for professional service organizations.

Employee task assignment
Project scheduling
Skill matching
View Professional Services SDK

API Reference

PlanSolveClient

The main client class for interacting with the PlanSolve API.

Constructor

new PlanSolveClient(apiKey?: string)

Methods

  • fieldService - Access to field service optimization methods
  • professionalServices - Access to professional services optimization methods
  • getStatus(jobId: string) - Get the status of a running optimization job

FieldServiceApiClient

Handles field service optimization requests and results.

Methods

  • start(request: FieldServiceRequest) - Start a new field service optimization
  • getResult(jobId: string) - Get the completed optimization result

ProfessionalServicesApiClient

Handles professional services task assignment optimization requests and results.

Methods

  • start(request: ProfessionalServicesRequest) - Start a new professional services optimization
  • getResult(jobId: string) - Get the completed optimization result
  • getStatus(jobId: string) - Get the status of a running optimization job
  • startAndWaitForCompletion(request, pollIntervalMs?, maxAttempts?) - Start optimization and wait for completion with polling

Data Models

Field Service Models

Vehicle

interface Vehicle { id: string; homeLocation: [number, number]; shifts: Shift[]; skills: string[]; }

Visit

interface Visit { id: string; name: string; location: [number, number]; timeWindows: TimeWindow[]; serviceDuration: string; priority: 'HIGH' | 'MEDIUM' | 'LOW'; requiredSkills: string[]; }

Professional Services Models

Employee

interface Employee { id: string; shifts: Shift[]; skills: string[]; }

Task

interface Task { id: string; name: string; deadline?: string; duration: string; priority: string; requiredSkills: string[]; }

Advanced Usage

Error Handling

try {
  const response = await client.professionalServices.start(request);
  // Handle success
} catch (error) {
  if (error.message.includes('API error: 401')) {
    console.error('Invalid API key');
  } else if (error.message.includes('API error: 400')) {
    console.error('Invalid request data');
  } else if (error.message.includes('API error: 429')) {
    console.error('Rate limit exceeded');
  } else {
    console.error('Unexpected error:', error.message);
  }
}

Async Optimization with Polling

async function waitForCompletion(client, jobId, maxWaitMinutes = 30) {
  const startTime = Date.now();
  const maxWaitMs = maxWaitMinutes * 60 * 1000;
  
  while (Date.now() - startTime < maxWaitMs) {
    const status = await client.getStatus(jobId);
    
    if (status.status === 'COMPLETED') {
      return await client.professionalServices.getResult(jobId);
    } else if (status.status === 'FAILED') {
      throw new Error(`Optimization failed: ${status.error || 'Unknown error'}`);
    }
    
    await new Promise(resolve => setTimeout(resolve, 5000));
  }
  
  throw new Error('Optimization timed out');
}

Browser Usage

The SDK works in modern browsers that support the Fetch API.

<!DOCTYPE html>
<html>
<head>
    <title>PlanSolve Optimization</title>
</head>
<body>
    <script type="module">
        import { PlanSolveClient } from 'https://unpkg.com/plansolve@latest/dist/plansolve.js';
        
        const client = new PlanSolveClient('YOUR_API_KEY');
        
        // Use the client as shown in the examples above
    </script>
</body>
</html>

Ready to Build?

Start integrating PlanSolve optimization into your applications today.