{"id":21700405,"url":"https://github.com/articulate/speedtrap","last_synced_at":"2026-04-16T00:32:48.477Z","repository":{"id":47152875,"uuid":"282311365","full_name":"articulate/speedtrap","owner":"articulate","description":null,"archived":false,"fork":false,"pushed_at":"2023-09-27T14:00:39.000Z","size":76,"stargazers_count":0,"open_issues_count":0,"forks_count":3,"subscribers_count":52,"default_branch":"main","last_synced_at":"2025-08-24T10:59:43.803Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/articulate.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-24T20:35:33.000Z","updated_at":"2023-09-27T13:58:40.000Z","dependencies_parsed_at":"2025-03-20T15:43:13.838Z","dependency_job_id":null,"html_url":"https://github.com/articulate/speedtrap","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/articulate/speedtrap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/articulate%2Fspeedtrap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/articulate%2Fspeedtrap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/articulate%2Fspeedtrap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/articulate%2Fspeedtrap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/articulate","download_url":"https://codeload.github.com/articulate/speedtrap/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/articulate%2Fspeedtrap/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31866346,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-15T15:24:51.572Z","status":"ssl_error","status_checked_at":"2026-04-15T15:24:39.138Z","response_time":63,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-25T20:14:14.046Z","updated_at":"2026-04-16T00:32:48.453Z","avatar_url":"https://github.com/articulate.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# :police_car: SpeedTrap\n\nTired of blowing 3rd party API rate limits? Does your 3rd party API keep counting requests even when it returns a 429? Does your app run in a distributed environment? Does your app have a \"heavy foot\"?? Then this library is for you! SpeedTrap is a tool that uses redis to keep track of your speed. Just `run()` the SpeedTrap with your function and parameters, and get a `Promise` back with your result. But watch your speed! If you go too fast, the SpeedTrap Will catch you and ticket you with a rejected `Promise`. You wont be running anywhere.\n\n## Config options\n\n| Name | Type   | Description | Default |\n| ---- | ------ | ----------- | ------- |\n| duration | Integer | the duration of the sliding window for speed calculation |  |\n| letOffWithAWarning | Boolean | when `true` will allow your function to still run when the speed limit is exceeded | false |\n| name | String | the unique name of your SpeedTrap used to create redis keys |  |\n| onExceeded | Function | an optional function that will be called when the speed limit is exceeded | noop |\n| max | Integer | the number off allowed calls per sliding duration window |  |\n| redis | [redis client](https://www.npmjs.com/package/ioredis) | the redis client to be used for tracking the rate | |\n\n## Usage\n\nCreate the SpeedTrap with your options object. Then when you are ready, call `speedTrap.run()` with your function and parameters\n\n```js\nconst { SpeedTrap } = require('@articulate/speedtrap')\nconst RedisClient = require('ioredis')\n\nconst redisClient = new RedisClient('my-redis-url')\n\nfunction onRateLimitExceeded(info) {\n  const {\n    waitTime // The time (ms) until a run can be made again\n  } = info\n\n  console.info(`Speed limit exceeded, must wait at least ${waitTime}ms`)\n}\n\nconst config = {\n  name: 'my-speed-trap',\n  duration: 2000,\n  max: 200,\n  onExceeded: onRateLimitExceeded,\n  redis: redisClient,\n}\n\nconst speedTrap = new SpeedTrap(config)\n\nfunction makeApiCall(param1, param2) {\n  return /* a call to a crummy rate limited 3rd party marketing api */\n}\n\nspeedTrap.run(myApiCall, param1, param2)\n  .then(doOtherThings)\n  .catch((error) =\u003e {\n    if (error.isSpeedTrap) {\n      // We were going too fast!! API call was not made. Maybe we sleep and retry?\n      console.log(`got ticketed, gonna have to wait ${error.waitTime}ms`)\n    } else {\n      throw error // not from speeding...\n    }\n  })\n```\n\n## Let off with a warning\n\nWant to be let off with a warning? Better hope you get a nice officer. The `letOffWithAWarning` configuration option will allow your function to continue running, but rest assured a warning will still be issued to the handler you provided for the `onExceeded` option.\n\n## Contributing\n\nIf you have Docker Compose installed, you can run lint and tests with:\n\n```bash\ndocker compose run --rm test\n```\n\nRun tests in watch mode with:\n\n```bash\ndocker compose run --rm test yarn test --watchAll\n```\n\nYou can also run without Docker Compose by setting a `REDIS_URL` environment variable.\n\n```bash\nREDIS_URL=redis://localhost:6379 yarn test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farticulate%2Fspeedtrap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farticulate%2Fspeedtrap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farticulate%2Fspeedtrap/lists"}