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
package/README.md CHANGED
@@ -131,6 +131,7 @@ Listing `nuxt-backend` in `modules` registers everything below — nothing needs
131
131
  - `useBackendConfig` — `appConfig.backend` with the package defaults merged in — the shipped components read content (plan catalog, labels, brand) through this, so a partial user config is always safe to destructure
132
132
  - `useBackendPagePath` — where a ready-made page lives, for a link to it: the path the module mounted it at (the `pages` module option, else its default), in the active locale when the app uses `@nuxtjs/i18n` (through its `localePath`, so `/pricing` reads `/fr/pricing` under a prefix strategy)
133
133
  - `useBilling` — reactive billing state plus the full subscription lifecycle — checkout, portal, plan change and undoing a scheduled one, cancel (with its save offer) and uncancel, pause/resume — linked to your auth user
134
+ - `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
134
135
  - `useCampaign` — the campaign a visitor arrived with, read from the address: a campaign link's discount code and its UTM attribution, ready for checkout
135
136
  - `useChat` — a chat with a model, live: the person's threads, the open thread's messages with the reply streaming into them, and sending (experimental)
136
137
  - `useConsents` — what a signed-in person agreed to, and the consent manager for optional storage
@@ -160,6 +161,7 @@ Listing `nuxt-backend` in `modules` registers everything below — nothing needs
160
161
  - `useOnboarding` — the first run at `/welcome` without its markup: the steps in order, where the person is, moving between them, and the stamp that ends it
161
162
  - `useOrders` — the signed-in customer's billing history — past charges straight from the provider's orders API, plus the per-order invoice link
162
163
  - `usePasskeys` — passkey management over the auth client — list, register, rename, remove
164
+ - `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
163
165
  - `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
164
166
  - `usePushSubscription` — web push on this device, for the signed-in person: whether the browser can take it, whether this device is subscribed, the permission, and the actions that subscribe and unsubscribe it
165
167
  - `useReauthentication` — asking the person to confirm it is them before a sensitive action: the client half of `requireRecentSignIn` and of the routes that take a recent sign-in
@@ -2,7 +2,7 @@ import { existsSync } from 'node:fs';
2
2
  import { stat } from 'node:fs/promises';
3
3
  import { join } from 'node:path';
4
4
  import { pathToFileURL } from 'node:url';
5
- import { j as resolveFunctionsDir } from '../shared/nuxt-backend.9IVxzzft.mjs';
5
+ import { j as resolveFunctionsDir } from '../shared/nuxt-backend.DbaXvH__.mjs';
6
6
  import 'node:crypto';
7
7
  import 'node:module';
8
8
  import 'node:child_process';
@@ -1,9 +1,9 @@
1
1
  import { readFileSync, readdirSync, existsSync, statSync } from 'node:fs';
2
2
  import { createRequire } from 'node:module';
3
3
  import { resolve, join, dirname, relative, sep } from 'node:path';
4
- import { l as executeEnvPush, f as runConvex, aY as envNames, a4 as REQUIRED_DEPLOYMENT_ENV, aZ as DEV_ONLY_DEPLOYMENT_ENV, m as generateAuthSecret, a_ as DEV_SITE_URL, g as deploymentFlags, a$ as finding, e as deployKeyType, r as readEnvFiles, aP as capabilityOfEnv, k as readTextIfPresent, aO as BACKEND_ENV, j as resolveFunctionsDir, b0 as parseBackendEnvironment, c as billingEnvironment, V as packageDir, b1 as proofKeys, b2 as TEST_CHALLENGE_SITE_KEYS, b3 as deploymentEnvId, b4 as protectionTakes, al as DEFAULT_AUTH_ROUTE, b5 as TEST_CHALLENGE_SECRET_KEYS, b6 as PROTECTED_AUTH_ROUTES, b7 as PROOF_HEADER, b8 as signProof, b9 as proofAudience, b as deploymentBackendEnvironment, ba as deploymentSiteOrigin, p as isLoopbackUrl, ab as HEALTH_ROUTE, a8 as resolveSiteUrl, a5 as deriveDeploymentUrls, a as deploymentEnvNames, bb as isLocalDeploymentId, q as configuredDeployment, J as computeDeployment, a2 as collectPreflightFindings, bc as capabilityOfGroup, bd as agentFilesFinding, U as installedVersion, a3 as OPTIONAL_DEPLOYMENT_ENV, be as chosenRoutes, bf as chosenGateways, bg as pinnedRegion, bh as namedModels, bi as usesProvenance, bj as moderationProviders, bk as monitoringDsnFinding, bl as monitoringFindings, bm as usageAlertsFinding, bn as readUsageLimits, bo as applyProductionPosture, bp as billingWebhookSecretHint, x as backendPathsOf, bq as BACKEND_PATH_KEYS, br as pathOption, v as pathsSourceOf, bs as aiFeatures, bt as pathsFileFinding, bu as brandFileFinding, z as appBrandOf, bv as labelsFileFinding, F as appLabelsOf, aQ as REMOVED_DEPLOYMENT_ENV, bw as checksImages, bx as namesModerationModel, by as GATEWAY_ORDER_UNREAD, bz as routeKeyFor, bA as installableFinding, d as deploymentFunctionSpec, bB as gatewayKeyIsTheFix, bC as DEFAULT_MODERATION_MODEL, bD as mountsComponent, bE as GATEWAY_KEY_FIX } from '../shared/nuxt-backend.9IVxzzft.mjs';
4
+ import { l as executeEnvPush, f as runConvex, aY as envNames, a4 as REQUIRED_DEPLOYMENT_ENV, aZ as DEV_ONLY_DEPLOYMENT_ENV, m as generateAuthSecret, a_ as DEV_SITE_URL, g as deploymentFlags, a$ as finding, e as deployKeyType, r as readEnvFiles, aP as capabilityOfEnv, k as readTextIfPresent, aO as BACKEND_ENV, j as resolveFunctionsDir, b0 as parseBackendEnvironment, c as billingEnvironment, V as packageDir, b1 as proofKeys, b2 as TEST_CHALLENGE_SITE_KEYS, b3 as deploymentEnvId, b4 as protectionTakes, al as DEFAULT_AUTH_ROUTE, b5 as TEST_CHALLENGE_SECRET_KEYS, b6 as PROTECTED_AUTH_ROUTES, b7 as PROOF_HEADER, b8 as signProof, b9 as proofAudience, b as deploymentBackendEnvironment, ba as deploymentSiteOrigin, p as isLoopbackUrl, ab as HEALTH_ROUTE, a8 as resolveSiteUrl, a5 as deriveDeploymentUrls, a as deploymentEnvNames, bb as isLocalDeploymentId, q as configuredDeployment, J as computeDeployment, a2 as collectPreflightFindings, bc as capabilityOfGroup, bd as agentFilesFinding, U as installedVersion, a3 as OPTIONAL_DEPLOYMENT_ENV, be as chosenRoutes, bf as chosenGateways, bg as pinnedRegion, bh as namedModels, bi as usesProvenance, bj as moderationProviders, bk as monitoringDsnFinding, bl as monitoringFindings, bm as usageAlertsFinding, bn as readUsageLimits, bo as applyProductionPosture, bp as billingWebhookSecretHint, x as backendPathsOf, bq as BACKEND_PATH_KEYS, br as pathOption, v as pathsSourceOf, bs as aiFeatures, bt as pathsFileFinding, bu as brandFileFinding, z as appBrandOf, bv as labelsFileFinding, F as appLabelsOf, aQ as REMOVED_DEPLOYMENT_ENV, bw as checksImages, bx as namesModerationModel, by as GATEWAY_ORDER_UNREAD, bz as routeKeyFor, bA as installableFinding, d as deploymentFunctionSpec, bB as gatewayKeyIsTheFix, bC as DEFAULT_MODERATION_MODEL, bD as mountsComponent, bE as GATEWAY_KEY_FIX } from '../shared/nuxt-backend.DbaXvH__.mjs';
5
5
  import { defineCommand } from 'citty';
6
- import { w as withContract, f as finish, p as progress, r as renderEnvExample, b as devScriptFinding } from '../shared/nuxt-backend.BjQoqNIu.mjs';
6
+ import { w as withContract, f as finish, p as progress, r as renderEnvExample, b as devScriptFinding } from '../shared/nuxt-backend.CBvrM7pG.mjs';
7
7
  import { pathToFileURL } from 'node:url';
8
8
  import { Polar } from '@polar-sh/sdk';
9
9
  import { benefitsList } from '@polar-sh/sdk/funcs/benefitsList.js';
@@ -26,7 +26,7 @@ import { customersGet } from '@polar-sh/sdk/funcs/customersGet.js';
26
26
  import '@convex-dev/polar';
27
27
  import { metricsLimits } from '@polar-sh/sdk/funcs/metricsLimits.js';
28
28
  import { r as readLastRun, i as installChangedSince, a as formatSize } from './report.mjs';
29
- import { c as convexConfigFinding } from '../shared/nuxt-backend.Baxb382E.mjs';
29
+ import { c as convexConfigFinding } from '../shared/nuxt-backend.DH1Ya3uB.mjs';
30
30
 
31
31
  const ENV_DEFAULT_TYPES = ["preview", "dev"];
32
32
  const ENV_DEFAULT_NAMES = [...REQUIRED_DEPLOYMENT_ENV, "BACKEND_ENVIRONMENT"];
@@ -3038,7 +3038,7 @@ function optionalDeploymentEnvFinding(name, degradation, isSet, { prod }) {
3038
3038
  }
3039
3039
  function removedEnvFinding(deployed, { prod }) {
3040
3040
  const left = REMOVED_DEPLOYMENT_ENV.filter((name) => deployed.includes(name));
3041
- if (left.length === 0) return finding("deployment-removed-env", "pass", "No variable `0.2.0` removed is still set on the deployment.");
3041
+ if (left.length === 0) return finding("deployment-removed-env", "pass", "No variable that 0.2.0 removed is still set on the deployment.");
3042
3042
  return finding(
3043
3043
  "deployment-removed-env",
3044
3044
  "warn",
@@ -1,4 +1,4 @@
1
- import { f as runConvex, q as configuredDeployment, aU as isDevDeployment } from '../shared/nuxt-backend.9IVxzzft.mjs';
1
+ import { f as runConvex, q as configuredDeployment, aU as isDevDeployment } from '../shared/nuxt-backend.DbaXvH__.mjs';
2
2
  import { n as normalizeLocale, f as forceColorScheme } from '../shared/nuxt-backend.C62dpRH3.mjs';
3
3
  import 'node:fs';
4
4
  import 'node:path';
@@ -1,5 +1,5 @@
1
- import { r as readConvexConfigDrift } from '../shared/nuxt-backend.Baxb382E.mjs';
2
- import { q as configuredDeployment, aU as isDevDeployment, f as runConvex } from '../shared/nuxt-backend.9IVxzzft.mjs';
1
+ import { r as readConvexConfigDrift } from '../shared/nuxt-backend.DH1Ya3uB.mjs';
2
+ import { q as configuredDeployment, aU as isDevDeployment, f as runConvex } from '../shared/nuxt-backend.DbaXvH__.mjs';
3
3
  import 'node:fs';
4
4
  import 'node:module';
5
5
  import 'node:path';
@@ -2,8 +2,8 @@ import { existsSync } from 'node:fs';
2
2
  import { stat, readFile } from 'node:fs/promises';
3
3
  import { resolve, sep, extname } from 'node:path';
4
4
  import { runWithNuxtContext, addDevServerHandler } from '@nuxt/kit';
5
- import { q as configuredDeployment, aU as isDevDeployment, P as CAPABILITY_NAMES, Z as doctorReport, a as deploymentEnvNames, aV as RPC_NAMESPACE, aW as DEVTOOLS_UI_ROUTE, aX as DEVTOOLS_UI_LOCAL_PORT } from '../shared/nuxt-backend.9IVxzzft.mjs';
6
- import { r as resolveBackendSource, e as envTier } from '../shared/nuxt-backend.CbR37s_c.mjs';
5
+ import { q as configuredDeployment, aU as isDevDeployment, P as CAPABILITY_NAMES, Z as doctorReport, a as deploymentEnvNames, aV as RPC_NAMESPACE, aW as DEVTOOLS_UI_ROUTE, aX as DEVTOOLS_UI_LOCAL_PORT } from '../shared/nuxt-backend.DbaXvH__.mjs';
6
+ import { r as resolveBackendSource, e as envTier } from '../shared/nuxt-backend.BqXAZChe.mjs';
7
7
  import 'node:url';
8
8
  import 'node:crypto';
9
9
  import 'node:module';
@@ -1,19 +1,19 @@
1
1
  import { useTerminal, getAddDependencyCommand } from '@nuxt/kit';
2
2
  import { relative, isAbsolute } from 'node:path';
3
3
  import { isCI } from 'std-env';
4
- import { V as packageDir } from '../shared/nuxt-backend.9IVxzzft.mjs';
5
- import { s as setUpProject, b as addedDependencies, f as formatNextSteps, i as installDeclaredDependencies } from '../shared/nuxt-backend.BCjeoX0x.mjs';
6
- import { l as logger } from '../shared/nuxt-backend.CbR37s_c.mjs';
4
+ import { e as execBinary, p as packageManagerOf, s as setUpProject, b as addedDependencies, f as formatNextSteps, c as installDeclaredDependencies } from '../shared/nuxt-backend.Dikfaocl.mjs';
5
+ import { V as packageDir } from '../shared/nuxt-backend.DbaXvH__.mjs';
6
+ import { l as logger } from '../shared/nuxt-backend.BqXAZChe.mjs';
7
+ import 'node:child_process';
7
8
  import 'node:fs';
9
+ import 'node:module';
10
+ import '../shared/nuxt-backend.CBvrM7pG.mjs';
11
+ import 'citty';
8
12
  import 'node:url';
9
13
  import 'node:crypto';
10
- import 'node:module';
11
- import 'node:child_process';
12
14
  import 'node:util';
13
15
  import 'dedent';
14
16
  import 'defu';
15
- import '../shared/nuxt-backend.BjQoqNIu.mjs';
16
- import 'citty';
17
17
  import '../../dist/runtime/config.js';
18
18
  import '../../dist/runtime/vue/trusted-types.js';
19
19
 
@@ -37,7 +37,7 @@ async function installProject(nuxt, given = {}) {
37
37
  const { terminal, log } = surroundings;
38
38
  const prepareOrDev = nuxt.options.dev || nuxt.options._prepare;
39
39
  if (nuxt.options.test || !prepareOrDev || !surroundings.interactive) {
40
- log("nuxt-backend is installed. Its setup runs at an interactive terminal: run `npx nuxt-backend init` to write the backend files, .env.example and the agent files.");
40
+ log(`nuxt-backend is installed. Its setup runs at an interactive terminal: run \`${execBinary(packageManagerOf(nuxt.options.rootDir), "nuxt-backend init")}\` to write the backend files, .env.example and the agent files.`);
41
41
  return;
