Skip to content

feat(integrations): connect HubSpot per brand, with consent and the Ansvisor property group - #2265

Merged
gkhngyk merged 4 commits into
ansvisor:mainfrom
cihan-gyk:feature/hubspot-connect
Nov 10, 2026
Merged

gkhngyk merged 4 commits into
ansvisor:mainfrom
cihan-gyk:feature/hubspot-connect

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

HubSpot, part 1 of #2140, as the owner approved it on 2026-11-10: the plan, and the mockup's Settings card, connect dialog and disconnect dialog. Settings › Integrations gets a new CRM group with a HubSpot card for the active brand.

What a person sees

  • Growth and above. On Starter the card is locked: a Growth badge, "HubSpot comes with the Growth plan", and Upgrade for admins or "Ask an admin to upgrade." for others.
  • Connect HubSpot opens a consent dialog first, with two choices, both unticked:
    • Mark contacts who came from an AI answer. Now, this creates the "Ansvisor" property group with 6 contact properties. Later, it fills them on contacts who came from an AI answer, and reads those contacts and their deals for the report.
    • Send pages to HubSpot as drafts.
    • "Continue to HubSpot" stays off until one is ticked. Then HubSpot's own sign-in opens in a popup. A blocked popup goes to HubSpot in the same tab, and the card finishes the sign-in when the person comes back.
  • Use the account another brand uses: a HubSpot account that a brand the person can see already uses. The same consent dialog opens first, because consent is per brand.
  • Connected, the card shows:
    • the account ("Hub ID 4412893") and the other brands on it;
    • "Property group "Ansvisor" ready in HubSpot, with 6 contact properties", or why HubSpot refused, with Try again;
    • a switch for each write;
    • "Allowed by {name} on {date}: …";
    • Change account and Disconnect.
  • Disconnect says three things: Ansvisor stops reading and writing at once; the Ansvisor properties and values stay in HubSpot; and which other brands still use the account.
  • Paused when the plan no longer includes HubSpot: nothing is read or written, the connection stays, and Disconnect still works.
  • Reconnect when HubSpot refuses the sign-in.
  • Not configured on a server without the env vars, which the card names.
  • Members see the state only.

