JavaScript SDK¶
The official JavaScript/TypeScript client for the BinDist API.
Installation¶
Or with yarn:
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.
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.
deleteApplication¶
Soft delete an application (admin only).
Versions¶
listVersions¶
List all versions for an application.
listVersionFiles¶
List all files in a version.
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).
createShareLink¶
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.
updateCustomer¶
Update a customer.
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.
startBackup¶
Start a new backup.
getBackupContents¶
Get backup contents with download URLs.
Account (Admin)¶
getAccount¶
Get account information.
archiveTenant¶
Archive/cancel the account.
Activity (Admin)¶
listActivity¶
List recent activity (uploads/downloads).
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: