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

@dofek/trainerroad

v0.1.4

Published

Unofficial TrainerRoad API client using reverse-engineered cookie-based authentication

Downloads

333

Readme

@dofek/trainerroad

Unofficial TypeScript client for private TrainerRoad web endpoints. It signs in through the observed HTML form flow and retrieves member information, activities, and career data.

This package is not affiliated with, endorsed by, or supported by TrainerRoad. Its authentication page and undocumented endpoints may change without notice.

Requirements and installation

Requires Node.js 22.14 or newer and its built-in fetch implementation.

npm install @dofek/trainerroad

Quick start

Save this as example.mjs, set TRAINERROAD_USERNAME and TRAINERROAD_PASSWORD, then run node example.mjs.

import { TrainerRoadClient } from "@dofek/trainerroad";

const login = process.env.TRAINERROAD_USERNAME;
const password = process.env.TRAINERROAD_PASSWORD;
if (!login || !password) {
  throw new Error("Set TRAINERROAD_USERNAME and TRAINERROAD_PASSWORD");
}

const { authCookie, username } = await TrainerRoadClient.signIn(
  login,
  password,
);
const client = new TrainerRoadClient(authCookie);
const activities = await client.getActivities(
  username,
  "2026-07-01",
  "2026-07-07",
);

console.log(activities);

Dates passed to getActivities use YYYY-MM-DD.

Public API

  • TrainerRoadClient.signIn(username, password, fetch?) returns the observed SharedTrainerRoadAuth cookie value and canonical account username.
  • new TrainerRoadClient(authCookie, fetch?) creates a session-backed client.
  • client.getMemberInfo() retrieves the current member's ID and username.
  • client.getActivities(username, startDate, endDate) retrieves scheduled and completed calendar activities.
  • client.getCareer(username) retrieves career data such as FTP and weight.

Supported deep imports:

  • @dofek/trainerroad/client — client class.
  • @dofek/trainerroad/parsing — activity type mapping and parseTrainerRoadActivity.
  • @dofek/trainerroad/types — raw member, activity, and career interfaces.
import { parseTrainerRoadActivity } from "@dofek/trainerroad/parsing";
import type { TrainerRoadActivity } from "@dofek/trainerroad/types";

Authentication and persistence

The current implementation loads /app/login, extracts the __RequestVerificationToken CSRF field and initial cookies, submits the login form, and returns the SharedTrainerRoadAuth cookie set by the response. It does not use embedded application credentials.

Treat authCookie as a password-equivalent session secret and keep it in encrypted storage. The package cannot inspect its expiry and has no cookie refresh endpoint. If an authenticated request begins failing, call signIn again and replace the stored cookie. Never log or commit the cookie or account password.

Rate limits and errors

The shared rate-limit wrapper throws ProviderRateLimitError for 429 and ProviderServiceUnavailableError for 502, 503, and 504. Both expose providerId, statusCode, responseBody, and retryAfterSeconds. The latter follows the HTTP Retry-After header when present. Other unsuccessful API responses throw a regular Error; a failed login without the expected session cookie also throws Error.

If your application handles these error classes directly, declare @dofek/provider-http as a direct dependency:

npm install @dofek/provider-http
import {
  ProviderRateLimitError,
  ProviderServiceUnavailableError,
} from "@dofek/provider-http/rate-limit";

try {
  await client.getCareer(username);
} catch (error) {
  if (
    error instanceof ProviderRateLimitError ||
    error instanceof ProviderServiceUnavailableError
  ) {
    console.error(error.providerId, error.statusCode, error.retryAfterSeconds);
  }
  throw error;
}

Parsing behavior

parseTrainerRoadActivity maps the currently observed activity names and IsOutside flag to canonical activity types. It treats CompletedDate as the end time and derives the start by subtracting Duration.

Project