@vandenberghinc/volt 1.2.5 → 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 +5 -1
  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,1713 +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
- Server: () => Server
31
- });
32
- module.exports = __toCommonJS(stdin_exports);
33
- var import_url = require("url");
34
- var path = __toESM(require("path"));
35
- var http = __toESM(require("http"));
36
- var http2 = __toESM(require("http2"));
37
- var crypto = __toESM(require("crypto"));
38
- var import_cluster = __toESM(require("cluster"));
39
- var os = __toESM(require("os"));
40
- var vlib = __toESM(require("@vandenberghinc/vlib"));
41
- var import_utils = require("./utils.js");
42
- var import_meta2 = require("./meta.js");
43
- var import_mail = require("./plugins/mail/mail.js");
44
- var import_status = require("./status.js");
45
- var import_endpoint = require("./endpoint.js");
46
- var import_image_endpoint = require("./image_endpoint.js");
47
- var import_stream = require("./stream.js");
48
- var import_database = require("./database/database.js");
49
- var import_users = require("./users.js");
50
- var import_rate_limit = require("./rate_limit.js");
51
- var import_route = require("./route.js");
52
- var import_internal_external = require("./errors/internal_external.js");
53
- var import_stripe = require("./payments/stripe/stripe.js");
54
- const import_meta = {};
55
- const __filename = (0, import_url.fileURLToPath)(import_meta.url);
56
- const __dirname = path.dirname(__filename);
57
- const { debug } = vlib;
58
- class Server {
59
- // ---------------------------------------------------------
60
- // Static attributes.
61
- // ---------------------------------------------------------
62
- /**
63
- * A temporary directory which holds the cached endpoint data.
64
- * For instance if we bundle JS then we save it to file and serve it from the file,
65
- * similar for transformed image endpoints.
66
- *
67
- * Note that upon each server start, we should clear this cache and remove all files inside this dir.
68
- */
69
- endpoint_cache_dir;
70
- // ---------------------------------------------------------
71
- // Attributes.
72
- // ---------------------------------------------------------
73
- /** The binded ip address. */
74
- ip;
75
- /** The binded http port. */
76
- port;
77
- /** The binded https port. */
78
- https_port;
79
- /** The raw domain. */
80
- domain;
81
- /** The full domain name with http/https depending if tls is enabled. */
82
- full_domain;
83
- /** The persistent storage source directory. */
84
- source;
85
- /** Is the primary thread. */
86
- is_primary;
87
- /** Is in production mode. */
88
- production;
89
- /** The company information. */
90
- company;
91
- /** The default meta information. */
92
- meta;
93
- /** Is running in offline mode. */
94
- offline;
95
- /** The database instance. */
96
- db;
97
- /** The rate limit instance. */
98
- rate_limit;
99
- /** The added endpoints. */
100
- endpoints = /* @__PURE__ */ new Map();
101
- /** The added error endpoints. */
102
- err_endpoints = /* @__PURE__ */ new Map();
103
- /** A record of keys used for hashing. */
104
- keys = {};
105
- /** Alias for the `Status` module. */
106
- status;
107
- /** Alias for the `RateLimits` module. */
108
- rate_limits;
109
- /** The file logger. */
110
- log;
111
- /** The users instance. */
112
- users;
113
- /** The payments instance. */
114
- payments;
115
- /** Daemon instance to manage a live daemon. */
116
- daemon;
117
- /** The mail instance. */
118
- mail;
119
- // Public for internal use:
120
- csp;
121
- statics_aspect_ratios;
122
- google_tag;
123
- rate_limit_api_key;
124
- performance;
125
- https_enabled;
126
- /** The events map @internal */
127
- events = new vlib.Events({
128
- single_events: ["2fa_mail"]
129
- });
130
- // Private.
131
- favicon;
132
- statics;
133
- _user_keys_opts;
134
- additional_sitemap_endpoints;
135
- tls;
136
- default_headers;
137
- http;
138
- https;
139
- threading;
140
- // Private ollections.
141
- _keys_db;
142
- _sys_keys_db;
143
- _website_status_db;
144
- /**
145
- * Construct a new server instance.
146
- * @docs
147
- */
148
- constructor({
149
- ip = "127.0.0.1",
150
- port,
151
- // leave undefined for blank detection.
152
- domain,
153
- is_primary = true,
154
- source,
155
- database,
156
- statics = [],
157
- favicon,
158
- company,
159
- meta = new import_meta2.Meta(),
160
- tls,
161
- mail,
162
- rate_limit = {
163
- server: {
164
- ip: void 0,
165
- port: import_rate_limit.RateLimitServer.default_port,
166
- https: void 0
167
- },
168
- client: {
169
- ip: void 0,
170
- port: import_rate_limit.RateLimitServer.default_port,
171
- url: void 0
172
- }
173
- },
174
- keys = [],
175
- payments,
176
- default_headers,
177
- google_tag = void 0,
178
- users,
179
- production = false,
180
- threading = {
181
- enabled: false,
182
- threads: void 0
183
- },
184
- offline = false,
185
- additional_sitemap_endpoints = [],
186
- log_level = 0,
187
- daemon = false
188
- // admin = {
189
- // password: null,
190
- // ips: [],
191
- // },
192
- // ts = {
193
- // compiler_opts: {},
194
- // output: undefined,
195
- // },
196
- // browser_preview = undefined,
197
- }) {
198
- if (production || port == null) {
199
- this.port = 80;
200
- this.https_port = 443;
201
- } else {
202
- this.port = port;
203
- this.https_port = port + 1;
204
- }
205
- this.ip = ip ?? "127.0.0.1";
206
- this.is_primary = is_primary && import_cluster.default.isPrimary;
207
- this.source = new vlib.Path(source);
208
- this.favicon = favicon;
209
- this.google_tag = google_tag;
210
- this.production = production;
211
- this.company = company;
212
- this.offline = offline;
213
- this._user_keys_opts = keys;
214
- this.additional_sitemap_endpoints = additional_sitemap_endpoints;
215
- this.tls = tls;
216
- this.https_enabled = tls != null;
217
- if (typeof threading === "boolean") {
218
- this.threading = {
219
- enabled: threading,
220
- threads: os.cpus().length
221
- };
222
- } else {
223
- this.threading = {
224
- enabled: threading.enabled ?? true,
225
- threads: threading.threads ?? os.cpus().length
226
- };
227
- }
228
- this.status = import_status.Status;
229
- this.rate_limits = import_rate_limit.RateLimits;
230
- this.performance = new vlib.Performance("Server performance");
231
- const log_source = this.source.join("logs");
232
- if (!log_source.exists()) {
233
- log_source.mkdir_sync({ recursive: true });
234
- }
235
- this.log = new vlib.logging.FileLogger({
236
- level: log_level,
237
- log_path: log_source.join("logs").str(),
238
- error_path: log_source.join("errors").str()
239
- });
240
- if (!this.source.exists()) {
241
- throw Error(`Source directory "${this.source.str()}" does not exist.`);
242
- }
243
- this.source = this.source.abs();
244
- this.domain = domain.replace("https://", "").replace("http://", "");
245
- while (this.domain.length > 0 && this.domain.charAt(this.domain.length - 1) === "/") {
246
- this.domain = this.domain.substr(0, this.domain.length - 1);
247
- }
248
- this.full_domain = `http${this.tls ? "s" : ""}://${this.domain}`;
249
- while (this.full_domain.endsWith("/")) {
250
- this.full_domain = this.full_domain.slice(0, -1);
251
- }
252
- this.endpoint_cache_dir = new vlib.Path("/tmp/volt_server_endpoint_cache/" + this.hash(this.domain));
253
- this.statics = statics;
254
- this.statics_aspect_ratios = /* @__PURE__ */ new Map();
255
- const volt_assets_path = new vlib.Path(`${__dirname}/../../../../../frontend/src/assets/`);
256
- if (!volt_assets_path.exists()) {
257
- this.log.warning(`${vlib.Color.yellow_bold("Warning")}: Could not find volt assets directory at "${volt_assets_path.abs().str()}". Please create a GitHub issue to report this.`);
258
- }
259
- this.statics.push({
260
- path: volt_assets_path.str(),
261
- endpoint: "/volt/assets"
262
- });
263
- if (!(meta instanceof import_meta2.Meta)) {
264
- meta = new import_meta2.Meta(meta);
265
- }
266
- if (favicon != null && meta.favicon == null) {
267
- meta.favicon = this.full_domain + "/favicon.ico";
268
- }
269
- if (favicon != null && meta.image == null) {
270
- meta.image = this.full_domain + "/favicon.ico";
271
- } else if (meta.image != null && !meta.image.startsWith("http")) {
272
- meta.image = this.full_domain + meta.image;
273
- }
274
- this.meta = meta;
275
- const base_default_headers = {
276
- // Cache correctness for CORS/preflight:
277
- "Vary": "Origin, Access-Control-Request-Method, Access-Control-Request-Headers",
278
- // Safer default than same-origin, still keeps useful referrers:
279
- "Referrer-Policy": "strict-origin-when-cross-origin",
280
- "Access-Control-Allow-Methods": "GET, POST, PUT, PATCH, DELETE, OPTIONS",
281
- "Access-Control-Allow-Headers": "Content-Type, Authorization",
282
- // Let browsers read our rate-limit hint:
283
- "Access-Control-Expose-Headers": "X-RateLimit-Reset",
284
- "X-Content-Type-Options": "nosniff",
285
- "X-Frame-Options": "DENY",
286
- // Helpful isolation defaults (safe for most apps):
287
- "Cross-Origin-Opener-Policy": "same-origin",
288
- "Cross-Origin-Resource-Policy": "same-site",
289
- // If you need SharedArrayBuffer, add COEP below (can break some embeds):
290
- // "Cross-Origin-Embedder-Policy": "require-corp",
291
- "Strict-Transport-Security": "max-age=63072000; includeSubDomains; preload",
292
- // Lock down powerful APIs by default.
293
- // If you need one on a third-party origin, add it beside (self).
294
- "Permissions-Policy": "accelerometer=(), camera=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), midi=(), payment=(), usb=(), hid=(), serial=(), xr-spatial-tracking=(), display-capture=(), screen-wake-lock=(), sync-xhr=(), publickey-credentials-get=(self), encrypted-media=(self), autoplay=(self 'https://www.youtube-nocookie.com') fullscreen=(self 'https://www.youtube-nocookie.com'), browsing-topics=()"
295
- // Do NOT set Allow-Origin / Credentials statically; set them per-request below.
296
- // "X-XSS-Protection": "1; mode=block", // deprecated
297
- };
298
- const default_csp = {
299
- "default-src": "'self'",
300
- "base-uri": "'none'",
301
- "object-src": "'none'",
302
- "form-action": "'self'",
303
- "frame-ancestors": "'none'",
304
- // Keep GA images; drop explicit http:// to avoid mixed content.
305
- "img-src": "'self' data: blob: https://*.google-analytics.com",
306
- "script-src": "'self' https://ajax.googleapis.com https://www.googletagmanager.com https://*.google-analytics.com",
307
- // Needed for GA/GTAG beacons/fetch:
308
- "connect-src": "'self' https://*.google-analytics.com",
309
- "style-src": "'self'",
310
- "font-src": "'self' data:",
311
- // Auto-upgrade stray http URLs where possible:
312
- "upgrade-insecure-requests": ""
313
- };
314
- if (default_headers == null) {
315
- this.csp = default_csp;
316
- this.default_headers = { ...base_default_headers };
317
- } else {
318
- if (default_headers["Content-Security-Policy"] != null && typeof default_headers["Content-Security-Policy"] !== "object") {
319
- throw Error(`The Content-Security-Policy of the default headers must be an object with values for each csp key, e.g. "{'script-src': '...'}".`);
320
- }
321
- this.csp = default_headers["Content-Security-Policy"] != null ? default_headers["Content-Security-Policy"] : default_csp;
322
- Object.keys(base_default_headers).forEach((key) => {
323
- if (default_headers[key] === void 0) {
324
- default_headers[key] = base_default_headers[key];
325
- }
326
- });
327
- this.default_headers = default_headers;
328
- }
329
- if (!this.tls) {
330
- delete this.default_headers["Strict-Transport-Security"];
331
- }
332
- if (payments) {
333
- if (payments.type === "stripe") {
334
- this.payments = new import_stripe.Stripe(this, payments);
335
- } else {
336
- throw Error(`Invalid payment processor type "${payments.type}", valid types are ["paddle"].`);
337
- }
338
- }
339
- if (daemon !== false) {
340
- const log_source2 = this.source.join("daemon");
341
- if (!log_source2.exists()) {
342
- log_source2.mkdir_sync({ recursive: true });
343
- }
344
- this.daemon = new vlib.Daemon({
345
- name: this.domain.replaceAll(".", ""),
346
- logs: daemon.logs || log_source2.join("logs").str(),
347
- errors: daemon.errors || log_source2.join("errors").str(),
348
- ...daemon
349
- // user: (daemon as Record<string, any>).user || os.userInfo().username,
350
- // group: (daemon as Record<string, any>).group || null,
351
- // command: "volt --service --start",
352
- // cwd: this.source.str(),
353
- // args: (daemon as Record<string, any>).args || [],
354
- // env: (daemon as Record<string, any>).env || {},
355
- // description: (daemon as Record<string, any>).description || `Service daemon for website ${this.domain}.`,
356
- // auto_restart: true,
357
- });
358
- }
359
- if (typeof database === "string") {
360
- this.db = new import_database.Database({ uri: database, _server: this });
361
- } else {
362
- this.db = new import_database.Database({ ...database, _server: this });
363
- }
364
- this._keys_db = this.db.collection({
365
- name: "Volt.Keys",
366
- indexes: ["id"]
367
- });
368
- this._sys_keys_db = this.db.collection({
369
- name: "Volt.SystemKeys",
370
- indexes: ["id"]
371
- });
372
- this._website_status_db = this.db.collection({
373
- name: "Volt.WebsiteStatus",
374
- indexes: ["id"]
375
- });
376
- this.users = new import_users.Users({
377
- support_recipient: mail?.smtp.sender,
378
- // ensure we assign the support recipient, so we dont need to define `this.mail` beforehand.
379
- ...users,
380
- // override support recipient if provided,
381
- _server: this
382
- });
383
- if (mail) {
384
- this.mail = new import_mail.Mail(mail);
385
- }
386
- if (rate_limit) {
387
- if (this.is_primary) {
388
- this.rate_limit = new import_rate_limit.RateLimitServer({ ...rate_limit.server ?? {}, _server: this });
389
- } else {
390
- if (rate_limit.server?.https) {
391
- rate_limit.client.https = true;
392
- }
393
- this.rate_limit = new import_rate_limit.RateLimitClient({ ...rate_limit.client ?? {}, _server: this });
394
- }
395
- }
396
- }
397
- // ---------------------------------------------------------
398
- // Utils.
399
- /** Get a content type (MIME) from a file extension. */
400
- /**
401
- * Get a content type (MIME) from a file extension. The file extension should include the leading dot, e.g. ".html".
402
- * @docs
403
- */
404
- get_content_type(extension) {
405
- return import_utils.Utils.mime_type(extension) ?? "application/octet-stream";
406
- }
407
- /**
408
- * Set the logging verbosity level.
409
- * @docs
410
- */
411
- set_log_level(level) {
412
- this.log.level.set(level);
413
- }
414
- // ---------------------------------------------------------
415
- // Crypto (private).
416
- /**
417
- * Generate a cryptographically secure random key as a hex string.
418
- * @docs
419
- */
420
- generate_crypto_key(length = 32) {
421
- return crypto.randomBytes(length).toString("hex");
422
- }
423
- /**
424
- * Create an HMAC hash using the provided key and data.
425
- * @docs
426
- */
427
- hmac(key, data, algo = "sha256") {
428
- const hmac = crypto.createHmac(algo, key);
429
- hmac.update(data);
430
- return hmac.digest("hex");
431
- }
432
- // /** Create an HMAC hash using the server's master hash key. */
433
- // hmac_with_master(data: string): string {
434
- // if (!this._master_hash_key) {
435
- // throw new Error("Hash key not initialized");
436
- // }
437
- // const hmac = crypto.createHmac("sha256", this._master_hash_key);
438
- // hmac.update(data);
439
- // return hmac.digest("hex");
440
- // }
441
- /**
442
- * Create a hash (no key) of the given data using the specified algorithm.
443
- * @docs
444
- */
445
- hash(data, algo = "sha256") {
446
- if (typeof data !== "string") {
447
- data = JSON.stringify(data);
448
- }
449
- return crypto.createHash(algo).update(data).digest("hex");
450
- }
451
- // ---------------------------------------------------------
452
- // Headers (private).
453
- // Initialize the default headers.
454
- _init_default_headers() {
455
- let csp = [];
456
- Object.entries(this.csp).forEach(([key, value]) => {
457
- csp.push(key);
458
- if (typeof value === "string" && value.length > 0) {
459
- csp.push(" ");
460
- csp.push(value);
461
- }
462
- csp.push(";");
463
- });
464
- this.default_headers["Content-Security-Policy"] = csp.join("");
465
- }
466
- // Add header defaults.
467
- _set_header_defaults(stream) {
468
- stream.set_headers(this.default_headers);
469
- const origin = stream.headers.origin;
470
- if (origin) {
471
- const same_http = `http://${this.domain}`;
472
- const same_https = `https://${this.domain}`;
473
- if (origin === same_http || origin === same_https) {
474
- stream.set_header("Access-Control-Allow-Origin", origin);
475
- stream.set_header("Access-Control-Allow-Credentials", "true");
476
- } else {
477
- stream.set_header("Access-Control-Allow-Origin", "*");
478
- }
479
- const req_hdrs = stream.headers["access-control-request-headers"];
480
- if (req_hdrs)
481
- stream.set_header("Access-Control-Allow-Headers", String(req_hdrs));
482
- const req_method = stream.headers["access-control-request-method"];
483
- if (req_method)
484
- stream.set_header("Access-Control-Allow-Methods", String(req_method));
485
- }
486
- }
487
- // ---------------------------------------------------------
488
- // Endpoints (private).
489
- // Create default endpoints.
490
- _create_default_endpoints() {
491
- if (this.favicon != null) {
492
- const favicon = new vlib.Path(this.favicon);
493
- if (favicon.exists() === false) {
494
- throw Error(`Specified favicon path "${favicon}" does not exist.`);
495
- }
496
- this.endpoint({
497
- method: "GET",
498
- endpoint: "/favicon.ico",
499
- data: favicon.load_sync({ type: "buffer" }),
500
- content_type: this.get_content_type(favicon.extension()),
501
- _is_static: true,
502
- server: this
503
- });
504
- }
505
- const status_dir = this.source.join(".status");
506
- if (!status_dir.exists()) {
507
- status_dir.mkdir_sync({ recursive: true });
508
- }
509
- const status_key_path = status_dir.join("key");
510
- let status_key;
511
- if (!status_key_path.exists()) {
512
- status_key = this.generate_crypto_key(32);
513
- status_key_path.save_sync(status_key);
514
- } else {
515
- status_key = status_key_path.load_sync();
516
- }
517
- this.endpoint({
518
- method: "GET",
519
- endpoint: "/.status",
520
- content_type: "application/json",
521
- params: {
522
- key: "string"
523
- },
524
- callback: async (stream, params) => {
525
- if (params.key !== status_key) {
526
- return stream.send({
527
- status: 403,
528
- headers: { "Content-Type": "text/plain" },
529
- data: "Access Denied"
530
- });
531
- }
532
- const status = {};
533
- status.ip = this.ip;
534
- if (this.http) {
535
- status.http_port = this.port;
536
- }
537
- if (this.https) {
538
- status.https_port = this.https_port;
539
- }
540
- const data = await this._website_status_db.load({ id: "status" }, {
541
- default: {
542
- id: "status",
543
- running_since: void 0,
544
- running_threads: 0,
545
- total_threads: 0
546
- }
547
- });
548
- Object.assign(status, data);
549
- return stream.send({
550
- status: 200,
551
- headers: { "Content-Type": "application/json" },
552
- data: status
553
- });
554
- }
555
- });
556
- }
557
- // Create the sitemap endpoint.
558
- async _create_sitemap() {
559
- this.log(2, "Creating sitemap.");
560
- let sitemap = "";
561
- sitemap += '<?xml version="1.0" encoding="UTF-8"?>\n';
562
- sitemap += '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n';
563
- for (const endpoint of this.endpoints.values()) {
564
- if (endpoint.allow_sitemap) {
565
- if (endpoint.route.is_regex)
566
- continue;
567
- const ep = encodeURI(endpoint.route.endpoint_str.startsWith("/") ? endpoint.route.endpoint_str : `/${endpoint.route.endpoint_str}`);
568
- sitemap += `<url>
569
- <loc>${this.full_domain}${ep}</loc>
570
- </url>
571
- `;
572
- }
573
- }
574
- this.additional_sitemap_endpoints.forEach((endpoint) => {
575
- while (endpoint.length > 0 && endpoint.charAt(0) === "/") {
576
- endpoint = endpoint.substr(1);
577
- }
578
- sitemap += `<url>
579
- <loc>${this.full_domain}/${endpoint}</loc>
580
- </url>
581
- `;
582
- });
583
- sitemap += "</urlset>\n";
584
- this.endpoint({
585
- method: "GET",
586
- endpoint: "/sitemap.xml",
587
- data: sitemap,
588
- content_type: "application/xml",
589
- _compress: false
590
- });
591
- }
592
- // Create the robots.txt endpoint.
593
- async _create_robots_txt() {
594
- this.log(2, "Creating robots.txt.");
595
- let robots = "User-agent: *\n";
596
- let disallowed = 0;
597
- for (const endpoint of this.endpoints.values()) {
598
- if (!endpoint.allow_robots) {
599
- robots += `Disallow: ${endpoint.route.endpoint_str}
600
- `;
601
- disallowed++;
602
- }
603
- }
604
- if (disallowed === 0) {
605
- robots += `Disallow:
606
- `;
607
- }
608
- robots += `
609
- Sitemap: ${this.full_domain}/sitemap.xml`;
610
- this.endpoint({
611
- method: "GET",
612
- endpoint: "/robots.txt",
613
- content_type: "text/plain",
614
- data: robots,
615
- _compress: false
616
- });
617
- }
618
- // Create admin endpoint.
619
- // @deprecated use MongoDB Atlas instead!
620
- /* private _create_admin_endpoint(): void {
621
-
622
- // Logs.
623
- this.log(2, "Creating admin endpoint.");
624
-
625
- // Add admin tokens.
626
- this.admin.tokens = [];
627
-
628
- // Verify token.
629
- const verify_token = (token: string): boolean => {
630
- const now = Date.now();
631
- let new_tokens: Array<{token: string, expiration: number}> = [];
632
- let verified = false;
633
- this.admin.tokens!.forEach((i) => {
634
- if (now < i.expiration) {
635
- if (i.token === token) {
636
- verified = true;
637
- }
638
- new_tokens.push(i);
639
- }
640
- })
641
- this.admin.tokens = new_tokens;
642
- return verified;
643
- }
644
-
645
- // Admin data.
646
- this.endpoint({
647
- method: "POST",
648
- endpoint: "/admin/auth",
649
- content_type: "application/json",
650
- rate_limit: {
651
- group: "volt.admin.auth",
652
- limit: 5,
653
- interval: 60,
654
- },
655
- params: {
656
- password: "string",
657
- },
658
- ip_whitelist: this.admin.ips,
659
- callback: async (stream: Stream, params: {password: string}) => {
660
- // Check key.
661
- if (params.password !== this.admin.password) {
662
- return stream.send({
663
- status: 403,
664
- headers: {"Content-Type": "text/plain"},
665
- data: "Access Denied",
666
- })
667
- }
668
-
669
- // Generate token.
670
- const token = {
671
- token: String.random(32),
672
- expiration: Date.now() + 3600 * 1000,
673
- };
674
- this.admin.tokens!.push(token)
675
-
676
- // Response.
677
- return stream.send({
678
- status: 200,
679
- headers: {"Content-Type": "application/json"},
680
- data: token,
681
- })
682
- },
683
- })
684
-
685
- // Admin data.
686
- this.endpoint({
687
- method: "GET",
688
- endpoint: "/admin/data",
689
- content_type: "application/json",
690
- rate_limit: "global",
691
- params: {
692
- token: "string",
693
- },
694
- ip_whitelist: this.admin.ips,
695
- callback: async (stream: Stream, params: {token: string}) => {
696
- // Verify token.
697
- if (!verify_token(params.token)) {
698
- return stream.send({
699
- status: 403,
700
- headers: {"Content-Type": "text/plain"},
701
- data: "Access Denied",
702
- })
703
- }
704
-
705
- // Data.
706
- const data: Record<string, any> = {};
707
-
708
- // Parse subscriptions.
709
- const subscriptions = await this.payments._get_all_active_subscriptions();
710
- data.subscriptions = subscriptions.length;
711
-
712
- // Load data.
713
- const status = await this._sys_db.load("status", {
714
- default: {
715
- running_since: null,
716
- running_threads: 0,
717
- total_threads: 0,
718
- }
719
- });
720
- Object.assign(data, status);
721
-
722
- // System data.
723
- data.cpu_usage = vlib.System.cpu_usage();
724
- data.memory_usage = vlib.System.memory_usage();
725
- data.network_usage = await vlib.System.network_usage();
726
-
727
- // Users.
728
- data.users = (await this.users.list()).length;
729
-
730
- // Response.
731
- return stream.send({
732
- status: 200,
733
- headers: {"Content-Type": "application/json"},
734
- data: data,
735
- })
736
- },
737
- })
738
-
739
- // Admin view.
740
- this.endpoint({
741
- method: "GET",
742
- endpoint: "/admin",
743
- content_type: "application/json",
744
- rate_limit: "global",
745
- params: {
746
- password: "string",
747
- },
748
- ip_whitelist: this.admin.ips,
749
- sitemap: false,
750
- robots: false,
751
- view: {
752
- templates: {
753
- DOMAIN: this.domain,
754
- },
755
- callback: () => {
756
- // Style.
757
- const style = {
758
- bg: "#F2F3F6",
759
- sub_bg: "#FAFAFA",
760
- fg: "#000000",
761
- sub_fg: "#9099B4",
762
- border: "#D6D6D6",
763
- tint: "#64B878", //"#8EB8EB", //"#4E9CF7",
764
- }
765
-
766
- // ... rest of the admin view implementation remains the same as it's client-side JavaScript ...
767
- },
768
- },
769
- })
770
- } */
771
- // Initialize statics.
772
- async _initialize_statics() {
773
- this.log(2, "Initializing static directories.");
774
- const static_paths = [];
775
- const add_static_file = async (path2, endpoint, cache = true) => {
776
- static_paths.push(path2.str());
777
- if (import_image_endpoint.ImageEndpoint.supported_images.has(path2.extension())) {
778
- const e = new import_image_endpoint.ImageEndpoint({
779
- endpoint,
780
- path: path2,
781
- cache,
782
- rate_limit: "global",
783
- _is_static: true
784
- });
785
- const aspect_ratio = await e.get_aspect_ratio();
786
- if (aspect_ratio != null) {
787
- this.statics_aspect_ratios.set(e.route.endpoint_str, aspect_ratio);
788
- }
789
- this.endpoint(e);
790
- } else {
791
- this.endpoint(new import_endpoint.Endpoint({
792
- method: "GET",
793
- endpoint,
794
- cache,
795
- rate_limit: "global",
796
- file_path: path2,
797
- _is_static: true
798
- }));
799
- }
800
- };
801
- const add_static = async (opts) => {
802
- if (opts == null) {
803
- return;
804
- }
805
- if (typeof opts === "object") {
806
- this.log(3, "Adding static directory " + opts.path);
807
- vlib.schema.validate(opts, {
808
- unknown: false,
809
- throw: true,
810
- schema: {
811
- path: "string",
812
- endpoint: { type: "string", default: null },
813
- cache: { type: ["boolean", "number"], default: true },
814
- endpoints_cache: { type: "object", default: {} },
815
- exclude: { type: "array", default: [] }
816
- }
817
- });
818
- const paths = [];
819
- const source = new vlib.Path(opts.path).abs();
820
- if (!source.exists()) {
821
- this.log(1, `Static path "${source.str()}" does not exist; skipping.`);
822
- return;
823
- }
824
- const source_len = source.str().length;
825
- const is_dir = source.is_dir();
826
- const exclude = [/\.DS_Store$/, /\.cache(?:\/|$)/, /\.old(?:\/|$)/, /\.ignore$/, ...opts.exclude || []];
827
- const is_excluded = (p) => {
828
- const s = typeof p === "string" ? p : p.str();
829
- return exclude.some((pattern) => pattern instanceof RegExp ? pattern.test(s) : s === String(pattern));
830
- };
831
- opts.endpoint = opts.endpoint || `/${source.full_name()}`;
832
- if (opts.endpoint.charAt(0) != "/") {
833
- opts.endpoint = "/" + opts.endpoint;
834
- }
835
- while (opts.endpoint.charAt(opts.endpoint.length - 1) == "/") {
836
- opts.endpoint = opts.endpoint.slice(0, -1);
837
- }
838
- if (!is_dir) {
839
- return await add_static_file(source, opts.endpoint, opts.cache);
840
- }
841
- const read_dir = async (path2) => {
842
- const dir_paths = await path2.paths();
843
- const promises = [];
844
- for (let i = 0; i < dir_paths.length; i++) {
845
- if (!is_excluded(dir_paths[i])) {
846
- if (dir_paths[i].is_dir()) {
847
- promises.push(read_dir(dir_paths[i]));
848
- } else {
849
- paths.push(dir_paths[i]);
850
- }
851
- }
852
- }
853
- ;
854
- await Promise.all(promises);
855
- };
856
- if (is_dir) {
857
- await read_dir(source);
858
- }
859
- for (const path2 of paths) {
860
- const endpoint = `${opts.endpoint}${path2.str().substr(source_len)}`;
861
- await add_static_file(path2, endpoint, opts.endpoints_cache === void 0 ? opts.cache : opts.endpoints_cache[endpoint] ?? opts.cache);
862
- }
863
- } else if (typeof opts === "string") {
864
- await add_static({ path: opts });
865
- }
866
- };
867
- for (let i = 0; i < this.statics.length; i++) {
868
- if (this.statics[i] instanceof vlib.Path) {
869
- this.statics[i] = this.statics[i].str();
870
- }
871
- await add_static(this.statics[i]);
872
- }
873
- return static_paths;
874
- }
875
- /** Initialize the system and user defined keys. */
876
- async _initialize_keys() {
877
- const start = Date.now();
878
- await this._db_init_promise;
879
- this.performance.end("_initialize_keys():await-db-init", start);
880
- const sys_keys = await this._sys_keys_db.load({ id: "sys_keys" }, {
881
- default: {
882
- id: "sys_keys",
883
- rate_limit_api_key: void 0
884
- }
885
- });
886
- let perform_sys_keys_save = false;
887
- if (sys_keys.rate_limit_api_key == null) {
888
- this.rate_limit_api_key = this.generate_crypto_key(32);
889
- sys_keys.rate_limit_api_key = this.rate_limit_api_key;
890
- perform_sys_keys_save = true;
891
- } else {
892
- this.rate_limit_api_key = sys_keys.rate_limit_api_key;
893
- }
894
- if (perform_sys_keys_save) {
895
- await this._sys_keys_db.set({ id: "sys_keys" }, sys_keys);
896
- }
897
- const user_keys = await this._keys_db.load({ id: "user_keys" }, {
898
- default: {
899
- id: "user_keys",
900
- keys: {}
901
- }
902
- });
903
- let perform_user_keys_save = false;
904
- for (const key of this._user_keys_opts) {
905
- const name = typeof key === "string" ? key : key.name;
906
- if (user_keys[name]) {
907
- this.keys[name] = user_keys[name];
908
- } else {
909
- perform_user_keys_save = true;
910
- if (typeof key === "string") {
911
- if (!key) {
912
- throw Error(`Crypto key "${key}" is an invalid key name.`);
913
- }
914
- const generated_key = this.generate_crypto_key(32);
915
- user_keys.keys[key] = generated_key;
916
- this.keys[key] = generated_key;
917
- } else {
918
- if (!key.name) {
919
- throw Error(`Crypto key "${key.name}" is an invalid key name.`);
920
- }
921
- if (key.length == null) {
922
- throw Error(`Crypto key "${key.name}" does not contain a "length" attribute.`);
923
- }
924
- if (typeof key.length !== "number") {
925
- throw Error(`Crypto key "${key.name}" has an invalid type for attribute "length", the valid type is "number".`);
926
- }
927
- const generated_key = this.generate_crypto_key(key.length);
928
- user_keys.keys[key.name] = generated_key;
929
- this.keys[key.name] = generated_key;
930
- }
931
- }
932
- }
933
- if (perform_user_keys_save) {
934
- await this._keys_db.set({ id: "user_keys" }, user_keys);
935
- }
936
- }
937
- /**
938
- * Checks if an endpoint route already exists.
939
- * @param method HTTP method
940
- * @param endpoint String path or RegExp
941
- */
942
- _check_duplicate_route(route) {
943
- const e = this.find_endpoint(route);
944
- if (e) {
945
- throw new Error(`Duplicate "${route.method}:${route.endpoint_str}" endpoint route, it is already defined by endpoint "${e.id}".`);
946
- }
947
- }
948
- // Serve a client.
949
- // @todo implement rate limiting.
950
- // @todo save internal server errors.
951
- async _serve(http2_stream, headers, req, res) {
952
- try {
953
- const stream = new import_stream.Stream(http2_stream, headers, req, res);
954
- let endpoint;
955
- let method;
956
- let endpoint_url;
957
- const log_endpoint_result = (message, status) => {
958
- let log_level = endpoint && endpoint.is_static ? 3 : 0;
959
- if (status == null) {
960
- status = stream.status_code;
961
- }
962
- this.log(log_level, `${method}:${endpoint_url}: ${message ? message : import_status.Status.get_description(status ?? "unknown")} [${status}] (${stream.ip}).`);
963
- };
964
- const serve_error_endpoint = async (status_code) => {
965
- const is_api_endpoint = endpoint && endpoint.callback != null;
966
- let default_response;
967
- switch (status_code) {
968
- case 400:
969
- default_response = {
970
- status: 400,
971
- headers: { "Content-Type": is_api_endpoint ? "application/json" : "text/plain" },
972
- data: is_api_endpoint ? { error: "Bad Request" } : "Bad Request"
973
- };
974
- break;
975
- case 403:
976
- default_response = {
977
- status: 403,
978
- headers: { "Content-Type": is_api_endpoint ? "application/json" : "text/plain" },
979
- data: is_api_endpoint ? { error: "Access Denied" } : "Access Denied"
980
- };
981
- break;
982
- case 404:
983
- default_response = {
984
- status: 404,
985
- headers: { "Content-Type": is_api_endpoint ? "application/json" : "text/plain" },
986
- data: is_api_endpoint ? { error: "Not Found" } : "Not Found"
987
- };
988
- break;
989
- case 500:
990
- default:
991
- default_response = {
992
- status: 500,
993
- headers: { "Content-Type": is_api_endpoint ? "application/json" : "text/plain" },
994
- data: is_api_endpoint ? { error: "Internal Server Error" } : "Internal Server Error"
995
- };
996
- break;
997
- }
998
- if (!this.err_endpoints.has(status_code)) {
999
- stream.send(default_response);
1000
- } else {
1001
- const err_endpoint = this.err_endpoints.get(status_code);
1002
- try {
1003
- await err_endpoint.serve({ stream, status: status_code });
1004
- } catch (err) {
1005
- this.log.error(`Error endpoint ${status_code}: `, err);
1006
- stream.send(default_response);
1007
- }
1008
- }
1009
- };
1010
- method = stream.method;
1011
- endpoint_url = stream.endpoint;
1012
- this.log(3, "Searching for endpoint: ", `${method}:${endpoint_url}`);
1013
- endpoint = this.endpoints.get(`${method}:${endpoint_url}`);
1014
- if (!endpoint) {
1015
- const route = new import_route.Route(method, endpoint_url);
1016
- for (const e of this.endpoints.values()) {
1017
- if (e.route.is_regex) {
1018
- const matched_params = e.route.match(route);
1019
- if (matched_params !== false) {
1020
- this.log(3, "Matched regex route: ", e.route.id);
1021
- endpoint = e;
1022
- Object.keys(matched_params).walk((k) => {
1023
- if (stream.params[k] == null) {
1024
- stream.params[k] = matched_params[k];
1025
- }
1026
- });
1027
- break;
1028
- }
1029
- }
1030
- }
1031
- } else {
1032
- this.log(3, "Matched route: ", endpoint.route.id);
1033
- }
1034
- if (!endpoint) {
1035
- if (method === "OPTIONS") {
1036
- const original_method = stream.headers["access-control-request-method"];
1037
- const original_endpoint = this.find_endpoint(endpoint_url, original_method);
1038
- if (original_endpoint) {
1039
- this._set_header_defaults(stream);
1040
- original_endpoint._set_headers(stream);
1041
- stream.send({ status: import_status.Status.no_content });
1042
- log_endpoint_result();
1043
- return;
1044
- }
1045
- }
1046
- await serve_error_endpoint(404);
1047
- log_endpoint_result();
1048
- return;
1049
- }
1050
- this._set_header_defaults(stream);
1051
- if (method === "OPTIONS") {
1052
- try {
1053
- await endpoint._serve_options(stream);
1054
- } catch (err) {
1055
- this.log.error(`${method}:${endpoint_url}: `, err);
1056
- if (!stream.destroyed && !stream.finished) {
1057
- await serve_error_endpoint(500);
1058
- log_endpoint_result();
1059
- }
1060
- return;
1061
- }
1062
- log_endpoint_result();
1063
- return;
1064
- }
1065
- if (!this.offline && this.production && this.rate_limit !== void 0 && endpoint.rate_limit_groups.length > 0) {
1066
- const result = await this.rate_limit.limit(stream.ip, endpoint.rate_limit_groups);
1067
- if (result != null) {
1068
- stream.send({
1069
- status: 429,
1070
- headers: {
1071
- "Content-Type": "text/plain",
1072
- "X-RateLimit-Reset": result
1073
- },
1074
- data: `Rate limit exceeded, please try again in ${Math.floor((result - Date.now()) / 1e3)} seconds.`
1075
- });
1076
- log_endpoint_result();
1077
- return;
1078
- }
1079
- }
1080
- try {
1081
- await stream.join();
1082
- } catch (err) {
1083
- this.log.error(`${method}:${endpoint_url}: `, err);
1084
- await serve_error_endpoint(500);
1085
- log_endpoint_result();
1086
- return;
1087
- }
1088
- try {
1089
- stream._parse_params();
1090
- } catch (err) {
1091
- this.log.error(`${method}:${endpoint_url}: `, err);
1092
- await serve_error_endpoint(400);
1093
- log_endpoint_result();
1094
- return;
1095
- }
1096
- if (!endpoint.is_static || endpoint.authenticated) {
1097
- const auth_result = await this.users._authenticate(stream);
1098
- if (auth_result != null && !endpoint.is_static) {
1099
- this.users._reset_cookies(stream);
1100
- }
1101
- if (auth_result != null && !endpoint.is_static && (endpoint.view != null || endpoint.content_type === "text/html")) {
1102
- stream.set_header("Location", `/signin?next=${encodeURIComponent(stream.endpoint)}`);
1103
- }
1104
- if (auth_result != null && endpoint.authenticated) {
1105
- stream.send(auth_result);
1106
- log_endpoint_result();
1107
- return;
1108
- }
1109
- }
1110
- try {
1111
- await endpoint.serve({ stream });
1112
- } catch (err) {
1113
- this.log.error(`${method}:${endpoint_url}: `, err);
1114
- if (!stream.destroyed && !stream.finished) {
1115
- await serve_error_endpoint(500);
1116
- log_endpoint_result();
1117
- }
1118
- return;
1119
- }
1120
- if (!stream.finished) {
1121
- this.log.error(`${method}:${endpoint_url}: `, "Unfinished response.");
1122
- await serve_error_endpoint(500);
1123
- log_endpoint_result();
1124
- return;
1125
- }
1126
- log_endpoint_result();
1127
- } catch (err) {
1128
- this.log.error(err);
1129
- }
1130
- }
1131
- // ---------------------------------------------------------
1132
- // Utilities.
1133
- /** The promise of database initialization and connecting. */
1134
- _db_init_promise;
1135
- /** Is initialized. */
1136
- _initialized = false;
1137
- /** Is initialized by a worker. */
1138
- _initialized_by_worker = false;
1139
- /**
1140
- * Initialize the server.
1141
- * @returns A promise that resolves when the server has been initialized.
1142
- * @docs
1143
- */
1144
- async initialize({ worker = false } = {}) {
1145
- if (this._initialized) {
1146
- return;
1147
- }
1148
- this._initialized = true;
1149
- this._initialized_by_worker = worker;
1150
- this.log(1, "Initializing server.");
1151
- const initialize_start = Date.now();
1152
- this.performance.start();
1153
- this._db_init_promise = (async () => {
1154
- let start = Date.now();
1155
- await this.db.initialize();
1156
- this.performance.end("init-db", start);
1157
- start = Date.now();
1158
- await this.db.connect();
1159
- this.performance.end("connect-db", start);
1160
- })();
1161
- if (this.endpoint_cache_dir.exists()) {
1162
- await this.endpoint_cache_dir.del({ recursive: true });
1163
- }
1164
- await this.endpoint_cache_dir.mkdir({ recursive: true });
1165
- if (!worker) {
1166
- if (this.tls) {
1167
- this.https = http2.createSecureServer({
1168
- key: new vlib.Path(this.tls.key).load_sync({ encoding: "utf8" }),
1169
- cert: new vlib.Path(this.tls.cert).load_sync({ encoding: "utf8" }),
1170
- ca: this.tls.ca == null ? void 0 : new vlib.Path(this.tls.ca).load_sync({ encoding: "utf8" }),
1171
- passphrase: this.tls.passphrase,
1172
- allowHTTP1: true
1173
- });
1174
- this.https.on("stream", (stream, headers) => {
1175
- this._serve(stream, headers, void 0, void 0);
1176
- });
1177
- this.https.on("request", (req, res) => {
1178
- if (req.httpVersionMajor === 1) {
1179
- this._serve(void 0, void 0, req, res);
1180
- }
1181
- });
1182
- } else if (this.production && this.payments) {
1183
- throw Error("Accepting payments in production mode requires HTTPS.");
1184
- }
1185
- this.performance.end("create-https-server");
1186
- if (this.tls) {
1187
- this.http = http.createServer((request, response) => {
1188
- const reqUrl = typeof request.url === "string" ? request.url : "/";
1189
- const location = `https://${this.domain}${reqUrl}`;
1190
- response.writeHead(308, { Location: location });
1191
- response.end();
1192
- });
1193
- } else {
1194
- this.http = http.createServer((req, res) => {
1195
- this._serve(void 0, void 0, req, res);
1196
- });
1197
- }
1198
- this.performance.end("create-http-server");
1199
- this._init_default_headers();
1200
- this.performance.end("init-default-headers");
1201
- this._create_default_endpoints();
1202
- this.performance.end("create-default-endpoints");
1203
- await this._initialize_statics();
1204
- this.performance.end("_initialize_statics()");
1205
- }
1206
- await this._initialize_keys();
1207
- this.performance.end("load-keys");
1208
- const promises = [];
1209
- this.performance.start();
1210
- promises.push(this.users._initialize({ worker }));
1211
- if (this.payments !== void 0) {
1212
- if (this.payments.type === "stripe") {
1213
- promises.push(this.payments.initialize({ worker }));
1214
- } else {
1215
- this.payments.type.toString();
1216
- throw Error(`Unsupported payments provider "${this.payments.type}".`);
1217
- }
1218
- }
1219
- if (!worker) {
1220
- if (this.find_endpoint("/sitemap.xml") == null) {
1221
- promises.push(this._create_sitemap());
1222
- }
1223
- if (this.find_endpoint("/robots.txt") == null) {
1224
- promises.push(this._create_robots_txt());
1225
- }
1226
- }
1227
- if (this.company.stroke_icon || this.company.icon) {
1228
- for (const endpoint of this.endpoints.values()) {
1229
- if (this.company.stroke_icon_path == null && endpoint.route.endpoint === this.company.stroke_icon) {
1230
- this.company.stroke_icon_path = endpoint.file_path?.str() || void 0;
1231
- }
1232
- if (this.company.icon_path == null && endpoint.route.endpoint === this.company.icon) {
1233
- this.company.icon_path = endpoint.file_path?.str() || void 0;
1234
- }
1235
- }
1236
- if (this.company.stroke_icon != null && this.company.stroke_icon_path == null) {
1237
- throw Error(`Unable to find the company's stroke icon endpoint "${this.company.stroke_icon}", consider defining the "company.stroke_icon_path" property.`);
1238
- }
1239
- if (this.company.icon != null && this.company.icon_path == null) {
1240
- throw Error(`Unable to find the company's icon endpoint "${this.company.icon}", consider defining the "company.icon_path" property.`);
1241
- }
1242
- }
1243
- await Promise.all(promises);
1244
- this.performance.end("awaiting-promise-list");
1245
- if (!worker) {
1246
- this.performance.start();
1247
- for (const endpoint of this.endpoints.values()) {
1248
- endpoint._initialize(this);
1249
- }
1250
- for (const endpoint of this.err_endpoints.values()) {
1251
- endpoint._initialize(this);
1252
- }
1253
- this.performance.end("initialize-endpoints");
1254
- }
1255
- for (const callback of this.events.get("initialize")) {
1256
- await callback({ worker });
1257
- }
1258
- this.performance.end("on-initialize-callbacks");
1259
- this.performance.end("initialize()", initialize_start);
1260
- }
1261
- find_endpoint(endpoint, method) {
1262
- let route;
1263
- if (endpoint instanceof import_route.Route) {
1264
- route = endpoint;
1265
- endpoint = route.endpoint_str;
1266
- method = route.method;
1267
- }
1268
- method ??= "GET";
1269
- const result = this.endpoints.get(`${method}:${endpoint}`);
1270
- if (!result) {
1271
- if (!route)
1272
- route = new import_route.Route(method, endpoint);
1273
- for (const e of this.endpoints.values()) {
1274
- if (e.route.is_regex && e.route.match(route)) {
1275
- return e;
1276
- }
1277
- }
1278
- }
1279
- return result;
1280
- }
1281
- /** Assert mail is configured. */
1282
- assert_mail() {
1283
- if (!this.mail) {
1284
- throw new import_internal_external.ExternalError({ message: "Mail is not configured." });
1285
- }
1286
- }
1287
- // ---------------------------------------------------------
1288
- // Server.
1289
- /**
1290
- * Start the server.
1291
- *
1292
- * @example
1293
- * {Start}
1294
- * Start the server.
1295
- * ```
1296
- * const server = new volt.Server({ ... });
1297
- * await server.start();
1298
- * ```
1299
- * @docs
1300
- */
1301
- async start() {
1302
- if (this._initialized_by_worker) {
1303
- throw Error("Cannot start the server when it is initialized as a worker by 'Server.initialize({ worker: true })'.");
1304
- }
1305
- await this.initialize();
1306
- if (this.production) {
1307
- for (const endpoint of this.endpoints.values()) {
1308
- if (endpoint.view) {
1309
- await endpoint.view.production_initialize();
1310
- }
1311
- }
1312
- }
1313
- if (this.rate_limit) {
1314
- this.performance.start();
1315
- await this.rate_limit.start();
1316
- this.performance.end("init-rate-limit");
1317
- }
1318
- let forked = false;
1319
- if (this.production && this.threading.enabled && import_cluster.default.isPrimary && this.threading.threads > 1) {
1320
- this.log(0, `Starting ${this.threading.threads} threads.`);
1321
- let active_threads = 0;
1322
- const thread_ids = {};
1323
- const restart_limiters = {};
1324
- const start_thread = (thread_id, restart = false) => {
1325
- const worker = import_cluster.default.fork();
1326
- this.log(restart ? 0 : 1, `Starting thread ${worker.process.pid}.`);
1327
- thread_ids[worker.process.pid] = thread_id;
1328
- ++active_threads;
1329
- };
1330
- for (let i = 0; i < this.threading.threads; i++) {
1331
- let thread_id;
1332
- while ((thread_id = vlib.String.random(8)) && Object.values(thread_ids).includes(thread_id)) {
1333
- }
1334
- restart_limiters[thread_id] = new vlib.TimeLimiter({ limit: 3, duration: 60 * 1e3 });
1335
- start_thread(thread_id);
1336
- }
1337
- await this._website_status_db.set({ id: "status" }, {
1338
- running_since: Date.now(),
1339
- total_threads: active_threads,
1340
- running_threads: active_threads
1341
- });
1342
- import_cluster.default.addListener("exit", async (worker, code, signal) => {
1343
- const thread_id = thread_ids[worker.process.pid];
1344
- delete thread_ids[worker.process.pid];
1345
- this.log.error(`Thread ${worker.process.pid} crashed.`);
1346
- const limiter = restart_limiters[thread_id];
1347
- if (limiter != null && limiter.limit()) {
1348
- --active_threads;
1349
- start_thread(thread_id, true);
1350
- } else {
1351
- this.log.error(`Thread ${worker.process.pid} is being shut down due to its periodic restart limit.`);
1352
- --active_threads;
1353
- await this._website_status_db.save({ id: "status" }, { $inc: { running_threads: -1 } });
1354
- if (active_threads === 0) {
1355
- this.log.error(`All threads died, stopping server.`);
1356
- process.exit(0);
1357
- }
1358
- }
1359
- });
1360
- await this.db.close();
1361
- } else {
1362
- forked = this.production && this.threading.enabled;
1363
- let is_running = false;
1364
- const on_running = () => {
1365
- if (!is_running) {
1366
- is_running = true;
1367
- if (this.https !== void 0) {
1368
- this.log(0, `Running on http://${this.ip}:${this.port} and https://${this.ip}:${this.https_port}.`);
1369
- } else {
1370
- this.log(0, `Running on http://${this.ip}:${this.port}.`);
1371
- }
1372
- }
1373
- };
1374
- const on_error = (error) => {
1375
- if (error.syscall !== "listen") {
1376
- throw error;
1377
- }
1378
- switch (error.code) {
1379
- case "EACCES":
1380
- console.error(`Error: Address ${this.ip}:${this.port} requires elevated privileges.`);
1381
- process.exit(1);
1382
- break;
1383
- case "EADDRINUSE":
1384
- console.error(`Error: Address ${this.ip}:${this.port} is already in use.`);
1385
- process.exit(1);
1386
- break;
1387
- default:
1388
- throw error;
1389
- }
1390
- };
1391
- this.http.listen(this.port, this.ip === "*" ? void 0 : this.ip, on_running);
1392
- this.http.on("error", on_error);
1393
- if (this.https !== void 0) {
1394
- this.https.listen(this.https_port, this.ip === "*" ? void 0 : this.ip, on_running);
1395
- this.https.on("error", on_error);
1396
- }
1397
- let graceful_shutdown_shutting_down = false;
1398
- const graceful_shutdown = async () => {
1399
- if (graceful_shutdown_shutting_down)
1400
- return;
1401
- graceful_shutdown_shutting_down = true;
1402
- try {
1403
- await this.stop();
1404
- } catch (e) {
1405
- this.log.error("Shutdown error:", e);
1406
- } finally {
1407
- process.exit(0);
1408
- }
1409
- };
1410
- process.on("SIGTERM", graceful_shutdown);
1411
- process.on("SIGINT", graceful_shutdown);
1412
- if (process.env.VOLT_FILE_WATCHER === "1") {
1413
- new vlib.Path(process.env.VOLT_STARTED_FILE).save_sync("1");
1414
- }
1415
- this.performance.end("listen");
1416
- }
1417
- this.performance.start();
1418
- for (const callback of this.events.get("start")) {
1419
- const res = callback({ forked });
1420
- if (res instanceof Promise) {
1421
- await res;
1422
- }
1423
- }
1424
- this.performance.end("on-start-callbacks");
1425
- console.log(this.performance.dump());
1426
- }
1427
- /**
1428
- * Stop the server.
1429
- * @note After stopping the server we can no longer restart the server.
1430
- *
1431
- * @example
1432
- * {Stop}
1433
- * Stop the server.
1434
- * ```
1435
- * const server = new volt.Server({ ... });
1436
- * await server.start();
1437
- * ...
1438
- * await server.stop();
1439
- * ```
1440
- *
1441
- * @docs
1442
- */
1443
- async stop() {
1444
- this.log(0, "Stopping the server...");
1445
- for (const callback of this.events.get("stop")) {
1446
- const res = callback();
1447
- if (res instanceof Promise) {
1448
- await res;
1449
- }
1450
- }
1451
- if (this.rate_limit) {
1452
- await this.rate_limit.stop();
1453
- }
1454
- if (this.https)
1455
- this.https.close();
1456
- if (this.http)
1457
- this.http.close();
1458
- await this.db.close();
1459
- this.log.stop();
1460
- this._initialized = false;
1461
- }
1462
- // ---------------------------------------------------------
1463
- // Events.
1464
- /**
1465
- * Add an event callback.
1466
- * See {@link Events} for more info.
1467
- * @docs
1468
- */
1469
- on(name, callback) {
1470
- this.events.add(name, callback);
1471
- return this;
1472
- }
1473
- /**
1474
- * Remove an event callback.
1475
- * See {@link Events} for more info.
1476
- * @docs
1477
- */
1478
- off(name, callback) {
1479
- this.events.remove(name, callback);
1480
- return this;
1481
- }
1482
- // ---------------------------------------------------------
1483
- // Endpoints.
1484
- /**
1485
- * Add a single endpoint.
1486
- * Only supports a single endpoint due to parameter inference.
1487
- * @note An error is thrown when the endpoint route already exists.
1488
- * @template Response User inputted response type that will be returned as response, optionaly typing used for consistency.
1489
- * @template S system template for inferring the endpoint callback parameters.
1490
- * @param endpoint The endpoint or endpoint options to add.
1491
- * @returns A registered endpoint object that can for instance be used to infer the endpoint parameters.
1492
- *
1493
- * @docs
1494
- */
1495
- endpoint(endpoint) {
1496
- const e = endpoint instanceof import_endpoint.Endpoint ? endpoint : new import_endpoint.Endpoint(endpoint);
1497
- this._check_duplicate_route(e.route);
1498
- this.endpoints.set(e.route.id, e);
1499
- return {
1500
- Params: void 0,
1501
- method: e.route.method,
1502
- Method: e.route.method,
1503
- endpoint: e.route.endpoint,
1504
- Endpoint: e.route.endpoint,
1505
- route: e.route
1506
- };
1507
- }
1508
- /**
1509
- * Add an endpoint per error status code.
1510
- * @param status_code
1511
- * The status code of the error.
1512
- *
1513
- * The supported status codes are:
1514
- * * `*` For all errors not specifically defined.
1515
- * * `status >= 400`
1516
- * @param endpoint The error endpoint or error endpoint options.
1517
- *
1518
- * @note
1519
- * Best practice is to define a universal `/error` endpoint using `Endpoint.templates` to render the error details.
1520
- * Then this endpoint can be cloned using `Endpoint.clone()` and defined with specific template values per status code.
1521
- *
1522
- * @docs
1523
- */
1524
- error_endpoint(status_code, endpoint) {
1525
- let e;
1526
- if (endpoint instanceof import_endpoint.Endpoint) {
1527
- e = endpoint;
1528
- } else {
1529
- e = new import_endpoint.Endpoint({
1530
- ...endpoint,
1531
- method: "GET",
1532
- endpoint: `/error/${status_code}`
1533
- });
1534
- }
1535
- if (status_code === "*") {
1536
- Object.values(import_status.Status).forEach((status) => {
1537
- if (typeof status === "number" && status >= 400 && !this.err_endpoints.has(status)) {
1538
- this.err_endpoints.set(status, e);
1539
- }
1540
- });
1541
- } else {
1542
- this.err_endpoints.set(status_code, e);
1543
- }
1544
- return this;
1545
- }
1546
- // ---------------------------------------------------------
1547
- // Content Security Policy.
1548
- /**
1549
- * Add an url to the Content-Security-Policy. This function does not overwrite the existing key's value.
1550
- * @warning This function no longer has any effect when `Server.start()` has been called.
1551
- * @param key The Content-Security-Policy key, e.g. `script-src`.
1552
- * @param value The value to add to the Content-Security-Policy key.
1553
- * @example
1554
- * ...
1555
- * server.add_csp("script-src", "somewebsite.com");
1556
- * server.add_csp("upgrade-insecure-requests");
1557
- * @docs
1558
- */
1559
- add_csp(key, value = null) {
1560
- if (this.csp[key] === void 0) {
1561
- this.csp[key] = "";
1562
- }
1563
- if (Array.isArray(value)) {
1564
- value.forEach((v) => {
1565
- if (typeof v === "string" && v.length > 0) {
1566
- this.csp[key] += " " + v.trim();
1567
- }
1568
- });
1569
- } else if (typeof value === "string" && value.length > 0) {
1570
- this.csp[key] += " " + value.trim();
1571
- }
1572
- }
1573
- // Remove a csp.
1574
- /**
1575
- * Remove an url from the Content-Security-Policy. This function does not overwrite the existing key's value.
1576
- * @warning This function no longer has any effect when `Server.start()` has been called.
1577
- * @param key The Content-Security-Policy key, e.g. `script-src`.
1578
- * @param value The value to remove from the Content-Security-Policy key.
1579
- * @example
1580
- * ...
1581
- * server.remove_csp("script-src", "somewebsite.com");
1582
- * server.remove_csp("upgrade-insecure-requests");
1583
- * @docs
1584
- */
1585
- remove_csp(key, value = null) {
1586
- if (this.csp[key] === void 0) {
1587
- return;
1588
- }
1589
- if (typeof value === "string" && value.length > 0) {
1590
- this.csp[key] = this.csp[key].replaceAll(value, "");
1591
- } else {
1592
- delete this.csp[key];
1593
- }
1594
- }
1595
- // Delete a csp key.
1596
- /**
1597
- * Delete an key from the Content-Security-Policy.
1598
- * @warning This function no longer has any effect when `Server.start()` has been called.
1599
- * @param key The Content-Security-Policy key, e.g. `script-src`.
1600
- * @example
1601
- * ...
1602
- * server.del_csp("script-src");
1603
- * server.del_csp("upgrade-insecure-requests");
1604
- * @docs
1605
- */
1606
- del_csp(key) {
1607
- delete this.csp[key];
1608
- }
1609
- // ---------------------------------------------------------
1610
- // Status.
1611
- /**
1612
- * This function is meant to be used when the server is in production mode, it will make an API request to your server through the defined `Server.domain` parameter.
1613
- * @note This function can be called without initializing the server.
1614
- * @param type The wanted output type. Either an `object` or a `string` type for CLI purposes.
1615
- * @docs
1616
- */
1617
- async fetch_status(type = "object") {
1618
- const key_path = this.source.join(".status/key");
1619
- if (!key_path.exists()) {
1620
- throw new Error("No status key has been generated yet. Start your server first.");
1621
- }
1622
- const key = key_path.load_sync();
1623
- const { body: status } = await vlib.request({
1624
- host: this.domain,
1625
- endpoint: "/.status",
1626
- method: "GET",
1627
- params: { key },
1628
- query: true,
1629
- json: true
1630
- });
1631
- if (type === "string") {
1632
- if (status.running_since != null) {
1633
- status.running_since = new vlib.Date(status.running_since).format("%d-%m-%y %H:%M:%S");
1634
- }
1635
- let str = `${this.domain}:
1636
- `;
1637
- Object.keys(status).forEach((key2) => {
1638
- str += ` * ${key2}: ${status[key2]}
1639
- `;
1640
- });
1641
- str = str.substr(0, str.length - 1);
1642
- return str;
1643
- }
1644
- return status;
1645
- }
1646
- // ---------------------------------------------------------
1647
- // TLS.
1648
- /**
1649
- * Generate a key and csr for tls.
1650
- * @docs
1651
- */
1652
- async generate_ssl_key({ output_path, ec = true }) {
1653
- if (output_path == null) {
1654
- throw Error('Define parameter "path".');
1655
- }
1656
- const key = new vlib.Path(output_path);
1657
- if (key.exists()) {
1658
- throw Error(`Key path "${key.str()}" already exists, remove the file manually to continue.`);
1659
- }
1660
- const proc = new vlib.Proc();
1661
- await proc.start({
1662
- command: "openssl",
1663
- args: ec ? ["ecparam", "-genkey", "-name", "secp384r1", "-out", key.str()] : ["genpkey", "-algorithm", "RSA", "-pkeyopt", "rsa_keygen_bits:2048", "-out", key.str()],
1664
- opts: { stdio: "inherit" }
1665
- });
1666
- if (proc.exit_status != 0) {
1667
- throw Error(`Encountered an error while generating the private key [${proc.exit_status}]: ${proc.err}`);
1668
- }
1669
- }
1670
- /**
1671
- * Generate a csr for tls.
1672
- * @docs
1673
- */
1674
- async generate_csr({ output_path, key_path, name, domain, organization_unit, country_code, province, city }) {
1675
- if (key_path == null) {
1676
- throw Error('Define parameter "key_path".');
1677
- }
1678
- if (organization_unit == null) {
1679
- throw Error('Define parameter "organization_unit".');
1680
- }
1681
- const key = new vlib.Path(key_path);
1682
- if (!key.exists()) {
1683
- throw Error(`Key path "${key.str()}" does not exist.`);
1684
- }
1685
- const csr = new vlib.Path(output_path);
1686
- if (csr.exists()) {
1687
- throw Error(`CSR path "${csr.str()}" already exists, remove the file manually to continue.`);
1688
- }
1689
- const proc = new vlib.Proc();
1690
- await proc.start({
1691
- command: "openssl",
1692
- args: [
1693
- "req",
1694
- "-new",
1695
- "-key",
1696
- key.str(),
1697
- "-out",
1698
- csr.str(),
1699
- "-subj",
1700
- `/C=${country_code}/ST=${province}/L=${city}/O=${name}/OU=${organization_unit}/CN=${domain}`
1701
- ],
1702
- opts: { stdio: "inherit" }
1703
- });
1704
- if (proc.exit_status != 0) {
1705
- throw Error(`Encountered an error while generating the CSR [${proc.exit_status}]: ${proc.err}`);
1706
- }
1707
- this.log(0, `Generated the tls key with CSR for domain "${this.domain}".`);
1708
- }
1709
- }
1710
- // Annotate the CommonJS export names for ESM import in node:
1711
- 0 && (module.exports = {
1712
- Server
1713
- });