@nextblock-cms/ecom 0.8.1 → 0.8.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs.js +1 -1
- package/index.es.js +136 -3224
- package/lib/CurrencyProvider.cjs.js +1 -0
- package/lib/CurrencyProvider.es.js +99 -0
- package/lib/cart-store.cjs.js +1 -0
- package/lib/cart-store.es.js +116 -0
- package/lib/components/AccountNavigationMenu.cjs.js +1 -0
- package/lib/components/AccountNavigationMenu.es.js +44 -0
- package/lib/components/AddToCartButton.cjs.js +1 -0
- package/lib/components/AddToCartButton.es.js +60 -0
- package/lib/components/Cart.cjs.js +1 -0
- package/lib/components/Cart.es.js +148 -0
- package/lib/components/CartDrawer.cjs.js +1 -0
- package/lib/components/CartDrawer.es.js +119 -0
- package/lib/components/CartIcon.cjs.js +1 -0
- package/lib/components/CartIcon.es.js +34 -0
- package/lib/components/Checkout.cjs.js +1 -0
- package/lib/components/Checkout.es.js +987 -0
- package/lib/components/CouponForm.cjs.js +1 -0
- package/lib/components/CouponForm.es.js +136 -0
- package/lib/components/CurrencySwitcher.cjs.js +1 -0
- package/lib/components/CurrencySwitcher.es.js +18 -0
- package/lib/components/CustomerProfileForm.cjs.js +1 -0
- package/lib/components/CustomerProfileForm.es.js +355 -0
- package/lib/components/FeaturedProduct.cjs.js +1 -0
- package/lib/components/FeaturedProduct.es.js +72 -0
- package/lib/components/InvoiceDocument.cjs.js +1 -0
- package/lib/components/InvoiceDocument.es.js +196 -0
- package/lib/components/InvoiceViewerShell.cjs.js +29 -0
- package/lib/components/InvoiceViewerShell.es.js +100 -0
- package/lib/components/ProductCard.cjs.js +1 -0
- package/lib/components/ProductCard.es.js +119 -0
- package/lib/components/ProductDetailsLayout.cjs.js +1 -0
- package/lib/components/ProductDetailsLayout.es.js +361 -0
- package/lib/components/ProductGallery.cjs.js +1 -0
- package/lib/components/ProductGallery.es.js +41 -0
- package/lib/components/ProductGrid.cjs.js +1 -0
- package/lib/components/ProductGrid.es.js +19 -0
- package/lib/components/ShippingEstimator.cjs.js +1 -0
- package/lib/components/ShippingEstimator.es.js +125 -0
- package/lib/components/SimpleTiptapRenderer.cjs.js +1 -0
- package/lib/components/SimpleTiptapRenderer.es.js +187 -0
- package/lib/components/SubscriptionSelector.cjs.js +1 -0
- package/lib/components/SubscriptionSelector.es.js +140 -0
- package/lib/countries.cjs.js +1 -0
- package/lib/countries.es.js +77 -0
- package/lib/coupon-server.cjs.js +1 -0
- package/lib/coupon-server.es.js +234 -0
- package/lib/coupons.cjs.js +1 -0
- package/lib/coupons.es.js +17 -0
- package/lib/currency-constants.cjs.js +1 -0
- package/lib/currency-constants.es.js +4 -0
- package/lib/currency-store.cjs.js +1 -0
- package/lib/currency-store.es.js +27 -0
- package/lib/currency-sync.cjs.js +1 -0
- package/lib/currency-sync.es.js +180 -0
- package/lib/currency.cjs.js +1 -0
- package/lib/currency.es.js +312 -0
- package/lib/customer-addresses.cjs.js +1 -0
- package/lib/customer-addresses.es.js +116 -0
- package/lib/customer-orders.cjs.js +1 -0
- package/lib/customer-orders.es.js +45 -0
- package/lib/customer.cjs.js +1 -0
- package/lib/customer.es.js +58 -0
- package/lib/export-helpers.cjs.js +1 -0
- package/lib/export-helpers.es.js +56 -0
- package/lib/factory.cjs.js +1 -0
- package/lib/factory.es.js +8 -0
- package/lib/freemius-coupons.cjs.js +1 -0
- package/lib/freemius-coupons.es.js +272 -0
- package/lib/freemius-order-sync.cjs.js +1 -0
- package/lib/freemius-order-sync.es.js +284 -0
- package/lib/inventory-settings.cjs.js +1 -0
- package/lib/inventory-settings.es.js +86 -0
- package/lib/invoice-server.cjs.js +33 -0
- package/lib/invoice-server.es.js +141 -0
- package/lib/invoice-ui.cjs.js +1 -0
- package/lib/invoice-ui.es.js +71 -0
- package/lib/invoice.cjs.js +1 -0
- package/lib/invoice.es.js +102 -0
- package/lib/order-inventory.cjs.js +61 -0
- package/lib/order-inventory.es.js +128 -0
- package/lib/order-tax-details.cjs.js +1 -0
- package/lib/order-tax-details.es.js +164 -0
- package/lib/pages/cms/coupons/CouponEditorForm.cjs.js +1 -0
- package/lib/pages/cms/coupons/CouponEditorForm.es.js +189 -0
- package/lib/pages/cms/coupons/CouponsPage.cjs.js +5 -0
- package/lib/pages/cms/coupons/CouponsPage.es.js +171 -0
- package/lib/pages/cms/coupons/CreateCouponDialog.cjs.js +1 -0
- package/lib/pages/cms/coupons/CreateCouponDialog.es.js +35 -0
- package/lib/pages/cms/coupons/EditCouponPage.cjs.js +1 -0
- package/lib/pages/cms/coupons/EditCouponPage.es.js +48 -0
- package/lib/pages/cms/coupons/ProductScopePicker.cjs.js +1 -0
- package/lib/pages/cms/coupons/ProductScopePicker.es.js +120 -0
- package/lib/pages/cms/coupons/actions.cjs.js +1 -0
- package/lib/pages/cms/coupons/actions.es.js +128 -0
- package/lib/pages/cms/coupons/product-options.cjs.js +1 -0
- package/lib/pages/cms/coupons/product-options.es.js +27 -0
- package/lib/pages/cms/orders/ExportReportsDialog.cjs.js +1 -0
- package/lib/pages/cms/orders/ExportReportsDialog.es.js +130 -0
- package/lib/pages/cms/orders/OrderDetailPage.cjs.js +1 -0
- package/lib/pages/cms/orders/OrderDetailPage.es.js +137 -0
- package/lib/pages/cms/orders/OrderPrintButton.cjs.js +1 -0
- package/lib/pages/cms/orders/OrderPrintButton.es.js +22 -0
- package/lib/pages/cms/orders/OrderStatusForm.cjs.js +1 -0
- package/lib/pages/cms/orders/OrderStatusForm.es.js +71 -0
- package/lib/pages/cms/orders/OrdersPage.cjs.js +1 -0
- package/lib/pages/cms/orders/OrdersPage.es.js +104 -0
- package/lib/pages/cms/orders/actions.cjs.js +7 -0
- package/lib/pages/cms/orders/actions.es.js +71 -0
- package/lib/pages/cms/orders/export-actions.cjs.js +1 -0
- package/lib/pages/cms/orders/export-actions.es.js +27 -0
- package/lib/pages/cms/orders/server-actions.cjs.js +1 -0
- package/lib/pages/cms/orders/server-actions.es.js +55 -0
- package/lib/pages/cms/payments/PaymentsClient.cjs.js +1 -0
- package/lib/pages/cms/payments/PaymentsClient.es.js +188 -0
- package/lib/pages/cms/payments/PaymentsPage.cjs.js +1 -0
- package/lib/pages/cms/payments/PaymentsPage.es.js +29 -0
- package/lib/pages/cms/payments/actions.cjs.js +1 -0
- package/lib/pages/cms/payments/actions.es.js +23 -0
- package/lib/pages/cms/payments/queries.cjs.js +1 -0
- package/lib/pages/cms/payments/queries.es.js +30 -0
- package/lib/pages/cms/products/ProductsPage.cjs.js +1 -0
- package/lib/pages/cms/products/ProductsPage.es.js +46 -0
- package/lib/pages/cms/products/_id_/edit/EditProductPage.cjs.js +1 -0
- package/lib/pages/cms/products/_id_/edit/EditProductPage.es.js +156 -0
- package/lib/pages/cms/products/actions.cjs.js +44 -0
- package/lib/pages/cms/products/actions.es.js +175 -0
- package/lib/pages/cms/products/attributes/AttributeManagementPage.cjs.js +1 -0
- package/lib/pages/cms/products/attributes/AttributeManagementPage.es.js +48 -0
- package/lib/pages/cms/products/attributes/components/AttributeManager.cjs.js +1 -0
- package/lib/pages/cms/products/attributes/components/AttributeManager.es.js +291 -0
- package/lib/pages/cms/products/categories/CategoryManagementPage.cjs.js +1 -0
- package/lib/pages/cms/products/categories/CategoryManagementPage.es.js +36 -0
- package/lib/pages/cms/products/categories/components/CategoryManager.cjs.js +1 -0
- package/lib/pages/cms/products/categories/components/CategoryManager.es.js +263 -0
- package/lib/pages/cms/products/components/CopyProductFromLanguage.cjs.js +1 -0
- package/lib/pages/cms/products/components/CopyProductFromLanguage.es.js +114 -0
- package/lib/pages/cms/products/components/CurrencyPriceFields.cjs.js +1 -0
- package/lib/pages/cms/products/components/CurrencyPriceFields.es.js +107 -0
- package/lib/pages/cms/products/components/DeleteProductButton.cjs.js +1 -0
- package/lib/pages/cms/products/components/DeleteProductButton.es.js +48 -0
- package/lib/pages/cms/products/components/FreemiusPricingDashboard.cjs.js +1 -0
- package/lib/pages/cms/products/components/FreemiusPricingDashboard.es.js +86 -0
- package/lib/pages/cms/products/components/ProductCategorySelector.cjs.js +1 -0
- package/lib/pages/cms/products/components/ProductCategorySelector.es.js +160 -0
- package/lib/pages/cms/products/components/ProductForm.cjs.js +1 -0
- package/lib/pages/cms/products/components/ProductForm.es.js +702 -0
- package/lib/pages/cms/products/components/ProductMediaManager.cjs.js +1 -0
- package/lib/pages/cms/products/components/ProductMediaManager.es.js +104 -0
- package/lib/pages/cms/products/components/ProductsBulkTable.cjs.js +1 -0
- package/lib/pages/cms/products/components/ProductsBulkTable.es.js +228 -0
- package/lib/pages/cms/products/components/SaleScheduleFields.cjs.js +1 -0
- package/lib/pages/cms/products/components/SaleScheduleFields.es.js +137 -0
- package/lib/pages/cms/products/components/SyncFreemiusButton.cjs.js +1 -0
- package/lib/pages/cms/products/components/SyncFreemiusButton.es.js +36 -0
- package/lib/pages/cms/products/components/SyncFreemiusPricingButton.cjs.js +1 -0
- package/lib/pages/cms/products/components/SyncFreemiusPricingButton.es.js +40 -0
- package/lib/pages/cms/products/components/VariationsEditor.cjs.js +1 -0
- package/lib/pages/cms/products/components/VariationsEditor.es.js +408 -0
- package/lib/pages/cms/products/inventory/InventoryPage.cjs.js +1 -0
- package/lib/pages/cms/products/inventory/InventoryPage.es.js +16 -0
- package/lib/pages/cms/products/inventory/InventoryTableClient.cjs.js +2 -0
- package/lib/pages/cms/products/inventory/InventoryTableClient.es.js +214 -0
- package/lib/pages/cms/products/inventory/actions.cjs.js +3 -0
- package/lib/pages/cms/products/inventory/actions.es.js +95 -0
- package/lib/pages/cms/products/new/NewProductPage.cjs.js +1 -0
- package/lib/pages/cms/products/new/NewProductPage.es.js +76 -0
- package/lib/pages/cms/products/product-price-sync.cjs.js +1 -0
- package/lib/pages/cms/products/product-price-sync.es.js +98 -0
- package/lib/pages/cms/products/server-actions.cjs.js +1 -0
- package/lib/pages/cms/products/server-actions.es.js +193 -0
- package/lib/pages/cms/shipping/ShippingPage.cjs.js +5 -0
- package/lib/pages/cms/shipping/ShippingPage.es.js +211 -0
- package/lib/pages/cms/shipping/components/RateForm.cjs.js +1 -0
- package/lib/pages/cms/shipping/components/RateForm.es.js +441 -0
- package/lib/pages/cms/shipping/components/ZoneForm.cjs.js +1 -0
- package/lib/pages/cms/shipping/components/ZoneForm.es.js +228 -0
- package/lib/pages/cms/shipping/server-actions.cjs.js +1 -0
- package/lib/pages/cms/shipping/server-actions.es.js +159 -0
- package/lib/pages/cms/taxes/TaxesPage.cjs.js +1 -0
- package/lib/pages/cms/taxes/TaxesPage.es.js +172 -0
- package/lib/pages/cms/taxes/actions.cjs.js +1 -0
- package/lib/pages/cms/taxes/actions.es.js +57 -0
- package/lib/pages/cms/taxes/components/TaxRateForm.cjs.js +1 -0
- package/lib/pages/cms/taxes/components/TaxRateForm.es.js +100 -0
- package/lib/product-actions.cjs.js +237 -0
- package/lib/product-actions.es.js +524 -0
- package/lib/product-context.cjs.js +1 -0
- package/lib/product-context.es.js +16 -0
- package/lib/product-schema.cjs.js +1 -0
- package/lib/product-schema.es.js +134 -0
- package/lib/providers/freemius.cjs.js +5 -0
- package/lib/providers/freemius.es.js +538 -0
- package/lib/providers/stripe.cjs.js +1 -0
- package/lib/providers/stripe.es.js +473 -0
- package/lib/server-actions/coupon-actions.cjs.js +1 -0
- package/lib/server-actions/coupon-actions.es.js +23 -0
- package/lib/server-actions/customer-actions.cjs.js +1 -0
- package/lib/server-actions/customer-actions.es.js +30 -0
- package/lib/server-actions/product-actions.cjs.js +1 -0
- package/lib/server-actions/product-actions.es.js +16 -0
- package/lib/server-actions/shipping-actions.cjs.js +1 -0
- package/lib/server-actions/shipping-actions.es.js +27 -0
- package/lib/server-actions/tax-actions.cjs.js +1 -0
- package/lib/server-actions/tax-actions.es.js +40 -0
- package/lib/shared-inventory.cjs.js +15 -0
- package/lib/shared-inventory.es.js +171 -0
- package/lib/shipping/resolver.cjs.js +7 -0
- package/lib/shipping/resolver.es.js +62 -0
- package/lib/shipping-rate-currency.cjs.js +1 -0
- package/lib/shipping-rate-currency.es.js +72 -0
- package/lib/states.cjs.js +1 -0
- package/lib/states.es.js +127 -0
- package/lib/stripe/checkout.cjs.js +1 -0
- package/lib/stripe/checkout.es.js +182 -0
- package/lib/stripe/client.cjs.js +1 -0
- package/lib/stripe/client.es.js +7 -0
- package/lib/stripe/order-sync.cjs.js +1 -0
- package/lib/stripe/order-sync.es.js +130 -0
- package/lib/stripe/webhooks.cjs.js +1 -0
- package/lib/stripe/webhooks.es.js +30 -0
- package/lib/tax-calculation.cjs.js +1 -0
- package/lib/tax-calculation.es.js +101 -0
- package/lib/trials.cjs.js +1 -0
- package/lib/trials.es.js +29 -0
- package/lib/types.cjs.js +1 -0
- package/lib/types.es.js +33 -0
- package/lib/use-cart.cjs.js +1 -0
- package/lib/use-cart.es.js +44 -0
- package/lib/variation-utils.cjs.js +1 -0
- package/lib/variation-utils.es.js +246 -0
- package/lib/zod-config.cjs.js +1 -0
- package/lib/zod-config.es.js +6 -0
- package/package.json +10 -5
- package/server.cjs.js +1 -110
- package/server.es.js +178 -6037
- package/invoice-ui-BJZfedDd.cjs +0 -332
- package/invoice-ui-GJ1ADAjn.js +0 -5759
- /package/{currency-rest-client-uolJxUkL.cjs → lib/currency-rest-client.cjs.js} +0 -0
- /package/{currency-rest-client-CwoqdgAP.js → lib/currency-rest-client.es.js} +0 -0
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import { normalizeCurrencyCode as u, getCurrencyMinorUnitFactor as g, majorUnitAmountToMinor as x, formatPrice as _, minorUnitAmountToMajor as N } from "@nextblock-cms/utils";
|
|
2
|
+
const R = [
|
|
3
|
+
"none",
|
|
4
|
+
"nearest",
|
|
5
|
+
"up",
|
|
6
|
+
"down",
|
|
7
|
+
"charm"
|
|
8
|
+
], E = {
|
|
9
|
+
AU: "AUD",
|
|
10
|
+
CA: "CAD",
|
|
11
|
+
CH: "CHF",
|
|
12
|
+
CZ: "CZK",
|
|
13
|
+
DE: "EUR",
|
|
14
|
+
DK: "DKK",
|
|
15
|
+
ES: "EUR",
|
|
16
|
+
EU: "EUR",
|
|
17
|
+
FI: "EUR",
|
|
18
|
+
FR: "EUR",
|
|
19
|
+
GB: "GBP",
|
|
20
|
+
IE: "EUR",
|
|
21
|
+
IN: "INR",
|
|
22
|
+
IT: "EUR",
|
|
23
|
+
JP: "JPY",
|
|
24
|
+
MX: "MXN",
|
|
25
|
+
NL: "EUR",
|
|
26
|
+
NO: "NOK",
|
|
27
|
+
NZ: "NZD",
|
|
28
|
+
PL: "PLN",
|
|
29
|
+
PT: "EUR",
|
|
30
|
+
SE: "SEK",
|
|
31
|
+
SG: "SGD",
|
|
32
|
+
US: "USD"
|
|
33
|
+
};
|
|
34
|
+
function y(n) {
|
|
35
|
+
return typeof n == "number" && Number.isFinite(n);
|
|
36
|
+
}
|
|
37
|
+
function P(n, e = 1) {
|
|
38
|
+
const r = typeof n == "string" ? Number.parseInt(n, 10) : n;
|
|
39
|
+
return typeof r == "number" && Number.isFinite(r) && r > 0 ? Math.max(1, Math.round(r)) : e;
|
|
40
|
+
}
|
|
41
|
+
function F(n) {
|
|
42
|
+
const e = typeof n == "string" ? Number.parseInt(n, 10) : n;
|
|
43
|
+
return typeof e == "number" && Number.isFinite(e) && e >= 0 ? Math.round(e) : null;
|
|
44
|
+
}
|
|
45
|
+
function z(n) {
|
|
46
|
+
if (typeof n == "string") {
|
|
47
|
+
const e = n.trim().toLowerCase();
|
|
48
|
+
if (R.includes(e))
|
|
49
|
+
return e;
|
|
50
|
+
}
|
|
51
|
+
return "none";
|
|
52
|
+
}
|
|
53
|
+
function l(n) {
|
|
54
|
+
const e = n || {}, r = u(
|
|
55
|
+
typeof e.code == "string" ? e.code : null
|
|
56
|
+
), t = e.is_default === !0;
|
|
57
|
+
return {
|
|
58
|
+
code: r,
|
|
59
|
+
symbol: typeof e.symbol == "string" && e.symbol.trim() ? e.symbol.trim() : r,
|
|
60
|
+
exchange_rate: t ? 1 : y(e.exchange_rate) && e.exchange_rate > 0 ? e.exchange_rate : 1,
|
|
61
|
+
is_default: t,
|
|
62
|
+
is_active: e.is_active !== !1,
|
|
63
|
+
auto_sync_product_prices: t ? !1 : e.auto_sync_product_prices === !0,
|
|
64
|
+
rounding_mode: z(e.rounding_mode),
|
|
65
|
+
rounding_increment: P(e.rounding_increment, 1),
|
|
66
|
+
rounding_charm_amount: F(e.rounding_charm_amount),
|
|
67
|
+
auto_update_exchange_rate: t ? !1 : e.auto_update_exchange_rate !== !1,
|
|
68
|
+
exchange_rate_source: typeof e.exchange_rate_source == "string" && e.exchange_rate_source.trim() ? e.exchange_rate_source.trim() : null,
|
|
69
|
+
exchange_rate_updated_at: typeof e.exchange_rate_updated_at == "string" && e.exchange_rate_updated_at.trim() ? e.exchange_rate_updated_at : null
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function C(n) {
|
|
73
|
+
return !n || typeof n != "object" || Array.isArray(n) ? {} : Object.entries(n).reduce(
|
|
74
|
+
(e, [r, t]) => {
|
|
75
|
+
const c = u(r), o = typeof t == "string" ? Number.parseFloat(t) : t;
|
|
76
|
+
return y(o) && o >= 0 && (e[c] = Math.round(o)), e;
|
|
77
|
+
},
|
|
78
|
+
{}
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
function U(n) {
|
|
82
|
+
return !n || typeof n != "object" || Array.isArray(n) ? {} : Object.entries(n).reduce(
|
|
83
|
+
(e, [r, t]) => {
|
|
84
|
+
const c = u(r), o = typeof t == "string" ? Number.parseFloat(t) : t;
|
|
85
|
+
return o === null ? (e[c] = null, e) : (y(o) && o >= 0 && (e[c] = Math.round(o)), e);
|
|
86
|
+
},
|
|
87
|
+
{}
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
function f(n) {
|
|
91
|
+
return n.map(l).find((e) => e.is_default) ?? l(n[0]) ?? l({
|
|
92
|
+
code: "USD",
|
|
93
|
+
symbol: "$",
|
|
94
|
+
exchange_rate: 1,
|
|
95
|
+
is_default: !0,
|
|
96
|
+
is_active: !0
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
function h(n) {
|
|
100
|
+
return n.reduce((e, r) => {
|
|
101
|
+
const t = l(r);
|
|
102
|
+
return e[t.code] = t, e;
|
|
103
|
+
}, {});
|
|
104
|
+
}
|
|
105
|
+
function O(n, e) {
|
|
106
|
+
const r = u(e), t = f(n);
|
|
107
|
+
return h(n)[r]?.exchange_rate ?? (r === t.code, 1);
|
|
108
|
+
}
|
|
109
|
+
function A(n) {
|
|
110
|
+
const { amount: e, currencies: r } = n, t = u(n.fromCurrencyCode), c = u(n.toCurrencyCode);
|
|
111
|
+
if (!Number.isFinite(e))
|
|
112
|
+
return 0;
|
|
113
|
+
if (t === c)
|
|
114
|
+
return Math.round(e);
|
|
115
|
+
const o = h(r), i = f(r), a = o[t]?.exchange_rate ?? (t === i.code ? 1 : i.exchange_rate), d = o[c]?.exchange_rate ?? (c === i.code ? 1 : i.exchange_rate), M = e / g(t) / a * d, p = x(M, c);
|
|
116
|
+
return n.applyRounding ? S({
|
|
117
|
+
amount: p,
|
|
118
|
+
currencyCode: c,
|
|
119
|
+
currencies: r
|
|
120
|
+
}) : p;
|
|
121
|
+
}
|
|
122
|
+
function S(n) {
|
|
123
|
+
const e = Math.max(0, Math.round(n.amount)), r = u(n.currencyCode), c = h(n.currencies)[r] ?? l(f(n.currencies)), o = P(c.rounding_increment, 1);
|
|
124
|
+
if (c.rounding_mode === "nearest")
|
|
125
|
+
return Math.round(e / o) * o;
|
|
126
|
+
if (c.rounding_mode === "up")
|
|
127
|
+
return Math.ceil(e / o) * o;
|
|
128
|
+
if (c.rounding_mode === "down")
|
|
129
|
+
return Math.floor(e / o) * o;
|
|
130
|
+
if (c.rounding_mode === "charm") {
|
|
131
|
+
const i = g(c.code), a = Math.min(
|
|
132
|
+
Math.max(c.rounding_charm_amount ?? 0, 0),
|
|
133
|
+
Math.max(i - 1, 0)
|
|
134
|
+
);
|
|
135
|
+
let s = Math.floor(e / i) * i + a;
|
|
136
|
+
return s < e && (s += i), s;
|
|
137
|
+
}
|
|
138
|
+
return e;
|
|
139
|
+
}
|
|
140
|
+
function T(n) {
|
|
141
|
+
const e = l(n);
|
|
142
|
+
if (e.rounding_mode === "nearest")
|
|
143
|
+
return `Nearest ${_(
|
|
144
|
+
e.rounding_increment ?? 1,
|
|
145
|
+
e.code
|
|
146
|
+
)}`;
|
|
147
|
+
if (e.rounding_mode === "up")
|
|
148
|
+
return `Round up to ${_(
|
|
149
|
+
e.rounding_increment ?? 1,
|
|
150
|
+
e.code
|
|
151
|
+
)}`;
|
|
152
|
+
if (e.rounding_mode === "down")
|
|
153
|
+
return `Round down to ${_(
|
|
154
|
+
e.rounding_increment ?? 1,
|
|
155
|
+
e.code
|
|
156
|
+
)}`;
|
|
157
|
+
if (e.rounding_mode === "charm") {
|
|
158
|
+
const r = e.rounding_charm_amount ?? 0;
|
|
159
|
+
return `Charm ending ${_(r, e.code)}`;
|
|
160
|
+
}
|
|
161
|
+
return `Exact conversion (${N(1, e.code).toFixed(
|
|
162
|
+
g(e.code) === 1 ? 0 : 2
|
|
163
|
+
)} step)`;
|
|
164
|
+
}
|
|
165
|
+
function k(n, e) {
|
|
166
|
+
const r = f(e);
|
|
167
|
+
return n[r.code] !== void 0 ? r.code : Object.keys(n)[0] ?? r.code;
|
|
168
|
+
}
|
|
169
|
+
function b(n) {
|
|
170
|
+
const { amountMap: e, fallbackAmount: r, currencies: t } = n, c = u(n.currencyCode), o = C(e);
|
|
171
|
+
if (o[c] !== void 0)
|
|
172
|
+
return o[c];
|
|
173
|
+
if (Object.keys(o).length > 0) {
|
|
174
|
+
const i = k(o, t), a = o[i];
|
|
175
|
+
if (a !== void 0)
|
|
176
|
+
return A({
|
|
177
|
+
amount: a,
|
|
178
|
+
fromCurrencyCode: i,
|
|
179
|
+
toCurrencyCode: c,
|
|
180
|
+
currencies: t,
|
|
181
|
+
applyRounding: !0
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
if (typeof r == "number" && Number.isFinite(r)) {
|
|
185
|
+
const i = f(t);
|
|
186
|
+
return A({
|
|
187
|
+
amount: r,
|
|
188
|
+
fromCurrencyCode: i.code,
|
|
189
|
+
toCurrencyCode: c,
|
|
190
|
+
currencies: t,
|
|
191
|
+
applyRounding: !0
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
return 0;
|
|
195
|
+
}
|
|
196
|
+
function D(n) {
|
|
197
|
+
const {
|
|
198
|
+
prices: e = {},
|
|
199
|
+
salePrices: r = {},
|
|
200
|
+
fallbackPrice: t,
|
|
201
|
+
fallbackSalePrice: c,
|
|
202
|
+
currencies: o
|
|
203
|
+
} = n, i = u(n.currencyCode), a = C(e), d = U(r), s = b({
|
|
204
|
+
amountMap: a,
|
|
205
|
+
fallbackAmount: t,
|
|
206
|
+
currencyCode: i,
|
|
207
|
+
currencies: o
|
|
208
|
+
}), m = b({
|
|
209
|
+
amountMap: C(d),
|
|
210
|
+
fallbackAmount: c,
|
|
211
|
+
currencyCode: i,
|
|
212
|
+
currencies: o
|
|
213
|
+
});
|
|
214
|
+
return {
|
|
215
|
+
currencyCode: i,
|
|
216
|
+
price: s,
|
|
217
|
+
sale_price: m > 0 && m <= s ? m : null
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
function w(n) {
|
|
221
|
+
const e = (n.now ?? /* @__PURE__ */ new Date()).getTime();
|
|
222
|
+
if (n.saleStartAt) {
|
|
223
|
+
const r = new Date(n.saleStartAt).getTime();
|
|
224
|
+
if (Number.isFinite(r) && e < r)
|
|
225
|
+
return !1;
|
|
226
|
+
}
|
|
227
|
+
if (n.saleEndAt) {
|
|
228
|
+
const r = new Date(n.saleEndAt).getTime();
|
|
229
|
+
if (Number.isFinite(r) && e >= r)
|
|
230
|
+
return !1;
|
|
231
|
+
}
|
|
232
|
+
return !0;
|
|
233
|
+
}
|
|
234
|
+
function j(n) {
|
|
235
|
+
if (!n.scheduledPriceAt)
|
|
236
|
+
return !1;
|
|
237
|
+
const e = new Date(n.scheduledPriceAt).getTime();
|
|
238
|
+
return Number.isFinite(e) ? (n.now ?? /* @__PURE__ */ new Date()).getTime() >= e : !1;
|
|
239
|
+
}
|
|
240
|
+
function v(n) {
|
|
241
|
+
const e = n.now ?? /* @__PURE__ */ new Date(), r = j({
|
|
242
|
+
scheduledPriceAt: n.scheduledPriceAt,
|
|
243
|
+
now: e
|
|
244
|
+
}), t = r ? n.scheduledPrices : n.prices, c = r ? n.scheduledPrice : n.fallbackPrice, o = w({
|
|
245
|
+
saleStartAt: n.saleStartAt,
|
|
246
|
+
saleEndAt: n.saleEndAt,
|
|
247
|
+
now: e
|
|
248
|
+
});
|
|
249
|
+
return D({
|
|
250
|
+
prices: t,
|
|
251
|
+
salePrices: o ? n.salePrices : null,
|
|
252
|
+
fallbackPrice: c,
|
|
253
|
+
fallbackSalePrice: o ? n.fallbackSalePrice : null,
|
|
254
|
+
currencyCode: n.currencyCode,
|
|
255
|
+
currencies: n.currencies
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
function L(n) {
|
|
259
|
+
const e = n.entries.map(
|
|
260
|
+
(r) => v({
|
|
261
|
+
prices: r.prices,
|
|
262
|
+
salePrices: r.sale_prices,
|
|
263
|
+
fallbackPrice: r.price,
|
|
264
|
+
fallbackSalePrice: r.sale_price,
|
|
265
|
+
saleStartAt: r.sale_start_at,
|
|
266
|
+
saleEndAt: r.sale_end_at,
|
|
267
|
+
scheduledPrice: r.scheduled_price,
|
|
268
|
+
scheduledPrices: r.scheduled_prices,
|
|
269
|
+
scheduledPriceAt: r.scheduled_price_at,
|
|
270
|
+
currencyCode: n.currencyCode,
|
|
271
|
+
currencies: n.currencies,
|
|
272
|
+
now: n.now
|
|
273
|
+
})
|
|
274
|
+
).map((r) => r.sale_price ?? r.price).filter((r) => Number.isFinite(r));
|
|
275
|
+
return e.length ? {
|
|
276
|
+
min: Math.min(...e),
|
|
277
|
+
max: Math.max(...e)
|
|
278
|
+
} : null;
|
|
279
|
+
}
|
|
280
|
+
function K(n, e) {
|
|
281
|
+
const r = f(e), t = n?.trim();
|
|
282
|
+
if (!t)
|
|
283
|
+
return r.code;
|
|
284
|
+
const o = t.replace("_", "-").split("-").map((d) => d.toUpperCase())[1];
|
|
285
|
+
if (!o)
|
|
286
|
+
return r.code;
|
|
287
|
+
const i = E[o];
|
|
288
|
+
return i && new Set(e.map((d) => u(d.code))).has(i) ? i : r.code;
|
|
289
|
+
}
|
|
290
|
+
function $(n) {
|
|
291
|
+
return n.map(l).sort((e, r) => e.is_default !== r.is_default ? e.is_default ? -1 : 1 : u(e.code).localeCompare(u(r.code)));
|
|
292
|
+
}
|
|
293
|
+
export {
|
|
294
|
+
R as CURRENCY_ROUNDING_MODES,
|
|
295
|
+
S as applyCurrencyRounding,
|
|
296
|
+
A as convertMinorUnitAmount,
|
|
297
|
+
T as describeCurrencyRoundingRule,
|
|
298
|
+
h as getCurrencyLookup,
|
|
299
|
+
f as getDefaultCurrency,
|
|
300
|
+
O as getExchangeRateForCurrency,
|
|
301
|
+
K as inferCurrencyCodeFromLocale,
|
|
302
|
+
w as isSaleWindowActive,
|
|
303
|
+
j as isScheduledPriceDue,
|
|
304
|
+
l as normalizeCurrencyRecord,
|
|
305
|
+
z as normalizeCurrencyRoundingMode,
|
|
306
|
+
C as normalizePriceMap,
|
|
307
|
+
U as normalizeSalePriceMap,
|
|
308
|
+
v as resolveEffectivePriceForCurrency,
|
|
309
|
+
D as resolvePriceForCurrency,
|
|
310
|
+
L as resolvePriceRangeForCurrency,
|
|
311
|
+
$ as sortCurrencies
|
|
312
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("@nextblock-cms/db/server"),w=require("./customer.cjs.js");function a(e){const s=e?.trim();return s||null}function p(e){return e?w.normalizeCustomerAddress({company_name:e.company_name,recipient_name:e.recipient_name,line1:e.line1,line2:e.line2,city:e.city,state:e.state,postal_code:e.postal_code,country_code:e.country_code}):null}function _(e,s){return e?.find(t=>t.address_type===s&&t.is_default)??e?.find(t=>t.address_type===s)??null}async function g(e,s,t,o){const r=w.normalizeCustomerAddress(o),{data:i,error:l}=await e.from("user_addresses").select("*").eq("user_id",s).eq("address_type",t).order("is_default",{ascending:!1}).order("updated_at",{ascending:!1});if(l)throw new Error(l.message);const d=i?.[0]??null,c=(i??[]).slice(1).map(n=>n.id);if(!r){if(i?.length){const n=i.map(h=>h.id),{error:m}=await e.from("user_addresses").delete().in("id",n);if(m)throw new Error(m.message)}return}const f={user_id:s,address_type:t,is_default:!0,company_name:r.company_name??null,recipient_name:r.recipient_name??null,line1:r.line1??null,line2:r.line2??null,city:r.city??null,state:r.state??null,postal_code:r.postal_code??null,country_code:r.country_code??null,updated_at:new Date().toISOString()};if(d){const{error:n}=await e.from("user_addresses").update(f).eq("id",d.id);if(n)throw new Error(n.message)}else{const{error:n}=await e.from("user_addresses").insert(f);if(n)throw new Error(n.message)}if(c.length){const{error:n}=await e.from("user_addresses").delete().in("id",c);if(n)throw new Error(n.message)}}async function y(e,s){const t=s??u.createClient(),{data:o,error:r}=await t.from("user_addresses").select("*").eq("user_id",e).in("address_type",["billing","shipping"]).order("is_default",{ascending:!1}).order("updated_at",{ascending:!1});if(r)throw new Error(r.message);const i=p(_(o??[],"billing")),l=p(_(o??[],"shipping"));return{billingAddress:i,shippingAddress:l}}async function A(e){const s=e.client??u.createClient();await g(s,e.userId,"billing",e.billingAddress??null),await g(s,e.userId,"shipping",e.shippingAddress??null)}async function E(e){const s=e.client??u.createClient(),t=a(e.fullName),o=a(e.phone);if(!t&&!o)return;const{data:r,error:i}=await s.from("profiles").select("full_name, phone").eq("id",e.userId).maybeSingle();if(i)throw new Error(i.message);if(!r)return;const l=a(r.full_name)||t,d=a(r.phone)||o;if(a(r.full_name)===l&&a(r.phone)===d)return;const{error:c}=await s.from("profiles").update({full_name:l,phone:d,updated_at:new Date().toISOString()}).eq("id",e.userId);if(c)throw new Error(c.message)}exports.fillMissingUserProfileCheckoutDetails=E;exports.getDefaultUserAddresses=y;exports.upsertDefaultUserAddresses=A;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { createClient as u } from "@nextblock-cms/db/server";
|
|
2
|
+
import { normalizeCustomerAddress as w } from "./customer.es.js";
|
|
3
|
+
function l(e) {
|
|
4
|
+
const n = e?.trim();
|
|
5
|
+
return n || null;
|
|
6
|
+
}
|
|
7
|
+
function p(e) {
|
|
8
|
+
return e ? w({
|
|
9
|
+
company_name: e.company_name,
|
|
10
|
+
recipient_name: e.recipient_name,
|
|
11
|
+
line1: e.line1,
|
|
12
|
+
line2: e.line2,
|
|
13
|
+
city: e.city,
|
|
14
|
+
state: e.state,
|
|
15
|
+
postal_code: e.postal_code,
|
|
16
|
+
country_code: e.country_code
|
|
17
|
+
}) : null;
|
|
18
|
+
}
|
|
19
|
+
function _(e, n) {
|
|
20
|
+
return e?.find(
|
|
21
|
+
(t) => t.address_type === n && t.is_default
|
|
22
|
+
) ?? e?.find((t) => t.address_type === n) ?? null;
|
|
23
|
+
}
|
|
24
|
+
async function g(e, n, t, i) {
|
|
25
|
+
const r = w(i), { data: o, error: a } = await e.from("user_addresses").select("*").eq("user_id", n).eq("address_type", t).order("is_default", { ascending: !1 }).order("updated_at", { ascending: !1 });
|
|
26
|
+
if (a)
|
|
27
|
+
throw new Error(a.message);
|
|
28
|
+
const d = o?.[0] ?? null, c = (o ?? []).slice(1).map((s) => s.id);
|
|
29
|
+
if (!r) {
|
|
30
|
+
if (o?.length) {
|
|
31
|
+
const s = o.map((h) => h.id), { error: m } = await e.from("user_addresses").delete().in("id", s);
|
|
32
|
+
if (m)
|
|
33
|
+
throw new Error(m.message);
|
|
34
|
+
}
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const f = {
|
|
38
|
+
user_id: n,
|
|
39
|
+
address_type: t,
|
|
40
|
+
is_default: !0,
|
|
41
|
+
company_name: r.company_name ?? null,
|
|
42
|
+
recipient_name: r.recipient_name ?? null,
|
|
43
|
+
line1: r.line1 ?? null,
|
|
44
|
+
line2: r.line2 ?? null,
|
|
45
|
+
city: r.city ?? null,
|
|
46
|
+
state: r.state ?? null,
|
|
47
|
+
postal_code: r.postal_code ?? null,
|
|
48
|
+
country_code: r.country_code ?? null,
|
|
49
|
+
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
50
|
+
};
|
|
51
|
+
if (d) {
|
|
52
|
+
const { error: s } = await e.from("user_addresses").update(f).eq("id", d.id);
|
|
53
|
+
if (s)
|
|
54
|
+
throw new Error(s.message);
|
|
55
|
+
} else {
|
|
56
|
+
const { error: s } = await e.from("user_addresses").insert(f);
|
|
57
|
+
if (s)
|
|
58
|
+
throw new Error(s.message);
|
|
59
|
+
}
|
|
60
|
+
if (c.length) {
|
|
61
|
+
const { error: s } = await e.from("user_addresses").delete().in("id", c);
|
|
62
|
+
if (s)
|
|
63
|
+
throw new Error(s.message);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async function A(e, n) {
|
|
67
|
+
const t = n ?? u(), { data: i, error: r } = await t.from("user_addresses").select("*").eq("user_id", e).in("address_type", ["billing", "shipping"]).order("is_default", { ascending: !1 }).order("updated_at", { ascending: !1 });
|
|
68
|
+
if (r)
|
|
69
|
+
throw new Error(r.message);
|
|
70
|
+
const o = p(_(i ?? [], "billing")), a = p(
|
|
71
|
+
_(i ?? [], "shipping")
|
|
72
|
+
);
|
|
73
|
+
return {
|
|
74
|
+
billingAddress: o,
|
|
75
|
+
shippingAddress: a
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
async function D(e) {
|
|
79
|
+
const n = e.client ?? u();
|
|
80
|
+
await g(
|
|
81
|
+
n,
|
|
82
|
+
e.userId,
|
|
83
|
+
"billing",
|
|
84
|
+
e.billingAddress ?? null
|
|
85
|
+
), await g(
|
|
86
|
+
n,
|
|
87
|
+
e.userId,
|
|
88
|
+
"shipping",
|
|
89
|
+
e.shippingAddress ?? null
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
async function q(e) {
|
|
93
|
+
const n = e.client ?? u(), t = l(e.fullName), i = l(e.phone);
|
|
94
|
+
if (!t && !i)
|
|
95
|
+
return;
|
|
96
|
+
const { data: r, error: o } = await n.from("profiles").select("full_name, phone").eq("id", e.userId).maybeSingle();
|
|
97
|
+
if (o)
|
|
98
|
+
throw new Error(o.message);
|
|
99
|
+
if (!r)
|
|
100
|
+
return;
|
|
101
|
+
const a = l(r.full_name) || t, d = l(r.phone) || i;
|
|
102
|
+
if (l(r.full_name) === a && l(r.phone) === d)
|
|
103
|
+
return;
|
|
104
|
+
const { error: c } = await n.from("profiles").update({
|
|
105
|
+
full_name: a,
|
|
106
|
+
phone: d,
|
|
107
|
+
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
108
|
+
}).eq("id", e.userId);
|
|
109
|
+
if (c)
|
|
110
|
+
throw new Error(c.message);
|
|
111
|
+
}
|
|
112
|
+
export {
|
|
113
|
+
q as fillMissingUserProfileCheckoutDetails,
|
|
114
|
+
A as getDefaultUserAddresses,
|
|
115
|
+
D as upsertDefaultUserAddresses
|
|
116
|
+
};
|
|
@@ -0,0 +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;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { createClient as u } from "@nextblock-cms/db/server";
|
|
2
|
+
import { getInvoicePresentationData as c } from "./invoice-server.es.js";
|
|
3
|
+
function o(t) {
|
|
4
|
+
return t ?? u();
|
|
5
|
+
}
|
|
6
|
+
async function s(t) {
|
|
7
|
+
const {
|
|
8
|
+
data: { user: e },
|
|
9
|
+
error: r
|
|
10
|
+
} = await t.auth.getUser();
|
|
11
|
+
if (r || !e)
|
|
12
|
+
throw new Error("Unauthorized");
|
|
13
|
+
return e;
|
|
14
|
+
}
|
|
15
|
+
async function p(t) {
|
|
16
|
+
const e = o(t), r = await s(e), { data: a, error: n } = await e.from("orders").select(
|
|
17
|
+
"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 ?? [];
|
|
22
|
+
}
|
|
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
|
+
"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();
|
|
27
|
+
if (i)
|
|
28
|
+
throw new Error(i.message);
|
|
29
|
+
return n ?? null;
|
|
30
|
+
}
|
|
31
|
+
async function f(t, e) {
|
|
32
|
+
const r = o(e), a = await d(t, r);
|
|
33
|
+
if (!a)
|
|
34
|
+
return null;
|
|
35
|
+
const n = a.invoice_number ? await c(t, r) : null;
|
|
36
|
+
return {
|
|
37
|
+
order: a,
|
|
38
|
+
invoice: n
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export {
|
|
42
|
+
d as getCurrentCustomerOrder,
|
|
43
|
+
f as getCurrentCustomerOrderInvoice,
|
|
44
|
+
p as getCurrentCustomerOrders
|
|
45
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./countries.cjs.js"),c=require("./states.cjs.js"),m=()=>({company_name:"",recipient_name:"",line1:"",line2:"",city:"",state:"",postal_code:"",country_code:"CA"});function t(e){const n=e?.trim();return n||null}function o(e){if(!e)return null;const n={company_name:t(e.company_name),recipient_name:t(e.recipient_name),line1:t(e.line1),line2:t(e.line2),city:t(e.city),postal_code:t(e.postal_code),country_code:a.normalizeCountryCode(e.country_code)};return n.state=c.normalizeSubdivisionCode(n.country_code,t(e.state)),Object.values(n).some(Boolean)?n:null}function u(e){const n=o(e);return n?!!(n.recipient_name&&n.line1&&n.city&&n.postal_code&&n.country_code&&(!c.countryUsesStructuredStates(n.country_code)||n.state)):!1}function d(e){const n=o(e.billing),r=o(e.shipping),i=t(e.email)?.toLowerCase()??null,s=t(e.phone),l=t(e.name)??n?.recipient_name??r?.recipient_name??null;return{email:i,name:l,phone:s,billing:n,shipping:r}}function y(e,n){const r=o(e),i=o(n);return JSON.stringify(r)===JSON.stringify(i)}exports.addressesMatch=y;exports.emptyCustomerAddress=m;exports.isCustomerAddressComplete=u;exports.normalizeCustomerAddress=o;exports.normalizeOrderCustomerDetails=d;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { normalizeCountryCode as a } from "./countries.es.js";
|
|
2
|
+
import { countryUsesStructuredStates as m, normalizeSubdivisionCode as s } from "./states.es.js";
|
|
3
|
+
const y = () => ({
|
|
4
|
+
company_name: "",
|
|
5
|
+
recipient_name: "",
|
|
6
|
+
line1: "",
|
|
7
|
+
line2: "",
|
|
8
|
+
city: "",
|
|
9
|
+
state: "",
|
|
10
|
+
postal_code: "",
|
|
11
|
+
country_code: "CA"
|
|
12
|
+
});
|
|
13
|
+
function o(n) {
|
|
14
|
+
const e = n?.trim();
|
|
15
|
+
return e || null;
|
|
16
|
+
}
|
|
17
|
+
function i(n) {
|
|
18
|
+
if (!n)
|
|
19
|
+
return null;
|
|
20
|
+
const e = {
|
|
21
|
+
company_name: o(n.company_name),
|
|
22
|
+
recipient_name: o(n.recipient_name),
|
|
23
|
+
line1: o(n.line1),
|
|
24
|
+
line2: o(n.line2),
|
|
25
|
+
city: o(n.city),
|
|
26
|
+
postal_code: o(n.postal_code),
|
|
27
|
+
country_code: a(n.country_code)
|
|
28
|
+
};
|
|
29
|
+
return e.state = s(
|
|
30
|
+
e.country_code,
|
|
31
|
+
o(n.state)
|
|
32
|
+
), Object.values(e).some(Boolean) ? e : null;
|
|
33
|
+
}
|
|
34
|
+
function _(n) {
|
|
35
|
+
const e = i(n);
|
|
36
|
+
return e ? !!(e.recipient_name && e.line1 && e.city && e.postal_code && e.country_code && (!m(e.country_code) || e.state)) : !1;
|
|
37
|
+
}
|
|
38
|
+
function d(n) {
|
|
39
|
+
const e = i(n.billing), t = i(n.shipping), c = o(n.email)?.toLowerCase() ?? null, r = o(n.phone), l = o(n.name) ?? e?.recipient_name ?? t?.recipient_name ?? null;
|
|
40
|
+
return {
|
|
41
|
+
email: c,
|
|
42
|
+
name: l,
|
|
43
|
+
phone: r,
|
|
44
|
+
billing: e,
|
|
45
|
+
shipping: t
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function f(n, e) {
|
|
49
|
+
const t = i(n), c = i(e);
|
|
50
|
+
return JSON.stringify(t) === JSON.stringify(c);
|
|
51
|
+
}
|
|
52
|
+
export {
|
|
53
|
+
f as addressesMatch,
|
|
54
|
+
y as emptyCustomerAddress,
|
|
55
|
+
_ as isCustomerAddressComplete,
|
|
56
|
+
i as normalizeCustomerAddress,
|
|
57
|
+
d as normalizeOrderCustomerDetails
|
|
58
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("papaparse");function o(n,t){const e=u.unparse(n),a=new Blob([e],{type:"text/csv;charset=utf-8;"}),i=document.createElement("a");if(i.download!==void 0){const l=URL.createObjectURL(a);i.setAttribute("href",l),i.setAttribute("download",t),i.style.visibility="hidden",document.body.appendChild(i),i.click(),document.body.removeChild(i)}}function c(n){return n.map(t=>({"Order ID":t.id,Date:new Date(t.created_at).toLocaleDateString(),"Customer Name":t.customer?.full_name||t.customer_details?.name||"Guest","Customer Email":t.customer?.email||t.customer_details?.email||"N/A",Subtotal:(t.subtotal/100).toFixed(2),"Tax Amount":(t.tax_total/100).toFixed(2),"Shipping Amount":(t.shipping_total/100).toFixed(2),Total:(t.total/100).toFixed(2),Currency:t.currency.toUpperCase(),"Payment Status":t.status,"Fulfillment Status":t.status==="shipped"?"Shipped":t.status==="paid"?"Paid":t.status==="trial"?"Trial":"Pending","Payment Gateway":t.provider==="freemius"?"Freemius":"Stripe"}))}function m(n){return n.filter(t=>t.status==="paid").map(t=>{const e=t.customer_details?.shipping||t.customer_details?.billing,a=e?.country_code||"N/A",i=e?.state||"N/A",l=t.tax_details?.lines?.[0]?.rate?.display_name||"N/A",s=t.tax_details?.lines?.[0]?.rate?.percentage||0;return{Date:t.paid_at?new Date(t.paid_at).toLocaleDateString():new Date(t.created_at).toLocaleDateString(),"Order ID":t.id,Destination:`${i}, ${a}`,"Tax Rate Applied":`${s}% (${l})`,"Total Taxable Amount":(t.subtotal/100).toFixed(2),"Tax Collected":(t.tax_total/100).toFixed(2),Currency:t.currency.toUpperCase()}})}function p(n){const t={};return n.filter(e=>e.status==="paid").forEach(e=>{const a=e.currency.toUpperCase();t[a]||(t[a]={volume:0,subtotal:0,tax:0}),t[a].volume+=e.total,t[a].subtotal+=e.subtotal,t[a].tax+=e.tax_total}),Object.entries(t).map(([e,a])=>({Currency:e,"Total Transaction Volume":(a.volume/100).toFixed(2),"Total Subtotal":(a.subtotal/100).toFixed(2),"Total Tax Collected":(a.tax/100).toFixed(2)}))}exports.generateCSV=o;exports.mapGeneralSalesLedger=c;exports.mapMultiCurrencyRevenue=p;exports.mapTaxLiabilitySummary=m;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import u from "papaparse";
|
|
2
|
+
function c(n, t) {
|
|
3
|
+
const a = u.unparse(n), e = new Blob([a], { type: "text/csv;charset=utf-8;" }), i = document.createElement("a");
|
|
4
|
+
if (i.download !== void 0) {
|
|
5
|
+
const s = URL.createObjectURL(e);
|
|
6
|
+
i.setAttribute("href", s), i.setAttribute("download", t), i.style.visibility = "hidden", document.body.appendChild(i), i.click(), document.body.removeChild(i);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
function m(n) {
|
|
10
|
+
return n.map((t) => ({
|
|
11
|
+
"Order ID": t.id,
|
|
12
|
+
Date: new Date(t.created_at).toLocaleDateString(),
|
|
13
|
+
"Customer Name": t.customer?.full_name || t.customer_details?.name || "Guest",
|
|
14
|
+
"Customer Email": t.customer?.email || t.customer_details?.email || "N/A",
|
|
15
|
+
Subtotal: (t.subtotal / 100).toFixed(2),
|
|
16
|
+
"Tax Amount": (t.tax_total / 100).toFixed(2),
|
|
17
|
+
"Shipping Amount": (t.shipping_total / 100).toFixed(2),
|
|
18
|
+
Total: (t.total / 100).toFixed(2),
|
|
19
|
+
Currency: t.currency.toUpperCase(),
|
|
20
|
+
"Payment Status": t.status,
|
|
21
|
+
"Fulfillment Status": t.status === "shipped" ? "Shipped" : t.status === "paid" ? "Paid" : t.status === "trial" ? "Trial" : "Pending",
|
|
22
|
+
"Payment Gateway": t.provider === "freemius" ? "Freemius" : "Stripe"
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
function p(n) {
|
|
26
|
+
return n.filter((t) => t.status === "paid").map((t) => {
|
|
27
|
+
const a = t.customer_details?.shipping || t.customer_details?.billing, e = a?.country_code || "N/A", i = a?.state || "N/A", s = t.tax_details?.lines?.[0]?.rate?.display_name || "N/A", l = t.tax_details?.lines?.[0]?.rate?.percentage || 0;
|
|
28
|
+
return {
|
|
29
|
+
Date: t.paid_at ? new Date(t.paid_at).toLocaleDateString() : new Date(t.created_at).toLocaleDateString(),
|
|
30
|
+
"Order ID": t.id,
|
|
31
|
+
Destination: `${i}, ${e}`,
|
|
32
|
+
"Tax Rate Applied": `${l}% (${s})`,
|
|
33
|
+
"Total Taxable Amount": (t.subtotal / 100).toFixed(2),
|
|
34
|
+
"Tax Collected": (t.tax_total / 100).toFixed(2),
|
|
35
|
+
Currency: t.currency.toUpperCase()
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function x(n) {
|
|
40
|
+
const t = {};
|
|
41
|
+
return n.filter((a) => a.status === "paid").forEach((a) => {
|
|
42
|
+
const e = a.currency.toUpperCase();
|
|
43
|
+
t[e] || (t[e] = { volume: 0, subtotal: 0, tax: 0 }), t[e].volume += a.total, t[e].subtotal += a.subtotal, t[e].tax += a.tax_total;
|
|
44
|
+
}), Object.entries(t).map(([a, e]) => ({
|
|
45
|
+
Currency: a,
|
|
46
|
+
"Total Transaction Volume": (e.volume / 100).toFixed(2),
|
|
47
|
+
"Total Subtotal": (e.subtotal / 100).toFixed(2),
|
|
48
|
+
"Total Tax Collected": (e.tax / 100).toFixed(2)
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
c as generateCSV,
|
|
53
|
+
m as mapGeneralSalesLedger,
|
|
54
|
+
x as mapMultiCurrencyRevenue,
|
|
55
|
+
p as mapTaxLiabilitySummary
|
|
56
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./providers/stripe.cjs.js"),t=require("./providers/freemius.cjs.js");function i(e){return e==="freemius"?new t.FreemiusProvider:new r.StripeProvider}exports.getPaymentProvider=i;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("@nextblock-cms/utils"),f=require("./providers/freemius.cjs.js");function y(e){if(!e)return null;const t=new Date(e);return Number.isNaN(t.getTime())?e:t.toISOString().replace("T"," ").replace(/\.\d{3}Z$/,"")}function h(e){return e==="percent"?"percentage":"dollar"}function C(e){return f.resolveFreemiusCheckoutCredentials(e).apiKey||f.readFreemiusEnvValue("FREEMIUS_API_KEY")}async function l(e){const t=C(e.productId);if(!t)throw new Error(`Missing Freemius API bearer token for product ${e.productId}. Set FREEMIUS_API_KEY or FREEMIUS_CHECKOUT_PRODUCTS_JSON[${e.productId}].apiKey.`);const s=e.couponId?`/${e.couponId}`:"",o=await fetch(`https://api.freemius.com/v1/products/${e.productId}/coupons${s}.json`,{method:e.method,headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json",Accept:"application/json"},body:e.method==="DELETE"?void 0:JSON.stringify(e.body||{})}),n=await o.text(),r=n?JSON.parse(n):null;if(!o.ok)throw new Error(r?.message||r?.error?.message||`Freemius coupon request failed with ${o.status}`);return r}function g(e,t){return{code:e.code,discount:e.discount_type==="fixed"?w.minorUnitAmountToMajor(e.discount_amount,"USD"):e.discount_amount,discount_type:h(e.discount_type),plans:t.planIds.length>0?t.planIds.join(","):null,licenses:null,billing_cycles:null,start_date:y(e.starts_at),end_date:y(e.ends_at),redemptions_limit:e.redemption_limit??null,has_renewals_discount:!1,has_addons_discount:!1,is_one_per_user:!1,is_active:e.is_active,user_type:"all"}}async function E(e,t){if(t.provider_scope==="stripe")return[];const{data:s,error:o}=await e.from("coupon_products").select("product_id").eq("coupon_id",t.id);if(o)throw new Error(o.message);const n=(s||[]).map(c=>c.product_id);let r=e.from("products").select("id, freemius_product_id, freemius_plan_id").eq("payment_provider","freemius").not("freemius_product_id","is",null);n.length>0&&(r=r.in("id",n));const{data:u,error:i}=await r;if(i)throw new Error(i.message);const d=new Map;for(const c of u||[]){const a=String(c.freemius_product_id||"").trim();if(!a)continue;const p=d.get(a)??{freemiusProductId:a,productId:c.id,planIds:[]};n.length>0&&c.freemius_plan_id&&p.planIds.push(String(c.freemius_plan_id)),d.set(a,p)}return[...d.values()].map(c=>({...c,planIds:[...new Set(c.planIds)]}))}async function P(e,t){const{data:s}=await e.from("coupon_freemius_mappings").select("sync_status, sync_error").eq("coupon_id",t),o=s||[];if(o.length===0){await e.from("coupons").update({freemius_sync_status:"not_required",freemius_sync_error:null}).eq("id",t);return}const n=o.find(r=>r.sync_status==="failed");await e.from("coupons").update({freemius_sync_status:n?"failed":"synced",freemius_sync_error:n?.sync_error??null}).eq("id",t)}async function q(e){const{data:t,error:s}=await e.client.from("coupons").select("id, code, name, internal_note, provider_scope, discount_type, discount_amount, is_active, starts_at, ends_at, redemption_limit").eq("id",e.couponId).single();if(s||!t)return{success:!1,error:s?.message||"Coupon not found"};const o=t,n=await E(e.client,o);await e.client.from("coupons").update({freemius_sync_status:n.length>0?"pending":"not_required",freemius_sync_error:null}).eq("id",o.id);for(const r of n){const{data:u}=await e.client.from("coupon_freemius_mappings").select("id, freemius_coupon_id").eq("coupon_id",o.id).eq("freemius_product_id",r.freemiusProductId).maybeSingle(),i=g(o,r);try{const d=await l({productId:r.freemiusProductId,method:u?.freemius_coupon_id?"PUT":"POST",couponId:u?.freemius_coupon_id??null,body:i}),c=d?.coupon??d;await e.client.from("coupon_freemius_mappings").upsert({id:u?.id,coupon_id:o.id,product_id:r.productId,freemius_product_id:r.freemiusProductId,freemius_coupon_id:c?.id?String(c.id):u?.freemius_coupon_id??null,freemius_coupon_code:o.code,sync_status:"synced",sync_error:null,remote_payload:d,last_synced_at:new Date().toISOString()},{onConflict:"coupon_id,freemius_product_id"})}catch(d){await e.client.from("coupon_freemius_mappings").upsert({id:u?.id,coupon_id:o.id,product_id:r.productId,freemius_product_id:r.freemiusProductId,freemius_coupon_id:u?.freemius_coupon_id??null,freemius_coupon_code:o.code,sync_status:"failed",sync_error:d.message||"Freemius sync failed",last_synced_at:new Date().toISOString()},{onConflict:"coupon_id,freemius_product_id"})}}return await P(e.client,o.id),{success:!0,targetCount:n.length}}function F(e){const t=(e.sku||"").toUpperCase().replace(/[^A-Z0-9]/g,"");return t?`SALE${t}`.slice(0,32):`SALE${e.productId.replace(/[^A-Za-z0-9]/g,"").toUpperCase()}`.slice(0,32)}function v(e,t){if(typeof e!="number"||e<=0||typeof t!="number"||t<0||t>=e)return null;const s=Math.round((1-t/e)*100);return s<=0||s>100?null:s}async function T(e){const{data:t,error:s}=await e.client.from("products").select("id, sku, price, sale_price, sale_start_at, sale_end_at, payment_provider, freemius_product_id, freemius_plan_id").eq("id",e.productId).maybeSingle();if(s||!t)return{success:!1,error:s?.message||"Product not found"};const o=t,n=String(o.freemius_product_id||"").trim();if(o.payment_provider!=="freemius"||!n)return{success:!0,skipped:!0,reason:"not_a_freemius_product"};const r=v(o.price,o.sale_price),u=r!==null,{data:i}=await e.client.from("product_freemius_sale_coupons").select("id, freemius_coupon_id, freemius_coupon_code, discount_percent, is_active").eq("product_id",o.id).maybeSingle();if(!u&&!i?.freemius_coupon_id)return i?.id&&await e.client.from("product_freemius_sale_coupons").update({is_active:!1,updated_at:new Date().toISOString()}).eq("id",i.id),{success:!0,active:!1};const d=i?.freemius_coupon_code||F({sku:o.sku,productId:o.id}),c=o.freemius_plan_id?[String(o.freemius_plan_id)]:[],a=r??i?.discount_percent??1,p={id:o.id,code:d,name:`Scheduled sale ${o.sku||o.id}`,discount_type:"percent",discount_amount:a,is_active:u,starts_at:o.sale_start_at,ends_at:o.sale_end_at,redemption_limit:null},S={productId:o.id,planIds:c},I=g(p,S);try{const _=await l({productId:n,method:i?.freemius_coupon_id?"PUT":"POST",couponId:i?.freemius_coupon_id??null,body:I}),m=_?.coupon??_;return await e.client.from("product_freemius_sale_coupons").upsert({id:i?.id,product_id:o.id,freemius_product_id:n,freemius_plan_id:o.freemius_plan_id?String(o.freemius_plan_id):null,freemius_coupon_id:m?.id?String(m.id):i?.freemius_coupon_id??null,freemius_coupon_code:d,discount_percent:r,starts_at:o.sale_start_at,ends_at:o.sale_end_at,is_active:u,sync_status:"synced",sync_error:null,remote_payload:_,last_synced_at:new Date().toISOString()},{onConflict:"product_id"}),{success:!0,active:u,code:d}}catch(_){return await e.client.from("product_freemius_sale_coupons").upsert({id:i?.id,product_id:o.id,freemius_product_id:n,freemius_plan_id:o.freemius_plan_id?String(o.freemius_plan_id):null,freemius_coupon_id:i?.freemius_coupon_id??null,freemius_coupon_code:d,discount_percent:r,starts_at:o.sale_start_at,ends_at:o.sale_end_at,is_active:u,sync_status:"failed",sync_error:_.message||"Freemius sale coupon sync failed",last_synced_at:new Date().toISOString()},{onConflict:"product_id"}),{success:!1,error:_.message||"Freemius sale coupon sync failed"}}}async function b(e){const{data:t}=await e.client.from("coupon_freemius_mappings").select("id, freemius_product_id, freemius_coupon_id").eq("coupon_id",e.couponId).not("freemius_coupon_id","is",null);for(const s of t||[])try{await l({productId:s.freemius_product_id,couponId:s.freemius_coupon_id,method:"DELETE"}),await e.client.from("coupon_freemius_mappings").update({sync_status:"deleted",sync_error:null,updated_at:new Date().toISOString()}).eq("id",s.id)}catch(o){await e.client.from("coupon_freemius_mappings").update({sync_status:"failed",sync_error:o.message||"Freemius delete failed",updated_at:new Date().toISOString()}).eq("id",s.id)}}exports.deleteCouponFromFreemius=b;exports.syncCouponToFreemius=q;exports.syncProductSaleCouponToFreemius=T;
|