@webiny/api-headless-cms 6.4.12-beta.5 → 6.4.12-beta.7

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.
Files changed (52) hide show
  1. package/context.js +3 -0
  2. package/context.js.map +1 -1
  3. package/crud/contentModel/validation.js +4 -4
  4. package/crud/contentModel/validation.js.map +1 -1
  5. package/domain/contentModel/schemas.js +3 -3
  6. package/domain/contentModel/schemas.js.map +1 -1
  7. package/domain/contentModelGroup/validation.js +2 -2
  8. package/domain/contentModelGroup/validation.js.map +1 -1
  9. package/export/crud/importing.js +8 -0
  10. package/export/crud/importing.js.map +1 -1
  11. package/features/contentEntry/GetEntriesByIds/GetEntriesByIdsUseCase.js +3 -1
  12. package/features/contentEntry/GetEntriesByIds/GetEntriesByIdsUseCase.js.map +1 -1
  13. package/features/contentEntry/GetLatestEntriesByIds/GetLatestEntriesByIdsUseCase.js +3 -1
  14. package/features/contentEntry/GetLatestEntriesByIds/GetLatestEntriesByIdsUseCase.js.map +1 -1
  15. package/features/contentEntry/GetLatestRevisionByEntryId/BaseUseCase.js +5 -1
  16. package/features/contentEntry/GetLatestRevisionByEntryId/BaseUseCase.js.map +1 -1
  17. package/features/contentEntry/GetPreviousRevisionByEntryId/BaseUseCase.js +5 -1
  18. package/features/contentEntry/GetPreviousRevisionByEntryId/BaseUseCase.js.map +1 -1
  19. package/features/contentEntry/GetPublishedEntriesByIds/GetPublishedEntriesByIdsUseCase.js +3 -1
  20. package/features/contentEntry/GetPublishedEntriesByIds/GetPublishedEntriesByIdsUseCase.js.map +1 -1
  21. package/features/contentEntry/GetPublishedRevisionByEntryId/GetPublishedRevisionByEntryIdUseCase.d.ts +5 -1
  22. package/features/contentEntry/GetPublishedRevisionByEntryId/GetPublishedRevisionByEntryIdUseCase.js +16 -3
  23. package/features/contentEntry/GetPublishedRevisionByEntryId/GetPublishedRevisionByEntryIdUseCase.js.map +1 -1
  24. package/features/contentEntry/GetPublishedRevisionByEntryId/abstractions.d.ts +2 -1
  25. package/features/contentEntry/GetPublishedRevisionByEntryId/abstractions.js.map +1 -1
  26. package/features/contentEntry/GetRevisionById/GetRevisionByIdUseCase.d.ts +7 -2
  27. package/features/contentEntry/GetRevisionById/GetRevisionByIdUseCase.js +18 -4
  28. package/features/contentEntry/GetRevisionById/GetRevisionByIdUseCase.js.map +1 -1
  29. package/features/contentEntry/GetRevisionById/abstractions.d.ts +4 -2
  30. package/features/contentEntry/GetRevisionById/abstractions.js.map +1 -1
  31. package/features/contentEntry/GetRevisionsByEntryId/GetRevisionsByEntryIdUseCase.js +3 -1
  32. package/features/contentEntry/GetRevisionsByEntryId/GetRevisionsByEntryIdUseCase.js.map +1 -1
  33. package/features/contentEntry/UpdateEntry/UpdateEntryUseCase.js +9 -6
  34. package/features/contentEntry/UpdateEntry/UpdateEntryUseCase.js.map +1 -1
  35. package/features/contentEntry/shared/entryOwnerAccess.d.ts +15 -0
  36. package/features/contentEntry/shared/entryOwnerAccess.js +21 -0
  37. package/features/contentEntry/shared/entryOwnerAccess.js.map +1 -0
  38. package/features/contentModel/CreateModelFrom/CreateModelFromUseCase.js +2 -1
  39. package/features/contentModel/CreateModelFrom/CreateModelFromUseCase.js.map +1 -1
  40. package/features/contentModelGroup/DeleteGroup/DeleteGroupUseCase.js +2 -1
  41. package/features/contentModelGroup/DeleteGroup/DeleteGroupUseCase.js.map +1 -1
  42. package/features/contentModelGroup/UpdateGroup/UpdateGroupUseCase.js +2 -1
  43. package/features/contentModelGroup/UpdateGroup/UpdateGroupUseCase.js.map +1 -1
  44. package/graphql/handleRequest.js +18 -9
  45. package/graphql/handleRequest.js.map +1 -1
  46. package/graphql/schema/contentEntries.js +15 -5
  47. package/graphql/schema/contentEntries.js.map +1 -1
  48. package/graphql/schema/contentModelGroups.js +11 -12
  49. package/graphql/schema/contentModelGroups.js.map +1 -1
  50. package/graphql/schema/contentModels.js +1 -1
  51. package/graphql/schema/contentModels.js.map +1 -1
  52. package/package.json +29 -29
@@ -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
- return Result.ok(result.value);
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(result.value);\n }\n}\n\nexport const GetPublishedRevisionByEntryIdUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: GetPublishedRevisionByEntryIdUseCaseImpl,\n dependencies: [GetPublishedRevisionByEntryIdRepository]\n});\n"],"names":["GetPublishedRevisionByEntryIdUseCaseImpl","repository","model","entryId","result","Result","GetPublishedRevisionByEntryIdUseCase","createImplementation","UseCaseAbstraction","GetPublishedRevisionByEntryIdRepository"],"mappings":";;AAcA,MAAMA;IACF,YAA2BC,UAA6D,CAAE;aAA/DA,UAAU,GAAVA;IAAgE;IAE3F,MAAa,QACTC,KAAe,EACfC,OAAe,EAC8C;QAE7D,MAAMC,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAIF,OAAOC;QAEvD,IAAIC,OAAO,MAAM,IACb,OAAOC,OAAO,IAAI,CAACD,OAAO,KAAK;QAGnC,OAAOC,OAAO,EAAE,CAACD,OAAO,KAAK;IACjC;AACJ;AAEO,MAAME,4EAAuCC,qBAAqB;IACrE,aAAaC;IACb,gBAAgBR;IAChB,cAAc;QAACS;KAAwC;AAC3D"}
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 { EntryNotFoundError, type EntryPersistenceError } 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 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":";AAsBO,MAAMA,uCACTC,kBACI;AA6BD,MAAMC,0CACTD,kBACI"}
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
- * This is a simple query use case that delegates to the repository.
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
- constructor(repository: GetRevisionByIdRepository.Interface);
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
- return this.repository.execute(model, id);
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 * This is a simple query use case that delegates to the repository.\n */\nclass GetRevisionByIdUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(private repository: GetRevisionByIdRepository.Interface) {}\n\n public async execute<T extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n id: string\n ): Promise<Result<CmsEntry<T>, UseCaseAbstraction.Error>> {\n return this.repository.execute<T>(model, id);\n }\n}\n\nexport const GetRevisionByIdUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: GetRevisionByIdUseCaseImpl,\n dependencies: [GetRevisionByIdRepository]\n});\n"],"names":["GetRevisionByIdUseCaseImpl","repository","model","id","GetRevisionByIdUseCase","createImplementation","UseCaseAbstraction","GetRevisionByIdRepository"],"mappings":";;AAWA,MAAMA;IACF,YAA2BC,UAA+C,CAAE;aAAjDA,UAAU,GAAVA;IAAkD;IAE7E,MAAa,QACTC,KAAe,EACfC,EAAU,EAC4C;QACtD,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAID,OAAOC;IAC7C;AACJ;AAEO,MAAMC,gDAAyBC,qBAAqB;IACvD,aAAaC;IACb,gBAAgBN;IAChB,cAAc;QAACO;KAA0B;AAC7C"}
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 { EntryNotFoundError, EntryPersistenceError } 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 */\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 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":";AAuBO,MAAMA,yBACTC,kBAA2C;AA4BxC,MAAMC,4BAA4BD,kBACrC"}
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
- return Result.ok(result.value);
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 return Result.ok(result.value);\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","GetRevisionsByEntryIdUseCase","createImplementation","UseCaseAbstraction","GetRevisionsByEntryIdRepository","AccessControl"],"mappings":";;;;AAeA,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;QAGnC,OAAOF,OAAO,EAAE,CAACE,OAAO,KAAK;IACjC;AACJ;AAEO,MAAMC,4DAA+BC,qBAAqB;IAC7D,aAAaC;IACb,gBAAgBX;IAChB,cAAc;QAACY;QAAiCC;KAAc;AAClE"}
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){
@@ -26,12 +27,14 @@ class UpdateEntryUseCaseImpl {
26
27
  const originalEntry = result.value;
27
28
  if (originalEntry.locked) return Result.fail(new EntryLockedError());
28
29
  const { entry, input } = await this.updateEntryDataFactory.create(model, rawInput, originalEntry, options);
29
- const canAccessEntry = await this.accessControl.canAccessEntry({
30
- model,
31
- entry,
32
- rwd: "w"
33
- });
34
- if (!canAccessEntry) return Result.fail(EntryNotAuthorizedError.fromModel(model));
30
+ if (!isSingletonModel(model)) {
31
+ const canAccessEntry = await this.accessControl.canAccessEntry({
32
+ model,
33
+ entry,
34
+ rwd: "w"
35
+ });
36
+ if (!canAccessEntry) return Result.fail(EntryNotAuthorizedError.fromModel(model));
37
+ }
35
38
  await this.eventPublisher.publish(new EntryBeforeUpdateEvent({
36
39
  entry,
37
40
  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 { EventPublisher } from \"@webiny/api-core/features/eventPublisher/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: EventPublisher.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 { entry, input } = await this.updateEntryDataFactory.create<T>(\n model,\n rawInput,\n originalEntry,\n options\n );\n\n const canAccessEntry = await this.accessControl.canAccessEntry({\n model,\n entry,\n rwd: \"w\"\n });\n\n if (!canAccessEntry) {\n return Result.fail(EntryNotAuthorizedError.fromModel(model));\n }\n\n await this.eventPublisher.publish(\n new 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 EventPublisher,\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","entry","input","canAccessEntry","EntryBeforeUpdateEvent","updateResult","EntryAfterUpdateEvent","error","UpdateEntryUseCase","createImplementation","UseCaseAbstraction","EventPublisher","UpdateEntryRepository","AccessControl","GetRevisionByIdUseCase","UpdateEntryDataFactory"],"mappings":";;;;;;;;AAgBA,MAAMA;IACF,YACYC,cAAwC,EACxCC,UA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,IAAIC,sBAAsB;gBACtBL;gBACA,UAAUF;gBACVG;gBACAX;YACJ;YAGJ,OAAOK,OAAO,EAAE,CAACK;QACrB,EAAE,OAAOM,OAAO;YACZ,OAAOX,OAAO,IAAI,CAACW;QACvB;IACJ;AACJ;AAEO,MAAMC,wCAAqBC,qBAAqB;IACnD,aAAaC;IACb,gBAAgBzB;IAChB,cAAc;QACV0B;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
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 { EventPublisher } from \"@webiny/api-core/features/eventPublisher/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: EventPublisher.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 { entry, input } = await this.updateEntryDataFactory.create<T>(\n model,\n rawInput,\n originalEntry,\n options\n );\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 EventPublisher,\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","entry","input","isSingletonModel","canAccessEntry","EntryBeforeUpdateEvent","updateResult","EntryAfterUpdateEvent","error","UpdateEntryUseCase","createImplementation","UseCaseAbstraction","EventPublisher","UpdateEntryRepository","AccessControl","GetRevisionByIdUseCase","UpdateEntryDataFactory"],"mappings":";;;;;;;;;AAiBA,MAAMA;IACF,YACYC,cAAwC,EACxCC,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,MAAM,EAAEC,KAAK,EAAEC,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,sBAAsB,CAAC,MAAM,CAC7DX,OACAE,UACAM,eACAL;YAKJ,IAAI,CAACS,iBAAiBZ,QAAQ;gBAC1B,MAAMa,iBAAiB,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;oBAC3Db;oBACAU;oBACA,KAAK;gBACT;gBAEA,IAAI,CAACG,gBACD,OAAOR,OAAO,IAAI,CAACC,wBAAwB,SAAS,CAACN;YAE7D;YAEA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIc,uBAAuB;gBAAEJ;gBAAO,UAAUF;gBAAeG;gBAAOX;YAAM;YAG9E,MAAMe,eAAe,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAACf,OAAOU;YAC1D,IAAIK,aAAa,MAAM,IACnB,OAAOV,OAAO,IAAI,CAACU,aAAa,KAAK;YAGzC,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIC,sBAAsB;gBACtBN;gBACA,UAAUF;gBACVG;gBACAX;YACJ;YAGJ,OAAOK,OAAO,EAAE,CAACK;QACrB,EAAE,OAAOO,OAAO;YACZ,OAAOZ,OAAO,IAAI,CAACY;QACvB;IACJ;AACJ;AAEO,MAAMC,wCAAqBC,qBAAqB;IACnD,aAAaC;IACb,gBAAgB1B;IAChB,cAAc;QACV2B;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
@@ -0,0 +1,15 @@
1
+ import type { AccessControl } from "../../../features/shared/abstractions.js";
2
+ import type { CmsEntry, CmsEntryValues, CmsModel } from "../../../types/index.js";
3
+ /**
4
+ * Entry-level (owner) access checks for entries loaded from storage.
5
+ *
6
+ * Model-level checks (`canAccessEntry({ model })`) cannot tell whether a user with
7
+ * "own entries only" permission may see a specific entry, so every read use case must
8
+ * run the loaded entries through these helpers as well.
9
+ *
10
+ * Singleton models are exempt: there is only one entry and it is shared by everyone
11
+ * who can access the model.
12
+ */
13
+ export declare const isSingletonModel: (model: Pick<CmsModel, "tags">) => boolean;
14
+ export declare const canAccessLoadedEntry: (accessControl: AccessControl.Interface, model: CmsModel, entry: Pick<CmsEntry, "entryId" | "createdBy">) => Promise<boolean>;
15
+ export declare const filterAccessibleEntries: <T extends CmsEntryValues = CmsEntryValues>(accessControl: AccessControl.Interface, model: CmsModel, entries: CmsEntry<T>[]) => Promise<CmsEntry<T>[]>;
@@ -0,0 +1,21 @@
1
+ import { CMS_MODEL_SINGLETON_TAG } from "../../../constants.js";
2
+ const isSingletonModel = (model)=>!!model.tags?.includes(CMS_MODEL_SINGLETON_TAG);
3
+ const canAccessLoadedEntry = async (accessControl, model, entry)=>{
4
+ if (isSingletonModel(model)) return true;
5
+ return accessControl.canAccessEntry({
6
+ model,
7
+ entry
8
+ });
9
+ };
10
+ const filterAccessibleEntries = async (accessControl, model, entries)=>{
11
+ if (isSingletonModel(model)) return entries;
12
+ const result = [];
13
+ for (const entry of entries)if (await accessControl.canAccessEntry({
14
+ model,
15
+ entry
16
+ })) result.push(entry);
17
+ return result;
18
+ };
19
+ export { canAccessLoadedEntry, filterAccessibleEntries, isSingletonModel };
20
+
21
+ //# sourceMappingURL=entryOwnerAccess.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/contentEntry/shared/entryOwnerAccess.js","sources":["../../../../src/features/contentEntry/shared/entryOwnerAccess.ts"],"sourcesContent":["import type { AccessControl } from \"~/features/shared/abstractions.js\";\nimport type { CmsEntry, CmsEntryValues, CmsModel } from \"~/types/index.js\";\nimport { CMS_MODEL_SINGLETON_TAG } from \"~/constants.js\";\n\n/**\n * Entry-level (owner) access checks for entries loaded from storage.\n *\n * Model-level checks (`canAccessEntry({ model })`) cannot tell whether a user with\n * \"own entries only\" permission may see a specific entry, so every read use case must\n * run the loaded entries through these helpers as well.\n *\n * Singleton models are exempt: there is only one entry and it is shared by everyone\n * who can access the model.\n */\nexport const isSingletonModel = (model: Pick<CmsModel, \"tags\">): boolean => {\n return !!model.tags?.includes(CMS_MODEL_SINGLETON_TAG);\n};\n\nexport const canAccessLoadedEntry = async (\n accessControl: AccessControl.Interface,\n model: CmsModel,\n entry: Pick<CmsEntry, \"entryId\" | \"createdBy\">\n): Promise<boolean> => {\n if (isSingletonModel(model)) {\n return true;\n }\n return accessControl.canAccessEntry({ model, entry });\n};\n\nexport const filterAccessibleEntries = async <T extends CmsEntryValues = CmsEntryValues>(\n accessControl: AccessControl.Interface,\n model: CmsModel,\n entries: CmsEntry<T>[]\n): Promise<CmsEntry<T>[]> => {\n if (isSingletonModel(model)) {\n return entries;\n }\n const result: CmsEntry<T>[] = [];\n for (const entry of entries) {\n if (await accessControl.canAccessEntry({ model, entry })) {\n result.push(entry);\n }\n }\n return result;\n};\n"],"names":["isSingletonModel","model","CMS_MODEL_SINGLETON_TAG","canAccessLoadedEntry","accessControl","entry","filterAccessibleEntries","entries","result"],"mappings":";AAcO,MAAMA,mBAAmB,CAACC,QACtB,CAAC,CAACA,MAAM,IAAI,EAAE,SAASC;AAG3B,MAAMC,uBAAuB,OAChCC,eACAH,OACAI;IAEA,IAAIL,iBAAiBC,QACjB,OAAO;IAEX,OAAOG,cAAc,cAAc,CAAC;QAAEH;QAAOI;IAAM;AACvD;AAEO,MAAMC,0BAA0B,OACnCF,eACAH,OACAM;IAEA,IAAIP,iBAAiBC,QACjB,OAAOM;IAEX,MAAMC,SAAwB,EAAE;IAChC,KAAK,MAAMH,SAASE,QAChB,IAAI,MAAMH,cAAc,cAAc,CAAC;QAAEH;QAAOI;IAAM,IAClDG,OAAO,IAAI,CAACH;IAGpB,OAAOG;AACX"}
@@ -5,7 +5,7 @@ import { ModelAfterCreateFromEvent, ModelBeforeCreateFromEvent, ModelCreateFromE
5
5
  import { AccessControl } from "../../shared/abstractions.js";
6
6
  import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
7
7
  import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
8
- import { ModelNotAuthorizedError, ModelValidationError } from "../../../domain/contentModel/errors.js";
8
+ import { ModelNotAuthorizedError, ModelNotFoundError, ModelValidationError } from "../../../domain/contentModel/errors.js";
9
9
  import { createZodError, removeUndefinedValues } from "@webiny/utils";
10
10
  import { createModelCreateFromValidation } from "../../../domain/contentModel/schemas.js";
11
11
  import { GetModelUseCase } from "../GetModel/index.js";
@@ -26,6 +26,7 @@ class CreateModelFromUseCaseImpl {
26
26
  const getResult = await this.getModelUseCase.execute(modelId);
27
27
  if (getResult.isFail()) return getResult;
28
28
  const original = getResult.value;
29
+ if (original.isPrivate) return Result.fail(new ModelNotFoundError(modelId));
29
30
  const validationResult = await createModelCreateFromValidation().safeParseAsync({
30
31
  ...input,
31
32
  description: input.description || original.description
@@ -1 +1 @@
1
- {"version":3,"file":"features/contentModel/CreateModelFrom/CreateModelFromUseCase.js","sources":["../../../../src/features/contentModel/CreateModelFrom/CreateModelFromUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { CreateModelFromUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { CreateModelFromRepository } from \"./abstractions.js\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport { ModelBeforeCreateFromEvent } from \"./events.js\";\nimport { ModelAfterCreateFromEvent } from \"./events.js\";\nimport { ModelCreateFromErrorEvent } from \"./events.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { ModelNotAuthorizedError, ModelValidationError } from \"~/domain/contentModel/errors.js\";\nimport { createZodError } from \"@webiny/utils\";\nimport { removeUndefinedValues } from \"@webiny/utils\";\nimport { createModelCreateFromValidation } from \"~/domain/contentModel/schemas.js\";\nimport type { CmsModel } from \"~/types/index.js\";\nimport type { CmsModelCreateFromInput } from \"~/types/index.js\";\nimport { GetModelUseCase } from \"~/features/contentModel/GetModel/index.js\";\n\n/**\n * CreateModelFromUseCase - Clone/copy a model from existing model.\n *\n * Responsibilities:\n * - Validate input (Zod)\n * - Fetch original model\n * - Create new model preserving fields and layout\n * - Handle group changes\n * - Access control checks\n * - Publish before event\n * - Delegate to repository for validation and persistence\n * - Publish after event or error event\n *\n * Note: Repository handles domain validations (modelId generation, uniqueness, etc.)\n */\nclass CreateModelFromUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private getModelUseCase: GetModelUseCase.Interface,\n private eventPublisher: EventPublisher.Interface,\n private repository: CreateModelFromRepository.Interface,\n private accessControl: AccessControl.Interface,\n private tenantContext: TenantContext.Interface,\n private identityContext: IdentityContext.Interface\n ) {}\n\n async execute(\n modelId: string,\n input: CmsModelCreateFromInput\n ): Promise<Result<CmsModel, UseCaseAbstraction.Error>> {\n // Initial access control check\n const canAccess = await this.accessControl.canAccessModel({ rwd: \"w\" });\n if (!canAccess) {\n return Result.fail(new ModelNotAuthorizedError());\n }\n\n // Get the original model (with access control check)\n const getResult = await this.getModelUseCase.execute(modelId);\n if (getResult.isFail()) {\n return getResult;\n }\n\n const original = getResult.value;\n\n // Validate input (merge with original description if not provided)\n const validationResult = await createModelCreateFromValidation().safeParseAsync({\n ...input,\n description: input.description || original.description\n });\n\n if (!validationResult.success) {\n const zodError = createZodError(validationResult.error);\n return Result.fail(new ModelValidationError(zodError.message));\n }\n\n const data = removeUndefinedValues(validationResult.data);\n\n // Create new model from original (preserve fields and layout)\n const identity = this.identityContext.getIdentity();\n const tenant = this.tenantContext.getTenant();\n\n const model: CmsModel = {\n ...original,\n isPlugin: undefined,\n group: input.group || original.group,\n singularApiName: data.singularApiName,\n pluralApiName: data.pluralApiName,\n icon: data.icon,\n name: data.name,\n modelId: data.modelId || \"\", // Will be set by repository\n description: data.description || \"\",\n createdBy: {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n },\n createdOn: new Date().toISOString(),\n savedOn: new Date().toISOString(),\n tenant: original.tenant || tenant.id\n };\n\n // Access control check on the new model\n const canAccessModel = await this.accessControl.canAccessModel({ model, rwd: \"w\" });\n if (!canAccessModel) {\n return Result.fail(ModelNotAuthorizedError.fromModel(model));\n }\n\n // Publish before event\n await this.eventPublisher.publish(\n new ModelBeforeCreateFromEvent({ model, original, input: data })\n );\n\n // Persist via repository (repository will validate and set modelId)\n const result = await this.repository.execute(model);\n if (result.isFail()) {\n // Publish error event\n await this.eventPublisher.publish(\n new ModelCreateFromErrorEvent({\n input: data,\n model,\n original,\n error: result.error\n })\n );\n return Result.fail(result.error);\n }\n\n // Publish after event\n await this.eventPublisher.publish(\n new ModelAfterCreateFromEvent({\n model: result.value,\n original\n })\n );\n\n return Result.ok(result.value);\n }\n}\n\nexport const CreateModelFromUseCase = UseCaseAbstraction.createImplementation({\n implementation: CreateModelFromUseCaseImpl,\n dependencies: [\n GetModelUseCase,\n EventPublisher,\n CreateModelFromRepository,\n AccessControl,\n TenantContext,\n IdentityContext\n ]\n});\n"],"names":["CreateModelFromUseCaseImpl","getModelUseCase","eventPublisher","repository","accessControl","tenantContext","identityContext","modelId","input","canAccess","Result","ModelNotAuthorizedError","getResult","original","validationResult","createModelCreateFromValidation","zodError","createZodError","ModelValidationError","data","removeUndefinedValues","identity","tenant","model","undefined","Date","canAccessModel","ModelBeforeCreateFromEvent","result","ModelCreateFromErrorEvent","ModelAfterCreateFromEvent","CreateModelFromUseCase","UseCaseAbstraction","GetModelUseCase","EventPublisher","CreateModelFromRepository","AccessControl","TenantContext","IdentityContext"],"mappings":";;;;;;;;;;;AAiCA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,cAAwC,EACxCC,UAA+C,EAC/CC,aAAsC,EACtCC,aAAsC,EACtCC,eAA0C,CACpD;aANUL,eAAe,GAAfA;aACAC,cAAc,GAAdA;aACAC,UAAU,GAAVA;aACAC,aAAa,GAAbA;aACAC,aAAa,GAAbA;aACAC,eAAe,GAAfA;IACT;IAEH,MAAM,QACFC,OAAe,EACfC,KAA8B,EACqB;QAEnD,MAAMC,YAAY,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;YAAE,KAAK;QAAI;QACrE,IAAI,CAACA,WACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAI3B,MAAMC,YAAY,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAACL;QACrD,IAAIK,UAAU,MAAM,IAChB,OAAOA;QAGX,MAAMC,WAAWD,UAAU,KAAK;QAGhC,MAAME,mBAAmB,MAAMC,kCAAkC,cAAc,CAAC;YAC5E,GAAGP,KAAK;YACR,aAAaA,MAAM,WAAW,IAAIK,SAAS,WAAW;QAC1D;QAEA,IAAI,CAACC,iBAAiB,OAAO,EAAE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AI,CAACkB,OAAO,KAAK;QACnC;QAGA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIE,0BAA0B;YAC1B,OAAOF,OAAO,KAAK;YACnBf;QACJ;QAGJ,OAAOH,OAAO,EAAE,CAACkB,OAAO,KAAK;IACjC;AACJ;AAEO,MAAMG,gDAAyBC,uBAAAA,oBAAuC,CAAC;IAC1E,gBAAgBhC;IAChB,cAAc;QACViC;QACAC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
1
+ {"version":3,"file":"features/contentModel/CreateModelFrom/CreateModelFromUseCase.js","sources":["../../../../src/features/contentModel/CreateModelFrom/CreateModelFromUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { CreateModelFromUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { CreateModelFromRepository } from \"./abstractions.js\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport { ModelBeforeCreateFromEvent } from \"./events.js\";\nimport { ModelAfterCreateFromEvent } from \"./events.js\";\nimport { ModelCreateFromErrorEvent } from \"./events.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport {\n ModelNotAuthorizedError,\n ModelNotFoundError,\n ModelValidationError\n} from \"~/domain/contentModel/errors.js\";\nimport { createZodError } from \"@webiny/utils\";\nimport { removeUndefinedValues } from \"@webiny/utils\";\nimport { createModelCreateFromValidation } from \"~/domain/contentModel/schemas.js\";\nimport type { CmsModel } from \"~/types/index.js\";\nimport type { CmsModelCreateFromInput } from \"~/types/index.js\";\nimport { GetModelUseCase } from \"~/features/contentModel/GetModel/index.js\";\n\n/**\n * CreateModelFromUseCase - Clone/copy a model from existing model.\n *\n * Responsibilities:\n * - Validate input (Zod)\n * - Fetch original model\n * - Create new model preserving fields and layout\n * - Handle group changes\n * - Access control checks\n * - Publish before event\n * - Delegate to repository for validation and persistence\n * - Publish after event or error event\n *\n * Note: Repository handles domain validations (modelId generation, uniqueness, etc.)\n */\nclass CreateModelFromUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private getModelUseCase: GetModelUseCase.Interface,\n private eventPublisher: EventPublisher.Interface,\n private repository: CreateModelFromRepository.Interface,\n private accessControl: AccessControl.Interface,\n private tenantContext: TenantContext.Interface,\n private identityContext: IdentityContext.Interface\n ) {}\n\n async execute(\n modelId: string,\n input: CmsModelCreateFromInput\n ): Promise<Result<CmsModel, UseCaseAbstraction.Error>> {\n // Initial access control check\n const canAccess = await this.accessControl.canAccessModel({ rwd: \"w\" });\n if (!canAccess) {\n return Result.fail(new ModelNotAuthorizedError());\n }\n\n // Get the original model (with access control check)\n const getResult = await this.getModelUseCase.execute(modelId);\n if (getResult.isFail()) {\n return getResult;\n }\n\n const original = getResult.value;\n\n // Private models are internal; they can't be used as a source for new models.\n if (original.isPrivate) {\n return Result.fail(new ModelNotFoundError(modelId));\n }\n\n // Validate input (merge with original description if not provided)\n const validationResult = await createModelCreateFromValidation().safeParseAsync({\n ...input,\n description: input.description || original.description\n });\n\n if (!validationResult.success) {\n const zodError = createZodError(validationResult.error);\n return Result.fail(new ModelValidationError(zodError.message));\n }\n\n const data = removeUndefinedValues(validationResult.data);\n\n // Create new model from original (preserve fields and layout)\n const identity = this.identityContext.getIdentity();\n const tenant = this.tenantContext.getTenant();\n\n const model: CmsModel = {\n ...original,\n isPlugin: undefined,\n group: input.group || original.group,\n singularApiName: data.singularApiName,\n pluralApiName: data.pluralApiName,\n icon: data.icon,\n name: data.name,\n modelId: data.modelId || \"\", // Will be set by repository\n description: data.description || \"\",\n createdBy: {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n },\n createdOn: new Date().toISOString(),\n savedOn: new Date().toISOString(),\n tenant: original.tenant || tenant.id\n };\n\n // Access control check on the new model\n const canAccessModel = await this.accessControl.canAccessModel({ model, rwd: \"w\" });\n if (!canAccessModel) {\n return Result.fail(ModelNotAuthorizedError.fromModel(model));\n }\n\n // Publish before event\n await this.eventPublisher.publish(\n new ModelBeforeCreateFromEvent({ model, original, input: data })\n );\n\n // Persist via repository (repository will validate and set modelId)\n const result = await this.repository.execute(model);\n if (result.isFail()) {\n // Publish error event\n await this.eventPublisher.publish(\n new ModelCreateFromErrorEvent({\n input: data,\n model,\n original,\n error: result.error\n })\n );\n return Result.fail(result.error);\n }\n\n // Publish after event\n await this.eventPublisher.publish(\n new ModelAfterCreateFromEvent({\n model: result.value,\n original\n })\n );\n\n return Result.ok(result.value);\n }\n}\n\nexport const CreateModelFromUseCase = UseCaseAbstraction.createImplementation({\n implementation: CreateModelFromUseCaseImpl,\n dependencies: [\n GetModelUseCase,\n EventPublisher,\n CreateModelFromRepository,\n AccessControl,\n TenantContext,\n IdentityContext\n ]\n});\n"],"names":["CreateModelFromUseCaseImpl","getModelUseCase","eventPublisher","repository","accessControl","tenantContext","identityContext","modelId","input","canAccess","Result","ModelNotAuthorizedError","getResult","original","ModelNotFoundError","validationResult","createModelCreateFromValidation","zodError","createZodError","ModelValidationError","data","removeUndefinedValues","identity","tenant","model","undefined","Date","canAccessModel","ModelBeforeCreateFromEvent","result","ModelCreateFromErrorEvent","ModelAfterCreateFromEvent","CreateModelFromUseCase","UseCaseAbstraction","GetModelUseCase","EventPublisher","CreateModelFromRepository","AccessControl","TenantContext","IdentityContext"],"mappings":";;;;;;;;;;;AAqCA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,cAAwC,EACxCC,UAA+C,EAC/CC,aAAsC,EACtCC,aAAsC,EACtCC,eAA0C,CACpD;aANUL,eAAe,GAAfA;aACAC,cAAc,GAAdA;aACAC,UAAU,GAAVA;aACAC,aAAa,GAAbA;aACAC,aAAa,GAAbA;aACAC,eAAe,GAAfA;IACT;IAEH,MAAM,QACFC,OAAe,EACfC,KAA8B,EACqB;QAEnD,MAAMC,YAAY,MAAM,IAAI,CAAC,aAAa,CAA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c,CAAC;YAAEH;YAAO,KAAK;QAAI;QACjF,IAAI,CAACG,gBACD,OAAOjB,OAAO,IAAI,CAACC,wBAAwB,SAAS,CAACa;QAIzD,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAII,2BAA2B;YAAEJ;YAAOX;YAAU,OAAOO;QAAK;QAIlE,MAAMS,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAACL;QAC7C,IAAIK,OAAO,MAAM,IAAI;YAEjB,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIC,0BAA0B;gBAC1B,OAAOV;gBACPI;gBACAX;gBACA,OAAOgB,OAAO,KAAK;YACvB;YAEJ,OAAOnB,OAAO,IAAI,CAACmB,OAAO,KAAK;QACnC;QAGA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIE,0BAA0B;YAC1B,OAAOF,OAAO,KAAK;YACnBhB;QACJ;QAGJ,OAAOH,OAAO,EAAE,CAACmB,OAAO,KAAK;IACjC;AACJ;AAEO,MAAMG,gDAAyBC,uBAAAA,oBAAuC,CAAC;IAC1E,gBAAgBjC;IAChB,cAAc;QACVkC;QACAC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
@@ -21,7 +21,8 @@ class DeleteGroupUseCaseImpl {
21
21
  if (getResult.isFail()) return Result.fail(getResult.error);
22
22
  const group = getResult.value;
23
23
  const canAccessGroup = await this.accessControl.canAccessGroup({
24
- group
24
+ group,
25
+ rwd: "d"
25
26
  });
26
27
  if (!canAccessGroup) return Result.fail(new GroupNotAuthorizedError());
27
28
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"features/contentModelGroup/DeleteGroup/DeleteGroupUseCase.js","sources":["../../../../src/features/contentModelGroup/DeleteGroup/DeleteGroupUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { DeleteGroupUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { DeleteGroupRepository } from \"./abstractions.js\";\nimport { GetGroupUseCase } from \"~/features/contentModelGroup/GetGroup/abstractions.js\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport { GroupBeforeDeleteEvent } from \"./events.js\";\nimport { GroupAfterDeleteEvent } from \"./events.js\";\nimport { GroupDeleteErrorEvent } from \"./events.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport { GroupNotAuthorizedError } from \"~/domain/contentModelGroup/errors.js\";\n\n/**\n * DeleteGroupUseCase - Orchestrates group deletion.\n *\n * Responsibilities:\n * - Fetch original group\n * - Access control checks\n * - Publish before event\n * - Delegate to repository\n * - Publish after event or error event\n */\nclass DeleteGroupUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private eventPublisher: EventPublisher.Interface,\n private repository: DeleteGroupRepository.Interface,\n private getGroupUseCase: GetGroupUseCase.Interface,\n private accessControl: AccessControl.Interface\n ) {}\n\n async execute(groupId: string): Promise<Result<void, UseCaseAbstraction.Error>> {\n // Initial access control check\n const canAccess = await this.accessControl.canAccessGroup({ rwd: \"d\" });\n if (!canAccess) {\n return Result.fail(new GroupNotAuthorizedError());\n }\n\n // Fetch original group\n const getResult = await this.getGroupUseCase.execute(groupId);\n if (getResult.isFail()) {\n return Result.fail(getResult.error);\n }\n const group = getResult.value;\n\n // Access control check on group\n const canAccessGroup = await this.accessControl.canAccessGroup({ group });\n if (!canAccessGroup) {\n return Result.fail(new GroupNotAuthorizedError());\n }\n\n try {\n // Publish before event\n await this.eventPublisher.publish(\n new GroupBeforeDeleteEvent({\n group\n })\n );\n\n // Persist via repository\n const result = await this.repository.execute(group);\n if (result.isFail()) {\n // Publish error event\n await this.eventPublisher.publish(\n new GroupDeleteErrorEvent({\n group,\n error: result.error\n })\n );\n return Result.fail(result.error);\n }\n\n // Publish after event\n await this.eventPublisher.publish(\n new GroupAfterDeleteEvent({\n group\n })\n );\n\n return Result.ok();\n } catch (error) {\n // Publish error event for unexpected errors\n await this.eventPublisher.publish(\n new GroupDeleteErrorEvent({\n group,\n error: error as Error\n })\n );\n return Result.fail(error as UseCaseAbstraction.Error);\n }\n }\n}\n\nexport const DeleteGroupUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: DeleteGroupUseCaseImpl,\n dependencies: [EventPublisher, DeleteGroupRepository, GetGroupUseCase, AccessControl]\n});\n"],"names":["DeleteGroupUseCaseImpl","eventPublisher","repository","getGroupUseCase","accessControl","groupId","canAccess","Result","GroupNotAuthorizedError","getResult","group","canAccessGroup","GroupBeforeDeleteEvent","result","GroupDeleteErrorEvent","GroupAfterDeleteEvent","error","DeleteGroupUseCase","createImplementation","UseCaseAbstraction","EventPublisher","DeleteGroupRepository","GetGroupUseCase","AccessControl"],"mappings":";;;;;;;AAsBA,MAAMA;IACF,YACYC,cAAwC,EACxCC,UAA2C,EAC3CC,eAA0C,EAC1CC,aAAsC,CAChD;aAJUH,cAAc,GAAdA;aACAC,UAAU,GAAVA;aACAC,eAAe,GAAfA;aACAC,aAAa,GAAbA;IACT;IAEH,MAAM,QAAQC,OAAe,EAAmD;QAE5E,MAAMC,YAAY,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;YAAE,KAAK;QAAI;QACrE,IAAI,CAACA,WACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAI3B,MAAMC,YAAY,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAACJ;QACrD,IAAII,UAAU,MAAM,IAChB,OAAOF,OAAO,IAAI,CAACE,UAAU,KAAK;QAEtC,MAAMC,QAAQD,UAAU,KAAK;QAG7B,MAAME,iBAAiB,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;YAAED;QAAM;QACvE,IAAI,CAACC,gBACD,OAAOJ,OAAO,IAAI,CAAC,IAAIC;QAG3B,IAAI;YAEA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAII,uBAAuB;gBACvBF;YACJ;YAIJ,MAAMG,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAACH;YAC7C,IAAIG,OAAO,MAAM,IAAI;gBAEjB,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIC,sBAAsB;oBACtBJ;oBACA,OAAOG,OAAO,KAAK;gBACvB;gBAEJ,OAAON,OAAO,IAAI,CAACM,OAAO,KAAK;YACnC;YAGA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIE,sBAAsB;gBACtBL;YACJ;YAGJ,OAAOH,OAAO,EAAE;QACpB,EAAE,OAAOS,OAAO;YAEZ,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIF,sBAAsB;gBACtBJ;gBACA,OAAOM;YACX;YAEJ,OAAOT,OAAO,IAAI,CAACS;QACvB;IACJ;AACJ;AAEO,MAAMC,wCAAqBC,qBAAqB;IACnD,aAAaC;IACb,gBAAgBnB;IAChB,cAAc;QAACoB;QAAgBC;QAAuBC;QAAiBC;KAAc;AACzF"}
1
+ {"version":3,"file":"features/contentModelGroup/DeleteGroup/DeleteGroupUseCase.js","sources":["../../../../src/features/contentModelGroup/DeleteGroup/DeleteGroupUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { DeleteGroupUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { DeleteGroupRepository } from \"./abstractions.js\";\nimport { GetGroupUseCase } from \"~/features/contentModelGroup/GetGroup/abstractions.js\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport { GroupBeforeDeleteEvent } from \"./events.js\";\nimport { GroupAfterDeleteEvent } from \"./events.js\";\nimport { GroupDeleteErrorEvent } from \"./events.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport { GroupNotAuthorizedError } from \"~/domain/contentModelGroup/errors.js\";\n\n/**\n * DeleteGroupUseCase - Orchestrates group deletion.\n *\n * Responsibilities:\n * - Fetch original group\n * - Access control checks\n * - Publish before event\n * - Delegate to repository\n * - Publish after event or error event\n */\nclass DeleteGroupUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private eventPublisher: EventPublisher.Interface,\n private repository: DeleteGroupRepository.Interface,\n private getGroupUseCase: GetGroupUseCase.Interface,\n private accessControl: AccessControl.Interface\n ) {}\n\n async execute(groupId: string): Promise<Result<void, UseCaseAbstraction.Error>> {\n // Initial access control check\n const canAccess = await this.accessControl.canAccessGroup({ rwd: \"d\" });\n if (!canAccess) {\n return Result.fail(new GroupNotAuthorizedError());\n }\n\n // Fetch original group\n const getResult = await this.getGroupUseCase.execute(groupId);\n if (getResult.isFail()) {\n return Result.fail(getResult.error);\n }\n const group = getResult.value;\n\n // Access control check on group\n const canAccessGroup = await this.accessControl.canAccessGroup({ group, rwd: \"d\" });\n if (!canAccessGroup) {\n return Result.fail(new GroupNotAuthorizedError());\n }\n\n try {\n // Publish before event\n await this.eventPublisher.publish(\n new GroupBeforeDeleteEvent({\n group\n })\n );\n\n // Persist via repository\n const result = await this.repository.execute(group);\n if (result.isFail()) {\n // Publish error event\n await this.eventPublisher.publish(\n new GroupDeleteErrorEvent({\n group,\n error: result.error\n })\n );\n return Result.fail(result.error);\n }\n\n // Publish after event\n await this.eventPublisher.publish(\n new GroupAfterDeleteEvent({\n group\n })\n );\n\n return Result.ok();\n } catch (error) {\n // Publish error event for unexpected errors\n await this.eventPublisher.publish(\n new GroupDeleteErrorEvent({\n group,\n error: error as Error\n })\n );\n return Result.fail(error as UseCaseAbstraction.Error);\n }\n }\n}\n\nexport const DeleteGroupUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: DeleteGroupUseCaseImpl,\n dependencies: [EventPublisher, DeleteGroupRepository, GetGroupUseCase, AccessControl]\n});\n"],"names":["DeleteGroupUseCaseImpl","eventPublisher","repository","getGroupUseCase","accessControl","groupId","canAccess","Result","GroupNotAuthorizedError","getResult","group","canAccessGroup","GroupBeforeDeleteEvent","result","GroupDeleteErrorEvent","GroupAfterDeleteEvent","error","DeleteGroupUseCase","createImplementation","UseCaseAbstraction","EventPublisher","DeleteGroupRepository","GetGroupUseCase","AccessControl"],"mappings":";;;;;;;AAsBA,MAAMA;IACF,YACYC,cAAwC,EACxCC,UAA2C,EAC3CC,eAA0C,EAC1CC,aAAsC,CAChD;aAJUH,cAAc,GAAdA;aACAC,UAAU,GAAVA;aACAC,eAAe,GAAfA;aACAC,aAAa,GAAbA;IACT;IAEH,MAAM,QAAQC,OAAe,EAAmD;QAE5E,MAAMC,YAAY,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;YAAE,KAAK;QAAI;QACrE,IAAI,CAACA,WACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAI3B,MAAMC,YAAY,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAACJ;QACrD,IAAII,UAAU,MAAM,IAChB,OAAOF,OAAO,IAAI,CAACE,UAAU,KAAK;QAEtC,MAAMC,QAAQD,UAAU,KAAK;QAG7B,MAAME,iBAAiB,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;YAAED;YAAO,KAAK;QAAI;QACjF,IAAI,CAACC,gBACD,OAAOJ,OAAO,IAAI,CAAC,IAAIC;QAG3B,IAAI;YAEA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAII,uBAAuB;gBACvBF;YACJ;YAIJ,MAAMG,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAACH;YAC7C,IAAIG,OAAO,MAAM,IAAI;gBAEjB,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIC,sBAAsB;oBACtBJ;oBACA,OAAOG,OAAO,KAAK;gBACvB;gBAEJ,OAAON,OAAO,IAAI,CAACM,OAAO,KAAK;YACnC;YAGA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIE,sBAAsB;gBACtBL;YACJ;YAGJ,OAAOH,OAAO,EAAE;QACpB,EAAE,OAAOS,OAAO;YAEZ,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIF,sBAAsB;gBACtBJ;gBACA,OAAOM;YACX;YAEJ,OAAOT,OAAO,IAAI,CAACS;QACvB;IACJ;AACJ;AAEO,MAAMC,wCAAqBC,qBAAqB;IACnD,aAAaC;IACb,gBAAgBnB;IAChB,cAAc;QAACoB;QAAgBC;QAAuBC;QAAiBC;KAAc;AACzF"}
@@ -25,7 +25,8 @@ class UpdateGroupUseCaseImpl {
25
25
  if (getResult.isFail()) return Result.fail(getResult.error);
26
26
  const original = getResult.value;
27
27
  const canAccessGroup = await this.accessControl.canAccessGroup({
28
- group: original
28
+ group: original,
29
+ rwd: "w"
29
30
  });
30
31
  if (!canAccessGroup) return Result.fail(new GroupNotAuthorizedError());
31
32
  const validationResult = await createGroupUpdateValidation().safeParseAsync(input);
@@ -1 +1 @@
1
- {"version":3,"file":"features/contentModelGroup/UpdateGroup/UpdateGroupUseCase.js","sources":["../../../../src/features/contentModelGroup/UpdateGroup/UpdateGroupUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { UpdateGroupUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { UpdateGroupRepository } from \"./abstractions.js\";\nimport { GetGroupUseCase } from \"~/features/contentModelGroup/GetGroup/abstractions.js\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport { GroupBeforeUpdateEvent } from \"./events.js\";\nimport { GroupAfterUpdateEvent } from \"./events.js\";\nimport { GroupUpdateErrorEvent } from \"./events.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport {\n GroupNotAuthorizedError,\n GroupValidationError\n} from \"~/domain/contentModelGroup/errors.js\";\nimport { createZodError } from \"@webiny/utils\";\nimport { createGroupUpdateValidation } from \"~/domain/contentModelGroup/validation.js\";\nimport type { CmsGroup } from \"~/types/index.js\";\nimport type { CmsGroupUpdateInput } from \"~/types/index.js\";\n\n/**\n * UpdateGroupUseCase - Orchestrates group updates.\n *\n * Responsibilities:\n * - Fetch original group\n * - Access control checks\n * - Validate input (Zod)\n * - Skip if no changes\n * - Merge changes\n * - Publish before event\n * - Delegate to repository\n * - Publish after event or error event\n */\nclass UpdateGroupUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private eventPublisher: EventPublisher.Interface,\n private repository: UpdateGroupRepository.Interface,\n private getGroupUseCase: GetGroupUseCase.Interface,\n private accessControl: AccessControl.Interface,\n private tenantContext: TenantContext.Interface\n ) {}\n\n async execute(\n groupId: string,\n input: CmsGroupUpdateInput\n ): Promise<Result<CmsGroup, UseCaseAbstraction.Error>> {\n // Initial access control check\n const canAccess = await this.accessControl.canAccessGroup({ rwd: \"w\" });\n if (!canAccess) {\n return Result.fail(new GroupNotAuthorizedError());\n }\n\n // Fetch original group\n const getResult = await this.getGroupUseCase.execute(groupId);\n if (getResult.isFail()) {\n return Result.fail(getResult.error);\n }\n const original = getResult.value;\n\n // Access control check on original group\n const canAccessGroup = await this.accessControl.canAccessGroup({ group: original });\n if (!canAccessGroup) {\n return Result.fail(new GroupNotAuthorizedError());\n }\n\n // Validate input\n const validationResult = await createGroupUpdateValidation().safeParseAsync(input);\n if (!validationResult.success) {\n const zodError = createZodError(validationResult.error);\n return Result.fail(\n new GroupValidationError(zodError.message, zodError.data!.invalidFields)\n );\n }\n const data = validationResult.data;\n\n // Skip if no changes\n if (Object.keys(data).length === 0) {\n return Result.ok(original);\n }\n\n // Merge changes\n const tenant = this.tenantContext.getTenant();\n const group: CmsGroup = {\n ...original,\n ...data,\n tenant: tenant.id,\n savedOn: new Date().toISOString()\n };\n\n try {\n // Publish before event\n await this.eventPublisher.publish(\n new GroupBeforeUpdateEvent({\n original,\n group\n })\n );\n\n // Persist via repository\n const result = await this.repository.execute(group);\n if (result.isFail()) {\n // Publish error event\n await this.eventPublisher.publish(\n new GroupUpdateErrorEvent({\n input,\n original,\n group,\n error: result.error\n })\n );\n return Result.fail(result.error);\n }\n\n // Publish after event\n await this.eventPublisher.publish(\n new GroupAfterUpdateEvent({\n original,\n group: result.value\n })\n );\n\n return Result.ok(result.value);\n } catch (error) {\n // Publish error event for unexpected errors\n await this.eventPublisher.publish(\n new GroupUpdateErrorEvent({\n input,\n original,\n group,\n error: error as Error\n })\n );\n return Result.fail(error as UseCaseAbstraction.Error);\n }\n }\n}\n\nexport const UpdateGroupUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: UpdateGroupUseCaseImpl,\n dependencies: [\n EventPublisher,\n UpdateGroupRepository,\n GetGroupUseCase,\n AccessControl,\n TenantContext\n ]\n});\n"],"names":["UpdateGroupUseCaseImpl","eventPublisher","repository","getGroupUseCase","accessControl","tenantContext","groupId","input","canAccess","Result","GroupNotAuthorizedError","getResult","original","canAccessGroup","validationResult","createGroupUpdateValidation","zodError","createZodError","GroupValidationError","data","Object","tenant","group","Date","GroupBeforeUpdateEvent","result","GroupUpdateErrorEvent","GroupAfterUpdateEvent","error","UpdateGroupUseCase","createImplementation","UseCaseAbstraction","EventPublisher","UpdateGroupRepository","GetGroupUseCase","AccessControl","TenantContext"],"mappings":";;;;;;;;;;AAiCA,MAAMA;IACF,YACYC,cAAwC,EACxCC,UAA2C,EAC3CC,eAA0C,EAC1CC,aAAsC,EACtCC,aAAsC,CAChD;aALUJ,cAAc,GAAdA;aACAC,UAAU,GAAVA;aACAC,eAAe,GAAfA;aACAC,aAAa,GAAbA;aACAC,aAAa,GAAbA;IACT;IAEH,MAAM,QACFC,OAAe,EACfC,KAA0B,EACyB;QAEnD,MAAMC,YAAY,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;YAAE,KAAK;QAAI;QACrE,IAAI,CAACA,WACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAI3B,MAAMC,YAAY,MAAM,IAAI,CAAC,eAAe,CAAC,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A,OAAOa,OAAO,KAAK;YACvB;YAGJ,OAAOhB,OAAO,EAAE,CAACgB,OAAO,KAAK;QACjC,EAAE,OAAOG,OAAO;YAEZ,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIF,sBAAsB;gBACtBnB;gBACAK;gBACAU;gBACA,OAAOM;YACX;YAEJ,OAAOnB,OAAO,IAAI,CAACmB;QACvB;IACJ;AACJ;AAEO,MAAMC,wCAAqBC,qBAAqB;IACnD,aAAaC;IACb,gBAAgB/B;IAChB,cAAc;QACVgC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
1
+ {"version":3,"file":"features/contentModelGroup/UpdateGroup/UpdateGroupUseCase.js","sources":["../../../../src/features/contentModelGroup/UpdateGroup/UpdateGroupUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { UpdateGroupUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { UpdateGroupRepository } from \"./abstractions.js\";\nimport { GetGroupUseCase } from \"~/features/contentModelGroup/GetGroup/abstractions.js\";\nimport { EventPublisher } from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport { GroupBeforeUpdateEvent } from \"./events.js\";\nimport { GroupAfterUpdateEvent } from \"./events.js\";\nimport { GroupUpdateErrorEvent } from \"./events.js\";\nimport { AccessControl } from \"~/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport {\n GroupNotAuthorizedError,\n GroupValidationError\n} from \"~/domain/contentModelGroup/errors.js\";\nimport { createZodError } from \"@webiny/utils\";\nimport { createGroupUpdateValidation } from \"~/domain/contentModelGroup/validation.js\";\nimport type { CmsGroup } from \"~/types/index.js\";\nimport type { CmsGroupUpdateInput } from \"~/types/index.js\";\n\n/**\n * UpdateGroupUseCase - Orchestrates group updates.\n *\n * Responsibilities:\n * - Fetch original group\n * - Access control checks\n * - Validate input (Zod)\n * - Skip if no changes\n * - Merge changes\n * - Publish before event\n * - Delegate to repository\n * - Publish after event or error event\n */\nclass UpdateGroupUseCaseImpl implements UseCaseAbstraction.Interface {\n public constructor(\n private eventPublisher: EventPublisher.Interface,\n private repository: UpdateGroupRepository.Interface,\n private getGroupUseCase: GetGroupUseCase.Interface,\n private accessControl: AccessControl.Interface,\n private tenantContext: TenantContext.Interface\n ) {}\n\n async execute(\n groupId: string,\n input: CmsGroupUpdateInput\n ): Promise<Result<CmsGroup, UseCaseAbstraction.Error>> {\n // Initial access control check\n const canAccess = await this.accessControl.canAccessGroup({ rwd: \"w\" });\n if (!canAccess) {\n return Result.fail(new GroupNotAuthorizedError());\n }\n\n // Fetch original group\n const getResult = await this.getGroupUseCase.execute(groupId);\n if (getResult.isFail()) {\n return Result.fail(getResult.error);\n }\n const original = getResult.value;\n\n // Access control check on original group\n const canAccessGroup = await this.accessControl.canAccessGroup({\n group: original,\n rwd: \"w\"\n });\n if (!canAccessGroup) {\n return Result.fail(new GroupNotAuthorizedError());\n }\n\n // Validate input\n const validationResult = await createGroupUpdateValidation().safeParseAsync(input);\n if (!validationResult.success) {\n const zodError = createZodError(validationResult.error);\n return Result.fail(\n new GroupValidationError(zodError.message, zodError.data!.invalidFields)\n );\n }\n const data = validationResult.data;\n\n // Skip if no changes\n if (Object.keys(data).length === 0) {\n return Result.ok(original);\n }\n\n // Merge changes\n const tenant = this.tenantContext.getTenant();\n const group: CmsGroup = {\n ...original,\n ...data,\n tenant: tenant.id,\n savedOn: new Date().toISOString()\n };\n\n try {\n // Publish before event\n await this.eventPublisher.publish(\n new GroupBeforeUpdateEvent({\n original,\n group\n })\n );\n\n // Persist via repository\n const result = await this.repository.execute(group);\n if (result.isFail()) {\n // Publish error event\n await this.eventPublisher.publish(\n new GroupUpdateErrorEvent({\n input,\n original,\n group,\n error: result.error\n })\n );\n return Result.fail(result.error);\n }\n\n // Publish after event\n await this.eventPublisher.publish(\n new GroupAfterUpdateEvent({\n original,\n group: result.value\n })\n );\n\n return Result.ok(result.value);\n } catch (error) {\n // Publish error event for unexpected errors\n await this.eventPublisher.publish(\n new GroupUpdateErrorEvent({\n input,\n original,\n group,\n error: error as Error\n })\n );\n return Result.fail(error as UseCaseAbstraction.Error);\n }\n }\n}\n\nexport const UpdateGroupUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: UpdateGroupUseCaseImpl,\n dependencies: [\n EventPublisher,\n UpdateGroupRepository,\n GetGroupUseCase,\n AccessControl,\n TenantContext\n ]\n});\n"],"names":["UpdateGroupUseCaseImpl","eventPublisher","repository","getGroupUseCase","accessControl","tenantContext","groupId","input","canAccess","Result","GroupNotAuthorizedError","getResult","original","canAccessGroup","validationResult","createGroupUpdateValidation","zodError","createZodError","GroupValidationError","data","Object","tenant","group","Date","GroupBeforeUpdateEvent","result","GroupUpdateErrorEvent","GroupAfterUpdateEvent","error","UpdateGroupUseCase","createImplementation","UseCaseAbstraction","EventPublisher","UpdateGroupRepository","GetGroupUseCase","AccessControl","TenantContext"],"mappings":";;;;;;;;;;AAiCA,MAAMA;IACF,YACYC,cAAwC,EACxCC,UAA2C,EAC3CC,eAA0C,EAC1CC,aAAsC,EACtCC,aAAsC,CAChD;aALUJ,cAAc,GAAdA;aACAC,UAAU,GAAVA;aACAC,eAAe,GAAfA;aACAC,aAAa,GAAbA;aACAC,aAAa,GAAbA;IACT;IAEH,MAAM,QACFC,OAAe,EACfC,KAA0B,EACyB;QAEnD,MAAMC,YAAY,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;YAAE,KAAK;QAAI;QACrE,IAAI,CAACA,WACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAI3B,MAAMC,YAAY,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAACL;QACrD,IAAIK,UAAU,MAAM,IAChB,OAAOF,OAAO,IAAI,CAACE,UAAU,KAAK;QAEtC,MAAMC,WAAWD,UAAU,KAAK;QAGhC,MAAME,iBAAiB,MAAM,IAAI,CAAC,aAAa,CAAC,c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sBAAsB;gBACtBnB;gBACAK;gBACAU;gBACA,OAAOM;YACX;YAEJ,OAAOnB,OAAO,IAAI,CAACmB;QACvB;IACJ;AACJ;AAEO,MAAMC,wCAAqBC,qBAAqB;IACnD,aAAaC;IACb,gBAAgB/B;IAChB,cAAc;QACVgC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
@@ -3,8 +3,10 @@ import { formatErrorPayload } from "./formatErrorPayload.js";
3
3
  import { getSchema } from "./getSchema.js";
4
4
  import { processRequestBody } from "@webiny/handler-graphql";
5
5
  import { createRequestBody } from "@webiny/handler-graphql/createRequestBody.js";
6
+ import { isJsonContentType, replyInvalidRequestBody, replyUnsupportedMediaType } from "@webiny/handler-graphql/jsonContentType.js";
6
7
  const handleRequest = async (params)=>{
7
8
  const { context, request, reply } = params;
9
+ if (!isJsonContentType(request)) return replyUnsupportedMediaType(reply);
8
10
  try {
9
11
  await checkEndpointAccess(context);
10
12
  } catch (ex) {
@@ -32,15 +34,22 @@ const handleRequest = async (params)=>{
32
34
  throw ex;
33
35
  }
34
36
  });
35
- const body = await context.benchmark.measure("headlessCms.graphql.createRequestBody", async ()=>{
36
- try {
37
- return createRequestBody(request.body);
38
- } catch (ex) {
39
- console.error("Error while creating the body request.");
40
- console.error(formatErrorPayload(ex));
41
- throw ex;
42
- }
43
- });
37
+ let body;
38
+ try {
39
+ body = await context.benchmark.measure("headlessCms.graphql.createRequestBody", async ()=>{
40
+ try {
41
+ return createRequestBody(request.body);
42
+ } catch (ex) {
43
+ console.error("Error while creating the body request.");
44
+ console.error(formatErrorPayload(ex));
45
+ throw ex;
46
+ }
47
+ });
48
+ } catch (ex) {
49
+ const invalidRequestReply = replyInvalidRequestBody(reply, ex);
50
+ if (invalidRequestReply) return invalidRequestReply;
51
+ throw ex;
52
+ }
44
53
  let result = null;
45
54
  await context.benchmark.measure("headlessCms.graphql.processRequestBody", async ()=>{
46
55
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"graphql/handleRequest.js","sources":["../../src/graphql/handleRequest.ts"],"sourcesContent":["import type { ApiEndpoint, CmsContext } from \"~/types/index.js\";\nimport { checkEndpointAccess } from \"./checkEndpointAccess.js\";\nimport { formatErrorPayload } from \"./formatErrorPayload.js\";\nimport { getSchema } from \"./getSchema.js\";\nimport type { Reply, Request } from \"@webiny/handler/types.js\";\nimport { processRequestBody } from \"@webiny/handler-graphql\";\nimport type { ExecutionResult } from \"graphql\";\nimport { createRequestBody } from \"@webiny/handler-graphql/createRequestBody.js\";\n\nexport interface HandleRequestParams {\n context: CmsContext;\n request: Request;\n reply: Reply;\n}\n\nexport interface HandleRequest {\n (params: HandleRequestParams): Promise<Reply>;\n}\n\nexport const handleRequest: HandleRequest = async params => {\n const { context, request, reply } = params;\n try {\n await checkEndpointAccess(context);\n } catch (ex) {\n return reply.code(401).send({\n data: null,\n error: {\n message: ex.message || \"Not authorized!\",\n code: ex.code || \"SECURITY_NOT_AUTHORIZED\",\n data: ex.data || null,\n stack: null\n }\n });\n }\n\n const getTenant = () => {\n return context.tenancy.getCurrentTenant();\n };\n\n const schema = await context.benchmark.measure(\"headlessCms.graphql.getSchema\", async () => {\n try {\n return await getSchema({\n context,\n getTenant,\n type: context.cms.type as ApiEndpoint\n });\n } catch (ex) {\n console.error(`Error while generating the schema.`);\n console.error(formatErrorPayload(ex));\n throw ex;\n }\n });\n\n const body = await context.benchmark.measure(\n \"headlessCms.graphql.createRequestBody\",\n async () => {\n try {\n return createRequestBody(request.body);\n } catch (ex) {\n console.error(`Error while creating the body request.`);\n console.error(formatErrorPayload(ex));\n throw ex;\n }\n }\n );\n\n /**\n * We need to store the processRequestBody result in a variable and output it after the measurement.\n * Otherwise, the measurement will not be shown in the output.\n */\n let result: ExecutionResult[] | ExecutionResult | null = null;\n\n await context.benchmark.measure(\"headlessCms.graphql.processRequestBody\", async () => {\n try {\n result = await processRequestBody(body, schema, context);\n } catch (ex) {\n console.error(`Error while processing the body request.`);\n console.error(formatErrorPayload(ex));\n throw ex;\n }\n });\n /**\n * IMPORTANT! Do not send anything if reply was already sent.\n */\n if (reply.sent) {\n console.warn(\"Reply already sent, cannot send the result (api-headless-cms).\");\n return reply;\n }\n\n return reply.send(result);\n};\n"],"names":["handleRequest","params","context","request","reply","checkEndpointAccess","ex","getTenant","schema","getSchema","console","formatErrorPayload","body","createRequestBody","result","processRequestBody"],"mappings":";;;;;AAmBO,MAAMA,gBAA+B,OAAMC;IAC9C,MAAM,EAAEC,OAAO,EAAEC,OAAO,EAAEC,KAAK,EAAE,GAAGH;IACpC,IAAI;QACA,MAAMI,oBAAoBH;IAC9B,EAAE,OAAOI,IAAI;QACT,OAAOF,MAAM,IAAI,CAAC,KAAK,IAAI,CAAC;YACxB,MAAM;YACN,OAAO;gBACH,SAASE,GAAG,OAAO,IAAI;gBACvB,MAAMA,GAAG,IAAI,IAAI;gBACjB,MAAMA,GAAG,IAAI,IAAI;gBACjB,OAAO;YACX;QACJ;IACJ;IAEA,MAAMC,YAAY,IACPL,QAAQ,OAAO,CAAC,gBAAgB;IAG3C,MAAMM,SAAS,MAAMN,QAAQ,SAAS,CAAC,OAAO,CAAC,iCAAiC;QAC5E,IAAI;YACA,OAAO,MAAMO,UAAU;gBACnBP;gBACAK;gBACA,MAAML,QAAQ,GAAG,CAAC,IAAI;YAC1B;QACJ,EAAE,OAAOI,IAAI;YACTI,QAAQ,KAAK,CAAC;YACdA,QAAQ,KAAK,CAACC,mBAAmBL;YACjC,MAAMA;QACV;IACJ;IAEA,MAAMM,OAAO,MAAMV,QAAQ,SAAS,CAAC,OAAO,CACxC,yCACA;QACI,IAAI;YACA,OAAOW,kBAAkBV,QAAQ,IAAI;QACzC,EAAE,OAAOG,IAAI;YACTI,QAAQ,KAAK,CAAC;YACdA,QAAQ,KAAK,CAACC,mBAAmBL;YACjC,MAAMA;QACV;IACJ;IAOJ,IAAIQ,SAAqD;IAEzD,MAAMZ,QAAQ,SAAS,CAAC,OAAO,CAAC,0CAA0C;QACtE,IAAI;YACAY,SAAS,MAAMC,mBAAmBH,MAAMJ,QAAQN;QACpD,EAAE,OAAOI,IAAI;YACTI,QAAQ,KAAK,CAAC;YACdA,QAAQ,KAAK,CAACC,mBAAmBL;YACjC,MAAMA;QACV;IACJ;IAIA,IAAIF,MAAM,IAAI,EAAE;QACZM,QAAQ,IAAI,CAAC;QACb,OAAON;IACX;IAEA,OAAOA,MAAM,IAAI,CAACU;AACtB"}
1
+ {"version":3,"file":"graphql/handleRequest.js","sources":["../../src/graphql/handleRequest.ts"],"sourcesContent":["import type { ApiEndpoint, CmsContext } from \"~/types/index.js\";\nimport { checkEndpointAccess } from \"./checkEndpointAccess.js\";\nimport { formatErrorPayload } from \"./formatErrorPayload.js\";\nimport { getSchema } from \"./getSchema.js\";\nimport type { Reply, Request } from \"@webiny/handler/types.js\";\nimport { processRequestBody } from \"@webiny/handler-graphql\";\nimport type { ExecutionResult } from \"graphql\";\nimport { createRequestBody } from \"@webiny/handler-graphql/createRequestBody.js\";\nimport {\n isJsonContentType,\n replyInvalidRequestBody,\n replyUnsupportedMediaType\n} from \"@webiny/handler-graphql/jsonContentType.js\";\n\nexport interface HandleRequestParams {\n context: CmsContext;\n request: Request;\n reply: Reply;\n}\n\nexport interface HandleRequest {\n (params: HandleRequestParams): Promise<Reply>;\n}\n\nexport const handleRequest: HandleRequest = async params => {\n const { context, request, reply } = params;\n if (!isJsonContentType(request)) {\n return replyUnsupportedMediaType(reply);\n }\n try {\n await checkEndpointAccess(context);\n } catch (ex) {\n return reply.code(401).send({\n data: null,\n error: {\n message: ex.message || \"Not authorized!\",\n code: ex.code || \"SECURITY_NOT_AUTHORIZED\",\n data: ex.data || null,\n stack: null\n }\n });\n }\n\n const getTenant = () => {\n return context.tenancy.getCurrentTenant();\n };\n\n const schema = await context.benchmark.measure(\"headlessCms.graphql.getSchema\", async () => {\n try {\n return await getSchema({\n context,\n getTenant,\n type: context.cms.type as ApiEndpoint\n });\n } catch (ex) {\n console.error(`Error while generating the schema.`);\n console.error(formatErrorPayload(ex));\n throw ex;\n }\n });\n\n let body: ReturnType<typeof createRequestBody>;\n try {\n body = await context.benchmark.measure(\n \"headlessCms.graphql.createRequestBody\",\n async () => {\n try {\n return createRequestBody(request.body);\n } catch (ex) {\n console.error(`Error while creating the body request.`);\n console.error(formatErrorPayload(ex));\n throw ex;\n }\n }\n );\n } catch (ex) {\n const invalidRequestReply = replyInvalidRequestBody(reply, ex);\n if (invalidRequestReply) {\n return invalidRequestReply;\n }\n throw ex;\n }\n\n /**\n * We need to store the processRequestBody result in a variable and output it after the measurement.\n * Otherwise, the measurement will not be shown in the output.\n */\n let result: ExecutionResult[] | ExecutionResult | null = null;\n\n await context.benchmark.measure(\"headlessCms.graphql.processRequestBody\", async () => {\n try {\n result = await processRequestBody(body, schema, context);\n } catch (ex) {\n console.error(`Error while processing the body request.`);\n console.error(formatErrorPayload(ex));\n throw ex;\n }\n });\n /**\n * IMPORTANT! Do not send anything if reply was already sent.\n */\n if (reply.sent) {\n console.warn(\"Reply already sent, cannot send the result (api-headless-cms).\");\n return reply;\n }\n\n return reply.send(result);\n};\n"],"names":["handleRequest","params","context","request","reply","isJsonContentType","replyUnsupportedMediaType","checkEndpointAccess","ex","getTenant","schema","getSchema","console","formatErrorPayload","body","createRequestBody","invalidRequestReply","replyInvalidRequestBody","result","processRequestBody"],"mappings":";;;;;;AAwBO,MAAMA,gBAA+B,OAAMC;IAC9C,MAAM,EAAEC,OAAO,EAAEC,OAAO,EAAEC,KAAK,EAAE,GAAGH;IACpC,IAAI,CAACI,kBAAkBF,UACnB,OAAOG,0BAA0BF;IAErC,IAAI;QACA,MAAMG,oBAAoBL;IAC9B,EAAE,OAAOM,IAAI;QACT,OAAOJ,MAAM,IAAI,CAAC,KAAK,IAAI,CAAC;YACxB,MAAM;YACN,OAAO;gBACH,SAASI,GAAG,OAAO,IAAI;gBACvB,MAAMA,GAAG,IAAI,IAAI;gBACjB,MAAMA,GAAG,IAAI,IAAI;gBACjB,OAAO;YACX;QACJ;IACJ;IAEA,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