42
42
  }
43
43
  const rootDir = nuxt.options.rootDir;
@@ -3,7 +3,7 @@ import { existsSync, readFileSync, mkdtempSync, rmSync, mkdirSync, writeFileSync
3
3
  import { createRequire } from 'node:module';
4
4
  import { join, dirname } from 'node:path';
5
5
  import { stripVTControlCharacters } from 'node:util';
6
- import { j as resolveFunctionsDir, V as packageDir } from '../shared/nuxt-backend.9IVxzzft.mjs';
6
+ import { j as resolveFunctionsDir, V as packageDir } from '../shared/nuxt-backend.DbaXvH__.mjs';
7
7
  import { tmpdir } from 'node:os';
8
8
  import { a as formatSize, r as readLastRun, c as checkBudgets, s as saveLastRun, B as BUDGET_FLAGS } from './report.mjs';
9
9
  import 'node:url';
@@ -1,7 +1,7 @@
1
1
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
2
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
3
3
  import { ListToolsRequestSchema, CallToolRequestSchema } from '@modelcontextprotocol/sdk/types.js';
4
- import { r as readEnvFiles, aM as resolveConvexCli, U as installedVersion, b as deploymentBackendEnvironment, aN as RECENT_SIGN_IN_SECONDS, P as CAPABILITY_NAMES, Z as doctorReport, a as deploymentEnvNames, aO as BACKEND_ENV, aP as capabilityOfEnv, aQ as REMOVED_DEPLOYMENT_ENV, d as deploymentFunctionSpec, Y as packageVersion } from '../shared/nuxt-backend.9IVxzzft.mjs';
4
+ import { r as readEnvFiles, aM as resolveConvexCli, U as installedVersion, b as deploymentBackendEnvironment, aN as RECENT_SIGN_IN_SECONDS, P as CAPABILITY_NAMES, Z as doctorReport, a as deploymentEnvNames, aO as BACKEND_ENV, aP as capabilityOfEnv, aQ as REMOVED_DEPLOYMENT_ENV, d as deploymentFunctionSpec, Y as packageVersion } from '../shared/nuxt-backend.DbaXvH__.mjs';
5
5
  import { Polar } from '@polar-sh/sdk';
6
6
  import { z } from 'zod';
7
7
  import { z as providerClientOptions, a9 as runDoctorChecks, af as REQUIRED_FUNCTION_EXPORTS } from './doctor.mjs';
@@ -20,7 +20,7 @@ import 'node:util';
20
20
  import 'dedent';
21
21
  import 'defu';
22
22
  import 'citty';
23
- import '../shared/nuxt-backend.BjQoqNIu.mjs';
23
+ import '../shared/nuxt-backend.CBvrM7pG.mjs';
24
24
  import '@polar-sh/sdk/funcs/benefitsList.js';
25
25
  import '@polar-sh/sdk/funcs/checkoutLinksList.js';
26
26
  import '@polar-sh/sdk/funcs/membersListMembers.js';
@@ -41,8 +41,8 @@ import '@polar-sh/sdk/funcs/customersGet.js';
41
41
  import '@convex-dev/polar';
42
42
  import '@polar-sh/sdk/funcs/metricsLimits.js';
43
43
  import './report.mjs';
44
- import '../shared/nuxt-backend.Baxb382E.mjs';
45
- import '../shared/nuxt-backend.BCjeoX0x.mjs';
44
+ import '../shared/nuxt-backend.DH1Ya3uB.mjs';
45
+ import '../shared/nuxt-backend.Dikfaocl.mjs';
46
46
  import 'node:readline';
47
47
  import '@polar-sh/sdk/funcs/webhooksResetWebhookEndpointSecret.js';
48
48
  import './run.mjs';
package/dist/cli.mjs CHANGED
@@ -1,13 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
  import { defineCommand, parseArgs, runMain } from 'citty';
3
3
  import { mkdtempSync, writeFileSync, rmSync, existsSync, readFileSync, readdirSync, mkdirSync, cpSync, symlinkSync } from 'node:fs';
4
- import { join, resolve, dirname, posix, relative, isAbsolute, sep } from 'node:path';
5
- import { C as CAPABILITY_STATES, d as deploymentFunctionSpec, a as deploymentEnvNames, i as isHttpUrl, b as deploymentBackendEnvironment, c as billingEnvironment, s as siteFromCloudUrl, e as deployKeyType, r as readEnvFiles, f as runConvex, R as RESYNC_ENTITLEMENTS_FUNCTION, g as deploymentFlags, h as ConvexCliError, n as nonProductionDeployKey, j as resolveFunctionsDir, k as readTextIfPresent, l as executeEnvPush, m as generateAuthSecret, o as setDeploymentEnv, p as isLoopbackUrl, q as configuredDeployment, t as spawnConvex, B as BACKEND_ENV_NAMES, D as DERIVED_DEPLOYMENT_ENV, u as scaffoldBackendFiles, v as pathsSourceOf, w as syncPathsFile, x as backendPathsOf, y as pathsFileLocation, z as appBrandOf, A as syncBrandFile, E as brandFileLocation, F as appLabelsOf, G as syncLabelsFile, H as labelsFileLocation, I as isDevDeploymentId, M as MCP_SDK, J as computeDeployment, K as appMonitoringDsn, L as monitoringSdkInstalled, N as detectCapabilities, O as DEPLOYMENT_KIND_LABEL, P as CAPABILITY_NAMES, Q as REGISTERED_UI, S as uiPath, T as BACKEND_PAGE_DEFS, U as installedVersion, V as packageDir, W as uiEntry, X as agentsMdVersion, Y as packageVersion, Z as doctorReport, _ as formatPreflightSummary, $ as runEnvPush, a0 as devPushRefusal } from './shared/nuxt-backend.9IVxzzft.mjs';
6
- import { s as setUpProject, n as nextCommands$1, f as formatNextSteps, a as setUpAgentFiles } from './shared/nuxt-backend.BCjeoX0x.mjs';
4
+ import { join, resolve, posix, relative, dirname, isAbsolute, sep } from 'node:path';
5
+ import { C as CAPABILITY_STATES, d as deploymentFunctionSpec, a as deploymentEnvNames, i as isHttpUrl, b as deploymentBackendEnvironment, c as billingEnvironment, s as siteFromCloudUrl, e as deployKeyType, r as readEnvFiles, f as runConvex, R as RESYNC_ENTITLEMENTS_FUNCTION, g as deploymentFlags, h as ConvexCliError, n as nonProductionDeployKey, j as resolveFunctionsDir, k as readTextIfPresent, l as executeEnvPush, m as generateAuthSecret, o as setDeploymentEnv, p as isLoopbackUrl, q as configuredDeployment, t as spawnConvex, B as BACKEND_ENV_NAMES, D as DERIVED_DEPLOYMENT_ENV, u as scaffoldBackendFiles, v as pathsSourceOf, w as syncPathsFile, x as backendPathsOf, y as pathsFileLocation, z as appBrandOf, A as syncBrandFile, E as brandFileLocation, F as appLabelsOf, G as syncLabelsFile, H as labelsFileLocation, I as isDevDeploymentId, M as MCP_SDK, J as computeDeployment, K as appMonitoringDsn, L as monitoringSdkInstalled, N as detectCapabilities, O as DEPLOYMENT_KIND_LABEL, P as CAPABILITY_NAMES, Q as REGISTERED_UI, S as uiPath, T as BACKEND_PAGE_DEFS, U as installedVersion, V as packageDir, W as uiEntry, X as agentsMdVersion, Y as packageVersion, Z as doctorReport, _ as formatPreflightSummary, $ as runEnvPush, a0 as devPushRefusal } from './shared/nuxt-backend.DbaXvH__.mjs';
6
+ import { e as execBinary, r as runScript, p as packageManagerOf, s as setUpProject, n as nextCommands$1, f as formatNextSteps, a as setUpAgentFiles, i as installCommand } from './shared/nuxt-backend.Dikfaocl.mjs';
7
7
  import { P as PROVIDER_COMPONENT, l as loadCatalog, f as freePlanOf, M as MANAGED_BY, i as isManaged, r as refuseUnpricedPlans, a as refuseInvalidPrices, b as refuseOnceCredits, c as refuseInvalidGifts, d as refuseInvalidQuotas, e as refuseInvalidDiscounts, g as listAllPages, h as refuseMissingDefaultCurrency, j as refuseMissingOrganizationCurrency, k as refuseUnpricedDiscounts, m as ensurePlanQuotas, n as retirePlan, p as pricedIntervals, o as attachRetiredPlanQuotas, q as recordQuotaKeys, s as packPricesByCurrency, t as syncPassProducts, u as syncDiscounts, v as planQuotasKeys, w as derivedPassKeys, x as droppedQuotasKeys, y as unpricedPlanProducts, z as providerClientOptions, A as planQuotasKey, B as planPricesByCurrency, C as findPlanProduct, D as isUntaggedPlanProduct, E as planCreditUnits, F as planQuotasBenefits, G as isFreePlan, H as zeroPrices, I as providerTrialOf, J as pushPlanTrial, K as attachPlanQuotas, L as BILLING_WEBHOOK_PROVISION_EVENTS, N as planProductKey, O as recordPlanProduct, Q as loadGenerated, R as renderGenerated, S as runEmailSync, T as runInboundSync, U as emailSyncLines, V as runEmailSyncCommand, W as probeWebhookRoute, X as emailSyncRefusal, Y as inboundSyncLines, Z as planSettingChanges, _ as planEndpointChanges, $ as applyProviderChanges, a0 as billingProviderTarget, a1 as providerClient, a2 as readProviderOrganization, a3 as readProviderEndpoint, a4 as ADMISSION_DAYS, a5 as CLI_ADMISSION_LABEL, a6 as admitInputRefusal, a7 as admitRefused, a8 as admitCleaned, a9 as runDoctorChecks, aa as readProductionPosture, ab as email, ac as runEnvDefaults, ad as firstAdministratorOnFix, ae as ENV_DEFAULT_TYPES } from './chunks/doctor.mjs';
8
8
  import { createInterface } from 'node:readline';
9
9
  import { webhooksResetWebhookEndpointSecret } from '@polar-sh/sdk/funcs/webhooksResetWebhookEndpointSecret.js';
10
- import { w as withContract, p as progress, f as finish, a as adoptBackendDevScript, d as dev } from './shared/nuxt-backend.BjQoqNIu.mjs';
10
+ import { w as withContract, p as progress, f as finish, a as adoptBackendDevScript, d as dev } from './shared/nuxt-backend.CBvrM7pG.mjs';
11
11
  import { runAnalyze, halvesOf } from './chunks/run.mjs';
12
12
  import { f as formatReport, b as budgetFailures, a as formatSize, p as parseSize, B as BUDGET_FLAGS } from './chunks/report.mjs';
13
13
  import { tmpdir } from 'node:os';
@@ -29,7 +29,7 @@ import { randomBytes } from 'node:crypto';
29
29
  import { spawn } from 'node:child_process';
30
30
  import { Resend } from 'resend';
31
31
  import { setTimeout } from 'node:timers/promises';
32
- import { f as fixConvexConfig } from './shared/nuxt-backend.Baxb382E.mjs';
32
+ import { f as fixConvexConfig } from './shared/nuxt-backend.DH1Ya3uB.mjs';
33
33
  import { isSandboxAddress, findCode } from '../dist/runtime/vue/utils/sandbox-code.js';
34
34
  import { styleText } from 'node:util';
35
35
  import { v } from 'convex/values';
@@ -1734,49 +1734,6 @@ const analyze = withContract("analyze", {
1734
1734
  }
1735
1735
  }));
