tiny-essentials 1.24.0 → 1.24.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (442) hide show
  1. package/.github/workflows/node.js.yml +2 -2
  2. package/README.md +6 -2
  3. package/changelog/1/24/1.md +12 -0
  4. package/dist/v1/TinyBasicsEs.min.js +1 -1
  5. package/dist/v1/TinyDragger.min.js +1 -1
  6. package/dist/v1/TinyEssentials.min.js +1 -1
  7. package/dist/v1/TinyHtml.min.js +1 -1
  8. package/dist/v1/TinySmartScroller.min.js +1 -1
  9. package/dist/v1/TinyUploadClicker.min.js +1 -1
  10. package/dist/v1/basics/array.cjs +28 -0
  11. package/dist/v1/basics/array.d.mts +16 -0
  12. package/dist/v1/basics/array.mjs +27 -0
  13. package/dist/v1/basics/index.cjs +2 -4
  14. package/dist/v1/basics/index.d.mts +2 -2
  15. package/dist/v1/basics/index.mjs +2 -4
  16. package/dist/v1/basics/text.cjs +33 -0
  17. package/dist/v1/basics/text.d.mts +15 -0
  18. package/dist/v1/basics/text.mjs +28 -0
  19. package/dist/v1/build/TinyLevelUp.cjs +2 -2
  20. package/dist/v1/build/TinyLevelUp.d.mts +1 -1
  21. package/dist/v1/build/TinyLevelUp.mjs +1 -1
  22. package/dist/v1/index.cjs +4 -6
  23. package/dist/v1/index.d.mts +3 -3
  24. package/dist/v1/index.mjs +7 -6
  25. package/dist/v1/libs/TinyHtml/TinyHtmlAnchor.cjs +220 -0
  26. package/dist/v1/libs/TinyHtml/TinyHtmlAnchor.d.mts +98 -0
  27. package/dist/v1/libs/TinyHtml/TinyHtmlAnchor.mjs +207 -0
  28. package/dist/v1/libs/TinyHtml/TinyHtmlButton.cjs +317 -0
  29. package/dist/v1/libs/TinyHtml/TinyHtmlButton.d.mts +150 -0
  30. package/dist/v1/libs/TinyHtml/TinyHtmlButton.mjs +290 -0
  31. package/dist/v1/libs/TinyHtml/TinyHtmlCanvas.cjs +48 -0
  32. package/dist/v1/libs/TinyHtml/TinyHtmlCanvas.d.mts +36 -0
  33. package/dist/v1/libs/TinyHtml/TinyHtmlCanvas.mjs +44 -0
  34. package/dist/v1/libs/TinyHtml/TinyHtmlDatalist.cjs +102 -0
  35. package/dist/v1/libs/TinyHtml/TinyHtmlDatalist.d.mts +65 -0
  36. package/dist/v1/libs/TinyHtml/TinyHtmlDatalist.mjs +91 -0
  37. package/dist/v1/libs/TinyHtml/TinyHtmlEmbed.cjs +80 -0
  38. package/dist/v1/libs/TinyHtml/TinyHtmlEmbed.d.mts +57 -0
  39. package/dist/v1/libs/TinyHtml/TinyHtmlEmbed.mjs +75 -0
  40. package/dist/v1/libs/TinyHtml/TinyHtmlForm.cjs +244 -0
  41. package/dist/v1/libs/TinyHtml/TinyHtmlForm.d.mts +129 -0
  42. package/dist/v1/libs/TinyHtml/TinyHtmlForm.mjs +228 -0
  43. package/dist/v1/libs/TinyHtml/TinyHtmlIcon.cjs +38 -0
  44. package/dist/v1/libs/TinyHtml/TinyHtmlIcon.d.mts +24 -0
  45. package/dist/v1/libs/TinyHtml/TinyHtmlIcon.mjs +33 -0
  46. package/dist/v1/libs/TinyHtml/TinyHtmlIframe.cjs +222 -0
  47. package/dist/v1/libs/TinyHtml/TinyHtmlIframe.d.mts +108 -0
  48. package/dist/v1/libs/TinyHtml/TinyHtmlIframe.mjs +212 -0
  49. package/dist/v1/libs/TinyHtml/TinyHtmlImage.cjs +286 -0
  50. package/dist/v1/libs/TinyHtml/TinyHtmlImage.d.mts +125 -0
  51. package/dist/v1/libs/TinyHtml/TinyHtmlImage.mjs +250 -0
  52. package/dist/v1/libs/TinyHtml/TinyHtmlInput.cjs +154 -0
  53. package/dist/v1/libs/TinyHtml/TinyHtmlInput.d.mts +76 -0
  54. package/dist/v1/libs/TinyHtml/TinyHtmlInput.mjs +134 -0
  55. package/dist/v1/libs/TinyHtml/TinyHtmlLink.cjs +282 -0
  56. package/dist/v1/libs/TinyHtml/TinyHtmlLink.d.mts +128 -0
  57. package/dist/v1/libs/TinyHtml/TinyHtmlLink.mjs +264 -0
  58. package/dist/v1/libs/TinyHtml/TinyHtmlMedia.cjs +358 -0
  59. package/dist/v1/libs/TinyHtml/TinyHtmlMedia.d.mts +168 -0
  60. package/dist/v1/libs/TinyHtml/TinyHtmlMedia.mjs +308 -0
  61. package/dist/v1/libs/TinyHtml/TinyHtmlScript.cjs +226 -0
  62. package/dist/v1/libs/TinyHtml/TinyHtmlScript.d.mts +99 -0
  63. package/dist/v1/libs/TinyHtml/TinyHtmlScript.mjs +209 -0
  64. package/dist/v1/libs/TinyHtml/TinyHtmlSelect.cjs +267 -0
  65. package/dist/v1/libs/TinyHtml/TinyHtmlSelect.d.mts +146 -0
  66. package/dist/v1/libs/TinyHtml/TinyHtmlSelect.mjs +251 -0
  67. package/dist/v1/libs/TinyHtml/TinyHtmlStyle.cjs +110 -0
  68. package/dist/v1/libs/TinyHtml/TinyHtmlStyle.d.mts +57 -0
  69. package/dist/v1/libs/TinyHtml/TinyHtmlStyle.mjs +108 -0
  70. package/dist/v1/libs/TinyHtml/TinyHtmlTemplate.cjs +209 -0
  71. package/dist/v1/libs/TinyHtml/TinyHtmlTemplate.d.mts +101 -0
  72. package/dist/v1/libs/TinyHtml/TinyHtmlTemplate.mjs +189 -0
  73. package/dist/v1/libs/TinyHtml/TinyHtmlTextarea.cjs +331 -0
  74. package/dist/v1/libs/TinyHtml/TinyHtmlTextarea.d.mts +139 -0
  75. package/dist/v1/libs/TinyHtml/TinyHtmlTextarea.mjs +299 -0
  76. package/dist/v1/libs/TinyHtml/index.cjs +202 -0
  77. package/dist/v1/libs/TinyHtml/index.d.mts +82 -0
  78. package/dist/v1/libs/TinyHtml/index.mjs +185 -0
  79. package/dist/v1/libs/TinyHtml/input/TinyHtmlColorInput.cjs +121 -0
  80. package/dist/v1/libs/TinyHtml/input/TinyHtmlColorInput.d.mts +67 -0
  81. package/dist/v1/libs/TinyHtml/input/TinyHtmlColorInput.mjs +99 -0
  82. package/dist/v1/libs/TinyHtml/input/TinyHtmlFileInput.cjs +109 -0
  83. package/dist/v1/libs/TinyHtml/input/TinyHtmlFileInput.d.mts +63 -0
  84. package/dist/v1/libs/TinyHtml/input/TinyHtmlFileInput.mjs +92 -0
  85. package/dist/v1/libs/TinyHtml/input/TinyHtmlHiddenInput.cjs +101 -0
  86. package/dist/v1/libs/TinyHtml/input/TinyHtmlHiddenInput.d.mts +54 -0
  87. package/dist/v1/libs/TinyHtml/input/TinyHtmlHiddenInput.mjs +82 -0
  88. package/dist/v1/libs/TinyHtml/input/TinyHtmlImageInput.cjs +181 -0
  89. package/dist/v1/libs/TinyHtml/input/TinyHtmlImageInput.d.mts +97 -0
  90. package/dist/v1/libs/TinyHtml/input/TinyHtmlImageInput.mjs +160 -0
  91. package/dist/v1/libs/TinyHtml/input/button/TinyHtmlButtonInput.cjs +90 -0
  92. package/dist/v1/libs/TinyHtml/input/button/TinyHtmlButtonInput.d.mts +54 -0
  93. package/dist/v1/libs/TinyHtml/input/button/TinyHtmlButtonInput.mjs +69 -0
  94. package/dist/v1/libs/TinyHtml/input/button/TinyHtmlResetInput.cjs +59 -0
  95. package/dist/v1/libs/TinyHtml/input/button/TinyHtmlResetInput.d.mts +43 -0
  96. package/dist/v1/libs/TinyHtml/input/button/TinyHtmlResetInput.mjs +45 -0
  97. package/dist/v1/libs/TinyHtml/input/button/TinyHtmlSubmitInput.cjs +141 -0
  98. package/dist/v1/libs/TinyHtml/input/button/TinyHtmlSubmitInput.d.mts +74 -0
  99. package/dist/v1/libs/TinyHtml/input/button/TinyHtmlSubmitInput.mjs +114 -0
  100. package/dist/v1/libs/TinyHtml/input/check/TinyHtmlCheckboxInput.cjs +103 -0
  101. package/dist/v1/libs/TinyHtml/input/check/TinyHtmlCheckboxInput.d.mts +61 -0
  102. package/dist/v1/libs/TinyHtml/input/check/TinyHtmlCheckboxInput.mjs +85 -0
  103. package/dist/v1/libs/TinyHtml/input/check/TinyHtmlRadioInput.cjs +115 -0
  104. package/dist/v1/libs/TinyHtml/input/check/TinyHtmlRadioInput.d.mts +56 -0
  105. package/dist/v1/libs/TinyHtml/input/check/TinyHtmlRadioInput.mjs +94 -0
  106. package/dist/v1/libs/TinyHtml/input/date/TinyHtmlDateInput.cjs +172 -0
  107. package/dist/v1/libs/TinyHtml/input/date/TinyHtmlDateInput.d.mts +74 -0
  108. package/dist/v1/libs/TinyHtml/input/date/TinyHtmlDateInput.mjs +140 -0
  109. package/dist/v1/libs/TinyHtml/input/date/TinyHtmlDateTimeInput.cjs +145 -0
  110. package/dist/v1/libs/TinyHtml/input/date/TinyHtmlDateTimeInput.d.mts +77 -0
  111. package/dist/v1/libs/TinyHtml/input/date/TinyHtmlDateTimeInput.mjs +121 -0
  112. package/dist/v1/libs/TinyHtml/input/date/TinyHtmlMonthInput.cjs +146 -0
  113. package/dist/v1/libs/TinyHtml/input/date/TinyHtmlMonthInput.d.mts +74 -0
  114. package/dist/v1/libs/TinyHtml/input/date/TinyHtmlMonthInput.mjs +120 -0
  115. package/dist/v1/libs/TinyHtml/input/date/TinyHtmlTimeInput.cjs +151 -0
  116. package/dist/v1/libs/TinyHtml/input/date/TinyHtmlTimeInput.d.mts +75 -0
  117. package/dist/v1/libs/TinyHtml/input/date/TinyHtmlTimeInput.mjs +128 -0
  118. package/dist/v1/libs/TinyHtml/input/date/TinyHtmlWeekInput.cjs +150 -0
  119. package/dist/v1/libs/TinyHtml/input/date/TinyHtmlWeekInput.d.mts +74 -0
  120. package/dist/v1/libs/TinyHtml/input/date/TinyHtmlWeekInput.mjs +122 -0
  121. package/dist/v1/libs/TinyHtml/input/number/TinyHtmlNumberInput.cjs +134 -0
  122. package/dist/v1/libs/TinyHtml/input/number/TinyHtmlNumberInput.d.mts +74 -0
  123. package/dist/v1/libs/TinyHtml/input/number/TinyHtmlNumberInput.mjs +110 -0
  124. package/dist/v1/libs/TinyHtml/input/number/TinyHtmlRangeInput.cjs +133 -0
  125. package/dist/v1/libs/TinyHtml/input/number/TinyHtmlRangeInput.d.mts +75 -0
  126. package/dist/v1/libs/TinyHtml/input/number/TinyHtmlRangeInput.mjs +111 -0
  127. package/dist/v1/libs/TinyHtml/input/text/TinyHtmlEmailInput.cjs +179 -0
  128. package/dist/v1/libs/TinyHtml/input/text/TinyHtmlEmailInput.d.mts +87 -0
  129. package/dist/v1/libs/TinyHtml/input/text/TinyHtmlEmailInput.mjs +151 -0
  130. package/dist/v1/libs/TinyHtml/input/text/TinyHtmlPasswordInput.cjs +126 -0
  131. package/dist/v1/libs/TinyHtml/input/text/TinyHtmlPasswordInput.d.mts +70 -0
  132. package/dist/v1/libs/TinyHtml/input/text/TinyHtmlPasswordInput.mjs +104 -0
  133. package/dist/v1/libs/TinyHtml/input/text/TinyHtmlSearchInput.cjs +177 -0
  134. package/dist/v1/libs/TinyHtml/input/text/TinyHtmlSearchInput.d.mts +91 -0
  135. package/dist/v1/libs/TinyHtml/input/text/TinyHtmlSearchInput.mjs +153 -0
  136. package/dist/v1/libs/TinyHtml/input/text/TinyHtmlTelInput.cjs +170 -0
  137. package/dist/v1/libs/TinyHtml/input/text/TinyHtmlTelInput.d.mts +91 -0
  138. package/dist/v1/libs/TinyHtml/input/text/TinyHtmlTelInput.mjs +143 -0
  139. package/dist/v1/libs/TinyHtml/input/text/TinyHtmlTextInput.cjs +173 -0
  140. package/dist/v1/libs/TinyHtml/input/text/TinyHtmlTextInput.d.mts +89 -0
  141. package/dist/v1/libs/TinyHtml/input/text/TinyHtmlTextInput.mjs +150 -0
  142. package/dist/v1/libs/TinyHtml/input/text/TinyHtmlUrlInput.cjs +166 -0
  143. package/dist/v1/libs/TinyHtml/input/text/TinyHtmlUrlInput.d.mts +81 -0
  144. package/dist/v1/libs/TinyHtml/input/text/TinyHtmlUrlInput.mjs +142 -0
  145. package/dist/v1/libs/TinyHtml/media/TinyHtmlAudio.cjs +135 -0
  146. package/dist/v1/libs/TinyHtml/media/TinyHtmlAudio.d.mts +47 -0
  147. package/dist/v1/libs/TinyHtml/media/TinyHtmlAudio.mjs +122 -0
  148. package/dist/v1/libs/TinyHtml/media/TinyHtmlObject.cjs +100 -0
  149. package/dist/v1/libs/TinyHtml/media/TinyHtmlObject.d.mts +62 -0
  150. package/dist/v1/libs/TinyHtml/media/TinyHtmlObject.mjs +94 -0
  151. package/dist/v1/libs/TinyHtml/media/TinyHtmlSource.cjs +159 -0
  152. package/dist/v1/libs/TinyHtml/media/TinyHtmlSource.d.mts +77 -0
  153. package/dist/v1/libs/TinyHtml/media/TinyHtmlSource.mjs +136 -0
  154. package/dist/v1/libs/TinyHtml/media/TinyHtmlVideo.cjs +193 -0
  155. package/dist/v1/libs/TinyHtml/media/TinyHtmlVideo.d.mts +91 -0
  156. package/dist/v1/libs/TinyHtml/media/TinyHtmlVideo.mjs +167 -0
  157. package/dist/v1/libs/TinyHtml.cjs +260 -3
  158. package/dist/v1/libs/TinyHtml.d.mts +196 -5
  159. package/dist/v1/libs/TinyHtml.mjs +238 -3
  160. package/dist/{legacy/libs/userLevel.d.mts → v1/libs/TinyLevelUp.d.mts} +1 -1
  161. package/docs/v1/libs/TinyHtml.md +4 -4
  162. package/package.json +11 -24
  163. package/dist/_virtual/_commonjsHelpers.cjs +0 -7
  164. package/dist/_virtual/common.cjs +0 -5
  165. package/dist/_virtual/index.cjs +0 -9
  166. package/dist/_virtual/index2.cjs +0 -5
  167. package/dist/_virtual/trace.cjs +0 -5
  168. package/dist/legacy/crypto/decrypt.cjs +0 -59
  169. package/dist/legacy/crypto/decrypt.d.mts +0 -20
  170. package/dist/legacy/crypto/decrypt.mjs +0 -49
  171. package/dist/legacy/crypto/default.cjs +0 -23
  172. package/dist/legacy/crypto/default.d.mts +0 -36
  173. package/dist/legacy/crypto/default.mjs +0 -19
  174. package/dist/legacy/crypto/encrypt.cjs +0 -55
  175. package/dist/legacy/crypto/encrypt.d.mts +0 -21
  176. package/dist/legacy/crypto/encrypt.mjs +0 -47
  177. package/dist/legacy/crypto/index.cjs +0 -11
  178. package/dist/legacy/crypto/index.d.mts +0 -5
  179. package/dist/legacy/crypto/index.mjs +0 -6
  180. package/dist/legacy/firebase/cookieSession.cjs +0 -123
  181. package/dist/legacy/firebase/cookieSession.d.mts +0 -57
  182. package/dist/legacy/firebase/cookieSession.mjs +0 -115
  183. package/dist/legacy/firebase/database/index.cjs +0 -14
  184. package/dist/legacy/firebase/database/index.d.mts +0 -8
  185. package/dist/legacy/firebase/database/index.mjs +0 -8
  186. package/dist/legacy/firebase/database/presence.cjs +0 -137
  187. package/dist/legacy/firebase/database/presence.d.mts +0 -13
  188. package/dist/legacy/firebase/database/presence.mjs +0 -115
  189. package/dist/legacy/firebase/database/saveAsync.cjs +0 -149
  190. package/dist/legacy/firebase/database/saveAsync.d.mts +0 -55
  191. package/dist/legacy/firebase/database/saveAsync.mjs +0 -148
  192. package/dist/legacy/firebase/databaseEscape.cjs +0 -45
  193. package/dist/legacy/firebase/databaseEscape.d.mts +0 -12
  194. package/dist/legacy/firebase/databaseEscape.mjs +0 -38
  195. package/dist/legacy/firebase/databaseLogger.cjs +0 -261
  196. package/dist/legacy/firebase/databaseLogger.d.mts +0 -8
  197. package/dist/legacy/firebase/databaseLogger.mjs +0 -235
  198. package/dist/legacy/firebase/discord/api/addGuildMember.cjs +0 -74
  199. package/dist/legacy/firebase/discord/api/addGuildMember.d.mts +0 -39
  200. package/dist/legacy/firebase/discord/api/addGuildMember.mjs +0 -65
  201. package/dist/legacy/firebase/discord/api/getGuildWidget.cjs +0 -50
  202. package/dist/legacy/firebase/discord/api/getGuildWidget.d.mts +0 -18
  203. package/dist/legacy/firebase/discord/api/getGuildWidget.mjs +0 -44
  204. package/dist/legacy/firebase/discord/api/getToken.cjs +0 -70
  205. package/dist/legacy/firebase/discord/api/getToken.d.mts +0 -36
  206. package/dist/legacy/firebase/discord/api/getToken.mjs +0 -64
  207. package/dist/legacy/firebase/discord/api/getUser.cjs +0 -61
  208. package/dist/legacy/firebase/discord/api/getUser.d.mts +0 -28
  209. package/dist/legacy/firebase/discord/api/getUser.mjs +0 -55
  210. package/dist/legacy/firebase/discord/api/getUserConnections.cjs +0 -60
  211. package/dist/legacy/firebase/discord/api/getUserConnections.d.mts +0 -27
  212. package/dist/legacy/firebase/discord/api/getUserConnections.mjs +0 -54
  213. package/dist/legacy/firebase/discord/api/getUserGuilds.cjs +0 -59
  214. package/dist/legacy/firebase/discord/api/getUserGuilds.d.mts +0 -26
  215. package/dist/legacy/firebase/discord/api/getUserGuilds.mjs +0 -53
  216. package/dist/legacy/firebase/discord/api/index.cjs +0 -27
  217. package/dist/legacy/firebase/discord/api/index.d.mts +0 -20
  218. package/dist/legacy/firebase/discord/api/index.mjs +0 -21
  219. package/dist/legacy/firebase/discord/api/refreshToken.cjs +0 -80
  220. package/dist/legacy/firebase/discord/api/refreshToken.d.mts +0 -46
  221. package/dist/legacy/firebase/discord/api/refreshToken.mjs +0 -74
  222. package/dist/legacy/firebase/discord/api/revokeToken.cjs +0 -64
  223. package/dist/legacy/firebase/discord/api/revokeToken.d.mts +0 -30
  224. package/dist/legacy/firebase/discord/api/revokeToken.mjs +0 -59
  225. package/dist/legacy/firebase/discord/config.cjs +0 -23
  226. package/dist/legacy/firebase/discord/config.d.mts +0 -28
  227. package/dist/legacy/firebase/discord/config.mjs +0 -18
  228. package/dist/legacy/firebase/discord/firebase_redirect/index.cjs +0 -14
  229. package/dist/legacy/firebase/discord/firebase_redirect/index.d.mts +0 -8
  230. package/dist/legacy/firebase/discord/firebase_redirect/index.mjs +0 -8
  231. package/dist/legacy/firebase/discord/firebase_redirect/login.cjs +0 -112
  232. package/dist/legacy/firebase/discord/firebase_redirect/login.d.mts +0 -5
  233. package/dist/legacy/firebase/discord/firebase_redirect/login.mjs +0 -108
  234. package/dist/legacy/firebase/discord/firebase_redirect/logout.cjs +0 -102
  235. package/dist/legacy/firebase/discord/firebase_redirect/logout.d.mts +0 -5
  236. package/dist/legacy/firebase/discord/firebase_redirect/logout.mjs +0 -98
  237. package/dist/legacy/firebase/discord/get/authURLGenerator.cjs +0 -79
  238. package/dist/legacy/firebase/discord/get/authURLGenerator.d.mts +0 -24
  239. package/dist/legacy/firebase/discord/get/authURLGenerator.mjs +0 -68
  240. package/dist/legacy/firebase/discord/get/cookie-session.cjs +0 -35
  241. package/dist/legacy/firebase/discord/get/cookie-session.d.mts +0 -21
  242. package/dist/legacy/firebase/discord/get/cookie-session.mjs +0 -29
  243. package/dist/legacy/firebase/discord/get/credentials.cjs +0 -26
  244. package/dist/legacy/firebase/discord/get/credentials.d.mts +0 -20
  245. package/dist/legacy/firebase/discord/get/credentials.mjs +0 -21
  246. package/dist/legacy/firebase/discord/get/errorValidator.cjs +0 -63
  247. package/dist/legacy/firebase/discord/get/errorValidator.d.mts +0 -29
  248. package/dist/legacy/firebase/discord/get/errorValidator.mjs +0 -56
  249. package/dist/legacy/firebase/discord/get/index.cjs +0 -20
  250. package/dist/legacy/firebase/discord/get/index.d.mts +0 -14
  251. package/dist/legacy/firebase/discord/get/index.mjs +0 -14
  252. package/dist/legacy/firebase/discord/get/randomAvatar.cjs +0 -40
  253. package/dist/legacy/firebase/discord/get/randomAvatar.d.mts +0 -23
  254. package/dist/legacy/firebase/discord/get/randomAvatar.mjs +0 -31
  255. package/dist/legacy/firebase/discord/http/index.cjs +0 -18
  256. package/dist/legacy/firebase/discord/http/index.d.mts +0 -12
  257. package/dist/legacy/firebase/discord/http/index.mjs +0 -12
  258. package/dist/legacy/firebase/discord/http/login.cjs +0 -130
  259. package/dist/legacy/firebase/discord/http/login.d.mts +0 -22
  260. package/dist/legacy/firebase/discord/http/login.mjs +0 -124
  261. package/dist/legacy/firebase/discord/http/logout.cjs +0 -158
  262. package/dist/legacy/firebase/discord/http/logout.d.mts +0 -23
  263. package/dist/legacy/firebase/discord/http/logout.mjs +0 -144
  264. package/dist/legacy/firebase/discord/http/redirect.cjs +0 -191
  265. package/dist/legacy/firebase/discord/http/redirect.d.mts +0 -25
  266. package/dist/legacy/firebase/discord/http/redirect.mjs +0 -179
  267. package/dist/legacy/firebase/discord/http/refreshToken.cjs +0 -136
  268. package/dist/legacy/firebase/discord/http/refreshToken.d.mts +0 -25
  269. package/dist/legacy/firebase/discord/http/refreshToken.mjs +0 -122
  270. package/dist/legacy/firebase/discord/index.cjs +0 -22
  271. package/dist/legacy/firebase/discord/index.d.mts +0 -16
  272. package/dist/legacy/firebase/discord/index.mjs +0 -16
  273. package/dist/legacy/firebase/discord/template/cookie-session.cjs +0 -1433
  274. package/dist/legacy/firebase/discord/template/cookie-session.d.mts +0 -23
  275. package/dist/legacy/firebase/discord/template/cookie-session.mjs +0 -1160
  276. package/dist/legacy/firebase/domainRedirect.cjs +0 -37
  277. package/dist/legacy/firebase/domainRedirect.d.mts +0 -13
  278. package/dist/legacy/firebase/domainRedirect.mjs +0 -28
  279. package/dist/legacy/firebase/escape.cjs +0 -77
  280. package/dist/legacy/firebase/escape.d.mts +0 -18
  281. package/dist/legacy/firebase/escape.mjs +0 -59
  282. package/dist/legacy/firebase/getDBAsync.cjs +0 -35
  283. package/dist/legacy/firebase/getDBAsync.d.mts +0 -11
  284. package/dist/legacy/firebase/getDBAsync.mjs +0 -27
  285. package/dist/legacy/firebase/getDBData.cjs +0 -24
  286. package/dist/legacy/firebase/getDBData.d.mts +0 -2
  287. package/dist/legacy/firebase/getDBData.mjs +0 -18
  288. package/dist/legacy/firebase/getDBValue.cjs +0 -19
  289. package/dist/legacy/firebase/getDBValue.d.mts +0 -10
  290. package/dist/legacy/firebase/getDBValue.mjs +0 -15
  291. package/dist/legacy/firebase/index.cjs +0 -264
  292. package/dist/legacy/firebase/index.d.mts +0 -52
  293. package/dist/legacy/firebase/index.mjs +0 -235
  294. package/dist/legacy/firebase/isEmulator.cjs +0 -16
  295. package/dist/legacy/firebase/isEmulator.d.mts +0 -9
  296. package/dist/legacy/firebase/isEmulator.mjs +0 -11
  297. package/dist/legacy/firebase/logger.cjs +0 -140
  298. package/dist/legacy/firebase/logger.d.mts +0 -8
  299. package/dist/legacy/firebase/logger.mjs +0 -126
  300. package/dist/legacy/firebase/mySQL.cjs +0 -30
  301. package/dist/legacy/firebase/mySQL.d.mts +0 -11
  302. package/dist/legacy/firebase/mySQL.mjs +0 -23
  303. package/dist/legacy/firebase/mysqlConnector/create.cjs +0 -121
  304. package/dist/legacy/firebase/mysqlConnector/create.d.mts +0 -37
  305. package/dist/legacy/firebase/mysqlConnector/create.mjs +0 -110
  306. package/dist/legacy/firebase/mysqlConnector/index.cjs +0 -26
  307. package/dist/legacy/firebase/mysqlConnector/index.d.mts +0 -12
  308. package/dist/legacy/firebase/mysqlConnector/index.mjs +0 -17
  309. package/dist/legacy/firebase/mysqlConnector/nextPrev.cjs +0 -77
  310. package/dist/legacy/firebase/mysqlConnector/nextPrev.d.mts +0 -32
  311. package/dist/legacy/firebase/mysqlConnector/nextPrev.mjs +0 -64
  312. package/dist/legacy/firebase/mysqlConnector/pagination.cjs +0 -93
  313. package/dist/legacy/firebase/mysqlConnector/pagination.d.mts +0 -34
  314. package/dist/legacy/firebase/mysqlConnector/pagination.mjs +0 -88
  315. package/dist/legacy/firebase/mysqlConnector/sameUser.cjs +0 -31
  316. package/dist/legacy/firebase/mysqlConnector/sameUser.d.mts +0 -13
  317. package/dist/legacy/firebase/mysqlConnector/sameUser.mjs +0 -24
  318. package/dist/legacy/firebase/transactionDBAsync.cjs +0 -35
  319. package/dist/legacy/firebase/transactionDBAsync.d.mts +0 -12
  320. package/dist/legacy/firebase/transactionDBAsync.mjs +0 -28
  321. package/dist/legacy/get/countObj.cjs +0 -7
  322. package/dist/legacy/get/countObj.d.mts +0 -3
  323. package/dist/legacy/get/countObj.mjs +0 -2
  324. package/dist/legacy/get/decimalColor.cjs +0 -63
  325. package/dist/legacy/get/decimalColor.d.mts +0 -14
  326. package/dist/legacy/get/decimalColor.mjs +0 -56
  327. package/dist/legacy/get/objType.cjs +0 -7
  328. package/dist/legacy/get/objType.d.mts +0 -3
  329. package/dist/legacy/get/objType.mjs +0 -2
  330. package/dist/legacy/get/pagination.cjs +0 -109
  331. package/dist/legacy/get/pagination.d.mts +0 -44
  332. package/dist/legacy/get/pagination.mjs +0 -100
  333. package/dist/legacy/get/queryUrlByName.cjs +0 -32
  334. package/dist/legacy/get/queryUrlByName.d.mts +0 -22
  335. package/dist/legacy/get/queryUrlByName.mjs +0 -29
  336. package/dist/legacy/get/queryUrlJSON.cjs +0 -57
  337. package/dist/legacy/get/queryUrlJSON.d.mts +0 -25
  338. package/dist/legacy/get/queryUrlJSON.mjs +0 -59
  339. package/dist/legacy/get/super_string_filter.cjs +0 -109
  340. package/dist/legacy/get/super_string_filter.d.mts +0 -27
  341. package/dist/legacy/get/super_string_filter.mjs +0 -95
  342. package/dist/legacy/get/versionCheck.cjs +0 -50
  343. package/dist/legacy/get/versionCheck.d.mts +0 -29
  344. package/dist/legacy/get/versionCheck.mjs +0 -40
  345. package/dist/legacy/http/HTTP-1.0.cjs +0 -153
  346. package/dist/legacy/http/HTTP-1.0.d.mts +0 -9
  347. package/dist/legacy/http/HTTP-1.0.mjs +0 -138
  348. package/dist/legacy/http/auth.cjs +0 -71
  349. package/dist/legacy/http/auth.d.mts +0 -43
  350. package/dist/legacy/http/auth.mjs +0 -64
  351. package/dist/legacy/http/check_domain.cjs +0 -103
  352. package/dist/legacy/http/check_domain.d.mts +0 -13
  353. package/dist/legacy/http/check_domain.mjs +0 -98
  354. package/dist/legacy/http/csrfTokenAnalyze.cjs +0 -50
  355. package/dist/legacy/http/csrfTokenAnalyze.d.mts +0 -23
  356. package/dist/legacy/http/csrfTokenAnalyze.mjs +0 -45
  357. package/dist/legacy/http/domainValidator.cjs +0 -106
  358. package/dist/legacy/http/domainValidator.d.mts +0 -41
  359. package/dist/legacy/http/domainValidator.mjs +0 -89
  360. package/dist/legacy/http/errorsCallback.cjs +0 -64
  361. package/dist/legacy/http/errorsCallback.d.mts +0 -41
  362. package/dist/legacy/http/errorsCallback.mjs +0 -58
  363. package/dist/legacy/http/fetch/json.cjs +0 -50
  364. package/dist/legacy/http/fetch/json.d.mts +0 -24
  365. package/dist/legacy/http/fetch/json.mjs +0 -43
  366. package/dist/legacy/http/fetch/text.cjs +0 -49
  367. package/dist/legacy/http/fetch/text.d.mts +0 -23
  368. package/dist/legacy/http/fetch/text.mjs +0 -42
  369. package/dist/legacy/http/fileCache.cjs +0 -80
  370. package/dist/legacy/http/fileCache.d.mts +0 -37
  371. package/dist/legacy/http/fileCache.mjs +0 -71
  372. package/dist/legacy/http/getDomainURL.cjs +0 -60
  373. package/dist/legacy/http/getDomainURL.d.mts +0 -20
  374. package/dist/legacy/http/getDomainURL.mjs +0 -55
  375. package/dist/legacy/http/userIP.cjs +0 -65
  376. package/dist/legacy/http/userIP.d.mts +0 -27
  377. package/dist/legacy/http/userIP.mjs +0 -53
  378. package/dist/legacy/index.cjs +0 -125
  379. package/dist/legacy/index.d.mts +0 -89
  380. package/dist/legacy/index.mjs +0 -93
  381. package/dist/legacy/libs/arraySortPositions.cjs +0 -30
  382. package/dist/legacy/libs/arraySortPositions.d.mts +0 -17
  383. package/dist/legacy/libs/arraySortPositions.mjs +0 -27
  384. package/dist/legacy/libs/capitalize.cjs +0 -22
  385. package/dist/legacy/libs/capitalize.d.mts +0 -15
  386. package/dist/legacy/libs/capitalize.mjs +0 -18
  387. package/dist/legacy/libs/convertBytes.cjs +0 -66
  388. package/dist/legacy/libs/convertBytes.d.mts +0 -18
  389. package/dist/legacy/libs/convertBytes.mjs +0 -57
  390. package/dist/legacy/libs/custom_module_loader.cjs +0 -91
  391. package/dist/legacy/libs/custom_module_loader.d.mts +0 -6
  392. package/dist/legacy/libs/custom_module_loader.mjs +0 -87
  393. package/dist/legacy/libs/dice.cjs +0 -37
  394. package/dist/legacy/libs/dice.d.mts +0 -6
  395. package/dist/legacy/libs/dice.mjs +0 -33
  396. package/dist/legacy/libs/markdown.cjs +0 -97
  397. package/dist/legacy/libs/markdown.d.mts +0 -12
  398. package/dist/legacy/libs/markdown.mjs +0 -90
  399. package/dist/legacy/libs/percentage.cjs +0 -23
  400. package/dist/legacy/libs/percentage.d.mts +0 -5
  401. package/dist/legacy/libs/percentage.mjs +0 -20
  402. package/dist/legacy/libs/regex/getLetter.cjs +0 -24
  403. package/dist/legacy/libs/regex/getLetter.d.mts +0 -15
  404. package/dist/legacy/libs/regex/getLetter.mjs +0 -21
  405. package/dist/legacy/libs/replaceAsync.cjs +0 -35
  406. package/dist/legacy/libs/replaceAsync.d.mts +0 -16
  407. package/dist/legacy/libs/replaceAsync.mjs +0 -28
  408. package/dist/legacy/libs/rule3.cjs +0 -59
  409. package/dist/legacy/libs/rule3.d.mts +0 -6
  410. package/dist/legacy/libs/rule3.mjs +0 -55
  411. package/dist/legacy/momentjs/getAge.cjs +0 -29
  412. package/dist/legacy/momentjs/getAge.d.mts +0 -11
  413. package/dist/legacy/momentjs/getAge.mjs +0 -23
  414. package/dist/legacy/momentjs/index.cjs +0 -9
  415. package/dist/legacy/momentjs/index.d.mts +0 -4
  416. package/dist/legacy/momentjs/index.mjs +0 -3
  417. package/dist/legacy/momentjs/timeDuration.cjs +0 -31
  418. package/dist/legacy/momentjs/timeDuration.d.mts +0 -12
  419. package/dist/legacy/momentjs/timeDuration.mjs +0 -25
  420. package/dist/legacy/socket.io/antiFlood/index.cjs +0 -9
  421. package/dist/legacy/socket.io/antiFlood/index.d.mts +0 -4
  422. package/dist/legacy/socket.io/antiFlood/index.mjs +0 -3
  423. package/dist/legacy/socket.io/antiFlood/install.cjs +0 -34
  424. package/dist/legacy/socket.io/antiFlood/install.d.mts +0 -16
  425. package/dist/legacy/socket.io/antiFlood/install.mjs +0 -29
  426. package/dist/legacy/socket.io/antiFlood/verify.cjs +0 -95
  427. package/dist/legacy/socket.io/antiFlood/verify.d.mts +0 -20
  428. package/dist/legacy/socket.io/antiFlood/verify.mjs +0 -79
  429. package/dist/legacy/socket.io/cookie-session.cjs +0 -27
  430. package/dist/legacy/socket.io/cookie-session.d.mts +0 -11
  431. package/dist/legacy/socket.io/cookie-session.mjs +0 -22
  432. package/dist/legacy/socket.io/discord.cjs +0 -62
  433. package/dist/legacy/socket.io/discord.d.mts +0 -12
  434. package/dist/legacy/socket.io/discord.mjs +0 -53
  435. package/dist/legacy/socket.io/index.cjs +0 -13
  436. package/dist/legacy/socket.io/index.d.mts +0 -10
  437. package/dist/legacy/socket.io/index.mjs +0 -9
  438. package/dist/node_modules/firebase-functions/lib/common/trace.cjs +0 -81
  439. package/dist/node_modules/firebase-functions/lib/logger/common.cjs +0 -57
  440. package/dist/node_modules/firebase-functions/lib/logger/index.cjs +0 -159
  441. /package/dist/{legacy/libs/userLevel.cjs → v1/libs/TinyLevelUp.cjs} +0 -0
  442. /package/dist/{legacy/libs/userLevel.mjs → v1/libs/TinyLevelUp.mjs} +0 -0
