@nextblock-cms/ecom 0.20.1 → 0.21.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 (317) hide show
  1. package/_virtual/_rolldown/runtime.cjs.js +1 -0
  2. package/index.cjs.js +1 -1
  3. package/index.es.js +38 -146
  4. package/lib/CurrencyProvider.cjs.js +1 -1
  5. package/lib/CurrencyProvider.d.ts +1 -1
  6. package/lib/CurrencyProvider.es.js +85 -95
  7. package/lib/PaymentReadinessProvider.cjs.js +1 -1
  8. package/lib/PaymentReadinessProvider.d.ts +1 -1
  9. package/lib/PaymentReadinessProvider.es.js +24 -27
  10. package/lib/cart-store.cjs.js +1 -1
  11. package/lib/cart-store.es.js +109 -121
  12. package/lib/components/AccountNavigationMenu.cjs.js +1 -1
  13. package/lib/components/AccountNavigationMenu.d.ts +1 -1
  14. package/lib/components/AccountNavigationMenu.es.js +36 -50
  15. package/lib/components/AddToCartButton.cjs.js +1 -1
  16. package/lib/components/AddToCartButton.d.ts +1 -1
  17. package/lib/components/AddToCartButton.es.js +94 -89
  18. package/lib/components/Cart.cjs.js +1 -1
  19. package/lib/components/Cart.d.ts +1 -1
  20. package/lib/components/Cart.es.js +261 -180
  21. package/lib/components/CartDrawer.cjs.js +1 -1
  22. package/lib/components/CartDrawer.d.ts +1 -1
  23. package/lib/components/CartDrawer.es.js +218 -148
  24. package/lib/components/CartIcon.cjs.js +1 -1
  25. package/lib/components/CartIcon.d.ts +1 -1
  26. package/lib/components/CartIcon.es.js +33 -35
  27. package/lib/components/Checkout.cjs.js +1 -1
  28. package/lib/components/Checkout.d.ts +1 -1
  29. package/lib/components/Checkout.es.js +1092 -1108
  30. package/lib/components/CouponForm.cjs.js +1 -1
  31. package/lib/components/CouponForm.d.ts +1 -1
  32. package/lib/components/CouponForm.es.js +136 -148
  33. package/lib/components/CurrencySwitcher.cjs.js +1 -1
  34. package/lib/components/CurrencySwitcher.d.ts +1 -1
  35. package/lib/components/CurrencySwitcher.es.js +22 -18
  36. package/lib/components/CustomerProfileForm.cjs.js +1 -1
  37. package/lib/components/CustomerProfileForm.es.js +454 -313
  38. package/lib/components/FeaturedProduct.cjs.js +1 -1
  39. package/lib/components/FeaturedProduct.d.ts +1 -1
  40. package/lib/components/FeaturedProduct.es.js +98 -83
  41. package/lib/components/FreemiusLicensePanel.cjs.js +1 -1
  42. package/lib/components/FreemiusLicensePanel.d.ts +1 -1
  43. package/lib/components/FreemiusLicensePanel.es.js +70 -65
  44. package/lib/components/InvoiceDocument.cjs.js +1 -1
  45. package/lib/components/InvoiceDocument.es.js +256 -192
  46. package/lib/components/InvoiceViewerShell.cjs.js +2 -2
  47. package/lib/components/InvoiceViewerShell.d.ts +1 -1
  48. package/lib/components/InvoiceViewerShell.es.js +75 -106
  49. package/lib/components/ProductCard.cjs.js +1 -1
  50. package/lib/components/ProductCard.d.ts +1 -1
  51. package/lib/components/ProductCard.es.js +186 -171
  52. package/lib/components/ProductDetailsLayout.cjs.js +1 -1
  53. package/lib/components/ProductDetailsLayout.es.js +405 -404
  54. package/lib/components/ProductGallery.cjs.js +1 -1
  55. package/lib/components/ProductGallery.d.ts +1 -1
  56. package/lib/components/ProductGallery.es.js +51 -54
  57. package/lib/components/ProductGrid.cjs.js +1 -1
  58. package/lib/components/ProductGrid.d.ts +1 -1
  59. package/lib/components/ProductGrid.es.js +23 -25
  60. package/lib/components/ShippingEstimator.cjs.js +1 -1
  61. package/lib/components/ShippingEstimator.d.ts +1 -1
  62. package/lib/components/ShippingEstimator.es.js +158 -153
  63. package/lib/components/ShortDescription.cjs.js +1 -1
  64. package/lib/components/ShortDescription.es.js +17 -17
  65. package/lib/components/SimpleTiptapRenderer.cjs.js +1 -1
  66. package/lib/components/SimpleTiptapRenderer.es.js +238 -211
  67. package/lib/components/SubscriptionSelector.cjs.js +1 -1
  68. package/lib/components/SubscriptionSelector.es.js +159 -154
  69. package/lib/countries.cjs.js +1 -1
  70. package/lib/countries.es.js +232 -75
  71. package/lib/coupon-server.cjs.js +1 -1
  72. package/lib/coupon-server.es.js +180 -224
  73. package/lib/coupons.cjs.js +1 -1
  74. package/lib/coupons.es.js +12 -14
  75. package/lib/currency-constants.cjs.js +1 -1
  76. package/lib/currency-constants.es.js +4 -4
  77. package/lib/currency-rest-client.cjs.js +1 -1
  78. package/lib/currency-rest-client.es.js +15 -22
  79. package/lib/currency-store.cjs.js +1 -1
  80. package/lib/currency-store.es.js +20 -27
  81. package/lib/currency-sync.cjs.js +1 -1
  82. package/lib/currency-sync.es.js +124 -170
  83. package/lib/currency.cjs.js +1 -1
  84. package/lib/currency.es.js +242 -310
  85. package/lib/customer-addresses.cjs.js +1 -1
  86. package/lib/customer-addresses.es.js +80 -109
  87. package/lib/customer-orders.cjs.js +1 -1
  88. package/lib/customer-orders.es.js +31 -43
  89. package/lib/customer.cjs.js +1 -1
  90. package/lib/customer.es.js +43 -52
  91. package/lib/export-helpers.cjs.js +1 -1
  92. package/lib/export-helpers.es.js +53 -52
  93. package/lib/factory.cjs.js +1 -1
  94. package/lib/factory.es.js +10 -7
  95. package/lib/freemius-coupons.cjs.js +1 -1
  96. package/lib/freemius-coupons.es.js +245 -262
  97. package/lib/freemius-license-claim.cjs.js +1 -1
  98. package/lib/freemius-license-claim.es.js +87 -71
  99. package/lib/freemius-license.cjs.js +1 -1
  100. package/lib/freemius-license.es.js +32 -39
  101. package/lib/freemius-order-sync.cjs.js +1 -1
  102. package/lib/freemius-order-sync.es.js +226 -290
  103. package/lib/freemius-trial-provision.cjs.js +1 -1
  104. package/lib/freemius-trial-provision.es.js +136 -130
  105. package/lib/inventory-settings.cjs.js +1 -1
  106. package/lib/inventory-settings.es.js +69 -77
  107. package/lib/invoice-server.cjs.js +3 -3
  108. package/lib/invoice-server.es.js +94 -141
  109. package/lib/invoice-ui.cjs.js +1 -1
  110. package/lib/invoice-ui.es.js +50 -66
  111. package/lib/invoice.cjs.js +1 -1
  112. package/lib/invoice.es.js +85 -94
  113. package/lib/order-inventory.cjs.js +25 -25
  114. package/lib/order-inventory.es.js +67 -79
  115. package/lib/order-tax-details.cjs.js +1 -1
  116. package/lib/order-tax-details.es.js +142 -153
  117. package/lib/pages/cms/coupons/CouponEditorForm.cjs.js +1 -1
  118. package/lib/pages/cms/coupons/CouponEditorForm.d.ts +1 -1
  119. package/lib/pages/cms/coupons/CouponEditorForm.es.js +227 -185
  120. package/lib/pages/cms/coupons/CouponsPage.cjs.js +2 -2
  121. package/lib/pages/cms/coupons/CouponsPage.d.ts +1 -1
  122. package/lib/pages/cms/coupons/CouponsPage.es.js +235 -166
  123. package/lib/pages/cms/coupons/CreateCouponDialog.cjs.js +1 -1
  124. package/lib/pages/cms/coupons/CreateCouponDialog.d.ts +1 -1
  125. package/lib/pages/cms/coupons/CreateCouponDialog.es.js +35 -34
  126. package/lib/pages/cms/coupons/EditCouponPage.cjs.js +1 -1
  127. package/lib/pages/cms/coupons/EditCouponPage.d.ts +1 -1
  128. package/lib/pages/cms/coupons/EditCouponPage.es.js +47 -47
  129. package/lib/pages/cms/coupons/ProductScopePicker.cjs.js +1 -1
  130. package/lib/pages/cms/coupons/ProductScopePicker.d.ts +1 -1
  131. package/lib/pages/cms/coupons/ProductScopePicker.es.js +128 -117
  132. package/lib/pages/cms/coupons/actions.cjs.js +1 -1
  133. package/lib/pages/cms/coupons/actions.es.js +112 -115
  134. package/lib/pages/cms/coupons/index.cjs.js +1 -0
  135. package/lib/pages/cms/coupons/index.es.js +3 -0
  136. package/lib/pages/cms/coupons/product-options.cjs.js +1 -1
  137. package/lib/pages/cms/coupons/product-options.es.js +21 -23
  138. package/lib/pages/cms/orders/ExportReportsDialog.cjs.js +1 -1
  139. package/lib/pages/cms/orders/ExportReportsDialog.es.js +135 -129
  140. package/lib/pages/cms/orders/MarkPaidButton.d.ts +1 -1
  141. package/lib/pages/cms/orders/OrderDetailPage.cjs.js +1 -1
  142. package/lib/pages/cms/orders/OrderDetailPage.d.ts +1 -1
  143. package/lib/pages/cms/orders/OrderDetailPage.es.js +186 -134
  144. package/lib/pages/cms/orders/OrderPrintButton.cjs.js +1 -1
  145. package/lib/pages/cms/orders/OrderPrintButton.d.ts +1 -1
  146. package/lib/pages/cms/orders/OrderPrintButton.es.js +15 -21
  147. package/lib/pages/cms/orders/OrderStatusForm.cjs.js +1 -1
  148. package/lib/pages/cms/orders/OrderStatusForm.d.ts +1 -1
  149. package/lib/pages/cms/orders/OrderStatusForm.es.js +85 -69
  150. package/lib/pages/cms/orders/OrdersPage.cjs.js +1 -1
  151. package/lib/pages/cms/orders/OrdersPage.d.ts +1 -1
  152. package/lib/pages/cms/orders/OrdersPage.es.js +170 -102
  153. package/lib/pages/cms/orders/actions.cjs.js +3 -3
  154. package/lib/pages/cms/orders/actions.es.js +53 -69
  155. package/lib/pages/cms/orders/export-actions.cjs.js +1 -1
  156. package/lib/pages/cms/orders/export-actions.es.js +23 -26
  157. package/lib/pages/cms/orders/index.cjs.js +1 -0
  158. package/lib/pages/cms/orders/index.es.js +6 -0
  159. package/lib/pages/cms/orders/server-actions.cjs.js +1 -1
  160. package/lib/pages/cms/orders/server-actions.es.js +60 -51
  161. package/lib/pages/cms/payments/PaymentsClient.cjs.js +1 -1
  162. package/lib/pages/cms/payments/PaymentsClient.d.ts +1 -1
  163. package/lib/pages/cms/payments/PaymentsClient.es.js +316 -346
  164. package/lib/pages/cms/payments/PaymentsPage.cjs.js +1 -1
  165. package/lib/pages/cms/payments/PaymentsPage.d.ts +1 -1
  166. package/lib/pages/cms/payments/PaymentsPage.es.js +29 -32
  167. package/lib/pages/cms/payments/actions.cjs.js +1 -1
  168. package/lib/pages/cms/payments/actions.es.js +38 -48
  169. package/lib/pages/cms/payments/index.cjs.js +1 -0
  170. package/lib/pages/cms/payments/index.es.js +3 -0
  171. package/lib/pages/cms/payments/queries.cjs.js +1 -1
  172. package/lib/pages/cms/payments/queries.es.js +38 -48
  173. package/lib/pages/cms/products/ProductsPage.cjs.js +1 -1
  174. package/lib/pages/cms/products/ProductsPage.d.ts +1 -1
  175. package/lib/pages/cms/products/ProductsPage.es.js +63 -66
  176. package/lib/pages/cms/products/[id]/edit/EditProductPage.d.ts +1 -1
  177. package/lib/pages/cms/products/_id_/edit/EditProductPage.cjs.js +1 -1
  178. package/lib/pages/cms/products/_id_/edit/EditProductPage.es.js +138 -155
  179. package/lib/pages/cms/products/actions.cjs.js +4 -4
  180. package/lib/pages/cms/products/actions.es.js +121 -162
  181. package/lib/pages/cms/products/attributes/AttributeManagementPage.cjs.js +1 -1
  182. package/lib/pages/cms/products/attributes/AttributeManagementPage.d.ts +1 -1
  183. package/lib/pages/cms/products/attributes/AttributeManagementPage.es.js +55 -47
  184. package/lib/pages/cms/products/attributes/components/AttributeManager.cjs.js +1 -1
  185. package/lib/pages/cms/products/attributes/components/AttributeManager.d.ts +1 -1
  186. package/lib/pages/cms/products/attributes/components/AttributeManager.es.js +285 -290
  187. package/lib/pages/cms/products/categories/CategoryManagementPage.cjs.js +1 -1
  188. package/lib/pages/cms/products/categories/CategoryManagementPage.d.ts +1 -1
  189. package/lib/pages/cms/products/categories/CategoryManagementPage.es.js +43 -35
  190. package/lib/pages/cms/products/categories/components/CategoryManager.cjs.js +1 -1
  191. package/lib/pages/cms/products/categories/components/CategoryManager.es.js +315 -262
  192. package/lib/pages/cms/products/components/CopyProductFromLanguage.cjs.js +1 -1
  193. package/lib/pages/cms/products/components/CopyProductFromLanguage.es.js +115 -113
  194. package/lib/pages/cms/products/components/CurrencyPriceFields.cjs.js +1 -1
  195. package/lib/pages/cms/products/components/CurrencyPriceFields.d.ts +1 -1
  196. package/lib/pages/cms/products/components/CurrencyPriceFields.es.js +136 -145
  197. package/lib/pages/cms/products/components/DeleteProductButton.cjs.js +1 -1
  198. package/lib/pages/cms/products/components/DeleteProductButton.d.ts +1 -1
  199. package/lib/pages/cms/products/components/DeleteProductButton.es.js +35 -47
  200. package/lib/pages/cms/products/components/FreemiusPricingDashboard.cjs.js +1 -1
  201. package/lib/pages/cms/products/components/FreemiusPricingDashboard.d.ts +1 -1
  202. package/lib/pages/cms/products/components/FreemiusPricingDashboard.es.js +106 -84
  203. package/lib/pages/cms/products/components/ProductCategorySelector.cjs.js +1 -1
  204. package/lib/pages/cms/products/components/ProductCategorySelector.es.js +156 -159
  205. package/lib/pages/cms/products/components/ProductForm.cjs.js +1 -1
  206. package/lib/pages/cms/products/components/ProductForm.es.js +872 -693
  207. package/lib/pages/cms/products/components/ProductMediaManager.cjs.js +1 -1
  208. package/lib/pages/cms/products/components/ProductMediaManager.es.js +106 -103
  209. package/lib/pages/cms/products/components/ProductsBulkTable.cjs.js +1 -1
  210. package/lib/pages/cms/products/components/ProductsBulkTable.d.ts +1 -1
  211. package/lib/pages/cms/products/components/ProductsBulkTable.es.js +303 -294
  212. package/lib/pages/cms/products/components/SaleScheduleFields.cjs.js +1 -1
  213. package/lib/pages/cms/products/components/SaleScheduleFields.d.ts +1 -1
  214. package/lib/pages/cms/products/components/SaleScheduleFields.es.js +111 -134
  215. package/lib/pages/cms/products/components/SyncFreemiusButton.cjs.js +1 -1
  216. package/lib/pages/cms/products/components/SyncFreemiusButton.d.ts +1 -1
  217. package/lib/pages/cms/products/components/SyncFreemiusButton.es.js +29 -35
  218. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.cjs.js +2 -2
  219. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.d.ts +1 -1
  220. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.es.js +36 -48
  221. package/lib/pages/cms/products/components/SyncProductForm.d.ts +1 -1
  222. package/lib/pages/cms/products/components/VariationsEditor.cjs.js +1 -1
  223. package/lib/pages/cms/products/components/VariationsEditor.d.ts +1 -1
  224. package/lib/pages/cms/products/components/VariationsEditor.es.js +396 -405
  225. package/lib/pages/cms/products/index.cjs.js +1 -0
  226. package/lib/pages/cms/products/index.es.js +8 -0
  227. package/lib/pages/cms/products/inventory/InventoryPage.cjs.js +1 -1
  228. package/lib/pages/cms/products/inventory/InventoryPage.d.ts +1 -1
  229. package/lib/pages/cms/products/inventory/InventoryPage.es.js +21 -15
  230. package/lib/pages/cms/products/inventory/InventoryTableClient.cjs.js +2 -2
  231. package/lib/pages/cms/products/inventory/InventoryTableClient.d.ts +1 -1
  232. package/lib/pages/cms/products/inventory/InventoryTableClient.es.js +230 -209
  233. package/lib/pages/cms/products/inventory/actions.cjs.js +3 -3
  234. package/lib/pages/cms/products/inventory/actions.es.js +83 -91
  235. package/lib/pages/cms/products/new/NewProductPage.cjs.js +1 -1
  236. package/lib/pages/cms/products/new/NewProductPage.d.ts +1 -1
  237. package/lib/pages/cms/products/new/NewProductPage.es.js +58 -74
  238. package/lib/pages/cms/products/product-price-sync.cjs.js +1 -1
  239. package/lib/pages/cms/products/product-price-sync.es.js +74 -89
  240. package/lib/pages/cms/products/server-actions.cjs.js +1 -1
  241. package/lib/pages/cms/products/server-actions.es.js +250 -233
  242. package/lib/pages/cms/shipping/ShippingPage.cjs.js +2 -2
  243. package/lib/pages/cms/shipping/ShippingPage.es.js +287 -209
  244. package/lib/pages/cms/shipping/components/RateForm.cjs.js +1 -1
  245. package/lib/pages/cms/shipping/components/RateForm.d.ts +1 -1
  246. package/lib/pages/cms/shipping/components/RateForm.es.js +439 -436
  247. package/lib/pages/cms/shipping/components/ZoneForm.cjs.js +1 -1
  248. package/lib/pages/cms/shipping/components/ZoneForm.es.js +245 -224
  249. package/lib/pages/cms/shipping/index.cjs.js +1 -0
  250. package/lib/pages/cms/shipping/index.es.js +3 -0
  251. package/lib/pages/cms/shipping/server-actions.cjs.js +1 -1
  252. package/lib/pages/cms/shipping/server-actions.es.js +131 -149
  253. package/lib/pages/cms/taxes/TaxesPage.cjs.js +1 -1
  254. package/lib/pages/cms/taxes/TaxesPage.d.ts +1 -1
  255. package/lib/pages/cms/taxes/TaxesPage.es.js +211 -169
  256. package/lib/pages/cms/taxes/actions.cjs.js +1 -1
  257. package/lib/pages/cms/taxes/actions.es.js +41 -53
  258. package/lib/pages/cms/taxes/components/TaxRateForm.cjs.js +1 -1
  259. package/lib/pages/cms/taxes/components/TaxRateForm.d.ts +1 -1
  260. package/lib/pages/cms/taxes/components/TaxRateForm.es.js +112 -99
  261. package/lib/pages/cms/taxes/index.cjs.js +1 -0
  262. package/lib/pages/cms/taxes/index.es.js +3 -0
  263. package/lib/payment-config.cjs.js +1 -1
  264. package/lib/payment-config.es.js +110 -126
  265. package/lib/product-actions.cjs.js +4 -4
  266. package/lib/product-actions.es.js +289 -544
  267. package/lib/product-context.cjs.js +1 -1
  268. package/lib/product-context.es.js +13 -15
  269. package/lib/product-schema.cjs.js +1 -1
  270. package/lib/product-schema.es.js +99 -134
  271. package/lib/providers/freemius.cjs.js +1 -5
  272. package/lib/providers/freemius.es.js +446 -530
  273. package/lib/providers/stripe.cjs.js +1 -1
  274. package/lib/providers/stripe.es.js +417 -477
  275. package/lib/server-actions/coupon-actions.cjs.js +1 -1
  276. package/lib/server-actions/coupon-actions.es.js +22 -22
  277. package/lib/server-actions/customer-actions.cjs.js +1 -1
  278. package/lib/server-actions/customer-actions.es.js +26 -28
  279. package/lib/server-actions/product-actions.cjs.js +1 -1
  280. package/lib/server-actions/product-actions.es.js +9 -15
  281. package/lib/server-actions/shipping-actions.cjs.js +1 -1
  282. package/lib/server-actions/shipping-actions.es.js +27 -24
  283. package/lib/server-actions/tax-actions.cjs.js +1 -1
  284. package/lib/server-actions/tax-actions.es.js +33 -39
  285. package/lib/shared-inventory.cjs.js +2 -2
  286. package/lib/shared-inventory.es.js +111 -160
  287. package/lib/shipping/resolver.cjs.js +2 -2
  288. package/lib/shipping/resolver.es.js +44 -61
  289. package/lib/shipping-rate-currency.cjs.js +1 -1
  290. package/lib/shipping-rate-currency.es.js +52 -67
  291. package/lib/states.cjs.js +1 -1
  292. package/lib/states.es.js +333 -154
  293. package/lib/stripe/checkout.cjs.js +1 -1
  294. package/lib/stripe/checkout.es.js +125 -181
  295. package/lib/stripe/client.cjs.js +1 -1
  296. package/lib/stripe/client.es.js +14 -19
  297. package/lib/stripe/order-sync.cjs.js +1 -1
  298. package/lib/stripe/order-sync.es.js +106 -126
  299. package/lib/stripe/webhooks.cjs.js +1 -1
  300. package/lib/stripe/webhooks.es.js +37 -31
  301. package/lib/tax-calculation.cjs.js +1 -1
  302. package/lib/tax-calculation.es.js +84 -98
  303. package/lib/trials.cjs.js +1 -1
  304. package/lib/trials.es.js +24 -30
  305. package/lib/types.cjs.js +1 -1
  306. package/lib/types.es.js +21 -27
  307. package/lib/use-cart.cjs.js +1 -1
  308. package/lib/use-cart.es.js +38 -40
  309. package/lib/use-price-formatter.cjs.js +1 -1
  310. package/lib/use-price-formatter.es.js +10 -11
  311. package/lib/variation-utils.cjs.js +1 -1
  312. package/lib/variation-utils.es.js +199 -261
  313. package/lib/zod-config.cjs.js +1 -1
  314. package/lib/zod-config.es.js +5 -6
  315. package/package.json +16 -16
  316. package/server.cjs.js +1 -1
  317. package/server.es.js +56 -211
