@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
@@ -1,143 +1,66 @@
1
- /*
2
- * Author: Daan van den Bergh
3
- * Copyright: © 2022 - 2024 Daan van den Bergh.
1
+ /**
2
+ * @author Daan van den Bergh
3
+ * @copyright © 2022 - 2025 Daan van den Bergh. All rights reserved
4
4
  */
5
5
  // Imports.
6
6
  import * as https from "https";
7
7
  import * as PDFDocument from "pdfkit";
8
8
  import * as libcrypto from "crypto";
9
- import blobstream from 'blob-stream';
10
9
  import * as vlib from "@vandenberghinc/vlib";
11
- import { Utils, ExternalError } from "../utils.js";
12
- import { logger } from "../logger.js";
10
+ import { ExternalError } from "../errors/index.js";
13
11
  import { Status } from "../status.js";
14
- const { log, error } = logger;
15
- // Request error.
16
- class RequestError extends Error {
17
- status_code;
18
- constructor(err, status_code) {
19
- super(err);
20
- this.status_code = status_code;
12
+ import { Collection } from "../database/collection.js";
13
+ import { Utils } from "../utils.js";
14
+ /** Nested types for the {@link LineItem} interface. */
15
+ export var LineItem;
16
+ (function (LineItem) {
17
+ /** Validation schema. */
18
+ LineItem.Schema = {
19
+ product: "string",
20
+ item_id: "string",
21
+ paddle_prod_id: "string",
22
+ quantity: "number",
23
+ tax_rate: "number",
24
+ tax: "number",
25
+ discount: "number",
26
+ subtotal: "number",
27
+ total: "number",
28
+ status: { type: "string", enum: ["paid", "refunded", "refunding"] },
29
+ };
30
+ })(LineItem || (LineItem = {}));
31
+ export const PaymentStatusValues = ['open', 'paid', 'past_due', 'unknown'];
32
+ /** Nested types for the {@link Payment} interface. */
33
+ export var Payment;
34
+ (function (Payment) {
35
+ /**
36
+ * Check if a payment should be anonymized,
37
+ * if so return a public version of the payment.
38
+ */
39
+ function anonymize(payment) {
40
+ if (!payment.uid || payment.uid === "unauth") {
41
+ const { billing_details, ...rest } = payment;
42
+ return {
43
+ ...rest,
44
+ billing_details: undefined,
45
+ };
46
+ }
47
+ return payment;
21
48
  }
22
- }
49
+ Payment.anonymize = anonymize;
50
+ })(Payment || (Payment = {}));
23
51
  // The paddle payments class.
24
52
  // @todo check if a user can subscribe twice to a sub, should not be allowed for system logic.
25
53
  // @todo still need to manage the reactivation of a subscription after a chargeback has been reversed.
26
54
  // @todo still check if a subscription is automatically cancelled by paddle when it is refunded.
27
- /* @docs:
28
- @nav: Backend
29
- @chapter: Payments
30
- @title: Paddle
31
- @description:
32
- The paddle payments class.
33
-
34
- Sandbox env: https://sandbox-vendors.paddle.com
35
- @param:
36
- @name: api_key
37
- @type: string
38
- @description: Your paddle api key.
39
- @required: true
40
- @param:
41
- @name: client_key
42
- @type: string
43
- @description: Your paddle client key.
44
- @required: true
45
- @param:
46
- @name: sandbox
47
- @type: boolean
48
- @description: Enable the sandbox environment.
49
- @param:
50
- @name: inclusive_tax
51
- @type: boolean
52
- @description: Enable when prices are inclusive tax.
53
- @param:
54
- @name: products
55
- @type: object
56
- @warning: The payment product objects are accessable by anyone through the backend rest api so they should not contain any sensitive data.
57
- @attributes_type: ProductObject
58
- @attribute:
59
- @name: id
60
- @type: string
61
- @required: true
62
- @desc: The id of product
63
- @warning: The id can not be changed
64
- @warning: The id must be unique across all your products.
65
- @attribute:
66
- @name: name
67
- @type: string
68
- @required: true
69
- @desc: The name of the product.
70
- @attribute:
71
- @name: price
72
- @type: number
73
- @required: true
74
- @desc: The price of the product, digits after the decimal are the minor units (e.g. cents).
75
- @attribute:
76
- @name: currency
77
- @type: string
78
- @required: true
79
- @desc: The ISO currency code of the price.
80
- @attribute:
81
- @name: tax_category
82
- @type: string
83
- @required: true
84
- @desc: The tax category https://developer.paddle.com/api-reference/products/create-product.
85
- @attribute:
86
- @name: icon
87
- @type: string
88
- @desc: The icon url of the product, may also be an endpoint url of your website.
89
- @attribute:
90
- @name: frequency
91
- @type: number
92
- @desc: The recurring frequency, when this is defined a product will become a subscription product.
93
- @attribute:
94
- @name: interval
95
- @type: string
96
- @desc: The recurring interval, when this is defined a product will become a subscription product.
97
- @enum:
98
- @value: "day"
99
- @desc: Use this value to create a subscription product that renews at a daily interval.
100
- @enum:
101
- @value: "week"
102
- @desc: Use this value to create a subscription product that renews at a weekly interval.
103
- @enum:
104
- @value: "month"
105
- @desc: Use this value to create a subscription product that renews at a monthly interval.
106
- @enum:
107
- @value: "year"
108
- @desc: Use this value to create a subscription product that renews at a yearly interval.
109
- @attribute:
110
- @name: trial
111
- @type: null, object
112
- @desc: The trial settings for this product. Leave undefined to disable a trialing period. This attribute will be ignored for one-time payments.
113
- @attribute:
114
- @name: frequency
115
- @type: number
116
- @desc: The trial frequency.
117
- @attribute:
118
- @name: interval
119
- @type: string
120
- @desc: The trial interval.
121
- @enum:
122
- @value: "day"
123
- @desc: Daily interval.
124
- @enum:
125
- @value: "week"
126
- @desc: Weekly interval.
127
- @enum:
128
- @value: "month"
129
- @desc: Monthly interval.
130
- @enum:
131
- @value: "year"
132
- @desc: Yearly interval.
133
- @attribute:
134
- @name: plans
135
- @type: array[ProductObject]
136
- @desc: The plans for this subscription product. Every item is a product object. However, attributes `currency`, `frequency`, `interval`, `tax_category` and `icon` can either be defined in the subscription product or on each individual plan.
137
- @parameter:
138
- @name: _server
139
- @ignore: true
140
- */
55
+ /**
56
+ * The paddle payments class.
57
+ *
58
+ * Sandbox env: https://sandbox-vendors.paddle.com
59
+ *
60
+ * @nav Backend/Payments
61
+ * @docs
62
+ * @deprecated Using stripe from now on.
63
+ */
141
64
  export class Paddle {
142
65
  type;
143
66
  client_key;
@@ -149,16 +72,21 @@ export class Paddle {
149
72
  _headers;
150
73
  webhook_key;
151
74
  _has_create_products_permission;
152
- _settings_db;
75
+ _last_products_db;
76
+ _webhook_conf_db;
153
77
  _sub_db;
154
78
  _active_sub_db;
155
79
  _pay_db;
156
- // private _inv_db?: Collection;
80
+ // private _inv_db: Collection;
157
81
  performance;
158
- constructor({ api_key, client_key, sandbox = false, products = [], inclusive_tax = false, _server = null, }) {
82
+ constructor({ api_key, client_key, sandbox = false, products = [], inclusive_tax = false, _server, }) {
159
83
  // Original constructor implementation remains the same
160
84
  // Verify args.
161
- vlib.Scheme.validate(arguments[0], { strict: true, parent: "payments", scheme: {
85
+ vlib.schema.validate(arguments[0], {
86
+ unknown: false,
87
+ throw: true,
88
+ parent: "payments",
89
+ schema: {
162
90
  type: { type: "string", default: "paddle" },
163
91
  api_key: "string",
164
92
  client_key: "string",
@@ -166,7 +94,8 @@ export class Paddle {
166
94
  inclusive_tax: { type: "boolean", default: false },
167
95
  products: "array",
168
96
  _server: "object",
169
- } });
97
+ }
98
+ });
170
99
  // Attributes.
171
100
  this.type = "paddle";
172
101
  this.client_key = client_key;
@@ -186,6 +115,31 @@ export class Paddle {
186
115
  this.server.csp["script-src"] += " https://*.paddle.com/ https://*.payments-amazon.com https://*.paypal.com https://*.google.com";
187
116
  this.server.csp["style-src"] += " https://*.paddle.com/ https://*.media-amazon.com https://*.paypal.com https://*.google.com";
188
117
  this.server.csp["img-src"] += " https://*.paddle.com/ https://*.media-amazon.com https://*.paypal.com https://*.google.com";
118
+ // Create database collections.
119
+ this._last_products_db = this.server.db.collection({
120
+ name: "Volt.Paddle.LastProducts",
121
+ indexes: ["production", "version"],
122
+ });
123
+ this._webhook_conf_db = this.server.db.collection({
124
+ name: "Volt.Paddle.WebhookConfig",
125
+ indexes: ["production", "version"],
126
+ });
127
+ this._sub_db = this.server.db.collection({
128
+ name: "Volt.Paddle.Subscriptions",
129
+ indexes: ["uid", "id"],
130
+ });
131
+ this._active_sub_db = this.server.db.collection({
132
+ name: "Volt.Paddle.ActiveSubscriptions",
133
+ indexes: ["uid", "prod_id"],
134
+ });
135
+ this._pay_db = this.server.db.collection({
136
+ name: "Volt.Paddle.Payments",
137
+ indexes: ["uid", "id", "tran_id"],
138
+ });
139
+ // this._inv_db = this.server.db.collection({
140
+ // name: "Volt.Paddle.Invoices",
141
+ // indexes: ["uid", "id", "tran_id" ],
142
+ // });
189
143
  /* @performance */ this.performance = new vlib.Performance("Payments performance");
190
144
  }
191
145
  // ---------------------------------------------------------
@@ -194,11 +148,28 @@ export class Paddle {
194
148
  // Utils (private).
195
149
  async _req(method, endpoint, params = null) {
196
150
  const promise = new Promise((resolve, reject) => {
151
+ // Build hostname + path for both relative and absolute endpoints.
152
+ const is_get_like = method === "GET" || method === "HEAD";
153
+ let hostname = this._host;
154
+ let path = endpoint;
155
+ try {
156
+ if (/^https?:\/\//i.test(endpoint)) {
157
+ const u = new URL(endpoint);
158
+ hostname = u.hostname;
159
+ path = u.pathname + u.search;
160
+ }
161
+ else if (is_get_like && params != null) {
162
+ path = `${endpoint}?${new URLSearchParams(params).toString()}`;
163
+ }
164
+ }
165
+ catch {
166
+ // fall back to original host + endpoint
167
+ }
197
168
  // Options.
198
169
  const options = {
199
170
  method: method,
200
- hostname: this._host,
201
- path: method === "GET" && params != null ? `${endpoint}?${new URLSearchParams(params).toString()}` : endpoint,
171
+ hostname,
172
+ path,
202
173
  port: 443,
203
174
  headers: this._headers,
204
175
  };
@@ -211,7 +182,7 @@ export class Paddle {
211
182
  response.on('end', () => {
212
183
  if (response?.statusCode >= 200 && response?.statusCode < 300) {
213
184
  try {
214
- resolve(JSON.parse(data));
185
+ resolve(data ? JSON.parse(data) : {});
215
186
  }
216
187
  catch (error) {
217
188
  reject(new Error('Failed to parse response data'));
@@ -219,16 +190,16 @@ export class Paddle {
219
190
  }
220
191
  else {
221
192
  if (data == null || data === "") {
222
- 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));
223
194
  }
224
195
  try {
225
196
  data = JSON.parse(data);
226
197
  }
227
198
  catch (e) {
228
- return reject(new RequestError(`${method}:${endpoint}: Request failed [${response.statusCode}].`, response.statusCode));
199
+ return reject(new Paddle.RequestError(`${method}:${endpoint}: Request failed [${response.statusCode}].`, response.statusCode));
229
200
  }
230
201
  if (data.error == null) {
231
- return reject(new RequestError(`${method}:${endpoint}: Request failed [${response.statusCode}].`, response.statusCode));
202
+ return reject(new Paddle.RequestError(`${method}:${endpoint}: Request failed [${response.statusCode}].`, response.statusCode));
232
203
  }
233
204
  data = data.error;
234
205
  let errs = "";
@@ -239,12 +210,12 @@ export class Paddle {
239
210
  });
240
211
  errs = errs.substr(0, errs.length - 2);
241
212
  }
242
- return reject(new RequestError(`${method}:${endpoint}: ${data.detail} [${response.statusCode}]${errs}.`, response.statusCode));
213
+ return reject(new Paddle.RequestError(`${method}:${endpoint}: ${data.detail} [${response.statusCode}]${errs}.`, response.statusCode));
243
214
  }
244
215
  });
245
216
  });
246
217
  // Write body params.
247
- if (params != null) {
218
+ if (!is_get_like && params != null) {
248
219
  // request.write(JSON.stringify(params));
249
220
  const requestBody = JSON.stringify(params);
250
221
  request.setHeader('Content-Length', Buffer.byteLength(requestBody));
@@ -262,7 +233,7 @@ export class Paddle {
262
233
  return await promise;
263
234
  }
264
235
  catch (e) {
265
- if (e instanceof Error || e instanceof RequestError) {
236
+ if (e instanceof Error || e instanceof Paddle.RequestError) {
266
237
  throw e;
267
238
  }
268
239
  throw new Error(e);
@@ -272,33 +243,25 @@ export class Paddle {
272
243
  // Database (private).
273
244
  // Add or remove a subscription to the user's active subscriptions.
274
245
  async _add_subscription(uid, prod_id, sub_id) {
275
- await this._active_sub_db.save({ uid, prod_id }, { prod_id, sub_id });
246
+ await this._active_sub_db.set({ uid, prod_id }, { prod_id, sub_id });
276
247
  }
277
248
  async _delete_subscription(uid, prod_id) {
278
249
  await this._active_sub_db.delete({ uid, prod_id });
279
250
  }
280
251
  async _check_subscription(uid, prod_id, load_data = false) {
281
- const doc = await this._active_sub_db.load({ uid, prod_id });
282
- let exists = false, sub_id;
283
- if (doc == null) {
284
- if (load_data) {
285
- return { exists, sub_id };
286
- }
287
- else {
288
- return exists;
289
- }
290
- }
291
- exists = true;
292
- sub_id = doc.sub_id;
293
- if (load_data) {
294
- return { exists, sub_id };
252
+ try {
253
+ const doc = await this._active_sub_db.load({ uid, prod_id });
254
+ return load_data ? { exists: true, sub_id: doc.sub_id } : true;
295
255
  }
296
- else {
297
- return exists;
256
+ catch (err) {
257
+ if (err instanceof Collection.NotFoundError) {
258
+ return load_data ? { exists: false, sub_id: undefined } : false;
259
+ }
260
+ throw err;
298
261
  }
299
262
  }
300
263
  async _get_active_subscriptions(uid, detailed = false) {
301
- const list = await this._active_sub_db.list_query({ uid: uid });
264
+ const list = await this._active_sub_db.list({ uid: uid });
302
265
  if (detailed) {
303
266
  return list;
304
267
  }
@@ -309,52 +272,40 @@ export class Paddle {
309
272
  return products;
310
273
  }
311
274
  async _save_subscription(subscription) {
312
- await this._sub_db.save({
275
+ await this._sub_db.set({
313
276
  uid: subscription.uid == null ? "unauth" : subscription.uid,
314
277
  id: subscription.id,
315
278
  }, subscription);
316
279
  }
317
280
  async _load_subscription(id) {
318
- const subscription = await this._sub_db.find({ id: id });
319
- if (subscription == null) {
320
- throw Error(`Unable to find subscription "${id}".`);
321
- }
322
- return subscription;
281
+ return await this._sub_db.load({ id: id }, { retry: 3 });
323
282
  }
324
283
  async _get_subscriptions(uid) {
325
284
  if (uid === "unauth" || uid == null) {
326
285
  return [];
327
286
  }
328
- const list = await this._sub_db.list_query({ uid: uid });
287
+ const list = await this._sub_db.list({ uid: uid });
329
288
  return list;
330
289
  }
331
290
  // Save and delete payments, all failed payments should be deleted from the database.
332
291
  async _save_payment(payment) {
333
- await this._pay_db.save({
292
+ await this._pay_db.set({
334
293
  uid: payment.uid == null ? "unauth" : payment.uid,
335
294
  id: payment.id,
336
295
  }, payment);
337
296
  }
338
297
  async _load_payment(id) {
339
298
  const uid = id.split("_")[1];
340
- const payment = await this._pay_db.load({ uid, id });
341
- if (payment == null) {
342
- throw Error(`Unable to find payment "${id}".`);
343
- }
344
- if (uid == null || uid == "unauth") {
345
- delete payment.billing_details;
346
- }
347
- return payment;
299
+ return await this._pay_db.load({ uid, id });
348
300
  }
349
- async _load_payment_by_transaction(id) {
350
- const payment = await this._pay_db.find({ tran_id: id });
351
- if (payment == null) {
352
- throw Error(`Unable to find the payment by transaction id "${id}".`);
353
- }
354
- if (payment.uid == null || payment.uid == "unauth") {
355
- delete payment.billing_details;
356
- }
357
- return payment;
301
+ async _load_payment_for_public(id) {
302
+ return Payment.anonymize(await this._load_payment(id));
303
+ }
304
+ async _load_payment_by_transaction(tran_id) {
305
+ return await this._pay_db.load({ tran_id: tran_id }, { retry: 3 });
306
+ }
307
+ async _load_payment_by_transaction_for_public(tran_id) {
308
+ return Payment.anonymize(await this._load_payment_by_transaction(tran_id));
358
309
  }
359
310
  async _delete_payment(id) {
360
311
  const uid = id.split("_")[1];
@@ -362,14 +313,14 @@ export class Paddle {
362
313
  }
363
314
  // Delete all info of a user.
364
315
  async _delete_user(uid) {
365
- await this._sub_db.delete_all({ uid });
366
- await this._active_sub_db.delete_all({ uid });
367
- await this._pay_db.delete_all({ uid });
316
+ await this._sub_db.delete_many({ uid });
317
+ await this._active_sub_db.delete_many({ uid });
318
+ await this._pay_db.delete_many({ uid });
368
319
  // await this._inv_db.delete_all({ uid });
369
320
  }
370
321
  // List all active subscriptions.
371
322
  async _get_all_active_subscriptions() {
372
- return await this._active_sub_db.list_query({});
323
+ return await this._active_sub_db.list_all();
373
324
  }
374
325
  // ---------------------------------------------------------
375
326
  // Overall (private).
@@ -444,8 +395,8 @@ export class Paddle {
444
395
  if (process.argv.includes("--no-payment-edits")) {
445
396
  return false;
446
397
  }
447
- if (this._has_create_products_permission) {
448
- return true;
398
+ if (this._has_create_products_permission != null) {
399
+ return this._has_create_products_permission;
449
400
  }
450
401
  const input = await vlib.logging.prompt("Some paddle products have to be edited, do you wish to make these changes? [y/n]: ");
451
402
  if (["y", "yes", "ok"].includes(input.toLowerCase())) {
@@ -469,7 +420,7 @@ export class Paddle {
469
420
  return;
470
421
  }
471
422
  // Create product.
472
- log(0, `Creating product ${product.name}.`);
423
+ this.server.log(0, `Creating product ${product.name}.`);
473
424
  const created_product = await this._req("POST", "/products", {
474
425
  name: product.name,
475
426
  description: product.description,
@@ -479,14 +430,14 @@ export class Paddle {
479
430
  });
480
431
  product.paddle_prod_id = created_product.data.id;
481
432
  // Create price.
482
- log(0, `Creating a price for product ${product.name}.`);
433
+ this.server.log(0, `Creating a price for product ${product.name}.`);
483
434
  const created_price = await this._req("POST", "/prices", {
484
435
  product_id: product.paddle_prod_id,
485
436
  name: product.name,
486
437
  description: product.description,
487
438
  unit_price: { amount: Math.floor(product.price * 100).toString(), currency_code: product.currency },
488
439
  billing_cycle: product.is_subscription ? { interval: product.interval, frequency: product.frequency } : null,
489
- trial_period: product.trial,
440
+ trial_period: product.is_subscription ? product.trial : null,
490
441
  tax_mode: this.inclusive_tax ? "internal" : "external",
491
442
  });
492
443
  product.price_id = created_price.data.id;
@@ -495,7 +446,7 @@ export class Paddle {
495
446
  else {
496
447
  // Vars.
497
448
  product.paddle_prod_id = existing_product.id;
498
- const has_trial = product.trial != null;
449
+ const has_trial = product.is_subscription && product.trial != null;
499
450
  // Check if the product should be updated.
500
451
  const update_product = (existing_product.name !== product.name ||
501
452
  existing_product.description !== product.description ||
@@ -507,7 +458,7 @@ export class Paddle {
507
458
  if (!await has_create_products_permission()) {
508
459
  return;
509
460
  }
510
- log(0, `Updating product ${product.name}.`);
461
+ this.server.log(0, `Updating product ${product.name}.`);
511
462
  await this._req("PATCH", `/products/${product.paddle_prod_id}`, {
512
463
  name: product.name,
513
464
  description: product.description,
@@ -528,14 +479,14 @@ export class Paddle {
528
479
  if (!await has_create_products_permission()) {
529
480
  return;
530
481
  }
531
- log(0, `Creating a price for product ${product.name}.`);
482
+ this.server.log(0, `Creating a price for product ${product.name}.`);
532
483
  const price = await this._req("POST", "/prices", {
533
484
  product_id: product.paddle_prod_id,
534
485
  name: product.name,
535
486
  description: product.description,
536
487
  unit_price: { amount: Math.floor(product.price * 100).toString(), currency_code: product.currency },
537
488
  billing_cycle: product.is_subscription ? { interval: product.interval, frequency: product.frequency } : null,
538
- trial_period: product.trial,
489
+ trial_period: product.is_subscription ? product.trial : null,
539
490
  tax_mode: this.inclusive_tax ? "internal" : "external",
540
491
  });
541
492
  product.price_id = price.data.id;
@@ -564,14 +515,14 @@ export class Paddle {
564
515
  if (!await has_create_products_permission()) {
565
516
  return;
566
517
  }
567
- log(0, `Updating the price of product ${product.name}.`);
518
+ this.server.log(0, `Updating the price of product ${product.name}.`);
568
519
  await this._req("PATCH", `/prices/${product.price_id}`, {
569
520
  // product_id: product.id, // not allowed.
570
521
  name: product.name,
571
522
  description: product.description,
572
523
  unit_price: { amount: Math.floor(product.price * 100).toString(), currency_code: product.currency },
573
524
  billing_cycle: product.is_subscription ? { interval: product.interval, frequency: product.frequency } : null,
574
- trial_period: product.trial,
525
+ trial_period: product.is_subscription ? product.trial : null,
575
526
  tax_mode: this.inclusive_tax ? "internal" : "external",
576
527
  status: "active",
577
528
  });
@@ -778,9 +729,9 @@ export class Paddle {
778
729
  // Expand the payment products.
779
730
  let sub_products = 0;
780
731
  this.products.iterate((product) => {
781
- if (product.plans != null) {
732
+ if (product.is_subscription) {
782
733
  // Check plans.
783
- if (product.plans != null && Array.isArray(product.plans) === false) {
734
+ if (!product.plans || !Array.isArray(product.plans)) {
784
735
  throw Error(`Product "${product_index}" has an incorrect value type for attribute "plans", the valid type is "array".`);
785
736
  }
786
737
  // Generate sub id.
@@ -817,9 +768,6 @@ export class Paddle {
817
768
  initialize_product(plan);
818
769
  });
819
770
  }
820
- else if (product.frequency != null || product.interval != null) {
821
- throw Error(`Subscription products should be nested as plans of a subscription "{... plans: [...]}". Not as a direct product without a subscription parent.`);
822
- }
823
771
  else {
824
772
  product.is_subscription = false;
825
773
  initialize_product(product);
@@ -827,10 +775,11 @@ export class Paddle {
827
775
  });
828
776
  /* @performance */ now = this.performance.end("init-products", now);
829
777
  // Check registered products.
830
- const last_products = await this._settings_db.load(`last_products${this.server.production ? "" : "_demo"}`);
831
- if (vlib.Object.eq(last_products, this.products)) {
832
- const product_ids = await this._settings_db.load(`product_ids${this.server.production ? "" : "_demo"}`);
833
- product_ids.iterate((item) => {
778
+ const last_products = await this._last_products_db.load({ production: this.server.production, version: 1 }, { throw: false });
779
+ if (last_products instanceof Error && !(last_products instanceof Collection.NotFoundError))
780
+ throw last_products;
781
+ if (!(last_products instanceof Collection.NotFoundError) && vlib.Object.eq(last_products.last_products, this.products)) {
782
+ last_products.product_ids.iterate((item) => {
834
783
  const product = this.get_product_sync(item.id);
835
784
  if (product != null) {
836
785
  product.paddle_prod_id = item.paddle_prod_id;
@@ -847,7 +796,7 @@ export class Paddle {
847
796
  // Check all products.
848
797
  const product_ids = [];
849
798
  for (const product of this.products) {
850
- if (product.plans != null) {
799
+ if (product.is_subscription) {
851
800
  for (const plan of product.plans) {
852
801
  await this._check_product(plan, existing_products, existing_prices);
853
802
  product_ids.append({
@@ -870,76 +819,59 @@ export class Paddle {
870
819
  ;
871
820
  /* @performance */ now = this.performance.end("check-products", now);
872
821
  // Save last products.
873
- 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"]));
874
- // Save price ids.
875
- await this._settings_db.save(`product_ids${this.server.production ? "" : "_demo"}`, product_ids);
822
+ await this._last_products_db.set({ production: this.server.production, version: 1 }, {
823
+ last_products: vlib.Object.delete_recursively(vlib.Object.deep_copy(this.products), ["paddle_prod_id", "price_id"]),
824
+ product_ids: product_ids,
825
+ });
876
826
  /* @performance */ now = this.performance.end("save-products-to-db", now);
877
827
  }
878
828
  }
879
829
  // Initialize the payments.
880
830
  async _initialize() {
881
- /* @performance */ this.performance.start();
882
- // Create database collections.
883
- this._settings_db = await this.server.db.collection({
884
- name: "Volt.Paddle.Settings",
885
- indexes: ["_path"],
886
- });
887
- this._sub_db = await this.server.db.collection({
888
- name: "Volt.Paddle.Subscriptions",
889
- indexes: ["uid", "id"],
890
- });
891
- this._active_sub_db = await this.server.db.collection({
892
- name: "Volt.Paddle.ActiveSubscriptions",
893
- indexes: ["uid", "prod_id"],
894
- });
895
- this._pay_db = await this.server.db.collection({
896
- name: "Volt.Paddle.Payments",
897
- indexes: ["uid", "id", "tran_id"],
898
- });
899
- // this._inv_db = await this.server.db.collection({
900
- // name: "Volt.Paddle.Invoices",
901
- // indexes: ["uid", "id", "tran_id" ],
902
- // });
903
- /* @performance */ this.performance.end("init-db");
904
831
  // Initialize products.
905
832
  await this._initialize_products();
906
833
  /* @performance */ let now = this.performance.start();
907
834
  // Initialize and verify an order, check if the user is authenticated when subscriptions are present and check if the user is not already subscribed to the same item.
908
835
  this.server.endpoint({
909
836
  method: "POST",
910
- endpoint: "/volt/payments/init",
837
+ endpoint: "/volt/api/v1/payments/init",
911
838
  content_type: "application/json",
912
839
  rate_limit: "global",
913
840
  params: {
914
- items: "array",
841
+ items: { type: "array", required: true, value_schema: "object" }, // add schema for items
915
842
  },
916
843
  callback: async (stream, params) => {
917
844
  // Check items.
918
845
  if (params.items.length === 0) {
919
- return stream.error({ status: Status.bad_request, data: { error: "Shopping cart is empty." } });
846
+ return stream.error({ status: Status.bad_request, message: "Shopping cart is empty." });
920
847
  }
921
848
  let sub_plan_count = {};
922
- const error = await params.items.iterate_async_await(async (item) => {
849
+ let error = undefined;
850
+ for (const item of params.items) {
923
851
  if (item.product.is_subscription) {
924
852
  if (stream.uid == null) {
925
- return "You must be signed-in to purchase a subscription.";
853
+ error = "You must be signed-in to purchase a subscription.";
854
+ break;
926
855
  }
927
856
  if (item.quantity != null && item.quantity > 1) {
928
- return "Subscriptions have a max quantity of 1.";
857
+ error = "Subscriptions have a max quantity of 1.";
858
+ break;
929
859
  }
930
860
  if (sub_plan_count[item.product.subscription_id] == null) {
931
861
  sub_plan_count[item.product.subscription_id] = 1;
932
862
  }
933
863
  else {
934
- return "You can not charge two different subscription plans from the same subscription product.";
864
+ error = "You can not charge two different subscription plans from the same subscription product.";
865
+ break;
935
866
  }
936
867
  if (await this._check_subscription(stream.uid, item.product.id, false)) {
937
- return `You are already subscribed to product "${item.product.name}".`;
868
+ error = `You are already subscribed to product "${item.product.name}".`;
869
+ break;
938
870
  }
939
871
  }
940
- });
872
+ }
941
873
  if (error) {
942
- return stream.error({ status: Status.bad_request, data: { error } });
874
+ return stream.error({ status: Status.bad_request, message: error });
943
875
  }
944
876
  // Success.
945
877
  return stream.success({ data: { message: "Successfully initialized the order." } });
@@ -948,7 +880,7 @@ export class Paddle {
948
880
  // Get products.
949
881
  this.server.endpoint({
950
882
  method: "GET",
951
- endpoint: "/volt/payments/products",
883
+ endpoint: "/volt/api/v1/payments/products",
952
884
  content_type: "application/json",
953
885
  rate_limit: "global",
954
886
  callback: (stream) => {
@@ -958,119 +890,130 @@ export class Paddle {
958
890
  // Get payment by id.
959
891
  this.server.endpoint({
960
892
  method: "GET",
961
- endpoint: "/volt/payments/payment",
893
+ endpoint: "/volt/api/v1/payments/payment",
962
894
  content_type: "application/json",
963
895
  rate_limit: "global",
964
896
  params: {
965
897
  id: "string",
966
898
  },
967
899
  callback: async (stream, params) => {
968
- return stream.success({ data: (await this._load_payment(params.id)) });
900
+ return stream.success({
901
+ data: await this._load_payment_for_public(params.id),
902
+ });
969
903
  }
970
904
  });
971
905
  // Get payments.
972
906
  this.server.endpoint({
973
907
  method: "GET",
974
- endpoint: "/volt/payments/payments",
908
+ endpoint: "/volt/api/v1/payments/payments",
975
909
  content_type: "application/json",
976
910
  authenticated: true,
977
911
  rate_limit: "global",
978
912
  params: {
979
913
  days: { type: "number", default: 30 },
980
- limit: { type: "number", default: null },
981
- status: { type: "string", default: null },
914
+ limit: { type: "number", required: false },
915
+ status: { type: "string", required: false, enum: PaymentStatusValues },
982
916
  },
983
917
  callback: async (stream, params) => {
984
- const result = await this.get_payments({
985
- uid: stream.uid,
986
- days: params.days,
987
- limit: params.limit,
988
- status: params.status,
918
+ return stream.success({
919
+ data: await this.get_payments({
920
+ uid: stream.uid,
921
+ days: params.days,
922
+ limit: params.limit,
923
+ status: params.status,
924
+ })
989
925
  });
990
- return stream.success({ data: result });
991
926
  }
992
927
  });
993
928
  // Get refundable payments.
994
929
  this.server.endpoint({
995
930
  method: "GET",
996
- endpoint: "/volt/payments/payments/refundable",
931
+ endpoint: "/volt/api/v1/payments/payments/refundable",
997
932
  content_type: "application/json",
998
933
  authenticated: true,
999
934
  rate_limit: "global",
1000
935
  params: {
1001
936
  days: { type: "number", default: 30 },
1002
- limit: { type: ["null", "number"], default: null },
1003
- status: { type: ["null", "string"], default: null },
937
+ limit: { type: "number", required: false },
1004
938
  },
1005
939
  callback: async (stream, params) => {
1006
- const result = await this.get_refundable_payments({
1007
- uid: stream.uid,
1008
- days: params.days,
1009
- limit: params.limit,
940
+ return stream.success({
941
+ data: await this.get_refundable_payments({
942
+ uid: stream.uid,
943
+ days: params.days,
944
+ limit: params.limit,
945
+ for_public: true,
946
+ })
1010
947
  });
1011
- return stream.success({ data: result });
1012
948
  }
1013
949
  });
1014
950
  // Get refunded payments.
1015
951
  this.server.endpoint({
1016
952
  method: "GET",
1017
- endpoint: "/volt/payments/payments/refunded",
953
+ endpoint: "/volt/api/v1/payments/payments/refunded",
1018
954
  content_type: "application/json",
1019
955
  authenticated: true,
1020
956
  rate_limit: "global",
1021
957
  params: {
1022
958
  days: { type: "number", default: 30 },
1023
- limit: { type: ["null", "number"], default: null },
959
+ limit: { type: "number", required: false },
1024
960
  },
1025
961
  callback: async (stream, params) => {
1026
- const result = await this.get_refunded_payments({
1027
- uid: stream.uid,
1028
- days: params.days,
1029
- limit: params.limit,
962
+ return stream.success({
963
+ data: await this.get_refunded_payments({
964
+ uid: stream.uid,
965
+ days: params.days,
966
+ limit: params.limit,
967
+ for_public: true,
968
+ })
1030
969
  });
1031
- return stream.success({ data: result });
1032
970
  }
1033
971
  });
1034
972
  // Get refunding payments.
1035
973
  this.server.endpoint({
1036
974
  method: "GET",
1037
- endpoint: "/volt/payments/payments/refunding",
975
+ endpoint: "/volt/api/v1/payments/payments/refunding",
1038
976
  content_type: "application/json",
1039
977
  authenticated: true,
1040
978
  rate_limit: "global",
1041
979
  params: {
1042
- days: { type: ["null", "number"], default: null },
1043
- limit: { type: ["null", "number"], default: null },
980
+ days: { type: "number", default: 30 },
981
+ limit: { type: "number", required: false },
1044
982
  },
1045
983
  callback: async (stream, params) => {
1046
- const result = await this.get_refunding_payments({
1047
- uid: stream.uid,
1048
- days: params.days,
1049
- limit: params.limit,
984
+ return stream.success({
985
+ data: await this.get_refunding_payments({
986
+ uid: stream.uid,
987
+ days: params.days,
988
+ limit: params.limit,
989
+ for_public: true,
990
+ })
1050
991
  });
1051
- return stream.success({ data: result });
1052
992
  }
1053
993
  });
1054
994
  // Create a refund.
1055
995
  this.server.endpoint({
1056
996
  method: "POST",
1057
- endpoint: "/volt/payments/refund",
997
+ endpoint: "/volt/api/v1/payments/refund",
1058
998
  content_type: "application/json",
999
+ authenticated: true,
1059
1000
  rate_limit: "global",
1060
1001
  params: {
1061
- payment: { type: ["string", "object"] },
1062
- line_items: { type: ["array", "null"], default: null },
1002
+ payment: { type: ["string", "object"], schema: { id: "string" } },
1003
+ line_items: { type: "array", required: false, value_schema: {
1004
+ type: "object", schema: LineItem.Schema
1005
+ } },
1063
1006
  reason: { type: "string", default: "refund" },
1064
1007
  },
1065
1008
  callback: async (stream, params) => {
1066
- await this.create_refund(params.payment, params.line_items, params.reason);
1009
+ await this.create_refund(typeof params.payment === "string" ? params.payment : params.payment.id, params.line_items, params.reason);
1067
1010
  return stream.success();
1068
1011
  }
1069
1012
  });
1070
1013
  // Cancel a subscription.
1071
1014
  this.server.endpoint({
1072
1015
  method: "DELETE",
1073
- endpoint: "/volt/payments/subscription",
1016
+ endpoint: "/volt/api/v1/payments/subscription",
1074
1017
  content_type: "application/json",
1075
1018
  authenticated: true,
1076
1019
  rate_limit: "global",
@@ -1085,7 +1028,7 @@ export class Paddle {
1085
1028
  // Cancel a subscription by payment.
1086
1029
  // {
1087
1030
  // method: "DELETE",
1088
- // endpoint: "/volt/payments/subscription_by_payment",
1031
+ // endpoint: "/volt/api/v1/payments/subscription_by_payment",
1089
1032
  // content_type: "application/json",
1090
1033
  // authenticated: true,
1091
1034
  // rate_limit: "global",
@@ -1100,20 +1043,22 @@ export class Paddle {
1100
1043
  // Get active subscriptions.
1101
1044
  this.server.endpoint({
1102
1045
  method: "GET",
1103
- endpoint: "/volt/payments/active_subscriptions",
1046
+ endpoint: "/volt/api/v1/payments/active_subscriptions",
1104
1047
  content_type: "application/json",
1105
1048
  authenticated: true,
1106
1049
  rate_limit: "global",
1107
- callback: async (stream, params) => {
1050
+ callback: async (stream) => {
1108
1051
  return stream.success({
1109
- data: { subscriptions: (await this.get_active_subscriptions(stream.uid)) },
1052
+ data: {
1053
+ subscriptions: await this.get_active_subscriptions(stream.uid)
1054
+ },
1110
1055
  });
1111
1056
  }
1112
1057
  });
1113
1058
  // Is subscribed
1114
1059
  this.server.endpoint({
1115
1060
  method: "GET",
1116
- endpoint: "/volt/payments/subscribed",
1061
+ endpoint: "/volt/api/v1/payments/subscribed",
1117
1062
  content_type: "application/json",
1118
1063
  authenticated: true,
1119
1064
  rate_limit: "global",
@@ -1122,7 +1067,9 @@ export class Paddle {
1122
1067
  },
1123
1068
  callback: async (stream, params) => {
1124
1069
  return stream.success({
1125
- data: { is_subscribed: (await this.is_subscribed(stream.uid, params.product)) }
1070
+ data: {
1071
+ is_subscribed: (await this.is_subscribed(stream.uid, params.product))
1072
+ }
1126
1073
  });
1127
1074
  }
1128
1075
  });
@@ -1165,7 +1112,7 @@ export class Paddle {
1165
1112
  // Only used in the paid webhook, other parts use the saved payment object.
1166
1113
  // This is required to manage the statuses of payments.
1167
1114
  // Make request.
1168
- let obj = (await this._req("GET", `/transactions/${data.id}`, { include: ["address", "adjustment", "business", "customer"] })).data;
1115
+ let obj = (await this._req("GET", `/transactions/${data.id}`, { include: ["address", "adjustments", "business", "customer"] })).data;
1169
1116
  // Initialize.
1170
1117
  const id = `pay_${obj.custom_data.uid == null ? "unauth" : obj.custom_data.uid}_${vlib.String.random(4)}${Date.now()}`;
1171
1118
  const payment = {
@@ -1246,7 +1193,7 @@ export class Paddle {
1246
1193
  payment.status = "past_due";
1247
1194
  break;
1248
1195
  default:
1249
- error(`Payment Webhook: Unknown payment status "${obj.status}".`);
1196
+ this.server.log.error(`Payment Webhook: Unknown payment status "${obj.status}".`);
1250
1197
  payment.status = "unknown";
1251
1198
  break;
1252
1199
  }
@@ -1258,10 +1205,10 @@ export class Paddle {
1258
1205
  paddle_prod_id: item.product.id, // paddle product id.
1259
1206
  quantity: item.quantity,
1260
1207
  tax_rate: parseFloat(item.tax_rate),
1261
- tax: parseFloat(item.totals.tax / 100), // should not be changed to unit totals, since mails and invoices depend on this behaviour, just divide by quantity.
1262
- discount: parseFloat(item.totals.discount / 100), // should not be changed to unit totals, since mails and invoices depend on this behaviour, just divide by quantity.
1263
- subtotal: parseFloat(item.totals.subtotal / 100), // should not be changed to unit totals, since mails and invoices depend on this behaviour, just divide by quantity.
1264
- total: parseFloat(item.totals.total / 100), // should not be changed to unit totals, since mails and invoices depend on this behaviour, just divide by quantity.
1208
+ tax: item.totals.tax / 100, // should not be changed to unit totals, since mails and invoices depend on this behaviour, just divide by quantity.
1209
+ discount: item.totals.discount / 100, // should not be changed to unit totals, since mails and invoices depend on this behaviour, just divide by quantity.
1210
+ subtotal: item.totals.subtotal / 100, // should not be changed to unit totals, since mails and invoices depend on this behaviour, just divide by quantity.
1211
+ total: item.totals.total / 100, // should not be changed to unit totals, since mails and invoices depend on this behaviour, just divide by quantity.
1265
1212
  status: "paid", // can be "paid", "refunded", "refunding".
1266
1213
  });
1267
1214
  });
@@ -1270,8 +1217,8 @@ export class Paddle {
1270
1217
  obj.adustments.iterate((adj) => {
1271
1218
  switch (adj.action) {
1272
1219
  case "refund":
1273
- case "cargeback":
1274
- case "cargeback_warning":
1220
+ case "chargeback":
1221
+ // case "chargeback_warning":
1275
1222
  adj.items.iterate((adj_item) => {
1276
1223
  payment.line_items.iterate((item) => {
1277
1224
  if (adj_item.item_id === item.item_id) {
@@ -1281,6 +1228,16 @@ export class Paddle {
1281
1228
  });
1282
1229
  });
1283
1230
  break;
1231
+ case "chargeback_reversal":
1232
+ adj.items.iterate((adj_item) => {
1233
+ payment.line_items.iterate((item) => {
1234
+ if (adj_item.item_id === item.item_id) {
1235
+ item.status = "paid";
1236
+ return false;
1237
+ }
1238
+ });
1239
+ });
1240
+ break;
1284
1241
  default:
1285
1242
  break;
1286
1243
  }
@@ -1290,9 +1247,9 @@ export class Paddle {
1290
1247
  await this._save_payment(payment);
1291
1248
  // ---------------------------------------------------------
1292
1249
  // Process the payment.
1293
- const { uid, cus_id } = payment;
1250
+ const { uid } = payment;
1294
1251
  // Check the payment line items.
1295
- for (const item of await payment.line_items) {
1252
+ for (const item of payment.line_items) {
1296
1253
  const product = this.get_product_sync(item.product, false);
1297
1254
  // @todo REFUND PAYMENT SINCE PRODUCT WAS NOT FOUND SO NO WAY OF DELIVERY.
1298
1255
  // Refund the payment since there is no way of delivery.
@@ -1308,11 +1265,11 @@ export class Paddle {
1308
1265
  // Cancel the other subscriptions plans that are part of this product.
1309
1266
  // The `create_payment()` function makes sure there are not multiple subscription plans of the same subscription product charged in a single request.
1310
1267
  const subscription = await this.get_product(product.subscription_id, true);
1311
- for (const plan of subscription.plans ?? []) {
1268
+ for (const plan of subscription?.plans ?? []) {
1312
1269
  if (plan.id != product.id) {
1313
1270
  const { exists, sub_id } = await this._check_subscription(uid, plan.id);
1314
1271
  if (exists) {
1315
- log(0, `Cancelling subscription "${plan.id}" due too downgrade/upgrade to "${product.id}" of user "${payment.uid}".`);
1272
+ this.server.log(0, `Cancelling subscription "${plan.id}" due too downgrade/upgrade to "${product.id}" of user "${payment.uid}".`);
1316
1273
  // @todo cancel sub by sub id.
1317
1274
  await this._cancel_subscription(sub_id);
1318
1275
  }
@@ -1356,7 +1313,7 @@ export class Paddle {
1356
1313
  const product = this._get_product_by_paddle_prod_id(item.price.product_id, false);
1357
1314
  // Product not found or no sub id found, nothing to do here, the payment webhook already handles this scenario.
1358
1315
  if (product == null) {
1359
- 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)}.`);
1316
+ 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)}.`);
1360
1317
  continue;
1361
1318
  }
1362
1319
  // Subscription.
@@ -1364,7 +1321,7 @@ export class Paddle {
1364
1321
  // Add to plans.
1365
1322
  subscription.plans.append(product.id);
1366
1323
  // Active the user's subscription in the database.
1367
- log(0, `Activating subscription "${product.id}" of user "${subscription.uid}".`);
1324
+ this.server.log(0, `Activating subscription "${product.id}" of user "${subscription.uid}".`);
1368
1325
  await this._add_subscription(uid, product.id, subscription.id);
1369
1326
  // No need to cancel other subs, this is already handled by the payment webhook.
1370
1327
  // Execute callback.
@@ -1382,7 +1339,7 @@ export class Paddle {
1382
1339
  // Delete subscriptions made by this subscription.
1383
1340
  for (const plan_id of subscription.plans) {
1384
1341
  await this._delete_subscription(subscription.uid, plan_id);
1385
- log(0, `Deactivating subscription "${plan_id}" of user "${subscription.uid}".`);
1342
+ this.server.log(0, `Deactivating subscription "${plan_id}" of user "${subscription.uid}".`);
1386
1343
  }
1387
1344
  // Update database.
1388
1345
  subscription.status = "cancelled";
@@ -1434,7 +1391,7 @@ export class Paddle {
1434
1391
  }
1435
1392
  // Execute callback.
1436
1393
  if (is_approved) {
1437
- log(0, `Refunded items of payment "${payment.id}" of user "${payment.uid}".`);
1394
+ this.server.log(0, `Refunded items of payment "${payment.id}" of user "${payment.uid}".`);
1438
1395
  await this._exec_user_callback(is_refund ? this.server.on_refund : this.server.on_chargeback, { payment, line_items });
1439
1396
  // try {
1440
1397
  // await this._send_payment_mail({
@@ -1447,7 +1404,7 @@ export class Paddle {
1447
1404
  // }
1448
1405
  }
1449
1406
  else {
1450
- log(0, `Refund denied for items of payment ${payment.id} of user "${payment.uid}".`);
1407
+ this.server.log(0, `Refund denied for items of payment ${payment.id} of user "${payment.uid}".`);
1451
1408
  await this._exec_user_callback(is_refund ? this.server.on_failed_refund : this.server.on_failed_chargeback, { payment, line_items });
1452
1409
  // try {
1453
1410
  // await this._send_payment_mail({
@@ -1466,7 +1423,7 @@ export class Paddle {
1466
1423
  const payment = await this._load_payment_by_transaction(data.transaction_id);
1467
1424
  // Log reactivation subscriptions on chargeback reverse.
1468
1425
  if (payment.sub_id != null) {
1469
- log(0, `Chargeback reversed for payment ${payment.id} from user "${payment.uid}".`);
1426
+ this.server.log(0, `Chargeback reversed for payment ${payment.id} from user "${payment.uid}".`);
1470
1427
  // @todo.
1471
1428
  }
1472
1429
  // Get and update line items.
@@ -1487,8 +1444,8 @@ export class Paddle {
1487
1444
  }
1488
1445
  // Create and register the webhook endpoint.
1489
1446
  async _create_webhook() {
1447
+ /* @performance */ const now = this.performance.start();
1490
1448
  // Register the webhook.
1491
- const webhook_doc = await this._settings_db.load(`webhook${this.server.production ? "" : "_demo"}`);
1492
1449
  const webhook_settings = {
1493
1450
  description: "volt webhook",
1494
1451
  destination: `${this.server.full_domain}/volt/payments/webhook`,
@@ -1515,72 +1472,89 @@ export class Paddle {
1515
1472
  "adjustment.updated",
1516
1473
  ],
1517
1474
  };
1475
+ const hashed_webhook_settings = this.server.hash(webhook_settings);
1518
1476
  // Register webhook.
1519
1477
  const register_webhook = async () => {
1520
- log(0, "Registering payments webhook.");
1478
+ this.server.log(0, "Registering payments webhook.");
1521
1479
  const response = await this._req("POST", "/notification-settings", webhook_settings);
1522
1480
  this.webhook_key = response.data.endpoint_secret_key;
1523
- await this._settings_db.save(`webhook${this.server.production ? "" : "_demo"}`, {
1481
+ await this._webhook_conf_db.set({ production: this.server.production, version: 1 }, {
1524
1482
  id: response.data.id,
1525
1483
  key: this.webhook_key,
1484
+ hash: this.server.hash(webhook_settings),
1526
1485
  });
1527
1486
  };
1528
- // Webhook registered.
1529
- if (webhook_doc != null) {
1530
- this.webhook_key = webhook_doc.key;
1531
- // Check update required.
1532
- const last_webhook = await this._settings_db.load(`last_webhook${this.server.production ? "" : "_demo"}`);
1533
- if (last_webhook !== this.server.hash(webhook_settings)) {
1534
- log(0, `Checking payments webhook.`);
1487
+ // For speeding up the restart process we store the hash of the previous webhook under a temporary document.
1488
+ const home_dir = vlib.Path.home().join(".volt/cache");
1489
+ if (!home_dir.exists()) {
1490
+ home_dir.mkdir({ recursive: true });
1491
+ }
1492
+ const cached_local_hash_file = home_dir.join(`paddle_webhook_${this.server.production ? "live" : "sandbox"}.hash`);
1493
+ const cached_local_hash = cached_local_hash_file.exists() ? (await cached_local_hash_file.load()) : null;
1494
+ if (cached_local_hash !== hashed_webhook_settings) {
1495
+ // Load webhook doc.
1496
+ const webhook_doc = await this._webhook_conf_db.load({ production: this.server.production, version: 1 }, { throw: false });
1497
+ if (webhook_doc instanceof Error && !(webhook_doc instanceof Collection.NotFoundError)) {
1498
+ throw webhook_doc;
1499
+ }
1500
+ // Webhook registered.
1501
+ if (!(webhook_doc instanceof Collection.NotFoundError)) {
1502
+ this.webhook_key = webhook_doc.key;
1535
1503
  // Check update required.
1536
- const webhook_id = webhook_doc.id;
1537
- let registered;
1538
- try {
1539
- registered = await this._req("GET", `/notification-settings/${webhook_id}`);
1540
- }
1541
- catch (error) {
1542
- if (error.status === 404 || error.status_code === 404) {
1543
- registered = undefined;
1544
- await register_webhook();
1545
- }
1546
- else {
1547
- throw error;
1504
+ if (webhook_doc.hash !== hashed_webhook_settings) {
1505
+ this.server.log(0, `Checking payments webhook.`);
1506
+ // Check update required.
1507
+ const webhook_id = webhook_doc.id;
1508
+ let registered;
1509
+ try {
1510
+ registered = await this._req("GET", `/notification-settings/${webhook_id}`);
1548
1511
  }
1549
- }
1550
- if (registered) {
1551
- const item = registered.data;
1552
- const patch = (() => {
1553
- if (item.active !== true ||
1554
- item.destination !== webhook_settings.destination ||
1555
- item.type !== webhook_settings.type ||
1556
- item.description !== webhook_settings.description ||
1557
- item.subscribed_events.length != webhook_settings.subscribed_events.length) {
1558
- return true;
1512
+ catch (error) {
1513
+ if (error.status === 404 || error.status_code === 404) {
1514
+ registered = undefined;
1515
+ await register_webhook();
1516
+ }
1517
+ else {
1518
+ throw error;
1559
1519
  }
1560
- return webhook_settings.subscribed_events.iterate((x) => {
1561
- const found = item.subscribed_events.iterate((y) => {
1562
- if (x === y.name) {
1520
+ }
1521
+ if (registered) {
1522
+ const item = registered.data;
1523
+ const patch = (() => {
1524
+ if (item.active !== true ||
1525
+ item.destination !== webhook_settings.destination ||
1526
+ item.type !== webhook_settings.type ||
1527
+ item.description !== webhook_settings.description ||
1528
+ item.subscribed_events.length != webhook_settings.subscribed_events.length) {
1529
+ return true;
1530
+ }
1531
+ return webhook_settings.subscribed_events.iterate((x) => {
1532
+ const found = item.subscribed_events.iterate((y) => {
1533
+ if (x === y.name) {
1534
+ return true;
1535
+ }
1536
+ });
1537
+ if (found === false) {
1563
1538
  return true;
1564
1539
  }
1565
1540
  });
1566
- if (found === false) {
1567
- return true;
1568
- }
1569
- });
1570
- })();
1571
- // Update.
1572
- if (patch === true) {
1573
- log(0, "Updating payments webhook.");
1574
- await this._req("PATCH", `/notification-settings/${webhook_id}`, { ...webhook_settings, active: true });
1541
+ })();
1542
+ // Update.
1543
+ if (patch === true) {
1544
+ this.server.log(0, "Updating payments webhook.");
1545
+ await this._req("PATCH", `/notification-settings/${webhook_id}`, { ...webhook_settings, active: true });
1546
+ }
1547
+ // Save new hash.
1548
+ await this._webhook_conf_db.set({ production: this.server.production, version: 1 }, { hash: this.server.hash(webhook_settings) });
1575
1549
  }
1576
- // Save.
1577
- await this._settings_db.save(`last_webhook${this.server.production ? "" : "_demo"}`, this.server.hash(webhook_settings));
1578
1550
  }
1579
1551
  }
1580
- }
1581
- // Register webhook.
1582
- else {
1583
- await register_webhook();
1552
+ // Register webhook.
1553
+ else {
1554
+ await register_webhook();
1555
+ }
1556
+ // Save the new hash.
1557
+ await cached_local_hash_file.save(hashed_webhook_settings);
1584
1558
  }
1585
1559
  // Ip whitelist.
1586
1560
  const ip_whitelist = [
@@ -1599,22 +1573,23 @@ export class Paddle {
1599
1573
  "44.241.183.62",
1600
1574
  "100.20.172.113",
1601
1575
  ];
1576
+ /* @performance */ this.server.performance.end("create-payments-webhook", now);
1602
1577
  // Create the endpoint.
1603
1578
  return {
1604
1579
  method: "POST",
1605
- endpoint: "/volt/payments/webhook",
1580
+ endpoint: "/volt/api/v1/payments/webhook",
1606
1581
  content_type: "application/json",
1607
1582
  rate_limit: undefined,
1608
1583
  callback: async (stream) => {
1609
1584
  // Ip whitelist.
1610
1585
  if (ip_whitelist.includes(stream.ip) === false) {
1611
- log(0, `POST:/volt/payments/webhook: Warning: Blocking non whitelisted ip "${stream.ip}".`);
1586
+ this.server.log(0, `POST:/volt/payments/webhook: Warning: Blocking non whitelisted ip "${stream.ip}".`);
1612
1587
  return stream.error({ status: Status.unauthorized });
1613
1588
  }
1614
1589
  // Verify.
1615
1590
  const full_signature = stream.headers["paddle-signature"];
1616
1591
  if (full_signature == null) {
1617
- log(0, "POST:/volt/payments/webhook: Error: No paddle signature found in the request headers.");
1592
+ this.server.log(0, "POST:/volt/payments/webhook: Error: No paddle signature found in the request headers.");
1618
1593
  return stream.error({ status: Status.unauthorized, data: { error: "Webhook signature verification failed." } });
1619
1594
  }
1620
1595
  const ts_index = full_signature.indexOf(";");
@@ -1622,7 +1597,7 @@ export class Paddle {
1622
1597
  const signature = full_signature.substr(ts_index + 4);
1623
1598
  const digest = libcrypto.createHmac("sha256", this.webhook_key).update(`${ts}:${stream.body}`).digest("hex");
1624
1599
  if (libcrypto.timingSafeEqual(Buffer.from(digest, "hex"), Buffer.from(signature, "hex")) !== true) {
1625
- log(0, "POST:/volt/payments/webhook: Error: Webhook signature verification failed.");
1600
+ this.server.log(0, "POST:/volt/payments/webhook: Error: Webhook signature verification failed.");
1626
1601
  return stream.error({ status: Status.unauthorized, data: { error: "Webhook signature verification failed." } });
1627
1602
  }
1628
1603
  // Process items.
@@ -1683,7 +1658,6 @@ export class Paddle {
1683
1658
  }
1684
1659
  return product;
1685
1660
  }
1686
- // Get a payment by id.
1687
1661
  /* @docs:
1688
1662
  @title: Get Payment.
1689
1663
  @desc: Get a payment by id.
@@ -1693,10 +1667,12 @@ export class Paddle {
1693
1667
  @type: string
1694
1668
  @desc: The id of the payment.
1695
1669
  */
1696
- async get_payment(id) {
1670
+ async get_payment(id, opts) {
1671
+ if (opts?.for_public) {
1672
+ return await this._load_payment_for_public(id);
1673
+ }
1697
1674
  return await this._load_payment(id);
1698
1675
  }
1699
- // Get payments.
1700
1676
  /* @docs:
1701
1677
  @title: Get Refunded Payments.
1702
1678
  @desc:
@@ -1725,37 +1701,30 @@ export class Paddle {
1725
1701
  @value: "paid"
1726
1702
  @desc: Payments that are paid.
1727
1703
  */
1728
- async get_payments({ uid, days = 30, limit = undefined, status = undefined, }) {
1704
+ async get_payments({ uid, days = 30, limit = 10_000, status = undefined, for_public, }) {
1729
1705
  // Get path.
1730
- const list = await this._pay_db.list_query({ uid: uid });
1731
- // Get the since time.
1732
- let since = null;
1706
+ const query = {
1707
+ uid,
1708
+ };
1733
1709
  if (days != null) {
1734
- since = new Date();
1710
+ const since = new Date();
1735
1711
  since.setHours(0, 0, 0, 0);
1736
- since = Math.floor(since.getTime() - (3600 * 24 * 1000 * days));
1712
+ query.timestamp = { $gte: Math.floor(since.getTime() - (3600 * 24 * 1000 * days)) };
1737
1713
  }
1738
- // Iterate list.
1739
- const payments = [];
1740
- const status_is_array = Array.isArray(status);
1741
- list.iterate((payment) => {
1742
- if ((since == null || payment.timestamp >= since)) {
1743
- if (status == null ||
1744
- (status_is_array === false && status === payment.status) ||
1745
- (status_is_array && status.includes(payment.status))) {
1746
- payments.append(payment);
1747
- }
1748
- }
1749
- if (limit != null && limit != -1 && payments.length >= limit) {
1750
- return false;
1751
- }
1752
- });
1714
+ if (Array.isArray(status)) {
1715
+ query.status = { $in: status };
1716
+ }
1717
+ else if (typeof status === "string") {
1718
+ query.status = status;
1719
+ }
1720
+ const payments = await this._pay_db.list(query, { limit });
1753
1721
  // Sort.
1754
1722
  payments.sort((a, b) => b.timestamp - a.timestamp);
1755
1723
  // Response.
1756
- return payments;
1724
+ return (for_public
1725
+ ? payments.map(p => Payment.anonymize(p))
1726
+ : payments);
1757
1727
  }
1758
- // Get all refundable payments.
1759
1728
  /* @docs:
1760
1729
  @title: Get Refundable Payments.
1761
1730
  @desc: Get all payments that are refundable.
@@ -1771,24 +1740,17 @@ export class Paddle {
1771
1740
  @type: number
1772
1741
  @desc: Limit the amount of response payment objects.
1773
1742
  */
1774
- async get_refundable_payments({ uid, days = 30, limit = undefined, }) {
1775
- const payments = [];
1776
- const all_payments = await this.get_payments({ uid, days, limit, status: "paid" });
1777
- all_payments.iterate((payment) => {
1778
- const line_items = [];
1779
- payment.line_items.iterate((item) => {
1780
- if (item.status === "paid" && item.total > 0) { // skip total 0 for free trial.
1781
- line_items.push(item);
1782
- }
1783
- });
1784
- if (line_items.length > 0) {
1785
- payment.line_items = line_items;
1786
- payments.push(payment);
1743
+ async get_refundable_payments({ uid, days = 30, limit = undefined, for_public, }) {
1744
+ const out = [];
1745
+ const all_payments = await this.get_payments({ uid, days, limit, status: "paid", for_public });
1746
+ all_payments.iterate((pmt) => {
1747
+ const refundable = pmt.line_items.filter((li) => li.status === "paid" && li.total > 0);
1748
+ if (refundable.length > 0) {
1749
+ out.push({ ...pmt, line_items: refundable });
1787
1750
  }
1788
1751
  });
1789
- return payments;
1752
+ return out;
1790
1753
  }
1791
- // Get all refunded payments.
1792
1754
  /* @docs:
1793
1755
  @title: Get Refunded Payments.
1794
1756
  @desc: Get all payments that are successfully refunded.
@@ -1804,24 +1766,17 @@ export class Paddle {
1804
1766
  @type: number
1805
1767
  @desc: Limit the amount of response payment objects.
1806
1768
  */
1807
- async get_refunded_payments({ uid, days = 30, limit = undefined, }) {
1808
- const payments = [];
1809
- const all_payments = await this.get_payments({ uid, days, limit, status: "paid" });
1810
- all_payments.iterate((payment) => {
1811
- const line_items = [];
1812
- payment.line_items.iterate((item) => {
1813
- if (item.status === "refunded") {
1814
- line_items.push(item);
1815
- }
1816
- });
1817
- if (line_items.length > 0) {
1818
- payment.line_items = line_items;
1819
- payments.push(payment);
1769
+ async get_refunded_payments({ uid, days = 30, limit = undefined, for_public, }) {
1770
+ const out = [];
1771
+ const all_payments = await this.get_payments({ uid, days, limit, status: "paid", for_public });
1772
+ all_payments.iterate((pmt) => {
1773
+ const refundable = pmt.line_items.filter((li) => li.status === "refunded" && li.total > 0);
1774
+ if (refundable.length > 0) {
1775
+ out.push({ ...pmt, line_items: refundable });
1820
1776
  }
1821
1777
  });
1822
- return payments;
1778
+ return out;
1823
1779
  }
1824
- // Get all payments that are currently in the refunding process.
1825
1780
  /* @docs:
1826
1781
  @title: Get Refunding Payments.
1827
1782
  @desc: Get all payments that are currently in the refunding process.
@@ -1837,24 +1792,17 @@ export class Paddle {
1837
1792
  @type: number
1838
1793
  @desc: Limit the amount of response payment objects.
1839
1794
  */
1840
- async get_refunding_payments({ uid, days = undefined, limit = undefined, }) {
1841
- const payments = [];
1842
- const all_payments = await this.get_payments({ uid, days, limit, status: "paid" });
1843
- all_payments.iterate((payment) => {
1844
- const line_items = [];
1845
- payment.line_items.iterate((item) => {
1846
- if (item.status === "refunding") {
1847
- line_items.push(item);
1848
- }
1849
- });
1850
- if (line_items.length > 0) {
1851
- payment.line_items = line_items;
1852
- payments.push(payment);
1795
+ async get_refunding_payments({ uid, days = undefined, limit = undefined, for_public, }) {
1796
+ const out = [];
1797
+ const all_payments = await this.get_payments({ uid, days, limit, status: "paid", for_public });
1798
+ all_payments.iterate((pmt) => {
1799
+ const refundable = pmt.line_items.filter((li) => li.status === "refunding" && li.total > 0);
1800
+ if (refundable.length > 0) {
1801
+ out.push({ ...pmt, line_items: refundable });
1853
1802
  }
1854
1803
  });
1855
- return payments;
1804
+ return out;
1856
1805
  }
1857
- // Refund a payment.
1858
1806
  /* @docs:
1859
1807
  @title: Refund Payment.
1860
1808
  @desc: Refund a payment based on the payment id.
@@ -1939,7 +1887,6 @@ export class Paddle {
1939
1887
  // Update the payment object.
1940
1888
  await this._save_payment(payment);
1941
1889
  }
1942
- // Cancel a subscription.
1943
1890
  /* @docs:
1944
1891
  @title: Cancel Subscription.
1945
1892
  @desc: Cancel a subscription based on the retrieved payment object or id.
@@ -1980,7 +1927,6 @@ export class Paddle {
1980
1927
  });
1981
1928
  }
1982
1929
  }
1983
- // Cancel subscription by subscription id.
1984
1930
  /* @docs:
1985
1931
  @title: Cancel subscription by subscription id.
1986
1932
  @desc: Cancel a subscription based on the retrieved subscription object or id.
@@ -2001,7 +1947,6 @@ export class Paddle {
2001
1947
  }
2002
1948
  return await this._cancel_subscription(subscription, immediate);
2003
1949
  }
2004
- // Get subscriptioms.
2005
1950
  /* @docs:
2006
1951
  @title: Get active subscriptions
2007
1952
  @desc: Get the active subscriptions of a user.
@@ -2022,7 +1967,6 @@ export class Paddle {
2022
1967
  async get_subscriptions(uid) {
2023
1968
  return await this._get_subscriptions(uid);
2024
1969
  }
2025
- // Is subscribed.
2026
1970
  /* @docs:
2027
1971
  @title: Is Subscribed
2028
1972
  @desc: Check if a user is subscribed to a product.
@@ -2038,7 +1982,6 @@ export class Paddle {
2038
1982
  async is_subscribed(uid, product) {
2039
1983
  return await this._check_subscription(uid, product, false);
2040
1984
  }
2041
- // Generate an invoice.
2042
1985
  /* @docs:
2043
1986
  @title: Generate Invoice
2044
1987
  @desc:
@@ -2248,17 +2191,24 @@ export class Paddle {
2248
2191
  // doc.pipe(fs.createWriteStream(path.str()));
2249
2192
  // return path;
2250
2193
  // Get as bytes.
2251
- const stream = doc.pipe(blobstream());
2252
- doc.end();
2253
- return new Promise((resolve, reject) => {
2254
- stream.on('finish', () => {
2255
- const bytes = stream.toBuffer();
2256
- resolve(bytes);
2257
- });
2258
- stream.on('error', (error) => {
2259
- reject(error);
2260
- });
2194
+ const chunks = [];
2195
+ return await new Promise((resolve, reject) => {
2196
+ doc.on("data", (chunk) => chunks.push(chunk));
2197
+ doc.on("end", () => resolve(Buffer.concat(chunks)));
2198
+ doc.on("error", (err) => reject(err));
2199
+ doc.end();
2261
2200
  });
2201
+ // const stream = doc.pipe(blobstream());
2202
+ // doc.end();
2203
+ // return new Promise((resolve, reject) => {
2204
+ // stream.on('finish', () => {
2205
+ // const bytes = stream.toBuffer();
2206
+ // resolve(bytes);
2207
+ // });
2208
+ // stream.on('error', (error) => {
2209
+ // reject(error);
2210
+ // });
2211
+ // });
2262
2212
  }
2263
2213
  // ---------------------------------------------------------
2264
2214
  // Development.
@@ -2280,7 +2230,7 @@ export class Paddle {
2280
2230
  // Cancel.
2281
2231
  for (const sub of subs) {
2282
2232
  if (sub.status === "active") {
2283
- console.log("Cancelling subscription", sub.id);
2233
+ this.server.log("Cancelling subscription ", sub.id);
2284
2234
  await this._req("POST", `/subscriptions/${sub.id}/cancel`, {
2285
2235
  effective_from: "immediately",
2286
2236
  });
@@ -2288,4 +2238,19 @@ export class Paddle {
2288
2238
  }
2289
2239
  }
2290
2240
  }
2291
- export default Paddle;
2241
+ /** Nested types for the {@link Paddle} class */
2242
+ (function (Paddle) {
2243
+ /** Paddle api request error. */
2244
+ class RequestError extends Error {
2245
+ status_code;
2246
+ constructor(err, status_code) {
2247
+ super(err);
2248
+ this.status_code = status_code;
2249
+ }
2250
+ }
2251
+ Paddle.RequestError = RequestError;
2252
+ })(Paddle || (Paddle = {}));
2253
+ // APPLY_FIX
2254
+ /**
2255
+ * @todo if undeprecate: ASK claude to audit.
2256
+ */