@nextblock-cms/ecom 0.13.4 → 0.13.6
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/lib/CurrencyProvider.cjs.js +1 -1
- package/lib/CurrencyProvider.es.js +31 -27
- package/lib/components/AccountNavigationMenu.cjs.js +1 -1
- package/lib/components/AccountNavigationMenu.es.js +53 -26
- package/lib/components/AddToCartButton.cjs.js +1 -1
- package/lib/components/AddToCartButton.es.js +49 -25
- package/lib/components/Cart.cjs.js +1 -1
- package/lib/components/Cart.es.js +367 -115
- package/lib/components/CartDrawer.cjs.js +1 -1
- package/lib/components/CartDrawer.es.js +272 -88
- package/lib/components/CartIcon.cjs.js +1 -1
- package/lib/components/CartIcon.es.js +44 -16
- package/lib/components/Checkout.cjs.js +1 -1
- package/lib/components/Checkout.es.js +1601 -694
- package/lib/components/CouponForm.cjs.js +1 -1
- package/lib/components/CouponForm.es.js +160 -96
- package/lib/components/CurrencySwitcher.cjs.js +1 -1
- package/lib/components/CurrencySwitcher.es.js +32 -12
- package/lib/components/CustomerProfileForm.cjs.js +1 -1
- package/lib/components/CustomerProfileForm.es.js +666 -250
- package/lib/components/FeaturedProduct.cjs.js +1 -1
- package/lib/components/FeaturedProduct.es.js +126 -42
- package/lib/components/FreemiusLicensePanel.cjs.js +1 -1
- package/lib/components/FreemiusLicensePanel.es.js +125 -45
- package/lib/components/InvoiceDocument.cjs.js +1 -1
- package/lib/components/InvoiceDocument.es.js +485 -146
- package/lib/components/InvoiceViewerShell.cjs.js +2 -2
- package/lib/components/InvoiceViewerShell.es.js +142 -54
- package/lib/components/ProductCard.cjs.js +1 -1
- package/lib/components/ProductCard.es.js +224 -81
- package/lib/components/ProductDetailsLayout.cjs.js +1 -1
- package/lib/components/ProductDetailsLayout.es.js +629 -275
- package/lib/components/ProductGallery.cjs.js +1 -1
- package/lib/components/ProductGallery.es.js +64 -21
- package/lib/components/ProductGrid.cjs.js +1 -1
- package/lib/components/ProductGrid.es.js +28 -12
- package/lib/components/ShippingEstimator.cjs.js +1 -1
- package/lib/components/ShippingEstimator.es.js +226 -90
- package/lib/components/SimpleTiptapRenderer.cjs.js +1 -1
- package/lib/components/SimpleTiptapRenderer.es.js +286 -93
- package/lib/components/SubscriptionSelector.cjs.js +1 -1
- package/lib/components/SubscriptionSelector.es.js +168 -92
- package/lib/pages/cms/coupons/CouponEditorForm.cjs.js +1 -1
- package/lib/pages/cms/coupons/CouponEditorForm.es.js +370 -110
- package/lib/pages/cms/coupons/CouponsPage.cjs.js +2 -2
- package/lib/pages/cms/coupons/CouponsPage.es.js +368 -116
- package/lib/pages/cms/coupons/CreateCouponDialog.cjs.js +1 -1
- package/lib/pages/cms/coupons/CreateCouponDialog.es.js +61 -25
- package/lib/pages/cms/coupons/EditCouponPage.cjs.js +1 -1
- package/lib/pages/cms/coupons/EditCouponPage.es.js +71 -35
- package/lib/pages/cms/coupons/ProductScopePicker.cjs.js +1 -1
- package/lib/pages/cms/coupons/ProductScopePicker.es.js +167 -72
- package/lib/pages/cms/orders/ExportReportsDialog.cjs.js +1 -1
- package/lib/pages/cms/orders/ExportReportsDialog.es.js +247 -87
- package/lib/pages/cms/orders/OrderDetailPage.cjs.js +1 -1
- package/lib/pages/cms/orders/OrderDetailPage.es.js +283 -95
- package/lib/pages/cms/orders/OrderPrintButton.cjs.js +1 -1
- package/lib/pages/cms/orders/OrderPrintButton.es.js +21 -9
- package/lib/pages/cms/orders/OrderStatusForm.cjs.js +1 -1
- package/lib/pages/cms/orders/OrderStatusForm.es.js +106 -46
- package/lib/pages/cms/orders/OrdersPage.cjs.js +1 -1
- package/lib/pages/cms/orders/OrdersPage.es.js +257 -78
- package/lib/pages/cms/payments/PaymentsClient.cjs.js +1 -1
- package/lib/pages/cms/payments/PaymentsClient.es.js +551 -155
- package/lib/pages/cms/payments/PaymentsPage.cjs.js +1 -1
- package/lib/pages/cms/payments/PaymentsPage.es.js +24 -16
- package/lib/pages/cms/products/ProductsPage.cjs.js +1 -1
- package/lib/pages/cms/products/ProductsPage.es.js +77 -37
- package/lib/pages/cms/products/_id_/edit/EditProductPage.cjs.js +1 -1
- package/lib/pages/cms/products/_id_/edit/EditProductPage.es.js +176 -96
- package/lib/pages/cms/products/attributes/AttributeManagementPage.cjs.js +1 -1
- package/lib/pages/cms/products/attributes/AttributeManagementPage.es.js +85 -41
- package/lib/pages/cms/products/attributes/components/AttributeManager.cjs.js +1 -1
- package/lib/pages/cms/products/attributes/components/AttributeManager.es.js +455 -192
- package/lib/pages/cms/products/categories/CategoryManagementPage.cjs.js +1 -1
- package/lib/pages/cms/products/categories/CategoryManagementPage.es.js +72 -28
- package/lib/pages/cms/products/categories/components/CategoryManager.cjs.js +1 -1
- package/lib/pages/cms/products/categories/components/CategoryManager.es.js +490 -183
- package/lib/pages/cms/products/components/CopyProductFromLanguage.cjs.js +1 -1
- package/lib/pages/cms/products/components/CopyProductFromLanguage.es.js +175 -67
- package/lib/pages/cms/products/components/CurrencyPriceFields.cjs.js +1 -1
- package/lib/pages/cms/products/components/CurrencyPriceFields.es.js +211 -100
- package/lib/pages/cms/products/components/DeleteProductButton.cjs.js +1 -1
- package/lib/pages/cms/products/components/DeleteProductButton.es.js +45 -25
- package/lib/pages/cms/products/components/FreemiusPricingDashboard.cjs.js +1 -1
- package/lib/pages/cms/products/components/FreemiusPricingDashboard.es.js +202 -58
- package/lib/pages/cms/products/components/ProductCategorySelector.cjs.js +1 -1
- package/lib/pages/cms/products/components/ProductCategorySelector.es.js +234 -88
- package/lib/pages/cms/products/components/ProductForm.cjs.js +1 -1
- package/lib/pages/cms/products/components/ProductForm.es.js +1199 -551
- package/lib/pages/cms/products/components/ProductMediaManager.cjs.js +1 -1
- package/lib/pages/cms/products/components/ProductMediaManager.es.js +154 -63
- package/lib/pages/cms/products/components/ProductsBulkTable.cjs.js +1 -1
- package/lib/pages/cms/products/components/ProductsBulkTable.es.js +391 -144
- package/lib/pages/cms/products/components/SaleScheduleFields.cjs.js +1 -1
- package/lib/pages/cms/products/components/SaleScheduleFields.es.js +203 -87
- package/lib/pages/cms/products/components/SyncFreemiusButton.cjs.js +1 -1
- package/lib/pages/cms/products/components/SyncFreemiusButton.es.js +30 -18
- package/lib/pages/cms/products/components/SyncFreemiusPricingButton.cjs.js +2 -2
- package/lib/pages/cms/products/components/SyncFreemiusPricingButton.es.js +35 -23
- package/lib/pages/cms/products/components/VariationsEditor.cjs.js +1 -1
- package/lib/pages/cms/products/components/VariationsEditor.es.js +492 -261
- package/lib/pages/cms/products/inventory/InventoryPage.cjs.js +1 -1
- package/lib/pages/cms/products/inventory/InventoryPage.es.js +33 -13
- package/lib/pages/cms/products/inventory/InventoryTableClient.cjs.js +2 -2
- package/lib/pages/cms/products/inventory/InventoryTableClient.es.js +365 -145
- package/lib/pages/cms/products/new/NewProductPage.cjs.js +1 -1
- package/lib/pages/cms/products/new/NewProductPage.es.js +46 -34
- package/lib/pages/cms/products/server-actions.cjs.js +1 -1
- package/lib/pages/cms/products/server-actions.es.js +163 -139
- package/lib/pages/cms/shipping/ShippingPage.cjs.js +2 -2
- package/lib/pages/cms/shipping/ShippingPage.es.js +507 -155
- package/lib/pages/cms/shipping/components/RateForm.cjs.js +1 -1
- package/lib/pages/cms/shipping/components/RateForm.es.js +717 -334
- package/lib/pages/cms/shipping/components/ZoneForm.cjs.js +1 -1
- package/lib/pages/cms/shipping/components/ZoneForm.es.js +392 -158
- package/lib/pages/cms/taxes/TaxesPage.cjs.js +1 -1
- package/lib/pages/cms/taxes/TaxesPage.es.js +448 -120
- package/lib/pages/cms/taxes/components/TaxRateForm.cjs.js +1 -1
- package/lib/pages/cms/taxes/components/TaxRateForm.es.js +159 -55
- package/lib/product-context.cjs.js +1 -1
- package/lib/product-context.es.js +14 -10
- package/package.json +4 -4
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ProductForm as
|
|
3
|
-
import { getGlobalProductAttributes as
|
|
4
|
-
import { mapRawVariantRelations as
|
|
5
|
-
import { createProductAction as
|
|
6
|
-
import { getEnabledPaymentProviders as
|
|
7
|
-
import { getServiceRoleSupabaseClient as
|
|
1
|
+
import { jsxDEV as c } from "react/jsx-dev-runtime";
|
|
2
|
+
import { ProductForm as h } from "../components/ProductForm.es.js";
|
|
3
|
+
import { getGlobalProductAttributes as w } from "../actions.es.js";
|
|
4
|
+
import { mapRawVariantRelations as A } from "../../../../variation-utils.es.js";
|
|
5
|
+
import { createProductAction as j } from "../server-actions.es.js";
|
|
6
|
+
import { getEnabledPaymentProviders as v, getStoreConfigStatus as R } from "../../payments/queries.es.js";
|
|
7
|
+
import { getServiceRoleSupabaseClient as y } from "@nextblock-cms/db/server";
|
|
8
8
|
import { minorUnitAmountToMajor as m } from "@nextblock-cms/utils";
|
|
9
|
-
import { normalizeCurrencyRecord as
|
|
10
|
-
async function
|
|
9
|
+
import { normalizeCurrencyRecord as S } from "../../../../currency.es.js";
|
|
10
|
+
async function G({
|
|
11
11
|
mediaPickerNode: d,
|
|
12
|
-
availableLanguagesProp:
|
|
12
|
+
availableLanguagesProp: o,
|
|
13
13
|
translationGroupId: a,
|
|
14
|
-
targetLanguageId:
|
|
14
|
+
targetLanguageId: n,
|
|
15
15
|
initialData: t
|
|
16
16
|
}) {
|
|
17
|
-
const [u,
|
|
18
|
-
j(),
|
|
17
|
+
const [u, l, p, _] = await Promise.all([
|
|
19
18
|
v(),
|
|
20
19
|
R(),
|
|
21
|
-
w()
|
|
20
|
+
w(),
|
|
21
|
+
y().from("currencies").select(
|
|
22
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
23
|
).eq("is_active", !0).order("code", { ascending: !0 }).then((e) => e.data || [])
|
|
24
|
-
]),
|
|
25
|
-
(e) =>
|
|
26
|
-
),
|
|
24
|
+
]), b = (_ || []).map(
|
|
25
|
+
(e) => S(e)
|
|
26
|
+
), f = (p || []).map((e) => ({
|
|
27
27
|
id: e.id,
|
|
28
28
|
name: e.name,
|
|
29
29
|
name_translations: e.name_translations || {},
|
|
@@ -32,45 +32,57 @@ async function U({
|
|
|
32
32
|
...r,
|
|
33
33
|
value_translations: r.value_translations || {}
|
|
34
34
|
}))
|
|
35
|
-
})), g =
|
|
35
|
+
})), g = o.find((e) => e.id === t?.language_id)?.code || o.find((e) => e.id === (n ? parseInt(n, 10) : void 0))?.code || o.find((e) => e.is_default)?.code, { attributes: P, variants: x } = A(
|
|
36
36
|
t?.product_variants || [],
|
|
37
37
|
g
|
|
38
|
-
),
|
|
38
|
+
), N = t && {
|
|
39
39
|
...t,
|
|
40
|
-
variation_attributes: t.variation_attributes ||
|
|
40
|
+
variation_attributes: t.variation_attributes || P.map((e) => ({
|
|
41
41
|
attribute_id: e.id,
|
|
42
42
|
term_ids: e.terms.map((r) => r.id)
|
|
43
43
|
})),
|
|
44
|
-
variants: t.variants ||
|
|
44
|
+
variants: t.variants || x.map((e) => ({
|
|
45
45
|
...e,
|
|
46
46
|
upc: e.upc ?? null,
|
|
47
47
|
price: e.price / 100,
|
|
48
48
|
prices: Object.entries(e.prices || {}).reduce(
|
|
49
|
-
(r, [
|
|
49
|
+
(r, [s, i]) => (r[s] = m(i, s), r),
|
|
50
50
|
{}
|
|
51
51
|
),
|
|
52
52
|
sale_price: typeof e.sale_price == "number" ? e.sale_price / 100 : null,
|
|
53
|
-
sale_prices: Object.entries(e.sale_prices || {}).reduce((r, [
|
|
53
|
+
sale_prices: Object.entries(e.sale_prices || {}).reduce((r, [s, i]) => (r[s] = typeof i == "number" ? m(i, s) : null, r), {}),
|
|
54
54
|
main_media_id: e.main_media_id ?? null,
|
|
55
55
|
main_image_url: e.image_url ?? null
|
|
56
56
|
}))
|
|
57
57
|
};
|
|
58
58
|
return /* @__PURE__ */ c("div", { className: "p-8", children: /* @__PURE__ */ c(
|
|
59
|
-
|
|
59
|
+
h,
|
|
60
60
|
{
|
|
61
61
|
mediaPickerNode: d,
|
|
62
|
-
availableLanguagesProp:
|
|
63
|
-
globalAttributesProp:
|
|
64
|
-
currenciesProp:
|
|
62
|
+
availableLanguagesProp: o,
|
|
63
|
+
globalAttributesProp: f,
|
|
64
|
+
currenciesProp: b,
|
|
65
65
|
translationGroupId: a,
|
|
66
|
-
targetLanguageId:
|
|
67
|
-
initialData:
|
|
66
|
+
targetLanguageId: n,
|
|
67
|
+
initialData: N,
|
|
68
68
|
enabledProviders: u,
|
|
69
|
-
configStatus:
|
|
70
|
-
createAction:
|
|
71
|
-
}
|
|
72
|
-
|
|
69
|
+
configStatus: l,
|
|
70
|
+
createAction: j
|
|
71
|
+
},
|
|
72
|
+
void 0,
|
|
73
|
+
!1,
|
|
74
|
+
{
|
|
75
|
+
fileName: "C:/Users/desjardinsn/Desktop/nextblock/libs/ecommerce/src/lib/pages/cms/products/new/NewProductPage.tsx",
|
|
76
|
+
lineNumber: 104,
|
|
77
|
+
columnNumber: 7
|
|
78
|
+
},
|
|
79
|
+
this
|
|
80
|
+
) }, void 0, !1, {
|
|
81
|
+
fileName: "C:/Users/desjardinsn/Desktop/nextblock/libs/ecommerce/src/lib/pages/cms/products/new/NewProductPage.tsx",
|
|
82
|
+
lineNumber: 103,
|
|
83
|
+
columnNumber: 5
|
|
84
|
+
}, this);
|
|
73
85
|
}
|
|
74
86
|
export {
|
|
75
|
-
|
|
87
|
+
G as NewProductPage
|
|
76
88
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("@nextblock-cms/db/server"),l=require("../../../product-actions.cjs.js"),h=require("../../../freemius-coupons.cjs.js"),g=require("../../../currency.cjs.js"),_=require("./product-price-sync.cjs.js"),a=require("next/cache"),v=require("next/navigation");function u(e){return e.toLowerCase().trim().replace(/\s+/g,"-").replace(/[^a-z0-9-]/g,"").replace(/-+/g,"-").replace(/^-|-$/g,"")}async function w(e){const t=i.createClient(),{data:r}=await t.from("currencies").select("code, symbol, exchange_rate, is_default, is_active, auto_sync_product_prices, auto_update_exchange_rate, exchange_rate_source, exchange_rate_updated_at, rounding_mode, rounding_increment, rounding_charm_amount").eq("is_active",!0).order("code",{ascending:!0}),s=_.sanitizeProductFormValuesForStoreManagedCurrencies(e,(r||[]).map(o=>g.normalizeCurrencyRecord(o))),c=await l.createProduct(t,s);if(s.payment_provider==="freemius"&&c?.id)try{await h.syncProductSaleCouponToFreemius({productId:c.id,client:i.getServiceRoleSupabaseClient()})}catch(o){console.error("Failed to sync Freemius sale coupon on create:",o)}a.revalidatePath("/cms/products"),v.redirect("/cms/products")}async function y(e,t,r,s){const c={author_id:r,meta:s,updated_at:new Date().toISOString()},o=async()=>{const{error:f}=await e.from("product_drafts").update(c).eq("product_id",t);if(f)throw new Error(`Failed to save product draft: ${f.message}`)},{data:n,error:m}=await e.from("product_drafts").select("id").eq("product_id",t).maybeSingle();if(m)throw new Error(`Failed to read product draft: ${m.message}`);if(n){await o();return}const{data:P,error:p}=await e.from("blocks").select("id, page_id, post_id, product_id, language_id, block_type, content, order, created_at, updated_at").eq("product_id",t).order("order",{ascending:!0});if(p)throw new Error(`Failed to read product blocks: ${p.message}`);const{error:d}=await e.from("product_drafts").insert({...c,blocks:P??[],product_id:t});if(d){if(d.code==="23505"){await o();return}throw new Error(`Failed to save product draft: ${d.message}`)}}async function A(e,t){const r=i.createClient(),{data:{user:s}}=await r.auth.getUser();if(!s)throw new Error("User not authenticated.");const{data:c}=await r.from("currencies").select("code, symbol, exchange_rate, is_default, is_active, auto_sync_product_prices, auto_update_exchange_rate, exchange_rate_source, exchange_rate_updated_at, rounding_mode, rounding_increment, rounding_charm_amount").eq("is_active",!0).order("code",{ascending:!0}),o=_.sanitizeProductFormValuesForStoreManagedCurrencies(t,(c||[]).map(n=>g.normalizeCurrencyRecord(n)));return await y(r,e,s.id,o),{success:!0}}async function S(e){const t=i.createClient();await l.deleteProduct(t,e),a.revalidatePath("/cms/products")}function b(e){return Array.from(new Set(e.map(t=>t.trim()).filter(Boolean)))}async function C(e){const t=b(e);if(t.length===0)return{success:!1,error:"Select at least one product."};const r=i.createClient(),{error:s}=await r.from("products").delete().in("id",t);return s?{success:!1,error:s.message}:(a.revalidatePath("/cms/products"),{success:!0,count:t.length})}async function q(e){const t=b(e);if(t.length===0)return{success:!1,error:"Select at least one product."};const r=i.createClient(),{error:s}=await r.from("products").update({status:"draft",updated_at:new Date().toISOString()}).in("id",t);return s?{success:!1,error:s.message}:(a.revalidatePath("/cms/products"),{success:!0,count:t.length})}async function T(e){const t=String(e||"").trim();if(!t)return{error:"Missing product id."};const r=i.createClient(),{data:{user:s}}=await r.auth.getUser();if(!s)return{error:"You must be signed in to publish a product."};const{data:c,error:o}=await r.from("products").update({status:"active",updated_at:new Date().toISOString()}).eq("id",t).select("slug").single();return o||!c?{error:o?.message||"Could not publish the product."}:(a.revalidatePath("/cms/products"),a.revalidatePath(`/cms/products/${t}/edit`),c.slug&&a.revalidatePath(`/product/${c.slug}`),{})}async function D(e){const t=i.getServiceRoleSupabaseClient(),r=e.name.trim(),s=u(e.slug?.trim()||e.name);if(!r||!s)return{success:!1,error:"Attribute name is required."};const{error:c}=await t.from("product_attributes").insert({name:r,slug:s});return c?{success:!1,error:c.message}:(a.revalidatePath("/cms/products/attributes"),a.revalidatePath("/cms/products/new"),a.revalidatePath("/cms/products"),{success:!0})}async function x(e){const t=i.getServiceRoleSupabaseClient(),{error:r}=await t.from("product_attributes").delete().eq("id",e);return r?{success:!1,error:r.message}:(a.revalidatePath("/cms/products/attributes"),a.revalidatePath("/cms/products/new"),a.revalidatePath("/cms/products"),{success:!0})}async function R(e){const t=i.getServiceRoleSupabaseClient(),r=e.value.trim(),s=u(e.slug?.trim()||e.value);if(!r||!s)return{success:!1,error:"Term value is required."};const{data:c}=await t.from("product_attribute_terms").select("sort_order").eq("attribute_id",e.attributeId).order("sort_order",{ascending:!1}).limit(1),o=typeof c?.[0]?.sort_order=="number"?c[0].sort_order+1:0,{error:n}=await t.from("product_attribute_terms").insert({attribute_id:e.attributeId,value:r,slug:s,sort_order:o});return n?{success:!1,error:n.message}:(a.revalidatePath("/cms/products/attributes"),a.revalidatePath("/cms/products/new"),a.revalidatePath("/cms/products"),{success:!0})}async function F(e){const t=i.getServiceRoleSupabaseClient();for(const[r,s]of e.orderedTermIds.entries()){const{error:c}=await t.from("product_attribute_terms").update({sort_order:r,updated_at:new Date().toISOString()}).eq("id",s).eq("attribute_id",e.attributeId);if(c)return{success:!1,error:c.message}}return a.revalidatePath("/cms/products/attributes"),a.revalidatePath("/cms/products/new"),a.revalidatePath("/cms/products"),{success:!0}}async function I(e){const t=i.getServiceRoleSupabaseClient(),{error:r}=await t.from("product_attributes").update({name_translations:e.nameTranslations,updated_at:new Date().toISOString()}).eq("id",e.attributeId);if(r)return{success:!1,error:r.message};for(const s of e.termTranslations){const{error:c}=await t.from("product_attribute_terms").update({value_translations:s.valueTranslations,updated_at:new Date().toISOString()}).eq("id",s.termId).eq("attribute_id",e.attributeId);if(c)return{success:!1,error:c.message}}return a.revalidatePath("/cms/products/attributes"),a.revalidatePath("/cms/products/new"),a.revalidatePath("/cms/products"),{success:!0}}async function E(e){const t=i.getServiceRoleSupabaseClient(),{error:r}=await t.from("product_attribute_terms").delete().eq("id",e);return r?{success:!1,error:r.message}:(a.revalidatePath("/cms/products/attributes"),a.revalidatePath("/cms/products/new"),a.revalidatePath("/cms/products"),{success:!0})}async function k(e){const t=i.getServiceRoleSupabaseClient(),r=e.name.trim(),s=u(e.slug?.trim()||e.name);if(!r||!s)return{success:!1,error:"Category name is required."};const{data:c,error:o}=await t.from("categories").insert({name:r,slug:s,description:e.description?.trim()||null,name_translations:e.nameTranslations||{},description_translations:e.descriptionTranslations||{}}).select().single();return o?{success:!1,error:o.message}:(a.revalidatePath("/cms/products/categories"),a.revalidatePath("/cms/products/new"),a.revalidatePath("/cms/products"),{success:!0,category:c})}async function z(e,t){const r=i.getServiceRoleSupabaseClient(),s=t.name.trim(),c=u(t.slug?.trim()||t.name);if(!s||!c)return{success:!1,error:"Category name is required."};const{error:o}=await r.from("categories").update({name:s,slug:c,description:t.description?.trim()||null,name_translations:t.nameTranslations||{},description_translations:t.descriptionTranslations||{}}).eq("id",e);return o?{success:!1,error:o.message}:(a.revalidatePath("/cms/products/categories"),a.revalidatePath("/cms/products/new"),a.revalidatePath("/cms/products"),{success:!0})}async function O(e){const t=i.getServiceRoleSupabaseClient(),{error:r}=await t.from("categories").delete().eq("id",e);return r?{success:!1,error:r.message}:(a.revalidatePath("/cms/products/categories"),a.revalidatePath("/cms/products/new"),a.revalidatePath("/cms/products"),{success:!0})}async function $(e,t){const r=i.getServiceRoleSupabaseClient();try{return await l.syncCategoriesForTranslationGroup(r,e,t),a.revalidatePath("/cms/products"),a.revalidatePath(`/cms/products/${e}/edit`),{success:!0}}catch(s){return{success:!1,error:s.message}}}exports.bulkDeleteProductsAction=C;exports.bulkDraftProductsAction=q;exports.createCategoryAction=k;exports.createProductAction=w;exports.createProductAttributeAction=D;exports.createProductAttributeTermAction=R;exports.deleteCategoryAction=O;exports.deleteProductAction=S;exports.deleteProductAttributeAction=x;exports.deleteProductAttributeTermAction=E;exports.publishProductAction=T;exports.reorderProductAttributeTermsAction=F;exports.syncProductCategoriesAction=$;exports.updateCategoryAction=z;exports.updateProductAction=A;exports.updateProductAttributeTranslationsAction=I;
|
|
@@ -1,209 +1,233 @@
|
|
|
1
1
|
'use server';
|
|
2
|
-
import { getServiceRoleSupabaseClient as n, createClient as
|
|
3
|
-
import { createProduct as
|
|
4
|
-
import { syncProductSaleCouponToFreemius as
|
|
5
|
-
import { normalizeCurrencyRecord as
|
|
6
|
-
import { sanitizeProductFormValuesForStoreManagedCurrencies as
|
|
2
|
+
import { getServiceRoleSupabaseClient as n, createClient as i } from "@nextblock-cms/db/server";
|
|
3
|
+
import { createProduct as y, deleteProduct as h, syncCategoriesForTranslationGroup as A } from "../../../product-actions.es.js";
|
|
4
|
+
import { syncProductSaleCouponToFreemius as S } from "../../../freemius-coupons.es.js";
|
|
5
|
+
import { normalizeCurrencyRecord as g } from "../../../currency.es.js";
|
|
6
|
+
import { sanitizeProductFormValuesForStoreManagedCurrencies as _ } from "./product-price-sync.es.js";
|
|
7
7
|
import { revalidatePath as s } from "next/cache";
|
|
8
|
-
import { redirect as
|
|
9
|
-
function d(
|
|
10
|
-
return
|
|
8
|
+
import { redirect as P } from "next/navigation";
|
|
9
|
+
function d(r) {
|
|
10
|
+
return r.toLowerCase().trim().replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
11
11
|
}
|
|
12
|
-
async function
|
|
13
|
-
const
|
|
12
|
+
async function F(r) {
|
|
13
|
+
const e = i(), { data: t } = await e.from("currencies").select(
|
|
14
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 }),
|
|
16
|
-
|
|
17
|
-
(t || []).map((
|
|
18
|
-
),
|
|
19
|
-
if (
|
|
15
|
+
).eq("is_active", !0).order("code", { ascending: !0 }), o = _(
|
|
16
|
+
r,
|
|
17
|
+
(t || []).map((c) => g(c))
|
|
18
|
+
), a = await y(e, o);
|
|
19
|
+
if (o.payment_provider === "freemius" && a?.id)
|
|
20
20
|
try {
|
|
21
|
-
await
|
|
22
|
-
productId:
|
|
21
|
+
await S({
|
|
22
|
+
productId: a.id,
|
|
23
23
|
client: n()
|
|
24
24
|
});
|
|
25
|
-
} catch (
|
|
26
|
-
console.error("Failed to sync Freemius sale coupon on create:",
|
|
25
|
+
} catch (c) {
|
|
26
|
+
console.error("Failed to sync Freemius sale coupon on create:", c);
|
|
27
|
+
}
|
|
28
|
+
s("/cms/products"), P("/cms/products");
|
|
29
|
+
}
|
|
30
|
+
async function q(r, e, t, o) {
|
|
31
|
+
const a = {
|
|
32
|
+
author_id: t,
|
|
33
|
+
meta: o,
|
|
34
|
+
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
35
|
+
}, c = async () => {
|
|
36
|
+
const { error: f } = await r.from("product_drafts").update(a).eq("product_id", e);
|
|
37
|
+
if (f)
|
|
38
|
+
throw new Error(`Failed to save product draft: ${f.message}`);
|
|
39
|
+
}, { data: u, error: l } = await r.from("product_drafts").select("id").eq("product_id", e).maybeSingle();
|
|
40
|
+
if (l)
|
|
41
|
+
throw new Error(`Failed to read product draft: ${l.message}`);
|
|
42
|
+
if (u) {
|
|
43
|
+
await c();
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const { data: w, error: p } = await r.from("blocks").select(
|
|
47
|
+
"id, page_id, post_id, product_id, language_id, block_type, content, order, created_at, updated_at"
|
|
48
|
+
).eq("product_id", e).order("order", { ascending: !0 });
|
|
49
|
+
if (p)
|
|
50
|
+
throw new Error(`Failed to read product blocks: ${p.message}`);
|
|
51
|
+
const { error: m } = await r.from("product_drafts").insert({
|
|
52
|
+
...a,
|
|
53
|
+
blocks: w ?? [],
|
|
54
|
+
product_id: e
|
|
55
|
+
});
|
|
56
|
+
if (m) {
|
|
57
|
+
if (m.code === "23505") {
|
|
58
|
+
await c();
|
|
59
|
+
return;
|
|
27
60
|
}
|
|
28
|
-
|
|
61
|
+
throw new Error(`Failed to save product draft: ${m.message}`);
|
|
62
|
+
}
|
|
29
63
|
}
|
|
30
|
-
async function
|
|
31
|
-
const t =
|
|
32
|
-
if (!
|
|
64
|
+
async function k(r, e) {
|
|
65
|
+
const t = i(), { data: { user: o } } = await t.auth.getUser();
|
|
66
|
+
if (!o)
|
|
33
67
|
throw new Error("User not authenticated.");
|
|
34
|
-
const { data:
|
|
68
|
+
const { data: a } = await t.from("currencies").select(
|
|
35
69
|
"code, symbol, exchange_rate, is_default, is_active, auto_sync_product_prices, auto_update_exchange_rate, exchange_rate_source, exchange_rate_updated_at, rounding_mode, rounding_increment, rounding_charm_amount"
|
|
36
|
-
).eq("is_active", !0).order("code", { ascending: !0 }),
|
|
37
|
-
|
|
38
|
-
(
|
|
39
|
-
), { error: i } = await t.from("product_drafts").upsert(
|
|
40
|
-
{
|
|
41
|
-
product_id: e,
|
|
42
|
-
author_id: c.id,
|
|
43
|
-
meta: a,
|
|
44
|
-
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
45
|
-
},
|
|
46
|
-
{ onConflict: "product_id" }
|
|
70
|
+
).eq("is_active", !0).order("code", { ascending: !0 }), c = _(
|
|
71
|
+
e,
|
|
72
|
+
(a || []).map((u) => g(u))
|
|
47
73
|
);
|
|
48
|
-
|
|
49
|
-
throw new Error(`Failed to save product draft: ${i.message}`);
|
|
50
|
-
return { success: !0 };
|
|
74
|
+
return await q(t, r, o.id, c), { success: !0 };
|
|
51
75
|
}
|
|
52
|
-
async function
|
|
53
|
-
const
|
|
54
|
-
await
|
|
76
|
+
async function $(r) {
|
|
77
|
+
const e = i();
|
|
78
|
+
await h(e, r), s("/cms/products");
|
|
55
79
|
}
|
|
56
|
-
function
|
|
80
|
+
function b(r) {
|
|
57
81
|
return Array.from(
|
|
58
82
|
new Set(
|
|
59
|
-
|
|
83
|
+
r.map((e) => e.trim()).filter(Boolean)
|
|
60
84
|
)
|
|
61
85
|
);
|
|
62
86
|
}
|
|
63
|
-
async function
|
|
64
|
-
const
|
|
65
|
-
if (
|
|
87
|
+
async function O(r) {
|
|
88
|
+
const e = b(r);
|
|
89
|
+
if (e.length === 0)
|
|
66
90
|
return { success: !1, error: "Select at least one product." };
|
|
67
|
-
const t =
|
|
68
|
-
return
|
|
91
|
+
const t = i(), { error: o } = await t.from("products").delete().in("id", e);
|
|
92
|
+
return o ? { success: !1, error: o.message } : (s("/cms/products"), { success: !0, count: e.length });
|
|
69
93
|
}
|
|
70
|
-
async function
|
|
71
|
-
const
|
|
72
|
-
if (
|
|
94
|
+
async function z(r) {
|
|
95
|
+
const e = b(r);
|
|
96
|
+
if (e.length === 0)
|
|
73
97
|
return { success: !1, error: "Select at least one product." };
|
|
74
|
-
const t =
|
|
98
|
+
const t = i(), { error: o } = await t.from("products").update({
|
|
75
99
|
status: "draft",
|
|
76
100
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
77
|
-
}).in("id",
|
|
78
|
-
return
|
|
101
|
+
}).in("id", e);
|
|
102
|
+
return o ? { success: !1, error: o.message } : (s("/cms/products"), { success: !0, count: e.length });
|
|
79
103
|
}
|
|
80
|
-
async function
|
|
81
|
-
const
|
|
82
|
-
if (!
|
|
104
|
+
async function U(r) {
|
|
105
|
+
const e = String(r || "").trim();
|
|
106
|
+
if (!e)
|
|
83
107
|
return { error: "Missing product id." };
|
|
84
|
-
const t =
|
|
85
|
-
data: { user:
|
|
108
|
+
const t = i(), {
|
|
109
|
+
data: { user: o }
|
|
86
110
|
} = await t.auth.getUser();
|
|
87
|
-
if (!
|
|
111
|
+
if (!o)
|
|
88
112
|
return { error: "You must be signed in to publish a product." };
|
|
89
|
-
const { data:
|
|
113
|
+
const { data: a, error: c } = await t.from("products").update({
|
|
90
114
|
status: "active",
|
|
91
115
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
92
|
-
}).eq("id",
|
|
93
|
-
return
|
|
116
|
+
}).eq("id", e).select("slug").single();
|
|
117
|
+
return c || !a ? { error: c?.message || "Could not publish the product." } : (s("/cms/products"), s(`/cms/products/${e}/edit`), a.slug && s(`/product/${a.slug}`), {});
|
|
94
118
|
}
|
|
95
|
-
async function
|
|
96
|
-
const
|
|
97
|
-
if (!t || !
|
|
119
|
+
async function M(r) {
|
|
120
|
+
const e = n(), t = r.name.trim(), o = d(r.slug?.trim() || r.name);
|
|
121
|
+
if (!t || !o)
|
|
98
122
|
return { success: !1, error: "Attribute name is required." };
|
|
99
|
-
const { error:
|
|
123
|
+
const { error: a } = await e.from("product_attributes").insert({
|
|
100
124
|
name: t,
|
|
101
|
-
slug:
|
|
125
|
+
slug: o
|
|
102
126
|
});
|
|
103
|
-
return
|
|
127
|
+
return a ? { success: !1, error: a.message } : (s("/cms/products/attributes"), s("/cms/products/new"), s("/cms/products"), { success: !0 });
|
|
104
128
|
}
|
|
105
|
-
async function
|
|
106
|
-
const
|
|
129
|
+
async function B(r) {
|
|
130
|
+
const e = n(), { error: t } = await e.from("product_attributes").delete().eq("id", r);
|
|
107
131
|
return t ? { success: !1, error: t.message } : (s("/cms/products/attributes"), s("/cms/products/new"), s("/cms/products"), { success: !0 });
|
|
108
132
|
}
|
|
109
|
-
async function
|
|
110
|
-
const
|
|
111
|
-
if (!t || !
|
|
133
|
+
async function R(r) {
|
|
134
|
+
const e = n(), t = r.value.trim(), o = d(r.slug?.trim() || r.value);
|
|
135
|
+
if (!t || !o)
|
|
112
136
|
return { success: !1, error: "Term value is required." };
|
|
113
|
-
const { data:
|
|
114
|
-
attribute_id:
|
|
137
|
+
const { data: a } = await e.from("product_attribute_terms").select("sort_order").eq("attribute_id", r.attributeId).order("sort_order", { ascending: !1 }).limit(1), c = typeof a?.[0]?.sort_order == "number" ? a[0].sort_order + 1 : 0, { error: u } = await e.from("product_attribute_terms").insert({
|
|
138
|
+
attribute_id: r.attributeId,
|
|
115
139
|
value: t,
|
|
116
|
-
slug:
|
|
117
|
-
sort_order:
|
|
140
|
+
slug: o,
|
|
141
|
+
sort_order: c
|
|
118
142
|
});
|
|
119
|
-
return
|
|
143
|
+
return u ? { success: !1, error: u.message } : (s("/cms/products/attributes"), s("/cms/products/new"), s("/cms/products"), { success: !0 });
|
|
120
144
|
}
|
|
121
|
-
async function
|
|
122
|
-
const
|
|
123
|
-
for (const [t,
|
|
124
|
-
const { error:
|
|
145
|
+
async function G(r) {
|
|
146
|
+
const e = n();
|
|
147
|
+
for (const [t, o] of r.orderedTermIds.entries()) {
|
|
148
|
+
const { error: a } = await e.from("product_attribute_terms").update({
|
|
125
149
|
sort_order: t,
|
|
126
150
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
127
|
-
}).eq("id",
|
|
128
|
-
if (
|
|
129
|
-
return { success: !1, error:
|
|
151
|
+
}).eq("id", o).eq("attribute_id", r.attributeId);
|
|
152
|
+
if (a)
|
|
153
|
+
return { success: !1, error: a.message };
|
|
130
154
|
}
|
|
131
155
|
return s("/cms/products/attributes"), s("/cms/products/new"), s("/cms/products"), { success: !0 };
|
|
132
156
|
}
|
|
133
|
-
async function
|
|
134
|
-
const
|
|
135
|
-
name_translations:
|
|
157
|
+
async function L(r) {
|
|
158
|
+
const e = n(), { error: t } = await e.from("product_attributes").update({
|
|
159
|
+
name_translations: r.nameTranslations,
|
|
136
160
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
137
|
-
}).eq("id",
|
|
161
|
+
}).eq("id", r.attributeId);
|
|
138
162
|
if (t)
|
|
139
163
|
return { success: !1, error: t.message };
|
|
140
|
-
for (const
|
|
141
|
-
const { error:
|
|
142
|
-
value_translations:
|
|
164
|
+
for (const o of r.termTranslations) {
|
|
165
|
+
const { error: a } = await e.from("product_attribute_terms").update({
|
|
166
|
+
value_translations: o.valueTranslations,
|
|
143
167
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
144
|
-
}).eq("id",
|
|
145
|
-
if (
|
|
146
|
-
return { success: !1, error:
|
|
168
|
+
}).eq("id", o.termId).eq("attribute_id", r.attributeId);
|
|
169
|
+
if (a)
|
|
170
|
+
return { success: !1, error: a.message };
|
|
147
171
|
}
|
|
148
172
|
return s("/cms/products/attributes"), s("/cms/products/new"), s("/cms/products"), { success: !0 };
|
|
149
173
|
}
|
|
150
|
-
async function
|
|
151
|
-
const
|
|
174
|
+
async function V(r) {
|
|
175
|
+
const e = n(), { error: t } = await e.from("product_attribute_terms").delete().eq("id", r);
|
|
152
176
|
return t ? { success: !1, error: t.message } : (s("/cms/products/attributes"), s("/cms/products/new"), s("/cms/products"), { success: !0 });
|
|
153
177
|
}
|
|
154
|
-
async function
|
|
155
|
-
const
|
|
156
|
-
if (!t || !
|
|
178
|
+
async function Y(r) {
|
|
179
|
+
const e = n(), t = r.name.trim(), o = d(r.slug?.trim() || r.name);
|
|
180
|
+
if (!t || !o)
|
|
157
181
|
return { success: !1, error: "Category name is required." };
|
|
158
|
-
const { data:
|
|
182
|
+
const { data: a, error: c } = await e.from("categories").insert({
|
|
159
183
|
name: t,
|
|
160
|
-
slug: c,
|
|
161
|
-
description: e.description?.trim() || null,
|
|
162
|
-
name_translations: e.nameTranslations || {},
|
|
163
|
-
description_translations: e.descriptionTranslations || {}
|
|
164
|
-
}).select().single();
|
|
165
|
-
return a ? { success: !1, error: a.message } : (s("/cms/products/categories"), s("/cms/products/new"), s("/cms/products"), { success: !0, category: o });
|
|
166
|
-
}
|
|
167
|
-
async function B(e, r) {
|
|
168
|
-
const t = n(), c = r.name.trim(), o = d(r.slug?.trim() || r.name);
|
|
169
|
-
if (!c || !o)
|
|
170
|
-
return { success: !1, error: "Category name is required." };
|
|
171
|
-
const { error: a } = await t.from("categories").update({
|
|
172
|
-
name: c,
|
|
173
184
|
slug: o,
|
|
174
185
|
description: r.description?.trim() || null,
|
|
175
186
|
name_translations: r.nameTranslations || {},
|
|
176
187
|
description_translations: r.descriptionTranslations || {}
|
|
177
|
-
}).
|
|
178
|
-
return
|
|
188
|
+
}).select().single();
|
|
189
|
+
return c ? { success: !1, error: c.message } : (s("/cms/products/categories"), s("/cms/products/new"), s("/cms/products"), { success: !0, category: a });
|
|
190
|
+
}
|
|
191
|
+
async function j(r, e) {
|
|
192
|
+
const t = n(), o = e.name.trim(), a = d(e.slug?.trim() || e.name);
|
|
193
|
+
if (!o || !a)
|
|
194
|
+
return { success: !1, error: "Category name is required." };
|
|
195
|
+
const { error: c } = await t.from("categories").update({
|
|
196
|
+
name: o,
|
|
197
|
+
slug: a,
|
|
198
|
+
description: e.description?.trim() || null,
|
|
199
|
+
name_translations: e.nameTranslations || {},
|
|
200
|
+
description_translations: e.descriptionTranslations || {}
|
|
201
|
+
}).eq("id", r);
|
|
202
|
+
return c ? { success: !1, error: c.message } : (s("/cms/products/categories"), s("/cms/products/new"), s("/cms/products"), { success: !0 });
|
|
179
203
|
}
|
|
180
|
-
async function
|
|
181
|
-
const
|
|
204
|
+
async function H(r) {
|
|
205
|
+
const e = n(), { error: t } = await e.from("categories").delete().eq("id", r);
|
|
182
206
|
return t ? { success: !1, error: t.message } : (s("/cms/products/categories"), s("/cms/products/new"), s("/cms/products"), { success: !0 });
|
|
183
207
|
}
|
|
184
|
-
async function
|
|
208
|
+
async function J(r, e) {
|
|
185
209
|
const t = n();
|
|
186
210
|
try {
|
|
187
|
-
return await
|
|
188
|
-
} catch (
|
|
189
|
-
return { success: !1, error:
|
|
211
|
+
return await A(t, r, e), s("/cms/products"), s(`/cms/products/${r}/edit`), { success: !0 };
|
|
212
|
+
} catch (o) {
|
|
213
|
+
return { success: !1, error: o.message };
|
|
190
214
|
}
|
|
191
215
|
}
|
|
192
216
|
export {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
217
|
+
O as bulkDeleteProductsAction,
|
|
218
|
+
z as bulkDraftProductsAction,
|
|
219
|
+
Y as createCategoryAction,
|
|
220
|
+
F as createProductAction,
|
|
221
|
+
M as createProductAttributeAction,
|
|
222
|
+
R as createProductAttributeTermAction,
|
|
223
|
+
H as deleteCategoryAction,
|
|
224
|
+
$ as deleteProductAction,
|
|
225
|
+
B as deleteProductAttributeAction,
|
|
226
|
+
V as deleteProductAttributeTermAction,
|
|
227
|
+
U as publishProductAction,
|
|
228
|
+
G as reorderProductAttributeTermsAction,
|
|
229
|
+
J as syncProductCategoriesAction,
|
|
230
|
+
j as updateCategoryAction,
|
|
231
|
+
k as updateProductAction,
|
|
232
|
+
L as updateProductAttributeTranslationsAction
|
|
209
233
|
};
|