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,234 @@
1
+ import objType from '../get/objType.mjs';
2
+ import moment from 'moment-timezone';
3
+ import getDBData from './getDBData.mjs';
4
+ // DB
5
+ const tinyCache = {};
6
+ let lastUpdate = { number: null, moment: null };
7
+ let cacheLimit = 2000;
8
+ // Action
9
+ // Error To JSON
10
+ if (!('toJSON' in Error.prototype)) {
11
+ Object.defineProperty(Error.prototype, 'toJSON', {
12
+ value: function () {
13
+ let alt = {};
14
+ Object.getOwnPropertyNames(this).forEach(function (key) {
15
+ alt[key] = this[key];
16
+ }, this);
17
+ return alt;
18
+ },
19
+ configurable: true,
20
+ writable: true,
21
+ });
22
+ }
23
+ /**
24
+ * Handles various logging actions (log, error, info, warn) and stores them in the database.
25
+ * Logs data are stored with a timestamp and are counted by type (log, error, info, warn).
26
+ * When the log count exceeds the specified cache limit, the database is cleared and reset.
27
+ *
28
+ * @param {string} where - The location or context where the log is coming from.
29
+ * @param {string} type - The type of log (log, error, info, or warn).
30
+ * @param {Array} args - The arguments to log (can include strings, numbers, objects, arrays, or errors).
31
+ * @returns {Promise<void>} Resolves once the log is stored in the database.
32
+ */
33
+ const tinyAction = async function (where, type, args) {
34
+ // Try
35
+ try {
36
+ // Production
37
+ if (!isDebug) {
38
+ // Date Now
39
+ const now = moment();
40
+ // Update Counter
41
+ let count = tinyCache[where].count[type];
42
+ tinyCache[where].count[type]++;
43
+ // New Date
44
+ if ((lastUpdate.moment && lastUpdate.moment.date() !== now.date()) ||
45
+ tinyCache[where].count[type] > cacheLimit) {
46
+ await tinyCache[where].db.remove();
47
+ for (const item in tinyCache[where].count) {
48
+ tinyCache[where].count[item] = 0;
49
+ }
50
+ }
51
+ // Update Time
52
+ lastUpdate.moment = now;
53
+ lastUpdate.number = lastUpdate.moment.valueOf();
54
+ // Check Args
55
+ const insertArgs = [];
56
+ for (const item in args) {
57
+ // Is Error
58
+ if (args[item] instanceof Error) {
59
+ try {
60
+ args[item] = JSON.parse(JSON.stringify(args[item]));
61
+ }
62
+ catch (err) {
63
+ console.error(err);
64
+ }
65
+ }
66
+ // Object Type
67
+ const type = objType(args[item]);
68
+ // Insert Args
69
+ if (type === 'string' || type === 'number' || type === 'object' || type === 'array')
70
+ insertArgs.push(args[item]);
71
+ }
72
+ // Add Log
73
+ if (insertArgs.length > 0) {
74
+ await tinyCache[where].db.child(type).child(count).set({
75
+ time: lastUpdate.number,
76
+ args: insertArgs,
77
+ });
78
+ }
79
+ // Nope
80
+ else {
81
+ tinyCache[where].count[type]--;
82
+ if (tinyCache[where].count[type] < 0)
83
+ tinyCache[where].count[type] = 0;
84
+ }
85
+ }
86
+ }
87
+ catch (err) {
88
+ // Error
89
+ console.error(`ERROR IN ${where} (${type})!`);
90
+ console.error(err);
91
+ }
92
+ };
93
+ // Is Debug
94
+ let isDebug = false;
95
+ /**
96
+ * Updates the last update time with the provided value, if it's newer than the current one.
97
+ *
98
+ * @param {number} value - The timestamp of the update to check against the last update.
99
+ * @returns {void}
100
+ */
101
+ const checkLastTime = function (value) {
102
+ // Update
103
+ if (!lastUpdate.number || value > lastUpdate.number) {
104
+ lastUpdate.moment = moment(value);
105
+ lastUpdate.number = lastUpdate.moment.valueOf();
106
+ }
107
+ };
108
+ /**
109
+ * Generates a logger object with methods for different types of logging (log, error, info, warn).
110
+ * Each log type is stored in the database with a timestamp and arguments.
111
+ *
112
+ * @param {string} where - The location or context where the log is coming from.
113
+ * @returns {Object} The logger object with methods for logging (log, error, info, warn).
114
+ */
115
+ const loggerGenerator = function (where) {
116
+ // Done
117
+ return {
118
+ // Log
119
+ log: async function () {
120
+ console.log.apply(console, arguments);
121
+ tinyAction(where, 'log', arguments);
122
+ },
123
+ // Error
124
+ error: async function () {
125
+ console.error.apply(console, arguments);
126
+ tinyAction(where, 'error', arguments);
127
+ },
128
+ // Info
129
+ info: async function () {
130
+ console.info.apply(console, arguments);
131
+ tinyAction(where, 'info', arguments);
132
+ },
133
+ // Warning
134
+ warn: async function () {
135
+ console.warn.apply(console, arguments);
136
+ tinyAction(where, 'warn', arguments);
137
+ },
138
+ };
139
+ };
140
+ /**
141
+ * Database logger module that manages logging actions and stores logs in a database.
142
+ * It provides functionality to start the logger with a new database instance,
143
+ * retrieve the logger instance, change the cache limit, and set debug mode.
144
+ *
145
+ * @module databaseLogger
146
+ */
147
+ const databaseLogger = {
148
+ /**
149
+ * Starts the logger with a new database instance and initializes cache values.
150
+ *
151
+ * @param {Object} newDB - The new database instance to use for storing logs.
152
+ * @param {string} where - The context or location where the logger will be used.
153
+ * @returns {Promise<Object>} The logger instance with methods for logging.
154
+ */
155
+ start: async function (newDB, where) {
156
+ // Prepare
157
+ tinyCache[where] = { db: newDB, count: { log: 0, error: 0, info: 0, warn: 0 } };
158
+ let loggerCache = null;
159
+ if (!isDebug) {
160
+ loggerCache = await getDBData(tinyCache[where].db);
161
+ if (loggerCache) {
162
+ try {
163
+ if (loggerCache.log) {
164
+ tinyCache[where].count.log = loggerCache.log.length;
165
+ for (const item in loggerCache.log) {
166
+ if (typeof loggerCache.log[item].time === 'number') {
167
+ checkLastTime(loggerCache.log[item].time);
168
+ }
169
+ }
170
+ }
171
+ if (loggerCache.error) {
172
+ tinyCache[where].count.error = loggerCache.error.length;
173
+ for (const item in loggerCache.error) {
174
+ if (typeof loggerCache.error[item].time === 'number') {
175
+ checkLastTime(loggerCache.error[item].time);
176
+ }
177
+ }
178
+ }
179
+ if (loggerCache.info) {
180
+ tinyCache[where].count.info = loggerCache.info.length;
181
+ for (const item in loggerCache.info) {
182
+ if (typeof loggerCache.info[item].time === 'number') {
183
+ checkLastTime(loggerCache.info[item].time);
184
+ }
185
+ }
186
+ }
187
+ if (loggerCache.warn) {
188
+ tinyCache[where].count.warn = loggerCache.warn.length;
189
+ for (const item in loggerCache.warn) {
190
+ if (typeof loggerCache.warn[item].time === 'number') {
191
+ checkLastTime(loggerCache.warn[item].time);
192
+ }
193
+ }
194
+ }
195
+ }
196
+ catch (err) {
197
+ console.error(err);
198
+ isDebug = true;
199
+ }
200
+ }
201
+ }
202
+ // Complete
203
+ return loggerGenerator(where);
204
+ },
205
+ /**
206
+ * Retrieves the logger instance for a given context.
207
+ *
208
+ * @param {string} where - The context or location where the logger will be used.
209
+ * @returns {Object} The logger instance with methods for logging.
210
+ */
211
+ get: function (where) {
212
+ return loggerGenerator(where);
213
+ },
214
+ /**
215
+ * Changes the cache limit for the logger.
216
+ *
217
+ * @param {number} value - The new cache limit to set.
218
+ * @returns {void}
219
+ */
220
+ changeCacheLimit: function (value) {
221
+ if (typeof value === 'number')
222
+ cacheLimit = value;
223
+ },
224
+ /**
225
+ * Enables or disables debug mode.
226
+ *
227
+ * @param {boolean} value - `true` to enable debug mode, `false` to disable it.
228
+ * @returns {void}
229
+ */
230
+ setDebugMode: function (value) {
231
+ isDebug = value;
232
+ },
233
+ };
234
+ export default databaseLogger;
@@ -0,0 +1,71 @@
1
+ 'use strict';
2
+
3
+ var json = require('../../../http/fetch/json.cjs');
4
+ var config = require('../config.cjs');
5
+ var errorValidator = require('../get/errorValidator.cjs');
6
+
7
+ /**
8
+ * Adds a member to a Discord guild (server) using a valid OAuth2 access token and a bot token.
9
+ * This method requires the `guilds.join` OAuth2 scope to be granted by the user.
10
+ *
11
+ * @param {string} bot_token - The Bot Token used for authorization (`Bot <token>`).
12
+ * @param {Object} data - The data required to add the member to the guild.
13
+ * @param {string} data.guild_id - The ID of the guild (server) the user should be added to.
14
+ * @param {string} data.user_id - The ID of the user to be added.
15
+ * @param {string} data.access_token - The OAuth2 access token granted by the user.
16
+ * @param {string[]} [data.roles] - An optional array of role IDs to assign to the member.
17
+ * @param {string} [data.nickname] - Optional nickname to assign to the user in the guild.
18
+ * @param {boolean} [data.mute=false] - Whether the user should be server-muted.
19
+ * @param {boolean} [data.deaf=false] - Whether the user should be server-deafened.
20
+ *
21
+ * @returns {Promise<Object>} Resolves with the user object if successful, or rejects with an error object.
22
+ *
23
+ * @throws {Object} If the request fails or Discord returns an error, rejects with an object containing a `code` and `message`.
24
+ *
25
+ * @example
26
+ * const result = await addGuildMember('your_bot_token', {
27
+ * guild_id: '1234567890',
28
+ * user_id: '0987654321',
29
+ * access_token: 'user_access_token',
30
+ * roles: ['1122334455'],
31
+ * nickname: 'CoolUser',
32
+ * mute: false,
33
+ * deaf: false,
34
+ * });
35
+ */
36
+ function addGuildMember(bot_token, data) {
37
+ return new Promise(function (resolve, reject) {
38
+ // API URL
39
+ const apiURL = config.url;
40
+
41
+ // Response
42
+ json(
43
+ `${apiURL}guilds/${encodeURIComponent(data.guild_id)}/members/${encodeURIComponent(data.user_id)}`,
44
+ {
45
+ method: 'PUT',
46
+ body: new URLSearchParams({
47
+ deaf: data.deaf,
48
+ mute: data.mute,
49
+ nick: data.nickname,
50
+ roles: data.roles,
51
+ access_token: data.access_token,
52
+ }),
53
+ headers: {
54
+ Authorization: `Bot ${bot_token}`,
55
+ 'Content-Type': 'application/json',
56
+ },
57
+ },
58
+ )
59
+ .then((data) => {
60
+ // Error Validator
61
+ const result = errorValidator(data);
62
+ if (!result.error) resolve(result.data);
63
+ else reject(result.error);
64
+ })
65
+ .catch((err) => {
66
+ reject({ code: err.response.status, message: err.message });
67
+ });
68
+ });
69
+ }
70
+
71
+ module.exports = addGuildMember;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Adds a member to a Discord guild (server) using a valid OAuth2 access token and a bot token.
3
+ * This method requires the `guilds.join` OAuth2 scope to be granted by the user.
4
+ *
5
+ * @param {string} bot_token - The Bot Token used for authorization (`Bot <token>`).
6
+ * @param {Object} data - The data required to add the member to the guild.
7
+ * @param {string} data.guild_id - The ID of the guild (server) the user should be added to.
8
+ * @param {string} data.user_id - The ID of the user to be added.
9
+ * @param {string} data.access_token - The OAuth2 access token granted by the user.
10
+ * @param {string[]} [data.roles] - An optional array of role IDs to assign to the member.
11
+ * @param {string} [data.nickname] - Optional nickname to assign to the user in the guild.
12
+ * @param {boolean} [data.mute=false] - Whether the user should be server-muted.
13
+ * @param {boolean} [data.deaf=false] - Whether the user should be server-deafened.
14
+ *
15
+ * @returns {Promise<Object>} Resolves with the user object if successful, or rejects with an error object.
16
+ *
17
+ * @throws {Object} If the request fails or Discord returns an error, rejects with an object containing a `code` and `message`.
18
+ *
19
+ * @example
20
+ * const result = await addGuildMember('your_bot_token', {
21
+ * guild_id: '1234567890',
22
+ * user_id: '0987654321',
23
+ * access_token: 'user_access_token',
24
+ * roles: ['1122334455'],
25
+ * nickname: 'CoolUser',
26
+ * mute: false,
27
+ * deaf: false,
28
+ * });
29
+ */
30
+ export default function addGuildMember(bot_token: string, data: {
31
+ guild_id: string;
32
+ user_id: string;
33
+ access_token: string;
34
+ roles?: string[] | undefined;
35
+ nickname?: string | undefined;
36
+ mute?: boolean | undefined;
37
+ deaf?: boolean | undefined;
38
+ }): Promise<Object>;
@@ -0,0 +1,64 @@
1
+ import getJsonFetch from '../../../http/fetch/json.mjs';
2
+ import config from '../config.mjs';
3
+ import errorValidator from '../get/errorValidator.mjs';
4
+ /**
5
+ * Adds a member to a Discord guild (server) using a valid OAuth2 access token and a bot token.
6
+ * This method requires the `guilds.join` OAuth2 scope to be granted by the user.
7
+ *
8
+ * @param {string} bot_token - The Bot Token used for authorization (`Bot <token>`).
9
+ * @param {Object} data - The data required to add the member to the guild.
10
+ * @param {string} data.guild_id - The ID of the guild (server) the user should be added to.
11
+ * @param {string} data.user_id - The ID of the user to be added.
12
+ * @param {string} data.access_token - The OAuth2 access token granted by the user.
13
+ * @param {string[]} [data.roles] - An optional array of role IDs to assign to the member.
14
+ * @param {string} [data.nickname] - Optional nickname to assign to the user in the guild.
15
+ * @param {boolean} [data.mute=false] - Whether the user should be server-muted.
16
+ * @param {boolean} [data.deaf=false] - Whether the user should be server-deafened.
17
+ *
18
+ * @returns {Promise<Object>} Resolves with the user object if successful, or rejects with an error object.
19
+ *
20
+ * @throws {Object} If the request fails or Discord returns an error, rejects with an object containing a `code` and `message`.
21
+ *
22
+ * @example
23
+ * const result = await addGuildMember('your_bot_token', {
24
+ * guild_id: '1234567890',
25
+ * user_id: '0987654321',
26
+ * access_token: 'user_access_token',
27
+ * roles: ['1122334455'],
28
+ * nickname: 'CoolUser',
29
+ * mute: false,
30
+ * deaf: false,
31
+ * });
32
+ */
33
+ export default function addGuildMember(bot_token, data) {
34
+ return new Promise(function (resolve, reject) {
35
+ // API URL
36
+ const apiURL = config.url;
37
+ // Response
38
+ getJsonFetch(`${apiURL}guilds/${encodeURIComponent(data.guild_id)}/members/${encodeURIComponent(data.user_id)}`, {
39
+ method: 'PUT',
40
+ body: new URLSearchParams({
41
+ deaf: data.deaf,
42
+ mute: data.mute,
43
+ nick: data.nickname,
44
+ roles: data.roles,
45
+ access_token: data.access_token,
46
+ }),
47
+ headers: {
48
+ Authorization: `Bot ${bot_token}`,
49
+ 'Content-Type': 'application/json',
50
+ },
51
+ })
52
+ .then((data) => {
53
+ // Error Validator
54
+ const result = errorValidator(data);
55
+ if (!result.error)
56
+ resolve(result.data);
57
+ else
58
+ reject(result.error);
59
+ })
60
+ .catch((err) => {
61
+ reject({ code: err.response.status, message: err.message });
62
+ });
63
+ });
64
+ }
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ var json = require('../../../http/fetch/json.cjs');
4
+ var config = require('../config.cjs');
5
+ var errorValidator = require('../get/errorValidator.cjs');
6
+
7
+ /**
8
+ * Fetches the public widget data for a Discord guild (server).
9
+ * This includes online members, presence counts, and basic guild information,
10
+ * but only if the widget is enabled in the server settings.
11
+ *
12
+ * @param {string} guildID - The ID of the guild whose widget is to be fetched.
13
+ *
14
+ * @returns {Promise<Object>} Resolves with the guild widget data if successful.
15
+ *
16
+ * @throws {Object} If the request fails or the widget is disabled, rejects with an object containing a `code` and `message`.
17
+ *
18
+ * @example
19
+ * getGuildWidget('123456789012345678')
20
+ * .then((data) => console.log(data))
21
+ * .catch((err) => console.error('Widget error:', err));
22
+ */
23
+ function getGuildWidget(guildID) {
24
+ return new Promise(function (resolve, reject) {
25
+ // API URL
26
+ const apiURL = config.url;
27
+
28
+ // Response
29
+ json(`${apiURL}guilds/${encodeURIComponent(guildID)}/widget.json`, {
30
+ method: 'GET',
31
+ headers: {
32
+ 'Content-Type': 'application/json',
33
+ },
34
+ })
35
+ .then((data) => {
36
+ // Error Validator
37
+ const result = errorValidator(data);
38
+ if (!result.error) resolve(result.data);
39
+ else reject(result.error);
40
+ })
41
+ .catch((err) => {
42
+ reject({ code: err.response.status, message: err.message });
43
+ });
44
+ });
45
+ }
46
+
47
+ module.exports = getGuildWidget;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Fetches the public widget data for a Discord guild (server).
3
+ * This includes online members, presence counts, and basic guild information,
4
+ * but only if the widget is enabled in the server settings.
5
+ *
6
+ * @param {string} guildID - The ID of the guild whose widget is to be fetched.
7
+ *
8
+ * @returns {Promise<Object>} Resolves with the guild widget data if successful.
9
+ *
10
+ * @throws {Object} If the request fails or the widget is disabled, rejects with an object containing a `code` and `message`.
11
+ *
12
+ * @example
13
+ * getGuildWidget('123456789012345678')
14
+ * .then((data) => console.log(data))
15
+ * .catch((err) => console.error('Widget error:', err));
16
+ */
17
+ export default function getGuildWidget(guildID: string): Promise<Object>;
@@ -0,0 +1,43 @@
1
+ import getJsonFetch from '../../../http/fetch/json.mjs';
2
+ import config from '../config.mjs';
3
+ import errorValidator from '../get/errorValidator.mjs';
4
+ /**
5
+ * Fetches the public widget data for a Discord guild (server).
6
+ * This includes online members, presence counts, and basic guild information,
7
+ * but only if the widget is enabled in the server settings.
8
+ *
9
+ * @param {string} guildID - The ID of the guild whose widget is to be fetched.
10
+ *
11
+ * @returns {Promise<Object>} Resolves with the guild widget data if successful.
12
+ *
13
+ * @throws {Object} If the request fails or the widget is disabled, rejects with an object containing a `code` and `message`.
14
+ *
15
+ * @example
16
+ * getGuildWidget('123456789012345678')
17
+ * .then((data) => console.log(data))
18
+ * .catch((err) => console.error('Widget error:', err));
19
+ */
20
+ export default function getGuildWidget(guildID) {
21
+ return new Promise(function (resolve, reject) {
22
+ // API URL
23
+ const apiURL = config.url;
24
+ // Response
25
+ getJsonFetch(`${apiURL}guilds/${encodeURIComponent(guildID)}/widget.json`, {
26
+ method: 'GET',
27
+ headers: {
28
+ 'Content-Type': 'application/json',
29
+ },
30
+ })
31
+ .then((data) => {
32
+ // Error Validator
33
+ const result = errorValidator(data);
34
+ if (!result.error)
35
+ resolve(result.data);
36
+ else
37
+ reject(result.error);
38
+ })
39
+ .catch((err) => {
40
+ reject({ code: err.response.status, message: err.message });
41
+ });
42
+ });
43
+ }
@@ -0,0 +1,67 @@
1
+ 'use strict';
2
+
3
+ var json = require('../../../http/fetch/json.cjs');
4
+ var config = require('../config.cjs');
5
+ var errorValidator = require('../get/errorValidator.cjs');
6
+
7
+ /**
8
+ * Exchanges an authorization code for an access token using Discord's OAuth2 API.
9
+ *
10
+ * This function is used in the OAuth2 authorization code flow.
11
+ * It sends a POST request to the `/oauth2/token` endpoint with the required parameters.
12
+ *
13
+ * @param {Object} dsData - The data required for the token exchange.
14
+ * @param {string} dsData.client_id - Your application's client ID.
15
+ * @param {string} dsData.client_secret - Your application's client secret.
16
+ * @param {string} dsData.code - The authorization code received from Discord.
17
+ * @param {string} dsData.redirect_uri - The redirect URI used during the authorization.
18
+ * @param {string} [dsData.scope] - The OAuth2 scopes being requested (optional but recommended).
19
+ *
20
+ * @returns {Promise<Object>} Resolves with the access token data (access_token, token_type, expires_in, refresh_token, scope).
21
+ *
22
+ * @throws {Object} If the request fails or Discord returns an error, rejects with an object containing a `code` and `message`.
23
+ *
24
+ * @example
25
+ * getToken({
26
+ * client_id: '123456789012345678',
27
+ * client_secret: 's3cr3t',
28
+ * code: 'authcodefromdiscord',
29
+ * redirect_uri: 'https://your.app/redirect',
30
+ * scope: 'identify guilds'
31
+ * })
32
+ * .then(token => console.log('Access Token:', token.access_token))
33
+ * .catch(err => console.error('Token error:', err));
34
+ */
35
+ function getToken(dsData) {
36
+ return new Promise(function (resolve, reject) {
37
+ // API URL
38
+ const apiURL = config.url;
39
+
40
+ // Response
41
+ json(`${apiURL}oauth2/token`, {
42
+ method: 'POST',
43
+ body: new URLSearchParams({
44
+ client_id: dsData.client_id,
45
+ client_secret: dsData.client_secret,
46
+ grant_type: 'authorization_code',
47
+ code: dsData.code,
48
+ redirect_uri: dsData.redirect_uri,
49
+ scope: dsData.scope,
50
+ }),
51
+ headers: {
52
+ 'Content-Type': 'application/x-www-form-urlencoded',
53
+ },
54
+ })
55
+ .then((data) => {
56
+ // Error Validator
57
+ const result = errorValidator(data);
58
+ if (!result.error) resolve(result.data);
59
+ else reject(result.error);
60
+ })
61
+ .catch((err) => {
62
+ reject({ code: err.response.status, message: err.message });
63
+ });
64
+ });
65
+ }
66
+
67
+ module.exports = getToken;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Exchanges an authorization code for an access token using Discord's OAuth2 API.
3
+ *
4
+ * This function is used in the OAuth2 authorization code flow.
5
+ * It sends a POST request to the `/oauth2/token` endpoint with the required parameters.
6
+ *
7
+ * @param {Object} dsData - The data required for the token exchange.
8
+ * @param {string} dsData.client_id - Your application's client ID.
9
+ * @param {string} dsData.client_secret - Your application's client secret.
10
+ * @param {string} dsData.code - The authorization code received from Discord.
11
+ * @param {string} dsData.redirect_uri - The redirect URI used during the authorization.
12
+ * @param {string} [dsData.scope] - The OAuth2 scopes being requested (optional but recommended).
13
+ *
14
+ * @returns {Promise<Object>} Resolves with the access token data (access_token, token_type, expires_in, refresh_token, scope).
15
+ *
16
+ * @throws {Object} If the request fails or Discord returns an error, rejects with an object containing a `code` and `message`.
17
+ *
18
+ * @example
19
+ * getToken({
20
+ * client_id: '123456789012345678',
21
+ * client_secret: 's3cr3t',
22
+ * code: 'authcodefromdiscord',
23
+ * redirect_uri: 'https://your.app/redirect',
24
+ * scope: 'identify guilds'
25
+ * })
26
+ * .then(token => console.log('Access Token:', token.access_token))
27
+ * .catch(err => console.error('Token error:', err));
28
+ */
29
+ export default function getToken(dsData: {
30
+ client_id: string;
31
+ client_secret: string;
32
+ code: string;
33
+ redirect_uri: string;
34
+ scope?: string | undefined;
35
+ }): Promise<Object>;
@@ -0,0 +1,63 @@
1
+ import getJsonFetch from '../../../http/fetch/json.mjs';
2
+ import config from '../config.mjs';
3
+ import errorValidator from '../get/errorValidator.mjs';
4
+ /**
5
+ * Exchanges an authorization code for an access token using Discord's OAuth2 API.
6
+ *
7
+ * This function is used in the OAuth2 authorization code flow.
8
+ * It sends a POST request to the `/oauth2/token` endpoint with the required parameters.
9
+ *
10
+ * @param {Object} dsData - The data required for the token exchange.
11
+ * @param {string} dsData.client_id - Your application's client ID.
12
+ * @param {string} dsData.client_secret - Your application's client secret.
13
+ * @param {string} dsData.code - The authorization code received from Discord.
14
+ * @param {string} dsData.redirect_uri - The redirect URI used during the authorization.
15
+ * @param {string} [dsData.scope] - The OAuth2 scopes being requested (optional but recommended).
16
+ *
17
+ * @returns {Promise<Object>} Resolves with the access token data (access_token, token_type, expires_in, refresh_token, scope).
18
+ *
19
+ * @throws {Object} If the request fails or Discord returns an error, rejects with an object containing a `code` and `message`.
20
+ *
21
+ * @example
22
+ * getToken({
23
+ * client_id: '123456789012345678',
24
+ * client_secret: 's3cr3t',
25
+ * code: 'authcodefromdiscord',
26
+ * redirect_uri: 'https://your.app/redirect',
27
+ * scope: 'identify guilds'
28
+ * })
29
+ * .then(token => console.log('Access Token:', token.access_token))
30
+ * .catch(err => console.error('Token error:', err));
31
+ */
32
+ export default function getToken(dsData) {
33
+ return new Promise(function (resolve, reject) {
34
+ // API URL
35
+ const apiURL = config.url;
36
+ // Response
37
+ getJsonFetch(`${apiURL}oauth2/token`, {
38
+ method: 'POST',
39
+ body: new URLSearchParams({
40
+ client_id: dsData.client_id,
41
+ client_secret: dsData.client_secret,
42
+ grant_type: 'authorization_code',
43
+ code: dsData.code,
44
+ redirect_uri: dsData.redirect_uri,
45
+ scope: dsData.scope,
46
+ }),
47
+ headers: {
48
+ 'Content-Type': 'application/x-www-form-urlencoded',
49
+ },
50
+ })
51
+ .then((data) => {
52
+ // Error Validator
53
+ const result = errorValidator(data);
54
+ if (!result.error)
55
+ resolve(result.data);
56
+ else
57
+ reject(result.error);
58
+ })
59
+ .catch((err) => {
60
+ reject({ code: err.response.status, message: err.message });
61
+ });
62
+ });
63
+ }