@nextblock-cms/ecom 0.12.9 → 0.12.12

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 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(`
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}).eq("status","active");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
@@ -1,5 +1,5 @@
1
1
  import { deleteMediaFiles as F } from "@nextblock-cms/utils/server";
2
- import { syncSharedInventoryForSavedProduct as v } from "./shared-inventory.es.js";
2
+ import { syncSharedInventoryForSavedProduct as k } from "./shared-inventory.es.js";
3
3
  import { normalizeCurrencyCode as b } from "@nextblock-cms/utils/utils";
4
4
  const g = (e) => Math.round(e * 100);
5
5
  function y(e) {
@@ -120,7 +120,7 @@ async function T(e, {
120
120
  let n = e.from("products").select(
121
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))",
122
122
  { count: "exact" }
123
- ).range(a, d).order("created_at", { ascending: !1 });
123
+ ).range(a, d).order("created_at", { ascending: !1 }).eq("status", "active");
124
124
  if (c && (n = n.eq("language_id", c)), o) {
125
125
  const { data: _, error: l } = await e.from("product_categories").select("product_id").eq("category_id", o);
126
126
  if (l)
@@ -333,7 +333,7 @@ async function $(e, t) {
333
333
  media_id: t.media_id,
334
334
  sort_order: 0
335
335
  });
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);
336
+ await x(e, i, t.is_taxable), await P(e, i, t), await S(e, i, t), await k(i, t), t.category_ids !== void 0 && await E(e, i, t.category_ids);
337
337
  const { data: c } = await e.from("products").select("*").eq("id", i).single();
338
338
  return c;
339
339
  }
@@ -371,12 +371,12 @@ async function z(e, t, i) {
371
371
  const { data: f } = await e.from("media").select("object_key, variants").eq("id", s).single();
372
372
  if (f) {
373
373
  const q = [f.object_key];
374
- f.variants && Array.isArray(f.variants) && f.variants.forEach((k) => {
375
- k.objectKey && q.push(k.objectKey);
374
+ f.variants && Array.isArray(f.variants) && f.variants.forEach((v) => {
375
+ v.objectKey && q.push(v.objectKey);
376
376
  }), await F(q), await e.from("media").delete().eq("id", s);
377
377
  }
378
378
  }
379
- await v(o, i), i.category_ids !== void 0 && await E(e, t, i.category_ids);
379
+ await k(o, i), i.category_ids !== void 0 && await E(e, t, i.category_ids);
380
380
  const { data: u } = await e.from("products").select("*").eq("id", o).single();
381
381
  return u;
382
382
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextblock-cms/ecom",
3
- "version": "0.12.9",
3
+ "version": "0.12.12",
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.12.9",
14
- "@nextblock-cms/ui": "^0.12.9",
15
- "@nextblock-cms/utils": "^0.12.9",
13
+ "@nextblock-cms/db": "^0.12.12",
14
+ "@nextblock-cms/ui": "^0.12.12",
15
+ "@nextblock-cms/utils": "^0.12.12",
16
16
  "@freemius/checkout": "^1.4.1",
17
17
  "@freemius/sdk": "^0.3.0",
18
18
  "@hookform/resolvers": "^5.2.2",