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.
Files changed (75) hide show
  1. package/README.md +2 -0
  2. package/dist/chunks/catalog.mjs +1 -1
  3. package/dist/chunks/doctor.mjs +4 -4
  4. package/dist/chunks/email-previews.mjs +1 -1
  5. package/dist/chunks/health.mjs +2 -2
  6. package/dist/chunks/index.mjs +2 -2
  7. package/dist/chunks/install.mjs +8 -8
  8. package/dist/chunks/run.mjs +1 -1
  9. package/dist/chunks/server.mjs +4 -4
  10. package/dist/cli.mjs +9 -52
  11. package/dist/devtools-client/index.html +1 -1
  12. package/dist/module.js +2 -2
  13. package/dist/module.json +1 -1
  14. package/dist/runtime/vue/components/auth/InviteRedeem.vue +4 -22
  15. package/dist/runtime/vue/components/auth/WaitlistStatus.vue +7 -17
  16. package/dist/runtime/vue/components/billing/PricingTable.vue +17 -51
  17. package/dist/runtime/vue/components/billing/ReferralLanding.vue +1 -2
  18. package/dist/runtime/vue/components/workspaces/WorkspaceBilling.vue +15 -18
  19. package/dist/runtime/vue/components/workspaces/WorkspaceBillingPause.vue +1 -2
  20. package/dist/runtime/vue/components/workspaces/WorkspaceSettings.d.vue.ts +2 -2
  21. package/dist/runtime/vue/components/workspaces/WorkspaceSettings.vue +9 -22
  22. package/dist/runtime/vue/components/workspaces/WorkspaceSettings.vue.d.ts +2 -2
  23. package/dist/runtime/vue/components/workspaces/workspace-billing.d.ts +12 -16
  24. package/dist/runtime/vue/components/workspaces/workspace-billing.js +22 -37
  25. package/dist/runtime/vue/composables/use-access.d.ts +18 -0
  26. package/dist/runtime/vue/composables/use-access.js +33 -6
  27. package/dist/runtime/vue/composables/use-billing-section.d.ts +115 -0
  28. package/dist/runtime/vue/composables/use-billing-section.js +76 -0
  29. package/dist/runtime/vue/composables/use-gift-form.js +7 -24
  30. package/dist/runtime/vue/composables/use-gift-list.d.ts +18 -1
  31. package/dist/runtime/vue/composables/use-gift-list.js +6 -1
  32. package/dist/runtime/vue/composables/use-plan-change.d.ts +148 -0
  33. package/dist/runtime/vue/composables/use-plan-change.js +130 -0
  34. package/dist/runtime/vue/composables/use-pricing.d.ts +29 -0
  35. package/dist/runtime/vue/composables/use-pricing.js +53 -14
  36. package/dist/runtime/vue/composables/use-referral-invite.d.ts +7 -0
  37. package/dist/runtime/vue/composables/use-referral-invite.js +4 -1
  38. package/dist/runtime/vue/composables/use-waitlist.d.ts +18 -0
  39. package/dist/runtime/vue/composables/use-waitlist.js +24 -0
  40. package/dist/runtime/vue/pages/pricing.vue +1 -2
  41. package/dist/runtime/vue/plugins/checkout-return.js +9 -2
  42. package/dist/runtime/vue/utils/checkout-return.d.ts +11 -1
  43. package/dist/runtime/vue/utils/checkout-return.js +6 -2
  44. package/dist/runtime/vue/utils/gift-days.d.ts +20 -0
  45. package/dist/runtime/vue/utils/gift-days.js +32 -0
  46. package/dist/runtime/vue/utils/namespace.js +7 -2
  47. package/dist/runtime/vue/utils/page-open.d.ts +1 -0
  48. package/dist/runtime/vue/utils/page-open.js +12 -0
  49. package/dist/runtime/vue/utils/plan-change-confirm.d.ts +38 -26
  50. package/dist/runtime/vue/utils/plan-change-confirm.js +25 -16
  51. package/dist/runtime/vue/utils/pricing-checkout.d.ts +39 -0
  52. package/dist/runtime/vue/utils/pricing-checkout.js +22 -0
  53. package/dist/runtime/vue/utils/tab-keep.d.ts +3 -1
  54. package/dist/runtime/vue/utils/tab-keep.js +1 -1
  55. package/dist/shared/{nuxt-backend.CbR37s_c.mjs → nuxt-backend.BqXAZChe.mjs} +23 -3
  56. package/dist/shared/{nuxt-backend.BjQoqNIu.mjs → nuxt-backend.CBvrM7pG.mjs} +1 -1
  57. package/dist/shared/{nuxt-backend.Baxb382E.mjs → nuxt-backend.DH1Ya3uB.mjs} +1 -1
  58. package/dist/shared/{nuxt-backend.9IVxzzft.mjs → nuxt-backend.DbaXvH__.mjs} +1 -1
  59. package/dist/shared/{nuxt-backend.BCjeoX0x.mjs → nuxt-backend.Dikfaocl.mjs} +56 -8
  60. package/package.json +1 -1
  61. package/skills/nuxt-backend/references/api.md +2 -0
  62. package/skills/nuxt-backend/references/install.md +4 -1
  63. package/skills/nuxt-backend/references/renames.json +8 -0
  64. package/skills/nuxt-backend/references/surface.json +2 -0
  65. package/skills/nuxt-backend-billing/SKILL.md +9 -0
  66. package/skills/nuxt-backend-billing/references/api.md +2 -0
  67. package/skills/nuxt-backend-upgrade/references/upgrade.md +6 -0
  68. package/src/runtime/vue/components/auth/InviteRedeem.vue +5 -26
  69. package/src/runtime/vue/components/auth/WaitlistStatus.vue +11 -20
  70. package/src/runtime/vue/components/billing/PricingTable.vue +25 -82
  71. package/src/runtime/vue/components/billing/ReferralLanding.vue +1 -2
  72. package/src/runtime/vue/components/workspaces/WorkspaceBilling.vue +21 -25
  73. package/src/runtime/vue/components/workspaces/WorkspaceBillingPause.vue +1 -2
  74. package/src/runtime/vue/components/workspaces/WorkspaceSettings.vue +16 -29
  75. package/src/runtime/vue/pages/pricing.vue +1 -4
@@ -1,8 +1,8 @@
1
1
  import { useLogger, addPlugin, hasNuxtModule, addVitePlugin, addServerHandler, addNitroPlugin, extendRouteRules, extendPages, addTypeTemplate, addPluginTemplate, updateTemplates, addImports, addComponent, addServerImports, addRouteMiddleware, addTemplate, resolveModule, defineNuxtModule, createResolver } from '@nuxt/kit';
2
2
  import { defu } from 'defu';
3
- import { j as resolveFunctionsDir, T as BACKEND_PAGE_DEFS, a1 as pagePathShape, J as computeDeployment, a2 as collectPreflightFindings, N as detectCapabilities, K as appMonitoringDsn, L as monitoringSdkInstalled, a3 as OPTIONAL_DEPLOYMENT_ENV, a4 as REQUIRED_DEPLOYMENT_ENV, a5 as deriveDeploymentUrls, a6 as provisionedEnvNames, a7 as appComponentIsStarter, r as readEnvFiles, a8 as resolveSiteUrl, _ as formatPreflightSummary, a9 as needsSetup, aa as AGENT_HINT, ab as HEALTH_ROUTE, ac as LOCAL_LOG_ROUTE, ad as monitoringSdkVersion, ae as MONITORING_SDK, af as TUNNEL_SDK_VERSION, ag as SOURCE_MAP_ENV, ah as sdkServesTunnel, ai as installableProblems, aj as pagesOptionProblems, ak as resolvedBackendPages, al as DEFAULT_AUTH_ROUTE, Q as REGISTERED_UI, am as publishedBackendPages, an as isPageOff, ao as privatePagePaths, ap as collectExistingPagePaths, aq as adoptChildPages, ar as pageRouteRules, as as cachingRulesOver, V as packageDir, z as appBrandOf, A as syncBrandFile, E as brandFileLocation, F as appLabelsOf, G as syncLabelsFile, H as labelsFileLocation, at as PUSH_WORKER_URL, au as ownsManifest, av as MANIFEST_MODULES, aw as namedIconWarnings, ax as installableGaps, ay as installIcons, az as webAppManifest, aA as maskableIcons, aB as MANIFEST_ROUTE, aC as APPLE_TOUCH_ICON, aD as themeColorMeta, w as syncPathsFile, x as backendPathsOf, y as pathsFileLocation, S as uiPath, aE as UI_SHARED_STYLES, aF as UI_ENTRIES, aG as UI_INTERNALS, aH as moduleDir, aI as VISITOR_IP_ROUTE, aJ as resolvePagePath, aK as dependencyRange, aL as runsFromSource, Y as packageVersion } from './nuxt-backend.9IVxzzft.mjs';
3
+ import { j as resolveFunctionsDir, T as BACKEND_PAGE_DEFS, a1 as pagePathShape, J as computeDeployment, a2 as collectPreflightFindings, N as detectCapabilities, K as appMonitoringDsn, L as monitoringSdkInstalled, a3 as OPTIONAL_DEPLOYMENT_ENV, a4 as REQUIRED_DEPLOYMENT_ENV, a5 as deriveDeploymentUrls, a6 as provisionedEnvNames, a7 as appComponentIsStarter, r as readEnvFiles, a8 as resolveSiteUrl, _ as formatPreflightSummary, a9 as needsSetup, aa as AGENT_HINT, ab as HEALTH_ROUTE, ac as LOCAL_LOG_ROUTE, ad as monitoringSdkVersion, ae as MONITORING_SDK, af as TUNNEL_SDK_VERSION, ag as SOURCE_MAP_ENV, ah as sdkServesTunnel, ai as installableProblems, aj as pagesOptionProblems, ak as resolvedBackendPages, al as DEFAULT_AUTH_ROUTE, Q as REGISTERED_UI, am as publishedBackendPages, an as isPageOff, ao as privatePagePaths, ap as collectExistingPagePaths, aq as adoptChildPages, ar as pageRouteRules, as as cachingRulesOver, V as packageDir, z as appBrandOf, A as syncBrandFile, E as brandFileLocation, F as appLabelsOf, G as syncLabelsFile, H as labelsFileLocation, at as PUSH_WORKER_URL, au as ownsManifest, av as MANIFEST_MODULES, aw as namedIconWarnings, ax as installableGaps, ay as installIcons, az as webAppManifest, aA as maskableIcons, aB as MANIFEST_ROUTE, aC as APPLE_TOUCH_ICON, aD as themeColorMeta, w as syncPathsFile, x as backendPathsOf, y as pathsFileLocation, S as uiPath, aE as UI_SHARED_STYLES, aF as UI_ENTRIES, aG as UI_INTERNALS, aH as moduleDir, aI as VISITOR_IP_ROUTE, aJ as resolvePagePath, aK as dependencyRange, aL as runsFromSource, Y as packageVersion } from './nuxt-backend.DbaXvH__.mjs';
4
4
  import { backendAppConfigDefaults } from '../../dist/runtime/config.js';
5
- import { existsSync, readFileSync, readdirSync, realpathSync } from 'node:fs';
5
+ import { readFileSync, existsSync, readdirSync, realpathSync } from 'node:fs';
6
6
  import { join, resolve, extname, dirname } from 'node:path';
7
7
  import { detectAgent } from 'std-env';
8
8
  import { createRequire } from 'node:module';
@@ -14,6 +14,22 @@ function hasGeneratedApi(rootDir, functionsDir = resolveFunctionsDir(rootDir)) {
14
14
  const generatedApi = join(rootDir, functionsDir, "_generated", "api");
15
15
  return existsSync(`${generatedApi}.d.ts`) || existsSync(`${generatedApi}.js`);
16
16
  }
