Skip to content

JavaScript SDK

The official JavaScript/TypeScript client for the BinDist API.

Installation

npm install @bindist/client

Or with yarn:

yarn add @bindist/client

Quick Start

import { createBinDistClient } from '@bindist/client';

const client = createBinDistClient({
  baseUrl: 'https://api.bindist.eu',
  apiKey: process.env.BINDIST_API_KEY!
});

// List applications
const apps = await client.listApplications();
if (apps.success) {
  console.log(apps.data.applications);
}

// Get download URL
const download = await client.getDownloadInfo('my-app', '2.1.0');
if (download.success) {
  console.log(download.data.downloadUrl);
}

Configuration

interface BinDistClientConfig {
  baseUrl: string;    // API base URL
  apiKey: string;     // Your API key
  timeout?: number;   // Request timeout in ms (default: 30000)
}

Methods

Applications

listApplications

List all accessible applications.

const result = await client.listApplications({
  search: 'my-app',
  tag: 'windows',
  limit: 10
});

Options:

Option Type Description
search string Search by name or description
tag string Filter by tag
limit number Maximum items
cursor string Pagination cursor

getApplication

Get details for a specific application.

const result = await client.getApplication('my-app');

deleteApplication

Soft delete an application (admin only).

const result = await client.deleteApplication('my-app');

Versions

listVersions

List all versions for an application.

const result = await client.listVersions('my-app');

listVersionFiles

List all files in a version.

const result = await client.listVersionFiles('my-app', '2.1.0');

Downloads

getDownloadInfo

Get a pre-signed download URL.

const result = await client.getDownloadInfo('my-app', '2.1.0');
if (result.success) {
  const { downloadUrl, fileName, fileSize } = result.data;
  console.log(`Download ${fileName} (${fileSize} bytes)`);
  console.log(downloadUrl);
}

downloadFile

Download a file and return as ArrayBuffer.

const info = await client.getDownloadInfo('my-app', '2.1.0');
if (info.success) {
  const buffer = await client.downloadFile(info.data.downloadUrl);
  // Save to file
  import { writeFileSync } from 'fs';
  writeFileSync('output.exe', Buffer.from(buffer));
}

downloadFileStream

Download a file as a stream (for large files).

const stream = await client.downloadFileStream(downloadUrl);
// Pipe to file or process

Create a shareable download link.

const result = await client.createShareLink({
  applicationId: 'my-app',
  version: '2.1.0',
  expiresInMinutes: 60
});

Customers (Admin)

listCustomers

List all customers.

const result = await client.listCustomers();

updateCustomer

Update a customer.

const result = await client.updateCustomer('cust_123', {
  name: 'New Name',
  isActive: true
});

regenerateCustomerKey

Regenerate a customer's API key.

const result = await client.regenerateCustomerKey('cust_123');
if (result.success) {
  console.log('New API key:', result.data.apiKey);
}

Backups (Admin)

listBackups

List available backups.

const result = await client.listBackups();

startBackup

Start a new backup.

const result = await client.startBackup('MANUAL');

getBackupContents

Get backup contents with download URLs.

const result = await client.getBackupContents('backup_123', true);

Account (Admin)

getAccount

Get account information.

const result = await client.getAccount({
  includeResources: true,
  includeEvents: true
});

archiveTenant

Archive/cancel the account.

const result = await client.archiveTenant();

Activity (Admin)

listActivity

List recent activity (uploads/downloads).

const result = await client.listActivity({
  type: 'download',
  applicationId: 'my-app',
  limit: 50
});

Error Handling

All methods return an ApiResponse object:

interface ApiResponse<T> {
  success: boolean;
  data?: T;
  error?: {
    code: string;
    message: string;
  };
}

Example error handling:

const result = await client.getApplication('unknown-app');

if (!result.success) {
  console.error(`Error ${result.error?.code}: ${result.error?.message}`);
  // Handle specific errors
  if (result.error?.code === 'NOT_FOUND') {
    console.log('Application does not exist');
  }
}

TypeScript Support

The SDK is written in TypeScript and includes full type definitions. All response types are exported:

import {
  ApplicationInfo,
  VersionInfo,
  DownloadInfo,
  CustomerInfo,
  // ... more types
} from '@bindist/client';