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

@trustrails/sdk

v0.4.10

Published

Official TypeScript SDK for TrustRails API

Readme

TrustRails TypeScript SDK

Official TypeScript/JavaScript client library for the TrustRails API.

Installation

npm install @trustrails/sdk

Quick Start

import TrustRails from '@trustrails/sdk';

// Initialize the SDK (baseUrl defaults to production)
const trustrails = new TrustRails('your-api-key');

// Search for products with filters
const results = await trustrails.search({
  brand: 'HP',
  category: 'Laptops',
  minPrice: 400,
  maxPrice: 600,
});

console.log(`Found ${results.total} products`);
results.products.forEach(product => {
  console.log(`${product.title} - £${product.price}`);
});

// Get a specific product
const product = await trustrails.product('product-id');
console.log(product);

API Reference

TrustRails

Constructor

new TrustRails(apiKey: string)

Or use a config object for custom baseUrl:

new TrustRails({ apiKey: string, baseUrl?: string })

Parameters:

  • apiKey - Your TrustRails API key
  • baseUrl (optional) - Custom base URL (defaults to https://trustrails.app)

Methods

search(options?: SearchOptions): Promise<SearchResponse>

Search for products. Returns summary data (title, price, availability, category). For full technical specs, call product(id) with the product ID.

Parameters:

  • options.query?: string - Refinement terms after brand and category are extracted: model lines, series, variants, technology descriptors, or model numbers (e.g. 'neo', 'ultra', 'oled', 'WH-1000XM5'). Omit entirely if brand + category fully describe what you want. Never put brand names, product family names, or prices here — use filters.
  • options.brand?: string - Filter by brand name (e.g., 'Sony', 'HP', 'Anker')
  • options.category?: string - Filter by product category (e.g., 'Laptops', 'Headphones')
  • options.minPrice?: number - Minimum price filter in GBP
  • options.maxPrice?: number - Maximum price filter in GBP
  • options.lite?: boolean - Return trimmed product objects with only essential fields including offer_count (reduces payload by ~80%)
  • options.limit?: number - Maximum number of results (default: 50, max: 100)
  • options.sort?: string - Sort order: 'relevance' (default), 'price_asc' (cheapest first), 'price_desc' (most expensive first)

Returns: Promise resolving to SearchResponse containing products array and total count.

Example — brand + category only (query omitted):

const results = await trustrails.search({
  brand: 'HP',
  category: 'Laptops',
  minPrice: 400,
  maxPrice: 1000,
  sort: 'price_asc'
});

Example — with model line in query:

// 'neo', 'ultra', 'oled' etc. go in query — they refine within brand/category
const results = await trustrails.search({
  brand: 'Samsung',
  category: 'TVs',
  query: 'qled',
});

Lite mode (faster responses, smaller payloads):

const results = await trustrails.search({
  brand: 'Anker',
  category: 'Cables & Chargers',
  lite: true  // Returns only: id, title, brand, price, availability, image_url, purchase_url
});
product(id: string): Promise<Product>

Get full details for a single product. Returns complete technical specifications including specs.description (full prose spec text with processor, RAM, storage, display, etc.), stock level, delivery time, and all retailer offers with per-retailer pricing. Accepts canonical product IDs or original retailer offer IDs. Use this after search() to get detailed specs for comparison or recommendations.

Parameters:

  • id: string - The product ID

Returns: Promise resolving to Product object with all fields populated

Example:

const product = await trustrails.product('prod_123');

Types

Product

interface Product {
  id: string;
  ean?: string;
  title: string;
  brand?: string;
  price: number;
  currency: string;
  availability: "in_stock" | "low_stock" | "out_of_stock";
  stock: number;
  delivery_time: string;
  image_url?: string;
  category: string;
  product_type: "product" | "accessory";
  specs: {
    description?: string;  // Full prose spec text — always check this for technical details
    model_number?: string;
    dimensions?: string;
  };
  provenance: {
    source: string;
    last_updated: string;
  };
  purchase_url: string;
  offer_count?: number;  // number of retailer offers (when >1, call product() to compare prices)
  offers?: Offer[];      // per-retailer offers sorted by price (returned by product())
}

interface Offer {
  id: string;
  source: string;
  title: string;
  price: number;
  currency: string;
  availability: "in_stock" | "low_stock" | "out_of_stock";
  stock: number;
  delivery_time: string;
  purchase_url: string;
  image_url?: string;
  last_updated: string;
}

SearchOptions

interface SearchOptions {
  query?: string;
  brand?: string;
  category?: string;
  minPrice?: number;
  maxPrice?: number;
  lite?: boolean;
  limit?: number;
  sort?: 'relevance' | 'price_asc' | 'price_desc';
}

SearchResponse

interface SearchResponse {
  products: Product[];
  total: number;
}

Error Handling

The SDK throws TrustRailsError for API-related errors:

import TrustRails, { TrustRailsError } from '@trustrails/sdk';

const trustrails = new TrustRails('your-api-key');

try {
  const product = await trustrails.product('invalid-id');
} catch (error) {
  if (error instanceof TrustRailsError) {
    console.error(`API Error: ${error.message}`);
    console.error(`Status Code: ${error.statusCode}`);
  }
}

License

MIT