npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@almosteffective/premiumize-api

v3.3.0

Published

A TypeScript library for interacting with the Premiumize.me API

Downloads

220

Readme

@almosteffective/premiumize-api

A TypeScript library for interacting with the Premiumize.me API with full type safety and runtime validation.

Installation

npm install @almosteffective/premiumize-api
# or
pnpm add @almosteffective/premiumize-api

Quick Start

import { 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);

API Methods

Account

  • accountInfo(): Get account information and limits

Transfers

  • createTransfer(options): Create a new transfer from magnet/torrent or NZB container
  • listTransfers(): List all transfers
  • deleteTransfers(options): Delete transfers
  • clearTransfers(): Clear all finished transfers

Folders

  • listFolder(options?): List contents of a folder
  • createFolder(options): Create a new folder
  • deleteFolder(options): Delete a folder
  • renameFolder(options): Rename a folder
  • searchFolder(options): Search files and folders

Items (Files)

  • listAllItems(): List all files across all folders
  • deleteItem(options): Delete a file
  • renameItem(options): Rename a file
  • getItemDetails(options): Get detailed information about a file

Zip

  • generateZip(options): Generate a zip file from multiple items

Cache

  • checkCache(options): Check if URLs are available in Premiumize cache

Services

  • listServices(): Get list of supported services and domains

Detailed Usage Examples

Working with Folders

// 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'
});

Managing Transfers

// 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();

Working with Files

// 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'
});

Utilities

// 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();

Error Handling

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);
  }
}

Configuration

Required Configuration

Only an API key is required to use the library. You can obtain your API key from your Premiumize account settings.

Optional Configuration

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'
});

Testing

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.

Running Tests

# Run tests in watch mode
pnpm test

# Run tests once
pnpm run test:run

# Run tests with coverage
pnpm run test:coverage

Test Structure

The tests are organized in the following way:

  1. src/test/setup.ts - Sets up the MSW server and provides mock handlers for API endpoints
  2. src/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

Adding New Tests

When adding new API methods to the library, make sure to add corresponding tests in src/client.test.ts. The pattern is:

  1. Define a mock response in src/test/setup.ts (if it's a new endpoint)
  2. Add a test case in src/client.test.ts that verifies the method works correctly
  3. Test both success and error cases

Features

  • 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

Development

# Install dependencies
pnpm install

# Build
pnpm run build

# Test
pnpm test

# Lint
pnpm run lint

License

MIT