isomorfeus-puppetmaster 0.5.5 → 0.5.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (710) hide show
  1. checksums.yaml +4 -4
  2. data/lib/isomorfeus/puppetmaster/console_message.rb +18 -18
  3. data/lib/isomorfeus/puppetmaster/cookie.rb +46 -46
  4. data/lib/isomorfeus/puppetmaster/driver/puppeteer.rb +413 -415
  5. data/lib/isomorfeus/puppetmaster/driver/puppeteer_document.rb +953 -953
  6. data/lib/isomorfeus/puppetmaster/driver/puppeteer_node.rb +851 -851
  7. data/lib/isomorfeus/puppetmaster/errors.rb +90 -90
  8. data/lib/isomorfeus/puppetmaster/iframe.rb +16 -16
  9. data/lib/isomorfeus/puppetmaster/node/content_editable.rb +17 -17
  10. data/lib/isomorfeus/puppetmaster/node/input.rb +20 -20
  11. data/lib/isomorfeus/puppetmaster/node/select.rb +35 -35
  12. data/lib/isomorfeus/puppetmaster/node.rb +279 -279
  13. data/lib/isomorfeus/puppetmaster/request.rb +16 -16
  14. data/lib/isomorfeus/puppetmaster/response.rb +25 -25
  15. data/lib/isomorfeus/puppetmaster/self_forwardable.rb +38 -38
  16. data/lib/isomorfeus/puppetmaster/version.rb +3 -3
  17. data/lib/isomorfeus/puppetmaster.rb +85 -85
  18. data/lib/isomorfeus-puppetmaster.rb +1 -0
  19. data/node_modules/.bin/extract-zip +12 -12
  20. data/node_modules/.bin/extract-zip.ps1 +28 -28
  21. data/node_modules/.bin/rimraf +12 -12
  22. data/node_modules/.bin/rimraf.ps1 +28 -28
  23. data/node_modules/.package-lock.json +530 -585
  24. data/node_modules/@types/node/LICENSE +21 -21
  25. data/node_modules/@types/node/assert/strict.d.ts +8 -8
  26. data/node_modules/@types/node/assert.d.ts +912 -912
  27. data/node_modules/@types/node/async_hooks.d.ts +497 -497
  28. data/node_modules/@types/node/buffer.d.ts +2142 -2142
  29. data/node_modules/@types/node/child_process.d.ts +1355 -1355
  30. data/node_modules/@types/node/cluster.d.ts +414 -414
  31. data/node_modules/@types/node/console.d.ts +407 -407
  32. data/node_modules/@types/node/constants.d.ts +18 -18
  33. data/node_modules/@types/node/crypto.d.ts +3224 -3224
  34. data/node_modules/@types/node/dgram.d.ts +545 -545
  35. data/node_modules/@types/node/diagnostics_channel.d.ts +128 -128
  36. data/node_modules/@types/node/dns/promises.d.ts +357 -357
  37. data/node_modules/@types/node/dns.d.ts +643 -643
  38. data/node_modules/@types/node/domain.d.ts +169 -169
  39. data/node_modules/@types/node/events.d.ts +623 -623
  40. data/node_modules/@types/node/fs/promises.d.ts +997 -997
  41. data/node_modules/@types/node/fs.d.ts +3723 -3723
  42. data/node_modules/@types/node/globals.d.ts +285 -285
  43. data/node_modules/@types/node/globals.global.d.ts +1 -1
  44. data/node_modules/@types/node/http.d.ts +1358 -1358
  45. data/node_modules/@types/node/http2.d.ts +2100 -2100
  46. data/node_modules/@types/node/https.d.ts +391 -391
  47. data/node_modules/@types/node/index.d.ts +131 -131
  48. data/node_modules/@types/node/inspector.d.ts +2738 -2738
  49. data/node_modules/@types/node/module.d.ts +114 -114
  50. data/node_modules/@types/node/net.d.ts +783 -783
  51. data/node_modules/@types/node/os.d.ts +455 -455
  52. data/node_modules/@types/node/package.json +229 -229
  53. data/node_modules/@types/node/path.d.ts +172 -172
  54. data/node_modules/@types/node/perf_hooks.d.ts +555 -555
  55. data/node_modules/@types/node/process.d.ts +1477 -1477
  56. data/node_modules/@types/node/punycode.d.ts +117 -117
  57. data/node_modules/@types/node/querystring.d.ts +131 -131
  58. data/node_modules/@types/node/readline.d.ts +542 -542
  59. data/node_modules/@types/node/repl.d.ts +424 -424
  60. data/node_modules/@types/node/stream/consumers.d.ts +24 -24
  61. data/node_modules/@types/node/stream/promises.d.ts +42 -42
  62. data/node_modules/@types/node/stream/web.d.ts +6 -6
  63. data/node_modules/@types/node/stream.d.ts +1181 -1181
  64. data/node_modules/@types/node/string_decoder.d.ts +67 -67
  65. data/node_modules/@types/node/timers/promises.d.ts +68 -68
  66. data/node_modules/@types/node/timers.d.ts +94 -94
  67. data/node_modules/@types/node/tls.d.ts +1019 -1019
  68. data/node_modules/@types/node/trace_events.d.ts +161 -161
  69. data/node_modules/@types/node/tty.d.ts +206 -206
  70. data/node_modules/@types/node/url.d.ts +798 -798
  71. data/node_modules/@types/node/util.d.ts +1556 -1556
  72. data/node_modules/@types/node/v8.d.ts +378 -378
  73. data/node_modules/@types/node/vm.d.ts +504 -504
  74. data/node_modules/@types/node/wasi.d.ts +153 -153
  75. data/node_modules/@types/node/worker_threads.d.ts +649 -649
  76. data/node_modules/@types/node/zlib.d.ts +517 -517
  77. data/node_modules/@types/yauzl/LICENSE +21 -21
  78. data/node_modules/@types/yauzl/index.d.ts +98 -98
  79. data/node_modules/@types/yauzl/package.json +26 -26
  80. data/node_modules/agent-base/README.md +145 -145
  81. data/node_modules/agent-base/dist/src/index.d.ts +78 -78
  82. data/node_modules/agent-base/dist/src/index.js +202 -202
  83. data/node_modules/agent-base/dist/src/promisify.d.ts +4 -4
  84. data/node_modules/agent-base/dist/src/promisify.js +17 -17
  85. data/node_modules/agent-base/package.json +64 -64
  86. data/node_modules/agent-base/src/index.ts +345 -345
  87. data/node_modules/agent-base/src/promisify.ts +33 -33
  88. data/node_modules/balanced-match/.github/FUNDING.yml +2 -2
  89. data/node_modules/balanced-match/LICENSE.md +21 -21
  90. data/node_modules/balanced-match/README.md +97 -97
  91. data/node_modules/balanced-match/index.js +62 -62
  92. data/node_modules/balanced-match/package.json +48 -48
  93. data/node_modules/base64-js/LICENSE +21 -21
  94. data/node_modules/base64-js/README.md +34 -34
  95. data/node_modules/base64-js/index.d.ts +3 -3
  96. data/node_modules/base64-js/index.js +150 -150
  97. data/node_modules/base64-js/package.json +47 -47
  98. data/node_modules/bl/.travis.yml +17 -17
  99. data/node_modules/bl/BufferList.js +396 -396
  100. data/node_modules/bl/LICENSE.md +13 -13
  101. data/node_modules/bl/README.md +247 -247
  102. data/node_modules/bl/bl.js +84 -84
  103. data/node_modules/bl/package.json +37 -37
  104. data/node_modules/bl/test/convert.js +21 -21
  105. data/node_modules/bl/test/indexOf.js +492 -492
  106. data/node_modules/bl/test/isBufferList.js +32 -32
  107. data/node_modules/bl/test/test.js +869 -869
  108. data/node_modules/brace-expansion/LICENSE +21 -21
  109. data/node_modules/brace-expansion/README.md +129 -129
  110. data/node_modules/brace-expansion/index.js +201 -201
  111. data/node_modules/brace-expansion/package.json +47 -47
  112. data/node_modules/buffer/AUTHORS.md +70 -70
  113. data/node_modules/buffer/LICENSE +21 -21
  114. data/node_modules/buffer/README.md +410 -410
  115. data/node_modules/buffer/index.d.ts +186 -186
  116. data/node_modules/buffer/index.js +1817 -1817
  117. data/node_modules/buffer/package.json +96 -96
  118. data/node_modules/buffer-crc32/LICENSE +19 -19
  119. data/node_modules/buffer-crc32/README.md +47 -47
  120. data/node_modules/buffer-crc32/index.js +111 -111
  121. data/node_modules/buffer-crc32/package.json +39 -39
  122. data/node_modules/chownr/LICENSE +15 -15
  123. data/node_modules/chownr/README.md +3 -3
  124. data/node_modules/chownr/chownr.js +167 -167
  125. data/node_modules/chownr/package.json +29 -29
  126. data/node_modules/concat-map/.travis.yml +4 -4
  127. data/node_modules/concat-map/LICENSE +18 -18
  128. data/node_modules/concat-map/README.markdown +62 -62
  129. data/node_modules/concat-map/example/map.js +6 -6
  130. data/node_modules/concat-map/index.js +13 -13
  131. data/node_modules/concat-map/package.json +43 -43
  132. data/node_modules/concat-map/test/map.js +39 -39
  133. data/node_modules/debug/LICENSE +19 -19
  134. data/node_modules/debug/README.md +455 -455
  135. data/node_modules/debug/package.json +59 -59
  136. data/node_modules/debug/src/browser.js +269 -269
  137. data/node_modules/debug/src/common.js +274 -274
  138. data/node_modules/debug/src/index.js +10 -10
  139. data/node_modules/debug/src/node.js +263 -263
  140. data/node_modules/devtools-protocol/LICENSE +27 -27
  141. data/node_modules/devtools-protocol/README.md +12 -12
  142. data/node_modules/devtools-protocol/json/browser_protocol.json +20985 -20640
  143. data/node_modules/devtools-protocol/json/js_protocol.json +3531 -3580
  144. data/node_modules/devtools-protocol/package.json +17 -18
  145. data/node_modules/devtools-protocol/pdl/browser_protocol.pdl +9849 -9637
  146. data/node_modules/devtools-protocol/pdl/js_protocol.pdl +1653 -1678
  147. data/node_modules/devtools-protocol/types/protocol-mapping.d.ts +4333 -4321
  148. data/node_modules/devtools-protocol/types/protocol-proxy-api.d.ts +3695 -3683
  149. data/node_modules/devtools-protocol/types/protocol.d.ts +15714 -15538
  150. data/node_modules/end-of-stream/LICENSE +20 -20
  151. data/node_modules/end-of-stream/README.md +54 -54
  152. data/node_modules/end-of-stream/index.js +94 -94
  153. data/node_modules/end-of-stream/package.json +37 -37
  154. data/node_modules/extract-zip/LICENSE +23 -23
  155. data/node_modules/extract-zip/cli.js +19 -19
  156. data/node_modules/extract-zip/index.d.ts +21 -21
  157. data/node_modules/extract-zip/index.js +173 -173
  158. data/node_modules/extract-zip/package.json +80 -80
  159. data/node_modules/extract-zip/readme.md +57 -57
  160. data/node_modules/fd-slicer/.npmignore +2 -2
  161. data/node_modules/fd-slicer/.travis.yml +7 -7
  162. data/node_modules/fd-slicer/CHANGELOG.md +49 -49
  163. data/node_modules/fd-slicer/LICENSE +21 -21
  164. data/node_modules/fd-slicer/README.md +199 -199
  165. data/node_modules/fd-slicer/index.js +296 -296
  166. data/node_modules/fd-slicer/package.json +36 -36
  167. data/node_modules/fd-slicer/test/test.js +350 -350
  168. data/node_modules/find-up/index.d.ts +137 -137
  169. data/node_modules/find-up/index.js +89 -89
  170. data/node_modules/find-up/license +9 -9
  171. data/node_modules/find-up/package.json +53 -53
  172. data/node_modules/find-up/readme.md +156 -156
  173. data/node_modules/fs-constants/LICENSE +21 -21
  174. data/node_modules/fs-constants/README.md +26 -26
  175. data/node_modules/fs-constants/browser.js +1 -1
  176. data/node_modules/fs-constants/index.js +1 -1
  177. data/node_modules/fs-constants/package.json +19 -19
  178. data/node_modules/fs.realpath/LICENSE +43 -43
  179. data/node_modules/fs.realpath/README.md +33 -33
  180. data/node_modules/fs.realpath/index.js +66 -66
  181. data/node_modules/fs.realpath/old.js +303 -303
  182. data/node_modules/fs.realpath/package.json +26 -26
  183. data/node_modules/get-stream/buffer-stream.js +52 -52
  184. data/node_modules/get-stream/index.d.ts +108 -108
  185. data/node_modules/get-stream/index.js +60 -60
  186. data/node_modules/get-stream/license +9 -9
  187. data/node_modules/get-stream/package.json +50 -50
  188. data/node_modules/get-stream/readme.md +124 -124
  189. data/node_modules/glob/LICENSE +21 -21
  190. data/node_modules/glob/README.md +375 -375
  191. data/node_modules/glob/changelog.md +67 -67
  192. data/node_modules/glob/common.js +234 -234
  193. data/node_modules/glob/glob.js +788 -788
  194. data/node_modules/glob/package.json +51 -51
  195. data/node_modules/glob/sync.js +484 -484
  196. data/node_modules/https-proxy-agent/README.md +137 -137
  197. data/node_modules/https-proxy-agent/dist/agent.d.ts +30 -30
  198. data/node_modules/https-proxy-agent/dist/agent.js +179 -179
  199. data/node_modules/https-proxy-agent/dist/index.d.ts +23 -23
  200. data/node_modules/https-proxy-agent/dist/index.js +13 -13
  201. data/node_modules/https-proxy-agent/dist/parse-proxy-response.d.ts +7 -7
  202. data/node_modules/https-proxy-agent/dist/parse-proxy-response.js +65 -65
  203. data/node_modules/https-proxy-agent/package.json +56 -56
  204. data/node_modules/ieee754/LICENSE +11 -11
  205. data/node_modules/ieee754/README.md +51 -51
  206. data/node_modules/ieee754/index.d.ts +9 -9
  207. data/node_modules/ieee754/index.js +85 -85
  208. data/node_modules/ieee754/package.json +52 -52
  209. data/node_modules/inflight/LICENSE +15 -15
  210. data/node_modules/inflight/README.md +37 -37
  211. data/node_modules/inflight/inflight.js +54 -54
  212. data/node_modules/inflight/package.json +29 -29
  213. data/node_modules/inherits/LICENSE +16 -16
  214. data/node_modules/inherits/README.md +42 -42
  215. data/node_modules/inherits/inherits.js +9 -9
  216. data/node_modules/inherits/inherits_browser.js +27 -27
  217. data/node_modules/inherits/package.json +29 -29
  218. data/node_modules/locate-path/index.d.ts +83 -83
  219. data/node_modules/locate-path/index.js +65 -65
  220. data/node_modules/locate-path/license +9 -9
  221. data/node_modules/locate-path/package.json +45 -45
  222. data/node_modules/locate-path/readme.md +122 -122
  223. data/node_modules/minimatch/LICENSE +15 -15
  224. data/node_modules/minimatch/README.md +209 -209
  225. data/node_modules/minimatch/minimatch.js +923 -923
  226. data/node_modules/minimatch/package.json +30 -30
  227. data/node_modules/mkdirp-classic/LICENSE +21 -21
  228. data/node_modules/mkdirp-classic/README.md +18 -18
  229. data/node_modules/mkdirp-classic/index.js +98 -98
  230. data/node_modules/mkdirp-classic/package.json +18 -18
  231. data/node_modules/ms/index.js +162 -162
  232. data/node_modules/ms/license.md +21 -21
  233. data/node_modules/ms/package.json +37 -37
  234. data/node_modules/ms/readme.md +60 -60
  235. data/node_modules/node-fetch/LICENSE.md +22 -22
  236. data/node_modules/node-fetch/README.md +590 -590
  237. data/node_modules/node-fetch/browser.js +24 -24
  238. data/node_modules/node-fetch/lib/index.es.js +1662 -1662
  239. data/node_modules/node-fetch/lib/index.js +1671 -1671
  240. data/node_modules/node-fetch/lib/index.mjs +1660 -1660
  241. data/node_modules/node-fetch/package.json +68 -68
  242. data/node_modules/once/LICENSE +15 -15
  243. data/node_modules/once/README.md +79 -79
  244. data/node_modules/once/once.js +42 -42
  245. data/node_modules/once/package.json +33 -33
  246. data/node_modules/p-limit/index.d.ts +38 -38
  247. data/node_modules/p-limit/index.js +57 -57
  248. data/node_modules/p-limit/license +9 -9
  249. data/node_modules/p-limit/package.json +52 -52
  250. data/node_modules/p-limit/readme.md +101 -101
  251. data/node_modules/p-locate/index.d.ts +64 -64
  252. data/node_modules/p-locate/index.js +52 -52
  253. data/node_modules/p-locate/license +9 -9
  254. data/node_modules/p-locate/package.json +53 -53
  255. data/node_modules/p-locate/readme.md +90 -90
  256. data/node_modules/p-try/index.d.ts +39 -39
  257. data/node_modules/p-try/index.js +9 -9
  258. data/node_modules/p-try/license +9 -9
  259. data/node_modules/p-try/package.json +42 -42
  260. data/node_modules/p-try/readme.md +58 -58
  261. data/node_modules/path-exists/index.d.ts +28 -28
  262. data/node_modules/path-exists/index.js +23 -23
  263. data/node_modules/path-exists/license +9 -9
  264. data/node_modules/path-exists/package.json +39 -39
  265. data/node_modules/path-exists/readme.md +52 -52
  266. data/node_modules/path-is-absolute/index.js +20 -20
  267. data/node_modules/path-is-absolute/license +21 -21
  268. data/node_modules/path-is-absolute/package.json +43 -43
  269. data/node_modules/path-is-absolute/readme.md +59 -59
  270. data/node_modules/pend/LICENSE +23 -23
  271. data/node_modules/pend/README.md +41 -41
  272. data/node_modules/pend/index.js +55 -55
  273. data/node_modules/pend/package.json +18 -18
  274. data/node_modules/pend/test.js +137 -137
  275. data/node_modules/pkg-dir/index.d.ts +44 -44
  276. data/node_modules/pkg-dir/index.js +17 -17
  277. data/node_modules/pkg-dir/license +9 -9
  278. data/node_modules/pkg-dir/package.json +56 -56
  279. data/node_modules/pkg-dir/readme.md +66 -66
  280. data/node_modules/progress/CHANGELOG.md +115 -115
  281. data/node_modules/progress/LICENSE +22 -22
  282. data/node_modules/progress/Makefile +8 -8
  283. data/node_modules/progress/Readme.md +146 -146
  284. data/node_modules/progress/index.js +1 -1
  285. data/node_modules/progress/lib/node-progress.js +236 -236
  286. data/node_modules/progress/package.json +26 -26
  287. data/node_modules/proxy-from-env/.eslintrc +29 -29
  288. data/node_modules/proxy-from-env/.travis.yml +10 -10
  289. data/node_modules/proxy-from-env/LICENSE +20 -20
  290. data/node_modules/proxy-from-env/README.md +131 -131
  291. data/node_modules/proxy-from-env/index.js +108 -108
  292. data/node_modules/proxy-from-env/package.json +34 -34
  293. data/node_modules/proxy-from-env/test.js +483 -483
  294. data/node_modules/pump/.travis.yml +5 -5
  295. data/node_modules/pump/LICENSE +20 -20
  296. data/node_modules/pump/README.md +65 -65
  297. data/node_modules/pump/index.js +82 -82
  298. data/node_modules/pump/package.json +24 -24
  299. data/node_modules/pump/test-browser.js +66 -66
  300. data/node_modules/pump/test-node.js +53 -53
  301. data/node_modules/puppeteer-core/CHANGELOG.md +319 -290
  302. data/node_modules/puppeteer-core/LICENSE +202 -202
  303. data/node_modules/puppeteer-core/README.md +481 -481
  304. data/node_modules/puppeteer-core/cjs-entry-core.js +29 -29
  305. data/node_modules/puppeteer-core/cjs-entry.js +29 -29
  306. data/node_modules/puppeteer-core/install.js +89 -89
  307. data/node_modules/puppeteer-core/lib/cjs/puppeteer/api-docs-entry.d.ts +110 -110
  308. data/node_modules/puppeteer-core/lib/cjs/puppeteer/api-docs-entry.js +80 -80
  309. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Accessibility.d.ts +175 -175
  310. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Accessibility.js +360 -360
  311. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/AriaQueryHandler.d.ts +20 -20
  312. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/AriaQueryHandler.js +84 -84
  313. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/AriaQueryHandler.js.map +1 -1
  314. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Browser.d.ts +455 -455
  315. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Browser.js +540 -540
  316. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/BrowserConnector.d.ts +53 -53
  317. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/BrowserConnector.js +97 -97
  318. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/BrowserWebSocketTransport.d.ts +25 -25
  319. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/BrowserWebSocketTransport.js +34 -34
  320. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.d.ts +135 -135
  321. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js +298 -298
  322. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/ConnectionTransport.d.ts +24 -24
  323. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/ConnectionTransport.js +17 -17
  324. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/ConsoleMessage.d.ts +72 -72
  325. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/ConsoleMessage.js +64 -64
  326. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Coverage.d.ts +204 -204
  327. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Coverage.js +335 -335
  328. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/DOMWorld.d.ts +175 -175
  329. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/DOMWorld.js +662 -662
  330. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Debug.d.ts +52 -52
  331. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Debug.js +81 -81
  332. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/DeviceDescriptors.d.ts +40 -40
  333. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/DeviceDescriptors.js +1070 -1070
  334. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Dialog.d.ts +74 -74
  335. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Dialog.js +97 -97
  336. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/EmulationManager.d.ts +24 -24
  337. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/EmulationManager.js +37 -37
  338. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Errors.d.ts +50 -50
  339. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Errors.js +56 -56
  340. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/EvalTypes.d.ts +60 -60
  341. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/EvalTypes.js +17 -17
  342. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/EventEmitter.d.ts +92 -92
  343. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/EventEmitter.js +116 -116
  344. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Events.d.ts +81 -81
  345. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Events.js +86 -86
  346. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/ExecutionContext.d.ts +193 -193
  347. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/ExecutionContext.js +321 -321
  348. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/FileChooser.d.ts +58 -58
  349. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/FileChooser.js +71 -71
  350. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/FrameManager.d.ts +744 -744
  351. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/FrameManager.js +1047 -1047
  352. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/FrameManager.js.map +1 -1
  353. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/HTTPRequest.d.ts +350 -345
  354. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/HTTPRequest.d.ts.map +1 -1
  355. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/HTTPRequest.js +549 -549
  356. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/HTTPRequest.js.map +1 -1
  357. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/HTTPResponse.d.ts +134 -125
  358. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/HTTPResponse.d.ts.map +1 -1
  359. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/HTTPResponse.js +184 -164
  360. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/HTTPResponse.js.map +1 -1
  361. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Input.d.ts +358 -358
  362. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Input.js +543 -543
  363. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/JSHandle.d.ts +490 -490
  364. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/JSHandle.js +827 -827
  365. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/LifecycleWatcher.d.ts +65 -65
  366. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/LifecycleWatcher.d.ts.map +1 -1
  367. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/LifecycleWatcher.js +149 -148
  368. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/LifecycleWatcher.js.map +1 -1
  369. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/NetworkConditions.d.ts +26 -26
  370. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/NetworkConditions.js +33 -33
  371. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/NetworkManager.d.ts +126 -97
  372. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/NetworkManager.d.ts.map +1 -1
  373. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/NetworkManager.js +467 -342
  374. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/NetworkManager.js.map +1 -1
  375. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/PDFOptions.d.ts +161 -161
  376. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/PDFOptions.js +34 -34
  377. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Page.d.ts +2055 -2055
  378. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Page.js +2533 -2533
  379. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Product.d.ts +20 -20
  380. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Product.js +17 -17
  381. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Puppeteer.d.ts +159 -159
  382. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Puppeteer.js +161 -161
  383. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/PuppeteerViewport.d.ts +51 -51
  384. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/PuppeteerViewport.js +2 -2
  385. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/QueryHandler.d.ts +64 -64
  386. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/QueryHandler.js +165 -165
  387. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/SecurityDetails.d.ts +60 -60
  388. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/SecurityDetails.js +76 -76
  389. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Target.d.ts +100 -100
  390. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Target.js +145 -145
  391. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/TaskQueue.d.ts +20 -20
  392. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/TaskQueue.js +29 -29
  393. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/TimeoutSettings.d.ts +27 -27
  394. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/TimeoutSettings.js +47 -47
  395. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Tracing.d.ts +46 -46
  396. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Tracing.js +109 -109
  397. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/USKeyboardLayout.d.ts +39 -39
  398. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/USKeyboardLayout.js +406 -406
  399. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/WebWorker.d.ts +98 -98
  400. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/WebWorker.js +112 -112
  401. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/assert.d.ts +22 -22
  402. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/assert.js +33 -33
  403. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/fetch.d.ts +16 -16
  404. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/fetch.js +43 -43
  405. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/helper.d.ts +84 -84
  406. data/node_modules/puppeteer-core/lib/cjs/puppeteer/common/helper.js +327 -327
  407. data/node_modules/puppeteer-core/lib/cjs/puppeteer/environment.d.ts +16 -16
  408. data/node_modules/puppeteer-core/lib/cjs/puppeteer/environment.js +19 -19
  409. data/node_modules/puppeteer-core/lib/cjs/puppeteer/global.d.ts +16 -16
  410. data/node_modules/puppeteer-core/lib/cjs/puppeteer/global.js +2 -2
  411. data/node_modules/puppeteer-core/lib/cjs/puppeteer/initialize-node.d.ts +17 -17
  412. data/node_modules/puppeteer-core/lib/cjs/puppeteer/initialize-node.js +44 -44
  413. data/node_modules/puppeteer-core/lib/cjs/puppeteer/initialize-web.d.ts +17 -17
  414. data/node_modules/puppeteer-core/lib/cjs/puppeteer/initialize-web.js +26 -26
  415. data/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserFetcher.d.ts +133 -133
  416. data/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserFetcher.js +500 -500
  417. data/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserRunner.d.ts +40 -39
  418. data/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserRunner.d.ts.map +1 -1
  419. data/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserRunner.js +256 -230
  420. data/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserRunner.js.map +1 -1
  421. data/node_modules/puppeteer-core/lib/cjs/puppeteer/node/LaunchOptions.d.ts +134 -134
  422. data/node_modules/puppeteer-core/lib/cjs/puppeteer/node/LaunchOptions.js +17 -17
  423. data/node_modules/puppeteer-core/lib/cjs/puppeteer/node/Launcher.d.ts +16 -16
  424. data/node_modules/puppeteer-core/lib/cjs/puppeteer/node/Launcher.d.ts.map +1 -1
  425. data/node_modules/puppeteer-core/lib/cjs/puppeteer/node/Launcher.js +655 -588
  426. data/node_modules/puppeteer-core/lib/cjs/puppeteer/node/Launcher.js.map +1 -1
  427. data/node_modules/puppeteer-core/lib/cjs/puppeteer/node/NodeWebSocketTransport.d.ts +26 -26
  428. data/node_modules/puppeteer-core/lib/cjs/puppeteer/node/NodeWebSocketTransport.js +47 -47
  429. data/node_modules/puppeteer-core/lib/cjs/puppeteer/node/PipeTransport.d.ts +29 -29
  430. data/node_modules/puppeteer-core/lib/cjs/puppeteer/node/PipeTransport.js +64 -64
  431. data/node_modules/puppeteer-core/lib/cjs/puppeteer/node/Puppeteer.d.ts +153 -153
  432. data/node_modules/puppeteer-core/lib/cjs/puppeteer/node/Puppeteer.js +188 -188
  433. data/node_modules/puppeteer-core/lib/cjs/puppeteer/node/install.d.ts +17 -17
  434. data/node_modules/puppeteer-core/lib/cjs/puppeteer/node/install.js +173 -173
  435. data/node_modules/puppeteer-core/lib/cjs/puppeteer/node-puppeteer-core.d.ts +17 -17
  436. data/node_modules/puppeteer-core/lib/cjs/puppeteer/node-puppeteer-core.js +24 -24
  437. data/node_modules/puppeteer-core/lib/cjs/puppeteer/node.d.ts +17 -17
  438. data/node_modules/puppeteer-core/lib/cjs/puppeteer/node.js +23 -23
  439. data/node_modules/puppeteer-core/lib/cjs/puppeteer/revisions.d.ts +21 -21
  440. data/node_modules/puppeteer-core/lib/cjs/puppeteer/revisions.js +22 -22
  441. data/node_modules/puppeteer-core/lib/cjs/puppeteer/web.d.ts +17 -17
  442. data/node_modules/puppeteer-core/lib/cjs/puppeteer/web.js +23 -23
  443. data/node_modules/puppeteer-core/lib/cjs/vendor/mitt/src/index.d.ts +27 -27
  444. data/node_modules/puppeteer-core/lib/cjs/vendor/mitt/src/index.js +56 -56
  445. data/node_modules/puppeteer-core/lib/esm/puppeteer/api-docs-entry.d.ts +110 -110
  446. data/node_modules/puppeteer-core/lib/esm/puppeteer/api-docs-entry.js +80 -80
  447. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/Accessibility.d.ts +175 -175
  448. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/Accessibility.js +356 -356
  449. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/AriaQueryHandler.d.ts +20 -20
  450. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/AriaQueryHandler.js +81 -81
  451. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/AriaQueryHandler.js.map +1 -1
  452. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/Browser.d.ts +455 -455
  453. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/Browser.js +535 -535
  454. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/BrowserConnector.d.ts +53 -53
  455. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/BrowserConnector.js +74 -74
  456. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/BrowserWebSocketTransport.d.ts +25 -25
  457. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/BrowserWebSocketTransport.js +30 -30
  458. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/Connection.d.ts +135 -135
  459. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/Connection.js +293 -293
  460. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/ConnectionTransport.d.ts +24 -24
  461. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/ConnectionTransport.js +16 -16
  462. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/ConsoleMessage.d.ts +72 -72
  463. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/ConsoleMessage.js +60 -60
  464. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/Coverage.d.ts +204 -204
  465. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/Coverage.js +329 -329
  466. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/DOMWorld.d.ts +175 -175
  467. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/DOMWorld.js +657 -657
  468. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/Debug.d.ts +52 -52
  469. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/Debug.js +77 -77
  470. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/DeviceDescriptors.d.ts +40 -40
  471. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/DeviceDescriptors.js +1067 -1067
  472. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/Dialog.d.ts +74 -74
  473. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/Dialog.js +93 -93
  474. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/EmulationManager.d.ts +24 -24
  475. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/EmulationManager.js +33 -33
  476. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/Errors.d.ts +50 -50
  477. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/Errors.js +50 -50
  478. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/EvalTypes.d.ts +60 -60
  479. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/EvalTypes.js +16 -16
  480. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/EventEmitter.d.ts +92 -92
  481. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/EventEmitter.js +109 -109
  482. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/Events.d.ts +81 -81
  483. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/Events.js +83 -83
  484. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/ExecutionContext.d.ts +193 -193
  485. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/ExecutionContext.js +317 -317
  486. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/FileChooser.d.ts +58 -58
  487. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/FileChooser.js +67 -67
  488. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/FrameManager.d.ts +744 -744
  489. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/FrameManager.js +1042 -1042
  490. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/FrameManager.js.map +1 -1
  491. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/HTTPRequest.d.ts +350 -345
  492. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/HTTPRequest.d.ts.map +1 -1
  493. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/HTTPRequest.js +545 -545
  494. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/HTTPRequest.js.map +1 -1
  495. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/HTTPResponse.d.ts +134 -125
  496. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/HTTPResponse.d.ts.map +1 -1
  497. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/HTTPResponse.js +180 -160
  498. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/HTTPResponse.js.map +1 -1
  499. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/Input.d.ts +358 -358
  500. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/Input.js +537 -537
  501. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/JSHandle.d.ts +490 -490
  502. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/JSHandle.js +802 -802
  503. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/LifecycleWatcher.d.ts +65 -65
  504. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/LifecycleWatcher.d.ts.map +1 -1
  505. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/LifecycleWatcher.js +145 -144
  506. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/LifecycleWatcher.js.map +1 -1
  507. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/NetworkConditions.d.ts +26 -26
  508. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/NetworkConditions.js +30 -30
  509. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/NetworkManager.d.ts +126 -97
  510. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/NetworkManager.d.ts.map +1 -1
  511. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/NetworkManager.js +463 -338
  512. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/NetworkManager.js.map +1 -1
  513. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/PDFOptions.d.ts +161 -161
  514. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/PDFOptions.js +31 -31
  515. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/Page.d.ts +2055 -2055
  516. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/Page.js +2529 -2529
  517. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/Product.d.ts +20 -20
  518. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/Product.js +16 -16
  519. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/Puppeteer.d.ts +159 -159
  520. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/Puppeteer.js +157 -157
  521. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/PuppeteerViewport.d.ts +51 -51
  522. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/PuppeteerViewport.js +1 -1
  523. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/QueryHandler.d.ts +64 -64
  524. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/QueryHandler.js +157 -157
  525. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/SecurityDetails.d.ts +60 -60
  526. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/SecurityDetails.js +72 -72
  527. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/Target.d.ts +100 -100
  528. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/Target.js +141 -141
  529. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/TaskQueue.d.ts +20 -20
  530. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/TaskQueue.js +25 -25
  531. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/TimeoutSettings.d.ts +27 -27
  532. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/TimeoutSettings.js +43 -43
  533. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/Tracing.d.ts +46 -46
  534. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/Tracing.js +105 -105
  535. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/USKeyboardLayout.d.ts +39 -39
  536. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/USKeyboardLayout.js +403 -403
  537. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/WebWorker.d.ts +98 -98
  538. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/WebWorker.js +108 -108
  539. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/assert.d.ts +22 -22
  540. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/assert.js +28 -28
  541. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/fetch.d.ts +16 -16
  542. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/fetch.js +20 -20
  543. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/helper.d.ts +84 -84
  544. data/node_modules/puppeteer-core/lib/esm/puppeteer/common/helper.js +305 -305
  545. data/node_modules/puppeteer-core/lib/esm/puppeteer/environment.d.ts +16 -16
  546. data/node_modules/puppeteer-core/lib/esm/puppeteer/environment.js +16 -16
  547. data/node_modules/puppeteer-core/lib/esm/puppeteer/global.d.ts +16 -16
  548. data/node_modules/puppeteer-core/lib/esm/puppeteer/global.js +1 -1
  549. data/node_modules/puppeteer-core/lib/esm/puppeteer/initialize-node.d.ts +17 -17
  550. data/node_modules/puppeteer-core/lib/esm/puppeteer/initialize-node.js +37 -37
  551. data/node_modules/puppeteer-core/lib/esm/puppeteer/initialize-web.d.ts +17 -17
  552. data/node_modules/puppeteer-core/lib/esm/puppeteer/initialize-web.js +22 -22
  553. data/node_modules/puppeteer-core/lib/esm/puppeteer/node/BrowserFetcher.d.ts +133 -133
  554. data/node_modules/puppeteer-core/lib/esm/puppeteer/node/BrowserFetcher.js +474 -474
  555. data/node_modules/puppeteer-core/lib/esm/puppeteer/node/BrowserRunner.d.ts +40 -39
  556. data/node_modules/puppeteer-core/lib/esm/puppeteer/node/BrowserRunner.d.ts.map +1 -1
  557. data/node_modules/puppeteer-core/lib/esm/puppeteer/node/BrowserRunner.js +230 -204
  558. data/node_modules/puppeteer-core/lib/esm/puppeteer/node/BrowserRunner.js.map +1 -1
  559. data/node_modules/puppeteer-core/lib/esm/puppeteer/node/LaunchOptions.d.ts +134 -134
  560. data/node_modules/puppeteer-core/lib/esm/puppeteer/node/LaunchOptions.js +16 -16
  561. data/node_modules/puppeteer-core/lib/esm/puppeteer/node/Launcher.d.ts +16 -16
  562. data/node_modules/puppeteer-core/lib/esm/puppeteer/node/Launcher.d.ts.map +1 -1
  563. data/node_modules/puppeteer-core/lib/esm/puppeteer/node/Launcher.js +633 -566
  564. data/node_modules/puppeteer-core/lib/esm/puppeteer/node/Launcher.js.map +1 -1
  565. data/node_modules/puppeteer-core/lib/esm/puppeteer/node/NodeWebSocketTransport.d.ts +26 -26
  566. data/node_modules/puppeteer-core/lib/esm/puppeteer/node/NodeWebSocketTransport.js +40 -40
  567. data/node_modules/puppeteer-core/lib/esm/puppeteer/node/PipeTransport.d.ts +29 -29
  568. data/node_modules/puppeteer-core/lib/esm/puppeteer/node/PipeTransport.js +60 -60
  569. data/node_modules/puppeteer-core/lib/esm/puppeteer/node/Puppeteer.d.ts +153 -153
  570. data/node_modules/puppeteer-core/lib/esm/puppeteer/node/Puppeteer.js +181 -181
  571. data/node_modules/puppeteer-core/lib/esm/puppeteer/node/install.d.ts +17 -17
  572. data/node_modules/puppeteer-core/lib/esm/puppeteer/node/install.js +165 -165
  573. data/node_modules/puppeteer-core/lib/esm/puppeteer/node-puppeteer-core.d.ts +17 -17
  574. data/node_modules/puppeteer-core/lib/esm/puppeteer/node-puppeteer-core.js +22 -22
  575. data/node_modules/puppeteer-core/lib/esm/puppeteer/node.d.ts +17 -17
  576. data/node_modules/puppeteer-core/lib/esm/puppeteer/node.js +21 -21
  577. data/node_modules/puppeteer-core/lib/esm/puppeteer/revisions.d.ts +21 -21
  578. data/node_modules/puppeteer-core/lib/esm/puppeteer/revisions.js +19 -19
  579. data/node_modules/puppeteer-core/lib/esm/puppeteer/web.d.ts +17 -17
  580. data/node_modules/puppeteer-core/lib/esm/puppeteer/web.js +21 -21
  581. data/node_modules/puppeteer-core/lib/esm/vendor/mitt/src/index.d.ts +27 -27
  582. data/node_modules/puppeteer-core/lib/esm/vendor/mitt/src/index.js +53 -53
  583. data/node_modules/puppeteer-core/lib/types.d.ts +67 -25
  584. data/node_modules/puppeteer-core/package.json +115 -115
  585. data/node_modules/puppeteer-core/typescript-if-required.js +61 -61
  586. data/node_modules/readable-stream/CONTRIBUTING.md +38 -38
  587. data/node_modules/readable-stream/GOVERNANCE.md +136 -136
  588. data/node_modules/readable-stream/LICENSE +47 -47
  589. data/node_modules/readable-stream/README.md +106 -106
  590. data/node_modules/readable-stream/errors-browser.js +127 -127
  591. data/node_modules/readable-stream/errors.js +116 -116
  592. data/node_modules/readable-stream/experimentalWarning.js +17 -17
  593. data/node_modules/readable-stream/lib/_stream_duplex.js +138 -138
  594. data/node_modules/readable-stream/lib/_stream_passthrough.js +38 -38
  595. data/node_modules/readable-stream/lib/_stream_readable.js +1123 -1123
  596. data/node_modules/readable-stream/lib/_stream_transform.js +200 -200
  597. data/node_modules/readable-stream/lib/_stream_writable.js +696 -696
  598. data/node_modules/readable-stream/lib/internal/streams/async_iterator.js +206 -206
  599. data/node_modules/readable-stream/lib/internal/streams/buffer_list.js +209 -209
  600. data/node_modules/readable-stream/lib/internal/streams/destroy.js +104 -104
  601. data/node_modules/readable-stream/lib/internal/streams/end-of-stream.js +103 -103
  602. data/node_modules/readable-stream/lib/internal/streams/from-browser.js +3 -3
  603. data/node_modules/readable-stream/lib/internal/streams/from.js +63 -63
  604. data/node_modules/readable-stream/lib/internal/streams/pipeline.js +96 -96
  605. data/node_modules/readable-stream/lib/internal/streams/state.js +26 -26
  606. data/node_modules/readable-stream/lib/internal/streams/stream-browser.js +1 -1
  607. data/node_modules/readable-stream/lib/internal/streams/stream.js +1 -1
  608. data/node_modules/readable-stream/package.json +68 -68
  609. data/node_modules/readable-stream/readable-browser.js +9 -9
  610. data/node_modules/readable-stream/readable.js +16 -16
  611. data/node_modules/rimraf/CHANGELOG.md +65 -65
  612. data/node_modules/rimraf/LICENSE +15 -15
  613. data/node_modules/rimraf/README.md +101 -101
  614. data/node_modules/rimraf/bin.js +68 -68
  615. data/node_modules/rimraf/package.json +32 -32
  616. data/node_modules/rimraf/rimraf.js +360 -360
  617. data/node_modules/safe-buffer/LICENSE +21 -21
  618. data/node_modules/safe-buffer/README.md +584 -584
  619. data/node_modules/safe-buffer/index.d.ts +186 -186
  620. data/node_modules/safe-buffer/index.js +65 -65
  621. data/node_modules/safe-buffer/package.json +51 -51
  622. data/node_modules/string_decoder/LICENSE +48 -48
  623. data/node_modules/string_decoder/README.md +47 -47
  624. data/node_modules/string_decoder/lib/string_decoder.js +295 -295
  625. data/node_modules/string_decoder/package.json +34 -34
  626. data/node_modules/tar-fs/.travis.yml +6 -6
  627. data/node_modules/tar-fs/LICENSE +20 -20
  628. data/node_modules/tar-fs/README.md +165 -165
  629. data/node_modules/tar-fs/index.js +351 -351
  630. data/node_modules/tar-fs/package.json +41 -41
  631. data/node_modules/tar-fs/test/fixtures/a/hello.txt +1 -1
  632. data/node_modules/tar-fs/test/fixtures/b/a/test.txt +1 -1
  633. data/node_modules/tar-fs/test/index.js +346 -346
  634. data/node_modules/tar-stream/LICENSE +20 -20
  635. data/node_modules/tar-stream/README.md +168 -168
  636. data/node_modules/tar-stream/extract.js +257 -257
  637. data/node_modules/tar-stream/headers.js +295 -295
  638. data/node_modules/tar-stream/index.js +2 -2
  639. data/node_modules/tar-stream/pack.js +255 -255
  640. data/node_modules/tar-stream/package.json +58 -58
  641. data/node_modules/tar-stream/sandbox.js +11 -11
  642. data/node_modules/through/.travis.yml +5 -5
  643. data/node_modules/through/LICENSE.APACHE2 +15 -15
  644. data/node_modules/through/LICENSE.MIT +24 -24
  645. data/node_modules/through/index.js +108 -108
  646. data/node_modules/through/package.json +36 -36
  647. data/node_modules/through/readme.markdown +64 -64
  648. data/node_modules/through/test/async.js +28 -28
  649. data/node_modules/through/test/auto-destroy.js +30 -30
  650. data/node_modules/through/test/buffering.js +71 -71
  651. data/node_modules/through/test/end.js +45 -45
  652. data/node_modules/through/test/index.js +133 -133
  653. data/node_modules/tr46/.npmignore +4 -4
  654. data/node_modules/tr46/index.js +193 -193
  655. data/node_modules/tr46/package.json +31 -31
  656. data/node_modules/unbzip2-stream/LICENSE +24 -24
  657. data/node_modules/unbzip2-stream/README.md +59 -59
  658. data/node_modules/unbzip2-stream/dist/unbzip2-stream.min.js +1 -1
  659. data/node_modules/unbzip2-stream/index.js +93 -93
  660. data/node_modules/unbzip2-stream/lib/bit_iterator.js +39 -39
  661. data/node_modules/unbzip2-stream/lib/bzip2.js +365 -365
  662. data/node_modules/unbzip2-stream/package.json +51 -51
  663. data/node_modules/util-deprecate/History.md +16 -16
  664. data/node_modules/util-deprecate/LICENSE +24 -24
  665. data/node_modules/util-deprecate/README.md +53 -53
  666. data/node_modules/util-deprecate/browser.js +67 -67
  667. data/node_modules/util-deprecate/node.js +6 -6
  668. data/node_modules/util-deprecate/package.json +27 -27
  669. data/node_modules/webidl-conversions/LICENSE.md +12 -12
  670. data/node_modules/webidl-conversions/README.md +53 -53
  671. data/node_modules/webidl-conversions/lib/index.js +189 -189
  672. data/node_modules/webidl-conversions/package.json +23 -23
  673. data/node_modules/whatwg-url/LICENSE.txt +21 -21
  674. data/node_modules/whatwg-url/README.md +67 -67
  675. data/node_modules/whatwg-url/lib/URL-impl.js +200 -200
  676. data/node_modules/whatwg-url/lib/URL.js +196 -196
  677. data/node_modules/whatwg-url/lib/public-api.js +11 -11
  678. data/node_modules/whatwg-url/lib/utils.js +20 -20
  679. data/node_modules/whatwg-url/package.json +32 -32
  680. data/node_modules/wrappy/LICENSE +15 -15
  681. data/node_modules/wrappy/README.md +36 -36
  682. data/node_modules/wrappy/package.json +29 -29
  683. data/node_modules/wrappy/wrappy.js +33 -33
  684. data/node_modules/ws/LICENSE +19 -19
  685. data/node_modules/ws/README.md +493 -493
  686. data/node_modules/ws/browser.js +8 -8
  687. data/node_modules/ws/index.js +13 -13
  688. data/node_modules/ws/lib/buffer-util.js +126 -126
  689. data/node_modules/ws/lib/constants.js +12 -12
  690. data/node_modules/ws/lib/event-target.js +266 -266
  691. data/node_modules/ws/lib/extension.js +203 -203
  692. data/node_modules/ws/lib/limiter.js +55 -55
  693. data/node_modules/ws/lib/permessage-deflate.js +511 -511
  694. data/node_modules/ws/lib/receiver.js +612 -612
  695. data/node_modules/ws/lib/sender.js +422 -422
  696. data/node_modules/ws/lib/stream.js +180 -180
  697. data/node_modules/ws/lib/subprotocol.js +62 -62
  698. data/node_modules/ws/lib/validation.js +124 -124
  699. data/node_modules/ws/lib/websocket-server.js +485 -485
  700. data/node_modules/ws/lib/websocket.js +1149 -1149
  701. data/node_modules/ws/package.json +61 -61
  702. data/node_modules/ws/wrapper.mjs +8 -8
  703. data/node_modules/yauzl/LICENSE +21 -21
  704. data/node_modules/yauzl/README.md +658 -658
  705. data/node_modules/yauzl/index.js +796 -796
  706. data/node_modules/yauzl/package.json +40 -40
  707. data/package.json +1 -1
  708. metadata +23 -25
  709. data/node_modules/devtools-protocol/changelog.md +0 -10491
  710. data/node_modules/devtools-protocol/externs/protocol_externs.js +0 -9734
