@vandenberghinc/volt 1.2.5 → 1.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (489) hide show
  1. package/frontend/assets/admin/admin.png +0 -0
  2. package/frontend/assets/admin/password.webp +0 -0
  3. package/frontend/assets/icons/arrow.v1.webp +0 -0
  4. package/frontend/assets/icons/copy.webp +0 -0
  5. package/frontend/assets/payments/arrow.long.webp +0 -0
  6. package/frontend/assets/payments/arrow.long2.webp +0 -0
  7. package/frontend/assets/payments/cancelled.webp +0 -0
  8. package/frontend/assets/payments/check.sign.webp +0 -0
  9. package/frontend/assets/payments/check.webp +0 -0
  10. package/frontend/assets/payments/close.webp +0 -0
  11. package/frontend/assets/payments/error.webp +0 -0
  12. package/frontend/assets/payments/exclamation.webp +0 -0
  13. package/frontend/assets/payments/minus.webp +0 -0
  14. package/frontend/assets/payments/party.webp +0 -0
  15. package/frontend/assets/payments/plus.webp +0 -0
  16. package/frontend/assets/payments/shopping_cart.webp +0 -0
  17. package/frontend/assets/payments/trash.webp +0 -0
  18. package/package.json +5 -1
  19. package/.libris/config.json +0 -82
  20. package/backend/dist/cjs/backend/src/blacklist.d.ts +0 -12
  21. package/backend/dist/cjs/backend/src/blacklist.js +0 -78
  22. package/backend/dist/cjs/backend/src/cli.d.ts +0 -2
  23. package/backend/dist/cjs/backend/src/cli.js +0 -198
  24. package/backend/dist/cjs/backend/src/database/collection.d.ts +0 -1765
  25. package/backend/dist/cjs/backend/src/database/collection.js +0 -3301
  26. package/backend/dist/cjs/backend/src/database/database.d.ts +0 -92
  27. package/backend/dist/cjs/backend/src/database/database.js +0 -170
  28. package/backend/dist/cjs/backend/src/database/document.d.ts +0 -1
  29. package/backend/dist/cjs/backend/src/database/document.js +0 -15
  30. package/backend/dist/cjs/backend/src/database/filters/filters.d.ts +0 -6
  31. package/backend/dist/cjs/backend/src/database/filters/filters.js +0 -15
  32. package/backend/dist/cjs/backend/src/database/filters/strict_filter.d.ts +0 -223
  33. package/backend/dist/cjs/backend/src/database/filters/strict_filter.js +0 -15
  34. package/backend/dist/cjs/backend/src/database/filters/strict_filter_test.d.ts +0 -1
  35. package/backend/dist/cjs/backend/src/database/filters/strict_filter_test.js +0 -443
  36. package/backend/dist/cjs/backend/src/database/filters/strict_filter_test_v0.d.ts +0 -1
  37. package/backend/dist/cjs/backend/src/database/filters/strict_filter_test_v0.js +0 -15
  38. package/backend/dist/cjs/backend/src/database/filters/strict_filter_v0.d.ts +0 -50
  39. package/backend/dist/cjs/backend/src/database/filters/strict_filter_v0.js +0 -15
  40. package/backend/dist/cjs/backend/src/database/filters/strict_filter_v1.d.ts +0 -76
  41. package/backend/dist/cjs/backend/src/database/filters/strict_filter_v1.js +0 -15
  42. package/backend/dist/cjs/backend/src/database/filters/strict_filter_v2.d.ts +0 -75
  43. package/backend/dist/cjs/backend/src/database/filters/strict_filter_v2.js +0 -15
  44. package/backend/dist/cjs/backend/src/database/filters/strict_filter_v3.d.ts +0 -219
  45. package/backend/dist/cjs/backend/src/database/filters/strict_filter_v3.js +0 -15
  46. package/backend/dist/cjs/backend/src/database/filters/strict_update_filter.d.ts +0 -165
  47. package/backend/dist/cjs/backend/src/database/filters/strict_update_filter.js +0 -15
  48. package/backend/dist/cjs/backend/src/database/filters/strict_update_filter_test.d.ts +0 -5
  49. package/backend/dist/cjs/backend/src/database/filters/strict_update_filter_test.js +0 -355
  50. package/backend/dist/cjs/backend/src/database/flatten.d.ts +0 -78
  51. package/backend/dist/cjs/backend/src/database/flatten.js +0 -53
  52. package/backend/dist/cjs/backend/src/database/flatten_test.d.ts +0 -1
  53. package/backend/dist/cjs/backend/src/database/flatten_test.js +0 -175
  54. package/backend/dist/cjs/backend/src/database/quota/quoata_v2.d.ts +0 -533
  55. package/backend/dist/cjs/backend/src/database/quota/quoata_v2.js +0 -1046
  56. package/backend/dist/cjs/backend/src/database/quota/quota.d.ts +0 -551
  57. package/backend/dist/cjs/backend/src/database/quota/quota.js +0 -1108
  58. package/backend/dist/cjs/backend/src/database/quota/quota_v1.d.ts +0 -534
  59. package/backend/dist/cjs/backend/src/database/quota/quota_v1.js +0 -1087
  60. package/backend/dist/cjs/backend/src/database/quota/safe_int.d.ts +0 -412
  61. package/backend/dist/cjs/backend/src/database/quota/safe_int.js +0 -745
  62. package/backend/dist/cjs/backend/src/endpoint.d.ts +0 -346
  63. package/backend/dist/cjs/backend/src/endpoint.js +0 -468
  64. package/backend/dist/cjs/backend/src/errors/index.d.ts +0 -7
  65. package/backend/dist/cjs/backend/src/errors/index.js +0 -25
  66. package/backend/dist/cjs/backend/src/errors/internal_external.d.ts +0 -52
  67. package/backend/dist/cjs/backend/src/errors/internal_external.js +0 -95
  68. package/backend/dist/cjs/backend/src/errors/invalid_usage_error.d.ts +0 -41
  69. package/backend/dist/cjs/backend/src/errors/invalid_usage_error.js +0 -47
  70. package/backend/dist/cjs/backend/src/errors/system_error.d.ts +0 -261
  71. package/backend/dist/cjs/backend/src/errors/system_error.js +0 -436
  72. package/backend/dist/cjs/backend/src/events.d.ts +0 -97
  73. package/backend/dist/cjs/backend/src/events.js +0 -15
  74. package/backend/dist/cjs/backend/src/frontend.d.ts +0 -11
  75. package/backend/dist/cjs/backend/src/frontend.js +0 -37
  76. package/backend/dist/cjs/backend/src/image_endpoint.d.ts +0 -44
  77. package/backend/dist/cjs/backend/src/image_endpoint.js +0 -185
  78. package/backend/dist/cjs/backend/src/index.d.ts +0 -23
  79. package/backend/dist/cjs/backend/src/index.js +0 -70
  80. package/backend/dist/cjs/backend/src/logger.d.ts +0 -5
  81. package/backend/dist/cjs/backend/src/logger.js +0 -15
  82. package/backend/dist/cjs/backend/src/meta.d.ts +0 -112
  83. package/backend/dist/cjs/backend/src/meta.js +0 -181
  84. package/backend/dist/cjs/backend/src/payments/paddle.d.ts +0 -329
  85. package/backend/dist/cjs/backend/src/payments/paddle.js +0 -1996
  86. package/backend/dist/cjs/backend/src/payments/stripe/checkout.d.ts +0 -113
  87. package/backend/dist/cjs/backend/src/payments/stripe/checkout.js +0 -295
  88. package/backend/dist/cjs/backend/src/payments/stripe/customers.d.ts +0 -17
  89. package/backend/dist/cjs/backend/src/payments/stripe/customers.js +0 -164
  90. package/backend/dist/cjs/backend/src/payments/stripe/error.d.ts +0 -74
  91. package/backend/dist/cjs/backend/src/payments/stripe/error.js +0 -64
  92. package/backend/dist/cjs/backend/src/payments/stripe/events.d.ts +0 -155
  93. package/backend/dist/cjs/backend/src/payments/stripe/events.js +0 -15
  94. package/backend/dist/cjs/backend/src/payments/stripe/meters.d.ts +0 -105
  95. package/backend/dist/cjs/backend/src/payments/stripe/meters.js +0 -230
  96. package/backend/dist/cjs/backend/src/payments/stripe/payment_methods.d.ts +0 -58
  97. package/backend/dist/cjs/backend/src/payments/stripe/payment_methods.js +0 -109
  98. package/backend/dist/cjs/backend/src/payments/stripe/products.d.ts +0 -519
  99. package/backend/dist/cjs/backend/src/payments/stripe/products.js +0 -650
  100. package/backend/dist/cjs/backend/src/payments/stripe/stripe.d.ts +0 -215
  101. package/backend/dist/cjs/backend/src/payments/stripe/stripe.js +0 -468
  102. package/backend/dist/cjs/backend/src/payments/stripe/subscriptions.d.ts +0 -172
  103. package/backend/dist/cjs/backend/src/payments/stripe/subscriptions.js +0 -557
  104. package/backend/dist/cjs/backend/src/payments/stripe/utils.d.ts +0 -63
  105. package/backend/dist/cjs/backend/src/payments/stripe/utils.js +0 -118
  106. package/backend/dist/cjs/backend/src/payments/stripe/webhooks.d.ts +0 -105
  107. package/backend/dist/cjs/backend/src/payments/stripe/webhooks.js +0 -627
  108. package/backend/dist/cjs/backend/src/plugins/browser.d.ts +0 -1
  109. package/backend/dist/cjs/backend/src/plugins/browser.js +0 -15
  110. package/backend/dist/cjs/backend/src/plugins/communication.d.ts +0 -70
  111. package/backend/dist/cjs/backend/src/plugins/communication.js +0 -196
  112. package/backend/dist/cjs/backend/src/plugins/mail/mail.d.ts +0 -255
  113. package/backend/dist/cjs/backend/src/plugins/mail/mail.js +0 -381
  114. package/backend/dist/cjs/backend/src/plugins/mail/ui.d.ts +0 -297
  115. package/backend/dist/cjs/backend/src/plugins/mail/ui.js +0 -1370
  116. package/backend/dist/cjs/backend/src/plugins/pdf.d.ts +0 -1
  117. package/backend/dist/cjs/backend/src/plugins/pdf.js +0 -1456
  118. package/backend/dist/cjs/backend/src/plugins/thread_monitor.d.ts +0 -18
  119. package/backend/dist/cjs/backend/src/plugins/thread_monitor.js +0 -116
  120. package/backend/dist/cjs/backend/src/rate_limit.d.ts +0 -148
  121. package/backend/dist/cjs/backend/src/rate_limit.js +0 -543
  122. package/backend/dist/cjs/backend/src/route.d.ts +0 -39
  123. package/backend/dist/cjs/backend/src/route.js +0 -172
  124. package/backend/dist/cjs/backend/src/server.d.ts +0 -502
  125. package/backend/dist/cjs/backend/src/server.js +0 -1713
  126. package/backend/dist/cjs/backend/src/server.old.d.ts +0 -594
  127. package/backend/dist/cjs/backend/src/server.old.js +0 -2058
  128. package/backend/dist/cjs/backend/src/splash_screen.d.ts +0 -93
  129. package/backend/dist/cjs/backend/src/splash_screen.js +0 -119
  130. package/backend/dist/cjs/backend/src/status.d.ts +0 -89
  131. package/backend/dist/cjs/backend/src/status.js +0 -211
  132. package/backend/dist/cjs/backend/src/stream.d.ts +0 -494
  133. package/backend/dist/cjs/backend/src/stream.js +0 -1370
  134. package/backend/dist/cjs/backend/src/users.d.ts +0 -926
  135. package/backend/dist/cjs/backend/src/users.js +0 -2223
  136. package/backend/dist/cjs/backend/src/utils.d.ts +0 -22
  137. package/backend/dist/cjs/backend/src/utils.js +0 -626
  138. package/backend/dist/cjs/backend/src/view.d.ts +0 -115
  139. package/backend/dist/cjs/backend/src/view.js +0 -519
  140. package/backend/dist/cjs/backend/src/vinc.d.ts +0 -6
  141. package/backend/dist/cjs/backend/src/vinc.js +0 -40
  142. package/backend/dist/cjs/backend/src/volt.d.ts +0 -24
  143. package/backend/dist/cjs/backend/src/volt.js +0 -72
  144. package/backend/dist/cjs/frontend/src/modules/request.d.ts +0 -70
  145. package/backend/dist/cjs/frontend/src/modules/request.js +0 -99
  146. package/backend/dist/cjs/package.json +0 -1
  147. package/backend/dist/esm/backend/src/blacklist.d.ts +0 -12
  148. package/backend/dist/esm/backend/src/blacklist.js +0 -52
  149. package/backend/dist/esm/backend/src/cli.d.ts +0 -2
  150. package/backend/dist/esm/backend/src/cli.js +0 -211
  151. package/backend/dist/esm/backend/src/database/collection.d.ts +0 -1765
  152. package/backend/dist/esm/backend/src/database/collection.js +0 -3779
  153. package/backend/dist/esm/backend/src/database/database.d.ts +0 -92
  154. package/backend/dist/esm/backend/src/database/database.js +0 -214
  155. package/backend/dist/esm/backend/src/database/document.d.ts +0 -1
  156. package/backend/dist/esm/backend/src/database/document.js +0 -558
  157. package/backend/dist/esm/backend/src/database/filters/filters.d.ts +0 -6
  158. package/backend/dist/esm/backend/src/database/filters/filters.js +0 -1
  159. package/backend/dist/esm/backend/src/database/filters/strict_filter.d.ts +0 -223
  160. package/backend/dist/esm/backend/src/database/filters/strict_filter.js +0 -3
  161. package/backend/dist/esm/backend/src/database/filters/strict_filter_test.d.ts +0 -1
  162. package/backend/dist/esm/backend/src/database/filters/strict_filter_test.js +0 -505
  163. package/backend/dist/esm/backend/src/database/filters/strict_filter_test_v0.d.ts +0 -1
  164. package/backend/dist/esm/backend/src/database/filters/strict_filter_test_v0.js +0 -712
  165. package/backend/dist/esm/backend/src/database/filters/strict_filter_v0.d.ts +0 -50
  166. package/backend/dist/esm/backend/src/database/filters/strict_filter_v0.js +0 -5
  167. package/backend/dist/esm/backend/src/database/filters/strict_filter_v1.d.ts +0 -76
  168. package/backend/dist/esm/backend/src/database/filters/strict_filter_v1.js +0 -44
  169. package/backend/dist/esm/backend/src/database/filters/strict_filter_v2.d.ts +0 -75
  170. package/backend/dist/esm/backend/src/database/filters/strict_filter_v2.js +0 -5
  171. package/backend/dist/esm/backend/src/database/filters/strict_filter_v3.d.ts +0 -219
  172. package/backend/dist/esm/backend/src/database/filters/strict_filter_v3.js +0 -1
  173. package/backend/dist/esm/backend/src/database/filters/strict_update_filter.d.ts +0 -165
  174. package/backend/dist/esm/backend/src/database/filters/strict_update_filter.js +0 -5
  175. package/backend/dist/esm/backend/src/database/filters/strict_update_filter_test.d.ts +0 -5
  176. package/backend/dist/esm/backend/src/database/filters/strict_update_filter_test.js +0 -415
  177. package/backend/dist/esm/backend/src/database/flatten.d.ts +0 -78
  178. package/backend/dist/esm/backend/src/database/flatten.js +0 -22
  179. package/backend/dist/esm/backend/src/database/flatten_test.d.ts +0 -1
  180. package/backend/dist/esm/backend/src/database/flatten_test.js +0 -174
  181. package/backend/dist/esm/backend/src/database/quota/quoata_v2.d.ts +0 -533
  182. package/backend/dist/esm/backend/src/database/quota/quoata_v2.js +0 -1155
  183. package/backend/dist/esm/backend/src/database/quota/quota.d.ts +0 -551
  184. package/backend/dist/esm/backend/src/database/quota/quota.js +0 -1219
  185. package/backend/dist/esm/backend/src/database/quota/quota_v1.d.ts +0 -534
  186. package/backend/dist/esm/backend/src/database/quota/quota_v1.js +0 -1242
  187. package/backend/dist/esm/backend/src/database/quota/safe_int.d.ts +0 -412
  188. package/backend/dist/esm/backend/src/database/quota/safe_int.js +0 -810
  189. package/backend/dist/esm/backend/src/endpoint.d.ts +0 -346
  190. package/backend/dist/esm/backend/src/endpoint.js +0 -479
  191. package/backend/dist/esm/backend/src/errors/index.d.ts +0 -7
  192. package/backend/dist/esm/backend/src/errors/index.js +0 -7
  193. package/backend/dist/esm/backend/src/errors/internal_external.d.ts +0 -52
  194. package/backend/dist/esm/backend/src/errors/internal_external.js +0 -86
  195. package/backend/dist/esm/backend/src/errors/invalid_usage_error.d.ts +0 -41
  196. package/backend/dist/esm/backend/src/errors/invalid_usage_error.js +0 -33
  197. package/backend/dist/esm/backend/src/errors/system_error.d.ts +0 -261
  198. package/backend/dist/esm/backend/src/errors/system_error.js +0 -444
  199. package/backend/dist/esm/backend/src/events.d.ts +0 -97
  200. package/backend/dist/esm/backend/src/events.js +0 -5
  201. package/backend/dist/esm/backend/src/frontend.d.ts +0 -11
  202. package/backend/dist/esm/backend/src/frontend.js +0 -12
  203. package/backend/dist/esm/backend/src/image_endpoint.d.ts +0 -44
  204. package/backend/dist/esm/backend/src/image_endpoint.js +0 -196
  205. package/backend/dist/esm/backend/src/index.d.ts +0 -23
  206. package/backend/dist/esm/backend/src/index.js +0 -26
  207. package/backend/dist/esm/backend/src/logger.d.ts +0 -5
  208. package/backend/dist/esm/backend/src/logger.js +0 -8
  209. package/backend/dist/esm/backend/src/meta.d.ts +0 -112
  210. package/backend/dist/esm/backend/src/meta.js +0 -152
  211. package/backend/dist/esm/backend/src/payments/paddle.d.ts +0 -329
  212. package/backend/dist/esm/backend/src/payments/paddle.js +0 -2276
  213. package/backend/dist/esm/backend/src/payments/stripe/checkout.d.ts +0 -113
  214. package/backend/dist/esm/backend/src/payments/stripe/checkout.js +0 -356
  215. package/backend/dist/esm/backend/src/payments/stripe/customers.d.ts +0 -17
  216. package/backend/dist/esm/backend/src/payments/stripe/customers.js +0 -193
  217. package/backend/dist/esm/backend/src/payments/stripe/error.d.ts +0 -74
  218. package/backend/dist/esm/backend/src/payments/stripe/error.js +0 -51
  219. package/backend/dist/esm/backend/src/payments/stripe/events.d.ts +0 -155
  220. package/backend/dist/esm/backend/src/payments/stripe/events.js +0 -5
  221. package/backend/dist/esm/backend/src/payments/stripe/meters.d.ts +0 -105
  222. package/backend/dist/esm/backend/src/payments/stripe/meters.js +0 -318
  223. package/backend/dist/esm/backend/src/payments/stripe/payment_methods.d.ts +0 -58
  224. package/backend/dist/esm/backend/src/payments/stripe/payment_methods.js +0 -135
  225. package/backend/dist/esm/backend/src/payments/stripe/products.d.ts +0 -519
  226. package/backend/dist/esm/backend/src/payments/stripe/products.js +0 -896
  227. package/backend/dist/esm/backend/src/payments/stripe/stripe.d.ts +0 -215
  228. package/backend/dist/esm/backend/src/payments/stripe/stripe.js +0 -464
  229. package/backend/dist/esm/backend/src/payments/stripe/subscriptions.d.ts +0 -172
  230. package/backend/dist/esm/backend/src/payments/stripe/subscriptions.js +0 -754
  231. package/backend/dist/esm/backend/src/payments/stripe/utils.d.ts +0 -63
  232. package/backend/dist/esm/backend/src/payments/stripe/utils.js +0 -131
  233. package/backend/dist/esm/backend/src/payments/stripe/webhooks.d.ts +0 -105
  234. package/backend/dist/esm/backend/src/payments/stripe/webhooks.js +0 -752
  235. package/backend/dist/esm/backend/src/plugins/browser.d.ts +0 -1
  236. package/backend/dist/esm/backend/src/plugins/browser.js +0 -170
  237. package/backend/dist/esm/backend/src/plugins/communication.d.ts +0 -70
  238. package/backend/dist/esm/backend/src/plugins/communication.js +0 -169
  239. package/backend/dist/esm/backend/src/plugins/mail/mail.d.ts +0 -255
  240. package/backend/dist/esm/backend/src/plugins/mail/mail.js +0 -396
  241. package/backend/dist/esm/backend/src/plugins/mail/ui.d.ts +0 -297
  242. package/backend/dist/esm/backend/src/plugins/mail/ui.js +0 -1400
  243. package/backend/dist/esm/backend/src/plugins/pdf.d.ts +0 -1
  244. package/backend/dist/esm/backend/src/plugins/pdf.js +0 -1694
  245. package/backend/dist/esm/backend/src/plugins/thread_monitor.d.ts +0 -18
  246. package/backend/dist/esm/backend/src/plugins/thread_monitor.js +0 -120
  247. package/backend/dist/esm/backend/src/rate_limit.d.ts +0 -148
  248. package/backend/dist/esm/backend/src/rate_limit.js +0 -667
  249. package/backend/dist/esm/backend/src/route.d.ts +0 -39
  250. package/backend/dist/esm/backend/src/route.js +0 -222
  251. package/backend/dist/esm/backend/src/server.d.ts +0 -502
  252. package/backend/dist/esm/backend/src/server.js +0 -2034
  253. package/backend/dist/esm/backend/src/server.old.d.ts +0 -594
  254. package/backend/dist/esm/backend/src/server.old.js +0 -2630
  255. package/backend/dist/esm/backend/src/splash_screen.d.ts +0 -93
  256. package/backend/dist/esm/backend/src/splash_screen.js +0 -156
  257. package/backend/dist/esm/backend/src/status.d.ts +0 -89
  258. package/backend/dist/esm/backend/src/status.js +0 -213
  259. package/backend/dist/esm/backend/src/stream.d.ts +0 -494
  260. package/backend/dist/esm/backend/src/stream.js +0 -1611
  261. package/backend/dist/esm/backend/src/users.d.ts +0 -926
  262. package/backend/dist/esm/backend/src/users.js +0 -2423
  263. package/backend/dist/esm/backend/src/utils.d.ts +0 -22
  264. package/backend/dist/esm/backend/src/utils.js +0 -463
  265. package/backend/dist/esm/backend/src/view.d.ts +0 -115
  266. package/backend/dist/esm/backend/src/view.js +0 -584
  267. package/backend/dist/esm/backend/src/vinc.d.ts +0 -6
  268. package/backend/dist/esm/backend/src/vinc.js +0 -6
  269. package/backend/dist/esm/backend/src/volt.d.ts +0 -24
  270. package/backend/dist/esm/backend/src/volt.js +0 -27
  271. package/backend/dist/esm/frontend/src/modules/request.d.ts +0 -70
  272. package/backend/dist/esm/frontend/src/modules/request.js +0 -117
  273. package/backend/old/file_watcher.ts +0 -359
  274. package/backend/old/request.deprc.js +0 -626
  275. package/backend/old/response.deprc.js +0 -354
  276. package/frontend/dist/backend/src/database/collection.d.ts +0 -1765
  277. package/frontend/dist/backend/src/database/collection.js +0 -3779
  278. package/frontend/dist/backend/src/database/database.d.ts +0 -92
  279. package/frontend/dist/backend/src/database/database.js +0 -214
  280. package/frontend/dist/backend/src/database/filters/filters.d.ts +0 -6
  281. package/frontend/dist/backend/src/database/filters/filters.js +0 -1
  282. package/frontend/dist/backend/src/database/filters/strict_filter.d.ts +0 -223
  283. package/frontend/dist/backend/src/database/filters/strict_filter.js +0 -3
  284. package/frontend/dist/backend/src/database/filters/strict_update_filter.d.ts +0 -165
  285. package/frontend/dist/backend/src/database/filters/strict_update_filter.js +0 -5
  286. package/frontend/dist/backend/src/database/flatten.d.ts +0 -78
  287. package/frontend/dist/backend/src/database/flatten.js +0 -22
  288. package/frontend/dist/backend/src/endpoint.d.ts +0 -346
  289. package/frontend/dist/backend/src/endpoint.js +0 -479
  290. package/frontend/dist/backend/src/errors/index.d.ts +0 -7
  291. package/frontend/dist/backend/src/errors/index.js +0 -7
  292. package/frontend/dist/backend/src/errors/internal_external.d.ts +0 -52
  293. package/frontend/dist/backend/src/errors/internal_external.js +0 -86
  294. package/frontend/dist/backend/src/errors/invalid_usage_error.d.ts +0 -41
  295. package/frontend/dist/backend/src/errors/invalid_usage_error.js +0 -33
  296. package/frontend/dist/backend/src/errors/system_error.d.ts +0 -261
  297. package/frontend/dist/backend/src/errors/system_error.js +0 -444
  298. package/frontend/dist/backend/src/events.d.ts +0 -97
  299. package/frontend/dist/backend/src/events.js +0 -5
  300. package/frontend/dist/backend/src/frontend.d.ts +0 -11
  301. package/frontend/dist/backend/src/frontend.js +0 -12
  302. package/frontend/dist/backend/src/image_endpoint.d.ts +0 -44
  303. package/frontend/dist/backend/src/image_endpoint.js +0 -196
  304. package/frontend/dist/backend/src/meta.d.ts +0 -112
  305. package/frontend/dist/backend/src/meta.js +0 -152
  306. package/frontend/dist/backend/src/payments/paddle.d.ts +0 -329
  307. package/frontend/dist/backend/src/payments/paddle.js +0 -2276
  308. package/frontend/dist/backend/src/payments/stripe/checkout.d.ts +0 -113
  309. package/frontend/dist/backend/src/payments/stripe/checkout.js +0 -356
  310. package/frontend/dist/backend/src/payments/stripe/customers.d.ts +0 -17
  311. package/frontend/dist/backend/src/payments/stripe/customers.js +0 -193
  312. package/frontend/dist/backend/src/payments/stripe/error.d.ts +0 -74
  313. package/frontend/dist/backend/src/payments/stripe/error.js +0 -51
  314. package/frontend/dist/backend/src/payments/stripe/events.d.ts +0 -155
  315. package/frontend/dist/backend/src/payments/stripe/events.js +0 -5
  316. package/frontend/dist/backend/src/payments/stripe/meters.d.ts +0 -105
  317. package/frontend/dist/backend/src/payments/stripe/meters.js +0 -318
  318. package/frontend/dist/backend/src/payments/stripe/payment_methods.d.ts +0 -58
  319. package/frontend/dist/backend/src/payments/stripe/payment_methods.js +0 -135
  320. package/frontend/dist/backend/src/payments/stripe/products.d.ts +0 -519
  321. package/frontend/dist/backend/src/payments/stripe/products.js +0 -896
  322. package/frontend/dist/backend/src/payments/stripe/stripe.d.ts +0 -215
  323. package/frontend/dist/backend/src/payments/stripe/stripe.js +0 -464
  324. package/frontend/dist/backend/src/payments/stripe/subscriptions.d.ts +0 -172
  325. package/frontend/dist/backend/src/payments/stripe/subscriptions.js +0 -754
  326. package/frontend/dist/backend/src/payments/stripe/utils.d.ts +0 -63
  327. package/frontend/dist/backend/src/payments/stripe/utils.js +0 -131
  328. package/frontend/dist/backend/src/payments/stripe/webhooks.d.ts +0 -105
  329. package/frontend/dist/backend/src/payments/stripe/webhooks.js +0 -752
  330. package/frontend/dist/backend/src/plugins/mail/mail.d.ts +0 -255
  331. package/frontend/dist/backend/src/plugins/mail/mail.js +0 -396
  332. package/frontend/dist/backend/src/plugins/mail/ui.d.ts +0 -297
  333. package/frontend/dist/backend/src/plugins/mail/ui.js +0 -1400
  334. package/frontend/dist/backend/src/rate_limit.d.ts +0 -148
  335. package/frontend/dist/backend/src/rate_limit.js +0 -667
  336. package/frontend/dist/backend/src/route.d.ts +0 -39
  337. package/frontend/dist/backend/src/route.js +0 -222
  338. package/frontend/dist/backend/src/server.d.ts +0 -502
  339. package/frontend/dist/backend/src/server.js +0 -2034
  340. package/frontend/dist/backend/src/splash_screen.d.ts +0 -93
  341. package/frontend/dist/backend/src/splash_screen.js +0 -156
  342. package/frontend/dist/backend/src/status.d.ts +0 -89
  343. package/frontend/dist/backend/src/status.js +0 -213
  344. package/frontend/dist/backend/src/stream.d.ts +0 -494
  345. package/frontend/dist/backend/src/stream.js +0 -1611
  346. package/frontend/dist/backend/src/users.d.ts +0 -926
  347. package/frontend/dist/backend/src/users.js +0 -2423
  348. package/frontend/dist/backend/src/utils.d.ts +0 -22
  349. package/frontend/dist/backend/src/utils.js +0 -463
  350. package/frontend/dist/backend/src/view.d.ts +0 -115
  351. package/frontend/dist/backend/src/view.js +0 -584
  352. package/frontend/dist/frontend/src/elements/base.d.ts +0 -3743
  353. package/frontend/dist/frontend/src/elements/base.js +0 -12151
  354. package/frontend/dist/frontend/src/elements/module.d.ts +0 -95
  355. package/frontend/dist/frontend/src/elements/module.js +0 -216
  356. package/frontend/dist/frontend/src/elements/register_element.d.ts +0 -3
  357. package/frontend/dist/frontend/src/elements/register_element.js +0 -22
  358. package/frontend/dist/frontend/src/elements/resize_query_manager.d.ts +0 -0
  359. package/frontend/dist/frontend/src/elements/resize_query_manager.js +0 -150
  360. package/frontend/dist/frontend/src/elements/types.d.ts +0 -52
  361. package/frontend/dist/frontend/src/elements/types.js +0 -5
  362. package/frontend/dist/frontend/src/index.d.ts +0 -21
  363. package/frontend/dist/frontend/src/index.js +0 -29
  364. package/frontend/dist/frontend/src/modules/attachment.d.ts +0 -126
  365. package/frontend/dist/frontend/src/modules/attachment.js +0 -306
  366. package/frontend/dist/frontend/src/modules/auth.d.ts +0 -44
  367. package/frontend/dist/frontend/src/modules/auth.js +0 -80
  368. package/frontend/dist/frontend/src/modules/color.d.ts +0 -160
  369. package/frontend/dist/frontend/src/modules/color.js +0 -316
  370. package/frontend/dist/frontend/src/modules/compression.d.ts +0 -39
  371. package/frontend/dist/frontend/src/modules/compression.js +0 -102
  372. package/frontend/dist/frontend/src/modules/cookies.d.ts +0 -44
  373. package/frontend/dist/frontend/src/modules/cookies.js +0 -143
  374. package/frontend/dist/frontend/src/modules/events.d.ts +0 -31
  375. package/frontend/dist/frontend/src/modules/events.js +0 -79
  376. package/frontend/dist/frontend/src/modules/google.d.ts +0 -23
  377. package/frontend/dist/frontend/src/modules/google.js +0 -52
  378. package/frontend/dist/frontend/src/modules/meta.d.ts +0 -14
  379. package/frontend/dist/frontend/src/modules/meta.js +0 -48
  380. package/frontend/dist/frontend/src/modules/paddle.d.ts +0 -1207
  381. package/frontend/dist/frontend/src/modules/paddle.js +0 -2594
  382. package/frontend/dist/frontend/src/modules/request.d.ts +0 -70
  383. package/frontend/dist/frontend/src/modules/request.js +0 -117
  384. package/frontend/dist/frontend/src/modules/settings.d.ts +0 -3
  385. package/frontend/dist/frontend/src/modules/settings.js +0 -5
  386. package/frontend/dist/frontend/src/modules/statics.d.ts +0 -21
  387. package/frontend/dist/frontend/src/modules/statics.js +0 -43
  388. package/frontend/dist/frontend/src/modules/stripe/cart.d.ts +0 -112
  389. package/frontend/dist/frontend/src/modules/stripe/cart.js +0 -321
  390. package/frontend/dist/frontend/src/modules/stripe/checkout.d.ts +0 -7
  391. package/frontend/dist/frontend/src/modules/stripe/checkout.js +0 -37
  392. package/frontend/dist/frontend/src/modules/stripe/index.m.d.ts +0 -6
  393. package/frontend/dist/frontend/src/modules/stripe/index.m.js +0 -6
  394. package/frontend/dist/frontend/src/modules/stripe/payments.d.ts +0 -58
  395. package/frontend/dist/frontend/src/modules/stripe/payments.js +0 -92
  396. package/frontend/dist/frontend/src/modules/support.d.ts +0 -30
  397. package/frontend/dist/frontend/src/modules/support.js +0 -53
  398. package/frontend/dist/frontend/src/modules/theme.d.ts +0 -133
  399. package/frontend/dist/frontend/src/modules/theme.js +0 -406
  400. package/frontend/dist/frontend/src/modules/themes.d.ts +0 -12
  401. package/frontend/dist/frontend/src/modules/themes.js +0 -22
  402. package/frontend/dist/frontend/src/modules/user.d.ts +0 -164
  403. package/frontend/dist/frontend/src/modules/user.js +0 -270
  404. package/frontend/dist/frontend/src/modules/utils.d.ts +0 -176
  405. package/frontend/dist/frontend/src/modules/utils.js +0 -569
  406. package/frontend/dist/frontend/src/types/gradient.d.ts +0 -29
  407. package/frontend/dist/frontend/src/types/gradient.js +0 -79
  408. package/frontend/dist/frontend/src/ui/border_button.d.ts +0 -94
  409. package/frontend/dist/frontend/src/ui/border_button.js +0 -228
  410. package/frontend/dist/frontend/src/ui/button.d.ts +0 -241
  411. package/frontend/dist/frontend/src/ui/button.js +0 -682
  412. package/frontend/dist/frontend/src/ui/canvas.d.ts +0 -138
  413. package/frontend/dist/frontend/src/ui/canvas.js +0 -444
  414. package/frontend/dist/frontend/src/ui/checkbox.d.ts +0 -74
  415. package/frontend/dist/frontend/src/ui/checkbox.js +0 -321
  416. package/frontend/dist/frontend/src/ui/code.d.ts +0 -235
  417. package/frontend/dist/frontend/src/ui/code.js +0 -1007
  418. package/frontend/dist/frontend/src/ui/context_menu.d.ts +0 -36
  419. package/frontend/dist/frontend/src/ui/context_menu.js +0 -205
  420. package/frontend/dist/frontend/src/ui/css.d.ts +0 -16
  421. package/frontend/dist/frontend/src/ui/css.js +0 -48
  422. package/frontend/dist/frontend/src/ui/divider.d.ts +0 -15
  423. package/frontend/dist/frontend/src/ui/divider.js +0 -78
  424. package/frontend/dist/frontend/src/ui/dropdown.d.ts +0 -176
  425. package/frontend/dist/frontend/src/ui/dropdown.js +0 -481
  426. package/frontend/dist/frontend/src/ui/for_each.d.ts +0 -37
  427. package/frontend/dist/frontend/src/ui/for_each.js +0 -92
  428. package/frontend/dist/frontend/src/ui/form.d.ts +0 -34
  429. package/frontend/dist/frontend/src/ui/form.js +0 -233
  430. package/frontend/dist/frontend/src/ui/frame_modes.d.ts +0 -37
  431. package/frontend/dist/frontend/src/ui/frame_modes.js +0 -108
  432. package/frontend/dist/frontend/src/ui/google_map.d.ts +0 -24
  433. package/frontend/dist/frontend/src/ui/google_map.js +0 -106
  434. package/frontend/dist/frontend/src/ui/gradient.d.ts +0 -25
  435. package/frontend/dist/frontend/src/ui/gradient.js +0 -131
  436. package/frontend/dist/frontend/src/ui/image.d.ts +0 -111
  437. package/frontend/dist/frontend/src/ui/image.js +0 -576
  438. package/frontend/dist/frontend/src/ui/input.d.ts +0 -392
  439. package/frontend/dist/frontend/src/ui/input.js +0 -1201
  440. package/frontend/dist/frontend/src/ui/link.d.ts +0 -25
  441. package/frontend/dist/frontend/src/ui/link.js +0 -140
  442. package/frontend/dist/frontend/src/ui/list.d.ts +0 -37
  443. package/frontend/dist/frontend/src/ui/list.js +0 -170
  444. package/frontend/dist/frontend/src/ui/loader_button.d.ts +0 -80
  445. package/frontend/dist/frontend/src/ui/loader_button.js +0 -193
  446. package/frontend/dist/frontend/src/ui/loaders.d.ts +0 -57
  447. package/frontend/dist/frontend/src/ui/loaders.js +0 -157
  448. package/frontend/dist/frontend/src/ui/popup.d.ts +0 -94
  449. package/frontend/dist/frontend/src/ui/popup.js +0 -510
  450. package/frontend/dist/frontend/src/ui/pseudo.d.ts +0 -44
  451. package/frontend/dist/frontend/src/ui/pseudo.js +0 -154
  452. package/frontend/dist/frontend/src/ui/scroller.d.ts +0 -105
  453. package/frontend/dist/frontend/src/ui/scroller.js +0 -1253
  454. package/frontend/dist/frontend/src/ui/slider.d.ts +0 -45
  455. package/frontend/dist/frontend/src/ui/slider.js +0 -217
  456. package/frontend/dist/frontend/src/ui/spacer.d.ts +0 -15
  457. package/frontend/dist/frontend/src/ui/spacer.js +0 -78
  458. package/frontend/dist/frontend/src/ui/span.d.ts +0 -15
  459. package/frontend/dist/frontend/src/ui/span.js +0 -73
  460. package/frontend/dist/frontend/src/ui/stack.d.ts +0 -66
  461. package/frontend/dist/frontend/src/ui/stack.js +0 -335
  462. package/frontend/dist/frontend/src/ui/steps.d.ts +0 -131
  463. package/frontend/dist/frontend/src/ui/steps.js +0 -308
  464. package/frontend/dist/frontend/src/ui/style.d.ts +0 -17
  465. package/frontend/dist/frontend/src/ui/style.js +0 -73
  466. package/frontend/dist/frontend/src/ui/switch.d.ts +0 -69
  467. package/frontend/dist/frontend/src/ui/switch.js +0 -357
  468. package/frontend/dist/frontend/src/ui/table.d.ts +0 -100
  469. package/frontend/dist/frontend/src/ui/table.js +0 -405
  470. package/frontend/dist/frontend/src/ui/tabs.d.ts +0 -111
  471. package/frontend/dist/frontend/src/ui/tabs.js +0 -424
  472. package/frontend/dist/frontend/src/ui/text.d.ts +0 -15
  473. package/frontend/dist/frontend/src/ui/text.js +0 -83
  474. package/frontend/dist/frontend/src/ui/title.d.ts +0 -91
  475. package/frontend/dist/frontend/src/ui/title.js +0 -272
  476. package/frontend/dist/frontend/src/ui/ui.d.ts +0 -35
  477. package/frontend/dist/frontend/src/ui/ui.js +0 -38
  478. package/frontend/dist/frontend/src/ui/view.d.ts +0 -15
  479. package/frontend/dist/frontend/src/ui/view.js +0 -88
  480. package/frontend/dist/frontend/src/volt.d.ts +0 -20
  481. package/frontend/dist/frontend/src/volt.js +0 -27
  482. package/frontend/examples/theme/theme.ts +0 -58
  483. package/frontend/tools/bundle_d_ts.js +0 -71
  484. package/frontend/tools/convert_to_jsdoc_input.txt +0 -9452
  485. package/frontend/tools/convert_to_jsdoc_output.txt +0 -7626
  486. package/frontend/tools/convert_to_jsdoc_tmp.js +0 -345
  487. package/frontend/tools/scan_mixed_imports.js +0 -69
  488. /package/frontend/{dist/frontend/src/css → css}/adyen.css +0 -0
  489. /package/frontend/{dist/frontend/src/css → css}/volt.css +0 -0
