@usethrottle/auth 0.4.0 → 0.6.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/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/react/components/index.cjs +53 -8
- package/dist/react/components/index.cjs.map +1 -1
- package/dist/react/components/index.d.cts +4 -1
- package/dist/react/components/index.d.ts +4 -1
- package/dist/react/components/index.js +64 -19
- package/dist/react/components/index.js.map +1 -1
- package/dist/react/index.d.cts +5 -0
- package/dist/react/index.d.ts +5 -0
- package/package.json +10 -9
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,11 +4383,42 @@ function InvoicesPanel(props) {
|
|
|
4380
4383
|
) }) }) });
|
|
4381
4384
|
}
|
|
4382
4385
|
|
|
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 = {
|
|
4402
|
+
weekly: "week",
|
|
4403
|
+
biweekly: "2 weeks",
|
|
4404
|
+
monthly: "month",
|
|
4405
|
+
quarterly: "quarter",
|
|
4406
|
+
yearly: "year"
|
|
4407
|
+
};
|
|
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
|
+
|
|
4383
4416
|
// src/react/components/account/SubscriptionsPanel.tsx
|
|
4384
4417
|
var import_jsx_runtime43 = require("react/jsx-runtime");
|
|
4385
4418
|
var CAN_PAUSE = /* @__PURE__ */ new Set(["active", "trialing"]);
|
|
4386
4419
|
var CAN_RESUME = /* @__PURE__ */ new Set(["paused"]);
|
|
4387
4420
|
var CAN_CANCEL2 = /* @__PURE__ */ new Set(["active", "trialing", "paused", "past_due", "unpaid"]);
|
|
4421
|
+
var isInstallment = (sub) => sub.totalPayments != null;
|
|
4388
4422
|
function SubscriptionsPanel(props) {
|
|
4389
4423
|
const a = useAppearance(props.appearance);
|
|
4390
4424
|
const scoped = useAppearanceProviderValue(props.appearance);
|
|
@@ -4404,9 +4438,12 @@ function SubscriptionsPanel(props) {
|
|
|
4404
4438
|
await run(fn);
|
|
4405
4439
|
})();
|
|
4406
4440
|
};
|
|
4407
|
-
const priceLabel = (sub) => `${formatMoney(sub.amount, sub.currency, locale)} / ${sub
|
|
4408
|
-
const renewsLabel = (sub) => formatDate(
|
|
4409
|
-
|
|
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: [
|
|
4410
4447
|
CAN_PAUSE.has(sub.status) ? /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
|
|
4411
4448
|
Button,
|
|
4412
4449
|
{
|
|
@@ -4481,7 +4518,10 @@ function SubscriptionsPanel(props) {
|
|
|
4481
4518
|
rowKey: (sub) => sub.id,
|
|
4482
4519
|
rows,
|
|
4483
4520
|
columns: [
|
|
4484
|
-
{ key: "plan", label: t.subscriptions.columnPlan, render: (sub) =>
|
|
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
|
+
] }) },
|
|
4485
4525
|
{ key: "price", label: t.subscriptions.columnPrice, render: (sub) => /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("span", { className: "throttle-table__money", children: priceLabel(sub) }) },
|
|
4486
4526
|
{ key: "renews", label: t.subscriptions.columnRenews, render: (sub) => renewsLabel(sub) },
|
|
4487
4527
|
{ key: "status", label: t.subscriptions.columnStatus, render: (sub) => /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("div", { className: "throttle-row", children: [
|
|
@@ -4497,13 +4537,18 @@ function SubscriptionsPanel(props) {
|
|
|
4497
4537
|
/* @__PURE__ */ (0, import_jsx_runtime43.jsx)("strong", { children: sub.planName ?? sub.planReference }),
|
|
4498
4538
|
/* @__PURE__ */ (0, import_jsx_runtime43.jsx)(StatusBadge, { status: sub.status, labels: t.subscriptions.statusLabels })
|
|
4499
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,
|
|
4500
4541
|
/* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("p", { className: "throttle-muted", children: [
|
|
4501
4542
|
formatMoney(sub.amount, sub.currency, locale),
|
|
4502
4543
|
" / ",
|
|
4503
|
-
sub
|
|
4544
|
+
cadenceNoun(sub),
|
|
4504
4545
|
sub.quantity > 1 ? ` \xD7 ${sub.quantity}` : ""
|
|
4505
4546
|
] }),
|
|
4506
|
-
sub.status === "
|
|
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: [
|
|
4507
4552
|
t.subscriptions.cancelledOn,
|
|
4508
4553
|
" ",
|
|
4509
4554
|
formatDate(sub.cancelledAt ?? sub.currentPeriodEnd, locale)
|