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

@vinnyum/google-places-reviews

v1.0.4

Published

Fetch rating and total user reviews securely from Google Places Details API for Astro SSR with fallback and timeout support

Readme

@vinnyum/google-places-reviews

Un paquete modular y seguro para consultar de forma asíncrona la calificación (rating) y el número de reseñas (user_ratings_total) de un negocio a través de la API de Google Places.

Diseñado específicamente para integrarse de forma robusta con arquitecturas SSR (Server-Side Rendering) como Astro y Next.js sin bloquear el hilo principal ni agotar tu cuota de API.

🚀 Características

  • TypeScript Nativo: Completamente tipado de forma estática con definiciones completas (.d.ts).
  • Resiliente y Seguro: Manejo inteligente de errores integrado. Si la API de Google falla o tus llaves son inválidas, devuelve un fallback configurable en lugar de romper tu renderizado.
  • Control de Tiempos de Espera (Timeout): Soporte para límite de tiempo configurable (por defecto 5 segundos) usando AbortController para que llamadas a APIs colgadas no demoren la carga de tu web.
  • Cero Dependencias Externas: Diseñado en base a la API estándar nativa de fetch presente en Node 18+.

📦 Instalación

Instala el paquete en tu proyecto cliente:

npm install @vinnyum/google-places-reviews

🛠️ Uso Básico

import { getPlacesReviews } from '@vinnyum/google-places-reviews';

const apiKey = 'TU_GOOGLE_PLACES_API_KEY';
const placeId = 'TU_PLACE_ID';

const result = await getPlacesReviews(apiKey, placeId, {
  timeout: 4000, // Límite de 4 segundos
  fallback: {
    rating: 5.0,
    count: 10 // alias para user_ratings_total
  }
});

console.log(result.rating); // ej: 4.8
console.log(result.count);  // ej: 45
console.log(result.isFallback); // true o false

Opciones (GetPlacesReviewsOptions)

| Opción | Tipo | Defecto | Descripción | | --- | --- | --- | --- | | timeout | number | 5000 | Tiempo de espera límite en milisegundos antes de abortar la petición a Google. | | fallback | object | { rating: 5.0, count: 0 } | Valores devueltos en caso de error, timeout o credenciales incorrectas. |

Objeto Retornado (PlacesReviewsResult)

| Propiedad | Tipo | Descripción | | --- | --- | --- | | rating | number | Calificación promedio del negocio (de 1.0 a 5.0). | | user_ratings_total | number | Cantidad total de reseñas en Google. | | count | number | Alias conveniente para user_ratings_total. | | status | string | Estado devuelto por la API (ej: "OK", "FALLBACK", "TIMEOUT_ERROR"). | | isFallback | boolean | true si falló la API y se están mostrando los valores por defecto, de lo contrario false. |


🌟 Integración en Astro (SSR con Caché para Vercel)

Para no agotar las cuotas de Google Places, se recomienda renderizar bajo SSR y configurar cabeceras de caché CDN (s-maxage).

Crea un componente Astro (ej. src/components/GoogleReviews.astro):

---
import { getPlacesReviews } from '@vinnyum/google-places-reviews';

const GOOGLE_PLACES_API_KEY = import.meta.env.GOOGLE_PLACES_API_KEY;
const GOOGLE_PLACE_ID = import.meta.env.GOOGLE_PLACE_ID;

// Configurar cabeceras de caché CDN (Vercel Edge Network)
// - Cachea la página en la red de Vercel por 24 horas (86400s)
// - Sirve contenido antiguo en background mientras revalida por 1 hora (3600s)
Astro.response.headers.set(
  'Cache-Control',
  'public, max-age=0, s-maxage=86400, stale-while-revalidate=3600'
);

const reviews = await getPlacesReviews(GOOGLE_PLACES_API_KEY, GOOGLE_PLACE_ID, {
  timeout: 4000,
  fallback: {
    rating: 5.0,
    count: 20
  }
});
---

<div class="reviews-badge">
  <strong>Google Reviews</strong>
  <span>⭐ {reviews.rating.toFixed(1)} / 5 ({reviews.count} reseñas)</span>
  {reviews.isFallback && <small class="offline">(offline)</small>}
</div>

📝 Licencia

ISC