@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 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, formatMoney } from '@usethrottle/quotes';
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
- return new Intl.NumberFormat(locale, { style: "currency", currency }).format(minorUnits / 100);
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, money) {
629
+ function recurringTermsLabel(terms, price, money2) {
606
630
  const quantity = price.quantity ?? 1;
607
631
  if (terms.schedule && terms.schedule.length > 0) {
608
- return `${money(scheduleUnitTotal(terms.schedule) * quantity)} total \xB7 ${terms.schedule.length} payments`;
632
+ return `${money2(scheduleUnitTotal(terms.schedule) * quantity)} total \xB7 ${terms.schedule.length} payments`;
609
633
  }
610
- const each = money(price.unitPrice * quantity);
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";
@@ -1035,19 +1060,33 @@ function QuoteRequestForm({
1035
1060
  }
1036
1061
  );
1037
1062
  }
1063
+
1064
+ // src/index.tsx
1065
+ var money = __toESM(require("@usethrottle/money"), 1);
1066
+ var import_money3 = require("@usethrottle/money");
1038
1067
  // Annotate the CommonJS export names for ESM import in node:
1039
1068
  0 && (module.exports = {
1069
+ CURRENCIES,
1040
1070
  QuoteRequestForm,
1041
1071
  QuoteView,
1042
1072
  QuotesClient,
1043
1073
  ThrottleQuotesError,
1074
+ UnknownCurrencyError,
1044
1075
  computeSelectionTotal,
1045
1076
  createQuoteCart,
1046
1077
  createQuotesClient,
1078
+ currencySymbol,
1047
1079
  formatMoney,
1048
1080
  isFreeTrialLine,
1081
+ isKnownCurrency,
1049
1082
  lineDueAtAcceptance,
1083
+ minorUnitsOf,
1084
+ money,
1085
+ moneyValue,
1086
+ parseMoney,
1050
1087
  scaleLineCharges,
1088
+ toDecimalString,
1089
+ toMinor,
1051
1090
  useQuote,
1052
1091
  useQuoteCart,
1053
1092
  useQuoteRequestForm