Skip to content

Commit d400e1c

Browse files
fix: downgrade cacheable to 6.1.0 (#398)
* fix: downgrade cacheable to 6.1.0 * fix: rework how modules are imported... * fix: add an option for choosing to use cacheable lib or not
1 parent 09929f3 commit d400e1c

4 files changed

Lines changed: 34 additions & 16 deletions

File tree

clients/javascript/lib/baseClient.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import {
1414
UnprocessableEntityError,
1515
sanitizeErrorData,
1616
} from './helpers/errors'
17+
import type cacheableLookupType from 'cacheable-lookup'
18+
import type httpsType from 'node:https'
19+
import type httpType from 'node:http'
1720

1821
/**
1922
* Configuration for the keep alive feature
@@ -23,6 +26,12 @@ export type KeepAliveConfig = {
2326
* Whether to keep the connection alive
2427
*/
2528
enabled: boolean
29+
30+
/**
31+
* Whether to use the cacheable lookup library for DNS lookups
32+
*/
33+
useCacheableLookupDNS?: boolean
34+
2635
/**
2736
* Maximum number of sockets to keep alive
2837
*/
@@ -400,17 +409,17 @@ export const createAxiosInstanceBackend = async (
400409
typeof module !== 'undefined' &&
401410
module.exports
402411
) {
403-
// This is a dynamic import to avoid loading this module in the browser
404-
const CacheableLookupLib = await import('cacheable-lookup')
412+
// Import the module here to avoid loading this module in the browser
413+
const CacheableLookup: typeof cacheableLookupType = require('cacheable-lookup')
405414

406415
// Create a cacheable lookup instance
407416
// Goal is to make DNS lookup fully async + avoid hitting the limit of 4 UV threads
408417
// See https://marmelab.com/blog/2025/07/28/dns-in-nodejs.html (for example) on the subject
409-
const cacheableLookup = new CacheableLookupLib.default()
418+
const cacheableLookup = new CacheableLookup()
410419

411420
if (args.baseUrl.startsWith('https')) {
412-
// This is a dynamic import to avoid loading the https module in the browser
413-
const https = await import('node:https')
421+
// Import the module here to avoid loading this module in the browser
422+
const https: typeof httpsType = require('node:https')
414423
// Default values are what we evaluated to be good for our load
415424
const httpsAgent = new https.Agent({
416425
keepAlive: true,
@@ -419,11 +428,13 @@ export const createAxiosInstanceBackend = async (
419428
keepAliveMsecs: args.keepAlive.keepAliveMsecs ?? 60000,
420429
})
421430

422-
cacheableLookup.install(httpsAgent)
431+
if (args.keepAlive.useCacheableLookupDNS) {
432+
cacheableLookup.install(httpsAgent)
433+
}
423434
config.httpsAgent = httpsAgent
424435
} else {
425-
// This is a dynamic import to avoid loading the http module in the browser
426-
const http = await import('node:http')
436+
// Import the module here to avoid loading this module in the browser
437+
const http: typeof httpType = require('node:http')
427438
// Default values are what we evaluated to be good for our load
428439
const httpAgent = new http.Agent({
429440
keepAlive: true,
@@ -432,7 +443,9 @@ export const createAxiosInstanceBackend = async (
432443
keepAliveMsecs: args.keepAlive.keepAliveMsecs ?? 60000,
433444
})
434445

435-
cacheableLookup.install(httpAgent)
446+
if (args.keepAlive.useCacheableLookupDNS) {
447+
cacheableLookup.install(httpAgent)
448+
}
436449
config.httpAgent = httpAgent
437450
}
438451
}

clients/javascript/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"dependencies": {
4444
"axios": "1.12.2",
4545
"axios-retry": "4.5.0",
46-
"cacheable-lookup": "^7.0.0",
46+
"cacheable-lookup": "^6.1.0",
4747
"dayjs": "1.11.18"
4848
},
4949
"devDependencies": {

clients/javascript/tests/helpers/fixtures.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ export const setupAccount = async (options?: { timeout?: number }) => {
1515

1616
const config: Parameters<typeof NitteiClient>[0] = {
1717
apiKey: account.secretApiKey,
18+
// Test the keep alive feature at the same time
19+
keepAlive: {
20+
enabled: true,
21+
useCacheableLookupDNS: true,
22+
},
1823
}
1924
if (options?.timeout) {
2025
config.timeout = options.timeout

pnpm-lock.yaml

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)