A TypeScript library for interacting with the Premiumize.me API with full type safety and runtime validation.
npm install @almosteffective/premiumize-api
# or
pnpm add @almosteffective/premiumize-apiimport { PremiumizeClient } from '@almosteffective/premiumize-api';
// Create a client instance (recommended method)
const client = PremiumizeClient.create('your-api-key-here');
// Or using the constructor directly
const client = new PremiumizeClient({
apiKey: 'your-api-key-here',
baseUrl: 'https://custom-api-endpoint.com' // optional
});
// Get account info
const account = await client.accountInfo();
console.log(account);
// Create a transfer
const transfer = await client.createTransfer({
src: 'magnet:?xt=urn:btih:...'
});
console.log(transfer);
// List transfers
const transfers = await client.listTransfers();
console.log(transfers);
// List folder contents
const folder = await client.listFolder();
console.log(folder);accountInfo(): Get account information and limits
createTransfer(options): Create a new transfer from magnet/torrent or NZB containerlistTransfers(): List all transfersdeleteTransfers(options): Delete transfersclearTransfers(): Clear all finished transfers
listFolder(options?): List contents of a foldercreateFolder(options): Create a new folderdeleteFolder(options): Delete a folderrenameFolder(options): Rename a foldersearchFolder(options): Search files and folders
listAllItems(): List all files across all foldersdeleteItem(options): Delete a filerenameItem(options): Rename a filegetItemDetails(options): Get detailed information about a file
generateZip(options): Generate a zip file from multiple items
checkCache(options): Check if URLs are available in Premiumize cache
listServices(): Get list of supported services and domains
// List root folder
const rootFolder = await client.listFolder();
// List a specific folder with breadcrumbs
const folderWithBreadcrumbs = await client.listFolder({
id: 'folder-id',
includebreadcrumbs: true
});
// Create a new folder
const newFolder = await client.createFolder({
name: 'My Downloads',
parent_id: 'parent-folder-id'
});
// Rename a folder
await client.renameFolder({
id: 'folder-id',
name: 'New Folder Name'
});
// Delete a folder
await client.deleteFolder({
id: 'folder-id'
});
// Search for items
const searchResults = await client.searchFolder({
query: 'movie title'
});// Create a new transfer
const transfer = await client.createTransfer({
src: 'magnet:?xt=urn:btih:...',
folder_id: 'destination-folder-uuid'
});
// List all transfers
const transfers = await client.listTransfers();
// Delete a specific transfer
await client.deleteTransfers({
id: 'transfer-id'
});
// Clear all finished transfers
await client.clearTransfers();// List all files across all folders
const allFiles = await client.listAllItems();
// Get detailed information about a file
const fileDetails = await client.getItemDetails({
id: 'file-id'
});
// Rename a file
await client.renameItem({
id: 'file-id',
name: 'New File Name.ext'
});
// Delete a file
await client.deleteItem({
id: 'file-id'
});// Check if URLs are in cache
const cacheCheck = await client.checkCache({
items: ['https://example.com/file1.zip', 'https://example.com/file2.zip']
});
// Generate a zip file
const zipFile = await client.generateZip({
files: ['file-id-1', 'file-id-2'],
folders: ['folder-id-1']
});
// Get supported services
const services = await client.listServices();The library provides comprehensive error handling with custom error types:
try {
const result = await client.accountInfo();
console.log(result);
} catch (error) {
if (error instanceof PremiumizeError) {
console.error('Premiumize API Error:', error.message);
// Additional error details are available in error.internalError
} else if (error instanceof HTTPError) {
console.error('HTTP Request Error:', error.message);
} else {
console.error('Unexpected Error:', error.message);
}
}Only an API key is required to use the library. You can obtain your API key from your Premiumize account settings.
You can optionally provide a custom base URL if you're using a proxy or different endpoint:
const client = new PremiumizeClient({
apiKey: 'your-api-key-here',
baseUrl: 'https://my-proxy.com/premiumize-api'
});This library uses Vitest for testing with MSW (Mock Service Worker) to mock API requests. This allows us to test the library without making real API calls.
# Run tests in watch mode
pnpm test
# Run tests once
pnpm run test:run
# Run tests with coverage
pnpm run test:coverageThe tests are organized in the following way:
src/test/setup.ts- Sets up the MSW server and provides mock handlers for API endpointssrc/client.test.ts- Contains tests for the PremiumizeClient class and its methods
Each test case mocks the API responses to verify that the client correctly handles different scenarios, including:
- Successful API responses
- API errors
- Network errors
- Validation of request parameters
When adding new API methods to the library, make sure to add corresponding tests in src/client.test.ts. The pattern is:
- Define a mock response in
src/test/setup.ts(if it's a new endpoint) - Add a test case in
src/client.test.tsthat verifies the method works correctly - Test both success and error cases
- Type Safety: Full TypeScript support with strict typing
- Schema Validation: Runtime validation using Zod schemas to ensure API responses match expected structure
- Error Handling: Comprehensive error handling with descriptive messages
- Easy Configuration: Simple setup with API key and optional custom base URL
- Comprehensive Testing: Full test coverage with mocked API responses
# Install dependencies
pnpm install
# Build
pnpm run build
# Test
pnpm test
# Lint
pnpm run lintMIT