1736
1736
 
1737
- const LOCKFILES = [
1738
- ["pnpm-lock.yaml", "pnpm"],
1739
- ["yarn.lock", "yarn"],
1740
- ["bun.lock", "bun"],
1741
- ["bun.lockb", "bun"],
1742
- ["package-lock.json", "npm"],
1743
- ["npm-shrinkwrap.json", "npm"]
1744
- ];
1745
- function pinned(dir) {
1746
- try {
1747
- const field = JSON.parse(readFileSync(join(dir, "package.json"), "utf8")).packageManager;
1748
- const name = typeof field === "string" ? field.split("@")[0] : void 0;
1749
- return LOCKFILES.find(([, manager]) => manager === name)?.[1] ?? null;
1750
- } catch {
1751
- return null;
1752
- }
1753
- }
1754
- function packageManagerOf(rootDir) {
1755
- let dir = rootDir;
1756
- for (; ; ) {
1757
- const manager = pinned(dir) ?? LOCKFILES.find(([file]) => existsSync(join(dir, file)))?.[1];
1758
- if (manager) return manager;
1759
- if (dir === dirname(dir) || existsSync(join(dir, ".git"))) return "npm";
1760
- dir = dirname(dir);
1761
- }
1762
- }
1763
- function runScript(manager, script) {
1764
- return `${manager} run ${script}`;
1765
- }
1766
- function execBinary(manager, binary) {
1767
- switch (manager) {
1768
- case "pnpm":
1769
- return `pnpm exec ${binary}`;
1770
- // Yarn 1 and Yarn Berry both run an installed binary by its name, Plug'n'Play too.
1771
- case "yarn":
1772
- return `yarn ${binary}`;
1773
- case "bun":
1774
- return `bunx ${binary}`;
1775
- default:
1776
- return `npx ${binary}`;
1777
- }
1778
- }
1779
-
1780
1737
  const BUILD_COMMAND = "npx convex deploy --cmd 'npm run build' --cmd-url-env-var-name NUXT_PUBLIC_BACKEND_URL";
1781
1738
  function isVercelLinked(rootDir) {
1782
1739
  return existsSync(join(rootDir, ".vercel", "project.json"));
@@ -3856,7 +3813,7 @@ function refreshAgentFiles(rootDir, json, print) {
3856
3813
  const { agentsMd, mcpJson, skills, messages, mcpSdkDependency } = setUpAgentFiles(rootDir, true, print);
3857
3814
  if (agentsMd === "malformed") process.exitCode = 1;
3858
3815
  if (messages.length === 0 && !mcpSdkDependency) print(`[nuxt-backend] AGENTS.md, .mcp.json and the agent skills are current for nuxt-backend ${installedVersion(rootDir)}`);
3859
- if (mcpSdkDependency) print(`[nuxt-backend] Run \`npm install\` to link it, then restart your agent.`);
3816
+ if (mcpSdkDependency) print(`[nuxt-backend] Run \`${installCommand(packageManagerOf(rootDir))}\` to link it, then restart your agent.`);
3860
3817
  if (json) {
3861
3818
  const report = { agentsMd, mcpJson, skills, mcpSdkDependency };
3862
3819
  console.log(JSON.stringify(report, null, 2));
@@ -3885,17 +3842,17 @@ const init = withContract("init", {
3885
3842
  refreshAgentFiles(rootDir, args.json, print);
3886
3843
  return;
3887
3844
  }
3888
- const { start, ...setup } = setUpProject(rootDir, { force: args.force, agents: args.agents !== false, print });
3845
+ const { start, packageManager, ...setup } = setUpProject(rootDir, { force: args.force, agents: args.agents !== false, print });
3889
3846
  if (setup.agentsMd === "malformed") process.exitCode = 1;
3890
3847
  const listed = await addModuleToNuxtConfig(rootDir);
3891
3848
  print(listed ? "[nuxt-backend] Added 'nuxt-backend' to nuxt.config modules" : "[nuxt-backend] Add the module yourself: modules: ['nuxt-backend'] in nuxt.config.ts");
3892
3849
  if (args.json) {
3893
- const report = { ...setup, nuxtConfig: listed ? "listed" : "manual", next: nextCommands$1({ ...setup, start }) };
3850
+ const report = { ...setup, nuxtConfig: listed ? "listed" : "manual", next: nextCommands$1({ ...setup, packageManager, start }) };
3894
3851
  console.log(JSON.stringify(report, null, 2));
3895
3852
  return;
3896
3853
  }
3897
3854
  console.log(`
3898
- ${formatNextSteps({ ...setup, start })}
3855
+ ${formatNextSteps({ ...setup, packageManager, start })}
3899
3856
  `);
3900
3857
  }
3901
3858
  }));
@@ -1 +1 @@
1
- <!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><script type="importmap">{"imports":{"#entry":"/__nuxt-backend/_nuxt/CiCAOwUc.js"}}</script><link rel="stylesheet" href="/__nuxt-backend/_nuxt/entry.DsMplBp-.css" crossorigin><link rel="modulepreload" as="script" crossorigin href="/__nuxt-backend/_nuxt/CiCAOwUc.js"><script type="module" src="/__nuxt-backend/_nuxt/CiCAOwUc.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-backend",buildId:"e9d6e19e-077a-4bc9-a88e-863e94219dcc",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},1794354164675,false]</script></body></html>
1
+ <!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><script type="importmap">{"imports":{"#entry":"/__nuxt-backend/_nuxt/CiCAOwUc.js"}}</script><link rel="stylesheet" href="/__nuxt-backend/_nuxt/entry.DsMplBp-.css" crossorigin><link rel="modulepreload" as="script" crossorigin href="/__nuxt-backend/_nuxt/CiCAOwUc.js"><script type="module" src="/__nuxt-backend/_nuxt/CiCAOwUc.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-backend",buildId:"c2e28d37-00b0-4a61-acc5-374ba81a9d22",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},1794504332245,false]</script></body></html>
package/dist/module.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import '@nuxt/kit';
2
2
  import 'defu';
