@vandenberghinc/volt 1.2.6 → 1.2.7

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 (462) hide show
  1. package/backend/dist/cjs/backend/src/blacklist.d.ts +12 -0
  2. package/backend/dist/cjs/backend/src/blacklist.js +78 -0
  3. package/backend/dist/cjs/backend/src/cli.d.ts +2 -0
  4. package/backend/dist/cjs/backend/src/cli.js +198 -0
  5. package/backend/dist/cjs/backend/src/database/collection.d.ts +1765 -0
  6. package/backend/dist/cjs/backend/src/database/collection.js +3301 -0
  7. package/backend/dist/cjs/backend/src/database/database.d.ts +92 -0
  8. package/backend/dist/cjs/backend/src/database/database.js +170 -0
  9. package/backend/dist/cjs/backend/src/database/document.d.ts +1 -0
  10. package/backend/dist/cjs/backend/src/database/document.js +15 -0
  11. package/backend/dist/cjs/backend/src/database/filters/filters.d.ts +6 -0
  12. package/backend/dist/cjs/backend/src/database/filters/filters.js +15 -0
  13. package/backend/dist/cjs/backend/src/database/filters/strict_filter.d.ts +223 -0
  14. package/backend/dist/cjs/backend/src/database/filters/strict_filter.js +15 -0
  15. package/backend/dist/cjs/backend/src/database/filters/strict_filter_test.d.ts +1 -0
  16. package/backend/dist/cjs/backend/src/database/filters/strict_filter_test.js +443 -0
  17. package/backend/dist/cjs/backend/src/database/filters/strict_filter_test_v0.d.ts +1 -0
  18. package/backend/dist/cjs/backend/src/database/filters/strict_filter_test_v0.js +15 -0
  19. package/backend/dist/cjs/backend/src/database/filters/strict_filter_v0.d.ts +50 -0
  20. package/backend/dist/cjs/backend/src/database/filters/strict_filter_v0.js +15 -0
  21. package/backend/dist/cjs/backend/src/database/filters/strict_filter_v1.d.ts +76 -0
  22. package/backend/dist/cjs/backend/src/database/filters/strict_filter_v1.js +15 -0
  23. package/backend/dist/cjs/backend/src/database/filters/strict_filter_v2.d.ts +75 -0
  24. package/backend/dist/cjs/backend/src/database/filters/strict_filter_v2.js +15 -0
  25. package/backend/dist/cjs/backend/src/database/filters/strict_filter_v3.d.ts +219 -0
  26. package/backend/dist/cjs/backend/src/database/filters/strict_filter_v3.js +15 -0
  27. package/backend/dist/cjs/backend/src/database/filters/strict_update_filter.d.ts +165 -0
  28. package/backend/dist/cjs/backend/src/database/filters/strict_update_filter.js +15 -0
  29. package/backend/dist/cjs/backend/src/database/filters/strict_update_filter_test.d.ts +5 -0
  30. package/backend/dist/cjs/backend/src/database/filters/strict_update_filter_test.js +355 -0
  31. package/backend/dist/cjs/backend/src/database/flatten.d.ts +78 -0
  32. package/backend/dist/cjs/backend/src/database/flatten.js +53 -0
  33. package/backend/dist/cjs/backend/src/database/flatten_test.d.ts +1 -0
  34. package/backend/dist/cjs/backend/src/database/flatten_test.js +175 -0
  35. package/backend/dist/cjs/backend/src/database/quota/quoata_v2.d.ts +533 -0
  36. package/backend/dist/cjs/backend/src/database/quota/quoata_v2.js +1046 -0
  37. package/backend/dist/cjs/backend/src/database/quota/quota.d.ts +551 -0
  38. package/backend/dist/cjs/backend/src/database/quota/quota.js +1108 -0
  39. package/backend/dist/cjs/backend/src/database/quota/quota_v1.d.ts +534 -0
  40. package/backend/dist/cjs/backend/src/database/quota/quota_v1.js +1087 -0
  41. package/backend/dist/cjs/backend/src/database/quota/safe_int.d.ts +412 -0
  42. package/backend/dist/cjs/backend/src/database/quota/safe_int.js +745 -0
  43. package/backend/dist/cjs/backend/src/endpoint.d.ts +346 -0
  44. package/backend/dist/cjs/backend/src/endpoint.js +468 -0
  45. package/backend/dist/cjs/backend/src/errors/index.d.ts +7 -0
  46. package/backend/dist/cjs/backend/src/errors/index.js +25 -0
  47. package/backend/dist/cjs/backend/src/errors/internal_external.d.ts +52 -0
  48. package/backend/dist/cjs/backend/src/errors/internal_external.js +95 -0
  49. package/backend/dist/cjs/backend/src/errors/invalid_usage_error.d.ts +41 -0
  50. package/backend/dist/cjs/backend/src/errors/invalid_usage_error.js +47 -0
  51. package/backend/dist/cjs/backend/src/errors/system_error.d.ts +261 -0
  52. package/backend/dist/cjs/backend/src/errors/system_error.js +436 -0
  53. package/backend/dist/cjs/backend/src/events.d.ts +97 -0
  54. package/backend/dist/cjs/backend/src/events.js +15 -0
  55. package/backend/dist/cjs/backend/src/frontend.d.ts +13 -0
  56. package/backend/dist/cjs/backend/src/frontend.js +56 -0
  57. package/backend/dist/cjs/backend/src/image_endpoint.d.ts +44 -0
  58. package/backend/dist/cjs/backend/src/image_endpoint.js +185 -0
  59. package/backend/dist/cjs/backend/src/index.d.ts +23 -0
  60. package/backend/dist/cjs/backend/src/index.js +70 -0
  61. package/backend/dist/cjs/backend/src/logger.d.ts +5 -0
  62. package/backend/dist/cjs/backend/src/logger.js +15 -0
  63. package/backend/dist/cjs/backend/src/meta.d.ts +112 -0
  64. package/backend/dist/cjs/backend/src/meta.js +181 -0
  65. package/backend/dist/cjs/backend/src/payments/paddle.d.ts +329 -0
  66. package/backend/dist/cjs/backend/src/payments/paddle.js +1996 -0
  67. package/backend/dist/cjs/backend/src/payments/stripe/checkout.d.ts +113 -0
  68. package/backend/dist/cjs/backend/src/payments/stripe/checkout.js +295 -0
  69. package/backend/dist/cjs/backend/src/payments/stripe/customers.d.ts +17 -0
  70. package/backend/dist/cjs/backend/src/payments/stripe/customers.js +164 -0
  71. package/backend/dist/cjs/backend/src/payments/stripe/error.d.ts +74 -0
  72. package/backend/dist/cjs/backend/src/payments/stripe/error.js +64 -0
  73. package/backend/dist/cjs/backend/src/payments/stripe/events.d.ts +155 -0
  74. package/backend/dist/cjs/backend/src/payments/stripe/events.js +15 -0
  75. package/backend/dist/cjs/backend/src/payments/stripe/meters.d.ts +105 -0
  76. package/backend/dist/cjs/backend/src/payments/stripe/meters.js +230 -0
  77. package/backend/dist/cjs/backend/src/payments/stripe/payment_methods.d.ts +58 -0
  78. package/backend/dist/cjs/backend/src/payments/stripe/payment_methods.js +109 -0
  79. package/backend/dist/cjs/backend/src/payments/stripe/products.d.ts +519 -0
  80. package/backend/dist/cjs/backend/src/payments/stripe/products.js +650 -0
  81. package/backend/dist/cjs/backend/src/payments/stripe/stripe.d.ts +215 -0
  82. package/backend/dist/cjs/backend/src/payments/stripe/stripe.js +468 -0
  83. package/backend/dist/cjs/backend/src/payments/stripe/subscriptions.d.ts +172 -0
  84. package/backend/dist/cjs/backend/src/payments/stripe/subscriptions.js +557 -0
  85. package/backend/dist/cjs/backend/src/payments/stripe/utils.d.ts +63 -0
  86. package/backend/dist/cjs/backend/src/payments/stripe/utils.js +118 -0
  87. package/backend/dist/cjs/backend/src/payments/stripe/webhooks.d.ts +105 -0
  88. package/backend/dist/cjs/backend/src/payments/stripe/webhooks.js +627 -0
  89. package/backend/dist/cjs/backend/src/plugins/browser.d.ts +1 -0
  90. package/backend/dist/cjs/backend/src/plugins/browser.js +15 -0
  91. package/backend/dist/cjs/backend/src/plugins/communication.d.ts +70 -0
  92. package/backend/dist/cjs/backend/src/plugins/communication.js +196 -0
  93. package/backend/dist/cjs/backend/src/plugins/mail/mail.d.ts +255 -0
  94. package/backend/dist/cjs/backend/src/plugins/mail/mail.js +381 -0
  95. package/backend/dist/cjs/backend/src/plugins/mail/ui.d.ts +297 -0
  96. package/backend/dist/cjs/backend/src/plugins/mail/ui.js +1370 -0
  97. package/backend/dist/cjs/backend/src/plugins/pdf.d.ts +1 -0
  98. package/backend/dist/cjs/backend/src/plugins/pdf.js +1456 -0
  99. package/backend/dist/cjs/backend/src/plugins/thread_monitor.d.ts +18 -0
  100. package/backend/dist/cjs/backend/src/plugins/thread_monitor.js +116 -0
  101. package/backend/dist/cjs/backend/src/rate_limit.d.ts +148 -0
  102. package/backend/dist/cjs/backend/src/rate_limit.js +543 -0
  103. package/backend/dist/cjs/backend/src/route.d.ts +39 -0
  104. package/backend/dist/cjs/backend/src/route.js +172 -0
  105. package/backend/dist/cjs/backend/src/server.d.ts +502 -0
  106. package/backend/dist/cjs/backend/src/server.js +1710 -0
  107. package/backend/dist/cjs/backend/src/server.old.d.ts +594 -0
  108. package/backend/dist/cjs/backend/src/server.old.js +2058 -0
  109. package/backend/dist/cjs/backend/src/splash_screen.d.ts +93 -0
  110. package/backend/dist/cjs/backend/src/splash_screen.js +119 -0
  111. package/backend/dist/cjs/backend/src/status.d.ts +89 -0
  112. package/backend/dist/cjs/backend/src/status.js +211 -0
  113. package/backend/dist/cjs/backend/src/stream.d.ts +494 -0
  114. package/backend/dist/cjs/backend/src/stream.js +1370 -0
  115. package/backend/dist/cjs/backend/src/users.d.ts +926 -0
  116. package/backend/dist/cjs/backend/src/users.js +2223 -0
  117. package/backend/dist/cjs/backend/src/utils.d.ts +22 -0
  118. package/backend/dist/cjs/backend/src/utils.js +626 -0
  119. package/backend/dist/cjs/backend/src/view.d.ts +115 -0
  120. package/backend/dist/cjs/backend/src/view.js +519 -0
  121. package/backend/dist/cjs/backend/src/vinc.d.ts +6 -0
  122. package/backend/dist/cjs/backend/src/vinc.js +40 -0
  123. package/backend/dist/cjs/backend/src/volt.d.ts +24 -0
  124. package/backend/dist/cjs/backend/src/volt.js +72 -0
  125. package/backend/dist/cjs/frontend/src/modules/request.d.ts +70 -0
  126. package/backend/dist/cjs/frontend/src/modules/request.js +99 -0
  127. package/backend/dist/cjs/package.json +1 -0
  128. package/backend/dist/esm/backend/src/blacklist.d.ts +12 -0
  129. package/backend/dist/esm/backend/src/blacklist.js +52 -0
  130. package/backend/dist/esm/backend/src/cli.d.ts +2 -0
  131. package/backend/dist/esm/backend/src/cli.js +211 -0
  132. package/backend/dist/esm/backend/src/database/collection.d.ts +1765 -0
  133. package/backend/dist/esm/backend/src/database/collection.js +3779 -0
  134. package/backend/dist/esm/backend/src/database/database.d.ts +92 -0
  135. package/backend/dist/esm/backend/src/database/database.js +214 -0
  136. package/backend/dist/esm/backend/src/database/document.d.ts +1 -0
  137. package/backend/dist/esm/backend/src/database/document.js +558 -0
  138. package/backend/dist/esm/backend/src/database/filters/filters.d.ts +6 -0
  139. package/backend/dist/esm/backend/src/database/filters/filters.js +1 -0
  140. package/backend/dist/esm/backend/src/database/filters/strict_filter.d.ts +223 -0
  141. package/backend/dist/esm/backend/src/database/filters/strict_filter.js +3 -0
  142. package/backend/dist/esm/backend/src/database/filters/strict_filter_test.d.ts +1 -0
  143. package/backend/dist/esm/backend/src/database/filters/strict_filter_test.js +505 -0
  144. package/backend/dist/esm/backend/src/database/filters/strict_filter_test_v0.d.ts +1 -0
  145. package/backend/dist/esm/backend/src/database/filters/strict_filter_test_v0.js +712 -0
  146. package/backend/dist/esm/backend/src/database/filters/strict_filter_v0.d.ts +50 -0
  147. package/backend/dist/esm/backend/src/database/filters/strict_filter_v0.js +5 -0
  148. package/backend/dist/esm/backend/src/database/filters/strict_filter_v1.d.ts +76 -0
  149. package/backend/dist/esm/backend/src/database/filters/strict_filter_v1.js +44 -0
  150. package/backend/dist/esm/backend/src/database/filters/strict_filter_v2.d.ts +75 -0
  151. package/backend/dist/esm/backend/src/database/filters/strict_filter_v2.js +5 -0
  152. package/backend/dist/esm/backend/src/database/filters/strict_filter_v3.d.ts +219 -0
  153. package/backend/dist/esm/backend/src/database/filters/strict_filter_v3.js +1 -0
  154. package/backend/dist/esm/backend/src/database/filters/strict_update_filter.d.ts +165 -0
  155. package/backend/dist/esm/backend/src/database/filters/strict_update_filter.js +5 -0
  156. package/backend/dist/esm/backend/src/database/filters/strict_update_filter_test.d.ts +5 -0
  157. package/backend/dist/esm/backend/src/database/filters/strict_update_filter_test.js +415 -0
  158. package/backend/dist/esm/backend/src/database/flatten.d.ts +78 -0
  159. package/backend/dist/esm/backend/src/database/flatten.js +22 -0
  160. package/backend/dist/esm/backend/src/database/flatten_test.d.ts +1 -0
  161. package/backend/dist/esm/backend/src/database/flatten_test.js +174 -0
  162. package/backend/dist/esm/backend/src/database/quota/quoata_v2.d.ts +533 -0
  163. package/backend/dist/esm/backend/src/database/quota/quoata_v2.js +1155 -0
  164. package/backend/dist/esm/backend/src/database/quota/quota.d.ts +551 -0
  165. package/backend/dist/esm/backend/src/database/quota/quota.js +1219 -0
  166. package/backend/dist/esm/backend/src/database/quota/quota_v1.d.ts +534 -0
  167. package/backend/dist/esm/backend/src/database/quota/quota_v1.js +1242 -0
  168. package/backend/dist/esm/backend/src/database/quota/safe_int.d.ts +412 -0
  169. package/backend/dist/esm/backend/src/database/quota/safe_int.js +810 -0
  170. package/backend/dist/esm/backend/src/endpoint.d.ts +346 -0
  171. package/backend/dist/esm/backend/src/endpoint.js +479 -0
  172. package/backend/dist/esm/backend/src/errors/index.d.ts +7 -0
  173. package/backend/dist/esm/backend/src/errors/index.js +7 -0
  174. package/backend/dist/esm/backend/src/errors/internal_external.d.ts +52 -0
  175. package/backend/dist/esm/backend/src/errors/internal_external.js +86 -0
  176. package/backend/dist/esm/backend/src/errors/invalid_usage_error.d.ts +41 -0
  177. package/backend/dist/esm/backend/src/errors/invalid_usage_error.js +33 -0
  178. package/backend/dist/esm/backend/src/errors/system_error.d.ts +261 -0
  179. package/backend/dist/esm/backend/src/errors/system_error.js +444 -0
  180. package/backend/dist/esm/backend/src/events.d.ts +97 -0
  181. package/backend/dist/esm/backend/src/events.js +5 -0
  182. package/backend/dist/esm/backend/src/frontend.d.ts +13 -0
  183. package/backend/dist/esm/backend/src/frontend.js +23 -0
  184. package/backend/dist/esm/backend/src/image_endpoint.d.ts +44 -0
  185. package/backend/dist/esm/backend/src/image_endpoint.js +196 -0
  186. package/backend/dist/esm/backend/src/index.d.ts +23 -0
  187. package/backend/dist/esm/backend/src/index.js +26 -0
  188. package/backend/dist/esm/backend/src/logger.d.ts +5 -0
  189. package/backend/dist/esm/backend/src/logger.js +8 -0
  190. package/backend/dist/esm/backend/src/meta.d.ts +112 -0
  191. package/backend/dist/esm/backend/src/meta.js +152 -0
  192. package/backend/dist/esm/backend/src/payments/paddle.d.ts +329 -0
  193. package/backend/dist/esm/backend/src/payments/paddle.js +2276 -0
  194. package/backend/dist/esm/backend/src/payments/stripe/checkout.d.ts +113 -0
  195. package/backend/dist/esm/backend/src/payments/stripe/checkout.js +356 -0
  196. package/backend/dist/esm/backend/src/payments/stripe/customers.d.ts +17 -0
  197. package/backend/dist/esm/backend/src/payments/stripe/customers.js +193 -0
  198. package/backend/dist/esm/backend/src/payments/stripe/error.d.ts +74 -0
  199. package/backend/dist/esm/backend/src/payments/stripe/error.js +51 -0
  200. package/backend/dist/esm/backend/src/payments/stripe/events.d.ts +155 -0
  201. package/backend/dist/esm/backend/src/payments/stripe/events.js +5 -0
  202. package/backend/dist/esm/backend/src/payments/stripe/meters.d.ts +105 -0
  203. package/backend/dist/esm/backend/src/payments/stripe/meters.js +318 -0
  204. package/backend/dist/esm/backend/src/payments/stripe/payment_methods.d.ts +58 -0
  205. package/backend/dist/esm/backend/src/payments/stripe/payment_methods.js +135 -0
  206. package/backend/dist/esm/backend/src/payments/stripe/products.d.ts +519 -0
  207. package/backend/dist/esm/backend/src/payments/stripe/products.js +896 -0
  208. package/backend/dist/esm/backend/src/payments/stripe/stripe.d.ts +215 -0
  209. package/backend/dist/esm/backend/src/payments/stripe/stripe.js +464 -0
  210. package/backend/dist/esm/backend/src/payments/stripe/subscriptions.d.ts +172 -0
  211. package/backend/dist/esm/backend/src/payments/stripe/subscriptions.js +754 -0
  212. package/backend/dist/esm/backend/src/payments/stripe/utils.d.ts +63 -0
  213. package/backend/dist/esm/backend/src/payments/stripe/utils.js +131 -0
  214. package/backend/dist/esm/backend/src/payments/stripe/webhooks.d.ts +105 -0
  215. package/backend/dist/esm/backend/src/payments/stripe/webhooks.js +752 -0
  216. package/backend/dist/esm/backend/src/plugins/browser.d.ts +1 -0
  217. package/backend/dist/esm/backend/src/plugins/browser.js +170 -0
  218. package/backend/dist/esm/backend/src/plugins/communication.d.ts +70 -0
  219. package/backend/dist/esm/backend/src/plugins/communication.js +169 -0
  220. package/backend/dist/esm/backend/src/plugins/mail/mail.d.ts +255 -0
  221. package/backend/dist/esm/backend/src/plugins/mail/mail.js +396 -0
  222. package/backend/dist/esm/backend/src/plugins/mail/ui.d.ts +297 -0
  223. package/backend/dist/esm/backend/src/plugins/mail/ui.js +1400 -0
  224. package/backend/dist/esm/backend/src/plugins/pdf.d.ts +1 -0
  225. package/backend/dist/esm/backend/src/plugins/pdf.js +1694 -0
  226. package/backend/dist/esm/backend/src/plugins/thread_monitor.d.ts +18 -0
  227. package/backend/dist/esm/backend/src/plugins/thread_monitor.js +120 -0
  228. package/backend/dist/esm/backend/src/rate_limit.d.ts +148 -0
  229. package/backend/dist/esm/backend/src/rate_limit.js +667 -0
  230. package/backend/dist/esm/backend/src/route.d.ts +39 -0
  231. package/backend/dist/esm/backend/src/route.js +222 -0
  232. package/backend/dist/esm/backend/src/server.d.ts +502 -0
  233. package/backend/dist/esm/backend/src/server.js +2031 -0
  234. package/backend/dist/esm/backend/src/server.old.d.ts +594 -0
  235. package/backend/dist/esm/backend/src/server.old.js +2630 -0
  236. package/backend/dist/esm/backend/src/splash_screen.d.ts +93 -0
  237. package/backend/dist/esm/backend/src/splash_screen.js +156 -0
  238. package/backend/dist/esm/backend/src/status.d.ts +89 -0
  239. package/backend/dist/esm/backend/src/status.js +213 -0
  240. package/backend/dist/esm/backend/src/stream.d.ts +494 -0
  241. package/backend/dist/esm/backend/src/stream.js +1611 -0
  242. package/backend/dist/esm/backend/src/users.d.ts +926 -0
  243. package/backend/dist/esm/backend/src/users.js +2423 -0
  244. package/backend/dist/esm/backend/src/utils.d.ts +22 -0
  245. package/backend/dist/esm/backend/src/utils.js +463 -0
  246. package/backend/dist/esm/backend/src/view.d.ts +115 -0
  247. package/backend/dist/esm/backend/src/view.js +584 -0
  248. package/backend/dist/esm/backend/src/vinc.d.ts +6 -0
  249. package/backend/dist/esm/backend/src/vinc.js +6 -0
  250. package/backend/dist/esm/backend/src/volt.d.ts +24 -0
  251. package/backend/dist/esm/backend/src/volt.js +27 -0
  252. package/backend/dist/esm/frontend/src/modules/request.d.ts +70 -0
  253. package/backend/dist/esm/frontend/src/modules/request.js +117 -0
  254. package/frontend/dist/backend/src/database/collection.d.ts +1765 -0
  255. package/frontend/dist/backend/src/database/collection.js +3779 -0
  256. package/frontend/dist/backend/src/database/database.d.ts +92 -0
  257. package/frontend/dist/backend/src/database/database.js +214 -0
  258. package/frontend/dist/backend/src/database/filters/filters.d.ts +6 -0
  259. package/frontend/dist/backend/src/database/filters/filters.js +1 -0
  260. package/frontend/dist/backend/src/database/filters/strict_filter.d.ts +223 -0
  261. package/frontend/dist/backend/src/database/filters/strict_filter.js +3 -0
  262. package/frontend/dist/backend/src/database/filters/strict_update_filter.d.ts +165 -0
  263. package/frontend/dist/backend/src/database/filters/strict_update_filter.js +5 -0
  264. package/frontend/dist/backend/src/database/flatten.d.ts +78 -0
  265. package/frontend/dist/backend/src/database/flatten.js +22 -0
  266. package/frontend/dist/backend/src/endpoint.d.ts +346 -0
  267. package/frontend/dist/backend/src/endpoint.js +479 -0
  268. package/frontend/dist/backend/src/errors/index.d.ts +7 -0
  269. package/frontend/dist/backend/src/errors/index.js +7 -0
  270. package/frontend/dist/backend/src/errors/internal_external.d.ts +52 -0
  271. package/frontend/dist/backend/src/errors/internal_external.js +86 -0
  272. package/frontend/dist/backend/src/errors/invalid_usage_error.d.ts +41 -0
  273. package/frontend/dist/backend/src/errors/invalid_usage_error.js +33 -0
  274. package/frontend/dist/backend/src/errors/system_error.d.ts +261 -0
  275. package/frontend/dist/backend/src/errors/system_error.js +444 -0
  276. package/frontend/dist/backend/src/events.d.ts +97 -0
  277. package/frontend/dist/backend/src/events.js +5 -0
  278. package/frontend/dist/backend/src/frontend.d.ts +13 -0
  279. package/frontend/dist/backend/src/frontend.js +23 -0
  280. package/frontend/dist/backend/src/image_endpoint.d.ts +44 -0
  281. package/frontend/dist/backend/src/image_endpoint.js +196 -0
  282. package/frontend/dist/backend/src/meta.d.ts +112 -0
  283. package/frontend/dist/backend/src/meta.js +152 -0
  284. package/frontend/dist/backend/src/payments/paddle.d.ts +329 -0
  285. package/frontend/dist/backend/src/payments/paddle.js +2276 -0
  286. package/frontend/dist/backend/src/payments/stripe/checkout.d.ts +113 -0
  287. package/frontend/dist/backend/src/payments/stripe/checkout.js +356 -0
  288. package/frontend/dist/backend/src/payments/stripe/customers.d.ts +17 -0
  289. package/frontend/dist/backend/src/payments/stripe/customers.js +193 -0
  290. package/frontend/dist/backend/src/payments/stripe/error.d.ts +74 -0
  291. package/frontend/dist/backend/src/payments/stripe/error.js +51 -0
  292. package/frontend/dist/backend/src/payments/stripe/events.d.ts +155 -0
  293. package/frontend/dist/backend/src/payments/stripe/events.js +5 -0
  294. package/frontend/dist/backend/src/payments/stripe/meters.d.ts +105 -0
  295. package/frontend/dist/backend/src/payments/stripe/meters.js +318 -0
  296. package/frontend/dist/backend/src/payments/stripe/payment_methods.d.ts +58 -0
  297. package/frontend/dist/backend/src/payments/stripe/payment_methods.js +135 -0
  298. package/frontend/dist/backend/src/payments/stripe/products.d.ts +519 -0
  299. package/frontend/dist/backend/src/payments/stripe/products.js +896 -0
  300. package/frontend/dist/backend/src/payments/stripe/stripe.d.ts +215 -0
  301. package/frontend/dist/backend/src/payments/stripe/stripe.js +464 -0
  302. package/frontend/dist/backend/src/payments/stripe/subscriptions.d.ts +172 -0
  303. package/frontend/dist/backend/src/payments/stripe/subscriptions.js +754 -0
  304. package/frontend/dist/backend/src/payments/stripe/utils.d.ts +63 -0
  305. package/frontend/dist/backend/src/payments/stripe/utils.js +131 -0
  306. package/frontend/dist/backend/src/payments/stripe/webhooks.d.ts +105 -0
  307. package/frontend/dist/backend/src/payments/stripe/webhooks.js +752 -0
  308. package/frontend/dist/backend/src/plugins/mail/mail.d.ts +255 -0
  309. package/frontend/dist/backend/src/plugins/mail/mail.js +396 -0
  310. package/frontend/dist/backend/src/plugins/mail/ui.d.ts +297 -0
  311. package/frontend/dist/backend/src/plugins/mail/ui.js +1400 -0
  312. package/frontend/dist/backend/src/rate_limit.d.ts +148 -0
  313. package/frontend/dist/backend/src/rate_limit.js +667 -0
  314. package/frontend/dist/backend/src/route.d.ts +39 -0
  315. package/frontend/dist/backend/src/route.js +222 -0
  316. package/frontend/dist/backend/src/server.d.ts +502 -0
  317. package/frontend/dist/backend/src/server.js +2031 -0
  318. package/frontend/dist/backend/src/splash_screen.d.ts +93 -0
  319. package/frontend/dist/backend/src/splash_screen.js +156 -0
  320. package/frontend/dist/backend/src/status.d.ts +89 -0
  321. package/frontend/dist/backend/src/status.js +213 -0
  322. package/frontend/dist/backend/src/stream.d.ts +494 -0
  323. package/frontend/dist/backend/src/stream.js +1611 -0
  324. package/frontend/dist/backend/src/users.d.ts +926 -0
  325. package/frontend/dist/backend/src/users.js +2423 -0
  326. package/frontend/dist/backend/src/utils.d.ts +22 -0
  327. package/frontend/dist/backend/src/utils.js +463 -0
  328. package/frontend/dist/backend/src/view.d.ts +115 -0
  329. package/frontend/dist/backend/src/view.js +584 -0
  330. package/frontend/dist/frontend/src/css/adyen.css +92 -0
  331. package/frontend/dist/frontend/src/css/volt.css +75 -0
  332. package/frontend/dist/frontend/src/elements/base.d.ts +3743 -0
  333. package/frontend/dist/frontend/src/elements/base.js +12151 -0
  334. package/frontend/dist/frontend/src/elements/module.d.ts +95 -0
  335. package/frontend/dist/frontend/src/elements/module.js +216 -0
  336. package/frontend/dist/frontend/src/elements/register_element.d.ts +3 -0
  337. package/frontend/dist/frontend/src/elements/register_element.js +22 -0
  338. package/frontend/dist/frontend/src/elements/resize_query_manager.d.ts +0 -0
  339. package/frontend/dist/frontend/src/elements/resize_query_manager.js +150 -0
  340. package/frontend/dist/frontend/src/elements/types.d.ts +52 -0
  341. package/frontend/dist/frontend/src/elements/types.js +5 -0
  342. package/frontend/dist/frontend/src/index.d.ts +21 -0
  343. package/frontend/dist/frontend/src/index.js +29 -0
  344. package/frontend/dist/frontend/src/modules/attachment.d.ts +126 -0
  345. package/frontend/dist/frontend/src/modules/attachment.js +306 -0
  346. package/frontend/dist/frontend/src/modules/auth.d.ts +44 -0
  347. package/frontend/dist/frontend/src/modules/auth.js +80 -0
  348. package/frontend/dist/frontend/src/modules/color.d.ts +160 -0
  349. package/frontend/dist/frontend/src/modules/color.js +316 -0
  350. package/frontend/dist/frontend/src/modules/compression.d.ts +39 -0
  351. package/frontend/dist/frontend/src/modules/compression.js +102 -0
  352. package/frontend/dist/frontend/src/modules/cookies.d.ts +44 -0
  353. package/frontend/dist/frontend/src/modules/cookies.js +143 -0
  354. package/frontend/dist/frontend/src/modules/events.d.ts +31 -0
  355. package/frontend/dist/frontend/src/modules/events.js +79 -0
  356. package/frontend/dist/frontend/src/modules/google.d.ts +23 -0
  357. package/frontend/dist/frontend/src/modules/google.js +52 -0
  358. package/frontend/dist/frontend/src/modules/meta.d.ts +14 -0
  359. package/frontend/dist/frontend/src/modules/meta.js +48 -0
  360. package/frontend/dist/frontend/src/modules/paddle.d.ts +1207 -0
  361. package/frontend/dist/frontend/src/modules/paddle.js +2594 -0
  362. package/frontend/dist/frontend/src/modules/request.d.ts +70 -0
  363. package/frontend/dist/frontend/src/modules/request.js +117 -0
  364. package/frontend/dist/frontend/src/modules/settings.d.ts +3 -0
  365. package/frontend/dist/frontend/src/modules/settings.js +5 -0
  366. package/frontend/dist/frontend/src/modules/statics.d.ts +21 -0
  367. package/frontend/dist/frontend/src/modules/statics.js +43 -0
  368. package/frontend/dist/frontend/src/modules/stripe/cart.d.ts +112 -0
  369. package/frontend/dist/frontend/src/modules/stripe/cart.js +321 -0
  370. package/frontend/dist/frontend/src/modules/stripe/checkout.d.ts +7 -0
  371. package/frontend/dist/frontend/src/modules/stripe/checkout.js +37 -0
  372. package/frontend/dist/frontend/src/modules/stripe/index.m.d.ts +6 -0
  373. package/frontend/dist/frontend/src/modules/stripe/index.m.js +6 -0
  374. package/frontend/dist/frontend/src/modules/stripe/payments.d.ts +58 -0
  375. package/frontend/dist/frontend/src/modules/stripe/payments.js +92 -0
  376. package/frontend/dist/frontend/src/modules/support.d.ts +30 -0
  377. package/frontend/dist/frontend/src/modules/support.js +53 -0
  378. package/frontend/dist/frontend/src/modules/theme.d.ts +133 -0
  379. package/frontend/dist/frontend/src/modules/theme.js +406 -0
  380. package/frontend/dist/frontend/src/modules/themes.d.ts +12 -0
  381. package/frontend/dist/frontend/src/modules/themes.js +22 -0
  382. package/frontend/dist/frontend/src/modules/user.d.ts +164 -0
  383. package/frontend/dist/frontend/src/modules/user.js +270 -0
  384. package/frontend/dist/frontend/src/modules/utils.d.ts +176 -0
  385. package/frontend/dist/frontend/src/modules/utils.js +569 -0
  386. package/frontend/dist/frontend/src/types/gradient.d.ts +29 -0
  387. package/frontend/dist/frontend/src/types/gradient.js +79 -0
  388. package/frontend/dist/frontend/src/ui/border_button.d.ts +94 -0
  389. package/frontend/dist/frontend/src/ui/border_button.js +228 -0
  390. package/frontend/dist/frontend/src/ui/button.d.ts +241 -0
  391. package/frontend/dist/frontend/src/ui/button.js +682 -0
  392. package/frontend/dist/frontend/src/ui/canvas.d.ts +138 -0
  393. package/frontend/dist/frontend/src/ui/canvas.js +444 -0
  394. package/frontend/dist/frontend/src/ui/checkbox.d.ts +74 -0
  395. package/frontend/dist/frontend/src/ui/checkbox.js +321 -0
  396. package/frontend/dist/frontend/src/ui/code.d.ts +235 -0
  397. package/frontend/dist/frontend/src/ui/code.js +1007 -0
  398. package/frontend/dist/frontend/src/ui/context_menu.d.ts +36 -0
  399. package/frontend/dist/frontend/src/ui/context_menu.js +205 -0
  400. package/frontend/dist/frontend/src/ui/css.d.ts +16 -0
  401. package/frontend/dist/frontend/src/ui/css.js +48 -0
  402. package/frontend/dist/frontend/src/ui/divider.d.ts +15 -0
  403. package/frontend/dist/frontend/src/ui/divider.js +78 -0
  404. package/frontend/dist/frontend/src/ui/dropdown.d.ts +176 -0
  405. package/frontend/dist/frontend/src/ui/dropdown.js +481 -0
  406. package/frontend/dist/frontend/src/ui/for_each.d.ts +37 -0
  407. package/frontend/dist/frontend/src/ui/for_each.js +92 -0
  408. package/frontend/dist/frontend/src/ui/form.d.ts +34 -0
  409. package/frontend/dist/frontend/src/ui/form.js +233 -0
  410. package/frontend/dist/frontend/src/ui/frame_modes.d.ts +37 -0
  411. package/frontend/dist/frontend/src/ui/frame_modes.js +108 -0
  412. package/frontend/dist/frontend/src/ui/google_map.d.ts +24 -0
  413. package/frontend/dist/frontend/src/ui/google_map.js +106 -0
  414. package/frontend/dist/frontend/src/ui/gradient.d.ts +25 -0
  415. package/frontend/dist/frontend/src/ui/gradient.js +131 -0
  416. package/frontend/dist/frontend/src/ui/image.d.ts +111 -0
  417. package/frontend/dist/frontend/src/ui/image.js +576 -0
  418. package/frontend/dist/frontend/src/ui/input.d.ts +392 -0
  419. package/frontend/dist/frontend/src/ui/input.js +1201 -0
  420. package/frontend/dist/frontend/src/ui/link.d.ts +25 -0
  421. package/frontend/dist/frontend/src/ui/link.js +140 -0
  422. package/frontend/dist/frontend/src/ui/list.d.ts +37 -0
  423. package/frontend/dist/frontend/src/ui/list.js +170 -0
  424. package/frontend/dist/frontend/src/ui/loader_button.d.ts +80 -0
  425. package/frontend/dist/frontend/src/ui/loader_button.js +193 -0
  426. package/frontend/dist/frontend/src/ui/loaders.d.ts +57 -0
  427. package/frontend/dist/frontend/src/ui/loaders.js +157 -0
  428. package/frontend/dist/frontend/src/ui/popup.d.ts +94 -0
  429. package/frontend/dist/frontend/src/ui/popup.js +510 -0
  430. package/frontend/dist/frontend/src/ui/pseudo.d.ts +44 -0
  431. package/frontend/dist/frontend/src/ui/pseudo.js +154 -0
  432. package/frontend/dist/frontend/src/ui/scroller.d.ts +105 -0
  433. package/frontend/dist/frontend/src/ui/scroller.js +1253 -0
  434. package/frontend/dist/frontend/src/ui/slider.d.ts +45 -0
  435. package/frontend/dist/frontend/src/ui/slider.js +217 -0
  436. package/frontend/dist/frontend/src/ui/spacer.d.ts +15 -0
  437. package/frontend/dist/frontend/src/ui/spacer.js +78 -0
  438. package/frontend/dist/frontend/src/ui/span.d.ts +15 -0
  439. package/frontend/dist/frontend/src/ui/span.js +73 -0
  440. package/frontend/dist/frontend/src/ui/stack.d.ts +66 -0
  441. package/frontend/dist/frontend/src/ui/stack.js +335 -0
  442. package/frontend/dist/frontend/src/ui/steps.d.ts +131 -0
  443. package/frontend/dist/frontend/src/ui/steps.js +308 -0
  444. package/frontend/dist/frontend/src/ui/style.d.ts +17 -0
  445. package/frontend/dist/frontend/src/ui/style.js +73 -0
  446. package/frontend/dist/frontend/src/ui/switch.d.ts +69 -0
  447. package/frontend/dist/frontend/src/ui/switch.js +357 -0
  448. package/frontend/dist/frontend/src/ui/table.d.ts +100 -0
  449. package/frontend/dist/frontend/src/ui/table.js +405 -0
  450. package/frontend/dist/frontend/src/ui/tabs.d.ts +111 -0
  451. package/frontend/dist/frontend/src/ui/tabs.js +424 -0
  452. package/frontend/dist/frontend/src/ui/text.d.ts +15 -0
  453. package/frontend/dist/frontend/src/ui/text.js +83 -0
  454. package/frontend/dist/frontend/src/ui/title.d.ts +91 -0
  455. package/frontend/dist/frontend/src/ui/title.js +272 -0
  456. package/frontend/dist/frontend/src/ui/ui.d.ts +35 -0
  457. package/frontend/dist/frontend/src/ui/ui.js +38 -0
  458. package/frontend/dist/frontend/src/ui/view.d.ts +15 -0
  459. package/frontend/dist/frontend/src/ui/view.js +88 -0
  460. package/frontend/dist/frontend/src/volt.d.ts +20 -0
  461. package/frontend/dist/frontend/src/volt.js +27 -0
  462. package/package.json +7 -2
