@nocobase/plugin-idp-oauth 2.1.0-alpha.17 → 2.1.0-alpha.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. package/build.config.ts +1 -1
  2. package/dist/externalVersion.js +4 -4
  3. package/dist/node_modules/light-my-request/package.json +1 -1
  4. package/dist/node_modules/undici/LICENSE +21 -0
  5. package/dist/node_modules/undici/README.md +741 -0
  6. package/dist/node_modules/undici/docs/docs/api/Agent.md +84 -0
  7. package/dist/node_modules/undici/docs/docs/api/BalancedPool.md +99 -0
  8. package/dist/node_modules/undici/docs/docs/api/CacheStorage.md +30 -0
  9. package/dist/node_modules/undici/docs/docs/api/CacheStore.md +164 -0
  10. package/dist/node_modules/undici/docs/docs/api/Client.md +285 -0
  11. package/dist/node_modules/undici/docs/docs/api/ClientStats.md +27 -0
  12. package/dist/node_modules/undici/docs/docs/api/Connector.md +115 -0
  13. package/dist/node_modules/undici/docs/docs/api/ContentType.md +57 -0
  14. package/dist/node_modules/undici/docs/docs/api/Cookies.md +101 -0
  15. package/dist/node_modules/undici/docs/docs/api/Debug.md +62 -0
  16. package/dist/node_modules/undici/docs/docs/api/DiagnosticsChannel.md +315 -0
  17. package/dist/node_modules/undici/docs/docs/api/Dispatcher.md +1392 -0
  18. package/dist/node_modules/undici/docs/docs/api/EnvHttpProxyAgent.md +159 -0
  19. package/dist/node_modules/undici/docs/docs/api/Errors.md +49 -0
  20. package/dist/node_modules/undici/docs/docs/api/EventSource.md +45 -0
  21. package/dist/node_modules/undici/docs/docs/api/Fetch.md +60 -0
  22. package/dist/node_modules/undici/docs/docs/api/GlobalInstallation.md +139 -0
  23. package/dist/node_modules/undici/docs/docs/api/H2CClient.md +263 -0
  24. package/dist/node_modules/undici/docs/docs/api/MockAgent.md +603 -0
  25. package/dist/node_modules/undici/docs/docs/api/MockCallHistory.md +197 -0
  26. package/dist/node_modules/undici/docs/docs/api/MockCallHistoryLog.md +43 -0
  27. package/dist/node_modules/undici/docs/docs/api/MockClient.md +81 -0
  28. package/dist/node_modules/undici/docs/docs/api/MockErrors.md +12 -0
  29. package/dist/node_modules/undici/docs/docs/api/MockPool.md +555 -0
  30. package/dist/node_modules/undici/docs/docs/api/Pool.md +84 -0
  31. package/dist/node_modules/undici/docs/docs/api/PoolStats.md +35 -0
  32. package/dist/node_modules/undici/docs/docs/api/ProxyAgent.md +229 -0
  33. package/dist/node_modules/undici/docs/docs/api/RedirectHandler.md +93 -0
  34. package/dist/node_modules/undici/docs/docs/api/RetryAgent.md +50 -0
  35. package/dist/node_modules/undici/docs/docs/api/RetryHandler.md +118 -0
  36. package/dist/node_modules/undici/docs/docs/api/RoundRobinPool.md +145 -0
  37. package/dist/node_modules/undici/docs/docs/api/SnapshotAgent.md +616 -0
  38. package/dist/node_modules/undici/docs/docs/api/Socks5ProxyAgent.md +274 -0
  39. package/dist/node_modules/undici/docs/docs/api/Util.md +25 -0
  40. package/dist/node_modules/undici/docs/docs/api/WebSocket.md +141 -0
  41. package/dist/node_modules/undici/docs/docs/api/api-lifecycle.md +91 -0
  42. package/dist/node_modules/undici/docs/docs/best-practices/client-certificate.md +64 -0
  43. package/dist/node_modules/undici/docs/docs/best-practices/crawling.md +58 -0
  44. package/dist/node_modules/undici/docs/docs/best-practices/mocking-request.md +190 -0
  45. package/dist/node_modules/undici/docs/docs/best-practices/proxy.md +127 -0
  46. package/dist/node_modules/undici/docs/docs/best-practices/undici-vs-builtin-fetch.md +224 -0
  47. package/dist/node_modules/undici/docs/docs/best-practices/writing-tests.md +63 -0
  48. package/dist/node_modules/undici/index-fetch.js +65 -0
  49. package/dist/node_modules/undici/index.d.ts +3 -0
  50. package/dist/node_modules/undici/index.js +234 -0
  51. package/dist/node_modules/undici/lib/api/abort-signal.js +59 -0
  52. package/dist/node_modules/undici/lib/api/api-connect.js +110 -0
  53. package/dist/node_modules/undici/lib/api/api-pipeline.js +252 -0
  54. package/dist/node_modules/undici/lib/api/api-request.js +214 -0
  55. package/dist/node_modules/undici/lib/api/api-stream.js +209 -0
  56. package/dist/node_modules/undici/lib/api/api-upgrade.js +111 -0
  57. package/dist/node_modules/undici/lib/api/index.js +7 -0
  58. package/dist/node_modules/undici/lib/api/readable.js +580 -0
  59. package/dist/node_modules/undici/lib/cache/memory-cache-store.js +234 -0
  60. package/dist/node_modules/undici/lib/cache/sqlite-cache-store.js +461 -0
  61. package/dist/node_modules/undici/lib/core/connect.js +137 -0
  62. package/dist/node_modules/undici/lib/core/constants.js +143 -0
  63. package/dist/node_modules/undici/lib/core/diagnostics.js +227 -0
  64. package/dist/node_modules/undici/lib/core/errors.js +477 -0
  65. package/dist/node_modules/undici/lib/core/request.js +438 -0
  66. package/dist/node_modules/undici/lib/core/socks5-client.js +407 -0
  67. package/dist/node_modules/undici/lib/core/socks5-utils.js +203 -0
  68. package/dist/node_modules/undici/lib/core/symbols.js +75 -0
  69. package/dist/node_modules/undici/lib/core/tree.js +160 -0
  70. package/dist/node_modules/undici/lib/core/util.js +992 -0
  71. package/dist/node_modules/undici/lib/dispatcher/agent.js +158 -0
  72. package/dist/node_modules/undici/lib/dispatcher/balanced-pool.js +219 -0
  73. package/dist/node_modules/undici/lib/dispatcher/client-h1.js +1610 -0
  74. package/dist/node_modules/undici/lib/dispatcher/client-h2.js +995 -0
  75. package/dist/node_modules/undici/lib/dispatcher/client.js +659 -0
  76. package/dist/node_modules/undici/lib/dispatcher/dispatcher-base.js +165 -0
  77. package/dist/node_modules/undici/lib/dispatcher/dispatcher.js +48 -0
  78. package/dist/node_modules/undici/lib/dispatcher/env-http-proxy-agent.js +146 -0
  79. package/dist/node_modules/undici/lib/dispatcher/fixed-queue.js +135 -0
  80. package/dist/node_modules/undici/lib/dispatcher/h2c-client.js +51 -0
  81. package/dist/node_modules/undici/lib/dispatcher/pool-base.js +214 -0
  82. package/dist/node_modules/undici/lib/dispatcher/pool.js +118 -0
  83. package/dist/node_modules/undici/lib/dispatcher/proxy-agent.js +318 -0
  84. package/dist/node_modules/undici/lib/dispatcher/retry-agent.js +35 -0
  85. package/dist/node_modules/undici/lib/dispatcher/round-robin-pool.js +137 -0
  86. package/dist/node_modules/undici/lib/dispatcher/socks5-proxy-agent.js +249 -0
  87. package/dist/node_modules/undici/lib/encoding/index.js +33 -0
  88. package/dist/node_modules/undici/lib/global.js +50 -0
  89. package/dist/node_modules/undici/lib/handler/cache-handler.js +578 -0
  90. package/dist/node_modules/undici/lib/handler/cache-revalidation-handler.js +124 -0
  91. package/dist/node_modules/undici/lib/handler/decorator-handler.js +67 -0
  92. package/dist/node_modules/undici/lib/handler/deduplication-handler.js +460 -0
  93. package/dist/node_modules/undici/lib/handler/redirect-handler.js +238 -0
  94. package/dist/node_modules/undici/lib/handler/retry-handler.js +394 -0
  95. package/dist/node_modules/undici/lib/handler/unwrap-handler.js +100 -0
  96. package/dist/node_modules/undici/lib/handler/wrap-handler.js +105 -0
  97. package/dist/node_modules/undici/lib/interceptor/cache.js +495 -0
  98. package/dist/node_modules/undici/lib/interceptor/decompress.js +259 -0
  99. package/dist/node_modules/undici/lib/interceptor/deduplicate.js +117 -0
  100. package/dist/node_modules/undici/lib/interceptor/dns.js +571 -0
  101. package/dist/node_modules/undici/lib/interceptor/dump.js +112 -0
  102. package/dist/node_modules/undici/lib/interceptor/redirect.js +21 -0
  103. package/dist/node_modules/undici/lib/interceptor/response-error.js +95 -0
  104. package/dist/node_modules/undici/lib/interceptor/retry.js +19 -0
  105. package/dist/node_modules/undici/lib/llhttp/.gitkeep +0 -0
  106. package/dist/node_modules/undici/lib/llhttp/constants.d.ts +195 -0
  107. package/dist/node_modules/undici/lib/llhttp/constants.js +531 -0
  108. package/dist/node_modules/undici/lib/llhttp/llhttp-wasm.js +15 -0
  109. package/dist/node_modules/undici/lib/llhttp/llhttp_simd-wasm.js +15 -0
  110. package/dist/node_modules/undici/lib/llhttp/utils.d.ts +2 -0
  111. package/dist/node_modules/undici/lib/llhttp/utils.js +12 -0
  112. package/dist/node_modules/undici/lib/mock/mock-agent.js +232 -0
  113. package/dist/node_modules/undici/lib/mock/mock-call-history.js +248 -0
  114. package/dist/node_modules/undici/lib/mock/mock-client.js +68 -0
  115. package/dist/node_modules/undici/lib/mock/mock-errors.js +29 -0
  116. package/dist/node_modules/undici/lib/mock/mock-interceptor.js +209 -0
  117. package/dist/node_modules/undici/lib/mock/mock-pool.js +68 -0
  118. package/dist/node_modules/undici/lib/mock/mock-symbols.js +32 -0
  119. package/dist/node_modules/undici/lib/mock/mock-utils.js +486 -0
  120. package/dist/node_modules/undici/lib/mock/pending-interceptors-formatter.js +43 -0
  121. package/dist/node_modules/undici/lib/mock/snapshot-agent.js +353 -0
  122. package/dist/node_modules/undici/lib/mock/snapshot-recorder.js +588 -0
  123. package/dist/node_modules/undici/lib/mock/snapshot-utils.js +158 -0
  124. package/dist/node_modules/undici/lib/util/cache.js +407 -0
  125. package/dist/node_modules/undici/lib/util/date.js +653 -0
  126. package/dist/node_modules/undici/lib/util/promise.js +28 -0
  127. package/dist/node_modules/undici/lib/util/runtime-features.js +124 -0
  128. package/dist/node_modules/undici/lib/util/stats.js +32 -0
  129. package/dist/node_modules/undici/lib/util/timers.js +425 -0
  130. package/dist/node_modules/undici/lib/web/cache/cache.js +864 -0
  131. package/dist/node_modules/undici/lib/web/cache/cachestorage.js +152 -0
  132. package/dist/node_modules/undici/lib/web/cache/util.js +45 -0
  133. package/dist/node_modules/undici/lib/web/cookies/constants.js +12 -0
  134. package/dist/node_modules/undici/lib/web/cookies/index.js +199 -0
  135. package/dist/node_modules/undici/lib/web/cookies/parse.js +322 -0
  136. package/dist/node_modules/undici/lib/web/cookies/util.js +282 -0
  137. package/dist/node_modules/undici/lib/web/eventsource/eventsource-stream.js +399 -0
  138. package/dist/node_modules/undici/lib/web/eventsource/eventsource.js +501 -0
  139. package/dist/node_modules/undici/lib/web/eventsource/util.js +29 -0
  140. package/dist/node_modules/undici/lib/web/fetch/LICENSE +21 -0
  141. package/dist/node_modules/undici/lib/web/fetch/body.js +509 -0
  142. package/dist/node_modules/undici/lib/web/fetch/constants.js +131 -0
  143. package/dist/node_modules/undici/lib/web/fetch/data-url.js +596 -0
  144. package/dist/node_modules/undici/lib/web/fetch/formdata-parser.js +575 -0
  145. package/dist/node_modules/undici/lib/web/fetch/formdata.js +259 -0
  146. package/dist/node_modules/undici/lib/web/fetch/global.js +40 -0
  147. package/dist/node_modules/undici/lib/web/fetch/headers.js +719 -0
  148. package/dist/node_modules/undici/lib/web/fetch/index.js +2397 -0
  149. package/dist/node_modules/undici/lib/web/fetch/request.js +1115 -0
  150. package/dist/node_modules/undici/lib/web/fetch/response.js +641 -0
  151. package/dist/node_modules/undici/lib/web/fetch/util.js +1520 -0
  152. package/dist/node_modules/undici/lib/web/infra/index.js +229 -0
  153. package/dist/node_modules/undici/lib/web/subresource-integrity/Readme.md +9 -0
  154. package/dist/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +307 -0
  155. package/dist/node_modules/undici/lib/web/webidl/index.js +1006 -0
  156. package/dist/node_modules/undici/lib/web/websocket/connection.js +329 -0
  157. package/dist/node_modules/undici/lib/web/websocket/constants.js +126 -0
  158. package/dist/node_modules/undici/lib/web/websocket/events.js +331 -0
  159. package/dist/node_modules/undici/lib/web/websocket/frame.js +133 -0
  160. package/dist/node_modules/undici/lib/web/websocket/permessage-deflate.js +118 -0
  161. package/dist/node_modules/undici/lib/web/websocket/receiver.js +450 -0
  162. package/dist/node_modules/undici/lib/web/websocket/sender.js +109 -0
  163. package/dist/node_modules/undici/lib/web/websocket/stream/websocketerror.js +104 -0
  164. package/dist/node_modules/undici/lib/web/websocket/stream/websocketstream.js +497 -0
  165. package/dist/node_modules/undici/lib/web/websocket/util.js +347 -0
  166. package/dist/node_modules/undici/lib/web/websocket/websocket.js +751 -0
  167. package/dist/node_modules/undici/package.json +152 -0
  168. package/dist/node_modules/undici/scripts/strip-comments.js +10 -0
  169. package/dist/node_modules/undici/types/README.md +6 -0
  170. package/dist/node_modules/undici/types/agent.d.ts +32 -0
  171. package/dist/node_modules/undici/types/api.d.ts +43 -0
  172. package/dist/node_modules/undici/types/balanced-pool.d.ts +30 -0
  173. package/dist/node_modules/undici/types/cache-interceptor.d.ts +179 -0
  174. package/dist/node_modules/undici/types/cache.d.ts +36 -0
  175. package/dist/node_modules/undici/types/client-stats.d.ts +15 -0
  176. package/dist/node_modules/undici/types/client.d.ts +123 -0
  177. package/dist/node_modules/undici/types/connector.d.ts +36 -0
  178. package/dist/node_modules/undici/types/content-type.d.ts +21 -0
  179. package/dist/node_modules/undici/types/cookies.d.ts +30 -0
  180. package/dist/node_modules/undici/types/diagnostics-channel.d.ts +74 -0
  181. package/dist/node_modules/undici/types/dispatcher.d.ts +273 -0
  182. package/dist/node_modules/undici/types/env-http-proxy-agent.d.ts +22 -0
  183. package/dist/node_modules/undici/types/errors.d.ts +177 -0
  184. package/dist/node_modules/undici/types/eventsource.d.ts +66 -0
  185. package/dist/node_modules/undici/types/fetch.d.ts +231 -0
  186. package/dist/node_modules/undici/types/formdata.d.ts +114 -0
  187. package/dist/node_modules/undici/types/global-dispatcher.d.ts +9 -0
  188. package/dist/node_modules/undici/types/global-origin.d.ts +7 -0
  189. package/dist/node_modules/undici/types/h2c-client.d.ts +73 -0
  190. package/dist/node_modules/undici/types/handlers.d.ts +14 -0
  191. package/dist/node_modules/undici/types/header.d.ts +160 -0
  192. package/dist/node_modules/undici/types/index.d.ts +91 -0
  193. package/dist/node_modules/undici/types/interceptors.d.ts +80 -0
  194. package/dist/node_modules/undici/types/mock-agent.d.ts +68 -0
  195. package/dist/node_modules/undici/types/mock-call-history.d.ts +111 -0
  196. package/dist/node_modules/undici/types/mock-client.d.ts +27 -0
  197. package/dist/node_modules/undici/types/mock-errors.d.ts +12 -0
  198. package/dist/node_modules/undici/types/mock-interceptor.d.ts +94 -0
  199. package/dist/node_modules/undici/types/mock-pool.d.ts +27 -0
  200. package/dist/node_modules/undici/types/patch.d.ts +29 -0
  201. package/dist/node_modules/undici/types/pool-stats.d.ts +19 -0
  202. package/dist/node_modules/undici/types/pool.d.ts +41 -0
  203. package/dist/node_modules/undici/types/proxy-agent.d.ts +29 -0
  204. package/dist/node_modules/undici/types/readable.d.ts +68 -0
  205. package/dist/node_modules/undici/types/retry-agent.d.ts +8 -0
  206. package/dist/node_modules/undici/types/retry-handler.d.ts +125 -0
  207. package/dist/node_modules/undici/types/round-robin-pool.d.ts +41 -0
  208. package/dist/node_modules/undici/types/snapshot-agent.d.ts +109 -0
  209. package/dist/node_modules/undici/types/socks5-proxy-agent.d.ts +25 -0
  210. package/dist/node_modules/undici/types/util.d.ts +18 -0
  211. package/dist/node_modules/undici/types/utility.d.ts +7 -0
  212. package/dist/node_modules/undici/types/webidl.d.ts +347 -0
  213. package/dist/node_modules/undici/types/websocket.d.ts +188 -0
  214. package/package.json +2 -2
