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

@sarfarajey/gcp-edge-auth

v1.0.0

Published

Google Cloud service account auth for edge runtimes — JWT, OAuth2 access tokens, Cloud Run ID tokens, Firestore REST. Zero dependencies, Web Crypto only.

Readme

@sarfarajey/gcp-edge-auth

Google Cloud service account authentication for edge runtimes. Zero dependencies — uses only Web Crypto, so it runs anywhere crypto.subtle is available:

  • Cloudflare Workers
  • Vercel Edge Functions
  • Deno / Bun
  • Node.js 18+

Solves the recurring problem that the official google-auth-library ships Node-only crypto and won't run in V8 isolate / edge runtimes.

Install

npm install @sarfarajey/gcp-edge-auth

OAuth2 access token

import { getServiceAccountToken } from '@sarfarajey/gcp-edge-auth';

const token = await getServiceAccountToken(env.SERVICE_ACCOUNT_JSON);
if (!token) return new Response('auth failed', { status: 500 });

const res = await fetch('https://aiplatform.googleapis.com/v1/...', {
    headers: { Authorization: `Bearer ${token}` },
});

Tokens are cached by ${client_email}:${scope} and reused while >5 minutes of life remain. Pass cache: false to opt out, or supply your own Map-like store for cross-request caching in cold-start environments:

const myCache = new Map(); // or a KV/Redis adapter exposing get(k)/set(k,v)
const token = await getServiceAccountToken(saJson, { cache: myCache });

Custom scope:

const token = await getServiceAccountToken(saJson, {
    scope: 'https://www.googleapis.com/auth/datastore',
});

Cloud Run ID token (service-to-service)

import { getCloudRunIdToken } from '@sarfarajey/gcp-edge-auth';

const idToken = await getCloudRunIdToken(saJson, 'https://my-svc-abc-uc.a.run.app');
const res = await fetch('https://my-svc-abc-uc.a.run.app/api', {
    headers: { Authorization: `Bearer ${idToken}` },
});

Firestore REST helpers

Imported separately so you only pay for what you use:

import { getServiceAccountToken } from '@sarfarajey/gcp-edge-auth';
import {
    firestoreBase,
    fsGet,
    fsCreate,
    fsPatch,
    fsUpdate,
    fsRunQuery,
} from '@sarfarajey/gcp-edge-auth/firestore';

const token = await getServiceAccountToken(saJson);
const base = firestoreBase('my-project');

// Read
const doc = await fsGet(`${base}/users/alice`, token);

// Upsert (no mask)
await fsCreate(`${base}/users/alice`, {
    email: { stringValue: '[email protected]' },
    role:  { stringValue: 'admin' },
}, token);

// Partial update — derives mask from keys
await fsUpdate(`${base}/users/alice`, {
    role: { stringValue: 'viewer' },
}, token);

// Explicit mask
await fsPatch(`${base}/users/alice`, fields, ['email', 'role'], token);

// Query
const docs = await fsRunQuery(base, {
    from: [{ collectionId: 'users' }],
    where: {
        fieldFilter: {
            field:  { fieldPath: 'role' },
            op:     'EQUAL',
            value:  { stringValue: 'admin' },
        },
    },
}, token);

Error handling

All functions return null / false / [] on failure rather than throwing. This matches edge-runtime ergonomics where you usually want a graceful 500 rather than an unhandled rejection. Inspect the returned value and decide how to handle the auth failure in your handler.

License

MIT