How it works

  • Plan: a new feature key crm_integrations in web/src/config/plans.ts and server/src/config/plans.js, on Growth, Enterprise and self-host. The billing plan cards don't list HubSpot yet. They mirror the pricing page, so the line goes in once the owner adds HubSpot there.
  • Per brand, in the brand access pool (00470):
    • A HubSpot sign-in is an integration_accounts row (provider hubspot) that the brand uses through brand_integrations.
    • It reuses startBrandAccount, activateBrandAccount, useAccountForBrand and removeBrandAccount.
    • A sign-in that no brand uses any more is removed on Composio too.
    • No migration.
  • Consent is kept in brand_integrations.settings as { contacts, pages, by, at }. The settings also keep the HubSpot account (Hub ID, currency, time zone, address) and the property setup (version, AI source list version, or the refusal's code).
  • The Ansvisor property group (lib/hubspot/properties.js, lib/hubspot/setup.js):
    • group ansvisor with ansvisor_ai_source (a dropdown of the AI source list), ansvisor_ai_landing_page, ansvisor_ai_first_visit_at, ansvisor_ai_converted_at, ansvisor_brand, and the hidden ansvisor_brand_id;
    • made right after the sign-in, only with consent to mark contacts;
    • safe to run again: what exists is kept, and the dropdown only gains options;
    • an archived property with the same name, or a missing scope, shows on the card with Try again.
  • API, under /api/hubspot/brands/:brandId:
    • GET reads it, for any member who can access the brand.
    • POST /connect, /activate, /use and /setup, and PUT /settings, are for admins and managers who can access the brand. They need crm_integrations (requireFeature).
    • DELETE is open on every plan (COST_STOPPING).
    • The demo brand is refused (DEMO_GUARDED).
    • No Composio id leaves the server.
  • Composio:
  • HubSpot client (lib/hubspot/client.js), which every HubSpot call goes through:
    • it calls only api.hubapi.com and waits out 429s;
    • it never sends a write twice;
    • it names refusals (auth, scopes, forbidden, conflict…);
    • its logs carry only the path's shape and HubSpot's category, never the body, query or ids.
  • Refactor: assertSignInReach and reachableBrandIds move from routes/integrations.js to lib/brand-integration-reach.js, shared with the HubSpot routes. Google's behaviour is unchanged, and its tests pass.
  • integrations-section.tsx: one import and one new group at the end, so a line elsewhere (P-7a) or another group (Slack's "Team and alerts", feat(settings): post a brand's Daily Pulse to Slack from Settings › Integrations #2264) merges cleanly.
  • Merged with upstream/main (93184ca: Slack feat(slack): connect a Slack workspace per brand and pick its channel (API) #2259, MCP OAuth feat(mcp): give every tool all three hints, with the reason for each #2260–feat(mcp): OAuth discovery, client registration, token and revoke endpoints #2262), keeping both sides:
    • plan features: Slack's two and crm_integrations;
    • composio.js: main's proxyRequest, plus linkHubspot next to Slack's connection;
    • COST_STOPPING: both disconnects, so the test expects 12;
    • .env.example and the env docs: both entries.
  • Env: server/.env.example and docs/self-host/env-variables.mdx document COMPOSIO_HUBSPOT_AUTH_CONFIG_ID and the scopes.
  • Help: new help/settings/hubspot.md (plan: growth, approved: false).

Differences from the mockup

  • The account is named "Hub ID 4412893", because HubSpot's account details API gives no company name.
  • The contacts row has no "42 contacts marked" counts yet. Marking contacts is PR 2, which waits for the HubSpot spike. In this PR, connecting writes only the property group.
  • The pages consent is stored now. Send to CMS uses it from the blog-post PR, which comes before site and landing pages (owner, 2026-11-10).

Live test with Gökhan. There is no HubSpot portal here, so the HubSpot answers in the tests (server/src/lib/hubspot/__fixtures__) follow HubSpot's API reference, with ids replaced. Gökhan should:

  • create the Composio HubSpot auth config and set COMPOSIO_HUBSPOT_AUTH_CONFIG_ID on staging;
  • connect a HubSpot test portal and check that the property group appears;
  • replace the fixtures with recorded answers.

Related issue

Part of #2140

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. cd server && npx vitest run src/lib/hubspot src/routes/hubspot.test.js src/lib/composio.test.js src/middleware src/routes/write-roles.test.js src/routes/integrations-*.test.js
  2. cd web && yarn vitest run src/components/settings/hubspot-card.test.tsx src/components/settings/integrations-section.test.tsx src/lib/hubspot-client.test.ts
  3. Live, on staging, with COMPOSIO_API_KEY and COMPOSIO_HUBSPOT_AUTH_CONFIG_ID set and a Growth workspace:
    • Open Settings › Integrations › CRM › HubSpot. Connect HubSpot opens the consent dialog, and Continue to HubSpot stays off until a box is ticked.
    • Tick Mark contacts who came from an AI answer, continue, and sign in to a HubSpot test portal. The card says Connected, "Hub ID …", and "Property group "Ansvisor" ready in HubSpot…".
    • In HubSpot, Settings › Properties › Contact properties has the Ansvisor group with its properties. The brand id property is hidden.
    • Switch to a second brand: Use the account another brand uses lists the first brand's account, and the dialog asks for consent again.
    • Disconnect: the card goes back to Connect HubSpot, and the properties stay in HubSpot.
    • Self-host without the env vars: the card says Not configured and names both variables.
    • A Starter workspace sees the locked card.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/) — 0 errors; 9 warnings, all in files this PR doesn't touch
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR
  • Help article updated under help/ (or no user-visible change) — see help/README.md

Checks run (on 76767ac and ee41cbe):

  • Server: npm run format:check and npm run lint pass. npm test: 447 files, 6124 passed, 4 skipped.
  • Web: yarn format:check, yarn lint (0 errors) and yarn typecheck pass.
  • Web yarn test: 1,058 files, 11,527 passed, 1 skipped.
    • The two failures were in plan-switcher.test.tsx, which checks the plan cards against the pricing page. A "HubSpot integration" line caused them.
    • That line came out in ee41cbe. plan-switcher.test.tsx and choose-plan-dialog.test.tsx now pass (70 tests).
  • Web yarn build (CI's placeholder env) passes.

After the merge with upstream/main (93184ca): the stacked AI-sourced pipeline branch, which contains this one, re-ran everything:

  • server: 451 files, 6211 tests;
  • web: 1,065 files, 11,664 tests;
  • all passing, and the build passes too.

This branch merges cleanly into current main.


Generated by Claude Code

…nsvisor property group

HubSpot, part 1 of ansvisor#2140: Settings › Integrations gets a CRM group with a
HubSpot card for the active brand.

- Growth and above: a new plan feature, crm_integrations (Growth,
  Enterprise and self-host, owner 2026-11-09). A connection kept past a
  downgrade is paused; disconnecting is open on every plan.
- Per brand, in the brand access pool (00470): a HubSpot sign-in is an
  integration_accounts row (provider 'hubspot') the brand uses through
  brand_integrations, so a brand can use the HubSpot account another
  brand uses. No migration.
- Consent before any write: the person ticks what Ansvisor may do (mark
  AI-sourced contacts, send pages as drafts) before HubSpot's sign-in.
  It is kept per brand in brand_integrations.settings, with who allowed
  it and when, and can be turned off on the card.
- With consent to mark contacts, the "Ansvisor" property group and its six
  contact properties are made right after the sign-in (safe to run again;
  the AI source dropdown follows the AI source list).
- /api/hubspot/brands/:brandId: read, connect, activate, use, settings,
  setup (Try again) and disconnect, for admins and managers who can
  access the brand; the demo brand connects nothing.
- Composio: proxyRequest takes a method and a JSON body; HubSpot's
  sign-in has its own auth config (COMPOSIO_HUBSPOT_AUTH_CONFIG_ID).
  Without it the card says HubSpot isn't set up.
- The sign-in reach helpers move from routes/integrations.js to
  lib/brand-integration-reach.js, shared with the HubSpot routes.
- Help: settings/hubspot (approved: false).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
…l it names HubSpot

The Growth card's extras mirror www.ansvisor.com/pricing, which doesn't list
HubSpot yet (the owner adds it there first).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
…nect

# Conflicts:
#	docs/self-host/env-variables.mdx
#	server/.env.example
#	server/src/config/plans.js
#	server/src/lib/composio.js
#	server/src/lib/composio.test.js
#	server/src/middleware/subscription.js
#	server/src/middleware/subscription.test.js
#	web/src/config/plans.ts
@mintlify

mintlify Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 5f83659.

Approve preview

gkhngyk
gkhngyk previously approved these changes Nov 10, 2026

@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.

LGTM.

…nect

The Slack PRs (ansvisor#2263, ansvisor#2264) added a Team and alerts group where this
branch adds the CRM group: both groups are kept, Slack's first, with
both strings and both tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
cihan-gyk pushed a commit to cihan-gyk/ansvisor that referenced this pull request Nov 10, 2026
Brings in upstream/main through ansvisor#2265's branch (the Slack PRs).
schema.sql is rebuilt with 00510, 00515 and 00520.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
cihan-gyk pushed a commit to cihan-gyk/ansvisor that referenced this pull request Nov 10, 2026
Brings in upstream/main through ansvisor#2265's branch (the Slack PRs).
schema.sql is rebuilt with 00510, 00515 and 00522.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9

@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.

LGTM.

@gkhngyk
gkhngyk merged commit f947d77 into ansvisor:main Nov 10, 2026
13 checks passed
gkhngyk pushed a commit that referenced this pull request Nov 10, 2026
* feat(content): send pages to the HubSpot blog as draft posts

HubSpot, part 4 of #2140 (stacked on #2265): Send to CMS can put a page
on the brand's HubSpot blog as a draft post, blog posts first as the owner
asked (site and landing pages come after).

- 00522: content_draft_deliveries.target takes 'hubspot' (the blog's id in
  target_collection, the post's in external_id), and reserve_content_deliveries
  keeps a page from going to HubSpot twice at once. 00521 stays kept for
  marking contacts.
- On the HubSpot card, with "Send pages to HubSpot as drafts" allowed:
  "Blog posts go to", the HubSpot account's blogs (GET/PUT
  /api/hubspot/brands/:brandId/blogs and /blog). Without HubSpot's content
  scope it asks to connect HubSpot again.
- The target (NATIVE.hubspot): only with HubSpot set up, connected, the
  plan's crm_integrations, consent to send pages and a blog picked; each
  refusal named. A post's title, slug, meta title and description and
  featured image go as the post's own, the JSON-LD in its head. A page's
  next send updates its post's draft; one deleted in HubSpot gets a new one.
  Nothing is published.
- Published there since: read when the Library opens (/content-drafts/
  hubspot-status) and once a day, as Wix's are.
- Send to CMS, the bulk send and the Library know HubSpot; publish and take
  down stay Webflow, WordPress and Wix's.
- Help: content/send-to-cms, content/connect-a-cms and settings/hubspot.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9

* test(content): keep the HubSpot card test's client mocks apart from the pipeline branch's

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9

---------

Co-authored-by: Claude <[email protected]>
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.

3 participants