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

@mcsr-cards/ranked

v0.2.3

Published

Typed client for the MCSR Ranked API, with caching and rate limiting

Readme

@mcsr-cards/ranked

Typed client for the MCSR Ranked API.

npm install @mcsr-cards/ranked

Requires Node 18+ (uses global fetch).

Usage

import { createClient } from '@mcsr-cards/ranked';

const ranked = createClient({ apiKey: process.env.MCSR_RANKED_API_KEY });

const user = await ranked.getUser('feinberg');
const matches = await ranked.getUserMatches(user.uuid, { type: 2, count: 50 });
const leaderboard = await ranked.getLeaderboard();

An identifier is a UUID, a nickname, or discord.{id}:

await ranked.getUser('discord.843230753734918154');

The API key is optional but raises your rate limit. Generate one in game under Profile, Settings, Generate & Copy API Private Key.

You can also request a private API key for larger projects with higher rate limits on the Discord server, as of June 2026 that limit is 3000 requests per 10 minutes by default.

Rate limiting

Requests are counted against a 10 minute window and RateLimitError is thrown locally once the budget is gone, so you find out before the API starts rate limiting. The budget is always the public limit of 500 requests per 10 minutes, even when you pass an apiKey. Raising rate limits is manual, so for a regular private key it looks something like this:

createClient({ apiKey, limiter: new RateLimiter(3000, 600_000) });

mcsr.remaining() shows how many requests are left in that window.

Caching

Responses are cached in memory per URL, 5 seconds on api.mcsrranked.com and 30 seconds on mcsrranked.com/api

You can (and should) raise it manually to your needs:

createClient({ ttl: { user: 300_000, leaderboard: 60_000 } });

Setting a TTL lower than the defaults is pointless, because you'll just be requesting already cached info.

Pass your own store to cache somewhere other than memory, useful for workers or whatever:

createClient({ cache: myRedisBackedStore });

Any object with this shape works, and CacheStore is exported if you want to implement it explicitly:

interface CacheStore {
  get(key: string): unknown | Promise<unknown>;
  set(key: string, value: unknown, ttlMs: number): void | Promise<void>;
}

get and set may return promises, so a Redis or KV backed store works as-is. If the store throws, a read is treated as a miss and a write is dropped, the request still goes through.

Timeouts and retries

Requests are aborted after 10 seconds by default, and MCSRRankedTimeoutError is thrown. Set timeoutMs: 0 to disable.

Network errors and 5xx responses are retried twice with exponential backoff (250ms, 500ms). 4xx responses and RateLimitError are never retried. Set retries: 0 to disable.

createClient({ timeoutMs: 5_000, retries: 0 });

Validation

Responses are validated against the API's own OpenAPI schema (via ajv) before being returned, corrupted or unexpected fields throw MCSRRankedValidationError Set validate: false to disable.

Errors

Failures throw MCSRRankedError with status, message and the raw data.

Be aware the API answers 400 for everything for some reason, so an unknown user and a malformed request can only be told apart by the message. isMissingUser does that for you:

import { isMissingUser } from '@mcsr-cards/ranked';

try {
  await ranked.getUser('discord.123');
} catch (err) {
  if (isMissingUser(err)) {
    // no linked account
  }
  throw err;
}

Cursors

after and before take a match ID, and the API rejects anything below 1 with Too small: expected number to be >=1. The spec gives them no minimum, only count has one, so this is a server rule you cannot see in the types. Use after: 1 when you mean "everything", not 0

Types

src/schema.d.ts (types) and src/schemas.ts (validation schemas) are both generated from the spec:

npm run update-spec   # pull the latest openapi.yaml
npm run generate      # regenerate src/schema.d.ts and src/schemas.ts

The upstream spec is maintained by hand and has shipped incorrect types before, so please review the updated spec before generating. (im gonna forget)

openapi.yaml carries local patches on top of upstream. right now that's three fields typed as plain integers that the api returns null for once a season rolls over and nobody has placed yet:

  • SeasonStanding.eloRate
  • SeasonResultDetailed.highest
  • SeasonResultDetailed.lowest

update-spec overwrites the file wholesale, so it checks for these afterwards and tells you which ones to re-apply. the list lives in LOCAL_PATCHES in scripts/update-spec.mjs, delete an entry once upstream takes it.

src/schema.d.ts gets biome formatted after generating, src/schemas.ts does not.

I'm an idiot. Please validate anything you depend on.

License

MIT