fca-shadow 0.0.1-security → 2.3.8

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 fca-shadow might be problematic. Click here for more details.

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