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(cms): give a Webflow item sent again a date when it has none (#1677)
Cihan555004996ea7
diff --git a/docs/guides/send-to-cms.mdx b/docs/guides/send-to-cms.mdxindex 10eab1af4..dba3b5e79 100644--- a/docs/guides/send-to-cms.mdx+++ b/docs/guides/send-to-cms.mdx@@ -26,8 +26,9 @@ Ansvisor never publishes on its own. When your workflow tells Ansvisor where the| Meta title | Plain text | Optional || Meta description | Plain text | Optional || JSON-LD (structured data) | Plain text | Optional |+ | Date (the day it's first sent) | Date/Time | Optional |- The page's title and slug always go to the item's **Name** and **Slug**. Ansvisor suggests fields from their names (`post-body`, `post-summary`, `seo-title`…); change them if they're wrong, and **Save**. A collection that requires a field Ansvisor doesn't fill can't be saved: **Save** names the field. Make it optional in Webflow first.+ The page's title and slug always go to the item's **Name** and **Slug**. Ansvisor suggests fields from their names (`post-body`, `post-summary`, `seo-title`…); change them if they're wrong, and **Save**. A collection that requires a field Ansvisor doesn't fill can't be saved: **Save** names the field. Make it optional in Webflow first. A page sent again keeps its item's date; an item that has none (sent before you mapped a date field) gets the day it's sent again.4. To use the JSON-LD field, add an **Embed** to the collection template that puts the field inside a `<script type="application/ld+json">` tag.A site token is one site's, so each brand connects its own. **Replace token** changes it (the collection and fields stay when it's the same site), and **Disconnect** removes it. If Webflow refuses the saved token, the card says so and asks for a new one.diff --git a/server/src/lib/cms/webflow-delivery.js b/server/src/lib/cms/webflow-delivery.jsindex d1a1faeaa..f3510dc83 100644--- a/server/src/lib/cms/webflow-delivery.js+++ b/server/src/lib/cms/webflow-delivery.js@@ -1,6 +1,6 @@import supabaseAdmin from '../../config/supabase.js';import { logger } from '../logger.js';-import { WebflowError, createItem, updateItem } from './webflow.js';+import { WebflowError, createItem, getItem, updateItem } from './webflow.js';import { fieldDataFor, toWebflowRichText, webflowSlug } from './webflow-items.js';/**@@ -33,6 +33,29 @@ async function lastItem(draftId, collectionId, deliveryId) {return data?.external_id ?? null;}+/**+ * Whether the item has no value in the date field the map gives: one sent+ * before a date was mapped, or before the brand made its date required in+ * Webflow, has none, and a send again gives it one (#1600). False when+ * there's no date field, or the item can't be read, or the read didn't see+ * its fields (every item has a slug): the update goes on without it, so an+ * answer in a shape we don't know never writes over the item's date.+ */+async function undated(account, collectionId, itemId, field) {+ if (!field) return false;+ try {+ const item = await getItem(account, collectionId, itemId);+ return (+ Boolean(item) &&+ Array.isArray(item.filledFields) &&+ item.filledFields.includes('slug') &&+ !item.filledFields.includes(field)+ );+ } catch {+ return false;+ }+}+/** The token the send was refused with: Settings asks for a new one. */async function markRefused(connection) {const { error } = await supabaseAdmin@@ -68,13 +91,18 @@ export async function sendToWebflow({ delivery, page, html, jsonLd, connection }let itemId = null;if (before) {try {- itemId = await updateItem(account, collectionId, before, fieldData);+ // An item sent again keeps its date; one that has none is given today's.+ const fields = (await undated(account, collectionId, before, fieldMap.date))+ ? fieldDataFor({ page, slug, body, jsonLd, sentAt: new Date() }, fieldMap)+ : fieldData;+ itemId = await updateItem(account, collectionId, before, fields);} catch (err) {if (!(err instanceof WebflowError && err.code === 'not_found')) throw err;}}const updated = Boolean(itemId);- // Only a new item is given the day it's sent: one sent again keeps its date.+ // A new item (or one gone from Webflow since) is given the day it's sent,+ // as one sent again with an empty date is above; any other keeps its date.itemId ??= await createItem(account,collectionId,diff --git a/server/src/lib/cms/webflow-delivery.test.js b/server/src/lib/cms/webflow-delivery.test.jsindex 635e17c77..a1f2b7764 100644--- a/server/src/lib/cms/webflow-delivery.test.js+++ b/server/src/lib/cms/webflow-delivery.test.js@@ -35,11 +35,12 @@ const logged = [];vi.mock('../logger.js', () => ({logger: { warn: (...args) => logged.push(JSON.stringify(args)) },}));-const webflow = { createItem: vi.fn(), updateItem: vi.fn() };+const webflow = { createItem: vi.fn(), updateItem: vi.fn(), getItem: vi.fn() };vi.mock('./webflow.js', async (importOriginal) => ({...(await importOriginal()),createItem: (...args) => webflow.createItem(...args),updateItem: (...args) => webflow.updateItem(...args),+ getItem: (...args) => webflow.getItem(...args),}));const { sendToWebflow } = await import('./webflow-delivery.js');@@ -76,6 +77,14 @@ beforeEach(() => {logged.length = 0;webflow.createItem.mockReset().mockResolvedValue('item-new');webflow.updateItem.mockReset().mockResolvedValue('item-old');+ // The item as sent before: dated.+ webflow.getItem.mockReset().mockResolvedValue({+ id: 'item-old',+ slug: 'cold-brew-at-home',+ live: false,+ lastPublished: null,+ filledFields: ['name', 'slug', 'date'],+ });});describe('sendToWebflow', () => {@@ -155,6 +164,59 @@ describe('sendToWebflow', () => {}});+ it('dates an item sent again that has no date, as one sent before the date was mapped (#1600)', async () => {+ vi.useFakeTimers({ now: new Date('2026-10-28T08:00:00Z') });+ try {+ const dated = { ...connection, field_map: { ...connection.field_map, date: 'date' } };+ const sendDated = () =>+ sendToWebflow({+ delivery: { id: 'd2345678-0000-0000-0000-000000000000' },+ page: { draftId: 'dr1', title: 'Cold brew at home', slug: 'cold-brew-at-home' },+ html: '<p>Smooth.</p>',+ jsonLd: [],+ connection: dated,+ });+ previous = 'item-old';+ webflow.getItem.mockResolvedValueOnce({+ id: 'item-old',+ slug: 'cold-brew-at-home',+ live: true,+ lastPublished: '2026-10-01T00:00:00Z',+ filledFields: ['name', 'slug', 'post-body'],+ });+ expect(await sendDated()).toMatchObject({ taken: true, updated: true });+ expect(webflow.getItem).toHaveBeenCalledWith(account, 'c1', 'item-old');+ expect(webflow.updateItem.mock.calls[0][3]).toHaveProperty(+ 'date',+ '2026-10-28T08:00:00.000Z',+ );++ // An item that can't be read is updated without a date, not refused.+ webflow.getItem.mockRejectedValueOnce(new WebflowError('failed', 'busy'));+ expect(await sendDated()).toMatchObject({ taken: true, updated: true });+ expect(webflow.updateItem.mock.calls[1][3]).not.toHaveProperty('date');++ // A read that didn't see the item's fields keeps its date.+ webflow.getItem.mockResolvedValueOnce({+ id: 'item-old',+ slug: null,+ live: true,+ lastPublished: null,+ filledFields: [],+ });+ expect(await sendDated()).toMatchObject({ taken: true, updated: true });+ expect(webflow.updateItem.mock.calls[2][3]).not.toHaveProperty('date');+ } finally {+ vi.useRealTimers();+ }+ });++ it('reads the item only when the map gives a date', async () => {+ previous = 'item-old';+ await send();+ expect(webflow.getItem).not.toHaveBeenCalled();+ });+it('gives Webflow a slug it takes, from the title when the page’s has nothing left', async () => {await send({ slug: 'soğuk.demleme' });expect(webflow.createItem.mock.calls[0][2].slug).toBe('soguk-demleme');diff --git a/server/src/lib/cms/webflow.js b/server/src/lib/cms/webflow.jsindex f8280f950..7376307dd 100644--- a/server/src/lib/cms/webflow.js+++ b/server/src/lib/cms/webflow.js@@ -172,7 +172,8 @@ export async function getCollection(account, collectionId) {/*** An item as Webflow has it: its slug, whether it's live (published, not a- * draft, not archived) and when it was last published. Null when it's gone.+ * draft, not archived), when it was last published, and which of its fields+ * hold a value (by slug). Null when it's gone.*/export async function getItem(account, collectionId, itemId) {let item;@@ -195,6 +196,7 @@ export async function getItem(account, collectionId, itemId) {slug: text(fields.slug, 256),live: Boolean(lastPublished) && item.isDraft !== true && item.isArchived !== true,lastPublished,+ filledFields: Object.keys(fields).filter((key) => fields[key] != null && fields[key] !== ''),};}diff --git a/server/src/lib/cms/webflow.test.js b/server/src/lib/cms/webflow.test.jsindex 51b13a12d..eb0bab254 100644--- a/server/src/lib/cms/webflow.test.js+++ b/server/src/lib/cms/webflow.test.js@@ -344,6 +344,7 @@ describe('where pages live', () => {slug: 'cold-brew',live: true,lastPublished: '2026-10-25T10:00:00Z',+ filledFields: ['slug', 'name'],});expect(executeWebflowTool).toHaveBeenLastCalledWith('WEBFLOW_GET_COLLECTION_ITEM', account, {collection_id: 'c1',