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

strava-sdk

v0.1.5

Published

TypeScript SDK for Strava API with OAuth, webhooks, and rate limiting

Readme

Strava SDK

TypeScript SDK for Strava API with OAuth, webhooks, and rate limiting.

Features

  • Complete OAuth Flow: Authorization URL generation and token exchange
  • Rate Limiting: Built-in Bottleneck integration respecting Strava's limits (200/15min, 2000/day)
  • Token Management: Automatic token refresh with configurable expiry buffer
  • Webhook Support: Full webhook subscription management and event handling
  • Type-Safe: Full TypeScript support with comprehensive type definitions
  • Storage Agnostic: Bring your own database via simple interface
  • Framework Integrations: Express middleware
  • Error Handling: Detailed error classification and retry logic

Installation

npm install strava-sdk

Quick Start

import { StravaClient, MemoryStorage } from "strava-sdk";

const strava = new StravaClient({
  clientId: process.env.STRAVA_CLIENT_ID!,
  clientSecret: process.env.STRAVA_CLIENT_SECRET!,
  redirectUri: "http://localhost:3000/auth/callback",
  storage: new MemoryStorage(), // Use your own storage implementation
});

// Generate OAuth URL
const authUrl = strava.oauth.getAuthUrl({
  scopes: ["activity:read_all", "activity:write"],
});

// Exchange code for tokens
const tokens = await strava.oauth.exchangeCode(code);

// Save tokens
await strava.storage.saveTokens(tokens.athlete.id.toString(), {
  athleteId: tokens.athlete.id.toString(),
  accessToken: tokens.access_token,
  refreshToken: tokens.refresh_token,
  expiresAt: new Date(tokens.expires_at * 1000),
});

// Get activity (with automatic token refresh)
const activity = await strava.getActivityWithRefresh("12345", athleteId);

// Update activity
await strava.updateActivityWithRefresh("12345", athleteId, {
  description: "Amazing ride!",
});

Express Integration

import express from "express";
import { createExpressHandlers } from "strava-sdk";

const app = express();
const handlers = createExpressHandlers(strava, "webhook-verify-token");

// OAuth routes
app.get("/auth/strava", handlers.oauth.authorize());
app.get(
  "/auth/callback",
  handlers.oauth.callback({
    onSuccess: async (req, res, tokens) => {
      // Save tokens and redirect
      res.redirect("/dashboard");
    },
    onError: (req, res, error) => {
      res.status(500).send("Auth failed");
    },
  }),
);

// Webhook routes
app.get("/api/webhook", handlers.webhooks.verify());
app.post("/api/webhook", handlers.webhooks.events());

// Handle webhook events
strava.webhooks.onActivityCreate(async (event, athleteId) => {
  console.log(`New activity: ${event.object_id}`);
});

Webhook Events

strava.webhooks.onActivityCreate(async (event, athleteId) => {
  // Handle new activity
});

strava.webhooks.onActivityUpdate(async (event, athleteId) => {
  // Handle activity update
});

strava.webhooks.onActivityDelete(async (event, athleteId) => {
  // Handle activity deletion
});

strava.webhooks.onAthleteDeauthorize(async (event, athleteId) => {
  // Clean up athlete data
  await strava.storage.deleteTokens(athleteId.toString());
});

Implementing Storage

For production, implement TokenStorage with your database:

import { TokenStorage, StoredTokens } from "strava-sdk";

class YourDatabaseStorage implements TokenStorage {
  async getTokens(athleteId: string): Promise<StoredTokens | null> {
    // Fetch from your database
  }

  async saveTokens(athleteId: string, tokens: StoredTokens): Promise<void> {
    // Save to your database
  }

  async deleteTokens(athleteId: string): Promise<void> {
    // Delete from your database
  }
}

See Storage Guide for complete examples with PostgreSQL, MongoDB, and Redis.

Documentation

Examples

Check out the examples directory for complete applications:

  • basic-app - Minimal Express app with OAuth and webhooks

Requirements

  • Node.js 18 or higher
  • TypeScript 5.0 or higher (for TypeScript projects)

Contributing

Contributions are welcome! Please open an issue or pull request.

License

MIT