Skip to content
On this page

TypeScript SDK

Authenticate with TrainHeroic and call the runtime-agnostic TypeScript client.

@trainheroic-unofficial/js provides the client, auth renewal, exercise library, workout builder, athlete reads, analytics, and messaging helpers.

Install

npm install @trainheroic-unofficial/js
pnpm add @trainheroic-unofficial/js
yarn add @trainheroic-unofficial/js
bun add @trainheroic-unofficial/js

Requires global fetch and Web Crypto: Node 18+, Cloudflare workerd, or a modern browser.

Create a client

import { TrainHeroicClient } from "@trainheroic-unofficial/js";

const client = new TrainHeroicClient(
  process.env.TRAINHEROIC_EMAIL!,
  process.env.TRAINHEROIC_PASSWORD!,
);

const response = await client.request<{ id: number }>("GET", "/user/simple");
if (response.ok) {
  console.log(response.data.id);
}

The client signs in lazily on the first request. If a request returns 401 or 403, it signs in again once and retries. Concurrent requests on a cold client share one login.

Two entry points

import { TrainHeroicClient, ExerciseLibrary, buildSession } from "@trainheroic-unofficial/js";
import { JsonFileLibraryCache, defaultCachePath } from "@trainheroic-unofficial/js/node";

The main entry imports no node:* modules. Filesystem-backed caching stays behind ./node so the same SDK can run inside Cloudflare Workers.

Guides

Was this page helpful?