@nextblock-cms/ecom 0.18.8 → 0.19.2
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 +26 -25
- package/lib/CurrencyProvider.cjs.js +1 -1
- package/lib/CurrencyProvider.es.js +41 -45
- package/lib/PaymentReadinessProvider.cjs.js +1 -1
- package/lib/PaymentReadinessProvider.es.js +15 -19
- package/lib/cart-store.cjs.js +1 -1
- package/lib/cart-store.d.ts +4 -0
- package/lib/cart-store.es.js +77 -69
- package/lib/components/AccountNavigationMenu.cjs.js +1 -1
- package/lib/components/AccountNavigationMenu.es.js +44 -62
- package/lib/components/AddToCartButton.cjs.js +1 -1
- package/lib/components/AddToCartButton.es.js +50 -78
- package/lib/components/Cart.cjs.js +1 -1
- package/lib/components/Cart.es.js +154 -381
- package/lib/components/CartDrawer.cjs.js +1 -1
- package/lib/components/CartDrawer.es.js +143 -297
- package/lib/components/CartIcon.cjs.js +1 -1
- package/lib/components/CartIcon.es.js +21 -47
- package/lib/components/Checkout.cjs.js +1 -1
- package/lib/components/Checkout.es.js +814 -1614
- package/lib/components/CouponForm.cjs.js +1 -1
- package/lib/components/CouponForm.es.js +104 -155
- package/lib/components/CurrencySwitcher.cjs.js +1 -1
- package/lib/components/CurrencySwitcher.es.js +14 -33
- package/lib/components/CustomerProfileForm.cjs.js +1 -1
- package/lib/components/CustomerProfileForm.es.js +264 -672
- package/lib/components/FeaturedProduct.cjs.js +1 -1
- package/lib/components/FeaturedProduct.es.js +46 -125
- package/lib/components/FreemiusLicensePanel.cjs.js +1 -1
- package/lib/components/FreemiusLicensePanel.es.js +45 -125
- package/lib/components/InvoiceDocument.cjs.js +1 -1
- package/lib/components/InvoiceDocument.es.js +148 -487
- package/lib/components/InvoiceViewerShell.cjs.js +2 -2
- package/lib/components/InvoiceViewerShell.d.ts +4 -1
- package/lib/components/InvoiceViewerShell.es.js +59 -142
- package/lib/components/ProductCard.cjs.js +1 -1
- package/lib/components/ProductCard.d.ts +3 -1
- package/lib/components/ProductCard.es.js +128 -242
- package/lib/components/ProductDetailsLayout.cjs.js +1 -1
- package/lib/components/ProductDetailsLayout.es.js +311 -652
- package/lib/components/ProductGallery.cjs.js +1 -1
- package/lib/components/ProductGallery.d.ts +2 -0
- package/lib/components/ProductGallery.es.js +37 -66
- package/lib/components/ProductGrid.cjs.js +1 -1
- package/lib/components/ProductGrid.es.js +23 -32
- package/lib/components/ShippingEstimator.cjs.js +1 -1
- package/lib/components/ShippingEstimator.es.js +118 -231
- package/lib/components/SimpleTiptapRenderer.cjs.js +1 -1
- package/lib/components/SimpleTiptapRenderer.es.js +111 -294
- package/lib/components/SubscriptionSelector.cjs.js +1 -1
- package/lib/components/SubscriptionSelector.es.js +120 -181
- package/lib/freemius-trial-provision.cjs.js +1 -0
- package/lib/freemius-trial-provision.d.ts +85 -0
- package/lib/freemius-trial-provision.es.js +136 -0
- package/lib/invoice.cjs.js +1 -1
- package/lib/invoice.d.ts +1 -1
- package/lib/invoice.es.js +6 -5
- package/lib/pages/cms/coupons/CouponEditorForm.cjs.js +1 -1
- package/lib/pages/cms/coupons/CouponEditorForm.es.js +115 -375
- package/lib/pages/cms/coupons/CouponsPage.cjs.js +2 -2
- package/lib/pages/cms/coupons/CouponsPage.es.js +116 -368
- package/lib/pages/cms/coupons/CreateCouponDialog.cjs.js +1 -1
- package/lib/pages/cms/coupons/CreateCouponDialog.es.js +26 -62
- package/lib/pages/cms/coupons/EditCouponPage.cjs.js +1 -1
- package/lib/pages/cms/coupons/EditCouponPage.es.js +35 -71
- package/lib/pages/cms/coupons/ProductScopePicker.cjs.js +1 -1
- package/lib/pages/cms/coupons/ProductScopePicker.es.js +72 -167
- package/lib/pages/cms/orders/ExportReportsDialog.cjs.js +1 -1
- package/lib/pages/cms/orders/ExportReportsDialog.es.js +87 -247
- package/lib/pages/cms/orders/OrderDetailPage.cjs.js +1 -1
- package/lib/pages/cms/orders/OrderDetailPage.es.js +95 -283
- package/lib/pages/cms/orders/OrderPrintButton.cjs.js +1 -1
- package/lib/pages/cms/orders/OrderPrintButton.es.js +9 -21
- package/lib/pages/cms/orders/OrderStatusForm.cjs.js +1 -1
- package/lib/pages/cms/orders/OrderStatusForm.es.js +46 -106
- package/lib/pages/cms/orders/OrdersPage.cjs.js +1 -1
- package/lib/pages/cms/orders/OrdersPage.es.js +78 -257
- package/lib/pages/cms/payments/PaymentsClient.cjs.js +1 -1
- package/lib/pages/cms/payments/PaymentsClient.es.js +192 -580
- package/lib/pages/cms/payments/PaymentsPage.cjs.js +1 -1
- package/lib/pages/cms/payments/PaymentsPage.es.js +14 -22
- package/lib/pages/cms/products/ProductsPage.cjs.js +1 -1
- package/lib/pages/cms/products/ProductsPage.es.js +47 -87
- package/lib/pages/cms/products/_id_/edit/EditProductPage.cjs.js +1 -1
- package/lib/pages/cms/products/_id_/edit/EditProductPage.es.js +97 -177
- package/lib/pages/cms/products/attributes/AttributeManagementPage.cjs.js +1 -1
- package/lib/pages/cms/products/attributes/AttributeManagementPage.es.js +40 -84
- package/lib/pages/cms/products/attributes/components/AttributeManager.cjs.js +1 -1
- package/lib/pages/cms/products/attributes/components/AttributeManager.es.js +192 -455
- package/lib/pages/cms/products/categories/CategoryManagementPage.cjs.js +1 -1
- package/lib/pages/cms/products/categories/CategoryManagementPage.es.js +28 -72
- package/lib/pages/cms/products/categories/components/CategoryManager.cjs.js +1 -1
- package/lib/pages/cms/products/categories/components/CategoryManager.es.js +183 -490
- package/lib/pages/cms/products/components/CopyProductFromLanguage.cjs.js +1 -1
- package/lib/pages/cms/products/components/CopyProductFromLanguage.es.js +69 -177
- package/lib/pages/cms/products/components/CurrencyPriceFields.cjs.js +1 -1
- package/lib/pages/cms/products/components/CurrencyPriceFields.es.js +102 -213
- package/lib/pages/cms/products/components/DeleteProductButton.cjs.js +1 -1
- package/lib/pages/cms/products/components/DeleteProductButton.es.js +25 -45
- package/lib/pages/cms/products/components/FreemiusPricingDashboard.cjs.js +1 -1
- package/lib/pages/cms/products/components/FreemiusPricingDashboard.es.js +58 -202
- package/lib/pages/cms/products/components/ProductCategorySelector.cjs.js +1 -1
- package/lib/pages/cms/products/components/ProductCategorySelector.es.js +89 -235
- package/lib/pages/cms/products/components/ProductForm.cjs.js +1 -1
- package/lib/pages/cms/products/components/ProductForm.es.js +526 -1110
- package/lib/pages/cms/products/components/ProductMediaManager.cjs.js +1 -1
- package/lib/pages/cms/products/components/ProductMediaManager.es.js +63 -154
- package/lib/pages/cms/products/components/ProductsBulkTable.cjs.js +1 -1
- package/lib/pages/cms/products/components/ProductsBulkTable.es.js +213 -544
- package/lib/pages/cms/products/components/SaleScheduleFields.cjs.js +1 -1
- package/lib/pages/cms/products/components/SaleScheduleFields.es.js +91 -207
- package/lib/pages/cms/products/components/SyncFreemiusButton.cjs.js +1 -1
- package/lib/pages/cms/products/components/SyncFreemiusButton.es.js +16 -28
- package/lib/pages/cms/products/components/SyncFreemiusPricingButton.cjs.js +2 -2
- package/lib/pages/cms/products/components/SyncFreemiusPricingButton.es.js +25 -37
- package/lib/pages/cms/products/components/VariationsEditor.cjs.js +1 -1
- package/lib/pages/cms/products/components/VariationsEditor.es.js +261 -492
- package/lib/pages/cms/products/inventory/InventoryPage.cjs.js +1 -1
- package/lib/pages/cms/products/inventory/InventoryPage.es.js +12 -32
- package/lib/pages/cms/products/inventory/InventoryTableClient.cjs.js +2 -2
- package/lib/pages/cms/products/inventory/InventoryTableClient.es.js +145 -365
- package/lib/pages/cms/products/new/NewProductPage.cjs.js +1 -1
- package/lib/pages/cms/products/new/NewProductPage.es.js +30 -42
- package/lib/pages/cms/shipping/ShippingPage.cjs.js +2 -2
- package/lib/pages/cms/shipping/ShippingPage.es.js +155 -507
- package/lib/pages/cms/shipping/components/RateForm.cjs.js +1 -1
- package/lib/pages/cms/shipping/components/RateForm.es.js +334 -717
- package/lib/pages/cms/shipping/components/ZoneForm.cjs.js +1 -1
- package/lib/pages/cms/shipping/components/ZoneForm.es.js +158 -392
- package/lib/pages/cms/taxes/TaxesPage.cjs.js +1 -1
- package/lib/pages/cms/taxes/TaxesPage.es.js +119 -447
- package/lib/pages/cms/taxes/components/TaxRateForm.cjs.js +1 -1
- package/lib/pages/cms/taxes/components/TaxRateForm.es.js +52 -156
- package/lib/product-context.cjs.js +1 -1
- package/lib/product-context.es.js +10 -14
- package/lib/trials.cjs.js +1 -1
- package/lib/trials.d.ts +10 -3
- package/lib/trials.es.js +28 -21
- package/lib/types.d.ts +2 -0
- package/lib/use-price-formatter.cjs.js +1 -0
- package/lib/use-price-formatter.d.ts +11 -0
- package/lib/use-price-formatter.es.js +13 -0
- package/lib/variation-utils.cjs.js +1 -1
- package/lib/variation-utils.d.ts +10 -0
- package/lib/variation-utils.es.js +139 -123
- package/package.json +4 -4
- package/server.cjs.js +1 -1
- package/server.d.ts +1 -0
- package/server.es.js +180 -172
|
@@ -1,54 +1,51 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import {
|
|
3
|
-
import { useState as
|
|
4
|
-
import { Button as
|
|
5
|
-
import { Skeleton as
|
|
6
|
-
import { useCart as
|
|
7
|
-
import { ShoppingCart as
|
|
8
|
-
import { toast as
|
|
9
|
-
import { getPublicFreemiusPricing as
|
|
10
|
-
import { useTranslations as
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
2
|
+
import { jsx as o, jsxs as m } from "react/jsx-runtime";
|
|
3
|
+
import { useState as y, useEffect as B } 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 E } from "lucide-react";
|
|
8
|
+
import { toast as P } from "sonner";
|
|
9
|
+
import { getPublicFreemiusPricing as z } from "../pages/cms/products/actions.es.js";
|
|
10
|
+
import { useTranslations as D, majorUnitAmountToMinor as d } from "@nextblock-cms/utils";
|
|
11
|
+
import { usePriceFormatter as G } from "../use-price-formatter.es.js";
|
|
12
|
+
import { useCurrency as H } from "../CurrencyProvider.es.js";
|
|
13
|
+
import { convertMinorUnitAmount as _ } from "../currency.es.js";
|
|
14
|
+
import { getTrialSummary as J } from "../trials.es.js";
|
|
15
|
+
const oe = ({ product: e }) => {
|
|
16
|
+
const S = G(), h = U((l) => l), { t } = D(), { activeCurrencyCode: c, currencies: u, defaultCurrency: n } = H(), [M, R] = y([]), [A, T] = y(!0), [i, f] = y("annual");
|
|
17
|
+
if (B(() => {
|
|
17
18
|
async function l() {
|
|
18
19
|
try {
|
|
19
20
|
if (!e.id) return;
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
} catch (
|
|
23
|
-
console.error("Failed to load pricing:",
|
|
21
|
+
const s = await z(e.id);
|
|
22
|
+
R(s);
|
|
23
|
+
} catch (s) {
|
|
24
|
+
console.error("Failed to load pricing:", s);
|
|
24
25
|
} finally {
|
|
25
|
-
|
|
26
|
+
T(!1);
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
l();
|
|
29
|
-
}, [e.id]), !
|
|
30
|
-
return /* @__PURE__ */
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const { addItem: D } = x, u = R[0], r = u?.pricing?.[0], H = () => {
|
|
36
|
-
let l = e.price, c = e.freemius_plan_id;
|
|
37
|
-
r && (o === "monthly" && r.monthly_price != null && (l = m(r.monthly_price, i.code)), o === "annual" && r.annual_price != null && (l = m(r.annual_price, i.code)), o === "lifetime" && r.lifetime_price != null && (l = m(r.lifetime_price, i.code)));
|
|
38
|
-
const y = a.reduce((C, k) => (C[k.code] = p({
|
|
30
|
+
}, [e.id]), !h)
|
|
31
|
+
return /* @__PURE__ */ o(k, { className: "h-14 w-full" });
|
|
32
|
+
const { addItem: $ } = h, g = M[0], r = g?.pricing?.[0], j = () => {
|
|
33
|
+
let l = e.price, s = e.freemius_plan_id;
|
|
34
|
+
r && (i === "monthly" && r.monthly_price != null && (l = d(r.monthly_price, n.code)), i === "annual" && r.annual_price != null && (l = d(r.annual_price, n.code)), i === "lifetime" && r.lifetime_price != null && (l = d(r.lifetime_price, n.code)));
|
|
35
|
+
const v = u.reduce((N, w) => (N[w.code] = _({
|
|
39
36
|
amount: l,
|
|
40
|
-
fromCurrencyCode:
|
|
41
|
-
toCurrencyCode:
|
|
42
|
-
currencies:
|
|
37
|
+
fromCurrencyCode: n.code,
|
|
38
|
+
toCurrencyCode: w.code,
|
|
39
|
+
currencies: u,
|
|
43
40
|
applyRounding: !0
|
|
44
|
-
}),
|
|
45
|
-
|
|
46
|
-
const { success:
|
|
41
|
+
}), N), {}), q = v[c] ?? l;
|
|
42
|
+
g && g.id && (s = g.id);
|
|
43
|
+
const { success: F, error: L } = $({
|
|
47
44
|
id: e.id,
|
|
48
45
|
product_id: e.id,
|
|
49
46
|
title: e.title,
|
|
50
|
-
price:
|
|
51
|
-
prices:
|
|
47
|
+
price: q,
|
|
48
|
+
prices: v,
|
|
52
49
|
image_url: e.image_url,
|
|
53
50
|
slug: e.slug,
|
|
54
51
|
sku: e.sku,
|
|
@@ -57,160 +54,102 @@ const ne = ({ product: e }) => {
|
|
|
57
54
|
product_type: "digital",
|
|
58
55
|
payment_provider: "freemius",
|
|
59
56
|
provider: "freemius",
|
|
60
|
-
billing_cycle:
|
|
57
|
+
billing_cycle: i,
|
|
61
58
|
freemius_product_id: e.freemius_product_id,
|
|
62
|
-
freemius_plan_id:
|
|
59
|
+
freemius_plan_id: s,
|
|
63
60
|
// Overwrite if we got a real plan id
|
|
64
61
|
trial_period_days: e.trial_period_days ?? 0,
|
|
65
62
|
trial_requires_payment_method: e.trial_requires_payment_method ?? !1,
|
|
66
63
|
is_taxable: e.is_taxable,
|
|
67
|
-
currency_code:
|
|
64
|
+
currency_code: c
|
|
68
65
|
});
|
|
69
|
-
|
|
66
|
+
F ? P.success(t("ecommerce.added_to_cart_success", { item: e.title })) : P.error(L || t("ecommerce.added_to_cart_error"));
|
|
70
67
|
};
|
|
71
|
-
if (
|
|
72
|
-
return /* @__PURE__ */
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
o === "annual" && !g && (_ ? d("monthly") : h && d("lifetime"));
|
|
85
|
-
const f = V(e);
|
|
86
|
-
let b = e.price;
|
|
87
|
-
return o === "monthly" && r.monthly_price != null && (b = p({
|
|
88
|
-
amount: m(r.monthly_price, i.code),
|
|
89
|
-
fromCurrencyCode: i.code,
|
|
90
|
-
toCurrencyCode: s,
|
|
91
|
-
currencies: a,
|
|
68
|
+
if (A)
|
|
69
|
+
return /* @__PURE__ */ o(k, { className: "h-32 w-full" });
|
|
70
|
+
if (!g || !r)
|
|
71
|
+
return /* @__PURE__ */ o("div", { className: "p-4 border border-dashed rounded-lg text-center text-muted-foreground", children: t("ecommerce.pricing_unavailable") });
|
|
72
|
+
const b = r.monthly_price != null, x = r.annual_price != null, C = r.lifetime_price != null;
|
|
73
|
+
i === "annual" && !x && (b ? f("monthly") : C && f("lifetime"));
|
|
74
|
+
const a = J(e, t);
|
|
75
|
+
let p = e.price;
|
|
76
|
+
return i === "monthly" && r.monthly_price != null && (p = _({
|
|
77
|
+
amount: d(r.monthly_price, n.code),
|
|
78
|
+
fromCurrencyCode: n.code,
|
|
79
|
+
toCurrencyCode: c,
|
|
80
|
+
currencies: u,
|
|
92
81
|
applyRounding: !0
|
|
93
|
-
})),
|
|
94
|
-
amount:
|
|
95
|
-
fromCurrencyCode:
|
|
96
|
-
toCurrencyCode:
|
|
97
|
-
currencies:
|
|
82
|
+
})), i === "annual" && r.annual_price != null && (p = _({
|
|
83
|
+
amount: d(r.annual_price, n.code),
|
|
84
|
+
fromCurrencyCode: n.code,
|
|
85
|
+
toCurrencyCode: c,
|
|
86
|
+
currencies: u,
|
|
98
87
|
applyRounding: !0
|
|
99
|
-
})),
|
|
100
|
-
amount:
|
|
101
|
-
fromCurrencyCode:
|
|
102
|
-
toCurrencyCode:
|
|
103
|
-
currencies:
|
|
88
|
+
})), i === "lifetime" && r.lifetime_price != null && (p = _({
|
|
89
|
+
amount: d(r.lifetime_price, n.code),
|
|
90
|
+
fromCurrencyCode: n.code,
|
|
91
|
+
toCurrencyCode: c,
|
|
92
|
+
currencies: u,
|
|
104
93
|
applyRounding: !0
|
|
105
|
-
})), /* @__PURE__ */
|
|
106
|
-
/* @__PURE__ */
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
fileName: "C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/components/SubscriptionSelector.tsx",
|
|
150
|
-
lineNumber: 205,
|
|
151
|
-
columnNumber: 13
|
|
152
|
-
},
|
|
153
|
-
void 0
|
|
154
|
-
)
|
|
155
|
-
] }, void 0, !0, {
|
|
156
|
-
fileName: "C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/components/SubscriptionSelector.tsx",
|
|
157
|
-
lineNumber: 179,
|
|
158
|
-
columnNumber: 7
|
|
159
|
-
}, void 0),
|
|
160
|
-
/* @__PURE__ */ n("div", { className: "text-center", children: [
|
|
161
|
-
/* @__PURE__ */ n("span", { className: "text-3xl font-extrabold text-foreground", children: F(b, s) }, void 0, !1, {
|
|
162
|
-
fileName: "C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/components/SubscriptionSelector.tsx",
|
|
163
|
-
lineNumber: 219,
|
|
164
|
-
columnNumber: 11
|
|
165
|
-
}, void 0),
|
|
166
|
-
o !== "lifetime" && /* @__PURE__ */ n("span", { className: "text-muted-foreground text-sm ml-1.5", children: [
|
|
94
|
+
})), /* @__PURE__ */ m("div", { className: "flex flex-col gap-4", children: [
|
|
95
|
+
/* @__PURE__ */ m(
|
|
96
|
+
"div",
|
|
97
|
+
{
|
|
98
|
+
role: "group",
|
|
99
|
+
"aria-label": t("ecommerce.billing_cycle") === "ecommerce.billing_cycle" ? "Billing cycle" : t("ecommerce.billing_cycle"),
|
|
100
|
+
className: "flex bg-secondary/35 p-1 rounded-lg w-full max-w-sm mx-auto shadow-inner",
|
|
101
|
+
children: [
|
|
102
|
+
b && /* @__PURE__ */ o(
|
|
103
|
+
"button",
|
|
104
|
+
{
|
|
105
|
+
type: "button",
|
|
106
|
+
"aria-pressed": i === "monthly",
|
|
107
|
+
onClick: () => f("monthly"),
|
|
108
|
+
className: `flex-1 py-1.5 text-xs font-semibold rounded-md transition-colors focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring ${i === "monthly" ? "bg-background shadow-sm text-foreground" : "text-muted-foreground hover:text-foreground"}`,
|
|
109
|
+
children: t("ecommerce.monthly")
|
|
110
|
+
}
|
|
111
|
+
),
|
|
112
|
+
x && /* @__PURE__ */ o(
|
|
113
|
+
"button",
|
|
114
|
+
{
|
|
115
|
+
type: "button",
|
|
116
|
+
"aria-pressed": i === "annual",
|
|
117
|
+
onClick: () => f("annual"),
|
|
118
|
+
className: `flex-1 py-1.5 text-xs font-semibold rounded-md transition-colors focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring ${i === "annual" ? "bg-background shadow-sm text-foreground" : "text-muted-foreground hover:text-foreground"}`,
|
|
119
|
+
children: t("ecommerce.annual")
|
|
120
|
+
}
|
|
121
|
+
),
|
|
122
|
+
C && /* @__PURE__ */ o(
|
|
123
|
+
"button",
|
|
124
|
+
{
|
|
125
|
+
type: "button",
|
|
126
|
+
"aria-pressed": i === "lifetime",
|
|
127
|
+
onClick: () => f("lifetime"),
|
|
128
|
+
className: `flex-1 py-1.5 text-xs font-semibold rounded-md transition-colors focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring ${i === "lifetime" ? "bg-background shadow-sm text-foreground" : "text-muted-foreground hover:text-foreground"}`,
|
|
129
|
+
children: t("ecommerce.lifetime")
|
|
130
|
+
}
|
|
131
|
+
)
|
|
132
|
+
]
|
|
133
|
+
}
|
|
134
|
+
),
|
|
135
|
+
/* @__PURE__ */ m("div", { className: "text-center", children: [
|
|
136
|
+
/* @__PURE__ */ o("span", { className: "text-3xl font-extrabold text-foreground tabular-nums", children: S(p, c) }),
|
|
137
|
+
i !== "lifetime" && /* @__PURE__ */ m("span", { className: "text-muted-foreground text-sm ml-1.5", children: [
|
|
167
138
|
"/ ",
|
|
168
|
-
t(
|
|
169
|
-
] },
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
/* @__PURE__ */ n("span", { className: "text-muted-foreground", children: f.paymentRequirementLabel }, void 0, !1, {
|
|
182
|
-
fileName: "C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/components/SubscriptionSelector.tsx",
|
|
183
|
-
lineNumber: 229,
|
|
184
|
-
columnNumber: 15
|
|
185
|
-
}, void 0)
|
|
186
|
-
] }, void 0, !0, {
|
|
187
|
-
fileName: "C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/components/SubscriptionSelector.tsx",
|
|
188
|
-
lineNumber: 226,
|
|
189
|
-
columnNumber: 13
|
|
190
|
-
}, void 0)
|
|
191
|
-
] }, void 0, !0, {
|
|
192
|
-
fileName: "C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/components/SubscriptionSelector.tsx",
|
|
193
|
-
lineNumber: 218,
|
|
194
|
-
columnNumber: 7
|
|
195
|
-
}, void 0),
|
|
196
|
-
/* @__PURE__ */ n(T, { onClick: H, className: "w-full h-12 text-md font-bold shadow-md transition-all hover:shadow-lg active:scale-[0.98]", children: [
|
|
197
|
-
/* @__PURE__ */ n(q, { className: "mr-2 h-4 w-4" }, void 0, !1, {
|
|
198
|
-
fileName: "C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/components/SubscriptionSelector.tsx",
|
|
199
|
-
lineNumber: 237,
|
|
200
|
-
columnNumber: 9
|
|
201
|
-
}, void 0),
|
|
202
|
-
f?.label ? `Start ${f.label}` : t("ecommerce.get_license")
|
|
203
|
-
] }, void 0, !0, {
|
|
204
|
-
fileName: "C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/components/SubscriptionSelector.tsx",
|
|
205
|
-
lineNumber: 236,
|
|
206
|
-
columnNumber: 7
|
|
207
|
-
}, void 0)
|
|
208
|
-
] }, void 0, !0, {
|
|
209
|
-
fileName: "C:/Users/desjardinsn/Desktop/NRH-NextBlock/libs/ecommerce/src/lib/components/SubscriptionSelector.tsx",
|
|
210
|
-
lineNumber: 177,
|
|
211
|
-
columnNumber: 5
|
|
212
|
-
}, void 0);
|
|
139
|
+
t(i === "annual" ? "ecommerce.year" : "ecommerce.month")
|
|
140
|
+
] }),
|
|
141
|
+
a && /* @__PURE__ */ m("div", { className: "mt-1 text-xs font-medium text-emerald-600 dark:text-emerald-400", children: [
|
|
142
|
+
a.label,
|
|
143
|
+
/* @__PURE__ */ o("span", { className: "mx-2 text-muted-foreground/50", children: "|" }),
|
|
144
|
+
/* @__PURE__ */ o("span", { className: "text-muted-foreground", children: a.paymentRequirementLabel })
|
|
145
|
+
] })
|
|
146
|
+
] }),
|
|
147
|
+
/* @__PURE__ */ m(I, { onClick: j, className: "w-full h-12 text-base font-bold shadow-md transition-shadow hover:shadow-lg active:scale-[0.98]", children: [
|
|
148
|
+
/* @__PURE__ */ o(E, { className: "mr-2 h-4 w-4" }),
|
|
149
|
+
a?.label ? t("ecommerce.start_trial", { trial: a.label }) === "ecommerce.start_trial" ? `Start ${a.label}` : t("ecommerce.start_trial", { trial: a.label }) : t("ecommerce.get_license")
|
|
150
|
+
] })
|
|
151
|
+
] });
|
|
213
152
|
};
|
|
214
153
|
export {
|
|
215
|
-
|
|
154
|
+
oe as SubscriptionSelector
|
|
216
155
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("@freemius/sdk"),F=require("./payment-config.cjs.js"),v=require("./providers/freemius.cjs.js"),y="A NextBlock license or trial already exists for this email. Activate that key from CMS Settings → Packages, or purchase a license at nextblock.dev.",m="The trial could not be provisioned automatically. Start it from CMS Settings → Packages instead.";function I(e){return e.toISOString().slice(0,19).replace("T"," ")}function S(e,n){const r=Number.isFinite(n)&&n>0?Math.floor(n):30;return new Date(e.getTime()+r*24*60*60*1e3)}function E(e){const n=e.filter(t=>t.id!==null&&t.id!==void 0);if(n.length===0)return null;const r=n.filter(t=>!t.is_hidden);return[...r.length>0?r:n].sort((t,s)=>{const a=t.licenses===null||t.licenses===void 0?Number.POSITIVE_INFINITY:t.licenses,u=s.licenses===null||s.licenses===void 0?Number.POSITIVE_INFINITY:s.licenses;return a-u})[0]}function k(e){return e.existingLicenses.some(r=>r.plugin_id===null||r.plugin_id===void 0||String(r.plugin_id).trim()===String(e.productId).trim())?{ok:!1,reason:"already_licensed"}:{ok:!0}}function b(e){return e.trim().toLowerCase()}async function w(e,n){await F.hydrateFreemiusEnvFromDb();const r=v.resolveFreemiusCheckoutCredentials(e.productId);if(!r.apiKey||!r.secretKey||!r.publicKey)return{error:"The license service is not configured for this product.",ok:!1,reason:"not_configured",status:503};const c=new T.Freemius({apiKey:r.apiKey,productId:Number(e.productId),publicKey:r.publicKey,secretKey:r.secretKey}),t=b(e.email),s=c.api.__unstable_ApiClient,a={product_id:e.productId};let u=[];try{const i=await c.api.user.retrieveByEmail(t);i?.id!==null&&i?.id!==void 0&&(u=await c.api.user.retrieveLicenses(i.id))}catch(i){return console.error("[Freemius trial] user lookup failed:",i),{error:"Freemius could not be reached to verify eligibility.",ok:!1,reason:"upstream_error",status:502}}if(!k({existingLicenses:u,productId:e.productId}).ok)return{error:y,ok:!1,reason:"already_licensed",status:409};let d=null;try{const{data:i,error:l}=await s.GET("/products/{product_id}/plans/{plan_id}/pricing.json",{params:{path:{...a,plan_id:e.planId}}});if(l)throw new Error(JSON.stringify(l));const o=E(i?.pricing??[]);d=o?.id!==null&&o?.id!==void 0?String(o.id):null}catch(i){return console.error("[Freemius trial] pricing lookup failed:",i),{error:"Freemius could not be reached to resolve the plan pricing.",ok:!1,reason:"upstream_error",status:502}}if(!d)return{error:m,ok:!1,reason:"no_pricing",status:502};const h=n?.now??new Date,f=I(S(h,e.trialDays));let p=null,_=null;try{const{data:i,error:l}=await s.POST("/products/{product_id}/plans/{plan_id}/pricing/{pricing_id}/licenses.json",{body:{expires_at:f,is_block_features:!0,send_email:!1},params:{path:{...a,plan_id:e.planId,pricing_id:d}}});if(l)throw new Error(JSON.stringify(l));const o=i?.license;p=o?.secret_key?.trim()||null,_=o?.id!==null&&o?.id!==void 0?String(o.id):null}catch(i){return console.error("[Freemius trial] license creation failed:",i),{error:"Freemius could not create the trial license.",ok:!1,reason:"upstream_error",status:502}}if(!p)return{error:m,ok:!1,reason:"no_key",status:502};let g=!1;try{const{error:i}=await s.PUT("/products/{product_id}/licenses.json",{body:{email:t,license_key:p,name:e.name.trim()},params:{path:a}});g=!i,i&&console.warn("[Freemius trial] license assignment refused:",JSON.stringify(i))}catch(i){console.warn("[Freemius trial] license assignment failed:",i)}return{assigned:g,expiresAt:f,licenseId:_,licenseKey:p,ok:!0,planId:e.planId,pricingId:d}}exports.FREEMIUS_TRIAL_ALREADY_USED_MESSAGE=y;exports.FREEMIUS_TRIAL_PROVISION_FAILED_MESSAGE=m;exports.computeTrialExpiry=S;exports.evaluateTrialEligibility=k;exports.formatFreemiusTimestamp=I;exports.pickTrialPricing=E;exports.provisionFreemiusTrialLicense=w;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vendor-side headless trial provisioning.
|
|
3
|
+
*
|
|
4
|
+
* The in-dashboard trial goes through the Freemius checkout overlay, which collects the
|
|
5
|
+
* buyer's name and email itself and creates a real Freemius *trial* (a subscription in a
|
|
6
|
+
* trialing state). Freemius exposes no API to start such a trial from a name and an
|
|
7
|
+
* email alone — the trial endpoint is install-scoped, and an install only exists once
|
|
8
|
+
* the buyer's site has activated something.
|
|
9
|
+
*
|
|
10
|
+
* What the API does allow the vendor to do is mint a time-boxed license on the plan
|
|
11
|
+
* (`POST .../plans/{plan}/pricing/{pricing}/licenses.json` with `expires_at`) and then
|
|
12
|
+
* assign it to an email (`PUT /products/{product}/licenses.json`), which creates the
|
|
13
|
+
* Freemius user if needed and sends the welcome email with the key. Functionally that is
|
|
14
|
+
* the same 30-day, no-card trial the overlay produces: the buyer's CMS activates the key
|
|
15
|
+
* normally, `package_activations.meta.nextblock.trial_ends_at` expires it locally, and
|
|
16
|
+
* the daily revalidation sees Freemius report it expired. What it is not is a Freemius
|
|
17
|
+
* subscription, so it never auto-converts — which a no-card trial cannot do anyway.
|
|
18
|
+
*
|
|
19
|
+
* Abuse controls: one trial per email per product (any existing license, even expired,
|
|
20
|
+
* refuses a new one), plus the route's per-address and per-email rate limits. The
|
|
21
|
+
* request is the buyer's own email, so the refusal names the reason.
|
|
22
|
+
*/
|
|
23
|
+
export type FreemiusTrialProvisionRequest = {
|
|
24
|
+
email: string;
|
|
25
|
+
name: string;
|
|
26
|
+
/** Freemius plan the trial license is minted on (`fm_plan_id` in the package registry). */
|
|
27
|
+
planId: string;
|
|
28
|
+
/** Freemius product id (`fm_product_id` in the package registry). */
|
|
29
|
+
productId: string;
|
|
30
|
+
trialDays: number;
|
|
31
|
+
};
|
|
32
|
+
export type FreemiusTrialProvisionRejection = 'already_licensed' | 'no_key' | 'no_pricing';
|
|
33
|
+
export type FreemiusTrialProvisionResult = {
|
|
34
|
+
/** False when the license was minted but could not be tied to the email; the key still works. */
|
|
35
|
+
assigned: boolean;
|
|
36
|
+
expiresAt: string;
|
|
37
|
+
licenseId: string | null;
|
|
38
|
+
licenseKey: string;
|
|
39
|
+
ok: true;
|
|
40
|
+
planId: string;
|
|
41
|
+
pricingId: string;
|
|
42
|
+
} | {
|
|
43
|
+
error: string;
|
|
44
|
+
ok: false;
|
|
45
|
+
reason: FreemiusTrialProvisionRejection | 'not_configured' | 'upstream_error';
|
|
46
|
+
status: number;
|
|
47
|
+
};
|
|
48
|
+
export declare const FREEMIUS_TRIAL_ALREADY_USED_MESSAGE = "A NextBlock license or trial already exists for this email. Activate that key from CMS Settings \u2192 Packages, or purchase a license at nextblock.dev.";
|
|
49
|
+
export declare const FREEMIUS_TRIAL_PROVISION_FAILED_MESSAGE = "The trial could not be provisioned automatically. Start it from CMS Settings \u2192 Packages instead.";
|
|
50
|
+
export type FreemiusPricingLike = {
|
|
51
|
+
id?: string | number | null;
|
|
52
|
+
is_hidden?: boolean | null;
|
|
53
|
+
/** Site quota; null means unlimited. */
|
|
54
|
+
licenses?: number | null;
|
|
55
|
+
};
|
|
56
|
+
export type FreemiusOwnedLicenseLike = {
|
|
57
|
+
id?: string | number | null;
|
|
58
|
+
plugin_id?: string | number | null;
|
|
59
|
+
};
|
|
60
|
+
/** Freemius timestamps are "YYYY-MM-DD HH:mm:ss" in UTC, without a zone marker. */
|
|
61
|
+
export declare function formatFreemiusTimestamp(date: Date): string;
|
|
62
|
+
export declare function computeTrialExpiry(now: Date, trialDays: number): Date;
|
|
63
|
+
/**
|
|
64
|
+
* The plan's cheapest tier is the one to trial: a visible pricing with the smallest site
|
|
65
|
+
* quota (a single-site license), falling back to whatever is listed first.
|
|
66
|
+
*/
|
|
67
|
+
export declare function pickTrialPricing(pricing: readonly FreemiusPricingLike[]): FreemiusPricingLike | null;
|
|
68
|
+
/** Pure decision: does this email already hold any license for the product? */
|
|
69
|
+
export declare function evaluateTrialEligibility(input: {
|
|
70
|
+
existingLicenses: readonly FreemiusOwnedLicenseLike[];
|
|
71
|
+
productId: string;
|
|
72
|
+
}): {
|
|
73
|
+
ok: true;
|
|
74
|
+
} | {
|
|
75
|
+
ok: false;
|
|
76
|
+
reason: 'already_licensed';
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Mint and assign a trial license. The Freemius product-scope bearer credentials come
|
|
80
|
+
* from the same resolver as the license claim route, so a vendor that already answers
|
|
81
|
+
* claims needs no extra configuration.
|
|
82
|
+
*/
|
|
83
|
+
export declare function provisionFreemiusTrialLicense(request: FreemiusTrialProvisionRequest, options?: {
|
|
84
|
+
now?: Date;
|
|
85
|
+
}): Promise<FreemiusTrialProvisionResult>;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { Freemius as I } from "@freemius/sdk";
|
|
2
|
+
import { hydrateFreemiusEnvFromDb as h } from "./payment-config.es.js";
|
|
3
|
+
import { resolveFreemiusCheckoutCredentials as k } from "./providers/freemius.es.js";
|
|
4
|
+
const S = "A NextBlock license or trial already exists for this email. Activate that key from CMS Settings → Packages, or purchase a license at nextblock.dev.", g = "The trial could not be provisioned automatically. Start it from CMS Settings → Packages instead.";
|
|
5
|
+
function E(e) {
|
|
6
|
+
return e.toISOString().slice(0, 19).replace("T", " ");
|
|
7
|
+
}
|
|
8
|
+
function v(e, n) {
|
|
9
|
+
const i = Number.isFinite(n) && n > 0 ? Math.floor(n) : 30;
|
|
10
|
+
return new Date(e.getTime() + i * 24 * 60 * 60 * 1e3);
|
|
11
|
+
}
|
|
12
|
+
function w(e) {
|
|
13
|
+
const n = e.filter((t) => t.id !== null && t.id !== void 0);
|
|
14
|
+
if (n.length === 0)
|
|
15
|
+
return null;
|
|
16
|
+
const i = n.filter((t) => !t.is_hidden);
|
|
17
|
+
return [...i.length > 0 ? i : n].sort((t, s) => {
|
|
18
|
+
const l = t.licenses === null || t.licenses === void 0 ? Number.POSITIVE_INFINITY : t.licenses, u = s.licenses === null || s.licenses === void 0 ? Number.POSITIVE_INFINITY : s.licenses;
|
|
19
|
+
return l - u;
|
|
20
|
+
})[0];
|
|
21
|
+
}
|
|
22
|
+
function F(e) {
|
|
23
|
+
return e.existingLicenses.some(
|
|
24
|
+
(i) => i.plugin_id === null || i.plugin_id === void 0 || String(i.plugin_id).trim() === String(e.productId).trim()
|
|
25
|
+
) ? { ok: !1, reason: "already_licensed" } : { ok: !0 };
|
|
26
|
+
}
|
|
27
|
+
function b(e) {
|
|
28
|
+
return e.trim().toLowerCase();
|
|
29
|
+
}
|
|
30
|
+
async function x(e, n) {
|
|
31
|
+
await h();
|
|
32
|
+
const i = k(e.productId);
|
|
33
|
+
if (!i.apiKey || !i.secretKey || !i.publicKey)
|
|
34
|
+
return {
|
|
35
|
+
error: "The license service is not configured for this product.",
|
|
36
|
+
ok: !1,
|
|
37
|
+
reason: "not_configured",
|
|
38
|
+
status: 503
|
|
39
|
+
};
|
|
40
|
+
const c = new I({
|
|
41
|
+
apiKey: i.apiKey,
|
|
42
|
+
productId: Number(e.productId),
|
|
43
|
+
publicKey: i.publicKey,
|
|
44
|
+
secretKey: i.secretKey
|
|
45
|
+
}), t = b(e.email), s = c.api.__unstable_ApiClient, l = { product_id: e.productId };
|
|
46
|
+
let u = [];
|
|
47
|
+
try {
|
|
48
|
+
const r = await c.api.user.retrieveByEmail(t);
|
|
49
|
+
r?.id !== null && r?.id !== void 0 && (u = await c.api.user.retrieveLicenses(r.id));
|
|
50
|
+
} catch (r) {
|
|
51
|
+
return console.error("[Freemius trial] user lookup failed:", r), {
|
|
52
|
+
error: "Freemius could not be reached to verify eligibility.",
|
|
53
|
+
ok: !1,
|
|
54
|
+
reason: "upstream_error",
|
|
55
|
+
status: 502
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
if (!F({ existingLicenses: u, productId: e.productId }).ok)
|
|
59
|
+
return { error: S, ok: !1, reason: "already_licensed", status: 409 };
|
|
60
|
+
let d = null;
|
|
61
|
+
try {
|
|
62
|
+
const { data: r, error: a } = await s.GET("/products/{product_id}/plans/{plan_id}/pricing.json", {
|
|
63
|
+
params: { path: { ...l, plan_id: e.planId } }
|
|
64
|
+
});
|
|
65
|
+
if (a)
|
|
66
|
+
throw new Error(JSON.stringify(a));
|
|
67
|
+
const o = w(r?.pricing ?? []);
|
|
68
|
+
d = o?.id !== null && o?.id !== void 0 ? String(o.id) : null;
|
|
69
|
+
} catch (r) {
|
|
70
|
+
return console.error("[Freemius trial] pricing lookup failed:", r), {
|
|
71
|
+
error: "Freemius could not be reached to resolve the plan pricing.",
|
|
72
|
+
ok: !1,
|
|
73
|
+
reason: "upstream_error",
|
|
74
|
+
status: 502
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
if (!d)
|
|
78
|
+
return {
|
|
79
|
+
error: g,
|
|
80
|
+
ok: !1,
|
|
81
|
+
reason: "no_pricing",
|
|
82
|
+
status: 502
|
|
83
|
+
};
|
|
84
|
+
const y = n?.now ?? /* @__PURE__ */ new Date(), m = E(v(y, e.trialDays));
|
|
85
|
+
let p = null, f = null;
|
|
86
|
+
try {
|
|
87
|
+
const { data: r, error: a } = await s.POST(
|
|
88
|
+
"/products/{product_id}/plans/{plan_id}/pricing/{pricing_id}/licenses.json",
|
|
89
|
+
{
|
|
90
|
+
body: { expires_at: m, is_block_features: !0, send_email: !1 },
|
|
91
|
+
params: { path: { ...l, plan_id: e.planId, pricing_id: d } }
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
if (a)
|
|
95
|
+
throw new Error(JSON.stringify(a));
|
|
96
|
+
const o = r?.license;
|
|
97
|
+
p = o?.secret_key?.trim() || null, f = o?.id !== null && o?.id !== void 0 ? String(o.id) : null;
|
|
98
|
+
} catch (r) {
|
|
99
|
+
return console.error("[Freemius trial] license creation failed:", r), {
|
|
100
|
+
error: "Freemius could not create the trial license.",
|
|
101
|
+
ok: !1,
|
|
102
|
+
reason: "upstream_error",
|
|
103
|
+
status: 502
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
if (!p)
|
|
107
|
+
return { error: g, ok: !1, reason: "no_key", status: 502 };
|
|
108
|
+
let _ = !1;
|
|
109
|
+
try {
|
|
110
|
+
const { error: r } = await s.PUT("/products/{product_id}/licenses.json", {
|
|
111
|
+
body: { email: t, license_key: p, name: e.name.trim() },
|
|
112
|
+
params: { path: l }
|
|
113
|
+
});
|
|
114
|
+
_ = !r, r && console.warn("[Freemius trial] license assignment refused:", JSON.stringify(r));
|
|
115
|
+
} catch (r) {
|
|
116
|
+
console.warn("[Freemius trial] license assignment failed:", r);
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
assigned: _,
|
|
120
|
+
expiresAt: m,
|
|
121
|
+
licenseId: f,
|
|
122
|
+
licenseKey: p,
|
|
123
|
+
ok: !0,
|
|
124
|
+
planId: e.planId,
|
|
125
|
+
pricingId: d
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
export {
|
|
129
|
+
S as FREEMIUS_TRIAL_ALREADY_USED_MESSAGE,
|
|
130
|
+
g as FREEMIUS_TRIAL_PROVISION_FAILED_MESSAGE,
|
|
131
|
+
v as computeTrialExpiry,
|
|
132
|
+
F as evaluateTrialEligibility,
|
|
133
|
+
E as formatFreemiusTimestamp,
|
|
134
|
+
w as pickTrialPricing,
|
|
135
|
+
x as provisionFreemiusTrialLicense
|
|
136
|
+
};
|
package/lib/invoice.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u="invoice_settings",
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u="invoice_settings",o={businessName:"",email:"",phone:"",address:{line1:"",line2:"",city:"",state:"",postal_code:"",country_code:"CA"},taxRegistrations:[]};function t(e){return typeof e!="string"?"":e.trim()}function s(e){if(!e||typeof e!="object"||Array.isArray(e))return{...o.address};const n=e;return{line1:t(n.line1),line2:t(n.line2),city:t(n.city),state:t(n.state),postal_code:t(n.postal_code),country_code:t(n.country_code).toUpperCase()||"CA"}}function c(e){return Array.isArray(e)?e.map(n=>{if(!n||typeof n!="object"||Array.isArray(n))return null;const i=n,r=t(i.label),a=t(i.value);return!r&&!a?null:{label:r,value:a}}).filter(n=>!!n):[]}function m(e){if(!e||typeof e!="object"||Array.isArray(e))return{...o};const n=e;return{businessName:t(n.business_name??n.businessName),email:t(n.email),phone:t(n.phone),address:s(n.address),taxRegistrations:c(n.tax_registrations??n.taxRegistrations)}}function l(e){return{business_name:t(e.businessName),email:t(e.email),phone:t(e.phone),address:s(e.address),tax_registrations:c(e.taxRegistrations)}}function f(e,n="usd",i="en-US"){return new Intl.NumberFormat(i,{style:"currency",currency:n.toUpperCase()}).format(e/100)}function y(e,n="en-US",i="UTC"){if(!e)return"";const r=new Date(e);return Number.isNaN(r.getTime())?"":new Intl.DateTimeFormat(n,{year:"numeric",month:"short",day:"numeric",timeZone:i}).format(r)}function p(e){if(!e)return[];const n=[e.city,e.state,e.postal_code].filter(Boolean).join(", ").replace(", ,",",").trim();return["company_name"in e&&e.company_name||"","recipient_name"in e&&e.recipient_name||"",e.line1||"",e.line2||"",n,e.country_code||""].filter(Boolean)}exports.DEFAULT_INVOICE_SETTINGS=o;exports.INVOICE_SETTINGS_KEY=u;exports.formatInvoiceCurrency=f;exports.formatInvoiceDate=y;exports.getInvoiceAddressLines=p;exports.normalizeInvoiceSettings=m;exports.serializeInvoiceSettings=l;
|
package/lib/invoice.d.ts
CHANGED
|
@@ -71,5 +71,5 @@ export declare function serializeInvoiceSettings(settings: InvoiceSettings): {
|
|
|
71
71
|
tax_registrations: InvoiceTaxRegistration[];
|
|
72
72
|
};
|
|
73
73
|
export declare function formatInvoiceCurrency(amount: number, currency?: string, locale?: string): string;
|
|
74
|
-
export declare function formatInvoiceDate(value?: string | null, locale?: string): string;
|
|
74
|
+
export declare function formatInvoiceDate(value?: string | null, locale?: string, timeZone?: string): string;
|
|
75
75
|
export declare function getInvoiceAddressLines(address?: InvoiceAddress | OrderCustomerDetails['billing']): string[];
|
package/lib/invoice.es.js
CHANGED
|
@@ -68,15 +68,16 @@ function f(e, n = "usd", r = "en-US") {
|
|
|
68
68
|
currency: n.toUpperCase()
|
|
69
69
|
}).format(e / 100);
|
|
70
70
|
}
|
|
71
|
-
function y(e, n = "en-US") {
|
|
71
|
+
function y(e, n = "en-US", r = "UTC") {
|
|
72
72
|
if (!e)
|
|
73
73
|
return "";
|
|
74
|
-
const
|
|
75
|
-
return Number.isNaN(
|
|
74
|
+
const i = new Date(e);
|
|
75
|
+
return Number.isNaN(i.getTime()) ? "" : new Intl.DateTimeFormat(n, {
|
|
76
76
|
year: "numeric",
|
|
77
77
|
month: "short",
|
|
78
|
-
day: "numeric"
|
|
79
|
-
|
|
78
|
+
day: "numeric",
|
|
79
|
+
timeZone: r
|
|
80
|
+
}).format(i);
|
|
80
81
|
}
|
|
81
82
|
function p(e) {
|
|
82
83
|
if (!e)
|