@nextblock-cms/ecom 0.8.1 → 0.8.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/AddToCartButton-DsSEH9yp.cjs +1 -0
  2. package/AddToCartButton-ffE0DhHu.js +59 -0
  3. package/CouponForm-BI_5SBHQ.js +152 -0
  4. package/CouponForm-D_uu2bLP.cjs +1 -0
  5. package/CurrencyProvider-Cg-Q6ucj.cjs +1 -0
  6. package/CurrencyProvider-OzlRN96V.js +120 -0
  7. package/CurrencyProvider.cjs.js +1 -0
  8. package/CurrencyProvider.es.js +10 -0
  9. package/ProductDetailsLayout-BxJH_BxR.cjs +1 -0
  10. package/ProductDetailsLayout-Dg8dRTYp.js +530 -0
  11. package/ProductGrid-BdL7iglO.cjs +1 -0
  12. package/ProductGrid-D3AWM8sr.js +130 -0
  13. package/actions-AHmBrS5e.cjs +48 -0
  14. package/actions-j5fuSZX-.js +820 -0
  15. package/cart-store.cjs.js +1 -0
  16. package/cart-store.es.js +116 -0
  17. package/components/Cart.cjs.js +1 -0
  18. package/components/Cart.es.js +259 -0
  19. package/components/CartDrawer.cjs.js +1 -0
  20. package/components/CartDrawer.es.js +118 -0
  21. package/components/CartIcon.cjs.js +1 -0
  22. package/components/CartIcon.es.js +33 -0
  23. package/components/Checkout.cjs.js +1 -0
  24. package/components/Checkout.es.js +1020 -0
  25. package/components/CurrencySwitcher.cjs.js +1 -0
  26. package/components/CurrencySwitcher.es.js +17 -0
  27. package/components/FeaturedProduct.cjs.js +1 -0
  28. package/components/FeaturedProduct.es.js +71 -0
  29. package/components/ProductDetailsLayout.cjs.js +1 -0
  30. package/components/ProductDetailsLayout.es.js +19 -0
  31. package/components/ProductGrid.cjs.js +1 -0
  32. package/components/ProductGrid.es.js +6 -0
  33. package/components/SimpleTiptapRenderer.cjs.js +1 -0
  34. package/components/SimpleTiptapRenderer.es.js +187 -0
  35. package/coupon-server-C9ySm3I5.cjs +1 -0
  36. package/coupon-server-DUKVtyYs.js +248 -0
  37. package/currency-constants.cjs.js +1 -0
  38. package/currency-constants.es.js +4 -0
  39. package/currency.cjs.js +1 -0
  40. package/currency.es.js +312 -0
  41. package/customer-C-UPvrYN.cjs +1 -0
  42. package/customer-C3xccjUg.js +57 -0
  43. package/index.cjs.js +1 -1
  44. package/index.es.js +414 -3105
  45. package/invoice-ui-CAnJPu6n.cjs +29 -0
  46. package/invoice-ui-DtpbTJE1.js +2886 -0
  47. package/package.json +10 -5
  48. package/product-actions-CONBF8i6.cjs +251 -0
  49. package/product-actions-DjlIWCMH.js +691 -0
  50. package/resolver-Fz_FKsfX.cjs +7 -0
  51. package/resolver-cfrCaHpE.js +128 -0
  52. package/server-actions/product-actions.cjs.js +1 -0
  53. package/server-actions/product-actions.es.js +15 -0
  54. package/server.cjs.js +27 -27
  55. package/server.es.js +478 -463
  56. package/shipping-actions-BnHjlo2q.js +25 -0
  57. package/shipping-actions-D6zt20gg.cjs +1 -0
  58. package/states-CWYRxV4B.cjs +1 -0
  59. package/states-DlHJezQ1.js +200 -0
  60. package/tax-calculation-Dab89aHd.js +181 -0
  61. package/tax-calculation-MkDKOEkL.cjs +1 -0
  62. package/trials-DvZaOtNy.cjs +1 -0
  63. package/trials-RDcRAZKx.js +29 -0
  64. package/types.cjs.js +1 -0
  65. package/types.es.js +33 -0
  66. package/use-cart.cjs.js +1 -0
  67. package/use-cart.es.js +43 -0
  68. package/variation-utils.cjs.js +1 -0
  69. package/variation-utils.es.js +246 -0
  70. package/invoice-ui-BJZfedDd.cjs +0 -332
  71. package/invoice-ui-GJ1ADAjn.js +0 -5759
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),r=require("@nextblock-cms/ui/select"),i=require("../CurrencyProvider-Cg-Q6ucj.cjs");function s(){const{activeCurrencyCode:c,currencies:n,setActiveCurrencyCode:l}=i.useCurrency();return n.length<=1?null:e.jsxs(r.Select,{value:c,onValueChange:l,children:[e.jsx(r.SelectTrigger,{className:"h-9 w-[88px] text-xs font-semibold",children:e.jsx(r.SelectValue,{placeholder:c})}),e.jsx(r.SelectContent,{children:n.map(t=>e.jsx(r.SelectItem,{value:t.code,children:t.code},t.code))})]})}exports.CurrencySwitcher=s;
@@ -0,0 +1,17 @@
1
+ import { jsxs as n, jsx as e } from "react/jsx-runtime";
2
+ import { Select as o, SelectTrigger as i, SelectValue as u, SelectContent as s, SelectItem as a } from "@nextblock-cms/ui/select";
3
+ import { u as d } from "../CurrencyProvider-OzlRN96V.js";
4
+ function p() {
5
+ const {
6
+ activeCurrencyCode: t,
7
+ currencies: c,
8
+ setActiveCurrencyCode: l
9
+ } = d();
10
+ return c.length <= 1 ? null : /* @__PURE__ */ n(o, { value: t, onValueChange: l, children: [
11
+ /* @__PURE__ */ e(i, { className: "h-9 w-[88px] text-xs font-semibold", children: /* @__PURE__ */ e(u, { placeholder: t }) }),
12
+ /* @__PURE__ */ e(s, { children: c.map((r) => /* @__PURE__ */ e(a, { value: r.code, children: r.code }, r.code)) })
13
+ ] });
14
+ }
15
+ export {
16
+ p as CurrencySwitcher
17
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),h=require("../AddToCartButton-DsSEH9yp.cjs"),s=require("@nextblock-cms/utils"),o=require("next/link"),g=require("../CurrencyProvider-Cg-Q6ucj.cjs"),m=require("../currency.cjs.js"),v=require("../trials-DvZaOtNy.cjs"),b=({product:e,className:x,imagePosition:u="left"})=>{const{t:c}=s.useTranslations(),{activeCurrencyCode:l,currencies:n}=g.useCurrency(),a=m.resolvePriceRangeForCurrency({entries:e.variants?.length?e.variants:e.product_variants?.length?e.product_variants:[],currencyCode:l,currencies:n}),d=!!(e.has_variants&&a),t=m.resolveEffectivePriceForCurrency({prices:e.prices,salePrices:e.sale_prices,fallbackPrice:e.price,fallbackSalePrice:e.sale_price,saleStartAt:e.sale_start_at,saleEndAt:e.sale_end_at,scheduledPrice:e.scheduled_price,scheduledPrices:e.scheduled_prices,scheduledPriceAt:e.scheduled_price_at,currencyCode:l,currencies:n}),f=d&&a?a.min===a.max?s.formatPrice(a.min,l):`${s.formatPrice(a.min,l)} - ${s.formatPrice(a.max,l)}`:s.formatPrice(t.sale_price??t.price,l),i=v.getTrialSummary(e);return r.jsx("div",{className:s.cn("overflow-hidden rounded-xl border bg-card shadow-sm",x),children:r.jsxs("div",{className:s.cn("flex flex-col gap-8 md:flex-row",u==="right"&&"md:flex-row-reverse"),children:[r.jsx("div",{className:"relative aspect-square w-full md:w-1/2",children:e.image_url?r.jsx("img",{src:e.image_url,alt:e.title,className:"h-full w-full object-cover"}):r.jsx("div",{className:"flex h-full w-full items-center justify-center bg-secondary text-muted-foreground",children:c("ecommerce.no_image")})}),r.jsxs("div",{className:"flex flex-1 flex-col justify-center p-6 md:p-12",children:[r.jsx(o,{href:`/product/${e.slug}`,children:r.jsx("h2",{className:"mb-4 text-3xl font-bold tracking-tight hover:underline md:text-4xl",children:e.title})}),r.jsxs("div",{className:"mb-6 flex items-baseline gap-3",children:[r.jsx("span",{className:"text-3xl font-bold text-primary",children:f}),!d&&t.sale_price&&r.jsx("span",{className:"text-lg text-muted-foreground line-through",children:s.formatPrice(t.price,l)})]}),i&&r.jsxs("div",{className:"mb-6 inline-flex w-fit flex-col rounded-md border border-emerald-200 bg-emerald-50 px-3 py-2 text-sm text-emerald-900",children:[r.jsx("span",{className:"font-semibold",children:i.label}),r.jsx("span",{className:"text-emerald-700",children:i.paymentRequirementLabel})]}),e.short_description&&r.jsx("p",{className:"mb-8 text-lg text-muted-foreground",children:e.short_description}),r.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row",children:[r.jsx(h.AddToCartButton,{product:e,className:"h-12 w-full px-8 text-lg sm:w-auto"}),r.jsx(o,{href:`/product/${e.slug}`,className:"inline-flex h-12 items-center justify-center rounded-md border border-input bg-background px-8 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground",children:c("ecommerce.view_details")})]})]})]})})};exports.FeaturedProduct=b;
@@ -0,0 +1,71 @@
1
+ import { jsx as r, jsxs as s } from "react/jsx-runtime";
2
+ import { A as g } from "../AddToCartButton-ffE0DhHu.js";
3
+ import { useTranslations as v, formatPrice as i, cn as o } from "@nextblock-cms/utils";
4
+ import f from "next/link";
5
+ import { u as b } from "../CurrencyProvider-OzlRN96V.js";
6
+ import { resolvePriceRangeForCurrency as p, resolveEffectivePriceForCurrency as _ } from "../currency.es.js";
7
+ import { d as N } from "../trials-RDcRAZKx.js";
8
+ const R = ({ product: e, className: h, imagePosition: x = "left" }) => {
9
+ const { t: c } = v(), { activeCurrencyCode: l, currencies: m } = b(), a = p({
10
+ entries: e.variants?.length ? e.variants : e.product_variants?.length ? e.product_variants : [],
11
+ currencyCode: l,
12
+ currencies: m
13
+ }), d = !!(e.has_variants && a), t = _({
14
+ prices: e.prices,
15
+ salePrices: e.sale_prices,
16
+ fallbackPrice: e.price,
17
+ fallbackSalePrice: e.sale_price,
18
+ saleStartAt: e.sale_start_at,
19
+ saleEndAt: e.sale_end_at,
20
+ scheduledPrice: e.scheduled_price,
21
+ scheduledPrices: e.scheduled_prices,
22
+ scheduledPriceAt: e.scheduled_price_at,
23
+ currencyCode: l,
24
+ currencies: m
25
+ }), u = d && a ? a.min === a.max ? i(a.min, l) : `${i(a.min, l)} - ${i(
26
+ a.max,
27
+ l
28
+ )}` : i(t.sale_price ?? t.price, l), n = N(e);
29
+ return /* @__PURE__ */ r("div", { className: o("overflow-hidden rounded-xl border bg-card shadow-sm", h), children: /* @__PURE__ */ s("div", { className: o("flex flex-col gap-8 md:flex-row", x === "right" && "md:flex-row-reverse"), children: [
30
+ /* @__PURE__ */ r("div", { className: "relative aspect-square w-full md:w-1/2", children: e.image_url ? /* @__PURE__ */ r(
31
+ "img",
32
+ {
33
+ src: e.image_url,
34
+ alt: e.title,
35
+ className: "h-full w-full object-cover"
36
+ }
37
+ ) : /* @__PURE__ */ r("div", { className: "flex h-full w-full items-center justify-center bg-secondary text-muted-foreground", children: c("ecommerce.no_image") }) }),
38
+ /* @__PURE__ */ s("div", { className: "flex flex-1 flex-col justify-center p-6 md:p-12", children: [
39
+ /* @__PURE__ */ r(f, { href: `/product/${e.slug}`, children: /* @__PURE__ */ r("h2", { className: "mb-4 text-3xl font-bold tracking-tight hover:underline md:text-4xl", children: e.title }) }),
40
+ /* @__PURE__ */ s("div", { className: "mb-6 flex items-baseline gap-3", children: [
41
+ /* @__PURE__ */ r("span", { className: "text-3xl font-bold text-primary", children: u }),
42
+ !d && t.sale_price && /* @__PURE__ */ r("span", { className: "text-lg text-muted-foreground line-through", children: i(t.price, l) })
43
+ ] }),
44
+ n && /* @__PURE__ */ s("div", { className: "mb-6 inline-flex w-fit flex-col rounded-md border border-emerald-200 bg-emerald-50 px-3 py-2 text-sm text-emerald-900", children: [
45
+ /* @__PURE__ */ r("span", { className: "font-semibold", children: n.label }),
46
+ /* @__PURE__ */ r("span", { className: "text-emerald-700", children: n.paymentRequirementLabel })
47
+ ] }),
48
+ e.short_description && /* @__PURE__ */ r("p", { className: "mb-8 text-lg text-muted-foreground", children: e.short_description }),
49
+ /* @__PURE__ */ s("div", { className: "flex flex-col gap-4 sm:flex-row", children: [
50
+ /* @__PURE__ */ r(
51
+ g,
52
+ {
53
+ product: e,
54
+ className: "h-12 w-full px-8 text-lg sm:w-auto"
55
+ }
56
+ ),
57
+ /* @__PURE__ */ r(
58
+ f,
59
+ {
60
+ href: `/product/${e.slug}`,
61
+ className: "inline-flex h-12 items-center justify-center rounded-md border border-input bg-background px-8 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground",
62
+ children: c("ecommerce.view_details")
63
+ }
64
+ )
65
+ ] })
66
+ ] })
67
+ ] }) });
68
+ };
69
+ export {
70
+ R as FeaturedProduct
71
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("react/jsx-runtime");require("react");require("lucide-react");require("@nextblock-cms/ui/badge");require("@nextblock-cms/ui/button");require("@nextblock-cms/ui/label");require("@nextblock-cms/ui/separator");require("@nextblock-cms/utils");const e=require("../ProductDetailsLayout-BxJH_BxR.cjs");require("../AddToCartButton-DsSEH9yp.cjs");require("./SimpleTiptapRenderer.cjs.js");require("../variation-utils.cjs.js");require("../CurrencyProvider-Cg-Q6ucj.cjs");require("../currency.cjs.js");require("../types.cjs.js");require("../trials-DvZaOtNy.cjs");exports.ProductDetailsLayout=e.ProductDetailsLayout;
@@ -0,0 +1,19 @@
1
+ import "react/jsx-runtime";
2
+ import "react";
3
+ import "lucide-react";
4
+ import "@nextblock-cms/ui/badge";
5
+ import "@nextblock-cms/ui/button";
6
+ import "@nextblock-cms/ui/label";
7
+ import "@nextblock-cms/ui/separator";
8
+ import "@nextblock-cms/utils";
9
+ import { P as D } from "../ProductDetailsLayout-Dg8dRTYp.js";
10
+ import "../AddToCartButton-ffE0DhHu.js";
11
+ import "./SimpleTiptapRenderer.es.js";
12
+ import "../variation-utils.es.js";
13
+ import "../CurrencyProvider-OzlRN96V.js";
14
+ import "../currency.es.js";
15
+ import "../types.es.js";
16
+ import "../trials-RDcRAZKx.js";
17
+ export {
18
+ D as ProductDetailsLayout
19
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("react/jsx-runtime");const r=require("../ProductGrid-BdL7iglO.cjs");require("@nextblock-cms/utils");exports.ProductGrid=r.ProductGrid;
@@ -0,0 +1,6 @@
1
+ import "react/jsx-runtime";
2
+ import { a as m } from "../ProductGrid-D3AWM8sr.js";
3
+ import "@nextblock-cms/utils";
4
+ export {
5
+ m as ProductGrid
6
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),m=require("react"),y=(e,a)=>a.reduce((s,r)=>{switch(r.type){case"bold":return t.jsx("strong",{children:s});case"italic":return t.jsx("em",{children:s});case"underline":case"u":return t.jsx("u",{children:s});case"strike":return t.jsx("s",{children:s});case"code":return t.jsx("code",{className:"bg-muted px-1.5 py-0.5 rounded text-[0.875em] font-mono",children:s});case"link":{const l=r.attrs?.href||"#",c=r.attrs?.target||"_blank";return t.jsx("a",{href:l,target:c,rel:"noopener noreferrer",className:"underline text-primary hover:text-primary/80",children:s})}case"highlight":{const l=r.attrs?.color,c=l?{backgroundColor:l}:{};return t.jsx("mark",{style:c,className:l?void 0:"bg-yellow-200 dark:bg-yellow-800/50",children:s})}case"subscript":return t.jsx("sub",{children:s});case"superscript":return t.jsx("sup",{children:s});case"textStyle":{const l={};return r.attrs?.color&&(l.color=r.attrs.color),r.attrs?.fontSize&&(l.fontSize=r.attrs.fontSize),r.attrs?.fontFamily&&(l.fontFamily=r.attrs.fontFamily),Object.keys(l).length>0?t.jsx("span",{style:l,children:s}):t.jsx(t.Fragment,{children:s})}default:return s}},e),b=["h1","h2","h3","h4","h5","h6"],g=(e,a,s,r)=>{const l=Math.max(1,Math.min(6,e)),c=b[l-1],o=r?.id;return m.createElement(c,{key:s,className:"font-bold my-4",id:o},a)},u=e=>{const a={},s={},r=e?.colspan,l=e?.rowspan,c=e?.colwidth;return r&&r>1&&(a.colSpan=r),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},d=(e,a)=>{if(e.type==="text"){const r=e.text??"";return t.jsx(m.Fragment,{children:e.marks?.length?y(r,e.marks):r},a)}const s=e.content?.map((r,l)=>d(r,l))??null;switch(e.type){case"doc":return t.jsx("div",{children:s},a);case"paragraph":{if(!e.content?.length||e.content.every(o=>o.type==="text"&&(!o.text||!o.text.trim())))return null;const l=e.attrs?.textAlign,c=l?{textAlign:l}:{};return t.jsx("p",{className:"mb-4",style:Object.keys(c).length?c:void 0,children:s},a)}case"heading":return g(e.attrs?.level||1,s,a,e.attrs??void 0);case"bulletList":return t.jsx("ul",{className:"list-disc pl-5 mb-4",children:s},a);case"orderedList":{const r=e.attrs?.start??1;return t.jsx("ol",{className:"list-decimal pl-5 mb-4",start:r!==1?r:void 0,children:s},a)}case"listItem":return t.jsx("li",{children:s},a);case"taskList":return t.jsx("ul",{className:"list-none pl-0 mb-4 space-y-1",children:s},a);case"taskItem":{const r=!!e.attrs?.checked;return t.jsxs("li",{className:"flex items-start gap-2",children:[t.jsx("input",{type:"checkbox",checked:r,readOnly:!0,className:"mt-1.5 rounded"}),t.jsx("div",{className:r?"line-through text-muted-foreground":"",children:s})]},a)}case"blockquote":return t.jsx("blockquote",{className:"border-l-4 border-border pl-4 italic my-4",children:s},a);case"codeBlock":{const r=e.attrs?.language;return t.jsx("pre",{className:"bg-muted rounded-lg p-4 mb-4 overflow-x-auto","data-language":r||void 0,children:t.jsx("code",{className:"text-sm font-mono",children:s})},a)}case"horizontalRule":return t.jsx("hr",{className:"my-6 border-border"},a);case"hardBreak":return t.jsx("br",{},a);case"image":{const r=e.attrs?.src,l=e.attrs?.alt||"",c=e.attrs?.title,o=e.attrs?.width,n=e.attrs?.height,i={};return o&&(i.width=typeof o=="number"?`${o}px`:o),n&&(i.height=typeof n=="number"?`${n}px`:n),t.jsx("img",{src:r,alt:l,title:c,style:Object.keys(i).length?i:void 0,className:"max-w-full h-auto rounded my-4"},a)}case"table":return t.jsx("div",{className:"overflow-x-auto my-4",children:t.jsx("table",{className:"w-full border-collapse border border-gray-300 dark:border-gray-700",style:{minWidth:500},children:t.jsx("tbody",{children:s})})},a);case"tableRow":return t.jsx("tr",{className:"border-b border-gray-300 dark:border-gray-700",children:s},a);case"tableHeader":return t.jsx("th",{...u(e.attrs??void 0),className:"bg-gray-100 dark:bg-gray-800 font-bold p-3 text-left border border-gray-300 dark:border-gray-700",children:s},a);case"tableCell":return t.jsx("td",{...u(e.attrs??void 0),className:"p-3 border border-gray-300 dark:border-gray-700",children:s},a);case"details":return t.jsx("details",{className:"my-4 border rounded-lg overflow-hidden",children:s},a);case"detailsSummary":return t.jsx("summary",{className:"cursor-pointer p-3 font-semibold bg-muted/30 hover:bg-muted/50",children:s},a);case"detailsContent":return t.jsx("div",{className:"p-3 border-t",children:s},a);case"youtube":{const r=e.attrs?.src,l=e.attrs?.width||640,c=e.attrs?.height||480;return t.jsx("div",{className:"relative my-4 overflow-hidden rounded-lg",style:{aspectRatio:`${l}/${c}`,maxWidth:l},children:t.jsx("iframe",{src:r,allow:"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture",allowFullScreen:!0,className:"absolute inset-0 w-full h-full"})},a)}case"iframe":{const r=e.attrs?.src;return t.jsx("div",{className:"my-4 overflow-hidden rounded-lg",style:{aspectRatio:"16/9"},children:t.jsx("iframe",{src:r,allowFullScreen:!0,className:"w-full h-full border-0"})},a)}case"mention":{const r=e.attrs?.label||e.attrs?.id||"";return t.jsxs("span",{className:"text-primary font-medium",children:["@",r]},a)}default:return t.jsx("div",{children:s},a)}},h=({content:e,className:a})=>{if(!e)return null;if(typeof e=="string"){if(e.trim().startsWith("{")||e.trim().startsWith("["))try{const r=JSON.parse(e);return t.jsx(h,{content:r,className:a})}catch{}return t.jsx("div",{className:a,dangerouslySetInnerHTML:{__html:e}})}const s=e;return!s.content||!Array.isArray(s.content)?null:t.jsx("div",{className:a,children:s.content.map((r,l)=>d(r,l))})};exports.SimpleTiptapRenderer=h;
@@ -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";const f=require("./currency.cjs.js");function P(e){return(e||"").trim().replace(/\s+/g,"").toUpperCase()}function q(e){return`${e.product_id}:${e.variant_id||"base"}`}function S(){return{stripe:0,freemius:0}}function M(e){if(!e)return null;const t=new Date(e);return Number.isNaN(t.getTime())?null:t}function D(e,t){return e==="all"||e===t}function x(e){return e==="stripe"||e==="freemius"?e:null}async function A(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 K(e){const{client:t,items:c}=e,i=await A(t);if(i.length===0)throw new Error("No active currencies are configured.");const r=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:r};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 o=w.get(n.product_id);if(!o)continue;const l=x(o.payment_provider)??(o.product_type==="digital"?"freemius":"stripe"),g=n.variant_id?m.get(n.variant_id):null,u=g&&g.product_id===o.id?g:o,b=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:r.code,currencies:i}),C=l==="freemius"?1:Math.max(1,Number(n.quantity)||1),E=Math.max(0,b.sale_price??b.price);h.push({key:q(n),product_id:o.id,variant_id:g?.id??null,title:o.title,quantity:C,provider:l,subtotal:E*C,freemius_product_id:o.freemius_product_id??null,freemius_plan_id:o.freemius_plan_id??null})}return{lines:h,currencies:i,selectedCurrency:r}}async function T(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(r=>r.product_id))}function k(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 r=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,r.set(s.key,a)}),r}async function I(e){const t=P(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 r=c,d=new Date,s=M(r.starts_at),p=M(r.ends_at);if(!r.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(r.redemption_limit!==null&&(r.redemptions_count??0)>=r.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([K({client:e.client,items:e.items,currencyCode:e.currencyCode}),T(e.client,r.id)]),v=a.size>0,_=y.filter(o=>o.subtotal>0&&D(r.provider_scope,o.provider)&&(!v||a.has(o.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=r.discount_type==="fixed"?k(_,r.discount_amount):null,m=S(),h=_.map(o=>{const l=r.discount_type==="percent"?Math.min(o.subtotal,Math.round(o.subtotal*r.discount_amount/100)):w?.get(o.key)??0;return m[o.provider]+=l,{key:o.key,product_id:o.product_id,variant_id:o.variant_id,provider:o.provider,title:o.title,quantity:o.quantity,subtotal:o.subtotal,discount:l}});return{success:!0,quote:{couponId:r.id,code:r.code,name:r.name,discountType:r.discount_type,discountAmount:r.discount_amount,providerScope:r.provider_scope,eligibleSubtotal:_.reduce((o,l)=>o+l.subtotal,0),discountTotal:m.stripe+m.freemius,providerDiscounts:m,lineDiscounts:h}}}function L(e){const t=new Map;for(const c of e?.lineDiscounts??[])t.set(c.key,c.discount);return t}async function z(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.emptyProviderDiscounts=S;exports.getCartLineCouponKey=q;exports.getCouponQuote=I;exports.getQuoteLineDiscountMap=L;exports.normalizeCouponCode=P;exports.recordCouponRedemption=z;
@@ -0,0 +1,248 @@
1
+ import { getDefaultCurrency as S, resolveEffectivePriceForCurrency as q, normalizePriceMap as C, normalizeSalePriceMap as E, normalizeCurrencyRecord as x } from "./currency.es.js";
2
+ function A(e) {
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
+ }
14
+ function M(e) {
15
+ if (!e)
16
+ return null;
17
+ const o = new Date(e);
18
+ return Number.isNaN(o.getTime()) ? null : o;
19
+ }
20
+ function k(e, o) {
21
+ return e === "all" || e === o;
22
+ }
23
+ function I(e) {
24
+ return e === "stripe" || e === "freemius" ? e : null;
25
+ }
26
+ async function K(e) {
27
+ const { data: o, error: c } = await e.from("currencies").select(
28
+ "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
+ ).eq("is_active", !0).order("code", { ascending: !0 });
30
+ if (c)
31
+ throw new Error(c.message);
32
+ return (o || []).map((s) => x(s));
33
+ }
34
+ async function L(e) {
35
+ const { client: o, items: c } = e, s = await K(o);
36
+ if (s.length === 0)
37
+ throw new Error("No active currencies are configured.");
38
+ const r = s.find((n) => n.code === (e.currencyCode || "").toUpperCase()) ?? S(s), d = [...new Set(c.map((n) => n.product_id).filter(Boolean))], i = [
39
+ ...new Set(
40
+ c.map((n) => n.variant_id).filter((n) => !!n)
41
+ )
42
+ ];
43
+ if (d.length === 0)
44
+ return {
45
+ lines: [],
46
+ currencies: s,
47
+ selectedCurrency: r
48
+ };
49
+ const [{ data: p, error: f }, a] = await Promise.all([
50
+ o.from("products").select(
51
+ "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", d),
53
+ i.length ? o.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
+ ]);
55
+ if (f)
56
+ throw new Error(f.message);
57
+ if (a.error)
58
+ throw new Error(a.error.message);
59
+ const g = p || [], _ = a.data || [], v = new Map(
60
+ g.map((n) => [n.id, n])
61
+ ), m = new Map(
62
+ _.map((n) => [n.id, n])
63
+ ), h = [];
64
+ for (const n of c) {
65
+ const t = v.get(n.product_id);
66
+ if (!t)
67
+ continue;
68
+ const l = I(t.payment_provider) ?? (t.product_type === "digital" ? "freemius" : "stripe"), y = n.variant_id ? m.get(n.variant_id) : null, u = y && y.product_id === t.id ? y : t, w = q({
69
+ prices: C(u.prices),
70
+ salePrices: E(u.sale_prices),
71
+ fallbackPrice: u.price,
72
+ fallbackSalePrice: u.sale_price,
73
+ saleStartAt: u.sale_start_at,
74
+ saleEndAt: u.sale_end_at,
75
+ scheduledPrice: u.scheduled_price,
76
+ scheduledPrices: C(u.scheduled_prices),
77
+ scheduledPriceAt: u.scheduled_price_at,
78
+ currencyCode: r.code,
79
+ currencies: s
80
+ }), b = l === "freemius" ? 1 : Math.max(1, Number(n.quantity) || 1), P = Math.max(0, w.sale_price ?? w.price);
81
+ h.push({
82
+ key: D(n),
83
+ product_id: t.id,
84
+ variant_id: y?.id ?? null,
85
+ title: t.title,
86
+ quantity: b,
87
+ provider: l,
88
+ subtotal: P * b,
89
+ freemius_product_id: t.freemius_product_id ?? null,
90
+ freemius_plan_id: t.freemius_plan_id ?? null
91
+ });
92
+ }
93
+ return {
94
+ lines: h,
95
+ currencies: s,
96
+ selectedCurrency: r
97
+ };
98
+ }
99
+ async function R(e, o) {
100
+ const { data: c, error: s } = await e.from("coupon_products").select("product_id").eq("coupon_id", o);
101
+ if (s)
102
+ throw new Error(s.message);
103
+ return new Set((c || []).map((r) => r.product_id));
104
+ }
105
+ function z(e, o) {
106
+ const c = e.reduce((i, p) => i + p.subtotal, 0), s = Math.min(o, c);
107
+ if (c <= 0 || s <= 0)
108
+ return /* @__PURE__ */ new Map();
109
+ const r = /* @__PURE__ */ new Map();
110
+ let d = 0;
111
+ return e.forEach((i, p) => {
112
+ const a = p === e.length - 1 ? s - d : Math.min(
113
+ i.subtotal,
114
+ Math.floor(s * i.subtotal / c)
115
+ );
116
+ d += a, r.set(i.key, a);
117
+ }), r;
118
+ }
119
+ async function F(e) {
120
+ const o = A(e.code);
121
+ if (!o)
122
+ return {
123
+ success: !1,
124
+ error: "Enter a coupon code.",
125
+ errorKey: "ecommerce.coupon_code_required"
126
+ };
127
+ if (!e.items.length)
128
+ return {
129
+ success: !1,
130
+ error: "Add an item to your cart before applying a coupon.",
131
+ errorKey: "ecommerce.coupon_cart_empty"
132
+ };
133
+ const { data: c, error: s } = await e.client.from("coupons").select(
134
+ "id, code, name, provider_scope, discount_type, discount_amount, is_active, starts_at, ends_at, redemption_limit, redemptions_count"
135
+ ).ilike("code", o).maybeSingle();
136
+ if (s)
137
+ throw new Error(s.message);
138
+ if (!c)
139
+ return {
140
+ success: !1,
141
+ error: "Coupon code not found.",
142
+ errorKey: "ecommerce.coupon_not_found"
143
+ };
144
+ const r = c, d = /* @__PURE__ */ new Date(), i = M(r.starts_at), p = M(r.ends_at);
145
+ if (!r.is_active)
146
+ return {
147
+ success: !1,
148
+ error: "This coupon is not active.",
149
+ errorKey: "ecommerce.coupon_inactive"
150
+ };
151
+ if (i && i > d)
152
+ return {
153
+ success: !1,
154
+ error: "This coupon is not active yet.",
155
+ errorKey: "ecommerce.coupon_not_started"
156
+ };
157
+ if (p && p <= d)
158
+ return {
159
+ success: !1,
160
+ error: "This coupon has expired.",
161
+ errorKey: "ecommerce.coupon_expired"
162
+ };
163
+ if (r.redemption_limit !== null && (r.redemptions_count ?? 0) >= r.redemption_limit)
164
+ return {
165
+ success: !1,
166
+ error: "This coupon has reached its redemption limit.",
167
+ errorKey: "ecommerce.coupon_limit_reached"
168
+ };
169
+ const [{ lines: f }, a] = await Promise.all([
170
+ L({
171
+ client: e.client,
172
+ items: e.items,
173
+ currencyCode: e.currencyCode
174
+ }),
175
+ R(e.client, r.id)
176
+ ]), g = a.size > 0, _ = f.filter(
177
+ (t) => t.subtotal > 0 && k(r.provider_scope, t.provider) && (!g || a.has(t.product_id))
178
+ );
179
+ if (_.length === 0)
180
+ return {
181
+ success: !1,
182
+ error: "This coupon does not apply to the items in your cart.",
183
+ errorKey: "ecommerce.coupon_not_applicable"
184
+ };
185
+ const v = r.discount_type === "fixed" ? z(_, r.discount_amount) : null, m = T(), h = _.map((t) => {
186
+ const l = r.discount_type === "percent" ? Math.min(t.subtotal, Math.round(t.subtotal * r.discount_amount / 100)) : v?.get(t.key) ?? 0;
187
+ return m[t.provider] += l, {
188
+ key: t.key,
189
+ product_id: t.product_id,
190
+ variant_id: t.variant_id,
191
+ provider: t.provider,
192
+ title: t.title,
193
+ quantity: t.quantity,
194
+ subtotal: t.subtotal,
195
+ discount: l
196
+ };
197
+ });
198
+ return {
199
+ success: !0,
200
+ quote: {
201
+ couponId: r.id,
202
+ code: r.code,
203
+ name: r.name,
204
+ discountType: r.discount_type,
205
+ discountAmount: r.discount_amount,
206
+ providerScope: r.provider_scope,
207
+ eligibleSubtotal: _.reduce((t, l) => t + l.subtotal, 0),
208
+ discountTotal: m.stripe + m.freemius,
209
+ providerDiscounts: m,
210
+ lineDiscounts: h
211
+ }
212
+ };
213
+ }
214
+ function B(e) {
215
+ const o = /* @__PURE__ */ new Map();
216
+ for (const c of e?.lineDiscounts ?? [])
217
+ o.set(c.key, c.discount);
218
+ return o;
219
+ }
220
+ async function Q(e) {
221
+ const { error: o } = await e.client.from("coupon_redemptions").insert({
222
+ coupon_id: e.quote.couponId,
223
+ order_id: e.orderId,
224
+ coupon_code: e.quote.code,
225
+ provider: e.provider,
226
+ discount_total: Math.max(0, e.discountTotal),
227
+ user_id: e.userId || null,
228
+ customer_email: e.customerEmail || null,
229
+ metadata: e.metadata || {}
230
+ });
231
+ if (o) {
232
+ console.error("Failed to record coupon redemption:", o);
233
+ return;
234
+ }
235
+ const { data: c } = await e.client.from("coupons").select("redemptions_count").eq("id", e.quote.couponId).single();
236
+ await e.client.from("coupons").update({
237
+ redemptions_count: (c?.redemptions_count ?? 0) + 1,
238
+ updated_at: (/* @__PURE__ */ new Date()).toISOString()
239
+ }).eq("id", e.quote.couponId);
240
+ }
241
+ export {
242
+ F as a,
243
+ B as b,
244
+ T as e,
245
+ D as g,
246
+ A as n,
247
+ Q as r
248
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C="NEXTBLOCK_CURRENCY";exports.CURRENCY_COOKIE_NAME=C;
@@ -0,0 +1,4 @@
1
+ const C = "NEXTBLOCK_CURRENCY";
2
+ export {
3
+ C as CURRENCY_COOKIE_NAME
4
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("@nextblock-cms/utils"),A=["none","nearest","up","down","charm"],S={AU:"AUD",CA:"CAD",CH:"CHF",CZ:"CZK",DE:"EUR",DK:"DKK",ES:"EUR",EU:"EUR",FI:"EUR",FR:"EUR",GB:"GBP",IE:"EUR",IN:"INR",IT:"EUR",JP:"JPY",MX:"MXN",NL:"EUR",NO:"NOK",NZ:"NZD",PL:"PLN",PT:"EUR",SE:"SEK",SG:"SGD",US:"USD"};function g(r){return typeof r=="number"&&Number.isFinite(r)}function P(r,e=1){const n=typeof r=="string"?Number.parseInt(r,10):r;return typeof n=="number"&&Number.isFinite(n)&&n>0?Math.max(1,Math.round(n)):e}function U(r){const e=typeof r=="string"?Number.parseInt(r,10):r;return typeof e=="number"&&Number.isFinite(e)&&e>=0?Math.round(e):null}function b(r){if(typeof r=="string"){const e=r.trim().toLowerCase();if(A.includes(e))return e}return"none"}function s(r){const e=r||{},n=u.normalizeCurrencyCode(typeof e.code=="string"?e.code:null),o=e.is_default===!0;return{code:n,symbol:typeof e.symbol=="string"&&e.symbol.trim()?e.symbol.trim():n,exchange_rate:o?1:g(e.exchange_rate)&&e.exchange_rate>0?e.exchange_rate:1,is_default:o,is_active:e.is_active!==!1,auto_sync_product_prices:o?!1:e.auto_sync_product_prices===!0,rounding_mode:b(e.rounding_mode),rounding_increment:P(e.rounding_increment,1),rounding_charm_amount:U(e.rounding_charm_amount),auto_update_exchange_rate:o?!1:e.auto_update_exchange_rate!==!1,exchange_rate_source:typeof e.exchange_rate_source=="string"&&e.exchange_rate_source.trim()?e.exchange_rate_source.trim():null,exchange_rate_updated_at:typeof e.exchange_rate_updated_at=="string"&&e.exchange_rate_updated_at.trim()?e.exchange_rate_updated_at:null}}function C(r){return!r||typeof r!="object"||Array.isArray(r)?{}:Object.entries(r).reduce((e,[n,o])=>{const c=u.normalizeCurrencyCode(n),t=typeof o=="string"?Number.parseFloat(o):o;return g(t)&&t>=0&&(e[c]=Math.round(t)),e},{})}function M(r){return!r||typeof r!="object"||Array.isArray(r)?{}:Object.entries(r).reduce((e,[n,o])=>{const c=u.normalizeCurrencyCode(n),t=typeof o=="string"?Number.parseFloat(o):o;return t===null?(e[c]=null,e):(g(t)&&t>=0&&(e[c]=Math.round(t)),e)},{})}function f(r){return r.map(s).find(e=>e.is_default)??s(r[0])??s({code:"USD",symbol:"$",exchange_rate:1,is_default:!0,is_active:!0})}function _(r){return r.reduce((e,n)=>{const o=s(n);return e[o.code]=o,e},{})}function D(r,e){const n=u.normalizeCurrencyCode(e),o=f(r);return _(r)[n]?.exchange_rate??(n===o.code,1)}function y(r){const{amount:e,currencies:n}=r,o=u.normalizeCurrencyCode(r.fromCurrencyCode),c=u.normalizeCurrencyCode(r.toCurrencyCode);if(!Number.isFinite(e))return 0;if(o===c)return Math.round(e);const t=_(n),i=f(n),a=t[o]?.exchange_rate??(o===i.code?1:i.exchange_rate),d=t[c]?.exchange_rate??(c===i.code?1:i.exchange_rate),x=e/u.getCurrencyMinorUnitFactor(o)/a*d,h=u.majorUnitAmountToMinor(x,c);return r.applyRounding?R({amount:h,currencyCode:c,currencies:n}):h}function R(r){const e=Math.max(0,Math.round(r.amount)),n=u.normalizeCurrencyCode(r.currencyCode),c=_(r.currencies)[n]??s(f(r.currencies)),t=P(c.rounding_increment,1);if(c.rounding_mode==="nearest")return Math.round(e/t)*t;if(c.rounding_mode==="up")return Math.ceil(e/t)*t;if(c.rounding_mode==="down")return Math.floor(e/t)*t;if(c.rounding_mode==="charm"){const i=u.getCurrencyMinorUnitFactor(c.code),a=Math.min(Math.max(c.rounding_charm_amount??0,0),Math.max(i-1,0));let l=Math.floor(e/i)*i+a;return l<e&&(l+=i),l}return e}function k(r){const e=s(r);if(e.rounding_mode==="nearest")return`Nearest ${u.formatPrice(e.rounding_increment??1,e.code)}`;if(e.rounding_mode==="up")return`Round up to ${u.formatPrice(e.rounding_increment??1,e.code)}`;if(e.rounding_mode==="down")return`Round down to ${u.formatPrice(e.rounding_increment??1,e.code)}`;if(e.rounding_mode==="charm"){const n=e.rounding_charm_amount??0;return`Charm ending ${u.formatPrice(n,e.code)}`}return`Exact conversion (${u.minorUnitAmountToMajor(1,e.code).toFixed(u.getCurrencyMinorUnitFactor(e.code)===1?0:2)} step)`}function w(r,e){const n=f(e);return r[n.code]!==void 0?n.code:Object.keys(r)[0]??n.code}function p(r){const{amountMap:e,fallbackAmount:n,currencies:o}=r,c=u.normalizeCurrencyCode(r.currencyCode),t=C(e);if(t[c]!==void 0)return t[c];if(Object.keys(t).length>0){const i=w(t,o),a=t[i];if(a!==void 0)return y({amount:a,fromCurrencyCode:i,toCurrencyCode:c,currencies:o,applyRounding:!0})}if(typeof n=="number"&&Number.isFinite(n)){const i=f(o);return y({amount:n,fromCurrencyCode:i.code,toCurrencyCode:c,currencies:o,applyRounding:!0})}return 0}function z(r){const{prices:e={},salePrices:n={},fallbackPrice:o,fallbackSalePrice:c,currencies:t}=r,i=u.normalizeCurrencyCode(r.currencyCode),a=C(e),d=M(n),l=p({amountMap:a,fallbackAmount:o,currencyCode:i,currencies:t}),m=p({amountMap:C(d),fallbackAmount:c,currencyCode:i,currencies:t});return{currencyCode:i,price:l,sale_price:m>0&&m<=l?m:null}}function F(r){const e=(r.now??new Date).getTime();if(r.saleStartAt){const n=new Date(r.saleStartAt).getTime();if(Number.isFinite(n)&&e<n)return!1}if(r.saleEndAt){const n=new Date(r.saleEndAt).getTime();if(Number.isFinite(n)&&e>=n)return!1}return!0}function N(r){if(!r.scheduledPriceAt)return!1;const e=new Date(r.scheduledPriceAt).getTime();return Number.isFinite(e)?(r.now??new Date).getTime()>=e:!1}function E(r){const e=r.now??new Date,n=N({scheduledPriceAt:r.scheduledPriceAt,now:e}),o=n?r.scheduledPrices:r.prices,c=n?r.scheduledPrice:r.fallbackPrice,t=F({saleStartAt:r.saleStartAt,saleEndAt:r.saleEndAt,now:e});return z({prices:o,salePrices:t?r.salePrices:null,fallbackPrice:c,fallbackSalePrice:t?r.fallbackSalePrice:null,currencyCode:r.currencyCode,currencies:r.currencies})}function v(r){const e=r.entries.map(n=>E({prices:n.prices,salePrices:n.sale_prices,fallbackPrice:n.price,fallbackSalePrice:n.sale_price,saleStartAt:n.sale_start_at,saleEndAt:n.sale_end_at,scheduledPrice:n.scheduled_price,scheduledPrices:n.scheduled_prices,scheduledPriceAt:n.scheduled_price_at,currencyCode:r.currencyCode,currencies:r.currencies,now:r.now})).map(n=>n.sale_price??n.price).filter(n=>Number.isFinite(n));return e.length?{min:Math.min(...e),max:Math.max(...e)}:null}function j(r,e){const n=f(e),o=r?.trim();if(!o)return n.code;const t=o.replace("_","-").split("-").map(d=>d.toUpperCase())[1];if(!t)return n.code;const i=S[t];return i&&new Set(e.map(d=>u.normalizeCurrencyCode(d.code))).has(i)?i:n.code}function O(r){return r.map(s).sort((e,n)=>e.is_default!==n.is_default?e.is_default?-1:1:u.normalizeCurrencyCode(e.code).localeCompare(u.normalizeCurrencyCode(n.code)))}exports.CURRENCY_ROUNDING_MODES=A;exports.applyCurrencyRounding=R;exports.convertMinorUnitAmount=y;exports.describeCurrencyRoundingRule=k;exports.getCurrencyLookup=_;exports.getDefaultCurrency=f;exports.getExchangeRateForCurrency=D;exports.inferCurrencyCodeFromLocale=j;exports.isSaleWindowActive=F;exports.isScheduledPriceDue=N;exports.normalizeCurrencyRecord=s;exports.normalizeCurrencyRoundingMode=b;exports.normalizePriceMap=C;exports.normalizeSalePriceMap=M;exports.resolveEffectivePriceForCurrency=E;exports.resolvePriceForCurrency=z;exports.resolvePriceRangeForCurrency=v;exports.sortCurrencies=O;