@usethrottle/quotes 0.6.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 +93 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +30 -2
- package/dist/index.d.ts +30 -2
- package/dist/index.js +83 -11
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -36,7 +36,8 @@ The default markup is intentionally plain. For your own presentation, use the
|
|
|
36
36
|
hook and render whatever you like:
|
|
37
37
|
|
|
38
38
|
```tsx
|
|
39
|
-
import { useQuote
|
|
39
|
+
import { useQuote } from '@usethrottle/quotes';
|
|
40
|
+
import { formatMoney } from '@usethrottle/money';
|
|
40
41
|
|
|
41
42
|
function MyQuote({ token }: { token: string }) {
|
|
42
43
|
const { quote, total, selections, setQuantity, setSelected, accept, error } = useQuote(token);
|
|
@@ -224,6 +225,15 @@ if (item.recurring) {
|
|
|
224
225
|
the rule the server charges by. Subscription quotes must be pay-in-full: a
|
|
225
226
|
rep cannot issue one on net terms or with a deposit.
|
|
226
227
|
|
|
228
|
+
## Money
|
|
229
|
+
|
|
230
|
+
Amounts are integers in the quote's minor unit; show them with
|
|
231
|
+
`formatMoney(amount, quote.currency)` from `@usethrottle/money`. This package
|
|
232
|
+
re-exports it as the `money` namespace (`money.formatMoney`) plus the
|
|
233
|
+
`CurrencyCode` and `MoneyValue` types. The root `formatMoney(minor, currency,
|
|
234
|
+
locale?)` is deprecated: it ignores the locale and prints what
|
|
235
|
+
`@usethrottle/money` prints.
|
|
236
|
+
|
|
227
237
|
## License
|
|
228
238
|
|
|
229
239
|
MIT
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,28 +17,49 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/index.tsx
|
|
21
31
|
var index_exports = {};
|
|
22
32
|
__export(index_exports, {
|
|
33
|
+
CURRENCIES: () => import_money3.CURRENCIES,
|
|
23
34
|
QuoteRequestForm: () => QuoteRequestForm,
|
|
24
35
|
QuoteView: () => QuoteView,
|
|
25
36
|
QuotesClient: () => QuotesClient,
|
|
26
37
|
ThrottleQuotesError: () => ThrottleQuotesError,
|
|
38
|
+
UnknownCurrencyError: () => import_money3.UnknownCurrencyError,
|
|
27
39
|
computeSelectionTotal: () => computeSelectionTotal,
|
|
28
40
|
createQuoteCart: () => createQuoteCart,
|
|
29
41
|
createQuotesClient: () => createQuotesClient,
|
|
42
|
+
currencySymbol: () => import_money3.currencySymbol,
|
|
30
43
|
formatMoney: () => formatMoney,
|
|
31
44
|
isFreeTrialLine: () => isFreeTrialLine,
|
|
45
|
+
isKnownCurrency: () => import_money3.isKnownCurrency,
|
|
32
46
|
lineDueAtAcceptance: () => lineDueAtAcceptance,
|
|
47
|
+
minorUnitsOf: () => import_money3.minorUnitsOf,
|
|
48
|
+
money: () => money,
|
|
49
|
+
moneyValue: () => import_money3.moneyValue,
|
|
50
|
+
parseMoney: () => import_money3.parseMoney,
|
|
33
51
|
scaleLineCharges: () => scaleLineCharges,
|
|
52
|
+
toDecimalString: () => import_money3.toDecimalString,
|
|
53
|
+
toMinor: () => import_money3.toMinor,
|
|
34
54
|
useQuote: () => useQuote,
|
|
35
55
|
useQuoteCart: () => useQuoteCart,
|
|
36
56
|
useQuoteRequestForm: () => useQuoteRequestForm
|
|
37
57
|
});
|
|
38
58
|
module.exports = __toCommonJS(index_exports);
|
|
39
59
|
|
|
60
|
+
// src/client.ts
|
|
61
|
+
var import_money = require("@usethrottle/money");
|
|
62
|
+
|
|
40
63
|
// src/errors.ts
|
|
41
64
|
var import_errors = require("@usethrottle/errors");
|
|
42
65
|
var ThrottleQuotesError = class extends import_errors.ThrottleError {
|
|
@@ -190,7 +213,8 @@ function createQuotesClient(opts = {}) {
|
|
|
190
213
|
return new QuotesClient(opts);
|
|
191
214
|
}
|
|
192
215
|
function formatMoney(minorUnits, currency, locale) {
|
|
193
|
-
|
|
216
|
+
void locale;
|
|
217
|
+
return (0, import_money.formatMoney)(minorUnits, currency);
|
|
194
218
|
}
|
|
195
219
|
function scaleLineCharges(item, quantity) {
|
|
196
220
|
const base = item.quantity;
|
|
@@ -602,12 +626,12 @@ function cadenceNoun(cadence) {
|
|
|
602
626
|
}
|
|
603
627
|
return cadence.interval;
|
|
604
628
|
}
|
|
605
|
-
function recurringTermsLabel(terms, price,
|
|
629
|
+
function recurringTermsLabel(terms, price, money2) {
|
|
606
630
|
const quantity = price.quantity ?? 1;
|
|
607
631
|
if (terms.schedule && terms.schedule.length > 0) {
|
|
608
|
-
return `${
|
|
632
|
+
return `${money2(scheduleUnitTotal(terms.schedule) * quantity)} total \xB7 ${terms.schedule.length} payments`;
|
|
609
633
|
}
|
|
610
|
-
const each =
|
|
634
|
+
const each = money2(price.unitPrice * quantity);
|
|
611
635
|
const noun = cadenceNoun(terms);
|
|
612
636
|
const trialDays = terms.trialDays ?? 0;
|
|
613
637
|
if (trialDays > 0) return `Free for ${trialDays} day${trialDays === 1 ? "" : "s"}, then ${each} / ${noun}`;
|
|
@@ -615,6 +639,7 @@ function recurringTermsLabel(terms, price, money) {
|
|
|
615
639
|
}
|
|
616
640
|
|
|
617
641
|
// src/QuoteView.tsx
|
|
642
|
+
var import_money2 = require("@usethrottle/money");
|
|
618
643
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
619
644
|
var row = { display: "flex", justifyContent: "space-between", gap: 16, padding: "8px 0" };
|
|
620
645
|
var muted = { color: "#666", fontSize: 13 };
|
|
@@ -696,10 +721,10 @@ function QuoteView({ token, options, onCheckout, loadingFallback, className }) {
|
|
|
696
721
|
item.description ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: muted, children: item.description }) : null,
|
|
697
722
|
item.recurring ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: muted, children: [
|
|
698
723
|
"Subscription \xB7 ",
|
|
699
|
-
recurringTermsLabel(item.recurring, { unitPrice: item.unitPrice, quantity: state.quantity }, (m) => formatMoney(m, currency))
|
|
724
|
+
recurringTermsLabel(item.recurring, { unitPrice: item.unitPrice, quantity: state.quantity }, (m) => (0, import_money2.formatMoney)(m, currency))
|
|
700
725
|
] }) : null
|
|
701
726
|
] }),
|
|
702
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", { align: "right", children: formatMoney(item.unitPrice, currency) }),
|
|
727
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", { align: "right", children: (0, import_money2.formatMoney)(item.unitPrice, currency) }),
|
|
703
728
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", { align: "right", children: item.qtyEditable && canAct ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
704
729
|
"input",
|
|
705
730
|
{
|
|
@@ -712,21 +737,21 @@ function QuoteView({ token, options, onCheckout, loadingFallback, className }) {
|
|
|
712
737
|
style: { width: 64 }
|
|
713
738
|
}
|
|
714
739
|
) : state.quantity }),
|
|
715
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", { align: "right", children: formatMoney(included ? lineDueAtAcceptance(item, state.quantity) : 0, currency) })
|
|
740
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", { align: "right", children: (0, import_money2.formatMoney)(included ? lineDueAtAcceptance(item, state.quantity) : 0, currency) })
|
|
716
741
|
] }, item.id);
|
|
717
742
|
}) })
|
|
718
743
|
] }) : null,
|
|
719
744
|
rev ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { children: [
|
|
720
745
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: row, children: [
|
|
721
746
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: recurringKept.length > 0 ? "Due at acceptance" : "Total" }),
|
|
722
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: formatMoney(q.total, currency) })
|
|
747
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: (0, import_money2.formatMoney)(q.total, currency) })
|
|
723
748
|
] }),
|
|
724
749
|
recurringKept.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
|
|
725
750
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { style: muted, children: "Recurring after" }),
|
|
726
751
|
recurringKept.map((i) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { style: muted, children: [
|
|
727
752
|
i.name,
|
|
728
753
|
": ",
|
|
729
|
-
recurringTermsLabel(i.recurring, { unitPrice: i.unitPrice, quantity: q.selections[i.id]?.quantity ?? i.quantity }, (m) => formatMoney(m, currency))
|
|
754
|
+
recurringTermsLabel(i.recurring, { unitPrice: i.unitPrice, quantity: q.selections[i.id]?.quantity ?? i.quantity }, (m) => (0, import_money2.formatMoney)(m, currency))
|
|
730
755
|
] }, i.id))
|
|
731
756
|
] }) : null,
|
|
732
757
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { style: muted, children: termsLabel(rev.paymentTerms, rev.depositAmount, currency) }),
|
|
@@ -790,7 +815,7 @@ function QuoteView({ token, options, onCheckout, loadingFallback, className }) {
|
|
|
790
815
|
"Revision ",
|
|
791
816
|
r.revisionNumber,
|
|
792
817
|
" \u2014 ",
|
|
793
|
-
formatMoney(r.total, currency),
|
|
818
|
+
(0, import_money2.formatMoney)(r.total, currency),
|
|
794
819
|
r.changeSummary ? ` \xB7 ${r.changeSummary}` : ""
|
|
795
820
|
] }, r.id)) })
|
|
796
821
|
] }) : null,
|
|
@@ -854,7 +879,7 @@ function statusLabel(status) {
|
|
|
854
879
|
function termsLabel(terms, depositAmount, currency) {
|
|
855
880
|
if (terms.mode === "net_terms") return `Payment terms: Net ${terms.netN}`;
|
|
856
881
|
if (terms.mode === "deposit_balance") {
|
|
857
|
-
const dep = depositAmount != null ? formatMoney(depositAmount, currency) : "a deposit";
|
|
882
|
+
const dep = depositAmount != null ? (0, import_money2.formatMoney)(depositAmount, currency) : "a deposit";
|
|
858
883
|
return `${dep} due today, balance Net ${terms.balanceNetN}`;
|
|
859
884
|
}
|
|
860
885
|
return "Payment in full";
|
|
@@ -891,6 +916,12 @@ function QuoteRequestForm({
|
|
|
891
916
|
companyName: "",
|
|
892
917
|
phone: "",
|
|
893
918
|
buyerReference: "",
|
|
919
|
+
addressLine1: "",
|
|
920
|
+
addressLine2: "",
|
|
921
|
+
city: "",
|
|
922
|
+
stateProvince: "",
|
|
923
|
+
postalCode: "",
|
|
924
|
+
countryCode: "",
|
|
894
925
|
message: "",
|
|
895
926
|
website: ""
|
|
896
927
|
// honeypot
|
|
@@ -920,6 +951,16 @@ function QuoteRequestForm({
|
|
|
920
951
|
companyName: fields.companyName ? values.companyName || null : null,
|
|
921
952
|
phone: fields.phone ? values.phone || null : null,
|
|
922
953
|
buyerReference: fields.buyerReference ? values.buyerReference || null : null,
|
|
954
|
+
...fields.shippingAddress ? {
|
|
955
|
+
shippingAddress: {
|
|
956
|
+
addressLine1: values.addressLine1 || null,
|
|
957
|
+
addressLine2: values.addressLine2 || null,
|
|
958
|
+
city: values.city || null,
|
|
959
|
+
stateProvince: values.stateProvince || null,
|
|
960
|
+
postalCode: values.postalCode || null,
|
|
961
|
+
countryCode: values.countryCode || null
|
|
962
|
+
}
|
|
963
|
+
} : {},
|
|
923
964
|
website: values.website || null,
|
|
924
965
|
...turnstileToken ? { turnstileToken } : {}
|
|
925
966
|
}).then(() => onSubmitted?.()).catch(() => {
|
|
@@ -945,6 +986,33 @@ function QuoteRequestForm({
|
|
|
945
986
|
"Phone",
|
|
946
987
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { value: values.phone, onChange: set("phone") })
|
|
947
988
|
] }) : null,
|
|
989
|
+
fields.shippingAddress ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("fieldset", { children: [
|
|
990
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("legend", { children: "Shipping address (optional)" }),
|
|
991
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { children: [
|
|
992
|
+
"Address line 1",
|
|
993
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { value: values.addressLine1, onChange: set("addressLine1") })
|
|
994
|
+
] }),
|
|
995
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { children: [
|
|
996
|
+
"Address line 2",
|
|
997
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { value: values.addressLine2, onChange: set("addressLine2") })
|
|
998
|
+
] }),
|
|
999
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { children: [
|
|
1000
|
+
"City",
|
|
1001
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { value: values.city, onChange: set("city") })
|
|
1002
|
+
] }),
|
|
1003
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { children: [
|
|
1004
|
+
"State / province",
|
|
1005
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { value: values.stateProvince, onChange: set("stateProvince") })
|
|
1006
|
+
] }),
|
|
1007
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { children: [
|
|
1008
|
+
"Postal code",
|
|
1009
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { value: values.postalCode, onChange: set("postalCode") })
|
|
1010
|
+
] }),
|
|
1011
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { children: [
|
|
1012
|
+
"Country code (e.g. US)",
|
|
1013
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { value: values.countryCode, onChange: set("countryCode"), maxLength: 2 })
|
|
1014
|
+
] })
|
|
1015
|
+
] }) : null,
|
|
948
1016
|
fields.buyerReference ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { children: [
|
|
949
1017
|
"Your reference #",
|
|
950
1018
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { value: values.buyerReference, onChange: set("buyerReference") })
|
|
@@ -992,19 +1060,33 @@ function QuoteRequestForm({
|
|
|
992
1060
|
}
|
|
993
1061
|
);
|
|
994
1062
|
}
|
|
1063
|
+
|
|
1064
|
+
// src/index.tsx
|
|
1065
|
+
var money = __toESM(require("@usethrottle/money"), 1);
|
|
1066
|
+
var import_money3 = require("@usethrottle/money");
|
|
995
1067
|
// Annotate the CommonJS export names for ESM import in node:
|
|
996
1068
|
0 && (module.exports = {
|
|
1069
|
+
CURRENCIES,
|
|
997
1070
|
QuoteRequestForm,
|
|
998
1071
|
QuoteView,
|
|
999
1072
|
QuotesClient,
|
|
1000
1073
|
ThrottleQuotesError,
|
|
1074
|
+
UnknownCurrencyError,
|
|
1001
1075
|
computeSelectionTotal,
|
|
1002
1076
|
createQuoteCart,
|
|
1003
1077
|
createQuotesClient,
|
|
1078
|
+
currencySymbol,
|
|
1004
1079
|
formatMoney,
|
|
1005
1080
|
isFreeTrialLine,
|
|
1081
|
+
isKnownCurrency,
|
|
1006
1082
|
lineDueAtAcceptance,
|
|
1083
|
+
minorUnitsOf,
|
|
1084
|
+
money,
|
|
1085
|
+
moneyValue,
|
|
1086
|
+
parseMoney,
|
|
1007
1087
|
scaleLineCharges,
|
|
1088
|
+
toDecimalString,
|
|
1089
|
+
toMinor,
|
|
1008
1090
|
useQuote,
|
|
1009
1091
|
useQuoteCart,
|
|
1010
1092
|
useQuoteRequestForm
|