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

medusa-product-detail-logic

v1.0.2

Published

Ported Product Detail logic from B&B_ui project.

Downloads

44

Readme

medusa-product-detail-logic

Reusable product detail hook logic for Medusa storefronts.

This package exposes useProduct and related service helpers used by the product detail page flow:

  • variant selection
  • price formatting
  • stock/availability
  • add-to-cart readiness and status
  • media/gallery state
  • wishlist (local or Medusa API)
  • reviews (callback or Medusa rating endpoint)
  • related products

Installation

npm install

For local development in this monorepo:

npm run build

Exports

From src/index.ts:

  • useProduct hook
  • product formatter/service helpers from medusa-services:
    • product-detail
    • wishlist
    • reviews
    • related-products

Quick Usage

import { useProduct } from "medusa-product-detail-logic"

const pdp = useProduct({
  initialProduct,
  onAddToCart: async (variantId, quantity) => {
    // call cart API
  },
  syncSelectionWithUrl: true,
  wishlistMedusa: {
    backendUrl: "https://your-medusa-server.com",
    publishableApiKey: "pk_...",
  },
  wishlistCustomerAuthorization: customerJwtOrNull,
  reviewsMedusa: {
    backendUrl: "https://your-medusa-server.com",
    publishableApiKey: "pk_...",
  },
  relatedProductsMedusa: {
    backendUrl: "https://your-medusa-server.com",
    publishableApiKey: "pk_...",
    regionId: "reg_...",
    limit: 8,
  },
})

useProduct Input (high level)

  • initialProduct: normalized product data for PDP
  • onAddToCart: async callback for cart add
  • maxLineQuantity: optional per-line quantity cap
  • syncSelectionWithUrl: read/write selected options in query params
  • wishlistMedusa + wishlistCustomerAuthorization: enables Medusa /store/wishlist mode
  • onFetchReviewsSummary: custom reviews summary callback (takes precedence)
  • reviewsMedusa: fallback Medusa rating summary source (GET /store/products/:id/rating)
  • onFetchRelatedProducts: custom related products callback (takes precedence)
  • relatedProductsMedusa: fallback Medusa related products source

Returned API (high level)

  • Core: product, isLoading, error
  • Variants: options, selectedOptions, activeVariant, availableOptions, setOption
  • Pricing: pricing
  • Quantity: quantity, incrementQuantity, decrementQuantity, setQuantity
  • Media: mediaUrls, activeMedia, activeMediaIndex, setActiveMedia
  • Cart: isReadyToAddToCart, addToCartStatus, handleAddToCart
  • Inventory: isAvailable, inventoryQuantity, stockStatusMessage
  • Wishlist group: wishlist.{ ids, isWishlisted, toggleWishlist, status, error, refresh }
  • Reviews group: reviews.{ averageRating, totalReviews, status, error, refresh, fetch }
  • Related group: relatedProducts.{ items, status, error, refresh, fetch }

Required Product Shape

initialProduct should include:

  • id, title, description
  • options[]
  • variants[] with option mapping, price, stock/backorder
  • mediaUrls[]

For related-products Medusa fallback, include:

  • collectionId (optional but recommended)
  • tagIds (optional but recommended)

Use formatProductData export from medusa-services/product-detail to normalize Medusa Store product responses.

Notes

  • Wishlist/reviews/related can run in callback mode or Medusa mode.
  • If Medusa config/auth is missing, the hook falls back safely where applicable.
  • This package is intended for UI-agnostic logic; render layer stays in your app.