@mmailaender/convex-creem 0.1.0

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 (383) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +1176 -0
  3. package/dist/client/helpers.d.ts +17 -0
  4. package/dist/client/helpers.d.ts.map +1 -0
  5. package/dist/client/helpers.js +43 -0
  6. package/dist/client/helpers.js.map +1 -0
  7. package/dist/client/index.d.ts +1041 -0
  8. package/dist/client/index.d.ts.map +1 -0
  9. package/dist/client/index.js +1068 -0
  10. package/dist/client/index.js.map +1 -0
  11. package/dist/client/parsers.d.ts +45 -0
  12. package/dist/client/parsers.d.ts.map +1 -0
  13. package/dist/client/parsers.js +138 -0
  14. package/dist/client/parsers.js.map +1 -0
  15. package/dist/client/polyfill.d.ts +2 -0
  16. package/dist/client/polyfill.d.ts.map +1 -0
  17. package/dist/client/polyfill.js +3 -0
  18. package/dist/client/polyfill.js.map +1 -0
  19. package/dist/component/_generated/api.d.ts +36 -0
  20. package/dist/component/_generated/api.d.ts.map +1 -0
  21. package/dist/component/_generated/api.js +31 -0
  22. package/dist/component/_generated/api.js.map +1 -0
  23. package/dist/component/_generated/component.d.ts +542 -0
  24. package/dist/component/_generated/component.d.ts.map +1 -0
  25. package/dist/component/_generated/component.js +11 -0
  26. package/dist/component/_generated/component.js.map +1 -0
  27. package/dist/component/_generated/dataModel.d.ts +46 -0
  28. package/dist/component/_generated/dataModel.d.ts.map +1 -0
  29. package/dist/component/_generated/dataModel.js +11 -0
  30. package/dist/component/_generated/dataModel.js.map +1 -0
  31. package/dist/component/_generated/server.d.ts +121 -0
  32. package/dist/component/_generated/server.d.ts.map +1 -0
  33. package/dist/component/_generated/server.js +78 -0
  34. package/dist/component/_generated/server.js.map +1 -0
  35. package/dist/component/convex.config.d.ts +3 -0
  36. package/dist/component/convex.config.d.ts.map +1 -0
  37. package/dist/component/convex.config.js +3 -0
  38. package/dist/component/convex.config.js.map +1 -0
  39. package/dist/component/lib.d.ts +1005 -0
  40. package/dist/component/lib.d.ts.map +1 -0
  41. package/dist/component/lib.js +647 -0
  42. package/dist/component/lib.js.map +1 -0
  43. package/dist/component/schema.d.ts +191 -0
  44. package/dist/component/schema.d.ts.map +1 -0
  45. package/dist/component/schema.js +104 -0
  46. package/dist/component/schema.js.map +1 -0
  47. package/dist/component/util.d.ts +61 -0
  48. package/dist/component/util.d.ts.map +1 -0
  49. package/dist/component/util.js +142 -0
  50. package/dist/component/util.js.map +1 -0
  51. package/dist/core/catalog.d.ts +18 -0
  52. package/dist/core/catalog.d.ts.map +1 -0
  53. package/dist/core/catalog.js +82 -0
  54. package/dist/core/catalog.js.map +1 -0
  55. package/dist/core/index.d.ts +9 -0
  56. package/dist/core/index.d.ts.map +1 -0
  57. package/dist/core/index.js +9 -0
  58. package/dist/core/index.js.map +1 -0
  59. package/dist/core/markdown.d.ts +12 -0
  60. package/dist/core/markdown.d.ts.map +1 -0
  61. package/dist/core/markdown.js +26 -0
  62. package/dist/core/markdown.js.map +1 -0
  63. package/dist/core/payments.d.ts +11 -0
  64. package/dist/core/payments.d.ts.map +1 -0
  65. package/dist/core/payments.js +27 -0
  66. package/dist/core/payments.js.map +1 -0
  67. package/dist/core/pendingCheckout.d.ts +15 -0
  68. package/dist/core/pendingCheckout.d.ts.map +1 -0
  69. package/dist/core/pendingCheckout.js +40 -0
  70. package/dist/core/pendingCheckout.js.map +1 -0
  71. package/dist/core/resolver.d.ts +11 -0
  72. package/dist/core/resolver.d.ts.map +1 -0
  73. package/dist/core/resolver.js +106 -0
  74. package/dist/core/resolver.js.map +1 -0
  75. package/dist/core/selectors.d.ts +12 -0
  76. package/dist/core/selectors.d.ts.map +1 -0
  77. package/dist/core/selectors.js +18 -0
  78. package/dist/core/selectors.js.map +1 -0
  79. package/dist/core/subscriptionUpdate.d.ts +20 -0
  80. package/dist/core/subscriptionUpdate.d.ts.map +1 -0
  81. package/dist/core/subscriptionUpdate.js +64 -0
  82. package/dist/core/subscriptionUpdate.js.map +1 -0
  83. package/dist/core/types.d.ts +170 -0
  84. package/dist/core/types.d.ts.map +1 -0
  85. package/dist/core/types.js +15 -0
  86. package/dist/core/types.js.map +1 -0
  87. package/dist/design-system/colors/color-utils.d.ts +10 -0
  88. package/dist/design-system/colors/color-utils.d.ts.map +1 -0
  89. package/dist/design-system/colors/color-utils.js +91 -0
  90. package/dist/design-system/colors/color-utils.js.map +1 -0
  91. package/dist/design-system/colors/config.d.ts +33 -0
  92. package/dist/design-system/colors/config.d.ts.map +1 -0
  93. package/dist/design-system/colors/config.js +224 -0
  94. package/dist/design-system/colors/config.js.map +1 -0
  95. package/dist/design-system/colors/index.d.ts +3 -0
  96. package/dist/design-system/colors/index.d.ts.map +1 -0
  97. package/dist/design-system/colors/index.js +3 -0
  98. package/dist/design-system/colors/index.js.map +1 -0
  99. package/dist/design-system/rounded/config.d.ts +31 -0
  100. package/dist/design-system/rounded/config.d.ts.map +1 -0
  101. package/dist/design-system/rounded/config.js +76 -0
  102. package/dist/design-system/rounded/config.js.map +1 -0
  103. package/dist/design-system/rounded/index.d.ts +2 -0
  104. package/dist/design-system/rounded/index.d.ts.map +1 -0
  105. package/dist/design-system/rounded/index.js +2 -0
  106. package/dist/design-system/rounded/index.js.map +1 -0
  107. package/dist/design-system/typography/config.d.ts +55 -0
  108. package/dist/design-system/typography/config.d.ts.map +1 -0
  109. package/dist/design-system/typography/config.js +308 -0
  110. package/dist/design-system/typography/config.js.map +1 -0
  111. package/dist/design-system/typography/index.d.ts +3 -0
  112. package/dist/design-system/typography/index.d.ts.map +1 -0
  113. package/dist/design-system/typography/index.js +3 -0
  114. package/dist/design-system/typography/index.js.map +1 -0
  115. package/dist/design-system/typography/tokens.d.ts +23 -0
  116. package/dist/design-system/typography/tokens.d.ts.map +1 -0
  117. package/dist/design-system/typography/tokens.js +99 -0
  118. package/dist/design-system/typography/tokens.js.map +1 -0
  119. package/dist/react/hooks/useCheckoutSuccessParams.d.ts +2 -0
  120. package/dist/react/hooks/useCheckoutSuccessParams.d.ts.map +1 -0
  121. package/dist/react/hooks/useCheckoutSuccessParams.js +5 -0
  122. package/dist/react/hooks/useCheckoutSuccessParams.js.map +1 -0
  123. package/dist/react/index.d.ts +25 -0
  124. package/dist/react/index.d.ts.map +1 -0
  125. package/dist/react/index.js +22 -0
  126. package/dist/react/index.js.map +1 -0
  127. package/dist/react/primitives/BillingGate.d.ts +8 -0
  128. package/dist/react/primitives/BillingGate.d.ts.map +1 -0
  129. package/dist/react/primitives/BillingGate.js +13 -0
  130. package/dist/react/primitives/BillingGate.js.map +1 -0
  131. package/dist/react/primitives/BillingToggle.d.ts +8 -0
  132. package/dist/react/primitives/BillingToggle.d.ts.map +1 -0
  133. package/dist/react/primitives/BillingToggle.js +12 -0
  134. package/dist/react/primitives/BillingToggle.js.map +1 -0
  135. package/dist/react/primitives/CheckoutButton.d.ts +11 -0
  136. package/dist/react/primitives/CheckoutButton.d.ts.map +1 -0
  137. package/dist/react/primitives/CheckoutButton.js +21 -0
  138. package/dist/react/primitives/CheckoutButton.js.map +1 -0
  139. package/dist/react/primitives/CheckoutSuccessSummary.d.ts +7 -0
  140. package/dist/react/primitives/CheckoutSuccessSummary.d.ts.map +1 -0
  141. package/dist/react/primitives/CheckoutSuccessSummary.js +11 -0
  142. package/dist/react/primitives/CheckoutSuccessSummary.js.map +1 -0
  143. package/dist/react/primitives/CustomerPortalButton.d.ts +8 -0
  144. package/dist/react/primitives/CustomerPortalButton.d.ts.map +1 -0
  145. package/dist/react/primitives/CustomerPortalButton.js +21 -0
  146. package/dist/react/primitives/CustomerPortalButton.js.map +1 -0
  147. package/dist/react/primitives/NumberInput.d.ts +11 -0
  148. package/dist/react/primitives/NumberInput.d.ts.map +1 -0
  149. package/dist/react/primitives/NumberInput.js +18 -0
  150. package/dist/react/primitives/NumberInput.js.map +1 -0
  151. package/dist/react/primitives/OneTimeCheckoutButton.d.ts +11 -0
  152. package/dist/react/primitives/OneTimeCheckoutButton.d.ts.map +1 -0
  153. package/dist/react/primitives/OneTimeCheckoutButton.js +4 -0
  154. package/dist/react/primitives/OneTimeCheckoutButton.js.map +1 -0
  155. package/dist/react/primitives/OneTimePaymentStatusBadge.d.ts +6 -0
  156. package/dist/react/primitives/OneTimePaymentStatusBadge.d.ts.map +1 -0
  157. package/dist/react/primitives/OneTimePaymentStatusBadge.js +11 -0
  158. package/dist/react/primitives/OneTimePaymentStatusBadge.js.map +1 -0
  159. package/dist/react/primitives/PaymentWarningBanner.d.ts +7 -0
  160. package/dist/react/primitives/PaymentWarningBanner.d.ts.map +1 -0
  161. package/dist/react/primitives/PaymentWarningBanner.js +18 -0
  162. package/dist/react/primitives/PaymentWarningBanner.js.map +1 -0
  163. package/dist/react/primitives/PricingCard.d.ts +37 -0
  164. package/dist/react/primitives/PricingCard.d.ts.map +1 -0
  165. package/dist/react/primitives/PricingCard.js +125 -0
  166. package/dist/react/primitives/PricingCard.js.map +1 -0
  167. package/dist/react/primitives/PricingSection.d.ts +39 -0
  168. package/dist/react/primitives/PricingSection.d.ts.map +1 -0
  169. package/dist/react/primitives/PricingSection.js +24 -0
  170. package/dist/react/primitives/PricingSection.js.map +1 -0
  171. package/dist/react/primitives/ScheduledChangeBanner.d.ts +8 -0
  172. package/dist/react/primitives/ScheduledChangeBanner.d.ts.map +1 -0
  173. package/dist/react/primitives/ScheduledChangeBanner.js +13 -0
  174. package/dist/react/primitives/ScheduledChangeBanner.js.map +1 -0
  175. package/dist/react/primitives/SegmentControl.d.ts +11 -0
  176. package/dist/react/primitives/SegmentControl.d.ts.map +1 -0
  177. package/dist/react/primitives/SegmentControl.js +8 -0
  178. package/dist/react/primitives/SegmentControl.js.map +1 -0
  179. package/dist/react/primitives/SegmentGroup.d.ts +14 -0
  180. package/dist/react/primitives/SegmentGroup.d.ts.map +1 -0
  181. package/dist/react/primitives/SegmentGroup.js +11 -0
  182. package/dist/react/primitives/SegmentGroup.js.map +1 -0
  183. package/dist/react/primitives/TrialLimitBanner.d.ts +7 -0
  184. package/dist/react/primitives/TrialLimitBanner.d.ts.map +1 -0
  185. package/dist/react/primitives/TrialLimitBanner.js +14 -0
  186. package/dist/react/primitives/TrialLimitBanner.js.map +1 -0
  187. package/dist/react/shared.d.ts +28 -0
  188. package/dist/react/shared.d.ts.map +1 -0
  189. package/dist/react/shared.js +109 -0
  190. package/dist/react/shared.js.map +1 -0
  191. package/dist/react/widgets/BillingPortal.d.ts +9 -0
  192. package/dist/react/widgets/BillingPortal.d.ts.map +1 -0
  193. package/dist/react/widgets/BillingPortal.js +30 -0
  194. package/dist/react/widgets/BillingPortal.js.map +1 -0
  195. package/dist/react/widgets/ProductItem.d.ts +8 -0
  196. package/dist/react/widgets/ProductItem.d.ts.map +1 -0
  197. package/dist/react/widgets/ProductItem.js +14 -0
  198. package/dist/react/widgets/ProductItem.js.map +1 -0
  199. package/dist/react/widgets/ProductRoot.d.ts +16 -0
  200. package/dist/react/widgets/ProductRoot.d.ts.map +1 -0
  201. package/dist/react/widgets/ProductRoot.js +171 -0
  202. package/dist/react/widgets/ProductRoot.js.map +1 -0
  203. package/dist/react/widgets/SubscriptionItem.d.ts +27 -0
  204. package/dist/react/widgets/SubscriptionItem.d.ts.map +1 -0
  205. package/dist/react/widgets/SubscriptionItem.js +32 -0
  206. package/dist/react/widgets/SubscriptionItem.js.map +1 -0
  207. package/dist/react/widgets/SubscriptionRoot.d.ts +16 -0
  208. package/dist/react/widgets/SubscriptionRoot.d.ts.map +1 -0
  209. package/dist/react/widgets/SubscriptionRoot.js +405 -0
  210. package/dist/react/widgets/SubscriptionRoot.js.map +1 -0
  211. package/dist/react/widgets/index.d.ts +19 -0
  212. package/dist/react/widgets/index.d.ts.map +1 -0
  213. package/dist/react/widgets/index.js +16 -0
  214. package/dist/react/widgets/index.js.map +1 -0
  215. package/dist/react/widgets/productGroupContext.d.ts +6 -0
  216. package/dist/react/widgets/productGroupContext.d.ts.map +1 -0
  217. package/dist/react/widgets/productGroupContext.js +3 -0
  218. package/dist/react/widgets/productGroupContext.js.map +1 -0
  219. package/dist/react/widgets/subscriptionContext.d.ts +6 -0
  220. package/dist/react/widgets/subscriptionContext.d.ts.map +1 -0
  221. package/dist/react/widgets/subscriptionContext.js +3 -0
  222. package/dist/react/widgets/subscriptionContext.js.map +1 -0
  223. package/dist/react/widgets/types.d.ts +171 -0
  224. package/dist/react/widgets/types.d.ts.map +1 -0
  225. package/dist/react/widgets/types.js +2 -0
  226. package/dist/react/widgets/types.js.map +1 -0
  227. package/dist/svelte/index.d.ts +22 -0
  228. package/dist/svelte/index.d.ts.map +1 -0
  229. package/dist/svelte/index.js +20 -0
  230. package/dist/svelte/index.js.map +1 -0
  231. package/dist/svelte/primitives/BillingGate.svelte +28 -0
  232. package/dist/svelte/primitives/BillingToggle.svelte +27 -0
  233. package/dist/svelte/primitives/CheckoutButton.svelte +60 -0
  234. package/dist/svelte/primitives/CheckoutSuccessSummary.svelte +34 -0
  235. package/dist/svelte/primitives/CustomerPortalButton.svelte +60 -0
  236. package/dist/svelte/primitives/NumberInput.svelte +71 -0
  237. package/dist/svelte/primitives/OneTimeCheckoutButton.svelte +37 -0
  238. package/dist/svelte/primitives/OneTimePaymentStatusBadge.svelte +20 -0
  239. package/dist/svelte/primitives/PaymentWarningBanner.svelte +30 -0
  240. package/dist/svelte/primitives/PricingCard.svelte +356 -0
  241. package/dist/svelte/primitives/PricingSection.svelte +121 -0
  242. package/dist/svelte/primitives/ScheduledChangeBanner.svelte +46 -0
  243. package/dist/svelte/primitives/SegmentControl.svelte +38 -0
  244. package/dist/svelte/primitives/SegmentGroup.svelte +52 -0
  245. package/dist/svelte/primitives/TrialLimitBanner.svelte +32 -0
  246. package/dist/svelte/primitives/shared.d.ts +13 -0
  247. package/dist/svelte/primitives/shared.d.ts.map +1 -0
  248. package/dist/svelte/primitives/shared.js +87 -0
  249. package/dist/svelte/primitives/shared.js.map +1 -0
  250. package/dist/svelte/widgets/BillingPortal.svelte +55 -0
  251. package/dist/svelte/widgets/Product.svelte +35 -0
  252. package/dist/svelte/widgets/ProductRoot.svelte +428 -0
  253. package/dist/svelte/widgets/Subscription.svelte +52 -0
  254. package/dist/svelte/widgets/SubscriptionRoot.svelte +690 -0
  255. package/dist/svelte/widgets/index.d.ts +19 -0
  256. package/dist/svelte/widgets/index.d.ts.map +1 -0
  257. package/dist/svelte/widgets/index.js +16 -0
  258. package/dist/svelte/widgets/index.js.map +1 -0
  259. package/dist/svelte/widgets/productGroupContext.d.ts +6 -0
  260. package/dist/svelte/widgets/productGroupContext.d.ts.map +1 -0
  261. package/dist/svelte/widgets/productGroupContext.js +2 -0
  262. package/dist/svelte/widgets/productGroupContext.js.map +1 -0
  263. package/dist/svelte/widgets/subscriptionContext.d.ts +6 -0
  264. package/dist/svelte/widgets/subscriptionContext.d.ts.map +1 -0
  265. package/dist/svelte/widgets/subscriptionContext.js +2 -0
  266. package/dist/svelte/widgets/subscriptionContext.js.map +1 -0
  267. package/dist/svelte/widgets/types.d.ts +171 -0
  268. package/dist/svelte/widgets/types.d.ts.map +1 -0
  269. package/dist/svelte/widgets/types.js +2 -0
  270. package/dist/svelte/widgets/types.js.map +1 -0
  271. package/package.json +182 -0
  272. package/src/client/helpers.test.ts +139 -0
  273. package/src/client/helpers.ts +51 -0
  274. package/src/client/index.test.ts +1554 -0
  275. package/src/client/index.ts +1504 -0
  276. package/src/client/parsers.test.ts +1017 -0
  277. package/src/client/parsers.ts +182 -0
  278. package/src/client/polyfill.ts +2 -0
  279. package/src/component/_generated/api.ts +52 -0
  280. package/src/component/_generated/component.ts +619 -0
  281. package/src/component/_generated/dataModel.ts +60 -0
  282. package/src/component/_generated/server.ts +156 -0
  283. package/src/component/convex.config.ts +3 -0
  284. package/src/component/lib.test.ts +1359 -0
  285. package/src/component/lib.ts +726 -0
  286. package/src/component/schema.ts +112 -0
  287. package/src/component/util.test.ts +281 -0
  288. package/src/component/util.ts +228 -0
  289. package/src/core/catalog.test.ts +212 -0
  290. package/src/core/catalog.ts +119 -0
  291. package/src/core/index.ts +8 -0
  292. package/src/core/markdown.test.ts +43 -0
  293. package/src/core/markdown.ts +26 -0
  294. package/src/core/payments.test.ts +69 -0
  295. package/src/core/payments.ts +33 -0
  296. package/src/core/pendingCheckout.test.ts +44 -0
  297. package/src/core/pendingCheckout.ts +40 -0
  298. package/src/core/resolver.test.ts +283 -0
  299. package/src/core/resolver.ts +160 -0
  300. package/src/core/selectors.test.ts +119 -0
  301. package/src/core/selectors.ts +35 -0
  302. package/src/core/subscriptionUpdate.test.ts +164 -0
  303. package/src/core/subscriptionUpdate.ts +102 -0
  304. package/src/core/types.ts +220 -0
  305. package/src/design-system/README.md +40 -0
  306. package/src/design-system/base.css +27 -0
  307. package/src/design-system/colors/color-utils.ts +110 -0
  308. package/src/design-system/colors/config.ts +282 -0
  309. package/src/design-system/colors/index.ts +2 -0
  310. package/src/design-system/colors/utilities.css +2328 -0
  311. package/src/design-system/components/badges.css +65 -0
  312. package/src/design-system/components/buttons.css +256 -0
  313. package/src/design-system/components/dialog.css +218 -0
  314. package/src/design-system/components/icon-buttons.css +115 -0
  315. package/src/design-system/components/inputs.css +94 -0
  316. package/src/design-system/components/links.css +53 -0
  317. package/src/design-system/components/prose.css +67 -0
  318. package/src/design-system/components/segment-control.css +303 -0
  319. package/src/design-system/index.css +21 -0
  320. package/src/design-system/rounded/config.ts +91 -0
  321. package/src/design-system/rounded/index.ts +1 -0
  322. package/src/design-system/rounded/utilities.css +37 -0
  323. package/src/design-system/typography/config.ts +340 -0
  324. package/src/design-system/typography/index.ts +2 -0
  325. package/src/design-system/typography/tokens.ts +148 -0
  326. package/src/design-system/typography/utilities.css +728 -0
  327. package/src/library.css +20 -0
  328. package/src/react/hooks/useCheckoutSuccessParams.ts +7 -0
  329. package/src/react/index.tsx +47 -0
  330. package/src/react/primitives/BillingGate.tsx +26 -0
  331. package/src/react/primitives/BillingToggle.tsx +29 -0
  332. package/src/react/primitives/CheckoutButton.tsx +47 -0
  333. package/src/react/primitives/CheckoutSuccessSummary.tsx +36 -0
  334. package/src/react/primitives/CustomerPortalButton.tsx +50 -0
  335. package/src/react/primitives/NumberInput.tsx +83 -0
  336. package/src/react/primitives/OneTimeCheckoutButton.tsx +27 -0
  337. package/src/react/primitives/OneTimePaymentStatusBadge.tsx +18 -0
  338. package/src/react/primitives/PaymentWarningBanner.tsx +33 -0
  339. package/src/react/primitives/PricingCard.tsx +421 -0
  340. package/src/react/primitives/PricingSection.tsx +129 -0
  341. package/src/react/primitives/ScheduledChangeBanner.tsx +52 -0
  342. package/src/react/primitives/SegmentControl.tsx +32 -0
  343. package/src/react/primitives/SegmentGroup.tsx +53 -0
  344. package/src/react/primitives/TrialLimitBanner.tsx +32 -0
  345. package/src/react/shared.ts +138 -0
  346. package/src/react/widgets/BillingPortal.tsx +56 -0
  347. package/src/react/widgets/ProductItem.tsx +26 -0
  348. package/src/react/widgets/ProductRoot.tsx +441 -0
  349. package/src/react/widgets/SubscriptionItem.tsx +71 -0
  350. package/src/react/widgets/SubscriptionRoot.tsx +759 -0
  351. package/src/react/widgets/index.ts +36 -0
  352. package/src/react/widgets/productGroupContext.ts +10 -0
  353. package/src/react/widgets/subscriptionContext.ts +10 -0
  354. package/src/react/widgets/types.ts +179 -0
  355. package/src/svelte/index.ts +43 -0
  356. package/src/svelte/primitives/BillingGate.svelte +28 -0
  357. package/src/svelte/primitives/BillingToggle.svelte +27 -0
  358. package/src/svelte/primitives/CheckoutButton.svelte +60 -0
  359. package/src/svelte/primitives/CheckoutSuccessSummary.svelte +34 -0
  360. package/src/svelte/primitives/CustomerPortalButton.svelte +60 -0
  361. package/src/svelte/primitives/NumberInput.svelte +71 -0
  362. package/src/svelte/primitives/OneTimeCheckoutButton.svelte +37 -0
  363. package/src/svelte/primitives/OneTimePaymentStatusBadge.svelte +20 -0
  364. package/src/svelte/primitives/PaymentWarningBanner.svelte +30 -0
  365. package/src/svelte/primitives/PricingCard.svelte +356 -0
  366. package/src/svelte/primitives/PricingSection.svelte +121 -0
  367. package/src/svelte/primitives/ScheduledChangeBanner.svelte +46 -0
  368. package/src/svelte/primitives/SegmentControl.svelte +38 -0
  369. package/src/svelte/primitives/SegmentGroup.svelte +52 -0
  370. package/src/svelte/primitives/TrialLimitBanner.svelte +32 -0
  371. package/src/svelte/primitives/shared.ts +113 -0
  372. package/src/svelte/svelte.d.ts +6 -0
  373. package/src/svelte/widgets/BillingPortal.svelte +55 -0
  374. package/src/svelte/widgets/Product.svelte +35 -0
  375. package/src/svelte/widgets/ProductRoot.svelte +428 -0
  376. package/src/svelte/widgets/Subscription.svelte +52 -0
  377. package/src/svelte/widgets/SubscriptionRoot.svelte +690 -0
  378. package/src/svelte/widgets/index.ts +36 -0
  379. package/src/svelte/widgets/productGroupContext.ts +7 -0
  380. package/src/svelte/widgets/subscriptionContext.ts +7 -0
  381. package/src/svelte/widgets/types.ts +179 -0
  382. package/src/tailwind.css +6 -0
  383. package/src/test.ts +18 -0
