@vandenberghinc/volt 1.2.4 → 1.2.6

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 (489) hide show
  1. package/frontend/assets/admin/admin.png +0 -0
  2. package/frontend/assets/admin/password.webp +0 -0
  3. package/frontend/assets/icons/arrow.v1.webp +0 -0
  4. package/frontend/assets/icons/copy.webp +0 -0
  5. package/frontend/assets/payments/arrow.long.webp +0 -0
  6. package/frontend/assets/payments/arrow.long2.webp +0 -0
  7. package/frontend/assets/payments/cancelled.webp +0 -0
  8. package/frontend/assets/payments/check.sign.webp +0 -0
  9. package/frontend/assets/payments/check.webp +0 -0
  10. package/frontend/assets/payments/close.webp +0 -0
  11. package/frontend/assets/payments/error.webp +0 -0
  12. package/frontend/assets/payments/exclamation.webp +0 -0
  13. package/frontend/assets/payments/minus.webp +0 -0
  14. package/frontend/assets/payments/party.webp +0 -0
  15. package/frontend/assets/payments/plus.webp +0 -0
  16. package/frontend/assets/payments/shopping_cart.webp +0 -0
  17. package/frontend/assets/payments/trash.webp +0 -0
  18. package/package.json +6 -2
  19. package/.libris/config.json +0 -82
  20. package/backend/dist/cjs/backend/src/blacklist.d.ts +0 -12
  21. package/backend/dist/cjs/backend/src/blacklist.js +0 -78
  22. package/backend/dist/cjs/backend/src/cli.d.ts +0 -2
  23. package/backend/dist/cjs/backend/src/cli.js +0 -198
  24. package/backend/dist/cjs/backend/src/database/collection.d.ts +0 -1765
  25. package/backend/dist/cjs/backend/src/database/collection.js +0 -3301
  26. package/backend/dist/cjs/backend/src/database/database.d.ts +0 -92
  27. package/backend/dist/cjs/backend/src/database/database.js +0 -170
  28. package/backend/dist/cjs/backend/src/database/document.d.ts +0 -1
  29. package/backend/dist/cjs/backend/src/database/document.js +0 -15
  30. package/backend/dist/cjs/backend/src/database/filters/filters.d.ts +0 -6
  31. package/backend/dist/cjs/backend/src/database/filters/filters.js +0 -15
  32. package/backend/dist/cjs/backend/src/database/filters/strict_filter.d.ts +0 -223
  33. package/backend/dist/cjs/backend/src/database/filters/strict_filter.js +0 -15
  34. package/backend/dist/cjs/backend/src/database/filters/strict_filter_test.d.ts +0 -1
  35. package/backend/dist/cjs/backend/src/database/filters/strict_filter_test.js +0 -443
  36. package/backend/dist/cjs/backend/src/database/filters/strict_filter_test_v0.d.ts +0 -1
  37. package/backend/dist/cjs/backend/src/database/filters/strict_filter_test_v0.js +0 -15
  38. package/backend/dist/cjs/backend/src/database/filters/strict_filter_v0.d.ts +0 -50
  39. package/backend/dist/cjs/backend/src/database/filters/strict_filter_v0.js +0 -15
  40. package/backend/dist/cjs/backend/src/database/filters/strict_filter_v1.d.ts +0 -76
  41. package/backend/dist/cjs/backend/src/database/filters/strict_filter_v1.js +0 -15
  42. package/backend/dist/cjs/backend/src/database/filters/strict_filter_v2.d.ts +0 -75
  43. package/backend/dist/cjs/backend/src/database/filters/strict_filter_v2.js +0 -15
  44. package/backend/dist/cjs/backend/src/database/filters/strict_filter_v3.d.ts +0 -219
  45. package/backend/dist/cjs/backend/src/database/filters/strict_filter_v3.js +0 -15
  46. package/backend/dist/cjs/backend/src/database/filters/strict_update_filter.d.ts +0 -165
  47. package/backend/dist/cjs/backend/src/database/filters/strict_update_filter.js +0 -15
  48. package/backend/dist/cjs/backend/src/database/filters/strict_update_filter_test.d.ts +0 -5
  49. package/backend/dist/cjs/backend/src/database/filters/strict_update_filter_test.js +0 -355
  50. package/backend/dist/cjs/backend/src/database/flatten.d.ts +0 -78
  51. package/backend/dist/cjs/backend/src/database/flatten.js +0 -53
  52. package/backend/dist/cjs/backend/src/database/flatten_test.d.ts +0 -1
  53. package/backend/dist/cjs/backend/src/database/flatten_test.js +0 -175
  54. package/backend/dist/cjs/backend/src/database/quota/quoata_v2.d.ts +0 -533
  55. package/backend/dist/cjs/backend/src/database/quota/quoata_v2.js +0 -1046
  56. package/backend/dist/cjs/backend/src/database/quota/quota.d.ts +0 -551
  57. package/backend/dist/cjs/backend/src/database/quota/quota.js +0 -1108
  58. package/backend/dist/cjs/backend/src/database/quota/quota_v1.d.ts +0 -534
  59. package/backend/dist/cjs/backend/src/database/quota/quota_v1.js +0 -1087
  60. package/backend/dist/cjs/backend/src/database/quota/safe_int.d.ts +0 -412
  61. package/backend/dist/cjs/backend/src/database/quota/safe_int.js +0 -745
  62. package/backend/dist/cjs/backend/src/endpoint.d.ts +0 -346
  63. package/backend/dist/cjs/backend/src/endpoint.js +0 -468
  64. package/backend/dist/cjs/backend/src/errors/index.d.ts +0 -7
  65. package/backend/dist/cjs/backend/src/errors/index.js +0 -25
  66. package/backend/dist/cjs/backend/src/errors/internal_external.d.ts +0 -52
  67. package/backend/dist/cjs/backend/src/errors/internal_external.js +0 -95
  68. package/backend/dist/cjs/backend/src/errors/invalid_usage_error.d.ts +0 -41
  69. package/backend/dist/cjs/backend/src/errors/invalid_usage_error.js +0 -47
  70. package/backend/dist/cjs/backend/src/errors/system_error.d.ts +0 -261
  71. package/backend/dist/cjs/backend/src/errors/system_error.js +0 -436
  72. package/backend/dist/cjs/backend/src/events.d.ts +0 -97
  73. package/backend/dist/cjs/backend/src/events.js +0 -15
  74. package/backend/dist/cjs/backend/src/frontend.d.ts +0 -11
  75. package/backend/dist/cjs/backend/src/frontend.js +0 -37
  76. package/backend/dist/cjs/backend/src/image_endpoint.d.ts +0 -44
  77. package/backend/dist/cjs/backend/src/image_endpoint.js +0 -185
  78. package/backend/dist/cjs/backend/src/index.d.ts +0 -23
  79. package/backend/dist/cjs/backend/src/index.js +0 -70
  80. package/backend/dist/cjs/backend/src/logger.d.ts +0 -5
  81. package/backend/dist/cjs/backend/src/logger.js +0 -15
  82. package/backend/dist/cjs/backend/src/meta.d.ts +0 -112
  83. package/backend/dist/cjs/backend/src/meta.js +0 -181
  84. package/backend/dist/cjs/backend/src/payments/paddle.d.ts +0 -329
  85. package/backend/dist/cjs/backend/src/payments/paddle.js +0 -1996
  86. package/backend/dist/cjs/backend/src/payments/stripe/checkout.d.ts +0 -113
  87. package/backend/dist/cjs/backend/src/payments/stripe/checkout.js +0 -295
  88. package/backend/dist/cjs/backend/src/payments/stripe/customers.d.ts +0 -17
  89. package/backend/dist/cjs/backend/src/payments/stripe/customers.js +0 -164
  90. package/backend/dist/cjs/backend/src/payments/stripe/error.d.ts +0 -74
  91. package/backend/dist/cjs/backend/src/payments/stripe/error.js +0 -64
  92. package/backend/dist/cjs/backend/src/payments/stripe/events.d.ts +0 -155
  93. package/backend/dist/cjs/backend/src/payments/stripe/events.js +0 -15
  94. package/backend/dist/cjs/backend/src/payments/stripe/meters.d.ts +0 -105
  95. package/backend/dist/cjs/backend/src/payments/stripe/meters.js +0 -230
  96. package/backend/dist/cjs/backend/src/payments/stripe/payment_methods.d.ts +0 -58
  97. package/backend/dist/cjs/backend/src/payments/stripe/payment_methods.js +0 -109
  98. package/backend/dist/cjs/backend/src/payments/stripe/products.d.ts +0 -519
  99. package/backend/dist/cjs/backend/src/payments/stripe/products.js +0 -650
  100. package/backend/dist/cjs/backend/src/payments/stripe/stripe.d.ts +0 -215
  101. package/backend/dist/cjs/backend/src/payments/stripe/stripe.js +0 -468
  102. package/backend/dist/cjs/backend/src/payments/stripe/subscriptions.d.ts +0 -172
  103. package/backend/dist/cjs/backend/src/payments/stripe/subscriptions.js +0 -557
  104. package/backend/dist/cjs/backend/src/payments/stripe/utils.d.ts +0 -63
  105. package/backend/dist/cjs/backend/src/payments/stripe/utils.js +0 -118
  106. package/backend/dist/cjs/backend/src/payments/stripe/webhooks.d.ts +0 -105
  107. package/backend/dist/cjs/backend/src/payments/stripe/webhooks.js +0 -627
  108. package/backend/dist/cjs/backend/src/plugins/browser.d.ts +0 -1
  109. package/backend/dist/cjs/backend/src/plugins/browser.js +0 -15
  110. package/backend/dist/cjs/backend/src/plugins/communication.d.ts +0 -70
  111. package/backend/dist/cjs/backend/src/plugins/communication.js +0 -196
  112. package/backend/dist/cjs/backend/src/plugins/mail/mail.d.ts +0 -255
  113. package/backend/dist/cjs/backend/src/plugins/mail/mail.js +0 -381
  114. package/backend/dist/cjs/backend/src/plugins/mail/ui.d.ts +0 -297
  115. package/backend/dist/cjs/backend/src/plugins/mail/ui.js +0 -1370
  116. package/backend/dist/cjs/backend/src/plugins/pdf.d.ts +0 -1
  117. package/backend/dist/cjs/backend/src/plugins/pdf.js +0 -1456
  118. package/backend/dist/cjs/backend/src/plugins/thread_monitor.d.ts +0 -18
  119. package/backend/dist/cjs/backend/src/plugins/thread_monitor.js +0 -116
  120. package/backend/dist/cjs/backend/src/rate_limit.d.ts +0 -148
  121. package/backend/dist/cjs/backend/src/rate_limit.js +0 -543
  122. package/backend/dist/cjs/backend/src/route.d.ts +0 -39
  123. package/backend/dist/cjs/backend/src/route.js +0 -172
  124. package/backend/dist/cjs/backend/src/server.d.ts +0 -502
  125. package/backend/dist/cjs/backend/src/server.js +0 -1713
  126. package/backend/dist/cjs/backend/src/server.old.d.ts +0 -594
  127. package/backend/dist/cjs/backend/src/server.old.js +0 -2058
  128. package/backend/dist/cjs/backend/src/splash_screen.d.ts +0 -93
  129. package/backend/dist/cjs/backend/src/splash_screen.js +0 -119
  130. package/backend/dist/cjs/backend/src/status.d.ts +0 -89
  131. package/backend/dist/cjs/backend/src/status.js +0 -211
  132. package/backend/dist/cjs/backend/src/stream.d.ts +0 -494
  133. package/backend/dist/cjs/backend/src/stream.js +0 -1370
  134. package/backend/dist/cjs/backend/src/users.d.ts +0 -926
  135. package/backend/dist/cjs/backend/src/users.js +0 -2223
  136. package/backend/dist/cjs/backend/src/utils.d.ts +0 -22
  137. package/backend/dist/cjs/backend/src/utils.js +0 -626
  138. package/backend/dist/cjs/backend/src/view.d.ts +0 -115
  139. package/backend/dist/cjs/backend/src/view.js +0 -519
  140. package/backend/dist/cjs/backend/src/vinc.d.ts +0 -6
  141. package/backend/dist/cjs/backend/src/vinc.js +0 -40
  142. package/backend/dist/cjs/backend/src/volt.d.ts +0 -24
  143. package/backend/dist/cjs/backend/src/volt.js +0 -72
  144. package/backend/dist/cjs/frontend/src/modules/request.d.ts +0 -70
  145. package/backend/dist/cjs/frontend/src/modules/request.js +0 -99
  146. package/backend/dist/cjs/package.json +0 -1
  147. package/backend/dist/esm/backend/src/blacklist.d.ts +0 -12
  148. package/backend/dist/esm/backend/src/blacklist.js +0 -52
  149. package/backend/dist/esm/backend/src/cli.d.ts +0 -2
  150. package/backend/dist/esm/backend/src/cli.js +0 -211
  151. package/backend/dist/esm/backend/src/database/collection.d.ts +0 -1765
  152. package/backend/dist/esm/backend/src/database/collection.js +0 -3779
  153. package/backend/dist/esm/backend/src/database/database.d.ts +0 -92
  154. package/backend/dist/esm/backend/src/database/database.js +0 -214
  155. package/backend/dist/esm/backend/src/database/document.d.ts +0 -1
  156. package/backend/dist/esm/backend/src/database/document.js +0 -558
  157. package/backend/dist/esm/backend/src/database/filters/filters.d.ts +0 -6
  158. package/backend/dist/esm/backend/src/database/filters/filters.js +0 -1
  159. package/backend/dist/esm/backend/src/database/filters/strict_filter.d.ts +0 -223
  160. package/backend/dist/esm/backend/src/database/filters/strict_filter.js +0 -3
  161. package/backend/dist/esm/backend/src/database/filters/strict_filter_test.d.ts +0 -1
  162. package/backend/dist/esm/backend/src/database/filters/strict_filter_test.js +0 -505
  163. package/backend/dist/esm/backend/src/database/filters/strict_filter_test_v0.d.ts +0 -1
  164. package/backend/dist/esm/backend/src/database/filters/strict_filter_test_v0.js +0 -712
  165. package/backend/dist/esm/backend/src/database/filters/strict_filter_v0.d.ts +0 -50
  166. package/backend/dist/esm/backend/src/database/filters/strict_filter_v0.js +0 -5
  167. package/backend/dist/esm/backend/src/database/filters/strict_filter_v1.d.ts +0 -76
  168. package/backend/dist/esm/backend/src/database/filters/strict_filter_v1.js +0 -44
  169. package/backend/dist/esm/backend/src/database/filters/strict_filter_v2.d.ts +0 -75
  170. package/backend/dist/esm/backend/src/database/filters/strict_filter_v2.js +0 -5
  171. package/backend/dist/esm/backend/src/database/filters/strict_filter_v3.d.ts +0 -219
  172. package/backend/dist/esm/backend/src/database/filters/strict_filter_v3.js +0 -1
  173. package/backend/dist/esm/backend/src/database/filters/strict_update_filter.d.ts +0 -165
  174. package/backend/dist/esm/backend/src/database/filters/strict_update_filter.js +0 -5
  175. package/backend/dist/esm/backend/src/database/filters/strict_update_filter_test.d.ts +0 -5
  176. package/backend/dist/esm/backend/src/database/filters/strict_update_filter_test.js +0 -415
  177. package/backend/dist/esm/backend/src/database/flatten.d.ts +0 -78
  178. package/backend/dist/esm/backend/src/database/flatten.js +0 -22
  179. package/backend/dist/esm/backend/src/database/flatten_test.d.ts +0 -1
  180. package/backend/dist/esm/backend/src/database/flatten_test.js +0 -174
  181. package/backend/dist/esm/backend/src/database/quota/quoata_v2.d.ts +0 -533
  182. package/backend/dist/esm/backend/src/database/quota/quoata_v2.js +0 -1155
  183. package/backend/dist/esm/backend/src/database/quota/quota.d.ts +0 -551
  184. package/backend/dist/esm/backend/src/database/quota/quota.js +0 -1219
  185. package/backend/dist/esm/backend/src/database/quota/quota_v1.d.ts +0 -534
  186. package/backend/dist/esm/backend/src/database/quota/quota_v1.js +0 -1242
  187. package/backend/dist/esm/backend/src/database/quota/safe_int.d.ts +0 -412
  188. package/backend/dist/esm/backend/src/database/quota/safe_int.js +0 -810
  189. package/backend/dist/esm/backend/src/endpoint.d.ts +0 -346
  190. package/backend/dist/esm/backend/src/endpoint.js +0 -479
  191. package/backend/dist/esm/backend/src/errors/index.d.ts +0 -7
  192. package/backend/dist/esm/backend/src/errors/index.js +0 -7
  193. package/backend/dist/esm/backend/src/errors/internal_external.d.ts +0 -52
  194. package/backend/dist/esm/backend/src/errors/internal_external.js +0 -86
  195. package/backend/dist/esm/backend/src/errors/invalid_usage_error.d.ts +0 -41
  196. package/backend/dist/esm/backend/src/errors/invalid_usage_error.js +0 -33
  197. package/backend/dist/esm/backend/src/errors/system_error.d.ts +0 -261
  198. package/backend/dist/esm/backend/src/errors/system_error.js +0 -444
  199. package/backend/dist/esm/backend/src/events.d.ts +0 -97
  200. package/backend/dist/esm/backend/src/events.js +0 -5
  201. package/backend/dist/esm/backend/src/frontend.d.ts +0 -11
  202. package/backend/dist/esm/backend/src/frontend.js +0 -12
  203. package/backend/dist/esm/backend/src/image_endpoint.d.ts +0 -44
  204. package/backend/dist/esm/backend/src/image_endpoint.js +0 -196
  205. package/backend/dist/esm/backend/src/index.d.ts +0 -23
  206. package/backend/dist/esm/backend/src/index.js +0 -26
  207. package/backend/dist/esm/backend/src/logger.d.ts +0 -5
  208. package/backend/dist/esm/backend/src/logger.js +0 -8
  209. package/backend/dist/esm/backend/src/meta.d.ts +0 -112
  210. package/backend/dist/esm/backend/src/meta.js +0 -152
  211. package/backend/dist/esm/backend/src/payments/paddle.d.ts +0 -329
  212. package/backend/dist/esm/backend/src/payments/paddle.js +0 -2276
  213. package/backend/dist/esm/backend/src/payments/stripe/checkout.d.ts +0 -113
  214. package/backend/dist/esm/backend/src/payments/stripe/checkout.js +0 -356
  215. package/backend/dist/esm/backend/src/payments/stripe/customers.d.ts +0 -17
  216. package/backend/dist/esm/backend/src/payments/stripe/customers.js +0 -193
  217. package/backend/dist/esm/backend/src/payments/stripe/error.d.ts +0 -74
  218. package/backend/dist/esm/backend/src/payments/stripe/error.js +0 -51
  219. package/backend/dist/esm/backend/src/payments/stripe/events.d.ts +0 -155
  220. package/backend/dist/esm/backend/src/payments/stripe/events.js +0 -5
  221. package/backend/dist/esm/backend/src/payments/stripe/meters.d.ts +0 -105
  222. package/backend/dist/esm/backend/src/payments/stripe/meters.js +0 -318
  223. package/backend/dist/esm/backend/src/payments/stripe/payment_methods.d.ts +0 -58
  224. package/backend/dist/esm/backend/src/payments/stripe/payment_methods.js +0 -135
  225. package/backend/dist/esm/backend/src/payments/stripe/products.d.ts +0 -519
  226. package/backend/dist/esm/backend/src/payments/stripe/products.js +0 -896
  227. package/backend/dist/esm/backend/src/payments/stripe/stripe.d.ts +0 -215
  228. package/backend/dist/esm/backend/src/payments/stripe/stripe.js +0 -464
  229. package/backend/dist/esm/backend/src/payments/stripe/subscriptions.d.ts +0 -172
  230. package/backend/dist/esm/backend/src/payments/stripe/subscriptions.js +0 -754
  231. package/backend/dist/esm/backend/src/payments/stripe/utils.d.ts +0 -63
  232. package/backend/dist/esm/backend/src/payments/stripe/utils.js +0 -131
  233. package/backend/dist/esm/backend/src/payments/stripe/webhooks.d.ts +0 -105
  234. package/backend/dist/esm/backend/src/payments/stripe/webhooks.js +0 -752
  235. package/backend/dist/esm/backend/src/plugins/browser.d.ts +0 -1
  236. package/backend/dist/esm/backend/src/plugins/browser.js +0 -170
  237. package/backend/dist/esm/backend/src/plugins/communication.d.ts +0 -70
  238. package/backend/dist/esm/backend/src/plugins/communication.js +0 -169
  239. package/backend/dist/esm/backend/src/plugins/mail/mail.d.ts +0 -255
  240. package/backend/dist/esm/backend/src/plugins/mail/mail.js +0 -396
  241. package/backend/dist/esm/backend/src/plugins/mail/ui.d.ts +0 -297
  242. package/backend/dist/esm/backend/src/plugins/mail/ui.js +0 -1400
  243. package/backend/dist/esm/backend/src/plugins/pdf.d.ts +0 -1
  244. package/backend/dist/esm/backend/src/plugins/pdf.js +0 -1694
  245. package/backend/dist/esm/backend/src/plugins/thread_monitor.d.ts +0 -18
  246. package/backend/dist/esm/backend/src/plugins/thread_monitor.js +0 -120
  247. package/backend/dist/esm/backend/src/rate_limit.d.ts +0 -148
  248. package/backend/dist/esm/backend/src/rate_limit.js +0 -667
  249. package/backend/dist/esm/backend/src/route.d.ts +0 -39
  250. package/backend/dist/esm/backend/src/route.js +0 -222
  251. package/backend/dist/esm/backend/src/server.d.ts +0 -502
  252. package/backend/dist/esm/backend/src/server.js +0 -2034
  253. package/backend/dist/esm/backend/src/server.old.d.ts +0 -594
  254. package/backend/dist/esm/backend/src/server.old.js +0 -2630
  255. package/backend/dist/esm/backend/src/splash_screen.d.ts +0 -93
  256. package/backend/dist/esm/backend/src/splash_screen.js +0 -156
  257. package/backend/dist/esm/backend/src/status.d.ts +0 -89
  258. package/backend/dist/esm/backend/src/status.js +0 -213
  259. package/backend/dist/esm/backend/src/stream.d.ts +0 -494
  260. package/backend/dist/esm/backend/src/stream.js +0 -1611
  261. package/backend/dist/esm/backend/src/users.d.ts +0 -926
  262. package/backend/dist/esm/backend/src/users.js +0 -2423
  263. package/backend/dist/esm/backend/src/utils.d.ts +0 -22
  264. package/backend/dist/esm/backend/src/utils.js +0 -463
  265. package/backend/dist/esm/backend/src/view.d.ts +0 -115
  266. package/backend/dist/esm/backend/src/view.js +0 -584
  267. package/backend/dist/esm/backend/src/vinc.d.ts +0 -6
  268. package/backend/dist/esm/backend/src/vinc.js +0 -6
  269. package/backend/dist/esm/backend/src/volt.d.ts +0 -24
  270. package/backend/dist/esm/backend/src/volt.js +0 -27
  271. package/backend/dist/esm/frontend/src/modules/request.d.ts +0 -70
  272. package/backend/dist/esm/frontend/src/modules/request.js +0 -117
  273. package/backend/old/file_watcher.ts +0 -359
  274. package/backend/old/request.deprc.js +0 -626
  275. package/backend/old/response.deprc.js +0 -354
  276. package/frontend/dist/backend/src/database/collection.d.ts +0 -1765
  277. package/frontend/dist/backend/src/database/collection.js +0 -3779
  278. package/frontend/dist/backend/src/database/database.d.ts +0 -92
  279. package/frontend/dist/backend/src/database/database.js +0 -214
  280. package/frontend/dist/backend/src/database/filters/filters.d.ts +0 -6
  281. package/frontend/dist/backend/src/database/filters/filters.js +0 -1
  282. package/frontend/dist/backend/src/database/filters/strict_filter.d.ts +0 -223
  283. package/frontend/dist/backend/src/database/filters/strict_filter.js +0 -3
  284. package/frontend/dist/backend/src/database/filters/strict_update_filter.d.ts +0 -165
  285. package/frontend/dist/backend/src/database/filters/strict_update_filter.js +0 -5
  286. package/frontend/dist/backend/src/database/flatten.d.ts +0 -78
  287. package/frontend/dist/backend/src/database/flatten.js +0 -22
  288. package/frontend/dist/backend/src/endpoint.d.ts +0 -346
  289. package/frontend/dist/backend/src/endpoint.js +0 -479
  290. package/frontend/dist/backend/src/errors/index.d.ts +0 -7
  291. package/frontend/dist/backend/src/errors/index.js +0 -7
  292. package/frontend/dist/backend/src/errors/internal_external.d.ts +0 -52
  293. package/frontend/dist/backend/src/errors/internal_external.js +0 -86
  294. package/frontend/dist/backend/src/errors/invalid_usage_error.d.ts +0 -41
  295. package/frontend/dist/backend/src/errors/invalid_usage_error.js +0 -33
  296. package/frontend/dist/backend/src/errors/system_error.d.ts +0 -261
  297. package/frontend/dist/backend/src/errors/system_error.js +0 -444
  298. package/frontend/dist/backend/src/events.d.ts +0 -97
  299. package/frontend/dist/backend/src/events.js +0 -5
  300. package/frontend/dist/backend/src/frontend.d.ts +0 -11
  301. package/frontend/dist/backend/src/frontend.js +0 -12
  302. package/frontend/dist/backend/src/image_endpoint.d.ts +0 -44
  303. package/frontend/dist/backend/src/image_endpoint.js +0 -196
  304. package/frontend/dist/backend/src/meta.d.ts +0 -112
  305. package/frontend/dist/backend/src/meta.js +0 -152
  306. package/frontend/dist/backend/src/payments/paddle.d.ts +0 -329
  307. package/frontend/dist/backend/src/payments/paddle.js +0 -2276
  308. package/frontend/dist/backend/src/payments/stripe/checkout.d.ts +0 -113
  309. package/frontend/dist/backend/src/payments/stripe/checkout.js +0 -356
  310. package/frontend/dist/backend/src/payments/stripe/customers.d.ts +0 -17
  311. package/frontend/dist/backend/src/payments/stripe/customers.js +0 -193
  312. package/frontend/dist/backend/src/payments/stripe/error.d.ts +0 -74
  313. package/frontend/dist/backend/src/payments/stripe/error.js +0 -51
  314. package/frontend/dist/backend/src/payments/stripe/events.d.ts +0 -155
  315. package/frontend/dist/backend/src/payments/stripe/events.js +0 -5
  316. package/frontend/dist/backend/src/payments/stripe/meters.d.ts +0 -105
  317. package/frontend/dist/backend/src/payments/stripe/meters.js +0 -318
  318. package/frontend/dist/backend/src/payments/stripe/payment_methods.d.ts +0 -58
  319. package/frontend/dist/backend/src/payments/stripe/payment_methods.js +0 -135
  320. package/frontend/dist/backend/src/payments/stripe/products.d.ts +0 -519
  321. package/frontend/dist/backend/src/payments/stripe/products.js +0 -896
  322. package/frontend/dist/backend/src/payments/stripe/stripe.d.ts +0 -215
  323. package/frontend/dist/backend/src/payments/stripe/stripe.js +0 -464
  324. package/frontend/dist/backend/src/payments/stripe/subscriptions.d.ts +0 -172
  325. package/frontend/dist/backend/src/payments/stripe/subscriptions.js +0 -754
  326. package/frontend/dist/backend/src/payments/stripe/utils.d.ts +0 -63
  327. package/frontend/dist/backend/src/payments/stripe/utils.js +0 -131
  328. package/frontend/dist/backend/src/payments/stripe/webhooks.d.ts +0 -105
  329. package/frontend/dist/backend/src/payments/stripe/webhooks.js +0 -752
  330. package/frontend/dist/backend/src/plugins/mail/mail.d.ts +0 -255
  331. package/frontend/dist/backend/src/plugins/mail/mail.js +0 -396
  332. package/frontend/dist/backend/src/plugins/mail/ui.d.ts +0 -297
  333. package/frontend/dist/backend/src/plugins/mail/ui.js +0 -1400
  334. package/frontend/dist/backend/src/rate_limit.d.ts +0 -148
  335. package/frontend/dist/backend/src/rate_limit.js +0 -667
  336. package/frontend/dist/backend/src/route.d.ts +0 -39
  337. package/frontend/dist/backend/src/route.js +0 -222
  338. package/frontend/dist/backend/src/server.d.ts +0 -502
  339. package/frontend/dist/backend/src/server.js +0 -2034
  340. package/frontend/dist/backend/src/splash_screen.d.ts +0 -93
  341. package/frontend/dist/backend/src/splash_screen.js +0 -156
  342. package/frontend/dist/backend/src/status.d.ts +0 -89
  343. package/frontend/dist/backend/src/status.js +0 -213
  344. package/frontend/dist/backend/src/stream.d.ts +0 -494
  345. package/frontend/dist/backend/src/stream.js +0 -1611
  346. package/frontend/dist/backend/src/users.d.ts +0 -926
  347. package/frontend/dist/backend/src/users.js +0 -2423
  348. package/frontend/dist/backend/src/utils.d.ts +0 -22
  349. package/frontend/dist/backend/src/utils.js +0 -463
  350. package/frontend/dist/backend/src/view.d.ts +0 -115
  351. package/frontend/dist/backend/src/view.js +0 -584
  352. package/frontend/dist/frontend/src/elements/base.d.ts +0 -3743
  353. package/frontend/dist/frontend/src/elements/base.js +0 -12151
  354. package/frontend/dist/frontend/src/elements/module.d.ts +0 -95
  355. package/frontend/dist/frontend/src/elements/module.js +0 -216
  356. package/frontend/dist/frontend/src/elements/register_element.d.ts +0 -3
  357. package/frontend/dist/frontend/src/elements/register_element.js +0 -22
  358. package/frontend/dist/frontend/src/elements/resize_query_manager.d.ts +0 -0
  359. package/frontend/dist/frontend/src/elements/resize_query_manager.js +0 -150
  360. package/frontend/dist/frontend/src/elements/types.d.ts +0 -52
  361. package/frontend/dist/frontend/src/elements/types.js +0 -5
  362. package/frontend/dist/frontend/src/index.d.ts +0 -21
  363. package/frontend/dist/frontend/src/index.js +0 -29
  364. package/frontend/dist/frontend/src/modules/attachment.d.ts +0 -126
  365. package/frontend/dist/frontend/src/modules/attachment.js +0 -306
  366. package/frontend/dist/frontend/src/modules/auth.d.ts +0 -44
  367. package/frontend/dist/frontend/src/modules/auth.js +0 -80
  368. package/frontend/dist/frontend/src/modules/color.d.ts +0 -160
  369. package/frontend/dist/frontend/src/modules/color.js +0 -316
  370. package/frontend/dist/frontend/src/modules/compression.d.ts +0 -39
  371. package/frontend/dist/frontend/src/modules/compression.js +0 -102
  372. package/frontend/dist/frontend/src/modules/cookies.d.ts +0 -44
  373. package/frontend/dist/frontend/src/modules/cookies.js +0 -143
  374. package/frontend/dist/frontend/src/modules/events.d.ts +0 -31
  375. package/frontend/dist/frontend/src/modules/events.js +0 -79
  376. package/frontend/dist/frontend/src/modules/google.d.ts +0 -23
  377. package/frontend/dist/frontend/src/modules/google.js +0 -52
  378. package/frontend/dist/frontend/src/modules/meta.d.ts +0 -14
  379. package/frontend/dist/frontend/src/modules/meta.js +0 -48
  380. package/frontend/dist/frontend/src/modules/paddle.d.ts +0 -1207
  381. package/frontend/dist/frontend/src/modules/paddle.js +0 -2594
  382. package/frontend/dist/frontend/src/modules/request.d.ts +0 -70
  383. package/frontend/dist/frontend/src/modules/request.js +0 -117
  384. package/frontend/dist/frontend/src/modules/settings.d.ts +0 -3
  385. package/frontend/dist/frontend/src/modules/settings.js +0 -5
  386. package/frontend/dist/frontend/src/modules/statics.d.ts +0 -21
  387. package/frontend/dist/frontend/src/modules/statics.js +0 -43
  388. package/frontend/dist/frontend/src/modules/stripe/cart.d.ts +0 -112
  389. package/frontend/dist/frontend/src/modules/stripe/cart.js +0 -321
  390. package/frontend/dist/frontend/src/modules/stripe/checkout.d.ts +0 -7
  391. package/frontend/dist/frontend/src/modules/stripe/checkout.js +0 -37
  392. package/frontend/dist/frontend/src/modules/stripe/index.m.d.ts +0 -6
  393. package/frontend/dist/frontend/src/modules/stripe/index.m.js +0 -6
  394. package/frontend/dist/frontend/src/modules/stripe/payments.d.ts +0 -58
  395. package/frontend/dist/frontend/src/modules/stripe/payments.js +0 -92
  396. package/frontend/dist/frontend/src/modules/support.d.ts +0 -30
  397. package/frontend/dist/frontend/src/modules/support.js +0 -53
  398. package/frontend/dist/frontend/src/modules/theme.d.ts +0 -133
  399. package/frontend/dist/frontend/src/modules/theme.js +0 -406
  400. package/frontend/dist/frontend/src/modules/themes.d.ts +0 -12
  401. package/frontend/dist/frontend/src/modules/themes.js +0 -22
  402. package/frontend/dist/frontend/src/modules/user.d.ts +0 -164
  403. package/frontend/dist/frontend/src/modules/user.js +0 -270
  404. package/frontend/dist/frontend/src/modules/utils.d.ts +0 -176
  405. package/frontend/dist/frontend/src/modules/utils.js +0 -569
  406. package/frontend/dist/frontend/src/types/gradient.d.ts +0 -29
  407. package/frontend/dist/frontend/src/types/gradient.js +0 -79
  408. package/frontend/dist/frontend/src/ui/border_button.d.ts +0 -94
  409. package/frontend/dist/frontend/src/ui/border_button.js +0 -228
  410. package/frontend/dist/frontend/src/ui/button.d.ts +0 -241
  411. package/frontend/dist/frontend/src/ui/button.js +0 -682
  412. package/frontend/dist/frontend/src/ui/canvas.d.ts +0 -138
  413. package/frontend/dist/frontend/src/ui/canvas.js +0 -444
  414. package/frontend/dist/frontend/src/ui/checkbox.d.ts +0 -74
  415. package/frontend/dist/frontend/src/ui/checkbox.js +0 -321
  416. package/frontend/dist/frontend/src/ui/code.d.ts +0 -235
  417. package/frontend/dist/frontend/src/ui/code.js +0 -1007
  418. package/frontend/dist/frontend/src/ui/context_menu.d.ts +0 -36
  419. package/frontend/dist/frontend/src/ui/context_menu.js +0 -205
  420. package/frontend/dist/frontend/src/ui/css.d.ts +0 -16
  421. package/frontend/dist/frontend/src/ui/css.js +0 -48
  422. package/frontend/dist/frontend/src/ui/divider.d.ts +0 -15
  423. package/frontend/dist/frontend/src/ui/divider.js +0 -78
  424. package/frontend/dist/frontend/src/ui/dropdown.d.ts +0 -176
  425. package/frontend/dist/frontend/src/ui/dropdown.js +0 -481
  426. package/frontend/dist/frontend/src/ui/for_each.d.ts +0 -37
  427. package/frontend/dist/frontend/src/ui/for_each.js +0 -92
  428. package/frontend/dist/frontend/src/ui/form.d.ts +0 -34
  429. package/frontend/dist/frontend/src/ui/form.js +0 -233
  430. package/frontend/dist/frontend/src/ui/frame_modes.d.ts +0 -37
  431. package/frontend/dist/frontend/src/ui/frame_modes.js +0 -108
  432. package/frontend/dist/frontend/src/ui/google_map.d.ts +0 -24
  433. package/frontend/dist/frontend/src/ui/google_map.js +0 -106
  434. package/frontend/dist/frontend/src/ui/gradient.d.ts +0 -25
  435. package/frontend/dist/frontend/src/ui/gradient.js +0 -131
  436. package/frontend/dist/frontend/src/ui/image.d.ts +0 -111
  437. package/frontend/dist/frontend/src/ui/image.js +0 -576
  438. package/frontend/dist/frontend/src/ui/input.d.ts +0 -392
  439. package/frontend/dist/frontend/src/ui/input.js +0 -1201
  440. package/frontend/dist/frontend/src/ui/link.d.ts +0 -25
  441. package/frontend/dist/frontend/src/ui/link.js +0 -140
  442. package/frontend/dist/frontend/src/ui/list.d.ts +0 -37
  443. package/frontend/dist/frontend/src/ui/list.js +0 -170
  444. package/frontend/dist/frontend/src/ui/loader_button.d.ts +0 -80
  445. package/frontend/dist/frontend/src/ui/loader_button.js +0 -193
  446. package/frontend/dist/frontend/src/ui/loaders.d.ts +0 -57
  447. package/frontend/dist/frontend/src/ui/loaders.js +0 -157
  448. package/frontend/dist/frontend/src/ui/popup.d.ts +0 -94
  449. package/frontend/dist/frontend/src/ui/popup.js +0 -510
  450. package/frontend/dist/frontend/src/ui/pseudo.d.ts +0 -44
  451. package/frontend/dist/frontend/src/ui/pseudo.js +0 -154
  452. package/frontend/dist/frontend/src/ui/scroller.d.ts +0 -105
  453. package/frontend/dist/frontend/src/ui/scroller.js +0 -1253
  454. package/frontend/dist/frontend/src/ui/slider.d.ts +0 -45
  455. package/frontend/dist/frontend/src/ui/slider.js +0 -217
  456. package/frontend/dist/frontend/src/ui/spacer.d.ts +0 -15
  457. package/frontend/dist/frontend/src/ui/spacer.js +0 -78
  458. package/frontend/dist/frontend/src/ui/span.d.ts +0 -15
  459. package/frontend/dist/frontend/src/ui/span.js +0 -73
  460. package/frontend/dist/frontend/src/ui/stack.d.ts +0 -66
  461. package/frontend/dist/frontend/src/ui/stack.js +0 -335
  462. package/frontend/dist/frontend/src/ui/steps.d.ts +0 -131
  463. package/frontend/dist/frontend/src/ui/steps.js +0 -308
  464. package/frontend/dist/frontend/src/ui/style.d.ts +0 -17
  465. package/frontend/dist/frontend/src/ui/style.js +0 -73
  466. package/frontend/dist/frontend/src/ui/switch.d.ts +0 -69
  467. package/frontend/dist/frontend/src/ui/switch.js +0 -357
  468. package/frontend/dist/frontend/src/ui/table.d.ts +0 -100
  469. package/frontend/dist/frontend/src/ui/table.js +0 -405
  470. package/frontend/dist/frontend/src/ui/tabs.d.ts +0 -111
  471. package/frontend/dist/frontend/src/ui/tabs.js +0 -424
  472. package/frontend/dist/frontend/src/ui/text.d.ts +0 -15
  473. package/frontend/dist/frontend/src/ui/text.js +0 -83
  474. package/frontend/dist/frontend/src/ui/title.d.ts +0 -91
  475. package/frontend/dist/frontend/src/ui/title.js +0 -272
  476. package/frontend/dist/frontend/src/ui/ui.d.ts +0 -35
  477. package/frontend/dist/frontend/src/ui/ui.js +0 -38
  478. package/frontend/dist/frontend/src/ui/view.d.ts +0 -15
  479. package/frontend/dist/frontend/src/ui/view.js +0 -88
  480. package/frontend/dist/frontend/src/volt.d.ts +0 -20
  481. package/frontend/dist/frontend/src/volt.js +0 -27
  482. package/frontend/examples/theme/theme.ts +0 -58
  483. package/frontend/tools/bundle_d_ts.js +0 -71
  484. package/frontend/tools/convert_to_jsdoc_input.txt +0 -9452
  485. package/frontend/tools/convert_to_jsdoc_output.txt +0 -7626
  486. package/frontend/tools/convert_to_jsdoc_tmp.js +0 -345
  487. package/frontend/tools/scan_mixed_imports.js +0 -69
  488. /package/frontend/{dist/frontend/src/css → css}/adyen.css +0 -0
  489. /package/frontend/{dist/frontend/src/css → css}/volt.css +0 -0
