New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@twitter-api-v2/plugin-rate-limit

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@twitter-api-v2/plugin-rate-limit

Rate limit plugin for twitter-api-v2

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.5K
increased by10.37%
Maintainers
1
Weekly downloads
 
Created
Source

@twitter-api-v2/plugin-rate-limit

Rate limit plugin for twitter-api-v2

Base plugin to handle rate limit storage. Can be extended with custom stores. By default, rate limits are stored into process memory.

Usage

import { TwitterApi } from 'twitter-api-v2'
import { TwitterApiRateLimitPlugin } from '@twitter-api-v2/plugin-rate-limit'

const rateLimitPlugin = new TwitterApiRateLimitPlugin()
const client = new TwitterApi(yourKeys, { plugins: [rateLimitPlugin] })

// ...make requests...
await client.v2.me()

const currentRateLimitForMe = await rateLimitPlugin.v2.getRateLimit('users/me')
console.log(currentRateLimitForMe.limit) // 75
console.log(currentRateLimitForMe.remaining) // 74

console.log(rateLimitPlugin.hasHitRateLimit(currentRateLimitForMe)) // false - .remaining > 0
console.log(rateLimitPlugin.isRateLimitStatusObsolete(currentRateLimitForMe)) // false - reset hasn't been hit yet

Modificators .v1/.v2/.v1.stream/.v1.upload/.v2.labs prefixes your endpoint with the good URL (like https://api.twitter.com/2 for .v2).

Create a custom store

You can create a custom store (for Redis, MongoDB, SQL...) to store your rate limit data. Store is given as the first argument of constructor of TwitterApiRateLimitPlugin.

A store is a class which implements ITwitterApiRateLimitStore.

You can find a example of store (the default one) TwitterApiRateLimitMemoryStore, here.

Keywords

FAQs

Package last updated on 19 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc