@nextblock-cms/ecom 0.20.3 → 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 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("@nextblock-cms/db/server"),l=require("../../../product-actions.cjs.js"),h=require("../../../freemius-coupons.cjs.js"),g=require("../../../currency.cjs.js"),_=require("./product-price-sync.cjs.js"),a=require("next/cache"),v=require("next/navigation");function u(e){return e.toLowerCase().trim().replace(/\s+/g,"-").replace(/[^a-z0-9-]/g,"").replace(/-+/g,"-").replace(/^-|-$/g,"")}async function w(e){const t=i.createClient(),{data:r}=await t.from("currencies").select("code, symbol, exchange_rate, is_default, is_active, auto_sync_product_prices, auto_update_exchange_rate, exchange_rate_source, exchange_rate_updated_at, rounding_mode, rounding_increment, rounding_charm_amount").eq("is_active",!0).order("code",{ascending:!0}),s=_.sanitizeProductFormValuesForStoreManagedCurrencies(e,(r||[]).map(o=>g.normalizeCurrencyRecord(o))),c=await l.createProduct(t,s);if(s.payment_provider==="freemius"&&c?.id)try{await h.syncProductSaleCouponToFreemius({productId:c.id,client:i.getServiceRoleSupabaseClient()})}catch(o){console.error("Failed to sync Freemius sale coupon on create:",o)}a.revalidatePath("/cms/products"),v.redirect("/cms/products")}async function y(e,t,r,s){const c={author_id:r,meta:s,updated_at:new Date().toISOString()},o=async()=>{const{error:f}=await e.from("product_drafts").update(c).eq("product_id",t);if(f)throw new Error(`Failed to save product draft: ${f.message}`)},{data:n,error:m}=await e.from("product_drafts").select("id").eq("product_id",t).maybeSingle();if(m)throw new Error(`Failed to read product draft: ${m.message}`);if(n){await o();return}const{data:P,error:p}=await e.from("blocks").select("id, page_id, post_id, product_id, language_id, block_type, content, order, created_at, updated_at").eq("product_id",t).order("order",{ascending:!0});if(p)throw new Error(`Failed to read product blocks: ${p.message}`);const{error:d}=await e.from("product_drafts").insert({...c,blocks:P??[],product_id:t});if(d){if(d.code==="23505"){await o();return}throw new Error(`Failed to save product draft: ${d.message}`)}}async function A(e,t){const r=i.createClient(),{data:{user:s}}=await r.auth.getUser();if(!s)throw new Error("User not authenticated.");const{data:c}=await r.from("currencies").select("code, symbol, exchange_rate, is_default, is_active, auto_sync_product_prices, auto_update_exchange_rate, exchange_rate_source, exchange_rate_updated_at, rounding_mode, rounding_increment, rounding_charm_amount").eq("is_active",!0).order("code",{ascending:!0}),o=_.sanitizeProductFormValuesForStoreManagedCurrencies(t,(c||[]).map(n=>g.normalizeCurrencyRecord(n)));return await y(r,e,s.id,o),{success:!0}}async function S(e){const t=i.createClient();await l.deleteProduct(t,e),a.revalidatePath("/cms/products")}function b(e){return Array.from(new Set(e.map(t=>t.trim()).filter(Boolean)))}async function C(e){const t=b(e);if(t.length===0)return{success:!1,error:"Select at least one product."};const r=i.createClient(),{error:s}=await r.from("products").delete().in("id",t);return s?{success:!1,error:s.message}:(a.revalidatePath("/cms/products"),{success:!0,count:t.length})}async function q(e){const t=b(e);if(t.length===0)return{success:!1,error:"Select at least one product."};const r=i.createClient(),{error:s}=await r.from("products").update({status:"draft",updated_at:new Date().toISOString()}).in("id",t);return s?{success:!1,error:s.message}:(a.revalidatePath("/cms/products"),{success:!0,count:t.length})}async function T(e){const t=String(e||"").trim();if(!t)return{error:"Missing product id."};const r=i.createClient(),{data:{user:s}}=await r.auth.getUser();if(!s)return{error:"You must be signed in to publish a product."};const{data:c,error:o}=await r.from("products").update({status:"active",updated_at:new Date().toISOString()}).eq("id",t).select("slug").single();return o||!c?{error:o?.message||"Could not publish the product."}:(a.revalidatePath("/cms/products"),a.revalidatePath(`/cms/products/${t}/edit`),c.slug&&a.revalidatePath(`/product/${c.slug}`),{})}async function D(e){const t=i.getServiceRoleSupabaseClient(),r=e.name.trim(),s=u(e.slug?.trim()||e.name);if(!r||!s)return{success:!1,error:"Attribute name is required."};const{error:c}=await t.from("product_attributes").insert({name:r,slug:s});return c?{success:!1,error:c.message}:(a.revalidatePath("/cms/products/attributes"),a.revalidatePath("/cms/products/new"),a.revalidatePath("/cms/products"),{success:!0})}async function x(e){const t=i.getServiceRoleSupabaseClient(),{error:r}=await t.from("product_attributes").delete().eq("id",e);return r?{success:!1,error:r.message}:(a.revalidatePath("/cms/products/attributes"),a.revalidatePath("/cms/products/new"),a.revalidatePath("/cms/products"),{success:!0})}async function R(e){const t=i.getServiceRoleSupabaseClient(),r=e.value.trim(),s=u(e.slug?.trim()||e.value);if(!r||!s)return{success:!1,error:"Term value is required."};const{data:c}=await t.from("product_attribute_terms").select("sort_order").eq("attribute_id",e.attributeId).order("sort_order",{ascending:!1}).limit(1),o=typeof c?.[0]?.sort_order=="number"?c[0].sort_order+1:0,{error:n}=await t.from("product_attribute_terms").insert({attribute_id:e.attributeId,value:r,slug:s,sort_order:o});return n?{success:!1,error:n.message}:(a.revalidatePath("/cms/products/attributes"),a.revalidatePath("/cms/products/new"),a.revalidatePath("/cms/products"),{success:!0})}async function F(e){const t=i.getServiceRoleSupabaseClient();for(const[r,s]of e.orderedTermIds.entries()){const{error:c}=await t.from("product_attribute_terms").update({sort_order:r,updated_at:new Date().toISOString()}).eq("id",s).eq("attribute_id",e.attributeId);if(c)return{success:!1,error:c.message}}return a.revalidatePath("/cms/products/attributes"),a.revalidatePath("/cms/products/new"),a.revalidatePath("/cms/products"),{success:!0}}async function I(e){const t=i.getServiceRoleSupabaseClient(),{error:r}=await t.from("product_attributes").update({name_translations:e.nameTranslations,updated_at:new Date().toISOString()}).eq("id",e.attributeId);if(r)return{success:!1,error:r.message};for(const s of e.termTranslations){const{error:c}=await t.from("product_attribute_terms").update({value_translations:s.valueTranslations,updated_at:new Date().toISOString()}).eq("id",s.termId).eq("attribute_id",e.attributeId);if(c)return{success:!1,error:c.message}}return a.revalidatePath("/cms/products/attributes"),a.revalidatePath("/cms/products/new"),a.revalidatePath("/cms/products"),{success:!0}}async function E(e){const t=i.getServiceRoleSupabaseClient(),{error:r}=await t.from("product_attribute_terms").delete().eq("id",e);return r?{success:!1,error:r.message}:(a.revalidatePath("/cms/products/attributes"),a.revalidatePath("/cms/products/new"),a.revalidatePath("/cms/products"),{success:!0})}async function k(e){const t=i.getServiceRoleSupabaseClient(),r=e.name.trim(),s=u(e.slug?.trim()||e.name);if(!r||!s)return{success:!1,error:"Category name is required."};const{data:c,error:o}=await t.from("categories").insert({name:r,slug:s,description:e.description?.trim()||null,name_translations:e.nameTranslations||{},description_translations:e.descriptionTranslations||{}}).select().single();return o?{success:!1,error:o.message}:(a.revalidatePath("/cms/products/categories"),a.revalidatePath("/cms/products/new"),a.revalidatePath("/cms/products"),{success:!0,category:c})}async function z(e,t){const r=i.getServiceRoleSupabaseClient(),s=t.name.trim(),c=u(t.slug?.trim()||t.name);if(!s||!c)return{success:!1,error:"Category name is required."};const{error:o}=await r.from("categories").update({name:s,slug:c,description:t.description?.trim()||null,name_translations:t.nameTranslations||{},description_translations:t.descriptionTranslations||{}}).eq("id",e);return o?{success:!1,error:o.message}:(a.revalidatePath("/cms/products/categories"),a.revalidatePath("/cms/products/new"),a.revalidatePath("/cms/products"),{success:!0})}async function O(e){const t=i.getServiceRoleSupabaseClient(),{error:r}=await t.from("categories").delete().eq("id",e);return r?{success:!1,error:r.message}:(a.revalidatePath("/cms/products/categories"),a.revalidatePath("/cms/products/new"),a.revalidatePath("/cms/products"),{success:!0})}async function $(e,t){const r=i.getServiceRoleSupabaseClient();try{return await l.syncCategoriesForTranslationGroup(r,e,t),a.revalidatePath("/cms/products"),a.revalidatePath(`/cms/products/${e}/edit`),{success:!0}}catch(s){return{success:!1,error:s.message}}}exports.bulkDeleteProductsAction=C;exports.bulkDraftProductsAction=q;exports.createCategoryAction=k;exports.createProductAction=w;exports.createProductAttributeAction=D;exports.createProductAttributeTermAction=R;exports.deleteCategoryAction=O;exports.deleteProductAction=S;exports.deleteProductAttributeAction=x;exports.deleteProductAttributeTermAction=E;exports.publishProductAction=T;exports.reorderProductAttributeTermsAction=F;exports.syncProductCategoriesAction=$;exports.updateCategoryAction=z;exports.updateProductAction=A;exports.updateProductAttributeTranslationsAction=I;
1
+ "use server";const e=require("../../../currency.cjs.js"),t=require("../../../product-actions.cjs.js"),n=require("./product-price-sync.cjs.js"),r=require("../../../freemius-coupons.cjs.js");let i=require("@nextblock-cms/db/server"),a=require("next/navigation"),o=require("next/cache");function s(e){return e.toLowerCase().trim().replace(/\s+/g,`-`).replace(/[^a-z0-9-]/g,``).replace(/-+/g,`-`).replace(/^-|-$/g,``)}async function c(s){let c=(0,i.createClient)(),{data:l}=await c.from(`currencies`).select(`code, symbol, exchange_rate, is_default, is_active, auto_sync_product_prices, auto_update_exchange_rate, exchange_rate_source, exchange_rate_updated_at, rounding_mode, rounding_increment, rounding_charm_amount`).eq(`is_active`,!0).order(`code`,{ascending:!0}),u=n.sanitizeProductFormValuesForStoreManagedCurrencies(s,(l||[]).map(t=>e.normalizeCurrencyRecord(t))),d=await t.createProduct(c,u);if(u.payment_provider===`freemius`&&d?.id)try{await r.syncProductSaleCouponToFreemius({productId:d.id,client:(0,i.getServiceRoleSupabaseClient)()})}catch(e){console.error(`Failed to sync Freemius sale coupon on create:`,e)}(0,o.revalidatePath)(`/cms/products`),(0,a.redirect)(`/cms/products`)}async function l(e,t,n,r){let i={author_id:n,meta:r,updated_at:new Date().toISOString()},a=async()=>{let{error:n}=await e.from(`product_drafts`).update(i).eq(`product_id`,t);if(n)throw Error(`Failed to save product draft: ${n.message}`)},{data:o,error:s}=await e.from(`product_drafts`).select(`id`).eq(`product_id`,t).maybeSingle();if(s)throw Error(`Failed to read product draft: ${s.message}`);if(o){await a();return}let{data:c,error:l}=await e.from(`blocks`).select(`id, page_id, post_id, product_id, language_id, block_type, content, order, created_at, updated_at`).eq(`product_id`,t).order(`order`,{ascending:!0});if(l)throw Error(`Failed to read product blocks: ${l.message}`);let{error:u}=await e.from(`product_drafts`).insert({...i,blocks:c??[],product_id:t});if(u){if(u.code===`23505`){await a();return}throw Error(`Failed to save product draft: ${u.message}`)}}async function u(t,r){let a=(0,i.createClient)(),{data:{user:o}}=await a.auth.getUser();if(!o)throw Error(`User not authenticated.`);let{data:s}=await a.from(`currencies`).select(`code, symbol, exchange_rate, is_default, is_active, auto_sync_product_prices, auto_update_exchange_rate, exchange_rate_source, exchange_rate_updated_at, rounding_mode, rounding_increment, rounding_charm_amount`).eq(`is_active`,!0).order(`code`,{ascending:!0}),c=n.sanitizeProductFormValuesForStoreManagedCurrencies(r,(s||[]).map(t=>e.normalizeCurrencyRecord(t)));return await l(a,t,o.id,c),{success:!0}}async function d(e){let n=(0,i.createClient)();await t.deleteProduct(n,e),(0,o.revalidatePath)(`/cms/products`)}function f(e){return Array.from(new Set(e.map(e=>e.trim()).filter(Boolean)))}async function p(e){let t=f(e);if(t.length===0)return{success:!1,error:`Select at least one product.`};let{error:n}=await(0,i.createClient)().from(`products`).delete().in(`id`,t);return n?{success:!1,error:n.message}:((0,o.revalidatePath)(`/cms/products`),{success:!0,count:t.length})}async function m(e){let t=f(e);if(t.length===0)return{success:!1,error:`Select at least one product.`};let{error:n}=await(0,i.createClient)().from(`products`).update({status:`draft`,updated_at:new Date().toISOString()}).in(`id`,t);return n?{success:!1,error:n.message}:((0,o.revalidatePath)(`/cms/products`),{success:!0,count:t.length})}async function h(e){let t=String(e||``).trim();if(!t)return{error:`Missing product id.`};let n=(0,i.createClient)(),{data:{user:r}}=await n.auth.getUser();if(!r)return{error:`You must be signed in to publish a product.`};let{data:a,error:s}=await n.from(`products`).update({status:`active`,updated_at:new Date().toISOString()}).eq(`id`,t).select(`slug`).single();return s||!a?{error:s?.message||`Could not publish the product.`}:((0,o.revalidatePath)(`/cms/products`),(0,o.revalidatePath)(`/cms/products/${t}/edit`),a.slug&&(0,o.revalidatePath)(`/product/${a.slug}`),{})}async function g(e){let t=(0,i.getServiceRoleSupabaseClient)(),n=e.name.trim(),r=s(e.slug?.trim()||e.name);if(!n||!r)return{success:!1,error:`Attribute name is required.`};let{error:a}=await t.from(`product_attributes`).insert({name:n,slug:r});return a?{success:!1,error:a.message}:((0,o.revalidatePath)(`/cms/products/attributes`),(0,o.revalidatePath)(`/cms/products/new`),(0,o.revalidatePath)(`/cms/products`),{success:!0})}async function _(e){let{error:t}=await(0,i.getServiceRoleSupabaseClient)().from(`product_attributes`).delete().eq(`id`,e);return t?{success:!1,error:t.message}:((0,o.revalidatePath)(`/cms/products/attributes`),(0,o.revalidatePath)(`/cms/products/new`),(0,o.revalidatePath)(`/cms/products`),{success:!0})}async function v(e){let t=(0,i.getServiceRoleSupabaseClient)(),n=e.value.trim(),r=s(e.slug?.trim()||e.value);if(!n||!r)return{success:!1,error:`Term value is required.`};let{data:a}=await t.from(`product_attribute_terms`).select(`sort_order`).eq(`attribute_id`,e.attributeId).order(`sort_order`,{ascending:!1}).limit(1),c=typeof a?.[0]?.sort_order==`number`?a[0].sort_order+1:0,{error:l}=await t.from(`product_attribute_terms`).insert({attribute_id:e.attributeId,value:n,slug:r,sort_order:c});return l?{success:!1,error:l.message}:((0,o.revalidatePath)(`/cms/products/attributes`),(0,o.revalidatePath)(`/cms/products/new`),(0,o.revalidatePath)(`/cms/products`),{success:!0})}async function y(e){let t=(0,i.getServiceRoleSupabaseClient)();for(let[n,r]of e.orderedTermIds.entries()){let{error:i}=await t.from(`product_attribute_terms`).update({sort_order:n,updated_at:new Date().toISOString()}).eq(`id`,r).eq(`attribute_id`,e.attributeId);if(i)return{success:!1,error:i.message}}return(0,o.revalidatePath)(`/cms/products/attributes`),(0,o.revalidatePath)(`/cms/products/new`),(0,o.revalidatePath)(`/cms/products`),{success:!0}}async function b(e){let t=(0,i.getServiceRoleSupabaseClient)(),{error:n}=await t.from(`product_attributes`).update({name_translations:e.nameTranslations,updated_at:new Date().toISOString()}).eq(`id`,e.attributeId);if(n)return{success:!1,error:n.message};for(let n of e.termTranslations){let{error:r}=await t.from(`product_attribute_terms`).update({value_translations:n.valueTranslations,updated_at:new Date().toISOString()}).eq(`id`,n.termId).eq(`attribute_id`,e.attributeId);if(r)return{success:!1,error:r.message}}return(0,o.revalidatePath)(`/cms/products/attributes`),(0,o.revalidatePath)(`/cms/products/new`),(0,o.revalidatePath)(`/cms/products`),{success:!0}}async function x(e){let{error:t}=await(0,i.getServiceRoleSupabaseClient)().from(`product_attribute_terms`).delete().eq(`id`,e);return t?{success:!1,error:t.message}:((0,o.revalidatePath)(`/cms/products/attributes`),(0,o.revalidatePath)(`/cms/products/new`),(0,o.revalidatePath)(`/cms/products`),{success:!0})}async function S(e){let t=(0,i.getServiceRoleSupabaseClient)(),n=e.name.trim(),r=s(e.slug?.trim()||e.name);if(!n||!r)return{success:!1,error:`Category name is required.`};let{data:a,error:c}=await t.from(`categories`).insert({name:n,slug:r,description:e.description?.trim()||null,name_translations:e.nameTranslations||{},description_translations:e.descriptionTranslations||{}}).select().single();return c?{success:!1,error:c.message}:((0,o.revalidatePath)(`/cms/products/categories`),(0,o.revalidatePath)(`/cms/products/new`),(0,o.revalidatePath)(`/cms/products`),{success:!0,category:a})}async function C(e,t){let n=(0,i.getServiceRoleSupabaseClient)(),r=t.name.trim(),a=s(t.slug?.trim()||t.name);if(!r||!a)return{success:!1,error:`Category name is required.`};let{error:c}=await n.from(`categories`).update({name:r,slug:a,description:t.description?.trim()||null,name_translations:t.nameTranslations||{},description_translations:t.descriptionTranslations||{}}).eq(`id`,e);return c?{success:!1,error:c.message}:((0,o.revalidatePath)(`/cms/products/categories`),(0,o.revalidatePath)(`/cms/products/new`),(0,o.revalidatePath)(`/cms/products`),{success:!0})}async function w(e){let{error:t}=await(0,i.getServiceRoleSupabaseClient)().from(`categories`).delete().eq(`id`,e);return t?{success:!1,error:t.message}:((0,o.revalidatePath)(`/cms/products/categories`),(0,o.revalidatePath)(`/cms/products/new`),(0,o.revalidatePath)(`/cms/products`),{success:!0})}async function T(e,n){let r=(0,i.getServiceRoleSupabaseClient)();try{return await t.syncCategoriesForTranslationGroup(r,e,n),(0,o.revalidatePath)(`/cms/products`),(0,o.revalidatePath)(`/cms/products/${e}/edit`),{success:!0}}catch(e){return{success:!1,error:e.message}}}exports.bulkDeleteProductsAction=p,exports.bulkDraftProductsAction=m,exports.createCategoryAction=S,exports.createProductAction=c,exports.createProductAttributeAction=g,exports.createProductAttributeTermAction=v,exports.deleteCategoryAction=w,exports.deleteProductAction=d,exports.deleteProductAttributeAction=_,exports.deleteProductAttributeTermAction=x,exports.publishProductAction=h,exports.reorderProductAttributeTermsAction=y,exports.syncProductCategoriesAction=T,exports.updateCategoryAction=C,exports.updateProductAction=u,exports.updateProductAttributeTranslationsAction=b;
@@ -1,233 +1,250 @@
1
- 'use server';
2
- import { getServiceRoleSupabaseClient as n, createClient as i } from "@nextblock-cms/db/server";
3
- import { createProduct as y, deleteProduct as h, syncCategoriesForTranslationGroup as A } from "../../../product-actions.es.js";
4
- import { syncProductSaleCouponToFreemius as S } from "../../../freemius-coupons.es.js";
5
- import { normalizeCurrencyRecord as g } from "../../../currency.es.js";
6
- import { sanitizeProductFormValuesForStoreManagedCurrencies as _ } from "./product-price-sync.es.js";
7
- import { revalidatePath as s } from "next/cache";
8
- import { redirect as P } from "next/navigation";
9
- function d(r) {
10
- return r.toLowerCase().trim().replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "").replace(/-+/g, "-").replace(/^-|-$/g, "");
11
- }
12
- async function F(r) {
13
- const e = i(), { data: t } = await e.from("currencies").select(
14
- "code, symbol, exchange_rate, is_default, is_active, auto_sync_product_prices, auto_update_exchange_rate, exchange_rate_source, exchange_rate_updated_at, rounding_mode, rounding_increment, rounding_charm_amount"
15
- ).eq("is_active", !0).order("code", { ascending: !0 }), o = _(
16
- r,
17
- (t || []).map((c) => g(c))
18
- ), a = await y(e, o);
19
- if (o.payment_provider === "freemius" && a?.id)
20
- try {
21
- await S({
22
- productId: a.id,
23
- client: n()
24
- });
25
- } catch (c) {
26
- console.error("Failed to sync Freemius sale coupon on create:", c);
27
- }
28
- s("/cms/products"), P("/cms/products");
29
- }
30
- async function q(r, e, t, o) {
31
- const a = {
32
- author_id: t,
33
- meta: o,
34
- updated_at: (/* @__PURE__ */ new Date()).toISOString()
35
- }, c = async () => {
36
- const { error: f } = await r.from("product_drafts").update(a).eq("product_id", e);
37
- if (f)
38
- throw new Error(`Failed to save product draft: ${f.message}`);
39
- }, { data: u, error: l } = await r.from("product_drafts").select("id").eq("product_id", e).maybeSingle();
40
- if (l)
41
- throw new Error(`Failed to read product draft: ${l.message}`);
42
- if (u) {
43
- await c();
44
- return;
45
- }
46
- const { data: w, error: p } = await r.from("blocks").select(
47
- "id, page_id, post_id, product_id, language_id, block_type, content, order, created_at, updated_at"
48
- ).eq("product_id", e).order("order", { ascending: !0 });
49
- if (p)
50
- throw new Error(`Failed to read product blocks: ${p.message}`);
51
- const { error: m } = await r.from("product_drafts").insert({
52
- ...a,
53
- blocks: w ?? [],
54
- product_id: e
55
- });
56
- if (m) {
57
- if (m.code === "23505") {
58
- await c();
59
- return;
60
- }
61
- throw new Error(`Failed to save product draft: ${m.message}`);
62
- }
63
- }
64
- async function k(r, e) {
65
- const t = i(), { data: { user: o } } = await t.auth.getUser();
66
- if (!o)
67
- throw new Error("User not authenticated.");
68
- const { data: a } = await t.from("currencies").select(
69
- "code, symbol, exchange_rate, is_default, is_active, auto_sync_product_prices, auto_update_exchange_rate, exchange_rate_source, exchange_rate_updated_at, rounding_mode, rounding_increment, rounding_charm_amount"
70
- ).eq("is_active", !0).order("code", { ascending: !0 }), c = _(
71
- e,
72
- (a || []).map((u) => g(u))
73
- );
74
- return await q(t, r, o.id, c), { success: !0 };
75
- }
76
- async function $(r) {
77
- const e = i();
78
- await h(e, r), s("/cms/products");
79
- }
80
- function b(r) {
81
- return Array.from(
82
- new Set(
83
- r.map((e) => e.trim()).filter(Boolean)
84
- )
85
- );
86
- }
87
- async function O(r) {
88
- const e = b(r);
89
- if (e.length === 0)
90
- return { success: !1, error: "Select at least one product." };
91
- const t = i(), { error: o } = await t.from("products").delete().in("id", e);
92
- return o ? { success: !1, error: o.message } : (s("/cms/products"), { success: !0, count: e.length });
93
- }
94
- async function z(r) {
95
- const e = b(r);
96
- if (e.length === 0)
97
- return { success: !1, error: "Select at least one product." };
98
- const t = i(), { error: o } = await t.from("products").update({
99
- status: "draft",
100
- updated_at: (/* @__PURE__ */ new Date()).toISOString()
101
- }).in("id", e);
102
- return o ? { success: !1, error: o.message } : (s("/cms/products"), { success: !0, count: e.length });
103
- }
104
- async function U(r) {
105
- const e = String(r || "").trim();
106
- if (!e)
107
- return { error: "Missing product id." };
108
- const t = i(), {
109
- data: { user: o }
110
- } = await t.auth.getUser();
111
- if (!o)
112
- return { error: "You must be signed in to publish a product." };
113
- const { data: a, error: c } = await t.from("products").update({
114
- status: "active",
115
- updated_at: (/* @__PURE__ */ new Date()).toISOString()
116
- }).eq("id", e).select("slug").single();
117
- return c || !a ? { error: c?.message || "Could not publish the product." } : (s("/cms/products"), s(`/cms/products/${e}/edit`), a.slug && s(`/product/${a.slug}`), {});
118
- }
119
- async function M(r) {
120
- const e = n(), t = r.name.trim(), o = d(r.slug?.trim() || r.name);
121
- if (!t || !o)
122
- return { success: !1, error: "Attribute name is required." };
123
- const { error: a } = await e.from("product_attributes").insert({
124
- name: t,
125
- slug: o
126
- });
127
- return a ? { success: !1, error: a.message } : (s("/cms/products/attributes"), s("/cms/products/new"), s("/cms/products"), { success: !0 });
128
- }
129
- async function B(r) {
130
- const e = n(), { error: t } = await e.from("product_attributes").delete().eq("id", r);
131
- return t ? { success: !1, error: t.message } : (s("/cms/products/attributes"), s("/cms/products/new"), s("/cms/products"), { success: !0 });
132
- }
133
- async function R(r) {
134
- const e = n(), t = r.value.trim(), o = d(r.slug?.trim() || r.value);
135
- if (!t || !o)
136
- return { success: !1, error: "Term value is required." };
137
- const { data: a } = await e.from("product_attribute_terms").select("sort_order").eq("attribute_id", r.attributeId).order("sort_order", { ascending: !1 }).limit(1), c = typeof a?.[0]?.sort_order == "number" ? a[0].sort_order + 1 : 0, { error: u } = await e.from("product_attribute_terms").insert({
138
- attribute_id: r.attributeId,
139
- value: t,
140
- slug: o,
141
- sort_order: c
142
- });
143
- return u ? { success: !1, error: u.message } : (s("/cms/products/attributes"), s("/cms/products/new"), s("/cms/products"), { success: !0 });
144
- }
145
- async function G(r) {
146
- const e = n();
147
- for (const [t, o] of r.orderedTermIds.entries()) {
148
- const { error: a } = await e.from("product_attribute_terms").update({
149
- sort_order: t,
150
- updated_at: (/* @__PURE__ */ new Date()).toISOString()
151
- }).eq("id", o).eq("attribute_id", r.attributeId);
152
- if (a)
153
- return { success: !1, error: a.message };
154
- }
155
- return s("/cms/products/attributes"), s("/cms/products/new"), s("/cms/products"), { success: !0 };
156
- }
157
- async function L(r) {
158
- const e = n(), { error: t } = await e.from("product_attributes").update({
159
- name_translations: r.nameTranslations,
160
- updated_at: (/* @__PURE__ */ new Date()).toISOString()
161
- }).eq("id", r.attributeId);
162
- if (t)
163
- return { success: !1, error: t.message };
164
- for (const o of r.termTranslations) {
165
- const { error: a } = await e.from("product_attribute_terms").update({
166
- value_translations: o.valueTranslations,
167
- updated_at: (/* @__PURE__ */ new Date()).toISOString()
168
- }).eq("id", o.termId).eq("attribute_id", r.attributeId);
169
- if (a)
170
- return { success: !1, error: a.message };
171
- }
172
- return s("/cms/products/attributes"), s("/cms/products/new"), s("/cms/products"), { success: !0 };
173
- }
174
- async function V(r) {
175
- const e = n(), { error: t } = await e.from("product_attribute_terms").delete().eq("id", r);
176
- return t ? { success: !1, error: t.message } : (s("/cms/products/attributes"), s("/cms/products/new"), s("/cms/products"), { success: !0 });
177
- }
178
- async function Y(r) {
179
- const e = n(), t = r.name.trim(), o = d(r.slug?.trim() || r.name);
180
- if (!t || !o)
181
- return { success: !1, error: "Category name is required." };
182
- const { data: a, error: c } = await e.from("categories").insert({
183
- name: t,
184
- slug: o,
185
- description: r.description?.trim() || null,
186
- name_translations: r.nameTranslations || {},
187
- description_translations: r.descriptionTranslations || {}
188
- }).select().single();
189
- return c ? { success: !1, error: c.message } : (s("/cms/products/categories"), s("/cms/products/new"), s("/cms/products"), { success: !0, category: a });
190
- }
191
- async function j(r, e) {
192
- const t = n(), o = e.name.trim(), a = d(e.slug?.trim() || e.name);
193
- if (!o || !a)
194
- return { success: !1, error: "Category name is required." };
195
- const { error: c } = await t.from("categories").update({
196
- name: o,
197
- slug: a,
198
- description: e.description?.trim() || null,
199
- name_translations: e.nameTranslations || {},
200
- description_translations: e.descriptionTranslations || {}
201
- }).eq("id", r);
202
- return c ? { success: !1, error: c.message } : (s("/cms/products/categories"), s("/cms/products/new"), s("/cms/products"), { success: !0 });
203
- }
204
- async function H(r) {
205
- const e = n(), { error: t } = await e.from("categories").delete().eq("id", r);
206
- return t ? { success: !1, error: t.message } : (s("/cms/products/categories"), s("/cms/products/new"), s("/cms/products"), { success: !0 });
207
- }
208
- async function J(r, e) {
209
- const t = n();
210
- try {
211
- return await A(t, r, e), s("/cms/products"), s(`/cms/products/${r}/edit`), { success: !0 };
212
- } catch (o) {
213
- return { success: !1, error: o.message };
214
- }
215
- }
216
- export {
217
- O as bulkDeleteProductsAction,
218
- z as bulkDraftProductsAction,
219
- Y as createCategoryAction,
220
- F as createProductAction,
221
- M as createProductAttributeAction,
222
- R as createProductAttributeTermAction,
223
- H as deleteCategoryAction,
224
- $ as deleteProductAction,
225
- B as deleteProductAttributeAction,
226
- V as deleteProductAttributeTermAction,
227
- U as publishProductAction,
228
- G as reorderProductAttributeTermsAction,
229
- J as syncProductCategoriesAction,
230
- j as updateCategoryAction,
231
- k as updateProductAction,
232
- L as updateProductAttributeTranslationsAction
233
- };
1
+ "use server";
2
+ import { normalizeCurrencyRecord as e } from "../../../currency.es.js";
3
+ import { createProduct as t, deleteProduct as n, syncCategoriesForTranslationGroup as r } from "../../../product-actions.es.js";
4
+ import { sanitizeProductFormValuesForStoreManagedCurrencies as i } from "./product-price-sync.es.js";
5
+ import { syncProductSaleCouponToFreemius as a } from "../../../freemius-coupons.es.js";
6
+ import { createClient as o, getServiceRoleSupabaseClient as s } from "@nextblock-cms/db/server";
7
+ import { redirect as c } from "next/navigation";
8
+ import { revalidatePath as l } from "next/cache";
9
+ //#region libs/ecommerce/src/lib/pages/cms/products/server-actions.ts
10
+ function u(e) {
11
+ return e.toLowerCase().trim().replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "").replace(/-+/g, "-").replace(/^-|-$/g, "");
12
+ }
13
+ async function d(n) {
14
+ let r = o(), { data: u } = await r.from("currencies").select("code, symbol, exchange_rate, is_default, is_active, auto_sync_product_prices, auto_update_exchange_rate, exchange_rate_source, exchange_rate_updated_at, rounding_mode, rounding_increment, rounding_charm_amount").eq("is_active", !0).order("code", { ascending: !0 }), d = i(n, (u || []).map((t) => e(t))), f = await t(r, d);
15
+ if (d.payment_provider === "freemius" && f?.id) try {
16
+ await a({
17
+ productId: f.id,
18
+ client: s()
19
+ });
20
+ } catch (e) {
21
+ console.error("Failed to sync Freemius sale coupon on create:", e);
22
+ }
23
+ l("/cms/products"), c("/cms/products");
24
+ }
25
+ async function f(e, t, n, r) {
26
+ let i = {
27
+ author_id: n,
28
+ meta: r,
29
+ updated_at: (/* @__PURE__ */ new Date()).toISOString()
30
+ }, a = async () => {
31
+ let { error: n } = await e.from("product_drafts").update(i).eq("product_id", t);
32
+ if (n) throw Error(`Failed to save product draft: ${n.message}`);
33
+ }, { data: o, error: s } = await e.from("product_drafts").select("id").eq("product_id", t).maybeSingle();
34
+ if (s) throw Error(`Failed to read product draft: ${s.message}`);
35
+ if (o) {
36
+ await a();
37
+ return;
38
+ }
39
+ let { data: c, error: l } = await e.from("blocks").select("id, page_id, post_id, product_id, language_id, block_type, content, order, created_at, updated_at").eq("product_id", t).order("order", { ascending: !0 });
40
+ if (l) throw Error(`Failed to read product blocks: ${l.message}`);
41
+ let { error: u } = await e.from("product_drafts").insert({
42
+ ...i,
43
+ blocks: c ?? [],
44
+ product_id: t
45
+ });
46
+ if (u) {
47
+ if (u.code === "23505") {
48
+ await a();
49
+ return;
50
+ }
51
+ throw Error(`Failed to save product draft: ${u.message}`);
52
+ }
53
+ }
54
+ async function p(t, n) {
55
+ let r = o(), { data: { user: a } } = await r.auth.getUser();
56
+ if (!a) throw Error("User not authenticated.");
57
+ let { data: s } = await r.from("currencies").select("code, symbol, exchange_rate, is_default, is_active, auto_sync_product_prices, auto_update_exchange_rate, exchange_rate_source, exchange_rate_updated_at, rounding_mode, rounding_increment, rounding_charm_amount").eq("is_active", !0).order("code", { ascending: !0 }), c = i(n, (s || []).map((t) => e(t)));
58
+ return await f(r, t, a.id, c), { success: !0 };
59
+ }
60
+ async function m(e) {
61
+ let t = o();
62
+ await n(t, e), l("/cms/products");
63
+ }
64
+ function h(e) {
65
+ return Array.from(new Set(e.map((e) => e.trim()).filter(Boolean)));
66
+ }
67
+ async function g(e) {
68
+ let t = h(e);
69
+ if (t.length === 0) return {
70
+ success: !1,
71
+ error: "Select at least one product."
72
+ };
73
+ let { error: n } = await o().from("products").delete().in("id", t);
74
+ return n ? {
75
+ success: !1,
76
+ error: n.message
77
+ } : (l("/cms/products"), {
78
+ success: !0,
79
+ count: t.length
80
+ });
81
+ }
82
+ async function _(e) {
83
+ let t = h(e);
84
+ if (t.length === 0) return {
85
+ success: !1,
86
+ error: "Select at least one product."
87
+ };
88
+ let { error: n } = await o().from("products").update({
89
+ status: "draft",
90
+ updated_at: (/* @__PURE__ */ new Date()).toISOString()
91
+ }).in("id", t);
92
+ return n ? {
93
+ success: !1,
94
+ error: n.message
95
+ } : (l("/cms/products"), {
96
+ success: !0,
97
+ count: t.length
98
+ });
99
+ }
100
+ async function v(e) {
101
+ let t = String(e || "").trim();
102
+ if (!t) return { error: "Missing product id." };
103
+ let n = o(), { data: { user: r } } = await n.auth.getUser();
104
+ if (!r) return { error: "You must be signed in to publish a product." };
105
+ let { data: i, error: a } = await n.from("products").update({
106
+ status: "active",
107
+ updated_at: (/* @__PURE__ */ new Date()).toISOString()
108
+ }).eq("id", t).select("slug").single();
109
+ return a || !i ? { error: a?.message || "Could not publish the product." } : (l("/cms/products"), l(`/cms/products/${t}/edit`), i.slug && l(`/product/${i.slug}`), {});
110
+ }
111
+ async function y(e) {
112
+ let t = s(), n = e.name.trim(), r = u(e.slug?.trim() || e.name);
113
+ if (!n || !r) return {
114
+ success: !1,
115
+ error: "Attribute name is required."
116
+ };
117
+ let { error: i } = await t.from("product_attributes").insert({
118
+ name: n,
119
+ slug: r
120
+ });
121
+ return i ? {
122
+ success: !1,
123
+ error: i.message
124
+ } : (l("/cms/products/attributes"), l("/cms/products/new"), l("/cms/products"), { success: !0 });
125
+ }
126
+ async function b(e) {
127
+ let { error: t } = await s().from("product_attributes").delete().eq("id", e);
128
+ return t ? {
129
+ success: !1,
130
+ error: t.message
131
+ } : (l("/cms/products/attributes"), l("/cms/products/new"), l("/cms/products"), { success: !0 });
132
+ }
133
+ async function x(e) {
134
+ let t = s(), n = e.value.trim(), r = u(e.slug?.trim() || e.value);
135
+ if (!n || !r) return {
136
+ success: !1,
137
+ error: "Term value is required."
138
+ };
139
+ let { data: i } = await t.from("product_attribute_terms").select("sort_order").eq("attribute_id", e.attributeId).order("sort_order", { ascending: !1 }).limit(1), a = typeof i?.[0]?.sort_order == "number" ? i[0].sort_order + 1 : 0, { error: o } = await t.from("product_attribute_terms").insert({
140
+ attribute_id: e.attributeId,
141
+ value: n,
142
+ slug: r,
143
+ sort_order: a
144
+ });
145
+ return o ? {
146
+ success: !1,
147
+ error: o.message
148
+ } : (l("/cms/products/attributes"), l("/cms/products/new"), l("/cms/products"), { success: !0 });
149
+ }
150
+ async function S(e) {
151
+ let t = s();
152
+ for (let [n, r] of e.orderedTermIds.entries()) {
153
+ let { error: i } = await t.from("product_attribute_terms").update({
154
+ sort_order: n,
155
+ updated_at: (/* @__PURE__ */ new Date()).toISOString()
156
+ }).eq("id", r).eq("attribute_id", e.attributeId);
157
+ if (i) return {
158
+ success: !1,
159
+ error: i.message
160
+ };
161
+ }
162
+ return l("/cms/products/attributes"), l("/cms/products/new"), l("/cms/products"), { success: !0 };
163
+ }
164
+ async function C(e) {
165
+ let t = s(), { error: n } = await t.from("product_attributes").update({
166
+ name_translations: e.nameTranslations,
167
+ updated_at: (/* @__PURE__ */ new Date()).toISOString()
168
+ }).eq("id", e.attributeId);
169
+ if (n) return {
170
+ success: !1,
171
+ error: n.message
172
+ };
173
+ for (let n of e.termTranslations) {
174
+ let { error: r } = await t.from("product_attribute_terms").update({
175
+ value_translations: n.valueTranslations,
176
+ updated_at: (/* @__PURE__ */ new Date()).toISOString()
177
+ }).eq("id", n.termId).eq("attribute_id", e.attributeId);
178
+ if (r) return {
179
+ success: !1,
180
+ error: r.message
181
+ };
182
+ }
183
+ return l("/cms/products/attributes"), l("/cms/products/new"), l("/cms/products"), { success: !0 };
184
+ }
185
+ async function w(e) {
186
+ let { error: t } = await s().from("product_attribute_terms").delete().eq("id", e);
187
+ return t ? {
188
+ success: !1,
189
+ error: t.message
190
+ } : (l("/cms/products/attributes"), l("/cms/products/new"), l("/cms/products"), { success: !0 });
191
+ }
192
+ async function T(e) {
193
+ let t = s(), n = e.name.trim(), r = u(e.slug?.trim() || e.name);
194
+ if (!n || !r) return {
195
+ success: !1,
196
+ error: "Category name is required."
197
+ };
198
+ let { data: i, error: a } = await t.from("categories").insert({
199
+ name: n,
200
+ slug: r,
201
+ description: e.description?.trim() || null,
202
+ name_translations: e.nameTranslations || {},
203
+ description_translations: e.descriptionTranslations || {}
204
+ }).select().single();
205
+ return a ? {
206
+ success: !1,
207
+ error: a.message
208
+ } : (l("/cms/products/categories"), l("/cms/products/new"), l("/cms/products"), {
209
+ success: !0,
210
+ category: i
211
+ });
212
+ }
213
+ async function E(e, t) {
214
+ let n = s(), r = t.name.trim(), i = u(t.slug?.trim() || t.name);
215
+ if (!r || !i) return {
216
+ success: !1,
217
+ error: "Category name is required."
218
+ };
219
+ let { error: a } = await n.from("categories").update({
220
+ name: r,
221
+ slug: i,
222
+ description: t.description?.trim() || null,
223
+ name_translations: t.nameTranslations || {},
224
+ description_translations: t.descriptionTranslations || {}
225
+ }).eq("id", e);
226
+ return a ? {
227
+ success: !1,
228
+ error: a.message
229
+ } : (l("/cms/products/categories"), l("/cms/products/new"), l("/cms/products"), { success: !0 });
230
+ }
231
+ async function D(e) {
232
+ let { error: t } = await s().from("categories").delete().eq("id", e);
233
+ return t ? {
234
+ success: !1,
235
+ error: t.message
236
+ } : (l("/cms/products/categories"), l("/cms/products/new"), l("/cms/products"), { success: !0 });
237
+ }
238
+ async function O(e, t) {
239
+ let n = s();
240
+ try {
241
+ return await r(n, e, t), l("/cms/products"), l(`/cms/products/${e}/edit`), { success: !0 };
242
+ } catch (e) {
243
+ return {
244
+ success: !1,
245
+ error: e.message
246
+ };
247
+ }
248
+ }
249
+ //#endregion
250
+ export { g as bulkDeleteProductsAction, _ as bulkDraftProductsAction, T as createCategoryAction, d as createProductAction, y as createProductAttributeAction, x as createProductAttributeTermAction, D as deleteCategoryAction, m as deleteProductAction, b as deleteProductAttributeAction, w as deleteProductAttributeTermAction, v as publishProductAction, S as reorderProductAttributeTermsAction, O as syncProductCategoriesAction, E as updateCategoryAction, p as updateProductAction, C as updateProductAttributeTranslationsAction };