@@ -1,2223 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var stdin_exports = {};
29
- __export(stdin_exports, {
30
- Users: () => Users
31
- });
32
- module.exports = __toCommonJS(stdin_exports);
33
- var crypto = __toESM(require("crypto"));
34
- var vlib = __toESM(require("@vandenberghinc/vlib"));
35
- var MailUI = __toESM(require("./plugins/mail/ui.js"));
36
- var import_mail = require("./plugins/mail/mail.js");
37
- var import_status = require("./status.js");
38
- var import_errors = require("./errors/index.js");
39
- var import_collection = require("./database/collection.js");
40
- class Users {
41
- // ---------------------------------------------------------
42
- // Readonly settings.
43
- // ---------------------------------------------------------
44
- /**
45
- * Number of random characters after `<prefix>_<uid>_`.
46
- * @warning If you change this, also update:
47
- * - {@link Users.LEGACY_TOKEN_SUFFIX_LENS} to include old size(s).
48
- * - Generators {@link _generate_api_key} and {@link _generate_token}.
49
- * - Parser {@link _parse_uid_from_token_api_key}.
50
- */
51
- static TOKEN_SUFFIX_LEN = 64;
52
- /** Accepted legacy suffix lengths; add old sizes here when rotating. */
53
- static LEGACY_TOKEN_SUFFIX_LENS = [];
54
- /**
55
- * Allowed characters for the random suffix.
56
- * @warning MUST NOT include `_` (delimiter). ASCII only for fast-path validation.
57
- */
58
- static TOKEN_SUFFIX_CHARSET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
59
- /**
60
- * UID length used by the generator.
61
- * @warning If you change this, add the old value to {@link Users.LEGACY_UID_LENGTHS}.
62
- */
63
- static UID_LENGTH = 16;
64
- /** Accepted legacy UID lengths; add old sizes here when rotating. */
65
- static LEGACY_UID_LENGTHS = [];
66
- /**
67
- * UID character set (ASCII). MUST NOT include `_`.
68
- */
69
- static UID_CHARSET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
70
- /**
71
- * Build an ASCII allow table for fast membership checks.
72
- * Index is charCode (0..127), value is 1 if allowed else 0.
73
- */
74
- static _build_ascii_allow(cs) {
75
- const tbl = new Uint8Array(128);
76
- for (let i = 0; i < cs.length; i++) {
77
- const c = cs.charCodeAt(i);
78
- if (c < 128)
79
- tbl[c] = 1;
80
- else
81
- throw new Error("Non-ASCII char in allowed charset; use ASCII-only here.");
82
- }
83
- return tbl;
84
- }
85
- /** ASCII allow table for token suffix validation (built from TOKEN_SUFFIX_CHARSET). */
86
- static TOKEN_SUFFIX_ALLOW = Users._build_ascii_allow(Users.TOKEN_SUFFIX_CHARSET);
87
- /** ASCII allow table for UID validation (built from UID_CHARSET). */
88
- static UID_ALLOW = Users._build_ascii_allow(Users.UID_CHARSET);
89
- // ---------------------------------------------------------
90
- // Attributes.
91
- // ---------------------------------------------------------
92
- /** The parent server instance. */
93
- server;
94
- /** The recipient email for support submit emails, defaults to `Server.smtp_sender`. */
95
- support_recipient;
96
- /** The avg wait time when sending 2FA codes. */
97
- avg_send_2fa_time = [];
98
- /** The database collection for token documents. */
99
- _tokens_db;
100
- /** The database collection for 2fa token documents. */
101
- _2fa_tokens_db;
102
- /** The database collection for user documents. */
103
- _users_db;
104
- /** Enable 2FA for user sign in. */
105
- enable_2fa;
106
- /** Enable 2FA account activation for user sign up. */
107
- enable_account_activation;
108
- /** The token expiration in seconds */
109
- token_expiration;
110
- /** Database collection for public (read:public, write:public) user documents. */
111
- public;
112
- /** Database collection for protected (read:public, write:private) user documents. */
113
- protected;
114
- /** Database collection for private (read:private, write:private) user documents. */
115
- private;
116
- // ---------------------------------------------------------
117
- // Constructor.
118
- // ---------------------------------------------------------
119
- /** Construct the users manager. */
120
- constructor(opts) {
121
- this.server = opts._server;
122
- this.enable_2fa = opts.enable_2fa ?? false;
123
- this.enable_account_activation = opts.enable_account_activation ?? true;
124
- this.token_expiration = opts.token_expiration ?? 86400;
125
- this.support_recipient = opts.support_recipient ?? this.server.mail?.sender;
126
- this._tokens_db = this.server.db.collection({
127
- name: "Volt.Server.Users.Tokens",
128
- indexes: ["uid", "token"],
129
- ttl: 1e3 * 3600 * 24 * 30
130
- // 30 days.
131
- });
132
- this._2fa_tokens_db = this.server.db.collection({
133
- name: "Volt.Server.Users.TwoFactorAuth",
134
- indexes: ["uid", "code"],
135
- ttl: 1e3 * 3600 * 24
136
- // 1 day.
137
- });
138
- this._users_db = this.server.db.collection({
139
- name: "Volt.Server.Users.Users",
140
- indexes: [
141
- { key: "uid", unique: true, forced: true },
142
- { key: "email", unique: true, forced: true },
143
- { key: "username", unique: true, forced: true },
144
- {
145
- key: "api_key",
146
- sparse: true,
147
- // api_key index sparse/partial so documents without api_key don’t bloat the index
148
- forced: true
149
- // hashed; non-unique is fine if you only store one per user, and we dont retrieve uid's alike by api key, but extract from raw api key string instead.
150
- }
151
- ]
152
- });
153
- this.public = this.server.db.collection({
154
- name: "Volt.Server.Users.Public",
155
- indexes: ["uid", "query"]
156
- });
157
- this.protected = this.server.db.collection({
158
- name: "Volt.Server.Users.Protected",
159
- indexes: ["uid", "query"]
160
- });
161
- this.private = this.server.db.collection({
162
- name: "Volt.Server.Users.Private",
163
- indexes: ["uid", "query"]
164
- });
165
- this.set_default_2fa_event();
166
- }
167
- // ---------------------------------------------------------
168
- // Utils.
169
- // ---------------------------------------------------------
170
- /** Generate a code. */
171
- _generate_code(length = 6) {
172
- const charset = "0123456789";
173
- let out = "";
174
- for (let i = 0; i < length; i++)
175
- out += charset[crypto.randomInt(charset.length)];
176
- return out;
177
- }
178
- /**
179
- * Generate a crypto str.
180
- * @warning ENSURE this does not add `_` to the charset, as this is used as a delimiter for tokens/api keys.
181
- */
182
- _generate_crypto_str(length = 32, charset) {
183
- let out = "";
184
- for (let i = 0; i < length; i++)
185
- out += charset[crypto.randomInt(charset.length)];
186
- return out;
187
- }
188
- /**
189
- * Derive a key with the async `crypto.scrypt` to avoid blocking the event loop.
190
- * Using the sync variant is CPU-bound and can stall Node’s main thread, enabling
191
- * trivial DoS via many concurrent hash ops. The async call runs in libuv’s
192
- * thread pool, preserving responsiveness under load with the same security.
193
- *
194
- * @param password - Secret/password or input buffer.
195
- * @param salt - Per-secret random salt.
196
- * @param keylen - Desired key length in bytes (default 64).
197
- * @returns Promise resolving to the derived key buffer.
198
- */
199
- _crypto_scrypt(password, salt, keylen = 64) {
200
- return new Promise((res, rej) => crypto.scrypt(password, salt, keylen, (e, dk) => e ? rej(e) : res(dk)));
201
- }
202
- /** Hash a password. */
203
- async _hash_password(plain) {
204
- const salt = crypto.randomBytes(16);
205
- const hash = await this._crypto_scrypt(plain, salt, 64);
206
- return `${salt.toString("hex")}:${hash.toString("hex")}`;
207
- }
208
- /** Verify a plain password vs stored hashed password. */
209
- async _verify_password(plain, stored) {
210
- const [saltHex, hashHex] = stored.split(":");
211
- const salt = Buffer.from(saltHex, "hex");
212
- const expected = Buffer.from(hashHex, "hex");
213
- const actual = await this._crypto_scrypt(plain, salt, expected.length);
214
- return crypto.timingSafeEqual(actual, expected);
215
- }
216
- /** Generate a unique user ID. */
217
- async _generate_uid() {
218
- let attempts = 0;
219
- const max_attempts = 1e4;
220
- while (attempts < max_attempts) {
221
- const uid = this._generate_crypto_str(Users.UID_LENGTH, Users.UID_CHARSET);
222
- if (await this.uid_exists(uid) === false)
223
- return uid;
224
- attempts++;
225
- }
226
- throw new Error("Failed to generate a unique uid after maximum attempts.");
227
- }
228
- /** Generate an API key. Format: `ak_<uid>_<suffix>` */
229
- _generate_api_key(uid) {
230
- return `ak_${uid}_${this._generate_crypto_str(Users.TOKEN_SUFFIX_LEN, Users.TOKEN_SUFFIX_CHARSET)}`;
231
- }
232
- /** Generate a token. Format: `tk_<uid>_<suffix>` */
233
- _generate_token(uid) {
234
- return `tk_${uid}_${this._generate_crypto_str(Users.TOKEN_SUFFIX_LEN, Users.TOKEN_SUFFIX_CHARSET)}`;
235
- }
236
- /**
237
- * Parse the uid from `<prefix>_<uid>_<suffix>`, where prefix is `ak_` or `tk_`,
238
- * `<uid>` passes {@link Users.is_valid_uid}, and `<suffix>`:
239
- * - length equals {@link Users.TOKEN_SUFFIX_LEN} or a legacy size; and
240
- * - every char is in {@link Users.TOKEN_SUFFIX_CHARSET} (ASCII).
241
- *
242
- * @warning If you change suffix length, add old sizes to
243
- * {@link Users.LEGACY_TOKEN_SUFFIX_LENS}. If you change charset, update
244
- * {@link Users.TOKEN_SUFFIX_CHARSET} (this table rebuilds automatically).
245
- * If you change delimiters/prefixes, update this and the generators together.
246
- */
247
- _parse_uid_from_token_api_key(input, expected_prefix) {
248
- if (typeof input !== "string" || !input.startsWith(expected_prefix))
249
- return void 0;
250
- const pfxLen = expected_prefix.length;
251
- const delimPos = input.indexOf("_", pfxLen);
252
- if (delimPos === -1)
253
- return void 0;
254
- const uid = input.slice(pfxLen, delimPos);
255
- if (uid.length === 0 || !this.is_valid_uid(uid))
256
- return void 0;
257
- const suffix = input.slice(delimPos + 1);
258
- const slen = suffix.length;
259
- if (slen !== Users.TOKEN_SUFFIX_LEN) {
260
- let ok = false;
261
- for (let i = 0; i < Users.LEGACY_TOKEN_SUFFIX_LENS.length; i++) {
262
- if (slen === Users.LEGACY_TOKEN_SUFFIX_LENS[i]) {
263
- ok = true;
264
- break;
265
- }
266
- }
267
- if (!ok)
268
- return void 0;
269
- }
270
- const allow = Users.TOKEN_SUFFIX_ALLOW;
271
- for (let i = 0; i < slen; i++) {
272
- const code = suffix.charCodeAt(i);
273
- if (code >= 128 || allow[code] === 0)
274
- return void 0;
275
- }
276
- return uid;
277
- }
278
- /**
279
- * Validate a proposed new password against basic rules and confirmation.
280
- * @param pass The new password to validate.
281
- * @param verify_pass The repeated password to confirm.
282
- * @returns An object with optional error message and invalid_fields mapping.
283
- */
284
- _verify_new_pass(pass, verify_pass) {
285
- let error = void 0;
286
- if (pass !== verify_pass) {
287
- error = "Passwords do not match.";
288
- } else if (pass.length < 8) {
289
- error = "The password should at least include eight characters.";
290
- } else if (pass.toLowerCase() === pass) {
291
- error = "The password should at least include one capital letter.";
292
- } else if (!/\d|[!@#$%^&*]/.test(pass)) {
293
- error = "The password should at least include one numeric or special character.";
294
- }
295
- if (error) {
296
- return { error, invalid_fields: { password: error, verify_password: error } };
297
- } else {
298
- return { error: void 0, invalid_fields: void 0 };
299
- }
300
- }
301
- // ---------------------------------------------------------
302
- // Authentication (private).
303
- // ---------------------------------------------------------
304
- /**
305
- * Generate and persist a new auth token for the given uid.
306
- * @param uid The user ID.
307
- * @returns The plaintext token string.
308
- */
309
- async _create_token(uid) {
310
- const token = this._generate_token(uid);
311
- await this._tokens_db.set({ uid }, {
312
- expiration: Date.now() + this.token_expiration * 1e3,
313
- token: await this._hash_password(token),
314
- active: true
315
- });
316
- return token;
317
- }
318
- /**
319
- * Deactivate the current token for the given uid.
320
- * @param uid The user ID.
321
- */
322
- async _deactivate_token(uid) {
323
- await this._tokens_db.set({ uid }, { active: false });
324
- }
325
- /**
326
- * Create and store a short-lived 2FA token (code).
327
- * @param uid_or_email The uid or email key used for the 2FA record.
328
- * @param expiration Expiration in seconds from now.
329
- * @returns The generated 2FA code.
330
- */
331
- async _create_2fa_token(uid_or_email, expiration) {
332
- const code = this._generate_code(6);
333
- await this._2fa_tokens_db.set({ uid: uid_or_email }, {
334
- expiration: Date.now() + expiration * 1e3,
335
- code,
336
- active: true
337
- });
338
- return code;
339
- }
340
- /**
341
- * Deactivate a stored 2FA token by uid/email key.
342
- * @param uid_or_email The uid or email key used for the 2FA record.
343
- */
344
- async _deactivate_2fa_token(uid_or_email) {
345
- await this._2fa_tokens_db.set({ uid: uid_or_email }, { active: false });
346
- }
347
- /**
348
- * Perform authentication on a request.
349
- * @returns An object on refusal, undefined on success.
350
- */
351
- async _authenticate(stream) {
352
- const authorization = stream.headers["authorization"];
353
- if (authorization !== void 0) {
354
- if (typeof authorization !== "string") {
355
- return {
356
- status: import_status.Status.bad_request,
357
- data: "Invalid authorization header."
358
- };
359
- }
360
- const match = authorization.match(/^Bearer\s+(\S+)$/i);
361
- if (!match) {
362
- return {
363
- status: import_status.Status.bad_request,
364
- data: 'Invalid authorization scheme, the authorization scheme must be "Bearer".'
365
- };
366
- }
367
- const api_key = match[1];
368
- const uid = this.get_uid_by_api_key(api_key);
369
- if (!uid) {
370
- return { status: import_status.Status.unauthorized, data: "Unauthorized." };
371
- }
372
- if (await this.verify_api_key_by_uid(uid, api_key) !== true) {
373
- return {
374
- status: import_status.Status.unauthorized,
375
- data: "Unauthorized."
376
- };
377
- }
378
- stream.uid = uid;
379
- return;
380
- } else {
381
- if (stream.cookies.T == null || stream.cookies.T.value == null) {
382
- return {
383
- status: 302,
384
- headers: { Location: `/signin?next=${encodeURIComponent(stream.endpoint)}` },
385
- data: "Permission denied."
386
- };
387
- }
388
- const token = stream.cookies.T.value;
389
- const uid = this.get_uid_by_token(token);
390
- if (!uid) {
391
- return {
392
- status: 302,
393
- headers: { Location: `/signin?next=${encodeURIComponent(stream.endpoint)}` },
394
- data: "Permission denied."
395
- };
396
- }
397
- if (await this.verify_token_by_uid(uid, token) !== true) {
398
- return {
399
- status: 302,
400
- headers: { Location: `/signin?next=${encodeURIComponent(stream.endpoint)}` },
401
- data: "Permission denied."
402
- };
403
- }
404
- stream.uid = uid;
405
- return;
406
- }
407
- }
408
- /**
409
- * Sign a user in, set cookies, and optionally send the success response.
410
- * @param stream The request stream.
411
- * @param uid The authenticated user's ID.
412
- * @param opts Optional settings (e.g., send: false to skip sending the response).
413
- */
414
- async _sign_in_response(stream, uid, opts) {
415
- const token = await this._create_token(uid);
416
- this._create_token_cookie(stream, token);
417
- await this._create_user_cookie(stream, uid);
418
- await this._create_detailed_user_cookie(stream, uid);
419
- if (opts?.send !== false) {
420
- stream.send({
421
- status: 200,
422
- data: { message: "Successfully signed in." }
423
- });
424
- }
425
- }
426
- // ---------------------------------------------------------
427
- // Cookies (private).
428
- // ---------------------------------------------------------
429
- /**
430
- * Create the auth token cookie on the response.
431
- * `T` is treated as a real authentication credential.
432
- *
433
- * @param stream The request stream.
434
- * @param token The token string or Token object.
435
- */
436
- _create_token_cookie(stream, token) {
437
- stream.set_header("Cache-Control", "max-age=0, no-cache, no-store, must-revalidate, proxy-revalidate");
438
- stream.set_header("Access-Control-Allow-Credentials", "true");
439
- const token_value = typeof token === "object" ? token.token : token;
440
- const max_age = this.token_expiration;
441
- stream.set_cookie({
442
- name: "T",
443
- value: token_value,
444
- path: "/",
445
- max_age,
446
- secure: true,
447
- http_only: true,
448
- same_site: "Lax"
449
- // REQUIRED for Stripe success/cancel redirects
450
- });
451
- }
452
- /**
453
- * Create user cookies (ID and activation flag).
454
- * These are user-state cookies, NOT auth credentials.
455
- *
456
- * @param stream The request stream.
457
- * @param uid The user ID, or invalid to clear.
458
- */
459
- async _create_user_cookie(stream, uid) {
460
- if (typeof uid === "string" && uid.length > 0) {
461
- stream.set_cookie({
462
- name: "UserID",
463
- value: uid,
464
- path: "/",
465
- secure: true,
466
- same_site: "Lax"
467
- });
468
- const is_activated = this.enable_account_activation ? await this.is_activated(uid) : true;
469
- stream.set_cookie({
470
- name: "UserActivated",
471
- value: is_activated ? "1" : "0",
472
- path: "/",
473
- secure: true,
474
- same_site: "Lax"
475
- });
476
- } else {
477
- stream.set_cookie({
478
- name: "UserID",
479
- value: "",
480
- path: "/",
481
- max_age: 0,
482
- secure: true,
483
- same_site: "Lax"
484
- });
485
- stream.set_cookie({
486
- name: "UserActivated",
487
- value: "0",
488
- path: "/",
489
- max_age: 0,
490
- secure: true,
491
- same_site: "Lax"
492
- });
493
- }
494
- }
495
- /**
496
- * Create non-HttpOnly cookies with detailed user info for frontend usage.
497
- * These are UI convenience cookies only.
498
- *
499
- * @param stream The request stream.
500
- * @param uid The user ID.
501
- */
502
- async _create_detailed_user_cookie(stream, uid) {
503
- const user = await this.get(uid);
504
- stream.set_cookie({
505
- name: "UserName",
506
- value: user.username ?? "",
507
- path: "/",
508
- secure: true,
509
- same_site: "Lax"
510
- });
511
- stream.set_cookie({
512
- name: "UserFirstName",
513
- value: user.first_name ?? "",
514
- path: "/",
515
- secure: true,
516
- same_site: "Lax"
517
- });
518
- stream.set_cookie({
519
- name: "UserLastName",
520
- value: user.last_name ?? "",
521
- path: "/",
522
- secure: true,
523
- same_site: "Lax"
524
- });
525
- stream.set_cookie({
526
- name: "UserEmail",
527
- value: user.email ?? "",
528
- path: "/",
529
- secure: true,
530
- same_site: "Lax"
531
- });
532
- }
533
- /**
534
- * Clear all default auth and user-related cookies.
535
- *
536
- * @param stream The request stream.
537
- */
538
- _reset_cookies(stream) {
539
- const clear = {
540
- path: "/",
541
- max_age: 0,
542
- secure: true,
543
- same_site: "Lax"
544
- };
545
- stream.set_cookie({ name: "T", value: "", http_only: true, ...clear });
546
- stream.set_cookie({ name: "UserID", value: "", ...clear });
547
- stream.set_cookie({ name: "UserActivated", value: "", ...clear });
548
- stream.set_cookie({ name: "UserName", value: "", ...clear });
549
- stream.set_cookie({ name: "UserFirstName", value: "", ...clear });
550
- stream.set_cookie({ name: "UserLastName", value: "", ...clear });
551
- stream.set_cookie({ name: "UserEmail", value: "", ...clear });
552
- }
553
- // ---------------------------------------------------------
554
- // 2FA mail.
555
- // Mail template.
556
- /** Build the base email layout used by the various transactional email builders. */
557
- _2fa_mail_template({ max_width = 400, children = [] }) {
558
- this.server.assert_mail();
559
- const style = this.server.mail.style;
560
- const { Title, Text, Image, Table, TableRow, TableData, VStack } = MailUI;
561
- let header;
562
- if (this.server.company.stroke_icon != null) {
563
- header = [
564
- Image(`${this.server.full_domain}${this.server.company.stroke_icon ?? ""}`).height(16)
565
- ];
566
- } else if (this.server.company.icon != null) {
567
- header = [
568
- Image(`${this.server.full_domain}${this.server.company.icon ?? ""}`).frame(20, 40)
569
- ];
570
- }
571
- if (header) {
572
- header = Table(TableRow(...header).wrap(true).center().center_vertical()).margin_bottom(15);
573
- }
574
- return MailUI.Mail(Table(TableData(Table(
575
- // Header.
576
- header,
577
- // Widget.
578
- Table(...children).background_color(style.widget_bg ?? "").border(`1px solid ${style.widget_border ?? ""}`).border_radius("10px").padding(40, 25, 25, 25).margin(0),
579
- // Copyright.
580
- Table(TableRow(Text(`Copyright \xA9 ${(/* @__PURE__ */ new Date()).getFullYear()} ${this.server.company.name}, ${this.server.company.legal_name} All Rights Included.
581
- ${this.server.company.street} ${this.server.company.house_number}, ${this.server.company.postal_code}, ${this.server.company.city}, ${this.server.company.province}, ${this.server.company.country}.
582
- ` + (this.server.company.tax_id == null ? "" : `VAT ID ${this.server.company.tax_id}`)).white_space("pre").display("inline-block").font_size(11).color(style.footer_fg).margin(0)).center().center_vertical()).margin(0, 0, 10, 0)
583
- ).max_width(max_width)).center()).padding(25, 20, 25, 20)).font_family(style.font).background(style.bg);
584
- }
585
- /**
586
- * Build the 2FA verification email content.
587
- */
588
- set_default_2fa_event() {
589
- this.server.on("2fa_mail", ({ code, username, email, date, ip, device }) => {
590
- this.server.assert_mail();
591
- const style = this.server.mail.style;
592
- const { Title, Text, Image, Table, TableRow, TableData, VStack } = MailUI;
593
- return this._2fa_mail_template({
594
- max_width: 400,
595
- children: [
596
- // Title.
597
- TableRow(Title("Verification Required").color(style.title_fg).width("fit-content").font_size(26)).center(),
598
- // Text.
599
- TableRow(Text("Please confirm your request with this 2FA code.").center().margin(10, 0, 20, 0).color(style.text_fg).font_size(18)),
600
- // Auth info.
601
- [
602
- ["Username", username],
603
- ["Email", email],
604
- ["Date", date],
605
- ["Ip Address", ip],
606
- ["Device", device]
607
- ].map((item) => {
608
- return [
609
- TableRow(VStack().margin_right(7.5).background_color(style.text_fg).border_radius("50%").frame(5, 5), Text(`<span style='font-weight: 600'>${item[0]}:</span> ${item[1]}`).color(style.text_fg).font_size(16).text_wrap("wrap").overflow_wrap("break-word").word_wrap("break-word")).wrap(true).center_vertical(),
610
- TableRow().fixed_frame(5, 5)
611
- ];
612
- }),
613
- // 2FA code.
614
- TableRow(Text(code).background(style.button_bg).border_radius("10px").padding(10, 15).center().color(style.button_fg).width("100%").margin(20, 0, 0, 0)),
615
- // Text.
616
- TableRow(Text("This 2FA code will be valid for 5 minutes.").color(style.text_fg).font_style("italic").font_size(12).margin_top(20).center())
617
- ]
618
- });
619
- });
620
- }
621
- // ---------------------------------------------------------
622
- // Initialization (private).
623
- // ---------------------------------------------------------
624
- /**
625
- * Initialize default authentication, user, and support endpoints.
626
- */
627
- async _initialize({ worker = false } = {}) {
628
- if (!worker) {
629
- this.server.endpoint({
630
- method: "POST",
631
- endpoint: "/volt/api/v1/auth/2fa",
632
- content_type: "application/json",
633
- rate_limit: "global",
634
- params: {
635
- email: "string"
636
- },
637
- callback: async (stream, params) => {
638
- let uid;
639
- if ((uid = await this.get_uid_by_email(params.email)) == null) {
640
- return stream.success({
641
- data: { message: "A 2FA code was sent if the specified email exists." }
642
- });
643
- }
644
- await this.send_2fa({ uid, stream });
645
- return stream.success({
646
- data: { message: "A 2FA code was sent if the specified email exists." }
647
- });
648
- }
649
- });
650
- this.server.endpoint({
651
- method: "POST",
652
- endpoint: "/volt/api/v1/auth/signin",
653
- content_type: "application/json",
654
- rate_limit: {
655
- limit: 10,
656
- interval: 60,
657
- group: "volt.auth"
658
- },
659
- callback: async (stream) => {
660
- const uniform_delay = async () => {
661
- if (this.avg_send_2fa_time.length >= 10) {
662
- const sorted = [...this.avg_send_2fa_time].sort((a, b) => a - b);
663
- const mid = Math.floor(sorted.length / 2);
664
- const median = sorted.length % 2 === 0 ? Math.floor((sorted[mid - 1] + sorted[mid]) / 2) : sorted[mid];
665
- await new Promise((res) => setTimeout(res, median));
666
- }
667
- };
668
- let email, email_err, username, username_err, password, uid, code;
669
- try {
670
- email = stream.param("email");
671
- } catch (err) {
672
- email_err = err;
673
- }
674
- try {
675
- username = stream.param("username");
676
- } catch (err) {
677
- username_err = err;
678
- }
679
- if (email_err && username_err) {
680
- await uniform_delay();
681
- return stream.error({
682
- status: import_status.Status.bad_request,
683
- type: "InvalidParams",
684
- message: email_err.message
685
- });
686
- }
687
- try {
688
- password = stream.param("password");
689
- } catch (err) {
690
- await uniform_delay();
691
- return stream.error({
692
- status: import_status.Status.bad_request,
693
- type: "InvalidParams",
694
- message: err.message
695
- });
696
- }
697
- if (email && email.indexOf("@") === -1) {
698
- username = email;
699
- email = void 0;
700
- } else if (username && username.indexOf("@") !== -1) {
701
- email = username;
702
- username = void 0;
703
- }
704
- if (email) {
705
- if ((uid = await this.get_uid_by_email(email)) == null) {
706
- await uniform_delay();
707
- return stream.error({
708
- status: import_status.Status.unauthorized,
709
- type: "Unauthorized",
710
- message: "Unauthorized.",
711
- invalid_fields: {
712
- "email": "Invalid or unrecognized email",
713
- "password": "Invalid or unrecognized password"
714
- }
715
- });
716
- }
717
- } else if (username) {
718
- if ((uid = await this.get_uid(username)) == null) {
719
- await uniform_delay();
720
- return stream.error({
721
- status: import_status.Status.unauthorized,
722
- type: "Unauthorized",
723
- message: "Unauthorized.",
724
- invalid_fields: {
725
- "username": "Invalid or unrecognized username",
726
- "password": "Invalid or unrecognized password"
727
- }
728
- });
729
- }
730
- } else {
731
- await uniform_delay();
732
- return stream.error({
733
- status: import_status.Status.unauthorized,
734
- type: "Unauthorized",
735
- message: "Unauthorized.",
736
- invalid_fields: {
737
- "username": "Invalid or unrecognized username",
738
- "password": "Invalid or unrecognized password"
739
- }
740
- });
741
- }
742
- if (await this.verify_password(uid, password)) {
743
- if (this.enable_2fa) {
744
- try {
745
- code = stream.param("code");
746
- } catch (err2) {
747
- const start_time = Date.now();
748
- await this.send_2fa({ uid, stream });
749
- if (this.avg_send_2fa_time.length >= 1e4) {
750
- this.avg_send_2fa_time.shift();
751
- }
752
- this.avg_send_2fa_time.push(Date.now() - start_time);
753
- return stream.error({
754
- status: import_status.Status.two_factor_auth_required,
755
- message: "2FA required.",
756
- type: "2FARequired",
757
- data: { error: "2FA required." }
758
- });
759
- }
760
- const err = await this.verify_2fa(uid, code);
761
- if (err) {
762
- return stream.error({
763
- status: import_status.Status.unauthorized,
764
- message: "Invalid 2FA code.",
765
- type: "Invalid2FACode",
766
- invalid_fields: {
767
- "code": err
768
- }
769
- });
770
- }
771
- }
772
- return await this._sign_in_response(stream, uid);
773
- }
774
- await uniform_delay();
775
- return stream.error({
776
- status: import_status.Status.unauthorized,
777
- type: "Unauthorized",
778
- message: "Unauthorized.",
779
- invalid_fields: {
780
- "username": "Invalid or unrecognized username",
781
- "password": "Invalid or unrecognized password"
782
- }
783
- });
784
- }
785
- });
786
- this.server.endpoint({
787
- method: "POST",
788
- endpoint: "/volt/api/v1/auth/signout",
789
- content_type: "application/json",
790
- authenticated: true,
791
- rate_limit: "global",
792
- callback: async (stream) => {
793
- await this._deactivate_token(stream.uid);
794
- this._reset_cookies(stream);
795
- return stream.success({
796
- data: { message: "Successfully signed out." }
797
- });
798
- }
799
- });
800
- this.server.endpoint({
801
- method: "POST",
802
- endpoint: "/volt/api/v1/auth/signup",
803
- content_type: "application/json",
804
- rate_limit: [
805
- "global",
806
- { limit: 5, interval: 60 * 10, group: "volt/Users/signup" }
807
- ],
808
- params: {
809
- username: { type: "string", allow_empty: false },
810
- first_name: { type: "string", allow_empty: false },
811
- last_name: { type: "string", allow_empty: false },
812
- email: { type: "string", allow_empty: false },
813
- password: { type: "string", allow_empty: false },
814
- verify_password: { type: "string", allow_empty: false },
815
- phone_number: { type: "string", required: false },
816
- code: { type: "string", required: false }
817
- },
818
- callback: async (stream, params) => {
819
- console.log("signup 1", params);
820
- const { error, invalid_fields } = this._verify_new_pass(params.password, params.verify_password);
821
- if (error) {
822
- return stream.error({
823
- status: import_status.Status.bad_request,
824
- type: "InvalidParams",
825
- message: error,
826
- invalid_fields: invalid_fields ?? void 0
827
- });
828
- }
829
- if (await this.username_exists(params.username)) {
830
- throw new import_errors.ExternalError({
831
- type: "UsernameAlreadyExists",
832
- message: `Username "${params.username}" is already registered.`,
833
- status: import_status.Status.bad_request,
834
- invalid_fields: { "username": "Username is already registered" }
835
- });
836
- }
837
- if (await this.email_exists(params.email)) {
838
- throw new import_errors.ExternalError({
839
- type: "EmailAlreadyExists",
840
- message: `Email "${params.email}" is already registered.`,
841
- status: import_status.Status.bad_request,
842
- invalid_fields: { "email": "Email is already registered" }
843
- });
844
- }
845
- if (this.enable_2fa) {
846
- if (params.code == null || params.code == "") {
847
- const start_time = Date.now();
848
- await this.send_2fa({
849
- _email: params.email,
850
- _username: params.username,
851
- stream,
852
- uid: void 0
853
- // keep uid required param but use _email sys arg here.
854
- });
855
- if (this.avg_send_2fa_time.length >= 1e4) {
856
- this.avg_send_2fa_time.shift();
857
- }
858
- this.avg_send_2fa_time.push(Date.now() - start_time);
859
- return stream.error({
860
- status: import_status.Status.two_factor_auth_required,
861
- message: "2FA required.",
862
- type: "TwoFactorAuthRequired"
863
- });
864
- }
865
- const err = await this.verify_2fa(params.email, params.code);
866
- if (err) {
867
- return stream.error({
868
- status: import_status.Status.unauthorized,
869
- type: "Invalid2FACode",
870
- message: "Invalid 2FA code.",
871
- invalid_fields: {
872
- "code": err
873
- }
874
- });
875
- }
876
- }
877
- let uid;
878
- try {
879
- uid = await this.create({
880
- // dont unpack params since we are performing param validation inside create().
881
- first_name: params.first_name,
882
- last_name: params.last_name,
883
- username: params.username,
884
- email: params.email,
885
- password: params.password,
886
- verify_password: params.verify_password,
887
- phone_number: params.phone_number,
888
- is_activated: true,
889
- // already verified by 2fa or no 2fa is enabled.
890
- _check_username_email: false
891
- // already checked.
892
- });
893
- } catch (err) {
894
- return stream.error({
895
- status: import_status.Status.bad_request,
896
- type: "InvalidParams",
897
- message: err.message,
898
- invalid_fields: err.invalid_fields || {}
899
- });
900
- }
901
- return await this._sign_in_response(stream, uid);
902
- }
903
- });
904
- this.server.endpoint({
905
- method: "POST",
906
- endpoint: "/volt/api/v1/auth/activate",
907
- content_type: "application/json",
908
- rate_limit: "global",
909
- params: {
910
- code: "string"
911
- },
912
- callback: async (stream, params) => {
913
- let uid = stream.uid;
914
- if (uid == null) {
915
- uid = stream.cookies.UserID?.value;
916
- if (!uid || uid === "null" || uid === "undefined" || uid === "-1") {
917
- uid = void 0;
918
- }
919
- }
920
- if (uid == null) {
921
- return stream.error({ status: import_status.Status.forbidden, message: "Permission denied." });
922
- }
923
- const err = await this.verify_2fa(uid, params.code);
924
- if (err) {
925
- return stream.error({
926
- status: import_status.Status.forbidden,
927
- message: "Permission denied.",
928
- invalid_fields: {
929
- "code": err
930
- }
931
- });
932
- }
933
- await this.set_activated(uid, true);
934
- await this._create_user_cookie(stream, uid);
935
- return stream.success({ data: { message: "Successfully activated your account." } });
936
- }
937
- });
938
- this.server.endpoint({
939
- method: "POST",
940
- endpoint: "/volt/api/v1/auth/forgot_password",
941
- content_type: "application/json",
942
- rate_limit: "global",
943
- params: {
944
- email: { type: "string", allow_empty: false },
945
- code: { type: "string", allow_empty: false },
946
- password: { type: "string", allow_empty: false },
947
- verify_password: { type: "string", allow_empty: false }
948
- },
949
- callback: async (stream, params) => {
950
- const { error, invalid_fields } = this._verify_new_pass(params.password, params.verify_password);
951
- if (error) {
952
- return stream.error({
953
- status: import_status.Status.bad_request,
954
- message: error,
955
- invalid_fields: invalid_fields ?? void 0
956
- });
957
- }
958
- let uid;
959
- if ((uid = await this.get_uid_by_email(params.email)) == null) {
960
- return stream.error({ status: import_status.Status.forbidden, message: "Invalid email." });
961
- }
962
- const err = await this.verify_2fa(uid, params.code);
963
- if (err) {
964
- return stream.error({
965
- status: import_status.Status.forbidden,
966
- message: "Invalid 2FA code.",
967
- invalid_fields: {
968
- "code": "Invalid code"
969
- }
970
- });
971
- }
972
- await this.set_password(uid, params.password);
973
- return await this._sign_in_response(stream, uid);
974
- }
975
- });
976
- this.server.endpoint({
977
- method: "GET",
978
- endpoint: "/volt/api/v1/user",
979
- content_type: "application/json",
980
- authenticated: true,
981
- rate_limit: "global",
982
- params: {
983
- // detailed: { type: "boolean", default: false },
984
- },
985
- callback: async (stream) => {
986
- const user = await this.get(stream.uid);
987
- if (user.password) {
988
- user.password = "*".repeat(user.password.length);
989
- }
990
- if (user.api_key) {
991
- user.api_key = "*".repeat(user.api_key.length);
992
- }
993
- user.first_name ??= "";
994
- user.last_name ??= "";
995
- user.username ??= "";
996
- user.email ??= "";
997
- user.password ??= "";
998
- user.support_pin ??= "";
999
- const frontend = {
1000
- uid: user.uid,
1001
- username: user.username ?? "",
1002
- first_name: user.first_name ?? "",
1003
- last_name: user.last_name ?? "",
1004
- email: user.email ?? "",
1005
- phone_number: user.phone_number,
1006
- // optional
1007
- created_at: user.created_at,
1008
- support_pin: user.support_pin ?? "",
1009
- is_activated: user.is_activated === true,
1010
- has_api_key: Boolean(user.api_key)
1011
- };
1012
- return stream.success({ data: frontend });
1013
- }
1014
- });
1015
- this.server.endpoint({
1016
- method: "POST",
1017
- endpoint: "/volt/api/v1/user",
1018
- content_type: "application/json",
1019
- authenticated: true,
1020
- rate_limit: "global",
1021
- params: {
1022
- first_name: { type: "string", required: false, allow_empty: false },
1023
- last_name: { type: "string", required: false, allow_empty: false },
1024
- phone_number: { type: "string", required: false, allow_empty: false },
1025
- // is_activated:{ type: "boolean", required: false },
1026
- // password:{ type: "string", required: false }, // dont allow password.
1027
- username: { type: "string", required: false, allow_empty: false },
1028
- email: { type: "string", required: false, allow_empty: false }
1029
- },
1030
- callback: async (stream, params) => {
1031
- if (params.password != null) {
1032
- return stream.error({
1033
- status: import_status.Status.unauthorized,
1034
- message: "This endpoint does not allow for password changes.",
1035
- invalid_fields: {
1036
- password: "This endpoint does not allow for password changes."
1037
- }
1038
- });
1039
- }
1040
- if (params.is_activated != null) {
1041
- return stream.error({
1042
- status: import_status.Status.unauthorized,
1043
- message: "This endpoint does not allow for user activation changes.",
1044
- invalid_fields: {
1045
- is_activated: "This endpoint does not allow for user activation changes."
1046
- }
1047
- });
1048
- }
1049
- await this.set(stream.uid, {
1050
- first_name: params.first_name,
1051
- last_name: params.last_name,
1052
- phone_number: params.phone_number,
1053
- username: params.username,
1054
- email: params.email
1055
- });
1056
- await this._sign_in_response(stream, stream.uid, { send: false });
1057
- return stream.success({ data: { message: "Successfully updated your account." } });
1058
- }
1059
- });
1060
- this.server.endpoint({
1061
- method: "POST",
1062
- endpoint: "/volt/api/v1/user/change_password",
1063
- content_type: "application/json",
1064
- authenticated: true,
1065
- rate_limit: "global",
1066
- params: {
1067
- current_password: { type: "string", allow_empty: false },
1068
- password: { type: "string", allow_empty: false },
1069
- verify_password: { type: "string", allow_empty: false }
1070
- },
1071
- callback: async (stream, params) => {
1072
- if (await this.verify_password(stream.uid, params.current_password) !== true) {
1073
- return stream.error({
1074
- status: import_status.Status.unauthorized,
1075
- message: "Incorrect password.",
1076
- invalid_fields: {
1077
- current_password: "Incorrect password."
1078
- }
1079
- });
1080
- }
1081
- const { error, invalid_fields } = this._verify_new_pass(params.password, params.verify_password);
1082
- if (error) {
1083
- return stream.error({
1084
- status: import_status.Status.bad_request,
1085
- message: error,
1086
- invalid_fields: invalid_fields ?? void 0
1087
- });
1088
- }
1089
- await this.set_password(stream.uid, params.password);
1090
- return stream.success({
1091
- status: import_status.Status.success,
1092
- data: { message: "Successfully updated your password." }
1093
- });
1094
- }
1095
- });
1096
- this.server.endpoint({
1097
- method: "DELETE",
1098
- endpoint: "/volt/api/v1/user",
1099
- content_type: "application/json",
1100
- authenticated: true,
1101
- rate_limit: "global",
1102
- callback: async (stream) => {
1103
- await this.delete(stream.uid);
1104
- this._reset_cookies(stream);
1105
- return stream.success({
1106
- status: import_status.Status.success,
1107
- data: { message: "Successfully deleted your account." }
1108
- });
1109
- }
1110
- });
1111
- this.server.endpoint({
1112
- method: "POST",
1113
- endpoint: "/volt/api/v1/user/api_key",
1114
- content_type: "application/json",
1115
- authenticated: true,
1116
- rate_limit: "global",
1117
- callback: async (stream) => {
1118
- return stream.success({
1119
- data: {
1120
- message: "Successfully generated an API key.",
1121
- api_key: await this.generate_api_key(stream.uid)
1122
- }
1123
- });
1124
- }
1125
- });
1126
- this.server.endpoint({
1127
- method: "GET",
1128
- endpoint: "/volt/api/v1/user/has_api_key",
1129
- content_type: "application/json",
1130
- authenticated: true,
1131
- rate_limit: "global",
1132
- callback: async (stream) => {
1133
- return stream.success({
1134
- data: {
1135
- message: "Successfully checked your API key.",
1136
- has_api_key: await this.has_api_key(stream.uid)
1137
- }
1138
- });
1139
- }
1140
- });
1141
- this.server.endpoint({
1142
- method: "DELETE",
1143
- endpoint: "/volt/api/v1/user/api_key",
1144
- content_type: "application/json",
1145
- authenticated: true,
1146
- rate_limit: "global",
1147
- callback: async (stream) => {
1148
- await this.revoke_api_key(stream.uid);
1149
- return stream.send({
1150
- status: import_status.Status.success,
1151
- data: { message: "Successfully revoked your API key." }
1152
- });
1153
- }
1154
- });
1155
- const init_user_data_query = (stream, uid, query) => {
1156
- if (typeof query === "object") {
1157
- if ("uid" in query) {
1158
- return stream.error({
1159
- message: "Invalid query parameter, the 'uid' field is not allowed.",
1160
- type: "invalid_query_parameter",
1161
- status: import_status.Status.bad_request,
1162
- invalid_fields: {
1163
- query: "Invalid query parameter, the 'uid' field is not allowed."
1164
- }
1165
- });
1166
- }
1167
- if ("data" in query) {
1168
- return stream.error({
1169
- message: "Invalid query parameter, the 'data' field is not allowed.",
1170
- type: "invalid_query_parameter",
1171
- status: import_status.Status.bad_request,
1172
- invalid_fields: {
1173
- query: "Invalid query parameter, the 'data' field is not allowed."
1174
- }
1175
- });
1176
- }
1177
- if ("query" in query) {
1178
- return stream.error({
1179
- message: "Invalid query parameter, the 'query' field is not allowed.",
1180
- type: "invalid_query_parameter",
1181
- status: import_status.Status.bad_request,
1182
- invalid_fields: {
1183
- query: "Invalid query parameter, the 'query' field is not allowed."
1184
- }
1185
- });
1186
- }
1187
- if ("_id" in query) {
1188
- return stream.error({
1189
- message: "Invalid query parameter, the '_id' field is not allowed.",
1190
- type: "invalid_query_parameter",
1191
- status: import_status.Status.bad_request,
1192
- invalid_fields: {
1193
- query: "Invalid query parameter, the '_id' field is not allowed."
1194
- }
1195
- });
1196
- }
1197
- }
1198
- return typeof query === "string" ? { uid, query } : { ...query, uid };
1199
- };
1200
- this.server.endpoint({
1201
- method: "GET",
1202
- endpoint: "/volt/api/v1/user/data",
1203
- content_type: "application/json",
1204
- authenticated: true,
1205
- rate_limit: "global",
1206
- params: {
1207
- query: { type: ["string", "object"], allow_empty: false },
1208
- default: { type: Users.Endpoints.JsonValueSchemaType, required: false }
1209
- },
1210
- callback: async (stream, params) => {
1211
- const query = init_user_data_query(stream, stream.uid, params.query);
1212
- if (!query)
1213
- return;
1214
- try {
1215
- const document = await this.public.load(query, {
1216
- default: params.default ? { ...query, data: params.default } : void 0,
1217
- retry: 3
1218
- });
1219
- return stream.send({
1220
- status: import_status.Status.success,
1221
- data: {
1222
- message: "Successfully loaded the requested document.",
1223
- data: document.data
1224
- }
1225
- });
1226
- } catch (e) {
1227
- if (e instanceof import_collection.Collection.NotFoundError) {
1228
- return stream.error({
1229
- message: "Document not found.",
1230
- type: "document_not_found",
1231
- status: import_status.Status.not_found
1232
- });
1233
- }
1234
- throw e;
1235
- }
1236
- }
1237
- });
1238
- this.server.endpoint({
1239
- method: "POST",
1240
- endpoint: "/volt/api/v1/user/data",
1241
- content_type: "application/json",
1242
- authenticated: true,
1243
- rate_limit: "global",
1244
- params: {
1245
- query: { type: ["string", "object"], allow_empty: false },
1246
- data: { type: Users.Endpoints.JsonValueSchemaType }
1247
- },
1248
- callback: async (stream, params) => {
1249
- const query = init_user_data_query(stream, stream.uid, params.query);
1250
- if (!query)
1251
- return;
1252
- await this.public.set(query, { data: params.data }, { retry: 3, flatten: true });
1253
- return stream.send({
1254
- status: import_status.Status.success,
1255
- data: { message: "Successfully saved." }
1256
- });
1257
- }
1258
- });
1259
- this.server.endpoint({
1260
- method: "DELETE",
1261
- endpoint: "/volt/api/v1/user/data",
1262
- content_type: "application/json",
1263
- authenticated: true,
1264
- rate_limit: "global",
1265
- params: {
1266
- query: { type: ["string", "object"], allow_empty: false }
1267
- },
1268
- callback: async (stream, params) => {
1269
- const query = init_user_data_query(stream, stream.uid, params.query);
1270
- if (!query)
1271
- return;
1272
- await this.public.delete(query);
1273
- return stream.send({
1274
- status: import_status.Status.success,
1275
- data: { message: "Successfully deleted." }
1276
- });
1277
- }
1278
- });
1279
- this.server.endpoint({
1280
- method: "GET",
1281
- endpoint: "/volt/api/v1/user/data/protected",
1282
- content_type: "application/json",
1283
- authenticated: true,
1284
- rate_limit: "global",
1285
- params: {
1286
- query: { type: ["string", "object"], allow_empty: false },
1287
- default: { type: Users.Endpoints.JsonValueSchemaType, required: false }
1288
- },
1289
- callback: async (stream, params) => {
1290
- const query = init_user_data_query(stream, stream.uid, params.query);
1291
- if (!query)
1292
- return;
1293
- try {
1294
- const document = await this.protected.load(query, {
1295
- default: params.default ? { ...query, data: params.default } : void 0,
1296
- retry: 3
1297
- });
1298
- return stream.send({
1299
- status: import_status.Status.success,
1300
- data: {
1301
- message: "Successfully loaded the requested document.",
1302
- data: document.data
1303
- }
1304
- });
1305
- } catch (e) {
1306
- if (e instanceof import_collection.Collection.NotFoundError) {
1307
- return stream.error({
1308
- message: "Document not found.",
1309
- type: "document_not_found",
1310
- status: import_status.Status.not_found
1311
- });
1312
- }
1313
- throw e;
1314
- }
1315
- }
1316
- });
1317
- this.server.endpoint({
1318
- method: "GET",
1319
- endpoint: "/volt/api/v1/support/pin",
1320
- content_type: "application/json",
1321
- authenticated: true,
1322
- rate_limit: "global",
1323
- callback: async (stream) => {
1324
- const pin = await this.get_support_pin(stream.uid);
1325
- return stream.success({
1326
- data: {
1327
- message: "Successfully retrieved your support PIN.",
1328
- pin
1329
- }
1330
- });
1331
- }
1332
- });
1333
- this.server.endpoint({
1334
- method: "POST",
1335
- endpoint: "/volt/api/v1/support/submit",
1336
- content_type: "application/json",
1337
- rate_limit: [
1338
- "global",
1339
- {
1340
- interval: 3600 * 24,
1341
- limit: 5
1342
- }
1343
- ],
1344
- params: {
1345
- subject: { type: "string", required: false, allow_empty: false },
1346
- type: { type: "string", required: false, allow_empty: false },
1347
- support_pin: { type: "string", required: false, allow_empty: false },
1348
- email: { type: "string", required: false, allow_empty: false },
1349
- first_name: { type: "string", required: false, allow_empty: false },
1350
- last_name: { type: "string", required: false, allow_empty: false },
1351
- summary: { type: "string", required: true, allow_empty: false },
1352
- detailed: { type: "string", required: false, allow_empty: false },
1353
- attachments: { type: "array", required: false, value_schema: {
1354
- type: "object",
1355
- schema: import_mail.Mail.Attachment.RestAPI.Schema
1356
- } }
1357
- },
1358
- callback: async (stream, params) => {
1359
- if (!this.support_recipient) {
1360
- throw new import_errors.ExternalError({
1361
- status: import_status.Status.unavailable_for_legal_reasons,
1362
- type: "NoSMTPSender",
1363
- message: "This server does not have a SMTP sender configured."
1364
- });
1365
- }
1366
- this.server.assert_mail();
1367
- let user = null, email, first_name, last_name;
1368
- if (stream.uid == null) {
1369
- try {
1370
- email = stream.param("email");
1371
- first_name = stream.param("first_name");
1372
- last_name = stream.param("last_name");
1373
- } catch (err) {
1374
- return stream.error({ status: import_status.Status.bad_request, message: err.message });
1375
- }
1376
- } else {
1377
- user = await this.get(stream.uid);
1378
- email = user.email;
1379
- first_name = user.first_name;
1380
- last_name = user.last_name;
1381
- }
1382
- let body = "";
1383
- const subject = params.subject || (params.type == null ? "Support" : `Support ${params.type}`);
1384
- body += `<h1>${subject}</h1>`;
1385
- if (params.type) {
1386
- body += `<span style='font-weight: bold'>Type</span>: ${params.type}<br>`;
1387
- }
1388
- if (user) {
1389
- body += `<span style='font-weight: bold'>UID</span>: ${stream.uid}<br>`;
1390
- body += `<span style='font-weight: bold'>User</span>: ${user.username}<br>`;
1391
- }
1392
- body += `<span style='font-weight: bold'>Email</span>: ${email}<br>`;
1393
- body += `<span style='font-weight: bold'>First Name</span>: ${first_name}<br>`;
1394
- body += `<span style='font-weight: bold'>Last Name</span>: ${last_name}<br>`;
1395
- if (stream.uid != null) {
1396
- const support_pin = await this.get_support_pin(stream.uid);
1397
- body += `<span style='font-weight: bold'>Support PIN</span>: ${support_pin} <span style='color: green'>verified</span><br>`;
1398
- } else if (params.support_pin) {
1399
- body += `<span style='font-weight: bold'>Support PIN</span>: ${params.support_pin} <span style='color: red'>not yet verified</span><br>`;
1400
- } else {
1401
- body += `<span style='font-weight: bold'>Support PIN</span>: Unknown<br>`;
1402
- }
1403
- if (params.summary) {
1404
- body += `<br><span style='font-weight: bold'>Summary</span>:<br>${params.summary}<br>`;
1405
- }
1406
- if (params.detailed) {
1407
- body += `<br><span style='font-weight: bold'>Detailed</span>:<br>${params.detailed}<br>`;
1408
- }
1409
- for (const key of Object.keys(params)) {
1410
- switch (key) {
1411
- case "subject":
1412
- case "type":
1413
- case "support_pin":
1414
- case "summary":
1415
- case "detailed":
1416
- case "attachments":
1417
- case "recipient":
1418
- continue;
1419
- default:
1420
- body += `<br><span style='font-weight: bold'>${key}</span>: ${params[key]}<br>`;
1421
- }
1422
- }
1423
- body += "<br>";
1424
- await this.server.mail.send({
1425
- // Only send to support_recipient since we dont want users/people to send emails to random people.
1426
- recipients: [this.support_recipient],
1427
- subject,
1428
- body,
1429
- attachments: params.attachments,
1430
- max_attachments_size: 5 * 1024 * 1024,
1431
- // 5 MB
1432
- allow_untrusted_urls: false
1433
- });
1434
- return stream.success({
1435
- data: { message: "Successfully sent your request." }
1436
- });
1437
- }
1438
- });
1439
- }
1440
- }
1441
- // ---------------------------------------------------------
1442
- // Public methods.
1443
- // ---------------------------------------------------------
1444
- /**
1445
- * Validate a UID against ASCII charset and allowed lengths (current + legacy).
1446
- * @dev_warning
1447
- * If you change {@link Users.UID_CHARSET} or {@link Users.UID_LENGTH},
1448
- * update {@link Users.LEGACY_UID_LENGTHS} for backward compatibility.
1449
- *
1450
- * @docs
1451
- */
1452
- is_valid_uid(uid) {
1453
- const len = uid.length;
1454
- if (len !== Users.UID_LENGTH) {
1455
- let ok = false;
1456
- for (let i = 0; i < Users.LEGACY_UID_LENGTHS.length; i++) {
1457
- if (len === Users.LEGACY_UID_LENGTHS[i]) {
1458
- ok = true;
1459
- break;
1460
- }
1461
- }
1462
- if (!ok)
1463
- return false;
1464
- }
1465
- const allow = Users.UID_ALLOW;
1466
- for (let i = 0; i < len; i++) {
1467
- const code = uid.charCodeAt(i);
1468
- if (code >= 128 || allow[code] === 0)
1469
- return false;
1470
- }
1471
- return true;
1472
- }
1473
- /**
1474
- * Check if a uid exists.
1475
- * @param uid The user ID to check.
1476
- * @returns True if a user with the given uid exists.
1477
- *
1478
- * @docs
1479
- */
1480
- async uid_exists(uid) {
1481
- return await this._users_db.exists({ uid });
1482
- }
1483
- /**
1484
- * Check if a username exists.
1485
- * @returns Returns a boolean indicating whether the username exists or not.
1486
- * @param username The username to check.
1487
- * @example
1488
- * const exists = await server.users.username_exists("someusername");
1489
- *
1490
- * @docs
1491
- */
1492
- async username_exists(username) {
1493
- return await this._users_db.exists({ username });
1494
- }
1495
- /**
1496
- * Check if an email exists.
1497
- * @returns Returns a boolean indicating whether the email exists or not.
1498
- * @param email The email to check.
1499
- * @example
1500
- * const exists = await server.users.email_exists("some@email.com");
1501
- *
1502
- * @docs
1503
- */
1504
- async email_exists(email) {
1505
- return await this._users_db.exists({ email });
1506
- }
1507
- /**
1508
- * Check if a user account is activated.
1509
- * @returns Returns a boolean indicating whether the account is activated or not.
1510
- * @param uid The id of the user.
1511
- * @example
1512
- * const activated = await server.users.is_activated("0");
1513
- *
1514
- * @docs
1515
- */
1516
- async is_activated(uid) {
1517
- return (await this.get(uid)).is_activated === true;
1518
- }
1519
- /**
1520
- * Set the activated status of a user account.
1521
- * @param uid The user id.
1522
- * @param is_activated The boolean with the new activated status.
1523
- * @example
1524
- * await server.users.set_activated("1", true);
1525
- *
1526
- * @docs
1527
- */
1528
- async set_activated(uid, is_activated) {
1529
- await this._sys_set(uid, { is_activated });
1530
- }
1531
- /**
1532
- * Create a user account. Only the hashed password will be saved.
1533
- * @returns Returns the uid of the newly created user.
1534
- * @param first_name The user's first name.
1535
- * @param last_name The user's last name.
1536
- * @param username The username of the new account.
1537
- * @param email The email of the new account.
1538
- * @param password The password of the new account.
1539
- * @param verify_password An optional second password input to check against the first input to ensure its the same.
1540
- * @param phone_number The phone number of the user account.
1541
- * @param is_activated Whether the account should be set to activated; by default `!Server.enable_account_activation`.
1542
- * @example
1543
- * const uid = await server.users.create({
1544
- * first_name: "John",
1545
- * last_name: "Doe",
1546
- * username: "johndoe",
1547
- * email: "johndoe@email.com",
1548
- * password: "HelloWorld!"
1549
- * });
1550
- *
1551
- * @docs
1552
- */
1553
- async create({ first_name, last_name, username, email, password, verify_password, phone_number = "", is_activated = void 0, _check_username_email = false }) {
1554
- vlib.schema.validate(arguments[0], {
1555
- unknown: false,
1556
- throw: true,
1557
- schema: {
1558
- first_name: "string",
1559
- last_name: "string",
1560
- username: "string",
1561
- email: "string",
1562
- password: "string",
1563
- verify_password: { type: "string", required: false },
1564
- phone_number: { type: "string", required: false },
1565
- is_activated: { type: "boolean", required: false },
1566
- _check_username_email: { type: "boolean", required: false }
1567
- }
1568
- });
1569
- const { error, invalid_fields } = this._verify_new_pass(password, verify_password ?? password);
1570
- if (error) {
1571
- throw new import_errors.ExternalError({
1572
- type: "InvalidPassword",
1573
- message: `Invalid password: ${error}.`,
1574
- status: import_status.Status.bad_request,
1575
- invalid_fields
1576
- });
1577
- }
1578
- if (_check_username_email) {
1579
- if (await this.username_exists(username)) {
1580
- throw new import_errors.ExternalError({
1581
- type: "UsernameAlreadyExists",
1582
- message: `Username "${username}" is already registered.`,
1583
- status: import_status.Status.bad_request,
1584
- invalid_fields: { "username": "Username is already registered" }
1585
- });
1586
- }
1587
- if (await this.email_exists(email)) {
1588
- throw new import_errors.ExternalError({
1589
- type: "EmailAlreadyExists",
1590
- message: `Email "${email}" is already registered.`,
1591
- status: import_status.Status.bad_request,
1592
- invalid_fields: { "email": "Email is already registered" }
1593
- });
1594
- }
1595
- }
1596
- const uid = await this._generate_uid();
1597
- const user = {
1598
- uid,
1599
- first_name,
1600
- last_name,
1601
- username,
1602
- email,
1603
- password: await this._hash_password(password),
1604
- phone_number,
1605
- created_at: Date.now(),
1606
- api_key: void 0,
1607
- // api key can be undefined, it doesnt have to be set.
1608
- support_pin: this._generate_code(8),
1609
- is_activated: is_activated ?? !this.enable_account_activation
1610
- };
1611
- await this._users_db.set({ uid }, user);
1612
- for (const cb of this.server.events.get("create_user")) {
1613
- try {
1614
- await cb({ user });
1615
- } catch (err) {
1616
- this.server.log.error(new Error(`Encountered an error in event callback "create_user".`, { cause: err }));
1617
- }
1618
- }
1619
- return uid;
1620
- }
1621
- /**
1622
- * Delete a user account and associated data.
1623
- * @param uid The user id.
1624
- * @example
1625
- * await server.users.delete("0");
1626
- *
1627
- * @docs
1628
- */
1629
- async delete(uid) {
1630
- const user = await this.get(uid);
1631
- if (!user) {
1632
- throw new import_errors.ExternalError({ status: import_status.Status.not_found, type: "UserNotFound", message: `User with uid "${uid}" not found.` });
1633
- }
1634
- await this._users_db.delete_many({ uid });
1635
- await this._tokens_db.delete_many({ uid });
1636
- await this._2fa_tokens_db.delete_many({ uid });
1637
- await this.public.delete_many({ uid });
1638
- await this.protected.delete_many({ uid });
1639
- await this.private.delete_many({ uid });
1640
- if (this.server.payments !== void 0) {
1641
- await this.server.payments.delete_user(uid);
1642
- }
1643
- for (const cb of this.server.events.get("delete_user")) {
1644
- try {
1645
- await cb({ user });
1646
- } catch (err) {
1647
- this.server.log.error(new Error(`Encountered an error in event callback "delete_user".`, { cause: err }));
1648
- }
1649
- }
1650
- }
1651
- /**
1652
- * Set a user's first name. Throws if uid does not exist.
1653
- * @param uid The user id.
1654
- * @param first_name The new first name.
1655
- * @example
1656
- * await server.users.set_first_name("1", "John");
1657
- *
1658
- * @docs
1659
- */
1660
- async set_first_name(uid, first_name) {
1661
- await this._sys_set(uid, { first_name });
1662
- }
1663
- /**
1664
- * Set a user's last name. Throws if uid does not exist.
1665
- * @param uid The user id.
1666
- * @param last_name The new last name.
1667
- * @example
1668
- * await server.users.set_last_name("1", "Doe");
1669
- *
1670
- * @docs
1671
- */
1672
- async set_last_name(uid, last_name) {
1673
- await this._sys_set(uid, { last_name });
1674
- }
1675
- /**
1676
- * Set a user's username. Throws if uid does not exist.
1677
- * @param uid The user id.
1678
- * @param username The new username.
1679
- * @example
1680
- * await server.users.set_username("1", "newusername");
1681
- *
1682
- * @docs
1683
- */
1684
- async set_username(uid, username) {
1685
- if (await this.username_exists(username)) {
1686
- throw Error(`Username "${username}" already exists.`);
1687
- }
1688
- await this._sys_set(uid, { username });
1689
- }
1690
- /**
1691
- * Set a user's email. Throws if uid does not exist.
1692
- * @param uid The user id.
1693
- * @param email The new email.
1694
- * @example
1695
- * await server.users.set_email("1", "new@email.com");
1696
- *
1697
- * @docs
1698
- */
1699
- async set_email(uid, email) {
1700
- if (await this.email_exists(email)) {
1701
- throw Error(`Email "${email}" already exists.`);
1702
- }
1703
- await this._sys_set(uid, { email });
1704
- }
1705
- /**
1706
- * Set a user's password. Throws on invalid input or unknown uid.
1707
- * @param uid The user id.
1708
- * @param password The new password.
1709
- * @example
1710
- * await server.users.set_password("1", "XXXXXX");
1711
- *
1712
- * @docs
1713
- */
1714
- async set_password(uid, password, verify_password) {
1715
- const { error } = this._verify_new_pass(password, verify_password ?? password);
1716
- if (error) {
1717
- throw Error(`Invalid password "${password}": ${error}.`);
1718
- }
1719
- await this._sys_set(uid, { password: await this._hash_password(password) });
1720
- }
1721
- /**
1722
- * Update an existing user object.
1723
- *
1724
- * This function only updates the passed user attributes, unpresent attributes will not be deleted.
1725
- *
1726
- * If the uid does not exist an `Error` will be thrown.
1727
- *
1728
- * A password will automatically be hashed if passed.
1729
- *
1730
- * Updating the API key through this function is not allowed (wont work).
1731
- *
1732
- * @warning Does not upsert documents.
1733
- *
1734
- * @docs
1735
- */
1736
- async set(uid, data) {
1737
- let old_data;
1738
- const set_data = {};
1739
- for (const key of Object.keys(data)) {
1740
- if (data[key] === void 0)
1741
- continue;
1742
- switch (key) {
1743
- case "first_name":
1744
- case "last_name":
1745
- case "phone_number":
1746
- if (!data[key]) {
1747
- throw Error(`Invalid ${key.replaceAll("_", " ")} "${data[key]}".`);
1748
- }
1749
- set_data[key] = data[key];
1750
- break;
1751
- case "is_activated":
1752
- set_data[key] = data[key];
1753
- break;
1754
- case "password": {
1755
- if (!data[key]) {
1756
- throw Error(`Password may not be empty.`);
1757
- }
1758
- const { error } = this._verify_new_pass(data[key], data[key]);
1759
- if (error) {
1760
- throw Error(`Invalid password "${data[key]}": ${error}.`);
1761
- }
1762
- set_data[key] = await this._hash_password(data[key]);
1763
- break;
1764
- }
1765
- case "username":
1766
- if (!data.username) {
1767
- throw Error(`Invalid username "${data.username}".`);
1768
- }
1769
- if (old_data === void 0) {
1770
- old_data = await this.get(uid);
1771
- }
1772
- if (old_data.username !== data.username) {
1773
- if (await this.username_exists(data.username)) {
1774
- throw Error(`Username "${data.username}" already exists.`);
1775
- }
1776
- set_data[key] = data[key];
1777
- }
1778
- break;
1779
- case "email":
1780
- if (!data.email) {
1781
- throw Error(`Invalid email "${data.email}".`);
1782
- }
1783
- if (old_data === void 0) {
1784
- old_data = await this.get(uid);
1785
- }
1786
- if (old_data.email !== data.email) {
1787
- if (await this.email_exists(data.email)) {
1788
- throw Error(`Email "${data.email}" already exists.`);
1789
- }
1790
- set_data[key] = data[key];
1791
- }
1792
- break;
1793
- default:
1794
- delete set_data[key];
1795
- break;
1796
- }
1797
- }
1798
- await this._users_db.set({ uid }, set_data, { upsert: false });
1799
- }
1800
- /**
1801
- * Insert new data into an EXISTING user.
1802
- * @warning Does not upsert documents.
1803
- */
1804
- async _sys_set(uid, data) {
1805
- await this._users_db.set({ uid }, data, { upsert: false });
1806
- }
1807
- /**
1808
- * Get a user by uid. Throws if the uid does not exist.
1809
- * @returns Returns a User object.
1810
- * @param uid The user id.
1811
- * @throws {Collection.NotFoundError} If the user id does not exist.
1812
- * @example
1813
- * const user = await server.users.get("0");
1814
- *
1815
- * @docs
1816
- */
1817
- async get(uid) {
1818
- return await this._users_db.load({ uid });
1819
- }
1820
- /**
1821
- * Get a user by username. Throws if the username does not exist.
1822
- * @returns Returns a User object.
1823
- * @param username The username of the user to fetch.
1824
- * @throws {Collection.NotFoundError} If the username does not exist.
1825
- * @example
1826
- * const user = await server.users.get_by_username("myusername");
1827
- *
1828
- * @docs
1829
- */
1830
- async get_by_username(username) {
1831
- return await this._users_db.load({ username });
1832
- }
1833
- /**
1834
- * Get a user by uid or username.
1835
- * This function can be used if you have a variable which can be both.
1836
- * Throws if the username does not exist.
1837
- * @returns Returns a User object.
1838
- * @param username The username of the user to fetch.
1839
- * @throws {Collection.NotFoundError} If the username or uid does not exist.
1840
- * @example
1841
- * const user = await server.users.get_by_username("myusername");
1842
- *
1843
- * @docs
1844
- */
1845
- async get_by_uid_or_username(uid_or_username) {
1846
- return await this._users_db.load({
1847
- $or: [
1848
- { uid: uid_or_username },
1849
- { username: uid_or_username }
1850
- ]
1851
- });
1852
- }
1853
- /**
1854
- * Get a user by email. Throws if the email does not exist.
1855
- * @returns Returns a User object.
1856
- * @param email The email of the user to fetch.
1857
- * @throws {Collection.NotFoundError} If the email does not exist.
1858
- * @example
1859
- * const user = await server.users.get_by_email("my@email.com");
1860
- *
1861
- * @docs
1862
- */
1863
- async get_by_email(email) {
1864
- return await this._users_db.load({ email });
1865
- }
1866
- /**
1867
- * Get a user by API key. Throws if invalid.
1868
- * @returns Returns a User object.
1869
- * @param api_key The API key of the user to fetch.
1870
- * @example
1871
- * const user = await server.users.get_by_api_key("XXXXXX");
1872
- *
1873
- * @docs
1874
- */
1875
- async get_by_api_key(api_key) {
1876
- const uid = this.get_uid_by_api_key(api_key);
1877
- if (!uid)
1878
- throw new Error("Unable to find a user by api key.");
1879
- const user = await this.get(uid);
1880
- const ok = await this.verify_api_key_by_uid(uid, api_key);
1881
- if (!ok)
1882
- throw new Error("Unable to find a user by api key.");
1883
- return user;
1884
- }
1885
- /**
1886
- * Get a user by token. Throws if invalid.
1887
- * @returns Returns a User object.
1888
- * @param token The authentication token of the user to fetch.
1889
- * @example
1890
- * const user = await server.users.get_by_token("XXXXXX");
1891
- *
1892
- * @docs
1893
- */
1894
- async get_by_token(token) {
1895
- const uid = this.get_uid_by_token(token);
1896
- if (!uid)
1897
- throw new Error("Unable to find a user by token.");
1898
- const ok = await this.verify_token_by_uid(uid, token);
1899
- if (!ok)
1900
- throw new Error("Unable to find a user by token.");
1901
- return await this.get(uid);
1902
- }
1903
- /**
1904
- * Get a uid by username.
1905
- * @returns Returns the uid of the username, or undefined if not found.
1906
- * @param username The username of the uid to fetch.
1907
- * @example
1908
- * const uid = await server.users.get_uid("myusername");
1909
- *
1910
- * @docs
1911
- */
1912
- async get_uid(username) {
1913
- try {
1914
- return (await this.get_by_username(username)).uid;
1915
- } catch (e) {
1916
- return void 0;
1917
- }
1918
- }
1919
- /**
1920
- * Get a uid by username.
1921
- * @returns Returns the uid of the username, or undefined if not found.
1922
- * @param username The username of the uid to fetch.
1923
- * @example
1924
- * const uid = await server.users.get_uid_by_username("myuser");
1925
- *
1926
- * @docs
1927
- */
1928
- async get_uid_by_username(username) {
1929
- try {
1930
- return (await this.get_by_username(username)).uid;
1931
- } catch (e) {
1932
- return void 0;
1933
- }
1934
- }
1935
- /**
1936
- * Get a uid by email.
1937
- * @returns Returns the uid of the email, or undefined if not found.
1938
- * @param email The email of the uid to fetch.
1939
- * @example
1940
- * const uid = await server.users.get_uid_by_email("my@email.com");
1941
- *
1942
- * @docs
1943
- */
1944
- async get_uid_by_email(email) {
1945
- try {
1946
- return (await this.get_by_email(email)).uid;
1947
- } catch (e) {
1948
- return void 0;
1949
- }
1950
- }
1951
- /**
1952
- * Get a uid by API key.
1953
- * @returns Returns the uid for the API key, or undefined if not valid.
1954
- * @param api_key The API key to parse.
1955
- * @example
1956
- * const uid = server.users.get_uid_by_api_key("XXXXXXXXXX");
1957
- *
1958
- * @docs
1959
- */
1960
- get_uid_by_api_key(api_key) {
1961
- return this._parse_uid_from_token_api_key(api_key, "ak_");
1962
- }
1963
- /**
1964
- * Get a uid by token.
1965
- * @returns Returns the uid for the token, or undefined if not valid.
1966
- * @param token The token to parse.
1967
- * @example
1968
- * const uid = server.users.get_uid_by_token("XXXXXXXXXX");
1969
- *
1970
- * @docs
1971
- */
1972
- get_uid_by_token(token) {
1973
- return this._parse_uid_from_token_api_key(token, "tk_");
1974
- }
1975
- /**
1976
- * Get a user's support pin by uid.
1977
- * @returns Returns the support PIN string.
1978
- * @param uid The user id.
1979
- * @example
1980
- * const pin = await server.users.get_support_pin("1");
1981
- *
1982
- * @docs
1983
- */
1984
- async get_support_pin(uid) {
1985
- return (await this.get(uid)).support_pin;
1986
- }
1987
- /**
1988
- * Generate an API key for a user and store its hash. Overwrites existing keys.
1989
- * @returns Returns the API key string (plaintext).
1990
- * @param uid The user id.
1991
- * @example
1992
- * const api_key = await server.users.generate_api_key("0");
1993
- *
1994
- * @docs
1995
- */
1996
- async generate_api_key(uid) {
1997
- const api_key = this._generate_api_key(uid);
1998
- await this._sys_set(uid, { api_key: await this._hash_password(api_key) });
1999
- return api_key;
2000
- }
2001
- /**
2002
- * Check if a user has a generated API key.
2003
- * @returns Returns a boolean indicating whether the user has an API key.
2004
- * @param uid The user id.
2005
- * @throws {Collection.NotFoundError} If the user id does not exist.
2006
- * @example
2007
- * const has_api_key = await server.users.has_api_key("0");
2008
- *
2009
- * @docs
2010
- */
2011
- async has_api_key(uid) {
2012
- const data = await this._users_db.load({ uid }, {
2013
- projection: { api_key: 1 }
2014
- });
2015
- return data.api_key != null && data.api_key.length > 0;
2016
- }
2017
- /**
2018
- * Revoke the API key of a user.
2019
- * @param uid The user id.
2020
- * @example
2021
- * await server.users.revoke_api_key("0");
2022
- *
2023
- * @docs
2024
- */
2025
- async revoke_api_key(uid) {
2026
- await this._users_db.save({ uid }, { $unset: { api_key: "" } }, { upsert: false });
2027
- }
2028
- /**
2029
- * Verify a plaintext password.
2030
- * @returns Returns a boolean indicating whether the verification was successful.
2031
- * @param uid The user id.
2032
- * @param password The plaintext password.
2033
- * @example
2034
- * const success = await server.users.verify_password("1", "XXXXXX");
2035
- *
2036
- * @docs
2037
- */
2038
- async verify_password(uid, password) {
2039
- try {
2040
- const user = await this.get(uid);
2041
- return user.uid != null && await this._verify_password(password, user.password);
2042
- } catch (err) {
2043
- return false;
2044
- }
2045
- }
2046
- /**
2047
- * Verify a plaintext API key.
2048
- * @returns Returns a boolean indicating whether the verification was successful.
2049
- * @param api_key The api key to verify.
2050
- * @example
2051
- * const success = await server.users.verify_api_key("XXXXXX");
2052
- *
2053
- * @docs
2054
- */
2055
- async verify_api_key(api_key) {
2056
- return await this.verify_api_key_by_uid(this.get_uid_by_api_key(api_key), api_key);
2057
- }
2058
- /**
2059
- * Verify a plaintext API key by uid.
2060
- * @returns Returns a boolean indicating whether the verification was successful.
2061
- * @param uid The user id.
2062
- * @param api_key The api key to verify.
2063
- * @example
2064
- * const success = await server.users.verify_api_key_by_uid("1", "XXXXXX");
2065
- *
2066
- * @docs
2067
- */
2068
- async verify_api_key_by_uid(uid, api_key) {
2069
- try {
2070
- if (!uid)
2071
- return false;
2072
- const user = await this.get(uid);
2073
- return user.uid != null && user.api_key != null && user.api_key?.length > 0 && await this._verify_password(api_key, user.api_key);
2074
- } catch (err) {
2075
- return false;
2076
- }
2077
- }
2078
- /**
2079
- * Verify a plaintext token.
2080
- * @returns Returns a boolean indicating whether the verification was successful.
2081
- * @param token The token to verify.
2082
- * @example
2083
- * const success = await server.users.verify_token("XXXXXX");
2084
- *
2085
- * @docs
2086
- */
2087
- async verify_token(token) {
2088
- return await this.verify_token_by_uid(this.get_uid_by_token(token), token);
2089
- }
2090
- /**
2091
- * Verify a plaintext token by uid.
2092
- * @returns Returns a boolean indicating whether the verification was successful.
2093
- * @param uid The user id.
2094
- * @param token The token to verify.
2095
- * @example
2096
- * const success = await server.users.verify_token_by_uid("1", "XXXXXX");
2097
- *
2098
- * @docs
2099
- */
2100
- async verify_token_by_uid(uid, token) {
2101
- try {
2102
- if (!uid)
2103
- return false;
2104
- const correct_token = await this._tokens_db.load({ uid });
2105
- return correct_token != null && correct_token.token != null && correct_token.active !== false && Date.now() < correct_token.expiration && await this._verify_password(token, correct_token.token);
2106
- } catch (err) {
2107
- if (err instanceof import_collection.Collection.NotFoundError) {
2108
- return false;
2109
- }
2110
- throw err;
2111
- }
2112
- }
2113
- /**
2114
- * Verify a 2FA code by user id/email key.
2115
- * @param uid The UID or email used when creating the 2FA token.
2116
- * @param code The 2FA code.
2117
- * @returns Returns undefined on success, otherwise a string describing the error.
2118
- * @example
2119
- * await server.users.verify_2fa("1", "123456");
2120
- *
2121
- * @docs
2122
- */
2123
- async verify_2fa(uid, code) {
2124
- try {
2125
- const auth = await this._2fa_tokens_db.load({ uid });
2126
- const now = Date.now();
2127
- if (now >= auth.expiration) {
2128
- await this._deactivate_2fa_token(uid);
2129
- return "The 2FA code has expired.";
2130
- }
2131
- const status = auth != null && auth.code != null && now < auth.expiration && auth.code == code && auth.active !== false;
2132
- if (status === false) {
2133
- return "Invalid 2FA code.";
2134
- }
2135
- await this._deactivate_2fa_token(uid);
2136
- return;
2137
- } catch (err) {
2138
- if (err instanceof import_collection.Collection.NotFoundError) {
2139
- return "Invalid 2FA code.";
2140
- }
2141
- this.server.log.error(`${err}.`);
2142
- return "Unknown error.";
2143
- }
2144
- }
2145
- /**
2146
- * Send a 2FA code to a user by user id.
2147
- * By default the 2FA code will be valid for 5 minutes.
2148
- * The mail body is generated via `Server.on_2fa_mail({code, username, email, date, ip, device})`.
2149
- * @returns Returns a promise that resolves when the 2FA mail has been sent.
2150
- * @param uid The user id (or use _email with internal flow).
2151
- * @param stream The stream object from the client request.
2152
- * @param expiration The amount of seconds in which the code will expire.
2153
- * @example
2154
- * await server.users.send_2fa({ uid: "0", stream });
2155
- *
2156
- * @docs
2157
- */
2158
- async send_2fa({ uid, stream, expiration = 300, _user_agent = void 0, _username = void 0, _email = void 0 }) {
2159
- let code;
2160
- if (_username == null && _email == null) {
2161
- code = await this._create_2fa_token(uid, expiration);
2162
- const user = await this.get(uid);
2163
- _username = user.username;
2164
- _email = user.email;
2165
- } else {
2166
- code = await this._create_2fa_token(_email, expiration);
2167
- }
2168
- const user_agent = _user_agent ?? (stream.headers["user-agent"] ?? "Unknown");
2169
- const on_2fa_mail = this.server.events.get("2fa_mail");
2170
- if (!on_2fa_mail?.length) {
2171
- throw Error('Define server callback "Server.on_2fa_mail" to generate the HTML mail body.');
2172
- }
2173
- const mail = await on_2fa_mail[0]({
2174
- code,
2175
- username: _username,
2176
- email: _email,
2177
- date: (/* @__PURE__ */ new Date()).toUTCString(),
2178
- ip: stream.ip,
2179
- device: user_agent
2180
- });
2181
- let body, subject;
2182
- if (mail instanceof MailUI.MailElement) {
2183
- body = mail.html();
2184
- subject = mail.subject();
2185
- } else if (typeof mail === "string") {
2186
- body = mail;
2187
- } else {
2188
- throw new Error(`Invalid return value from server callback "Server.on('2fa_mail')", expected string or MailUI.MailElement.`);
2189
- }
2190
- this.server.assert_mail();
2191
- await this.server.mail.send({
2192
- recipients: [_email],
2193
- subject: subject ?? "Two Factor Authentication Code",
2194
- body
2195
- });
2196
- }
2197
- /**
2198
- * List all users.
2199
- * @returns An array of User objects.
2200
- *
2201
- * @docs
2202
- */
2203
- async list() {
2204
- return await this._users_db.list_all();
2205
- }
2206
- }
2207
- (function(Users2) {
2208
- let Endpoints;
2209
- (function(Endpoints2) {
2210
- Endpoints2.JsonValueSchemaType = [
2211
- "string",
2212
- "number",
2213
- "boolean",
2214
- "null",
2215
- "array",
2216
- "object"
2217
- ];
2218
- })(Endpoints = Users2.Endpoints || (Users2.Endpoints = {}));
2219
- })(Users || (Users = {}));
2220
- // Annotate the CommonJS export names for ESM import in node:
2221
- 0 && (module.exports = {
2222
- Users
2223
- });