diff --git a/packages/twenty-server/src/engine/core-modules/tool-provider/output-transforms/__tests__/strip-empty-values.util.spec.ts b/packages/twenty-server/src/engine/core-modules/tool-provider/output-transforms/__tests__/strip-empty-values.util.spec.ts index 6810f6ab51..b7d0904c9b 100644 --- a/packages/twenty-server/src/engine/core-modules/tool-provider/output-transforms/__tests__/strip-empty-values.util.spec.ts +++ b/packages/twenty-server/src/engine/core-modules/tool-provider/output-transforms/__tests__/strip-empty-values.util.spec.ts @@ -141,6 +141,47 @@ describe('stripEmptyValues', () => { }); }); + it('should preserve Date objects', () => { + const date = new Date('2024-01-15T10:30:00.000Z'); + + expect(stripEmptyValues({ createdAt: date, name: 'Test' })).toEqual({ + createdAt: date, + name: 'Test', + }); + }); + + it('should preserve Date objects inside nested records', () => { + const createdAt = new Date('2024-01-15T10:30:00.000Z'); + const updatedAt = new Date('2024-02-20T14:00:00.000Z'); + + const input = { + result: { + records: [ + { + id: 'abc-123', + name: 'Acme', + createdAt, + updatedAt, + deletedAt: null, + }, + ], + }, + }; + + expect(stripEmptyValues(input)).toEqual({ + result: { + records: [ + { + id: 'abc-123', + name: 'Acme', + createdAt, + updatedAt, + }, + ], + }, + }); + }); + it('should handle primitive values', () => { expect(stripEmptyValues(42)).toBe(42); expect(stripEmptyValues('hello')).toBe('hello'); diff --git a/packages/twenty-server/src/engine/core-modules/tool-provider/output-transforms/strip-empty-values.util.ts b/packages/twenty-server/src/engine/core-modules/tool-provider/output-transforms/strip-empty-values.util.ts index c2d21925ef..81c9ee92d0 100644 --- a/packages/twenty-server/src/engine/core-modules/tool-provider/output-transforms/strip-empty-values.util.ts +++ b/packages/twenty-server/src/engine/core-modules/tool-provider/output-transforms/strip-empty-values.util.ts @@ -1,11 +1,18 @@ // Recursively strips null, undefined, empty strings, empty objects, // and empty arrays from a value. Returns undefined if the entire + +import { isDate } from '@sniptt/guards'; + // value is empty so the caller can decide whether to include it. export const stripEmptyValues = (value: unknown): unknown => { if (value === null || value === undefined || value === '') { return undefined; } + if (isDate(value)) { + return value; + } + if (Array.isArray(value)) { const cleaned = value .map(stripEmptyValues)