fca-shadow 0.0.1-security → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of fca-shadow might be problematic. Click here for more details.

Files changed (502) hide show
  1. package/.1obgge4cxlazf1346921747~ +0 -0
  2. package/CHANGELOG.md +2 -0
  3. package/DOCS.md +1738 -0
  4. package/GetThreads/GetThreadInfo.js +128 -0
  5. package/GetThreads/Last-Run.js +65 -0
  6. package/LICENSE-MIT +21 -0
  7. package/README.md +132 -3
  8. package/StateCrypt.js +96 -0
  9. package/broadcast.js +22 -0
  10. package/index.html +1200 -0
  11. package/index.js +684 -0
  12. package/languages/index.json +150 -0
  13. package/lib/getInfoNew.js +34 -0
  14. package/lib/getToken.js +44 -0
  15. package/logger.js +23 -0
  16. package/package/database/SyntheticDatabase.sqlite +0 -0
  17. package/package/database/index.js +358 -0
  18. package/package/database/node_modules/lodash/_baseGet/README.md +20 -0
  19. package/package/database/node_modules/lodash/_baseGet/index.js +74 -0
  20. package/package/database/node_modules/lodash/_baseGet/package.json +18 -0
  21. package/package/database/node_modules/lodash/add.js +22 -0
  22. package/package/database/node_modules/lodash/after.js +42 -0
  23. package/package/database/node_modules/lodash/array.js +67 -0
  24. package/package/database/node_modules/lodash/ary.js +29 -0
  25. package/package/database/node_modules/lodash/assign.js +58 -0
  26. package/package/database/node_modules/lodash/assignIn.js +40 -0
  27. package/package/database/node_modules/lodash/assignInWith.js +38 -0
  28. package/package/database/node_modules/lodash/assignWith.js +37 -0
  29. package/package/database/node_modules/lodash/at.js +23 -0
  30. package/package/database/node_modules/lodash/attempt.js +35 -0
  31. package/package/database/node_modules/lodash/before.js +40 -0
  32. package/package/database/node_modules/lodash/bind.js +57 -0
  33. package/package/database/node_modules/lodash/bindAll.js +41 -0
  34. package/package/database/node_modules/lodash/bindKey.js +68 -0
  35. package/package/database/node_modules/lodash/camelCase.js +29 -0
  36. package/package/database/node_modules/lodash/capitalize.js +23 -0
  37. package/package/database/node_modules/lodash/castArray.js +44 -0
  38. package/package/database/node_modules/lodash/ceil.js +26 -0
  39. package/package/database/node_modules/lodash/chain.js +38 -0
  40. package/package/database/node_modules/lodash/chunk.js +50 -0
  41. package/package/database/node_modules/lodash/clamp.js +39 -0
  42. package/package/database/node_modules/lodash/clone.js +36 -0
  43. package/package/database/node_modules/lodash/cloneDeep.js +29 -0
  44. package/package/database/node_modules/lodash/cloneDeepWith.js +40 -0
  45. package/package/database/node_modules/lodash/cloneWith.js +42 -0
  46. package/package/database/node_modules/lodash/collection.js +30 -0
  47. package/package/database/node_modules/lodash/commit.js +33 -0
  48. package/package/database/node_modules/lodash/compact.js +31 -0
  49. package/package/database/node_modules/lodash/concat.js +43 -0
  50. package/package/database/node_modules/lodash/cond.js +60 -0
  51. package/package/database/node_modules/lodash/conforms.js +35 -0
  52. package/package/database/node_modules/lodash/conformsTo.js +32 -0
  53. package/package/database/node_modules/lodash/constant.js +26 -0
  54. package/package/database/node_modules/lodash/core.js +3877 -0
  55. package/package/database/node_modules/lodash/core.min.js +29 -0
  56. package/package/database/node_modules/lodash/countBy.js +40 -0
  57. package/package/database/node_modules/lodash/create.js +43 -0
  58. package/package/database/node_modules/lodash/curry.js +57 -0
  59. package/package/database/node_modules/lodash/curryRight.js +54 -0
  60. package/package/database/node_modules/lodash/date.js +3 -0
  61. package/package/database/node_modules/lodash/debounce.js +191 -0
  62. package/package/database/node_modules/lodash/deburr.js +45 -0
  63. package/package/database/node_modules/lodash/defaultTo.js +25 -0
  64. package/package/database/node_modules/lodash/defaults.js +64 -0
  65. package/package/database/node_modules/lodash/defaultsDeep.js +30 -0
  66. package/package/database/node_modules/lodash/defer.js +26 -0
  67. package/package/database/node_modules/lodash/delay.js +28 -0
  68. package/package/database/node_modules/lodash/difference.js +33 -0
  69. package/package/database/node_modules/lodash/differenceBy.js +44 -0
  70. package/package/database/node_modules/lodash/differenceWith.js +40 -0
  71. package/package/database/node_modules/lodash/divide.js +22 -0
  72. package/package/database/node_modules/lodash/drop.js +38 -0
  73. package/package/database/node_modules/lodash/dropRight.js +39 -0
  74. package/package/database/node_modules/lodash/dropRightWhile.js +45 -0
  75. package/package/database/node_modules/lodash/dropWhile.js +45 -0
  76. package/package/database/node_modules/lodash/each.js +1 -0
  77. package/package/database/node_modules/lodash/eachRight.js +1 -0
  78. package/package/database/node_modules/lodash/endsWith.js +43 -0
  79. package/package/database/node_modules/lodash/entries.js +1 -0
  80. package/package/database/node_modules/lodash/entriesIn.js +1 -0
  81. package/package/database/node_modules/lodash/eq.js +37 -0
  82. package/package/database/node_modules/lodash/escape.js +43 -0
  83. package/package/database/node_modules/lodash/escapeRegExp.js +32 -0
  84. package/package/database/node_modules/lodash/every.js +56 -0
  85. package/package/database/node_modules/lodash/extend.js +1 -0
  86. package/package/database/node_modules/lodash/extendWith.js +1 -0
  87. package/package/database/node_modules/lodash/fill.js +45 -0
  88. package/package/database/node_modules/lodash/filter.js +52 -0
  89. package/package/database/node_modules/lodash/find.js +42 -0
  90. package/package/database/node_modules/lodash/findIndex.js +55 -0
  91. package/package/database/node_modules/lodash/findKey.js +44 -0
  92. package/package/database/node_modules/lodash/findLast.js +25 -0
  93. package/package/database/node_modules/lodash/findLastIndex.js +59 -0
  94. package/package/database/node_modules/lodash/findLastKey.js +44 -0
  95. package/package/database/node_modules/lodash/first.js +1 -0
  96. package/package/database/node_modules/lodash/flake.lock +40 -0
  97. package/package/database/node_modules/lodash/flake.nix +20 -0
  98. package/package/database/node_modules/lodash/flatMap.js +29 -0
  99. package/package/database/node_modules/lodash/flatMapDeep.js +31 -0
  100. package/package/database/node_modules/lodash/flatMapDepth.js +31 -0
  101. package/package/database/node_modules/lodash/flatten.js +22 -0
  102. package/package/database/node_modules/lodash/flattenDeep.js +25 -0
  103. package/package/database/node_modules/lodash/flattenDepth.js +33 -0
  104. package/package/database/node_modules/lodash/flip.js +28 -0
  105. package/package/database/node_modules/lodash/floor.js +26 -0
  106. package/package/database/node_modules/lodash/flow.js +27 -0
  107. package/package/database/node_modules/lodash/flowRight.js +26 -0
  108. package/package/database/node_modules/lodash/forEach.js +41 -0
  109. package/package/database/node_modules/lodash/forEachRight.js +31 -0
  110. package/package/database/node_modules/lodash/forIn.js +39 -0
  111. package/package/database/node_modules/lodash/forInRight.js +37 -0
  112. package/package/database/node_modules/lodash/forOwn.js +36 -0
  113. package/package/database/node_modules/lodash/forOwnRight.js +34 -0
  114. package/package/database/node_modules/lodash/fp/F.js +1 -0
  115. package/package/database/node_modules/lodash/fp/add.js +5 -0
  116. package/package/database/node_modules/lodash/fp/after.js +5 -0
  117. package/package/database/node_modules/lodash/fp/all.js +1 -0
  118. package/package/database/node_modules/lodash/fp/allPass.js +1 -0
  119. package/package/database/node_modules/lodash/fp/always.js +1 -0
  120. package/package/database/node_modules/lodash/fp/any.js +1 -0
  121. package/package/database/node_modules/lodash/fp/anyPass.js +1 -0
  122. package/package/database/node_modules/lodash/fp/apply.js +1 -0
  123. package/package/database/node_modules/lodash/fp/array.js +2 -0
  124. package/package/database/node_modules/lodash/fp/ary.js +5 -0
  125. package/package/database/node_modules/lodash/fp/assign.js +5 -0
  126. package/package/database/node_modules/lodash/fp/assignAll.js +5 -0
  127. package/package/database/node_modules/lodash/fp/assignAllWith.js +5 -0
  128. package/package/database/node_modules/lodash/fp/assignIn.js +5 -0
  129. package/package/database/node_modules/lodash/fp/assignInAll.js +5 -0
  130. package/package/database/node_modules/lodash/fp/assignInAllWith.js +5 -0
  131. package/package/database/node_modules/lodash/fp/assignInWith.js +5 -0
  132. package/package/database/node_modules/lodash/fp/assignWith.js +5 -0
  133. package/package/database/node_modules/lodash/fp/assoc.js +1 -0
  134. package/package/database/node_modules/lodash/fp/assocPath.js +1 -0
  135. package/package/database/node_modules/lodash/fp/at.js +5 -0
  136. package/package/database/node_modules/lodash/fp/attempt.js +5 -0
  137. package/package/database/node_modules/lodash/fp/before.js +5 -0
  138. package/package/database/node_modules/lodash/fp/bind.js +5 -0
  139. package/package/database/node_modules/lodash/fp/bindAll.js +5 -0
  140. package/package/database/node_modules/lodash/fp/bindKey.js +5 -0
  141. package/package/database/node_modules/lodash/fp/camelCase.js +5 -0
  142. package/package/database/node_modules/lodash/fp/capitalize.js +5 -0
  143. package/package/database/node_modules/lodash/fp/castArray.js +5 -0
  144. package/package/database/node_modules/lodash/fp/ceil.js +5 -0
  145. package/package/database/node_modules/lodash/fp/chain.js +5 -0
  146. package/package/database/node_modules/lodash/fp/chunk.js +5 -0
  147. package/package/database/node_modules/lodash/fp/clamp.js +5 -0
  148. package/package/database/node_modules/lodash/fp/clone.js +5 -0
  149. package/package/database/node_modules/lodash/fp/cloneDeep.js +5 -0
  150. package/package/database/node_modules/lodash/fp/cloneDeepWith.js +5 -0
  151. package/package/database/node_modules/lodash/fp/cloneWith.js +5 -0
  152. package/package/database/node_modules/lodash/fp/collection.js +2 -0
  153. package/package/database/node_modules/lodash/fp/commit.js +5 -0
  154. package/package/database/node_modules/lodash/fp/compact.js +5 -0
  155. package/package/database/node_modules/lodash/fp/complement.js +1 -0
  156. package/package/database/node_modules/lodash/fp/compose.js +1 -0
  157. package/package/database/node_modules/lodash/fp/concat.js +5 -0
  158. package/package/database/node_modules/lodash/fp/cond.js +5 -0
  159. package/package/database/node_modules/lodash/fp/conforms.js +1 -0
  160. package/package/database/node_modules/lodash/fp/conformsTo.js +5 -0
  161. package/package/database/node_modules/lodash/fp/constant.js +5 -0
  162. package/package/database/node_modules/lodash/fp/contains.js +1 -0
  163. package/package/database/node_modules/lodash/fp/convert.js +18 -0
  164. package/package/database/node_modules/lodash/fp/countBy.js +5 -0
  165. package/package/database/node_modules/lodash/fp/create.js +5 -0
  166. package/package/database/node_modules/lodash/fp/curry.js +5 -0
  167. package/package/database/node_modules/lodash/fp/curryN.js +5 -0
  168. package/package/database/node_modules/lodash/fp/curryRight.js +5 -0
  169. package/package/database/node_modules/lodash/fp/curryRightN.js +5 -0
  170. package/package/database/node_modules/lodash/fp/date.js +2 -0
  171. package/package/database/node_modules/lodash/fp/debounce.js +5 -0
  172. package/package/database/node_modules/lodash/fp/deburr.js +5 -0
  173. package/package/database/node_modules/lodash/fp/defaultTo.js +5 -0
  174. package/package/database/node_modules/lodash/fp/defaults.js +5 -0
  175. package/package/database/node_modules/lodash/fp/defaultsAll.js +5 -0
  176. package/package/database/node_modules/lodash/fp/defaultsDeep.js +5 -0
  177. package/package/database/node_modules/lodash/fp/defaultsDeepAll.js +5 -0
  178. package/package/database/node_modules/lodash/fp/defer.js +5 -0
  179. package/package/database/node_modules/lodash/fp/delay.js +5 -0
  180. package/package/database/node_modules/lodash/fp/difference.js +5 -0
  181. package/package/database/node_modules/lodash/fp/differenceBy.js +5 -0
  182. package/package/database/node_modules/lodash/fp/differenceWith.js +5 -0
  183. package/package/database/node_modules/lodash/fp/dissoc.js +1 -0
  184. package/package/database/node_modules/lodash/fp/dissocPath.js +1 -0
  185. package/package/database/node_modules/lodash/fp/divide.js +5 -0
  186. package/package/database/node_modules/lodash/fp/drop.js +5 -0
  187. package/package/database/node_modules/lodash/fp/dropLast.js +1 -0
  188. package/package/database/node_modules/lodash/fp/dropLastWhile.js +1 -0
  189. package/package/database/node_modules/lodash/fp/dropRight.js +5 -0
  190. package/package/database/node_modules/lodash/fp/dropRightWhile.js +5 -0
  191. package/package/database/node_modules/lodash/fp/dropWhile.js +5 -0
  192. package/package/database/node_modules/lodash/fp/each.js +1 -0
  193. package/package/database/node_modules/lodash/fp/eachRight.js +1 -0
  194. package/package/database/node_modules/lodash/fp/endsWith.js +5 -0
  195. package/package/database/node_modules/lodash/fp/entries.js +1 -0
  196. package/package/database/node_modules/lodash/fp/entriesIn.js +1 -0
  197. package/package/database/node_modules/lodash/fp/eq.js +5 -0
  198. package/package/database/node_modules/lodash/fp/equals.js +1 -0
  199. package/package/database/node_modules/lodash/fp/escape.js +5 -0
  200. package/package/database/node_modules/lodash/fp/escapeRegExp.js +5 -0
  201. package/package/database/node_modules/lodash/fp/every.js +5 -0
  202. package/package/database/node_modules/lodash/fp/extend.js +1 -0
  203. package/package/database/node_modules/lodash/fp/extendAll.js +1 -0
  204. package/package/database/node_modules/lodash/fp/extendAllWith.js +1 -0
  205. package/package/database/node_modules/lodash/fp/extendWith.js +1 -0
  206. package/package/database/node_modules/lodash/fp/fill.js +5 -0
  207. package/package/database/node_modules/lodash/fp/filter.js +5 -0
  208. package/package/database/node_modules/lodash/fp/find.js +5 -0
  209. package/package/database/node_modules/lodash/fp/findFrom.js +5 -0
  210. package/package/database/node_modules/lodash/fp/findIndex.js +5 -0
  211. package/package/database/node_modules/lodash/fp/findIndexFrom.js +5 -0
  212. package/package/database/node_modules/lodash/fp/findKey.js +5 -0
  213. package/package/database/node_modules/lodash/fp/findLast.js +5 -0
  214. package/package/database/node_modules/lodash/fp.js +2 -0
  215. package/package/database/node_modules/lodash/fromPairs.js +28 -0
  216. package/package/database/node_modules/lodash/function.js +25 -0
  217. package/package/database/node_modules/lodash/functions.js +31 -0
  218. package/package/database/node_modules/lodash/functionsIn.js +31 -0
  219. package/package/database/node_modules/lodash/get.js +33 -0
  220. package/package/database/node_modules/node-fetch/CHANGELOG.md +266 -0
  221. package/package/database/node_modules/node-fetch/LICENSE.md +22 -0
  222. package/package/database/node_modules/node-fetch/README.md +583 -0
  223. package/package/database/node_modules/node-fetch/browser.js +23 -0
  224. package/package/database/node_modules/node-fetch/lib/index.es.js +1633 -0
  225. package/package/database/node_modules/node-fetch/lib/index.js +1642 -0
  226. package/package/database/node_modules/node-fetch/lib/index.mjs +1631 -0
  227. package/package/database/node_modules/node-fetch/package.json +70 -0
  228. package/package/database/node_modules/sqlite3/CHANGELOG.md +313 -0
  229. package/package/database/node_modules/sqlite3/CONTRIBUTING.md +57 -0
  230. package/package/database/node_modules/sqlite3/LICENSE +25 -0
  231. package/package/database/node_modules/sqlite3/README.md +259 -0
  232. package/package/database/node_modules/sqlite3/binding.gyp +66 -0
  233. package/package/database/node_modules/sqlite3/deps/common-sqlite.gypi +60 -0
  234. package/package/database/node_modules/sqlite3/deps/extract.js +10 -0
  235. package/package/database/node_modules/sqlite3/deps/sqlite-autoconf-3380200.tar.gz +0 -0
  236. package/package/database/node_modules/sqlite3/deps/sqlite3.gyp +121 -0
  237. package/package/database/node_modules/sqlite3/lib/binding/napi-v6-linux-x64/node_sqlite3.node +0 -0
  238. package/package/database/node_modules/sqlite3/lib/index.js +1 -0
  239. package/package/database/node_modules/sqlite3/lib/sqlite3-binding.js +5 -0
  240. package/package/database/node_modules/sqlite3/lib/sqlite3.js +205 -0
  241. package/package/database/node_modules/sqlite3/lib/trace.js +38 -0
  242. package/package/database/node_modules/sqlite3/package.json +82 -0
  243. package/package/database/node_modules/sqlite3/sqlite3.js +1 -0
  244. package/package/database/node_modules/sqlite3/src/async.h +82 -0
  245. package/package/database/node_modules/sqlite3/src/backup.cc +420 -0
  246. package/package/database/node_modules/sqlite3/src/backup.h +221 -0
  247. package/package/database/node_modules/sqlite3/src/database.cc +738 -0
  248. package/package/database/node_modules/sqlite3/src/database.h +206 -0
  249. package/package/database/node_modules/sqlite3/src/gcc-preinclude.h +6 -0
  250. package/package/database/node_modules/sqlite3/src/macros.h +212 -0
  251. package/package/database/node_modules/sqlite3/src/node_sqlite3.cc +115 -0
  252. package/package/database/node_modules/sqlite3/src/statement.cc +947 -0
  253. package/package/database/node_modules/sqlite3/src/statement.h +249 -0
  254. package/package/database/node_modules/sqlite3/src/threading.h +48 -0
  255. package/package/database/package.json +31 -0
  256. package/package/database/readme.md +8 -0
  257. package/package/database/test.js +3 -0
  258. package/package/horizon-sp/README.md +11 -0
  259. package/package/horizon-sp/index.js +41 -0
  260. package/package/horizon-sp/logger.js +16 -0
  261. package/package/horizon-sp/node_modules/.package-lock.json +140 -0
  262. package/package/horizon-sp/node_modules/asynckit/LICENSE +21 -0
  263. package/package/horizon-sp/node_modules/asynckit/README.md +233 -0
  264. package/package/horizon-sp/node_modules/asynckit/bench.js +76 -0
  265. package/package/horizon-sp/node_modules/asynckit/index.js +6 -0
  266. package/package/horizon-sp/node_modules/asynckit/lib/abort.js +29 -0
  267. package/package/horizon-sp/node_modules/asynckit/lib/async.js +34 -0
  268. package/package/horizon-sp/node_modules/asynckit/lib/defer.js +26 -0
  269. package/package/horizon-sp/node_modules/asynckit/lib/iterate.js +75 -0
  270. package/package/horizon-sp/node_modules/asynckit/lib/readable_asynckit.js +91 -0
  271. package/package/horizon-sp/node_modules/asynckit/lib/readable_parallel.js +25 -0
  272. package/package/horizon-sp/node_modules/asynckit/lib/readable_serial.js +25 -0
  273. package/package/horizon-sp/node_modules/asynckit/lib/readable_serial_ordered.js +29 -0
  274. package/package/horizon-sp/node_modules/asynckit/lib/state.js +37 -0
  275. package/package/horizon-sp/node_modules/asynckit/lib/streamify.js +141 -0
  276. package/package/horizon-sp/node_modules/asynckit/lib/terminator.js +29 -0
  277. package/package/horizon-sp/node_modules/asynckit/package.json +63 -0
  278. package/package/horizon-sp/node_modules/asynckit/parallel.js +43 -0
  279. package/package/horizon-sp/node_modules/asynckit/serial.js +17 -0
  280. package/package/horizon-sp/node_modules/asynckit/serialOrdered.js +75 -0
  281. package/package/horizon-sp/node_modules/asynckit/stream.js +21 -0
  282. package/package/horizon-sp/node_modules/axios/CHANGELOG.md +410 -0
  283. package/package/horizon-sp/node_modules/axios/LICENSE +7 -0
  284. package/package/horizon-sp/node_modules/axios/MIGRATION_GUIDE.md +3 -0
  285. package/package/horizon-sp/node_modules/axios/README.md +1310 -0
  286. package/package/horizon-sp/node_modules/axios/SECURITY.md +6 -0
  287. package/package/horizon-sp/node_modules/axios/index.d.cts +524 -0
  288. package/package/horizon-sp/node_modules/axios/index.d.ts +539 -0
  289. package/package/horizon-sp/node_modules/axios/index.js +41 -0
  290. package/package/horizon-sp/node_modules/axios/lib/adapters/README.md +37 -0
  291. package/package/horizon-sp/node_modules/axios/lib/adapters/adapters.js +59 -0
  292. package/package/horizon-sp/node_modules/axios/lib/adapters/http.js +608 -0
  293. package/package/horizon-sp/node_modules/axios/lib/adapters/xhr.js +249 -0
  294. package/package/horizon-sp/node_modules/axios/lib/axios.js +86 -0
  295. package/package/horizon-sp/node_modules/axios/lib/cancel/CancelToken.js +121 -0
  296. package/package/horizon-sp/node_modules/axios/lib/cancel/CanceledError.js +25 -0
  297. package/package/horizon-sp/node_modules/axios/lib/cancel/isCancel.js +5 -0
  298. package/package/horizon-sp/node_modules/axios/lib/core/Axios.js +197 -0
  299. package/package/horizon-sp/node_modules/axios/lib/core/AxiosError.js +100 -0
  300. package/package/horizon-sp/node_modules/axios/lib/core/AxiosHeaders.js +274 -0
  301. package/package/horizon-sp/node_modules/axios/lib/core/InterceptorManager.js +71 -0
  302. package/package/horizon-sp/node_modules/axios/lib/core/README.md +8 -0
  303. package/package/horizon-sp/node_modules/axios/lib/core/buildFullPath.js +21 -0
  304. package/package/horizon-sp/node_modules/axios/lib/core/dispatchRequest.js +81 -0
  305. package/package/horizon-sp/node_modules/axios/lib/core/mergeConfig.js +105 -0
  306. package/package/horizon-sp/node_modules/axios/lib/core/settle.js +27 -0
  307. package/package/horizon-sp/node_modules/axios/lib/core/transformData.js +28 -0
  308. package/package/horizon-sp/node_modules/axios/lib/defaults/index.js +166 -0
  309. package/package/horizon-sp/node_modules/axios/lib/defaults/transitional.js +7 -0
  310. package/package/horizon-sp/node_modules/axios/lib/env/README.md +3 -0
  311. package/package/horizon-sp/node_modules/axios/lib/env/classes/FormData.js +2 -0
  312. package/package/horizon-sp/node_modules/axios/lib/env/data.js +1 -0
  313. package/package/horizon-sp/node_modules/axios/lib/helpers/AxiosTransformStream.js +191 -0
  314. package/package/horizon-sp/node_modules/axios/lib/helpers/AxiosURLSearchParams.js +58 -0
  315. package/package/horizon-sp/node_modules/axios/lib/helpers/HttpStatusCode.js +71 -0
  316. package/package/horizon-sp/node_modules/axios/lib/helpers/README.md +7 -0
  317. package/package/horizon-sp/node_modules/axios/lib/helpers/bind.js +7 -0
  318. package/package/horizon-sp/node_modules/axios/lib/helpers/buildURL.js +63 -0
  319. package/package/horizon-sp/node_modules/axios/lib/helpers/combineURLs.js +15 -0
  320. package/package/horizon-sp/node_modules/axios/lib/helpers/cookies.js +52 -0
  321. package/package/horizon-sp/node_modules/axios/lib/helpers/deprecatedMethod.js +26 -0
  322. package/package/horizon-sp/node_modules/axios/lib/helpers/formDataToJSON.js +92 -0
  323. package/package/horizon-sp/node_modules/axios/lib/helpers/fromDataURI.js +53 -0
  324. package/package/horizon-sp/node_modules/axios/lib/helpers/isAbsoluteURL.js +15 -0
  325. package/package/horizon-sp/node_modules/axios/lib/helpers/isAxiosError.js +14 -0
  326. package/package/horizon-sp/node_modules/axios/lib/helpers/isURLSameOrigin.js +67 -0
  327. package/package/horizon-sp/node_modules/axios/lib/helpers/null.js +2 -0
  328. package/package/horizon-sp/node_modules/axios/lib/helpers/parseHeaders.js +55 -0
  329. package/package/horizon-sp/node_modules/axios/lib/helpers/parseProtocol.js +6 -0
  330. package/package/horizon-sp/node_modules/axios/lib/helpers/speedometer.js +55 -0
  331. package/package/horizon-sp/node_modules/axios/lib/helpers/spread.js +28 -0
  332. package/package/horizon-sp/node_modules/axios/lib/helpers/throttle.js +33 -0
  333. package/package/horizon-sp/node_modules/axios/lib/helpers/toFormData.js +229 -0
  334. package/package/horizon-sp/node_modules/axios/lib/helpers/toURLEncodedForm.js +18 -0
  335. package/package/horizon-sp/node_modules/axios/lib/helpers/validator.js +91 -0
  336. package/package/horizon-sp/node_modules/axios/lib/platform/browser/classes/FormData.js +3 -0
  337. package/package/horizon-sp/node_modules/axios/lib/platform/browser/classes/URLSearchParams.js +4 -0
  338. package/package/horizon-sp/node_modules/axios/lib/platform/browser/index.js +63 -0
  339. package/package/horizon-sp/node_modules/axios/lib/platform/index.js +3 -0
  340. package/package/horizon-sp/node_modules/axios/lib/platform/node/classes/FormData.js +3 -0
  341. package/package/horizon-sp/node_modules/axios/lib/platform/node/classes/URLSearchParams.js +4 -0
  342. package/package/horizon-sp/node_modules/axios/lib/platform/node/index.js +12 -0
  343. package/package/horizon-sp/node_modules/axios/lib/utils.js +677 -0
  344. package/package/horizon-sp/node_modules/axios/package.json +197 -0
  345. package/package/horizon-sp/node_modules/child_process/README.md +9 -0
  346. package/package/horizon-sp/node_modules/child_process/package.json +20 -0
  347. package/package/horizon-sp/node_modules/combined-stream/License +19 -0
  348. package/package/horizon-sp/node_modules/combined-stream/Readme.md +138 -0
  349. package/package/horizon-sp/node_modules/combined-stream/lib/combined_stream.js +208 -0
  350. package/package/horizon-sp/node_modules/combined-stream/package.json +25 -0
  351. package/package/horizon-sp/node_modules/delayed-stream/License +19 -0
  352. package/package/horizon-sp/node_modules/delayed-stream/Makefile +7 -0
  353. package/package/horizon-sp/node_modules/delayed-stream/Readme.md +141 -0
  354. package/package/horizon-sp/node_modules/delayed-stream/lib/delayed_stream.js +107 -0
  355. package/package/horizon-sp/node_modules/delayed-stream/package.json +27 -0
  356. package/package/horizon-sp/node_modules/follow-redirects/LICENSE +18 -0
  357. package/package/horizon-sp/node_modules/follow-redirects/README.md +155 -0
  358. package/package/horizon-sp/node_modules/follow-redirects/debug.js +15 -0
  359. package/package/horizon-sp/node_modules/follow-redirects/http.js +1 -0
  360. package/package/horizon-sp/node_modules/follow-redirects/https.js +1 -0
  361. package/package/horizon-sp/node_modules/follow-redirects/index.js +621 -0
  362. package/package/horizon-sp/node_modules/follow-redirects/package.json +59 -0
  363. package/package/horizon-sp/node_modules/form-data/License +19 -0
  364. package/package/horizon-sp/node_modules/form-data/README.md.bak +358 -0
  365. package/package/horizon-sp/node_modules/form-data/Readme.md +358 -0
  366. package/package/horizon-sp/node_modules/form-data/index.d.ts +62 -0
  367. package/package/horizon-sp/node_modules/form-data/lib/browser.js +2 -0
  368. package/package/horizon-sp/node_modules/form-data/lib/form_data.js +501 -0
  369. package/package/horizon-sp/node_modules/form-data/lib/populate.js +10 -0
  370. package/package/horizon-sp/node_modules/form-data/package.json +68 -0
  371. package/package/horizon-sp/node_modules/fs-extra/LICENSE +15 -0
  372. package/package/horizon-sp/node_modules/fs-extra/README.md +290 -0
  373. package/package/horizon-sp/node_modules/fs-extra/lib/copy/copy-sync.js +161 -0
  374. package/package/horizon-sp/node_modules/fs-extra/lib/copy/copy.js +238 -0
  375. package/package/horizon-sp/node_modules/fs-extra/lib/copy/index.js +7 -0
  376. package/package/horizon-sp/node_modules/fs-extra/lib/empty/index.js +39 -0
  377. package/package/horizon-sp/node_modules/fs-extra/lib/ensure/file.js +69 -0
  378. package/package/horizon-sp/node_modules/fs-extra/lib/ensure/index.js +23 -0
  379. package/package/horizon-sp/node_modules/fs-extra/lib/ensure/link.js +64 -0
  380. package/package/horizon-sp/node_modules/fs-extra/lib/ensure/symlink-paths.js +99 -0
  381. package/package/horizon-sp/node_modules/fs-extra/lib/ensure/symlink-type.js +31 -0
  382. package/package/horizon-sp/node_modules/fs-extra/lib/ensure/symlink.js +82 -0
  383. package/package/horizon-sp/node_modules/fs-extra/lib/esm.mjs +68 -0
  384. package/package/horizon-sp/node_modules/fs-extra/lib/fs/index.js +140 -0
  385. package/package/horizon-sp/node_modules/fs-extra/lib/index.js +16 -0
  386. package/package/horizon-sp/node_modules/fs-extra/lib/json/index.js +16 -0
  387. package/package/horizon-sp/node_modules/fs-extra/lib/json/jsonfile.js +11 -0
  388. package/package/horizon-sp/node_modules/fs-extra/lib/json/output-json-sync.js +12 -0
  389. package/package/horizon-sp/node_modules/fs-extra/lib/json/output-json.js +12 -0
  390. package/package/horizon-sp/node_modules/fs-extra/lib/mkdirs/index.js +14 -0
  391. package/package/horizon-sp/node_modules/fs-extra/lib/mkdirs/make-dir.js +27 -0
  392. package/package/horizon-sp/node_modules/fs-extra/lib/mkdirs/utils.js +21 -0
  393. package/package/horizon-sp/node_modules/fs-extra/lib/move/index.js +7 -0
  394. package/package/horizon-sp/node_modules/fs-extra/lib/move/move-sync.js +54 -0
  395. package/package/horizon-sp/node_modules/fs-extra/lib/move/move.js +75 -0
  396. package/package/horizon-sp/node_modules/fs-extra/lib/output-file/index.js +40 -0
  397. package/package/horizon-sp/node_modules/fs-extra/lib/path-exists/index.js +12 -0
  398. package/package/horizon-sp/node_modules/fs-extra/lib/remove/index.js +17 -0
  399. package/package/horizon-sp/node_modules/fs-extra/lib/util/stat.js +154 -0
  400. package/package/horizon-sp/node_modules/fs-extra/lib/util/utimes.js +26 -0
  401. package/package/horizon-sp/node_modules/fs-extra/package.json +71 -0
  402. package/package/horizon-sp/node_modules/graceful-fs/LICENSE +15 -0
  403. package/package/horizon-sp/node_modules/graceful-fs/README.md +143 -0
  404. package/package/horizon-sp/node_modules/graceful-fs/clone.js +23 -0
  405. package/package/horizon-sp/node_modules/graceful-fs/graceful-fs.js +448 -0
  406. package/package/horizon-sp/node_modules/graceful-fs/legacy-streams.js +118 -0
  407. package/package/horizon-sp/node_modules/graceful-fs/package.json +50 -0
  408. package/package/horizon-sp/node_modules/graceful-fs/polyfills.js +355 -0
  409. package/package/horizon-sp/node_modules/jsonfile/CHANGELOG.md +171 -0
  410. package/package/horizon-sp/node_modules/jsonfile/LICENSE +15 -0
  411. package/package/horizon-sp/node_modules/jsonfile/README.md +230 -0
  412. package/package/horizon-sp/node_modules/jsonfile/index.js +88 -0
  413. package/package/horizon-sp/node_modules/jsonfile/package.json +40 -0
  414. package/package/horizon-sp/node_modules/jsonfile/utils.js +14 -0
  415. package/package/horizon-sp/node_modules/mime-db/HISTORY.md +507 -0
  416. package/package/horizon-sp/node_modules/mime-db/LICENSE +23 -0
  417. package/package/horizon-sp/node_modules/mime-db/README.md +100 -0
  418. package/package/horizon-sp/node_modules/mime-db/db.json +8519 -0
  419. package/package/horizon-sp/node_modules/mime-db/index.js +12 -0
  420. package/package/horizon-sp/node_modules/mime-db/package.json +60 -0
  421. package/package/horizon-sp/node_modules/mime-types/HISTORY.md +397 -0
  422. package/package/horizon-sp/node_modules/mime-types/LICENSE +23 -0
  423. package/package/horizon-sp/node_modules/mime-types/README.md +113 -0
  424. package/package/horizon-sp/node_modules/mime-types/index.js +188 -0
  425. package/package/horizon-sp/node_modules/mime-types/package.json +44 -0
  426. package/package/horizon-sp/node_modules/proxy-from-env/LICENSE +20 -0
  427. package/package/horizon-sp/node_modules/proxy-from-env/README.md +131 -0
  428. package/package/horizon-sp/node_modules/proxy-from-env/index.js +108 -0
  429. package/package/horizon-sp/node_modules/proxy-from-env/package.json +34 -0
  430. package/package/horizon-sp/node_modules/proxy-from-env/test.js +483 -0
  431. package/package/horizon-sp/node_modules/universalify/LICENSE +20 -0
  432. package/package/horizon-sp/node_modules/universalify/README.md +76 -0
  433. package/package/horizon-sp/node_modules/universalify/index.js +24 -0
  434. package/package/horizon-sp/node_modules/universalify/package.json +34 -0
  435. package/package/horizon-sp/package-lock.json +150 -0
  436. package/package/horizon-sp/package.json +20 -0
  437. package/package.json +134 -3
  438. package/src/ReportV1.js +55 -0
  439. package/src/addExternalModule.js +16 -0
  440. package/src/addUserToGroup.js +78 -0
  441. package/src/changeAdminStatus.js +79 -0
  442. package/src/changeArchivedStatus.js +41 -0
  443. package/src/changeAvt.js +86 -0
  444. package/src/changeBio.js +65 -0
  445. package/src/changeBlockedStatus.js +36 -0
  446. package/src/changeGroupImage.js +106 -0
  447. package/src/changeNickname.js +45 -0
  448. package/src/changeThreadColor.js +62 -0
  449. package/src/changeThreadEmoji.js +42 -0
  450. package/src/createNewGroup.js +70 -0
  451. package/src/createPoll.js +60 -0
  452. package/src/data/getThreadInfo.json +31985 -0
  453. package/src/deleteMessage.js +45 -0
  454. package/src/deleteThread.js +43 -0
  455. package/src/forwardAttachment.js +48 -0
  456. package/src/getAccessToken.js +33 -0
  457. package/src/getCurrentUserID.js +7 -0
  458. package/src/getEmojiUrl.js +27 -0
  459. package/src/getFriendsList.js +73 -0
  460. package/src/getMessage.js +80 -0
  461. package/src/getThreadHistory.js +537 -0
  462. package/src/getThreadHistoryDeprecated.js +71 -0
  463. package/src/getThreadInfo.js +193 -0
  464. package/src/getThreadInfoDeprecated.js +56 -0
  465. package/src/getThreadList.js +213 -0
  466. package/src/getThreadListDeprecated.js +46 -0
  467. package/src/getThreadMain.js +219 -0
  468. package/src/getThreadPictures.js +59 -0
  469. package/src/getUserID.js +62 -0
  470. package/src/getUserInfo.js +66 -0
  471. package/src/getUserInfoMain.js +65 -0
  472. package/src/getUserInfoV2.js +36 -0
  473. package/src/getUserInfoV3.js +63 -0
  474. package/src/getUserInfoV4.js +55 -0
  475. package/src/getUserInfoV5.js +61 -0
  476. package/src/handleFriendRequest.js +46 -0
  477. package/src/handleMessageRequest.js +49 -0
  478. package/src/httpGet.js +49 -0
  479. package/src/httpPost.js +48 -0
  480. package/src/httpPostFormData.js +41 -0
  481. package/src/listenMqtt.js +629 -0
  482. package/src/logout.js +68 -0
  483. package/src/markAsDelivered.js +48 -0
  484. package/src/markAsRead.js +70 -0
  485. package/src/markAsReadAll.js +43 -0
  486. package/src/markAsSeen.js +51 -0
  487. package/src/muteThread.js +47 -0
  488. package/src/removeUserFromGroup.js +49 -0
  489. package/src/resolvePhotoUrl.js +37 -0
  490. package/src/searchForThread.js +43 -0
  491. package/src/sendMessage.js +321 -0
  492. package/src/sendTypingIndicator.js +80 -0
  493. package/src/setMessageReaction.js +109 -0
  494. package/src/setPostReaction.js +102 -0
  495. package/src/setTitle.js +74 -0
  496. package/src/threadColors.js +39 -0
  497. package/src/unfriend.js +43 -0
  498. package/src/unsendMessage.js +40 -0
  499. package/test/example-config.json +18 -0
  500. package/test/test-page.js +140 -0
  501. package/test/test.js +385 -0
  502. package/utils.js +1246 -0
