tiny-essentials 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (302) hide show
  1. package/.github/FUNDING.yml +4 -0
  2. package/.github/workflows/node.js.yml +31 -0
  3. package/LICENSE +674 -0
  4. package/README.md +67 -0
  5. package/dist/TinyEssentials.min.js +1 -0
  6. package/dist/_virtual/_commonjsHelpers.cjs +7 -0
  7. package/dist/_virtual/common.cjs +5 -0
  8. package/dist/_virtual/index.cjs +9 -0
  9. package/dist/_virtual/index2.cjs +5 -0
  10. package/dist/_virtual/trace.cjs +5 -0
  11. package/dist/legacy/crypto/decrypt.cjs +57 -0
  12. package/dist/legacy/crypto/decrypt.d.mts +18 -0
  13. package/dist/legacy/crypto/decrypt.mjs +47 -0
  14. package/dist/legacy/crypto/default.cjs +23 -0
  15. package/dist/legacy/crypto/default.d.mts +35 -0
  16. package/dist/legacy/crypto/default.mjs +19 -0
  17. package/dist/legacy/crypto/encrypt.cjs +54 -0
  18. package/dist/legacy/crypto/encrypt.d.mts +19 -0
  19. package/dist/legacy/crypto/encrypt.mjs +46 -0
  20. package/dist/legacy/crypto/index.cjs +11 -0
  21. package/dist/legacy/crypto/index.d.mts +4 -0
  22. package/dist/legacy/crypto/index.mjs +6 -0
  23. package/dist/legacy/firebase/cookieSession.cjs +121 -0
  24. package/dist/legacy/firebase/cookieSession.d.mts +56 -0
  25. package/dist/legacy/firebase/cookieSession.mjs +114 -0
  26. package/dist/legacy/firebase/database/index.cjs +11 -0
  27. package/dist/legacy/firebase/database/index.d.mts +7 -0
  28. package/dist/legacy/firebase/database/index.mjs +7 -0
  29. package/dist/legacy/firebase/database/presence.cjs +131 -0
  30. package/dist/legacy/firebase/database/presence.d.mts +9 -0
  31. package/dist/legacy/firebase/database/presence.mjs +111 -0
  32. package/dist/legacy/firebase/database/saveAsync.cjs +147 -0
  33. package/dist/legacy/firebase/database/saveAsync.d.mts +54 -0
  34. package/dist/legacy/firebase/database/saveAsync.mjs +147 -0
  35. package/dist/legacy/firebase/databaseEscape.cjs +42 -0
  36. package/dist/legacy/firebase/databaseEscape.d.mts +11 -0
  37. package/dist/legacy/firebase/databaseEscape.mjs +37 -0
  38. package/dist/legacy/firebase/databaseLogger.cjs +258 -0
  39. package/dist/legacy/firebase/databaseLogger.d.mts +7 -0
  40. package/dist/legacy/firebase/databaseLogger.mjs +234 -0
  41. package/dist/legacy/firebase/discord/api/addGuildMember.cjs +71 -0
  42. package/dist/legacy/firebase/discord/api/addGuildMember.d.mts +38 -0
  43. package/dist/legacy/firebase/discord/api/addGuildMember.mjs +64 -0
  44. package/dist/legacy/firebase/discord/api/getGuildWidget.cjs +47 -0
  45. package/dist/legacy/firebase/discord/api/getGuildWidget.d.mts +17 -0
  46. package/dist/legacy/firebase/discord/api/getGuildWidget.mjs +43 -0
  47. package/dist/legacy/firebase/discord/api/getToken.cjs +67 -0
  48. package/dist/legacy/firebase/discord/api/getToken.d.mts +35 -0
  49. package/dist/legacy/firebase/discord/api/getToken.mjs +63 -0
  50. package/dist/legacy/firebase/discord/api/getUser.cjs +58 -0
  51. package/dist/legacy/firebase/discord/api/getUser.d.mts +27 -0
  52. package/dist/legacy/firebase/discord/api/getUser.mjs +54 -0
  53. package/dist/legacy/firebase/discord/api/getUserConnections.cjs +57 -0
  54. package/dist/legacy/firebase/discord/api/getUserConnections.d.mts +26 -0
  55. package/dist/legacy/firebase/discord/api/getUserConnections.mjs +53 -0
  56. package/dist/legacy/firebase/discord/api/getUserGuilds.cjs +56 -0
  57. package/dist/legacy/firebase/discord/api/getUserGuilds.d.mts +25 -0
  58. package/dist/legacy/firebase/discord/api/getUserGuilds.mjs +52 -0
  59. package/dist/legacy/firebase/discord/api/index.cjs +24 -0
  60. package/dist/legacy/firebase/discord/api/index.d.mts +19 -0
  61. package/dist/legacy/firebase/discord/api/index.mjs +20 -0
  62. package/dist/legacy/firebase/discord/api/refreshToken.cjs +77 -0
  63. package/dist/legacy/firebase/discord/api/refreshToken.d.mts +45 -0
  64. package/dist/legacy/firebase/discord/api/refreshToken.mjs +73 -0
  65. package/dist/legacy/firebase/discord/api/revokeToken.cjs +61 -0
  66. package/dist/legacy/firebase/discord/api/revokeToken.d.mts +29 -0
  67. package/dist/legacy/firebase/discord/api/revokeToken.mjs +58 -0
  68. package/dist/legacy/firebase/discord/config.cjs +21 -0
  69. package/dist/legacy/firebase/discord/config.d.mts +27 -0
  70. package/dist/legacy/firebase/discord/config.mjs +17 -0
  71. package/dist/legacy/firebase/discord/firebase_redirect/index.cjs +11 -0
  72. package/dist/legacy/firebase/discord/firebase_redirect/index.d.mts +7 -0
  73. package/dist/legacy/firebase/discord/firebase_redirect/index.mjs +7 -0
  74. package/dist/legacy/firebase/discord/firebase_redirect/login.cjs +110 -0
  75. package/dist/legacy/firebase/discord/firebase_redirect/login.d.mts +4 -0
  76. package/dist/legacy/firebase/discord/firebase_redirect/login.mjs +107 -0
  77. package/dist/legacy/firebase/discord/firebase_redirect/logout.cjs +100 -0
  78. package/dist/legacy/firebase/discord/firebase_redirect/logout.d.mts +4 -0
  79. package/dist/legacy/firebase/discord/firebase_redirect/logout.mjs +97 -0
  80. package/dist/legacy/firebase/discord/get/authURLGenerator.cjs +76 -0
  81. package/dist/legacy/firebase/discord/get/authURLGenerator.d.mts +23 -0
  82. package/dist/legacy/firebase/discord/get/authURLGenerator.mjs +67 -0
  83. package/dist/legacy/firebase/discord/get/cookie-session.cjs +32 -0
  84. package/dist/legacy/firebase/discord/get/cookie-session.d.mts +20 -0
  85. package/dist/legacy/firebase/discord/get/cookie-session.mjs +28 -0
  86. package/dist/legacy/firebase/discord/get/credentials.cjs +24 -0
  87. package/dist/legacy/firebase/discord/get/credentials.d.mts +19 -0
  88. package/dist/legacy/firebase/discord/get/credentials.mjs +20 -0
  89. package/dist/legacy/firebase/discord/get/errorValidator.cjs +60 -0
  90. package/dist/legacy/firebase/discord/get/errorValidator.d.mts +28 -0
  91. package/dist/legacy/firebase/discord/get/errorValidator.mjs +55 -0
  92. package/dist/legacy/firebase/discord/get/index.cjs +17 -0
  93. package/dist/legacy/firebase/discord/get/index.d.mts +13 -0
  94. package/dist/legacy/firebase/discord/get/index.mjs +13 -0
  95. package/dist/legacy/firebase/discord/get/randomAvatar.cjs +37 -0
  96. package/dist/legacy/firebase/discord/get/randomAvatar.d.mts +22 -0
  97. package/dist/legacy/firebase/discord/get/randomAvatar.mjs +30 -0
  98. package/dist/legacy/firebase/discord/http/index.cjs +15 -0
  99. package/dist/legacy/firebase/discord/http/index.d.mts +11 -0
  100. package/dist/legacy/firebase/discord/http/index.mjs +11 -0
  101. package/dist/legacy/firebase/discord/http/login.cjs +127 -0
  102. package/dist/legacy/firebase/discord/http/login.d.mts +21 -0
  103. package/dist/legacy/firebase/discord/http/login.mjs +123 -0
  104. package/dist/legacy/firebase/discord/http/logout.cjs +155 -0
  105. package/dist/legacy/firebase/discord/http/logout.d.mts +22 -0
  106. package/dist/legacy/firebase/discord/http/logout.mjs +143 -0
  107. package/dist/legacy/firebase/discord/http/redirect.cjs +188 -0
  108. package/dist/legacy/firebase/discord/http/redirect.d.mts +24 -0
  109. package/dist/legacy/firebase/discord/http/redirect.mjs +178 -0
  110. package/dist/legacy/firebase/discord/http/refreshToken.cjs +133 -0
  111. package/dist/legacy/firebase/discord/http/refreshToken.d.mts +24 -0
  112. package/dist/legacy/firebase/discord/http/refreshToken.mjs +121 -0
  113. package/dist/legacy/firebase/discord/index.cjs +19 -0
  114. package/dist/legacy/firebase/discord/index.d.mts +15 -0
  115. package/dist/legacy/firebase/discord/index.mjs +15 -0
  116. package/dist/legacy/firebase/discord/template/cookie-session.cjs +1430 -0
  117. package/dist/legacy/firebase/discord/template/cookie-session.d.mts +22 -0
  118. package/dist/legacy/firebase/discord/template/cookie-session.mjs +1159 -0
  119. package/dist/legacy/firebase/domainRedirect.cjs +35 -0
  120. package/dist/legacy/firebase/domainRedirect.d.mts +12 -0
  121. package/dist/legacy/firebase/domainRedirect.mjs +27 -0
  122. package/dist/legacy/firebase/escape.cjs +75 -0
  123. package/dist/legacy/firebase/escape.d.mts +17 -0
  124. package/dist/legacy/firebase/escape.mjs +58 -0
  125. package/dist/legacy/firebase/getDBAsync.cjs +33 -0
  126. package/dist/legacy/firebase/getDBAsync.d.mts +10 -0
  127. package/dist/legacy/firebase/getDBAsync.mjs +26 -0
  128. package/dist/legacy/firebase/getDBData.cjs +21 -0
  129. package/dist/legacy/firebase/getDBData.d.mts +1 -0
  130. package/dist/legacy/firebase/getDBData.mjs +17 -0
  131. package/dist/legacy/firebase/getDBValue.cjs +17 -0
  132. package/dist/legacy/firebase/getDBValue.d.mts +9 -0
  133. package/dist/legacy/firebase/getDBValue.mjs +14 -0
  134. package/dist/legacy/firebase/index.cjs +261 -0
  135. package/dist/legacy/firebase/index.d.mts +51 -0
  136. package/dist/legacy/firebase/index.mjs +234 -0
  137. package/dist/legacy/firebase/isEmulator.cjs +14 -0
  138. package/dist/legacy/firebase/isEmulator.d.mts +8 -0
  139. package/dist/legacy/firebase/isEmulator.mjs +10 -0
  140. package/dist/legacy/firebase/logger.cjs +137 -0
  141. package/dist/legacy/firebase/logger.d.mts +7 -0
  142. package/dist/legacy/firebase/logger.mjs +125 -0
  143. package/dist/legacy/firebase/mySQL.cjs +26 -0
  144. package/dist/legacy/firebase/mySQL.d.mts +10 -0
  145. package/dist/legacy/firebase/mySQL.mjs +22 -0
  146. package/dist/legacy/firebase/mysqlConnector/create.cjs +119 -0
  147. package/dist/legacy/firebase/mysqlConnector/create.d.mts +36 -0
  148. package/dist/legacy/firebase/mysqlConnector/create.mjs +109 -0
  149. package/dist/legacy/firebase/mysqlConnector/index.cjs +23 -0
  150. package/dist/legacy/firebase/mysqlConnector/index.d.mts +11 -0
  151. package/dist/legacy/firebase/mysqlConnector/index.mjs +16 -0
  152. package/dist/legacy/firebase/mysqlConnector/nextPrev.cjs +75 -0
  153. package/dist/legacy/firebase/mysqlConnector/nextPrev.d.mts +31 -0
  154. package/dist/legacy/firebase/mysqlConnector/nextPrev.mjs +63 -0
  155. package/dist/legacy/firebase/mysqlConnector/pagination.cjs +91 -0
  156. package/dist/legacy/firebase/mysqlConnector/pagination.d.mts +33 -0
  157. package/dist/legacy/firebase/mysqlConnector/pagination.mjs +87 -0
  158. package/dist/legacy/firebase/mysqlConnector/sameUser.cjs +28 -0
  159. package/dist/legacy/firebase/mysqlConnector/sameUser.d.mts +12 -0
  160. package/dist/legacy/firebase/mysqlConnector/sameUser.mjs +23 -0
  161. package/dist/legacy/firebase/transactionDBAsync.cjs +33 -0
  162. package/dist/legacy/firebase/transactionDBAsync.d.mts +11 -0
  163. package/dist/legacy/firebase/transactionDBAsync.mjs +27 -0
  164. package/dist/legacy/get/countObj.cjs +24 -0
  165. package/dist/legacy/get/countObj.d.mts +11 -0
  166. package/dist/legacy/get/countObj.mjs +21 -0
  167. package/dist/legacy/get/decimalColor.cjs +60 -0
  168. package/dist/legacy/get/decimalColor.d.mts +12 -0
  169. package/dist/legacy/get/decimalColor.mjs +54 -0
  170. package/dist/legacy/get/objType.cjs +43 -0
  171. package/dist/legacy/get/objType.d.mts +19 -0
  172. package/dist/legacy/get/objType.mjs +40 -0
  173. package/dist/legacy/get/pagination.cjs +100 -0
  174. package/dist/legacy/get/pagination.d.mts +25 -0
  175. package/dist/legacy/get/pagination.mjs +91 -0
  176. package/dist/legacy/get/queryUrlByName.cjs +31 -0
  177. package/dist/legacy/get/queryUrlByName.d.mts +20 -0
  178. package/dist/legacy/get/queryUrlByName.mjs +28 -0
  179. package/dist/legacy/get/queryUrlJSON.cjs +54 -0
  180. package/dist/legacy/get/queryUrlJSON.d.mts +23 -0
  181. package/dist/legacy/get/queryUrlJSON.mjs +57 -0
  182. package/dist/legacy/get/super_string_filter.cjs +97 -0
  183. package/dist/legacy/get/super_string_filter.d.mts +25 -0
  184. package/dist/legacy/get/super_string_filter.mjs +83 -0
  185. package/dist/legacy/get/versionCheck.cjs +49 -0
  186. package/dist/legacy/get/versionCheck.d.mts +17 -0
  187. package/dist/legacy/get/versionCheck.mjs +38 -0
  188. package/dist/legacy/http/HTTP-1.0.cjs +151 -0
  189. package/dist/legacy/http/HTTP-1.0.d.mts +8 -0
  190. package/dist/legacy/http/HTTP-1.0.mjs +136 -0
  191. package/dist/legacy/http/auth.cjs +70 -0
  192. package/dist/legacy/http/auth.d.mts +41 -0
  193. package/dist/legacy/http/auth.mjs +63 -0
  194. package/dist/legacy/http/check_domain.cjs +84 -0
  195. package/dist/legacy/http/check_domain.d.mts +10 -0
  196. package/dist/legacy/http/check_domain.mjs +82 -0
  197. package/dist/legacy/http/csrfTokenAnalyze.cjs +46 -0
  198. package/dist/legacy/http/csrfTokenAnalyze.d.mts +21 -0
  199. package/dist/legacy/http/csrfTokenAnalyze.mjs +40 -0
  200. package/dist/legacy/http/domainValidator.cjs +98 -0
  201. package/dist/legacy/http/domainValidator.d.mts +30 -0
  202. package/dist/legacy/http/domainValidator.mjs +82 -0
  203. package/dist/legacy/http/errorsCallback.cjs +55 -0
  204. package/dist/legacy/http/errorsCallback.d.mts +29 -0
  205. package/dist/legacy/http/errorsCallback.mjs +48 -0
  206. package/dist/legacy/http/fetch/json.cjs +48 -0
  207. package/dist/legacy/http/fetch/json.d.mts +22 -0
  208. package/dist/legacy/http/fetch/json.mjs +41 -0
  209. package/dist/legacy/http/fetch/text.cjs +47 -0
  210. package/dist/legacy/http/fetch/text.d.mts +21 -0
  211. package/dist/legacy/http/fetch/text.mjs +40 -0
  212. package/dist/legacy/http/fileCache.cjs +79 -0
  213. package/dist/legacy/http/fileCache.d.mts +35 -0
  214. package/dist/legacy/http/fileCache.mjs +70 -0
  215. package/dist/legacy/http/getDomainURL.cjs +59 -0
  216. package/dist/legacy/http/getDomainURL.d.mts +18 -0
  217. package/dist/legacy/http/getDomainURL.mjs +54 -0
  218. package/dist/legacy/http/userIP.cjs +59 -0
  219. package/dist/legacy/http/userIP.d.mts +21 -0
  220. package/dist/legacy/http/userIP.mjs +48 -0
  221. package/dist/legacy/index.cjs +122 -0
  222. package/dist/legacy/index.d.mts +89 -0
  223. package/dist/legacy/index.mjs +92 -0
  224. package/dist/legacy/libs/arraySortPositions.cjs +30 -0
  225. package/dist/legacy/libs/arraySortPositions.d.mts +16 -0
  226. package/dist/legacy/libs/arraySortPositions.mjs +27 -0
  227. package/dist/legacy/libs/capitalize.cjs +21 -0
  228. package/dist/legacy/libs/capitalize.d.mts +13 -0
  229. package/dist/legacy/libs/capitalize.mjs +17 -0
  230. package/dist/legacy/libs/convertBytes.cjs +64 -0
  231. package/dist/legacy/libs/convertBytes.d.mts +17 -0
  232. package/dist/legacy/libs/convertBytes.mjs +55 -0
  233. package/dist/legacy/libs/custom_module_loader.cjs +82 -0
  234. package/dist/legacy/libs/custom_module_loader.d.mts +5 -0
  235. package/dist/legacy/libs/custom_module_loader.mjs +79 -0
  236. package/dist/legacy/libs/dice.cjs +35 -0
  237. package/dist/legacy/libs/dice.d.mts +5 -0
  238. package/dist/legacy/libs/dice.mjs +31 -0
  239. package/dist/legacy/libs/markdown.cjs +85 -0
  240. package/dist/legacy/libs/markdown.d.mts +75 -0
  241. package/dist/legacy/libs/markdown.mjs +78 -0
  242. package/dist/legacy/libs/percentage.cjs +22 -0
  243. package/dist/legacy/libs/percentage.d.mts +4 -0
  244. package/dist/legacy/libs/percentage.mjs +19 -0
  245. package/dist/legacy/libs/regex/getLetter.cjs +22 -0
  246. package/dist/legacy/libs/regex/getLetter.d.mts +12 -0
  247. package/dist/legacy/libs/regex/getLetter.mjs +19 -0
  248. package/dist/legacy/libs/replaceAsync.cjs +32 -0
  249. package/dist/legacy/libs/replaceAsync.d.mts +15 -0
  250. package/dist/legacy/libs/replaceAsync.mjs +25 -0
  251. package/dist/legacy/libs/rule3.cjs +58 -0
  252. package/dist/legacy/libs/rule3.d.mts +5 -0
  253. package/dist/legacy/libs/rule3.mjs +54 -0
  254. package/dist/legacy/libs/userLevel.cjs +134 -0
  255. package/dist/legacy/libs/userLevel.d.mts +69 -0
  256. package/dist/legacy/libs/userLevel.mjs +123 -0
  257. package/dist/legacy/momentjs/getAge.cjs +28 -0
  258. package/dist/legacy/momentjs/getAge.d.mts +8 -0
  259. package/dist/legacy/momentjs/getAge.mjs +22 -0
  260. package/dist/legacy/momentjs/index.cjs +9 -0
  261. package/dist/legacy/momentjs/index.d.mts +3 -0
  262. package/dist/legacy/momentjs/index.mjs +3 -0
  263. package/dist/legacy/momentjs/timeDuration.cjs +29 -0
  264. package/dist/legacy/momentjs/timeDuration.d.mts +9 -0
  265. package/dist/legacy/momentjs/timeDuration.mjs +23 -0
  266. package/dist/legacy/socket.io/antiFlood/index.cjs +9 -0
  267. package/dist/legacy/socket.io/antiFlood/index.d.mts +3 -0
  268. package/dist/legacy/socket.io/antiFlood/index.mjs +3 -0
  269. package/dist/legacy/socket.io/antiFlood/install.cjs +32 -0
  270. package/dist/legacy/socket.io/antiFlood/install.d.mts +14 -0
  271. package/dist/legacy/socket.io/antiFlood/install.mjs +27 -0
  272. package/dist/legacy/socket.io/antiFlood/verify.cjs +87 -0
  273. package/dist/legacy/socket.io/antiFlood/verify.d.mts +15 -0
  274. package/dist/legacy/socket.io/antiFlood/verify.mjs +73 -0
  275. package/dist/legacy/socket.io/cookie-session.cjs +25 -0
  276. package/dist/legacy/socket.io/cookie-session.d.mts +9 -0
  277. package/dist/legacy/socket.io/cookie-session.mjs +20 -0
  278. package/dist/legacy/socket.io/discord.cjs +61 -0
  279. package/dist/legacy/socket.io/discord.d.mts +10 -0
  280. package/dist/legacy/socket.io/discord.mjs +52 -0
  281. package/dist/legacy/socket.io/index.cjs +13 -0
  282. package/dist/legacy/socket.io/index.d.mts +9 -0
  283. package/dist/legacy/socket.io/index.mjs +9 -0
  284. package/dist/v1/basics/array.cjs +31 -0
  285. package/dist/v1/basics/array.d.mts +10 -0
  286. package/dist/v1/basics/array.mjs +22 -0
  287. package/dist/v1/basics/clock.cjs +187 -0
  288. package/dist/v1/basics/clock.d.mts +37 -0
  289. package/dist/v1/basics/clock.mjs +152 -0
  290. package/dist/v1/basics/objFilter.cjs +55 -0
  291. package/dist/v1/basics/objFilter.d.mts +27 -0
  292. package/dist/v1/basics/objFilter.mjs +52 -0
  293. package/dist/v1/basics/simpleMath.cjs +88 -0
  294. package/dist/v1/basics/simpleMath.d.mts +54 -0
  295. package/dist/v1/basics/simpleMath.mjs +75 -0
  296. package/dist/v1/basics/text.cjs +34 -0
  297. package/dist/v1/basics/text.d.mts +20 -0
  298. package/dist/v1/basics/text.mjs +25 -0
  299. package/dist/v1/index.cjs +26 -0
  300. package/dist/v1/index.d.mts +15 -0
  301. package/dist/v1/index.mjs +8 -0
  302. package/package.json +72 -0
