@usethrottle/auth 0.5.0 → 0.6.1

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/dist/index.d.cts CHANGED
@@ -170,6 +170,11 @@ interface Subscription {
170
170
  planReference: string;
171
171
  planName: string | null;
172
172
  interval: string;
173
+ intervalUnit: string | null;
174
+ intervalCount: number | null;
175
+ totalPayments: number | null;
176
+ paymentsMade: number;
177
+ completedAt: string | null;
173
178
  amount: number;
174
179
  quantity: number;
175
180
  currency: string;
package/dist/index.d.ts CHANGED
@@ -170,6 +170,11 @@ interface Subscription {
170
170
  planReference: string;
171
171
  planName: string | null;
172
172
  interval: string;
173
+ intervalUnit: string | null;
174
+ intervalCount: number | null;
175
+ totalPayments: number | null;
176
+ paymentsMade: number;
177
+ completedAt: string | null;
173
178
  amount: number;
174
179
  quantity: number;
175
180
  currency: string;
@@ -1225,6 +1225,7 @@ var enUS = {
1225
1225
  endsOn: "Ends on",
1226
1226
  cancelledOn: "Cancelled on",
1227
1227
  trialEnds: "Trial ends",
1228
+ installmentProgress: "Payment {paid} of {total}",
1228
1229
  cancelButton: "Cancel",
1229
1230
  cancelAtPeriodEnd: "Cancel at period end",
1230
1231
  cancelNow: "Cancel immediately",
@@ -1240,7 +1241,8 @@ var enUS = {
1240
1241
  * Display copy for `subscription.status`. Mirrors SubscriptionStatus in
1241
1242
  * `@commerce/subscriptions`; copied rather than imported because this
1242
1243
  * package has no runtime dependencies. Without it a buyer in dunning saw
1243
- * the literal pill `past_due`.
1244
+ * the literal pill `past_due`. `completed` is an installment plan that
1245
+ * has taken its last payment.
1244
1246
  */
1245
1247
  statusLabels: {
1246
1248
  active: "Active",
@@ -1248,7 +1250,8 @@ var enUS = {
1248
1250
  cancelled: "Cancelled",
1249
1251
  pastDue: "Payment overdue",
1250
1252
  trialing: "Trial",
1251
- unpaid: "Unpaid"
1253
+ unpaid: "Unpaid",
1254
+ completed: "Paid in full"
1252
1255
  }
1253
1256
  },
1254
1257
  security: {
@@ -4380,19 +4383,42 @@ function InvoicesPanel(props) {
4380
4383
  ) }) }) });
4381
4384
  }
4382
4385
 
4383
- // src/react/components/account/SubscriptionsPanel.tsx
4384
- var import_jsx_runtime43 = require("react/jsx-runtime");
4385
- var CAN_PAUSE = /* @__PURE__ */ new Set(["active", "trialing"]);
4386
- var CAN_RESUME = /* @__PURE__ */ new Set(["paused"]);
4387
- var CAN_CANCEL2 = /* @__PURE__ */ new Set(["active", "trialing", "paused", "past_due", "unpaid"]);
4388
- var INTERVAL_WORD = {
4386
+ // ../core-cadence/src/cadence.ts
4387
+ var INTERVAL_UNITS = ["hour", "day", "week", "month"];
4388
+ var NAMED_INTERVALS = ["weekly", "biweekly", "monthly", "quarterly", "yearly"];
4389
+ var INTERVAL_VALUES = [...NAMED_INTERVALS, "custom"];
4390
+ var HOUR_MS = 36e5;
4391
+ var DAY_MS = 24 * HOUR_MS;
4392
+ var WEEK_MS = 7 * DAY_MS;
4393
+ function isNamedInterval(value) {
4394
+ return typeof value === "string" && NAMED_INTERVALS.includes(value);
4395
+ }
4396
+ function isIntervalUnit(value) {
4397
+ return typeof value === "string" && INTERVAL_UNITS.includes(value);
4398
+ }
4399
+
4400
+ // ../core-cadence/src/labels.ts
4401
+ var NAMED_NOUN = {
4389
4402
  weekly: "week",
4390
4403
  biweekly: "2 weeks",
4391
4404
  monthly: "month",
4392
4405
  quarterly: "quarter",
4393
4406
  yearly: "year"
4394
4407
  };
4395
- var intervalWord = (interval) => INTERVAL_WORD[interval] ?? interval;
4408
+ function cadenceNoun(cadence) {
4409
+ if (isNamedInterval(cadence.interval)) return NAMED_NOUN[cadence.interval];
4410
+ if (isIntervalUnit(cadence.intervalUnit) && cadence.intervalCount != null) {
4411
+ return cadence.intervalCount === 1 ? cadence.intervalUnit : `${cadence.intervalCount} ${cadence.intervalUnit}s`;
4412
+ }
4413
+ return cadence.interval;
4414
+ }
4415
+
4416
+ // src/react/components/account/SubscriptionsPanel.tsx
4417
+ var import_jsx_runtime43 = require("react/jsx-runtime");
4418
+ var CAN_PAUSE = /* @__PURE__ */ new Set(["active"]);
4419
+ var CAN_RESUME = /* @__PURE__ */ new Set(["paused"]);
4420
+ var CAN_CANCEL2 = /* @__PURE__ */ new Set(["active", "trialing", "paused", "past_due", "unpaid"]);
4421
+ var isInstallment = (sub) => sub.totalPayments != null;
4396
4422
  function SubscriptionsPanel(props) {
4397
4423
  const a = useAppearance(props.appearance);
4398
4424
  const scoped = useAppearanceProviderValue(props.appearance);
@@ -4412,9 +4438,12 @@ function SubscriptionsPanel(props) {
4412
4438
  await run(fn);
4413
4439
  })();
4414
4440
  };
