@webiny/api-headless-cms 6.6.0-alpha.1 → 6.6.0-alpha.10
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.
- package/HeadlessCmsFeature.js +13 -37
- package/HeadlessCmsFeature.js.map +1 -1
- package/createCmsRoute.d.ts +3 -5
- package/createCmsRoute.js +26 -14
- package/createCmsRoute.js.map +1 -1
- package/crud/contentEntry/entryDataValidation.js +17 -11
- package/crud/contentEntry/entryDataValidation.js.map +1 -1
- package/crud/contentModel/validate/endingAllowed.js +1 -1
- package/crud/contentModel/validate/endingAllowed.js.map +1 -1
- package/crud/contentModel/validate/pluralApiName.js +1 -1
- package/crud/contentModel/validate/pluralApiName.js.map +1 -1
- package/crud/contentModel/validate/singularApiName.js +1 -1
- package/crud/contentModel/validate/singularApiName.js.map +1 -1
- package/crud/contentModel/validation.js +2 -2
- package/crud/contentModel/validation.js.map +1 -1
- package/domain/contentModel/schemas.d.ts +2 -0
- package/domain/contentModel/schemas.js +1 -0
- package/domain/contentModel/schemas.js.map +1 -1
- package/domain/contentModel/validation/dateExpressions.d.ts +6 -0
- package/domain/contentModel/validation/dateExpressions.js +27 -0
- package/domain/contentModel/validation/dateExpressions.js.map +1 -0
- package/domain/contentModel/validation/endingAllowed.js +1 -1
- package/domain/contentModel/validation/endingAllowed.js.map +1 -1
- package/domain/contentModel/validation/modelFields.js +4 -2
- package/domain/contentModel/validation/modelFields.js.map +1 -1
- package/domain/contentModel/validation/pluralApiName.js +1 -1
- package/domain/contentModel/validation/pluralApiName.js.map +1 -1
- package/domain/contentModel/validation/singularApiName.js +1 -1
- package/domain/contentModel/validation/singularApiName.js.map +1 -1
- package/export/crud/exporting.js +2 -2
- package/export/crud/exporting.js.map +1 -1
- package/export/crud/imports/importGroups.js +1 -2
- package/export/crud/imports/importGroups.js.map +1 -1
- package/export/crud/imports/validateModels.js +1 -1
- package/export/crud/imports/validateModels.js.map +1 -1
- package/exports/api/cms/entry.d.ts +5 -0
- package/exports/api/cms/entry.js +5 -0
- package/features/ai/DescribeContentModelTool.d.ts +11 -6
- package/features/ai/DescribeContentModelTool.js +21 -12
- package/features/ai/DescribeContentModelTool.js.map +1 -1
- package/features/ai/ListContentModelsTool.d.ts +11 -6
- package/features/ai/ListContentModelsTool.js +21 -12
- package/features/ai/ListContentModelsTool.js.map +1 -1
- package/features/ai/QueryEntriesTool.d.ts +14 -9
- package/features/ai/QueryEntriesTool.js +20 -11
- package/features/ai/QueryEntriesTool.js.map +1 -1
- package/features/ai/feature.d.ts +2 -2
- package/features/ai/feature.js.map +1 -1
- package/features/contentEntry/ContentEntriesFeature.js +8 -0
- package/features/contentEntry/ContentEntriesFeature.js.map +1 -1
- package/features/contentEntry/CreateEntry/CreateEntryRepository.d.ts +4 -2
- package/features/contentEntry/CreateEntry/CreateEntryRepository.js +8 -3
- package/features/contentEntry/CreateEntry/CreateEntryRepository.js.map +1 -1
- package/features/contentEntry/CreateEntry/CreateEntryUseCase.d.ts +2 -2
- package/features/contentEntry/CreateEntry/CreateEntryUseCase.js +3 -4
- package/features/contentEntry/CreateEntry/CreateEntryUseCase.js.map +1 -1
- package/features/contentEntry/CreateEntryRevisionFrom/CreateEntryRevisionFromRepository.d.ts +4 -2
- package/features/contentEntry/CreateEntryRevisionFrom/CreateEntryRevisionFromRepository.js +8 -3
- package/features/contentEntry/CreateEntryRevisionFrom/CreateEntryRevisionFromRepository.js.map +1 -1
- package/features/contentEntry/CreateEntryRevisionFrom/CreateEntryRevisionFromUseCase.d.ts +2 -4
- package/features/contentEntry/CreateEntryRevisionFrom/CreateEntryRevisionFromUseCase.js +6 -14
- package/features/contentEntry/CreateEntryRevisionFrom/CreateEntryRevisionFromUseCase.js.map +1 -1
- package/features/contentEntry/CreateEntryRevisionFrom/abstractions.d.ts +2 -0
- package/features/contentEntry/CreateEntryRevisionFrom/abstractions.js.map +1 -1
- package/features/contentEntry/DeleteEntry/DeleteEntryRepository.d.ts +4 -2
- package/features/contentEntry/DeleteEntry/DeleteEntryRepository.js +8 -3
- package/features/contentEntry/DeleteEntry/DeleteEntryRepository.js.map +1 -1
- package/features/contentEntry/DeleteEntry/DeleteEntryUseCase.d.ts +2 -2
- package/features/contentEntry/DeleteEntry/DeleteEntryUseCase.js +2 -2
- package/features/contentEntry/DeleteEntry/DeleteEntryUseCase.js.map +1 -1
- package/features/contentEntry/DeleteEntry/MoveEntryToBinRepository.d.ts +3 -1
- package/features/contentEntry/DeleteEntry/MoveEntryToBinRepository.js +7 -3
- package/features/contentEntry/DeleteEntry/MoveEntryToBinRepository.js.map +1 -1
- package/features/contentEntry/DeleteEntry/MoveEntryToBinUseCase.d.ts +2 -2
- package/features/contentEntry/DeleteEntry/MoveEntryToBinUseCase.js +2 -2
- package/features/contentEntry/DeleteEntry/MoveEntryToBinUseCase.js.map +1 -1
- package/features/contentEntry/DeleteEntryRevision/DeleteEntryRevisionRepository.d.ts +3 -1
- package/features/contentEntry/DeleteEntryRevision/DeleteEntryRevisionRepository.js +9 -3
- package/features/contentEntry/DeleteEntryRevision/DeleteEntryRevisionRepository.js.map +1 -1
- package/features/contentEntry/DeleteEntryRevision/DeleteEntryRevisionUseCase.d.ts +2 -2
- package/features/contentEntry/DeleteEntryRevision/DeleteEntryRevisionUseCase.js +2 -2
- package/features/contentEntry/DeleteEntryRevision/DeleteEntryRevisionUseCase.js.map +1 -1
- package/features/contentEntry/DeleteMultipleEntries/DeleteMultipleEntriesRepository.d.ts +4 -2
- package/features/contentEntry/DeleteMultipleEntries/DeleteMultipleEntriesRepository.js +7 -3
- package/features/contentEntry/DeleteMultipleEntries/DeleteMultipleEntriesRepository.js.map +1 -1
- package/features/contentEntry/DeleteMultipleEntries/DeleteMultipleEntriesUseCase.d.ts +2 -2
- package/features/contentEntry/DeleteMultipleEntries/DeleteMultipleEntriesUseCase.js +11 -10
- package/features/contentEntry/DeleteMultipleEntries/DeleteMultipleEntriesUseCase.js.map +1 -1
- package/features/contentEntry/DuplicateEntry/DuplicateEntryUseCase.d.ts +17 -0
- package/features/contentEntry/DuplicateEntry/DuplicateEntryUseCase.js +83 -0
- package/features/contentEntry/DuplicateEntry/DuplicateEntryUseCase.js.map +1 -0
- package/features/contentEntry/DuplicateEntry/abstractions.d.ts +47 -0
- package/features/contentEntry/DuplicateEntry/abstractions.js +5 -0
- package/features/contentEntry/DuplicateEntry/abstractions.js.map +1 -0
- package/features/contentEntry/DuplicateEntry/events.d.ts +41 -0
- package/features/contentEntry/DuplicateEntry/events.js +32 -0
- package/features/contentEntry/DuplicateEntry/events.js.map +1 -0
- package/features/contentEntry/DuplicateEntry/feature.d.ts +4 -0
- package/features/contentEntry/DuplicateEntry/feature.js +11 -0
- package/features/contentEntry/DuplicateEntry/feature.js.map +1 -0
- package/features/contentEntry/DuplicateEntry/index.d.ts +2 -0
- package/features/contentEntry/DuplicateEntry/index.js +2 -0
- package/features/contentEntry/DuplicateEntry/prepareDuplicateValues.d.ts +7 -0
- package/features/contentEntry/DuplicateEntry/prepareDuplicateValues.js +12 -0
- package/features/contentEntry/DuplicateEntry/prepareDuplicateValues.js.map +1 -0
- package/features/contentEntry/EntryEventPublisher/EntryEventPublisher.d.ts +10 -0
- package/features/contentEntry/EntryEventPublisher/EntryEventPublisher.js +25 -0
- package/features/contentEntry/EntryEventPublisher/EntryEventPublisher.js.map +1 -0
- package/features/contentEntry/EntryEventPublisher/abstractions.d.ts +16 -0
- package/features/contentEntry/EntryEventPublisher/abstractions.js +5 -0
- package/features/contentEntry/EntryEventPublisher/abstractions.js.map +1 -0
- package/features/contentEntry/EntryEventPublisher/feature.d.ts +4 -0
- package/features/contentEntry/EntryEventPublisher/feature.js +11 -0
- package/features/contentEntry/EntryEventPublisher/feature.js.map +1 -0
- package/features/contentEntry/EntryEventPublisher/index.d.ts +2 -0
- package/features/contentEntry/EntryEventPublisher/index.js +2 -0
- package/features/contentEntry/EntrySystemField/abstractions.d.ts +14 -0
- package/features/contentEntry/EntrySystemField/abstractions.js +5 -0
- package/features/contentEntry/EntrySystemField/abstractions.js.map +1 -0
- package/features/contentEntry/EntrySystemField/index.d.ts +1 -0
- package/features/contentEntry/EntrySystemField/index.js +1 -0
- package/features/contentEntry/GetEntriesByIds/GetEntriesByIdsRepository.d.ts +4 -4
- package/features/contentEntry/GetEntriesByIds/GetEntriesByIdsRepository.js +8 -11
- package/features/contentEntry/GetEntriesByIds/GetEntriesByIdsRepository.js.map +1 -1
- package/features/contentEntry/GetLatestEntriesByIds/GetLatestEntriesByIdsRepository.d.ts +4 -2
- package/features/contentEntry/GetLatestEntriesByIds/GetLatestEntriesByIdsRepository.js +7 -3
- package/features/contentEntry/GetLatestEntriesByIds/GetLatestEntriesByIdsRepository.js.map +1 -1
- package/features/contentEntry/GetLatestRevisionByEntryId/GetLatestRevisionByEntryIdRepository.d.ts +4 -2
- package/features/contentEntry/GetLatestRevisionByEntryId/GetLatestRevisionByEntryIdRepository.js +7 -3
- package/features/contentEntry/GetLatestRevisionByEntryId/GetLatestRevisionByEntryIdRepository.js.map +1 -1
- package/features/contentEntry/GetPreviousRevisionByEntryId/GetPreviousRevisionByEntryIdRepository.d.ts +4 -2
- package/features/contentEntry/GetPreviousRevisionByEntryId/GetPreviousRevisionByEntryIdRepository.js +7 -3
- package/features/contentEntry/GetPreviousRevisionByEntryId/GetPreviousRevisionByEntryIdRepository.js.map +1 -1
- package/features/contentEntry/GetPublishedEntriesByIds/GetPublishedEntriesByIdsRepository.d.ts +4 -2
- package/features/contentEntry/GetPublishedEntriesByIds/GetPublishedEntriesByIdsRepository.js +7 -3
- package/features/contentEntry/GetPublishedEntriesByIds/GetPublishedEntriesByIdsRepository.js.map +1 -1
- package/features/contentEntry/GetPublishedRevisionByEntryId/GetPublishedRevisionByEntryIdRepository.d.ts +4 -2
- package/features/contentEntry/GetPublishedRevisionByEntryId/GetPublishedRevisionByEntryIdRepository.js +7 -3
- package/features/contentEntry/GetPublishedRevisionByEntryId/GetPublishedRevisionByEntryIdRepository.js.map +1 -1
- package/features/contentEntry/GetRevisionById/GetRevisionByIdRepository.d.ts +4 -2
- package/features/contentEntry/GetRevisionById/GetRevisionByIdRepository.js +7 -3
- package/features/contentEntry/GetRevisionById/GetRevisionByIdRepository.js.map +1 -1
- package/features/contentEntry/GetRevisionsByEntryId/GetRevisionsByEntryIdRepository.d.ts +4 -2
- package/features/contentEntry/GetRevisionsByEntryId/GetRevisionsByEntryIdRepository.js +7 -3
- package/features/contentEntry/GetRevisionsByEntryId/GetRevisionsByEntryIdRepository.js.map +1 -1
- package/features/contentEntry/GetUniqueFieldValues/GetUniqueFieldValuesRepository.d.ts +4 -2
- package/features/contentEntry/GetUniqueFieldValues/GetUniqueFieldValuesRepository.js +7 -3
- package/features/contentEntry/GetUniqueFieldValues/GetUniqueFieldValuesRepository.js.map +1 -1
- package/features/contentEntry/GetUniqueFieldValues/GetUniqueFieldValuesUseCase.js +3 -0
- package/features/contentEntry/GetUniqueFieldValues/GetUniqueFieldValuesUseCase.js.map +1 -1
- package/features/contentEntry/ListEntries/ListEntriesRepository.d.ts +4 -2
- package/features/contentEntry/ListEntries/ListEntriesRepository.js +7 -3
- package/features/contentEntry/ListEntries/ListEntriesRepository.js.map +1 -1
- package/features/contentEntry/MoveEntry/MoveEntryRepository.d.ts +4 -2
- package/features/contentEntry/MoveEntry/MoveEntryRepository.js +7 -3
- package/features/contentEntry/MoveEntry/MoveEntryRepository.js.map +1 -1
- package/features/contentEntry/MoveEntry/MoveEntryUseCase.d.ts +2 -2
- package/features/contentEntry/MoveEntry/MoveEntryUseCase.js +11 -4
- package/features/contentEntry/MoveEntry/MoveEntryUseCase.js.map +1 -1
- package/features/contentEntry/PublishEntry/PublishEntryRepository.d.ts +4 -2
- package/features/contentEntry/PublishEntry/PublishEntryRepository.js +8 -3
- package/features/contentEntry/PublishEntry/PublishEntryRepository.js.map +1 -1
- package/features/contentEntry/PublishEntry/PublishEntryUseCase.d.ts +4 -6
- package/features/contentEntry/PublishEntry/PublishEntryUseCase.js +11 -13
- package/features/contentEntry/PublishEntry/PublishEntryUseCase.js.map +1 -1
- package/features/contentEntry/PublishEntry/abstractions.d.ts +8 -1
- package/features/contentEntry/PublishEntry/abstractions.js.map +1 -1
- package/features/contentEntry/RepublishEntry/RepublishEntryRepository.d.ts +4 -2
- package/features/contentEntry/RepublishEntry/RepublishEntryRepository.js +8 -3
- package/features/contentEntry/RepublishEntry/RepublishEntryRepository.js.map +1 -1
- package/features/contentEntry/RepublishEntry/RepublishEntryUseCase.d.ts +2 -2
- package/features/contentEntry/RepublishEntry/RepublishEntryUseCase.js +5 -3
- package/features/contentEntry/RepublishEntry/RepublishEntryUseCase.js.map +1 -1
- package/features/contentEntry/RestoreEntryFromBin/RestoreEntryFromBinRepository.d.ts +4 -2
- package/features/contentEntry/RestoreEntryFromBin/RestoreEntryFromBinRepository.js +8 -3
- package/features/contentEntry/RestoreEntryFromBin/RestoreEntryFromBinRepository.js.map +1 -1
- package/features/contentEntry/RestoreEntryFromBin/RestoreEntryFromBinUseCase.d.ts +2 -2
- package/features/contentEntry/RestoreEntryFromBin/RestoreEntryFromBinUseCase.js +2 -2
- package/features/contentEntry/RestoreEntryFromBin/RestoreEntryFromBinUseCase.js.map +1 -1
- package/features/contentEntry/UnpublishEntry/UnpublishEntryRepository.d.ts +4 -2
- package/features/contentEntry/UnpublishEntry/UnpublishEntryRepository.js +8 -3
- package/features/contentEntry/UnpublishEntry/UnpublishEntryRepository.js.map +1 -1
- package/features/contentEntry/UnpublishEntry/UnpublishEntryUseCase.d.ts +2 -2
- package/features/contentEntry/UnpublishEntry/UnpublishEntryUseCase.js +5 -3
- package/features/contentEntry/UnpublishEntry/UnpublishEntryUseCase.js.map +1 -1
- package/features/contentEntry/UpdateEntry/UpdateEntryRepository.d.ts +4 -2
- package/features/contentEntry/UpdateEntry/UpdateEntryRepository.js +8 -3
- package/features/contentEntry/UpdateEntry/UpdateEntryRepository.js.map +1 -1
- package/features/contentEntry/UpdateEntry/UpdateEntryUseCase.d.ts +2 -2
- package/features/contentEntry/UpdateEntry/UpdateEntryUseCase.js +5 -3
- package/features/contentEntry/UpdateEntry/UpdateEntryUseCase.js.map +1 -1
- package/features/contentEntry/UpdateEntrySystem/UpdateEntrySystemUseCase.d.ts +19 -0
- package/features/contentEntry/UpdateEntrySystem/UpdateEntrySystemUseCase.js +70 -0
- package/features/contentEntry/UpdateEntrySystem/UpdateEntrySystemUseCase.js.map +1 -0
- package/features/contentEntry/UpdateEntrySystem/abstractions.d.ts +24 -0
- package/features/contentEntry/UpdateEntrySystem/abstractions.js +5 -0
- package/features/contentEntry/UpdateEntrySystem/abstractions.js.map +1 -0
- package/features/contentEntry/UpdateEntrySystem/events.d.ts +29 -0
- package/features/contentEntry/UpdateEntrySystem/events.js +23 -0
- package/features/contentEntry/UpdateEntrySystem/events.js.map +1 -0
- package/features/contentEntry/UpdateEntrySystem/feature.d.ts +4 -0
- package/features/contentEntry/UpdateEntrySystem/feature.js +11 -0
- package/features/contentEntry/UpdateEntrySystem/feature.js.map +1 -0
- package/features/contentEntry/UpdateEntrySystem/index.d.ts +2 -0
- package/features/contentEntry/UpdateEntrySystem/index.js +2 -0
- package/features/contentEntry/UpdateRevisionDescription/UpdateRevisionDescriptionUseCase.d.ts +2 -2
- package/features/contentEntry/UpdateRevisionDescription/UpdateRevisionDescriptionUseCase.js +2 -2
- package/features/contentEntry/UpdateRevisionDescription/UpdateRevisionDescriptionUseCase.js.map +1 -1
- package/features/contentEntry/ensureItemIds.d.ts +13 -0
- package/features/contentEntry/ensureItemIds.js +22 -0
- package/features/contentEntry/ensureItemIds.js.map +1 -0
- package/features/contentEntry/entryDataFactories/CreateEntryDataFactory/CreateEntryDataFactory.d.ts +3 -1
- package/features/contentEntry/entryDataFactories/CreateEntryDataFactory/CreateEntryDataFactory.js +8 -2
- package/features/contentEntry/entryDataFactories/CreateEntryDataFactory/CreateEntryDataFactory.js.map +1 -1
- package/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.d.ts +7 -3
- package/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.js +46 -13
- package/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.js.map +1 -1
- package/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/abstractions.d.ts +17 -1
- package/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/abstractions.js.map +1 -1
- package/features/contentEntry/entryDataFactories/CreatePublishEntryDataFactory/CreatePublishEntryDataFactory.d.ts +5 -3
- package/features/contentEntry/entryDataFactories/CreatePublishEntryDataFactory/CreatePublishEntryDataFactory.js +22 -15
- package/features/contentEntry/entryDataFactories/CreatePublishEntryDataFactory/CreatePublishEntryDataFactory.js.map +1 -1
- package/features/contentEntry/entryDataFactories/CreatePublishEntryDataFactory/abstractions.d.ts +15 -1
- package/features/contentEntry/entryDataFactories/CreatePublishEntryDataFactory/abstractions.js.map +1 -1
- package/features/contentEntry/entryDataFactories/CreateRepublishEntryDataFactory/CreateRepublishEntryDataFactory.d.ts +5 -3
- package/features/contentEntry/entryDataFactories/CreateRepublishEntryDataFactory/CreateRepublishEntryDataFactory.js +17 -12
- package/features/contentEntry/entryDataFactories/CreateRepublishEntryDataFactory/CreateRepublishEntryDataFactory.js.map +1 -1
- package/features/contentEntry/entryDataFactories/CreateRepublishEntryDataFactory/abstractions.d.ts +13 -1
- package/features/contentEntry/entryDataFactories/CreateRepublishEntryDataFactory/abstractions.js.map +1 -1
- package/features/contentEntry/entryDataFactories/CreateUnpublishEntryDataFactory/CreateUnpublishEntryDataFactory.d.ts +6 -6
- package/features/contentEntry/entryDataFactories/CreateUnpublishEntryDataFactory/CreateUnpublishEntryDataFactory.js +17 -17
- package/features/contentEntry/entryDataFactories/CreateUnpublishEntryDataFactory/CreateUnpublishEntryDataFactory.js.map +1 -1
- package/features/contentEntry/entryDataFactories/CreateUnpublishEntryDataFactory/abstractions.d.ts +14 -2
- package/features/contentEntry/entryDataFactories/CreateUnpublishEntryDataFactory/abstractions.js.map +1 -1
- package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.d.ts +7 -3
- package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.js +72 -28
- package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.js.map +1 -1
- package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/abstractions.d.ts +15 -1
- package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/abstractions.js.map +1 -1
- package/features/contentEntry/entryDataFactories/expiresAt.js +2 -2
- package/features/contentEntry/entryDataFactories/expiresAt.js.map +1 -1
- package/features/contentEntry/entryDataFactories/hasEntryContentChanged.d.ts +24 -0
- package/features/contentEntry/entryDataFactories/hasEntryContentChanged.js +13 -0
- package/features/contentEntry/entryDataFactories/hasEntryContentChanged.js.map +1 -0
- package/features/contentModel/CreateModel/CreateModelRepository.js +1 -2
- package/features/contentModel/CreateModel/CreateModelRepository.js.map +1 -1
- package/features/contentModel/CreateModelFrom/CreateModelFromRepository.js +1 -2
- package/features/contentModel/CreateModelFrom/CreateModelFromRepository.js.map +1 -1
- package/features/contentModel/DeleteModel/DeleteModelRepository.d.ts +4 -2
- package/features/contentModel/DeleteModel/DeleteModelRepository.js +7 -3
- package/features/contentModel/DeleteModel/DeleteModelRepository.js.map +1 -1
- package/features/contentModel/DeleteModel/DeleteModelWithEntryCleanup.d.ts +9 -4
- package/features/contentModel/DeleteModel/DeleteModelWithEntryCleanup.js +36 -21
- package/features/contentModel/DeleteModel/DeleteModelWithEntryCleanup.js.map +1 -1
- package/features/contentModel/ModelToAstConverter/ModelToAstConverter.d.ts +1 -1
- package/features/contentModel/ModelToAstConverter/ModelToAstConverter.js.map +1 -1
- package/features/contentModel/ModelToAstConverter/abstractions.d.ts +1 -1
- package/features/contentModel/ModelToAstConverter/abstractions.js.map +1 -1
- package/features/contentModel/UpdateModel/UpdateModelRepository.d.ts +4 -2
- package/features/contentModel/UpdateModel/UpdateModelRepository.js +8 -4
- package/features/contentModel/UpdateModel/UpdateModelRepository.js.map +1 -1
- package/features/contentModel/UpdateModel/UpdateModelUseCase.js +2 -2
- package/features/contentModel/UpdateModel/UpdateModelUseCase.js.map +1 -1
- package/features/contentModel/UpdateModel/abstractions.d.ts +1 -1
- package/features/contentModel/UpdateModel/abstractions.js.map +1 -1
- package/features/contentModel/ValuesSelectionGenerator/ValuesSelectionGenerator.js +4 -3
- package/features/contentModel/ValuesSelectionGenerator/ValuesSelectionGenerator.js.map +1 -1
- package/features/contentModel/shared/ModelsFetcher.d.ts +6 -5
- package/features/contentModel/shared/ModelsFetcher.js.map +1 -1
- package/features/contentModel/shared/PluginModelsProvider.d.ts +6 -3
- package/features/contentModel/shared/PluginModelsProvider.js +2 -9
- package/features/contentModel/shared/PluginModelsProvider.js.map +1 -1
- package/features/contentModelGroup/DeleteGroup/DeleteGroupRepository.d.ts +4 -2
- package/features/contentModelGroup/DeleteGroup/DeleteGroupRepository.js +7 -3
- package/features/contentModelGroup/DeleteGroup/DeleteGroupRepository.js.map +1 -1
- package/features/contentModelGroup/UpdateGroup/UpdateGroupRepository.d.ts +4 -2
- package/features/contentModelGroup/UpdateGroup/UpdateGroupRepository.js +8 -4
- package/features/contentModelGroup/UpdateGroup/UpdateGroupRepository.js.map +1 -1
- package/features/contentModelGroup/UpdateGroup/UpdateGroupUseCase.js +2 -2
- package/features/contentModelGroup/UpdateGroup/UpdateGroupUseCase.js.map +1 -1
- package/features/contentModelGroup/UpdateGroup/abstractions.d.ts +1 -1
- package/features/contentModelGroup/UpdateGroup/abstractions.js.map +1 -1
- package/features/graphql/fields/base/AssetToGraphQL.js +7 -2
- package/features/graphql/fields/base/AssetToGraphQL.js.map +1 -1
- package/features/graphql/fields/base/DynamicZoneToGraphQL.js +7 -1
- package/features/graphql/fields/base/DynamicZoneToGraphQL.js.map +1 -1
- package/features/graphql/fields/base/ObjectToGraphQL.js +6 -3
- package/features/graphql/fields/base/ObjectToGraphQL.js.map +1 -1
- package/features/graphql/fields/base/RefToGraphQL.js +24 -10
- package/features/graphql/fields/base/RefToGraphQL.js.map +1 -1
- package/features/modelBuilder/abstractions.d.ts +5 -2
- package/features/modelBuilder/abstractions.js.map +1 -1
- package/features/modelBuilder/feature.js +1 -8
- package/features/modelBuilder/feature.js.map +1 -1
- package/features/modelBuilder/fields/DataFieldBuilder.d.ts +17 -0
- package/features/modelBuilder/fields/DataFieldBuilder.js +6 -0
- package/features/modelBuilder/fields/DataFieldBuilder.js.map +1 -1
- package/features/modelBuilder/fields/DateTimeFieldType.js +27 -12
- package/features/modelBuilder/fields/DateTimeFieldType.js.map +1 -1
- package/features/modelBuilder/fields/fieldTypeValidator.d.ts +5 -3
- package/features/modelBuilder/models/ModelBuilder.d.ts +8 -0
- package/features/modelBuilder/models/ModelBuilder.js +1 -0
- package/features/modelBuilder/models/ModelBuilder.js.map +1 -1
- package/features/modelBuilder/models/ModelsProvider.d.ts +1 -3
- package/features/modelBuilder/models/ModelsProvider.js +2 -7
- package/features/modelBuilder/models/ModelsProvider.js.map +1 -1
- package/features/modelBuilder/models/PrivateModelBuilder.d.ts +5 -0
- package/features/modelBuilder/models/PrivateModelBuilder.js +12 -1
- package/features/modelBuilder/models/PrivateModelBuilder.js.map +1 -1
- package/features/modelStorageSync/ModelStorageSyncTask.d.ts +31 -0
- package/features/modelStorageSync/ModelStorageSyncTask.js +66 -0
- package/features/modelStorageSync/ModelStorageSyncTask.js.map +1 -0
- package/features/modelStorageSync/SyncStorageOnModelUpdate.d.ts +23 -0
- package/features/modelStorageSync/SyncStorageOnModelUpdate.js +51 -0
- package/features/modelStorageSync/SyncStorageOnModelUpdate.js.map +1 -0
- package/features/modelStorageSync/abstractions.d.ts +34 -0
- package/features/modelStorageSync/abstractions.js +6 -0
- package/features/modelStorageSync/abstractions.js.map +1 -0
- package/features/modelStorageSync/feature.d.ts +8 -0
- package/features/modelStorageSync/feature.js +13 -0
- package/features/modelStorageSync/feature.js.map +1 -0
- package/features/modelStorageSync/index.d.ts +2 -0
- package/features/modelStorageSync/index.js +2 -0
- package/features/runtimeTenant/RuntimeTenant.d.ts +13 -0
- package/features/runtimeTenant/RuntimeTenant.js +22 -0
- package/features/runtimeTenant/RuntimeTenant.js.map +1 -0
- package/features/runtimeTenant/abstractions.d.ts +11 -0
- package/features/runtimeTenant/abstractions.js +5 -0
- package/features/runtimeTenant/abstractions.js.map +1 -0
- package/features/runtimeTenant/index.d.ts +2 -0
- package/features/runtimeTenant/index.js +2 -0
- package/features/shared/abstractions.d.ts +1 -5
- package/features/shared/abstractions.js +1 -2
- package/features/shared/abstractions.js.map +1 -1
- package/features/storage/fields/CompressedTextStorageTransform.js +1 -1
- package/features/storage/fields/CompressedTextStorageTransform.js.map +1 -1
- package/features/storage/fields/DateStorageTransform.js +3 -4
- package/features/storage/fields/DateStorageTransform.js.map +1 -1
- package/features/storage/fields/DynamicZoneStorageTransform.js +2 -2
- package/features/storage/fields/DynamicZoneStorageTransform.js.map +1 -1
- package/features/storage/fields/JsonStorageTransform.js +1 -1
- package/features/storage/fields/JsonStorageTransform.js.map +1 -1
- package/features/storage/fields/LongTextStorageTransform.js +1 -1
- package/features/storage/fields/LongTextStorageTransform.js.map +1 -1
- package/features/storage/fields/ObjectStorageTransform.js +27 -7
- package/features/storage/fields/ObjectStorageTransform.js.map +1 -1
- package/features/storage/fields/RichTextStorageTransform.js +1 -1
- package/features/storage/fields/RichTextStorageTransform.js.map +1 -1
- package/features/validation/abstractions/CmsModelFieldValidator.d.ts +5 -0
- package/features/validation/abstractions/CmsModelFieldValidator.js.map +1 -1
- package/features/validation/validators/DateGteValidator.d.ts +2 -0
- package/features/validation/validators/DateGteValidator.js +12 -2
- package/features/validation/validators/DateGteValidator.js.map +1 -1
- package/features/validation/validators/DateLteValidator.d.ts +2 -0
- package/features/validation/validators/DateLteValidator.js +12 -2
- package/features/validation/validators/DateLteValidator.js.map +1 -1
- package/features/validation/validators/PatternValidator.js +1 -1
- package/features/validation/validators/PatternValidator.js.map +1 -1
- package/features/validation/validators/dateLimit.d.ts +9 -0
- package/features/validation/validators/dateLimit.js +18 -0
- package/features/validation/validators/dateLimit.js.map +1 -0
- package/features/whereMapper/WhereMapper.js +3 -5
- package/features/whereMapper/WhereMapper.js.map +1 -1
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js +15 -5
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js.map +1 -1
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js +8 -2
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js.map +1 -1
- package/graphql/checkEndpointAccess.d.ts +7 -2
- package/graphql/checkEndpointAccess.js +2 -4
- package/graphql/checkEndpointAccess.js.map +1 -1
- package/graphql/getSchema/generateCacheKey.js +1 -1
- package/graphql/getSchema/generateCacheKey.js.map +1 -1
- package/graphql/scalars/RevisionId.js +1 -1
- package/graphql/scalars/RevisionId.js.map +1 -1
- package/graphql/schema/cms/CmsBaseErrorTypeFactory.d.ts +1 -0
- package/graphql/schema/cms/CmsBaseErrorTypeFactory.js +4 -0
- package/graphql/schema/cms/CmsBaseErrorTypeFactory.js.map +1 -1
- package/graphql/schema/cms/resolvers/createEntry.d.ts +1 -0
- package/graphql/schema/cms/resolvers/createEntry.js +4 -0
- package/graphql/schema/cms/resolvers/createEntry.js.map +1 -1
- package/graphql/schema/cms/resolvers/deleteEntryRevision.d.ts +1 -0
- package/graphql/schema/cms/resolvers/deleteEntryRevision.js +4 -0
- package/graphql/schema/cms/resolvers/deleteEntryRevision.js.map +1 -1
- package/graphql/schema/cms/resolvers/getEntry.d.ts +1 -0
- package/graphql/schema/cms/resolvers/getEntry.js +4 -0
- package/graphql/schema/cms/resolvers/getEntry.js.map +1 -1
- package/graphql/schema/cms/resolvers/getModel.d.ts +1 -0
- package/graphql/schema/cms/resolvers/getModel.js +4 -0
- package/graphql/schema/cms/resolvers/getModel.js.map +1 -1
- package/graphql/schema/cms/resolvers/listEntries.d.ts +1 -0
- package/graphql/schema/cms/resolvers/listEntries.js +4 -0
- package/graphql/schema/cms/resolvers/listEntries.js.map +1 -1
- package/graphql/schema/cms/resolvers/mutationCms.d.ts +1 -0
- package/graphql/schema/cms/resolvers/mutationCms.js +4 -0
- package/graphql/schema/cms/resolvers/mutationCms.js.map +1 -1
- package/graphql/schema/cms/resolvers/publishEntryRevision.d.ts +1 -0
- package/graphql/schema/cms/resolvers/publishEntryRevision.js +4 -0
- package/graphql/schema/cms/resolvers/publishEntryRevision.js.map +1 -1
- package/graphql/schema/cms/resolvers/queryCms.d.ts +1 -0
- package/graphql/schema/cms/resolvers/queryCms.js +4 -0
- package/graphql/schema/cms/resolvers/queryCms.js.map +1 -1
- package/graphql/schema/cms/resolvers/unpublishEntryRevision.d.ts +1 -0
- package/graphql/schema/cms/resolvers/unpublishEntryRevision.js +4 -0
- package/graphql/schema/cms/resolvers/unpublishEntryRevision.js.map +1 -1
- package/graphql/schema/cms/resolvers/updateEntryRevision.d.ts +1 -0
- package/graphql/schema/cms/resolvers/updateEntryRevision.js +4 -0
- package/graphql/schema/cms/resolvers/updateEntryRevision.js.map +1 -1
- package/graphql/schema/cms/typeDefs/mutation.d.ts +1 -0
- package/graphql/schema/cms/typeDefs/mutation.js +4 -0
- package/graphql/schema/cms/typeDefs/mutation.js.map +1 -1
- package/graphql/schema/cms/typeDefs/query.d.ts +1 -0
- package/graphql/schema/cms/typeDefs/query.js +4 -0
- package/graphql/schema/cms/typeDefs/query.js.map +1 -1
- package/graphql/schema/cms/typeDefs/responses.d.ts +1 -0
- package/graphql/schema/cms/typeDefs/responses.js +4 -0
- package/graphql/schema/cms/typeDefs/responses.js.map +1 -1
- package/graphql/schema/contentEntries.js +19 -4
- package/graphql/schema/contentEntries.js.map +1 -1
- package/graphql/schema/contentModels.js +2 -0
- package/graphql/schema/contentModels.js.map +1 -1
- package/graphql/schema/createFieldResolvers.js +1 -1
- package/graphql/schema/createFieldResolvers.js.map +1 -1
- package/graphql/schema/createManageResolvers.js +3 -1
- package/graphql/schema/createManageResolvers.js.map +1 -1
- package/graphql/schema/createManageSDL.js +2 -0
- package/graphql/schema/createManageSDL.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveDuplicate.d.ts +7 -0
- package/graphql/schema/resolvers/manage/resolveDuplicate.js +11 -0
- package/graphql/schema/resolvers/manage/resolveDuplicate.js.map +1 -0
- package/package.json +24 -24
- package/plugins/CmsModelPlugin.js +9 -10
- package/plugins/CmsModelPlugin.js.map +1 -1
- package/types/index.d.ts +0 -1
- package/types/modelField.d.ts +11 -0
- package/types/types.d.ts +14 -109
- package/types/types.js.map +1 -1
- package/utils/caching/Cache.js +1 -1
- package/utils/caching/Cache.js.map +1 -1
- package/utils/createModelField.js +2 -1
- package/utils/createModelField.js.map +1 -1
- package/utils/createModelSchemaKey.d.ts +8 -0
- package/utils/createModelSchemaKey.js +18 -0
- package/utils/createModelSchemaKey.js.map +1 -0
- package/utils/date.js +1 -1
- package/utils/date.js.map +1 -1
- package/utils/entryStorage.js +1 -1
- package/utils/entryStorage.js.map +1 -1
- package/utils/renderFields.js +1 -1
- package/utils/renderFields.js.map +1 -1
- package/HeadlessCmsContextualSchema.d.ts +0 -16
- package/HeadlessCmsContextualSchema.js +0 -32
- package/HeadlessCmsContextualSchema.js.map +0 -1
- package/crud/contentEntry.crud.d.ts +0 -6
- package/crud/contentEntry.crud.js +0 -336
- package/crud/contentEntry.crud.js.map +0 -1
- package/crud/contentModel.crud.d.ts +0 -5
- package/crud/contentModel.crud.js +0 -79
- package/crud/contentModel.crud.js.map +0 -1
- package/crud/contentModelGroup.crud.d.ts +0 -5
- package/crud/contentModelGroup.crud.js +0 -76
- package/crud/contentModelGroup.crud.js.map +0 -1
- package/types/context.d.ts +0 -110
- package/types/context.js +0 -0
package/HeadlessCmsFeature.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { staticSchemaKey } from "@webiny/api-graphql/graphql/staticSchemaKey.js";
|
|
2
3
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/abstractions.js";
|
|
3
4
|
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/abstractions.js";
|
|
4
5
|
import { HeadlessCmsEndpointConfig } from "./HeadlessCmsEndpointConfig.js";
|
|
@@ -20,14 +21,12 @@ import { ModelBuilderFeature } from "./features/modelBuilder/index.js";
|
|
|
20
21
|
import { CmsWhereMapperFeature } from "./features/whereMapper/feature.js";
|
|
21
22
|
import { CmsSortMapperFeature } from "./features/sortMapper/feature.js";
|
|
22
23
|
import { CmsWebhooksFeature } from "./features/webhooks/feature.js";
|
|
24
|
+
import { ModelStorageSyncFeature } from "./features/modelStorageSync/index.js";
|
|
23
25
|
import { CmsBaseErrorTypeFactory } from "./graphql/schema/cms/CmsBaseErrorTypeFactory.js";
|
|
24
26
|
import { CmsSchemaExecutor } from "./graphql/CmsSchemaExecutor.js";
|
|
25
27
|
import { CmsMutationTypeDefsImpl, CmsQueryTypeDefsImpl, CmsResponseTypeDefsImpl } from "./graphql/schema/cms/typeDefs/index.js";
|
|
26
28
|
import { CreateEntryResolverImpl, DeleteEntryRevisionResolverImpl, GetEntryResolverImpl, GetModelResolverImpl, ListEntriesResolverImpl, MutationCmsResolverImpl, PublishEntryRevisionResolverImpl, QueryCmsResolverImpl, UnpublishEntryRevisionResolverImpl, UpdateEntryRevisionResolverImpl } from "./graphql/schema/cms/resolvers/index.js";
|
|
27
29
|
import { AccessControl } from "./crud/AccessControl/AccessControl.js";
|
|
28
|
-
import { createModelGroupsCrud } from "./crud/contentModelGroup.crud.js";
|
|
29
|
-
import { createModelsCrud } from "./crud/contentModel.crud.js";
|
|
30
|
-
import { createContentEntryCrud } from "./crud/contentEntry.crud.js";
|
|
31
30
|
import { CmsGraphQLSchemaPlugin, CmsGroupPlugin, CmsModelPlugin, StorageOperationsCmsModelPlugin } from "./plugins/index.js";
|
|
32
31
|
import { createCmsModelFieldConvertersAttachFactory } from "./utils/converters/valueKeyStorageConverter.js";
|
|
33
32
|
import { registerFieldConverters } from "./fieldConverters/abstractions.js";
|
|
@@ -43,14 +42,13 @@ import { CmsGraphQLSchemaFactory } from "./graphql/CmsGraphQLSchemaFactory.js";
|
|
|
43
42
|
import { CmsExport, CmsImport } from "./export/abstractions.js";
|
|
44
43
|
import { ListGroupsUseCase } from "./features/contentModelGroup/ListGroups/index.js";
|
|
45
44
|
import { RevisionIdScalar } from "./graphql/scalars/RevisionId.js";
|
|
46
|
-
import { AccessControl as abstractions_js_AccessControl, CmsContext, CmsStorageModelProvider
|
|
45
|
+
import { AccessControl as abstractions_js_AccessControl, CmsContext, CmsStorageModelProvider } from "./features/shared/abstractions.js";
|
|
47
46
|
import { EntryFromStorageTransform, EntryToStorageTransform, PluginsContainer as abstractions_js_PluginsContainer, SearchableFieldsProvider } from "./legacy/abstractions.js";
|
|
48
47
|
import { entryFromStorageTransform, entryToStorageTransform } from "./utils/entryStorage.js";
|
|
49
48
|
import { getSearchableFields } from "./crud/contentEntry/searchableFields.js";
|
|
50
49
|
const HeadlessCmsFeature = createFeature({
|
|
51
50
|
name: "HeadlessCms",
|
|
52
51
|
register (container, config) {
|
|
53
|
-
const { type } = config;
|
|
54
52
|
container.register(CmsBaseErrorTypeFactory);
|
|
55
53
|
container.register(CmsResponseTypeDefsImpl);
|
|
56
54
|
container.register(CmsQueryTypeDefsImpl);
|
|
@@ -81,6 +79,7 @@ const HeadlessCmsFeature = createFeature({
|
|
|
81
79
|
CmsWhereMapperFeature.register(container);
|
|
82
80
|
CmsSortMapperFeature.register(container);
|
|
83
81
|
CmsWebhooksFeature.register(container);
|
|
82
|
+
ModelStorageSyncFeature.register(container);
|
|
84
83
|
registerFieldConverters(container);
|
|
85
84
|
const pluginsContainer = new PluginsContainer([
|
|
86
85
|
...config.extraPlugins ?? []
|
|
@@ -104,6 +103,7 @@ const HeadlessCmsFeature = createFeature({
|
|
|
104
103
|
};
|
|
105
104
|
container.registerInstance(CmsContext, cmsContext);
|
|
106
105
|
container.registerInstance(CoreGraphQLSchemaFactory, {
|
|
106
|
+
getSchemaKey: staticSchemaKey("api-headless-cms/RevisionId"),
|
|
107
107
|
execute: async (builder)=>{
|
|
108
108
|
builder.addTypeDefs("scalar RevisionId");
|
|
109
109
|
builder.addLegacyResolvers({
|
|
@@ -132,34 +132,8 @@ const HeadlessCmsFeature = createFeature({
|
|
|
132
132
|
return accessControlInstance;
|
|
133
133
|
};
|
|
134
134
|
container.registerFactory(abstractions_js_AccessControl, ()=>getAccessControl());
|
|
135
|
-
|
|
136
|
-
container.registerFactory(
|
|
137
|
-
if (!cmsFacade) cmsFacade = {
|
|
138
|
-
type,
|
|
139
|
-
READ: "read" === type,
|
|
140
|
-
PREVIEW: "preview" === type,
|
|
141
|
-
MANAGE: "manage" === type,
|
|
142
|
-
accessControl: getAccessControl(),
|
|
143
|
-
...createModelGroupsCrud({
|
|
144
|
-
context: cmsContext
|
|
145
|
-
}),
|
|
146
|
-
...createModelsCrud({
|
|
147
|
-
context: cmsContext
|
|
148
|
-
}),
|
|
149
|
-
...createContentEntryCrud({
|
|
150
|
-
context: cmsContext
|
|
151
|
-
}),
|
|
152
|
-
export: {
|
|
153
|
-
...createExportCrud(cmsContext)
|
|
154
|
-
},
|
|
155
|
-
importing: {
|
|
156
|
-
...createImportCrud(cmsContext)
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
return cmsFacade;
|
|
160
|
-
});
|
|
161
|
-
container.registerFactory(CmsExport, ()=>container.resolve(HeadlessCms).export);
|
|
162
|
-
container.registerFactory(CmsImport, ()=>container.resolve(HeadlessCms).importing);
|
|
135
|
+
container.registerFactory(CmsExport, ()=>createExportCrud(cmsContext));
|
|
136
|
+
container.registerFactory(CmsImport, ()=>createImportCrud(cmsContext));
|
|
163
137
|
container.registerInstance(CmsSchemaExecutor, {
|
|
164
138
|
execute: async (schemaType, body)=>{
|
|
165
139
|
const bm = container.resolve(BenchmarkAbstraction);
|
|
@@ -175,10 +149,10 @@ const HeadlessCmsFeature = createFeature({
|
|
|
175
149
|
container.registerInstance(CmsGraphQLSchemaFactory, {
|
|
176
150
|
execute: ()=>createBaseSchemaPlugins(cmsContext)
|
|
177
151
|
});
|
|
178
|
-
|
|
179
|
-
execute: ()=>[
|
|
152
|
+
container.registerInstance(CmsGraphQLSchemaFactory, {
|
|
153
|
+
execute: ()=>"manage" === container.resolve(HeadlessCmsEndpointConfig).type ? [
|
|
180
154
|
exportPlugin
|
|
181
|
-
]
|
|
155
|
+
] : []
|
|
182
156
|
});
|
|
183
157
|
container.registerInstance(EntryToStorageTransform, (model, entry)=>entryToStorageTransform(cmsContext, model, entry));
|
|
184
158
|
container.registerInstance(EntryFromStorageTransform, (model, entry)=>entryFromStorageTransform(cmsContext, model, entry));
|
|
@@ -187,7 +161,9 @@ const HeadlessCmsFeature = createFeature({
|
|
|
187
161
|
fields: params.fields,
|
|
188
162
|
input: []
|
|
189
163
|
}));
|
|
190
|
-
container.register(createCmsRoute(
|
|
164
|
+
container.register(createCmsRoute("manage"));
|
|
165
|
+
container.register(createCmsRoute("read"));
|
|
166
|
+
container.register(createCmsRoute("preview"));
|
|
191
167
|
}
|
|
192
168
|
});
|
|
193
169
|
export { HeadlessCmsFeature };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HeadlessCmsFeature.js","sources":["../src/HeadlessCmsFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/abstractions.js\";\nimport { HeadlessCmsEndpointConfig } from \"./HeadlessCmsEndpointConfig.js\";\nimport { createCmsRoute } from \"./createCmsRoute.js\";\nimport { createRequestBody, processRequestBody } from \"@webiny/api-graphql\";\nimport { BenchmarkAbstraction } from \"@webiny/api\";\nimport { Benchmark } from \"@webiny/api/Benchmark.js\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { CompressionFeature } from \"@webiny/utils/features/compression/feature.js\";\nimport { GraphQLFeature } from \"~/features/graphql/index.js\";\nimport { ValidationFeature } from \"~/features/validation/index.js\";\nimport { StorageFeature } from \"~/features/storage/index.js\";\nimport { CmsInstallerFeature } from \"~/features/installer/feature.js\";\nimport { ContentEntriesFeature } from \"~/features/contentEntry/ContentEntriesFeature.js\";\nimport { ContentModelFeature } from \"~/features/contentModel/ContentModelFeature.js\";\nimport { CmsAiToolsFeature } from \"~/features/ai/index.js\";\nimport { ContentModelGroupFeature } from \"~/features/contentModelGroup/ContentModelGroupFeature.js\";\nimport { ModelBuilderFeature } from \"~/features/modelBuilder/index.js\";\nimport { CmsWhereMapperFeature } from \"~/features/whereMapper/feature.js\";\nimport { CmsSortMapperFeature } from \"~/features/sortMapper/feature.js\";\nimport { CmsWebhooksFeature } from \"~/features/webhooks/feature.js\";\nimport type { ApiEndpoint, CmsContext } from \"~/types/index.js\";\nimport { CmsBaseErrorTypeFactory } from \"~/graphql/schema/cms/CmsBaseErrorTypeFactory.js\";\nimport { CmsSchemaExecutor } from \"~/graphql/CmsSchemaExecutor.js\";\nimport {\n CmsResponseTypeDefsImpl,\n CmsQueryTypeDefsImpl,\n CmsMutationTypeDefsImpl\n} from \"~/graphql/schema/cms/typeDefs/index.js\";\nimport {\n QueryCmsResolverImpl,\n MutationCmsResolverImpl,\n GetModelResolverImpl,\n GetEntryResolverImpl,\n ListEntriesResolverImpl,\n CreateEntryResolverImpl,\n UpdateEntryRevisionResolverImpl,\n DeleteEntryRevisionResolverImpl,\n PublishEntryRevisionResolverImpl,\n UnpublishEntryRevisionResolverImpl\n} from \"~/graphql/schema/cms/resolvers/index.js\";\n// Facade wiring (moved here from HeadlessCmsInitializer so the facade can be a lazy DI factory).\nimport { AccessControl } from \"~/crud/AccessControl/AccessControl.js\";\nimport { createModelGroupsCrud } from \"~/crud/contentModelGroup.crud.js\";\nimport { createModelsCrud } from \"~/crud/contentModel.crud.js\";\nimport { createContentEntryCrud } from \"~/crud/contentEntry.crud.js\";\nimport type { ICmsGraphQLSchemaPlugin } from \"~/plugins/index.js\";\nimport {\n CmsGraphQLSchemaPlugin,\n CmsGroupPlugin,\n CmsModelPlugin,\n StorageOperationsCmsModelPlugin\n} from \"~/plugins/index.js\";\nimport { createCmsModelFieldConvertersAttachFactory } from \"~/utils/converters/valueKeyStorageConverter.js\";\nimport { registerFieldConverters } from \"~/fieldConverters/abstractions.js\";\nimport { CmsModelPluginInstance } from \"~/features/contentModel/shared/abstractions.js\";\nimport { CmsGroupPluginInstance } from \"~/features/contentModelGroup/shared/abstractions.js\";\nimport { createExportCrud } from \"~/export/index.js\";\nimport { createImportCrud } from \"~/export/crud/importing.js\";\nimport { getSchema } from \"~/graphql/getSchema.js\";\nimport { createBaseSchemaPlugins } from \"~/graphql/schema/baseSchema.js\";\nimport { exportPlugin } from \"~/export/graphql/index.js\";\nimport { CoreGraphQLSchemaFactory } from \"@webiny/api-graphql/graphql/abstractions.js\";\nimport { CmsGraphQLSchemaFactory } from \"~/graphql/CmsGraphQLSchemaFactory.js\";\nimport { CmsExport, CmsImport } from \"~/export/abstractions.js\";\nimport { ListGroupsUseCase } from \"~/features/contentModelGroup/ListGroups/index.js\";\nimport { RevisionIdScalar } from \"~/graphql/scalars/RevisionId.js\";\nimport {\n AccessControl as AccessControlAbstraction,\n CmsContext as CmsContextAbstraction,\n CmsStorageModelProvider,\n HeadlessCms\n} from \"~/features/shared/abstractions.js\";\n\nimport {\n EntryFromStorageTransform,\n EntryToStorageTransform,\n PluginsContainer as PluginsContainerAbstraction,\n SearchableFieldsProvider\n} from \"~/legacy/abstractions.js\";\nimport { entryFromStorageTransform, entryToStorageTransform } from \"~/utils/entryStorage.js\";\nimport { getSearchableFields } from \"~/crud/contentEntry/searchableFields.js\";\n\nexport interface HeadlessCmsConfig {\n type: ApiEndpoint;\n /** Extra plugins (e.g. CmsGraphQLSchemaPlugin) to register in ctx.plugins at runtime. */\n extraPlugins?: any[];\n}\n\nexport const HeadlessCmsFeature = createFeature<HeadlessCmsConfig>({\n name: \"HeadlessCms\",\n register(container, config) {\n const { type } = config;\n\n // Pre-register the CMS SDK namespace schema (Query.cms / Mutation.cms) so it is\n // available when GraphQLSchemaComposer is constructed (before context enhancement).\n // All these implementations have zero DI dependencies and are safe to register early.\n container.register(CmsBaseErrorTypeFactory); // CmsError must come first\n container.register(CmsResponseTypeDefsImpl);\n container.register(CmsQueryTypeDefsImpl);\n container.register(CmsMutationTypeDefsImpl);\n container.register(QueryCmsResolverImpl);\n container.register(MutationCmsResolverImpl);\n container.register(GetModelResolverImpl);\n container.register(GetEntryResolverImpl);\n container.register(ListEntriesResolverImpl);\n container.register(CreateEntryResolverImpl);\n container.register(UpdateEntryRevisionResolverImpl);\n container.register(DeleteEntryRevisionResolverImpl);\n container.register(PublishEntryRevisionResolverImpl);\n container.register(UnpublishEntryRevisionResolverImpl);\n\n container.registerInstance(HeadlessCmsEndpointConfig, {\n type: config.type\n });\n\n // Register CMS DI features statically so they are available before any enhancers run.\n // All these are pure class registrations (no eager instantiation) so they are safe\n // to register here before any request-time context is available.\n CompressionFeature.register(container);\n GraphQLFeature.register(container);\n ValidationFeature.register(container);\n StorageFeature.register(container);\n CmsInstallerFeature.register(container);\n ContentEntriesFeature.register(container);\n ContentModelFeature.register(container);\n CmsAiToolsFeature.register(container);\n ContentModelGroupFeature.register(container);\n ModelBuilderFeature.register(container);\n CmsWhereMapperFeature.register(container);\n CmsSortMapperFeature.register(container);\n CmsWebhooksFeature.register(container);\n\n // ============================================================================\n // Synchronous per-request wiring (moved out of HeadlessCmsInitializer.init).\n // register() runs per request, pre-auth — correct for pure wiring and closures.\n // ============================================================================\n\n // Field value converters are resolved from the DI container.\n registerFieldConverters(container);\n\n // PluginsContainer still carries legacy extension plugins (e.g. CmsGraphQLSchemaPlugin)\n // until those remaining consumers are migrated to DI.\n const pluginsContainer = new PluginsContainer([...(config.extraPlugins ?? [])]);\n container.registerInstance(PluginsContainerAbstraction, pluginsContainer);\n\n // Code-defined model/group plugins are exposed via DI tokens so the\n // Plugin{Models,Groups}Provider can resolve them without the plugins container.\n for (const plugin of pluginsContainer.byType<CmsModelPlugin>(CmsModelPlugin.type)) {\n container.registerInstance(CmsModelPluginInstance, plugin);\n }\n for (const plugin of pluginsContainer.byType<CmsGroupPlugin>(CmsGroupPlugin.type)) {\n container.registerInstance(CmsGroupPluginInstance, plugin);\n }\n\n // User-provided GraphQL schema extension plugins (added via extraPlugins) are bridged\n // to the CmsGraphQLSchemaFactory DI token so generateSchema includes them.\n const userSchemaPlugins = pluginsContainer.byType<ICmsGraphQLSchemaPlugin>(\n CmsGraphQLSchemaPlugin.type\n );\n if (userSchemaPlugins.length > 0) {\n container.registerInstance(CmsGraphQLSchemaFactory, {\n execute: () => userSchemaPlugins\n });\n }\n\n // RegisterExtensionPlugins supplied via extraPlugins (test infra) only do DI registration\n // via their apply(). Apply them here at register() time — matching the app's registerExtensions\n // and the storage presets above — so code-defined models are present before per-request model\n // listing runs.\n for (const plugin of config.extraPlugins ?? []) {\n if (plugin && typeof (plugin as any).apply === \"function\") {\n (plugin as any).apply({ container });\n }\n }\n\n const benchmark = new Benchmark();\n container.registerInstance(BenchmarkAbstraction, benchmark);\n\n // The CmsContext \"shim\": the request-scoped context object the facade builders, transforms\n // and getSchema operate on. They only read `.container` (+ plugins/benchmark), so this is\n // all they need — there is no legacy bag.\n const cmsContext = {\n container,\n plugins: pluginsContainer,\n benchmark\n } as unknown as CmsContext;\n container.registerInstance(CmsContextAbstraction, cmsContext);\n\n container.registerInstance(CoreGraphQLSchemaFactory, {\n execute: async builder => {\n builder.addTypeDefs(\"scalar RevisionId\");\n builder.addLegacyResolvers({ RevisionId: RevisionIdScalar });\n return builder;\n }\n });\n\n container.registerInstance(\n CmsStorageModelProvider,\n new StorageOperationsCmsModelPlugin(\n createCmsModelFieldConvertersAttachFactory(cmsContext)\n )\n );\n\n // Entry storage operations are registered by each adapter's feature at app-scope.\n // HeadlessCmsFeature no longer manages entry storage registration.\n\n const identityContext = container.resolve(IdentityContext);\n const tenantContext = container.resolve(TenantContext);\n const getTenant = () => tenantContext.getTenant();\n\n // AccessControl is identity-dependent; build it lazily and memoise per request container.\n let accessControlInstance: AccessControl | undefined;\n const getAccessControl = (): AccessControl => {\n if (!accessControlInstance) {\n accessControlInstance = new AccessControl({\n getIdentity: async () => identityContext.getIdentity(),\n getGroupsPermissions: () =>\n identityContext.getPermissions(\"cms.contentModelGroup\"),\n getModelsPermissions: () => identityContext.getPermissions(\"cms.contentModel\"),\n getEntriesPermissions: () => identityContext.getPermissions(\"cms.contentEntry\"),\n listAllGroups: async () => {\n const result = await identityContext.withoutAuthorization(() =>\n container.resolve(ListGroupsUseCase).execute()\n );\n if (result.isFail()) {\n throw result.error;\n }\n return result.value;\n }\n });\n }\n return accessControlInstance;\n };\n container.registerFactory(AccessControlAbstraction, () => getAccessControl());\n\n // The HeadlessCms facade — a LAZY factory built on first resolve (post-auth), memoised per\n // request container.\n let cmsFacade: HeadlessCms.Interface | undefined;\n container.registerFactory(HeadlessCms, () => {\n if (!cmsFacade) {\n cmsFacade = {\n type,\n READ: type === \"read\",\n PREVIEW: type === \"preview\",\n MANAGE: type === \"manage\",\n accessControl: getAccessControl(),\n ...createModelGroupsCrud({ context: cmsContext }),\n ...createModelsCrud({ context: cmsContext }),\n ...createContentEntryCrud({ context: cmsContext }),\n export: { ...createExportCrud(cmsContext) },\n importing: { ...createImportCrud(cmsContext) }\n } as HeadlessCms.Interface;\n }\n return cmsFacade;\n });\n container.registerFactory(CmsExport, () => container.resolve(HeadlessCms).export);\n container.registerFactory(CmsImport, () => container.resolve(HeadlessCms).importing);\n\n // Register CmsSchemaExecutor so proxy resolvers can build and execute the CMS sub-schema.\n container.registerInstance(CmsSchemaExecutor, {\n execute: async (schemaType: ApiEndpoint, body: any) => {\n const bm = container.resolve(BenchmarkAbstraction);\n const schema = await bm.measure(\"headlessCms.graphql.getSchema\", () =>\n identityContext.withoutAuthorization(() =>\n getSchema({ context: cmsContext, getTenant, type: schemaType })\n )\n );\n const requestBody = await bm.measure(\n \"headlessCms.graphql.createRequestBody\",\n async () => createRequestBody(body)\n );\n return bm.measure(\"headlessCms.graphql.processRequestBody\", () =>\n processRequestBody(requestBody, schema, cmsContext)\n );\n }\n });\n\n // Register CMS sub-schema factories: base types (CmsError, CmsIdentity, etc.)\n // and, for manage endpoints, the import/export operations.\n container.registerInstance(CmsGraphQLSchemaFactory, {\n execute: () => createBaseSchemaPlugins(cmsContext)\n });\n if (type === \"manage\") {\n container.registerInstance(CmsGraphQLSchemaFactory, {\n execute: () => [exportPlugin]\n });\n }\n\n container.registerInstance(EntryToStorageTransform, (model, entry) => {\n return entryToStorageTransform(cmsContext, model, entry);\n });\n container.registerInstance(EntryFromStorageTransform, (model, entry) => {\n return entryFromStorageTransform(cmsContext, model, entry);\n });\n container.registerInstance(SearchableFieldsProvider, params => {\n return getSearchableFields({\n context: cmsContext,\n fields: params.fields,\n input: []\n });\n });\n\n container.register(createCmsRoute(config.type));\n }\n});\n"],"names":["HeadlessCmsFeature","createFeature","container","config","type","CmsBaseErrorTypeFactory","CmsResponseTypeDefsImpl","CmsQueryTypeDefsImpl","CmsMutationTypeDefsImpl","QueryCmsResolverImpl","MutationCmsResolverImpl","GetModelResolverImpl","GetEntryResolverImpl","ListEntriesResolverImpl","CreateEntryResolverImpl","UpdateEntryRevisionResolverImpl","DeleteEntryRevisionResolverImpl","PublishEntryRevisionResolverImpl","UnpublishEntryRevisionResolverImpl","HeadlessCmsEndpointConfig","CompressionFeature","GraphQLFeature","ValidationFeature","StorageFeature","CmsInstallerFeature","ContentEntriesFeature","ContentModelFeature","CmsAiToolsFeature","ContentModelGroupFeature","ModelBuilderFeature","CmsWhereMapperFeature","CmsSortMapperFeature","CmsWebhooksFeature","registerFieldConverters","pluginsContainer","PluginsContainer","PluginsContainerAbstraction","plugin","CmsModelPlugin","CmsModelPluginInstance","CmsGroupPlugin","CmsGroupPluginInstance","userSchemaPlugins","CmsGraphQLSchemaPlugin","CmsGraphQLSchemaFactory","benchmark","Benchmark","BenchmarkAbstraction","cmsContext","CmsContextAbstraction","CoreGraphQLSchemaFactory","builder","RevisionIdScalar","CmsStorageModelProvider","StorageOperationsCmsModelPlugin","createCmsModelFieldConvertersAttachFactory","identityContext","IdentityContext","tenantContext","TenantContext","getTenant","accessControlInstance","getAccessControl","AccessControl","result","ListGroupsUseCase","AccessControlAbstraction","cmsFacade","HeadlessCms","createModelGroupsCrud","createModelsCrud","createContentEntryCrud","createExportCrud","createImportCrud","CmsExport","CmsImport","CmsSchemaExecutor","schemaType","body","bm","schema","getSchema","requestBody","createRequestBody","processRequestBody","createBaseSchemaPlugins","exportPlugin","EntryToStorageTransform","model","entry","entryToStorageTransform","EntryFromStorageTransform","entryFromStorageTransform","SearchableFieldsProvider","params","getSearchableFields","createCmsRoute"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0FO,MAAMA,qBAAqBC,cAAiC;IAC/D,MAAM;IACN,UAASC,SAAS,EAAEC,MAAM;QACtB,MAAM,EAAEC,IAAI,EAAE,GAAGD;QAKjBD,UAAU,QAAQ,CAACG;QACnBH,UAAU,QAAQ,CAACI;QACnBJ,UAAU,QAAQ,CAACK;QACnBL,UAAU,QAAQ,CAACM;QACnBN,UAAU,QAAQ,CAACO;QACnBP,UAAU,QAAQ,CAACQ;QACnBR,UAAU,QAAQ,CAACS;QACnBT,UAAU,QAAQ,CAACU;QACnBV,UAAU,QAAQ,CAACW;QACnBX,UAAU,QAAQ,CAACY;QACnBZ,UAAU,QAAQ,CAACa;QACnBb,UAAU,QAAQ,CAACc;QACnBd,UAAU,QAAQ,CAACe;QACnBf,UAAU,QAAQ,CAACgB;QAEnBhB,UAAU,gBAAgB,CAACiB,2BAA2B;YAClD,MAAMhB,OAAO,IAAI;QACrB;QAKAiB,mBAAmB,QAAQ,CA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":["../src/HeadlessCmsFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { staticSchemaKey } from \"@webiny/api-graphql/graphql/staticSchemaKey.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/abstractions.js\";\nimport { HeadlessCmsEndpointConfig } from \"./HeadlessCmsEndpointConfig.js\";\nimport { createCmsRoute } from \"./createCmsRoute.js\";\nimport { createRequestBody, processRequestBody } from \"@webiny/api-graphql\";\nimport { BenchmarkAbstraction } from \"@webiny/api\";\nimport { Benchmark } from \"@webiny/api/Benchmark.js\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { CompressionFeature } from \"@webiny/utils/features/compression/feature.js\";\nimport { GraphQLFeature } from \"~/features/graphql/index.js\";\nimport { ValidationFeature } from \"~/features/validation/index.js\";\nimport { StorageFeature } from \"~/features/storage/index.js\";\nimport { CmsInstallerFeature } from \"~/features/installer/feature.js\";\nimport { ContentEntriesFeature } from \"~/features/contentEntry/ContentEntriesFeature.js\";\nimport { ContentModelFeature } from \"~/features/contentModel/ContentModelFeature.js\";\nimport { CmsAiToolsFeature } from \"~/features/ai/index.js\";\nimport { ContentModelGroupFeature } from \"~/features/contentModelGroup/ContentModelGroupFeature.js\";\nimport { ModelBuilderFeature } from \"~/features/modelBuilder/index.js\";\nimport { CmsWhereMapperFeature } from \"~/features/whereMapper/feature.js\";\nimport { CmsSortMapperFeature } from \"~/features/sortMapper/feature.js\";\nimport { CmsWebhooksFeature } from \"~/features/webhooks/feature.js\";\nimport { ModelStorageSyncFeature } from \"~/features/modelStorageSync/index.js\";\nimport type { ApiEndpoint, CmsContext } from \"~/types/index.js\";\nimport { CmsBaseErrorTypeFactory } from \"~/graphql/schema/cms/CmsBaseErrorTypeFactory.js\";\nimport { CmsSchemaExecutor } from \"~/graphql/CmsSchemaExecutor.js\";\nimport {\n CmsResponseTypeDefsImpl,\n CmsQueryTypeDefsImpl,\n CmsMutationTypeDefsImpl\n} from \"~/graphql/schema/cms/typeDefs/index.js\";\nimport {\n QueryCmsResolverImpl,\n MutationCmsResolverImpl,\n GetModelResolverImpl,\n GetEntryResolverImpl,\n ListEntriesResolverImpl,\n CreateEntryResolverImpl,\n UpdateEntryRevisionResolverImpl,\n DeleteEntryRevisionResolverImpl,\n PublishEntryRevisionResolverImpl,\n UnpublishEntryRevisionResolverImpl\n} from \"~/graphql/schema/cms/resolvers/index.js\";\n// Facade wiring (moved here from HeadlessCmsInitializer so the facade can be a lazy DI factory).\nimport { AccessControl } from \"~/crud/AccessControl/AccessControl.js\";\nimport type { ICmsGraphQLSchemaPlugin } from \"~/plugins/index.js\";\nimport {\n CmsGraphQLSchemaPlugin,\n CmsGroupPlugin,\n CmsModelPlugin,\n StorageOperationsCmsModelPlugin\n} from \"~/plugins/index.js\";\nimport { createCmsModelFieldConvertersAttachFactory } from \"~/utils/converters/valueKeyStorageConverter.js\";\nimport { registerFieldConverters } from \"~/fieldConverters/abstractions.js\";\nimport { CmsModelPluginInstance } from \"~/features/contentModel/shared/abstractions.js\";\nimport { CmsGroupPluginInstance } from \"~/features/contentModelGroup/shared/abstractions.js\";\nimport { createExportCrud } from \"~/export/index.js\";\nimport { createImportCrud } from \"~/export/crud/importing.js\";\nimport { getSchema } from \"~/graphql/getSchema.js\";\nimport { createBaseSchemaPlugins } from \"~/graphql/schema/baseSchema.js\";\nimport { exportPlugin } from \"~/export/graphql/index.js\";\nimport { CoreGraphQLSchemaFactory } from \"@webiny/api-graphql/graphql/abstractions.js\";\nimport { CmsGraphQLSchemaFactory } from \"~/graphql/CmsGraphQLSchemaFactory.js\";\nimport { CmsExport, CmsImport } from \"~/export/abstractions.js\";\nimport { ListGroupsUseCase } from \"~/features/contentModelGroup/ListGroups/index.js\";\nimport { RevisionIdScalar } from \"~/graphql/scalars/RevisionId.js\";\nimport {\n AccessControl as AccessControlAbstraction,\n CmsContext as CmsContextAbstraction,\n CmsStorageModelProvider\n} from \"~/features/shared/abstractions.js\";\n\nimport {\n EntryFromStorageTransform,\n EntryToStorageTransform,\n PluginsContainer as PluginsContainerAbstraction,\n SearchableFieldsProvider\n} from \"~/legacy/abstractions.js\";\nimport { entryFromStorageTransform, entryToStorageTransform } from \"~/utils/entryStorage.js\";\nimport { getSearchableFields } from \"~/crud/contentEntry/searchableFields.js\";\n\nexport interface HeadlessCmsConfig {\n type: ApiEndpoint;\n /** Extra plugins (e.g. CmsGraphQLSchemaPlugin) to register in ctx.plugins at runtime. */\n extraPlugins?: any[];\n}\n\nexport const HeadlessCmsFeature = createFeature<HeadlessCmsConfig>({\n name: \"HeadlessCms\",\n register(container, config) {\n // Pre-register the CMS SDK namespace schema (Query.cms / Mutation.cms) so it is\n // available when GraphQLSchemaComposer is constructed (before context enhancement).\n // All these implementations have zero DI dependencies and are safe to register early.\n container.register(CmsBaseErrorTypeFactory); // CmsError must come first\n container.register(CmsResponseTypeDefsImpl);\n container.register(CmsQueryTypeDefsImpl);\n container.register(CmsMutationTypeDefsImpl);\n container.register(QueryCmsResolverImpl);\n container.register(MutationCmsResolverImpl);\n container.register(GetModelResolverImpl);\n container.register(GetEntryResolverImpl);\n container.register(ListEntriesResolverImpl);\n container.register(CreateEntryResolverImpl);\n container.register(UpdateEntryRevisionResolverImpl);\n container.register(DeleteEntryRevisionResolverImpl);\n container.register(PublishEntryRevisionResolverImpl);\n container.register(UnpublishEntryRevisionResolverImpl);\n\n container.registerInstance(HeadlessCmsEndpointConfig, {\n type: config.type\n });\n\n // Register CMS DI features statically so they are available before any enhancers run.\n // All these are pure class registrations (no eager instantiation) so they are safe\n // to register here before any request-time context is available.\n CompressionFeature.register(container);\n GraphQLFeature.register(container);\n ValidationFeature.register(container);\n StorageFeature.register(container);\n CmsInstallerFeature.register(container);\n ContentEntriesFeature.register(container);\n ContentModelFeature.register(container);\n CmsAiToolsFeature.register(container);\n ContentModelGroupFeature.register(container);\n ModelBuilderFeature.register(container);\n CmsWhereMapperFeature.register(container);\n CmsSortMapperFeature.register(container);\n CmsWebhooksFeature.register(container);\n ModelStorageSyncFeature.register(container);\n\n // ============================================================================\n // Synchronous per-request wiring (moved out of HeadlessCmsInitializer.init).\n // register() runs per request, pre-auth — correct for pure wiring and closures.\n // ============================================================================\n\n // Field value converters are resolved from the DI container.\n registerFieldConverters(container);\n\n // PluginsContainer still carries legacy extension plugins (e.g. CmsGraphQLSchemaPlugin)\n // until those remaining consumers are migrated to DI.\n const pluginsContainer = new PluginsContainer([...(config.extraPlugins ?? [])]);\n container.registerInstance(PluginsContainerAbstraction, pluginsContainer);\n\n // Code-defined model/group plugins are exposed via DI tokens so the\n // Plugin{Models,Groups}Provider can resolve them without the plugins container.\n for (const plugin of pluginsContainer.byType<CmsModelPlugin>(CmsModelPlugin.type)) {\n container.registerInstance(CmsModelPluginInstance, plugin);\n }\n for (const plugin of pluginsContainer.byType<CmsGroupPlugin>(CmsGroupPlugin.type)) {\n container.registerInstance(CmsGroupPluginInstance, plugin);\n }\n\n // User-provided GraphQL schema extension plugins (added via extraPlugins) are bridged\n // to the CmsGraphQLSchemaFactory DI token so generateSchema includes them.\n const userSchemaPlugins = pluginsContainer.byType<ICmsGraphQLSchemaPlugin>(\n CmsGraphQLSchemaPlugin.type\n );\n if (userSchemaPlugins.length > 0) {\n container.registerInstance(CmsGraphQLSchemaFactory, {\n execute: () => userSchemaPlugins\n });\n }\n\n // RegisterExtensionPlugins supplied via extraPlugins (test infra) only do DI registration\n // via their apply(). Apply them here at register() time — matching the app's registerExtensions\n // and the storage presets above — so code-defined models are present before per-request model\n // listing runs.\n for (const plugin of config.extraPlugins ?? []) {\n if (plugin && typeof (plugin as any).apply === \"function\") {\n (plugin as any).apply({ container });\n }\n }\n\n const benchmark = new Benchmark();\n container.registerInstance(BenchmarkAbstraction, benchmark);\n\n // The CmsContext \"shim\": the request-scoped context object the facade builders, transforms\n // and getSchema operate on. They only read `.container` (+ plugins/benchmark), so this is\n // all they need — there is no legacy bag.\n const cmsContext = {\n container,\n plugins: pluginsContainer,\n benchmark\n } as unknown as CmsContext;\n container.registerInstance(CmsContextAbstraction, cmsContext);\n\n container.registerInstance(CoreGraphQLSchemaFactory, {\n getSchemaKey: staticSchemaKey(\"api-headless-cms/RevisionId\"),\n execute: async builder => {\n builder.addTypeDefs(\"scalar RevisionId\");\n builder.addLegacyResolvers({ RevisionId: RevisionIdScalar });\n return builder;\n }\n });\n\n container.registerInstance(\n CmsStorageModelProvider,\n new StorageOperationsCmsModelPlugin(\n createCmsModelFieldConvertersAttachFactory(cmsContext)\n )\n );\n\n // Entry storage operations are registered by each adapter's feature at app-scope.\n // HeadlessCmsFeature no longer manages entry storage registration.\n\n const identityContext = container.resolve(IdentityContext);\n const tenantContext = container.resolve(TenantContext);\n const getTenant = () => tenantContext.getTenant();\n\n // AccessControl is identity-dependent; build it lazily and memoise per request container.\n let accessControlInstance: AccessControl | undefined;\n const getAccessControl = (): AccessControl => {\n if (!accessControlInstance) {\n accessControlInstance = new AccessControl({\n getIdentity: async () => identityContext.getIdentity(),\n getGroupsPermissions: () =>\n identityContext.getPermissions(\"cms.contentModelGroup\"),\n getModelsPermissions: () => identityContext.getPermissions(\"cms.contentModel\"),\n getEntriesPermissions: () => identityContext.getPermissions(\"cms.contentEntry\"),\n listAllGroups: async () => {\n const result = await identityContext.withoutAuthorization(() =>\n container.resolve(ListGroupsUseCase).execute()\n );\n if (result.isFail()) {\n throw result.error;\n }\n return result.value;\n }\n });\n }\n return accessControlInstance;\n };\n container.registerFactory(AccessControlAbstraction, () => getAccessControl());\n\n container.registerFactory(CmsExport, () => createExportCrud(cmsContext));\n container.registerFactory(CmsImport, () => createImportCrud(cmsContext));\n\n // Register CmsSchemaExecutor so proxy resolvers can build and execute the CMS sub-schema.\n container.registerInstance(CmsSchemaExecutor, {\n execute: async (schemaType: ApiEndpoint, body: any) => {\n const bm = container.resolve(BenchmarkAbstraction);\n const schema = await bm.measure(\"headlessCms.graphql.getSchema\", () =>\n identityContext.withoutAuthorization(() =>\n getSchema({ context: cmsContext, getTenant, type: schemaType })\n )\n );\n const requestBody = await bm.measure(\n \"headlessCms.graphql.createRequestBody\",\n async () => createRequestBody(body)\n );\n return bm.measure(\"headlessCms.graphql.processRequestBody\", () =>\n processRequestBody(requestBody, schema, cmsContext)\n );\n }\n });\n\n // Register CMS sub-schema factories: base types (CmsError, CmsIdentity, etc.)\n // and, for manage endpoints, the import/export operations.\n container.registerInstance(CmsGraphQLSchemaFactory, {\n execute: () => createBaseSchemaPlugins(cmsContext)\n });\n // Export/import belongs to the manage schema only; the endpoint is known per request.\n container.registerInstance(CmsGraphQLSchemaFactory, {\n execute: () =>\n container.resolve(HeadlessCmsEndpointConfig).type === \"manage\" ? [exportPlugin] : []\n });\n\n container.registerInstance(EntryToStorageTransform, (model, entry) => {\n return entryToStorageTransform(cmsContext, model, entry);\n });\n container.registerInstance(EntryFromStorageTransform, (model, entry) => {\n return entryFromStorageTransform(cmsContext, model, entry);\n });\n container.registerInstance(SearchableFieldsProvider, params => {\n return getSearchableFields({\n context: cmsContext,\n fields: params.fields,\n input: []\n });\n });\n\n // Every endpoint is served; each route runs its request as its own endpoint type.\n container.register(createCmsRoute(\"manage\"));\n container.register(createCmsRoute(\"read\"));\n container.register(createCmsRoute(\"preview\"));\n }\n});\n"],"names":["HeadlessCmsFeature","createFeature","container","config","CmsBaseErrorTypeFactory","CmsResponseTypeDefsImpl","CmsQueryTypeDefsImpl","CmsMutationTypeDefsImpl","QueryCmsResolverImpl","MutationCmsResolverImpl","GetModelResolverImpl","GetEntryResolverImpl","ListEntriesResolverImpl","CreateEntryResolverImpl","UpdateEntryRevisionResolverImpl","DeleteEntryRevisionResolverImpl","PublishEntryRevisionResolverImpl","UnpublishEntryRevisionResolverImpl","HeadlessCmsEndpointConfig","CompressionFeature","GraphQLFeature","ValidationFeature","StorageFeature","CmsInstallerFeature","ContentEntriesFeature","ContentModelFeature","CmsAiToolsFeature","ContentModelGroupFeature","ModelBuilderFeature","CmsWhereMapperFeature","CmsSortMapperFeature","CmsWebhooksFeature","ModelStorageSyncFeature","registerFieldConverters","pluginsContainer","PluginsContainer","PluginsContainerAbstraction","plugin","CmsModelPlugin","CmsModelPluginInstance","CmsGroupPlugin","CmsGroupPluginInstance","userSchemaPlugins","CmsGraphQLSchemaPlugin","CmsGraphQLSchemaFactory","benchmark","Benchmark","BenchmarkAbstraction","cmsContext","CmsContextAbstraction","CoreGraphQLSchemaFactory","staticSchemaKey","builder","RevisionIdScalar","CmsStorageModelProvider","StorageOperationsCmsModelPlugin","createCmsModelFieldConvertersAttachFactory","identityContext","IdentityContext","tenantContext","TenantContext","getTenant","accessControlInstance","getAccessControl","AccessControl","result","ListGroupsUseCase","AccessControlAbstraction","CmsExport","createExportCrud","CmsImport","createImportCrud","CmsSchemaExecutor","schemaType","body","bm","schema","getSchema","requestBody","createRequestBody","processRequestBody","createBaseSchemaPlugins","exportPlugin","EntryToStorageTransform","model","entry","entryToStorageTransform","EntryFromStorageTransform","entryFromStorageTransform","SearchableFieldsProvider","params","getSearchableFields","createCmsRoute"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwFO,MAAMA,qBAAqBC,cAAiC;IAC/D,MAAM;IACN,UAASC,SAAS,EAAEC,MAAM;QAItBD,UAAU,QAAQ,CAACE;QACnBF,UAAU,QAAQ,CAACG;QACnBH,UAAU,QAAQ,CAACI;QACnBJ,UAAU,QAAQ,CAACK;QACnBL,UAAU,QAAQ,CAACM;QACnBN,UAAU,QAAQ,CAACO;QACnBP,UAAU,QAAQ,CAACQ;QACnBR,UAAU,QAAQ,CAACS;QACnBT,UAAU,QAAQ,CAACU;QACnBV,UAAU,QAAQ,CAACW;QACnBX,UAAU,QAAQ,CAACY;QACnBZ,UAAU,QAAQ,CAACa;QACnBb,UAAU,QAAQ,CAACc;QACnBd,UAAU,QAAQ,CAACe;QAEnBf,UAAU,gBAAgB,CAACgB,2BAA2B;YAClD,MAAMf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oBAAoB,CAAC,IACjCoB,UAAU;4BAAE,SAAS7B;4BAAYa;4BAAW,MAAMY;wBAAW;gBAGrE,MAAMK,cAAc,MAAMH,GAAG,OAAO,CAChC,yCACA,UAAYI,kBAAkBL;gBAElC,OAAOC,GAAG,OAAO,CAAC,0CAA0C,IACxDK,mBAAmBF,aAAaF,QAAQ5B;YAEhD;QACJ;QAIA9C,UAAU,gBAAgB,CAAC0C,yBAAyB;YAChD,SAAS,IAAMqC,wBAAwBjC;QAC3C;QAEA9C,UAAU,gBAAgB,CAAC0C,yBAAyB;YAChD,SAAS,IACL1C,AAAsD,aAAtDA,UAAU,OAAO,CAACgB,2BAA2B,IAAI,GAAgB;oBAACgE;iBAAa,GAAG,EAAE;QAC5F;QAEAhF,UAAU,gBAAgB,CAACiF,yBAAyB,CAACC,OAAOC,QACjDC,wBAAwBtC,YAAYoC,OAAOC;QAEtDnF,UAAU,gBAAgB,CAACqF,2BAA2B,CAACH,OAAOC,QACnDG,0BAA0BxC,YAAYoC,OAAOC;QAExDnF,UAAU,gBAAgB,CAACuF,0BAA0BC,CAAAA,SAC1CC,oBAAoB;gBACvB,SAAS3C;gBACT,QAAQ0C,OAAO,MAAM;gBACrB,OAAO,EAAE;YACb;QAIJxF,UAAU,QAAQ,CAAC0F,eAAe;QAClC1F,UAAU,QAAQ,CAAC0F,eAAe;QAClC1F,UAAU,QAAQ,CAAC0F,eAAe;IACtC;AACJ"}
|
package/createCmsRoute.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { Container } from "@webiny/di";
|
|
2
2
|
import type { IHttpRequest, IHttpResponse } from "@webiny/event-handler-core";
|
|
3
|
-
import type { IGraphQLContextualSchema } from "@webiny/api-graphql";
|
|
4
3
|
import type { ApiEndpoint } from "./types/index.js";
|
|
5
4
|
/**
|
|
6
|
-
* The HTTP route for a CMS GraphQL endpoint (manage/read/preview).
|
|
7
|
-
*
|
|
5
|
+
* The HTTP route for a CMS GraphQL endpoint (manage/read/preview). It executes the CMS sub-schema
|
|
6
|
+
* via CmsSchemaExecutor.
|
|
8
7
|
*/
|
|
9
8
|
export declare function createCmsRoute(type: ApiEndpoint): {
|
|
10
9
|
new (): {
|
|
@@ -12,9 +11,8 @@ export declare function createCmsRoute(type: ApiEndpoint): {
|
|
|
12
11
|
readonly method: "POST";
|
|
13
12
|
readonly path: string;
|
|
14
13
|
readonly handler: {
|
|
15
|
-
new (container: Container
|
|
14
|
+
new (container: Container): {
|
|
16
15
|
container: Container;
|
|
17
|
-
contextualSchemas: IGraphQLContextualSchema[];
|
|
18
16
|
handle(request: IHttpRequest): Promise<IHttpResponse>;
|
|
19
17
|
};
|
|
20
18
|
} & {
|
package/createCmsRoute.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { HttpRouteDefinition, HttpRouteHandler, RequestContainer } from "@webiny/event-handler-core";
|
|
2
|
-
import { GraphQLContextualSchema } from "@webiny/api-graphql";
|
|
3
2
|
import { BenchmarkAbstraction } from "@webiny/api";
|
|
4
3
|
import { CmsSchemaExecutor } from "./graphql/CmsSchemaExecutor.js";
|
|
4
|
+
import { HeadlessCmsEndpointConfig } from "./HeadlessCmsEndpointConfig.js";
|
|
5
|
+
import { checkEndpointAccess } from "./graphql/checkEndpointAccess.js";
|
|
5
6
|
const CMS_PATHS = {
|
|
6
7
|
manage: "/cms/manage",
|
|
7
8
|
read: "/cms/read",
|
|
@@ -9,15 +10,32 @@ const CMS_PATHS = {
|
|
|
9
10
|
};
|
|
10
11
|
function createCmsRoute(type) {
|
|
11
12
|
class CmsGraphQLRoute {
|
|
12
|
-
constructor(container
|
|
13
|
+
constructor(container){
|
|
13
14
|
this.container = container;
|
|
14
|
-
this.contextualSchemas = contextualSchemas;
|
|
15
15
|
}
|
|
16
16
|
async handle(request) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
|
|
17
|
+
this.container.registerInstance(HeadlessCmsEndpointConfig, {
|
|
18
|
+
type
|
|
19
|
+
});
|
|
20
|
+
try {
|
|
21
|
+
await checkEndpointAccess(this.container, type);
|
|
22
|
+
} catch (ex) {
|
|
23
|
+
return {
|
|
24
|
+
statusCode: 401,
|
|
25
|
+
headers: {
|
|
26
|
+
"Content-Type": "application/json"
|
|
27
|
+
},
|
|
28
|
+
body: {
|
|
29
|
+
data: null,
|
|
30
|
+
error: {
|
|
31
|
+
message: ex.message || "Not authorized!",
|
|
32
|
+
code: ex.code || "SECURITY_NOT_AUTHORIZED",
|
|
33
|
+
data: ex.data || null,
|
|
34
|
+
stack: null
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
21
39
|
const result = await this.container.resolve(CmsSchemaExecutor).execute(type, request.body);
|
|
22
40
|
await this.container.resolve(BenchmarkAbstraction).output();
|
|
23
41
|
return {
|
|
@@ -32,13 +50,7 @@ function createCmsRoute(type) {
|
|
|
32
50
|
const implementation = HttpRouteHandler.createImplementation({
|
|
33
51
|
implementation: CmsGraphQLRoute,
|
|
34
52
|
dependencies: [
|
|
35
|
-
RequestContainer
|
|
36
|
-
[
|
|
37
|
-
GraphQLContextualSchema,
|
|
38
|
-
{
|
|
39
|
-
multiple: true
|
|
40
|
-
}
|
|
41
|
-
]
|
|
53
|
+
RequestContainer
|
|
42
54
|
]
|
|
43
55
|
});
|
|
44
56
|
class CmsRouteDefinition {
|
package/createCmsRoute.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createCmsRoute.js","sources":["../src/createCmsRoute.ts"],"sourcesContent":["import type { Container } from \"@webiny/di\";\nimport {\n HttpRouteDefinition,\n HttpRouteHandler,\n RequestContainer\n} from \"@webiny/event-handler-core\";\nimport type { IHttpRequest, IHttpResponse } from \"@webiny/event-handler-core\";\nimport {
|
|
1
|
+
{"version":3,"file":"createCmsRoute.js","sources":["../src/createCmsRoute.ts"],"sourcesContent":["import type { Container } from \"@webiny/di\";\nimport {\n HttpRouteDefinition,\n HttpRouteHandler,\n RequestContainer\n} from \"@webiny/event-handler-core\";\nimport type { IHttpRequest, IHttpResponse } from \"@webiny/event-handler-core\";\nimport { BenchmarkAbstraction } from \"@webiny/api\";\nimport { CmsSchemaExecutor } from \"~/graphql/CmsSchemaExecutor.js\";\nimport type { ApiEndpoint } from \"~/types/index.js\";\nimport { HeadlessCmsEndpointConfig } from \"~/HeadlessCmsEndpointConfig.js\";\nimport { checkEndpointAccess } from \"~/graphql/checkEndpointAccess.js\";\n\nconst CMS_PATHS: Record<ApiEndpoint, string> = {\n manage: \"/cms/manage\",\n read: \"/cms/read\",\n preview: \"/cms/preview\"\n};\n\n/**\n * The HTTP route for a CMS GraphQL endpoint (manage/read/preview). It executes the CMS sub-schema\n * via CmsSchemaExecutor.\n */\nexport function createCmsRoute(type: ApiEndpoint) {\n class CmsGraphQLRoute implements HttpRouteHandler.Interface {\n // public (not private): this class is returned from an exported factory, so its members\n // must be declarable in the emitted .d.ts — private parameter-properties on an exported\n // anonymous class type are a TS4094 error.\n constructor(public container: Container) {}\n\n async handle(request: IHttpRequest): Promise<IHttpResponse> {\n /*\n * The request runs as this endpoint: the schema, reference fields and validation read\n * HeadlessCmsEndpointConfig. The feature registers a default for the whole request;\n * the last instance registered wins.\n */\n this.container.registerInstance(HeadlessCmsEndpointConfig, { type });\n\n try {\n await checkEndpointAccess(this.container, type);\n } catch (ex) {\n return {\n statusCode: 401,\n headers: { \"Content-Type\": \"application/json\" },\n body: {\n data: null,\n error: {\n message: ex.message || \"Not authorized!\",\n code: ex.code || \"SECURITY_NOT_AUTHORIZED\",\n data: ex.data || null,\n stack: null\n }\n }\n };\n }\n\n const result = await this.container\n .resolve(CmsSchemaExecutor)\n .execute(type, request.body);\n // Flush benchmark measurements (no-op unless benchmarking was enabled for the request).\n await this.container.resolve(BenchmarkAbstraction).output();\n return {\n statusCode: 200,\n headers: { \"Content-Type\": \"application/json\" },\n body: result\n };\n }\n }\n\n const implementation = HttpRouteHandler.createImplementation({\n implementation: CmsGraphQLRoute,\n dependencies: [RequestContainer]\n });\n\n class CmsRouteDefinition implements HttpRouteDefinition.Interface {\n readonly name = `cms-${type}`;\n readonly method = \"POST\";\n readonly path = CMS_PATHS[type];\n readonly handler = implementation;\n }\n\n return HttpRouteDefinition.createImplementation({\n implementation: CmsRouteDefinition,\n dependencies: []\n });\n}\n"],"names":["CMS_PATHS","createCmsRoute","type","CmsGraphQLRoute","container","request","HeadlessCmsEndpointConfig","checkEndpointAccess","ex","result","CmsSchemaExecutor","BenchmarkAbstraction","implementation","HttpRouteHandler","RequestContainer","CmsRouteDefinition","HttpRouteDefinition"],"mappings":";;;;;AAaA,MAAMA,YAAyC;IAC3C,QAAQ;IACR,MAAM;IACN,SAAS;AACb;AAMO,SAASC,eAAeC,IAAiB;IAC5C,MAAMC;QAIF,YAAmBC,SAAoB,CAAE;iBAAtBA,SAAS,GAATA;QAAuB;QAE1C,MAAM,OAAOC,OAAqB,EAA0B;YAMxD,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAACC,2BAA2B;gBAAEJ;YAAK;YAElE,IAAI;gBACA,MAAMK,oBAAoB,IAAI,CAAC,SAAS,EAAEL;YAC9C,EAAE,OAAOM,IAAI;gBACT,OAAO;oBACH,YAAY;oBACZ,SAAS;wBAAE,gBAAgB;oBAAmB;oBAC9C,MAAM;wBACF,MAAM;wBACN,OAAO;4BACH,SAASA,GAAG,OAAO,IAAI;4BACvB,MAAMA,GAAG,IAAI,IAAI;4BACjB,MAAMA,GAAG,IAAI,IAAI;4BACjB,OAAO;wBACX;oBACJ;gBACJ;YACJ;YAEA,MAAMC,SAAS,MAAM,IAAI,CAAC,SAAS,CAC9B,OAAO,CAACC,mBACR,OAAO,CAACR,MAAMG,QAAQ,IAAI;YAE/B,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAACM,sBAAsB,MAAM;YACzD,OAAO;gBACH,YAAY;gBACZ,SAAS;oBAAE,gBAAgB;gBAAmB;gBAC9C,MAAMF;YACV;QACJ;IACJ;IAEA,MAAMG,iBAAiBC,iBAAiB,oBAAoB,CAAC;QACzD,gBAAgBV;QAChB,cAAc;YAACW;SAAiB;IACpC;IAEA,MAAMC;;iBACO,IAAI,GAAG,CAAC,IAAI,EAAEb,MAAM;iBACpB,MAAM,GAAG;iBACT,IAAI,GAAGF,SAAS,CAACE,KAAK;iBACtB,OAAO,GAAGU;;IACvB;IAEA,OAAOI,oBAAoB,oBAAoB,CAAC;QAC5C,gBAAgBD;QAChB,cAAc,EAAE;IACpB;AACJ"}
|
|
@@ -8,16 +8,20 @@ const validateValue = async (params, fieldValidators, value)=>{
|
|
|
8
8
|
const name = fieldValidator.name;
|
|
9
9
|
const validations = validatorList[name];
|
|
10
10
|
if (!validations || 0 === validations.length) return `There are no "${name}" validators defined.`;
|
|
11
|
-
for (const
|
|
12
|
-
const
|
|
11
|
+
for (const validation of validations){
|
|
12
|
+
const validateParams = {
|
|
13
13
|
value,
|
|
14
14
|
context,
|
|
15
15
|
validator: fieldValidator,
|
|
16
16
|
field,
|
|
17
17
|
model,
|
|
18
18
|
entry
|
|
19
|
-
}
|
|
20
|
-
|
|
19
|
+
};
|
|
20
|
+
const result = await validation.validate(validateParams);
|
|
21
|
+
if (!result) {
|
|
22
|
+
const message = fieldValidator.message;
|
|
23
|
+
return message && validation.formatMessage ? validation.formatMessage(message, validateParams) : message;
|
|
24
|
+
}
|
|
21
25
|
}
|
|
22
26
|
}
|
|
23
27
|
} catch (ex) {
|
|
@@ -28,8 +32,8 @@ const validateValue = async (params, fieldValidators, value)=>{
|
|
|
28
32
|
const validatePredefinedValue = (field, value)=>{
|
|
29
33
|
const { enabled = false, values: predefinedValues = [] } = field.predefinedValues || {};
|
|
30
34
|
if (!enabled) return null;
|
|
31
|
-
if (false === Array.isArray(predefinedValues) || 0 === predefinedValues.length) return "Missing predefined values to validate against.";
|
|
32
|
-
if ("" === value || null == value) return null;
|
|
35
|
+
else if (false === Array.isArray(predefinedValues) || 0 === predefinedValues.length) return "Missing predefined values to validate against.";
|
|
36
|
+
else if ("" === value || null == value) return null;
|
|
33
37
|
for (const predefinedValue of predefinedValues)if (predefinedValue.value == value) return null;
|
|
34
38
|
return "Value sent does not match any of the available predefined values.";
|
|
35
39
|
};
|
|
@@ -99,9 +103,12 @@ const validateModelEntryData = async (params)=>{
|
|
|
99
103
|
for (const validator of validators){
|
|
100
104
|
const name = validator.name;
|
|
101
105
|
if (!validatorList[name]) validatorList[name] = [];
|
|
102
|
-
validatorList[name].push(
|
|
106
|
+
validatorList[name].push({
|
|
107
|
+
validate: (params)=>validator.validate(params),
|
|
108
|
+
formatMessage: validator.formatMessage ? (message, params)=>validator.formatMessage(message, params) : void 0
|
|
109
|
+
});
|
|
103
110
|
}
|
|
104
|
-
return await
|
|
111
|
+
return await validate({
|
|
105
112
|
validatorList,
|
|
106
113
|
context,
|
|
107
114
|
model,
|
|
@@ -160,8 +167,7 @@ const executeFieldValidation = async (params)=>{
|
|
|
160
167
|
}
|
|
161
168
|
}
|
|
162
169
|
return validations;
|
|
163
|
-
}
|
|
164
|
-
if ("dynamicZone" === field.type) {
|
|
170
|
+
} else if ("dynamicZone" === field.type) {
|
|
165
171
|
const validations = [];
|
|
166
172
|
const error = await execValidation({
|
|
167
173
|
...params,
|
|
@@ -217,7 +223,7 @@ const executeFieldValidation = async (params)=>{
|
|
|
217
223
|
}
|
|
218
224
|
];
|
|
219
225
|
};
|
|
220
|
-
const
|
|
226
|
+
const validate = async (params)=>{
|
|
221
227
|
const { fields } = params;
|
|
222
228
|
const errors = [];
|
|
223
229
|
const results = await Promise.all(fields.map(async (field)=>await executeFieldValidation({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crud/contentEntry/entryDataValidation.js","sources":["../../../src/crud/contentEntry/entryDataValidation.ts"],"sourcesContent":["import type {\n CmsContext,\n CmsDynamicZoneTemplate,\n CmsEntry,\n CmsEntryValues,\n CmsModel,\n CmsModelField,\n CmsModelFieldValidation\n} from \"~/types/index.js\";\nimport { EntryValidationError } from \"~/domain/contentEntry/errors.js\";\nimport {\n type CmsModelFieldValidator,\n CmsModelFieldValidatorRegistry\n} from \"~/features/validation/index.js\";\n\ntype PluginValidationCallable = (\n params: CmsModelFieldValidator.Params\n) => CmsModelFieldValidator.Response;\ntype PluginValidationList = Record<string, PluginValidationCallable[]>;\n\ninterface ExecuteValidationParams<TValues extends CmsEntryValues = CmsEntryValues> {\n validatorList: PluginValidationList;\n field: CmsModelField;\n model: CmsModel;\n values: TValues;\n context: CmsContext;\n entry?: CmsEntry<TValues>;\n}\n\ntype PossibleValue = boolean | number | string | null | undefined;\n\nconst validateValue = async <TValues extends CmsEntryValues = CmsEntryValues>(\n params: ExecuteValidationParams<TValues>,\n fieldValidators: CmsModelFieldValidation[],\n value: PossibleValue | PossibleValue[]\n): Promise<string | null> => {\n if (!fieldValidators) {\n return null;\n }\n const { validatorList, context, field, model, entry } = params;\n try {\n for (const fieldValidator of fieldValidators) {\n const name = fieldValidator.name;\n const validations = validatorList[name];\n if (!validations || validations.length === 0) {\n return `There are no \"${name}\" validators defined.`;\n }\n for (const validate of validations) {\n const result = await validate({\n value,\n context,\n validator: fieldValidator,\n field,\n model,\n entry\n });\n if (!result) {\n return fieldValidator.message;\n }\n }\n }\n } catch (ex) {\n return ex.message;\n }\n\n return null;\n};\n\nconst validatePredefinedValue = (field: CmsModelField, value: any | any[]): string | null => {\n const { enabled = false, values: predefinedValues = [] } = field.predefinedValues || {};\n if (!enabled) {\n return null;\n } else if (Array.isArray(predefinedValues) === false || predefinedValues.length === 0) {\n return \"Missing predefined values to validate against.\";\n } else if (value === \"\" || value === null || value === undefined) {\n return null;\n }\n for (const predefinedValue of predefinedValues) {\n /**\n * No strict compare because the value sent can be 12345 (number) and predefinedValue can be \"12345\" (string),\n * and we want it to match.\n */\n if (predefinedValue.value == value) {\n return null;\n }\n }\n return \"Value sent does not match any of the available predefined values.\";\n};\n\nconst DATE_RE = /^\\d{4}-\\d{2}-\\d{2}$/;\nconst TIME_RE = /^\\d{2}:\\d{2}(:\\d{2})?$/;\nconst DATETIME_RE = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}/;\n\nconst validateDatetimeFormat = (field: CmsModelField, value: any): string | null => {\n if (field.type !== \"datetime\") {\n return null;\n }\n if (value === null || value === undefined || value === \"\") {\n return null;\n }\n if (typeof value !== \"string\") {\n return null;\n }\n\n const dateType = field.settings?.type;\n\n switch (dateType) {\n case \"date\":\n if (!DATE_RE.test(value)) {\n return `Invalid date format for field \"${field.fieldId}\". Expected YYYY-MM-DD.`;\n }\n return null;\n case \"time\":\n if (!TIME_RE.test(value)) {\n return `Invalid time format for field \"${field.fieldId}\". Expected HH:mm or HH:mm:ss.`;\n }\n return null;\n case \"dateTimeWithTimezone\":\n case \"dateTimeWithoutTimezone\":\n if (!DATETIME_RE.test(value)) {\n return `Invalid dateTime format for field \"${field.fieldId}\". Expected ISO 8601 dateTime.`;\n }\n return null;\n default:\n return null;\n }\n};\n\nconst getFieldValidation = (\n listValidation?: CmsModelFieldValidation[]\n): CmsModelFieldValidation[] => {\n if (!listValidation?.length) {\n return [];\n }\n // Filter out the legacy \"dynamicZone\" validator that was never implemented.\n // Existing models may still have it in their persisted listValidation data.\n return listValidation.filter(item => item.name !== \"dynamicZone\");\n};\n/**\n * When multiple values is selected we must run validations on the array containing the values\n * And then on each value in the array\n */\nconst runFieldMultipleValuesValidations = async <TValues extends CmsEntryValues = CmsEntryValues>(\n params: ExecuteValidationParams<TValues>\n): Promise<string | null> => {\n const { field, values: initialValues } = params;\n const values = initialValues[field.fieldId as keyof TValues] as\n | PossibleValue[]\n | null\n | undefined;\n const valuesError = await validateValue(\n params,\n getFieldValidation(field.listValidation),\n values\n );\n if (valuesError) {\n return valuesError;\n }\n if (values === null || values === undefined) {\n return null;\n }\n for (const value of values) {\n const datetimeError = validateDatetimeFormat(field, value);\n if (datetimeError) {\n return datetimeError;\n }\n const valueError = await validateValue(params, getFieldValidation(field.validation), value);\n if (valueError) {\n return valueError;\n }\n const predefinedValueError = validatePredefinedValue(field, value);\n if (predefinedValueError) {\n return predefinedValueError;\n }\n }\n return null;\n};\n/**\n * Runs validation on given value.\n */\nconst runFieldValueValidations = async <TValues extends CmsEntryValues = CmsEntryValues>(\n params: ExecuteValidationParams<TValues>\n): Promise<string | null> => {\n const { values, field } = params;\n const value = values[field.fieldId as keyof TValues];\n const datetimeError = validateDatetimeFormat(field, value);\n if (datetimeError) {\n return datetimeError;\n }\n const error = await validateValue(params, field.validation || [], value);\n if (error) {\n return error;\n }\n return validatePredefinedValue(field, value);\n};\n\nconst execValidation = async (params: ExecuteValidationParams): Promise<string | null> => {\n const { field } = params;\n if (field.list) {\n return await runFieldMultipleValuesValidations(params);\n }\n return await runFieldValueValidations(params);\n};\n\ninterface IValidateModelEntryDataParams<TValues extends CmsEntryValues = CmsEntryValues> {\n context: CmsContext;\n model: CmsModel;\n values: TValues;\n entry?: CmsEntry<TValues>;\n skipValidation?: boolean;\n}\n\nexport const validateModelEntryData = async <TValues extends CmsEntryValues = CmsEntryValues>(\n params: IValidateModelEntryDataParams<TValues>\n) => {\n const { context, model, entry, values, skipValidation } = params;\n\n if (skipValidation) {\n return [];\n }\n\n const validatorList: PluginValidationList = {};\n const registry = context.container.resolve(CmsModelFieldValidatorRegistry);\n const validators = registry.getAll();\n for (const validator of validators) {\n const name = validator.name;\n if (!validatorList[name]) {\n validatorList[name] = [];\n }\n validatorList[name].push(params => {\n return validator.validate(params);\n });\n }\n\n return await validate<TValues>({\n validatorList,\n context,\n model,\n entry,\n parents: [],\n fields: model.fields,\n values: {\n ...entry?.values,\n ...values\n }\n });\n};\n\nexport const validateModelEntryDataOrThrow = async <\n TValues extends CmsEntryValues = CmsEntryValues\n>(\n params: IValidateModelEntryDataParams<TValues>\n) => {\n const invalidFields = await validateModelEntryData(params);\n if (invalidFields.length === 0) {\n return;\n }\n throw new EntryValidationError(\"Validation failed.\", invalidFields);\n};\n\n/**\n *\n */\ninterface FieldError {\n id: string;\n fieldId: string;\n storageId: string;\n error: any;\n parents: string[];\n}\n\ninterface ValidateFieldParams<TValues extends CmsEntryValues = CmsEntryValues> {\n validatorList: PluginValidationList;\n parents: string[];\n model: CmsModel;\n values: TValues;\n context: CmsContext;\n field: CmsModelField;\n entry?: CmsEntry<TValues>;\n}\n\nconst executeFieldValidation = async <TValues extends CmsEntryValues = CmsEntryValues>(\n params: ValidateFieldParams<TValues>\n): Promise<FieldError[]> => {\n // TODO put per-field validation into plugins.\n const { field } = params;\n /**\n * Object field.\n */\n if (field.type === \"object\") {\n const fields = field.settings?.fields;\n if (!Array.isArray(fields)) {\n return [];\n }\n const validations: FieldError[] = [];\n /**\n * We need to validate the object field as well.\n */\n const error = await execValidation({\n ...params,\n field\n });\n if (error) {\n validations.push({\n id: field.id,\n fieldId: field.fieldId,\n storageId: field.storageId,\n error,\n parents: params.parents\n });\n }\n const objectValue = params.values[field.fieldId as keyof TValues];\n if (!objectValue) {\n return validations;\n }\n const values = (Array.isArray(objectValue) ? objectValue : [objectValue]) as TValues[];\n for (const index in values) {\n const parents = field.list ? [field.fieldId, index] : [field.fieldId];\n const value = values[index] as TValues;\n for (const childField of fields) {\n const errors = await executeFieldValidation<typeof value>({\n ...params,\n parents: params.parents.concat(parents),\n field: childField,\n values: value\n });\n if (errors.length === 0) {\n continue;\n }\n validations.push(...errors);\n }\n }\n return validations;\n }\n /**\n * Dynamic Zone Field\n */\n //\n else if (field.type === \"dynamicZone\") {\n const validations: FieldError[] = [];\n\n const error = await execValidation({\n ...params,\n field\n });\n if (error) {\n validations.push({\n id: field.id,\n fieldId: field.fieldId,\n storageId: field.storageId,\n error,\n parents: params.parents\n });\n }\n\n const templates = (field.settings?.templates || []) as CmsDynamicZoneTemplate[];\n for (const template of templates) {\n const fields = template.fields;\n const fieldData = params.values[field.fieldId as keyof TValues];\n if (!fieldData) {\n continue;\n }\n const values: TValues[keyof TValues][] = Array.isArray(fieldData)\n ? fieldData\n : [fieldData];\n for (const index in values) {\n const templateValue = values[index]?.[template.gqlTypeName];\n if (!templateValue) {\n continue;\n }\n /**\n * Order of the parents must be\n * - fieldId\n * - index (if multiple values)\n * - gqlTypeName\n */\n const parents = [field.fieldId];\n if (field.list) {\n parents.push(index);\n }\n parents.push(template.gqlTypeName);\n for (const childField of fields) {\n const errors = await executeFieldValidation({\n ...params,\n parents: params.parents.concat(parents),\n field: childField,\n values: templateValue\n });\n if (errors.length === 0) {\n continue;\n }\n validations.push(...errors);\n }\n }\n }\n\n return validations;\n }\n const error = await execValidation({\n ...params\n });\n if (!error) {\n return [];\n }\n return [\n {\n id: field.id,\n fieldId: field.fieldId,\n storageId: field.storageId,\n error,\n parents: params.parents\n }\n ];\n};\n\ninterface ValidateFieldsParams<TValues extends CmsEntryValues = CmsEntryValues> {\n validatorList: PluginValidationList;\n parents: string[];\n model: CmsModel;\n values: TValues;\n fields: CmsModelField[];\n context: CmsContext;\n entry?: CmsEntry<TValues>;\n}\n\nconst validate = async <TValues extends CmsEntryValues = CmsEntryValues>(\n params: ValidateFieldsParams<TValues>\n): Promise<FieldError[]> => {\n const { fields } = params;\n const errors: FieldError[] = [];\n\n const results = await Promise.all(\n fields.map(async field => {\n return await executeFieldValidation<TValues>({\n ...params,\n field\n });\n })\n );\n\n for (const result of results) {\n if (result.length === 0) {\n continue;\n }\n errors.push(...result);\n }\n return errors;\n};\n"],"names":["validateValue","params","fieldValidators","value","validatorList","context","field","model","entry","fieldValidator","name","validations","validate","result","ex","validatePredefinedValue","enabled","predefinedValues","Array","predefinedValue","DATE_RE","TIME_RE","DATETIME_RE","validateDatetimeFormat","dateType","getFieldValidation","listValidation","item","runFieldMultipleValuesValidations","initialValues","values","valuesError","datetimeError","valueError","predefinedValueError","runFieldValueValidations","error","execValidation","validateModelEntryData","skipValidation","registry","CmsModelFieldValidatorRegistry","validators","validator","validateModelEntryDataOrThrow","invalidFields","EntryValidationError","executeFieldValidation","fields","objectValue","index","parents","childField","errors","templates","template","fieldData","templateValue","results","Promise"],"mappings":";;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OACD,OAAO,EAAE;IAEb,OAAO;QACH;YACI,IAAI9B,MAAM,EAAE;YACZ,SAASA,MAAM,OAAO;YACtB,WAAWA,MAAM,SAAS;YAC1B8B;YACA,SAASnC,OAAO,OAAO;QAC3B;KACH;AACL;AAYA,MAAMW,+BAAW,OACbX;IAEA,MAAM,EAAE+C,MAAM,EAAE,GAAG/C;IACnB,MAAMoD,SAAuB,EAAE;IAE/B,MAAMK,UAAU,MAAMC,QAAQ,GAAG,CAC7BX,OAAO,GAAG,CAAC,OAAM1C,QACN,MAAMyC,uBAAgC;YACzC,GAAG9C,MAAM;YACTK;QACJ;IAIR,KAAK,MAAMO,UAAU6C,QACjB,IAAI7C,AAAkB,MAAlBA,OAAO,MAAM,EAGjBwC,OAAO,IAAI,IAAIxC;IAEnB,OAAOwC;AACX"}
|
|
1
|
+
{"version":3,"file":"crud/contentEntry/entryDataValidation.js","sources":["../../../src/crud/contentEntry/entryDataValidation.ts"],"sourcesContent":["import type {\n CmsContext,\n CmsDynamicZoneTemplate,\n CmsEntry,\n CmsEntryValues,\n CmsModel,\n CmsModelField,\n CmsModelFieldValidation\n} from \"~/types/index.js\";\nimport { EntryValidationError } from \"~/domain/contentEntry/errors.js\";\nimport {\n type CmsModelFieldValidator,\n CmsModelFieldValidatorRegistry\n} from \"~/features/validation/index.js\";\n\ntype PluginValidationList = Record<\n string,\n Pick<CmsModelFieldValidator.Interface, \"validate\" | \"formatMessage\">[]\n>;\n\ninterface ExecuteValidationParams<TValues extends CmsEntryValues = CmsEntryValues> {\n validatorList: PluginValidationList;\n field: CmsModelField;\n model: CmsModel;\n values: TValues;\n context: CmsContext;\n entry?: CmsEntry<TValues>;\n}\n\ntype PossibleValue = boolean | number | string | null | undefined;\n\nconst validateValue = async <TValues extends CmsEntryValues = CmsEntryValues>(\n params: ExecuteValidationParams<TValues>,\n fieldValidators: CmsModelFieldValidation[],\n value: PossibleValue | PossibleValue[]\n): Promise<string | null> => {\n if (!fieldValidators) {\n return null;\n }\n const { validatorList, context, field, model, entry } = params;\n try {\n for (const fieldValidator of fieldValidators) {\n const name = fieldValidator.name;\n const validations = validatorList[name];\n if (!validations || validations.length === 0) {\n return `There are no \"${name}\" validators defined.`;\n }\n for (const validation of validations) {\n const validateParams: CmsModelFieldValidator.Params = {\n value,\n context,\n validator: fieldValidator,\n field,\n model,\n entry\n };\n const result = await validation.validate(validateParams);\n if (!result) {\n const message = fieldValidator.message;\n return message && validation.formatMessage\n ? validation.formatMessage(message, validateParams)\n : message;\n }\n }\n }\n } catch (ex) {\n return ex.message;\n }\n\n return null;\n};\n\nconst validatePredefinedValue = (field: CmsModelField, value: any | any[]): string | null => {\n const { enabled = false, values: predefinedValues = [] } = field.predefinedValues || {};\n if (!enabled) {\n return null;\n } else if (Array.isArray(predefinedValues) === false || predefinedValues.length === 0) {\n return \"Missing predefined values to validate against.\";\n } else if (value === \"\" || value === null || value === undefined) {\n return null;\n }\n for (const predefinedValue of predefinedValues) {\n /**\n * No strict compare because the value sent can be 12345 (number) and predefinedValue can be \"12345\" (string),\n * and we want it to match.\n */\n if (predefinedValue.value == value) {\n return null;\n }\n }\n return \"Value sent does not match any of the available predefined values.\";\n};\n\nconst DATE_RE = /^\\d{4}-\\d{2}-\\d{2}$/;\nconst TIME_RE = /^\\d{2}:\\d{2}(:\\d{2})?$/;\nconst DATETIME_RE = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}/;\n\nconst validateDatetimeFormat = (field: CmsModelField, value: any): string | null => {\n if (field.type !== \"datetime\") {\n return null;\n }\n if (value === null || value === undefined || value === \"\") {\n return null;\n }\n if (typeof value !== \"string\") {\n return null;\n }\n\n const dateType = field.settings?.type;\n\n switch (dateType) {\n case \"date\":\n if (!DATE_RE.test(value)) {\n return `Invalid date format for field \"${field.fieldId}\". Expected YYYY-MM-DD.`;\n }\n return null;\n case \"time\":\n if (!TIME_RE.test(value)) {\n return `Invalid time format for field \"${field.fieldId}\". Expected HH:mm or HH:mm:ss.`;\n }\n return null;\n case \"dateTimeWithTimezone\":\n case \"dateTimeWithoutTimezone\":\n if (!DATETIME_RE.test(value)) {\n return `Invalid dateTime format for field \"${field.fieldId}\". Expected ISO 8601 dateTime.`;\n }\n return null;\n default:\n return null;\n }\n};\n\nconst getFieldValidation = (\n listValidation?: CmsModelFieldValidation[]\n): CmsModelFieldValidation[] => {\n if (!listValidation?.length) {\n return [];\n }\n // Filter out the legacy \"dynamicZone\" validator that was never implemented.\n // Existing models may still have it in their persisted listValidation data.\n return listValidation.filter(item => item.name !== \"dynamicZone\");\n};\n/**\n * When multiple values is selected we must run validations on the array containing the values\n * And then on each value in the array\n */\nconst runFieldMultipleValuesValidations = async <TValues extends CmsEntryValues = CmsEntryValues>(\n params: ExecuteValidationParams<TValues>\n): Promise<string | null> => {\n const { field, values: initialValues } = params;\n const values = initialValues[field.fieldId as keyof TValues] as\n | PossibleValue[]\n | null\n | undefined;\n const valuesError = await validateValue(\n params,\n getFieldValidation(field.listValidation),\n values\n );\n if (valuesError) {\n return valuesError;\n }\n if (values === null || values === undefined) {\n return null;\n }\n for (const value of values) {\n const datetimeError = validateDatetimeFormat(field, value);\n if (datetimeError) {\n return datetimeError;\n }\n const valueError = await validateValue(params, getFieldValidation(field.validation), value);\n if (valueError) {\n return valueError;\n }\n const predefinedValueError = validatePredefinedValue(field, value);\n if (predefinedValueError) {\n return predefinedValueError;\n }\n }\n return null;\n};\n/**\n * Runs validation on given value.\n */\nconst runFieldValueValidations = async <TValues extends CmsEntryValues = CmsEntryValues>(\n params: ExecuteValidationParams<TValues>\n): Promise<string | null> => {\n const { values, field } = params;\n const value = values[field.fieldId as keyof TValues];\n const datetimeError = validateDatetimeFormat(field, value);\n if (datetimeError) {\n return datetimeError;\n }\n const error = await validateValue(params, field.validation || [], value);\n if (error) {\n return error;\n }\n return validatePredefinedValue(field, value);\n};\n\nconst execValidation = async (params: ExecuteValidationParams): Promise<string | null> => {\n const { field } = params;\n if (field.list) {\n return await runFieldMultipleValuesValidations(params);\n }\n return await runFieldValueValidations(params);\n};\n\ninterface IValidateModelEntryDataParams<TValues extends CmsEntryValues = CmsEntryValues> {\n context: CmsContext;\n model: CmsModel;\n values: TValues;\n entry?: CmsEntry<TValues>;\n skipValidation?: boolean;\n}\n\nexport const validateModelEntryData = async <TValues extends CmsEntryValues = CmsEntryValues>(\n params: IValidateModelEntryDataParams<TValues>\n) => {\n const { context, model, entry, values, skipValidation } = params;\n\n if (skipValidation) {\n return [];\n }\n\n const validatorList: PluginValidationList = {};\n const registry = context.container.resolve(CmsModelFieldValidatorRegistry);\n const validators = registry.getAll();\n for (const validator of validators) {\n const name = validator.name;\n if (!validatorList[name]) {\n validatorList[name] = [];\n }\n validatorList[name].push({\n validate: params => validator.validate(params),\n formatMessage: validator.formatMessage\n ? (message, params) => validator.formatMessage!(message, params)\n : undefined\n });\n }\n\n return await validate<TValues>({\n validatorList,\n context,\n model,\n entry,\n parents: [],\n fields: model.fields,\n values: {\n ...entry?.values,\n ...values\n }\n });\n};\n\nexport const validateModelEntryDataOrThrow = async <\n TValues extends CmsEntryValues = CmsEntryValues\n>(\n params: IValidateModelEntryDataParams<TValues>\n) => {\n const invalidFields = await validateModelEntryData(params);\n if (invalidFields.length === 0) {\n return;\n }\n throw new EntryValidationError(\"Validation failed.\", invalidFields);\n};\n\n/**\n *\n */\ninterface FieldError {\n id: string;\n fieldId: string;\n storageId: string;\n error: any;\n parents: string[];\n}\n\ninterface ValidateFieldParams<TValues extends CmsEntryValues = CmsEntryValues> {\n validatorList: PluginValidationList;\n parents: string[];\n model: CmsModel;\n values: TValues;\n context: CmsContext;\n field: CmsModelField;\n entry?: CmsEntry<TValues>;\n}\n\nconst executeFieldValidation = async <TValues extends CmsEntryValues = CmsEntryValues>(\n params: ValidateFieldParams<TValues>\n): Promise<FieldError[]> => {\n // TODO put per-field validation into plugins.\n const { field } = params;\n /**\n * Object field.\n */\n if (field.type === \"object\") {\n const fields = field.settings?.fields;\n if (!Array.isArray(fields)) {\n return [];\n }\n const validations: FieldError[] = [];\n /**\n * We need to validate the object field as well.\n */\n const error = await execValidation({\n ...params,\n field\n });\n if (error) {\n validations.push({\n id: field.id,\n fieldId: field.fieldId,\n storageId: field.storageId,\n error,\n parents: params.parents\n });\n }\n const objectValue = params.values[field.fieldId as keyof TValues];\n if (!objectValue) {\n return validations;\n }\n const values = (Array.isArray(objectValue) ? objectValue : [objectValue]) as TValues[];\n for (const index in values) {\n const parents = field.list ? [field.fieldId, index] : [field.fieldId];\n const value = values[index] as TValues;\n for (const childField of fields) {\n const errors = await executeFieldValidation<typeof value>({\n ...params,\n parents: params.parents.concat(parents),\n field: childField,\n values: value\n });\n if (errors.length === 0) {\n continue;\n }\n validations.push(...errors);\n }\n }\n return validations;\n }\n /**\n * Dynamic Zone Field\n */\n //\n else if (field.type === \"dynamicZone\") {\n const validations: FieldError[] = [];\n\n const error = await execValidation({\n ...params,\n field\n });\n if (error) {\n validations.push({\n id: field.id,\n fieldId: field.fieldId,\n storageId: field.storageId,\n error,\n parents: params.parents\n });\n }\n\n const templates = (field.settings?.templates || []) as CmsDynamicZoneTemplate[];\n for (const template of templates) {\n const fields = template.fields;\n const fieldData = params.values[field.fieldId as keyof TValues];\n if (!fieldData) {\n continue;\n }\n const values: TValues[keyof TValues][] = Array.isArray(fieldData)\n ? fieldData\n : [fieldData];\n for (const index in values) {\n const templateValue = values[index]?.[template.gqlTypeName];\n if (!templateValue) {\n continue;\n }\n /**\n * Order of the parents must be\n * - fieldId\n * - index (if multiple values)\n * - gqlTypeName\n */\n const parents = [field.fieldId];\n if (field.list) {\n parents.push(index);\n }\n parents.push(template.gqlTypeName);\n for (const childField of fields) {\n const errors = await executeFieldValidation({\n ...params,\n parents: params.parents.concat(parents),\n field: childField,\n values: templateValue\n });\n if (errors.length === 0) {\n continue;\n }\n validations.push(...errors);\n }\n }\n }\n\n return validations;\n }\n const error = await execValidation({\n ...params\n });\n if (!error) {\n return [];\n }\n return [\n {\n id: field.id,\n fieldId: field.fieldId,\n storageId: field.storageId,\n error,\n parents: params.parents\n }\n ];\n};\n\ninterface ValidateFieldsParams<TValues extends CmsEntryValues = CmsEntryValues> {\n validatorList: PluginValidationList;\n parents: string[];\n model: CmsModel;\n values: TValues;\n fields: CmsModelField[];\n context: CmsContext;\n entry?: CmsEntry<TValues>;\n}\n\nconst validate = async <TValues extends CmsEntryValues = CmsEntryValues>(\n params: ValidateFieldsParams<TValues>\n): Promise<FieldError[]> => {\n const { fields } = params;\n const errors: FieldError[] = [];\n\n const results = await Promise.all(\n fields.map(async field => {\n return await executeFieldValidation<TValues>({\n ...params,\n field\n });\n })\n );\n\n for (const result of results) {\n if (result.length === 0) {\n continue;\n }\n errors.push(...result);\n }\n return errors;\n};\n"],"names":["validateValue","params","fieldValidators","value","validatorList","context","field","model","entry","fieldValidator","name","validations","validation","validateParams","result","message","ex","validatePredefinedValue","enabled","predefinedValues","Array","predefinedValue","DATE_RE","TIME_RE","DATETIME_RE","validateDatetimeFormat","dateType","getFieldValidation","listValidation","item","runFieldMultipleValuesValidations","initialValues","values","valuesError","datetimeError","valueError","predefinedValueError","runFieldValueValidations","error","execValidation","validateModelEntryData","skipValidation","registry","CmsModelFieldValidatorRegistry","validators","validator","undefined","validate","validateModelEntryDataOrThrow","invalidFields","EntryValidationError","executeFieldValidation","fields","objectValue","index","parents","childField","errors","templates","template","fieldData","templateValue","results","Promise"],"mappings":";;AA+BA,MAAMA,gBAAgB,OAClBC,QACAC,iBACAC;IAEA,IAAI,CAACD,iBACD,OAAO;IAEX,MAAM,EAAEE,aAAa,EAAEC,OAAO,EAAEC,KAAK,EAAEC,KAAK,EAAEC,KAAK,EAAE,GAAGP;IACxD,IAAI;QACA,KAAK,MAAMQ,kBAAkBP,gBAAiB;YAC1C,MAAMQ,OAAOD,eAAe,IAAI;YAChC,MAAME,cAAcP,aAAa,CAACM,KAAK;YACvC,IAAI,CAACC,eAAeA,AAAuB,MAAvBA,YAAY,MAAM,EAClC,OAAO,CAAC,cAAc,EAAED,KAA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AO,OAAO;QAC3B;KACH;AACL;AAYA,MAAM8C,WAAW,OACb9C;IAEA,MAAM,EAAEmD,MAAM,EAAE,GAAGnD;IACnB,MAAMwD,SAAuB,EAAE;IAE/B,MAAMK,UAAU,MAAMC,QAAQ,GAAG,CAC7BX,OAAO,GAAG,CAAC,OAAM9C,QACN,MAAM6C,uBAAgC;YACzC,GAAGlD,MAAM;YACTK;QACJ;IAIR,KAAK,MAAMQ,UAAUgD,QACjB,IAAIhD,AAAkB,MAAlBA,OAAO,MAAM,EAGjB2C,OAAO,IAAI,IAAI3C;IAEnB,OAAO2C;AACX"}
|
|
@@ -6,7 +6,7 @@ const validateEndingAllowed = (params)=>{
|
|
|
6
6
|
input: model.singularApiName,
|
|
7
7
|
disallowedEnding: disallowedEnding
|
|
8
8
|
});
|
|
9
|
-
if (false === isModelEndingAllowed(model.pluralApiName)) throw new error(`Content model with pluralApiName "${model.pluralApiName}" is not allowed, as it ends in disallowed value.`, "MODEL_PLURAL_API_NAME_NOT_ENDING_ALLOWED", {
|
|
9
|
+
else if (false === isModelEndingAllowed(model.pluralApiName)) throw new error(`Content model with pluralApiName "${model.pluralApiName}" is not allowed, as it ends in disallowed value.`, "MODEL_PLURAL_API_NAME_NOT_ENDING_ALLOWED", {
|
|
10
10
|
input: model.pluralApiName,
|
|
11
11
|
disallowedEnding: disallowedEnding
|
|
12
12
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crud/contentModel/validate/endingAllowed.js","sources":["../../../../src/crud/contentModel/validate/endingAllowed.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { disallowedEnding, isModelEndingAllowed } from \"./isModelEndingAllowed.js\";\nimport type { CmsModel } from \"~/types/index.js\";\n\ninterface Params {\n model: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n}\n\nexport const validateEndingAllowed = (params: Params): void => {\n const { model } = params;\n if (isModelEndingAllowed(model.singularApiName) === false) {\n throw new WebinyError(\n `Content model with singularApiName \"${model.singularApiName}\" is not allowed, as it ends in disallowed value.`,\n \"MODEL_SINGULAR_API_NAME_ENDING_NOT_ALLOWED\",\n {\n input: model.singularApiName,\n disallowedEnding\n }\n );\n } else if (isModelEndingAllowed(model.pluralApiName) === false) {\n throw new WebinyError(\n `Content model with pluralApiName \"${model.pluralApiName}\" is not allowed, as it ends in disallowed value.`,\n \"MODEL_PLURAL_API_NAME_NOT_ENDING_ALLOWED\",\n {\n input: model.pluralApiName,\n disallowedEnding: disallowedEnding\n }\n );\n }\n};\n"],"names":["validateEndingAllowed","params","model","isModelEndingAllowed","WebinyError","disallowedEnding"],"mappings":";;AAQO,MAAMA,wBAAwB,CAACC;IAClC,MAAM,EAAEC,KAAK,EAAE,GAAGD;IAClB,IAAIE,AAAgD,UAAhDA,qBAAqBD,MAAM,eAAe,GAC1C,MAAM,IAAIE,MACN,CAAC,oCAAoC,EAAEF,MAAM,eAAe,CAAC,iDAAiD,CAAC,EAC/G,8CACA;QACI,OAAOA,MAAM,eAAe;QAC5BG,kBAAgBA;IACpB;
|
|
1
|
+
{"version":3,"file":"crud/contentModel/validate/endingAllowed.js","sources":["../../../../src/crud/contentModel/validate/endingAllowed.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { disallowedEnding, isModelEndingAllowed } from \"./isModelEndingAllowed.js\";\nimport type { CmsModel } from \"~/types/index.js\";\n\ninterface Params {\n model: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n}\n\nexport const validateEndingAllowed = (params: Params): void => {\n const { model } = params;\n if (isModelEndingAllowed(model.singularApiName) === false) {\n throw new WebinyError(\n `Content model with singularApiName \"${model.singularApiName}\" is not allowed, as it ends in disallowed value.`,\n \"MODEL_SINGULAR_API_NAME_ENDING_NOT_ALLOWED\",\n {\n input: model.singularApiName,\n disallowedEnding\n }\n );\n } else if (isModelEndingAllowed(model.pluralApiName) === false) {\n throw new WebinyError(\n `Content model with pluralApiName \"${model.pluralApiName}\" is not allowed, as it ends in disallowed value.`,\n \"MODEL_PLURAL_API_NAME_NOT_ENDING_ALLOWED\",\n {\n input: model.pluralApiName,\n disallowedEnding: disallowedEnding\n }\n );\n }\n};\n"],"names":["validateEndingAllowed","params","model","isModelEndingAllowed","WebinyError","disallowedEnding"],"mappings":";;AAQO,MAAMA,wBAAwB,CAACC;IAClC,MAAM,EAAEC,KAAK,EAAE,GAAGD;IAClB,IAAIE,AAAgD,UAAhDA,qBAAqBD,MAAM,eAAe,GAC1C,MAAM,IAAIE,MACN,CAAC,oCAAoC,EAAEF,MAAM,eAAe,CAAC,iDAAiD,CAAC,EAC/G,8CACA;QACI,OAAOA,MAAM,eAAe;QAC5BG,kBAAgBA;IACpB;SAED,IAAIF,AAA8C,UAA9CA,qBAAqBD,MAAM,aAAa,GAC/C,MAAM,IAAIE,MACN,CAAC,kCAAkC,EAAEF,MAAM,aAAa,CAAC,iDAAiD,CAAC,EAC3G,4CACA;QACI,OAAOA,MAAM,aAAa;QAC1B,kBAAkBG;IACtB;AAGZ"}
|
|
@@ -4,7 +4,7 @@ const validatePluralApiName = (params)=>{
|
|
|
4
4
|
if (existingModel.singularApiName === model.pluralApiName) throw new error(`Content model with singularApiName "${model.pluralApiName}" already exists.`, "MODEL_SINGULAR_API_NAME_EXISTS", {
|
|
5
5
|
input: model.pluralApiName
|
|
6
6
|
});
|
|
7
|
-
if (existingModel.pluralApiName === model.pluralApiName) throw new error(`Content model with pluralApiName "${model.pluralApiName}" already exists.`, "MODEL_PLURAL_API_NAME_EXISTS", {
|
|
7
|
+
else if (existingModel.pluralApiName === model.pluralApiName) throw new error(`Content model with pluralApiName "${model.pluralApiName}" already exists.`, "MODEL_PLURAL_API_NAME_EXISTS", {
|
|
8
8
|
input: model.pluralApiName
|
|
9
9
|
});
|
|
10
10
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crud/contentModel/validate/pluralApiName.js","sources":["../../../../src/crud/contentModel/validate/pluralApiName.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsModel } from \"~/types/index.js\";\n\ninterface Params {\n existingModel: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n model: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n}\n\nexport const validatePluralApiName = (params: Params): void => {\n const { existingModel, model } = params;\n\n if (existingModel.singularApiName === model.pluralApiName) {\n throw new WebinyError(\n `Content model with singularApiName \"${model.pluralApiName}\" already exists.`,\n \"MODEL_SINGULAR_API_NAME_EXISTS\",\n {\n input: model.pluralApiName\n }\n );\n } else if (existingModel.pluralApiName === model.pluralApiName) {\n throw new WebinyError(\n `Content model with pluralApiName \"${model.pluralApiName}\" already exists.`,\n \"MODEL_PLURAL_API_NAME_EXISTS\",\n {\n input: model.pluralApiName\n }\n );\n }\n};\n"],"names":["validatePluralApiName","params","existingModel","model","WebinyError"],"mappings":";AAQO,MAAMA,wBAAwB,CAACC;IAClC,MAAM,EAAEC,aAAa,EAAEC,KAAK,EAAE,GAAGF;IAEjC,IAAIC,cAAc,eAAe,KAAKC,MAAM,aAAa,EACrD,MAAM,IAAIC,MACN,CAAC,oCAAoC,EAAED,MAAM,aAAa,CAAC,iBAAiB,CAAC,EAC7E,kCACA;QACI,OAAOA,MAAM,aAAa;IAC9B;
|
|
1
|
+
{"version":3,"file":"crud/contentModel/validate/pluralApiName.js","sources":["../../../../src/crud/contentModel/validate/pluralApiName.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsModel } from \"~/types/index.js\";\n\ninterface Params {\n existingModel: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n model: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n}\n\nexport const validatePluralApiName = (params: Params): void => {\n const { existingModel, model } = params;\n\n if (existingModel.singularApiName === model.pluralApiName) {\n throw new WebinyError(\n `Content model with singularApiName \"${model.pluralApiName}\" already exists.`,\n \"MODEL_SINGULAR_API_NAME_EXISTS\",\n {\n input: model.pluralApiName\n }\n );\n } else if (existingModel.pluralApiName === model.pluralApiName) {\n throw new WebinyError(\n `Content model with pluralApiName \"${model.pluralApiName}\" already exists.`,\n \"MODEL_PLURAL_API_NAME_EXISTS\",\n {\n input: model.pluralApiName\n }\n );\n }\n};\n"],"names":["validatePluralApiName","params","existingModel","model","WebinyError"],"mappings":";AAQO,MAAMA,wBAAwB,CAACC;IAClC,MAAM,EAAEC,aAAa,EAAEC,KAAK,EAAE,GAAGF;IAEjC,IAAIC,cAAc,eAAe,KAAKC,MAAM,aAAa,EACrD,MAAM,IAAIC,MACN,CAAC,oCAAoC,EAAED,MAAM,aAAa,CAAC,iBAAiB,CAAC,EAC7E,kCACA;QACI,OAAOA,MAAM,aAAa;IAC9B;SAED,IAAID,cAAc,aAAa,KAAKC,MAAM,aAAa,EAC1D,MAAM,IAAIC,MACN,CAAC,kCAAkC,EAAED,MAAM,aAAa,CAAC,iBAAiB,CAAC,EAC3E,gCACA;QACI,OAAOA,MAAM,aAAa;IAC9B;AAGZ"}
|
|
@@ -4,7 +4,7 @@ const validateSingularApiName = (params)=>{
|
|
|
4
4
|
if (existingModel.singularApiName === model.singularApiName) throw new error(`Content model with singularApiName "${model.singularApiName}" already exists.`, "MODEL_SINGULAR_API_NAME_EXISTS", {
|
|
5
5
|
input: model.singularApiName
|
|
6
6
|
});
|
|
7
|
-
if (existingModel.pluralApiName === model.singularApiName) throw new error(`Content model with pluralApiName "${model.singularApiName}" already exists.`, "MODEL_PLURAL_API_NAME_EXISTS", {
|
|
7
|
+
else if (existingModel.pluralApiName === model.singularApiName) throw new error(`Content model with pluralApiName "${model.singularApiName}" already exists.`, "MODEL_PLURAL_API_NAME_EXISTS", {
|
|
8
8
|
input: model.singularApiName
|
|
9
9
|
});
|
|
10
10
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crud/contentModel/validate/singularApiName.js","sources":["../../../../src/crud/contentModel/validate/singularApiName.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsModel } from \"~/types/index.js\";\n\ninterface Params {\n existingModel: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n model: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n}\n\nexport const validateSingularApiName = (params: Params): void => {\n const { existingModel, model } = params;\n\n if (existingModel.singularApiName === model.singularApiName) {\n throw new WebinyError(\n `Content model with singularApiName \"${model.singularApiName}\" already exists.`,\n \"MODEL_SINGULAR_API_NAME_EXISTS\",\n {\n input: model.singularApiName\n }\n );\n } else if (existingModel.pluralApiName === model.singularApiName) {\n throw new WebinyError(\n `Content model with pluralApiName \"${model.singularApiName}\" already exists.`,\n \"MODEL_PLURAL_API_NAME_EXISTS\",\n {\n input: model.singularApiName\n }\n );\n }\n};\n"],"names":["validateSingularApiName","params","existingModel","model","WebinyError"],"mappings":";AAQO,MAAMA,0BAA0B,CAACC;IACpC,MAAM,EAAEC,aAAa,EAAEC,KAAK,EAAE,GAAGF;IAEjC,IAAIC,cAAc,eAAe,KAAKC,MAAM,eAAe,EACvD,MAAM,IAAIC,MACN,CAAC,oCAAoC,EAAED,MAAM,eAAe,CAAC,iBAAiB,CAAC,EAC/E,kCACA;QACI,OAAOA,MAAM,eAAe;IAChC;
|
|
1
|
+
{"version":3,"file":"crud/contentModel/validate/singularApiName.js","sources":["../../../../src/crud/contentModel/validate/singularApiName.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsModel } from \"~/types/index.js\";\n\ninterface Params {\n existingModel: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n model: Pick<CmsModel, \"singularApiName\" | \"pluralApiName\">;\n}\n\nexport const validateSingularApiName = (params: Params): void => {\n const { existingModel, model } = params;\n\n if (existingModel.singularApiName === model.singularApiName) {\n throw new WebinyError(\n `Content model with singularApiName \"${model.singularApiName}\" already exists.`,\n \"MODEL_SINGULAR_API_NAME_EXISTS\",\n {\n input: model.singularApiName\n }\n );\n } else if (existingModel.pluralApiName === model.singularApiName) {\n throw new WebinyError(\n `Content model with pluralApiName \"${model.singularApiName}\" already exists.`,\n \"MODEL_PLURAL_API_NAME_EXISTS\",\n {\n input: model.singularApiName\n }\n );\n }\n};\n"],"names":["validateSingularApiName","params","existingModel","model","WebinyError"],"mappings":";AAQO,MAAMA,0BAA0B,CAACC;IACpC,MAAM,EAAEC,aAAa,EAAEC,KAAK,EAAE,GAAGF;IAEjC,IAAIC,cAAc,eAAe,KAAKC,MAAM,eAAe,EACvD,MAAM,IAAIC,MACN,CAAC,oCAAoC,EAAED,MAAM,eAAe,CAAC,iBAAiB,CAAC,EAC/E,kCACA;QACI,OAAOA,MAAM,eAAe;IAChC;SAED,IAAID,cAAc,aAAa,KAAKC,MAAM,eAAe,EAC5D,MAAM,IAAIC,MACN,CAAC,kCAAkC,EAAED,MAAM,eAAe,CAAC,iBAAiB,CAAC,EAC7E,gCACA;QACI,OAAOA,MAAM,eAAe;IAChC;AAGZ"}
|
|
@@ -114,13 +114,13 @@ const refinementPluralValidationMessage = (value)=>({
|
|
|
114
114
|
});
|
|
115
115
|
const refinementModelIdValidation = (value)=>{
|
|
116
116
|
if (!value) return true;
|
|
117
|
-
if (null === value.match(/^[a-zA-Z]/)) return false;
|
|
117
|
+
else if (null === value.match(/^[a-zA-Z]/)) return false;
|
|
118
118
|
const camelCasedValue = camelCase(value).toLowerCase();
|
|
119
119
|
return camelCasedValue === value.toLowerCase();
|
|
120
120
|
};
|
|
121
121
|
const refinementModelIdValidationMessage = (value)=>{
|
|
122
122
|
if (!value) return {};
|
|
123
|
-
if (null === value.match(/^[a-zA-Z]/)) return {
|
|
123
|
+
else if (null === value.match(/^[a-zA-Z]/)) return {
|
|
124
124
|
message: `The modelId "${value}" is not valid. It must start with a A-Z or a-z.`
|
|
125
125
|
};
|
|
126
126
|
return {
|