Skip to content

feat(demo): show the demo brand in the product and start a plan by buying or a free trial (demo brand, part 5) - #1738

Merged
gkhngyk merged 144 commits into
ansvisor:mainfrom
cihan-gyk:feature/demo-brand-web
Oct 29, 2026
Merged

gkhngyk merged 144 commits into
ansvisor:mainfrom
cihan-gyk:feature/demo-brand-web

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Demo brand, part 5 of 7 (web). The demo brand in the product: who gets it, how it looks, and how every action on it turns into the plan dialog. It also brings the two ways to start a plan (buy now, or the free trial) to every place a plan starts.

Who gets it

  • Sign-up, plan step: below the plans, Not ready to add a card? Explore a demo brand. The demo is built ahead while the person sets up their own brand (from step 2), so the click usually opens it at once. When it's still being built, a setup screen shows its real steps (DemoSetupDialog, lib/demo/setup-steps.ts).
    • An admin who never subscribed and has a demo brand lands on the read-only dashboard instead of being sent back to the plan step (hasDemoBrand in evaluateSubscriptionAccess).
  • Ended trial or cancelled plan: the workspace keeps its own data read-only, and the read-only banner offers See the demo.
  • After a purchase the demo brand is hidden, never deleted. It is hidden on Stripe's checkout.session.completed and on the return from Checkout, whichever comes first, and only when a subscription starts. Admins and managers show or hide it again from the brand menu.

How it looks

  • A band across the top while the demo brand is open. It names the workspace's own brand ("Start tracking Acme Coffee…") and leads to the plans, or, with a plan active, back to the own brand. Each visit asks POST /api/demo once whether the demo is current, and refreshes the page if it was rebuilt.
  • Brand menu: Demo · sample data, with Show/Hide. The demo brand doesn't count toward the plan's brand limit.
  • The demo brand reads as Growth, the whole product (effectivePlanIdForBrand). Its locked tabs, engines and reports open. Writes still open the plan dialog. Enterprise and self-hosted keep their own plan.
  • Chat shows Soon (next week) in the menu. The page shows the Chat v2 mockups 1:1 (static copies under web/public/demo/chat, 820 KB with the logos, in an iframe), with Brewline Coffee as the tracked brand.
    • Chat preview follows the app's dark theme (1204e5f).
    • The Chat preview answers its shortcuts (⌘/Ctrl ⇧O new chat, K search) from anywhere on the page, and shows ⌘ on a Mac (8f3ea5f).
  • Settings › Integrations: Google Search Console, Google Analytics and Webflow show as connected with sample data, marked Sample data. Merchant Center, Shopify and Wix show as Coming soon. WordPress and Framer, live on main now, show as on any brand: their buttons open the plan dialog through useUpgradeGate, the same gate as read-only.
  • The Danger tab says the demo brand is hidden, not deleted. The demo's made-up sites get real-looking logos (web/public/demo/logos).

Nothing runs on it

  • useUpgradeGate treats the demo brand as locked, whatever the plan. Its dialog makes the demo's offer: the free trial or 50% off the first month for a workspace that never subscribed, buying now for one whose plan ended. With a plan active, it points back to the own brand.
  • Server actions: every action that writes for a brand passes its brand to assertWritable({ brandId }), which refuses a demo brand with DemoBrandError (46 calls in 21 files). The brand and the plan are read in one round trip, with main's named organizations!profiles_organization_id_fkey relationship.
    • subscription-guard-coverage.test.ts fails on a new brand write that doesn't hand its brand over.
    • Next routes answer 402 demo_brand. api-failure reads demo_brand as a plan refusal, so a call no button caught still opens the dialog.

Two ways to start a plan, both with a card

  • Buy now: the full plan from day one, with 50% off the first month on a monthly plan (SAVE50, marked Limited offer).
  • 14-day free trial: limited AI usage, then the usual price, no discount. Only for an organization that never had a subscription.
  • One start selector above the cards (trial / monthly / yearly), one button per plan, a "Due today" line per card, the trust line ("Secure checkout with Stripe · Cancel any time") and the trial's end date. A promo code goes behind Have a code?.
  • Shared by the plan dialog, Billing and the onboarding plan step (components/billing/plan-start.tsx). Onboarding says what is ready to track for the own brand.
  • POST /api/stripe/checkout now takes mode: 'buy' | 'trial'. A trial with a promo code is refused (400). A trial for an organization, or a Stripe customer, that already had a subscription is refused too (409 trial_unavailable); the client then turns to buying.
  • Flag: NEXT_PUBLIC_FIRST_MONTH_OFFER=off turns the offer off everywhere; the code must also be ended in Stripe. .env.example documents it.

