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

cds-rate-limit

v0.0.6

Published

enabled rate limit pattern for CAP NodeJS Runtime

Readme

CDS Rate Limit

apply rate limit pattern to CAP nodejs application

npm node-test codecov

Quality Gate Status Security Rating Vulnerabilities

Get Started

package.json

{
  "cds": {
    "plugins": ["cds-rate-limit"]
  }
}

cds definition

using {cuid, managed} from '@sap/cds/common';
@path : '/sample3'
service Sample3Service {

  // define rate limit for entity CRUD events and actions
  // accepts 1000 requests in 120 seconds
  // other requests will be rejected by HTTP 429 status
  @cds.rate.limit : {
    duration : 120,
    points   : 1000,
  }
  entity People : cuid, managed {
    Name : String(255);
    Age  : Integer;
  }

  // share global quota
  entity Other: cuid, managed {
    Name : String(255);
  }
}

Headers

  • Retry-After - reset after seconds later
  • X-RateLimit-Reset - reset timestamp (unix timestamp)
  • X-RateLimit-Limit - total quota for each window
  • X-RateLimit-Remaining - remaining quota for current window

RateLimiter Hierarchy

the RateLimiter configuration will apply restriction by order, if you do not annotate @cds.rate.limit on entity/action/function level, it will share the quota of the global RateLimiter

  1. Event/Action/Function
  2. Entity
  3. Service
  4. Global

Options

  • keyParts: use to generated the key
    • remote_ip - req._.req.ip - please ref express document to setup trust proxy
    • user_id - ctx.user.id
    • tenant - ctx.tenant
  • points: quota for each key (user, ip, tenant or combined)
  • duration: quota for each key in duration (reset duration for quota)

Default Global Options

if there is no annotation on CDS Service/Entity/Action/Function, it will use the global configuration

{
  impl: "memory", // use in-memory
  keyParts: ["tenant"], // generate key from tenant
  keyPrefix: GLOBAL_RATE_LIMITER_PREFIX, // default prefix
  duration: 60, // 60 seconds
  points: 200 * 60, // 200 requests per seconds

  // for anonymous requests (without authorization header)
  anonymous: {
    // per seconds per remote ip allow 1000 requests
    keyPrefix: GLOBAL_ANONYMOUS_RATE_LIMITER_PREFIX,
    duration: 10,
    points: 10 * 100,
  },
}

Example - Memory

configuration global default configuration, each user could call API 6000 times in 1 minute duration

{
  "cds": {
    "plugins": ["cds-rate-limit"],
    "config": {
      "rateLimit": {
        "impl": "memory",
        "duration": 60,
        "points": 6000,
        "keyParts": ["user_id"]
      }
    }
  }
}

Example - Redis

each user in each tenant could use the API 300 times in 5 seconds duration

{
  "cds": {
    "plugins": [
      "cds-rate-limit"
    ],
    "config": {
      "rateLimit": {
        "impl": "redis",
        "duration": 5,
        "points": 300,
        "keyParts": ["tenant", "user_id"],
        "redisOptions": {
          "enableOfflineQueue": false
        }
      }
    }
  }
}

Features

  • [x] Global Rate Limit
  • [x] Event Rate Limit
    • [x] Inner event ignore
  • [x] Anonymous Request Rate Limit
  • [x] Custom key
  • [ ] Global Env Configuration
  • [x] Redis store
  • [ ] Dynamic quota configuration
  • [ ] Sampling store to reduce remote store network consumption

ToDo

  • [x] How to process anonymous requests
  • [ ] Documents for microservice
  • [ ] Performance

CHANGELOG

LICENSE