@nextblock-cms/ecom 0.8.6 → 0.8.7
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/index.cjs.js +1 -1
- package/index.es.js +136 -533
- package/lib/CurrencyProvider.cjs.js +1 -0
- package/lib/CurrencyProvider.es.js +99 -0
- package/lib/cart-store.cjs.js +1 -0
- package/{cart-store.es.js → lib/cart-store.es.js} +13 -13
- package/lib/components/AccountNavigationMenu.cjs.js +1 -0
- package/lib/components/AccountNavigationMenu.es.js +44 -0
- package/lib/components/AddToCartButton.cjs.js +1 -0
- package/{AddToCartButton-ffE0DhHu.js → lib/components/AddToCartButton.es.js} +14 -13
- package/lib/components/Cart.cjs.js +1 -0
- package/lib/components/Cart.es.js +148 -0
- package/lib/components/CartDrawer.cjs.js +1 -0
- package/{components → lib/components}/CartDrawer.es.js +15 -14
- package/{components → lib/components}/CartIcon.cjs.js +1 -1
- package/{components → lib/components}/CartIcon.es.js +1 -0
- package/lib/components/Checkout.cjs.js +1 -0
- package/{components → lib/components}/Checkout.es.js +330 -363
- package/lib/components/CouponForm.cjs.js +1 -0
- package/lib/components/CouponForm.es.js +136 -0
- package/lib/components/CurrencySwitcher.cjs.js +1 -0
- package/{components → lib/components}/CurrencySwitcher.es.js +5 -4
- package/lib/components/CustomerProfileForm.cjs.js +1 -0
- package/lib/components/CustomerProfileForm.es.js +355 -0
- package/lib/components/FeaturedProduct.cjs.js +1 -0
- package/{components → lib/components}/FeaturedProduct.es.js +9 -8
- package/lib/components/InvoiceDocument.cjs.js +1 -0
- package/lib/components/InvoiceDocument.es.js +196 -0
- package/lib/components/InvoiceViewerShell.cjs.js +29 -0
- package/lib/components/InvoiceViewerShell.es.js +100 -0
- package/lib/components/ProductCard.cjs.js +1 -0
- package/lib/components/ProductCard.es.js +119 -0
- package/lib/components/ProductDetailsLayout.cjs.js +1 -0
- package/lib/components/ProductDetailsLayout.es.js +361 -0
- package/lib/components/ProductGallery.cjs.js +1 -0
- package/lib/components/ProductGallery.es.js +41 -0
- package/lib/components/ProductGrid.cjs.js +1 -0
- package/lib/components/ProductGrid.es.js +19 -0
- package/lib/components/ShippingEstimator.cjs.js +1 -0
- package/lib/components/ShippingEstimator.es.js +125 -0
- package/lib/components/SubscriptionSelector.cjs.js +1 -0
- package/lib/components/SubscriptionSelector.es.js +140 -0
- package/lib/countries.cjs.js +1 -0
- package/lib/countries.es.js +77 -0
- package/lib/coupon-server.cjs.js +1 -0
- package/{coupon-server-DUKVtyYs.js → lib/coupon-server.es.js} +68 -82
- package/lib/coupons.cjs.js +1 -0
- package/lib/coupons.es.js +17 -0
- package/lib/currency-store.cjs.js +1 -0
- package/lib/currency-store.es.js +27 -0
- package/lib/currency-sync.cjs.js +1 -0
- package/lib/currency-sync.es.js +180 -0
- package/lib/customer-addresses.cjs.js +1 -0
- package/lib/customer-addresses.es.js +116 -0
- package/lib/customer-orders.cjs.js +1 -0
- package/lib/customer-orders.es.js +45 -0
- package/lib/customer.cjs.js +1 -0
- package/{customer-C3xccjUg.js → lib/customer.es.js} +15 -14
- package/lib/export-helpers.cjs.js +1 -0
- package/lib/export-helpers.es.js +56 -0
- package/lib/factory.cjs.js +1 -0
- package/lib/factory.es.js +8 -0
- package/lib/freemius-coupons.cjs.js +1 -0
- package/lib/freemius-coupons.es.js +272 -0
- package/lib/freemius-order-sync.cjs.js +1 -0
- package/lib/freemius-order-sync.es.js +284 -0
- package/lib/inventory-settings.cjs.js +1 -0
- package/lib/inventory-settings.es.js +86 -0
- package/lib/invoice-server.cjs.js +33 -0
- package/lib/invoice-server.es.js +141 -0
- package/lib/invoice-ui.cjs.js +1 -0
- package/lib/invoice-ui.es.js +71 -0
- package/lib/invoice.cjs.js +1 -0
- package/lib/invoice.es.js +102 -0
- package/lib/order-inventory.cjs.js +61 -0
- package/lib/order-inventory.es.js +128 -0
- package/lib/order-tax-details.cjs.js +1 -0
- package/lib/order-tax-details.es.js +164 -0
- package/lib/pages/cms/coupons/CouponEditorForm.cjs.js +1 -0
- package/lib/pages/cms/coupons/CouponEditorForm.es.js +189 -0
- package/lib/pages/cms/coupons/CouponsPage.cjs.js +5 -0
- package/lib/pages/cms/coupons/CouponsPage.es.js +171 -0
- package/lib/pages/cms/coupons/CreateCouponDialog.cjs.js +1 -0
- package/lib/pages/cms/coupons/CreateCouponDialog.es.js +35 -0
- package/lib/pages/cms/coupons/EditCouponPage.cjs.js +1 -0
- package/lib/pages/cms/coupons/EditCouponPage.es.js +48 -0
- package/lib/pages/cms/coupons/ProductScopePicker.cjs.js +1 -0
- package/lib/pages/cms/coupons/ProductScopePicker.es.js +120 -0
- package/lib/pages/cms/coupons/actions.cjs.js +1 -0
- package/lib/pages/cms/coupons/actions.es.js +128 -0
- package/lib/pages/cms/coupons/product-options.cjs.js +1 -0
- package/lib/pages/cms/coupons/product-options.es.js +27 -0
- package/lib/pages/cms/orders/ExportReportsDialog.cjs.js +1 -0
- package/lib/pages/cms/orders/ExportReportsDialog.es.js +130 -0
- package/lib/pages/cms/orders/OrderDetailPage.cjs.js +1 -0
- package/lib/pages/cms/orders/OrderDetailPage.es.js +137 -0
- package/lib/pages/cms/orders/OrderPrintButton.cjs.js +1 -0
- package/lib/pages/cms/orders/OrderPrintButton.es.js +22 -0
- package/lib/pages/cms/orders/OrderStatusForm.cjs.js +1 -0
- package/lib/pages/cms/orders/OrderStatusForm.es.js +71 -0
- package/lib/pages/cms/orders/OrdersPage.cjs.js +1 -0
- package/lib/pages/cms/orders/OrdersPage.es.js +104 -0
- package/lib/pages/cms/orders/actions.cjs.js +7 -0
- package/lib/pages/cms/orders/actions.es.js +71 -0
- package/lib/pages/cms/orders/export-actions.cjs.js +1 -0
- package/lib/pages/cms/orders/export-actions.es.js +27 -0
- package/lib/pages/cms/orders/server-actions.cjs.js +1 -0
- package/lib/pages/cms/orders/server-actions.es.js +55 -0
- package/lib/pages/cms/payments/PaymentsClient.cjs.js +1 -0
- package/lib/pages/cms/payments/PaymentsClient.es.js +188 -0
- package/lib/pages/cms/payments/PaymentsPage.cjs.js +1 -0
- package/lib/pages/cms/payments/PaymentsPage.es.js +29 -0
- package/lib/pages/cms/payments/actions.cjs.js +1 -0
- package/lib/pages/cms/payments/actions.es.js +23 -0
- package/lib/pages/cms/payments/queries.cjs.js +1 -0
- package/lib/pages/cms/payments/queries.es.js +30 -0
- package/lib/pages/cms/products/ProductsPage.cjs.js +1 -0
- package/lib/pages/cms/products/ProductsPage.es.js +46 -0
- package/lib/pages/cms/products/_id_/edit/EditProductPage.cjs.js +1 -0
- package/lib/pages/cms/products/_id_/edit/EditProductPage.es.js +156 -0
- package/lib/pages/cms/products/actions.cjs.js +44 -0
- package/lib/pages/cms/products/actions.es.js +175 -0
- package/lib/pages/cms/products/attributes/AttributeManagementPage.cjs.js +1 -0
- package/lib/pages/cms/products/attributes/AttributeManagementPage.es.js +48 -0
- package/lib/pages/cms/products/attributes/components/AttributeManager.cjs.js +1 -0
- package/lib/pages/cms/products/attributes/components/AttributeManager.es.js +291 -0
- package/lib/pages/cms/products/categories/CategoryManagementPage.cjs.js +1 -0
- package/lib/pages/cms/products/categories/CategoryManagementPage.es.js +36 -0
- package/lib/pages/cms/products/categories/components/CategoryManager.cjs.js +1 -0
- package/lib/pages/cms/products/categories/components/CategoryManager.es.js +263 -0
- package/lib/pages/cms/products/components/CopyProductFromLanguage.cjs.js +1 -0
- package/lib/pages/cms/products/components/CopyProductFromLanguage.es.js +114 -0
- package/lib/pages/cms/products/components/CurrencyPriceFields.cjs.js +1 -0
- package/lib/pages/cms/products/components/CurrencyPriceFields.es.js +107 -0
- package/lib/pages/cms/products/components/DeleteProductButton.cjs.js +1 -0
- package/lib/pages/cms/products/components/DeleteProductButton.es.js +48 -0
- package/lib/pages/cms/products/components/FreemiusPricingDashboard.cjs.js +1 -0
- package/lib/pages/cms/products/components/FreemiusPricingDashboard.es.js +86 -0
- package/lib/pages/cms/products/components/ProductCategorySelector.cjs.js +1 -0
- package/lib/pages/cms/products/components/ProductCategorySelector.es.js +160 -0
- package/lib/pages/cms/products/components/ProductForm.cjs.js +1 -0
- package/lib/pages/cms/products/components/ProductForm.es.js +702 -0
- package/lib/pages/cms/products/components/ProductMediaManager.cjs.js +1 -0
- package/lib/pages/cms/products/components/ProductMediaManager.es.js +104 -0
- package/lib/pages/cms/products/components/ProductsBulkTable.cjs.js +1 -0
- package/lib/pages/cms/products/components/ProductsBulkTable.es.js +228 -0
- package/lib/pages/cms/products/components/SaleScheduleFields.cjs.js +1 -0
- package/lib/pages/cms/products/components/SaleScheduleFields.es.js +137 -0
- package/lib/pages/cms/products/components/SyncFreemiusButton.cjs.js +1 -0
- package/lib/pages/cms/products/components/SyncFreemiusButton.es.js +36 -0
- package/lib/pages/cms/products/components/SyncFreemiusPricingButton.cjs.js +1 -0
- package/lib/pages/cms/products/components/SyncFreemiusPricingButton.es.js +40 -0
- package/lib/pages/cms/products/components/VariationsEditor.cjs.js +1 -0
- package/lib/pages/cms/products/components/VariationsEditor.es.js +408 -0
- package/lib/pages/cms/products/inventory/InventoryPage.cjs.js +1 -0
- package/lib/pages/cms/products/inventory/InventoryPage.es.js +16 -0
- package/lib/pages/cms/products/inventory/InventoryTableClient.cjs.js +2 -0
- package/lib/pages/cms/products/inventory/InventoryTableClient.es.js +214 -0
- package/lib/pages/cms/products/inventory/actions.cjs.js +3 -0
- package/lib/pages/cms/products/inventory/actions.es.js +95 -0
- package/lib/pages/cms/products/new/NewProductPage.cjs.js +1 -0
- package/lib/pages/cms/products/new/NewProductPage.es.js +76 -0
- package/lib/pages/cms/products/product-price-sync.cjs.js +1 -0
- package/lib/pages/cms/products/product-price-sync.es.js +98 -0
- package/lib/pages/cms/products/server-actions.cjs.js +1 -0
- package/lib/pages/cms/products/server-actions.es.js +193 -0
- package/lib/pages/cms/shipping/ShippingPage.cjs.js +5 -0
- package/lib/pages/cms/shipping/ShippingPage.es.js +211 -0
- package/lib/pages/cms/shipping/components/RateForm.cjs.js +1 -0
- package/lib/pages/cms/shipping/components/RateForm.es.js +441 -0
- package/lib/pages/cms/shipping/components/ZoneForm.cjs.js +1 -0
- package/lib/pages/cms/shipping/components/ZoneForm.es.js +228 -0
- package/lib/pages/cms/shipping/server-actions.cjs.js +1 -0
- package/lib/pages/cms/shipping/server-actions.es.js +159 -0
- package/lib/pages/cms/taxes/TaxesPage.cjs.js +1 -0
- package/lib/pages/cms/taxes/TaxesPage.es.js +172 -0
- package/lib/pages/cms/taxes/actions.cjs.js +1 -0
- package/lib/pages/cms/taxes/actions.es.js +57 -0
- package/lib/pages/cms/taxes/components/TaxRateForm.cjs.js +1 -0
- package/lib/pages/cms/taxes/components/TaxRateForm.es.js +100 -0
- package/lib/product-actions.cjs.js +237 -0
- package/lib/product-actions.es.js +524 -0
- package/lib/product-context.cjs.js +1 -0
- package/lib/product-context.es.js +16 -0
- package/lib/product-schema.cjs.js +1 -0
- package/lib/product-schema.es.js +134 -0
- package/lib/providers/freemius.cjs.js +5 -0
- package/lib/providers/freemius.es.js +538 -0
- package/lib/providers/stripe.cjs.js +1 -0
- package/lib/providers/stripe.es.js +473 -0
- package/lib/server-actions/coupon-actions.cjs.js +1 -0
- package/lib/server-actions/coupon-actions.es.js +23 -0
- package/lib/server-actions/customer-actions.cjs.js +1 -0
- package/lib/server-actions/customer-actions.es.js +30 -0
- package/lib/server-actions/product-actions.cjs.js +1 -0
- package/{server-actions → lib/server-actions}/product-actions.es.js +5 -4
- package/lib/server-actions/shipping-actions.cjs.js +1 -0
- package/{shipping-actions-BnHjlo2q.js → lib/server-actions/shipping-actions.es.js} +9 -7
- package/lib/server-actions/tax-actions.cjs.js +1 -0
- package/lib/server-actions/tax-actions.es.js +40 -0
- package/lib/shared-inventory.cjs.js +15 -0
- package/lib/shared-inventory.es.js +171 -0
- package/lib/shipping/resolver.cjs.js +7 -0
- package/lib/shipping/resolver.es.js +62 -0
- package/lib/shipping-rate-currency.cjs.js +1 -0
- package/lib/shipping-rate-currency.es.js +72 -0
- package/lib/states.cjs.js +1 -0
- package/{states-DlHJezQ1.js → lib/states.es.js} +27 -100
- package/lib/stripe/checkout.cjs.js +1 -0
- package/lib/stripe/checkout.es.js +182 -0
- package/lib/stripe/client.cjs.js +1 -0
- package/lib/stripe/client.es.js +7 -0
- package/lib/stripe/order-sync.cjs.js +1 -0
- package/lib/stripe/order-sync.es.js +130 -0
- package/lib/stripe/webhooks.cjs.js +1 -0
- package/lib/stripe/webhooks.es.js +30 -0
- package/lib/tax-calculation.cjs.js +1 -0
- package/lib/tax-calculation.es.js +101 -0
- package/lib/trials.cjs.js +1 -0
- package/{trials-RDcRAZKx.js → lib/trials.es.js} +9 -9
- package/{use-cart.es.js → lib/use-cart.es.js} +1 -0
- package/lib/zod-config.cjs.js +1 -0
- package/lib/zod-config.es.js +6 -0
- package/package.json +4 -4
- package/server.cjs.js +1 -110
- package/server.es.js +178 -6052
- package/AddToCartButton-DsSEH9yp.cjs +0 -1
- package/CouponForm-BI_5SBHQ.js +0 -152
- package/CouponForm-D_uu2bLP.cjs +0 -1
- package/CurrencyProvider-Cg-Q6ucj.cjs +0 -1
- package/CurrencyProvider-OzlRN96V.js +0 -120
- package/CurrencyProvider.cjs.js +0 -1
- package/CurrencyProvider.es.js +0 -10
- package/ProductDetailsLayout-BxJH_BxR.cjs +0 -1
- package/ProductDetailsLayout-Dg8dRTYp.js +0 -530
- package/ProductGrid-BdL7iglO.cjs +0 -1
- package/ProductGrid-D3AWM8sr.js +0 -130
- package/actions-AHmBrS5e.cjs +0 -48
- package/actions-j5fuSZX-.js +0 -820
- package/cart-store.cjs.js +0 -1
- package/components/Cart.cjs.js +0 -1
- package/components/Cart.es.js +0 -259
- package/components/CartDrawer.cjs.js +0 -1
- package/components/Checkout.cjs.js +0 -1
- package/components/CurrencySwitcher.cjs.js +0 -1
- package/components/FeaturedProduct.cjs.js +0 -1
- package/components/ProductDetailsLayout.cjs.js +0 -1
- package/components/ProductDetailsLayout.es.js +0 -19
- package/components/ProductGrid.cjs.js +0 -1
- package/components/ProductGrid.es.js +0 -6
- package/coupon-server-C9ySm3I5.cjs +0 -1
- package/customer-C-UPvrYN.cjs +0 -1
- package/invoice-ui-CAnJPu6n.cjs +0 -29
- package/invoice-ui-DtpbTJE1.js +0 -2886
- package/product-actions-CONBF8i6.cjs +0 -251
- package/product-actions-DjlIWCMH.js +0 -691
- package/resolver-Fz_FKsfX.cjs +0 -7
- package/resolver-cfrCaHpE.js +0 -128
- package/server-actions/product-actions.cjs.js +0 -1
- package/shipping-actions-D6zt20gg.cjs +0 -1
- package/states-CWYRxV4B.cjs +0 -1
- package/tax-calculation-Dab89aHd.js +0 -181
- package/tax-calculation-MkDKOEkL.cjs +0 -1
- package/trials-DvZaOtNy.cjs +0 -1
- /package/{components → lib/components}/SimpleTiptapRenderer.cjs.js +0 -0
- /package/{components → lib/components}/SimpleTiptapRenderer.es.js +0 -0
- /package/{currency-constants.cjs.js → lib/currency-constants.cjs.js} +0 -0
- /package/{currency-constants.es.js → lib/currency-constants.es.js} +0 -0
- /package/{currency-rest-client-uolJxUkL.cjs → lib/currency-rest-client.cjs.js} +0 -0
- /package/{currency-rest-client-CwoqdgAP.js → lib/currency-rest-client.es.js} +0 -0
- /package/{currency.cjs.js → lib/currency.cjs.js} +0 -0
- /package/{currency.es.js → lib/currency.es.js} +0 -0
- /package/{types.cjs.js → lib/types.cjs.js} +0 -0
- /package/{types.es.js → lib/types.es.js} +0 -0
- /package/{use-cart.cjs.js → lib/use-cart.cjs.js} +0 -0
- /package/{variation-utils.cjs.js → lib/variation-utils.cjs.js} +0 -0
- /package/{variation-utils.es.js → lib/variation-utils.es.js} +0 -0
|
@@ -1,251 +0,0 @@
|
|
|
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;
|