@nextblock-cms/ecom 0.8.1 → 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 -3224
- package/lib/CurrencyProvider.cjs.js +1 -0
- package/lib/CurrencyProvider.es.js +99 -0
- package/lib/cart-store.cjs.js +1 -0
- package/lib/cart-store.es.js +116 -0
- 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/lib/components/AddToCartButton.es.js +60 -0
- 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/lib/components/CartDrawer.es.js +119 -0
- package/lib/components/CartIcon.cjs.js +1 -0
- package/lib/components/CartIcon.es.js +34 -0
- package/lib/components/Checkout.cjs.js +1 -0
- package/lib/components/Checkout.es.js +987 -0
- 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/lib/components/CurrencySwitcher.es.js +18 -0
- 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/lib/components/FeaturedProduct.es.js +72 -0
- 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/SimpleTiptapRenderer.cjs.js +1 -0
- package/lib/components/SimpleTiptapRenderer.es.js +187 -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/lib/coupon-server.es.js +234 -0
- package/lib/coupons.cjs.js +1 -0
- package/lib/coupons.es.js +17 -0
- package/lib/currency-constants.cjs.js +1 -0
- package/lib/currency-constants.es.js +4 -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/currency.cjs.js +1 -0
- package/lib/currency.es.js +312 -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/lib/customer.es.js +58 -0
- 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/lib/server-actions/product-actions.es.js +16 -0
- package/lib/server-actions/shipping-actions.cjs.js +1 -0
- package/lib/server-actions/shipping-actions.es.js +27 -0
- 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/lib/states.es.js +127 -0
- 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/lib/trials.es.js +29 -0
- package/lib/types.cjs.js +1 -0
- package/lib/types.es.js +33 -0
- package/lib/use-cart.cjs.js +1 -0
- package/lib/use-cart.es.js +44 -0
- package/lib/variation-utils.cjs.js +1 -0
- package/lib/variation-utils.es.js +246 -0
- package/lib/zod-config.cjs.js +1 -0
- package/lib/zod-config.es.js +6 -0
- package/package.json +10 -5
- package/server.cjs.js +1 -110
- package/server.es.js +178 -6037
- package/invoice-ui-BJZfedDd.cjs +0 -332
- package/invoice-ui-GJ1ADAjn.js +0 -5759
- /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
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { jsx as r, jsxs as u, Fragment as y } from "react/jsx-runtime";
|
|
2
|
+
import d from "react";
|
|
3
|
+
const b = (t, a) => a.reduce((s, e) => {
|
|
4
|
+
switch (e.type) {
|
|
5
|
+
case "bold":
|
|
6
|
+
return /* @__PURE__ */ r("strong", { children: s });
|
|
7
|
+
case "italic":
|
|
8
|
+
return /* @__PURE__ */ r("em", { children: s });
|
|
9
|
+
case "underline":
|
|
10
|
+
case "u":
|
|
11
|
+
return /* @__PURE__ */ r("u", { children: s });
|
|
12
|
+
case "strike":
|
|
13
|
+
return /* @__PURE__ */ r("s", { children: s });
|
|
14
|
+
case "code":
|
|
15
|
+
return /* @__PURE__ */ r("code", { className: "bg-muted px-1.5 py-0.5 rounded text-[0.875em] font-mono", children: s });
|
|
16
|
+
case "link": {
|
|
17
|
+
const l = e.attrs?.href || "#", c = e.attrs?.target || "_blank";
|
|
18
|
+
return /* @__PURE__ */ r("a", { href: l, target: c, rel: "noopener noreferrer", className: "underline text-primary hover:text-primary/80", children: s });
|
|
19
|
+
}
|
|
20
|
+
case "highlight": {
|
|
21
|
+
const l = e.attrs?.color;
|
|
22
|
+
return /* @__PURE__ */ r("mark", { style: l ? { backgroundColor: l } : {}, className: l ? void 0 : "bg-yellow-200 dark:bg-yellow-800/50", children: s });
|
|
23
|
+
}
|
|
24
|
+
case "subscript":
|
|
25
|
+
return /* @__PURE__ */ r("sub", { children: s });
|
|
26
|
+
case "superscript":
|
|
27
|
+
return /* @__PURE__ */ r("sup", { children: s });
|
|
28
|
+
case "textStyle": {
|
|
29
|
+
const l = {};
|
|
30
|
+
return e.attrs?.color && (l.color = e.attrs.color), e.attrs?.fontSize && (l.fontSize = e.attrs.fontSize), e.attrs?.fontFamily && (l.fontFamily = e.attrs.fontFamily), Object.keys(l).length > 0 ? /* @__PURE__ */ r("span", { style: l, children: s }) : /* @__PURE__ */ r(y, { children: s });
|
|
31
|
+
}
|
|
32
|
+
default:
|
|
33
|
+
return s;
|
|
34
|
+
}
|
|
35
|
+
}, t), g = ["h1", "h2", "h3", "h4", "h5", "h6"], f = (t, a, s, e) => {
|
|
36
|
+
const l = Math.max(1, Math.min(6, t)), c = g[l - 1], o = e?.id;
|
|
37
|
+
return d.createElement(c, { key: s, className: "font-bold my-4", id: o }, a);
|
|
38
|
+
}, m = (t) => {
|
|
39
|
+
const a = {}, s = {}, e = t?.colspan, l = t?.rowspan, c = t?.colwidth;
|
|
40
|
+
return e && e > 1 && (a.colSpan = e), l && l > 1 && (a.rowSpan = l), c && Array.isArray(c) && c[0] && (s.minWidth = c[0]), Object.keys(s).length > 0 && (a.style = s), a;
|
|
41
|
+
}, h = (t, a) => {
|
|
42
|
+
if (t.type === "text") {
|
|
43
|
+
const e = t.text ?? "";
|
|
44
|
+
return /* @__PURE__ */ r(d.Fragment, { children: t.marks?.length ? b(e, t.marks) : e }, a);
|
|
45
|
+
}
|
|
46
|
+
const s = t.content?.map((e, l) => h(e, l)) ?? null;
|
|
47
|
+
switch (t.type) {
|
|
48
|
+
// ── Document ────────────────────────────────────────────────
|
|
49
|
+
case "doc":
|
|
50
|
+
return /* @__PURE__ */ r("div", { children: s }, a);
|
|
51
|
+
// ── Block-level text ────────────────────────────────────────
|
|
52
|
+
case "paragraph": {
|
|
53
|
+
if (!t.content?.length || t.content.every(
|
|
54
|
+
(o) => o.type === "text" && (!o.text || !o.text.trim())
|
|
55
|
+
)) return null;
|
|
56
|
+
const l = t.attrs?.textAlign, c = l ? { textAlign: l } : {};
|
|
57
|
+
return /* @__PURE__ */ r("p", { className: "mb-4", style: Object.keys(c).length ? c : void 0, children: s }, a);
|
|
58
|
+
}
|
|
59
|
+
case "heading":
|
|
60
|
+
return f(
|
|
61
|
+
t.attrs?.level || 1,
|
|
62
|
+
s,
|
|
63
|
+
a,
|
|
64
|
+
t.attrs ?? void 0
|
|
65
|
+
);
|
|
66
|
+
// ── Lists ───────────────────────────────────────────────────
|
|
67
|
+
case "bulletList":
|
|
68
|
+
return /* @__PURE__ */ r("ul", { className: "list-disc pl-5 mb-4", children: s }, a);
|
|
69
|
+
case "orderedList": {
|
|
70
|
+
const e = t.attrs?.start ?? 1;
|
|
71
|
+
return /* @__PURE__ */ r("ol", { className: "list-decimal pl-5 mb-4", start: e !== 1 ? e : void 0, children: s }, a);
|
|
72
|
+
}
|
|
73
|
+
case "listItem":
|
|
74
|
+
return /* @__PURE__ */ r("li", { children: s }, a);
|
|
75
|
+
case "taskList":
|
|
76
|
+
return /* @__PURE__ */ r("ul", { className: "list-none pl-0 mb-4 space-y-1", children: s }, a);
|
|
77
|
+
case "taskItem": {
|
|
78
|
+
const e = !!t.attrs?.checked;
|
|
79
|
+
return /* @__PURE__ */ u("li", { className: "flex items-start gap-2", children: [
|
|
80
|
+
/* @__PURE__ */ r("input", { type: "checkbox", checked: e, readOnly: !0, className: "mt-1.5 rounded" }),
|
|
81
|
+
/* @__PURE__ */ r("div", { className: e ? "line-through text-muted-foreground" : "", children: s })
|
|
82
|
+
] }, a);
|
|
83
|
+
}
|
|
84
|
+
// ── Quotes & code ───────────────────────────────────────────
|
|
85
|
+
case "blockquote":
|
|
86
|
+
return /* @__PURE__ */ r("blockquote", { className: "border-l-4 border-border pl-4 italic my-4", children: s }, a);
|
|
87
|
+
case "codeBlock": {
|
|
88
|
+
const e = t.attrs?.language;
|
|
89
|
+
return /* @__PURE__ */ r("pre", { className: "bg-muted rounded-lg p-4 mb-4 overflow-x-auto", "data-language": e || void 0, children: /* @__PURE__ */ r("code", { className: "text-sm font-mono", children: s }) }, a);
|
|
90
|
+
}
|
|
91
|
+
// ── Inline / void ───────────────────────────────────────────
|
|
92
|
+
case "horizontalRule":
|
|
93
|
+
return /* @__PURE__ */ r("hr", { className: "my-6 border-border" }, a);
|
|
94
|
+
case "hardBreak":
|
|
95
|
+
return /* @__PURE__ */ r("br", {}, a);
|
|
96
|
+
case "image": {
|
|
97
|
+
const e = t.attrs?.src, l = t.attrs?.alt || "", c = t.attrs?.title, o = t.attrs?.width, n = t.attrs?.height, i = {};
|
|
98
|
+
return o && (i.width = typeof o == "number" ? `${o}px` : o), n && (i.height = typeof n == "number" ? `${n}px` : n), /* @__PURE__ */ r(
|
|
99
|
+
"img",
|
|
100
|
+
{
|
|
101
|
+
src: e,
|
|
102
|
+
alt: l,
|
|
103
|
+
title: c,
|
|
104
|
+
style: Object.keys(i).length ? i : void 0,
|
|
105
|
+
className: "max-w-full h-auto rounded my-4"
|
|
106
|
+
},
|
|
107
|
+
a
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
// ── Table ───────────────────────────────────────────────────
|
|
111
|
+
case "table":
|
|
112
|
+
return /* @__PURE__ */ r("div", { className: "overflow-x-auto my-4", children: /* @__PURE__ */ r("table", { className: "w-full border-collapse border border-gray-300 dark:border-gray-700", style: { minWidth: 500 }, children: /* @__PURE__ */ r("tbody", { children: s }) }) }, a);
|
|
113
|
+
case "tableRow":
|
|
114
|
+
return /* @__PURE__ */ r("tr", { className: "border-b border-gray-300 dark:border-gray-700", children: s }, a);
|
|
115
|
+
case "tableHeader":
|
|
116
|
+
return /* @__PURE__ */ r(
|
|
117
|
+
"th",
|
|
118
|
+
{
|
|
119
|
+
...m(t.attrs ?? void 0),
|
|
120
|
+
className: "bg-gray-100 dark:bg-gray-800 font-bold p-3 text-left border border-gray-300 dark:border-gray-700",
|
|
121
|
+
children: s
|
|
122
|
+
},
|
|
123
|
+
a
|
|
124
|
+
);
|
|
125
|
+
case "tableCell":
|
|
126
|
+
return /* @__PURE__ */ r(
|
|
127
|
+
"td",
|
|
128
|
+
{
|
|
129
|
+
...m(t.attrs ?? void 0),
|
|
130
|
+
className: "p-3 border border-gray-300 dark:border-gray-700",
|
|
131
|
+
children: s
|
|
132
|
+
},
|
|
133
|
+
a
|
|
134
|
+
);
|
|
135
|
+
// ── Details / collapsible ───────────────────────────────────
|
|
136
|
+
case "details":
|
|
137
|
+
return /* @__PURE__ */ r("details", { className: "my-4 border rounded-lg overflow-hidden", children: s }, a);
|
|
138
|
+
case "detailsSummary":
|
|
139
|
+
return /* @__PURE__ */ r("summary", { className: "cursor-pointer p-3 font-semibold bg-muted/30 hover:bg-muted/50", children: s }, a);
|
|
140
|
+
case "detailsContent":
|
|
141
|
+
return /* @__PURE__ */ r("div", { className: "p-3 border-t", children: s }, a);
|
|
142
|
+
// ── Embeds ──────────────────────────────────────────────────
|
|
143
|
+
case "youtube": {
|
|
144
|
+
const e = t.attrs?.src, l = t.attrs?.width || 640, c = t.attrs?.height || 480;
|
|
145
|
+
return /* @__PURE__ */ r("div", { className: "relative my-4 overflow-hidden rounded-lg", style: { aspectRatio: `${l}/${c}`, maxWidth: l }, children: /* @__PURE__ */ r(
|
|
146
|
+
"iframe",
|
|
147
|
+
{
|
|
148
|
+
src: e,
|
|
149
|
+
allow: "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture",
|
|
150
|
+
allowFullScreen: !0,
|
|
151
|
+
className: "absolute inset-0 w-full h-full"
|
|
152
|
+
}
|
|
153
|
+
) }, a);
|
|
154
|
+
}
|
|
155
|
+
case "iframe": {
|
|
156
|
+
const e = t.attrs?.src;
|
|
157
|
+
return /* @__PURE__ */ r("div", { className: "my-4 overflow-hidden rounded-lg", style: { aspectRatio: "16/9" }, children: /* @__PURE__ */ r("iframe", { src: e, allowFullScreen: !0, className: "w-full h-full border-0" }) }, a);
|
|
158
|
+
}
|
|
159
|
+
// ── Mention ─────────────────────────────────────────────────
|
|
160
|
+
case "mention": {
|
|
161
|
+
const e = t.attrs?.label || t.attrs?.id || "";
|
|
162
|
+
return /* @__PURE__ */ u("span", { className: "text-primary font-medium", children: [
|
|
163
|
+
"@",
|
|
164
|
+
e
|
|
165
|
+
] }, a);
|
|
166
|
+
}
|
|
167
|
+
// ── Fallback ────────────────────────────────────────────────
|
|
168
|
+
default:
|
|
169
|
+
return /* @__PURE__ */ r("div", { children: s }, a);
|
|
170
|
+
}
|
|
171
|
+
}, p = ({ content: t, className: a }) => {
|
|
172
|
+
if (!t) return null;
|
|
173
|
+
if (typeof t == "string") {
|
|
174
|
+
if (t.trim().startsWith("{") || t.trim().startsWith("["))
|
|
175
|
+
try {
|
|
176
|
+
const e = JSON.parse(t);
|
|
177
|
+
return /* @__PURE__ */ r(p, { content: e, className: a });
|
|
178
|
+
} catch {
|
|
179
|
+
}
|
|
180
|
+
return /* @__PURE__ */ r("div", { className: a, dangerouslySetInnerHTML: { __html: t } });
|
|
181
|
+
}
|
|
182
|
+
const s = t;
|
|
183
|
+
return !s.content || !Array.isArray(s.content) ? null : /* @__PURE__ */ r("div", { className: a, children: s.content.map((e, l) => h(e, l)) });
|
|
184
|
+
};
|
|
185
|
+
export {
|
|
186
|
+
p as SimpleTiptapRenderer
|
|
187
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),_=require("react"),$=require("@nextblock-cms/ui/button"),S=require("@nextblock-cms/ui/Skeleton"),L=require("../use-cart.cjs.js"),F=require("lucide-react"),N=require("sonner"),I=require("../pages/cms/products/actions.cjs.js"),a=require("@nextblock-cms/utils"),B=require("../CurrencyProvider.cjs.js"),g=require("../currency.cjs.js"),E=require("../trials.cjs.js"),O=({product:e})=>{const y=L.useCart(l=>l),{t:o}=a.useTranslations(),{activeCurrencyCode:s,currencies:u,defaultCurrency:i}=B.useCurrency(),[q,M]=_.useState([]),[k,w]=_.useState(!0),[t,d]=_.useState("annual");if(_.useEffect(()=>{async function l(){try{if(!e.id)return;const c=await I.getPublicFreemiusPricing(e.id);M(c)}catch(c){console.error("Failed to load pricing:",c)}finally{w(!1)}}l()},[e.id]),!y)return r.jsx(S.Skeleton,{className:"h-14 w-full"});const{addItem:A}=y,m=q[0],n=m?.pricing?.[0],P=()=>{let l=e.price,c=e.freemius_plan_id;n&&(t==="monthly"&&n.monthly_price!=null&&(l=a.majorUnitAmountToMinor(n.monthly_price,i.code)),t==="annual"&&n.annual_price!=null&&(l=a.majorUnitAmountToMinor(n.annual_price,i.code)),t==="lifetime"&&n.lifetime_price!=null&&(l=a.majorUnitAmountToMinor(n.lifetime_price,i.code)));const C=u.reduce((j,v)=>(j[v.code]=g.convertMinorUnitAmount({amount:l,fromCurrencyCode:i.code,toCurrencyCode:v.code,currencies:u,applyRounding:!0}),j),{}),T=C[s]??l;m&&m.id&&(c=m.id);const{success:U,error:R}=A({id:e.id,product_id:e.id,title:e.title,price:T,prices:C,image_url:e.image_url,slug:e.slug,sku:e.sku,language_id:e.language_id,translation_group_id:e.translation_group_id,product_type:"digital",payment_provider:"freemius",provider:"freemius",billing_cycle:t,freemius_product_id:e.freemius_product_id,freemius_plan_id:c,trial_period_days:e.trial_period_days??0,trial_requires_payment_method:e.trial_requires_payment_method??!1,is_taxable:e.is_taxable,currency_code:s});U?N.toast.success(o("ecommerce.added_to_cart_success",{item:e.title})):N.toast.error(R||o("ecommerce.added_to_cart_error"))};if(k)return r.jsx(S.Skeleton,{className:"h-32 w-full"});if(!m||!n)return r.jsx("div",{className:"p-4 border border-dashed rounded-lg text-center text-muted-foreground",children:o("ecommerce.pricing_unavailable")});const h=n.monthly_price!=null,p=n.annual_price!=null,b=n.lifetime_price!=null;t==="annual"&&!p&&(h?d("monthly"):b&&d("lifetime"));const f=E.getTrialSummary(e);let x=e.price;return t==="monthly"&&n.monthly_price!=null&&(x=g.convertMinorUnitAmount({amount:a.majorUnitAmountToMinor(n.monthly_price,i.code),fromCurrencyCode:i.code,toCurrencyCode:s,currencies:u,applyRounding:!0})),t==="annual"&&n.annual_price!=null&&(x=g.convertMinorUnitAmount({amount:a.majorUnitAmountToMinor(n.annual_price,i.code),fromCurrencyCode:i.code,toCurrencyCode:s,currencies:u,applyRounding:!0})),t==="lifetime"&&n.lifetime_price!=null&&(x=g.convertMinorUnitAmount({amount:a.majorUnitAmountToMinor(n.lifetime_price,i.code),fromCurrencyCode:i.code,toCurrencyCode:s,currencies:u,applyRounding:!0})),r.jsxs("div",{className:"flex flex-col gap-4",children:[r.jsxs("div",{className:"flex bg-secondary/35 p-1 rounded-lg w-full max-w-sm mx-auto shadow-inner",children:[h&&r.jsx("button",{onClick:()=>d("monthly"),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"}`,children:o("ecommerce.monthly")}),p&&r.jsx("button",{onClick:()=>d("annual"),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"}`,children:o("ecommerce.annual")}),b&&r.jsx("button",{onClick:()=>d("lifetime"),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"}`,children:o("ecommerce.lifetime")})]}),r.jsxs("div",{className:"text-center",children:[r.jsx("span",{className:"text-3xl font-extrabold text-foreground",children:a.formatPrice(x,s)}),t!=="lifetime"&&r.jsxs("span",{className:"text-muted-foreground text-sm ml-1.5",children:["/ ",o(t==="annual"?"ecommerce.year":"ecommerce.month")]}),f&&r.jsxs("div",{className:"mt-1 text-xs font-medium text-emerald-600 dark:text-emerald-400",children:[f.label,r.jsx("span",{className:"mx-2 text-muted-foreground/50",children:"|"}),r.jsx("span",{className:"text-muted-foreground",children:f.paymentRequirementLabel})]})]}),r.jsxs($.Button,{onClick:P,className:"w-full h-12 text-md font-bold shadow-md transition-all hover:shadow-lg active:scale-[0.98]",children:[r.jsx(F.ShoppingCart,{className:"mr-2 h-4 w-4"}),f?.label?`Start ${f.label}`:o("ecommerce.get_license")]})]})};exports.SubscriptionSelector=O;
|
|
@@ -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;
|