@@ -0,0 +1,659 @@
1
+ 'use strict'
2
+
3
+ const assert = require('node:assert')
4
+ const net = require('node:net')
5
+ const http = require('node:http')
6
+ const util = require('../core/util.js')
7
+ const { ClientStats } = require('../util/stats.js')
8
+ const { channels } = require('../core/diagnostics.js')
9
+ const Request = require('../core/request.js')
10
+ const DispatcherBase = require('./dispatcher-base')
11
+ const {
12
+ InvalidArgumentError,
13
+ InformationalError,
14
+ ClientDestroyedError
15
+ } = require('../core/errors.js')
16
+ const buildConnector = require('../core/connect.js')
17
+ const {
18
+ kUrl,
19
+ kServerName,
20
+ kClient,
21
+ kBusy,
22
+ kConnect,
23
+ kResuming,
24
+ kRunning,
25
+ kPending,
26
+ kSize,
27
+ kQueue,
28
+ kConnected,
29
+ kConnecting,
30
+ kNeedDrain,
31
+ kKeepAliveDefaultTimeout,
32
+ kHostHeader,
33
+ kPendingIdx,
34
+ kRunningIdx,
35
+ kError,
36
+ kPipelining,
37
+ kKeepAliveTimeoutValue,
38
+ kMaxHeadersSize,
39
+ kKeepAliveMaxTimeout,
40
+ kKeepAliveTimeoutThreshold,
41
+ kHeadersTimeout,
42
+ kBodyTimeout,
43
+ kStrictContentLength,
44
+ kConnector,
45
+ kMaxRequests,
46
+ kCounter,
47
+ kClose,
48
+ kDestroy,
49
+ kDispatch,
50
+ kLocalAddress,
51
+ kMaxResponseSize,
52
+ kOnError,
53
+ kHTTPContext,
54
+ kMaxConcurrentStreams,
55
+ kHTTP2InitialWindowSize,
56
+ kHTTP2ConnectionWindowSize,
57
+ kResume,
58
+ kPingInterval
59
+ } = require('../core/symbols.js')
60
+ const connectH1 = require('./client-h1.js')
61
+ const connectH2 = require('./client-h2.js')
62
+
63
+ const kClosedResolve = Symbol('kClosedResolve')
64
+
65
+ const getDefaultNodeMaxHeaderSize = http &&
66
+ http.maxHeaderSize &&
67
+ Number.isInteger(http.maxHeaderSize) &&
68
+ http.maxHeaderSize > 0
69
+ ? () => http.maxHeaderSize
70
+ : () => { throw new InvalidArgumentError('http module not available or http.maxHeaderSize invalid') }
71
+
72
+ const noop = () => { }
73
+
74
+ function getPipelining (client) {
75
+ return client[kPipelining] ?? client[kHTTPContext]?.defaultPipelining ?? 1
76
+ }
77
+
78
+ /**
79
+ * @type {import('../../types/client.js').default}
80
+ */
81
+ class Client extends DispatcherBase {
82
+ /**
83
+ *
84
+ * @param {string|URL} url
85
+ * @param {import('../../types/client.js').Client.Options} options
86
+ */
87
+ constructor (url, {
88
+ maxHeaderSize,
89
+ headersTimeout,
90
+ socketTimeout,
91
+ requestTimeout,
92
+ connectTimeout,
93
+ bodyTimeout,
94
+ idleTimeout,
95
+ keepAlive,
96
+ keepAliveTimeout,
97
+ maxKeepAliveTimeout,
98
+ keepAliveMaxTimeout,
99
+ keepAliveTimeoutThreshold,
100
+ socketPath,
101
+ pipelining,
102
+ tls,
103
+ strictContentLength,
104
+ maxCachedSessions,
105
+ connect,
106
+ maxRequestsPerClient,
107
+ localAddress,
108
+ maxResponseSize,
109
+ autoSelectFamily,
110
+ autoSelectFamilyAttemptTimeout,
111
+ // h2
112
+ maxConcurrentStreams,
113
+ allowH2,
114
+ useH2c,
115
+ initialWindowSize,
116
+ connectionWindowSize,
117
+ pingInterval
118
+ } = {}) {
119
+ if (keepAlive !== undefined) {
120
+ throw new InvalidArgumentError('unsupported keepAlive, use pipelining=0 instead')
121
+ }
122
+
123
+ if (socketTimeout !== undefined) {
124
+ throw new InvalidArgumentError('unsupported socketTimeout, use headersTimeout & bodyTimeout instead')
125
+ }
126
+
127
+ if (requestTimeout !== undefined) {
128
+ throw new InvalidArgumentError('unsupported requestTimeout, use headersTimeout & bodyTimeout instead')
129
+ }
130
+
131
+ if (idleTimeout !== undefined) {
132
+ throw new InvalidArgumentError('unsupported idleTimeout, use keepAliveTimeout instead')
133
+ }
134
+
135
+ if (maxKeepAliveTimeout !== undefined) {
136
+ throw new InvalidArgumentError('unsupported maxKeepAliveTimeout, use keepAliveMaxTimeout instead')
137
+ }
138
+
139
+ if (maxHeaderSize != null) {
140
+ if (!Number.isInteger(maxHeaderSize) || maxHeaderSize < 1) {
141
+ throw new InvalidArgumentError('invalid maxHeaderSize')
142
+ }
143
+ } else {
144
+ // If maxHeaderSize is not provided, use the default value from the http module
145
+ // or if that is not available, throw an error.
146
+ maxHeaderSize = getDefaultNodeMaxHeaderSize()
147
+ }
148
+
149
+ if (socketPath != null && typeof socketPath !== 'string') {
150
+ throw new InvalidArgumentError('invalid socketPath')
151
+ }
152
+
153
+ if (connectTimeout != null && (!Number.isFinite(connectTimeout) || connectTimeout < 0)) {
154
+ throw new InvalidArgumentError('invalid connectTimeout')
155
+ }
156
+
157
+ if (keepAliveTimeout != null && (!Number.isFinite(keepAliveTimeout) || keepAliveTimeout <= 0)) {
158
+ throw new InvalidArgumentError('invalid keepAliveTimeout')
159
+ }
160
+
161
+ if (keepAliveMaxTimeout != null && (!Number.isFinite(keepAliveMaxTimeout) || keepAliveMaxTimeout <= 0)) {
162
+ throw new InvalidArgumentError('invalid keepAliveMaxTimeout')
163
+ }
164
+
165
+ if (keepAliveTimeoutThreshold != null && !Number.isFinite(keepAliveTimeoutThreshold)) {
166
+ throw new InvalidArgumentError('invalid keepAliveTimeoutThreshold')
167
+ }
168
+
169
+ if (headersTimeout != null && (!Number.isInteger(headersTimeout) || headersTimeout < 0)) {
170
+ throw new InvalidArgumentError('headersTimeout must be a positive integer or zero')
171
+ }
172
+
173
+ if (bodyTimeout != null && (!Number.isInteger(bodyTimeout) || bodyTimeout < 0)) {
174
+ throw new InvalidArgumentError('bodyTimeout must be a positive integer or zero')
175
+ }
176
+
177
+ if (connect != null && typeof connect !== 'function' && typeof connect !== 'object') {
178
+ throw new InvalidArgumentError('connect must be a function or an object')
179
+ }
180
+
181
+ if (maxRequestsPerClient != null && (!Number.isInteger(maxRequestsPerClient) || maxRequestsPerClient < 0)) {
182
+ throw new InvalidArgumentError('maxRequestsPerClient must be a positive number')
183
+ }
184
+
185
+ if (localAddress != null && (typeof localAddress !== 'string' || net.isIP(localAddress) === 0)) {
186
+ throw new InvalidArgumentError('localAddress must be valid string IP address')
187
+ }
188
+
189
+ if (maxResponseSize != null && (!Number.isInteger(maxResponseSize) || maxResponseSize < -1)) {
190
+ throw new InvalidArgumentError('maxResponseSize must be a positive number')
191
+ }
192
+
193
+ if (
194
+ autoSelectFamilyAttemptTimeout != null &&
195
+ (!Number.isInteger(autoSelectFamilyAttemptTimeout) || autoSelectFamilyAttemptTimeout < -1)
196
+ ) {
197
+ throw new InvalidArgumentError('autoSelectFamilyAttemptTimeout must be a positive number')
198
+ }
199
+
200
+ // h2
201
+ if (allowH2 != null && typeof allowH2 !== 'boolean') {
202
+ throw new InvalidArgumentError('allowH2 must be a valid boolean value')
203
+ }
204
+
205
+ if (maxConcurrentStreams != null && (typeof maxConcurrentStreams !== 'number' || maxConcurrentStreams < 1)) {
206
+ throw new InvalidArgumentError('maxConcurrentStreams must be a positive integer, greater than 0')
207
+ }
208
+
209
+ if (useH2c != null && typeof useH2c !== 'boolean') {
210
+ throw new InvalidArgumentError('useH2c must be a valid boolean value')
211
+ }
212
+
213
+ if (initialWindowSize != null && (!Number.isInteger(initialWindowSize) || initialWindowSize < 1)) {
214
+ throw new InvalidArgumentError('initialWindowSize must be a positive integer, greater than 0')
215
+ }
216
+
217
+ if (connectionWindowSize != null && (!Number.isInteger(connectionWindowSize) || connectionWindowSize < 1)) {
218
+ throw new InvalidArgumentError('connectionWindowSize must be a positive integer, greater than 0')
219
+ }
220
+
221
+ if (pingInterval != null && (typeof pingInterval !== 'number' || !Number.isInteger(pingInterval) || pingInterval < 0)) {
222
+ throw new InvalidArgumentError('pingInterval must be a positive integer, greater or equal to 0')
223
+ }
224
+
225
+ super()
226
+
227
+ if (typeof connect !== 'function') {
228
+ connect = buildConnector({
229
+ ...tls,
230
+ maxCachedSessions,
231
+ allowH2,
232
+ useH2c,
233
+ socketPath,
234
+ timeout: connectTimeout,
235
+ ...(typeof autoSelectFamily === 'boolean' ? { autoSelectFamily, autoSelectFamilyAttemptTimeout } : undefined),
236
+ ...connect
237
+ })
238
+ } else if (socketPath != null) {
239
+ const customConnect = connect
240
+ connect = (opts, callback) => customConnect({ ...opts, socketPath }, callback)
241
+ }
242
+
243
+ this[kUrl] = util.parseOrigin(url)
244
+ this[kConnector] = connect
245
+ this[kPipelining] = pipelining != null ? pipelining : 1
246
+ this[kMaxHeadersSize] = maxHeaderSize
247
+ this[kKeepAliveDefaultTimeout] = keepAliveTimeout == null ? 4e3 : keepAliveTimeout
248
+ this[kKeepAliveMaxTimeout] = keepAliveMaxTimeout == null ? 600e3 : keepAliveMaxTimeout
249
+ this[kKeepAliveTimeoutThreshold] = keepAliveTimeoutThreshold == null ? 2e3 : keepAliveTimeoutThreshold
250
+ this[kKeepAliveTimeoutValue] = this[kKeepAliveDefaultTimeout]
251
+ this[kServerName] = null
252
+ this[kLocalAddress] = localAddress != null ? localAddress : null
253
+ this[kResuming] = 0 // 0, idle, 1, scheduled, 2 resuming
254
+ this[kNeedDrain] = 0 // 0, idle, 1, scheduled, 2 resuming
255
+ this[kHostHeader] = `host: ${this[kUrl].hostname}${this[kUrl].port ? `:${this[kUrl].port}` : ''}\r\n`
256
+ this[kBodyTimeout] = bodyTimeout != null ? bodyTimeout : 300e3
257
+ this[kHeadersTimeout] = headersTimeout != null ? headersTimeout : 300e3
258
+ this[kStrictContentLength] = strictContentLength == null ? true : strictContentLength
259
+ this[kMaxRequests] = maxRequestsPerClient
260
+ this[kClosedResolve] = null
261
+ this[kMaxResponseSize] = maxResponseSize > -1 ? maxResponseSize : -1
262
+ this[kHTTPContext] = null
263
+ // h2
264
+ this[kMaxConcurrentStreams] = maxConcurrentStreams != null ? maxConcurrentStreams : 100 // Max peerConcurrentStreams for a Node h2 server
265
+ // HTTP/2 window sizes are set to higher defaults than Node.js core for better performance:
266
+ // - initialWindowSize: 262144 (256KB) vs Node.js default 65535 (64KB - 1)
267
+ // Allows more data to be sent before requiring acknowledgment, improving throughput
268
+ // especially on high-latency networks. This matches common production HTTP/2 servers.
269
+ // - connectionWindowSize: 524288 (512KB) vs Node.js default (none set)
270
+ // Provides better flow control for the entire connection across multiple streams.
271
+ this[kHTTP2InitialWindowSize] = initialWindowSize != null ? initialWindowSize : 262144
272
+ this[kHTTP2ConnectionWindowSize] = connectionWindowSize != null ? connectionWindowSize : 524288
273
+ this[kPingInterval] = pingInterval != null ? pingInterval : 60e3 // Default ping interval for h2 - 1 minute
274
+
275
+ // kQueue is built up of 3 sections separated by
276
+ // the kRunningIdx and kPendingIdx indices.
277
+ // | complete | running | pending |
278
+ // ^ kRunningIdx ^ kPendingIdx ^ kQueue.length
279
+ // kRunningIdx points to the first running element.
280
+ // kPendingIdx points to the first pending element.
281
+ // This implements a fast queue with an amortized
282
+ // time of O(1).
283
+
284
+ this[kQueue] = []
285
+ this[kRunningIdx] = 0
286
+ this[kPendingIdx] = 0
287
+
288
+ this[kResume] = (sync) => resume(this, sync)
289
+ this[kOnError] = (err) => onError(this, err)
290
+ }
291
+
292
+ get pipelining () {
293
+ return this[kPipelining]
294
+ }
295
+
296
+ set pipelining (value) {
297
+ this[kPipelining] = value
298
+ this[kResume](true)
299
+ }
300
+
301
+ get stats () {
302
+ return new ClientStats(this)
303
+ }
304
+
305
+ get [kPending] () {
306
+ return this[kQueue].length - this[kPendingIdx]
307
+ }
308
+
309
+ get [kRunning] () {
310
+ return this[kPendingIdx] - this[kRunningIdx]
311
+ }
312
+
313
+ get [kSize] () {
314
+ return this[kQueue].length - this[kRunningIdx]
315
+ }
316
+
317
+ get [kConnected] () {
318
+ return !!this[kHTTPContext] && !this[kConnecting] && !this[kHTTPContext].destroyed
319
+ }
320
+
321
+ get [kBusy] () {
322
+ return Boolean(
323
+ this[kHTTPContext]?.busy(null) ||
324
+ (this[kSize] >= (getPipelining(this) || 1)) ||
325
+ this[kPending] > 0
326
+ )
327
+ }
328
+
329
+ [kConnect] (cb) {
330
+ connect(this)
331
+ this.once('connect', cb)
332
+ }
333
+
334
+ [kDispatch] (opts, handler) {
335
+ const request = new Request(this[kUrl].origin, opts, handler)
336
+
337
+ this[kQueue].push(request)
338
+ if (this[kResuming]) {
339
+ // Do nothing.
340
+ } else if (util.bodyLength(request.body) == null && util.isIterable(request.body)) {
341
+ // Wait a tick in case stream/iterator is ended in the same tick.
342
+ this[kResuming] = 1
343
+ queueMicrotask(() => resume(this))
344
+ } else {
345
+ this[kResume](true)
346
+ }
347
+
348
+ if (this[kResuming] && this[kNeedDrain] !== 2 && this[kBusy]) {
349
+ this[kNeedDrain] = 2
350
+ }
351
+
352
+ return this[kNeedDrain] < 2
353
+ }
354
+
355
+ [kClose] () {
356
+ // TODO: for H2 we need to gracefully flush the remaining enqueued
357
+ // request and close each stream.
358
+ return new Promise((resolve) => {
359
+ if (this[kSize]) {
360
+ this[kClosedResolve] = resolve
361
+ } else {
362
+ resolve(null)
363
+ }
364
+ })
365
+ }
366
+
367
+ [kDestroy] (err) {
368
+ return new Promise((resolve) => {
369
+ const requests = this[kQueue].splice(this[kPendingIdx])
370
+ for (let i = 0; i < requests.length; i++) {
371
+ const request = requests[i]
372
+ util.errorRequest(this, request, err)
373
+ }
374
+
375
+ const callback = () => {
376
+ if (this[kClosedResolve]) {
377
+ // TODO (fix): Should we error here with ClientDestroyedError?
378
+ this[kClosedResolve]()
379
+ this[kClosedResolve] = null
380
+ }
381
+ resolve(null)
382
+ }
383
+
384
+ if (this[kHTTPContext]) {
385
+ this[kHTTPContext].destroy(err, callback)
386
+ this[kHTTPContext] = null
387
+ } else {
388
+ queueMicrotask(callback)
389
+ }
390
+
391
+ this[kResume]()
392
+ })
393
+ }
394
+ }
395
+
396
+ function onError (client, err) {
397
+ if (
398
+ client[kRunning] === 0 &&
399
+ err.code !== 'UND_ERR_INFO' &&
400
+ err.code !== 'UND_ERR_SOCKET'
401
+ ) {
402
+ // Error is not caused by running request and not a recoverable
403
+ // socket error.
404
+
405
+ assert(client[kPendingIdx] === client[kRunningIdx])
406
+
407
+ const requests = client[kQueue].splice(client[kRunningIdx])
408
+
409
+ for (let i = 0; i < requests.length; i++) {
410
+ const request = requests[i]
411
+ util.errorRequest(client, request, err)
412
+ }
413
+ assert(client[kSize] === 0)
414
+ }
415
+ }
416
+
417
+ /**
418
+ * @param {Client} client
419
+ * @returns {void}
420
+ */
421
+ function connect (client) {
422
+ assert(!client[kConnecting])
423
+ assert(!client[kHTTPContext])
424
+
425
+ let { host, hostname, protocol, port } = client[kUrl]
426
+
427
+ // Resolve ipv6
428
+ if (hostname[0] === '[') {
429
+ const idx = hostname.indexOf(']')
430
+
431
+ assert(idx !== -1)
432
+ const ip = hostname.substring(1, idx)
433
+
434
+ assert(net.isIPv6(ip))
435
+ hostname = ip
436
+ }
437
+
438
+ client[kConnecting] = true
439
+
440
+ if (channels.beforeConnect.hasSubscribers) {
441
+ channels.beforeConnect.publish({
442
+ connectParams: {
443
+ host,
444
+ hostname,
445
+ protocol,
446
+ port,
447
+ version: client[kHTTPContext]?.version,
448
+ servername: client[kServerName],
449
+ localAddress: client[kLocalAddress]
450
+ },
451
+ connector: client[kConnector]
452
+ })
453
+ }
454
+
455
+ try {
456
+ client[kConnector]({
457
+ host,
458
+ hostname,
459
+ protocol,
460
+ port,
461
+ servername: client[kServerName],
462
+ localAddress: client[kLocalAddress]
463
+ }, (err, socket) => {
464
+ if (err) {
465
+ handleConnectError(client, err, { host, hostname, protocol, port })
466
+ client[kResume]()
467
+ return
468
+ }
469
+
470
+ if (client.destroyed) {
471
+ util.destroy(socket.on('error', noop), new ClientDestroyedError())
472
+ client[kResume]()
473
+ return
474
+ }
475
+
476
+ assert(socket)
477
+
478
+ try {
479
+ client[kHTTPContext] = socket.alpnProtocol === 'h2'
480
+ ? connectH2(client, socket)
481
+ : connectH1(client, socket)
482
+ } catch (err) {
483
+ socket.destroy().on('error', noop)
484
+ handleConnectError(client, err, { host, hostname, protocol, port })
485
+ client[kResume]()
486
+ return
487
+ }
488
+
489
+ client[kConnecting] = false
490
+
491
+ socket[kCounter] = 0
492
+ socket[kMaxRequests] = client[kMaxRequests]
493
+ socket[kClient] = client
494
+ socket[kError] = null
495
+
496
+ if (channels.connected.hasSubscribers) {
497
+ channels.connected.publish({
498
+ connectParams: {
499
+ host,
500
+ hostname,
501
+ protocol,
502
+ port,
503
+ version: client[kHTTPContext]?.version,
504
+ servername: client[kServerName],
505
+ localAddress: client[kLocalAddress]
506
+ },
507
+ connector: client[kConnector],
508
+ socket
509
+ })
510
+ }
511
+
512
+ client.emit('connect', client[kUrl], [client])
513
+ client[kResume]()
514
+ })
515
+ } catch (err) {
516
+ handleConnectError(client, err, { host, hostname, protocol, port })
517
+ client[kResume]()
518
+ }
519
+ }
520
+
521
+ function handleConnectError (client, err, { host, hostname, protocol, port }) {
522
+ if (client.destroyed) {
523
+ return
524
+ }
525
+
526
+ client[kConnecting] = false
527
+
528
+ if (channels.connectError.hasSubscribers) {
529
+ channels.connectError.publish({
530
+ connectParams: {
531
+ host,
532
+ hostname,
533
+ protocol,
534
+ port,
535
+ version: client[kHTTPContext]?.version,
536
+ servername: client[kServerName],
537
+ localAddress: client[kLocalAddress]
538
+ },
539
+ connector: client[kConnector],
540
+ error: err
541
+ })
542
+ }
543
+
544
+ if (err.code === 'ERR_TLS_CERT_ALTNAME_INVALID') {
545
+ assert(client[kRunning] === 0)
546
+ while (client[kPending] > 0 && client[kQueue][client[kPendingIdx]].servername === client[kServerName]) {
547
+ const request = client[kQueue][client[kPendingIdx]++]
548
+ util.errorRequest(client, request, err)
549
+ }
550
+ } else {
551
+ onError(client, err)
552
+ }
553
+
554
+ client.emit('connectionError', client[kUrl], [client], err)
555
+ }
556
+
557
+ function emitDrain (client) {
558
+ client[kNeedDrain] = 0
559
+ client.emit('drain', client[kUrl], [client])
560
+ }
561
+
562
+ function resume (client, sync) {
563
+ if (client[kResuming] === 2) {
564
+ return
565
+ }
566
+
567
+ client[kResuming] = 2
568
+
569
+ _resume(client, sync)
570
+ client[kResuming] = 0
571
+
572
+ if (client[kRunningIdx] > 256) {
573
+ client[kQueue].splice(0, client[kRunningIdx])
574
+ client[kPendingIdx] -= client[kRunningIdx]
575
+ client[kRunningIdx] = 0
576
+ }
577
+ }
578
+
579
+ function _resume (client, sync) {
580
+ while (true) {
581
+ if (client.destroyed) {
582
+ assert(client[kPending] === 0)
583
+ return
584
+ }
585
+
586
+ if (client[kClosedResolve] && !client[kSize]) {
587
+ client[kClosedResolve]()
588
+ client[kClosedResolve] = null
589
+ return
590
+ }
591
+
592
+ if (client[kHTTPContext]) {
593
+ client[kHTTPContext].resume()
594
+ }
595
+
596
+ if (client[kBusy]) {
597
+ client[kNeedDrain] = 2
598
+ } else if (client[kNeedDrain] === 2) {
599
+ if (sync) {
600
+ client[kNeedDrain] = 1
601
+ queueMicrotask(() => emitDrain(client))
602
+ } else {
603
+ emitDrain(client)
604
+ }
605
+ continue
606
+ }
607
+
608
+ if (client[kPending] === 0) {
609
+ return
610
+ }
611
+
612
+ if (client[kRunning] >= (getPipelining(client) || 1)) {
613
+ return
614
+ }
615
+
616
+ const request = client[kQueue][client[kPendingIdx]]
617
+
618
+ if (request === null) {
619
+ return
620
+ }
621
+
622
+ if (client[kUrl].protocol === 'https:' && client[kServerName] !== request.servername) {
623
+ if (client[kRunning] > 0) {
624
+ return
625
+ }
626
+
627
+ client[kServerName] = request.servername
628
+ client[kHTTPContext]?.destroy(new InformationalError('servername changed'), () => {
629
+ client[kHTTPContext] = null
630
+ resume(client)
631
+ })
632
+ }
633
+
634
+ if (client[kConnecting]) {
635
+ return
636
+ }
637
+
638
+ if (!client[kHTTPContext]) {
639
+ connect(client)
640
+ return
641
+ }
642
+
643
+ if (client[kHTTPContext].destroyed) {
644
+ return
645
+ }
646
+
647
+ if (client[kHTTPContext].busy(request)) {
648
+ return
649
+ }
650
+
651
+ if (!request.aborted && client[kHTTPContext].write(request)) {
652
+ client[kPendingIdx]++
653
+ } else {
654
+ client[kQueue].splice(client[kPendingIdx], 1)
655
+ }
656
+ }
657
+ }
658
+
659
+ module.exports = Client