@usethrottle/quotes 0.7.0 → 0.8.0
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/README.md +11 -1
- package/dist/index.cjs +50 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -2
- package/dist/index.d.ts +15 -2
- package/dist/index.js +40 -11
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
package/dist/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// src/client.ts
|
|
2
|
+
import { formatMoney as formatMinor } from "@usethrottle/money";
|
|
3
|
+
|
|
1
4
|
// src/errors.ts
|
|
2
5
|
import { ThrottleError } from "@usethrottle/errors";
|
|
3
6
|
var ThrottleQuotesError = class extends ThrottleError {
|
|
@@ -151,7 +154,8 @@ function createQuotesClient(opts = {}) {
|
|
|
151
154
|
return new QuotesClient(opts);
|
|
152
155
|
}
|
|
153
156
|
function formatMoney(minorUnits, currency, locale) {
|
|
154
|
-
|
|
157
|
+
void locale;
|
|
158
|
+
return formatMinor(minorUnits, currency);
|
|
155
159
|
}
|
|
156
160
|
function scaleLineCharges(item, quantity) {
|
|
157
161
|
const base = item.quantity;
|
|
@@ -563,12 +567,12 @@ function cadenceNoun(cadence) {
|
|
|
563
567
|
}
|
|
564
568
|
return cadence.interval;
|
|
565
569
|
}
|
|
566
|
-
function recurringTermsLabel(terms, price,
|
|
570
|
+
function recurringTermsLabel(terms, price, money2) {
|
|
567
571
|
const quantity = price.quantity ?? 1;
|
|
568
572
|
if (terms.schedule && terms.schedule.length > 0) {
|
|
569
|
-
return `${
|
|
573
|
+
return `${money2(scheduleUnitTotal(terms.schedule) * quantity)} total \xB7 ${terms.schedule.length} payments`;
|
|
570
574
|
}
|
|
571
|
-
const each =
|
|
575
|
+
const each = money2(price.unitPrice * quantity);
|
|
572
576
|
const noun = cadenceNoun(terms);
|
|
573
577
|
const trialDays = terms.trialDays ?? 0;
|
|
574
578
|
if (trialDays > 0) return `Free for ${trialDays} day${trialDays === 1 ? "" : "s"}, then ${each} / ${noun}`;
|
|
@@ -576,6 +580,7 @@ function recurringTermsLabel(terms, price, money) {
|
|
|
576
580
|
}
|
|
577
581
|
|
|
578
582
|
// src/QuoteView.tsx
|
|
583
|
+
import { formatMoney as formatMoney2 } from "@usethrottle/money";
|
|
579
584
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
580
585
|
var row = { display: "flex", justifyContent: "space-between", gap: 16, padding: "8px 0" };
|
|
581
586
|
var muted = { color: "#666", fontSize: 13 };
|
|
@@ -657,10 +662,10 @@ function QuoteView({ token, options, onCheckout, loadingFallback, className }) {
|
|
|
657
662
|
item.description ? /* @__PURE__ */ jsx("div", { style: muted, children: item.description }) : null,
|
|
658
663
|
item.recurring ? /* @__PURE__ */ jsxs("div", { style: muted, children: [
|
|
659
664
|
"Subscription \xB7 ",
|
|
660
|
-
recurringTermsLabel(item.recurring, { unitPrice: item.unitPrice, quantity: state.quantity }, (m) =>
|
|
665
|
+
recurringTermsLabel(item.recurring, { unitPrice: item.unitPrice, quantity: state.quantity }, (m) => formatMoney2(m, currency))
|
|
661
666
|
] }) : null
|
|
662
667
|
] }),
|
|
663
|
-
/* @__PURE__ */ jsx("td", { align: "right", children:
|
|
668
|
+
/* @__PURE__ */ jsx("td", { align: "right", children: formatMoney2(item.unitPrice, currency) }),
|
|
664
669
|
/* @__PURE__ */ jsx("td", { align: "right", children: item.qtyEditable && canAct ? /* @__PURE__ */ jsx(
|
|
665
670
|
"input",
|
|
666
671
|
{
|
|
@@ -673,21 +678,21 @@ function QuoteView({ token, options, onCheckout, loadingFallback, className }) {
|
|
|
673
678
|
style: { width: 64 }
|
|
674
679
|
}
|
|
675
680
|
) : state.quantity }),
|
|
676
|
-
/* @__PURE__ */ jsx("td", { align: "right", children:
|
|
681
|
+
/* @__PURE__ */ jsx("td", { align: "right", children: formatMoney2(included ? lineDueAtAcceptance(item, state.quantity) : 0, currency) })
|
|
677
682
|
] }, item.id);
|
|
678
683
|
}) })
|
|
679
684
|
] }) : null,
|
|
680
685
|
rev ? /* @__PURE__ */ jsxs("section", { children: [
|
|
681
686
|
/* @__PURE__ */ jsxs("div", { style: row, children: [
|
|
682
687
|
/* @__PURE__ */ jsx("strong", { children: recurringKept.length > 0 ? "Due at acceptance" : "Total" }),
|
|
683
|
-
/* @__PURE__ */ jsx("strong", { children:
|
|
688
|
+
/* @__PURE__ */ jsx("strong", { children: formatMoney2(q.total, currency) })
|
|
684
689
|
] }),
|
|
685
690
|
recurringKept.length > 0 ? /* @__PURE__ */ jsxs("div", { children: [
|
|
686
691
|
/* @__PURE__ */ jsx("p", { style: muted, children: "Recurring after" }),
|
|
687
692
|
recurringKept.map((i) => /* @__PURE__ */ jsxs("p", { style: muted, children: [
|
|
688
693
|
i.name,
|
|
689
694
|
": ",
|
|
690
|
-
recurringTermsLabel(i.recurring, { unitPrice: i.unitPrice, quantity: q.selections[i.id]?.quantity ?? i.quantity }, (m) =>
|
|
695
|
+
recurringTermsLabel(i.recurring, { unitPrice: i.unitPrice, quantity: q.selections[i.id]?.quantity ?? i.quantity }, (m) => formatMoney2(m, currency))
|
|
691
696
|
] }, i.id))
|
|
692
697
|
] }) : null,
|
|
693
698
|
/* @__PURE__ */ jsx("p", { style: muted, children: termsLabel(rev.paymentTerms, rev.depositAmount, currency) }),
|
|
@@ -751,7 +756,7 @@ function QuoteView({ token, options, onCheckout, loadingFallback, className }) {
|
|
|
751
756
|
"Revision ",
|
|
752
757
|
r.revisionNumber,
|
|
753
758
|
" \u2014 ",
|
|
754
|
-
|
|
759
|
+
formatMoney2(r.total, currency),
|
|
755
760
|
r.changeSummary ? ` \xB7 ${r.changeSummary}` : ""
|
|
756
761
|
] }, r.id)) })
|
|
757
762
|
] }) : null,
|
|
@@ -815,7 +820,7 @@ function statusLabel(status) {
|
|
|
815
820
|
function termsLabel(terms, depositAmount, currency) {
|
|
816
821
|
if (terms.mode === "net_terms") return `Payment terms: Net ${terms.netN}`;
|
|
817
822
|
if (terms.mode === "deposit_balance") {
|
|
818
|
-
const dep = depositAmount != null ?
|
|
823
|
+
const dep = depositAmount != null ? formatMoney2(depositAmount, currency) : "a deposit";
|
|
819
824
|
return `${dep} due today, balance Net ${terms.balanceNetN}`;
|
|
820
825
|
}
|
|
821
826
|
return "Payment in full";
|
|
@@ -996,18 +1001,42 @@ function QuoteRequestForm({
|
|
|
996
1001
|
}
|
|
997
1002
|
);
|
|
998
1003
|
}
|
|
1004
|
+
|
|
1005
|
+
// src/index.tsx
|
|
1006
|
+
import * as money from "@usethrottle/money";
|
|
1007
|
+
import {
|
|
1008
|
+
currencySymbol,
|
|
1009
|
+
minorUnitsOf,
|
|
1010
|
+
toDecimalString,
|
|
1011
|
+
toMinor,
|
|
1012
|
+
parseMoney,
|
|
1013
|
+
moneyValue,
|
|
1014
|
+
CURRENCIES,
|
|
1015
|
+
isKnownCurrency,
|
|
1016
|
+
UnknownCurrencyError
|
|
1017
|
+
} from "@usethrottle/money";
|
|
999
1018
|
export {
|
|
1019
|
+
CURRENCIES,
|
|
1000
1020
|
QuoteRequestForm,
|
|
1001
1021
|
QuoteView,
|
|
1002
1022
|
QuotesClient,
|
|
1003
1023
|
ThrottleQuotesError,
|
|
1024
|
+
UnknownCurrencyError,
|
|
1004
1025
|
computeSelectionTotal,
|
|
1005
1026
|
createQuoteCart,
|
|
1006
1027
|
createQuotesClient,
|
|
1028
|
+
currencySymbol,
|
|
1007
1029
|
formatMoney,
|
|
1008
1030
|
isFreeTrialLine,
|
|
1031
|
+
isKnownCurrency,
|
|
1009
1032
|
lineDueAtAcceptance,
|
|
1033
|
+
minorUnitsOf,
|
|
1034
|
+
money,
|
|
1035
|
+
moneyValue,
|
|
1036
|
+
parseMoney,
|
|
1010
1037
|
scaleLineCharges,
|
|
1038
|
+
toDecimalString,
|
|
1039
|
+
toMinor,
|
|
1011
1040
|
useQuote,
|
|
1012
1041
|
useQuoteCart,
|
|
1013
1042
|
useQuoteRequestForm
|