@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,557 @@
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
+ cancel_user_subscription: () => cancel_user_subscription,
31
+ create_user_subscription: () => create_user_subscription,
32
+ delete_subscription_caches: () => delete_subscription_caches,
33
+ enforce_single_subscription_plan: () => enforce_single_subscription_plan,
34
+ is_user_subscribed_to: () => is_user_subscribed_to,
35
+ list_subscribed_meters: () => list_subscribed_meters,
36
+ list_subscribed_plans: () => list_subscribed_plans,
37
+ update_subscription_record: () => update_subscription_record
38
+ });
39
+ module.exports = __toCommonJS(stdin_exports);
40
+ var vlib = __toESM(require("@vandenberghinc/vlib"));
41
+ var import_error = require("./error.js");
42
+ var import_customers = require("./customers.js");
43
+ var import_utils = require("./utils.js");
44
+ var import_collection = require("../../database/collection.js");
45
+ const subscription_record_cache = new vlib.Cache({
46
+ max_size: 25e4,
47
+ ttl: {
48
+ sliding: true,
49
+ // Short lived cache, see docstring why
50
+ duration: 1e3 * 60 * 5
51
+ }
52
+ });
53
+ async function list_all_customer_subscriptions(client, server, uid, customer_id) {
54
+ (0, import_utils.assert)(uid.trim().length > 0, "invalid_argument", "Uid must be a non-empty string.", { uid });
55
+ const ensured_customer_id = customer_id ?? await (0, import_customers.ensure_stripe_customer)(client, server, uid);
56
+ const subscriptions = [];
57
+ let starting_after;
58
+ for (; ; ) {
59
+ const page = await (0, import_utils.stripe_api_call)(() => client.subscriptions.list({
60
+ customer: ensured_customer_id,
61
+ status: "all",
62
+ limit: 100,
63
+ starting_after,
64
+ // ALWAYS expand, since the callee's expect this.
65
+ expand: ["data.items.data.price"]
66
+ }), { operation: "subscriptions.list", customer_id: ensured_customer_id, starting_after });
67
+ subscriptions.push(...page.data);
68
+ if (!page.has_more || page.data.length === 0) {
69
+ break;
70
+ }
71
+ const last = page.data[page.data.length - 1];
72
+ (0, import_utils.assert)(last !== void 0, "api_error", "Stripe subscriptions pagination returned an empty last item.", {
73
+ customer_id: ensured_customer_id,
74
+ returned: page.data.length
75
+ });
76
+ starting_after = last.id;
77
+ }
78
+ return subscriptions;
79
+ }
80
+ function resolve_plan_parent_subscription(opts) {
81
+ for (const product of opts.all_products) {
82
+ if (product.type === "subscription" && product.id === opts.plan.subscription_id) {
83
+ return product;
84
+ }
85
+ }
86
+ throw new import_error.InternalStripeError("invalid_product", "Subscription plan refers to a missing parent subscription product.", { plan_id: opts.plan.id, subscription_id: opts.plan.subscription_id });
87
+ }
88
+ async function resolve_default_payment_method_id(client, opts) {
89
+ const customer = await (0, import_utils.stripe_api_call)(() => client.customers.retrieve(opts.stripe_customer_id, {
90
+ expand: ["invoice_settings.default_payment_method"]
91
+ }), { operation: "customers.retrieve", uid: opts.uid, stripe_customer_id: opts.stripe_customer_id });
92
+ (0, import_utils.public_assert)(customer.deleted !== true, "customer_not_found", "Stripe customer was not found.", { uid: opts.uid, stripe_customer_id: opts.stripe_customer_id });
93
+ const invoice_settings = customer.invoice_settings;
94
+ const default_payment_method = invoice_settings?.default_payment_method;
95
+ if (typeof default_payment_method === "string") {
96
+ return default_payment_method;
97
+ }
98
+ if (default_payment_method && typeof default_payment_method === "object") {
99
+ const id = default_payment_method.id;
100
+ if (typeof id === "string" && id.trim().length > 0) {
101
+ return id;
102
+ }
103
+ }
104
+ throw new import_error.ExternalStripeError("payment_method_missing", "No default payment method on file. Please add a payment method before subscribing.", { uid: opts.uid, stripe_customer_id: opts.stripe_customer_id });
105
+ }
106
+ function resolve_payment_intent_from_subscription(subscription) {
107
+ const latest_invoice = subscription.latest_invoice;
108
+ if (!latest_invoice || typeof latest_invoice === "string") {
109
+ return null;
110
+ }
111
+ const payment_intent = latest_invoice.payment_intent;
112
+ if (!payment_intent || typeof payment_intent === "string") {
113
+ return null;
114
+ }
115
+ return payment_intent;
116
+ }
117
+ function build_subscription_create_params_from_product(opts) {
118
+ const parent = opts.parent_subscription;
119
+ const subscription_params = {
120
+ // Safe metadata for reconciliation and security auditing.
121
+ metadata: {
122
+ __volt_uid: opts.uid,
123
+ __volt_subscription_id: parent.id
124
+ }
125
+ };
126
+ if (parent.trial_days !== void 0) {
127
+ subscription_params.trial_period_days = parent.trial_days;
128
+ }
129
+ const billing_anchor = parent.billing_anchor ?? "immediately";
130
+ if (billing_anchor === "immediately") {
131
+ return subscription_params;
132
+ }
133
+ if (billing_anchor === "first_of_month") {
134
+ const now = /* @__PURE__ */ new Date();
135
+ const trial_days = parent.trial_days;
136
+ const trial_end_reference = trial_days !== void 0 ? new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate() + trial_days, now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds(), now.getUTCMilliseconds())) : now;
137
+ const anchor_date = new Date(Date.UTC(trial_end_reference.getUTCFullYear(), trial_end_reference.getUTCMonth() + 1, 1, 0, 0, 0, 0));
138
+ subscription_params.billing_cycle_anchor = Math.floor(anchor_date.getTime() / 1e3);
139
+ subscription_params.proration_behavior = "none";
140
+ return subscription_params;
141
+ }
142
+ throw new import_error.InternalStripeError("invalid_product", "Unsupported billing_anchor value.", { billing_anchor, subscription_id: parent.id });
143
+ }
144
+ function create_subscriptions_db(server) {
145
+ return server.db.collection({
146
+ name: "Volt.Stripe.Subscriptions",
147
+ indexes: [
148
+ {
149
+ keys: { uid: 1 },
150
+ unique: true
151
+ }
152
+ ],
153
+ // Ensure its not unique so we retrieve the cached collection if already created.
154
+ unique: false
155
+ });
156
+ }
157
+ async function update_subscription_record(client, server, opts) {
158
+ const subscriptions = await list_all_customer_subscriptions(client, server, opts.uid, void 0);
159
+ const sub_price_id_to_plan_id = /* @__PURE__ */ new Map();
160
+ const meter_price_id_to_product_id = /* @__PURE__ */ new Map();
161
+ for (const product of opts.all_products) {
162
+ if (product.type === "subscription") {
163
+ for (const plan of product.plans) {
164
+ sub_price_id_to_plan_id.set(plan.stripe_price_id, plan.id);
165
+ }
166
+ } else if (product.type === "meter") {
167
+ meter_price_id_to_product_id.set(product.stripe_price_id, product.id);
168
+ } else if (product.type !== "one_time") {
169
+ product.toString();
170
+ }
171
+ }
172
+ const record = {
173
+ uid: opts.uid,
174
+ subscriptions: {},
175
+ meters: {}
176
+ };
177
+ for (const subscription of subscriptions) {
178
+ switch (subscription.status) {
179
+ // Store all semi-active statuses, they can later be filtered.
180
+ case "active":
181
+ case "trialing":
182
+ case "past_due": {
183
+ for (const item of subscription.items.data) {
184
+ const price = item.price;
185
+ if (!price) {
186
+ continue;
187
+ }
188
+ if (sub_price_id_to_plan_id.has(price.id)) {
189
+ const plan_id = sub_price_id_to_plan_id.get(price.id);
190
+ if (!plan_id) {
191
+ continue;
192
+ }
193
+ record.subscriptions[plan_id] = subscription.status;
194
+ }
195
+ if (meter_price_id_to_product_id.has(price.id)) {
196
+ const product_id = meter_price_id_to_product_id.get(price.id);
197
+ if (!product_id) {
198
+ continue;
199
+ }
200
+ record.meters[product_id] = subscription.status;
201
+ }
202
+ }
203
+ break;
204
+ }
205
+ default:
206
+ break;
207
+ }
208
+ }
209
+ const db = create_subscriptions_db(server);
210
+ await db.set({ uid: opts.uid }, record, {
211
+ // ensure we do not flatten the subscriptions object so we can remove old plans that are no longer active.
212
+ flatten: false,
213
+ upsert: true,
214
+ retry: 3
215
+ });
216
+ }
217
+ async function load_subscription_record(server, opts) {
218
+ const use_cache = opts.cache ?? true;
219
+ if (use_cache) {
220
+ const cached = subscription_record_cache.get(opts.uid);
221
+ if (cached != null) {
222
+ return cached;
223
+ }
224
+ }
225
+ const db = create_subscriptions_db(server);
226
+ const record = await db.load({ uid: opts.uid }, { throw: false });
227
+ if (record instanceof Error) {
228
+ if (record instanceof import_collection.Collection.NotFoundError) {
229
+ const empty_record = { uid: opts.uid, subscriptions: {}, meters: {} };
230
+ subscription_record_cache.set(opts.uid, empty_record);
231
+ return empty_record;
232
+ }
233
+ throw record;
234
+ }
235
+ subscription_record_cache.set(opts.uid, record);
236
+ return record;
237
+ }
238
+ function delete_subscription_caches(uid) {
239
+ subscription_record_cache.delete(uid);
240
+ }
241
+ async function list_subscribed_plans(client, server, opts) {
242
+ (0, import_utils.assert)(opts.uid.trim().length > 0, "invalid_argument", "Uid must be a non-empty string.", { uid: opts.uid });
243
+ const record = await load_subscription_record(server, { uid: opts.uid });
244
+ const active_statuses = new Set(opts.status ?? [
245
+ "active",
246
+ "trialing",
247
+ "past_due"
248
+ ]);
249
+ const active = {};
250
+ for (const [id, status] of Object.entries(record.subscriptions)) {
251
+ if (!active_statuses.has(status)) {
252
+ continue;
253
+ }
254
+ active[id] = status;
255
+ }
256
+ return active;
257
+ }
258
+ async function list_subscribed_meters(client, server, opts) {
259
+ const record = await load_subscription_record(server, { uid: opts.uid });
260
+ const active_statuses = new Set(opts.status ?? [
261
+ "active"
262
+ // We dont allow `trialing` and `past_due` to reduce risk of accidental/abusive access.
263
+ ]);
264
+ const active = {};
265
+ for (const [id, status] of Object.entries(record.meters)) {
266
+ if (!active_statuses.has(status)) {
267
+ continue;
268
+ }
269
+ active[id] = status;
270
+ }
271
+ return active;
272
+ }
273
+ async function is_user_subscribed_to(client, server, opts) {
274
+ (0, import_utils.assert)(opts.plan.id.trim().length > 0, "invalid_argument", "Plan.id must be a non-empty string.", { plan_id: opts.plan.id });
275
+ if (opts.plan.type === "meter") {
276
+ const subscribed_plans = await list_subscribed_meters(client, server, {
277
+ uid: opts.uid,
278
+ stripe_customer_id: opts.customer_id ?? await (0, import_customers.ensure_stripe_customer)(client, server, opts.uid),
279
+ all_products: opts.all_products,
280
+ status: opts.status
281
+ });
282
+ return Object.keys(subscribed_plans).includes(opts.plan.id);
283
+ } else {
284
+ const subscribed_plans = await list_subscribed_plans(client, server, {
285
+ uid: opts.uid,
286
+ customer_id: opts.customer_id,
287
+ all_products: opts.all_products,
288
+ status: opts.status
289
+ });
290
+ return Object.keys(subscribed_plans).includes(opts.plan.id);
291
+ }
292
+ return false;
293
+ }
294
+ async function create_user_subscription(client, server, opts) {
295
+ (0, import_utils.public_assert)((0, import_utils.is_non_empty_string)(opts.uid), "invalid_argument", "Property 'uid' must be a non-empty string.");
296
+ (0, import_utils.assert)(Array.isArray(opts.all_products), "invalid_argument", "Property 'all_products' must be an array.");
297
+ (0, import_utils.assert)(opts.target.id.trim().length > 0, "invalid_argument", "Target.id must be non-empty.", { target_id: opts.target.id });
298
+ delete_subscription_caches(opts.uid);
299
+ const stripe_customer_id = await (0, import_customers.ensure_stripe_customer)(client, server, opts.uid);
300
+ const default_payment_method_id = await resolve_default_payment_method_id(client, {
301
+ uid: opts.uid,
302
+ stripe_customer_id
303
+ });
304
+ const idempotency_key = (0, import_utils.stable_idempotency_key)(`sub_create:${opts.uid}:${opts.idempotency_key}`);
305
+ const base_params = {
306
+ customer: stripe_customer_id,
307
+ // We always charge automatically for subscriptions.
308
+ // Docs: https://docs.stripe.com/api/subscriptions/create#create_subscription-collection_method
309
+ collection_method: "charge_automatically",
310
+ // Use the default invoice payment method for off-session charges.
311
+ // Docs: https://docs.stripe.com/api/subscriptions/create#create_subscription-default_payment_method
312
+ default_payment_method: default_payment_method_id,
313
+ // Crucial: create an incomplete subscription when payment can't be completed immediately,
314
+ // so we can surface the PaymentIntent client_secret to the UI for SCA/3DS.
315
+ // Docs: https://docs.stripe.com/billing/subscriptions/overview#handling-incomplete-subscriptions
316
+ payment_behavior: "default_incomplete",
317
+ // Safe metadata only.
318
+ metadata: {
319
+ __volt_uid: opts.uid,
320
+ __volt_target_id: opts.target.id,
321
+ __volt_target_type: opts.target.type
322
+ }
323
+ };
324
+ if (opts.target.type === "subscription_plan") {
325
+ const parent_subscription = resolve_plan_parent_subscription({
326
+ plan: opts.target,
327
+ all_products: opts.all_products
328
+ });
329
+ const subscription_level_params = build_subscription_create_params_from_product({
330
+ uid: opts.uid,
331
+ parent_subscription
332
+ });
333
+ base_params.items = [{ price: opts.target.stripe_price_id, quantity: 1 }];
334
+ base_params.trial_period_days = subscription_level_params.trial_period_days;
335
+ base_params.billing_cycle_anchor = subscription_level_params.billing_cycle_anchor;
336
+ base_params.proration_behavior = subscription_level_params.proration_behavior;
337
+ base_params.metadata = {
338
+ ...base_params.metadata ?? {},
339
+ ...subscription_level_params.metadata ?? {},
340
+ __volt_subscription_id: parent_subscription.id,
341
+ __volt_plan_id: opts.target.id
342
+ };
343
+ } else if (opts.target.type === "meter") {
344
+ base_params.items = [{ price: opts.target.stripe_price_id, quantity: 1 }];
345
+ base_params.metadata = {
346
+ ...base_params.metadata ?? {},
347
+ __volt_meter_product_id: opts.target.id,
348
+ __volt_meter_event_name: opts.target.meter_event_name
349
+ };
350
+ } else {
351
+ opts.target.toString();
352
+ throw new import_error.InternalStripeError("invalid_argument", "Unsupported subscription target type.", { target_type: opts.target.type });
353
+ }
354
+ const subscription = await (0, import_utils.stripe_api_call)(() => client.subscriptions.create({
355
+ ...base_params,
356
+ // Expand payment intent so we can return client_secret for SCA, if required.
357
+ // Docs: https://docs.stripe.com/expand
358
+ expand: ["latest_invoice.payment_intent"]
359
+ }, { idempotencyKey: idempotency_key }), {
360
+ operation: "subscriptions.create",
361
+ uid: opts.uid,
362
+ stripe_customer_id,
363
+ target_id: opts.target.id,
364
+ target_type: opts.target.type
365
+ });
366
+ delete_subscription_caches(opts.uid);
367
+ const payment_intent = resolve_payment_intent_from_subscription(subscription);
368
+ if (payment_intent && payment_intent.status === "requires_action") {
369
+ const client_secret = payment_intent.client_secret;
370
+ (0, import_utils.public_assert)((0, import_utils.is_non_empty_string)(client_secret), "subscription_payment_action_required", "Additional payment verification is required, but Stripe did not return a client secret.", { subscription_id: subscription.id, payment_intent_id: payment_intent.id });
371
+ return {
372
+ type: "requires_action",
373
+ subscription_id: subscription.id,
374
+ stripe_customer_id,
375
+ payment_intent_id: payment_intent.id,
376
+ client_secret,
377
+ status: subscription.status
378
+ };
379
+ }
380
+ if (payment_intent && payment_intent.status === "requires_payment_method") {
381
+ throw new import_error.ExternalStripeError("payment_method_missing", "Your default payment method could not be charged. Please update your payment method and try again.", { subscription_id: subscription.id, payment_intent_id: payment_intent.id });
382
+ }
383
+ if (subscription.status === "incomplete" || subscription.status === "incomplete_expired") {
384
+ throw new import_error.InternalStripeError("subscription_create_error", "Subscription was created in an incomplete state without a resolvable PaymentIntent.", {
385
+ uid: opts.uid,
386
+ stripe_customer_id,
387
+ subscription_id: subscription.id,
388
+ status: subscription.status,
389
+ has_latest_invoice: subscription.latest_invoice != null,
390
+ has_payment_intent: payment_intent != null
391
+ });
392
+ }
393
+ return {
394
+ type: "created",
395
+ subscription_id: subscription.id,
396
+ stripe_customer_id,
397
+ status: subscription.status
398
+ };
399
+ }
400
+ async function cancel_user_subscription(client, server, opts) {
401
+ const uid = opts.uid;
402
+ (0, import_utils.assert)(uid.trim().length > 0, "invalid_argument", "Uid must be a non-empty string.", { uid });
403
+ (0, import_utils.assert)(opts.plan.id.trim().length > 0, "invalid_argument", "Plan.id must be non-empty.", { plan_id: opts.plan.id });
404
+ (0, import_utils.assert)(opts.plan.stripe_price_id.trim().length > 0, "invalid_argument", "Plan.stripe_price_id must be non-empty.", { plan_id: opts.plan.id });
405
+ const cancel_at_period_end = opts.cancel_at_period_end ?? true;
406
+ delete_subscription_caches(uid);
407
+ const subscriptions = await list_all_customer_subscriptions(client, server, uid, opts.customer_id);
408
+ const active_sub_status = /* @__PURE__ */ new Set([
409
+ "active",
410
+ "trialing",
411
+ "past_due"
412
+ // since Stripe can keep subscriptions in past_due while retrying payment.
413
+ ]);
414
+ const affected_subscriptions = [];
415
+ for (const subscription of subscriptions) {
416
+ if (!active_sub_status.has(subscription.status)) {
417
+ continue;
418
+ }
419
+ let matches_plan = false;
420
+ for (const item of subscription.items.data) {
421
+ const price = item.price;
422
+ if (!price) {
423
+ continue;
424
+ }
425
+ if (price.id === opts.plan.stripe_price_id) {
426
+ matches_plan = true;
427
+ break;
428
+ }
429
+ }
430
+ if (!matches_plan) {
431
+ continue;
432
+ }
433
+ affected_subscriptions.push(subscription);
434
+ }
435
+ if (affected_subscriptions.length === 0) {
436
+ delete_subscription_caches(uid);
437
+ return [];
438
+ }
439
+ await Promise.all(affected_subscriptions.map(async (subscription) => {
440
+ if (cancel_at_period_end) {
441
+ await (0, import_utils.stripe_api_call)(() => client.subscriptions.update(subscription.id, { cancel_at_period_end: true }, { idempotencyKey: (0, import_utils.stable_idempotency_key)(`sub_update_cancel_at_period_end:${subscription.id}`) }), {
442
+ operation: "subscriptions.update",
443
+ action: "cancel_at_period_end",
444
+ uid,
445
+ subscription_id: subscription.id,
446
+ plan_id: opts.plan.id,
447
+ stripe_price_id: opts.plan.stripe_price_id
448
+ });
449
+ } else {
450
+ await (0, import_utils.stripe_api_call)(() => client.subscriptions.cancel(subscription.id, void 0, { idempotencyKey: (0, import_utils.stable_idempotency_key)(`sub_cancel_immediate:${subscription.id}`) }), {
451
+ operation: "subscriptions.cancel",
452
+ action: "cancel_immediately",
453
+ uid,
454
+ subscription_id: subscription.id,
455
+ plan_id: opts.plan.id,
456
+ stripe_price_id: opts.plan.stripe_price_id
457
+ });
458
+ }
459
+ }));
460
+ delete_subscription_caches(uid);
461
+ return affected_subscriptions;
462
+ }
463
+ async function enforce_single_subscription_plan(client, server, opts) {
464
+ (0, import_utils.assert)(opts.uid.length > 0, "invalid_argument", "uid must be provided");
465
+ (0, import_utils.assert)(opts.stripe_customer_id.length > 0, "invalid_argument", "stripe_customer_id must be provided");
466
+ const { new_subscription, all_products } = opts;
467
+ const active_sub_status = /* @__PURE__ */ new Set([
468
+ "active",
469
+ "trialing",
470
+ "past_due"
471
+ ]);
472
+ if (!active_sub_status.has(new_subscription.status)) {
473
+ return [];
474
+ }
475
+ const price_to_subscription_product = /* @__PURE__ */ new Map();
476
+ for (const product of all_products) {
477
+ if (product.type !== "subscription")
478
+ continue;
479
+ for (const plan of product.plans) {
480
+ price_to_subscription_product.set(plan.stripe_price_id, product);
481
+ }
482
+ }
483
+ const resolved_products = /* @__PURE__ */ new Set();
484
+ for (const item of new_subscription.items.data) {
485
+ const price = item.price;
486
+ if (!price)
487
+ continue;
488
+ (0, import_utils.assert)(typeof price !== "string", "invalid_argument", "new_subscription.items.data.price must be expanded.", {
489
+ subscription_id: new_subscription.id
490
+ });
491
+ const sub_product = price_to_subscription_product.get(price.id);
492
+ if (sub_product) {
493
+ resolved_products.add(sub_product);
494
+ }
495
+ }
496
+ if (resolved_products.size === 0) {
497
+ return [];
498
+ }
499
+ if (resolved_products.size > 1) {
500
+ throw new import_error.InternalStripeError("subscription_resolution_error", "Subscription resolves to multiple subscription products.", {
501
+ subscription_id: new_subscription.id,
502
+ subscription_product_ids: [...resolved_products].map((p) => p.id)
503
+ });
504
+ }
505
+ const [subscription_product] = [...resolved_products];
506
+ const product_price_ids = new Set(subscription_product.plans.map((p) => p.stripe_price_id));
507
+ const all_subscriptions = await list_all_customer_subscriptions(client, server, opts.uid, opts.stripe_customer_id);
508
+ const canceled = [];
509
+ for (const sub of all_subscriptions) {
510
+ if (sub.id === new_subscription.id)
511
+ continue;
512
+ if (!active_sub_status.has(sub.status))
513
+ continue;
514
+ let overlaps = false;
515
+ for (const item of sub.items.data) {
516
+ const price = item.price;
517
+ if (!price)
518
+ continue;
519
+ (0, import_utils.assert)(typeof price !== "string", "api_error", "Expected expanded item.price from subscriptions.list expand.", {
520
+ subscription_id: sub.id
521
+ });
522
+ if (product_price_ids.has(price.id)) {
523
+ overlaps = true;
524
+ break;
525
+ }
526
+ }
527
+ if (!overlaps)
528
+ continue;
529
+ await (0, import_utils.stripe_api_call)(() => client.subscriptions.cancel(sub.id, void 0, {
530
+ idempotencyKey: opts.idempotency_key ?? (0, import_utils.stable_idempotency_key)(`enforce_single_plan:${opts.stripe_customer_id}:${new_subscription.id}:${sub.id}`)
531
+ }), {
532
+ operation: "subscriptions.cancel",
533
+ action: "enforce_single_plan",
534
+ uid: opts.uid,
535
+ stripe_customer_id: opts.stripe_customer_id,
536
+ kept_subscription_id: new_subscription.id,
537
+ canceled_subscription_id: sub.id,
538
+ subscription_product_id: subscription_product.id
539
+ });
540
+ canceled.push(sub);
541
+ }
542
+ if (canceled.length > 0) {
543
+ delete_subscription_caches(opts.uid);
544
+ }
545
+ return canceled;
546
+ }
547
+ // Annotate the CommonJS export names for ESM import in node:
548
+ 0 && (module.exports = {
549
+ cancel_user_subscription,
550
+ create_user_subscription,
551
+ delete_subscription_caches,
552
+ enforce_single_subscription_plan,
553
+ is_user_subscribed_to,
554
+ list_subscribed_meters,
555
+ list_subscribed_plans,
556
+ update_subscription_record
557
+ });
@@ -0,0 +1,63 @@
1
+ /**
2
+ * @author Daan van den Bergh
3
+ * @copyright © 2026 - 2026 Daan van den Bergh. All rights reserved
4
+ */
5
+ import { StripeErrorCode } from "./error.js";
6
+ /**
7
+ * Wrap a Stripe API call to consistently attach safe context and preserve cause.
8
+ */
9
+ export declare function stripe_api_call<T>(fn: () => Promise<T>, context: Record<string, unknown>): Promise<T>;
10
+ /**
11
+ * Ensure a condition is true, otherwise throw a typed InternalStripeError.
12
+ * Throwing internal errors not presented to the user.
13
+ */
14
+ export declare function assert(condition: unknown, error_code: StripeErrorCode, message: string, context?: Record<string, unknown>, cause?: unknown): asserts condition;
15
+ /**
16
+ * Ensure a condition is true, otherwise throw a typed ExternalStripeError.
17
+ * Throwing external errors presented to the user.
18
+ */
19
+ export declare function public_assert(condition: unknown, error_code: StripeErrorCode, message: string, context?: Record<string, unknown>, cause?: unknown): asserts condition;
20
+ /**
21
+ * Exhaustive check helper for discriminated unions.
22
+ * Throwing internal errors not presented to the user.
23
+ */
24
+ export declare function assert_never(value: never, message: string): never;
25
+ /**
26
+ * Exhaustive check helper for discriminated unions.
27
+ * Throwing external errors presented to the user.
28
+ */
29
+ export declare function public_assert_never(value: never, message: string): never;
30
+ /**
31
+ * Type-guard: checks whether a value is a non-empty string.
32
+ */
33
+ export declare function is_non_empty_string(value: unknown): value is string;
34
+ /**
35
+ * Generate a random Stripe idempotency key.
36
+ *
37
+ * Stripe suggests using a UUID v4 as idempotency keys are best treated as opaque unique tokens.
38
+ * Stripe docs: https://docs.stripe.com/api/idempotent_requests
39
+ *
40
+ * @param prefix A string prefix for observability and to avoid collisions with other idempotency domains in logs.
41
+ * This is still suffixed with a `_${randomUUID()}`.
42
+ */
43
+ export declare function generate_random_idempotency_key(prefix: string, max_length?: number): string;
44
+ /**
45
+ * Generate a stable idempotency key by hashing a seed string if it exceeds the max length.
46
+ * This is useful when you want idempotency based on a natural key that may be too long for Stripe's limits.
47
+ * The seed should be unique for each distinct operation you want to dedupe.
48
+ */
49
+ export declare function stable_idempotency_key(seed: string, max_length?: number): string;
50
+ /**
51
+ * Convert a Date into a unix timestamp (seconds).
52
+ */
53
+ export declare function to_unix_seconds(date: Date): number;
54
+ /**
55
+ * Compute the first day of the next month at 00:00:00 UTC.
56
+ *
57
+ * This is used for subscription billing anchors like "first_of_month".
58
+ */
59
+ export declare function first_day_of_next_month_utc(now: Date): Date;
60
+ /**
61
+ * Add N days to a date using UTC fields to avoid DST/local-time surprises.
62
+ */
63
+ export declare function add_days_utc(date: Date, days: number): Date;