@nextblock-cms/ecom 0.12.12 → 0.12.13

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.
@@ -201,7 +201,7 @@ function Be({
201
201
  ] });
202
202
  }
203
203
  const Wt = ({ initialCustomer: c }) => {
204
- const [x, P] = _({}), [l, f] = _(null), [h, I] = _({}), [E, W] = _(c?.email || ""), [q, K] = _(""), [a, U] = _(c?.phone || ""), [de, Z] = _(!1), [Ke, we] = _(null), [Se, ee] = _(!1), [Ue, te] = _(!1), [J, re] = _([]), [b, B] = _(null), [C, ce] = _(null), [D, Je] = _(null), [A, Ce] = _(
204
+ const [x, P] = _({}), [l, f] = _(null), [h, I] = _({}), [E, W] = _(c?.email || ""), [q, K] = _(""), [a, U] = _(c?.phone || ""), [de, Z] = _(!1), [Ke, we] = _(null), [Se, ee] = _(!1), [Ue, te] = _(!1), [J, re] = _([]), [b, B] = _(null), [S, ce] = _(null), [D, Je] = _(null), [A, Ce] = _(
205
205
  () => ae(c?.billingAddress, c?.fullName)
206
206
  ), [O, Fe] = _(
207
207
  () => ae(
@@ -213,7 +213,7 @@ const Wt = ({ initialCustomer: c }) => {
213
213
  ), G = dt((t) => t), { t: s, lang: me } = qe(), { activeCurrencyCode: o, currencies: M } = wt(), N = G?.items ?? [], k = $(
214
214
  () => N.filter((t) => !xe(t)),
215
215
  [N]
216
- ), w = $(
216
+ ), C = $(
217
217
  () => N.filter((t) => xe(t)),
218
218
  [N]
219
219
  ), R = c?.isAuthenticated ?? !1, n = (t, i, u) => {
@@ -229,27 +229,27 @@ const Wt = ({ initialCustomer: c }) => {
229
229
  String(d)
230
230
  );
231
231
  }), g;
232
- }, S = k.length > 0, Ge = $(
232
+ }, w = k.length > 0, Ge = $(
233
233
  () => be(N, o, M),
234
234
  [o, M, N]
235
235
  ), ue = $(
236
236
  () => be(k, o, M),
237
237
  [o, M, k]
238
238
  ), pe = $(
239
- () => be(w, o, M),
240
- [o, M, w]
239
+ () => be(C, o, M),
240
+ [o, M, C]
241
241
  ), he = D?.providerDiscounts.stripe ?? 0, fe = D?.providerDiscounts.freemius ?? 0, ne = Math.max(0, ue - he), He = Math.max(0, pe - fe), F = $(
242
242
  () => L ? A : O,
243
243
  [A, O, L]
244
244
  ), z = $(
245
- () => S ? F : A,
246
- [A, S, F]
247
- ), se = !S || Ft(F), le = $(
245
+ () => w ? F : A,
246
+ [A, w, F]
247
+ ), se = !w || Ft(F), le = $(
248
248
  () => J.find((t) => t.id === b),
249
249
  [J, b]
250
250
  ), Te = $(
251
- () => ne + (le?.amount ?? 0) + (C && !C.isPendingExternalCalculation ? C.amount : 0),
252
- [ne, le, C]
251
+ () => ne + (le?.amount ?? 0) + (S && !S.isPendingExternalCalculation ? S.amount : 0),
252
+ [ne, le, S]
253
253
  ), Qe = Te + He;
254
254
  if (ie(() => {
255
255
  if (!(R || typeof window > "u"))
@@ -289,7 +289,7 @@ const Wt = ({ initialCustomer: c }) => {
289
289
  O,
290
290
  L
291
291
  ]), ie(() => {
292
- if (!S) {
292
+ if (!w) {
293
293
  re([]), B(null), ee(!1);
294
294
  return;
295
295
  }
@@ -319,7 +319,7 @@ const Wt = ({ initialCustomer: c }) => {
319
319
  };
320
320
  }, [
321
321
  o,
322
- S,
322
+ w,
323
323
  se,
324
324
  me,
325
325
  b,
@@ -329,7 +329,7 @@ const Wt = ({ initialCustomer: c }) => {
329
329
  ne
330
330
  ]), ie(() => {
331
331
  const i = setTimeout(async () => {
332
- if (!S || !z.country_code) {
332
+ if (!w || !z.country_code) {
333
333
  te(!1), ce(null);
334
334
  return;
335
335
  }
@@ -353,7 +353,7 @@ const Wt = ({ initialCustomer: c }) => {
353
353
  return () => clearTimeout(i);
354
354
  }, [
355
355
  o,
356
- S,
356
+ w,
357
357
  k,
358
358
  z.country_code,
359
359
  z.state,
@@ -415,7 +415,7 @@ const Wt = ({ initialCustomer: c }) => {
415
415
  const i = ve(A);
416
416
  if (!Le(i))
417
417
  return alert(s("checkout_complete_billing_address")), null;
418
- const u = S ? ve(L ? A : O) : null;
418
+ const u = w ? ve(L ? A : O) : null;
419
419
  if (t === "stripe") {
420
420
  if (!Le(u))
421
421
  return alert(s("checkout_complete_shipping_address")), null;
@@ -545,7 +545,7 @@ const Wt = ({ initialCustomer: c }) => {
545
545
  /* @__PURE__ */ e(_e, { asChild: !0, children: /* @__PURE__ */ e("a", { href: "/shop", children: s("ecommerce.go_to_shop") }) })
546
546
  ] })
547
547
  ] });
548
- const ge = S ? se ? Se ? n(
548
+ const ge = w ? se ? Se ? n(
549
549
  "ecommerce.calculating_shipping",
550
550
  "Calculating shipping..."
551
551
  ) : b ? null : J.length > 0 ? s("ecommerce.select_rate") : s("ecommerce.no_rates_for_region") : n(
@@ -555,10 +555,10 @@ const Wt = ({ initialCustomer: c }) => {
555
555
  count: k.length
556
556
  }) : n("ecommerce.item_count_other", "{count} items", {
557
557
  count: k.length
558
- }), We = w.length === 1 ? n("ecommerce.license_count_one", "{count} license", {
559
- count: w.length
558
+ }), We = C.length === 1 ? n("ecommerce.license_count_one", "{count} license", {
559
+ count: C.length
560
560
  }) : n("ecommerce.license_count_other", "{count} licenses", {
561
- count: w.length
561
+ count: C.length
562
562
  }), Ze = (t) => xe(t) ? n("ecommerce.digital_label", "Digital") : n("ecommerce.physical_label", "Physical"), et = (t) => t === "monthly" ? n(
563
563
  "ecommerce.checkout_billing_cycle_monthly",
564
564
  "Monthly subscription"
@@ -626,7 +626,7 @@ const Wt = ({ initialCustomer: c }) => {
626
626
  onChange: Ce
627
627
  }
628
628
  ),
629
- S ? /* @__PURE__ */ r("div", { className: "flex items-center space-x-3 rounded-xl border bg-muted/20 p-4", children: [
629
+ w ? /* @__PURE__ */ r("div", { className: "flex items-center space-x-3 rounded-xl border bg-muted/20 p-4", children: [
630
630
  /* @__PURE__ */ e(
631
631
  lt,
632
632
  {
@@ -640,7 +640,7 @@ const Wt = ({ initialCustomer: c }) => {
640
640
  /* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground", children: s("checkout_use_billing_for_shipping_help") })
641
641
  ] })
642
642
  ] }) : null,
643
- S && !L ? /* @__PURE__ */ e(
643
+ w && !L ? /* @__PURE__ */ e(
644
644
  ze,
645
645
  {
646
646
  idPrefix: "shipping",
@@ -650,7 +650,7 @@ const Wt = ({ initialCustomer: c }) => {
650
650
  onChange: Fe
651
651
  }
652
652
  ) : null,
653
- S ? /* @__PURE__ */ r(Q, { children: [
653
+ w ? /* @__PURE__ */ r(Q, { children: [
654
654
  /* @__PURE__ */ e(X, { children: /* @__PURE__ */ r(Y, { className: "flex items-center gap-2", children: [
655
655
  /* @__PURE__ */ e(ht, { className: "w-5 h-5 text-primary" }),
656
656
  s("ecommerce.shipping_method")
@@ -741,7 +741,7 @@ const Wt = ({ initialCustomer: c }) => {
741
741
  ) }),
742
742
  /* @__PURE__ */ e("span", { children: y(ue, o) })
743
743
  ] }) : null,
744
- w.length > 0 ? /* @__PURE__ */ r("div", { className: "flex justify-between text-muted-foreground", children: [
744
+ C.length > 0 ? /* @__PURE__ */ r("div", { className: "flex justify-between text-muted-foreground", children: [
745
745
  /* @__PURE__ */ e("span", { children: n(
746
746
  "ecommerce.digital_products",
747
747
  "Digital products"
@@ -760,7 +760,7 @@ const Wt = ({ initialCustomer: c }) => {
760
760
  y(D.discountTotal, o)
761
761
  ] })
762
762
  ] }) : null,
763
- (k.length > 0 || w.length > 0) && /* @__PURE__ */ r("div", { className: "flex justify-between font-bold text-lg pt-2 border-t mt-2", children: [
763
+ (k.length > 0 || C.length > 0) && /* @__PURE__ */ r("div", { className: "flex justify-between font-bold text-lg pt-2 border-t mt-2", children: [
764
764
  /* @__PURE__ */ e("span", { children: n(
765
765
  "ecommerce.estimated_total",
766
766
  "Estimated total"
@@ -804,12 +804,12 @@ const Wt = ({ initialCustomer: c }) => {
804
804
  ] }),
805
805
  /* @__PURE__ */ r("div", { className: "flex justify-between", children: [
806
806
  /* @__PURE__ */ e("span", { children: n("ecommerce.tax", "Tax") }),
807
- /* @__PURE__ */ e("span", { children: Ue ? "..." : C?.isPendingExternalCalculation ? n(
807
+ /* @__PURE__ */ e("span", { children: Ue ? "..." : S?.isPendingExternalCalculation ? n(
808
808
  "ecommerce.tax_calculated_on_stripe",
809
809
  "Calculated on Stripe"
810
- ) : C ? y(C.amount, o) : "-" })
810
+ ) : S ? y(S.amount, o) : "-" })
811
811
  ] }),
812
- C && C.lines.length > 0 ? /* @__PURE__ */ e("div", { className: "rounded-lg bg-muted/20 px-3 py-2 text-xs text-muted-foreground", children: C.lines.map((t) => /* @__PURE__ */ r("div", { className: "flex justify-between gap-3", children: [
812
+ S && S.lines.length > 0 ? /* @__PURE__ */ e("div", { className: "rounded-lg bg-muted/20 px-3 py-2 text-xs text-muted-foreground", children: S.lines.map((t) => /* @__PURE__ */ r("div", { className: "flex justify-between gap-3", children: [
813
813
  /* @__PURE__ */ r("span", { children: [
814
814
  t.name,
815
815
  " (",
@@ -844,7 +844,7 @@ const Wt = ({ initialCustomer: c }) => {
844
844
  ),
845
845
  ge && l === null ? /* @__PURE__ */ e("p", { className: "text-[11px] text-muted-foreground", children: ge }) : null,
846
846
  h.stripe ? /* @__PURE__ */ e("div", { className: "rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 text-xs text-destructive", children: h.stripe }) : null,
847
- /* @__PURE__ */ e("p", { className: "text-[11px] text-muted-foreground", children: C?.isPendingExternalCalculation ? n(
847
+ /* @__PURE__ */ e("p", { className: "text-[11px] text-muted-foreground", children: S?.isPendingExternalCalculation ? n(
848
848
  "checkout_stripe_tax_finalized_notice",
849
849
  "Tax will be finalized by Stripe Tax on the payment step."
850
850
  ) : n(
@@ -854,7 +854,7 @@ const Wt = ({ initialCustomer: c }) => {
854
854
  ]
855
855
  }
856
856
  ) : null,
857
- w.length > 0 ? /* @__PURE__ */ r(
857
+ C.length > 0 ? /* @__PURE__ */ r(
858
858
  Be,
859
859
  {
860
860
  title: n(
@@ -867,7 +867,7 @@ const Wt = ({ initialCustomer: c }) => {
867
867
  ),
868
868
  badgeLabel: We,
869
869
  children: [
870
- /* @__PURE__ */ e("div", { className: "space-y-3", children: w.map((t) => {
870
+ /* @__PURE__ */ e("div", { className: "space-y-3", children: C.map((t) => {
871
871
  const i = Ne(t, {
872
872
  currencyCode: o,
873
873
  currencies: M
@@ -925,7 +925,6 @@ const Wt = ({ initialCustomer: c }) => {
925
925
  _e,
926
926
  {
927
927
  className: "w-full h-auto min-h-[2.75rem] py-2",
928
- variant: w.length > 1 ? "outline" : "default",
929
928
  onClick: () => Pe(
930
929
  "freemius",
931
930
  [
@@ -939,7 +938,7 @@ const Wt = ({ initialCustomer: c }) => {
939
938
  disabled: l !== null,
940
939
  children: [
941
940
  l === m ? /* @__PURE__ */ e(ye, { className: "mr-2 h-4 w-4 shrink-0 animate-spin" }) : /* @__PURE__ */ e(gt, { className: "mr-2 h-4 w-4 shrink-0" }),
942
- /* @__PURE__ */ e("span", { className: "whitespace-normal text-left", children: l === m ? s("ecommerce.processing") : w.length > 1 ? n(
941
+ /* @__PURE__ */ e("span", { className: "whitespace-normal text-left", children: l === m ? s("ecommerce.processing") : C.length > 1 ? n(
943
942
  "ecommerce.checkout_product",
944
943
  "Checkout {title}",
945
944
  { title: t.title }
@@ -967,7 +966,7 @@ const Wt = ({ initialCustomer: c }) => {
967
966
  ] })
968
967
  ] }) : null,
969
968
  h.freemius ? /* @__PURE__ */ e("div", { className: "rounded-lg border border-destructive/20 bg-destructive/10 px-3 py-2 text-xs text-destructive", children: h.freemius }) : null,
970
- /* @__PURE__ */ e("p", { className: "text-[11px] text-muted-foreground", children: w.length > 1 ? n(
969
+ /* @__PURE__ */ e("p", { className: "text-[11px] text-muted-foreground", children: C.length > 1 ? n(
971
970
  "ecommerce.freemius_multi_checkout_notice",
972
971
  "Freemius licenses are completed one at a time, so each digital product gets its own checkout action."
973
972
  ) : n(
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),u=require("react"),r=require("lucide-react"),x=require("@nextblock-cms/ui/button"),p=require("@nextblock-cms/utils"),a=require("../invoice-ui.cjs.js"),f=require("../invoice.cjs.js");function y({license:s}){const{t,lang:o}=p.useTranslations(),[l,n]=u.useState(!1);if(!s)return null;const m=a.getInvoiceLocale(o),c=s.expiration??s.trialEndsAt,i=c?f.formatInvoiceDate(c,m):null,d=async()=>{if(!(!s.licenseKey||typeof navigator>"u"||!navigator.clipboard))try{await navigator.clipboard.writeText(s.licenseKey),n(!0),window.setTimeout(()=>n(!1),2e3)}catch{}};return e.jsxs("div",{className:"mb-6 rounded-2xl border border-primary/30 bg-primary/5 p-5 print:hidden",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(r.KeyRound,{className:"h-5 w-5 text-primary"}),e.jsx("h2",{className:"text-lg font-semibold",children:a.translateOrFallback(t,"ecommerce.license_panel_title","Your license")})]}),s.licenseKey?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:a.translateOrFallback(t,"ecommerce.license_panel_help","Activate this key in your NextBlock install under Settings → Packages.")}),e.jsxs("div",{className:"mt-3 flex flex-col gap-2 sm:flex-row sm:items-center",children:[e.jsx("code",{className:"flex-1 overflow-x-auto rounded-lg border bg-background px-3 py-2 font-mono text-sm",children:s.licenseKey}),e.jsxs(x.Button,{type:"button",variant:"default",onClick:d,className:"shrink-0",children:[l?e.jsx(r.Check,{className:"mr-2 h-4 w-4"}):e.jsx(r.Copy,{className:"mr-2 h-4 w-4"}),l?a.translateOrFallback(t,"ecommerce.license_copied","Copied"):a.translateOrFallback(t,"ecommerce.license_copy","Copy key")]})]})]}):e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:a.translateOrFallback(t,"ecommerce.license_panel_email_fallback","Your license key was sent to your email. It will also appear here once your purchase is confirmed.")}),e.jsxs("dl",{className:"mt-4 grid gap-x-6 gap-y-1 text-xs text-muted-foreground sm:grid-cols-2",children:[e.jsxs("div",{className:"flex justify-between gap-3 sm:block",children:[e.jsx("dt",{className:"font-medium",children:a.translateOrFallback(t,"ecommerce.license_number","License #")}),e.jsx("dd",{className:"font-mono",children:s.licenseId})]}),i?e.jsxs("div",{className:"flex justify-between gap-3 sm:block",children:[e.jsx("dt",{className:"font-medium",children:s.isCancelled?a.translateOrFallback(t,"ecommerce.license_expires","Expires"):s.trialEndsAt?a.translateOrFallback(t,"ecommerce.license_trial_ends","Trial ends"):a.translateOrFallback(t,"ecommerce.license_renews","Renews / expires")}),e.jsx("dd",{children:i})]}):null]})]})}exports.FreemiusLicensePanel=y;
@@ -0,0 +1,6 @@
1
+ import { FreemiusOrderLicense } from '../freemius-license-types';
2
+ interface FreemiusLicensePanelProps {
3
+ license?: FreemiusOrderLicense | null;
4
+ }
5
+ export declare function FreemiusLicensePanel({ license }: FreemiusLicensePanelProps): import("react").JSX.Element | null;
6
+ export {};
@@ -0,0 +1,66 @@
1
+ 'use client';
2
+ import { jsxs as l, jsx as e, Fragment as p } from "react/jsx-runtime";
3
+ import { useState as u } from "react";
4
+ import { KeyRound as f, Check as x, Copy as h } from "lucide-react";
5
+ import { Button as y } from "@nextblock-cms/ui/button";
6
+ import { useTranslations as g } from "@nextblock-cms/utils";
7
+ import { translateOrFallback as a, getInvoiceLocale as b } from "../invoice-ui.es.js";
8
+ import { formatInvoiceDate as N } from "../invoice.es.js";
9
+ function E({ license: r }) {
10
+ const { t, lang: s } = g(), [o, n] = u(!1);
11
+ if (!r)
12
+ return null;
13
+ const m = b(s), c = r.expiration ?? r.trialEndsAt, i = c ? N(c, m) : null, d = async () => {
14
+ if (!(!r.licenseKey || typeof navigator > "u" || !navigator.clipboard))
15
+ try {
16
+ await navigator.clipboard.writeText(r.licenseKey), n(!0), window.setTimeout(() => n(!1), 2e3);
17
+ } catch {
18
+ }
19
+ };
20
+ return /* @__PURE__ */ l("div", { className: "mb-6 rounded-2xl border border-primary/30 bg-primary/5 p-5 print:hidden", children: [
21
+ /* @__PURE__ */ l("div", { className: "flex items-center gap-2", children: [
22
+ /* @__PURE__ */ e(f, { className: "h-5 w-5 text-primary" }),
23
+ /* @__PURE__ */ e("h2", { className: "text-lg font-semibold", children: a(t, "ecommerce.license_panel_title", "Your license") })
24
+ ] }),
25
+ r.licenseKey ? /* @__PURE__ */ l(p, { children: [
26
+ /* @__PURE__ */ e("p", { className: "mt-1 text-sm text-muted-foreground", children: a(
27
+ t,
28
+ "ecommerce.license_panel_help",
29
+ "Activate this key in your NextBlock install under Settings → Packages."
30
+ ) }),
31
+ /* @__PURE__ */ l("div", { className: "mt-3 flex flex-col gap-2 sm:flex-row sm:items-center", children: [
32
+ /* @__PURE__ */ e("code", { className: "flex-1 overflow-x-auto rounded-lg border bg-background px-3 py-2 font-mono text-sm", children: r.licenseKey }),
33
+ /* @__PURE__ */ l(
34
+ y,
35
+ {
36
+ type: "button",
37
+ variant: "default",
38
+ onClick: d,
39
+ className: "shrink-0",
40
+ children: [
41
+ o ? /* @__PURE__ */ e(x, { className: "mr-2 h-4 w-4" }) : /* @__PURE__ */ e(h, { className: "mr-2 h-4 w-4" }),
42
+ o ? a(t, "ecommerce.license_copied", "Copied") : a(t, "ecommerce.license_copy", "Copy key")
43
+ ]
44
+ }
45
+ )
46
+ ] })
47
+ ] }) : /* @__PURE__ */ e("p", { className: "mt-1 text-sm text-muted-foreground", children: a(
48
+ t,
49
+ "ecommerce.license_panel_email_fallback",
50
+ "Your license key was sent to your email. It will also appear here once your purchase is confirmed."
51
+ ) }),
52
+ /* @__PURE__ */ l("dl", { className: "mt-4 grid gap-x-6 gap-y-1 text-xs text-muted-foreground sm:grid-cols-2", children: [
53
+ /* @__PURE__ */ l("div", { className: "flex justify-between gap-3 sm:block", children: [
54
+ /* @__PURE__ */ e("dt", { className: "font-medium", children: a(t, "ecommerce.license_number", "License #") }),
55
+ /* @__PURE__ */ e("dd", { className: "font-mono", children: r.licenseId })
56
+ ] }),
57
+ i ? /* @__PURE__ */ l("div", { className: "flex justify-between gap-3 sm:block", children: [
58
+ /* @__PURE__ */ e("dt", { className: "font-medium", children: r.isCancelled ? a(t, "ecommerce.license_expires", "Expires") : r.trialEndsAt ? a(t, "ecommerce.license_trial_ends", "Trial ends") : a(t, "ecommerce.license_renews", "Renews / expires") }),
59
+ /* @__PURE__ */ e("dd", { children: i })
60
+ ] }) : null
61
+ ] })
62
+ ] });
63
+ }
64
+ export {
65
+ E as FreemiusLicensePanel
66
+ };
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),b=require("next/link"),j=require("lucide-react"),s=require("@nextblock-cms/ui/button"),v=require("./InvoiceDocument.cjs.js");function f({invoice:i,labels:a,locale:o,title:c,description:r,printLabel:x,headerVisual:d,action:t,loading:l=!1,loadingMessage:m,error:n,emptyMessage:u,className:p="",showHeader:h=!0}){return e.jsxs(e.Fragment,{children:[e.jsx("style",{children:`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),j=require("next/link"),v=require("lucide-react"),s=require("@nextblock-cms/ui/button"),f=require("./InvoiceDocument.cjs.js");function g({invoice:i,labels:a,locale:o,title:c,description:r,printLabel:x,headerVisual:d,action:t,loading:l=!1,loadingMessage:m,error:n,emptyMessage:u,className:p="",showHeader:h=!0,beforeInvoice:b}){return e.jsxs(e.Fragment,{children:[e.jsx("style",{children:`
2
2
  @media print {
3
3
  @page {
4
4
  size: portrait;
@@ -26,4 +26,4 @@
26
26
  padding: 0;
27
27
  }
28
28
  }
29
- `}),e.jsxs("div",{className:`mx-auto max-w-6xl px-4 py-10 md:px-6 print:max-w-none print:px-0 print:py-0 ${p}`,children:[h?e.jsxs("div",{className:"mb-6 flex flex-col gap-4 md:flex-row md:items-center md:justify-between print:hidden",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[d?e.jsx("div",{className:"shrink-0",children:d}):null,e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold",children:c}),r?e.jsx("p",{className:"text-sm text-muted-foreground",children:r}):null]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs(s.Button,{type:"button",variant:"outline",onClick:()=>window.print(),disabled:!i,children:[e.jsx(j.Printer,{className:"mr-2 h-4 w-4"}),x]}),t?e.jsx(s.Button,{asChild:!0,variant:t.variant||"default",children:e.jsx(b,{href:t.href,children:t.label})}):null]})]}):null,l?e.jsx("div",{className:"mb-6 flex items-center justify-center gap-3 rounded-2xl border bg-background px-5 py-4 text-sm text-muted-foreground print:hidden",children:m}):null,n?e.jsx("div",{className:"mb-6 rounded-2xl border border-amber-200 bg-amber-50 px-5 py-4 text-sm text-amber-700 print:hidden",children:n}):null,i?e.jsx("div",{"data-print-invoice-root":!0,children:e.jsx(v.InvoiceDocument,{data:i,labels:a,locale:o})}):!l&&!n?e.jsx("div",{className:"rounded-2xl border bg-background px-6 py-12 text-center text-muted-foreground print:hidden",children:u}):null]})]})}exports.InvoiceViewerShell=f;
29
+ `}),e.jsxs("div",{className:`mx-auto max-w-6xl px-4 py-10 md:px-6 print:max-w-none print:px-0 print:py-0 ${p}`,children:[h?e.jsxs("div",{className:"mb-6 flex flex-col gap-4 md:flex-row md:items-center md:justify-between print:hidden",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[d?e.jsx("div",{className:"shrink-0",children:d}):null,e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold",children:c}),r?e.jsx("p",{className:"text-sm text-muted-foreground",children:r}):null]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs(s.Button,{type:"button",variant:"outline",onClick:()=>window.print(),disabled:!i,children:[e.jsx(v.Printer,{className:"mr-2 h-4 w-4"}),x]}),t?e.jsx(s.Button,{asChild:!0,variant:t.variant||"default",children:e.jsx(j,{href:t.href,children:t.label})}):null]})]}):null,l?e.jsx("div",{className:"mb-6 flex items-center justify-center gap-3 rounded-2xl border bg-background px-5 py-4 text-sm text-muted-foreground print:hidden",children:m}):null,n?e.jsx("div",{className:"mb-6 rounded-2xl border border-amber-200 bg-amber-50 px-5 py-4 text-sm text-amber-700 print:hidden",children:n}):null,b,i?e.jsx("div",{"data-print-invoice-root":!0,children:e.jsx(f.InvoiceDocument,{data:i,labels:a,locale:o})}):!l&&!n?e.jsx("div",{className:"rounded-2xl border bg-background px-6 py-12 text-center text-muted-foreground print:hidden",children:u}):null]})]})}exports.InvoiceViewerShell=g;
@@ -21,6 +21,8 @@ interface InvoiceViewerShellProps {
21
21
  emptyMessage?: string;
22
22
  className?: string;
23
23
  showHeader?: boolean;
24
+ /** Optional content rendered above the invoice (and hidden when printing). */
25
+ beforeInvoice?: ReactNode;
24
26
  }
25
- export declare function InvoiceViewerShell({ invoice, labels, locale, title, description, printLabel, headerVisual, action, loading, loadingMessage, error, emptyMessage, className, showHeader, }: InvoiceViewerShellProps): import("react").JSX.Element;
27
+ export declare function InvoiceViewerShell({ invoice, labels, locale, title, description, printLabel, headerVisual, action, loading, loadingMessage, error, emptyMessage, className, showHeader, beforeInvoice, }: InvoiceViewerShellProps): import("react").JSX.Element;
26
28
  export {};
@@ -1,10 +1,10 @@
1
1
  'use client';
2
- import { jsxs as i, Fragment as f, jsx as e } from "react/jsx-runtime";
3
- import v from "next/link";
4
- import { Printer as g } from "lucide-react";
2
+ import { jsxs as i, Fragment as v, jsx as e } from "react/jsx-runtime";
3
+ import g from "next/link";
4
+ import { Printer as y } from "lucide-react";
5
5
  import { Button as m } from "@nextblock-cms/ui/button";
6
- import { InvoiceDocument as y } from "./InvoiceDocument.es.js";
7
- function I({
6
+ import { InvoiceDocument as w } from "./InvoiceDocument.es.js";
7
+ function z({
8
8
  invoice: r,
9
9
  labels: o,
10
10
  locale: s,
@@ -18,9 +18,10 @@ function I({
18
18
  error: n,
19
19
  emptyMessage: u,
20
20
  className: h = "",
21
- showHeader: b = !0
21
+ showHeader: b = !0,
22
+ beforeInvoice: f
22
23
  }) {
23
- return /* @__PURE__ */ i(f, { children: [
24
+ return /* @__PURE__ */ i(v, { children: [
24
25
  /* @__PURE__ */ e("style", { children: `
25
26
  @media print {
26
27
  @page {
@@ -72,18 +73,19 @@ function I({
72
73
  onClick: () => window.print(),
73
74
  disabled: !r,
74
75
  children: [
75
- /* @__PURE__ */ e(g, { className: "mr-2 h-4 w-4" }),
76
+ /* @__PURE__ */ e(y, { className: "mr-2 h-4 w-4" }),
76
77
  p
77
78
  ]
78
79
  }
79
80
  ),
80
- t ? /* @__PURE__ */ e(m, { asChild: !0, variant: t.variant || "default", children: /* @__PURE__ */ e(v, { href: t.href, children: t.label }) }) : null
81
+ t ? /* @__PURE__ */ e(m, { asChild: !0, variant: t.variant || "default", children: /* @__PURE__ */ e(g, { href: t.href, children: t.label }) }) : null
81
82
  ] })
82
83
  ] }) : null,
83
84
  a ? /* @__PURE__ */ e("div", { className: "mb-6 flex items-center justify-center gap-3 rounded-2xl border bg-background px-5 py-4 text-sm text-muted-foreground print:hidden", children: x }) : null,
84
85
  n ? /* @__PURE__ */ e("div", { className: "mb-6 rounded-2xl border border-amber-200 bg-amber-50 px-5 py-4 text-sm text-amber-700 print:hidden", children: n }) : null,
86
+ f,
85
87
  r ? /* @__PURE__ */ e("div", { "data-print-invoice-root": !0, children: /* @__PURE__ */ e(
86
- y,
88
+ w,
87
89
  {
88
90
  data: r,
89
91
  labels: o,
@@ -96,5 +98,5 @@ function I({
96
98
  ] });
97
99
  }
98
100
  export {
99
- I as InvoiceViewerShell
101
+ z as InvoiceViewerShell
100
102
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@nextblock-cms/db/server"),d=require("./invoice-server.cjs.js");function o(e){return e??c.createClient()}async function i(e){const{data:{user:r},error:t}=await e.auth.getUser();if(t||!r)throw new Error("Unauthorized");return r}async function l(e){const r=o(e),t=await i(r),{data:n,error:a}=await r.from("orders").select("id, invoice_number, paid_at, created_at, currency, status, provider, subtotal, shipping_total, tax_total, total").eq("user_id",t.id).order("created_at",{ascending:!1});if(a)throw new Error(a.message);return n??[]}async function u(e,r){const t=o(r),n=await i(t),{data:a,error:s}=await t.from("orders").select("id, invoice_number, paid_at, created_at, currency, status, provider, subtotal, shipping_total, tax_total, total").eq("id",e).eq("user_id",n.id).maybeSingle();if(s)throw new Error(s.message);return a??null}async function g(e,r){const t=o(r),n=await u(e,t);if(!n)return null;const a=n.invoice_number?await d.getInvoicePresentationData(e,t):null;return{order:n,invoice:a}}exports.getCurrentCustomerOrder=u;exports.getCurrentCustomerOrderInvoice=g;exports.getCurrentCustomerOrders=l;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("@nextblock-cms/db/server"),l=require("./invoice-server.cjs.js"),g=require("./freemius-license.cjs.js"),o=["pending"];function i(e){return e??d.createClient()}async function u(e){const{data:{user:r},error:t}=await e.auth.getUser();if(t||!r)throw new Error("Unauthorized");return r}async function m(e){const r=i(e),t=await u(r),{data:n,error:s}=await r.from("orders").select("id, invoice_number, paid_at, created_at, currency, status, provider, subtotal, shipping_total, tax_total, total").eq("user_id",t.id).not("status","in",`(${o.join(",")})`).order("created_at",{ascending:!1});if(s)throw new Error(s.message);return n??[]}async function c(e,r){const t=i(r),n=await u(t),{data:s,error:a}=await t.from("orders").select("id, invoice_number, paid_at, created_at, currency, status, provider, subtotal, shipping_total, tax_total, total").eq("id",e).eq("user_id",n.id).not("status","in",`(${o.join(",")})`).maybeSingle();if(a)throw new Error(a.message);return s??null}async function _(e,r){const t=i(r),n=await c(e,t);if(!n)return null;const s=n.invoice_number?await l.getInvoicePresentationData(e,t):null,a=n.provider==="freemius"?await g.getFreemiusOrderLicense({orderId:e,client:t}):null;return{order:n,invoice:s,license:a}}exports.getCurrentCustomerOrder=c;exports.getCurrentCustomerOrderInvoice=_;exports.getCurrentCustomerOrders=m;
@@ -1,5 +1,6 @@
1
1
  import { SupabaseClient } from '@supabase/supabase-js';
2
2
  import { InvoicePresentationData } from './invoice';
3
+ import { FreemiusOrderLicense } from './freemius-license-types';
3
4
  type SupabaseLikeClient = SupabaseClient<any>;
4
5
  export interface CustomerOrderSummary {
5
6
  id: string;
@@ -19,5 +20,6 @@ export declare function getCurrentCustomerOrder(orderId: string, client?: Supaba
19
20
  export declare function getCurrentCustomerOrderInvoice(orderId: string, client?: SupabaseLikeClient): Promise<{
20
21
  order: CustomerOrderSummary;
21
22
  invoice: InvoicePresentationData | null;
23
+ license: FreemiusOrderLicense | null;
22
24
  } | null>;
23
25
  export {};
@@ -1,45 +1,48 @@
1
- import { createClient as u } from "@nextblock-cms/db/server";
2
- import { getInvoicePresentationData as c } from "./invoice-server.es.js";
1
+ import { createClient as c } from "@nextblock-cms/db/server";
2
+ import { getInvoicePresentationData as d } from "./invoice-server.es.js";
3
+ import { getFreemiusOrderLicense as l } from "./freemius-license.es.js";
4
+ const s = ["pending"];
3
5
  function o(t) {
4
- return t ?? u();
6
+ return t ?? c();
5
7
  }
6
- async function s(t) {
8
+ async function u(t) {
7
9
  const {
8
- data: { user: e },
9
- error: r
10
+ data: { user: r },
11
+ error: e
10
12
  } = await t.auth.getUser();
11
- if (r || !e)
13
+ if (e || !r)
12
14
  throw new Error("Unauthorized");
13
- return e;
15
+ return r;
14
16
  }
15
- async function p(t) {
16
- const e = o(t), r = await s(e), { data: a, error: n } = await e.from("orders").select(
17
+ async function g(t) {
18
+ const r = o(t), e = await u(r), { data: n, error: a } = await r.from("orders").select(
17
19
  "id, invoice_number, paid_at, created_at, currency, status, provider, subtotal, shipping_total, tax_total, total"
18
- ).eq("user_id", r.id).order("created_at", { ascending: !1 });
19
- if (n)
20
- throw new Error(n.message);
21
- return a ?? [];
20
+ ).eq("user_id", e.id).not("status", "in", `(${s.join(",")})`).order("created_at", { ascending: !1 });
21
+ if (a)
22
+ throw new Error(a.message);
23
+ return n ?? [];
22
24
  }
23
- async function d(t, e) {
24
- const r = o(e), a = await s(r), { data: n, error: i } = await r.from("orders").select(
25
+ async function m(t, r) {
26
+ const e = o(r), n = await u(e), { data: a, error: i } = await e.from("orders").select(
25
27
  "id, invoice_number, paid_at, created_at, currency, status, provider, subtotal, shipping_total, tax_total, total"
26
- ).eq("id", t).eq("user_id", a.id).maybeSingle();
28
+ ).eq("id", t).eq("user_id", n.id).not("status", "in", `(${s.join(",")})`).maybeSingle();
27
29
  if (i)
28
30
  throw new Error(i.message);
29
- return n ?? null;
31
+ return a ?? null;
30
32
  }
31
- async function f(t, e) {
32
- const r = o(e), a = await d(t, r);
33
- if (!a)
33
+ async function w(t, r) {
34
+ const e = o(r), n = await m(t, e);
35
+ if (!n)
34
36
  return null;
35
- const n = a.invoice_number ? await c(t, r) : null;
37
+ const a = n.invoice_number ? await d(t, e) : null, i = n.provider === "freemius" ? await l({ orderId: t, client: e }) : null;
36
38
  return {
37
- order: a,
38
- invoice: n
39
+ order: n,
40
+ invoice: a,
41
+ license: i
39
42
  };
40
43
  }
41
44
  export {
42
- d as getCurrentCustomerOrder,
43
- f as getCurrentCustomerOrderInvoice,
44
- p as getCurrentCustomerOrders
45
+ m as getCurrentCustomerOrder,
46
+ w as getCurrentCustomerOrderInvoice,
47
+ g as getCurrentCustomerOrders
45
48
  };
@@ -0,0 +1,19 @@
1
+ export interface FreemiusOrderLicense {
2
+ /** Freemius license id captured on the order (always present). */
3
+ licenseId: string;
4
+ /**
5
+ * The activatable license key (Freemius `secret_key`), fetched on demand and
6
+ * never stored locally. Null when it could not be resolved (e.g. the Freemius
7
+ * API was unreachable or no key has been issued yet) — surface the email
8
+ * fallback in that case.
9
+ */
10
+ licenseKey: string | null;
11
+ /** Freemius plan id the license belongs to, when known. */
12
+ planId: string | null;
13
+ /** License expiration (ISO) — for trials this is the trial end. */
14
+ expiration: string | null;
15
+ /** Trial end recorded on the order, if the order started as a trial. */
16
+ trialEndsAt: string | null;
17
+ /** Whether Freemius reports the license as cancelled. */
18
+ isCancelled: boolean;
19
+ }
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@freemius/sdk"),l=require("./payment-config.cjs.js"),u=require("./providers/freemius.cjs.js");async function c(n,e){if(!n)return null;const r=u.resolveFreemiusCheckoutCredentials(n);return!r.apiKey||!r.secretKey||!r.publicKey?null:new t.Freemius({productId:Number(n),apiKey:r.apiKey,secretKey:r.secretKey,publicKey:r.publicKey}).api.license.retrieve(e)}async function a(n){const{data:e,error:r}=await n.client.from("orders").select("id, provider, freemius_product_id, freemius_license_id, freemius_trial_ends_at").eq("id",n.orderId).maybeSingle();if(r||!e||e.provider!=="freemius"||!e.freemius_license_id)return null;let i=null;try{await l.hydrateFreemiusEnvFromDb(),i=await c(e.freemius_product_id,String(e.freemius_license_id))}catch(s){console.error("[Freemius License] Failed to retrieve license key:",s)}return{licenseId:String(e.freemius_license_id),licenseKey:i?.secret_key??null,planId:i?.plan_id!=null?String(i.plan_id):null,expiration:i?.expiration??null,trialEndsAt:e.freemius_trial_ends_at??null,isCancelled:!!i?.is_cancelled}}exports.getFreemiusOrderLicense=a;
@@ -0,0 +1,20 @@
1
+ import { SupabaseClient } from '@supabase/supabase-js';
2
+ import { FreemiusOrderLicense } from './freemius-license-types';
3
+ export type { FreemiusOrderLicense };
4
+ type SupabaseLikeClient = SupabaseClient<any>;
5
+ /**
6
+ * Fetches the activatable Freemius license key for an order on demand.
7
+ *
8
+ * The key is never persisted locally — it is retrieved straight from Freemius
9
+ * using the license id captured on the order at checkout time. Returns null for
10
+ * non-Freemius orders or orders that have no license yet.
11
+ *
12
+ * Authorization is the caller's responsibility: this only reads what the passed
13
+ * Supabase client can see, so pass an owner-scoped (RLS) client on customer
14
+ * surfaces and the service-role client only right after checkout, keyed by the
15
+ * order's own (unguessable) id.
16
+ */
17
+ export declare function getFreemiusOrderLicense(input: {
18
+ orderId: string;
19
+ client: SupabaseLikeClient;
20
+ }): Promise<FreemiusOrderLicense | null>;
@@ -0,0 +1,41 @@
1
+ import { Freemius as s } from "@freemius/sdk";
2
+ import { hydrateFreemiusEnvFromDb as t } from "./payment-config.es.js";
3
+ import { resolveFreemiusCheckoutCredentials as u } from "./providers/freemius.es.js";
4
+ async function c(n, e) {
5
+ if (!n)
6
+ return null;
7
+ const r = u(n);
8
+ return !r.apiKey || !r.secretKey || !r.publicKey ? null : new s({
9
+ productId: Number(n),
10
+ apiKey: r.apiKey,
11
+ secretKey: r.secretKey,
12
+ publicKey: r.publicKey
13
+ }).api.license.retrieve(e);
14
+ }
15
+ async function m(n) {
16
+ const { data: e, error: r } = await n.client.from("orders").select(
17
+ "id, provider, freemius_product_id, freemius_license_id, freemius_trial_ends_at"
18
+ ).eq("id", n.orderId).maybeSingle();
19
+ if (r || !e || e.provider !== "freemius" || !e.freemius_license_id)
20
+ return null;
21
+ let i = null;
22
+ try {
23
+ await t(), i = await c(
24
+ e.freemius_product_id,
25
+ String(e.freemius_license_id)
26
+ );
27
+ } catch (l) {
28
+ console.error("[Freemius License] Failed to retrieve license key:", l);
29
+ }
30
+ return {
31
+ licenseId: String(e.freemius_license_id),
32
+ licenseKey: i?.secret_key ?? null,
33
+ planId: i?.plan_id != null ? String(i.plan_id) : null,
34
+ expiration: i?.expiration ?? null,
35
+ trialEndsAt: e.freemius_trial_ends_at ?? null,
36
+ isCancelled: !!i?.is_cancelled
37
+ };
38
+ }
39
+ export {
40
+ m as getFreemiusOrderLicense
41
+ };