@strapi/core 0.0.0-experimental.f56bca7c4d88bc4c61b6de9f65648d857cf242d9 → 0.0.0-experimental.f600e084b864385e72758f0425ff073b2c4f84ee
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @strapi/core might be problematic. Click here for more details.
- package/dist/Strapi.d.ts.map +1 -1
- package/dist/Strapi.js +2 -0
- package/dist/Strapi.js.map +1 -1
- package/dist/Strapi.mjs +2 -0
- package/dist/Strapi.mjs.map +1 -1
- package/dist/configuration/index.d.ts +1 -0
- package/dist/configuration/index.d.ts.map +1 -1
- package/dist/configuration/index.js +1 -0
- package/dist/configuration/index.js.map +1 -1
- package/dist/configuration/index.mjs +1 -0
- package/dist/configuration/index.mjs.map +1 -1
- package/dist/core-api/routes/index.d.ts +4 -22
- package/dist/core-api/routes/index.d.ts.map +1 -1
- package/dist/core-api/routes/index.js +150 -8
- package/dist/core-api/routes/index.js.map +1 -1
- package/dist/core-api/routes/index.mjs +131 -8
- package/dist/core-api/routes/index.mjs.map +1 -1
- package/dist/core-api/routes/validation/attributes.d.ts +244 -0
- package/dist/core-api/routes/validation/attributes.d.ts.map +1 -0
- package/dist/core-api/routes/validation/attributes.js +560 -0
- package/dist/core-api/routes/validation/attributes.js.map +1 -0
- package/dist/core-api/routes/validation/attributes.mjs +521 -0
- package/dist/core-api/routes/validation/attributes.mjs.map +1 -0
- package/dist/core-api/routes/validation/common.d.ts +105 -0
- package/dist/core-api/routes/validation/common.d.ts.map +1 -0
- package/dist/core-api/routes/validation/common.js +116 -0
- package/dist/core-api/routes/validation/common.js.map +1 -0
- package/dist/core-api/routes/validation/common.mjs +95 -0
- package/dist/core-api/routes/validation/common.mjs.map +1 -0
- package/dist/core-api/routes/validation/component.d.ts +34 -0
- package/dist/core-api/routes/validation/component.d.ts.map +1 -0
- package/dist/core-api/routes/validation/component.js +45 -0
- package/dist/core-api/routes/validation/component.js.map +1 -0
- package/dist/core-api/routes/validation/component.mjs +43 -0
- package/dist/core-api/routes/validation/component.mjs.map +1 -0
- package/dist/core-api/routes/validation/constants.d.ts +8 -0
- package/dist/core-api/routes/validation/constants.d.ts.map +1 -0
- package/dist/core-api/routes/validation/constants.js +18 -0
- package/dist/core-api/routes/validation/constants.js.map +1 -0
- package/dist/core-api/routes/validation/constants.mjs +16 -0
- package/dist/core-api/routes/validation/constants.mjs.map +1 -0
- package/dist/core-api/routes/validation/content-type.d.ts +128 -0
- package/dist/core-api/routes/validation/content-type.d.ts.map +1 -0
- package/dist/core-api/routes/validation/content-type.js +201 -0
- package/dist/core-api/routes/validation/content-type.js.map +1 -0
- package/dist/core-api/routes/validation/content-type.mjs +180 -0
- package/dist/core-api/routes/validation/content-type.mjs.map +1 -0
- package/dist/core-api/routes/validation/index.d.ts +5 -0
- package/dist/core-api/routes/validation/index.d.ts.map +1 -0
- package/dist/core-api/routes/validation/mappers.d.ts +105 -0
- package/dist/core-api/routes/validation/mappers.d.ts.map +1 -0
- package/dist/core-api/routes/validation/mappers.js +238 -0
- package/dist/core-api/routes/validation/mappers.js.map +1 -0
- package/dist/core-api/routes/validation/mappers.mjs +214 -0
- package/dist/core-api/routes/validation/mappers.mjs.map +1 -0
- package/dist/core-api/routes/validation/utils.d.ts +47 -0
- package/dist/core-api/routes/validation/utils.d.ts.map +1 -0
- package/dist/core-api/routes/validation/utils.js +112 -0
- package/dist/core-api/routes/validation/utils.js.map +1 -0
- package/dist/core-api/routes/validation/utils.mjs +90 -0
- package/dist/core-api/routes/validation/utils.mjs.map +1 -0
- package/dist/domain/content-type/index.d.ts.map +1 -1
- package/dist/domain/content-type/index.js +17 -1
- package/dist/domain/content-type/index.js.map +1 -1
- package/dist/domain/content-type/index.mjs +17 -1
- package/dist/domain/content-type/index.mjs.map +1 -1
- package/dist/domain/module/index.d.ts.map +1 -1
- package/dist/domain/module/index.js +3 -0
- package/dist/domain/module/index.js.map +1 -1
- package/dist/domain/module/index.mjs +3 -0
- package/dist/domain/module/index.mjs.map +1 -1
- package/dist/ee/index.d.ts +6 -0
- package/dist/ee/index.d.ts.map +1 -1
- package/dist/ee/index.js +29 -3
- package/dist/ee/index.js.map +1 -1
- package/dist/ee/index.mjs +30 -4
- package/dist/ee/index.mjs.map +1 -1
- package/dist/ee/license.d.ts +3 -1
- package/dist/ee/license.d.ts.map +1 -1
- package/dist/ee/license.js +8 -2
- package/dist/ee/license.js.map +1 -1
- package/dist/ee/license.mjs +9 -4
- package/dist/ee/license.mjs.map +1 -1
- package/dist/factories.d.ts +3 -1
- package/dist/factories.d.ts.map +1 -1
- package/dist/factories.js +10 -2
- package/dist/factories.js.map +1 -1
- package/dist/factories.mjs +10 -3
- package/dist/factories.mjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/middlewares/cors.d.ts +9 -1
- package/dist/middlewares/cors.d.ts.map +1 -1
- package/dist/middlewares/cors.js +39 -17
- package/dist/middlewares/cors.js.map +1 -1
- package/dist/middlewares/cors.mjs +39 -18
- package/dist/middlewares/cors.mjs.map +1 -1
- package/dist/migrations/first-published-at.d.ts +4 -0
- package/dist/migrations/first-published-at.d.ts.map +1 -0
- package/dist/migrations/first-published-at.js +51 -0
- package/dist/migrations/first-published-at.js.map +1 -0
- package/dist/migrations/first-published-at.mjs +49 -0
- package/dist/migrations/first-published-at.mjs.map +1 -0
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/index.js +5 -0
- package/dist/migrations/index.js.map +1 -1
- package/dist/migrations/index.mjs +5 -0
- package/dist/migrations/index.mjs.map +1 -1
- package/dist/package.json.js +17 -14
- package/dist/package.json.js.map +1 -1
- package/dist/package.json.mjs +17 -14
- package/dist/package.json.mjs.map +1 -1
- package/dist/services/core-store.d.ts +2 -2
- package/dist/services/core-store.d.ts.map +1 -1
- package/dist/services/core-store.js.map +1 -1
- package/dist/services/core-store.mjs.map +1 -1
- package/dist/services/document-service/entries.d.ts.map +1 -1
- package/dist/services/document-service/entries.js +42 -0
- package/dist/services/document-service/entries.js.map +1 -1
- package/dist/services/document-service/entries.mjs +43 -1
- package/dist/services/document-service/entries.mjs.map +1 -1
- package/dist/services/document-service/first-published-at.d.ts +7 -0
- package/dist/services/document-service/first-published-at.d.ts.map +1 -0
- package/dist/services/document-service/first-published-at.js +31 -0
- package/dist/services/document-service/first-published-at.js.map +1 -0
- package/dist/services/document-service/first-published-at.mjs +28 -0
- package/dist/services/document-service/first-published-at.mjs.map +1 -0
- package/dist/services/document-service/internationalization.d.ts +6 -1
- package/dist/services/document-service/internationalization.d.ts.map +1 -1
- package/dist/services/document-service/internationalization.js +32 -0
- package/dist/services/document-service/internationalization.js.map +1 -1
- package/dist/services/document-service/internationalization.mjs +32 -1
- package/dist/services/document-service/internationalization.mjs.map +1 -1
- package/dist/services/document-service/repository.d.ts.map +1 -1
- package/dist/services/document-service/repository.js +12 -8
- package/dist/services/document-service/repository.js.map +1 -1
- package/dist/services/document-service/repository.mjs +13 -9
- package/dist/services/document-service/repository.mjs.map +1 -1
- package/dist/services/entity-validator/index.d.ts.map +1 -1
- package/dist/services/entity-validator/index.js +9 -0
- package/dist/services/entity-validator/index.js.map +1 -1
- package/dist/services/entity-validator/index.mjs +9 -0
- package/dist/services/entity-validator/index.mjs.map +1 -1
- package/dist/services/entity-validator/validators.d.ts +1 -0
- package/dist/services/entity-validator/validators.d.ts.map +1 -1
- package/dist/services/entity-validator/validators.js +3 -0
- package/dist/services/entity-validator/validators.js.map +1 -1
- package/dist/services/entity-validator/validators.mjs +3 -0
- package/dist/services/entity-validator/validators.mjs.map +1 -1
- package/dist/services/metrics/admin-user-hash.d.ts.map +1 -1
- package/dist/services/metrics/admin-user-hash.js.map +1 -1
- package/dist/services/metrics/admin-user-hash.mjs.map +1 -1
- package/dist/services/metrics/index.d.ts +1 -1
- package/dist/services/metrics/index.d.ts.map +1 -1
- package/dist/services/metrics/index.js +9 -8
- package/dist/services/metrics/index.js.map +1 -1
- package/dist/services/metrics/index.mjs +9 -8
- package/dist/services/metrics/index.mjs.map +1 -1
- package/dist/services/metrics/sender.d.ts.map +1 -1
- package/dist/services/metrics/sender.js +5 -5
- package/dist/services/metrics/sender.js.map +1 -1
- package/dist/services/metrics/sender.mjs +6 -6
- package/dist/services/metrics/sender.mjs.map +1 -1
- package/dist/services/server/register-routes.js +22 -2
- package/dist/services/server/register-routes.js.map +1 -1
- package/dist/services/server/register-routes.mjs +22 -2
- package/dist/services/server/register-routes.mjs.map +1 -1
- package/dist/services/server/routing.d.ts +10 -0
- package/dist/services/server/routing.d.ts.map +1 -1
- package/dist/services/server/routing.js +7 -1
- package/dist/services/server/routing.js.map +1 -1
- package/dist/services/server/routing.mjs +7 -1
- package/dist/services/server/routing.mjs.map +1 -1
- package/dist/services/utils/conditional-fields.d.ts +3 -0
- package/dist/services/utils/conditional-fields.d.ts.map +1 -0
- package/dist/services/utils/conditional-fields.js +22 -0
- package/dist/services/utils/conditional-fields.js.map +1 -0
- package/dist/services/utils/conditional-fields.mjs +20 -0
- package/dist/services/utils/conditional-fields.mjs.map +1 -0
- package/dist/utils/fetch.d.ts +5 -1
- package/dist/utils/fetch.d.ts.map +1 -1
- package/dist/utils/fetch.js +8 -4
- package/dist/utils/fetch.js.map +1 -1
- package/dist/utils/fetch.mjs +8 -4
- package/dist/utils/fetch.mjs.map +1 -1
- package/dist/utils/transform-content-types-to-models.d.ts +197 -0
- package/dist/utils/transform-content-types-to-models.d.ts.map +1 -1
- package/package.json +17 -14
|
@@ -1 +1 @@
|
|
|
1
|
-
{"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<TAttribute> = Schema.Attribute.Value<TAttribute>,\n> {\n attr: TAttribute;\n model: Struct.Schema;\n updatedAttribute: {\n name: string;\n value: TValue;\n };\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 = <T extends yup.AnySchema>(\n validator: T,\n {\n attr,\n model,\n updatedAttribute,\n entity,\n componentContext,\n }: ValidatorMetas<Schema.Attribute.AnyAttribute & Schema.Attribute.UniqueOption>,\n options: ValidatorOptions\n): T => {\n if (attr.type !== 'uid' && !attr.unique) {\n return validator;\n }\n\n const validateUniqueFieldWithinComponent = async (value: any): Promise<boolean> => {\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<string, any> = {};\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<boolean> => {\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<string, any> = {\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<Schema.Attribute.Email>,\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<Schema.Attribute.UID>,\n options: ValidatorOptions\n) => {\n const schema = stringValidator(metas, options);\n\n if (options.isDraft) {\n return schema;\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<Schema.Attribute.Integer | Schema.Attribute.BigInteger>,\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<Schema.Attribute.Decimal | Schema.Attribute.Float>,\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<Schema.Attribute.BigInteger>,\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":";;;;AAoCA;;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,CAAKO,SAAS,CAAIR,GAAAA,SAAAA;AACzF,CAAA;AAEA;;;AAGC,IACD,MAAMU,sBAAAA,GAAyB,CAC7BV,SAAAA,EACA,EACEC,IAAI,EAGL,EACD,EA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AAA,oBAAAA;IACbgB,OAAS,EAAA,IAAMxB,IAAIwB,OAAO,EAAA;IAC1B9D,GAAK6C,EAAAA,YAAAA;IACLkB,IAAM,EAAA,IAAMzB,IAAIiB,KAAK,EAAA;IACrBH,OAASF,EAAAA,gBAAAA;IACTc,UAAYV,EAAAA,mBAAAA;IACZW,KAAOZ,EAAAA,cAAAA;IACPa,OAASb,EAAAA,cAAAA;IACTc,IAAMX,EAAAA,cAAAA;IACNY,IAAMZ,EAAAA,cAAAA;IACNa,QAAUb,EAAAA,cAAAA;IACVc,SAAWd,EAAAA,cAAAA;IACXe,MAAQC,EAAAA;AACV;;;;"}
|
|
1
|
+
{"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<TAttribute> = Schema.Attribute.Value<TAttribute>,\n> {\n attr: TAttribute;\n model: Struct.Schema;\n updatedAttribute: {\n name: string;\n value: TValue;\n };\n data: Record<string, unknown>;\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 = <T extends yup.AnySchema>(\n validator: T,\n {\n attr,\n model,\n updatedAttribute,\n entity,\n componentContext,\n }: ValidatorMetas<Schema.Attribute.AnyAttribute & Schema.Attribute.UniqueOption>,\n options: ValidatorOptions\n): T => {\n if (attr.type !== 'uid' && !attr.unique) {\n return validator;\n }\n\n const validateUniqueFieldWithinComponent = async (value: any): Promise<boolean> => {\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<string, any> = {};\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<boolean> => {\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<string, any> = {\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<Schema.Attribute.Email>,\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<Schema.Attribute.UID>,\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<Schema.Attribute.Integer | Schema.Attribute.BigInteger>,\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<Schema.Attribute.Decimal | Schema.Attribute.Float>,\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<Schema.Attribute.BigInteger>,\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,CAAKO,SAAS,CAAIR,GAAAA,SAAAA;AACzF,CAAA;AAEA;;;AAGC,IACD,MAAMU,sBAAAA,GAAyB,CAC7BV,SAAAA,EACA,EACEC,IAAI,EAGL,EACD,EAAEC,OAAO,EAAoB,GACzBE,CAAEO,CAAAA,QAAQ,CAACV,IAAAA,CAAKK,GAAG,CAAA,IAAK,CAACJ,OAAAA,GAAUF,SAAUM,CAAAA,GAAG,CAACF,CAAAA,CAAEQ,SAAS,CAACX,IAAKK,CAAAA,GAAG,CAAKN,CAAAA,GAAAA,SAAAA;AAEhF;;IAGA,MAAMa,yBAAyB,CAC7Bb,SAAAA,EACA,EACEC,IAAI,EAGL,GACGG,CAAAA,CAAEO,QAAQ,CAACV,KAAKQ,GAAG,CAAA,GAAIT,UAAUS,GAAG,CAACL,EAAEQ,SAAS,CAACX,IAAKQ,CAAAA,GAAG,CAAKT,CAAAA,GAAAA,SAAAA;AAEpE;;IAGA,MAAMc,oBAAuB,GAAA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,EAAAA,cAAAA;IACNa,QAAUb,EAAAA,cAAAA;IACVc,SAAWd,EAAAA,cAAAA;IACXe,MAAQC,EAAAA;AACV;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"admin-user-hash.d.ts","sourceRoot":"","sources":["../../../src/services/metrics/admin-user-hash.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C;;GAEG;AACH,QAAA,MAAM,qBAAqB,WAAY,KAAK,MAAM,
|
|
1
|
+
{"version":3,"file":"admin-user-hash.d.ts","sourceRoot":"","sources":["../../../src/services/metrics/admin-user-hash.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C;;GAEG;AACH,QAAA,MAAM,qBAAqB,WAAY,KAAK,MAAM,WAOjD,CAAC;AAEF,OAAO,EAAE,qBAAqB,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"admin-user-hash.js","sources":["../../../src/services/metrics/admin-user-hash.ts"],"sourcesContent":["import crypto from 'crypto';\nimport type { Core } from '@strapi/types';\n\n/**\n * Generate an admin user hash\n */\nconst generateAdminUserHash = (strapi: Core.Strapi) => {\n const ctx = strapi?.requestContext?.get();\n if (!ctx?.state?.user?.email) {\n return '';\n }\n return crypto.createHash('sha256').update(ctx.state.user.email).digest('hex');\n};\n\nexport { generateAdminUserHash };\n"],"names":["generateAdminUserHash","strapi","ctx","requestContext","get","state","user","email","crypto","createHash","update","digest"],"mappings":";;;;AAGA;;IAGA,MAAMA,wBAAwB,CAACC,MAAAA,GAAAA;IAC7B,MAAMC,GAAAA,GAAMD,QAAQE,cAAgBC,EAAAA,GAAAA,EAAAA;
|
|
1
|
+
{"version":3,"file":"admin-user-hash.js","sources":["../../../src/services/metrics/admin-user-hash.ts"],"sourcesContent":["import crypto from 'crypto';\nimport type { Core } from '@strapi/types';\n\n/**\n * Generate an admin user hash\n */\nconst generateAdminUserHash = (strapi: Core.Strapi) => {\n const ctx = strapi?.requestContext?.get();\n\n if (!ctx?.state?.user?.email) {\n return '';\n }\n return crypto.createHash('sha256').update(ctx.state.user.email).digest('hex');\n};\n\nexport { generateAdminUserHash };\n"],"names":["generateAdminUserHash","strapi","ctx","requestContext","get","state","user","email","crypto","createHash","update","digest"],"mappings":";;;;AAGA;;IAGA,MAAMA,wBAAwB,CAACC,MAAAA,GAAAA;IAC7B,MAAMC,GAAAA,GAAMD,QAAQE,cAAgBC,EAAAA,GAAAA,EAAAA;AAEpC,IAAA,IAAI,CAACF,GAAAA,EAAKG,KAAOC,EAAAA,IAAAA,EAAMC,KAAO,EAAA;QAC5B,OAAO,EAAA;AACT;AACA,IAAA,OAAOC,MAAOC,CAAAA,UAAU,CAAC,QAAA,CAAA,CAAUC,MAAM,CAACR,GAAAA,CAAIG,KAAK,CAACC,IAAI,CAACC,KAAK,CAAA,CAAEI,MAAM,CAAC,KAAA,CAAA;AACzE;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"admin-user-hash.mjs","sources":["../../../src/services/metrics/admin-user-hash.ts"],"sourcesContent":["import crypto from 'crypto';\nimport type { Core } from '@strapi/types';\n\n/**\n * Generate an admin user hash\n */\nconst generateAdminUserHash = (strapi: Core.Strapi) => {\n const ctx = strapi?.requestContext?.get();\n if (!ctx?.state?.user?.email) {\n return '';\n }\n return crypto.createHash('sha256').update(ctx.state.user.email).digest('hex');\n};\n\nexport { generateAdminUserHash };\n"],"names":["generateAdminUserHash","strapi","ctx","requestContext","get","state","user","email","crypto","createHash","update","digest"],"mappings":";;AAGA;;IAGA,MAAMA,wBAAwB,CAACC,MAAAA,GAAAA;IAC7B,MAAMC,GAAAA,GAAMD,QAAQE,cAAgBC,EAAAA,GAAAA,EAAAA;
|
|
1
|
+
{"version":3,"file":"admin-user-hash.mjs","sources":["../../../src/services/metrics/admin-user-hash.ts"],"sourcesContent":["import crypto from 'crypto';\nimport type { Core } from '@strapi/types';\n\n/**\n * Generate an admin user hash\n */\nconst generateAdminUserHash = (strapi: Core.Strapi) => {\n const ctx = strapi?.requestContext?.get();\n\n if (!ctx?.state?.user?.email) {\n return '';\n }\n return crypto.createHash('sha256').update(ctx.state.user.email).digest('hex');\n};\n\nexport { generateAdminUserHash };\n"],"names":["generateAdminUserHash","strapi","ctx","requestContext","get","state","user","email","crypto","createHash","update","digest"],"mappings":";;AAGA;;IAGA,MAAMA,wBAAwB,CAACC,MAAAA,GAAAA;IAC7B,MAAMC,GAAAA,GAAMD,QAAQE,cAAgBC,EAAAA,GAAAA,EAAAA;AAEpC,IAAA,IAAI,CAACF,GAAAA,EAAKG,KAAOC,EAAAA,IAAAA,EAAMC,KAAO,EAAA;QAC5B,OAAO,EAAA;AACT;AACA,IAAA,OAAOC,MAAOC,CAAAA,UAAU,CAAC,QAAA,CAAA,CAAUC,MAAM,CAACR,GAAAA,CAAIG,KAAK,CAACC,IAAI,CAACC,KAAK,CAAA,CAAEI,MAAM,CAAC,KAAA,CAAA;AACzE;;;;"}
|
|
@@ -7,8 +7,8 @@ declare const createTelemetryInstance: (strapi: Core.Strapi) => {
|
|
|
7
7
|
readonly isDisabled: boolean;
|
|
8
8
|
register(): void;
|
|
9
9
|
bootstrap(): void;
|
|
10
|
-
destroy(): void;
|
|
11
10
|
send(event: string, payload?: Record<string, unknown>): Promise<boolean>;
|
|
11
|
+
destroy(): void;
|
|
12
12
|
};
|
|
13
13
|
export default createTelemetryInstance;
|
|
14
14
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/metrics/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/metrics/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAe1C,QAAA,MAAM,uBAAuB,WAAY,KAAK,MAAM;;;;gBA6B9B,MAAM,YAAW,OAAO,MAAM,EAAE,OAAO,CAAC;;CAS7D,CAAC;AAEF,eAAe,uBAAuB,CAAC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var nodeSchedule = require('node-schedule');
|
|
4
3
|
var rateLimiter = require('./rate-limiter.js');
|
|
5
4
|
var sender = require('./sender.js');
|
|
6
5
|
var middleware = require('./middleware.js');
|
|
@@ -17,7 +16,6 @@ const createTelemetryInstance = (strapi)=>{
|
|
|
17
16
|
const uuid = strapi.config.get('uuid');
|
|
18
17
|
const telemetryDisabled = strapi.config.get('packageJsonStrapi.telemetryDisabled');
|
|
19
18
|
const isDisabled = !uuid || isTruthy(process.env.STRAPI_TELEMETRY_DISABLED) || isTruthy(telemetryDisabled);
|
|
20
|
-
const crons = [];
|
|
21
19
|
const sender$1 = sender(strapi);
|
|
22
20
|
const sendEvent = rateLimiter(sender$1, {
|
|
23
21
|
limitedEvents: LIMITED_EVENTS
|
|
@@ -28,21 +26,24 @@ const createTelemetryInstance = (strapi)=>{
|
|
|
28
26
|
},
|
|
29
27
|
register () {
|
|
30
28
|
if (!isDisabled) {
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
strapi.cron.add({
|
|
30
|
+
sendPingEvent: {
|
|
31
|
+
task: ()=>sendEvent('ping'),
|
|
32
|
+
options: '0 0 12 * * *'
|
|
33
|
+
}
|
|
34
|
+
});
|
|
33
35
|
strapi.server.use(middleware({
|
|
34
36
|
sendEvent
|
|
35
37
|
}));
|
|
36
38
|
}
|
|
37
39
|
},
|
|
38
40
|
bootstrap () {},
|
|
39
|
-
destroy () {
|
|
40
|
-
// Clear open handles
|
|
41
|
-
crons.forEach((cron)=>cron.cancel());
|
|
42
|
-
},
|
|
43
41
|
async send (event, payload = {}) {
|
|
44
42
|
if (isDisabled) return true;
|
|
45
43
|
return sendEvent(event, payload);
|
|
44
|
+
},
|
|
45
|
+
destroy () {
|
|
46
|
+
// Clean up resources if needed
|
|
46
47
|
}
|
|
47
48
|
};
|
|
48
49
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/services/metrics/index.ts"],"sourcesContent":["/**\n * Strapi telemetry package.\n * You can learn more at https://docs.strapi.io/developer-docs/latest/getting-started/usage-information.html\n */\n\nimport
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/services/metrics/index.ts"],"sourcesContent":["/**\n * Strapi telemetry package.\n * You can learn more at https://docs.strapi.io/developer-docs/latest/getting-started/usage-information.html\n */\n\nimport type { Core } from '@strapi/types';\n\nimport wrapWithRateLimit from './rate-limiter';\nimport createSender from './sender';\nimport createMiddleware from './middleware';\nimport isTruthy from './is-truthy';\n\nconst LIMITED_EVENTS = [\n 'didSaveMediaWithAlternativeText',\n 'didSaveMediaWithCaption',\n 'didDisableResponsiveDimensions',\n 'didEnableResponsiveDimensions',\n 'didInitializePluginUpload',\n];\n\nconst createTelemetryInstance = (strapi: Core.Strapi) => {\n const uuid = strapi.config.get('uuid');\n const telemetryDisabled = strapi.config.get('packageJsonStrapi.telemetryDisabled');\n const isDisabled =\n !uuid || isTruthy(process.env.STRAPI_TELEMETRY_DISABLED) || isTruthy(telemetryDisabled);\n\n const sender = createSender(strapi);\n const sendEvent = wrapWithRateLimit(sender, { limitedEvents: LIMITED_EVENTS });\n\n return {\n get isDisabled() {\n return isDisabled;\n },\n\n register() {\n if (!isDisabled) {\n strapi.cron.add({\n sendPingEvent: {\n task: () => sendEvent('ping'),\n options: '0 0 12 * * *',\n },\n });\n\n strapi.server.use(createMiddleware({ sendEvent }));\n }\n },\n\n bootstrap() {},\n\n async send(event: string, payload: Record<string, unknown> = {}) {\n if (isDisabled) return true;\n return sendEvent(event, payload);\n },\n\n destroy() {\n // Clean up resources if needed\n },\n };\n};\n\nexport default createTelemetryInstance;\n"],"names":["LIMITED_EVENTS","createTelemetryInstance","strapi","uuid","config","get","telemetryDisabled","isDisabled","isTruthy","process","env","STRAPI_TELEMETRY_DISABLED","sender","createSender","sendEvent","wrapWithRateLimit","limitedEvents","register","cron","add","sendPingEvent","task","options","server","use","createMiddleware","bootstrap","send","event","payload","destroy"],"mappings":";;;;;;;AAYA,MAAMA,cAAiB,GAAA;AACrB,IAAA,iCAAA;AACA,IAAA,yBAAA;AACA,IAAA,gCAAA;AACA,IAAA,+BAAA;AACA,IAAA;AACD,CAAA;AAED,MAAMC,0BAA0B,CAACC,MAAAA,GAAAA;AAC/B,IAAA,MAAMC,IAAOD,GAAAA,MAAAA,CAAOE,MAAM,CAACC,GAAG,CAAC,MAAA,CAAA;AAC/B,IAAA,MAAMC,iBAAoBJ,GAAAA,MAAAA,CAAOE,MAAM,CAACC,GAAG,CAAC,qCAAA,CAAA;IAC5C,MAAME,UAAAA,GACJ,CAACJ,IAAQK,IAAAA,QAAAA,CAASC,QAAQC,GAAG,CAACC,yBAAyB,CAAA,IAAKH,QAASF,CAAAA,iBAAAA,CAAAA;AAEvE,IAAA,MAAMM,WAASC,MAAaX,CAAAA,MAAAA,CAAAA;IAC5B,MAAMY,SAAAA,GAAYC,YAAkBH,QAAQ,EAAA;QAAEI,aAAehB,EAAAA;AAAe,KAAA,CAAA;IAE5E,OAAO;AACL,QAAA,IAAIO,UAAa,CAAA,GAAA;YACf,OAAOA,UAAAA;AACT,SAAA;AAEAU,QAAAA,QAAAA,CAAAA,GAAAA;AACE,YAAA,IAAI,CAACV,UAAY,EAAA;gBACfL,MAAOgB,CAAAA,IAAI,CAACC,GAAG,CAAC;oBACdC,aAAe,EAAA;AACbC,wBAAAA,IAAAA,EAAM,IAAMP,SAAU,CAAA,MAAA,CAAA;wBACtBQ,OAAS,EAAA;AACX;AACF,iBAAA,CAAA;AAEApB,gBAAAA,MAAAA,CAAOqB,MAAM,CAACC,GAAG,CAACC,UAAiB,CAAA;AAAEX,oBAAAA;AAAU,iBAAA,CAAA,CAAA;AACjD;AACF,SAAA;QAEAY,SAAa,CAAA,GAAA,EAAA;AAEb,QAAA,MAAMC,IAAKC,CAAAA,CAAAA,KAAa,EAAEC,OAAAA,GAAmC,EAAE,EAAA;AAC7D,YAAA,IAAItB,YAAY,OAAO,IAAA;AACvB,YAAA,OAAOO,UAAUc,KAAOC,EAAAA,OAAAA,CAAAA;AAC1B,SAAA;AAEAC,QAAAA,OAAAA,CAAAA,GAAAA;;AAEA;AACF,KAAA;AACF;;;;"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { scheduleJob } from 'node-schedule';
|
|
2
1
|
import wrapWithRateLimit from './rate-limiter.mjs';
|
|
3
2
|
import createSender from './sender.mjs';
|
|
4
3
|
import createMiddleware from './middleware.mjs';
|
|
@@ -15,7 +14,6 @@ const createTelemetryInstance = (strapi)=>{
|
|
|
15
14
|
const uuid = strapi.config.get('uuid');
|
|
16
15
|
const telemetryDisabled = strapi.config.get('packageJsonStrapi.telemetryDisabled');
|
|
17
16
|
const isDisabled = !uuid || isTruthy(process.env.STRAPI_TELEMETRY_DISABLED) || isTruthy(telemetryDisabled);
|
|
18
|
-
const crons = [];
|
|
19
17
|
const sender = createSender(strapi);
|
|
20
18
|
const sendEvent = wrapWithRateLimit(sender, {
|
|
21
19
|
limitedEvents: LIMITED_EVENTS
|
|
@@ -26,21 +24,24 @@ const createTelemetryInstance = (strapi)=>{
|
|
|
26
24
|
},
|
|
27
25
|
register () {
|
|
28
26
|
if (!isDisabled) {
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
strapi.cron.add({
|
|
28
|
+
sendPingEvent: {
|
|
29
|
+
task: ()=>sendEvent('ping'),
|
|
30
|
+
options: '0 0 12 * * *'
|
|
31
|
+
}
|
|
32
|
+
});
|
|
31
33
|
strapi.server.use(createMiddleware({
|
|
32
34
|
sendEvent
|
|
33
35
|
}));
|
|
34
36
|
}
|
|
35
37
|
},
|
|
36
38
|
bootstrap () {},
|
|
37
|
-
destroy () {
|
|
38
|
-
// Clear open handles
|
|
39
|
-
crons.forEach((cron)=>cron.cancel());
|
|
40
|
-
},
|
|
41
39
|
async send (event, payload = {}) {
|
|
42
40
|
if (isDisabled) return true;
|
|
43
41
|
return sendEvent(event, payload);
|
|
42
|
+
},
|
|
43
|
+
destroy () {
|
|
44
|
+
// Clean up resources if needed
|
|
44
45
|
}
|
|
45
46
|
};
|
|
46
47
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../src/services/metrics/index.ts"],"sourcesContent":["/**\n * Strapi telemetry package.\n * You can learn more at https://docs.strapi.io/developer-docs/latest/getting-started/usage-information.html\n */\n\nimport
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../src/services/metrics/index.ts"],"sourcesContent":["/**\n * Strapi telemetry package.\n * You can learn more at https://docs.strapi.io/developer-docs/latest/getting-started/usage-information.html\n */\n\nimport type { Core } from '@strapi/types';\n\nimport wrapWithRateLimit from './rate-limiter';\nimport createSender from './sender';\nimport createMiddleware from './middleware';\nimport isTruthy from './is-truthy';\n\nconst LIMITED_EVENTS = [\n 'didSaveMediaWithAlternativeText',\n 'didSaveMediaWithCaption',\n 'didDisableResponsiveDimensions',\n 'didEnableResponsiveDimensions',\n 'didInitializePluginUpload',\n];\n\nconst createTelemetryInstance = (strapi: Core.Strapi) => {\n const uuid = strapi.config.get('uuid');\n const telemetryDisabled = strapi.config.get('packageJsonStrapi.telemetryDisabled');\n const isDisabled =\n !uuid || isTruthy(process.env.STRAPI_TELEMETRY_DISABLED) || isTruthy(telemetryDisabled);\n\n const sender = createSender(strapi);\n const sendEvent = wrapWithRateLimit(sender, { limitedEvents: LIMITED_EVENTS });\n\n return {\n get isDisabled() {\n return isDisabled;\n },\n\n register() {\n if (!isDisabled) {\n strapi.cron.add({\n sendPingEvent: {\n task: () => sendEvent('ping'),\n options: '0 0 12 * * *',\n },\n });\n\n strapi.server.use(createMiddleware({ sendEvent }));\n }\n },\n\n bootstrap() {},\n\n async send(event: string, payload: Record<string, unknown> = {}) {\n if (isDisabled) return true;\n return sendEvent(event, payload);\n },\n\n destroy() {\n // Clean up resources if needed\n },\n };\n};\n\nexport default createTelemetryInstance;\n"],"names":["LIMITED_EVENTS","createTelemetryInstance","strapi","uuid","config","get","telemetryDisabled","isDisabled","isTruthy","process","env","STRAPI_TELEMETRY_DISABLED","sender","createSender","sendEvent","wrapWithRateLimit","limitedEvents","register","cron","add","sendPingEvent","task","options","server","use","createMiddleware","bootstrap","send","event","payload","destroy"],"mappings":";;;;;AAYA,MAAMA,cAAiB,GAAA;AACrB,IAAA,iCAAA;AACA,IAAA,yBAAA;AACA,IAAA,gCAAA;AACA,IAAA,+BAAA;AACA,IAAA;AACD,CAAA;AAED,MAAMC,0BAA0B,CAACC,MAAAA,GAAAA;AAC/B,IAAA,MAAMC,IAAOD,GAAAA,MAAAA,CAAOE,MAAM,CAACC,GAAG,CAAC,MAAA,CAAA;AAC/B,IAAA,MAAMC,iBAAoBJ,GAAAA,MAAAA,CAAOE,MAAM,CAACC,GAAG,CAAC,qCAAA,CAAA;IAC5C,MAAME,UAAAA,GACJ,CAACJ,IAAQK,IAAAA,QAAAA,CAASC,QAAQC,GAAG,CAACC,yBAAyB,CAAA,IAAKH,QAASF,CAAAA,iBAAAA,CAAAA;AAEvE,IAAA,MAAMM,SAASC,YAAaX,CAAAA,MAAAA,CAAAA;IAC5B,MAAMY,SAAAA,GAAYC,kBAAkBH,MAAQ,EAAA;QAAEI,aAAehB,EAAAA;AAAe,KAAA,CAAA;IAE5E,OAAO;AACL,QAAA,IAAIO,UAAa,CAAA,GAAA;YACf,OAAOA,UAAAA;AACT,SAAA;AAEAU,QAAAA,QAAAA,CAAAA,GAAAA;AACE,YAAA,IAAI,CAACV,UAAY,EAAA;gBACfL,MAAOgB,CAAAA,IAAI,CAACC,GAAG,CAAC;oBACdC,aAAe,EAAA;AACbC,wBAAAA,IAAAA,EAAM,IAAMP,SAAU,CAAA,MAAA,CAAA;wBACtBQ,OAAS,EAAA;AACX;AACF,iBAAA,CAAA;AAEApB,gBAAAA,MAAAA,CAAOqB,MAAM,CAACC,GAAG,CAACC,gBAAiB,CAAA;AAAEX,oBAAAA;AAAU,iBAAA,CAAA,CAAA;AACjD;AACF,SAAA;QAEAY,SAAa,CAAA,GAAA,EAAA;AAEb,QAAA,MAAMC,IAAKC,CAAAA,CAAAA,KAAa,EAAEC,OAAAA,GAAmC,EAAE,EAAA;AAC7D,YAAA,IAAItB,YAAY,OAAO,IAAA;AACvB,YAAA,OAAOO,UAAUc,KAAOC,EAAAA,OAAAA,CAAAA;AAC1B,SAAA;AAEAC,QAAAA,OAAAA,CAAAA,GAAAA;;AAEA;AACF,KAAA;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sender.d.ts","sourceRoot":"","sources":["../../../src/services/metrics/sender.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAG1C,MAAM,WAAW,OAAO;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1C,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC3C;AAED,MAAM,MAAM,MAAM,GAAG,CACnB,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,OAAO,EACjB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC3B,OAAO,CAAC,OAAO,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"sender.d.ts","sourceRoot":"","sources":["../../../src/services/metrics/sender.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAG1C,MAAM,WAAW,OAAO;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1C,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC3C;AAED,MAAM,MAAM,MAAM,GAAG,CACnB,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,OAAO,EACjB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC3B,OAAO,CAAC,OAAO,CAAC,CAAC;AAgBtB;;GAEG;iCACqB,KAAK,MAAM,KAAG,MAAM;AAA5C,wBAyDE"}
|
|
@@ -15,7 +15,6 @@ const defaultQueryOpts = {
|
|
|
15
15
|
'Content-Type': 'application/json'
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
|
-
const ANALYTICS_URI = 'https://analytics.strapi.io';
|
|
19
18
|
/**
|
|
20
19
|
* Add properties from the package.json strapi key in the metadata
|
|
21
20
|
*/ const addPackageJsonStrapiMetadata = (metadata, strapi)=>{
|
|
@@ -25,8 +24,8 @@ const ANALYTICS_URI = 'https://analytics.strapi.io';
|
|
|
25
24
|
/**
|
|
26
25
|
* Create a send function for event with all the necessary metadata
|
|
27
26
|
*/ var createSender = ((strapi)=>{
|
|
28
|
-
const { uuid } = strapi.config;
|
|
29
|
-
const
|
|
27
|
+
const { uuid, installId: installIdFromPackageJson } = strapi.config;
|
|
28
|
+
const installId = strapiUtils.generateInstallId(uuid, installIdFromPackageJson);
|
|
30
29
|
const serverRootPath = strapi.dirs.app.root;
|
|
31
30
|
const adminRootPath = path.join(strapi.dirs.app.root, 'src', 'admin');
|
|
32
31
|
const anonymousUserProperties = {
|
|
@@ -54,7 +53,7 @@ const ANALYTICS_URI = 'https://analytics.strapi.io';
|
|
|
54
53
|
body: JSON.stringify({
|
|
55
54
|
event,
|
|
56
55
|
userId,
|
|
57
|
-
|
|
56
|
+
installId,
|
|
58
57
|
eventProperties: payload.eventProperties,
|
|
59
58
|
userProperties: userId ? {
|
|
60
59
|
...anonymousUserProperties,
|
|
@@ -73,7 +72,8 @@ const ANALYTICS_URI = 'https://analytics.strapi.io';
|
|
|
73
72
|
}, defaultQueryOpts, opts)
|
|
74
73
|
};
|
|
75
74
|
try {
|
|
76
|
-
const
|
|
75
|
+
const analyticsUrl = strapiUtils.env('STRAPI_ANALYTICS_URL', 'https://analytics.strapi.io');
|
|
76
|
+
const res = await strapi.fetch(`${analyticsUrl}/api/v2/track`, reqParams);
|
|
77
77
|
return res.ok;
|
|
78
78
|
} catch (err) {
|
|
79
79
|
return false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sender.js","sources":["../../../src/services/metrics/sender.ts"],"sourcesContent":["import os from 'os';\nimport path from 'path';\nimport _ from 'lodash';\nimport isDocker from 'is-docker';\nimport ciEnv from 'ci-info';\nimport tsUtils from '@strapi/typescript-utils';\nimport { env,
|
|
1
|
+
{"version":3,"file":"sender.js","sources":["../../../src/services/metrics/sender.ts"],"sourcesContent":["import os from 'os';\nimport path from 'path';\nimport _ from 'lodash';\nimport isDocker from 'is-docker';\nimport ciEnv from 'ci-info';\nimport tsUtils from '@strapi/typescript-utils';\nimport { env, generateInstallId } from '@strapi/utils';\nimport type { Core } from '@strapi/types';\nimport { generateAdminUserHash } from './admin-user-hash';\n\nexport interface Payload {\n eventProperties?: Record<string, unknown>;\n userProperties?: Record<string, unknown>;\n groupProperties?: Record<string, unknown>;\n}\n\nexport type Sender = (\n event: string,\n payload?: Payload,\n opts?: Record<string, unknown>\n) => Promise<boolean>;\n\nconst defaultQueryOpts = {\n timeout: 1000,\n headers: { 'Content-Type': 'application/json' },\n};\n\n/**\n * Add properties from the package.json strapi key in the metadata\n */\nconst addPackageJsonStrapiMetadata = (metadata: Record<string, unknown>, strapi: Core.Strapi) => {\n const { packageJsonStrapi = {} } = strapi.config;\n\n _.defaults(metadata, packageJsonStrapi);\n};\n\n/**\n * Create a send function for event with all the necessary metadata\n */\nexport default (strapi: Core.Strapi): Sender => {\n const { uuid, installId: installIdFromPackageJson } = strapi.config;\n\n const installId = generateInstallId(uuid, installIdFromPackageJson);\n\n const serverRootPath = strapi.dirs.app.root;\n const adminRootPath = path.join(strapi.dirs.app.root, 'src', 'admin');\n\n const anonymousUserProperties = {\n environment: strapi.config.environment,\n os: os.type(),\n osPlatform: os.platform(),\n osArch: os.arch(),\n osRelease: os.release(),\n nodeVersion: process.versions.node,\n };\n\n const anonymousGroupProperties = {\n docker: process.env.DOCKER || isDocker(),\n isCI: ciEnv.isCI,\n version: strapi.config.get('info.strapi'),\n useTypescriptOnServer: tsUtils.isUsingTypeScriptSync(serverRootPath),\n useTypescriptOnAdmin: tsUtils.isUsingTypeScriptSync(adminRootPath),\n projectId: uuid,\n isHostedOnStrapiCloud: env('STRAPI_HOSTING', null) === 'strapi.cloud',\n };\n\n addPackageJsonStrapiMetadata(anonymousGroupProperties, strapi);\n\n return async (event: string, payload: Payload = {}, opts = {}) => {\n const userId = generateAdminUserHash(strapi);\n\n const reqParams = {\n method: 'POST',\n body: JSON.stringify({\n event,\n userId,\n installId,\n eventProperties: payload.eventProperties,\n userProperties: userId ? { ...anonymousUserProperties, ...payload.userProperties } : {},\n groupProperties: {\n ...anonymousGroupProperties,\n projectType: strapi.EE ? 'Enterprise' : 'Community',\n ...payload.groupProperties,\n },\n }),\n ..._.merge({ headers: { 'X-Strapi-Event': event } }, defaultQueryOpts, opts),\n };\n\n try {\n const analyticsUrl = env('STRAPI_ANALYTICS_URL', 'https://analytics.strapi.io');\n const res = await strapi.fetch(`${analyticsUrl}/api/v2/track`, reqParams);\n return res.ok;\n } catch (err) {\n return false;\n }\n };\n};\n"],"names":["defaultQueryOpts","timeout","headers","addPackageJsonStrapiMetadata","metadata","strapi","packageJsonStrapi","config","_","defaults","uuid","installId","installIdFromPackageJson","generateInstallId","serverRootPath","dirs","app","root","adminRootPath","path","join","anonymousUserProperties","environment","os","type","osPlatform","platform","osArch","arch","osRelease","release","nodeVersion","process","versions","node","anonymousGroupProperties","docker","env","DOCKER","isDocker","isCI","ciEnv","version","get","useTypescriptOnServer","tsUtils","isUsingTypeScriptSync","useTypescriptOnAdmin","projectId","isHostedOnStrapiCloud","event","payload","opts","userId","generateAdminUserHash","reqParams","method","body","JSON","stringify","eventProperties","userProperties","groupProperties","projectType","EE","merge","analyticsUrl","res","fetch","ok","err"],"mappings":";;;;;;;;;;;AAsBA,MAAMA,gBAAmB,GAAA;IACvBC,OAAS,EAAA,IAAA;IACTC,OAAS,EAAA;QAAE,cAAgB,EAAA;AAAmB;AAChD,CAAA;AAEA;;IAGA,MAAMC,4BAA+B,GAAA,CAACC,QAAmCC,EAAAA,MAAAA,GAAAA;AACvE,IAAA,MAAM,EAAEC,iBAAoB,GAAA,EAAE,EAAE,GAAGD,OAAOE,MAAM;IAEhDC,CAAEC,CAAAA,QAAQ,CAACL,QAAUE,EAAAA,iBAAAA,CAAAA;AACvB,CAAA;AAEA;;IAGA,mBAAe,CAAA,CAACD,MAAAA,GAAAA;IACd,MAAM,EAAEK,IAAI,EAAEC,SAAAA,EAAWC,wBAAwB,EAAE,GAAGP,OAAOE,MAAM;IAEnE,MAAMI,SAAAA,GAAYE,8BAAkBH,IAAME,EAAAA,wBAAAA,CAAAA;AAE1C,IAAA,MAAME,iBAAiBT,MAAOU,CAAAA,IAAI,CAACC,GAAG,CAACC,IAAI;IAC3C,MAAMC,aAAAA,GAAgBC,IAAKC,CAAAA,IAAI,CAACf,MAAAA,CAAOU,IAAI,CAACC,GAAG,CAACC,IAAI,EAAE,KAAO,EAAA,OAAA,CAAA;AAE7D,IAAA,MAAMI,uBAA0B,GAAA;QAC9BC,WAAajB,EAAAA,MAAAA,CAAOE,MAAM,CAACe,WAAW;AACtCC,QAAAA,EAAAA,EAAIA,GAAGC,IAAI,EAAA;AACXC,QAAAA,UAAAA,EAAYF,GAAGG,QAAQ,EAAA;AACvBC,QAAAA,MAAAA,EAAQJ,GAAGK,IA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AAAA,MAAAA,CAAO2D,EAAE,GAAG,YAAe,GAAA,WAAA;AACxC,oBAAA,GAAGb,QAAQW;AACb;AACF,aAAA,CAAA;YACA,GAAGtD,CAAAA,CAAEyD,KAAK,CAAC;gBAAE/D,OAAS,EAAA;oBAAE,gBAAkBgD,EAAAA;AAAM;AAAE,aAAA,EAAGlD,kBAAkBoD,IAAK;AAC9E,SAAA;QAEA,IAAI;YACF,MAAMc,YAAAA,GAAe7B,gBAAI,sBAAwB,EAAA,6BAAA,CAAA;YACjD,MAAM8B,GAAAA,GAAM,MAAM9D,MAAAA,CAAO+D,KAAK,CAAC,CAAC,EAAEF,YAAAA,CAAa,aAAa,CAAC,EAAEX,SAAAA,CAAAA;AAC/D,YAAA,OAAOY,IAAIE,EAAE;AACf,SAAA,CAAE,OAAOC,GAAK,EAAA;YACZ,OAAO,KAAA;AACT;AACF,KAAA;AACF,CAAA;;;;"}
|
|
@@ -4,7 +4,7 @@ import _ from 'lodash';
|
|
|
4
4
|
import isDocker from 'is-docker';
|
|
5
5
|
import ciEnv from 'ci-info';
|
|
6
6
|
import tsUtils from '@strapi/typescript-utils';
|
|
7
|
-
import {
|
|
7
|
+
import { generateInstallId, env } from '@strapi/utils';
|
|
8
8
|
import { generateAdminUserHash } from './admin-user-hash.mjs';
|
|
9
9
|
|
|
10
10
|
const defaultQueryOpts = {
|
|
@@ -13,7 +13,6 @@ const defaultQueryOpts = {
|
|
|
13
13
|
'Content-Type': 'application/json'
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
|
-
const ANALYTICS_URI = 'https://analytics.strapi.io';
|
|
17
16
|
/**
|
|
18
17
|
* Add properties from the package.json strapi key in the metadata
|
|
19
18
|
*/ const addPackageJsonStrapiMetadata = (metadata, strapi)=>{
|
|
@@ -23,8 +22,8 @@ const ANALYTICS_URI = 'https://analytics.strapi.io';
|
|
|
23
22
|
/**
|
|
24
23
|
* Create a send function for event with all the necessary metadata
|
|
25
24
|
*/ var createSender = ((strapi)=>{
|
|
26
|
-
const { uuid } = strapi.config;
|
|
27
|
-
const
|
|
25
|
+
const { uuid, installId: installIdFromPackageJson } = strapi.config;
|
|
26
|
+
const installId = generateInstallId(uuid, installIdFromPackageJson);
|
|
28
27
|
const serverRootPath = strapi.dirs.app.root;
|
|
29
28
|
const adminRootPath = path.join(strapi.dirs.app.root, 'src', 'admin');
|
|
30
29
|
const anonymousUserProperties = {
|
|
@@ -52,7 +51,7 @@ const ANALYTICS_URI = 'https://analytics.strapi.io';
|
|
|
52
51
|
body: JSON.stringify({
|
|
53
52
|
event,
|
|
54
53
|
userId,
|
|
55
|
-
|
|
54
|
+
installId,
|
|
56
55
|
eventProperties: payload.eventProperties,
|
|
57
56
|
userProperties: userId ? {
|
|
58
57
|
...anonymousUserProperties,
|
|
@@ -71,7 +70,8 @@ const ANALYTICS_URI = 'https://analytics.strapi.io';
|
|
|
71
70
|
}, defaultQueryOpts, opts)
|
|
72
71
|
};
|
|
73
72
|
try {
|
|
74
|
-
const
|
|
73
|
+
const analyticsUrl = env('STRAPI_ANALYTICS_URL', 'https://analytics.strapi.io');
|
|
74
|
+
const res = await strapi.fetch(`${analyticsUrl}/api/v2/track`, reqParams);
|
|
75
75
|
return res.ok;
|
|
76
76
|
} catch (err) {
|
|
77
77
|
return false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sender.mjs","sources":["../../../src/services/metrics/sender.ts"],"sourcesContent":["import os from 'os';\nimport path from 'path';\nimport _ from 'lodash';\nimport isDocker from 'is-docker';\nimport ciEnv from 'ci-info';\nimport tsUtils from '@strapi/typescript-utils';\nimport { env,
|
|
1
|
+
{"version":3,"file":"sender.mjs","sources":["../../../src/services/metrics/sender.ts"],"sourcesContent":["import os from 'os';\nimport path from 'path';\nimport _ from 'lodash';\nimport isDocker from 'is-docker';\nimport ciEnv from 'ci-info';\nimport tsUtils from '@strapi/typescript-utils';\nimport { env, generateInstallId } from '@strapi/utils';\nimport type { Core } from '@strapi/types';\nimport { generateAdminUserHash } from './admin-user-hash';\n\nexport interface Payload {\n eventProperties?: Record<string, unknown>;\n userProperties?: Record<string, unknown>;\n groupProperties?: Record<string, unknown>;\n}\n\nexport type Sender = (\n event: string,\n payload?: Payload,\n opts?: Record<string, unknown>\n) => Promise<boolean>;\n\nconst defaultQueryOpts = {\n timeout: 1000,\n headers: { 'Content-Type': 'application/json' },\n};\n\n/**\n * Add properties from the package.json strapi key in the metadata\n */\nconst addPackageJsonStrapiMetadata = (metadata: Record<string, unknown>, strapi: Core.Strapi) => {\n const { packageJsonStrapi = {} } = strapi.config;\n\n _.defaults(metadata, packageJsonStrapi);\n};\n\n/**\n * Create a send function for event with all the necessary metadata\n */\nexport default (strapi: Core.Strapi): Sender => {\n const { uuid, installId: installIdFromPackageJson } = strapi.config;\n\n const installId = generateInstallId(uuid, installIdFromPackageJson);\n\n const serverRootPath = strapi.dirs.app.root;\n const adminRootPath = path.join(strapi.dirs.app.root, 'src', 'admin');\n\n const anonymousUserProperties = {\n environment: strapi.config.environment,\n os: os.type(),\n osPlatform: os.platform(),\n osArch: os.arch(),\n osRelease: os.release(),\n nodeVersion: process.versions.node,\n };\n\n const anonymousGroupProperties = {\n docker: process.env.DOCKER || isDocker(),\n isCI: ciEnv.isCI,\n version: strapi.config.get('info.strapi'),\n useTypescriptOnServer: tsUtils.isUsingTypeScriptSync(serverRootPath),\n useTypescriptOnAdmin: tsUtils.isUsingTypeScriptSync(adminRootPath),\n projectId: uuid,\n isHostedOnStrapiCloud: env('STRAPI_HOSTING', null) === 'strapi.cloud',\n };\n\n addPackageJsonStrapiMetadata(anonymousGroupProperties, strapi);\n\n return async (event: string, payload: Payload = {}, opts = {}) => {\n const userId = generateAdminUserHash(strapi);\n\n const reqParams = {\n method: 'POST',\n body: JSON.stringify({\n event,\n userId,\n installId,\n eventProperties: payload.eventProperties,\n userProperties: userId ? { ...anonymousUserProperties, ...payload.userProperties } : {},\n groupProperties: {\n ...anonymousGroupProperties,\n projectType: strapi.EE ? 'Enterprise' : 'Community',\n ...payload.groupProperties,\n },\n }),\n ..._.merge({ headers: { 'X-Strapi-Event': event } }, defaultQueryOpts, opts),\n };\n\n try {\n const analyticsUrl = env('STRAPI_ANALYTICS_URL', 'https://analytics.strapi.io');\n const res = await strapi.fetch(`${analyticsUrl}/api/v2/track`, reqParams);\n return res.ok;\n } catch (err) {\n return false;\n }\n };\n};\n"],"names":["defaultQueryOpts","timeout","headers","addPackageJsonStrapiMetadata","metadata","strapi","packageJsonStrapi","config","_","defaults","uuid","installId","installIdFromPackageJson","generateInstallId","serverRootPath","dirs","app","root","adminRootPath","path","join","anonymousUserProperties","environment","os","type","osPlatform","platform","osArch","arch","osRelease","release","nodeVersion","process","versions","node","anonymousGroupProperties","docker","env","DOCKER","isDocker","isCI","ciEnv","version","get","useTypescriptOnServer","tsUtils","isUsingTypeScriptSync","useTypescriptOnAdmin","projectId","isHostedOnStrapiCloud","event","payload","opts","userId","generateAdminUserHash","reqParams","method","body","JSON","stringify","eventProperties","userProperties","groupProperties","projectType","EE","merge","analyticsUrl","res","fetch","ok","err"],"mappings":";;;;;;;;;AAsBA,MAAMA,gBAAmB,GAAA;IACvBC,OAAS,EAAA,IAAA;IACTC,OAAS,EAAA;QAAE,cAAgB,EAAA;AAAmB;AAChD,CAAA;AAEA;;IAGA,MAAMC,4BAA+B,GAAA,CAACC,QAAmCC,EAAAA,MAAAA,GAAAA;AACvE,IAAA,MAAM,EAAEC,iBAAoB,GAAA,EAAE,EAAE,GAAGD,OAAOE,MAAM;IAEhDC,CAAEC,CAAAA,QAAQ,CAACL,QAAUE,EAAAA,iBAAAA,CAAAA;AACvB,CAAA;AAEA;;IAGA,mBAAe,CAAA,CAACD,MAAAA,GAAAA;IACd,MAAM,EAAEK,IAAI,EAAEC,SAAAA,EAAWC,wBAAwB,EAAE,GAAGP,OAAOE,MAAM;IAEnE,MAAMI,SAAAA,GAAYE,kBAAkBH,IAAME,EAAAA,wBAAAA,CAAAA;AAE1C,IAAA,MAAME,iBA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AA,MAAMkD,SAAY,GAAA;YAChBC,MAAQ,EAAA,MAAA;YACRC,IAAMC,EAAAA,IAAAA,CAAKC,SAAS,CAAC;AACnBT,gBAAAA,KAAAA;AACAG,gBAAAA,MAAAA;AACA1C,gBAAAA,SAAAA;AACAiD,gBAAAA,eAAAA,EAAiBT,QAAQS,eAAe;AACxCC,gBAAAA,cAAAA,EAAgBR,MAAS,GAAA;AAAE,oBAAA,GAAGhC,uBAAuB;AAAE,oBAAA,GAAG8B,QAAQU;AAAe,iBAAA,GAAI,EAAC;gBACtFC,eAAiB,EAAA;AACf,oBAAA,GAAG3B,wBAAwB;oBAC3B4B,WAAa1D,EAAAA,MAAAA,CAAO2D,EAAE,GAAG,YAAe,GAAA,WAAA;AACxC,oBAAA,GAAGb,QAAQW;AACb;AACF,aAAA,CAAA;YACA,GAAGtD,CAAAA,CAAEyD,KAAK,CAAC;gBAAE/D,OAAS,EAAA;oBAAE,gBAAkBgD,EAAAA;AAAM;AAAE,aAAA,EAAGlD,kBAAkBoD,IAAK;AAC9E,SAAA;QAEA,IAAI;YACF,MAAMc,YAAAA,GAAe7B,IAAI,sBAAwB,EAAA,6BAAA,CAAA;YACjD,MAAM8B,GAAAA,GAAM,MAAM9D,MAAAA,CAAO+D,KAAK,CAAC,CAAC,EAAEF,YAAAA,CAAa,aAAa,CAAC,EAAEX,SAAAA,CAAAA;AAC/D,YAAA,OAAOY,IAAIE,EAAE;AACf,SAAA,CAAE,OAAOC,GAAK,EAAA;YACZ,OAAO,KAAA;AACT;AACF,KAAA;AACF,CAAA;;;;"}
|
|
@@ -28,6 +28,9 @@ const createRouteScopeGenerator = (namespace)=>(route)=>{
|
|
|
28
28
|
* @param {import('../../').Strapi} strapi
|
|
29
29
|
*/ const registerAdminRoutes = (strapi)=>{
|
|
30
30
|
const generateRouteScope = createRouteScopeGenerator(`admin::`);
|
|
31
|
+
// Instantiate function-like routers
|
|
32
|
+
// Mutate admin.routes in-place and make sure router factories are instantiated correctly
|
|
33
|
+
strapi.admin.routes = instantiateRouterInputs(strapi.admin.routes, strapi);
|
|
31
34
|
_.forEach(strapi.admin.routes, (router)=>{
|
|
32
35
|
router.type = router.type || 'admin';
|
|
33
36
|
router.prefix = router.prefix || `/admin`;
|
|
@@ -60,9 +63,12 @@ const createRouteScopeGenerator = (namespace)=>(route)=>{
|
|
|
60
63
|
routes: plugin.routes
|
|
61
64
|
});
|
|
62
65
|
} else {
|
|
66
|
+
// Instantiate function-like routers
|
|
67
|
+
// Mutate plugin.routes in-place and make sure router factories are instantiated correctly
|
|
68
|
+
plugin.routes = instantiateRouterInputs(plugin.routes, strapi);
|
|
63
69
|
_.forEach(plugin.routes, (router)=>{
|
|
64
|
-
router.type = router.type
|
|
65
|
-
router.prefix = router.prefix
|
|
70
|
+
router.type = router.type ?? 'admin';
|
|
71
|
+
router.prefix = router.prefix ?? `/${pluginName}`;
|
|
66
72
|
router.routes.forEach((route)=>{
|
|
67
73
|
generateRouteScope(route);
|
|
68
74
|
route.info = {
|
|
@@ -80,6 +86,8 @@ const createRouteScopeGenerator = (namespace)=>(route)=>{
|
|
|
80
86
|
for (const apiName of Object.keys(strapi.apis)){
|
|
81
87
|
const api = strapi.api(apiName);
|
|
82
88
|
const generateRouteScope = createRouteScopeGenerator(`api::${apiName}`);
|
|
89
|
+
// Mutate api.routes in-place and make sure router factories are instantiated correctly
|
|
90
|
+
api.routes = instantiateRouterInputs(api.routes, strapi);
|
|
83
91
|
_.forEach(api.routes, (router)=>{
|
|
84
92
|
// TODO: remove once auth setup
|
|
85
93
|
// pass meta down to compose endpoint
|
|
@@ -94,6 +102,18 @@ const createRouteScopeGenerator = (namespace)=>(route)=>{
|
|
|
94
102
|
});
|
|
95
103
|
}
|
|
96
104
|
};
|
|
105
|
+
const instantiateRouterInputs = (routers, strapi)=>{
|
|
106
|
+
const entries = Object.entries(routers);
|
|
107
|
+
return entries.reduce((record, [key, inputOrCallback])=>{
|
|
108
|
+
const isCallback = typeof inputOrCallback === 'function';
|
|
109
|
+
return {
|
|
110
|
+
...record,
|
|
111
|
+
[key]: isCallback ? inputOrCallback({
|
|
112
|
+
strapi
|
|
113
|
+
}) : inputOrCallback
|
|
114
|
+
};
|
|
115
|
+
}, {});
|
|
116
|
+
};
|
|
97
117
|
|
|
98
118
|
module.exports = registerAllRoutes;
|
|
99
119
|
//# sourceMappingURL=register-routes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-routes.js","sources":["../../../src/services/server/register-routes.ts"],"sourcesContent":["import _ from 'lodash';\nimport type { Core } from '@strapi/types';\n\nconst createRouteScopeGenerator = (namespace: string) => (route: Core.RouteInput) => {\n const prefix = namespace.endsWith('::') ? namespace : `${namespace}.`;\n\n if (typeof route.handler === 'string') {\n _.defaultsDeep(route, {\n config: {\n auth: {\n scope: [`${route.handler.startsWith(prefix) ? '' : prefix}${route.handler}`],\n },\n },\n });\n }\n};\n\n/**\n * Register all routes\n */\nexport default (strapi: Core.Strapi) => {\n registerAdminRoutes(strapi);\n registerAPIRoutes(strapi);\n registerPluginRoutes(strapi);\n};\n\n/**\n * Register admin routes\n * @param {import('../../').Strapi} strapi\n */\nconst registerAdminRoutes = (strapi: Core.Strapi) => {\n const generateRouteScope = createRouteScopeGenerator(`admin::`);\n\n _.forEach(strapi.admin.routes, (router) => {\n router.type = router.type || 'admin';\n router.prefix = router.prefix || `/admin`;\n router.routes.forEach((route) => {\n generateRouteScope(route);\n route.info = { pluginName: 'admin' };\n });\n strapi.server.routes(router);\n });\n};\n\n/**\n * Register plugin routes\n * @param {import('../../').Strapi} strapi\n */\nconst registerPluginRoutes = (strapi: Core.Strapi) => {\n for (const pluginName of Object.keys(strapi.plugins)) {\n const plugin = strapi.plugins[pluginName];\n\n const generateRouteScope = createRouteScopeGenerator(`plugin::${pluginName}`);\n\n if (Array.isArray(plugin.routes)) {\n plugin.routes.forEach((route) => {\n generateRouteScope(route);\n route.info = { pluginName };\n });\n\n strapi.server.routes({\n type: 'admin',\n prefix: `/${pluginName}`,\n routes: plugin.routes,\n });\n } else {\n _.forEach(plugin.routes, (router) => {\n router.type = router.type
|
|
1
|
+
{"version":3,"file":"register-routes.js","sources":["../../../src/services/server/register-routes.ts"],"sourcesContent":["import _ from 'lodash';\nimport type { Core } from '@strapi/types';\n\nconst createRouteScopeGenerator = (namespace: string) => (route: Core.RouteInput) => {\n const prefix = namespace.endsWith('::') ? namespace : `${namespace}.`;\n\n if (typeof route.handler === 'string') {\n _.defaultsDeep(route, {\n config: {\n auth: {\n scope: [`${route.handler.startsWith(prefix) ? '' : prefix}${route.handler}`],\n },\n },\n });\n }\n};\n\n/**\n * Register all routes\n */\nexport default (strapi: Core.Strapi) => {\n registerAdminRoutes(strapi);\n registerAPIRoutes(strapi);\n registerPluginRoutes(strapi);\n};\n\n/**\n * Register admin routes\n * @param {import('../../').Strapi} strapi\n */\nconst registerAdminRoutes = (strapi: Core.Strapi) => {\n const generateRouteScope = createRouteScopeGenerator(`admin::`);\n\n // Instantiate function-like routers\n // Mutate admin.routes in-place and make sure router factories are instantiated correctly\n strapi.admin.routes = instantiateRouterInputs(strapi.admin.routes, strapi);\n\n _.forEach(strapi.admin.routes, (router) => {\n router.type = router.type || 'admin';\n router.prefix = router.prefix || `/admin`;\n router.routes.forEach((route) => {\n generateRouteScope(route);\n route.info = { pluginName: 'admin' };\n });\n strapi.server.routes(router);\n });\n};\n\n/**\n * Register plugin routes\n * @param {import('../../').Strapi} strapi\n */\nconst registerPluginRoutes = (strapi: Core.Strapi) => {\n for (const pluginName of Object.keys(strapi.plugins)) {\n const plugin = strapi.plugins[pluginName];\n\n const generateRouteScope = createRouteScopeGenerator(`plugin::${pluginName}`);\n\n if (Array.isArray(plugin.routes)) {\n plugin.routes.forEach((route) => {\n generateRouteScope(route);\n route.info = { pluginName };\n });\n\n strapi.server.routes({\n type: 'admin',\n prefix: `/${pluginName}`,\n routes: plugin.routes,\n });\n } else {\n // Instantiate function-like routers\n // Mutate plugin.routes in-place and make sure router factories are instantiated correctly\n plugin.routes = instantiateRouterInputs(plugin.routes, strapi);\n\n _.forEach(plugin.routes, (router) => {\n router.type = router.type ?? 'admin';\n router.prefix = router.prefix ?? `/${pluginName}`;\n router.routes.forEach((route) => {\n generateRouteScope(route);\n route.info = { pluginName };\n });\n\n strapi.server.routes(router);\n });\n }\n }\n};\n\n/**\n * Register api routes\n */\nconst registerAPIRoutes = (strapi: Core.Strapi) => {\n for (const apiName of Object.keys(strapi.apis)) {\n const api = strapi.api(apiName);\n\n const generateRouteScope = createRouteScopeGenerator(`api::${apiName}`);\n\n // Mutate api.routes in-place and make sure router factories are instantiated correctly\n api.routes = instantiateRouterInputs(api.routes, strapi);\n\n _.forEach(api.routes, (router) => {\n // TODO: remove once auth setup\n // pass meta down to compose endpoint\n router.type = 'content-api';\n router.routes?.forEach((route) => {\n generateRouteScope(route);\n route.info = { apiName };\n });\n\n return strapi.server.routes(router);\n });\n }\n};\n\nconst instantiateRouterInputs = (\n routers: Record<string, Core.RouterConfig>,\n strapi: Core.Strapi\n): Record<string, Core.Router> => {\n const entries = Object.entries(routers);\n\n return entries.reduce((record, [key, inputOrCallback]) => {\n const isCallback = typeof inputOrCallback === 'function';\n\n return { ...record, [key]: isCallback ? inputOrCallback({ strapi }) : inputOrCallback };\n }, {});\n};\n"],"names":["createRouteScopeGenerator","namespace","route","prefix","endsWith","handler","_","defaultsDeep","config","auth","scope","startsWith","strapi","registerAdminRoutes","registerAPIRoutes","registerPluginRoutes","generateRouteScope","admin","routes","instantiateRouterInputs","forEach","router","type","info","pluginName","server","Object","keys","plugins","plugin","Array","isArray","apiName","apis","api","routers","entries","reduce","record","key","inputOrCallback","isCallback"],"mappings":";;;;AAGA,MAAMA,yBAAAA,GAA4B,CAACC,SAAAA,GAAsB,CAACC,KAAAA,GAAAA;QACxD,MAAMC,MAAAA,GAASF,SAAUG,CAAAA,QAAQ,CAAC,IAAA,CAAA,GAAQH,YAAY,CAAC,EAAEA,SAAU,CAAA,CAAC,CAAC;AAErE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