Remove dependency on lodash.pick. (#15213)

Fixes [Dependabot Alert
85](https://github.com/twentyhq/twenty/security/dependabot/85) -
prototype pollution in lodash.

Added a shared pick helper (with unit tests) in twenty-shared and
refactored front-end/server code to import { pick } from the shared
barrel instead of lodash.pick.

---------

Co-authored-by: Félix Malfait <felix.malfait@gmail.com>
Co-authored-by: martmull <martmull@hotmail.fr>
This commit is contained in:
Abdullah.
2025-10-21 13:19:49 +05:00
committed by GitHub
parent 187cf400aa
commit 793dc3d6fc
14 changed files with 67 additions and 90 deletions
@@ -1,16 +1,16 @@
import pick from 'lodash.pick';
import { getRecordsFromRecordConnection } from '@/object-record/cache/utils/getRecordsFromRecordConnection';
import { type RecordGqlNode } from '@/object-record/graphql/types/RecordGqlNode';
import { type ObjectRecord } from '@/object-record/types/ObjectRecord';
import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull';
import { isDefined } from 'twenty-shared/utils';
import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull';
export const getRecordFromRecordNode = <T extends ObjectRecord>({
recordNode,
}: {
recordNode: RecordGqlNode;
}): T => {
const { id, __typename } = recordNode;
return {
...Object.fromEntries(
Object.entries(recordNode).map(([fieldName, value]) => {
@@ -34,6 +34,7 @@ export const getRecordFromRecordNode = <T extends ObjectRecord>({
// RawJson field value passes through this method and does not have `id` or `__typename`.
// This prevents adding an undefined `id` and `__typename` to the RawJson field value,
// which is invalid JSON.
...pick(recordNode, ['id', '__typename'] as const),
...(isDefined(id) ? { id } : {}),
...(isDefined(__typename) ? { __typename } : {}),
} as T;
};