@webiny/api-headless-cms 6.5.1 → 6.5.2-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/references/validateEntries.js +14 -4
- package/crud/contentEntry/references/validateEntries.js.map +1 -1
- package/features/contentEntry/GetEntriesByIds/GetEntriesByIdsUseCase.js +3 -1
- package/features/contentEntry/GetEntriesByIds/GetEntriesByIdsUseCase.js.map +1 -1
- package/features/contentEntry/GetLatestEntriesByIds/GetLatestEntriesByIdsUseCase.js +3 -1
- package/features/contentEntry/GetLatestEntriesByIds/GetLatestEntriesByIdsUseCase.js.map +1 -1
- package/features/contentEntry/GetLatestRevisionByEntryId/BaseUseCase.js +5 -1
- package/features/contentEntry/GetLatestRevisionByEntryId/BaseUseCase.js.map +1 -1
- package/features/contentEntry/GetPreviousRevisionByEntryId/BaseUseCase.js +5 -1
- package/features/contentEntry/GetPreviousRevisionByEntryId/BaseUseCase.js.map +1 -1
- package/features/contentEntry/GetPublishedEntriesByIds/GetPublishedEntriesByIdsUseCase.js +3 -1
- package/features/contentEntry/GetPublishedEntriesByIds/GetPublishedEntriesByIdsUseCase.js.map +1 -1
- package/features/contentEntry/GetPublishedRevisionByEntryId/GetPublishedRevisionByEntryIdUseCase.d.ts +5 -1
- package/features/contentEntry/GetPublishedRevisionByEntryId/GetPublishedRevisionByEntryIdUseCase.js +16 -3
- package/features/contentEntry/GetPublishedRevisionByEntryId/GetPublishedRevisionByEntryIdUseCase.js.map +1 -1
- package/features/contentEntry/GetPublishedRevisionByEntryId/abstractions.d.ts +2 -1
- package/features/contentEntry/GetPublishedRevisionByEntryId/abstractions.js.map +1 -1
- package/features/contentEntry/GetRevisionById/GetRevisionByIdUseCase.d.ts +7 -2
- package/features/contentEntry/GetRevisionById/GetRevisionByIdUseCase.js +18 -4
- package/features/contentEntry/GetRevisionById/GetRevisionByIdUseCase.js.map +1 -1
- package/features/contentEntry/GetRevisionById/abstractions.d.ts +4 -2
- package/features/contentEntry/GetRevisionById/abstractions.js.map +1 -1
- package/features/contentEntry/GetRevisionsByEntryId/GetRevisionsByEntryIdUseCase.js +3 -1
- package/features/contentEntry/GetRevisionsByEntryId/GetRevisionsByEntryIdUseCase.js.map +1 -1
- package/features/contentEntry/UpdateEntry/UpdateEntryUseCase.js +9 -6
- package/features/contentEntry/UpdateEntry/UpdateEntryUseCase.js.map +1 -1
- package/features/contentEntry/shared/entryOwnerAccess.d.ts +15 -0
- package/features/contentEntry/shared/entryOwnerAccess.js +21 -0
- package/features/contentEntry/shared/entryOwnerAccess.js.map +1 -0
- package/features/contentModel/CreateModelFrom/CreateModelFromUseCase.js +2 -1
- package/features/contentModel/CreateModelFrom/CreateModelFromUseCase.js.map +1 -1
- package/features/graphql/fields/base/RefToGraphQL.js +2 -0
- package/features/graphql/fields/base/RefToGraphQL.js.map +1 -1
- package/features/storage/fields/CompressedTextStorageTransform.js +2 -1
- package/features/storage/fields/CompressedTextStorageTransform.js.map +1 -1
- package/graphql/handleRequest.js +18 -9
- package/graphql/handleRequest.js.map +1 -1
- package/graphql/schema/cms/helpers/getModel.js +1 -1
- package/graphql/schema/cms/helpers/getModel.js.map +1 -1
- package/graphql/schema/contentEntries.js +15 -5
- package/graphql/schema/contentEntries.js.map +1 -1
- package/graphql/schema/contentModels.js +1 -1
- package/graphql/schema/contentModels.js.map +1 -1
- package/package.json +21 -21
|
@@ -15,11 +15,21 @@ const validateReferencedEntries = async ({ output, context, referenceFieldPaths
|
|
|
15
15
|
referencesByModel.set(result.modelId, refs);
|
|
16
16
|
}
|
|
17
17
|
if (0 === referencesByModel.size) return;
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
if (0 === entries.length) return false;
|
|
21
|
-
return true;
|
|
18
|
+
const allModels = await context.security.withoutAuthorization(async ()=>context.cms.listModels({
|
|
19
|
+
includePrivate: true
|
|
22
20
|
}));
|
|
21
|
+
for (const model of allModels){
|
|
22
|
+
if (!model.isPrivate) continue;
|
|
23
|
+
const [id] = referencesByModel.get(model.modelId) || [];
|
|
24
|
+
if (id) throw new WebinyError(`Missing referenced entry with id "${id}" in model "${model.modelId}".`, "ENTRY_NOT_FOUND", {
|
|
25
|
+
id,
|
|
26
|
+
model: model.modelId
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
const models = allModels.filter((model)=>{
|
|
30
|
+
const entries = referencesByModel.get(model.modelId) || [];
|
|
31
|
+
return entries.length > 0;
|
|
32
|
+
});
|
|
23
33
|
if (!models.length) return;
|
|
24
34
|
const promises = await context.security.withoutAuthorization(async ()=>models.map((model)=>context.cms.getEntriesByIds(model, referencesByModel.get(model.modelId) || [])));
|
|
25
35
|
const allEntries = await Promise.all(promises).then((res)=>res.flat());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crud/contentEntry/references/validateEntries.js","sources":["../../../../src/crud/contentEntry/references/validateEntries.ts"],"sourcesContent":["import type { CmsContext } from \"~/types/index.js\";\nimport dotPropImmutable from \"dot-prop-immutable\";\nimport { WebinyError } from \"@webiny/error\";\n\ninterface ReferenceObject {\n id: string;\n modelId: string;\n}\n\ninterface ValidateReferencedEntriesParams {\n output: Record<string, any>;\n context: Pick<CmsContext, \"cms\" | \"security\">;\n referenceFieldPaths: string[];\n}\n\nconst getReferenceFieldValue = (\n ref: Partial<ReferenceObject> | null | undefined\n): ReferenceObject | null => {\n if (!ref?.id || !ref.modelId) {\n return null;\n }\n return ref as ReferenceObject;\n};\n\nexport const validateReferencedEntries = async ({\n output,\n context,\n referenceFieldPaths\n}: ValidateReferencedEntriesParams) => {\n const referencesByModel = new Map<string, string[]>();\n\n /**\n * Group references by modelId.\n */\n for (const path of referenceFieldPaths) {\n const ref = dotPropImmutable.get(output, path) as ReferenceObject | any;\n\n const result = getReferenceFieldValue(ref);\n\n if (!result) {\n continue;\n }\n\n const refs = referencesByModel.get(result.modelId) || [];\n refs.push(result.id);\n referencesByModel.set(result.modelId, refs);\n }\n\n if (referencesByModel.size === 0) {\n return;\n }\n\n /**\n * Load all models and use only those that are used in reference.\n */\n const
|
|
1
|
+
{"version":3,"file":"crud/contentEntry/references/validateEntries.js","sources":["../../../../src/crud/contentEntry/references/validateEntries.ts"],"sourcesContent":["import type { CmsContext } from \"~/types/index.js\";\nimport dotPropImmutable from \"dot-prop-immutable\";\nimport { WebinyError } from \"@webiny/error\";\n\ninterface ReferenceObject {\n id: string;\n modelId: string;\n}\n\ninterface ValidateReferencedEntriesParams {\n output: Record<string, any>;\n context: Pick<CmsContext, \"cms\" | \"security\">;\n referenceFieldPaths: string[];\n}\n\nconst getReferenceFieldValue = (\n ref: Partial<ReferenceObject> | null | undefined\n): ReferenceObject | null => {\n if (!ref?.id || !ref.modelId) {\n return null;\n }\n return ref as ReferenceObject;\n};\n\nexport const validateReferencedEntries = async ({\n output,\n context,\n referenceFieldPaths\n}: ValidateReferencedEntriesParams) => {\n const referencesByModel = new Map<string, string[]>();\n\n /**\n * Group references by modelId.\n */\n for (const path of referenceFieldPaths) {\n const ref = dotPropImmutable.get(output, path) as ReferenceObject | any;\n\n const result = getReferenceFieldValue(ref);\n\n if (!result) {\n continue;\n }\n\n const refs = referencesByModel.get(result.modelId) || [];\n refs.push(result.id);\n referencesByModel.set(result.modelId, refs);\n }\n\n if (referencesByModel.size === 0) {\n return;\n }\n\n /**\n * Load all models and use only those that are used in reference.\n */\n const allModels = await context.security.withoutAuthorization(async () => {\n // Private models are included, so references to them can be refused below.\n return context.cms.listModels({ includePrivate: true });\n });\n\n /**\n * Private models are internal, so a reference to their entries fails as a missing entry.\n */\n for (const model of allModels) {\n if (!model.isPrivate) {\n continue;\n }\n const [id] = referencesByModel.get(model.modelId) || [];\n if (id) {\n throw new WebinyError(\n `Missing referenced entry with id \"${id}\" in model \"${model.modelId}\".`,\n \"ENTRY_NOT_FOUND\",\n {\n id,\n model: model.modelId\n }\n );\n }\n }\n\n const models = allModels.filter(model => {\n const entries = referencesByModel.get(model.modelId) || [];\n return entries.length > 0;\n });\n\n if (!models.length) {\n return;\n }\n\n /**\n * Load all the entries by their IDs.\n */\n const promises = await context.security.withoutAuthorization(async () => {\n return models.map(model => {\n return context.cms.getEntriesByIds(model, referencesByModel.get(model.modelId) || []);\n });\n });\n\n const allEntries = await Promise.all(promises).then(res => res.flat());\n const entriesByModel = allEntries.reduce<Record<string, string[]>>((acc, entry) => {\n return { ...acc, [entry.modelId]: [...(acc[entry.modelId] || []), entry.id] };\n }, {});\n\n /**\n * Verify that all entries exist.\n */\n referencesByModel.forEach((ids, modelId) => {\n const modelEntriesInDb = entriesByModel[modelId];\n for (const id of ids) {\n if (!modelEntriesInDb || !modelEntriesInDb.includes(id)) {\n throw new WebinyError(\n `Missing referenced entry with id \"${id}\" in model \"${modelId}\".`,\n \"ENTRY_NOT_FOUND\",\n {\n id,\n model: modelId\n }\n );\n }\n }\n });\n};\n"],"names":["getReferenceFieldValue","ref","validateReferencedEntries","output","context","referenceFieldPaths","referencesByModel","Map","path","dotPropImmutable","result","refs","allModels","model","id","WebinyError","models","entries","promises","allEntries","Promise","res","entriesByModel","acc","entry","ids","modelId","modelEntriesInDb"],"mappings":";;AAeA,MAAMA,yBAAyB,CAC3BC;IAEA,IAAI,CAACA,KAAK,MAAM,CAACA,IAAI,OAAO,EACxB,OAAO;IAEX,OAAOA;AACX;AAEO,MAAMC,4BAA4B,OAAO,EAC5CC,MAAM,EACNC,OAAO,EACPC,mBAAmB,EACW;IAC9B,MAAMC,oBAAoB,IAAIC;IAK9B,KAAK,MAAMC,QAAQH,oBAAqB;QACpC,MAAMJ,MAAMQ,mBAAAA,GAAoB,CAACN,QAAQK;QAEzC,MAAME,SAASV,uBAAuBC;QAEtC,IAAI,CAACS,QACD;QAGJ,MAAMC,OAAOL,kBAAkB,GAAG,CAACI,OAAO,OAAO,KAAK,EAAE;QACxDC,KAAK,IAAI,CAACD,OAAO,EAAE;QACnBJ,kBAAkB,GAAG,CAACI,OAAO,OAAO,EAAEC;IAC1C;IAEA,IAAIL,AAA2B,MAA3BA,kBAAkB,IAAI,EACtB;IAMJ,MAAMM,YAAY,MAAMR,QAAQ,QAAQ,CAAC,oBAAoB,CAAC,UAEnDA,QAAQ,GAAG,CAAC,UAAU,CAAC;YAAE,gBAAgB;QAAK;IAMzD,KAAK,MAAMS,SAASD,UAAW;QAC3B,IAAI,CAACC,MAAM,SAAS,EAChB;QAEJ,MAAM,CAACC,GAAG,GAAGR,kBAAkB,GAAG,CAACO,MAAM,OAAO,KAAK,EAAE;QACvD,IAAIC,IACA,MAAM,IAAIC,YACN,CAAC,kCAAkC,EAAED,GAAG,YAAY,EAAED,MAAM,OAAO,CAAC,EAAE,CAAC,EACvE,mBACA;YACIC;YACA,OAAOD,MAAM,OAAO;QACxB;IAGZ;IAEA,MAAMG,SAASJ,UAAU,MAAM,CAACC,CAAAA;QAC5B,MAAMI,UAAUX,kBAAkB,GAAG,CAACO,MAAM,OAAO,KAAK,EAAE;QAC1D,OAAOI,QAAQ,MAAM,GAAG;IAC5B;IAEA,IAAI,CAACD,OAAO,MAAM,EACd;IAMJ,MAAME,WAAW,MAAMd,QAAQ,QAAQ,CAAC,oBAAoB,CAAC,UAClDY,OAAO,GAAG,CAACH,CAAAA,QACPT,QAAQ,GAAG,CAAC,eAAe,CAACS,OAAOP,kBAAkB,GAAG,CAACO,MAAM,OAAO,KAAK,EAAE;IAI5F,MAAMM,aAAa,MAAMC,QAAQ,GAAG,CAACF,UAAU,IAAI,CAACG,CAAAA,MAAOA,IAAI,IAAI;IACnE,MAAMC,iBAAiBH,WAAW,MAAM,CAA2B,CAACI,KAAKC,QAC9D;YAAE,GAAGD,GAAG;YAAE,CAACC,MAAM,OAAO,CAAC,EAAE;mBAAKD,GAAG,CAACC,MAAM,OAAO,CAAC,IAAI,EAAE;gBAAGA,MAAM,EAAE;aAAC;QAAC,IAC7E,CAAC;IAKJlB,kBAAkB,OAAO,CAAC,CAACmB,KAAKC;QAC5B,MAAMC,mBAAmBL,cAAc,CAACI,QAAQ;QAChD,KAAK,MAAMZ,MAAMW,IACb,IAAI,CAACE,oBAAoB,CAACA,iBAAiB,QAAQ,CAACb,KAChD,MAAM,IAAIC,YACN,CAAC,kCAAkC,EAAED,GAAG,YAAY,EAAEY,QAAQ,EAAE,CAAC,EACjE,mBACA;YACIZ;YACA,OAAOY;QACX;IAIhB;AACJ"}
|
|
@@ -2,6 +2,7 @@ import { Result, createImplementation } from "@webiny/feature/api";
|
|
|
2
2
|
import { GetEntriesByIdsRepository, GetEntriesByIdsUseCase } from "./abstractions.js";
|
|
3
3
|
import { AccessControl } from "../../shared/abstractions.js";
|
|
4
4
|
import { EntryNotAuthorizedError } from "../../../domain/contentEntry/errors.js";
|
|
5
|
+
import { filterAccessibleEntries } from "../shared/entryOwnerAccess.js";
|
|
5
6
|
class GetEntriesByIdsUseCaseImpl {
|
|
6
7
|
constructor(repository, accessControl){
|
|
7
8
|
this.repository = repository;
|
|
@@ -14,7 +15,8 @@ class GetEntriesByIdsUseCaseImpl {
|
|
|
14
15
|
if (!canAccess) return Result.fail(EntryNotAuthorizedError.fromModel(model));
|
|
15
16
|
const result = await this.repository.execute(model, ids);
|
|
16
17
|
if (result.isFail()) return Result.fail(result.error);
|
|
17
|
-
|
|
18
|
+
const entries = await filterAccessibleEntries(this.accessControl, model, result.value);
|
|
19
|
+
return Result.ok(entries);
|
|
18
20
|
}
|
|
19
21
|
}
|
|
20
22
|
const GetEntriesByIdsUseCase_GetEntriesByIdsUseCase = createImplementation({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentEntry/GetEntriesByIds/GetEntriesByIdsUseCase.js","sources":["../../../../src/features/contentEntry/GetEntriesByIds/GetEntriesByIdsUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { GetEntriesByIdsUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { GetEntriesByIdsRepository } from \"./abstractions.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport type { CmsEntry, CmsEntryValues, CmsModel } from \"~/types/index.js\";\nimport { EntryNotAuthorizedError } from \"~/domain/contentEntry/errors.js\";\n\n/**\n * GetEntriesByIdsUseCase - Orchestrates fetching entries by IDs with access control.\n *\n * Responsibilities:\n * - Apply access control\n * - Delegate to repository for data fetching\n */\nclass GetEntriesByIdsUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private repository: GetEntriesByIdsRepository.Interface,\n private accessControl: AccessControl.Interface\n ) {}\n\n async execute<T extends CmsEntryValues>(\n model: CmsModel,\n ids: string[]\n ): Promise<Result<CmsEntry<T>[], UseCaseAbstraction.Error>> {\n // Check access control\n const canAccess = await this.accessControl.canAccessEntry({ model });\n if (!canAccess) {\n return Result.fail(EntryNotAuthorizedError.fromModel(model));\n }\n\n // Delegate to repository\n const result = await this.repository.execute<T>(model, ids);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n
|
|
1
|
+
{"version":3,"file":"features/contentEntry/GetEntriesByIds/GetEntriesByIdsUseCase.js","sources":["../../../../src/features/contentEntry/GetEntriesByIds/GetEntriesByIdsUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { GetEntriesByIdsUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { GetEntriesByIdsRepository } from \"./abstractions.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport type { CmsEntry, CmsEntryValues, CmsModel } from \"~/types/index.js\";\nimport { EntryNotAuthorizedError } from \"~/domain/contentEntry/errors.js\";\nimport { filterAccessibleEntries } from \"~/features/contentEntry/shared/entryOwnerAccess.js\";\n\n/**\n * GetEntriesByIdsUseCase - Orchestrates fetching entries by IDs with access control.\n *\n * Responsibilities:\n * - Apply access control\n * - Delegate to repository for data fetching\n */\nclass GetEntriesByIdsUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private repository: GetEntriesByIdsRepository.Interface,\n private accessControl: AccessControl.Interface\n ) {}\n\n async execute<T extends CmsEntryValues>(\n model: CmsModel,\n ids: string[]\n ): Promise<Result<CmsEntry<T>[], UseCaseAbstraction.Error>> {\n // Check access control\n const canAccess = await this.accessControl.canAccessEntry({ model });\n if (!canAccess) {\n return Result.fail(EntryNotAuthorizedError.fromModel(model));\n }\n\n // Delegate to repository\n const result = await this.repository.execute<T>(model, ids);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n // Drop entries the identity is not allowed to access (e.g. \"own entries only\").\n const entries = await filterAccessibleEntries(this.accessControl, model, result.value);\n\n return Result.ok(entries);\n }\n}\n\nexport const GetEntriesByIdsUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: GetEntriesByIdsUseCaseImpl,\n dependencies: [GetEntriesByIdsRepository, AccessControl]\n});\n"],"names":["GetEntriesByIdsUseCaseImpl","repository","accessControl","model","ids","canAccess","Result","EntryNotAuthorizedError","result","entries","filterAccessibleEntries","GetEntriesByIdsUseCase","createImplementation","UseCaseAbstraction","GetEntriesByIdsRepository","AccessControl"],"mappings":";;;;;AAgBA,MAAMA;IACF,YACYC,UAA+C,EAC/CC,aAAsC,CAChD;aAFUD,UAAU,GAAVA;aACAC,aAAa,GAAbA;IACT;IAEH,MAAM,QACFC,KAAe,EACfC,GAAa,EAC2C;QAExD,MAAMC,YAAY,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;YAAEF;QAAM;QAClE,IAAI,CAACE,WACD,OAAOC,OAAO,IAAI,CAACC,wBAAwB,SAAS,CAACJ;QAIzD,MAAMK,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAIL,OAAOC;QAEvD,IAAII,OAAO,MAAM,IACb,OAAOF,OAAO,IAAI,CAACE,OAAO,KAAK;QAInC,MAAMC,UAAU,MAAMC,wBAAwB,IAAI,CAAC,aAAa,EAAEP,OAAOK,OAAO,KAAK;QAErF,OAAOF,OAAO,EAAE,CAACG;IACrB;AACJ;AAEO,MAAME,gDAAyBC,qBAAqB;IACvD,aAAaC;IACb,gBAAgBb;IAChB,cAAc;QAACc;QAA2BC;KAAc;AAC5D"}
|
|
@@ -2,6 +2,7 @@ import { Result, createImplementation } from "@webiny/feature/api";
|
|
|
2
2
|
import { GetLatestEntriesByIdsRepository, GetLatestEntriesByIdsUseCase } from "./abstractions.js";
|
|
3
3
|
import { AccessControl } from "../../shared/abstractions.js";
|
|
4
4
|
import { EntryNotAuthorizedError } from "../../../domain/contentEntry/errors.js";
|
|
5
|
+
import { filterAccessibleEntries } from "../shared/entryOwnerAccess.js";
|
|
5
6
|
class GetLatestEntriesByIdsUseCaseImpl {
|
|
6
7
|
constructor(repository, accessControl){
|
|
7
8
|
this.repository = repository;
|
|
@@ -14,7 +15,8 @@ class GetLatestEntriesByIdsUseCaseImpl {
|
|
|
14
15
|
if (!canAccess) return Result.fail(EntryNotAuthorizedError.fromModel(model));
|
|
15
16
|
const result = await this.repository.execute(model, ids);
|
|
16
17
|
if (result.isFail()) return Result.fail(result.error);
|
|
17
|
-
|
|
18
|
+
const entries = await filterAccessibleEntries(this.accessControl, model, result.value);
|
|
19
|
+
return Result.ok(entries);
|
|
18
20
|
}
|
|
19
21
|
}
|
|
20
22
|
const GetLatestEntriesByIdsUseCase_GetLatestEntriesByIdsUseCase = createImplementation({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentEntry/GetLatestEntriesByIds/GetLatestEntriesByIdsUseCase.js","sources":["../../../../src/features/contentEntry/GetLatestEntriesByIds/GetLatestEntriesByIdsUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { GetLatestEntriesByIdsUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { GetLatestEntriesByIdsRepository } from \"./abstractions.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport type { CmsEntry, CmsEntryValues, CmsModel } from \"~/types/index.js\";\nimport { EntryNotAuthorizedError } from \"~/domain/contentEntry/errors.js\";\n\n/**\n * GetLatestEntriesByIdsUseCase - Orchestrates fetching latest entries by IDs.\n *\n * Responsibilities:\n * - Apply access control\n * - Delegate to repository for data fetching\n */\nclass GetLatestEntriesByIdsUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private repository: GetLatestEntriesByIdsRepository.Interface,\n private accessControl: AccessControl.Interface\n ) {}\n\n async execute<T extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n ids: string[]\n ): Promise<Result<CmsEntry<T>[], UseCaseAbstraction.Error>> {\n // Check access control\n const canAccess = await this.accessControl.canAccessEntry({ model });\n if (!canAccess) {\n return Result.fail(EntryNotAuthorizedError.fromModel(model));\n }\n\n // Delegate to repository\n const result = await this.repository.execute<T>(model, ids);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n
|
|
1
|
+
{"version":3,"file":"features/contentEntry/GetLatestEntriesByIds/GetLatestEntriesByIdsUseCase.js","sources":["../../../../src/features/contentEntry/GetLatestEntriesByIds/GetLatestEntriesByIdsUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { GetLatestEntriesByIdsUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { GetLatestEntriesByIdsRepository } from \"./abstractions.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport type { CmsEntry, CmsEntryValues, CmsModel } from \"~/types/index.js\";\nimport { EntryNotAuthorizedError } from \"~/domain/contentEntry/errors.js\";\nimport { filterAccessibleEntries } from \"~/features/contentEntry/shared/entryOwnerAccess.js\";\n\n/**\n * GetLatestEntriesByIdsUseCase - Orchestrates fetching latest entries by IDs.\n *\n * Responsibilities:\n * - Apply access control\n * - Delegate to repository for data fetching\n */\nclass GetLatestEntriesByIdsUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private repository: GetLatestEntriesByIdsRepository.Interface,\n private accessControl: AccessControl.Interface\n ) {}\n\n async execute<T extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n ids: string[]\n ): Promise<Result<CmsEntry<T>[], UseCaseAbstraction.Error>> {\n // Check access control\n const canAccess = await this.accessControl.canAccessEntry({ model });\n if (!canAccess) {\n return Result.fail(EntryNotAuthorizedError.fromModel(model));\n }\n\n // Delegate to repository\n const result = await this.repository.execute<T>(model, ids);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n // Drop entries the identity is not allowed to access (e.g. \"own entries only\").\n const entries = await filterAccessibleEntries(this.accessControl, model, result.value);\n\n return Result.ok(entries);\n }\n}\n\nexport const GetLatestEntriesByIdsUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: GetLatestEntriesByIdsUseCaseImpl,\n dependencies: [GetLatestEntriesByIdsRepository, AccessControl]\n});\n"],"names":["GetLatestEntriesByIdsUseCaseImpl","repository","accessControl","model","ids","canAccess","Result","EntryNotAuthorizedError","result","entries","filterAccessibleEntries","GetLatestEntriesByIdsUseCase","createImplementation","UseCaseAbstraction","GetLatestEntriesByIdsRepository","AccessControl"],"mappings":";;;;;AAgBA,MAAMA;IACF,YACYC,UAAqD,EACrDC,aAAsC,CAChD;aAFUD,UAAU,GAAVA;aACAC,aAAa,GAAbA;IACT;IAEH,MAAM,QACFC,KAAe,EACfC,GAAa,EAC2C;QAExD,MAAMC,YAAY,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;YAAEF;QAAM;QAClE,IAAI,CAACE,WACD,OAAOC,OAAO,IAAI,CAACC,wBAAwB,SAAS,CAACJ;QAIzD,MAAMK,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAIL,OAAOC;QAEvD,IAAII,OAAO,MAAM,IACb,OAAOF,OAAO,IAAI,CAACE,OAAO,KAAK;QAInC,MAAMC,UAAU,MAAMC,wBAAwB,IAAI,CAAC,aAAa,EAAEP,OAAOK,OAAO,KAAK;QAErF,OAAOF,OAAO,EAAE,CAACG;IACrB;AACJ;AAEO,MAAME,4DAA+BC,qBAAqB;IAC7D,aAAaC;IACb,gBAAgBb;IAChB,cAAc;QAACc;QAAiCC;KAAc;AAClE"}
|
|
@@ -2,6 +2,7 @@ import { Result, createImplementation } from "@webiny/feature/api";
|
|
|
2
2
|
import { GetLatestRevisionByEntryIdBaseUseCase, GetLatestRevisionByEntryIdRepository } from "./abstractions.js";
|
|
3
3
|
import { AccessControl } from "../../shared/abstractions.js";
|
|
4
4
|
import { EntryNotAuthorizedError } from "../../../domain/contentEntry/errors.js";
|
|
5
|
+
import { canAccessLoadedEntry } from "../shared/entryOwnerAccess.js";
|
|
5
6
|
class GetLatestRevisionByEntryIdUseCaseImpl {
|
|
6
7
|
constructor(repository, accessControl){
|
|
7
8
|
this.repository = repository;
|
|
@@ -14,7 +15,10 @@ class GetLatestRevisionByEntryIdUseCaseImpl {
|
|
|
14
15
|
if (!canAccess) return Result.fail(EntryNotAuthorizedError.fromModel(model));
|
|
15
16
|
const result = await this.repository.execute(model, params);
|
|
16
17
|
if (result.isFail()) return Result.fail(result.error);
|
|
17
|
-
|
|
18
|
+
const entry = result.value;
|
|
19
|
+
const canAccessEntry = await canAccessLoadedEntry(this.accessControl, model, entry);
|
|
20
|
+
if (!canAccessEntry) return Result.fail(EntryNotAuthorizedError.fromEntry(entry));
|
|
21
|
+
return Result.ok(entry);
|
|
18
22
|
}
|
|
19
23
|
}
|
|
20
24
|
const BaseUseCase = createImplementation({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentEntry/GetLatestRevisionByEntryId/BaseUseCase.js","sources":["../../../../src/features/contentEntry/GetLatestRevisionByEntryId/BaseUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { GetLatestRevisionByEntryIdBaseUseCase as BaseUseCaseAbstraction } from \"./abstractions.js\";\nimport { GetLatestRevisionByEntryIdRepository } from \"./abstractions.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport type {\n CmsEntry,\n CmsEntryValues,\n CmsModel,\n CmsEntryStorageOperationsGetLatestRevisionParams\n} from \"~/types/index.js\";\nimport { EntryNotAuthorizedError } from \"~/domain/contentEntry/errors.js\";\n\n/**\n * Orchestrates fetching latest revision by entry ID.\n *\n * Responsibilities:\n * - Apply access control\n * - Delegate to repository for data fetching\n * - Returns entry regardless of deleted state (decorators handle filtering)\n */\nclass GetLatestRevisionByEntryIdUseCaseImpl implements BaseUseCaseAbstraction.Interface {\n public constructor(\n private repository: GetLatestRevisionByEntryIdRepository.Interface,\n private accessControl: AccessControl.Interface\n ) {}\n\n async execute<T extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n params: CmsEntryStorageOperationsGetLatestRevisionParams\n ): Promise<Result<CmsEntry<T>, BaseUseCaseAbstraction.Error>> {\n // Check access control\n const canAccess = await this.accessControl.canAccessEntry({ model });\n if (!canAccess) {\n return Result.fail(EntryNotAuthorizedError.fromModel(model));\n }\n\n // Delegate to repository\n const result = await this.repository.execute<T>(model, params);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n return Result.
|
|
1
|
+
{"version":3,"file":"features/contentEntry/GetLatestRevisionByEntryId/BaseUseCase.js","sources":["../../../../src/features/contentEntry/GetLatestRevisionByEntryId/BaseUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { GetLatestRevisionByEntryIdBaseUseCase as BaseUseCaseAbstraction } from \"./abstractions.js\";\nimport { GetLatestRevisionByEntryIdRepository } from \"./abstractions.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport type {\n CmsEntry,\n CmsEntryValues,\n CmsModel,\n CmsEntryStorageOperationsGetLatestRevisionParams\n} from \"~/types/index.js\";\nimport { EntryNotAuthorizedError } from \"~/domain/contentEntry/errors.js\";\nimport { canAccessLoadedEntry } from \"~/features/contentEntry/shared/entryOwnerAccess.js\";\n\n/**\n * Orchestrates fetching latest revision by entry ID.\n *\n * Responsibilities:\n * - Apply access control\n * - Delegate to repository for data fetching\n * - Returns entry regardless of deleted state (decorators handle filtering)\n */\nclass GetLatestRevisionByEntryIdUseCaseImpl implements BaseUseCaseAbstraction.Interface {\n public constructor(\n private repository: GetLatestRevisionByEntryIdRepository.Interface,\n private accessControl: AccessControl.Interface\n ) {}\n\n async execute<T extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n params: CmsEntryStorageOperationsGetLatestRevisionParams\n ): Promise<Result<CmsEntry<T>, BaseUseCaseAbstraction.Error>> {\n // Check access control\n const canAccess = await this.accessControl.canAccessEntry({ model });\n if (!canAccess) {\n return Result.fail(EntryNotAuthorizedError.fromModel(model));\n }\n\n // Delegate to repository\n const result = await this.repository.execute<T>(model, params);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n const entry = result.value;\n\n // Check entry-level access (e.g. \"own entries only\").\n const canAccessEntry = await canAccessLoadedEntry(this.accessControl, model, entry);\n if (!canAccessEntry) {\n return Result.fail(EntryNotAuthorizedError.fromEntry(entry));\n }\n\n return Result.ok(entry);\n }\n}\n\nexport const BaseUseCase = createImplementation({\n abstraction: BaseUseCaseAbstraction,\n implementation: GetLatestRevisionByEntryIdUseCaseImpl,\n dependencies: [GetLatestRevisionByEntryIdRepository, AccessControl]\n});\n"],"names":["GetLatestRevisionByEntryIdUseCaseImpl","repository","accessControl","model","params","canAccess","Result","EntryNotAuthorizedError","result","entry","canAccessEntry","canAccessLoadedEntry","BaseUseCase","createImplementation","BaseUseCaseAbstraction","GetLatestRevisionByEntryIdRepository","AccessControl"],"mappings":";;;;;AAsBA,MAAMA;IACF,YACYC,UAA0D,EAC1DC,aAAsC,CAChD;aAFUD,UAAU,GAAVA;aACAC,aAAa,GAAbA;IACT;IAEH,MAAM,QACFC,KAAe,EACfC,MAAwD,EACE;QAE1D,MAAMC,YAAY,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;YAAEF;QAAM;QAClE,IAAI,CAACE,WACD,OAAOC,OAAO,IAAI,CAACC,wBAAwB,SAAS,CAACJ;QAIzD,MAAMK,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAIL,OAAOC;QAEvD,IAAII,OAAO,MAAM,IACb,OAAOF,OAAO,IAAI,CAACE,OAAO,KAAK;QAGnC,MAAMC,QAAQD,OAAO,KAAK;QAG1B,MAAME,iBAAiB,MAAMC,qBAAqB,IAAI,CAAC,aAAa,EAAER,OAAOM;QAC7E,IAAI,CAACC,gBACD,OAAOJ,OAAO,IAAI,CAACC,wBAAwB,SAAS,CAACE;QAGzD,OAAOH,OAAO,EAAE,CAACG;IACrB;AACJ;AAEO,MAAMG,cAAcC,qBAAqB;IAC5C,aAAaC;IACb,gBAAgBd;IAChB,cAAc;QAACe;QAAsCC;KAAc;AACvE"}
|
|
@@ -2,6 +2,7 @@ import { Result, createImplementation } from "@webiny/feature/api";
|
|
|
2
2
|
import { GetPreviousRevisionByEntryIdBaseUseCase, GetPreviousRevisionByEntryIdRepository } from "./abstractions.js";
|
|
3
3
|
import { AccessControl } from "../../shared/abstractions.js";
|
|
4
4
|
import { EntryNotAuthorizedError } from "../../../domain/contentEntry/errors.js";
|
|
5
|
+
import { canAccessLoadedEntry } from "../shared/entryOwnerAccess.js";
|
|
5
6
|
class GetPreviousRevisionByEntryIdUseCaseImpl {
|
|
6
7
|
constructor(repository, accessControl){
|
|
7
8
|
this.repository = repository;
|
|
@@ -14,7 +15,10 @@ class GetPreviousRevisionByEntryIdUseCaseImpl {
|
|
|
14
15
|
if (!canAccess) return Result.fail(EntryNotAuthorizedError.fromModel(model));
|
|
15
16
|
const result = await this.repository.execute(model, params);
|
|
16
17
|
if (result.isFail()) return Result.fail(result.error);
|
|
17
|
-
|
|
18
|
+
const entry = result.value;
|
|
19
|
+
const canAccessEntry = await canAccessLoadedEntry(this.accessControl, model, entry);
|
|
20
|
+
if (!canAccessEntry) return Result.fail(EntryNotAuthorizedError.fromEntry(entry));
|
|
21
|
+
return Result.ok(entry);
|
|
18
22
|
}
|
|
19
23
|
}
|
|
20
24
|
const BaseUseCase = createImplementation({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentEntry/GetPreviousRevisionByEntryId/BaseUseCase.js","sources":["../../../../src/features/contentEntry/GetPreviousRevisionByEntryId/BaseUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { GetPreviousRevisionByEntryIdBaseUseCase as BaseUseCaseAbstraction } from \"./abstractions.js\";\nimport { GetPreviousRevisionByEntryIdRepository } from \"./abstractions.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport type {\n CmsEntry,\n CmsEntryValues,\n CmsModel,\n CmsEntryStorageOperationsGetPreviousRevisionParams\n} from \"~/types/index.js\";\nimport { EntryNotAuthorizedError } from \"~/domain/contentEntry/errors.js\";\n\n/**\n * Orchestrates fetching previous revision by entry ID and version.\n *\n * Responsibilities:\n * - Apply access control\n * - Delegate to repository for data fetching\n * - Returns entry regardless of deleted state (variations handle filtering)\n */\nclass GetPreviousRevisionByEntryIdUseCaseImpl implements BaseUseCaseAbstraction.Interface {\n public constructor(\n private repository: GetPreviousRevisionByEntryIdRepository.Interface,\n private accessControl: AccessControl.Interface\n ) {}\n\n async execute<T extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n params: CmsEntryStorageOperationsGetPreviousRevisionParams\n ): Promise<Result<CmsEntry<T>, BaseUseCaseAbstraction.Error>> {\n // Check access control\n const canAccess = await this.accessControl.canAccessEntry({ model });\n if (!canAccess) {\n return Result.fail(EntryNotAuthorizedError.fromModel(model));\n }\n\n // Delegate to repository\n const result = await this.repository.execute<T>(model, params);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n return Result.
|
|
1
|
+
{"version":3,"file":"features/contentEntry/GetPreviousRevisionByEntryId/BaseUseCase.js","sources":["../../../../src/features/contentEntry/GetPreviousRevisionByEntryId/BaseUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { GetPreviousRevisionByEntryIdBaseUseCase as BaseUseCaseAbstraction } from \"./abstractions.js\";\nimport { GetPreviousRevisionByEntryIdRepository } from \"./abstractions.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport type {\n CmsEntry,\n CmsEntryValues,\n CmsModel,\n CmsEntryStorageOperationsGetPreviousRevisionParams\n} from \"~/types/index.js\";\nimport { EntryNotAuthorizedError } from \"~/domain/contentEntry/errors.js\";\nimport { canAccessLoadedEntry } from \"~/features/contentEntry/shared/entryOwnerAccess.js\";\n\n/**\n * Orchestrates fetching previous revision by entry ID and version.\n *\n * Responsibilities:\n * - Apply access control\n * - Delegate to repository for data fetching\n * - Returns entry regardless of deleted state (variations handle filtering)\n */\nclass GetPreviousRevisionByEntryIdUseCaseImpl implements BaseUseCaseAbstraction.Interface {\n public constructor(\n private repository: GetPreviousRevisionByEntryIdRepository.Interface,\n private accessControl: AccessControl.Interface\n ) {}\n\n async execute<T extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n params: CmsEntryStorageOperationsGetPreviousRevisionParams\n ): Promise<Result<CmsEntry<T>, BaseUseCaseAbstraction.Error>> {\n // Check access control\n const canAccess = await this.accessControl.canAccessEntry({ model });\n if (!canAccess) {\n return Result.fail(EntryNotAuthorizedError.fromModel(model));\n }\n\n // Delegate to repository\n const result = await this.repository.execute<T>(model, params);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n const entry = result.value;\n\n // Check entry-level access (e.g. \"own entries only\").\n const canAccessEntry = await canAccessLoadedEntry(this.accessControl, model, entry);\n if (!canAccessEntry) {\n return Result.fail(EntryNotAuthorizedError.fromEntry(entry));\n }\n\n return Result.ok(entry);\n }\n}\n\nexport const BaseUseCase = createImplementation({\n abstraction: BaseUseCaseAbstraction,\n implementation: GetPreviousRevisionByEntryIdUseCaseImpl,\n dependencies: [GetPreviousRevisionByEntryIdRepository, AccessControl]\n});\n"],"names":["GetPreviousRevisionByEntryIdUseCaseImpl","repository","accessControl","model","params","canAccess","Result","EntryNotAuthorizedError","result","entry","canAccessEntry","canAccessLoadedEntry","BaseUseCase","createImplementation","BaseUseCaseAbstraction","GetPreviousRevisionByEntryIdRepository","AccessControl"],"mappings":";;;;;AAsBA,MAAMA;IACF,YACYC,UAA4D,EAC5DC,aAAsC,CAChD;aAFUD,UAAU,GAAVA;aACAC,aAAa,GAAbA;IACT;IAEH,MAAM,QACFC,KAAe,EACfC,MAA0D,EACA;QAE1D,MAAMC,YAAY,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;YAAEF;QAAM;QAClE,IAAI,CAACE,WACD,OAAOC,OAAO,IAAI,CAACC,wBAAwB,SAAS,CAACJ;QAIzD,MAAMK,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAIL,OAAOC;QAEvD,IAAII,OAAO,MAAM,IACb,OAAOF,OAAO,IAAI,CAACE,OAAO,KAAK;QAGnC,MAAMC,QAAQD,OAAO,KAAK;QAG1B,MAAME,iBAAiB,MAAMC,qBAAqB,IAAI,CAAC,aAAa,EAAER,OAAOM;QAC7E,IAAI,CAACC,gBACD,OAAOJ,OAAO,IAAI,CAACC,wBAAwB,SAAS,CAACE;QAGzD,OAAOH,OAAO,EAAE,CAACG;IACrB;AACJ;AAEO,MAAMG,cAAcC,qBAAqB;IAC5C,aAAaC;IACb,gBAAgBd;IAChB,cAAc;QAACe;QAAwCC;KAAc;AACzE"}
|
|
@@ -2,6 +2,7 @@ import { Result, createImplementation } from "@webiny/feature/api";
|
|
|
2
2
|
import { GetPublishedEntriesByIdsRepository, GetPublishedEntriesByIdsUseCase } from "./abstractions.js";
|
|
3
3
|
import { AccessControl } from "../../shared/abstractions.js";
|
|
4
4
|
import { EntryNotAuthorizedError } from "../../../domain/contentEntry/errors.js";
|
|
5
|
+
import { filterAccessibleEntries } from "../shared/entryOwnerAccess.js";
|
|
5
6
|
class GetPublishedEntriesByIdsUseCaseImpl {
|
|
6
7
|
constructor(repository, accessControl){
|
|
7
8
|
this.repository = repository;
|
|
@@ -14,7 +15,8 @@ class GetPublishedEntriesByIdsUseCaseImpl {
|
|
|
14
15
|
if (!canAccess) return Result.fail(EntryNotAuthorizedError.fromModel(model));
|
|
15
16
|
const result = await this.repository.execute(model, ids);
|
|
16
17
|
if (result.isFail()) return Result.fail(result.error);
|
|
17
|
-
|
|
18
|
+
const entries = await filterAccessibleEntries(this.accessControl, model, result.value);
|
|
19
|
+
return Result.ok(entries);
|
|
18
20
|
}
|
|
19
21
|
}
|
|
20
22
|
const GetPublishedEntriesByIdsUseCase_GetPublishedEntriesByIdsUseCase = createImplementation({
|
package/features/contentEntry/GetPublishedEntriesByIds/GetPublishedEntriesByIdsUseCase.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentEntry/GetPublishedEntriesByIds/GetPublishedEntriesByIdsUseCase.js","sources":["../../../../src/features/contentEntry/GetPublishedEntriesByIds/GetPublishedEntriesByIdsUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { GetPublishedEntriesByIdsUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { GetPublishedEntriesByIdsRepository } from \"./abstractions.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport type { CmsEntry, CmsEntryValues, CmsModel } from \"~/types/index.js\";\nimport { EntryNotAuthorizedError } from \"~/domain/contentEntry/errors.js\";\n\n/**\n * GetPublishedEntriesByIdsUseCase - Orchestrates fetching published entries by IDs.\n *\n * Responsibilities:\n * - Apply access control\n * - Delegate to repository for data fetching\n */\nclass GetPublishedEntriesByIdsUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private repository: GetPublishedEntriesByIdsRepository.Interface,\n private accessControl: AccessControl.Interface\n ) {}\n\n public async execute<T extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n ids: string[]\n ): Promise<Result<CmsEntry<T>[], UseCaseAbstraction.Error>> {\n // Check access control\n const canAccess = await this.accessControl.canAccessEntry({ model });\n if (!canAccess) {\n return Result.fail(EntryNotAuthorizedError.fromModel(model));\n }\n\n // Delegate to repository\n const result = await this.repository.execute<T>(model, ids);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n
|
|
1
|
+
{"version":3,"file":"features/contentEntry/GetPublishedEntriesByIds/GetPublishedEntriesByIdsUseCase.js","sources":["../../../../src/features/contentEntry/GetPublishedEntriesByIds/GetPublishedEntriesByIdsUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { GetPublishedEntriesByIdsUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { GetPublishedEntriesByIdsRepository } from \"./abstractions.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport type { CmsEntry, CmsEntryValues, CmsModel } from \"~/types/index.js\";\nimport { EntryNotAuthorizedError } from \"~/domain/contentEntry/errors.js\";\nimport { filterAccessibleEntries } from \"~/features/contentEntry/shared/entryOwnerAccess.js\";\n\n/**\n * GetPublishedEntriesByIdsUseCase - Orchestrates fetching published entries by IDs.\n *\n * Responsibilities:\n * - Apply access control\n * - Delegate to repository for data fetching\n */\nclass GetPublishedEntriesByIdsUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private repository: GetPublishedEntriesByIdsRepository.Interface,\n private accessControl: AccessControl.Interface\n ) {}\n\n public async execute<T extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n ids: string[]\n ): Promise<Result<CmsEntry<T>[], UseCaseAbstraction.Error>> {\n // Check access control\n const canAccess = await this.accessControl.canAccessEntry({ model });\n if (!canAccess) {\n return Result.fail(EntryNotAuthorizedError.fromModel(model));\n }\n\n // Delegate to repository\n const result = await this.repository.execute<T>(model, ids);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n // Drop entries the identity is not allowed to access (e.g. \"own entries only\").\n const entries = await filterAccessibleEntries(this.accessControl, model, result.value);\n\n return Result.ok(entries);\n }\n}\n\nexport const GetPublishedEntriesByIdsUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: GetPublishedEntriesByIdsUseCaseImpl,\n dependencies: [GetPublishedEntriesByIdsRepository, AccessControl]\n});\n"],"names":["GetPublishedEntriesByIdsUseCaseImpl","repository","accessControl","model","ids","canAccess","Result","EntryNotAuthorizedError","result","entries","filterAccessibleEntries","GetPublishedEntriesByIdsUseCase","createImplementation","UseCaseAbstraction","GetPublishedEntriesByIdsRepository","AccessControl"],"mappings":";;;;;AAgBA,MAAMA;IACF,YACYC,UAAwD,EACxDC,aAAsC,CAChD;aAFUD,UAAU,GAAVA;aACAC,aAAa,GAAbA;IACT;IAEH,MAAa,QACTC,KAAe,EACfC,GAAa,EAC2C;QAExD,MAAMC,YAAY,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;YAAEF;QAAM;QAClE,IAAI,CAACE,WACD,OAAOC,OAAO,IAAI,CAACC,wBAAwB,SAAS,CAACJ;QAIzD,MAAMK,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAIL,OAAOC;QAEvD,IAAII,OAAO,MAAM,IACb,OAAOF,OAAO,IAAI,CAACE,OAAO,KAAK;QAInC,MAAMC,UAAU,MAAMC,wBAAwB,IAAI,CAAC,aAAa,EAAEP,OAAOK,OAAO,KAAK;QAErF,OAAOF,OAAO,EAAE,CAACG;IACrB;AACJ;AAEO,MAAME,kEAAkCC,qBAAqB;IAChE,aAAaC;IACb,gBAAgBb;IAChB,cAAc;QAACc;QAAoCC;KAAc;AACrE"}
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { GetPublishedRevisionByEntryIdRepository, GetPublishedRevisionByEntryIdUseCase as UseCaseAbstraction } from "./abstractions.js";
|
|
3
|
+
import { AccessControl } from "../../../features/shared/abstractions.js";
|
|
3
4
|
import type { CmsEntry, CmsEntryValues, CmsModel } from "../../../types/index.js";
|
|
4
5
|
/**
|
|
5
6
|
* GetPublishedRevisionByEntryIdUseCase - Orchestrates fetching published revision by entry ID.
|
|
6
7
|
*
|
|
7
8
|
* Responsibilities:
|
|
9
|
+
* - Apply model-level access control
|
|
8
10
|
* - Delegate to repository for data fetching
|
|
11
|
+
* - Apply entry-level access control (e.g. "own entries only")
|
|
9
12
|
* - Return null if entry not found or deleted
|
|
10
13
|
*/
|
|
11
14
|
declare class GetPublishedRevisionByEntryIdUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
12
15
|
private repository;
|
|
13
|
-
|
|
16
|
+
private accessControl;
|
|
17
|
+
constructor(repository: GetPublishedRevisionByEntryIdRepository.Interface, accessControl: AccessControl.Interface);
|
|
14
18
|
execute<T extends CmsEntryValues = CmsEntryValues>(model: CmsModel, entryId: string): Promise<Result<CmsEntry<T> | null, UseCaseAbstraction.Error>>;
|
|
15
19
|
}
|
|
16
20
|
export declare const GetPublishedRevisionByEntryIdUseCase: import("@webiny/di").Implementation<typeof GetPublishedRevisionByEntryIdUseCaseImpl>;
|
package/features/contentEntry/GetPublishedRevisionByEntryId/GetPublishedRevisionByEntryIdUseCase.js
CHANGED
|
@@ -1,20 +1,33 @@
|
|
|
1
1
|
import { Result, createImplementation } from "@webiny/feature/api";
|
|
2
2
|
import { GetPublishedRevisionByEntryIdRepository, GetPublishedRevisionByEntryIdUseCase } from "./abstractions.js";
|
|
3
|
+
import { AccessControl } from "../../shared/abstractions.js";
|
|
4
|
+
import { EntryNotAuthorizedError } from "../../../domain/contentEntry/errors.js";
|
|
5
|
+
import { canAccessLoadedEntry } from "../shared/entryOwnerAccess.js";
|
|
3
6
|
class GetPublishedRevisionByEntryIdUseCaseImpl {
|
|
4
|
-
constructor(repository){
|
|
7
|
+
constructor(repository, accessControl){
|
|
5
8
|
this.repository = repository;
|
|
9
|
+
this.accessControl = accessControl;
|
|
6
10
|
}
|
|
7
11
|
async execute(model, entryId) {
|
|
12
|
+
const canAccess = await this.accessControl.canAccessEntry({
|
|
13
|
+
model
|
|
14
|
+
});
|
|
15
|
+
if (!canAccess) return Result.fail(EntryNotAuthorizedError.fromModel(model));
|
|
8
16
|
const result = await this.repository.execute(model, entryId);
|
|
9
17
|
if (result.isFail()) return Result.fail(result.error);
|
|
10
|
-
|
|
18
|
+
const entry = result.value;
|
|
19
|
+
if (!entry) return Result.ok(null);
|
|
20
|
+
const canAccessEntry = await canAccessLoadedEntry(this.accessControl, model, entry);
|
|
21
|
+
if (!canAccessEntry) return Result.fail(EntryNotAuthorizedError.fromEntry(entry));
|
|
22
|
+
return Result.ok(entry);
|
|
11
23
|
}
|
|
12
24
|
}
|
|
13
25
|
const GetPublishedRevisionByEntryIdUseCase_GetPublishedRevisionByEntryIdUseCase = createImplementation({
|
|
14
26
|
abstraction: GetPublishedRevisionByEntryIdUseCase,
|
|
15
27
|
implementation: GetPublishedRevisionByEntryIdUseCaseImpl,
|
|
16
28
|
dependencies: [
|
|
17
|
-
GetPublishedRevisionByEntryIdRepository
|
|
29
|
+
GetPublishedRevisionByEntryIdRepository,
|
|
30
|
+
AccessControl
|
|
18
31
|
]
|
|
19
32
|
});
|
|
20
33
|
export { GetPublishedRevisionByEntryIdUseCase_GetPublishedRevisionByEntryIdUseCase as GetPublishedRevisionByEntryIdUseCase };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentEntry/GetPublishedRevisionByEntryId/GetPublishedRevisionByEntryIdUseCase.js","sources":["../../../../src/features/contentEntry/GetPublishedRevisionByEntryId/GetPublishedRevisionByEntryIdUseCase.ts"],"sourcesContent":["import { createImplementation, Result } from \"@webiny/feature/api\";\nimport {\n GetPublishedRevisionByEntryIdRepository,\n GetPublishedRevisionByEntryIdUseCase as UseCaseAbstraction\n} from \"./abstractions.js\";\nimport type { CmsEntry, CmsEntryValues, CmsModel } from \"~/types/index.js\";\n\n/**\n * GetPublishedRevisionByEntryIdUseCase - Orchestrates fetching published revision by entry ID.\n *\n * Responsibilities:\n * - Delegate to repository for data fetching\n * - Return null if entry not found or deleted\n */\nclass GetPublishedRevisionByEntryIdUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(private repository: GetPublishedRevisionByEntryIdRepository.Interface) {}\n\n public async execute<T extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n entryId: string\n ): Promise<Result<CmsEntry<T> | null, UseCaseAbstraction.Error>> {\n // Delegate to repository\n const result = await this.repository.execute<T>(model, entryId);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n return Result.ok(
|
|
1
|
+
{"version":3,"file":"features/contentEntry/GetPublishedRevisionByEntryId/GetPublishedRevisionByEntryIdUseCase.js","sources":["../../../../src/features/contentEntry/GetPublishedRevisionByEntryId/GetPublishedRevisionByEntryIdUseCase.ts"],"sourcesContent":["import { createImplementation, Result } from \"@webiny/feature/api\";\nimport {\n GetPublishedRevisionByEntryIdRepository,\n GetPublishedRevisionByEntryIdUseCase as UseCaseAbstraction\n} from \"./abstractions.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport type { CmsEntry, CmsEntryValues, CmsModel } from \"~/types/index.js\";\nimport { EntryNotAuthorizedError } from \"~/domain/contentEntry/errors.js\";\nimport { canAccessLoadedEntry } from \"~/features/contentEntry/shared/entryOwnerAccess.js\";\n\n/**\n * GetPublishedRevisionByEntryIdUseCase - Orchestrates fetching published revision by entry ID.\n *\n * Responsibilities:\n * - Apply model-level access control\n * - Delegate to repository for data fetching\n * - Apply entry-level access control (e.g. \"own entries only\")\n * - Return null if entry not found or deleted\n */\nclass GetPublishedRevisionByEntryIdUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private repository: GetPublishedRevisionByEntryIdRepository.Interface,\n private accessControl: AccessControl.Interface\n ) {}\n\n public async execute<T extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n entryId: string\n ): Promise<Result<CmsEntry<T> | null, UseCaseAbstraction.Error>> {\n const canAccess = await this.accessControl.canAccessEntry({ model });\n if (!canAccess) {\n return Result.fail(EntryNotAuthorizedError.fromModel(model));\n }\n\n // Delegate to repository\n const result = await this.repository.execute<T>(model, entryId);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n const entry = result.value;\n if (!entry) {\n return Result.ok(null);\n }\n\n const canAccessEntry = await canAccessLoadedEntry(this.accessControl, model, entry);\n if (!canAccessEntry) {\n return Result.fail(EntryNotAuthorizedError.fromEntry(entry));\n }\n\n return Result.ok(entry);\n }\n}\n\nexport const GetPublishedRevisionByEntryIdUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: GetPublishedRevisionByEntryIdUseCaseImpl,\n dependencies: [GetPublishedRevisionByEntryIdRepository, AccessControl]\n});\n"],"names":["GetPublishedRevisionByEntryIdUseCaseImpl","repository","accessControl","model","entryId","canAccess","Result","EntryNotAuthorizedError","result","entry","canAccessEntry","canAccessLoadedEntry","GetPublishedRevisionByEntryIdUseCase","createImplementation","UseCaseAbstraction","GetPublishedRevisionByEntryIdRepository","AccessControl"],"mappings":";;;;;AAmBA,MAAMA;IACF,YACYC,UAA6D,EAC7DC,aAAsC,CAChD;aAFUD,UAAU,GAAVA;aACAC,aAAa,GAAbA;IACT;IAEH,MAAa,QACTC,KAAe,EACfC,OAAe,EAC8C;QAC7D,MAAMC,YAAY,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;YAAEF;QAAM;QAClE,IAAI,CAACE,WACD,OAAOC,OAAO,IAAI,CAACC,wBAAwB,SAAS,CAACJ;QAIzD,MAAMK,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAIL,OAAOC;QAEvD,IAAII,OAAO,MAAM,IACb,OAAOF,OAAO,IAAI,CAACE,OAAO,KAAK;QAGnC,MAAMC,QAAQD,OAAO,KAAK;QAC1B,IAAI,CAACC,OACD,OAAOH,OAAO,EAAE,CAAC;QAGrB,MAAMI,iBAAiB,MAAMC,qBAAqB,IAAI,CAAC,aAAa,EAAER,OAAOM;QAC7E,IAAI,CAACC,gBACD,OAAOJ,OAAO,IAAI,CAACC,wBAAwB,SAAS,CAACE;QAGzD,OAAOH,OAAO,EAAE,CAACG;IACrB;AACJ;AAEO,MAAMG,4EAAuCC,qBAAqB;IACrE,aAAaC;IACb,gBAAgBd;IAChB,cAAc;QAACe;QAAyCC;KAAc;AAC1E"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import type { CmsEntry, CmsEntryValues, CmsModel } from "../../../types/index.js";
|
|
3
|
-
import { EntryNotFoundError, type EntryPersistenceError } from "../../../domain/contentEntry/errors.js";
|
|
3
|
+
import { EntryNotFoundError, type EntryNotAuthorizedError, type EntryPersistenceError } from "../../../domain/contentEntry/errors.js";
|
|
4
4
|
/**
|
|
5
5
|
* GetPublishedRevisionByEntryId Use Case
|
|
6
6
|
*/
|
|
@@ -8,6 +8,7 @@ export interface IGetPublishedRevisionByEntryIdUseCase {
|
|
|
8
8
|
execute<T extends CmsEntryValues = CmsEntryValues>(model: CmsModel, entryId: string): Promise<Result<CmsEntry<T> | null, UseCaseError>>;
|
|
9
9
|
}
|
|
10
10
|
export interface IGetPublishedRevisionByEntryIdUseCaseErrors {
|
|
11
|
+
notAuthorized: EntryNotAuthorizedError;
|
|
11
12
|
repository: RepositoryError;
|
|
12
13
|
}
|
|
13
14
|
type UseCaseError = IGetPublishedRevisionByEntryIdUseCaseErrors[keyof IGetPublishedRevisionByEntryIdUseCaseErrors];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentEntry/GetPublishedRevisionByEntryId/abstractions.js","sources":["../../../../src/features/contentEntry/GetPublishedRevisionByEntryId/abstractions.ts"],"sourcesContent":["import { createAbstraction, Result } from \"@webiny/feature/api\";\nimport type { CmsEntry, CmsEntryValues, CmsModel } from \"~/types/index.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"features/contentEntry/GetPublishedRevisionByEntryId/abstractions.js","sources":["../../../../src/features/contentEntry/GetPublishedRevisionByEntryId/abstractions.ts"],"sourcesContent":["import { createAbstraction, Result } from \"@webiny/feature/api\";\nimport type { CmsEntry, CmsEntryValues, CmsModel } from \"~/types/index.js\";\nimport {\n EntryNotFoundError,\n type EntryNotAuthorizedError,\n type EntryPersistenceError\n} from \"~/domain/contentEntry/errors.js\";\n\n/**\n * GetPublishedRevisionByEntryId Use Case\n */\nexport interface IGetPublishedRevisionByEntryIdUseCase {\n execute<T extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n entryId: string\n ): Promise<Result<CmsEntry<T> | null, UseCaseError>>;\n}\n\nexport interface IGetPublishedRevisionByEntryIdUseCaseErrors {\n notAuthorized: EntryNotAuthorizedError;\n repository: RepositoryError;\n}\n\ntype UseCaseError =\n IGetPublishedRevisionByEntryIdUseCaseErrors[keyof IGetPublishedRevisionByEntryIdUseCaseErrors];\n\n/** Retrieve the published revision of an entry. */\nexport const GetPublishedRevisionByEntryIdUseCase =\n createAbstraction<IGetPublishedRevisionByEntryIdUseCase>(\n \"GetPublishedRevisionByEntryIdUseCase\"\n );\n\nexport namespace GetPublishedRevisionByEntryIdUseCase {\n export type Interface = IGetPublishedRevisionByEntryIdUseCase;\n export type Error = UseCaseError;\n export type Return<T extends CmsEntryValues = CmsEntryValues> = Promise<\n Result<CmsEntry<T> | null, UseCaseError>\n >;\n}\n\n/**\n * GetPublishedRevisionByEntryIdRepository - Fetches published revision from storage.\n */\nexport interface IGetPublishedRevisionByEntryIdRepository {\n execute<T extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n entryId: string\n ): Promise<Result<CmsEntry<T> | null, RepositoryError>>;\n}\n\nexport interface IGetPublishedRevisionByEntryIdRepositoryErrors {\n storage: EntryPersistenceError;\n notFound: EntryNotFoundError;\n}\n\ntype RepositoryError =\n IGetPublishedRevisionByEntryIdRepositoryErrors[keyof IGetPublishedRevisionByEntryIdRepositoryErrors];\n\nexport const GetPublishedRevisionByEntryIdRepository =\n createAbstraction<IGetPublishedRevisionByEntryIdRepository>(\n \"GetPublishedRevisionByEntryIdRepository\"\n );\n\nexport namespace GetPublishedRevisionByEntryIdRepository {\n export type Interface = IGetPublishedRevisionByEntryIdRepository;\n export type Error = RepositoryError;\n}\n"],"names":["GetPublishedRevisionByEntryIdUseCase","createAbstraction","GetPublishedRevisionByEntryIdRepository"],"mappings":";AA2BO,MAAMA,uCACTC,kBACI;AA6BD,MAAMC,0CACTD,kBACI"}
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { GetRevisionByIdUseCase as UseCaseAbstraction } from "./abstractions.js";
|
|
3
3
|
import { GetRevisionByIdRepository } from "./abstractions.js";
|
|
4
|
+
import { AccessControl } from "../../../features/shared/abstractions.js";
|
|
4
5
|
import type { CmsEntry, CmsEntryValues, CmsModel } from "../../../types/index.js";
|
|
5
6
|
/**
|
|
6
7
|
* GetRevisionByIdUseCase - Fetches a specific entry revision.
|
|
7
8
|
*
|
|
8
|
-
*
|
|
9
|
+
* Responsibilities:
|
|
10
|
+
* - Apply model-level access control
|
|
11
|
+
* - Delegate to repository for data fetching
|
|
12
|
+
* - Apply entry-level access control (e.g. "own entries only")
|
|
9
13
|
*/
|
|
10
14
|
declare class GetRevisionByIdUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
11
15
|
private repository;
|
|
12
|
-
|
|
16
|
+
private accessControl;
|
|
17
|
+
constructor(repository: GetRevisionByIdRepository.Interface, accessControl: AccessControl.Interface);
|
|
13
18
|
execute<T extends CmsEntryValues = CmsEntryValues>(model: CmsModel, id: string): Promise<Result<CmsEntry<T>, UseCaseAbstraction.Error>>;
|
|
14
19
|
}
|
|
15
20
|
export declare const GetRevisionByIdUseCase: import("@webiny/di").Implementation<typeof GetRevisionByIdUseCaseImpl>;
|
|
@@ -1,18 +1,32 @@
|
|
|
1
|
-
import { createImplementation } from "@webiny/feature/api";
|
|
1
|
+
import { Result, createImplementation } from "@webiny/feature/api";
|
|
2
2
|
import { GetRevisionByIdRepository, GetRevisionByIdUseCase } from "./abstractions.js";
|
|
3
|
+
import { AccessControl } from "../../shared/abstractions.js";
|
|
4
|
+
import { EntryNotAuthorizedError } from "../../../domain/contentEntry/errors.js";
|
|
5
|
+
import { canAccessLoadedEntry } from "../shared/entryOwnerAccess.js";
|
|
3
6
|
class GetRevisionByIdUseCaseImpl {
|
|
4
|
-
constructor(repository){
|
|
7
|
+
constructor(repository, accessControl){
|
|
5
8
|
this.repository = repository;
|
|
9
|
+
this.accessControl = accessControl;
|
|
6
10
|
}
|
|
7
11
|
async execute(model, id) {
|
|
8
|
-
|
|
12
|
+
const canAccess = await this.accessControl.canAccessEntry({
|
|
13
|
+
model
|
|
14
|
+
});
|
|
15
|
+
if (!canAccess) return Result.fail(EntryNotAuthorizedError.fromModel(model));
|
|
16
|
+
const result = await this.repository.execute(model, id);
|
|
17
|
+
if (result.isFail()) return Result.fail(result.error);
|
|
18
|
+
const entry = result.value;
|
|
19
|
+
const canAccessEntry = await canAccessLoadedEntry(this.accessControl, model, entry);
|
|
20
|
+
if (!canAccessEntry) return Result.fail(EntryNotAuthorizedError.fromEntry(entry));
|
|
21
|
+
return Result.ok(entry);
|
|
9
22
|
}
|
|
10
23
|
}
|
|
11
24
|
const GetRevisionByIdUseCase_GetRevisionByIdUseCase = createImplementation({
|
|
12
25
|
abstraction: GetRevisionByIdUseCase,
|
|
13
26
|
implementation: GetRevisionByIdUseCaseImpl,
|
|
14
27
|
dependencies: [
|
|
15
|
-
GetRevisionByIdRepository
|
|
28
|
+
GetRevisionByIdRepository,
|
|
29
|
+
AccessControl
|
|
16
30
|
]
|
|
17
31
|
});
|
|
18
32
|
export { GetRevisionByIdUseCase_GetRevisionByIdUseCase as GetRevisionByIdUseCase };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentEntry/GetRevisionById/GetRevisionByIdUseCase.js","sources":["../../../../src/features/contentEntry/GetRevisionById/GetRevisionByIdUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { GetRevisionByIdUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { GetRevisionByIdRepository } from \"./abstractions.js\";\nimport type { CmsEntry, CmsEntryValues, CmsModel } from \"~/types/index.js\";\n\n/**\n * GetRevisionByIdUseCase - Fetches a specific entry revision.\n *\n *
|
|
1
|
+
{"version":3,"file":"features/contentEntry/GetRevisionById/GetRevisionByIdUseCase.js","sources":["../../../../src/features/contentEntry/GetRevisionById/GetRevisionByIdUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { GetRevisionByIdUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { GetRevisionByIdRepository } from \"./abstractions.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport type { CmsEntry, CmsEntryValues, CmsModel } from \"~/types/index.js\";\nimport { EntryNotAuthorizedError } from \"~/domain/contentEntry/errors.js\";\nimport { canAccessLoadedEntry } from \"~/features/contentEntry/shared/entryOwnerAccess.js\";\n\n/**\n * GetRevisionByIdUseCase - Fetches a specific entry revision.\n *\n * Responsibilities:\n * - Apply model-level access control\n * - Delegate to repository for data fetching\n * - Apply entry-level access control (e.g. \"own entries only\")\n */\nclass GetRevisionByIdUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private repository: GetRevisionByIdRepository.Interface,\n private accessControl: AccessControl.Interface\n ) {}\n\n public async execute<T extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n id: string\n ): Promise<Result<CmsEntry<T>, UseCaseAbstraction.Error>> {\n const canAccess = await this.accessControl.canAccessEntry({ model });\n if (!canAccess) {\n return Result.fail(EntryNotAuthorizedError.fromModel(model));\n }\n\n const result = await this.repository.execute<T>(model, id);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n const entry = result.value;\n\n const canAccessEntry = await canAccessLoadedEntry(this.accessControl, model, entry);\n if (!canAccessEntry) {\n return Result.fail(EntryNotAuthorizedError.fromEntry(entry));\n }\n\n return Result.ok(entry);\n }\n}\n\nexport const GetRevisionByIdUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: GetRevisionByIdUseCaseImpl,\n dependencies: [GetRevisionByIdRepository, AccessControl]\n});\n"],"names":["GetRevisionByIdUseCaseImpl","repository","accessControl","model","id","canAccess","Result","EntryNotAuthorizedError","result","entry","canAccessEntry","canAccessLoadedEntry","GetRevisionByIdUseCase","createImplementation","UseCaseAbstraction","GetRevisionByIdRepository","AccessControl"],"mappings":";;;;;AAiBA,MAAMA;IACF,YACYC,UAA+C,EAC/CC,aAAsC,CAChD;aAFUD,UAAU,GAAVA;aACAC,aAAa,GAAbA;IACT;IAEH,MAAa,QACTC,KAAe,EACfC,EAAU,EAC4C;QACtD,MAAMC,YAAY,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;YAAEF;QAAM;QAClE,IAAI,CAACE,WACD,OAAOC,OAAO,IAAI,CAACC,wBAAwB,SAAS,CAACJ;QAGzD,MAAMK,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAIL,OAAOC;QAEvD,IAAII,OAAO,MAAM,IACb,OAAOF,OAAO,IAAI,CAACE,OAAO,KAAK;QAGnC,MAAMC,QAAQD,OAAO,KAAK;QAE1B,MAAME,iBAAiB,MAAMC,qBAAqB,IAAI,CAAC,aAAa,EAAER,OAAOM;QAC7E,IAAI,CAACC,gBACD,OAAOJ,OAAO,IAAI,CAACC,wBAAwB,SAAS,CAACE;QAGzD,OAAOH,OAAO,EAAE,CAACG;IACrB;AACJ;AAEO,MAAMG,gDAAyBC,qBAAqB;IACvD,aAAaC;IACb,gBAAgBd;IAChB,cAAc;QAACe;QAA2BC;KAAc;AAC5D"}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import type { CmsEntry, CmsEntryValues, CmsModel } from "../../../types/index.js";
|
|
3
|
-
import type { EntryNotFoundError, EntryPersistenceError } from "../../../domain/contentEntry/errors.js";
|
|
3
|
+
import type { EntryNotAuthorizedError, EntryNotFoundError, EntryPersistenceError } from "../../../domain/contentEntry/errors.js";
|
|
4
4
|
/**
|
|
5
5
|
* GetRevisionById Use Case - Fetches a specific entry revision by ID.
|
|
6
|
-
* Returns the entry or fails with EntryNotFoundError if not found or deleted
|
|
6
|
+
* Returns the entry or fails with EntryNotFoundError if not found or deleted,
|
|
7
|
+
* or with EntryNotAuthorizedError if the identity is not allowed to access it.
|
|
7
8
|
*/
|
|
8
9
|
export interface IGetRevisionByIdUseCase {
|
|
9
10
|
execute<T extends CmsEntryValues = CmsEntryValues>(model: CmsModel, id: string): Promise<Result<CmsEntry<T>, UseCaseError>>;
|
|
10
11
|
}
|
|
11
12
|
export interface IGetRevisionByIdUseCaseErrors {
|
|
13
|
+
notAuthorized: EntryNotAuthorizedError;
|
|
12
14
|
notFound: EntryNotFoundError;
|
|
13
15
|
storage: EntryPersistenceError;
|
|
14
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentEntry/GetRevisionById/abstractions.js","sources":["../../../../src/features/contentEntry/GetRevisionById/abstractions.ts"],"sourcesContent":["import { createAbstraction, Result } from \"@webiny/feature/api\";\nimport type { CmsEntry, CmsEntryValues, CmsModel } from \"~/types/index.js\";\nimport type {
|
|
1
|
+
{"version":3,"file":"features/contentEntry/GetRevisionById/abstractions.js","sources":["../../../../src/features/contentEntry/GetRevisionById/abstractions.ts"],"sourcesContent":["import { createAbstraction, Result } from \"@webiny/feature/api\";\nimport type { CmsEntry, CmsEntryValues, CmsModel } from \"~/types/index.js\";\nimport type {\n EntryNotAuthorizedError,\n EntryNotFoundError,\n EntryPersistenceError\n} from \"~/domain/contentEntry/errors.js\";\n\n/**\n * GetRevisionById Use Case - Fetches a specific entry revision by ID.\n * Returns the entry or fails with EntryNotFoundError if not found or deleted,\n * or with EntryNotAuthorizedError if the identity is not allowed to access it.\n */\nexport interface IGetRevisionByIdUseCase {\n execute<T extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n id: string\n ): Promise<Result<CmsEntry<T>, UseCaseError>>;\n}\n\nexport interface IGetRevisionByIdUseCaseErrors {\n notAuthorized: EntryNotAuthorizedError;\n notFound: EntryNotFoundError;\n storage: EntryPersistenceError;\n}\n\ntype UseCaseError = IGetRevisionByIdUseCaseErrors[keyof IGetRevisionByIdUseCaseErrors];\n\n/** Retrieve a specific entry revision by ID. */\nexport const GetRevisionByIdUseCase =\n createAbstraction<IGetRevisionByIdUseCase>(\"GetRevisionByIdUseCase\");\n\nexport namespace GetRevisionByIdUseCase {\n export type Interface = IGetRevisionByIdUseCase;\n export type Error = UseCaseError;\n export type Return<T extends CmsEntryValues = CmsEntryValues> = Promise<\n Result<CmsEntry<T>, UseCaseError>\n >;\n}\n\n/**\n * GetRevisionByIdRepository - Fetches entry revision from storage.\n * Returns the entry or fails with EntryNotFoundError if not found.\n */\nexport interface IGetRevisionByIdRepository {\n execute<T extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n id: string\n ): Promise<Result<CmsEntry<T>, RepositoryError>>;\n}\n\nexport interface IGetRevisionByIdRepositoryErrors {\n notFound: EntryNotFoundError;\n storage: EntryPersistenceError;\n}\n\ntype RepositoryError = IGetRevisionByIdRepositoryErrors[keyof IGetRevisionByIdRepositoryErrors];\n\nexport const GetRevisionByIdRepository = createAbstraction<IGetRevisionByIdRepository>(\n \"GetRevisionByIdRepository\"\n);\n\nexport namespace GetRevisionByIdRepository {\n export type Interface = IGetRevisionByIdRepository;\n export type Error = RepositoryError;\n}\n"],"names":["GetRevisionByIdUseCase","createAbstraction","GetRevisionByIdRepository"],"mappings":";AA6BO,MAAMA,yBACTC,kBAA2C;AA4BxC,MAAMC,4BAA4BD,kBACrC"}
|
|
@@ -2,6 +2,7 @@ import { Result, createImplementation } from "@webiny/feature/api";
|
|
|
2
2
|
import { GetRevisionsByEntryIdRepository, GetRevisionsByEntryIdUseCase } from "./abstractions.js";
|
|
3
3
|
import { AccessControl } from "../../shared/abstractions.js";
|
|
4
4
|
import { EntryNotAuthorizedError } from "../../../domain/contentEntry/errors.js";
|
|
5
|
+
import { filterAccessibleEntries } from "../shared/entryOwnerAccess.js";
|
|
5
6
|
class GetRevisionsByEntryIdUseCaseImpl {
|
|
6
7
|
constructor(repository, accessControl){
|
|
7
8
|
this.repository = repository;
|
|
@@ -14,7 +15,8 @@ class GetRevisionsByEntryIdUseCaseImpl {
|
|
|
14
15
|
if (!canAccess) return Result.fail(EntryNotAuthorizedError.fromModel(model));
|
|
15
16
|
const result = await this.repository.execute(model, entryId);
|
|
16
17
|
if (result.isFail()) return Result.fail(result.error);
|
|
17
|
-
|
|
18
|
+
const entries = await filterAccessibleEntries(this.accessControl, model, result.value);
|
|
19
|
+
return Result.ok(entries);
|
|
18
20
|
}
|
|
19
21
|
}
|
|
20
22
|
const GetRevisionsByEntryIdUseCase_GetRevisionsByEntryIdUseCase = createImplementation({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentEntry/GetRevisionsByEntryId/GetRevisionsByEntryIdUseCase.js","sources":["../../../../src/features/contentEntry/GetRevisionsByEntryId/GetRevisionsByEntryIdUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { GetRevisionsByEntryIdUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { GetRevisionsByEntryIdRepository } from \"./abstractions.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport type { CmsEntry, CmsEntryValues, CmsModel } from \"~/types/index.js\";\nimport { EntryNotAuthorizedError } from \"~/domain/contentEntry/errors.js\";\n\n/**\n * GetRevisionsByEntryIdUseCase - Orchestrates fetching all revisions for an entry.\n *\n * Responsibilities:\n * - Apply access control\n * - Delegate to repository for data fetching\n */\nclass GetRevisionsByEntryIdUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private repository: GetRevisionsByEntryIdRepository.Interface,\n private accessControl: AccessControl.Interface\n ) {}\n\n public async execute<T extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n entryId: string\n ): Promise<Result<CmsEntry<T>[], UseCaseAbstraction.Error>> {\n // Check access control\n const canAccess = await this.accessControl.canAccessEntry({ model });\n if (!canAccess) {\n return Result.fail(EntryNotAuthorizedError.fromModel(model));\n }\n\n // Delegate to repository\n const result = await this.repository.execute<T>(model, entryId);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n
|
|
1
|
+
{"version":3,"file":"features/contentEntry/GetRevisionsByEntryId/GetRevisionsByEntryIdUseCase.js","sources":["../../../../src/features/contentEntry/GetRevisionsByEntryId/GetRevisionsByEntryIdUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { GetRevisionsByEntryIdUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { GetRevisionsByEntryIdRepository } from \"./abstractions.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport type { CmsEntry, CmsEntryValues, CmsModel } from \"~/types/index.js\";\nimport { EntryNotAuthorizedError } from \"~/domain/contentEntry/errors.js\";\nimport { filterAccessibleEntries } from \"~/features/contentEntry/shared/entryOwnerAccess.js\";\n\n/**\n * GetRevisionsByEntryIdUseCase - Orchestrates fetching all revisions for an entry.\n *\n * Responsibilities:\n * - Apply access control\n * - Delegate to repository for data fetching\n */\nclass GetRevisionsByEntryIdUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private repository: GetRevisionsByEntryIdRepository.Interface,\n private accessControl: AccessControl.Interface\n ) {}\n\n public async execute<T extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n entryId: string\n ): Promise<Result<CmsEntry<T>[], UseCaseAbstraction.Error>> {\n // Check access control\n const canAccess = await this.accessControl.canAccessEntry({ model });\n if (!canAccess) {\n return Result.fail(EntryNotAuthorizedError.fromModel(model));\n }\n\n // Delegate to repository\n const result = await this.repository.execute<T>(model, entryId);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n // Drop entries the identity is not allowed to access (e.g. \"own entries only\").\n const entries = await filterAccessibleEntries(this.accessControl, model, result.value);\n\n return Result.ok(entries);\n }\n}\n\nexport const GetRevisionsByEntryIdUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: GetRevisionsByEntryIdUseCaseImpl,\n dependencies: [GetRevisionsByEntryIdRepository, AccessControl]\n});\n"],"names":["GetRevisionsByEntryIdUseCaseImpl","repository","accessControl","model","entryId","canAccess","Result","EntryNotAuthorizedError","result","entries","filterAccessibleEntries","GetRevisionsByEntryIdUseCase","createImplementation","UseCaseAbstraction","GetRevisionsByEntryIdRepository","AccessControl"],"mappings":";;;;;AAgBA,MAAMA;IACF,YACYC,UAAqD,EACrDC,aAAsC,CAChD;aAFUD,UAAU,GAAVA;aACAC,aAAa,GAAbA;IACT;IAEH,MAAa,QACTC,KAAe,EACfC,OAAe,EACyC;QAExD,MAAMC,YAAY,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;YAAEF;QAAM;QAClE,IAAI,CAACE,WACD,OAAOC,OAAO,IAAI,CAACC,wBAAwB,SAAS,CAACJ;QAIzD,MAAMK,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAIL,OAAOC;QAEvD,IAAII,OAAO,MAAM,IACb,OAAOF,OAAO,IAAI,CAACE,OAAO,KAAK;QAInC,MAAMC,UAAU,MAAMC,wBAAwB,IAAI,CAAC,aAAa,EAAEP,OAAOK,OAAO,KAAK;QAErF,OAAOF,OAAO,EAAE,CAACG;IACrB;AACJ;AAEO,MAAME,4DAA+BC,qBAAqB;IAC7D,aAAaC;IACb,gBAAgBb;IAChB,cAAc;QAACc;QAAiCC;KAAc;AAClE"}
|
|
@@ -5,6 +5,7 @@ import { EntryAfterUpdateEvent, EntryBeforeUpdateEvent } from "./events.js";
|
|
|
5
5
|
import { AccessControl } from "../../shared/abstractions.js";
|
|
6
6
|
import { GetRevisionByIdUseCase } from "../GetRevisionById/abstractions.js";
|
|
7
7
|
import { EntryLockedError, EntryNotAuthorizedError } from "../../../domain/contentEntry/errors.js";
|
|
8
|
+
import { isSingletonModel } from "../shared/entryOwnerAccess.js";
|
|
8
9
|
import { UpdateEntryDataFactory } from "../entryDataFactories/UpdateEntryDataFactory/index.js";
|
|
9
10
|
class UpdateEntryUseCaseImpl {
|
|
10
11
|
constructor(eventPublisher, repository, accessControl, getRevisionByIdUseCase, updateEntryDataFactory){
|
|
@@ -28,12 +29,14 @@ class UpdateEntryUseCaseImpl {
|
|
|
28
29
|
const dataResult = await this.updateEntryDataFactory.create(model, rawInput, originalEntry, options);
|
|
29
30
|
if (dataResult.isFail()) return Result.fail(dataResult.error);
|
|
30
31
|
const { entry, input } = dataResult.value;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
if (!isSingletonModel(model)) {
|
|
33
|
+
const canAccessEntry = await this.accessControl.canAccessEntry({
|
|
34
|
+
model,
|
|
35
|
+
entry,
|
|
36
|
+
rwd: "w"
|
|
37
|
+
});
|
|
38
|
+
if (!canAccessEntry) return Result.fail(EntryNotAuthorizedError.fromModel(model));
|
|
39
|
+
}
|
|
37
40
|
await this.eventPublisher.publish(new EntryBeforeUpdateEvent({
|
|
38
41
|
entry,
|
|
39
42
|
original: originalEntry,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/contentEntry/UpdateEntry/UpdateEntryUseCase.js","sources":["../../../../src/features/contentEntry/UpdateEntry/UpdateEntryUseCase.ts"],"sourcesContent":["import { createImplementation, Result } from \"@webiny/feature/api\";\nimport { UpdateEntryRepository, UpdateEntryUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { EntryEventPublisher } from \"~/features/contentEntry/EntryEventPublisher/index.js\";\nimport { EntryAfterUpdateEvent, EntryBeforeUpdateEvent } from \"./events.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport { GetRevisionByIdUseCase } from \"~/features/contentEntry/GetRevisionById/abstractions.js\";\nimport type {\n CmsEntry,\n CmsEntryValues,\n CmsModel,\n UpdateCmsEntryInput,\n UpdateCmsEntryOptionsInput\n} from \"~/types/index.js\";\nimport { EntryLockedError, EntryNotAuthorizedError } from \"~/domain/contentEntry/errors.js\";\nimport { UpdateEntryDataFactory } from \"~/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/index.js\";\n\nclass UpdateEntryUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private eventPublisher: EntryEventPublisher.Interface,\n private repository: UpdateEntryRepository.Interface,\n private accessControl: AccessControl.Interface,\n private getRevisionByIdUseCase: GetRevisionByIdUseCase.Interface,\n private updateEntryDataFactory: UpdateEntryDataFactory.Interface\n ) {}\n\n async execute<T extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n id: string,\n rawInput: UpdateCmsEntryInput<T>,\n options?: UpdateCmsEntryOptionsInput\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 if (originalEntry.locked) {\n return Result.fail(new EntryLockedError());\n }\n\n const dataResult = await this.updateEntryDataFactory.create<T>(\n model,\n rawInput,\n originalEntry,\n options\n );\n if (dataResult.isFail()) {\n return Result.fail(dataResult.error);\n }\n const { entry, input } = dataResult.value;\n\n const canAccessEntry = await this.accessControl.canAccessEntry({\n
|
|
1
|
+
{"version":3,"file":"features/contentEntry/UpdateEntry/UpdateEntryUseCase.js","sources":["../../../../src/features/contentEntry/UpdateEntry/UpdateEntryUseCase.ts"],"sourcesContent":["import { createImplementation, Result } from \"@webiny/feature/api\";\nimport { UpdateEntryRepository, UpdateEntryUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { EntryEventPublisher } from \"~/features/contentEntry/EntryEventPublisher/index.js\";\nimport { EntryAfterUpdateEvent, EntryBeforeUpdateEvent } from \"./events.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport { GetRevisionByIdUseCase } from \"~/features/contentEntry/GetRevisionById/abstractions.js\";\nimport type {\n CmsEntry,\n CmsEntryValues,\n CmsModel,\n UpdateCmsEntryInput,\n UpdateCmsEntryOptionsInput\n} from \"~/types/index.js\";\nimport { EntryLockedError, EntryNotAuthorizedError } from \"~/domain/contentEntry/errors.js\";\nimport { isSingletonModel } from \"~/features/contentEntry/shared/entryOwnerAccess.js\";\nimport { UpdateEntryDataFactory } from \"~/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/index.js\";\n\nclass UpdateEntryUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private eventPublisher: EntryEventPublisher.Interface,\n private repository: UpdateEntryRepository.Interface,\n private accessControl: AccessControl.Interface,\n private getRevisionByIdUseCase: GetRevisionByIdUseCase.Interface,\n private updateEntryDataFactory: UpdateEntryDataFactory.Interface\n ) {}\n\n async execute<T extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n id: string,\n rawInput: UpdateCmsEntryInput<T>,\n options?: UpdateCmsEntryOptionsInput\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 if (originalEntry.locked) {\n return Result.fail(new EntryLockedError());\n }\n\n const dataResult = await this.updateEntryDataFactory.create<T>(\n model,\n rawInput,\n originalEntry,\n options\n );\n if (dataResult.isFail()) {\n return Result.fail(dataResult.error);\n }\n const { entry, input } = dataResult.value;\n\n // Singleton entries are shared by everyone who can access the model, so the\n // entry-level (owner) check is skipped for them.\n if (!isSingletonModel(model)) {\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\n await this.eventPublisher.publish(\n new EntryBeforeUpdateEvent({ entry, original: originalEntry, input, model })\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 EntryAfterUpdateEvent({\n entry,\n original: originalEntry,\n input,\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 UpdateEntryUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: UpdateEntryUseCaseImpl,\n dependencies: [\n EntryEventPublisher,\n UpdateEntryRepository,\n AccessControl,\n GetRevisionByIdUseCase,\n UpdateEntryDataFactory\n ]\n});\n"],"names":["UpdateEntryUseCaseImpl","eventPublisher","repository","accessControl","getRevisionByIdUseCase","updateEntryDataFactory","model","id","rawInput","options","canAccess","Result","EntryNotAuthorizedError","result","originalEntry","EntryLockedError","dataResult","entry","input","isSingletonModel","canAccessEntry","EntryBeforeUpdateEvent","updateResult","EntryAfterUpdateEvent","error","UpdateEntryUseCase","createImplementation","UseCaseAbstraction","EntryEventPublisher","UpdateEntryRepository","AccessControl","GetRevisionByIdUseCase","UpdateEntryDataFactory"],"mappings":";;;;;;;;;AAiBA,MAAMA;IACF,YACYC,cAA6C,EAC7CC,UAA2C,EAC3CC,aAAsC,EACtCC,sBAAwD,EACxDC,sBAAwD,CAClE;aALUJ,cAAc,GAAdA;aACAC,UAAU,GAAVA;aACAC,aAAa,GAAbA;aACAC,sBAAsB,GAAtBA;aACAC,sBAAsB,GAAtBA;IACT;IAEH,MAAM,QACFC,KAAe,EACfC,EAAU,EACVC,QAAgC,EAChCC,OAAoC,EACkB;QACtD,MAAMC,YAAY,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;YAAEJ;YAAO,KAAK;QAAI;QAC5E,IAAI,CAACI,WACD,OAAOC,OAAO,IAAI,CAACC,wBAAwB,SAAS,CAACN;QAGzD,IAAI;YACA,MAAMO,SAAS,MAAM,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAIP,OAAOC;YAEnE,IAAIM,OAAO,MAAM,IACb,OAAOF,OAAO,IAAI,CAACE,OAAO,KAAK;YAGnC,MAAMC,gBAAgBD,OAAO,KAAK;YAElC,IAAIC,cAAc,MAAM,EACpB,OAAOH,OAAO,IAAI,CAAC,IAAII;YAG3B,MAAMC,aAAa,MAAM,IAAI,CAAC,sBAAsB,CAAC,MAAM,CACvDV,OACAE,UACAM,eACAL;YAEJ,IAAIO,WAAW,MAAM,IACjB,OAAOL,OAAO,IAAI,CAACK,WAAW,KAAK;YAEvC,MAAM,EAAEC,KAAK,EAAEC,KAAK,EAAE,GAAGF,WAAW,KAAK;YAIzC,IAAI,CAACG,iBAAiBb,QAAQ;gBAC1B,MAAMc,iBAAiB,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;oBAC3Dd;oBACAW;oBACA,KAAK;gBACT;gBAEA,IAAI,CAACG,gBACD,OAAOT,OAAO,IAAI,CAACC,wBAAwB,SAAS,CAACN;YAE7D;YAEA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIe,uBAAuB;gBAAEJ;gBAAO,UAAUH;gBAAeI;gBAAOZ;YAAM;YAG9E,MAAMgB,eAAe,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAChB,OAAOW;YAC1D,IAAIK,aAAa,MAAM,IACnB,OAAOX,OAAO,IAAI,CAACW,aAAa,KAAK;YAGzC,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIC,sBAAsB;gBACtBN;gBACA,UAAUH;gBACVI;gBACAZ;YACJ;YAGJ,OAAOK,OAAO,EAAE,CAACM;QACrB,EAAE,OAAOO,OAAO;YACZ,OAAOb,OAAO,IAAI,CAACa;QACvB;IACJ;AACJ;AAEO,MAAMC,wCAAqBC,qBAAqB;IACnD,aAAaC;IACb,gBAAgB3B;IAChB,cAAc;QACV4B;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|