@webiny/api-headless-cms 0.0.0-unstable.9e825fd5fb → 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 +32 -0
- package/constants.js +57 -0
- package/constants.js.map +1 -0
- package/context.js +77 -39
- 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 +142 -90
- 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 +5 -4
- package/crud/contentEntry.crud.js +558 -528
- 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.d.ts +1 -1
- package/crud/contentModel/beforeDelete.js +4 -6
- 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 +8 -7
- package/crud/contentModel/validateModelFields.js.map +1 -1
- package/crud/contentModel/validation.d.ts +586 -233
- package/crud/contentModel/validation.js +73 -13
- package/crud/contentModel/validation.js.map +1 -1
- package/crud/contentModel.crud.d.ts +2 -0
- package/crud/contentModel.crud.js +146 -181
- 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 +10 -7
- package/crud/contentModelGroup/validation.js +5 -2
- package/crud/contentModelGroup/validation.js.map +1 -1
- package/crud/contentModelGroup.crud.d.ts +3 -1
- package/crud/contentModelGroup.crud.js +139 -123
- 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.d.ts +2 -0
- package/graphql/checkEndpointAccess.js +20 -0
- package/graphql/checkEndpointAccess.js.map +1 -0
- package/graphql/createExecutableSchema.js +3 -1
- package/graphql/createExecutableSchema.js.map +1 -1
- package/graphql/createRequestBody.d.ts +2 -0
- package/graphql/createRequestBody.js +16 -0
- package/graphql/createRequestBody.js.map +1 -0
- package/graphql/formatErrorPayload.d.ts +1 -0
- package/graphql/formatErrorPayload.js +27 -0
- package/graphql/formatErrorPayload.js.map +1 -0
- package/graphql/generateSchema.js +3 -1
- package/graphql/generateSchema.js.map +1 -1
- package/graphql/getSchema.d.ts +16 -0
- package/graphql/getSchema.js +118 -0
- package/graphql/getSchema.js.map +1 -0
- package/graphql/graphQLHandlerFactory.js +8 -191
- package/graphql/graphQLHandlerFactory.js.map +1 -1
- package/graphql/handleRequest.d.ts +11 -0
- package/graphql/handleRequest.js +79 -0
- package/graphql/handleRequest.js.map +1 -0
- 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 +95 -2
- package/graphql/schema/baseSchema.js.map +1 -1
- package/graphql/schema/contentEntries.js +54 -16
- 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.d.ts +1 -1
- package/graphql/schema/createFieldResolvers.js +18 -22
- package/graphql/schema/createFieldResolvers.js.map +1 -1
- package/graphql/schema/createFieldTypePluginRecords.d.ts +3 -0
- package/graphql/schema/createFieldTypePluginRecords.js +15 -0
- package/graphql/schema/createFieldTypePluginRecords.js.map +1 -0
- package/graphql/schema/createManageResolvers.d.ts +1 -1
- package/graphql/schema/createManageResolvers.js +27 -10
- package/graphql/schema/createManageResolvers.js.map +1 -1
- package/graphql/schema/createManageSDL.js +83 -42
- 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 +35 -24
- 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.d.ts +2 -1
- package/graphql/schema/resolvers/manage/resolveDelete.js +16 -4
- package/graphql/schema/resolvers/manage/resolveDelete.js.map +1 -1
- package/graphql/schema/resolvers/manage/resolveDeleteMultiple.d.ts +7 -0
- package/graphql/schema/resolvers/manage/resolveDeleteMultiple.js +22 -0
- package/graphql/schema/resolvers/manage/resolveDeleteMultiple.js.map +1 -0
- 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.d.ts +4 -0
- package/graphql/schema/resolvers/manage/resolveGetUniqueFieldValues.js +20 -0
- package/graphql/schema/resolvers/manage/resolveGetUniqueFieldValues.js.map +1 -0
- 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.d.ts +8 -0
- package/graphql/schema/resolvers/manage/resolveMove.js +27 -0
- package/graphql/schema/resolvers/manage/resolveMove.js.map +1 -0
- 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 +5 -12
- package/graphql/schema/schemaPlugins.js.map +1 -1
- package/graphql/system.d.ts +2 -5
- package/graphql/system.js +4 -12
- 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.d.ts +1 -1
- package/graphqlFields/dynamicZone/dynamicZoneField.js +76 -26
- 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 +4 -1
- package/graphqlFields/number.js.map +1 -1
- package/graphqlFields/object.js +26 -46
- package/graphqlFields/object.js.map +1 -1
- package/graphqlFields/ref.js +35 -23
- 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 +5 -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 +3 -2
- package/index.js +33 -14
- 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 +36 -39
- 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 +8 -4
- package/plugins/CmsModelPlugin.js +61 -32
- 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.d.ts +23 -0
- package/plugins/StorageOperationsCmsModelPlugin.js +41 -0
- package/plugins/StorageOperationsCmsModelPlugin.js.map +1 -0
- 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 +2 -0
- package/plugins/index.js +25 -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 +437 -313
- package/types.js +20 -20
- package/types.js.map +1 -1
- package/utils/access.d.ts +9 -8
- package/utils/access.js +12 -62
- package/utils/access.js.map +1 -1
- 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.d.ts +1 -5
- package/utils/converters/valueKeyStorageConverter.js +32 -26
- package/utils/converters/valueKeyStorageConverter.js.map +1 -1
- package/utils/createTypeFromFields.js +8 -4
- package/utils/createTypeFromFields.js.map +1 -1
- package/utils/createTypeName.d.ts +0 -2
- package/utils/createTypeName.js +3 -9
- 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.d.ts +1 -3
- package/utils/getBaseFieldType.js +3 -1
- package/utils/getBaseFieldType.js.map +1 -1
- package/utils/getEntryDescription.d.ts +1 -1
- package/utils/getEntryDescription.js +3 -1
- package/utils/getEntryDescription.js.map +1 -1
- package/utils/getEntryImage.d.ts +1 -1
- package/utils/getEntryImage.js +3 -1
- package/utils/getEntryImage.js.map +1 -1
- package/utils/getEntryTitle.d.ts +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.d.ts +4 -0
- package/utils/permissions/EntriesPermissions.js +11 -0
- package/utils/permissions/EntriesPermissions.js.map +1 -0
- package/utils/permissions/ModelGroupsPermissions.d.ts +9 -0
- package/utils/permissions/ModelGroupsPermissions.js +50 -0
- package/utils/permissions/ModelGroupsPermissions.js.map +1 -0
- package/utils/permissions/ModelsPermissions.d.ts +22 -0
- package/utils/permissions/ModelsPermissions.js +90 -0
- package/utils/permissions/ModelsPermissions.js.map +1 -0
- package/utils/renderFields.d.ts +2 -1
- package/utils/renderFields.js +5 -2
- package/utils/renderFields.js.map +1 -1
- package/utils/renderGetFilterFields.d.ts +2 -2
- package/utils/renderGetFilterFields.js +9 -21
- package/utils/renderGetFilterFields.js.map +1 -1
- package/utils/renderInputFields.d.ts +2 -1
- package/utils/renderInputFields.js +17 -7
- package/utils/renderInputFields.js.map +1 -1
- package/utils/renderListFilterFields.d.ts +3 -1
- package/utils/renderListFilterFields.js +25 -22
- package/utils/renderListFilterFields.js.map +1 -1
- package/utils/renderSortEnum.d.ts +3 -2
- package/utils/renderSortEnum.js +10 -3
- 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/createFieldModels.d.ts +0 -2
- package/crud/contentModel/createFieldModels.js +0 -26
- package/crud/contentModel/createFieldModels.js.map +0 -1
- package/crud/contentModel/fieldIdValidation.d.ts +0 -1
- package/crud/contentModel/fieldIdValidation.js +0 -25
- package/crud/contentModel/fieldIdValidation.js.map +0 -1
- package/crud/contentModel/idValidation.d.ts +0 -1
- package/crud/contentModel/idValidation.js +0 -22
- package/crud/contentModel/idValidation.js.map +0 -1
- package/crud/contentModel/models.d.ts +0 -4
- package/crud/contentModel/models.js +0 -192
- package/crud/contentModel/models.js.map +0 -1
- package/crud/contentModel/systemFields.d.ts +0 -1
- package/crud/contentModel/systemFields.js +0 -8
- package/crud/contentModel/systemFields.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 -10
- package/crud/settings.crud.js +0 -66
- 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/upgrades/5.33.0/index.d.ts +0 -3
- package/upgrades/5.33.0/index.js +0 -182
- package/upgrades/5.33.0/index.js.map +0 -1
- package/upgrades/index.d.ts +0 -1
- package/upgrades/index.js +0 -12
- package/upgrades/index.js.map +0 -1
- package/utils/ownership.d.ts +0 -8
- package/utils/ownership.js +0 -33
- package/utils/ownership.js.map +0 -1
- package/utils/permissions.d.ts +0 -7
- package/utils/permissions.js +0 -91
- package/utils/permissions.js.map +0 -1
- package/utils/pluralizedTypeName.d.ts +0 -1
- package/utils/pluralizedTypeName.js +0 -26
- package/utils/pluralizedTypeName.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,108 +5,116 @@ 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
|
-
var _mdbid = _interopRequireDefault(require("mdbid"));
|
|
11
8
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
12
|
-
var _handlerGraphql = require("@webiny/handler-graphql");
|
|
13
9
|
var _CmsGroupPlugin = require("../plugins/CmsGroupPlugin");
|
|
14
10
|
var _pubsub = require("@webiny/pubsub");
|
|
15
11
|
var _beforeUpdate = require("./contentModelGroup/beforeUpdate");
|
|
16
12
|
var _beforeCreate = require("./contentModelGroup/beforeCreate");
|
|
17
13
|
var _beforeDelete = require("./contentModelGroup/beforeDelete");
|
|
18
|
-
var _permissions = require("../utils/permissions");
|
|
19
|
-
var _ownership = require("../utils/ownership");
|
|
20
|
-
var _access = require("../utils/access");
|
|
21
14
|
var _validation = require("./contentModelGroup/validation");
|
|
22
15
|
var _utils = require("@webiny/utils");
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
16
|
+
var _filterAsync = require("../utils/filterAsync");
|
|
17
|
+
var _utils2 = require("../utils");
|
|
18
|
+
var _listGroupsFromDatabase = require("./contentModelGroup/listGroupsFromDatabase");
|
|
19
|
+
var _handlerGraphql = require("@webiny/handler-graphql");
|
|
28
20
|
const createModelGroupsCrud = params => {
|
|
29
21
|
const {
|
|
30
22
|
getTenant,
|
|
31
23
|
getIdentity,
|
|
32
24
|
getLocale,
|
|
33
25
|
storageOperations,
|
|
26
|
+
modelGroupsPermissions,
|
|
34
27
|
context
|
|
35
28
|
} = params;
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
});
|
|
52
|
-
return [groups.concat(pluginsGroups)];
|
|
53
|
-
})
|
|
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
|
+
});
|
|
54
44
|
};
|
|
45
|
+
const listDatabaseGroupsCache = (0, _utils2.createMemoryCache)();
|
|
46
|
+
const listFilteredDatabaseGroupsCache = (0, _utils2.createMemoryCache)();
|
|
47
|
+
const listPluginGroupsCache = (0, _utils2.createMemoryCache)();
|
|
55
48
|
const clearGroupsCache = () => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
49
|
+
listPluginGroupsCache.clear();
|
|
50
|
+
listDatabaseGroupsCache.clear();
|
|
51
|
+
listFilteredDatabaseGroupsCache.clear();
|
|
59
52
|
};
|
|
60
|
-
const
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
|
|
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);
|
|
64
94
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
return true;
|
|
78
|
-
}).map(plugin => {
|
|
79
|
-
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,
|
|
80
106
|
tenant,
|
|
81
|
-
locale
|
|
82
|
-
webinyVersion: context.WEBINY_VERSION
|
|
107
|
+
locale
|
|
83
108
|
});
|
|
84
109
|
});
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
rwd: check
|
|
110
|
+
const filteredCacheKey = (0, _utils2.createCacheKey)({
|
|
111
|
+
dbCacheKey: cacheKey.get(),
|
|
112
|
+
identity: context.security.isAuthorizationEnabled() ? getIdentity()?.id : undefined
|
|
89
113
|
});
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if (!group) {
|
|
95
|
-
throw new _handlerGraphql.NotFoundError(`Cms Group "${id}" was not found!`);
|
|
96
|
-
}
|
|
97
|
-
return group;
|
|
98
|
-
};
|
|
99
|
-
const listGroupsViaDataLoader = async params => {
|
|
100
|
-
const {
|
|
101
|
-
where
|
|
102
|
-
} = params || {};
|
|
103
|
-
try {
|
|
104
|
-
return await dataLoaders.listGroups.load("listGroups");
|
|
105
|
-
} catch (ex) {
|
|
106
|
-
throw new _error.default(ex.message, ex.code || "LIST_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, ex.data || {}), {}, {
|
|
107
|
-
where
|
|
108
|
-
}));
|
|
109
|
-
}
|
|
114
|
+
const groups = await listFilteredDatabaseGroupsCache.getOrSet(filteredCacheKey, async () => {
|
|
115
|
+
return (0, _filterAsync.filterAsync)(databaseGroups, filterGroup);
|
|
116
|
+
});
|
|
117
|
+
return groups.concat(pluginGroups);
|
|
110
118
|
};
|
|
111
119
|
|
|
112
120
|
/**
|
|
@@ -149,10 +157,22 @@ const createModelGroupsCrud = params => {
|
|
|
149
157
|
* CRUD Methods
|
|
150
158
|
*/
|
|
151
159
|
const getGroup = async id => {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
160
|
+
await modelGroupsPermissions.ensure({
|
|
161
|
+
rwd: "r"
|
|
162
|
+
});
|
|
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
|
+
}
|
|
170
|
+
await modelGroupsPermissions.ensure({
|
|
171
|
+
owns: group.createdBy
|
|
172
|
+
});
|
|
173
|
+
await modelGroupsPermissions.ensureCanAccessGroup({
|
|
174
|
+
group
|
|
175
|
+
});
|
|
156
176
|
return group;
|
|
157
177
|
};
|
|
158
178
|
const listGroups = async params => {
|
|
@@ -163,30 +183,24 @@ const createModelGroupsCrud = params => {
|
|
|
163
183
|
tenant,
|
|
164
184
|
locale
|
|
165
185
|
} = where || {};
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
where: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, where || {}), {}, {
|
|
169
|
-
tenant: tenant || getTenant().id,
|
|
170
|
-
locale: locale || getLocale().code
|
|
171
|
-
})
|
|
172
|
-
}));
|
|
173
|
-
return response.filter(group => {
|
|
174
|
-
if (!(0, _ownership.validateOwnership)(context, permission, group)) {
|
|
175
|
-
return false;
|
|
176
|
-
}
|
|
177
|
-
return (0, _access.validateGroupAccess)(context, permission, group);
|
|
186
|
+
await modelGroupsPermissions.ensure({
|
|
187
|
+
rwd: "r"
|
|
178
188
|
});
|
|
189
|
+
return fetchGroups(tenant || getTenant().id, locale || getLocale().code);
|
|
179
190
|
};
|
|
180
191
|
const createGroup = async input => {
|
|
181
|
-
await
|
|
192
|
+
await modelGroupsPermissions.ensure({
|
|
193
|
+
rwd: "w"
|
|
194
|
+
});
|
|
182
195
|
const result = await (0, _validation.createGroupCreateValidation)().safeParseAsync(input);
|
|
183
196
|
if (!result.success) {
|
|
184
197
|
throw (0, _utils.createZodError)(result.error);
|
|
185
198
|
}
|
|
186
199
|
const data = result.data;
|
|
187
200
|
const identity = getIdentity();
|
|
188
|
-
const id = (0,
|
|
189
|
-
const group =
|
|
201
|
+
const id = data.id || (0, _utils.mdbid)();
|
|
202
|
+
const group = {
|
|
203
|
+
...data,
|
|
190
204
|
id,
|
|
191
205
|
tenant: getTenant().id,
|
|
192
206
|
locale: getLocale().code,
|
|
@@ -198,7 +212,7 @@ const createModelGroupsCrud = params => {
|
|
|
198
212
|
type: identity.type
|
|
199
213
|
},
|
|
200
214
|
webinyVersion: context.WEBINY_VERSION
|
|
201
|
-
}
|
|
215
|
+
};
|
|
202
216
|
try {
|
|
203
217
|
await onGroupBeforeCreate.publish({
|
|
204
218
|
group
|
|
@@ -217,16 +231,21 @@ const createModelGroupsCrud = params => {
|
|
|
217
231
|
group,
|
|
218
232
|
error: ex
|
|
219
233
|
});
|
|
220
|
-
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 || {}),
|
|
221
236
|
group,
|
|
222
237
|
input
|
|
223
|
-
})
|
|
238
|
+
});
|
|
224
239
|
}
|
|
225
240
|
};
|
|
226
241
|
const updateGroup = async (id, input) => {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
242
|
+
await modelGroupsPermissions.ensure({
|
|
243
|
+
rwd: "w"
|
|
244
|
+
});
|
|
245
|
+
const original = await getGroup(id);
|
|
246
|
+
await modelGroupsPermissions.ensure({
|
|
247
|
+
owns: original.createdBy
|
|
248
|
+
});
|
|
230
249
|
const result = await (0, _validation.createGroupUpdateValidation)().safeParseAsync(input);
|
|
231
250
|
if (!result.success) {
|
|
232
251
|
throw (0, _utils.createZodError)(result.error);
|
|
@@ -239,11 +258,13 @@ const createModelGroupsCrud = params => {
|
|
|
239
258
|
if (Object.keys(data).length === 0) {
|
|
240
259
|
return original;
|
|
241
260
|
}
|
|
242
|
-
const group =
|
|
261
|
+
const group = {
|
|
262
|
+
...original,
|
|
263
|
+
...data,
|
|
243
264
|
locale: getLocale().code,
|
|
244
265
|
tenant: getTenant().id,
|
|
245
266
|
savedOn: new Date().toISOString()
|
|
246
|
-
}
|
|
267
|
+
};
|
|
247
268
|
try {
|
|
248
269
|
await onGroupBeforeUpdate.publish({
|
|
249
270
|
original,
|
|
@@ -274,9 +295,13 @@ const createModelGroupsCrud = params => {
|
|
|
274
295
|
}
|
|
275
296
|
};
|
|
276
297
|
const deleteGroup = async id => {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
298
|
+
await modelGroupsPermissions.ensure({
|
|
299
|
+
rwd: "d"
|
|
300
|
+
});
|
|
301
|
+
const group = await getGroup(id);
|
|
302
|
+
await modelGroupsPermissions.ensure({
|
|
303
|
+
owns: group.createdBy
|
|
304
|
+
});
|
|
280
305
|
try {
|
|
281
306
|
await onGroupBeforeDelete.publish({
|
|
282
307
|
group
|
|
@@ -293,25 +318,14 @@ const createModelGroupsCrud = params => {
|
|
|
293
318
|
group,
|
|
294
319
|
error: ex
|
|
295
320
|
});
|
|
296
|
-
throw new _error.default(ex.message, ex.code || "DELETE_ERROR",
|
|
321
|
+
throw new _error.default(ex.message, ex.code || "DELETE_ERROR", {
|
|
322
|
+
...(ex.data || {}),
|
|
297
323
|
id
|
|
298
|
-
})
|
|
324
|
+
});
|
|
299
325
|
}
|
|
300
326
|
return true;
|
|
301
327
|
};
|
|
302
328
|
return {
|
|
303
|
-
/**
|
|
304
|
-
* Deprecated - will be removed in 5.36.0
|
|
305
|
-
*/
|
|
306
|
-
onBeforeGroupCreate: onGroupBeforeCreate,
|
|
307
|
-
onAfterGroupCreate: onGroupAfterCreate,
|
|
308
|
-
onBeforeGroupUpdate: onGroupBeforeUpdate,
|
|
309
|
-
onAfterGroupUpdate: onGroupAfterUpdate,
|
|
310
|
-
onBeforeGroupDelete: onGroupBeforeDelete,
|
|
311
|
-
onAfterGroupDelete: onGroupAfterDelete,
|
|
312
|
-
/**
|
|
313
|
-
* Released in 5.34.0
|
|
314
|
-
*/
|
|
315
329
|
onGroupBeforeCreate,
|
|
316
330
|
onGroupAfterCreate,
|
|
317
331
|
onGroupCreateError,
|
|
@@ -349,4 +363,6 @@ const createModelGroupsCrud = params => {
|
|
|
349
363
|
}
|
|
350
364
|
};
|
|
351
365
|
};
|
|
352
|
-
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","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","checkPermissions","check","baseCheckPermissions","rwd","getGroupViaDataLoader","load","find","g","NotFoundError","listGroupsViaDataLoader","ex","WebinyError","message","data","onGroupBeforeCreate","createTopic","onGroupAfterCreate","onGroupCreateError","onGroupBeforeUpdate","onGroupAfterUpdate","onGroupUpdateError","onGroupBeforeDelete","onGroupAfterDelete","onGroupDeleteError","assignBeforeGroupCreate","assignBeforeGroupUpdate","assignBeforeGroupDelete","getGroup","permission","checkOwnership","validateGroupAccess","response","validateOwnership","createGroup","input","result","createGroupCreateValidation","safeParseAsync","success","createZodError","error","identity","mdbid","createdOn","Date","toISOString","savedOn","createdBy","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\";\n/**\n * Package mdbid does not have types.\n */\n// @ts-ignore\nimport mdbid from \"mdbid\";\nimport WebinyError from \"@webiny/error\";\nimport {\n CmsGroupContext,\n CmsGroupListParams,\n CmsGroupPermission,\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 { checkPermissions as baseCheckPermissions } from \"~/utils/permissions\";\nimport { checkOwnership, validateOwnership } from \"~/utils/ownership\";\nimport { validateGroupAccess } from \"~/utils/access\";\nimport {\n createGroupCreateValidation,\n createGroupUpdateValidation\n} from \"~/crud/contentModelGroup/validation\";\nimport { createZodError } from \"@webiny/utils\";\n\nexport interface CreateModelGroupsCrudParams {\n getTenant: () => Tenant;\n getLocale: () => I18NLocale;\n storageOperations: HeadlessCmsStorageOperations;\n context: CmsContext;\n getIdentity: () => SecurityIdentity;\n}\n\nexport const createModelGroupsCrud = (params: CreateModelGroupsCrudParams): CmsGroupContext => {\n const { getTenant, getIdentity, getLocale, storageOperations, context } = 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 checkPermissions = (check: string): Promise<CmsGroupPermission> => {\n return baseCheckPermissions(context, \"cms.contentModelGroup\", { rwd: check });\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 const permission = await checkPermissions(\"r\");\n\n const group = await getGroupViaDataLoader(id);\n checkOwnership(context, permission, group);\n validateGroupAccess(context, permission, group);\n\n return group;\n };\n const listGroups: CmsGroupContext[\"listGroups\"] = async params => {\n const { where } = params || {};\n\n const { tenant, locale } = where || {};\n const permission = await checkPermissions(\"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 response.filter(group => {\n if (!validateOwnership(context, permission, group)) {\n return false;\n }\n return validateGroupAccess(context, permission, group);\n });\n };\n const createGroup: CmsGroupContext[\"createGroup\"] = async input => {\n await checkPermissions(\"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 const permission = await checkPermissions(\"w\");\n\n const original = await getGroupViaDataLoader(id);\n\n checkOwnership(context, permission, original);\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 const permission = await checkPermissions(\"d\");\n\n const group = await getGroupViaDataLoader(id);\n\n checkOwnership(context, permission, group);\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;AAKA;AACA;AAkBA;AACA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAIA;AAvCA;AACA;AACA;AACA;;AA8CO,MAAMA,qBAAqB,GAAIC,MAAmC,IAAsB;EAC3F,MAAM;IAAEC,SAAS;IAAEC,WAAW;IAAEC,SAAS;IAAEC,iBAAiB;IAAEC;EAAQ,CAAC,GAAGL,MAAM;EAEhF,MAAMM,WAAW,GAAG;IAChBC,UAAU,EAAE,IAAIC,mBAAU,CAAC,YAAY;MACnC,MAA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AAkB;IAClBC,kBAAkB;IAClBC,mBAAmB;IACnBC,kBAAkB;IAClBC,kBAAkB;IAClBC,mBAAmB;IACnBC,kBAAkB;IAClBC,kBAAkB;IAClBvC,gBAAgB;IAChB2C,QAAQ,EAAE,MAAMtD,EAAE,IAAI;MAClB,OAAOL,OAAO,CAACkG,SAAS,CAACC,OAAO,CAAC,kCAAkC,EAAE,YAAY;QAC7E,OAAOxC,QAAQ,CAACtD,EAAE,CAAC;MACvB,CAAC,CAAC;IACN,CAAC;IACDH,UAAU,EAAE,MAAMP,MAAM,IAAI;MACxB,OAAOK,OAAO,CAACkG,SAAS,CAACC,OAAO,CAAC,oCAAoC,EAAE,YAAY;QAC/E,OAAOjG,UAAU,CAACP,MAAM,CAAC;MAC7B,CAAC,CAAC;IACN,CAAC;IACDsE,WAAW,EAAE,MAAMC,KAAK,IAAI;MACxB,OAAOlE,OAAO,CAACkG,SAAS,CAACC,OAAO,CAAC,qCAAqC,EAAE,YAAY;QAChF,OAAOlC,WAAW,CAACC,KAAK,CAAC;MAC7B,CAAC,CAAC;IACN,CAAC;IACDiB,WAAW,EAAE,OAAO9E,EAAE,EAAE6D,KAAK,KAAK;MAC9B,OAAOlE,OAAO,CAACkG,SAAS,CAACC,OAAO,CAAC,qCAAqC,EAAE,YAAY;QAChF,OAAOhB,WAAW,CAAC9E,EAAE,EAAE6D,KAAK,CAAC;MACjC,CAAC,CAAC;IACN,CAAC;IACDwB,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,IAA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,CAAC,kCAAkC,EAAE,YAAY;QAC7E,OAAOvC,QAAQ,CAACpC,EAAE,CAAC;MACvB,CAAC,CAAC;IACN,CAAC;IACD2C,UAAU,EAAE,MAAM7E,MAAM,IAAI;MACxB,OAAOM,OAAO,CAACsG,SAAS,CAACC,OAAO,CAAC,oCAAoC,EAAE,YAAY;QAC/E,OAAOhC,UAAU,CAAC7E,MAAM,CAAC;MAC7B,CAAC,CAAC;IACN,CAAC;IACD+E,WAAW,EAAE,MAAMC,KAAK,IAAI;MACxB,OAAO1E,OAAO,CAACsG,SAAS,CAACC,OAAO,CAAC,qCAAqC,EAAE,YAAY;QAChF,OAAO9B,WAAW,CAACC,KAAK,CAAC;MAC7B,CAAC,CAAC;IACN,CAAC;IACDkB,WAAW,EAAE,MAAAA,CAAOhE,EAAE,EAAE8C,KAAK,KAAK;MAC9B,OAAO1E,OAAO,CAACsG,SAAS,CAACC,OAAO,CAAC,qCAAqC,EAAE,YAAY;QAChF,OAAOX,WAAW,CAAChE,EAAE,EAAE8C,KAAK,CAAC;MACjC,CAAC,CAAC;IACN,CAAC;IACD0B,WAAW,EAAE,MAAMxE,EAAE,IAAI;MACrB,OAAO5B,OAAO,CAACsG,SAAS,CAACC,OAAO,CAAC,qCAAqC,EAAE,YAAY;QAChF,OAAOH,WAAW,CAACxE,EAAE,CAAC;MAC1B,CAAC,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,GAA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,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
|