@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
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as o, jsxs as m } from "react/jsx-runtime";
|
|
3
|
+
import { useState as h, useEffect as F } from "react";
|
|
4
|
+
import { Button as I } from "@nextblock-cms/ui/button";
|
|
5
|
+
import { Skeleton as k } from "@nextblock-cms/ui/Skeleton";
|
|
6
|
+
import { useCart as U } from "../use-cart.es.js";
|
|
7
|
+
import { ShoppingCart as B } from "lucide-react";
|
|
8
|
+
import { toast as P } from "sonner";
|
|
9
|
+
import { getPublicFreemiusPricing as E } from "../pages/cms/products/actions.es.js";
|
|
10
|
+
import { useTranslations as z, majorUnitAmountToMinor as s, formatPrice as D } from "@nextblock-cms/utils";
|
|
11
|
+
import { useCurrency as G } from "../CurrencyProvider.es.js";
|
|
12
|
+
import { convertMinorUnitAmount as g } from "../currency.es.js";
|
|
13
|
+
import { getTrialSummary as H } from "../trials.es.js";
|
|
14
|
+
const ne = ({ product: e }) => {
|
|
15
|
+
const y = U((l) => l), { t: i } = z(), { activeCurrencyCode: a, currencies: d, defaultCurrency: n } = G(), [S, M] = h([]), [R, A] = h(!0), [t, u] = h("annual");
|
|
16
|
+
if (F(() => {
|
|
17
|
+
async function l() {
|
|
18
|
+
try {
|
|
19
|
+
if (!e.id) return;
|
|
20
|
+
const c = await E(e.id);
|
|
21
|
+
M(c);
|
|
22
|
+
} catch (c) {
|
|
23
|
+
console.error("Failed to load pricing:", c);
|
|
24
|
+
} finally {
|
|
25
|
+
A(!1);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
l();
|
|
29
|
+
}, [e.id]), !y)
|
|
30
|
+
return /* @__PURE__ */ o(k, { className: "h-14 w-full" });
|
|
31
|
+
const { addItem: T } = y, f = S[0], r = f?.pricing?.[0], $ = () => {
|
|
32
|
+
let l = e.price, c = e.freemius_plan_id;
|
|
33
|
+
r && (t === "monthly" && r.monthly_price != null && (l = s(r.monthly_price, n.code)), t === "annual" && r.annual_price != null && (l = s(r.annual_price, n.code)), t === "lifetime" && r.lifetime_price != null && (l = s(r.lifetime_price, n.code)));
|
|
34
|
+
const v = d.reduce((N, w) => (N[w.code] = g({
|
|
35
|
+
amount: l,
|
|
36
|
+
fromCurrencyCode: n.code,
|
|
37
|
+
toCurrencyCode: w.code,
|
|
38
|
+
currencies: d,
|
|
39
|
+
applyRounding: !0
|
|
40
|
+
}), N), {}), j = v[a] ?? l;
|
|
41
|
+
f && f.id && (c = f.id);
|
|
42
|
+
const { success: q, error: L } = T({
|
|
43
|
+
id: e.id,
|
|
44
|
+
product_id: e.id,
|
|
45
|
+
title: e.title,
|
|
46
|
+
price: j,
|
|
47
|
+
prices: v,
|
|
48
|
+
image_url: e.image_url,
|
|
49
|
+
slug: e.slug,
|
|
50
|
+
sku: e.sku,
|
|
51
|
+
language_id: e.language_id,
|
|
52
|
+
translation_group_id: e.translation_group_id,
|
|
53
|
+
product_type: "digital",
|
|
54
|
+
payment_provider: "freemius",
|
|
55
|
+
provider: "freemius",
|
|
56
|
+
billing_cycle: t,
|
|
57
|
+
freemius_product_id: e.freemius_product_id,
|
|
58
|
+
freemius_plan_id: c,
|
|
59
|
+
// Overwrite if we got a real plan id
|
|
60
|
+
trial_period_days: e.trial_period_days ?? 0,
|
|
61
|
+
trial_requires_payment_method: e.trial_requires_payment_method ?? !1,
|
|
62
|
+
is_taxable: e.is_taxable,
|
|
63
|
+
currency_code: a
|
|
64
|
+
});
|
|
65
|
+
q ? P.success(i("ecommerce.added_to_cart_success", { item: e.title })) : P.error(L || i("ecommerce.added_to_cart_error"));
|
|
66
|
+
};
|
|
67
|
+
if (R)
|
|
68
|
+
return /* @__PURE__ */ o(k, { className: "h-32 w-full" });
|
|
69
|
+
if (!f || !r)
|
|
70
|
+
return /* @__PURE__ */ o("div", { className: "p-4 border border-dashed rounded-lg text-center text-muted-foreground", children: i("ecommerce.pricing_unavailable") });
|
|
71
|
+
const x = r.monthly_price != null, C = r.annual_price != null, b = r.lifetime_price != null;
|
|
72
|
+
t === "annual" && !C && (x ? u("monthly") : b && u("lifetime"));
|
|
73
|
+
const p = H(e);
|
|
74
|
+
let _ = e.price;
|
|
75
|
+
return t === "monthly" && r.monthly_price != null && (_ = g({
|
|
76
|
+
amount: s(r.monthly_price, n.code),
|
|
77
|
+
fromCurrencyCode: n.code,
|
|
78
|
+
toCurrencyCode: a,
|
|
79
|
+
currencies: d,
|
|
80
|
+
applyRounding: !0
|
|
81
|
+
})), t === "annual" && r.annual_price != null && (_ = g({
|
|
82
|
+
amount: s(r.annual_price, n.code),
|
|
83
|
+
fromCurrencyCode: n.code,
|
|
84
|
+
toCurrencyCode: a,
|
|
85
|
+
currencies: d,
|
|
86
|
+
applyRounding: !0
|
|
87
|
+
})), t === "lifetime" && r.lifetime_price != null && (_ = g({
|
|
88
|
+
amount: s(r.lifetime_price, n.code),
|
|
89
|
+
fromCurrencyCode: n.code,
|
|
90
|
+
toCurrencyCode: a,
|
|
91
|
+
currencies: d,
|
|
92
|
+
applyRounding: !0
|
|
93
|
+
})), /* @__PURE__ */ m("div", { className: "flex flex-col gap-4", children: [
|
|
94
|
+
/* @__PURE__ */ m("div", { className: "flex bg-secondary/35 p-1 rounded-lg w-full max-w-sm mx-auto shadow-inner", children: [
|
|
95
|
+
x && /* @__PURE__ */ o(
|
|
96
|
+
"button",
|
|
97
|
+
{
|
|
98
|
+
onClick: () => u("monthly"),
|
|
99
|
+
className: `flex-1 py-1.5 text-xs font-semibold rounded-md transition-all ${t === "monthly" ? "bg-background shadow-sm text-foreground" : "text-muted-foreground hover:text-foreground"}`,
|
|
100
|
+
children: i("ecommerce.monthly")
|
|
101
|
+
}
|
|
102
|
+
),
|
|
103
|
+
C && /* @__PURE__ */ o(
|
|
104
|
+
"button",
|
|
105
|
+
{
|
|
106
|
+
onClick: () => u("annual"),
|
|
107
|
+
className: `flex-1 py-1.5 text-xs font-semibold rounded-md transition-all ${t === "annual" ? "bg-background shadow-sm text-foreground" : "text-muted-foreground hover:text-foreground"}`,
|
|
108
|
+
children: i("ecommerce.annual")
|
|
109
|
+
}
|
|
110
|
+
),
|
|
111
|
+
b && /* @__PURE__ */ o(
|
|
112
|
+
"button",
|
|
113
|
+
{
|
|
114
|
+
onClick: () => u("lifetime"),
|
|
115
|
+
className: `flex-1 py-1.5 text-xs font-semibold rounded-md transition-all ${t === "lifetime" ? "bg-background shadow-sm text-foreground" : "text-muted-foreground hover:text-foreground"}`,
|
|
116
|
+
children: i("ecommerce.lifetime")
|
|
117
|
+
}
|
|
118
|
+
)
|
|
119
|
+
] }),
|
|
120
|
+
/* @__PURE__ */ m("div", { className: "text-center", children: [
|
|
121
|
+
/* @__PURE__ */ o("span", { className: "text-3xl font-extrabold text-foreground", children: D(_, a) }),
|
|
122
|
+
t !== "lifetime" && /* @__PURE__ */ m("span", { className: "text-muted-foreground text-sm ml-1.5", children: [
|
|
123
|
+
"/ ",
|
|
124
|
+
i(t === "annual" ? "ecommerce.year" : "ecommerce.month")
|
|
125
|
+
] }),
|
|
126
|
+
p && /* @__PURE__ */ m("div", { className: "mt-1 text-xs font-medium text-emerald-600 dark:text-emerald-400", children: [
|
|
127
|
+
p.label,
|
|
128
|
+
/* @__PURE__ */ o("span", { className: "mx-2 text-muted-foreground/50", children: "|" }),
|
|
129
|
+
/* @__PURE__ */ o("span", { className: "text-muted-foreground", children: p.paymentRequirementLabel })
|
|
130
|
+
] })
|
|
131
|
+
] }),
|
|
132
|
+
/* @__PURE__ */ m(I, { onClick: $, className: "w-full h-12 text-md font-bold shadow-md transition-all hover:shadow-lg active:scale-[0.98]", children: [
|
|
133
|
+
/* @__PURE__ */ o(B, { className: "mr-2 h-4 w-4" }),
|
|
134
|
+
p?.label ? `Start ${p.label}` : i("ecommerce.get_license")
|
|
135
|
+
] })
|
|
136
|
+
] });
|
|
137
|
+
};
|
|
138
|
+
export {
|
|
139
|
+
ne as SubscriptionSelector
|
|
140
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=[{code:"US",name:"United States"},{code:"CA",name:"Canada"},{code:"GB",name:"United Kingdom"},{code:"AU",name:"Australia"},{code:"NZ",name:"New Zealand"},{code:"IE",name:"Ireland"},{code:"FR",name:"France"},{code:"DE",name:"Germany"},{code:"IT",name:"Italy"},{code:"ES",name:"Spain"},{code:"MX",name:"Mexico"},{code:"BR",name:"Brazil"},{code:"AR",name:"Argentina"},{code:"CL",name:"Chile"},{code:"CO",name:"Colombia"},{code:"PE",name:"Peru"},{code:"ZA",name:"South Africa"},{code:"NG",name:"Nigeria"},{code:"KE",name:"Kenya"},{code:"IN",name:"India"},{code:"JP",name:"Japan"},{code:"KR",name:"South Korea"},{code:"CN",name:"China"},{code:"SG",name:"Singapore"},{code:"MY",name:"Malaysia"},{code:"PH",name:"Philippines"},{code:"TH",name:"Thailand"},{code:"VN",name:"Vietnam"},{code:"ID",name:"Indonesia"},{code:"AE",name:"United Arab Emirates"},{code:"SA",name:"Saudi Arabia"},{code:"EG",name:"Egypt"},{code:"MA",name:"Morocco"},{code:"DZ",name:"Algeria"},{code:"TN",name:"Tunisia"},{code:"PT",name:"Portugal"},{code:"NL",name:"Netherlands"},{code:"BE",name:"Belgium"},{code:"CH",name:"Switzerland"},{code:"AT",name:"Austria"},{code:"SE",name:"Sweden"},{code:"NO",name:"Norway"},{code:"DK",name:"Denmark"},{code:"FI",name:"Finland"},{code:"PL",name:"Poland"},{code:"CZ",name:"Czech Republic"},{code:"HU",name:"Hungary"},{code:"RO",name:"Romania"},{code:"BG",name:"Bulgaria"},{code:"GR",name:"Greece"},{code:"TR",name:"Turkey"},{code:"IL",name:"Israel"},{code:"CY",name:"Cyprus"},{code:"MT",name:"Malta"}],i={USA:"US","UNITED STATES OF AMERICA":"US",UK:"GB","GREAT BRITAIN":"GB"};function r(m){const o=m?.trim();if(!o)return null;const e=o.toUpperCase(),c=i[e];if(c)return c;const d=n.find(a=>a.code===e);return d?d.code:n.find(a=>a.name.toUpperCase()===e)?.code??null}exports.countries=n;exports.normalizeCountryCode=r;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
const d = [
|
|
2
|
+
{ code: "US", name: "United States" },
|
|
3
|
+
{ code: "CA", name: "Canada" },
|
|
4
|
+
{ code: "GB", name: "United Kingdom" },
|
|
5
|
+
{ code: "AU", name: "Australia" },
|
|
6
|
+
{ code: "NZ", name: "New Zealand" },
|
|
7
|
+
{ code: "IE", name: "Ireland" },
|
|
8
|
+
{ code: "FR", name: "France" },
|
|
9
|
+
{ code: "DE", name: "Germany" },
|
|
10
|
+
{ code: "IT", name: "Italy" },
|
|
11
|
+
{ code: "ES", name: "Spain" },
|
|
12
|
+
{ code: "MX", name: "Mexico" },
|
|
13
|
+
{ code: "BR", name: "Brazil" },
|
|
14
|
+
{ code: "AR", name: "Argentina" },
|
|
15
|
+
{ code: "CL", name: "Chile" },
|
|
16
|
+
{ code: "CO", name: "Colombia" },
|
|
17
|
+
{ code: "PE", name: "Peru" },
|
|
18
|
+
{ code: "ZA", name: "South Africa" },
|
|
19
|
+
{ code: "NG", name: "Nigeria" },
|
|
20
|
+
{ code: "KE", name: "Kenya" },
|
|
21
|
+
{ code: "IN", name: "India" },
|
|
22
|
+
{ code: "JP", name: "Japan" },
|
|
23
|
+
{ code: "KR", name: "South Korea" },
|
|
24
|
+
{ code: "CN", name: "China" },
|
|
25
|
+
{ code: "SG", name: "Singapore" },
|
|
26
|
+
{ code: "MY", name: "Malaysia" },
|
|
27
|
+
{ code: "PH", name: "Philippines" },
|
|
28
|
+
{ code: "TH", name: "Thailand" },
|
|
29
|
+
{ code: "VN", name: "Vietnam" },
|
|
30
|
+
{ code: "ID", name: "Indonesia" },
|
|
31
|
+
{ code: "AE", name: "United Arab Emirates" },
|
|
32
|
+
{ code: "SA", name: "Saudi Arabia" },
|
|
33
|
+
{ code: "EG", name: "Egypt" },
|
|
34
|
+
{ code: "MA", name: "Morocco" },
|
|
35
|
+
{ code: "DZ", name: "Algeria" },
|
|
36
|
+
{ code: "TN", name: "Tunisia" },
|
|
37
|
+
{ code: "PT", name: "Portugal" },
|
|
38
|
+
{ code: "NL", name: "Netherlands" },
|
|
39
|
+
{ code: "BE", name: "Belgium" },
|
|
40
|
+
{ code: "CH", name: "Switzerland" },
|
|
41
|
+
{ code: "AT", name: "Austria" },
|
|
42
|
+
{ code: "SE", name: "Sweden" },
|
|
43
|
+
{ code: "NO", name: "Norway" },
|
|
44
|
+
{ code: "DK", name: "Denmark" },
|
|
45
|
+
{ code: "FI", name: "Finland" },
|
|
46
|
+
{ code: "PL", name: "Poland" },
|
|
47
|
+
{ code: "CZ", name: "Czech Republic" },
|
|
48
|
+
{ code: "HU", name: "Hungary" },
|
|
49
|
+
{ code: "RO", name: "Romania" },
|
|
50
|
+
{ code: "BG", name: "Bulgaria" },
|
|
51
|
+
{ code: "GR", name: "Greece" },
|
|
52
|
+
{ code: "TR", name: "Turkey" },
|
|
53
|
+
{ code: "IL", name: "Israel" },
|
|
54
|
+
{ code: "CY", name: "Cyprus" },
|
|
55
|
+
{ code: "MT", name: "Malta" }
|
|
56
|
+
], i = {
|
|
57
|
+
USA: "US",
|
|
58
|
+
"UNITED STATES OF AMERICA": "US",
|
|
59
|
+
UK: "GB",
|
|
60
|
+
"GREAT BRITAIN": "GB"
|
|
61
|
+
};
|
|
62
|
+
function t(m) {
|
|
63
|
+
const n = m?.trim();
|
|
64
|
+
if (!n)
|
|
65
|
+
return null;
|
|
66
|
+
const e = n.toUpperCase(), o = i[e];
|
|
67
|
+
if (o)
|
|
68
|
+
return o;
|
|
69
|
+
const c = d.find((a) => a.code === e);
|
|
70
|
+
return c ? c.code : d.find(
|
|
71
|
+
(a) => a.name.toUpperCase() === e
|
|
72
|
+
)?.code ?? null;
|
|
73
|
+
}
|
|
74
|
+
export {
|
|
75
|
+
d as countries,
|
|
76
|
+
t as normalizeCountryCode
|
|
77
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("./coupons.cjs.js"),f=require("./currency.cjs.js");function P(e){if(!e)return null;const t=new Date(e);return Number.isNaN(t.getTime())?null:t}function q(e,t){return e==="all"||e===t}function E(e){return e==="stripe"||e==="freemius"?e:null}async function x(e){const{data:t,error:c}=await e.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});if(c)throw new Error(c.message);return(t||[]).map(i=>f.normalizeCurrencyRecord(i))}async function D(e){const{client:t,items:c}=e,i=await x(t);if(i.length===0)throw new Error("No active currencies are configured.");const o=i.find(n=>n.code===(e.currencyCode||"").toUpperCase())??f.getDefaultCurrency(i),d=[...new Set(c.map(n=>n.product_id).filter(Boolean))],s=[...new Set(c.map(n=>n.variant_id).filter(n=>!!n))];if(d.length===0)return{lines:[],currencies:i,selectedCurrency:o};const[{data:p,error:y},a]=await Promise.all([t.from("products").select("id, title, price, prices, sale_price, sale_prices, sale_start_at, sale_end_at, scheduled_price, scheduled_prices, scheduled_price_at, product_type, payment_provider, freemius_product_id, freemius_plan_id").in("id",d),s.length?t.from("product_variants").select("id, product_id, price, prices, sale_price, sale_prices, sale_start_at, sale_end_at, scheduled_price, scheduled_prices, scheduled_price_at").in("id",s):Promise.resolve({data:[],error:null})]);if(y)throw new Error(y.message);if(a.error)throw new Error(a.error.message);const v=p||[],_=a.data||[],w=new Map(v.map(n=>[n.id,n])),m=new Map(_.map(n=>[n.id,n])),h=[];for(const n of c){const r=w.get(n.product_id);if(!r)continue;const l=E(r.payment_provider)??(r.product_type==="digital"?"freemius":"stripe"),g=n.variant_id?m.get(n.variant_id):null,u=g&&g.product_id===r.id?g:r,C=f.resolveEffectivePriceForCurrency({prices:f.normalizePriceMap(u.prices),salePrices:f.normalizeSalePriceMap(u.sale_prices),fallbackPrice:u.price,fallbackSalePrice:u.sale_price,saleStartAt:u.sale_start_at,saleEndAt:u.sale_end_at,scheduledPrice:u.scheduled_price,scheduledPrices:f.normalizePriceMap(u.scheduled_prices),scheduledPriceAt:u.scheduled_price_at,currencyCode:o.code,currencies:i}),M=l==="freemius"?1:Math.max(1,Number(n.quantity)||1),S=Math.max(0,C.sale_price??C.price);h.push({key:b.getCartLineCouponKey(n),product_id:r.id,variant_id:g?.id??null,title:r.title,quantity:M,provider:l,subtotal:S*M,freemius_product_id:r.freemius_product_id??null,freemius_plan_id:r.freemius_plan_id??null})}return{lines:h,currencies:i,selectedCurrency:o}}async function A(e,t){const{data:c,error:i}=await e.from("coupon_products").select("product_id").eq("coupon_id",t);if(i)throw new Error(i.message);return new Set((c||[]).map(o=>o.product_id))}function T(e,t){const c=e.reduce((s,p)=>s+p.subtotal,0),i=Math.min(t,c);if(c<=0||i<=0)return new Map;const o=new Map;let d=0;return e.forEach((s,p)=>{const a=p===e.length-1?i-d:Math.min(s.subtotal,Math.floor(i*s.subtotal/c));d+=a,o.set(s.key,a)}),o}async function k(e){const t=b.normalizeCouponCode(e.code);if(!t)return{success:!1,error:"Enter a coupon code.",errorKey:"ecommerce.coupon_code_required"};if(!e.items.length)return{success:!1,error:"Add an item to your cart before applying a coupon.",errorKey:"ecommerce.coupon_cart_empty"};const{data:c,error:i}=await e.client.from("coupons").select("id, code, name, provider_scope, discount_type, discount_amount, is_active, starts_at, ends_at, redemption_limit, redemptions_count").ilike("code",t).maybeSingle();if(i)throw new Error(i.message);if(!c)return{success:!1,error:"Coupon code not found.",errorKey:"ecommerce.coupon_not_found"};const o=c,d=new Date,s=P(o.starts_at),p=P(o.ends_at);if(!o.is_active)return{success:!1,error:"This coupon is not active.",errorKey:"ecommerce.coupon_inactive"};if(s&&s>d)return{success:!1,error:"This coupon is not active yet.",errorKey:"ecommerce.coupon_not_started"};if(p&&p<=d)return{success:!1,error:"This coupon has expired.",errorKey:"ecommerce.coupon_expired"};if(o.redemption_limit!==null&&(o.redemptions_count??0)>=o.redemption_limit)return{success:!1,error:"This coupon has reached its redemption limit.",errorKey:"ecommerce.coupon_limit_reached"};const[{lines:y},a]=await Promise.all([D({client:e.client,items:e.items,currencyCode:e.currencyCode}),A(e.client,o.id)]),v=a.size>0,_=y.filter(r=>r.subtotal>0&&q(o.provider_scope,r.provider)&&(!v||a.has(r.product_id)));if(_.length===0)return{success:!1,error:"This coupon does not apply to the items in your cart.",errorKey:"ecommerce.coupon_not_applicable"};const w=o.discount_type==="fixed"?T(_,o.discount_amount):null,m=b.emptyProviderDiscounts(),h=_.map(r=>{const l=o.discount_type==="percent"?Math.min(r.subtotal,Math.round(r.subtotal*o.discount_amount/100)):w?.get(r.key)??0;return m[r.provider]+=l,{key:r.key,product_id:r.product_id,variant_id:r.variant_id,provider:r.provider,title:r.title,quantity:r.quantity,subtotal:r.subtotal,discount:l}});return{success:!0,quote:{couponId:o.id,code:o.code,name:o.name,discountType:o.discount_type,discountAmount:o.discount_amount,providerScope:o.provider_scope,eligibleSubtotal:_.reduce((r,l)=>r+l.subtotal,0),discountTotal:m.stripe+m.freemius,providerDiscounts:m,lineDiscounts:h}}}function I(e){const t=new Map;for(const c of e?.lineDiscounts??[])t.set(c.key,c.discount);return t}async function K(e){const{error:t}=await e.client.from("coupon_redemptions").insert({coupon_id:e.quote.couponId,order_id:e.orderId,coupon_code:e.quote.code,provider:e.provider,discount_total:Math.max(0,e.discountTotal),user_id:e.userId||null,customer_email:e.customerEmail||null,metadata:e.metadata||{}});if(t){console.error("Failed to record coupon redemption:",t);return}const{data:c}=await e.client.from("coupons").select("redemptions_count").eq("id",e.quote.couponId).single();await e.client.from("coupons").update({redemptions_count:(c?.redemptions_count??0)+1,updated_at:new Date().toISOString()}).eq("id",e.quote.couponId)}exports.getCouponQuote=k;exports.getQuoteLineDiscountMap=I;exports.recordCouponRedemption=K;
|
|
@@ -1,56 +1,45 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
return (e || "").trim().replace(/\s+/g, "").toUpperCase();
|
|
4
|
-
}
|
|
5
|
-
function D(e) {
|
|
6
|
-
return `${e.product_id}:${e.variant_id || "base"}`;
|
|
7
|
-
}
|
|
8
|
-
function T() {
|
|
9
|
-
return {
|
|
10
|
-
stripe: 0,
|
|
11
|
-
freemius: 0
|
|
12
|
-
};
|
|
13
|
-
}
|
|
1
|
+
import { normalizeCouponCode as S, getCartLineCouponKey as q, emptyProviderDiscounts as E } from "./coupons.es.js";
|
|
2
|
+
import { getDefaultCurrency as x, resolveEffectivePriceForCurrency as A, normalizePriceMap as C, normalizeSalePriceMap as D, normalizeCurrencyRecord as T } from "./currency.es.js";
|
|
14
3
|
function M(e) {
|
|
15
4
|
if (!e)
|
|
16
5
|
return null;
|
|
17
|
-
const
|
|
18
|
-
return Number.isNaN(
|
|
6
|
+
const t = new Date(e);
|
|
7
|
+
return Number.isNaN(t.getTime()) ? null : t;
|
|
19
8
|
}
|
|
20
|
-
function k(e,
|
|
21
|
-
return e === "all" || e ===
|
|
9
|
+
function k(e, t) {
|
|
10
|
+
return e === "all" || e === t;
|
|
22
11
|
}
|
|
23
12
|
function I(e) {
|
|
24
13
|
return e === "stripe" || e === "freemius" ? e : null;
|
|
25
14
|
}
|
|
26
15
|
async function K(e) {
|
|
27
|
-
const { data:
|
|
16
|
+
const { data: t, error: c } = await e.from("currencies").select(
|
|
28
17
|
"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"
|
|
29
18
|
).eq("is_active", !0).order("code", { ascending: !0 });
|
|
30
19
|
if (c)
|
|
31
20
|
throw new Error(c.message);
|
|
32
|
-
return (
|
|
21
|
+
return (t || []).map((s) => T(s));
|
|
33
22
|
}
|
|
34
23
|
async function L(e) {
|
|
35
|
-
const { client:
|
|
24
|
+
const { client: t, items: c } = e, s = await K(t);
|
|
36
25
|
if (s.length === 0)
|
|
37
26
|
throw new Error("No active currencies are configured.");
|
|
38
|
-
const r = s.find((n) => n.code === (e.currencyCode || "").toUpperCase()) ??
|
|
27
|
+
const r = s.find((n) => n.code === (e.currencyCode || "").toUpperCase()) ?? x(s), u = [...new Set(c.map((n) => n.product_id).filter(Boolean))], i = [
|
|
39
28
|
...new Set(
|
|
40
29
|
c.map((n) => n.variant_id).filter((n) => !!n)
|
|
41
30
|
)
|
|
42
31
|
];
|
|
43
|
-
if (
|
|
32
|
+
if (u.length === 0)
|
|
44
33
|
return {
|
|
45
34
|
lines: [],
|
|
46
35
|
currencies: s,
|
|
47
36
|
selectedCurrency: r
|
|
48
37
|
};
|
|
49
38
|
const [{ data: p, error: f }, a] = await Promise.all([
|
|
50
|
-
|
|
39
|
+
t.from("products").select(
|
|
51
40
|
"id, title, price, prices, sale_price, sale_prices, sale_start_at, sale_end_at, scheduled_price, scheduled_prices, scheduled_price_at, product_type, payment_provider, freemius_product_id, freemius_plan_id"
|
|
52
|
-
).in("id",
|
|
53
|
-
i.length ?
|
|
41
|
+
).in("id", u),
|
|
42
|
+
i.length ? t.from("product_variants").select("id, product_id, price, prices, sale_price, sale_prices, sale_start_at, sale_end_at, scheduled_price, scheduled_prices, scheduled_price_at").in("id", i) : Promise.resolve({ data: [], error: null })
|
|
54
43
|
]);
|
|
55
44
|
if (f)
|
|
56
45
|
throw new Error(f.message);
|
|
@@ -62,32 +51,32 @@ async function L(e) {
|
|
|
62
51
|
_.map((n) => [n.id, n])
|
|
63
52
|
), h = [];
|
|
64
53
|
for (const n of c) {
|
|
65
|
-
const
|
|
66
|
-
if (!
|
|
54
|
+
const o = v.get(n.product_id);
|
|
55
|
+
if (!o)
|
|
67
56
|
continue;
|
|
68
|
-
const l = I(
|
|
69
|
-
prices: C(
|
|
70
|
-
salePrices:
|
|
71
|
-
fallbackPrice:
|
|
72
|
-
fallbackSalePrice:
|
|
73
|
-
saleStartAt:
|
|
74
|
-
saleEndAt:
|
|
75
|
-
scheduledPrice:
|
|
76
|
-
scheduledPrices: C(
|
|
77
|
-
scheduledPriceAt:
|
|
57
|
+
const l = I(o.payment_provider) ?? (o.product_type === "digital" ? "freemius" : "stripe"), y = n.variant_id ? m.get(n.variant_id) : null, d = y && y.product_id === o.id ? y : o, w = A({
|
|
58
|
+
prices: C(d.prices),
|
|
59
|
+
salePrices: D(d.sale_prices),
|
|
60
|
+
fallbackPrice: d.price,
|
|
61
|
+
fallbackSalePrice: d.sale_price,
|
|
62
|
+
saleStartAt: d.sale_start_at,
|
|
63
|
+
saleEndAt: d.sale_end_at,
|
|
64
|
+
scheduledPrice: d.scheduled_price,
|
|
65
|
+
scheduledPrices: C(d.scheduled_prices),
|
|
66
|
+
scheduledPriceAt: d.scheduled_price_at,
|
|
78
67
|
currencyCode: r.code,
|
|
79
68
|
currencies: s
|
|
80
69
|
}), b = l === "freemius" ? 1 : Math.max(1, Number(n.quantity) || 1), P = Math.max(0, w.sale_price ?? w.price);
|
|
81
70
|
h.push({
|
|
82
|
-
key:
|
|
83
|
-
product_id:
|
|
71
|
+
key: q(n),
|
|
72
|
+
product_id: o.id,
|
|
84
73
|
variant_id: y?.id ?? null,
|
|
85
|
-
title:
|
|
74
|
+
title: o.title,
|
|
86
75
|
quantity: b,
|
|
87
76
|
provider: l,
|
|
88
77
|
subtotal: P * b,
|
|
89
|
-
freemius_product_id:
|
|
90
|
-
freemius_plan_id:
|
|
78
|
+
freemius_product_id: o.freemius_product_id ?? null,
|
|
79
|
+
freemius_plan_id: o.freemius_plan_id ?? null
|
|
91
80
|
});
|
|
92
81
|
}
|
|
93
82
|
return {
|
|
@@ -96,29 +85,29 @@ async function L(e) {
|
|
|
96
85
|
selectedCurrency: r
|
|
97
86
|
};
|
|
98
87
|
}
|
|
99
|
-
async function R(e,
|
|
100
|
-
const { data: c, error: s } = await e.from("coupon_products").select("product_id").eq("coupon_id",
|
|
88
|
+
async function R(e, t) {
|
|
89
|
+
const { data: c, error: s } = await e.from("coupon_products").select("product_id").eq("coupon_id", t);
|
|
101
90
|
if (s)
|
|
102
91
|
throw new Error(s.message);
|
|
103
92
|
return new Set((c || []).map((r) => r.product_id));
|
|
104
93
|
}
|
|
105
|
-
function z(e,
|
|
106
|
-
const c = e.reduce((i, p) => i + p.subtotal, 0), s = Math.min(
|
|
94
|
+
function z(e, t) {
|
|
95
|
+
const c = e.reduce((i, p) => i + p.subtotal, 0), s = Math.min(t, c);
|
|
107
96
|
if (c <= 0 || s <= 0)
|
|
108
97
|
return /* @__PURE__ */ new Map();
|
|
109
98
|
const r = /* @__PURE__ */ new Map();
|
|
110
|
-
let
|
|
99
|
+
let u = 0;
|
|
111
100
|
return e.forEach((i, p) => {
|
|
112
|
-
const a = p === e.length - 1 ? s -
|
|
101
|
+
const a = p === e.length - 1 ? s - u : Math.min(
|
|
113
102
|
i.subtotal,
|
|
114
103
|
Math.floor(s * i.subtotal / c)
|
|
115
104
|
);
|
|
116
|
-
|
|
105
|
+
u += a, r.set(i.key, a);
|
|
117
106
|
}), r;
|
|
118
107
|
}
|
|
119
|
-
async function
|
|
120
|
-
const
|
|
121
|
-
if (!
|
|
108
|
+
async function B(e) {
|
|
109
|
+
const t = S(e.code);
|
|
110
|
+
if (!t)
|
|
122
111
|
return {
|
|
123
112
|
success: !1,
|
|
124
113
|
error: "Enter a coupon code.",
|
|
@@ -132,7 +121,7 @@ async function F(e) {
|
|
|
132
121
|
};
|
|
133
122
|
const { data: c, error: s } = await e.client.from("coupons").select(
|
|
134
123
|
"id, code, name, provider_scope, discount_type, discount_amount, is_active, starts_at, ends_at, redemption_limit, redemptions_count"
|
|
135
|
-
).ilike("code",
|
|
124
|
+
).ilike("code", t).maybeSingle();
|
|
136
125
|
if (s)
|
|
137
126
|
throw new Error(s.message);
|
|
138
127
|
if (!c)
|
|
@@ -141,20 +130,20 @@ async function F(e) {
|
|
|
141
130
|
error: "Coupon code not found.",
|
|
142
131
|
errorKey: "ecommerce.coupon_not_found"
|
|
143
132
|
};
|
|
144
|
-
const r = c,
|
|
133
|
+
const r = c, u = /* @__PURE__ */ new Date(), i = M(r.starts_at), p = M(r.ends_at);
|
|
145
134
|
if (!r.is_active)
|
|
146
135
|
return {
|
|
147
136
|
success: !1,
|
|
148
137
|
error: "This coupon is not active.",
|
|
149
138
|
errorKey: "ecommerce.coupon_inactive"
|
|
150
139
|
};
|
|
151
|
-
if (i && i >
|
|
140
|
+
if (i && i > u)
|
|
152
141
|
return {
|
|
153
142
|
success: !1,
|
|
154
143
|
error: "This coupon is not active yet.",
|
|
155
144
|
errorKey: "ecommerce.coupon_not_started"
|
|
156
145
|
};
|
|
157
|
-
if (p && p <=
|
|
146
|
+
if (p && p <= u)
|
|
158
147
|
return {
|
|
159
148
|
success: !1,
|
|
160
149
|
error: "This coupon has expired.",
|
|
@@ -174,7 +163,7 @@ async function F(e) {
|
|
|
174
163
|
}),
|
|
175
164
|
R(e.client, r.id)
|
|
176
165
|
]), g = a.size > 0, _ = f.filter(
|
|
177
|
-
(
|
|
166
|
+
(o) => o.subtotal > 0 && k(r.provider_scope, o.provider) && (!g || a.has(o.product_id))
|
|
178
167
|
);
|
|
179
168
|
if (_.length === 0)
|
|
180
169
|
return {
|
|
@@ -182,16 +171,16 @@ async function F(e) {
|
|
|
182
171
|
error: "This coupon does not apply to the items in your cart.",
|
|
183
172
|
errorKey: "ecommerce.coupon_not_applicable"
|
|
184
173
|
};
|
|
185
|
-
const v = r.discount_type === "fixed" ? z(_, r.discount_amount) : null, m =
|
|
186
|
-
const l = r.discount_type === "percent" ? Math.min(
|
|
187
|
-
return m[
|
|
188
|
-
key:
|
|
189
|
-
product_id:
|
|
190
|
-
variant_id:
|
|
191
|
-
provider:
|
|
192
|
-
title:
|
|
193
|
-
quantity:
|
|
194
|
-
subtotal:
|
|
174
|
+
const v = r.discount_type === "fixed" ? z(_, r.discount_amount) : null, m = E(), h = _.map((o) => {
|
|
175
|
+
const l = r.discount_type === "percent" ? Math.min(o.subtotal, Math.round(o.subtotal * r.discount_amount / 100)) : v?.get(o.key) ?? 0;
|
|
176
|
+
return m[o.provider] += l, {
|
|
177
|
+
key: o.key,
|
|
178
|
+
product_id: o.product_id,
|
|
179
|
+
variant_id: o.variant_id,
|
|
180
|
+
provider: o.provider,
|
|
181
|
+
title: o.title,
|
|
182
|
+
quantity: o.quantity,
|
|
183
|
+
subtotal: o.subtotal,
|
|
195
184
|
discount: l
|
|
196
185
|
};
|
|
197
186
|
});
|
|
@@ -204,21 +193,21 @@ async function F(e) {
|
|
|
204
193
|
discountType: r.discount_type,
|
|
205
194
|
discountAmount: r.discount_amount,
|
|
206
195
|
providerScope: r.provider_scope,
|
|
207
|
-
eligibleSubtotal: _.reduce((
|
|
196
|
+
eligibleSubtotal: _.reduce((o, l) => o + l.subtotal, 0),
|
|
208
197
|
discountTotal: m.stripe + m.freemius,
|
|
209
198
|
providerDiscounts: m,
|
|
210
199
|
lineDiscounts: h
|
|
211
200
|
}
|
|
212
201
|
};
|
|
213
202
|
}
|
|
214
|
-
function
|
|
215
|
-
const
|
|
203
|
+
function Q(e) {
|
|
204
|
+
const t = /* @__PURE__ */ new Map();
|
|
216
205
|
for (const c of e?.lineDiscounts ?? [])
|
|
217
|
-
|
|
218
|
-
return
|
|
206
|
+
t.set(c.key, c.discount);
|
|
207
|
+
return t;
|
|
219
208
|
}
|
|
220
|
-
async function
|
|
221
|
-
const { error:
|
|
209
|
+
async function O(e) {
|
|
210
|
+
const { error: t } = await e.client.from("coupon_redemptions").insert({
|
|
222
211
|
coupon_id: e.quote.couponId,
|
|
223
212
|
order_id: e.orderId,
|
|
224
213
|
coupon_code: e.quote.code,
|
|
@@ -228,8 +217,8 @@ async function Q(e) {
|
|
|
228
217
|
customer_email: e.customerEmail || null,
|
|
229
218
|
metadata: e.metadata || {}
|
|
230
219
|
});
|
|
231
|
-
if (
|
|
232
|
-
console.error("Failed to record coupon redemption:",
|
|
220
|
+
if (t) {
|
|
221
|
+
console.error("Failed to record coupon redemption:", t);
|
|
233
222
|
return;
|
|
234
223
|
}
|
|
235
224
|
const { data: c } = await e.client.from("coupons").select("redemptions_count").eq("id", e.quote.couponId).single();
|
|
@@ -239,10 +228,7 @@ async function Q(e) {
|
|
|
239
228
|
}).eq("id", e.quote.couponId);
|
|
240
229
|
}
|
|
241
230
|
export {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
D as g,
|
|
246
|
-
A as n,
|
|
247
|
-
Q as r
|
|
231
|
+
B as getCouponQuote,
|
|
232
|
+
Q as getQuoteLineDiscountMap,
|
|
233
|
+
O as recordCouponRedemption
|
|
248
234
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function o(e){return(e||"").trim().replace(/\s+/g,"").toUpperCase()}function r(e){return`${e.product_id}:${e.variant_id||"base"}`}function t(){return{stripe:0,freemius:0}}exports.emptyProviderDiscounts=t;exports.getCartLineCouponKey=r;exports.normalizeCouponCode=o;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
function r(e) {
|
|
2
|
+
return (e || "").trim().replace(/\s+/g, "").toUpperCase();
|
|
3
|
+
}
|
|
4
|
+
function n(e) {
|
|
5
|
+
return `${e.product_id}:${e.variant_id || "base"}`;
|
|
6
|
+
}
|
|
7
|
+
function t() {
|
|
8
|
+
return {
|
|
9
|
+
stripe: 0,
|
|
10
|
+
freemius: 0
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
t as emptyProviderDiscounts,
|
|
15
|
+
n as getCartLineCouponKey,
|
|
16
|
+
r as normalizeCouponCode
|
|
17
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("zustand"),t=require("zustand/middleware"),c=require("@nextblock-cms/utils"),o=a.create()(t.persist(e=>({activeCurrencyCode:null,hasHydrated:!1,setActiveCurrencyCode:r=>e({activeCurrencyCode:c.normalizeCurrencyCode(r)}),setHasHydrated:r=>e({hasHydrated:r})}),{name:"currency-preference-storage",storage:t.createJSONStorage(()=>localStorage),skipHydration:!0,partialize:e=>({activeCurrencyCode:e.activeCurrencyCode}),onRehydrateStorage:()=>e=>{e?.setHasHydrated(!0)}}));exports.useCurrencyPreferenceStore=o;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { create as t } from "zustand";
|
|
2
|
+
import { persist as a, createJSONStorage as o } from "zustand/middleware";
|
|
3
|
+
import { normalizeCurrencyCode as c } from "@nextblock-cms/utils";
|
|
4
|
+
const s = t()(
|
|
5
|
+
a(
|
|
6
|
+
(e) => ({
|
|
7
|
+
activeCurrencyCode: null,
|
|
8
|
+
hasHydrated: !1,
|
|
9
|
+
setActiveCurrencyCode: (r) => e({ activeCurrencyCode: c(r) }),
|
|
10
|
+
setHasHydrated: (r) => e({ hasHydrated: r })
|
|
11
|
+
}),
|
|
12
|
+
{
|
|
13
|
+
name: "currency-preference-storage",
|
|
14
|
+
storage: o(() => localStorage),
|
|
15
|
+
skipHydration: !0,
|
|
16
|
+
partialize: (e) => ({
|
|
17
|
+
activeCurrencyCode: e.activeCurrencyCode
|
|
18
|
+
}),
|
|
19
|
+
onRehydrateStorage: () => (e) => {
|
|
20
|
+
e?.setHasHydrated(!0);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
)
|
|
24
|
+
);
|
|
25
|
+
export {
|
|
26
|
+
s as useCurrencyPreferenceStore
|
|
27
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("server-only");const R=require("@nextblock-cms/db/server"),a=require("@nextblock-cms/utils"),S=require("./currency.cjs.js"),v="https://api.frankfurter.dev",z="id, code, symbol, exchange_rate, is_default, is_active, auto_update_exchange_rate, auto_sync_product_prices, exchange_rate_source, exchange_rate_updated_at, updated_at, rounding_mode, rounding_increment, rounding_charm_amount";function w(r){if(!r.id)throw new Error(`Currency ${a.normalizeCurrencyCode(r.code)} is missing its ID.`);return r.id}function F(){return process.env.FX_API_BASE_URL?.trim().replace(/\/+$/,"")||v}function A(r){try{const e=new URL(r),n=e.pathname.replace(/\/+$/,"");return`${e.host}${n&&n!=="/"?n:""}`}catch{return r}}function $(r){if(!r||typeof r!="object")return!1;const e=r;return typeof e.base=="string"&&typeof e.date=="string"&&typeof e.quote=="string"&&typeof e.rate=="number"&&Number.isFinite(e.rate)&&e.rate>0}function q(r){return Array.isArray(r)&&r.every($)}async function E(){const r=R.getServiceRoleSupabaseClient(),{data:e,error:n}=await r.from("currencies").select(z).order("code",{ascending:!0});if(n)throw new Error(n.message);return{supabase:r,currencies:e||[]}}async function D(r){const e=a.normalizeCurrencyCode(r.newDefaultCurrencyCode),n=Number(r.previousBaseRate);if(!Number.isFinite(n)||n<=0)throw new Error("Cannot rebase exchange rates without a valid previous base rate.");const{supabase:f,currencies:c}=await E();if(!c.find(o=>a.normalizeCurrencyCode(o.code)===e))throw new Error(`Currency ${e} was not found for rebasing.`);const i=new Date().toISOString(),d=[],p=c.map(o=>{const C=w(o),u=a.normalizeCurrencyCode(o.code),y=u===e?1:Number((o.exchange_rate/n).toFixed(10));return d.push(u),{...o,id:C,exchange_rate:y,auto_update_exchange_rate:u===e?!1:o.auto_update_exchange_rate,exchange_rate_source:u===e?"store-default":o.exchange_rate_source||"rebased-default",exchange_rate_updated_at:i,updated_at:i}}),{error:s}=await f.from("currencies").upsert(p,{onConflict:"id"});if(s)throw new Error(s.message);return{rebasedAt:i,newDefaultCurrencyCode:e,updatedCurrencies:d}}async function N(){const{supabase:r,currencies:e}=await E();if(!e.length)throw new Error("No currencies are configured yet.");const n=e.map(t=>S.normalizeCurrencyRecord(t)),f=S.getDefaultCurrency(n),c=a.normalizeCurrencyCode(f.code),_=e.find(t=>a.normalizeCurrencyCode(t.code)===c);if(!_)throw new Error(`Default currency ${c} could not be found for syncing.`);const i=e.filter(t=>a.normalizeCurrencyCode(t.code)!==c&&t.auto_update_exchange_rate!==!1),d=F(),p=A(d),s=new Date().toISOString(),{error:o}=await r.from("currencies").upsert({..._,id:w(_),exchange_rate:1,auto_update_exchange_rate:!1,exchange_rate_source:"store-default",exchange_rate_updated_at:s,updated_at:s},{onConflict:"id"});if(o)throw new Error(o.message);if(!i.length)return{baseCurrencyCode:c,fetchedAt:s,provider:p,providerUrl:d,skippedCurrencies:[],updatedCurrencies:[]};const C=new URL(`${d}/v2/rates`);C.searchParams.set("base",c),C.searchParams.set("quotes",[...new Set(i.map(t=>a.normalizeCurrencyCode(t.code)))].join(","));const u=await fetch(C.toString(),{cache:"no-store",headers:{Accept:"application/json"}});if(!u.ok){const t=await u.text();throw new Error(`FX provider request failed (${u.status}): ${t||"Unexpected response body."}`)}const y=await u.json();if(!q(y))throw new Error("FX provider returned an unexpected response payload.");const m=new Map;for(const t of y)m.set(a.normalizeCurrencyCode(t.quote),t.rate);const x=[],b=[],g=[];for(const t of i){const h=a.normalizeCurrencyCode(t.code),l=m.get(h);if(!l||!Number.isFinite(l)||l<=0){b.push(h);continue}g.push({...t,id:w(t),exchange_rate:Number(l.toFixed(10)),exchange_rate_source:p,exchange_rate_updated_at:s,updated_at:s}),x.push(h)}if(g.length){const{error:t}=await r.from("currencies").upsert(g,{onConflict:"id"});if(t)throw new Error(t.message)}return{baseCurrencyCode:c,fetchedAt:s,provider:p,providerUrl:d,skippedCurrencies:b,updatedCurrencies:x}}async function P(r){const e=a.normalizeCurrencyCode(r),n=R.getServiceRoleSupabaseClient(),{error:f}=await n.rpc("clear_currency_price_overrides",{target_currency:e});if(f)throw new Error(f.message);return{currencyCode:e}}exports.clearAutoSyncedCurrencyPriceOverrides=P;exports.rebaseStoreCurrencyExchangeRates=D;exports.syncStoreCurrencyRates=N;
|