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

@api-buddy/firebase-utils

v1.0.0

Published

Shared Firebase utilities for API Buddy plugins

Readme

@api-buddy/firebase-utils

Shared Firebase utilities for API Buddy plugins, providing consistent Firebase initialization, emulator support, and error handling.

Features

  • 🔥 Firebase Admin & Client Initialization - Simple and consistent initialization of Firebase Admin and Client SDKs
  • 🧪 Emulator Support - Built-in support for Firebase emulators with automatic configuration
  • 🛡️ Type Safety - Full TypeScript support with comprehensive type definitions
  • 🚦 Error Handling - Consistent error handling with custom error types and utilities
  • 🔍 Validation - Runtime validation for Firebase configurations
  • 🔌 Modular - Import only what you need to keep your bundle size small

Installation

# Using pnpm (recommended)
pnpm add @api-buddy/firebase-utils firebase firebase-admin

# Using npm
npm install @api-buddy/firebase-utils firebase firebase-admin

# Using yarn
yarn add @api-buddy/firebase-utils firebase firebase-admin

Usage

Basic Initialization

import {
  initializeFirebaseAdmin,
  initializeFirebaseClient,
  validateFirebaseConfig,
} from '@api-buddy/firebase-utils';

// Define your Firebase configuration
const config = {
  projectId: 'your-project-id',
  useEmulators: process.env.NODE_ENV === 'development',
  emulatorHosts: {
    auth: 'localhost:9099',
    firestore: 'localhost:8080',
    // ... other emulator hosts
  },
  clientConfig: {
    apiKey: 'your-api-key',
    authDomain: 'your-project-id.firebaseapp.com',
    projectId: 'your-project-id',
    // ... other Firebase config
  },
};

// Validate configuration
const validatedConfig = validateFirebaseConfig(config);

// Initialize Firebase Admin
const { adminApp, adminAuth, firestore } = await initializeFirebaseAdmin(validatedConfig);

// Initialize Firebase Client (browser)
const { app, auth, firestore: clientFirestore } = await initializeFirebaseClient(validatedConfig);

Error Handling

import { ERROR_CODES, isFirebaseUtilsError } from '@api-buddy/firebase-utils';

try {
  // Your Firebase operations
} catch (error) {
  if (isFirebaseUtilsError(error)) {
    console.error(`Firebase error (${error.code}):`, error.message);
    
    if (error.code === ERROR_CODES.ADMIN_INIT_FAILED) {
      // Handle specific error
    }
  } else {
    console.error('Unexpected error:', error);
  }
}

Emulator Configuration

import { getDefaultEmulatorHosts } from '@api-buddy/firebase-utils';

// Get default emulator hosts
const emulatorHosts = getDefaultEmulatorHosts();
// {
//   auth: 'localhost:9099',
//   firestore: 'localhost:8080',
//   database: 'localhost:9000',
//   storage: 'localhost:9199',
//   functions: 'localhost:5001'
// }

// Use with your config
const config = {
  projectId: 'your-project-id',
  useEmulators: true,
  emulatorHosts: {
    ...emulatorHosts,
    // Override specific hosts if needed
    auth: 'localhost:9999',
  },
};

API Reference

Functions

initializeFirebaseAdmin(config: FirebaseUtilsConfig): Promise<FirebaseAdminInstances>

Initializes the Firebase Admin SDK with the provided configuration.

initializeFirebaseClient(config: FirebaseUtilsConfig): Promise<FirebaseClientInstances>

Initializes the Firebase Client SDK with the provided configuration.

validateFirebaseConfig(config: unknown): FirebaseUtilsConfig

Validates the Firebase configuration object against the expected schema.

getDefaultEmulatorHosts(): Record<string, string>

Returns the default emulator host configuration.

Error Handling

FirebaseUtilsError

Custom error class for Firebase-related errors.

ERROR_CODES

Enum of possible error codes.

isFirebaseUtilsError(error: unknown): error is FirebaseUtilsError

Type guard to check if an error is a FirebaseUtilsError.

License

MIT