{"name":"@octokit/plugin-throttling","version":"3.3.3","license":"MIT","_id":"@octokit/plugin-throttling@3.3.3","homepage":"https://github.com/octokit/plugin-throttling.js#readme","bugs":{"url":"https://github.com/octokit/plugin-throttling.js/issues"},"dist":{"shasum":"b78d67c1e460392afc2245c98cce9c0ac778ecea","tarball":"http://registry-npm.ywwl.com/@octokit/plugin-throttling/download/@octokit/plugin-throttling-3.3.3.tgz","fileCount":17,"integrity":"sha512-G9BLSE33Vijc45qRuQ8uGF8N1YOk0i8nKosgGJw8TRH+CRjoPDMxYuo28roGiHvFZ5t2KArbJlneZb499wApLA==","signatures":[{"sig":"MEQCIDpbvPhdWo/P4b1DfBkRlb4aciPkAcdzlApe+vxCJw7bAiBay2aosExa3mznybbFrXAPytkbrRD5XQny8Upf3mgRIg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":67919,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfnvgiCRA9TVsSAnZWagAA7YAP/j/Bu4YWCMvIcYyNc6j3\nNVMtfltijD4mTybl2gYXdcKn7f5F/pCnCIFgXPAR8uVKDwhsvqAW/1ixoRzD\nZkTKWvqQ0ManN/bIoyio+i9TEucK7UOwnt1tU2zUCtgbpCVmo6LiWgUrD+ON\nO8fnCKW4OMDSbcnjomHwZ+9xvxmTRaePclof9h0OwaP0omkzMyROLEl+t+Fm\nFiHZVdbKIVe0RX1wQcrs0/LZz+srWtTq043KTtrBcpqHEHi2JC4iA0OGuPJY\nvcoD/1qcXrTEsq0peEA2qwieyHO2t81v5N8m+K/WdND6xS7gIOdvWMWLX7re\nEpaVv0GgNUChXxAgNLtDpRvyFwSKy13RFqgnsXSf1DuA4L46bziYK31tZkZM\nDy4QUUkfsPzMsDZqz5/0MMc7zE/3+du/OC1RpaUaNvkDIze6LK2e107oz6V6\nrUCF4xWJegiCr4ux+fnu7uu+LPv4gq9FYP+i29xYSU3g0TPgtmPX61BQKySG\nnjSOzXUMGvwoVqlD3euecOZpUGEj2vyAnreZ6xh7gYZSKpNUoiJvJHwia8BT\n1ZaBwMmgYz7P8Z5Pt2mkRyT8n80VJkwq10xG3NzJK8mBiojcFsp+DPQ67l9Q\n96ERp6s/vhimTWObg+AQbkagkfYTZyimTkhh+hWDymsPlnNia9UEw+etUvyn\n1+qK\r\n=b2dn\r\n-----END PGP SIGNATURE-----\r\n","size":13266,"noattachment":false,"key":"/@octokit/plugin-throttling/-/@octokit/plugin-throttling-3.3.3.tgz"},"main":"dist-node/index.js","pika":true,"types":"dist-types/index.d.ts","module":"dist-web/index.js","source":"dist-src/index.js","_npmUser":{"name":"octokitbot","email":"octokitbot@martynus.net"},"repository":{"url":"git+https://github.com/octokit/plugin-throttling.js.git","type":"git"},"_npmVersion":"6.14.8","description":"Octokit plugin for GitHub’s recommended request throttling","directories":{},"sideEffects":false,"_nodeVersion":"12.19.0","dependencies":{"bottleneck":"^2.15.3","@octokit/types":"^5.5.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^26.0.1","ts-jest":"^26.0.0","prettier":"^2.0.1","@pika/pack":"^0.5.0","fetch-mock":"^9.0.0","typescript":"^4.0.2","@types/jest":"^26.0.0","@types/node":"^14.0.1","npm-run-all":"^4.1.5","@octokit/core":"^3.0.0","semantic-release":"^17.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","semantic-release-plugin-update-version-in-files":"^1.0.0"},"peerDependencies":{"@octokit/core":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/plugin-throttling_3.3.3_1604253729638_0.1002988670067686","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":1604253729801,"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":1604253729801,"dist-tags":{"latest":"11.0.5"}}