@nextblock-cms/ecom 0.8.6 → 0.8.7

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 (277) hide show
  1. package/index.cjs.js +1 -1
  2. package/index.es.js +136 -533
  3. package/lib/CurrencyProvider.cjs.js +1 -0
  4. package/lib/CurrencyProvider.es.js +99 -0
  5. package/lib/cart-store.cjs.js +1 -0
  6. package/{cart-store.es.js → lib/cart-store.es.js} +13 -13
  7. package/lib/components/AccountNavigationMenu.cjs.js +1 -0
  8. package/lib/components/AccountNavigationMenu.es.js +44 -0
  9. package/lib/components/AddToCartButton.cjs.js +1 -0
  10. package/{AddToCartButton-ffE0DhHu.js → lib/components/AddToCartButton.es.js} +14 -13
  11. package/lib/components/Cart.cjs.js +1 -0
  12. package/lib/components/Cart.es.js +148 -0
  13. package/lib/components/CartDrawer.cjs.js +1 -0
  14. package/{components → lib/components}/CartDrawer.es.js +15 -14
  15. package/{components → lib/components}/CartIcon.cjs.js +1 -1
  16. package/{components → lib/components}/CartIcon.es.js +1 -0
  17. package/lib/components/Checkout.cjs.js +1 -0
  18. package/{components → lib/components}/Checkout.es.js +330 -363
  19. package/lib/components/CouponForm.cjs.js +1 -0
  20. package/lib/components/CouponForm.es.js +136 -0
  21. package/lib/components/CurrencySwitcher.cjs.js +1 -0
  22. package/{components → lib/components}/CurrencySwitcher.es.js +5 -4
  23. package/lib/components/CustomerProfileForm.cjs.js +1 -0
  24. package/lib/components/CustomerProfileForm.es.js +355 -0
  25. package/lib/components/FeaturedProduct.cjs.js +1 -0
  26. package/{components → lib/components}/FeaturedProduct.es.js +9 -8
  27. package/lib/components/InvoiceDocument.cjs.js +1 -0
  28. package/lib/components/InvoiceDocument.es.js +196 -0
  29. package/lib/components/InvoiceViewerShell.cjs.js +29 -0
  30. package/lib/components/InvoiceViewerShell.es.js +100 -0
  31. package/lib/components/ProductCard.cjs.js +1 -0
  32. package/lib/components/ProductCard.es.js +119 -0
  33. package/lib/components/ProductDetailsLayout.cjs.js +1 -0
  34. package/lib/components/ProductDetailsLayout.es.js +361 -0
  35. package/lib/components/ProductGallery.cjs.js +1 -0
  36. package/lib/components/ProductGallery.es.js +41 -0
  37. package/lib/components/ProductGrid.cjs.js +1 -0
  38. package/lib/components/ProductGrid.es.js +19 -0
  39. package/lib/components/ShippingEstimator.cjs.js +1 -0
  40. package/lib/components/ShippingEstimator.es.js +125 -0
  41. package/lib/components/SubscriptionSelector.cjs.js +1 -0
  42. package/lib/components/SubscriptionSelector.es.js +140 -0
  43. package/lib/countries.cjs.js +1 -0
  44. package/lib/countries.es.js +77 -0
  45. package/lib/coupon-server.cjs.js +1 -0
  46. package/{coupon-server-DUKVtyYs.js → lib/coupon-server.es.js} +68 -82
  47. package/lib/coupons.cjs.js +1 -0
  48. package/lib/coupons.es.js +17 -0
  49. package/lib/currency-store.cjs.js +1 -0
  50. package/lib/currency-store.es.js +27 -0
  51. package/lib/currency-sync.cjs.js +1 -0
  52. package/lib/currency-sync.es.js +180 -0
  53. package/lib/customer-addresses.cjs.js +1 -0
  54. package/lib/customer-addresses.es.js +116 -0
  55. package/lib/customer-orders.cjs.js +1 -0
  56. package/lib/customer-orders.es.js +45 -0
  57. package/lib/customer.cjs.js +1 -0
  58. package/{customer-C3xccjUg.js → lib/customer.es.js} +15 -14
  59. package/lib/export-helpers.cjs.js +1 -0
  60. package/lib/export-helpers.es.js +56 -0
  61. package/lib/factory.cjs.js +1 -0
  62. package/lib/factory.es.js +8 -0
  63. package/lib/freemius-coupons.cjs.js +1 -0
  64. package/lib/freemius-coupons.es.js +272 -0
  65. package/lib/freemius-order-sync.cjs.js +1 -0
  66. package/lib/freemius-order-sync.es.js +284 -0
  67. package/lib/inventory-settings.cjs.js +1 -0
  68. package/lib/inventory-settings.es.js +86 -0
  69. package/lib/invoice-server.cjs.js +33 -0
  70. package/lib/invoice-server.es.js +141 -0
  71. package/lib/invoice-ui.cjs.js +1 -0
  72. package/lib/invoice-ui.es.js +71 -0
  73. package/lib/invoice.cjs.js +1 -0
  74. package/lib/invoice.es.js +102 -0
  75. package/lib/order-inventory.cjs.js +61 -0
  76. package/lib/order-inventory.es.js +128 -0
  77. package/lib/order-tax-details.cjs.js +1 -0
  78. package/lib/order-tax-details.es.js +164 -0
  79. package/lib/pages/cms/coupons/CouponEditorForm.cjs.js +1 -0
  80. package/lib/pages/cms/coupons/CouponEditorForm.es.js +189 -0
  81. package/lib/pages/cms/coupons/CouponsPage.cjs.js +5 -0
  82. package/lib/pages/cms/coupons/CouponsPage.es.js +171 -0
  83. package/lib/pages/cms/coupons/CreateCouponDialog.cjs.js +1 -0
  84. package/lib/pages/cms/coupons/CreateCouponDialog.es.js +35 -0
  85. package/lib/pages/cms/coupons/EditCouponPage.cjs.js +1 -0
  86. package/lib/pages/cms/coupons/EditCouponPage.es.js +48 -0
  87. package/lib/pages/cms/coupons/ProductScopePicker.cjs.js +1 -0
  88. package/lib/pages/cms/coupons/ProductScopePicker.es.js +120 -0
  89. package/lib/pages/cms/coupons/actions.cjs.js +1 -0
  90. package/lib/pages/cms/coupons/actions.es.js +128 -0
  91. package/lib/pages/cms/coupons/product-options.cjs.js +1 -0
  92. package/lib/pages/cms/coupons/product-options.es.js +27 -0
  93. package/lib/pages/cms/orders/ExportReportsDialog.cjs.js +1 -0
  94. package/lib/pages/cms/orders/ExportReportsDialog.es.js +130 -0
  95. package/lib/pages/cms/orders/OrderDetailPage.cjs.js +1 -0
  96. package/lib/pages/cms/orders/OrderDetailPage.es.js +137 -0
  97. package/lib/pages/cms/orders/OrderPrintButton.cjs.js +1 -0
  98. package/lib/pages/cms/orders/OrderPrintButton.es.js +22 -0
  99. package/lib/pages/cms/orders/OrderStatusForm.cjs.js +1 -0
  100. package/lib/pages/cms/orders/OrderStatusForm.es.js +71 -0
  101. package/lib/pages/cms/orders/OrdersPage.cjs.js +1 -0
  102. package/lib/pages/cms/orders/OrdersPage.es.js +104 -0
  103. package/lib/pages/cms/orders/actions.cjs.js +7 -0
  104. package/lib/pages/cms/orders/actions.es.js +71 -0
  105. package/lib/pages/cms/orders/export-actions.cjs.js +1 -0
  106. package/lib/pages/cms/orders/export-actions.es.js +27 -0
  107. package/lib/pages/cms/orders/server-actions.cjs.js +1 -0
  108. package/lib/pages/cms/orders/server-actions.es.js +55 -0
  109. package/lib/pages/cms/payments/PaymentsClient.cjs.js +1 -0
  110. package/lib/pages/cms/payments/PaymentsClient.es.js +188 -0
  111. package/lib/pages/cms/payments/PaymentsPage.cjs.js +1 -0
  112. package/lib/pages/cms/payments/PaymentsPage.es.js +29 -0
  113. package/lib/pages/cms/payments/actions.cjs.js +1 -0
  114. package/lib/pages/cms/payments/actions.es.js +23 -0
  115. package/lib/pages/cms/payments/queries.cjs.js +1 -0
  116. package/lib/pages/cms/payments/queries.es.js +30 -0
  117. package/lib/pages/cms/products/ProductsPage.cjs.js +1 -0
  118. package/lib/pages/cms/products/ProductsPage.es.js +46 -0
  119. package/lib/pages/cms/products/_id_/edit/EditProductPage.cjs.js +1 -0
  120. package/lib/pages/cms/products/_id_/edit/EditProductPage.es.js +156 -0
  121. package/lib/pages/cms/products/actions.cjs.js +44 -0
  122. package/lib/pages/cms/products/actions.es.js +175 -0
  123. package/lib/pages/cms/products/attributes/AttributeManagementPage.cjs.js +1 -0
  124. package/lib/pages/cms/products/attributes/AttributeManagementPage.es.js +48 -0
  125. package/lib/pages/cms/products/attributes/components/AttributeManager.cjs.js +1 -0
  126. package/lib/pages/cms/products/attributes/components/AttributeManager.es.js +291 -0
  127. package/lib/pages/cms/products/categories/CategoryManagementPage.cjs.js +1 -0
  128. package/lib/pages/cms/products/categories/CategoryManagementPage.es.js +36 -0
  129. package/lib/pages/cms/products/categories/components/CategoryManager.cjs.js +1 -0
  130. package/lib/pages/cms/products/categories/components/CategoryManager.es.js +263 -0
  131. package/lib/pages/cms/products/components/CopyProductFromLanguage.cjs.js +1 -0
  132. package/lib/pages/cms/products/components/CopyProductFromLanguage.es.js +114 -0
  133. package/lib/pages/cms/products/components/CurrencyPriceFields.cjs.js +1 -0
  134. package/lib/pages/cms/products/components/CurrencyPriceFields.es.js +107 -0
  135. package/lib/pages/cms/products/components/DeleteProductButton.cjs.js +1 -0
  136. package/lib/pages/cms/products/components/DeleteProductButton.es.js +48 -0
  137. package/lib/pages/cms/products/components/FreemiusPricingDashboard.cjs.js +1 -0
  138. package/lib/pages/cms/products/components/FreemiusPricingDashboard.es.js +86 -0
  139. package/lib/pages/cms/products/components/ProductCategorySelector.cjs.js +1 -0
  140. package/lib/pages/cms/products/components/ProductCategorySelector.es.js +160 -0
  141. package/lib/pages/cms/products/components/ProductForm.cjs.js +1 -0
  142. package/lib/pages/cms/products/components/ProductForm.es.js +702 -0
  143. package/lib/pages/cms/products/components/ProductMediaManager.cjs.js +1 -0
  144. package/lib/pages/cms/products/components/ProductMediaManager.es.js +104 -0
  145. package/lib/pages/cms/products/components/ProductsBulkTable.cjs.js +1 -0
  146. package/lib/pages/cms/products/components/ProductsBulkTable.es.js +228 -0
  147. package/lib/pages/cms/products/components/SaleScheduleFields.cjs.js +1 -0
  148. package/lib/pages/cms/products/components/SaleScheduleFields.es.js +137 -0
  149. package/lib/pages/cms/products/components/SyncFreemiusButton.cjs.js +1 -0
  150. package/lib/pages/cms/products/components/SyncFreemiusButton.es.js +36 -0
  151. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.cjs.js +1 -0
  152. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.es.js +40 -0
  153. package/lib/pages/cms/products/components/VariationsEditor.cjs.js +1 -0
  154. package/lib/pages/cms/products/components/VariationsEditor.es.js +408 -0
  155. package/lib/pages/cms/products/inventory/InventoryPage.cjs.js +1 -0
  156. package/lib/pages/cms/products/inventory/InventoryPage.es.js +16 -0
  157. package/lib/pages/cms/products/inventory/InventoryTableClient.cjs.js +2 -0
  158. package/lib/pages/cms/products/inventory/InventoryTableClient.es.js +214 -0
  159. package/lib/pages/cms/products/inventory/actions.cjs.js +3 -0
  160. package/lib/pages/cms/products/inventory/actions.es.js +95 -0
  161. package/lib/pages/cms/products/new/NewProductPage.cjs.js +1 -0
  162. package/lib/pages/cms/products/new/NewProductPage.es.js +76 -0
  163. package/lib/pages/cms/products/product-price-sync.cjs.js +1 -0
  164. package/lib/pages/cms/products/product-price-sync.es.js +98 -0
  165. package/lib/pages/cms/products/server-actions.cjs.js +1 -0
  166. package/lib/pages/cms/products/server-actions.es.js +193 -0
  167. package/lib/pages/cms/shipping/ShippingPage.cjs.js +5 -0
  168. package/lib/pages/cms/shipping/ShippingPage.es.js +211 -0
  169. package/lib/pages/cms/shipping/components/RateForm.cjs.js +1 -0
  170. package/lib/pages/cms/shipping/components/RateForm.es.js +441 -0
  171. package/lib/pages/cms/shipping/components/ZoneForm.cjs.js +1 -0
  172. package/lib/pages/cms/shipping/components/ZoneForm.es.js +228 -0
  173. package/lib/pages/cms/shipping/server-actions.cjs.js +1 -0
  174. package/lib/pages/cms/shipping/server-actions.es.js +159 -0
  175. package/lib/pages/cms/taxes/TaxesPage.cjs.js +1 -0
  176. package/lib/pages/cms/taxes/TaxesPage.es.js +172 -0
  177. package/lib/pages/cms/taxes/actions.cjs.js +1 -0
  178. package/lib/pages/cms/taxes/actions.es.js +57 -0
  179. package/lib/pages/cms/taxes/components/TaxRateForm.cjs.js +1 -0
  180. package/lib/pages/cms/taxes/components/TaxRateForm.es.js +100 -0
  181. package/lib/product-actions.cjs.js +237 -0
  182. package/lib/product-actions.es.js +524 -0
  183. package/lib/product-context.cjs.js +1 -0
  184. package/lib/product-context.es.js +16 -0
  185. package/lib/product-schema.cjs.js +1 -0
  186. package/lib/product-schema.es.js +134 -0
  187. package/lib/providers/freemius.cjs.js +5 -0
  188. package/lib/providers/freemius.es.js +538 -0
  189. package/lib/providers/stripe.cjs.js +1 -0
  190. package/lib/providers/stripe.es.js +473 -0
  191. package/lib/server-actions/coupon-actions.cjs.js +1 -0
  192. package/lib/server-actions/coupon-actions.es.js +23 -0
  193. package/lib/server-actions/customer-actions.cjs.js +1 -0
  194. package/lib/server-actions/customer-actions.es.js +30 -0
  195. package/lib/server-actions/product-actions.cjs.js +1 -0
  196. package/{server-actions → lib/server-actions}/product-actions.es.js +5 -4
  197. package/lib/server-actions/shipping-actions.cjs.js +1 -0
  198. package/{shipping-actions-BnHjlo2q.js → lib/server-actions/shipping-actions.es.js} +9 -7
  199. package/lib/server-actions/tax-actions.cjs.js +1 -0
  200. package/lib/server-actions/tax-actions.es.js +40 -0
  201. package/lib/shared-inventory.cjs.js +15 -0
  202. package/lib/shared-inventory.es.js +171 -0
  203. package/lib/shipping/resolver.cjs.js +7 -0
  204. package/lib/shipping/resolver.es.js +62 -0
  205. package/lib/shipping-rate-currency.cjs.js +1 -0
  206. package/lib/shipping-rate-currency.es.js +72 -0
  207. package/lib/states.cjs.js +1 -0
  208. package/{states-DlHJezQ1.js → lib/states.es.js} +27 -100
  209. package/lib/stripe/checkout.cjs.js +1 -0
  210. package/lib/stripe/checkout.es.js +182 -0
  211. package/lib/stripe/client.cjs.js +1 -0
  212. package/lib/stripe/client.es.js +7 -0
  213. package/lib/stripe/order-sync.cjs.js +1 -0
  214. package/lib/stripe/order-sync.es.js +130 -0
  215. package/lib/stripe/webhooks.cjs.js +1 -0
  216. package/lib/stripe/webhooks.es.js +30 -0
  217. package/lib/tax-calculation.cjs.js +1 -0
  218. package/lib/tax-calculation.es.js +101 -0
  219. package/lib/trials.cjs.js +1 -0
  220. package/{trials-RDcRAZKx.js → lib/trials.es.js} +9 -9
  221. package/{use-cart.es.js → lib/use-cart.es.js} +1 -0
  222. package/lib/zod-config.cjs.js +1 -0
  223. package/lib/zod-config.es.js +6 -0
  224. package/package.json +4 -4
  225. package/server.cjs.js +1 -110
  226. package/server.es.js +178 -6052
  227. package/AddToCartButton-DsSEH9yp.cjs +0 -1
  228. package/CouponForm-BI_5SBHQ.js +0 -152
  229. package/CouponForm-D_uu2bLP.cjs +0 -1
  230. package/CurrencyProvider-Cg-Q6ucj.cjs +0 -1
  231. package/CurrencyProvider-OzlRN96V.js +0 -120
  232. package/CurrencyProvider.cjs.js +0 -1
  233. package/CurrencyProvider.es.js +0 -10
  234. package/ProductDetailsLayout-BxJH_BxR.cjs +0 -1
  235. package/ProductDetailsLayout-Dg8dRTYp.js +0 -530
  236. package/ProductGrid-BdL7iglO.cjs +0 -1
  237. package/ProductGrid-D3AWM8sr.js +0 -130
  238. package/actions-AHmBrS5e.cjs +0 -48
  239. package/actions-j5fuSZX-.js +0 -820
  240. package/cart-store.cjs.js +0 -1
  241. package/components/Cart.cjs.js +0 -1
  242. package/components/Cart.es.js +0 -259
  243. package/components/CartDrawer.cjs.js +0 -1
  244. package/components/Checkout.cjs.js +0 -1
  245. package/components/CurrencySwitcher.cjs.js +0 -1
  246. package/components/FeaturedProduct.cjs.js +0 -1
  247. package/components/ProductDetailsLayout.cjs.js +0 -1
  248. package/components/ProductDetailsLayout.es.js +0 -19
  249. package/components/ProductGrid.cjs.js +0 -1
  250. package/components/ProductGrid.es.js +0 -6
  251. package/coupon-server-C9ySm3I5.cjs +0 -1
  252. package/customer-C-UPvrYN.cjs +0 -1
  253. package/invoice-ui-CAnJPu6n.cjs +0 -29
  254. package/invoice-ui-DtpbTJE1.js +0 -2886
  255. package/product-actions-CONBF8i6.cjs +0 -251
  256. package/product-actions-DjlIWCMH.js +0 -691
  257. package/resolver-Fz_FKsfX.cjs +0 -7
  258. package/resolver-cfrCaHpE.js +0 -128
  259. package/server-actions/product-actions.cjs.js +0 -1
  260. package/shipping-actions-D6zt20gg.cjs +0 -1
  261. package/states-CWYRxV4B.cjs +0 -1
  262. package/tax-calculation-Dab89aHd.js +0 -181
  263. package/tax-calculation-MkDKOEkL.cjs +0 -1
  264. package/trials-DvZaOtNy.cjs +0 -1
  265. /package/{components → lib/components}/SimpleTiptapRenderer.cjs.js +0 -0
  266. /package/{components → lib/components}/SimpleTiptapRenderer.es.js +0 -0
  267. /package/{currency-constants.cjs.js → lib/currency-constants.cjs.js} +0 -0
  268. /package/{currency-constants.es.js → lib/currency-constants.es.js} +0 -0
  269. /package/{currency-rest-client-uolJxUkL.cjs → lib/currency-rest-client.cjs.js} +0 -0
  270. /package/{currency-rest-client-CwoqdgAP.js → lib/currency-rest-client.es.js} +0 -0
  271. /package/{currency.cjs.js → lib/currency.cjs.js} +0 -0
  272. /package/{currency.es.js → lib/currency.es.js} +0 -0
  273. /package/{types.cjs.js → lib/types.cjs.js} +0 -0
  274. /package/{types.es.js → lib/types.es.js} +0 -0
  275. /package/{use-cart.cjs.js → lib/use-cart.cjs.js} +0 -0
  276. /package/{variation-utils.cjs.js → lib/variation-utils.cjs.js} +0 -0
  277. /package/{variation-utils.es.js → lib/variation-utils.es.js} +0 -0