3
- import './shared/nuxt-backend.9IVxzzft.mjs';
3
+ import './shared/nuxt-backend.DbaXvH__.mjs';
4
4
  import '../dist/runtime/config.js';
5
- export { m as default } from './shared/nuxt-backend.CbR37s_c.mjs';
5
+ export { m as default } from './shared/nuxt-backend.BqXAZChe.mjs';
6
6
  import 'node:fs';
7
7
  import 'node:path';
8
8
  import 'node:url';
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-backend",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "configKey": "backend",
5
5
  "docs": "https://nuxt-backend.dev",
6
6
  "compatibility": {
@@ -1,12 +1,11 @@
1
1
  <script setup>
2
- import { computed, inject, nextTick, onMounted, ref, useId, useTemplateRef, watch } from "vue";
2
+ import { computed, inject, nextTick, ref, useId, useTemplateRef } from "vue";
3
3
  import { ConvexAuthStateKey } from "nuxt-convex-module/client";
4
4
  import { useAccessPhase, useInvite } from "../../composables/use-access";
5
5
  import { useBackendPagePath } from "../../composables/use-backend-page-path";
6
6
  import { useLabels } from "../../composables/use-labels";
7
7
  import { useReturnPath } from "../../composables/use-return-path";
8
- import { keepInvite, takeInviteFromAddress } from "../../utils/kept-invite";
9
- const invite = useInvite();
8
+ const invite = useInvite({ fromAddress: true });
10
9
  const { phase } = useAccessPhase();
11
10
  const { t, errorMessage } = useLabels("auth");
12
11
  const waitlistPath = useBackendPagePath("waitlist");
@@ -15,29 +14,12 @@ const auth = inject(ConvexAuthStateKey, null);
15
14
  const signedIn = computed(() => auth != null && auth.isAuthenticated.value);
16
15
  const codeId = useId();
17
16
  const code = ref("");
18
- const checked = ref(false);
19
- const asked = ref(false);
17
+ const checked = invite.linkChecked;
18
+ const asked = invite.asked;
20
19
  const continueLink = useTemplateRef("continueLink");
21
- onMounted(() => {
22
- const taken = takeInviteFromAddress();
23
- if (taken) keepInvite(taken);
24
- let started = false;
25
- watch(() => auth != null && auth.isLoading.value, async (loading) => {
26
- if (loading || started) return;
27
- started = true;
28
- if (signedIn.value) {
29
- invite.forget();
30
- } else {
31
- asked.value = taken !== null || invite.isKept.value;
32
- if (asked.value) await invite.check();
33
- }
34
- checked.value = true;
35
- }, { immediate: true });
36
- });
37
20
  async function redeem() {
38
21
  const typed = code.value.trim();
39
22
  if (invite.isPending.value || !typed) return;
40
- asked.value = true;
41
23
  await invite.check(typed);
42
24
  if (state.value !== "valid") return;
43
25
  await nextTick();
@@ -5,9 +5,8 @@ import { useAccessPhase } from "../../composables/use-access";
5
5
  import { useBackendPagePath } from "../../composables/use-backend-page-path";
6
6
  import { useLabels } from "../../composables/use-labels";
7
7
  import { useReturnPath } from "../../composables/use-return-path";
8
- import { useWaitlist } from "../../composables/use-waitlist";
9
- import { takeFragment, tabKeep } from "../../utils/tab-keep";
10
- const waitlist = useWaitlist({ ref: null });
8
+ import { keptStatusToken, useWaitlist } from "../../composables/use-waitlist";
9
+ const waitlist = useWaitlist({ ref: null, statusLink: true });
11
10
  const { phase, isLoading: phaseLoading } = useAccessPhase();
12
11
  const { t } = useLabels("waitlist");
13
12
  const loginPath = useBackendPagePath("login");
@@ -16,25 +15,16 @@ const home = useReturnPath();
16
15
  const auth = inject(ConvexAuthStateKey, null);
17
16
  const signedIn = computed(() => auth != null && auth.isAuthenticated.value);
18
17
  const authLoading = computed(() => auth != null && auth.isLoading.value);
19
- const opened = ref(false);
20
18
  const hadToken = ref(false);
21
19
  const left = ref(false);
22
- const kept = tabKeep("nuxt-backend:waitlist");
20
+ const kept = keptStatusToken();
23
21
  onMounted(() => {
24
- const taken = takeFragment();
25
- if (taken) kept.keep(taken);
26
- const token = taken ?? kept.read();
27
- if (token) {
28
- hadToken.value = true;
29
- waitlist.status(token);
30
- }
31
- opened.value = true;
22
+ hadToken.value = waitlist.step.value === "status";
32
23
  });
33
- watch(() => waitlist.step.value, (step, before) => {
34
- if (before !== "status" || step !== "join") return;
24
+ watch(() => waitlist.left.value, (now) => {
25
+ if (!now) return;
35
26
  left.value = true;
36
27
  hadToken.value = false;
37
- kept.drop();
38
28
  });
39
29
  function joined(place) {
40
30
  left.value = false;
@@ -46,7 +36,7 @@ function leftForm() {
46
36
  kept.drop();
47
37
  }
48
38
  const state = computed(() => {
49
- if (!opened.value || authLoading.value || phase.value === void 0 && phaseLoading.value || hadToken.value && waitlist.isLoading.value) return "checking";
39
+ if (!waitlist.linkChecked.value || authLoading.value || phase.value === void 0 && phaseLoading.value || hadToken.value && waitlist.isLoading.value) return "checking";
50
40
  if (signedIn.value) return "member";
51
41
  if (phase.value === "public") return "open";
52
42
  if (hadToken.value && waitlist.place.value !== void 0) return "ready";
@@ -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 } from "../../composables/use-labels";
12
+ import { usePlanChange } from "../../composables/use-plan-change";
12
13
  import { usePricing } 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 } 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 { providePricingView } from "./pricing-table";
22
23
  defineOptions({ name: "PricingTable" });
23
24
  const props = defineProps({
@@ -48,8 +49,9 @@ const billing = useBilling();
48
49
  const credits = useCredits();
49
50
  const campaign = useCampaign();
50
51
  const experimentDiscount = useExperimentDiscount();
52
+ const asked = () => props.discount ?? campaign.discountCode.value ?? experimentDiscount.value;
51
53
  const pricing = usePricing({
52
- discount: () => props.discount ?? campaign.discountCode.value ?? experimentDiscount.value,
54
+ discount: asked,
53
55
  actions: false,
54
56
  // Read when a checkout starts, so a changed prop counts.
55
57
  successUrl: {
@@ -61,16 +63,7 @@ const pricing = usePricing({
61
63
  }
62
64
  }
63
65
  });
64
- const subscriptionCurrency = computed(() => {
65
- const currency = billing.subscription.value?.currency;
66
- return typeof currency === "string" && currency !== "" ? currency.toLowerCase() : void 0;
67
- });
68
- const switchPricing = usePricing({
69
- server: false,
70
- actions: false,
71
- currency: () => subscriptionCurrency.value,
72
- enabled: () => billing.isSubscribed.value && billing.pass.value === null && subscriptionCurrency.value !== void 0 && pricing.currency.value !== void 0 && subscriptionCurrency.value !== pricing.currency.value
73
- });
66
+ const planChange = usePlanChange({ labels: () => props.labels, pricing });
74
67
  const route = useRoute();
75
68
  const { isAuthenticated } = useAuthSession();
76
69
  const config = useBackendConfig();
@@ -107,8 +100,7 @@ function resolvePlan(card, offer) {
107
100
  const priceAt = offer.prices[at];
108
101
  const isCurrent = Object.values(offer.prices).some((price) => price?.productId === subscribedId.value);
109
102
  const comparable = !isCurrent && currentMonthly.value !== void 0;
110
- const scheduled = billing.pendingChange.value;
111
- const scheduledFor = scheduled?.productId === priceAt.productId ? scheduled.appliesAt : void 0;
103
+ const scheduledFor = planChange.scheduledFor(priceAt.productId) ?? void 0;
112
104
  const priceCurrency = offer.free ? pricing.currency.value ?? priceAt.currency : priceAt.currency;
113
105
  return {
114
106
  ...card,
@@ -186,23 +178,12 @@ async function run(key, busy2, action) {
186
178
  }
187
179
  }
188
180
  const planByKey = (key) => resolvedPlans.value.find((plan) => plan.key === key);
189
- const payIn = (currency) => currency && pricing.currencies.value.length > 1 ? { currency } : {};
190
- function refusedCode(failure) {
191
- const refusal = getBackendError(failure);
192
- const field = refusal?.data?.field;
193
- return refusal?.code === "invalid_input" && (field === "discountCode" || field === "discount");
194
- }
195
- async function withCampaign(offered, start) {
196
- const { discountCode, ...attribution } = campaign.checkoutOptions.value;
197
- const promotion2 = props.discount ?? (discountCode ? void 0 : experimentDiscount.value);
198
- const options = promotion2 && offered ? { ...attribution, discount: promotion2 } : { ...attribution, ...discountCode ? { discountCode } : {} };
199
- try {
200
- return await start(options);
201
- } catch (failure) {
202
- if (!("discountCode" in options || "discount" in options) || !refusedCode(failure)) throw failure;
203
- return start(attribution);
204
- }
205
- }
181
+ const { payIn, withCampaign } = pricingCheckout({
182
+ campaign,
183
+ asked,
184
+ active: () => pricing.activePromotion.value,
185
+ currencies: () => pricing.currencies.value
186
+ });
206
187
  const emailOptOut = ref(false);
207
188
  const showsEmailOptOut = computed(() => billing.softOptIn?.value === true && isAuthenticated.value && billing.canManage.value);
208
189
  const optOut = () => showsEmailOptOut.value ? { emailOptOut: emailOptOut.value } : {};
@@ -219,7 +200,7 @@ async function checkOutFromPass(key) {
219
200
  const switchTo = (key) => run(key, () => t("changing"), async () => {
220
201
  const plan = planByKey(key);
221
202
  if (!plan) return;
222
- await billing.changePlan(plan.priceAt.productId, { proration: CONFIRMED_PRORATION });
203
+ await planChange.switchTo(plan.priceAt.productId);
223
204
  change.settle();
224
205
  emit("plan-changed", key);
225
206
  void nextTick(() => returnFocus(root.value?.querySelector(`[aria-labelledby="${uid}-plan-${key}"] [data-pricing="plan-action"]`) ?? root.value?.querySelector('[data-pricing="plan"][data-current] [data-pricing="plan-action"]')));
@@ -228,21 +209,6 @@ function returnTo(kind, key) {
228
209
  const url = pricing.successUrlFor(kind, key);
229
210
  return url ? { successUrl: url } : {};
230
211
  }
231
- function changeTarget(plan) {
232
- const price = billing.pass.value === null ? priceInSubscriptionCurrency(plan) : plan.price;
233
- if (price === null) return null;
234
- if (price === "") return void 0;
235
- const name = plan.isCurrent ? t(`billedAt.${plan.interval}`, { plan: plan.name }) : plan.name;
236
- return { key: plan.key, productId: plan.priceAt.productId, plan: name, price: `${price}${t(`period.${plan.interval}`)}` };
237
- }
238
- function priceInSubscriptionCurrency(plan) {
239
- const currency = subscriptionCurrency.value;
240
- if (!currency || plan.priceAt.currency === currency) return plan.price;
241
- const offers = switchPricing.plans.value;
242
- if (offers === void 0) return null;
243
- const at = offers.find((entry) => entry.key === plan.key)?.prices[plan.interval];
244
- return at?.productId === plan.priceAt.productId && at.currency === currency ? formatBillingAmount(at.amount, at.currency, locale.value) : "";
245
- }
246
212
  const root = ref(null);
247
213
  const confirm = createCancelConfirm({
248
214
  family: "pricing",
@@ -258,11 +224,11 @@ const change = createPlanChangeConfirm({
258
224
  titleTag: "p",
259
225
  partId: (part) => `${uid}-change-${part}`,
260
226
  isBusy: () => pending.value !== null && pending.value === change.target.value?.key,
261
- preview: (productId) => billing.changeOf(productId),
227
+ change: planChange,
262
228
  confirm: (target) => billing.pass.value === null ? switchTo(target.key) : checkOutFromPass(target.key),
263
229
  t,
264
230
  date: (value) => formatBillingDate(value, { dateStyle: "medium" }, locale.value) || null,
265
- gifted: (target) => billing.pass.value === null ? null : t("changeGifted", { price: target.price })
231
+ gifted: (target) => t("changeGifted", { price: target.price })
266
232
  });
267
233
  function cancelPlan(key) {
268
234
  return run(key, () => t("canceling"), async () => {
@@ -343,7 +309,7 @@ function planAction(plan) {
343
309
  }
344
310
  if (plan.scheduledFor) return { kind: "note", hook: "plan-scheduled", text: t("scheduled", { date: formatBillingDate(plan.scheduledFor, { dateStyle: "medium" }, locale.value) }) };
345
311
  if (billing.isSubscribed.value) {
346
- const target = changeTarget(plan);
312
+ const target = planChange.targetFor(plan.key, plan.interval);
347
313
  if (target === void 0) return { kind: "none" };
348
314
  const asks = billing.pass.value !== null || billing.changeOf(plan.priceAt.productId) !== null;
349
315
  const switching = (intent2, idle) => target === null ? { kind: "button", intent: intent2, idle, busy: t("changing"), run: () => {
@@ -8,10 +8,9 @@ import { useApiNamespace } from "../../utils/namespace";
8
8
  const invite = useReferralInvite();
9
9
  const { t, errorMessage } = useLabels("referral");
10
10
  const home = useBackendPagePath("settings");
11
- const invitePath = useBackendPagePath("invite");
12
11
  const waitlistPath = useBackendPagePath("waitlist");
13
12
  const { phase } = useAccessPhase({ api: useApiNamespace("access") ?? {} });
14
- const inviteTo = computed(() => invitePath.value ? `${invitePath.value}?ref=${encodeURIComponent(invite.code.value)}` : null);
13
+ const inviteTo = invite.inviteTo;
15
14
  const needsTicket = computed(() => invite.state.value === "ready" && invite.closed.value === true);
16
15
  const phaseUnknown = computed(() => invite.state.value === "ready" && invite.closed.value === void 0);
17
16
  const offer = computed(() => invite.preview.value?.program.referred ?? null);