nuxt-backend 0.4.0 → 0.5.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/README.md +5 -2
- package/dist/chunks/catalog.mjs +1 -1
- package/dist/chunks/doctor.mjs +4 -4
- package/dist/chunks/email-previews.mjs +1 -1
- package/dist/chunks/health.mjs +2 -2
- package/dist/chunks/index.mjs +2 -2
- package/dist/chunks/install.mjs +8 -8
- package/dist/chunks/run.mjs +1 -1
- package/dist/chunks/server.mjs +4 -4
- package/dist/cli.mjs +13 -56
- package/dist/devtools-client/index.html +1 -1
- package/dist/module.js +2 -2
- package/dist/module.json +1 -1
- package/dist/runtime/vue/components/auth/InviteRedeem.vue +4 -22
- package/dist/runtime/vue/components/auth/WaitlistStatus.vue +7 -17
- package/dist/runtime/vue/components/billing/PricingTable.vue +17 -51
- package/dist/runtime/vue/components/billing/ReferralLanding.vue +1 -2
- package/dist/runtime/vue/components/workspaces/WorkspaceBilling.vue +15 -18
- package/dist/runtime/vue/components/workspaces/WorkspaceBillingPause.vue +1 -2
- package/dist/runtime/vue/components/workspaces/WorkspaceSettings.d.vue.ts +2 -2
- package/dist/runtime/vue/components/workspaces/WorkspaceSettings.vue +9 -22
- package/dist/runtime/vue/components/workspaces/WorkspaceSettings.vue.d.ts +2 -2
- package/dist/runtime/vue/components/workspaces/workspace-billing.d.ts +12 -16
- package/dist/runtime/vue/components/workspaces/workspace-billing.js +22 -37
- package/dist/runtime/vue/composables/use-access.d.ts +18 -0
- package/dist/runtime/vue/composables/use-access.js +33 -6
- package/dist/runtime/vue/composables/use-billing-section.d.ts +115 -0
- package/dist/runtime/vue/composables/use-billing-section.js +76 -0
- package/dist/runtime/vue/composables/use-gift-form.js +7 -24
- package/dist/runtime/vue/composables/use-gift-list.d.ts +18 -1
- package/dist/runtime/vue/composables/use-gift-list.js +6 -1
- package/dist/runtime/vue/composables/use-plan-change.d.ts +148 -0
- package/dist/runtime/vue/composables/use-plan-change.js +130 -0
- package/dist/runtime/vue/composables/use-pricing.d.ts +29 -0
- package/dist/runtime/vue/composables/use-pricing.js +53 -14
- package/dist/runtime/vue/composables/use-referral-invite.d.ts +7 -0
- package/dist/runtime/vue/composables/use-referral-invite.js +4 -1
- package/dist/runtime/vue/composables/use-waitlist.d.ts +18 -0
- package/dist/runtime/vue/composables/use-waitlist.js +24 -0
- package/dist/runtime/vue/pages/pricing.vue +1 -2
- package/dist/runtime/vue/plugins/checkout-return.js +9 -2
- package/dist/runtime/vue/utils/checkout-return.d.ts +11 -1
- package/dist/runtime/vue/utils/checkout-return.js +6 -2
- package/dist/runtime/vue/utils/gift-days.d.ts +20 -0
- package/dist/runtime/vue/utils/gift-days.js +32 -0
- package/dist/runtime/vue/utils/namespace.js +7 -2
- package/dist/runtime/vue/utils/page-open.d.ts +1 -0
- package/dist/runtime/vue/utils/page-open.js +12 -0
- package/dist/runtime/vue/utils/plan-change-confirm.d.ts +38 -26
- package/dist/runtime/vue/utils/plan-change-confirm.js +25 -16
- package/dist/runtime/vue/utils/pricing-checkout.d.ts +39 -0
- package/dist/runtime/vue/utils/pricing-checkout.js +22 -0
- package/dist/runtime/vue/utils/tab-keep.d.ts +3 -1
- package/dist/runtime/vue/utils/tab-keep.js +1 -1
- package/dist/shared/{nuxt-backend.CbR37s_c.mjs → nuxt-backend.0r1vvS1c.mjs} +24 -4
- package/dist/shared/{nuxt-backend.BjQoqNIu.mjs → nuxt-backend.BvKvJ1mo.mjs} +1 -1
- package/dist/shared/nuxt-backend.DRuHg-IQ.mjs +290 -0
- package/dist/shared/{nuxt-backend.9IVxzzft.mjs → nuxt-backend.suXOnqOQ.mjs} +163 -4
- package/dist/shared/{nuxt-backend.Baxb382E.mjs → nuxt-backend.zY6UDqDu.mjs} +1 -1
- package/package.json +2 -2
- package/skills/nuxt-backend/references/api.md +3 -1
- package/skills/nuxt-backend/references/install.md +9 -3
- package/skills/nuxt-backend/references/renames.json +8 -0
- package/skills/nuxt-backend/references/surface.json +2 -0
- package/skills/nuxt-backend-billing/SKILL.md +9 -0
- package/skills/nuxt-backend-billing/references/api.md +2 -0
- package/skills/nuxt-backend-upgrade/references/upgrade.md +6 -0
- package/src/runtime/vue/components/auth/InviteRedeem.vue +5 -26
- package/src/runtime/vue/components/auth/WaitlistStatus.vue +11 -20
- package/src/runtime/vue/components/billing/PricingTable.vue +25 -82
- package/src/runtime/vue/components/billing/ReferralLanding.vue +1 -2
- package/src/runtime/vue/components/workspaces/WorkspaceBilling.vue +21 -25
- package/src/runtime/vue/components/workspaces/WorkspaceBillingPause.vue +1 -2
- package/src/runtime/vue/components/workspaces/WorkspaceSettings.vue +16 -29
- package/src/runtime/vue/pages/pricing.vue +1 -4
- package/dist/shared/nuxt-backend.BCjeoX0x.mjs +0 -119
|
@@ -38,22 +38,18 @@ const STATE_WORDS = {
|
|
|
38
38
|
const TONES = { gifted: "ok", past_due: "error", paused: "warn", canceling: "warn", changing: "warn", trialing: "ok", active: "ok" };
|
|
39
39
|
const words = computed(() => section.state.value ? STATE_WORDS[section.state.value]() : null);
|
|
40
40
|
const finishing = computed(() => props.billing.isFinishingCheckout.value);
|
|
41
|
-
const loading =
|
|
42
|
-
const failed = computed(() =>
|
|
41
|
+
const loading = section.plan.isLoading;
|
|
42
|
+
const failed = computed(() => section.plan.state.value === "error");
|
|
43
43
|
const managing = computed(() => props.billing.canManage.value);
|
|
44
44
|
const pending = (key) => view.context.value.pending === key;
|
|
45
45
|
const press = (key, action) => pending(key) ? void 0 : action();
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
const cancellable = computed(() => !gifted.value && !props.billing.cancelAtPeriodEnd.value && !props.billing.isPaused.value);
|
|
49
|
-
const portalFirst = computed(() => section.state.value === "past_due");
|
|
50
|
-
const portalLast = computed(() => !portalFirst.value && !gifted.value);
|
|
46
|
+
const keepOffered = computed(() => section.actions.value.includes("keep-gifted"));
|
|
47
|
+
const cancellable = section.plan.cancellable;
|
|
51
48
|
const cancelling = computed(() => {
|
|
52
49
|
if (props.billing.saveOffers?.value !== true) return { is: CancelConfirmGroup, props: { confirm: section.confirm } };
|
|
53
50
|
if (!section.confirm.isOpen.value) return { is: () => null, props: {} };
|
|
54
51
|
return { is: resolveComponent("CancelFlow"), props: { id: view.partId("cancel", "confirm"), onClose: () => section.confirm.close(), onCanceled: section.flowCanceled, onKept: section.flowKept } };
|
|
55
52
|
});
|
|
56
|
-
const changeCancellable = computed(() => props.billing.pendingChange.value !== null && !props.billing.cancelAtPeriodEnd.value);
|
|
57
53
|
const opens = (hook, text, toggle) => {
|
|
58
54
|
const { ref: element, ...attributes } = toggle;
|
|
59
55
|
return { hook, attributes, text, element };
|
|
@@ -63,16 +59,17 @@ const runs = (hook, key, idle, busy, action) => ({
|
|
|
63
59
|
attributes: { ...busyAttributes(pending(key)), onClick: () => press(key, action) },
|
|
64
60
|
text: pending(key) ? busy : idle
|
|
65
61
|
});
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
62
|
+
const BUTTONS = {
|
|
63
|
+
// A failed payment's portal button says what it is for.
|
|
64
|
+
"portal": () => runs("portal", "portal", section.state.value === "past_due" ? t("updatePayment") : t("portal"), t("openingPortal"), section.openPortal),
|
|
65
|
+
"resume": () => runs("resume", "resume", t("resume"), t("resuming"), section.resumePlan),
|
|
66
|
+
"uncancel": () => runs("uncancel", "uncancel", t("keepPlan"), t("keeping"), section.keepPlan),
|
|
67
|
+
"cancel-change": () => runs("cancel-change", "cancel-change", t("cancelChange"), t("cancelingChange"), section.cancelChange),
|
|
68
|
+
"change-plan": () => opens("change-plan", t("changePlan"), section.switchToggleProps()),
|
|
69
|
+
"pause": () => opens("pause", t("pause"), section.pauseToggleProps()),
|
|
70
|
+
"cancel": () => opens("cancel", t("cancel"), section.confirm.toggleProps())
|
|
71
|
+
};
|
|
72
|
+
const actions = computed(() => section.actions.value.flatMap((action) => action === "keep-gifted" ? [] : [BUTTONS[action]()]));
|
|
76
73
|
const kind = (benefit) => valueLabel(labels, "settings", "benefitKinds", benefit.kind ?? "other");
|
|
77
74
|
const detail = (benefit) => benefit.licenseKey ?? benefit.repository ?? (benefit.files === void 0 ? null : t("files", { count: benefit.files }));
|
|
78
75
|
const benefitsTitle = view.partId("benefits", "title");
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import { computed } from "vue";
|
|
3
3
|
import { busyAttributes } from "../../a11y";
|
|
4
4
|
import { closesOnEscape } from "../../utils/confirm-group";
|
|
5
|
-
import { PAUSE_MONTHS } from "./workspace-billing";
|
|
6
5
|
import { useWorkspaceSettingsView } from "./workspace-settings";
|
|
7
6
|
defineOptions({ name: "WorkspaceBillingPause" });
|
|
8
7
|
const view = useWorkspaceSettingsView("WorkspaceBillingPause");
|
|
@@ -36,7 +35,7 @@ const busy = computed(() => view.context.value.pending === "pause");
|
|
|
36
35
|
{{ t("pauseFor") }}
|
|
37
36
|
</legend>
|
|
38
37
|
<label
|
|
39
|
-
v-for="months in
|
|
38
|
+
v-for="months in section.plan.pauseLengths"
|
|
40
39
|
:key="months"
|
|
41
40
|
data-settings="pause-length"
|
|
42
41
|
>
|
|
@@ -11,9 +11,9 @@ type __VLS_Props = {
|
|
|
11
11
|
type __VLS_Slots = WorkspaceSettingsSlots;
|
|
12
12
|
declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
13
13
|
error: (_message: string) => void;
|
|
14
|
+
"workspace-created": (_workspace: Workspace) => void;
|
|
14
15
|
"plan-changed": (_productId: string) => void;
|
|
15
16
|
"topped-up": (_key: string) => void;
|
|
16
|
-
"workspace-created": (_workspace: Workspace) => void;
|
|
17
17
|
"plan-canceled": () => void;
|
|
18
18
|
"plan-uncanceled": () => void;
|
|
19
19
|
"plan-resumed": () => void;
|
|
@@ -22,9 +22,9 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {},
|
|
|
22
22
|
"workspace-switched": (_id: string) => void;
|
|
23
23
|
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
24
24
|
onError?: ((_message: string) => any) | undefined;
|
|
25
|
+
"onWorkspace-created"?: ((_workspace: Workspace) => any) | undefined;
|
|
25
26
|
"onPlan-changed"?: ((_productId: string) => any) | undefined;
|
|
26
27
|
"onTopped-up"?: ((_key: string) => any) | undefined;
|
|
27
|
-
"onWorkspace-created"?: ((_workspace: Workspace) => any) | undefined;
|
|
28
28
|
"onPlan-canceled"?: (() => any) | undefined;
|
|
29
29
|
"onPlan-uncanceled"?: (() => any) | undefined;
|
|
30
30
|
"onPlan-resumed"?: (() => any) | undefined;
|
|
@@ -4,10 +4,10 @@ import { useBackendConfig } from "../../composables/use-backend-config";
|
|
|
4
4
|
import { useBackendPagePath } from "../../composables/use-backend-page-path";
|
|
5
5
|
import { formatBillingAmount } from "../../composables/billing-format";
|
|
6
6
|
import { useBilling } from "../../composables/use-billing";
|
|
7
|
+
import { useBillingSection } from "../../composables/use-billing-section";
|
|
7
8
|
import { useCredits } from "../../composables/use-credits";
|
|
8
9
|
import { useFeatures } from "../../composables/use-features";
|
|
9
10
|
import { refusalText, useLabels } from "../../composables/use-labels";
|
|
10
|
-
import { usePricing } from "../../composables/use-pricing";
|
|
11
11
|
import { useWorkspace } from "../../composables/use-workspace";
|
|
12
12
|
import { inLocale } from "../../utils/intl";
|
|
13
13
|
import { useSettingsMessage } from "../../utils/settings-message";
|
|
@@ -39,11 +39,7 @@ const workspace = useWorkspace();
|
|
|
39
39
|
const billing = useBilling();
|
|
40
40
|
const credits = useCredits();
|
|
41
41
|
const features = useFeatures();
|
|
42
|
-
const
|
|
43
|
-
const currency = billing.subscription.value?.currency;
|
|
44
|
-
return typeof currency === "string" ? currency : void 0;
|
|
45
|
-
};
|
|
46
|
-
const pricing = usePricing({ server: false, actions: false, currency: subscriptionCurrency, enabled: () => props.sections.includes("billing") });
|
|
42
|
+
const plan = useBillingSection({ enabled: () => props.sections.includes("billing") });
|
|
47
43
|
const config = useBackendConfig();
|
|
48
44
|
const labels = useLabels("settings", () => props.labels);
|
|
49
45
|
const { t, locale } = labels;
|
|
@@ -112,31 +108,22 @@ const products = computed(() => billing.products.value ?? {});
|
|
|
112
108
|
const productName = (productId) => Object.values(products.value).find((product) => product?.id === productId)?.name;
|
|
113
109
|
const packs = computed(() => config.billing.packs.length > 0 ? config.billing.packs : Object.entries(products.value).flatMap(([key, product]) => product?.isRecurring === false && product.isArchived !== true ? [{ key }] : []));
|
|
114
110
|
function switchOptions() {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if (!price || price.archived || price.productId === current || currency !== void 0 && price.currency !== currency) return [];
|
|
122
|
-
return [{
|
|
123
|
-
key: price.productId,
|
|
124
|
-
productId: price.productId,
|
|
125
|
-
plan: t(`billedAt.${interval}`, { plan: plan.name }),
|
|
126
|
-
price: `${formatBillingAmount(price.amount, price.currency, locale.value)}${t(`period.${interval}`)}`
|
|
127
|
-
}];
|
|
128
|
-
});
|
|
129
|
-
});
|
|
111
|
+
return (plan.change.targets.value ?? []).map((target) => ({
|
|
112
|
+
key: target.productId,
|
|
113
|
+
productId: target.productId,
|
|
114
|
+
plan: t(`billedAt.${target.interval}`, { plan: target.name }),
|
|
115
|
+
price: `${formatBillingAmount(target.amount, target.currency, locale.value)}${t(`period.${target.interval}`)}`
|
|
116
|
+
}));
|
|
130
117
|
}
|
|
131
118
|
const section = createBillingSection({
|
|
132
119
|
billing,
|
|
120
|
+
plan,
|
|
133
121
|
features,
|
|
134
122
|
labels,
|
|
135
123
|
pending,
|
|
136
124
|
run,
|
|
137
125
|
partId,
|
|
138
126
|
productName,
|
|
139
|
-
giftedProduct: (plan) => products.value[plan]?.id,
|
|
140
127
|
switchOptions,
|
|
141
128
|
// One event per outcome; the union reads as each of them.
|
|
142
129
|
notify: (event, argument) => emit(event, ...argument === void 0 ? [] : [argument]),
|
|
@@ -11,9 +11,9 @@ type __VLS_Props = {
|
|
|
11
11
|
type __VLS_Slots = WorkspaceSettingsSlots;
|
|
12
12
|
declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
13
13
|
error: (_message: string) => void;
|
|
14
|
+
"workspace-created": (_workspace: Workspace) => void;
|
|
14
15
|
"plan-changed": (_productId: string) => void;
|
|
15
16
|
"topped-up": (_key: string) => void;
|
|
16
|
-
"workspace-created": (_workspace: Workspace) => void;
|
|
17
17
|
"plan-canceled": () => void;
|
|
18
18
|
"plan-uncanceled": () => void;
|
|
19
19
|
"plan-resumed": () => void;
|
|
@@ -22,9 +22,9 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {},
|
|
|
22
22
|
"workspace-switched": (_id: string) => void;
|
|
23
23
|
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
24
24
|
onError?: ((_message: string) => any) | undefined;
|
|
25
|
+
"onWorkspace-created"?: ((_workspace: Workspace) => any) | undefined;
|
|
25
26
|
"onPlan-changed"?: ((_productId: string) => any) | undefined;
|
|
26
27
|
"onTopped-up"?: ((_key: string) => any) | undefined;
|
|
27
|
-
"onWorkspace-created"?: ((_workspace: Workspace) => any) | undefined;
|
|
28
28
|
"onPlan-canceled"?: (() => any) | undefined;
|
|
29
29
|
"onPlan-uncanceled"?: (() => any) | undefined;
|
|
30
30
|
"onPlan-resumed"?: (() => any) | undefined;
|
|
@@ -1,27 +1,20 @@
|
|
|
1
1
|
import { type ComputedRef, type Ref } from 'vue';
|
|
2
2
|
import type { CancellationReason, EntitlementBenefit, UseBillingReturn } from '../../composables/use-billing.js';
|
|
3
|
+
import { type BillingSectionAction, type PlanState, type UseBillingSectionReturn } from '../../composables/use-billing-section.js';
|
|
3
4
|
import type { UseFeaturesReturn } from '../../composables/use-features.js';
|
|
4
5
|
import type { UseLabelsReturn } from '../../composables/use-labels.js';
|
|
5
6
|
import { type CancelConfirm } from '../../utils/cancel-confirm.js';
|
|
6
7
|
import { type PlanChangeConfirm, type PlanChangeTarget } from '../../utils/plan-change-confirm.js';
|
|
7
|
-
|
|
8
|
-
export declare const PAUSE_MONTHS: readonly [1, 2, 3];
|
|
8
|
+
export type { PlanState } from '../../composables/use-billing-section.js';
|
|
9
9
|
/** One price the plan can switch to: another plan, or the same plan at its other billing period. */
|
|
10
|
-
export type PlanSwitchOption = PlanChangeTarget
|
|
11
|
-
/**
|
|
12
|
-
* The states a plan can be in, in the order they are tried: the first that
|
|
13
|
-
* holds is the one shown. A plan pass gifted until its end date, a failed payment, a pause, a cancellation set for
|
|
14
|
-
* the period's end, a plan change scheduled for it, a trial, else active.
|
|
15
|
-
* The Subscriptions page lists them in this order (test/docs pins it).
|
|
16
|
-
*/
|
|
17
|
-
export declare const PLAN_STATES: readonly ["gifted", "past_due", "paused", "canceling", "changing", "trialing", "active"];
|
|
18
|
-
/** The state the plan is in: the first of {@link PLAN_STATES} that holds. */
|
|
19
|
-
export type PlanState = typeof PLAN_STATES[number];
|
|
10
|
+
export type PlanSwitchOption = Required<PlanChangeTarget>;
|
|
20
11
|
/** Kinds of benefit the billing portal holds more of: the whole key, the files, the connected account. */
|
|
21
12
|
export declare const IN_PORTAL: Set<string>;
|
|
22
13
|
/** What the section needs from `<WorkspaceSettings>`. */
|
|
23
14
|
export interface BillingSectionContext {
|
|
24
15
|
billing: UseBillingReturn;
|
|
16
|
+
/** The section's state and its rules, as an app's own reads them. */
|
|
17
|
+
plan: UseBillingSectionReturn;
|
|
25
18
|
features: UseFeaturesReturn;
|
|
26
19
|
labels: UseLabelsReturn<'settings'>;
|
|
27
20
|
/** The key of the action in flight, or `null`. */
|
|
@@ -32,9 +25,7 @@ export interface BillingSectionContext {
|
|
|
32
25
|
partId: (key: string, part: string) => string;
|
|
33
26
|
/** The plan's product name, by its id. */
|
|
34
27
|
productName: (productId: string) => string | undefined;
|
|
35
|
-
/** The
|
|
36
|
-
giftedProduct: (plan: string) => string | undefined;
|
|
37
|
-
/** The prices the plan can switch to, in the reader's words: every plan on sale at each period, but the one it is on. */
|
|
28
|
+
/** The prices the plan can switch to (`plan.change.targets`), in the section's words. */
|
|
38
29
|
switchOptions: () => PlanSwitchOption[];
|
|
39
30
|
/** Tell the component's own listener: the matching event, with its argument. */
|
|
40
31
|
notify: (event: 'plan-canceled' | 'plan-uncanceled' | 'plan-resumed' | 'change-canceled' | 'plan-changed' | 'plan-paused', argument?: unknown) => void;
|
|
@@ -54,7 +45,12 @@ export interface CancelPlanOptions {
|
|
|
54
45
|
}
|
|
55
46
|
/** The section's state and actions. */
|
|
56
47
|
export interface BillingSection {
|
|
48
|
+
/** The headless state and rules the section is built on. */
|
|
49
|
+
plan: UseBillingSectionReturn;
|
|
50
|
+
/** The running plan's state, `null` on the free plan, while it loads and once its read failed. */
|
|
57
51
|
state: ComputedRef<PlanState | null>;
|
|
52
|
+
/** What the state calls for, in the order the section offers it (`plan.actions`). */
|
|
53
|
+
actions: ComputedRef<BillingSectionAction[]>;
|
|
58
54
|
/** The plan's benefits: what it includes, each in neutral words. */
|
|
59
55
|
benefits: ComputedRef<EntitlementBenefit[]>;
|
|
60
56
|
/** The one-step cancellation. */
|
|
@@ -101,7 +97,7 @@ export interface BillingSection {
|
|
|
101
97
|
pauseOpen: Ref<boolean>;
|
|
102
98
|
/** What the button that opens and closes the pause's group carries. */
|
|
103
99
|
pauseToggleProps: () => Record<string, unknown>;
|
|
104
|
-
/** The pause's length in months, one of
|
|
100
|
+
/** The pause's length in months, one of `plan.pauseLengths`. */
|
|
105
101
|
pauseMonths: Ref<number>;
|
|
106
102
|
/** Close the pause's group, focus back on its button. */
|
|
107
103
|
closePause: () => void;
|
|
@@ -1,25 +1,17 @@
|
|
|
1
1
|
import { computed, nextTick, ref } from "vue";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { formatBillingDate } from "../../composables/billing-format.js";
|
|
3
|
+
import { PLAN_STATES } from "../../composables/use-billing-section.js";
|
|
4
4
|
import { createCancelConfirm } from "../../utils/cancel-confirm.js";
|
|
5
5
|
import { returnFocus } from "../../utils/focus-return.js";
|
|
6
|
-
import {
|
|
7
|
-
export const PAUSE_MONTHS = [1, 2, 3];
|
|
8
|
-
export const PLAN_STATES = ["gifted", "past_due", "paused", "canceling", "changing", "trialing", "active"];
|
|
6
|
+
import { createPlanChangeConfirm } from "../../utils/plan-change-confirm.js";
|
|
9
7
|
export const IN_PORTAL = /* @__PURE__ */ new Set(["license_key", "download", "community", "repository", "shared_channel"]);
|
|
10
8
|
export function createBillingSection(context) {
|
|
11
|
-
const { billing, features, labels, pending, run, partId, notify, announce } = context;
|
|
9
|
+
const { billing, plan, features, labels, pending, run, partId, notify, announce } = context;
|
|
12
10
|
const { t, locale } = labels;
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
canceling: () => billing.cancelAtPeriodEnd.value,
|
|
18
|
-
changing: () => billing.pendingChange.value !== null,
|
|
19
|
-
trialing: () => billing.isTrialing.value,
|
|
20
|
-
active: () => true
|
|
21
|
-
};
|
|
22
|
-
const state = computed(() => billing.isSubscribed.value ? PLAN_STATES.find((key) => holds[key]()) ?? "active" : null);
|
|
11
|
+
const state = computed(() => {
|
|
12
|
+
const now = plan.state.value;
|
|
13
|
+
return PLAN_STATES.includes(now) ? now : null;
|
|
14
|
+
});
|
|
23
15
|
const benefits = computed(() => features.benefits.value ?? []);
|
|
24
16
|
const stateLine = ref(null);
|
|
25
17
|
const date = (value) => formatBillingDate(value, { dateStyle: "medium" }, locale.value) || null;
|
|
@@ -33,7 +25,6 @@ export function createBillingSection(context) {
|
|
|
33
25
|
endsOn: () => date(billing.subscription.value?.currentPeriodEnd)
|
|
34
26
|
});
|
|
35
27
|
const switchOptions = computed(() => context.switchOptions());
|
|
36
|
-
const switchable = computed(() => billing.isSubscribed.value && billing.pass.value === null && !billing.cancelAtPeriodEnd.value && !billing.isPaused.value && billing.pendingChange.value === null && switchOptions.value.length > 0);
|
|
37
28
|
const switchOpen = ref(false);
|
|
38
29
|
const switchToggle = ref(null);
|
|
39
30
|
const change = createPlanChangeConfirm({
|
|
@@ -41,7 +32,7 @@ export function createBillingSection(context) {
|
|
|
41
32
|
titleTag: "h4",
|
|
42
33
|
partId: (part) => partId("change", part),
|
|
43
34
|
isBusy: () => pending.value === "switch",
|
|
44
|
-
|
|
35
|
+
change: plan.change,
|
|
45
36
|
confirm: (target) => switchPlan(target.productId),
|
|
46
37
|
t,
|
|
47
38
|
date: (value) => date(value)
|
|
@@ -60,36 +51,31 @@ export function createBillingSection(context) {
|
|
|
60
51
|
function switchPlan(productId) {
|
|
61
52
|
const option = switchOptions.value.find((entry) => entry.productId === productId);
|
|
62
53
|
const preview = billing.changeOf(productId);
|
|
63
|
-
const
|
|
54
|
+
const name = option?.plan ?? context.productName(productId) ?? t("unknownPlan");
|
|
64
55
|
return run("switch", () => t("switchingPlan"), async () => {
|
|
65
|
-
await
|
|
56
|
+
await plan.change.switchTo(productId);
|
|
66
57
|
switchOpen.value = false;
|
|
67
58
|
change.settle();
|
|
68
59
|
void nextTick(() => returnFocus(stateLine.value));
|
|
69
60
|
notify("plan-changed", productId);
|
|
70
61
|
}, () => {
|
|
71
|
-
if (preview?.applies !== "period_end") return t("switched", { plan });
|
|
62
|
+
if (preview?.applies !== "period_end") return t("switched", { plan: name });
|
|
72
63
|
const when = preview.appliesAt ? date(preview.appliesAt) : null;
|
|
73
|
-
return when ? t("switchScheduled", { plan, date: when }) : t("switchScheduledPeriod", { plan });
|
|
64
|
+
return when ? t("switchScheduled", { plan: name, date: when }) : t("switchScheduledPeriod", { plan: name });
|
|
74
65
|
});
|
|
75
66
|
}
|
|
76
|
-
const pausable = computed(() => billing.isSubscribed.value && billing.pass.value === null && !billing.cancelAtPeriodEnd.value && !billing.isPaused.value && !billing.isPastDue.value && !billing.isTrialing.value && billing.resumesAt.value === null);
|
|
77
67
|
const pauseOpen = ref(false);
|
|
78
68
|
const pauseToggle = ref(null);
|
|
79
|
-
const pauseMonths = ref(
|
|
69
|
+
const pauseMonths = ref(plan.pauseLengths[0]);
|
|
80
70
|
const closePause = () => {
|
|
81
71
|
if (pending.value === "pause") return;
|
|
82
72
|
pauseOpen.value = false;
|
|
83
73
|
void nextTick(() => returnFocus(pauseToggle.value));
|
|
84
74
|
};
|
|
85
|
-
const resumesAfter = (months) => {
|
|
86
|
-
const end = toBillingDate(billing.subscription.value?.currentPeriodEnd);
|
|
87
|
-
return end ? new Date(addMonths(end.getTime(), months)) : null;
|
|
88
|
-
};
|
|
89
75
|
const pausePlan = (months) => {
|
|
90
|
-
const resumesAt = resumesAfter(months);
|
|
76
|
+
const resumesAt = plan.resumesAfter(months);
|
|
91
77
|
return run("pause", () => t("pausing"), async () => {
|
|
92
|
-
await
|
|
78
|
+
await plan.pause(months);
|
|
93
79
|
pauseOpen.value = false;
|
|
94
80
|
void nextTick(() => returnFocus(stateLine.value));
|
|
95
81
|
notify("plan-paused", resumesAt?.getTime() ?? null);
|
|
@@ -118,7 +104,9 @@ export function createBillingSection(context) {
|
|
|
118
104
|
}, () => t("canceled"));
|
|
119
105
|
}
|
|
120
106
|
return {
|
|
107
|
+
plan,
|
|
121
108
|
state,
|
|
109
|
+
actions: plan.actions,
|
|
122
110
|
benefits,
|
|
123
111
|
confirm,
|
|
124
112
|
stateLine,
|
|
@@ -143,24 +131,21 @@ export function createBillingSection(context) {
|
|
|
143
131
|
notify("change-canceled");
|
|
144
132
|
}, () => t("changeCanceled")),
|
|
145
133
|
openPortal: () => run("portal", () => t("openingPortal"), () => billing.portal({ redirect: true })),
|
|
146
|
-
keepGifted: () => run("keep-gifted", () => t("keepingGiftedPlan"),
|
|
147
|
-
const product = billing.pass.value ? context.giftedProduct(billing.pass.value.plan) : void 0;
|
|
148
|
-
if (product) await billing.checkout(product, { redirect: true });
|
|
149
|
-
}),
|
|
134
|
+
keepGifted: () => run("keep-gifted", () => t("keepingGiftedPlan"), () => plan.keepGifted()),
|
|
150
135
|
switchOptions,
|
|
151
|
-
switchable,
|
|
136
|
+
switchable: plan.switchable,
|
|
152
137
|
switchOpen,
|
|
153
138
|
switchToggleProps: () => toggle(switchToggle, switchOpen, closeSwitch, partId("switch", "picker"), "switch"),
|
|
154
139
|
closeSwitch,
|
|
155
140
|
change,
|
|
156
141
|
pick,
|
|
157
142
|
switchPlan,
|
|
158
|
-
pausable,
|
|
143
|
+
pausable: plan.pausable,
|
|
159
144
|
pauseOpen,
|
|
160
145
|
pauseToggleProps: () => toggle(pauseToggle, pauseOpen, closePause, partId("pause", "confirm"), "pause"),
|
|
161
146
|
pauseMonths,
|
|
162
147
|
closePause,
|
|
163
148
|
pausePlan,
|
|
164
|
-
resumesAfter
|
|
149
|
+
resumesAfter: plan.resumesAfter
|
|
165
150
|
};
|
|
166
151
|
}
|
|
@@ -71,6 +71,16 @@ export declare function useAccessPhase(options?: UseAccessPhaseOptions): UseAcce
|
|
|
71
71
|
export interface UseInviteOptions {
|
|
72
72
|
/** Override the injected `api.access` namespace. */
|
|
73
73
|
api?: AccessApiRefs;
|
|
74
|
+
/**
|
|
75
|
+
* Open the access link the page was reached by (default `false`), for the
|
|
76
|
+
* page an access link opens: `/invite`, or an app's own page there. Once
|
|
77
|
+
* the page mounts, the token leaves the address's fragment (`#<token>`)
|
|
78
|
+
* at once and the tab keeps it, so a reload while the session settles
|
|
79
|
+
* still has it. Once the session settles, a signed-in visitor's is
|
|
80
|
+
* forgotten, as there is no sign-up to hand it to, and anyone else's, or
|
|
81
|
+
* the one the tab kept, is checked. `linkChecked` says when that is done.
|
|
82
|
+
*/
|
|
83
|
+
fromAddress?: boolean;
|
|
74
84
|
}
|
|
75
85
|
export interface UseInviteReturn {
|
|
76
86
|
/**
|
|
@@ -92,6 +102,14 @@ export interface UseInviteReturn {
|
|
|
92
102
|
isKept: ComputedRef<boolean>;
|
|
93
103
|
/** Drop the kept code or token. */
|
|
94
104
|
forget: () => void;
|
|
105
|
+
/**
|
|
106
|
+
* `true` once the access link has been opened: with `fromAddress`, once
|
|
107
|
+
* the page mounted and the session settled (the server cannot read the
|
|
108
|
+
* fragment); from the start without it.
|
|
109
|
+
*/
|
|
110
|
+
linkChecked: Readonly<Ref<boolean>>;
|
|
111
|
+
/** Whether a ticket was asked about at all: a link brought one, the tab kept one, or a code was checked. */
|
|
112
|
+
asked: Readonly<Ref<boolean>>;
|
|
95
113
|
/**
|
|
96
114
|
* The referral code the address carries, `/invite?ref=<code>`: the
|
|
97
115
|
* referral page links here with it for a visitor who holds an invite
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { computed, inject, ref } from "vue";
|
|
1
|
+
import { computed, inject, ref, watch } from "vue";
|
|
2
2
|
import { useRoute } from "#imports";
|
|
3
3
|
import { ConvexAuthStateKey, useMutation } from "nuxt-convex-module/client";
|
|
4
4
|
import { useAsyncQuery } from "nuxt-convex-module/app";
|
|
@@ -6,12 +6,13 @@ import { normalizeShareCode } from "../../../convex/referral-rules";
|
|
|
6
6
|
import { useActionState } from "../utils/action-state.js";
|
|
7
7
|
import { failureOf } from "../utils/backend-error.js";
|
|
8
8
|
import { forgetInvite, keepInvite, keptInvite, takeInviteFromAddress } from "../utils/kept-invite.js";
|
|
9
|
+
import { onPageOpen } from "../utils/page-open.js";
|
|
9
10
|
import { absentQuery, diagnostics, useLiveQuery } from "../utils/live-query.js";
|
|
10
11
|
import { useApiNamespace, useBackendNamespace } from "../utils/namespace.js";
|
|
11
12
|
import { usePageOrigin } from "../utils/page-origin.js";
|
|
12
13
|
import { useBackendPagePath } from "./use-backend-page-path.js";
|
|
13
14
|
export function useAccessPhase(options = {}) {
|
|
14
|
-
const api =
|
|
15
|
+
const api = options.api ?? useApiNamespace("access") ?? {};
|
|
15
16
|
if (!api.getAccessPhase) {
|
|
16
17
|
return { phase: computed(() => "public"), isPublic: computed(() => true), isLoading: computed(() => false), error: computed(() => null) };
|
|
17
18
|
}
|
|
@@ -34,6 +35,8 @@ export function useInvite(options = {}) {
|
|
|
34
35
|
const { isPending, failure, run } = useActionState();
|
|
35
36
|
const status = ref(null);
|
|
36
37
|
const kept = ref(keptInvite() !== null);
|
|
38
|
+
const linkChecked = ref(!options.fromAddress);
|
|
39
|
+
const asked = ref(false);
|
|
37
40
|
const referral = computed(() => {
|
|
38
41
|
const value = route.query.ref;
|
|
39
42
|
const code = Array.isArray(value) ? value[0] : value;
|
|
@@ -45,6 +48,7 @@ export function useInvite(options = {}) {
|
|
|
45
48
|
status.value = "unknown";
|
|
46
49
|
return status.value;
|
|
47
50
|
}
|
|
51
|
+
asked.value = true;
|
|
48
52
|
keepInvite(code);
|
|
49
53
|
kept.value = true;
|
|
50
54
|
try {
|
|
@@ -60,16 +64,39 @@ export function useInvite(options = {}) {
|
|
|
60
64
|
return null;
|
|
61
65
|
}
|
|
62
66
|
};
|
|
67
|
+
const forget = () => {
|
|
68
|
+
forgetInvite();
|
|
69
|
+
kept.value = false;
|
|
70
|
+
};
|
|
71
|
+
if (options.fromAddress) {
|
|
72
|
+
const auth = inject(ConvexAuthStateKey, null);
|
|
73
|
+
const open = () => {
|
|
74
|
+
const taken = takeInviteFromAddress();
|
|
75
|
+
if (taken) {
|
|
76
|
+
keepInvite(taken);
|
|
77
|
+
kept.value = true;
|
|
78
|
+
}
|
|
79
|
+
let started = false;
|
|
80
|
+
const stop = watch(() => auth != null && auth.isLoading.value, async (loading) => {
|
|
81
|
+
if (loading || started) return;
|
|
82
|
+
started = true;
|
|
83
|
+
queueMicrotask(() => stop());
|
|
84
|
+
if (auth?.isAuthenticated.value) forget();
|
|
85
|
+
else if (kept.value) await check();
|
|
86
|
+
linkChecked.value = true;
|
|
87
|
+
}, { immediate: true });
|
|
88
|
+
};
|
|
89
|
+
onPageOpen(open);
|
|
90
|
+
}
|
|
63
91
|
return {
|
|
64
92
|
check,
|
|
65
93
|
status,
|
|
66
94
|
isPending,
|
|
67
95
|
error: computed(() => failure.value),
|
|
68
96
|
isKept: computed(() => kept.value),
|
|
69
|
-
forget
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
},
|
|
97
|
+
forget,
|
|
98
|
+
linkChecked,
|
|
99
|
+
asked,
|
|
73
100
|
referral,
|
|
74
101
|
signInTo: computed(() => {
|
|
75
102
|
if (!loginPath.value) return null;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { type ComputedRef, type MaybeRefOrGetter } from 'vue';
|
|
2
|
+
import type { BackendError } from '../utils/backend-error.js';
|
|
3
|
+
import { type CheckoutOptions } from './use-billing.js';
|
|
4
|
+
import type { LabelGroupOverrides } from './use-labels.js';
|
|
5
|
+
import { type UsePlanChangeReturn } from './use-plan-change.js';
|
|
6
|
+
/**
|
|
7
|
+
* The states a running plan can be in, in the order they are tried: the
|
|
8
|
+
* first that holds is the one shown. A plan pass gifted until its end date,
|
|
9
|
+
* a failed payment, a pause, a cancellation set for the period's end, a
|
|
10
|
+
* plan change scheduled for it, a trial, else active. The Subscriptions
|
|
11
|
+
* page lists them in this order (test/docs pins it).
|
|
12
|
+
*/
|
|
13
|
+
export declare const PLAN_STATES: readonly ["gifted", "past_due", "paused", "canceling", "changing", "trialing", "active"];
|
|
14
|
+
/** The state a running plan is in: the first of {@link PLAN_STATES} that holds. */
|
|
15
|
+
export type PlanState = typeof PLAN_STATES[number];
|
|
16
|
+
/**
|
|
17
|
+
* The state the billing section shows: `'loading'` until the plan is known,
|
|
18
|
+
* `'error'` when it could not be read (never a plan it might not be),
|
|
19
|
+
* `'free'` on the free plan or none, else the running plan's {@link PlanState}.
|
|
20
|
+
*/
|
|
21
|
+
export type BillingSectionState = 'loading' | 'error' | 'free' | PlanState;
|
|
22
|
+
/** The lengths of a pause the section offers, in months from the period's end. */
|
|
23
|
+
export declare const PAUSE_MONTHS: readonly [1, 2, 3];
|
|
24
|
+
/**
|
|
25
|
+
* One thing a billing manager can do with the plan, as the billing section
|
|
26
|
+
* offers it: keep a gifted plan by checking it out, open the portal (to
|
|
27
|
+
* update the payment method first when one failed), resume a pause, keep a
|
|
28
|
+
* plan set to end, cancel a scheduled change, switch the plan or its
|
|
29
|
+
* billing period, pause it, cancel it.
|
|
30
|
+
*/
|
|
31
|
+
export type BillingSectionAction = 'keep-gifted' | 'portal' | 'resume' | 'uncancel' | 'cancel-change' | 'change-plan' | 'pause' | 'cancel';
|
|
32
|
+
/** Options for {@link useBillingSection}. */
|
|
33
|
+
export interface UseBillingSectionOptions {
|
|
34
|
+
/** Copy for the switch's confirmation (`change`), over `appConfig.backend.labels.pricing` and the translations. */
|
|
35
|
+
labels?: MaybeRefOrGetter<LabelGroupOverrides<'pricing'> | undefined>;
|
|
36
|
+
/** While this is `false` no pricing is read for a switch, and none is offered (default `true`). */
|
|
37
|
+
enabled?: MaybeRefOrGetter<boolean>;
|
|
38
|
+
}
|
|
39
|
+
/** What {@link useBillingSection} returns. */
|
|
40
|
+
export interface UseBillingSectionReturn {
|
|
41
|
+
/** The state the section shows (see {@link BillingSectionState}). */
|
|
42
|
+
state: ComputedRef<BillingSectionState>;
|
|
43
|
+
/** `true` until the plan is known, unless its read failed, and while a return from checkout is being finished (`useBilling().isFinishingCheckout`): mark the section busy. */
|
|
44
|
+
isLoading: ComputedRef<boolean>;
|
|
45
|
+
/** `true` while a pause or a gifted plan's checkout is on its way. */
|
|
46
|
+
isPending: ComputedRef<boolean>;
|
|
47
|
+
/** Why the last action failed, else why the plan could not be read, else `null`. */
|
|
48
|
+
error: ComputedRef<BackendError | null>;
|
|
49
|
+
/**
|
|
50
|
+
* What the state calls for, in the order the section offers it: on a
|
|
51
|
+
* failed payment the portal first, then the plan's ways back (resume,
|
|
52
|
+
* keep, cancel the scheduled change), the portal, then a switch, a pause
|
|
53
|
+
* and a cancellation where each is open. A gifted plan's one offer is to
|
|
54
|
+
* keep it. Empty for anyone who does not manage the billing
|
|
55
|
+
* (`useBilling().canManage`), on the free plan, while loading and after a
|
|
56
|
+
* failed read.
|
|
57
|
+
*/
|
|
58
|
+
actions: ComputedRef<BillingSectionAction[]>;
|
|
59
|
+
/** Whether a switch is offered: a running plan, not gifted, set to end, paused or already changing, with a price to switch to (`change.targets`). */
|
|
60
|
+
switchable: ComputedRef<boolean>;
|
|
61
|
+
/**
|
|
62
|
+
* Whether a pause is offered: a running plan, not gifted, set to end,
|
|
63
|
+
* paused, past due or in its trial (the provider pauses only an active
|
|
64
|
+
* subscription), and with no pause scheduled (`resumesAt` is `null`).
|
|
65
|
+
*/
|
|
66
|
+
pausable: ComputedRef<boolean>;
|
|
67
|
+
/** Whether a cancellation is offered: a running plan, not gifted, set to end already or paused, which the provider would refuse a second one for. */
|
|
68
|
+
cancellable: ComputedRef<boolean>;
|
|
69
|
+
/** The lengths a pause is offered for, in months: {@link PAUSE_MONTHS}. */
|
|
70
|
+
pauseLengths: readonly number[];
|
|
71
|
+
/**
|
|
72
|
+
* When a pause of `months` from the period's end resumes: the period's
|
|
73
|
+
* end moved on by whole months in UTC the way the provider counts them,
|
|
74
|
+
* the same day of the month, or its last when the month is shorter (a
|
|
75
|
+
* period ending January 31 paused for a month resumes February 28).
|
|
76
|
+
* `null` while the period's end is not known.
|
|
77
|
+
*/
|
|
78
|
+
resumesAfter: (months: number) => Date | null;
|
|
79
|
+
/** Pause the plan from the period's end for `months`, resuming by itself on `resumesAfter(months)`. Rejects as `useBilling().pause` does. */
|
|
80
|
+
pause: (months: number) => Promise<void>;
|
|
81
|
+
/** Keep a gifted plan: an ordinary checkout of its plan (`options` go with it, `{ redirect: true }` by default), which moves the pass to the paid plan in place. */
|
|
82
|
+
keepGifted: (options?: CheckoutOptions) => Promise<void>;
|
|
83
|
+
/** The switch to another plan or billing period, and its confirmation (`usePlanChange`). */
|
|
84
|
+
change: UsePlanChangeReturn;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The billing section of `/settings` without its markup: the state the
|
|
88
|
+
* plan is in, in the order the section tries them (a gifted plan, a failed
|
|
89
|
+
* payment, a pause, a cancellation or a plan change set for the period's
|
|
90
|
+
* end, a trial, else active), a read that failed as a failure rather than
|
|
91
|
+
* a plan, a return from checkout still finishing as busy, and what each
|
|
92
|
+
* state calls for, with the rules each offer follows: a switch only while
|
|
93
|
+
* nothing is scheduled, a pause only while none is, and its resume date
|
|
94
|
+
* counted the way the provider counts months. `<WorkspaceSettings>`'s
|
|
95
|
+
* billing section is this with the package's markup.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```vue
|
|
99
|
+
* <script setup lang="ts">
|
|
100
|
+
* const section = useBillingSection()
|
|
101
|
+
* // The app's language, not the visitor's, so the server's HTML and the browser's agree.
|
|
102
|
+
* const { locale } = useLabels('settings')
|
|
103
|
+
* const day = (date: Date | null) => (date ? new Intl.DateTimeFormat(locale.value ?? 'en', { dateStyle: 'medium' }).format(date) : '')
|
|
104
|
+
* </script>
|
|
105
|
+
* <template>
|
|
106
|
+
* <section :aria-busy="section.isLoading.value || undefined">
|
|
107
|
+
* <p v-if="section.state.value === 'error'" role="alert">The plan could not be read.</p>
|
|
108
|
+
* <button v-for="months in section.pausable.value ? section.pauseLengths : []" :key="months" @click="section.pause(months)">
|
|
109
|
+
* Pause until {{ day(section.resumesAfter(months)) }}
|
|
110
|
+
* </button>
|
|
111
|
+
* </section>
|
|
112
|
+
* </template>
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
export declare function useBillingSection(options?: UseBillingSectionOptions): UseBillingSectionReturn;
|