@nextblock-cms/ecom 0.11.2 → 0.12.0

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,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const F=require("@nextblock-cms/utils/server"),P=require("./shared-inventory.cjs.js"),b=require("@nextblock-cms/utils/utils"),g=e=>Math.round(e*100);function y(e){return Object.entries(e||{}).reduce((t,[r,i])=>(typeof i=="number"&&Number.isFinite(i)&&i>=0&&(t[b.normalizeCurrencyCode(r)]=g(i)),t),{})}function E(e){return(e||[]).map(t=>({id:t.id,sku:t.sku,upc:t.upc??null,price:g(t.price),sale_price:typeof t.sale_price=="number"&&!isNaN(t.sale_price)?g(t.sale_price):null,prices:y(t.prices),sale_prices:y(t.sale_prices),sale_start_at:t.sale_start_at??null,sale_end_at:t.sale_end_at??null,stock_quantity:t.stock_quantity,main_media_id:t.main_media_id??null,attribute_term_ids:t.attribute_term_ids}))}function j(e,t){const i=e.product_type==="digital"&&e.payment_provider==="freemius"?Math.max(0,Number(e.trial_period_days??0)):0;return{id:t,product_type:e.product_type,payment_provider:e.payment_provider,title:e.title,slug:e.slug,sku:e.sku,upc:e.upc??null,stock:e.stock,status:e.status,short_description:e.short_description??null,description_json:e.description_json??null,metadata:{},price:g(e.price),sale_price:typeof e.sale_price=="number"&&!isNaN(e.sale_price)?g(e.sale_price):null,prices:y(e.prices),sale_prices:y(e.sale_prices),sale_start_at:e.sale_start_at??null,sale_end_at:e.sale_end_at??null,freemius_plan_id:e.freemius_plan_id??null,freemius_product_id:e.freemius_product_id??null,trial_period_days:i,trial_requires_payment_method:i>0?e.trial_requires_payment_method??!1:!1,is_taxable:e.is_taxable,language_id:e.language_id,translation_group_id:e.translation_group_id||void 0,variants:E(e.variants)}}async function S(e,t,r){const{error:i}=await e.from("products").update({is_taxable:r,updated_at:new Date().toISOString()}).eq("id",t);if(i)throw i}async function x(e,t,r){const i=new Date().toISOString(),{data:c}=await e.from("products").select("sku, sale_price, sale_prices").eq("id",t).maybeSingle(),s=c?.sku??r.sku,{data:a}=await e.from("products").select("id").eq("sku",s),d=(a??[]).map(o=>o.id);d.length===0&&d.push(t);const{error:n}=await e.from("products").update({sale_price:c?.sale_price??null,sale_prices:c?.sale_prices??null,sale_start_at:r.sale_start_at??null,sale_end_at:r.sale_end_at??null,updated_at:i}).in("id",d);if(n)throw n;const _=r.variants??[];if(_.length===0)return;const{data:l}=await e.from("product_variants").select("sku, sale_price, sale_prices").eq("product_id",t),u=new Map((l??[]).map(o=>[o.sku,o]));for(const o of _){const p=u.get(o.sku);if(!p)continue;const{error:m}=await e.from("product_variants").update({sale_price:p.sale_price??null,sale_prices:p.sale_prices??null,sale_start_at:o.sale_start_at??null,sale_end_at:o.sale_end_at??null,updated_at:i}).eq("sku",o.sku).in("product_id",d);if(m)throw m}}async function C(e,{page:t=1,limit:r=10,search:i="",languageId:c,categoryId:s}={}){const a=(t-1)*r,d=a+r-1;let n=e.from("products").select("id, title, 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"}).range(a,d).order("created_at",{ascending:!1});if(c&&(n=n.eq("language_id",c)),s){const{data:_,error:l}=await e.from("product_categories").select("product_id").eq("category_id",s);if(l)return{data:[],error:l,count:0};const u=(_||[]).map(o=>o.product_id).filter(Boolean);if(u.length===0)return{data:[],error:null,count:0};n=n.in("id",u)}return i&&(n=n.or(`title.ilike.%${i}%,sku.ilike.%${i}%`)),n}async function M(e,t){return e.from("products").select(`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("@nextblock-cms/utils/server"),P=require("./shared-inventory.cjs.js"),E=require("@nextblock-cms/utils/utils"),g=e=>Math.round(e*100);function y(e){return Object.entries(e||{}).reduce((t,[r,i])=>(typeof i=="number"&&Number.isFinite(i)&&i>=0&&(t[E.normalizeCurrencyCode(r)]=g(i)),t),{})}function M(e){return(e||[]).map(t=>({id:t.id,sku:t.sku,upc:t.upc??null,price:g(t.price),sale_price:typeof t.sale_price=="number"&&!isNaN(t.sale_price)?g(t.sale_price):null,prices:y(t.prices),sale_prices:y(t.sale_prices),sale_start_at:t.sale_start_at??null,sale_end_at:t.sale_end_at??null,stock_quantity:t.stock_quantity,main_media_id:t.main_media_id??null,attribute_term_ids:t.attribute_term_ids}))}function 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:g(e.price),sale_price:typeof e.sale_price=="number"&&!isNaN(e.sale_price)?g(e.sale_price):null,prices:y(e.prices),sale_prices:y(e.sale_prices),sale_start_at:e.sale_start_at??null,sale_end_at:e.sale_end_at??null,freemius_plan_id:e.freemius_plan_id??null,freemius_product_id:e.freemius_product_id??null,trial_period_days:i,trial_requires_payment_method:i>0?e.trial_requires_payment_method??!1:!1,is_taxable:e.is_taxable,language_id:e.language_id,translation_group_id:e.translation_group_id||void 0,variants:M(e.variants)}}async function j(e,t,r){const i=a=>{const o=typeof a=="string"?a.trim():"";return o||null},{error:c}=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(c)throw c}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:c}=await e.from("products").select("sku, sale_price, sale_prices").eq("id",t).maybeSingle(),a=c?.sku??r.sku,{data:o}=await e.from("products").select("id").eq("sku",a),d=(o??[]).map(s=>s.id);d.length===0&&d.push(t);const{error:n}=await e.from("products").update({sale_price:c?.sale_price??null,sale_prices:c?.sale_prices??null,sale_start_at:r.sale_start_at??null,sale_end_at:r.sale_end_at??null,updated_at:i}).in("id",d);if(n)throw n;const _=r.variants??[];if(_.length===0)return;const{data:l}=await e.from("product_variants").select("sku, sale_price, sale_prices").eq("product_id",t),u=new Map((l??[]).map(s=>[s.sku,s]));for(const s of _){const p=u.get(s.sku);if(!p)continue;const{error:m}=await e.from("product_variants").update({sale_price:p.sale_price??null,sale_prices:p.sale_prices??null,sale_start_at:s.sale_start_at??null,sale_end_at:s.sale_end_at??null,updated_at:i}).eq("sku",s.sku).in("product_id",d);if(m)throw m}}async function C(e,{page:t=1,limit:r=10,search:i="",languageId:c,categoryId:a}={}){const o=(t-1)*r,d=o+r-1;let n=e.from("products").select("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))",{count:"exact"}).range(o,d).order("created_at",{ascending:!1});if(c&&(n=n.eq("language_id",c)),a){const{data:_,error:l}=await e.from("product_categories").select("product_id").eq("category_id",a);if(l)return{data:[],error:l,count:0};const u=(_||[]).map(s=>s.product_id).filter(Boolean);if(u.length===0)return{data:[],error:null,count:0};n=n.in("id",u)}return i&&(n=n.or(`title.ilike.%${i}%,sku.ilike.%${i}%`)),n}async function T(e,t){return e.from("products").select(`
2
2
  *,
3
3
  languages (
4
4
  code
@@ -81,7 +81,7 @@
81
81
  description_translations
82
82
  )
83
83
  )
84
- `).eq("id",t).single()}async function T(e,t,r){const{data:i,error:c}=await e.from("products").select(`
84
+ `).eq("id",t).single()}async function A(e,t,r){const{data:i,error:c}=await e.from("products").select(`
85
85
  *,
86
86
  languages (
87
87
  id,
@@ -166,7 +166,7 @@
166
166
  description_translations
167
167
  )
168
168
  )
