happy-dom 8.9.0 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of happy-dom might be problematic. Click here for more details.

Files changed (360) hide show
  1. package/README.md +2 -2
  2. package/lib/cookie/CookieJar.js +1 -1
  3. package/lib/cookie/CookieJar.js.map +1 -1
  4. package/lib/dom-token-list/DOMTokenList.js +24 -20
  5. package/lib/dom-token-list/DOMTokenList.js.map +1 -1
  6. package/lib/event/EventTarget.js +6 -3
  7. package/lib/event/EventTarget.js.map +1 -1
  8. package/lib/exception/DOMExceptionNameEnum.d.ts +5 -1
  9. package/lib/exception/DOMExceptionNameEnum.js +4 -0
  10. package/lib/exception/DOMExceptionNameEnum.js.map +1 -1
  11. package/lib/fetch/AbortController.d.ts +19 -0
  12. package/lib/fetch/AbortController.js +30 -0
  13. package/lib/fetch/AbortController.js.map +1 -0
  14. package/lib/fetch/AbortSignal.d.ts +25 -0
  15. package/lib/fetch/AbortSignal.js +51 -0
  16. package/lib/fetch/AbortSignal.js.map +1 -0
  17. package/lib/fetch/Fetch.d.ts +117 -0
  18. package/lib/fetch/Fetch.js +530 -0
  19. package/lib/fetch/Fetch.js.map +1 -0
  20. package/lib/fetch/Headers.d.ts +81 -3
  21. package/lib/fetch/Headers.js +139 -24
  22. package/lib/fetch/Headers.js.map +1 -1
  23. package/lib/fetch/Request.d.ts +56 -32
  24. package/lib/fetch/Request.js +165 -110
  25. package/lib/fetch/Request.js.map +1 -1
  26. package/lib/fetch/{ResourceFetchHandler.d.ts → ResourceFetch.d.ts} +1 -1
  27. package/lib/fetch/{ResourceFetchHandler.js → ResourceFetch.js} +5 -5
  28. package/lib/fetch/ResourceFetch.js.map +1 -0
  29. package/lib/fetch/Response.d.ts +60 -26
  30. package/lib/fetch/Response.js +196 -104
  31. package/lib/fetch/Response.js.map +1 -1
  32. package/lib/fetch/data-uri/DataURIParser.d.ts +20 -0
  33. package/lib/fetch/data-uri/DataURIParser.js +60 -0
  34. package/lib/fetch/data-uri/DataURIParser.js.map +1 -0
  35. package/lib/fetch/multipart/MultipartFormDataParser.d.ts +40 -0
  36. package/lib/fetch/multipart/MultipartFormDataParser.js +81 -0
  37. package/lib/fetch/multipart/MultipartFormDataParser.js.map +1 -0
  38. package/lib/fetch/multipart/MultipartReader.d.ts +49 -0
  39. package/lib/fetch/multipart/MultipartReader.js +178 -0
  40. package/lib/fetch/multipart/MultipartReader.js.map +1 -0
  41. package/lib/fetch/types/IHeaders.d.ts +71 -0
  42. package/lib/fetch/{IHeaders.js.map → types/IHeaders.js.map} +1 -1
  43. package/lib/fetch/types/IHeadersInit.js.map +1 -0
  44. package/lib/fetch/types/IRequest.d.ts +60 -0
  45. package/lib/fetch/{IRequest.js.map → types/IRequest.js.map} +1 -1
  46. package/lib/fetch/types/IRequestBody.d.ts +7 -0
  47. package/lib/fetch/{IBody.js → types/IRequestBody.js} +1 -1
  48. package/lib/fetch/types/IRequestBody.js.map +1 -0
  49. package/lib/fetch/types/IRequestCredentials.d.ts +2 -0
  50. package/lib/fetch/types/IRequestCredentials.js +3 -0
  51. package/lib/fetch/types/IRequestCredentials.js.map +1 -0
  52. package/lib/fetch/{RequestInfo.d.ts → types/IRequestInfo.d.ts} +2 -2
  53. package/lib/fetch/types/IRequestInfo.js +3 -0
  54. package/lib/fetch/types/IRequestInfo.js.map +1 -0
  55. package/lib/fetch/types/IRequestInit.d.ts +21 -0
  56. package/lib/fetch/types/IRequestInit.js.map +1 -0
  57. package/lib/fetch/types/IRequestRedirect.d.ts +2 -0
  58. package/lib/fetch/types/IRequestRedirect.js +3 -0
  59. package/lib/fetch/types/IRequestRedirect.js.map +1 -0
  60. package/lib/fetch/types/IRequestReferrerPolicy.d.ts +2 -0
  61. package/lib/fetch/types/IRequestReferrerPolicy.js +3 -0
  62. package/lib/fetch/types/IRequestReferrerPolicy.js.map +1 -0
  63. package/lib/fetch/types/IResponse.d.ts +27 -0
  64. package/lib/fetch/{IResponse.js.map → types/IResponse.js.map} +1 -1
  65. package/lib/fetch/types/IResponseBody.d.ts +7 -0
  66. package/lib/fetch/types/IResponseBody.js +3 -0
  67. package/lib/fetch/types/IResponseBody.js.map +1 -0
  68. package/lib/fetch/types/IResponseInit.d.ts +9 -0
  69. package/lib/fetch/types/IResponseInit.js.map +1 -0
  70. package/lib/fetch/utilities/FetchBodyUtility.d.ts +44 -0
  71. package/lib/fetch/utilities/FetchBodyUtility.js +156 -0
  72. package/lib/fetch/utilities/FetchBodyUtility.js.map +1 -0
  73. package/lib/fetch/utilities/FetchCORSUtility.d.ts +12 -0
  74. package/lib/fetch/utilities/FetchCORSUtility.js +20 -0
  75. package/lib/fetch/utilities/FetchCORSUtility.js.map +1 -0
  76. package/lib/fetch/utilities/FetchRequestHeaderUtility.d.ts +12 -0
  77. package/lib/fetch/utilities/FetchRequestHeaderUtility.js +45 -0
  78. package/lib/fetch/utilities/FetchRequestHeaderUtility.js.map +1 -0
  79. package/lib/fetch/utilities/FetchRequestReferrerUtility.d.ts +55 -0
  80. package/lib/fetch/utilities/FetchRequestReferrerUtility.js +194 -0
  81. package/lib/fetch/utilities/FetchRequestReferrerUtility.js.map +1 -0
  82. package/lib/fetch/utilities/FetchRequestValidationUtility.d.ts +38 -0
  83. package/lib/fetch/utilities/FetchRequestValidationUtility.js +70 -0
  84. package/lib/fetch/utilities/FetchRequestValidationUtility.js.map +1 -0
  85. package/lib/file/Blob.d.ts +2 -2
  86. package/lib/file/Blob.js +1 -1
  87. package/lib/file/Blob.js.map +1 -1
  88. package/lib/file/File.d.ts +2 -1
  89. package/lib/file/File.js.map +1 -1
  90. package/lib/form-data/FormData.d.ts +98 -0
  91. package/lib/form-data/FormData.js +212 -0
  92. package/lib/form-data/FormData.js.map +1 -0
  93. package/lib/index.d.ts +14 -1
  94. package/lib/index.js +20 -2
  95. package/lib/index.js.map +1 -1
  96. package/lib/nodes/document/Document.d.ts +5 -17
  97. package/lib/nodes/document/Document.js +11 -54
  98. package/lib/nodes/document/Document.js.map +1 -1
  99. package/lib/nodes/document/IDocument.d.ts +1 -1
  100. package/lib/nodes/document-fragment/DocumentFragment.d.ts +3 -14
  101. package/lib/nodes/document-fragment/DocumentFragment.js +7 -51
  102. package/lib/nodes/document-fragment/DocumentFragment.js.map +1 -1
  103. package/lib/nodes/document-fragment/IDocumentFragment.d.ts +2 -1
  104. package/lib/nodes/element/Element.d.ts +8 -8
  105. package/lib/nodes/element/Element.js +28 -45
  106. package/lib/nodes/element/Element.js.map +1 -1
  107. package/lib/nodes/element/ElementUtility.d.ts +32 -0
  108. package/lib/nodes/element/ElementUtility.js +105 -0
  109. package/lib/nodes/element/ElementUtility.js.map +1 -0
  110. package/lib/nodes/element/HTMLCollection.d.ts +26 -3
  111. package/lib/nodes/element/HTMLCollection.js +51 -0
  112. package/lib/nodes/element/HTMLCollection.js.map +1 -1
  113. package/lib/nodes/element/IHTMLCollection.d.ts +9 -2
  114. package/lib/nodes/html-anchor-element/HTMLAnchorElement.js +24 -24
  115. package/lib/nodes/html-anchor-element/HTMLAnchorElement.js.map +1 -1
  116. package/lib/nodes/html-base-element/HTMLBaseElement.js +4 -4
  117. package/lib/nodes/html-base-element/HTMLBaseElement.js.map +1 -1
  118. package/lib/nodes/html-button-element/HTMLButtonElement.d.ts +79 -3
  119. package/lib/nodes/html-button-element/HTMLButtonElement.js +158 -10
  120. package/lib/nodes/html-button-element/HTMLButtonElement.js.map +1 -1
  121. package/lib/nodes/html-button-element/IHTMLButtonElement.d.ts +28 -2
  122. package/lib/nodes/html-dialog-element/HTMLDialogElement.js +3 -3
  123. package/lib/nodes/html-dialog-element/HTMLDialogElement.js.map +1 -1
  124. package/lib/nodes/html-element/HTMLElement.js +12 -12
  125. package/lib/nodes/html-element/HTMLElement.js.map +1 -1
  126. package/lib/nodes/html-form-element/HTMLFormControlsCollection.d.ts +32 -0
  127. package/lib/nodes/html-form-element/HTMLFormControlsCollection.js +58 -0
  128. package/lib/nodes/html-form-element/HTMLFormControlsCollection.js.map +1 -0
  129. package/lib/nodes/html-form-element/HTMLFormElement.d.ts +37 -17
  130. package/lib/nodes/html-form-element/HTMLFormElement.js +128 -37
  131. package/lib/nodes/html-form-element/HTMLFormElement.js.map +1 -1
  132. package/lib/nodes/html-form-element/IHTMLFormControlsCollection.d.ts +25 -0
  133. package/lib/nodes/html-form-element/IHTMLFormControlsCollection.js +3 -0
  134. package/lib/nodes/html-form-element/IHTMLFormControlsCollection.js.map +1 -0
  135. package/lib/nodes/html-form-element/IHTMLFormElement.d.ts +16 -6
  136. package/lib/nodes/html-form-element/IRadioNodeList.d.ts +15 -0
  137. package/lib/nodes/html-form-element/IRadioNodeList.js +3 -0
  138. package/lib/nodes/html-form-element/IRadioNodeList.js.map +1 -0
  139. package/lib/nodes/html-form-element/RadioNodeList.d.ts +16 -0
  140. package/lib/nodes/html-form-element/RadioNodeList.js +28 -0
  141. package/lib/nodes/html-form-element/RadioNodeList.js.map +1 -0
  142. package/lib/nodes/html-image-element/HTMLImageElement.js +19 -19
  143. package/lib/nodes/html-image-element/HTMLImageElement.js.map +1 -1
  144. package/lib/nodes/html-input-element/HTMLInputElement.d.ts +43 -19
  145. package/lib/nodes/html-input-element/HTMLInputElement.js +206 -111
  146. package/lib/nodes/html-input-element/HTMLInputElement.js.map +1 -1
  147. package/lib/nodes/html-input-element/IHTMLInputElement.d.ts +14 -1
  148. package/lib/nodes/html-label-element/HTMLLabelElement.js +3 -7
  149. package/lib/nodes/html-label-element/HTMLLabelElement.js.map +1 -1
  150. package/lib/nodes/html-link-element/HTMLLinkElement.js +21 -21
  151. package/lib/nodes/html-link-element/HTMLLinkElement.js.map +1 -1
  152. package/lib/nodes/html-media-element/HTMLMediaElement.js +21 -21
  153. package/lib/nodes/html-media-element/HTMLMediaElement.js.map +1 -1
  154. package/lib/nodes/html-meta-element/HTMLMetaElement.js +8 -8
  155. package/lib/nodes/html-meta-element/HTMLMetaElement.js.map +1 -1
  156. package/lib/nodes/html-opt-group-element/HTMLOptGroupElement.js +6 -6
  157. package/lib/nodes/html-opt-group-element/HTMLOptGroupElement.js.map +1 -1
  158. package/lib/nodes/html-option-element/HTMLOptionElement.d.ts +3 -4
  159. package/lib/nodes/html-option-element/HTMLOptionElement.js +26 -29
  160. package/lib/nodes/html-option-element/HTMLOptionElement.js.map +1 -1
  161. package/lib/nodes/html-script-element/HTMLScriptElement.js +16 -16
  162. package/lib/nodes/html-script-element/HTMLScriptElement.js.map +1 -1
  163. package/lib/nodes/html-script-element/ScriptUtility.js +5 -5
  164. package/lib/nodes/html-script-element/ScriptUtility.js.map +1 -1
  165. package/lib/nodes/{html-option-element → html-select-element}/HTMLOptionsCollection.d.ts +5 -6
  166. package/lib/nodes/{html-option-element → html-select-element}/HTMLOptionsCollection.js.map +1 -1
  167. package/lib/nodes/html-select-element/HTMLSelectElement.d.ts +42 -41
  168. package/lib/nodes/html-select-element/HTMLSelectElement.js +134 -138
  169. package/lib/nodes/html-select-element/HTMLSelectElement.js.map +1 -1
  170. package/lib/nodes/{html-option-element → html-select-element}/IHTMLOptionsCollection.d.ts +4 -5
  171. package/lib/nodes/html-select-element/IHTMLOptionsCollection.js.map +1 -0
  172. package/lib/nodes/html-select-element/IHTMLSelectElement.d.ts +22 -2
  173. package/lib/nodes/html-slot-element/HTMLSlotElement.js +2 -2
  174. package/lib/nodes/html-slot-element/HTMLSlotElement.js.map +1 -1
  175. package/lib/nodes/html-style-element/HTMLStyleElement.js +7 -7
  176. package/lib/nodes/html-style-element/HTMLStyleElement.js.map +1 -1
  177. package/lib/nodes/html-text-area-element/HTMLTextAreaElement.d.ts +55 -2
  178. package/lib/nodes/html-text-area-element/HTMLTextAreaElement.js +150 -40
  179. package/lib/nodes/html-text-area-element/HTMLTextAreaElement.js.map +1 -1
  180. package/lib/nodes/html-text-area-element/IHTMLTextAreaElement.d.ts +16 -0
  181. package/lib/nodes/node/Node.d.ts +12 -1
  182. package/lib/nodes/node/Node.js +50 -4
  183. package/lib/nodes/node/Node.js.map +1 -1
  184. package/lib/nodes/node/NodeList.d.ts +2 -3
  185. package/lib/nodes/node/NodeList.js.map +1 -1
  186. package/lib/nodes/parent-node/IParentNode.d.ts +4 -4
  187. package/lib/nodes/parent-node/ParentNodeUtility.d.ts +3 -3
  188. package/lib/nodes/parent-node/ParentNodeUtility.js +13 -11
  189. package/lib/nodes/parent-node/ParentNodeUtility.js.map +1 -1
  190. package/lib/nodes/text/Text.d.ts +13 -0
  191. package/lib/nodes/text/Text.js +30 -0
  192. package/lib/nodes/text/Text.js.map +1 -1
  193. package/lib/query-selector/QuerySelector.js +2 -2
  194. package/lib/query-selector/QuerySelector.js.map +1 -1
  195. package/lib/query-selector/SelectorItem.js +2 -0
  196. package/lib/query-selector/SelectorItem.js.map +1 -1
  197. package/lib/validity-state/ValidityState.d.ts +87 -0
  198. package/lib/validity-state/ValidityState.js +171 -0
  199. package/lib/validity-state/ValidityState.js.map +1 -0
  200. package/lib/window/GlobalWindow.d.ts +0 -8
  201. package/lib/window/GlobalWindow.js +0 -2
  202. package/lib/window/GlobalWindow.js.map +1 -1
  203. package/lib/window/INodeJSGlobal.d.ts +71 -0
  204. package/lib/window/INodeJSGlobal.js +2 -0
  205. package/lib/window/INodeJSGlobal.js.map +1 -0
  206. package/lib/window/IWindow.d.ts +30 -10
  207. package/lib/window/Window.d.ts +36 -20
  208. package/lib/window/Window.js +16 -9
  209. package/lib/window/Window.js.map +1 -1
  210. package/lib/xml-http-request/XMLHttpRequest.js +20 -12
  211. package/lib/xml-http-request/XMLHttpRequest.js.map +1 -1
  212. package/lib/xml-parser/XMLParser.js +1 -1
  213. package/lib/xml-parser/XMLParser.js.map +1 -1
  214. package/package.json +2 -3
  215. package/src/cookie/CookieJar.ts +1 -1
  216. package/src/dom-token-list/DOMTokenList.ts +24 -20
  217. package/src/event/EventTarget.ts +7 -3
  218. package/src/exception/DOMExceptionNameEnum.ts +5 -1
  219. package/src/fetch/AbortController.ts +26 -0
  220. package/src/fetch/AbortSignal.ts +44 -0
  221. package/src/fetch/Fetch.ts +666 -0
  222. package/src/fetch/Headers.ts +151 -3
  223. package/src/fetch/Request.ts +226 -94
  224. package/src/fetch/{ResourceFetchHandler.ts → ResourceFetch.ts} +3 -3
  225. package/src/fetch/Response.ts +252 -89
  226. package/src/fetch/data-uri/DataURIParser.ts +66 -0
  227. package/src/fetch/multipart/MultipartFormDataParser.ts +113 -0
  228. package/src/fetch/multipart/MultipartReader.ts +217 -0
  229. package/src/fetch/types/IHeaders.ts +80 -0
  230. package/src/fetch/types/IRequest.ts +65 -0
  231. package/src/fetch/types/IRequestBody.ts +15 -0
  232. package/src/fetch/types/IRequestCredentials.ts +2 -0
  233. package/src/fetch/types/IRequestInfo.ts +6 -0
  234. package/src/fetch/types/IRequestInit.ts +21 -0
  235. package/src/fetch/types/IRequestRedirect.ts +3 -0
  236. package/src/fetch/types/IRequestReferrerPolicy.ts +11 -0
  237. package/src/fetch/types/IResponse.ts +27 -0
  238. package/src/fetch/types/IResponseBody.ts +15 -0
  239. package/src/fetch/types/IResponseInit.ts +10 -0
  240. package/src/fetch/utilities/FetchBodyUtility.ts +175 -0
  241. package/src/fetch/utilities/FetchCORSUtility.ts +18 -0
  242. package/src/fetch/utilities/FetchRequestHeaderUtility.ts +47 -0
  243. package/src/fetch/utilities/FetchRequestReferrerUtility.ts +241 -0
  244. package/src/fetch/utilities/FetchRequestValidationUtility.ts +82 -0
  245. package/src/file/Blob.ts +2 -2
  246. package/src/file/File.ts +5 -1
  247. package/src/form-data/FormData.ts +237 -0
  248. package/src/index.ts +27 -1
  249. package/src/nodes/document/Document.ts +23 -64
  250. package/src/nodes/document/IDocument.ts +1 -1
  251. package/src/nodes/document-fragment/DocumentFragment.ts +9 -59
  252. package/src/nodes/document-fragment/IDocumentFragment.ts +2 -1
  253. package/src/nodes/element/Element.ts +43 -56
  254. package/src/nodes/element/ElementUtility.ts +137 -0
  255. package/src/nodes/element/HTMLCollection.ts +60 -3
  256. package/src/nodes/element/IHTMLCollection.ts +10 -2
  257. package/src/nodes/html-anchor-element/HTMLAnchorElement.ts +24 -24
  258. package/src/nodes/html-base-element/HTMLBaseElement.ts +4 -4
  259. package/src/nodes/html-button-element/HTMLButtonElement.ts +184 -10
  260. package/src/nodes/html-button-element/IHTMLButtonElement.ts +31 -2
  261. package/src/nodes/html-dialog-element/HTMLDialogElement.ts +3 -3
  262. package/src/nodes/html-element/HTMLElement.ts +12 -12
  263. package/src/nodes/html-form-element/HTMLFormControlsCollection.ts +76 -0
  264. package/src/nodes/html-form-element/HTMLFormElement.ts +147 -41
  265. package/src/nodes/html-form-element/IHTMLFormControlsCollection.ts +45 -0
  266. package/src/nodes/html-form-element/IHTMLFormElement.ts +17 -6
  267. package/src/nodes/html-form-element/IRadioNodeList.ts +16 -0
  268. package/src/nodes/html-form-element/RadioNodeList.ts +24 -0
  269. package/src/nodes/html-image-element/HTMLImageElement.ts +19 -19
  270. package/src/nodes/html-input-element/HTMLInputElement.ts +232 -113
  271. package/src/nodes/html-input-element/IHTMLInputElement.ts +20 -1
  272. package/src/nodes/html-label-element/HTMLLabelElement.ts +3 -7
  273. package/src/nodes/html-link-element/HTMLLinkElement.ts +21 -21
  274. package/src/nodes/html-media-element/HTMLMediaElement.ts +21 -21
  275. package/src/nodes/html-meta-element/HTMLMetaElement.ts +8 -8
  276. package/src/nodes/html-opt-group-element/HTMLOptGroupElement.ts +6 -6
  277. package/src/nodes/html-option-element/HTMLOptionElement.ts +29 -30
  278. package/src/nodes/html-script-element/HTMLScriptElement.ts +16 -16
  279. package/src/nodes/html-script-element/ScriptUtility.ts +5 -5
  280. package/src/nodes/{html-option-element → html-select-element}/HTMLOptionsCollection.ts +5 -9
  281. package/src/nodes/html-select-element/HTMLSelectElement.ts +159 -170
  282. package/src/nodes/{html-option-element → html-select-element}/IHTMLOptionsCollection.ts +4 -8
  283. package/src/nodes/html-select-element/IHTMLSelectElement.ts +25 -2
  284. package/src/nodes/html-slot-element/HTMLSlotElement.ts +2 -2
  285. package/src/nodes/html-style-element/HTMLStyleElement.ts +7 -7
  286. package/src/nodes/html-text-area-element/HTMLTextAreaElement.ts +174 -41
  287. package/src/nodes/html-text-area-element/IHTMLTextAreaElement.ts +18 -0
  288. package/src/nodes/node/Node.ts +61 -6
  289. package/src/nodes/node/NodeList.ts +2 -3
  290. package/src/nodes/parent-node/IParentNode.ts +7 -4
  291. package/src/nodes/parent-node/ParentNodeUtility.ts +25 -15
  292. package/src/nodes/text/Text.ts +38 -0
  293. package/src/query-selector/QuerySelector.ts +2 -2
  294. package/src/query-selector/SelectorItem.ts +3 -0
  295. package/src/validity-state/ValidityState.ts +211 -0
  296. package/src/window/GlobalWindow.ts +0 -2
  297. package/src/window/INodeJSGlobal.ts +70 -0
  298. package/src/window/IWindow.ts +32 -10
  299. package/src/window/Window.ts +37 -20
  300. package/src/xml-http-request/XMLHttpRequest.ts +27 -26
  301. package/src/xml-parser/XMLParser.ts +1 -1
  302. package/lib/fetch/FetchHandler.d.ts +0 -18
  303. package/lib/fetch/FetchHandler.js +0 -83
  304. package/lib/fetch/FetchHandler.js.map +0 -1
  305. package/lib/fetch/IAbortSignal.d.ts +0 -16
  306. package/lib/fetch/IAbortSignal.js +0 -4
  307. package/lib/fetch/IAbortSignal.js.map +0 -1
  308. package/lib/fetch/IBody.d.ts +0 -17
  309. package/lib/fetch/IBody.js.map +0 -1
  310. package/lib/fetch/IHeaders.d.ts +0 -18
  311. package/lib/fetch/IHeadersInit.js.map +0 -1
  312. package/lib/fetch/IRequest.d.ts +0 -18
  313. package/lib/fetch/IRequestInit.d.ts +0 -16
  314. package/lib/fetch/IRequestInit.js.map +0 -1
  315. package/lib/fetch/IResponse.d.ts +0 -20
  316. package/lib/fetch/IResponseInit.d.ts +0 -9
  317. package/lib/fetch/IResponseInit.js.map +0 -1
  318. package/lib/fetch/RequestInfo.js +0 -3
  319. package/lib/fetch/RequestInfo.js.map +0 -1
  320. package/lib/fetch/ResourceFetchHandler.js.map +0 -1
  321. package/lib/form-data/IFormData.d.ts +0 -32
  322. package/lib/form-data/IFormData.js +0 -3
  323. package/lib/form-data/IFormData.js.map +0 -1
  324. package/lib/location/RelativeURL.d.ts +0 -15
  325. package/lib/location/RelativeURL.js +0 -19
  326. package/lib/location/RelativeURL.js.map +0 -1
  327. package/lib/nodes/element/HTMLCollectionFactory.d.ts +0 -21
  328. package/lib/nodes/element/HTMLCollectionFactory.js +0 -31
  329. package/lib/nodes/element/HTMLCollectionFactory.js.map +0 -1
  330. package/lib/nodes/html-option-element/IHTMLOptionsCollection.js.map +0 -1
  331. package/lib/nodes/node/NodeListFactory.d.ts +0 -21
  332. package/lib/nodes/node/NodeListFactory.js +0 -31
  333. package/lib/nodes/node/NodeListFactory.js.map +0 -1
  334. package/lib/nodes/validity-state/ValidityState.d.ts +0 -52
  335. package/lib/nodes/validity-state/ValidityState.js +0 -81
  336. package/lib/nodes/validity-state/ValidityState.js.map +0 -1
  337. package/src/fetch/FetchHandler.ts +0 -90
  338. package/src/fetch/IAbortSignal.ts +0 -34
  339. package/src/fetch/IBody.ts +0 -18
  340. package/src/fetch/IHeaders.ts +0 -18
  341. package/src/fetch/IRequest.ts +0 -59
  342. package/src/fetch/IRequestInit.ts +0 -41
  343. package/src/fetch/IResponse.ts +0 -22
  344. package/src/fetch/IResponseInit.ts +0 -10
  345. package/src/fetch/RequestInfo.ts +0 -6
  346. package/src/form-data/IFormData.ts +0 -33
  347. package/src/location/RelativeURL.ts +0 -17
  348. package/src/nodes/element/HTMLCollectionFactory.ts +0 -31
  349. package/src/nodes/node/NodeListFactory.ts +0 -31
  350. package/src/nodes/validity-state/ValidityState.ts +0 -84
  351. /package/lib/fetch/{IHeaders.js → types/IHeaders.js} +0 -0
  352. /package/lib/fetch/{IHeadersInit.d.ts → types/IHeadersInit.d.ts} +0 -0
  353. /package/lib/fetch/{IHeadersInit.js → types/IHeadersInit.js} +0 -0
  354. /package/lib/fetch/{IRequest.js → types/IRequest.js} +0 -0
  355. /package/lib/fetch/{IRequestInit.js → types/IRequestInit.js} +0 -0
  356. /package/lib/fetch/{IResponse.js → types/IResponse.js} +0 -0
  357. /package/lib/fetch/{IResponseInit.js → types/IResponseInit.js} +0 -0
  358. /package/lib/nodes/{html-option-element → html-select-element}/HTMLOptionsCollection.js +0 -0
  359. /package/lib/nodes/{html-option-element → html-select-element}/IHTMLOptionsCollection.js +0 -0
  360. /package/src/fetch/{IHeadersInit.ts → types/IHeadersInit.ts} +0 -0
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=IResponseBody.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IResponseBody.js","sourceRoot":"","sources":["../../../src/fetch/types/IResponseBody.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ import IHeadersInit from './IHeadersInit';
2
+ /**
3
+ * Response init.
4
+ */
5
+ export default interface IResponseInit {
6
+ headers?: IHeadersInit | undefined;
7
+ status?: number | undefined;
8
+ statusText?: string | undefined;
9
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IResponseInit.js","sourceRoot":"","sources":["../../../src/fetch/types/IResponseInit.ts"],"names":[],"mappings":""}
@@ -0,0 +1,44 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import Stream from 'stream';
4
+ import IRequestBody from '../types/IRequestBody';
5
+ import IResponseBody from '../types/IResponseBody';
6
+ import Request from '../Request';
7
+ /**
8
+ * Fetch body utility.
9
+ */
10
+ export default class FetchBodyUtility {
11
+ /**
12
+ * Parses body and returns stream and type.
13
+ *
14
+ * Based on:
15
+ * https://github.com/node-fetch/node-fetch/blob/main/src/body.js (MIT)
16
+ *
17
+ * @param body Body.
18
+ * @returns Stream and type.
19
+ */
20
+ static getBodyStream(body: IRequestBody | IResponseBody): {
21
+ contentType: string;
22
+ contentLength: number | null;
23
+ stream: Stream.Readable;
24
+ buffer: Buffer | null;
25
+ };
26
+ /**
27
+ * Clones a request body stream.
28
+ *
29
+ * @param request Request.
30
+ * @returns Stream.
31
+ */
32
+ static cloneRequestBodyStream(request: Request): Stream.Readable;
33
+ /**
34
+ * Consume and convert an entire Body to a Buffer.
35
+ *
36
+ * Based on:
37
+ * https://github.com/node-fetch/node-fetch/blob/main/src/body.js (MIT)
38
+ *
39
+ * @see https://fetch.spec.whatwg.org/#concept-body-consume-body
40
+ * @param body Body stream.
41
+ * @returns Promise.
42
+ */
43
+ static consumeBodyStream(body: Stream.Readable | null): Promise<Buffer>;
44
+ }
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const MultipartFormDataParser_1 = __importDefault(require("../multipart/MultipartFormDataParser"));
7
+ const stream_1 = __importDefault(require("stream"));
8
+ const url_1 = require("url");
9
+ const FormData_1 = __importDefault(require("../../form-data/FormData"));
10
+ const Blob_1 = __importDefault(require("../../file/Blob"));
11
+ const DOMException_1 = __importDefault(require("../../exception/DOMException"));
12
+ const DOMExceptionNameEnum_1 = __importDefault(require("../../exception/DOMExceptionNameEnum"));
13
+ /**
14
+ * Fetch body utility.
15
+ */
16
+ class FetchBodyUtility {
17
+ /**
18
+ * Parses body and returns stream and type.
19
+ *
20
+ * Based on:
21
+ * https://github.com/node-fetch/node-fetch/blob/main/src/body.js (MIT)
22
+ *
23
+ * @param body Body.
24
+ * @returns Stream and type.
25
+ */
26
+ static getBodyStream(body) {
27
+ if (body === null || body === undefined) {
28
+ return { stream: null, buffer: null, contentType: null, contentLength: null };
29
+ }
30
+ else if (body instanceof url_1.URLSearchParams) {
31
+ const buffer = Buffer.from(body.toString());
32
+ return {
33
+ buffer,
34
+ stream: stream_1.default.Readable.from(Buffer.from(buffer)),
35
+ contentType: 'application/x-www-form-urlencoded;charset=UTF-8',
36
+ contentLength: buffer.length
37
+ };
38
+ }
39
+ else if (body instanceof Blob_1.default) {
40
+ const buffer = body._buffer;
41
+ return {
42
+ buffer,
43
+ stream: stream_1.default.Readable.from(buffer),
44
+ contentType: body.type,
45
+ contentLength: body.size
46
+ };
47
+ }
48
+ else if (Buffer.isBuffer(body)) {
49
+ return {
50
+ buffer: body,
51
+ stream: stream_1.default.Readable.from(body),
52
+ contentType: null,
53
+ contentLength: body.length
54
+ };
55
+ }
56
+ else if (body instanceof ArrayBuffer) {
57
+ const buffer = Buffer.from(body);
58
+ return {
59
+ buffer,
60
+ stream: stream_1.default.Readable.from(buffer),
61
+ contentType: null,
62
+ contentLength: body.byteLength
63
+ };
64
+ }
65
+ else if (ArrayBuffer.isView(body)) {
66
+ const buffer = Buffer.from(body.buffer, body.byteOffset, body.byteLength);
67
+ return {
68
+ buffer,
69
+ stream: stream_1.default.Readable.from(buffer),
70
+ contentType: null,
71
+ contentLength: body.byteLength
72
+ };
73
+ }
74
+ else if (body instanceof stream_1.default.Stream) {
75
+ return {
76
+ buffer: null,
77
+ stream: body,
78
+ contentType: null,
79
+ contentLength: null
80
+ };
81
+ }
82
+ else if (body instanceof FormData_1.default) {
83
+ return MultipartFormDataParser_1.default.formDataToStream(body);
84
+ }
85
+ const buffer = Buffer.from(String(body));
86
+ return {
87
+ buffer,
88
+ stream: stream_1.default.Readable.from(buffer),
89
+ contentType: 'text/plain;charset=UTF-8',
90
+ contentLength: buffer.length
91
+ };
92
+ }
93
+ /**
94
+ * Clones a request body stream.
95
+ *
96
+ * @param request Request.
97
+ * @returns Stream.
98
+ */
99
+ static cloneRequestBodyStream(request) {
100
+ if (request.bodyUsed) {
101
+ throw new DOMException_1.default(`Failed to clone body stream of request: Request body is already used.`, DOMExceptionNameEnum_1.default.invalidStateError);
102
+ }
103
+ const p1 = new stream_1.default.PassThrough();
104
+ const p2 = new stream_1.default.PassThrough();
105
+ request.body.pipe(p1);
106
+ request.body.pipe(p2);
107
+ // Sets the body of the cloned request to the first pass through stream.
108
+ request.body = p1;
109
+ // Returns the clone.
110
+ return p2;
111
+ }
112
+ /**
113
+ * Consume and convert an entire Body to a Buffer.
114
+ *
115
+ * Based on:
116
+ * https://github.com/node-fetch/node-fetch/blob/main/src/body.js (MIT)
117
+ *
118
+ * @see https://fetch.spec.whatwg.org/#concept-body-consume-body
119
+ * @param body Body stream.
120
+ * @returns Promise.
121
+ */
122
+ static async consumeBodyStream(body) {
123
+ if (body === null || !(body instanceof stream_1.default.Stream)) {
124
+ return Buffer.alloc(0);
125
+ }
126
+ const chunks = [];
127
+ let bytes = 0;
128
+ try {
129
+ for await (const chunk of body) {
130
+ bytes += chunk.length;
131
+ chunks.push(chunk);
132
+ }
133
+ }
134
+ catch (error) {
135
+ if (error instanceof DOMException_1.default) {
136
+ throw error;
137
+ }
138
+ throw new DOMException_1.default(`Failed to read response body. Error: ${error.message}.`, DOMExceptionNameEnum_1.default.encodingError);
139
+ }
140
+ if (body.readableEnded === false ||
141
+ body['_readableState']?.ended === false) {
142
+ throw new DOMException_1.default(`Premature close of server response.`, DOMExceptionNameEnum_1.default.invalidStateError);
143
+ }
144
+ try {
145
+ if (typeof chunks[0] === 'string') {
146
+ return Buffer.from(chunks.join(''));
147
+ }
148
+ return Buffer.concat(chunks, bytes);
149
+ }
150
+ catch (error) {
151
+ throw new DOMException_1.default(`Could not create Buffer from response body. Error: ${error.message}.`, DOMExceptionNameEnum_1.default.invalidStateError);
152
+ }
153
+ }
154
+ }
155
+ exports.default = FetchBodyUtility;
156
+ //# sourceMappingURL=FetchBodyUtility.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FetchBodyUtility.js","sourceRoot":"","sources":["../../../src/fetch/utilities/FetchBodyUtility.ts"],"names":[],"mappings":";;;;;AAAA,mGAA2E;AAC3E,oDAA4B;AAC5B,6BAAsC;AACtC,wEAAgD;AAChD,2DAAmC;AACnC,gFAAwD;AACxD,gGAAwE;AAKxE;;GAEG;AACH,MAAqB,gBAAgB;IACpC;;;;;;;;OAQG;IACI,MAAM,CAAC,aAAa,CAAC,IAAkC;QAM7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,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;aACpC;YAED,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;SACpC;QAAC,OAAO,KAAK,EAAE;YACf,MAAM,IAAI,sBAAY,CACrB,sDAAsD,KAAK,CAAC,OAAO,GAAG,EACtE,8BAAoB,CAAC,iBAAiB,CACtC,CAAC;SACF;IACF,CAAC;CACD;AAhKD,mCAgKC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Fetch CORS utility.
3
+ */
4
+ export default class FetchCORSUtility {
5
+ /**
6
+ * Validates request headers.
7
+ *
8
+ * @param originURL Origin URL.
9
+ * @param targetURL Target URL.
10
+ */
11
+ static isCORS(originURL: any, targetURL: any): boolean;
12
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Fetch CORS utility.
5
+ */
6
+ class FetchCORSUtility {
7
+ /**
8
+ * Validates request headers.
9
+ *
10
+ * @param originURL Origin URL.
11
+ * @param targetURL Target URL.
12
+ */
13
+ static isCORS(originURL, targetURL) {
14
+ return ((originURL.hostname !== targetURL.hostname &&
15
+ !originURL.hostname.endsWith(targetURL.hostname)) ||
16
+ originURL.protocol !== targetURL.protocol);
17
+ }
18
+ }
19
+ exports.default = FetchCORSUtility;
20
+ //# sourceMappingURL=FetchCORSUtility.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FetchCORSUtility.js","sourceRoot":"","sources":["../../../src/fetch/utilities/FetchCORSUtility.ts"],"names":[],"mappings":";;AAAA;;GAEG;AACH,MAAqB,gBAAgB;IACpC;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,SAAS;QACxC,OAAO,CACN,CAAC,SAAS,CAAC,QAAQ,KAAK,SAAS,CAAC,QAAQ;YACzC,CAAC,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;YAClD,SAAS,CAAC,QAAQ,KAAK,SAAS,CAAC,QAAQ,CACzC,CAAC;IACH,CAAC;CACD;AAdD,mCAcC"}
@@ -0,0 +1,12 @@
1
+ import IHeaders from '../types/IHeaders';
2
+ /**
3
+ * Fetch request header utility.
4
+ */
5
+ export default class FetchRequestHeaderUtility {
6
+ /**
7
+ * Validates request headers.
8
+ *
9
+ * @param headers Headers.
10
+ */
11
+ static removeForbiddenHeaders(headers: IHeaders): void;
12
+ }
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const FORBIDDEN_HEADER_NAMES = [
4
+ 'accept-charset',
5
+ 'accept-encoding',
6
+ 'access-control-request-headers',
7
+ 'access-control-request-method',
8
+ 'connection',
9
+ 'content-length',
10
+ 'cookie',
11
+ 'cookie2',
12
+ 'date',
13
+ 'dnt',
14
+ 'expect',
15
+ 'host',
16
+ 'keep-alive',
17
+ 'origin',
18
+ 'referer',
19
+ 'te',
20
+ 'trailer',
21
+ 'transfer-encoding',
22
+ 'upgrade',
23
+ 'via'
24
+ ];
25
+ /**
26
+ * Fetch request header utility.
27
+ */
28
+ class FetchRequestHeaderUtility {
29
+ /**
30
+ * Validates request headers.
31
+ *
32
+ * @param headers Headers.
33
+ */
34
+ static removeForbiddenHeaders(headers) {
35
+ for (const key of Object.keys(headers._entries)) {
36
+ if (FORBIDDEN_HEADER_NAMES.includes(key) ||
37
+ key.startsWith('proxy-') ||
38
+ key.startsWith('sec-')) {
39
+ delete headers._entries[key];
40
+ }
41
+ }
42
+ }
43
+ }
44
+ exports.default = FetchRequestHeaderUtility;
45
+ //# sourceMappingURL=FetchRequestHeaderUtility.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FetchRequestHeaderUtility.js","sourceRoot":"","sources":["../../../src/fetch/utilities/FetchRequestHeaderUtility.ts"],"names":[],"mappings":";;AAGA,MAAM,sBAAsB,GAAG;IAC9B,gBAAgB;IAChB,iBAAiB;IACjB,gCAAgC;IAChC,+BAA+B;IAC/B,YAAY;IACZ,gBAAgB;IAChB,QAAQ;IACR,SAAS;IACT,MAAM;IACN,KAAK;IACL,QAAQ;IACR,MAAM;IACN,YAAY;IACZ,QAAQ;IACR,SAAS;IACT,IAAI;IACJ,SAAS;IACT,mBAAmB;IACnB,SAAS;IACT,KAAK;CACL,CAAC;AAEF;;GAEG;AACH,MAAqB,yBAAyB;IAC7C;;;;OAIG;IACI,MAAM,CAAC,sBAAsB,CAAC,OAAiB;QACrD,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAW,OAAQ,CAAC,QAAQ,CAAC,EAAE;YAC3D,IACC,sBAAsB,CAAC,QAAQ,CAAC,GAAG,CAAC;gBACpC,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC;gBACxB,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,EACrB;gBACD,OAAiB,OAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;aACxC;SACD;IACF,CAAC;CACD;AAjBD,4CAiBC"}
@@ -0,0 +1,55 @@
1
+ /// <reference types="node" />
2
+ import { URL } from 'url';
3
+ import IRequest from '../types/IRequest';
4
+ import IDocument from '../../nodes/document/IDocument';
5
+ import Headers from '../Headers';
6
+ import IRequestReferrerPolicy from '../types/IRequestReferrerPolicy';
7
+ /**
8
+ * Fetch referrer utility.
9
+ */
10
+ export default class FetchRequestReferrerUtility {
11
+ /**
12
+ * Returns the request referrer to be used as the value for the "Referer" header.
13
+ *
14
+ * Based on:
15
+ * https://github.com/node-fetch/node-fetch/blob/main/src/utils/referrer.js (MIT)
16
+ *
17
+ * @see https://w3c.github.io/webappsec-referrer-policy/#determine-requests-referrer
18
+ * @param document Document.
19
+ * @param request Request.
20
+ * @returns Request referrer.
21
+ */
22
+ static getSentReferrer(document: IDocument, request: IRequest): '' | 'no-referrer' | 'client' | URL;
23
+ /**
24
+ * Returns initial referrer.
25
+ *
26
+ * @param document Document.
27
+ * @param referrer Referrer.
28
+ * @returns Initial referrer.
29
+ */
30
+ static getInitialReferrer(document: IDocument, referrer: '' | 'no-referrer' | 'client' | string | URL): '' | 'no-referrer' | 'client' | URL;
31
+ /**
32
+ * Returns referrer policy from header.
33
+ *
34
+ * @see https://w3c.github.io/webappsec-referrer-policy/#parse-referrer-policy-from-header
35
+ * @param headers Response headers
36
+ * @returns Policy.
37
+ */
38
+ static getReferrerPolicyFromHeader(headers: Headers): IRequestReferrerPolicy;
39
+ /**
40
+ * Returns "true" if the request's referrer is potentially trustworthy.
41
+ *
42
+ * @see https://w3c.github.io/webappsec-secure-contexts/#is-origin-trustworthy
43
+ * @param url URL.
44
+ * @returns "true" if the request's referrer is potentially trustworthy.
45
+ */
46
+ private static isURLPotentiallyTrustWorthy;
47
+ /**
48
+ * Returns "true" if the request's referrer origin is potentially trustworthy.
49
+ *
50
+ * @see https://w3c.github.io/webappsec-secure-contexts/#is-origin-trustworthy
51
+ * @param url URL.
52
+ * @returns "true" if the request's referrer origin is potentially trustworthy.
53
+ */
54
+ private static isOriginPotentiallyTrustWorthy;
55
+ }
@@ -0,0 +1,194 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const url_1 = require("url");
4
+ const net_1 = require("net");
5
+ const REQUEST_REFERRER_UNSUPPORTED_PROTOCOL_REGEXP = /^(about|blob|data):$/;
6
+ const REFERRER_POLICIES = [
7
+ '',
8
+ 'no-referrer',
9
+ 'no-referrer-when-downgrade',
10
+ 'same-origin',
11
+ 'origin',
12
+ 'strict-origin',
13
+ 'origin-when-cross-origin',
14
+ 'strict-origin-when-cross-origin',
15
+ 'unsafe-url'
16
+ ];
17
+ /**
18
+ * Fetch referrer utility.
19
+ */
20
+ class FetchRequestReferrerUtility {
21
+ /**
22
+ * Returns the request referrer to be used as the value for the "Referer" header.
23
+ *
24
+ * Based on:
25
+ * https://github.com/node-fetch/node-fetch/blob/main/src/utils/referrer.js (MIT)
26
+ *
27
+ * @see https://w3c.github.io/webappsec-referrer-policy/#determine-requests-referrer
28
+ * @param document Document.
29
+ * @param request Request.
30
+ * @returns Request referrer.
31
+ */
32
+ static getSentReferrer(document, request) {
33
+ if (request.referrer === 'about:client' && document.defaultView.location.origin === 'null') {
34
+ return 'no-referrer';
35
+ }
36
+ const requestURL = new url_1.URL(request.url);
37
+ const referrerURL = request.referrer === 'about:client'
38
+ ? new url_1.URL(document.defaultView.location.href)
39
+ : new url_1.URL(request.referrer);
40
+ if (REQUEST_REFERRER_UNSUPPORTED_PROTOCOL_REGEXP.test(referrerURL.protocol)) {
41
+ return 'no-referrer';
42
+ }
43
+ referrerURL.username = '';
44
+ referrerURL.password = '';
45
+ referrerURL.hash = '';
46
+ switch (request.referrerPolicy) {
47
+ case 'no-referrer':
48
+ return 'no-referrer';
49
+ case 'origin':
50
+ return new url_1.URL(referrerURL.origin);
51
+ case 'unsafe-url':
52
+ return referrerURL;
53
+ case 'strict-origin':
54
+ if (this.isURLPotentiallyTrustWorthy(referrerURL) &&
55
+ !this.isURLPotentiallyTrustWorthy(requestURL)) {
56
+ return 'no-referrer';
57
+ }
58
+ return new url_1.URL(referrerURL.origin);
59
+ case 'strict-origin-when-cross-origin':
60
+ if (referrerURL.origin === requestURL.origin) {
61
+ return referrerURL;
62
+ }
63
+ if (this.isURLPotentiallyTrustWorthy(referrerURL) &&
64
+ !this.isURLPotentiallyTrustWorthy(requestURL)) {
65
+ return 'no-referrer';
66
+ }
67
+ return new url_1.URL(referrerURL.origin);
68
+ case 'same-origin':
69
+ if (referrerURL.origin === requestURL.origin) {
70
+ return referrerURL;
71
+ }
72
+ return 'no-referrer';
73
+ case 'origin-when-cross-origin':
74
+ if (referrerURL.origin === requestURL.origin) {
75
+ return referrerURL;
76
+ }
77
+ return new url_1.URL(referrerURL.origin);
78
+ case 'no-referrer-when-downgrade':
79
+ if (this.isURLPotentiallyTrustWorthy(referrerURL) &&
80
+ !this.isURLPotentiallyTrustWorthy(requestURL)) {
81
+ return 'no-referrer';
82
+ }
83
+ return referrerURL;
84
+ }
85
+ return 'no-referrer';
86
+ }
87
+ /**
88
+ * Returns initial referrer.
89
+ *
90
+ * @param document Document.
91
+ * @param referrer Referrer.
92
+ * @returns Initial referrer.
93
+ */
94
+ static getInitialReferrer(document, referrer) {
95
+ if (referrer === '' || referrer === 'no-referrer' || referrer === 'client') {
96
+ return referrer;
97
+ }
98
+ else if (referrer) {
99
+ const referrerURL = referrer instanceof url_1.URL ? referrer : new url_1.URL(referrer, document.location);
100
+ return referrerURL.origin === document.location.origin ? referrerURL : 'client';
101
+ }
102
+ return 'client';
103
+ }
104
+ /**
105
+ * Returns referrer policy from header.
106
+ *
107
+ * @see https://w3c.github.io/webappsec-referrer-policy/#parse-referrer-policy-from-header
108
+ * @param headers Response headers
109
+ * @returns Policy.
110
+ */
111
+ static getReferrerPolicyFromHeader(headers) {
112
+ const referrerPolicyHeader = headers.get('Referrer-Policy');
113
+ if (!referrerPolicyHeader) {
114
+ return '';
115
+ }
116
+ const policyTokens = referrerPolicyHeader.split(/[,\s]+/);
117
+ let policy = '';
118
+ for (const token of policyTokens) {
119
+ if (token && REFERRER_POLICIES.includes(token)) {
120
+ policy = token;
121
+ }
122
+ }
123
+ return policy;
124
+ }
125
+ /**
126
+ * Returns "true" if the request's referrer is potentially trustworthy.
127
+ *
128
+ * @see https://w3c.github.io/webappsec-secure-contexts/#is-origin-trustworthy
129
+ * @param url URL.
130
+ * @returns "true" if the request's referrer is potentially trustworthy.
131
+ */
132
+ static isURLPotentiallyTrustWorthy(url) {
133
+ // 1. If url is "about:blank" or "about:srcdoc", return "Potentially Trustworthy".
134
+ if (/^about:(blank|srcdoc)$/.test(url.href)) {
135
+ return true;
136
+ }
137
+ // 2. If url's scheme is "data", return "Potentially Trustworthy".
138
+ if (url.protocol === 'data:') {
139
+ return true;
140
+ }
141
+ // Note: The origin of blob: and filesystem: URLs is the origin of the context in which they were
142
+ // Created. Therefore, blobs created in a trustworthy origin will themselves be potentially
143
+ // Trustworthy.
144
+ if (/^(blob|filesystem):$/.test(url.protocol)) {
145
+ return true;
146
+ }
147
+ // 3. Return the result of executing §3.2 Is origin potentially trustworthy? on url's origin.
148
+ return this.isOriginPotentiallyTrustWorthy(url);
149
+ }
150
+ /**
151
+ * Returns "true" if the request's referrer origin is potentially trustworthy.
152
+ *
153
+ * @see https://w3c.github.io/webappsec-secure-contexts/#is-origin-trustworthy
154
+ * @param url URL.
155
+ * @returns "true" if the request's referrer origin is potentially trustworthy.
156
+ */
157
+ static isOriginPotentiallyTrustWorthy(url) {
158
+ // 1. If origin is an opaque origin, return "Not Trustworthy".
159
+ // Not applicable
160
+ // 2. Assert: origin is a tuple origin.
161
+ // Not for implementations
162
+ // 3. If origin's scheme is either "https" or "wss", return "Potentially Trustworthy".
163
+ if (/^(http|ws)s:$/.test(url.protocol)) {
164
+ return true;
165
+ }
166
+ // 4. If origin's host component matches one of the CIDR notations 127.0.0.0/8 or ::1/128 [RFC4632], return "Potentially Trustworthy".
167
+ const hostIp = url.host.replace(/(^\[)|(]$)/g, '');
168
+ const hostIPVersion = (0, net_1.isIP)(hostIp);
169
+ if (hostIPVersion === 4 && /^127\./.test(hostIp)) {
170
+ return true;
171
+ }
172
+ if (hostIPVersion === 6 && /^(((0+:){7})|(::(0+:){0,6}))0*1$/.test(hostIp)) {
173
+ return true;
174
+ }
175
+ // 5. If origin's host component is "localhost" or falls within ".localhost", and the user agent conforms to the name resolution rules in [let-localhost-be-localhost], return "Potentially Trustworthy".
176
+ // We are returning FALSE here because we cannot ensure conformance to
177
+ // Let-localhost-be-loalhost (https://tools.ietf.org/html/draft-west-let-localhost-be-localhost)
178
+ if (url.host === 'localhost' || url.host.endsWith('.localhost')) {
179
+ return false;
180
+ }
181
+ // 6. If origin's scheme component is file, return "Potentially Trustworthy".
182
+ if (url.protocol === 'file:') {
183
+ return true;
184
+ }
185
+ // 7. If origin's scheme component is one which the user agent considers to be authenticated, return "Potentially Trustworthy".
186
+ // Not supported
187
+ // 8. If origin has been configured as a trustworthy origin, return "Potentially Trustworthy".
188
+ // Not supported
189
+ // 9. Return "Not Trustworthy".
190
+ return false;
191
+ }
192
+ }
193
+ exports.default = FetchRequestReferrerUtility;
194
+ //# sourceMappingURL=FetchRequestReferrerUtility.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FetchRequestReferrerUtility.js","sourceRoot":"","sources":["../../../src/fetch/utilities/FetchRequestReferrerUtility.ts"],"names":[],"mappings":";;AAAA,6BAA0B;AAG1B,6BAA2B;AAI3B,MAAM,4CAA4C,GAAG,sBAAsB,CAAC;AAC5E,MAAM,iBAAiB,GAA6B;IACnD,EAAE;IACF,aAAa;IACb,4BAA4B;IAC5B,aAAa;IACb,QAAQ;IACR,eAAe;IACf,0BAA0B;IAC1B,iCAAiC;IACjC,YAAY;CACZ,CAAC;AAEF;;GAEG;AACH,MAAqB,2BAA2B;IAC/C;;;;;;;;;;OAUG;IACI,MAAM,CAAC,eAAe,CAC5B,QAAmB,EACnB,OAAiB;QAEjB,IAAI,OAAO,CAAC,QAAQ,KAAK,cAAc,IAAI,QAAQ,CAAC,WAAW,CAAC,QAAQ,CAAC,MAAM,KAAK,MAAM,EAAE;YAC3F,OAAO,aAAa,CAAC;SACrB;QAED,MAAM,UAAU,GAAG,IAAI,SAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACxC,MAAM,WAAW,GAChB,OAAO,CAAC,QAAQ,KAAK,cAAc;YAClC,CAAC,CAAC,IAAI,SAAG,CAAC,QAAQ,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC;YAC7C,CAAC,CAAC,IAAI,SAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAE9B,IAAI,4CAA4C,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE;YAC5E,OAAO,aAAa,CAAC;SACrB;QAED,WAAW,CAAC,QAAQ,GAAG,EAAE,CAAC;QAC1B,WAAW,CAAC,QAAQ,GAAG,EAAE,CAAC;QAC1B,WAAW,CAAC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;SACZ;QAED,+HAA+H;QAC/H,gBAAgB;QAEhB,8FAA8F;QAC9F,gBAAgB;QAEhB,+BAA+B;QAC/B,OAAO,KAAK,CAAC;IACd,CAAC;CACD;AAzND,8CAyNC"}
@@ -0,0 +1,38 @@
1
+ /// <reference types="node" />
2
+ import IRequestReferrerPolicy from '../types/IRequestReferrerPolicy';
3
+ import IRequestRedirect from '../types/IRequestRedirect';
4
+ import { URL } from 'url';
5
+ import IRequest from '../types/IRequest';
6
+ /**
7
+ * Fetch request validation utility.
8
+ */
9
+ export default class FetchRequestValidationUtility {
10
+ /**
11
+ * Validates request body.
12
+ *
13
+ * @throws DOMException
14
+ * @param request Request.
15
+ */
16
+ static validateBody(request: IRequest): void;
17
+ /**
18
+ * Validates request URL.
19
+ *
20
+ * @throws DOMException
21
+ * @param url URL.
22
+ */
23
+ static validateURL(url: URL): void;
24
+ /**
25
+ * Validates request referrer policy.
26
+ *
27
+ * @throws DOMException
28
+ * @param referrerPolicy Referrer policy.
29
+ */
30
+ static validateReferrerPolicy(referrerPolicy: IRequestReferrerPolicy): void;
31
+ /**
32
+ * Validates request redirect.
33
+ *
34
+ * @throws DOMException
35
+ * @param redirect Redirect.
36
+ */
37
+ static validateRedirect(redirect: IRequestRedirect): void;
38
+ }