@@ -1,1160 +0,0 @@
1
- // @ts-nocheck
2
- import hash from 'object-hash';
3
- import moment from 'moment-timezone';
4
- import _ from 'lodash';
5
- import clone from 'clone';
6
- import defaultCrypto from '../../../crypto/default.mjs';
7
- import objType from '../../../get/objType.mjs';
8
- import config from '../config.mjs';
9
- import fbLogger from '../../logger.mjs';
10
- import getUser from '../api/getUser.mjs';
11
- import userIp from '../../../http/userIP.mjs';
12
- import getDomainURL from '../../../http/getDomainURL.mjs';
13
- import login from '../firebase_redirect/login.mjs';
14
- import logout from '../firebase_redirect/logout.mjs';
15
- import addGuildMember from '../api/addGuildMember.mjs';
16
- import getGuildWidget from '../api/getGuildWidget.mjs';
17
- import getUserConnections from '../api/getUserConnections.mjs';
18
- import discordAuth from '../index.mjs';
19
- import getUserGuilds from '../api/getUserGuilds.mjs';
20
- import getCookieSession from '../get/cookie-session.mjs';
21
- import getFirebaseCookieSession from '../../../socket.io/cookie-session.mjs';
22
- import AuthSystem from '../../cookieSession.mjs';
23
- import revokeToken from '../api/revokeToken.mjs';
24
- /**
25
- * Middleware function to handle Discord and Firebase sessions, including login, logout,
26
- * and redirection functionalities.
27
- *
28
- * @param {Record<string, any>} app - The Express.js app object.
29
- * @param {Record<string, any>} cfg - The configuration object for the middleware, including Firebase settings.
30
- * @throws {Error} Throws an error if the configuration object is invalid.
31
- */
32
- export default function cookieSession(app, cfg) {
33
- // Config
34
- if (objType(cfg, 'object')) {
35
- // Validator Session Discord and Firebase
36
- const sessionFirebaseDiscordValidator = function (req) {
37
- return (req.firebase_session.uid ===
38
- `${discordSession.varsTemplate.uid}${tinyAuth.client_id}_${req.discord_session.user.id}`);
39
- };
40
- // Prepare Base
41
- app.use((req, res, next) => {
42
- // Add Discord Session
43
- if (!req.discord_session)
44
- req.discord_session = {};
45
- // Complete
46
- next();
47
- });
48
- // Logger
49
- const logger = fbLogger;
50
- // Get Discord User
51
- const getDiscordUser = getUser;
52
- // Get User IP
53
- const getUserIP = userIp;
54
- // Discord session
55
- const discordSession = {};
56
- // Firebase Auth
57
- discordSession.firebaseAuth = {};
58
- // Redirect
59
- discordSession.firebaseAuth.redirect = {
60
- template: function (type, req, res, redirect_url, csrfToken, firebase_auth) {
61
- // Get Domain
62
- const tinyDomain = getDomainURL(req, cfg.port);
63
- // Fix URL
64
- if (typeof redirect_url !== 'string')
65
- redirect_url = '';
66
- else if (redirect_url.startsWith('/'))
67
- redirect_url = redirect_url.substring(1);
68
- // New URL
69
- redirect_url = `${tinyURLPath[type]}?redirect=${encodeURIComponent(redirect_url)}`;
70
- if (typeof csrfToken === 'string')
71
- redirect_url += `&key=${csrfToken}`;
72
- if (typeof firebase_auth === 'string')
73
- redirect_url += `&token=${firebase_auth}`;
74
- // Complete
75
- res.redirect(tinyDomain + redirect_url);
76
- },
77
- // Login
78
- login: function (req, res, redirect_url, csrfToken) {
79
- return discordSession.firebaseAuth.redirect.template('firebaseLogin', req, res, redirect_url, csrfToken);
80
- },
81
- // Logout
82
- logout: function (req, res, redirect_url, csrfToken, firebase_auth) {
83
- return discordSession.firebaseAuth.redirect.template('firebaseLogout', req, res, redirect_url, csrfToken, firebase_auth);
84
- },
85
- };
86
- // Variables
87
- discordSession.varsTemplate = {
88
- uid: 'discord_user_id_',
89
- avatarURL: 'https://cdn.discordapp.com/avatars/',
90
- };
91
- // Get Firebase UID
92
- discordSession.uidGenerator = function (userID) {
93
- return `${discordSession.varsTemplate.uid}${tinyAuth.client_id}_${encodeURIComponent(userID)}`;
94
- };
95
- // Session Set
96
- discordSession.set = function (req, tokenRequest, extra_text = '') {
97
- // Session Items
98
- req.session[sessionVars.access_token + extra_text] = tokenRequest.access_token;
99
- req.session[sessionVars.refresh_token + extra_text] = tokenRequest.refresh_token;
100
- req.session[sessionVars.token_type + extra_text] = tokenRequest.token_type;
101
- req.session[sessionVars.scope + extra_text] = tokenRequest.scope;
102
- // Expire In
103
- req.session[sessionVars.token_expires_in + extra_text] = moment
104
- .tz('Universal')
105
- .add(tokenRequest.expires_in, 'second')
106
- .format();
107
- };
108
- discordSession.get = function (req) {
109
- return {
110
- access_token: req.session[sessionVars.access_token],
111
- refresh_token: req.session[sessionVars.refresh_token],
112
- token_type: req.session[sessionVars.token_type],
113
- scope: req.session[sessionVars.scope],
114
- token_expires_in: req.session[sessionVars.token_expires_in],
115
- };
116
- };
117
- // Prepare Firebase Items
118
- const prepare_fire_auth_discord = function (req, user) {
119
- // Discord Session
120
- const dsSession = discordSession.get(req);
121
- const preparedsSession = {};
122
- // Scope
123
- if (typeof dsSession.scope === 'string')
124
- preparedsSession.scope = dsSession.scope.split(' ');
125
- else
126
- preparedsSession.scope = dsSession.scope;
127
- // User IP
128
- if (tinyCfg.ipVerification) {
129
- const requestIpAddress = getUserIP(req, { isFirebase: true });
130
- preparedsSession.user_ip = requestIpAddress.value;
131
- preparedsSession.user_ip_type = requestIpAddress.type;
132
- }
133
- // Discord
134
- preparedsSession.discord = user;
135
- // Complete
136
- return preparedsSession;
137
- };
138
- // Firebase Discord Auth
139
- discordSession.firebase = {};
140
- discordSession.firebase.createAccountData = function (access_token, userData, oldData) {
141
- // Prepare New User Data
142
- const newUserData = {};
143
- const existOLD = objType(oldData, 'object');
144
- // Password
145
- if (typeof access_token === 'string' && access_token.length > 0)
146
- newUserData.password = access_token;
147
- // Main Data
148
- const newUsername = userData.username + '#' + userData.discriminator;
149
- const newAvatar = `${discordSession.varsTemplate.avatarURL}${userData.id}/${userData.avatar}`;
150
- // Basic Profile
151
- if (!existOLD || newUsername !== oldData.displayNama)
152
- newUserData.displayName = newUsername;
153
- if (!existOLD || newAvatar !== oldData.photoURL)
154
- newUserData.photoURL = newAvatar;
155
- // Insert User Email
156
- if (typeof userData.email === 'string') {
157
- if (!existOLD || userData.email !== oldData.email) {
158
- newUserData.email = userData.email;
159
- newUserData.emailVerified = userData.verified;
160
- }
161
- }
162
- // Complete
163
- return newUserData;
164
- };
165
- discordSession.firebase.updateUser = function (access_token, user, oldUser) {
166
- return new Promise(function (resolve, reject) {
167
- // Prepare MD5
168
- const validator = {};
169
- validator.user = hash(user);
170
- if (objType(oldUser, 'object'))
171
- validator.oldUser = hash(oldUser);
172
- else
173
- validator.oldUser = '';
174
- // Validate
175
- if (validator.user !== validator.oldUser) {
176
- // Get UID
177
- const uid = discordSession.uidGenerator(user.id);
178
- const firebaseAccount = discordSession.firebase.createAccountData(access_token, user, oldUser);
179
- // Update User
180
- cfg.firebase.auth
181
- .updateUser(uid, firebaseAccount)
182
- .then((userRecord) => resolve({
183
- updated: true,
184
- uid: uid,
185
- newData: firebaseAccount,
186
- userRecord: userRecord,
187
- }))
188
- .catch(reject);
189
- }
190
- // Nope
191
- else
192
- resolve({ updated: false });
193
- });
194
- };
195
- // Set User
196
- discordSession.firebase.set = function (req, user) {
197
- return new Promise(function (resolve, reject) {
198
- // UID
199
- const uid = discordSession.uidGenerator(user.id);
200
- const claims = prepare_fire_auth_discord(req, user);
201
- // Prepare Auth
202
- cfg.firebase.auth
203
- .createCustomToken(uid, claims)
204
- // Complete
205
- .then((customToken) => {
206
- req.session[sessionVars.firebase_auth_token] = customToken;
207
- resolve(customToken);
208
- })
209
- // Error
210
- .catch((err) => {
211
- reject({ code: 500, message: err.message });
212
- });
213
- });
214
- };
215
- // Get User
216
- discordSession.firebase.get = function (req, res) {
217
- return new Promise(function (resolve, reject) {
218
- // Prepare Auth
219
- cfg.firebase.auth
220
- .verifySessionCookie(req.session[sessionVars.firebase_token])
221
- // Complete
222
- .then((decodedToken) => {
223
- // Validator
224
- if (tinyCfg.ipVerification) {
225
- // Get Request IP
226
- const requestIpAddress = getUserIP(req, { isFirebase: true });
227
- // Convert
228
- if (typeof decodedToken.user_ip === 'string')
229
- decodedToken.user_ip = [decodedToken.user_ip];
230
- if (typeof requestIpAddress.value === 'string')
231
- requestIpAddress.value = [requestIpAddress.value];
232
- // Verification
233
- if (hash(decodedToken.user_ip) === hash(requestIpAddress.value) &&
234
- decodedToken.user_ip_type === requestIpAddress.type) {
235
- req.firebase_session = decodedToken;
236
- resolve();
237
- }
238
- // Nope
239
- else
240
- reject({ code: 406, message: 'Invalid User IP Session!' });
241
- }
242
- // Nope
243
- else {
244
- req.firebase_session = decodedToken;
245
- resolve();
246
- }
247
- })
248
- // Error
249
- .catch((err) => {
250
- reject({ code: 500, message: err.message });
251
- });
252
- });
253
- };
254
- // Firebase Redirect
255
- const firebase_redirect = { login, logout };
256
- for (const page in firebase_redirect)
257
- for (const item in firebase_redirect[page])
258
- firebase_redirect[page][item] = firebase_redirect[page][item].toString();
259
- // Create Settings
260
- const tinyCfg = _.defaultsDeep({}, cfg.cfg, {
261
- // IP Verification
262
- ipVerification: false,
263
- // Need Verification
264
- needEmailVerified: true,
265
- // Error Callback
266
- errorCallback: function (err, req, res) {
267
- if (res) {
268
- return res.json(err);
269
- }
270
- else {
271
- logger.error(err);
272
- }
273
- },
274
- // Redirect
275
- redirect: {
276
- /* Login */
277
- login: function (data, req, res) {
278
- return res.json(data);
279
- },
280
- /* Logout */
281
- logout: function (data, req, res) {
282
- return res.json(data);
283
- },
284
- webhook: function (data, req, res) {
285
- return res.json(data);
286
- },
287
- },
288
- });
289
- // Auth Config
290
- const tinyAuth = _.defaultsDeep({}, cfg.auth, {
291
- redirect: '',
292
- client_id: '',
293
- client_secret: '',
294
- bot_token: '',
295
- first_get_user: true,
296
- discordScope: ['identify', 'email'],
297
- });
298
- // Auth Commands Config
299
- const tinyCommandAuth = _.defaultsDeep({}, cfg.comamndAuth, {
300
- redirect: tinyAuth.redirect,
301
- client_id: tinyAuth.client_id,
302
- client_secret: tinyAuth.client_secret,
303
- bot_token: tinyAuth.bot_token,
304
- first_get_user: tinyAuth.first_get_user,
305
- discordScope: ['applications.commands'],
306
- });
307
- // Bot Auth
308
- const botAuth = _.defaultsDeep({}, cfg.bot, {
309
- discordScope: ['bot', 'applications.commands'],
310
- permissions: 0,
311
- });
312
- // Final Result
313
- const final_functions = {
314
- // Auth
315
- auth: tinyAuth,
316
- commandAuth: tinyCommandAuth,
317
- // API
318
- addGuildMember: function (data) {
319
- return addGuildMember(tinyAuth.bot_token, data);
320
- },
321
- getGuildWidget: function (guildID) {
322
- return getGuildWidget(guildID);
323
- },
324
- // UID Generator
325
- uidGenerator: function (userID) {
326
- return discordSession.uidGenerator(userID);
327
- },
328
- // Session Validator
329
- sessionValidator: function (data = {}) {
330
- return (req, res, next) => {
331
- // Validator Progress
332
- const validatorItems = {
333
- values: ['getUserConnections', 'getUser', 'getUserGuilds'],
334
- count: 0,
335
- callback: function () {
336
- // The Item
337
- const item = validatorItems.values[validatorItems.count];
338
- if (typeof item === 'string') {
339
- // Read Item
340
- if (data[item]) {
341
- final_functions.sessionPlugins[item](req, res, () => {
342
- validatorItems.count++;
343
- return validatorItems.callback();
344
- });
345
- }
346
- else {
347
- validatorItems.count++;
348
- validatorItems.callback();
349
- }
350
- }
351
- // Next
352
- else
353
- final_functions.sessionPlugins.validator(req, res, () => {
354
- next();
355
- });
356
- },
357
- };
358
- // Complete
359
- return validatorItems.callback();
360
- };
361
- },
362
- // Session Plugins
363
- sessionPlugins: {
364
- // Session Validator
365
- validator: function (req, res, next) {
366
- // Empty CSRF Token
367
- if (!req.csrfToken)
368
- req.csrfToken = { new: {}, now: {} };
369
- // Preparing Clocks
370
- if (!req.utc_clock)
371
- req.utc_clock = { now: moment.tz('Universal') };
372
- // Add Auth
373
- req.discord_session.auth = {
374
- app: tinyAuth,
375
- command: tinyCommandAuth,
376
- bot: botAuth,
377
- };
378
- // Exist Discord Session
379
- const existDiscordSession = typeof req.session[sessionVars.token_expires_in] === 'string' &&
380
- typeof req.session[sessionVars.access_token] === 'string' &&
381
- typeof req.session[sessionVars.refresh_token] === 'string';
382
- // Exist Session
383
- if (existDiscordSession &&
384
- !req.url.startsWith(tinyURLPath.firebaseLogin + '?') &&
385
- req.url !== tinyURLPath.firebaseLogin &&
386
- !req.url.startsWith(tinyURLPath.firebaseLogout + '?') &&
387
- req.url !== tinyURLPath.firebaseLogout) {
388
- // Exist Firebase
389
- if (cfg.firebase) {
390
- // Finish the Session
391
- const finishTinySession = function (err) {
392
- // Firebase Auth
393
- const firebase_auth = req.session[sessionVars.firebase_token];
394
- // Logout
395
- auto_logout(req, err)
396
- .then((result) => {
397
- logout_firebase(res, req, result.redirect, firebase_auth);
398
- })
399
- .catch((err) => {
400
- tinyCfg.errorCallback(err, req, res);
401
- });
402
- };
403
- discordSession.firebase
404
- .get(req, res)
405
- .then(() => {
406
- // Discord and Firebase same session
407
- if (!req.discord_session.user || sessionFirebaseDiscordValidator(req))
408
- checkDiscordSession(req, res, next);
409
- // Nope
410
- else
411
- finishTinySession();
412
- })
413
- .catch(finishTinySession);
414
- }
415
- // Nope
416
- else
417
- checkDiscordSession(req, res, next);
418
- }
419
- else
420
- next();
421
- },
422
- // Get User Module
423
- getUser: function (req, res, next) {
424
- // Get User Discord Data
425
- const access_token = req.session[sessionVars.access_token];
426
- if (typeof access_token === 'string') {
427
- getDiscordUser(access_token)
428
- .then((user) => {
429
- // Set Discord Data
430
- req.discord_session.user = user;
431
- // Complete
432
- next();
433
- })
434
- .catch((err) => {
435
- if (!req.discord_session.errors) {
436
- req.discord_session.errors = {};
437
- }
438
- req.discord_session.errors.user = err;
439
- delete req.discord_session.user;
440
- prepare_final_session(req, res, err);
441
- });
442
- }
443
- else
444
- next();
445
- },
446
- // Get User Module
447
- getUserConnections: function (req, res, next) {
448
- // Get User Discord Data
449
- if (typeof req.session[sessionVars.access_token] === 'string') {
450
- getUserConnections(req.session[sessionVars.access_token])
451
- .then((connections) => {
452
- // Set Discord Data
453
- req.discord_session.connections = connections;
454
- // Complete
455
- next();
456
- })
457
- .catch((err) => {
458
- if (!req.discord_session.errors) {
459
- req.discord_session.errors = {};
460
- }
461
- req.discord_session.errors.connections = err;
462
- delete req.discord_session.connections;
463
- prepare_final_session(req, res, err);
464
- });
465
- }
466
- else
467
- next();
468
- },
469
- // Get User Module
470
- getUserGuilds: function (req, res, next) {
471
- // Get User Discord Data
472
- if (typeof req.session[sessionVars.access_token] === 'string') {
473
- getUserGuilds(req.session[sessionVars.access_token])
474
- .then((guilds) => {
475
- // Set Discord Data
476
- req.discord_session.guilds = guilds;
477
- // Complete
478
- next();
479
- })
480
- .catch((err) => {
481
- if (!req.discord_session.errors) {
482
- req.discord_session.errors = {};
483
- }
484
- req.discord_session.errors.guilds = err;
485
- delete req.discord_session.guilds;
486
- prepare_final_session(req, res, err);
487
- });
488
- }
489
- else
490
- next();
491
- },
492
- },
493
- };
494
- // Test Modules Prepare
495
- const getSessionFromCookie = getCookieSession;
496
- // Need Identify
497
- if (tinyAuth.discordScope.indexOf('identify') < 0)
498
- tinyAuth.discordScope.push('identify');
499
- if (tinyAuth.discordScope.indexOf('email') < 0)
500
- tinyAuth.discordScope.push('email');
501
- // Firebase Mode
502
- if (objType(cfg.firebase, 'object')) {
503
- // Fix First Get User Value
504
- tinyAuth.first_get_user = true;
505
- // Fix Auth Value
506
- if (!cfg.firebase.auth)
507
- cfg.firebase.auth = cfg.firebase.root.auth();
508
- }
509
- // Session Vars
510
- const sessionVars = _.defaultsDeep({}, cfg.vars, {
511
- access_token: 'access_token',
512
- refresh_token: 'refresh_token',
513
- token_type: 'token_type',
514
- csrfToken: 'csrfToken',
515
- scope: 'scope',
516
- token_expires_in: 'token_expires_in',
517
- firebase_token: 'firebase_token',
518
- firebase_auth_token: 'firebase_auth_token',
519
- });
520
- // Crypto Values
521
- const tinyCrypto = _.defaultsDeep({}, cfg.crypto, defaultCrypto);
522
- // Crypto Values
523
- const tinyURLPath = _.defaultsDeep({}, cfg.url, {
524
- commandLogin: '/commandLogin',
525
- botLogin: '/botLogin',
526
- login: '/login',
527
- logout: '/logout',
528
- redirect: '/redirect',
529
- firebaseLogin: '/firebase/login',
530
- firebaseLogout: '/firebase/logout',
531
- });
532
- // Logout Firebase
533
- const logout_firebase = (res, req, redirect, firebase_auth) => {
534
- // Firebase Logout
535
- if (cfg.firebase)
536
- return discordSession.firebaseAuth.redirect.logout(req, res, redirect, req.csrfToken.now.value, firebase_auth);
537
- // Normal
538
- else {
539
- // Get Domain
540
- const tinyDomain = getDomainURL(req, cfg.port);
541
- return res.redirect(tinyDomain + redirect);
542
- }
543
- };
544
- // Logout Result
545
- const logout_result = (req, user) => {
546
- return new Promise(function (resolve) {
547
- // Firebase Logout
548
- if (cfg.firebase) {
549
- // Exist User
550
- if (user) {
551
- // Revoke Refresh
552
- cfg.firebase.auth
553
- .revokeRefreshTokens(discordSession.uidGenerator(user.id))
554
- .then(() => {
555
- req.session = null;
556
- resolve(user);
557
- })
558
- .catch((err) => {
559
- req.session = null;
560
- resolve(user);
561
- });
562
- }
563
- // Nope
564
- else {
565
- req.session = null;
566
- resolve();
567
- }
568
- }
569
- // Nope
570
- else {
571
- req.session = null;
572
- resolve(user);
573
- }
574
- });
575
- };
576
- // Remove Values
577
- const removeCommandSession = function (req, callback) {
578
- // Session Items
579
- delete req.session[sessionVars.access_token + '_command'];
580
- delete req.session[sessionVars.refresh_token + '_command'];
581
- delete req.session[sessionVars.token_type + '_command'];
582
- delete req.session[sessionVars.scope + '_command'];
583
- // Expire In
584
- delete req.session[sessionVars.token_expires_in + '_command'];
585
- // Complete
586
- return callback();
587
- };
588
- // Logout Action
589
- const logout_action = function (req, csrfToken, redirect) {
590
- return new Promise(function (resolve) {
591
- // State
592
- const state = { csrfToken: req.csrfToken.now.value };
593
- // Redirect
594
- if (redirect)
595
- state.redirect = redirect;
596
- // Result
597
- const finalResult = function () {
598
- discordAuth
599
- .logout(req, req.session[sessionVars.access_token], {
600
- // CSRF Token
601
- csrfToken: csrfToken,
602
- // Query
603
- query: {
604
- csrfToken: 'csrfToken',
605
- redirect: 'redirect',
606
- },
607
- // State
608
- state: state,
609
- // Auth
610
- auth: tinyAuth,
611
- }, (getSessionFromCookie(req, sessionVars.access_token),
612
- req.session[sessionVars.access_token]))
613
- .then(resolve)
614
- .catch(resolve);
615
- };
616
- // Normal
617
- if (typeof req.session[sessionVars.access_token + '_command'] !== 'string')
618
- finalResult();
619
- // Remove Command Token
620
- else {
621
- // Prepare Auth
622
- const commandAuth = clone(tinyAuth);
623
- commandAuth.discordScope = ['applications.commands', 'applications.commands.update'];
624
- discordAuth
625
- .logout(req, req.session[sessionVars.access_token], {
626
- // CSRF Token
627
- csrfToken: csrfToken,
628
- // Query
629
- query: {
630
- csrfToken: 'csrfToken',
631
- redirect: 'redirect',
632
- },
633
- // State
634
- state: state,
635
- // Auth
636
- auth: commandAuth,
637
- }, (getSessionFromCookie(req, sessionVars.access_token),
638
- req.session[sessionVars.access_token]))
639
- .then((result) => {
640
- removeCommandSession(req, finalResult);
641
- })
642
- .catch((err) => {
643
- removeCommandSession(req, finalResult);
644
- });
645
- }
646
- });
647
- };
648
- // Auto Logout
649
- const auto_logout = function (req, err) {
650
- return new Promise(function (resolve, reject) {
651
- // Print Error
652
- if (err)
653
- tinyCfg.errorCallback(err);
654
- // Result
655
- logout_action(req, req.csrfToken.now.value, req.url).then((result) => {
656
- // Discord Logout Complete
657
- logout_result(req, result.user).then(resolve);
658
- });
659
- });
660
- };
661
- // Prepare Final Session
662
- const prepare_final_session = function (req, res, err) {
663
- // Firebase Auth
664
- const firebase_auth = req.session[sessionVars.firebase_token];
665
- if (err)
666
- tinyCfg.errorCallback(err);
667
- // Logout
668
- auto_logout(req)
669
- .then((result) => {
670
- logout_firebase(res, req, result.redirect, firebase_auth);
671
- })
672
- .catch((err) => {
673
- tinyCfg.errorCallback(err, req, res);
674
- });
675
- };
676
- // Check Discord Session
677
- const checkDiscordSession = function (req, res, next) {
678
- // Rest Checker
679
- const restChecker = function () {
680
- // Add to Req
681
- if (typeof req.session[sessionVars.access_token + '_command'] === 'string' ||
682
- typeof req.session[sessionVars.access_token + '_command'] === 'number') {
683
- // Add Access Command
684
- req.discord_session.commands = {};
685
- req.discord_session.commands.access_token =
686
- req.session[sessionVars.access_token + '_command'];
687
- // Other Values
688
- if (typeof req.session[sessionVars.token_type + '_command'] === 'string' ||
689
- typeof req.session[sessionVars.token_type + '_command'] === 'number') {
690
- req.discord_session.commands.token_type =
691
- req.session[sessionVars.token_type + '_command'];
692
- }
693
- if (typeof req.session[sessionVars.scope + '_command'] === 'string' ||
694
- typeof req.session[sessionVars.scope + '_command'] === 'number')
695
- req.discord_session.commands.scope = req.session[sessionVars.scope + '_command'];
696
- }
697
- // Need Refresh
698
- if (req.utc_clock.ds_token_time_left < 1440) {
699
- // Not Expired
700
- if (req.utc_clock.ds_token_time_left > 0) {
701
- discordAuth
702
- .refreshToken(req, {
703
- // Auth
704
- auth: tinyAuth,
705
- // Refresh Token
706
- refresh_token: req.session[sessionVars.refresh_token],
707
- }, getSessionFromCookie(req, sessionVars.access_token))
708
- .then((result) => {
709
- // Complete
710
- if (result.refreshed) {
711
- // Set Cookie Session
712
- discordSession.set(req, result.tokenRequest);
713
- // Exist Firebase
714
- if (cfg.firebase) {
715
- // Set New Firebase Session Data
716
- const access_token = req.session[sessionVars.access_token];
717
- getDiscordUser(access_token)
718
- .then((user) => {
719
- // Set Custom Usre Claims
720
- cfg.firebase.auth
721
- .setCustomUserClaims(discordSession.uidGenerator(user.id), prepare_fire_auth_discord(req, user))
722
- .then(() => {
723
- // Update User Data
724
- /* discordSession.firebase.updateUser(access_token, user).then(function () {
725
- next();
726
- }).catch(error => {
727
- logger.error(error);
728
- prepare_final_session(req, res, error);
729
- }); */
730
- next();
731
- })
732
- .catch((err) => {
733
- prepare_final_session(req, res, err);
734
- });
735
- })
736
- .catch((err) => {
737
- prepare_final_session(req, res, err);
738
- });
739
- }
740
- // Nope
741
- else
742
- next();
743
- }
744
- // Nope
745
- else
746
- next();
747
- })
748
- .catch((err) => {
749
- prepare_final_session(req, res, err);
750
- });
751
- }
752
- // Finish the Session
753
- else
754
- prepare_final_session(req, res);
755
- }
756
- else {
757
- // Exist Discord Session Data and Firebase
758
- if (cfg.firebase && req.discord_session.user && objType(req.firebase_session, 'object')) {
759
- // Set New Firebase Session Data
760
- const access_token = req.session[sessionVars.access_token];
761
- // Prepare OLD User
762
- /* const oldUser = {};
763
-
764
- // Get ID
765
- oldUser.id = req.firebase_session.uid.substring(discordSession.varsTemplate.uid.length + tinyAuth.client_id.length + 1);
766
-
767
- // Convert Username
768
- oldUser.username = req.firebase_session.name.split('#');
769
-
770
- // Get Discriminator
771
- oldUser.discriminator = oldUser.username[oldUser.username.length - 1];
772
-
773
- // Remove Discriminator
774
- oldUser.username.pop();
775
-
776
- // Insert Username
777
- oldUser.username = oldUser.username.join('#');
778
-
779
- // Get Avatar
780
- oldUser.avatar = req.firebase_session.picture.substring(discordSession.varsTemplate.avatarURL.length + oldUser.id.length + 1);
781
-
782
- // Get Email
783
- oldUser.email = req.firebase_session.email;
784
- oldUser.verified = req.firebase_session.email_verified; */
785
- // Prepare New User
786
- const user = {
787
- id: req.discord_session.user.id,
788
- username: req.discord_session.user.username,
789
- avatar: req.discord_session.user.avatar,
790
- discriminator: req.discord_session.user.discriminator,
791
- email: req.discord_session.user.email,
792
- verified: req.discord_session.user.verified,
793
- };
794
- // Update User Data
795
- const make_the_update = function () {
796
- /*
797
- discordSession.firebase.updateUser(access_token, user, oldUser).then(function () {
798
- next();
799
- }).catch(error => {
800
- logger.error(error);
801
- prepare_final_session(req, res, error);
802
- });
803
- */
804
- next();
805
- };
806
- // Check Need Update
807
- let needUpdate = false;
808
- if (!objType(req.firebase_session.discord, 'object') ||
809
- hash(req.firebase_session.discord) !== hash(req.discord_session.user))
810
- needUpdate = true;
811
- // User Verified
812
- if (!needUpdate)
813
- make_the_update();
814
- // Nope
815
- else
816
- cfg.firebase.auth
817
- .setCustomUserClaims(discordSession.uidGenerator(req.discord_session.user.id), prepare_fire_auth_discord(req, req.discord_session.user))
818
- .then(() => make_the_update())
819
- .catch((err) => prepare_final_session(req, res, err));
820
- }
821
- // Nope
822
- else
823
- next();
824
- }
825
- };
826
- // Get Token Expiration
827
- req.utc_clock.ds_token_expires_in = moment.tz(req.session[sessionVars.token_expires_in], 'Universal');
828
- // Time Left
829
- req.utc_clock.ds_token_time_left = req.utc_clock.ds_token_expires_in.diff(req.utc_clock.now, 'minutes');
830
- // Command Time Left
831
- if (!req.session[sessionVars.token_expires_in + '_command'])
832
- return restChecker();
833
- // Nope
834
- else {
835
- // Get Token Expiration
836
- req.utc_clock.ds_token_expires_in_command = moment.tz(req.session[sessionVars.token_expires_in + '_command'], 'Universal');
837
- // Time Left
838
- req.utc_clock.ds_token_time_left_command = req.utc_clock.ds_token_expires_in.diff(req.utc_clock.now, 'minutes');
839
- // Need Refresh
840
- if (req.utc_clock.ds_token_time_left_command < 1440) {
841
- // Prepare Auth
842
- const commandAuth = clone(tinyAuth);
843
- commandAuth.discordScope = ['applications.commands', 'applications.commands.update'];
844
- // Logout
845
- const logoutCommand = function () {
846
- // Revoke Token
847
- revokeToken(req.session[sessionVars.access_token + '_command'], commandAuth)
848
- .then((data) => {
849
- removeCommandSession(req, restChecker);
850
- })
851
- .catch((err) => {
852
- removeCommandSession(req, restChecker);
853
- });
854
- };
855
- // Not Expired
856
- if (req.utc_clock.ds_token_time_left_command > 0) {
857
- discordAuth
858
- .refreshToken(req, {
859
- // Auth
860
- auth: commandAuth,
861
- // Refresh Token
862
- refresh_token: req.session[sessionVars.refresh_token + '_command'],
863
- }, getSessionFromCookie(req, sessionVars.access_token))
864
- .then((result) => {
865
- // Complete
866
- if (result.refreshed)
867
- discordSession.set(req, result.tokenRequest, '_command');
868
- // Rest
869
- restChecker();
870
- })
871
- .catch(async (err) => {
872
- logoutCommand();
873
- });
874
- }
875
- // Finish the Session
876
- else
877
- logoutCommand();
878
- }
879
- else
880
- restChecker();
881
- }
882
- };
883
- // Prepare Body Parser
884
- let bodyParser = {};
885
- if (cfg.bodyParser) {
886
- bodyParser.json = cfg.bodyParser.json();
887
- bodyParser.urlencoded = cfg.bodyParser.urlencoded({ extended: true });
888
- }
889
- // Login Firebase
890
- const firebaseLoginCallback = (req, res) => {
891
- // Remove OLD Auth Token
892
- req.session[sessionVars.firebase_auth_token] = null;
893
- // Exist Discord
894
- if (req.discord_session.user) {
895
- // Exist Body
896
- if (objType(req.body, 'object') && typeof req.body.token === 'string') {
897
- // Exist Query
898
- if (typeof req.csrfToken.now.value !== 'string' ||
899
- req.csrfToken.now.value.length < 1 ||
900
- (typeof req.body.csrfToken === 'string' &&
901
- req.csrfToken.now.value === req.body.csrfToken)) {
902
- // Prepare Module
903
- const newCookie = new AuthSystem();
904
- // Set Settings
905
- newCookie.setCookieTimeGenerator(cfg.cookieTimeGenerator);
906
- newCookie.setCheckAuthTime(cfg.checkAuthTime);
907
- // Action
908
- newCookie
909
- .genCookieSession(cfg.firebase.auth, req.body.token)
910
- .then((sessionCookie) => {
911
- req.session[sessionVars.firebase_token] = sessionCookie;
912
- res.json({ success: true });
913
- })
914
- .catch((err) => {
915
- res.json({ success: false, error: err.message });
916
- });
917
- /* discordSession.firebase.updateUser(req.session[sessionVars.access_token], req.discord_session.user).then(function () {
918
- res.json({ success: true });
919
- }).catch(error => {
920
- logger.error(error);
921
- res.json({ success: false, error: 'Error updating user' });
922
- }); */
923
- }
924
- // Nope
925
- else
926
- return res.json({ success: false, error: 'Invalid csrfToken!' });
927
- }
928
- // Nope
929
- else
930
- return res.json({ success: false, error: 'Invalid Data!' });
931
- }
932
- // Nope
933
- else
934
- return res.json({ success: false, error: 'Invalid Discord User!' });
935
- };
936
- if (cfg.bodyParser)
937
- app.post(tinyURLPath.firebaseLogin, bodyParser.json, bodyParser.urlencoded, final_functions.sessionPlugins.getUser, final_functions.sessionPlugins.validator, firebaseLoginCallback);
938
- else
939
- app.post(tinyURLPath.firebaseLogin, final_functions.sessionPlugins.getUser, final_functions.sessionPlugins.validator, firebaseLoginCallback);
940
- app.get(tinyURLPath.firebaseLogin, final_functions.sessionPlugins.validator, (req, res) => {
941
- // Final Data
942
- const final_data = {};
943
- // Exist Redirect
944
- if (typeof req.query.redirect === 'string')
945
- final_data.redirect = '/' + req.query.redirect;
946
- else
947
- final_data.redirect = '/';
948
- // Auth Token
949
- if (typeof req.session[sessionVars.firebase_auth_token] === 'string') {
950
- // Insert Data
951
- if (typeof req.query.key === 'string' && req.query.key.length > 0) {
952
- final_data.key = req.query.key;
953
- }
954
- final_data.functions = firebase_redirect.login;
955
- final_data.token = req.session[sessionVars.firebase_auth_token];
956
- // Complete
957
- return tinyCfg.redirect.login(final_data, req, res);
958
- }
959
- // Nope
960
- else {
961
- // Get Domain
962
- const tinyDomain = getDomainURL(req, cfg.port);
963
- return res.redirect(tinyDomain + final_data.redirect);
964
- }
965
- });
966
- // Logout Firebase
967
- const firebaseLogoutCallback = (req, res) => {
968
- req.session[sessionVars.firebase_token] = null;
969
- return res.json({ success: true });
970
- };
971
- if (cfg.bodyParser)
972
- app.post(tinyURLPath.firebaseLogout, bodyParser.json, bodyParser.urlencoded, final_functions.sessionPlugins.validator, firebaseLogoutCallback);
973
- else
974
- app.post(tinyURLPath.firebaseLogout, final_functions.sessionPlugins.validator, firebaseLogoutCallback);
975
- app.get(tinyURLPath.firebaseLogout, final_functions.sessionPlugins.validator, (req, res) => {
976
- // Final Data
977
- const final_data = {};
978
- // Exist Redirect
979
- if (typeof req.query.redirect === 'string')
980
- final_data.redirect = '/' + req.query.redirect;
981
- else
982
- final_data.redirect = '/';
983
- // Exist Token
984
- if (typeof req.query.firebase_auth === 'string') {
985
- // Insert Data
986
- if (typeof req.query.key === 'string' && req.query.key.length > 0) {
987
- final_data.key = req.query.key;
988
- }
989
- final_data.originalKey = req.csrfToken.now.value;
990
- final_data.functions = firebase_redirect.logout;
991
- final_data.token = req.query.firebase_auth;
992
- // Complete
993
- return tinyCfg.redirect.logout(final_data, req, res);
994
- }
995
- // Nope
996
- else {
997
- // Get Domain
998
- const tinyDomain = getDomainURL(req, cfg.port);
999
- return res.redirect(tinyDomain + final_data.redirect);
1000
- }
1001
- });
1002
- // Login
1003
- if (typeof tinyURLPath.login === 'string') {
1004
- app.get(tinyURLPath.login, final_functions.sessionPlugins.validator, (req, res) => {
1005
- // Result
1006
- discordAuth.login(req, res, {
1007
- // Error
1008
- errorCallback: tinyCfg.errorCallback,
1009
- // Crypto
1010
- crypto: tinyCrypto,
1011
- // Auth
1012
- auth: tinyAuth,
1013
- // Type
1014
- type: 'login',
1015
- // Query
1016
- query: { redirect: 'redirect' },
1017
- // State
1018
- state: {
1019
- csrfToken: req.csrfToken.now.value,
1020
- },
1021
- // Port
1022
- port: cfg.port,
1023
- }, getSessionFromCookie(req, sessionVars.access_token));
1024
- });
1025
- }
1026
- // Command Login
1027
- if (typeof tinyURLPath.commandLogin === 'string') {
1028
- app.get(tinyURLPath.commandLogin, final_functions.sessionPlugins.validator, (req, res) => {
1029
- // Prepare Auth
1030
- const commandAuth = clone(tinyCommandAuth);
1031
- // Result
1032
- discordAuth.login(req, res, {
1033
- // Error
1034
- errorCallback: tinyCfg.errorCallback,
1035
- // Crypto
1036
- crypto: tinyCrypto,
1037
- // Auth
1038
- auth: commandAuth,
1039
- // Type
1040
- type: 'login_command',
1041
- // Query
1042
- query: { redirect: 'redirect' },
1043
- // State
1044
- state: {
1045
- csrfToken: req.csrfToken.now.value,
1046
- },
1047
- // Port
1048
- port: cfg.port,
1049
- }, getSessionFromCookie(req, sessionVars.access_token));
1050
- });
1051
- }
1052
- // Add Commands
1053
- if (typeof tinyURLPath.botLogin === 'string') {
1054
- app.get(tinyURLPath.botLogin, (req, res) => {
1055
- return res.redirect(`${config.oauth2}?client_id=${encodeURIComponent(tinyAuth.client_id)}&scope=${encodeURIComponent(botAuth.discordScope.join(' '))}&permissions=${botAuth.permissions}`);
1056
- });
1057
- }
1058
- // Logout
1059
- app.get(tinyURLPath.logout, final_functions.sessionPlugins.validator, (req, res) => {
1060
- // Firebase Auth
1061
- const firebase_auth = req.session[sessionVars.firebase_token];
1062
- // Result
1063
- logout_action(req, req.query[sessionVars.csrfToken]).then((result) => {
1064
- // Discord Logout Complete
1065
- logout_result(req, result.user).then(() => {
1066
- logout_firebase(res, req, result.redirect, firebase_auth);
1067
- });
1068
- });
1069
- });
1070
- // Redirect
1071
- app.get(tinyURLPath.redirect, final_functions.sessionPlugins.validator, (req, res) => {
1072
- // Result
1073
- discordAuth
1074
- .redirect(req, {
1075
- // Auth
1076
- auth: tinyAuth,
1077
- // Crypto
1078
- crypto: tinyCrypto,
1079
- // Query
1080
- query: { redirect: 'redirect' },
1081
- // State
1082
- state: {
1083
- csrfToken: req.csrfToken.now.value,
1084
- },
1085
- }, getSessionFromCookie(req, sessionVars.access_token))
1086
- .then((result) => {
1087
- // New Session Result
1088
- if (result.state.type === 'login' && result.newSession) {
1089
- // Verified
1090
- if (!tinyCfg.needEmailVerified || result.user.verified) {
1091
- // Set Cookie Session
1092
- discordSession.set(req, result.tokenRequest);
1093
- // Set Firebase Session
1094
- if (cfg.firebase) {
1095
- discordSession.firebase
1096
- .set(req, result.user)
1097
- .then(() => {
1098
- discordSession.firebaseAuth.redirect.login(req, res, result.redirect, result.state.csrfToken);
1099
- })
1100
- .catch((err) => {
1101
- // Firebase Auth
1102
- const firebase_auth = req.session[sessionVars.firebase_token];
1103
- // Logout
1104
- auto_logout(req, { code: 500, message: err.message })
1105
- .then((result) => {
1106
- logout_firebase(res, req, result.redirect, firebase_auth);
1107
- })
1108
- .catch((err) => {
1109
- tinyCfg.errorCallback(err, req, res);
1110
- });
1111
- });
1112
- }
1113
- // Normal
1114
- else {
1115
- // Get Domain
1116
- const tinyDomain = getDomainURL(req, cfg.port);
1117
- res.redirect(tinyDomain + result.redirect);
1118
- }
1119
- }
1120
- // Nope
1121
- else
1122
- tinyCfg.errorCallback({ code: 401, message: 'This email is not a verified email!' }, req, res);
1123
- }
1124
- // Command
1125
- else if (result.state.type === 'login_command') {
1126
- // Verified
1127
- if (!tinyCfg.needEmailVerified || result.user.verified) {
1128
- // Set Cookie Session
1129
- discordSession.set(req, result.tokenRequest, '_command');
1130
- // Get Domain
1131
- const tinyDomain = getDomainURL(req, cfg.port);
1132
- res.redirect(tinyDomain + result.redirect);
1133
- }
1134
- // Nope
1135
- else
1136
- tinyCfg.errorCallback({ code: 401, message: 'This email is not a verified email!' }, req, res);
1137
- }
1138
- // Normal Redirect
1139
- else {
1140
- if (typeof tinyCfg.redirect[result.state.type] === 'function')
1141
- tinyCfg.redirect[result.state.type](result, req, res);
1142
- // Nope
1143
- else {
1144
- // Get Domain
1145
- const tinyDomain = getDomainURL(req, cfg.port);
1146
- res.redirect(tinyDomain + result.redirect);
1147
- }
1148
- }
1149
- })
1150
- .catch((err) => {
1151
- tinyCfg.errorCallback(err, req, res);
1152
- });
1153
- });
1154
- // Complete
1155
- return final_functions;
1156
- }
1157
- // Nope
1158
- else
1159
- throw new Error('Invalid Config Value!');
1160
- }