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 🙏

© 2025 – Pkg Stats / Ryan Hefner

tripadvisor-client

v0.1.1

Published

A comprehensive TypeScript client library for TripAdvisor Content API. Built to address the lack of official SDK and unreliable field type documentation.

Readme

TripAdvisor Client

License: MIT npm version Node.js

A comprehensive TypeScript client library for TripAdvisor Content API. Built to address the lack of official SDK and unreliable field type documentation.

✨ Features

  • 🔒 Type Safety: Full TypeScript support with comprehensive type definitions
  • 📦 Modular Architecture: Clean, modular codebase for easy maintenance
  • 🛡️ Error Handling: Robust error handling with custom error classes
  • ⚡ Performance: Optimized HTTP client with retry logic and timeout handling
  • 🔧 Configurable: Flexible configuration options for different use cases
  • 📚 Well Documented: Comprehensive JSDoc documentation and examples

🚀 Quick Start

Installation

npm install tripadvisor-client

Basic Usage

import { TripAdvisorClient } from 'tripadvisor-client';

// Create client instance
const client = new TripAdvisorClient({
  apiKey: 'your-api-key',
});

// Search for locations
const locations = await client.locationSearch({
  searchQuery: 'Eiffel Tower',
  category: 'attractions',
});

// Get location details
const details = await client.locationDetails(
  '12345',
  {
    language: 'en',
    currency: 'USD',
  },
  'attractions'
);

// Get reviews
const reviews = await client.locationReviews('12345', {
  language: 'en',
  limit: 10,
});

// Get photos
const photos = await client.locationPhotos('12345', 20);

📖 API Reference

TripAdvisorClient

The main client class for interacting with TripAdvisor API.

Constructor

new TripAdvisorClient(config?: Partial<TripAdvisorConfig>)

Configuration Options:

  • apiKey (required): Your TripAdvisor API key
  • baseUrl (optional): API base URL (default: https://api.content.tripadvisor.com/api/v1)
  • language (optional): Default language (default: 'en')
  • currency (optional): Default currency (default: 'USD')
  • timeout (optional): Request timeout in milliseconds (default: 30000)
  • retries (optional): Number of retry attempts (default: 3)
  • retryDelay (optional): Delay between retries in milliseconds (default: 1000)

Methods

locationSearch(payload: LocationSearchPayload): Promise<LocationSearchResult[]>

Search for locations based on query parameters.

const results = await client.locationSearch({
  searchQuery: 'Paris hotels',
  category: 'hotels',
  language: 'en',
  latLong: '48.8566,2.3522',
  radius: 10,
  radiusUnit: 'km',
});
locationDetails(locationId: string, payload: LocationDetailsPayload, category?: TripAdvisorCategory): Promise<LocationDetailsResponse>

Get detailed information about a specific location.

// Type-safe hotel details
const hotelDetails = await client.locationDetails(
  '12345',
  {
    language: 'en',
    currency: 'USD',
  },
  'hotels'
);

// Generic location details
const locationDetails = await client.locationDetails('12345', {
  language: 'en',
});
locationReviews(locationId: string, payload: LocationReviewsPayload): Promise<LocationReviewsResult[]>

Get reviews for a specific location.

const reviews = await client.locationReviews('12345', {
  language: 'en',
  limit: 10,
  offset: 0,
});
locationPhotos(locationId: string, limit: number): Promise<LocationPhotosData[]>

Get photos for a specific location.

const photos = await client.locationPhotos('12345', 20);
getConfig(): TripAdvisorConfig

Get current client configuration.

updateConfig(updates: Partial<TripAdvisorConfig>): void

Update client configuration.

client.updateConfig({
  language: 'es',
  currency: 'EUR',
});

🏗️ Architecture

The library is built with a modular architecture for maintainability and extensibility:

src/
├── index.ts              # Main entry point
├── client.ts             # Main client class
├── config.ts             # Configuration management
├── errors.ts             # Custom error classes
├── http-client.ts        # HTTP client with retry logic
└── types/                # Type definitions
    ├── index.ts          # Type exports
    ├── common.ts         # Common types
    ├── search.ts         # Search-related types
    ├── details.ts        # Details-related types
    ├── reviews.ts        # Reviews-related types
    └── photos.ts         # Photos-related types

🛡️ Error Handling

The library provides custom error classes for better error handling:

import { TripAdvisorError, ConfigurationError, ValidationError } from 'tripadvisor-client';

try {
  const results = await client.locationSearch({ searchQuery: 'test' });
} catch (error) {
  if (error instanceof TripAdvisorError) {
    console.error('API Error:', error.message, error.code);
  } else if (error instanceof ConfigurationError) {
    console.error('Configuration Error:', error.message);
  } else if (error instanceof ValidationError) {
    console.error('Validation Error:', error.message);
  }
}

🔧 Configuration

Environment Variables

You can set the API key using environment variables:

export TRIPADVISOR_API_KEY="your-api-key"

Default Client

A default client instance is exported for convenience:

import { tripAdvisorClient } from 'tripadvisor-client';

// Uses TRIPADVISOR_API_KEY environment variable
const results = await tripAdvisorClient.locationSearch({
  searchQuery: 'Eiffel Tower',
});

📝 Examples

See the examples/ directory for more detailed usage examples:

  • basic-usage.js - Basic usage examples
  • advanced-usage.ts - Advanced usage with error handling

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Development Setup

  1. Clone the repository
  2. Install dependencies: npm install
  3. Set your API key: export TRIPADVISOR_API_KEY="your-key"
  4. Run tests: npm test
  5. Build: npm run build

Code Quality

The project uses several tools to maintain code quality:

  • ESLint - Code linting
  • Prettier - Code formatting
  • TypeScript - Type checking
  • Vitest - Testing

Run quality checks:

npm run check-all  # Run all checks
npm run lint       # Lint code
npm run format     # Format code
npm run test       # Run tests

📄 License

MIT License - see LICENSE file for details.

🔗 Links