4415
- const priceLabel = (sub) => `${formatMoney(sub.amount, sub.currency, locale)} / ${intervalWord(sub.interval)}${sub.quantity > 1 ? ` \xD7 ${sub.quantity}` : ""}`;
4416
- const renewsLabel = (sub) => formatDate(sub.status === "cancelled" ? sub.cancelledAt ?? sub.currentPeriodEnd : sub.currentPeriodEnd, locale);
4417
- const lifecycleActions = (sub, variantFor) => /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("div", { className: "throttle-actions", children: [
4441
+ const priceLabel = (sub) => `${formatMoney(sub.amount, sub.currency, locale)} / ${cadenceNoun(sub)}${sub.quantity > 1 ? ` \xD7 ${sub.quantity}` : ""}`;
4442
+ const renewsLabel = (sub) => formatDate(
4443
+ sub.status === "completed" ? sub.completedAt ?? sub.currentPeriodEnd : sub.status === "cancelled" ? sub.cancelledAt ?? sub.currentPeriodEnd : sub.currentPeriodEnd,
4444
+ locale
4445
+ );
4446
+ const lifecycleActions = (sub, variantFor) => isInstallment(sub) ? null : /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("div", { className: "throttle-actions", children: [
4418
4447
  CAN_PAUSE.has(sub.status) ? /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4419
4448
  Button,
4420
4449
  {
@@ -4489,7 +4518,10 @@ function SubscriptionsPanel(props) {
4489
4518
  rowKey: (sub) => sub.id,
4490
4519
  rows,
4491
4520
  columns: [
4492
- { key: "plan", label: t.subscriptions.columnPlan, render: (sub) => sub.planName ?? sub.planReference },
4521
+ { key: "plan", label: t.subscriptions.columnPlan, render: (sub) => /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(import_jsx_runtime43.Fragment, { children: [
4522
+ sub.planName ?? sub.planReference,
4523
+ sub.totalPayments != null ? /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", { className: "throttle-muted", children: t.subscriptions.installmentProgress.replace("{paid}", String(Math.min(sub.paymentsMade ?? 0, sub.totalPayments))).replace("{total}", String(sub.totalPayments)) }) : null
4524
+ ] }) },
4493
4525
  { key: "price", label: t.subscriptions.columnPrice, render: (sub) => /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("span", { className: "throttle-table__money", children: priceLabel(sub) }) },
4494
4526
  { key: "renews", label: t.subscriptions.columnRenews, render: (sub) => renewsLabel(sub) },
4495
4527
  { key: "status", label: t.subscriptions.columnStatus, render: (sub) => /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("div", { className: "throttle-row", children: [
@@ -4505,13 +4537,18 @@ function SubscriptionsPanel(props) {
4505
4537
  /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("strong", { children: sub.planName ?? sub.planReference }),
4506
4538
  /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(StatusBadge, { status: sub.status, labels: t.subscriptions.statusLabels })
4507
4539
  ] }),
4540
+ sub.totalPayments != null ? /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", { className: "throttle-muted", children: t.subscriptions.installmentProgress.replace("{paid}", String(Math.min(sub.paymentsMade ?? 0, sub.totalPayments))).replace("{total}", String(sub.totalPayments)) }) : null,
4508
4541
  /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("p", { className: "throttle-muted", children: [
4509
4542
  formatMoney(sub.amount, sub.currency, locale),
4510
4543
  " / ",
4511
- intervalWord(sub.interval),
4544
+ cadenceNoun(sub),
4512
4545
  sub.quantity > 1 ? ` \xD7 ${sub.quantity}` : ""
4513
4546
  ] }),
4514
- sub.status === "cancelled" ? /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("p", { className: "throttle-muted", children: [
4547
+ sub.status === "completed" ? /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("p", { className: "throttle-muted", children: [
4548
+ t.subscriptions.statusLabels.completed,
4549
+ " ",
4550
+ formatDate(sub.completedAt ?? sub.currentPeriodEnd, locale)
4551
+ ] }) : sub.status === "cancelled" ? /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("p", { className: "throttle-muted", children: [
4515
4552
  t.subscriptions.cancelledOn,
4516
4553
  " ",
4517
4554
  formatDate(sub.cancelledAt ?? sub.currentPeriodEnd, locale)