@webiny/api-headless-cms 6.4.12-beta.5 → 6.5.0-beta.1
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/crud/contentEntry/entryDataValidation.d.ts +1 -1
- package/crud/contentEntry/entryDataValidation.js +33 -18
- package/crud/contentEntry/entryDataValidation.js.map +1 -1
- package/crud/contentEntry.crud.js +12 -39
- package/crud/contentEntry.crud.js.map +1 -1
- package/crud/contentModel/defaultFields.js +3 -2
- package/crud/contentModel/defaultFields.js.map +1 -1
- package/crud/contentModel/validate/endingAllowed.js +1 -1
- package/crud/contentModel/validate/endingAllowed.js.map +1 -1
- package/crud/contentModel/validate/pluralApiName.js +1 -1
- package/crud/contentModel/validate/pluralApiName.js.map +1 -1
- package/crud/contentModel/validate/singularApiName.js +1 -1
- package/crud/contentModel/validate/singularApiName.js.map +1 -1
- package/crud/contentModel/validation.js +2 -2
- package/crud/contentModel/validation.js.map +1 -1
- package/domain/contentModel/schemas.d.ts +4 -0
- package/domain/contentModel/schemas.js +5 -2
- package/domain/contentModel/schemas.js.map +1 -1
- package/domain/contentModel/validation/endingAllowed.js +1 -1
- package/domain/contentModel/validation/endingAllowed.js.map +1 -1
- package/domain/contentModel/validation/pluralApiName.js +1 -1
- package/domain/contentModel/validation/pluralApiName.js.map +1 -1
- package/domain/contentModel/validation/singularApiName.js +1 -1
- package/domain/contentModel/validation/singularApiName.js.map +1 -1
- package/export/crud/exporting.js +2 -2
- package/export/crud/exporting.js.map +1 -1
- package/export/crud/imports/importGroups.js +2 -1
- package/export/crud/imports/importGroups.js.map +1 -1
- package/export/crud/imports/validateModels.js +1 -1
- package/export/crud/imports/validateModels.js.map +1 -1
- package/exports/api/cms/model.d.ts +4 -1
- package/exports/api/cms/model.js +2 -0
- package/extension.d.ts +3 -0
- package/extension.js +19 -0
- package/extension.js.map +1 -0
- package/features/contentEntry/ContentEntriesFeature.js +2 -0
- package/features/contentEntry/ContentEntriesFeature.js.map +1 -1
- package/features/contentEntry/CreateEntry/CreateEntryUseCase.js +1 -2
- package/features/contentEntry/CreateEntry/CreateEntryUseCase.js.map +1 -1
- package/features/contentEntry/CreateEntryRevisionFrom/CreateEntryRevisionFromUseCase.d.ts +1 -3
- package/features/contentEntry/CreateEntryRevisionFrom/CreateEntryRevisionFromUseCase.js +4 -12
- package/features/contentEntry/CreateEntryRevisionFrom/CreateEntryRevisionFromUseCase.js.map +1 -1
- package/features/contentEntry/CreateEntryRevisionFrom/abstractions.d.ts +2 -0
- package/features/contentEntry/CreateEntryRevisionFrom/abstractions.js.map +1 -1
- package/features/contentEntry/DeleteEntryRevision/DeleteEntryRevisionRepository.js +1 -0
- package/features/contentEntry/DeleteEntryRevision/DeleteEntryRevisionRepository.js.map +1 -1
- package/features/contentEntry/GetSingletonEntry/GetSingletonEntryUseCase.js +1 -3
- package/features/contentEntry/GetSingletonEntry/GetSingletonEntryUseCase.js.map +1 -1
- package/features/contentEntry/PublishEntry/PublishEntryUseCase.d.ts +1 -3
- package/features/contentEntry/PublishEntry/PublishEntryUseCase.js +4 -10
- package/features/contentEntry/PublishEntry/PublishEntryUseCase.js.map +1 -1
- package/features/contentEntry/RepublishEntry/RepublishEntryUseCase.js +3 -1
- package/features/contentEntry/RepublishEntry/RepublishEntryUseCase.js.map +1 -1
- package/features/contentEntry/UnpublishEntry/UnpublishEntryUseCase.js +3 -1
- package/features/contentEntry/UnpublishEntry/UnpublishEntryUseCase.js.map +1 -1
- package/features/contentEntry/UpdateEntry/UpdateEntryUseCase.js +3 -1
- package/features/contentEntry/UpdateEntry/UpdateEntryUseCase.js.map +1 -1
- package/features/contentEntry/UpdateRevision/UpdateRevisionRepository.d.ts +14 -0
- package/features/contentEntry/UpdateRevision/UpdateRevisionRepository.js +34 -0
- package/features/contentEntry/UpdateRevision/UpdateRevisionRepository.js.map +1 -0
- package/features/contentEntry/UpdateRevision/abstractions.d.ts +10 -0
- package/features/contentEntry/UpdateRevision/abstractions.js +5 -0
- package/features/contentEntry/UpdateRevision/abstractions.js.map +1 -0
- package/features/contentEntry/UpdateRevision/feature.d.ts +4 -0
- package/features/contentEntry/UpdateRevision/feature.js +11 -0
- package/features/contentEntry/UpdateRevision/feature.js.map +1 -0
- package/features/contentEntry/UpdateRevision/index.d.ts +1 -0
- package/features/contentEntry/UpdateRevision/index.js +1 -0
- package/features/contentEntry/UpdateRevisionDescription/UpdateRevisionDescriptionUseCase.d.ts +2 -2
- package/features/contentEntry/UpdateRevisionDescription/UpdateRevisionDescriptionUseCase.js +2 -2
- package/features/contentEntry/UpdateRevisionDescription/UpdateRevisionDescriptionUseCase.js.map +1 -1
- package/features/contentEntry/ensureItemIds.d.ts +13 -0
- package/features/contentEntry/ensureItemIds.js +22 -0
- package/features/contentEntry/ensureItemIds.js.map +1 -0
- package/features/contentEntry/entryDataFactories/CreateEntryDataFactory/CreateEntryDataFactory.d.ts +3 -1
- package/features/contentEntry/entryDataFactories/CreateEntryDataFactory/CreateEntryDataFactory.js +9 -3
- package/features/contentEntry/entryDataFactories/CreateEntryDataFactory/CreateEntryDataFactory.js.map +1 -1
- package/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.d.ts +7 -5
- package/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.js +48 -18
- package/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.js.map +1 -1
- package/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/abstractions.d.ts +17 -1
- package/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/abstractions.js.map +1 -1
- package/features/contentEntry/entryDataFactories/CreatePublishEntryDataFactory/CreatePublishEntryDataFactory.d.ts +5 -3
- package/features/contentEntry/entryDataFactories/CreatePublishEntryDataFactory/CreatePublishEntryDataFactory.js +22 -16
- package/features/contentEntry/entryDataFactories/CreatePublishEntryDataFactory/CreatePublishEntryDataFactory.js.map +1 -1
- package/features/contentEntry/entryDataFactories/CreatePublishEntryDataFactory/abstractions.d.ts +15 -1
- package/features/contentEntry/entryDataFactories/CreatePublishEntryDataFactory/abstractions.js.map +1 -1
- package/features/contentEntry/entryDataFactories/CreateRepublishEntryDataFactory/CreateRepublishEntryDataFactory.d.ts +5 -3
- package/features/contentEntry/entryDataFactories/CreateRepublishEntryDataFactory/CreateRepublishEntryDataFactory.js +17 -13
- package/features/contentEntry/entryDataFactories/CreateRepublishEntryDataFactory/CreateRepublishEntryDataFactory.js.map +1 -1
- package/features/contentEntry/entryDataFactories/CreateRepublishEntryDataFactory/abstractions.d.ts +13 -1
- package/features/contentEntry/entryDataFactories/CreateRepublishEntryDataFactory/abstractions.js.map +1 -1
- package/features/contentEntry/entryDataFactories/CreateUnpublishEntryDataFactory/CreateUnpublishEntryDataFactory.d.ts +6 -6
- package/features/contentEntry/entryDataFactories/CreateUnpublishEntryDataFactory/CreateUnpublishEntryDataFactory.js +17 -18
- package/features/contentEntry/entryDataFactories/CreateUnpublishEntryDataFactory/CreateUnpublishEntryDataFactory.js.map +1 -1
- package/features/contentEntry/entryDataFactories/CreateUnpublishEntryDataFactory/abstractions.d.ts +14 -2
- package/features/contentEntry/entryDataFactories/CreateUnpublishEntryDataFactory/abstractions.js.map +1 -1
- package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.d.ts +7 -3
- package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.js +73 -30
- package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.js.map +1 -1
- package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/abstractions.d.ts +15 -1
- package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/abstractions.js.map +1 -1
- package/features/contentEntry/entryDataFactories/expiresAt.js +2 -2
- package/features/contentEntry/entryDataFactories/expiresAt.js.map +1 -1
- package/features/contentEntry/entryDataFactories/hasEntryContentChanged.d.ts +24 -0
- package/features/contentEntry/entryDataFactories/hasEntryContentChanged.js +13 -0
- package/features/contentEntry/entryDataFactories/hasEntryContentChanged.js.map +1 -0
- package/features/contentModel/ComponentMapGenerator/ComponentMapGenerator.d.ts +14 -0
- package/features/contentModel/ComponentMapGenerator/ComponentMapGenerator.js +32 -0
- package/features/contentModel/ComponentMapGenerator/ComponentMapGenerator.js.map +1 -0
- package/features/contentModel/ComponentMapGenerator/abstractions.d.ts +8 -0
- package/features/contentModel/ComponentMapGenerator/abstractions.js +5 -0
- package/features/contentModel/ComponentMapGenerator/abstractions.js.map +1 -0
- package/features/contentModel/ComponentMapGenerator/feature.d.ts +4 -0
- package/features/contentModel/ComponentMapGenerator/feature.js +11 -0
- package/features/contentModel/ComponentMapGenerator/feature.js.map +1 -0
- package/features/contentModel/ComponentMapGenerator/index.d.ts +2 -0
- package/features/contentModel/ComponentMapGenerator/index.js +2 -0
- package/features/contentModel/ContentModelFeature.js +6 -0
- package/features/contentModel/ContentModelFeature.js.map +1 -1
- package/features/contentModel/CreateModel/CreateModelRepository.js +2 -1
- package/features/contentModel/CreateModel/CreateModelRepository.js.map +1 -1
- package/features/contentModel/CreateModelFrom/CreateModelFromRepository.js +2 -1
- package/features/contentModel/CreateModelFrom/CreateModelFromRepository.js.map +1 -1
- package/features/contentModel/RefModelsGenerator/RefModelsGenerator.d.ts +19 -0
- package/features/contentModel/RefModelsGenerator/RefModelsGenerator.js +56 -0
- package/features/contentModel/RefModelsGenerator/RefModelsGenerator.js.map +1 -0
- package/features/contentModel/RefModelsGenerator/abstractions.d.ts +11 -0
- package/features/contentModel/RefModelsGenerator/abstractions.js +5 -0
- package/features/contentModel/RefModelsGenerator/abstractions.js.map +1 -0
- package/features/contentModel/RefModelsGenerator/feature.d.ts +4 -0
- package/features/contentModel/RefModelsGenerator/feature.js +11 -0
- package/features/contentModel/RefModelsGenerator/feature.js.map +1 -0
- package/features/contentModel/RefModelsGenerator/index.d.ts +2 -0
- package/features/contentModel/RefModelsGenerator/index.js +2 -0
- package/features/contentModel/ValuesSelectionGenerator/ValuesSelectionGenerator.d.ts +16 -0
- package/features/contentModel/ValuesSelectionGenerator/ValuesSelectionGenerator.js +54 -0
- package/features/contentModel/ValuesSelectionGenerator/ValuesSelectionGenerator.js.map +1 -0
- package/features/contentModel/ValuesSelectionGenerator/abstractions.d.ts +8 -0
- package/features/contentModel/ValuesSelectionGenerator/abstractions.js +5 -0
- package/features/contentModel/ValuesSelectionGenerator/abstractions.js.map +1 -0
- package/features/contentModel/ValuesSelectionGenerator/feature.d.ts +4 -0
- package/features/contentModel/ValuesSelectionGenerator/feature.js +11 -0
- package/features/contentModel/ValuesSelectionGenerator/feature.js.map +1 -0
- package/features/contentModel/ValuesSelectionGenerator/index.d.ts +1 -0
- package/features/contentModel/ValuesSelectionGenerator/index.js +1 -0
- package/features/graphql/feature.js +2 -0
- package/features/graphql/feature.js.map +1 -1
- package/features/graphql/fields/base/AssetToGraphQL.d.ts +26 -0
- package/features/graphql/fields/base/AssetToGraphQL.js +153 -0
- package/features/graphql/fields/base/AssetToGraphQL.js.map +1 -0
- package/features/graphql/fields/base/DynamicZoneToGraphQL.js +12 -2
- package/features/graphql/fields/base/DynamicZoneToGraphQL.js.map +1 -1
- package/features/graphql/fields/base/ObjectToGraphQL.js +8 -5
- package/features/graphql/fields/base/ObjectToGraphQL.js.map +1 -1
- package/features/modelBuilder/abstractions.d.ts +9 -0
- package/features/modelBuilder/abstractions.js.map +1 -1
- package/features/modelBuilder/feature.js +2 -0
- package/features/modelBuilder/feature.js.map +1 -1
- package/features/modelBuilder/fields/AssetFieldType.d.ts +20 -0
- package/features/modelBuilder/fields/AssetFieldType.js +46 -0
- package/features/modelBuilder/fields/AssetFieldType.js.map +1 -0
- package/features/modelBuilder/fields/DataFieldBuilder.d.ts +62 -18
- package/features/modelBuilder/fields/DataFieldBuilder.js +8 -0
- package/features/modelBuilder/fields/DataFieldBuilder.js.map +1 -1
- package/features/modelBuilder/fields/DynamicZoneFieldType.d.ts +1 -0
- package/features/modelBuilder/fields/DynamicZoneFieldType.js +2 -6
- package/features/modelBuilder/fields/DynamicZoneFieldType.js.map +1 -1
- package/features/modelBuilder/fields/resolveAssetUrl.d.ts +35 -0
- package/features/modelBuilder/fields/resolveAssetUrl.js +26 -0
- package/features/modelBuilder/fields/resolveAssetUrl.js.map +1 -0
- package/features/modelBuilder/index.d.ts +1 -1
- package/features/modelBuilder/models/BaseModelBuilder.d.ts +3 -1
- package/features/modelBuilder/models/BaseModelBuilder.js +7 -0
- package/features/modelBuilder/models/BaseModelBuilder.js.map +1 -1
- package/features/modelBuilder/models/PrivateModelBuilder.js +2 -1
- package/features/modelBuilder/models/PrivateModelBuilder.js.map +1 -1
- package/features/modelBuilder/models/PublicModelBuilder.js +2 -1
- package/features/modelBuilder/models/PublicModelBuilder.js.map +1 -1
- package/features/sortMapper/SortMapper.js +2 -5
- package/features/sortMapper/SortMapper.js.map +1 -1
- package/features/storage/fields/CompressedTextStorageTransform.js +1 -1
- package/features/storage/fields/CompressedTextStorageTransform.js.map +1 -1
- package/features/storage/fields/DateStorageTransform.js +4 -3
- package/features/storage/fields/DateStorageTransform.js.map +1 -1
- package/features/storage/fields/DynamicZoneStorageTransform.js +2 -2
- package/features/storage/fields/DynamicZoneStorageTransform.js.map +1 -1
- package/features/storage/fields/JsonStorageTransform.js +1 -1
- package/features/storage/fields/JsonStorageTransform.js.map +1 -1
- package/features/storage/fields/LongTextStorageTransform.js +1 -1
- package/features/storage/fields/LongTextStorageTransform.js.map +1 -1
- package/features/storage/fields/ObjectStorageTransform.js +27 -7
- package/features/storage/fields/ObjectStorageTransform.js.map +1 -1
- package/features/storage/fields/RichTextStorageTransform.js +1 -1
- package/features/storage/fields/RichTextStorageTransform.js.map +1 -1
- package/features/validation/validators/DateGteValidator.js +1 -1
- package/features/validation/validators/DateGteValidator.js.map +1 -1
- package/features/validation/validators/DateLteValidator.js +1 -1
- package/features/validation/validators/DateLteValidator.js.map +1 -1
- package/features/validation/validators/PatternValidator.js +1 -1
- package/features/validation/validators/PatternValidator.js.map +1 -1
- package/features/whereMapper/WhereMapper.js +10 -7
- package/features/whereMapper/WhereMapper.js.map +1 -1
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js +8 -2
- package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js.map +1 -1
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js +8 -2
- package/fieldConverters/CmsModelObjectFieldConverterPlugin.js.map +1 -1
- package/fieldConverters/index.d.ts +1 -1
- package/graphql/getSchema/generateCacheKey.js +1 -1
- package/graphql/getSchema/generateCacheKey.js.map +1 -1
- package/graphql/scalars/RevisionId.js +1 -1
- package/graphql/scalars/RevisionId.js.map +1 -1
- package/graphql/schema/baseSchema.js +5 -25
- package/graphql/schema/baseSchema.js.map +1 -1
- package/graphql/schema/cms/getEntryResolver.js +3 -2
- package/graphql/schema/cms/getEntryResolver.js.map +1 -1
- package/graphql/schema/cms/getModelResolver.d.ts +35 -0
- package/graphql/schema/cms/getModelResolver.js +49 -0
- package/graphql/schema/cms/getModelResolver.js.map +1 -0
- package/graphql/schema/cms/helpers/buildFieldsSelection.js +9 -2
- package/graphql/schema/cms/helpers/buildFieldsSelection.js.map +1 -1
- package/graphql/schema/cms/helpers/expandFieldWildcards.d.ts +2 -0
- package/graphql/schema/cms/helpers/expandFieldWildcards.js +13 -0
- package/graphql/schema/cms/helpers/expandFieldWildcards.js.map +1 -0
- package/graphql/schema/cms/helpers/index.d.ts +1 -0
- package/graphql/schema/cms/helpers/index.js +1 -0
- package/graphql/schema/cms/helpers.d.ts +1 -0
- package/graphql/schema/cms/helpers.js +1 -0
- package/graphql/schema/cms/index.js +2 -1
- package/graphql/schema/cms/index.js.map +1 -1
- package/graphql/schema/cms/listEntriesResolver.js +3 -2
- package/graphql/schema/cms/listEntriesResolver.js.map +1 -1
- package/graphql/schema/cms/resolvers/getModel.d.ts +8 -0
- package/graphql/schema/cms/resolvers/getModel.js +18 -0
- package/graphql/schema/cms/resolvers/getModel.js.map +1 -0
- package/graphql/schema/cms/resolvers/index.d.ts +1 -0
- package/graphql/schema/cms/resolvers/index.js +1 -0
- package/graphql/schema/cms/typeDefs/query.js +1 -0
- package/graphql/schema/cms/typeDefs/query.js.map +1 -1
- package/graphql/schema/cms/typeDefs/responses.js +5 -0
- package/graphql/schema/cms/typeDefs/responses.js.map +1 -1
- package/graphql/schema/contentModels.js +40 -1
- package/graphql/schema/contentModels.js.map +1 -1
- package/graphql/schema/createFieldResolvers.js +1 -1
- package/graphql/schema/createFieldResolvers.js.map +1 -1
- package/index.d.ts +2 -5
- package/index.js +1 -21
- package/package.json +27 -30
- package/plugins/CmsModelPlugin.js +12 -10
- package/plugins/CmsModelPlugin.js.map +1 -1
- package/types/fields/dynamicZoneField.d.ts +1 -0
- package/types/model.d.ts +6 -0
- package/types/modelField.d.ts +13 -0
- package/types/types.d.ts +8 -4
- package/types/types.js.map +1 -1
- package/utils/caching/Cache.js +1 -1
- package/utils/caching/Cache.js.map +1 -1
- package/utils/contentModelToJsonSchema/CmsModelToJsonSchemaConverter.d.ts +28 -0
- package/utils/contentModelToJsonSchema/CmsModelToJsonSchemaConverter.js +324 -0
- package/utils/contentModelToJsonSchema/CmsModelToJsonSchemaConverter.js.map +1 -0
- package/utils/contentModelToJsonSchema/index.d.ts +2 -0
- package/utils/contentModelToJsonSchema/index.js +1 -0
- package/utils/contentModelToJsonSchema/types.d.ts +24 -0
- package/utils/contentModelToJsonSchema/types.js +0 -0
- package/utils/createModelField.js +2 -1
- package/utils/createModelField.js.map +1 -1
- package/utils/date.js +1 -1
- package/utils/date.js.map +1 -1
- package/utils/entryStorage.js +1 -1
- package/utils/entryStorage.js.map +1 -1
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/renderFields.js +1 -1
- package/utils/renderFields.js.map +1 -1
- package/index.js.map +0 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { UpdateRevisionRepository } from "./UpdateRevisionRepository.js";
|
|
3
|
+
const UpdateRevisionFeature = createFeature({
|
|
4
|
+
name: "UpdateRevision",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(UpdateRevisionRepository);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { UpdateRevisionFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/contentEntry/UpdateRevision/feature.js","sources":["../../../../src/features/contentEntry/UpdateRevision/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { UpdateRevisionRepository } from \"./UpdateRevisionRepository.js\";\n\nexport const UpdateRevisionFeature = createFeature({\n name: \"UpdateRevision\",\n register(container) {\n container.register(UpdateRevisionRepository);\n }\n});\n"],"names":["UpdateRevisionFeature","createFeature","container","UpdateRevisionRepository"],"mappings":";;AAGO,MAAMA,wBAAwBC,cAAc;IAC/C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { UpdateRevisionRepository } from "./abstractions.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { UpdateRevisionRepository } from "./abstractions.js";
|
package/features/contentEntry/UpdateRevisionDescription/UpdateRevisionDescriptionUseCase.d.ts
CHANGED
|
@@ -3,14 +3,14 @@ import { UpdateRevisionDescriptionUseCase as UseCaseAbstraction } from "./abstra
|
|
|
3
3
|
import { EventPublisher } from "@webiny/api-core/features/eventPublisher/index.js";
|
|
4
4
|
import { AccessControl } from "../../../features/shared/abstractions.js";
|
|
5
5
|
import { GetRevisionByIdUseCase } from "../../../features/contentEntry/GetRevisionById/abstractions.js";
|
|
6
|
+
import { UpdateRevisionRepository } from "../../../features/contentEntry/UpdateRevision/abstractions.js";
|
|
6
7
|
import type { CmsEntry, CmsEntryValues, CmsModel } from "../../../types/index.js";
|
|
7
|
-
import { UpdateEntryRepository } from "../UpdateEntry/index.js";
|
|
8
8
|
declare class UpdateRevisionDescriptionUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
9
9
|
private eventPublisher;
|
|
10
10
|
private repository;
|
|
11
11
|
private accessControl;
|
|
12
12
|
private getRevisionByIdUseCase;
|
|
13
|
-
constructor(eventPublisher: EventPublisher.Interface, repository:
|
|
13
|
+
constructor(eventPublisher: EventPublisher.Interface, repository: UpdateRevisionRepository.Interface, accessControl: AccessControl.Interface, getRevisionByIdUseCase: GetRevisionByIdUseCase.Interface);
|
|
14
14
|
execute<T extends CmsEntryValues = CmsEntryValues>(model: CmsModel, id: string, revisionDescription: string | undefined): Promise<Result<CmsEntry<T>, UseCaseAbstraction.Error>>;
|
|
15
15
|
}
|
|
16
16
|
export declare const UpdateRevisionDescriptionUseCase: import("@webiny/di").Implementation<typeof UpdateRevisionDescriptionUseCaseImpl>;
|
|
@@ -4,8 +4,8 @@ import { EventPublisher } from "@webiny/api-core/features/eventPublisher/index.j
|
|
|
4
4
|
import { EntryAfterUpdateRevisionDescriptionEvent, EntryBeforeUpdateRevisionDescriptionEvent } from "./events.js";
|
|
5
5
|
import { AccessControl } from "../../shared/abstractions.js";
|
|
6
6
|
import { GetRevisionByIdUseCase } from "../GetRevisionById/abstractions.js";
|
|
7
|
+
import { UpdateRevisionRepository } from "../UpdateRevision/abstractions.js";
|
|
7
8
|
import { EntryNotAuthorizedError } from "../../../domain/contentEntry/errors.js";
|
|
8
|
-
import { UpdateEntryRepository } from "../UpdateEntry/index.js";
|
|
9
9
|
class UpdateRevisionDescriptionUseCaseImpl {
|
|
10
10
|
constructor(eventPublisher, repository, accessControl, getRevisionByIdUseCase){
|
|
11
11
|
this.eventPublisher = eventPublisher;
|
|
@@ -58,7 +58,7 @@ const UpdateRevisionDescriptionUseCase_UpdateRevisionDescriptionUseCase = create
|
|
|
58
58
|
implementation: UpdateRevisionDescriptionUseCaseImpl,
|
|
59
59
|
dependencies: [
|
|
60
60
|
EventPublisher,
|
|
61
|
-
|
|
61
|
+
UpdateRevisionRepository,
|
|
62
62
|
AccessControl,
|
|
63
63
|
GetRevisionByIdUseCase
|
|
64
64
|
]
|
package/features/contentEntry/UpdateRevisionDescription/UpdateRevisionDescriptionUseCase.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentEntry/UpdateRevisionDescription/UpdateRevisionDescriptionUseCase.js","sources":["../../../../src/features/contentEntry/UpdateRevisionDescription/UpdateRevisionDescriptionUseCase.ts"],"sourcesContent":["import { createImplementation, Result } from \"@webiny/feature/api\";\nimport { UpdateRevisionDescriptionUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport {\n EntryAfterUpdateRevisionDescriptionEvent,\n EntryBeforeUpdateRevisionDescriptionEvent\n} from \"./events.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport { GetRevisionByIdUseCase } from \"~/features/contentEntry/GetRevisionById/abstractions.js\";\nimport
|
|
1
|
+
{"version":3,"file":"features/contentEntry/UpdateRevisionDescription/UpdateRevisionDescriptionUseCase.js","sources":["../../../../src/features/contentEntry/UpdateRevisionDescription/UpdateRevisionDescriptionUseCase.ts"],"sourcesContent":["import { createImplementation, Result } from \"@webiny/feature/api\";\nimport { UpdateRevisionDescriptionUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport {\n EntryAfterUpdateRevisionDescriptionEvent,\n EntryBeforeUpdateRevisionDescriptionEvent\n} from \"./events.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport { GetRevisionByIdUseCase } from \"~/features/contentEntry/GetRevisionById/abstractions.js\";\nimport { UpdateRevisionRepository } from \"~/features/contentEntry/UpdateRevision/abstractions.js\";\nimport type { CmsEntry, CmsEntryValues, CmsModel } from \"~/types/index.js\";\nimport { EntryNotAuthorizedError } from \"~/domain/contentEntry/errors.js\";\n\nclass UpdateRevisionDescriptionUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private eventPublisher: EventPublisher.Interface,\n private repository: UpdateRevisionRepository.Interface,\n private accessControl: AccessControl.Interface,\n private getRevisionByIdUseCase: GetRevisionByIdUseCase.Interface\n ) {}\n\n async execute<T extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n id: string,\n revisionDescription: string | undefined\n ): Promise<Result<CmsEntry<T>, UseCaseAbstraction.Error>> {\n const canAccess = await this.accessControl.canAccessEntry({ model, rwd: \"w\" });\n if (!canAccess) {\n return Result.fail(EntryNotAuthorizedError.fromModel(model));\n }\n\n try {\n const result = await this.getRevisionByIdUseCase.execute<T>(model, id);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n const originalEntry = result.value;\n\n const entry = {\n ...originalEntry,\n revisionDescription\n };\n\n const canAccessEntry = await this.accessControl.canAccessEntry({\n model,\n entry,\n rwd: \"w\"\n });\n\n if (!canAccessEntry) {\n return Result.fail(EntryNotAuthorizedError.fromModel(model));\n }\n\n await this.eventPublisher.publish(\n new EntryBeforeUpdateRevisionDescriptionEvent({\n entry,\n original: originalEntry,\n revisionDescription,\n model\n })\n );\n\n const updateResult = await this.repository.execute(model, entry);\n if (updateResult.isFail()) {\n return Result.fail(updateResult.error);\n }\n\n await this.eventPublisher.publish(\n new EntryAfterUpdateRevisionDescriptionEvent({\n entry,\n original: originalEntry,\n revisionDescription,\n model\n })\n );\n\n return Result.ok(entry);\n } catch (error) {\n return Result.fail(error as UseCaseAbstraction.Error);\n }\n }\n}\n\nexport const UpdateRevisionDescriptionUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: UpdateRevisionDescriptionUseCaseImpl,\n dependencies: [EventPublisher, UpdateRevisionRepository, AccessControl, GetRevisionByIdUseCase]\n});\n"],"names":["UpdateRevisionDescriptionUseCaseImpl","eventPublisher","repository","accessControl","getRevisionByIdUseCase","model","id","revisionDescription","canAccess","Result","EntryNotAuthorizedError","result","originalEntry","entry","canAccessEntry","EntryBeforeUpdateRevisionDescriptionEvent","updateResult","EntryAfterUpdateRevisionDescriptionEvent","error","UpdateRevisionDescriptionUseCase","createImplementation","UseCaseAbstraction","EventPublisher","UpdateRevisionRepository","AccessControl","GetRevisionByIdUseCase"],"mappings":";;;;;;;;AAaA,MAAMA;IACF,YACYC,cAAwC,EACxCC,UAA8C,EAC9CC,aAAsC,EACtCC,sBAAwD,CAClE;aAJUH,cAAc,GAAdA;aACAC,UAAU,GAAVA;aACAC,aAAa,GAAbA;aACAC,sBAAsB,GAAtBA;IACT;IAEH,MAAM,QACFC,KAAe,EACfC,EAAU,EACVC,mBAAuC,EACe;QACtD,MAAMC,YAAY,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;YAAEH;YAAO,KAAK;QAAI;QAC5E,IAAI,CAACG,WACD,OAAOC,OAAO,IAAI,CAACC,wBAAwB,SAAS,CAACL;QAGzD,IAAI;YACA,MAAMM,SAAS,MAAM,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAIN,OAAOC;YAEnE,IAAIK,OAAO,MAAM,IACb,OAAOF,OAAO,IAAI,CAACE,OAAO,KAAK;YAGnC,MAAMC,gBAAgBD,OAAO,KAAK;YAElC,MAAME,QAAQ;gBACV,GAAGD,aAAa;gBAChBL;YACJ;YAEA,MAAMO,iBAAiB,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;gBAC3DT;gBACAQ;gBACA,KAAK;YACT;YAEA,IAAI,CAACC,gBACD,OAAOL,OAAO,IAAI,CAACC,wBAAwB,SAAS,CAACL;YAGzD,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIU,0CAA0C;gBAC1CF;gBACA,UAAUD;gBACVL;gBACAF;YACJ;YAGJ,MAAMW,eAAe,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAACX,OAAOQ;YAC1D,IAAIG,aAAa,MAAM,IACnB,OAAOP,OAAO,IAAI,CAACO,aAAa,KAAK;YAGzC,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIC,yCAAyC;gBACzCJ;gBACA,UAAUD;gBACVL;gBACAF;YACJ;YAGJ,OAAOI,OAAO,EAAE,CAACI;QACrB,EAAE,OAAOK,OAAO;YACZ,OAAOT,OAAO,IAAI,CAACS;QACvB;IACJ;AACJ;AAEO,MAAMC,oEAAmCC,qBAAqB;IACjE,aAAaC;IACb,gBAAgBrB;IAChB,cAAc;QAACsB;QAAgBC;QAA0BC;QAAeC;KAAuB;AACnG"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CmsModelAst, CmsEntryValues } from "../../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Walk entry values using the model AST and assign a stable `_id` to every
|
|
4
|
+
* object and dynamic-zone value — both list items and single values.
|
|
5
|
+
*
|
|
6
|
+
* - Values that already carry an `_id` keep it.
|
|
7
|
+
* - Values without `_id` get a newly generated one.
|
|
8
|
+
* - Duplicate `_id` values within a list array are silently regenerated.
|
|
9
|
+
*
|
|
10
|
+
* Uses `ContentEntryTraverser` so nested objects / dynamic zones are handled
|
|
11
|
+
* automatically — no manual recursion needed.
|
|
12
|
+
*/
|
|
13
|
+
export declare function ensureItemIds(modelAst: CmsModelAst, values: CmsEntryValues): Promise<void>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { generateAlphaNumericLowerCaseId } from "@webiny/utils";
|
|
2
|
+
import { ContentEntryTraverser } from "./ContentEntryTraverser/ContentEntryTraverser.js";
|
|
3
|
+
async function ensureItemIds(modelAst, values) {
|
|
4
|
+
const traverser = new ContentEntryTraverser(modelAst);
|
|
5
|
+
await traverser.traverse(values, async ({ field, value })=>{
|
|
6
|
+
if ("object" !== field.type && "dynamicZone" !== field.type) return;
|
|
7
|
+
if (field.list && Array.isArray(value)) {
|
|
8
|
+
const seen = new Set();
|
|
9
|
+
for (const item of value)if (null != item && "object" == typeof item) {
|
|
10
|
+
if (!item._id || seen.has(item._id)) item._id = generateAlphaNumericLowerCaseId(12);
|
|
11
|
+
seen.add(item._id);
|
|
12
|
+
}
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (!field.list && null != value && "object" == typeof value && !Array.isArray(value)) {
|
|
16
|
+
if (!value._id) value._id = generateAlphaNumericLowerCaseId(12);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
export { ensureItemIds };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=ensureItemIds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/contentEntry/ensureItemIds.js","sources":["../../../src/features/contentEntry/ensureItemIds.ts"],"sourcesContent":["import { generateAlphaNumericLowerCaseId } from \"@webiny/utils\";\nimport type { CmsModelAst, CmsEntryValues } from \"~/types/index.js\";\nimport { ContentEntryTraverser } from \"./ContentEntryTraverser/ContentEntryTraverser.js\";\n\n/**\n * Walk entry values using the model AST and assign a stable `_id` to every\n * object and dynamic-zone value — both list items and single values.\n *\n * - Values that already carry an `_id` keep it.\n * - Values without `_id` get a newly generated one.\n * - Duplicate `_id` values within a list array are silently regenerated.\n *\n * Uses `ContentEntryTraverser` so nested objects / dynamic zones are handled\n * automatically — no manual recursion needed.\n */\nexport async function ensureItemIds(modelAst: CmsModelAst, values: CmsEntryValues): Promise<void> {\n const traverser = new ContentEntryTraverser(modelAst);\n\n await traverser.traverse(values, async ({ field, value }) => {\n if (field.type !== \"object\" && field.type !== \"dynamicZone\") {\n return;\n }\n\n // List fields: assign _id to every array item.\n if (field.list && Array.isArray(value)) {\n const seen = new Set<string>();\n\n for (const item of value) {\n if (item == null || typeof item !== \"object\") {\n continue;\n }\n\n if (!item._id || seen.has(item._id)) {\n item._id = generateAlphaNumericLowerCaseId(12);\n }\n\n seen.add(item._id);\n }\n return;\n }\n\n // Single-value: assign _id to the value object.\n if (!field.list && value != null && typeof value === \"object\" && !Array.isArray(value)) {\n if (!value._id) {\n value._id = generateAlphaNumericLowerCaseId(12);\n }\n }\n });\n}\n"],"names":["ensureItemIds","modelAst","values","traverser","ContentEntryTraverser","field","value","Array","seen","Set","item","generateAlphaNumericLowerCaseId"],"mappings":";;AAeO,eAAeA,cAAcC,QAAqB,EAAEC,MAAsB;IAC7E,MAAMC,YAAY,IAAIC,sBAAsBH;IAE5C,MAAME,UAAU,QAAQ,CAACD,QAAQ,OAAO,EAAEG,KAAK,EAAEC,KAAK,EAAE;QACpD,IAAID,AAAe,aAAfA,MAAM,IAAI,IAAiBA,AAAe,kBAAfA,MAAM,IAAI,EACrC;QAIJ,IAAIA,MAAM,IAAI,IAAIE,MAAM,OAAO,CAACD,QAAQ;YACpC,MAAME,OAAO,IAAIC;YAEjB,KAAK,MAAMC,QAAQJ,MACf,IAAII,AAAQ,QAARA,QAAgB,AAAgB,YAAhB,OAAOA;gBAI3B,IAAI,CAACA,KAAK,GAAG,IAAIF,KAAK,GAAG,CAACE,KAAK,GAAG,GAC9BA,KAAK,GAAG,GAAGC,gCAAgC;gBAG/CH,KAAK,GAAG,CAACE,KAAK,GAAG;;YAErB;QACJ;QAGA,IAAI,CAACL,MAAM,IAAI,IAAIC,AAAS,QAATA,SAAiB,AAAiB,YAAjB,OAAOA,SAAsB,CAACC,MAAM,OAAO,CAACD,QAC5E;YAAA,IAAI,CAACA,MAAM,GAAG,EACVA,MAAM,GAAG,GAAGK,gCAAgC;QAChD;IAER;AACJ"}
|
package/features/contentEntry/entryDataFactories/CreateEntryDataFactory/CreateEntryDataFactory.d.ts
CHANGED
|
@@ -3,12 +3,14 @@ import { AccessControl, CmsContext } from "../../../../features/shared/abstracti
|
|
|
3
3
|
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
4
4
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
5
5
|
import type { CmsEntryValues, CmsModel, CreateCmsEntryInput, CreateCmsEntryOptionsInput } from "../../../../types/index.js";
|
|
6
|
+
import { ModelToAstConverter } from "../../../../features/contentModel/ModelToAstConverter/abstractions.js";
|
|
6
7
|
declare class CreateEntryDataFactoryImpl implements ICreateEntryDataFactory {
|
|
7
8
|
private readonly cmsContext;
|
|
8
9
|
private readonly identityContext;
|
|
9
10
|
private readonly tenantContext;
|
|
10
11
|
private readonly accessControl;
|
|
11
|
-
|
|
12
|
+
private readonly modelToAstConverter;
|
|
13
|
+
constructor(cmsContext: CmsContext.Interface, identityContext: IdentityContext.Interface, tenantContext: TenantContext.Interface, accessControl: AccessControl.Interface, modelToAstConverter: ModelToAstConverter.Interface);
|
|
12
14
|
create<TValues extends CmsEntryValues = CmsEntryValues>(model: CmsModel, rawInput: CreateCmsEntryInput<TValues>, options?: CreateCmsEntryOptionsInput): Promise<ICreateEntryDataResponse<TValues>>;
|
|
13
15
|
}
|
|
14
16
|
export declare const CreateEntryDataFactory: import("@webiny/di").Implementation<typeof CreateEntryDataFactoryImpl>;
|
package/features/contentEntry/entryDataFactories/CreateEntryDataFactory/CreateEntryDataFactory.js
CHANGED
|
@@ -14,6 +14,8 @@ import { getIdentity } from "../../../../utils/identity.js";
|
|
|
14
14
|
import { NotAuthorizedError } from "../../../../utils/errors.js";
|
|
15
15
|
import { getSystem } from "../system.js";
|
|
16
16
|
import { getExpiresAt } from "../expiresAt.js";
|
|
17
|
+
import { ModelToAstConverter } from "../../../contentModel/ModelToAstConverter/abstractions.js";
|
|
18
|
+
import { ensureItemIds } from "../../ensureItemIds.js";
|
|
17
19
|
const convertDefaultValue = (field, value)=>{
|
|
18
20
|
switch(field.type){
|
|
19
21
|
case "boolean":
|
|
@@ -64,19 +66,22 @@ const createEntryId = (input)=>{
|
|
|
64
66
|
};
|
|
65
67
|
};
|
|
66
68
|
class CreateEntryDataFactoryImpl {
|
|
67
|
-
constructor(cmsContext, identityContext, tenantContext, accessControl){
|
|
69
|
+
constructor(cmsContext, identityContext, tenantContext, accessControl, modelToAstConverter){
|
|
68
70
|
this.cmsContext = cmsContext;
|
|
69
71
|
this.identityContext = identityContext;
|
|
70
72
|
this.tenantContext = tenantContext;
|
|
71
73
|
this.accessControl = accessControl;
|
|
74
|
+
this.modelToAstConverter = modelToAstConverter;
|
|
72
75
|
}
|
|
73
76
|
async create(model, rawInput, options) {
|
|
74
77
|
const initialValues = cleanInputValues(model, rawInput.values || {});
|
|
78
|
+
const modelAst = this.modelToAstConverter.toAst(model);
|
|
79
|
+
await ensureItemIds(modelAst, initialValues);
|
|
75
80
|
await validateModelEntryDataOrThrow({
|
|
76
81
|
context: this.cmsContext,
|
|
77
82
|
model,
|
|
78
83
|
values: initialValues,
|
|
79
|
-
|
|
84
|
+
skipValidation: options?.skipValidation
|
|
80
85
|
});
|
|
81
86
|
const values = await referenceFieldsMapping({
|
|
82
87
|
context: this.cmsContext,
|
|
@@ -208,7 +213,8 @@ const CreateEntryDataFactory_CreateEntryDataFactory = createImplementation({
|
|
|
208
213
|
CmsContext,
|
|
209
214
|
IdentityContext,
|
|
210
215
|
TenantContext,
|
|
211
|
-
AccessControl
|
|
216
|
+
AccessControl,
|
|
217
|
+
ModelToAstConverter
|
|
212
218
|
]
|
|
213
219
|
});
|
|
214
220
|
export { CreateEntryDataFactory_CreateEntryDataFactory as CreateEntryDataFactory };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentEntry/entryDataFactories/CreateEntryDataFactory/CreateEntryDataFactory.js","sources":["../../../../../src/features/contentEntry/entryDataFactories/CreateEntryDataFactory/CreateEntryDataFactory.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport {\n CreateEntryDataFactory as FactoryAbstraction,\n type ICreateEntryDataFactory,\n type ICreateEntryDataResponse\n} from \"./abstractions.js\";\nimport { AccessControl, CmsContext } from \"~/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport type {\n CmsEntry,\n CmsEntryValues,\n CmsModel,\n CmsModelField,\n CreateCmsEntryInput,\n CreateCmsEntryOptionsInput\n} from \"~/types/index.js\";\nimport { getDate } from \"~/utils/date.js\";\nimport { ROOT_FOLDER } from \"~/constants.js\";\nimport WebinyError from \"@webiny/error\";\nimport { validateModelEntryDataOrThrow } from \"~/crud/contentEntry/entryDataValidation.js\";\nimport { referenceFieldsMapping } from \"~/crud/contentEntry/referenceFieldsMapping.js\";\nimport { createIdentifier, mdbid } from \"@webiny/utils\";\nimport { STATUS_DRAFT, STATUS_PUBLISHED, STATUS_UNPUBLISHED } from \"../statuses.js\";\nimport { getIdentity } from \"~/utils/identity.js\";\nimport { NotAuthorizedError } from \"~/utils/errors.js\";\nimport { getSystem } from \"../system.js\";\nimport { getExpiresAt } from \"../expiresAt.js\";\n\ntype DefaultValue = boolean | number | string | null;\n\nconst convertDefaultValue = (field: CmsModelField, value: DefaultValue): DefaultValue => {\n switch (field.type) {\n case \"boolean\":\n return Boolean(value);\n case \"number\":\n return Number(value);\n default:\n return value;\n }\n};\n\nconst getDefaultValue = (field: CmsModelField): (DefaultValue | DefaultValue[]) | undefined => {\n const { settings, list } = field;\n if (settings && settings.defaultValue !== undefined) {\n return convertDefaultValue(field, settings.defaultValue);\n }\n const { predefinedValues } = field;\n if (\n !predefinedValues ||\n !predefinedValues.enabled ||\n Array.isArray(predefinedValues.values) === false\n ) {\n return undefined;\n }\n if (!list) {\n const selectedValue = predefinedValues.values.find(value => {\n return !!value.selected;\n });\n if (selectedValue) {\n return convertDefaultValue(field, selectedValue.value);\n }\n return undefined;\n }\n return predefinedValues.values\n .filter(({ selected }) => !!selected)\n .map(({ value }) => {\n return convertDefaultValue(field, value);\n });\n};\n\nconst cleanInputValues = <TValues extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n input: TValues\n) => {\n return model.fields.reduce<TValues>((acc, field) => {\n if (!field.fieldId) {\n throw new WebinyError(\"Field does not have an fieldId.\", \"MISSING_FIELD_ID\", {\n field\n });\n }\n const key = field.fieldId as keyof TValues;\n const value = input[key] as TValues[keyof TValues];\n acc[key] = value === undefined ? (getDefaultValue(field) as TValues[keyof TValues]) : value;\n return acc;\n }, {} as TValues);\n};\n\nconst createEntryId = (input: CreateCmsEntryInput) => {\n let entryId = mdbid();\n if (input.id) {\n if (input.id.match(/^([a-zA-Z0-9])([a-zA-Z0-9-]+)([a-zA-Z0-9])$/) === null) {\n throw new WebinyError(\n \"The provided ID is not valid. It must be a string which can be A-Z, a-z, 0-9, - and it cannot start or end with a -.\",\n \"INVALID_ID\",\n {\n id: input.id\n }\n );\n }\n entryId = input.id;\n }\n const version = 1;\n return {\n entryId,\n version,\n id: createIdentifier({\n id: entryId,\n version\n })\n };\n};\n\nclass CreateEntryDataFactoryImpl implements ICreateEntryDataFactory {\n public constructor(\n private readonly cmsContext: CmsContext.Interface,\n private readonly identityContext: IdentityContext.Interface,\n private readonly tenantContext: TenantContext.Interface,\n private readonly accessControl: AccessControl.Interface\n ) {}\n\n public async create<TValues extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n rawInput: CreateCmsEntryInput<TValues>,\n options?: CreateCmsEntryOptionsInput\n ): Promise<ICreateEntryDataResponse<TValues>> {\n const initialValues = cleanInputValues<TValues>(model, rawInput.values || ({} as TValues));\n\n await validateModelEntryDataOrThrow({\n context: this.cmsContext,\n model,\n values: initialValues,\n skipValidators: options?.skipValidators\n });\n\n const values = await referenceFieldsMapping<TValues>({\n context: this.cmsContext,\n model,\n values: initialValues,\n validateEntries: true\n });\n\n const { id, entryId, version } = createEntryId(rawInput);\n\n const currentIdentity = this.identityContext.getIdentity();\n const currentDateTime = new Date();\n\n const status = rawInput.status || STATUS_DRAFT;\n if (status !== STATUS_DRAFT) {\n if (status === STATUS_PUBLISHED) {\n const canPublish = await this.accessControl.canAccessEntry({ model, pw: \"p\" });\n if (!canPublish) {\n throw new NotAuthorizedError(\n `Not allowed to access \"${model.modelId}\" entries.`\n );\n }\n } else if (status === STATUS_UNPUBLISHED) {\n const canUnpublish = await this.accessControl.canAccessEntry({ model, pw: \"u\" });\n if (!canUnpublish) {\n throw new NotAuthorizedError(\n `Not allowed to access \"${model.modelId}\" entries.`\n );\n }\n }\n }\n\n const locked = status !== STATUS_DRAFT;\n\n let revisionLevelPublishingMetaFields: Pick<\n CmsEntry,\n | \"revisionFirstPublishedOn\"\n | \"revisionLastPublishedOn\"\n | \"revisionFirstPublishedBy\"\n | \"revisionLastPublishedBy\"\n > = {\n revisionFirstPublishedOn: null,\n revisionLastPublishedOn: null,\n revisionFirstPublishedBy: null,\n revisionLastPublishedBy: null\n };\n\n let entryLevelPublishingMetaFields: Pick<\n CmsEntry,\n \"firstPublishedOn\" | \"lastPublishedOn\" | \"firstPublishedBy\" | \"lastPublishedBy\"\n > = {\n firstPublishedOn: null,\n lastPublishedOn: null,\n firstPublishedBy: null,\n lastPublishedBy: null\n };\n\n if (status === STATUS_PUBLISHED) {\n revisionLevelPublishingMetaFields = {\n revisionFirstPublishedOn: getDate(\n rawInput.revisionFirstPublishedOn,\n currentDateTime\n ),\n revisionLastPublishedOn: getDate(rawInput.revisionLastPublishedOn, currentDateTime),\n revisionFirstPublishedBy: getIdentity(\n rawInput.revisionFirstPublishedBy,\n currentIdentity\n ),\n revisionLastPublishedBy: getIdentity(\n rawInput.revisionLastPublishedBy,\n currentIdentity\n )\n };\n\n entryLevelPublishingMetaFields = {\n firstPublishedOn: getDate(rawInput.firstPublishedOn, currentDateTime),\n lastPublishedOn: getDate(rawInput.lastPublishedOn, currentDateTime),\n firstPublishedBy: getIdentity(rawInput.firstPublishedBy, currentIdentity),\n lastPublishedBy: getIdentity(rawInput.lastPublishedBy, currentIdentity)\n };\n }\n\n const entry: CmsEntry<TValues> = {\n tenant: this.tenantContext.getTenant().id,\n entryId,\n id,\n modelId: model.modelId,\n createdOn: getDate(rawInput.createdOn, currentDateTime),\n modifiedOn: getDate(rawInput.modifiedOn, null),\n savedOn: getDate(rawInput.savedOn, currentDateTime),\n deletedOn: getDate(rawInput.deletedOn, null),\n restoredOn: getDate(rawInput.restoredOn, null),\n createdBy: getIdentity(rawInput.createdBy, currentIdentity)!,\n modifiedBy: getIdentity(rawInput.modifiedBy, null),\n savedBy: getIdentity(rawInput.savedBy, currentIdentity)!,\n deletedBy: getIdentity(rawInput.deletedBy, null),\n restoredBy: getIdentity(rawInput.restoredBy, null),\n ...entryLevelPublishingMetaFields,\n revisionCreatedOn: getDate(rawInput.revisionCreatedOn, currentDateTime),\n revisionModifiedOn: getDate(rawInput.revisionModifiedOn, null),\n revisionSavedOn: getDate(rawInput.revisionSavedOn, currentDateTime),\n revisionDeletedOn: getDate(rawInput.revisionDeletedOn, null),\n revisionRestoredOn: getDate(rawInput.revisionRestoredOn, null),\n revisionCreatedBy: getIdentity(rawInput.revisionCreatedBy, currentIdentity)!,\n revisionModifiedBy: getIdentity(rawInput.revisionModifiedBy, null),\n revisionSavedBy: getIdentity(rawInput.revisionSavedBy, currentIdentity)!,\n revisionDeletedBy: getIdentity(rawInput.revisionDeletedBy, null),\n revisionRestoredBy: getIdentity(rawInput.revisionRestoredBy, null),\n ...revisionLevelPublishingMetaFields,\n version,\n status,\n locked,\n values,\n location: {\n folderId:\n rawInput.location?.folderId || rawInput.wbyAco_location?.folderId || ROOT_FOLDER\n },\n system: getSystem({\n input: rawInput\n }),\n live:\n status === STATUS_PUBLISHED\n ? {\n version\n }\n : null,\n revisionDescription: \"\",\n expiresAt: getExpiresAt({ expiresAt: rawInput.expiresAt })\n };\n\n if (status !== STATUS_DRAFT) {\n if (status === STATUS_PUBLISHED) {\n const canPublish = await this.accessControl.canAccessEntry({\n model,\n entry,\n pw: \"p\"\n });\n if (!canPublish) {\n throw new NotAuthorizedError(`Not allowed to access entry \"${entry.entryId}\".`);\n }\n } else if (status === STATUS_UNPUBLISHED) {\n const canUnpublish = await this.accessControl.canAccessEntry({\n model,\n entry,\n pw: \"u\"\n });\n if (!canUnpublish) {\n throw new NotAuthorizedError(`Not allowed to access entry \"${entry.entryId}\".`);\n }\n }\n }\n\n return {\n entry,\n input: {\n ...rawInput,\n values: structuredClone(values)\n }\n };\n }\n}\n\nexport const CreateEntryDataFactory = createImplementation({\n abstraction: FactoryAbstraction,\n implementation: CreateEntryDataFactoryImpl,\n dependencies: [CmsContext, IdentityContext, TenantContext, AccessControl]\n});\n"],"names":["convertDefaultValue","field","value","Boolean","Number","getDefaultValue","settings","list","undefined","predefinedValues","Array","selectedValue","selected","cleanInputValues","model","input","acc","WebinyError","key","createEntryId","entryId","mdbid","version","createIdentifier","CreateEntryDataFactoryImpl","cmsContext","identityContext","tenantContext","accessControl","rawInput","options","initialValues","validateModelEntryDataOrThrow","values","referenceFieldsMapping","id","currentIdentity","currentDateTime","Date","status","STATUS_DRAFT","STATUS_PUBLISHED","canPublish","NotAuthorizedError","STATUS_UNPUBLISHED","canUnpublish","locked","revisionLevelPublishingMetaFields","entryLevelPublishingMetaFields","getDate","getIdentity","entry","ROOT_FOLDER","getSystem","getExpiresAt","structuredClone","CreateEntryDataFactory","createImplementation","FactoryAbstraction","CmsContext","IdentityContext","TenantContext","AccessControl"],"mappings":";;;;;;;;;;;;;;;;AA+BA,MAAMA,sBAAsB,CAACC,OAAsBC;IAC/C,OAAQD,MAAM,IAAI;QACd,KAAK;YACD,OAAOE,QAAQD;QACnB,KAAK;YACD,OAAOE,OAAOF;QAClB;YACI,OAAOA;IACf;AACJ;AAEA,MAAMG,kBAAkB,CAACJ;IACrB,MAAM,EAAEK,QAAQ,EAAEC,IAAI,EAAE,GAAGN;IAC3B,IAAIK,YAAYA,AAA0BE,WAA1BF,SAAS,YAAY,EACjC,OAAON,oBAAoBC,OAAOK,SAAS,YAAY;IAE3D,MAAM,EAAEG,gBAAgB,EAAE,GAAGR;IAC7B,IACI,CAACQ,oBACD,CAACA,iBAAiB,OAAO,IACzBC,AAA2C,UAA3CA,MAAM,OAAO,CAACD,iBAAiB,MAAM,GAErC;IAEJ,IAAI,CAACF,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ataFactory/CreateEntryDataFactory.js","sources":["../../../../../src/features/contentEntry/entryDataFactories/CreateEntryDataFactory/CreateEntryDataFactory.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport {\n CreateEntryDataFactory as FactoryAbstraction,\n type ICreateEntryDataFactory,\n type ICreateEntryDataResponse\n} from \"./abstractions.js\";\nimport { AccessControl, CmsContext } from \"~/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport type {\n CmsEntry,\n CmsEntryValues,\n CmsModel,\n CmsModelField,\n CreateCmsEntryInput,\n CreateCmsEntryOptionsInput\n} from \"~/types/index.js\";\nimport { getDate } from \"~/utils/date.js\";\nimport { ROOT_FOLDER } from \"~/constants.js\";\nimport WebinyError from \"@webiny/error\";\nimport { validateModelEntryDataOrThrow } from \"~/crud/contentEntry/entryDataValidation.js\";\nimport { referenceFieldsMapping } from \"~/crud/contentEntry/referenceFieldsMapping.js\";\nimport { createIdentifier, mdbid } from \"@webiny/utils\";\nimport { STATUS_DRAFT, STATUS_PUBLISHED, STATUS_UNPUBLISHED } from \"../statuses.js\";\nimport { getIdentity } from \"~/utils/identity.js\";\nimport { NotAuthorizedError } from \"~/utils/errors.js\";\nimport { getSystem } from \"../system.js\";\nimport { getExpiresAt } from \"../expiresAt.js\";\nimport { ModelToAstConverter } from \"~/features/contentModel/ModelToAstConverter/abstractions.js\";\nimport { ensureItemIds } from \"../../ensureItemIds.js\";\n\ntype DefaultValue = boolean | number | string | null;\n\nconst convertDefaultValue = (field: CmsModelField, value: DefaultValue): DefaultValue => {\n switch (field.type) {\n case \"boolean\":\n return Boolean(value);\n case \"number\":\n return Number(value);\n default:\n return value;\n }\n};\n\nconst getDefaultValue = (field: CmsModelField): (DefaultValue | DefaultValue[]) | undefined => {\n const { settings, list } = field;\n if (settings && settings.defaultValue !== undefined) {\n return convertDefaultValue(field, settings.defaultValue);\n }\n const { predefinedValues } = field;\n if (\n !predefinedValues ||\n !predefinedValues.enabled ||\n Array.isArray(predefinedValues.values) === false\n ) {\n return undefined;\n }\n if (!list) {\n const selectedValue = predefinedValues.values.find(value => {\n return !!value.selected;\n });\n if (selectedValue) {\n return convertDefaultValue(field, selectedValue.value);\n }\n return undefined;\n }\n return predefinedValues.values\n .filter(({ selected }) => !!selected)\n .map(({ value }) => {\n return convertDefaultValue(field, value);\n });\n};\n\nconst cleanInputValues = <TValues extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n input: TValues\n) => {\n return model.fields.reduce<TValues>((acc, field) => {\n if (!field.fieldId) {\n throw new WebinyError(\"Field does not have an fieldId.\", \"MISSING_FIELD_ID\", {\n field\n });\n }\n const key = field.fieldId as keyof TValues;\n const value = input[key] as TValues[keyof TValues];\n acc[key] = value === undefined ? (getDefaultValue(field) as TValues[keyof TValues]) : value;\n return acc;\n }, {} as TValues);\n};\n\nconst createEntryId = (input: CreateCmsEntryInput) => {\n let entryId = mdbid();\n if (input.id) {\n if (input.id.match(/^([a-zA-Z0-9])([a-zA-Z0-9-]+)([a-zA-Z0-9])$/) === null) {\n throw new WebinyError(\n \"The provided ID is not valid. It must be a string which can be A-Z, a-z, 0-9, - and it cannot start or end with a -.\",\n \"INVALID_ID\",\n {\n id: input.id\n }\n );\n }\n entryId = input.id;\n }\n const version = 1;\n return {\n entryId,\n version,\n id: createIdentifier({\n id: entryId,\n version\n })\n };\n};\n\nclass CreateEntryDataFactoryImpl implements ICreateEntryDataFactory {\n public constructor(\n private readonly cmsContext: CmsContext.Interface,\n private readonly identityContext: IdentityContext.Interface,\n private readonly tenantContext: TenantContext.Interface,\n private readonly accessControl: AccessControl.Interface,\n private readonly modelToAstConverter: ModelToAstConverter.Interface\n ) {}\n\n public async create<TValues extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n rawInput: CreateCmsEntryInput<TValues>,\n options?: CreateCmsEntryOptionsInput\n ): Promise<ICreateEntryDataResponse<TValues>> {\n const initialValues = cleanInputValues<TValues>(model, rawInput.values || ({} as TValues));\n\n const modelAst = this.modelToAstConverter.toAst(model);\n await ensureItemIds(modelAst, initialValues);\n\n await validateModelEntryDataOrThrow({\n context: this.cmsContext,\n model,\n values: initialValues,\n skipValidation: options?.skipValidation\n });\n\n const values = await referenceFieldsMapping<TValues>({\n context: this.cmsContext,\n model,\n values: initialValues,\n validateEntries: true\n });\n\n const { id, entryId, version } = createEntryId(rawInput);\n\n const currentIdentity = this.identityContext.getIdentity();\n const currentDateTime = new Date();\n\n const status = rawInput.status || STATUS_DRAFT;\n if (status !== STATUS_DRAFT) {\n if (status === STATUS_PUBLISHED) {\n const canPublish = await this.accessControl.canAccessEntry({ model, pw: \"p\" });\n if (!canPublish) {\n throw new NotAuthorizedError(\n `Not allowed to access \"${model.modelId}\" entries.`\n );\n }\n } else if (status === STATUS_UNPUBLISHED) {\n const canUnpublish = await this.accessControl.canAccessEntry({ model, pw: \"u\" });\n if (!canUnpublish) {\n throw new NotAuthorizedError(\n `Not allowed to access \"${model.modelId}\" entries.`\n );\n }\n }\n }\n\n const locked = status !== STATUS_DRAFT;\n\n let revisionLevelPublishingMetaFields: Pick<\n CmsEntry,\n | \"revisionFirstPublishedOn\"\n | \"revisionLastPublishedOn\"\n | \"revisionFirstPublishedBy\"\n | \"revisionLastPublishedBy\"\n > = {\n revisionFirstPublishedOn: null,\n revisionLastPublishedOn: null,\n revisionFirstPublishedBy: null,\n revisionLastPublishedBy: null\n };\n\n let entryLevelPublishingMetaFields: Pick<\n CmsEntry,\n \"firstPublishedOn\" | \"lastPublishedOn\" | \"firstPublishedBy\" | \"lastPublishedBy\"\n > = {\n firstPublishedOn: null,\n lastPublishedOn: null,\n firstPublishedBy: null,\n lastPublishedBy: null\n };\n\n if (status === STATUS_PUBLISHED) {\n revisionLevelPublishingMetaFields = {\n revisionFirstPublishedOn: getDate(\n rawInput.revisionFirstPublishedOn,\n currentDateTime\n ),\n revisionLastPublishedOn: getDate(rawInput.revisionLastPublishedOn, currentDateTime),\n revisionFirstPublishedBy: getIdentity(\n rawInput.revisionFirstPublishedBy,\n currentIdentity\n ),\n revisionLastPublishedBy: getIdentity(\n rawInput.revisionLastPublishedBy,\n currentIdentity\n )\n };\n\n entryLevelPublishingMetaFields = {\n firstPublishedOn: getDate(rawInput.firstPublishedOn, currentDateTime),\n lastPublishedOn: getDate(rawInput.lastPublishedOn, currentDateTime),\n firstPublishedBy: getIdentity(rawInput.firstPublishedBy, currentIdentity),\n lastPublishedBy: getIdentity(rawInput.lastPublishedBy, currentIdentity)\n };\n }\n\n const entry: CmsEntry<TValues> = {\n tenant: this.tenantContext.getTenant().id,\n entryId,\n id,\n modelId: model.modelId,\n createdOn: getDate(rawInput.createdOn, currentDateTime),\n modifiedOn: getDate(rawInput.modifiedOn, null),\n savedOn: getDate(rawInput.savedOn, currentDateTime),\n deletedOn: getDate(rawInput.deletedOn, null),\n restoredOn: getDate(rawInput.restoredOn, null),\n createdBy: getIdentity(rawInput.createdBy, currentIdentity)!,\n modifiedBy: getIdentity(rawInput.modifiedBy, null),\n savedBy: getIdentity(rawInput.savedBy, currentIdentity)!,\n deletedBy: getIdentity(rawInput.deletedBy, null),\n restoredBy: getIdentity(rawInput.restoredBy, null),\n ...entryLevelPublishingMetaFields,\n revisionCreatedOn: getDate(rawInput.revisionCreatedOn, currentDateTime),\n revisionModifiedOn: getDate(rawInput.revisionModifiedOn, null),\n revisionSavedOn: getDate(rawInput.revisionSavedOn, currentDateTime),\n revisionDeletedOn: getDate(rawInput.revisionDeletedOn, null),\n revisionRestoredOn: getDate(rawInput.revisionRestoredOn, null),\n revisionCreatedBy: getIdentity(rawInput.revisionCreatedBy, currentIdentity)!,\n revisionModifiedBy: getIdentity(rawInput.revisionModifiedBy, null),\n revisionSavedBy: getIdentity(rawInput.revisionSavedBy, currentIdentity)!,\n revisionDeletedBy: getIdentity(rawInput.revisionDeletedBy, null),\n revisionRestoredBy: getIdentity(rawInput.revisionRestoredBy, null),\n ...revisionLevelPublishingMetaFields,\n version,\n status,\n locked,\n values,\n location: {\n folderId:\n rawInput.location?.folderId || rawInput.wbyAco_location?.folderId || ROOT_FOLDER\n },\n system: getSystem({\n input: rawInput\n }),\n live:\n status === STATUS_PUBLISHED\n ? {\n version\n }\n : null,\n revisionDescription: \"\",\n expiresAt: getExpiresAt({ expiresAt: rawInput.expiresAt })\n };\n\n if (status !== STATUS_DRAFT) {\n if (status === STATUS_PUBLISHED) {\n const canPublish = await this.accessControl.canAccessEntry({\n model,\n entry,\n pw: \"p\"\n });\n if (!canPublish) {\n throw new NotAuthorizedError(`Not allowed to access entry \"${entry.entryId}\".`);\n }\n } else if (status === STATUS_UNPUBLISHED) {\n const canUnpublish = await this.accessControl.canAccessEntry({\n model,\n entry,\n pw: \"u\"\n });\n if (!canUnpublish) {\n throw new NotAuthorizedError(`Not allowed to access entry \"${entry.entryId}\".`);\n }\n }\n }\n\n return {\n entry,\n input: {\n ...rawInput,\n values: structuredClone(values)\n }\n };\n }\n}\n\nexport const CreateEntryDataFactory = createImplementation({\n abstraction: FactoryAbstraction,\n implementation: CreateEntryDataFactoryImpl,\n dependencies: [CmsContext, IdentityContext, TenantContext, AccessControl, ModelToAstConverter]\n});\n"],"names":["convertDefaultValue","field","value","Boolean","Number","getDefaultValue","settings","list","undefined","predefinedValues","Array","selectedValue","selected","cleanInputValues","model","input","acc","WebinyError","key","createEntryId","entryId","mdbid","version","createIdentifier","CreateEntryDataFactoryImpl","cmsContext","identityContext","tenantContext","accessControl","modelToAstConverter","rawInput","options","initialValues","modelAst","ensureItemIds","validateModelEntryDataOrThrow","values","referenceFieldsMapping","id","currentIdentity","currentDateTime","Date","status","STATUS_DRAFT","STATUS_PUBLISHED","canPublish","NotAuthorizedError","STATUS_UNPUBLISHED","canUnpublish","locked","revisionLevelPublishingMetaFields","entryLevelPublishingMetaFields","getDate","getIdentity","entry","ROOT_FOLDER","getSystem","getExpiresAt","structuredClone","CreateEntryDataFactory","createImplementation","FactoryAbstraction","CmsContext","IdentityContext","TenantContext","AccessControl","ModelToAstConverter"],"mappings":";;;;;;;;;;;;;;;;;;AAiCA,MAAMA,sBAAsB,CAACC,OAAsBC;IAC/C,OAAQD,MAAM,IAAI;QACd,KAAK;YACD,OAAOE,QAAQD;QACnB,KAAK;YACD,OAAOE,OAAOF;QAClB;YACI,OAAOA;IACf;AACJ;AAEA,MAAMG,kBAAkB,CAACJ;IACrB,MAAM,EAAEK,QAAQ,EAAEC,IAAI,EAAE,GAAGN;IAC3B,IAAIK,YAAYA,AAA0BE,WAA1BF,SAAS,YAAY,EACjC,OAAON,oBAAoBC,OAAOK,SAAS,YAAY;IAE3D,MAAM,EAAEG,gBAAgB,EAAE,GAAGR;IAC7B,IACI,CAACQ,oBACD,CAACA,iBAAiB,OAAO,IACzBC,AAA2C,UAA3CA,MAAM,OAAO,CAACD,iBAAiB,MAAM,GAErC;IAEJ,IAAI,CAACF,MAAM;QACP,MAAMI,gBAAgBF,iBAAiB,MAAM,CAAC,IAAI,CAACP,CAAAA,QACxC,CAAC,CAACA,MAAM,QAAQ;QAE3B,IAAIS,eACA,OAAOX,oBAAoBC,OAAOU,cAAc,KAAK;QAEzD;IACJ;IACA,OAAOF,iBAAiB,MAAM,CACzB,MAAM,CAAC,CAAC,EAAEG,QAAQ,EAAE,GAAK,CAAC,CAACA,UAC3B,GAAG,CAAC,CAAC,EAAEV,KAAK,EAAE,GACJF,oBAAoBC,OAAOC;AAE9C;AAEA,MAAMW,mBAAmB,CACrBC,OACAC,QAEOD,MAAM,MAAM,CAAC,MAAM,CAAU,CAACE,KAAKf;QACtC,IAAI,CAACA,MAAM,OAAO,EACd,MAAM,IAAIgB,MAAY,mCAAmC,oBAAoB;YACzEhB;QACJ;QAEJ,MAAMiB,MAAMjB,MAAM,OAAO;QACzB,MAAMC,QAAQa,KAAK,CAACG,IAAI;QACxBF,GAAG,CAACE,IAAI,GAAGhB,AAAUM,WAAVN,QAAuBG,gBAAgBJ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a,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;oBACvD/B;oBACAwC;oBACA,IAAI;gBACR;gBACA,IAAI,CAACT,YACD,MAAM,IAAIC,mBAAmB,CAAC,6BAA6B,EAAEQ,MAAM,OAAO,CAAC,EAAE,CAAC;YAEtF,OAAO,IAAIZ,WAAWK,oBAAoB;gBACtC,MAAMC,eAAe,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;oBACzDlC;oBACAwC;oBACA,IAAI;gBACR;gBACA,IAAI,CAACN,cACD,MAAM,IAAIF,mBAAmB,CAAC,6BAA6B,EAAEQ,MAAM,OAAO,CAAC,EAAE,CAAC;YAEtF;QAAA;QAGJ,OAAO;YACHA;YACA,OAAO;gBACH,GAAGxB,QAAQ;gBACX,QAAQ4B,gBAAgBtB;YAC5B;QACJ;IACJ;AACJ;AAEO,MAAMuB,gDAAyBC,qBAAqB;IACvD,aAAaC;IACb,gBAAgBrC;IAChB,cAAc;QAACsC;QAAYC;QAAiBC;QAAeC;QAAeC;KAAoB;AAClG"}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CreateEntryRevisionFromDataFactory as FactoryAbstraction, type ICreateEntryRevisionFromDataFactory } from "./abstractions.js";
|
|
2
2
|
import { AccessControl, CmsContext } from "../../../../features/shared/abstractions.js";
|
|
3
|
-
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
4
3
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
5
4
|
import type { CmsEntry, CmsEntryValues, CmsModel, CreateCmsEntryInput, CreateCmsEntryOptionsInput } from "../../../../types/index.js";
|
|
5
|
+
import { ModelToAstConverter } from "../../../../features/contentModel/ModelToAstConverter/abstractions.js";
|
|
6
|
+
import { GetLatestRevisionByEntryIdUseCase } from "../../../../features/contentEntry/GetLatestRevisionByEntryId/index.js";
|
|
6
7
|
declare class CreateEntryRevisionFromDataFactoryImpl implements ICreateEntryRevisionFromDataFactory {
|
|
7
8
|
private readonly cmsContext;
|
|
8
9
|
private readonly identityContext;
|
|
9
|
-
private readonly tenantContext;
|
|
10
10
|
private readonly accessControl;
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
private readonly modelToAstConverter;
|
|
12
|
+
private readonly getLatestRevision;
|
|
13
|
+
constructor(cmsContext: CmsContext.Interface, identityContext: IdentityContext.Interface, accessControl: AccessControl.Interface, modelToAstConverter: ModelToAstConverter.Interface, getLatestRevision: GetLatestRevisionByEntryIdUseCase.Interface);
|
|
14
|
+
create<TValues extends CmsEntryValues = CmsEntryValues>(sourceId: string, model: CmsModel, rawInput: CreateCmsEntryInput<TValues>, originalEntry: CmsEntry<TValues>, options?: CreateCmsEntryOptionsInput): Promise<FactoryAbstraction.Return<TValues>>;
|
|
13
15
|
}
|
|
14
16
|
export declare const CreateEntryRevisionFromDataFactory: import("@webiny/di").Implementation<typeof CreateEntryRevisionFromDataFactoryImpl>;
|
|
15
17
|
export {};
|
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
import { createImplementation } from "@webiny/feature/api";
|
|
1
|
+
import { Result, createImplementation } from "@webiny/feature/api";
|
|
2
2
|
import { CreateEntryRevisionFromDataFactory } from "./abstractions.js";
|
|
3
3
|
import { AccessControl, CmsContext } from "../../../shared/abstractions.js";
|
|
4
|
-
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
5
4
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
6
5
|
import { getDate } from "../../../../utils/date.js";
|
|
7
6
|
import { getIdentity } from "../../../../utils/identity.js";
|
|
8
7
|
import { mapAndCleanUpdatedInputData } from "../mapAndCleanUpdatedInputData.js";
|
|
9
|
-
import {
|
|
8
|
+
import { validateModelEntryData } from "../../../../crud/contentEntry/entryDataValidation.js";
|
|
9
|
+
import { EntryValidationError } from "../../../../domain/contentEntry/errors.js";
|
|
10
10
|
import { referenceFieldsMapping } from "../../../../crud/contentEntry/referenceFieldsMapping.js";
|
|
11
11
|
import { createIdentifier, parseIdentifier } from "@webiny/utils";
|
|
12
12
|
import error from "@webiny/error";
|
|
13
13
|
import { STATUS_DRAFT, STATUS_PUBLISHED, STATUS_UNPUBLISHED } from "../statuses.js";
|
|
14
14
|
import { NotAuthorizedError } from "../../../../utils/errors.js";
|
|
15
15
|
import { getSystem } from "../system.js";
|
|
16
|
+
import { ModelToAstConverter } from "../../../contentModel/ModelToAstConverter/abstractions.js";
|
|
17
|
+
import { ensureItemIds } from "../../ensureItemIds.js";
|
|
18
|
+
import { hasEntryContentChanged } from "../hasEntryContentChanged.js";
|
|
19
|
+
import { GetLatestRevisionByEntryIdUseCase } from "../../GetLatestRevisionByEntryId/index.js";
|
|
16
20
|
const increaseEntryIdVersion = (id)=>{
|
|
17
21
|
const { id: entryId, version } = parseIdentifier(id);
|
|
18
22
|
if (!version) throw new error("Cannot increase version on the ID without the version part.", "WRONG_ID", {
|
|
@@ -28,24 +32,33 @@ const increaseEntryIdVersion = (id)=>{
|
|
|
28
32
|
};
|
|
29
33
|
};
|
|
30
34
|
class CreateEntryRevisionFromDataFactoryImpl {
|
|
31
|
-
constructor(cmsContext, identityContext,
|
|
35
|
+
constructor(cmsContext, identityContext, accessControl, modelToAstConverter, getLatestRevision){
|
|
32
36
|
this.cmsContext = cmsContext;
|
|
33
37
|
this.identityContext = identityContext;
|
|
34
|
-
this.tenantContext = tenantContext;
|
|
35
38
|
this.accessControl = accessControl;
|
|
39
|
+
this.modelToAstConverter = modelToAstConverter;
|
|
40
|
+
this.getLatestRevision = getLatestRevision;
|
|
36
41
|
}
|
|
37
|
-
async create(sourceId, model, rawInput, originalEntry,
|
|
42
|
+
async create(sourceId, model, rawInput, originalEntry, options) {
|
|
43
|
+
const latestResult = await this.getLatestRevision.execute(model, {
|
|
44
|
+
id: originalEntry.entryId
|
|
45
|
+
});
|
|
46
|
+
if (latestResult.isFail()) return Result.fail(latestResult.error);
|
|
47
|
+
const latestStorageEntry = latestResult.value;
|
|
38
48
|
const initialValues = {
|
|
39
49
|
...originalEntry.values,
|
|
40
50
|
...mapAndCleanUpdatedInputData(model, rawInput.values)
|
|
41
51
|
};
|
|
42
|
-
|
|
52
|
+
const modelAst = this.modelToAstConverter.toAst(model);
|
|
53
|
+
await ensureItemIds(modelAst, initialValues);
|
|
54
|
+
const invalidFields = await validateModelEntryData({
|
|
43
55
|
context: this.cmsContext,
|
|
44
56
|
model,
|
|
45
57
|
values: initialValues,
|
|
46
58
|
entry: originalEntry,
|
|
47
|
-
|
|
59
|
+
skipValidation: options?.skipValidation
|
|
48
60
|
});
|
|
61
|
+
if (invalidFields.length > 0) return Result.fail(new EntryValidationError("Validation failed.", invalidFields));
|
|
49
62
|
const values = await referenceFieldsMapping({
|
|
50
63
|
context: this.cmsContext,
|
|
51
64
|
model,
|
|
@@ -63,13 +76,13 @@ class CreateEntryRevisionFromDataFactoryImpl {
|
|
|
63
76
|
model,
|
|
64
77
|
pw: "p"
|
|
65
78
|
});
|
|
66
|
-
if (!canPublish)
|
|
79
|
+
if (!canPublish) return Result.fail(new NotAuthorizedError(`Not allowed to access "${model.modelId}" entries.`));
|
|
67
80
|
} else if (status === STATUS_UNPUBLISHED) {
|
|
68
81
|
const canUnpublish = await this.accessControl.canAccessEntry({
|
|
69
82
|
model,
|
|
70
83
|
pw: "u"
|
|
71
84
|
});
|
|
72
|
-
if (!canUnpublish)
|
|
85
|
+
if (!canUnpublish) return Result.fail(new NotAuthorizedError(`Not allowed to access "${model.modelId}" entries.`));
|
|
73
86
|
}
|
|
74
87
|
}
|
|
75
88
|
const locked = status !== STATUS_DRAFT;
|
|
@@ -99,16 +112,31 @@ class CreateEntryRevisionFromDataFactoryImpl {
|
|
|
99
112
|
lastPublishedBy: getIdentity(rawInput.lastPublishedBy, currentIdentity)
|
|
100
113
|
};
|
|
101
114
|
}
|
|
115
|
+
const contentChanged = hasEntryContentChanged({
|
|
116
|
+
values,
|
|
117
|
+
baselineValues: latestStorageEntry.values
|
|
118
|
+
});
|
|
119
|
+
const entryLevelSaved = contentChanged ? {
|
|
120
|
+
savedOn: currentDateTime,
|
|
121
|
+
modifiedOn: currentDateTime,
|
|
122
|
+
savedBy: currentIdentity,
|
|
123
|
+
modifiedBy: currentIdentity
|
|
124
|
+
} : {
|
|
125
|
+
savedOn: latestStorageEntry.savedOn,
|
|
126
|
+
modifiedOn: latestStorageEntry.modifiedOn,
|
|
127
|
+
savedBy: latestStorageEntry.savedBy,
|
|
128
|
+
modifiedBy: latestStorageEntry.modifiedBy
|
|
129
|
+
};
|
|
102
130
|
const entry = {
|
|
103
131
|
...originalEntry,
|
|
104
132
|
id,
|
|
105
133
|
version: nextVersion,
|
|
106
134
|
createdOn: getDate(rawInput.createdOn, latestStorageEntry.createdOn),
|
|
107
|
-
savedOn: getDate(rawInput.savedOn,
|
|
108
|
-
modifiedOn: getDate(rawInput.modifiedOn,
|
|
135
|
+
savedOn: getDate(rawInput.savedOn, entryLevelSaved.savedOn),
|
|
136
|
+
modifiedOn: getDate(rawInput.modifiedOn, entryLevelSaved.modifiedOn),
|
|
109
137
|
createdBy: getIdentity(rawInput.createdBy, latestStorageEntry.createdBy),
|
|
110
|
-
savedBy: getIdentity(rawInput.savedBy,
|
|
111
|
-
modifiedBy: getIdentity(rawInput.modifiedBy,
|
|
138
|
+
savedBy: getIdentity(rawInput.savedBy, entryLevelSaved.savedBy),
|
|
139
|
+
modifiedBy: getIdentity(rawInput.modifiedBy, entryLevelSaved.modifiedBy),
|
|
112
140
|
...entryLevelPublishingMetaFields,
|
|
113
141
|
revisionCreatedOn: getDate(rawInput.revisionCreatedOn, currentDateTime),
|
|
114
142
|
revisionSavedOn: getDate(rawInput.revisionSavedOn, currentDateTime),
|
|
@@ -116,6 +144,7 @@ class CreateEntryRevisionFromDataFactoryImpl {
|
|
|
116
144
|
revisionCreatedBy: getIdentity(rawInput.revisionCreatedBy, currentIdentity),
|
|
117
145
|
revisionSavedBy: getIdentity(rawInput.revisionSavedBy, currentIdentity),
|
|
118
146
|
revisionModifiedBy: getIdentity(rawInput.revisionModifiedBy, null),
|
|
147
|
+
revisionDescription: void 0,
|
|
119
148
|
...revisionLevelPublishingMetaFields,
|
|
120
149
|
locked,
|
|
121
150
|
status,
|
|
@@ -127,13 +156,13 @@ class CreateEntryRevisionFromDataFactoryImpl {
|
|
|
127
156
|
live: originalEntry.live,
|
|
128
157
|
expiresAt: null
|
|
129
158
|
};
|
|
130
|
-
return {
|
|
159
|
+
return Result.ok({
|
|
131
160
|
entry,
|
|
132
161
|
input: {
|
|
133
162
|
...rawInput,
|
|
134
163
|
values: structuredClone(values)
|
|
135
164
|
}
|
|
136
|
-
};
|
|
165
|
+
});
|
|
137
166
|
}
|
|
138
167
|
}
|
|
139
168
|
const CreateEntryRevisionFromDataFactory_CreateEntryRevisionFromDataFactory = createImplementation({
|
|
@@ -142,8 +171,9 @@ const CreateEntryRevisionFromDataFactory_CreateEntryRevisionFromDataFactory = cr
|
|
|
142
171
|
dependencies: [
|
|
143
172
|
CmsContext,
|
|
144
173
|
IdentityContext,
|
|
145
|
-
|
|
146
|
-
|
|
174
|
+
AccessControl,
|
|
175
|
+
ModelToAstConverter,
|
|
176
|
+
GetLatestRevisionByEntryIdUseCase
|
|
147
177
|
]
|
|
148
178
|
});
|
|
149
179
|
export { CreateEntryRevisionFromDataFactory_CreateEntryRevisionFromDataFactory as CreateEntryRevisionFromDataFactory };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.js","sources":["../../../../../src/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport {\n CreateEntryRevisionFromDataFactory as FactoryAbstraction,\n type ICreateEntryRevisionFromDataFactory,\n type ICreateEntryRevisionFromDataResponse\n} from \"./abstractions.js\";\nimport { AccessControl, CmsContext } from \"~/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport type {\n CmsEntry,\n CmsEntryValues,\n CmsModel,\n CreateCmsEntryInput,\n CreateCmsEntryOptionsInput\n} from \"~/types/index.js\";\nimport { getDate } from \"~/utils/date.js\";\nimport { getIdentity } from \"~/utils/identity.js\";\nimport { mapAndCleanUpdatedInputData } from \"../mapAndCleanUpdatedInputData.js\";\nimport { validateModelEntryDataOrThrow } from \"~/crud/contentEntry/entryDataValidation.js\";\nimport { referenceFieldsMapping } from \"~/crud/contentEntry/referenceFieldsMapping.js\";\nimport { createIdentifier, parseIdentifier } from \"@webiny/utils\";\nimport WebinyError from \"@webiny/error\";\nimport { STATUS_DRAFT, STATUS_PUBLISHED, STATUS_UNPUBLISHED } from \"../statuses.js\";\nimport { NotAuthorizedError } from \"~/utils/errors.js\";\nimport { getSystem } from \"../system.js\";\n\nconst increaseEntryIdVersion = (id: string) => {\n const { id: entryId, version } = parseIdentifier(id);\n if (!version) {\n throw new WebinyError(\n \"Cannot increase version on the ID without the version part.\",\n \"WRONG_ID\",\n {\n id\n }\n );\n }\n return {\n entryId,\n version: version + 1,\n id: createIdentifier({\n id: entryId,\n version: version + 1\n })\n };\n};\n\nclass CreateEntryRevisionFromDataFactoryImpl implements ICreateEntryRevisionFromDataFactory {\n public constructor(\n private readonly cmsContext: CmsContext.Interface,\n private readonly identityContext: IdentityContext.Interface,\n private readonly tenantContext: TenantContext.Interface,\n private readonly accessControl: AccessControl.Interface\n ) {}\n\n public async create<TValues extends CmsEntryValues = CmsEntryValues>(\n sourceId: string,\n model: CmsModel,\n rawInput: CreateCmsEntryInput<TValues>,\n originalEntry: CmsEntry<TValues>,\n latestStorageEntry: CmsEntry<TValues>,\n options?: CreateCmsEntryOptionsInput\n ): Promise<ICreateEntryRevisionFromDataResponse<TValues>> {\n const initialValues = {\n ...originalEntry.values,\n ...mapAndCleanUpdatedInputData<TValues>(model, rawInput.values)\n };\n\n await validateModelEntryDataOrThrow({\n context: this.cmsContext,\n model,\n values: initialValues,\n entry: originalEntry,\n skipValidators: options?.skipValidators\n });\n\n const values = await referenceFieldsMapping<TValues>({\n context: this.cmsContext,\n model,\n values: initialValues,\n validateEntries: false\n });\n\n const latestId = latestStorageEntry ? latestStorageEntry.id : sourceId;\n const { id, version: nextVersion } = increaseEntryIdVersion(latestId);\n\n const currentIdentity = this.identityContext.getIdentity();\n const currentDateTime = new Date();\n\n const status = rawInput.status || STATUS_DRAFT;\n if (status !== STATUS_DRAFT) {\n if (status === STATUS_PUBLISHED) {\n const canPublish = await this.accessControl.canAccessEntry({ model, pw: \"p\" });\n if (!canPublish) {\n throw new NotAuthorizedError(\n `Not allowed to access \"${model.modelId}\" entries.`\n );\n }\n } else if (status === STATUS_UNPUBLISHED) {\n const canUnpublish = await this.accessControl.canAccessEntry({ model, pw: \"u\" });\n if (!canUnpublish) {\n throw new NotAuthorizedError(\n `Not allowed to access \"${model.modelId}\" entries.`\n );\n }\n }\n }\n\n const locked = status !== STATUS_DRAFT;\n\n let revisionLevelPublishingMetaFields: Pick<\n CmsEntry,\n | \"revisionFirstPublishedOn\"\n | \"revisionLastPublishedOn\"\n | \"revisionFirstPublishedBy\"\n | \"revisionLastPublishedBy\"\n > = {\n revisionFirstPublishedOn: getDate(rawInput.revisionFirstPublishedOn, null),\n revisionLastPublishedOn: getDate(rawInput.revisionLastPublishedOn, null),\n revisionFirstPublishedBy: getIdentity(rawInput.revisionFirstPublishedBy, null),\n revisionLastPublishedBy: getIdentity(rawInput.revisionLastPublishedBy, null)\n };\n\n let entryLevelPublishingMetaFields: Pick<\n CmsEntry,\n \"firstPublishedOn\" | \"lastPublishedOn\" | \"firstPublishedBy\" | \"lastPublishedBy\"\n > = {\n firstPublishedOn: getDate(\n rawInput.firstPublishedOn,\n latestStorageEntry.firstPublishedOn\n ),\n lastPublishedOn: getDate(rawInput.lastPublishedOn, latestStorageEntry.lastPublishedOn),\n firstPublishedBy: getIdentity(\n rawInput.firstPublishedBy,\n latestStorageEntry.firstPublishedBy\n ),\n lastPublishedBy: getIdentity(\n rawInput.lastPublishedBy,\n latestStorageEntry.lastPublishedBy\n )\n };\n\n if (status === STATUS_PUBLISHED) {\n revisionLevelPublishingMetaFields = {\n revisionFirstPublishedOn: getDate(\n rawInput.revisionFirstPublishedOn,\n currentDateTime\n ),\n revisionLastPublishedOn: getDate(rawInput.revisionLastPublishedOn, currentDateTime),\n revisionFirstPublishedBy: getIdentity(\n rawInput.revisionFirstPublishedBy,\n currentIdentity\n ),\n revisionLastPublishedBy: getIdentity(\n rawInput.revisionLastPublishedBy,\n currentIdentity\n )\n };\n\n entryLevelPublishingMetaFields = {\n firstPublishedOn: getDate(\n rawInput.firstPublishedOn,\n latestStorageEntry.firstPublishedOn\n ),\n lastPublishedOn: getDate(rawInput.lastPublishedOn, currentDateTime),\n firstPublishedBy: getIdentity(\n rawInput.firstPublishedBy,\n latestStorageEntry.firstPublishedBy\n ),\n lastPublishedBy: getIdentity(rawInput.lastPublishedBy, currentIdentity)\n };\n }\n\n const entry: CmsEntry<TValues> = {\n ...originalEntry,\n id,\n version: nextVersion,\n createdOn: getDate(rawInput.createdOn, latestStorageEntry.createdOn),\n savedOn: getDate(rawInput.savedOn, currentDateTime),\n modifiedOn: getDate(rawInput.modifiedOn, currentDateTime),\n createdBy: getIdentity(rawInput.createdBy, latestStorageEntry.createdBy)!,\n savedBy: getIdentity(rawInput.savedBy, currentIdentity)!,\n modifiedBy: getIdentity(rawInput.modifiedBy, currentIdentity),\n ...entryLevelPublishingMetaFields,\n revisionCreatedOn: getDate(rawInput.revisionCreatedOn, currentDateTime),\n revisionSavedOn: getDate(rawInput.revisionSavedOn, currentDateTime),\n revisionModifiedOn: getDate(rawInput.revisionModifiedOn, null),\n revisionCreatedBy: getIdentity(rawInput.revisionCreatedBy, currentIdentity)!,\n revisionSavedBy: getIdentity(rawInput.revisionSavedBy, currentIdentity)!,\n revisionModifiedBy: getIdentity(rawInput.revisionModifiedBy, null),\n ...revisionLevelPublishingMetaFields,\n locked,\n status,\n values,\n system: getSystem({\n input: rawInput,\n original: originalEntry\n }),\n live: originalEntry.live,\n expiresAt: null\n };\n\n return {\n entry,\n input: {\n ...rawInput,\n values: structuredClone(values)\n }\n };\n }\n}\n\nexport const CreateEntryRevisionFromDataFactory = createImplementation({\n abstraction: FactoryAbstraction,\n implementation: CreateEntryRevisionFromDataFactoryImpl,\n dependencies: [CmsContext, IdentityContext, TenantContext, AccessControl]\n});\n"],"names":["increaseEntryIdVersion","id","entryId","version","parseIdentifier","WebinyError","createIdentifier","CreateEntryRevisionFromDataFactoryImpl","cmsContext","identityContext","tenantContext","accessControl","sourceId","model","rawInput","originalEntry","latestStorageEntry","options","initialValues","mapAndCleanUpdatedInputData","validateModelEntryDataOrThrow","values","referenceFieldsMapping","latestId","nextVersion","currentIdentity","currentDateTime","Date","status","STATUS_DRAFT","STATUS_PUBLISHED","canPublish","NotAuthorizedError","STATUS_UNPUBLISHED","canUnpublish","locked","revisionLevelPublishingMetaFields","getDate","getIdentity","entryLevelPublishingMetaFields","entry","getSystem","structuredClone","CreateEntryRevisionFromDataFactory","createImplementation","FactoryAbstraction","CmsContext","IdentityContext","TenantContext","AccessControl"],"mappings":";;;;;;;;;;;;;;;AA2BA,MAAMA,yBAAyB,CAACC;IAC5B,MAAM,EAAE,IAAIC,OAAO,EAAEC,OAAO,EAAE,GAAGC,gBAAgBH;IACjD,IAAI,CAACE,SACD,MAAM,IAAIE,MACN,+DACA,YACA;QACIJ;IACJ;IAGR,OAAO;QACHC;QACA,SAASC,UAAU;QACnB,IAAIG,iBAAiB;YACjB,IAAIJ;YACJ,SAASC,UAAU;QACvB;IACJ;AACJ;AAEA,MAAMI;IACF,YACqBC,UAAgC,EAChCC,eAA0C,EAC1CC,aAAsC,EACtCC,aAAsC,CACzD;aAJmBH,UAAU,GAAVA;aACAC,eA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YAAYxB,SAAS,OAAO,EAAEW;YACvC,YAAYa,YAAYxB,SAAS,UAAU,EAAEW;YAC7C,GAAGc,8BAA8B;YACjC,mBAAmBF,QAAQvB,SAAS,iBAAiB,EAAEY;YACvD,iBAAiBW,QAAQvB,SAAS,eAAe,EAAEY;YACnD,oBAAoBW,QAAQvB,SAAS,kBAAkB,EAAE;YACzD,mBAAmBwB,YAAYxB,SAAS,iBAAiB,EAAEW;YAC3D,iBAAiBa,YAAYxB,SAAS,eAAe,EAAEW;YACvD,oBAAoBa,YAAYxB,SAAS,kBAAkB,EAAE;YAC7D,GAAGsB,iCAAiC;YACpCD;YACAP;YACAP;YACA,QAAQoB,UAAU;gBACd,OAAO3B;gBACP,UAAUC;YACd;YACA,MAAMA,cAAc,IAAI;YACxB,WAAW;QACf;QAEA,OAAO;YACHyB;YACA,OAAO;gBACH,GAAG1B,QAAQ;gBACX,QAAQ4B,gBAAgBrB;YAC5B;QACJ;IACJ;AACJ;AAEO,MAAMsB,wEAAqCC,qBAAqB;IACnE,aAAaC;IACb,gBAAgBtC;IAChB,cAAc;QAACuC;QAAYC;QAAiBC;QAAeC;KAAc;AAC7E"}
|
|
1
|
+
{"version":3,"file":"features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.js","sources":["../../../../../src/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.ts"],"sourcesContent":["import { createImplementation, Result } from \"@webiny/feature/api\";\nimport {\n CreateEntryRevisionFromDataFactory as FactoryAbstraction,\n type ICreateEntryRevisionFromDataFactory\n} from \"./abstractions.js\";\nimport { AccessControl, CmsContext } from \"~/features/shared/abstractions.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport type {\n CmsEntry,\n CmsEntryValues,\n CmsModel,\n CreateCmsEntryInput,\n CreateCmsEntryOptionsInput\n} from \"~/types/index.js\";\nimport { getDate } from \"~/utils/date.js\";\nimport { getIdentity } from \"~/utils/identity.js\";\nimport { mapAndCleanUpdatedInputData } from \"../mapAndCleanUpdatedInputData.js\";\nimport { validateModelEntryData } from \"~/crud/contentEntry/entryDataValidation.js\";\nimport { EntryValidationError } from \"~/domain/contentEntry/errors.js\";\nimport { referenceFieldsMapping } from \"~/crud/contentEntry/referenceFieldsMapping.js\";\nimport { createIdentifier, parseIdentifier } from \"@webiny/utils\";\nimport WebinyError from \"@webiny/error\";\nimport { STATUS_DRAFT, STATUS_PUBLISHED, STATUS_UNPUBLISHED } from \"../statuses.js\";\nimport { NotAuthorizedError } from \"~/utils/errors.js\";\nimport { getSystem } from \"../system.js\";\nimport { ModelToAstConverter } from \"~/features/contentModel/ModelToAstConverter/abstractions.js\";\nimport { ensureItemIds } from \"../../ensureItemIds.js\";\nimport { hasEntryContentChanged } from \"../hasEntryContentChanged.js\";\nimport { GetLatestRevisionByEntryIdUseCase } from \"~/features/contentEntry/GetLatestRevisionByEntryId/index.js\";\n\nconst increaseEntryIdVersion = (id: string) => {\n const { id: entryId, version } = parseIdentifier(id);\n if (!version) {\n throw new WebinyError(\n \"Cannot increase version on the ID without the version part.\",\n \"WRONG_ID\",\n {\n id\n }\n );\n }\n return {\n entryId,\n version: version + 1,\n id: createIdentifier({\n id: entryId,\n version: version + 1\n })\n };\n};\n\nclass CreateEntryRevisionFromDataFactoryImpl implements ICreateEntryRevisionFromDataFactory {\n public constructor(\n private readonly cmsContext: CmsContext.Interface,\n private readonly identityContext: IdentityContext.Interface,\n private readonly accessControl: AccessControl.Interface,\n private readonly modelToAstConverter: ModelToAstConverter.Interface,\n private readonly getLatestRevision: GetLatestRevisionByEntryIdUseCase.Interface\n ) {}\n\n public async create<TValues extends CmsEntryValues = CmsEntryValues>(\n sourceId: string,\n model: CmsModel,\n rawInput: CreateCmsEntryInput<TValues>,\n originalEntry: CmsEntry<TValues>,\n options?: CreateCmsEntryOptionsInput\n ): Promise<FactoryAbstraction.Return<TValues>> {\n const latestResult = await this.getLatestRevision.execute<TValues>(model, {\n id: originalEntry.entryId\n });\n if (latestResult.isFail()) {\n return Result.fail(latestResult.error);\n }\n const latestStorageEntry = latestResult.value;\n\n const initialValues = {\n ...originalEntry.values,\n ...mapAndCleanUpdatedInputData<TValues>(model, rawInput.values)\n };\n\n const modelAst = this.modelToAstConverter.toAst(model);\n await ensureItemIds(modelAst, initialValues);\n\n const invalidFields = await validateModelEntryData({\n context: this.cmsContext,\n model,\n values: initialValues,\n entry: originalEntry,\n skipValidation: options?.skipValidation\n });\n if (invalidFields.length > 0) {\n return Result.fail(new EntryValidationError(\"Validation failed.\", invalidFields));\n }\n\n const values = await referenceFieldsMapping<TValues>({\n context: this.cmsContext,\n model,\n values: initialValues,\n validateEntries: false\n });\n\n const latestId = latestStorageEntry ? latestStorageEntry.id : sourceId;\n const { id, version: nextVersion } = increaseEntryIdVersion(latestId);\n\n const currentIdentity = this.identityContext.getIdentity();\n const currentDateTime = new Date();\n\n const status = rawInput.status || STATUS_DRAFT;\n if (status !== STATUS_DRAFT) {\n if (status === STATUS_PUBLISHED) {\n const canPublish = await this.accessControl.canAccessEntry({ model, pw: \"p\" });\n if (!canPublish) {\n return Result.fail(\n new NotAuthorizedError(`Not allowed to access \"${model.modelId}\" entries.`)\n );\n }\n } else if (status === STATUS_UNPUBLISHED) {\n const canUnpublish = await this.accessControl.canAccessEntry({ model, pw: \"u\" });\n if (!canUnpublish) {\n return Result.fail(\n new NotAuthorizedError(`Not allowed to access \"${model.modelId}\" entries.`)\n );\n }\n }\n }\n\n const locked = status !== STATUS_DRAFT;\n\n let revisionLevelPublishingMetaFields: Pick<\n CmsEntry,\n | \"revisionFirstPublishedOn\"\n | \"revisionLastPublishedOn\"\n | \"revisionFirstPublishedBy\"\n | \"revisionLastPublishedBy\"\n > = {\n revisionFirstPublishedOn: getDate(rawInput.revisionFirstPublishedOn, null),\n revisionLastPublishedOn: getDate(rawInput.revisionLastPublishedOn, null),\n revisionFirstPublishedBy: getIdentity(rawInput.revisionFirstPublishedBy, null),\n revisionLastPublishedBy: getIdentity(rawInput.revisionLastPublishedBy, null)\n };\n\n let entryLevelPublishingMetaFields: Pick<\n CmsEntry,\n \"firstPublishedOn\" | \"lastPublishedOn\" | \"firstPublishedBy\" | \"lastPublishedBy\"\n > = {\n firstPublishedOn: getDate(\n rawInput.firstPublishedOn,\n latestStorageEntry.firstPublishedOn\n ),\n lastPublishedOn: getDate(rawInput.lastPublishedOn, latestStorageEntry.lastPublishedOn),\n firstPublishedBy: getIdentity(\n rawInput.firstPublishedBy,\n latestStorageEntry.firstPublishedBy\n ),\n lastPublishedBy: getIdentity(\n rawInput.lastPublishedBy,\n latestStorageEntry.lastPublishedBy\n )\n };\n\n if (status === STATUS_PUBLISHED) {\n revisionLevelPublishingMetaFields = {\n revisionFirstPublishedOn: getDate(\n rawInput.revisionFirstPublishedOn,\n currentDateTime\n ),\n revisionLastPublishedOn: getDate(rawInput.revisionLastPublishedOn, currentDateTime),\n revisionFirstPublishedBy: getIdentity(\n rawInput.revisionFirstPublishedBy,\n currentIdentity\n ),\n revisionLastPublishedBy: getIdentity(\n rawInput.revisionLastPublishedBy,\n currentIdentity\n )\n };\n\n entryLevelPublishingMetaFields = {\n firstPublishedOn: getDate(\n rawInput.firstPublishedOn,\n latestStorageEntry.firstPublishedOn\n ),\n lastPublishedOn: getDate(rawInput.lastPublishedOn, currentDateTime),\n firstPublishedBy: getIdentity(\n rawInput.firstPublishedBy,\n latestStorageEntry.firstPublishedBy\n ),\n lastPublishedBy: getIdentity(rawInput.lastPublishedBy, currentIdentity)\n };\n }\n\n /**\n * Creating a revision without changing the entry's content (e.g. \"New revision\" in the\n * revisions list, or saving a published entry without editing anything) is not a\n * modification, so the entry-level saved/modified meta fields are kept. The new revision\n * is compared with the latest revision, not the source revision: creating a revision from\n * an older one reverts the content, which is a change. Explicitly provided meta field\n * values always take precedence.\n */\n const contentChanged = hasEntryContentChanged({\n values,\n baselineValues: latestStorageEntry.values\n });\n\n const entryLevelSaved = contentChanged\n ? {\n savedOn: currentDateTime,\n modifiedOn: currentDateTime,\n savedBy: currentIdentity,\n modifiedBy: currentIdentity\n }\n : {\n savedOn: latestStorageEntry.savedOn,\n modifiedOn: latestStorageEntry.modifiedOn,\n savedBy: latestStorageEntry.savedBy,\n modifiedBy: latestStorageEntry.modifiedBy\n };\n\n const entry: CmsEntry<TValues> = {\n ...originalEntry,\n id,\n version: nextVersion,\n createdOn: getDate(rawInput.createdOn, latestStorageEntry.createdOn),\n savedOn: getDate(rawInput.savedOn, entryLevelSaved.savedOn),\n modifiedOn: getDate(rawInput.modifiedOn, entryLevelSaved.modifiedOn),\n createdBy: getIdentity(rawInput.createdBy, latestStorageEntry.createdBy)!,\n savedBy: getIdentity(rawInput.savedBy, entryLevelSaved.savedBy)!,\n modifiedBy: getIdentity(rawInput.modifiedBy, entryLevelSaved.modifiedBy),\n ...entryLevelPublishingMetaFields,\n revisionCreatedOn: getDate(rawInput.revisionCreatedOn, currentDateTime),\n revisionSavedOn: getDate(rawInput.revisionSavedOn, currentDateTime),\n revisionModifiedOn: getDate(rawInput.revisionModifiedOn, null),\n revisionCreatedBy: getIdentity(rawInput.revisionCreatedBy, currentIdentity)!,\n revisionSavedBy: getIdentity(rawInput.revisionSavedBy, currentIdentity)!,\n revisionModifiedBy: getIdentity(rawInput.revisionModifiedBy, null),\n revisionDescription: undefined,\n ...revisionLevelPublishingMetaFields,\n locked,\n status,\n values,\n system: getSystem({\n input: rawInput,\n original: originalEntry\n }),\n live: originalEntry.live,\n expiresAt: null\n };\n\n return Result.ok({\n entry,\n input: {\n ...rawInput,\n values: structuredClone(values)\n }\n });\n }\n}\n\nexport const CreateEntryRevisionFromDataFactory = createImplementation({\n abstraction: FactoryAbstraction,\n implementation: CreateEntryRevisionFromDataFactoryImpl,\n dependencies: [\n CmsContext,\n IdentityContext,\n AccessControl,\n ModelToAstConverter,\n GetLatestRevisionByEntryIdUseCase\n ]\n});\n"],"names":["increaseEntryIdVersion","id","entryId","version","parseIdentifier","WebinyError","createIdentifier","CreateEntryRevisionFromDataFactoryImpl","cmsContext","identityContext","accessControl","modelToAstConverter","getLatestRevision","sourceId","model","rawInput","originalEntry","options","latestResult","Result","latestStorageEntry","initialValues","mapAndCleanUpdatedInputData","modelAst","ensureItemIds","invalidFields","validateModelEntryData","EntryValidationError","values","referenceFieldsMapping","latestId","nextVersion","currentIdentity","currentDateTime","Date","status","STATUS_DRAFT","STATUS_PUBLISHED","canPublish","NotAuthorizedError","STATUS_UNPUBLISHED","canUnpublish","locked","revisionLevelPublishingMetaFields","getDate","getIdentity","entryLevelPublishingMetaFields","contentChanged","hasEntryContentChanged","entryLevelSaved","entry","undefined","getSystem","structuredClone","CreateEntryRevisionFromDataFactory","createImplementation","FactoryAbstraction","CmsContext","IdentityContext","AccessControl","ModelToAstConverter","GetLatestRevisionByEntryIdUseCase"],"mappings":";;;;;;;;;;;;;;;;;;;AA8BA,MAAMA,yBAAyB,CAACC;IAC5B,MAAM,EAAE,IAAIC,OAAO,EAAEC,OAAO,EAAE,GAAGC,gBAAgBH;IACjD,IAAI,CAACE,SACD,MAAM,IAAIE,MACN,+DACA,YACA;QACIJ;IACJ;IAGR,OAAO;QACHC;QACA,SAASC,UAAU;QACnB,IAAIG,iBAAiB;YACjB,IAAIJ;YACJ,SAASC,UAAU;QACvB;IACJ;AACJ;AAEA,MAAMI;IACF,YACqBC,UAAgC,EAChCC,eAA0C,EAC1CC,aAAsC,EACtCC,mBAAkD,EAClDC,iBAA8D,CACjF;aALmBJ,UAAU,GAAVA;aACAC,eAAe,GAAfA;aACAC,aAAa,GAAbA;aACAC,mBAAmB,GAAnBA;aACAC,iBAAiB,GAAjBA;IAClB;IAEH,MAAa,OACTC,QAAgB,EAChBC,KAAe,EACfC,QAAsC,EACtCC,aAAgC,EAChCC,OAAoC,EACO;QAC3C,MAAMC,eAAe,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAUJ,OAAO;YACtE,IAAIE,cAAc,OAAO;QAC7B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;IACnE,aAAaC;IACb,gBAAgBjD;IAChB,cAAc;QACVkD;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -1,13 +1,29 @@
|
|
|
1
|
+
import { type Result } from "@webiny/feature/api";
|
|
2
|
+
import type { GetLatestRevisionByEntryIdUseCase } from "../../../../features/contentEntry/GetLatestRevisionByEntryId/index.js";
|
|
3
|
+
import type { EntryValidationError } from "../../../../domain/contentEntry/errors.js";
|
|
4
|
+
import type { NotAuthorizedError } from "../../../../utils/errors.js";
|
|
1
5
|
import type { CmsEntry, CmsEntryValues, CmsModel, CreateCmsEntryInput, CreateCmsEntryOptionsInput } from "../../../../types/index.js";
|
|
2
6
|
export interface ICreateEntryRevisionFromDataResponse<TValues extends CmsEntryValues = CmsEntryValues> {
|
|
3
7
|
entry: CmsEntry<TValues>;
|
|
4
8
|
input: CreateCmsEntryInput<TValues>;
|
|
5
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Expected failures of building the data of a new entry revision.
|
|
12
|
+
*/
|
|
13
|
+
export interface ICreateEntryRevisionFromDataFactoryErrors {
|
|
14
|
+
latest: GetLatestRevisionByEntryIdUseCase.Error;
|
|
15
|
+
validation: EntryValidationError;
|
|
16
|
+
notAuthorized: NotAuthorizedError;
|
|
17
|
+
}
|
|
18
|
+
type FactoryError = ICreateEntryRevisionFromDataFactoryErrors[keyof ICreateEntryRevisionFromDataFactoryErrors];
|
|
6
19
|
export interface ICreateEntryRevisionFromDataFactory {
|
|
7
|
-
create<TValues extends CmsEntryValues = CmsEntryValues>(sourceId: string, model: CmsModel, rawInput: CreateCmsEntryInput<TValues>, originalEntry: CmsEntry<TValues>,
|
|
20
|
+
create<TValues extends CmsEntryValues = CmsEntryValues>(sourceId: string, model: CmsModel, rawInput: CreateCmsEntryInput<TValues>, originalEntry: CmsEntry<TValues>, options?: CreateCmsEntryOptionsInput): Promise<Result<ICreateEntryRevisionFromDataResponse<TValues>, FactoryError>>;
|
|
8
21
|
}
|
|
9
22
|
export declare const CreateEntryRevisionFromDataFactory: import("@webiny/di").Abstraction<ICreateEntryRevisionFromDataFactory>;
|
|
10
23
|
export declare namespace CreateEntryRevisionFromDataFactory {
|
|
11
24
|
type Interface = ICreateEntryRevisionFromDataFactory;
|
|
25
|
+
type Error = FactoryError;
|
|
26
|
+
type Return<TValues extends CmsEntryValues = CmsEntryValues> = Result<ICreateEntryRevisionFromDataResponse<TValues>, FactoryError>;
|
|
12
27
|
type Response<TValues extends CmsEntryValues = CmsEntryValues> = ICreateEntryRevisionFromDataResponse<TValues>;
|
|
13
28
|
}
|
|
29
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/abstractions.js","sources":["../../../../../src/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type {\n CmsEntry,\n CmsEntryValues,\n CmsModel,\n CreateCmsEntryInput,\n CreateCmsEntryOptionsInput\n} from \"~/types/index.js\";\n\nexport interface ICreateEntryRevisionFromDataResponse<\n TValues extends CmsEntryValues = CmsEntryValues\n> {\n entry: CmsEntry<TValues>;\n input: CreateCmsEntryInput<TValues>;\n}\n\nexport interface ICreateEntryRevisionFromDataFactory {\n create<TValues extends CmsEntryValues = CmsEntryValues>(\n sourceId: string,\n model: CmsModel,\n rawInput: CreateCmsEntryInput<TValues>,\n originalEntry: CmsEntry<TValues>,\n
|
|
1
|
+
{"version":3,"file":"features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/abstractions.js","sources":["../../../../../src/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/abstractions.ts"],"sourcesContent":["import { createAbstraction, type Result } from \"@webiny/feature/api\";\nimport type { GetLatestRevisionByEntryIdUseCase } from \"~/features/contentEntry/GetLatestRevisionByEntryId/index.js\";\nimport type { EntryValidationError } from \"~/domain/contentEntry/errors.js\";\nimport type { NotAuthorizedError } from \"~/utils/errors.js\";\nimport type {\n CmsEntry,\n CmsEntryValues,\n CmsModel,\n CreateCmsEntryInput,\n CreateCmsEntryOptionsInput\n} from \"~/types/index.js\";\n\nexport interface ICreateEntryRevisionFromDataResponse<\n TValues extends CmsEntryValues = CmsEntryValues\n> {\n entry: CmsEntry<TValues>;\n input: CreateCmsEntryInput<TValues>;\n}\n\n/**\n * Expected failures of building the data of a new entry revision.\n */\nexport interface ICreateEntryRevisionFromDataFactoryErrors {\n latest: GetLatestRevisionByEntryIdUseCase.Error;\n validation: EntryValidationError;\n notAuthorized: NotAuthorizedError;\n}\n\ntype FactoryError =\n ICreateEntryRevisionFromDataFactoryErrors[keyof ICreateEntryRevisionFromDataFactoryErrors];\n\nexport interface ICreateEntryRevisionFromDataFactory {\n create<TValues extends CmsEntryValues = CmsEntryValues>(\n sourceId: string,\n model: CmsModel,\n rawInput: CreateCmsEntryInput<TValues>,\n originalEntry: CmsEntry<TValues>,\n options?: CreateCmsEntryOptionsInput\n ): Promise<Result<ICreateEntryRevisionFromDataResponse<TValues>, FactoryError>>;\n}\n\nexport const CreateEntryRevisionFromDataFactory =\n createAbstraction<ICreateEntryRevisionFromDataFactory>(\n \"Cms/Entry/CreateEntryRevisionFromDataFactory\"\n );\n\nexport namespace CreateEntryRevisionFromDataFactory {\n export type Interface = ICreateEntryRevisionFromDataFactory;\n export type Error = FactoryError;\n export type Return<TValues extends CmsEntryValues = CmsEntryValues> = Result<\n ICreateEntryRevisionFromDataResponse<TValues>,\n FactoryError\n >;\n export type Response<TValues extends CmsEntryValues = CmsEntryValues> =\n ICreateEntryRevisionFromDataResponse<TValues>;\n}\n"],"names":["CreateEntryRevisionFromDataFactory","createAbstraction"],"mappings":";AAyCO,MAAMA,qCACTC,kBACI"}
|