169
- `).eq("slug",t);if(c)return{data:null,error:c};if(!i||i.length===0)return{data:null,error:{message:"Product not found",code:"PGRST116"}};let s=null;return r&&(s=i.find(a=>(Array.isArray(a.languages)?a.languages[0]:a.languages)?.code===r)),s||(s=i.find(a=>(Array.isArray(a.languages)?a.languages[0]:a.languages)?.is_default)),s||(s=i.find(a=>(Array.isArray(a.languages)?a.languages[0]:a.languages)?.code==="en")),s||(s=i[0]),{data:s,error:null}}async function A(e,t){const{data:r,error:i}=await e.rpc("upsert_product_with_variants",{product_payload:j(t)});if(i||!r)throw i||new Error("Failed to create product");if(t.product_media&&t.product_media.length>0){const s=t.product_media.map((a,d)=>({product_id:r,media_id:a.media_id,sort_order:d}));await e.from("product_media").insert(s)}else t.media_id&&await e.from("product_media").insert({product_id:r,media_id:t.media_id,sort_order:0});await S(e,r,t.is_taxable),await x(e,r,t),await P.syncSharedInventoryForSavedProduct(r,t),t.category_ids!==void 0&&await v(e,r,t.category_ids);const{data:c}=await e.from("products").select("*").eq("id",r).single();return c}async function R(e,t,r){const{data:i}=await e.from("product_media").select("media_id").eq("product_id",t),c=i?.map(o=>o.media_id)||[],{data:s,error:a}=await e.rpc("upsert_product_with_variants",{product_payload:j(r,t)});if(a||!s)throw a||new Error("Failed to update product");if(r.product_media){if(await e.from("product_media").delete().eq("product_id",t),r.product_media.length>0){const o=r.product_media.map((p,m)=>({product_id:t,media_id:p.media_id,sort_order:m}));await e.from("product_media").insert(o)}}else r.media_id&&(await e.from("product_media").delete().eq("product_id",t),await e.from("product_media").insert({product_id:t,media_id:r.media_id,sort_order:0}));await S(e,s,r.is_taxable),await x(e,s,r);const d=r.product_media?r.product_media.map(o=>o.media_id):r.media_id?[r.media_id]:[],n=r.explicitly_removed_media_ids||[],_=c.filter(o=>!d.includes(o)),l=Array.from(new Set([..._,...n]));if(l.length>0)for(const o of l){const{count:p}=await e.from("product_media").select("*",{count:"exact",head:!0}).eq("media_id",o);if(p&&p>0)continue;const{count:m}=await e.from("posts").select("*",{count:"exact",head:!0}).eq("feature_image_id",o);if(m&&m>0)continue;const{count:h}=await e.from("logos").select("*",{count:"exact",head:!0}).eq("media_id",o);if(h&&h>0)continue;const{count:w}=await e.from("product_variants").select("*",{count:"exact",head:!0}).eq("main_media_id",o);if(w&&w>0)continue;const{data:f}=await e.from("media").select("object_key, variants").eq("id",o).single();if(f){const q=[f.object_key];f.variants&&Array.isArray(f.variants)&&f.variants.forEach(k=>{k.objectKey&&q.push(k.objectKey)}),await F.deleteMediaFiles(q),await e.from("media").delete().eq("id",o)}}await P.syncSharedInventoryForSavedProduct(s,r),r.category_ids!==void 0&&await v(e,t,r.category_ids);const{data:u}=await e.from("products").select("*").eq("id",s).single();return u}async function I(e,t){const{error:r}=await e.from("products").delete().eq("id",t);if(r)throw r;return!0}async function N(e,t,r){const{data:i,error:c}=await e.from("products").select("*").eq("id",r).single();if(c||!i)throw new Error(c?.message||"Source product not found");const{data:s,error:a}=await e.from("products").select("language_id").eq("id",t).single();if(a||!s)throw new Error(a?.message||"Target product not found");const{error:d}=await e.from("products").update({title:i.title,short_description:i.short_description,description_json:i.description_json}).eq("id",t);if(d)throw d;const{data:n,error:_}=await e.from("blocks").select("*").eq("product_id",r).order("order",{ascending:!0});if(_)throw _;if(await e.from("blocks").delete().eq("product_id",t),n&&n.length>0){const u=n.map(p=>{const{id:m,created_at:h,updated_at:w,...f}=p;return{...f,product_id:t,language_id:s.language_id}}),{error:o}=await e.from("blocks").insert(u);if(o)throw o}await e.from("product_drafts").delete().eq("product_id",t),await e.from("product_media").delete().eq("product_id",t);const{data:l}=await e.from("product_media").select("media_id, sort_order").eq("product_id",r);if(l&&l.length>0){const u=l.map(o=>({product_id:t,media_id:o.media_id,sort_order:o.sort_order}));await e.from("product_media").insert(u)}return{success:!0}}async function $(e,t,r,i=[],c=[]){const{data:s}=await e.from("languages").select("id").eq("code",r).single();if(!s)return{data:[],error:"Language not found"};const a=[];t.length>0&&a.push(`translation_group_id.in.(${t.join(",")})`),i.length>0&&a.push(`sku.in.(${i.map(_=>`"${_}"`).join(",")})`),c.length>0&&a.push(`id.in.(${c.join(",")})`);let d=e.from("products").select(`
169
+ `).eq("slug",t);if(c)return{data:null,error:c};if(!i||i.length===0)return{data:null,error:{message:"Product not found",code:"PGRST116"}};let a=null;return r&&(a=i.find(o=>(Array.isArray(o.languages)?o.languages[0]:o.languages)?.code===r)),a||(a=i.find(o=>(Array.isArray(o.languages)?o.languages[0]:o.languages)?.is_default)),a||(a=i.find(o=>(Array.isArray(o.languages)?o.languages[0]:o.languages)?.code==="en")),a||(a=i[0]),{data:a,error:null}}async function R(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 a=t.product_media.map((o,d)=>({product_id:r,media_id:o.media_id,sort_order:d}));await e.from("product_media").insert(a)}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 q(e,r,t.category_ids);const{data:c}=await e.from("products").select("*").eq("id",r).single();return c}async function I(e,t,r){const{data:i}=await e.from("product_media").select("media_id").eq("product_id",t),c=i?.map(s=>s.media_id)||[],{data:a,error:o}=await e.rpc("upsert_product_with_variants",{product_payload:S(r,t)});if(o||!a)throw o||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 s=r.product_media.map((p,m)=>({product_id:t,media_id:p.media_id,sort_order:m}));await e.from("product_media").insert(s)}}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,a,r.is_taxable),await j(e,a,r),await F(e,a,r);const d=r.product_media?r.product_media.map(s=>s.media_id):r.media_id?[r.media_id]:[],n=r.explicitly_removed_media_ids||[],_=c.filter(s=>!d.includes(s)),l=Array.from(new Set([..._,...n]));if(l.length>0)for(const s of l){const{count:p}=await e.from("product_media").select("*",{count:"exact",head:!0}).eq("media_id",s);if(p&&p>0)continue;const{count:m}=await e.from("posts").select("*",{count:"exact",head:!0}).eq("feature_image_id",s);if(m&&m>0)continue;const{count:h}=await e.from("logos").select("*",{count:"exact",head:!0}).eq("media_id",s);if(h&&h>0)continue;const{count:w}=await e.from("product_variants").select("*",{count:"exact",head:!0}).eq("main_media_id",s);if(w&&w>0)continue;const{data:f}=await e.from("media").select("object_key, variants").eq("id",s).single();if(f){const v=[f.object_key];f.variants&&Array.isArray(f.variants)&&f.variants.forEach(k=>{k.objectKey&&v.push(k.objectKey)}),await b.deleteMediaFiles(v),await e.from("media").delete().eq("id",s)}}await P.syncSharedInventoryForSavedProduct(a,r),r.category_ids!==void 0&&await q(e,t,r.category_ids);const{data:u}=await e.from("products").select("*").eq("id",a).single();return u}async function D(e,t){const{error:r}=await e.from("products").delete().eq("id",t);if(r)throw r;return!0}async function N(e,t,r){const{data:i,error:c}=await e.from("products").select("*").eq("id",r).single();if(c||!i)throw new Error(c?.message||"Source product not found");const{data:a,error:o}=await e.from("products").select("language_id").eq("id",t).single();if(o||!a)throw new Error(o?.message||"Target product not found");const{error:d}=await e.from("products").update({title:i.title,short_description:i.short_description,description_json:i.description_json}).eq("id",t);if(d)throw d;const{data:n,error:_}=await e.from("blocks").select("*").eq("product_id",r).order("order",{ascending:!0});if(_)throw _;if(await e.from("blocks").delete().eq("product_id",t),n&&n.length>0){const u=n.map(p=>{const{id:m,created_at:h,updated_at:w,...f}=p;return{...f,product_id:t,language_id:a.language_id}}),{error:s}=await e.from("blocks").insert(u);if(s)throw s}await e.from("product_drafts").delete().eq("product_id",t),await e.from("product_media").delete().eq("product_id",t);const{data:l}=await e.from("product_media").select("media_id, sort_order").eq("product_id",r);if(l&&l.length>0){const u=l.map(s=>({product_id:t,media_id:s.media_id,sort_order:s.sort_order}));await e.from("product_media").insert(u)}return{success:!0}}async function $(e,t,r,i=[],c=[]){const{data:a}=await e.from("languages").select("id").eq("code",r).single();if(!a)return{data:[],error:"Language not found"};const o=[];t.length>0&&o.push(`translation_group_id.in.(${t.join(",")})`),i.length>0&&o.push(`sku.in.(${i.map(_=>`"${_}"`).join(",")})`),c.length>0&&o.push(`id.in.(${c.join(",")})`);let d=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",s.id).eq("status","active");return a.length>0&&(d=d.or(a.join(","))),await d.order("id")}async function v(e,t,r){const{data:i}=await e.from("products").select("translation_group_id").eq("id",t).single();if(!i||!i.translation_group_id){if(await e.from("product_categories").delete().eq("product_id",t),r.length>0){const a=r.map(d=>({product_id:t,category_id:d}));await e.from("product_categories").insert(a)}return}const{data:c}=await e.from("products").select("id").eq("translation_group_id",i.translation_group_id),s=c&&c.length>0?c.map(a=>a.id):[t];if(await e.from("product_categories").delete().in("product_id",s),r.length>0){const a=[];for(const d of s)for(const n of r)a.push({product_id:d,category_id:n});await e.from("product_categories").insert(a)}}exports.copyProductFromLanguage=N;exports.createProduct=A;exports.deleteProduct=I;exports.fetchTranslatedProductsForCartInternal=$;exports.getProduct=M;exports.getProductBySlug=T;exports.getProducts=C;exports.syncCategoriesForTranslationGroup=v;exports.updateProduct=R;
237
+ `).eq("language_id",a.id).eq("status","active");return o.length>0&&(d=d.or(o.join(","))),await d.order("id")}async function q(e,t,r){const{data:i}=await e.from("products").select("translation_group_id").eq("id",t).single();if(!i||!i.translation_group_id){if(await e.from("product_categories").delete().eq("product_id",t),r.length>0){const o=r.map(d=>({product_id:t,category_id:d}));await e.from("product_categories").insert(o)}return}const{data:c}=await e.from("products").select("id").eq("translation_group_id",i.translation_group_id),a=c&&c.length>0?c.map(o=>o.id):[t];if(await e.from("product_categories").delete().in("product_id",a),r.length>0){const o=[];for(const d of a)for(const n of r)o.push({product_id:d,category_id:n});await e.from("product_categories").insert(o)}}exports.copyProductFromLanguage=N;exports.createProduct=R;exports.deleteProduct=D;exports.fetchTranslatedProductsForCartInternal=$;exports.getProduct=T;exports.getProductBySlug=A;exports.getProducts=C;exports.syncCategoriesForTranslationGroup=q;exports.updateProduct=I;
@@ -92,6 +92,7 @@ export declare function getProducts(supabase: SupabaseClient<Database>, { page,
92
92
  export declare function getProduct(supabase: SupabaseClient<Database>, id: string): Promise<import('@supabase/postgrest-js').PostgrestSingleResponse<{
93
93
  average_rating: number;
94
94
  created_at: string | null;
95
+ custom_canonical: string | null;
95
96
  description_json: import('../../../db/src/index.ts').Json | null;
96
97
  freemius_plan_id: string | null;
97
98
  freemius_product_id: string | null;
@@ -216,6 +217,7 @@ export declare function getProductBySlug(supabase: SupabaseClient<Database>, slu
216
217
  export declare function createProduct(supabase: SupabaseClient<Database>, data: ProductFormValues): Promise<{
217
218
  average_rating: number;
218
219
  created_at: string | null;
220
+ custom_canonical: string | null;
219
221
  description_json: import('../../../db/src/index.ts').Json | null;
220
222
  freemius_plan_id: string | null;
221
223
  freemius_product_id: string | null;
@@ -252,6 +254,7 @@ export declare function createProduct(supabase: SupabaseClient<Database>, data:
252
254
  export declare function updateProduct(supabase: SupabaseClient<Database>, id: string, data: ProductFormValues): Promise<{
253
255
  average_rating: number;
254
256
  created_at: string | null;
257
+ custom_canonical: string | null;
255
258
  description_json: import('../../../db/src/index.ts').Json | null;
256
259
  freemius_plan_id: string | null;
257
260
  freemius_product_id: string | null;
@@ -1,22 +1,22 @@
1
- import { deleteMediaFiles as b } from "@nextblock-cms/utils/server";
2
- import { syncSharedInventoryForSavedProduct as k } from "./shared-inventory.es.js";
3
- import { normalizeCurrencyCode as E } from "@nextblock-cms/utils/utils";
1
+ import { deleteMediaFiles as F } from "@nextblock-cms/utils/server";
2
+ import { syncSharedInventoryForSavedProduct as v } from "./shared-inventory.es.js";
3
+ import { normalizeCurrencyCode as b } from "@nextblock-cms/utils/utils";
4
4
  const g = (e) => Math.round(e * 100);
5
- function h(e) {
5
+ function y(e) {
6
6
  return Object.entries(e || {}).reduce(
7
- (t, [i, r]) => (typeof r == "number" && Number.isFinite(r) && r >= 0 && (t[E(i)] = g(r)), t),
7
+ (t, [i, r]) => (typeof r == "number" && Number.isFinite(r) && r >= 0 && (t[b(i)] = g(r)), t),
8
8
  {}
9
9
  );
10
10
  }
11
- function F(e) {
11
+ function M(e) {
12
12
  return (e || []).map((t) => ({
13
13
  id: t.id,
14
14
  sku: t.sku,
15
15
  upc: t.upc ?? null,
16
16
  price: g(t.price),
17
17
  sale_price: typeof t.sale_price == "number" && !isNaN(t.sale_price) ? g(t.sale_price) : null,
18
- prices: h(t.prices),
19
- sale_prices: h(t.sale_prices),
18
+ prices: y(t.prices),
19
+ sale_prices: y(t.sale_prices),
20
20
  sale_start_at: t.sale_start_at ?? null,
21
21
  sale_end_at: t.sale_end_at ?? null,
22
22
  stock_quantity: t.stock_quantity,
@@ -41,8 +41,8 @@ function j(e, t) {
41
41
  metadata: {},
42
42
  price: g(e.price),
43
43
  sale_price: typeof e.sale_price == "number" && !isNaN(e.sale_price) ? g(e.sale_price) : null,
44
- prices: h(e.prices),
45
- sale_prices: h(e.sale_prices),
44
+ prices: y(e.prices),
45
+ sale_prices: y(e.sale_prices),
46
46
  sale_start_at: e.sale_start_at ?? null,
47
47
  sale_end_at: e.sale_end_at ?? null,
48
48
  freemius_plan_id: e.freemius_plan_id ?? null,
@@ -52,9 +52,22 @@ function j(e, t) {
52
52
  is_taxable: e.is_taxable,
53
53
  language_id: e.language_id,
54
54
  translation_group_id: e.translation_group_id || void 0,
55
- variants: F(e.variants)
55
+ variants: M(e.variants)
56
56
  };
57
57
  }
58
+ async function P(e, t, i) {
59
+ const r = (o) => {
60
+ const a = typeof o == "string" ? o.trim() : "";
61
+ return a || null;
62
+ }, { error: c } = await e.from("products").update({
63
+ meta_title: r(i.meta_title),
64
+ meta_description: r(i.meta_description),
65
+ custom_canonical: r(i.custom_canonical),
66
+ updated_at: (/* @__PURE__ */ new Date()).toISOString()
67
+ }).eq("id", t);
68
+ if (c)
69
+ throw c;
70
+ }
58
71
  async function x(e, t, i) {
59
72
  const { error: r } = await e.from("products").update({
60
73
  is_taxable: i,
@@ -63,8 +76,8 @@ async function x(e, t, i) {
63
76
  if (r)
64
77
  throw r;
65
78
  }
66
- async function P(e, t, i) {
67
- const r = (/* @__PURE__ */ new Date()).toISOString(), { data: c } = await e.from("products").select("sku, sale_price, sale_prices").eq("id", t).maybeSingle(), s = c?.sku ?? i.sku, { data: a } = await e.from("products").select("id").eq("sku", s), d = (a ?? []).map((o) => o.id);
79
+ async function S(e, t, i) {
80
+ const r = (/* @__PURE__ */ new Date()).toISOString(), { data: c } = await e.from("products").select("sku, sale_price, sale_prices").eq("id", t).maybeSingle(), o = c?.sku ?? i.sku, { data: a } = await e.from("products").select("id").eq("sku", o), d = (a ?? []).map((s) => s.id);
68
81
  d.length === 0 && d.push(t);
69
82
  const { error: n } = await e.from("products").update({
70
83
  sale_price: c?.sale_price ?? null,
@@ -79,47 +92,47 @@ async function P(e, t, i) {
79
92
  if (_.length === 0)
80
93
  return;
81
94
  const { data: l } = await e.from("product_variants").select("sku, sale_price, sale_prices").eq("product_id", t), u = new Map(
82
- (l ?? []).map((o) => [o.sku, o])
95
+ (l ?? []).map((s) => [s.sku, s])
83
96
  );
84
- for (const o of _) {
85
- const p = u.get(o.sku);
97
+ for (const s of _) {
98
+ const p = u.get(s.sku);
86
99
  if (!p)
87
100
  continue;
88
101
  const { error: m } = await e.from("product_variants").update({
89
102
  sale_price: p.sale_price ?? null,
90
103
  sale_prices: p.sale_prices ?? null,
91
- sale_start_at: o.sale_start_at ?? null,
92
- sale_end_at: o.sale_end_at ?? null,
104
+ sale_start_at: s.sale_start_at ?? null,
105
+ sale_end_at: s.sale_end_at ?? null,
93
106
  updated_at: r
94
- }).eq("sku", o.sku).in("product_id", d);
107
+ }).eq("sku", s.sku).in("product_id", d);
95
108
  if (m)
96
109
  throw m;
97
110
  }
98
111
  }
99
- async function R(e, {
112
+ async function T(e, {
100
113
  page: t = 1,
101
114
  limit: i = 10,
102
115
  search: r = "",
103
116
  languageId: c,
104
- categoryId: s
117
+ categoryId: o
105
118
  } = {}) {
106
119
  const a = (t - 1) * i, d = a + i - 1;
107
120
  let n = e.from("products").select(
108
121
  "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))",
109
122
  { count: "exact" }
110
123
  ).range(a, d).order("created_at", { ascending: !1 });
111
- if (c && (n = n.eq("language_id", c)), s) {
112
- const { data: _, error: l } = await e.from("product_categories").select("product_id").eq("category_id", s);
124
+ if (c && (n = n.eq("language_id", c)), o) {
125
+ const { data: _, error: l } = await e.from("product_categories").select("product_id").eq("category_id", o);
113
126
  if (l)
114
127
  return { data: [], error: l, count: 0 };
115
- const u = (_ || []).map((o) => o.product_id).filter(Boolean);
128
+ const u = (_ || []).map((s) => s.product_id).filter(Boolean);
116
129
  if (u.length === 0)
117
130
  return { data: [], error: null, count: 0 };
118
131
  n = n.in("id", u);
119
132
  }
120
133
  return r && (n = n.or(`title.ilike.%${r}%,sku.ilike.%${r}%`)), n;
121
134
  }
122
- async function T(e, t) {
135
+ async function D(e, t) {
123
136
  return e.from("products").select(
124
137
  `
125
138
  *,
@@ -300,8 +313,8 @@ async function N(e, t, i) {
300
313
  return { data: null, error: c };
301
314
  if (!r || r.length === 0)
302
315
  return { data: null, error: { message: "Product not found", code: "PGRST116" } };
303
- let s = null;
304
- return i && (s = r.find((a) => (Array.isArray(a.languages) ? a.languages[0] : a.languages)?.code === i)), s || (s = r.find((a) => (Array.isArray(a.languages) ? a.languages[0] : a.languages)?.is_default)), s || (s = r.find((a) => (Array.isArray(a.languages) ? a.languages[0] : a.languages)?.code === "en")), s || (s = r[0]), { data: s, error: null };
316
+ let o = null;
317
+ return i && (o = r.find((a) => (Array.isArray(a.languages) ? a.languages[0] : a.languages)?.code === i)), o || (o = r.find((a) => (Array.isArray(a.languages) ? a.languages[0] : a.languages)?.is_default)), o || (o = r.find((a) => (Array.isArray(a.languages) ? a.languages[0] : a.languages)?.code === "en")), o || (o = r[0]), { data: o, error: null };
305
318
  }
306
319
  async function $(e, t) {
307
320
  const { data: i, error: r } = await e.rpc("upsert_product_with_variants", {
@@ -309,62 +322,62 @@ async function $(e, t) {
309
322
  });
310
323
  if (r || !i) throw r || new Error("Failed to create product");
311
324
  if (t.product_media && t.product_media.length > 0) {
312
- const s = t.product_media.map((a, d) => ({
325
+ const o = t.product_media.map((a, d) => ({
313
326
  product_id: i,
314
327
  media_id: a.media_id,
315
328
  sort_order: d
316
329
  }));
317
- await e.from("product_media").insert(s);
330
+ await e.from("product_media").insert(o);
318
331
  } else t.media_id && await e.from("product_media").insert({
319
332
  product_id: i,
320
333
  media_id: t.media_id,
321
334
  sort_order: 0
322
335
  });
323
- await x(e, i, t.is_taxable), await P(e, i, t), await k(i, t), t.category_ids !== void 0 && await S(e, i, t.category_ids);
336
+ await x(e, i, t.is_taxable), await P(e, i, t), await S(e, i, t), await v(i, t), t.category_ids !== void 0 && await E(e, i, t.category_ids);
324
337
  const { data: c } = await e.from("products").select("*").eq("id", i).single();
325
338
  return c;
326
339
  }
327
- async function D(e, t, i) {
328
- const { data: r } = await e.from("product_media").select("media_id").eq("product_id", t), c = r?.map((o) => o.media_id) || [], { data: s, error: a } = await e.rpc("upsert_product_with_variants", {
340
+ async function z(e, t, i) {
341
+ const { data: r } = await e.from("product_media").select("media_id").eq("product_id", t), c = r?.map((s) => s.media_id) || [], { data: o, error: a } = await e.rpc("upsert_product_with_variants", {
329
342
  product_payload: j(i, t)
330
343
  });
331
- if (a || !s) throw a || new Error("Failed to update product");
344
+ if (a || !o) throw a || new Error("Failed to update product");
332
345
  if (i.product_media) {
333
346
  if (await e.from("product_media").delete().eq("product_id", t), i.product_media.length > 0) {
334
- const o = i.product_media.map((p, m) => ({
347
+ const s = i.product_media.map((p, m) => ({
335
348
  product_id: t,
336
349
  media_id: p.media_id,
337
350
  sort_order: m
338
351
  }));
339
- await e.from("product_media").insert(o);
352
+ await e.from("product_media").insert(s);
340
353
  }
341
354
  } else i.media_id && (await e.from("product_media").delete().eq("product_id", t), await e.from("product_media").insert({
342
355
  product_id: t,
343
356
  media_id: i.media_id,
344
357
  sort_order: 0
345
358
  }));
346
- await x(e, s, i.is_taxable), await P(e, s, i);
347
- const d = i.product_media ? i.product_media.map((o) => o.media_id) : i.media_id ? [i.media_id] : [], n = i.explicitly_removed_media_ids || [], _ = c.filter((o) => !d.includes(o)), l = Array.from(/* @__PURE__ */ new Set([..._, ...n]));
359
+ await x(e, o, i.is_taxable), await P(e, o, i), await S(e, o, i);
360
+ const d = i.product_media ? i.product_media.map((s) => s.media_id) : i.media_id ? [i.media_id] : [], n = i.explicitly_removed_media_ids || [], _ = c.filter((s) => !d.includes(s)), l = Array.from(/* @__PURE__ */ new Set([..._, ...n]));
348
361
  if (l.length > 0)
349
- for (const o of l) {
350
- const { count: p } = await e.from("product_media").select("*", { count: "exact", head: !0 }).eq("media_id", o);
362
+ for (const s of l) {
363
+ const { count: p } = await e.from("product_media").select("*", { count: "exact", head: !0 }).eq("media_id", s);
351
364
  if (p && p > 0) continue;
352
- const { count: m } = await e.from("posts").select("*", { count: "exact", head: !0 }).eq("feature_image_id", o);
365
+ const { count: m } = await e.from("posts").select("*", { count: "exact", head: !0 }).eq("feature_image_id", s);
353
366
  if (m && m > 0) continue;
354
- const { count: y } = await e.from("logos").select("*", { count: "exact", head: !0 }).eq("media_id", o);
355
- if (y && y > 0) continue;
356
- const { count: w } = await e.from("product_variants").select("*", { count: "exact", head: !0 }).eq("main_media_id", o);
367
+ const { count: h } = await e.from("logos").select("*", { count: "exact", head: !0 }).eq("media_id", s);
368
+ if (h && h > 0) continue;
369
+ const { count: w } = await e.from("product_variants").select("*", { count: "exact", head: !0 }).eq("main_media_id", s);
357
370
  if (w && w > 0) continue;
358
- const { data: f } = await e.from("media").select("object_key, variants").eq("id", o).single();
371
+ const { data: f } = await e.from("media").select("object_key, variants").eq("id", s).single();
359
372
  if (f) {
360
373
  const q = [f.object_key];
361
- f.variants && Array.isArray(f.variants) && f.variants.forEach((v) => {
362
- v.objectKey && q.push(v.objectKey);
363
- }), await b(q), await e.from("media").delete().eq("id", o);
374
+ f.variants && Array.isArray(f.variants) && f.variants.forEach((k) => {
375
+ k.objectKey && q.push(k.objectKey);
376
+ }), await F(q), await e.from("media").delete().eq("id", s);
364
377
  }
365
378
  }
366
- await k(s, i), i.category_ids !== void 0 && await S(e, t, i.category_ids);
367
- const { data: u } = await e.from("products").select("*").eq("id", s).single();
379
+ await v(o, i), i.category_ids !== void 0 && await E(e, t, i.category_ids);
380
+ const { data: u } = await e.from("products").select("*").eq("id", o).single();
368
381
  return u;
369
382
  }
370
383
  async function B(e, t) {
@@ -372,12 +385,12 @@ async function B(e, t) {
372
385
  if (i) throw i;
373
386
  return !0;
374
387
  }
375
- async function U(e, t, i) {
388
+ async function I(e, t, i) {
376
389
  const { data: r, error: c } = await e.from("products").select("*").eq("id", i).single();
377
390
  if (c || !r)
378
391
  throw new Error(c?.message || "Source product not found");
379
- const { data: s, error: a } = await e.from("products").select("language_id").eq("id", t).single();
380
- if (a || !s)
392
+ const { data: o, error: a } = await e.from("products").select("language_id").eq("id", t).single();
393
+ if (a || !o)
381
394
  throw new Error(a?.message || "Target product not found");
382
395
  const { error: d } = await e.from("products").update({
383
396
  title: r.title,
@@ -389,30 +402,30 @@ async function U(e, t, i) {
389
402
  if (_) throw _;
390
403
  if (await e.from("blocks").delete().eq("product_id", t), n && n.length > 0) {
391
404
  const u = n.map((p) => {
392
- const { id: m, created_at: y, updated_at: w, ...f } = p;
405
+ const { id: m, created_at: h, updated_at: w, ...f } = p;
393
406
  return {
394
407
  ...f,
395
408
  product_id: t,
396
- language_id: s.language_id
409
+ language_id: o.language_id
397
410
  };
398
- }), { error: o } = await e.from("blocks").insert(u);
399
- if (o) throw o;
411
+ }), { error: s } = await e.from("blocks").insert(u);
412
+ if (s) throw s;
400
413
  }
401
414
  await e.from("product_drafts").delete().eq("product_id", t), await e.from("product_media").delete().eq("product_id", t);
402
415
  const { data: l } = await e.from("product_media").select("media_id, sort_order").eq("product_id", i);
403
416
  if (l && l.length > 0) {
404
- const u = l.map((o) => ({
417
+ const u = l.map((s) => ({
405
418
  product_id: t,
406
- media_id: o.media_id,
407
- sort_order: o.sort_order
419
+ media_id: s.media_id,
420
+ sort_order: s.sort_order
408
421
  }));
409
422
  await e.from("product_media").insert(u);
410
423
  }
411
424
  return { success: !0 };
412
425
  }
413
- async function z(e, t, i, r = [], c = []) {
414
- const { data: s } = await e.from("languages").select("id").eq("code", i).single();
415
- if (!s)
426
+ async function O(e, t, i, r = [], c = []) {
427
+ const { data: o } = await e.from("languages").select("id").eq("code", i).single();
428
+ if (!o)
416
429
  return { data: [], error: "Language not found" };
417
430
  const a = [];
418
431
  t.length > 0 && a.push(`translation_group_id.in.(${t.join(",")})`), r.length > 0 && a.push(`sku.in.(${r.map((_) => `"${_}"`).join(",")})`), c.length > 0 && a.push(`id.in.(${c.join(",")})`);
@@ -484,10 +497,10 @@ async function z(e, t, i, r = [], c = []) {
484
497
  )
485
498
  ),
486
499
  translation_group_id
487
- `).eq("language_id", s.id).eq("status", "active");
500
+ `).eq("language_id", o.id).eq("status", "active");
488
501
  return a.length > 0 && (d = d.or(a.join(","))), await d.order("id");
489
502
  }
490
- async function S(e, t, i) {
503
+ async function E(e, t, i) {
491
504
  const { data: r } = await e.from("products").select("translation_group_id").eq("id", t).single();
492
505
  if (!r || !r.translation_group_id) {
493
506
  if (await e.from("product_categories").delete().eq("product_id", t), i.length > 0) {
@@ -499,10 +512,10 @@ async function S(e, t, i) {
499
512
  }
500
513
  return;
501
514
  }
502
- const { data: c } = await e.from("products").select("id").eq("translation_group_id", r.translation_group_id), s = c && c.length > 0 ? c.map((a) => a.id) : [t];
503
- if (await e.from("product_categories").delete().in("product_id", s), i.length > 0) {
515
+ const { data: c } = await e.from("products").select("id").eq("translation_group_id", r.translation_group_id), o = c && c.length > 0 ? c.map((a) => a.id) : [t];
516
+ if (await e.from("product_categories").delete().in("product_id", o), i.length > 0) {
504
517
  const a = [];
505
- for (const d of s)
518
+ for (const d of o)
506
519
  for (const n of i)
507
520
  a.push({
508
521
  product_id: d,
@@ -512,13 +525,13 @@ async function S(e, t, i) {
512
525
  }
513
526
  }
514
527
  export {
515
- U as copyProductFromLanguage,
528
+ I as copyProductFromLanguage,
516
529
  $ as createProduct,
517
530
  B as deleteProduct,
518
- z as fetchTranslatedProductsForCartInternal,
519
- T as getProduct,
531
+ O as fetchTranslatedProductsForCartInternal,
532
+ D as getProduct,
520
533
  N as getProductBySlug,
521
- R as getProducts,
522
- S as syncCategoriesForTranslationGroup,
523
- D as updateProduct
534
+ T as getProducts,
535
+ E as syncCategoriesForTranslationGroup,
536
+ z as updateProduct
524
537
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("./zod-config.cjs.js");const e=require("zod"),u=e.z.enum(["physical","digital"]).or(e.z.literal("")).refine(r=>r!=="",{message:"Product type is required"}).transform(r=>r),s=e.z.record(e.z.string().regex(/^[A-Z]{3}$/,"Currency code must be ISO 4217"),e.z.coerce.number().min(0,"Prices must be non-negative")),l=e.z.record(e.z.string().regex(/^[A-Z]{3}$/,"Currency code must be ISO 4217"),e.z.coerce.number().min(0,"Sale prices must be non-negative").nullable()),n=e.z.string().trim().refine(r=>r===""||!Number.isNaN(Date.parse(r)),{message:"Must be a valid date and time"}).transform(r=>r===""?null:r).nullable().optional();function o(r,a){if(!r||!a)return!0;const t=Date.parse(r),i=Date.parse(a);return Number.isNaN(t)||Number.isNaN(i)?!0:t<i}const c=e.z.object({attribute_id:e.z.string().uuid(),attribute_name:e.z.string(),term_id:e.z.string().uuid(),term_value:e.z.string(),term_slug:e.z.string().optional()}),m=e.z.object({id:e.z.string().uuid().optional(),combination_key:e.z.string().min(1),sku:e.z.string().min(1,"Variant SKU is required"),upc:e.z.string().optional().nullable(),price:e.z.coerce.number().min(0,"Variant price must be non-negative"),prices:s.default({}),sale_price:e.z.coerce.number().min(0,"Variant sale price must be non-negative").optional().nullable(),sale_prices:l.default({}),sale_start_at:n,sale_end_at:n,stock_quantity:e.z.coerce.number().int().min(0,"Variant stock must be a non-negative integer"),main_media_id:e.z.string().uuid().optional().nullable(),main_image_url:e.z.string().optional().nullable(),attribute_term_ids:e.z.array(e.z.string().uuid()).min(1),selected_options:e.z.array(c).min(1),label:e.z.string().min(1)}).refine(r=>r.sale_price===null||r.sale_price===void 0||r.sale_price<=r.price,{message:"Variant sale price cannot exceed the regular price",path:["sale_price"]}).refine(r=>Object.entries(r.sale_prices||{}).every(([a,t])=>{if(t==null)return!0;const i=r.prices?.[a];return typeof i=="number"?t<=i:!0}),{message:"Variant sale prices cannot exceed regular prices",path:["sale_prices"]}).refine(r=>o(r.sale_start_at,r.sale_end_at),{message:"Sale end must be after the sale start",path:["sale_end_at"]}),p=e.z.object({attribute_id:e.z.string().uuid(),term_ids:e.z.array(e.z.string().uuid())}),d=e.z.object({product_type:u,payment_provider:e.z.enum(["stripe","freemius"]),title:e.z.string().min(1,"Title is required"),slug:e.z.string().min(1,"Slug is required").regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/,"Slug must be lowercase alphanumeric with hyphens"),sku:e.z.string().min(1,"SKU is required"),upc:e.z.string().optional().nullable(),price:e.z.coerce.number().min(0,"Price must be non-negative"),prices:s.default({}),sale_price:e.z.coerce.number().min(0,"Sale price must be non-negative").optional().nullable(),sale_prices:l.default({}),sale_start_at:n,sale_end_at:n,stock:e.z.coerce.number().int().min(0,"Stock must be a non-negative integer"),meta_title:e.z.string().optional().nullable(),meta_description:e.z.string().optional().nullable(),short_description:e.z.string().optional(),description_json:e.z.any().optional(),freemius_plan_id:e.z.string().optional(),freemius_product_id:e.z.string().optional(),trial_period_days:e.z.coerce.number().int().min(0,"Trial period must be zero or greater").default(0),trial_requires_payment_method:e.z.boolean().default(!1),media_id:e.z.string().optional(),product_media:e.z.array(e.z.object({media_id:e.z.string()})).optional(),category_ids:e.z.array(e.z.string().uuid()).optional(),is_taxable:e.z.boolean(),status:e.z.enum(["draft","active","archived"]),language_id:e.z.coerce.number().int().min(1,"Language is required"),translation_group_id:e.z.string().uuid().optional().or(e.z.literal("")).transform(r=>r===""?void 0:r),explicitly_removed_media_ids:e.z.array(e.z.string()).optional(),variation_attributes:e.z.array(p).optional(),variants:e.z.array(m).optional()}).refine(r=>r.sale_price===null||r.sale_price===void 0||r.sale_price<=r.price,{message:"Sale price cannot exceed the regular price",path:["sale_price"]}).refine(r=>Object.entries(r.sale_prices||{}).every(([a,t])=>{if(t==null)return!0;const i=r.prices?.[a];return typeof i=="number"?t<=i:!0}),{message:"Sale prices cannot exceed regular prices",path:["sale_prices"]}).refine(r=>o(r.sale_start_at,r.sale_end_at),{message:"Sale end must be after the sale start",path:["sale_end_at"]});exports.productSchema=d;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("./zod-config.cjs.js");const e=require("zod"),u=e.z.enum(["physical","digital"]).or(e.z.literal("")).refine(r=>r!=="",{message:"Product type is required"}).transform(r=>r),s=e.z.record(e.z.string().regex(/^[A-Z]{3}$/,"Currency code must be ISO 4217"),e.z.coerce.number().min(0,"Prices must be non-negative")),l=e.z.record(e.z.string().regex(/^[A-Z]{3}$/,"Currency code must be ISO 4217"),e.z.coerce.number().min(0,"Sale prices must be non-negative").nullable()),n=e.z.string().trim().refine(r=>r===""||!Number.isNaN(Date.parse(r)),{message:"Must be a valid date and time"}).transform(r=>r===""?null:r).nullable().optional();function o(r,a){if(!r||!a)return!0;const t=Date.parse(r),i=Date.parse(a);return Number.isNaN(t)||Number.isNaN(i)?!0:t<i}const c=e.z.object({attribute_id:e.z.string().uuid(),attribute_name:e.z.string(),term_id:e.z.string().uuid(),term_value:e.z.string(),term_slug:e.z.string().optional()}),m=e.z.object({id:e.z.string().uuid().optional(),combination_key:e.z.string().min(1),sku:e.z.string().min(1,"Variant SKU is required"),upc:e.z.string().optional().nullable(),price:e.z.coerce.number().min(0,"Variant price must be non-negative"),prices:s.default({}),sale_price:e.z.coerce.number().min(0,"Variant sale price must be non-negative").optional().nullable(),sale_prices:l.default({}),sale_start_at:n,sale_end_at:n,stock_quantity:e.z.coerce.number().int().min(0,"Variant stock must be a non-negative integer"),main_media_id:e.z.string().uuid().optional().nullable(),main_image_url:e.z.string().optional().nullable(),attribute_term_ids:e.z.array(e.z.string().uuid()).min(1),selected_options:e.z.array(c).min(1),label:e.z.string().min(1)}).refine(r=>r.sale_price===null||r.sale_price===void 0||r.sale_price<=r.price,{message:"Variant sale price cannot exceed the regular price",path:["sale_price"]}).refine(r=>Object.entries(r.sale_prices||{}).every(([a,t])=>{if(t==null)return!0;const i=r.prices?.[a];return typeof i=="number"?t<=i:!0}),{message:"Variant sale prices cannot exceed regular prices",path:["sale_prices"]}).refine(r=>o(r.sale_start_at,r.sale_end_at),{message:"Sale end must be after the sale start",path:["sale_end_at"]}),p=e.z.object({attribute_id:e.z.string().uuid(),term_ids:e.z.array(e.z.string().uuid())}),d=e.z.object({product_type:u,payment_provider:e.z.enum(["stripe","freemius"]),title:e.z.string().min(1,"Title is required"),slug:e.z.string().min(1,"Slug is required").regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/,"Slug must be lowercase alphanumeric with hyphens"),sku:e.z.string().min(1,"SKU is required"),upc:e.z.string().optional().nullable(),price:e.z.coerce.number().min(0,"Price must be non-negative"),prices:s.default({}),sale_price:e.z.coerce.number().min(0,"Sale price must be non-negative").optional().nullable(),sale_prices:l.default({}),sale_start_at:n,sale_end_at:n,stock:e.z.coerce.number().int().min(0,"Stock must be a non-negative integer"),meta_title:e.z.string().optional().nullable(),meta_description:e.z.string().optional().nullable(),custom_canonical:e.z.string().optional().nullable(),short_description:e.z.string().optional(),description_json:e.z.any().optional(),freemius_plan_id:e.z.string().optional(),freemius_product_id:e.z.string().optional(),trial_period_days:e.z.coerce.number().int().min(0,"Trial period must be zero or greater").default(0),trial_requires_payment_method:e.z.boolean().default(!1),media_id:e.z.string().optional(),product_media:e.z.array(e.z.object({media_id:e.z.string()})).optional(),category_ids:e.z.array(e.z.string().uuid()).optional(),is_taxable:e.z.boolean(),status:e.z.enum(["draft","active","archived"]),language_id:e.z.coerce.number().int().min(1,"Language is required"),translation_group_id:e.z.string().uuid().optional().or(e.z.literal("")).transform(r=>r===""?void 0:r),explicitly_removed_media_ids:e.z.array(e.z.string()).optional(),variation_attributes:e.z.array(p).optional(),variants:e.z.array(m).optional()}).refine(r=>r.sale_price===null||r.sale_price===void 0||r.sale_price<=r.price,{message:"Sale price cannot exceed the regular price",path:["sale_price"]}).refine(r=>Object.entries(r.sale_prices||{}).every(([a,t])=>{if(t==null)return!0;const i=r.prices?.[a];return typeof i=="number"?t<=i:!0}),{message:"Sale prices cannot exceed regular prices",path:["sale_prices"]}).refine(r=>o(r.sale_start_at,r.sale_end_at),{message:"Sale end must be after the sale start",path:["sale_end_at"]});exports.productSchema=d;
@@ -21,6 +21,7 @@ export declare const productSchema: z.ZodObject<{
21
21
  stock: z.ZodCoercedNumber<unknown>;
22
22
  meta_title: z.ZodNullable<z.ZodOptional<z.ZodString>>;
23
23
  meta_description: z.ZodNullable<z.ZodOptional<z.ZodString>>;
24
+ custom_canonical: z.ZodNullable<z.ZodOptional<z.ZodString>>;
24
25
  short_description: z.ZodOptional<z.ZodString>;
25
26
  description_json: z.ZodOptional<z.ZodAny>;
26
27
  freemius_plan_id: z.ZodOptional<z.ZodString>;
@@ -82,6 +82,7 @@ const c = e.object({
82
82
  stock: e.coerce.number().int().min(0, "Stock must be a non-negative integer"),
83
83
  meta_title: e.string().optional().nullable(),
84
84
  meta_description: e.string().optional().nullable(),
85
+ custom_canonical: e.string().optional().nullable(),
85
86
  short_description: e.string().optional(),
86
87
  description_json: e.any().optional(),
87
88
  // Using any for Tiptap JSON structure
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextblock-cms/ecom",
3
- "version": "0.11.2",
3
+ "version": "0.12.0",
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.11.2",
14
- "@nextblock-cms/ui": "^0.11.2",
15
- "@nextblock-cms/utils": "^0.11.2",
13
+ "@nextblock-cms/db": "^0.12.0",
14
+ "@nextblock-cms/ui": "^0.12.0",
15
+ "@nextblock-cms/utils": "^0.12.0",
16
16
  "@freemius/checkout": "^1.4.1",
17
17
  "@freemius/sdk": "^0.3.0",
18
18
  "@hookform/resolvers": "^5.2.2",