package/utils.js ADDED
@@ -0,0 +1,1246 @@
1
+ /* eslint-disable no-prototype-builtins */
2
+ "use strict";
3
+
4
+ const bluebird = require("bluebird");
5
+ var request = bluebird.promisify(require("request").defaults({ jar: true }));
6
+ var stream = require("stream");
7
+ var log = require("npmlog");
8
+ var querystring = require("querystring");
9
+ var url = require("url");
10
+
11
+ function setProxy(url) {
12
+ if (typeof url == undefined) return request = bluebird.promisify(require("request").defaults({ jar: true }));
13
+ return request = bluebird.promisify(require("request").defaults({ jar: true, proxy: url }));
14
+ }
15
+
16
+ function getHeaders(url, options, ctx, customHeader) {
17
+ var headers = {
18
+ "Content-Type": "application/x-www-form-urlencoded",
19
+ Referer: "https://www.facebook.com/",
20
+ Host: url.replace("https://", "").split("/")[0],
21
+ Origin: "https://www.facebook.com",
22
+ "User-Agent": options.userAgent,
23
+ Connection: "keep-alive",
24
+ 'sec-fetch-site': 'same-origin'
25
+ };
26
+ if (customHeader) Object.assign(headers, customHeader);
27
+
28
+ if (ctx && ctx.region) headers["X-MSGR-Region"] = ctx.region;
29
+
30
+ return headers;
31
+ }
32
+
33
+ function isReadableStream(obj) {
34
+ return (
35
+ obj instanceof stream.Stream &&
36
+ (getType(obj._read) === "Function" ||
37
+ getType(obj._read) === "AsyncFunction") &&
38
+ getType(obj._readableState) === "Object"
39
+ );
40
+ }
41
+
42
+ function get(url, jar, qs, options, ctx) {
43
+ // I'm still confused about this
44
+ if (getType(qs) === "Object")
45
+ for (var prop in qs)
46
+ if (qs.hasOwnProperty(prop) && getType(qs[prop]) === "Object") qs[prop] = JSON.stringify(qs[prop]);
47
+ var op = {
48
+ headers: getHeaders(url, options, ctx),
49
+ timeout: 60000,
50
+ qs: qs,
51
+ url: url,
52
+ method: "GET",
53
+ jar: jar,
54
+ gzip: true
55
+ };
56
+
57
+ return request(op).then(function(res) {
58
+ return res[0];
59
+ });
60
+ }
61
+
62
+ function post(url, jar, form, options, ctx, customHeader) {
63
+ let headers = getHeaders(url, options);
64
+ headers['sec-fetch-site'] = 'same-origin';
65
+ var op = {
66
+ headers: headers,
67
+ timeout: 60000,
68
+ url: url,
69
+ method: "POST",
70
+ form: form,
71
+ jar: jar,
72
+ gzip: true
73
+ };
74
+
75
+ return request(op).then(function(res) {
76
+ return res[0];
77
+ });
78
+ }
79
+
80
+ function postFormData(url, jar, form, qs, options, ctx) {
81
+ var headers = getHeaders(url, options, ctx);
82
+ headers["Content-Type"] = "multipart/form-data";
83
+ var op = {
84
+ headers: headers,
85
+ timeout: 60000,
86
+ url: url,
87
+ method: "POST",
88
+ formData: form,
89
+ qs: qs,
90
+ jar: jar,
91
+ gzip: true
92
+ };
93
+
94
+ return request(op).then(function(res) {
95
+ return res[0];
96
+ });
97
+ }
98
+
99
+ function padZeros(val, len) {
100
+ val = String(val);
101
+ len = len || 2;
102
+ while (val.length < len) val = "0" + val;
103
+ return val;
104
+ }
105
+
106
+ function generateThreadingID(clientID) {
107
+ var k = Date.now();
108
+ var l = Math.floor(Math.random() * 4294967295);
109
+ var m = clientID;
110
+ return "<" + k + ":" + l + "-" + m + "@mail.projektitan.com>";
111
+ }
112
+
113
+ function binaryToDecimal(data) {
114
+ var ret = "";
115
+ while (data !== "0") {
116
+ var end = 0;
117
+ var fullName = "";
118
+ var i = 0;
119
+ for (; i < data.length; i++) {
120
+ end = 2 * end + parseInt(data[i], 10);
121
+ if (end >= 10) {
122
+ fullName += "1";
123
+ end -= 10;
124
+ } else fullName += "0";
125
+ }
126
+ ret = end.toString() + ret;
127
+ data = fullName.slice(fullName.indexOf("1"));
128
+ }
129
+ return ret;
130
+ }
131
+
132
+ function generateOfflineThreadingID() {
133
+ var ret = Date.now();
134
+ var value = Math.floor(Math.random() * 4294967295);
135
+ var str = ("0000000000000000000000" + value.toString(2)).slice(-22);
136
+ var msgs = ret.toString(2) + str;
137
+ return binaryToDecimal(msgs);
138
+ }
139
+
140
+ var h;
141
+ var i = {};
142
+ var j = {
143
+ _: "%",
144
+ A: "%2",
145
+ B: "000",
146
+ C: "%7d",
147
+ D: "%7b%22",
148
+ E: "%2c%22",
149
+ F: "%22%3a",
150
+ G: "%2c%22ut%22%3a1",
151
+ H: "%2c%22bls%22%3a",
152
+ I: "%2c%22n%22%3a%22%",
153
+ J: "%22%3a%7b%22i%22%3a0%7d",
154
+ K: "%2c%22pt%22%3a0%2c%22vis%22%3a",
155
+ L: "%2c%22ch%22%3a%7b%22h%22%3a%22",
156
+ M: "%7b%22v%22%3a2%2c%22time%22%3a1",
157
+ N: ".channel%22%2c%22sub%22%3a%5b",
158
+ O: "%2c%22sb%22%3a1%2c%22t%22%3a%5b",
159
+ P: "%2c%22ud%22%3a100%2c%22lc%22%3a0",
160
+ Q: "%5d%2c%22f%22%3anull%2c%22uct%22%3a",
161
+ R: ".channel%22%2c%22sub%22%3a%5b1%5d",
162
+ S: "%22%2c%22m%22%3a0%7d%2c%7b%22i%22%3a",
163
+ T: "%2c%22blc%22%3a1%2c%22snd%22%3a1%2c%22ct%22%3a",
164
+ U: "%2c%22blc%22%3a0%2c%22snd%22%3a1%2c%22ct%22%3a",
165
+ V: "%2c%22blc%22%3a0%2c%22snd%22%3a0%2c%22ct%22%3a",
166
+ W: "%2c%22s%22%3a0%2c%22blo%22%3a0%7d%2c%22bl%22%3a%7b%22ac%22%3a",
167
+ X: "%2c%22ri%22%3a0%7d%2c%22state%22%3a%7b%22p%22%3a0%2c%22ut%22%3a1",
168
+ Y: "%2c%22pt%22%3a0%2c%22vis%22%3a1%2c%22bls%22%3a0%2c%22blc%22%3a0%2c%22snd%22%3a1%2c%22ct%22%3a",
169
+ Z: "%2c%22sb%22%3a1%2c%22t%22%3a%5b%5d%2c%22f%22%3anull%2c%22uct%22%3a0%2c%22s%22%3a0%2c%22blo%22%3a0%7d%2c%22bl%22%3a%7b%22ac%22%3a"
170
+ };
171
+ (function() {
172
+ var l = [];
173
+ for (var m in j) {
174
+ i[j[m]] = m;
175
+ l.push(j[m]);
176
+ }
177
+ l.reverse();
178
+ h = new RegExp(l.join("|"), "g");
179
+ })();
180
+
181
+ function presenceEncode(str) {
182
+ return encodeURIComponent(str)
183
+ .replace(/([_A-Z])|%../g, function(m, n) {
184
+ return n ? "%" + n.charCodeAt(0).toString(16) : m;
185
+ })
186
+ .toLowerCase()
187
+ .replace(h, function(m) {
188
+ return i[m];
189
+ });
190
+ }
191
+
192
+ // eslint-disable-next-line no-unused-vars
193
+ function presenceDecode(str) {
194
+ return decodeURIComponent(
195
+ str.replace(/[_A-Z]/g, function(m) {
196
+ return j[m];
197
+ })
198
+ );
199
+ }
200
+
201
+ function generatePresence(userID) {
202
+ var time = Date.now();
203
+ return (
204
+ "E" +
205
+ presenceEncode(
206
+ JSON.stringify({
207
+ v: 3,
208
+ time: parseInt(time / 1000, 10),
209
+ user: userID,
210
+ state: {
211
+ ut: 0,
212
+ t2: [],
213
+ lm2: null,
214
+ uct2: time,
215
+ tr: null,
216
+ tw: Math.floor(Math.random() * 4294967295) + 1,
217
+ at: time
218
+ },
219
+ ch: {
220
+ ["p_" + userID]: 0
221
+ }
222
+ })
223
+ )
224
+ );
225
+ }
226
+
227
+ function generateAccessiblityCookie() {
228
+ var time = Date.now();
229
+ return encodeURIComponent(
230
+ JSON.stringify({
231
+ sr: 0,
232
+ "sr-ts": time,
233
+ jk: 0,
234
+ "jk-ts": time,
235
+ kb: 0,
236
+ "kb-ts": time,
237
+ hcm: 0,
238
+ "hcm-ts": time
239
+ })
240
+ );
241
+ }
242
+
243
+ function getGUID() {
244
+ /** @type {number} */
245
+ var sectionLength = Date.now();
246
+ /** @type {string} */
247
+ var id = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
248
+ /** @type {number} */
249
+ var r = Math.floor((sectionLength + Math.random() * 16) % 16);
250
+ /** @type {number} */
251
+ sectionLength = Math.floor(sectionLength / 16);
252
+ /** @type {string} */
253
+ var _guid = (c == "x" ? r : (r & 7) | 8).toString(16);
254
+ return _guid;
255
+ });
256
+ return id;
257
+ }
258
+
259
+ function _formatAttachment(attachment1, attachment2) {
260
+ // TODO: THIS IS REALLY BAD
261
+ // This is an attempt at fixing Facebook's inconsistencies. Sometimes they give us
262
+ // two attachment objects, but sometimes only one. They each contain part of the
263
+ // data that you'd want so we merge them for convenience.
264
+ // Instead of having a bunch of if statements guarding every access to image_data,
265
+ // we set it to empty object and use the fact that it'll return undefined.
266
+ attachment2 = attachment2 || { id: "", image_data: {} };
267
+ attachment1 = attachment1.mercury ? attachment1.mercury : attachment1;
268
+ var blob = attachment1.blob_attachment;
269
+ var type =
270
+ blob && blob.__typename ? blob.__typename : attachment1.attach_type;
271
+ if (!type && attachment1.sticker_attachment) {
272
+ type = "StickerAttachment";
273
+ blob = attachment1.sticker_attachment;
274
+ } else if (!type && attachment1.extensible_attachment) {
275
+ if (
276
+ attachment1.extensible_attachment.story_attachment &&
277
+ attachment1.extensible_attachment.story_attachment.target &&
278
+ attachment1.extensible_attachment.story_attachment.target.__typename &&
279
+ attachment1.extensible_attachment.story_attachment.target.__typename === "MessageLocation"
280
+ ) type = "MessageLocation";
281
+ else type = "ExtensibleAttachment";
282
+
283
+ blob = attachment1.extensible_attachment;
284
+ }
285
+ // TODO: Determine whether "sticker", "photo", "file" etc are still used
286
+ // KEEP IN SYNC WITH getThreadHistory
287
+ switch (type) {
288
+ case "sticker":
289
+ return {
290
+ type: "sticker",
291
+ ID: attachment1.metadata.stickerID.toString(),
292
+ url: attachment1.url,
293
+
294
+ packID: attachment1.metadata.packID.toString(),
295
+ spriteUrl: attachment1.metadata.spriteURI,
296
+ spriteUrl2x: attachment1.metadata.spriteURI2x,
297
+ width: attachment1.metadata.width,
298
+ height: attachment1.metadata.height,
299
+
300
+ caption: attachment2.caption,
301
+ description: attachment2.description,
302
+
303
+ frameCount: attachment1.metadata.frameCount,
304
+ frameRate: attachment1.metadata.frameRate,
305
+ framesPerRow: attachment1.metadata.framesPerRow,
306
+ framesPerCol: attachment1.metadata.framesPerCol,
307
+
308
+ stickerID: attachment1.metadata.stickerID.toString(), // @Legacy
309
+ spriteURI: attachment1.metadata.spriteURI, // @Legacy
310
+ spriteURI2x: attachment1.metadata.spriteURI2x // @Legacy
311
+ };
312
+ case "file":
313
+ return {
314
+ type: "file",
315
+ filename: attachment1.name,
316
+ ID: attachment2.id.toString(),
317
+ url: attachment1.url,
318
+
319
+ isMalicious: attachment2.is_malicious,
320
+ contentType: attachment2.mime_type,
321
+
322
+ name: attachment1.name, // @Legacy
323
+ mimeType: attachment2.mime_type, // @Legacy
324
+ fileSize: attachment2.file_size // @Legacy
325
+ };
326
+ case "photo":
327
+ return {
328
+ type: "photo",
329
+ ID: attachment1.metadata.fbid.toString(),
330
+ filename: attachment1.fileName,
331
+ thumbnailUrl: attachment1.thumbnail_url,
332
+
333
+ previewUrl: attachment1.preview_url,
334
+ previewWidth: attachment1.preview_width,
335
+ previewHeight: attachment1.preview_height,
336
+
337
+ largePreviewUrl: attachment1.large_preview_url,
338
+ largePreviewWidth: attachment1.large_preview_width,
339
+ largePreviewHeight: attachment1.large_preview_height,
340
+
341
+ url: attachment1.metadata.url, // @Legacy
342
+ width: attachment1.metadata.dimensions.split(",")[0], // @Legacy
343
+ height: attachment1.metadata.dimensions.split(",")[1], // @Legacy
344
+ name: attachment1.fileName // @Legacy
345
+ };
346
+ case "animated_image":
347
+ return {
348
+ type: "animated_image",
349
+ ID: attachment2.id.toString(),
350
+ filename: attachment2.filename,
351
+
352
+ previewUrl: attachment1.preview_url,
353
+ previewWidth: attachment1.preview_width,
354
+ previewHeight: attachment1.preview_height,
355
+
356
+ url: attachment2.image_data.url,
357
+ width: attachment2.image_data.width,
358
+ height: attachment2.image_data.height,
359
+
360
+ name: attachment1.name, // @Legacy
361
+ facebookUrl: attachment1.url, // @Legacy
362
+ thumbnailUrl: attachment1.thumbnail_url, // @Legacy
363
+ mimeType: attachment2.mime_type, // @Legacy
364
+ rawGifImage: attachment2.image_data.raw_gif_image, // @Legacy
365
+ rawWebpImage: attachment2.image_data.raw_webp_image, // @Legacy
366
+ animatedGifUrl: attachment2.image_data.animated_gif_url, // @Legacy
367
+ animatedGifPreviewUrl: attachment2.image_data.animated_gif_preview_url, // @Legacy
368
+ animatedWebpUrl: attachment2.image_data.animated_webp_url, // @Legacy
369
+ animatedWebpPreviewUrl: attachment2.image_data.animated_webp_preview_url // @Legacy
370
+ };
371
+ case "share":
372
+ return {
373
+ type: "share",
374
+ ID: attachment1.share.share_id.toString(),
375
+ url: attachment2.href,
376
+
377
+ title: attachment1.share.title,
378
+ description: attachment1.share.description,
379
+ source: attachment1.share.source,
380
+
381
+ image: attachment1.share.media.image,
382
+ width: attachment1.share.media.image_size.width,
383
+ height: attachment1.share.media.image_size.height,
384
+ playable: attachment1.share.media.playable,
385
+ duration: attachment1.share.media.duration,
386
+
387
+ subattachments: attachment1.share.subattachments,
388
+ properties: {},
389
+
390
+ animatedImageSize: attachment1.share.media.animated_image_size, // @Legacy
391
+ facebookUrl: attachment1.share.uri, // @Legacy
392
+ target: attachment1.share.target, // @Legacy
393
+ styleList: attachment1.share.style_list // @Legacy
394
+ };
395
+ case "video":
396
+ return {
397
+ type: "video",
398
+ ID: attachment1.metadata.fbid.toString(),
399
+ filename: attachment1.name,
400
+
401
+ previewUrl: attachment1.preview_url,
402
+ previewWidth: attachment1.preview_width,
403
+ previewHeight: attachment1.preview_height,
404
+
405
+ url: attachment1.url,
406
+ width: attachment1.metadata.dimensions.width,
407
+ height: attachment1.metadata.dimensions.height,
408
+
409
+ duration: attachment1.metadata.duration,
410
+ videoType: "unknown",
411
+
412
+ thumbnailUrl: attachment1.thumbnail_url // @Legacy
413
+ };
414
+ case "error":
415
+ return {
416
+ type: "error",
417
+
418
+ // Save error attachments because we're unsure of their format,
419
+ // and whether there are cases they contain something useful for debugging.
420
+ attachment1: attachment1,
421
+ attachment2: attachment2
422
+ };
423
+ case "MessageImage":
424
+ return {
425
+ type: "photo",
426
+ ID: blob.legacy_attachment_id,
427
+ filename: blob.filename,
428
+ thumbnailUrl: blob.thumbnail.uri,
429
+
430
+ previewUrl: blob.preview.uri,
431
+ previewWidth: blob.preview.width,
432
+ previewHeight: blob.preview.height,
433
+
434
+ largePreviewUrl: blob.large_preview.uri,
435
+ largePreviewWidth: blob.large_preview.width,
436
+ largePreviewHeight: blob.large_preview.height,
437
+
438
+ url: blob.large_preview.uri, // @Legacy
439
+ width: blob.original_dimensions.x, // @Legacy
440
+ height: blob.original_dimensions.y, // @Legacy
441
+ name: blob.filename // @Legacy
442
+ };
443
+ case "MessageAnimatedImage":
444
+ return {
445
+ type: "animated_image",
446
+ ID: blob.legacy_attachment_id,
447
+ filename: blob.filename,
448
+
449
+ previewUrl: blob.preview_image.uri,
450
+ previewWidth: blob.preview_image.width,
451
+ previewHeight: blob.preview_image.height,
452
+
453
+ url: blob.animated_image.uri,
454
+ width: blob.animated_image.width,
455
+ height: blob.animated_image.height,
456
+
457
+ thumbnailUrl: blob.preview_image.uri, // @Legacy
458
+ name: blob.filename, // @Legacy
459
+ facebookUrl: blob.animated_image.uri, // @Legacy
460
+ rawGifImage: blob.animated_image.uri, // @Legacy
461
+ animatedGifUrl: blob.animated_image.uri, // @Legacy
462
+ animatedGifPreviewUrl: blob.preview_image.uri, // @Legacy
463
+ animatedWebpUrl: blob.animated_image.uri, // @Legacy
464
+ animatedWebpPreviewUrl: blob.preview_image.uri // @Legacy
465
+ };
466
+ case "MessageVideo":
467
+ return {
468
+ type: "video",
469
+ filename: blob.filename,
470
+ ID: blob.legacy_attachment_id,
471
+
472
+ previewUrl: blob.large_image.uri,
473
+ previewWidth: blob.large_image.width,
474
+ previewHeight: blob.large_image.height,
475
+
476
+ url: blob.playable_url,
477
+ width: blob.original_dimensions.x,
478
+ height: blob.original_dimensions.y,
479
+
480
+ duration: blob.playable_duration_in_ms,
481
+ videoType: blob.video_type.toLowerCase(),
482
+
483
+ thumbnailUrl: blob.large_image.uri // @Legacy
484
+ };
485
+ case "MessageAudio":
486
+ return {
487
+ type: "audio",
488
+ filename: blob.filename,
489
+ ID: blob.url_shimhash,
490
+
491
+ audioType: blob.audio_type,
492
+ duration: blob.playable_duration_in_ms,
493
+ url: blob.playable_url,
494
+
495
+ isVoiceMail: blob.is_voicemail
496
+ };
497
+ case "StickerAttachment":
498
+ return {
499
+ type: "sticker",
500
+ ID: blob.id,
501
+ url: blob.url,
502
+
503
+ packID: blob.pack ? blob.pack.id : null,
504
+ spriteUrl: blob.sprite_image,
505
+ spriteUrl2x: blob.sprite_image_2x,
506
+ width: blob.width,
507
+ height: blob.height,
508
+
509
+ caption: blob.label,
510
+ description: blob.label,
511
+
512
+ frameCount: blob.frame_count,
513
+ frameRate: blob.frame_rate,
514
+ framesPerRow: blob.frames_per_row,
515
+ framesPerCol: blob.frames_per_column,
516
+
517
+ stickerID: blob.id, // @Legacy
518
+ spriteURI: blob.sprite_image, // @Legacy
519
+ spriteURI2x: blob.sprite_image_2x // @Legacy
520
+ };
521
+ case "MessageLocation":
522
+ var urlAttach = blob.story_attachment.url;
523
+ var mediaAttach = blob.story_attachment.media;
524
+
525
+ var u = querystring.parse(url.parse(urlAttach).query).u;
526
+ var where1 = querystring.parse(url.parse(u).query).where1;
527
+ var address = where1.split(", ");
528
+
529
+ var latitude;
530
+ var longitude;
531
+
532
+ try {
533
+ latitude = Number.parseFloat(address[0]);
534
+ longitude = Number.parseFloat(address[1]);
535
+ } catch (err) {
536
+ /* empty */
537
+ }
538
+
539
+ var imageUrl;
540
+ var width;
541
+ var height;
542
+
543
+ if (mediaAttach && mediaAttach.image) {
544
+ imageUrl = mediaAttach.image.uri;
545
+ width = mediaAttach.image.width;
546
+ height = mediaAttach.image.height;
547
+ }
548
+
549
+ return {
550
+ type: "location",
551
+ ID: blob.legacy_attachment_id,
552
+ latitude: latitude,
553
+ longitude: longitude,
554
+ image: imageUrl,
555
+ width: width,
556
+ height: height,
557
+ url: u || urlAttach,
558
+ address: where1,
559
+
560
+ facebookUrl: blob.story_attachment.url, // @Legacy
561
+ target: blob.story_attachment.target, // @Legacy
562
+ styleList: blob.story_attachment.style_list // @Legacy
563
+ };
564
+ case "ExtensibleAttachment":
565
+ return {
566
+ type: "share",
567
+ ID: blob.legacy_attachment_id,
568
+ url: blob.story_attachment.url,
569
+
570
+ title: blob.story_attachment.title_with_entities.text,
571
+ description: blob.story_attachment.description &&
572
+ blob.story_attachment.description.text,
573
+ source: blob.story_attachment.source ? blob.story_attachment.source.text : null,
574
+
575
+ image: blob.story_attachment.media &&
576
+ blob.story_attachment.media.image &&
577
+ blob.story_attachment.media.image.uri,
578
+ width: blob.story_attachment.media &&
579
+ blob.story_attachment.media.image &&
580
+ blob.story_attachment.media.image.width,
581
+ height: blob.story_attachment.media &&
582
+ blob.story_attachment.media.image &&
583
+ blob.story_attachment.media.image.height,
584
+ playable: blob.story_attachment.media &&
585
+ blob.story_attachment.media.is_playable,
586
+ duration: blob.story_attachment.media &&
587
+ blob.story_attachment.media.playable_duration_in_ms,
588
+ playableUrl: blob.story_attachment.media == null ? null : blob.story_attachment.media.playable_url,
589
+
590
+ subattachments: blob.story_attachment.subattachments,
591
+ properties: blob.story_attachment.properties.reduce(function(obj, cur) {
592
+ obj[cur.key] = cur.value.text;
593
+ return obj;
594
+ }, {}),
595
+
596
+ facebookUrl: blob.story_attachment.url, // @Legacy
597
+ target: blob.story_attachment.target, // @Legacy
598
+ styleList: blob.story_attachment.style_list // @Legacy
599
+ };
600
+ case "MessageFile":
601
+ return {
602
+ type: "file",
603
+ filename: blob.filename,
604
+ ID: blob.message_file_fbid,
605
+
606
+ url: blob.url,
607
+ isMalicious: blob.is_malicious,
608
+ contentType: blob.content_type,
609
+
610
+ name: blob.filename,
611
+ mimeType: "",
612
+ fileSize: -1
613
+ };
614
+ default:
615
+ throw new Error(
616
+ "unrecognized attach_file of type " +
617
+ type +
618
+ "`" +
619
+ JSON.stringify(attachment1, null, 4) +
620
+ " attachment2: " +
621
+ JSON.stringify(attachment2, null, 4) +
622
+ "`"
623
+ );
624
+ }
625
+ }
626
+
627
+ function formatAttachment(attachments, attachmentIds, attachmentMap, shareMap) {
628
+ attachmentMap = shareMap || attachmentMap;
629
+ return attachments ?
630
+ attachments.map(function(val, i) {
631
+ if (!attachmentMap ||
632
+ !attachmentIds ||
633
+ !attachmentMap[attachmentIds[i]]
634
+ ) {
635
+ return _formatAttachment(val);
636
+ }
637
+ return _formatAttachment(val, attachmentMap[attachmentIds[i]]);
638
+ }) : [];
639
+ }
640
+
641
+ function formatDeltaMessage(m) {
642
+ var md = m.delta.messageMetadata;
643
+ var mdata =
644
+ m.delta.data === undefined ? [] :
645
+ m.delta.data.prng === undefined ? [] :
646
+ JSON.parse(m.delta.data.prng);
647
+ var m_id = mdata.map(u => u.i);
648
+ var m_offset = mdata.map(u => u.o);
649
+ var m_length = mdata.map(u => u.l);
650
+ var mentions = {};
651
+ var body = m.delta.body || "";
652
+ var args = body == "" ? [] : body.trim().split(/\s+/);
653
+ for (var i = 0; i < m_id.length; i++) mentions[m_id[i]] = m.delta.body.substring(m_offset[i], m_offset[i] + m_length[i]);
654
+
655
+ return {
656
+ type: "message",
657
+ senderID: formatID(md.actorFbId.toString()),
658
+ threadID: formatID((md.threadKey.threadFbId || md.threadKey.otherUserFbId).toString()),
659
+ messageID: md.messageId,
660
+ args: args,
661
+ body: body,
662
+ attachments: (m.delta.attachments || []).map(v => _formatAttachment(v)),
663
+ mentions: mentions,
664
+ timestamp: md.timestamp,
665
+ isGroup: !!md.threadKey.threadFbId,
666
+ participantIDs: m.delta.participants || []
667
+ };
668
+ }
669
+
670
+ function formatID(id) {
671
+ if (id != undefined && id != null) return id.replace(/(fb)?id[:.]/, "");
672
+ else return id;
673
+ }
674
+
675
+ function formatMessage(m) {
676
+ var originalMessage = m.message ? m.message : m;
677
+ var obj = {
678
+ type: "message",
679
+ senderName: originalMessage.sender_name,
680
+ senderID: formatID(originalMessage.sender_fbid.toString()),
681
+ participantNames: originalMessage.group_thread_info ? originalMessage.group_thread_info.participant_names : [originalMessage.sender_name.split(" ")[0]],
682
+ participantIDs: originalMessage.group_thread_info ?
683
+ originalMessage.group_thread_info.participant_ids.map(function(v) {
684
+ return formatID(v.toString());
685
+ }) : [formatID(originalMessage.sender_fbid)],
686
+ body: originalMessage.body || "",
687
+ threadID: formatID((originalMessage.thread_fbid || originalMessage.other_user_fbid).toString()),
688
+ threadName: originalMessage.group_thread_info ? originalMessage.group_thread_info.name : originalMessage.sender_name,
689
+ location: originalMessage.coordinates ? originalMessage.coordinates : null,
690
+ messageID: originalMessage.mid ? originalMessage.mid.toString() : originalMessage.message_id,
691
+ attachments: formatAttachment(
692
+ originalMessage.attachments,
693
+ originalMessage.attachmentIds,
694
+ originalMessage.attachment_map,
695
+ originalMessage.share_map
696
+ ),
697
+ timestamp: originalMessage.timestamp,
698
+ timestampAbsolute: originalMessage.timestamp_absolute,
699
+ timestampRelative: originalMessage.timestamp_relative,
700
+ timestampDatetime: originalMessage.timestamp_datetime,
701
+ tags: originalMessage.tags,
702
+ reactions: originalMessage.reactions ? originalMessage.reactions : [],
703
+ isUnread: originalMessage.is_unread
704
+ };
705
+
706
+ if (m.type === "pages_messaging") obj.pageID = m.realtime_viewer_fbid.toString();
707
+ obj.isGroup = obj.participantIDs.length > 2;
708
+
709
+ return obj;
710
+ }
711
+
712
+ function formatEvent(m) {
713
+ var originalMessage = m.message ? m.message : m;
714
+ var logMessageType = originalMessage.log_message_type;
715
+ var logMessageData;
716
+ if (logMessageType === "log:generic-admin-text") {
717
+ logMessageData = originalMessage.log_message_data.untypedData;
718
+ logMessageType = getAdminTextMessageType(originalMessage.log_message_data.message_type);
719
+ } else logMessageData = originalMessage.log_message_data;
720
+
721
+ return Object.assign(formatMessage(originalMessage), {
722
+ type: "event",
723
+ logMessageType: logMessageType,
724
+ logMessageData: logMessageData,
725
+ logMessageBody: originalMessage.log_message_body
726
+ });
727
+ }
728
+
729
+ function formatHistoryMessage(m) {
730
+ switch (m.action_type) {
731
+ case "ma-type:log-message":
732
+ return formatEvent(m);
733
+ default:
734
+ return formatMessage(m);
735
+ }
736
+ }
737
+
738
+ // Get a more readable message type for AdminTextMessages
739
+ function getAdminTextMessageType(m) {
740
+ switch (m.type) {
741
+ case "change_thread_theme":
742
+ return "log:thread-color";
743
+ case "change_thread_icon":
744
+ return "log:thread-icon";
745
+ case "change_thread_nickname":
746
+ return "log:user-nickname";
747
+ case "change_thread_admins":
748
+ return "log:thread-admins";
749
+ case "group_poll":
750
+ return "log:thread-poll";
751
+ case "change_thread_approval_mode":
752
+ return "log:thread-approval-mode";
753
+ case "messenger_call_log":
754
+ case "participant_joined_group_call":
755
+ return "log:thread-call";
756
+ }
757
+ }
758
+
759
+ function formatDeltaEvent(m) {
760
+ var logMessageType;
761
+ var logMessageData;
762
+
763
+ // log:thread-color => {theme_color}
764
+ // log:user-nickname => {participant_id, nickname}
765
+ // log:thread-icon => {thread_icon}
766
+ // log:thread-name => {name}
767
+ // log:subscribe => {addedParticipants - [Array]}
768
+ //log:unsubscribe => {leftParticipantFbId}
769
+
770
+ switch (m.class) {
771
+ case "AdminTextMessage":
772
+ logMessageType = getAdminTextMessageType(m);
773
+ logMessageData = m.untypedData;
774
+ break;
775
+ case "ThreadName":
776
+ logMessageType = "log:thread-name";
777
+ logMessageData = { name: m.name };
778
+ break;
779
+ case "ParticipantsAddedToGroupThread":
780
+ logMessageType = "log:subscribe";
781
+ logMessageData = { addedParticipants: m.addedParticipants };
782
+ break;
783
+ case "ParticipantLeftGroupThread":
784
+ logMessageType = "log:unsubscribe";
785
+ logMessageData = { leftParticipantFbId: m.leftParticipantFbId };
786
+ break;
787
+ }
788
+
789
+ return {
790
+ type: "event",
791
+ threadID: formatID((m.messageMetadata.threadKey.threadFbId || m.messageMetadata.threadKey.otherUserFbId).toString()),
792
+ logMessageType: logMessageType,
793
+ logMessageData: logMessageData,
794
+ logMessageBody: m.messageMetadata.adminText,
795
+ author: m.messageMetadata.actorFbId,
796
+ participantIDs: m.participants || []
797
+ };
798
+ }
799
+
800
+ function formatTyp(event) {
801
+ return {
802
+ isTyping: !!event.st,
803
+ from: event.from.toString(),
804
+ threadID: formatID((event.to || event.thread_fbid || event.from).toString()),
805
+ // When receiving typ indication from mobile, `from_mobile` isn't set.
806
+ // If it is, we just use that value.
807
+ fromMobile: event.hasOwnProperty("from_mobile") ? event.from_mobile : true,
808
+ userID: (event.realtime_viewer_fbid || event.from).toString(),
809
+ type: "typ"
810
+ };
811
+ }
812
+
813
+ function formatDeltaReadReceipt(delta) {
814
+ // otherUserFbId seems to be used as both the readerID and the threadID in a 1-1 chat.
815
+ // In a group chat actorFbId is used for the reader and threadFbId for the thread.
816
+ return {
817
+ reader: (delta.threadKey.otherUserFbId || delta.actorFbId).toString(),
818
+ time: delta.actionTimestampMs,
819
+ threadID: formatID((delta.threadKey.otherUserFbId || delta.threadKey.threadFbId).toString()),
820
+ type: "read_receipt"
821
+ };
822
+ }
823
+
824
+ function formatReadReceipt(event) {
825
+ return {
826
+ reader: event.reader.toString(),
827
+ time: event.time,
828
+ threadID: formatID((event.thread_fbid || event.reader).toString()),
829
+ type: "read_receipt"
830
+ };
831
+ }
832
+
833
+ function formatRead(event) {
834
+ return {
835
+ threadID: formatID(((event.chat_ids && event.chat_ids[0]) || (event.thread_fbids && event.thread_fbids[0])).toString()),
836
+ time: event.timestamp,
837
+ type: "read"
838
+ };
839
+ }
840
+
841
+ function getFrom(str, startToken, endToken) {
842
+ var start = str.indexOf(startToken) + startToken.length;
843
+ if (start < startToken.length) return "";
844
+
845
+ var lastHalf = str.substring(start);
846
+ var end = lastHalf.indexOf(endToken);
847
+ if (end === -1) throw Error("Could not find endTime `" + endToken + "` in the given string.");
848
+ return lastHalf.substring(0, end);
849
+ }
850
+
851
+ function makeParsable(html) {
852
+ let withoutForLoop = html.replace(/for\s*\(\s*;\s*;\s*\)\s*;\s*/, "");
853
+
854
+ // (What the fuck FB, why windows style newlines?)
855
+ // So sometimes FB will send us base multiple objects in the same response.
856
+ // They're all valid JSON, one after the other, at the top level. We detect
857
+ // that and make it parse-able by JSON.parse.
858
+ // Ben - July 15th 2017
859
+ //
860
+ // It turns out that Facebook may insert random number of spaces before
861
+ // next object begins (issue #616)
862
+ // rav_kr - 2018-03-19
863
+ let maybeMultipleObjects = withoutForLoop.split(/\}\r\n *\{/);
864
+ if (maybeMultipleObjects.length === 1) return maybeMultipleObjects;
865
+
866
+ return "[" + maybeMultipleObjects.join("},{") + "]";
867
+ }
868
+
869
+ function arrToForm(form) {
870
+ return arrayToObject(form,
871
+ function(v) {
872
+ return v.name;
873
+ },
874
+ function(v) {
875
+ return v.val;
876
+ }
877
+ );
878
+ }
879
+
880
+ function arrayToObject(arr, getKey, getValue) {
881
+ return arr.reduce(function(acc, val) {
882
+ acc[getKey(val)] = getValue(val);
883
+ return acc;
884
+ }, {});
885
+ }
886
+
887
+ function getSignatureID() {
888
+ return Math.floor(Math.random() * 2147483648).toString(16);
889
+ }
890
+
891
+ function generateTimestampRelative() {
892
+ var d = new Date();
893
+ return d.getHours() + ":" + padZeros(d.getMinutes());
894
+ }
895
+
896
+ function makeDefaults(html, userID, ctx) {
897
+ var reqCounter = 1;
898
+ var fb_dtsg = getFrom(html, 'name="fb_dtsg" value="', '"');
899
+
900
+ // @Hack Ok we've done hacky things, this is definitely on top 5.
901
+ // We totally assume the object is flat and try parsing until a }.
902
+ // If it works though it's cool because we get a bunch of extra data things.
903
+ //
904
+ // Update: we don't need this. Leaving it in in case we ever do.
905
+ // Ben - July 15th 2017
906
+
907
+ // var siteData = getFrom(html, "[\"SiteData\",[],", "},");
908
+ // try {
909
+ // siteData = JSON.parse(siteData + "}");
910
+ // } catch(e) {
911
+ // log.warn("makeDefaults", "Couldn't parse SiteData. Won't have access to some variables.");
912
+ // siteData = {};
913
+ // }
914
+
915
+ var ttstamp = "2";
916
+ for (var i = 0; i < fb_dtsg.length; i++) ttstamp += fb_dtsg.charCodeAt(i);
917
+ var revision = getFrom(html, 'revision":', ",");
918
+
919
+ function mergeWithDefaults(obj) {
920
+ // @TODO This is missing a key called __dyn.
921
+ // After some investigation it seems like __dyn is some sort of set that FB
922
+ // calls BitMap. It seems like certain responses have a "define" key in the
923
+ // res.jsmods arrays. I think the code iterates over those and calls `set`
924
+ // on the bitmap for each of those keys. Then it calls
925
+ // bitmap.toCompressedString() which returns what __dyn is.
926
+ //
927
+ // So far the API has been working without this.
928
+ //
929
+ // Ben - July 15th 2017
930
+ var newObj = {
931
+ __user: userID,
932
+ __req: (reqCounter++).toString(36),
933
+ __rev: revision,
934
+ __a: 1,
935
+ // __af: siteData.features,
936
+ fb_dtsg: ctx.fb_dtsg ? ctx.fb_dtsg : fb_dtsg,
937
+ jazoest: ctx.ttstamp ? ctx.ttstamp : ttstamp
938
+ // __spin_r: siteData.__spin_r,
939
+ // __spin_b: siteData.__spin_b,
940
+ // __spin_t: siteData.__spin_t,
941
+ };
942
+
943
+ // @TODO this is probably not needed.
944
+ // Ben - July 15th 2017
945
+ // if (siteData.be_key) {
946
+ // newObj[siteData.be_key] = siteData.be_mode;
947
+ // }
948
+ // if (siteData.pkg_cohort_key) {
949
+ // newObj[siteData.pkg_cohort_key] = siteData.pkg_cohort;
950
+ // }
951
+
952
+ if (!obj) return newObj;
953
+ for (var prop in obj)
954
+ if (obj.hasOwnProperty(prop))
955
+ if (!newObj[prop]) newObj[prop] = obj[prop];
956
+ return newObj;
957
+ }
958
+
959
+ function postWithDefaults(url, jar, form, ctxx) {
960
+ return post(url, jar, mergeWithDefaults(form), ctx.globalOptions, ctxx || ctx);
961
+ }
962
+
963
+ function getWithDefaults(url, jar, qs, ctxx) {
964
+ return get(url, jar, mergeWithDefaults(qs), ctx.globalOptions, ctxx || ctx);
965
+ }
966
+
967
+ function postFormDataWithDefault(url, jar, form, qs, ctxx) {
968
+ return postFormData(url, jar, mergeWithDefaults(form), mergeWithDefaults(qs), ctx.globalOptions, ctxx || ctx);
969
+ }
970
+
971
+ return {
972
+ get: getWithDefaults,
973
+ post: postWithDefaults,
974
+ postFormData: postFormDataWithDefault
975
+ };
976
+ }
977
+
978
+ function parseAndCheckLogin(ctx, defaultFuncs, retryCount) {
979
+ if (retryCount == undefined) retryCount = 0;
980
+ return function(data) {
981
+ return bluebird.try(function() {
982
+ log.verbose("parseAndCheckLogin", data.body);
983
+ if (data.statusCode >= 500 && data.statusCode < 600) {
984
+ if (retryCount >= 5) {
985
+ throw {
986
+ error: "Request retry failed. Check the `res` and `statusCode` property on this error.",
987
+ statusCode: data.statusCode,
988
+ res: data.body
989
+ };
990
+ }
991
+ retryCount++;
992
+ var retryTime = Math.floor(Math.random() * 5000);
993
+ log.warn("parseAndCheckLogin", "Got status code " + data.statusCode + " - " + retryCount + ". attempt to retry in " + retryTime + " milliseconds...");
994
+ var url = data.request.uri.protocol + "//" + data.request.uri.hostname + data.request.uri.pathname;
995
+ if (data.request.headers["Content-Type"].split(";")[0] === "multipart/form-data") {
996
+ return bluebird.delay(retryTime).then(() => defaultFuncs.postFormData(url, ctx.jar, data.request.formData, {}))
997
+ .then(parseAndCheckLogin(ctx, defaultFuncs, retryCount));
998
+ } else {
999
+ return bluebird.delay(retryTime).then(() => defaultFuncs.post(url, ctx.jar, data.request.formData))
1000
+ .then(parseAndCheckLogin(ctx, defaultFuncs, retryCount));
1001
+ }
1002
+ }
1003
+ if (data.statusCode !== 200) throw new Error("parseAndCheckLogin got status code: " + data.statusCode + ". Bailing out of trying to parse response.");
1004
+
1005
+ var res = null;
1006
+ try {
1007
+ res = JSON.parse(makeParsable(data.body));
1008
+ } catch (e) {
1009
+ throw {
1010
+ error: "JSON.parse error. Check the `detail` property on this error.",
1011
+ detail: e,
1012
+ res: data.body
1013
+ };
1014
+ }
1015
+
1016
+ // In some cases the response contains only a redirect URL which should be followed
1017
+ if (res.redirect && data.request.method === "GET") return defaultFuncs.get(res.redirect, ctx.jar).then(parseAndCheckLogin(ctx, defaultFuncs));
1018
+
1019
+ // TODO: handle multiple cookies?
1020
+ if (res.jsmods && res.jsmods.require && Array.isArray(res.jsmods.require[0]) && res.jsmods.require[0][0] === "Cookie") {
1021
+ res.jsmods.require[0][3][0] = res.jsmods.require[0][3][0].replace("_js_", "");
1022
+ var cookie = formatCookie(res.jsmods.require[0][3], "facebook");
1023
+ var cookie2 = formatCookie(res.jsmods.require[0][3], "messenger");
1024
+ ctx.jar.setCookie(cookie, "https://www.facebook.com");
1025
+ ctx.jar.setCookie(cookie2, "https://www.messenger.com");
1026
+ }
1027
+
1028
+ // On every request we check if we got a DTSG and we mutate the context so that we use the latest
1029
+ // one for the next requests.
1030
+ if (res.jsmods && Array.isArray(res.jsmods.require)) {
1031
+ var arr = res.jsmods.require;
1032
+ for (var i in arr) {
1033
+ if (arr[i][0] === "DTSG" && arr[i][1] === "setToken") {
1034
+ ctx.fb_dtsg = arr[i][3][0];
1035
+
1036
+ // Update ttstamp since that depends on fb_dtsg
1037
+ ctx.ttstamp = "2";
1038
+ for (var j = 0; j < ctx.fb_dtsg.length; j++) ctx.ttstamp += ctx.fb_dtsg.charCodeAt(j);
1039
+ }
1040
+ }
1041
+ }
1042
+
1043
+ if (res.error === 1357001) throw { error: "Appstate Đã Bị Lỗi" };
1044
+ return res;
1045
+ });
1046
+ };
1047
+ }
1048
+
1049
+ function saveCookies(jar) {
1050
+ return function(res) {
1051
+ var cookies = res.headers["set-cookie"] || [];
1052
+ cookies.forEach(function(c) {
1053
+ if (c.indexOf(".facebook.com") > -1) jar.setCookie(c, "https://www.facebook.com");
1054
+ var c2 = c.replace(/domain=\.facebook\.com/, "domain=.messenger.com");
1055
+ jar.setCookie(c2, "https://www.messenger.com");
1056
+ });
1057
+ return res;
1058
+ };
1059
+ }
1060
+
1061
+ var NUM_TO_MONTH = [
1062
+ "Jan",
1063
+ "Feb",
1064
+ "Mar",
1065
+ "Apr",
1066
+ "May",
1067
+ "Jun",
1068
+ "Jul",
1069
+ "Aug",
1070
+ "Sep",
1071
+ "Oct",
1072
+ "Nov",
1073
+ "Dec"
1074
+ ];
1075
+ var NUM_TO_DAY = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
1076
+
1077
+ function formatDate(date) {
1078
+ var d = date.getUTCDate();
1079
+ d = d >= 10 ? d : "0" + d;
1080
+ var h = date.getUTCHours();
1081
+ h = h >= 10 ? h : "0" + h;
1082
+ var m = date.getUTCMinutes();
1083
+ m = m >= 10 ? m : "0" + m;
1084
+ var s = date.getUTCSeconds();
1085
+ s = s >= 10 ? s : "0" + s;
1086
+ return (NUM_TO_DAY[date.getUTCDay()] + ", " + d + " " + NUM_TO_MONTH[date.getUTCMonth()] + " " + date.getUTCFullYear() + " " + h + ":" + m + ":" + s + " GMT");
1087
+ }
1088
+
1089
+ function formatCookie(arr, url) {
1090
+ return arr[0] + "=" + arr[1] + "; Path=" + arr[3] + "; Domain=" + url + ".com";
1091
+ }
1092
+
1093
+ function formatThread(data) {
1094
+ return {
1095
+ threadID: formatID(data.thread_fbid.toString()),
1096
+ participants: data.participants.map(formatID),
1097
+ participantIDs: data.participants.map(formatID),
1098
+ name: data.name,
1099
+ nicknames: data.custom_nickname,
1100
+ snippet: data.snippet,
1101
+ snippetAttachments: data.snippet_attachments,
1102
+ snippetSender: formatID((data.snippet_sender || "").toString()),
1103
+ unreadCount: data.unread_count,
1104
+ messageCount: data.message_count,
1105
+ imageSrc: data.image_src,
1106
+ timestamp: data.timestamp,
1107
+ serverTimestamp: data.server_timestamp, // what is this?
1108
+ muteUntil: data.mute_until,
1109
+ isCanonicalUser: data.is_canonical_user,
1110
+ isCanonical: data.is_canonical,
1111
+ isSubscribed: data.is_subscribed,
1112
+ folder: data.folder,
1113
+ isArchived: data.is_archived,
1114
+ recipientsLoadable: data.recipients_loadable,
1115
+ hasEmailParticipant: data.has_email_participant,
1116
+ readOnly: data.read_only,
1117
+ canReply: data.can_reply,
1118
+ cannotReplyReason: data.cannot_reply_reason,
1119
+ lastMessageTimestamp: data.last_message_timestamp,
1120
+ lastReadTimestamp: data.last_read_timestamp,
1121
+ lastMessageType: data.last_message_type,
1122
+ emoji: data.custom_like_icon,
1123
+ color: data.custom_color,
1124
+ adminIDs: data.admin_ids,
1125
+ threadType: data.thread_type
1126
+ };
1127
+ }
1128
+
1129
+ function getType(obj) {
1130
+ return Object.prototype.toString.call(obj).slice(8, -1);
1131
+ }
1132
+
1133
+ function formatProxyPresence(presence, userID) {
1134
+ if (presence.lat === undefined || presence.p === undefined) return null;
1135
+ return {
1136
+ type: "presence",
1137
+ timestamp: presence.lat * 1000,
1138
+ userID: userID || '',
1139
+ statuses: presence.p
1140
+ };
1141
+ }
1142
+
1143
+ function formatPresence(presence, userID) {
1144
+ return {
1145
+ type: "presence",
1146
+ timestamp: presence.la * 1000,
1147
+ userID: userID || '',
1148
+ statuses: presence.a
1149
+ };
1150
+ }
1151
+
1152
+ function decodeClientPayload(payload) {
1153
+ /*
1154
+ Special function which Client using to "encode" clients JSON payload
1155
+ */
1156
+ function Utf8ArrayToStr(array) {
1157
+ var out, i, len, c;
1158
+ var char2, char3;
1159
+ out = "";
1160
+ len = array.length;
1161
+ i = 0;
1162
+ while (i < len) {
1163
+ c = array[i++];
1164
+ switch (c >> 4) {
1165
+ case 0:
1166
+ case 1:
1167
+ case 2:
1168
+ case 3:
1169
+ case 4:
1170
+ case 5:
1171
+ case 6:
1172
+ case 7:
1173
+ out += String.fromCharCode(c);
1174
+ break;
1175
+ case 12:
1176
+ case 13:
1177
+ char2 = array[i++];
1178
+ out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
1179
+ break;
1180
+ case 14:
1181
+ char2 = array[i++];
1182
+ char3 = array[i++];
1183
+ out += String.fromCharCode(((c & 0x0F) << 12) | ((char2 & 0x3F) << 6) | ((char3 & 0x3F) << 0));
1184
+ break;
1185
+ }
1186
+ }
1187
+ return out;
1188
+ }
1189
+ return JSON.parse(Utf8ArrayToStr(payload));
1190
+ }
1191
+ function getAppState(jar) {
1192
+ var appstate = jar.getCookies("https://www.facebook.com").concat(jar.getCookies("https://facebook.com")).concat(jar.getCookies("https://www.messenger.com"));
1193
+ if (global.fca.ObjFcaConfig['encryptSt']) {
1194
+ var StateCrypt = require('./StateCrypt');
1195
+ var logger = require('./logger');
1196
+ logger(global.fca.languages.encAppstate,'[ FCA-DUONG ]');
1197
+ var keyy = process.env['FBKEY'];
1198
+
1199
+ if (process.env['FBKEY']) {
1200
+
1201
+ return StateCrypt.encryptState(JSON.stringify(appstate),process.env['FBKEY']);
1202
+
1203
+ }
1204
+ }
1205
+ else return appstate;
1206
+ }
1207
+ module.exports = {
1208
+ isReadableStream:isReadableStream,
1209
+ get:get,
1210
+ post:post,
1211
+ postFormData:postFormData,
1212
+ generateThreadingID:generateThreadingID,
1213
+ generateOfflineThreadingID:generateOfflineThreadingID,
1214
+ getGUID:getGUID,
1215
+ getFrom:getFrom,
1216
+ makeParsable:makeParsable,
1217
+ arrToForm:arrToForm,
1218
+ getSignatureID:getSignatureID,
1219
+ getJar: request.jar,
1220
+ generateTimestampRelative:generateTimestampRelative,
1221
+ makeDefaults:makeDefaults,
1222
+ parseAndCheckLogin:parseAndCheckLogin,
1223
+ saveCookies,
1224
+ getType,
1225
+ _formatAttachment,
1226
+ formatHistoryMessage,
1227
+ formatID,
1228
+ formatMessage,
1229
+ formatDeltaEvent,
1230
+ formatDeltaMessage,
1231
+ formatProxyPresence,
1232
+ formatPresence,
1233
+ formatTyp,
1234
+ formatDeltaReadReceipt,
1235
+ formatCookie,
1236
+ formatThread,
1237
+ formatReadReceipt,
1238
+ formatRead,
1239
+ generatePresence,
1240
+ generateAccessiblityCookie,
1241
+ formatDate,
1242
+ decodeClientPayload,
1243
+ getAppState,
1244
+ getAdminTextMessageType,
1245
+ setProxy
1246
+ };