Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.
TypeScript aeoai-agentai-searchanswer-engine-optimizationbrand-monitoringchatgptclaudecopilotdockergeminigeogoogle-ai-overviewsgrokmcpnextjsopen-sourceperplexityseosupabasetypescript
fix(server): let a workspace whose plan has ended delete a brand (#1630)
Cihan22c05912f2fa
diff --git a/server/src/middleware/subscription.js b/server/src/middleware/subscription.jsindex 3960ec424..6202000c9 100644--- a/server/src/middleware/subscription.js+++ b/server/src/middleware/subscription.js@@ -14,6 +14,7 @@ import logger from '../lib/logger.js';* - BILLING_ROUTES: telling us why a plan is cancelled;* - COST_STOPPING: stopping work under way, and taking back the access to* an outside account (Google, a CMS, a bot log, a store) the person gave us;+ * - DATA_REMOVAL: deleting what the person gave us (a brand and its data);* - ONBOARDING_ROUTES, for an organization that never had a subscription:* setup suggests the brand's topics, prompts and competitors before the* plan step, and again when the person comes back from it, up to@@ -64,6 +65,15 @@ export const COST_STOPPING = [{ method: 'DELETE', path: /^\/catalog\/sources\/[^/]+\/?$/ },];+/**+ * Requests, under /api, that only delete what the person gave us: open+ * whatever the plan, so leaving needs no purchase (Ansvisor, 2026-10-27).+ */+export const DATA_REMOVAL = [+ // Deletes a brand and all its data (brands.js); admins only, as before.+ { method: 'DELETE', path: /^\/brands\/[^/]+\/?$/ },+];+/*** The writes onboarding asks of this API (web/src/lib/ai-brand-setup.ts):* open to an organization that never had a subscription, so setup works@@ -123,7 +133,7 @@ function matches(routes, { method, path }) {}function isOpen(req) {- return matches(BILLING_ROUTES, req) || matches(COST_STOPPING, req);+ return matches(BILLING_ROUTES, req) || matches(COST_STOPPING, req) || matches(DATA_REMOVAL, req);}/**diff --git a/server/src/middleware/subscription.test.js b/server/src/middleware/subscription.test.jsindex 95491efe4..13ea108aa 100644--- a/server/src/middleware/subscription.test.js+++ b/server/src/middleware/subscription.test.js@@ -34,6 +34,7 @@ const {ACTIVE_CACHE_MS,BILLING_ROUTES,COST_STOPPING,+ DATA_REMOVAL,MAX_ENTRIES,ONBOARDING_DAILY_CALLS,ONBOARDING_LIMIT_REACHED,@@ -187,8 +188,6 @@ describe('requireActiveSubscription', () => {['PUT', '/catalog/sources/s1/credentials'],['DELETE', '/catalog/sources/s1/extra'],['POST', '/catalog/upload'],- // A brand is deleted only on a plan (product decision, 2026-10-27).- ['DELETE', '/brands/b1'],]) {const { res, next } = await run({ method, path });expect(next, `${method} ${path}`).not.toHaveBeenCalled();@@ -198,6 +197,28 @@ describe('requireActiveSubscription', () => {expect(COST_STOPPING).toHaveLength(6);});+ it('lets an organization off a plan delete a brand, and nothing near it', async () => {+ org = ended;+ // Leaving needs no purchase (product decision, 2026-10-27).+ for (const path of ['/brands/9b2c1e40-0000-4000-8000-000000000004', '/brands/b1/']) {+ const { res, next } = await run({ method: 'DELETE', path });+ expect(next, path).toHaveBeenCalledOnce();+ expect(res.status).not.toHaveBeenCalled();+ }+ for (const [method, path] of [+ ['POST', '/brands'],+ ['PUT', '/brands/b1'],+ ['PATCH', '/brands/b1'],+ ['DELETE', '/brands/b1/domains/d1'],+ ['DELETE', '/brands'],+ ]) {+ const { res, next } = await run({ method, path });+ expect(next, `${method} ${path}`).not.toHaveBeenCalled();+ expect(res.status).toHaveBeenCalledWith(402);+ }+ expect(DATA_REMOVAL).toHaveLength(1);+ });+it("opens onboarding's routes, and only them, to an organization that never subscribed", async () => {// Setting up, before the plan step; and back from it (onboarding marked// done, still no subscription): the flag is not read.