@nextblock-cms/ecom 0.8.1 → 0.8.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.
Files changed (71) hide show
  1. package/AddToCartButton-DsSEH9yp.cjs +1 -0
  2. package/AddToCartButton-ffE0DhHu.js +59 -0
  3. package/CouponForm-BI_5SBHQ.js +152 -0
  4. package/CouponForm-D_uu2bLP.cjs +1 -0
  5. package/CurrencyProvider-Cg-Q6ucj.cjs +1 -0
  6. package/CurrencyProvider-OzlRN96V.js +120 -0
  7. package/CurrencyProvider.cjs.js +1 -0
  8. package/CurrencyProvider.es.js +10 -0
  9. package/ProductDetailsLayout-BxJH_BxR.cjs +1 -0
  10. package/ProductDetailsLayout-Dg8dRTYp.js +530 -0
  11. package/ProductGrid-BdL7iglO.cjs +1 -0
  12. package/ProductGrid-D3AWM8sr.js +130 -0
  13. package/actions-AHmBrS5e.cjs +48 -0
  14. package/actions-j5fuSZX-.js +820 -0
  15. package/cart-store.cjs.js +1 -0
  16. package/cart-store.es.js +116 -0
  17. package/components/Cart.cjs.js +1 -0
  18. package/components/Cart.es.js +259 -0
  19. package/components/CartDrawer.cjs.js +1 -0
  20. package/components/CartDrawer.es.js +118 -0
  21. package/components/CartIcon.cjs.js +1 -0
  22. package/components/CartIcon.es.js +33 -0
  23. package/components/Checkout.cjs.js +1 -0
  24. package/components/Checkout.es.js +1020 -0
  25. package/components/CurrencySwitcher.cjs.js +1 -0
  26. package/components/CurrencySwitcher.es.js +17 -0
  27. package/components/FeaturedProduct.cjs.js +1 -0
  28. package/components/FeaturedProduct.es.js +71 -0
  29. package/components/ProductDetailsLayout.cjs.js +1 -0
  30. package/components/ProductDetailsLayout.es.js +19 -0
  31. package/components/ProductGrid.cjs.js +1 -0
  32. package/components/ProductGrid.es.js +6 -0
  33. package/components/SimpleTiptapRenderer.cjs.js +1 -0
  34. package/components/SimpleTiptapRenderer.es.js +187 -0
  35. package/coupon-server-C9ySm3I5.cjs +1 -0
  36. package/coupon-server-DUKVtyYs.js +248 -0
  37. package/currency-constants.cjs.js +1 -0
  38. package/currency-constants.es.js +4 -0
  39. package/currency.cjs.js +1 -0
  40. package/currency.es.js +312 -0
  41. package/customer-C-UPvrYN.cjs +1 -0
  42. package/customer-C3xccjUg.js +57 -0
  43. package/index.cjs.js +1 -1
  44. package/index.es.js +414 -3105
  45. package/invoice-ui-CAnJPu6n.cjs +29 -0
  46. package/invoice-ui-DtpbTJE1.js +2886 -0
  47. package/package.json +10 -5
  48. package/product-actions-CONBF8i6.cjs +251 -0
  49. package/product-actions-DjlIWCMH.js +691 -0
  50. package/resolver-Fz_FKsfX.cjs +7 -0
  51. package/resolver-cfrCaHpE.js +128 -0
  52. package/server-actions/product-actions.cjs.js +1 -0
  53. package/server-actions/product-actions.es.js +15 -0
  54. package/server.cjs.js +27 -27
  55. package/server.es.js +478 -463
  56. package/shipping-actions-BnHjlo2q.js +25 -0
  57. package/shipping-actions-D6zt20gg.cjs +1 -0
  58. package/states-CWYRxV4B.cjs +1 -0
  59. package/states-DlHJezQ1.js +200 -0
  60. package/tax-calculation-Dab89aHd.js +181 -0
  61. package/tax-calculation-MkDKOEkL.cjs +1 -0
  62. package/trials-DvZaOtNy.cjs +1 -0
  63. package/trials-RDcRAZKx.js +29 -0
  64. package/types.cjs.js +1 -0
  65. package/types.es.js +33 -0
  66. package/use-cart.cjs.js +1 -0
  67. package/use-cart.es.js +43 -0
  68. package/variation-utils.cjs.js +1 -0
  69. package/variation-utils.es.js +246 -0
  70. package/invoice-ui-BJZfedDd.cjs +0 -332
  71. package/invoice-ui-GJ1ADAjn.js +0 -5759
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextblock-cms/ecom",
3
- "version": "0.8.1",
3
+ "version": "0.8.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.8.1",
14
- "@nextblock-cms/ui": "^0.8.1",
15
- "@nextblock-cms/utils": "^0.8.1",
13
+ "@nextblock-cms/db": "^0.8.6",
14
+ "@nextblock-cms/ui": "^0.8.6",
15
+ "@nextblock-cms/utils": "^0.8.6",
16
16
  "@freemius/checkout": "^1.4.1",
