{"name":"@octokit/plugin-throttling","version":"4.0.1","license":"MIT","_id":"@octokit/plugin-throttling@4.0.1","homepage":"https://github.com/octokit/plugin-throttling.js#readme","bugs":{"url":"https://github.com/octokit/plugin-throttling.js/issues"},"dist":{"shasum":"06cd4af959a98fe601d780d3476063f249b5eec1","tarball":"http://registry-npm.ywwl.com/@octokit/plugin-throttling/download/@octokit/plugin-throttling-4.0.1.tgz","fileCount":19,"integrity":"sha512-CWAM7+3XkkmzwAd4FrI4+ogOd5oAmMJER8/6AYDTb4ErGuvSdSSGeI5jFw6quNj7qNV7TvSWLTnNgRjSdBEE2A==","signatures":[{"sig":"MEUCIQDVacDqBQSes5qi0loJeAYuTEIYorbm24gtdqAMhu/PWAIgPq6qzkFL2onWOPWTKm9XP7IQi5T6+4ylHX44ZQIgBr0=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":72715,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJix8F4ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmproQ//Xp7qHVhi0fVl6T6PNgOAaghyuX72dtOkSjge9q2xkU/u780B\r\nBHmEz+OijipfE61ZVipvZuC27ZGTSCsg6IxL4fc3V8d0BIACcOw+2xWlJTSP\r\nOC83VqjRnO9QGy1/JdmMweGpkAE52efPgUxiHpHcovi/eDypsCJmMj/aSEXQ\r\n7RTBFq3mg1tJVzoLTRyVIWUKce0ZQ15Gvqun/fFR7bWo0n9FjU8V82gSRliO\r\njfxxqZvA/SMFHk9L7B3H/xHCOvpiaM+ytnmHore/kBpnSKsFkYBdCnepbLO0\r\nd9yhp8/MrSbjzWd4atqFg7T2Xl1i+SpgnIcs+6MT8X1823neGq5cAbJqr28Q\r\nEC+dxHFULJPGZvm0Gfo71eHbzPyfweRhcCYV+9KjYWv3CQfDTp4farmonac4\r\nJMffAI4zfOwRkycssPrk/MniOkC0R4S4aKatimiOv8BSI3DLIVRwShsTo5Cv\r\nHLlk2t2o149tpzXpF0KHH1lr0yxYZwNrLDabBGzZmAYw3SfaKdhMdvSK6NUr\r\nAg4TRG+h8v/NBT/dyFraHDhsuR2y8IoYG+J01MsnVwHofS8Up6PFU3o53APZ\r\nneOod5t4pg11WXXzHfwa4sYyduMGV2mNLKm8jqLwhkClSYCfsIv4qdoB1aIh\r\nkr1R1nEt12vXbTFMRLmWPAnhuMjl6nL2kVI=\r\n=77/d\r\n-----END PGP SIGNATURE-----\r\n","size":13512,"noattachment":false,"key":"/@octokit/plugin-throttling/-/@octokit/plugin-throttling-4.0.1.tgz"},"main":"dist-node/index.js","pika":true,"types":"dist-types/index.d.ts","module":"dist-web/index.js","source":"dist-src/index.js","engines":{"node":">= 14"},"gitHead":"c487a0ec8afef3087a5bc16ab139803ab697c43c","_npmUser":{"name":"octokitbot","email":"security+octokitbot@github.com"},"repository":{"url":"git+https://github.com/octokit/plugin-throttling.js.git","type":"git"},"_npmVersion":"8.11.0","description":"Octokit plugin for GitHub's recommended request throttling","directories":{},"sideEffects":false,"_nodeVersion":"16.15.1","dependencies":{"bottleneck":"^2.15.3","@octokit/types":"^6.0.1"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^28.0.0","ts-jest":"^28.0.0","prettier":"2.7.1","@pika/pack":"^0.5.0","fetch-mock":"^9.0.0","typescript":"^4.0.2","@types/jest":"^28.0.0","@types/node":"^16.0.0","npm-run-all":"^4.1.5","@octokit/core":"^4.0.0","@types/fetch-mock":"^7.3.1","@octokit/request-error":"^2.0.0","@pika/plugin-build-web":"^0.9.1","@pika/plugin-build-node":"^0.9.1","@pika/plugin-ts-standard-pkg":"^0.9.1","github-openapi-graphql-query":"^2.0.0","semantic-release-plugin-update-version-in-files":"^1.0.0"},"peerDependencies":{"@octokit/core":"^4.0.0"},"_npmOperationalInternal":{"tmp":"tmp/plugin-throttling_4.0.1_1657258360023_0.3408773515184511","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":1657258360284,"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":1657258360284,"dist-tags":{"latest":"11.0.5"}}