@@ -1,48 +1,48 @@
1
- import { jsxs as i, jsx as e } from "react/jsx-runtime";
2
- import l from "next/link";
3
- import { notFound as m } from "next/navigation";
4
- import { Button as f } from "@nextblock-cms/ui";
5
- import { getServiceRoleSupabaseClient as _ } from "@nextblock-cms/db/server";
6
- import { updateCouponAction as g } from "./actions.es.js";
7
- import { CouponEditorForm as h } from "./CouponEditorForm.es.js";
8
- import { normalizeCouponProductOptions as x } from "./product-options.es.js";
9
- async function N({ params: n }) {
10
- const { id: t } = await n, o = _(), [
11
- { data: c },
12
- { data: a },
13
- { data: s },
14
- { data: d }
15
- ] = await Promise.all([
16
- o.from("coupons").select("*").eq("id", t).single(),
17
- o.from("products").select(
18
- "id, title, sku, payment_provider, freemius_product_id, language:languages(code, name), product_media(sort_order, media(file_path, object_key))"
19
- ).order("title", { ascending: !0 }),
20
- o.from("coupon_products").select("product_id").eq("coupon_id", t),
21
- o.from("currencies").select("code, is_default").eq("is_active", !0)
22
- ]);
23
- c || m();
24
- const u = (s || []).map((r) => r.product_id), p = d?.find((r) => r.is_default)?.code || d?.[0]?.code || "USD";
25
- return /* @__PURE__ */ i("div", { className: "mx-auto w-full max-w-5xl space-y-6 px-6 py-8", children: [
26
- /* @__PURE__ */ i("div", { className: "flex items-center justify-between", children: [
27
- /* @__PURE__ */ i("div", { children: [
28
- /* @__PURE__ */ e("h1", { className: "text-3xl font-bold tracking-tight", children: "Edit Coupon" }),
29
- /* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground", children: "Changes are resynced to Freemius after saving." })
30
- ] }),
31
- /* @__PURE__ */ e(f, { asChild: !0, variant: "outline", children: /* @__PURE__ */ e(l, { href: "/cms/coupons", children: "Back to coupons" }) })
32
- ] }),
33
- /* @__PURE__ */ e(
34
- h,
35
- {
36
- action: g.bind(null, t),
37
- products: x(a),
38
- coupon: c,
39
- selectedProductIds: u,
40
- submitLabel: "Save Coupon",
41
- currencyCode: p
42
- }
43
- )
44
- ] });
1
+ import { updateCouponAction as e } from "./actions.es.js";
2
+ import { CouponEditorForm as t } from "./CouponEditorForm.es.js";
3
+ import { normalizeCouponProductOptions as n } from "./product-options.es.js";
4
+ import r from "next/link";
5
+ import { jsx as i, jsxs as a } from "react/jsx-runtime";
6
+ import { getServiceRoleSupabaseClient as o } from "@nextblock-cms/db/server";
7
+ import { notFound as s } from "next/navigation";
8
+ import { Button as c } from "@nextblock-cms/ui";
9
+ //#region libs/ecommerce/src/lib/pages/cms/coupons/EditCouponPage.tsx
10
+ async function l({ params: l }) {
11
+ let { id: u } = await l, d = o(), [{ data: f }, { data: p }, { data: m }, { data: h }] = await Promise.all([
12
+ d.from("coupons").select("*").eq("id", u).single(),
13
+ d.from("products").select("id, title, sku, payment_provider, freemius_product_id, language:languages(code, name), product_media(sort_order, media(file_path, object_key))").order("title", { ascending: !0 }),
14
+ d.from("coupon_products").select("product_id").eq("coupon_id", u),
15
+ d.from("currencies").select("code, is_default").eq("is_active", !0)
16
+ ]);
17
+ f || s();
18
+ let g = (m || []).map((e) => e.product_id), _ = h?.find((e) => e.is_default)?.code || h?.[0]?.code || "USD";
19
+ return /* @__PURE__ */ a("div", {
20
+ className: "mx-auto w-full max-w-5xl space-y-6 px-6 py-8",
21
+ children: [/* @__PURE__ */ a("div", {
22
+ className: "flex items-center justify-between",
23
+ children: [/* @__PURE__ */ a("div", { children: [/* @__PURE__ */ i("h1", {
24
+ className: "text-3xl font-bold tracking-tight",
25
+ children: "Edit Coupon"
26
+ }), /* @__PURE__ */ i("p", {
27
+ className: "text-sm text-muted-foreground",
28
+ children: "Changes are resynced to Freemius after saving."
29
+ })] }), /* @__PURE__ */ i(c, {
30
+ asChild: !0,
31
+ variant: "outline",
32
+ children: /* @__PURE__ */ i(r, {
33
+ href: "/cms/coupons",
34
+ children: "Back to coupons"
35
+ })
36
+ })]
37
+ }), /* @__PURE__ */ i(t, {
38
+ action: e.bind(null, u),
39
+ products: n(p),
40
+ coupon: f,
41
+ selectedProductIds: g,
42
+ submitLabel: "Save Coupon",
43
+ currencyCode: _
44
+ })]
45
+ });
45
46
  }
46
- export {
47
- N as EditCouponPage
48
- };
47
+ //#endregion
48
+ export { l as EditCouponPage };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),a=require("react"),p=require("@nextblock-cms/ui/button"),j=require("@nextblock-cms/ui/input"),y=require("lucide-react");function k(s){const r=s.sku?.trim();return r?r.toUpperCase():`PRODUCT:${s.id}`}function v(s){const r=new Map;for(const o of s){const c=k(o),i=r.get(c);if(i){i.productIds.push(o.id);continue}r.set(c,{key:c,title:o.title,sku:o.sku?.trim()||"No SKU",thumbnailUrl:o.thumbnailUrl??null,productIds:[o.id]})}return[...r.values()]}function S({products:s,selectedProductIds:r=[]}){const o=a.useMemo(()=>new Set(r),[r]),[c,i]=a.useState(o),[u,b]=a.useState(""),d=a.useMemo(()=>v(s),[s]),h=a.useMemo(()=>{const t=u.trim().toLowerCase();return t?d.filter(n=>[n.title,n.sku].some(l=>l.toLowerCase().includes(t))):d},[d,u]),x=t=>{i(new Set(s.filter(n=>n.payment_provider===t).map(n=>n.id)))};return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(p.Button,{type:"button",variant:"outline",size:"sm",onClick:()=>i(new Set(s.map(t=>t.id))),children:"Select All"}),e.jsx(p.Button,{type:"button",variant:"outline",size:"sm",onClick:()=>x("stripe"),children:"Stripe"}),e.jsx(p.Button,{type:"button",variant:"outline",size:"sm",onClick:()=>x("freemius"),children:"Freemius"})]}),e.jsxs("div",{className:"relative",children:[e.jsx(y.Search,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(j.Input,{type:"search",value:u,onChange:t=>b(t.target.value),placeholder:"Search products by title or SKU",className:"pl-9"})]}),e.jsxs("div",{className:"grid max-h-[420px] gap-2 overflow-y-auto rounded-lg border p-3 md:grid-cols-2",children:[h.map(t=>{const n=t.productIds.some(l=>c.has(l));return e.jsxs("label",{className:"flex cursor-pointer items-center gap-3 rounded-md px-2 py-2 hover:bg-muted/40",children:[e.jsx("input",{type:"checkbox",checked:n,onChange:l=>{const m=new Set(c);for(const f of t.productIds)l.target.checked?m.add(f):m.delete(f);i(m)},className:"mt-0.5 h-4 w-4 rounded border-slate-300 text-primary focus:ring-primary"}),n?t.productIds.map(l=>e.jsx("input",{type:"hidden",name:"product_ids",value:l},l)):null,e.jsx("span",{className:"flex h-12 w-12 shrink-0 items-center justify-center overflow-hidden rounded-md border bg-muted",children:t.thumbnailUrl?e.jsx("img",{src:t.thumbnailUrl,alt:"",loading:"lazy",className:"h-full w-full object-cover"}):e.jsx(y.ImageIcon,{className:"h-5 w-5 text-muted-foreground","aria-hidden":"true"})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block whitespace-normal break-words text-sm font-medium",children:t.title}),e.jsx("span",{className:"block font-mono text-xs text-muted-foreground",children:t.sku})]})]},t.key)}),h.length===0?e.jsx("div",{className:"px-2 py-8 text-center text-sm text-muted-foreground md:col-span-2",children:"No matching products."}):null]})]})}exports.ProductScopePicker=S;
1
+ "use client";let e=require("@nextblock-cms/ui/button"),t=require("react"),n=require("lucide-react"),r=require("react/jsx-runtime"),i=require("@nextblock-cms/ui/input");function a(e){let t=e.sku?.trim();return t?t.toUpperCase():`PRODUCT:${e.id}`}function o(e){let t=new Map;for(let n of e){let e=a(n),r=t.get(e);if(r){r.productIds.push(n.id);continue}t.set(e,{key:e,title:n.title,sku:n.sku?.trim()||`No SKU`,thumbnailUrl:n.thumbnailUrl??null,productIds:[n.id]})}return[...t.values()]}function s({products:a,selectedProductIds:s=[]}){let c=(0,t.useMemo)(()=>new Set(s),[s]),[l,u]=(0,t.useState)(c),[d,f]=(0,t.useState)(``),p=(0,t.useMemo)(()=>o(a),[a]),m=(0,t.useMemo)(()=>{let e=d.trim().toLowerCase();return e?p.filter(t=>[t.title,t.sku].some(t=>t.toLowerCase().includes(e))):p},[p,d]),h=e=>{u(new Set(a.filter(t=>t.payment_provider===e).map(e=>e.id)))};return(0,r.jsxs)(`div`,{className:`space-y-3`,children:[(0,r.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,r.jsx)(e.Button,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>u(new Set(a.map(e=>e.id))),children:`Select All`}),(0,r.jsx)(e.Button,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>h(`stripe`),children:`Stripe`}),(0,r.jsx)(e.Button,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>h(`freemius`),children:`Freemius`})]}),(0,r.jsxs)(`div`,{className:`relative`,children:[(0,r.jsx)(n.Search,{className:`pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`}),(0,r.jsx)(i.Input,{type:`search`,value:d,onChange:e=>f(e.target.value),placeholder:`Search products by title or SKU`,className:`pl-9`})]}),(0,r.jsxs)(`div`,{className:`grid max-h-[420px] gap-2 overflow-y-auto rounded-lg border p-3 md:grid-cols-2`,children:[m.map(e=>{let t=e.productIds.some(e=>l.has(e));return(0,r.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-3 rounded-md px-2 py-2 hover:bg-muted/40`,children:[(0,r.jsx)(`input`,{type:`checkbox`,checked:t,onChange:t=>{let n=new Set(l);for(let r of e.productIds)t.target.checked?n.add(r):n.delete(r);u(n)},className:`mt-0.5 h-4 w-4 rounded border-slate-300 text-primary focus:ring-primary`}),t?e.productIds.map(e=>(0,r.jsx)(`input`,{type:`hidden`,name:`product_ids`,value:e},e)):null,(0,r.jsx)(`span`,{className:`flex h-12 w-12 shrink-0 items-center justify-center overflow-hidden rounded-md border bg-muted`,children:e.thumbnailUrl?(0,r.jsx)(`img`,{src:e.thumbnailUrl,alt:``,loading:`lazy`,className:`h-full w-full object-cover`}):(0,r.jsx)(n.ImageIcon,{className:`h-5 w-5 text-muted-foreground`,"aria-hidden":`true`})}),(0,r.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,r.jsx)(`span`,{className:`block whitespace-normal break-words text-sm font-medium`,children:e.title}),(0,r.jsx)(`span`,{className:`block font-mono text-xs text-muted-foreground`,children:e.sku})]})]},e.key)}),m.length===0?(0,r.jsx)(`div`,{className:`px-2 py-8 text-center text-sm text-muted-foreground md:col-span-2`,children:`No matching products.`}):null]})]})}exports.ProductScopePicker=s;
@@ -13,4 +13,4 @@ export type CouponProductOption = {
13
13
  export declare function ProductScopePicker({ products, selectedProductIds, }: {
14
14
  products: CouponProductOption[];
15
15
  selectedProductIds?: string[];
16
- }): import("react").JSX.Element;
16
+ }): import('react').JSX.Element;
@@ -1,120 +1,131 @@
1
- 'use client';
2
- import { jsxs as c, jsx as t } from "react/jsx-runtime";
3
- import { useMemo as p, useState as b } from "react";
4
- import { Button as h } from "@nextblock-cms/ui/button";
5
- import { Input as v } from "@nextblock-cms/ui/input";
6
- import { Search as w, ImageIcon as g } from "lucide-react";
7
- function N(r) {
8
- const s = r.sku?.trim();
9
- return s ? s.toUpperCase() : `PRODUCT:${r.id}`;
1
+ "use client";
2
+ import { Button as e } from "@nextblock-cms/ui/button";
3
+ import { useMemo as t, useState as n } from "react";
4
+ import { ImageIcon as r, Search as i } from "lucide-react";
5
+ import { jsx as a, jsxs as o } from "react/jsx-runtime";
6
+ import { Input as s } from "@nextblock-cms/ui/input";
7
+ //#region libs/ecommerce/src/lib/pages/cms/coupons/ProductScopePicker.tsx
8
+ function c(e) {
9
+ let t = e.sku?.trim();
10
+ return t ? t.toUpperCase() : `PRODUCT:${e.id}`;
10
11
  }
11
- function S(r) {
12
- const s = /* @__PURE__ */ new Map();
13
- for (const o of r) {
14
- const a = N(o), i = s.get(a);
15
- if (i) {
16
- i.productIds.push(o.id);
17
- continue;
18
- }
19
- s.set(a, {
20
- key: a,
21
- title: o.title,
22
- sku: o.sku?.trim() || "No SKU",
23
- thumbnailUrl: o.thumbnailUrl ?? null,
24
- productIds: [o.id]
25
- });
26
- }
27
- return [...s.values()];
12
+ function l(e) {
13
+ let t = /* @__PURE__ */ new Map();
14
+ for (let n of e) {
15
+ let e = c(n), r = t.get(e);
16
+ if (r) {
17
+ r.productIds.push(n.id);
18
+ continue;
19
+ }
20
+ t.set(e, {
21
+ key: e,
22
+ title: n.title,
23
+ sku: n.sku?.trim() || "No SKU",
24
+ thumbnailUrl: n.thumbnailUrl ?? null,
25
+ productIds: [n.id]
26
+ });
27
+ }
28
+ return [...t.values()];
28
29
  }
29
- function P({
30
- products: r,
31
- selectedProductIds: s = []
32
- }) {
33
- const o = p(() => new Set(s), [s]), [a, i] = b(o), [d, k] = b(""), u = p(() => S(r), [r]), f = p(() => {
34
- const e = d.trim().toLowerCase();
35
- return e ? u.filter(
36
- (n) => [n.title, n.sku].some((l) => l.toLowerCase().includes(e))
37
- ) : u;
38
- }, [u, d]), x = (e) => {
39
- i(
40
- new Set(
41
- r.filter((n) => n.payment_provider === e).map((n) => n.id)
42
- )
43
- );
44
- };
45
- return /* @__PURE__ */ c("div", { className: "space-y-3", children: [
46
- /* @__PURE__ */ c("div", { className: "flex flex-wrap items-center gap-2", children: [
47
- /* @__PURE__ */ t(
48
- h,
49
- {
50
- type: "button",
51
- variant: "outline",
52
- size: "sm",
53
- onClick: () => i(new Set(r.map((e) => e.id))),
54
- children: "Select All"
55
- }
56
- ),
57
- /* @__PURE__ */ t(h, { type: "button", variant: "outline", size: "sm", onClick: () => x("stripe"), children: "Stripe" }),
58
- /* @__PURE__ */ t(h, { type: "button", variant: "outline", size: "sm", onClick: () => x("freemius"), children: "Freemius" })
59
- ] }),
60
- /* @__PURE__ */ c("div", { className: "relative", children: [
61
- /* @__PURE__ */ t(w, { className: "pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" }),
62
- /* @__PURE__ */ t(
63
- v,
64
- {
65
- type: "search",
66
- value: d,
67
- onChange: (e) => k(e.target.value),
68
- placeholder: "Search products by title or SKU",
69
- className: "pl-9"
70
- }
71
- )
72
- ] }),
73
- /* @__PURE__ */ c("div", { className: "grid max-h-[420px] gap-2 overflow-y-auto rounded-lg border p-3 md:grid-cols-2", children: [
74
- f.map((e) => {
75
- const n = e.productIds.some((l) => a.has(l));
76
- return /* @__PURE__ */ c(
77
- "label",
78
- {
79
- className: "flex cursor-pointer items-center gap-3 rounded-md px-2 py-2 hover:bg-muted/40",
80
- children: [
81
- /* @__PURE__ */ t(
82
- "input",
83
- {
84
- type: "checkbox",
85
- checked: n,
86
- onChange: (l) => {
87
- const m = new Set(a);
88
- for (const y of e.productIds)
89
- l.target.checked ? m.add(y) : m.delete(y);
90
- i(m);
91
- },
92
- className: "mt-0.5 h-4 w-4 rounded border-slate-300 text-primary focus:ring-primary"
93
- }
94
- ),
95
- n ? e.productIds.map((l) => /* @__PURE__ */ t("input", { type: "hidden", name: "product_ids", value: l }, l)) : null,
96
- /* @__PURE__ */ t("span", { className: "flex h-12 w-12 shrink-0 items-center justify-center overflow-hidden rounded-md border bg-muted", children: e.thumbnailUrl ? /* @__PURE__ */ t(
97
- "img",
98
- {
99
- src: e.thumbnailUrl,
100
- alt: "",
101
- loading: "lazy",
102
- className: "h-full w-full object-cover"
103
- }
104
- ) : /* @__PURE__ */ t(g, { className: "h-5 w-5 text-muted-foreground", "aria-hidden": "true" }) }),
105
- /* @__PURE__ */ c("span", { className: "min-w-0 flex-1", children: [
106
- /* @__PURE__ */ t("span", { className: "block whitespace-normal break-words text-sm font-medium", children: e.title }),
107
- /* @__PURE__ */ t("span", { className: "block font-mono text-xs text-muted-foreground", children: e.sku })
108
- ] })
109
- ]
110
- },
111
- e.key
112
- );
113
- }),
114
- f.length === 0 ? /* @__PURE__ */ t("div", { className: "px-2 py-8 text-center text-sm text-muted-foreground md:col-span-2", children: "No matching products." }) : null
115
- ] })
116
- ] });
30
+ function u({ products: c, selectedProductIds: u = [] }) {
31
+ let d = t(() => new Set(u), [u]), [f, p] = n(d), [m, h] = n(""), g = t(() => l(c), [c]), _ = t(() => {
32
+ let e = m.trim().toLowerCase();
33
+ return e ? g.filter((t) => [t.title, t.sku].some((t) => t.toLowerCase().includes(e))) : g;
34
+ }, [g, m]), v = (e) => {
35
+ p(new Set(c.filter((t) => t.payment_provider === e).map((e) => e.id)));
36
+ };
37
+ return /* @__PURE__ */ o("div", {
38
+ className: "space-y-3",
39
+ children: [
40
+ /* @__PURE__ */ o("div", {
41
+ className: "flex flex-wrap items-center gap-2",
42
+ children: [
43
+ /* @__PURE__ */ a(e, {
44
+ type: "button",
45
+ variant: "outline",
46
+ size: "sm",
47
+ onClick: () => p(new Set(c.map((e) => e.id))),
48
+ children: "Select All"
49
+ }),
50
+ /* @__PURE__ */ a(e, {
51
+ type: "button",
52
+ variant: "outline",
53
+ size: "sm",
54
+ onClick: () => v("stripe"),
55
+ children: "Stripe"
56
+ }),
57
+ /* @__PURE__ */ a(e, {
58
+ type: "button",
59
+ variant: "outline",
60
+ size: "sm",
61
+ onClick: () => v("freemius"),
62
+ children: "Freemius"
63
+ })
64
+ ]
65
+ }),
66
+ /* @__PURE__ */ o("div", {
67
+ className: "relative",
68
+ children: [/* @__PURE__ */ a(i, { className: "pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" }), /* @__PURE__ */ a(s, {
69
+ type: "search",
70
+ value: m,
71
+ onChange: (e) => h(e.target.value),
72
+ placeholder: "Search products by title or SKU",
73
+ className: "pl-9"
74
+ })]
75
+ }),
76
+ /* @__PURE__ */ o("div", {
77
+ className: "grid max-h-[420px] gap-2 overflow-y-auto rounded-lg border p-3 md:grid-cols-2",
78
+ children: [_.map((e) => {
79
+ let t = e.productIds.some((e) => f.has(e));
80
+ return /* @__PURE__ */ o("label", {
81
+ className: "flex cursor-pointer items-center gap-3 rounded-md px-2 py-2 hover:bg-muted/40",
82
+ children: [
83
+ /* @__PURE__ */ a("input", {
84
+ type: "checkbox",
85
+ checked: t,
86
+ onChange: (t) => {
87
+ let n = new Set(f);
88
+ for (let r of e.productIds) t.target.checked ? n.add(r) : n.delete(r);
89
+ p(n);
90
+ },
91
+ className: "mt-0.5 h-4 w-4 rounded border-slate-300 text-primary focus:ring-primary"
92
+ }),
93
+ t ? e.productIds.map((e) => /* @__PURE__ */ a("input", {
94
+ type: "hidden",
95
+ name: "product_ids",
96
+ value: e
97
+ }, e)) : null,
98
+ /* @__PURE__ */ a("span", {
99
+ className: "flex h-12 w-12 shrink-0 items-center justify-center overflow-hidden rounded-md border bg-muted",
100
+ children: e.thumbnailUrl ? /* @__PURE__ */ a("img", {
101
+ src: e.thumbnailUrl,
102
+ alt: "",
103
+ loading: "lazy",
104
+ className: "h-full w-full object-cover"
105
+ }) : /* @__PURE__ */ a(r, {
106
+ className: "h-5 w-5 text-muted-foreground",
107
+ "aria-hidden": "true"
108
+ })
109
+ }),
110
+ /* @__PURE__ */ o("span", {
111
+ className: "min-w-0 flex-1",
112
+ children: [/* @__PURE__ */ a("span", {
113
+ className: "block whitespace-normal break-words text-sm font-medium",
114
+ children: e.title
115
+ }), /* @__PURE__ */ a("span", {
116
+ className: "block font-mono text-xs text-muted-foreground",
117
+ children: e.sku
118
+ })]
119
+ })
120
+ ]
121
+ }, e.key);
122
+ }), _.length === 0 ? /* @__PURE__ */ a("div", {
123
+ className: "px-2 py-8 text-center text-sm text-muted-foreground md:col-span-2",
124
+ children: "No matching products."
125
+ }) : null]
126
+ })
127
+ ]
128
+ });
117
129
  }
118
- export {
119
- P as ProductScopePicker
120
- };
130
+ //#endregion
131
+ export { u as ProductScopePicker };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@nextblock-cms/db/server"),w=require("@nextblock-cms/utils"),c=require("next/cache"),g=require("next/navigation"),C=require("../../../coupons.cjs.js"),s=require("../../../freemius-coupons.cjs.js");async function u(){const e=l.createClient(),{data:{user:o}}=await e.auth.getUser();if(!o)throw new Error("Unauthorized");const{data:t}=await e.from("profiles").select("role").eq("id",o.id).single();if(t?.role!=="ADMIN")throw new Error("Forbidden");return l.getServiceRoleSupabaseClient()}function i(e){return(typeof e=="string"?e.trim():"")||null}function m(e){const o=i(e);if(!o)return null;const t=new Date(o);return Number.isNaN(t.getTime())?null:t.toISOString()}function h(e){const o=i(e.value),t=o?Number.parseFloat(o):Number.NaN;if(!Number.isFinite(t)||t<=0)throw new Error("Discount amount must be greater than zero.");return e.discountType==="fixed"?w.majorUnitAmountToMinor(t,e.currencyCode):Math.round(t)}function v(e,o){return e.getAll(o).some(t=>t==="true")}function f(e){const o=C.normalizeCouponCode(i(e.get("code"))),t=i(e.get("name")),n=i(e.get("provider_scope"))||"all",r=i(e.get("discount_type"))||"percent",y=w.normalizeCurrencyCode(i(e.get("currency_code"))),a=h({value:e.get("discount_amount"),discountType:r,currencyCode:y}),d=i(e.get("redemption_limit"));if(!o)throw new Error("Coupon code is required.");if(!t)throw new Error("Coupon name is required.");if(r==="percent"&&a>100)throw new Error("Percent discounts cannot exceed 100.");return{coupon:{code:o,name:t,internal_note:i(e.get("internal_note")),provider_scope:n,discount_type:r,discount_amount:a,is_active:v(e,"is_active"),starts_at:m(e.get("starts_at")),ends_at:m(e.get("ends_at")),redemption_limit:d?Number.parseInt(d,10):null,freemius_sync_status:n==="stripe"?"not_required":"pending",freemius_sync_error:null},productIds:e.getAll("product_ids").map(p=>typeof p=="string"?p.trim():"").filter(Boolean)}}async function _(e){if(await e.client.from("coupon_products").delete().eq("coupon_id",e.couponId),e.productIds.length===0)return;const{error:o}=await e.client.from("coupon_products").insert(e.productIds.map(t=>({coupon_id:e.couponId,product_id:t})));if(o)throw new Error(o.message)}async function A(e){const o=await u(),t=f(e),{data:n,error:r}=await o.from("coupons").insert(t.coupon).select("id").single();if(r||!n)throw new Error(r?.message||"Failed to create coupon.");await _({client:o,couponId:n.id,productIds:t.productIds}),await s.syncCouponToFreemius({couponId:n.id,client:o}),c.revalidatePath("/cms/coupons"),g.redirect("/cms/coupons")}async function q(e,o){const t=await u(),n=f(o),{error:r}=await t.from("coupons").update(n.coupon).eq("id",e);if(r)throw new Error(r.message);await _({client:t,couponId:e,productIds:n.productIds}),n.coupon.provider_scope==="stripe"?await s.deleteCouponFromFreemius({couponId:e,client:t}):await s.syncCouponToFreemius({couponId:e,client:t}),c.revalidatePath("/cms/coupons"),c.revalidatePath(`/cms/coupons/${e}/edit`),g.redirect("/cms/coupons")}async function b(e,o){const t=await u(),{error:n}=await t.from("coupons").update({is_active:o,freemius_sync_status:"pending",updated_at:new Date().toISOString()}).eq("id",e);if(n)throw new Error(n.message);await s.syncCouponToFreemius({couponId:e,client:t}),c.revalidatePath("/cms/coupons")}async function F(e){const o=await u();await s.syncCouponToFreemius({couponId:e,client:o}),c.revalidatePath("/cms/coupons"),c.revalidatePath(`/cms/coupons/${e}/edit`)}async function E(e){const o=await u();await s.deleteCouponFromFreemius({couponId:e,client:o});const{error:t}=await o.from("coupons").delete().eq("id",e);if(t)throw new Error(t.message);c.revalidatePath("/cms/coupons")}exports.createCouponAction=A;exports.deleteCouponAction=E;exports.syncCouponAction=F;exports.toggleCouponActiveAction=b;exports.updateCouponAction=q;
1
+ "use server";const e=require("../../../coupons.cjs.js"),t=require("../../../freemius-coupons.cjs.js");let n=require("@nextblock-cms/utils"),r=require("@nextblock-cms/db/server"),i=require("next/navigation"),a=require("next/cache");async function o(){let e=(0,r.createClient)(),{data:{user:t}}=await e.auth.getUser();if(!t)throw Error(`Unauthorized`);let{data:n}=await e.from(`profiles`).select(`role`).eq(`id`,t.id).single();if(n?.role!==`ADMIN`)throw Error(`Forbidden`);return(0,r.getServiceRoleSupabaseClient)()}function s(e){return(typeof e==`string`?e.trim():``)||null}function c(e){let t=s(e);if(!t)return null;let n=new Date(t);return Number.isNaN(n.getTime())?null:n.toISOString()}function l(e){let t=s(e.value),r=t?Number.parseFloat(t):NaN;if(!Number.isFinite(r)||r<=0)throw Error(`Discount amount must be greater than zero.`);return e.discountType===`fixed`?(0,n.majorUnitAmountToMinor)(r,e.currencyCode):Math.round(r)}function u(e,t){return e.getAll(t).some(e=>e===`true`)}function d(t){let r=e.normalizeCouponCode(s(t.get(`code`))),i=s(t.get(`name`)),a=s(t.get(`provider_scope`))||`all`,o=s(t.get(`discount_type`))||`percent`,d=(0,n.normalizeCurrencyCode)(s(t.get(`currency_code`))),f=l({value:t.get(`discount_amount`),discountType:o,currencyCode:d}),p=s(t.get(`redemption_limit`));if(!r)throw Error(`Coupon code is required.`);if(!i)throw Error(`Coupon name is required.`);if(o===`percent`&&f>100)throw Error(`Percent discounts cannot exceed 100.`);return{coupon:{code:r,name:i,internal_note:s(t.get(`internal_note`)),provider_scope:a,discount_type:o,discount_amount:f,is_active:u(t,`is_active`),starts_at:c(t.get(`starts_at`)),ends_at:c(t.get(`ends_at`)),redemption_limit:p?Number.parseInt(p,10):null,freemius_sync_status:a===`stripe`?`not_required`:`pending`,freemius_sync_error:null},productIds:t.getAll(`product_ids`).map(e=>typeof e==`string`?e.trim():``).filter(Boolean)}}async function f(e){if(await e.client.from(`coupon_products`).delete().eq(`coupon_id`,e.couponId),e.productIds.length===0)return;let{error:t}=await e.client.from(`coupon_products`).insert(e.productIds.map(t=>({coupon_id:e.couponId,product_id:t})));if(t)throw Error(t.message)}async function p(e){let n=await o(),r=d(e),{data:s,error:c}=await n.from(`coupons`).insert(r.coupon).select(`id`).single();if(c||!s)throw Error(c?.message||`Failed to create coupon.`);await f({client:n,couponId:s.id,productIds:r.productIds}),await t.syncCouponToFreemius({couponId:s.id,client:n}),(0,a.revalidatePath)(`/cms/coupons`),(0,i.redirect)(`/cms/coupons`)}async function m(e,n){let r=await o(),s=d(n),{error:c}=await r.from(`coupons`).update(s.coupon).eq(`id`,e);if(c)throw Error(c.message);await f({client:r,couponId:e,productIds:s.productIds}),s.coupon.provider_scope===`stripe`?await t.deleteCouponFromFreemius({couponId:e,client:r}):await t.syncCouponToFreemius({couponId:e,client:r}),(0,a.revalidatePath)(`/cms/coupons`),(0,a.revalidatePath)(`/cms/coupons/${e}/edit`),(0,i.redirect)(`/cms/coupons`)}async function h(e,n){let r=await o(),{error:i}=await r.from(`coupons`).update({is_active:n,freemius_sync_status:`pending`,updated_at:new Date().toISOString()}).eq(`id`,e);if(i)throw Error(i.message);await t.syncCouponToFreemius({couponId:e,client:r}),(0,a.revalidatePath)(`/cms/coupons`)}async function g(e){let n=await o();await t.syncCouponToFreemius({couponId:e,client:n}),(0,a.revalidatePath)(`/cms/coupons`),(0,a.revalidatePath)(`/cms/coupons/${e}/edit`)}async function _(e){let n=await o();await t.deleteCouponFromFreemius({couponId:e,client:n});let{error:r}=await n.from(`coupons`).delete().eq(`id`,e);if(r)throw Error(r.message);(0,a.revalidatePath)(`/cms/coupons`)}exports.createCouponAction=p,exports.deleteCouponAction=_,exports.syncCouponAction=g,exports.toggleCouponActiveAction=h,exports.updateCouponAction=m;