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

garmin-auth

v0.8.1

Published

Self-healing Garmin Connect OAuth (TypeScript) — token stores, rate limiting, DI auth. TS twin of the Python garmin-auth.

Readme

garmin-auth

Garmin Connect authentication and API access in TypeScript, with the parsers for what Garmin returns. It keeps a Garmin DI token pair in a token store, refreshes it when it expires, and gives you a client for Garmin Connect's API.

npm install garmin-auth

pg is needed only for the database token store (npm install pg).

Signing in

Garmin blocks its own sign-in from most cloud IPs, so a fresh login (email, password and the second factor) goes through a small Cloudflare Worker, which is in this repository's worker/ folder. createSsoWorkerClient talks to it, and tokensFromResult turns its answer into tokens you can save in a store.

A self-hosted server on a home connection is usually not blocked, and can run the same Worker code in its own process instead, so the password and code go only to Garmin. garmin-auth/sso-local gives you that client; it has the same login, loginMfa and exchange as the Worker client.

import { createLocalSsoClient } from "garmin-auth/sso-local";
import { tokensFromResult } from "garmin-auth/sso-worker";

const sso = createLocalSsoClient(); // keep one per process: it holds a pending MFA step
const r = await sso.login(email, password); // or "needs_mfa", then sso.loginMfa(r.session_id!, code)
const tokens = tokensFromResult(r); // save these in a store

Pending MFA steps live in memory, so the second step has to reach the same process as the first: a long-running server, not a serverless function.

After that the package works from the saved tokens. GarminAuth loads them, refreshes the DI token when it expires, saves the new tokens after every refresh (Garmin rotates the refresh token each time, so an unsaved one stops working), and gives you a client.

import { GarminAuth, DBTokenStore, FileTokenStore } from "garmin-auth";

// Tokens in a Postgres table (platform_credentials), or in a folder on disk.
const auth = new GarminAuth({ store: new DBTokenStore(process.env.DATABASE_URL!) });
// const auth = new GarminAuth({ store: new FileTokenStore("~/.garmin-auth") });

const client = await auth.client(); // throws GarminAuthenticationError if a fresh login is needed
const profile = await client.connectapi("/userprofile-service/socialProfile");

await auth.status(); // what the store holds, without calling Garmin
await auth.refresh(); // refresh the DI token now

auth.login() returns "needs_mfa" instead of throwing when the saved tokens cannot be used, so a web app can send the user to its sign-in page.

The client has connectapi (GET), post, put, delete, postForm and getBytes, each taking a Connect API path. A 401 refreshes the token once and retries.

Garmin data

The package also carries the parsers for Garmin Connect's payloads, so every app reads them the same way.

  • endpoints: the daily, range, activity-detail and discovery request catalogue, and buildRequest.
  • health-parsers: parseDailyHealth, parseWeightEntries, parseSleep, parseHrv, parseTrainingReadiness.
  • lap-parser: parseStructuredLaps, parseUnstructuredLaps.
  • activity-routes: deriveRouteSamples, thinSamples.

Each is also a subpath export (for example garmin-auth/health-parsers), so code that only parses does not load the token store or pg.

More

The Python package of the same name is deprecated, with an end date of 2026-10-31. Changes are listed in the CHANGELOG. MIT licensed.