1- import type { Octokit } from "@octokit/core" ;
1+ import type { Octokit , OctokitOptions } from "@octokit/core" ;
22import type { RequestError } from "@octokit/request-error" ;
33
44import { VERSION } from "./version.js" ;
55import { errorRequest } from "./error-request.js" ;
66import { wrapRequest } from "./wrap-request.js" ;
7+ import type { RetryOptions , RetryPlugin , RetryState } from "./types.js" ;
8+ import type { RequestRequestOptions } from "@octokit/types" ;
79export { VERSION } from "./version.js" ;
810
9- export function retry ( octokit : Octokit , octokitOptions : any ) {
10- const state = Object . assign (
11+ export function retry (
12+ octokit : Octokit ,
13+ octokitOptions : OctokitOptions ,
14+ ) : RetryPlugin {
15+ const state : RetryState = Object . assign (
1116 {
1217 enabled : true ,
1318 retryAfterBaseValue : 1000 ,
1419 doNotRetry : [ 400 , 401 , 403 , 404 , 410 , 422 , 451 ] ,
1520 retries : 3 ,
16- } ,
21+ } satisfies RetryState ,
1722 octokitOptions . retry ,
1823 ) ;
1924
20- if ( state . enabled ) {
21- octokit . hook . error ( "request" , errorRequest . bind ( null , state , octokit ) ) ;
22- octokit . hook . wrap ( "request" , wrapRequest . bind ( null , state , octokit ) ) ;
23- }
24-
25- return {
25+ const retryPlugin : RetryPlugin = {
2626 retry : {
2727 retryRequest : (
2828 error : RequestError ,
@@ -32,11 +32,26 @@ export function retry(octokit: Octokit, octokitOptions: any) {
3232 error . request . request = Object . assign ( { } , error . request . request , {
3333 retries : retries ,
3434 retryAfter : retryAfter ,
35- } ) ;
35+ } satisfies RequestRequestOptions ) ;
3636
3737 return error ;
3838 } ,
3939 } ,
4040 } ;
41+
42+ if ( state . enabled ) {
43+ octokit . hook . error ( "request" , errorRequest . bind ( null , state , retryPlugin ) ) ;
44+ octokit . hook . wrap ( "request" , wrapRequest . bind ( null , state , retryPlugin ) ) ;
45+ }
46+
47+ return retryPlugin ;
4148}
4249retry . VERSION = VERSION ;
50+
51+ declare module "@octokit/core/types" {
52+ interface OctokitOptions {
53+ retry ?: RetryOptions ;
54+ }
55+ }
56+
57+ export type { RetryPlugin , RetryOptions } ;
0 commit comments