@vandenberghinc/volt 1.1.26 → 1.1.28

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 (502) hide show
  1. package/backend/dist/cjs/{blacklist.d.ts → backend/src/blacklist.d.ts} +5 -3
  2. package/backend/dist/cjs/{blacklist.js → backend/src/blacklist.js} +8 -5
  3. package/backend/dist/cjs/{cli.js → backend/src/cli.js} +29 -47
  4. package/backend/dist/cjs/backend/src/database/collection.d.ts +1543 -0
  5. package/backend/dist/cjs/backend/src/database/collection.js +3042 -0
  6. package/backend/dist/cjs/backend/src/database/database.d.ts +66 -0
  7. package/backend/dist/cjs/{database → backend/src/database}/database.js +48 -43
  8. package/backend/dist/cjs/backend/src/database/filters/filters.d.ts +6 -0
  9. package/backend/dist/cjs/backend/src/database/filters/filters.js +15 -0
  10. package/backend/dist/cjs/backend/src/database/filters/strict_filter.d.ts +223 -0
  11. package/backend/dist/cjs/backend/src/database/filters/strict_filter.js +15 -0
  12. package/backend/dist/cjs/backend/src/database/filters/strict_filter_test.js +443 -0
  13. package/backend/dist/cjs/backend/src/database/filters/strict_filter_test_v0.js +15 -0
  14. package/backend/dist/cjs/backend/src/database/filters/strict_filter_v0.d.ts +50 -0
  15. package/backend/dist/cjs/backend/src/database/filters/strict_filter_v0.js +15 -0
  16. package/backend/dist/cjs/backend/src/database/filters/strict_filter_v1.d.ts +76 -0
  17. package/backend/dist/cjs/backend/src/database/filters/strict_filter_v1.js +15 -0
  18. package/backend/dist/cjs/backend/src/database/filters/strict_filter_v2.d.ts +75 -0
  19. package/backend/dist/cjs/backend/src/database/filters/strict_filter_v2.js +15 -0
  20. package/backend/dist/cjs/backend/src/database/filters/strict_filter_v3.d.ts +219 -0
  21. package/backend/dist/cjs/backend/src/database/filters/strict_filter_v3.js +15 -0
  22. package/backend/dist/cjs/backend/src/database/filters/strict_update_filter.d.ts +165 -0
  23. package/backend/dist/cjs/backend/src/database/filters/strict_update_filter.js +15 -0
  24. package/backend/dist/cjs/backend/src/database/filters/strict_update_filter_test.d.ts +5 -0
  25. package/backend/dist/cjs/backend/src/database/filters/strict_update_filter_test.js +355 -0
  26. package/backend/dist/cjs/backend/src/database/flatten.d.ts +75 -0
  27. package/backend/dist/cjs/{logger.js → backend/src/database/flatten.js} +18 -7
  28. package/backend/dist/cjs/backend/src/database/flatten_test.js +175 -0
  29. package/backend/dist/cjs/backend/src/database/quota/quota.d.ts +461 -0
  30. package/backend/dist/cjs/backend/src/database/quota/quota.js +1014 -0
  31. package/backend/dist/cjs/backend/src/database/quota/quota_v1.d.ts +534 -0
  32. package/backend/dist/cjs/backend/src/database/quota/quota_v1.js +1087 -0
  33. package/backend/dist/cjs/backend/src/database/quota/safe_int.d.ts +293 -0
  34. package/backend/dist/cjs/backend/src/database/quota/safe_int.js +573 -0
  35. package/backend/dist/{esm → cjs/backend/src}/endpoint.d.ts +69 -46
  36. package/backend/dist/cjs/{endpoint.js → backend/src/endpoint.js} +87 -101
  37. package/backend/dist/cjs/backend/src/errors/index.d.ts +7 -0
  38. package/backend/dist/cjs/backend/src/errors/index.js +25 -0
  39. package/backend/dist/{esm/utils.d.ts → cjs/backend/src/errors/internal_external.d.ts} +14 -22
  40. package/backend/dist/cjs/backend/src/errors/internal_external.js +85 -0
  41. package/backend/dist/cjs/backend/src/errors/invalid_usage_error.d.ts +38 -0
  42. package/backend/dist/cjs/{mutex.js → backend/src/errors/invalid_usage_error.js} +20 -37
  43. package/backend/dist/cjs/backend/src/errors/system_error.d.ts +230 -0
  44. package/backend/dist/cjs/backend/src/errors/system_error.js +393 -0
  45. package/backend/dist/cjs/backend/src/events.d.ts +54 -0
  46. package/backend/dist/cjs/backend/src/events.js +15 -0
  47. package/backend/dist/cjs/{frontend.js → backend/src/frontend.js} +1 -1
  48. package/backend/dist/cjs/{image_endpoint.d.ts → backend/src/image_endpoint.d.ts} +16 -1
  49. package/backend/dist/cjs/{image_endpoint.js → backend/src/image_endpoint.js} +3 -5
  50. package/backend/dist/cjs/backend/src/logger.d.ts +5 -0
  51. package/backend/dist/cjs/backend/src/logger.js +15 -0
  52. package/backend/dist/cjs/backend/src/meta.d.ts +64 -0
  53. package/backend/dist/cjs/{meta.js → backend/src/meta.js} +9 -12
  54. package/backend/dist/cjs/backend/src/payments/paddle.d.ts +326 -0
  55. package/backend/dist/cjs/{payments → backend/src/payments}/paddle.js +377 -327
  56. package/backend/dist/cjs/backend/src/plugins/browser.d.ts +1 -0
  57. package/backend/dist/cjs/backend/src/plugins/browser.js +15 -0
  58. package/backend/dist/cjs/backend/src/plugins/mail/mail.d.ts +248 -0
  59. package/backend/dist/cjs/backend/src/plugins/mail/mail.js +379 -0
  60. package/backend/dist/{esm → cjs/backend/src}/plugins/mail/ui.d.ts +23 -0
  61. package/backend/dist/cjs/backend/src/plugins/pdf.d.ts +1 -0
  62. package/backend/dist/cjs/backend/src/rate_limit.d.ts +145 -0
  63. package/backend/dist/cjs/backend/src/rate_limit.js +549 -0
  64. package/backend/dist/cjs/{route.d.ts → backend/src/route.d.ts} +3 -10
  65. package/backend/dist/cjs/{route.js → backend/src/route.js} +23 -21
  66. package/backend/dist/cjs/backend/src/server.d.ts +485 -0
  67. package/backend/dist/cjs/{server.js → backend/src/server.js} +688 -873
  68. package/backend/dist/cjs/backend/src/splash_screen.d.ts +80 -0
  69. package/backend/dist/cjs/{splash_screen.js → backend/src/splash_screen.js} +24 -3
  70. package/backend/dist/cjs/backend/src/status.d.ts +74 -0
  71. package/backend/dist/cjs/{status.js → backend/src/status.js} +64 -64
  72. package/backend/dist/cjs/backend/src/stream.d.ts +376 -0
  73. package/backend/dist/cjs/{stream.js → backend/src/stream.js} +299 -276
  74. package/backend/dist/cjs/backend/src/users.d.ts +807 -0
  75. package/backend/dist/cjs/backend/src/users.js +1971 -0
  76. package/backend/dist/cjs/backend/src/utils.d.ts +16 -0
  77. package/backend/dist/cjs/{utils.js → backend/src/utils.js} +14 -77
  78. package/backend/dist/{esm → cjs/backend/src}/view.d.ts +33 -11
  79. package/backend/dist/cjs/backend/src/view.js +508 -0
  80. package/backend/dist/{esm → cjs/backend/src}/volt.d.ts +10 -1
  81. package/backend/dist/cjs/{volt.js → backend/src/volt.js} +8 -5
  82. package/backend/dist/cjs/frontend/src/modules/request.d.ts +70 -0
  83. package/backend/dist/cjs/frontend/src/modules/request.js +99 -0
  84. package/backend/dist/esm/{blacklist.d.ts → backend/src/blacklist.d.ts} +5 -3
  85. package/backend/dist/esm/{blacklist.js → backend/src/blacklist.js} +9 -6
  86. package/backend/dist/esm/{cli.js → backend/src/cli.js} +43 -60
  87. package/backend/dist/esm/backend/src/database/collection.d.ts +1543 -0
  88. package/backend/dist/esm/backend/src/database/collection.js +3510 -0
  89. package/backend/dist/esm/backend/src/database/database.d.ts +66 -0
  90. package/backend/dist/esm/{database → backend/src/database}/database.js +62 -103
  91. package/backend/dist/esm/backend/src/database/document.d.ts +1 -0
  92. package/backend/dist/esm/backend/src/database/document.js +558 -0
  93. package/backend/dist/esm/backend/src/database/filters/filters.d.ts +6 -0
  94. package/backend/dist/esm/backend/src/database/filters/filters.js +1 -0
  95. package/backend/dist/esm/backend/src/database/filters/strict_filter.d.ts +223 -0
  96. package/backend/dist/esm/backend/src/database/filters/strict_filter.js +3 -0
  97. package/backend/dist/esm/backend/src/database/filters/strict_filter_test.d.ts +1 -0
  98. package/backend/dist/esm/backend/src/database/filters/strict_filter_test.js +505 -0
  99. package/backend/dist/esm/backend/src/database/filters/strict_filter_test_v0.d.ts +1 -0
  100. package/backend/dist/esm/backend/src/database/filters/strict_filter_test_v0.js +712 -0
  101. package/backend/dist/esm/backend/src/database/filters/strict_filter_v0.d.ts +50 -0
  102. package/backend/dist/esm/backend/src/database/filters/strict_filter_v0.js +5 -0
  103. package/backend/dist/esm/backend/src/database/filters/strict_filter_v1.d.ts +76 -0
  104. package/backend/dist/esm/backend/src/database/filters/strict_filter_v1.js +44 -0
  105. package/backend/dist/esm/backend/src/database/filters/strict_filter_v2.d.ts +75 -0
  106. package/backend/dist/esm/backend/src/database/filters/strict_filter_v2.js +5 -0
  107. package/backend/dist/esm/backend/src/database/filters/strict_filter_v3.d.ts +219 -0
  108. package/backend/dist/esm/backend/src/database/filters/strict_filter_v3.js +1 -0
  109. package/backend/dist/esm/backend/src/database/filters/strict_update_filter.d.ts +165 -0
  110. package/backend/dist/esm/backend/src/database/filters/strict_update_filter.js +5 -0
  111. package/backend/dist/esm/backend/src/database/filters/strict_update_filter_test.d.ts +5 -0
  112. package/backend/dist/esm/backend/src/database/filters/strict_update_filter_test.js +405 -0
  113. package/backend/dist/esm/backend/src/database/flatten.d.ts +75 -0
  114. package/backend/dist/esm/backend/src/database/flatten.js +22 -0
  115. package/backend/dist/esm/backend/src/database/flatten_test.d.ts +1 -0
  116. package/backend/dist/esm/backend/src/database/flatten_test.js +174 -0
  117. package/backend/dist/esm/backend/src/database/quota/quota.d.ts +461 -0
  118. package/backend/dist/esm/backend/src/database/quota/quota.js +1118 -0
  119. package/backend/dist/esm/backend/src/database/quota/quota_v1.d.ts +534 -0
  120. package/backend/dist/esm/backend/src/database/quota/quota_v1.js +1242 -0
  121. package/backend/dist/esm/backend/src/database/quota/safe_int.d.ts +293 -0
  122. package/backend/dist/esm/backend/src/database/quota/safe_int.js +602 -0
  123. package/backend/dist/{cjs → esm/backend/src}/endpoint.d.ts +69 -46
  124. package/backend/dist/esm/{endpoint.js → backend/src/endpoint.js} +136 -127
  125. package/backend/dist/esm/backend/src/errors/index.d.ts +7 -0
  126. package/backend/dist/esm/backend/src/errors/index.js +7 -0
  127. package/backend/dist/{cjs/utils.d.ts → esm/backend/src/errors/internal_external.d.ts} +14 -22
  128. package/backend/dist/esm/backend/src/errors/internal_external.js +70 -0
  129. package/backend/dist/esm/backend/src/errors/invalid_usage_error.d.ts +38 -0
  130. package/backend/dist/esm/backend/src/errors/invalid_usage_error.js +30 -0
  131. package/backend/dist/esm/backend/src/errors/system_error.d.ts +230 -0
  132. package/backend/dist/esm/backend/src/errors/system_error.js +402 -0
  133. package/backend/dist/esm/backend/src/events.d.ts +54 -0
  134. package/backend/dist/esm/backend/src/events.js +5 -0
  135. package/backend/dist/esm/{frontend.js → backend/src/frontend.js} +1 -1
  136. package/backend/dist/esm/{image_endpoint.d.ts → backend/src/image_endpoint.d.ts} +16 -1
  137. package/backend/dist/esm/{image_endpoint.js → backend/src/image_endpoint.js} +16 -20
  138. package/backend/dist/esm/backend/src/logger.d.ts +5 -0
  139. package/backend/dist/esm/backend/src/logger.js +8 -0
  140. package/backend/dist/esm/backend/src/meta.d.ts +64 -0
  141. package/backend/dist/esm/{meta.js → backend/src/meta.js} +15 -54
  142. package/backend/dist/esm/backend/src/payments/paddle.d.ts +326 -0
  143. package/backend/dist/esm/{payments → backend/src/payments}/paddle.js +417 -452
  144. package/backend/dist/esm/backend/src/plugins/browser.d.ts +1 -0
  145. package/backend/dist/esm/backend/src/plugins/browser.js +170 -0
  146. package/backend/dist/esm/backend/src/plugins/mail/mail.d.ts +248 -0
  147. package/backend/dist/esm/backend/src/plugins/mail/mail.js +389 -0
  148. package/backend/dist/{cjs → esm/backend/src}/plugins/mail/ui.d.ts +23 -0
  149. package/backend/dist/esm/{plugins → backend/src/plugins}/mail/ui.js +3 -6
  150. package/backend/dist/esm/backend/src/plugins/pdf.d.ts +1 -0
  151. package/backend/dist/esm/{plugins → backend/src/plugins}/pdf.js +3 -3
  152. package/backend/dist/esm/backend/src/rate_limit.d.ts +145 -0
  153. package/backend/dist/esm/backend/src/rate_limit.js +667 -0
  154. package/backend/dist/esm/{route.d.ts → backend/src/route.d.ts} +3 -10
  155. package/backend/dist/esm/{route.js → backend/src/route.js} +26 -21
  156. package/backend/dist/esm/backend/src/server.d.ts +485 -0
  157. package/backend/dist/esm/{server.js → backend/src/server.js} +891 -1441
  158. package/backend/dist/esm/backend/src/splash_screen.d.ts +80 -0
  159. package/backend/dist/esm/{splash_screen.js → backend/src/splash_screen.js} +42 -55
  160. package/backend/dist/esm/backend/src/status.d.ts +74 -0
  161. package/backend/dist/esm/backend/src/status.js +199 -0
  162. package/backend/dist/esm/backend/src/stream.d.ts +376 -0
  163. package/backend/dist/esm/{stream.js → backend/src/stream.js} +327 -292
  164. package/backend/dist/esm/backend/src/users.d.ts +809 -0
  165. package/backend/dist/esm/backend/src/users.js +2140 -0
  166. package/backend/dist/esm/backend/src/utils.d.ts +16 -0
  167. package/backend/dist/esm/{utils.js → backend/src/utils.js} +20 -81
  168. package/backend/dist/{cjs → esm/backend/src}/view.d.ts +33 -11
  169. package/backend/dist/esm/{view.js → backend/src/view.js} +266 -86
  170. package/backend/dist/{cjs → esm/backend/src}/volt.d.ts +10 -1
  171. package/backend/dist/esm/{volt.js → backend/src/volt.js} +7 -4
  172. package/backend/dist/esm/frontend/src/modules/request.d.ts +70 -0
  173. package/backend/dist/esm/frontend/src/modules/request.js +117 -0
  174. package/frontend/dist/backend/src/database/collection.d.ts +1543 -0
  175. package/frontend/dist/backend/src/database/collection.js +3510 -0
  176. package/frontend/dist/backend/src/database/database.d.ts +66 -0
  177. package/frontend/dist/backend/src/database/database.js +196 -0
  178. package/frontend/dist/backend/src/database/filters/filters.d.ts +6 -0
  179. package/frontend/dist/backend/src/database/filters/filters.js +1 -0
  180. package/frontend/dist/backend/src/database/filters/strict_filter.d.ts +223 -0
  181. package/frontend/dist/backend/src/database/filters/strict_filter.js +3 -0
  182. package/frontend/dist/backend/src/database/filters/strict_update_filter.d.ts +165 -0
  183. package/frontend/dist/backend/src/database/filters/strict_update_filter.js +5 -0
  184. package/frontend/dist/backend/src/database/flatten.d.ts +75 -0
  185. package/frontend/dist/backend/src/database/flatten.js +22 -0
  186. package/frontend/dist/backend/src/endpoint.d.ts +204 -0
  187. package/frontend/dist/backend/src/endpoint.js +570 -0
  188. package/frontend/dist/backend/src/errors/index.d.ts +7 -0
  189. package/frontend/dist/backend/src/errors/index.js +7 -0
  190. package/frontend/dist/backend/src/errors/internal_external.d.ts +38 -0
  191. package/frontend/dist/backend/src/errors/internal_external.js +70 -0
  192. package/frontend/dist/backend/src/errors/invalid_usage_error.d.ts +38 -0
  193. package/frontend/dist/backend/src/errors/invalid_usage_error.js +30 -0
  194. package/frontend/dist/backend/src/errors/system_error.d.ts +230 -0
  195. package/frontend/dist/backend/src/errors/system_error.js +402 -0
  196. package/frontend/dist/backend/src/events.d.ts +54 -0
  197. package/frontend/dist/backend/src/events.js +5 -0
  198. package/frontend/dist/backend/src/frontend.d.ts +11 -0
  199. package/frontend/dist/backend/src/frontend.js +12 -0
  200. package/frontend/dist/backend/src/image_endpoint.d.ts +39 -0
  201. package/frontend/dist/backend/src/image_endpoint.js +202 -0
  202. package/frontend/dist/backend/src/meta.d.ts +64 -0
  203. package/frontend/dist/backend/src/meta.js +110 -0
  204. package/frontend/dist/backend/src/payments/paddle.d.ts +326 -0
  205. package/frontend/dist/backend/src/payments/paddle.js +2256 -0
  206. package/frontend/dist/backend/src/plugins/mail/mail.d.ts +248 -0
  207. package/frontend/dist/backend/src/plugins/mail/mail.js +389 -0
  208. package/{backend/dist/esm/plugins/mail.d.ts → frontend/dist/backend/src/plugins/mail/ui.d.ts} +23 -0
  209. package/{backend/dist/esm/plugins/mail.js → frontend/dist/backend/src/plugins/mail/ui.js} +3 -6
  210. package/frontend/dist/backend/src/rate_limit.d.ts +145 -0
  211. package/frontend/dist/backend/src/rate_limit.js +673 -0
  212. package/frontend/dist/backend/src/route.d.ts +35 -0
  213. package/frontend/dist/backend/src/route.js +212 -0
  214. package/frontend/dist/backend/src/server.d.ts +485 -0
  215. package/frontend/dist/backend/src/server.js +2670 -0
  216. package/frontend/dist/backend/src/splash_screen.d.ts +80 -0
  217. package/frontend/dist/backend/src/splash_screen.js +135 -0
  218. package/frontend/dist/backend/src/status.d.ts +74 -0
  219. package/frontend/dist/backend/src/status.js +199 -0
  220. package/frontend/dist/backend/src/stream.d.ts +376 -0
  221. package/frontend/dist/backend/src/stream.js +1007 -0
  222. package/frontend/dist/backend/src/users.d.ts +807 -0
  223. package/frontend/dist/backend/src/users.js +2118 -0
  224. package/frontend/dist/backend/src/utils.d.ts +16 -0
  225. package/frontend/dist/backend/src/utils.js +241 -0
  226. package/frontend/dist/backend/src/view.d.ts +162 -0
  227. package/frontend/dist/backend/src/view.js +720 -0
  228. package/frontend/dist/frontend/src/elements/base.d.ts +4414 -0
  229. package/frontend/dist/{elements → frontend/src/elements}/base.js +3624 -260
  230. package/frontend/dist/frontend/src/elements/module.d.ts +95 -0
  231. package/frontend/dist/{elements → frontend/src/elements}/module.js +53 -52
  232. package/frontend/dist/frontend/src/elements/types.d.ts +52 -0
  233. package/frontend/dist/frontend/src/elements/types.js +5 -0
  234. package/frontend/dist/frontend/src/modules/attachment.d.ts +126 -0
  235. package/frontend/dist/frontend/src/modules/attachment.js +306 -0
  236. package/frontend/dist/frontend/src/modules/auth.d.ts +44 -0
  237. package/frontend/dist/frontend/src/modules/auth.js +80 -0
  238. package/frontend/dist/{modules → frontend/src/modules}/color.js +2 -2
  239. package/frontend/dist/frontend/src/modules/compression.d.ts +39 -0
  240. package/frontend/dist/frontend/src/modules/compression.js +102 -0
  241. package/frontend/dist/frontend/src/modules/cookies.d.ts +44 -0
  242. package/frontend/dist/frontend/src/modules/cookies.js +143 -0
  243. package/frontend/dist/frontend/src/modules/events.d.ts +31 -0
  244. package/frontend/dist/frontend/src/modules/events.js +74 -0
  245. package/frontend/dist/frontend/src/modules/google.d.ts +23 -0
  246. package/frontend/dist/frontend/src/modules/google.js +52 -0
  247. package/frontend/dist/frontend/src/modules/meta.d.ts +14 -0
  248. package/frontend/dist/{modules → frontend/src/modules}/meta.js +9 -7
  249. package/frontend/dist/{modules → frontend/src/modules}/paddle.d.ts +37 -134
  250. package/frontend/dist/{modules → frontend/src/modules}/paddle.js +620 -568
  251. package/frontend/dist/frontend/src/modules/request.d.ts +70 -0
  252. package/frontend/dist/frontend/src/modules/request.js +117 -0
  253. package/frontend/dist/frontend/src/modules/settings.d.ts +3 -0
  254. package/frontend/dist/frontend/src/modules/settings.js +5 -0
  255. package/frontend/dist/frontend/src/modules/statics.d.ts +21 -0
  256. package/frontend/dist/{modules → frontend/src/modules}/statics.js +15 -18
  257. package/frontend/dist/frontend/src/modules/support.d.ts +30 -0
  258. package/frontend/dist/frontend/src/modules/support.js +53 -0
  259. package/frontend/dist/{modules → frontend/src/modules}/theme.d.ts +67 -0
  260. package/frontend/dist/{modules → frontend/src/modules}/theme.js +68 -38
  261. package/frontend/dist/frontend/src/modules/themes.d.ts +12 -0
  262. package/frontend/dist/frontend/src/modules/themes.js +22 -0
  263. package/frontend/dist/frontend/src/modules/user.d.ts +164 -0
  264. package/frontend/dist/frontend/src/modules/user.js +268 -0
  265. package/frontend/dist/frontend/src/modules/utils.d.ts +176 -0
  266. package/frontend/dist/frontend/src/modules/utils.js +569 -0
  267. package/frontend/dist/frontend/src/types/gradient.d.ts +29 -0
  268. package/frontend/dist/{types → frontend/src/types}/gradient.js +14 -18
  269. package/frontend/dist/frontend/src/ui/border_button.d.ts +94 -0
  270. package/frontend/dist/{ui → frontend/src/ui}/border_button.js +7 -13
  271. package/frontend/dist/frontend/src/ui/button.d.ts +28 -0
  272. package/frontend/dist/{ui → frontend/src/ui}/button.js +21 -12
  273. package/frontend/dist/frontend/src/ui/canvas.d.ts +138 -0
  274. package/frontend/dist/{ui → frontend/src/ui}/canvas.js +88 -55
  275. package/frontend/dist/frontend/src/ui/checkbox.d.ts +74 -0
  276. package/frontend/dist/{ui → frontend/src/ui}/checkbox.js +80 -41
  277. package/frontend/dist/{ui → frontend/src/ui}/code.d.ts +73 -6
  278. package/frontend/dist/{ui → frontend/src/ui}/code.js +55 -52
  279. package/frontend/dist/{ui → frontend/src/ui}/context_menu.d.ts +4 -0
  280. package/frontend/dist/{ui → frontend/src/ui}/context_menu.js +12 -17
  281. package/frontend/dist/{ui → frontend/src/ui}/css.d.ts +4 -0
  282. package/frontend/dist/{ui → frontend/src/ui}/css.js +3 -3
  283. package/frontend/dist/{ui → frontend/src/ui}/divider.d.ts +4 -0
  284. package/frontend/dist/{ui → frontend/src/ui}/divider.js +3 -3
  285. package/frontend/dist/{ui → frontend/src/ui}/dropdown.d.ts +57 -2
  286. package/frontend/dist/{ui → frontend/src/ui}/dropdown.js +87 -94
  287. package/frontend/dist/{ui → frontend/src/ui}/for_each.d.ts +4 -0
  288. package/frontend/dist/{ui → frontend/src/ui}/for_each.js +3 -3
  289. package/frontend/dist/{ui → frontend/src/ui}/form.d.ts +6 -2
  290. package/frontend/dist/{ui → frontend/src/ui}/form.js +10 -7
  291. package/frontend/dist/frontend/src/ui/frame_modes.d.ts +37 -0
  292. package/frontend/dist/{ui → frontend/src/ui}/frame_modes.js +16 -22
  293. package/frontend/dist/{ui → frontend/src/ui}/google_map.d.ts +4 -0
  294. package/frontend/dist/{ui → frontend/src/ui}/google_map.js +4 -4
  295. package/frontend/dist/{ui → frontend/src/ui}/gradient.d.ts +4 -0
  296. package/frontend/dist/{ui → frontend/src/ui}/gradient.js +3 -3
  297. package/frontend/dist/{ui → frontend/src/ui}/image.d.ts +4 -0
  298. package/frontend/dist/{ui → frontend/src/ui}/image.js +5 -5
  299. package/frontend/dist/frontend/src/ui/input.d.ts +392 -0
  300. package/frontend/dist/{ui → frontend/src/ui}/input.js +346 -360
  301. package/frontend/dist/{ui → frontend/src/ui}/link.d.ts +4 -0
  302. package/frontend/dist/{ui → frontend/src/ui}/link.js +3 -3
  303. package/frontend/dist/{ui → frontend/src/ui}/list.d.ts +4 -0
  304. package/frontend/dist/{ui → frontend/src/ui}/list.js +12 -6
  305. package/frontend/dist/frontend/src/ui/loader_button.d.ts +80 -0
  306. package/frontend/dist/{ui → frontend/src/ui}/loader_button.js +35 -47
  307. package/frontend/dist/frontend/src/ui/loaders.d.ts +57 -0
  308. package/frontend/dist/{ui → frontend/src/ui}/loaders.js +11 -11
  309. package/frontend/dist/{ui → frontend/src/ui}/popup.d.ts +11 -6
  310. package/frontend/dist/{ui → frontend/src/ui}/popup.js +32 -18
  311. package/frontend/dist/frontend/src/ui/pseudo.d.ts +44 -0
  312. package/frontend/dist/{ui → frontend/src/ui}/pseudo.js +84 -8
  313. package/frontend/dist/{ui → frontend/src/ui}/scroller.d.ts +14 -2
  314. package/frontend/dist/{ui → frontend/src/ui}/scroller.js +37 -43
  315. package/frontend/dist/{ui → frontend/src/ui}/slider.d.ts +5 -1
  316. package/frontend/dist/{ui → frontend/src/ui}/slider.js +4 -4
  317. package/frontend/dist/{ui → frontend/src/ui}/spacer.d.ts +4 -0
  318. package/frontend/dist/{ui → frontend/src/ui}/spacer.js +3 -3
  319. package/frontend/dist/{ui → frontend/src/ui}/span.d.ts +4 -0
  320. package/frontend/dist/{ui → frontend/src/ui}/span.js +3 -3
  321. package/frontend/dist/{ui → frontend/src/ui}/stack.d.ts +4 -0
  322. package/frontend/dist/{ui → frontend/src/ui}/stack.js +3 -9
  323. package/frontend/dist/frontend/src/ui/steps.d.ts +131 -0
  324. package/frontend/dist/{ui → frontend/src/ui}/steps.js +30 -45
  325. package/frontend/dist/{ui → frontend/src/ui}/style.d.ts +4 -0
  326. package/frontend/dist/{ui → frontend/src/ui}/style.js +3 -3
  327. package/frontend/dist/{ui → frontend/src/ui}/switch.d.ts +5 -1
  328. package/frontend/dist/{ui → frontend/src/ui}/switch.js +4 -4
  329. package/frontend/dist/{ui → frontend/src/ui}/table.d.ts +4 -0
  330. package/frontend/dist/{ui → frontend/src/ui}/table.js +6 -6
  331. package/frontend/dist/{ui → frontend/src/ui}/tabs.d.ts +45 -3
  332. package/frontend/dist/{ui → frontend/src/ui}/tabs.js +65 -40
  333. package/frontend/dist/{ui → frontend/src/ui}/text.d.ts +4 -0
  334. package/frontend/dist/{ui → frontend/src/ui}/text.js +3 -3
  335. package/frontend/dist/frontend/src/ui/title.d.ts +91 -0
  336. package/frontend/dist/frontend/src/ui/title.js +272 -0
  337. package/frontend/dist/{ui → frontend/src/ui}/view.d.ts +4 -0
  338. package/frontend/dist/{ui → frontend/src/ui}/view.js +3 -3
  339. package/frontend/dist/{volt.d.ts → frontend/src/volt.d.ts} +3 -0
  340. package/frontend/dist/{volt.js → frontend/src/volt.js} +4 -0
  341. package/frontend/tools/bundle_d_ts.js +71 -0
  342. package/frontend/tools/convert_to_jsdoc_input.txt +9452 -0
  343. package/frontend/tools/convert_to_jsdoc_output.txt +7626 -0
  344. package/frontend/tools/convert_to_jsdoc_tmp.js +345 -0
  345. package/package.json +11 -12
  346. package/backend/dist/cjs/database/collection.d.ts +0 -160
  347. package/backend/dist/cjs/database/collection.js +0 -842
  348. package/backend/dist/cjs/database/database.d.ts +0 -121
  349. package/backend/dist/cjs/database/document.d.ts +0 -131
  350. package/backend/dist/cjs/database/document.js +0 -224
  351. package/backend/dist/cjs/database.d.ts +0 -502
  352. package/backend/dist/cjs/database.js +0 -2248
  353. package/backend/dist/cjs/logger.d.ts +0 -3
  354. package/backend/dist/cjs/meta.d.ts +0 -50
  355. package/backend/dist/cjs/mutex.d.ts +0 -24
  356. package/backend/dist/cjs/payments/paddle.d.ts +0 -160
  357. package/backend/dist/cjs/plugins/browser.d.ts +0 -36
  358. package/backend/dist/cjs/plugins/browser.js +0 -198
  359. package/backend/dist/cjs/plugins/css.d.ts +0 -11
  360. package/backend/dist/cjs/plugins/css.js +0 -80
  361. package/backend/dist/cjs/plugins/mail.d.ts +0 -277
  362. package/backend/dist/cjs/plugins/mail.js +0 -1370
  363. package/backend/dist/cjs/plugins/ts/compiler.d.ts +0 -139
  364. package/backend/dist/cjs/plugins/ts/compiler.js +0 -750
  365. package/backend/dist/cjs/plugins/ts/preprocessing.d.ts +0 -14
  366. package/backend/dist/cjs/plugins/ts/preprocessing.js +0 -440
  367. package/backend/dist/cjs/rate_limit.d.ts +0 -63
  368. package/backend/dist/cjs/rate_limit.js +0 -348
  369. package/backend/dist/cjs/request.deprc.d.ts +0 -48
  370. package/backend/dist/cjs/request.deprc.js +0 -572
  371. package/backend/dist/cjs/response.deprc.d.ts +0 -55
  372. package/backend/dist/cjs/response.deprc.js +0 -275
  373. package/backend/dist/cjs/server.d.ts +0 -342
  374. package/backend/dist/cjs/splash_screen.d.ts +0 -35
  375. package/backend/dist/cjs/status.d.ts +0 -61
  376. package/backend/dist/cjs/stream.d.ts +0 -79
  377. package/backend/dist/cjs/users.d.ts +0 -111
  378. package/backend/dist/cjs/users.js +0 -1817
  379. package/backend/dist/cjs/view.js +0 -352
  380. package/backend/dist/cjs/vinc.dev.d.ts +0 -3
  381. package/backend/dist/cjs/vinc.dev.js +0 -7
  382. package/backend/dist/css/adyen.css +0 -92
  383. package/backend/dist/css/volt.css +0 -70
  384. package/backend/dist/esm/database/collection.d.ts +0 -160
  385. package/backend/dist/esm/database/collection.js +0 -1328
  386. package/backend/dist/esm/database/database.d.ts +0 -121
  387. package/backend/dist/esm/database/document.d.ts +0 -131
  388. package/backend/dist/esm/database/document.js +0 -247
  389. package/backend/dist/esm/database.d.ts +0 -502
  390. package/backend/dist/esm/database.js +0 -2423
  391. package/backend/dist/esm/file_watcher.js +0 -329
  392. package/backend/dist/esm/logger.d.ts +0 -3
  393. package/backend/dist/esm/logger.js +0 -11
  394. package/backend/dist/esm/meta.d.ts +0 -50
  395. package/backend/dist/esm/mutex.d.ts +0 -24
  396. package/backend/dist/esm/mutex.js +0 -48
  397. package/backend/dist/esm/payments/paddle.d.ts +0 -160
  398. package/backend/dist/esm/plugins/browser.d.ts +0 -36
  399. package/backend/dist/esm/plugins/browser.js +0 -176
  400. package/backend/dist/esm/plugins/css.d.ts +0 -11
  401. package/backend/dist/esm/plugins/css.js +0 -90
  402. package/backend/dist/esm/plugins/ts/compiler.d.ts +0 -139
  403. package/backend/dist/esm/plugins/ts/compiler.js +0 -1194
  404. package/backend/dist/esm/plugins/ts/preprocessing.d.ts +0 -14
  405. package/backend/dist/esm/plugins/ts/preprocessing.js +0 -726
  406. package/backend/dist/esm/rate_limit.d.ts +0 -63
  407. package/backend/dist/esm/rate_limit.js +0 -417
  408. package/backend/dist/esm/request.deprc.d.ts +0 -48
  409. package/backend/dist/esm/request.deprc.js +0 -572
  410. package/backend/dist/esm/response.deprc.d.ts +0 -55
  411. package/backend/dist/esm/response.deprc.js +0 -275
  412. package/backend/dist/esm/server.d.ts +0 -342
  413. package/backend/dist/esm/splash_screen.d.ts +0 -35
  414. package/backend/dist/esm/status.d.ts +0 -61
  415. package/backend/dist/esm/status.js +0 -197
  416. package/backend/dist/esm/stream.d.ts +0 -79
  417. package/backend/dist/esm/users.d.ts +0 -111
  418. package/backend/dist/esm/users.js +0 -1935
  419. package/backend/dist/esm/vinc.dev.d.ts +0 -3
  420. package/backend/dist/esm/vinc.dev.js +0 -7
  421. package/frontend/dist/elements/base.d.ts +0 -9889
  422. package/frontend/dist/elements/module.d.ts +0 -30
  423. package/frontend/dist/modules/array.d.ts +0 -94
  424. package/frontend/dist/modules/array.js +0 -634
  425. package/frontend/dist/modules/auth.d.ts +0 -46
  426. package/frontend/dist/modules/auth.js +0 -139
  427. package/frontend/dist/modules/colors.d.ts +0 -1
  428. package/frontend/dist/modules/colors.js +0 -417
  429. package/frontend/dist/modules/compression.d.ts +0 -6
  430. package/frontend/dist/modules/compression.js +0 -999
  431. package/frontend/dist/modules/cookies.d.ts +0 -18
  432. package/frontend/dist/modules/cookies.js +0 -167
  433. package/frontend/dist/modules/date.d.ts +0 -142
  434. package/frontend/dist/modules/date.js +0 -493
  435. package/frontend/dist/modules/events.d.ts +0 -8
  436. package/frontend/dist/modules/events.js +0 -91
  437. package/frontend/dist/modules/google.d.ts +0 -11
  438. package/frontend/dist/modules/google.js +0 -54
  439. package/frontend/dist/modules/meta.d.ts +0 -10
  440. package/frontend/dist/modules/mutex.d.ts +0 -7
  441. package/frontend/dist/modules/mutex.js +0 -51
  442. package/frontend/dist/modules/number.d.ts +0 -16
  443. package/frontend/dist/modules/number.js +0 -23
  444. package/frontend/dist/modules/object.d.ts +0 -52
  445. package/frontend/dist/modules/object.js +0 -383
  446. package/frontend/dist/modules/scheme.d.ts +0 -227
  447. package/frontend/dist/modules/scheme.js +0 -531
  448. package/frontend/dist/modules/settings.d.ts +0 -3
  449. package/frontend/dist/modules/settings.js +0 -4
  450. package/frontend/dist/modules/statics.d.ts +0 -5
  451. package/frontend/dist/modules/string.d.ts +0 -124
  452. package/frontend/dist/modules/string.js +0 -745
  453. package/frontend/dist/modules/support.d.ts +0 -19
  454. package/frontend/dist/modules/support.js +0 -103
  455. package/frontend/dist/modules/themes.d.ts +0 -8
  456. package/frontend/dist/modules/themes.js +0 -18
  457. package/frontend/dist/modules/user.d.ts +0 -59
  458. package/frontend/dist/modules/user.js +0 -280
  459. package/frontend/dist/modules/utils.d.ts +0 -87
  460. package/frontend/dist/modules/utils.js +0 -923
  461. package/frontend/dist/types/gradient.d.ts +0 -12
  462. package/frontend/dist/ui/border_button.d.ts +0 -152
  463. package/frontend/dist/ui/button.d.ts +0 -21
  464. package/frontend/dist/ui/canvas.d.ts +0 -56
  465. package/frontend/dist/ui/checkbox.d.ts +0 -52
  466. package/frontend/dist/ui/frame_modes.d.ts +0 -25
  467. package/frontend/dist/ui/input.d.ts +0 -241
  468. package/frontend/dist/ui/loader_button.d.ts +0 -93
  469. package/frontend/dist/ui/loaders.d.ts +0 -57
  470. package/frontend/dist/ui/pseudo.d.ts +0 -16
  471. package/frontend/dist/ui/steps.d.ts +0 -59
  472. package/frontend/dist/ui/title.d.ts +0 -21
  473. package/frontend/dist/ui/title.js +0 -121
  474. package/frontend/examples/dashboard/dashboard.ts +0 -776
  475. /package/backend/dist/cjs/{cli.d.ts → backend/src/cli.d.ts} +0 -0
  476. /package/backend/dist/cjs/{file_watcher.d.ts → backend/src/database/document.d.ts} +0 -0
  477. /package/backend/dist/cjs/{file_watcher.js → backend/src/database/document.js} +0 -0
  478. /package/backend/dist/cjs/{plugins/pdf.d.ts → backend/src/database/filters/strict_filter_test.d.ts} +0 -0
  479. /package/backend/dist/{esm/file_watcher.d.ts → cjs/backend/src/database/filters/strict_filter_test_v0.d.ts} +0 -0
  480. /package/backend/dist/{esm/plugins/pdf.d.ts → cjs/backend/src/database/flatten_test.d.ts} +0 -0
  481. /package/backend/dist/cjs/{frontend.d.ts → backend/src/frontend.d.ts} +0 -0
  482. /package/backend/dist/cjs/{plugins → backend/src/plugins}/communication.d.ts +0 -0
  483. /package/backend/dist/cjs/{plugins → backend/src/plugins}/communication.js +0 -0
  484. /package/backend/dist/cjs/{plugins → backend/src/plugins}/mail/ui.js +0 -0
  485. /package/backend/dist/cjs/{plugins → backend/src/plugins}/pdf.js +0 -0
  486. /package/backend/dist/cjs/{plugins → backend/src/plugins}/thread_monitor.d.ts +0 -0
  487. /package/backend/dist/cjs/{plugins → backend/src/plugins}/thread_monitor.js +0 -0
  488. /package/backend/dist/cjs/{vinc.d.ts → backend/src/vinc.d.ts} +0 -0
  489. /package/backend/dist/cjs/{vinc.js → backend/src/vinc.js} +0 -0
  490. /package/backend/dist/esm/{cli.d.ts → backend/src/cli.d.ts} +0 -0
  491. /package/backend/dist/esm/{frontend.d.ts → backend/src/frontend.d.ts} +0 -0
  492. /package/backend/dist/esm/{plugins → backend/src/plugins}/communication.d.ts +0 -0
  493. /package/backend/dist/esm/{plugins → backend/src/plugins}/communication.js +0 -0
  494. /package/backend/dist/esm/{plugins → backend/src/plugins}/thread_monitor.d.ts +0 -0
  495. /package/backend/dist/esm/{plugins → backend/src/plugins}/thread_monitor.js +0 -0
  496. /package/backend/dist/esm/{vinc.d.ts → backend/src/vinc.d.ts} +0 -0
  497. /package/backend/dist/esm/{vinc.js → backend/src/vinc.js} +0 -0
  498. /package/frontend/dist/{elements → frontend/src/elements}/register_element.d.ts +0 -0
  499. /package/frontend/dist/{elements → frontend/src/elements}/register_element.js +0 -0
  500. /package/frontend/dist/{modules → frontend/src/modules}/color.d.ts +0 -0
  501. /package/frontend/dist/{ui → frontend/src/ui}/ui.d.ts +0 -0
  502. /package/frontend/dist/{ui → frontend/src/ui}/ui.js +0 -0
