@usethrottle/auth 0.7.0 → 0.9.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.
@@ -303,6 +303,12 @@ declare const enUS: {
303
303
  viewSubscription: string;
304
304
  payButton: string;
305
305
  billedTo: string;
306
+ /** Shown when an invoice bills less than the order, matching the PDF. */
307
+ orderTotal: string;
308
+ amountPaid: string;
309
+ waived: string;
310
+ amountDue: string;
311
+ balanceDue: string;
306
312
  /** Display copy for `invoice.status` — the wire values are paid|open|void. */
307
313
  statusLabels: {
308
314
  paid: string;
@@ -324,6 +330,11 @@ declare const enUS: {
324
330
  cancelledOn: string;
325
331
  trialEnds: string;
326
332
  installmentProgress: string;
333
+ installmentTotal: string;
334
+ installmentNext: string;
335
+ /** Spec §5: a varied schedule's dated list; dates are estimates, hence "~". */
336
+ upcomingPayments: string;
337
+ upcomingPayment: string;
327
338
  cancelButton: string;
328
339
  cancelAtPeriodEnd: string;
329
340
  cancelNow: string;
@@ -303,6 +303,12 @@ declare const enUS: {
303
303
  viewSubscription: string;
304
304
  payButton: string;
305
305
  billedTo: string;
306
+ /** Shown when an invoice bills less than the order, matching the PDF. */
307
+ orderTotal: string;
308
+ amountPaid: string;
309
+ waived: string;
310
+ amountDue: string;
311
+ balanceDue: string;
306
312
  /** Display copy for `invoice.status` — the wire values are paid|open|void. */
307
313
  statusLabels: {
308
314
  paid: string;
@@ -324,6 +330,11 @@ declare const enUS: {
324
330
  cancelledOn: string;
325
331
  trialEnds: string;
326
332
  installmentProgress: string;
333
+ installmentTotal: string;
334
+ installmentNext: string;
335
+ /** Spec §5: a varied schedule's dated list; dates are estimates, hence "~". */
336
+ upcomingPayments: string;
337
+ upcomingPayment: string;
327
338
  cancelButton: string;
328
339
  cancelAtPeriodEnd: string;
329
340
  cancelNow: string;
@@ -655,6 +655,12 @@ var enUS = {
655
655
  viewSubscription: "View subscription",
656
656
  payButton: "Pay this invoice",
657
657
  billedTo: "Billed to",
658
+ /** Shown when an invoice bills less than the order, matching the PDF. */
659
+ orderTotal: "Order total",
660
+ amountPaid: "Amount paid",
661
+ waived: "Waived",
662
+ amountDue: "Amount due",
663
+ balanceDue: "Balance due",
658
664
  /** Display copy for `invoice.status` — the wire values are paid|open|void. */
659
665
  statusLabels: { paid: "Paid", open: "Open", void: "Void" },
660
666
  downloadUnavailable: "This invoice is not available to download right now."
@@ -674,6 +680,11 @@ var enUS = {
674
680
  cancelledOn: "Cancelled on",
675
681
  trialEnds: "Trial ends",
676
682
  installmentProgress: "Payment {paid} of {total}",
683
+ installmentTotal: "{amount} total",
684
+ installmentNext: "Next {amount} on {date}",
685
+ /** Spec §5: a varied schedule's dated list; dates are estimates, hence "~". */
686
+ upcomingPayments: "Upcoming payments",
687
+ upcomingPayment: "{amount} \xB7 ~{date}",
677
688
  cancelButton: "Cancel",
678
689
  cancelAtPeriodEnd: "Cancel at period end",
679
690
  cancelNow: "Cancel immediately",
@@ -3542,6 +3553,9 @@ function InvoiceDetail(props) {
3542
3553
  /* @__PURE__ */ jsx40(PanelState, { resource, isEmpty: (i) => i === null, emptyTitle: t.invoices.empty, skeletonRows: 4, children: (invoice) => {
3543
3554
  const money = (v) => formatMoney(v, invoice.currency, locale);
3544
3555
  const lines = invoice.lineItems ?? [];
3556
+ const partOfOrder = invoice.orderTotal != null;
3557
+ const isDepositReceipt = partOfOrder && invoice.balanceDue != null;
3558
+ const headlineLabel = !partOfOrder ? t.invoices.total : isDepositReceipt ? t.invoices.amountPaid : t.invoices.amountDue;
3545
3559
  return /* @__PURE__ */ jsxs30("div", { ...a.el("invoiceDetail.layout", "throttle-detail"), children: [
3546
3560
  /* @__PURE__ */ jsxs30("div", { ...a.el("invoiceDetail.main", "throttle-detail__main"), children: [
3547
3561
  /* @__PURE__ */ jsxs30("div", { className: "throttle-detail__section", children: [
@@ -3575,10 +3589,14 @@ function InvoiceDetail(props) {
3575
3589
  ] }),
3576
3590
  /* @__PURE__ */ jsxs30("aside", { ...a.el("invoiceDetail.rail", "throttle-detail__rail"), children: [
3577
3591
  /* @__PURE__ */ jsxs30("div", { className: "throttle-detail__section", children: [
3578
- /* @__PURE__ */ jsx40("span", { className: "throttle-detail__label", children: t.invoices.total }),
3592
+ /* @__PURE__ */ jsx40("span", { className: "throttle-detail__label", children: headlineLabel }),
3579
3593
  /* @__PURE__ */ jsx40("span", { className: "throttle-detail__headline", children: money(invoice.total) })
3580
3594
  ] }),
3581
3595
  /* @__PURE__ */ jsxs30("div", { ...a.el("invoiceDetail.totals", "throttle-totals"), children: [
3596
+ partOfOrder ? /* @__PURE__ */ jsx40(Line2, { label: t.invoices.orderTotal, value: money(invoice.orderTotal) }) : null,
3597
+ partOfOrder && invoice.amountPaid ? /* @__PURE__ */ jsx40(Line2, { label: t.invoices.amountPaid, value: `-${money(invoice.amountPaid)}` }) : null,
3598
+ partOfOrder && invoice.compWaived ? /* @__PURE__ */ jsx40(Line2, { label: t.invoices.waived, value: `-${money(invoice.compWaived)}` }) : null,
3599
+ isDepositReceipt && invoice.balanceDue ? /* @__PURE__ */ jsx40(Line2, { label: t.invoices.balanceDue, value: money(invoice.balanceDue) }) : null,
3582
3600
  invoice.dueAt ? /* @__PURE__ */ jsx40(Line2, { label: t.invoices.due, value: formatDate(invoice.dueAt, locale) }) : null,
3583
3601
  invoice.periodStart && invoice.periodEnd ? /* @__PURE__ */ jsx40(
3584
3602
  Line2,
@@ -3737,6 +3755,18 @@ function isIntervalUnit(value) {
3737
3755
  return typeof value === "string" && INTERVAL_UNITS.includes(value);
3738
3756
  }
3739
3757
 
3758
+ // ../core-cadence/src/schedule.ts
3759
+ function isVariedSchedule(rows) {
3760
+ if (!rows || rows.length === 0) return false;
3761
+ return rows.some(
3762
+ (r, i) => r.discount !== 0 || r.amount !== rows[0].amount || i > 1 && (r.intervalUnit !== rows[1].intervalUnit || r.intervalCount !== rows[1].intervalCount)
3763
+ );
3764
+ }
3765
+ function upcomingSchedulePayments(rows) {
3766
+ if (!rows || !isVariedSchedule(rows)) return [];
3767
+ return rows.filter((r) => r.status !== "paid" && r.dueAt != null);
3768
+ }
3769
+
3740
3770
  // ../core-cadence/src/labels.ts
3741
3771
  var NAMED_NOUN = {
3742
3772
  weekly: "week",
@@ -3752,6 +3782,10 @@ function cadenceNoun(cadence) {
3752
3782
  }
3753
3783
  return cadence.interval;
3754
3784
  }
3785
+ function scheduleDeal(sub) {
3786
+ if (!sub.paymentSchedule || sub.scheduleTotal == null || !isVariedSchedule(sub.paymentSchedule)) return null;
3787
+ return { total: sub.scheduleTotal, payments: sub.paymentSchedule.length };
3788
+ }
3755
3789
 
3756
3790
  // src/react/components/account/SubscriptionsPanel.tsx
3757
3791
  import { Fragment as Fragment8, jsx as jsx42, jsxs as jsxs32 } from "react/jsx-runtime";
@@ -3778,7 +3812,20 @@ function SubscriptionsPanel(props) {
3778
3812
  await run(fn);
3779
3813
  })();
3780
3814
  };
3781
- const priceLabel = (sub) => `${formatMoney(sub.amount, sub.currency, locale)} / ${cadenceNoun(sub)}${sub.quantity > 1 ? ` \xD7 ${sub.quantity}` : ""}`;
3815
+ const priceLabel = (sub) => {
3816
+ const deal = scheduleDeal(sub);
3817
+ return deal ? t.subscriptions.installmentTotal.replace("{amount}", formatMoney(deal.total, sub.currency, locale)) : `${formatMoney(sub.amount, sub.currency, locale)} / ${cadenceNoun(sub)}${sub.quantity > 1 ? ` \xD7 ${sub.quantity}` : ""}`;
3818
+ };
3819
+ const nextPaymentLabel = (sub) => {
3820
+ if (!isVariedSchedule(sub.paymentSchedule) || !sub.paymentSchedule || sub.nextPaymentAmount == null) return null;
3821
+ const upcoming = sub.paymentSchedule.find((r) => r.status !== "paid");
3822
+ return t.subscriptions.installmentNext.replace("{amount}", formatMoney(sub.nextPaymentAmount, sub.currency, locale)).replace("{date}", formatDate(upcoming?.dueAt ?? sub.currentPeriodEnd, locale));
3823
+ };
3824
+ const upcomingList = (sub) => {
3825
+ const upcoming = upcomingSchedulePayments(sub.paymentSchedule);
3826
+ if (upcoming.length === 0) return null;
3827
+ return /* @__PURE__ */ jsx42("ul", { className: "throttle-muted", "aria-label": t.subscriptions.upcomingPayments, children: upcoming.map((r) => /* @__PURE__ */ jsx42("li", { children: t.subscriptions.upcomingPayment.replace("{amount}", formatMoney(r.net, sub.currency, locale)).replace("{date}", formatDate(r.dueAt, locale)) }, r.dueAt)) });
3828
+ };
3782
3829
  const renewsLabel = (sub) => formatDate(
3783
3830
  sub.status === "completed" ? sub.completedAt ?? sub.currentPeriodEnd : sub.status === "cancelled" ? sub.cancelledAt ?? sub.currentPeriodEnd : sub.currentPeriodEnd,
3784
3831
  locale
@@ -3860,7 +3907,9 @@ function SubscriptionsPanel(props) {
3860
3907
  columns: [
3861
3908
  { key: "plan", label: t.subscriptions.columnPlan, render: (sub) => /* @__PURE__ */ jsxs32(Fragment8, { children: [
3862
3909
  sub.planName ?? sub.planReference,
3863
- sub.totalPayments != null ? /* @__PURE__ */ jsx42("div", { className: "throttle-muted", children: t.subscriptions.installmentProgress.replace("{paid}", String(Math.min(sub.paymentsMade ?? 0, sub.totalPayments))).replace("{total}", String(sub.totalPayments)) }) : null
3910
+ sub.totalPayments != null ? /* @__PURE__ */ jsx42("div", { className: "throttle-muted", children: t.subscriptions.installmentProgress.replace("{paid}", String(Math.min(sub.paymentsMade ?? 0, sub.totalPayments))).replace("{total}", String(sub.totalPayments)) }) : null,
3911
+ nextPaymentLabel(sub) ? /* @__PURE__ */ jsx42("div", { className: "throttle-muted", children: nextPaymentLabel(sub) }) : null,
3912
+ upcomingList(sub)
3864
3913
  ] }) },
3865
3914
  { key: "price", label: t.subscriptions.columnPrice, render: (sub) => /* @__PURE__ */ jsx42("span", { className: "throttle-table__money", children: priceLabel(sub) }) },
3866
3915
  { key: "renews", label: t.subscriptions.columnRenews, render: (sub) => renewsLabel(sub) },
@@ -3878,12 +3927,9 @@ function SubscriptionsPanel(props) {
3878
3927
  /* @__PURE__ */ jsx42(StatusBadge, { status: sub.status, labels: t.subscriptions.statusLabels })
3879
3928
  ] }),
3880
3929
  sub.totalPayments != null ? /* @__PURE__ */ jsx42("div", { className: "throttle-muted", children: t.subscriptions.installmentProgress.replace("{paid}", String(Math.min(sub.paymentsMade ?? 0, sub.totalPayments))).replace("{total}", String(sub.totalPayments)) }) : null,
3881
- /* @__PURE__ */ jsxs32("p", { className: "throttle-muted", children: [
3882
- formatMoney(sub.amount, sub.currency, locale),
3883
- " / ",
3884
- cadenceNoun(sub),
3885
- sub.quantity > 1 ? ` \xD7 ${sub.quantity}` : ""
3886
- ] }),
3930
+ nextPaymentLabel(sub) ? /* @__PURE__ */ jsx42("div", { className: "throttle-muted", children: nextPaymentLabel(sub) }) : null,
3931
+ upcomingList(sub),
3932
+ /* @__PURE__ */ jsx42("p", { className: "throttle-muted", children: priceLabel(sub) }),
3887
3933
  sub.status === "completed" ? /* @__PURE__ */ jsxs32("p", { className: "throttle-muted", children: [
3888
3934
  t.subscriptions.statusLabels.completed,
3889
3935
  " ",