@nextblock-cms/ecom 0.13.5 → 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.
|
@@ -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
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nextblock-cms/ecom",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.6",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
},
|
|
11
11
|
"type": "module",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@nextblock-cms/db": "^0.13.
|
|
14
|
-
"@nextblock-cms/ui": "^0.13.
|
|
15
|
-
"@nextblock-cms/utils": "^0.13.
|
|
13
|
+
"@nextblock-cms/db": "^0.13.6",
|
|
14
|
+
"@nextblock-cms/ui": "^0.13.6",
|
|
15
|
+
"@nextblock-cms/utils": "^0.13.6",
|
|
16
16
|
"@freemius/checkout": "^1.4.1",
|
|
17
17
|
"@freemius/sdk": "^0.3.0",
|
|
18
18
|
"@hookform/resolvers": "^5.2.2",
|