@@ -1,1662 +1,1662 @@
1
- process.emitWarning("The .es.js file is deprecated. Use .mjs instead.");
2
-
3
- import Stream from 'stream';
4
- import http from 'http';
5
- import Url from 'url';
6
- import whatwgUrl from 'whatwg-url';
7
- import https from 'https';
8
- import zlib from 'zlib';
9
-
10
- // Based on https://github.com/tmpvar/jsdom/blob/aa85b2abf07766ff7bf5c1f6daafb3726f2f2db5/lib/jsdom/living/blob.js
11
-
12
- // fix for "Readable" isn't a named export issue
13
- const Readable = Stream.Readable;
14
-
15
- const BUFFER = Symbol('buffer');
16
- const TYPE = Symbol('type');
17
-
18
- class Blob {
19
- constructor() {
20
- this[TYPE] = '';
21
-
22
- const blobParts = arguments[0];
23
- const options = arguments[1];
24
-
25
- const buffers = [];
26
- let size = 0;
27
-
28
- if (blobParts) {
29
- const a = blobParts;
30
- const length = Number(a.length);
31
- for (let i = 0; i < length; i++) {
32
- const element = a[i];
33
- let buffer;
34
- if (element instanceof Buffer) {
35
- buffer = element;
36
- } else if (ArrayBuffer.isView(element)) {
37
- buffer = Buffer.from(element.buffer, element.byteOffset, element.byteLength);
38
- } else if (element instanceof ArrayBuffer) {
39
- buffer = Buffer.from(element);
40
- } else if (element instanceof Blob) {
41
- buffer = element[BUFFER];
42
- } else {
43
- buffer = Buffer.from(typeof element === 'string' ? element : String(element));
44
- }
45
- size += buffer.length;
46
- buffers.push(buffer);
47
- }
48
- }
49
-
50
- this[BUFFER] = Buffer.concat(buffers);
51
-
52
- let type = options && options.type !== undefined && String(options.type).toLowerCase();
53
- if (type && !/[^\u0020-\u007E]/.test(type)) {
54
- this[TYPE] = type;
55
- }
56
- }
57
- get size() {
58
- return this[BUFFER].length;
59
- }
60
- get type() {
61
- return this[TYPE];
62
- }
63
- text() {
64
- return Promise.resolve(this[BUFFER].toString());
65
- }
66
- arrayBuffer() {
67
- const buf = this[BUFFER];
68
- const ab = buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
69
- return Promise.resolve(ab);
70
- }
71
- stream() {
72
- const readable = new Readable();
73
- readable._read = function () {};
74
- readable.push(this[BUFFER]);
75
- readable.push(null);
76
- return readable;
77
- }
78
- toString() {
79
- return '[object Blob]';
80
- }
81
- slice() {
82
- const size = this.size;
83
-
84
- const start = arguments[0];
85
- const end = arguments[1];
86
- let relativeStart, relativeEnd;
87
- if (start === undefined) {
88
- relativeStart = 0;
89
- } else if (start < 0) {
90
- relativeStart = Math.max(size + start, 0);
91
- } else {
92
- relativeStart = Math.min(start, size);
93
- }
94
- if (end === undefined) {
95
- relativeEnd = size;
96
- } else if (end < 0) {
97
- relativeEnd = Math.max(size + end, 0);
98
- } else {
99
- relativeEnd = Math.min(end, size);
100
- }
101
- const span = Math.max(relativeEnd - relativeStart, 0);
102
-
103
- const buffer = this[BUFFER];
104
- const slicedBuffer = buffer.slice(relativeStart, relativeStart + span);
105
- const blob = new Blob([], { type: arguments[2] });
106
- blob[BUFFER] = slicedBuffer;
107
- return blob;
108
- }
109
- }
110
-
111
- Object.defineProperties(Blob.prototype, {
112
- size: { enumerable: true },
113
- type: { enumerable: true },
114
- slice: { enumerable: true }
115
- });
116
-
117
- Object.defineProperty(Blob.prototype, Symbol.toStringTag, {
118
- value: 'Blob',
119
- writable: false,
120
- enumerable: false,
121
- configurable: true
122
- });
123
-
124
- /**
125
- * fetch-error.js
126
- *
127
- * FetchError interface for operational errors
128
- */
129
-
130
- /**
131
- * Create FetchError instance
132
- *
133
- * @param String message Error message for human
134
- * @param String type Error type for machine
135
- * @param String systemError For Node.js system error
136
- * @return FetchError
137
- */
138
- function FetchError(message, type, systemError) {
139
- Error.call(this, message);
140
-
141
- this.message = message;
142
- this.type = type;
143
-
144
- // when err.type is `system`, err.code contains system error code
145
- if (systemError) {
146
- this.code = this.errno = systemError.code;
147
- }
148
-
149
- // hide custom error implementation details from end-users
150
- Error.captureStackTrace(this, this.constructor);
151
- }
152
-
153
- FetchError.prototype = Object.create(Error.prototype);
154
- FetchError.prototype.constructor = FetchError;
155
- FetchError.prototype.name = 'FetchError';
156
-
157
- let convert;
158
- try {
159
- convert = require('encoding').convert;
160
- } catch (e) {}
161
-
162
- const INTERNALS = Symbol('Body internals');
163
-
164
- // fix an issue where "PassThrough" isn't a named export for node <10
165
- const PassThrough = Stream.PassThrough;
166
-
167
- /**
168
- * Body mixin
169
- *
170
- * Ref: https://fetch.spec.whatwg.org/#body
171
- *
172
- * @param Stream body Readable stream
173
- * @param Object opts Response options
174
- * @return Void
175
- */
176
- function Body(body) {
177
- var _this = this;
178
-
179
- var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
180
- _ref$size = _ref.size;
181
-
182
- let size = _ref$size === undefined ? 0 : _ref$size;
183
- var _ref$timeout = _ref.timeout;
184
- let timeout = _ref$timeout === undefined ? 0 : _ref$timeout;
185
-
186
- if (body == null) {
187
- // body is undefined or null
188
- body = null;
189
- } else if (isURLSearchParams(body)) {
190
- // body is a URLSearchParams
191
- body = Buffer.from(body.toString());
192
- } else if (isBlob(body)) ; else if (Buffer.isBuffer(body)) ; else if (Object.prototype.toString.call(body) === '[object ArrayBuffer]') {
193
- // body is ArrayBuffer
194
- body = Buffer.from(body);
195
- } else if (ArrayBuffer.isView(body)) {
196
- // body is ArrayBufferView
197
- body = Buffer.from(body.buffer, body.byteOffset, body.byteLength);
198
- } else if (body instanceof Stream) ; else {
199
- // none of the above
200
- // coerce to string then buffer
201
- body = Buffer.from(String(body));
202
- }
203
- this[INTERNALS] = {
204
- body,
205
- disturbed: false,
206
- error: null
207
- };
208
- this.size = size;
209
- this.timeout = timeout;
210
-
211
- if (body instanceof Stream) {
212
- body.on('error', function (err) {
213
- const error = err.name === 'AbortError' ? err : new FetchError(`Invalid response body while trying to fetch ${_this.url}: ${err.message}`, 'system', err);
214
- _this[INTERNALS].error = error;
215
- });
216
- }
217
- }
218
-
219
- Body.prototype = {
220
- get body() {
221
- return this[INTERNALS].body;
222
- },
223
-
224
- get bodyUsed() {
225
- return this[INTERNALS].disturbed;
226
- },
227
-
228
- /**
229
- * Decode response as ArrayBuffer
230
- *
231
- * @return Promise
232
- */
233
- arrayBuffer() {
234
- return consumeBody.call(this).then(function (buf) {
235
- return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
236
- });
237
- },
238
-
239
- /**
240
- * Return raw response as Blob
241
- *
242
- * @return Promise
243
- */
244
- blob() {
245
- let ct = this.headers && this.headers.get('content-type') || '';
246
- return consumeBody.call(this).then(function (buf) {
247
- return Object.assign(
248
- // Prevent copying
249
- new Blob([], {
250
- type: ct.toLowerCase()
251
- }), {
252
- [BUFFER]: buf
253
- });
254
- });
255
- },
256
-
257
- /**
258
- * Decode response as json
259
- *
260
- * @return Promise
261
- */
262
- json() {
263
- var _this2 = this;
264
-
265
- return consumeBody.call(this).then(function (buffer) {
266
- try {
267
- return JSON.parse(buffer.toString());
268
- } catch (err) {
269
- return Body.Promise.reject(new FetchError(`invalid json response body at ${_this2.url} reason: ${err.message}`, 'invalid-json'));
270
- }
271
- });
272
- },
273
-
274
- /**
275
- * Decode response as text
276
- *
277
- * @return Promise
278
- */
279
- text() {
280
- return consumeBody.call(this).then(function (buffer) {
281
- return buffer.toString();
282
- });
283
- },
284
-
285
- /**
286
- * Decode response as buffer (non-spec api)
287
- *
288
- * @return Promise
289
- */
290
- buffer() {
291
- return consumeBody.call(this);
292
- },
293
-
294
- /**
295
- * Decode response as text, while automatically detecting the encoding and
296
- * trying to decode to UTF-8 (non-spec api)
297
- *
298
- * @return Promise
299
- */
300
- textConverted() {
301
- var _this3 = this;
302
-
303
- return consumeBody.call(this).then(function (buffer) {
304
- return convertBody(buffer, _this3.headers);
305
- });
306
- }
307
- };
308
-
309
- // In browsers, all properties are enumerable.
310
- Object.defineProperties(Body.prototype, {
311
- body: { enumerable: true },
312
- bodyUsed: { enumerable: true },
313
- arrayBuffer: { enumerable: true },
314
- blob: { enumerable: true },
315
- json: { enumerable: true },
316
- text: { enumerable: true }
317
- });
318
-
319
- Body.mixIn = function (proto) {
320
- for (const name of Object.getOwnPropertyNames(Body.prototype)) {
321
- // istanbul ignore else: future proof
322
- if (!(name in proto)) {
323
- const desc = Object.getOwnPropertyDescriptor(Body.prototype, name);
324
- Object.defineProperty(proto, name, desc);
325
- }
326
- }
327
- };
328
-
329
- /**
330
- * Consume and convert an entire Body to a Buffer.
331
- *
332
- * Ref: https://fetch.spec.whatwg.org/#concept-body-consume-body
333
- *
334
- * @return Promise
335
- */
336
- function consumeBody() {
337
- var _this4 = this;
338
-
339
- if (this[INTERNALS].disturbed) {
340
- return Body.Promise.reject(new TypeError(`body used already for: ${this.url}`));
341
- }
342
-
343
- this[INTERNALS].disturbed = true;
344
-
345
- if (this[INTERNALS].error) {
346
- return Body.Promise.reject(this[INTERNALS].error);
347
- }
348
-
349
- let body = this.body;
350
-
351
- // body is null
352
- if (body === null) {
353
- return Body.Promise.resolve(Buffer.alloc(0));
354
- }
355
-
356
- // body is blob
357
- if (isBlob(body)) {
358
- body = body.stream();
359
- }
360
-
361
- // body is buffer
362
- if (Buffer.isBuffer(body)) {
363
- return Body.Promise.resolve(body);
364
- }
365
-
366
- // istanbul ignore if: should never happen
367
- if (!(body instanceof Stream)) {
368
- return Body.Promise.resolve(Buffer.alloc(0));
369
- }
370
-
371
- // body is stream
372
- // get ready to actually consume the body
373
- let accum = [];
374
- let accumBytes = 0;
375
- let abort = false;
376
-
377
- return new Body.Promise(function (resolve, reject) {
378
- let resTimeout;
379
-
380
- // allow timeout on slow response body
381
- if (_this4.timeout) {
382
- resTimeout = setTimeout(function () {
383
- abort = true;
384
- reject(new FetchError(`Response timeout while trying to fetch ${_this4.url} (over ${_this4.timeout}ms)`, 'body-timeout'));
385
- }, _this4.timeout);
386
- }
387
-
388
- // handle stream errors
389
- body.on('error', function (err) {
390
- if (err.name === 'AbortError') {
391
- // if the request was aborted, reject with this Error
392
- abort = true;
393
- reject(err);
394
- } else {
395
- // other errors, such as incorrect content-encoding
396
- reject(new FetchError(`Invalid response body while trying to fetch ${_this4.url}: ${err.message}`, 'system', err));
397
- }
398
- });
399
-
400
- body.on('data', function (chunk) {
401
- if (abort || chunk === null) {
402
- return;
403
- }
404
-
405
- if (_this4.size && accumBytes + chunk.length > _this4.size) {
406
- abort = true;
407
- reject(new FetchError(`content size at ${_this4.url} over limit: ${_this4.size}`, 'max-size'));
408
- return;
409
- }
410
-
411
- accumBytes += chunk.length;
412
- accum.push(chunk);
413
- });
414
-
415
- body.on('end', function () {
416
- if (abort) {
417
- return;
418
- }
419
-
420
- clearTimeout(resTimeout);
421
-
422
- try {
423
- resolve(Buffer.concat(accum, accumBytes));
424
- } catch (err) {
425
- // handle streams that have accumulated too much data (issue #414)
426
- reject(new FetchError(`Could not create Buffer from response body for ${_this4.url}: ${err.message}`, 'system', err));
427
- }
428
- });
429
- });
430
- }
431
-
432
- /**
433
- * Detect buffer encoding and convert to target encoding
434
- * ref: http://www.w3.org/TR/2011/WD-html5-20110113/parsing.html#determining-the-character-encoding
435
- *
436
- * @param Buffer buffer Incoming buffer
437
- * @param String encoding Target encoding
438
- * @return String
439
- */
440
- function convertBody(buffer, headers) {
441
- if (typeof convert !== 'function') {
442
- throw new Error('The package `encoding` must be installed to use the textConverted() function');
443
- }
444
-
445
- const ct = headers.get('content-type');
446
- let charset = 'utf-8';
447
- let res, str;
448
-
449
- // header
450
- if (ct) {
451
- res = /charset=([^;]*)/i.exec(ct);
452
- }
453
-
454
- // no charset in content type, peek at response body for at most 1024 bytes
455
- str = buffer.slice(0, 1024).toString();
456
-
457
- // html5
458
- if (!res && str) {
459
- res = /<meta.+?charset=(['"])(.+?)\1/i.exec(str);
460
- }
461
-
462
- // html4
463
- if (!res && str) {
464
- res = /<meta[\s]+?http-equiv=(['"])content-type\1[\s]+?content=(['"])(.+?)\2/i.exec(str);
465
- if (!res) {
466
- res = /<meta[\s]+?content=(['"])(.+?)\1[\s]+?http-equiv=(['"])content-type\3/i.exec(str);
467
- if (res) {
468
- res.pop(); // drop last quote
469
- }
470
- }
471
-
472
- if (res) {
473
- res = /charset=(.*)/i.exec(res.pop());
474
- }
475
- }
476
-
477
- // xml
478
- if (!res && str) {
479
- res = /<\?xml.+?encoding=(['"])(.+?)\1/i.exec(str);
480
- }
481
-
482
- // found charset
483
- if (res) {
484
- charset = res.pop();
485
-
486
- // prevent decode issues when sites use incorrect encoding
487
- // ref: https://hsivonen.fi/encoding-menu/
488
- if (charset === 'gb2312' || charset === 'gbk') {
489
- charset = 'gb18030';
490
- }
491
- }
492
-
493
- // turn raw buffers into a single utf-8 buffer
494
- return convert(buffer, 'UTF-8', charset).toString();
495
- }
496
-
497
- /**
498
- * Detect a URLSearchParams object
499
- * ref: https://github.com/bitinn/node-fetch/issues/296#issuecomment-307598143
500
- *
501
- * @param Object obj Object to detect by type or brand
502
- * @return String
503
- */
504
- function isURLSearchParams(obj) {
505
- // Duck-typing as a necessary condition.
506
- if (typeof obj !== 'object' || typeof obj.append !== 'function' || typeof obj.delete !== 'function' || typeof obj.get !== 'function' || typeof obj.getAll !== 'function' || typeof obj.has !== 'function' || typeof obj.set !== 'function') {
507
- return false;
508
- }
509
-
510
- // Brand-checking and more duck-typing as optional condition.
511
- return obj.constructor.name === 'URLSearchParams' || Object.prototype.toString.call(obj) === '[object URLSearchParams]' || typeof obj.sort === 'function';
512
- }
513
-
514
- /**
515
- * Check if `obj` is a W3C `Blob` object (which `File` inherits from)
516
- * @param {*} obj
517
- * @return {boolean}
518
- */
519
- function isBlob(obj) {
520
- return typeof obj === 'object' && typeof obj.arrayBuffer === 'function' && typeof obj.type === 'string' && typeof obj.stream === 'function' && typeof obj.constructor === 'function' && typeof obj.constructor.name === 'string' && /^(Blob|File)$/.test(obj.constructor.name) && /^(Blob|File)$/.test(obj[Symbol.toStringTag]);
521
- }
522
-
523
- /**
524
- * Clone body given Res/Req instance
525
- *
526
- * @param Mixed instance Response or Request instance
527
- * @return Mixed
528
- */
529
- function clone(instance) {
530
- let p1, p2;
531
- let body = instance.body;
532
-
533
- // don't allow cloning a used body
534
- if (instance.bodyUsed) {
535
- throw new Error('cannot clone body after it is used');
536
- }
537
-
538
- // check that body is a stream and not form-data object
539
- // note: we can't clone the form-data object without having it as a dependency
540
- if (body instanceof Stream && typeof body.getBoundary !== 'function') {
541
- // tee instance body
542
- p1 = new PassThrough();
543
- p2 = new PassThrough();
544
- body.pipe(p1);
545
- body.pipe(p2);
546
- // set instance body to teed body and return the other teed body
547
- instance[INTERNALS].body = p1;
548
- body = p2;
549
- }
550
-
551
- return body;
552
- }
553
-
554
- /**
555
- * Performs the operation "extract a `Content-Type` value from |object|" as
556
- * specified in the specification:
557
- * https://fetch.spec.whatwg.org/#concept-bodyinit-extract
558
- *
559
- * This function assumes that instance.body is present.
560
- *
561
- * @param Mixed instance Any options.body input
562
- */
563
- function extractContentType(body) {
564
- if (body === null) {
565
- // body is null
566
- return null;
567
- } else if (typeof body === 'string') {
568
- // body is string
569
- return 'text/plain;charset=UTF-8';
570
- } else if (isURLSearchParams(body)) {
571
- // body is a URLSearchParams
572
- return 'application/x-www-form-urlencoded;charset=UTF-8';
573
- } else if (isBlob(body)) {
574
- // body is blob
575
- return body.type || null;
576
- } else if (Buffer.isBuffer(body)) {
577
- // body is buffer
578
- return null;
579
- } else if (Object.prototype.toString.call(body) === '[object ArrayBuffer]') {
580
- // body is ArrayBuffer
581
- return null;
582
- } else if (ArrayBuffer.isView(body)) {
583
- // body is ArrayBufferView
584
- return null;
585
- } else if (typeof body.getBoundary === 'function') {
586
- // detect form data input from form-data module
587
- return `multipart/form-data;boundary=${body.getBoundary()}`;
588
- } else if (body instanceof Stream) {
589
- // body is stream
590
- // can't really do much about this
591
- return null;
592
- } else {
593
- // Body constructor defaults other things to string
594
- return 'text/plain;charset=UTF-8';
595
- }
596
- }
597
-
598
- /**
599
- * The Fetch Standard treats this as if "total bytes" is a property on the body.
600
- * For us, we have to explicitly get it with a function.
601
- *
602
- * ref: https://fetch.spec.whatwg.org/#concept-body-total-bytes
603
- *
604
- * @param Body instance Instance of Body
605
- * @return Number? Number of bytes, or null if not possible
606
- */
607
- function getTotalBytes(instance) {
608
- const body = instance.body;
609
-
610
-
611
- if (body === null) {
612
- // body is null
613
- return 0;
614
- } else if (isBlob(body)) {
615
- return body.size;
616
- } else if (Buffer.isBuffer(body)) {
617
- // body is buffer
618
- return body.length;
619
- } else if (body && typeof body.getLengthSync === 'function') {
620
- // detect form data input from form-data module
621
- if (body._lengthRetrievers && body._lengthRetrievers.length == 0 || // 1.x
622
- body.hasKnownLength && body.hasKnownLength()) {
623
- // 2.x
624
- return body.getLengthSync();
625
- }
626
- return null;
627
- } else {
628
- // body is stream
629
- return null;
630
- }
631
- }
632
-
633
- /**
634
- * Write a Body to a Node.js WritableStream (e.g. http.Request) object.
635
- *
636
- * @param Body instance Instance of Body
637
- * @return Void
638
- */
639
- function writeToStream(dest, instance) {
640
- const body = instance.body;
641
-
642
-
643
- if (body === null) {
644
- // body is null
645
- dest.end();
646
- } else if (isBlob(body)) {
647
- body.stream().pipe(dest);
648
- } else if (Buffer.isBuffer(body)) {
649
- // body is buffer
650
- dest.write(body);
651
- dest.end();
652
- } else {
653
- // body is stream
654
- body.pipe(dest);
655
- }
656
- }
657
-
658
- // expose Promise
659
- Body.Promise = global.Promise;
660
-
661
- /**
662
- * headers.js
663
- *
664
- * Headers class offers convenient helpers
665
- */
666
-
667
- const invalidTokenRegex = /[^\^_`a-zA-Z\-0-9!#$%&'*+.|~]/;
668
- const invalidHeaderCharRegex = /[^\t\x20-\x7e\x80-\xff]/;
669
-
670
- function validateName(name) {
671
- name = `${name}`;
672
- if (invalidTokenRegex.test(name) || name === '') {
673
- throw new TypeError(`${name} is not a legal HTTP header name`);
674
- }
675
- }
676
-
677
- function validateValue(value) {
678
- value = `${value}`;
679
- if (invalidHeaderCharRegex.test(value)) {
680
- throw new TypeError(`${value} is not a legal HTTP header value`);
681
- }
682
- }
683
-
684
- /**
685
- * Find the key in the map object given a header name.
686
- *
687
- * Returns undefined if not found.
688
- *
689
- * @param String name Header name
690
- * @return String|Undefined
691
- */
692
- function find(map, name) {
693
- name = name.toLowerCase();
694
- for (const key in map) {
695
- if (key.toLowerCase() === name) {
696
- return key;
697
- }
698
- }
699
- return undefined;
700
- }
701
-
702
- const MAP = Symbol('map');
703
- class Headers {
704
- /**
705
- * Headers class
706
- *
707
- * @param Object headers Response headers
708
- * @return Void
709
- */
710
- constructor() {
711
- let init = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined;
712
-
713
- this[MAP] = Object.create(null);
714
-
715
- if (init instanceof Headers) {
716
- const rawHeaders = init.raw();
717
- const headerNames = Object.keys(rawHeaders);
718
-
719
- for (const headerName of headerNames) {
720
- for (const value of rawHeaders[headerName]) {
721
- this.append(headerName, value);
722
- }
723
- }
724
-
725
- return;
726
- }
727
-
728
- // We don't worry about converting prop to ByteString here as append()
729
- // will handle it.
730
- if (init == null) ; else if (typeof init === 'object') {
731
- const method = init[Symbol.iterator];
732
- if (method != null) {
733
- if (typeof method !== 'function') {
734
- throw new TypeError('Header pairs must be iterable');
735
- }
736
-
737
- // sequence<sequence<ByteString>>
738
- // Note: per spec we have to first exhaust the lists then process them
739
- const pairs = [];
740
- for (const pair of init) {
741
- if (typeof pair !== 'object' || typeof pair[Symbol.iterator] !== 'function') {
742
- throw new TypeError('Each header pair must be iterable');
743
- }
744
- pairs.push(Array.from(pair));
745
- }
746
-
747
- for (const pair of pairs) {
748
- if (pair.length !== 2) {
749
- throw new TypeError('Each header pair must be a name/value tuple');
750
- }
751
- this.append(pair[0], pair[1]);
752
- }
753
- } else {
754
- // record<ByteString, ByteString>
755
- for (const key of Object.keys(init)) {
756
- const value = init[key];
757
- this.append(key, value);
758
- }
759
- }
760
- } else {
761
- throw new TypeError('Provided initializer must be an object');
762
- }
763
- }
764
-
765
- /**
766
- * Return combined header value given name
767
- *
768
- * @param String name Header name
769
- * @return Mixed
770
- */
771
- get(name) {
772
- name = `${name}`;
773
- validateName(name);
774
- const key = find(this[MAP], name);
775
- if (key === undefined) {
776
- return null;
777
- }
778
-
779
- return this[MAP][key].join(', ');
780
- }
781
-
782
- /**
783
- * Iterate over all headers
784
- *
785
- * @param Function callback Executed for each item with parameters (value, name, thisArg)
786
- * @param Boolean thisArg `this` context for callback function
787
- * @return Void
788
- */
789
- forEach(callback) {
790
- let thisArg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
791
-
792
- let pairs = getHeaders(this);
793
- let i = 0;
794
- while (i < pairs.length) {
795
- var _pairs$i = pairs[i];
796
- const name = _pairs$i[0],
797
- value = _pairs$i[1];
798
-
799
- callback.call(thisArg, value, name, this);
800
- pairs = getHeaders(this);
801
- i++;
802
- }
803
- }
804
-
805
- /**
806
- * Overwrite header values given name
807
- *
808
- * @param String name Header name
809
- * @param String value Header value
810
- * @return Void
811
- */
812
- set(name, value) {
813
- name = `${name}`;
814
- value = `${value}`;
815
- validateName(name);
816
- validateValue(value);
817
- const key = find(this[MAP], name);
818
- this[MAP][key !== undefined ? key : name] = [value];
819
- }
820
-
821
- /**
822
- * Append a value onto existing header
823
- *
824
- * @param String name Header name
825
- * @param String value Header value
826
- * @return Void
827
- */
828
- append(name, value) {
829
- name = `${name}`;
830
- value = `${value}`;
831
- validateName(name);
832
- validateValue(value);
833
- const key = find(this[MAP], name);
834
- if (key !== undefined) {
835
- this[MAP][key].push(value);
836
- } else {
837
- this[MAP][name] = [value];
838
- }
839
- }
840
-
841
- /**
842
- * Check for header name existence
843
- *
844
- * @param String name Header name
845
- * @return Boolean
846
- */
847
- has(name) {
848
- name = `${name}`;
849
- validateName(name);
850
- return find(this[MAP], name) !== undefined;
851
- }
852
-
853
- /**
854
- * Delete all header values given name
855
- *
856
- * @param String name Header name
857
- * @return Void
858
- */
859
- delete(name) {
860
- name = `${name}`;
861
- validateName(name);
862
- const key = find(this[MAP], name);
863
- if (key !== undefined) {
864
- delete this[MAP][key];
865
- }
866
- }
867
-
868
- /**
869
- * Return raw headers (non-spec api)
870
- *
871
- * @return Object
872
- */
873
- raw() {
874
- return this[MAP];
875
- }
876
-
877
- /**
878
- * Get an iterator on keys.
879
- *
880
- * @return Iterator
881
- */
882
- keys() {
883
- return createHeadersIterator(this, 'key');
884
- }
885
-
886
- /**
887
- * Get an iterator on values.
888
- *
889
- * @return Iterator
890
- */
891
- values() {
892
- return createHeadersIterator(this, 'value');
893
- }
894
-
895
- /**
896
- * Get an iterator on entries.
897
- *
898
- * This is the default iterator of the Headers object.
899
- *
900
- * @return Iterator
901
- */
902
- [Symbol.iterator]() {
903
- return createHeadersIterator(this, 'key+value');
904
- }
905
- }
906
- Headers.prototype.entries = Headers.prototype[Symbol.iterator];
907
-
908
- Object.defineProperty(Headers.prototype, Symbol.toStringTag, {
909
- value: 'Headers',
910
- writable: false,
911
- enumerable: false,
912
- configurable: true
913
- });
914
-
915
- Object.defineProperties(Headers.prototype, {
916
- get: { enumerable: true },
917
- forEach: { enumerable: true },
918
- set: { enumerable: true },
919
- append: { enumerable: true },
920
- has: { enumerable: true },
921
- delete: { enumerable: true },
922
- keys: { enumerable: true },
923
- values: { enumerable: true },
924
- entries: { enumerable: true }
925
- });
926
-
927
- function getHeaders(headers) {
928
- let kind = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'key+value';
929
-
930
- const keys = Object.keys(headers[MAP]).sort();
931
- return keys.map(kind === 'key' ? function (k) {
932
- return k.toLowerCase();
933
- } : kind === 'value' ? function (k) {
934
- return headers[MAP][k].join(', ');
935
- } : function (k) {
936
- return [k.toLowerCase(), headers[MAP][k].join(', ')];
937
- });
938
- }
939
-
940
- const INTERNAL = Symbol('internal');
941
-
942
- function createHeadersIterator(target, kind) {
943
- const iterator = Object.create(HeadersIteratorPrototype);
944
- iterator[INTERNAL] = {
945
- target,
946
- kind,
947
- index: 0
948
- };
949
- return iterator;
950
- }
951
-
952
- const HeadersIteratorPrototype = Object.setPrototypeOf({
953
- next() {
954
- // istanbul ignore if
955
- if (!this || Object.getPrototypeOf(this) !== HeadersIteratorPrototype) {
956
- throw new TypeError('Value of `this` is not a HeadersIterator');
957
- }
958
-
959
- var _INTERNAL = this[INTERNAL];
960
- const target = _INTERNAL.target,
961
- kind = _INTERNAL.kind,
962
- index = _INTERNAL.index;
963
-
964
- const values = getHeaders(target, kind);
965
- const len = values.length;
966
- if (index >= len) {
967
- return {
968
- value: undefined,
969
- done: true
970
- };
971
- }
972
-
973
- this[INTERNAL].index = index + 1;
974
-
975
- return {
976
- value: values[index],
977
- done: false
978
- };
979
- }
980
- }, Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]())));
981
-
982
- Object.defineProperty(HeadersIteratorPrototype, Symbol.toStringTag, {
983
- value: 'HeadersIterator',
984
- writable: false,
985
- enumerable: false,
986
- configurable: true
987
- });
988
-
989
- /**
990
- * Export the Headers object in a form that Node.js can consume.
991
- *
992
- * @param Headers headers
993
- * @return Object
994
- */
995
- function exportNodeCompatibleHeaders(headers) {
996
- const obj = Object.assign({ __proto__: null }, headers[MAP]);
997
-
998
- // http.request() only supports string as Host header. This hack makes
999
- // specifying custom Host header possible.
1000
- const hostHeaderKey = find(headers[MAP], 'Host');
1001
- if (hostHeaderKey !== undefined) {
1002
- obj[hostHeaderKey] = obj[hostHeaderKey][0];
1003
- }
1004
-
1005
- return obj;
1006
- }
1007
-
1008
- /**
1009
- * Create a Headers object from an object of headers, ignoring those that do
1010
- * not conform to HTTP grammar productions.
1011
- *
1012
- * @param Object obj Object of headers
1013
- * @return Headers
1014
- */
1015
- function createHeadersLenient(obj) {
1016
- const headers = new Headers();
1017
- for (const name of Object.keys(obj)) {
1018
- if (invalidTokenRegex.test(name)) {
1019
- continue;
1020
- }
1021
- if (Array.isArray(obj[name])) {
1022
- for (const val of obj[name]) {
1023
- if (invalidHeaderCharRegex.test(val)) {
1024
- continue;
1025
- }
1026
- if (headers[MAP][name] === undefined) {
1027
- headers[MAP][name] = [val];
1028
- } else {
1029
- headers[MAP][name].push(val);
1030
- }
1031
- }
1032
- } else if (!invalidHeaderCharRegex.test(obj[name])) {
1033
- headers[MAP][name] = [obj[name]];
1034
- }
1035
- }
1036
- return headers;
1037
- }
1038
-
1039
- const INTERNALS$1 = Symbol('Response internals');
1040
-
1041
- // fix an issue where "STATUS_CODES" aren't a named export for node <10
1042
- const STATUS_CODES = http.STATUS_CODES;
1043
-
1044
- /**
1045
- * Response class
1046
- *
1047
- * @param Stream body Readable stream
1048
- * @param Object opts Response options
1049
- * @return Void
1050
- */
1051
- class Response {
1052
- constructor() {
1053
- let body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
1054
- let opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1055
-
1056
- Body.call(this, body, opts);
1057
-
1058
- const status = opts.status || 200;
1059
- const headers = new Headers(opts.headers);
1060
-
1061
- if (body != null && !headers.has('Content-Type')) {
1062
- const contentType = extractContentType(body);
1063
- if (contentType) {
1064
- headers.append('Content-Type', contentType);
1065
- }
1066
- }
1067
-
1068
- this[INTERNALS$1] = {
1069
- url: opts.url,
1070
- status,
1071
- statusText: opts.statusText || STATUS_CODES[status],
1072
- headers,
1073
- counter: opts.counter
1074
- };
1075
- }
1076
-
1077
- get url() {
1078
- return this[INTERNALS$1].url || '';
1079
- }
1080
-
1081
- get status() {
1082
- return this[INTERNALS$1].status;
1083
- }
1084
-
1085
- /**
1086
- * Convenience property representing if the request ended normally
1087
- */
1088
- get ok() {
1089
- return this[INTERNALS$1].status >= 200 && this[INTERNALS$1].status < 300;
1090
- }
1091
-
1092
- get redirected() {
1093
- return this[INTERNALS$1].counter > 0;
1094
- }
1095
-
1096
- get statusText() {
1097
- return this[INTERNALS$1].statusText;
1098
- }
1099
-
1100
- get headers() {
1101
- return this[INTERNALS$1].headers;
1102
- }
1103
-
1104
- /**
1105
- * Clone this response
1106
- *
1107
- * @return Response
1108
- */
1109
- clone() {
1110
- return new Response(clone(this), {
1111
- url: this.url,
1112
- status: this.status,
1113
- statusText: this.statusText,
1114
- headers: this.headers,
1115
- ok: this.ok,
1116
- redirected: this.redirected
1117
- });
1118
- }
1119
- }
1120
-
1121
- Body.mixIn(Response.prototype);
1122
-
1123
- Object.defineProperties(Response.prototype, {
1124
- url: { enumerable: true },
1125
- status: { enumerable: true },
1126
- ok: { enumerable: true },
1127
- redirected: { enumerable: true },
1128
- statusText: { enumerable: true },
1129
- headers: { enumerable: true },
1130
- clone: { enumerable: true }
1131
- });
1132
-
1133
- Object.defineProperty(Response.prototype, Symbol.toStringTag, {
1134
- value: 'Response',
1135
- writable: false,
1136
- enumerable: false,
1137
- configurable: true
1138
- });
1139
-
1140
- const INTERNALS$2 = Symbol('Request internals');
1141
- const URL = whatwgUrl.URL;
1142
-
1143
- // fix an issue where "format", "parse" aren't a named export for node <10
1144
- const parse_url = Url.parse;
1145
- const format_url = Url.format;
1146
-
1147
- /**
1148
- * Wrapper around `new URL` to handle arbitrary URLs
1149
- *
1150
- * @param {string} urlStr
1151
- * @return {void}
1152
- */
1153
- function parseURL(urlStr) {
1154
- /*
1155
- Check whether the URL is absolute or not
1156
- Scheme: https://tools.ietf.org/html/rfc3986#section-3.1
1157
- Absolute URL: https://tools.ietf.org/html/rfc3986#section-4.3
1158
- */
1159
- if (/^[a-zA-Z][a-zA-Z\d+\-.]*:/.exec(urlStr)) {
1160
- urlStr = new URL(urlStr).toString();
1161
- }
1162
-
1163
- // Fallback to old implementation for arbitrary URLs
1164
- return parse_url(urlStr);
1165
- }
1166
-
1167
- const streamDestructionSupported = 'destroy' in Stream.Readable.prototype;
1168
-
1169
- /**
1170
- * Check if a value is an instance of Request.
1171
- *
1172
- * @param Mixed input
1173
- * @return Boolean
1174
- */
1175
- function isRequest(input) {
1176
- return typeof input === 'object' && typeof input[INTERNALS$2] === 'object';
1177
- }
1178
-
1179
- function isAbortSignal(signal) {
1180
- const proto = signal && typeof signal === 'object' && Object.getPrototypeOf(signal);
1181
- return !!(proto && proto.constructor.name === 'AbortSignal');
1182
- }
1183
-
1184
- /**
1185
- * Request class
1186
- *
1187
- * @param Mixed input Url or Request instance
1188
- * @param Object init Custom options
1189
- * @return Void
1190
- */
1191
- class Request {
1192
- constructor(input) {
1193
- let init = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1194
-
1195
- let parsedURL;
1196
-
1197
- // normalize input
1198
- if (!isRequest(input)) {
1199
- if (input && input.href) {
1200
- // in order to support Node.js' Url objects; though WHATWG's URL objects
1201
- // will fall into this branch also (since their `toString()` will return
1202
- // `href` property anyway)
1203
- parsedURL = parseURL(input.href);
1204
- } else {
1205
- // coerce input to a string before attempting to parse
1206
- parsedURL = parseURL(`${input}`);
1207
- }
1208
- input = {};
1209
- } else {
1210
- parsedURL = parseURL(input.url);
1211
- }
1212
-
1213
- let method = init.method || input.method || 'GET';
1214
- method = method.toUpperCase();
1215
-
1216
- if ((init.body != null || isRequest(input) && input.body !== null) && (method === 'GET' || method === 'HEAD')) {
1217
- throw new TypeError('Request with GET/HEAD method cannot have body');
1218
- }
1219
-
1220
- let inputBody = init.body != null ? init.body : isRequest(input) && input.body !== null ? clone(input) : null;
1221
-
1222
- Body.call(this, inputBody, {
1223
- timeout: init.timeout || input.timeout || 0,
1224
- size: init.size || input.size || 0
1225
- });
1226
-
1227
- const headers = new Headers(init.headers || input.headers || {});
1228
-
1229
- if (inputBody != null && !headers.has('Content-Type')) {
1230
- const contentType = extractContentType(inputBody);
1231
- if (contentType) {
1232
- headers.append('Content-Type', contentType);
1233
- }
1234
- }
1235
-
1236
- let signal = isRequest(input) ? input.signal : null;
1237
- if ('signal' in init) signal = init.signal;
1238
-
1239
- if (signal != null && !isAbortSignal(signal)) {
1240
- throw new TypeError('Expected signal to be an instanceof AbortSignal');
1241
- }
1242
-
1243
- this[INTERNALS$2] = {
1244
- method,
1245
- redirect: init.redirect || input.redirect || 'follow',
1246
- headers,
1247
- parsedURL,
1248
- signal
1249
- };
1250
-
1251
- // node-fetch-only options
1252
- this.follow = init.follow !== undefined ? init.follow : input.follow !== undefined ? input.follow : 20;
1253
- this.compress = init.compress !== undefined ? init.compress : input.compress !== undefined ? input.compress : true;
1254
- this.counter = init.counter || input.counter || 0;
1255
- this.agent = init.agent || input.agent;
1256
- }
1257
-
1258
- get method() {
1259
- return this[INTERNALS$2].method;
1260
- }
1261
-
1262
- get url() {
1263
- return format_url(this[INTERNALS$2].parsedURL);
1264
- }
1265
-
1266
- get headers() {
1267
- return this[INTERNALS$2].headers;
1268
- }
1269
-
1270
- get redirect() {
1271
- return this[INTERNALS$2].redirect;
1272
- }
1273
-
1274
- get signal() {
1275
- return this[INTERNALS$2].signal;
1276
- }
1277
-
1278
- /**
1279
- * Clone this request
1280
- *
1281
- * @return Request
1282
- */
1283
- clone() {
1284
- return new Request(this);
1285
- }
1286
- }
1287
-
1288
- Body.mixIn(Request.prototype);
1289
-
1290
- Object.defineProperty(Request.prototype, Symbol.toStringTag, {
1291
- value: 'Request',
1292
- writable: false,
1293
- enumerable: false,
1294
- configurable: true
1295
- });
1296
-
1297
- Object.defineProperties(Request.prototype, {
1298
- method: { enumerable: true },
1299
- url: { enumerable: true },
1300
- headers: { enumerable: true },
1301
- redirect: { enumerable: true },
1302
- clone: { enumerable: true },
1303
- signal: { enumerable: true }
1304
- });
1305
-
1306
- /**
1307
- * Convert a Request to Node.js http request options.
1308
- *
1309
- * @param Request A Request instance
1310
- * @return Object The options object to be passed to http.request
1311
- */
1312
- function getNodeRequestOptions(request) {
1313
- const parsedURL = request[INTERNALS$2].parsedURL;
1314
- const headers = new Headers(request[INTERNALS$2].headers);
1315
-
1316
- // fetch step 1.3
1317
- if (!headers.has('Accept')) {
1318
- headers.set('Accept', '*/*');
1319
- }
1320
-
1321
- // Basic fetch
1322
- if (!parsedURL.protocol || !parsedURL.hostname) {
1323
- throw new TypeError('Only absolute URLs are supported');
1324
- }
1325
-
1326
- if (!/^https?:$/.test(parsedURL.protocol)) {
1327
- throw new TypeError('Only HTTP(S) protocols are supported');
1328
- }
1329
-
1330
- if (request.signal && request.body instanceof Stream.Readable && !streamDestructionSupported) {
1331
- throw new Error('Cancellation of streamed requests with AbortSignal is not supported in node < 8');
1332
- }
1333
-
1334
- // HTTP-network-or-cache fetch steps 2.4-2.7
1335
- let contentLengthValue = null;
1336
- if (request.body == null && /^(POST|PUT)$/i.test(request.method)) {
1337
- contentLengthValue = '0';
1338
- }
1339
- if (request.body != null) {
1340
- const totalBytes = getTotalBytes(request);
1341
- if (typeof totalBytes === 'number') {
1342
- contentLengthValue = String(totalBytes);
1343
- }
1344
- }
1345
- if (contentLengthValue) {
1346
- headers.set('Content-Length', contentLengthValue);
1347
- }
1348
-
1349
- // HTTP-network-or-cache fetch step 2.11
1350
- if (!headers.has('User-Agent')) {
1351
- headers.set('User-Agent', 'node-fetch/1.0 (+https://github.com/bitinn/node-fetch)');
1352
- }
1353
-
1354
- // HTTP-network-or-cache fetch step 2.15
1355
- if (request.compress && !headers.has('Accept-Encoding')) {
1356
- headers.set('Accept-Encoding', 'gzip,deflate');
1357
- }
1358
-
1359
- let agent = request.agent;
1360
- if (typeof agent === 'function') {
1361
- agent = agent(parsedURL);
1362
- }
1363
-
1364
- if (!headers.has('Connection') && !agent) {
1365
- headers.set('Connection', 'close');
1366
- }
1367
-
1368
- // HTTP-network fetch step 4.2
1369
- // chunked encoding is handled by Node.js
1370
-
1371
- return Object.assign({}, parsedURL, {
1372
- method: request.method,
1373
- headers: exportNodeCompatibleHeaders(headers),
1374
- agent
1375
- });
1376
- }
1377
-
1378
- /**
1379
- * abort-error.js
1380
- *
1381
- * AbortError interface for cancelled requests
1382
- */
1383
-
1384
- /**
1385
- * Create AbortError instance
1386
- *
1387
- * @param String message Error message for human
1388
- * @return AbortError
1389
- */
1390
- function AbortError(message) {
1391
- Error.call(this, message);
1392
-
1393
- this.type = 'aborted';
1394
- this.message = message;
1395
-
1396
- // hide custom error implementation details from end-users
1397
- Error.captureStackTrace(this, this.constructor);
1398
- }
1399
-
1400
- AbortError.prototype = Object.create(Error.prototype);
1401
- AbortError.prototype.constructor = AbortError;
1402
- AbortError.prototype.name = 'AbortError';
1403
-
1404
- // fix an issue where "PassThrough", "resolve" aren't a named export for node <10
1405
- const PassThrough$1 = Stream.PassThrough;
1406
- const resolve_url = Url.resolve;
1407
-
1408
- /**
1409
- * Fetch function
1410
- *
1411
- * @param Mixed url Absolute url or Request instance
1412
- * @param Object opts Fetch options
1413
- * @return Promise
1414
- */
1415
- function fetch(url, opts) {
1416
-
1417
- // allow custom promise
1418
- if (!fetch.Promise) {
1419
- throw new Error('native promise missing, set fetch.Promise to your favorite alternative');
1420
- }
1421
-
1422
- Body.Promise = fetch.Promise;
1423
-
1424
- // wrap http.request into fetch
1425
- return new fetch.Promise(function (resolve, reject) {
1426
- // build request object
1427
- const request = new Request(url, opts);
1428
- const options = getNodeRequestOptions(request);
1429
-
1430
- const send = (options.protocol === 'https:' ? https : http).request;
1431
- const signal = request.signal;
1432
-
1433
- let response = null;
1434
-
1435
- const abort = function abort() {
1436
- let error = new AbortError('The user aborted a request.');
1437
- reject(error);
1438
- if (request.body && request.body instanceof Stream.Readable) {
1439
- request.body.destroy(error);
1440
- }
1441
- if (!response || !response.body) return;
1442
- response.body.emit('error', error);
1443
- };
1444
-
1445
- if (signal && signal.aborted) {
1446
- abort();
1447
- return;
1448
- }
1449
-
1450
- const abortAndFinalize = function abortAndFinalize() {
1451
- abort();
1452
- finalize();
1453
- };
1454
-
1455
- // send request
1456
- const req = send(options);
1457
- let reqTimeout;
1458
-
1459
- if (signal) {
1460
- signal.addEventListener('abort', abortAndFinalize);
1461
- }
1462
-
1463
- function finalize() {
1464
- req.abort();
1465
- if (signal) signal.removeEventListener('abort', abortAndFinalize);
1466
- clearTimeout(reqTimeout);
1467
- }
1468
-
1469
- if (request.timeout) {
1470
- req.once('socket', function (socket) {
1471
- reqTimeout = setTimeout(function () {
1472
- reject(new FetchError(`network timeout at: ${request.url}`, 'request-timeout'));
1473
- finalize();
1474
- }, request.timeout);
1475
- });
1476
- }
1477
-
1478
- req.on('error', function (err) {
1479
- reject(new FetchError(`request to ${request.url} failed, reason: ${err.message}`, 'system', err));
1480
- finalize();
1481
- });
1482
-
1483
- req.on('response', function (res) {
1484
- clearTimeout(reqTimeout);
1485
-
1486
- const headers = createHeadersLenient(res.headers);
1487
-
1488
- // HTTP fetch step 5
1489
- if (fetch.isRedirect(res.statusCode)) {
1490
- // HTTP fetch step 5.2
1491
- const location = headers.get('Location');
1492
-
1493
- // HTTP fetch step 5.3
1494
- const locationURL = location === null ? null : resolve_url(request.url, location);
1495
-
1496
- // HTTP fetch step 5.5
1497
- switch (request.redirect) {
1498
- case 'error':
1499
- reject(new FetchError(`uri requested responds with a redirect, redirect mode is set to error: ${request.url}`, 'no-redirect'));
1500
- finalize();
1501
- return;
1502
- case 'manual':
1503
- // node-fetch-specific step: make manual redirect a bit easier to use by setting the Location header value to the resolved URL.
1504
- if (locationURL !== null) {
1505
- // handle corrupted header
1506
- try {
1507
- headers.set('Location', locationURL);
1508
- } catch (err) {
1509
- // istanbul ignore next: nodejs server prevent invalid response headers, we can't test this through normal request
1510
- reject(err);
1511
- }
1512
- }
1513
- break;
1514
- case 'follow':
1515
- // HTTP-redirect fetch step 2
1516
- if (locationURL === null) {
1517
- break;
1518
- }
1519
-
1520
- // HTTP-redirect fetch step 5
1521
- if (request.counter >= request.follow) {
1522
- reject(new FetchError(`maximum redirect reached at: ${request.url}`, 'max-redirect'));
1523
- finalize();
1524
- return;
1525
- }
1526
-
1527
- // HTTP-redirect fetch step 6 (counter increment)
1528
- // Create a new Request object.
1529
- const requestOpts = {
1530
- headers: new Headers(request.headers),
1531
- follow: request.follow,
1532
- counter: request.counter + 1,
1533
- agent: request.agent,
1534
- compress: request.compress,
1535
- method: request.method,
1536
- body: request.body,
1537
- signal: request.signal,
1538
- timeout: request.timeout,
1539
- size: request.size
1540
- };
1541
-
1542
- // HTTP-redirect fetch step 9
1543
- if (res.statusCode !== 303 && request.body && getTotalBytes(request) === null) {
1544
- reject(new FetchError('Cannot follow redirect with body being a readable stream', 'unsupported-redirect'));
1545
- finalize();
1546
- return;
1547
- }
1548
-
1549
- // HTTP-redirect fetch step 11
1550
- if (res.statusCode === 303 || (res.statusCode === 301 || res.statusCode === 302) && request.method === 'POST') {
1551
- requestOpts.method = 'GET';
1552
- requestOpts.body = undefined;
1553
- requestOpts.headers.delete('content-length');
1554
- }
1555
-
1556
- // HTTP-redirect fetch step 15
1557
- resolve(fetch(new Request(locationURL, requestOpts)));
1558
- finalize();
1559
- return;
1560
- }
1561
- }
1562
-
1563
- // prepare response
1564
- res.once('end', function () {
1565
- if (signal) signal.removeEventListener('abort', abortAndFinalize);
1566
- });
1567
- let body = res.pipe(new PassThrough$1());
1568
-
1569
- const response_options = {
1570
- url: request.url,
1571
- status: res.statusCode,
1572
- statusText: res.statusMessage,
1573
- headers: headers,
1574
- size: request.size,
1575
- timeout: request.timeout,
1576
- counter: request.counter
1577
- };
1578
-
1579
- // HTTP-network fetch step 12.1.1.3
1580
- const codings = headers.get('Content-Encoding');
1581
-
1582
- // HTTP-network fetch step 12.1.1.4: handle content codings
1583
-
1584
- // in following scenarios we ignore compression support
1585
- // 1. compression support is disabled
1586
- // 2. HEAD request
1587
- // 3. no Content-Encoding header
1588
- // 4. no content response (204)
1589
- // 5. content not modified response (304)
1590
- if (!request.compress || request.method === 'HEAD' || codings === null || res.statusCode === 204 || res.statusCode === 304) {
1591
- response = new Response(body, response_options);
1592
- resolve(response);
1593
- return;
1594
- }
1595
-
1596
- // For Node v6+
1597
- // Be less strict when decoding compressed responses, since sometimes
1598
- // servers send slightly invalid responses that are still accepted
1599
- // by common browsers.
1600
- // Always using Z_SYNC_FLUSH is what cURL does.
1601
- const zlibOptions = {
1602
- flush: zlib.Z_SYNC_FLUSH,
1603
- finishFlush: zlib.Z_SYNC_FLUSH
1604
- };
1605
-
1606
- // for gzip
1607
- if (codings == 'gzip' || codings == 'x-gzip') {
1608
- body = body.pipe(zlib.createGunzip(zlibOptions));
1609
- response = new Response(body, response_options);
1610
- resolve(response);
1611
- return;
1612
- }
1613
-
1614
- // for deflate
1615
- if (codings == 'deflate' || codings == 'x-deflate') {
1616
- // handle the infamous raw deflate response from old servers
1617
- // a hack for old IIS and Apache servers
1618
- const raw = res.pipe(new PassThrough$1());
1619
- raw.once('data', function (chunk) {
1620
- // see http://stackoverflow.com/questions/37519828
1621
- if ((chunk[0] & 0x0F) === 0x08) {
1622
- body = body.pipe(zlib.createInflate());
1623
- } else {
1624
- body = body.pipe(zlib.createInflateRaw());
1625
- }
1626
- response = new Response(body, response_options);
1627
- resolve(response);
1628
- });
1629
- return;
1630
- }
1631
-
1632
- // for br
1633
- if (codings == 'br' && typeof zlib.createBrotliDecompress === 'function') {
1634
- body = body.pipe(zlib.createBrotliDecompress());
1635
- response = new Response(body, response_options);
1636
- resolve(response);
1637
- return;
1638
- }
1639
-
1640
- // otherwise, use response as-is
1641
- response = new Response(body, response_options);
1642
- resolve(response);
1643
- });
1644
-
1645
- writeToStream(req, request);
1646
- });
1647
- }
1648
- /**
1649
- * Redirect code matching
1650
- *
1651
- * @param Number code Status code
1652
- * @return Boolean
1653
- */
1654
- fetch.isRedirect = function (code) {
1655
- return code === 301 || code === 302 || code === 303 || code === 307 || code === 308;
1656
- };
1657
-
1658
- // expose Promise
1659
- fetch.Promise = global.Promise;
1660
-
1661
- export default fetch;
1662
- export { Headers, Request, Response, FetchError };
1
+ process.emitWarning("The .es.js file is deprecated. Use .mjs instead.");
2
+
3
+ import Stream from 'stream';
4
+ import http from 'http';
5
+ import Url from 'url';
6
+ import whatwgUrl from 'whatwg-url';
7
+ import https from 'https';
8
+ import zlib from 'zlib';
9
+
10
+ // Based on https://github.com/tmpvar/jsdom/blob/aa85b2abf07766ff7bf5c1f6daafb3726f2f2db5/lib/jsdom/living/blob.js
11
+
12
+ // fix for "Readable" isn't a named export issue
13
+ const Readable = Stream.Readable;
14
+
15
+ const BUFFER = Symbol('buffer');
16
+ const TYPE = Symbol('type');
17
+
18
+ class Blob {
19
+ constructor() {
20
+ this[TYPE] = '';
21
+
22
+ const blobParts = arguments[0];
23
+ const options = arguments[1];
24
+
25
+ const buffers = [];
26
+ let size = 0;
27
+
28
+ if (blobParts) {
29
+ const a = blobParts;
30
+ const length = Number(a.length);
31
+ for (let i = 0; i < length; i++) {
32
+ const element = a[i];
33
+ let buffer;
34
+ if (element instanceof Buffer) {
35
+ buffer = element;
36
+ } else if (ArrayBuffer.isView(element)) {
37
+ buffer = Buffer.from(element.buffer, element.byteOffset, element.byteLength);
38
+ } else if (element instanceof ArrayBuffer) {
39
+ buffer = Buffer.from(element);
40
+ } else if (element instanceof Blob) {
41
+ buffer = element[BUFFER];
42
+ } else {
43
+ buffer = Buffer.from(typeof element === 'string' ? element : String(element));
44
+ }
45
+ size += buffer.length;
46
+ buffers.push(buffer);
47
+ }
48
+ }
49
+
50
+ this[BUFFER] = Buffer.concat(buffers);
51
+
52
+ let type = options && options.type !== undefined && String(options.type).toLowerCase();
53
+ if (type && !/[^\u0020-\u007E]/.test(type)) {
54
+ this[TYPE] = type;
55
+ }
56
+ }
57
+ get size() {
58
+ return this[BUFFER].length;
59
+ }
60
+ get type() {
61
+ return this[TYPE];
62
+ }
63
+ text() {
64
+ return Promise.resolve(this[BUFFER].toString());
65
+ }
66
+ arrayBuffer() {
67
+ const buf = this[BUFFER];
68
+ const ab = buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
69
+ return Promise.resolve(ab);
70
+ }
71
+ stream() {
72
+ const readable = new Readable();
73
+ readable._read = function () {};
74
+ readable.push(this[BUFFER]);
75
+ readable.push(null);
76
+ return readable;
77
+ }
78
+ toString() {
79
+ return '[object Blob]';
80
+ }
81
+ slice() {
82
+ const size = this.size;
83
+
84
+ const start = arguments[0];
85
+ const end = arguments[1];
86
+ let relativeStart, relativeEnd;
87
+ if (start === undefined) {
88
+ relativeStart = 0;
89
+ } else if (start < 0) {
90
+ relativeStart = Math.max(size + start, 0);
91
+ } else {
92
+ relativeStart = Math.min(start, size);
93
+ }
94
+ if (end === undefined) {
95
+ relativeEnd = size;
96
+ } else if (end < 0) {
97
+ relativeEnd = Math.max(size + end, 0);
98
+ } else {
99
+ relativeEnd = Math.min(end, size);
100
+ }
101
+ const span = Math.max(relativeEnd - relativeStart, 0);
102
+
103
+ const buffer = this[BUFFER];
104
+ const slicedBuffer = buffer.slice(relativeStart, relativeStart + span);
105
+ const blob = new Blob([], { type: arguments[2] });
106
+ blob[BUFFER] = slicedBuffer;
107
+ return blob;
108
+ }
109
+ }
110
+
111
+ Object.defineProperties(Blob.prototype, {
112
+ size: { enumerable: true },
113
+ type: { enumerable: true },
114
+ slice: { enumerable: true }
115
+ });
116
+
117
+ Object.defineProperty(Blob.prototype, Symbol.toStringTag, {
118
+ value: 'Blob',
119
+ writable: false,
120
+ enumerable: false,
121
+ configurable: true
122
+ });
123
+
124
+ /**
125
+ * fetch-error.js
126
+ *
127
+ * FetchError interface for operational errors
128
+ */
129
+
130
+ /**
131
+ * Create FetchError instance
132
+ *
133
+ * @param String message Error message for human
134
+ * @param String type Error type for machine
135
+ * @param String systemError For Node.js system error
136
+ * @return FetchError
137
+ */
138
+ function FetchError(message, type, systemError) {
139
+ Error.call(this, message);
140
+
141
+ this.message = message;
142
+ this.type = type;
143
+
144
+ // when err.type is `system`, err.code contains system error code
145
+ if (systemError) {
146
+ this.code = this.errno = systemError.code;
147
+ }
148
+
149
+ // hide custom error implementation details from end-users
150
+ Error.captureStackTrace(this, this.constructor);
151
+ }
152
+
153
+ FetchError.prototype = Object.create(Error.prototype);
154
+ FetchError.prototype.constructor = FetchError;
155
+ FetchError.prototype.name = 'FetchError';
156
+
157
+ let convert;
158
+ try {
159
+ convert = require('encoding').convert;
160
+ } catch (e) {}
161
+
162
+ const INTERNALS = Symbol('Body internals');
163
+
164
+ // fix an issue where "PassThrough" isn't a named export for node <10
165
+ const PassThrough = Stream.PassThrough;
166
+
167
+ /**
168
+ * Body mixin
169
+ *
170
+ * Ref: https://fetch.spec.whatwg.org/#body
171
+ *
172
+ * @param Stream body Readable stream
173
+ * @param Object opts Response options
174
+ * @return Void
175
+ */
176
+ function Body(body) {
177
+ var _this = this;
178
+
179
+ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
180
+ _ref$size = _ref.size;
181
+
182
+ let size = _ref$size === undefined ? 0 : _ref$size;
183
+ var _ref$timeout = _ref.timeout;
184
+ let timeout = _ref$timeout === undefined ? 0 : _ref$timeout;
185
+
186
+ if (body == null) {
187
+ // body is undefined or null
188
+ body = null;
189
+ } else if (isURLSearchParams(body)) {
190
+ // body is a URLSearchParams
191
+ body = Buffer.from(body.toString());
192
+ } else if (isBlob(body)) ; else if (Buffer.isBuffer(body)) ; else if (Object.prototype.toString.call(body) === '[object ArrayBuffer]') {
193
+ // body is ArrayBuffer
194
+ body = Buffer.from(body);
195
+ } else if (ArrayBuffer.isView(body)) {
196
+ // body is ArrayBufferView
197
+ body = Buffer.from(body.buffer, body.byteOffset, body.byteLength);
198
+ } else if (body instanceof Stream) ; else {
199
+ // none of the above
200
+ // coerce to string then buffer
201
+ body = Buffer.from(String(body));
202
+ }
203
+ this[INTERNALS] = {
204
+ body,
205
+ disturbed: false,
206
+ error: null
207
+ };
208
+ this.size = size;
209
+ this.timeout = timeout;
210
+
211
+ if (body instanceof Stream) {
212
+ body.on('error', function (err) {
213
+ const error = err.name === 'AbortError' ? err : new FetchError(`Invalid response body while trying to fetch ${_this.url}: ${err.message}`, 'system', err);
214
+ _this[INTERNALS].error = error;
215
+ });
216
+ }
217
+ }
218
+
219
+ Body.prototype = {
220
+ get body() {
221
+ return this[INTERNALS].body;
222
+ },
223
+
224
+ get bodyUsed() {
225
+ return this[INTERNALS].disturbed;
226
+ },
227
+
228
+ /**
229
+ * Decode response as ArrayBuffer
230
+ *
231
+ * @return Promise
232
+ */
233
+ arrayBuffer() {
234
+ return consumeBody.call(this).then(function (buf) {
235
+ return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
236
+ });
237
+ },
238
+
239
+ /**
240
+ * Return raw response as Blob
241
+ *
242
+ * @return Promise
243
+ */
244
+ blob() {
245
+ let ct = this.headers && this.headers.get('content-type') || '';
246
+ return consumeBody.call(this).then(function (buf) {
247
+ return Object.assign(
248
+ // Prevent copying
249
+ new Blob([], {
250
+ type: ct.toLowerCase()
251
+ }), {
252
+ [BUFFER]: buf
253
+ });
254
+ });
255
+ },
256
+
257
+ /**
258
+ * Decode response as json
259
+ *
260
+ * @return Promise
261
+ */
262
+ json() {
263
+ var _this2 = this;
264
+
265
+ return consumeBody.call(this).then(function (buffer) {
266
+ try {
267
+ return JSON.parse(buffer.toString());
268
+ } catch (err) {
269
+ return Body.Promise.reject(new FetchError(`invalid json response body at ${_this2.url} reason: ${err.message}`, 'invalid-json'));
270
+ }
271
+ });
272
+ },
273
+
274
+ /**
275
+ * Decode response as text
276
+ *
277
+ * @return Promise
278
+ */
279
+ text() {
280
+ return consumeBody.call(this).then(function (buffer) {
281
+ return buffer.toString();
282
+ });
283
+ },
284
+
285
+ /**
286
+ * Decode response as buffer (non-spec api)
287
+ *
288
+ * @return Promise
289
+ */
290
+ buffer() {
291
+ return consumeBody.call(this);
292
+ },
293
+
294
+ /**
295
+ * Decode response as text, while automatically detecting the encoding and
296
+ * trying to decode to UTF-8 (non-spec api)
297
+ *
298
+ * @return Promise
299
+ */
300
+ textConverted() {
301
+ var _this3 = this;
302
+
303
+ return consumeBody.call(this).then(function (buffer) {
304
+ return convertBody(buffer, _this3.headers);
305
+ });
306
+ }
307
+ };
308
+
309
+ // In browsers, all properties are enumerable.
310
+ Object.defineProperties(Body.prototype, {
311
+ body: { enumerable: true },
312
+ bodyUsed: { enumerable: true },
313
+ arrayBuffer: { enumerable: true },
314
+ blob: { enumerable: true },
315
+ json: { enumerable: true },
316
+ text: { enumerable: true }
317
+ });
318
+
319
+ Body.mixIn = function (proto) {
320
+ for (const name of Object.getOwnPropertyNames(Body.prototype)) {
321
+ // istanbul ignore else: future proof
322
+ if (!(name in proto)) {
323
+ const desc = Object.getOwnPropertyDescriptor(Body.prototype, name);
324
+ Object.defineProperty(proto, name, desc);
325
+ }
326
+ }
327
+ };
328
+
329
+ /**
330
+ * Consume and convert an entire Body to a Buffer.
331
+ *
332
+ * Ref: https://fetch.spec.whatwg.org/#concept-body-consume-body
333
+ *
334
+ * @return Promise
335
+ */
336
+ function consumeBody() {
337
+ var _this4 = this;
338
+
339
+ if (this[INTERNALS].disturbed) {
340
+ return Body.Promise.reject(new TypeError(`body used already for: ${this.url}`));
341
+ }
342
+
343
+ this[INTERNALS].disturbed = true;
344
+
345
+ if (this[INTERNALS].error) {
346
+ return Body.Promise.reject(this[INTERNALS].error);
347
+ }
348
+
349
+ let body = this.body;
350
+
351
+ // body is null
352
+ if (body === null) {
353
+ return Body.Promise.resolve(Buffer.alloc(0));
354
+ }
355
+
356
+ // body is blob
357
+ if (isBlob(body)) {
358
+ body = body.stream();
359
+ }
360
+
361
+ // body is buffer
362
+ if (Buffer.isBuffer(body)) {
363
+ return Body.Promise.resolve(body);
364
+ }
365
+
366
+ // istanbul ignore if: should never happen
367
+ if (!(body instanceof Stream)) {
368
+ return Body.Promise.resolve(Buffer.alloc(0));
369
+ }
370
+
371
+ // body is stream
372
+ // get ready to actually consume the body
373
+ let accum = [];
374
+ let accumBytes = 0;
375
+ let abort = false;
376
+
377
+ return new Body.Promise(function (resolve, reject) {
378
+ let resTimeout;
379
+
380
+ // allow timeout on slow response body
381
+ if (_this4.timeout) {
382
+ resTimeout = setTimeout(function () {
383
+ abort = true;
384
+ reject(new FetchError(`Response timeout while trying to fetch ${_this4.url} (over ${_this4.timeout}ms)`, 'body-timeout'));
385
+ }, _this4.timeout);
386
+ }
387
+
388
+ // handle stream errors
389
+ body.on('error', function (err) {
390
+ if (err.name === 'AbortError') {
391
+ // if the request was aborted, reject with this Error
392
+ abort = true;
393
+ reject(err);
394
+ } else {
395
+ // other errors, such as incorrect content-encoding
396
+ reject(new FetchError(`Invalid response body while trying to fetch ${_this4.url}: ${err.message}`, 'system', err));
397
+ }
398
+ });
399
+
400
+ body.on('data', function (chunk) {
401
+ if (abort || chunk === null) {
402
+ return;
403
+ }
404
+
405
+ if (_this4.size && accumBytes + chunk.length > _this4.size) {
406
+ abort = true;
407
+ reject(new FetchError(`content size at ${_this4.url} over limit: ${_this4.size}`, 'max-size'));
408
+ return;
409
+ }
410
+
411
+ accumBytes += chunk.length;
412
+ accum.push(chunk);
413
+ });
414
+
415
+ body.on('end', function () {
416
+ if (abort) {
417
+ return;
418
+ }
419
+
420
+ clearTimeout(resTimeout);
421
+
422
+ try {
423
+ resolve(Buffer.concat(accum, accumBytes));
424
+ } catch (err) {
425
+ // handle streams that have accumulated too much data (issue #414)
426
+ reject(new FetchError(`Could not create Buffer from response body for ${_this4.url}: ${err.message}`, 'system', err));
427
+ }
428
+ });
429
+ });
430
+ }
431
+
432
+ /**
433
+ * Detect buffer encoding and convert to target encoding
434
+ * ref: http://www.w3.org/TR/2011/WD-html5-20110113/parsing.html#determining-the-character-encoding
435
+ *
436
+ * @param Buffer buffer Incoming buffer
437
+ * @param String encoding Target encoding
438
+ * @return String
439
+ */
440
+ function convertBody(buffer, headers) {
441
+ if (typeof convert !== 'function') {
442
+ throw new Error('The package `encoding` must be installed to use the textConverted() function');
443
+ }
444
+
445
+ const ct = headers.get('content-type');
446
+ let charset = 'utf-8';
447
+ let res, str;
448
+
449
+ // header
450
+ if (ct) {
451
+ res = /charset=([^;]*)/i.exec(ct);
452
+ }
453
+
454
+ // no charset in content type, peek at response body for at most 1024 bytes
455
+ str = buffer.slice(0, 1024).toString();
456
+
457
+ // html5
458
+ if (!res && str) {
459
+ res = /<meta.+?charset=(['"])(.+?)\1/i.exec(str);
460
+ }
461
+
462
+ // html4
463
+ if (!res && str) {
464
+ res = /<meta[\s]+?http-equiv=(['"])content-type\1[\s]+?content=(['"])(.+?)\2/i.exec(str);
465
+ if (!res) {
466
+ res = /<meta[\s]+?content=(['"])(.+?)\1[\s]+?http-equiv=(['"])content-type\3/i.exec(str);
467
+ if (res) {
468
+ res.pop(); // drop last quote
469
+ }
470
+ }
471
+
472
+ if (res) {
473
+ res = /charset=(.*)/i.exec(res.pop());
474
+ }
475
+ }
476
+
477
+ // xml
478
+ if (!res && str) {
479
+ res = /<\?xml.+?encoding=(['"])(.+?)\1/i.exec(str);
480
+ }
481
+
482
+ // found charset
483
+ if (res) {
484
+ charset = res.pop();
485
+
486
+ // prevent decode issues when sites use incorrect encoding
487
+ // ref: https://hsivonen.fi/encoding-menu/
488
+ if (charset === 'gb2312' || charset === 'gbk') {
489
+ charset = 'gb18030';
490
+ }
491
+ }
492
+
493
+ // turn raw buffers into a single utf-8 buffer
494
+ return convert(buffer, 'UTF-8', charset).toString();
495
+ }
496
+
497
+ /**
498
+ * Detect a URLSearchParams object
499
+ * ref: https://github.com/bitinn/node-fetch/issues/296#issuecomment-307598143
500
+ *
501
+ * @param Object obj Object to detect by type or brand
502
+ * @return String
503
+ */
504
+ function isURLSearchParams(obj) {
505
+ // Duck-typing as a necessary condition.
506
+ if (typeof obj !== 'object' || typeof obj.append !== 'function' || typeof obj.delete !== 'function' || typeof obj.get !== 'function' || typeof obj.getAll !== 'function' || typeof obj.has !== 'function' || typeof obj.set !== 'function') {
507
+ return false;
508
+ }
509
+
510
+ // Brand-checking and more duck-typing as optional condition.
511
+ return obj.constructor.name === 'URLSearchParams' || Object.prototype.toString.call(obj) === '[object URLSearchParams]' || typeof obj.sort === 'function';
512
+ }
513
+
514
+ /**
515
+ * Check if `obj` is a W3C `Blob` object (which `File` inherits from)
516
+ * @param {*} obj
517
+ * @return {boolean}
518
+ */
519
+ function isBlob(obj) {
520
+ return typeof obj === 'object' && typeof obj.arrayBuffer === 'function' && typeof obj.type === 'string' && typeof obj.stream === 'function' && typeof obj.constructor === 'function' && typeof obj.constructor.name === 'string' && /^(Blob|File)$/.test(obj.constructor.name) && /^(Blob|File)$/.test(obj[Symbol.toStringTag]);
521
+ }
522
+
523
+ /**
524
+ * Clone body given Res/Req instance
525
+ *
526
+ * @param Mixed instance Response or Request instance
527
+ * @return Mixed
528
+ */
529
+ function clone(instance) {
530
+ let p1, p2;
531
+ let body = instance.body;
532
+
533
+ // don't allow cloning a used body
534
+ if (instance.bodyUsed) {
535
+ throw new Error('cannot clone body after it is used');
536
+ }
537
+
538
+ // check that body is a stream and not form-data object
539
+ // note: we can't clone the form-data object without having it as a dependency
540
+ if (body instanceof Stream && typeof body.getBoundary !== 'function') {
541
+ // tee instance body
542
+ p1 = new PassThrough();
543
+ p2 = new PassThrough();
544
+ body.pipe(p1);
545
+ body.pipe(p2);
546
+ // set instance body to teed body and return the other teed body
547
+ instance[INTERNALS].body = p1;
548
+ body = p2;
549
+ }
550
+
551
+ return body;
552
+ }
553
+
554
+ /**
555
+ * Performs the operation "extract a `Content-Type` value from |object|" as
556
+ * specified in the specification:
557
+ * https://fetch.spec.whatwg.org/#concept-bodyinit-extract
558
+ *
559
+ * This function assumes that instance.body is present.
560
+ *
561
+ * @param Mixed instance Any options.body input
562
+ */
563
+ function extractContentType(body) {
564
+ if (body === null) {
565
+ // body is null
566
+ return null;
567
+ } else if (typeof body === 'string') {
568
+ // body is string
569
+ return 'text/plain;charset=UTF-8';
570
+ } else if (isURLSearchParams(body)) {
571
+ // body is a URLSearchParams
572
+ return 'application/x-www-form-urlencoded;charset=UTF-8';
573
+ } else if (isBlob(body)) {
574
+ // body is blob
575
+ return body.type || null;
576
+ } else if (Buffer.isBuffer(body)) {
577
+ // body is buffer
578
+ return null;
579
+ } else if (Object.prototype.toString.call(body) === '[object ArrayBuffer]') {
580
+ // body is ArrayBuffer
581
+ return null;
582
+ } else if (ArrayBuffer.isView(body)) {
583
+ // body is ArrayBufferView
584
+ return null;
585
+ } else if (typeof body.getBoundary === 'function') {
586
+ // detect form data input from form-data module
587
+ return `multipart/form-data;boundary=${body.getBoundary()}`;
588
+ } else if (body instanceof Stream) {
589
+ // body is stream
590
+ // can't really do much about this
591
+ return null;
592
+ } else {
593
+ // Body constructor defaults other things to string
594
+ return 'text/plain;charset=UTF-8';
595
+ }
596
+ }
597
+
598
+ /**
599
+ * The Fetch Standard treats this as if "total bytes" is a property on the body.
600
+ * For us, we have to explicitly get it with a function.
601
+ *
602
+ * ref: https://fetch.spec.whatwg.org/#concept-body-total-bytes
603
+ *
604
+ * @param Body instance Instance of Body
605
+ * @return Number? Number of bytes, or null if not possible
606
+ */
607
+ function getTotalBytes(instance) {
608
+ const body = instance.body;
609
+
610
+
611
+ if (body === null) {
612
+ // body is null
613
+ return 0;
614
+ } else if (isBlob(body)) {
615
+ return body.size;
616
+ } else if (Buffer.isBuffer(body)) {
617
+ // body is buffer
618
+ return body.length;
619
+ } else if (body && typeof body.getLengthSync === 'function') {
620
+ // detect form data input from form-data module
621
+ if (body._lengthRetrievers && body._lengthRetrievers.length == 0 || // 1.x
622
+ body.hasKnownLength && body.hasKnownLength()) {
623
+ // 2.x
624
+ return body.getLengthSync();
625
+ }
626
+ return null;
627
+ } else {
628
+ // body is stream
629
+ return null;
630
+ }
631
+ }
632
+
633
+ /**
634
+ * Write a Body to a Node.js WritableStream (e.g. http.Request) object.
635
+ *
636
+ * @param Body instance Instance of Body
637
+ * @return Void
638
+ */
639
+ function writeToStream(dest, instance) {
640
+ const body = instance.body;
641
+
642
+
643
+ if (body === null) {
644
+ // body is null
645
+ dest.end();
646
+ } else if (isBlob(body)) {
647
+ body.stream().pipe(dest);
648
+ } else if (Buffer.isBuffer(body)) {
649
+ // body is buffer
650
+ dest.write(body);
651
+ dest.end();
652
+ } else {
653
+ // body is stream
654
+ body.pipe(dest);
655
+ }
656
+ }
657
+
658
+ // expose Promise
659
+ Body.Promise = global.Promise;
660
+
661
+ /**
662
+ * headers.js
663
+ *
664
+ * Headers class offers convenient helpers
665
+ */
666
+
667
+ const invalidTokenRegex = /[^\^_`a-zA-Z\-0-9!#$%&'*+.|~]/;
668
+ const invalidHeaderCharRegex = /[^\t\x20-\x7e\x80-\xff]/;
669
+
670
+ function validateName(name) {
671
+ name = `${name}`;
672
+ if (invalidTokenRegex.test(name) || name === '') {
673
+ throw new TypeError(`${name} is not a legal HTTP header name`);
674
+ }
675
+ }
676
+
677
+ function validateValue(value) {
678
+ value = `${value}`;
679
+ if (invalidHeaderCharRegex.test(value)) {
680
+ throw new TypeError(`${value} is not a legal HTTP header value`);
681
+ }
682
+ }
683
+
684
+ /**
685
+ * Find the key in the map object given a header name.
686
+ *
687
+ * Returns undefined if not found.
688
+ *
689
+ * @param String name Header name
690
+ * @return String|Undefined
691
+ */
692
+ function find(map, name) {
693
+ name = name.toLowerCase();
694
+ for (const key in map) {
695
+ if (key.toLowerCase() === name) {
696
+ return key;
697
+ }
698
+ }
699
+ return undefined;
700
+ }
701
+
702
+ const MAP = Symbol('map');
703
+ class Headers {
704
+ /**
705
+ * Headers class
706
+ *
707
+ * @param Object headers Response headers
708
+ * @return Void
709
+ */
710
+ constructor() {
711
+ let init = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined;
712
+
713
+ this[MAP] = Object.create(null);
714
+
715
+ if (init instanceof Headers) {
716
+ const rawHeaders = init.raw();
717
+ const headerNames = Object.keys(rawHeaders);
718
+
719
+ for (const headerName of headerNames) {
720
+ for (const value of rawHeaders[headerName]) {
721
+ this.append(headerName, value);
722
+ }
723
+ }
724
+
725
+ return;
726
+ }
727
+
728
+ // We don't worry about converting prop to ByteString here as append()
729
+ // will handle it.
730
+ if (init == null) ; else if (typeof init === 'object') {
731
+ const method = init[Symbol.iterator];
732
+ if (method != null) {
733
+ if (typeof method !== 'function') {
734
+ throw new TypeError('Header pairs must be iterable');
735
+ }
736
+
737
+ // sequence<sequence<ByteString>>
738
+ // Note: per spec we have to first exhaust the lists then process them
739
+ const pairs = [];
740
+ for (const pair of init) {
741
+ if (typeof pair !== 'object' || typeof pair[Symbol.iterator] !== 'function') {
742
+ throw new TypeError('Each header pair must be iterable');
743
+ }
744
+ pairs.push(Array.from(pair));
745
+ }
746
+
747
+ for (const pair of pairs) {
748
+ if (pair.length !== 2) {
749
+ throw new TypeError('Each header pair must be a name/value tuple');
750
+ }
751
+ this.append(pair[0], pair[1]);
752
+ }
753
+ } else {
754
+ // record<ByteString, ByteString>
755
+ for (const key of Object.keys(init)) {
756
+ const value = init[key];
757
+ this.append(key, value);
758
+ }
759
+ }
760
+ } else {
761
+ throw new TypeError('Provided initializer must be an object');
762
+ }
763
+ }
764
+
765
+ /**
766
+ * Return combined header value given name
767
+ *
768
+ * @param String name Header name
769
+ * @return Mixed
770
+ */
771
+ get(name) {
772
+ name = `${name}`;
773
+ validateName(name);
774
+ const key = find(this[MAP], name);
775
+ if (key === undefined) {
776
+ return null;
777
+ }
778
+
779
+ return this[MAP][key].join(', ');
780
+ }
781
+
782
+ /**
783
+ * Iterate over all headers
784
+ *
785
+ * @param Function callback Executed for each item with parameters (value, name, thisArg)
786
+ * @param Boolean thisArg `this` context for callback function
787
+ * @return Void
788
+ */
789
+ forEach(callback) {
790
+ let thisArg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
791
+
792
+ let pairs = getHeaders(this);
793
+ let i = 0;
794
+ while (i < pairs.length) {
795
+ var _pairs$i = pairs[i];
796
+ const name = _pairs$i[0],
797
+ value = _pairs$i[1];
798
+
799
+ callback.call(thisArg, value, name, this);
800
+ pairs = getHeaders(this);
801
+ i++;
802
+ }
803
+ }
804
+
805
+ /**
806
+ * Overwrite header values given name
807
+ *
808
+ * @param String name Header name
809
+ * @param String value Header value
810
+ * @return Void
811
+ */
812
+ set(name, value) {
813
+ name = `${name}`;
814
+ value = `${value}`;
815
+ validateName(name);
816
+ validateValue(value);
817
+ const key = find(this[MAP], name);
818
+ this[MAP][key !== undefined ? key : name] = [value];
819
+ }
820
+
821
+ /**
822
+ * Append a value onto existing header
823
+ *
824
+ * @param String name Header name
825
+ * @param String value Header value
826
+ * @return Void
827
+ */
828
+ append(name, value) {
829
+ name = `${name}`;
830
+ value = `${value}`;
831
+ validateName(name);
832
+ validateValue(value);
833
+ const key = find(this[MAP], name);
834
+ if (key !== undefined) {
835
+ this[MAP][key].push(value);
836
+ } else {
837
+ this[MAP][name] = [value];
838
+ }
839
+ }
840
+
841
+ /**
842
+ * Check for header name existence
843
+ *
844
+ * @param String name Header name
845
+ * @return Boolean
846
+ */
847
+ has(name) {
848
+ name = `${name}`;
849
+ validateName(name);
850
+ return find(this[MAP], name) !== undefined;
851
+ }
852
+
853
+ /**
854
+ * Delete all header values given name
855
+ *
856
+ * @param String name Header name
857
+ * @return Void
858
+ */
859
+ delete(name) {
860
+ name = `${name}`;
861
+ validateName(name);
862
+ const key = find(this[MAP], name);
863
+ if (key !== undefined) {
864
+ delete this[MAP][key];
865
+ }
866
+ }
867
+
868
+ /**
869
+ * Return raw headers (non-spec api)
870
+ *
871
+ * @return Object
872
+ */
873
+ raw() {
874
+ return this[MAP];
875
+ }
876
+
877
+ /**
878
+ * Get an iterator on keys.
879
+ *
880
+ * @return Iterator
881
+ */
882
+ keys() {
883
+ return createHeadersIterator(this, 'key');
884
+ }
885
+
886
+ /**
887
+ * Get an iterator on values.
888
+ *
889
+ * @return Iterator
890
+ */
891
+ values() {
892
+ return createHeadersIterator(this, 'value');
893
+ }
894
+
895
+ /**
896
+ * Get an iterator on entries.
897
+ *
898
+ * This is the default iterator of the Headers object.
899
+ *
900
+ * @return Iterator
901
+ */
902
+ [Symbol.iterator]() {
903
+ return createHeadersIterator(this, 'key+value');
904
+ }
905
+ }
906
+ Headers.prototype.entries = Headers.prototype[Symbol.iterator];
907
+
908
+ Object.defineProperty(Headers.prototype, Symbol.toStringTag, {
909
+ value: 'Headers',
910
+ writable: false,
911
+ enumerable: false,
912
+ configurable: true
913
+ });
914
+
915
+ Object.defineProperties(Headers.prototype, {
916
+ get: { enumerable: true },
917
+ forEach: { enumerable: true },
918
+ set: { enumerable: true },
919
+ append: { enumerable: true },
920
+ has: { enumerable: true },
921
+ delete: { enumerable: true },
922
+ keys: { enumerable: true },
923
+ values: { enumerable: true },
924
+ entries: { enumerable: true }
925
+ });
926
+
927
+ function getHeaders(headers) {
928
+ let kind = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'key+value';
929
+
930
+ const keys = Object.keys(headers[MAP]).sort();
931
+ return keys.map(kind === 'key' ? function (k) {
932
+ return k.toLowerCase();
933
+ } : kind === 'value' ? function (k) {
934
+ return headers[MAP][k].join(', ');
935
+ } : function (k) {
936
+ return [k.toLowerCase(), headers[MAP][k].join(', ')];
937
+ });
938
+ }
939
+
940
+ const INTERNAL = Symbol('internal');
941
+
942
+ function createHeadersIterator(target, kind) {
943
+ const iterator = Object.create(HeadersIteratorPrototype);
944
+ iterator[INTERNAL] = {
945
+ target,
946
+ kind,
947
+ index: 0
948
+ };
949
+ return iterator;
950
+ }
951
+
952
+ const HeadersIteratorPrototype = Object.setPrototypeOf({
953
+ next() {
954
+ // istanbul ignore if
955
+ if (!this || Object.getPrototypeOf(this) !== HeadersIteratorPrototype) {
956
+ throw new TypeError('Value of `this` is not a HeadersIterator');
957
+ }
958
+
959
+ var _INTERNAL = this[INTERNAL];
960
+ const target = _INTERNAL.target,
961
+ kind = _INTERNAL.kind,
962
+ index = _INTERNAL.index;
963
+
964
+ const values = getHeaders(target, kind);
965
+ const len = values.length;
966
+ if (index >= len) {
967
+ return {
968
+ value: undefined,
969
+ done: true
970
+ };
971
+ }
972
+
973
+ this[INTERNAL].index = index + 1;
974
+
975
+ return {
976
+ value: values[index],
977
+ done: false
978
+ };
979
+ }
980
+ }, Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]())));
981
+
982
+ Object.defineProperty(HeadersIteratorPrototype, Symbol.toStringTag, {
983
+ value: 'HeadersIterator',
984
+ writable: false,
985
+ enumerable: false,
986
+ configurable: true
987
+ });
988
+
989
+ /**
990
+ * Export the Headers object in a form that Node.js can consume.
991
+ *
992
+ * @param Headers headers
993
+ * @return Object
994
+ */
995
+ function exportNodeCompatibleHeaders(headers) {
996
+ const obj = Object.assign({ __proto__: null }, headers[MAP]);
997
+
998
+ // http.request() only supports string as Host header. This hack makes
999
+ // specifying custom Host header possible.
1000
+ const hostHeaderKey = find(headers[MAP], 'Host');
1001
+ if (hostHeaderKey !== undefined) {
1002
+ obj[hostHeaderKey] = obj[hostHeaderKey][0];
1003
+ }
1004
+
1005
+ return obj;
1006
+ }
1007
+
1008
+ /**
1009
+ * Create a Headers object from an object of headers, ignoring those that do
1010
+ * not conform to HTTP grammar productions.
1011
+ *
1012
+ * @param Object obj Object of headers
1013
+ * @return Headers
1014
+ */
1015
+ function createHeadersLenient(obj) {
1016
+ const headers = new Headers();
1017
+ for (const name of Object.keys(obj)) {
1018
+ if (invalidTokenRegex.test(name)) {
1019
+ continue;
1020
+ }
1021
+ if (Array.isArray(obj[name])) {
1022
+ for (const val of obj[name]) {
1023
+ if (invalidHeaderCharRegex.test(val)) {
1024
+ continue;
1025
+ }
1026
+ if (headers[MAP][name] === undefined) {
1027
+ headers[MAP][name] = [val];
1028
+ } else {
1029
+ headers[MAP][name].push(val);
1030
+ }
1031
+ }
1032
+ } else if (!invalidHeaderCharRegex.test(obj[name])) {
1033
+ headers[MAP][name] = [obj[name]];
1034
+ }
1035
+ }
1036
+ return headers;
1037
+ }
1038
+
1039
+ const INTERNALS$1 = Symbol('Response internals');
1040
+
1041
+ // fix an issue where "STATUS_CODES" aren't a named export for node <10
1042
+ const STATUS_CODES = http.STATUS_CODES;
1043
+
1044
+ /**
1045
+ * Response class
1046
+ *
1047
+ * @param Stream body Readable stream
1048
+ * @param Object opts Response options
1049
+ * @return Void
1050
+ */
1051
+ class Response {
1052
+ constructor() {
1053
+ let body = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
1054
+ let opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1055
+
1056
+ Body.call(this, body, opts);
1057
+
1058
+ const status = opts.status || 200;
1059
+ const headers = new Headers(opts.headers);
1060
+
1061
+ if (body != null && !headers.has('Content-Type')) {
1062
+ const contentType = extractContentType(body);
1063
+ if (contentType) {
1064
+ headers.append('Content-Type', contentType);
1065
+ }
1066
+ }
1067
+
1068
+ this[INTERNALS$1] = {
1069
+ url: opts.url,
1070
+ status,
1071
+ statusText: opts.statusText || STATUS_CODES[status],
1072
+ headers,
1073
+ counter: opts.counter
1074
+ };
1075
+ }
1076
+
1077
+ get url() {
1078
+ return this[INTERNALS$1].url || '';
1079
+ }
1080
+
1081
+ get status() {
1082
+ return this[INTERNALS$1].status;
1083
+ }
1084
+
1085
+ /**
1086
+ * Convenience property representing if the request ended normally
1087
+ */
1088
+ get ok() {
1089
+ return this[INTERNALS$1].status >= 200 && this[INTERNALS$1].status < 300;
1090
+ }
1091
+
1092
+ get redirected() {
1093
+ return this[INTERNALS$1].counter > 0;
1094
+ }
1095
+
1096
+ get statusText() {
1097
+ return this[INTERNALS$1].statusText;
1098
+ }
1099
+
1100
+ get headers() {
1101
+ return this[INTERNALS$1].headers;
1102
+ }
1103
+
1104
+ /**
1105
+ * Clone this response
1106
+ *
1107
+ * @return Response
1108
+ */
1109
+ clone() {
1110
+ return new Response(clone(this), {
1111
+ url: this.url,
1112
+ status: this.status,
1113
+ statusText: this.statusText,
1114
+ headers: this.headers,
1115
+ ok: this.ok,
1116
+ redirected: this.redirected
1117
+ });
1118
+ }
1119
+ }
1120
+
1121
+ Body.mixIn(Response.prototype);
1122
+
1123
+ Object.defineProperties(Response.prototype, {
1124
+ url: { enumerable: true },
1125
+ status: { enumerable: true },
1126
+ ok: { enumerable: true },
1127
+ redirected: { enumerable: true },
1128
+ statusText: { enumerable: true },
1129
+ headers: { enumerable: true },
1130
+ clone: { enumerable: true }
1131
+ });
1132
+
1133
+ Object.defineProperty(Response.prototype, Symbol.toStringTag, {
1134
+ value: 'Response',
1135
+ writable: false,
1136
+ enumerable: false,
1137
+ configurable: true
1138
+ });
1139
+
1140
+ const INTERNALS$2 = Symbol('Request internals');
1141
+ const URL = whatwgUrl.URL;
1142
+
1143
+ // fix an issue where "format", "parse" aren't a named export for node <10
1144
+ const parse_url = Url.parse;
1145
+ const format_url = Url.format;
1146
+
1147
+ /**
1148
+ * Wrapper around `new URL` to handle arbitrary URLs
1149
+ *
1150
+ * @param {string} urlStr
1151
+ * @return {void}
1152
+ */
1153
+ function parseURL(urlStr) {
1154
+ /*
1155
+ Check whether the URL is absolute or not
1156
+ Scheme: https://tools.ietf.org/html/rfc3986#section-3.1
1157
+ Absolute URL: https://tools.ietf.org/html/rfc3986#section-4.3
1158
+ */
1159
+ if (/^[a-zA-Z][a-zA-Z\d+\-.]*:/.exec(urlStr)) {
1160
+ urlStr = new URL(urlStr).toString();
1161
+ }
1162
+
1163
+ // Fallback to old implementation for arbitrary URLs
1164
+ return parse_url(urlStr);
1165
+ }
1166
+
1167
+ const streamDestructionSupported = 'destroy' in Stream.Readable.prototype;
1168
+
1169
+ /**
1170
+ * Check if a value is an instance of Request.
1171
+ *
1172
+ * @param Mixed input
1173
+ * @return Boolean
1174
+ */
1175
+ function isRequest(input) {
1176
+ return typeof input === 'object' && typeof input[INTERNALS$2] === 'object';
1177
+ }
1178
+
1179
+ function isAbortSignal(signal) {
1180
+ const proto = signal && typeof signal === 'object' && Object.getPrototypeOf(signal);
1181
+ return !!(proto && proto.constructor.name === 'AbortSignal');
1182
+ }
1183
+
1184
+ /**
1185
+ * Request class
1186
+ *
1187
+ * @param Mixed input Url or Request instance
1188
+ * @param Object init Custom options
1189
+ * @return Void
1190
+ */
1191
+ class Request {
1192
+ constructor(input) {
1193
+ let init = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1194
+
1195
+ let parsedURL;
1196
+
1197
+ // normalize input
1198
+ if (!isRequest(input)) {
1199
+ if (input && input.href) {
1200
+ // in order to support Node.js' Url objects; though WHATWG's URL objects
1201
+ // will fall into this branch also (since their `toString()` will return
1202
+ // `href` property anyway)
1203
+ parsedURL = parseURL(input.href);
1204
+ } else {
1205
+ // coerce input to a string before attempting to parse
1206
+ parsedURL = parseURL(`${input}`);
1207
+ }
1208
+ input = {};
1209
+ } else {
1210
+ parsedURL = parseURL(input.url);
1211
+ }
1212
+
1213
+ let method = init.method || input.method || 'GET';
1214
+ method = method.toUpperCase();
1215
+
1216
+ if ((init.body != null || isRequest(input) && input.body !== null) && (method === 'GET' || method === 'HEAD')) {
1217
+ throw new TypeError('Request with GET/HEAD method cannot have body');
1218
+ }
1219
+
1220
+ let inputBody = init.body != null ? init.body : isRequest(input) && input.body !== null ? clone(input) : null;
1221
+
1222
+ Body.call(this, inputBody, {
1223
+ timeout: init.timeout || input.timeout || 0,
1224
+ size: init.size || input.size || 0
1225
+ });
1226
+
1227
+ const headers = new Headers(init.headers || input.headers || {});
1228
+
1229
+ if (inputBody != null && !headers.has('Content-Type')) {
1230
+ const contentType = extractContentType(inputBody);
1231
+ if (contentType) {
1232
+ headers.append('Content-Type', contentType);
1233
+ }
1234
+ }
1235
+
1236
+ let signal = isRequest(input) ? input.signal : null;
1237
+ if ('signal' in init) signal = init.signal;
1238
+
1239
+ if (signal != null && !isAbortSignal(signal)) {
1240
+ throw new TypeError('Expected signal to be an instanceof AbortSignal');
1241
+ }
1242
+
1243
+ this[INTERNALS$2] = {
1244
+ method,
1245
+ redirect: init.redirect || input.redirect || 'follow',
1246
+ headers,
1247
+ parsedURL,
1248
+ signal
1249
+ };
1250
+
1251
+ // node-fetch-only options
1252
+ this.follow = init.follow !== undefined ? init.follow : input.follow !== undefined ? input.follow : 20;
1253
+ this.compress = init.compress !== undefined ? init.compress : input.compress !== undefined ? input.compress : true;
1254
+ this.counter = init.counter || input.counter || 0;
1255
+ this.agent = init.agent || input.agent;
1256
+ }
1257
+
1258
+ get method() {
1259
+ return this[INTERNALS$2].method;
1260
+ }
1261
+
1262
+ get url() {
1263
+ return format_url(this[INTERNALS$2].parsedURL);
1264
+ }
1265
+
1266
+ get headers() {
1267
+ return this[INTERNALS$2].headers;
1268
+ }
1269
+
1270
+ get redirect() {
1271
+ return this[INTERNALS$2].redirect;
1272
+ }
1273
+
1274
+ get signal() {
1275
+ return this[INTERNALS$2].signal;
1276
+ }
1277
+
1278
+ /**
1279
+ * Clone this request
1280
+ *
1281
+ * @return Request
1282
+ */
1283
+ clone() {
1284
+ return new Request(this);
1285
+ }
1286
+ }
1287
+
1288
+ Body.mixIn(Request.prototype);
1289
+
1290
+ Object.defineProperty(Request.prototype, Symbol.toStringTag, {
1291
+ value: 'Request',
1292
+ writable: false,
1293
+ enumerable: false,
1294
+ configurable: true
1295
+ });
1296
+
1297
+ Object.defineProperties(Request.prototype, {
1298
+ method: { enumerable: true },
1299
+ url: { enumerable: true },
1300
+ headers: { enumerable: true },
1301
+ redirect: { enumerable: true },
1302
+ clone: { enumerable: true },
1303
+ signal: { enumerable: true }
1304
+ });
1305
+
1306
+ /**
1307
+ * Convert a Request to Node.js http request options.
1308
+ *
1309
+ * @param Request A Request instance
1310
+ * @return Object The options object to be passed to http.request
1311
+ */
1312
+ function getNodeRequestOptions(request) {
1313
+ const parsedURL = request[INTERNALS$2].parsedURL;
1314
+ const headers = new Headers(request[INTERNALS$2].headers);
1315
+
1316
+ // fetch step 1.3
1317
+ if (!headers.has('Accept')) {
1318
+ headers.set('Accept', '*/*');
1319
+ }
1320
+
1321
+ // Basic fetch
1322
+ if (!parsedURL.protocol || !parsedURL.hostname) {
1323
+ throw new TypeError('Only absolute URLs are supported');
1324
+ }
1325
+
1326
+ if (!/^https?:$/.test(parsedURL.protocol)) {
1327
+ throw new TypeError('Only HTTP(S) protocols are supported');
1328
+ }
1329
+
1330
+ if (request.signal && request.body instanceof Stream.Readable && !streamDestructionSupported) {
1331
+ throw new Error('Cancellation of streamed requests with AbortSignal is not supported in node < 8');
1332
+ }
1333
+
1334
+ // HTTP-network-or-cache fetch steps 2.4-2.7
1335
+ let contentLengthValue = null;
1336
+ if (request.body == null && /^(POST|PUT)$/i.test(request.method)) {
1337
+ contentLengthValue = '0';
1338
+ }
1339
+ if (request.body != null) {
1340
+ const totalBytes = getTotalBytes(request);
1341
+ if (typeof totalBytes === 'number') {
1342
+ contentLengthValue = String(totalBytes);
1343
+ }
1344
+ }
1345
+ if (contentLengthValue) {
1346
+ headers.set('Content-Length', contentLengthValue);
1347
+ }
1348
+
1349
+ // HTTP-network-or-cache fetch step 2.11
1350
+ if (!headers.has('User-Agent')) {
1351
+ headers.set('User-Agent', 'node-fetch/1.0 (+https://github.com/bitinn/node-fetch)');
1352
+ }
1353
+
1354
+ // HTTP-network-or-cache fetch step 2.15
1355
+ if (request.compress && !headers.has('Accept-Encoding')) {
1356
+ headers.set('Accept-Encoding', 'gzip,deflate');
1357
+ }
1358
+
1359
+ let agent = request.agent;
1360
+ if (typeof agent === 'function') {
1361
+ agent = agent(parsedURL);
1362
+ }
1363
+
1364
+ if (!headers.has('Connection') && !agent) {
1365
+ headers.set('Connection', 'close');
1366
+ }
1367
+
1368
+ // HTTP-network fetch step 4.2
1369
+ // chunked encoding is handled by Node.js
1370
+
1371
+ return Object.assign({}, parsedURL, {
1372
+ method: request.method,
1373
+ headers: exportNodeCompatibleHeaders(headers),
1374
+ agent
1375
+ });
1376
+ }
1377
+
1378
+ /**
1379
+ * abort-error.js
1380
+ *
1381
+ * AbortError interface for cancelled requests
1382
+ */
1383
+
1384
+ /**
1385
+ * Create AbortError instance
1386
+ *
1387
+ * @param String message Error message for human
1388
+ * @return AbortError
1389
+ */
1390
+ function AbortError(message) {
1391
+ Error.call(this, message);
1392
+
1393
+ this.type = 'aborted';
1394
+ this.message = message;
1395
+
1396
+ // hide custom error implementation details from end-users
1397
+ Error.captureStackTrace(this, this.constructor);
1398
+ }
1399
+
1400
+ AbortError.prototype = Object.create(Error.prototype);
1401
+ AbortError.prototype.constructor = AbortError;
1402
+ AbortError.prototype.name = 'AbortError';
1403
+
1404
+ // fix an issue where "PassThrough", "resolve" aren't a named export for node <10
1405
+ const PassThrough$1 = Stream.PassThrough;
1406
+ const resolve_url = Url.resolve;
1407
+
1408
+ /**
1409
+ * Fetch function
1410
+ *
1411
+ * @param Mixed url Absolute url or Request instance
1412
+ * @param Object opts Fetch options
1413
+ * @return Promise
1414
+ */
1415
+ function fetch(url, opts) {
1416
+
1417
+ // allow custom promise
1418
+ if (!fetch.Promise) {
1419
+ throw new Error('native promise missing, set fetch.Promise to your favorite alternative');
1420
+ }
1421
+
1422
+ Body.Promise = fetch.Promise;
1423
+
1424
+ // wrap http.request into fetch
1425
+ return new fetch.Promise(function (resolve, reject) {
1426
+ // build request object
1427
+ const request = new Request(url, opts);
1428
+ const options = getNodeRequestOptions(request);
1429
+
1430
+ const send = (options.protocol === 'https:' ? https : http).request;
1431
+ const signal = request.signal;
1432
+
1433
+ let response = null;
1434
+
1435
+ const abort = function abort() {
1436
+ let error = new AbortError('The user aborted a request.');
1437
+ reject(error);
1438
+ if (request.body && request.body instanceof Stream.Readable) {
1439
+ request.body.destroy(error);
1440
+ }
1441
+ if (!response || !response.body) return;
1442
+ response.body.emit('error', error);
1443
+ };
1444
+
1445
+ if (signal && signal.aborted) {
1446
+ abort();
1447
+ return;
1448
+ }
1449
+
1450
+ const abortAndFinalize = function abortAndFinalize() {
1451
+ abort();
1452
+ finalize();
1453
+ };
1454
+
1455
+ // send request
1456
+ const req = send(options);
1457
+ let reqTimeout;
1458
+
1459
+ if (signal) {
1460
+ signal.addEventListener('abort', abortAndFinalize);
1461
+ }
1462
+
1463
+ function finalize() {
1464
+ req.abort();
1465
+ if (signal) signal.removeEventListener('abort', abortAndFinalize);
1466
+ clearTimeout(reqTimeout);
1467
+ }
1468
+
1469
+ if (request.timeout) {
1470
+ req.once('socket', function (socket) {
1471
+ reqTimeout = setTimeout(function () {
1472
+ reject(new FetchError(`network timeout at: ${request.url}`, 'request-timeout'));
1473
+ finalize();
1474
+ }, request.timeout);
1475
+ });
1476
+ }
1477
+
1478
+ req.on('error', function (err) {
1479
+ reject(new FetchError(`request to ${request.url} failed, reason: ${err.message}`, 'system', err));
1480
+ finalize();
1481
+ });
1482
+
1483
+ req.on('response', function (res) {
1484
+ clearTimeout(reqTimeout);
1485
+
1486
+ const headers = createHeadersLenient(res.headers);
1487
+
1488
+ // HTTP fetch step 5
1489
+ if (fetch.isRedirect(res.statusCode)) {
1490
+ // HTTP fetch step 5.2
1491
+ const location = headers.get('Location');
1492
+
1493
+ // HTTP fetch step 5.3
1494
+ const locationURL = location === null ? null : resolve_url(request.url, location);
1495
+
1496
+ // HTTP fetch step 5.5
1497
+ switch (request.redirect) {
1498
+ case 'error':
1499
+ reject(new FetchError(`uri requested responds with a redirect, redirect mode is set to error: ${request.url}`, 'no-redirect'));
1500
+ finalize();
1501
+ return;
1502
+ case 'manual':
1503
+ // node-fetch-specific step: make manual redirect a bit easier to use by setting the Location header value to the resolved URL.
1504
+ if (locationURL !== null) {
1505
+ // handle corrupted header
1506
+ try {
1507
+ headers.set('Location', locationURL);
1508
+ } catch (err) {
1509
+ // istanbul ignore next: nodejs server prevent invalid response headers, we can't test this through normal request
1510
+ reject(err);
1511
+ }
1512
+ }
1513
+ break;
1514
+ case 'follow':
1515
+ // HTTP-redirect fetch step 2
1516
+ if (locationURL === null) {
1517
+ break;
1518
+ }
1519
+
1520
+ // HTTP-redirect fetch step 5
1521
+ if (request.counter >= request.follow) {
1522
+ reject(new FetchError(`maximum redirect reached at: ${request.url}`, 'max-redirect'));
1523
+ finalize();
1524
+ return;
1525
+ }
1526
+
1527
+ // HTTP-redirect fetch step 6 (counter increment)
1528
+ // Create a new Request object.
1529
+ const requestOpts = {
1530
+ headers: new Headers(request.headers),
1531
+ follow: request.follow,
1532
+ counter: request.counter + 1,
1533
+ agent: request.agent,
1534
+ compress: request.compress,
1535
+ method: request.method,
1536
+ body: request.body,
1537
+ signal: request.signal,
1538
+ timeout: request.timeout,
1539
+ size: request.size
1540
+ };
1541
+
1542
+ // HTTP-redirect fetch step 9
1543
+ if (res.statusCode !== 303 && request.body && getTotalBytes(request) === null) {
1544
+ reject(new FetchError('Cannot follow redirect with body being a readable stream', 'unsupported-redirect'));
1545
+ finalize();
1546
+ return;
1547
+ }
1548
+
1549
+ // HTTP-redirect fetch step 11
1550
+ if (res.statusCode === 303 || (res.statusCode === 301 || res.statusCode === 302) && request.method === 'POST') {
1551
+ requestOpts.method = 'GET';
1552
+ requestOpts.body = undefined;
1553
+ requestOpts.headers.delete('content-length');
1554
+ }
1555
+
1556
+ // HTTP-redirect fetch step 15
1557
+ resolve(fetch(new Request(locationURL, requestOpts)));
1558
+ finalize();
1559
+ return;
1560
+ }
1561
+ }
1562
+
1563
+ // prepare response
1564
+ res.once('end', function () {
1565
+ if (signal) signal.removeEventListener('abort', abortAndFinalize);
1566
+ });
1567
+ let body = res.pipe(new PassThrough$1());
1568
+
1569
+ const response_options = {
1570
+ url: request.url,
1571
+ status: res.statusCode,
1572
+ statusText: res.statusMessage,
1573
+ headers: headers,
1574
+ size: request.size,
1575
+ timeout: request.timeout,
1576
+ counter: request.counter
1577
+ };
1578
+
1579
+ // HTTP-network fetch step 12.1.1.3
1580
+ const codings = headers.get('Content-Encoding');
1581
+
1582
+ // HTTP-network fetch step 12.1.1.4: handle content codings
1583
+
1584
+ // in following scenarios we ignore compression support
1585
+ // 1. compression support is disabled
1586
+ // 2. HEAD request
1587
+ // 3. no Content-Encoding header
1588
+ // 4. no content response (204)
1589
+ // 5. content not modified response (304)
1590
+ if (!request.compress || request.method === 'HEAD' || codings === null || res.statusCode === 204 || res.statusCode === 304) {
1591
+ response = new Response(body, response_options);
1592
+ resolve(response);
1593
+ return;
1594
+ }
1595
+
1596
+ // For Node v6+
1597
+ // Be less strict when decoding compressed responses, since sometimes
1598
+ // servers send slightly invalid responses that are still accepted
1599
+ // by common browsers.
1600
+ // Always using Z_SYNC_FLUSH is what cURL does.
1601
+ const zlibOptions = {
1602
+ flush: zlib.Z_SYNC_FLUSH,
1603
+ finishFlush: zlib.Z_SYNC_FLUSH
1604
+ };
1605
+
1606
+ // for gzip
1607
+ if (codings == 'gzip' || codings == 'x-gzip') {
1608
+ body = body.pipe(zlib.createGunzip(zlibOptions));
1609
+ response = new Response(body, response_options);
1610
+ resolve(response);
1611
+ return;
1612
+ }
1613
+
1614
+ // for deflate
1615
+ if (codings == 'deflate' || codings == 'x-deflate') {
1616
+ // handle the infamous raw deflate response from old servers
1617
+ // a hack for old IIS and Apache servers
1618
+ const raw = res.pipe(new PassThrough$1());
1619
+ raw.once('data', function (chunk) {
1620
+ // see http://stackoverflow.com/questions/37519828
1621
+ if ((chunk[0] & 0x0F) === 0x08) {
1622
+ body = body.pipe(zlib.createInflate());
1623
+ } else {
1624
+ body = body.pipe(zlib.createInflateRaw());
1625
+ }
1626
+ response = new Response(body, response_options);
1627
+ resolve(response);
1628
+ });
1629
+ return;
1630
+ }
1631
+
1632
+ // for br
1633
+ if (codings == 'br' && typeof zlib.createBrotliDecompress === 'function') {
1634
+ body = body.pipe(zlib.createBrotliDecompress());
1635
+ response = new Response(body, response_options);
1636
+ resolve(response);
1637
+ return;
1638
+ }
1639
+
1640
+ // otherwise, use response as-is
1641
+ response = new Response(body, response_options);
1642
+ resolve(response);
1643
+ });
1644
+
1645
+ writeToStream(req, request);
1646
+ });
1647
+ }
1648
+ /**
1649
+ * Redirect code matching
1650
+ *
1651
+ * @param Number code Status code
1652
+ * @return Boolean
1653
+ */
1654
+ fetch.isRedirect = function (code) {
1655
+ return code === 301 || code === 302 || code === 303 || code === 307 || code === 308;
1656
+ };
1657
+
1658
+ // expose Promise
1659
+ fetch.Promise = global.Promise;
1660
+
1661
+ export default fetch;
1662
+ export { Headers, Request, Response, FetchError };