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

reviews-headless-sdk

v1.0.1

Published

TypeScript SDK for Reviews Headless API

Readme

Reviews SDK

A TypeScript SDK for the Reviews Headless API, providing a clean interface for all CRUD operations on product reviews.

Installation

npm install @alexa-maxa/reviews-sdk

Quick Start

import { ReviewsSDK } from '@alexa-maxa/reviews-sdk';

const reviewsSDK = new ReviewsSDK({
  apiKey: process.env.REVIEWS_HEADLESS_API_KEY!,
  baseUrl: process.env.REVIEWS_HEADLESS_API_URL!,
  timeout: 30000, // optional, defaults to 30 seconds
});

// Get reviews for a product
const reviews = await reviewsSDK.getByProduct('product-id', {
  page: 1,
  limit: 10,
  sortBy: 'submittedAt',
  sortOrder: 'desc'
});

// Create a new review
const newReview = await reviewsSDK.create({
  productId: 'gid://shopify/Product/123',
  productHandle: 'product-handle',
  rating: '5',
  title: 'Great product!',
  customerName: 'John Doe',
  customerEmail: '[email protected]',
  description: 'Really loved this product!'
});

Features

  • 🔧 Full CRUD Support: Create, Read, Update, Delete, and Approve reviews
  • 🛡️ Type Safety: Full TypeScript support with comprehensive type definitions
  • Error Handling: Centralized error handling with specific error codes
  • 🌐 Server-Side Focused: Optimized for Next.js server components and API routes
  • 📦 Zero Dependencies: Lightweight with no external runtime dependencies

API Reference

Constructor

new ReviewsSDK(config: ReviewsSDKConfig)

Config Options:

  • apiKey (string): Your Reviews Headless API key
  • baseUrl (string): The base URL for the Reviews API
  • timeout (number, optional): Request timeout in milliseconds (default: 30000)

Methods

getByProduct(productId, filters?)

Get reviews for a specific product with optional filtering.

const reviews = await reviewsSDK.getByProduct('product-id', {
  rating: 5,           // Filter by rating (1-5 or "all")
  sortBy: 'rating',    // Sort by 'submittedAt' or 'rating'
  sortOrder: 'desc',   // 'asc' or 'desc'
  page: 1,             // Page number
  limit: 10            // Results per page
});

getById(reviewId)

Get a single review by its ID.

const review = await reviewsSDK.getById('review-id');

create(data)

Create a new review.

const newReview = await reviewsSDK.create({
  productId: 'gid://shopify/Product/123',
  productHandle: 'product-handle',
  rating: '5',
  title: 'Great product!',
  customerName: 'John Doe',
  customerEmail: '[email protected]',
  description: 'Really loved this product!'
});

update(reviewId, data)

Update an existing review.

const updatedReview = await reviewsSDK.update('review-id', {
  title: 'Updated title',
  description: 'Updated description',
  rating: '4'
});

delete(reviewId)

Delete a review.

const result = await reviewsSDK.delete('review-id');

approve(reviewId)

Approve a review (admin operation).

const approvedReview = await reviewsSDK.approve('review-id');

getAll(filters?) & getPending(filters?)

Admin operations for getting all reviews or pending reviews.

// Get all reviews (admin)
const allReviews = await reviewsSDK.getAll({ page: 1, limit: 20 });

// Get pending reviews (admin)
const pendingReviews = await reviewsSDK.getPending({ page: 1, limit: 20 });

Error Handling

The SDK throws ReviewsSDKError instances with specific error codes:

import { ReviewsSDKError } from '@alexa-maxa/reviews-sdk';

try {
  await reviewsSDK.getByProduct('product-id');
} catch (error) {
  if (error instanceof ReviewsSDKError) {
    console.log(`Error: ${error.message}`);
    console.log(`Code: ${error.code}`);
    console.log(`Status: ${error.status}`);
    
    switch (error.code) {
      case 'NOT_FOUND':
        // Handle not found
        break;
      case 'AUTHENTICATION_ERROR':
        // Handle auth error
        break;
      case 'NETWORK_ERROR':
        // Handle network error
        break;
      // ... other error codes
    }
  }
}

Error Codes

  • AUTHENTICATION_ERROR: Invalid or missing API key
  • NOT_FOUND: Resource not found
  • VALIDATION_ERROR: Invalid request data
  • PERMISSION_ERROR: Insufficient permissions
  • CONFLICT_ERROR: Resource conflict (e.g., duplicate review)
  • RATE_LIMIT_ERROR: Too many requests
  • SERVER_ERROR: Internal server error
  • NETWORK_ERROR: Network connection failed
  • TIMEOUT_ERROR: Request timed out
  • HTTP_ERROR: Generic HTTP error
  • UNKNOWN_ERROR: Unknown error occurred

Usage with Next.js

Server Components

// app/products/[id]/page.tsx
import { reviewsSDK } from '@/lib/reviews/sdk-instance';

export default async function ProductPage({ params }) {
  const reviews = await reviewsSDK.getByProduct(params.id);
  return <ProductReviews initialData={reviews} />;
}

Server Actions

// actions/submit-review.ts
"use server";

import { reviewsSDK } from '@/lib/reviews/sdk-instance';

export async function submitReview(formData: FormData) {
  try {
    const result = await reviewsSDK.create({
      productId: formData.get('productId'),
      productHandle: formData.get('productHandle'),
      // ... other fields
    });
    
    return { success: true, data: result };
  } catch (error) {
    return { success: false, error: error.message };
  }
}

API Routes

// app/api/reviews/[productId]/route.ts
import { reviewsSDK } from '@/lib/reviews/sdk-instance';

export async function GET(request: Request, { params }) {
  try {
    const reviews = await reviewsSDK.getByProduct(params.productId);
    return Response.json(reviews);
  } catch (error) {
    return Response.json({ error: error.message }, { status: 500 });
  }
}

Development

To work on this SDK:

cd packages/reviews-sdk

# Install dependencies
npm install

# Build the SDK
npm run build

# Watch for changes during development
npm run dev

License

MIT