Fixes in this branch

  • A new browser no longer shows "No brands yet" or the read-only band for a moment before the demo selection resolves (3113a16). The brand store says when it holds the server's list (loaded, never persisted). Until then pages show their skeleton and the bands and Add Brand wait. Leaving the dashboard clears it.
  • A new sign-up's free plan reads as Starter (toPlanId).
  • Merging main: createTopics, createTopic and updateTopic had two plan checks each; now each has one, first, with its brand (6699a7e).

Merge notes (main merged in, nothing on main undone)

Deploy: server first (00380, 00381, /api/demo), then the web. No migration in this part.

Related issue

None (demo brand).

Stacked on #1737 (demo brand, part 4: guard).

Type of change

  • feat — New feature
  • fix — Bug fix (first-load flash, free plan as Starter, double plan check)

How to test

Locally, with parts 1–5, the dev database, NEXT_PUBLIC_IS_CLOUD=true and the demo account ([email protected]):

  1. Open http://localhost:3000 in a fresh browser profile and sign in. The demo brand opens on the Action Center with its band. No "No brands yet" or read-only band shows first.
  2. Prompts (12 prompts), Action Center, Content, Audit, AI Referral Traffic and Product Visibility are filled.
  3. See plans in the band: the plan dialog with the start selector (14-day trial / Monthly 50% off the first month / Yearly) and "Due today" on each card.
  4. Add prompt on Prompts: the plan dialog, labelled "Adding prompts works on your own brand". No prompt dialog opens.
  5. Chat: Soon (next week) and the preview. Press ⌘/Ctrl ⇧O or ⌘/Ctrl K with the focus outside the preview: it answers. Switch the app to dark: the preview follows.
  6. Settings › Integrations: Search Console, Analytics and Webflow connected with Sample data; Merchant Center, Shopify and Wix Coming soon; WordPress and Framer Connect opens the plan dialog.
  7. Brand menu: Hide the demo brand, then Show the demo brand.

For the maintainer (Stripe, test mode): Checkout can't be tried without Stripe keys locally. Please try both modes: Buy now monthly with SAVE50 (does the 50% land on the first invoice?) and the 14-day trial (card taken, no code, $0 today). Then check that the demo brand is hidden after either.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • Web: yarn typecheck passes. ESLint on the 261 files the main merge touched: 0 errors (2 warnings, in files identical to main). Prettier: clean.
  • Web tests: the conflicted files' tests plus lib/demo, components/billing, providers, settings, layout, lib/mcp, lib/billing, hooks and stores (98 files, 1,083 tests) pass. The Library page test timed out once under load and passes alone (63 tests).
  • The embed guard from test(web): fail on an embed between twice-joined tables that doesn't name its foreign key #1714 passes on this branch
  • Browser check on a local server (fresh profile): the steps above, light and dark
  • Full CI-like run: done at the top of the stack (docs PR), see there
  • Stripe test-mode checkout (both modes): the maintainer's

🤖 Generated with Claude Code

cihan-gyk and others added 30 commits October 27, 2026 17:58
…e "Choose a plan" dialog

On the cloud, an ended trial, a cancel during the trial and a cancel
after the first payment can now sign in and look around. They used to
see a full-screen "subscription expired" notice that only signed out.
Onboarding is unchanged: an admin who never started a trial still goes
to the plan step.

- The dashboard layout lets these workspaces in, read-only. A thin
  banner says so, with "See plans".
- UpgradeDialogProvider and useUpgradeGate ({ guard, isLocked,
  openUpgrade }) open one "Choose a plan to keep going" dialog, with the
  action that was clicked as a label.
  - Admins go to Billing; members are told to ask their admin.
  - A failed payment (past_due, unpaid) says so and opens Stripe's
    portal.
  - A 402 subscription_inactive from the API opens the dialog
    (use-failure-toast, api-failure's subscription class, and the
    Webflow, catalog, publish and Send to CMS clients).