17
+ function generatedModules(rootDir, functionsDir = resolveFunctionsDir(rootDir)) {
18
+ let source;
19
+ try {
20
+ source = readFileSync(join(rootDir, functionsDir, "_generated", "api.d.ts"), "utf8");
21
+ } catch {
22
+ return null;
23
+ }
24
+ const block = /ApiFromModules<\{([^}]*)\}>/.exec(source)?.[1];
25
+ if (block === void 0) return null;
26
+ if (block.trim() === "") return [];
27
+ const names = /* @__PURE__ */ new Set();
28
+ for (const [, quoted, bare] of block.matchAll(/^\s*(?:"([^"]+)"|([\w$]+))\s*:\s*typeof\b/gm)) {
29
+ names.add((quoted ?? bare).split("/")[0]);
30
+ }
31
+ return names.size > 0 ? [...names].sort() : null;
32
+ }
17
33
  function getBackendAliases(rootDir, runtimeDir) {
18
34
  const functionsDir = resolveFunctionsDir(rootDir);
19
35
  const backendDir = join(rootDir, functionsDir);
@@ -863,6 +879,8 @@ function registerSaasComposables(resolver) {
863
879
  { name: "useFeatures", from: resolver.resolve("./runtime/vue/composables/use-features") },
864
880
  { name: "useCredits", from: resolver.resolve("./runtime/vue/composables/use-credits") },
865
881
  { name: "usePricing", from: resolver.resolve("./runtime/vue/composables/use-pricing") },
882
+ { name: "usePlanChange", from: resolver.resolve("./runtime/vue/composables/use-plan-change") },
883
+ { name: "useBillingSection", from: resolver.resolve("./runtime/vue/composables/use-billing-section") },
866
884
  { name: "useCampaign", from: resolver.resolve("./runtime/vue/composables/use-campaign") },
867
885
  { name: "useOrders", from: resolver.resolve("./runtime/vue/composables/use-orders") },
868
886
  { name: "useUsage", from: resolver.resolve("./runtime/vue/composables/use-usage") },
@@ -1050,7 +1068,9 @@ function registerBackendApi(resolver, nuxt) {
1050
1068
  "import { defineNuxtPlugin } from '#app'",
1051
1069
  "import { api } from '#backend/api'",
1052
1070
  `import { provideBackendApi } from ${JSON.stringify(namespaceModule)}`,
1053
- "export default defineNuxtPlugin({ name: 'nuxt-backend:api', setup(nuxtApp) { provideBackendApi(api, nuxtApp.vueApp) } })",
1071
+ // The top-level names codegen listed: `api` itself answers any name.
1072
+ `const modules = ${JSON.stringify(generatedModules(nuxt.options.rootDir, functionsDir))}`,
1073
+ "export default defineNuxtPlugin({ name: 'nuxt-backend:api', setup(nuxtApp) { provideBackendApi(api, nuxtApp.vueApp, modules ?? undefined) } })",
1054
1074
  ""
1055
1075
  ].join("\n") : "import { defineNuxtPlugin } from '#app'\nexport default defineNuxtPlugin({ name: 'nuxt-backend:api', setup() {} })\n"
1056
1076
  });
@@ -1,4 +1,4 @@
1
- import { bF as CAPABILITIES, aO as BACKEND_ENV, j as resolveFunctionsDir, u as scaffoldBackendFiles, q as configuredDeployment, I as isDevDeploymentId, bG as isEnvProvisioned, a0 as devPushRefusal, bH as markEnvProvisioned, a$ as finding, $ as runEnvPush, t as spawnConvex } from './nuxt-backend.9IVxzzft.mjs';
1
+ import { bF as CAPABILITIES, aO as BACKEND_ENV, j as resolveFunctionsDir, u as scaffoldBackendFiles, q as configuredDeployment, I as isDevDeploymentId, bG as isEnvProvisioned, a0 as devPushRefusal, bH as markEnvProvisioned, a$ as finding, $ as runEnvPush, t as spawnConvex } from './nuxt-backend.DbaXvH__.mjs';
2
2
  import { existsSync, writeFileSync, readFileSync } from 'node:fs';
3
3
  import { resolve, join, delimiter } from 'node:path';
4
4
  import { defineCommand } from 'citty';
@@ -1,7 +1,7 @@
1
1
  import { existsSync, readFileSync, readdirSync } from 'node:fs';
2
2
  import { createRequire } from 'node:module';
3
3
  import { join } from 'node:path';
4
- import { a$ as finding, j as resolveFunctionsDir, bI as readSource, bJ as parse, bK as keyOf, bL as writeSource, bM as REMOVED_ENV, bN as applyEdits, bO as walk, bP as BACKEND_FILE_TEMPLATES } from './nuxt-backend.9IVxzzft.mjs';
4
+ import { a$ as finding, j as resolveFunctionsDir, bI as readSource, bJ as parse, bK as keyOf, bL as writeSource, bM as REMOVED_ENV, bN as applyEdits, bO as walk, bP as BACKEND_FILE_TEMPLATES } from './nuxt-backend.DbaXvH__.mjs';
5
5
 
6
6
  const LAST_SCAFFOLD_MOUNT = "@convex-dev/workpool/convex.config";