@@ -0,0 +1,1370 @@
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
+ Stream: () => Stream
31
+ });
32
+ module.exports = __toCommonJS(stdin_exports);
33
+ var vlib = __toESM(require("@vandenberghinc/vlib"));
34
+ var import_node_stream = require("node:stream");
35
+ var fs = __toESM(require("node:fs"));
36
+ var import_node_stream2 = require("node:stream");
37
+ var zlib = __toESM(require("node:zlib"));
38
+ var import_rate_limit = __toESM(require("./rate_limit.js"));
39
+ var import_utils = require("./utils.js");
40
+ const { debug } = vlib;
41
+ class Stream {
42
+ /** The request headers. */
43
+ headers;
44
+ /** Whether this stream is an HTTP/2 stream. */
45
+ http2;
46
+ /** Whether this stream is an HTTP/1.1 stream (when false, it's an HTTP/2 stream). */
47
+ http1;
48
+ /** The status code of the sent response. */
49
+ status_code;
50
+ /** Whether the response has been finished. */
51
+ finished;
52
+ /** The received body potentially decompressed as string. */
53
+ body;
54
+ /** The raw body as a Buffer, potentially decompressed. */
55
+ raw_body;
56
+ /** The body wired exactly as is, not decompressed etc. */
57
+ wire_body;
58
+ /** The internal promise that resolves when the body is fully received. */
59
+ promise;
60
+ /** The cached value of {@link normalize_ip} */
61
+ _normalized_ip;
62
+ s;
63
+ req;
64
+ res;
65
+ _ip;
66
+ _port;
67
+ _method;
68
+ _params;
69
+ _is_query_params;
70
+ _endpoint;
71
+ _query_string;
72
+ _cookies;
73
+ _uid;
74
+ res_cookies;
75
+ res_headers;
76
+ /**
77
+ * Create a new Stream wrapper for HTTP/1.1 or HTTP/2.
78
+ *
79
+ * @param stream The HTTP/2 stream (when using HTTP/2).
80
+ * @param headers The request headers.
81
+ * @param req The HTTP/1.1 request (when using HTTP/1.1).
82
+ * @param res The HTTP/1.1/HTTP/2 response object.
83
+ */
84
+ constructor(stream, headers, req, res) {
85
+ this.s = stream;
86
+ this.headers = headers ?? {};
87
+ this.req = req;
88
+ this.res = res;
89
+ this.http2 = req == null;
90
+ this.http1 = req != null;
91
+ if (this.http1) {
92
+ this.headers = this.req.headers;
93
+ }
94
+ this._ip = this.http2 ? this.s.session.socket.remoteAddress : this.req.socket.remoteAddress;
95
+ this._port = this.http2 ? this.s.session.socket.remotePort : this.req.socket.remotePort;
96
+ this._method = this.http2 ? this.headers[":method"] : this.req.method;
97
+ this._params = void 0;
98
+ this._is_query_params = false;
99
+ this._endpoint = void 0;
100
+ this._query_string = void 0;
101
+ this._cookies = void 0;
102
+ this._uid = void 0;
103
+ this.status_code = void 0;
104
+ this.finished = false;
105
+ this.res_cookies = [];
106
+ this.res_headers = this.http1 ? [] : {};
107
+ this.body = "";
108
+ this.raw_body = Buffer.alloc(0);
109
+ this.wire_body = Buffer.alloc(0);
110
+ this.promise = void 0;
111
+ this._recv_body();
112
+ }
113
+ /**
114
+ * Receive and buffer the request body, handling optional gzip/deflate decompression.
115
+ * Sets {@link body} and resolves the internal promise used by {@link join}.
116
+ */
117
+ _recv_body() {
118
+ this.promise = new Promise((resolve, reject) => {
119
+ const buffs = [];
120
+ const wire_buffs = [];
121
+ let decompress_stream;
122
+ const content_encoding = this.headers["content-encoding"];
123
+ if (content_encoding === "gzip") {
124
+ decompress_stream = zlib.createGunzip();
125
+ } else if (content_encoding === "deflate") {
126
+ decompress_stream = zlib.createInflate();
127
+ }
128
+ const cleanup = () => {
129
+ if (decompress_stream) {
130
+ decompress_stream.close();
131
+ }
132
+ };
133
+ const on_error = (e) => {
134
+ cleanup();
135
+ reject(e);
136
+ };
137
+ if (this.http2) {
138
+ const source2 = this.s;
139
+ source2.on("data", (chunk) => {
140
+ wire_buffs.push(chunk);
141
+ });
142
+ let decoded2 = source2;
143
+ if (decompress_stream) {
144
+ decoded2 = source2.pipe(decompress_stream);
145
+ }
146
+ source2.on("error", on_error);
147
+ decoded2.on("error", on_error);
148
+ decoded2.on("data", (chunk) => {
149
+ buffs.push(chunk);
150
+ });
151
+ decoded2.on("end", () => {
152
+ try {
153
+ this.wire_body = Buffer.concat(wire_buffs);
154
+ this.raw_body = Buffer.concat(buffs);
155
+ this.body = this.raw_body.toString("utf8");
156
+ cleanup();
157
+ resolve();
158
+ } catch (e) {
159
+ on_error(e);
160
+ }
161
+ });
162
+ return;
163
+ }
164
+ const source = this.req;
165
+ source.on("data", (chunk) => {
166
+ wire_buffs.push(chunk);
167
+ });
168
+ let decoded = source;
169
+ if (decompress_stream) {
170
+ decoded = source.pipe(decompress_stream);
171
+ }
172
+ source.on("error", on_error);
173
+ decoded.on("error", on_error);
174
+ decoded.on("data", (chunk) => {
175
+ buffs.push(chunk);
176
+ });
177
+ decoded.on("end", () => {
178
+ try {
179
+ this.wire_body = Buffer.concat(wire_buffs);
180
+ this.raw_body = Buffer.concat(buffs);
181
+ this.body = this.raw_body.toString("utf8");
182
+ cleanup();
183
+ resolve();
184
+ } catch (e) {
185
+ on_error(e);
186
+ }
187
+ });
188
+ });
189
+ }
190
+ /**
191
+ * Parse and cache the request endpoint and query string.
192
+ * Populates {@link _endpoint} and {@link _query_string}.
193
+ * @private
194
+ */
195
+ _parse_endoint() {
196
+ if (this._endpoint !== void 0) {
197
+ return;
198
+ }
199
+ this._endpoint = this.http2 ? this.headers[":path"] : this.req.url;
200
+ let index;
201
+ if ((index = this._endpoint.indexOf("?")) !== -1) {
202
+ this._query_string = this._endpoint.substr(index + 1);
203
+ this._endpoint = this._endpoint.substr(0, index);
204
+ }
205
+ this._endpoint = this._endpoint.replace(/\/\//g, "/");
206
+ if (this._endpoint.length > 1 && this._endpoint.charAt(this._endpoint.length - 1) === "/") {
207
+ this._endpoint = this._endpoint.substr(0, this._endpoint.length - 1);
208
+ }
209
+ }
210
+ /**
211
+ * Parse and cache request parameters from the query string or JSON body.
212
+ * Returns the parsed params map.
213
+ */
214
+ _parse_params() {
215
+ this._parse_endoint();
216
+ if (this._params !== void 0) {
217
+ return;
218
+ }
219
+ this._params = {};
220
+ if (this._query_string !== void 0) {
221
+ if (this._query_string.charAt(0) === "{") {
222
+ try {
223
+ this._params = JSON.parse(decodeURIComponent(this._query_string));
224
+ } catch (err) {
225
+ throw Error(`Invalid json request query: ${err}.`);
226
+ }
227
+ } else {
228
+ this._is_query_params = true;
229
+ let is_key = true, key = "", value = "";
230
+ const number_regex = /^-?\d+(\.\d+)?$/;
231
+ const add_value = () => {
232
+ let output_value;
233
+ switch (value) {
234
+ case "true":
235
+ case "True":
236
+ output_value = true;
237
+ break;
238
+ case "false":
239
+ case "False":
240
+ output_value = false;
241
+ break;
242
+ case "null":
243
+ case "None":
244
+ case "undefined":
245
+ output_value = null;
246
+ break;
247
+ default:
248
+ output_value = decodeURIComponent(value.replaceAll("+", " "));
249
+ if (number_regex.test(output_value)) {
250
+ if (output_value.indexOf(".") !== -1) {
251
+ output_value = parseFloat(output_value);
252
+ } else {
253
+ output_value = parseInt(output_value);
254
+ }
255
+ }
256
+ break;
257
+ }
258
+ this._params[decodeURIComponent(key.replaceAll("+", " "))] = output_value;
259
+ key = "";
260
+ value = "";
261
+ is_key = true;
262
+ };
263
+ for (let i = 0; i < this._query_string.length; i++) {
264
+ const c = this._query_string.charAt(i);
265
+ if (is_key && c === "=") {
266
+ is_key = false;
267
+ continue;
268
+ } else if (is_key === false && c === "&") {
269
+ add_value();
270
+ continue;
271
+ }
272
+ if (is_key) {
273
+ key += c;
274
+ } else {
275
+ value += c;
276
+ }
277
+ }
278
+ if (key.length > 0) {
279
+ add_value();
280
+ }
281
+ }
282
+ } else if (this.body.trim().charAt(0) === "{") {
283
+ try {
284
+ this._params = JSON.parse(this.body);
285
+ } catch (err) {
286
+ throw Error(`Invalid json request body: ${err}.`);
287
+ }
288
+ }
289
+ return this._params;
290
+ }
291
+ /**
292
+ * Parses & returns the cookies cookies,
293
+ * while assigning it to {@link _cookies}
294
+ *
295
+ * @warning On subsequent calls cookies will be parsed again.
296
+ */
297
+ _parse_cookies() {
298
+ this._cookies = {};
299
+ const cookie_str = this.http2 ? this.headers["cookie"] : this.req.headers.cookie;
300
+ if (cookie_str == null) {
301
+ return this._cookies;
302
+ }
303
+ let key = "";
304
+ let value = "";
305
+ let cookie = {};
306
+ let cookie_length = 0;
307
+ let cookie_key = null;
308
+ let is_value = false;
309
+ let is_str = null;
310
+ const append_to_cookie = () => {
311
+ if (key.length > 0) {
312
+ if (cookie_length === 0) {
313
+ cookie.value = value;
314
+ } else {
315
+ cookie[key] = value;
316
+ }
317
+ ++cookie_length;
318
+ }
319
+ key = "";
320
+ value = "";
321
+ is_value = false;
322
+ is_str = null;
323
+ };
324
+ const append_cookie = () => {
325
+ if (cookie_key != null) {
326
+ this._cookies[cookie_key] = cookie;
327
+ cookie_key = null;
328
+ cookie = {};
329
+ cookie_length = 0;
330
+ }
331
+ };
332
+ for (let x = 0; x < cookie_str.length; x++) {
333
+ const c = cookie_str.charAt(x);
334
+ if (is_value) {
335
+ if (is_str === c) {
336
+ value = value.substr(1, value.length - 1);
337
+ append_to_cookie();
338
+ } else if (is_str == null && c === " ") {
339
+ append_to_cookie();
340
+ } else if (is_str == null && c === ";") {
341
+ append_to_cookie();
342
+ append_cookie();
343
+ } else {
344
+ value += c;
345
+ if (value.length === 1 && (c === '"' || c === "'")) {
346
+ is_str = c;
347
+ }
348
+ }
349
+ } else if (c == " " || c == " ") {
350
+ continue;
351
+ } else if (c == "=") {
352
+ if (cookie_key == null) {
353
+ cookie_key = key;
354
+ }
355
+ is_value = true;
356
+ } else {
357
+ key += c;
358
+ }
359
+ }
360
+ append_to_cookie();
361
+ append_cookie();
362
+ return this._cookies;
363
+ }
364
+ // ---------------------------------------------------------
365
+ // Functions.
366
+ /**
367
+ * Wait until the request body is fully received.
368
+ * Resolves when the internal receive promise completes.
369
+ */
370
+ async join() {
371
+ await this.promise;
372
+ }
373
+ // Get the requests ip.
374
+ /**
375
+ * Get the request's ip.
376
+ *
377
+ * @example
378
+ * ```ts
379
+ * const ip = stream.ip;
380
+ * ```
381
+ * @docs
382
+ */
383
+ get ip() {
384
+ return this._ip;
385
+ }
386
+ /**
387
+ * Retrieve the normalized IP address, suitable for rate limiting and logging.
388
+ * @throws {Error} If the IP is invalid.
389
+ * @returns The normalized IP.
390
+ * @docs
391
+ */
392
+ normalized_ip() {
393
+ if (this._normalized_ip != null) {
394
+ return this._normalized_ip;
395
+ }
396
+ return this._normalized_ip = import_rate_limit.default.normalize_ip(this._ip);
397
+ }
398
+ // Get the requests port.
399
+ /**
400
+ * Get the request's port.
401
+ *
402
+ * @example
403
+ * ```ts
404
+ * const port = stream.port;
405
+ * ```
406
+ * @docs
407
+ */
408
+ get port() {
409
+ return this._port;
410
+ }
411
+ // Get the method.
412
+ /**
413
+ * Get the request method.
414
+ *
415
+ * @example
416
+ * ```ts
417
+ * const method = stream.method;
418
+ * ```
419
+ * @docs
420
+ */
421
+ get method() {
422
+ return this._method;
423
+ }
424
+ // Get the endpoint.
425
+ /**
426
+ * Get the request's endpoint. This will not include the query string.
427
+ *
428
+ * @example
429
+ * ```ts
430
+ * const endpoint = stream.endpoint;
431
+ * ```
432
+ * @docs
433
+ */
434
+ get endpoint() {
435
+ if (this._endpoint !== void 0) {
436
+ return this._endpoint;
437
+ }
438
+ this._parse_endoint();
439
+ return this._endpoint;
440
+ }
441
+ // Get the params.
442
+ /**
443
+ * Get the request's query or body params.
444
+ *
445
+ * @example
446
+ * ```ts
447
+ * const params = stream.params;
448
+ * ```
449
+ * @docs
450
+ */
451
+ get params() {
452
+ if (this._params !== void 0) {
453
+ return this._params;
454
+ }
455
+ this._parse_params();
456
+ return this._params;
457
+ }
458
+ /** Add a param (used by the server backend for path parameters). */
459
+ add_param(name, value) {
460
+ if (!this._params) {
461
+ this._params = {};
462
+ }
463
+ this._params[name] = value;
464
+ }
465
+ // Get a param by name and optionally by type.
466
+ /**
467
+ * Get a single query or body parameter with an optional type cast.
468
+ *
469
+ * @warning Throws an error when the parameter does not exist or when the type is different from the specified type(s), unless parameter `def` is defined.
470
+ *
471
+ * @param name The name of the parameter.
472
+ * @param type The type cast of the parameters, valid types are `[null, "boolean", "number", "string", "array", "object"]`.
473
+ * @param def
474
+ * The default value to return when the parameter does not exist.
475
+ *
476
+ * If the parameter is not defined and `def` is `undefined` then this function will throw an error.
477
+ * When `def` is `undefined` errors will be thrown, when `def` is `null` and the parameter is undefined then `null` will be returned as the default value.
478
+ *
479
+ * Errors will always be thrown when the incorrect type has been sent by the user.
480
+ * @example
481
+ * ```ts
482
+ * const param = stream.param("myparameter", "number", 10);
483
+ * ```
484
+ * @docs
485
+ */
486
+ param(name, type = null, def = void 0) {
487
+ this._parse_params();
488
+ let value = this._params[name];
489
+ if (type != null) {
490
+ let is_type_array = Array.isArray(type);
491
+ const type_str = () => {
492
+ let str = "";
493
+ if (type != null) {
494
+ str += " type ";
495
+ if (is_type_array) {
496
+ let i = 0, one_but_last_i = type.length - 2;
497
+ type.forEach((item, i2) => {
498
+ str += `"${item}"`;
499
+ if (i2 < one_but_last_i) {
500
+ str += ", ";
501
+ } else if (i2 === one_but_last_i) {
502
+ str += " or ";
503
+ }
504
+ });
505
+ } else {
506
+ str += `"${type}"`;
507
+ }
508
+ }
509
+ return str;
510
+ };
511
+ const type_eq_or_includes = (match) => {
512
+ if (is_type_array) {
513
+ return type.includes(match);
514
+ }
515
+ return match === type;
516
+ };
517
+ if (value == null || value === "") {
518
+ if (def !== void 0) {
519
+ return def;
520
+ }
521
+ throw Error(`Define parameter "${name}"${type_str()}.`);
522
+ }
523
+ if (this._is_query_params && type_eq_or_includes("string") === false) {
524
+ if (is_type_array === false) {
525
+ type = [type];
526
+ }
527
+ const success = type.some((type2) => {
528
+ if (type2 === "string") {
529
+ return true;
530
+ }
531
+ if (type2 === "null" && value === "null") {
532
+ value = null;
533
+ return true;
534
+ }
535
+ const is_boolean = type2 === "boolean";
536
+ if (is_boolean && value === "true") {
537
+ value = true;
538
+ return true;
539
+ }
540
+ if (is_boolean && value === "false") {
541
+ value = false;
542
+ return true;
543
+ }
544
+ if (type2 === "array") {
545
+ value = value.split(",");
546
+ return true;
547
+ }
548
+ if (type2 === "object") {
549
+ const split = value.split(",");
550
+ value = {};
551
+ split.forEach((item) => {
552
+ const pair = item.split(":");
553
+ value[pair[0]] = pair[1];
554
+ });
555
+ return true;
556
+ }
557
+ if (type2 === "number" && /^-?\d+(\.\d+)?$/.test(value)) {
558
+ value = parseFloat(value);
559
+ return true;
560
+ }
561
+ });
562
+ if (!success) {
563
+ throw Error(`Parameter "${name}" should be of${type_str()}.`);
564
+ }
565
+ } else if (!this._is_query_params) {
566
+ const value_type = typeof value;
567
+ if (!is_type_array) {
568
+ type = [type];
569
+ }
570
+ const success = type.some((type2) => {
571
+ const l_is_array = type2 === "array";
572
+ const l_is_null = type2 === "null";
573
+ if (!l_is_array && !l_is_null && type2 === value_type) {
574
+ return true;
575
+ }
576
+ if (l_is_null && value == null) {
577
+ return true;
578
+ }
579
+ if (l_is_array && Array.isArray(value)) {
580
+ return true;
581
+ }
582
+ });
583
+ if (!success) {
584
+ throw Error(`Parameter "${name}" should be of${type_str()}.`);
585
+ }
586
+ }
587
+ } else if (value == null || value === "") {
588
+ if (def !== void 0) {
589
+ return def;
590
+ }
591
+ throw Error(`Define parameter "${name}".`);
592
+ }
593
+ return value;
594
+ }
595
+ // Get the request cookies.
596
+ /**
597
+ * Get the request's cookies
598
+ *
599
+ * @example
600
+ * ```ts
601
+ * const cookies = stream.cookies;
602
+ * ```
603
+ * @docs
604
+ */
605
+ get cookies() {
606
+ if (this._cookies != null)
607
+ return this._cookies;
608
+ return this._parse_cookies();
609
+ }
610
+ // DEPRECATED since its only available for http2.
611
+ // /**
612
+ // * Check if the stream is closed.
613
+ // *
614
+ // * @example
615
+ // * ```ts
616
+ // * const ip = stream.closed;
617
+ // * ```
618
+ // * @docs
619
+ // */
620
+ // get closed(): boolean {
621
+ // if (!this.http2) { throw new Error("This function is only supported for http2 streams."); }
622
+ // return this.s!.closed;
623
+ // }
624
+ // Check if the stream is destroyed
625
+ /**
626
+ * Check if the stream is destroyed.
627
+ *
628
+ * @example
629
+ * ```ts
630
+ * const ip = stream.destroyed;
631
+ * ```
632
+ * @docs
633
+ */
634
+ get destroyed() {
635
+ if (this.http2) {
636
+ return this.s.destroyed;
637
+ } else {
638
+ return this.req.destroyed;
639
+ }
640
+ }
641
+ // ---------------------------------------------------------
642
+ // Functions.
643
+ // Get the authenticated uid.
644
+ /**
645
+ * Get the authenticated uid; `undefined` when the request was not authenticated.
646
+ *
647
+ * @example
648
+ * ```ts
649
+ * const uid = stream.uid;
650
+ * ```
651
+ * @docs
652
+ */
653
+ get uid() {
654
+ return this._uid;
655
+ }
656
+ set uid(value) {
657
+ this._uid = value;
658
+ }
659
+ /**
660
+ * Apply templates to an in-memory body.
661
+ * Only applies to string bodies to avoid corrupting binary payloads.
662
+ */
663
+ apply_templates_to_body(input, templates) {
664
+ if (templates == null || Object.keys(templates).length === 0) {
665
+ return input;
666
+ }
667
+ if (typeof input !== "string") {
668
+ return input;
669
+ }
670
+ let out = input;
671
+ for (const key of Object.keys(templates)) {
672
+ const value = templates[key];
673
+ const value_str = typeof value === "string" ? value : JSON.stringify(value);
674
+ out = out.split(`{{${key}}}`).join(value_str);
675
+ }
676
+ return out;
677
+ }
678
+ /**
679
+ * Create a transform stream that applies templates across chunk boundaries.
680
+ * This avoids missing replacements when a template key is split between chunks.
681
+ */
682
+ create_template_replace_transform(templates) {
683
+ const keys = Object.keys(templates);
684
+ const max_key_len = keys.reduce((max, k) => Math.max(max, k.length), 0);
685
+ const keep_len = Math.max(0, max_key_len - 1);
686
+ let carry = "";
687
+ return new import_node_stream.Transform({
688
+ transform(chunk, _enc, cb) {
689
+ try {
690
+ const str = carry + chunk.toString("utf8");
691
+ const cut_idx = Math.max(0, str.length - keep_len);
692
+ const safe_head = str.slice(0, cut_idx);
693
+ carry = str.slice(cut_idx);
694
+ let out = safe_head;
695
+ for (const key of keys) {
696
+ const value = templates[key];
697
+ const value_str = typeof value === "string" ? value : JSON.stringify(value);
698
+ out = out.split(`{{${key}}}`).join(value_str);
699
+ }
700
+ cb(null, out);
701
+ } catch (err) {
702
+ cb(err);
703
+ }
704
+ },
705
+ flush(cb) {
706
+ try {
707
+ let out = carry;
708
+ for (const key of keys) {
709
+ const value = templates[key];
710
+ const value_str = typeof value === "string" ? value : JSON.stringify(value);
711
+ out = out.split(`{{${key}}}`).join(value_str);
712
+ }
713
+ cb(null, out);
714
+ } catch (err) {
715
+ cb(err);
716
+ }
717
+ }
718
+ });
719
+ }
720
+ /** Create output headers for http2. */
721
+ create_http2_headers(status, new_headers) {
722
+ const normalize_header_value = (v) => {
723
+ if (v == null)
724
+ return void 0;
725
+ if (typeof v === "boolean")
726
+ return v ? "true" : "false";
727
+ if (typeof v === "number")
728
+ return v;
729
+ if (typeof v === "string")
730
+ return v;
731
+ return String(v);
732
+ };
733
+ const out_headers = {
734
+ ":status": status
735
+ };
736
+ if (!Array.isArray(this.res_headers)) {
737
+ for (const [k, v] of Object.entries(this.res_headers)) {
738
+ const nv = normalize_header_value(v);
739
+ if (nv !== void 0)
740
+ out_headers[k.toLowerCase()] = nv;
741
+ }
742
+ }
743
+ for (const [k, v] of Object.entries(new_headers)) {
744
+ const nv = normalize_header_value(v);
745
+ if (nv !== void 0)
746
+ out_headers[k.toLowerCase()] = nv;
747
+ }
748
+ if (this.res_cookies.length > 0) {
749
+ out_headers["set-cookie"] = this.res_cookies;
750
+ }
751
+ return out_headers;
752
+ }
753
+ /** Assign http headers to response. */
754
+ set_http1_headers(status, headers) {
755
+ if (!this.res) {
756
+ throw new Error("HTTP/1.1 response is missing.");
757
+ }
758
+ this.res.statusCode = status;
759
+ for (let i = 0; i < this.res_headers.length; i++) {
760
+ this.res.setHeader(this.res_headers[i][0].toLowerCase(), this.res_headers[i][1]);
761
+ }
762
+ Object.keys(headers).forEach((key) => {
763
+ const v = headers[key];
764
+ if (v != null) {
765
+ this.res?.setHeader(key.toLowerCase(), typeof v === "boolean" ? v.toString() : v);
766
+ }
767
+ });
768
+ }
769
+ /**
770
+ * Send a response.
771
+ * @example
772
+ * ```ts
773
+ * stream.send({status: 200, data: "Hello World!"});
774
+ * ```
775
+ * @docs
776
+ */
777
+ send({ status = 200, headers = {}, data, compress = false, from_file, templates }) {
778
+ this.status_code = status;
779
+ let body = data;
780
+ if (typeof body === "boolean" || typeof body === "number") {
781
+ body = body.toString();
782
+ }
783
+ const get_accept_encoding = () => {
784
+ const accept_encoding = this.headers?.["accept-encoding"];
785
+ if (typeof accept_encoding === "string") {
786
+ return accept_encoding;
787
+ }
788
+ if (Array.isArray(accept_encoding) && accept_encoding.length > 0) {
789
+ return accept_encoding.join(", ");
790
+ }
791
+ const req_accept_encoding = this.req?.headers?.["accept-encoding"];
792
+ if (typeof req_accept_encoding === "string") {
793
+ return req_accept_encoding;
794
+ }
795
+ if (Array.isArray(req_accept_encoding) && req_accept_encoding.length > 0) {
796
+ return req_accept_encoding.join(", ");
797
+ }
798
+ return "";
799
+ };
800
+ body = this.apply_templates_to_body(body, templates);
801
+ if (this.http2) {
802
+ const stream = this.s;
803
+ const out_headers = this.create_http2_headers(status, headers);
804
+ if (from_file) {
805
+ const from_path = from_file instanceof vlib.Path ? from_file : new vlib.Path(from_file);
806
+ const needs_template_replace = templates != null && Object.keys(templates).length > 0;
807
+ const should_gzip = compress && get_accept_encoding().includes("gzip") && !(import_utils.Utils.is_compressed_extension(from_path.extension()) ?? false);
808
+ const content_type = import_utils.Utils.mime_type(from_path.extension());
809
+ if (content_type && out_headers["content-type"] == null) {
810
+ out_headers["content-type"] = content_type;
811
+ }
812
+ const is_text_response = typeof content_type === "string" && (content_type.startsWith("text/") || content_type === "application/javascript" || content_type === "application/json" || content_type === "image/svg+xml" || content_type === "application/xml" || content_type === "text/xml");
813
+ const should_apply_templates = needs_template_replace && is_text_response;
814
+ if (should_gzip) {
815
+ out_headers["content-encoding"] = "gzip";
816
+ out_headers["vary"] = "Accept-Encoding";
817
+ delete out_headers["content-length"];
818
+ }
819
+ if (should_apply_templates) {
820
+ delete out_headers["content-length"];
821
+ }
822
+ if (!should_gzip && !should_apply_templates && typeof stream.respondWithFile === "function") {
823
+ stream.respondWithFile(from_path.toString(), out_headers, {});
824
+ if (debug.on(3))
825
+ debug("Sending http2 file response: ", status, " - file: ", from_path.toString());
826
+ this.finished = true;
827
+ return this;
828
+ }
829
+ stream.respond(out_headers);
830
+ const file_read_stream = fs.createReadStream(from_path.toString());
831
+ const transforms = [];
832
+ if (should_apply_templates) {
833
+ transforms.push(this.create_template_replace_transform(templates));
834
+ }
835
+ if (should_gzip) {
836
+ transforms.push(zlib.createGzip({ level: zlib.constants.Z_BEST_COMPRESSION }));
837
+ }
838
+ (0, import_node_stream2.pipeline)(file_read_stream, ...transforms, stream, (err) => {
839
+ if (err) {
840
+ try {
841
+ stream.close();
842
+ } catch {
843
+ }
844
+ }
845
+ });
846
+ if (debug.on(3))
847
+ debug("Sending http2 streamed file response: ", status, " - file: ", from_path.toString());
848
+ this.finished = true;
849
+ return this;
850
+ } else {
851
+ if (body && typeof body === "object" && Buffer.isBuffer(body) === false && body instanceof Uint8Array === false) {
852
+ out_headers["content-type"] = "application/json";
853
+ body = JSON.stringify(body);
854
+ body = this.apply_templates_to_body(body, templates);
855
+ }
856
+ if (body && typeof body === "object" && !(body instanceof Buffer) && !(body instanceof Uint8Array)) {
857
+ body = JSON.stringify(body);
858
+ body = this.apply_templates_to_body(body, templates);
859
+ }
860
+ const should_gzip_body = compress && !!body && get_accept_encoding().includes("gzip");
861
+ if (should_gzip_body) {
862
+ out_headers["content-encoding"] = "gzip";
863
+ out_headers["vary"] = "Accept-Encoding";
864
+ delete out_headers["content-length"];
865
+ }
866
+ stream.respond(out_headers);
867
+ if (debug.on(3))
868
+ debug("Sending response: ", status, " - has body: ", !!body);
869
+ if (!body) {
870
+ stream.end();
871
+ this.finished = true;
872
+ return this;
873
+ } else if (should_gzip_body) {
874
+ const raw_buffer = typeof body === "string" ? Buffer.from(body) : Buffer.isBuffer(body) || body instanceof Uint8Array ? Buffer.from(body) : Buffer.from(JSON.stringify(body));
875
+ zlib.gzip(raw_buffer, { level: zlib.constants.Z_BEST_COMPRESSION }, (err, gz_buffer) => {
876
+ if (err) {
877
+ stream.end(raw_buffer);
878
+ return;
879
+ }
880
+ stream.end(gz_buffer);
881
+ });
882
+ this.finished = true;
883
+ return this;
884
+ } else {
885
+ if (Buffer.isBuffer(body) || body instanceof Uint8Array) {
886
+ stream.end(body);
887
+ } else {
888
+ stream.end(Buffer.from(body));
889
+ }
890
+ this.finished = true;
891
+ return this;
892
+ }
893
+ }
894
+ } else {
895
+ const req = this.req;
896
+ const res = this.res;
897
+ this.set_http1_headers(status, headers);
898
+ if (from_file) {
899
+ const from_path = from_file instanceof vlib.Path ? from_file : new vlib.Path(from_file);
900
+ const content_type = import_utils.Utils.mime_type(from_path.extension());
901
+ if (content_type) {
902
+ res.setHeader("Content-Type", content_type);
903
+ }
904
+ const needs_template_replace = templates != null && Object.keys(templates).length > 0;
905
+ const is_text_response = typeof content_type === "string" && (content_type.startsWith("text/") || content_type === "application/javascript" || content_type === "application/json" || content_type === "image/svg+xml" || content_type === "application/xml" || content_type === "text/xml");
906
+ const should_apply_templates = needs_template_replace && is_text_response;
907
+ const should_gzip = compress && get_accept_encoding().includes("gzip") && !(import_utils.Utils.is_compressed_extension(from_path.extension()) ?? false);
908
+ if (should_gzip) {
909
+ res.setHeader("Content-Encoding", "gzip");
910
+ res.setHeader("Vary", "Accept-Encoding");
911
+ res.removeHeader("Content-Length");
912
+ } else if (!should_apply_templates) {
913
+ try {
914
+ if (from_path.is_file()) {
915
+ res.setHeader("Content-Length", from_path.size);
916
+ }
917
+ } catch {
918
+ }
919
+ }
920
+ if (should_apply_templates) {
921
+ res.removeHeader("Content-Length");
922
+ }
923
+ const file_read_stream = fs.createReadStream(from_path.toString());
924
+ const transforms = [];
925
+ if (should_apply_templates) {
926
+ transforms.push(this.create_template_replace_transform(templates));
927
+ }
928
+ if (should_gzip) {
929
+ transforms.push(zlib.createGzip({ level: zlib.constants.Z_BEST_COMPRESSION }));
930
+ }
931
+ (0, import_node_stream2.pipeline)(file_read_stream, ...transforms, res, (err) => {
932
+ if (err) {
933
+ try {
934
+ res.destroy(err);
935
+ } catch {
936
+ }
937
+ }
938
+ });
939
+ if (debug.on(3))
940
+ debug("Sending http1 streamed file response: ", status, " - file: ", from_path.toString());
941
+ this.finished = true;
942
+ return this;
943
+ } else {
944
+ if (body && typeof body === "object" && Buffer.isBuffer(body) === false && body instanceof Uint8Array === false) {
945
+ res.setHeader("Content-Type", "application/json");
946
+ body = JSON.stringify(body);
947
+ body = this.apply_templates_to_body(body, templates);
948
+ }
949
+ const should_gzip_body = compress && !!body && get_accept_encoding().includes("gzip");
950
+ if (should_gzip_body) {
951
+ res.setHeader("Content-Encoding", "gzip");
952
+ res.setHeader("Vary", "Accept-Encoding");
953
+ res.removeHeader("Content-Length");
954
+ const raw_buffer = typeof body === "string" ? Buffer.from(body) : Buffer.isBuffer(body) || body instanceof Uint8Array ? Buffer.from(body) : Buffer.from(JSON.stringify(body));
955
+ zlib.gzip(raw_buffer, { level: zlib.constants.Z_BEST_COMPRESSION }, (err, gz_buffer) => {
956
+ if (err) {
957
+ res.end(raw_buffer);
958
+ return;
959
+ }
960
+ res.end(gz_buffer);
961
+ });
962
+ if (debug.on(3))
963
+ debug("Sending http1 response: ", status, " - has body: ", !!body, " - gzip: true");
964
+ } else if (body) {
965
+ res.end(body);
966
+ } else {
967
+ res.end();
968
+ }
969
+ this.finished = true;
970
+ return this;
971
+ }
972
+ }
973
+ }
974
+ // Send a successs response.
975
+ /**
976
+ * Send a response
977
+ *
978
+ * @param options The response options.
979
+ * @param options.status The response status.
980
+ * @param options.headers The response headers.
981
+ * @param options.data The data of the response body to send.
982
+ * @param options.compress Whether the response should be gzip-compressed.
983
+ * @example
984
+ * ```ts
985
+ * stream.success({data: "Hello World!"});
986
+ * ```
987
+ * @docs
988
+ */
989
+ success({ status = 200, headers = {}, data, from_file, compress = false } = {}) {
990
+ if (debug.on(3))
991
+ debug("Sending [success] response: ", status, " - body: ", data);
992
+ return this.send({ status, headers, data, compress, from_file });
993
+ }
994
+ // Send an error response.
995
+ /**
996
+ * Send an error response
997
+ *
998
+ * @param options The error response options.
999
+ * @param options.message The error message.
1000
+ * @param options.type The error type.
1001
+ * @param options.invalid_fields The invalid fields when validation fails.
1002
+ * @param options.status The response status.
1003
+ * @param options.headers The response headers.
1004
+ * @param options.compress Whether the response should be gzip-compressed.
1005
+ * @param options.data Optional data to include in the error response, nested in the JSON response under field `data`.
1006
+ * @example
1007
+ * ```ts
1008
+ * stream.error({ message: "Some error occurred", status: 400 });
1009
+ * ```
1010
+ * @docs
1011
+ */
1012
+ error({ message, type = "APIError", invalid_fields = {}, status = 500, headers = {}, compress = false, data }) {
1013
+ if (debug.on(3))
1014
+ debug("Sending [error] response: ", status, " - message: ", message);
1015
+ const api_error = {
1016
+ error: {
1017
+ type,
1018
+ message,
1019
+ status,
1020
+ invalid_fields
1021
+ },
1022
+ data
1023
+ };
1024
+ return this.send({ status, headers, compress, data: api_error });
1025
+ }
1026
+ /**
1027
+ * Stream a response through a transform pipeline with an optional gzip step and a hard byte limit.
1028
+ *
1029
+ * @param options Pipeline options.
1030
+ * @param options.status The HTTP status code to send.
1031
+ * @param options.headers The response headers to send.
1032
+ * @param options.body The readable stream to pipe into the response.
1033
+ * @param options.transforms Optional transform streams applied in order.
1034
+ * @param options.compress When true, gzip-compresses the streamed response if the client supports it.
1035
+ * @param options.max_bytes The maximum number of bytes allowed to be written to the client.
1036
+ * Set to `-1` for unlimited (use with caution).
1037
+ */
1038
+ pipeline({ status = 200, headers = {}, body, transforms = [], compress = false, max_bytes = 10 * 1024 * 1024 }) {
1039
+ if (this.finished) {
1040
+ throw new Error("Cannot pipeline a response that has already been finished.");
1041
+ }
1042
+ if (!Number.isInteger(status) || status < 100 || status > 599) {
1043
+ throw new Error("Invalid status code.");
1044
+ }
1045
+ if (!Number.isFinite(max_bytes)) {
1046
+ throw new Error("Invalid max_bytes value.");
1047
+ }
1048
+ if (!Array.isArray(transforms) || transforms.length > 32) {
1049
+ throw new Error("Invalid transforms configuration.");
1050
+ }
1051
+ this.status_code = status;
1052
+ this.finished = true;
1053
+ const all_streams = [body, ...transforms];
1054
+ const accept_encoding_header = this.headers?.["accept-encoding"];
1055
+ const accept_encoding = typeof accept_encoding_header === "string" ? accept_encoding_header : Array.isArray(accept_encoding_header) ? accept_encoding_header.join(", ") : "";
1056
+ const has_content_encoding = (() => {
1057
+ for (const k of Object.keys(headers ?? {})) {
1058
+ if (k.toLowerCase() === "content-encoding")
1059
+ return true;
1060
+ }
1061
+ const existing = this.get_header("content-encoding");
1062
+ return existing != null;
1063
+ })();
1064
+ const should_gzip = compress === true && accept_encoding.includes("gzip") && !has_content_encoding;
1065
+ if (should_gzip) {
1066
+ all_streams.push(zlib.createGzip({ level: zlib.constants.Z_BEST_COMPRESSION }));
1067
+ }
1068
+ if (max_bytes >= 0) {
1069
+ let written = 0;
1070
+ const limiter = new import_node_stream.Transform({
1071
+ transform(chunk, _enc, cb) {
1072
+ written += chunk.length;
1073
+ if (written > max_bytes) {
1074
+ cb(new Error("Response exceeded max_bytes."));
1075
+ return;
1076
+ }
1077
+ cb(null, chunk);
1078
+ }
1079
+ });
1080
+ all_streams.push(limiter);
1081
+ }
1082
+ const cleanup = (err) => {
1083
+ for (const s of all_streams) {
1084
+ if ("destroy" in s && typeof s.destroy === "function") {
1085
+ s.destroy(err);
1086
+ }
1087
+ }
1088
+ };
1089
+ if (this.http2) {
1090
+ const h2 = this.s;
1091
+ if (!h2) {
1092
+ throw new Error("HTTP/2 stream is missing.");
1093
+ }
1094
+ const out_headers = this.create_http2_headers(status, headers);
1095
+ if (should_gzip) {
1096
+ out_headers["content-encoding"] = "gzip";
1097
+ out_headers["vary"] = "Accept-Encoding";
1098
+ }
1099
+ delete out_headers["content-length"];
1100
+ h2.respond(out_headers);
1101
+ h2.once("close", () => {
1102
+ cleanup(new Error("Client disconnected."));
1103
+ });
1104
+ (0, import_node_stream2.pipeline)(...all_streams, h2, (err) => {
1105
+ if (err) {
1106
+ cleanup(err instanceof Error ? err : new Error("Pipeline failed."));
1107
+ try {
1108
+ h2.close();
1109
+ } catch {
1110
+ }
1111
+ }
1112
+ });
1113
+ return this;
1114
+ } else {
1115
+ const res = this.res;
1116
+ if (!res) {
1117
+ throw new Error("HTTP/1.1 response is missing.");
1118
+ }
1119
+ this.set_http1_headers(status, headers);
1120
+ if (should_gzip) {
1121
+ res.setHeader("Content-Encoding", "gzip");
1122
+ res.setHeader("Vary", "Accept-Encoding");
1123
+ }
1124
+ res.removeHeader("Content-Length");
1125
+ res.once("close", () => {
1126
+ cleanup(new Error("Client disconnected."));
1127
+ });
1128
+ (0, import_node_stream2.pipeline)(...all_streams, res, (err) => {
1129
+ if (err) {
1130
+ cleanup(err instanceof Error ? err : new Error("Pipeline failed."));
1131
+ try {
1132
+ res.destroy();
1133
+ } catch {
1134
+ }
1135
+ }
1136
+ });
1137
+ }
1138
+ return this;
1139
+ }
1140
+ // Set headers.
1141
+ /**
1142
+ * Add a new header to the response data.
1143
+ *
1144
+ * @param name The header name.
1145
+ * @param value The header value.
1146
+ * @example
1147
+ * ```ts
1148
+ * stream.set_header("Connection", "close");
1149
+ * ```
1150
+ * @docs
1151
+ */
1152
+ set_header(name, value) {
1153
+ name = name.toLowerCase();
1154
+ if (this.http2) {
1155
+ this.res_headers[name] = value;
1156
+ } else {
1157
+ this.res_headers.append([name, value]);
1158
+ }
1159
+ return this;
1160
+ }
1161
+ // Set headers.
1162
+ /**
1163
+ * Add new headers to the response data.
1164
+ *
1165
+ * @param headers The new response headers.
1166
+ * @example
1167
+ * ```ts
1168
+ * stream.set_headers({"Connection": "close"});
1169
+ * ```
1170
+ * @docs
1171
+ */
1172
+ set_headers(headers = {}) {
1173
+ if (headers == null) {
1174
+ return this;
1175
+ }
1176
+ if (this.http2) {
1177
+ Object.keys(headers).forEach((key) => {
1178
+ this.res_headers[key.toLowerCase()] = headers[key];
1179
+ });
1180
+ } else {
1181
+ Object.keys(headers).forEach((key) => {
1182
+ this.res_headers.append([key.toLowerCase(), headers[key]]);
1183
+ });
1184
+ }
1185
+ return this;
1186
+ }
1187
+ /**
1188
+ * Get an added response header.
1189
+ *
1190
+ * @param name The header name.
1191
+ * @example
1192
+ * ```ts
1193
+ * stream.get_header("Connection");
1194
+ * ```
1195
+ * @docs
1196
+ */
1197
+ get_header(name) {
1198
+ name = name.toLowerCase();
1199
+ if (this.http2) {
1200
+ return this.res_headers[name];
1201
+ } else {
1202
+ return this.res_headers.find((h) => h[0] === name)?.[1];
1203
+ }
1204
+ }
1205
+ /**
1206
+ * Remove header names from the response data.
1207
+ *
1208
+ * @param names The header names to remove.
1209
+ * @example
1210
+ * ```ts
1211
+ * stream.remove_header("Connection", "User-Agent");
1212
+ * ```
1213
+ * @docs
1214
+ */
1215
+ remove_header(...names) {
1216
+ names = names.map((n) => n.toLowerCase());
1217
+ if (this.http1) {
1218
+ const headers = [];
1219
+ for (let i = 0; i < this.res_headers.length; i++) {
1220
+ if (!names.includes(this.res_headers[i][0])) {
1221
+ headers.push(this.res_headers[i]);
1222
+ }
1223
+ }
1224
+ this.res_headers = headers;
1225
+ } else {
1226
+ for (let i = 0; i < names.length; i++) {
1227
+ delete this.res_headers[names[i]];
1228
+ }
1229
+ }
1230
+ return this;
1231
+ }
1232
+ /**
1233
+ * Alias of {@link remove_header}.
1234
+ *
1235
+ * @param names The header names to remove.
1236
+ */
1237
+ remove_headers(...names) {
1238
+ return this.remove_header(...names);
1239
+ }
1240
+ /**
1241
+ * Set a cookie to be sent with the response.
1242
+ *
1243
+ * Accepts either:
1244
+ * 1) a pre-built cookie header string (used as-is, no validation), or
1245
+ * 2) a structured object describing the cookie, from which a standards-compliant
1246
+ * cookie string will be generated.
1247
+ *
1248
+ * If a cookie with the same name already exists in the pending response list,
1249
+ * it will be replaced.
1250
+ *
1251
+ * @warning Cookies are only included in the response when using `send()`,
1252
+ * `success()` or `error()`.
1253
+ *
1254
+ * @example
1255
+ * ```ts
1256
+ * stream.set_cookie("sid=abc123; Path=/; SameSite=Lax; Secure; HttpOnly");
1257
+ *
1258
+ * stream.set_cookie({
1259
+ * name: "sid",
1260
+ * value: session_id,
1261
+ * http_only: true,
1262
+ * secure: true,
1263
+ * same_site: "Lax",
1264
+ * path: "/",
1265
+ * max_age: 60 * 60 * 24 * 14,
1266
+ * });
1267
+ * ```
1268
+ */
1269
+ set_cookie(cookie) {
1270
+ if (typeof cookie === "string") {
1271
+ const cookie_str2 = cookie.trim();
1272
+ const name_end2 = cookie_str2.indexOf("=");
1273
+ if (name_end2 !== -1) {
1274
+ const name2 = cookie_str2.substring(0, name_end2);
1275
+ for (let i = 0; i < this.res_cookies.length; i++) {
1276
+ if (this.res_cookies[i].startsWith(name2)) {
1277
+ this.res_cookies[i] = cookie_str2;
1278
+ return this;
1279
+ }
1280
+ }
1281
+ }
1282
+ this.res_cookies.push(cookie_str2);
1283
+ return this;
1284
+ }
1285
+ const { name, value, path = "/", domain, max_age, expires, secure, http_only, same_site, prefix, extra } = cookie;
1286
+ if (!name || typeof name !== "string") {
1287
+ throw new Error("set_cookie: cookie.name must be a non-empty string");
1288
+ }
1289
+ const full_name = `${prefix ?? ""}${name}`;
1290
+ if (prefix === "__Host-") {
1291
+ if (domain) {
1292
+ throw new Error("__Host- cookies must not include a domain attribute");
1293
+ }
1294
+ if (path !== "/") {
1295
+ throw new Error("__Host- cookies must have path='/'");
1296
+ }
1297
+ if (!secure) {
1298
+ throw new Error("__Host- cookies require secure=true");
1299
+ }
1300
+ }
1301
+ if (prefix === "__Secure-" && !secure) {
1302
+ throw new Error("__Secure- cookies require secure=true");
1303
+ }
1304
+ const encoded_value = value === null || typeof value === "undefined" ? "" : encodeURIComponent(String(value));
1305
+ const parts = [];
1306
+ parts.push(`${full_name}=${encoded_value}`);
1307
+ if (path)
1308
+ parts.push(`Path=${path}`);
1309
+ if (domain)
1310
+ parts.push(`Domain=${domain}`);
1311
+ if (typeof max_age === "number" && Number.isFinite(max_age)) {
1312
+ parts.push(`Max-Age=${Math.trunc(max_age)}`);
1313
+ }
1314
+ if (expires) {
1315
+ const exp = expires instanceof Date ? expires.toUTCString() : String(expires).trim();
1316
+ if (exp)
1317
+ parts.push(`Expires=${exp}`);
1318
+ }
1319
+ if (secure)
1320
+ parts.push("Secure");
1321
+ if (http_only)
1322
+ parts.push("HttpOnly");
1323
+ if (same_site)
1324
+ parts.push(`SameSite=${same_site}`);
1325
+ if (extra && Array.isArray(extra)) {
1326
+ for (const attr of extra) {
1327
+ const trimmed = String(attr).trim();
1328
+ if (trimmed)
1329
+ parts.push(trimmed);
1330
+ }
1331
+ }
1332
+ const cookie_str = parts.join("; ");
1333
+ const name_end = cookie_str.indexOf("=");
1334
+ if (name_end !== -1) {
1335
+ const existing_name = cookie_str.substring(0, name_end);
1336
+ for (let i = 0; i < this.res_cookies.length; i++) {
1337
+ if (this.res_cookies[i].startsWith(existing_name)) {
1338
+ this.res_cookies[i] = cookie_str;
1339
+ return this;
1340
+ }
1341
+ }
1342
+ }
1343
+ this.res_cookies.push(cookie_str);
1344
+ return this;
1345
+ }
1346
+ // Set cookies.
1347
+ /**
1348
+ * Set cookies that will be sent with the response.
1349
+ *
1350
+ * @warning Will only be added to the response when the user uses `send()`, `success()` or `error()`.
1351
+ * @param cookies The cookie strings.
1352
+ * @example
1353
+ * ```ts
1354
+ * stream.set_cookies("MyCookie1=Hello World;", "MyCookie2=Hello Universe;");
1355
+ * ```
1356
+ * @docs
1357
+ */
1358
+ set_cookies(...cookies) {
1359
+ for (let i = 0; i < cookies.length; i++) {
1360
+ this.set_cookie(cookies[i]);
1361
+ }
1362
+ return this;
1363
+ }
1364
+ }
1365
+ ;
1366
+ ;
1367
+ // Annotate the CommonJS export names for ESM import in node:
1368
+ 0 && (module.exports = {
1369
+ Stream
1370
+ });