@@ -0,0 +1,57 @@
1
+ 'use server';
2
+ import { createClient as g } from "@nextblock-cms/db/server";
3
+ import { revalidatePath as s } from "next/cache";
4
+ import { redirect as w } from "next/navigation";
5
+ import { normalizeCountryCode as l } from "../../../countries.es.js";
6
+ import { getEcommerceInventorySettings as x, upsertEcommerceInventorySettings as p } from "../../../inventory-settings.es.js";
7
+ import { normalizeSubdivisionCode as f } from "../../../states.es.js";
8
+ async function c() {
9
+ const t = g(), {
10
+ data: { user: e }
11
+ } = await t.auth.getUser();
12
+ if (!e)
13
+ throw new Error("Unauthorized");
14
+ const { data: r } = await t.from("profiles").select("role").eq("id", e.id).single();
15
+ if (!r || r.role !== "ADMIN")
16
+ throw new Error("Forbidden");
17
+ return t;
18
+ }
19
+ async function C(t) {
20
+ const e = await c(), r = await x(e), a = t.getAll("enableTaxes").includes("true"), i = t.get("taxCalculationMode") === "automatic" ? "automatic" : "manual", { error: n } = await p(e, {
21
+ trackQuantities: r.trackQuantities,
22
+ enableTaxes: a,
23
+ taxCalculationMode: i
24
+ });
25
+ if (n)
26
+ throw new Error(n.message);
27
+ s("/cms/shipping"), s("/cms/settings/taxes"), w("/cms/settings/taxes?success=Tax settings updated");
28
+ }
29
+ async function T(t) {
30
+ const e = await c(), r = String(t.get("id") || "").trim(), a = l(String(t.get("country_code") || "").trim()), i = String(t.get("state_code") || "").trim(), n = String(t.get("tax_name") || "").trim(), o = Number(t.get("tax_rate"));
31
+ if (!a)
32
+ throw new Error("Country code is required.");
33
+ if (!n)
34
+ throw new Error("Tax name is required.");
35
+ if (!Number.isFinite(o) || o < 0 || o > 100)
36
+ throw new Error("Tax rate must be between 0 and 100.");
37
+ const m = {
38
+ country_code: a,
39
+ state_code: f(a, i) || null,
40
+ tax_name: n,
41
+ tax_rate: o
42
+ }, d = r ? e.from("tax_rates").update(m).eq("id", r) : e.from("tax_rates").insert(m), { error: u } = await d;
43
+ if (u)
44
+ throw new Error(u.message);
45
+ s("/cms/settings/taxes");
46
+ }
47
+ async function q(t) {
48
+ const e = await c(), { error: r } = await e.from("tax_rates").delete().eq("id", t);
49
+ if (r)
50
+ throw new Error(r.message);
51
+ s("/cms/settings/taxes");
52
+ }
53
+ export {
54
+ q as deleteTaxRateAction,
55
+ T as saveTaxRateAction,
56
+ C as updateTaxSettingsAction
57
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),s=require("@nextblock-cms/ui"),u=require("react"),m=require("../../../../countries.cjs.js"),c=require("../../../../states.cjs.js"),S=require("../actions.cjs.js");function C({initialData:e,submitLabel:p="Save tax rate",compact:a=!1}){const l=m.normalizeCountryCode(e?.country_code)||"US",[d,h]=u.useState(l),[o,n]=u.useState(c.normalizeSubdivisionCode(l,e?.state_code)||e?.state_code||""),y=u.useMemo(()=>c.getStatesForCountry(d),[d]),j=c.countryUsesStructuredStates(d);return t.jsxs("form",{action:S.saveTaxRateAction,className:"space-y-4",children:[e?.id?t.jsx("input",{type:"hidden",name:"id",value:e.id}):null,t.jsxs("div",{className:a?"grid gap-4 md:grid-cols-4":"grid gap-4 md:grid-cols-2 xl:grid-cols-4",children:[t.jsxs("div",{className:"space-y-2",children:[t.jsx(s.Label,{htmlFor:e?.id?`country-${e.id}`:"tax-rate-country",children:"Country"}),t.jsx("select",{id:e?.id?`country-${e.id}`:"tax-rate-country",name:"country_code",value:d,onChange:r=>{const x=r.target.value,g=c.getStatesForCountry(x);h(x),n(g.some(v=>v.code===o)?o:"")},className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",children:m.countries.map(r=>t.jsx("option",{value:r.code,children:r.name},r.code))})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx(s.Label,{htmlFor:e?.id?`state-${e.id}`:"tax-rate-state",children:"State / Province"}),j?t.jsxs("select",{id:e?.id?`state-${e.id}`:"tax-rate-state",name:"state_code",value:o,onChange:r=>n(r.target.value),className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",children:[t.jsx("option",{value:"",children:"Country-wide / federal"}),y.map(r=>t.jsx("option",{value:r.code,children:r.name},r.code))]}):t.jsx(s.Input,{id:e?.id?`state-${e.id}`:"tax-rate-state",name:"state_code",value:o,onChange:r=>n(r.target.value),placeholder:"Optional"})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx(s.Label,{htmlFor:e?.id?`name-${e.id}`:"tax-rate-name",children:"Tax name"}),t.jsx(s.Input,{id:e?.id?`name-${e.id}`:"tax-rate-name",name:"tax_name",defaultValue:e?.tax_name||"",placeholder:"GST, PST, State Sales Tax",required:!0})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx(s.Label,{htmlFor:e?.id?`rate-${e.id}`:"tax-rate-rate",children:"Rate (%)"}),t.jsx(s.Input,{id:e?.id?`rate-${e.id}`:"tax-rate-rate",name:"tax_rate",type:"number",min:"0",max:"100",step:"0.0001",defaultValue:typeof e?.tax_rate=="number"?e.tax_rate.toString():"",placeholder:"5.0000",required:!0})]})]}),t.jsx("div",{className:"flex justify-end",children:t.jsx(s.Button,{type:"submit",size:a?"sm":"default",children:p})})]})}exports.TaxRateForm=C;
@@ -0,0 +1,100 @@
1
+ 'use client';
2
+ import { jsxs as t, jsx as r } from "react/jsx-runtime";
3
+ import { Label as c, Input as a, Button as S } from "@nextblock-cms/ui";
4
+ import { useState as p, useMemo as b } from "react";
5
+ import { normalizeCountryCode as i, countries as _ } from "../../../../countries.es.js";
6
+ import { normalizeSubdivisionCode as N, getStatesForCountry as x, countryUsesStructuredStates as $ } from "../../../../states.es.js";
7
+ import { saveTaxRateAction as F } from "../actions.es.js";
8
+ function q({
9
+ initialData: e,
10
+ submitLabel: h = "Save tax rate",
11
+ compact: u = !1
12
+ }) {
13
+ const m = i(e?.country_code) || "US", [o, y] = p(m), [s, n] = p(
14
+ N(m, e?.state_code) || e?.state_code || ""
15
+ ), f = b(() => x(o), [o]), v = $(o);
16
+ return /* @__PURE__ */ t("form", { action: F, className: "space-y-4", children: [
17
+ e?.id ? /* @__PURE__ */ r("input", { type: "hidden", name: "id", value: e.id }) : null,
18
+ /* @__PURE__ */ t("div", { className: u ? "grid gap-4 md:grid-cols-4" : "grid gap-4 md:grid-cols-2 xl:grid-cols-4", children: [
19
+ /* @__PURE__ */ t("div", { className: "space-y-2", children: [
20
+ /* @__PURE__ */ r(c, { htmlFor: e?.id ? `country-${e.id}` : "tax-rate-country", children: "Country" }),
21
+ /* @__PURE__ */ r(
22
+ "select",
23
+ {
24
+ id: e?.id ? `country-${e.id}` : "tax-rate-country",
25
+ name: "country_code",
26
+ value: o,
27
+ onChange: (d) => {
28
+ const l = d.target.value, g = x(l);
29
+ y(l), n(
30
+ g.some((C) => C.code === s) ? s : ""
31
+ );
32
+ },
33
+ className: "flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",
34
+ children: _.map((d) => /* @__PURE__ */ r("option", { value: d.code, children: d.name }, d.code))
35
+ }
36
+ )
37
+ ] }),
38
+ /* @__PURE__ */ t("div", { className: "space-y-2", children: [
39
+ /* @__PURE__ */ r(c, { htmlFor: e?.id ? `state-${e.id}` : "tax-rate-state", children: "State / Province" }),
40
+ v ? /* @__PURE__ */ t(
41
+ "select",
42
+ {
43
+ id: e?.id ? `state-${e.id}` : "tax-rate-state",
44
+ name: "state_code",
45
+ value: s,
46
+ onChange: (d) => n(d.target.value),
47
+ className: "flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",
48
+ children: [
49
+ /* @__PURE__ */ r("option", { value: "", children: "Country-wide / federal" }),
50
+ f.map((d) => /* @__PURE__ */ r("option", { value: d.code, children: d.name }, d.code))
51
+ ]
52
+ }
53
+ ) : /* @__PURE__ */ r(
54
+ a,
55
+ {
56
+ id: e?.id ? `state-${e.id}` : "tax-rate-state",
57
+ name: "state_code",
58
+ value: s,
59
+ onChange: (d) => n(d.target.value),
60
+ placeholder: "Optional"
61
+ }
62
+ )
63
+ ] }),
64
+ /* @__PURE__ */ t("div", { className: "space-y-2", children: [
65
+ /* @__PURE__ */ r(c, { htmlFor: e?.id ? `name-${e.id}` : "tax-rate-name", children: "Tax name" }),
66
+ /* @__PURE__ */ r(
67
+ a,
68
+ {
69
+ id: e?.id ? `name-${e.id}` : "tax-rate-name",
70
+ name: "tax_name",
71
+ defaultValue: e?.tax_name || "",
72
+ placeholder: "GST, PST, State Sales Tax",
73
+ required: !0
74
+ }
75
+ )
76
+ ] }),
77
+ /* @__PURE__ */ t("div", { className: "space-y-2", children: [
78
+ /* @__PURE__ */ r(c, { htmlFor: e?.id ? `rate-${e.id}` : "tax-rate-rate", children: "Rate (%)" }),
79
+ /* @__PURE__ */ r(
80
+ a,
81
+ {
82
+ id: e?.id ? `rate-${e.id}` : "tax-rate-rate",
83
+ name: "tax_rate",
84
+ type: "number",
85
+ min: "0",
86
+ max: "100",
87
+ step: "0.0001",
88
+ defaultValue: typeof e?.tax_rate == "number" ? e.tax_rate.toString() : "",
89
+ placeholder: "5.0000",
90
+ required: !0
91
+ }
92
+ )
93
+ ] })
94
+ ] }),
95
+ /* @__PURE__ */ r("div", { className: "flex justify-end", children: /* @__PURE__ */ r(S, { type: "submit", size: u ? "sm" : "default", children: h }) })
96
+ ] });
97
+ }
98
+ export {
99
+ q as TaxRateForm
100
+ };
@@ -0,0 +1,237 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const F=require("@nextblock-cms/utils/server"),P=require("./shared-inventory.cjs.js"),b=require("@nextblock-cms/utils"),g=e=>Math.round(e*100);function y(e){return Object.entries(e||{}).reduce((t,[r,i])=>(typeof i=="number"&&Number.isFinite(i)&&i>=0&&(t[b.normalizeCurrencyCode(r)]=g(i)),t),{})}function E(e){return(e||[]).map(t=>({id:t.id,sku:t.sku,upc:t.upc??null,price:g(t.price),sale_price:typeof t.sale_price=="number"&&!isNaN(t.sale_price)?g(t.sale_price):null,prices:y(t.prices),sale_prices:y(t.sale_prices),sale_start_at:t.sale_start_at??null,sale_end_at:t.sale_end_at??null,stock_quantity:t.stock_quantity,main_media_id:t.main_media_id??null,attribute_term_ids:t.attribute_term_ids}))}function j(e,t){const i=e.product_type==="digital"&&e.payment_provider==="freemius"?Math.max(0,Number(e.trial_period_days??0)):0;return{id:t,product_type:e.product_type,payment_provider:e.payment_provider,title:e.title,slug:e.slug,sku:e.sku,upc:e.upc??null,stock:e.stock,status:e.status,short_description:e.short_description??null,description_json:e.description_json??null,metadata:{},price:g(e.price),sale_price:typeof e.sale_price=="number"&&!isNaN(e.sale_price)?g(e.sale_price):null,prices:y(e.prices),sale_prices:y(e.sale_prices),sale_start_at:e.sale_start_at??null,sale_end_at:e.sale_end_at??null,freemius_plan_id:e.freemius_plan_id??null,freemius_product_id:e.freemius_product_id??null,trial_period_days:i,trial_requires_payment_method:i>0?e.trial_requires_payment_method??!1:!1,is_taxable:e.is_taxable,language_id:e.language_id,translation_group_id:e.translation_group_id||void 0,variants:E(e.variants)}}async function S(e,t,r){const{error:i}=await e.from("products").update({is_taxable:r,updated_at:new Date().toISOString()}).eq("id",t);if(i)throw i}async function x(e,t,r){const i=new Date().toISOString(),{data:c}=await e.from("products").select("sku, sale_price, sale_prices").eq("id",t).maybeSingle(),s=c?.sku??r.sku,{data:a}=await e.from("products").select("id").eq("sku",s),d=(a??[]).map(o=>o.id);d.length===0&&d.push(t);const{error:n}=await e.from("products").update({sale_price:c?.sale_price??null,sale_prices:c?.sale_prices??null,sale_start_at:r.sale_start_at??null,sale_end_at:r.sale_end_at??null,updated_at:i}).in("id",d);if(n)throw n;const _=r.variants??[];if(_.length===0)return;const{data:l}=await e.from("product_variants").select("sku, sale_price, sale_prices").eq("product_id",t),u=new Map((l??[]).map(o=>[o.sku,o]));for(const o of _){const p=u.get(o.sku);if(!p)continue;const{error:m}=await e.from("product_variants").update({sale_price:p.sale_price??null,sale_prices:p.sale_prices??null,sale_start_at:o.sale_start_at??null,sale_end_at:o.sale_end_at??null,updated_at:i}).eq("sku",o.sku).in("product_id",d);if(m)throw m}}async function C(e,{page:t=1,limit:r=10,search:i="",languageId:c,categoryId:s}={}){const a=(t-1)*r,d=a+r-1;let n=e.from("products").select("id, title, sku, upc, price, prices, sale_price, sale_prices, sale_start_at, sale_end_at, scheduled_price, scheduled_prices, scheduled_price_at, is_taxable, product_type, payment_provider, short_description, stock, status, slug, language_id, translation_group_id, freemius_product_id, freemius_plan_id, trial_period_days, trial_requires_payment_method, product_media(media(file_path, object_key)), product_variants(id, price, prices, sale_price, sale_prices, sale_start_at, sale_end_at, scheduled_price, scheduled_prices, scheduled_price_at), freemius_plans(id, name, title, freemius_pricing(id, license_quota, api_monthly_price, api_annual_price, api_lifetime_price, override_monthly_price, override_annual_price, override_lifetime_price, is_active)), product_categories(category:categories(id, name, slug, description, name_translations, description_translations))",{count:"exact"}).range(a,d).order("created_at",{ascending:!1});if(c&&(n=n.eq("language_id",c)),s){const{data:_,error:l}=await e.from("product_categories").select("product_id").eq("category_id",s);if(l)return{data:[],error:l,count:0};const u=(_||[]).map(o=>o.product_id).filter(Boolean);if(u.length===0)return{data:[],error:null,count:0};n=n.in("id",u)}return i&&(n=n.or(`title.ilike.%${i}%,sku.ilike.%${i}%`)),n}async function M(e,t){return e.from("products").select(`
2
+ *,
3
+ languages (
4
+ code
5
+ ),
6
+ product_media (
7
+ media_id,
8
+ sort_order,
9
+ media (
10
+ id,
11
+ file_path,
12
+ object_key,
13
+ file_name,
14
+ blur_data_url,
15
+ width,
16
+ height
17
+ )
18
+ ),
19
+ product_variants (
20
+ id,
21
+ sku,
22
+ upc,
23
+ main_media_id,
24
+ price,
25
+ prices,
26
+ sale_price,
27
+ sale_prices,
28
+ sale_start_at,
29
+ sale_end_at,
30
+ scheduled_price,
31
+ scheduled_prices,
32
+ scheduled_price_at,
33
+ stock_quantity,
34
+ media:main_media_id (
35
+ id,
36
+ file_path,
37
+ object_key,
38
+ description
39
+ ),
40
+ variant_attribute_mapping (
41
+ attribute_term_id,
42
+ product_attribute_terms (
43
+ id,
44
+ attribute_id,
45
+ value,
46
+ slug,
47
+ sort_order,
48
+ value_translations,
49
+ product_attributes (
50
+ id,
51
+ name,
52
+ slug,
53
+ name_translations
54
+ )
55
+ )
56
+ )
57
+ ),
58
+ freemius_plans (
59
+ id,
60
+ name,
61
+ title,
62
+ freemius_pricing (
63
+ id,
64
+ license_quota,
65
+ api_monthly_price,
66
+ api_annual_price,
67
+ api_lifetime_price,
68
+ override_monthly_price,
69
+ override_annual_price,
70
+ override_lifetime_price,
71
+ is_active
72
+ )
73
+ ),
74
+ product_categories (
75
+ category:categories (
76
+ id,
77
+ name,
78
+ slug,
79
+ description,
80
+ name_translations,
81
+ description_translations
82
+ )
83
+ )
84
+ `).eq("id",t).single()}async function T(e,t,r){const{data:i,error:c}=await e.from("products").select(`
85
+ *,
86
+ languages (
87
+ id,
88
+ code,
89
+ is_default
90
+ ),
91
+ product_media (
92
+ media_id,
93
+ sort_order,
94
+ media (
95
+ id,
96
+ file_path,
97
+ object_key,
98
+ file_name,
99
+ blur_data_url,
100
+ width,
101
+ height
102
+ )
103
+ ),
104
+ product_variants (
105
+ id,
106
+ sku,
107
+ upc,
108
+ main_media_id,
109
+ price,
110
+ prices,
111
+ sale_price,
112
+ sale_prices,
113
+ sale_start_at,
114
+ sale_end_at,
115
+ scheduled_price,
116
+ scheduled_prices,
117
+ scheduled_price_at,
118
+ stock_quantity,
119
+ media:main_media_id (
120
+ id,
121
+ file_path,
122
+ object_key,
123
+ description
124
+ ),
125
+ variant_attribute_mapping (
126
+ attribute_term_id,
127
+ product_attribute_terms (
128
+ id,
129
+ attribute_id,
130
+ value,
131
+ slug,
132
+ sort_order,
133
+ value_translations,
134
+ product_attributes (
135
+ id,
136
+ name,
137
+ slug,
138
+ name_translations
139
+ )
140
+ )
141
+ )
142
+ ),
143
+ freemius_plans (
144
+ id,
145
+ name,
146
+ title,
147
+ freemius_pricing (
148
+ id,
149
+ license_quota,
150
+ api_monthly_price,
151
+ api_annual_price,
152
+ api_lifetime_price,
153
+ override_monthly_price,
154
+ override_annual_price,
155
+ override_lifetime_price,
156
+ is_active
157
+ )
158
+ ),
159
+ product_categories (
160
+ category:categories (
161
+ id,
162
+ name,
163
+ slug,
164
+ description,
165
+ name_translations,
166
+ description_translations
167
+ )
168
+ )
169
+ `).eq("slug",t);if(c)return{data:null,error:c};if(!i||i.length===0)return{data:null,error:{message:"Product not found",code:"PGRST116"}};let s=null;return r&&(s=i.find(a=>(Array.isArray(a.languages)?a.languages[0]:a.languages)?.code===r)),s||(s=i.find(a=>(Array.isArray(a.languages)?a.languages[0]:a.languages)?.is_default)),s||(s=i.find(a=>(Array.isArray(a.languages)?a.languages[0]:a.languages)?.code==="en")),s||(s=i[0]),{data:s,error:null}}async function A(e,t){const{data:r,error:i}=await e.rpc("upsert_product_with_variants",{product_payload:j(t)});if(i||!r)throw i||new Error("Failed to create product");if(t.product_media&&t.product_media.length>0){const s=t.product_media.map((a,d)=>({product_id:r,media_id:a.media_id,sort_order:d}));await e.from("product_media").insert(s)}else t.media_id&&await e.from("product_media").insert({product_id:r,media_id:t.media_id,sort_order:0});await S(e,r,t.is_taxable),await x(e,r,t),await P.syncSharedInventoryForSavedProduct(r,t),t.category_ids!==void 0&&await q(e,r,t.category_ids);const{data:c}=await e.from("products").select("*").eq("id",r).single();return c}async function R(e,t,r){const{data:i}=await e.from("product_media").select("media_id").eq("product_id",t),c=i?.map(o=>o.media_id)||[],{data:s,error:a}=await e.rpc("upsert_product_with_variants",{product_payload:j(r,t)});if(a||!s)throw a||new Error("Failed to update product");if(r.product_media){if(await e.from("product_media").delete().eq("product_id",t),r.product_media.length>0){const o=r.product_media.map((p,m)=>({product_id:t,media_id:p.media_id,sort_order:m}));await e.from("product_media").insert(o)}}else r.media_id&&(await e.from("product_media").delete().eq("product_id",t),await e.from("product_media").insert({product_id:t,media_id:r.media_id,sort_order:0}));await S(e,s,r.is_taxable),await x(e,s,r);const d=r.product_media?r.product_media.map(o=>o.media_id):r.media_id?[r.media_id]:[],n=r.explicitly_removed_media_ids||[],_=c.filter(o=>!d.includes(o)),l=Array.from(new Set([..._,...n]));if(l.length>0)for(const o of l){const{count:p}=await e.from("product_media").select("*",{count:"exact",head:!0}).eq("media_id",o);if(p&&p>0)continue;const{count:m}=await e.from("posts").select("*",{count:"exact",head:!0}).eq("feature_image_id",o);if(m&&m>0)continue;const{count:h}=await e.from("logos").select("*",{count:"exact",head:!0}).eq("media_id",o);if(h&&h>0)continue;const{count:w}=await e.from("product_variants").select("*",{count:"exact",head:!0}).eq("main_media_id",o);if(w&&w>0)continue;const{data:f}=await e.from("media").select("object_key, variants").eq("id",o).single();if(f){const v=[f.object_key];f.variants&&Array.isArray(f.variants)&&f.variants.forEach(k=>{k.objectKey&&v.push(k.objectKey)}),await F.deleteMediaFiles(v),await e.from("media").delete().eq("id",o)}}await P.syncSharedInventoryForSavedProduct(s,r),r.category_ids!==void 0&&await q(e,t,r.category_ids);const{data:u}=await e.from("products").select("*").eq("id",s).single();return u}async function I(e,t){const{error:r}=await e.from("products").delete().eq("id",t);if(r)throw r;return!0}async function N(e,t,r){const{data:i,error:c}=await e.from("products").select("*").eq("id",r).single();if(c||!i)throw new Error(c?.message||"Source product not found");const{data:s,error:a}=await e.from("products").select("language_id").eq("id",t).single();if(a||!s)throw new Error(a?.message||"Target product not found");const{error:d}=await e.from("products").update({title:i.title,short_description:i.short_description,description_json:i.description_json}).eq("id",t);if(d)throw d;const{data:n,error:_}=await e.from("blocks").select("*").eq("product_id",r).order("order",{ascending:!0});if(_)throw _;if(await e.from("blocks").delete().eq("product_id",t),n&&n.length>0){const u=n.map(p=>{const{id:m,created_at:h,updated_at:w,...f}=p;return{...f,product_id:t,language_id:s.language_id}}),{error:o}=await e.from("blocks").insert(u);if(o)throw o}await e.from("product_drafts").delete().eq("product_id",t),await e.from("product_media").delete().eq("product_id",t);const{data:l}=await e.from("product_media").select("media_id, sort_order").eq("product_id",r);if(l&&l.length>0){const u=l.map(o=>({product_id:t,media_id:o.media_id,sort_order:o.sort_order}));await e.from("product_media").insert(u)}return{success:!0}}async function $(e,t,r,i=[],c=[]){const{data:s}=await e.from("languages").select("id").eq("code",r).single();if(!s)return{data:[],error:"Language not found"};const a=[];t.length>0&&a.push(`translation_group_id.in.(${t.join(",")})`),i.length>0&&a.push(`sku.in.(${i.map(_=>`"${_}"`).join(",")})`),c.length>0&&a.push(`id.in.(${c.join(",")})`);let d=e.from("products").select(`
170
+ id,
171
+ title,
172
+ sku,
173
+ price,
174
+ prices,
175
+ sale_price,
176
+ sale_prices,
177
+ sale_start_at,
178
+ sale_end_at,
179
+ scheduled_price,
180
+ scheduled_prices,
181
+ scheduled_price_at,
182
+ stock,
183
+ slug,
184
+ language_id,
185
+ product_type,
186
+ payment_provider,
187
+ freemius_product_id,
188
+ freemius_plan_id,
189
+ trial_period_days,
190
+ trial_requires_payment_method,
191
+ is_taxable,
192
+ product_media (
193
+ media (
194
+ file_path,
195
+ object_key
196
+ )
197
+ ),
198
+ product_variants (
199
+ id,
200
+ sku,
201
+ upc,
202
+ main_media_id,
203
+ price,
204
+ prices,
205
+ sale_price,
206
+ sale_prices,
207
+ sale_start_at,
208
+ sale_end_at,
209
+ scheduled_price,
210
+ scheduled_prices,
211
+ scheduled_price_at,
212
+ stock_quantity,
213
+ media:main_media_id (
214
+ file_path,
215
+ object_key,
216
+ description
217
+ ),
218
+ variant_attribute_mapping (
219
+ attribute_term_id,
220
+ product_attribute_terms (
221
+ id,
222
+ attribute_id,
223
+ value,
224
+ slug,
225
+ sort_order,
226
+ value_translations,
227
+ product_attributes (
228
+ id,
229
+ name,
230
+ slug,
231
+ name_translations
232
+ )
233
+ )
234
+ )
235
+ ),
236
+ translation_group_id
237
+ `).eq("language_id",s.id).eq("status","active");return a.length>0&&(d=d.or(a.join(","))),await d.order("id")}async function q(e,t,r){const{data:i}=await e.from("products").select("translation_group_id").eq("id",t).single();if(!i||!i.translation_group_id){if(await e.from("product_categories").delete().eq("product_id",t),r.length>0){const a=r.map(d=>({product_id:t,category_id:d}));await e.from("product_categories").insert(a)}return}const{data:c}=await e.from("products").select("id").eq("translation_group_id",i.translation_group_id),s=c&&c.length>0?c.map(a=>a.id):[t];if(await e.from("product_categories").delete().in("product_id",s),r.length>0){const a=[];for(const d of s)for(const n of r)a.push({product_id:d,category_id:n});await e.from("product_categories").insert(a)}}exports.copyProductFromLanguage=N;exports.createProduct=A;exports.deleteProduct=I;exports.fetchTranslatedProductsForCartInternal=$;exports.getProduct=M;exports.getProductBySlug=T;exports.getProducts=C;exports.syncCategoriesForTranslationGroup=q;exports.updateProduct=R;