@@ -22,7 +22,14 @@ type SocketSdkResultType<T extends SocketSdkOperations> =
22
22
| SocketSdkErrorType < T >
23
23
24
24
export interface SocketSdkOptions {
25
- agent ?: Agent | undefined
25
+ agent ?:
26
+ | Agent
27
+ | {
28
+ http ?: Agent | undefined
29
+ https ?: Agent | undefined
30
+ http2 ?: Agent | undefined
31
+ }
32
+ | undefined
26
33
baseUrl ?: string | undefined
27
34
userAgent ?: string | undefined
28
35
}
@@ -206,6 +213,9 @@ export function createUserAgentFromPkgJson(pkgData: {
206
213
return `${ name } /${ pkgData . version } ${ homepage ? ` (${ homepage } )` : '' } `
207
214
}
208
215
216
+ // https://github.com/sindresorhus/got/blob/v14.4.6/documentation/2-options.md#agent
217
+ const agentNames = new Set ( [ 'http' , 'https' , 'http2' ] )
218
+
209
219
export class SocketSdk {
210
220
readonly #baseUrl: string
211
221
readonly #reqOptions: RequestOptions
@@ -215,11 +225,16 @@ export class SocketSdk {
215
225
*/
216
226
constructor ( apiToken : string , options ?: SocketSdkOptions | undefined ) {
217
227
const {
218
- agent,
228
+ agent : agentOrObj ,
219
229
baseUrl = 'https://api.socket.dev/v0/' ,
220
230
userAgent
221
231
} = { __proto__ : null , ...options } as SocketSdkOptions
222
-
232
+ const agentKeys = agentOrObj ? Object . keys ( agentOrObj ) : [ ]
233
+ const agent = (
234
+ agentKeys . length && agentKeys . every ( k => agentNames . has ( k ) )
235
+ ? ( agentOrObj as any ) . https
236
+ : agentOrObj
237
+ ) as Agent | undefined
223
238
this . #baseUrl = baseUrl
224
239
this . #reqOptions = {
225
240
...( agent ? { agent } : { } ) ,
0 commit comments