@@ -27,26 +27,50 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
28
  var stdin_exports = {};
29
29
  __export(stdin_exports, {
30
+ LineItem: () => LineItem,
30
31
  Paddle: () => Paddle,
31
- default: () => stdin_default
32
+ Payment: () => Payment,
33
+ PaymentStatusValues: () => PaymentStatusValues
32
34
  });
33
35
  module.exports = __toCommonJS(stdin_exports);
34
36
  var https = __toESM(require("https"));
35
37
  var PDFDocument = __toESM(require("pdfkit"));
36
38
  var libcrypto = __toESM(require("crypto"));
37
- var import_blob_stream = __toESM(require("blob-stream"));
38
39
  var vlib = __toESM(require("@vandenberghinc/vlib"));
39
- var import_utils = require("../utils.js");
40
- var import_logger = require("../logger.js");
40
+ var import_errors = require("../errors/index.js");
41
41
  var import_status = require("../status.js");
42
- const { log, error } = import_logger.logger;
43
- class RequestError extends Error {
44
- status_code;
45
- constructor(err, status_code) {
46
- super(err);
47
- this.status_code = status_code;
42
+ var import_collection = require("../database/collection.js");
43
+ var import_utils = require("../utils.js");
44
+ var LineItem;
45
+ (function(LineItem2) {
46
+ LineItem2.Schema = {
47
+ product: "string",
48
+ item_id: "string",
49
+ paddle_prod_id: "string",
50
+ quantity: "number",
51
+ tax_rate: "number",
52
+ tax: "number",
53
+ discount: "number",
54
+ subtotal: "number",
55
+ total: "number",
56
+ status: { type: "string", enum: ["paid", "refunded", "refunding"] }
57
+ };
58
+ })(LineItem || (LineItem = {}));
59
+ const PaymentStatusValues = ["open", "paid", "past_due", "unknown"];
60
+ var Payment;
61
+ (function(Payment2) {
62
+ function anonymize(payment) {
63
+ if (!payment.uid || payment.uid === "unauth") {
64
+ const { billing_details, ...rest } = payment;
65
+ return {
66
+ ...rest,
67
+ billing_details: void 0
68
+ };
69
+ }
70
+ return payment;
48
71
  }
49
- }
72
+ Payment2.anonymize = anonymize;
73
+ })(Payment || (Payment = {}));
50
74
  class Paddle {
51
75
  type;
52
76
  client_key;
@@ -58,22 +82,28 @@ class Paddle {
58
82
  _headers;
59
83
  webhook_key;
60
84
  _has_create_products_permission;
61
- _settings_db;
85
+ _last_products_db;
86
+ _webhook_conf_db;
62
87
  _sub_db;
63
88
  _active_sub_db;
64
89
  _pay_db;
65
- // private _inv_db?: Collection;
90
+ // private _inv_db: Collection;
66
91
  performance;
67
- constructor({ api_key, client_key, sandbox = false, products = [], inclusive_tax = false, _server = null }) {
68
- vlib.Scheme.validate(arguments[0], { strict: true, parent: "payments", scheme: {
69
- type: { type: "string", default: "paddle" },
70
- api_key: "string",
71
- client_key: "string",
72
- sandbox: { type: "boolean", default: false },
73
- inclusive_tax: { type: "boolean", default: false },
74
- products: "array",
75
- _server: "object"
76
- } });
92
+ constructor({ api_key, client_key, sandbox = false, products = [], inclusive_tax = false, _server }) {
93
+ vlib.schema.validate(arguments[0], {
94
+ unknown: false,
95
+ throw: true,
96
+ parent: "payments",
97
+ schema: {
98
+ type: { type: "string", default: "paddle" },
99
+ api_key: "string",
100
+ client_key: "string",
101
+ sandbox: { type: "boolean", default: false },
102
+ inclusive_tax: { type: "boolean", default: false },
103
+ products: "array",
104
+ _server: "object"
105
+ }
106
+ });
77
107
  this.type = "paddle";
78
108
  this.client_key = client_key;
79
109
  this.sandbox = sandbox;
@@ -90,6 +120,26 @@ class Paddle {
90
120
  this.server.csp["script-src"] += " https://*.paddle.com/ https://*.payments-amazon.com https://*.paypal.com https://*.google.com";
91
121
  this.server.csp["style-src"] += " https://*.paddle.com/ https://*.media-amazon.com https://*.paypal.com https://*.google.com";
92
122
  this.server.csp["img-src"] += " https://*.paddle.com/ https://*.media-amazon.com https://*.paypal.com https://*.google.com";
123
+ this._last_products_db = this.server.db.collection({
124
+ name: "Volt.Paddle.LastProducts",
125
+ indexes: ["production", "version"]
126
+ });
127
+ this._webhook_conf_db = this.server.db.collection({
128
+ name: "Volt.Paddle.WebhookConfig",
129
+ indexes: ["production", "version"]
130
+ });
131
+ this._sub_db = this.server.db.collection({
132
+ name: "Volt.Paddle.Subscriptions",
133
+ indexes: ["uid", "id"]
134
+ });
135
+ this._active_sub_db = this.server.db.collection({
136
+ name: "Volt.Paddle.ActiveSubscriptions",
137
+ indexes: ["uid", "prod_id"]
138
+ });
139
+ this._pay_db = this.server.db.collection({
140
+ name: "Volt.Paddle.Payments",
141
+ indexes: ["uid", "id", "tran_id"]
142
+ });
93
143
  this.performance = new vlib.Performance("Payments performance");
94
144
  }
95
145
  // ---------------------------------------------------------
@@ -98,10 +148,23 @@ class Paddle {
98
148
  // Utils (private).
99
149
  async _req(method, endpoint, params = null) {
100
150
  const promise = new Promise((resolve, reject) => {
151
+ const is_get_like = method === "GET" || method === "HEAD";
152
+ let hostname = this._host;
153
+ let path = endpoint;
154
+ try {
155
+ if (/^https?:\/\//i.test(endpoint)) {
156
+ const u = new URL(endpoint);
157
+ hostname = u.hostname;
158
+ path = u.pathname + u.search;
159
+ } else if (is_get_like && params != null) {
160
+ path = `${endpoint}?${new URLSearchParams(params).toString()}`;
161
+ }
162
+ } catch {
163
+ }
101
164
  const options = {
102
165
  method,
103
- hostname: this._host,
104
- path: method === "GET" && params != null ? `${endpoint}?${new URLSearchParams(params).toString()}` : endpoint,
166
+ hostname,
167
+ path,
105
168
  port: 443,
106
169
  headers: this._headers
107
170
  };
@@ -113,21 +176,21 @@ class Paddle {
113
176
  response.on("end", () => {
114
177
  if (response?.statusCode >= 200 && response?.statusCode < 300) {
115
178
  try {
116
- resolve(JSON.parse(data));
117
- } catch (error2) {
179
+ resolve(data ? JSON.parse(data) : {});
180
+ } catch (error) {
118
181
  reject(new Error("Failed to parse response data"));
119
182
  }
120
183
  } else {
121
184
  if (data == null || data === "") {
122
- return reject(new RequestError(`${method}:${endpoint}: Request failed [${response.statusCode}].`, response.statusCode));
185
+ return reject(new Paddle.RequestError(`${method}:${endpoint}: Request failed [${response.statusCode}].`, response.statusCode));
123
186
  }
124
187
  try {
125
188
  data = JSON.parse(data);
126
189
  } catch (e) {
127
- return reject(new RequestError(`${method}:${endpoint}: Request failed [${response.statusCode}].`, response.statusCode));
190
+ return reject(new Paddle.RequestError(`${method}:${endpoint}: Request failed [${response.statusCode}].`, response.statusCode));
128
191
  }
129
192
  if (data.error == null) {
130
- return reject(new RequestError(`${method}:${endpoint}: Request failed [${response.statusCode}].`, response.statusCode));
193
+ return reject(new Paddle.RequestError(`${method}:${endpoint}: Request failed [${response.statusCode}].`, response.statusCode));
131
194
  }
132
195
  data = data.error;
133
196
  let errs = "";
@@ -138,24 +201,24 @@ class Paddle {
138
201
  });
139
202
  errs = errs.substr(0, errs.length - 2);
140
203
  }
141
- return reject(new RequestError(`${method}:${endpoint}: ${data.detail} [${response.statusCode}]${errs}.`, response.statusCode));
204
+ return reject(new Paddle.RequestError(`${method}:${endpoint}: ${data.detail} [${response.statusCode}]${errs}.`, response.statusCode));
142
205
  }
143
206
  });
144
207
  });
145
- if (params != null) {
208
+ if (!is_get_like && params != null) {
146
209
  const requestBody = JSON.stringify(params);
147
210
  request.setHeader("Content-Length", Buffer.byteLength(requestBody));
148
211
  request.write(requestBody);
149
212
  }
150
- request.on("error", (error2) => {
151
- reject(error2);
213
+ request.on("error", (error) => {
214
+ reject(error);
152
215
  });
153
216
  request.end();
154
217
  });
155
218
  try {
156
219
  return await promise;
157
220
  } catch (e) {
158
- if (e instanceof Error || e instanceof RequestError) {
221
+ if (e instanceof Error || e instanceof Paddle.RequestError) {
159
222
  throw e;
160
223
  }
161
224
  throw new Error(e);
@@ -165,31 +228,24 @@ class Paddle {
165
228
  // Database (private).
166
229
  // Add or remove a subscription to the user's active subscriptions.
167
230
  async _add_subscription(uid, prod_id, sub_id) {
168
- await this._active_sub_db.save({ uid, prod_id }, { prod_id, sub_id });
231
+ await this._active_sub_db.set({ uid, prod_id }, { prod_id, sub_id });
169
232
  }
170
233
  async _delete_subscription(uid, prod_id) {
171
234
  await this._active_sub_db.delete({ uid, prod_id });
172
235
  }
173
236
  async _check_subscription(uid, prod_id, load_data = false) {
174
- const doc = await this._active_sub_db.load({ uid, prod_id });
175
- let exists = false, sub_id;
176
- if (doc == null) {
177
- if (load_data) {
178
- return { exists, sub_id };
179
- } else {
180
- return exists;
237
+ try {
238
+ const doc = await this._active_sub_db.load({ uid, prod_id });
239
+ return load_data ? { exists: true, sub_id: doc.sub_id } : true;
240
+ } catch (err) {
241
+ if (err instanceof import_collection.Collection.NotFoundError) {
242
+ return load_data ? { exists: false, sub_id: void 0 } : false;
181
243
  }
182
- }
183
- exists = true;
184
- sub_id = doc.sub_id;
185
- if (load_data) {
186
- return { exists, sub_id };
187
- } else {
188
- return exists;
244
+ throw err;
189
245
  }
190
246
  }
191
247
  async _get_active_subscriptions(uid, detailed = false) {
192
- const list = await this._active_sub_db.list_query({ uid });
248
+ const list = await this._active_sub_db.list({ uid });
193
249
  if (detailed) {
194
250
  return list;
195
251
  }
@@ -200,52 +256,40 @@ class Paddle {
200
256
  return products;
201
257
  }
202
258
  async _save_subscription(subscription) {
203
- await this._sub_db.save({
259
+ await this._sub_db.set({
204
260
  uid: subscription.uid == null ? "unauth" : subscription.uid,
205
261
  id: subscription.id
206
262
  }, subscription);
207
263
  }
208
264
  async _load_subscription(id) {
209
- const subscription = await this._sub_db.find({ id });
210
- if (subscription == null) {
211
- throw Error(`Unable to find subscription "${id}".`);
212
- }
213
- return subscription;
265
+ return await this._sub_db.load({ id }, { retry: 3 });
214
266
  }
215
267
  async _get_subscriptions(uid) {
216
268
  if (uid === "unauth" || uid == null) {
217
269
  return [];
218
270
  }
219
- const list = await this._sub_db.list_query({ uid });
271
+ const list = await this._sub_db.list({ uid });
220
272
  return list;
221
273
  }
222
274
  // Save and delete payments, all failed payments should be deleted from the database.
223
275
  async _save_payment(payment) {
224
- await this._pay_db.save({
276
+ await this._pay_db.set({
225
277
  uid: payment.uid == null ? "unauth" : payment.uid,
226
278
  id: payment.id
227
279
  }, payment);
228
280
  }
229
281
  async _load_payment(id) {
230
282
  const uid = id.split("_")[1];
231
- const payment = await this._pay_db.load({ uid, id });
232
- if (payment == null) {
233
- throw Error(`Unable to find payment "${id}".`);
234
- }
235
- if (uid == null || uid == "unauth") {
236
- delete payment.billing_details;
237
- }
238
- return payment;
283
+ return await this._pay_db.load({ uid, id });
239
284
  }
240
- async _load_payment_by_transaction(id) {
241
- const payment = await this._pay_db.find({ tran_id: id });
242
- if (payment == null) {
243
- throw Error(`Unable to find the payment by transaction id "${id}".`);
244
- }
245
- if (payment.uid == null || payment.uid == "unauth") {
246
- delete payment.billing_details;
247
- }
248
- return payment;
285
+ async _load_payment_for_public(id) {
286
+ return Payment.anonymize(await this._load_payment(id));
287
+ }
288
+ async _load_payment_by_transaction(tran_id) {
289
+ return await this._pay_db.load({ tran_id }, { retry: 3 });
290
+ }
291
+ async _load_payment_by_transaction_for_public(tran_id) {
292
+ return Payment.anonymize(await this._load_payment_by_transaction(tran_id));
249
293
  }
250
294
  async _delete_payment(id) {
251
295
  const uid = id.split("_")[1];
@@ -253,13 +297,13 @@ class Paddle {
253
297
  }
254
298
  // Delete all info of a user.
255
299
  async _delete_user(uid) {
256
- await this._sub_db.delete_all({ uid });
257
- await this._active_sub_db.delete_all({ uid });
258
- await this._pay_db.delete_all({ uid });
300
+ await this._sub_db.delete_many({ uid });
301
+ await this._active_sub_db.delete_many({ uid });
302
+ await this._pay_db.delete_many({ uid });
259
303
  }
260
304
  // List all active subscriptions.
261
305
  async _get_all_active_subscriptions() {
262
- return await this._active_sub_db.list_query({});
306
+ return await this._active_sub_db.list_all();
263
307
  }
264
308
  // ---------------------------------------------------------
265
309
  // Overall (private).
@@ -328,8 +372,8 @@ class Paddle {
328
372
  if (process.argv.includes("--no-payment-edits")) {
329
373
  return false;
330
374
  }
331
- if (this._has_create_products_permission) {
332
- return true;
375
+ if (this._has_create_products_permission != null) {
376
+ return this._has_create_products_permission;
333
377
  }
334
378
  const input = await vlib.logging.prompt("Some paddle products have to be edited, do you wish to make these changes? [y/n]: ");
335
379
  if (["y", "yes", "ok"].includes(input.toLowerCase())) {
@@ -348,7 +392,7 @@ class Paddle {
348
392
  if (!await has_create_products_permission()) {
349
393
  return;
350
394
  }
351
- log(0, `Creating product ${product.name}.`);
395
+ this.server.log(0, `Creating product ${product.name}.`);
352
396
  const created_product = await this._req("POST", "/products", {
353
397
  name: product.name,
354
398
  description: product.description,
@@ -357,26 +401,26 @@ class Paddle {
357
401
  custom_data: { id: product.id }
358
402
  });
359
403
  product.paddle_prod_id = created_product.data.id;
360
- log(0, `Creating a price for product ${product.name}.`);
404
+ this.server.log(0, `Creating a price for product ${product.name}.`);
361
405
  const created_price = await this._req("POST", "/prices", {
362
406
  product_id: product.paddle_prod_id,
363
407
  name: product.name,
364
408
  description: product.description,
365
409
  unit_price: { amount: Math.floor(product.price * 100).toString(), currency_code: product.currency },
366
410
  billing_cycle: product.is_subscription ? { interval: product.interval, frequency: product.frequency } : null,
367
- trial_period: product.trial,
411
+ trial_period: product.is_subscription ? product.trial : null,
368
412
  tax_mode: this.inclusive_tax ? "internal" : "external"
369
413
  });
370
414
  product.price_id = created_price.data.id;
371
415
  } else {
372
416
  product.paddle_prod_id = existing_product.id;
373
- const has_trial = product.trial != null;
417
+ const has_trial = product.is_subscription && product.trial != null;
374
418
  const update_product = existing_product.name !== product.name || existing_product.description !== product.description || existing_product.image_url !== product.icon || existing_product.tax_category !== product.tax_category || existing_product.status !== "active";
375
419
  if (update_product) {
376
420
  if (!await has_create_products_permission()) {
377
421
  return;
378
422
  }
379
- log(0, `Updating product ${product.name}.`);
423
+ this.server.log(0, `Updating product ${product.name}.`);
380
424
  await this._req("PATCH", `/products/${product.paddle_prod_id}`, {
381
425
  name: product.name,
382
426
  description: product.description,
@@ -395,14 +439,14 @@ class Paddle {
395
439
  if (!await has_create_products_permission()) {
396
440
  return;
397
441
  }
398
- log(0, `Creating a price for product ${product.name}.`);
442
+ this.server.log(0, `Creating a price for product ${product.name}.`);
399
443
  const price = await this._req("POST", "/prices", {
400
444
  product_id: product.paddle_prod_id,
401
445
  name: product.name,
402
446
  description: product.description,
403
447
  unit_price: { amount: Math.floor(product.price * 100).toString(), currency_code: product.currency },
404
448
  billing_cycle: product.is_subscription ? { interval: product.interval, frequency: product.frequency } : null,
405
- trial_period: product.trial,
449
+ trial_period: product.is_subscription ? product.trial : null,
406
450
  tax_mode: this.inclusive_tax ? "internal" : "external"
407
451
  });
408
452
  product.price_id = price.data.id;
@@ -413,14 +457,14 @@ class Paddle {
413
457
  if (!await has_create_products_permission()) {
414
458
  return;
415
459
  }
416
- log(0, `Updating the price of product ${product.name}.`);
460
+ this.server.log(0, `Updating the price of product ${product.name}.`);
417
461
  await this._req("PATCH", `/prices/${product.price_id}`, {
418
462
  // product_id: product.id, // not allowed.
419
463
  name: product.name,
420
464
  description: product.description,
421
465
  unit_price: { amount: Math.floor(product.price * 100).toString(), currency_code: product.currency },
422
466
  billing_cycle: product.is_subscription ? { interval: product.interval, frequency: product.frequency } : null,
423
- trial_period: product.trial,
467
+ trial_period: product.is_subscription ? product.trial : null,
424
468
  tax_mode: this.inclusive_tax ? "internal" : "external",
425
469
  status: "active"
426
470
  });
@@ -438,7 +482,7 @@ class Paddle {
438
482
  throw Error(`Unable to find subscription "${id}".`);
439
483
  }
440
484
  if (subscription.status !== "active") {
441
- throw new import_utils.ExternalError({
485
+ throw new import_errors.ExternalError({
442
486
  type: "NoActiveSubscriptionError",
443
487
  message: `This subscription is already cancelled and will become inactive at the end of the billing period.`,
444
488
  status: import_status.Status.bad_request
@@ -617,8 +661,8 @@ class Paddle {
617
661
  };
618
662
  let sub_products = 0;
619
663
  this.products.iterate((product) => {
620
- if (product.plans != null) {
621
- if (product.plans != null && Array.isArray(product.plans) === false) {
664
+ if (product.is_subscription) {
665
+ if (!product.plans || !Array.isArray(product.plans)) {
622
666
  throw Error(`Product "${product_index}" has an incorrect value type for attribute "plans", the valid type is "array".`);
623
667
  }
624
668
  product.id = `sub_${sub_products}`;
@@ -651,18 +695,17 @@ class Paddle {
651
695
  }
652
696
  initialize_product(plan);
653
697
  });
654
- } else if (product.frequency != null || product.interval != null) {
655
- throw Error(`Subscription products should be nested as plans of a subscription "{... plans: [...]}". Not as a direct product without a subscription parent.`);
656
698
  } else {
657
699
  product.is_subscription = false;
658
700
  initialize_product(product);
659
701
  }
660
702
  });
661
703
  now = this.performance.end("init-products", now);
662
- const last_products = await this._settings_db.load(`last_products${this.server.production ? "" : "_demo"}`);
663
- if (vlib.Object.eq(last_products, this.products)) {
664
- const product_ids2 = await this._settings_db.load(`product_ids${this.server.production ? "" : "_demo"}`);
665
- product_ids2.iterate((item) => {
704
+ const last_products = await this._last_products_db.load({ production: this.server.production, version: 1 }, { throw: false });
705
+ if (last_products instanceof Error && !(last_products instanceof import_collection.Collection.NotFoundError))
706
+ throw last_products;
707
+ if (!(last_products instanceof import_collection.Collection.NotFoundError) && vlib.Object.eq(last_products.last_products, this.products)) {
708
+ last_products.product_ids.iterate((item) => {
666
709
  const product = this.get_product_sync(item.id);
667
710
  if (product != null) {
668
711
  product.paddle_prod_id = item.paddle_prod_id;
@@ -676,7 +719,7 @@ class Paddle {
676
719
  now = this.performance.end("get-prices-and-products", now);
677
720
  const product_ids2 = [];
678
721
  for (const product of this.products) {
679
- if (product.plans != null) {
722
+ if (product.is_subscription) {
680
723
  for (const plan of product.plans) {
681
724
  await this._check_product(plan, existing_products, existing_prices);
682
725
  product_ids2.append({
@@ -697,73 +740,63 @@ class Paddle {
697
740
  }
698
741
  ;
699
742
  now = this.performance.end("check-products", now);
700
- await this._settings_db.save(`last_products${this.server.production ? "" : "_demo"}`, vlib.Object.delete_recursively(vlib.Object.deep_copy(this.products), ["paddle_prod_id", "price_id"]));
701
- await this._settings_db.save(`product_ids${this.server.production ? "" : "_demo"}`, product_ids2);
743
+ await this._last_products_db.set({ production: this.server.production, version: 1 }, {
744
+ last_products: vlib.Object.delete_recursively(vlib.Object.deep_copy(this.products), ["paddle_prod_id", "price_id"]),
745
+ product_ids: product_ids2
746
+ });
702
747
  now = this.performance.end("save-products-to-db", now);
703
748
  }
704
749
  }
705
750
  // Initialize the payments.
706
751
  async _initialize() {
707
- this.performance.start();
708
- this._settings_db = await this.server.db.collection({
709
- name: "Volt.Paddle.Settings",
710
- indexes: ["_path"]
711
- });
712
- this._sub_db = await this.server.db.collection({
713
- name: "Volt.Paddle.Subscriptions",
714
- indexes: ["uid", "id"]
715
- });
716
- this._active_sub_db = await this.server.db.collection({
717
- name: "Volt.Paddle.ActiveSubscriptions",
718
- indexes: ["uid", "prod_id"]
719
- });
720
- this._pay_db = await this.server.db.collection({
721
- name: "Volt.Paddle.Payments",
722
- indexes: ["uid", "id", "tran_id"]
723
- });
724
- this.performance.end("init-db");
725
752
  await this._initialize_products();
726
753
  let now = this.performance.start();
727
754
  this.server.endpoint({
728
755
  method: "POST",
729
- endpoint: "/volt/payments/init",
756
+ endpoint: "/volt/api/v1/payments/init",
730
757
  content_type: "application/json",
731
758
  rate_limit: "global",
732
759
  params: {
733
- items: "array"
760
+ items: { type: "array", required: true, value_schema: "object" }
761
+ // add schema for items
734
762
  },
735
763
  callback: async (stream, params) => {
736
764
  if (params.items.length === 0) {
737
- return stream.error({ status: import_status.Status.bad_request, data: { error: "Shopping cart is empty." } });
765
+ return stream.error({ status: import_status.Status.bad_request, message: "Shopping cart is empty." });
738
766
  }
739
767
  let sub_plan_count = {};
740
- const error2 = await params.items.iterate_async_await(async (item) => {
768
+ let error = void 0;
769
+ for (const item of params.items) {
741
770
  if (item.product.is_subscription) {
742
771
  if (stream.uid == null) {
743
- return "You must be signed-in to purchase a subscription.";
772
+ error = "You must be signed-in to purchase a subscription.";
773
+ break;
744
774
  }
745
775
  if (item.quantity != null && item.quantity > 1) {
746
- return "Subscriptions have a max quantity of 1.";
776
+ error = "Subscriptions have a max quantity of 1.";
777
+ break;
747
778
  }
748
779
  if (sub_plan_count[item.product.subscription_id] == null) {
749
780
  sub_plan_count[item.product.subscription_id] = 1;
750
781
  } else {
751
- return "You can not charge two different subscription plans from the same subscription product.";
782
+ error = "You can not charge two different subscription plans from the same subscription product.";
783
+ break;
752
784
  }
753
785
  if (await this._check_subscription(stream.uid, item.product.id, false)) {
754
- return `You are already subscribed to product "${item.product.name}".`;
786
+ error = `You are already subscribed to product "${item.product.name}".`;
787
+ break;
755
788
  }
756
789
  }
757
- });
758
- if (error2) {
759
- return stream.error({ status: import_status.Status.bad_request, data: { error: error2 } });
790
+ }
791
+ if (error) {
792
+ return stream.error({ status: import_status.Status.bad_request, message: error });
760
793
  }
761
794
  return stream.success({ data: { message: "Successfully initialized the order." } });
762
795
  }
763
796
  });
764
797
  this.server.endpoint({
765
798
  method: "GET",
766
- endpoint: "/volt/payments/products",
799
+ endpoint: "/volt/api/v1/payments/products",
767
800
  content_type: "application/json",
768
801
  rate_limit: "global",
769
802
  callback: (stream) => {
@@ -772,113 +805,125 @@ class Paddle {
772
805
  });
773
806
  this.server.endpoint({
774
807
  method: "GET",
775
- endpoint: "/volt/payments/payment",
808
+ endpoint: "/volt/api/v1/payments/payment",
776
809
  content_type: "application/json",
777
810
  rate_limit: "global",
778
811
  params: {
779
812
  id: "string"
780
813
  },
781
814
  callback: async (stream, params) => {
782
- return stream.success({ data: await this._load_payment(params.id) });
815
+ return stream.success({
816
+ data: await this._load_payment_for_public(params.id)
817
+ });
783
818
  }
784
819
  });
785
820
  this.server.endpoint({
786
821
  method: "GET",
787
- endpoint: "/volt/payments/payments",
822
+ endpoint: "/volt/api/v1/payments/payments",
788
823
  content_type: "application/json",
789
824
  authenticated: true,
790
825
  rate_limit: "global",
791
826
  params: {
792
827
  days: { type: "number", default: 30 },
793
- limit: { type: "number", default: null },
794
- status: { type: "string", default: null }
828
+ limit: { type: "number", required: false },
829
+ status: { type: "string", required: false, enum: PaymentStatusValues }
795
830
  },
796
831
  callback: async (stream, params) => {
797
- const result = await this.get_payments({
798
- uid: stream.uid,
799
- days: params.days,
800
- limit: params.limit,
801
- status: params.status
832
+ return stream.success({
833
+ data: await this.get_payments({
834
+ uid: stream.uid,
835
+ days: params.days,
836
+ limit: params.limit,
837
+ status: params.status
838
+ })
802
839
  });
803
- return stream.success({ data: result });
804
840
  }
805
841
  });
806
842
  this.server.endpoint({
807
843
  method: "GET",
808
- endpoint: "/volt/payments/payments/refundable",
844
+ endpoint: "/volt/api/v1/payments/payments/refundable",
809
845
  content_type: "application/json",
810
846
  authenticated: true,
811
847
  rate_limit: "global",
812
848
  params: {
813
849
  days: { type: "number", default: 30 },
814
- limit: { type: ["null", "number"], default: null },
815
- status: { type: ["null", "string"], default: null }
850
+ limit: { type: "number", required: false }
816
851
  },
817
852
  callback: async (stream, params) => {
818
- const result = await this.get_refundable_payments({
819
- uid: stream.uid,
820
- days: params.days,
821
- limit: params.limit
853
+ return stream.success({
854
+ data: await this.get_refundable_payments({
855
+ uid: stream.uid,
856
+ days: params.days,
857
+ limit: params.limit,
858
+ for_public: true
859
+ })
822
860
  });
823
- return stream.success({ data: result });
824
861
  }
825
862
  });
826
863
  this.server.endpoint({
827
864
  method: "GET",
828
- endpoint: "/volt/payments/payments/refunded",
865
+ endpoint: "/volt/api/v1/payments/payments/refunded",
829
866
  content_type: "application/json",
830
867
  authenticated: true,
831
868
  rate_limit: "global",
832
869
  params: {
833
870
  days: { type: "number", default: 30 },
834
- limit: { type: ["null", "number"], default: null }
871
+ limit: { type: "number", required: false }
835
872
  },
836
873
  callback: async (stream, params) => {
837
- const result = await this.get_refunded_payments({
838
- uid: stream.uid,
839
- days: params.days,
840
- limit: params.limit
874
+ return stream.success({
875
+ data: await this.get_refunded_payments({
876
+ uid: stream.uid,
877
+ days: params.days,
878
+ limit: params.limit,
879
+ for_public: true
880
+ })
841
881
  });
842
- return stream.success({ data: result });
843
882
  }
844
883
  });
845
884
  this.server.endpoint({
846
885
  method: "GET",
847
- endpoint: "/volt/payments/payments/refunding",
886
+ endpoint: "/volt/api/v1/payments/payments/refunding",
848
887
  content_type: "application/json",
849
888
  authenticated: true,
850
889
  rate_limit: "global",
851
890
  params: {
852
- days: { type: ["null", "number"], default: null },
853
- limit: { type: ["null", "number"], default: null }
891
+ days: { type: "number", default: 30 },
892
+ limit: { type: "number", required: false }
854
893
  },
855
894
  callback: async (stream, params) => {
856
- const result = await this.get_refunding_payments({
857
- uid: stream.uid,
858
- days: params.days,
859
- limit: params.limit
895
+ return stream.success({
896
+ data: await this.get_refunding_payments({
897
+ uid: stream.uid,
898
+ days: params.days,
899
+ limit: params.limit,
900
+ for_public: true
901
+ })
860
902
  });
861
- return stream.success({ data: result });
862
903
  }
863
904
  });
864
905
  this.server.endpoint({
865
906
  method: "POST",
866
- endpoint: "/volt/payments/refund",
907
+ endpoint: "/volt/api/v1/payments/refund",
867
908
  content_type: "application/json",
909
+ authenticated: true,
868
910
  rate_limit: "global",
869
911
  params: {
870
- payment: { type: ["string", "object"] },
871
- line_items: { type: ["array", "null"], default: null },
912
+ payment: { type: ["string", "object"], schema: { id: "string" } },
913
+ line_items: { type: "array", required: false, value_schema: {
914
+ type: "object",
915
+ schema: LineItem.Schema
916
+ } },
872
917
  reason: { type: "string", default: "refund" }
873
918
  },
874
919
  callback: async (stream, params) => {
875
- await this.create_refund(params.payment, params.line_items, params.reason);
920
+ await this.create_refund(typeof params.payment === "string" ? params.payment : params.payment.id, params.line_items, params.reason);
876
921
  return stream.success();
877
922
  }
878
923
  });
879
924
  this.server.endpoint({
880
925
  method: "DELETE",
881
- endpoint: "/volt/payments/subscription",
926
+ endpoint: "/volt/api/v1/payments/subscription",
882
927
  content_type: "application/json",
883
928
  authenticated: true,
884
929
  rate_limit: "global",
@@ -892,19 +937,21 @@ class Paddle {
892
937
  });
893
938
  this.server.endpoint({
894
939
  method: "GET",
895
- endpoint: "/volt/payments/active_subscriptions",
940
+ endpoint: "/volt/api/v1/payments/active_subscriptions",
896
941
  content_type: "application/json",
897
942
  authenticated: true,
898
943
  rate_limit: "global",
899
- callback: async (stream, params) => {
944
+ callback: async (stream) => {
900
945
  return stream.success({
901
- data: { subscriptions: await this.get_active_subscriptions(stream.uid) }
946
+ data: {
947
+ subscriptions: await this.get_active_subscriptions(stream.uid)
948
+ }
902
949
  });
903
950
  }
904
951
  });
905
952
  this.server.endpoint({
906
953
  method: "GET",
907
- endpoint: "/volt/payments/subscribed",
954
+ endpoint: "/volt/api/v1/payments/subscribed",
908
955
  content_type: "application/json",
909
956
  authenticated: true,
910
957
  rate_limit: "global",
@@ -913,7 +960,9 @@ class Paddle {
913
960
  },
914
961
  callback: async (stream, params) => {
915
962
  return stream.success({
916
- data: { is_subscribed: await this.is_subscribed(stream.uid, params.product) }
963
+ data: {
964
+ is_subscribed: await this.is_subscribed(stream.uid, params.product)
965
+ }
917
966
  });
918
967
  }
919
968
  });
@@ -932,8 +981,8 @@ class Paddle {
932
981
  if (res instanceof Promise) {
933
982
  res = await res;
934
983
  }
935
- } catch (error2) {
936
- console.error(error2);
984
+ } catch (error) {
985
+ console.error(error);
937
986
  }
938
987
  }
939
988
  }
@@ -948,7 +997,7 @@ class Paddle {
948
997
  // }
949
998
  // On a successfull payment webhook event.
950
999
  async _payment_webhook(data) {
951
- let obj = (await this._req("GET", `/transactions/${data.id}`, { include: ["address", "adjustment", "business", "customer"] })).data;
1000
+ let obj = (await this._req("GET", `/transactions/${data.id}`, { include: ["address", "adjustments", "business", "customer"] })).data;
952
1001
  const id = `pay_${obj.custom_data.uid == null ? "unauth" : obj.custom_data.uid}_${vlib.String.random(4)}${Date.now()}`;
953
1002
  const payment = {
954
1003
  id,
@@ -1029,7 +1078,7 @@ class Paddle {
1029
1078
  payment.status = "past_due";
1030
1079
  break;
1031
1080
  default:
1032
- error(`Payment Webhook: Unknown payment status "${obj.status}".`);
1081
+ this.server.log.error(`Payment Webhook: Unknown payment status "${obj.status}".`);
1033
1082
  payment.status = "unknown";
1034
1083
  break;
1035
1084
  }
@@ -1043,13 +1092,13 @@ class Paddle {
1043
1092
  // paddle product id.
1044
1093
  quantity: item.quantity,
1045
1094
  tax_rate: parseFloat(item.tax_rate),
1046
- tax: parseFloat(item.totals.tax / 100),
1095
+ tax: item.totals.tax / 100,
1047
1096
  // should not be changed to unit totals, since mails and invoices depend on this behaviour, just divide by quantity.
1048
- discount: parseFloat(item.totals.discount / 100),
1097
+ discount: item.totals.discount / 100,
1049
1098
  // should not be changed to unit totals, since mails and invoices depend on this behaviour, just divide by quantity.
1050
- subtotal: parseFloat(item.totals.subtotal / 100),
1099
+ subtotal: item.totals.subtotal / 100,
1051
1100
  // should not be changed to unit totals, since mails and invoices depend on this behaviour, just divide by quantity.
1052
- total: parseFloat(item.totals.total / 100),
1101
+ total: item.totals.total / 100,
1053
1102
  // should not be changed to unit totals, since mails and invoices depend on this behaviour, just divide by quantity.
1054
1103
  status: "paid"
1055
1104
  // can be "paid", "refunded", "refunding".
@@ -1059,8 +1108,7 @@ class Paddle {
1059
1108
  obj.adustments.iterate((adj) => {
1060
1109
  switch (adj.action) {
1061
1110
  case "refund":
1062
- case "cargeback":
1063
- case "cargeback_warning":
1111
+ case "chargeback":
1064
1112
  adj.items.iterate((adj_item) => {
1065
1113
  payment.line_items.iterate((item) => {
1066
1114
  if (adj_item.item_id === item.item_id) {
@@ -1070,24 +1118,34 @@ class Paddle {
1070
1118
  });
1071
1119
  });
1072
1120
  break;
1121
+ case "chargeback_reversal":
1122
+ adj.items.iterate((adj_item) => {
1123
+ payment.line_items.iterate((item) => {
1124
+ if (adj_item.item_id === item.item_id) {
1125
+ item.status = "paid";
1126
+ return false;
1127
+ }
1128
+ });
1129
+ });
1130
+ break;
1073
1131
  default:
1074
1132
  break;
1075
1133
  }
1076
1134
  });
1077
1135
  }
1078
1136
  await this._save_payment(payment);
1079
- const { uid, cus_id } = payment;
1080
- for (const item of await payment.line_items) {
1137
+ const { uid } = payment;
1138
+ for (const item of payment.line_items) {
1081
1139
  const product = this.get_product_sync(item.product, false);
1082
1140
  if (product == null) {
1083
1141
  continue;
1084
1142
  } else if (product.is_subscription) {
1085
1143
  const subscription = await this.get_product(product.subscription_id, true);
1086
- for (const plan of subscription.plans ?? []) {
1144
+ for (const plan of subscription?.plans ?? []) {
1087
1145
  if (plan.id != product.id) {
1088
1146
  const { exists, sub_id } = await this._check_subscription(uid, plan.id);
1089
1147
  if (exists) {
1090
- log(0, `Cancelling subscription "${plan.id}" due too downgrade/upgrade to "${product.id}" of user "${payment.uid}".`);
1148
+ this.server.log(0, `Cancelling subscription "${plan.id}" due too downgrade/upgrade to "${product.id}" of user "${payment.uid}".`);
1091
1149
  await this._cancel_subscription(sub_id);
1092
1150
  }
1093
1151
  }
@@ -1113,11 +1171,11 @@ class Paddle {
1113
1171
  for (const item of data.items) {
1114
1172
  const product = this._get_product_by_paddle_prod_id(item.price.product_id, false);
1115
1173
  if (product == null) {
1116
- error(`Subscription webhook [#sub1]: Unable to find product with id ${item.price.product_id}. This is a serious error which causes a non activated subscription for a paid transaction. You should manually cancel the subscription. Event: ${JSON.stringify(data, null, 4)}.`);
1174
+ this.server.log.error(`Subscription webhook [#sub1]: Unable to find product with id ${item.price.product_id}. This is a serious error which causes a non activated subscription for a paid transaction. You should manually cancel the subscription. Event: ${JSON.stringify(data, null, 4)}.`);
1117
1175
  continue;
1118
1176
  } else if (product.is_subscription) {
1119
1177
  subscription.plans.append(product.id);
1120
- log(0, `Activating subscription "${product.id}" of user "${subscription.uid}".`);
1178
+ this.server.log(0, `Activating subscription "${product.id}" of user "${subscription.uid}".`);
1121
1179
  await this._add_subscription(uid, product.id, subscription.id);
1122
1180
  await this._exec_user_callback(this.server.on_subscription, { product, subscription });
1123
1181
  }
@@ -1129,7 +1187,7 @@ class Paddle {
1129
1187
  const subscription = await this._load_subscription(data.id);
1130
1188
  for (const plan_id of subscription.plans) {
1131
1189
  await this._delete_subscription(subscription.uid, plan_id);
1132
- log(0, `Deactivating subscription "${plan_id}" of user "${subscription.uid}".`);
1190
+ this.server.log(0, `Deactivating subscription "${plan_id}" of user "${subscription.uid}".`);
1133
1191
  }
1134
1192
  subscription.status = "cancelled";
1135
1193
  await this._save_subscription(subscription);
@@ -1163,16 +1221,16 @@ class Paddle {
1163
1221
  await this._save_payment(payment);
1164
1222
  }
1165
1223
  if (is_approved) {
1166
- log(0, `Refunded items of payment "${payment.id}" of user "${payment.uid}".`);
1224
+ this.server.log(0, `Refunded items of payment "${payment.id}" of user "${payment.uid}".`);
1167
1225
  await this._exec_user_callback(is_refund ? this.server.on_refund : this.server.on_chargeback, { payment, line_items });
1168
1226
  } else {
1169
- log(0, `Refund denied for items of payment ${payment.id} of user "${payment.uid}".`);
1227
+ this.server.log(0, `Refund denied for items of payment ${payment.id} of user "${payment.uid}".`);
1170
1228
  await this._exec_user_callback(is_refund ? this.server.on_failed_refund : this.server.on_failed_chargeback, { payment, line_items });
1171
1229
  }
1172
1230
  } else if (data.action === "chargeback_reverse" && data.status === "reversed") {
1173
1231
  const payment = await this._load_payment_by_transaction(data.transaction_id);
1174
1232
  if (payment.sub_id != null) {
1175
- log(0, `Chargeback reversed for payment ${payment.id} from user "${payment.uid}".`);
1233
+ this.server.log(0, `Chargeback reversed for payment ${payment.id} from user "${payment.uid}".`);
1176
1234
  }
1177
1235
  let line_items = [];
1178
1236
  data.items.iterate((adj_item) => {
@@ -1190,7 +1248,7 @@ class Paddle {
1190
1248
  }
1191
1249
  // Create and register the webhook endpoint.
1192
1250
  async _create_webhook() {
1193
- const webhook_doc = await this._settings_db.load(`webhook${this.server.production ? "" : "_demo"}`);
1251
+ const now = this.performance.start();
1194
1252
  const webhook_settings = {
1195
1253
  description: "volt webhook",
1196
1254
  destination: `${this.server.full_domain}/volt/payments/webhook`,
@@ -1217,58 +1275,72 @@ class Paddle {
1217
1275
  "adjustment.updated"
1218
1276
  ]
1219
1277
  };
1278
+ const hashed_webhook_settings = this.server.hash(webhook_settings);
1220
1279
  const register_webhook = async () => {
1221
- log(0, "Registering payments webhook.");
1280
+ this.server.log(0, "Registering payments webhook.");
1222
1281
  const response = await this._req("POST", "/notification-settings", webhook_settings);
1223
1282
  this.webhook_key = response.data.endpoint_secret_key;
1224
- await this._settings_db.save(`webhook${this.server.production ? "" : "_demo"}`, {
1283
+ await this._webhook_conf_db.set({ production: this.server.production, version: 1 }, {
1225
1284
  id: response.data.id,
1226
- key: this.webhook_key
1285
+ key: this.webhook_key,
1286
+ hash: this.server.hash(webhook_settings)
1227
1287
  });
1228
1288
  };
1229
- if (webhook_doc != null) {
1230
- this.webhook_key = webhook_doc.key;
1231
- const last_webhook = await this._settings_db.load(`last_webhook${this.server.production ? "" : "_demo"}`);
1232
- if (last_webhook !== this.server.hash(webhook_settings)) {
1233
- log(0, `Checking payments webhook.`);
1234
- const webhook_id = webhook_doc.id;
1235
- let registered;
1236
- try {
1237
- registered = await this._req("GET", `/notification-settings/${webhook_id}`);
1238
- } catch (error2) {
1239
- if (error2.status === 404 || error2.status_code === 404) {
1240
- registered = void 0;
1241
- await register_webhook();
1242
- } else {
1243
- throw error2;
1244
- }
1245
- }
1246
- if (registered) {
1247
- const item = registered.data;
1248
- const patch = (() => {
1249
- if (item.active !== true || item.destination !== webhook_settings.destination || item.type !== webhook_settings.type || item.description !== webhook_settings.description || item.subscribed_events.length != webhook_settings.subscribed_events.length) {
1250
- return true;
1289
+ const home_dir = vlib.Path.home().join(".volt/cache");
1290
+ if (!home_dir.exists()) {
1291
+ home_dir.mkdir({ recursive: true });
1292
+ }
1293
+ const cached_local_hash_file = home_dir.join(`paddle_webhook_${this.server.production ? "live" : "sandbox"}.hash`);
1294
+ const cached_local_hash = cached_local_hash_file.exists() ? await cached_local_hash_file.load() : null;
1295
+ if (cached_local_hash !== hashed_webhook_settings) {
1296
+ const webhook_doc = await this._webhook_conf_db.load({ production: this.server.production, version: 1 }, { throw: false });
1297
+ if (webhook_doc instanceof Error && !(webhook_doc instanceof import_collection.Collection.NotFoundError)) {
1298
+ throw webhook_doc;
1299
+ }
1300
+ if (!(webhook_doc instanceof import_collection.Collection.NotFoundError)) {
1301
+ this.webhook_key = webhook_doc.key;
1302
+ if (webhook_doc.hash !== hashed_webhook_settings) {
1303
+ this.server.log(0, `Checking payments webhook.`);
1304
+ const webhook_id = webhook_doc.id;
1305
+ let registered;
1306
+ try {
1307
+ registered = await this._req("GET", `/notification-settings/${webhook_id}`);
1308
+ } catch (error) {
1309
+ if (error.status === 404 || error.status_code === 404) {
1310
+ registered = void 0;
1311
+ await register_webhook();
1312
+ } else {
1313
+ throw error;
1251
1314
  }
1252
- return webhook_settings.subscribed_events.iterate((x) => {
1253
- const found = item.subscribed_events.iterate((y) => {
1254
- if (x === y.name) {
1315
+ }
1316
+ if (registered) {
1317
+ const item = registered.data;
1318
+ const patch = (() => {
1319
+ if (item.active !== true || item.destination !== webhook_settings.destination || item.type !== webhook_settings.type || item.description !== webhook_settings.description || item.subscribed_events.length != webhook_settings.subscribed_events.length) {
1320
+ return true;
1321
+ }
1322
+ return webhook_settings.subscribed_events.iterate((x) => {
1323
+ const found = item.subscribed_events.iterate((y) => {
1324
+ if (x === y.name) {
1325
+ return true;
1326
+ }
1327
+ });
1328
+ if (found === false) {
1255
1329
  return true;
1256
1330
  }
1257
1331
  });
1258
- if (found === false) {
1259
- return true;
1260
- }
1261
- });
1262
- })();
1263
- if (patch === true) {
1264
- log(0, "Updating payments webhook.");
1265
- await this._req("PATCH", `/notification-settings/${webhook_id}`, { ...webhook_settings, active: true });
1332
+ })();
1333
+ if (patch === true) {
1334
+ this.server.log(0, "Updating payments webhook.");
1335
+ await this._req("PATCH", `/notification-settings/${webhook_id}`, { ...webhook_settings, active: true });
1336
+ }
1337
+ await this._webhook_conf_db.set({ production: this.server.production, version: 1 }, { hash: this.server.hash(webhook_settings) });
1266
1338
  }
1267
- await this._settings_db.save(`last_webhook${this.server.production ? "" : "_demo"}`, this.server.hash(webhook_settings));
1268
1339
  }
1340
+ } else {
1341
+ await register_webhook();
1269
1342
  }
1270
- } else {
1271
- await register_webhook();
1343
+ await cached_local_hash_file.save(hashed_webhook_settings);
1272
1344
  }
1273
1345
  const ip_whitelist = [
1274
1346
  // Live.
@@ -1286,19 +1358,20 @@ class Paddle {
1286
1358
  "44.241.183.62",
1287
1359
  "100.20.172.113"
1288
1360
  ];
1361
+ this.server.performance.end("create-payments-webhook", now);
1289
1362
  return {
1290
1363
  method: "POST",
1291
- endpoint: "/volt/payments/webhook",
1364
+ endpoint: "/volt/api/v1/payments/webhook",
1292
1365
  content_type: "application/json",
1293
1366
  rate_limit: void 0,
1294
1367
  callback: async (stream) => {
1295
1368
  if (ip_whitelist.includes(stream.ip) === false) {
1296
- log(0, `POST:/volt/payments/webhook: Warning: Blocking non whitelisted ip "${stream.ip}".`);
1369
+ this.server.log(0, `POST:/volt/payments/webhook: Warning: Blocking non whitelisted ip "${stream.ip}".`);
1297
1370
  return stream.error({ status: import_status.Status.unauthorized });
1298
1371
  }
1299
1372
  const full_signature = stream.headers["paddle-signature"];
1300
1373
  if (full_signature == null) {
1301
- log(0, "POST:/volt/payments/webhook: Error: No paddle signature found in the request headers.");
1374
+ this.server.log(0, "POST:/volt/payments/webhook: Error: No paddle signature found in the request headers.");
1302
1375
  return stream.error({ status: import_status.Status.unauthorized, data: { error: "Webhook signature verification failed." } });
1303
1376
  }
1304
1377
  const ts_index = full_signature.indexOf(";");
@@ -1306,7 +1379,7 @@ class Paddle {
1306
1379
  const signature = full_signature.substr(ts_index + 4);
1307
1380
  const digest = libcrypto.createHmac("sha256", this.webhook_key).update(`${ts}:${stream.body}`).digest("hex");
1308
1381
  if (libcrypto.timingSafeEqual(Buffer.from(digest, "hex"), Buffer.from(signature, "hex")) !== true) {
1309
- log(0, "POST:/volt/payments/webhook: Error: Webhook signature verification failed.");
1382
+ this.server.log(0, "POST:/volt/payments/webhook: Error: Webhook signature verification failed.");
1310
1383
  return stream.error({ status: import_status.Status.unauthorized, data: { error: "Webhook signature verification failed." } });
1311
1384
  }
1312
1385
  const event = JSON.parse(stream.body);
@@ -1365,7 +1438,6 @@ class Paddle {
1365
1438
  }
1366
1439
  return product;
1367
1440
  }
1368
- // Get a payment by id.
1369
1441
  /* @docs:
1370
1442
  @title: Get Payment.
1371
1443
  @desc: Get a payment by id.
@@ -1375,10 +1447,12 @@ class Paddle {
1375
1447
  @type: string
1376
1448
  @desc: The id of the payment.
1377
1449
  */
1378
- async get_payment(id) {
1450
+ async get_payment(id, opts) {
1451
+ if (opts?.for_public) {
1452
+ return await this._load_payment_for_public(id);
1453
+ }
1379
1454
  return await this._load_payment(id);
1380
1455
  }
1381
- // Get payments.
1382
1456
  /* @docs:
1383
1457
  @title: Get Refunded Payments.
1384
1458
  @desc:
@@ -1407,30 +1481,24 @@ class Paddle {
1407
1481
  @value: "paid"
1408
1482
  @desc: Payments that are paid.
1409
1483
  */
1410
- async get_payments({ uid, days = 30, limit = void 0, status = void 0 }) {
1411
- const list = await this._pay_db.list_query({ uid });
1412
- let since = null;
1484
+ async get_payments({ uid, days = 30, limit = 1e4, status = void 0, for_public }) {
1485
+ const query = {
1486
+ uid
1487
+ };
1413
1488
  if (days != null) {
1414
- since = /* @__PURE__ */ new Date();
1489
+ const since = /* @__PURE__ */ new Date();
1415
1490
  since.setHours(0, 0, 0, 0);
1416
- since = Math.floor(since.getTime() - 3600 * 24 * 1e3 * days);
1491
+ query.timestamp = { $gte: Math.floor(since.getTime() - 3600 * 24 * 1e3 * days) };
1417
1492
  }
1418
- const payments = [];
1419
- const status_is_array = Array.isArray(status);
1420
- list.iterate((payment) => {
1421
- if (since == null || payment.timestamp >= since) {
1422
- if (status == null || status_is_array === false && status === payment.status || status_is_array && status.includes(payment.status)) {
1423
- payments.append(payment);
1424
- }
1425
- }
1426
- if (limit != null && limit != -1 && payments.length >= limit) {
1427
- return false;
1428
- }
1429
- });
1493
+ if (Array.isArray(status)) {
1494
+ query.status = { $in: status };
1495
+ } else if (typeof status === "string") {
1496
+ query.status = status;
1497
+ }
1498
+ const payments = await this._pay_db.list(query, { limit });
1430
1499
  payments.sort((a, b) => b.timestamp - a.timestamp);
1431
- return payments;
1500
+ return for_public ? payments.map((p) => Payment.anonymize(p)) : payments;
1432
1501
  }
1433
- // Get all refundable payments.
1434
1502
  /* @docs:
1435
1503
  @title: Get Refundable Payments.
1436
1504
  @desc: Get all payments that are refundable.
@@ -1446,24 +1514,17 @@ class Paddle {
1446
1514
  @type: number
1447
1515
  @desc: Limit the amount of response payment objects.
1448
1516
  */
1449
- async get_refundable_payments({ uid, days = 30, limit = void 0 }) {
1450
- const payments = [];
1451
- const all_payments = await this.get_payments({ uid, days, limit, status: "paid" });
1452
- all_payments.iterate((payment) => {
1453
- const line_items = [];
1454
- payment.line_items.iterate((item) => {
1455
- if (item.status === "paid" && item.total > 0) {
1456
- line_items.push(item);
1457
- }
1458
- });
1459
- if (line_items.length > 0) {
1460
- payment.line_items = line_items;
1461
- payments.push(payment);
1517
+ async get_refundable_payments({ uid, days = 30, limit = void 0, for_public }) {
1518
+ const out = [];
1519
+ const all_payments = await this.get_payments({ uid, days, limit, status: "paid", for_public });
1520
+ all_payments.iterate((pmt) => {
1521
+ const refundable = pmt.line_items.filter((li) => li.status === "paid" && li.total > 0);
1522
+ if (refundable.length > 0) {
1523
+ out.push({ ...pmt, line_items: refundable });
1462
1524
  }
1463
1525
  });
1464
- return payments;
1526
+ return out;
1465
1527
  }
1466
- // Get all refunded payments.
1467
1528
  /* @docs:
1468
1529
  @title: Get Refunded Payments.
1469
1530
  @desc: Get all payments that are successfully refunded.
@@ -1479,24 +1540,17 @@ class Paddle {
1479
1540
  @type: number
1480
1541
  @desc: Limit the amount of response payment objects.
1481
1542
  */
1482
- async get_refunded_payments({ uid, days = 30, limit = void 0 }) {
1483
- const payments = [];
1484
- const all_payments = await this.get_payments({ uid, days, limit, status: "paid" });
1485
- all_payments.iterate((payment) => {
1486
- const line_items = [];
1487
- payment.line_items.iterate((item) => {
1488
- if (item.status === "refunded") {
1489
- line_items.push(item);
1490
- }
1491
- });
1492
- if (line_items.length > 0) {
1493
- payment.line_items = line_items;
1494
- payments.push(payment);
1543
+ async get_refunded_payments({ uid, days = 30, limit = void 0, for_public }) {
1544
+ const out = [];
1545
+ const all_payments = await this.get_payments({ uid, days, limit, status: "paid", for_public });
1546
+ all_payments.iterate((pmt) => {
1547
+ const refundable = pmt.line_items.filter((li) => li.status === "refunded" && li.total > 0);
1548
+ if (refundable.length > 0) {
1549
+ out.push({ ...pmt, line_items: refundable });
1495
1550
  }
1496
1551
  });
1497
- return payments;
1552
+ return out;
1498
1553
  }
1499
- // Get all payments that are currently in the refunding process.
1500
1554
  /* @docs:
1501
1555
  @title: Get Refunding Payments.
1502
1556
  @desc: Get all payments that are currently in the refunding process.
@@ -1512,24 +1566,17 @@ class Paddle {
1512
1566
  @type: number
1513
1567
  @desc: Limit the amount of response payment objects.
1514
1568
  */
1515
- async get_refunding_payments({ uid, days = void 0, limit = void 0 }) {
1516
- const payments = [];
1517
- const all_payments = await this.get_payments({ uid, days, limit, status: "paid" });
1518
- all_payments.iterate((payment) => {
1519
- const line_items = [];
1520
- payment.line_items.iterate((item) => {
1521
- if (item.status === "refunding") {
1522
- line_items.push(item);
1523
- }
1524
- });
1525
- if (line_items.length > 0) {
1526
- payment.line_items = line_items;
1527
- payments.push(payment);
1569
+ async get_refunding_payments({ uid, days = void 0, limit = void 0, for_public }) {
1570
+ const out = [];
1571
+ const all_payments = await this.get_payments({ uid, days, limit, status: "paid", for_public });
1572
+ all_payments.iterate((pmt) => {
1573
+ const refundable = pmt.line_items.filter((li) => li.status === "refunding" && li.total > 0);
1574
+ if (refundable.length > 0) {
1575
+ out.push({ ...pmt, line_items: refundable });
1528
1576
  }
1529
1577
  });
1530
- return payments;
1578
+ return out;
1531
1579
  }
1532
- // Refund a payment.
1533
1580
  /* @docs:
1534
1581
  @title: Refund Payment.
1535
1582
  @desc: Refund a payment based on the payment id.
@@ -1602,7 +1649,6 @@ class Paddle {
1602
1649
  }
1603
1650
  await this._save_payment(payment);
1604
1651
  }
1605
- // Cancel a subscription.
1606
1652
  /* @docs:
1607
1653
  @title: Cancel Subscription.
1608
1654
  @desc: Cancel a subscription based on the retrieved payment object or id.
@@ -1636,14 +1682,13 @@ class Paddle {
1636
1682
  }
1637
1683
  ;
1638
1684
  if (_throw_no_cancelled_err && cancelled.length === 0) {
1639
- throw new import_utils.ExternalError({
1685
+ throw new import_errors.ExternalError({
1640
1686
  type: "NoCancellableSubscriptions",
1641
1687
  message: "No cancellable subscriptions found.",
1642
1688
  status: import_status.Status.bad_request
1643
1689
  });
1644
1690
  }
1645
1691
  }
1646
- // Cancel subscription by subscription id.
1647
1692
  /* @docs:
1648
1693
  @title: Cancel subscription by subscription id.
1649
1694
  @desc: Cancel a subscription based on the retrieved subscription object or id.
@@ -1664,7 +1709,6 @@ class Paddle {
1664
1709
  }
1665
1710
  return await this._cancel_subscription(subscription, immediate);
1666
1711
  }
1667
- // Get subscriptioms.
1668
1712
  /* @docs:
1669
1713
  @title: Get active subscriptions
1670
1714
  @desc: Get the active subscriptions of a user.
@@ -1685,7 +1729,6 @@ class Paddle {
1685
1729
  async get_subscriptions(uid) {
1686
1730
  return await this._get_subscriptions(uid);
1687
1731
  }
1688
- // Is subscribed.
1689
1732
  /* @docs:
1690
1733
  @title: Is Subscribed
1691
1734
  @desc: Check if a user is subscribed to a product.
@@ -1701,7 +1744,6 @@ class Paddle {
1701
1744
  async is_subscribed(uid, product) {
1702
1745
  return await this._check_subscription(uid, product, false);
1703
1746
  }
1704
- // Generate an invoice.
1705
1747
  /* @docs:
1706
1748
  @title: Generate Invoice
1707
1749
  @desc:
@@ -1882,16 +1924,12 @@ class Paddle {
1882
1924
  doc.font("Helvetica-Bold");
1883
1925
  gen_line_item({ unit_cost: "Total Due:", total_cost: `${currency} ${total_due.toFixed(2)}` });
1884
1926
  top_offset -= spacing - 3;
1885
- const stream = doc.pipe((0, import_blob_stream.default)());
1886
- doc.end();
1887
- return new Promise((resolve, reject) => {
1888
- stream.on("finish", () => {
1889
- const bytes = stream.toBuffer();
1890
- resolve(bytes);
1891
- });
1892
- stream.on("error", (error2) => {
1893
- reject(error2);
1894
- });
1927
+ const chunks = [];
1928
+ return await new Promise((resolve, reject) => {
1929
+ doc.on("data", (chunk) => chunks.push(chunk));
1930
+ doc.on("end", () => resolve(Buffer.concat(chunks)));
1931
+ doc.on("error", (err) => reject(err));
1932
+ doc.end();
1895
1933
  });
1896
1934
  }
1897
1935
  // ---------------------------------------------------------
@@ -1912,7 +1950,7 @@ class Paddle {
1912
1950
  }
1913
1951
  for (const sub of subs) {
1914
1952
  if (sub.status === "active") {
1915
- console.log("Cancelling subscription", sub.id);
1953
+ this.server.log("Cancelling subscription ", sub.id);
1916
1954
  await this._req("POST", `/subscriptions/${sub.id}/cancel`, {
1917
1955
  effective_from: "immediately"
1918
1956
  });
@@ -1920,8 +1958,20 @@ class Paddle {
1920
1958
  }
1921
1959
  }
1922
1960
  }
1923
- var stdin_default = Paddle;
1961
+ (function(Paddle2) {
1962
+ class RequestError extends Error {
1963
+ status_code;
1964
+ constructor(err, status_code) {
1965
+ super(err);
1966
+ this.status_code = status_code;
1967
+ }
1968
+ }
1969
+ Paddle2.RequestError = RequestError;
1970
+ })(Paddle || (Paddle = {}));
1924
1971
  // Annotate the CommonJS export names for ESM import in node:
1925
1972
  0 && (module.exports = {
1926
- Paddle
1973
+ LineItem,
1974
+ Paddle,
1975
+ Payment,
1976
+ PaymentStatusValues
1927
1977
  });