{"version":3,"sources":["../../../src/fields/config/sanitize.ts"],"sourcesContent":["import { deepMergeSimple } from '@payloadcms/translations/utilities'\n\nimport type {\n CollectionConfig,\n SanitizedJoin,\n SanitizedJoins,\n} from '../../collections/config/types.js'\nimport type { Config, SanitizedConfig } from '../../config/types.js'\nimport type { GlobalConfig } from '../../globals/config/types.js'\nimport type { Field } from './types.js'\n\nimport {\n DuplicateFieldName,\n InvalidConfiguration,\n InvalidFieldName,\n InvalidFieldRelationship,\n MissingEditorProp,\n MissingFieldType,\n} from '../../errors/index.js'\nimport { ReservedFieldName } from '../../errors/ReservedFieldName.js'\nimport { flattenAllFields } from '../../utilities/flattenAllFields.js'\nimport { formatLabels, toWords } from '../../utilities/formatLabels.js'\nimport { validateTimezones } from '../../utilities/validateTimezones.js'\nimport { baseBlockFields } from '../baseFields/baseBlockFields.js'\nimport { baseIDField } from '../baseFields/baseIDField.js'\nimport { baseTimezoneField } from '../baseFields/timezone/baseField.js'\nimport { defaultTimezones } from '../baseFields/timezone/defaultTimezones.js'\nimport { getFieldPaths } from '../getFieldPaths.js'\nimport { setDefaultBeforeDuplicate } from '../setDefaultBeforeDuplicate.js'\nimport { validations } from '../validations.js'\nimport {\n reservedAPIKeyFieldNames,\n reservedBaseAuthFieldNames,\n reservedBaseUploadFieldNames,\n reservedVerifyFieldNames,\n} from './reservedFieldNames.js'\nimport { sanitizeJoinField } from './sanitizeJoinField.js'\nimport {\n fieldAffectsData as _fieldAffectsData,\n fieldIsLocalized,\n fieldIsVirtual,\n tabHasName,\n} from './types.js'\n\ntype Args = {\n collectionConfig?: CollectionConfig\n config: Config\n existingFieldNames?: Set\n fields: Field[]\n globalConfig?: GlobalConfig\n /**\n * Used to prevent unnecessary sanitization of fields that are not top-level.\n */\n isTopLevelField?: boolean\n joinPath?: string\n /**\n * When not passed in, assume that join are not supported (globals, arrays, blocks)\n */\n joins?: SanitizedJoins\n /**\n * A string of '-' separated indexes representing where\n * to find this field in a given field schema array.\n */\n parentIndexPath?: string\n parentIsLocalized: boolean\n /**\n * Path for parent fields relative to their position in the schema.\n */\n parentSchemaPath?: string\n polymorphicJoins?: SanitizedJoin[]\n /**\n * If true, a richText field will require an editor property to be set, as the sanitizeFields function will not add it from the payload config if not present.\n *\n * @default false\n */\n requireFieldLevelRichTextEditor?: boolean\n /**\n * If this property is set, RichText fields won't be sanitized immediately. Instead, they will be added to this array as promises\n * so that you can sanitize them together, after the config has been sanitized.\n */\n richTextSanitizationPromises?: Array<(config: SanitizedConfig) => Promise>\n /**\n * If not null, will validate that upload and relationship fields do not relate to a collection that is not in this array.\n * This validation will be skipped if validRelationships is null.\n */\n validRelationships: null | string[]\n}\n\nexport const sanitizeFields = async ({\n collectionConfig,\n config,\n existingFieldNames = new Set(),\n fields,\n globalConfig,\n isTopLevelField = true,\n joinPath = '',\n joins,\n parentIndexPath = '',\n parentIsLocalized,\n parentSchemaPath = '',\n polymorphicJoins,\n requireFieldLevelRichTextEditor = false,\n richTextSanitizationPromises,\n validRelationships,\n}: Args): Promise => {\n if (!fields) {\n return []\n }\n\n for (let i = 0; i < fields.length; i++) {\n const field = fields[i]!\n\n if ('_sanitized' in field && field._sanitized === true) {\n continue\n }\n\n if ('_sanitized' in field) {\n field._sanitized = true\n }\n\n if (!field.type) {\n throw new MissingFieldType(field)\n }\n\n const fieldAffectsData = _fieldAffectsData(field)\n\n const { indexPath, schemaPath } = getFieldPaths({\n field,\n index: i,\n parentIndexPath,\n parentSchemaPath,\n })\n\n if (isTopLevelField && fieldAffectsData && field.name) {\n if (collectionConfig && collectionConfig.upload) {\n if (reservedBaseUploadFieldNames.includes(field.name)) {\n throw new ReservedFieldName(field, field.name)\n }\n }\n\n if (\n collectionConfig &&\n collectionConfig.auth &&\n typeof collectionConfig.auth === 'object' &&\n !collectionConfig.auth.disableLocalStrategy\n ) {\n if (reservedBaseAuthFieldNames.includes(field.name)) {\n throw new ReservedFieldName(field, field.name)\n }\n\n if (collectionConfig.auth.verify) {\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n if (reservedAPIKeyFieldNames.includes(field.name)) {\n throw new ReservedFieldName(field, field.name)\n }\n\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n if (reservedVerifyFieldNames.includes(field.name)) {\n throw new ReservedFieldName(field, field.name)\n }\n }\n }\n }\n\n // assert that field names do not contain forbidden characters\n if (fieldAffectsData && field.name.includes('.')) {\n throw new InvalidFieldName(field, field.name)\n }\n\n // Auto-label\n if (\n 'name' in field &&\n field.name &&\n typeof field.label !== 'object' &&\n typeof field.label !== 'string' &&\n typeof field.label !== 'function' &&\n field.label !== false\n ) {\n field.label = toWords(field.name)\n }\n\n if (\n field.type === 'checkbox' &&\n typeof field.defaultValue === 'undefined' &&\n field.required === true\n ) {\n field.defaultValue = false\n }\n\n if (field.type === 'join') {\n sanitizeJoinField({ config, field, joinPath, joins, parentIsLocalized, polymorphicJoins })\n }\n\n if (field.type === 'relationship' || field.type === 'upload') {\n // Validate that relationTo is not empty\n if (Array.isArray(field.relationTo) && field.relationTo.length === 0) {\n throw new Error(\n `Field \"${field.name}\" of type \"${field.type}\" has an empty relationTo array. At least one collection must be specified.`,\n )\n }\n\n if (validRelationships) {\n const relationships = Array.isArray(field.relationTo)\n ? field.relationTo\n : [field.relationTo]\n\n relationships.forEach((relationship: string) => {\n if (!validRelationships.includes(relationship)) {\n throw new InvalidFieldRelationship(field, relationship)\n }\n })\n }\n\n if (field.min && !field.minRows) {\n console.warn(\n `(payload): The \"min\" property is deprecated for the Relationship field \"${field.name}\" and will be removed in a future version. Please use \"minRows\" instead.`,\n )\n field.minRows = field.min\n }\n\n if (field.max && !field.maxRows) {\n console.warn(\n `(payload): The \"max\" property is deprecated for the Relationship field \"${field.name}\" and will be removed in a future version. Please use \"maxRows\" instead.`,\n )\n field.maxRows = field.max\n }\n }\n\n if (field.type === 'upload') {\n if (!field.admin || !('isSortable' in field.admin)) {\n field.admin = {\n isSortable: true,\n ...field.admin,\n }\n }\n }\n\n if (field.type === 'array' && field.fields) {\n const hasCustomID = field.fields.some((f) => 'name' in f && f.name === 'id')\n if (!hasCustomID) {\n field.fields.push(baseIDField)\n }\n }\n\n if ((field.type === 'blocks' || field.type === 'array') && field.label) {\n field.labels = field.labels || formatLabels(field.name)\n }\n\n if (fieldAffectsData) {\n if (existingFieldNames.has(field.name)) {\n throw new DuplicateFieldName(field.name)\n } else if (!['blockName', 'id'].includes(field.name)) {\n existingFieldNames.add(field.name)\n }\n\n if (typeof field.localized !== 'undefined') {\n let shouldDisableLocalized = !config.localization\n\n if (\n process.env.NEXT_PUBLIC_PAYLOAD_COMPATIBILITY_allowLocalizedWithinLocalized !== 'true' &&\n parentIsLocalized &&\n // @todo PAYLOAD_DO_NOT_SANITIZE_LOCALIZED_PROPERTY=true will be the default in 4.0\n process.env.PAYLOAD_DO_NOT_SANITIZE_LOCALIZED_PROPERTY !== 'true'\n ) {\n shouldDisableLocalized = true\n }\n\n if (shouldDisableLocalized) {\n delete field.localized\n }\n }\n\n if (typeof field.validate === 'undefined') {\n const defaultValidate = validations[field.type as keyof typeof validations]\n if (defaultValidate) {\n field.validate = (val: any, options: any) =>\n defaultValidate(val, { ...field, ...options })\n } else {\n field.validate = (): true => true\n }\n }\n\n if (!field.hooks) {\n field.hooks = {}\n }\n\n if (!field.access) {\n field.access = {}\n }\n\n setDefaultBeforeDuplicate(field, parentIsLocalized)\n }\n\n if (!field.admin) {\n field.admin = {}\n }\n\n // Make sure that the richText field has an editor\n if (field.type === 'richText') {\n const sanitizeRichText = async (_config: SanitizedConfig) => {\n if (!field.editor) {\n if (_config.editor && !requireFieldLevelRichTextEditor) {\n // config.editor should be sanitized at this point\n field.editor = _config.editor\n } else {\n throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n }\n\n if (typeof field.editor === 'function') {\n field.editor = await field.editor({\n config: _config,\n isRoot: requireFieldLevelRichTextEditor,\n parentIsLocalized: (parentIsLocalized || field.localized)!,\n })\n }\n\n if (field.editor.i18n && Object.keys(field.editor.i18n).length >= 0) {\n config.i18n!.translations = deepMergeSimple(config.i18n!.translations!, field.editor.i18n)\n }\n }\n if (richTextSanitizationPromises) {\n richTextSanitizationPromises.push(sanitizeRichText)\n } else {\n await sanitizeRichText(config as unknown as SanitizedConfig)\n }\n }\n\n if (field.type === 'blocks' && field.blocks) {\n if (field.blockReferences && field.blocks?.length) {\n throw new Error('You cannot have both blockReferences and blocks in the same blocks field')\n }\n\n const blockSlugs: string[] = []\n\n for (const block of field.blockReferences ?? field.blocks) {\n const blockSlug = typeof block === 'string' ? block : block.slug\n\n if (blockSlugs.includes(blockSlug)) {\n throw new DuplicateFieldName(blockSlug)\n }\n\n blockSlugs.push(blockSlug)\n\n if (typeof block === 'string') {\n continue\n }\n\n if (block._sanitized === true) {\n continue\n }\n\n block._sanitized = true\n block.fields = block.fields.concat(baseBlockFields)\n block.labels = !block.labels ? formatLabels(block.slug) : block.labels\n\n block.fields = await sanitizeFields({\n collectionConfig,\n config,\n existingFieldNames: new Set(),\n fields: block.fields,\n isTopLevelField: false,\n parentIndexPath: '',\n parentIsLocalized: (parentIsLocalized || field.localized)!,\n parentSchemaPath: schemaPath + '.' + block.slug,\n requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n validRelationships,\n })\n }\n }\n\n if ('fields' in field && field.fields) {\n field.fields = await sanitizeFields({\n collectionConfig,\n config,\n existingFieldNames: fieldAffectsData ? new Set() : existingFieldNames,\n fields: field.fields,\n isTopLevelField: isTopLevelField && !fieldAffectsData,\n joinPath: fieldAffectsData ? `${joinPath ? joinPath + '.' : ''}${field.name}` : joinPath,\n joins,\n parentIndexPath: fieldAffectsData ? '' : indexPath,\n parentIsLocalized: parentIsLocalized || fieldIsLocalized(field),\n parentSchemaPath: schemaPath,\n polymorphicJoins,\n requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n validRelationships,\n })\n }\n\n if (field.type === 'tabs') {\n for (let j = 0; j < field.tabs.length; j++) {\n const tab = field.tabs[j]!\n\n const isNamedTab = tabHasName(tab)\n\n if (isNamedTab && typeof tab.label === 'undefined') {\n tab.label = toWords(tab.name)\n }\n\n const { indexPath: tabIndexPath, schemaPath: tabSchemaPath } = getFieldPaths({\n field: tab,\n index: j,\n parentIndexPath: indexPath,\n parentSchemaPath: schemaPath,\n })\n\n if (\n 'admin' in tab &&\n tab.admin?.condition &&\n typeof tab.admin.condition === 'function' &&\n !tab.id\n ) {\n tab.id = tabSchemaPath\n }\n\n tab.fields = await sanitizeFields({\n collectionConfig,\n config,\n existingFieldNames: isNamedTab ? new Set() : existingFieldNames,\n fields: tab.fields,\n isTopLevelField: isTopLevelField && !isNamedTab,\n joinPath: isNamedTab ? `${joinPath ? joinPath + '.' : ''}${tab.name}` : joinPath,\n joins,\n parentIndexPath: isNamedTab ? '' : tabIndexPath,\n parentIsLocalized: parentIsLocalized || (isNamedTab && tab.localized)!,\n parentSchemaPath: tabSchemaPath,\n polymorphicJoins,\n requireFieldLevelRichTextEditor,\n richTextSanitizationPromises,\n validRelationships,\n })\n\n field.tabs[j] = tab\n }\n }\n\n if (field.type === 'ui' && typeof field.admin.disableBulkEdit === 'undefined') {\n field.admin.disableBulkEdit = true\n }\n\n fields[i] = field\n\n // Insert our field after assignment\n if (field.type === 'date' && field.timezone) {\n const name = field.name + '_tz'\n\n let defaultTimezone =\n field.timezone && typeof field.timezone === 'object'\n ? field.timezone.defaultTimezone\n : config.admin?.timezones?.defaultTimezone\n\n const required =\n field.required ||\n (field.timezone && typeof field.timezone === 'object' && field.timezone.required)\n\n const supportedTimezones =\n field.timezone && typeof field.timezone === 'object' && field.timezone.supportedTimezones\n ? field.timezone.supportedTimezones\n : config.admin?.timezones?.supportedTimezones\n\n const options =\n typeof supportedTimezones === 'function'\n ? supportedTimezones({ defaultTimezones })\n : supportedTimezones\n\n validateTimezones({\n source: `field \"${field.name}\" timezone.supportedTimezones`,\n timezones: options,\n })\n\n if (options && options.length === 1 && options[0]?.value) {\n defaultTimezone = options[0].value\n }\n\n // Generate label for timezone field\n // Use parent field's label + ' Tz' if it's a simple string, otherwise fallback to name\n const timezoneLabel = typeof field.label === 'string' ? `${field.label} Tz` : toWords(name)\n\n // Need to set the options here manually so that any database enums are generated correctly\n // The UI component will import the options from the config\n const baseField = baseTimezoneField({\n name,\n defaultValue: defaultTimezone,\n label: timezoneLabel,\n options,\n required,\n })\n\n // Apply override if provided\n const timezoneField =\n typeof field.timezone === 'object' && typeof field.timezone.override === 'function'\n ? field.timezone.override({ baseField })\n : baseField\n\n fields.splice(++i, 0, timezoneField)\n }\n\n if ('virtual' in field && typeof field.virtual === 'string') {\n const virtualField = field\n const fields = (collectionConfig || globalConfig)?.fields\n if (fields) {\n let flattenFields = flattenAllFields({ fields })\n const paths = field.virtual.split('.')\n let isHasMany = false\n\n for (const [i, segment] of paths.entries()) {\n const field = flattenFields.find((e) => e.name === segment)\n if (!field) {\n break\n }\n\n if (field.type === 'group' || field.type === 'tab' || field.type === 'array') {\n flattenFields = field.flattenedFields\n } else if (\n (field.type === 'relationship' || field.type === 'upload') &&\n i !== paths.length - 1 &&\n typeof field.relationTo === 'string'\n ) {\n if (\n field.hasMany &&\n (virtualField.type === 'text' ||\n virtualField.type === 'number' ||\n virtualField.type === 'select')\n ) {\n if (isHasMany) {\n throw new InvalidConfiguration(\n `Virtual field ${virtualField.name} in ${globalConfig ? `global ${globalConfig.slug}` : `collection ${collectionConfig?.slug}`} references 2 or more hasMany relationships on the path ${virtualField.virtual} which is not allowed.`,\n )\n }\n\n isHasMany = true\n virtualField.hasMany = true\n }\n const relatedCollection = config.collections?.find((e) => e.slug === field.relationTo)\n if (relatedCollection) {\n flattenFields = flattenAllFields({ fields: relatedCollection.fields })\n }\n }\n }\n }\n }\n }\n\n return fields\n}\n"],"names":["deepMergeSimple","DuplicateFieldName","InvalidConfiguration","InvalidFieldName","InvalidFieldRelationship","MissingEditorProp","MissingFieldType","ReservedFieldName","flattenAllFields","formatLabels","toWords","validateTimezones","baseBlockFields","baseIDField","baseTimezoneField","defaultTimezones","getFieldPaths","setDefaultBeforeDuplicate","validations","reservedAPIKeyFieldNames","reservedBaseAuthFieldNames","reservedBaseUploadFieldNames","reservedVerifyFieldNames","sanitizeJoinField","fieldAffectsData","_fieldAffectsData","fieldIsLocalized","tabHasName","sanitizeFields","collectionConfig","config","existingFieldNames","Set","fields","globalConfig","isTopLevelField","joinPath","joins","parentIndexPath","parentIsLocalized","parentSchemaPath","polymorphicJoins","requireFieldLevelRichTextEditor","richTextSanitizationPromises","validRelationships","i","length","field","_sanitized","type","indexPath","schemaPath","index","name","upload","includes","auth","disableLocalStrategy","verify","label","defaultValue","required","Array","isArray","relationTo","Error","relationships","forEach","relationship","min","minRows","console","warn","max","maxRows","admin","isSortable","hasCustomID","some","f","push","labels","has","add","localized","shouldDisableLocalized","localization","process","env","NEXT_PUBLIC_PAYLOAD_COMPATIBILITY_allowLocalizedWithinLocalized","PAYLOAD_DO_NOT_SANITIZE_LOCALIZED_PROPERTY","validate","defaultValidate","val","options","hooks","access","sanitizeRichText","_config","editor","isRoot","i18n","Object","keys","translations","blocks","blockReferences","blockSlugs","block","blockSlug","slug","concat","j","tabs","tab","isNamedTab","tabIndexPath","tabSchemaPath","condition","id","disableBulkEdit","timezone","defaultTimezone","timezones","supportedTimezones","source","value","timezoneLabel","baseField","timezoneField","override","splice","virtual","virtualField","flattenFields","paths","split","isHasMany","segment","entries","find","e","flattenedFields","hasMany","relatedCollection","collections"],"mappings":"AAAA,SAASA,eAAe,QAAQ,qCAAoC;AAWpE,SACEC,kBAAkB,EAClBC,oBAAoB,EACpBC,gBAAgB,EAChBC,wBAAwB,EACxBC,iBAAiB,EACjBC,gBAAgB,QACX,wBAAuB;AAC9B,SAASC,iBAAiB,QAAQ,oCAAmC;AACrE,SAASC,gBAAgB,QAAQ,sCAAqC;AACtE,SAASC,YAAY,EAAEC,OAAO,QAAQ,kCAAiC;AACvE,SAASC,iBAAiB,QAAQ,uCAAsC;AACxE,SAAS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