@webiny/api-headless-cms 0.0.0-unstable.99666aeb00 → 0.0.0-unstable.a9593f74dd
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/constants.d.ts +31 -0
- package/constants.js +51 -2
- package/constants.js.map +1 -1
- package/context.js +50 -45
- package/context.js.map +1 -1
- package/crud/contentEntry/afterDelete.js +3 -1
- package/crud/contentEntry/afterDelete.js.map +1 -1
- package/crud/contentEntry/beforeCreate.js +3 -1
- package/crud/contentEntry/beforeCreate.js.map +1 -1
- package/crud/contentEntry/beforeUpdate.js +3 -1
- package/crud/contentEntry/beforeUpdate.js.map +1 -1
- package/crud/contentEntry/entryDataFactories/createEntryData.d.ts +20 -0
- package/crud/contentEntry/entryDataFactories/createEntryData.js +228 -0
- package/crud/contentEntry/entryDataFactories/createEntryData.js.map +1 -0
- package/crud/contentEntry/entryDataFactories/createEntryRevisionFromData.d.ts +21 -0
- package/crud/contentEntry/entryDataFactories/createEntryRevisionFromData.js +114 -0
- package/crud/contentEntry/entryDataFactories/createEntryRevisionFromData.js.map +1 -0
- package/crud/contentEntry/entryDataFactories/createPublishEntryData.d.ts +13 -0
- package/crud/contentEntry/entryDataFactories/createPublishEntryData.js +61 -0
- package/crud/contentEntry/entryDataFactories/createPublishEntryData.js.map +1 -0
- package/crud/contentEntry/entryDataFactories/createRepublishEntryData.d.ts +12 -0
- package/crud/contentEntry/entryDataFactories/createRepublishEntryData.js +57 -0
- package/crud/contentEntry/entryDataFactories/createRepublishEntryData.js.map +1 -0
- package/crud/contentEntry/entryDataFactories/createUnpublishEntryData.d.ts +12 -0
- package/crud/contentEntry/entryDataFactories/createUnpublishEntryData.js +38 -0
- package/crud/contentEntry/entryDataFactories/createUnpublishEntryData.js.map +1 -0
- package/crud/contentEntry/entryDataFactories/createUpdateEntryData.d.ts +20 -0
- package/crud/contentEntry/entryDataFactories/createUpdateEntryData.js +122 -0
- package/crud/contentEntry/entryDataFactories/createUpdateEntryData.js.map +1 -0
- package/crud/contentEntry/entryDataFactories/index.d.ts +8 -0
- package/crud/contentEntry/entryDataFactories/index.js +95 -0
- package/crud/contentEntry/entryDataFactories/index.js.map +1 -0
- package/crud/contentEntry/entryDataFactories/mapAndCleanUpdatedInputData.d.ts +5 -0
- package/crud/contentEntry/entryDataFactories/mapAndCleanUpdatedInputData.js +36 -0
- package/crud/contentEntry/entryDataFactories/mapAndCleanUpdatedInputData.js.map +1 -0
- package/crud/contentEntry/entryDataFactories/statuses.d.ts +4 -0
- package/crud/contentEntry/entryDataFactories/statuses.js +15 -0
- package/crud/contentEntry/entryDataFactories/statuses.js.map +1 -0
- package/crud/contentEntry/entryDataValidation.d.ts +4 -2
- package/crud/contentEntry/entryDataValidation.js +223 -45
- package/crud/contentEntry/entryDataValidation.js.map +1 -1
- package/crud/contentEntry/markLockedFields.js +17 -10
- package/crud/contentEntry/markLockedFields.js.map +1 -1
- package/crud/contentEntry/referenceFieldsMapping.d.ts +6 -0
- package/crud/contentEntry/referenceFieldsMapping.js +134 -111
- package/crud/contentEntry/referenceFieldsMapping.js.map +1 -1
- package/crud/contentEntry/searchableFields.js +5 -4
- package/crud/contentEntry/searchableFields.js.map +1 -1
- package/crud/contentEntry.crud.d.ts +1 -4
- package/crud/contentEntry.crud.js +295 -466
- package/crud/contentEntry.crud.js.map +1 -1
- package/crud/contentModel/beforeCreate.d.ts +1 -1
- package/crud/contentModel/beforeCreate.js +11 -9
- package/crud/contentModel/beforeCreate.js.map +1 -1
- package/crud/contentModel/beforeDelete.js +3 -1
- package/crud/contentModel/beforeDelete.js.map +1 -1
- package/crud/contentModel/beforeUpdate.d.ts +1 -1
- package/crud/contentModel/beforeUpdate.js +3 -6
- package/crud/contentModel/beforeUpdate.js.map +1 -1
- package/crud/contentModel/compatibility/modelApiName.js +3 -1
- package/crud/contentModel/compatibility/modelApiName.js.map +1 -1
- package/crud/contentModel/contentModelManagerFactory.js +3 -1
- package/crud/contentModel/contentModelManagerFactory.js.map +1 -1
- package/crud/contentModel/createFieldStorageId.js +3 -1
- package/crud/contentModel/createFieldStorageId.js.map +1 -1
- package/crud/contentModel/defaultFields.js +3 -1
- package/crud/contentModel/defaultFields.js.map +1 -1
- package/crud/contentModel/ensureTypeTag.d.ts +5 -0
- package/crud/contentModel/ensureTypeTag.js +21 -0
- package/crud/contentModel/ensureTypeTag.js.map +1 -0
- package/crud/contentModel/fields/descriptionField.js +4 -2
- package/crud/contentModel/fields/descriptionField.js.map +1 -1
- package/crud/contentModel/fields/imageField.js +6 -8
- package/crud/contentModel/fields/imageField.js.map +1 -1
- package/crud/contentModel/fields/titleField.js +4 -2
- package/crud/contentModel/fields/titleField.js.map +1 -1
- package/crud/contentModel/listModelsFromDatabase.d.ts +10 -0
- package/crud/contentModel/listModelsFromDatabase.js +38 -0
- package/crud/contentModel/listModelsFromDatabase.js.map +1 -0
- package/crud/contentModel/validate/endingAllowed.js +3 -1
- package/crud/contentModel/validate/endingAllowed.js.map +1 -1
- package/crud/contentModel/validate/isModelEndingAllowed.js +4 -2
- package/crud/contentModel/validate/isModelEndingAllowed.js.map +1 -1
- package/crud/contentModel/validate/modelId.js +3 -1
- package/crud/contentModel/validate/modelId.js.map +1 -1
- package/crud/contentModel/validate/pluralApiName.js +3 -1
- package/crud/contentModel/validate/pluralApiName.js.map +1 -1
- package/crud/contentModel/validate/singularApiName.js +3 -1
- package/crud/contentModel/validate/singularApiName.js.map +1 -1
- package/crud/contentModel/validateModel.js +3 -1
- package/crud/contentModel/validateModel.js.map +1 -1
- package/crud/contentModel/validateModelFields.js +7 -6
- package/crud/contentModel/validateModelFields.js.map +1 -1
- package/crud/contentModel/validation.d.ts +531 -210
- package/crud/contentModel/validation.js +71 -11
- package/crud/contentModel/validation.js.map +1 -1
- package/crud/contentModel.crud.js +137 -182
- package/crud/contentModel.crud.js.map +1 -1
- package/crud/contentModelGroup/beforeCreate.d.ts +1 -1
- package/crud/contentModelGroup/beforeCreate.js +15 -1
- package/crud/contentModelGroup/beforeCreate.js.map +1 -1
- package/crud/contentModelGroup/beforeDelete.js +3 -1
- package/crud/contentModelGroup/beforeDelete.js.map +1 -1
- package/crud/contentModelGroup/beforeUpdate.js +3 -1
- package/crud/contentModelGroup/beforeUpdate.js.map +1 -1
- package/crud/contentModelGroup/listGroupsFromDatabase.d.ts +8 -0
- package/crud/contentModelGroup/listGroupsFromDatabase.js +22 -0
- package/crud/contentModelGroup/listGroupsFromDatabase.js.map +1 -0
- package/crud/contentModelGroup/validation.d.ts +9 -6
- package/crud/contentModelGroup/validation.js +5 -2
- package/crud/contentModelGroup/validation.js.map +1 -1
- package/crud/contentModelGroup.crud.d.ts +1 -1
- package/crud/contentModelGroup.crud.js +113 -112
- package/crud/contentModelGroup.crud.js.map +1 -1
- package/crud/system.crud.js +8 -11
- package/crud/system.crud.js.map +1 -1
- package/export/crud/exporting.d.ts +3 -0
- package/export/crud/exporting.js +49 -0
- package/export/crud/exporting.js.map +1 -0
- package/export/crud/importing.d.ts +3 -0
- package/export/crud/importing.js +79 -0
- package/export/crud/importing.js.map +1 -0
- package/export/crud/imports/importData.d.ts +14 -0
- package/export/crud/imports/importData.js +52 -0
- package/export/crud/imports/importData.js.map +1 -0
- package/export/crud/imports/importGroups.d.ts +8 -0
- package/export/crud/imports/importGroups.js +104 -0
- package/export/crud/imports/importGroups.js.map +1 -0
- package/export/crud/imports/importModels.d.ts +8 -0
- package/export/crud/imports/importModels.js +136 -0
- package/export/crud/imports/importModels.js.map +1 -0
- package/export/crud/imports/validateGroups.d.ts +8 -0
- package/export/crud/imports/validateGroups.js +112 -0
- package/export/crud/imports/validateGroups.js.map +1 -0
- package/export/crud/imports/validateInput.d.ts +19 -0
- package/export/crud/imports/validateInput.js +55 -0
- package/export/crud/imports/validateInput.js.map +1 -0
- package/export/crud/imports/validateModels.d.ts +12 -0
- package/export/crud/imports/validateModels.js +203 -0
- package/export/crud/imports/validateModels.js.map +1 -0
- package/export/crud/index.d.ts +4 -0
- package/export/crud/index.js +15 -0
- package/export/crud/index.js.map +1 -0
- package/export/crud/sanitize.d.ts +4 -0
- package/export/crud/sanitize.js +35 -0
- package/export/crud/sanitize.js.map +1 -0
- package/export/graphql/index.d.ts +3 -0
- package/export/graphql/index.js +188 -0
- package/export/graphql/index.js.map +1 -0
- package/export/index.d.ts +2 -0
- package/export/index.js +29 -0
- package/export/index.js.map +1 -0
- package/export/types.d.ts +113 -0
- package/export/types.js +22 -0
- package/export/types.js.map +1 -0
- package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js +4 -7
- package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js.map +1 -1
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js +5 -8
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js.map +1 -1
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js +47 -38
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js.map +1 -1
- package/fieldConverters/index.js +3 -1
- package/fieldConverters/index.js.map +1 -1
- package/graphql/buildSchemaPlugins.js +7 -1
- package/graphql/buildSchemaPlugins.js.map +1 -1
- package/graphql/checkEndpointAccess.js +3 -1
- package/graphql/checkEndpointAccess.js.map +1 -1
- package/graphql/createExecutableSchema.js +3 -1
- package/graphql/createExecutableSchema.js.map +1 -1
- package/graphql/createRequestBody.js +3 -1
- package/graphql/createRequestBody.js.map +1 -1
- package/graphql/formatErrorPayload.js +3 -1
- package/graphql/formatErrorPayload.js.map +1 -1
- package/graphql/generateSchema.js +3 -1
- package/graphql/generateSchema.js.map +1 -1
- package/graphql/getSchema.d.ts +0 -1
- package/graphql/getSchema.js +34 -18
- package/graphql/getSchema.js.map +1 -1
- package/graphql/graphQLHandlerFactory.js +3 -1
- package/graphql/graphQLHandlerFactory.js.map +1 -1
- package/graphql/handleRequest.js +3 -5
- package/graphql/handleRequest.js.map +1 -1
- package/graphql/index.d.ts +1 -1
- package/graphql/index.js +4 -2
- package/graphql/index.js.map +1 -1
- package/graphql/schema/baseContentSchema.js +9 -8
- package/graphql/schema/baseContentSchema.js.map +1 -1
- package/graphql/schema/baseSchema.d.ts +2 -3
- package/graphql/schema/baseSchema.js +64 -2
- package/graphql/schema/baseSchema.js.map +1 -1
- package/graphql/schema/contentEntries.js +51 -18
- package/graphql/schema/contentEntries.js.map +1 -1
- package/graphql/schema/contentModelGroups.js +5 -2
- package/graphql/schema/contentModelGroups.js.map +1 -1
- package/graphql/schema/contentModels.js +10 -10
- package/graphql/schema/contentModels.js.map +1 -1
- package/graphql/schema/createFieldResolvers.js +14 -12
- package/graphql/schema/createFieldResolvers.js.map +1 -1
- package/graphql/schema/createFieldTypePluginRecords.js +3 -1
- package/graphql/schema/createFieldTypePluginRecords.js.map +1 -1
- package/graphql/schema/createManageResolvers.js +13 -10
- package/graphql/schema/createManageResolvers.js.map +1 -1
- package/graphql/schema/createManageSDL.js +37 -19
- package/graphql/schema/createManageSDL.js.map +1 -1
- package/graphql/schema/createPreviewResolvers.js +7 -6
- package/graphql/schema/createPreviewResolvers.js.map +1 -1
- package/graphql/schema/createReadResolvers.js +7 -6
- package/graphql/schema/createReadResolvers.js.map +1 -1
- package/graphql/schema/createReadSDL.js +12 -5
- package/graphql/schema/createReadSDL.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveCreate.d.ts +2 -1
- package/graphql/schema/resolvers/manage/resolveCreate.js +4 -2
- package/graphql/schema/resolvers/manage/resolveCreate.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveCreateFrom.d.ts +2 -1
- package/graphql/schema/resolvers/manage/resolveCreateFrom.js +4 -2
- package/graphql/schema/resolvers/manage/resolveCreateFrom.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveDelete.js +4 -2
- package/graphql/schema/resolvers/manage/resolveDelete.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveDeleteMultiple.js +4 -2
- package/graphql/schema/resolvers/manage/resolveDeleteMultiple.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveGet.js +12 -5
- package/graphql/schema/resolvers/manage/resolveGet.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveGetByIds.js +3 -1
- package/graphql/schema/resolvers/manage/resolveGetByIds.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveGetRevisions.js +3 -1
- package/graphql/schema/resolvers/manage/resolveGetRevisions.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveGetUniqueFieldValues.js +3 -1
- package/graphql/schema/resolvers/manage/resolveGetUniqueFieldValues.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveList.js +3 -1
- package/graphql/schema/resolvers/manage/resolveList.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveMove.js +7 -10
- package/graphql/schema/resolvers/manage/resolveMove.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolvePublish.js +3 -1
- package/graphql/schema/resolvers/manage/resolvePublish.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveRepublish.js +3 -1
- package/graphql/schema/resolvers/manage/resolveRepublish.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveUnpublish.js +3 -1
- package/graphql/schema/resolvers/manage/resolveUnpublish.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveUpdate.d.ts +2 -1
- package/graphql/schema/resolvers/manage/resolveUpdate.js +4 -2
- package/graphql/schema/resolvers/manage/resolveUpdate.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveValidate.d.ts +8 -0
- package/graphql/schema/resolvers/manage/resolveValidate.js +20 -0
- package/graphql/schema/resolvers/manage/resolveValidate.js.map +1 -0
- package/graphql/schema/resolvers/preview/resolveGet.js +6 -5
- package/graphql/schema/resolvers/preview/resolveGet.js.map +1 -1
- package/graphql/schema/resolvers/preview/resolveList.js +3 -1
- package/graphql/schema/resolvers/preview/resolveList.js.map +1 -1
- package/graphql/schema/resolvers/read/resolveGet.js +6 -5
- package/graphql/schema/resolvers/read/resolveGet.js.map +1 -1
- package/graphql/schema/resolvers/read/resolveList.js +3 -1
- package/graphql/schema/resolvers/read/resolveList.js.map +1 -1
- package/graphql/schema/schemaPlugins.js +3 -1
- package/graphql/schema/schemaPlugins.js.map +1 -1
- package/graphql/system.js +3 -1
- package/graphql/system.js.map +1 -1
- package/graphqlFields/boolean.js +3 -1
- package/graphqlFields/boolean.js.map +1 -1
- package/graphqlFields/datetime.js +5 -5
- package/graphqlFields/datetime.js.map +1 -1
- package/graphqlFields/dynamicZone/dynamicZoneField.js +42 -19
- package/graphqlFields/dynamicZone/dynamicZoneField.js.map +1 -1
- package/graphqlFields/dynamicZone/dynamicZoneStorage.js +60 -12
- package/graphqlFields/dynamicZone/dynamicZoneStorage.js.map +1 -1
- package/graphqlFields/dynamicZone/index.js +3 -1
- package/graphqlFields/dynamicZone/index.js.map +1 -1
- package/graphqlFields/file.js +3 -1
- package/graphqlFields/file.js.map +1 -1
- package/graphqlFields/helpers.d.ts +0 -1
- package/graphqlFields/helpers.js +6 -18
- package/graphqlFields/helpers.js.map +1 -1
- package/graphqlFields/index.js +5 -2
- package/graphqlFields/index.js.map +1 -1
- package/graphqlFields/json.d.ts +2 -0
- package/graphqlFields/json.js +49 -0
- package/graphqlFields/json.js.map +1 -0
- package/graphqlFields/longText.js +14 -3
- package/graphqlFields/longText.js.map +1 -1
- package/graphqlFields/number.js +3 -1
- package/graphqlFields/number.js.map +1 -1
- package/graphqlFields/object.js +24 -44
- package/graphqlFields/object.js.map +1 -1
- package/graphqlFields/ref.js +28 -16
- package/graphqlFields/ref.js.map +1 -1
- package/graphqlFields/richText/RichTextPluginsProcessor.d.ts +6 -0
- package/graphqlFields/richText/RichTextPluginsProcessor.js +34 -0
- package/graphqlFields/richText/RichTextPluginsProcessor.js.map +1 -0
- package/graphqlFields/richText/richTextResolver.d.ts +7 -0
- package/graphqlFields/richText/richTextResolver.js +39 -0
- package/graphqlFields/richText/richTextResolver.js.map +1 -0
- package/graphqlFields/richText.js +11 -3
- package/graphqlFields/richText.js.map +1 -1
- package/graphqlFields/text.js +3 -1
- package/graphqlFields/text.js.map +1 -1
- package/htmlRenderer/LexicalRenderer.d.ts +5 -0
- package/htmlRenderer/LexicalRenderer.js +28 -0
- package/htmlRenderer/LexicalRenderer.js.map +1 -0
- package/htmlRenderer/createLexicalHTMLRenderer.d.ts +2 -0
- package/htmlRenderer/createLexicalHTMLRenderer.js +31 -0
- package/htmlRenderer/createLexicalHTMLRenderer.js.map +1 -0
- package/index.d.ts +2 -1
- package/index.js +20 -5
- package/index.js.map +1 -1
- package/modelManager/DefaultCmsModelManager.js +3 -5
- package/modelManager/DefaultCmsModelManager.js.map +1 -1
- package/modelManager/index.js +3 -1
- package/modelManager/index.js.map +1 -1
- package/package.json +27 -26
- package/parameters/context.js +4 -2
- package/parameters/context.js.map +1 -1
- package/parameters/header.js +7 -6
- package/parameters/header.js.map +1 -1
- package/parameters/index.js +3 -1
- package/parameters/index.js.map +1 -1
- package/parameters/manual.js +9 -4
- package/parameters/manual.js.map +1 -1
- package/parameters/path.js +4 -3
- package/parameters/path.js.map +1 -1
- package/plugins/CmsGraphQLSchemaPlugin.js +5 -4
- package/plugins/CmsGraphQLSchemaPlugin.js.map +1 -1
- package/plugins/CmsGraphQLSchemaSorterPlugin.js +4 -5
- package/plugins/CmsGraphQLSchemaSorterPlugin.js.map +1 -1
- package/plugins/CmsGroupPlugin.d.ts +6 -3
- package/plugins/CmsGroupPlugin.js +8 -6
- package/plugins/CmsGroupPlugin.js.map +1 -1
- package/plugins/CmsModelFieldConverterPlugin.js +5 -4
- package/plugins/CmsModelFieldConverterPlugin.js.map +1 -1
- package/plugins/CmsModelPlugin.d.ts +6 -4
- package/plugins/CmsModelPlugin.js +56 -27
- package/plugins/CmsModelPlugin.js.map +1 -1
- package/plugins/CmsParametersPlugin.js +7 -4
- package/plugins/CmsParametersPlugin.js.map +1 -1
- package/plugins/CmsRichTextRendererPlugin.d.ts +24 -0
- package/plugins/CmsRichTextRendererPlugin.js +28 -0
- package/plugins/CmsRichTextRendererPlugin.js.map +1 -0
- package/plugins/StorageOperationsCmsModelPlugin.js +5 -6
- package/plugins/StorageOperationsCmsModelPlugin.js.map +1 -1
- package/plugins/StorageTransformPlugin.d.ts +2 -2
- package/plugins/StorageTransformPlugin.js +3 -4
- package/plugins/StorageTransformPlugin.js.map +1 -1
- package/plugins/index.d.ts +1 -0
- package/plugins/index.js +14 -1
- package/plugins/index.js.map +1 -1
- package/storage/default.js +3 -1
- package/storage/default.js.map +1 -1
- package/storage/index.d.ts +1 -0
- package/storage/index.js +15 -0
- package/storage/index.js.map +1 -0
- package/storage/json.d.ts +2 -0
- package/storage/json.js +27 -0
- package/storage/json.js.map +1 -0
- package/storage/object.js +8 -8
- package/storage/object.js.map +1 -1
- package/types.d.ts +300 -260
- package/types.js +9 -20
- package/types.js.map +1 -1
- package/utils/access.d.ts +9 -0
- package/utils/access.js +26 -0
- package/utils/access.js.map +1 -0
- package/utils/caching/Cache.d.ts +2 -0
- package/utils/caching/Cache.js +51 -0
- package/utils/caching/Cache.js.map +1 -0
- package/utils/caching/CacheKey.d.ts +2 -0
- package/utils/caching/CacheKey.js +40 -0
- package/utils/caching/CacheKey.js.map +1 -0
- package/utils/caching/index.d.ts +2 -0
- package/utils/caching/index.js +29 -0
- package/utils/caching/index.js.map +1 -0
- package/utils/caching/types.d.ts +11 -0
- package/utils/caching/types.js +7 -0
- package/utils/caching/types.js.map +1 -0
- package/utils/converters/Converter.js +4 -5
- package/utils/converters/Converter.js.map +1 -1
- package/utils/converters/ConverterCollection.js +13 -7
- package/utils/converters/ConverterCollection.js.map +1 -1
- package/utils/converters/valueKeyStorageConverter.js +11 -4
- package/utils/converters/valueKeyStorageConverter.js.map +1 -1
- package/utils/createTypeFromFields.js +6 -1
- package/utils/createTypeFromFields.js.map +1 -1
- package/utils/createTypeName.js +3 -1
- package/utils/createTypeName.js.map +1 -1
- package/utils/date.d.ts +10 -0
- package/utils/date.js +36 -0
- package/utils/date.js.map +1 -0
- package/utils/entryStorage.d.ts +4 -4
- package/utils/entryStorage.js +6 -4
- package/utils/entryStorage.js.map +1 -1
- package/utils/filterAsync.js +9 -8
- package/utils/filterAsync.js.map +1 -1
- package/utils/getBaseFieldType.js +3 -1
- package/utils/getBaseFieldType.js.map +1 -1
- package/utils/getEntryDescription.js +3 -1
- package/utils/getEntryDescription.js.map +1 -1
- package/utils/getEntryImage.js +3 -1
- package/utils/getEntryImage.js.map +1 -1
- package/utils/getEntryTitle.js +3 -1
- package/utils/getEntryTitle.js.map +1 -1
- package/utils/getSchemaFromFieldPlugins.d.ts +13 -2
- package/utils/getSchemaFromFieldPlugins.js +22 -4
- package/utils/getSchemaFromFieldPlugins.js.map +1 -1
- package/utils/identity.d.ts +2 -0
- package/utils/identity.js +20 -0
- package/utils/identity.js.map +1 -0
- package/utils/incrementEntryIdVersion.js +3 -1
- package/utils/incrementEntryIdVersion.js.map +1 -1
- package/utils/index.d.ts +1 -0
- package/utils/index.js +18 -0
- package/utils/index.js.map +1 -0
- package/utils/permissions/EntriesPermissions.js +3 -1
- package/utils/permissions/EntriesPermissions.js.map +1 -1
- package/utils/permissions/ModelGroupsPermissions.d.ts +3 -5
- package/utils/permissions/ModelGroupsPermissions.js +8 -6
- package/utils/permissions/ModelGroupsPermissions.js.map +1 -1
- package/utils/permissions/ModelsPermissions.d.ts +9 -7
- package/utils/permissions/ModelsPermissions.js +5 -6
- package/utils/permissions/ModelsPermissions.js.map +1 -1
- package/utils/renderFields.js +3 -1
- package/utils/renderFields.js.map +1 -1
- package/utils/renderGetFilterFields.js +5 -4
- package/utils/renderGetFilterFields.js.map +1 -1
- package/utils/renderInputFields.js +3 -1
- package/utils/renderInputFields.js.map +1 -1
- package/utils/renderListFilterFields.js +12 -4
- package/utils/renderListFilterFields.js.map +1 -1
- package/utils/renderSortEnum.js +5 -2
- package/utils/renderSortEnum.js.map +1 -1
- package/utils/toSlug.js +3 -1
- package/utils/toSlug.js.map +1 -1
- package/validators/dateGte.js +3 -1
- package/validators/dateGte.js.map +1 -1
- package/validators/dateLte.js +3 -1
- package/validators/dateLte.js.map +1 -1
- package/validators/gte.js +4 -3
- package/validators/gte.js.map +1 -1
- package/validators/in.js +4 -3
- package/validators/in.js.map +1 -1
- package/validators/index.js +4 -3
- package/validators/index.js.map +1 -1
- package/validators/lte.js +4 -3
- package/validators/lte.js.map +1 -1
- package/validators/maxLength.js +4 -3
- package/validators/maxLength.js.map +1 -1
- package/validators/minLength.js +4 -3
- package/validators/minLength.js.map +1 -1
- package/validators/pattern.js +5 -3
- package/validators/pattern.js.map +1 -1
- package/validators/patternPlugins/email.js +3 -1
- package/validators/patternPlugins/email.js.map +1 -1
- package/validators/patternPlugins/index.js +3 -1
- package/validators/patternPlugins/index.js.map +1 -1
- package/validators/patternPlugins/lowerCase.js +3 -1
- package/validators/patternPlugins/lowerCase.js.map +1 -1
- package/validators/patternPlugins/lowerCaseSpace.js +3 -1
- package/validators/patternPlugins/lowerCaseSpace.js.map +1 -1
- package/validators/patternPlugins/upperCase.js +3 -1
- package/validators/patternPlugins/upperCase.js.map +1 -1
- package/validators/patternPlugins/upperCaseSpace.js +3 -1
- package/validators/patternPlugins/upperCaseSpace.js.map +1 -1
- package/validators/patternPlugins/url.js +3 -1
- package/validators/patternPlugins/url.js.map +1 -1
- package/validators/required.js +3 -1
- package/validators/required.js.map +1 -1
- package/validators/timeGte.js +4 -3
- package/validators/timeGte.js.map +1 -1
- package/validators/timeLte.js +4 -3
- package/validators/timeLte.js.map +1 -1
- package/validators/unique.js +4 -2
- package/validators/unique.js.map +1 -1
- package/crud/contentModel/afterCreate.d.ts +0 -8
- package/crud/contentModel/afterCreate.js +0 -16
- package/crud/contentModel/afterCreate.js.map +0 -1
- package/crud/contentModel/afterCreateFrom.d.ts +0 -8
- package/crud/contentModel/afterCreateFrom.js +0 -16
- package/crud/contentModel/afterCreateFrom.js.map +0 -1
- package/crud/contentModel/afterDelete.d.ts +0 -8
- package/crud/contentModel/afterDelete.js +0 -16
- package/crud/contentModel/afterDelete.js.map +0 -1
- package/crud/contentModel/afterUpdate.d.ts +0 -8
- package/crud/contentModel/afterUpdate.js +0 -16
- package/crud/contentModel/afterUpdate.js.map +0 -1
- package/crud/contentModel/validateLayout.d.ts +0 -2
- package/crud/contentModel/validateLayout.js +0 -28
- package/crud/contentModel/validateLayout.js.map +0 -1
- package/crud/settings.crud.d.ts +0 -12
- package/crud/settings.crud.js +0 -62
- package/crud/settings.crud.js.map +0 -1
- package/graphql/schema/resolvers/commonFieldResolvers.d.ts +0 -7
- package/graphql/schema/resolvers/commonFieldResolvers.js +0 -13
- package/graphql/schema/resolvers/commonFieldResolvers.js.map +0 -1
- package/utils/permissions/SettingsPermissions.d.ts +0 -4
- package/utils/permissions/SettingsPermissions.js +0 -9
- package/utils/permissions/SettingsPermissions.js.map +0 -1
- package/validators/dynamicZone.d.ts +0 -2
- package/validators/dynamicZone.js +0 -20
- package/validators/dynamicZone.js.map +0 -1
|
@@ -5,10 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.createModelGroupsCrud = void 0;
|
|
8
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
9
|
-
var _dataloader = _interopRequireDefault(require("dataloader"));
|
|
10
8
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
|
-
var _handlerGraphql = require("@webiny/handler-graphql");
|
|
12
9
|
var _CmsGroupPlugin = require("../plugins/CmsGroupPlugin");
|
|
13
10
|
var _pubsub = require("@webiny/pubsub");
|
|
14
11
|
var _beforeUpdate = require("./contentModelGroup/beforeUpdate");
|
|
@@ -17,6 +14,9 @@ var _beforeDelete = require("./contentModelGroup/beforeDelete");
|
|
|
17
14
|
var _validation = require("./contentModelGroup/validation");
|
|
18
15
|
var _utils = require("@webiny/utils");
|
|
19
16
|
var _filterAsync = require("../utils/filterAsync");
|
|
17
|
+
var _utils2 = require("../utils");
|
|
18
|
+
var _listGroupsFromDatabase = require("./contentModelGroup/listGroupsFromDatabase");
|
|
19
|
+
var _handlerGraphql = require("@webiny/handler-graphql");
|
|
20
20
|
const createModelGroupsCrud = params => {
|
|
21
21
|
const {
|
|
22
22
|
getTenant,
|
|
@@ -26,75 +26,95 @@ const createModelGroupsCrud = params => {
|
|
|
26
26
|
modelGroupsPermissions,
|
|
27
27
|
context
|
|
28
28
|
} = params;
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
});
|
|
45
|
-
return [groups.concat(pluginsGroups)];
|
|
46
|
-
})
|
|
29
|
+
const filterGroup = async group => {
|
|
30
|
+
if (!group) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
const ownsGroup = await modelGroupsPermissions.ensure({
|
|
34
|
+
owns: group.createdBy
|
|
35
|
+
}, {
|
|
36
|
+
throw: false
|
|
37
|
+
});
|
|
38
|
+
if (!ownsGroup) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
return await modelGroupsPermissions.canAccessGroup({
|
|
42
|
+
group
|
|
43
|
+
});
|
|
47
44
|
};
|
|
45
|
+
const listDatabaseGroupsCache = (0, _utils2.createMemoryCache)();
|
|
46
|
+
const listFilteredDatabaseGroupsCache = (0, _utils2.createMemoryCache)();
|
|
47
|
+
const listPluginGroupsCache = (0, _utils2.createMemoryCache)();
|
|
48
48
|
const clearGroupsCache = () => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
listPluginGroupsCache.clear();
|
|
50
|
+
listDatabaseGroupsCache.clear();
|
|
51
|
+
listFilteredDatabaseGroupsCache.clear();
|
|
52
52
|
};
|
|
53
|
-
const
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
|
|
53
|
+
const fetchPluginGroups = (tenant, locale) => {
|
|
54
|
+
const pluginGroups = context.plugins.byType(_CmsGroupPlugin.CmsGroupPlugin.type);
|
|
55
|
+
const cacheKey = (0, _utils2.createCacheKey)({
|
|
56
|
+
tenant,
|
|
57
|
+
locale,
|
|
58
|
+
identity: context.security.isAuthorizationEnabled() ? getIdentity()?.id : undefined,
|
|
59
|
+
groups: pluginGroups.map(({
|
|
60
|
+
contentModelGroup: group
|
|
61
|
+
}) => {
|
|
62
|
+
return `${group.id}#${group.slug}#${group.savedOn || "unknown"}`;
|
|
63
|
+
}).join("/")
|
|
64
|
+
});
|
|
65
|
+
return listPluginGroupsCache.getOrSet(cacheKey, async () => {
|
|
66
|
+
const groups = pluginGroups
|
|
67
|
+
/**
|
|
68
|
+
* We need to filter out groups that are not for this tenant or locale.
|
|
69
|
+
* If it does not have tenant or locale define, it is for every locale and tenant
|
|
70
|
+
*/.filter(plugin => {
|
|
71
|
+
const {
|
|
72
|
+
tenant: t,
|
|
73
|
+
locale: l
|
|
74
|
+
} = plugin.contentModelGroup;
|
|
75
|
+
if (t && t !== tenant) {
|
|
76
|
+
return false;
|
|
77
|
+
} else if (l && l !== locale) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
return true;
|
|
81
|
+
}).map(plugin => {
|
|
82
|
+
return {
|
|
83
|
+
...plugin.contentModelGroup,
|
|
84
|
+
tenant,
|
|
85
|
+
locale,
|
|
86
|
+
webinyVersion: context.WEBINY_VERSION
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
return (0, _filterAsync.filterAsync)(groups, filterGroup);
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
const fetchGroups = async (tenant, locale) => {
|
|
93
|
+
const pluginGroups = await fetchPluginGroups(tenant, locale);
|
|
57
94
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
return true;
|
|
71
|
-
}).map(plugin => {
|
|
72
|
-
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, plugin.contentModelGroup), {}, {
|
|
95
|
+
* Maybe we can cache based on permissions, not the identity id?
|
|
96
|
+
*
|
|
97
|
+
* TODO: @adrian please check if possible.
|
|
98
|
+
*/
|
|
99
|
+
const cacheKey = (0, _utils2.createCacheKey)({
|
|
100
|
+
tenant,
|
|
101
|
+
locale
|
|
102
|
+
});
|
|
103
|
+
const databaseGroups = await listDatabaseGroupsCache.getOrSet(cacheKey, async () => {
|
|
104
|
+
return await (0, _listGroupsFromDatabase.listGroupsFromDatabase)({
|
|
105
|
+
storageOperations,
|
|
73
106
|
tenant,
|
|
74
|
-
locale
|
|
75
|
-
webinyVersion: context.WEBINY_VERSION
|
|
107
|
+
locale
|
|
76
108
|
});
|
|
77
109
|
});
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
return
|
|
86
|
-
};
|
|
87
|
-
const listGroupsViaDataLoader = async params => {
|
|
88
|
-
const {
|
|
89
|
-
where
|
|
90
|
-
} = params || {};
|
|
91
|
-
try {
|
|
92
|
-
return await dataLoaders.listGroups.load("listGroups");
|
|
93
|
-
} catch (ex) {
|
|
94
|
-
throw new _error.default(ex.message, ex.code || "LIST_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ex.data || {}), {}, {
|
|
95
|
-
where
|
|
96
|
-
}));
|
|
97
|
-
}
|
|
110
|
+
const filteredCacheKey = (0, _utils2.createCacheKey)({
|
|
111
|
+
dbCacheKey: cacheKey.get(),
|
|
112
|
+
identity: context.security.isAuthorizationEnabled() ? getIdentity()?.id : undefined
|
|
113
|
+
});
|
|
114
|
+
const groups = await listFilteredDatabaseGroupsCache.getOrSet(filteredCacheKey, async () => {
|
|
115
|
+
return (0, _filterAsync.filterAsync)(databaseGroups, filterGroup);
|
|
116
|
+
});
|
|
117
|
+
return groups.concat(pluginGroups);
|
|
98
118
|
};
|
|
99
119
|
|
|
100
120
|
/**
|
|
@@ -140,13 +160,18 @@ const createModelGroupsCrud = params => {
|
|
|
140
160
|
await modelGroupsPermissions.ensure({
|
|
141
161
|
rwd: "r"
|
|
142
162
|
});
|
|
143
|
-
const
|
|
163
|
+
const groups = await context.security.withoutAuthorization(async () => {
|
|
164
|
+
return fetchGroups(getTenant().id, getLocale().code);
|
|
165
|
+
});
|
|
166
|
+
const group = groups.find(group => group.id === id);
|
|
167
|
+
if (!group) {
|
|
168
|
+
throw new _handlerGraphql.NotFoundError(`Cms Group "${id}" was not found!`);
|
|
169
|
+
}
|
|
144
170
|
await modelGroupsPermissions.ensure({
|
|
145
171
|
owns: group.createdBy
|
|
146
172
|
});
|
|
147
173
|
await modelGroupsPermissions.ensureCanAccessGroup({
|
|
148
|
-
group
|
|
149
|
-
locale: getLocale().code
|
|
174
|
+
group
|
|
150
175
|
});
|
|
151
176
|
return group;
|
|
152
177
|
};
|
|
@@ -161,26 +186,7 @@ const createModelGroupsCrud = params => {
|
|
|
161
186
|
await modelGroupsPermissions.ensure({
|
|
162
187
|
rwd: "r"
|
|
163
188
|
});
|
|
164
|
-
|
|
165
|
-
where: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, where || {}), {}, {
|
|
166
|
-
tenant: tenant || getTenant().id,
|
|
167
|
-
locale: locale || getLocale().code
|
|
168
|
-
})
|
|
169
|
-
}));
|
|
170
|
-
return (0, _filterAsync.filterAsync)(response, async group => {
|
|
171
|
-
const ownsGroup = await modelGroupsPermissions.ensure({
|
|
172
|
-
owns: group.createdBy
|
|
173
|
-
}, {
|
|
174
|
-
throw: false
|
|
175
|
-
});
|
|
176
|
-
if (!ownsGroup) {
|
|
177
|
-
return false;
|
|
178
|
-
}
|
|
179
|
-
return await modelGroupsPermissions.canAccessGroup({
|
|
180
|
-
group,
|
|
181
|
-
locale: getLocale().code
|
|
182
|
-
});
|
|
183
|
-
});
|
|
189
|
+
return fetchGroups(tenant || getTenant().id, locale || getLocale().code);
|
|
184
190
|
};
|
|
185
191
|
const createGroup = async input => {
|
|
186
192
|
await modelGroupsPermissions.ensure({
|
|
@@ -192,8 +198,9 @@ const createModelGroupsCrud = params => {
|
|
|
192
198
|
}
|
|
193
199
|
const data = result.data;
|
|
194
200
|
const identity = getIdentity();
|
|
195
|
-
const id = (0, _utils.mdbid)();
|
|
196
|
-
const group =
|
|
201
|
+
const id = data.id || (0, _utils.mdbid)();
|
|
202
|
+
const group = {
|
|
203
|
+
...data,
|
|
197
204
|
id,
|
|
198
205
|
tenant: getTenant().id,
|
|
199
206
|
locale: getLocale().code,
|
|
@@ -205,7 +212,7 @@ const createModelGroupsCrud = params => {
|
|
|
205
212
|
type: identity.type
|
|
206
213
|
},
|
|
207
214
|
webinyVersion: context.WEBINY_VERSION
|
|
208
|
-
}
|
|
215
|
+
};
|
|
209
216
|
try {
|
|
210
217
|
await onGroupBeforeCreate.publish({
|
|
211
218
|
group
|
|
@@ -224,17 +231,18 @@ const createModelGroupsCrud = params => {
|
|
|
224
231
|
group,
|
|
225
232
|
error: ex
|
|
226
233
|
});
|
|
227
|
-
throw new _error.default(ex.message || "Could not save data model group.", ex.code || "ERROR_ON_CREATE",
|
|
234
|
+
throw new _error.default(ex.message || "Could not save data model group.", ex.code || "ERROR_ON_CREATE", {
|
|
235
|
+
...(ex.data || {}),
|
|
228
236
|
group,
|
|
229
237
|
input
|
|
230
|
-
})
|
|
238
|
+
});
|
|
231
239
|
}
|
|
232
240
|
};
|
|
233
241
|
const updateGroup = async (id, input) => {
|
|
234
242
|
await modelGroupsPermissions.ensure({
|
|
235
243
|
rwd: "w"
|
|
236
244
|
});
|
|
237
|
-
const original = await
|
|
245
|
+
const original = await getGroup(id);
|
|
238
246
|
await modelGroupsPermissions.ensure({
|
|
239
247
|
owns: original.createdBy
|
|
240
248
|
});
|
|
@@ -250,11 +258,13 @@ const createModelGroupsCrud = params => {
|
|
|
250
258
|
if (Object.keys(data).length === 0) {
|
|
251
259
|
return original;
|
|
252
260
|
}
|
|
253
|
-
const group =
|
|
261
|
+
const group = {
|
|
262
|
+
...original,
|
|
263
|
+
...data,
|
|
254
264
|
locale: getLocale().code,
|
|
255
265
|
tenant: getTenant().id,
|
|
256
266
|
savedOn: new Date().toISOString()
|
|
257
|
-
}
|
|
267
|
+
};
|
|
258
268
|
try {
|
|
259
269
|
await onGroupBeforeUpdate.publish({
|
|
260
270
|
original,
|
|
@@ -288,7 +298,7 @@ const createModelGroupsCrud = params => {
|
|
|
288
298
|
await modelGroupsPermissions.ensure({
|
|
289
299
|
rwd: "d"
|
|
290
300
|
});
|
|
291
|
-
const group = await
|
|
301
|
+
const group = await getGroup(id);
|
|
292
302
|
await modelGroupsPermissions.ensure({
|
|
293
303
|
owns: group.createdBy
|
|
294
304
|
});
|
|
@@ -308,25 +318,14 @@ const createModelGroupsCrud = params => {
|
|
|
308
318
|
group,
|
|
309
319
|
error: ex
|
|
310
320
|
});
|
|
311
|
-
throw new _error.default(ex.message, ex.code || "DELETE_ERROR",
|
|
321
|
+
throw new _error.default(ex.message, ex.code || "DELETE_ERROR", {
|
|
322
|
+
...(ex.data || {}),
|
|
312
323
|
id
|
|
313
|
-
})
|
|
324
|
+
});
|
|
314
325
|
}
|
|
315
326
|
return true;
|
|
316
327
|
};
|
|
317
328
|
return {
|
|
318
|
-
/**
|
|
319
|
-
* Deprecated - will be removed in 5.36.0
|
|
320
|
-
*/
|
|
321
|
-
onBeforeGroupCreate: onGroupBeforeCreate,
|
|
322
|
-
onAfterGroupCreate: onGroupAfterCreate,
|
|
323
|
-
onBeforeGroupUpdate: onGroupBeforeUpdate,
|
|
324
|
-
onAfterGroupUpdate: onGroupAfterUpdate,
|
|
325
|
-
onBeforeGroupDelete: onGroupBeforeDelete,
|
|
326
|
-
onAfterGroupDelete: onGroupAfterDelete,
|
|
327
|
-
/**
|
|
328
|
-
* Released in 5.34.0
|
|
329
|
-
*/
|
|
330
329
|
onGroupBeforeCreate,
|
|
331
330
|
onGroupAfterCreate,
|
|
332
331
|
onGroupCreateError,
|
|
@@ -364,4 +363,6 @@ const createModelGroupsCrud = params => {
|
|
|
364
363
|
}
|
|
365
364
|
};
|
|
366
365
|
};
|
|
367
|
-
exports.createModelGroupsCrud = createModelGroupsCrud;
|
|
366
|
+
exports.createModelGroupsCrud = createModelGroupsCrud;
|
|
367
|
+
|
|
368
|
+
//# sourceMappingURL=contentModelGroup.crud.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createModelGroupsCrud","params","getTenant","getIdentity","getLocale","storageOperations","modelGroupsPermissions","context","dataLoaders","listGroups","DataLoader","tenant","id","locale","code","pluginsGroups","getGroupsAsPlugins","map","group","groups","list","where","concat","clearGroupsCache","loader","Object","values","clearAll","plugins","byType","CmsGroupPlugin","type","filter","plugin","t","l","contentModelGroup","webinyVersion","WEBINY_VERSION","getGroupViaDataLoader","load","find","g","NotFoundError","listGroupsViaDataLoader","ex","WebinyError","message","data","onGroupBeforeCreate","createTopic","onGroupAfterCreate","onGroupCreateError","onGroupBeforeUpdate","onGroupAfterUpdate","onGroupUpdateError","onGroupBeforeDelete","onGroupAfterDelete","onGroupDeleteError","assignBeforeGroupCreate","assignBeforeGroupUpdate","assignBeforeGroupDelete","getGroup","ensure","rwd","owns","createdBy","ensureCanAccessGroup","response","filterAsync","ownsGroup","throw","canAccessGroup","createGroup","input","result","createGroupCreateValidation","safeParseAsync","success","createZodError","error","identity","mdbid","createdOn","Date","toISOString","savedOn","displayName","publish","create","updateGroup","original","createGroupUpdateValidation","keys","length","updatedGroup","update","deleteGroup","delete","onBeforeGroupCreate","onAfterGroupCreate","onBeforeGroupUpdate","onAfterGroupUpdate","onBeforeGroupDelete","onAfterGroupDelete","benchmark","measure"],"sources":["contentModelGroup.crud.ts"],"sourcesContent":["import DataLoader from \"dataloader\";\nimport WebinyError from \"@webiny/error\";\nimport {\n CmsGroupContext,\n CmsGroupListParams,\n CmsGroup,\n CmsContext,\n HeadlessCmsStorageOperations,\n OnGroupBeforeCreateTopicParams,\n OnGroupAfterCreateTopicParams,\n OnGroupBeforeUpdateTopicParams,\n OnGroupAfterUpdateTopicParams,\n OnGroupBeforeDeleteTopicParams,\n OnGroupAfterDeleteTopicParams,\n OnGroupCreateErrorTopicParams,\n OnGroupUpdateErrorTopicParams,\n OnGroupDeleteErrorTopicParams\n} from \"~/types\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\nimport { CmsGroupPlugin } from \"~/plugins/CmsGroupPlugin\";\nimport { Tenant } from \"@webiny/api-tenancy/types\";\nimport { I18NLocale } from \"@webiny/api-i18n/types\";\nimport { SecurityIdentity } from \"@webiny/api-security/types\";\nimport { createTopic } from \"@webiny/pubsub\";\nimport { assignBeforeGroupUpdate } from \"./contentModelGroup/beforeUpdate\";\nimport { assignBeforeGroupCreate } from \"./contentModelGroup/beforeCreate\";\nimport { assignBeforeGroupDelete } from \"./contentModelGroup/beforeDelete\";\nimport {\n createGroupCreateValidation,\n createGroupUpdateValidation\n} from \"~/crud/contentModelGroup/validation\";\nimport { createZodError, mdbid } from \"@webiny/utils\";\nimport { ModelGroupsPermissions } from \"~/utils/permissions/ModelGroupsPermissions\";\nimport { filterAsync } from \"~/utils/filterAsync\";\n\nexport interface CreateModelGroupsCrudParams {\n getTenant: () => Tenant;\n getLocale: () => I18NLocale;\n storageOperations: HeadlessCmsStorageOperations;\n modelGroupsPermissions: ModelGroupsPermissions;\n context: CmsContext;\n getIdentity: () => SecurityIdentity;\n}\n\nexport const createModelGroupsCrud = (params: CreateModelGroupsCrudParams): CmsGroupContext => {\n const {\n getTenant,\n getIdentity,\n getLocale,\n storageOperations,\n modelGroupsPermissions,\n context\n } = params;\n\n const dataLoaders = {\n listGroups: new DataLoader(async () => {\n const tenant = getTenant().id;\n const locale = getLocale().code;\n\n const pluginsGroups = getGroupsAsPlugins().map(group => {\n return {\n ...group,\n tenant: group.tenant || tenant,\n locale: group.locale || locale\n };\n });\n\n const groups = await storageOperations.groups.list({\n where: {\n tenant: getTenant().id,\n locale: getLocale().code\n }\n });\n\n return [groups.concat(pluginsGroups)];\n })\n };\n\n const clearGroupsCache = (): void => {\n for (const loader of Object.values(dataLoaders)) {\n loader.clearAll();\n }\n };\n\n const getGroupsAsPlugins = (): CmsGroup[] => {\n const tenant = getTenant().id;\n const locale = getLocale().code;\n\n return (\n context.plugins\n .byType<CmsGroupPlugin>(CmsGroupPlugin.type)\n /**\n * We need to filter out groups that are not for this tenant or locale.\n * If it does not have tenant or locale define, it is for every locale and tenant\n */\n .filter(plugin => {\n const { tenant: t, locale: l } = plugin.contentModelGroup;\n if (t && t !== tenant) {\n return false;\n } else if (l && l !== locale) {\n return false;\n }\n return true;\n })\n .map(plugin => {\n return {\n ...plugin.contentModelGroup,\n tenant,\n locale,\n webinyVersion: context.WEBINY_VERSION\n };\n })\n );\n };\n\n const getGroupViaDataLoader = async (id: string) => {\n const groups = await dataLoaders.listGroups.load(\"listGroups\");\n\n const group = groups.find(g => g.id === id);\n\n if (!group) {\n throw new NotFoundError(`Cms Group \"${id}\" was not found!`);\n }\n return group;\n };\n\n const listGroupsViaDataLoader = async (params: CmsGroupListParams) => {\n const { where } = params || {};\n\n try {\n return await dataLoaders.listGroups.load(\"listGroups\");\n } catch (ex) {\n throw new WebinyError(ex.message, ex.code || \"LIST_ERROR\", {\n ...(ex.data || {}),\n where\n });\n }\n };\n\n /**\n * Create\n */\n const onGroupBeforeCreate =\n createTopic<OnGroupBeforeCreateTopicParams>(\"cms.onGroupBeforeCreate\");\n const onGroupAfterCreate = createTopic<OnGroupAfterCreateTopicParams>(\"cms.onGroupAfterCreate\");\n const onGroupCreateError = createTopic<OnGroupCreateErrorTopicParams>(\"cms.onGroupCreateError\");\n /**\n * Update\n */\n const onGroupBeforeUpdate =\n createTopic<OnGroupBeforeUpdateTopicParams>(\"cms.onGroupBeforeUpdate\");\n const onGroupAfterUpdate = createTopic<OnGroupAfterUpdateTopicParams>(\"cms.onGroupAfterUpdate\");\n const onGroupUpdateError = createTopic<OnGroupUpdateErrorTopicParams>(\"cms.onGroupUpdateError\");\n /**\n * Delete\n */\n const onGroupBeforeDelete =\n createTopic<OnGroupBeforeDeleteTopicParams>(\"cms.onGroupBeforeDelete\");\n const onGroupAfterDelete = createTopic<OnGroupAfterDeleteTopicParams>(\"cms.onGroupAfterDelete\");\n const onGroupDeleteError = createTopic<OnGroupDeleteErrorTopicParams>(\"cms.onGroupDeleteError\");\n\n /**\n * We need to assign some default behaviors.\n */\n assignBeforeGroupCreate({\n onGroupBeforeCreate,\n plugins: context.plugins,\n storageOperations\n });\n assignBeforeGroupUpdate({\n onGroupBeforeUpdate,\n plugins: context.plugins\n });\n assignBeforeGroupDelete({\n onGroupBeforeDelete,\n plugins: context.plugins,\n storageOperations\n });\n /**\n * CRUD Methods\n */\n const getGroup: CmsGroupContext[\"getGroup\"] = async id => {\n await modelGroupsPermissions.ensure({ rwd: \"r\" });\n\n const group = await getGroupViaDataLoader(id);\n\n await modelGroupsPermissions.ensure({ owns: group.createdBy });\n await modelGroupsPermissions.ensureCanAccessGroup({ group, locale: getLocale().code });\n\n return group;\n };\n const listGroups: CmsGroupContext[\"listGroups\"] = async params => {\n const { where } = params || {};\n\n const { tenant, locale } = where || {};\n\n await modelGroupsPermissions.ensure({ rwd: \"r\" });\n\n const response = await listGroupsViaDataLoader({\n ...(params || {}),\n where: {\n ...(where || {}),\n tenant: tenant || getTenant().id,\n locale: locale || getLocale().code\n }\n });\n\n return filterAsync(response, async group => {\n const ownsGroup = await modelGroupsPermissions.ensure(\n { owns: group.createdBy },\n { throw: false }\n );\n\n if (!ownsGroup) {\n return false;\n }\n\n return await modelGroupsPermissions.canAccessGroup({\n group,\n locale: getLocale().code\n });\n });\n };\n const createGroup: CmsGroupContext[\"createGroup\"] = async input => {\n await modelGroupsPermissions.ensure({ rwd: \"w\" });\n\n const result = await createGroupCreateValidation().safeParseAsync(input);\n\n if (!result.success) {\n throw createZodError(result.error);\n }\n const data = result.data;\n\n const identity = getIdentity();\n\n const id = mdbid();\n const group: CmsGroup = {\n ...data,\n id,\n tenant: getTenant().id,\n locale: getLocale().code,\n createdOn: new Date().toISOString(),\n savedOn: new Date().toISOString(),\n createdBy: {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n },\n webinyVersion: context.WEBINY_VERSION\n };\n try {\n await onGroupBeforeCreate.publish({\n group\n });\n\n const result = await storageOperations.groups.create({\n group\n });\n\n clearGroupsCache();\n\n await onGroupAfterCreate.publish({\n group: result\n });\n\n return group;\n } catch (ex) {\n await onGroupCreateError.publish({\n input,\n group,\n error: ex\n });\n throw new WebinyError(\n ex.message || \"Could not save data model group.\",\n ex.code || \"ERROR_ON_CREATE\",\n {\n ...(ex.data || {}),\n group,\n input\n }\n );\n }\n };\n const updateGroup: CmsGroupContext[\"updateGroup\"] = async (id, input) => {\n await modelGroupsPermissions.ensure({ rwd: \"w\" });\n\n const original = await getGroupViaDataLoader(id);\n\n await modelGroupsPermissions.ensure({ owns: original.createdBy });\n\n const result = await createGroupUpdateValidation().safeParseAsync(input);\n\n if (!result.success) {\n throw createZodError(result.error);\n }\n const data = result.data;\n\n /**\n * No need to continue if no values were changed\n */\n if (Object.keys(data).length === 0) {\n return original;\n }\n\n const group: CmsGroup = {\n ...original,\n ...data,\n locale: getLocale().code,\n tenant: getTenant().id,\n savedOn: new Date().toISOString()\n };\n\n try {\n await onGroupBeforeUpdate.publish({\n original,\n group\n });\n\n const updatedGroup = await storageOperations.groups.update({\n group\n });\n clearGroupsCache();\n\n await onGroupAfterUpdate.publish({\n original,\n group: updatedGroup\n });\n\n return updatedGroup;\n } catch (ex) {\n await onGroupUpdateError.publish({\n input,\n original,\n group,\n error: ex\n });\n throw new WebinyError(ex.message, ex.code || \"UPDATE_ERROR\", {\n error: ex,\n original,\n group,\n input\n });\n }\n };\n const deleteGroup: CmsGroupContext[\"deleteGroup\"] = async id => {\n await modelGroupsPermissions.ensure({ rwd: \"d\" });\n\n const group = await getGroupViaDataLoader(id);\n\n await modelGroupsPermissions.ensure({ owns: group.createdBy });\n\n try {\n await onGroupBeforeDelete.publish({\n group\n });\n\n await storageOperations.groups.delete({ group });\n clearGroupsCache();\n\n await onGroupAfterDelete.publish({\n group\n });\n } catch (ex) {\n await onGroupDeleteError.publish({\n group,\n error: ex\n });\n throw new WebinyError(ex.message, ex.code || \"DELETE_ERROR\", {\n ...(ex.data || {}),\n id\n });\n }\n\n return true;\n };\n\n return {\n /**\n * Deprecated - will be removed in 5.36.0\n */\n onBeforeGroupCreate: onGroupBeforeCreate,\n onAfterGroupCreate: onGroupAfterCreate,\n onBeforeGroupUpdate: onGroupBeforeUpdate,\n onAfterGroupUpdate: onGroupAfterUpdate,\n onBeforeGroupDelete: onGroupBeforeDelete,\n onAfterGroupDelete: onGroupAfterDelete,\n /**\n * Released in 5.34.0\n */\n onGroupBeforeCreate,\n onGroupAfterCreate,\n onGroupCreateError,\n onGroupBeforeUpdate,\n onGroupAfterUpdate,\n onGroupUpdateError,\n onGroupBeforeDelete,\n onGroupAfterDelete,\n onGroupDeleteError,\n clearGroupsCache,\n getGroup: async id => {\n return context.benchmark.measure(\"headlessCms.crud.groups.getGroup\", async () => {\n return getGroup(id);\n });\n },\n listGroups: async params => {\n return context.benchmark.measure(\"headlessCms.crud.groups.listGroups\", async () => {\n return listGroups(params);\n });\n },\n createGroup: async input => {\n return context.benchmark.measure(\"headlessCms.crud.groups.createGroup\", async () => {\n return createGroup(input);\n });\n },\n updateGroup: async (id, input) => {\n return context.benchmark.measure(\"headlessCms.crud.groups.updateGroup\", async () => {\n return updateGroup(id, input);\n });\n },\n deleteGroup: async id => {\n return context.benchmark.measure(\"headlessCms.crud.groups.deleteGroup\", async () => {\n return deleteGroup(id);\n });\n }\n };\n};\n"],"mappings":";;;;;;;;AAAA;AACA;AAiBA;AACA;AAIA;AACA;AACA;AACA;AACA;AAIA;AAEA;AAWO,MAAMA,qBAAqB,GAAIC,MAAmC,IAAsB;EAC3F,MAAM;I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8D,KAAK,CAAC;MACjC,CAAC,CAAC;IACN,CAAC;IACDuB,WAAW,EAAE,MAAMrF,EAAE,IAAI;MACrB,OAAOL,OAAO,CAACkG,SAAS,CAACC,OAAO,CAAC,qCAAqC,EAAE,YAAY;QAChF,OAAOT,WAAW,CAACrF,EAAE,CAAC;MAC1B,CAAC,CAAC;IACN;EACJ,CAAC;AACL,CAAC;AAAC"}
|
|
1
|
+
{"version":3,"names":["_error","_interopRequireDefault","require","_CmsGroupPlugin","_pubsub","_beforeUpdate","_beforeCreate","_beforeDelete","_validation","_utils","_filterAsync","_utils2","_listGroupsFromDatabase","_handlerGraphql","createModelGroupsCrud","params","getTenant","getIdentity","getLocale","storageOperations","modelGroupsPermissions","context","filterGroup","group","ownsGroup","ensure","owns","createdBy","throw","canAccessGroup","listDatabaseGroupsCache","createMemoryCache","listFilteredDatabaseGroupsCache","listPluginGroupsCache","clearGroupsCache","clear","fetchPluginGroups","tenant","locale","pluginGroups","plugins","byType","CmsGroupPlugin","type","cacheKey","createCacheKey","identity","security","isAuthorizationEnabled","id","undefined","groups","map","contentModelGroup","slug","savedOn","join","getOrSet","filter","plugin","t","l","webinyVersion","WEBINY_VERSION","filterAsync","fetchGroups","databaseGroups","listGroupsFromDatabase","filteredCacheKey","dbCacheKey","get","concat","onGroupBeforeCreate","createTopic","onGroupAfterCreate","onGroupCreateError","onGroupBeforeUpdate","onGroupAfterUpdate","onGroupUpdateError","onGroupBeforeDelete","onGroupAfterDelete","onGroupDeleteError","assignBeforeGroupCreate","assignBeforeGroupUpdate","assignBeforeGroupDelete","getGroup","rwd","withoutAuthorization","code","find","NotFoundError","ensureCanAccessGroup","listGroups","where","createGroup","input","result","createGroupCreateValidation","safeParseAsync","success","createZodError","error","data","mdbid","createdOn","Date","toISOString","displayName","publish","create","ex","WebinyError","message","updateGroup","original","createGroupUpdateValidation","Object","keys","length","updatedGroup","update","deleteGroup","delete","benchmark","measure","exports"],"sources":["contentModelGroup.crud.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport {\n CmsContext,\n CmsGroup,\n CmsGroupContext,\n HeadlessCmsStorageOperations,\n OnGroupAfterCreateTopicParams,\n OnGroupAfterDeleteTopicParams,\n OnGroupAfterUpdateTopicParams,\n OnGroupBeforeCreateTopicParams,\n OnGroupBeforeDeleteTopicParams,\n OnGroupBeforeUpdateTopicParams,\n OnGroupCreateErrorTopicParams,\n OnGroupDeleteErrorTopicParams,\n OnGroupUpdateErrorTopicParams\n} from \"~/types\";\nimport { CmsGroupPlugin } from \"~/plugins/CmsGroupPlugin\";\nimport { Tenant } from \"@webiny/api-tenancy/types\";\nimport { I18NLocale } from \"@webiny/api-i18n/types\";\nimport { SecurityIdentity } from \"@webiny/api-security/types\";\nimport { createTopic } from \"@webiny/pubsub\";\nimport { assignBeforeGroupUpdate } from \"./contentModelGroup/beforeUpdate\";\nimport { assignBeforeGroupCreate } from \"./contentModelGroup/beforeCreate\";\nimport { assignBeforeGroupDelete } from \"./contentModelGroup/beforeDelete\";\nimport {\n createGroupCreateValidation,\n createGroupUpdateValidation\n} from \"~/crud/contentModelGroup/validation\";\nimport { createZodError, mdbid } from \"@webiny/utils\";\nimport { ModelGroupsPermissions } from \"~/utils/permissions/ModelGroupsPermissions\";\nimport { filterAsync } from \"~/utils/filterAsync\";\nimport { createCacheKey, createMemoryCache } from \"~/utils\";\nimport { listGroupsFromDatabase } from \"~/crud/contentModelGroup/listGroupsFromDatabase\";\nimport { NotFoundError } from \"@webiny/handler-graphql\";\n\nexport interface CreateModelGroupsCrudParams {\n getTenant: () => Tenant;\n getLocale: () => I18NLocale;\n storageOperations: HeadlessCmsStorageOperations;\n modelGroupsPermissions: ModelGroupsPermissions;\n context: CmsContext;\n getIdentity: () => SecurityIdentity;\n}\n\nexport const createModelGroupsCrud = (params: CreateModelGroupsCrudParams): CmsGroupContext => {\n const {\n getTenant,\n getIdentity,\n getLocale,\n storageOperations,\n modelGroupsPermissions,\n context\n } = params;\n\n const filterGroup = async (group?: CmsGroup) => {\n if (!group) {\n return false;\n }\n const ownsGroup = await modelGroupsPermissions.ensure(\n { owns: group.createdBy },\n { throw: false }\n );\n\n if (!ownsGroup) {\n return false;\n }\n\n return await modelGroupsPermissions.canAccessGroup({\n group\n });\n };\n\n const listDatabaseGroupsCache = createMemoryCache<Promise<CmsGroup[]>>();\n const listFilteredDatabaseGroupsCache = createMemoryCache<Promise<CmsGroup[]>>();\n const listPluginGroupsCache = createMemoryCache<Promise<CmsGroup[]>>();\n const clearGroupsCache = (): void => {\n listPluginGroupsCache.clear();\n listDatabaseGroupsCache.clear();\n listFilteredDatabaseGroupsCache.clear();\n };\n\n const fetchPluginGroups = (tenant: string, locale: string): Promise<CmsGroup[]> => {\n const pluginGroups = context.plugins.byType<CmsGroupPlugin>(CmsGroupPlugin.type);\n\n const cacheKey = createCacheKey({\n tenant,\n locale,\n identity: context.security.isAuthorizationEnabled() ? getIdentity()?.id : undefined,\n groups: pluginGroups\n .map(({ contentModelGroup: group }) => {\n return `${group.id}#${group.slug}#${group.savedOn || \"unknown\"}`;\n })\n .join(\"/\")\n });\n\n return listPluginGroupsCache.getOrSet(cacheKey, async (): Promise<CmsGroup[]> => {\n const groups = pluginGroups\n /**\n * We need to filter out groups that are not for this tenant or locale.\n * If it does not have tenant or locale define, it is for every locale and tenant\n */\n .filter(plugin => {\n const { tenant: t, locale: l } = plugin.contentModelGroup;\n if (t && t !== tenant) {\n return false;\n } else if (l && l !== locale) {\n return false;\n }\n return true;\n })\n .map(plugin => {\n return {\n ...plugin.contentModelGroup,\n tenant,\n locale,\n webinyVersion: context.WEBINY_VERSION\n };\n });\n return filterAsync(groups, filterGroup);\n });\n };\n\n const fetchGroups = async (tenant: string, locale: string) => {\n const pluginGroups = await fetchPluginGroups(tenant, locale);\n /**\n * Maybe we can cache based on permissions, not the identity id?\n *\n * TODO: @adrian please check if possible.\n */\n const cacheKey = createCacheKey({\n tenant,\n locale\n });\n const databaseGroups = await listDatabaseGroupsCache.getOrSet(cacheKey, async () => {\n return await listGroupsFromDatabase({\n storageOperations,\n tenant,\n locale\n });\n });\n const filteredCacheKey = createCacheKey({\n dbCacheKey: cacheKey.get(),\n identity: context.security.isAuthorizationEnabled() ? getIdentity()?.id : undefined\n });\n\n const groups = await listFilteredDatabaseGroupsCache.getOrSet(\n filteredCacheKey,\n async () => {\n return filterAsync(databaseGroups, filterGroup);\n }\n );\n\n return groups.concat(pluginGroups);\n };\n\n /**\n * Create\n */\n const onGroupBeforeCreate =\n createTopic<OnGroupBeforeCreateTopicParams>(\"cms.onGroupBeforeCreate\");\n const onGroupAfterCreate = createTopic<OnGroupAfterCreateTopicParams>(\"cms.onGroupAfterCreate\");\n const onGroupCreateError = createTopic<OnGroupCreateErrorTopicParams>(\"cms.onGroupCreateError\");\n /**\n * Update\n */\n const onGroupBeforeUpdate =\n createTopic<OnGroupBeforeUpdateTopicParams>(\"cms.onGroupBeforeUpdate\");\n const onGroupAfterUpdate = createTopic<OnGroupAfterUpdateTopicParams>(\"cms.onGroupAfterUpdate\");\n const onGroupUpdateError = createTopic<OnGroupUpdateErrorTopicParams>(\"cms.onGroupUpdateError\");\n /**\n * Delete\n */\n const onGroupBeforeDelete =\n createTopic<OnGroupBeforeDeleteTopicParams>(\"cms.onGroupBeforeDelete\");\n const onGroupAfterDelete = createTopic<OnGroupAfterDeleteTopicParams>(\"cms.onGroupAfterDelete\");\n const onGroupDeleteError = createTopic<OnGroupDeleteErrorTopicParams>(\"cms.onGroupDeleteError\");\n\n /**\n * We need to assign some default behaviors.\n */\n assignBeforeGroupCreate({\n onGroupBeforeCreate,\n plugins: context.plugins,\n storageOperations\n });\n assignBeforeGroupUpdate({\n onGroupBeforeUpdate,\n plugins: context.plugins\n });\n assignBeforeGroupDelete({\n onGroupBeforeDelete,\n plugins: context.plugins,\n storageOperations\n });\n /**\n * CRUD Methods\n */\n const getGroup: CmsGroupContext[\"getGroup\"] = async id => {\n await modelGroupsPermissions.ensure({ rwd: \"r\" });\n\n const groups = await context.security.withoutAuthorization(async () => {\n return fetchGroups(getTenant().id, getLocale().code);\n });\n const group = groups.find(group => group.id === id);\n if (!group) {\n throw new NotFoundError(`Cms Group \"${id}\" was not found!`);\n }\n\n await modelGroupsPermissions.ensure({ owns: group.createdBy });\n await modelGroupsPermissions.ensureCanAccessGroup({\n group\n });\n\n return group;\n };\n\n const listGroups: CmsGroupContext[\"listGroups\"] = async params => {\n const { where } = params || {};\n\n const { tenant, locale } = where || {};\n\n await modelGroupsPermissions.ensure({ rwd: \"r\" });\n\n return fetchGroups(tenant || getTenant().id, locale || getLocale().code);\n };\n\n const createGroup: CmsGroupContext[\"createGroup\"] = async input => {\n await modelGroupsPermissions.ensure({ rwd: \"w\" });\n\n const result = await createGroupCreateValidation().safeParseAsync(input);\n\n if (!result.success) {\n throw createZodError(result.error);\n }\n const data = result.data;\n\n const identity = getIdentity();\n\n const id = data.id || mdbid();\n const group: CmsGroup = {\n ...data,\n id,\n tenant: getTenant().id,\n locale: getLocale().code,\n createdOn: new Date().toISOString(),\n savedOn: new Date().toISOString(),\n createdBy: {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n },\n webinyVersion: context.WEBINY_VERSION\n };\n try {\n await onGroupBeforeCreate.publish({\n group\n });\n\n const result = await storageOperations.groups.create({\n group\n });\n\n clearGroupsCache();\n\n await onGroupAfterCreate.publish({\n group: result\n });\n\n return group;\n } catch (ex) {\n await onGroupCreateError.publish({\n input,\n group,\n error: ex\n });\n throw new WebinyError(\n ex.message || \"Could not save data model group.\",\n ex.code || \"ERROR_ON_CREATE\",\n {\n ...(ex.data || {}),\n group,\n input\n }\n );\n }\n };\n const updateGroup: CmsGroupContext[\"updateGroup\"] = async (id, input) => {\n await modelGroupsPermissions.ensure({ rwd: \"w\" });\n\n const original = await getGroup(id);\n\n await modelGroupsPermissions.ensure({ owns: original.createdBy });\n\n const result = await createGroupUpdateValidation().safeParseAsync(input);\n\n if (!result.success) {\n throw createZodError(result.error);\n }\n const data = result.data;\n\n /**\n * No need to continue if no values were changed\n */\n if (Object.keys(data).length === 0) {\n return original;\n }\n\n const group: CmsGroup = {\n ...original,\n ...data,\n locale: getLocale().code,\n tenant: getTenant().id,\n savedOn: new Date().toISOString()\n };\n\n try {\n await onGroupBeforeUpdate.publish({\n original,\n group\n });\n\n const updatedGroup = await storageOperations.groups.update({\n group\n });\n clearGroupsCache();\n\n await onGroupAfterUpdate.publish({\n original,\n group: updatedGroup\n });\n\n return updatedGroup;\n } catch (ex) {\n await onGroupUpdateError.publish({\n input,\n original,\n group,\n error: ex\n });\n throw new WebinyError(ex.message, ex.code || \"UPDATE_ERROR\", {\n error: ex,\n original,\n group,\n input\n });\n }\n };\n const deleteGroup: CmsGroupContext[\"deleteGroup\"] = async id => {\n await modelGroupsPermissions.ensure({ rwd: \"d\" });\n\n const group = await getGroup(id);\n\n await modelGroupsPermissions.ensure({ owns: group.createdBy });\n\n try {\n await onGroupBeforeDelete.publish({\n group\n });\n\n await storageOperations.groups.delete({ group });\n clearGroupsCache();\n\n await onGroupAfterDelete.publish({\n group\n });\n } catch (ex) {\n await onGroupDeleteError.publish({\n group,\n error: ex\n });\n throw new WebinyError(ex.message, ex.code || \"DELETE_ERROR\", {\n ...(ex.data || {}),\n id\n });\n }\n\n return true;\n };\n\n return {\n onGroupBeforeCreate,\n onGroupAfterCreate,\n onGroupCreateError,\n onGroupBeforeUpdate,\n onGroupAfterUpdate,\n onGroupUpdateError,\n onGroupBeforeDelete,\n onGroupAfterDelete,\n onGroupDeleteError,\n clearGroupsCache,\n getGroup: async id => {\n return context.benchmark.measure(\"headlessCms.crud.groups.getGroup\", async () => {\n return getGroup(id);\n });\n },\n listGroups: async params => {\n return context.benchmark.measure(\"headlessCms.crud.groups.listGroups\", async () => {\n return listGroups(params);\n });\n },\n createGroup: async input => {\n return context.benchmark.measure(\"headlessCms.crud.groups.createGroup\", async () => {\n return createGroup(input);\n });\n },\n updateGroup: async (id, input) => {\n return context.benchmark.measure(\"headlessCms.crud.groups.updateGroup\", async () => {\n return updateGroup(id, input);\n });\n },\n deleteGroup: async id => {\n return context.benchmark.measure(\"headlessCms.crud.groups.deleteGroup\", async () => {\n return deleteGroup(id);\n });\n }\n };\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAgBA,IAAAC,eAAA,GAAAD,OAAA;AAIA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,aAAA,GAAAH,OAAA;AACA,IAAAI,aAAA,GAAAJ,OAAA;AACA,IAAAK,aAAA,GAAAL,OAAA;AACA,IAAAM,WAAA,GAAAN,OAAA;AAIA,IAAAO,MAAA,GAAAP,OAAA;AAEA,IAAAQ,YAAA,GAAAR,OAAA;AACA,IAAAS,OAAA,GAAAT,OAAA;AACA,IAAAU,uBAAA,GAAAV,OAAA;AACA,IAAAW,eAAA,GAAAX,OAAA;AAWO,MAAMY,qBAAqB,GAAIC,MAAmC,IAAsB;EAC3F,MAAM;IACFC,SAAS;IACTC,WAAW;IACXC,SAAS;IACTC,iBAAiB;IACjBC,sBAAsB;IACtBC;EACJ,CAAC,GAAGN,MAAM;EAEV,MAAMO,WAAW,GAAG,MAAOC,KAAgB,IAAK;IAC5C,IAAI,CAACA,KAAK,EAAE;MACR,OAAO,KAAK;IAChB;IACA,MAAMC,SAAS,GAAG,MAAMJ,sBAAsB,CAACK,MAAM,CACjD;MAAEC,IAAI,EAAEH,KAAK,CAACI;IAAU,CAAC,EACzB;MAAEC,KAAK,EAAE;IAAM,CACnB,CAAC;IAED,IAAI,CAACJ,SAAS,EAAE;MACZ,OAAO,KAAK;IAChB;IAEA,OAAO,MAAMJ,sBAAsB,CAACS,cAAc,CAAC;MAC/CN;IACJ,CAAC,CAAC;EACN,CAAC;EAED,MAAMO,uBAAuB,GAAG,IAAAC,yBAAiB,EAAsB,CAAC;EACxE,MAAMC,+BAA+B,GAAG,IAAAD,yBAAiB,EAAsB,CAAC;EAChF,MAAME,qBAAqB,GAAG,IAAAF,yBA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CAAC;IACN;EACJ,CAAC;AACL,CAAC;AAAC4E,OAAA,CAAA/G,qBAAA,GAAAA,qBAAA"}
|
package/crud/system.crud.js
CHANGED
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.createSystemCrud = void 0;
|
|
8
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
9
8
|
var _apiSecurity = require("@webiny/api-security");
|
|
10
9
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
10
|
var _pubsub = require("@webiny/pubsub");
|
|
@@ -33,16 +32,17 @@ const createSystemCrud = params => {
|
|
|
33
32
|
const system = await storageOperations.system.get({
|
|
34
33
|
tenant: getTenant().id
|
|
35
34
|
});
|
|
36
|
-
return
|
|
35
|
+
return system?.version || null;
|
|
37
36
|
};
|
|
38
37
|
const setVersion = async version => {
|
|
39
38
|
const original = await storageOperations.system.get({
|
|
40
39
|
tenant: getTenant().id
|
|
41
40
|
});
|
|
42
|
-
const system =
|
|
41
|
+
const system = {
|
|
42
|
+
...(original || {}),
|
|
43
43
|
version,
|
|
44
44
|
tenant: getTenant().id
|
|
45
|
-
}
|
|
45
|
+
};
|
|
46
46
|
if (!original) {
|
|
47
47
|
await storageOperations.system.create({
|
|
48
48
|
system
|
|
@@ -55,12 +55,7 @@ const createSystemCrud = params => {
|
|
|
55
55
|
};
|
|
56
56
|
return {
|
|
57
57
|
/**
|
|
58
|
-
*
|
|
59
|
-
*/
|
|
60
|
-
onBeforeSystemInstall: onSystemBeforeInstall,
|
|
61
|
-
onAfterSystemInstall: onSystemAfterInstall,
|
|
62
|
-
/**
|
|
63
|
-
* Released in 5.34.0
|
|
58
|
+
* Lifecycle Events.
|
|
64
59
|
*/
|
|
65
60
|
onSystemBeforeInstall,
|
|
66
61
|
onSystemAfterInstall,
|
|
@@ -123,4 +118,6 @@ const createSystemCrud = params => {
|
|
|
123
118
|
}
|
|
124
119
|
};
|
|
125
120
|
};
|
|
126
|
-
exports.createSystemCrud = createSystemCrud;
|
|
121
|
+
exports.createSystemCrud = createSystemCrud;
|
|
122
|
+
|
|
123
|
+
//# sourceMappingURL=system.crud.js.map
|
package/crud/system.crud.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["initialContentModelGroup","name","slug","description","icon","createSystemCrud","params","getTenant","getLocale","storageOperations","context","getIdentity","onSystemBeforeInstall","createTopic","onSystemAfterInstall","onSystemInstallError","getVersion","system","get","tenant","id","version","setVersion","original","create","update","
|
|
1
|
+
{"version":3,"names":["_apiSecurity","require","_error","_interopRequireDefault","_pubsub","initialContentModelGroup","name","slug","description","icon","createSystemCrud","params","getTenant","getLocale","storageOperations","context","getIdentity","onSystemBeforeInstall","createTopic","onSystemAfterInstall","onSystemInstallError","getVersion","system","get","tenant","id","version","setVersion","original","create","update","getSystemVersion","setSystemVersion","installSystem","identity","NotAuthorizedError","publish","locale","code","cms","createGroup","ex","WebinyError","message","group","WEBINY_VERSION","error","data","exports"],"sources":["system.crud.ts"],"sourcesContent":["import { NotAuthorizedError } from \"@webiny/api-security\";\nimport WebinyError from \"@webiny/error\";\nimport {\n OnSystemAfterInstallTopicParams,\n OnSystemBeforeInstallTopicParams,\n CmsContext,\n CmsSystem,\n CmsSystemContext,\n HeadlessCmsStorageOperations,\n OnSystemInstallErrorTopicParams\n} from \"~/types\";\nimport { Tenant } from \"@webiny/api-tenancy/types\";\nimport { SecurityIdentity } from \"@webiny/api-security/types\";\nimport { createTopic } from \"@webiny/pubsub\";\nimport { I18NLocale } from \"@webiny/api-i18n/types\";\n\nconst initialContentModelGroup = {\n name: \"Ungrouped\",\n slug: \"ungrouped\",\n description: \"A generic content model group\",\n icon: \"fas/star\"\n};\n\ninterface CreateSystemCrudParams {\n getTenant: () => Tenant;\n getLocale: () => I18NLocale;\n storageOperations: HeadlessCmsStorageOperations;\n context: CmsContext;\n getIdentity: () => SecurityIdentity;\n}\nexport const createSystemCrud = (params: CreateSystemCrudParams): CmsSystemContext => {\n const { getTenant, getLocale, storageOperations, context, getIdentity } = params;\n\n const onSystemBeforeInstall = createTopic<OnSystemBeforeInstallTopicParams>(\n \"cms.onSystemBeforeInstall\"\n );\n const onSystemAfterInstall = createTopic<OnSystemAfterInstallTopicParams>(\n \"cms.onSystemAfterInstall\"\n );\n\n const onSystemInstallError = createTopic<OnSystemInstallErrorTopicParams>(\n \"cms.onSystemInstallError\"\n );\n\n const getVersion = async () => {\n if (!getTenant()) {\n return null;\n }\n\n const system = await storageOperations.system.get({\n tenant: getTenant().id\n });\n\n return system?.version || null;\n };\n\n const setVersion = async (version: string) => {\n const original = await storageOperations.system.get({\n tenant: getTenant().id\n });\n const system: CmsSystem = {\n ...(original || {}),\n version,\n tenant: getTenant().id\n };\n if (!original) {\n await storageOperations.system.create({\n system\n });\n return;\n }\n await storageOperations.system.update({\n system\n });\n };\n\n return {\n /**\n * Lifecycle Events.\n */\n onSystemBeforeInstall,\n onSystemAfterInstall,\n onSystemInstallError,\n getSystemVersion: getVersion,\n setSystemVersion: setVersion,\n installSystem: async (): Promise<void> => {\n const identity = getIdentity();\n if (!identity) {\n throw new NotAuthorizedError();\n }\n\n const version = await getVersion();\n if (version) {\n return;\n }\n try {\n /**\n * First trigger before install event.\n */\n await onSystemBeforeInstall.publish({\n tenant: getTenant().id,\n locale: getLocale().code\n });\n\n /**\n * Add default content model group.\n */\n try {\n await context.cms.createGroup(initialContentModelGroup);\n } catch (ex) {\n throw new WebinyError(\n ex.message,\n \"CMS_INSTALLATION_CONTENT_MODEL_GROUP_ERROR\",\n {\n group: initialContentModelGroup\n }\n );\n }\n\n const system: CmsSystem = {\n version: context.WEBINY_VERSION,\n tenant: getTenant().id\n };\n /**\n * We need to create the system data.\n */\n await storageOperations.system.create({\n system\n });\n /**\n * And trigger after install event.\n */\n await onSystemAfterInstall.publish({\n tenant: getTenant().id,\n locale: getLocale().code\n });\n } catch (ex) {\n await onSystemInstallError.publish({\n error: ex,\n tenant: getTenant().id,\n locale: getLocale().code\n });\n throw new WebinyError(ex.message, ex.code, ex.data);\n }\n }\n };\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,sBAAA,CAAAF,OAAA;AAYA,IAAAG,OAAA,GAAAH,OAAA;AAGA,MAAMI,wBAAwB,GAAG;EAC7BC,IAAI,EAAE,WAAW;EACjBC,IAAI,EAAE,WAAW;EACjBC,WAAW,EAAE,+BAA+B;EAC5CC,IAAI,EAAE;AACV,CAAC;AASM,MAAMC,gBAAgB,GAAIC,MAA8B,IAAuB;EAClF,MAAM;IAAEC,SAAS;IAAEC,SAAS;IAAEC,iBAAiB;IAAEC,OAAO;IAAEC;EAAY,CAAC,GAAGL,MAAM;EAEhF,MAAMM,qBAAqB,GAAG,IAAAC,mBAAW,EACrC,2BACJ,CAAC;EACD,MAAMC,oBAAoB,GAAG,IAAAD,mBAAW,EACpC,0BACJ,CAAC;EAED,MAAME,oBAAoB,GAAG,IAAAF,mBAAW,EACpC,0BACJ,CAAC;EAED,MAAMG,UAAU,GAAG,MAAAA,CAAA,KAAY;IAC3B,IAAI,CAACT,SAAS,CAAC,CAAC,EAAE;MACd,OAAO,IAAI;IACf;IAEA,MAAMU,MAAM,GAAG,MAAMR,iBAAiB,CAACQ,MAAM,CAACC,GAAG,CAAC;MAC9CC,MAAM,EAAEZ,SAAS,CAAC,CAAC,CAACa;IACxB,CAAC,CAAC;IAEF,OAAOH,MAAM,EAAEI,OAAO,IAAI,IAAI;EAClC,CAAC;EAED,MAAMC,UAAU,GAAG,MAAOD,OAAe,IAAK;IAC1C,MAAME,QAAQ,GAAG,MAAMd,iBAAiB,CAACQ,MAAM,CAACC,GAAG,CAAC;MAChDC,MAAM,EAAEZ,SAAS,CAAC,CAAC,CAACa;IACxB,CAAC,CAAC;IACF,MAAMH,MAAiB,GAAG;MACtB,IAAIM,QAAQ,IAAI,CAAC,C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D;AAChB;AACA;QACgB,MAAMX,iBAAiB,CAACQ,MAAM,CAACO,MAAM,CAAC;UAClCP;QACJ,CAAC,CAAC;QACF;AAChB;AACA;QACgB,MAAMH,oBAAoB,CAACiB,OAAO,CAAC;UAC/BZ,MAAM,EAAEZ,SAAS,CAAC,CAAC,CAACa,EAAE;UACtBY,MAAM,EAAExB,SAAS,CAAC,CAAC,CAACyB;QACxB,CAAC,CAAC;MACN,CAAC,CAAC,OAAOG,EAAE,EAAE;QACT,MAAMrB,oBAAoB,CAACgB,OAAO,CAAC;UAC/BU,KAAK,EAAEL,EAAE;UACTjB,MAAM,EAAEZ,SAAS,CAAC,CAAC,CAACa,EAAE;UACtBY,MAAM,EAAExB,SAAS,CAAC,CAAC,CAACyB;QACxB,CAAC,CAAC;QACF,MAAM,IAAII,cAAW,CAACD,EAAE,CAACE,OAAO,EAAEF,EAAE,CAACH,IAAI,EAAEG,EAAE,CAACM,IAAI,CAAC;MACvD;IACJ;EACJ,CAAC;AACL,CAAC;AAACC,OAAA,CAAAtC,gBAAA,GAAAA,gBAAA"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createExportStructureContext = void 0;
|
|
7
|
+
var _sanitize = require("./sanitize");
|
|
8
|
+
const createExportStructureContext = context => {
|
|
9
|
+
return async params => {
|
|
10
|
+
const {
|
|
11
|
+
models: modelIdList
|
|
12
|
+
} = params;
|
|
13
|
+
const groups = (await context.cms.listGroups()).map(_sanitize.sanitizeGroup);
|
|
14
|
+
/**
|
|
15
|
+
* We need all the models which:
|
|
16
|
+
* * are accessible by current user
|
|
17
|
+
* * are not private
|
|
18
|
+
* * are included (if targets are provided)
|
|
19
|
+
* * are part of one of the groups we already fetched
|
|
20
|
+
*/
|
|
21
|
+
const models = (await context.cms.listModels()).filter(model => {
|
|
22
|
+
if (model.isPrivate) {
|
|
23
|
+
return false;
|
|
24
|
+
} else if (!model.fields?.length) {
|
|
25
|
+
return false;
|
|
26
|
+
} else if (!modelIdList?.length) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
return modelIdList.includes(model.modelId);
|
|
30
|
+
}).map(model => {
|
|
31
|
+
const group = groups.find(group => group.id === model.group.id);
|
|
32
|
+
if (!group) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return (0, _sanitize.sanitizeModel)(group, model);
|
|
36
|
+
}).filter(model => {
|
|
37
|
+
return !!model;
|
|
38
|
+
});
|
|
39
|
+
return {
|
|
40
|
+
groups: groups.filter(group => {
|
|
41
|
+
return models.some(model => model.group === group.id);
|
|
42
|
+
}),
|
|
43
|
+
models
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
exports.createExportStructureContext = createExportStructureContext;
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=exporting.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_sanitize","require","createExportStructureContext","context","params","models","modelIdList","groups","cms","listGroups","map","sanitizeGroup","listModels","filter","model","isPrivate","fields","length","includes","modelId","group","find","id","sanitizeModel","some","exports"],"sources":["exporting.ts"],"sourcesContent":["import { HeadlessCmsExportStructure, SanitizedCmsModel } from \"~/export/types\";\nimport { CmsContext } from \"~/types\";\nimport { sanitizeGroup, sanitizeModel } from \"./sanitize\";\n\nexport const createExportStructureContext = (context: CmsContext): HeadlessCmsExportStructure => {\n return async params => {\n const { models: modelIdList } = params;\n const groups = (await context.cms.listGroups()).map(sanitizeGroup);\n /**\n * We need all the models which:\n * * are accessible by current user\n * * are not private\n * * are included (if targets are provided)\n * * are part of one of the groups we already fetched\n */\n const models = (await context.cms.listModels())\n .filter(model => {\n if (model.isPrivate) {\n return false;\n } else if (!model.fields?.length) {\n return false;\n } else if (!modelIdList?.length) {\n return true;\n }\n return modelIdList.includes(model.modelId);\n })\n .map(model => {\n const group = groups.find(group => group.id === model.group.id);\n if (!group) {\n return null;\n }\n return sanitizeModel(group, model);\n })\n .filter((model): model is SanitizedCmsModel => {\n return !!model;\n });\n\n return {\n groups: groups.filter(group => {\n return models.some(model => model.group === group.id);\n }),\n models\n };\n };\n};\n"],"mappings":";;;;;;AAEA,IAAAA,SAAA,GAAAC,OAAA;AAEO,MAAMC,4BAA4B,GAAIC,OAAmB,IAAiC;EAC7F,OAAO,MAAMC,MAAM,IAAI;IACnB,MAAM;MAAEC,MAAM,EAAEC;IAAY,CAAC,GAAGF,MAAM;IACtC,MAAMG,MAAM,GAAG,CAAC,MAAMJ,OAAO,CAACK,GAAG,CAACC,UAAU,CAAC,CAAC,EAAEC,GAAG,CAACC,uBAAa,CAAC;IAClE;AACR;AACA;AACA;AACA;AACA;AACA;IACQ,MAAMN,MAAM,GAAG,CAAC,MAAMF,OAAO,CAACK,GAAG,CAACI,UAAU,CAAC,CAAC,EACzCC,MAAM,CAACC,KAAK,IAAI;MACb,IAAIA,KAAK,CAACC,SAAS,EAAE;QACjB,OAAO,KAAK;MAChB,CAAC,MAAM,IAAI,CAACD,KAAK,CAACE,MAAM,EAAEC,MAAM,EAAE;QAC9B,OAAO,KAAK;MAChB,CAAC,MAAM,IAAI,CAACX,WAAW,EAAEW,MAAM,EAAE;QAC7B,OAAO,IAAI;MACf;MACA,OAAOX,WAAW,CAACY,QAAQ,CAACJ,KAAK,CAACK,OAAO,CAAC;IAC9C,CAAC,CAAC,CACDT,GAAG,CAACI,KAAK,IAAI;MACV,MAAMM,KAAK,GAAGb,MAAM,CAACc,IAAI,CAACD,KAAK,IAAIA,KAAK,CAACE,EAAE,KAAKR,KAAK,CAACM,KAAK,CAACE,EAAE,CAAC;MAC/D,IAAI,CAACF,KAAK,EAAE;QACR,OAAO,IAAI;MACf;MACA,OAAO,IAAAG,uBAAa,EAACH,KAAK,EAAEN,KAAK,CAAC;IACtC,CAAC,CAAC,CACDD,MAAM,CAAEC,KAAK,IAAi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