17
17
  "@freemius/sdk": "^0.3.0",
18
18
  "@hookform/resolvers": "^5.2.2",
@@ -46,6 +46,11 @@
46
46
  "import": "./server.es.js",
47
47
  "require": "./server.cjs.js"
48
48
  },
49
- "./package.json": "./package.json"
49
+ "./package.json": "./package.json",
50
+ "./*": {
51
+ "types": "./lib/*.d.ts",
52
+ "import": "./*.es.js",
53
+ "require": "./*.cjs.js"
54
+ }
50
55
  }
51
56
  }
@@ -0,0 +1,251 @@
1
+ "use strict";const F=require("@nextblock-cms/utils/server");require("server-only");const E=require("@nextblock-cms/db/server"),A=require("@nextblock-cms/utils");function q(e){return e??E.getServiceRoleSupabaseClient()}function R(e){return e?(Array.isArray(e)?e:[e]).map(r=>r?.code?.toUpperCase().trim()).filter(r=>!!r):[]}function g(e){return[...new Set(e)].sort((t,r)=>t.localeCompare(r))}function B(e,t){return!e||e===t?t:"mixed"}async function h(e,t){const r=Array.from(t.reduce((c,s)=>{const i=s.sku.trim();return i&&c.set(i,{sku:i,quantity:Math.max(0,Math.trunc(s.quantity))}),c},new Map).values());if(r.length===0)return;const{error:a}=await e.from("inventory_items").upsert(r,{onConflict:"sku"});if(a)throw new Error(a.message)}async function x(e,t){const r=g(t.map(s=>s.trim()).filter(Boolean));if(r.length===0)return new Map;const{data:a,error:c}=await e.from("inventory_items").select("sku, quantity").in("sku",r);if(c)throw new Error(c.message);return new Map((a||[]).map(s=>[s.sku,Math.max(0,s.quantity??0)]))}async function j(e){const{data:t,error:r}=await e.from("products").select(`
2
+ id,
3
+ title,
4
+ sku,
5
+ stock,
6
+ status,
7
+ languages (
8
+ code
9
+ ),
10
+ product_variants (
11
+ id,
12
+ sku,
13
+ stock_quantity
14
+ )
15
+ `).order("title",{ascending:!0});if(r)throw new Error(r.message);const a=new Map,c=(s,i,o,d,u)=>{const _=s.trim();if(!_)return;const l=R(d.languages),n=a.get(_);if(n){n.usageType=B(n.usageType,i),n.stockFallback=Math.min(n.stockFallback,o),n.productTitles.add(d.title),n.parentProductSkus.add(d.sku),n.languages=new Set([...n.languages,...l]),n.statuses.add(d.status),n.productIds.add(d.id),u&&n.variantIds.add(u);return}a.set(_,{sku:_,stockFallback:o,usageType:i,productTitles:new Set([d.title]),parentProductSkus:new Set([d.sku]),languages:new Set(l),statuses:new Set([d.status]),productIds:new Set([d.id]),variantIds:u?new Set([u]):new Set})};for(const s of t||[]){const i=s.product_variants||[];if(i.length>0){for(const o of i)c(o.sku,"variant",Math.max(0,o.stock_quantity??0),s,o.id);continue}c(s.sku,"product",Math.max(0,s.stock??0),s)}return a}async function U(e){const t=q(e),r=await j(t),a=[...r.keys()];if(a.length===0)return[];let c=await x(t,a);const s=a.filter(i=>!c.has(i)).flatMap(i=>{const o=r.get(i);return o?[{sku:i,quantity:o.stockFallback}]:[]});return s.length>0&&(await h(t,s),c=await x(t,a)),a.flatMap(i=>{const o=r.get(i);return o?{key:i,sku:i,stock:c.get(i)??o.stockFallback,usageType:o.usageType,productTitles:g(o.productTitles),parentProductSkus:g(o.parentProductSkus),languages:g(o.languages),statuses:g(o.statuses),productIds:g(o.productIds),variantIds:g(o.variantIds)}:[]}).sort((i,o)=>i.sku.localeCompare(o.sku)||i.usageType.localeCompare(o.usageType)||i.productTitles.join(", ").localeCompare(o.productTitles.join(", ")))}async function z(e,t){const r=q(t),a=e.sku.trim(),c=Math.max(0,Math.trunc(e.stock));if(!a)throw new Error("SKU is required to update inventory.");await h(r,[{sku:a,quantity:c}]);const i=(await j(r)).get(a),o=(i?.productIds.size??0)+(i?.variantIds.size??0);return{stock:c,affectedCount:o}}async function C(e,t,r){const a=q(r);if(t.variants&&t.variants.length>0){const c=Array.from(t.variants.reduce((s,i)=>(s.set(i.sku.trim(),Math.max(0,Math.trunc(i.stock_quantity))),s),new Map).entries()).map(([s,i])=>({sku:s,quantity:i}));await h(a,c);return}await h(a,[{sku:t.sku,quantity:Math.max(0,Math.trunc(t.stock))}])}const y=e=>Math.round(e*100);function w(e){return Object.entries(e||{}).reduce((t,[r,a])=>(typeof a=="number"&&Number.isFinite(a)&&a>=0&&(t[A.normalizeCurrencyCode(r)]=y(a)),t),{})}function $(e){return(e||[]).map(t=>({id:t.id,sku:t.sku,upc:t.upc??null,price:y(t.price),sale_price:typeof t.sale_price=="number"&&!isNaN(t.sale_price)?y(t.sale_price):null,prices:w(t.prices),sale_prices:w(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 I(e,t){const a=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:y(e.price),sale_price:typeof e.sale_price=="number"&&!isNaN(e.sale_price)?y(e.sale_price):null,prices:w(e.prices),sale_prices:w(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:a,trial_requires_payment_method:a>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.variants)}}async function b(e,t,r){const{error:a}=await e.from("products").update({is_taxable:r,updated_at:new Date().toISOString()}).eq("id",t);if(a)throw a}async function T(e,t,r){const a=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:i}=await e.from("products").select("id").eq("sku",s),o=(i??[]).map(n=>n.id);o.length===0&&o.push(t);const{error:d}=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:a}).in("id",o);if(d)throw d;const u=r.variants??[];if(u.length===0)return;const{data:_}=await e.from("product_variants").select("sku, sale_price, sale_prices").eq("product_id",t),l=new Map((_??[]).map(n=>[n.sku,n]));for(const n of u){const p=l.get(n.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:n.sale_start_at??null,sale_end_at:n.sale_end_at??null,updated_at:a}).eq("sku",n.sku).in("product_id",o);if(m)throw m}}async function N(e,{page:t=1,limit:r=10,search:a="",languageId:c,categoryId:s}={}){const i=(t-1)*r,o=i+r-1;let d=e.from("products").select("id, title, 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(i,o).order("created_at",{ascending:!1});if(c&&(d=d.eq("language_id",c)),s){const{data:u,error:_}=await e.from("product_categories").select("product_id").eq("category_id",s);if(_)return{data:[],error:_,count:0};const l=(u||[]).map(n=>n.product_id).filter(Boolean);if(l.length===0)return{data:[],error:null,count:0};d=d.in("id",l)}return a&&(d=d.or(`title.ilike.%${a}%,sku.ilike.%${a}%`)),d}async function D(e,t){return e.from("products").select(`
16
+ *,
17
+ languages (
18
+ code
19
+ ),
20
+ product_media (
21
+ media_id,
22
+ sort_order,
23
+ media (
24
+ id,
25
+ file_path,
26
+ object_key,
27
+ file_name,
28
+ blur_data_url,
29
+ width,
30
+ height
31
+ )
32
+ ),
33
+ product_variants (
34
+ id,
35
+ sku,
36
+ upc,
37
+ main_media_id,
38
+ price,
39
+ prices,
40
+ sale_price,
41
+ sale_prices,
42
+ sale_start_at,
43
+ sale_end_at,
44
+ scheduled_price,
45
+ scheduled_prices,
46
+ scheduled_price_at,
47
+ stock_quantity,
48
+ media:main_media_id (
49
+ id,
50
+ file_path,
51
+ object_key,
52
+ description
53
+ ),
54
+ variant_attribute_mapping (
55
+ attribute_term_id,
56
+ product_attribute_terms (
57
+ id,
58
+ attribute_id,
59
+ value,
60
+ slug,
61
+ sort_order,
62
+ value_translations,
63
+ product_attributes (
64
+ id,
65
+ name,
66
+ slug,
67
+ name_translations
68
+ )
69
+ )
70
+ )
71
+ ),
72
+ freemius_plans (
73
+ id,
74
+ name,
75
+ title,
76
+ freemius_pricing (
77
+ id,
78
+ license_quota,
79
+ api_monthly_price,
80
+ api_annual_price,
81
+ api_lifetime_price,
82
+ override_monthly_price,
83
+ override_annual_price,
84
+ override_lifetime_price,
85
+ is_active
86
+ )
87
+ ),
88
+ product_categories (
89
+ category:categories (
90
+ id,
91
+ name,
92
+ slug,
93
+ description,
94
+ name_translations,
95
+ description_translations
96
+ )
97
+ )
98
+ `).eq("id",t).single()}async function L(e,t,r){const{data:a,error:c}=await e.from("products").select(`
99
+ *,
100
+ languages (
101
+ id,
102
+ code,
103
+ is_default
104
+ ),
105
+ product_media (
106
+ media_id,
107
+ sort_order,
108
+ media (
109
+ id,
110
+ file_path,
111
+ object_key,
112
+ file_name,
113
+ blur_data_url,
114
+ width,
115
+ height
116
+ )
117
+ ),
118
+ product_variants (
119
+ id,
120
+ sku,
121
+ upc,
122
+ main_media_id,
123
+ price,
124
+ prices,
125
+ sale_price,
126
+ sale_prices,
127
+ sale_start_at,
128
+ sale_end_at,
129
+ scheduled_price,
130
+ scheduled_prices,
131
+ scheduled_price_at,
132
+ stock_quantity,
133
+ media:main_media_id (
134
+ id,
135
+ file_path,
136
+ object_key,
137
+ description
138
+ ),
139
+ variant_attribute_mapping (
140
+ attribute_term_id,
141
+ product_attribute_terms (
142
+ id,
143
+ attribute_id,
144
+ value,
145
+ slug,
146
+ sort_order,
147
+ value_translations,
148
+ product_attributes (
149
+ id,
150
+ name,
151
+ slug,
152
+ name_translations
153
+ )
154
+ )
155
+ )
156
+ ),
157
+ freemius_plans (
158
+ id,
159
+ name,
160
+ title,
161
+ freemius_pricing (
162
+ id,
163
+ license_quota,
164
+ api_monthly_price,
165
+ api_annual_price,
166
+ api_lifetime_price,
167
+ override_monthly_price,
168
+ override_annual_price,
169
+ override_lifetime_price,
170
+ is_active
171
+ )
172
+ ),
173
+ product_categories (
174
+ category:categories (
175
+ id,
176
+ name,
177
+ slug,
178
+ description,
179
+ name_translations,
180
+ description_translations
181
+ )
182
+ )
183
+ `).eq("slug",t);if(c)return{data:null,error:c};if(!a||a.length===0)return{data:null,error:{message:"Product not found",code:"PGRST116"}};let s=null;return r&&(s=a.find(i=>(Array.isArray(i.languages)?i.languages[0]:i.languages)?.code===r)),s||(s=a.find(i=>(Array.isArray(i.languages)?i.languages[0]:i.languages)?.is_default)),s||(s=a.find(i=>(Array.isArray(i.languages)?i.languages[0]:i.languages)?.code==="en")),s||(s=a[0]),{data:s,error:null}}async function O(e,t){const{data:r,error:a}=await e.rpc("upsert_product_with_variants",{product_payload:I(t)});if(a||!r)throw a||new Error("Failed to create product");if(t.product_media&&t.product_media.length>0){const s=t.product_media.map((i,o)=>({product_id:r,media_id:i.media_id,sort_order:o}));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 b(e,r,t.is_taxable),await T(e,r,t),await C(r,t),t.category_ids!==void 0&&await S(e,r,t.category_ids);const{data:c}=await e.from("products").select("*").eq("id",r).single();return c}async function Q(e,t,r){const{data:a}=await e.from("product_media").select("media_id").eq("product_id",t),c=a?.map(n=>n.media_id)||[],{data:s,error:i}=await e.rpc("upsert_product_with_variants",{product_payload:I(r,t)});if(i||!s)throw i||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((p,m)=>({product_id:t,media_id:p.media_id,sort_order:m}));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 b(e,s,r.is_taxable),await T(e,s,r);const o=r.product_media?r.product_media.map(n=>n.media_id):r.media_id?[r.media_id]:[],d=r.explicitly_removed_media_ids||[],u=c.filter(n=>!o.includes(n)),_=Array.from(new Set([...u,...d]));if(_.length>0)for(const n of _){const{count:p}=await e.from("product_media").select("*",{count:"exact",head:!0}).eq("media_id",n);if(p&&p>0)continue;const{count:m}=await e.from("posts").select("*",{count:"exact",head:!0}).eq("feature_image_id",n);if(m&&m>0)continue;const{count:k}=await e.from("logos").select("*",{count:"exact",head:!0}).eq("media_id",n);if(k&&k>0)continue;const{count:v}=await e.from("product_variants").select("*",{count:"exact",head:!0}).eq("main_media_id",n);if(v&&v>0)continue;const{data:f}=await e.from("media").select("object_key, variants").eq("id",n).single();if(f){const M=[f.object_key];f.variants&&Array.isArray(f.variants)&&f.variants.forEach(P=>{P.objectKey&&M.push(P.objectKey)}),await F.deleteMediaFiles(M),await e.from("media").delete().eq("id",n)}}await C(s,r),r.category_ids!==void 0&&await S(e,t,r.category_ids);const{data:l}=await e.from("products").select("*").eq("id",s).single();return l}async function V(e,t){const{error:r}=await e.from("products").delete().eq("id",t);if(r)throw r;return!0}async function G(e,t,r){const{data:a,error:c}=await e.from("products").select("*").eq("id",r).single();if(c||!a)throw new Error(c?.message||"Source product not found");const{data:s,error:i}=await e.from("products").select("language_id").eq("id",t).single();if(i||!s)throw new Error(i?.message||"Target product not found");const{error:o}=await e.from("products").update({title:a.title,short_description:a.short_description,description_json:a.description_json}).eq("id",t);if(o)throw o;const{data:d,error:u}=await e.from("blocks").select("*").eq("product_id",r).order("order",{ascending:!0});if(u)throw u;if(await e.from("blocks").delete().eq("product_id",t),d&&d.length>0){const l=d.map(p=>{const{id:m,created_at:k,updated_at:v,...f}=p;return{...f,product_id:t,language_id:s.language_id}}),{error:n}=await e.from("blocks").insert(l);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:_}=await e.from("product_media").select("media_id, sort_order").eq("product_id",r);if(_&&_.length>0){const l=_.map(n=>({product_id:t,media_id:n.media_id,sort_order:n.sort_order}));await e.from("product_media").insert(l)}return{success:!0}}async function K(e,t,r,a=[],c=[]){const{data:s}=await e.from("languages").select("id").eq("code",r).single();if(!s)return{data:[],error:"Language not found"};const i=[];t.length>0&&i.push(`translation_group_id.in.(${t.join(",")})`),a.length>0&&i.push(`sku.in.(${a.map(u=>`"${u}"`).join(",")})`),c.length>0&&i.push(`id.in.(${c.join(",")})`);let o=e.from("products").select(`
184
+ id,
185
+ title,
186
+ sku,
187
+ price,
188
+ prices,
189
+ sale_price,
190
+ sale_prices,
191
+ sale_start_at,
192
+ sale_end_at,
193
+ scheduled_price,
194
+ scheduled_prices,
195
+ scheduled_price_at,
196
+ stock,
197
+ slug,
198
+ language_id,
199
+ product_type,
200
+ payment_provider,
201
+ freemius_product_id,
202
+ freemius_plan_id,
203
+ trial_period_days,
204
+ trial_requires_payment_method,
205
+ is_taxable,
206
+ product_media (
207
+ media (
208
+ file_path,
209
+ object_key
210
+ )
211
+ ),
212
+ product_variants (
213
+ id,
214
+ sku,
215
+ upc,
216
+ main_media_id,
217
+ price,
218
+ prices,
219
+ sale_price,
220
+ sale_prices,
221
+ sale_start_at,
222
+ sale_end_at,
223
+ scheduled_price,
224
+ scheduled_prices,
225
+ scheduled_price_at,
226
+ stock_quantity,
227
+ media:main_media_id (
228
+ file_path,
229
+ object_key,
230
+ description
231
+ ),
232
+ variant_attribute_mapping (
233
+ attribute_term_id,
234
+ product_attribute_terms (
235
+ id,
236
+ attribute_id,
237
+ value,
238
+ slug,
239
+ sort_order,
240
+ value_translations,
241
+ product_attributes (
242
+ id,
243
+ name,
244
+ slug,
245
+ name_translations
246
+ )
247
+ )
248
+ )
249
+ ),
250
+ translation_group_id
251
+ `).eq("language_id",s.id).eq("status","active");return i.length>0&&(o=o.or(i.join(","))),await o.order("id")}async function S(e,t,r){const{data:a}=await e.from("products").select("translation_group_id").eq("id",t).single();if(!a||!a.translation_group_id){if(await e.from("product_categories").delete().eq("product_id",t),r.length>0){const i=r.map(o=>({product_id:t,category_id:o}));await e.from("product_categories").insert(i)}return}const{data:c}=await e.from("products").select("id").eq("translation_group_id",a.translation_group_id),s=c&&c.length>0?c.map(i=>i.id):[t];if(await e.from("product_categories").delete().in("product_id",s),r.length>0){const i=[];for(const o of s)for(const d of r)i.push({product_id:o,category_id:d});await e.from("product_categories").insert(i)}}exports.copyProductFromLanguage=G;exports.createProduct=O;exports.deleteProduct=V;exports.fetchTranslatedProductsForCartInternal=K;exports.getInventoryItems=U;exports.getProduct=D;exports.getProductBySlug=L;exports.getProducts=N;exports.setSharedInventoryQuantity=z;exports.syncCategoriesForTranslationGroup=S;exports.updateProduct=Q;