@nextblock-cms/ecom 0.16.3 → 0.16.4
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/pages/cms/products/ProductsPage.cjs.js +1 -1
- package/lib/pages/cms/products/ProductsPage.es.js +66 -45
- package/lib/pages/cms/products/actions.d.ts +2 -0
- package/lib/pages/cms/products/components/ProductForm.cjs.js +1 -1
- package/lib/pages/cms/products/components/ProductForm.d.ts +7 -1
- package/lib/pages/cms/products/components/ProductForm.es.js +343 -336
- package/lib/pages/cms/products/components/ProductsBulkTable.cjs.js +1 -1
- package/lib/pages/cms/products/components/ProductsBulkTable.d.ts +1 -0
- package/lib/pages/cms/products/components/ProductsBulkTable.es.js +346 -194
- package/lib/product-actions.cjs.js +3 -3
- package/lib/product-actions.d.ts +2 -0
- package/lib/product-actions.es.js +1 -1
- package/package.json +4 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("@nextblock-cms/utils/server"),P=require("./shared-inventory.cjs.js"),M=require("@nextblock-cms/utils/utils"),C=require("@nextblock-cms/utils"),w=e=>Math.round(e*100);function q(e){return Object.entries(e||{}).reduce((t,[r,i])=>(typeof i=="number"&&Number.isFinite(i)&&i>=0&&(t[M.normalizeCurrencyCode(r)]=w(i)),t),{})}function E(e){return(e||[]).map(t=>({id:t.id,sku:t.sku,upc:t.upc??null,price:w(t.price),sale_price:typeof t.sale_price=="number"&&!isNaN(t.sale_price)?w(t.sale_price):null,prices:q(t.prices),sale_prices:q(t.sale_prices),sale_start_at:t.sale_start_at??null,sale_end_at:t.sale_end_at??null,stock_quantity:t.stock_quantity,main_media_id:t.main_media_id??null,attribute_term_ids:t.attribute_term_ids}))}function S(e,t){const i=e.product_type==="digital"&&e.payment_provider==="freemius"?Math.max(0,Number(e.trial_period_days??0)):0;return{id:t,product_type:e.product_type,payment_provider:e.payment_provider,title:e.title,slug:e.slug,sku:e.sku,upc:e.upc??null,stock:e.stock,status:e.status,short_description:e.short_description??null,description_json:e.description_json??null,metadata:{},price:w(e.price),sale_price:typeof e.sale_price=="number"&&!isNaN(e.sale_price)?w(e.sale_price):null,prices:q(e.prices),sale_prices:q(e.sale_prices),sale_start_at:e.sale_start_at??null,sale_end_at:e.sale_end_at??null,freemius_plan_id:e.freemius_plan_id??null,freemius_product_id:e.freemius_product_id??null,trial_period_days:i,trial_requires_payment_method:i>0?e.trial_requires_payment_method??!1:!1,is_taxable:e.is_taxable,language_id:e.language_id,translation_group_id:e.translation_group_id||void 0,variants:E(e.variants)}}async function j(e,t,r){const i=
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("@nextblock-cms/utils/server"),P=require("./shared-inventory.cjs.js"),M=require("@nextblock-cms/utils/utils"),C=require("@nextblock-cms/utils"),w=e=>Math.round(e*100);function q(e){return Object.entries(e||{}).reduce((t,[r,i])=>(typeof i=="number"&&Number.isFinite(i)&&i>=0&&(t[M.normalizeCurrencyCode(r)]=w(i)),t),{})}function E(e){return(e||[]).map(t=>({id:t.id,sku:t.sku,upc:t.upc??null,price:w(t.price),sale_price:typeof t.sale_price=="number"&&!isNaN(t.sale_price)?w(t.sale_price):null,prices:q(t.prices),sale_prices:q(t.sale_prices),sale_start_at:t.sale_start_at??null,sale_end_at:t.sale_end_at??null,stock_quantity:t.stock_quantity,main_media_id:t.main_media_id??null,attribute_term_ids:t.attribute_term_ids}))}function S(e,t){const i=e.product_type==="digital"&&e.payment_provider==="freemius"?Math.max(0,Number(e.trial_period_days??0)):0;return{id:t,product_type:e.product_type,payment_provider:e.payment_provider,title:e.title,slug:e.slug,sku:e.sku,upc:e.upc??null,stock:e.stock,status:e.status,short_description:e.short_description??null,description_json:e.description_json??null,metadata:{},price:w(e.price),sale_price:typeof e.sale_price=="number"&&!isNaN(e.sale_price)?w(e.sale_price):null,prices:q(e.prices),sale_prices:q(e.sale_prices),sale_start_at:e.sale_start_at??null,sale_end_at:e.sale_end_at??null,freemius_plan_id:e.freemius_plan_id??null,freemius_product_id:e.freemius_product_id??null,trial_period_days:i,trial_requires_payment_method:i>0?e.trial_requires_payment_method??!1:!1,is_taxable:e.is_taxable,language_id:e.language_id,translation_group_id:e.translation_group_id||void 0,variants:E(e.variants)}}async function j(e,t,r){const i=o=>{const a=typeof o=="string"?o.trim():"";return a||null},{error:s}=await e.from("products").update({meta_title:i(r.meta_title),meta_description:i(r.meta_description),custom_canonical:i(r.custom_canonical),updated_at:new Date().toISOString()}).eq("id",t);if(s)throw s}async function x(e,t,r){const{error:i}=await e.from("products").update({is_taxable:r,updated_at:new Date().toISOString()}).eq("id",t);if(i)throw i}async function F(e,t,r){const i=new Date().toISOString(),{data:s}=await e.from("products").select("sku, sale_price, sale_prices").eq("id",t).maybeSingle(),o=s?.sku??r.sku,{data:a}=await e.from("products").select("id").eq("sku",o),c=(a??[]).map(n=>n.id);c.length===0&&c.push(t);const{error:_}=await e.from("products").update({sale_price:s?.sale_price??null,sale_prices:s?.sale_prices??null,sale_start_at:r.sale_start_at??null,sale_end_at:r.sale_end_at??null,updated_at:i}).in("id",c);if(_)throw _;const l=r.variants??[];if(l.length===0)return;const{data:p}=await e.from("product_variants").select("sku, sale_price, sale_prices").eq("product_id",t),f=new Map((p??[]).map(n=>[n.sku,n]));for(const n of l){const u=f.get(n.sku);if(!u)continue;const{error:d}=await e.from("product_variants").update({sale_price:u.sale_price??null,sale_prices:u.sale_prices??null,sale_start_at:n.sale_start_at??null,sale_end_at:n.sale_end_at??null,updated_at:i}).eq("sku",n.sku).in("product_id",c);if(d)throw d}}async function A(e,{page:t=1,limit:r=10,offset:i,search:s="",languageId:o,categoryId:a,categoryIds:c,productIds:_,translationGroupIds:l,status:p="active"}={}){const f=r>0,n=typeof i=="number"?Math.max(0,i):(t-1)*r,u=n+r-1;let d=e.from("products").select("id, title, meta_title, meta_description, average_rating, total_reviews, sku, upc, price, prices, sale_price, sale_prices, sale_start_at, sale_end_at, scheduled_price, scheduled_prices, scheduled_price_at, is_taxable, product_type, payment_provider, short_description, stock, status, slug, language_id, translation_group_id, freemius_product_id, freemius_plan_id, trial_period_days, trial_requires_payment_method, product_media(media(file_path, object_key)), product_variants(id, price, prices, sale_price, sale_prices, sale_start_at, sale_end_at, scheduled_price, scheduled_prices, scheduled_price_at), freemius_plans(id, name, title, freemius_pricing(id, license_quota, api_monthly_price, api_annual_price, api_lifetime_price, override_monthly_price, override_annual_price, override_lifetime_price, is_active)), product_categories(category:categories(id, name, slug, description, name_translations, description_translations))",{count:"exact"}).order("created_at",{ascending:!1});if(f&&(d=d.range(n,u)),p!=="all"&&(d=d.eq("status",p)),o&&(d=d.eq("language_id",o)),_){if(_.length===0)return{data:[],error:null,count:0};d=d.in("id",_)}if(l){if(l.length===0)return{data:[],error:null,count:0};d=d.in("translation_group_id",l)}const g=c?.length?c:a?[a]:[];if(g.length>0){const{data:y,error:m}=await e.from("product_categories").select("product_id").in("category_id",g);if(m)return{data:[],error:m,count:0};const h=Array.from(new Set((y||[]).map(v=>v.product_id).filter(Boolean)));if(h.length===0)return{data:[],error:null,count:0};d=d.in("id",h)}return s&&(d=d.or(`title.ilike.%${s}%,sku.ilike.%${s}%`)),d}async function T(e,t){return e.from("products").select(`
|
|
2
2
|
*,
|
|
3
3
|
languages (
|
|
4
4
|
code
|
|
@@ -166,7 +166,7 @@
|
|
|
166
166
|
description_translations
|
|
167
167
|
)
|
|
168
168
|
)
|
|
169
|
-
`).eq("slug",t);if(s)return{data:null,error:s};if(!i||i.length===0)return{data:null,error:{message:"Product not found",code:"PGRST116"}};let
|
|
169
|
+
`).eq("slug",t);if(s)return{data:null,error:s};if(!i||i.length===0)return{data:null,error:{message:"Product not found",code:"PGRST116"}};let o=null;return r&&(o=i.find(a=>(Array.isArray(a.languages)?a.languages[0]:a.languages)?.code===r)),o||(o=i.find(a=>(Array.isArray(a.languages)?a.languages[0]:a.languages)?.is_default)),o||(o=i.find(a=>(Array.isArray(a.languages)?a.languages[0]:a.languages)?.code==="en")),o||(o=i[0]),{data:o,error:null}}async function $(e,t){const{data:r,error:i}=await e.rpc("upsert_product_with_variants",{product_payload:S(t)});if(i||!r)throw i||new Error("Failed to create product");if(t.product_media&&t.product_media.length>0){const o=t.product_media.map((a,c)=>({product_id:r,media_id:a.media_id,sort_order:c}));await e.from("product_media").insert(o)}else t.media_id&&await e.from("product_media").insert({product_id:r,media_id:t.media_id,sort_order:0});await x(e,r,t.is_taxable),await j(e,r,t),await F(e,r,t),await P.syncSharedInventoryForSavedProduct(r,t),t.category_ids!==void 0&&await k(e,r,t.category_ids);const{data:s}=await e.from("products").select("*").eq("id",r).single();return s}async function D(e,t,r){const{data:i}=await e.from("product_media").select("media_id").eq("product_id",t),s=i?.map(n=>n.media_id)||[],{data:o,error:a}=await e.rpc("upsert_product_with_variants",{product_payload:S(r,t)});if(a||!o)throw a||new Error("Failed to update product");if(r.product_media){if(await e.from("product_media").delete().eq("product_id",t),r.product_media.length>0){const n=r.product_media.map((u,d)=>({product_id:t,media_id:u.media_id,sort_order:d}));await e.from("product_media").insert(n)}}else r.media_id&&(await e.from("product_media").delete().eq("product_id",t),await e.from("product_media").insert({product_id:t,media_id:r.media_id,sort_order:0}));await x(e,o,r.is_taxable),await j(e,o,r),await F(e,o,r);const c=r.product_media?r.product_media.map(n=>n.media_id):r.media_id?[r.media_id]:[],_=r.explicitly_removed_media_ids||[],l=s.filter(n=>!c.includes(n)),p=Array.from(new Set([...l,..._]));if(p.length>0)for(const n of p){const{count:u}=await e.from("product_media").select("*",{count:"exact",head:!0}).eq("media_id",n);if(u&&u>0)continue;const{count:d}=await e.from("posts").select("*",{count:"exact",head:!0}).eq("feature_image_id",n);if(d&&d>0)continue;const{count:g}=await e.from("logos").select("*",{count:"exact",head:!0}).eq("media_id",n);if(g&&g>0)continue;const{count:y}=await e.from("product_variants").select("*",{count:"exact",head:!0}).eq("main_media_id",n);if(y&&y>0)continue;const{data:m}=await e.from("media").select("object_key, variants").eq("id",n).single();if(m){const h=[m.object_key];m.variants&&Array.isArray(m.variants)&&m.variants.forEach(v=>{v.objectKey&&h.push(v.objectKey)}),await b.deleteMediaFiles(h),await e.from("media").delete().eq("id",n)}}await P.syncSharedInventoryForSavedProduct(o,r),r.category_ids!==void 0&&await k(e,t,r.category_ids);const{data:f}=await e.from("products").select("*").eq("id",o).single();return f}async function N(e,t){const{error:r}=await e.from("products").delete().eq("id",t);if(r)throw r;return!0}async function O(e,t,r){const{data:i,error:s}=await e.from("products").select("*").eq("id",r).single();if(s||!i)throw new Error(s?.message||"Source product not found");const{data:o,error:a}=await e.from("products").select("language_id").eq("id",t).single();if(a||!o)throw new Error(a?.message||"Target product not found");const{error:c}=await e.from("products").update({title:i.title,short_description:i.short_description,description_json:i.description_json}).eq("id",t);if(c)throw c;const{data:_,error:l}=await e.from("blocks").select("*").eq("product_id",r).order("order",{ascending:!0});if(l)throw l;if(await e.from("blocks").delete().eq("product_id",t),_&&_.length>0){const f=_.map(u=>{const{id:d,created_at:g,updated_at:y,...m}=u;return{...m,product_id:t,language_id:o.language_id}}),{error:n}=await e.from("blocks").insert(f);if(n)throw n}await e.from("product_drafts").delete().eq("product_id",t),await e.from("product_media").delete().eq("product_id",t);const{data:p}=await e.from("product_media").select("media_id, sort_order").eq("product_id",r);if(p&&p.length>0){const f=p.map(n=>({product_id:t,media_id:n.media_id,sort_order:n.sort_order}));await e.from("product_media").insert(f)}return{success:!0}}async function B(e,t,r,i=[],s=[]){const{data:o}=await e.from("languages").select("id").eq("code",r).single();if(!o)return{data:[],error:"Language not found"};const a=[];t.length>0&&a.push(`translation_group_id.in.(${t.join(",")})`),i.length>0&&a.push(`sku.in.(${i.map(l=>`"${l}"`).join(",")})`),s.length>0&&a.push(`id.in.(${s.join(",")})`);let c=e.from("products").select(`
|
|
170
170
|
id,
|
|
171
171
|
title,
|
|
172
172
|
sku,
|
|
@@ -234,4 +234,4 @@
|
|
|
234
234
|
)
|
|
235
235
|
),
|
|
236
236
|
translation_group_id
|
|
237
|
-
`).eq("language_id",
|
|
237
|
+
`).eq("language_id",o.id).eq("status","active").or(C.buildPublishedAtOrFilter());return a.length>0&&(c=c.or(a.join(","))),await c.order("id")}async function k(e,t,r){const{data:i}=await e.from("products").select("translation_group_id").eq("id",t).single();if(!i||!i.translation_group_id){if(await e.from("product_categories").delete().eq("product_id",t),r.length>0){const a=r.map(c=>({product_id:t,category_id:c}));await e.from("product_categories").insert(a)}return}const{data:s}=await e.from("products").select("id").eq("translation_group_id",i.translation_group_id),o=s&&s.length>0?s.map(a=>a.id):[t];if(await e.from("product_categories").delete().in("product_id",o),r.length>0){const a=[];for(const c of o)for(const _ of r)a.push({product_id:c,category_id:_});await e.from("product_categories").insert(a)}}exports.copyProductFromLanguage=O;exports.createProduct=$;exports.deleteProduct=N;exports.fetchTranslatedProductsForCartInternal=B;exports.getProduct=T;exports.getProductBySlug=R;exports.getProducts=A;exports.syncCategoriesForTranslationGroup=k;exports.updateProduct=D;
|
package/lib/product-actions.d.ts
CHANGED
|
@@ -21,6 +21,8 @@ export declare function getProducts(supabase: SupabaseClient<Database>, { page,
|
|
|
21
21
|
}): Promise<import('@supabase/postgrest-js').PostgrestResponseFailure | import('@supabase/postgrest-js').PostgrestResponseSuccess<{
|
|
22
22
|
id: string;
|
|
23
23
|
title: string;
|
|
24
|
+
meta_title: string | null;
|
|
25
|
+
meta_description: string | null;
|
|
24
26
|
average_rating: number;
|
|
25
27
|
total_reviews: number;
|
|
26
28
|
sku: string;
|
|
@@ -124,7 +124,7 @@ async function N(e, {
|
|
|
124
124
|
} = {}) {
|
|
125
125
|
const f = i > 0, n = typeof r == "number" ? Math.max(0, r) : (t - 1) * i, u = n + i - 1;
|
|
126
126
|
let d = e.from("products").select(
|
|
127
|
-
"id, title, average_rating, total_reviews, sku, upc, price, prices, sale_price, sale_prices, sale_start_at, sale_end_at, scheduled_price, scheduled_prices, scheduled_price_at, is_taxable, product_type, payment_provider, short_description, stock, status, slug, language_id, translation_group_id, freemius_product_id, freemius_plan_id, trial_period_days, trial_requires_payment_method, product_media(media(file_path, object_key)), product_variants(id, price, prices, sale_price, sale_prices, sale_start_at, sale_end_at, scheduled_price, scheduled_prices, scheduled_price_at), freemius_plans(id, name, title, freemius_pricing(id, license_quota, api_monthly_price, api_annual_price, api_lifetime_price, override_monthly_price, override_annual_price, override_lifetime_price, is_active)), product_categories(category:categories(id, name, slug, description, name_translations, description_translations))",
|
|
127
|
+
"id, title, meta_title, meta_description, average_rating, total_reviews, sku, upc, price, prices, sale_price, sale_prices, sale_start_at, sale_end_at, scheduled_price, scheduled_prices, scheduled_price_at, is_taxable, product_type, payment_provider, short_description, stock, status, slug, language_id, translation_group_id, freemius_product_id, freemius_plan_id, trial_period_days, trial_requires_payment_method, product_media(media(file_path, object_key)), product_variants(id, price, prices, sale_price, sale_prices, sale_start_at, sale_end_at, scheduled_price, scheduled_prices, scheduled_price_at), freemius_plans(id, name, title, freemius_pricing(id, license_quota, api_monthly_price, api_annual_price, api_lifetime_price, override_monthly_price, override_annual_price, override_lifetime_price, is_active)), product_categories(category:categories(id, name, slug, description, name_translations, description_translations))",
|
|
128
128
|
{ count: "exact" }
|
|
129
129
|
).order("created_at", { ascending: !1 });
|
|
130
130
|
if (f && (d = d.range(n, u)), p !== "all" && (d = d.eq("status", p)), o && (d = d.eq("language_id", o)), _) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nextblock-cms/ecom",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.4",
|
|
4
4
|
"license": "AGPL-3.0-or-later",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
},
|
|
12
12
|
"type": "module",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@nextblock-cms/db": "^0.16.
|
|
15
|
-
"@nextblock-cms/ui": "^0.16.
|
|
16
|
-
"@nextblock-cms/utils": "^0.16.
|
|
14
|
+
"@nextblock-cms/db": "^0.16.4",
|
|
15
|
+
"@nextblock-cms/ui": "^0.16.4",
|
|
16
|
+
"@nextblock-cms/utils": "^0.16.4",
|
|
17
17
|
"@freemius/checkout": "^1.4.1",
|
|
18
18
|
"@freemius/sdk": "^0.3.0",
|
|
19
19
|
"@hookform/resolvers": "^5.2.2",
|