The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Convert workflow rich text to BlockNote in the workflow record actions (#27721)
Charles Bochet9070979232c4
diff --git a/packages/twenty-server/src/engine/core-modules/record-transformer/utils/__tests__/transform-rich-text.util.spec.ts b/packages/twenty-server/src/engine/core-modules/record-transformer/utils/__tests__/transform-rich-text.util.spec.tsindex 0caf5630b9f..df46d2f27c3 100644--- a/packages/twenty-server/src/engine/core-modules/record-transformer/utils/__tests__/transform-rich-text.util.spec.ts+++ b/packages/twenty-server/src/engine/core-modules/record-transformer/utils/__tests__/transform-rich-text.util.spec.ts@@ -4,16 +4,6 @@ const BLOCKNOTE_VALUE = JSON.stringify([{ id: '1', type: 'paragraph', content: [{ type: 'text', text: 'Hello' }] },]);-const TIPTAP_VALUE = JSON.stringify({- type: 'doc',- content: [- {- type: 'paragraph',- content: [{ type: 'text', text: 'Hello', marks: [{ type: 'bold' }] }],- },- ],-});-const blockTypesOf = (blocknote: string | null | undefined) =>JSON.parse(blocknote ?? '[]').map((block: { type: string }) => block.type);@@ -47,14 +37,4 @@ describe('transformRichTextValue', () => {expect(result).toEqual({ markdown: null, blocknote: null });});-- it('should rebuild blocknote from tiptap content', async () => {- const result = await transformRichTextValue({ blocknote: TIPTAP_VALUE });-- expect(result.markdown).toBe('**Hello**');- expect(JSON.parse(result.blocknote ?? '[]')[0]).toMatchObject({- type: 'paragraph',- content: [{ type: 'text', text: 'Hello', styles: { bold: true } }],- });- });});diff --git a/packages/twenty-server/src/engine/core-modules/record-transformer/utils/transform-rich-text.util.ts b/packages/twenty-server/src/engine/core-modules/record-transformer/utils/transform-rich-text.util.tsindex 417242de973..3bf8eb052b2 100644--- a/packages/twenty-server/src/engine/core-modules/record-transformer/utils/transform-rich-text.util.ts+++ b/packages/twenty-server/src/engine/core-modules/record-transformer/utils/transform-rich-text.util.ts@@ -3,7 +3,6 @@ import {type RichTextMetadata,richTextValueSchema,} from 'twenty-shared/types';-import { convertTipTapBlocksToMarkdown, isDefined } from 'twenty-shared/utils';import type { ServerBlockNoteEditor } from '@blocknote/server-util';@@ -62,17 +61,6 @@ export const transformRichTextValue = async (? richTextValueSchema.parse(richTextValue): richTextValue;- const tipTapMarkdown = isDefined(parsedValue.blocknote)- ? convertTipTapBlocksToMarkdown(parsedValue.blocknote)- : undefined;-- if (isDefined(tipTapMarkdown)) {- return {- markdown: parsedValue.markdown || tipTapMarkdown,- blocknote: convertMarkdownToBlocknote(tipTapMarkdown),- };- }-return {markdown:parsedValue.markdown ||diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/utils/__tests__/convert-step-object-record-tiptap-to-markdown.util.spec.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/__tests__/convert-step-object-record-tiptap-to-markdown.util.spec.tsnew file mode 100644index 00000000000..74a7cef6034--- /dev/null+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/__tests__/convert-step-object-record-tiptap-to-markdown.util.spec.ts@@ -0,0 +1,133 @@+import { FieldMetadataType } from 'twenty-shared/types';++import { type FlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/types/flat-entity-maps.type';+import { getFlatFieldMetadataMock } from 'src/engine/metadata-modules/flat-field-metadata/__mocks__/get-flat-field-metadata.mock';+import { type FlatFieldMetadata } from 'src/engine/metadata-modules/flat-field-metadata/types/flat-field-metadata.type';+import { getFlatObjectMetadataMock } from 'src/engine/metadata-modules/flat-object-metadata/__mocks__/get-flat-object-metadata.mock';+import { convertStepObjectRecordTipTapToMarkdown } from 'src/modules/workflow/workflow-executor/utils/convert-step-object-record-tiptap-to-markdown.util';++const bodyField = getFlatFieldMetadataMock({+ id: 'body-field',+ universalIdentifier: 'body-universal-id',+ objectMetadataId: 'note-object',+ name: 'body',+ type: FieldMetadataType.RICH_TEXT,+});++const titleField = getFlatFieldMetadataMock({+ id: 'title-field',+ universalIdentifier: 'title-universal-id',+ objectMetadataId: 'note-object',+ name: 'title',+ type: FieldMetadataType.TEXT,+});++const flatFieldMetadataMaps: FlatEntityMaps<FlatFieldMetadata> = {+ byUniversalIdentifier: {+ [bodyField.universalIdentifier]: bodyField,+ [titleField.universalIdentifier]: titleField,+ },+ universalIdentifierById: {+ [bodyField.id]: bodyField.universalIdentifier,+ [titleField.id]: titleField.universalIdentifier,+ },+ universalIdentifiersByApplicationId: {},+};++const objectMetadataInfo = {+ flatObjectMetadata: getFlatObjectMetadataMock({+ id: 'note-object',+ universalIdentifier: 'note-universal-id',+ nameSingular: 'note',+ namePlural: 'notes',+ fieldIds: [bodyField.id, titleField.id],+ }),+ flatFieldMetadataMaps,+};++const paragraph = (content: unknown[]) =>+ JSON.stringify([{ type: 'paragraph', content }]);++describe('convertStepObjectRecordTipTapToMarkdown', () => {+ it('converts a TipTap body into markdown, keeping its variables', () => {+ const tipTapBody = paragraph([+ { type: 'text', text: 'Amount', marks: [{ type: 'bold' }] },+ { type: 'text', text: ': ' },+ { type: 'variableTag', attrs: { variable: '{{trigger.body.amount}}' } },+ ]);++ const converted = convertStepObjectRecordTipTapToMarkdown(+ { body: { blocknote: tipTapBody, markdown: null } },+ objectMetadataInfo,+ );++ expect(converted.body).toEqual({+ markdown: '**Amount**: {{trigger.body.amount}}',+ });+ });++ it('keeps a variable used as a link destination', () => {+ const tipTapBody = paragraph([+ {+ type: 'text',+ text: 'Website',+ marks: [{ type: 'link', attrs: { href: '{{trigger.url}}' } }],+ },+ ]);++ const converted = convertStepObjectRecordTipTapToMarkdown(+ { body: { blocknote: tipTapBody, markdown: null } },+ objectMetadataInfo,+ );++ expect(converted.body).toEqual({ markdown: '[Website]({{trigger.url}})' });+ });++ it.each([+ {+ name: 'a markdown only value',+ value: { blocknote: null, markdown: '{{trigger.body.amount}}' },+ },+ {+ name: 'a blocknote variable',+ value: {+ blocknote: '{{codeStep.report.blocknote}}',+ markdown: '{{codeStep.report.markdown}}',+ },+ },+ {+ name: 'a BlockNote body',+ value: {+ blocknote: JSON.stringify([+ {+ id: 'b1',+ type: 'paragraph',+ props: {},+ children: [],+ content: [{ type: 'text', text: 'Bold', styles: { bold: true } }],+ },+ ]),+ markdown: null,+ },+ },+ { name: 'a value that is not a rich text object', value: 'legacy' },+ ])('leaves $name untouched', ({ value }) => {+ const converted = convertStepObjectRecordTipTapToMarkdown(+ { body: value },+ objectMetadataInfo,+ );++ expect(converted.body).toEqual(value);+ });++ it('does not touch fields that are not rich text', () => {+ const tipTapBody = paragraph([{ type: 'text', text: 'Hello' }]);++ const converted = convertStepObjectRecordTipTapToMarkdown(+ { title: tipTapBody },+ objectMetadataInfo,+ );++ expect(converted.title).toBe(tipTapBody);+ });+});diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/utils/__tests__/resolve-rich-text-fields-in-record.util.spec.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/__tests__/resolve-rich-text-markdown-variables.util.spec.tssimilarity index 54%rename from packages/twenty-server/src/modules/workflow/workflow-executor/utils/__tests__/resolve-rich-text-fields-in-record.util.spec.tsrename to packages/twenty-server/src/modules/workflow/workflow-executor/utils/__tests__/resolve-rich-text-markdown-variables.util.spec.tsindex 50ff4f867b1..8786a5c62da 100644--- a/packages/twenty-server/src/modules/workflow/workflow-executor/utils/__tests__/resolve-rich-text-fields-in-record.util.spec.ts+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/__tests__/resolve-rich-text-markdown-variables.util.spec.ts@@ -4,7 +4,7 @@ import { type FlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/typimport { getFlatFieldMetadataMock } from 'src/engine/metadata-modules/flat-field-metadata/__mocks__/get-flat-field-metadata.mock';import { type FlatFieldMetadata } from 'src/engine/metadata-modules/flat-field-metadata/types/flat-field-metadata.type';import { getFlatObjectMetadataMock } from 'src/engine/metadata-modules/flat-object-metadata/__mocks__/get-flat-object-metadata.mock';-import { resolveRichTextFieldsInRecord } from 'src/modules/workflow/workflow-executor/utils/resolve-rich-text-fields-in-record.util';+import { resolveRichTextMarkdownVariables } from 'src/modules/workflow/workflow-executor/utils/resolve-rich-text-markdown-variables.util';const bodyField = getFlatFieldMetadataMock({id: 'body-field',@@ -49,65 +49,31 @@ const context = {trigger: { body: { amount: 42, currency: 'EUR', meta: { source: 'form' } } },};-describe('resolveRichTextFieldsInRecord', () => {- it('keeps a markdown that is exactly one variable a string', () => {- const resolved = resolveRichTextFieldsInRecord(- { body: { markdown: '{{trigger.body.amount}}', blocknote: null } },- objectMetadataInfo,- context,- );-- expect(resolved.body).toEqual({ markdown: '42', blocknote: null });- });-- it('interpolates variables inside a markdown', () => {- const resolved = resolveRichTextFieldsInRecord(- {- body: {- markdown:- 'Latest donation: {{trigger.body.amount}} {{trigger.body.currency}}',- blocknote: null,- },- },- objectMetadataInfo,- context,- );-- expect(resolved.body).toEqual({- markdown: 'Latest donation: 42 EUR',- blocknote: null,- });- });-- it('serializes an object resolved from a whole-string variable', () => {- const resolved = resolveRichTextFieldsInRecord(- { body: { markdown: '{{trigger.body.meta}}', blocknote: null } },+describe('resolveRichTextMarkdownVariables', () => {+ it.each([+ { markdown: '{{trigger.body.amount}}', expected: '42' },+ {+ markdown:+ 'Latest donation: {{trigger.body.amount}} {{trigger.body.currency}}',+ expected: 'Latest donation: 42 EUR',+ },+ { markdown: '{{trigger.body.meta}}', expected: '{"source":"form"}' },+ ])('resolves $markdown into a string', ({ markdown, expected }) => {+ const resolved = resolveRichTextMarkdownVariables(+ { body: { markdown, blocknote: '{{codeStep.report.blocknote}}' } },objectMetadataInfo,context,);expect(resolved.body).toEqual({- markdown: '{"source":"form"}',- blocknote: null,+ markdown: expected,+ blocknote: '{{codeStep.report.blocknote}}',});});- it('leaves a value that is not a rich text object untouched', () => {- const resolved = resolveRichTextFieldsInRecord(- { body: 'legacy bare string {{trigger.body.amount}}', title: 'x' },- objectMetadataInfo,- context,- );-- expect(resolved.body).toBe('legacy bare string {{trigger.body.amount}}');- });-it('does not touch fields that are not rich text', () => {- const resolved = resolveRichTextFieldsInRecord(- {- title: '{{trigger.body.amount}}',- body: { markdown: 'a', blocknote: null },- },+ const resolved = resolveRichTextMarkdownVariables(+ { title: '{{trigger.body.amount}}' },objectMetadataInfo,context,);diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/utils/convert-step-object-record-tiptap-to-markdown.util.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/convert-step-object-record-tiptap-to-markdown.util.tsnew file mode 100644index 00000000000..834c71c04b5--- /dev/null+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/convert-step-object-record-tiptap-to-markdown.util.ts@@ -0,0 +1,41 @@+import { richTextValueSchema } from 'twenty-shared/types';+import { convertTipTapBlocksToMarkdown, isDefined } from 'twenty-shared/utils';++import { type ObjectMetadataInfo } from 'src/modules/workflow/common/workspace-services/workflow-common.workspace-service';+import { findRichTextFieldNames } from 'src/modules/workflow/workflow-executor/utils/find-rich-text-field-names.util';++// The step editor is TipTap but saves its JSON under a key named blocknote+const workflowStepTipTapValueSchema = richTextValueSchema;++export const convertStepObjectRecordTipTapToMarkdown = (+ stepObjectRecord: Record<string, unknown>,+ objectMetadataInfo: Pick<+ ObjectMetadataInfo,+ 'flatObjectMetadata' | 'flatFieldMetadataMaps'+ >,+): Record<string, unknown> => {+ const objectRecord = { ...stepObjectRecord };++ for (const fieldName of findRichTextFieldNames(objectMetadataInfo)) {+ const parsedStepValue = workflowStepTipTapValueSchema.safeParse(+ stepObjectRecord[fieldName],+ );++ const tipTapJson = parsedStepValue.success+ ? parsedStepValue.data.blocknote+ : undefined;+ const tipTapMarkdown = isDefined(tipTapJson)+ ? convertTipTapBlocksToMarkdown(tipTapJson)+ : undefined;++ // TODO: steps built through the API can hold markdown only, BlockNote or a variable instead of TipTap.+ // Migrate them to TipTap so they go through the same conversion, then remove this check.+ if (!isDefined(tipTapMarkdown)) {+ continue;+ }++ objectRecord[fieldName] = { markdown: tipTapMarkdown };+ }++ return objectRecord;+};diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/utils/resolve-rich-text-fields-in-record.util.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/resolve-rich-text-fields-in-record.util.tsdeleted file mode 100644index 238bf8f1d58..00000000000--- a/packages/twenty-server/src/modules/workflow/workflow-executor/utils/resolve-rich-text-fields-in-record.util.ts+++ /dev/null@@ -1,45 +0,0 @@-import { isString } from '@sniptt/guards';-import { richTextValueSchema } from 'twenty-shared/types';-import {- resolveRichTextVariables,- resolveStringTemplate,-} from 'twenty-shared/utils';--import { type ObjectMetadataInfo } from 'src/modules/workflow/common/workspace-services/workflow-common.workspace-service';-import { findRichTextFieldNames } from 'src/modules/workflow/workflow-executor/utils/find-rich-text-field-names.util';--export const resolveRichTextFieldsInRecord = (- objectRecord: Record<string, unknown>,- objectMetadataInfo: Pick<- ObjectMetadataInfo,- 'flatObjectMetadata' | 'flatFieldMetadataMaps'- >,- context: Record<string, unknown>,-): Record<string, unknown> => {- const richTextFieldNames = findRichTextFieldNames(objectMetadataInfo);-- const resolvedRecord = { ...objectRecord };-- for (const fieldName of richTextFieldNames) {- const parsedRichTextValue = richTextValueSchema.safeParse(- resolvedRecord[fieldName],- );-- if (!parsedRichTextValue.success) {- continue;- }-- const { blocknote, markdown } = parsedRichTextValue.data;-- resolvedRecord[fieldName] = {- blocknote: isString(blocknote)- ? resolveRichTextVariables(blocknote, context)- : blocknote,- markdown: isString(markdown)- ? resolveStringTemplate(markdown, context)- : markdown,- };- }-- return resolvedRecord;-};diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/utils/resolve-rich-text-markdown-variables.util.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/resolve-rich-text-markdown-variables.util.tsnew file mode 100644index 00000000000..3cb6c807980--- /dev/null+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/resolve-rich-text-markdown-variables.util.ts@@ -0,0 +1,32 @@+import { isString } from '@sniptt/guards';+import { isPlainObject, resolveStringTemplate } from 'twenty-shared/utils';++import { type ObjectMetadataInfo } from 'src/modules/workflow/common/workspace-services/workflow-common.workspace-service';+import { findRichTextFieldNames } from 'src/modules/workflow/workflow-executor/utils/find-rich-text-field-names.util';++// resolveInput would turn a markdown that is exactly one variable into a number or an object+export const resolveRichTextMarkdownVariables = (+ objectRecord: Record<string, unknown>,+ objectMetadataInfo: Pick<+ ObjectMetadataInfo,+ 'flatObjectMetadata' | 'flatFieldMetadataMaps'+ >,+ context: Record<string, unknown>,+): Record<string, unknown> => {+ const resolvedRecord = { ...objectRecord };++ for (const fieldName of findRichTextFieldNames(objectMetadataInfo)) {+ const richTextValue = resolvedRecord[fieldName];++ if (!isPlainObject(richTextValue) || !isString(richTextValue.markdown)) {+ continue;+ }++ resolvedRecord[fieldName] = {+ ...richTextValue,+ markdown: resolveStringTemplate(richTextValue.markdown, context),+ };+ }++ return resolvedRecord;+};diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/record-crud/create-record.workflow-action.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/record-crud/create-record.workflow-action.tsindex 0c4184530fa..4ae31e21134 100644--- a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/record-crud/create-record.workflow-action.ts+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/record-crud/create-record.workflow-action.ts@@ -13,7 +13,8 @@ import { buildWorkflowActorMetadata } from 'src/modules/workflow/workflow-executimport { filterValidFieldsInRecord } from 'src/modules/workflow/workflow-executor/utils/filter-valid-fields-in-record.util';import { formatWorkflowRecordRelationFields } from 'src/modules/workflow/workflow-executor/utils/format-workflow-record-relation-fields.util';import { findStepOrThrow } from 'src/modules/workflow/workflow-executor/utils/find-step-or-throw.util';-import { resolveRichTextFieldsInRecord } from 'src/modules/workflow/workflow-executor/utils/resolve-rich-text-fields-in-record.util';+import { convertStepObjectRecordTipTapToMarkdown } from 'src/modules/workflow/workflow-executor/utils/convert-step-object-record-tiptap-to-markdown.util';+import { resolveRichTextMarkdownVariables } from 'src/modules/workflow/workflow-executor/utils/resolve-rich-text-markdown-variables.util';import { type WorkflowCreateRecordActionInput } from 'src/modules/workflow/workflow-executor/workflow-actions/record-crud/types/workflow-record-crud-action-input.type';@Injectable()@@ -45,17 +46,20 @@ export class CreateRecordWorkflowAction implements WorkflowAction {workspaceId,);- const inputWithResolvedRichText = {+ const inputWithRichText = {...rawInput,- objectRecord: resolveRichTextFieldsInRecord(- rawInput.objectRecord,+ objectRecord: resolveRichTextMarkdownVariables(+ convertStepObjectRecordTipTapToMarkdown(+ rawInput.objectRecord,+ objectMetadataInfo,+ ),objectMetadataInfo,context,),};const workflowActionInput = resolveInput(- inputWithResolvedRichText,+ inputWithRichText,context,) as WorkflowCreateRecordActionInput;diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/record-crud/update-record.workflow-action.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/record-crud/update-record.workflow-action.tsindex 741c726488b..f2661f8cbd9 100644--- a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/record-crud/update-record.workflow-action.ts+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/record-crud/update-record.workflow-action.ts@@ -17,7 +17,8 @@ import { buildWorkflowActorMetadata } from 'src/modules/workflow/workflow-executimport { filterValidFieldsInRecord } from 'src/modules/workflow/workflow-executor/utils/filter-valid-fields-in-record.util';import { formatWorkflowRecordRelationFields } from 'src/modules/workflow/workflow-executor/utils/format-workflow-record-relation-fields.util';import { findStepOrThrow } from 'src/modules/workflow/workflow-executor/utils/find-step-or-throw.util';-import { resolveRichTextFieldsInRecord } from 'src/modules/workflow/workflow-executor/utils/resolve-rich-text-fields-in-record.util';+import { convertStepObjectRecordTipTapToMarkdown } from 'src/modules/workflow/workflow-executor/utils/convert-step-object-record-tiptap-to-markdown.util';+import { resolveRichTextMarkdownVariables } from 'src/modules/workflow/workflow-executor/utils/resolve-rich-text-markdown-variables.util';import { isWorkflowUpdateRecordAction } from 'src/modules/workflow/workflow-executor/workflow-actions/record-crud/guards/is-workflow-update-record-action.guard';import { type WorkflowUpdateRecordActionInput } from 'src/modules/workflow/workflow-executor/workflow-actions/record-crud/types/workflow-record-crud-action-input.type';@@ -57,17 +58,20 @@ export class UpdateRecordWorkflowAction implements WorkflowAction {workspaceId,);- const inputWithResolvedRichText = {+ const inputWithRichText = {...rawInput,- objectRecord: resolveRichTextFieldsInRecord(- rawInput.objectRecord,+ objectRecord: resolveRichTextMarkdownVariables(+ convertStepObjectRecordTipTapToMarkdown(+ rawInput.objectRecord,+ objectMetadataInfo,+ ),objectMetadataInfo,context,),};const workflowActionInput = resolveInput(- inputWithResolvedRichText,+ inputWithRichText,context,) as WorkflowUpdateRecordActionInput;diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/record-crud/upsert-record.workflow-action.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/record-crud/upsert-record.workflow-action.tsindex 54ed746e937..e5c3f8c670b 100644--- a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/record-crud/upsert-record.workflow-action.ts+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/record-crud/upsert-record.workflow-action.ts@@ -16,7 +16,8 @@ import { type WorkflowActionOutput } from 'src/modules/workflow/workflow-executoimport { filterValidFieldsInRecord } from 'src/modules/workflow/workflow-executor/utils/filter-valid-fields-in-record.util';import { formatWorkflowRecordRelationFields } from 'src/modules/workflow/workflow-executor/utils/format-workflow-record-relation-fields.util';import { findStepOrThrow } from 'src/modules/workflow/workflow-executor/utils/find-step-or-throw.util';-import { resolveRichTextFieldsInRecord } from 'src/modules/workflow/workflow-executor/utils/resolve-rich-text-fields-in-record.util';+import { convertStepObjectRecordTipTapToMarkdown } from 'src/modules/workflow/workflow-executor/utils/convert-step-object-record-tiptap-to-markdown.util';+import { resolveRichTextMarkdownVariables } from 'src/modules/workflow/workflow-executor/utils/resolve-rich-text-markdown-variables.util';import { isWorkflowUpsertRecordAction } from 'src/modules/workflow/workflow-executor/workflow-actions/record-crud/guards/is-workflow-upsert-record-action.guard';import { type WorkflowUpsertRecordActionInput } from 'src/modules/workflow/workflow-executor/workflow-actions/record-crud/types/workflow-record-crud-action-input.type';@@ -56,17 +57,20 @@ export class UpsertRecordWorkflowAction implements WorkflowAction {workspaceId,);- const inputWithResolvedRichText = {+ const inputWithRichText = {...rawInput,- objectRecord: resolveRichTextFieldsInRecord(- rawInput.objectRecord,+ objectRecord: resolveRichTextMarkdownVariables(+ convertStepObjectRecordTipTapToMarkdown(+ rawInput.objectRecord,+ objectMetadataInfo,+ ),objectMetadataInfo,context,),};const workflowActionInput = resolveInput(- inputWithResolvedRichText,+ inputWithRichText,context,) as WorkflowUpsertRecordActionInput;diff --git a/packages/twenty-server/test/integration/constants/widget-configuration-test-data.constants.ts b/packages/twenty-server/test/integration/constants/widget-configuration-test-data.constants.tsindex 267b4150fa2..d3a2d4b6a0b 100644--- a/packages/twenty-server/test/integration/constants/widget-configuration-test-data.constants.ts+++ b/packages/twenty-server/test/integration/constants/widget-configuration-test-data.constants.ts@@ -47,16 +47,6 @@ export const TEST_STANDALONE_RICH_TEXT_CONFIG_MINIMAL: StandaloneRichTextConfigu},};-export const TEST_STANDALONE_RICH_TEXT_CONFIG_TIPTAP_BODY: StandaloneRichTextConfigurationDTO =- {- configurationType: WidgetConfigurationType.STANDALONE_RICH_TEXT,- body: {- blocknote:- '{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"Checklist:"}]},{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"call the client"}]}]}]}]}',- markdown: null,- },- };-export const INVALID_STANDALONE_RICH_TEXT_CONFIG_MISSING_BODY = {};export const INVALID_STANDALONE_RICH_TEXT_CONFIG_BODY_WRONG_TYPE = {diff --git a/packages/twenty-server/test/integration/metadata/suites/page-layout-widget/successful-page-layout-widget-creation.integration-spec.ts b/packages/twenty-server/test/integration/metadata/suites/page-layout-widget/successful-page-layout-widget-creation.integration-spec.tsindex f1d46eba101..8d9ee0acb43 100644--- a/packages/twenty-server/test/integration/metadata/suites/page-layout-widget/successful-page-layout-widget-creation.integration-spec.ts+++ b/packages/twenty-server/test/integration/metadata/suites/page-layout-widget/successful-page-layout-widget-creation.integration-spec.ts@@ -2,7 +2,6 @@ import {TEST_IFRAME_CONFIG,TEST_STANDALONE_RICH_TEXT_CONFIG,TEST_STANDALONE_RICH_TEXT_CONFIG_MINIMAL,- TEST_STANDALONE_RICH_TEXT_CONFIG_TIPTAP_BODY,} from 'test/integration/constants/widget-configuration-test-data.constants';import { createOnePageLayoutTab } from 'test/integration/metadata/suites/page-layout-tab/utils/create-one-page-layout-tab.util';import { destroyOnePageLayoutTab } from 'test/integration/metadata/suites/page-layout-tab/utils/destroy-one-page-layout-tab.util';@@ -27,7 +26,6 @@ import { AxisNameDisplay } from 'src/engine/metadata-modules/page-layout-widget/import { BarChartLayout } from 'src/engine/metadata-modules/page-layout-widget/enums/bar-chart-layout.enum';import { ChartNumberFormat } from 'src/engine/metadata-modules/page-layout-widget/enums/chart-number-format.enum';import { GraphOrderBy } from 'src/engine/metadata-modules/page-layout-widget/enums/graph-order-by.enum';-import { type StandaloneRichTextConfigurationDTO } from 'src/engine/metadata-modules/page-layout-widget/dtos/standalone-rich-text-configuration.dto';import { WidgetConfigurationType } from 'src/engine/metadata-modules/page-layout-widget/enums/widget-configuration-type.type';import { type AllPageLayoutWidgetConfiguration } from 'src/engine/metadata-modules/page-layout-widget/types/all-page-layout-widget-configuration.type';@@ -366,33 +364,6 @@ describe('Page layout widget creation should succeed', () => {},);- it('should store a tiptap rich text body as blocknote blocks', async () => {- const { data } = await createOnePageLayoutWidget({- expectToFail: false,- input: {- title: 'Rich Text Widget TipTap',- type: WidgetType.STANDALONE_RICH_TEXT,- configuration: TEST_STANDALONE_RICH_TEXT_CONFIG_TIPTAP_BODY,- position: DEFAULT_GRID_POSITION,- pageLayoutTabId: testSetup.pageLayoutTabId,- },- });-- createdPageLayoutWidgetId = data?.createPageLayoutWidget?.id;-- const { body } = data.createPageLayoutWidget- .configuration as StandaloneRichTextConfigurationDTO;-- expect(body.markdown).toBe('Checklist:\n\n- call the client');-- const storedBlocks = JSON.parse(body.blocknote ?? '[]');-- expect(storedBlocks.map((block: { type: string }) => block.type)).toEqual([- 'paragraph',- 'bulletListItem',- ]);- });-it.each(eachTestingContextFilter(graphTestCases))('should $title',async ({ context: { widgetTitle, buildConfiguration } }) => {diff --git a/packages/twenty-shared/src/utils/__tests__/rich-text-variable-resolver.test.ts b/packages/twenty-shared/src/utils/__tests__/rich-text-variable-resolver.test.tsdeleted file mode 100644index 241fc90695a..00000000000--- a/packages/twenty-shared/src/utils/__tests__/rich-text-variable-resolver.test.ts+++ /dev/null@@ -1,236 +0,0 @@-import { resolveRichTextVariables } from '../rich-text-variable-resolver';--describe('resolveRichTextVariables', () => {- const context = {- step1: {- message: 'Hello World',- name: 'John',- },- user: {- email: '[email protected]',- },- };-- it('should resolve a single variableTag node', () => {- const input =- '[{"type":"paragraph","content":[{"type":"variableTag","attrs":{"variable":"{{step1.message}}"}}]}]';-- const result = resolveRichTextVariables(input, context);-- expect(result).toBe(- '[{"type":"paragraph","content":[{"type":"text","text":"Hello World"}]}]',- );- });-- it('should resolve variableTag nodes mixed with text', () => {- const input =- '[{"type":"paragraph","content":[{"type":"text","text":"Message: "},{"type":"variableTag","attrs":{"variable":"{{step1.message}}"}},{"type":"text","text":" from user"}]}]';-- const result = resolveRichTextVariables(input, context);-- expect(result).toBe(- '[{"type":"paragraph","content":[{"type":"text","text":"Message: "},{"type":"text","text":"Hello World"},{"type":"text","text":" from user"}]}]',- );- });-- it('should resolve multiple variableTag nodes', () => {- const input =- '[{"type":"paragraph","content":[{"type":"variableTag","attrs":{"variable":"{{step1.name}}"}},{"type":"text","text":" - "},{"type":"variableTag","attrs":{"variable":"{{user.email}}"}}]}]';-- const result = resolveRichTextVariables(input, context);-- expect(result).toBe(- '[{"type":"paragraph","content":[{"type":"text","text":"John"},{"type":"text","text":" - "},{"type":"text","text":"[email protected]"}]}]',- );- });-- it('should handle undefined variables by replacing with empty string', () => {- const input =- '[{"type":"paragraph","content":[{"type":"variableTag","attrs":{"variable":"{{nonexistent.field}}"}}]}]';-- const result = resolveRichTextVariables(input, context);-- expect(result).toBe(- '[{"type":"paragraph","content":[{"type":"text","text":""}]}]',- );- });-- it('should escape special characters in resolved values', () => {- const contextWithSpecialChars = {- step1: {- message: 'Hello "World" with \\ backslash',- },- };-- const input =- '[{"type":"paragraph","content":[{"type":"variableTag","attrs":{"variable":"{{step1.message}}"}}]}]';-- const result = resolveRichTextVariables(input, contextWithSpecialChars);-- expect(result).toBe(- '[{"type":"paragraph","content":[{"type":"text","text":"Hello \\"World\\" with \\\\ backslash"}]}]',- );- });-- it('should not modify strings without variableTag nodes', () => {- const input =- '[{"type":"paragraph","content":[{"type":"text","text":"Plain text content"}]}]';-- const result = resolveRichTextVariables(input, context);-- expect(result).toBe(input);- });-- it('should handle doc type structure', () => {- const input =- '{"type":"doc","content":[{"type":"paragraph","content":[{"type":"variableTag","attrs":{"variable":"{{step1.message}}"}}]}]}';-- const result = resolveRichTextVariables(input, context);-- expect(result).toBe(- '{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"Hello World"}]}]}',- );- });-- it('should handle null context values by replacing with empty string', () => {- const contextWithNull = {- step1: {- value: null,- },- };-- const input =- '[{"type":"paragraph","content":[{"type":"variableTag","attrs":{"variable":"{{step1.value}}"}}]}]';-- const result = resolveRichTextVariables(input, contextWithNull);-- expect(result).toBe(- '[{"type":"paragraph","content":[{"type":"text","text":""}]}]',- );- });-- it('should handle numeric values', () => {- const contextWithNumber = {- step1: {- count: 42,- },- };-- const input =- '[{"type":"paragraph","content":[{"type":"variableTag","attrs":{"variable":"{{step1.count}}"}}]}]';-- const result = resolveRichTextVariables(input, contextWithNumber);-- expect(result).toBe(- '[{"type":"paragraph","content":[{"type":"text","text":"42"}]}]',- );- });-- it('should serialize object values as JSON instead of [object Object]', () => {- const contextWithObject = {- step1: {- message: { foo: 'bar', count: 1 },- },- };-- const input =- '[{"type":"paragraph","content":[{"type":"variableTag","attrs":{"variable":"{{step1.message}}"}}]}]';-- const result = resolveRichTextVariables(input, contextWithObject);-- expect(result).toBe(- '[{"type":"paragraph","content":[{"type":"text","text":"{\\"foo\\":\\"bar\\",\\"count\\":1}"}]}]',- );- });-- it('should preserve regular {{variable}} patterns in non-variableTag contexts', () => {- const input =- '[{"type":"paragraph","content":[{"type":"text","text":"Regular {{step1.message}} pattern"}]}]';-- const result = resolveRichTextVariables(input, context);-- expect(result).toBe(input);- });-- it('should return undefined for undefined input', () => {- const result = resolveRichTextVariables(undefined, context);-- expect(result).toBeUndefined();- });-- it('should resolve variableTag nodes with attrs before type (alternate JSON order)', () => {- const input =- '[{"type":"paragraph","content":[{"attrs":{"variable":"{{step1.message}}"},"type":"variableTag"}]}]';-- const result = resolveRichTextVariables(input, context);-- expect(result).toBe(- '[{"type":"paragraph","content":[{"type":"text","text":"Hello World"}]}]',- );- });-- it('should resolve mixed property order variableTag nodes', () => {- const input =- '[{"type":"paragraph","content":[{"type":"variableTag","attrs":{"variable":"{{step1.name}}"}},{"attrs":{"variable":"{{user.email}}"},"type":"variableTag"}]}]';-- const result = resolveRichTextVariables(input, context);-- expect(result).toBe(- '[{"type":"paragraph","content":[{"type":"text","text":"John"},{"type":"text","text":"[email protected]"}]}]',- );- });-- it('should convert newlines to hardBreak nodes', () => {- const contextWithNewlines = {- step1: {- message: 'Hello\nWorld',- },- };-- const input =- '[{"type":"paragraph","content":[{"type":"variableTag","attrs":{"variable":"{{step1.message}}"}}]}]';-- const result = resolveRichTextVariables(input, contextWithNewlines);-- expect(result).toBe(- '[{"type":"paragraph","content":[{"type":"text","text":"Hello"},{"type":"hardBreak"},{"type":"text","text":"World"}]}]',- );- });-- it('should handle multiple newlines', () => {- const contextWithMultipleNewlines = {- step1: {- message: 'Line 1\nLine 2\nLine 3',- },- };-- const input =- '[{"type":"paragraph","content":[{"type":"variableTag","attrs":{"variable":"{{step1.message}}"}}]}]';-- const result = resolveRichTextVariables(input, contextWithMultipleNewlines);-- expect(result).toBe(- '[{"type":"paragraph","content":[{"type":"text","text":"Line 1"},{"type":"hardBreak"},{"type":"text","text":"Line 2"},{"type":"hardBreak"},{"type":"text","text":"Line 3"}]}]',- );- });-- it('should handle newlines with special characters', () => {- const contextWithNewlinesAndSpecialChars = {- step1: {- message: 'Hello "World"\nGoodbye',- },- };-- const input =- '[{"type":"paragraph","content":[{"type":"variableTag","attrs":{"variable":"{{step1.message}}"}}]}]';-- const result = resolveRichTextVariables(- input,- contextWithNewlinesAndSpecialChars,- );-- expect(result).toBe(- '[{"type":"paragraph","content":[{"type":"text","text":"Hello \\"World\\""},{"type":"hardBreak"},{"type":"text","text":"Goodbye"}]}]',- );- });-});diff --git a/packages/twenty-shared/src/utils/index.ts b/packages/twenty-shared/src/utils/index.tsindex 7effe39e982..402066e9270 100644--- a/packages/twenty-shared/src/utils/index.ts+++ b/packages/twenty-shared/src/utils/index.ts@@ -218,7 +218,6 @@ export { getPageLayoutWidgetHeightBehavior } from './pageLayout/getPageLayoutWidexport { parseJson } from './parseJson';export { removePropertiesFromRecord } from './removePropertiesFromRecord';export { removeUndefinedFields } from './removeUndefinedFields';-export { resolveRichTextVariables } from './rich-text-variable-resolver';export { safeParseRelativeDateFilterJsonStringified } from './safeParseRelativeDateFilterJsonStringified';export { getGenericOperationName } from './sentry/getGenericOperationName';export { getHumanReadableNameFromCode } from './sentry/getHumanReadableNameFromCode';diff --git a/packages/twenty-shared/src/utils/rich-text-variable-resolver.ts b/packages/twenty-shared/src/utils/rich-text-variable-resolver.tsdeleted file mode 100644index dc62c3ba0c2..00000000000--- a/packages/twenty-shared/src/utils/rich-text-variable-resolver.ts+++ /dev/null@@ -1,53 +0,0 @@-import { isDefined } from '@/utils/validation';-import { evalFromContext } from './evalFromContext';--const VARIABLE_TAG_PATTERN =- /\{"type":"variableTag","attrs":\{"variable":"(\{\{[^{}]+\}\})"\}\}|\{"attrs":\{"variable":"(\{\{[^{}]+\}\})"\},"type":"variableTag"\}/g;--const escapeJsonString = (text: string): string => {- return JSON.stringify(text).slice(1, -1);-};--const buildTextNodesWithLineBreaks = (text: string): string => {- const lines = text.split('\n');-- if (lines.length === 1) {- return `{"type":"text","text":"${escapeJsonString(text)}"}`;- }-- return lines- .map((line, index) => {- const textNode = `{"type":"text","text":"${escapeJsonString(line)}"}`;-- if (index < lines.length - 1) {- return `${textNode},{"type":"hardBreak"}`;- }-- return textNode;- })- .join(',');-};--export const resolveRichTextVariables = (- input: string | null | undefined,- context: Record<string, unknown>,-): string | undefined => {- if (!isDefined(input)) {- return undefined;- }-- return input.replace(- VARIABLE_TAG_PATTERN,- (_, variableTypeFirst: string, variableAttrsFirst: string) => {- const variable = variableTypeFirst ?? variableAttrsFirst;- const resolvedValue = evalFromContext(variable, context);- const textValue = !isDefined(resolvedValue)- ? ''- : typeof resolvedValue === 'object'- ? JSON.stringify(resolvedValue)- : String(resolvedValue);-- return buildTextNodesWithLineBreaks(textValue);- },- );-};diff --git a/packages/twenty-shared/src/utils/tiptap/__tests__/convert-tiptap-blocks-to-markdown.test.ts b/packages/twenty-shared/src/utils/tiptap/__tests__/convert-tiptap-blocks-to-markdown.test.tsindex b7da093390e..972fd2862a4 100644--- a/packages/twenty-shared/src/utils/tiptap/__tests__/convert-tiptap-blocks-to-markdown.test.ts+++ b/packages/twenty-shared/src/utils/tiptap/__tests__/convert-tiptap-blocks-to-markdown.test.ts@@ -99,14 +99,11 @@ describe('convertTipTapBlocksToMarkdown', () => {],markdown: 'First\nSecond',},- ])(- 'should convert $name without any TipTap-only block',- ({ blocks, markdown }) => {- expect(convertTipTapBlocksToMarkdown(JSON.stringify(blocks))).toBe(- markdown,- );- },- );+ ])('should convert $name', ({ blocks, markdown }) => {+ expect(convertTipTapBlocksToMarkdown(JSON.stringify(blocks))).toBe(+ markdown,+ );+ });it('should return undefined for invalid json', () => {expect(convertTipTapBlocksToMarkdown('not json')).toBeUndefined();@@ -120,45 +117,26 @@ describe('convertTipTapBlocksToMarkdown', () => {expect(convertTipTapBlocksToMarkdown('[{"foo":"bar"}]')).toBeUndefined();});- it('should leave a blocknote body carrying a mention alone', () => {+ it('should leave a blocknote body with a divider alone', () => {const blocknoteBody = JSON.stringify([{id: 'b1',type: 'paragraph',props: {},children: [],- content: [- { type: 'text', text: 'Hello ', styles: {} },- { type: 'mention', props: { label: 'John Doe' } },- ],- },- ]);-- expect(convertTipTapBlocksToMarkdown(blocknoteBody)).toBeUndefined();- });-- it('should leave a blocknote list alone', () => {- const blocknoteBody = JSON.stringify([- {- id: 'b1',- type: 'bulletListItem',- props: {},- children: [],- content: [{ type: 'text', text: 'call the client', styles: {} }],+ content: [{ type: 'text', text: 'Bold', styles: { bold: true } }],},+ { id: 'b2', type: 'divider', props: {}, children: [] },]);expect(convertTipTapBlocksToMarkdown(blocknoteBody)).toBeUndefined();});- it('should leave a blocknote table alone, whose content is not an array', () => {+ it('should leave a blocknote body without block ids alone', () => {const blocknoteBody = JSON.stringify([{- id: 'b1',- type: 'table',- props: {},- children: [],- content: { type: 'tableContent', rows: [] },+ type: 'paragraph',+ content: [{ type: 'text', text: 'Bold', styles: { bold: true } }],},]);diff --git a/packages/twenty-shared/src/utils/tiptap/convert-tiptap-blocks-to-markdown.ts b/packages/twenty-shared/src/utils/tiptap/convert-tiptap-blocks-to-markdown.tsindex a00778b7478..5ed445d481a 100644--- a/packages/twenty-shared/src/utils/tiptap/convert-tiptap-blocks-to-markdown.ts+++ b/packages/twenty-shared/src/utils/tiptap/convert-tiptap-blocks-to-markdown.ts@@ -1,35 +1,24 @@-import { isDefined } from '@/utils/validation';+import { isPlainObject } from '@/utils/typeguard/isPlainObject';import { isTipTapNode } from './parse-tiptap-json-document';import { type TipTapDocument } from './tiptap-document';import { tipTapDocumentToMarkdown } from './tiptap-document-to-markdown';-import { type TipTapNode } from './tiptap-node';import { TIPTAP_NODE_TYPES } from './tiptap-node-types';-const TIPTAP_ONLY_NODE_TYPES: string[] = [- TIPTAP_NODE_TYPES.DOCUMENT,- TIPTAP_NODE_TYPES.BULLET_LIST,- TIPTAP_NODE_TYPES.ORDERED_LIST,- TIPTAP_NODE_TYPES.LIST_ITEM,- TIPTAP_NODE_TYPES.TASK_LIST,- TIPTAP_NODE_TYPES.TASK_ITEM,- TIPTAP_NODE_TYPES.SECTION,- TIPTAP_NODE_TYPES.COLUMNS,- TIPTAP_NODE_TYPES.COLUMN,- TIPTAP_NODE_TYPES.BUTTON,- TIPTAP_NODE_TYPES.DIVIDER,- TIPTAP_NODE_TYPES.HTML,- TIPTAP_NODE_TYPES.HARD_BREAK,- TIPTAP_NODE_TYPES.VARIABLE_TAG,- TIPTAP_NODE_TYPES.MENTION_TAG,- TIPTAP_NODE_TYPES.SKILL_TAG,-];--const containsTipTapOnlyContent = (node: TipTapNode): boolean =>- TIPTAP_ONLY_NODE_TYPES.includes(node.type) ||- isDefined(node.attrs) ||- isDefined(node.marks) ||- (node.content ?? []).some(containsTipTapOnlyContent);+// Workflow steps created through the API can still hold BlockNote, which also parses as TipTap+const BLOCKNOTE_ONLY_KEYS = ['id', 'props', 'children', 'styles'];++const isBlockNoteContent = (value: unknown): boolean => {+ if (!isPlainObject(value)) {+ return false;+ }++ if (BLOCKNOTE_ONLY_KEYS.some((key) => key in value)) {+ return true;+ }++ return Array.isArray(value.content) && value.content.some(isBlockNoteContent);+};export const convertTipTapBlocksToMarkdown = (serializedBlocks: string,@@ -44,7 +33,11 @@ export const convertTipTapBlocksToMarkdown = (const nodes = Array.isArray(parsedBlocks) ? parsedBlocks : [parsedBlocks];- if (!nodes.every(isTipTapNode) || !nodes.some(containsTipTapOnlyContent)) {+ if (+ nodes.length === 0 ||+ nodes.some(isBlockNoteContent) ||+ !nodes.every(isTipTapNode)+ ) {return undefined;}