@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.
- package/index.cjs.js +1 -1
- package/index.es.js +136 -533
- package/lib/CurrencyProvider.cjs.js +1 -0
- package/lib/CurrencyProvider.es.js +99 -0
- package/lib/cart-store.cjs.js +1 -0
- package/{cart-store.es.js → lib/cart-store.es.js} +13 -13
- package/lib/components/AccountNavigationMenu.cjs.js +1 -0
- package/lib/components/AccountNavigationMenu.es.js +44 -0
- package/lib/components/AddToCartButton.cjs.js +1 -0
- package/{AddToCartButton-ffE0DhHu.js → lib/components/AddToCartButton.es.js} +14 -13
- package/lib/components/Cart.cjs.js +1 -0
- package/lib/components/Cart.es.js +148 -0
- package/lib/components/CartDrawer.cjs.js +1 -0
- package/{components → lib/components}/CartDrawer.es.js +15 -14
- package/{components → lib/components}/CartIcon.cjs.js +1 -1
- package/{components → lib/components}/CartIcon.es.js +1 -0
- package/lib/components/Checkout.cjs.js +1 -0
- package/{components → lib/components}/Checkout.es.js +330 -363
- package/lib/components/CouponForm.cjs.js +1 -0
- package/lib/components/CouponForm.es.js +136 -0
- package/lib/components/CurrencySwitcher.cjs.js +1 -0
- package/{components → lib/components}/CurrencySwitcher.es.js +5 -4
- package/lib/components/CustomerProfileForm.cjs.js +1 -0
- package/lib/components/CustomerProfileForm.es.js +355 -0
- package/lib/components/FeaturedProduct.cjs.js +1 -0
- package/{components → lib/components}/FeaturedProduct.es.js +9 -8
- package/lib/components/InvoiceDocument.cjs.js +1 -0
- package/lib/components/InvoiceDocument.es.js +196 -0
- package/lib/components/InvoiceViewerShell.cjs.js +29 -0
- package/lib/components/InvoiceViewerShell.es.js +100 -0
- package/lib/components/ProductCard.cjs.js +1 -0
- package/lib/components/ProductCard.es.js +119 -0
- package/lib/components/ProductDetailsLayout.cjs.js +1 -0
- package/lib/components/ProductDetailsLayout.es.js +361 -0
- package/lib/components/ProductGallery.cjs.js +1 -0
- package/lib/components/ProductGallery.es.js +41 -0
- package/lib/components/ProductGrid.cjs.js +1 -0
- package/lib/components/ProductGrid.es.js +19 -0
- package/lib/components/ShippingEstimator.cjs.js +1 -0
- package/lib/components/ShippingEstimator.es.js +125 -0
- package/lib/components/SubscriptionSelector.cjs.js +1 -0
- package/lib/components/SubscriptionSelector.es.js +140 -0
- package/lib/countries.cjs.js +1 -0
- package/lib/countries.es.js +77 -0
- package/lib/coupon-server.cjs.js +1 -0
- package/{coupon-server-DUKVtyYs.js → lib/coupon-server.es.js} +68 -82
- package/lib/coupons.cjs.js +1 -0
- package/lib/coupons.es.js +17 -0
- package/lib/currency-store.cjs.js +1 -0
- package/lib/currency-store.es.js +27 -0
- package/lib/currency-sync.cjs.js +1 -0
- package/lib/currency-sync.es.js +180 -0
- package/lib/customer-addresses.cjs.js +1 -0
- package/lib/customer-addresses.es.js +116 -0
- package/lib/customer-orders.cjs.js +1 -0
- package/lib/customer-orders.es.js +45 -0
- package/lib/customer.cjs.js +1 -0
- package/{customer-C3xccjUg.js → lib/customer.es.js} +15 -14
- package/lib/export-helpers.cjs.js +1 -0
- package/lib/export-helpers.es.js +56 -0
- package/lib/factory.cjs.js +1 -0
- package/lib/factory.es.js +8 -0
- package/lib/freemius-coupons.cjs.js +1 -0
- package/lib/freemius-coupons.es.js +272 -0
- package/lib/freemius-order-sync.cjs.js +1 -0
- package/lib/freemius-order-sync.es.js +284 -0
- package/lib/inventory-settings.cjs.js +1 -0
- package/lib/inventory-settings.es.js +86 -0
- package/lib/invoice-server.cjs.js +33 -0
- package/lib/invoice-server.es.js +141 -0
- package/lib/invoice-ui.cjs.js +1 -0
- package/lib/invoice-ui.es.js +71 -0
- package/lib/invoice.cjs.js +1 -0
- package/lib/invoice.es.js +102 -0
- package/lib/order-inventory.cjs.js +61 -0
- package/lib/order-inventory.es.js +128 -0
- package/lib/order-tax-details.cjs.js +1 -0
- package/lib/order-tax-details.es.js +164 -0
- package/lib/pages/cms/coupons/CouponEditorForm.cjs.js +1 -0
- package/lib/pages/cms/coupons/CouponEditorForm.es.js +189 -0
- package/lib/pages/cms/coupons/CouponsPage.cjs.js +5 -0
- package/lib/pages/cms/coupons/CouponsPage.es.js +171 -0
- package/lib/pages/cms/coupons/CreateCouponDialog.cjs.js +1 -0
- package/lib/pages/cms/coupons/CreateCouponDialog.es.js +35 -0
- package/lib/pages/cms/coupons/EditCouponPage.cjs.js +1 -0
- package/lib/pages/cms/coupons/EditCouponPage.es.js +48 -0
- package/lib/pages/cms/coupons/ProductScopePicker.cjs.js +1 -0
- package/lib/pages/cms/coupons/ProductScopePicker.es.js +120 -0
- package/lib/pages/cms/coupons/actions.cjs.js +1 -0
- package/lib/pages/cms/coupons/actions.es.js +128 -0
- package/lib/pages/cms/coupons/product-options.cjs.js +1 -0
- package/lib/pages/cms/coupons/product-options.es.js +27 -0
- package/lib/pages/cms/orders/ExportReportsDialog.cjs.js +1 -0
- package/lib/pages/cms/orders/ExportReportsDialog.es.js +130 -0
- package/lib/pages/cms/orders/OrderDetailPage.cjs.js +1 -0
- package/lib/pages/cms/orders/OrderDetailPage.es.js +137 -0
- package/lib/pages/cms/orders/OrderPrintButton.cjs.js +1 -0
- package/lib/pages/cms/orders/OrderPrintButton.es.js +22 -0
- package/lib/pages/cms/orders/OrderStatusForm.cjs.js +1 -0
- package/lib/pages/cms/orders/OrderStatusForm.es.js +71 -0
- package/lib/pages/cms/orders/OrdersPage.cjs.js +1 -0
- package/lib/pages/cms/orders/OrdersPage.es.js +104 -0
- package/lib/pages/cms/orders/actions.cjs.js +7 -0
- package/lib/pages/cms/orders/actions.es.js +71 -0
- package/lib/pages/cms/orders/export-actions.cjs.js +1 -0
- package/lib/pages/cms/orders/export-actions.es.js +27 -0
- package/lib/pages/cms/orders/server-actions.cjs.js +1 -0
- package/lib/pages/cms/orders/server-actions.es.js +55 -0
- package/lib/pages/cms/payments/PaymentsClient.cjs.js +1 -0
- package/lib/pages/cms/payments/PaymentsClient.es.js +188 -0
- package/lib/pages/cms/payments/PaymentsPage.cjs.js +1 -0
- package/lib/pages/cms/payments/PaymentsPage.es.js +29 -0
- package/lib/pages/cms/payments/actions.cjs.js +1 -0
- package/lib/pages/cms/payments/actions.es.js +23 -0
- package/lib/pages/cms/payments/queries.cjs.js +1 -0
- package/lib/pages/cms/payments/queries.es.js +30 -0
- package/lib/pages/cms/products/ProductsPage.cjs.js +1 -0
- package/lib/pages/cms/products/ProductsPage.es.js +46 -0
- package/lib/pages/cms/products/_id_/edit/EditProductPage.cjs.js +1 -0
- package/lib/pages/cms/products/_id_/edit/EditProductPage.es.js +156 -0
- package/lib/pages/cms/products/actions.cjs.js +44 -0
- package/lib/pages/cms/products/actions.es.js +175 -0
- package/lib/pages/cms/products/attributes/AttributeManagementPage.cjs.js +1 -0
- package/lib/pages/cms/products/attributes/AttributeManagementPage.es.js +48 -0
- package/lib/pages/cms/products/attributes/components/AttributeManager.cjs.js +1 -0
- package/lib/pages/cms/products/attributes/components/AttributeManager.es.js +291 -0
- package/lib/pages/cms/products/categories/CategoryManagementPage.cjs.js +1 -0
- package/lib/pages/cms/products/categories/CategoryManagementPage.es.js +36 -0
- package/lib/pages/cms/products/categories/components/CategoryManager.cjs.js +1 -0
- package/lib/pages/cms/products/categories/components/CategoryManager.es.js +263 -0
- package/lib/pages/cms/products/components/CopyProductFromLanguage.cjs.js +1 -0
- package/lib/pages/cms/products/components/CopyProductFromLanguage.es.js +114 -0
- package/lib/pages/cms/products/components/CurrencyPriceFields.cjs.js +1 -0
- package/lib/pages/cms/products/components/CurrencyPriceFields.es.js +107 -0
- package/lib/pages/cms/products/components/DeleteProductButton.cjs.js +1 -0
- package/lib/pages/cms/products/components/DeleteProductButton.es.js +48 -0
- package/lib/pages/cms/products/components/FreemiusPricingDashboard.cjs.js +1 -0
- package/lib/pages/cms/products/components/FreemiusPricingDashboard.es.js +86 -0
- package/lib/pages/cms/products/components/ProductCategorySelector.cjs.js +1 -0
- package/lib/pages/cms/products/components/ProductCategorySelector.es.js +160 -0
- package/lib/pages/cms/products/components/ProductForm.cjs.js +1 -0
- package/lib/pages/cms/products/components/ProductForm.es.js +702 -0
- package/lib/pages/cms/products/components/ProductMediaManager.cjs.js +1 -0
- package/lib/pages/cms/products/components/ProductMediaManager.es.js +104 -0
- package/lib/pages/cms/products/components/ProductsBulkTable.cjs.js +1 -0
- package/lib/pages/cms/products/components/ProductsBulkTable.es.js +228 -0
- package/lib/pages/cms/products/components/SaleScheduleFields.cjs.js +1 -0
- package/lib/pages/cms/products/components/SaleScheduleFields.es.js +137 -0
- package/lib/pages/cms/products/components/SyncFreemiusButton.cjs.js +1 -0
- package/lib/pages/cms/products/components/SyncFreemiusButton.es.js +36 -0
- package/lib/pages/cms/products/components/SyncFreemiusPricingButton.cjs.js +1 -0
- package/lib/pages/cms/products/components/SyncFreemiusPricingButton.es.js +40 -0
- package/lib/pages/cms/products/components/VariationsEditor.cjs.js +1 -0
- package/lib/pages/cms/products/components/VariationsEditor.es.js +408 -0
- package/lib/pages/cms/products/inventory/InventoryPage.cjs.js +1 -0
- package/lib/pages/cms/products/inventory/InventoryPage.es.js +16 -0
- package/lib/pages/cms/products/inventory/InventoryTableClient.cjs.js +2 -0
- package/lib/pages/cms/products/inventory/InventoryTableClient.es.js +214 -0
- package/lib/pages/cms/products/inventory/actions.cjs.js +3 -0
- package/lib/pages/cms/products/inventory/actions.es.js +95 -0
- package/lib/pages/cms/products/new/NewProductPage.cjs.js +1 -0
- package/lib/pages/cms/products/new/NewProductPage.es.js +76 -0
- package/lib/pages/cms/products/product-price-sync.cjs.js +1 -0
- package/lib/pages/cms/products/product-price-sync.es.js +98 -0
- package/lib/pages/cms/products/server-actions.cjs.js +1 -0
- package/lib/pages/cms/products/server-actions.es.js +193 -0
- package/lib/pages/cms/shipping/ShippingPage.cjs.js +5 -0
- package/lib/pages/cms/shipping/ShippingPage.es.js +211 -0
- package/lib/pages/cms/shipping/components/RateForm.cjs.js +1 -0
- package/lib/pages/cms/shipping/components/RateForm.es.js +441 -0
- package/lib/pages/cms/shipping/components/ZoneForm.cjs.js +1 -0
- package/lib/pages/cms/shipping/components/ZoneForm.es.js +228 -0
- package/lib/pages/cms/shipping/server-actions.cjs.js +1 -0
- package/lib/pages/cms/shipping/server-actions.es.js +159 -0
- package/lib/pages/cms/taxes/TaxesPage.cjs.js +1 -0
- package/lib/pages/cms/taxes/TaxesPage.es.js +172 -0
- package/lib/pages/cms/taxes/actions.cjs.js +1 -0
- package/lib/pages/cms/taxes/actions.es.js +57 -0
- package/lib/pages/cms/taxes/components/TaxRateForm.cjs.js +1 -0
- package/lib/pages/cms/taxes/components/TaxRateForm.es.js +100 -0
- package/lib/product-actions.cjs.js +237 -0
- package/lib/product-actions.es.js +524 -0
- package/lib/product-context.cjs.js +1 -0
- package/lib/product-context.es.js +16 -0
- package/lib/product-schema.cjs.js +1 -0
- package/lib/product-schema.es.js +134 -0
- package/lib/providers/freemius.cjs.js +5 -0
- package/lib/providers/freemius.es.js +538 -0
- package/lib/providers/stripe.cjs.js +1 -0
- package/lib/providers/stripe.es.js +473 -0
- package/lib/server-actions/coupon-actions.cjs.js +1 -0
- package/lib/server-actions/coupon-actions.es.js +23 -0
- package/lib/server-actions/customer-actions.cjs.js +1 -0
- package/lib/server-actions/customer-actions.es.js +30 -0
- package/lib/server-actions/product-actions.cjs.js +1 -0
- package/{server-actions → lib/server-actions}/product-actions.es.js +5 -4
- package/lib/server-actions/shipping-actions.cjs.js +1 -0
- package/{shipping-actions-BnHjlo2q.js → lib/server-actions/shipping-actions.es.js} +9 -7
- package/lib/server-actions/tax-actions.cjs.js +1 -0
- package/lib/server-actions/tax-actions.es.js +40 -0
- package/lib/shared-inventory.cjs.js +15 -0
- package/lib/shared-inventory.es.js +171 -0
- package/lib/shipping/resolver.cjs.js +7 -0
- package/lib/shipping/resolver.es.js +62 -0
- package/lib/shipping-rate-currency.cjs.js +1 -0
- package/lib/shipping-rate-currency.es.js +72 -0
- package/lib/states.cjs.js +1 -0
- package/{states-DlHJezQ1.js → lib/states.es.js} +27 -100
- package/lib/stripe/checkout.cjs.js +1 -0
- package/lib/stripe/checkout.es.js +182 -0
- package/lib/stripe/client.cjs.js +1 -0
- package/lib/stripe/client.es.js +7 -0
- package/lib/stripe/order-sync.cjs.js +1 -0
- package/lib/stripe/order-sync.es.js +130 -0
- package/lib/stripe/webhooks.cjs.js +1 -0
- package/lib/stripe/webhooks.es.js +30 -0
- package/lib/tax-calculation.cjs.js +1 -0
- package/lib/tax-calculation.es.js +101 -0
- package/lib/trials.cjs.js +1 -0
- package/{trials-RDcRAZKx.js → lib/trials.es.js} +9 -9
- package/{use-cart.es.js → lib/use-cart.es.js} +1 -0
- package/lib/zod-config.cjs.js +1 -0
- package/lib/zod-config.es.js +6 -0
- package/package.json +4 -4
- package/server.cjs.js +1 -110
- package/server.es.js +178 -6052
- package/AddToCartButton-DsSEH9yp.cjs +0 -1
- package/CouponForm-BI_5SBHQ.js +0 -152
- package/CouponForm-D_uu2bLP.cjs +0 -1
- package/CurrencyProvider-Cg-Q6ucj.cjs +0 -1
- package/CurrencyProvider-OzlRN96V.js +0 -120
- package/CurrencyProvider.cjs.js +0 -1
- package/CurrencyProvider.es.js +0 -10
- package/ProductDetailsLayout-BxJH_BxR.cjs +0 -1
- package/ProductDetailsLayout-Dg8dRTYp.js +0 -530
- package/ProductGrid-BdL7iglO.cjs +0 -1
- package/ProductGrid-D3AWM8sr.js +0 -130
- package/actions-AHmBrS5e.cjs +0 -48
- package/actions-j5fuSZX-.js +0 -820
- package/cart-store.cjs.js +0 -1
- package/components/Cart.cjs.js +0 -1
- package/components/Cart.es.js +0 -259
- package/components/CartDrawer.cjs.js +0 -1
- package/components/Checkout.cjs.js +0 -1
- package/components/CurrencySwitcher.cjs.js +0 -1
- package/components/FeaturedProduct.cjs.js +0 -1
- package/components/ProductDetailsLayout.cjs.js +0 -1
- package/components/ProductDetailsLayout.es.js +0 -19
- package/components/ProductGrid.cjs.js +0 -1
- package/components/ProductGrid.es.js +0 -6
- package/coupon-server-C9ySm3I5.cjs +0 -1
- package/customer-C-UPvrYN.cjs +0 -1
- package/invoice-ui-CAnJPu6n.cjs +0 -29
- package/invoice-ui-DtpbTJE1.js +0 -2886
- package/product-actions-CONBF8i6.cjs +0 -251
- package/product-actions-DjlIWCMH.js +0 -691
- package/resolver-Fz_FKsfX.cjs +0 -7
- package/resolver-cfrCaHpE.js +0 -128
- package/server-actions/product-actions.cjs.js +0 -1
- package/shipping-actions-D6zt20gg.cjs +0 -1
- package/states-CWYRxV4B.cjs +0 -1
- package/tax-calculation-Dab89aHd.js +0 -181
- package/tax-calculation-MkDKOEkL.cjs +0 -1
- package/trials-DvZaOtNy.cjs +0 -1
- /package/{components → lib/components}/SimpleTiptapRenderer.cjs.js +0 -0
- /package/{components → lib/components}/SimpleTiptapRenderer.es.js +0 -0
- /package/{currency-constants.cjs.js → lib/currency-constants.cjs.js} +0 -0
- /package/{currency-constants.es.js → lib/currency-constants.es.js} +0 -0
- /package/{currency-rest-client-uolJxUkL.cjs → lib/currency-rest-client.cjs.js} +0 -0
- /package/{currency-rest-client-CwoqdgAP.js → lib/currency-rest-client.es.js} +0 -0
- /package/{currency.cjs.js → lib/currency.cjs.js} +0 -0
- /package/{currency.es.js → lib/currency.es.js} +0 -0
- /package/{types.cjs.js → lib/types.cjs.js} +0 -0
- /package/{types.es.js → lib/types.es.js} +0 -0
- /package/{use-cart.cjs.js → lib/use-cart.cjs.js} +0 -0
- /package/{variation-utils.cjs.js → lib/variation-utils.cjs.js} +0 -0
- /package/{variation-utils.es.js → lib/variation-utils.es.js} +0 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
'use server';
|
|
2
|
+
import { revalidatePath as u } from "next/cache";
|
|
3
|
+
import { getServiceRoleSupabaseClient as h } from "@nextblock-cms/db/server";
|
|
4
|
+
import { setSharedInventoryQuantity as p, getInventoryItems as y } from "../../../../shared-inventory.es.js";
|
|
5
|
+
function v(t) {
|
|
6
|
+
const e = [];
|
|
7
|
+
let o = [], r = "", c = !1;
|
|
8
|
+
for (let s = 0; s < t.length; s += 1) {
|
|
9
|
+
const n = t[s], i = t[s + 1];
|
|
10
|
+
if (n === '"') {
|
|
11
|
+
c && i === '"' ? (r += '"', s += 1) : c = !c;
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
if (n === "," && !c) {
|
|
15
|
+
o.push(r), r = "";
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
if ((n === `
|
|
19
|
+
` || n === "\r") && !c) {
|
|
20
|
+
n === "\r" && i === `
|
|
21
|
+
` && (s += 1), (r.length > 0 || o.length > 0) && (o.push(r), e.push(o)), o = [], r = "";
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
r += n;
|
|
25
|
+
}
|
|
26
|
+
return (r.length > 0 || o.length > 0) && (o.push(r), e.push(o)), e.filter((s) => s.some((n) => n.trim().length > 0));
|
|
27
|
+
}
|
|
28
|
+
function k(t) {
|
|
29
|
+
return t.sku;
|
|
30
|
+
}
|
|
31
|
+
async function C(t) {
|
|
32
|
+
try {
|
|
33
|
+
const e = Math.max(0, Math.trunc(t.stock));
|
|
34
|
+
return await p({
|
|
35
|
+
sku: t.sku,
|
|
36
|
+
stock: e
|
|
37
|
+
}), u("/cms/products"), u("/cms/products/inventory"), {
|
|
38
|
+
success: !0,
|
|
39
|
+
itemKey: k(t),
|
|
40
|
+
stock: e
|
|
41
|
+
};
|
|
42
|
+
} catch (e) {
|
|
43
|
+
return {
|
|
44
|
+
success: !1,
|
|
45
|
+
error: e instanceof Error ? e.message : "Failed to update inventory."
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async function x(t) {
|
|
50
|
+
try {
|
|
51
|
+
const e = v(t);
|
|
52
|
+
if (e.length < 2)
|
|
53
|
+
return { success: !1, error: "The CSV file is empty." };
|
|
54
|
+
const [o, ...r] = e, c = o.map((a) => a.trim().toLowerCase()), s = c.indexOf("sku"), n = c.indexOf("stock");
|
|
55
|
+
if (s === -1 || n === -1)
|
|
56
|
+
return {
|
|
57
|
+
success: !1,
|
|
58
|
+
error: "The CSV format is invalid. Please import a file exported from the Inventory page."
|
|
59
|
+
};
|
|
60
|
+
const i = h();
|
|
61
|
+
let m = 0;
|
|
62
|
+
for (const a of r) {
|
|
63
|
+
const f = (a[s] || "").trim(), l = Number.parseInt((a[n] || "").trim(), 10);
|
|
64
|
+
if (f) {
|
|
65
|
+
if (!Number.isFinite(l) || l < 0)
|
|
66
|
+
return {
|
|
67
|
+
success: !1,
|
|
68
|
+
error: `Invalid stock value for SKU "${f}".`
|
|
69
|
+
};
|
|
70
|
+
await p(
|
|
71
|
+
{
|
|
72
|
+
sku: f,
|
|
73
|
+
stock: l
|
|
74
|
+
},
|
|
75
|
+
i
|
|
76
|
+
), m += 1;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const d = await y(i);
|
|
80
|
+
return u("/cms/products"), u("/cms/products/inventory"), {
|
|
81
|
+
success: !0,
|
|
82
|
+
updatedCount: m,
|
|
83
|
+
items: d
|
|
84
|
+
};
|
|
85
|
+
} catch (e) {
|
|
86
|
+
return {
|
|
87
|
+
success: !1,
|
|
88
|
+
error: e instanceof Error ? e.message : "Failed to import inventory CSV."
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
export {
|
|
93
|
+
x as importInventoryCsvAction,
|
|
94
|
+
C as updateInventoryQuantityAction
|
|
95
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react/jsx-runtime"),v=require("../components/ProductForm.cjs.js"),y=require("../actions.cjs.js"),h=require("../../../../variation-utils.cjs.js"),x=require("../server-actions.cjs.js"),u=require("../../payments/queries.cjs.js"),R=require("@nextblock-cms/db/server"),a=require("@nextblock-cms/utils"),S=require("../../../../currency.cjs.js");async function w({mediaPickerNode:d,availableLanguagesProp:s,translationGroupId:l,targetLanguageId:o,initialData:t}){const[_,m,p,b]=await Promise.all([u.getEnabledPaymentProviders(),u.getStoreConfigStatus(),y.getGlobalProductAttributes(),R.getServiceRoleSupabaseClient().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}).then(e=>e.data||[])]),g=(b||[]).map(e=>S.normalizeCurrencyRecord(e)),f=(p||[]).map(e=>({id:e.id,name:e.name,name_translations:e.name_translations||{},slug:e.slug,terms:(e.product_attribute_terms||[]).map(r=>({...r,value_translations:r.value_translations||{}}))})),P=s.find(e=>e.id===t?.language_id)?.code||s.find(e=>e.id===(o?parseInt(o,10):void 0))?.code||s.find(e=>e.is_default)?.code,{attributes:q,variants:A}=h.mapRawVariantRelations(t?.product_variants||[],P),j=t&&{...t,variation_attributes:t.variation_attributes||q.map(e=>({attribute_id:e.id,term_ids:e.terms.map(r=>r.id)})),variants:t.variants||A.map(e=>({...e,upc:e.upc??null,price:e.price/100,prices:Object.entries(e.prices||{}).reduce((r,[i,n])=>(r[i]=a.minorUnitAmountToMajor(n,i),r),{}),sale_price:typeof e.sale_price=="number"?e.sale_price/100:null,sale_prices:Object.entries(e.sale_prices||{}).reduce((r,[i,n])=>(r[i]=typeof n=="number"?a.minorUnitAmountToMajor(n,i):null,r),{}),main_media_id:e.main_media_id??null,main_image_url:e.image_url??null}))};return c.jsx("div",{className:"p-8",children:c.jsx(v.ProductForm,{mediaPickerNode:d,availableLanguagesProp:s,globalAttributesProp:f,currenciesProp:g,translationGroupId:l,targetLanguageId:o,initialData:j,enabledProviders:_,configStatus:m,createAction:x.createProductAction})})}exports.NewProductPage=w;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { jsx as c } from "react/jsx-runtime";
|
|
2
|
+
import { ProductForm as x } from "../components/ProductForm.es.js";
|
|
3
|
+
import { getGlobalProductAttributes as R } from "../actions.es.js";
|
|
4
|
+
import { mapRawVariantRelations as y } from "../../../../variation-utils.es.js";
|
|
5
|
+
import { createProductAction as S } from "../server-actions.es.js";
|
|
6
|
+
import { getEnabledPaymentProviders as j, getStoreConfigStatus as v } from "../../payments/queries.es.js";
|
|
7
|
+
import { getServiceRoleSupabaseClient as w } from "@nextblock-cms/db/server";
|
|
8
|
+
import { minorUnitAmountToMajor as m } from "@nextblock-cms/utils";
|
|
9
|
+
import { normalizeCurrencyRecord as z } from "../../../../currency.es.js";
|
|
10
|
+
async function U({
|
|
11
|
+
mediaPickerNode: d,
|
|
12
|
+
availableLanguagesProp: i,
|
|
13
|
+
translationGroupId: a,
|
|
14
|
+
targetLanguageId: s,
|
|
15
|
+
initialData: t
|
|
16
|
+
}) {
|
|
17
|
+
const [u, _, l, p] = await Promise.all([
|
|
18
|
+
j(),
|
|
19
|
+
v(),
|
|
20
|
+
R(),
|
|
21
|
+
w().from("currencies").select(
|
|
22
|
+
"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"
|
|
23
|
+
).eq("is_active", !0).order("code", { ascending: !0 }).then((e) => e.data || [])
|
|
24
|
+
]), f = (p || []).map(
|
|
25
|
+
(e) => z(e)
|
|
26
|
+
), b = (l || []).map((e) => ({
|
|
27
|
+
id: e.id,
|
|
28
|
+
name: e.name,
|
|
29
|
+
name_translations: e.name_translations || {},
|
|
30
|
+
slug: e.slug,
|
|
31
|
+
terms: (e.product_attribute_terms || []).map((r) => ({
|
|
32
|
+
...r,
|
|
33
|
+
value_translations: r.value_translations || {}
|
|
34
|
+
}))
|
|
35
|
+
})), g = i.find((e) => e.id === t?.language_id)?.code || i.find((e) => e.id === (s ? parseInt(s, 10) : void 0))?.code || i.find((e) => e.is_default)?.code, { attributes: A, variants: P } = y(
|
|
36
|
+
t?.product_variants || [],
|
|
37
|
+
g
|
|
38
|
+
), h = t && {
|
|
39
|
+
...t,
|
|
40
|
+
variation_attributes: t.variation_attributes || A.map((e) => ({
|
|
41
|
+
attribute_id: e.id,
|
|
42
|
+
term_ids: e.terms.map((r) => r.id)
|
|
43
|
+
})),
|
|
44
|
+
variants: t.variants || P.map((e) => ({
|
|
45
|
+
...e,
|
|
46
|
+
upc: e.upc ?? null,
|
|
47
|
+
price: e.price / 100,
|
|
48
|
+
prices: Object.entries(e.prices || {}).reduce(
|
|
49
|
+
(r, [o, n]) => (r[o] = m(n, o), r),
|
|
50
|
+
{}
|
|
51
|
+
),
|
|
52
|
+
sale_price: typeof e.sale_price == "number" ? e.sale_price / 100 : null,
|
|
53
|
+
sale_prices: Object.entries(e.sale_prices || {}).reduce((r, [o, n]) => (r[o] = typeof n == "number" ? m(n, o) : null, r), {}),
|
|
54
|
+
main_media_id: e.main_media_id ?? null,
|
|
55
|
+
main_image_url: e.image_url ?? null
|
|
56
|
+
}))
|
|
57
|
+
};
|
|
58
|
+
return /* @__PURE__ */ c("div", { className: "p-8", children: /* @__PURE__ */ c(
|
|
59
|
+
x,
|
|
60
|
+
{
|
|
61
|
+
mediaPickerNode: d,
|
|
62
|
+
availableLanguagesProp: i,
|
|
63
|
+
globalAttributesProp: b,
|
|
64
|
+
currenciesProp: f,
|
|
65
|
+
translationGroupId: a,
|
|
66
|
+
targetLanguageId: s,
|
|
67
|
+
initialData: h,
|
|
68
|
+
enabledProviders: u,
|
|
69
|
+
configStatus: _,
|
|
70
|
+
createAction: S
|
|
71
|
+
}
|
|
72
|
+
) });
|
|
73
|
+
}
|
|
74
|
+
export {
|
|
75
|
+
U as NewProductPage
|
|
76
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@nextblock-cms/utils"),l=require("../../../currency.cjs.js");function p(r){return Object.entries(r||{}).reduce((e,[o,n])=>(typeof n=="number"&&Number.isFinite(n)&&n>=0?e[a.normalizeCurrencyCode(o)]=n:n===null&&(e[a.normalizeCurrencyCode(o)]=null),e),{})}function C(r){const e=l.normalizeCurrencyRecord(r);return e.is_default!==!0&&e.auto_sync_product_prices===!0}function z(r){return r.map(e=>l.normalizeCurrencyRecord(e)).filter(e=>C(e)).map(e=>e.code)}function f(r,e){const o=new Set(z(e)),n=p(r);return Object.entries(n).reduce((t,[i,u])=>(o.has(i)||(t[i]=u),t),{})}function g(r){const{baseAmount:e,defaultCurrencyCode:o,targetCurrencyCode:n,currencies:t}=r;if(typeof e!="number"||!Number.isFinite(e)||e<0)return null;const i=l.convertMinorUnitAmount({amount:a.majorUnitAmountToMinor(e,o),fromCurrencyCode:o,toCurrencyCode:n,currencies:t,applyRounding:!0});return a.minorUnitAmountToMajor(i,n)}function F(r){const{currencies:e,fallbackPrice:o,fallbackSalePrice:n}=r,t=p(r.prices),i=p(r.salePrices),u=e.find(s=>s.is_default)??e[0];if(!u)return{prices:t,salePrices:i};const d=a.normalizeCurrencyCode(u.code),m=t[d]??(typeof o=="number"?o:null),b=i[d]??(typeof n=="number"?n:null),S=e.reduce((s,y)=>{const c=l.normalizeCurrencyRecord(y);return C(c)?(s[c.code]=g({baseAmount:m,defaultCurrencyCode:d,targetCurrencyCode:c.code,currencies:e}),s):(s[c.code]=t[c.code]??(c.code===d?m:void 0),s)},{}),_=e.reduce((s,y)=>{const c=l.normalizeCurrencyRecord(y);return C(c)?(s[c.code]=g({baseAmount:b,defaultCurrencyCode:d,targetCurrencyCode:c.code,currencies:e}),s):(s[c.code]=i[c.code]??(c.code===d?b:void 0),s)},{});return{prices:S,salePrices:_}}function P(r,e){const o=e.find(u=>u.is_default)??e[0],n=o?a.normalizeCurrencyCode(o.code):"USD",t=f(r.prices,e),i=f(r.sale_prices,e);return{...r,price:typeof t[n]=="number"?t[n]:r.price,prices:t,sale_price:typeof i[n]=="number"?i[n]:r.sale_price??null,sale_prices:i}}function M(r,e){return r?.map(o=>P(o,e))||[]}function A(r,e){const o=e.find(u=>u.is_default)??e[0],n=o?a.normalizeCurrencyCode(o.code):"USD",t=f(r.prices,e),i=f(r.sale_prices,e);return{...r,price:typeof t[n]=="number"?t[n]:r.price,prices:t,sale_price:typeof i[n]=="number"?i[n]:r.sale_price??null,sale_prices:i,variants:M(r.variants,e)}}exports.getStoreManagedPriceCurrencyCodes=z;exports.isCurrencyStoreManagedPrice=C;exports.resolveEditorCurrencyPriceMaps=F;exports.sanitizeProductFormValuesForStoreManagedCurrencies=A;exports.sanitizeVariantDraftForStoreManagedCurrencies=P;exports.sanitizeVariantDraftsForStoreManagedCurrencies=M;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { normalizeCurrencyCode as l, majorUnitAmountToMinor as M, minorUnitAmountToMajor as z } from "@nextblock-cms/utils";
|
|
2
|
+
import { normalizeCurrencyRecord as a, convertMinorUnitAmount as S } from "../../../currency.es.js";
|
|
3
|
+
function C(r) {
|
|
4
|
+
return Object.entries(r || {}).reduce(
|
|
5
|
+
(e, [o, n]) => (typeof n == "number" && Number.isFinite(n) && n >= 0 ? e[l(o)] = n : n === null && (e[l(o)] = null), e),
|
|
6
|
+
{}
|
|
7
|
+
);
|
|
8
|
+
}
|
|
9
|
+
function y(r) {
|
|
10
|
+
const e = a(r);
|
|
11
|
+
return e.is_default !== !0 && e.auto_sync_product_prices === !0;
|
|
12
|
+
}
|
|
13
|
+
function A(r) {
|
|
14
|
+
return r.map((e) => a(e)).filter((e) => y(e)).map((e) => e.code);
|
|
15
|
+
}
|
|
16
|
+
function f(r, e) {
|
|
17
|
+
const o = new Set(A(e)), n = C(r);
|
|
18
|
+
return Object.entries(n).reduce(
|
|
19
|
+
(t, [i, u]) => (o.has(i) || (t[i] = u), t),
|
|
20
|
+
{}
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
function P(r) {
|
|
24
|
+
const { baseAmount: e, defaultCurrencyCode: o, targetCurrencyCode: n, currencies: t } = r;
|
|
25
|
+
if (typeof e != "number" || !Number.isFinite(e) || e < 0)
|
|
26
|
+
return null;
|
|
27
|
+
const i = S({
|
|
28
|
+
amount: M(e, o),
|
|
29
|
+
fromCurrencyCode: o,
|
|
30
|
+
toCurrencyCode: n,
|
|
31
|
+
currencies: t,
|
|
32
|
+
applyRounding: !0
|
|
33
|
+
});
|
|
34
|
+
return z(i, n);
|
|
35
|
+
}
|
|
36
|
+
function v(r) {
|
|
37
|
+
const { currencies: e, fallbackPrice: o, fallbackSalePrice: n } = r, t = C(r.prices), i = C(r.salePrices), u = e.find((s) => s.is_default) ?? e[0];
|
|
38
|
+
if (!u)
|
|
39
|
+
return {
|
|
40
|
+
prices: t,
|
|
41
|
+
salePrices: i
|
|
42
|
+
};
|
|
43
|
+
const d = l(u.code), m = t[d] ?? (typeof o == "number" ? o : null), b = i[d] ?? (typeof n == "number" ? n : null), _ = e.reduce((s, p) => {
|
|
44
|
+
const c = a(p);
|
|
45
|
+
return y(c) ? (s[c.code] = P({
|
|
46
|
+
baseAmount: m,
|
|
47
|
+
defaultCurrencyCode: d,
|
|
48
|
+
targetCurrencyCode: c.code,
|
|
49
|
+
currencies: e
|
|
50
|
+
}), s) : (s[c.code] = t[c.code] ?? (c.code === d ? m : void 0), s);
|
|
51
|
+
}, {}), g = e.reduce((s, p) => {
|
|
52
|
+
const c = a(p);
|
|
53
|
+
return y(c) ? (s[c.code] = P({
|
|
54
|
+
baseAmount: b,
|
|
55
|
+
defaultCurrencyCode: d,
|
|
56
|
+
targetCurrencyCode: c.code,
|
|
57
|
+
currencies: e
|
|
58
|
+
}), s) : (s[c.code] = i[c.code] ?? (c.code === d ? b : void 0), s);
|
|
59
|
+
}, {});
|
|
60
|
+
return {
|
|
61
|
+
prices: _,
|
|
62
|
+
salePrices: g
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function F(r, e) {
|
|
66
|
+
const o = e.find((u) => u.is_default) ?? e[0], n = o ? l(o.code) : "USD", t = f(r.prices, e), i = f(r.sale_prices, e);
|
|
67
|
+
return {
|
|
68
|
+
...r,
|
|
69
|
+
price: typeof t[n] == "number" ? t[n] : r.price,
|
|
70
|
+
prices: t,
|
|
71
|
+
sale_price: typeof i[n] == "number" ? i[n] : r.sale_price ?? null,
|
|
72
|
+
sale_prices: i
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function D(r, e) {
|
|
76
|
+
return r?.map(
|
|
77
|
+
(o) => F(o, e)
|
|
78
|
+
) || [];
|
|
79
|
+
}
|
|
80
|
+
function E(r, e) {
|
|
81
|
+
const o = e.find((u) => u.is_default) ?? e[0], n = o ? l(o.code) : "USD", t = f(r.prices, e), i = f(r.sale_prices, e);
|
|
82
|
+
return {
|
|
83
|
+
...r,
|
|
84
|
+
price: typeof t[n] == "number" ? t[n] : r.price,
|
|
85
|
+
prices: t,
|
|
86
|
+
sale_price: typeof i[n] == "number" ? i[n] : r.sale_price ?? null,
|
|
87
|
+
sale_prices: i,
|
|
88
|
+
variants: D(r.variants, e)
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
export {
|
|
92
|
+
A as getStoreManagedPriceCurrencyCodes,
|
|
93
|
+
y as isCurrencyStoreManagedPrice,
|
|
94
|
+
v as resolveEditorCurrencyPriceMaps,
|
|
95
|
+
E as sanitizeProductFormValuesForStoreManagedCurrencies,
|
|
96
|
+
F as sanitizeVariantDraftForStoreManagedCurrencies,
|
|
97
|
+
D as sanitizeVariantDraftsForStoreManagedCurrencies
|
|
98
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@nextblock-cms/db/server"),d=require("../../../product-actions.cjs.js"),g=require("../../../freemius-coupons.cjs.js"),l=require("../../../currency.cjs.js"),m=require("./product-price-sync.cjs.js"),a=require("next/cache"),_=require("next/navigation");function u(e){return e.toLowerCase().trim().replace(/\s+/g,"-").replace(/[^a-z0-9-]/g,"").replace(/-+/g,"-").replace(/^-|-$/g,"")}async function b(e){const t=o.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=m.sanitizeProductFormValuesForStoreManagedCurrencies(e,(r||[]).map(n=>l.normalizeCurrencyRecord(n))),c=await d.createProduct(t,s);if(s.payment_provider==="freemius"&&c?.id)try{await g.syncProductSaleCouponToFreemius({productId:c.id,client:o.getServiceRoleSupabaseClient()})}catch(n){console.error("Failed to sync Freemius sale coupon on create:",n)}a.revalidatePath("/cms/products"),_.redirect("/cms/products")}async function P(e,t){const r=o.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}),n=m.sanitizeProductFormValuesForStoreManagedCurrencies(t,(c||[]).map(f=>l.normalizeCurrencyRecord(f))),{error:i}=await r.from("product_drafts").upsert({product_id:e,author_id:s.id,meta:n,updated_at:new Date().toISOString()},{onConflict:"product_id"});if(i)throw new Error(`Failed to save product draft: ${i.message}`);return{success:!0}}async function v(e){const t=o.createClient();await d.deleteProduct(t,e),a.revalidatePath("/cms/products")}function p(e){return Array.from(new Set(e.map(t=>t.trim()).filter(Boolean)))}async function h(e){const t=p(e);if(t.length===0)return{success:!1,error:"Select at least one product."};const r=o.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 y(e){const t=p(e);if(t.length===0)return{success:!1,error:"Select at least one product."};const r=o.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 A(e){const t=o.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 S(e){const t=o.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 w(e){const t=o.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),n=typeof c?.[0]?.sort_order=="number"?c[0].sort_order+1:0,{error:i}=await t.from("product_attribute_terms").insert({attribute_id:e.attributeId,value:r,slug:s,sort_order:n});return i?{success:!1,error:i.message}:(a.revalidatePath("/cms/products/attributes"),a.revalidatePath("/cms/products/new"),a.revalidatePath("/cms/products"),{success:!0})}async function C(e){const t=o.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 q(e){const t=o.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 T(e){const t=o.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 I(e){const t=o.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:n}=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 n?{success:!1,error:n.message}:(a.revalidatePath("/cms/products/categories"),a.revalidatePath("/cms/products/new"),a.revalidatePath("/cms/products"),{success:!0,category:c})}async function R(e,t){const r=o.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:n}=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 n?{success:!1,error:n.message}:(a.revalidatePath("/cms/products/categories"),a.revalidatePath("/cms/products/new"),a.revalidatePath("/cms/products"),{success:!0})}async function x(e){const t=o.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 D(e,t){const r=o.getServiceRoleSupabaseClient();try{return await d.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=h;exports.bulkDraftProductsAction=y;exports.createCategoryAction=I;exports.createProductAction=b;exports.createProductAttributeAction=A;exports.createProductAttributeTermAction=w;exports.deleteCategoryAction=x;exports.deleteProductAction=v;exports.deleteProductAttributeAction=S;exports.deleteProductAttributeTermAction=T;exports.reorderProductAttributeTermsAction=C;exports.syncProductCategoriesAction=D;exports.updateCategoryAction=R;exports.updateProductAction=P;exports.updateProductAttributeTranslationsAction=q;
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
'use server';
|
|
2
|
+
import { getServiceRoleSupabaseClient as n, createClient as i } from "@nextblock-cms/db/server";
|
|
3
|
+
import { createProduct as _, deleteProduct as g, syncCategoriesForTranslationGroup as b } from "../../../product-actions.es.js";
|
|
4
|
+
import { syncProductSaleCouponToFreemius as w } from "../../../freemius-coupons.es.js";
|
|
5
|
+
import { normalizeCurrencyRecord as m } from "../../../currency.es.js";
|
|
6
|
+
import { sanitizeProductFormValuesForStoreManagedCurrencies as l } from "./product-price-sync.es.js";
|
|
7
|
+
import { revalidatePath as s } from "next/cache";
|
|
8
|
+
import { redirect as y } from "next/navigation";
|
|
9
|
+
function d(e) {
|
|
10
|
+
return e.toLowerCase().trim().replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
11
|
+
}
|
|
12
|
+
async function C(e) {
|
|
13
|
+
const r = i(), { data: t } = await r.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 }), c = l(
|
|
16
|
+
e,
|
|
17
|
+
(t || []).map((o) => m(o))
|
|
18
|
+
), a = await _(r, c);
|
|
19
|
+
if (c.payment_provider === "freemius" && a?.id)
|
|
20
|
+
try {
|
|
21
|
+
await w({
|
|
22
|
+
productId: a.id,
|
|
23
|
+
client: n()
|
|
24
|
+
});
|
|
25
|
+
} catch (o) {
|
|
26
|
+
console.error("Failed to sync Freemius sale coupon on create:", o);
|
|
27
|
+
}
|
|
28
|
+
s("/cms/products"), y("/cms/products");
|
|
29
|
+
}
|
|
30
|
+
async function I(e, r) {
|
|
31
|
+
const t = i(), { data: { user: c } } = await t.auth.getUser();
|
|
32
|
+
if (!c)
|
|
33
|
+
throw new Error("User not authenticated.");
|
|
34
|
+
const { data: a } = await t.from("currencies").select(
|
|
35
|
+
"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"
|
|
36
|
+
).eq("is_active", !0).order("code", { ascending: !0 }), o = l(
|
|
37
|
+
r,
|
|
38
|
+
(a || []).map((f) => m(f))
|
|
39
|
+
), { error: u } = await t.from("product_drafts").upsert(
|
|
40
|
+
{
|
|
41
|
+
product_id: e,
|
|
42
|
+
author_id: c.id,
|
|
43
|
+
meta: o,
|
|
44
|
+
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
45
|
+
},
|
|
46
|
+
{ onConflict: "product_id" }
|
|
47
|
+
);
|
|
48
|
+
if (u)
|
|
49
|
+
throw new Error(`Failed to save product draft: ${u.message}`);
|
|
50
|
+
return { success: !0 };
|
|
51
|
+
}
|
|
52
|
+
async function x(e) {
|
|
53
|
+
const r = i();
|
|
54
|
+
await g(r, e), s("/cms/products");
|
|
55
|
+
}
|
|
56
|
+
function p(e) {
|
|
57
|
+
return Array.from(
|
|
58
|
+
new Set(
|
|
59
|
+
e.map((r) => r.trim()).filter(Boolean)
|
|
60
|
+
)
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
async function D(e) {
|
|
64
|
+
const r = p(e);
|
|
65
|
+
if (r.length === 0)
|
|
66
|
+
return { success: !1, error: "Select at least one product." };
|
|
67
|
+
const t = i(), { error: c } = await t.from("products").delete().in("id", r);
|
|
68
|
+
return c ? { success: !1, error: c.message } : (s("/cms/products"), { success: !0, count: r.length });
|
|
69
|
+
}
|
|
70
|
+
async function F(e) {
|
|
71
|
+
const r = p(e);
|
|
72
|
+
if (r.length === 0)
|
|
73
|
+
return { success: !1, error: "Select at least one product." };
|
|
74
|
+
const t = i(), { error: c } = await t.from("products").update({
|
|
75
|
+
status: "draft",
|
|
76
|
+
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
77
|
+
}).in("id", r);
|
|
78
|
+
return c ? { success: !1, error: c.message } : (s("/cms/products"), { success: !0, count: r.length });
|
|
79
|
+
}
|
|
80
|
+
async function z(e) {
|
|
81
|
+
const r = n(), t = e.name.trim(), c = d(e.slug?.trim() || e.name);
|
|
82
|
+
if (!t || !c)
|
|
83
|
+
return { success: !1, error: "Attribute name is required." };
|
|
84
|
+
const { error: a } = await r.from("product_attributes").insert({
|
|
85
|
+
name: t,
|
|
86
|
+
slug: c
|
|
87
|
+
});
|
|
88
|
+
return a ? { success: !1, error: a.message } : (s("/cms/products/attributes"), s("/cms/products/new"), s("/cms/products"), { success: !0 });
|
|
89
|
+
}
|
|
90
|
+
async function O(e) {
|
|
91
|
+
const r = n(), { error: t } = await r.from("product_attributes").delete().eq("id", e);
|
|
92
|
+
return t ? { success: !1, error: t.message } : (s("/cms/products/attributes"), s("/cms/products/new"), s("/cms/products"), { success: !0 });
|
|
93
|
+
}
|
|
94
|
+
async function E(e) {
|
|
95
|
+
const r = n(), t = e.value.trim(), c = d(e.slug?.trim() || e.value);
|
|
96
|
+
if (!t || !c)
|
|
97
|
+
return { success: !1, error: "Term value is required." };
|
|
98
|
+
const { data: a } = await r.from("product_attribute_terms").select("sort_order").eq("attribute_id", e.attributeId).order("sort_order", { ascending: !1 }).limit(1), o = typeof a?.[0]?.sort_order == "number" ? a[0].sort_order + 1 : 0, { error: u } = await r.from("product_attribute_terms").insert({
|
|
99
|
+
attribute_id: e.attributeId,
|
|
100
|
+
value: t,
|
|
101
|
+
slug: c,
|
|
102
|
+
sort_order: o
|
|
103
|
+
});
|
|
104
|
+
return u ? { success: !1, error: u.message } : (s("/cms/products/attributes"), s("/cms/products/new"), s("/cms/products"), { success: !0 });
|
|
105
|
+
}
|
|
106
|
+
async function $(e) {
|
|
107
|
+
const r = n();
|
|
108
|
+
for (const [t, c] of e.orderedTermIds.entries()) {
|
|
109
|
+
const { error: a } = await r.from("product_attribute_terms").update({
|
|
110
|
+
sort_order: t,
|
|
111
|
+
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
112
|
+
}).eq("id", c).eq("attribute_id", e.attributeId);
|
|
113
|
+
if (a)
|
|
114
|
+
return { success: !1, error: a.message };
|
|
115
|
+
}
|
|
116
|
+
return s("/cms/products/attributes"), s("/cms/products/new"), s("/cms/products"), { success: !0 };
|
|
117
|
+
}
|
|
118
|
+
async function k(e) {
|
|
119
|
+
const r = n(), { error: t } = await r.from("product_attributes").update({
|
|
120
|
+
name_translations: e.nameTranslations,
|
|
121
|
+
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
122
|
+
}).eq("id", e.attributeId);
|
|
123
|
+
if (t)
|
|
124
|
+
return { success: !1, error: t.message };
|
|
125
|
+
for (const c of e.termTranslations) {
|
|
126
|
+
const { error: a } = await r.from("product_attribute_terms").update({
|
|
127
|
+
value_translations: c.valueTranslations,
|
|
128
|
+
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
129
|
+
}).eq("id", c.termId).eq("attribute_id", e.attributeId);
|
|
130
|
+
if (a)
|
|
131
|
+
return { success: !1, error: a.message };
|
|
132
|
+
}
|
|
133
|
+
return s("/cms/products/attributes"), s("/cms/products/new"), s("/cms/products"), { success: !0 };
|
|
134
|
+
}
|
|
135
|
+
async function R(e) {
|
|
136
|
+
const r = n(), { error: t } = await r.from("product_attribute_terms").delete().eq("id", e);
|
|
137
|
+
return t ? { success: !1, error: t.message } : (s("/cms/products/attributes"), s("/cms/products/new"), s("/cms/products"), { success: !0 });
|
|
138
|
+
}
|
|
139
|
+
async function U(e) {
|
|
140
|
+
const r = n(), t = e.name.trim(), c = d(e.slug?.trim() || e.name);
|
|
141
|
+
if (!t || !c)
|
|
142
|
+
return { success: !1, error: "Category name is required." };
|
|
143
|
+
const { data: a, error: o } = await r.from("categories").insert({
|
|
144
|
+
name: t,
|
|
145
|
+
slug: c,
|
|
146
|
+
description: e.description?.trim() || null,
|
|
147
|
+
name_translations: e.nameTranslations || {},
|
|
148
|
+
description_translations: e.descriptionTranslations || {}
|
|
149
|
+
}).select().single();
|
|
150
|
+
return o ? { success: !1, error: o.message } : (s("/cms/products/categories"), s("/cms/products/new"), s("/cms/products"), { success: !0, category: a });
|
|
151
|
+
}
|
|
152
|
+
async function B(e, r) {
|
|
153
|
+
const t = n(), c = r.name.trim(), a = d(r.slug?.trim() || r.name);
|
|
154
|
+
if (!c || !a)
|
|
155
|
+
return { success: !1, error: "Category name is required." };
|
|
156
|
+
const { error: o } = await t.from("categories").update({
|
|
157
|
+
name: c,
|
|
158
|
+
slug: a,
|
|
159
|
+
description: r.description?.trim() || null,
|
|
160
|
+
name_translations: r.nameTranslations || {},
|
|
161
|
+
description_translations: r.descriptionTranslations || {}
|
|
162
|
+
}).eq("id", e);
|
|
163
|
+
return o ? { success: !1, error: o.message } : (s("/cms/products/categories"), s("/cms/products/new"), s("/cms/products"), { success: !0 });
|
|
164
|
+
}
|
|
165
|
+
async function G(e) {
|
|
166
|
+
const r = n(), { error: t } = await r.from("categories").delete().eq("id", e);
|
|
167
|
+
return t ? { success: !1, error: t.message } : (s("/cms/products/categories"), s("/cms/products/new"), s("/cms/products"), { success: !0 });
|
|
168
|
+
}
|
|
169
|
+
async function L(e, r) {
|
|
170
|
+
const t = n();
|
|
171
|
+
try {
|
|
172
|
+
return await b(t, e, r), s("/cms/products"), s(`/cms/products/${e}/edit`), { success: !0 };
|
|
173
|
+
} catch (c) {
|
|
174
|
+
return { success: !1, error: c.message };
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
export {
|
|
178
|
+
D as bulkDeleteProductsAction,
|
|
179
|
+
F as bulkDraftProductsAction,
|
|
180
|
+
U as createCategoryAction,
|
|
181
|
+
C as createProductAction,
|
|
182
|
+
z as createProductAttributeAction,
|
|
183
|
+
E as createProductAttributeTermAction,
|
|
184
|
+
G as deleteCategoryAction,
|
|
185
|
+
x as deleteProductAction,
|
|
186
|
+
O as deleteProductAttributeAction,
|
|
187
|
+
R as deleteProductAttributeTermAction,
|
|
188
|
+
$ as reorderProductAttributeTermsAction,
|
|
189
|
+
L as syncProductCategoriesAction,
|
|
190
|
+
B as updateCategoryAction,
|
|
191
|
+
I as updateProductAction,
|
|
192
|
+
k as updateProductAttributeTranslationsAction
|
|
193
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),j=require("@nextblock-cms/db/server"),a=require("@nextblock-cms/ui"),r=require("lucide-react"),h=require("./components/ZoneForm.cjs.js"),u=require("./components/RateForm.cjs.js"),l=require("./server-actions.cjs.js"),f=require("../../../currency.cjs.js"),v=require("../../../inventory-settings.cjs.js"),b=require("../../../states.cjs.js"),o=require("@nextblock-cms/utils");async function N({searchParams:m}){const n=j.getServiceRoleSupabaseClient(),[{data:c},g,{data:x},{data:d}]=await Promise.all([n.from("shipping_zones").select(`
|
|
2
|
+
*,
|
|
3
|
+
shipping_zone_locations (*),
|
|
4
|
+
shipping_zone_methods (*)
|
|
5
|
+
`).order("priority_order",{ascending:!0}),v.getEcommerceInventorySettings(n),n.from("languages").select("code, name, is_default").eq("is_active",!0).order("name",{ascending:!0}),n.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("is_default",{ascending:!1}).order("code",{ascending:!0})]),i=d?.find(t=>t.is_default)?.code||d?.[0]?.code||"USD",p=(d||[]).map(t=>f.normalizeCurrencyRecord(t));return e.jsx(a.TooltipProvider,{children:e.jsxs("div",{className:"space-y-6",children:[m?.success?e.jsx("div",{className:"rounded-lg border border-emerald-200 bg-emerald-50 px-4 py-3 text-sm text-emerald-700",children:m.success}):null,e.jsx(a.Card,{className:"overflow-hidden border-slate-200 dark:border-slate-800 shadow-sm",children:e.jsx(a.CardContent,{className:"p-4 sm:p-5",children:e.jsxs("form",{action:l.updateInventoryTrackingAction,className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{className:"flex items-start gap-3 min-w-0",children:[e.jsx("div",{className:"p-2 bg-primary/10 rounded-lg text-primary shadow-inner shrink-0",children:e.jsx(r.Boxes,{className:"h-4 w-4"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx(a.CardTitle,{className:"text-base font-semibold leading-none",children:"Inventory Tracking"}),e.jsx(a.CardDescription,{className:"mt-1 text-sm",children:"Control whether checkout enforces stock counts and paid orders deduct inventory."})]})]}),e.jsx("div",{className:"flex justify-end lg:justify-start shrink-0",children:e.jsx(a.Button,{type:"submit",size:"sm",className:"w-full sm:w-auto",children:"Save Inventory Settings"})})]}),e.jsxs("div",{className:"rounded-lg border bg-muted/20 px-4 py-3",children:[e.jsx("input",{type:"hidden",name:"trackQuantities",value:"false"}),e.jsxs("label",{htmlFor:"track-quantities",className:"flex cursor-pointer items-start gap-3",children:[e.jsx("input",{id:"track-quantities",name:"trackQuantities",type:"checkbox",value:"true",defaultChecked:g.trackQuantities,className:"mt-0.5 h-4 w-4 rounded border-slate-300 text-primary focus:ring-primary"}),e.jsxs("span",{className:"space-y-0.5",children:[e.jsx("span",{className:"block text-sm font-medium text-slate-900 dark:text-slate-100",children:"Track product quantities"}),e.jsx("span",{className:"block text-sm text-muted-foreground",children:"Prevent overselling by checking stock during checkout and decrementing quantities after payment is confirmed."})]})]})]})]})})}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight text-slate-900 dark:text-slate-100",children:"Shipping Zones"}),e.jsx("p",{className:"text-slate-500 dark:text-slate-400 text-sm",children:"Manage geographical delivery areas and their associated shipping rates."})]}),e.jsx(h.ZoneForm,{})]}),e.jsx("div",{className:"grid gap-6",children:!c||c.length===0?e.jsx(a.Card,{className:"bg-slate-50/50 dark:bg-slate-900/10 border-dashed",children:e.jsxs(a.CardContent,{className:"flex flex-col items-center justify-center py-12",children:[e.jsx(r.Truck,{className:"h-12 w-12 text-slate-300 dark:text-slate-700 mb-4"}),e.jsx("p",{className:"text-slate-600 dark:text-slate-400 font-medium",children:"No shipping zones defined yet."}),e.jsx("p",{className:"text-xs text-slate-500 mb-6 text-center max-w-xs",children:"Create a zone to start defining shipping rates for specific regions (e.g., North America, Europe)."})]})}):c.map(t=>e.jsxs(a.Card,{className:"overflow-hidden border-slate-200 dark:border-slate-800 shadow-sm hover:shadow-md transition-shadow",children:[e.jsx(a.CardHeader,{className:"bg-slate-50/50 dark:bg-slate-900/50 border-b dark:border-slate-800 py-4",children:e.jsxs("div",{className:"flex justify-between items-start md:items-center",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-primary/10 rounded-lg text-primary shadow-inner",children:e.jsx(r.Globe,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(a.CardTitle,{className:"text-lg font-bold",children:t.name}),e.jsxs(a.Badge,{variant:"outline",className:"text-[10px] uppercase font-bold py-0 h-4 border-slate-200 bg-white/50 dark:bg-black/20",children:["Prio: ",t.priority_order]})]}),e.jsxs(a.CardDescription,{className:"text-xs",children:[t.shipping_zone_locations?.length||0," regions covered"]})]})]}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(h.ZoneForm,{mode:"edit",initialData:{id:t.id,name:t.name,priority_order:t.priority_order,locations:t.shipping_zone_locations?.map(s=>({country_code:s.country_code,state_code:s.state_code}))||[]}}),e.jsx("form",{action:async()=>{"use server";await l.deleteShippingZone(t.id)},children:e.jsx(a.Button,{type:"submit",variant:"ghost",size:"icon",className:"h-8 w-8 text-slate-400 hover:text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20",children:e.jsx(r.Trash2,{className:"h-4 w-4"})})})]})]})}),e.jsx(a.CardContent,{className:"p-0",children:e.jsxs("div",{className:"grid md:grid-cols-2 divide-y md:divide-y-0 md:divide-x divide-slate-100 dark:divide-slate-800",children:[e.jsxs("div",{className:"p-6",children:[e.jsxs("h4",{className:"text-[10px] font-bold uppercase tracking-widest text-slate-500 mb-4 flex items-center gap-1.5",children:[e.jsx(r.Globe,{className:"h-3 w-3"})," Target Regions"]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:t.shipping_zone_locations?.length>0?t.shipping_zone_locations.map(s=>e.jsxs(a.Badge,{variant:"secondary",className:"bg-slate-100 dark:bg-slate-800/80 text-slate-700 dark:text-slate-300 hover:bg-slate-200 border-none px-2 py-0.5 text-[11px] font-medium",children:[s.country_code,s.state_code?e.jsxs("span",{className:"text-slate-400 ml-1",children:["(",b.resolveSubdivisionName(s.country_code,s.state_code),")"]}):""]},s.id)):e.jsx("p",{className:"text-sm text-slate-400 italic",children:"No specific locations assigned."})})]}),e.jsxs("div",{className:"p-6",children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsxs("h4",{className:"text-[10px] font-bold uppercase tracking-widest text-slate-500 flex items-center gap-1.5",children:[e.jsx(r.Truck,{className:"h-3 w-3"})," Shipping Methods"]}),e.jsx(u.RateForm,{zoneId:t.id,zoneName:t.name,languages:x||[],currencies:p,defaultCurrencyCode:i})]}),e.jsx("div",{className:"space-y-2",children:t.shipping_zone_methods?.length>0?t.shipping_zone_methods.map(s=>e.jsxs("div",{className:"flex justify-between items-center group p-2 hover:bg-slate-50/80 dark:hover:bg-slate-800/30 rounded-lg transition-all border border-transparent hover:border-slate-100 dark:hover:border-slate-800",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"text-sm font-semibold text-slate-900 dark:text-slate-100 truncate",children:s.name}),e.jsx(a.Badge,{variant:"outline",className:"h-4 px-1 text-[9px]",children:s.currency_pricing_mode==="manual"?"Manual FX":"Auto FX"}),(s.min_order_amount||0)>0&&e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsxs(a.Badge,{variant:"outline",className:"h-4 px-1 text-[9px] bg-emerald-50 text-emerald-700 dark:bg-emerald-900/20 dark:text-emerald-400 border-emerald-100 dark:border-emerald-900/50",children:[e.jsx(r.Info,{className:"h-2 w-2 mr-0.5"}),o.formatPrice(s.min_order_amount,s.cost_currency?.toUpperCase()||i)]})}),e.jsxs(a.TooltipContent,{children:["Available for orders over ",o.formatPrice(s.min_order_amount,s.cost_currency?.toUpperCase()||i)]})]})]}),e.jsx("p",{className:"text-[10px] text-slate-500 uppercase tracking-tighter mix-blend-multiply dark:mix-blend-normal",children:s.method_type.replace("_"," ")})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("p",{className:"text-sm font-black text-primary px-2",children:s.method_type==="free_shipping"?"FREE":o.formatPrice(s.cost_amount,s.cost_currency?.toUpperCase()||i)}),e.jsxs("div",{className:"flex opacity-0 group-hover:opacity-100 transition-opacity",children:[e.jsx(u.RateForm,{zoneId:t.id,zoneName:t.name,languages:x||[],currencies:p,defaultCurrencyCode:i,mode:"edit",initialData:s}),e.jsx("form",{action:async()=>{"use server";await l.deleteShippingRate(s.id)},children:e.jsx(a.Button,{type:"submit",variant:"ghost",size:"icon",className:"h-7 w-7 text-slate-400 hover:text-red-500",children:e.jsx(r.Trash2,{className:"h-3 w-3"})})})]})]})]},s.id)):e.jsx("p",{className:"text-xs text-slate-400 italic",children:"No methods defined for this zone."})})]})]})})]},t.id))})]})})}exports.ShippingPage=N;
|