nuxt-backend 0.4.0 → 0.5.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 +2 -0
- 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 +9 -52
- 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.BqXAZChe.mjs} +23 -3
- package/dist/shared/{nuxt-backend.BjQoqNIu.mjs → nuxt-backend.CBvrM7pG.mjs} +1 -1
- package/dist/shared/{nuxt-backend.Baxb382E.mjs → nuxt-backend.DH1Ya3uB.mjs} +1 -1
- package/dist/shared/{nuxt-backend.9IVxzzft.mjs → nuxt-backend.DbaXvH__.mjs} +1 -1
- package/dist/shared/{nuxt-backend.BCjeoX0x.mjs → nuxt-backend.Dikfaocl.mjs} +56 -8
- package/package.json +1 -1
- package/skills/nuxt-backend/references/api.md +2 -0
- package/skills/nuxt-backend/references/install.md +4 -1
- 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
|
@@ -22,6 +22,13 @@ export interface UseReferralInviteReturn {
|
|
|
22
22
|
isPending: ComputedRef<boolean>;
|
|
23
23
|
/** Where the sign-in page sends a visitor, who is returned to this page to claim. `null` with the sign-in page turned off. */
|
|
24
24
|
signInTo: ComputedRef<string | null>;
|
|
25
|
+
/**
|
|
26
|
+
* The invite page for a visitor who holds an invite while the app is
|
|
27
|
+
* `closed`: `/invite?ref=<code>`, so the sign-in it leads to comes back
|
|
28
|
+
* here to claim (`useInvite().signInTo`). `null` with the invite page
|
|
29
|
+
* turned off.
|
|
30
|
+
*/
|
|
31
|
+
inviteTo: ComputedRef<string | null>;
|
|
25
32
|
/**
|
|
26
33
|
* `true` while the app is not public (`useAccessPhase`): a new account
|
|
27
34
|
* needs a ticket first, an invite or an admitted place on the waitlist,
|
|
@@ -16,6 +16,7 @@ export function useReferralInvite(options = {}) {
|
|
|
16
16
|
const signedIn = computed(() => auth != null && auth.isAuthenticated.value);
|
|
17
17
|
const loginPath = useBackendPagePath("login");
|
|
18
18
|
const landing = useBackendPagePath("referral");
|
|
19
|
+
const invitePath = useBackendPagePath("invite");
|
|
19
20
|
const { phase, isLoading: phaseLoading } = useAccessPhase({ api: useApiNamespace("access") ?? {} });
|
|
20
21
|
const phaseWaited = useTimeout(PHASE_WAIT_MS);
|
|
21
22
|
const code = computed(() => {
|
|
@@ -24,7 +25,7 @@ export function useReferralInvite(options = {}) {
|
|
|
24
25
|
});
|
|
25
26
|
const read = api.previewReferral ? useAsyncQuery(api.previewReferral, () => ({ code: code.value })) : absentQuery();
|
|
26
27
|
const readFailure = computed(() => read.error.value ? failureOf(read.error.value) : null);
|
|
27
|
-
const preview = computed(() => read.data.value === void 0 && readFailure.value ? null : read.data.value);
|
|
28
|
+
const preview = computed(() => !api.previewReferral || read.data.value === void 0 && readFailure.value ? null : read.data.value);
|
|
28
29
|
const runClaim = api.claimReferral ? useMutation(api.claimReferral) : null;
|
|
29
30
|
const outcome = ref(null);
|
|
30
31
|
const claimFailure = shallowRef(null);
|
|
@@ -64,6 +65,7 @@ export function useReferralInvite(options = {}) {
|
|
|
64
65
|
const here = (landing.value ?? "/r/:code").replace(":code", encodeURIComponent(code.value));
|
|
65
66
|
return `${loginPath.value}?redirect=${encodeURIComponent(`${here}?claim=1`)}`;
|
|
66
67
|
});
|
|
68
|
+
const inviteTo = computed(() => invitePath.value ? `${invitePath.value}?ref=${encodeURIComponent(code.value)}` : null);
|
|
67
69
|
return {
|
|
68
70
|
code,
|
|
69
71
|
state,
|
|
@@ -71,6 +73,7 @@ export function useReferralInvite(options = {}) {
|
|
|
71
73
|
isLoading: computed(() => Boolean(api.previewReferral) && preview.value === void 0),
|
|
72
74
|
isPending: computed(() => outcome.value === "claiming"),
|
|
73
75
|
signInTo,
|
|
76
|
+
inviteTo,
|
|
74
77
|
closed: computed(() => {
|
|
75
78
|
if (phaseLoading.value) return phaseWaited.value ? false : void 0;
|
|
76
79
|
return phase.value !== void 0 && phase.value !== "public";
|
|
@@ -78,6 +78,16 @@ export interface UseWaitlistOptions {
|
|
|
78
78
|
* form, as a path on this site. Default: the page this runs on.
|
|
79
79
|
*/
|
|
80
80
|
shareTo?: MaybeRefOrGetter<string | undefined>;
|
|
81
|
+
/**
|
|
82
|
+
* Open the status link the page was reached by (default `false`), for the
|
|
83
|
+
* page a status email links to: `/waitlist`, or an app's own page there.
|
|
84
|
+
* Once the page mounts, the token leaves the address's fragment
|
|
85
|
+
* (`#<token>`) and the tab keeps it, as it keeps a join's and one passed
|
|
86
|
+
* to `status`, so a reload shows the place again while the address, a
|
|
87
|
+
* bookmark or a copied link never holds it. `leave` drops it. The server
|
|
88
|
+
* cannot read the fragment: `linkChecked` says when the page has.
|
|
89
|
+
*/
|
|
90
|
+
statusLink?: boolean;
|
|
81
91
|
}
|
|
82
92
|
/** The attributes and handlers custom markup spreads on its elements. */
|
|
83
93
|
export interface WaitlistBindings {
|
|
@@ -144,6 +154,14 @@ export interface UseWaitlistReturn {
|
|
|
144
154
|
shareLink: ComputedRef<string | null>;
|
|
145
155
|
/** `true` while a status token's place is first read. */
|
|
146
156
|
isLoading: ComputedRef<boolean>;
|
|
157
|
+
/**
|
|
158
|
+
* `true` once the page has looked for a status link: on mount with
|
|
159
|
+
* `statusLink`, as only the browser reads the fragment, so the server
|
|
160
|
+
* renders a wait; from the start without it.
|
|
161
|
+
*/
|
|
162
|
+
linkChecked: Readonly<Ref<boolean>>;
|
|
163
|
+
/** `true` once `leave` took the person off the list, until a code checks or a status link is read again. */
|
|
164
|
+
left: Readonly<Ref<boolean>>;
|
|
147
165
|
/** `true` once the code signed the person in instead: they hold a ticket, or the app is no longer in early access. */
|
|
148
166
|
signedIn: Ref<boolean>;
|
|
149
167
|
/**
|
|
@@ -12,10 +12,15 @@ import { useCampaign } from "./use-campaign.js";
|
|
|
12
12
|
import { useHumanCheck } from "./use-human-check.js";
|
|
13
13
|
import { useLabels } from "./use-labels.js";
|
|
14
14
|
import { usePageOrigin } from "../utils/page-origin.js";
|
|
15
|
+
import { onPageOpen } from "../utils/page-open.js";
|
|
16
|
+
import { takeFragment, tabKeep } from "../utils/tab-keep.js";
|
|
15
17
|
export function campaignSource(source, attribution) {
|
|
16
18
|
const tags = [attribution?.source, attribution?.campaign].flatMap((tag) => tag ? [tag.replace(/[^\w.-]+/g, "-")] : []);
|
|
17
19
|
return (tags.length > 0 ? `${source}:${tags.join("/")}` : source).slice(0, WAITLIST_SOURCE_MAX);
|
|
18
20
|
}
|
|
21
|
+
export function keptStatusToken() {
|
|
22
|
+
return tabKeep("nuxt-backend:waitlist");
|
|
23
|
+
}
|
|
19
24
|
function referralFromAddress(route) {
|
|
20
25
|
const value = route.query.ref;
|
|
21
26
|
const code = Array.isArray(value) ? value[0] : value;
|
|
@@ -61,6 +66,9 @@ export function useWaitlist(options = {}) {
|
|
|
61
66
|
return `${origin}${to}${to.includes("?") ? "&" : "?"}ref=${encodeURIComponent(code2)}`;
|
|
62
67
|
});
|
|
63
68
|
const asked = api.getWaitlistQuestions ? useLiveQuery(api.getWaitlistQuestions, {}) : absentQuery();
|
|
69
|
+
const kept = options.statusLink ? keptStatusToken() : null;
|
|
70
|
+
const linkChecked = ref(!options.statusLink);
|
|
71
|
+
const left = ref(false);
|
|
64
72
|
const trimmed = () => email.value.trim();
|
|
65
73
|
const join = async () => {
|
|
66
74
|
clearError();
|
|
@@ -98,6 +106,8 @@ export function useWaitlist(options = {}) {
|
|
|
98
106
|
const waiting = failure.data.waitlist;
|
|
99
107
|
if (failure.code !== "forbidden" || failure.data.reason !== "ticket_required" || failure.data.phase !== "early-access") throw cause;
|
|
100
108
|
token.value = waiting?.token ?? null;
|
|
109
|
+
if (token.value) kept?.keep(token.value);
|
|
110
|
+
left.value = false;
|
|
101
111
|
result = { status: "waiting", position: waiting?.position ?? null, total: waiting?.total ?? 0, friends: 0, cap: 0, shareCode: "", launchNews: launchNews.value, token: waiting?.token ?? "" };
|
|
102
112
|
joined.value = result;
|
|
103
113
|
step.value = "status";
|
|
@@ -111,13 +121,25 @@ export function useWaitlist(options = {}) {
|
|
|
111
121
|
const status = (statusToken) => {
|
|
112
122
|
clearError();
|
|
113
123
|
token.value = statusToken.trim() || null;
|
|
124
|
+
if (token.value) kept?.keep(token.value);
|
|
125
|
+
left.value = false;
|
|
114
126
|
step.value = "status";
|
|
115
127
|
};
|
|
128
|
+
if (options.statusLink) {
|
|
129
|
+
const open = () => {
|
|
130
|
+
const found = takeFragment() ?? kept?.read();
|
|
131
|
+
if (found) status(found);
|
|
132
|
+
linkChecked.value = true;
|
|
133
|
+
};
|
|
134
|
+
onPageOpen(open);
|
|
135
|
+
}
|
|
116
136
|
const leave = async () => {
|
|
117
137
|
await run(async () => {
|
|
118
138
|
if (!runLeave || !token.value) throw new Error("[nuxt-backend] Leaving needs `leaveWaitlist` re-exported from setupWaitlist() in backend/waitlist.ts, and a place to leave.");
|
|
119
139
|
await runLeave({ token: token.value });
|
|
120
140
|
token.value = null;
|
|
141
|
+
kept?.drop();
|
|
142
|
+
left.value = true;
|
|
121
143
|
joined.value = null;
|
|
122
144
|
code.value = "";
|
|
123
145
|
step.value = "join";
|
|
@@ -138,6 +160,8 @@ export function useWaitlist(options = {}) {
|
|
|
138
160
|
place,
|
|
139
161
|
shareLink,
|
|
140
162
|
isLoading: computed(() => live.isLoading.value),
|
|
163
|
+
linkChecked,
|
|
164
|
+
left,
|
|
141
165
|
signedIn,
|
|
142
166
|
join,
|
|
143
167
|
verify,
|
|
@@ -3,7 +3,6 @@ import { useHead, useRuntimeConfig, useSeoMeta } from "#imports";
|
|
|
3
3
|
import PageFrame from "../components/shell/PageFrame.vue";
|
|
4
4
|
import { useLabels } from "../composables/use-labels";
|
|
5
5
|
import { usePricing } from "../composables/use-pricing";
|
|
6
|
-
import { pricingStructuredData } from "../utils/pricing-seo";
|
|
7
6
|
defineOptions({ name: "BackendPricingPage" });
|
|
8
7
|
const { t } = useLabels("pricing");
|
|
9
8
|
const pricing = usePricing({ actions: false });
|
|
@@ -18,7 +17,7 @@ if (seo) {
|
|
|
18
17
|
key: "backend-pricing",
|
|
19
18
|
type: "application/ld+json",
|
|
20
19
|
// An object: the head manager serializes it, and escapes what could end the script early.
|
|
21
|
-
innerHTML: () => pricing.
|
|
20
|
+
innerHTML: () => pricing.structuredData.value ?? ""
|
|
22
21
|
}]
|
|
23
22
|
});
|
|
24
23
|
}
|
|
@@ -8,9 +8,16 @@ export default defineNuxtPlugin({
|
|
|
8
8
|
const check = () => {
|
|
9
9
|
const route = router.currentRoute.value;
|
|
10
10
|
if (!(CHECKOUT_RETURN_PARAM in route.query)) return;
|
|
11
|
-
import("../utils/checkout-return.js").then(({ entitlementSync, finishCheckoutReturn }) => finishCheckoutReturn({
|
|
11
|
+
import("../utils/checkout-return.js").then(({ entitlementSync, finishCheckoutReturn, withoutCheckoutReturn }) => finishCheckoutReturn({
|
|
12
12
|
query: route.query,
|
|
13
|
-
|
|
13
|
+
// From the address as it is by now, not as it was on arrival: the
|
|
14
|
+
// page may have taken a parameter of its own off it meanwhile, and
|
|
15
|
+
// the arrival's copy would put that back. A token left behind alone goes too.
|
|
16
|
+
strip: () => {
|
|
17
|
+
const now = router.currentRoute.value;
|
|
18
|
+
const rest = now.path === route.path ? withoutCheckoutReturn(now.query) : null;
|
|
19
|
+
return rest && router.replace({ path: now.path, query: rest, hash: now.hash });
|
|
20
|
+
},
|
|
14
21
|
sync: (checkoutId) => nuxtApp.vueApp.runWithContext(entitlementSync)(checkoutId)
|
|
15
22
|
})).catch((cause) => {
|
|
16
23
|
if (import.meta.dev) console.error("[nuxt-backend] the checkout return could not finish:", cause);
|
|
@@ -12,11 +12,21 @@ export declare const finishingCheckout: import("vue").ShallowRef<boolean, boolea
|
|
|
12
12
|
* key has no place in an address that is bookmarked, shared and logged.
|
|
13
13
|
*/
|
|
14
14
|
export declare const CUSTOMER_SESSION_PARAM = "customer_session_token";
|
|
15
|
+
/**
|
|
16
|
+
* `query` without what a return from checkout adds to it: `checkout_return`
|
|
17
|
+
* and the provider's `customer_session_token`. `null` when it has neither,
|
|
18
|
+
* so there is nothing to take off.
|
|
19
|
+
*/
|
|
20
|
+
export declare function withoutCheckoutReturn(query: LocationQuery): LocationQuery | null;
|
|
15
21
|
/** What finishing a return needs from the page. */
|
|
16
22
|
export interface CheckoutReturn {
|
|
17
23
|
/** The address's query. */
|
|
18
24
|
query: LocationQuery;
|
|
19
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* Take the parameter and the provider's token off the address. `query`
|
|
27
|
+
* is the arrival's without them (`withoutCheckoutReturn`): a page whose
|
|
28
|
+
* address may have changed since strips its current one instead.
|
|
29
|
+
*/
|
|
20
30
|
strip: (query: LocationQuery) => unknown;
|
|
21
31
|
/** Refresh the entitlements from the provider once, for the checkout this id names. A failure is left to the webhooks. */
|
|
22
32
|
sync: (checkoutId: string) => Promise<unknown>;
|
|
@@ -5,13 +5,17 @@ import { CHECKOUT_RETURN_PARAM } from "../../../convex/constants.js";
|
|
|
5
5
|
import { useBackendNamespace } from "./namespace.js";
|
|
6
6
|
export const finishingCheckout = shallowRef(false);
|
|
7
7
|
export const CUSTOMER_SESSION_PARAM = "customer_session_token";
|
|
8
|
+
export function withoutCheckoutReturn(query) {
|
|
9
|
+
if (!(CHECKOUT_RETURN_PARAM in query) && !(CUSTOMER_SESSION_PARAM in query)) return null;
|
|
10
|
+
const { [CHECKOUT_RETURN_PARAM]: _returned, [CUSTOMER_SESSION_PARAM]: _token, ...rest } = query;
|
|
11
|
+
return rest;
|
|
12
|
+
}
|
|
8
13
|
const finished = /* @__PURE__ */ new Set();
|
|
9
14
|
const AUTH_WAIT_MS = 1e4;
|
|
10
15
|
export async function finishCheckoutReturn({ query, strip, sync }) {
|
|
11
16
|
const value = query[CHECKOUT_RETURN_PARAM];
|
|
12
17
|
if (value === void 0) return false;
|
|
13
|
-
|
|
14
|
-
await strip(rest);
|
|
18
|
+
await strip(withoutCheckoutReturn(query) ?? query);
|
|
15
19
|
const id = (Array.isArray(value) ? value[0] : value) ?? "";
|
|
16
20
|
if (!id || finished.has(id)) return false;
|
|
17
21
|
finished.add(id);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type ComputedRef } from 'vue';
|
|
2
|
+
/** Whether a value is a day as an input of type `date` writes it: `YYYY-MM-DD`. */
|
|
3
|
+
export declare function isGiftDay(value: string): boolean;
|
|
4
|
+
/** The moment a dated gift goes out: `DELIVERY_HOUR` on `day` (`YYYY-MM-DD`), in the runtime's own time zone. */
|
|
5
|
+
export declare function giftDeliveryTime(day: string): number;
|
|
6
|
+
/** The first and the last day a gift may be dated for, `YYYY-MM-DD`: a date input's `min` and `max`. */
|
|
7
|
+
export interface GiftDays {
|
|
8
|
+
firstDay: ComputedRef<string>;
|
|
9
|
+
lastDay: ComputedRef<string>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The days a gift may be dated for. Today on the page's clock: while
|
|
13
|
+
* hydrating, the server's, in UTC, so the date input's bounds read as the
|
|
14
|
+
* server rendered them; once the page is the browser's (mounted, or entered
|
|
15
|
+
* by a client-side visit), the purchaser's own today, whose 09:00 is theirs
|
|
16
|
+
* too. A UTC day would be yesterday east of UTC, and its 09:00 the evening
|
|
17
|
+
* before far west of it. The last day is a year after the first, which
|
|
18
|
+
* still falls inside the server's window (`DELIVER_AHEAD_DAYS`, 366) from now.
|
|
19
|
+
*/
|
|
20
|
+
export declare function useGiftDays(): GiftDays;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { tryOnMounted } from "@vueuse/core";
|
|
2
|
+
import { computed, ref } from "vue";
|
|
3
|
+
import { tryUseNuxtApp } from "#imports";
|
|
4
|
+
import { DELIVER_AHEAD_DAYS } from "../../../convex/integrations/billing/gift-rules.js";
|
|
5
|
+
import { usePageClock } from "./pricing-bindings.js";
|
|
6
|
+
const DAY_MS = 24 * 60 * 60 * 1e3;
|
|
7
|
+
const DELIVERY_HOUR = 9;
|
|
8
|
+
const isoDay = (at) => new Date(at).toISOString().slice(0, 10);
|
|
9
|
+
function localDay(at) {
|
|
10
|
+
const date = new Date(at);
|
|
11
|
+
const pad = (value) => String(value).padStart(2, "0");
|
|
12
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
|
|
13
|
+
}
|
|
14
|
+
export function isGiftDay(value) {
|
|
15
|
+
return /^\d{4}-\d{2}-\d{2}$/.test(value);
|
|
16
|
+
}
|
|
17
|
+
export function giftDeliveryTime(day) {
|
|
18
|
+
const [year, month, date] = day.split("-").map(Number);
|
|
19
|
+
return new Date(year, month - 1, date, DELIVERY_HOUR).getTime();
|
|
20
|
+
}
|
|
21
|
+
export function useGiftDays() {
|
|
22
|
+
const clock = usePageClock();
|
|
23
|
+
const ownCalendar = ref(import.meta.client && !tryUseNuxtApp()?.isHydrating);
|
|
24
|
+
tryOnMounted(() => {
|
|
25
|
+
ownCalendar.value = true;
|
|
26
|
+
});
|
|
27
|
+
const firstDay = computed(() => ownCalendar.value ? localDay(clock.value) : isoDay(clock.value));
|
|
28
|
+
return {
|
|
29
|
+
firstDay,
|
|
30
|
+
lastDay: computed(() => isoDay(Date.parse(firstDay.value) + (DELIVER_AHEAD_DAYS - 1) * DAY_MS))
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { hasInjectionContext, inject } from "vue";
|
|
2
2
|
export const BackendApiKey = Symbol("nuxt-backend:api");
|
|
3
3
|
export const beforeApiRead = /* @__PURE__ */ new Set();
|
|
4
|
-
export function provideBackendApi(api, app) {
|
|
5
|
-
app.provide(BackendApiKey, api);
|
|
4
|
+
export function provideBackendApi(api, app, modules) {
|
|
5
|
+
app.provide(BackendApiKey, modules ? declaredOnly(api, new Set(modules)) : api);
|
|
6
|
+
}
|
|
7
|
+
function declaredOnly(api, modules) {
|
|
8
|
+
return new Proxy(api, {
|
|
9
|
+
get: (target, key, receiver) => typeof key === "string" && !modules.has(key) ? void 0 : Reflect.get(target, key, receiver)
|
|
10
|
+
});
|
|
6
11
|
}
|
|
7
12
|
export function useApiNamespace(name) {
|
|
8
13
|
if (!hasInjectionContext()) return void 0;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { getCurrentInstance, onMounted } from "vue";
|
|
2
|
+
import { tryUseNuxtApp } from "#imports";
|
|
3
|
+
export function onPageOpen(open) {
|
|
4
|
+
if (getCurrentInstance()) {
|
|
5
|
+
onMounted(open);
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
if (typeof window === "undefined") return;
|
|
9
|
+
const nuxtApp = tryUseNuxtApp();
|
|
10
|
+
if (nuxtApp?.isHydrating) nuxtApp.hooks.hookOnce("app:suspense:resolve", open);
|
|
11
|
+
else open();
|
|
12
|
+
}
|
|
@@ -1,28 +1,42 @@
|
|
|
1
1
|
import { type ComputedRef, type Ref } from 'vue';
|
|
2
2
|
import type { PlanChangePreview } from '../composables/use-billing.js';
|
|
3
|
+
import type { PlanChangeApplies, PlanChangeTarget, UsePlanChangeReturn } from '../composables/use-plan-change.js';
|
|
4
|
+
export type { PlanChangeTarget } from '../composables/use-plan-change.js';
|
|
3
5
|
/**
|
|
4
6
|
* How a confirmed switch settles: the period's difference charged or
|
|
5
7
|
* credited at once, as the confirmation says it is. Sent with every switch
|
|
6
|
-
* the packaged components make, so the organization's
|
|
7
|
-
* may defer the charge to the next invoice or schedule
|
|
8
|
-
* period's end, never makes the words untrue.
|
|
8
|
+
* `usePlanChange` and the packaged components make, so the organization's
|
|
9
|
+
* own default, which may defer the charge to the next invoice or schedule
|
|
10
|
+
* the switch for the period's end, never makes the words untrue.
|
|
9
11
|
*/
|
|
10
12
|
export declare const CONFIRMED_PRORATION = "invoice";
|
|
11
|
-
/** The labels the
|
|
13
|
+
/** The labels the words read, the same keys in every group that confirms a switch. */
|
|
12
14
|
type ChangeKey = 'changeTitle' | 'changeNow' | 'changeLater' | 'changeLaterPeriod' | 'changeTrial' | 'changeTrialEnds' | 'changeTrialLater' | 'confirmChange' | 'switchingPlan' | 'keepCurrent';
|
|
13
15
|
/** A component's `t`, as far as the group reads it. */
|
|
14
16
|
export type ChangeTranslate = (key: ChangeKey, params?: Record<string, string | number>) => string;
|
|
15
|
-
/**
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
|
|
21
|
-
/**
|
|
17
|
+
/** What a switch's confirmation says about it. */
|
|
18
|
+
interface ChangeWords {
|
|
19
|
+
/** How it goes: `usePlanChange().applies`. */
|
|
20
|
+
applies: PlanChangeApplies | null;
|
|
21
|
+
/** What the switch would do: `useBilling().changeOf`. */
|
|
22
|
+
preview: PlanChangePreview | null;
|
|
23
|
+
/** The price it moves to, with its period. */
|
|
22
24
|
price: string;
|
|
23
|
-
/**
|
|
24
|
-
|
|
25
|
+
/** What a gifted plan's checkout says, which the preview has nothing to say about. */
|
|
26
|
+
gifted: string;
|
|
27
|
+
t: ChangeTranslate;
|
|
28
|
+
/** A date in the reader's words, or `null`. */
|
|
29
|
+
date: (value: Date) => string | null;
|
|
25
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* When a switch happens and how it settles, in the reader's words: at once
|
|
33
|
+
* with the period's difference settled now, or at the paid year's end; in
|
|
34
|
+
* a trial, carrying the trial over, ending it with a first payment, or
|
|
35
|
+
* waiting for its end. A gifted plan's holder reads that theirs is a
|
|
36
|
+
* checkout that ends the gift. `''` for a switch there is nothing to say
|
|
37
|
+
* about.
|
|
38
|
+
*/
|
|
39
|
+
export declare function planChangeWhen(words: ChangeWords): string;
|
|
26
40
|
/** What the group needs from the component that offers it. */
|
|
27
41
|
export interface PlanChangeConfirmOptions {
|
|
28
42
|
/** The component's markup family: `settings` writes `data-settings` hooks. */
|
|
@@ -33,34 +47,33 @@ export interface PlanChangeConfirmOptions {
|
|
|
33
47
|
partId: (part: 'confirm' | 'title') => string;
|
|
34
48
|
/** `true` while the switch is on its way. */
|
|
35
49
|
isBusy: () => boolean;
|
|
36
|
-
/**
|
|
37
|
-
|
|
50
|
+
/** The plan change the group confirms: what it is about, and what it would do. */
|
|
51
|
+
change: UsePlanChangeReturn;
|
|
38
52
|
/** Make the switch. */
|
|
39
|
-
confirm: (target: PlanChangeTarget) => unknown;
|
|
53
|
+
confirm: (target: Required<PlanChangeTarget>) => unknown;
|
|
40
54
|
/** The component's labels. */
|
|
41
55
|
t: ChangeTranslate;
|
|
42
56
|
/** A date in the reader's words, or `null`. */
|
|
43
57
|
date: (value: Date) => string | null;
|
|
44
58
|
/**
|
|
45
59
|
* What the group says for a gifted plan's holder, whose switch is a
|
|
46
|
-
* checkout of the new plan that ends the gift and which
|
|
47
|
-
* nothing to say about (`changeOf` is `null` for a pass)
|
|
48
|
-
*
|
|
49
|
-
* describes.
|
|
60
|
+
* checkout of the new plan that ends the gift and which the preview has
|
|
61
|
+
* nothing to say about (`changeOf` is `null` for a pass). A component
|
|
62
|
+
* that never opens the group for one leaves it out.
|
|
50
63
|
*/
|
|
51
|
-
gifted?: (target: PlanChangeTarget) => string
|
|
64
|
+
gifted?: (target: PlanChangeTarget) => string;
|
|
52
65
|
}
|
|
53
66
|
/** The plan change confirmation of one component. */
|
|
54
67
|
export interface PlanChangeConfirm {
|
|
55
68
|
/** What it was built with. */
|
|
56
69
|
options: PlanChangeConfirmOptions;
|
|
57
70
|
/** The price the group is open for, `null` while it is closed. */
|
|
58
|
-
target: Ref<PlanChangeTarget | null>;
|
|
71
|
+
target: Ref<Required<PlanChangeTarget> | null>;
|
|
59
72
|
/** What switching to it would do; `null` while closed, or for a change there is none to make. */
|
|
60
73
|
preview: ComputedRef<PlanChangePreview | null>;
|
|
61
|
-
/** `true` while the group is open for a switch it can describe: one
|
|
74
|
+
/** `true` while the group is open for a switch it can describe: one the preview knows, or a gifted plan's checkout. */
|
|
62
75
|
shows: ComputedRef<boolean>;
|
|
63
|
-
/** When the switch happens and how it settles, in the
|
|
76
|
+
/** When the switch happens and how it settles, in the component's words. */
|
|
64
77
|
when: ComputedRef<string>;
|
|
65
78
|
/** What the button that opens and closes the group for `target` carries, over its own props. */
|
|
66
79
|
toggleProps: (target: PlanChangeTarget) => Record<string, unknown>;
|
|
@@ -71,6 +84,5 @@ export interface PlanChangeConfirm {
|
|
|
71
84
|
/** Close the group once the switch went through; the component moves focus to what took its place. */
|
|
72
85
|
settle: () => void;
|
|
73
86
|
}
|
|
74
|
-
/** Build the plan change confirmation of a component. */
|
|
87
|
+
/** Build the plan change confirmation of a component, over the plan change it confirms. */
|
|
75
88
|
export declare function createPlanChangeConfirm(options: PlanChangeConfirmOptions): PlanChangeConfirm;
|
|
76
|
-
export {};
|
|
@@ -1,32 +1,41 @@
|
|
|
1
1
|
import { computed, nextTick, ref } from "vue";
|
|
2
2
|
import { returnFocus } from "./focus-return.js";
|
|
3
3
|
export const CONFIRMED_PRORATION = "invoice";
|
|
4
|
+
export function planChangeWhen(words) {
|
|
5
|
+
const { applies, preview, price, t } = words;
|
|
6
|
+
if (applies === "checkout") return words.gifted;
|
|
7
|
+
if (!preview) return "";
|
|
8
|
+
if (preview.trial) return t(preview.applies === "period_end" ? "changeTrialLater" : preview.proration === "none" ? "changeTrial" : "changeTrialEnds", { price });
|
|
9
|
+
if (preview.applies === "now") return t("changeNow", { price });
|
|
10
|
+
const date = preview.appliesAt ? words.date(preview.appliesAt) : null;
|
|
11
|
+
return date ? t("changeLater", { price, date }) : t("changeLaterPeriod", { price });
|
|
12
|
+
}
|
|
4
13
|
export function createPlanChangeConfirm(options) {
|
|
5
|
-
const
|
|
14
|
+
const { change } = options;
|
|
6
15
|
const opener = ref(null);
|
|
7
|
-
const preview = computed(() => target.value ? options.preview(target.value.productId) : null);
|
|
8
|
-
const gifted = computed(() => target.value && options.gifted ? options.gifted(target.value) : null);
|
|
9
16
|
const when = computed(() => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
const target = change.target.value;
|
|
18
|
+
if (!target) return "";
|
|
19
|
+
return planChangeWhen({
|
|
20
|
+
applies: change.applies.value,
|
|
21
|
+
preview: change.preview.value,
|
|
22
|
+
price: target.price,
|
|
23
|
+
gifted: options.gifted?.(target) ?? "",
|
|
24
|
+
t: options.t,
|
|
25
|
+
date: options.date
|
|
26
|
+
});
|
|
18
27
|
});
|
|
19
28
|
const close = () => {
|
|
20
29
|
if (options.isBusy()) return;
|
|
21
|
-
|
|
30
|
+
change.close();
|
|
22
31
|
void nextTick(() => returnFocus(opener.value));
|
|
23
32
|
};
|
|
24
33
|
const open = (next, from = null) => {
|
|
25
|
-
|
|
34
|
+
change.open(next);
|
|
26
35
|
opener.value = from;
|
|
27
36
|
};
|
|
28
37
|
const toggleProps = (next) => {
|
|
29
|
-
const isOpen = target.value?.key === next.key;
|
|
38
|
+
const isOpen = change.target.value?.key === (next.key ?? next.productId);
|
|
30
39
|
return {
|
|
31
40
|
"aria-expanded": isOpen ? "true" : "false",
|
|
32
41
|
"data-state": isOpen ? "open" : "closed",
|
|
@@ -34,6 +43,6 @@ export function createPlanChangeConfirm(options) {
|
|
|
34
43
|
"onClick": (event) => isOpen ? close() : open(next, event.currentTarget)
|
|
35
44
|
};
|
|
36
45
|
};
|
|
37
|
-
const shows = computed(() => target.value !== null &&
|
|
38
|
-
return { options, target, preview, shows, when, toggleProps, open, close, settle: () =>
|
|
46
|
+
const shows = computed(() => change.target.value !== null && change.applies.value !== null);
|
|
47
|
+
return { options, target: change.target, preview: change.preview, shows, when, toggleProps, open, close, settle: () => change.close() };
|
|
39
48
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { PricedPromotion } from '../../../convex/integrations/billing/types/records.js';
|
|
2
|
+
import type { CheckoutOptions } from '../composables/use-billing.js';
|
|
3
|
+
import type { UseCampaignReturn } from '../composables/use-campaign.js';
|
|
4
|
+
/** What a pricing view's checkout reads. */
|
|
5
|
+
export interface PricingCheckoutContext {
|
|
6
|
+
/** The address's campaign: its discount code and UTM attribution. */
|
|
7
|
+
campaign: Pick<UseCampaignReturn, 'checkoutOptions'>;
|
|
8
|
+
/** The promotion the view asked the pricing for (`usePricing({ discount })`): a key, a code, or the campaign link's own code. */
|
|
9
|
+
asked: () => string | undefined;
|
|
10
|
+
/** The promotion that runs now (`usePricing().activePromotion`). */
|
|
11
|
+
active: () => PricedPromotion | undefined;
|
|
12
|
+
/** Every currency the catalog prices (`usePricing().currencies`). */
|
|
13
|
+
currencies: () => string[];
|
|
14
|
+
}
|
|
15
|
+
/** The campaign's part of one checkout: a discount, and the attribution. */
|
|
16
|
+
export type CampaignCheckoutOptions = Pick<CheckoutOptions, 'discount' | 'discountCode' | 'utm'>;
|
|
17
|
+
/** A pricing view's checkout, as far as the campaign and the currency go. */
|
|
18
|
+
export interface PricingCheckout {
|
|
19
|
+
/**
|
|
20
|
+
* The currency a checkout of a price shown in `currency` pays in: a
|
|
21
|
+
* product the catalog prices in one currency only shows, and is paid, in
|
|
22
|
+
* that one whatever the page's. Named only where the catalog prices more
|
|
23
|
+
* than one; a single-currency checkout keeps the provider's own.
|
|
24
|
+
*/
|
|
25
|
+
payIn: (currency: string | undefined) => {
|
|
26
|
+
currency?: string;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Start a checkout with the campaign: the view's promotion, on a price it
|
|
30
|
+
* is `offered` on, in the place of the campaign link's code (one discount
|
|
31
|
+
* per checkout), else that code. A view that shows a promotion for the
|
|
32
|
+
* campaign link's own code sends the code. When the server refuses the
|
|
33
|
+
* discount (an expired, used-up or unknown code, a promotion no longer
|
|
34
|
+
* redeemed), the checkout starts again without it, the attribution kept.
|
|
35
|
+
*/
|
|
36
|
+
withCampaign: <T>(offered: boolean, start: (options: CampaignCheckoutOptions) => Promise<T>) => Promise<T>;
|
|
37
|
+
}
|
|
38
|
+
/** The campaign and currency rules of one pricing view's checkouts. */
|
|
39
|
+
export declare function pricingCheckout(context: PricingCheckoutContext): PricingCheckout;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { getBackendError } from "./backend-error.js";
|
|
2
|
+
function refusedCode(failure) {
|
|
3
|
+
const refusal = getBackendError(failure);
|
|
4
|
+
const field = refusal?.data?.field;
|
|
5
|
+
return refusal?.code === "invalid_input" && (field === "discountCode" || field === "discount");
|
|
6
|
+
}
|
|
7
|
+
export function pricingCheckout(context) {
|
|
8
|
+
return {
|
|
9
|
+
payIn: (currency) => currency && context.currencies().length > 1 ? { currency } : {},
|
|
10
|
+
withCampaign: async (offered, start) => {
|
|
11
|
+
const { discountCode, ...attribution } = context.campaign.checkoutOptions.value;
|
|
12
|
+
const promotion = context.asked() === discountCode ? void 0 : context.active()?.key;
|
|
13
|
+
const options = promotion && offered ? { ...attribution, discount: promotion } : { ...attribution, ...discountCode ? { discountCode } : {} };
|
|
14
|
+
try {
|
|
15
|
+
return await start(options);
|
|
16
|
+
} catch (failure) {
|
|
17
|
+
if (!("discountCode" in options || "discount" in options) || !refusedCode(failure)) throw failure;
|
|
18
|
+
return start(attribution);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -12,6 +12,8 @@ export declare function tabKeep(key: string): TabKeep;
|
|
|
12
12
|
/**
|
|
13
13
|
* The token in the address's fragment (`#<token>`), taken off the address
|
|
14
14
|
* at once, so it is neither bookmarked nor copied with it. A fragment that
|
|
15
|
-
* is no valid encoding is read as it stands. `null` without one
|
|
15
|
+
* is no valid encoding is read as it stands. `null` without one, and for
|
|
16
|
+
* one that names an element of the page: an in-page link (`#how-it-works`),
|
|
17
|
+
* left for the browser to scroll to.
|
|
16
18
|
*/
|
|
17
19
|
export declare function takeFragment(): string | null;
|
|
@@ -40,7 +40,7 @@ export function takeFragment() {
|
|
|
40
40
|
} catch {
|
|
41
41
|
token = hash.trim();
|
|
42
42
|
}
|
|
43
|
-
if (!token) return null;
|
|
43
|
+
if (!token || document.getElementById(token) !== null) return null;
|
|
44
44
|
window.history.replaceState(window.history.state, "", window.location.pathname + window.location.search);
|
|
45
45
|
return token;
|
|
46
46
|
}
|