@nextblock-cms/ecom 0.8.6 → 0.8.11
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 +6 -6
- 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,691 +0,0 @@
|
|
|
1
|
-
import { deleteMediaFiles as E } from "@nextblock-cms/utils/server";
|
|
2
|
-
import "server-only";
|
|
3
|
-
import { getServiceRoleSupabaseClient as F } from "@nextblock-cms/db/server";
|
|
4
|
-
import { normalizeCurrencyCode as A } from "@nextblock-cms/utils";
|
|
5
|
-
function q(e) {
|
|
6
|
-
return e ?? F();
|
|
7
|
-
}
|
|
8
|
-
function R(e) {
|
|
9
|
-
return e ? (Array.isArray(e) ? e : [e]).map((r) => r?.code?.toUpperCase().trim()).filter((r) => !!r) : [];
|
|
10
|
-
}
|
|
11
|
-
function g(e) {
|
|
12
|
-
return [...new Set(e)].sort((t, r) => t.localeCompare(r));
|
|
13
|
-
}
|
|
14
|
-
function U(e, t) {
|
|
15
|
-
return !e || e === t ? t : "mixed";
|
|
16
|
-
}
|
|
17
|
-
async function w(e, t) {
|
|
18
|
-
const r = Array.from(
|
|
19
|
-
t.reduce((c, s) => {
|
|
20
|
-
const i = s.sku.trim();
|
|
21
|
-
return i && c.set(i, {
|
|
22
|
-
sku: i,
|
|
23
|
-
quantity: Math.max(0, Math.trunc(s.quantity))
|
|
24
|
-
}), c;
|
|
25
|
-
}, /* @__PURE__ */ new Map()).values()
|
|
26
|
-
);
|
|
27
|
-
if (r.length === 0)
|
|
28
|
-
return;
|
|
29
|
-
const { error: a } = await e.from("inventory_items").upsert(r, { onConflict: "sku" });
|
|
30
|
-
if (a)
|
|
31
|
-
throw new Error(a.message);
|
|
32
|
-
}
|
|
33
|
-
async function x(e, t) {
|
|
34
|
-
const r = g(
|
|
35
|
-
t.map((s) => s.trim()).filter(Boolean)
|
|
36
|
-
);
|
|
37
|
-
if (r.length === 0)
|
|
38
|
-
return /* @__PURE__ */ new Map();
|
|
39
|
-
const { data: a, error: c } = await e.from("inventory_items").select("sku, quantity").in("sku", r);
|
|
40
|
-
if (c)
|
|
41
|
-
throw new Error(c.message);
|
|
42
|
-
return new Map(
|
|
43
|
-
(a || []).map((s) => [
|
|
44
|
-
s.sku,
|
|
45
|
-
Math.max(0, s.quantity ?? 0)
|
|
46
|
-
])
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
async function b(e) {
|
|
50
|
-
const { data: t, error: r } = await e.from("products").select(
|
|
51
|
-
`
|
|
52
|
-
id,
|
|
53
|
-
title,
|
|
54
|
-
sku,
|
|
55
|
-
stock,
|
|
56
|
-
status,
|
|
57
|
-
languages (
|
|
58
|
-
code
|
|
59
|
-
),
|
|
60
|
-
product_variants (
|
|
61
|
-
id,
|
|
62
|
-
sku,
|
|
63
|
-
stock_quantity
|
|
64
|
-
)
|
|
65
|
-
`
|
|
66
|
-
).order("title", { ascending: !0 });
|
|
67
|
-
if (r)
|
|
68
|
-
throw new Error(r.message);
|
|
69
|
-
const a = /* @__PURE__ */ new Map(), c = (s, i, o, d, u) => {
|
|
70
|
-
const _ = s.trim();
|
|
71
|
-
if (!_)
|
|
72
|
-
return;
|
|
73
|
-
const l = R(d.languages), n = a.get(_);
|
|
74
|
-
if (n) {
|
|
75
|
-
n.usageType = U(n.usageType, i), n.stockFallback = Math.min(n.stockFallback, o), n.productTitles.add(d.title), n.parentProductSkus.add(d.sku), n.languages = /* @__PURE__ */ new Set([...n.languages, ...l]), n.statuses.add(d.status), n.productIds.add(d.id), u && n.variantIds.add(u);
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
a.set(_, {
|
|
79
|
-
sku: _,
|
|
80
|
-
stockFallback: o,
|
|
81
|
-
usageType: i,
|
|
82
|
-
productTitles: /* @__PURE__ */ new Set([d.title]),
|
|
83
|
-
parentProductSkus: /* @__PURE__ */ new Set([d.sku]),
|
|
84
|
-
languages: new Set(l),
|
|
85
|
-
statuses: /* @__PURE__ */ new Set([d.status]),
|
|
86
|
-
productIds: /* @__PURE__ */ new Set([d.id]),
|
|
87
|
-
variantIds: u ? /* @__PURE__ */ new Set([u]) : /* @__PURE__ */ new Set()
|
|
88
|
-
});
|
|
89
|
-
};
|
|
90
|
-
for (const s of t || []) {
|
|
91
|
-
const i = s.product_variants || [];
|
|
92
|
-
if (i.length > 0) {
|
|
93
|
-
for (const o of i)
|
|
94
|
-
c(
|
|
95
|
-
o.sku,
|
|
96
|
-
"variant",
|
|
97
|
-
Math.max(0, o.stock_quantity ?? 0),
|
|
98
|
-
s,
|
|
99
|
-
o.id
|
|
100
|
-
);
|
|
101
|
-
continue;
|
|
102
|
-
}
|
|
103
|
-
c(
|
|
104
|
-
s.sku,
|
|
105
|
-
"product",
|
|
106
|
-
Math.max(0, s.stock ?? 0),
|
|
107
|
-
s
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
return a;
|
|
111
|
-
}
|
|
112
|
-
async function O(e) {
|
|
113
|
-
const t = q(e), r = await b(t), a = [...r.keys()];
|
|
114
|
-
if (a.length === 0)
|
|
115
|
-
return [];
|
|
116
|
-
let c = await x(t, a);
|
|
117
|
-
const s = a.filter((i) => !c.has(i)).flatMap((i) => {
|
|
118
|
-
const o = r.get(i);
|
|
119
|
-
return o ? [
|
|
120
|
-
{
|
|
121
|
-
sku: i,
|
|
122
|
-
quantity: o.stockFallback
|
|
123
|
-
}
|
|
124
|
-
] : [];
|
|
125
|
-
});
|
|
126
|
-
return s.length > 0 && (await w(t, s), c = await x(t, a)), a.flatMap((i) => {
|
|
127
|
-
const o = r.get(i);
|
|
128
|
-
return o ? {
|
|
129
|
-
key: i,
|
|
130
|
-
sku: i,
|
|
131
|
-
stock: c.get(i) ?? o.stockFallback,
|
|
132
|
-
usageType: o.usageType,
|
|
133
|
-
productTitles: g(o.productTitles),
|
|
134
|
-
parentProductSkus: g(o.parentProductSkus),
|
|
135
|
-
languages: g(o.languages),
|
|
136
|
-
statuses: g(o.statuses),
|
|
137
|
-
productIds: g(o.productIds),
|
|
138
|
-
variantIds: g(o.variantIds)
|
|
139
|
-
} : [];
|
|
140
|
-
}).sort((i, o) => i.sku.localeCompare(o.sku) || i.usageType.localeCompare(o.usageType) || i.productTitles.join(", ").localeCompare(o.productTitles.join(", ")));
|
|
141
|
-
}
|
|
142
|
-
async function V(e, t) {
|
|
143
|
-
const r = q(t), a = e.sku.trim(), c = Math.max(0, Math.trunc(e.stock));
|
|
144
|
-
if (!a)
|
|
145
|
-
throw new Error("SKU is required to update inventory.");
|
|
146
|
-
await w(r, [{ sku: a, quantity: c }]);
|
|
147
|
-
const i = (await b(r)).get(a), o = (i?.productIds.size ?? 0) + (i?.variantIds.size ?? 0);
|
|
148
|
-
return { stock: c, affectedCount: o };
|
|
149
|
-
}
|
|
150
|
-
async function j(e, t, r) {
|
|
151
|
-
const a = q(r);
|
|
152
|
-
if (t.variants && t.variants.length > 0) {
|
|
153
|
-
const c = Array.from(
|
|
154
|
-
t.variants.reduce((s, i) => (s.set(
|
|
155
|
-
i.sku.trim(),
|
|
156
|
-
Math.max(0, Math.trunc(i.stock_quantity))
|
|
157
|
-
), s), /* @__PURE__ */ new Map()).entries()
|
|
158
|
-
).map(([s, i]) => ({ sku: s, quantity: i }));
|
|
159
|
-
await w(a, c);
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
await w(a, [
|
|
163
|
-
{
|
|
164
|
-
sku: t.sku,
|
|
165
|
-
quantity: Math.max(0, Math.trunc(t.stock))
|
|
166
|
-
}
|
|
167
|
-
]);
|
|
168
|
-
}
|
|
169
|
-
const y = (e) => Math.round(e * 100);
|
|
170
|
-
function h(e) {
|
|
171
|
-
return Object.entries(e || {}).reduce(
|
|
172
|
-
(t, [r, a]) => (typeof a == "number" && Number.isFinite(a) && a >= 0 && (t[A(r)] = y(a)), t),
|
|
173
|
-
{}
|
|
174
|
-
);
|
|
175
|
-
}
|
|
176
|
-
function z(e) {
|
|
177
|
-
return (e || []).map((t) => ({
|
|
178
|
-
id: t.id,
|
|
179
|
-
sku: t.sku,
|
|
180
|
-
upc: t.upc ?? null,
|
|
181
|
-
price: y(t.price),
|
|
182
|
-
sale_price: typeof t.sale_price == "number" && !isNaN(t.sale_price) ? y(t.sale_price) : null,
|
|
183
|
-
prices: h(t.prices),
|
|
184
|
-
sale_prices: h(t.sale_prices),
|
|
185
|
-
sale_start_at: t.sale_start_at ?? null,
|
|
186
|
-
sale_end_at: t.sale_end_at ?? null,
|
|
187
|
-
stock_quantity: t.stock_quantity,
|
|
188
|
-
main_media_id: t.main_media_id ?? null,
|
|
189
|
-
attribute_term_ids: t.attribute_term_ids
|
|
190
|
-
}));
|
|
191
|
-
}
|
|
192
|
-
function P(e, t) {
|
|
193
|
-
const a = e.product_type === "digital" && e.payment_provider === "freemius" ? Math.max(0, Number(e.trial_period_days ?? 0)) : 0;
|
|
194
|
-
return {
|
|
195
|
-
id: t,
|
|
196
|
-
product_type: e.product_type,
|
|
197
|
-
payment_provider: e.payment_provider,
|
|
198
|
-
title: e.title,
|
|
199
|
-
slug: e.slug,
|
|
200
|
-
sku: e.sku,
|
|
201
|
-
upc: e.upc ?? null,
|
|
202
|
-
stock: e.stock,
|
|
203
|
-
status: e.status,
|
|
204
|
-
short_description: e.short_description ?? null,
|
|
205
|
-
description_json: e.description_json ?? null,
|
|
206
|
-
metadata: {},
|
|
207
|
-
price: y(e.price),
|
|
208
|
-
sale_price: typeof e.sale_price == "number" && !isNaN(e.sale_price) ? y(e.sale_price) : null,
|
|
209
|
-
prices: h(e.prices),
|
|
210
|
-
sale_prices: h(e.sale_prices),
|
|
211
|
-
sale_start_at: e.sale_start_at ?? null,
|
|
212
|
-
sale_end_at: e.sale_end_at ?? null,
|
|
213
|
-
freemius_plan_id: e.freemius_plan_id ?? null,
|
|
214
|
-
freemius_product_id: e.freemius_product_id ?? null,
|
|
215
|
-
trial_period_days: a,
|
|
216
|
-
trial_requires_payment_method: a > 0 ? e.trial_requires_payment_method ?? !1 : !1,
|
|
217
|
-
is_taxable: e.is_taxable,
|
|
218
|
-
language_id: e.language_id,
|
|
219
|
-
translation_group_id: e.translation_group_id || void 0,
|
|
220
|
-
variants: z(e.variants)
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
async function C(e, t, r) {
|
|
224
|
-
const { error: a } = await e.from("products").update({
|
|
225
|
-
is_taxable: r,
|
|
226
|
-
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
227
|
-
}).eq("id", t);
|
|
228
|
-
if (a)
|
|
229
|
-
throw a;
|
|
230
|
-
}
|
|
231
|
-
async function T(e, t, r) {
|
|
232
|
-
const a = (/* @__PURE__ */ 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);
|
|
233
|
-
o.length === 0 && o.push(t);
|
|
234
|
-
const { error: d } = await e.from("products").update({
|
|
235
|
-
sale_price: c?.sale_price ?? null,
|
|
236
|
-
sale_prices: c?.sale_prices ?? null,
|
|
237
|
-
sale_start_at: r.sale_start_at ?? null,
|
|
238
|
-
sale_end_at: r.sale_end_at ?? null,
|
|
239
|
-
updated_at: a
|
|
240
|
-
}).in("id", o);
|
|
241
|
-
if (d)
|
|
242
|
-
throw d;
|
|
243
|
-
const u = r.variants ?? [];
|
|
244
|
-
if (u.length === 0)
|
|
245
|
-
return;
|
|
246
|
-
const { data: _ } = await e.from("product_variants").select("sku, sale_price, sale_prices").eq("product_id", t), l = new Map(
|
|
247
|
-
(_ ?? []).map((n) => [n.sku, n])
|
|
248
|
-
);
|
|
249
|
-
for (const n of u) {
|
|
250
|
-
const p = l.get(n.sku);
|
|
251
|
-
if (!p)
|
|
252
|
-
continue;
|
|
253
|
-
const { error: m } = await e.from("product_variants").update({
|
|
254
|
-
sale_price: p.sale_price ?? null,
|
|
255
|
-
sale_prices: p.sale_prices ?? null,
|
|
256
|
-
sale_start_at: n.sale_start_at ?? null,
|
|
257
|
-
sale_end_at: n.sale_end_at ?? null,
|
|
258
|
-
updated_at: a
|
|
259
|
-
}).eq("sku", n.sku).in("product_id", o);
|
|
260
|
-
if (m)
|
|
261
|
-
throw m;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
async function K(e, {
|
|
265
|
-
page: t = 1,
|
|
266
|
-
limit: r = 10,
|
|
267
|
-
search: a = "",
|
|
268
|
-
languageId: c,
|
|
269
|
-
categoryId: s
|
|
270
|
-
} = {}) {
|
|
271
|
-
const i = (t - 1) * r, o = i + r - 1;
|
|
272
|
-
let d = e.from("products").select(
|
|
273
|
-
"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))",
|
|
274
|
-
{ count: "exact" }
|
|
275
|
-
).range(i, o).order("created_at", { ascending: !1 });
|
|
276
|
-
if (c && (d = d.eq("language_id", c)), s) {
|
|
277
|
-
const { data: u, error: _ } = await e.from("product_categories").select("product_id").eq("category_id", s);
|
|
278
|
-
if (_)
|
|
279
|
-
return { data: [], error: _, count: 0 };
|
|
280
|
-
const l = (u || []).map((n) => n.product_id).filter(Boolean);
|
|
281
|
-
if (l.length === 0)
|
|
282
|
-
return { data: [], error: null, count: 0 };
|
|
283
|
-
d = d.in("id", l);
|
|
284
|
-
}
|
|
285
|
-
return a && (d = d.or(`title.ilike.%${a}%,sku.ilike.%${a}%`)), d;
|
|
286
|
-
}
|
|
287
|
-
async function L(e, t) {
|
|
288
|
-
return e.from("products").select(
|
|
289
|
-
`
|
|
290
|
-
*,
|
|
291
|
-
languages (
|
|
292
|
-
code
|
|
293
|
-
),
|
|
294
|
-
product_media (
|
|
295
|
-
media_id,
|
|
296
|
-
sort_order,
|
|
297
|
-
media (
|
|
298
|
-
id,
|
|
299
|
-
file_path,
|
|
300
|
-
object_key,
|
|
301
|
-
file_name,
|
|
302
|
-
blur_data_url,
|
|
303
|
-
width,
|
|
304
|
-
height
|
|
305
|
-
)
|
|
306
|
-
),
|
|
307
|
-
product_variants (
|
|
308
|
-
id,
|
|
309
|
-
sku,
|
|
310
|
-
upc,
|
|
311
|
-
main_media_id,
|
|
312
|
-
price,
|
|
313
|
-
prices,
|
|
314
|
-
sale_price,
|
|
315
|
-
sale_prices,
|
|
316
|
-
sale_start_at,
|
|
317
|
-
sale_end_at,
|
|
318
|
-
scheduled_price,
|
|
319
|
-
scheduled_prices,
|
|
320
|
-
scheduled_price_at,
|
|
321
|
-
stock_quantity,
|
|
322
|
-
media:main_media_id (
|
|
323
|
-
id,
|
|
324
|
-
file_path,
|
|
325
|
-
object_key,
|
|
326
|
-
description
|
|
327
|
-
),
|
|
328
|
-
variant_attribute_mapping (
|
|
329
|
-
attribute_term_id,
|
|
330
|
-
product_attribute_terms (
|
|
331
|
-
id,
|
|
332
|
-
attribute_id,
|
|
333
|
-
value,
|
|
334
|
-
slug,
|
|
335
|
-
sort_order,
|
|
336
|
-
value_translations,
|
|
337
|
-
product_attributes (
|
|
338
|
-
id,
|
|
339
|
-
name,
|
|
340
|
-
slug,
|
|
341
|
-
name_translations
|
|
342
|
-
)
|
|
343
|
-
)
|
|
344
|
-
)
|
|
345
|
-
),
|
|
346
|
-
freemius_plans (
|
|
347
|
-
id,
|
|
348
|
-
name,
|
|
349
|
-
title,
|
|
350
|
-
freemius_pricing (
|
|
351
|
-
id,
|
|
352
|
-
license_quota,
|
|
353
|
-
api_monthly_price,
|
|
354
|
-
api_annual_price,
|
|
355
|
-
api_lifetime_price,
|
|
356
|
-
override_monthly_price,
|
|
357
|
-
override_annual_price,
|
|
358
|
-
override_lifetime_price,
|
|
359
|
-
is_active
|
|
360
|
-
)
|
|
361
|
-
),
|
|
362
|
-
product_categories (
|
|
363
|
-
category:categories (
|
|
364
|
-
id,
|
|
365
|
-
name,
|
|
366
|
-
slug,
|
|
367
|
-
description,
|
|
368
|
-
name_translations,
|
|
369
|
-
description_translations
|
|
370
|
-
)
|
|
371
|
-
)
|
|
372
|
-
`
|
|
373
|
-
).eq("id", t).single();
|
|
374
|
-
}
|
|
375
|
-
async function Q(e, t, r) {
|
|
376
|
-
const { data: a, error: c } = await e.from("products").select(
|
|
377
|
-
`
|
|
378
|
-
*,
|
|
379
|
-
languages (
|
|
380
|
-
id,
|
|
381
|
-
code,
|
|
382
|
-
is_default
|
|
383
|
-
),
|
|
384
|
-
product_media (
|
|
385
|
-
media_id,
|
|
386
|
-
sort_order,
|
|
387
|
-
media (
|
|
388
|
-
id,
|
|
389
|
-
file_path,
|
|
390
|
-
object_key,
|
|
391
|
-
file_name,
|
|
392
|
-
blur_data_url,
|
|
393
|
-
width,
|
|
394
|
-
height
|
|
395
|
-
)
|
|
396
|
-
),
|
|
397
|
-
product_variants (
|
|
398
|
-
id,
|
|
399
|
-
sku,
|
|
400
|
-
upc,
|
|
401
|
-
main_media_id,
|
|
402
|
-
price,
|
|
403
|
-
prices,
|
|
404
|
-
sale_price,
|
|
405
|
-
sale_prices,
|
|
406
|
-
sale_start_at,
|
|
407
|
-
sale_end_at,
|
|
408
|
-
scheduled_price,
|
|
409
|
-
scheduled_prices,
|
|
410
|
-
scheduled_price_at,
|
|
411
|
-
stock_quantity,
|
|
412
|
-
media:main_media_id (
|
|
413
|
-
id,
|
|
414
|
-
file_path,
|
|
415
|
-
object_key,
|
|
416
|
-
description
|
|
417
|
-
),
|
|
418
|
-
variant_attribute_mapping (
|
|
419
|
-
attribute_term_id,
|
|
420
|
-
product_attribute_terms (
|
|
421
|
-
id,
|
|
422
|
-
attribute_id,
|
|
423
|
-
value,
|
|
424
|
-
slug,
|
|
425
|
-
sort_order,
|
|
426
|
-
value_translations,
|
|
427
|
-
product_attributes (
|
|
428
|
-
id,
|
|
429
|
-
name,
|
|
430
|
-
slug,
|
|
431
|
-
name_translations
|
|
432
|
-
)
|
|
433
|
-
)
|
|
434
|
-
)
|
|
435
|
-
),
|
|
436
|
-
freemius_plans (
|
|
437
|
-
id,
|
|
438
|
-
name,
|
|
439
|
-
title,
|
|
440
|
-
freemius_pricing (
|
|
441
|
-
id,
|
|
442
|
-
license_quota,
|
|
443
|
-
api_monthly_price,
|
|
444
|
-
api_annual_price,
|
|
445
|
-
api_lifetime_price,
|
|
446
|
-
override_monthly_price,
|
|
447
|
-
override_annual_price,
|
|
448
|
-
override_lifetime_price,
|
|
449
|
-
is_active
|
|
450
|
-
)
|
|
451
|
-
),
|
|
452
|
-
product_categories (
|
|
453
|
-
category:categories (
|
|
454
|
-
id,
|
|
455
|
-
name,
|
|
456
|
-
slug,
|
|
457
|
-
description,
|
|
458
|
-
name_translations,
|
|
459
|
-
description_translations
|
|
460
|
-
)
|
|
461
|
-
)
|
|
462
|
-
`
|
|
463
|
-
).eq("slug", t);
|
|
464
|
-
if (c)
|
|
465
|
-
return { data: null, error: c };
|
|
466
|
-
if (!a || a.length === 0)
|
|
467
|
-
return { data: null, error: { message: "Product not found", code: "PGRST116" } };
|
|
468
|
-
let s = null;
|
|
469
|
-
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 };
|
|
470
|
-
}
|
|
471
|
-
async function G(e, t) {
|
|
472
|
-
const { data: r, error: a } = await e.rpc("upsert_product_with_variants", {
|
|
473
|
-
product_payload: P(t)
|
|
474
|
-
});
|
|
475
|
-
if (a || !r) throw a || new Error("Failed to create product");
|
|
476
|
-
if (t.product_media && t.product_media.length > 0) {
|
|
477
|
-
const s = t.product_media.map((i, o) => ({
|
|
478
|
-
product_id: r,
|
|
479
|
-
media_id: i.media_id,
|
|
480
|
-
sort_order: o
|
|
481
|
-
}));
|
|
482
|
-
await e.from("product_media").insert(s);
|
|
483
|
-
} else t.media_id && await e.from("product_media").insert({
|
|
484
|
-
product_id: r,
|
|
485
|
-
media_id: t.media_id,
|
|
486
|
-
sort_order: 0
|
|
487
|
-
});
|
|
488
|
-
await C(e, r, t.is_taxable), await T(e, r, t), await j(r, t), t.category_ids !== void 0 && await I(e, r, t.category_ids);
|
|
489
|
-
const { data: c } = await e.from("products").select("*").eq("id", r).single();
|
|
490
|
-
return c;
|
|
491
|
-
}
|
|
492
|
-
async function H(e, t, r) {
|
|
493
|
-
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", {
|
|
494
|
-
product_payload: P(r, t)
|
|
495
|
-
});
|
|
496
|
-
if (i || !s) throw i || new Error("Failed to update product");
|
|
497
|
-
if (r.product_media) {
|
|
498
|
-
if (await e.from("product_media").delete().eq("product_id", t), r.product_media.length > 0) {
|
|
499
|
-
const n = r.product_media.map((p, m) => ({
|
|
500
|
-
product_id: t,
|
|
501
|
-
media_id: p.media_id,
|
|
502
|
-
sort_order: m
|
|
503
|
-
}));
|
|
504
|
-
await e.from("product_media").insert(n);
|
|
505
|
-
}
|
|
506
|
-
} else r.media_id && (await e.from("product_media").delete().eq("product_id", t), await e.from("product_media").insert({
|
|
507
|
-
product_id: t,
|
|
508
|
-
media_id: r.media_id,
|
|
509
|
-
sort_order: 0
|
|
510
|
-
}));
|
|
511
|
-
await C(e, s, r.is_taxable), await T(e, s, r);
|
|
512
|
-
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(/* @__PURE__ */ new Set([...u, ...d]));
|
|
513
|
-
if (_.length > 0)
|
|
514
|
-
for (const n of _) {
|
|
515
|
-
const { count: p } = await e.from("product_media").select("*", { count: "exact", head: !0 }).eq("media_id", n);
|
|
516
|
-
if (p && p > 0) continue;
|
|
517
|
-
const { count: m } = await e.from("posts").select("*", { count: "exact", head: !0 }).eq("feature_image_id", n);
|
|
518
|
-
if (m && m > 0) continue;
|
|
519
|
-
const { count: k } = await e.from("logos").select("*", { count: "exact", head: !0 }).eq("media_id", n);
|
|
520
|
-
if (k && k > 0) continue;
|
|
521
|
-
const { count: v } = await e.from("product_variants").select("*", { count: "exact", head: !0 }).eq("main_media_id", n);
|
|
522
|
-
if (v && v > 0) continue;
|
|
523
|
-
const { data: f } = await e.from("media").select("object_key, variants").eq("id", n).single();
|
|
524
|
-
if (f) {
|
|
525
|
-
const S = [f.object_key];
|
|
526
|
-
f.variants && Array.isArray(f.variants) && f.variants.forEach((M) => {
|
|
527
|
-
M.objectKey && S.push(M.objectKey);
|
|
528
|
-
}), await E(S), await e.from("media").delete().eq("id", n);
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
await j(s, r), r.category_ids !== void 0 && await I(e, t, r.category_ids);
|
|
532
|
-
const { data: l } = await e.from("products").select("*").eq("id", s).single();
|
|
533
|
-
return l;
|
|
534
|
-
}
|
|
535
|
-
async function J(e, t) {
|
|
536
|
-
const { error: r } = await e.from("products").delete().eq("id", t);
|
|
537
|
-
if (r) throw r;
|
|
538
|
-
return !0;
|
|
539
|
-
}
|
|
540
|
-
async function W(e, t, r) {
|
|
541
|
-
const { data: a, error: c } = await e.from("products").select("*").eq("id", r).single();
|
|
542
|
-
if (c || !a)
|
|
543
|
-
throw new Error(c?.message || "Source product not found");
|
|
544
|
-
const { data: s, error: i } = await e.from("products").select("language_id").eq("id", t).single();
|
|
545
|
-
if (i || !s)
|
|
546
|
-
throw new Error(i?.message || "Target product not found");
|
|
547
|
-
const { error: o } = await e.from("products").update({
|
|
548
|
-
title: a.title,
|
|
549
|
-
short_description: a.short_description,
|
|
550
|
-
description_json: a.description_json
|
|
551
|
-
}).eq("id", t);
|
|
552
|
-
if (o) throw o;
|
|
553
|
-
const { data: d, error: u } = await e.from("blocks").select("*").eq("product_id", r).order("order", { ascending: !0 });
|
|
554
|
-
if (u) throw u;
|
|
555
|
-
if (await e.from("blocks").delete().eq("product_id", t), d && d.length > 0) {
|
|
556
|
-
const l = d.map((p) => {
|
|
557
|
-
const { id: m, created_at: k, updated_at: v, ...f } = p;
|
|
558
|
-
return {
|
|
559
|
-
...f,
|
|
560
|
-
product_id: t,
|
|
561
|
-
language_id: s.language_id
|
|
562
|
-
};
|
|
563
|
-
}), { error: n } = await e.from("blocks").insert(l);
|
|
564
|
-
if (n) throw n;
|
|
565
|
-
}
|
|
566
|
-
await e.from("product_drafts").delete().eq("product_id", t), await e.from("product_media").delete().eq("product_id", t);
|
|
567
|
-
const { data: _ } = await e.from("product_media").select("media_id, sort_order").eq("product_id", r);
|
|
568
|
-
if (_ && _.length > 0) {
|
|
569
|
-
const l = _.map((n) => ({
|
|
570
|
-
product_id: t,
|
|
571
|
-
media_id: n.media_id,
|
|
572
|
-
sort_order: n.sort_order
|
|
573
|
-
}));
|
|
574
|
-
await e.from("product_media").insert(l);
|
|
575
|
-
}
|
|
576
|
-
return { success: !0 };
|
|
577
|
-
}
|
|
578
|
-
async function X(e, t, r, a = [], c = []) {
|
|
579
|
-
const { data: s } = await e.from("languages").select("id").eq("code", r).single();
|
|
580
|
-
if (!s)
|
|
581
|
-
return { data: [], error: "Language not found" };
|
|
582
|
-
const i = [];
|
|
583
|
-
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(",")})`);
|
|
584
|
-
let o = e.from("products").select(`
|
|
585
|
-
id,
|
|
586
|
-
title,
|
|
587
|
-
sku,
|
|
588
|
-
price,
|
|
589
|
-
prices,
|
|
590
|
-
sale_price,
|
|
591
|
-
sale_prices,
|
|
592
|
-
sale_start_at,
|
|
593
|
-
sale_end_at,
|
|
594
|
-
scheduled_price,
|
|
595
|
-
scheduled_prices,
|
|
596
|
-
scheduled_price_at,
|
|
597
|
-
stock,
|
|
598
|
-
slug,
|
|
599
|
-
language_id,
|
|
600
|
-
product_type,
|
|
601
|
-
payment_provider,
|
|
602
|
-
freemius_product_id,
|
|
603
|
-
freemius_plan_id,
|
|
604
|
-
trial_period_days,
|
|
605
|
-
trial_requires_payment_method,
|
|
606
|
-
is_taxable,
|
|
607
|
-
product_media (
|
|
608
|
-
media (
|
|
609
|
-
file_path,
|
|
610
|
-
object_key
|
|
611
|
-
)
|
|
612
|
-
),
|
|
613
|
-
product_variants (
|
|
614
|
-
id,
|
|
615
|
-
sku,
|
|
616
|
-
upc,
|
|
617
|
-
main_media_id,
|
|
618
|
-
price,
|
|
619
|
-
prices,
|
|
620
|
-
sale_price,
|
|
621
|
-
sale_prices,
|
|
622
|
-
sale_start_at,
|
|
623
|
-
sale_end_at,
|
|
624
|
-
scheduled_price,
|
|
625
|
-
scheduled_prices,
|
|
626
|
-
scheduled_price_at,
|
|
627
|
-
stock_quantity,
|
|
628
|
-
media:main_media_id (
|
|
629
|
-
file_path,
|
|
630
|
-
object_key,
|
|
631
|
-
description
|
|
632
|
-
),
|
|
633
|
-
variant_attribute_mapping (
|
|
634
|
-
attribute_term_id,
|
|
635
|
-
product_attribute_terms (
|
|
636
|
-
id,
|
|
637
|
-
attribute_id,
|
|
638
|
-
value,
|
|
639
|
-
slug,
|
|
640
|
-
sort_order,
|
|
641
|
-
value_translations,
|
|
642
|
-
product_attributes (
|
|
643
|
-
id,
|
|
644
|
-
name,
|
|
645
|
-
slug,
|
|
646
|
-
name_translations
|
|
647
|
-
)
|
|
648
|
-
)
|
|
649
|
-
)
|
|
650
|
-
),
|
|
651
|
-
translation_group_id
|
|
652
|
-
`).eq("language_id", s.id).eq("status", "active");
|
|
653
|
-
return i.length > 0 && (o = o.or(i.join(","))), await o.order("id");
|
|
654
|
-
}
|
|
655
|
-
async function I(e, t, r) {
|
|
656
|
-
const { data: a } = await e.from("products").select("translation_group_id").eq("id", t).single();
|
|
657
|
-
if (!a || !a.translation_group_id) {
|
|
658
|
-
if (await e.from("product_categories").delete().eq("product_id", t), r.length > 0) {
|
|
659
|
-
const i = r.map((o) => ({
|
|
660
|
-
product_id: t,
|
|
661
|
-
category_id: o
|
|
662
|
-
}));
|
|
663
|
-
await e.from("product_categories").insert(i);
|
|
664
|
-
}
|
|
665
|
-
return;
|
|
666
|
-
}
|
|
667
|
-
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];
|
|
668
|
-
if (await e.from("product_categories").delete().in("product_id", s), r.length > 0) {
|
|
669
|
-
const i = [];
|
|
670
|
-
for (const o of s)
|
|
671
|
-
for (const d of r)
|
|
672
|
-
i.push({
|
|
673
|
-
product_id: o,
|
|
674
|
-
category_id: d
|
|
675
|
-
});
|
|
676
|
-
await e.from("product_categories").insert(i);
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
export {
|
|
680
|
-
G as a,
|
|
681
|
-
L as b,
|
|
682
|
-
W as c,
|
|
683
|
-
J as d,
|
|
684
|
-
Q as e,
|
|
685
|
-
X as f,
|
|
686
|
-
O as g,
|
|
687
|
-
K as h,
|
|
688
|
-
I as i,
|
|
689
|
-
V as s,
|
|
690
|
-
H as u
|
|
691
|
-
};
|
package/resolver-Fz_FKsfX.cjs
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";const v=require("@nextblock-cms/db/server"),m=require("./currency.cjs.js"),y=require("@nextblock-cms/utils"),b=require("./variation-utils.cjs.js"),S=["auto","manual"];function p(e){if(typeof e=="string"){const o=e.trim().toLowerCase();if(S.includes(o))return o}return"auto"}function C(e,o=0){return typeof e=="number"&&Number.isFinite(e)&&e>=0?Math.round(e):o}function h(e){const o=y.normalizeCurrencyCode(e.sourceCurrencyCode),t=m.normalizePriceMap(e.amountMap);if(t[o]!==void 0)return o;const c=Object.keys(t)[0];return c?y.normalizeCurrencyCode(c):m.getDefaultCurrency(e.currencies).code}function O(e){const o=p(e.mode),t=m.normalizePriceMap(e.costAmounts),c=m.normalizePriceMap(e.minOrderAmounts),r=h({amountMap:Object.keys(t).length>0?t:c,sourceCurrencyCode:e.sourceCurrencyCode,currencies:e.currencies}),u=t[r]??C(e.fallbackCostAmount),s=c[r]??C(e.fallbackMinOrderAmount);if(o==="auto")return{mode:o,sourceCurrencyCode:r,costAmounts:{[r]:u},minOrderAmounts:{[r]:s}};const a=Object.keys(t).length>0?{...t}:{[r]:u},d=Object.keys(c).length>0?{...c}:{[r]:s};return a[r]===void 0&&(a[r]=u),d[r]===void 0&&(d[r]=s),{mode:o,sourceCurrencyCode:r,costAmounts:a,minOrderAmounts:d}}function M(e){const o=p(e.mode),t=m.normalizePriceMap(e.amountMap),c=y.normalizeCurrencyCode(e.currencyCode);if(o==="manual"&&t[c]!==void 0)return t[c];const r=h({amountMap:t,sourceCurrencyCode:e.sourceCurrencyCode,currencies:e.currencies}),u=t[r]??C(e.fallbackAmount);return c===r?u:m.convertMinorUnitAmount({amount:u,fromCurrencyCode:r,toCurrencyCode:c,currencies:e.currencies})}async function R(e,o,t,c){const r=v.getSsgSupabaseClient(),{data:u}=await r.from("currencies").select("code, symbol, exchange_rate, is_default, is_active, auto_sync_product_prices, auto_update_exchange_rate, exchange_rate_source, exchange_rate_updated_at, rounding_mode, rounding_increment, rounding_charm_amount").eq("is_active",!0).order("code",{ascending:!0}),s=u??[],a=m.getDefaultCurrency(s),d=c||a.code,{data:l,error:z}=await r.from("shipping_zone_locations").select(`
|
|
2
|
-
zone_id,
|
|
3
|
-
country_code,
|
|
4
|
-
state_code,
|
|
5
|
-
postal_code,
|
|
6
|
-
shipping_zones!inner(priority_order)
|
|
7
|
-
`).eq("country_code",o.country).order("shipping_zones(priority_order)",{ascending:!0});if(z||!l||l.length===0)return[];let _=null;if(o.state){const n=l.find(i=>i.state_code===o.state);n&&(_=n.zone_id)}if(!_){const n=l.find(i=>!i.state_code&&!i.postal_code);n&&(_=n.zone_id)}_||(_=l[0].zone_id);const{data:f,error:A}=await r.from("shipping_zone_methods").select("id, zone_id, method_type, cost_amount, cost_amounts, cost_currency, currency_pricing_mode, min_order_amount, min_order_amounts, name, name_translations").eq("zone_id",_);if(A||!f)return[];const g=f.filter(n=>{const i=M({amountMap:n.min_order_amounts||{},fallbackAmount:n.min_order_amount||0,sourceCurrencyCode:n.cost_currency||a.code,mode:n.currency_pricing_mode,currencyCode:d,currencies:s});return e>=i}).map(n=>({id:n.id,name:b.resolveTranslatedText(n.name,n.name_translations||null,t),amount:M({amountMap:n.cost_amounts||{},fallbackAmount:n.cost_amount||0,sourceCurrencyCode:n.cost_currency||a.code,mode:n.currency_pricing_mode,currencyCode:d,currencies:s}),currency:d,type:n.method_type})).sort((n,i)=>n.amount-i.amount)[0];return g?[g]:[]}exports.normalizeShippingRateCurrencyMode=p;exports.resolveShippingOptions=R;exports.sanitizeShippingRateAmountMaps=O;
|