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,114 @@
1
+ /**
2
+ * Class representing an authentication system for generating session cookies.
3
+ *
4
+ * The AuthSystem handles checking the authentication time and generating session cookies based on
5
+ * ID token verification. It supports custom time checking and cookie generation logic.
6
+ *
7
+ * @class AuthSystem
8
+ */
9
+ class AuthSystem {
10
+ /**
11
+ * Creates an instance of AuthSystem.
12
+ * Initializes default configurations for authentication time checking and session cookie expiration.
13
+ *
14
+ * @constructor
15
+ */
16
+ constructor() {
17
+ this.auth_time = 5;
18
+ // Default Values
19
+ const authSystem = this;
20
+ this.default = {
21
+ /**
22
+ * Checks whether the authentication time is within the last 5 minutes.
23
+ *
24
+ * @param {Object} decodedIdToken - The decoded ID token object.
25
+ * @param {number} decodedIdToken.auth_time - The authentication time from the ID token.
26
+ * @returns {boolean} Returns `true` if the authentication time is within the last 5 minutes.
27
+ */
28
+ checkAuthTime: (decodedIdToken) => {
29
+ // Only process if the user just signed in in the last {this.auth_time} minutes.
30
+ if (new Date().getTime() / 1000 - decodedIdToken.auth_time < authSystem.auth_time * 60)
31
+ return true;
32
+ // Nope
33
+ else
34
+ return false;
35
+ },
36
+ /**
37
+ * Generates the session cookie expiration time ({this.auth_time} days by default).
38
+ *
39
+ * @returns {number} Returns the expiration time in milliseconds (5 days).
40
+ */
41
+ cookieTimeGenerator: () => {
42
+ // Set session expiration to 5 days.
43
+ const expiresIn = 60 * 60 * 24 * authSystem.auth_time * 1000;
44
+ // Create the session cookie. This will also verify the ID token in the process.
45
+ // The session cookie will have the same claims as the ID token.
46
+ // To only allow session cookie setting on recent sign-in, auth_time in ID token
47
+ // can be checked to ensure user was recently signed in before creating a session cookie.
48
+ // Complete
49
+ return expiresIn;
50
+ },
51
+ };
52
+ // Set Value
53
+ this.checkAuthTime = this.default.checkAuthTime;
54
+ this.cookieTimeGenerator = this.default.cookieTimeGenerator;
55
+ }
56
+ /**
57
+ * Sets a custom callback to check authentication time.
58
+ *
59
+ * @param {Function} callback - The callback function to validate authentication time.
60
+ * @returns {void}
61
+ */
62
+ setCookieTimeGenerator(callback) {
63
+ if (typeof callback === 'function')
64
+ this.cookieTimeGenerator = callback;
65
+ }
66
+ /**
67
+ * Sets a custom callback to generate the cookie expiration time.
68
+ *
69
+ * @param {Function} callback - The callback function to generate cookie expiration time.
70
+ * @returns {void}
71
+ */
72
+ setCheckAuthTime(callback) {
73
+ if (typeof callback === 'function')
74
+ this.checkAuthTime = callback;
75
+ }
76
+ /**
77
+ * Generates a session cookie for the user after verifying the ID token.
78
+ *
79
+ * @param {Object} auth - The authentication object used to verify the ID token and create session cookies.
80
+ * @param {string} token - The ID token of the authenticated user.
81
+ * @returns {Promise<string>} A promise that resolves with the session cookie or rejects with an error.
82
+ */
83
+ genCookieSession(auth, token) {
84
+ const tinyThis = this;
85
+ return new Promise(function (resolve, reject) {
86
+ auth
87
+ .verifyIdToken(token)
88
+ .then(async (decodedIdToken) => {
89
+ try {
90
+ // Validate the authentication time
91
+ const checkedTime = await tinyThis.checkAuthTime(decodedIdToken);
92
+ if (checkedTime) {
93
+ // Generate session cookie
94
+ const expiresIn = await tinyThis.cookieTimeGenerator(decodedIdToken);
95
+ auth.createSessionCookie(token, { expiresIn }).then(resolve).catch(reject);
96
+ }
97
+ // Nope
98
+ else {
99
+ const err = new Error('Invalid Account ID Token Time.');
100
+ err.code = 401;
101
+ reject(err);
102
+ }
103
+ }
104
+ catch (err) {
105
+ // Fail
106
+ reject(err);
107
+ }
108
+ })
109
+ .catch(reject);
110
+ });
111
+ }
112
+ }
113
+ // Module
114
+ export default AuthSystem;
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ var presence = require('./presence.cjs');
4
+ var saveAsync = require('./saveAsync.cjs');
5
+
6
+ const database = {
7
+ presence: presence,
8
+ SaveAsync: saveAsync,
9
+ };
10
+
11
+ module.exports = database;
@@ -0,0 +1,7 @@
1
+ export default database;
2
+ declare namespace database {
3
+ export { presenceSystem as presence };
4
+ export { SaveAsync };
5
+ }
6
+ import presenceSystem from './presence.mjs';
7
+ import SaveAsync from './saveAsync.mjs';
@@ -0,0 +1,7 @@
1
+ import presenceSystem from './presence.mjs';
2
+ import SaveAsync from './saveAsync.mjs';
3
+ const database = {
4
+ presence: presenceSystem,
5
+ SaveAsync,
6
+ };
7
+ export default database;
@@ -0,0 +1,131 @@
1
+ 'use strict';
2
+
3
+ var moment = require('moment-timezone');
4
+ var _ = require('lodash');
5
+
6
+ /**
7
+ * Firebase Presence System
8
+ *
9
+ * This module allows real-time tracking of user presence using Firebase Realtime Database.
10
+ * It handles multiple connections (tabs/devices), updates online status, and records the last time online.
11
+ *
12
+ * @module presenceSystem
13
+ */
14
+ const presenceSystem = {
15
+ /**
16
+ * Returns the source code of the `start` function as a string, with placeholders replaced.
17
+ *
18
+ * This function is useful to retrieve a browser-compatible version of the `start` function
19
+ * for client-side injection (e.g., for Firebase emulators or test UIs).
20
+ *
21
+ * @param {string} [lodash='_'] - The lodash import replacement string (usually `_`).
22
+ * @returns {string} JavaScript source code as a string with `lodash` and `moment` replaced or removed.
23
+ */
24
+ browserVersion: function (lodash = '_') {
25
+ // Get Browser Version
26
+ return presenceSystem.start
27
+ .toString()
28
+ .replace(`import _ from 'lodash'`, lodash)
29
+ .replace('let moment;', '')
30
+ .replace('moment = null;', 'console.error(err);')
31
+ .replace(
32
+ `import moment from 'moment-timezone'`,
33
+ "const tinypudding = 'Tiny Jasmini's Pudding.'",
34
+ );
35
+ },
36
+
37
+ /**
38
+ * Starts presence tracking for a given user in Firebase Realtime Database.
39
+ *
40
+ * It sets up handlers for `.info/connected`, manages disconnect events,
41
+ * and updates the last online time in UTC format.
42
+ *
43
+ * @param {object} database - Firebase database reference (usually `admin.database()` or `firebase.database()`).
44
+ * @param {string|object} myConnectionsRef - Path or database ref to the user's `connections` node.
45
+ * @param {string|object} lastOnlineRef - Path or database ref to the user's `lastOnline` node.
46
+ * @param {object} [data] - Optional configuration overrides.
47
+ * @param {boolean|object} [data.connected=true] - Data to store when device is connected.
48
+ * @param {Function} [data.removeError] - Callback for `onDisconnect().remove()` errors.
49
+ * @param {Function} [data.getDate] - Function to return a UTC-based timestamp object (uses `moment` if available).
50
+ */
51
+ start: (database, myConnectionsRef, lastOnlineRef, data) => {
52
+ // Since I can connect from multiple devices or browser tabs, we store each connection instance separately
53
+ // any time that connectionsRef's value is null (i.e. has no children) I am offline
54
+ if (typeof myConnectionsRef === 'string') {
55
+ myConnectionsRef = database.ref(myConnectionsRef);
56
+ }
57
+
58
+ // stores the timestamp of my last disconnect (the last time I was seen online)
59
+ if (typeof lastOnlineRef === 'string') {
60
+ lastOnlineRef = database.ref(lastOnlineRef);
61
+ }
62
+
63
+ // Get Base
64
+ data = _.defaultsDeep({}, data, {
65
+ // Remove Error
66
+ removeError: (err) => {
67
+ if (err) {
68
+ console.group('could not establish onDisconnect event');
69
+ console.error(err);
70
+ console.groupEnd();
71
+ }
72
+ },
73
+
74
+ // Is Connected
75
+ connected: true,
76
+
77
+ // Get Data
78
+ getDate: function () {
79
+ // Prepare Values
80
+ let momentTime;
81
+
82
+ // Timezone Module
83
+ if (moment) {
84
+ momentTime = moment.utc().toObject();
85
+ }
86
+
87
+ // Vanilla
88
+ else {
89
+ const date = new Date();
90
+ momentTime = {
91
+ date: date.getUTCDate(),
92
+ hours: date.getUTCHours(),
93
+ milliseconds: date.getUTCMilliseconds(),
94
+ minutes: date.getUTCMinutes(),
95
+ months: date.getUTCMonth(),
96
+ seconds: date.getUTCSeconds(),
97
+ years: date.getUTCFullYear(),
98
+ };
99
+ }
100
+
101
+ // Insert Timezone Name
102
+ momentTime.timezone = 'Universal';
103
+
104
+ // Return the value
105
+ return momentTime;
106
+ },
107
+ });
108
+
109
+ // Prepare Connection
110
+ const connectedRef = database.ref('.info/connected');
111
+ connectedRef.on('value', (snap) => {
112
+ if (snap.val() === true) {
113
+ // We're connected (or reconnected)! Do anything here that should happen only if online (or on reconnect)
114
+ const con = myConnectionsRef.push();
115
+
116
+ // When I disconnect, remove this device
117
+ con.onDisconnect().remove(data.removeError);
118
+
119
+ // Add this device to my connections list
120
+ // this value could contain info about the device or a timestamp too
121
+ con.set(data.connected);
122
+
123
+ // When I disconnect, update the last time I was seen online
124
+ const momentTime = data.getDate();
125
+ lastOnlineRef.onDisconnect().set(momentTime);
126
+ }
127
+ });
128
+ },
129
+ };
130
+
131
+ module.exports = presenceSystem;
@@ -0,0 +1,9 @@
1
+ export default presenceSystem;
2
+ declare namespace presenceSystem {
3
+ function browserVersion(lodash?: string): string;
4
+ function start(database: object, myConnectionsRef: string | object, lastOnlineRef: string | object, data?: {
5
+ connected?: boolean | object | undefined;
6
+ removeError?: Function | undefined;
7
+ getDate?: Function | undefined;
8
+ }): void;
9
+ }
@@ -0,0 +1,111 @@
1
+ import moment from 'moment-timezone';
2
+ import _ from 'lodash';
3
+ /**
4
+ * Firebase Presence System
5
+ *
6
+ * This module allows real-time tracking of user presence using Firebase Realtime Database.
7
+ * It handles multiple connections (tabs/devices), updates online status, and records the last time online.
8
+ *
9
+ * @module presenceSystem
10
+ */
11
+ const presenceSystem = {
12
+ /**
13
+ * Returns the source code of the `start` function as a string, with placeholders replaced.
14
+ *
15
+ * This function is useful to retrieve a browser-compatible version of the `start` function
16
+ * for client-side injection (e.g., for Firebase emulators or test UIs).
17
+ *
18
+ * @param {string} [lodash='_'] - The lodash import replacement string (usually `_`).
19
+ * @returns {string} JavaScript source code as a string with `lodash` and `moment` replaced or removed.
20
+ */
21
+ browserVersion: function (lodash = '_') {
22
+ // Get Browser Version
23
+ return presenceSystem.start
24
+ .toString()
25
+ .replace(`import _ from 'lodash'`, lodash)
26
+ .replace('let moment;', '')
27
+ .replace('moment = null;', 'console.error(err);')
28
+ .replace(`import moment from 'moment-timezone'`, "const tinypudding = 'Tiny Jasmini's Pudding.'");
29
+ },
30
+ /**
31
+ * Starts presence tracking for a given user in Firebase Realtime Database.
32
+ *
33
+ * It sets up handlers for `.info/connected`, manages disconnect events,
34
+ * and updates the last online time in UTC format.
35
+ *
36
+ * @param {object} database - Firebase database reference (usually `admin.database()` or `firebase.database()`).
37
+ * @param {string|object} myConnectionsRef - Path or database ref to the user's `connections` node.
38
+ * @param {string|object} lastOnlineRef - Path or database ref to the user's `lastOnline` node.
39
+ * @param {object} [data] - Optional configuration overrides.
40
+ * @param {boolean|object} [data.connected=true] - Data to store when device is connected.
41
+ * @param {Function} [data.removeError] - Callback for `onDisconnect().remove()` errors.
42
+ * @param {Function} [data.getDate] - Function to return a UTC-based timestamp object (uses `moment` if available).
43
+ */
44
+ start: (database, myConnectionsRef, lastOnlineRef, data) => {
45
+ // Since I can connect from multiple devices or browser tabs, we store each connection instance separately
46
+ // any time that connectionsRef's value is null (i.e. has no children) I am offline
47
+ if (typeof myConnectionsRef === 'string') {
48
+ myConnectionsRef = database.ref(myConnectionsRef);
49
+ }
50
+ // stores the timestamp of my last disconnect (the last time I was seen online)
51
+ if (typeof lastOnlineRef === 'string') {
52
+ lastOnlineRef = database.ref(lastOnlineRef);
53
+ }
54
+ // Get Base
55
+ data = _.defaultsDeep({}, data, {
56
+ // Remove Error
57
+ removeError: (err) => {
58
+ if (err) {
59
+ console.group('could not establish onDisconnect event');
60
+ console.error(err);
61
+ console.groupEnd();
62
+ }
63
+ },
64
+ // Is Connected
65
+ connected: true,
66
+ // Get Data
67
+ getDate: function () {
68
+ // Prepare Values
69
+ let momentTime;
70
+ // Timezone Module
71
+ if (moment) {
72
+ momentTime = moment.utc().toObject();
73
+ }
74
+ // Vanilla
75
+ else {
76
+ const date = new Date();
77
+ momentTime = {
78
+ date: date.getUTCDate(),
79
+ hours: date.getUTCHours(),
80
+ milliseconds: date.getUTCMilliseconds(),
81
+ minutes: date.getUTCMinutes(),
82
+ months: date.getUTCMonth(),
83
+ seconds: date.getUTCSeconds(),
84
+ years: date.getUTCFullYear(),
85
+ };
86
+ }
87
+ // Insert Timezone Name
88
+ momentTime.timezone = 'Universal';
89
+ // Return the value
90
+ return momentTime;
91
+ },
92
+ });
93
+ // Prepare Connection
94
+ const connectedRef = database.ref('.info/connected');
95
+ connectedRef.on('value', (snap) => {
96
+ if (snap.val() === true) {
97
+ // We're connected (or reconnected)! Do anything here that should happen only if online (or on reconnect)
98
+ const con = myConnectionsRef.push();
99
+ // When I disconnect, remove this device
100
+ con.onDisconnect().remove(data.removeError);
101
+ // Add this device to my connections list
102
+ // this value could contain info about the device or a timestamp too
103
+ con.set(data.connected);
104
+ // When I disconnect, update the last time I was seen online
105
+ const momentTime = data.getDate();
106
+ lastOnlineRef.onDisconnect().set(momentTime);
107
+ }
108
+ });
109
+ },
110
+ };
111
+ export default presenceSystem;
@@ -0,0 +1,147 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Class representing an asynchronous save system with callback support.
5
+ *
6
+ * This class is designed to handle database operations asynchronously and supports
7
+ * adding multiple operations to a queue, as well as running callbacks after each action.
8
+ *
9
+ * @class SaveAsync
10
+ */
11
+ class SaveAsync {
12
+ /**
13
+ * Creates an instance of SaveAsync.
14
+ *
15
+ * @param {object} db - The database reference to interact with (e.g., Firebase or other DB).
16
+ */
17
+ constructor(db) {
18
+ this.db = db;
19
+ this.list = [];
20
+ this.callbacks = {};
21
+ this.using = false;
22
+ }
23
+
24
+ /**
25
+ * Registers a callback to be run when a specific action type is executed.
26
+ *
27
+ * @param {string} where - The action type (e.g., "set", "push", etc.).
28
+ * @param {Function} callback - The callback function to run when the action is performed.
29
+ * @returns {boolean} Returns `true` if the callback is successfully registered.
30
+ */
31
+ on(where, callback) {
32
+ if (!Array.isArray(this.callbacks[where])) this.callbacks[where] = [];
33
+ this.callbacks[where].push(callback);
34
+ return true;
35
+ }
36
+
37
+ /**
38
+ * Runs all callbacks associated with a specific action type.
39
+ *
40
+ * @param {string} type - The action type (e.g., "set", "push", etc.).
41
+ * @param {any} data - The data passed to the callback(s).
42
+ * @param {string} [where] - The location (optional) where the action was performed.
43
+ */
44
+ _runCallbacks(type, data, where) {
45
+ if (Array.isArray(this.callbacks[type]))
46
+ for (const item in this.callbacks[type])
47
+ if (typeof this.callbacks[type][item] === 'function')
48
+ this.callbacks[type][item](data, where);
49
+ }
50
+
51
+ /**
52
+ * Processes the queued actions and executes them one by one.
53
+ *
54
+ * Each action in the queue is processed asynchronously. Once one action completes,
55
+ * the next action in the queue is triggered.
56
+ */
57
+ action() {
58
+ // Insert
59
+ if (this.list.length > 0) {
60
+ // Get Item
61
+ const post = this.list.shift();
62
+ const tinyThis = this;
63
+
64
+ // Try
65
+ try {
66
+ if (typeof post.where !== 'string') {
67
+ if (post.data) {
68
+ this.db[post.type](post.data)
69
+ .then(() => {
70
+ this._runCallbacks(post.type, post.data);
71
+ tinyThis.action();
72
+ })
73
+ .catch((err) => {
74
+ console.error(err);
75
+ });
76
+ } else {
77
+ this.db[post.type]()
78
+ .then(() => {
79
+ this._runCallbacks(post.type);
80
+ tinyThis.action();
81
+ })
82
+ .catch((err) => {
83
+ console.error(err);
84
+ });
85
+ }
86
+ } else {
87
+ if (post.data) {
88
+ this.db
89
+ .child(post.where)
90
+ [post.type](post.data)
91
+ .then(() => {
92
+ this._runCallbacks(post.type, post.data, post.where);
93
+ tinyThis.action();
94
+ })
95
+ .catch((err) => {
96
+ console.error(err);
97
+ });
98
+ } else {
99
+ this.db
100
+ .child(post.where)
101
+ [post.type]()
102
+ .then(() => {
103
+ this._runCallbacks(post.type, null, post.where);
104
+ tinyThis.action();
105
+ })
106
+ .catch((err) => {
107
+ console.error(err);
108
+ });
109
+ }
110
+ }
111
+ } catch (err) {
112
+ // Error
113
+ console.error(err);
114
+ }
115
+ }
116
+
117
+ // Nope
118
+ else this.using = false;
119
+ }
120
+
121
+ /**
122
+ * Inserts a new action into the queue.
123
+ *
124
+ * The action will be executed when the system is ready (i.e., when the queue is not in use).
125
+ *
126
+ * @param {object} [data={}] - The data to be saved (optional).
127
+ * @param {string} [type='set'] - The type of the database action (e.g., 'set', 'push', etc.).
128
+ * @param {string|null} [where=null] - The location where the data should be stored (optional).
129
+ */
130
+ insert(data = {}, type = 'set', where = null) {
131
+ // Insert
132
+ if (data !== null) {
133
+ if (where !== null) this.list.push({ where: String(where), data: data, type: type });
134
+ else this.list.push({ data: data, type: type });
135
+ } else {
136
+ if (where !== null) this.list.push({ where: String(where), type: type });
137
+ else this.list.push({ type: type });
138
+ }
139
+
140
+ if (!this.using) {
141
+ this.using = true;
142
+ this.action();
143
+ }
144
+ }
145
+ }
146
+
147
+ module.exports = SaveAsync;
@@ -0,0 +1,54 @@
1
+ export default SaveAsync;
2
+ /**
3
+ * Class representing an asynchronous save system with callback support.
4
+ *
5
+ * This class is designed to handle database operations asynchronously and supports
6
+ * adding multiple operations to a queue, as well as running callbacks after each action.
7
+ *
8
+ * @class SaveAsync
9
+ */
10
+ declare class SaveAsync {
11
+ /**
12
+ * Creates an instance of SaveAsync.
13
+ *
14
+ * @param {object} db - The database reference to interact with (e.g., Firebase or other DB).
15
+ */
16
+ constructor(db: object);
17
+ db: object;
18
+ list: any[];
19
+ callbacks: {};
20
+ using: boolean;
21
+ /**
22
+ * Registers a callback to be run when a specific action type is executed.
23
+ *
24
+ * @param {string} where - The action type (e.g., "set", "push", etc.).
25
+ * @param {Function} callback - The callback function to run when the action is performed.
26
+ * @returns {boolean} Returns `true` if the callback is successfully registered.
27
+ */
28
+ on(where: string, callback: Function): boolean;
29
+ /**
30
+ * Runs all callbacks associated with a specific action type.
31
+ *
32
+ * @param {string} type - The action type (e.g., "set", "push", etc.).
33
+ * @param {any} data - The data passed to the callback(s).
34
+ * @param {string} [where] - The location (optional) where the action was performed.
35
+ */
36
+ _runCallbacks(type: string, data: any, where?: string): void;
37
+ /**
38
+ * Processes the queued actions and executes them one by one.
39
+ *
40
+ * Each action in the queue is processed asynchronously. Once one action completes,
41
+ * the next action in the queue is triggered.
42
+ */
43
+ action(): void;
44
+ /**
45
+ * Inserts a new action into the queue.
46
+ *
47
+ * The action will be executed when the system is ready (i.e., when the queue is not in use).
48
+ *
49
+ * @param {object} [data={}] - The data to be saved (optional).
50
+ * @param {string} [type='set'] - The type of the database action (e.g., 'set', 'push', etc.).
51
+ * @param {string|null} [where=null] - The location where the data should be stored (optional).
52
+ */
53
+ insert(data?: object, type?: string, where?: string | null): void;
54
+ }