@fightmegg/riot-rate-limiter

中文文档
0.0.23发布于 2025/07/29MITTypeScriptESM + CJS近 30 天下载 2642

Rate Limiter for Riot Games API

原始使用文档
文档目录9 节
  1. Features
  2. Contents
  3. Installation
  4. Usage
  5. API
  6. Helpers
  7. Debugging
  8. Testing
  9. Maintainers

Riot Rate Limiter

Version Downloads CircleCI

Node.JS Rate Limiter for Riot Games API

Wiki

Features

Contents

Installation

$ npm install @fightmegg/riot-rate-limiter

Usage

import { RiotRateLimiter } from "@fightmegg/riot-rate-limiter";

const limiter = new RiotRateLimiter();

// async await
const response = await limiter.execute({
  url: "https://euw1.api.riotgames.com/lol/some/method",
  options: {
    headers: {
      "X-Riot-Token": "...",
    },
  },
});

// Promises
limiter
  .execute({
    url: "https://euw1.api.riotgames.com/lol/some/method",
    options: {
      headers: {
        "X-Riot-Token": "...",
      },
    },
  })
  .then((response) => {
    // ...
  });

API

constructor

new RiotRateLimiter({
  debug: boolean = false,
  concurrency: number = 1,
  retryAfterDefault: number = 5000,
  retryCount: number = 4,
  datastore: 'local' | 'ioredis' = 'local'
  redis?: RedisConnectionOptions | RedisConnectionString = null
});

.execute

This library uses node-fetch underneath the hood for making requests. The .execute method literally passes everything given to node-fetch, therefore you can change things like method, headers etc..

Any responses that are not 2xx or 429 will be thrown, and must be caught.

We will auto-retry 429 responses, up until the retryCount limit is hit (defaults to 4), utilising the Retry-After header to respect the API.

limiter.execute({
  url: RequestInfo,
  options: RequestInit,
},
  jobOptions?: Bottleneck.JobOptions
);

The second argument is optional, which allows you to specify JobOptions such as job priority and unique ID for log identification. The weight of a job cannot be changed from the value of 1 no matter what you pass in.

.rateLimiters

This is a map of all of the rate-limiters created, we create at least 1 rate-limiter for the region of the request, and then at least 1 rate-limiter per method underneath that region.

We use the library Bottleneck as our rate-limiter, which supports chaining rate-limiters, meaning that the parents rate-limiter is always respected by its children.

You can access the region rate-limiters via: limiter.rateLimiters[region].main and you can access the method rate-limiters via: limiter.rateLimiters[region][method].main

Helpers

We also provided some helper functions & objects.

extractRegion

This can extract the region or platformId from your URL:

import { extractRegion } from "@fightmegg/riot-rate-limiter";

extractRegion("https://na1.api.riotgames.com/method"); // returns na1

extractMethod

This can extract the method from your URL:

import { extractMethod } from "@fightmegg/riot-rate-limiter";

extractMethod(
  "https://na1.api.riotgames.com/lol/champion-mastery/v4/scores/by-summoner/12345"
); // returns 'CHAMPION_MASTERY.GET_CHAMPION_MASTERY_SCORE'

METHODS & HOST

For those looking to build a RiotGamesAPI library ontop of this rate limiter, we export two object called METHODS & HOST. You can use these exports to create the URLs for you, as seen below:

import { compile } from "path-to-regexp";
import { HOST, METHODS } from "@fightmegg/riot-rate-limiter";

const createHost = compile(HOST, { encode: encodeURIComponent });
const createPath = compile(METHODS.ACCOUNT.GET_BY_PUUID, {
  encode: encodeURIComponent,
});

const url = `https://${createHost({ platformId: "euw1" })}${createPath({
  puuid: "12345",
})}`;

Debugging

If you want to see want the rate-limiter is currently doing, we use the debug module for logging. Simply run your app with:

DEBUG=riotratelimiter* node ...

Testing

Unit tests: npm test

E2E tests: npm run test:e2e

Maintainers

@olliejennings

版本与发布记录

@fightmegg/riot-rate-limiter 共发布 25 个版本,首次发布于 2020/09/09;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.0.23latest2025/07/291.3 年前
0.0.222024/05/182 年前
0.0.212024/03/032 年前
0.0.202023/11/172 年前
0.0.192023/10/053 年前
0.0.182023/04/273 年前

其他发布通道:dev → 0.0.2-alpha.1。

关于 @fightmegg/riot-rate-limiter 的常见问题

@fightmegg/riot-rate-limiter 是什么?

Rate Limiter for Riot Games API

如何安装 @fightmegg/riot-rate-limiter?

在项目目录运行 npm install @fightmegg/riot-rate-limiter,或使用 pnpm add / yarn add / bun add。

@fightmegg/riot-rate-limiter 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@fightmegg/riot-rate-limiter 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@fightmegg/riot-rate-limiter 可以商用吗?

@fightmegg/riot-rate-limiter 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@fightmegg/riot-rate-limiter 的下载量有多少?

根据 npm 官方下载统计,@fightmegg/riot-rate-limiter 在 2026/10/15 – 2026/11/13 这 30 天内被下载 2,642 次,日均约 88 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@fightmegg/riot-rate-limiter 还在维护吗?

最新版本 0.0.23 发布于 2025/07/29(1.3 年前);至今共发布 25 个版本,其中过去 12 个月发布了 0 个;首次发布于 2020/09/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。