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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sharks-interactive/workers-firebase-rtdb-rest-client

v1.1.0

Published

Firebase RTDB Client for CloudFlare Workers.

Downloads

9

Readme

Workers Firebase RTDB Client

Workers Firebase RTDB is a Firebase Realtime Database client library for use specifically with Cloudflare Workers written in TypeScript.

Functionality

  • Easily create, edit, update, and delete json from your database
  • Easy authentication with your database and its rules
  • Supports conditional requests/ETag's
  • Follows Workers guidelines, such as not mutating global state
  • Thorough documentation and easy to understand functions

Usage:

npm i --save @sharks-interactive/workers-firebase-rtdb-rest-client

Quick Examples:

Writing Data

import Database from '@sharks-interactive/workers-firebase-rtdb';

addEventListener('fetch', (event) => {
  const db = new Database({
    databaseUrl: 'https://example-db-default-rtdb.firebaseio.com/',
    authentication: 'bearer ya29.[YOUR-OAUTH-TOKEN-HERE]',
    tokenAuthentication: true,
  });
  event.respondWith(async () => {
    const success = await db.update(
        'user/settings',
        JSON.stringify({theme: 'dark'}),
        true,
        new Headers(), // Optional
    );

    if (success) return new Response('Ok', {status: 200, statusText: 'OK'});
    else return new Response('Something went wrong', {status: 500, statusText: 'Internal Server Error'});
  });
});

Reading Data

import Database from '@sharks-interactive/workers-firebase-rtdb';

addEventListener('fetch', (event) => {
  const db = new Database({
    databaseUrl: 'https://example-db-default-rtdb.firebaseio.com/',
    authentication: 'bearer ya29.[YOUR-OAUTH-TOKEN-HERE]',
    tokenAuthentication: true,
  });
  event.respondWith(async () => {
    const response = await db.read(
        'user/settings',
        true,
        new Headers(), // Optional
    );

    if (response != '') return new Response(response, {status: 200, statusText: 'OK'});
    else return new Response('Something went wrong', {status: 500, statusText: 'Internal Server Error'});
  });
});

Features:

  • .update() updates data with a PATCH request
  • .push() pushes data with a POST request
  • .write() writes data with a PUT request
  • .read() reads data with a GET request
  • .delete() deletes data with a DELETE request
  • .appendGetEtagHeader() appends to a list of headers the header required to get the ETag of data in the database
  • .appendEtagIfHeader() appends to a list of headers the header required to submit a conditional ETag request to the database
  • tokenAuthentication supports OAUTH token authentication as well as Firebase ID authentication

Options (Required)

| Option | Type | Description | | ------ | ---- | ----------- | | databaseUrl | string | A string containing the base URL of your database. It SHOULD end in a / and it MUST start with https://. See: https://firebase.google.com/docs/database/rest/start | | authentication | string | Your authentication information. This should be a OAUTH token if tokenAuthentication is true, and an ID token if if is false. See: https://firebase.google.com/docs/database/rest/auth | | tokenAuthentication | boolean | Whether the authentication string is an OAUTH token or Firebase ID. See: https://firebase.google.com/docs/database/rest/auth

How it works:

This client library is a simplified layer between your code and the Firebase REST API. In the background it uses the Workers FETCH API to send HTTP requests to your Database.

Read the wiki for extra documentation.

Project created and maintained by Sharks Interactive.

Developing:

  • Commit to staging and pr to prod for changes

Code Style:

  • Continious Integration will handle formatting for you
  • Use ESLINT locally to catch errors pre-pr

Acknowledgements:

README.MD and general SDK structure, styling, practices etc, modelled after and taken from the excellent Toucan-JS