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

observoo

v2.1.1

Published

SDK oficial do Observoo para envio de logs em aplicações Node.js

Downloads

23

Readme

Observoo SDK

SDK oficial do Observoo para envio de logs em aplicações Node.js.

Instalação

npm install observoo

Configuração

import { Observoo } from 'observoo';

const observoo = new Observoo({
  projectId: 'seu-project-id',
  apiKey: 'seu-api-key',
  timeout: 10000, // opcional, padrão: 10000ms
  retries: 3, // opcional, padrão: 3
  retryDelay: 1000, // opcional, padrão: 1000ms
});

Uso Básico

s de conversão

// Rastrear compra
const result = await observoo.purchase('order-123', 99.9, 'BRL', {
  productId: 'prod-456',
  category: 'electronics',
});

// Rastrear cadastro
const result = await observoo.signup('email', {
  plan: 'premium',
});

// Rastrear login
const result = await observoo.signin('google', {
  userId: 'user-123',
});

Enviar eventos de erro

// Rastrear erro
await observoo.error('API timeout', 'Error: Request timeout at fetch...', {
  type: 'ERROR',
  ...
});

Configuração Avançada

Definir opções padrão

// Configurar opções que serão usadas em todos os eventos
observoo.setDefaultOptions({
  url: 'https://meusite.com',
  userAgent: 'MyApp/1.0',
  visitorId: 'visitor-123',
});

Exemplos Práticos

Next.js API Route

// pages/api/track.ts
import { NextApiRequest, NextApiResponse } from 'next';
import { Observoo } from 'observoo';

const observoo = new Observoo({
  projectId: process.env.OBSERVOO_PROJECT_ID!,
  apiKey: process.env.OBSERVOO_API_KEY,
});

export default async function handler(
  req: NextApiRequest,
  res: NextApiResponse
) {
  if (req.method !== 'POST') {
    return res.status(405).json({ error: 'Method not allowed' });
  }

  const { event, data, url, referrer } = req.body;

  try {
    const result = await observoo.serverAction('create_checkout_session', {
      type: 'SERVER_ACTION',
      method: 'CREATE',
      statusText: 'success',
      message: 'success',
      data: {
        email: email,
        userAgent: req.headers['user-agent'],
      },
    });

    res.status(200).json(result);
  } catch (error) {
    res.status(500).json({ error: 'Internal server error' });
  }
}

Error Tracking

// Middleware para capturar erros
app.use(
  (
    error: Error,
    req: express.Request,
    res: express.Response,
    next: express.NextFunction
  ) => {
    observoo
      .error(error.message, error.stack, {
        type: 'ERROR',
        method: 'CREATE',
        statusText: 'error',
        path: req.url,
        data: {
          userAgent: req.get('user-agent'),
        },
      })
      .catch(console.error);

    next(error);
  }
);

Tipos TypeScript

O SDK inclui tipos TypeScript completos:

import {
  ObservooConfig,
  ObservooOptions,
  TrackEvent,
  EventData,
  TrackResponse,
} from 'observoo';

// Use os tipos para melhor tipagem
const config: ObservooConfig = {
  projectId: 'seu-project-id',
  apiKey: 'seu-api-key',
};

const options: ObservooOptions = {
  url: 'https://meusite.com',
  visitorId: 'visitor-123',
};

Tratamento de Erros

O SDK inclui retry automático e tratamento de erros robusto:

const result = await observoo.track('custom');

if (!result.success) {
  console.error('Erro ao enviar evento:', result.error);
  console.error('Detalhes:', result.details);
} else {
  console.log(
    `Evento enviado com sucesso. ${result.count} eventos processados.`
  );
}

Configuração de Ambiente

# .env
OBSERVOO_PROJECT_ID=seu-project-id
OBSERVOO_API_KEY=api_key

Licença

MIT