- Automatic calls (Library's Webflow status, the editor's link, source,
  claim and page reads, Improve's read) aren't sent while locked.
- Billing: an ended subscription starts a new Checkout ("Choose
  {plan}", monthly or annual). The checkout route takes admins only,
  refuses a second live subscription (409), and validates its body.
  Billing reads again after a change.
- MCP: list_ and get_ tools stay open; every other tool, and REST
  writes, answer subscription_inactive. Chat and new conversations
  answer 402, and runSiteAuditFor, generateBriefFor and
  createImproveActionFor check too. A chat message refused by a 402
  goes back to the input.

Self-hosted is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…r Annual and a promo code

The "Choose a plan to keep going" dialog for an ended plan now carries
the plans, as the approved design has them.
- Starter and Growth (Popular) have "Choose {plan}"; Custom has "Starting
  at $499/mo" and "Contact us". Each lists the Billing cards' features,
  through a shared usePlanFeatures.
- Monthly or Annual ("Save 20%"): an annual price shows its struck 12×
  price and what it is a month.
- A promo code is checked by the API (POST /api/stripe/promo-code, admins
  only), through the same Stripe lookup ansvisor#1300 uses (findPromotionCode,
  takesPromoCode: monthly plans only).
  - A valid code shows its chip, the first month's price on each card and
    in the button ("Choose Growth · $124.50 today").
  - A bad one says so; on Annual a note offers Switch to Monthly.
- Choose opens Stripe Checkout for that plan and period, with the code
  applied as a discount. The checkout route checks the code again and
  refuses it on an annual plan.
- Members see "Ask your admin to choose a plan", with no code field.
- The footer reads "Prices in USD." with a link to the pricing page.
- A failed payment keeps its "Update payment method" dialog.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… the plan has ended

Read-only, part C1. On an ended plan, every action in Prompts, Prompt
Suggestions, Topics, Query Fan-out, Brand Visibility and Competitors
opens the "Choose a plan" dialog with the action named, and runs
nothing. On an active plan they run as before. Buttons aren't disabled.
- Tracked Prompts: add, import, edit, analyze and refresh volumes, the
  bulk bar, work status and the row menu.
- Prompt and topic suggestions: generate, add, accept, dismiss.
- Manage prompts and topics: add, generate, locations, analyze, edit,
  delete.
- Query Fan-out's Track; Brand Visibility's Run All, Test Single Prompt,
  Opportunities' Track and Send, and pinning a competitor.
- Competitors: suggest (its dialog calls AI on opening), add, delete.
- The Positions panel: Improve's Generate and Regenerate, Send Actions,
  and Create or Optimize content.
- The labels live in readOnly.actions.* ("Adding prompts needs a plan").
- volumes.ts tells the API's 402 subscription_inactive from a feature
  the plan lacks, so a refused analysis opens the dialog instead of "not
  part of your current plan".
- While locked, Tracked Prompts doesn't warn that volume data is
  unavailable, and Query Fan-out doesn't send its intent classification.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…keep the editor read-only, while the plan has ended

Read-only, part C2. On an ended plan, every action that writes or costs
in Content Opportunities, the opportunity panel, Content Plan, Library,
New content and the Content Editor opens the "Choose a plan" dialog,
naming the action, and runs nothing.
- Opportunities: New, the bulk bar (send, done, dismiss and delete open
  the dialog instead of their confirm), the row menu, the webhook
  settings' Test and Save, and the panel's sends, brief, Reviewed,
  Restore and Dismiss.
- Plan: New content, Start, Assign, Priority, Hide and Show. A ?start=
  link starts nothing while locked.
- Library: New content (and ?new=1), status changes, archive, delete,
  and single and bulk Send to CMS.
- The editor:
  - Run Agent, Rewrite, Fix rules, hand-off;
  - accepting or rejecting suggestions;
  - Mark ready, Ready back to review, Mark published, Send to CMS,
    History Restore;
  - page and site type, author and reviewer;
  - Quality's confirms, sources and images, and Add line or Remove;
  - renaming, dropping files, the toolbar;
  - the Brief's run, rewrite and edit; the Sources and Rules changes;
    Your input.
- The editor itself is read-only while locked (editable: false, the
  HTML view readOnly), and autosave is off (useDraftAutosave { off }):
  nothing is saved, and leaving doesn't warn.
- Reading, filters, exports, Copy HTML and Stop stay open.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d from every way to add a brand, while the plan has ended

Site Audit, Action Center, Mentions, Citations, AI Referral Traffic,
Shopping, Reports, Chat, brand settings and Settings now guard their
actions with useUpgradeGate, as Prompts (ansvisor#1606) and Content (ansvisor#1609) do.
Every way to add a brand (sidebar, /dashboard/brands, brand guard,
/dashboard/brands/new) opens the dialog. Disconnects, key revokes and
API key creation stay open.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…has ended, on the server

Server actions and Next routes that write to Supabase without going
through the API now call assertWritable() first: on the cloud, an
organization without an active plan gets SubscriptionInactiveError
(routes: 402 subscription_inactive), so the read-only rule holds even if
a guarded button is bypassed. Setup's writes stay open to an
organization that never subscribed, as the API's onboarding routes do.
Profile, invitations accepted, revokes, removals, API keys and billing
stay open. A static test pins every writing action to the check or to
the open list.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ng stores open while read-only, and stop the site trust card's automatic re-read

From the pre-push review: ending an access stays open, as disconnects
do; a partial site trust result isn't re-read while the plan has ended,
since that read scrapes. Adds tests for the audit page's Run audit and
the integrations' property mapping, resets shared mocks between tests,
closes the mobile menu before the dialog, and words the KPI preview for
a read-only workspace.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…it too, while read-only

At the limit, /dashboard/brands' Add Brand links to Billing; a read-only
workspace now gets the dialog there as on every other way to add a brand.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Ansvisor's decision (2026-10-27): deleting a brand only removes what the
person gave us, so it stays open while the plan has ended. The API opens
DELETE /brands/:id in ansvisor#1611.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d the plan in one query, and pin the write check's place

From the pre-push review: markBrandAsEcommerce no longer goes through
the strictly guarded setBrandShoppingMode (a shared applyShoppingMode
does the writes), so a setup detected as e-commerce turns Shopping on
again. assertWritable reads the profile and its organization in one
query. The coverage test now requires the check as each writer's first
await, sees writers kept in variables and signed upload URLs, refuses a
setup-open function that reaches a strictly guarded one, and keeps brand
deletion open (Ansvisor, 2026-10-27). main's saveDraftShoppingPath is
guarded; catalog-client's every-code test leaves out 'subscription',
which opens the plan dialog instead of a message.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… plan has ended, and keep the buttons opening the plan dialog

With ansvisor#1611, an ended workspace's quota reads come back as `noPlan` with
0 limits. isNoPlan(quota, isLocked) keeps those from reading as used up:
Site Audit, Prompts, the content usage card, Improve and the opportunity
panel say "No active plan" instead of a red 0/0 or "limit reached", and
their buttons stay clickable so the guard opens the dialog. The AI bot
report shows the workspace's own data instead of the Starter upsell.
Setup's suggestions name the onboarding daily limit (429) on their own.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…upsell and one lock rule while the plan has ended

From the pre-push review: the Prompts row menu still looks up an open
content suggestion with no plan; an ended Starter workspace keeps the
bot report's upsell (its old plan has no report), read from the plan
the web already knows; auditBlock, bulkSuggestBlock and the bot states
take isLocked as the pages do; the audit settings and the content usage
tooltip don't speak of a plan that renews; setup's prompt step keeps its
own "add your own" line. Improve's unreachable no-plan branch is gone.
Tests for the onboarding limit and the quota meter.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…essage test

main's catalog-client test (ansvisor#1583) asks for words for every StoreError
code; 'subscription' opens the upgrade dialog instead of saying one, so
the test leaves it out, as ansvisor#1613 does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…y-plan-dialog

Co-Authored-By: Claude Opus 5.5 <[email protected]>

# Conflicts:
#	web/src/components/settings/plan-switcher.tsx
…nd main's other new actions while the plan has ended

main's new writes, with C3's guard pattern and labels:
- Merchant Center (ansvisor#1583): picking and adding an account open the plan
  dialog ("Connecting a store needs a plan"); the server's 'subscription'
  refusal on Add opens it too, instead of looking up a missing
  settings.catalog.stores.errors.subscription message.
- Category pages (ansvisor#1587): Change, Save, No page and Use the match are
  guarded; the catalog client reads the server's 402
  subscription_inactive as 'subscription', which opens the dialog
  instead of the generic failure.
- Brief › Shopping path (ansvisor#1591): Pick from the catalog, Pick again, Add
  product, Lock, Swap and Remove are guarded.
- Action Center Check now (AC-010, ansvisor#1565) is guarded.

New labels: changeCategoryPages, changeShoppingPath, checkTasks.
Insert › Products (ansvisor#1607) already goes through the toolbar's guard and
the read-only editor shows no insert menu; a test now says so. The
Shopping rules (ansvisor#1610) change through the rules hook, already guarded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…g it during render

React's refs rule refuses passing add, which reads addingRef, to guard
while rendering. add now opens the plan dialog itself on a read-only
workspace.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	web/src/app/[locale]/(dashboard)/dashboard/brands/[id]/prompts/page.test.tsx
cihan-gyk and others added 9 commits October 29, 2026 00:49
…ver main's new tables

sweepPromptDemand chose brands by their organization's plan only, so an
active workspace's demo brand would have had its sample prompts read and
DataForSEO's paid tasks set for them. It now leaves demo brands out, as
the other sweeps do. The demo coverage list names the two brand tables
main added: prompt_table_views (skipped: the demo starts on the default
columns) and prompt_demand (pending a demo follow-up).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lumn layouts open

Main added write routes that name a brand: Action Center's audits and
products, WordPress and Framer connections, and their publish-status
checks. Each now answers 402 demo_brand on a demo brand, as the Webflow
ones do. The Tracked Prompts column layouts (prompt_table_views, 00363)
stay writable on a demo brand: they change no sample data and cost
nothing, and the web keeps them open while read-only too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	web/messages/en.json
#	web/src/app/[locale]/(dashboard)/dashboard/agent/page.test.tsx
#	web/src/app/[locale]/(dashboard)/dashboard/agent/page.tsx
#	web/src/app/[locale]/(dashboard)/dashboard/brands/[id]/settings/page.tsx
#	web/src/app/[locale]/(dashboard)/dashboard/brands/page.test.tsx
#	web/src/app/[locale]/(dashboard)/dashboard/content/library/_bulk-send-dialog.tsx
#	web/src/app/[locale]/(dashboard)/dashboard/content/library/page.test.tsx
#	web/src/app/[locale]/(dashboard)/dashboard/content/library/page.tsx
#	web/src/app/[locale]/(dashboard)/dashboard/prompts/_suggestions-card.test.tsx
#	web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx
#	web/src/app/[locale]/(dashboard)/layout.test.tsx
#	web/src/app/[locale]/(dashboard)/layout.tsx
#	web/src/app/[locale]/(onboarding)/dashboard/onboarding/page.test.tsx
#	web/src/app/[locale]/(onboarding)/dashboard/onboarding/page.tsx
#	web/src/app/api/stripe/checkout/route.test.ts
#	web/src/app/api/stripe/checkout/route.ts
#	web/src/components/action-center/action-drawer.test.tsx
#	web/src/components/action-center/action-drawer.tsx
#	web/src/components/action-center/action-table.tsx
#	web/src/components/billing/choose-plan-dialog.test.tsx
#	web/src/components/billing/choose-plan-dialog.tsx
#	web/src/components/billing/read-only-banner.test.tsx
#	web/src/components/billing/read-only-banner.tsx
#	web/src/components/content/send-to-cms-dialog.tsx
#	web/src/components/dashboard/add-brand-link.test.tsx
#	web/src/components/layout/brand-switcher.test.tsx
#	web/src/components/layout/brand-switcher.tsx
#	web/src/components/providers/plan-provider.tsx
#	web/src/components/providers/upgrade-dialog-provider.test.tsx
#	web/src/components/providers/upgrade-dialog-provider.tsx
#	web/src/components/providers/upgrade-gate.ts
#	web/src/components/settings/billing-section.tsx
#	web/src/components/settings/integrations-section.test.tsx
#	web/src/components/settings/integrations-section.tsx
#	web/src/components/settings/plan-switcher.test.tsx
#	web/src/components/settings/plan-switcher.tsx
#	web/src/components/settings/webflow-card.tsx
#	web/src/lib/actions/action-center.ts
#	web/src/lib/actions/action-task-reviews.ts
#	web/src/lib/actions/brand-domain.ts
#	web/src/lib/actions/brand-platform.ts
#	web/src/lib/actions/brand.ts
#	web/src/lib/actions/catalog.ts
#	web/src/lib/actions/competitor.ts
#	web/src/lib/actions/content-authors.ts
#	web/src/lib/actions/content-drafts.ts
#	web/src/lib/actions/content-plan.ts
#	web/src/lib/actions/content-settings.ts
#	web/src/lib/actions/content.ts
#	web/src/lib/actions/getting-started.ts
#	web/src/lib/actions/integrations.ts
#	web/src/lib/actions/kpis.ts
#	web/src/lib/actions/prompt-suggestions.ts
#	web/src/lib/actions/prompt.ts
#	web/src/lib/actions/read-only.test.ts
#	web/src/lib/actions/reports.ts
#	web/src/lib/actions/shopping-openai-index.ts
#	web/src/lib/actions/signals.ts
#	web/src/lib/api-failure.test.ts
#	web/src/lib/api-failure.ts
#	web/src/lib/billing/plan-purchase.test.ts
#	web/src/lib/billing/subscription-access.test.ts
#	web/src/lib/billing/subscription-access.ts
#	web/src/lib/mcp/server.ts
#	web/src/lib/mcp/subscription-gate.test.ts
#	web/src/lib/subscription-guard-coverage.test.ts
#	web/src/lib/subscription-guard.test.ts
#	web/src/lib/subscription-guard.ts
The preview reads the app's .dark class from its parent page and follows it live; standalone it follows the system setting. Its colours moved to variables with a dark palette close to the app's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ck comes first

Merging main left createTopics, createTopic and updateTopic with two
plan checks each: main's, moved ahead of the name check, and the demo's,
which hands the brand over. Each now checks once, first, with its brand
where it has one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…page

⌘ or Ctrl with ⇧O (new chat), K (search), J (side panel) or \ (menu)
reach the preview while the app around it has the focus: the page hands
them to the frame, which answers them as it does inside. The frame takes
the focus when it opens, and on a Mac the preview shows ⌘ for Ctrl.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cihan-gyk and others added 13 commits October 29, 2026 18:49
…core

# Conflicts:
#	server/src/lib/action-center/execution/run.js
#	server/src/lib/action-center/execution/run.test.js
#	supabase/schema.sql
…n's new tables

sweepCompetitorTimeline (learning C3, on main) chose brands by their
organization's plan only, so a demo brand's sample answers would have had
their cited pages read every night. It now leaves demo brands out, as the
other sweeps do. The demo coverage list names the brand tables main added:
cited_page_features, competitor_page_events and competitor_timeline_scans
(pending a demo follow-up) and chat_conversations (with Chat).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Chat's precedence (ansvisor#1776) left readBrandIsDemo false until the demo chain
added brands.is_demo, with a type check that stops compiling once the
column exists. It now reads the column, as the server's demo guard does,
so a tool that changes or spends on the demo brand is refused with
demo_brand; a brand that isn't found isn't one, and a failed read throws.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
POST /brands/:id/detect-site-type (ansvisor#1761, on main) reads the brand's home
page and may ask AI for its kind. The demo guard's coverage test fails on a
write route in neither list, so it is now guarded by the brand in its path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
chat_user_prefs (00400) and chat_auto_choices (00401) are a person's own
rows, not a brand's: the write guard's coverage test fails on a writable
table in no list, so both are named as no brand's rows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	web/src/lib/actions/brand.ts
#	web/src/lib/actions/prompt.test.ts
#	web/src/lib/actions/prompt.ts
#	web/src/lib/subscription-guard.ts
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

Merged main forward through #1737's updated branch (conflicts in web/src/lib/subscription-guard.ts, web/src/lib/actions/brand.ts, web/src/lib/actions/prompt.ts and its test; resolved by keeping both sides: failedCallResponse answers both DemoBrandError and main's RoleRequiredError; markBrandAsEcommerce keeps main's siteType result and the demo's assertWritable({ onboarding: true, brandId }); the Positions column reads main's embedded organization row plus is_demo, then applies effectivePlanForBrand to planFromOrgRow).

Typecheck and the conflicted files' tests pass (plus subscription-guard-coverage, read-only, demo and billing lib tests).

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, with follow-ups: the demo opens read-only for a workspace without a plan, and a plan still starts only through Stripe Checkout. Nothing here grants one. This part changes nothing I'd block on. take-1738 (35f11f56) is this head with take-1737 merged in (part 4's fixes), so later parts carry them. Merging with main needs four conflicts resolved (below).

What I checked:

  • Starting a plan. One caller is left: useStartCheckout → POST /api/stripe/checkout. Its new mode (buy | trial) is required.
    • The trial goes only to an organization with no stripe_subscription_id whose Stripe customer never had a subscription (hasUsedTrial), else 409 trial_unavailable.
    • A code with the trial is refused (promo_with_trial).
    • Both modes take a card (payment_method_collection: 'always').
    • The first-month code is looked up in Stripe again, not taken from the client. If Stripe no longer takes it, the plan opens at its price with Checkout's own code box.
    • The organization is still checked against the caller, admins only, and never beside a live subscription.
    • The plan itself is written only by the webhook and the success route, from Stripe's subscription, as before.
  • The demo's plan. effectivePlanForBrand raises Starter to Growth on the demo brand only for what's read: the plan context, the Positions column's engines. Every write still goes through assertWritable({ brandId }), which refuses the demo brand with DemoBrandError whatever the plan. Behind that are the API's guard and 00381.
  • A workspace that never subscribed. With a demo brand, its admin gets read_only instead of the redirect to the plan step (evaluateSubscriptionAccess). Writes stay refused (assertWritable reads the subscription, not the plan; toPlanId maps free to Starter for limits only).
  • Hiding. hideDemoBrandAfterPurchase runs only on checkout.session.completed and the success route, only for an active or trialing subscription, and only on a demo brand still shown. It never deletes it, and it never throws into the purchase. The layout leaves a hidden demo brand out of the brand list.
  • Sign-up. wantsDemoAhead builds the demo ahead only for an admin of an organization without a plan and without a demo brand. Anything it can't read says no.
  • Server actions. Those that write with the service role (startDraftFromAction) pass brandId to assertWritable. The rest write as the person, so 00381 refuses them in the database.
  • Embeds. One new one, profiles → organizations!profiles_organization_id_fkey (hinted; two FKs). The rest are plain column reads.
  • Tests. On take-1738, the web tests in every area this PR touches pass: 168 files, 1,305 tests. tsc is clean.

Merge (with main 3b7611c): conflicts in

  • web/src/lib/actions/brand.ts: keep main's siteType in the return type and this PR's assertWritable({ onboarding: true, brandId }).
  • web/src/lib/actions/prompt.ts and prompt.test.ts: main now reads the plan through the brand's embed. Keep it and add is_demo: .select(\organization_id, is_demo, organizations!brands_organization_id_fkey(${ORG_PLAN_COLUMNS})`), then effectivePlanForBrand(planFromOrgRow(org ?? null), brand.is_demo === true). Keep getOrgPlanand add theeffectivePlanForBrandimport. The test mock returns bothis_demoandorganizations`.
  • web/src/lib/subscription-guard.ts: keep both lines (RoleRequiredError and DemoBrandError).
  • Plus run.js/run.test.js/schema.sql from the earlier parts.

Resolved that way, tsc and the web tests above pass on the merged tree, except two checks that main pins on purpose. chat/precedence-context.test.ts stops compiling once brands.is_demo is in the types: wire readBrandIsDemo to it in the same merge (part 1's types). mcp/demo-gate.test.ts is part 6's.

Follow-ups:

  1. Clients open across the deploy POST to checkout without mode and get a 400 until they reload. A default of buy when mode is missing would cover the first hour.
  2. Buy now no longer comes with the trial. A first subscription used to get the 14 days automatically, and now it gets them only by choosing the trial. That's intended in the docs; worth a line in the release note.
  3. Copy that will age: "Soon (next week)" for Chat in the band, the preview and the docs.

@gkhngyk
gkhngyk merged commit d16dcce into ansvisor:main Oct 29, 2026
3 of 5 checks passed
@github-actions github-actions Bot removed the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants