@@ -13,17 +13,41 @@ import rootPkgJson from '../package.json' with { type: 'json' }
13
13
14
14
import type { operations } from '../types/api'
15
15
import type { OpErrorType , OpReturnType } from '../types/api-helpers'
16
+ import type { ClientHttp2Session } from 'http2-wrapper'
16
17
import type { ReadStream } from 'node:fs'
17
- import type { ClientRequest , IncomingMessage } from 'node:http'
18
- import type { Agent , RequestOptions } from 'node:https'
19
-
20
- type BatchPackageFetchResultType = SocketSdkResultType < 'batchPackageFetch' >
21
-
22
- type BatchPackageStreamOptions = {
18
+ import type {
19
+ ClientRequest ,
20
+ Agent as HttpAgent ,
21
+ RequestOptions as HttpRequestOptions ,
22
+ IncomingMessage
23
+ } from 'node:http'
24
+ import type { ClientSessionRequestOptions } from 'node:http2'
25
+ import type {
26
+ Agent as HttpsAgent ,
27
+ RequestOptions as HttpsRequestOptions
28
+ } from 'node:https'
29
+
30
+ export type Agent = HttpsAgent | HttpAgent | ClientHttp2Session
31
+
32
+ export type BatchPackageFetchResultType =
33
+ SocketSdkResultType < 'batchPackageFetch' >
34
+
35
+ export type BatchPackageStreamOptions = {
23
36
chunkSize : number
24
37
concurrencyLimit : number
25
38
}
26
39
40
+ export type GotOptions = {
41
+ http ?: HttpAgent | undefined
42
+ https ?: HttpsAgent | undefined
43
+ http2 ?: ClientHttp2Session | undefined
44
+ }
45
+
46
+ export type RequestOptions =
47
+ | HttpsRequestOptions
48
+ | HttpRequestOptions
49
+ | ClientSessionRequestOptions
50
+
27
51
export type SocketSdkOperations = keyof operations
28
52
29
53
export type SocketSdkReturnType < T extends SocketSdkOperations > = OpReturnType <
@@ -43,14 +67,7 @@ export type SocketSdkResultType<T extends SocketSdkOperations> =
43
67
| SocketSdkErrorType < T >
44
68
45
69
export interface SocketSdkOptions {
46
- agent ?:
47
- | Agent
48
- | {
49
- http ?: Agent | undefined
50
- https ?: Agent | undefined
51
- http2 ?: Agent | undefined
52
- }
53
- | undefined
70
+ agent ?: Agent | GotOptions | undefined
54
71
baseUrl ?: string | undefined
55
72
userAgent ?: string | undefined
56
73
}
@@ -183,7 +200,7 @@ async function createUploadRequest(
183
200
method : 'POST' ,
184
201
...options ,
185
202
headers : {
186
- ...options ?. headers ,
203
+ ...( options as HttpsRequestOptions ) ?. headers ,
187
204
'Content-Type' : `multipart/form-data; boundary=${ boundary } `
188
205
}
189
206
} )
@@ -407,9 +424,12 @@ export class SocketSdk {
407
424
userAgent
408
425
} = { __proto__ : null , ...options } as SocketSdkOptions
409
426
const agentKeys = agentOrObj ? Object . keys ( agentOrObj ) : [ ]
427
+ const agentAsGotOptions = agentOrObj as GotOptions
410
428
const agent = (
411
429
agentKeys . length && agentKeys . every ( k => agentNames . has ( k ) )
412
- ? ( agentOrObj as any ) . https
430
+ ? agentAsGotOptions . https ||
431
+ agentAsGotOptions . http ||
432
+ agentAsGotOptions . http2
413
433
: agentOrObj
414
434
) as Agent | undefined
415
435
this . #baseUrl = baseUrl
0 commit comments