From 32b598d33be59e1ccbf88d908110ef306bd0fb35 Mon Sep 17 00:00:00 2001 From: wolfy1339 <4595477+wolfy1339@users.noreply.github.com> Date: Sun, 21 May 2023 21:05:18 -0400 Subject: [PATCH] feat: v6 (#592) BREAKING CHANGE: Drop support for NodeJS v14, v16 BREAKING CHANGE: remove deprecated `options.throttle.minimalSecondaryRateRetryAfter` BREAKING CHANGE: remove deprecated `options.throttle.onAbuseLimit` Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com> --- .github/workflows/test.yml | 3 +- package-lock.json | 76 ++++++++++++++++++------------------- package.json | 4 +- src/index.ts | 23 ----------- src/types.ts | 20 ++-------- test/deprecations.test.ts | 42 +------------------- test/events.test.ts | 47 ----------------------- test/typescript-validate.ts | 19 ---------- 8 files changed, 47 insertions(+), 187 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3e4867bd..9ced3a2a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,9 +13,8 @@ jobs: strategy: matrix: node_version: - - 14 - - 16 - 18 + - 20 steps: - uses: actions/checkout@v3 - name: Test with Node.js ${{ matrix.node_version }} diff --git a/package-lock.json b/package-lock.json index a107faf5..c1cdfa4e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,7 +32,7 @@ "typescript": "^5.0.0" }, "engines": { - "node": ">= 14" + "node": ">= 18" }, "peerDependencies": { "@octokit/core": "^4.0.0" @@ -2638,9 +2638,9 @@ } }, "node_modules/@octokit/core": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/@octokit/core/-/core-4.2.0.tgz", - "integrity": "sha512-AgvDRUg3COpR82P7PBdGZF/NNqGmtMq2NiPqeSsDIeCfYFOZ9gddqWNQHnFdEUf+YwOj4aZYmJnlPp7OXmDIDg==", + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/@octokit/core/-/core-4.2.1.tgz", + "integrity": "sha512-tEDxFx8E38zF3gT7sSMDrT1tGumDgsw5yPG6BBh/X+5ClIQfMH/Yqocxz1PnHx6CHyF6pxmovUTOfZAUvQ0Lvw==", "dev": true, "dependencies": { "@octokit/auth-token": "^3.0.0", @@ -2670,9 +2670,9 @@ } }, "node_modules/@octokit/graphql": { - "version": "5.0.5", - "resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-5.0.5.tgz", - "integrity": "sha512-Qwfvh3xdqKtIznjX9lz2D458r7dJPP8l6r4GQkIdWQouZwHQK0mVT88uwiU2bdTU2OtT1uOlKpRciUWldpG0yQ==", + "version": "5.0.6", + "resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-5.0.6.tgz", + "integrity": "sha512-Fxyxdy/JH0MnIB5h+UQ3yCoh1FG4kWXfFKkpWqjZHw/p+Kc8Y44Hu/kCgNBT6nU1shNumEchmW/sUO1JuQnPcw==", "dev": true, "dependencies": { "@octokit/request": "^6.0.0", @@ -2684,14 +2684,14 @@ } }, "node_modules/@octokit/openapi-types": { - "version": "17.1.2", - "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-17.1.2.tgz", - "integrity": "sha512-OaS7Ol4Y+U50PbejfzQflGWRMxO04nYWO5ZBv6JerqMKE2WS/tI9VoVDDPXHBlRMGG2fOdKwtVGlFfc7AVIstw==" + "version": "17.2.0", + "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-17.2.0.tgz", + "integrity": "sha512-MazrFNx4plbLsGl+LFesMo96eIXkFgEtaKbnNpdh4aQ0VM10aoylFsTYP1AEjkeoRNZiiPe3T6Gl2Hr8dJWdlQ==" }, "node_modules/@octokit/request": { - "version": "6.2.3", - "resolved": "https://registry.npmjs.org/@octokit/request/-/request-6.2.3.tgz", - "integrity": "sha512-TNAodj5yNzrrZ/VxP+H5HiYaZep0H3GU0O7PaF+fhDrt8FPrnkei9Aal/txsN/1P7V3CPiThG0tIvpPDYUsyAA==", + "version": "6.2.5", + "resolved": "https://registry.npmjs.org/@octokit/request/-/request-6.2.5.tgz", + "integrity": "sha512-z83E8UIlPNaJUsXpjD8E0V5o/5f+vJJNbNcBwVZsX3/vC650U41cOkTLjq4PKk9BYonQGOnx7N17gvLyNjgGcQ==", "dev": true, "dependencies": { "@octokit/endpoint": "^7.0.0", @@ -2720,11 +2720,11 @@ } }, "node_modules/@octokit/types": { - "version": "9.2.2", - "resolved": "https://registry.npmjs.org/@octokit/types/-/types-9.2.2.tgz", - "integrity": "sha512-9BjDxjgQIvCjNWZsbqyH5QC2Yni16oaE6xL+8SUBMzcYPF4TGQBXGA97Cl3KceK9mwiNMb1mOYCz6FbCCLEL+g==", + "version": "9.2.3", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-9.2.3.tgz", + "integrity": "sha512-MMeLdHyFIALioycq+LFcA71v0S2xpQUX2cw6pPbHQjaibcHYwLnmK/kMZaWuGfGfjBJZ3wRUq+dOaWsvrPJVvA==", "dependencies": { - "@octokit/openapi-types": "^17.1.2" + "@octokit/openapi-types": "^17.2.0" } }, "node_modules/@pika/babel-plugin-esm-import-rewrite": { @@ -3024,9 +3024,9 @@ } }, "node_modules/@sinonjs/fake-timers": { - "version": "10.1.0", - "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-10.1.0.tgz", - "integrity": "sha512-w1qd368vtrwttm1PRJWPW1QHlbmHrVDGs1eBH/jZvRPUFS4MNXV9Q33EQdjOdeAxZ7O8+3wM7zxztm2nfUSyKw==", + "version": "10.2.0", + "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-10.2.0.tgz", + "integrity": "sha512-OPwQlEdg40HAj5KNF8WW6q2KG4Z+cBCZb3m4ninfTZKaBmbIJodviQsDBoYMPHkOyJJMHnOJo5j2+LKDOhOACg==", "dev": true, "dependencies": { "@sinonjs/commons": "^3.0.0" @@ -3174,9 +3174,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "18.16.9", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.16.9.tgz", - "integrity": "sha512-IeB32oIV4oGArLrd7znD2rkHQ6EDCM+2Sr76dJnrHwv9OHBTTM6nuDLK9bmikXzPa0ZlWMWtRGo/Uw4mrzQedA==", + "version": "18.16.14", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.16.14.tgz", + "integrity": "sha512-+ImzUB3mw2c5ISJUq0punjDilUQ5GnUim0ZRvchHIWJmOC0G+p0kzhXBqj6cDjK0QdPFwzrHWgrJp3RPvCG5qg==", "dev": true }, "node_modules/@types/prettier": { @@ -3711,9 +3711,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001487", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001487.tgz", - "integrity": "sha512-83564Z3yWGqXsh2vaH/mhXfEM0wX+NlBCm1jYHOb97TrTWJEmPTccZgeLTPBUUb0PNVo+oomb7wkimZBIERClA==", + "version": "1.0.30001488", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001488.tgz", + "integrity": "sha512-NORIQuuL4xGpIy6iCCQGN4iFjlBXtfKWIenlUuyZJumLRIindLb7wXM+GO8erEhb7vXfcnf4BAg2PrSDN5TNLQ==", "dev": true, "funding": [ { @@ -4078,9 +4078,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.4.394", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.394.tgz", - "integrity": "sha512-0IbC2cfr8w5LxTz+nmn2cJTGafsK9iauV2r5A5scfzyovqLrxuLoxOHE5OBobP3oVIggJT+0JfKnw9sm87c8Hw==", + "version": "1.4.402", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.402.tgz", + "integrity": "sha512-gWYvJSkohOiBE6ecVYXkrDgNaUjo47QEKK0kQzmWyhkH+yoYiG44bwuicTGNSIQRG3WDMsWVZJLRnJnLNkbWvA==", "dev": true }, "node_modules/emittery": { @@ -5015,9 +5015,9 @@ } }, "node_modules/is-core-module": { - "version": "2.12.0", - "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.12.0.tgz", - "integrity": "sha512-RECHCBCd/viahWmwj6enj19sKbHfJrddi/6cBDsNTKbNq0f7VeaUkBo60BqzvPqo/W54ChS62Z5qyun7cfOMqQ==", + "version": "2.12.1", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.12.1.tgz", + "integrity": "sha512-Q4ZuBAe2FUsKtyQJoQHlvP8OvBERxO3jEmy1I7hcRXcJBGGHFh/aJBswbXuS9sgrDH2QUO8ilkwNPHvHMd8clg==", "dev": true, "dependencies": { "has": "^1.0.3" @@ -7514,9 +7514,9 @@ "dev": true }, "node_modules/node-releases": { - "version": "2.0.10", - "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.10.tgz", - "integrity": "sha512-5GFldHPXVG/YZmFzJvKK2zDSzPKhEp0+ZR5SVaoSag9fsL5YgHbUHDfnG5494ISANDcK4KwPXAx2xqVEydmd7w==", + "version": "2.0.11", + "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.11.tgz", + "integrity": "sha512-+M0PwXeU80kRohZ3aT4J/OnR+l9/KD2nVLNNoRgFtnf+umQVFdGBAO2N8+nCnEi0xlh/Wk3zOGC+vNNx+uM79Q==", "dev": true }, "node_modules/normalize-package-data": { @@ -8821,9 +8821,9 @@ "dev": true }, "node_modules/tslib": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.5.0.tgz", - "integrity": "sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==", + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.5.2.tgz", + "integrity": "sha512-5svOrSA2w3iGFDs1HibEVBGbDrAY82bFQ3HZ3ixB+88nsbsWQoKqDRb5UBYAUPEzbBn6dAp5gRNXglySbx1MlA==", "dev": true }, "node_modules/type-detect": { diff --git a/package.json b/package.json index 09fcd52d..66db3ce1 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ [ "@pika/plugin-build-node", { - "minNodeVersion": "14" + "minNodeVersion": 18 } ], [ @@ -105,6 +105,6 @@ ] }, "engines": { - "node": ">= 14" + "node": ">= 18" } } diff --git a/src/index.ts b/src/index.ts index 1cfd232d..e80f8f7e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -59,29 +59,6 @@ export function throttling(octokit: Octokit, octokitOptions: OctokitOptions) { createGroups(Bottleneck, common); } - if ( - octokitOptions.throttle && - octokitOptions.throttle.minimalSecondaryRateRetryAfter - ) { - octokit.log.warn( - "[@octokit/plugin-throttling] `options.throttle.minimalSecondaryRateRetryAfter` is deprecated, please use `options.throttle.fallbackSecondaryRateRetryAfter` instead" - ); - octokitOptions.throttle.fallbackSecondaryRateRetryAfter = - octokitOptions.throttle.minimalSecondaryRateRetryAfter; - delete octokitOptions.throttle.minimalSecondaryRateRetryAfter; - } - - if (octokitOptions.throttle && octokitOptions.throttle.onAbuseLimit) { - octokit.log.warn( - "[@octokit/plugin-throttling] `onAbuseLimit()` is deprecated and will be removed in a future release of `@octokit/plugin-throttling`, please use the `onSecondaryRateLimit` handler instead" - ); - // @ts-ignore types don't allow for both properties to be set - octokitOptions.throttle.onSecondaryRateLimit = - octokitOptions.throttle.onAbuseLimit; - // @ts-ignore - delete octokitOptions.throttle.onAbuseLimit; - } - const state = Object.assign( { clustering: connection != null, diff --git a/src/types.ts b/src/types.ts index 978d89f1..9bb0b23f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -8,19 +8,7 @@ type LimitHandler = ( retryCount: number ) => void; -export type AbuseLimitHandler = { - /** - * @deprecated "[@octokit/plugin-throttling] `onAbuseLimit()` is deprecated and will be removed in a future release of `@octokit/plugin-throttling`, please use the `onSecondaryRateLimit` handler instead" - */ - onAbuseLimit: LimitHandler; - onSecondaryRateLimit?: never; -}; - export type SecondaryLimitHandler = { - /** - * @deprecated "[@octokit/plugin-throttling] `onAbuseLimit()` is deprecated and will be removed in a future release of `@octokit/plugin-throttling`, please use the `onSecondaryRateLimit` handler instead" - */ - onAbuseLimit?: never; onSecondaryRateLimit: LimitHandler; }; @@ -43,10 +31,10 @@ export type ThrottlingOptionsBase = { }; export type ThrottlingOptions = - | (ThrottlingOptionsBase & (AbuseLimitHandler | SecondaryLimitHandler)) - | (Partial< - ThrottlingOptionsBase & (AbuseLimitHandler | SecondaryLimitHandler) - > & { enabled: false }); + | (ThrottlingOptionsBase & SecondaryLimitHandler) + | (Partial & { + enabled: false; + }); export type Groups = { global?: Bottleneck.Group; diff --git a/test/deprecations.test.ts b/test/deprecations.test.ts index 5816ecef..2ae1c8de 100644 --- a/test/deprecations.test.ts +++ b/test/deprecations.test.ts @@ -3,44 +3,6 @@ import { throttling } from "../src"; const TestOctokit = Octokit.plugin(throttling); -describe("deprecations", () => { - it("throttle.minimalSecondaryRateRetryAfter option", () => { - const log = { - warn: jest.fn(), - }; - new TestOctokit({ - // @ts-expect-error - log, - throttle: { - minimalSecondaryRateRetryAfter: 1, - onSecondaryRateLimit: () => 1, - onRateLimit: () => 1, - }, - }); - - expect(log.warn).toHaveBeenCalledWith( - "[@octokit/plugin-throttling] `options.throttle.minimalSecondaryRateRetryAfter` is deprecated, please use `options.throttle.fallbackSecondaryRateRetryAfter` instead" - ); - }); - - describe("throttle.onAbuseLimit", function () { - it("Should detect SecondaryRate limit and broadcast event", async function () { - const log = { - warn: jest.fn(), - }; - - new TestOctokit({ - // @ts-expect-error - log, - throttle: { - onAbuseLimit: () => 1, - onRateLimit: () => 1, - }, - }); - - expect(log.warn).toHaveBeenCalledWith( - "[@octokit/plugin-throttling] `onAbuseLimit()` is deprecated and will be removed in a future release of `@octokit/plugin-throttling`, please use the `onSecondaryRateLimit` handler instead" - ); - }); - }); +describe.skip("deprecations", () => { + it("No deprecations", () => {}); }); diff --git a/test/events.test.ts b/test/events.test.ts index a8977213..93fa5ad5 100644 --- a/test/events.test.ts +++ b/test/events.test.ts @@ -121,53 +121,6 @@ describe("Events", function () { expect(error.status).toEqual(403); } - expect(eventCount).toEqual(1); - }); - }); - describe("with 'onSecondaryRateLimit'", function () { - it("Should detect SecondaryRate limit and broadcast event", async function () { - let eventCount = 0; - - const octokit = new TestOctokit({ - throttle: { - onSecondaryRateLimit: (retryAfter, options, octokitFromOptions) => { - expect(octokit).toBe(octokitFromOptions); - expect(retryAfter).toEqual(60); - expect(options).toMatchObject({ - method: "GET", - url: "/route2", - request: { retryCount: 0 }, - }); - eventCount++; - }, - onRateLimit: () => 1, - }, - }); - - await octokit.request("GET /route1", { - request: { - responses: [{ status: 201, headers: {}, data: {} }], - }, - }); - try { - await octokit.request("GET /route2", { - request: { - responses: [ - { - status: 403, - headers: { "retry-after": "60" }, - data: { - message: "You have exceeded a secondary rate limit", - }, - }, - ], - }, - }); - throw new Error("Should not reach this point"); - } catch (error: any) { - expect(error.status).toEqual(403); - } - expect(eventCount).toEqual(1); }); }); diff --git a/test/typescript-validate.ts b/test/typescript-validate.ts index 2c0dcd47..df4106c5 100644 --- a/test/typescript-validate.ts +++ b/test/typescript-validate.ts @@ -6,12 +6,6 @@ import { throttling } from "../src/index"; const octokit = new Octokit(); -// will be deprecated soon -// onAbuseLimit() -throttling(octokit, { - throttle: { enabled: true, onRateLimit: () => {}, onAbuseLimit: () => {} }, -}); - // onSecondaryLimit() throttling(octokit, { throttle: { @@ -21,22 +15,10 @@ throttling(octokit, { }, }); -// onSecondaryLimit() and onAbuseLimit() should be a TS Error -throttling(octokit, { - // @ts-expect-error - throttle: { - enabled: true, - onRateLimit: () => {}, - onSecondaryRateLimit: () => {}, - onAbuseLimit: () => {}, - }, -}); - // onRateLimit() missing should be a TS Error throttling(octokit, { // @ts-expect-error throttle: { - enabled: true, onSecondaryRateLimit: () => {}, }, }); @@ -45,7 +27,6 @@ throttling(octokit, { throttling(octokit, { // @ts-expect-error throttle: { - enabled: true, onRateLimit: () => {}, }, });