import http from 'http' ; import https from 'https' ; import type { OptionsOfJSONResponseBody } from 'got' ; import got from 'got' ; const { version } = require ( '../../package.json' ) ; export const USER_AGENT = `Algolia npm-search/${ version } (https://github.com/algolia/npm-search)` ; const options = { keepAlive : true , timeout : 60000 , maxFreeSockets : 2000 , scheduling : 'fifo' , } ; export const httpAgent = new http . Agent ( options ) ; export const httpsAgent = new https . Agent ( options ) ; export async function request < TRes > ( url , opts ) { return await got < TRes > ( url , { ... opts , headers : { ... ( opts . headers || { } ) , 'user-agent' : USER_AGENT , } , timeout : 15000 , dnsCache : true , dnsLookupIpVersion : 'ipv4' , agent : { http : httpAgent , https : httpsAgent , } , } ) ; }