@webiny/api-headless-cms 6.5.0-beta.0 → 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/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/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/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.d.ts +5 -3
- package/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.js +40 -14
- 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 +5 -3
- package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.js +66 -29
- 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/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/ValuesSelectionGenerator/ValuesSelectionGenerator.js +1 -1
- package/features/contentModel/ValuesSelectionGenerator/ValuesSelectionGenerator.js.map +1 -1
- package/features/graphql/fields/base/AssetToGraphQL.js +7 -2
- package/features/graphql/fields/base/AssetToGraphQL.js.map +1 -1
- package/package.json +18 -18
|
@@ -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 { 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\";\nimport { ModelToAstConverter } from \"~/features/contentModel/ModelToAstConverter/abstractions.js\";\nimport { ensureItemIds } from \"../../ensureItemIds.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 ) {}\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 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 entry: originalEntry,\n skipValidation: options?.skipValidation\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 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 {\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, AccessControl, ModelToAstConverter]\n});\n"],"names":["increaseEntryIdVersion","id","entryId","version","parseIdentifier","WebinyError","createIdentifier","CreateEntryRevisionFromDataFactoryImpl","cmsContext","identityContext","accessControl","modelToAstConverter","sourceId","model","rawInput","originalEntry","latestStorageEntry","options","initialValues","mapAndCleanUpdatedInputData","modelAst","ensureItemIds","validateModelEntryDataOrThrow","values","referenceFieldsMapping","latestId","nextVersion","currentIdentity","currentDateTime","Date","status","STATUS_DRAFT","STATUS_PUBLISHED","canPublish","NotAuthorizedError","STATUS_UNPUBLISHED","canUnpublish","locked","revisionLevelPublishingMetaFields","getDate","getIdentity","entryLevelPublishingMetaFields","entry","undefined","getSystem","structuredClone","CreateEntryRevisionFromDataFactory","createImplementation","FactoryAbstraction","CmsContext","IdentityContext","AccessControl","ModelToAstConverter"],"mappings":";;;;;;;;;;;;;;;;AA4BA,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,CACrE;aAJmBH,UAAU,GAAVA;aACAC,eAAe,GAAfA;aACAC,aAAa,GAAbA;aACAC,mBAAmB,GAAnBA;IAClB;IAEH,MAAa,OACTC,QAAgB,EAChBC,KAAe,EACfC,QAAsC,EACtCC,aAAgC,EAChCC,kBAAqC,EACrCC,OAAoC,EACkB;QACtD,MAAMC,gBAAgB;YAClB,GAAGH,cAAc,MAAM;YACvB,GAAGI,4BAAqCN,OAAOC,SAAS,MAAM,CAAC;QACnE;QAEA,MAAMM,WAAW,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAACP;QAChD,MAAMQ,cAAcD,UAAUF;QAE9B,MA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AAEa;YAC3D,iBAAiBa,YAAY1B,SAAS,eAAe,EAAEa;YACvD,oBAAoBa,YAAY1B,SAAS,kBAAkB,EAAE;YAC7D,qBAAqB6B;YACrB,GAAGL,iCAAiC;YACpCD;YACAP;YACAP;YACA,QAAQqB,UAAU;gBACd,OAAO9B;gBACP,UAAUC;YACd;YACA,MAAMA,cAAc,IAAI;YACxB,WAAW;QACf;QAEA,OAAO;YACH2B;YACA,OAAO;gBACH,GAAG5B,QAAQ;gBACX,QAAQ+B,gBAAgBtB;YAC5B;QACJ;IACJ;AACJ;AAEO,MAAMuB,wEAAqCC,qBAAqB;IACnE,aAAaC;IACb,gBAAgBzC;IAChB,cAAc;QAAC0C;QAAYC;QAAiBC;QAAeC;KAAoB;AACnF"}
|
|
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;QACA,IAAIE,aAAa,MAAM,IACnB,OAAOC,OAAO,IAAI,CAACD,aAAa,KAAK;QAEzC,MAAME,qBAAqBF,aAAa,KAAK;QAE7C,MAAMG,gBAAgB;YAClB,GAAGL,cAAc,MAAM;YACvB,GAAGM,4BAAqCR,OAAOC,SAAS,MAAM,CAAC;QACnE;QAEA,MAAMQ,WAAW,IAAI,CAAC,mBAAmB,CA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GAAGlC,aAAa;YAChBf;YACA,SAAS8B;YACT,WAAWa,QAAQ7B,SAAS,SAAS,EAAEK,mBAAmB,SAAS;YACnE,SAASwB,QAAQ7B,SAAS,OAAO,EAAEkC,gBAAgB,OAAO;YAC1D,YAAYL,QAAQ7B,SAAS,UAAU,EAAEkC,gBAAgB,UAAU;YACnE,WAAWJ,YAAY9B,SAAS,SAAS,EAAEK,mBAAmB,SAAS;YACvE,SAASyB,YAAY9B,SAAS,OAAO,EAAEkC,gBAAgB,OAAO;YAC9D,YAAYJ,YAAY9B,SAAS,UAAU,EAAEkC,gBAAgB,UAAU;YACvE,GAAGH,8BAA8B;YACjC,mBAAmBF,QAAQ7B,SAAS,iBAAiB,EAAEkB;YACvD,iBAAiBW,QAAQ7B,SAAS,eAAe,EAAEkB;YACnD,oBAAoBW,QAAQ7B,SAAS,kBAAkB,EAAE;YACzD,mBAAmB8B,YAAY9B,SAAS,iBAAiB,EAAEiB;YAC3D,iBAAiBa,YAAY9B,SAAS,eAAe,EAAEiB;YACvD,oBAAoBa,YAAY9B,SAAS,kBAAkB,EAAE;YAC7D,qBAAqBoC;YACrB,GAAGR,iCAAiC;YACpCD;YACAP;YACAP;YACA,QAAQwB,UAAU;gBACd,OAAOrC;gBACP,UAAUC;YACd;YACA,MAAMA,cAAc,IAAI;YACxB,WAAW;QACf;QAEA,OAAOG,OAAO,EAAE,CAAC;YACb+B;YACA,OAAO;gBACH,GAAGnC,QAAQ;gBACX,QAAQsC,gBAAgBzB;YAC5B;QACJ;IACJ;AACJ;AAEO,MAAM0B,wEAAqCC,qBAAqB;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"}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CreatePublishEntryDataFactory as FactoryAbstraction, type ICreatePublishEntryDataFactory } from "./abstractions.js";
|
|
2
2
|
import { CmsContext } from "../../../../features/shared/abstractions.js";
|
|
3
3
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
4
4
|
import type { CmsEntry, CmsEntryValues, CmsModel } from "../../../../types/index.js";
|
|
5
|
+
import { GetLatestRevisionByEntryIdUseCase } from "../../../../features/contentEntry/GetLatestRevisionByEntryId/index.js";
|
|
5
6
|
declare class CreatePublishEntryDataFactoryImpl implements ICreatePublishEntryDataFactory {
|
|
6
7
|
private readonly cmsContext;
|
|
7
8
|
private readonly identityContext;
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
private readonly getLatestRevision;
|
|
10
|
+
constructor(cmsContext: CmsContext.Interface, identityContext: IdentityContext.Interface, getLatestRevision: GetLatestRevisionByEntryIdUseCase.Interface);
|
|
11
|
+
create<TValues extends CmsEntryValues = CmsEntryValues>(model: CmsModel, originalEntry: CmsEntry<TValues>): Promise<FactoryAbstraction.Return<TValues>>;
|
|
10
12
|
}
|
|
11
13
|
export declare const CreatePublishEntryDataFactory: import("@webiny/di").Implementation<typeof CreatePublishEntryDataFactoryImpl>;
|
|
12
14
|
export {};
|
|
@@ -1,23 +1,32 @@
|
|
|
1
|
-
import { createImplementation } from "@webiny/feature/api";
|
|
1
|
+
import { Result, createImplementation } from "@webiny/feature/api";
|
|
2
2
|
import { CreatePublishEntryDataFactory } from "./abstractions.js";
|
|
3
3
|
import { CmsContext } from "../../../shared/abstractions.js";
|
|
4
4
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
5
5
|
import { STATUS_PUBLISHED } from "../statuses.js";
|
|
6
|
-
import {
|
|
6
|
+
import { validateModelEntryData } from "../../../../crud/contentEntry/entryDataValidation.js";
|
|
7
|
+
import { EntryValidationError } from "../../../../domain/contentEntry/errors.js";
|
|
7
8
|
import { getIdentity } from "../../../../utils/identity.js";
|
|
8
9
|
import { getDate } from "../../../../utils/date.js";
|
|
10
|
+
import { GetLatestRevisionByEntryIdUseCase } from "../../GetLatestRevisionByEntryId/index.js";
|
|
9
11
|
class CreatePublishEntryDataFactoryImpl {
|
|
10
|
-
constructor(cmsContext, identityContext){
|
|
12
|
+
constructor(cmsContext, identityContext, getLatestRevision){
|
|
11
13
|
this.cmsContext = cmsContext;
|
|
12
14
|
this.identityContext = identityContext;
|
|
15
|
+
this.getLatestRevision = getLatestRevision;
|
|
13
16
|
}
|
|
14
|
-
async create(model, originalEntry
|
|
15
|
-
await
|
|
17
|
+
async create(model, originalEntry) {
|
|
18
|
+
const latestResult = await this.getLatestRevision.execute(model, {
|
|
19
|
+
id: originalEntry.entryId
|
|
20
|
+
});
|
|
21
|
+
if (latestResult.isFail()) return Result.fail(latestResult.error);
|
|
22
|
+
const latestEntry = latestResult.value;
|
|
23
|
+
const invalidFields = await validateModelEntryData({
|
|
16
24
|
context: this.cmsContext,
|
|
17
25
|
model,
|
|
18
26
|
values: originalEntry.values,
|
|
19
27
|
entry: originalEntry
|
|
20
28
|
});
|
|
29
|
+
if (invalidFields.length > 0) return Result.fail(new EntryValidationError("Validation failed.", invalidFields));
|
|
21
30
|
const currentDateTime = new Date().toISOString();
|
|
22
31
|
const currentIdentity = this.identityContext.getIdentity();
|
|
23
32
|
const entry = {
|
|
@@ -25,32 +34,28 @@ class CreatePublishEntryDataFactoryImpl {
|
|
|
25
34
|
status: STATUS_PUBLISHED,
|
|
26
35
|
locked: true,
|
|
27
36
|
createdOn: getDate(latestEntry.createdOn),
|
|
28
|
-
modifiedOn: getDate(
|
|
29
|
-
savedOn: getDate(
|
|
37
|
+
modifiedOn: getDate(latestEntry.modifiedOn),
|
|
38
|
+
savedOn: getDate(latestEntry.savedOn, originalEntry.savedOn),
|
|
30
39
|
firstPublishedOn: getDate(latestEntry.firstPublishedOn, currentDateTime),
|
|
31
40
|
lastPublishedOn: getDate(currentDateTime),
|
|
32
41
|
createdBy: getIdentity(latestEntry.createdBy),
|
|
33
|
-
modifiedBy: getIdentity(
|
|
34
|
-
savedBy: getIdentity(
|
|
42
|
+
modifiedBy: getIdentity(latestEntry.modifiedBy),
|
|
43
|
+
savedBy: getIdentity(latestEntry.savedBy, originalEntry.savedBy),
|
|
35
44
|
firstPublishedBy: getIdentity(latestEntry.firstPublishedBy, currentIdentity),
|
|
36
45
|
lastPublishedBy: getIdentity(currentIdentity),
|
|
37
46
|
revisionCreatedOn: getDate(originalEntry.revisionCreatedOn),
|
|
38
|
-
revisionSavedOn: getDate(currentDateTime),
|
|
39
|
-
revisionModifiedOn: getDate(currentDateTime),
|
|
40
47
|
revisionFirstPublishedOn: getDate(originalEntry.revisionFirstPublishedOn, currentDateTime),
|
|
41
48
|
revisionLastPublishedOn: getDate(currentDateTime),
|
|
42
49
|
revisionCreatedBy: getIdentity(originalEntry.revisionCreatedBy),
|
|
43
|
-
revisionSavedBy: getIdentity(currentIdentity),
|
|
44
|
-
revisionModifiedBy: getIdentity(currentIdentity),
|
|
45
50
|
revisionFirstPublishedBy: getIdentity(originalEntry.revisionFirstPublishedBy, currentIdentity),
|
|
46
51
|
revisionLastPublishedBy: getIdentity(currentIdentity),
|
|
47
52
|
live: {
|
|
48
53
|
version: originalEntry.version
|
|
49
54
|
}
|
|
50
55
|
};
|
|
51
|
-
return {
|
|
56
|
+
return Result.ok({
|
|
52
57
|
entry
|
|
53
|
-
};
|
|
58
|
+
});
|
|
54
59
|
}
|
|
55
60
|
}
|
|
56
61
|
const CreatePublishEntryDataFactory_CreatePublishEntryDataFactory = createImplementation({
|
|
@@ -58,7 +63,8 @@ const CreatePublishEntryDataFactory_CreatePublishEntryDataFactory = createImplem
|
|
|
58
63
|
implementation: CreatePublishEntryDataFactoryImpl,
|
|
59
64
|
dependencies: [
|
|
60
65
|
CmsContext,
|
|
61
|
-
IdentityContext
|
|
66
|
+
IdentityContext,
|
|
67
|
+
GetLatestRevisionByEntryIdUseCase
|
|
62
68
|
]
|
|
63
69
|
});
|
|
64
70
|
export { CreatePublishEntryDataFactory_CreatePublishEntryDataFactory as CreatePublishEntryDataFactory };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentEntry/entryDataFactories/CreatePublishEntryDataFactory/CreatePublishEntryDataFactory.js","sources":["../../../../../src/features/contentEntry/entryDataFactories/CreatePublishEntryDataFactory/CreatePublishEntryDataFactory.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport {\n CreatePublishEntryDataFactory as FactoryAbstraction,\n type ICreatePublishEntryDataFactory
|
|
1
|
+
{"version":3,"file":"features/contentEntry/entryDataFactories/CreatePublishEntryDataFactory/CreatePublishEntryDataFactory.js","sources":["../../../../../src/features/contentEntry/entryDataFactories/CreatePublishEntryDataFactory/CreatePublishEntryDataFactory.ts"],"sourcesContent":["import { createImplementation, Result } from \"@webiny/feature/api\";\nimport {\n CreatePublishEntryDataFactory as FactoryAbstraction,\n type ICreatePublishEntryDataFactory\n} from \"./abstractions.js\";\nimport { CmsContext } from \"~/features/shared/abstractions.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport type { CmsEntry, CmsEntryValues, CmsModel } from \"~/types/index.js\";\nimport { STATUS_PUBLISHED } from \"../statuses.js\";\nimport { validateModelEntryData } from \"~/crud/contentEntry/entryDataValidation.js\";\nimport { EntryValidationError } from \"~/domain/contentEntry/errors.js\";\nimport { getIdentity } from \"~/utils/identity.js\";\nimport { getDate } from \"~/utils/date.js\";\nimport { GetLatestRevisionByEntryIdUseCase } from \"~/features/contentEntry/GetLatestRevisionByEntryId/index.js\";\n\nclass CreatePublishEntryDataFactoryImpl implements ICreatePublishEntryDataFactory {\n public constructor(\n private readonly cmsContext: CmsContext.Interface,\n private readonly identityContext: IdentityContext.Interface,\n private readonly getLatestRevision: GetLatestRevisionByEntryIdUseCase.Interface\n ) {}\n\n public async create<TValues extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n originalEntry: CmsEntry<TValues>\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 latestEntry = latestResult.value;\n\n const invalidFields = await validateModelEntryData({\n context: this.cmsContext,\n model,\n values: originalEntry.values,\n entry: originalEntry\n });\n if (invalidFields.length > 0) {\n return Result.fail(new EntryValidationError(\"Validation failed.\", invalidFields));\n }\n\n const currentDateTime = new Date().toISOString();\n const currentIdentity = this.identityContext.getIdentity();\n\n /**\n * Publishing is not a content modification, so saved/modified meta fields are kept.\n * Entry-level values are taken from the latest revision, because storage copies them\n * onto the latest revision when a non-latest revision is published. Revision-level\n * values are the published revision's own, and come from `originalEntry`.\n */\n const entry: CmsEntry<TValues> = {\n ...originalEntry,\n status: STATUS_PUBLISHED,\n locked: true,\n createdOn: getDate(latestEntry.createdOn),\n modifiedOn: getDate(latestEntry.modifiedOn),\n savedOn: getDate(latestEntry.savedOn, originalEntry.savedOn),\n firstPublishedOn: getDate(latestEntry.firstPublishedOn, currentDateTime),\n lastPublishedOn: getDate(currentDateTime),\n createdBy: getIdentity(latestEntry.createdBy),\n modifiedBy: getIdentity(latestEntry.modifiedBy),\n savedBy: getIdentity(latestEntry.savedBy, originalEntry.savedBy),\n firstPublishedBy: getIdentity(latestEntry.firstPublishedBy, currentIdentity),\n lastPublishedBy: getIdentity(currentIdentity),\n revisionCreatedOn: getDate(originalEntry.revisionCreatedOn),\n revisionFirstPublishedOn: getDate(\n originalEntry.revisionFirstPublishedOn,\n currentDateTime\n ),\n revisionLastPublishedOn: getDate(currentDateTime),\n revisionCreatedBy: getIdentity(originalEntry.revisionCreatedBy),\n revisionFirstPublishedBy: getIdentity(\n originalEntry.revisionFirstPublishedBy,\n currentIdentity\n ),\n revisionLastPublishedBy: getIdentity(currentIdentity),\n live: {\n version: originalEntry.version\n }\n };\n\n return Result.ok({ entry });\n }\n}\n\nexport const CreatePublishEntryDataFactory = createImplementation({\n abstraction: FactoryAbstraction,\n implementation: CreatePublishEntryDataFactoryImpl,\n dependencies: [CmsContext, IdentityContext, GetLatestRevisionByEntryIdUseCase]\n});\n"],"names":["CreatePublishEntryDataFactoryImpl","cmsContext","identityContext","getLatestRevision","model","originalEntry","latestResult","Result","latestEntry","invalidFields","validateModelEntryData","EntryValidationError","currentDateTime","Date","currentIdentity","entry","STATUS_PUBLISHED","getDate","getIdentity","CreatePublishEntryDataFactory","createImplementation","FactoryAbstraction","CmsContext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BY,QACtBZ,cAAc,wBAAwB,EACtCO;YAEJ,yBAAyBK,QAAQL;YACjC,mBAAmBM,YAAYb,cAAc,iBAAiB;YAC9D,0BAA0Ba,YACtBb,cAAc,wBAAwB,EACtCS;YAEJ,yBAAyBI,YAAYJ;YACrC,MAAM;gBACF,SAAST,cAAc,OAAO;YAClC;QACJ;QAEA,OAAOE,OAAO,EAAE,CAAC;YAAEQ;QAAM;IAC7B;AACJ;AAEO,MAAMI,8DAAgCC,qBAAqB;IAC9D,aAAaC;IACb,gBAAgBrB;IAChB,cAAc;QAACsB;QAAYC;QAAiBC;KAAkC;AAClF"}
|
package/features/contentEntry/entryDataFactories/CreatePublishEntryDataFactory/abstractions.d.ts
CHANGED
|
@@ -1,12 +1,26 @@
|
|
|
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";
|
|
1
4
|
import type { CmsEntry, CmsEntryValues, CmsModel } from "../../../../types/index.js";
|
|
2
5
|
export interface ICreatePublishEntryDataResponse<TValues extends CmsEntryValues = CmsEntryValues> {
|
|
3
6
|
entry: CmsEntry<TValues>;
|
|
4
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* Expected failures of building the data of an entry being published.
|
|
10
|
+
*/
|
|
11
|
+
export interface ICreatePublishEntryDataFactoryErrors {
|
|
12
|
+
latest: GetLatestRevisionByEntryIdUseCase.Error;
|
|
13
|
+
validation: EntryValidationError;
|
|
14
|
+
}
|
|
15
|
+
type FactoryError = ICreatePublishEntryDataFactoryErrors[keyof ICreatePublishEntryDataFactoryErrors];
|
|
5
16
|
export interface ICreatePublishEntryDataFactory {
|
|
6
|
-
create<TValues extends CmsEntryValues = CmsEntryValues>(model: CmsModel, originalEntry: CmsEntry<TValues
|
|
17
|
+
create<TValues extends CmsEntryValues = CmsEntryValues>(model: CmsModel, originalEntry: CmsEntry<TValues>): Promise<Result<ICreatePublishEntryDataResponse<TValues>, FactoryError>>;
|
|
7
18
|
}
|
|
8
19
|
export declare const CreatePublishEntryDataFactory: import("@webiny/di").Abstraction<ICreatePublishEntryDataFactory>;
|
|
9
20
|
export declare namespace CreatePublishEntryDataFactory {
|
|
10
21
|
type Interface = ICreatePublishEntryDataFactory;
|
|
22
|
+
type Error = FactoryError;
|
|
23
|
+
type Return<TValues extends CmsEntryValues = CmsEntryValues> = Result<ICreatePublishEntryDataResponse<TValues>, FactoryError>;
|
|
11
24
|
type Response<TValues extends CmsEntryValues = CmsEntryValues> = ICreatePublishEntryDataResponse<TValues>;
|
|
12
25
|
}
|
|
26
|
+
export {};
|
package/features/contentEntry/entryDataFactories/CreatePublishEntryDataFactory/abstractions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentEntry/entryDataFactories/CreatePublishEntryDataFactory/abstractions.js","sources":["../../../../../src/features/contentEntry/entryDataFactories/CreatePublishEntryDataFactory/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { CmsEntry, CmsEntryValues, CmsModel } from \"~/types/index.js\";\n\nexport interface ICreatePublishEntryDataResponse<TValues extends CmsEntryValues = CmsEntryValues> {\n entry: CmsEntry<TValues>;\n}\n\nexport interface ICreatePublishEntryDataFactory {\n create<TValues extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n originalEntry: CmsEntry<TValues
|
|
1
|
+
{"version":3,"file":"features/contentEntry/entryDataFactories/CreatePublishEntryDataFactory/abstractions.js","sources":["../../../../../src/features/contentEntry/entryDataFactories/CreatePublishEntryDataFactory/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 { CmsEntry, CmsEntryValues, CmsModel } from \"~/types/index.js\";\n\nexport interface ICreatePublishEntryDataResponse<TValues extends CmsEntryValues = CmsEntryValues> {\n entry: CmsEntry<TValues>;\n}\n\n/**\n * Expected failures of building the data of an entry being published.\n */\nexport interface ICreatePublishEntryDataFactoryErrors {\n latest: GetLatestRevisionByEntryIdUseCase.Error;\n validation: EntryValidationError;\n}\n\ntype FactoryError =\n ICreatePublishEntryDataFactoryErrors[keyof ICreatePublishEntryDataFactoryErrors];\n\nexport interface ICreatePublishEntryDataFactory {\n create<TValues extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n originalEntry: CmsEntry<TValues>\n ): Promise<Result<ICreatePublishEntryDataResponse<TValues>, FactoryError>>;\n}\n\nexport const CreatePublishEntryDataFactory = createAbstraction<ICreatePublishEntryDataFactory>(\n \"Cms/Entry/CreatePublishEntryDataFactory\"\n);\n\nexport namespace CreatePublishEntryDataFactory {\n export type Interface = ICreatePublishEntryDataFactory;\n export type Error = FactoryError;\n export type Return<TValues extends CmsEntryValues = CmsEntryValues> = Result<\n ICreatePublishEntryDataResponse<TValues>,\n FactoryError\n >;\n export type Response<TValues extends CmsEntryValues = CmsEntryValues> =\n ICreatePublishEntryDataResponse<TValues>;\n}\n"],"names":["CreatePublishEntryDataFactory","createAbstraction"],"mappings":";AA2BO,MAAMA,gCAAgCC,kBACzC"}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CreateRepublishEntryDataFactory as FactoryAbstraction, type ICreateRepublishEntryDataFactory } from "./abstractions.js";
|
|
2
2
|
import { CmsContext } from "../../../../features/shared/abstractions.js";
|
|
3
3
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
4
4
|
import type { CmsEntry, CmsEntryValues, CmsModel } from "../../../../types/index.js";
|
|
5
|
+
import { GetLatestRevisionByEntryIdUseCase } from "../../../../features/contentEntry/GetLatestRevisionByEntryId/index.js";
|
|
5
6
|
declare class CreateRepublishEntryDataFactoryImpl implements ICreateRepublishEntryDataFactory {
|
|
6
7
|
private readonly cmsContext;
|
|
7
8
|
private readonly identityContext;
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
private readonly getLatestRevision;
|
|
10
|
+
constructor(cmsContext: CmsContext.Interface, identityContext: IdentityContext.Interface, getLatestRevision: GetLatestRevisionByEntryIdUseCase.Interface);
|
|
11
|
+
create<TValues extends CmsEntryValues = CmsEntryValues>(model: CmsModel, originalEntry: CmsEntry<TValues>): Promise<FactoryAbstraction.Return<TValues>>;
|
|
10
12
|
}
|
|
11
13
|
export declare const CreateRepublishEntryDataFactory: import("@webiny/di").Implementation<typeof CreateRepublishEntryDataFactoryImpl>;
|
|
12
14
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createImplementation } from "@webiny/feature/api";
|
|
1
|
+
import { Result, createImplementation } from "@webiny/feature/api";
|
|
2
2
|
import { CreateRepublishEntryDataFactory } from "./abstractions.js";
|
|
3
3
|
import { CmsContext } from "../../../shared/abstractions.js";
|
|
4
4
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
@@ -6,12 +6,19 @@ import { referenceFieldsMapping } from "../../../../crud/contentEntry/referenceF
|
|
|
6
6
|
import { STATUS_PUBLISHED } from "../statuses.js";
|
|
7
7
|
import { getIdentity } from "../../../../utils/identity.js";
|
|
8
8
|
import { getDate } from "../../../../utils/date.js";
|
|
9
|
+
import { GetLatestRevisionByEntryIdUseCase } from "../../GetLatestRevisionByEntryId/index.js";
|
|
9
10
|
class CreateRepublishEntryDataFactoryImpl {
|
|
10
|
-
constructor(cmsContext, identityContext){
|
|
11
|
+
constructor(cmsContext, identityContext, getLatestRevision){
|
|
11
12
|
this.cmsContext = cmsContext;
|
|
12
13
|
this.identityContext = identityContext;
|
|
14
|
+
this.getLatestRevision = getLatestRevision;
|
|
13
15
|
}
|
|
14
16
|
async create(model, originalEntry) {
|
|
17
|
+
const latestResult = await this.getLatestRevision.execute(model, {
|
|
18
|
+
id: originalEntry.entryId
|
|
19
|
+
});
|
|
20
|
+
if (latestResult.isFail()) return Result.fail(latestResult.error);
|
|
21
|
+
const latestEntry = latestResult.value;
|
|
15
22
|
const values = await referenceFieldsMapping({
|
|
16
23
|
context: this.cmsContext,
|
|
17
24
|
model,
|
|
@@ -23,18 +30,14 @@ class CreateRepublishEntryDataFactoryImpl {
|
|
|
23
30
|
const entry = {
|
|
24
31
|
...originalEntry,
|
|
25
32
|
status: STATUS_PUBLISHED,
|
|
26
|
-
savedOn: getDate(
|
|
27
|
-
modifiedOn: getDate(
|
|
28
|
-
savedBy: getIdentity(
|
|
29
|
-
modifiedBy: getIdentity(
|
|
33
|
+
savedOn: getDate(latestEntry.savedOn, originalEntry.savedOn),
|
|
34
|
+
modifiedOn: getDate(latestEntry.modifiedOn),
|
|
35
|
+
savedBy: getIdentity(latestEntry.savedBy, originalEntry.savedBy),
|
|
36
|
+
modifiedBy: getIdentity(latestEntry.modifiedBy),
|
|
30
37
|
firstPublishedOn: getDate(originalEntry.firstPublishedOn, currentDateTime),
|
|
31
38
|
firstPublishedBy: getIdentity(originalEntry.firstPublishedBy, currentIdentity),
|
|
32
39
|
lastPublishedOn: getDate(currentDateTime),
|
|
33
40
|
lastPublishedBy: getIdentity(currentIdentity),
|
|
34
|
-
revisionSavedOn: getDate(currentDateTime),
|
|
35
|
-
revisionModifiedOn: getDate(currentDateTime),
|
|
36
|
-
revisionSavedBy: getIdentity(currentIdentity),
|
|
37
|
-
revisionModifiedBy: getIdentity(currentIdentity),
|
|
38
41
|
revisionFirstPublishedOn: getDate(originalEntry.revisionFirstPublishedOn, currentDateTime),
|
|
39
42
|
revisionFirstPublishedBy: getIdentity(originalEntry.revisionFirstPublishedBy, currentIdentity),
|
|
40
43
|
revisionLastPublishedOn: getDate(currentDateTime),
|
|
@@ -44,9 +47,9 @@ class CreateRepublishEntryDataFactoryImpl {
|
|
|
44
47
|
version: originalEntry.version
|
|
45
48
|
}
|
|
46
49
|
};
|
|
47
|
-
return {
|
|
50
|
+
return Result.ok({
|
|
48
51
|
entry
|
|
49
|
-
};
|
|
52
|
+
});
|
|
50
53
|
}
|
|
51
54
|
}
|
|
52
55
|
const CreateRepublishEntryDataFactory_CreateRepublishEntryDataFactory = createImplementation({
|
|
@@ -54,7 +57,8 @@ const CreateRepublishEntryDataFactory_CreateRepublishEntryDataFactory = createIm
|
|
|
54
57
|
implementation: CreateRepublishEntryDataFactoryImpl,
|
|
55
58
|
dependencies: [
|
|
56
59
|
CmsContext,
|
|
57
|
-
IdentityContext
|
|
60
|
+
IdentityContext,
|
|
61
|
+
GetLatestRevisionByEntryIdUseCase
|
|
58
62
|
]
|
|
59
63
|
});
|
|
60
64
|
export { CreateRepublishEntryDataFactory_CreateRepublishEntryDataFactory as CreateRepublishEntryDataFactory };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentEntry/entryDataFactories/CreateRepublishEntryDataFactory/CreateRepublishEntryDataFactory.js","sources":["../../../../../src/features/contentEntry/entryDataFactories/CreateRepublishEntryDataFactory/CreateRepublishEntryDataFactory.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport {\n CreateRepublishEntryDataFactory as FactoryAbstraction,\n type ICreateRepublishEntryDataFactory
|
|
1
|
+
{"version":3,"file":"features/contentEntry/entryDataFactories/CreateRepublishEntryDataFactory/CreateRepublishEntryDataFactory.js","sources":["../../../../../src/features/contentEntry/entryDataFactories/CreateRepublishEntryDataFactory/CreateRepublishEntryDataFactory.ts"],"sourcesContent":["import { createImplementation, Result } from \"@webiny/feature/api\";\nimport {\n CreateRepublishEntryDataFactory as FactoryAbstraction,\n type ICreateRepublishEntryDataFactory\n} from \"./abstractions.js\";\nimport { CmsContext } from \"~/features/shared/abstractions.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport type { CmsEntry, CmsEntryValues, CmsModel } from \"~/types/index.js\";\nimport { referenceFieldsMapping } from \"~/crud/contentEntry/referenceFieldsMapping.js\";\nimport { STATUS_PUBLISHED } from \"../statuses.js\";\nimport { getIdentity } from \"~/utils/identity.js\";\nimport { getDate } from \"~/utils/date.js\";\nimport { GetLatestRevisionByEntryIdUseCase } from \"~/features/contentEntry/GetLatestRevisionByEntryId/index.js\";\n\nclass CreateRepublishEntryDataFactoryImpl implements ICreateRepublishEntryDataFactory {\n public constructor(\n private readonly cmsContext: CmsContext.Interface,\n private readonly identityContext: IdentityContext.Interface,\n private readonly getLatestRevision: GetLatestRevisionByEntryIdUseCase.Interface\n ) {}\n\n public async create<TValues extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n originalEntry: CmsEntry<TValues>\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 latestEntry = latestResult.value;\n\n const values = await referenceFieldsMapping<TValues>({\n context: this.cmsContext,\n model,\n values: originalEntry.values,\n validateEntries: false\n });\n\n const currentDateTime = new Date().toISOString();\n const currentIdentity = this.identityContext.getIdentity();\n\n /**\n * Republishing is not a content modification, so saved/modified meta fields are kept.\n * Entry-level values are taken from the latest revision, because storage copies them\n * onto the latest revision when a non-latest revision is republished. Revision-level\n * values are the republished revision's own, and come from `originalEntry`.\n */\n const entry: CmsEntry<TValues> = {\n ...originalEntry,\n status: STATUS_PUBLISHED,\n savedOn: getDate(latestEntry.savedOn, originalEntry.savedOn),\n modifiedOn: getDate(latestEntry.modifiedOn),\n savedBy: getIdentity(latestEntry.savedBy, originalEntry.savedBy),\n modifiedBy: getIdentity(latestEntry.modifiedBy),\n firstPublishedOn: getDate(originalEntry.firstPublishedOn, currentDateTime),\n firstPublishedBy: getIdentity(originalEntry.firstPublishedBy, currentIdentity),\n lastPublishedOn: getDate(currentDateTime),\n lastPublishedBy: getIdentity(currentIdentity),\n revisionFirstPublishedOn: getDate(\n originalEntry.revisionFirstPublishedOn,\n currentDateTime\n ),\n revisionFirstPublishedBy: getIdentity(\n originalEntry.revisionFirstPublishedBy,\n currentIdentity\n ),\n revisionLastPublishedOn: getDate(currentDateTime),\n revisionLastPublishedBy: getIdentity(currentIdentity),\n values,\n live: {\n version: originalEntry.version\n }\n };\n\n return Result.ok({ entry });\n }\n}\n\nexport const CreateRepublishEntryDataFactory = createImplementation({\n abstraction: FactoryAbstraction,\n implementation: CreateRepublishEntryDataFactoryImpl,\n dependencies: [CmsContext, IdentityContext, GetLatestRevisionByEntryIdUseCase]\n});\n"],"names":["CreateRepublishEntryDataFactoryImpl","cmsContext","identityContext","getLatestRevision","model","originalEntry","latestResult","Result","latestEntry","values","referenceFieldsMapping","currentDateTime","Date","currentIdentity","entry","STATUS_PUBLISHED","getDate","getIdentity","CreateRepublishEntryDataFactory","createImplementation","FactoryAbstraction","CmsContext","IdentityContext","GetLatestRevisionByEntryIdUseCase"],"mappings":";;;;;;;;;AAcA,MAAMA;IACF,YACqBC,UAAgC,EAChCC,eAA0C,EAC1CC,iBAA8D,CACjF;aAHmBF,UAAU,GAAVA;aACAC,eAAe,GAAfA;aACAC,iBAAiB,GAAjBA;IAClB;IAEH,MAAa,OACTC,KAAe,EACfC,aAAgC,EACW;QAC3C,MAAMC,eAAe,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAUF,OAAO;YACtE,IAAIC,cAAc,OAAO;QAC7B;QACA,IAAIC,aAAa,MAAM,IACnB,OAAOC,OAAO,IAAI,CAACD,aAAa,KAAK;QAEzC,MAAME,cAAcF,aAAa,KAAK;QAEtC,MAAMG,SAAS,MAAMC,uBAAgC;YACjD,SAAS,IAAI,CAAC,UAAU;YACxBN;YACA,QAAQC,cAAc,MAAM;YAC5B,iBAAiB;QACrB;QAEA,MAAMM,kBAAkB,IAAIC,OAAO,WAAW;QAC9C,MAAMC,kBAAkB,IAAI,CAAC,eAAe,CAAC,WAAW;QAQxD,MAAMC,QAA2B;YAC7B,GAAGT,aAAa;YAChB,QAAQU;YACR,SAASC,QAAQR,YAAY,OAAO,EAAEH,cAAc,OAAO;YAC3D,YAAYW,QAAQR,YAAY,UAAU;YAC1C,SAASS,YAAYT,YAAY,OAAO,EAAEH,cAAc,OAAO;YAC/D,YAAYY,YAAYT,YAAY,UAAU;YAC9C,kBAAkBQ,QAAQX,cAAc,gBAAgB,EAAEM;YAC1D,kBAAkBM,YAAYZ,cAAc,gBAAgB,EAAEQ;YAC9D,iBAAiBG,QAAQL;YACzB,iBAAiBM,YAAYJ;YAC7B,0BAA0BG,QACtBX,cAAc,wBAAwB,EACtCM;YAEJ,0BAA0BM,YACtBZ,cAAc,wBAAwB,EACtCQ;YAEJ,yBAAyBG,QAAQL;YACjC,yBAAyBM,YAAYJ;YACrCJ;YACA,MAAM;gBACF,SAASJ,cAAc,OAAO;YAClC;QACJ;QAEA,OAAOE,OAAO,EAAE,CAAC;YAAEO;QAAM;IAC7B;AACJ;AAEO,MAAMI,kEAAkCC,qBAAqB;IAChE,aAAaC;IACb,gBAAgBpB;IAChB,cAAc;QAACqB;QAAYC;QAAiBC;KAAkC;AAClF"}
|
package/features/contentEntry/entryDataFactories/CreateRepublishEntryDataFactory/abstractions.d.ts
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
|
+
import { type Result } from "@webiny/feature/api";
|
|
2
|
+
import type { GetLatestRevisionByEntryIdUseCase } from "../../../../features/contentEntry/GetLatestRevisionByEntryId/index.js";
|
|
1
3
|
import type { CmsEntry, CmsEntryValues, CmsModel } from "../../../../types/index.js";
|
|
2
4
|
export interface ICreateRepublishEntryDataResponse<TValues extends CmsEntryValues = CmsEntryValues> {
|
|
3
5
|
entry: CmsEntry<TValues>;
|
|
4
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Expected failures of building the data of an entry being republished.
|
|
9
|
+
*/
|
|
10
|
+
export interface ICreateRepublishEntryDataFactoryErrors {
|
|
11
|
+
latest: GetLatestRevisionByEntryIdUseCase.Error;
|
|
12
|
+
}
|
|
13
|
+
type FactoryError = ICreateRepublishEntryDataFactoryErrors[keyof ICreateRepublishEntryDataFactoryErrors];
|
|
5
14
|
export interface ICreateRepublishEntryDataFactory {
|
|
6
|
-
create<TValues extends CmsEntryValues = CmsEntryValues>(model: CmsModel, originalEntry: CmsEntry<TValues>): Promise<ICreateRepublishEntryDataResponse<TValues>>;
|
|
15
|
+
create<TValues extends CmsEntryValues = CmsEntryValues>(model: CmsModel, originalEntry: CmsEntry<TValues>): Promise<Result<ICreateRepublishEntryDataResponse<TValues>, FactoryError>>;
|
|
7
16
|
}
|
|
8
17
|
export declare const CreateRepublishEntryDataFactory: import("@webiny/di").Abstraction<ICreateRepublishEntryDataFactory>;
|
|
9
18
|
export declare namespace CreateRepublishEntryDataFactory {
|
|
10
19
|
type Interface = ICreateRepublishEntryDataFactory;
|
|
20
|
+
type Error = FactoryError;
|
|
21
|
+
type Return<TValues extends CmsEntryValues = CmsEntryValues> = Result<ICreateRepublishEntryDataResponse<TValues>, FactoryError>;
|
|
11
22
|
type Response<TValues extends CmsEntryValues = CmsEntryValues> = ICreateRepublishEntryDataResponse<TValues>;
|
|
12
23
|
}
|
|
24
|
+
export {};
|
package/features/contentEntry/entryDataFactories/CreateRepublishEntryDataFactory/abstractions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentEntry/entryDataFactories/CreateRepublishEntryDataFactory/abstractions.js","sources":["../../../../../src/features/contentEntry/entryDataFactories/CreateRepublishEntryDataFactory/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { CmsEntry, CmsEntryValues, CmsModel } from \"~/types/index.js\";\n\nexport interface ICreateRepublishEntryDataResponse<\n TValues extends CmsEntryValues = CmsEntryValues\n> {\n entry: CmsEntry<TValues>;\n}\n\nexport interface ICreateRepublishEntryDataFactory {\n create<TValues extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n originalEntry: CmsEntry<TValues>\n ): Promise<ICreateRepublishEntryDataResponse<TValues>>;\n}\n\nexport const CreateRepublishEntryDataFactory = createAbstraction<ICreateRepublishEntryDataFactory>(\n \"Cms/Entry/CreateRepublishEntryDataFactory\"\n);\n\nexport namespace CreateRepublishEntryDataFactory {\n export type Interface = ICreateRepublishEntryDataFactory;\n export type Response<TValues extends CmsEntryValues = CmsEntryValues> =\n ICreateRepublishEntryDataResponse<TValues>;\n}\n"],"names":["CreateRepublishEntryDataFactory","createAbstraction"],"mappings":";
|
|
1
|
+
{"version":3,"file":"features/contentEntry/entryDataFactories/CreateRepublishEntryDataFactory/abstractions.js","sources":["../../../../../src/features/contentEntry/entryDataFactories/CreateRepublishEntryDataFactory/abstractions.ts"],"sourcesContent":["import { createAbstraction, type Result } from \"@webiny/feature/api\";\nimport type { GetLatestRevisionByEntryIdUseCase } from \"~/features/contentEntry/GetLatestRevisionByEntryId/index.js\";\nimport type { CmsEntry, CmsEntryValues, CmsModel } from \"~/types/index.js\";\n\nexport interface ICreateRepublishEntryDataResponse<\n TValues extends CmsEntryValues = CmsEntryValues\n> {\n entry: CmsEntry<TValues>;\n}\n\n/**\n * Expected failures of building the data of an entry being republished.\n */\nexport interface ICreateRepublishEntryDataFactoryErrors {\n latest: GetLatestRevisionByEntryIdUseCase.Error;\n}\n\ntype FactoryError =\n ICreateRepublishEntryDataFactoryErrors[keyof ICreateRepublishEntryDataFactoryErrors];\n\nexport interface ICreateRepublishEntryDataFactory {\n create<TValues extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n originalEntry: CmsEntry<TValues>\n ): Promise<Result<ICreateRepublishEntryDataResponse<TValues>, FactoryError>>;\n}\n\nexport const CreateRepublishEntryDataFactory = createAbstraction<ICreateRepublishEntryDataFactory>(\n \"Cms/Entry/CreateRepublishEntryDataFactory\"\n);\n\nexport namespace CreateRepublishEntryDataFactory {\n export type Interface = ICreateRepublishEntryDataFactory;\n export type Error = FactoryError;\n export type Return<TValues extends CmsEntryValues = CmsEntryValues> = Result<\n ICreateRepublishEntryDataResponse<TValues>,\n FactoryError\n >;\n export type Response<TValues extends CmsEntryValues = CmsEntryValues> =\n ICreateRepublishEntryDataResponse<TValues>;\n}\n"],"names":["CreateRepublishEntryDataFactory","createAbstraction"],"mappings":";AA2BO,MAAMA,kCAAkCC,kBAC3C"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import { CreateUnpublishEntryDataFactory as FactoryAbstraction, type ICreateUnpublishEntryDataFactory } from "./abstractions.js";
|
|
2
|
+
import type { CmsEntry, CmsEntryValues, CmsModel } from "../../../../types/index.js";
|
|
3
|
+
import { GetLatestRevisionByEntryIdUseCase } from "../../../../features/contentEntry/GetLatestRevisionByEntryId/index.js";
|
|
4
4
|
declare class CreateUnpublishEntryDataFactoryImpl implements ICreateUnpublishEntryDataFactory {
|
|
5
|
-
private readonly
|
|
6
|
-
constructor(
|
|
7
|
-
create<TValues extends CmsEntryValues = CmsEntryValues>(originalEntry: CmsEntry<TValues>): Promise<
|
|
5
|
+
private readonly getLatestRevision;
|
|
6
|
+
constructor(getLatestRevision: GetLatestRevisionByEntryIdUseCase.Interface);
|
|
7
|
+
create<TValues extends CmsEntryValues = CmsEntryValues>(model: CmsModel, originalEntry: CmsEntry<TValues>): Promise<FactoryAbstraction.Return<TValues>>;
|
|
8
8
|
}
|
|
9
9
|
export declare const CreateUnpublishEntryDataFactory: import("@webiny/di").Implementation<typeof CreateUnpublishEntryDataFactoryImpl>;
|
|
10
10
|
export {};
|
|
@@ -1,39 +1,38 @@
|
|
|
1
|
-
import { createImplementation } from "@webiny/feature/api";
|
|
1
|
+
import { Result, createImplementation } from "@webiny/feature/api";
|
|
2
2
|
import { CreateUnpublishEntryDataFactory } from "./abstractions.js";
|
|
3
|
-
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
4
3
|
import { STATUS_UNPUBLISHED } from "../statuses.js";
|
|
5
4
|
import { getIdentity } from "../../../../utils/identity.js";
|
|
6
5
|
import { getDate } from "../../../../utils/date.js";
|
|
6
|
+
import { GetLatestRevisionByEntryIdUseCase } from "../../GetLatestRevisionByEntryId/index.js";
|
|
7
7
|
class CreateUnpublishEntryDataFactoryImpl {
|
|
8
|
-
constructor(
|
|
9
|
-
this.
|
|
8
|
+
constructor(getLatestRevision){
|
|
9
|
+
this.getLatestRevision = getLatestRevision;
|
|
10
10
|
}
|
|
11
|
-
async create(originalEntry) {
|
|
12
|
-
const
|
|
13
|
-
|
|
11
|
+
async create(model, originalEntry) {
|
|
12
|
+
const latestResult = await this.getLatestRevision.execute(model, {
|
|
13
|
+
id: originalEntry.entryId
|
|
14
|
+
});
|
|
15
|
+
if (latestResult.isFail()) return Result.fail(latestResult.error);
|
|
16
|
+
const latestEntry = latestResult.value;
|
|
14
17
|
const entry = {
|
|
15
18
|
...originalEntry,
|
|
16
19
|
status: STATUS_UNPUBLISHED,
|
|
17
|
-
savedOn: getDate(
|
|
18
|
-
modifiedOn: getDate(
|
|
19
|
-
savedBy: getIdentity(
|
|
20
|
-
modifiedBy: getIdentity(
|
|
21
|
-
revisionSavedOn: getDate(currentDateTime),
|
|
22
|
-
revisionModifiedOn: getDate(currentDateTime),
|
|
23
|
-
revisionSavedBy: getIdentity(currentIdentity),
|
|
24
|
-
revisionModifiedBy: getIdentity(currentIdentity),
|
|
20
|
+
savedOn: getDate(latestEntry.savedOn, originalEntry.savedOn),
|
|
21
|
+
modifiedOn: getDate(latestEntry.modifiedOn),
|
|
22
|
+
savedBy: getIdentity(latestEntry.savedBy, originalEntry.savedBy),
|
|
23
|
+
modifiedBy: getIdentity(latestEntry.modifiedBy),
|
|
25
24
|
live: null
|
|
26
25
|
};
|
|
27
|
-
return {
|
|
26
|
+
return Result.ok({
|
|
28
27
|
entry
|
|
29
|
-
};
|
|
28
|
+
});
|
|
30
29
|
}
|
|
31
30
|
}
|
|
32
31
|
const CreateUnpublishEntryDataFactory_CreateUnpublishEntryDataFactory = createImplementation({
|
|
33
32
|
abstraction: CreateUnpublishEntryDataFactory,
|
|
34
33
|
implementation: CreateUnpublishEntryDataFactoryImpl,
|
|
35
34
|
dependencies: [
|
|
36
|
-
|
|
35
|
+
GetLatestRevisionByEntryIdUseCase
|
|
37
36
|
]
|
|
38
37
|
});
|
|
39
38
|
export { CreateUnpublishEntryDataFactory_CreateUnpublishEntryDataFactory as CreateUnpublishEntryDataFactory };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentEntry/entryDataFactories/CreateUnpublishEntryDataFactory/CreateUnpublishEntryDataFactory.js","sources":["../../../../../src/features/contentEntry/entryDataFactories/CreateUnpublishEntryDataFactory/CreateUnpublishEntryDataFactory.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport {\n CreateUnpublishEntryDataFactory as FactoryAbstraction,\n type ICreateUnpublishEntryDataFactory
|
|
1
|
+
{"version":3,"file":"features/contentEntry/entryDataFactories/CreateUnpublishEntryDataFactory/CreateUnpublishEntryDataFactory.js","sources":["../../../../../src/features/contentEntry/entryDataFactories/CreateUnpublishEntryDataFactory/CreateUnpublishEntryDataFactory.ts"],"sourcesContent":["import { createImplementation, Result } from \"@webiny/feature/api\";\nimport {\n CreateUnpublishEntryDataFactory as FactoryAbstraction,\n type ICreateUnpublishEntryDataFactory\n} from \"./abstractions.js\";\nimport type { CmsEntry, CmsEntryValues, CmsModel } from \"~/types/index.js\";\nimport { STATUS_UNPUBLISHED } from \"../statuses.js\";\nimport { getIdentity } from \"~/utils/identity.js\";\nimport { getDate } from \"~/utils/date.js\";\nimport { GetLatestRevisionByEntryIdUseCase } from \"~/features/contentEntry/GetLatestRevisionByEntryId/index.js\";\n\nclass CreateUnpublishEntryDataFactoryImpl implements ICreateUnpublishEntryDataFactory {\n public constructor(\n private readonly getLatestRevision: GetLatestRevisionByEntryIdUseCase.Interface\n ) {}\n\n public async create<TValues extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n originalEntry: CmsEntry<TValues>\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 latestEntry = latestResult.value;\n\n /**\n * Unpublishing is not a content modification, so saved/modified meta fields are kept.\n * Entry-level values are taken from the latest revision, because storage copies them\n * onto the latest revision when a non-latest revision is unpublished. Revision-level\n * values are the unpublished revision's own, and come from `originalEntry`.\n */\n const entry: CmsEntry<TValues> = {\n ...originalEntry,\n status: STATUS_UNPUBLISHED,\n savedOn: getDate(latestEntry.savedOn, originalEntry.savedOn),\n modifiedOn: getDate(latestEntry.modifiedOn),\n savedBy: getIdentity(latestEntry.savedBy, originalEntry.savedBy),\n modifiedBy: getIdentity(latestEntry.modifiedBy),\n live: null\n };\n\n return Result.ok({ entry });\n }\n}\n\nexport const CreateUnpublishEntryDataFactory = createImplementation({\n abstraction: FactoryAbstraction,\n implementation: CreateUnpublishEntryDataFactoryImpl,\n dependencies: [GetLatestRevisionByEntryIdUseCase]\n});\n"],"names":["CreateUnpublishEntryDataFactoryImpl","getLatestRevision","model","originalEntry","latestResult","Result","latestEntry","entry","STATUS_UNPUBLISHED","getDate","getIdentity","CreateUnpublishEntryDataFactory","createImplementation","FactoryAbstraction","GetLatestRevisionByEntryIdUseCase"],"mappings":";;;;;;AAWA,MAAMA;IACF,YACqBC,iBAA8D,CACjF;aADmBA,iBAAiB,GAAjBA;IAClB;IAEH,MAAa,OACTC,KAAe,EACfC,aAAgC,EACW;QAC3C,MAAMC,eAAe,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAUF,OAAO;YACtE,IAAIC,cAAc,OAAO;QAC7B;QACA,IAAIC,aAAa,MAAM,IACnB,OAAOC,OAAO,IAAI,CAACD,aAAa,KAAK;QAEzC,MAAME,cAAcF,aAAa,KAAK;QAQtC,MAAMG,QAA2B;YAC7B,GAAGJ,aAAa;YAChB,QAAQK;YACR,SAASC,QAAQH,YAAY,OAAO,EAAEH,cAAc,OAAO;YAC3D,YAAYM,QAAQH,YAAY,UAAU;YAC1C,SAASI,YAAYJ,YAAY,OAAO,EAAEH,cAAc,OAAO;YAC/D,YAAYO,YAAYJ,YAAY,UAAU;YAC9C,MAAM;QACV;QAEA,OAAOD,OAAO,EAAE,CAAC;YAAEE;QAAM;IAC7B;AACJ;AAEO,MAAMI,kEAAkCC,qBAAqB;IAChE,aAAaC;IACb,gBAAgBb;IAChB,cAAc;QAACc;KAAkC;AACrD"}
|
package/features/contentEntry/entryDataFactories/CreateUnpublishEntryDataFactory/abstractions.d.ts
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type Result } from "@webiny/feature/api";
|
|
2
|
+
import type { GetLatestRevisionByEntryIdUseCase } from "../../../../features/contentEntry/GetLatestRevisionByEntryId/index.js";
|
|
3
|
+
import type { CmsEntry, CmsEntryValues, CmsModel } from "../../../../types/index.js";
|
|
2
4
|
export interface ICreateUnpublishEntryDataResponse<TValues extends CmsEntryValues = CmsEntryValues> {
|
|
3
5
|
entry: CmsEntry<TValues>;
|
|
4
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Expected failures of building the data of an entry being unpublished.
|
|
9
|
+
*/
|
|
10
|
+
export interface ICreateUnpublishEntryDataFactoryErrors {
|
|
11
|
+
latest: GetLatestRevisionByEntryIdUseCase.Error;
|
|
12
|
+
}
|
|
13
|
+
type FactoryError = ICreateUnpublishEntryDataFactoryErrors[keyof ICreateUnpublishEntryDataFactoryErrors];
|
|
5
14
|
export interface ICreateUnpublishEntryDataFactory {
|
|
6
|
-
create<TValues extends CmsEntryValues = CmsEntryValues>(originalEntry: CmsEntry<TValues>): Promise<ICreateUnpublishEntryDataResponse<TValues>>;
|
|
15
|
+
create<TValues extends CmsEntryValues = CmsEntryValues>(model: CmsModel, originalEntry: CmsEntry<TValues>): Promise<Result<ICreateUnpublishEntryDataResponse<TValues>, FactoryError>>;
|
|
7
16
|
}
|
|
8
17
|
export declare const CreateUnpublishEntryDataFactory: import("@webiny/di").Abstraction<ICreateUnpublishEntryDataFactory>;
|
|
9
18
|
export declare namespace CreateUnpublishEntryDataFactory {
|
|
10
19
|
type Interface = ICreateUnpublishEntryDataFactory;
|
|
20
|
+
type Error = FactoryError;
|
|
21
|
+
type Return<TValues extends CmsEntryValues = CmsEntryValues> = Result<ICreateUnpublishEntryDataResponse<TValues>, FactoryError>;
|
|
11
22
|
type Response<TValues extends CmsEntryValues = CmsEntryValues> = ICreateUnpublishEntryDataResponse<TValues>;
|
|
12
23
|
}
|
|
24
|
+
export {};
|