@@ -0,0 +1,35 @@
1
+ 'use strict';
2
+
3
+ // https://stackoverflow.com/questions/34212039/redirect-to-firebase-hosting-custom-domain
4
+
5
+ /**
6
+ * Redirects requests from invalid domains to a specified base URL or calls a callback function.
7
+ * This middleware checks the 'x-forwarded-host' header of incoming requests and compares it to a list of valid domains.
8
+ * If the domain is invalid, it either redirects to the base URL or calls a provided callback.
9
+ *
10
+ * @param {string[]} [domains=['localhost:5000', 'example.com']] - A list of valid domains that the request must come from.
11
+ * @param {string} [baseurl='https://example.com/'] - The URL to redirect invalid requests to.
12
+ * @param {Function} [callback] - An optional callback function that is called when an invalid domain is detected.
13
+ *
14
+ * @returns {Function} A middleware function for use in an Express.js application.
15
+ */
16
+ function domainRedirect(
17
+ domains = ['localhost:5000', 'example.com'],
18
+ baseurl = 'https://example.com/',
19
+ callback,
20
+ ) {
21
+ return (req, res, next) => {
22
+ // Invalid Domain Detected
23
+ if (!domains.includes(req.headers['x-forwarded-host'])) {
24
+ // No Callback
25
+ if (typeof callback !== 'function') return res.status(301).redirect(baseurl + req.url);
26
+ // Yes
27
+ else callback(req, res, next);
28
+ }
29
+
30
+ // Complete
31
+ return next();
32
+ };
33
+ }
34
+
35
+ module.exports = domainRedirect;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Redirects requests from invalid domains to a specified base URL or calls a callback function.
3
+ * This middleware checks the 'x-forwarded-host' header of incoming requests and compares it to a list of valid domains.
4
+ * If the domain is invalid, it either redirects to the base URL or calls a provided callback.
5
+ *
6
+ * @param {string[]} [domains=['localhost:5000', 'example.com']] - A list of valid domains that the request must come from.
7
+ * @param {string} [baseurl='https://example.com/'] - The URL to redirect invalid requests to.
8
+ * @param {Function} [callback] - An optional callback function that is called when an invalid domain is detected.
9
+ *
10
+ * @returns {Function} A middleware function for use in an Express.js application.
11
+ */
12
+ export default function domainRedirect(domains?: string[], baseurl?: string, callback?: Function): Function;
@@ -0,0 +1,27 @@
1
+ // https://stackoverflow.com/questions/34212039/redirect-to-firebase-hosting-custom-domain
2
+ /**
3
+ * Redirects requests from invalid domains to a specified base URL or calls a callback function.
4
+ * This middleware checks the 'x-forwarded-host' header of incoming requests and compares it to a list of valid domains.
5
+ * If the domain is invalid, it either redirects to the base URL or calls a provided callback.
6
+ *
7
+ * @param {string[]} [domains=['localhost:5000', 'example.com']] - A list of valid domains that the request must come from.
8
+ * @param {string} [baseurl='https://example.com/'] - The URL to redirect invalid requests to.
9
+ * @param {Function} [callback] - An optional callback function that is called when an invalid domain is detected.
10
+ *
11
+ * @returns {Function} A middleware function for use in an Express.js application.
12
+ */
13
+ export default function domainRedirect(domains = ['localhost:5000', 'example.com'], baseurl = 'https://example.com/', callback) {
14
+ return (req, res, next) => {
15
+ // Invalid Domain Detected
16
+ if (!domains.includes(req.headers['x-forwarded-host'])) {
17
+ // No Callback
18
+ if (typeof callback !== 'function')
19
+ return res.status(301).redirect(baseurl + req.url);
20
+ // Yes
21
+ else
22
+ callback(req, res, next);
23
+ }
24
+ // Complete
25
+ return next();
26
+ };
27
+ }
@@ -0,0 +1,75 @@
1
+ 'use strict';
2
+
3
+ // Credits
4
+ // https://github.com/joonhocho/firebase-encode/blob/master/src/index.js
5
+
6
+ // http://stackoverflow.com/a/6969486/692528
7
+
8
+ /**
9
+ * Escapes special characters in a string to make them safe for use in regular expressions.
10
+ *
11
+ * @param {string} str - The string to escape.
12
+ * @returns {string} The escaped string.
13
+ */
14
+ const escapeRegExp = (str) => str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
15
+
16
+ /**
17
+ * Creates encoding and decoding functions for custom characters.
18
+ *
19
+ * This function returns two pairs of functions: one for encoding and decoding
20
+ * the characters to/from their hexadecimal representations and another for encoding
21
+ * and decoding components (without the `/` character).
22
+ *
23
+ * @param {Array<string>} chars - The list of characters to encode/decode.
24
+ * @returns {Object} An object containing:
25
+ * - `encode`: Function that encodes characters to hexadecimal format.
26
+ * - `decode`: Function that decodes hexadecimal values back to characters.
27
+ */
28
+ const create = (chars) => {
29
+ // Map characters to their hexadecimal representations
30
+ const charCodes = chars.map((c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`);
31
+
32
+ // Maps to convert between character and hexadecimal code
33
+ const charToCode = {};
34
+ const codeToChar = {};
35
+
36
+ chars.forEach((c, i) => {
37
+ charToCode[c] = charCodes[i];
38
+ codeToChar[charCodes[i]] = c;
39
+ });
40
+
41
+ // Regex for matching characters and their corresponding hex codes
42
+ const charsRegex = new RegExp(`[${escapeRegExp(chars.join(''))}]`, 'g');
43
+ const charCodesRegex = new RegExp(charCodes.join('|'), 'g');
44
+
45
+ /**
46
+ * Encodes a string by replacing its characters with their corresponding hexadecimal codes.
47
+ *
48
+ * @param {string} str - The string to encode.
49
+ * @returns {string} The encoded string.
50
+ */
51
+ const encode = (str) => str.replace(charsRegex, (match) => charToCode[match]);
52
+
53
+ /**
54
+ * Decodes a string by replacing its hexadecimal codes with their corresponding characters.
55
+ *
56
+ * @param {string} str - The string to decode.
57
+ * @returns {string} The decoded string.
58
+ */
59
+ const decode = (str) => str.replace(charCodesRegex, (match) => codeToChar[match]);
60
+
61
+ return { encode, decode };
62
+ };
63
+
64
+ // http://stackoverflow.com/a/19148116/692528
65
+ // Create encode and decode functions for specific characters.
66
+ const { encode, decode } = create('.$[]#/%'.split(''));
67
+
68
+ // Create encode and decode functions for components (without `/`).
69
+ const { encode: encodeComponents, decode: decodeComponents } = create('.$[]#%'.split(''));
70
+
71
+ exports.create = create;
72
+ exports.decode = decode;
73
+ exports.decodeComponents = decodeComponents;
74
+ exports.encode = encode;
75
+ exports.encodeComponents = encodeComponents;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Creates encoding and decoding functions for custom characters.
3
+ *
4
+ * This function returns two pairs of functions: one for encoding and decoding
5
+ * the characters to/from their hexadecimal representations and another for encoding
6
+ * and decoding components (without the `/` character).
7
+ *
8
+ * @param {Array<string>} chars - The list of characters to encode/decode.
9
+ * @returns {Object} An object containing:
10
+ * - `encode`: Function that encodes characters to hexadecimal format.
11
+ * - `decode`: Function that decodes hexadecimal values back to characters.
12
+ */
13
+ export function create(chars: Array<string>): Object;
14
+ export const encode: any;
15
+ export const decode: any;
16
+ export const encodeComponents: any;
17
+ export const decodeComponents: any;
@@ -0,0 +1,58 @@
1
+ // Credits
2
+ // https://github.com/joonhocho/firebase-encode/blob/master/src/index.js
3
+ // http://stackoverflow.com/a/6969486/692528
4
+ /**
5
+ * Escapes special characters in a string to make them safe for use in regular expressions.
6
+ *
7
+ * @param {string} str - The string to escape.
8
+ * @returns {string} The escaped string.
9
+ */
10
+ const escapeRegExp = (str) => str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
11
+ /**
12
+ * Creates encoding and decoding functions for custom characters.
13
+ *
14
+ * This function returns two pairs of functions: one for encoding and decoding
15
+ * the characters to/from their hexadecimal representations and another for encoding
16
+ * and decoding components (without the `/` character).
17
+ *
18
+ * @param {Array<string>} chars - The list of characters to encode/decode.
19
+ * @returns {Object} An object containing:
20
+ * - `encode`: Function that encodes characters to hexadecimal format.
21
+ * - `decode`: Function that decodes hexadecimal values back to characters.
22
+ */
23
+ const create = (chars) => {
24
+ // Map characters to their hexadecimal representations
25
+ const charCodes = chars.map((c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`);
26
+ // Maps to convert between character and hexadecimal code
27
+ const charToCode = {};
28
+ const codeToChar = {};
29
+ chars.forEach((c, i) => {
30
+ charToCode[c] = charCodes[i];
31
+ codeToChar[charCodes[i]] = c;
32
+ });
33
+ // Regex for matching characters and their corresponding hex codes
34
+ const charsRegex = new RegExp(`[${escapeRegExp(chars.join(''))}]`, 'g');
35
+ const charCodesRegex = new RegExp(charCodes.join('|'), 'g');
36
+ /**
37
+ * Encodes a string by replacing its characters with their corresponding hexadecimal codes.
38
+ *
39
+ * @param {string} str - The string to encode.
40
+ * @returns {string} The encoded string.
41
+ */
42
+ const encode = (str) => str.replace(charsRegex, (match) => charToCode[match]);
43
+ /**
44
+ * Decodes a string by replacing its hexadecimal codes with their corresponding characters.
45
+ *
46
+ * @param {string} str - The string to decode.
47
+ * @returns {string} The decoded string.
48
+ */
49
+ const decode = (str) => str.replace(charCodesRegex, (match) => codeToChar[match]);
50
+ return { encode, decode };
51
+ };
52
+ // http://stackoverflow.com/a/19148116/692528
53
+ // Create encode and decode functions for specific characters.
54
+ const { encode, decode } = create('.$[]#/%'.split(''));
55
+ // Create encode and decode functions for components (without `/`).
56
+ const { encode: encodeComponents, decode: decodeComponents } = create('.$[]#%'.split(''));
57
+ // Export the functions for use.
58
+ export { create, encode, decode, encodeComponents, decodeComponents };
@@ -0,0 +1,33 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Fetches data from a Firebase database asynchronously using the specified event type.
5
+ * This function wraps the Firebase database `once` method in a Promise, allowing asynchronous handling of database responses.
6
+ *
7
+ * @param {firebase.database.Reference} data - The Firebase database reference from which to retrieve data.
8
+ * @param {string} [type='value'] - The event type to listen for (e.g., 'value', 'child_added', 'child_changed', etc.).
9
+ * @returns {Promise<firebase.database.DataSnapshot>} A promise that resolves with the snapshot data when the request is successful.
10
+ * @throws {Error} If an error occurs during the database operation, the promise will be rejected with the error.
11
+ */
12
+ function getDBAsync(data, type = 'value') {
13
+ return new Promise(function (resolve, reject) {
14
+ // Try
15
+ try {
16
+ // Run Data
17
+ data.once(
18
+ type,
19
+ function (snapshot) {
20
+ resolve(snapshot);
21
+ },
22
+ function (errorObject) {
23
+ reject(errorObject);
24
+ },
25
+ );
26
+ } catch (err) {
27
+ // Error
28
+ reject(err);
29
+ }
30
+ });
31
+ }
32
+
33
+ module.exports = getDBAsync;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Fetches data from a Firebase database asynchronously using the specified event type.
3
+ * This function wraps the Firebase database `once` method in a Promise, allowing asynchronous handling of database responses.
4
+ *
5
+ * @param {firebase.database.Reference} data - The Firebase database reference from which to retrieve data.
6
+ * @param {string} [type='value'] - The event type to listen for (e.g., 'value', 'child_added', 'child_changed', etc.).
7
+ * @returns {Promise<firebase.database.DataSnapshot>} A promise that resolves with the snapshot data when the request is successful.
8
+ * @throws {Error} If an error occurs during the database operation, the promise will be rejected with the error.
9
+ */
10
+ export default function getDBAsync(data: firebase.database.Reference, type?: string): Promise<firebase.database.DataSnapshot>;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Fetches data from a Firebase database asynchronously using the specified event type.
3
+ * This function wraps the Firebase database `once` method in a Promise, allowing asynchronous handling of database responses.
4
+ *
5
+ * @param {firebase.database.Reference} data - The Firebase database reference from which to retrieve data.
6
+ * @param {string} [type='value'] - The event type to listen for (e.g., 'value', 'child_added', 'child_changed', etc.).
7
+ * @returns {Promise<firebase.database.DataSnapshot>} A promise that resolves with the snapshot data when the request is successful.
8
+ * @throws {Error} If an error occurs during the database operation, the promise will be rejected with the error.
9
+ */
10
+ export default function getDBAsync(data, type = 'value') {
11
+ return new Promise(function (resolve, reject) {
12
+ // Try
13
+ try {
14
+ // Run Data
15
+ data.once(type, function (snapshot) {
16
+ resolve(snapshot);
17
+ }, function (errorObject) {
18
+ reject(errorObject);
19
+ });
20
+ }
21
+ catch (err) {
22
+ // Error
23
+ reject(err);
24
+ }
25
+ });
26
+ }
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ var getDBAsync = require('./getDBAsync.cjs');
4
+ var getDBValue = require('./getDBValue.cjs');
5
+
6
+ function getDBData(data, type) {
7
+ return new Promise(function (resolve, reject) {
8
+ // Try
9
+ try {
10
+ // Get Data
11
+ getDBAsync(data, type)
12
+ .then((final_data) => resolve(getDBValue(final_data)))
13
+ .catch(reject);
14
+ } catch (err) {
15
+ // Error
16
+ reject(err);
17
+ }
18
+ });
19
+ }
20
+
21
+ module.exports = getDBData;
@@ -0,0 +1 @@
1
+ export default function getDBData(data: any, type: any): Promise<any>;
@@ -0,0 +1,17 @@
1
+ import getDBAsync from './getDBAsync.mjs';
2
+ import getDBValue from './getDBValue.mjs';
3
+ export default function getDBData(data, type) {
4
+ return new Promise(function (resolve, reject) {
5
+ // Try
6
+ try {
7
+ // Get Data
8
+ getDBAsync(data, type)
9
+ .then((final_data) => resolve(getDBValue(final_data)))
10
+ .catch(reject);
11
+ }
12
+ catch (err) {
13
+ // Error
14
+ reject(err);
15
+ }
16
+ });
17
+ }
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Retrieves the value from a Firebase database snapshot.
5
+ * This function checks if the provided data object is a valid Firebase snapshot and
6
+ * calls its `.val()` method to get the actual data value.
7
+ *
8
+ * @param {firebase.database.DataSnapshot} data - The Firebase database snapshot from which to retrieve the value.
9
+ * @returns {any} The value stored in the snapshot, or `null` if the data is invalid or doesn't contain a valid value.
10
+ */
11
+ function getDBValue(data) {
12
+ let new_data = null;
13
+ if (data && typeof data.val === 'function') new_data = data.val();
14
+ return new_data;
15
+ }
16
+
17
+ module.exports = getDBValue;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Retrieves the value from a Firebase database snapshot.
3
+ * This function checks if the provided data object is a valid Firebase snapshot and
4
+ * calls its `.val()` method to get the actual data value.
5
+ *
6
+ * @param {firebase.database.DataSnapshot} data - The Firebase database snapshot from which to retrieve the value.
7
+ * @returns {any} The value stored in the snapshot, or `null` if the data is invalid or doesn't contain a valid value.
8
+ */
9
+ export default function getDBValue(data: firebase.database.DataSnapshot): any;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Retrieves the value from a Firebase database snapshot.
3
+ * This function checks if the provided data object is a valid Firebase snapshot and
4
+ * calls its `.val()` method to get the actual data value.
5
+ *
6
+ * @param {firebase.database.DataSnapshot} data - The Firebase database snapshot from which to retrieve the value.
7
+ * @returns {any} The value stored in the snapshot, or `null` if the data is invalid or doesn't contain a valid value.
8
+ */
9
+ export default function getDBValue(data) {
10
+ let new_data = null;
11
+ if (data && typeof data.val === 'function')
12
+ new_data = data.val();
13
+ return new_data;
14
+ }
@@ -0,0 +1,261 @@
1
+ 'use strict';
2
+
3
+ var path = require('path');
4
+ var fs = require('fs');
5
+ var cookieSession = require('./cookieSession.cjs');
6
+ var domainRedirect = require('./domainRedirect.cjs');
7
+ var index = require('./database/index.cjs');
8
+ var escape = require('./escape.cjs');
9
+ var mySQL = require('./mySQL.cjs');
10
+ var getDBAsync = require('./getDBAsync.cjs');
11
+ var getDBValue = require('./getDBValue.cjs');
12
+ var getDBData = require('./getDBData.cjs');
13
+ var transactionDBAsync = require('./transactionDBAsync.cjs');
14
+ var databaseEscape = require('./databaseEscape.cjs');
15
+ var isEmulator = require('./isEmulator.cjs');
16
+
17
+ /**
18
+ * Firebase Object to handle various Firebase services and utilities.
19
+ * Includes database, authentication, Firestore, storage, and more.
20
+ *
21
+ * @namespace firebaseObject
22
+ */
23
+ const firebaseObject = { apps: {} };
24
+
25
+ /**
26
+ * Retrieves a Firebase app by its identifier.
27
+ *
28
+ * @param {string|number} value - The app identifier to retrieve.
29
+ * @returns {Object|null} The Firebase app or `null` if not found.
30
+ */
31
+ firebaseObject.get = function (value) {
32
+ // Check
33
+ if ((typeof value === 'string' || typeof value === 'number') && firebaseObject.apps[value]) {
34
+ // Send Item
35
+ return firebaseObject.apps[value];
36
+ }
37
+
38
+ // Nope
39
+ else return null;
40
+ };
41
+
42
+ /**
43
+ * Manages cookie session for authentication.
44
+ *
45
+ * @type {AuthSystem}
46
+ */
47
+ firebaseObject.cookieSession = cookieSession;
48
+
49
+ /**
50
+ * Manages domain redirection.
51
+ *
52
+ * @type {domainRedirect}
53
+ */
54
+ firebaseObject.domainRedirect = domainRedirect;
55
+
56
+ /**
57
+ * Handles Firebase Database interactions.
58
+ *
59
+ * @type {database}
60
+ */
61
+ firebaseObject.database = index;
62
+
63
+ /**
64
+ * Handles database escaping for safe queries.
65
+ *
66
+ * @type {Object}
67
+ */
68
+ firebaseObject.escape = escape;
69
+
70
+ /**
71
+ * Manages MySQL database interactions.
72
+ *
73
+ * @type {mySQL}
74
+ */
75
+ firebaseObject.mysql = mySQL;
76
+
77
+ /**
78
+ * Retrieves the database asynchronously.
79
+ *
80
+ * @type {getDBAsync}
81
+ */
82
+ firebaseObject.getDBAsync = getDBAsync;
83
+
84
+ /**
85
+ * Retrieves a specific database value.
86
+ *
87
+ * @type {getDBValue}
88
+ */
89
+ firebaseObject.getDBValue = getDBValue;
90
+
91
+ /**
92
+ * Retrieves database data asynchronously.
93
+ *
94
+ * @type {getDBData}
95
+ */
96
+ firebaseObject.getDBData = getDBData;
97
+
98
+ /**
99
+ * Handles asynchronous database transactions.
100
+ *
101
+ * @type {transactionDBAsync}
102
+ */
103
+ firebaseObject.transactionDBAsync = transactionDBAsync;
104
+
105
+ /**
106
+ * Provides database escape functionality for safe querying.
107
+ *
108
+ * @type {databaseEscape}
109
+ */
110
+ firebaseObject.databaseEscape = databaseEscape;
111
+
112
+ /**
113
+ * Logger to log information using Firebase or console.
114
+ *
115
+ * @type {Object}
116
+ */
117
+ firebaseObject.logger = logger;
118
+
119
+ /**
120
+ * Checks if the Firebase environment is running in emulator mode.
121
+ *
122
+ * @type {isEmulator}
123
+ */
124
+ firebaseObject.isEmulator = isEmulator;
125
+
126
+ /**
127
+ * Starts Firebase modules based on the provided configuration.
128
+ * Initializes services such as Database, Auth, Firestore, etc.
129
+ *
130
+ * @param {string} value - The Firebase app ID.
131
+ * @param {Object} item - Configuration for the Firebase app and services to initialize.
132
+ * @returns {boolean} `true` if the modules were successfully started, `false` otherwise.
133
+ */
134
+ firebaseObject.startModule = function (value, item) {
135
+ // Check
136
+ if ((typeof value === 'string' || typeof value === 'number') && firebaseObject.apps[value]) {
137
+ // Confirm Action
138
+ let action_confirmed = false;
139
+
140
+ // Database
141
+ if (item.database) {
142
+ firebaseObject.apps[value].db = firebaseObject.apps[value].root.database();
143
+ action_confirmed = true;
144
+ }
145
+
146
+ // Auth
147
+ if (item.auth) {
148
+ firebaseObject.apps[value].auth = firebaseObject.apps[value].root.auth();
149
+ action_confirmed = true;
150
+ }
151
+
152
+ // Firestore
153
+ if (item.firestore) {
154
+ firebaseObject.apps[value].store = firebaseObject.apps[value].root.firestore();
155
+ action_confirmed = true;
156
+ }
157
+
158
+ // Storage
159
+ if (item.storage) {
160
+ firebaseObject.apps[value].storage = firebaseObject.apps[value].root.storage();
161
+ action_confirmed = true;
162
+ }
163
+
164
+ // Cloud Messaging
165
+ if (item.messaging) {
166
+ firebaseObject.apps[value].messaging = firebaseObject.apps[value].root.messaging();
167
+ action_confirmed = true;
168
+ }
169
+
170
+ // Send positive result
171
+ return action_confirmed;
172
+ }
173
+
174
+ // Nope
175
+ else return false;
176
+ };
177
+
178
+ /**
179
+ * Starts the Firebase app and initializes required services.
180
+ *
181
+ * @param {Object} admin - The Firebase Admin SDK.
182
+ * @param {Object} item - Configuration containing app details and options.
183
+ * @param {Object} data - Additional data to initialize the app.
184
+ * @throws {Error} Throws an error if the Firebase file is not found or if the app ID is missing.
185
+ */
186
+ firebaseObject.start = function (admin, item, data) {
187
+ // Try
188
+ try {
189
+ // Start Firebase
190
+ const start_firebase = function (json_file = null) {
191
+ // Check Exist
192
+ if (!firebaseObject.apps[item.id]) {
193
+ // Firebase Settings
194
+ const firebase_settings = {};
195
+
196
+ // Exist File
197
+ if (json_file) firebase_settings.credential = admin.credential.cert(json_file);
198
+
199
+ // Read Data
200
+ if (data) {
201
+ for (const data_item in data) firebase_settings[data_item] = data[data_item];
202
+ }
203
+
204
+ // Fix Database URL
205
+ if (typeof firebase_settings.databaseURL === 'string') {
206
+ if (
207
+ !firebase_settings.databaseURL.startsWith('https://') &&
208
+ !firebase_settings.databaseURL.endsWith('.firebaseio.com')
209
+ )
210
+ firebase_settings.databaseURL = `https://${firebase_settings.databaseURL}.firebaseio.com`;
211
+ }
212
+
213
+ // Fix Storage URL
214
+ if (typeof firebase_settings.storageBucket === 'string')
215
+ if (!firebase_settings.storageBucket.endsWith('.appspot.com'))
216
+ firebase_settings.storageBucket = `${firebase_settings.storageBucket}.appspot.com`;
217
+
218
+ // Prepare Base
219
+ firebaseObject.apps[item.id] = {};
220
+
221
+ // Initialize App
222
+ firebaseObject.apps[item.id].root = admin.initializeApp(firebase_settings, item.id);
223
+
224
+ // Auto Start
225
+ if (item.autoStart) firebaseObject.startModule(item.id, item.autoStart);
226
+ }
227
+ };
228
+
229
+ // Exist ID
230
+ if (item && typeof item.id === 'string' && item.id !== 'start') {
231
+ // Check Variables
232
+ if (typeof item.appID === 'string') {
233
+ // Key File
234
+ let keyFile = null;
235
+ if (item.keysFolder) keyFile = path.join(item.keysFolder, item.appID + '.json');
236
+
237
+ // Exist File
238
+ if (keyFile && fs.existsSync(keyFile) && fs.lstatSync(keyFile).isFile()) {
239
+ try {
240
+ const jsonData = fs.readFileSync(keyFile, 'utf8');
241
+ const parsedKey = JSON.parse(jsonData);
242
+ start_firebase(parsedKey);
243
+ } catch (err) {
244
+ console.error(new Error('Failed to parse Firebase JSON file: ' + err.message));
245
+ }
246
+ } else console.error(new Error('Firebase File Not Found.'));
247
+ }
248
+
249
+ // Nope
250
+ else start_firebase();
251
+ }
252
+
253
+ // Nope
254
+ else console.error(new Error('You need to insert a ID value!'));
255
+ } catch (err) {
256
+ // Get Error
257
+ console.error(err);
258
+ }
259
+ };
260
+
261
+ module.exports = firebaseObject;