@@ -1,896 +0,0 @@
1
- /**
2
- * @author Daan van den Bergh
3
- * @copyright © 2026 - 2026 Daan van den Bergh. All rights reserved
4
- */
5
- import { InternalStripeError } from "./error.js";
6
- import { assert, generate_random_idempotency_key, stripe_api_call } from "./utils.js";
7
- /**
8
- * Nested types for the meter product definition.
9
- *
10
- * A meter product defines:
11
- * - a Stripe Billing Meter (usage aggregation definition)
12
- * - a Stripe Product + recurring metered Price attached to that meter
13
- *
14
- * Stripe docs:
15
- * - Meters: https://docs.stripe.com/api/billing/meter
16
- * - Create meter: https://docs.stripe.com/api/billing/meter/create
17
- * - Prices (recurring.meter): https://docs.stripe.com/api/prices/create
18
- */
19
- export var MeterProduct;
20
- (function (MeterProduct) {
21
- /** Multiplier from major units to pico-cent units: 100 * 10^12 = 10^14. */
22
- MeterProduct.MONEY_METER_MAJOR_TO_PICO_CENTS_SHIFT = 14;
23
- /** Fixed Stripe unit_amount_decimal for money meters, in cents. */
24
- MeterProduct.MONEY_METER_UNIT_AMOUNT_DECIMAL_CENTS = "0.000000000001"; // 10^-12 cents
25
- })(MeterProduct || (MeterProduct = {}));
26
- // ----------------------------------------------------------------------------
27
- // Internal constants.
28
- /**
29
- * The metadata key used to link an internal product id to a Stripe Product.
30
- */
31
- const app_product_id_metadata_key = "__volt_app_product_id";
32
- /**
33
- * The metadata key used to link an internal plan id (or one-time price id) to a Stripe Price.
34
- */
35
- const app_price_id_metadata_key = "__volt_app_price_id";
36
- /**
37
- * The metadata key storing a stable signature of price settings, used for detecting changes.
38
- */
39
- const app_price_signature_metadata_key = "__volt_app_price_signature";
40
- /**
41
- * The Stripe list page size (maximum allowed by Stripe for list endpoints).
42
- */
43
- const stripe_list_page_size = 100;
44
- // ----------------------------------------------------------------------------
45
- // Internal utilities.
46
- /**
47
- * Validate an integer amount in the smallest currency unit (e.g., cents).
48
- */
49
- function validate_unit_amount(unit_amount, field_name) {
50
- assert(Number.isInteger(unit_amount), "invalid_product", `Property '${field_name}' must be an integer (smallest currency unit)`, { field_name, unit_amount });
51
- assert(unit_amount > 0, "invalid_product", `Property '${field_name}' must be > 0`, { field_name, unit_amount });
52
- }
53
- /**
54
- * Normalize a Stripe-compatible `unit_amount_decimal` string (smallest currency unit, e.g. cents).
55
- *
56
- * Goals:
57
- * - Accept only Stripe-style non-negative decimals with up to 12 fractional digits.
58
- * - Canonicalize equivalent numeric strings so signatures/metadata comparisons are stable.
59
- * - Remove leading/trailing whitespace.
60
- * - Normalize leading zeros in the whole part:
61
- * "00012.3400" -> "12.3400"
62
- * "0000.5" -> "0.5"
63
- * "0.5" -> "0.5"
64
- * - Normalize trailing zeros in the fractional part:
65
- * "12.3400" -> "12.34"
66
- * "12.000" -> "12"
67
- * - Disallow zero values (matches your current pricing policy):
68
- * "0", "0.0", "000.000" -> throws
69
- *
70
- * Notes:
71
- * - This is designed for Stripe Price `unit_amount_decimal` (string) which supports up to 12 decimals.
72
- * - This is intentionally strict (no "+", no "-", no scientific notation, no ".5").
73
- *
74
- * @throws {InternalStripeError} via `assert(...)` when invalid.
75
- */
76
- function normalize_unit_amount_decimal(unit_amount_decimal, field_name) {
77
- assert(typeof unit_amount_decimal === "string", "invalid_product", `Property '${field_name}' must be a string`, { field_name, unit_amount_decimal });
78
- let s = unit_amount_decimal.trim();
79
- assert(s.length > 0, "invalid_product", `Property '${field_name}' must be non-empty`, { field_name });
80
- // Strict Stripe-style non-negative decimal with up to 12 fractional digits.
81
- // - no sign
82
- // - no scientific notation
83
- // - requires whole digits (so ".5" is rejected)
84
- // - allows optional fractional part with 1..12 digits
85
- assert(/^\d+(\.\d{1,12})?$/.test(s), "invalid_product", `Property '${field_name}' must be a non-negative decimal with up to 12 decimals`, { field_name, unit_amount_decimal: s });
86
- // Split whole/fractional.
87
- const dot = s.indexOf(".");
88
- const whole_raw = dot >= 0 ? s.slice(0, dot) : s;
89
- const frac_raw = dot >= 0 ? s.slice(dot + 1) : "";
90
- // Normalize whole:
91
- // - strip all leading zeros
92
- // - if empty -> "0"
93
- let whole = whole_raw.replace(/^0+/, "");
94
- if (whole === "")
95
- whole = "0";
96
- // Normalize fractional:
97
- // - remove trailing zeros
98
- // - if becomes empty -> no fractional part
99
- let frac = frac_raw;
100
- if (frac.length > 0) {
101
- frac = frac.replace(/0+$/, "");
102
- }
103
- // Recompose canonical string.
104
- s = frac.length > 0 ? `${whole}.${frac}` : whole;
105
- // Reject zero values: "0" only (since "0.0" etc collapse to "0")
106
- assert(s !== "0", "invalid_product", `Property '${field_name}' must be > 0`, { field_name, unit_amount_decimal: s });
107
- // Final validation to be sure the normalization didn't produce an invalid string.
108
- assert(/^\d+(\.\d{1,12})?$/.test(s), "invalid_product", "Normalization produced invalid decimal.", { s });
109
- return s;
110
- }
111
- /**
112
- * Resolve a unit price for meter products into Stripe Price create fields.
113
- *
114
- * Behavior:
115
- * - Money meters: fixed `unit_amount_decimal` (in cents) at 10^-12 cents per unit.
116
- * - Unit meters:
117
- * - If `price` is a number: validate as a positive integer and return `{ unit_amount }`.
118
- * - If `price` is `{ decimals: string }`: normalize to canonical form and return `{ unit_amount_decimal }`.
119
- *
120
- * Canonicalization:
121
- * - Decimal prices are normalized by `normalize_unit_amount_decimal` to ensure:
122
- * - stable signatures (`app_price_signature`)
123
- * - stable matching of existing Stripe Prices
124
- *
125
- * @throws {InternalStripeError} via `assert(...)` when invalid.
126
- */
127
- function resolve_unit_price_fields(product) {
128
- if (product.kind === "money") {
129
- // Fixed Stripe unit_amount_decimal for money meters, in cents (10^-12 cents).
130
- return { unit_amount_decimal: MeterProduct.MONEY_METER_UNIT_AMOUNT_DECIMAL_CENTS };
131
- }
132
- if (product.kind === "units") {
133
- const p = product.price;
134
- if (typeof p === "number") {
135
- // Positive integer in smallest currency unit (e.g., cents).
136
- assert(Number.isInteger(p), "invalid_product", "Property 'price' must be an integer (smallest currency unit)", { field_name: "price", unit_amount: p });
137
- assert(p > 0, "invalid_product", "Property 'price' must be > 0", { field_name: "price", unit_amount: p });
138
- return { unit_amount: p };
139
- }
140
- // Validate object shape defensively.
141
- assert(p !== null && typeof p === "object", "invalid_product", "Property 'price' must be a number or { decimals: string }", { price: p });
142
- const decimals = p.decimals;
143
- assert(typeof decimals === "string", "invalid_product", "Property 'price.decimals' must be a string", { price: p });
144
- return { unit_amount_decimal: normalize_unit_amount_decimal(decimals, "price.decimals") };
145
- }
146
- // Exhaustiveness guard.
147
- // @ts-expect-error exhaustive
148
- product.kind.toString();
149
- throw new InternalStripeError("invalid_product", `Unsupported meter product kind: ${product.kind}`, { kind: product.kind });
150
- }
151
- /**
152
- * Validate quantity rules.
153
- */
154
- function validate_quantity_rules(quantity_rules) {
155
- if (!quantity_rules) {
156
- return;
157
- }
158
- const { min, max } = quantity_rules;
159
- if (min !== undefined) {
160
- assert(Number.isInteger(min) && min >= 1, "invalid_product", "Quantity_rules.min must be an integer >= 1", {
161
- min,
162
- });
163
- }
164
- if (max !== undefined) {
165
- assert(Number.isInteger(max) && max >= 1, "invalid_product", "Quantity_rules.max must be an integer >= 1", {
166
- max,
167
- });
168
- }
169
- if (min !== undefined && max !== undefined) {
170
- assert(min <= max, "invalid_product", "Quantity_rules.min must be <= quantity_rules.max", { min, max });
171
- }
172
- }
173
- /**
174
- * Validate product images.
175
- */
176
- function validate_images(images) {
177
- if (!images) {
178
- return;
179
- }
180
- assert(Array.isArray(images), "invalid_product", "Images must be an array", { images });
181
- assert(images.length <= 8, "invalid_product", "Images must contain at most 8 URLs", { count: images.length });
182
- for (const image of images) {
183
- assert(typeof image === "string" && image.trim().length > 0, "invalid_product", "Image URL must be a non-empty string", { image });
184
- // Require https URLs to avoid weird schemes ending up in Stripe/user-facing UIs.
185
- assert(/^https:\/\/\S+$/i.test(image.trim()), "invalid_product", "Image URL must be an https URL", { image });
186
- }
187
- }
188
- /**
189
- * Create a stable signature for a one-time price.
190
- * This signature is stored in Stripe Price metadata to detect config changes.
191
- * @warning Never change this signature since it is used to link Stripe Prices to internal price definitions.
192
- * Changing the signature format would cause all existing Stripe Prices to be considered stale and deactivated on the next initialization.
193
- */
194
- function make_one_time_price_signature(opts) {
195
- return `v1|one_time|${opts.currency}|${opts.unit_amount}|${opts.tax_behavior}`;
196
- }
197
- /**
198
- * Create a stable signature for a recurring price.
199
- * This signature is stored in Stripe Price metadata to detect config changes.
200
- * @warning Never change this signature since it is used to link Stripe Prices to internal price definitions.
201
- * Changing the signature format would cause all existing Stripe Prices to be considered stale and deactivated on the next initialization.
202
- */
203
- function make_recurring_price_signature(opts) {
204
- const meter_part = opts.usage_type === "metered" ? `|meter:${opts.meter_id ?? ""}` : "|meter:";
205
- const amount_part = opts.unit_amount_decimal !== undefined ? opts.unit_amount_decimal : (opts.unit_amount ?? 0);
206
- return `v1|recurring|${opts.currency}|${amount_part}|${opts.tax_behavior}|${opts.interval}|${opts.interval_count}|usage:${opts.usage_type}${meter_part}`;
207
- }
208
- /**
209
- * Create a unique app id for the price's metadata.
210
- * @warning This should not be changed, since this is used to link Stripe Prices to internal price definitions.
211
- */
212
- function make_price_app_id(product_id, plan_id) {
213
- return plan_id ? `${product_id}__plan__${plan_id}` : `${product_id}__one_time`;
214
- }
215
- /**
216
- * List all Stripe products, paginated.
217
- *
218
- * Docs: https://docs.stripe.com/api/products/list
219
- */
220
- async function list_all_stripe_products(client) {
221
- const all_products = [];
222
- let starting_after;
223
- for (;;) {
224
- const page = await stripe_api_call(() => client.products.list({
225
- limit: stripe_list_page_size,
226
- starting_after,
227
- expand: ["data.default_price"],
228
- }), { operation: "products.list_all", starting_after });
229
- all_products.push(...page.data);
230
- if (!page.has_more || page.data.length === 0) {
231
- break;
232
- }
233
- const last = page.data[page.data.length - 1];
234
- assert(last !== undefined, "api_error", "Stripe products pagination returned an empty last item", {
235
- returned: page.data.length,
236
- });
237
- starting_after = last.id;
238
- }
239
- return all_products;
240
- }
241
- /**
242
- * List all Stripe prices, paginated.
243
- *
244
- * Docs: https://docs.stripe.com/api/prices/list
245
- */
246
- async function list_all_stripe_prices(client) {
247
- const all_prices = [];
248
- let starting_after;
249
- for (;;) {
250
- const page = await stripe_api_call(() => client.prices.list({
251
- limit: stripe_list_page_size,
252
- // We list only active prices because inactive ones are not usable for new purchases,
253
- // and we only need active ones for initialization comparisons.
254
- active: true,
255
- starting_after,
256
- }), { operation: "prices.list_all", starting_after });
257
- all_prices.push(...page.data);
258
- if (!page.has_more || page.data.length === 0) {
259
- break;
260
- }
261
- const last = page.data[page.data.length - 1];
262
- assert(last !== undefined, "api_error", "Stripe prices pagination returned an empty last item", {
263
- returned: page.data.length,
264
- });
265
- starting_after = last.id;
266
- }
267
- return all_prices;
268
- }
269
- /**
270
- * List all Stripe billing meters, paginated.
271
- *
272
- * Docs: https://docs.stripe.com/api/billing/meter/list
273
- */
274
- async function list_all_stripe_meters(client) {
275
- const all_meters = [];
276
- let starting_after;
277
- for (;;) {
278
- // Stripe docs: https://docs.stripe.com/api/billing/meter/list
279
- const page = await stripe_api_call(() => client.billing.meters.list({
280
- limit: stripe_list_page_size,
281
- starting_after,
282
- }), { operation: "billing.meters.list_all", starting_after });
283
- all_meters.push(...page.data);
284
- if (!page.has_more || page.data.length === 0) {
285
- break;
286
- }
287
- const last = page.data[page.data.length - 1];
288
- assert(last !== undefined, "api_error", "Stripe meters pagination returned an empty last item", {
289
- returned: page.data.length,
290
- });
291
- starting_after = last.id;
292
- }
293
- return all_meters;
294
- }
295
- /**
296
- * Build a lookup table from app product id -> Stripe Product.
297
- */
298
- function index_stripe_products_by_app_id(stripe_products) {
299
- const map = new Map();
300
- for (const product of stripe_products) {
301
- const app_id = product.metadata?.[app_product_id_metadata_key];
302
- if (app_id) {
303
- assert(!map.has(app_id), "api_error", "Duplicate Stripe product metadata app id", {
304
- app_id,
305
- existing_stripe_product_id: map.get(app_id)?.id,
306
- duplicate_stripe_product_id: product.id,
307
- });
308
- map.set(app_id, product);
309
- }
310
- }
311
- return map;
312
- }
313
- /**
314
- * Build a lookup table from Stripe product id -> active Stripe prices for that product.
315
- */
316
- function index_active_prices_by_stripe_product_id(stripe_prices) {
317
- const map = new Map();
318
- for (const price of stripe_prices) {
319
- // Stripe.Price.product can be string | Stripe.Product | Stripe.DeletedProduct
320
- // We only index when it is a string id.
321
- if (typeof price.product !== "string") {
322
- continue;
323
- }
324
- const list = map.get(price.product) ?? [];
325
- list.push(price);
326
- map.set(price.product, list);
327
- }
328
- return map;
329
- }
330
- /**
331
- * Build a lookup table from meter event_name -> Stripe Billing Meter.
332
- *
333
- * Note: Stripe Billing Meters do not currently expose metadata in the API reference,
334
- * so we link by stable event_name (which must be unique in the Stripe account).
335
- * Docs: https://docs.stripe.com/api/billing/meter/object
336
- */
337
- function index_stripe_meters_by_event_name(stripe_meters) {
338
- const map = new Map();
339
- for (const meter of stripe_meters) {
340
- const event_name = meter.event_name;
341
- if (event_name) {
342
- assert(!map.has(event_name), "api_error", "Duplicate Stripe meter event_name", {
343
- event_name,
344
- existing_stripe_meter_id: map.get(event_name)?.id,
345
- duplicate_stripe_meter_id: meter.id,
346
- });
347
- map.set(event_name, meter);
348
- }
349
- }
350
- return map;
351
- }
352
- /**
353
- * Find an active Stripe Price by internal price id and signature.
354
- *
355
- * Docs: https://docs.stripe.com/api/prices
356
- */
357
- function find_matching_active_price(active_prices, app_price_id, expected_signature) {
358
- const match = active_prices.find((p) => {
359
- const meta_price_id = p.metadata?.[app_price_id_metadata_key];
360
- const meta_signature = p.metadata?.[app_price_signature_metadata_key];
361
- return meta_price_id === app_price_id && meta_signature === expected_signature;
362
- });
363
- return match ?? null;
364
- }
365
- // /**
366
- // * Deactivate all active Stripe Prices that match the internal price id but have different signatures.
367
- // *
368
- // * Docs: https://docs.stripe.com/api/prices/update
369
- // */
370
- // async function deactivate_stale_prices_for_app_price_id(
371
- // client: Stripe,
372
- // server: Server,
373
- // active_prices: Stripe.Price[],
374
- // app_price_id: string,
375
- // expected_signature: string,
376
- // ): Promise<void> {
377
- // const stale_prices = active_prices.filter((p) => {
378
- // const meta_price_id = p.metadata?.[app_price_id_metadata_key];
379
- // const meta_signature = p.metadata?.[app_price_signature_metadata_key];
380
- // return meta_price_id === app_price_id && meta_signature !== expected_signature;
381
- // });
382
- // await Promise.all(
383
- // stale_prices.map((p) =>
384
- // stripe_api_call(
385
- // () =>
386
- // client.prices.update(
387
- // p.id,
388
- // { active: false },
389
- // { idempotencyKey: stable_idempotency_key(`init|prices.update|deactivate|${app_price_id}|${p.id}`) },
390
- // ),
391
- // { operation: "prices.update", app_price_id, stripe_price_id: p.id, action: "deactivate" },
392
- // ),
393
- // ),
394
- // );
395
- // }
396
- /**
397
- * Create a Stripe Product for a given internal Product.
398
- *
399
- * Docs: https://docs.stripe.com/api/products/create
400
- * Tax code docs: https://docs.stripe.com/tax/tax-codes
401
- */
402
- async function create_stripe_product(client, server, product) {
403
- server.log(0, `Creating Stripe product for product '${product.id}'`);
404
- return await stripe_api_call(() => client.products.create({
405
- name: product.name,
406
- description: product.description,
407
- tax_code: product.tax_code,
408
- images: product.images,
409
- metadata: {
410
- [app_product_id_metadata_key]: product.id,
411
- },
412
- expand: ["default_price"],
413
- }, { idempotencyKey: generate_random_idempotency_key(`create_product_${product.id}`) }), { operation: "products.create", app_product_id: product.id });
414
- }
415
- /**
416
- * Update a Stripe Product if user-facing fields changed.
417
- *
418
- * Docs: https://docs.stripe.com/api/products/update
419
- */
420
- async function update_stripe_product_if_needed(client, server, stripe_product, product) {
421
- const stripe_images = stripe_product.images ?? [];
422
- const app_images = product.images ?? [];
423
- const images_equal = stripe_images.length === app_images.length &&
424
- stripe_images.every((url, index) => url === app_images[index]);
425
- const needs_update = stripe_product.name !== product.name ||
426
- (stripe_product.description ?? "") !== (product.description ?? "") ||
427
- (stripe_product.tax_code ?? "") !== (product.tax_code ?? "") ||
428
- !images_equal;
429
- if (!needs_update) {
430
- return stripe_product;
431
- }
432
- server.log(0, `Updating Stripe product '${stripe_product.id}' to match app product '${product.id}'`);
433
- return await stripe_api_call(() => client.products.update(stripe_product.id, {
434
- name: product.name,
435
- description: product.description,
436
- tax_code: product.tax_code,
437
- images: product.images,
438
- expand: ["default_price"],
439
- }, { idempotencyKey: generate_random_idempotency_key(`update_product_${product.id}_${stripe_product.id}`) }), { operation: "products.update", app_product_id: product.id, stripe_product_id: stripe_product.id });
440
- }
441
- /**
442
- * Update default price on a stripe product if needed.
443
- */
444
- async function update_stripe_product_default_price_if_needed(client, server, stripe_product, default_price, other_plans_from_parent_subscription) {
445
- // Extract default price.
446
- let default_price_id = null;
447
- if (typeof stripe_product.default_price === "string") {
448
- default_price_id = stripe_product.default_price;
449
- }
450
- else if (stripe_product.default_price && typeof stripe_product.default_price === "object") {
451
- default_price_id = stripe_product.default_price.id;
452
- }
453
- // If its still undefined, fetch the product to get the default_price expanded (this should be rare since we expand it on list/create/update).
454
- if (!default_price_id) {
455
- const fetched = await stripe_api_call(() => client.products.retrieve(stripe_product.id, {
456
- expand: ["default_price"],
457
- }), { operation: "products.retrieve_for_default_price", stripe_product_id: stripe_product.id });
458
- default_price_id = typeof fetched.default_price === "string" ? fetched.default_price : fetched.default_price?.id ?? null;
459
- }
460
- // If the default price is already correct, do nothing.
461
- if (default_price_id === default_price.id
462
- // For subscription products, the default_price may be shared across multiple plans, so we also check if any other plan from the same subscription is using the price. If so, we should not update the default_price since it would affect those plans as well.
463
- || other_plans_from_parent_subscription?.some((plan) => plan.stripe_price_id === default_price_id)) {
464
- return;
465
- }
466
- server.log(0, `Updating default price for Stripe product '${stripe_product.id}' to price '${default_price.id}'`);
467
- await stripe_api_call(() => client.products.update(stripe_product.id, {
468
- default_price: default_price.id,
469
- }, { idempotencyKey: generate_random_idempotency_key(`update_product_default_price_${stripe_product.id}_${default_price.id}`) }), { operation: "products.update", app_product_id: stripe_product.metadata?.[app_product_id_metadata_key], stripe_product_id: stripe_product.id, action: "update_default_price" });
470
- }
471
- /**
472
- * Create a Stripe one-time Price for a product.
473
- *
474
- * Docs: https://docs.stripe.com/api/prices/create
475
- */
476
- async function create_one_time_price(client, server, opts) {
477
- server.log(0, `Creating stripe one-time price for product: ${opts.product_id}`);
478
- return await stripe_api_call(() => client.prices.create({
479
- product: opts.stripe_product_id,
480
- currency: opts.currency,
481
- unit_amount: opts.unit_amount,
482
- // Docs: https://docs.stripe.com/tax/tax-behavior
483
- tax_behavior: opts.tax_behavior,
484
- nickname: opts.nickname,
485
- metadata: {
486
- [app_price_id_metadata_key]: opts.app_price_id,
487
- [app_price_signature_metadata_key]: make_one_time_price_signature({
488
- currency: opts.currency,
489
- unit_amount: opts.unit_amount,
490
- tax_behavior: opts.tax_behavior,
491
- }),
492
- },
493
- }, { idempotencyKey: generate_random_idempotency_key(`create_one_time_price_${opts.app_price_id}_${opts.stripe_product_id}`) }), { operation: "prices.create", app_price_id: opts.app_price_id, stripe_product_id: opts.stripe_product_id });
494
- }
495
- /**
496
- * Create a Stripe recurring Price.
497
- *
498
- * Docs: https://docs.stripe.com/api/prices/create
499
- */
500
- async function create_recurring_price(client, server, opts) {
501
- // Build recurring fields with optional metered settings.
502
- const recurring = {
503
- interval: opts.interval,
504
- interval_count: opts.interval_count,
505
- // "metered" links the price to a billing meter; "licensed" is standard recurring.
506
- // Docs: https://docs.stripe.com/api/prices/create (recurring.usage_type)
507
- usage_type: opts.recurring_usage.usage_type,
508
- // For metered prices, connect the Stripe price to a meter id.
509
- // Docs: https://docs.stripe.com/api/prices/create (recurring.meter)
510
- ...(opts.recurring_usage.usage_type === "metered" ? { meter: opts.recurring_usage.meter_id } : {}),
511
- };
512
- const signature = make_recurring_price_signature({
513
- currency: opts.currency,
514
- ...(("unit_amount_decimal" in opts)
515
- ? { unit_amount_decimal: opts.unit_amount_decimal }
516
- : { unit_amount: opts.unit_amount }),
517
- tax_behavior: opts.tax_behavior,
518
- interval: opts.interval,
519
- interval_count: opts.interval_count,
520
- usage_type: opts.recurring_usage.usage_type,
521
- meter_id: opts.recurring_usage.usage_type === "metered" ? opts.recurring_usage.meter_id : undefined,
522
- });
523
- server.log(0, `Creating stripe recurring price for product: ${opts.product_id}`);
524
- return await stripe_api_call(() => client.prices.create({
525
- product: opts.stripe_product_id,
526
- currency: opts.currency,
527
- ...(("unit_amount_decimal" in opts)
528
- ? { unit_amount_decimal: opts.unit_amount_decimal }
529
- : { unit_amount: opts.unit_amount }),
530
- tax_behavior: opts.tax_behavior,
531
- nickname: opts.nickname,
532
- // Docs: https://docs.stripe.com/billing/prices-guide#create-prices
533
- recurring,
534
- metadata: {
535
- [app_price_id_metadata_key]: opts.app_price_id,
536
- [app_price_signature_metadata_key]: signature,
537
- },
538
- }, { idempotencyKey: generate_random_idempotency_key(`create_recurring_price_${opts.app_price_id}_${opts.stripe_product_id}`) }), { operation: "prices.create", app_price_id: opts.app_price_id, stripe_product_id: opts.stripe_product_id });
539
- }
540
- /**
541
- * Create a Stripe Billing Meter.
542
- *
543
- * Docs: https://docs.stripe.com/api/billing/meter/create
544
- */
545
- async function create_stripe_meter(client, server, product) {
546
- const aggregation_formula = product.aggregation_formula ?? "sum";
547
- const customer_mapping_event_payload_key = product.customer_mapping_event_payload_key ?? "stripe_customer_id";
548
- const value_settings_event_payload_key = product.value_settings_event_payload_key ?? "value";
549
- server.log(0, `Creating stripe billing meter for product: ${product.id}`);
550
- return await stripe_api_call(() => client.billing.meters.create({
551
- display_name: product.name,
552
- event_name: product.meter_event_name,
553
- default_aggregation: {
554
- formula: aggregation_formula,
555
- },
556
- // Stripe currently requires by_id mapping and a payload key that contains the customer id.
557
- // Docs: https://docs.stripe.com/api/billing/meter/create#billing_meter_create-customer_mapping
558
- customer_mapping: {
559
- type: "by_id",
560
- event_payload_key: customer_mapping_event_payload_key,
561
- },
562
- // Value key used as the numeric value for "sum"/"last" aggregation.
563
- // Docs: https://docs.stripe.com/api/billing/meter/create#billing_meter_create-value_settings
564
- value_settings: {
565
- event_payload_key: value_settings_event_payload_key,
566
- },
567
- ...(product.event_time_window ? { event_time_window: product.event_time_window } : {}),
568
- }, { idempotencyKey: generate_random_idempotency_key(`create_billing_meter_${product.id}_${product.meter_event_name}`) }), {
569
- operation: "billing.meters.create",
570
- app_meter_product_id: product.id,
571
- event_name: product.meter_event_name,
572
- aggregation_formula,
573
- customer_mapping_event_payload_key,
574
- value_settings_event_payload_key,
575
- event_time_window: product.event_time_window ?? null,
576
- });
577
- }
578
- /**
579
- * Run async work with limited concurrency, preserving input order.
580
- */
581
- async function map_with_concurrency(items, concurrency, mapper) {
582
- assert(Number.isInteger(concurrency) && concurrency >= 1, "invalid_argument", "Concurrency must be an integer >= 1", { concurrency });
583
- const results = new Array(items.length);
584
- let next_index = 0;
585
- let first_error = null;
586
- const worker = async () => {
587
- for (;;) {
588
- if (first_error)
589
- return;
590
- const current_index = next_index;
591
- next_index += 1;
592
- if (current_index >= items.length) {
593
- return;
594
- }
595
- const current_item = items[current_index];
596
- assert(current_item !== undefined, "invalid_argument", "Missing item for concurrency worker index", { current_index, items_length: items.length });
597
- try {
598
- results[current_index] = await mapper(current_item, current_index);
599
- }
600
- catch (e) {
601
- // Stop other workers ASAP; rethrow after all workers settle.
602
- if (!first_error)
603
- first_error = e;
604
- return;
605
- }
606
- }
607
- };
608
- const worker_count = Math.min(concurrency, items.length);
609
- await Promise.allSettled(Array.from({ length: worker_count }, () => worker()));
610
- if (first_error)
611
- throw first_error;
612
- return results;
613
- }
614
- // ----------------------------------------------------------------------------
615
- // Private initializer.
616
- /**
617
- * Initialize a product using pre-fetched Stripe products/prices indexes.
618
- */
619
- async function initialize_product(client, server, product, stripe_products_by_app_id, active_prices_by_stripe_product_id, stripe_meters_by_event_name) {
620
- assert(product.id.trim().length > 0, "invalid_product", "Product.id must be non-empty", { product_id: product.id });
621
- assert(product.name.trim().length > 0, "invalid_product", "Product.name must be non-empty", { product_id: product.id });
622
- assert(product.currency.trim().length > 0, "invalid_product", "Product.currency must be non-empty", { product_id: product.id });
623
- assert(product.tax_code.trim().length > 0, "invalid_product", "Product.tax_code must be non-empty", { product_id: product.id });
624
- assert(product.tax_behavior === "inclusive" ||
625
- product.tax_behavior === "exclusive" ||
626
- product.tax_behavior === "unspecified", "invalid_product", "Product.tax_behavior is invalid", { product_id: product.id, tax_behavior: product.tax_behavior });
627
- validate_images(product.images);
628
- // Normalize currency code to lowercase for consistent matching and Stripe API usage.
629
- product.currency = product.currency.trim().toLowerCase();
630
- assert(/^[a-z]{3}$/.test(product.currency), "invalid_product", `Invalid currency code: "${product.currency}"`, { currency: product.currency });
631
- if (product.type === "one_time") {
632
- validate_unit_amount(product.price, "Product.price");
633
- validate_quantity_rules(product.quantity_rules);
634
- }
635
- else if (product.type === "subscription") {
636
- assert(Array.isArray(product.plans) && product.plans.length > 0, "invalid_product", "Subscription product must have plans", { product_id: product.id });
637
- if (product.trial_days !== undefined) {
638
- assert(Number.isInteger(product.trial_days) && product.trial_days >= 1, "invalid_product", "Subscription.trial_days must be an integer >= 1", { product_id: product.id, trial_days: product.trial_days });
639
- }
640
- if (product.billing_anchor !== undefined) {
641
- const anchor = product.billing_anchor;
642
- assert(anchor === "immediately" || anchor === "first_of_month", "invalid_product", "Subscription.billing_anchor is invalid", { product_id: product.id, billing_anchor: anchor });
643
- }
644
- else {
645
- // Default to "immediately" if not set.
646
- product.billing_anchor = "immediately";
647
- }
648
- for (const plan of product.plans) {
649
- assert(plan.id.trim().length > 0, "invalid_product", "Plan.id must be non-empty", { product_id: product.id });
650
- assert(plan.name.trim().length > 0, "invalid_product", "Plan.name must be non-empty", { product_id: product.id, plan_id: plan.id });
651
- validate_unit_amount(plan.price, "Plan.price");
652
- assert(Number.isInteger(plan.interval_count) && plan.interval_count >= 1, "invalid_product", "Plan.interval_count must be >= 1", { product_id: product.id, plan_id: plan.id, interval_count: plan.interval_count });
653
- assert(plan.interval === "day" || plan.interval === "week" || plan.interval === "month" || plan.interval === "year", "invalid_product", "Plan.interval is invalid", { product_id: product.id, plan_id: plan.id, interval: plan.interval });
654
- }
655
- }
656
- else if (product.type === "meter") {
657
- assert(product.interval === "day" || product.interval === "week" || product.interval === "month" || product.interval === "year", "invalid_product", "Property 'interval' is invalid", { product_id: product.id, interval: product.interval });
658
- if (product.kind === "units") {
659
- assert(product.price !== undefined, "invalid_product", "MeterProduct with kind='units' must define 'price'.", { product_id: product.id });
660
- // validates + normalizes shape
661
- resolve_unit_price_fields(product);
662
- }
663
- else if (product.kind === "money") {
664
- // money meter: no price is allowed
665
- assert(product.price === undefined, "invalid_product", "MeterProduct with kind='money' must not define 'price'.", { product_id: product.id });
666
- }
667
- else {
668
- // @ts-expect-error
669
- product.kind.toString();
670
- throw new InternalStripeError("invalid_product", `Invalid 'kind': ${product.kind}`, { product_id: product.id, kind: product.kind });
671
- }
672
- assert(Number.isInteger(product.interval_count) && product.interval_count >= 1, "invalid_product", "Property 'interval_count' must be >= 1", { product_id: product.id, interval_count: product.interval_count });
673
- assert(product.meter_event_name.trim().length > 0, "invalid_product", "Property 'meter_event_name' must be non-empty", {
674
- product_id: product.id,
675
- meter_event_name: product.meter_event_name,
676
- });
677
- // Stripe meter event_name max length is 100 chars.
678
- // Docs: https://docs.stripe.com/api/billing/meter/create
679
- assert(product.meter_event_name.length <= 100, "invalid_product", "Property 'meter_event_name' must be <= 100 characters", { product_id: product.id, meter_event_name_length: product.meter_event_name.length });
680
- if (product.aggregation_formula !== undefined) {
681
- const formula = product.aggregation_formula;
682
- assert(formula === "count" || formula === "sum" || formula === "last", "invalid_product", "Property 'aggregation_formula' is invalid", { product_id: product.id, aggregation_formula: formula });
683
- }
684
- if (product.customer_mapping_event_payload_key !== undefined) {
685
- assert(product.customer_mapping_event_payload_key.trim().length > 0, "invalid_product", "Property 'customer_mapping_event_payload_key' must be non-empty", { product_id: product.id, customer_mapping_event_payload_key: product.customer_mapping_event_payload_key });
686
- }
687
- if (product.value_settings_event_payload_key !== undefined) {
688
- assert(product.value_settings_event_payload_key.trim().length > 0, "invalid_product", "Property 'value_settings_event_payload_key' must be non-empty", { product_id: product.id, value_settings_event_payload_key: product.value_settings_event_payload_key });
689
- }
690
- if (product.event_time_window !== undefined) {
691
- const window = product.event_time_window;
692
- assert(window === "hour" || window === "day", "invalid_product", "Property 'event_time_window' is invalid", { product_id: product.id, event_time_window: window });
693
- }
694
- }
695
- else {
696
- //@ts-expect-error product.type should be never here
697
- product.type.toString();
698
- throw new InternalStripeError("invalid_product", `Invalid product type: ${product.type}`, {
699
- product_id: product.id, product_type: product.type
700
- });
701
- }
702
- // 0) If this is a meter product, ensure the Stripe Billing Meter exists (or create it).
703
- let stripe_meter = null;
704
- if (product.type === "meter") {
705
- stripe_meter = stripe_meters_by_event_name.get(product.meter_event_name) ?? null;
706
- if (!stripe_meter) {
707
- stripe_meter = await create_stripe_meter(client, server, product);
708
- stripe_meters_by_event_name.set(product.meter_event_name, stripe_meter);
709
- }
710
- }
711
- // 1) Ensure Stripe Product exists (or create it), linked by metadata.
712
- let stripe_product = stripe_products_by_app_id.get(product.id) ?? null;
713
- if (!stripe_product) {
714
- stripe_product = await create_stripe_product(client, server, product);
715
- stripe_products_by_app_id.set(product.id, stripe_product);
716
- }
717
- else {
718
- stripe_product = await update_stripe_product_if_needed(client, server, stripe_product, product);
719
- stripe_products_by_app_id.set(product.id, stripe_product);
720
- }
721
- // 2) Resolve active prices for this Stripe product (from pre-fetched index).
722
- const active_prices = active_prices_by_stripe_product_id.get(stripe_product.id) ?? [];
723
- if (product.type === "one_time") {
724
- const app_price_id = make_price_app_id(product.id, undefined);
725
- const signature = make_one_time_price_signature({
726
- currency: product.currency,
727
- unit_amount: product.price,
728
- tax_behavior: product.tax_behavior,
729
- });
730
- let stripe_price = find_matching_active_price(active_prices, app_price_id, signature);
731
- if (!stripe_price) {
732
- stripe_price = await create_one_time_price(client, server, {
733
- product_id: product.id,
734
- stripe_product_id: stripe_product.id,
735
- app_price_id,
736
- currency: product.currency,
737
- unit_amount: product.price,
738
- tax_behavior: product.tax_behavior,
739
- nickname: product.name,
740
- });
741
- const updated_prices = [...active_prices, stripe_price];
742
- active_prices_by_stripe_product_id.set(stripe_product.id, updated_prices);
743
- }
744
- await update_stripe_product_default_price_if_needed(client, server, stripe_product, stripe_price);
745
- return {
746
- ...product,
747
- stripe_product_id: stripe_product.id,
748
- stripe_price_id: stripe_price.id,
749
- };
750
- }
751
- else if (product.type === "subscription") {
752
- const initialized_plans = [];
753
- for (const plan of product.plans) {
754
- const app_price_id = make_price_app_id(product.id, plan.id);
755
- const signature = make_recurring_price_signature({
756
- currency: product.currency,
757
- unit_amount: plan.price,
758
- tax_behavior: product.tax_behavior,
759
- interval: plan.interval,
760
- interval_count: plan.interval_count,
761
- usage_type: "licensed",
762
- });
763
- let stripe_price = find_matching_active_price(active_prices, app_price_id, signature);
764
- if (!stripe_price) {
765
- stripe_price = await create_recurring_price(client, server, {
766
- product_id: product.id,
767
- stripe_product_id: stripe_product.id,
768
- app_price_id,
769
- currency: product.currency,
770
- unit_amount: plan.price,
771
- tax_behavior: product.tax_behavior,
772
- nickname: `${product.name} - ${plan.name}`,
773
- interval: plan.interval,
774
- interval_count: plan.interval_count,
775
- recurring_usage: { usage_type: "licensed" },
776
- });
777
- const updated_prices = [...active_prices, stripe_price];
778
- active_prices_by_stripe_product_id.set(stripe_product.id, updated_prices);
779
- }
780
- await update_stripe_product_default_price_if_needed(client, server, stripe_product, stripe_price, initialized_plans);
781
- initialized_plans.push({
782
- ...plan,
783
- type: "subscription_plan",
784
- subscription_id: product.id,
785
- stripe_price_id: stripe_price.id,
786
- });
787
- }
788
- return {
789
- ...product,
790
- stripe_product_id: stripe_product.id,
791
- plans: initialized_plans,
792
- };
793
- }
794
- else if (product.type === "meter") {
795
- assert(stripe_meter !== null, "api_error", "Stripe meter must be resolved for meter product initialization", {
796
- product_id: product.id,
797
- meter_event_name: product.meter_event_name,
798
- });
799
- const app_price_id = `${product.id}__meter`;
800
- const unit_price_fields = resolve_unit_price_fields(product);
801
- const signature = make_recurring_price_signature({
802
- currency: product.currency,
803
- ...unit_price_fields,
804
- tax_behavior: product.tax_behavior,
805
- interval: product.interval,
806
- interval_count: product.interval_count,
807
- usage_type: "metered",
808
- meter_id: stripe_meter.id,
809
- });
810
- let stripe_price = find_matching_active_price(active_prices, app_price_id, signature);
811
- if (!stripe_price) {
812
- const new_price = await create_recurring_price(client, server, {
813
- product_id: product.id,
814
- stripe_product_id: stripe_product.id,
815
- app_price_id,
816
- currency: product.currency,
817
- ...unit_price_fields,
818
- tax_behavior: product.tax_behavior,
819
- nickname: product.name,
820
- interval: product.interval,
821
- interval_count: product.interval_count,
822
- recurring_usage: { usage_type: "metered", meter_id: stripe_meter.id },
823
- });
824
- stripe_price = new_price;
825
- active_prices_by_stripe_product_id.set(stripe_product.id, [...active_prices, new_price]);
826
- }
827
- await update_stripe_product_default_price_if_needed(client, server, stripe_product, stripe_price);
828
- return {
829
- ...product,
830
- stripe_meter_id: stripe_meter.id,
831
- stripe_product_id: stripe_product.id,
832
- stripe_price_id: stripe_price.id,
833
- };
834
- }
835
- else {
836
- //@ts-expect-error product.type should be never here
837
- product.type.toString();
838
- throw new InternalStripeError("invalid_product", `Invalid product type: ${product.type}`, {
839
- product_id: product.id, product_type: product.type
840
- });
841
- }
842
- }
843
- // ----------------------------------------------------------------------------
844
- // Public API.
845
- /**
846
- * Resolve the subscription product (InitializedSubscriptionProduct) that owns a given plan.
847
- */
848
- export function resolve_plan_to_parent_subscription(opts) {
849
- for (const product of opts.all_products) {
850
- if (product.type === "subscription" && product.id === opts.plan.subscription_id) {
851
- return product;
852
- }
853
- }
854
- // If we cannot find it, this indicates a corrupted initialization state.
855
- throw new InternalStripeError("invalid_product", "Subscription plan refers to a missing parent subscription product.", { plan_id: opts.plan.id, subscription_id: opts.plan.subscription_id });
856
- }
857
- /**
858
- * Initialize a list of products through the internal initializer, using a single paginated scan
859
- * of Stripe products and prices which is then reused for all initializations.
860
- */
861
- export async function initialize_products(client, server, products) {
862
- assert(Array.isArray(products), "invalid_argument", "Products must be an array");
863
- // Verify that all `id` attributes from Products and Plans are unique.
864
- const seen_ids = new Set();
865
- const seen_meter_event_names = new Set();
866
- for (const product of products) {
867
- assert(!seen_ids.has(product.id), "invalid_product", `Duplicate product id: ${product.id}`, { product_id: product.id });
868
- seen_ids.add(product.id);
869
- if (product.type === "subscription") {
870
- for (const plan of product.plans) {
871
- assert(!seen_ids.has(plan.id), "invalid_product", `Duplicate plan id: ${plan.id} in product ${product.id}`, { product_id: product.id, plan_id: plan.id });
872
- seen_ids.add(plan.id);
873
- }
874
- }
875
- if (product.type === "meter") {
876
- assert(!seen_meter_event_names.has(product.meter_event_name), "invalid_product", `Duplicate meter_event_name: ${product.meter_event_name}`, { product_id: product.id, meter_event_name: product.meter_event_name });
877
- seen_meter_event_names.add(product.meter_event_name);
878
- }
879
- }
880
- // High-performance: list all products, prices, and meters once, then reuse indexes.
881
- const [all_stripe_products, all_active_stripe_prices, all_stripe_meters] = await Promise.all([
882
- list_all_stripe_products(client),
883
- list_all_stripe_prices(client),
884
- list_all_stripe_meters(client),
885
- ]);
886
- const stripe_products_by_app_id = index_stripe_products_by_app_id(all_stripe_products);
887
- const active_prices_by_stripe_product_id = index_active_prices_by_stripe_product_id(all_active_stripe_prices);
888
- const stripe_meters_by_event_name = index_stripe_meters_by_event_name(all_stripe_meters);
889
- // Initialize with limited concurrency to reduce latency while avoiding Stripe rate spikes.
890
- const concurrency = 5;
891
- const initialized_products = await map_with_concurrency(products, concurrency, async (product) => {
892
- return await initialize_product(client, server, product, stripe_products_by_app_id, active_prices_by_stripe_product_id, stripe_meters_by_event_name);
893
- });
894
- // Response.
895
- return initialized_products;
896
- }