{"name":"@octokit/plugin-throttling","version":"2.7.1","author":{"url":"http://github.com/SGrondin","name":"Simon Grondin"},"license":"MIT","_id":"@octokit/plugin-throttling@2.7.1","homepage":"https://github.com/octokit/plugin-throttling.js#readme","bugs":{"url":"https://github.com/octokit/plugin-throttling.js/issues"},"dist":{"shasum":"9cff29fdac4ac110b854587652f37e6cc39d76ac","tarball":"http://registry-npm.ywwl.com/@octokit/plugin-throttling/download/@octokit/plugin-throttling-2.7.1.tgz","fileCount":20,"integrity":"sha512-08CKNFCpSpmOEAQBn6/MR8zbJgjP4+bplNUJbKlqJSNBHTO1NdsDHzBD4VeFYopOo7rBEySng4WifxNVaQ5bVw==","signatures":[{"sig":"MEUCIQDeLY8M8+q8SmSM+VEszpBDb5zXDgddrl+qomSofndY5wIgZygnrCSV5FjT/vD3JX3+729PjNsbX3I1W/6Ok7661p4=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":94638,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJd+90cCRA9TVsSAnZWagAAKq8QAI/MMPmBjtEFDwHrt+4a\nIJj+1h2mToSZtf9ZyZeraXbNmYvMPW67Mwgty3uMQ2YXkxJQYRwopYNFvbjJ\nWfaSyTmqhujkqOB5BsIQrtaYmwr60ZJPa1/b08RZpqfxmxmC6AX+JTDzqFkc\ntn2THYlVTqaDsVc4Bct5TJ9pXh5+dunsn+EDA2xKTWE+F0haGAH90JjzbHQF\nhrSz7uoU3hYh+l2d0PYpkJ1jd3bfZj8IoyZuybfQ7JIvM2TUMf263xTDQ/5K\nVL8CSoyIvGkJ+o5s4HC8Xx/pPZj6QR2VFVZUJnmTWNVdeciYc8d5vuikqQRz\nSPsAPtsR+40ePkUR0dHpW0tRrnP24vl0pEVvjK32PKfO/m73rrcFCYr8xp/f\ntj+9Y4Es9cY7wdRSPOgz3l2ECN2iYCwlk5TZnY/06ef+RQ/YOhfZJHtwpKLY\nHzX6vstRpAdgJQXdVbU4Pyy5piJtMpnzMpTlD+6Up70E2hw6mgHlUimsKSPk\nqYiGuh40PCcz/19t5mB5cqqkZQIgpFEgSnMcB3T+Uvo6shqz4cc/l79si7iO\naHWFFX/WltYX+eKoDnjPUIUU1hvd/MDuVpDTLPmh3hv0RoKZszYOxWL887Dl\ngcfYyoyGtPz0/zO30lR6uWC+cf+LOzPpLbeHwVhh8A0jae8FFWnIwv9pvIMd\n3OlO\r\n=49lq\r\n-----END PGP SIGNATURE-----\r\n","size":14109,"noattachment":false,"key":"/@octokit/plugin-throttling/-/@octokit/plugin-throttling-2.7.1.tgz"},"main":"lib/index.js","gitHead":"3d35007f05fd81eb217876638cf5c10aed10176d","scripts":{"test":"nyc mocha test/integration/","pretest":"standard","coverage":"nyc report --reporter=html && open coverage/index.html","update-endpoints":"npm-run-all update-endpoints:*","update-endpoints:code":"node scripts/update-endpoints/code","update-endpoints:fetch-json":"node scripts/update-endpoints/fetch-json"},"_npmUser":{"name":"octokitbot","email":"octokitbot@martynus.net"},"standard":{"globals":["describe","before","beforeEach","afterEach","after","it","expect"]},"repository":{"url":"git+https://github.com/octokit/plugin-throttling.js.git","type":"git"},"_npmVersion":"6.13.4","description":"Automatic rate limiting plugin for octokit","directories":{},"_nodeVersion":"12.14.0","dependencies":{"bottleneck":"^2.15.3"},"publishConfig":{"tag":"latest","access":"public"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","mocha":"^6.0.2","standard":"^14.0.2","npm-run-all":"^4.1.5","@octokit/rest":"^16.3.0","@octokit/graphql":"^4.2.0","semantic-release":"^15.13.25","@octokit/request-error":"^1.0.2"},"_npmOperationalInternal":{"tmp":"tmp/plugin-throttling_2.7.1_1576787227834_0.3822141577810523","host":"s3://npm-registry-packages"},"readme":"# plugin-throttling.js\n\n> Octokit plugin for GitHub’s recommended request throttling\n\n[![@latest](https://img.shields.io/npm/v/@octokit/plugin-throttling.svg)](https://www.npmjs.com/package/@octokit/plugin-throttling)\n[![Build Status](https://github.com/octokit/plugin-throttling.js/workflows/Test/badge.svg)](https://github.com/octokit/plugin-throttling.js/actions?workflow=Test)\n\nImplements all [recommended best practices](https://docs.github.com/en/rest/guides/best-practices-for-integrators) to prevent hitting secondary rate limits.\n\n## Usage\n\n<table>\n<tbody valign=top align=left>\n<tr><th>\nBrowsers\n</th><td width=100%>\n\nLoad `@octokit/plugin-throttling` and [`@octokit/core`](https://github.com/octokit/core.js) (or core-compatible module) directly from [esm.sh](https://esm.sh)\n\n```html\n<script type=\"module\">\n  import { Octokit } from \"https://esm.sh/@octokit/core\";\n  import { throttling } from \"https://esm.sh/@octokit/plugin-throttling\";\n</script>\n```\n\n</td></tr>\n<tr><th>\nNode\n</th><td>\n\nInstall with `npm install @octokit/core @octokit/plugin-throttling`. Optionally replace `@octokit/core` with a core-compatible module.\n\n**Note**: If you use it with `@octokit/rest` v16, install `@octokit/core` as a devDependency. This is only temporary and will no longer be necessary with `@octokit/rest` v17.\n\n```js\nimport { Octokit } from \"@octokit/core\";\nimport { throttling } from \"@octokit/plugin-throttling\";\n```\n\n</td></tr>\n</tbody>\n</table>\n\n> [!IMPORTANT]\n> As we use [conditional exports](https://nodejs.org/api/packages.html#conditional-exports), you will need to adapt your `tsconfig.json` by setting `\"moduleResolution\": \"node16\", \"module\": \"node16\"`.\n>\n> See the TypeScript docs on [package.json \"exports\"](https://www.typescriptlang.org/docs/handbook/modules/reference.html#packagejson-exports).<br>\n> See this [helpful guide on transitioning to ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) from [@sindresorhus](https://github.com/sindresorhus)\n\nThe code below creates a \"Hello, world!\" issue on every repository in a given organization. Without the throttling plugin it would send many requests in parallel and would hit rate limits very quickly. But the `@octokit/plugin-throttling` slows down your requests according to the official guidelines, so you don't get blocked before your quota is exhausted.\n\nThe `throttle.onSecondaryRateLimit` and `throttle.onRateLimit` options are required. Return `true` to automatically retry the request after `retryAfter` seconds.\n\n```js\nconst MyOctokit = Octokit.plugin(throttling);\n\nconst octokit = new MyOctokit({\n  auth: `secret123`,\n  throttle: {\n    onRateLimit: (retryAfter, options, octokit, retryCount) => {\n      octokit.log.warn(\n        `Request quota exhausted for request ${options.method} ${options.url}`,\n      );\n\n      if (retryCount < 1) {\n        // only retries once\n        octokit.log.info(`Retrying after ${retryAfter} seconds!`);\n        return true;\n      }\n    },\n    onSecondaryRateLimit: (retryAfter, options, octokit) => {\n      // does not retry, only logs a warning\n      octokit.log.warn(\n        `SecondaryRateLimit detected for request ${options.method} ${options.url}`,\n      );\n    },\n  },\n});\n\nasync function createIssueOnAllRepos(org) {\n  const repos = await octokit.paginate(\n    octokit.repos.listForOrg.endpoint({ org }),\n  );\n  return Promise.all(\n    repos.map(({ name }) =>\n      octokit.issues.create({\n        owner,\n        repo: name,\n        title: \"Hello, world!\",\n      }),\n    ),\n  );\n}\n```\n\nPass `{ throttle: { enabled: false } }` to disable this plugin.\n\n### Clustering\n\nEnabling Clustering support ensures that your application will not go over rate limits **across Octokit instances and across Nodejs processes**.\n\nFirst install either `redis` or `ioredis`:\n\n```\n# NodeRedis (https://github.com/NodeRedis/node_redis)\nnpm install --save redis\n\n# or ioredis (https://github.com/luin/ioredis)\nnpm install --save ioredis\n```\n\nThen in your application:\n\n```js\nimport Bottleneck from \"bottleneck\";\nimport Redis from \"redis\";\n\nconst client = Redis.createClient({\n  /* options */\n});\nconst connection = new Bottleneck.RedisConnection({ client });\nconnection.on(\"error\", err => console.error(err));\n\nconst octokit = new MyOctokit({\n  auth: 'secret123'\n  throttle: {\n    onSecondaryRateLimit: (retryAfter, options, octokit) => {\n      /* ... */\n    },\n    onRateLimit: (retryAfter, options, octokit) => {\n      /* ... */\n    },\n\n    // The Bottleneck connection object\n    connection,\n\n    // A \"throttling ID\". All octokit instances with the same ID\n    // using the same Redis server will share the throttling.\n    id: \"my-super-app\",\n\n    // Otherwise the plugin uses a lighter version of Bottleneck without Redis support\n    Bottleneck\n  }\n});\n\n// To close the connection and allow your application to exit cleanly:\nawait connection.disconnect();\n```\n\nTo use the `ioredis` library instead:\n\n```js\nimport Redis from \"ioredis\";\nconst client = new Redis({\n  /* options */\n});\nconst connection = new Bottleneck.IORedisConnection({ client });\nconnection.on(\"error\", (err) => console.error(err));\n```\n\n## Options\n\n<table>\n  <thead align=left>\n    <tr>\n      <th>\n        name\n      </th>\n      <th>\n        type\n      </th>\n      <th width=100%>\n        description\n      </th>\n    </tr>\n  </thead>\n  <tbody align=left valign=top>\n    <tr>\n      <th>\n        <code>options.retryAfterBaseValue</code>\n      </th>\n      <td>\n        <code>Number</code>\n      </td>\n      <td>\n        Number of milliseconds that will be used to multiply the time to wait based on `retry-after` or `x-ratelimit-reset` headers. Defaults to <code>1000</code>\n      </td>\n    </tr>\n    <tr>\n      <th>\n        <code>options.fallbackSecondaryRateRetryAfter</code>\n      </th>\n      <td>\n        <code>Number</code>\n      </td>\n      <td>\n        Number of seconds to wait until retrying a request in case a secondary rate limit is hit and no <code>retry-after</code> header was present in the response. Defaults to <code>60</code>\n      </td>\n    </tr>\n    <tr>\n      <th>\n        <code>options.connection</code>\n      </th>\n      <td>\n        <code>Bottleneck.RedisConnection</code>\n      </td>\n      <td>\n        A Bottleneck connection instance. See <a href=\"#clustering\">Clustering</a> above.\n      </td>\n    </tr>\n    <tr>\n      <th>\n        <code>options.id</code>\n      </th>\n      <td>\n        <code>string</code>\n      </td>\n      <td>\n        A \"throttling ID\". All octokit instances with the same ID using the same Redis server will share the throttling. See <a href=\"#clustering\">Clustering</a> above. Defaults to <code>no-id</code>.\n      </td>\n    </tr>\n    <tr>\n      <th>\n        <code>options.Bottleneck</code>\n      </th>\n      <td>\n        <code>Bottleneck</code>\n      </td>\n      <td>\n        Bottleneck constructor. See <a href=\"#clustering\">Clustering</a> above. Defaults to `bottleneck/light`.\n      </td>\n    </tr>\n  </tbody>\n</table>\n\n## LICENSE\n\n[MIT](LICENSE)\n","publish_time":1576787227970,"maintainers":[{"name":"kfcampbell","email":"kfcampbell@github.com"},{"name":"nickfloyd","email":"nicholas.floyd.info@gmail.com"},{"name":"gr2m","email":"gregor@martynus.net"},{"name":"octokitbot","email":"security+octokitbot@github.com"}],"_cnpm_publish_time":1576787227970,"dist-tags":{"latest":"11.0.5"}}