{"version":3,"file":"validators.mjs","sources":["../../../src/services/entity-validator/validators.ts"],"sourcesContent":["/**\n * Validators check if the entry data meets specific criteria before saving or publishing.\n * (e.g., length, range, format).\n *\n * Drafts have limited validations (mainly max constraints),\n * while published content undergoes full validation.\n *\n * The system also takes locales into account when validating data.\n * E.g, unique fields must be unique within the same locale.\n */\nimport _ from 'lodash';\nimport { yup } from '@strapi/utils';\nimport type { Schema, Struct, Modules } from '@strapi/types';\nimport { blocksValidator } from './blocks-validator';\n\nimport type { ComponentContext } from '.';\n\nexport interface ValidatorMetas<\n TAttribute extends Schema.Attribute.AnyAttribute = Schema.Attribute.AnyAttribute,\n TValue extends Schema.Attribute.Value = Schema.Attribute.Value,\n> {\n attr: TAttribute;\n model: Struct.Schema;\n updatedAttribute: {\n name: string;\n value: TValue;\n };\n data: Record;\n componentContext?: ComponentContext;\n entity?: Modules.EntityValidator.Entity;\n}\n\ninterface ValidatorOptions {\n isDraft: boolean;\n locale?: string;\n}\n\n/* Validator utils */\n\n/**\n * Adds minLength validator\n */\nconst addMinLengthValidator = (\n validator: yup.StringSchema,\n {\n attr,\n }: {\n attr:\n | Schema.Attribute.String\n | Schema.Attribute.Text\n | Schema.Attribute.RichText\n | Schema.Attribute.Password\n | Schema.Attribute.Email\n | Schema.Attribute.UID;\n },\n { isDraft }: ValidatorOptions\n) => {\n return attr.minLength && _.isInteger(attr.minLength) && !isDraft\n ? validator.min(attr.minLength)\n : validator;\n};\n\n/**\n * Adds maxLength validator\n * @returns {StringSchema}\n */\nconst addMaxLengthValidator = (\n validator: yup.StringSchema,\n {\n attr,\n }: {\n attr:\n | Schema.Attribute.String\n | Schema.Attribute.Text\n | Schema.Attribute.RichText\n | Schema.Attribute.Password\n | Schema.Attribute.Email\n | Schema.Attribute.UID;\n }\n) => {\n return attr.maxLength && _.isInteger(attr.maxLength) ? validator.max(attr.maxLength) : validator;\n};\n\n/**\n * Adds min integer validator\n * @returns {NumberSchema}\n */\nconst addMinIntegerValidator = (\n validator: yup.NumberSchema,\n {\n attr,\n }: {\n attr: Schema.Attribute.Integer | Schema.Attribute.BigInteger;\n },\n { isDraft }: ValidatorOptions\n) => (_.isNumber(attr.min) && !isDraft ? validator.min(_.toInteger(attr.min)) : validator);\n\n/**\n * Adds max integer validator\n */\nconst addMaxIntegerValidator = (\n validator: yup.NumberSchema,\n {\n attr,\n }: {\n attr: Schema.Attribute.Integer | Schema.Attribute.BigInteger;\n }\n) => (_.isNumber(attr.max) ? validator.max(_.toInteger(attr.max)) : validator);\n\n/**\n * Adds min float/decimal validator\n */\nconst addMinFloatValidator = (\n validator: yup.NumberSchema,\n {\n attr,\n }: {\n attr: Schema.Attribute.Decimal | Schema.Attribute.Float;\n },\n { isDraft }: ValidatorOptions\n) => (_.isNumber(attr.min) && !isDraft ? validator.min(attr.min) : validator);\n\n/**\n * Adds max float/decimal validator\n */\nconst addMaxFloatValidator = (\n validator: yup.NumberSchema,\n {\n attr,\n }: {\n attr: Schema.Attribute.Decimal | Schema.Attribute.Float;\n }\n) => (_.isNumber(attr.max) ? validator.max(attr.max) : validator);\n\n/**\n * Adds regex validator\n */\nconst addStringRegexValidator = (\n validator: yup.StringSchema,\n {\n attr,\n }: {\n attr:\n | Schema.Attribute.String\n | Schema.Attribute.Text\n | Schema.Attribute.RichText\n | Schema.Attribute.Password\n | Schema.Attribute.Email\n | Schema.Attribute.UID;\n },\n { isDraft }: ValidatorOptions\n) => {\n return 'regex' in attr && !_.isUndefined(attr.regex) && !isDraft\n ? validator.matches(new RegExp(attr.regex), { excludeEmptyString: !attr.required })\n : validator;\n};\n\nconst addUniqueValidator = (\n validator: T,\n {\n attr,\n model,\n updatedAttribute,\n entity,\n componentContext,\n }: ValidatorMetas,\n options: ValidatorOptions\n): T => {\n if (attr.type !== 'uid' && !attr.unique) {\n return validator;\n }\n\n const validateUniqueFieldWithinComponent = async (value: any): Promise => {\n if (!componentContext) {\n return false;\n }\n\n // If we are validating a unique field within a repeatable component,\n // we first need to ensure that the repeatable in the current entity is\n // valid against itself.\n const hasRepeatableData = componentContext.repeatableData.length > 0;\n if (hasRepeatableData) {\n const { name: updatedName, value: updatedValue } = updatedAttribute;\n // Construct the full path to the unique field within the component.\n const pathToCheck = [...componentContext.pathToComponent.slice(1), updatedName].join('.');\n\n // Extract the values from the repeatable data using the constructed path\n const values = componentContext.repeatableData.map((item) => {\n return pathToCheck.split('.').reduce((acc, key) => acc[key], item as any);\n });\n\n // Check if the value is repeated in the current entity\n const isUpdatedAttributeRepeatedInThisEntity =\n values.filter((value) => value === updatedValue).length > 1;\n\n if (isUpdatedAttributeRepeatedInThisEntity) {\n return false;\n }\n }\n\n /**\n * When `componentContext` is present it means we are dealing with a unique\n * field within a component.\n *\n * The unique validation must consider the specific context of the\n * component, which will always be contained within a parent content type\n * and may also be nested within another component.\n *\n * We construct a query that takes into account the parent's model UID,\n * dimensions (such as draft and publish state/locale) and excludes the current\n * content type entity by its ID if provided.\n */\n const {\n model: parentModel,\n options: parentOptions,\n id: excludeId,\n } = componentContext.parentContent;\n\n const whereConditions: Record = {};\n const isParentDraft = parentOptions && parentOptions.isDraft;\n\n whereConditions.publishedAt = isParentDraft ? null : { $notNull: true };\n\n if (parentOptions?.locale) {\n whereConditions.locale = parentOptions.locale;\n }\n\n if (excludeId && !Number.isNaN(excludeId)) {\n whereConditions.id = { $ne: excludeId };\n }\n\n const queryUid = parentModel.uid;\n const queryWhere = {\n ...componentContext.pathToComponent.reduceRight((acc, key) => ({ [key]: acc }), {\n [updatedAttribute.name]: value,\n }),\n\n ...whereConditions,\n };\n\n // The validation should pass if there is no other record found from the query\n return !(await strapi.db.query(queryUid).findOne({ where: queryWhere }));\n };\n\n const validateUniqueFieldWithinDynamicZoneComponent = async (\n startOfPath: string\n ): Promise => {\n if (!componentContext) {\n return false;\n }\n\n const targetComponentUID = model.uid;\n // Ensure that the value is unique within the dynamic zone in this entity.\n const countOfValueInThisEntity = (componentContext?.fullDynamicZoneContent ?? []).reduce(\n (acc, component) => {\n if (component.__component !== targetComponentUID) {\n return acc;\n }\n\n const updatedValue = component[updatedAttribute.name];\n return updatedValue === updatedAttribute.value ? acc + 1 : acc;\n },\n 0\n );\n\n if (countOfValueInThisEntity > 1) {\n // If the value is repeated in the current entity, the validation fails.\n return false;\n }\n\n // Build a query for the parent content type to find all entities in the\n // same locale and publication state\n type QueryType = {\n select: string[];\n where: {\n published_at?: { $eq: null } | { $ne: null };\n id?: { $ne: number };\n locale?: string;\n };\n populate: {\n [key: string]: {\n on: {\n [key: string]: {\n select: string[];\n where: { [key: string]: string | number | boolean };\n };\n };\n };\n };\n };\n\n // Populate the dynamic zone for any components that share the same value\n // as the updated attribute.\n const query: QueryType = {\n select: ['id'],\n where: {},\n populate: {\n [startOfPath]: {\n on: {\n [targetComponentUID]: {\n select: ['id'],\n where: { [updatedAttribute.name]: updatedAttribute.value },\n },\n },\n },\n },\n };\n\n const { options, id } = componentContext.parentContent;\n\n if (options?.isDraft !== undefined) {\n query.where.published_at = options.isDraft ? { $eq: null } : { $ne: null };\n }\n\n if (id) {\n query.where.id = { $ne: id };\n }\n\n if (options?.locale) {\n query.where.locale = options.locale;\n }\n\n const parentModelQueryResult = await strapi.db\n .query(componentContext.parentContent.model.uid)\n .findMany(query);\n\n // Filter the results to only include results that have components in the\n // dynamic zone that match the target component type.\n const filteredResults = parentModelQueryResult\n .filter((result) => Array.isArray(result[startOfPath]) && result[startOfPath].length)\n .flatMap((result) => result[startOfPath])\n .filter((dynamicZoneComponent) => dynamicZoneComponent.__component === targetComponentUID);\n\n if (filteredResults.length >= 1) {\n return false;\n }\n\n return true;\n };\n\n return validator.test('unique', 'This attribute must be unique', async (value) => {\n /**\n * If the attribute value is `null` or an empty string we want to skip the unique validation.\n * Otherwise it'll only accept a single entry with that value in the database.\n */\n if (_.isNil(value) || value === '') {\n return true;\n }\n\n /**\n * We don't validate any unique constraint for draft entries.\n */\n if (options.isDraft) {\n return true;\n }\n\n const hasPathToComponent = componentContext && componentContext.pathToComponent.length > 0;\n if (hasPathToComponent) {\n // Detect if we are validating within a dynamiczone by checking if the first\n // path is a dynamiczone attribute in the parent content type.\n const startOfPath = componentContext.pathToComponent[0];\n const testingDZ =\n componentContext.parentContent.model.attributes[startOfPath].type === 'dynamiczone';\n\n if (testingDZ) {\n return validateUniqueFieldWithinDynamicZoneComponent(startOfPath);\n }\n\n return validateUniqueFieldWithinComponent(value);\n }\n\n /**\n * Here we are validating a scalar unique field from the content type's schema.\n * We construct a query to check if the value is unique\n * considering dimensions (e.g. locale, publication state) and excluding the current entity by its ID if available.\n */\n const scalarAttributeWhere: Record = {\n [updatedAttribute.name]: value,\n publishedAt: { $notNull: true },\n };\n\n if (options?.locale) {\n scalarAttributeWhere.locale = options.locale;\n }\n\n if (entity?.id) {\n scalarAttributeWhere.id = { $ne: entity.id };\n }\n\n // The validation should pass if there is no other record found from the query\n return !(await strapi.db\n .query(model.uid)\n .findOne({ where: scalarAttributeWhere, select: ['id'] }));\n });\n};\n\n/* Type validators */\n\nconst stringValidator = (\n metas: ValidatorMetas<\n | Schema.Attribute.String\n | Schema.Attribute.Text\n | Schema.Attribute.RichText\n | Schema.Attribute.Password\n | Schema.Attribute.Email\n | Schema.Attribute.UID\n >,\n options: ValidatorOptions\n) => {\n let schema = yup.string().transform((val, originalVal) => originalVal);\n\n schema = addMinLengthValidator(schema, metas, options);\n schema = addMaxLengthValidator(schema, metas);\n schema = addStringRegexValidator(schema, metas, options);\n schema = addUniqueValidator(schema, metas, options);\n\n return schema;\n};\n\nexport const emailValidator = (\n metas: ValidatorMetas,\n options: ValidatorOptions\n) => {\n const schema = stringValidator(metas, options);\n\n if (options.isDraft) {\n return schema;\n }\n\n return schema.email().min(\n 1,\n // eslint-disable-next-line no-template-curly-in-string\n '${path} cannot be empty'\n );\n};\n\nexport const uidValidator = (\n metas: ValidatorMetas,\n options: ValidatorOptions\n) => {\n const schema = stringValidator(metas, options);\n\n if (options.isDraft) {\n return schema;\n }\n\n if (metas.attr.regex) {\n return schema.matches(new RegExp(metas.attr.regex));\n }\n\n return schema.matches(/^[A-Za-z0-9-_.~]*$/);\n};\n\nexport const enumerationValidator = ({ attr }: { attr: Schema.Attribute.Enumeration }) => {\n return yup\n .string()\n .oneOf((Array.isArray(attr.enum) ? attr.enum : [attr.enum]).concat(null as any));\n};\n\nexport const integerValidator = (\n metas: ValidatorMetas,\n options: ValidatorOptions\n) => {\n let schema = yup.number().integer();\n\n schema = addMinIntegerValidator(schema, metas, options);\n schema = addMaxIntegerValidator(schema, metas);\n schema = addUniqueValidator(schema, metas, options);\n\n return schema;\n};\n\nexport const floatValidator = (\n metas: ValidatorMetas,\n options: ValidatorOptions\n) => {\n let schema = yup.number();\n\n schema = addMinFloatValidator(schema, metas, options);\n schema = addMaxFloatValidator(schema, metas);\n schema = addUniqueValidator(schema, metas, options);\n\n return schema;\n};\n\nexport const bigintegerValidator = (\n metas: ValidatorMetas,\n options: ValidatorOptions\n) => {\n const schema = yup.mixed();\n return addUniqueValidator(schema, metas, options);\n};\n\nexport const datesValidator = (\n metas: ValidatorMetas<\n | Schema.Attribute.Date\n | Schema.Attribute.DateTime\n | Schema.Attribute.Time\n | Schema.Attribute.Timestamp\n >,\n options: ValidatorOptions\n) => {\n const schema = yup.mixed();\n return addUniqueValidator(schema, metas, options);\n};\n\nexport const Validators = {\n string: stringValidator,\n text: stringValidator,\n richtext: stringValidator,\n password: stringValidator,\n email: emailValidator,\n enumeration: enumerationValidator,\n boolean: () => yup.boolean(),\n uid: uidValidator,\n json: () => yup.mixed(),\n integer: integerValidator,\n biginteger: bigintegerValidator,\n float: floatValidator,\n decimal: floatValidator,\n date: datesValidator,\n time: datesValidator,\n datetime: datesValidator,\n timestamp: datesValidator,\n blocks: blocksValidator,\n};\n"],"names":["addMinLengthValidator","validator","attr","isDraft","minLength","_","isInteger","min","addMaxLengthValidator","maxLength","max","addMinIntegerValidator","isNumber","toInteger","addMaxIntegerValidator","addMinFloatValidator","addMaxFloatValidator","addStringRegexValidator","isUndefined","regex","matches","RegExp","excludeEmptyString","required","addUniqueValidator","model","updatedAttribute","entity","componentContext","options","type","unique","validateUniqueFieldWithinComponent","value","hasRepeatableData","repeatableData","length","name","updatedName","updatedValue","pathToCheck","pathToComponent","slice","join","values","map","item","split","reduce","acc","key","isUpdatedAttributeRepeatedInThisEntity","filter","parentModel","parentOptions","id","excludeId","parentContent","whereConditions","isParentDraft","publishedAt","$notNull","locale","Number","isNaN","$ne","queryUid","uid","queryWhere","reduceRight","strapi","db","query","findOne","where","validateUniqueFieldWithinDynamicZoneComponent","startOfPath","targetComponentUID","countOfValueInThisEntity","fullDynamicZoneContent","component","__component","select","populate","on","undefined","published_at","$eq","parentModelQueryResult","findMany","filteredResults","result","Array","isArray","flatMap","dynamicZoneComponent","test","isNil","hasPathToComponent","testingDZ","attributes","scalarAttributeWhere","stringValidator","metas","schema","yup","string","transform","val","originalVal","emailValidator","email","uidValidator","enumerationValidator","oneOf","enum","concat","integerValidator","number","integer","floatValidator","bigintegerValidator","mixed","datesValidator","Validators","text","richtext","password","enumeration","boolean","json","biginteger","float","decimal","date","time","datetime","timestamp","blocks","blocksValidator"],"mappings":";;;;AAqCA;;IAKA,MAAMA,qBAAwB,GAAA,CAC5BC,SACA,EAAA,EACEC,IAAI,EASL,EACD,EAAEC,OAAO,EAAoB,GAAA;AAE7B,IAAA,OAAOD,KAAKE,SAAS,IAAIC,CAAEC,CAAAA,SAAS,CAACJ,IAAKE,CAAAA,SAAS,CAAK,IAAA,CAACD,UACrDF,SAAUM,CAAAA,GAAG,CAACL,IAAAA,CAAKE,SAAS,CAC5BH,GAAAA,SAAAA;AACN,CAAA;AAEA;;;AAGC,IACD,MAAMO,qBAAwB,GAAA,CAC5BP,SACA,EAAA,EACEC,IAAI,EASL,GAAA;AAED,IAAA,OAAOA,IAAKO,CAAAA,SAAS,IAAIJ,CAAAA,CAAEC,SAAS,CAACJ,IAAAA,CAAKO,SAAS,CAAA,GAAIR,SAAUS,CAAAA,GAAG,CAACR,IAAAA,CAAK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