7
7
  const OPTIONAL_MOUNTS = [
@@ -897,7 +897,7 @@ const TASK_SKILLS = [
897
897
  covers: "the catalog, plans, checkout, the portal, feature gates, plan quotas and credits",
898
898
  docs: ["/docs/build/billing"],
899
899
  entrypoints: ["nuxt-backend/billing"],
900
- composables: ["useBilling", "useFeatures", "useCredits", "usePricing", "useOrders", "useUsage", "useWithdrawal", "formatBillingAmount"],
900
+ composables: ["useBilling", "useFeatures", "useCredits", "usePricing", "usePlanChange", "useBillingSection", "useOrders", "useUsage", "useWithdrawal", "formatBillingAmount"],
901
901
  components: ["PricingTable", "BillingCheckoutLink", "BillingPortalLink", "BillingHistory", "UsageHistory", "UpgradePrompt", "CancelFlow", "WithdrawalButton"],
902
902
  commands: ["billing sync", "billing reset", "billing resync"],
903
903
  findings: ["billing"],
@@ -1,9 +1,52 @@
1
1
  import { spawnSync } from 'node:child_process';
2
- import { existsSync, writeFileSync, readFileSync } from 'node:fs';
2
+ import { existsSync, readFileSync, writeFileSync } from 'node:fs';
3
3
  import { createRequire } from 'node:module';
4
- import { join } from 'node:path';
5
- import { u as scaffoldBackendFiles, aR as mountPagesInAppComponent, aS as ensureDefaultLayout, aT as writeAgentFiles, U as installedVersion, M as MCP_SDK, V as packageDir } from './nuxt-backend.9IVxzzft.mjs';
6
- import { a as adoptBackendDevScript, r as renderEnvExample } from './nuxt-backend.BjQoqNIu.mjs';
4
+ import { join, dirname } from 'node:path';
5
+ import { u as scaffoldBackendFiles, aR as mountPagesInAppComponent, aS as ensureDefaultLayout, aT as writeAgentFiles, U as installedVersion, M as MCP_SDK, V as packageDir } from './nuxt-backend.DbaXvH__.mjs';
6
+ import { a as adoptBackendDevScript, r as renderEnvExample } from './nuxt-backend.CBvrM7pG.mjs';
7
+
8
+ const LOCKFILES = [
9
+ ["pnpm-lock.yaml", "pnpm"],
10
+ ["yarn.lock", "yarn"],
11
+ ["bun.lock", "bun"],
12
+ ["bun.lockb", "bun"],
13
+ ["package-lock.json", "npm"],
14
+ ["npm-shrinkwrap.json", "npm"]
15
+ ];
16
+ function pinned(dir) {
17
+ try {
18
+ const field = JSON.parse(readFileSync(join(dir, "package.json"), "utf8")).packageManager;
19
+ const name = typeof field === "string" ? field.split("@")[0] : void 0;
20
+ return LOCKFILES.find(([, manager]) => manager === name)?.[1] ?? null;
21
+ } catch {
22
+ return null;
23
+ }
24
+ }
25
+ function packageManagerOf(rootDir) {
26
+ let dir = rootDir;
27
+ for (; ; ) {
28
+ const manager = pinned(dir) ?? LOCKFILES.find(([file]) => existsSync(join(dir, file)))?.[1];
29
+ if (manager) return manager;
30
+ if (dir === dirname(dir) || existsSync(join(dir, ".git"))) return "npm";
31
+ dir = dirname(dir);
32
+ }
33
+ }
34
+ function runScript(manager, script) {
35
+ return `${manager} run ${script}`;
36
+ }
37
+ function execBinary(manager, binary) {
38
+ switch (manager) {
39
+ case "pnpm":
40
+ return `pnpm exec ${binary}`;
41
+ // Yarn 1 and Yarn Berry both run an installed binary by its name, Plug'n'Play too.
42
+ case "yarn":
43
+ return `yarn ${binary}`;
44
+ case "bun":
45
+ return `bunx ${binary}`;
46
+ default:
47
+ return `npx ${binary}`;
48
+ }
49
+ }
7
50
 
8
51
  const ENV_EXAMPLE = renderEnvExample();
9
52
  function declareConvexDependency(rootDir) {
@@ -76,22 +119,27 @@ function adoptProjectFiles(rootDir, print) {
76
119
  if (convexDependency) {
77
120
  print(`[nuxt-backend] Added convex@${convexDependency} to dependencies (\`npx convex dev\` needs the app itself to declare it)`);
78
121
  }
122
+ const packageManager = packageManagerOf(rootDir);
79
123
  return {
80
124
  devScript: devScript?.changed ? devScript.script : null,
81
125
  convexDependency,
82
- start: devScript ? "npm run dev" : "npx nuxt-backend dev"
126
+ packageManager,
127
+ start: devScript ? runScript(packageManager, "dev") : execBinary(packageManager, "nuxt-backend dev")
83
128
  };
84
129
  }
85
130
  function addedDependencies(setup) {
86
131
  return Boolean(setup.convexDependency || setup.mcpSdkDependency);
87
132
  }
133
+ function installCommand(packageManager) {
134
+ return `${packageManager} install`;
135
+ }
88
136
  function nextCommands(setup, { installed = false } = {}) {
89
- return [...addedDependencies(setup) && !installed ? ["npm install"] : [], setup.start];
137
+ return [...addedDependencies(setup) && !installed ? [installCommand(setup.packageManager)] : [], setup.start];
90
138
  }
91
139
  function formatNextSteps(setup, { installed = false } = {}) {
92
140
  const comment = (command, text) => ` ${command.padEnd(27)}# ${text}`;
93
141
  const added = setup.convexDependency && setup.mcpSdkDependency ? "convex and the MCP SDK, added above" : setup.convexDependency ? "the convex dependency added above" : "the MCP SDK added above";
94
- const install = addedDependencies(setup) && !installed ? [comment("npm install", `links ${added}`)] : [];
142
+ const install = addedDependencies(setup) && !installed ? [comment(installCommand(setup.packageManager), `links ${added}`)] : [];
95
143
  return [
96
144
  "Next steps:",
97
145
  ...install,
@@ -116,4 +164,4 @@ function installDeclaredDependencies(rootDir, packageManager) {
116
164
  }
117
165
  }
118
166
 
119
- export { setUpAgentFiles as a, addedDependencies as b, formatNextSteps as f, installDeclaredDependencies as i, nextCommands as n, setUpProject as s };
167
+ export { setUpAgentFiles as a, addedDependencies as b, installDeclaredDependencies as c, execBinary as e, formatNextSteps as f, installCommand as i, nextCommands as n, packageManagerOf as p, runScript as r, setUpProject as s };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "nuxt-backend",
4
- "version": "0.4.0",
4
+ "version": "0.5.0",
5
5
  "description": "The complete backend for a Nuxt app on Convex: passwordless sign-in with passkeys, workspaces, plans and credits, email, notifications and metered AI, with the pages that use them, in one module.",
6
6
  "repository": {
7
7
  "type": "git",
@@ -23,6 +23,8 @@ skill's own `references/api.md` has the part it covers. The docs: https://nuxt-b
23
23
  | `useFeatures()` | Reactive feature-gating for the current user — the SaaS access primitive. |
24
24
  | `useCredits()` | Reactive prepaid-credit balance for the current user, plus a `topUp()` checkout and a `refresh()` re-sync. |
25
25
  | `usePricing()` | The app's plans and credit packs as a pricing page shows them — every plan with its monthly and yearly price, what a year saves, its trial and the credits it grants per cycle; every pack with its price per credit and which is the best value — read through the scaffolded `getPricing`, in the visitor's currency where the catalog prices it. |
26
+ | `usePlanChange()` | A subscriber's switch to another plan or billing period, without its markup: the prices it can move to, in the subscription's own currency, and one confirmation that says what the switch does before it does it — the price, when it happens (a yearly price left for a monthly one waits for the paid year's end) and how the period's difference is settled, or, in a trial, what becomes of it — then the switch itself, settling that difference at once (`proration: 'invoice'`), so the words stay true whatever the organization's default. |
27
+ | `useBillingSection()` | The billing section of `/settings` without its markup: the state the plan is in, in the order the section tries them (a gifted plan, a failed payment, a pause, a cancellation or a plan change set for the period's end, a trial, else active), a read that failed as a failure rather than a plan, a return from checkout still finishing as busy, and what each state calls for, with the rules each offer follows: a switch only while nothing is scheduled, a pause only while none is, and its resume date counted the way the provider counts months. |
26
28
  | `useCampaign()` | The campaign a visitor arrived with, read from the address: a campaign link's discount code and its UTM attribution, ready for checkout. |
27
29
  | `useOrders()` | The signed-in customer's billing history — past charges straight from the provider's orders API, plus the per-order invoice link. |
28
30
  | `useUsage()` | Consumption history for a credit meter, read from the provider's events API — the events your server ingested when it spent credits. |
@@ -104,12 +104,15 @@ the user before editing it; don't overwrite their code.
104
104
 
105
105
  pnpm notes:
106
106
 
107
- - pnpm 11 stops an install on dependency build scripts it has not been told about. Show the user
107
+ - pnpm 11 and later stop an install on dependency build scripts they have not been told about. Show the user
108
108
  the list and let them choose: approve or deny with `pnpm approve-builds`, or in `allowBuilds` in
109
109
  `pnpm-workspace.yaml`. `esbuild` works without its script. Don't turn off `strictDepBuilds`.
110
110
  - pnpm's default layout hides the Convex components nuxt-backend brings, and Convex needs to
111
111
  resolve them: add `publicHoistPattern: ['@convex-dev/*']` to `pnpm-workspace.yaml`, then install
112
112
  again. (Apps made from the starter carry both settings in `.pnpmfile.mjs`.)
113
+ - pnpm 12 lists nuxt-backend under "Agent skills awaiting approval". `init` already installed
114
+ those skills in `.agents/skills`, and approving links a second copy of each. Tell the user, and
115
+ suggest denying it: `pnpm approve '!nuxt-backend'`.
113
116
 
114
117
  ## 2. Start it: the deployment, its env, the generated code
115
118
 
@@ -1,6 +1,14 @@
1
1
  {
2
2
  "$comment": "Every public name a release renamed, reshaped or removed, with the Upgrade page section that explains it. `npx nuxt-backend upgrade` rewrites none of an app's code: the edit is yours. Generated by `pnpm generate` (scripts/agent-guidance.mjs). Do not edit: change the code it reads.",
3
3
  "renames": [
4
+ {
5
+ "from": "api",
6
+ "to": "_generated/api.d.ts",
7
+ "change": "reshaped",
8
+ "section": "A composable falls back when the app lacks its backend file",
9
+ "note": "the packaged plugin provides only the modules `_generated/api.d.ts` lists, so a namespace it doesn't list reads as absent and its composable falls back; an app that commits `_generated/` commits it again after adding a backend file",
10
+ "url": "https://nuxt-backend.dev/docs/ship/releases/upgrade#a-composable-falls-back-when-the-app-lacks-its-backend-file"
11
+ },
4
12
  {
5
13
  "from": "doctor --fix",
6
14
  "to": "--yes",
@@ -897,6 +897,7 @@
897
897
  "useBackendConfig",
898
898
  "useBackendPagePath",
899
899
  "useBilling",
900
+ "useBillingSection",
900
901
  "useCampaign",
901
902
  "useChat",
902
903
  "useConnectionState",
@@ -927,6 +928,7 @@
927
928
  "useOnboarding",
928
929
  "useOrders",
929
930
  "usePasskeys",
931
+ "usePlanChange",
930
932
  "usePricing",
931
933
  "usePushSubscription",
932
934
  "useReauthentication",
@@ -103,12 +103,21 @@ credits and gifts.
103
103
  Nothing is stored on the device.
104
104
  - Out of credits: `usePricing().packFor(refusal.data.need)` is the smallest pack that covers an
105
105
  `insufficient_credits` refusal; `<BackendNotices />` shows the low-credits notice on its own.
106
+ - A pricing page of your own checks out with `usePricing().checkout('plan' | 'pack', key)`, the
107
+ table's rules: the campaign's code or the page's promotion, one discount, retried without a
108
+ refused one, the price's currency. A subscriber switches through `usePlanChange({ pricing })`
109
+ (prices in the subscription's currency, words from `changeOf`, `confirm()` with
110
+ `proration: 'invoice'`), never a `changePlan` without it behind words that say "settled now".
111
+ `usePricing().structuredData` is the schema.org data.
106
112
 
107
113
  ## The billing section of /settings
108
114
 
109
115
  - `<WorkspaceSettings>` (its `billing` section, on the ready-made `/settings`) follows the
110
116
  subscription's state: past due, paused, set to cancel, change scheduled, trial, active (the
111
117
  first that holds), with the actions the subscription allows, plus the benefits and the history.
118
+ A billing page of your own reads `useBillingSection()`: `state` (`error` for a failed read,
119
+ never active), `actions` in order, `pausable` (none while one is scheduled), `switchable`,
120
+ `resumesAfter(months)` and `pause(months)`. Never re-derive them from `useBilling()`.
112
121
  - Cancelling is one step there and on `<PricingTable>`'s current plan: what ends when and one
113
122
  button, nothing else. Never add a save offer, a question or a field to that confirmation.
114
123
  The provider keeps a reason and comment only with the cancellation itself (it refuses a
@@ -15,6 +15,8 @@ core skill, `nuxt-backend`, lists every public name in its own `references/api.m
15
15
  | `useFeatures()` | Reactive feature-gating for the current user — the SaaS access primitive. |
16
16
  | `useCredits()` | Reactive prepaid-credit balance for the current user, plus a `topUp()` checkout and a `refresh()` re-sync. |
17
17
  | `usePricing()` | The app's plans and credit packs as a pricing page shows them — every plan with its monthly and yearly price, what a year saves, its trial and the credits it grants per cycle; every pack with its price per credit and which is the best value — read through the scaffolded `getPricing`, in the visitor's currency where the catalog prices it. |
18
+ | `usePlanChange()` | A subscriber's switch to another plan or billing period, without its markup: the prices it can move to, in the subscription's own currency, and one confirmation that says what the switch does before it does it — the price, when it happens (a yearly price left for a monthly one waits for the paid year's end) and how the period's difference is settled, or, in a trial, what becomes of it — then the switch itself, settling that difference at once (`proration: 'invoice'`), so the words stay true whatever the organization's default. |
19
+ | `useBillingSection()` | The billing section of `/settings` without its markup: the state the plan is in, in the order the section tries them (a gifted plan, a failed payment, a pause, a cancellation or a plan change set for the period's end, a trial, else active), a read that failed as a failure rather than a plan, a return from checkout still finishing as busy, and what each state calls for, with the rules each offer follows: a switch only while nothing is scheduled, a pause only while none is, and its resume date counted the way the provider counts months. |
18
20
  | `useOrders()` | The signed-in customer's billing history — past charges straight from the provider's orders API, plus the per-order invoice link. |
19
21
  | `useUsage()` | Consumption history for a credit meter, read from the provider's events API — the events your server ingested when it spent credits. |
20
22
  | `useWithdrawal()` | The EU withdrawal window: whether the signed-in billing manager's purchase is still inside the 14 days of the Consumer Rights Directive's Art. 9, until when, and the withdrawal itself, the withdrawal function of its Art. 11a — what `<WithdrawalButton>` is built on, for a section of your own around it. |
@@ -17,6 +17,12 @@ has the reasons and every step. The core skill's `references/renames.json`, in
17
17
  After it, run `npx nuxt-backend doctor`, and `npx nuxt-backend init --agents` to refresh the app's
18
18
  agent files and skills.
19
19
 
20
+ ## [A composable falls back when the app lacks its backend file](https://nuxt-backend.dev/docs/ship/releases/upgrade#a-composable-falls-back-when-the-app-lacks-its-backend-file)
21
+
22
+ | Was | Now | Change | Note |
23
+ |---|---|---|---|
24
+ | `api` | `_generated/api.d.ts` | reshaped | the packaged plugin provides only the modules `_generated/api.d.ts` lists, so a namespace it doesn't list reads as absent and its composable falls back; an app that commits `_generated/` commits it again after adding a backend file |
25
+
20
26
  ## [`doctor --fix` asks before it syncs email, and a deploy runs the package's migrations](https://nuxt-backend.dev/docs/ship/releases/upgrade#doctor---fix-asks-before-it-syncs-email-and-a-deploy-runs-the-packages-migrations)
21
27
 
22
28
  | Was | Now | Change | Note |
@@ -16,15 +16,15 @@
16
16
  *
17
17
  * @internal
18
18
  */
19
- import { computed, inject, nextTick, onMounted, ref, useId, useTemplateRef, watch } from 'vue'
19
+ import { computed, inject, nextTick, ref, useId, useTemplateRef } from 'vue'
20
20
  import { ConvexAuthStateKey } from 'nuxt-convex-module/client'
21
21
  import { useAccessPhase, useInvite } from '../../composables/use-access'
22
22
  import { useBackendPagePath } from '../../composables/use-backend-page-path'
23
23
  import { useLabels } from '../../composables/use-labels'
24
24
  import { useReturnPath } from '../../composables/use-return-path'
25
- import { keepInvite, takeInviteFromAddress } from '../../utils/kept-invite'
26
25
 
27
- const invite = useInvite()
26
+ // `fromAddress` takes the link's token off the address, waits for the session, then checks or forgets it.
27
+ const invite = useInvite({ fromAddress: true })
28
28
  const { phase } = useAccessPhase()
29
29
  const { t, errorMessage } = useLabels('auth')
30
30
  const waitlistPath = useBackendPagePath('waitlist')
@@ -33,35 +33,14 @@ const auth = inject(ConvexAuthStateKey, null)
33
33
  const signedIn = computed(() => auth != null && auth.isAuthenticated.value)
34
34
  const codeId = useId()
35
35
  const code = ref('')
36
- const checked = ref(false)
36
+ const checked = invite.linkChecked
37
37
  // Whether a ticket was asked about at all: a link brought one, the tab kept one, or a code was typed.
38
- const asked = ref(false)
38
+ const asked = invite.asked
39
39
  const continueLink = useTemplateRef<HTMLAnchorElement>('continueLink')
40
40
 
41
- onMounted(() => {
42
- // The link's token leaves the address at once, kept for the tab, so a reload while the session settles still has it.
43
- const taken = takeInviteFromAddress()
44
- if (taken) keepInvite(taken)
45
- // The session settles first: a signed-in visitor's link is neither checked nor kept.
46
- let started = false
47
- watch(() => auth != null && auth.isLoading.value, async (loading) => {
48
- if (loading || started) return
49
- started = true
50
- if (signedIn.value) {
51
- invite.forget()
52
- }
53
- else {
54
- asked.value = taken !== null || invite.isKept.value
55
- if (asked.value) await invite.check()
56
- }
57
- checked.value = true
58
- }, { immediate: true })
59
- })
60
-
61
41
  async function redeem() {
62
42
  const typed = code.value.trim()
63
43
  if (invite.isPending.value || !typed) return
64
- asked.value = true
65
44
  await invite.check(typed)
66
45
  // The form goes once the code checks: focus moves on to the way in, never back to the page's start.
67
46
  if (state.value !== 'valid') return
@@ -29,11 +29,11 @@ import { useAccessPhase } from '../../composables/use-access'
29
29
  import { useBackendPagePath } from '../../composables/use-backend-page-path'
30
30
  import { useLabels } from '../../composables/use-labels'
31
31
  import { useReturnPath } from '../../composables/use-return-path'
32
- import { useWaitlist, type WaitlistPlace } from '../../composables/use-waitlist'
33
- import { takeFragment, tabKeep } from '../../utils/tab-keep'
32
+ import { keptStatusToken, useWaitlist, type WaitlistPlace } from '../../composables/use-waitlist'
34
33
 
35
34
  // The place behind a status link: the link's own, never a friend's code.
36
- const waitlist = useWaitlist({ ref: null })
35
+ // `statusLink` takes the token off the address and keeps it for the tab.
36
+ const waitlist = useWaitlist({ ref: null, statusLink: true })
37
37
  const { phase, isLoading: phaseLoading } = useAccessPhase()
38
38
  const { t } = useLabels('waitlist')
39
39
  const loginPath = useBackendPagePath('login')
@@ -42,31 +42,22 @@ const home = useReturnPath()
42
42
  const auth = inject(ConvexAuthStateKey, null)
43
43
  const signedIn = computed(() => auth != null && auth.isAuthenticated.value)
44
44
  const authLoading = computed(() => auth != null && auth.isLoading.value)
45
- const opened = ref(false)
46
45
  const hadToken = ref(false)
47
46
  // The person left the list, here or through the form: the page says so above the join.
48
47
  const left = ref(false)
49
- // The status token this tab keeps, out of the address.
50
- const kept = tabKeep('nuxt-backend:waitlist')
48
+ // The join's own instance (the form's) keeps its token under the same key.
49
+ const kept = keptStatusToken()
51
50
 
51
+ // useWaitlist read the status link (or the tab's token) as the page mounted, before this.
52
52
  onMounted(() => {
53
- // A status link's token leaves the address at once; a reload reads the one the tab keeps.
54
- const taken = takeFragment()
55
- if (taken) kept.keep(taken)
56
- const token = taken ?? kept.read()
57
- if (token) {
58
- hadToken.value = true
59
- waitlist.status(token)
60
- }
61
- opened.value = true
53
+ hadToken.value = waitlist.step.value === 'status'
62
54
  })
63
55
 
64
- // Leave took the entry behind the token: a reload must not read it as a dead link.
65
- watch(() => waitlist.step.value, (step, before) => {
66
- if (before !== 'status' || step !== 'join') return
56
+ // Leave took the entry behind the token (useWaitlist().left); it dropped what the tab kept.
57
+ watch(() => waitlist.left.value, (now) => {
58
+ if (!now) return
67
59
  left.value = true
68
60
  hadToken.value = false
69
- kept.drop()
70
61
  })
71
62
 
72
63
  /** A join made here: its status token kept for the tab, over a dead one. */
@@ -85,7 +76,7 @@ function leftForm() {
85
76
  /** The `data-state` of the page: what the person reads now. */
86
77
  const state = computed(() => {
87
78
  // The fragment is the browser's alone, so the server renders the wait.
88
- if (!opened.value || authLoading.value || (phase.value === undefined && phaseLoading.value) || (hadToken.value && waitlist.isLoading.value)) return 'checking'
79
+ if (!waitlist.linkChecked.value || authLoading.value || (phase.value === undefined && phaseLoading.value) || (hadToken.value && waitlist.isLoading.value)) return 'checking'
89
80
  if (signedIn.value) return 'member'
90
81
  // Open to all, the line is over; invite only, a place already held stands.
91
82
  if (phase.value === 'public') return 'open'
@@ -9,15 +9,16 @@ import { useCampaign } from '../../composables/use-campaign'
9
9
  import { useCredits } from '../../composables/use-credits'
10
10
  import { useExperimentDiscount } from '../../composables/use-experiment'
11
11
  import { refusalText, useLabels, type BackendLabels, type LabelKey, type LabelOverrides } from '../../composables/use-labels'
12
+ import { usePlanChange } from '../../composables/use-plan-change'
12
13
  import { usePricing, type PricedOffer, type PricedPlan, type PricingInterval, type PricingSuccessUrls, type UsePricingReturn } from '../../composables/use-pricing'
13
14
  import { busyAttributes } from '../../a11y'
14
15
  import { useAuthSession } from '../../utils/auth-session'
15
- import { getBackendError } from '../../utils/backend-error'
16
16
  import { createCancelConfirm } from '../../utils/cancel-confirm'
17
- import { CONFIRMED_PRORATION, createPlanChangeConfirm, type PlanChangeTarget } from '../../utils/plan-change-confirm'
17
+ import { createPlanChangeConfirm } from '../../utils/plan-change-confirm'
18
18
  import { returnFocus } from '../../utils/focus-return'
19
19
  import { useMeterUnit } from '../../utils/meter-unit'
20
20
  import { pricingBindings, shownInterval } from '../../utils/pricing-bindings'
21
+ import { pricingCheckout } from '../../utils/pricing-checkout'
21
22
  import type { CreditPack, PricingContact, PricingPlan } from '../../../config'
22
23
  import { providePricingView, type PlanAction, type PlanTrial, type PricingSlotContext, type PricingTableSlots, type ResolvedPack, type ResolvedPlan } from './pricing-table'
23
24
 
@@ -130,8 +131,10 @@ const credits = useCredits()
130
131
  const campaign = useCampaign()
131
132
  // A price test's promotion for the person's variant, when the address carries no campaign code.
132
133
  const experimentDiscount = useExperimentDiscount()
134
+ /** The promotion the table shows: the prop's, else the campaign link's code, else a price test's. */
135
+ const asked = () => props.discount ?? campaign.discountCode.value ?? experimentDiscount.value
133
136
  const pricing = usePricing({
134
- discount: () => props.discount ?? campaign.discountCode.value ?? experimentDiscount.value,
137
+ discount: asked,
135
138
  actions: false,
136
139
  // Read when a checkout starts, so a changed prop counts.
137
140
  successUrl: {
@@ -140,19 +143,9 @@ const pricing = usePricing({
140
143
  },
141
144
  })
142
145
  // A subscriber's switch keeps the subscription's currency (the provider's
143
- // rule), so its confirmation states the price in it: read apart, in the
144
- // browser, only while the page shows another one.
145
- const subscriptionCurrency = computed(() => {
146
- const currency = billing.subscription.value?.currency
147
- return typeof currency === 'string' && currency !== '' ? currency.toLowerCase() : undefined
148
- })
149
- const switchPricing = usePricing({
150
- server: false,
151
- actions: false,
152
- currency: () => subscriptionCurrency.value,
153
- enabled: () => billing.isSubscribed.value && billing.pass.value === null && subscriptionCurrency.value !== undefined
154
- && pricing.currency.value !== undefined && subscriptionCurrency.value !== pricing.currency.value,
155
- })
146
+ // rule), so its confirmation states the price in it: the page's where it is
147
+ // in it, else read apart, in the browser, only while the page shows another.
148
+ const planChange = usePlanChange({ labels: () => props.labels, pricing })
156
149
  const route = useRoute()
157
150
  const { isAuthenticated } = useAuthSession()
158
151
  const config = useBackendConfig()
@@ -209,8 +202,7 @@ function resolvePlan(card: PricingPlan, offer: PricedPlan): ResolvedPlan | null
209
202
  const priceAt = offer.prices[at]!
210
203
  const isCurrent = Object.values(offer.prices).some(price => price?.productId === subscribedId.value)
211
204
  const comparable = !isCurrent && currentMonthly.value !== undefined
212
- const scheduled = billing.pendingChange.value
213
- const scheduledFor = scheduled?.productId === priceAt.productId ? scheduled.appliesAt : undefined
205
+ const scheduledFor = planChange.scheduledFor(priceAt.productId) ?? undefined
214
206
  // The free plan is free in every currency: in the page's, whatever its product's.
215
207
  const priceCurrency = offer.free ? pricing.currency.value ?? priceAt.currency : priceAt.currency
216
208
  return {
@@ -309,42 +301,18 @@ async function run(key: string, busy: () => string, action: () => Promise<unknow
309
301
  const planByKey = (key: string) => resolvedPlans.value.find(plan => plan.key === key)
310
302
 
311
303
  /**
312
- * The currency a card's price shows in, for its checkout to pay in it: a
313
- * product the catalog prices in one currency only shows, and is paid, in
314
- * that one whatever the page's. Named only where the catalog prices more
315
- * than one; a single-currency checkout keeps the provider's own.
304
+ * A checkout with the address's campaign, its discount code and UTM, in the
305
+ * currency the card's price shows in (`usePricing().checkout`'s rules): the
306
+ * table's own promotion (`discount`, else a price test's for a link with no
307
+ * code) goes in the code's place on a product it is offered on, one discount
308
+ * per checkout, and a discount the server refuses never blocks the purchase.
316
309
  */
317
- const payIn = (currency: string | undefined): { currency?: string } =>
318
- currency && pricing.currencies.value.length > 1 ? { currency } : {}
319
-
320
- /** A refusal of a checkout's discount: an expired, used-up or unknown campaign code, or a promotion no longer redeemed. */
321
- function refusedCode(failure: unknown): boolean {
322
- const refusal = getBackendError(failure)
323
- const field = (refusal?.data as { field?: unknown } | undefined)?.field
324
- return refusal?.code === 'invalid_input' && (field === 'discountCode' || field === 'discount')
325
- }
326
-
327
- /**
328
- * A checkout with the address's campaign: its discount code and UTM. The
329
- * table's own promotion (`discount`, else a price test's for a link with
330
- * no code) goes in the code's place on a product it is offered on (one
331
- * discount per checkout); elsewhere the campaign's code still goes. A discount the server refuses never blocks the purchase:
332
- * the checkout opens again without it, the attribution kept.
333
- */
334
- async function withCampaign<T>(offered: boolean, start: (campaignOptions: { discountCode?: string, discount?: string, utm?: typeof campaign.checkoutOptions.value.utm }) => Promise<T>): Promise<T> {
335
- const { discountCode, ...attribution } = campaign.checkoutOptions.value
336
- const promotion = props.discount ?? (discountCode ? undefined : experimentDiscount.value)
337
- const options = promotion && offered
338
- ? { ...attribution, discount: promotion }
339
- : { ...attribution, ...(discountCode ? { discountCode } : {}) }
340
- try {
341
- return await start(options)
342
- }
343
- catch (failure) {
344
- if (!('discountCode' in options || 'discount' in options) || !refusedCode(failure)) throw failure
345
- return start(attribution)
346
- }
347
- }
310
+ const { payIn, withCampaign } = pricingCheckout({
311
+ campaign,
312
+ asked,
313
+ active: () => pricing.activePromotion.value,
314
+ currencies: () => pricing.currencies.value,
315
+ })
348
316
 
349
317
  // The EU soft opt-in's box, under the checkout buttons while a topic takes it: ticked, the paid order joins no topic.
350
318
  const emailOptOut = ref(false)
@@ -366,7 +334,7 @@ async function checkOutFromPass(key: string): Promise<void> {
366
334
  const switchTo = (key: string) => run(key, () => t('changing'), async () => {
367
335
  const plan = planByKey(key)
368
336
  if (!plan) return
369
- await billing.changePlan(plan.priceAt.productId, { proration: CONFIRMED_PRORATION })
337
+ await planChange.switchTo(plan.priceAt.productId)
370
338
  change.settle()
371
339
  emit('plan-changed', key)
372
340
  // The step went with the switch: focus moves to the card's action, else the current plan's.
@@ -380,31 +348,6 @@ function returnTo(kind: 'plan' | 'pack', key: string): { successUrl?: string } {
380
348
  return url ? { successUrl: url } : {}
381
349
  }
382
350
 
383
- /**
384
- * The price a switch to a card's plan is about. A subscriber's is in the
385
- * subscription's currency: `null` while that price is read, `undefined`
386
- * when the plan has none in it, which no switch can move to. A gifted
387
- * plan's holder checks out, in the card's own.
388
- */
389
- function changeTarget(plan: ResolvedPlan): PlanChangeTarget | null | undefined {
390
- const price = billing.pass.value === null ? priceInSubscriptionCurrency(plan) : plan.price
391
- if (price === null) return null
392
- if (price === '') return undefined
393
- // Their own plan at the other period is named with it: "Pro, billed yearly".
394
- const name = plan.isCurrent ? t(`billedAt.${plan.interval}` as LabelKey<BackendLabels['pricing']>, { plan: plan.name }) : plan.name
395
- return { key: plan.key, productId: plan.priceAt.productId, plan: name, price: `${price}${t(`period.${plan.interval}` as LabelKey<BackendLabels['pricing']>)}` }
396
- }
397
-
398
- /** A card's price in the subscription's currency, formatted: `null` while it is read, `''` when the product has no price in it. */
399
- function priceInSubscriptionCurrency(plan: ResolvedPlan): string | null {
400
- const currency = subscriptionCurrency.value
401
- if (!currency || plan.priceAt.currency === currency) return plan.price
402
- const offers = switchPricing.plans.value
403
- if (offers === undefined) return null
404
- const at = offers.find(entry => entry.key === plan.key)?.prices[plan.interval]
405
- // A product with no price in it comes back in the catalog's currency.
406
- return at?.productId === plan.priceAt.productId && at.currency === currency ? formatBillingAmount(at.amount, at.currency, locale.value) : ''
407
- }
408
351
  const root = ref<HTMLElement | null>(null)
409
352
  // Cancelling the current plan takes one step: its button opens what ends
410
353
  // when and the one button that cancels, nothing else.
@@ -425,11 +368,11 @@ const change = createPlanChangeConfirm({
425
368
  titleTag: 'p',
426
369
  partId: part => `${uid}-change-${part}`,
427
370
  isBusy: () => pending.value !== null && pending.value === change.target.value?.key,
428
- preview: productId => billing.changeOf(productId),
371
+ change: planChange,
429
372
  confirm: target => (billing.pass.value === null ? switchTo(target.key) : checkOutFromPass(target.key)),
430
373
  t,
431
374
  date: value => formatBillingDate(value, { dateStyle: 'medium' }, locale.value) || null,
432
- gifted: target => (billing.pass.value === null ? null : t('changeGifted', { price: target.price })),
375
+ gifted: target => t('changeGifted', { price: target.price }),
433
376
  })
434
377
  function cancelPlan(key: string): Promise<void> {
435
378
  return run(key, () => t('canceling'), async () => {
@@ -539,7 +482,7 @@ function planAction(plan: ResolvedPlan): PlanAction {
539
482
  // checkout; one the preview cannot describe goes at once. One to a plan
540
483
  // with no price in the subscription's currency is none the provider
541
484
  // makes; one whose price in it is still being read waits.
542
- const target = changeTarget(plan)
485
+ const target = planChange.targetFor(plan.key, plan.interval)
543
486
  if (target === undefined) return { kind: 'none' }
544
487
  const asks = billing.pass.value !== null || billing.changeOf(plan.priceAt.productId) !== null
545
488
  const switching = (intent: string, idle: string): PlanAction => target === null
@@ -23,13 +23,12 @@ import { useApiNamespace } from '../../utils/namespace'
23
23
  const invite = useReferralInvite()
24
24
  const { t, errorMessage } = useLabels('referral')
25
25
  const home = useBackendPagePath('settings')
26
- const invitePath = useBackendPagePath('invite')
27
26
  const waitlistPath = useBackendPagePath('waitlist')
28
27
  // An app without backend/access.ts is open, and lacks no file: no warning for it.
29
28
  const { phase } = useAccessPhase({ api: useApiNamespace<AccessApiRefs>('access') ?? {} })
30
29
 
31
30
  /** The invite page, carrying this link's code: the sign-in it leads to comes back here to claim. */
32
- const inviteTo = computed(() => (invitePath.value ? `${invitePath.value}?ref=${encodeURIComponent(invite.code.value)}` : null))
31
+ const inviteTo = invite.inviteTo
33
32
  /** The visitor needs a ticket first: the app is not public, and nobody is signed in. */
34
33
  const needsTicket = computed(() => invite.state.value === 'ready' && invite.closed.value === true)
35
34
  /** A visitor's way in waits for the phase: neither the sign-up nor the ways to a ticket until it is read, or a few seconds pass. */