@@ -0,0 +1,1041 @@
1
+ import "./polyfill.js";
2
+ import { Creem as CreemSDK } from "creem";
3
+ import { type CreemWebhookEvent } from "./parsers.js";
4
+ import { type FunctionReference, type HttpRouter } from "convex/server";
5
+ import { type Infer } from "convex/values";
6
+ import { type RunMutationCtx, type RunSchedulerMutationCtx, type RunQueryCtx, type RunActionCtx } from "../component/util.js";
7
+ import type { ComponentApi } from "../component/_generated/component.js";
8
+ import type { BillingSnapshot, PaymentSnapshot } from "../core/types.js";
9
+ export * from "../core/index.js";
10
+ export type { RunSchedulerMutationCtx } from "../component/util.js";
11
+ export { getEntityId, lowerCaseHeaders, toHex, constantTimeEqual, normalizeSignature, } from "./helpers.js";
12
+ export { type CreemWebhookEvent, getEventType, getEventData, getCustomerId, getConvexEntityId, parseSubscription, parseCheckout, parseProduct, manualParseSubscription, } from "./parsers.js";
13
+ /** Convex validator for the `subscriptions` table. Use with `v.object(subscriptionValidator.fields)` in custom functions. */
14
+ export declare const subscriptionValidator: import("convex/values").VObject<{
15
+ mode?: string | undefined;
16
+ collectionMethod?: string | undefined;
17
+ priceId?: string | undefined;
18
+ discountId?: string | null | undefined;
19
+ canceledAt?: string | null | undefined;
20
+ endsAt?: string | null | undefined;
21
+ trialStart?: string | null | undefined;
22
+ trialEnd?: string | null | undefined;
23
+ seats?: number | null | undefined;
24
+ lastTransactionId?: string | null | undefined;
25
+ nextTransactionDate?: string | null | undefined;
26
+ id: string;
27
+ createdAt: string;
28
+ status: string;
29
+ metadata: Record<string, any>;
30
+ currency: string | null;
31
+ modifiedAt: string | null;
32
+ recurringInterval: string | null;
33
+ customerId: string;
34
+ productId: string;
35
+ amount: number | null;
36
+ currentPeriodStart: string;
37
+ currentPeriodEnd: string | null;
38
+ cancelAtPeriodEnd: boolean;
39
+ startedAt: string | null;
40
+ endedAt: string | null;
41
+ checkoutId: string | null;
42
+ }, {
43
+ id: import("convex/values").VString<string, "required">;
44
+ customerId: import("convex/values").VString<string, "required">;
45
+ productId: import("convex/values").VString<string, "required">;
46
+ status: import("convex/values").VString<string, "required">;
47
+ amount: import("convex/values").VUnion<number | null, [import("convex/values").VFloat64<number, "required">, import("convex/values").VNull<null, "required">], "required", never>;
48
+ currency: import("convex/values").VUnion<string | null, [import("convex/values").VString<string, "required">, import("convex/values").VNull<null, "required">], "required", never>;
49
+ recurringInterval: import("convex/values").VUnion<string | null, [import("convex/values").VString<string, "required">, import("convex/values").VNull<null, "required">], "required", never>;
50
+ currentPeriodStart: import("convex/values").VString<string, "required">;
51
+ currentPeriodEnd: import("convex/values").VUnion<string | null, [import("convex/values").VString<string, "required">, import("convex/values").VNull<null, "required">], "required", never>;
52
+ cancelAtPeriodEnd: import("convex/values").VBoolean<boolean, "required">;
53
+ startedAt: import("convex/values").VUnion<string | null, [import("convex/values").VString<string, "required">, import("convex/values").VNull<null, "required">], "required", never>;
54
+ endedAt: import("convex/values").VUnion<string | null, [import("convex/values").VString<string, "required">, import("convex/values").VNull<null, "required">], "required", never>;
55
+ priceId: import("convex/values").VString<string | undefined, "optional">;
56
+ checkoutId: import("convex/values").VUnion<string | null, [import("convex/values").VString<string, "required">, import("convex/values").VNull<null, "required">], "required", never>;
57
+ metadata: import("convex/values").VRecord<Record<string, any>, import("convex/values").VString<string, "required">, import("convex/values").VAny<any, "required", string>, "required", string>;
58
+ collectionMethod: import("convex/values").VString<string | undefined, "optional">;
59
+ discountId: import("convex/values").VUnion<string | null | undefined, [import("convex/values").VString<string, "required">, import("convex/values").VNull<null, "required">], "optional", never>;
60
+ canceledAt: import("convex/values").VUnion<string | null | undefined, [import("convex/values").VString<string, "required">, import("convex/values").VNull<null, "required">], "optional", never>;
61
+ endsAt: import("convex/values").VUnion<string | null | undefined, [import("convex/values").VString<string, "required">, import("convex/values").VNull<null, "required">], "optional", never>;
62
+ trialStart: import("convex/values").VUnion<string | null | undefined, [import("convex/values").VString<string, "required">, import("convex/values").VNull<null, "required">], "optional", never>;
63
+ trialEnd: import("convex/values").VUnion<string | null | undefined, [import("convex/values").VString<string, "required">, import("convex/values").VNull<null, "required">], "optional", never>;
64
+ seats: import("convex/values").VUnion<number | null | undefined, [import("convex/values").VFloat64<number, "required">, import("convex/values").VNull<null, "required">], "optional", never>;
65
+ lastTransactionId: import("convex/values").VUnion<string | null | undefined, [import("convex/values").VString<string, "required">, import("convex/values").VNull<null, "required">], "optional", never>;
66
+ nextTransactionDate: import("convex/values").VUnion<string | null | undefined, [import("convex/values").VString<string, "required">, import("convex/values").VNull<null, "required">], "optional", never>;
67
+ mode: import("convex/values").VString<string | undefined, "optional">;
68
+ createdAt: import("convex/values").VString<string, "required">;
69
+ modifiedAt: import("convex/values").VUnion<string | null, [import("convex/values").VString<string, "required">, import("convex/values").VNull<null, "required">], "required", never>;
70
+ }, "required", "id" | "mode" | "createdAt" | "collectionMethod" | "status" | "metadata" | `metadata.${string}` | "currency" | "modifiedAt" | "recurringInterval" | "customerId" | "productId" | "amount" | "currentPeriodStart" | "currentPeriodEnd" | "cancelAtPeriodEnd" | "startedAt" | "endedAt" | "priceId" | "checkoutId" | "discountId" | "canceledAt" | "endsAt" | "trialStart" | "trialEnd" | "seats" | "lastTransactionId" | "nextTransactionDate">;
71
+ /** TypeScript type for a subscription document (inferred from the Convex schema). */
72
+ export type Subscription = Infer<typeof subscriptionValidator>;
73
+ /**
74
+ * Convex arg validator for checkout creation.
75
+ * Matches the args sent by `<Subscription.Root>` and `<Product.Root>` widgets.
76
+ * Use in your own `action()` definitions for custom RBAC wrappers.
77
+ */
78
+ export declare const checkoutCreateArgs: {
79
+ productId: import("convex/values").VString<string, "required">;
80
+ successUrl: import("convex/values").VString<string | undefined, "optional">;
81
+ fallbackSuccessUrl: import("convex/values").VString<string | undefined, "optional">;
82
+ units: import("convex/values").VFloat64<number | undefined, "optional">;
83
+ metadata: import("convex/values").VRecord<Record<string, string> | undefined, import("convex/values").VString<string, "required">, import("convex/values").VString<string, "required">, "optional", string>;
84
+ discountCode: import("convex/values").VString<string | undefined, "optional">;
85
+ theme: import("convex/values").VUnion<"light" | "dark" | undefined, [import("convex/values").VLiteral<"light", "required">, import("convex/values").VLiteral<"dark", "required">], "optional", never>;
86
+ };
87
+ /**
88
+ * Convex arg validator for subscription updates (plan switch or seat change).
89
+ * Matches the args sent by `<Subscription.Root>` widgets.
90
+ */
91
+ export declare const subscriptionUpdateArgs: {
92
+ subscriptionId: import("convex/values").VString<string | undefined, "optional">;
93
+ productId: import("convex/values").VString<string | undefined, "optional">;
94
+ units: import("convex/values").VFloat64<number | undefined, "optional">;
95
+ updateBehavior: import("convex/values").VUnion<"proration-charge-immediately" | "proration-charge" | "proration-none" | undefined, [import("convex/values").VLiteral<"proration-charge-immediately", "required">, import("convex/values").VLiteral<"proration-charge", "required">, import("convex/values").VLiteral<"proration-none", "required">], "optional", never>;
96
+ };
97
+ /**
98
+ * Convex arg validator for subscription cancellation.
99
+ * Matches the args sent by `<Subscription.Root>` cancel button.
100
+ */
101
+ export declare const subscriptionCancelArgs: {
102
+ subscriptionId: import("convex/values").VString<string | undefined, "optional">;
103
+ revokeImmediately: import("convex/values").VBoolean<boolean | undefined, "optional">;
104
+ };
105
+ /**
106
+ * Convex arg validator for subscription resume.
107
+ * Matches the args sent by `<Subscription.Root>` resume button.
108
+ */
109
+ export declare const subscriptionResumeArgs: {
110
+ subscriptionId: import("convex/values").VString<string | undefined, "optional">;
111
+ };
112
+ /**
113
+ * Convex arg validator for subscription pause.
114
+ * Matches the args sent by `<Subscription.Root>` pause button.
115
+ */
116
+ export declare const subscriptionPauseArgs: {
117
+ subscriptionId: import("convex/values").VString<string | undefined, "optional">;
118
+ };
119
+ /** Function reference type for internal mutations that receive a subscription document. */
120
+ export type SubscriptionHandler = FunctionReference<"mutation", "internal", {
121
+ subscription: Subscription;
122
+ }>;
123
+ /**
124
+ * Map of webhook event type → handler function.
125
+ * Handlers run **after** the component's built-in processing (customer/subscription/order upserts).
126
+ * The `ctx` is a Convex mutation context — you can read/write to your own tables.
127
+ *
128
+ * @example
129
+ * ```ts
130
+ * creem.registerRoutes(http, {
131
+ * events: {
132
+ * "checkout.completed": async (ctx, event) => {
133
+ * // Grant entitlements, send emails, log analytics
134
+ * },
135
+ * },
136
+ * });
137
+ * ```
138
+ */
139
+ export type WebhookEventHandlers = Record<string, (ctx: RunMutationCtx, event: CreemWebhookEvent) => Promise<void> | void>;
140
+ /**
141
+ * Callback that resolves the authenticated user for `creem.api({ resolve })`.
142
+ * Called on every generated Convex function to determine the billing entity.
143
+ *
144
+ * - `userId` — your app's user ID (stored in checkout metadata as `convexUserId`)
145
+ * - `email` — user's email (passed to Creem for customer creation)
146
+ * - `entityId` — billing entity ID. For personal billing, same as `userId`.
147
+ * For org billing, return the org ID so all billing scopes to the organization.
148
+ *
149
+ * @example
150
+ * ```ts
151
+ * const resolve: ApiResolver = async (ctx) => {
152
+ * const user = await ctx.runQuery(api.users.currentUser);
153
+ * return { userId: user._id, email: user.email, entityId: user._id };
154
+ * };
155
+ * ```
156
+ */
157
+ export type ApiResolver = (ctx: RunQueryCtx) => Promise<{
158
+ userId: string;
159
+ email: string;
160
+ entityId: string;
161
+ }>;
162
+ /**
163
+ * Configuration for the Creem Convex component.
164
+ * All fields are optional — environment variables are used as fallbacks.
165
+ */
166
+ type CreemConfig = {
167
+ /**
168
+ * Default cancel mode for subscriptions.
169
+ * - `"immediate"` — cancel and revoke access now
170
+ * - `"scheduled"` — cancel at end of current billing period
171
+ * - Omit to use Creem's store-level default.
172
+ */
173
+ cancelMode?: "immediate" | "scheduled";
174
+ /** Creem API key. Falls back to `CREEM_API_KEY` env var. */
175
+ apiKey?: string;
176
+ /** Creem webhook signing secret. Falls back to `CREEM_WEBHOOK_SECRET` env var. */
177
+ webhookSecret?: string;
178
+ /** Creem SDK server index (for non-default endpoints). Falls back to `CREEM_SERVER_IDX` env var. */
179
+ serverIdx?: number;
180
+ /** Creem SDK server URL override (for test/staging). Falls back to `CREEM_SERVER_URL` env var. */
181
+ serverURL?: string;
182
+ };
183
+ /**
184
+ * Main entry point for the Creem–Convex integration.
185
+ *
186
+ * Instantiate once in your `convex/billing.ts` and use its methods
187
+ * to manage subscriptions, checkouts, products, customers, and orders.
188
+ *
189
+ * **Two usage patterns:**
190
+ * 1. **Quick start** — call `creem.api({ resolve })` to generate ready-to-export Convex functions
191
+ * 2. **Full control** — use namespace getters (`creem.subscriptions.*`, `creem.checkouts.*`, etc.)
192
+ * directly in your own Convex functions for custom auth/RBAC
193
+ *
194
+ * @example
195
+ * ```ts
196
+ * import { Creem } from "@mmailaender/convex-creem";
197
+ * import { components } from "./_generated/api";
198
+ *
199
+ * export const creem = new Creem(components.creem);
200
+ * ```
201
+ */
202
+ export declare class Creem {
203
+ component: ComponentApi;
204
+ private config;
205
+ /** Direct access to the Creem SDK client, pre-configured with your API key. Use for resources without webhook sync (licenses, discounts, transactions). */
206
+ sdk: CreemSDK;
207
+ private apiKey;
208
+ private webhookSecret;
209
+ private serverIdx?;
210
+ private serverURL?;
211
+ constructor(component: ComponentApi, config?: CreemConfig);
212
+ private getCustomerByEntityId;
213
+ /** Pull all products from the Creem API into the Convex database. Typically called once via `internalAction` or the CLI. */
214
+ syncProducts(ctx: RunActionCtx): Promise<void>;
215
+ private createCheckoutSession;
216
+ private createCustomerPortalSession;
217
+ private listProducts;
218
+ private getCurrentSubscription;
219
+ /** Return active subscriptions for an entity, excluding ended and expired trials. */
220
+ private listUserSubscriptions;
221
+ /** Return paid one-time orders for an entity. */
222
+ private listUserOrders;
223
+ /** Return all subscriptions for an entity, including ended and expired trials. */
224
+ private listAllUserSubscriptions;
225
+ private getProduct;
226
+ private toSubscriptionSnapshot;
227
+ /**
228
+ * Resolve the current billing state for a billing entity.
229
+ * Returns plan, status, available actions, subscription metadata, etc.
230
+ * Used internally by `getBillingModel` and exposed for custom billing UIs.
231
+ */
232
+ getBillingSnapshot(ctx: RunQueryCtx, { entityId, payment, }: {
233
+ entityId: string;
234
+ payment?: PaymentSnapshot | null;
235
+ }): Promise<BillingSnapshot>;
236
+ private verifyWebhook;
237
+ /** Upsert a customer record if we have both entityId and customerId. */
238
+ private upsertCustomerFromWebhook;
239
+ /**
240
+ * Subscription management namespace.
241
+ *
242
+ * All methods take explicit `entityId` — use them directly in your own
243
+ * Convex functions, or let `creem.api({ resolve })` handle auth for you.
244
+ *
245
+ * - `.getCurrent()` — current active subscription with product join (Convex DB)
246
+ * - `.list()` — active subscriptions, excludes ended + expired trials (Convex DB)
247
+ * - `.listAll()` — all subscriptions including ended (Convex DB)
248
+ * - `.update()` — plan switch (`productId`) or seat change (`units`) (Creem API, optimistic)
249
+ * - `.cancel()` — cancel subscription (Creem API, optimistic)
250
+ * - `.pause()` — pause an active subscription (Creem API, optimistic)
251
+ * - `.resume()` — resume a paused or scheduled-cancel subscription (Creem API, optimistic)
252
+ */
253
+ get subscriptions(): {
254
+ getCurrent: (ctx: RunQueryCtx, { entityId }: {
255
+ entityId: string;
256
+ }) => Promise<{
257
+ product: {
258
+ billingPeriod?: string;
259
+ billingType: string;
260
+ createdAt: string;
261
+ currency: string;
262
+ defaultSuccessUrl?: string | null;
263
+ description: string | null;
264
+ features?: Array<{
265
+ description: string;
266
+ id: string;
267
+ }>;
268
+ id: string;
269
+ imageUrl?: string;
270
+ metadata?: Record<string, any>;
271
+ mode?: string;
272
+ modifiedAt: string | null;
273
+ name: string;
274
+ price: number;
275
+ productUrl?: string;
276
+ status: string;
277
+ taxCategory?: string;
278
+ taxMode?: string;
279
+ };
280
+ amount: number | null;
281
+ cancelAtPeriodEnd: boolean;
282
+ canceledAt?: string | null;
283
+ checkoutId: string | null;
284
+ collectionMethod?: string;
285
+ createdAt: string;
286
+ currency: string | null;
287
+ currentPeriodEnd: string | null;
288
+ currentPeriodStart: string;
289
+ customerId: string;
290
+ discountId?: string | null;
291
+ endedAt: string | null;
292
+ endsAt?: string | null;
293
+ id: string;
294
+ lastTransactionId?: string | null;
295
+ metadata: Record<string, any>;
296
+ mode?: string;
297
+ modifiedAt: string | null;
298
+ nextTransactionDate?: string | null;
299
+ priceId?: string;
300
+ productId: string;
301
+ recurringInterval: string | null;
302
+ seats?: number | null;
303
+ startedAt: string | null;
304
+ status: string;
305
+ trialEnd?: string | null;
306
+ trialStart?: string | null;
307
+ } | null>;
308
+ list: (ctx: RunQueryCtx, { entityId }: {
309
+ entityId: string;
310
+ }) => Promise<{
311
+ amount: number | null;
312
+ cancelAtPeriodEnd: boolean;
313
+ canceledAt?: string | null;
314
+ checkoutId: string | null;
315
+ collectionMethod?: string;
316
+ createdAt: string;
317
+ currency: string | null;
318
+ currentPeriodEnd: string | null;
319
+ currentPeriodStart: string;
320
+ customerId: string;
321
+ discountId?: string | null;
322
+ endedAt: string | null;
323
+ endsAt?: string | null;
324
+ id: string;
325
+ lastTransactionId?: string | null;
326
+ metadata: Record<string, any>;
327
+ mode?: string;
328
+ modifiedAt: string | null;
329
+ nextTransactionDate?: string | null;
330
+ priceId?: string;
331
+ product: {
332
+ billingPeriod?: string;
333
+ billingType: string;
334
+ createdAt: string;
335
+ currency: string;
336
+ defaultSuccessUrl?: string | null;
337
+ description: string | null;
338
+ features?: Array<{
339
+ description: string;
340
+ id: string;
341
+ }>;
342
+ id: string;
343
+ imageUrl?: string;
344
+ metadata?: Record<string, any>;
345
+ mode?: string;
346
+ modifiedAt: string | null;
347
+ name: string;
348
+ price: number;
349
+ productUrl?: string;
350
+ status: string;
351
+ taxCategory?: string;
352
+ taxMode?: string;
353
+ } | null;
354
+ productId: string;
355
+ recurringInterval: string | null;
356
+ seats?: number | null;
357
+ startedAt: string | null;
358
+ status: string;
359
+ trialEnd?: string | null;
360
+ trialStart?: string | null;
361
+ }[]>;
362
+ listAll: (ctx: RunQueryCtx, { entityId }: {
363
+ entityId: string;
364
+ }) => Promise<{
365
+ amount: number | null;
366
+ cancelAtPeriodEnd: boolean;
367
+ canceledAt?: string | null;
368
+ checkoutId: string | null;
369
+ collectionMethod?: string;
370
+ createdAt: string;
371
+ currency: string | null;
372
+ currentPeriodEnd: string | null;
373
+ currentPeriodStart: string;
374
+ customerId: string;
375
+ discountId?: string | null;
376
+ endedAt: string | null;
377
+ endsAt?: string | null;
378
+ id: string;
379
+ lastTransactionId?: string | null;
380
+ metadata: Record<string, any>;
381
+ mode?: string;
382
+ modifiedAt: string | null;
383
+ nextTransactionDate?: string | null;
384
+ priceId?: string;
385
+ product: {
386
+ billingPeriod?: string;
387
+ billingType: string;
388
+ createdAt: string;
389
+ currency: string;
390
+ defaultSuccessUrl?: string | null;
391
+ description: string | null;
392
+ features?: Array<{
393
+ description: string;
394
+ id: string;
395
+ }>;
396
+ id: string;
397
+ imageUrl?: string;
398
+ metadata?: Record<string, any>;
399
+ mode?: string;
400
+ modifiedAt: string | null;
401
+ name: string;
402
+ price: number;
403
+ productUrl?: string;
404
+ status: string;
405
+ taxCategory?: string;
406
+ taxMode?: string;
407
+ } | null;
408
+ productId: string;
409
+ recurringInterval: string | null;
410
+ seats?: number | null;
411
+ startedAt: string | null;
412
+ status: string;
413
+ trialEnd?: string | null;
414
+ trialStart?: string | null;
415
+ }[]>;
416
+ update: (ctx: RunSchedulerMutationCtx, args: {
417
+ entityId: string;
418
+ subscriptionId?: string;
419
+ productId?: string;
420
+ units?: number;
421
+ updateBehavior?: "proration-charge-immediately" | "proration-charge" | "proration-none";
422
+ }) => Promise<void>;
423
+ cancel: (ctx: RunSchedulerMutationCtx, args: {
424
+ entityId: string;
425
+ subscriptionId?: string;
426
+ revokeImmediately?: boolean;
427
+ }) => Promise<void>;
428
+ pause: (ctx: RunSchedulerMutationCtx, args: {
429
+ entityId: string;
430
+ subscriptionId?: string;
431
+ }) => Promise<void>;
432
+ resume: (ctx: RunSchedulerMutationCtx, args: {
433
+ entityId: string;
434
+ subscriptionId?: string;
435
+ }) => Promise<void>;
436
+ };
437
+ /**
438
+ * Checkout namespace.
439
+ *
440
+ * - `.create()` — create a checkout URL with 3-tier `successUrl` resolution and optional `theme` (Creem API)
441
+ */
442
+ get checkouts(): {
443
+ create: (ctx: RunActionCtx, args: {
444
+ entityId: string;
445
+ userId: string;
446
+ email: string;
447
+ productId: string;
448
+ successUrl?: string;
449
+ fallbackSuccessUrl?: string;
450
+ units?: number;
451
+ metadata?: Record<string, string>;
452
+ discountCode?: string;
453
+ theme?: "light" | "dark";
454
+ }) => Promise<{
455
+ url: string;
456
+ }>;
457
+ };
458
+ /**
459
+ * Product namespace. All reads come from the local Convex DB (synced via webhooks).
460
+ *
461
+ * - `.list()` — all synced products (public, no `entityId` needed)
462
+ * - `.get()` — single product by Creem product ID
463
+ */
464
+ get products(): {
465
+ list: (ctx: RunQueryCtx, options?: {
466
+ includeArchived?: boolean;
467
+ }) => Promise<{
468
+ billingPeriod?: string;
469
+ billingType: string;
470
+ createdAt: string;
471
+ currency: string;
472
+ defaultSuccessUrl?: string | null;
473
+ description: string | null;
474
+ features?: Array<{
475
+ description: string;
476
+ id: string;
477
+ }>;
478
+ id: string;
479
+ imageUrl?: string;
480
+ metadata?: Record<string, any>;
481
+ mode?: string;
482
+ modifiedAt: string | null;
483
+ name: string;
484
+ price: number;
485
+ productUrl?: string;
486
+ status: string;
487
+ taxCategory?: string;
488
+ taxMode?: string;
489
+ }[]>;
490
+ get: (ctx: RunQueryCtx, { productId }: {
491
+ productId: string;
492
+ }) => Promise<{
493
+ billingPeriod?: string;
494
+ billingType: string;
495
+ createdAt: string;
496
+ currency: string;
497
+ defaultSuccessUrl?: string | null;
498
+ description: string | null;
499
+ features?: Array<{
500
+ description: string;
501
+ id: string;
502
+ }>;
503
+ id: string;
504
+ imageUrl?: string;
505
+ metadata?: Record<string, any>;
506
+ mode?: string;
507
+ modifiedAt: string | null;
508
+ name: string;
509
+ price: number;
510
+ productUrl?: string;
511
+ status: string;
512
+ taxCategory?: string;
513
+ taxMode?: string;
514
+ } | null>;
515
+ };
516
+ /**
517
+ * Customer namespace.
518
+ *
519
+ * - `.retrieve()` — customer record by billing entity (Convex DB)
520
+ * - `.portalUrl()` — generate a Creem customer billing portal URL (Creem API)
521
+ */
522
+ get customers(): {
523
+ retrieve: (ctx: RunQueryCtx, { entityId }: {
524
+ entityId: string;
525
+ }) => Promise<{
526
+ country?: string;
527
+ createdAt?: string;
528
+ email?: string;
529
+ entityId: string;
530
+ id: string;
531
+ metadata?: Record<string, any>;
532
+ mode?: string;
533
+ name?: string | null;
534
+ updatedAt?: string;
535
+ } | null>;
536
+ portalUrl: (ctx: RunActionCtx, { entityId }: {
537
+ entityId: string;
538
+ }) => Promise<{
539
+ url: string;
540
+ }>;
541
+ };
542
+ /**
543
+ * Order namespace.
544
+ *
545
+ * - `.list()` — paid one-time orders for a billing entity (Convex DB)
546
+ */
547
+ get orders(): {
548
+ list: (ctx: RunQueryCtx, { entityId }: {
549
+ entityId: string;
550
+ }) => Promise<{
551
+ affiliate?: string | null;
552
+ amount: number;
553
+ amountDue?: number;
554
+ amountPaid?: number;
555
+ checkoutId?: string | null;
556
+ createdAt: string;
557
+ currency: string;
558
+ customerId: string;
559
+ discountAmount?: number;
560
+ discountId?: string | null;
561
+ id: string;
562
+ metadata?: Record<string, any>;
563
+ mode?: string;
564
+ productId: string;
565
+ status: string;
566
+ subTotal?: number;
567
+ taxAmount?: number;
568
+ transactionId?: string | null;
569
+ type: string;
570
+ updatedAt: string;
571
+ }[]>;
572
+ };
573
+ /**
574
+ * Composite billing model for connected widgets.
575
+ *
576
+ * Aggregates snapshot + products + subscriptions + orders into a single
577
+ * object that `<Subscription.Root>` and `<Product.Root>` widgets consume.
578
+ *
579
+ * Graceful when `entityId` is `null` — returns public product catalog only
580
+ * (useful for unauthenticated pricing pages).
581
+ *
582
+ * @param ctx - Convex query context
583
+ * @param options.entityId - Billing entity ID, or `null` for public-only data
584
+ * @param options.user - User info for the UI (widgets display email, etc.)
585
+ */
586
+ getBillingModel(ctx: RunQueryCtx, { entityId, user, }: {
587
+ entityId: string | null;
588
+ user?: {
589
+ _id: string;
590
+ email: string;
591
+ } | null;
592
+ }): Promise<{
593
+ user: {
594
+ _id: string;
595
+ email: string;
596
+ } | null;
597
+ billingSnapshot: BillingSnapshot | null;
598
+ allProducts: {
599
+ billingPeriod?: string;
600
+ billingType: string;
601
+ createdAt: string;
602
+ currency: string;
603
+ defaultSuccessUrl?: string | null;
604
+ description: string | null;
605
+ features?: Array<{
606
+ description: string;
607
+ id: string;
608
+ }>;
609
+ id: string;
610
+ imageUrl?: string;
611
+ metadata?: Record<string, any>;
612
+ mode?: string;
613
+ modifiedAt: string | null;
614
+ name: string;
615
+ price: number;
616
+ productUrl?: string;
617
+ status: string;
618
+ taxCategory?: string;
619
+ taxMode?: string;
620
+ }[];
621
+ ownedProductIds: string[];
622
+ subscriptionProductId: string | null;
623
+ activeSubscriptions: Array<{
624
+ id: string;
625
+ productId: string;
626
+ status: string;
627
+ cancelAtPeriodEnd: boolean;
628
+ currentPeriodEnd: string | null;
629
+ currentPeriodStart: string;
630
+ seats: number | null;
631
+ recurringInterval: string | null;
632
+ trialEnd: string | null;
633
+ }>;
634
+ hasCreemCustomer: boolean;
635
+ } | {
636
+ user: {
637
+ _id: string;
638
+ email: string;
639
+ } | null;
640
+ billingSnapshot: BillingSnapshot;
641
+ allProducts: {
642
+ billingPeriod?: string;
643
+ billingType: string;
644
+ createdAt: string;
645
+ currency: string;
646
+ defaultSuccessUrl?: string | null;
647
+ description: string | null;
648
+ features?: Array<{
649
+ description: string;
650
+ id: string;
651
+ }>;
652
+ id: string;
653
+ imageUrl?: string;
654
+ metadata?: Record<string, any>;
655
+ mode?: string;
656
+ modifiedAt: string | null;
657
+ name: string;
658
+ price: number;
659
+ productUrl?: string;
660
+ status: string;
661
+ taxCategory?: string;
662
+ taxMode?: string;
663
+ }[];
664
+ ownedProductIds: string[];
665
+ subscriptionProductId: string | null;
666
+ activeSubscriptions: {
667
+ id: string;
668
+ productId: string;
669
+ status: string;
670
+ cancelAtPeriodEnd: boolean;
671
+ currentPeriodEnd: string | null;
672
+ currentPeriodStart: string;
673
+ seats: number | null | undefined;
674
+ recurringInterval: string | null;
675
+ trialEnd: string | null;
676
+ }[];
677
+ hasCreemCustomer: boolean;
678
+ }>;
679
+ /**
680
+ * Generate ready-to-export Convex function definitions.
681
+ *
682
+ * Each function calls your `resolve` callback to authenticate the user
683
+ * and determine the billing entity, then delegates to the corresponding
684
+ * namespace method. Destructure and re-export in your `convex/billing.ts`.
685
+ *
686
+ * For full control, use the namespace getters directly instead
687
+ * (e.g. `creem.subscriptions.cancel(ctx, { entityId })`).
688
+ *
689
+ * @param options.resolve - Auth callback that returns `{ userId, email, entityId }`
690
+ * @returns Object with `uiModel`, `snapshot`, `checkouts`, `subscriptions`, `products`, `customers`, `orders`
691
+ *
692
+ * @example
693
+ * ```ts
694
+ * const { uiModel, checkouts, subscriptions } = creem.api({ resolve });
695
+ * export { uiModel };
696
+ * export const checkoutsCreate = checkouts.create;
697
+ * ```
698
+ */
699
+ api({ resolve }: {
700
+ resolve: ApiResolver;
701
+ }): {
702
+ uiModel: import("convex/server").RegisteredQuery<"public", {}, Promise<{
703
+ user: {
704
+ _id: string;
705
+ email: string;
706
+ } | null;
707
+ billingSnapshot: BillingSnapshot | null;
708
+ allProducts: {
709
+ billingPeriod?: string;
710
+ billingType: string;
711
+ createdAt: string;
712
+ currency: string;
713
+ defaultSuccessUrl?: string | null;
714
+ description: string | null;
715
+ features?: Array<{
716
+ description: string;
717
+ id: string;
718
+ }>;
719
+ id: string;
720
+ imageUrl?: string;
721
+ metadata?: Record<string, any>;
722
+ mode?: string;
723
+ modifiedAt: string | null;
724
+ name: string;
725
+ price: number;
726
+ productUrl?: string;
727
+ status: string;
728
+ taxCategory?: string;
729
+ taxMode?: string;
730
+ }[];
731
+ ownedProductIds: string[];
732
+ subscriptionProductId: string | null;
733
+ activeSubscriptions: Array<{
734
+ id: string;
735
+ productId: string;
736
+ status: string;
737
+ cancelAtPeriodEnd: boolean;
738
+ currentPeriodEnd: string | null;
739
+ currentPeriodStart: string;
740
+ seats: number | null;
741
+ recurringInterval: string | null;
742
+ trialEnd: string | null;
743
+ }>;
744
+ hasCreemCustomer: boolean;
745
+ } | {
746
+ user: {
747
+ _id: string;
748
+ email: string;
749
+ } | null;
750
+ billingSnapshot: BillingSnapshot;
751
+ allProducts: {
752
+ billingPeriod?: string;
753
+ billingType: string;
754
+ createdAt: string;
755
+ currency: string;
756
+ defaultSuccessUrl?: string | null;
757
+ description: string | null;
758
+ features?: Array<{
759
+ description: string;
760
+ id: string;
761
+ }>;
762
+ id: string;
763
+ imageUrl?: string;
764
+ metadata?: Record<string, any>;
765
+ mode?: string;
766
+ modifiedAt: string | null;
767
+ name: string;
768
+ price: number;
769
+ productUrl?: string;
770
+ status: string;
771
+ taxCategory?: string;
772
+ taxMode?: string;
773
+ }[];
774
+ ownedProductIds: string[];
775
+ subscriptionProductId: string | null;
776
+ activeSubscriptions: {
777
+ id: string;
778
+ productId: string;
779
+ status: string;
780
+ cancelAtPeriodEnd: boolean;
781
+ currentPeriodEnd: string | null;
782
+ currentPeriodStart: string;
783
+ seats: number | null | undefined;
784
+ recurringInterval: string | null;
785
+ trialEnd: string | null;
786
+ }[];
787
+ hasCreemCustomer: boolean;
788
+ }>>;
789
+ snapshot: import("convex/server").RegisteredQuery<"public", {}, Promise<BillingSnapshot | null>>;
790
+ checkouts: {
791
+ create: import("convex/server").RegisteredAction<"public", {
792
+ units?: number | undefined;
793
+ metadata?: Record<string, string> | undefined;
794
+ successUrl?: string | undefined;
795
+ fallbackSuccessUrl?: string | undefined;
796
+ discountCode?: string | undefined;
797
+ theme?: "light" | "dark" | undefined;
798
+ productId: string;
799
+ }, Promise<{
800
+ url: string;
801
+ }>>;
802
+ };
803
+ subscriptions: {
804
+ update: import("convex/server").RegisteredMutation<"public", {
805
+ units?: number | undefined;
806
+ productId?: string | undefined;
807
+ subscriptionId?: string | undefined;
808
+ updateBehavior?: "proration-charge-immediately" | "proration-charge" | "proration-none" | undefined;
809
+ }, Promise<void>>;
810
+ cancel: import("convex/server").RegisteredMutation<"public", {
811
+ subscriptionId?: string | undefined;
812
+ revokeImmediately?: boolean | undefined;
813
+ }, Promise<void>>;
814
+ resume: import("convex/server").RegisteredMutation<"public", {
815
+ subscriptionId?: string | undefined;
816
+ }, Promise<void>>;
817
+ pause: import("convex/server").RegisteredMutation<"public", {
818
+ subscriptionId?: string | undefined;
819
+ }, Promise<void>>;
820
+ list: import("convex/server").RegisteredQuery<"public", {}, Promise<{
821
+ amount: number | null;
822
+ cancelAtPeriodEnd: boolean;
823
+ canceledAt?: string | null;
824
+ checkoutId: string | null;
825
+ collectionMethod?: string;
826
+ createdAt: string;
827
+ currency: string | null;
828
+ currentPeriodEnd: string | null;
829
+ currentPeriodStart: string;
830
+ customerId: string;
831
+ discountId?: string | null;
832
+ endedAt: string | null;
833
+ endsAt?: string | null;
834
+ id: string;
835
+ lastTransactionId?: string | null;
836
+ metadata: Record<string, any>;
837
+ mode?: string;
838
+ modifiedAt: string | null;
839
+ nextTransactionDate?: string | null;
840
+ priceId?: string;
841
+ product: {
842
+ billingPeriod?: string;
843
+ billingType: string;
844
+ createdAt: string;
845
+ currency: string;
846
+ defaultSuccessUrl?: string | null;
847
+ description: string | null;
848
+ features?: Array<{
849
+ description: string;
850
+ id: string;
851
+ }>;
852
+ id: string;
853
+ imageUrl?: string;
854
+ metadata?: Record<string, any>;
855
+ mode?: string;
856
+ modifiedAt: string | null;
857
+ name: string;
858
+ price: number;
859
+ productUrl?: string;
860
+ status: string;
861
+ taxCategory?: string;
862
+ taxMode?: string;
863
+ } | null;
864
+ productId: string;
865
+ recurringInterval: string | null;
866
+ seats?: number | null;
867
+ startedAt: string | null;
868
+ status: string;
869
+ trialEnd?: string | null;
870
+ trialStart?: string | null;
871
+ }[]>>;
872
+ listAll: import("convex/server").RegisteredQuery<"public", {}, Promise<{
873
+ amount: number | null;
874
+ cancelAtPeriodEnd: boolean;
875
+ canceledAt?: string | null;
876
+ checkoutId: string | null;
877
+ collectionMethod?: string;
878
+ createdAt: string;
879
+ currency: string | null;
880
+ currentPeriodEnd: string | null;
881
+ currentPeriodStart: string;
882
+ customerId: string;
883
+ discountId?: string | null;
884
+ endedAt: string | null;
885
+ endsAt?: string | null;
886
+ id: string;
887
+ lastTransactionId?: string | null;
888
+ metadata: Record<string, any>;
889
+ mode?: string;
890
+ modifiedAt: string | null;
891
+ nextTransactionDate?: string | null;
892
+ priceId?: string;
893
+ product: {
894
+ billingPeriod?: string;
895
+ billingType: string;
896
+ createdAt: string;
897
+ currency: string;
898
+ defaultSuccessUrl?: string | null;
899
+ description: string | null;
900
+ features?: Array<{
901
+ description: string;
902
+ id: string;
903
+ }>;
904
+ id: string;
905
+ imageUrl?: string;
906
+ metadata?: Record<string, any>;
907
+ mode?: string;
908
+ modifiedAt: string | null;
909
+ name: string;
910
+ price: number;
911
+ productUrl?: string;
912
+ status: string;
913
+ taxCategory?: string;
914
+ taxMode?: string;
915
+ } | null;
916
+ productId: string;
917
+ recurringInterval: string | null;
918
+ seats?: number | null;
919
+ startedAt: string | null;
920
+ status: string;
921
+ trialEnd?: string | null;
922
+ trialStart?: string | null;
923
+ }[]>>;
924
+ };
925
+ products: {
926
+ list: import("convex/server").RegisteredQuery<"public", {}, Promise<{
927
+ billingPeriod?: string;
928
+ billingType: string;
929
+ createdAt: string;
930
+ currency: string;
931
+ defaultSuccessUrl?: string | null;
932
+ description: string | null;
933
+ features?: Array<{
934
+ description: string;
935
+ id: string;
936
+ }>;
937
+ id: string;
938
+ imageUrl?: string;
939
+ metadata?: Record<string, any>;
940
+ mode?: string;
941
+ modifiedAt: string | null;
942
+ name: string;
943
+ price: number;
944
+ productUrl?: string;
945
+ status: string;
946
+ taxCategory?: string;
947
+ taxMode?: string;
948
+ }[]>>;
949
+ get: import("convex/server").RegisteredQuery<"public", {
950
+ productId: string;
951
+ }, Promise<{
952
+ billingPeriod?: string;
953
+ billingType: string;
954
+ createdAt: string;
955
+ currency: string;
956
+ defaultSuccessUrl?: string | null;
957
+ description: string | null;
958
+ features?: Array<{
959
+ description: string;
960
+ id: string;
961
+ }>;
962
+ id: string;
963
+ imageUrl?: string;
964
+ metadata?: Record<string, any>;
965
+ mode?: string;
966
+ modifiedAt: string | null;
967
+ name: string;
968
+ price: number;
969
+ productUrl?: string;
970
+ status: string;
971
+ taxCategory?: string;
972
+ taxMode?: string;
973
+ } | null>>;
974
+ };
975
+ customers: {
976
+ retrieve: import("convex/server").RegisteredQuery<"public", {}, Promise<{
977
+ country?: string;
978
+ createdAt?: string;
979
+ email?: string;
980
+ entityId: string;
981
+ id: string;
982
+ metadata?: Record<string, any>;
983
+ mode?: string;
984
+ name?: string | null;
985
+ updatedAt?: string;
986
+ } | null>>;
987
+ portalUrl: import("convex/server").RegisteredAction<"public", {}, Promise<{
988
+ url: string;
989
+ }>>;
990
+ };
991
+ orders: {
992
+ list: import("convex/server").RegisteredQuery<"public", {}, Promise<{
993
+ affiliate?: string | null;
994
+ amount: number;
995
+ amountDue?: number;
996
+ amountPaid?: number;
997
+ checkoutId?: string | null;
998
+ createdAt: string;
999
+ currency: string;
1000
+ customerId: string;
1001
+ discountAmount?: number;
1002
+ discountId?: string | null;
1003
+ id: string;
1004
+ metadata?: Record<string, any>;
1005
+ mode?: string;
1006
+ productId: string;
1007
+ status: string;
1008
+ subTotal?: number;
1009
+ taxAmount?: number;
1010
+ transactionId?: string | null;
1011
+ type: string;
1012
+ updatedAt: string;
1013
+ }[]>>;
1014
+ };
1015
+ };
1016
+ /**
1017
+ * Register the Creem webhook HTTP route on your Convex `httpRouter`.
1018
+ *
1019
+ * Automatically handles `checkout.completed`, `subscription.*`, and `product.*`
1020
+ * events — upserts customers, subscriptions, orders, and products in the Convex DB.
1021
+ *
1022
+ * @param http - Your Convex HTTP router (from `httpRouter()`)
1023
+ * @param options.path - Webhook endpoint path (default: `"/creem/events"`)
1024
+ * @param options.events - Optional custom handlers that run **after** built-in processing
1025
+ *
1026
+ * @example
1027
+ * ```ts
1028
+ * const http = httpRouter();
1029
+ * creem.registerRoutes(http, {
1030
+ * events: {
1031
+ * "checkout.completed": async (ctx, event) => { ... },
1032
+ * },
1033
+ * });
1034
+ * ```
1035
+ */
1036
+ registerRoutes(http: HttpRouter, { path, events, }?: {
1037
+ path?: string;
1038
+ events?: WebhookEventHandlers;
1039
+ }): void;
1040
+ }
1041
+ //# sourceMappingURL=index.d.ts.map