@webiny/api-headless-cms 6.4.12-beta.1 → 6.4.12-beta.10

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 (71) hide show
  1. package/context.js +6 -1
  2. package/context.js.map +1 -1
  3. package/crud/AccessControl/AccessControl.d.ts +11 -1
  4. package/crud/AccessControl/AccessControl.js +18 -1
  5. package/crud/AccessControl/AccessControl.js.map +1 -1
  6. package/crud/contentModel/validation.js +4 -4
  7. package/crud/contentModel/validation.js.map +1 -1
  8. package/domain/contentModel/schemas.js +3 -3
  9. package/domain/contentModel/schemas.js.map +1 -1
  10. package/domain/contentModelGroup/validation.js +2 -2
  11. package/domain/contentModelGroup/validation.js.map +1 -1
  12. package/export/crud/importing.js +8 -0
  13. package/export/crud/importing.js.map +1 -1
  14. package/export/types.js.map +1 -1
  15. package/features/contentEntry/CreateEntryRevisionFrom/CreateEntryRevisionFromUseCase.js +2 -2
  16. package/features/contentEntry/CreateEntryRevisionFrom/CreateEntryRevisionFromUseCase.js.map +1 -1
  17. package/features/contentEntry/DeleteMultipleEntries/DeleteMultipleEntriesUseCase.js +2 -1
  18. package/features/contentEntry/DeleteMultipleEntries/DeleteMultipleEntriesUseCase.js.map +1 -1
  19. package/features/contentEntry/GetEntriesByIds/GetEntriesByIdsUseCase.js +3 -1
  20. package/features/contentEntry/GetEntriesByIds/GetEntriesByIdsUseCase.js.map +1 -1
  21. package/features/contentEntry/GetLatestEntriesByIds/GetLatestEntriesByIdsUseCase.js +3 -1
  22. package/features/contentEntry/GetLatestEntriesByIds/GetLatestEntriesByIdsUseCase.js.map +1 -1
  23. package/features/contentEntry/GetLatestRevisionByEntryId/BaseUseCase.js +5 -1
  24. package/features/contentEntry/GetLatestRevisionByEntryId/BaseUseCase.js.map +1 -1
  25. package/features/contentEntry/GetPreviousRevisionByEntryId/BaseUseCase.js +5 -1
  26. package/features/contentEntry/GetPreviousRevisionByEntryId/BaseUseCase.js.map +1 -1
  27. package/features/contentEntry/GetPublishedEntriesByIds/GetPublishedEntriesByIdsUseCase.js +3 -1
  28. package/features/contentEntry/GetPublishedEntriesByIds/GetPublishedEntriesByIdsUseCase.js.map +1 -1
  29. package/features/contentEntry/GetPublishedRevisionByEntryId/GetPublishedRevisionByEntryIdUseCase.d.ts +5 -1
  30. package/features/contentEntry/GetPublishedRevisionByEntryId/GetPublishedRevisionByEntryIdUseCase.js +16 -3
  31. package/features/contentEntry/GetPublishedRevisionByEntryId/GetPublishedRevisionByEntryIdUseCase.js.map +1 -1
  32. package/features/contentEntry/GetPublishedRevisionByEntryId/abstractions.d.ts +2 -1
  33. package/features/contentEntry/GetPublishedRevisionByEntryId/abstractions.js.map +1 -1
  34. package/features/contentEntry/GetRevisionById/GetRevisionByIdUseCase.d.ts +7 -2
  35. package/features/contentEntry/GetRevisionById/GetRevisionByIdUseCase.js +18 -4
  36. package/features/contentEntry/GetRevisionById/GetRevisionByIdUseCase.js.map +1 -1
  37. package/features/contentEntry/GetRevisionById/abstractions.d.ts +4 -2
  38. package/features/contentEntry/GetRevisionById/abstractions.js.map +1 -1
  39. package/features/contentEntry/GetRevisionsByEntryId/GetRevisionsByEntryIdUseCase.js +3 -1
  40. package/features/contentEntry/GetRevisionsByEntryId/GetRevisionsByEntryIdUseCase.js.map +1 -1
  41. package/features/contentEntry/UpdateEntry/UpdateEntryUseCase.js +9 -6
  42. package/features/contentEntry/UpdateEntry/UpdateEntryUseCase.js.map +1 -1
  43. package/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.js +1 -1
  44. package/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.js.map +1 -1
  45. package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.js +1 -1
  46. package/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.js.map +1 -1
  47. package/features/contentEntry/shared/entryOwnerAccess.d.ts +15 -0
  48. package/features/contentEntry/shared/entryOwnerAccess.js +21 -0
  49. package/features/contentEntry/shared/entryOwnerAccess.js.map +1 -0
  50. package/features/contentModel/CreateModelFrom/CreateModelFromUseCase.js +2 -1
  51. package/features/contentModel/CreateModelFrom/CreateModelFromUseCase.js.map +1 -1
  52. package/features/contentModel/ModelAccessGuard/abstractions.d.ts +30 -0
  53. package/features/contentModel/ModelAccessGuard/abstractions.js +5 -0
  54. package/features/contentModel/ModelAccessGuard/abstractions.js.map +1 -0
  55. package/features/contentModel/ModelAccessGuard/index.d.ts +2 -0
  56. package/features/contentModel/ModelAccessGuard/index.js +1 -0
  57. package/features/contentModelGroup/DeleteGroup/DeleteGroupUseCase.js +2 -1
  58. package/features/contentModelGroup/DeleteGroup/DeleteGroupUseCase.js.map +1 -1
  59. package/features/contentModelGroup/UpdateGroup/UpdateGroupUseCase.js +2 -1
  60. package/features/contentModelGroup/UpdateGroup/UpdateGroupUseCase.js.map +1 -1
  61. package/features/modelBuilder/fields/TextFieldType.js.map +1 -1
  62. package/graphql/handleRequest.js +18 -9
  63. package/graphql/handleRequest.js.map +1 -1
  64. package/graphql/schema/contentEntries.js +15 -5
  65. package/graphql/schema/contentEntries.js.map +1 -1
  66. package/graphql/schema/contentModelGroups.js +11 -12
  67. package/graphql/schema/contentModelGroups.js.map +1 -1
  68. package/graphql/schema/contentModels.js +1 -1
  69. package/graphql/schema/contentModels.js.map +1 -1
  70. package/package.json +30 -30
  71. package/types/types.js.map +1 -1
@@ -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){
@@ -25,13 +26,15 @@ class UpdateEntryUseCaseImpl {
25
26
  if (result.isFail()) return Result.fail(result.error);
26
27
  const originalEntry = result.value;
27
28
  if (originalEntry.locked) return Result.fail(new EntryLockedError());
29
+ if (!isSingletonModel(model)) {
30
+ const canAccessEntry = await this.accessControl.canAccessEntry({
31
+ model,
32
+ entry: originalEntry,
33
+ rwd: "w"
34
+ });
35
+ if (!canAccessEntry) return Result.fail(EntryNotAuthorizedError.fromModel(model));
36
+ }
28
37
  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));
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,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;YAGJ,MAAMS,iBAAiB,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;gBAC3DZ;gBACAU;gBACA,KAAK;YACT;YAEA,IAAI,CAACE,gBACD,OAAOP,OAAO,IAAI,CAACC,wBAAwB,SAAS,CAACN;YAGzD,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIa,uBAAuB;gBAAEH;gBAAO,UAAUF;gBAAeG;gBAAOX;YAAM;YAG9E,MAAMc,eAAe,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAACd,OAAOU;YAC1D,IAAII,aAAa,MAAM,IACnB,OAAOT,OAAO,IAAI,CAACS,aAAa,KAAK;YAGzC,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,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 // Singleton entries are shared by everyone who can access the model, so the\n // entry-level (owner) check is skipped for them.\n // The check runs against the stored entry, never against the one built from input.\n if (!isSingletonModel(model)) {\n const canAccessEntry = await this.accessControl.canAccessEntry({\n model,\n entry: originalEntry,\n rwd: \"w\"\n });\n\n if (!canAccessEntry) {\n return Result.fail(EntryNotAuthorizedError.fromModel(model));\n }\n }\n\n const { entry, input } = await this.updateEntryDataFactory.create<T>(\n model,\n rawInput,\n originalEntry,\n options\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","isSingletonModel","canAccessEntry","entry","input","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;YAM3B,IAAI,CAACC,iBAAiBV,QAAQ;gBAC1B,MAAMW,iBAAiB,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;oBAC3DX;oBACA,OAAOQ;oBACP,KAAK;gBACT;gBAEA,IAAI,CAACG,gBACD,OAAON,OAAO,IAAI,CAACC,wBAAwB,SAAS,CAACN;YAE7D;YAEA,MAAM,EAAEY,KAAK,EAAEC,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,sBAAsB,CAAC,MAAM,CAC7Db,OACAE,UACAM,eACAL;YAGJ,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIW,uBAAuB;gBAAEF;gBAAO,UAAUJ;gBAAeK;gBAAOb;YAAM;YAG9E,MAAMe,eAAe,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAACf,OAAOY;YAC1D,IAAIG,aAAa,MAAM,IACnB,OAAOV,OAAO,IAAI,CAACU,aAAa,KAAK;YAGzC,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIC,sBAAsB;gBACtBJ;gBACA,UAAUJ;gBACVK;gBACAb;YACJ;YAGJ,OAAOK,OAAO,EAAE,CAACO;QACrB,EAAE,OAAOK,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"}
@@ -106,7 +106,7 @@ class CreateEntryRevisionFromDataFactoryImpl {
106
106
  createdOn: getDate(rawInput.createdOn, latestStorageEntry.createdOn),
107
107
  savedOn: getDate(rawInput.savedOn, currentDateTime),
108
108
  modifiedOn: getDate(rawInput.modifiedOn, currentDateTime),
109
- createdBy: getIdentity(rawInput.createdBy, latestStorageEntry.createdBy),
109
+ createdBy: latestStorageEntry.createdBy,
110
110
  savedBy: getIdentity(rawInput.savedBy, currentIdentity),
111
111
  modifiedBy: getIdentity(rawInput.modifiedBy, currentIdentity),
112
112
  ...entryLevelPublishingMetaFields,
@@ -1 +1 @@
1
- {"version":3,"file":"features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.js","sources":["../../../../../src/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport {\n CreateEntryRevisionFromDataFactory as FactoryAbstraction,\n type ICreateEntryRevisionFromDataFactory,\n type ICreateEntryRevisionFromDataResponse\n} from \"./abstractions.js\";\nimport { AccessControl, CmsContext } from \"~/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport type {\n CmsEntry,\n CmsEntryValues,\n CmsModel,\n CreateCmsEntryInput,\n CreateCmsEntryOptionsInput\n} from \"~/types/index.js\";\nimport { getDate } from \"~/utils/date.js\";\nimport { getIdentity } from \"~/utils/identity.js\";\nimport { mapAndCleanUpdatedInputData } from \"../mapAndCleanUpdatedInputData.js\";\nimport { validateModelEntryDataOrThrow } from \"~/crud/contentEntry/entryDataValidation.js\";\nimport { referenceFieldsMapping } from \"~/crud/contentEntry/referenceFieldsMapping.js\";\nimport { createIdentifier, parseIdentifier } from \"@webiny/utils\";\nimport WebinyError from \"@webiny/error\";\nimport { STATUS_DRAFT, STATUS_PUBLISHED, STATUS_UNPUBLISHED } from \"../statuses.js\";\nimport { NotAuthorizedError } from \"~/utils/errors.js\";\nimport { getSystem } from \"../system.js\";\n\nconst increaseEntryIdVersion = (id: string) => {\n const { id: entryId, version } = parseIdentifier(id);\n if (!version) {\n throw new WebinyError(\n \"Cannot increase version on the ID without the version part.\",\n \"WRONG_ID\",\n {\n id\n }\n );\n }\n return {\n entryId,\n version: version + 1,\n id: createIdentifier({\n id: entryId,\n version: version + 1\n })\n };\n};\n\nclass CreateEntryRevisionFromDataFactoryImpl implements ICreateEntryRevisionFromDataFactory {\n public constructor(\n private readonly cmsContext: CmsContext.Interface,\n private readonly identityContext: IdentityContext.Interface,\n private readonly tenantContext: TenantContext.Interface,\n private readonly accessControl: AccessControl.Interface\n ) {}\n\n public async create<TValues extends CmsEntryValues = CmsEntryValues>(\n sourceId: string,\n model: CmsModel,\n rawInput: CreateCmsEntryInput<TValues>,\n originalEntry: CmsEntry<TValues>,\n latestStorageEntry: CmsEntry<TValues>,\n options?: CreateCmsEntryOptionsInput\n ): Promise<ICreateEntryRevisionFromDataResponse<TValues>> {\n const initialValues = {\n ...originalEntry.values,\n ...mapAndCleanUpdatedInputData<TValues>(model, rawInput.values)\n };\n\n await validateModelEntryDataOrThrow({\n context: this.cmsContext,\n model,\n values: initialValues,\n entry: originalEntry,\n skipValidators: options?.skipValidators\n });\n\n const values = await referenceFieldsMapping<TValues>({\n context: this.cmsContext,\n model,\n values: initialValues,\n validateEntries: false\n });\n\n const latestId = latestStorageEntry ? latestStorageEntry.id : sourceId;\n const { id, version: nextVersion } = increaseEntryIdVersion(latestId);\n\n const currentIdentity = this.identityContext.getIdentity();\n const currentDateTime = new Date();\n\n const status = rawInput.status || STATUS_DRAFT;\n if (status !== STATUS_DRAFT) {\n if (status === STATUS_PUBLISHED) {\n const canPublish = await this.accessControl.canAccessEntry({ model, pw: \"p\" });\n if (!canPublish) {\n throw new NotAuthorizedError(\n `Not allowed to access \"${model.modelId}\" entries.`\n );\n }\n } else if (status === STATUS_UNPUBLISHED) {\n const canUnpublish = await this.accessControl.canAccessEntry({ model, pw: \"u\" });\n if (!canUnpublish) {\n throw new NotAuthorizedError(\n `Not allowed to access \"${model.modelId}\" entries.`\n );\n }\n }\n }\n\n const locked = status !== STATUS_DRAFT;\n\n let revisionLevelPublishingMetaFields: Pick<\n CmsEntry,\n | \"revisionFirstPublishedOn\"\n | \"revisionLastPublishedOn\"\n | \"revisionFirstPublishedBy\"\n | \"revisionLastPublishedBy\"\n > = {\n revisionFirstPublishedOn: getDate(rawInput.revisionFirstPublishedOn, null),\n revisionLastPublishedOn: getDate(rawInput.revisionLastPublishedOn, null),\n revisionFirstPublishedBy: getIdentity(rawInput.revisionFirstPublishedBy, null),\n revisionLastPublishedBy: getIdentity(rawInput.revisionLastPublishedBy, null)\n };\n\n let entryLevelPublishingMetaFields: Pick<\n CmsEntry,\n \"firstPublishedOn\" | \"lastPublishedOn\" | \"firstPublishedBy\" | \"lastPublishedBy\"\n > = {\n firstPublishedOn: getDate(\n rawInput.firstPublishedOn,\n latestStorageEntry.firstPublishedOn\n ),\n lastPublishedOn: getDate(rawInput.lastPublishedOn, latestStorageEntry.lastPublishedOn),\n firstPublishedBy: getIdentity(\n rawInput.firstPublishedBy,\n latestStorageEntry.firstPublishedBy\n ),\n lastPublishedBy: getIdentity(\n rawInput.lastPublishedBy,\n latestStorageEntry.lastPublishedBy\n )\n };\n\n if (status === STATUS_PUBLISHED) {\n revisionLevelPublishingMetaFields = {\n revisionFirstPublishedOn: getDate(\n rawInput.revisionFirstPublishedOn,\n currentDateTime\n ),\n revisionLastPublishedOn: getDate(rawInput.revisionLastPublishedOn, currentDateTime),\n revisionFirstPublishedBy: getIdentity(\n rawInput.revisionFirstPublishedBy,\n currentIdentity\n ),\n revisionLastPublishedBy: getIdentity(\n rawInput.revisionLastPublishedBy,\n currentIdentity\n )\n };\n\n entryLevelPublishingMetaFields = {\n firstPublishedOn: getDate(\n rawInput.firstPublishedOn,\n latestStorageEntry.firstPublishedOn\n ),\n lastPublishedOn: getDate(rawInput.lastPublishedOn, currentDateTime),\n firstPublishedBy: getIdentity(\n rawInput.firstPublishedBy,\n latestStorageEntry.firstPublishedBy\n ),\n lastPublishedBy: getIdentity(rawInput.lastPublishedBy, currentIdentity)\n };\n }\n\n const entry: CmsEntry<TValues> = {\n ...originalEntry,\n id,\n version: nextVersion,\n createdOn: getDate(rawInput.createdOn, latestStorageEntry.createdOn),\n savedOn: getDate(rawInput.savedOn, currentDateTime),\n modifiedOn: getDate(rawInput.modifiedOn, currentDateTime),\n createdBy: getIdentity(rawInput.createdBy, latestStorageEntry.createdBy)!,\n savedBy: getIdentity(rawInput.savedBy, currentIdentity)!,\n modifiedBy: getIdentity(rawInput.modifiedBy, currentIdentity),\n ...entryLevelPublishingMetaFields,\n revisionCreatedOn: getDate(rawInput.revisionCreatedOn, currentDateTime),\n revisionSavedOn: getDate(rawInput.revisionSavedOn, currentDateTime),\n revisionModifiedOn: getDate(rawInput.revisionModifiedOn, null),\n revisionCreatedBy: getIdentity(rawInput.revisionCreatedBy, currentIdentity)!,\n revisionSavedBy: getIdentity(rawInput.revisionSavedBy, currentIdentity)!,\n revisionModifiedBy: getIdentity(rawInput.revisionModifiedBy, null),\n ...revisionLevelPublishingMetaFields,\n locked,\n status,\n values,\n system: getSystem({\n input: rawInput,\n original: originalEntry\n }),\n live: originalEntry.live,\n expiresAt: null\n };\n\n return {\n entry,\n input: {\n ...rawInput,\n values: structuredClone(values)\n }\n };\n }\n}\n\nexport const CreateEntryRevisionFromDataFactory = createImplementation({\n abstraction: FactoryAbstraction,\n implementation: CreateEntryRevisionFromDataFactoryImpl,\n dependencies: [CmsContext, IdentityContext, TenantContext, AccessControl]\n});\n"],"names":["increaseEntryIdVersion","id","entryId","version","parseIdentifier","WebinyError","createIdentifier","CreateEntryRevisionFromDataFactoryImpl","cmsContext","identityContext","tenantContext","accessControl","sourceId","model","rawInput","originalEntry","latestStorageEntry","options","initialValues","mapAndCleanUpdatedInputData","validateModelEntryDataOrThrow","values","referenceFieldsMapping","latestId","nextVersion","currentIdentity","currentDateTime","Date","status","STATUS_DRAFT","STATUS_PUBLISHED","canPublish","NotAuthorizedError","STATUS_UNPUBLISHED","canUnpublish","locked","revisionLevelPublishingMetaFields","getDate","getIdentity","entryLevelPublishingMetaFields","entry","getSystem","structuredClone","CreateEntryRevisionFromDataFactory","createImplementation","FactoryAbstraction","CmsContext","IdentityContext","TenantContext","Acc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QvB,SAAS,eAAe,EAAEY;gBACnD,kBAAkBY,YACdxB,SAAS,gBAAgB,EACzBE,mBAAmB,gBAAgB;gBAEvC,iBAAiBsB,YAAYxB,SAAS,eAAe,EAAEW;YAC3D;QACJ;QAEA,MAAMe,QAA2B;YAC7B,GAAGzB,aAAa;YAChBd;YACA,SAASuB;YACT,WAAWa,QAAQvB,SAAS,SAAS,EAAEE,mBAAmB,SAAS;YACnE,SAASqB,QAAQvB,SAAS,OAAO,EAAEY;YACnC,YAAYW,QAAQvB,SAAS,UAAU,EAAEY;YACzC,WAAWY,YAAYxB,SAAS,SAAS,EAAEE,mBAAmB,SAAS;YACvE,SAASsB,YAAYxB,SAAS,OAAO,EAAEW;YACvC,YAAYa,YAAYxB,SAAS,UAAU,EAAEW;YAC7C,GAAGc,8BAA8B;YACjC,mBAAmBF,QAAQvB,SAAS,iBAAiB,EAAEY;YACvD,iBAAiBW,QAAQvB,SAAS,eAAe,EAAEY;YACnD,oBAAoBW,QAAQvB,SAAS,kBAAkB,EAAE;YACzD,mBAAmBwB,YAAYxB,SAAS,iBAAiB,EAAEW;YAC3D,iBAAiBa,YAAYxB,SAAS,eAAe,EAAEW;YACvD,oBAAoBa,YAAYxB,SAAS,kBAAkB,EAAE;YAC7D,GAAGsB,iCAAiC;YACpCD;YACAP;YACAP;YACA,QAAQoB,UAAU;gBACd,OAAO3B;gBACP,UAAUC;YACd;YACA,MAAMA,cAAc,IAAI;YACxB,WAAW;QACf;QAEA,OAAO;YACHyB;YACA,OAAO;gBACH,GAAG1B,QAAQ;gBACX,QAAQ4B,gBAAgBrB;YAC5B;QACJ;IACJ;AACJ;AAEO,MAAMsB,wEAAqCC,qBAAqB;IACnE,aAAaC;IACb,gBAAgBtC;IAChB,cAAc;QAACuC;QAAYC;QAAiBC;QAAeC;KAAc;AAC7E"}
1
+ {"version":3,"file":"features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.js","sources":["../../../../../src/features/contentEntry/entryDataFactories/CreateEntryRevisionFromDataFactory/CreateEntryRevisionFromDataFactory.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport {\n CreateEntryRevisionFromDataFactory as FactoryAbstraction,\n type ICreateEntryRevisionFromDataFactory,\n type ICreateEntryRevisionFromDataResponse\n} from \"./abstractions.js\";\nimport { AccessControl, CmsContext } from \"~/features/shared/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport type {\n CmsEntry,\n CmsEntryValues,\n CmsModel,\n CreateCmsEntryInput,\n CreateCmsEntryOptionsInput\n} from \"~/types/index.js\";\nimport { getDate } from \"~/utils/date.js\";\nimport { getIdentity } from \"~/utils/identity.js\";\nimport { mapAndCleanUpdatedInputData } from \"../mapAndCleanUpdatedInputData.js\";\nimport { validateModelEntryDataOrThrow } from \"~/crud/contentEntry/entryDataValidation.js\";\nimport { referenceFieldsMapping } from \"~/crud/contentEntry/referenceFieldsMapping.js\";\nimport { createIdentifier, parseIdentifier } from \"@webiny/utils\";\nimport WebinyError from \"@webiny/error\";\nimport { STATUS_DRAFT, STATUS_PUBLISHED, STATUS_UNPUBLISHED } from \"../statuses.js\";\nimport { NotAuthorizedError } from \"~/utils/errors.js\";\nimport { getSystem } from \"../system.js\";\n\nconst increaseEntryIdVersion = (id: string) => {\n const { id: entryId, version } = parseIdentifier(id);\n if (!version) {\n throw new WebinyError(\n \"Cannot increase version on the ID without the version part.\",\n \"WRONG_ID\",\n {\n id\n }\n );\n }\n return {\n entryId,\n version: version + 1,\n id: createIdentifier({\n id: entryId,\n version: version + 1\n })\n };\n};\n\nclass CreateEntryRevisionFromDataFactoryImpl implements ICreateEntryRevisionFromDataFactory {\n public constructor(\n private readonly cmsContext: CmsContext.Interface,\n private readonly identityContext: IdentityContext.Interface,\n private readonly tenantContext: TenantContext.Interface,\n private readonly accessControl: AccessControl.Interface\n ) {}\n\n public async create<TValues extends CmsEntryValues = CmsEntryValues>(\n sourceId: string,\n model: CmsModel,\n rawInput: CreateCmsEntryInput<TValues>,\n originalEntry: CmsEntry<TValues>,\n latestStorageEntry: CmsEntry<TValues>,\n options?: CreateCmsEntryOptionsInput\n ): Promise<ICreateEntryRevisionFromDataResponse<TValues>> {\n const initialValues = {\n ...originalEntry.values,\n ...mapAndCleanUpdatedInputData<TValues>(model, rawInput.values)\n };\n\n await validateModelEntryDataOrThrow({\n context: this.cmsContext,\n model,\n values: initialValues,\n entry: originalEntry,\n skipValidators: options?.skipValidators\n });\n\n const values = await referenceFieldsMapping<TValues>({\n context: this.cmsContext,\n model,\n values: initialValues,\n validateEntries: false\n });\n\n const latestId = latestStorageEntry ? latestStorageEntry.id : sourceId;\n const { id, version: nextVersion } = increaseEntryIdVersion(latestId);\n\n const currentIdentity = this.identityContext.getIdentity();\n const currentDateTime = new Date();\n\n const status = rawInput.status || STATUS_DRAFT;\n if (status !== STATUS_DRAFT) {\n if (status === STATUS_PUBLISHED) {\n const canPublish = await this.accessControl.canAccessEntry({ model, pw: \"p\" });\n if (!canPublish) {\n throw new NotAuthorizedError(\n `Not allowed to access \"${model.modelId}\" entries.`\n );\n }\n } else if (status === STATUS_UNPUBLISHED) {\n const canUnpublish = await this.accessControl.canAccessEntry({ model, pw: \"u\" });\n if (!canUnpublish) {\n throw new NotAuthorizedError(\n `Not allowed to access \"${model.modelId}\" entries.`\n );\n }\n }\n }\n\n const locked = status !== STATUS_DRAFT;\n\n let revisionLevelPublishingMetaFields: Pick<\n CmsEntry,\n | \"revisionFirstPublishedOn\"\n | \"revisionLastPublishedOn\"\n | \"revisionFirstPublishedBy\"\n | \"revisionLastPublishedBy\"\n > = {\n revisionFirstPublishedOn: getDate(rawInput.revisionFirstPublishedOn, null),\n revisionLastPublishedOn: getDate(rawInput.revisionLastPublishedOn, null),\n revisionFirstPublishedBy: getIdentity(rawInput.revisionFirstPublishedBy, null),\n revisionLastPublishedBy: getIdentity(rawInput.revisionLastPublishedBy, null)\n };\n\n let entryLevelPublishingMetaFields: Pick<\n CmsEntry,\n \"firstPublishedOn\" | \"lastPublishedOn\" | \"firstPublishedBy\" | \"lastPublishedBy\"\n > = {\n firstPublishedOn: getDate(\n rawInput.firstPublishedOn,\n latestStorageEntry.firstPublishedOn\n ),\n lastPublishedOn: getDate(rawInput.lastPublishedOn, latestStorageEntry.lastPublishedOn),\n firstPublishedBy: getIdentity(\n rawInput.firstPublishedBy,\n latestStorageEntry.firstPublishedBy\n ),\n lastPublishedBy: getIdentity(\n rawInput.lastPublishedBy,\n latestStorageEntry.lastPublishedBy\n )\n };\n\n if (status === STATUS_PUBLISHED) {\n revisionLevelPublishingMetaFields = {\n revisionFirstPublishedOn: getDate(\n rawInput.revisionFirstPublishedOn,\n currentDateTime\n ),\n revisionLastPublishedOn: getDate(rawInput.revisionLastPublishedOn, currentDateTime),\n revisionFirstPublishedBy: getIdentity(\n rawInput.revisionFirstPublishedBy,\n currentIdentity\n ),\n revisionLastPublishedBy: getIdentity(\n rawInput.revisionLastPublishedBy,\n currentIdentity\n )\n };\n\n entryLevelPublishingMetaFields = {\n firstPublishedOn: getDate(\n rawInput.firstPublishedOn,\n latestStorageEntry.firstPublishedOn\n ),\n lastPublishedOn: getDate(rawInput.lastPublishedOn, currentDateTime),\n firstPublishedBy: getIdentity(\n rawInput.firstPublishedBy,\n latestStorageEntry.firstPublishedBy\n ),\n lastPublishedBy: getIdentity(rawInput.lastPublishedBy, currentIdentity)\n };\n }\n\n const entry: CmsEntry<TValues> = {\n ...originalEntry,\n id,\n version: nextVersion,\n createdOn: getDate(rawInput.createdOn, latestStorageEntry.createdOn),\n savedOn: getDate(rawInput.savedOn, currentDateTime),\n modifiedOn: getDate(rawInput.modifiedOn, currentDateTime),\n createdBy: latestStorageEntry.createdBy,\n savedBy: getIdentity(rawInput.savedBy, currentIdentity)!,\n modifiedBy: getIdentity(rawInput.modifiedBy, currentIdentity),\n ...entryLevelPublishingMetaFields,\n revisionCreatedOn: getDate(rawInput.revisionCreatedOn, currentDateTime),\n revisionSavedOn: getDate(rawInput.revisionSavedOn, currentDateTime),\n revisionModifiedOn: getDate(rawInput.revisionModifiedOn, null),\n revisionCreatedBy: getIdentity(rawInput.revisionCreatedBy, currentIdentity)!,\n revisionSavedBy: getIdentity(rawInput.revisionSavedBy, currentIdentity)!,\n revisionModifiedBy: getIdentity(rawInput.revisionModifiedBy, null),\n ...revisionLevelPublishingMetaFields,\n locked,\n status,\n values,\n system: getSystem({\n input: rawInput,\n original: originalEntry\n }),\n live: originalEntry.live,\n expiresAt: null\n };\n\n return {\n entry,\n input: {\n ...rawInput,\n values: structuredClone(values)\n }\n };\n }\n}\n\nexport const CreateEntryRevisionFromDataFactory = createImplementation({\n abstraction: FactoryAbstraction,\n implementation: CreateEntryRevisionFromDataFactoryImpl,\n dependencies: [CmsContext, IdentityContext, TenantContext, AccessControl]\n});\n"],"names":["increaseEntryIdVersion","id","entryId","version","parseIdentifier","WebinyError","createIdentifier","CreateEntryRevisionFromDataFactoryImpl","cmsContext","identityContext","tenantContext","accessControl","sourceId","model","rawInput","originalEntry","latestStorageEntry","options","initialValues","mapAndCleanUpdatedInputData","validateModelEntryDataOrThrow","values","referenceFieldsMapping","latestId","nextVersion","currentIdentity","currentDateTime","Date","status","STATUS_DRAFT","STATUS_PUBLISHED","canPublish","NotAuthorizedError","STATUS_UNPUBLISHED","canUnpublish","locked","revisionLevelPublishingMetaFields","getDate","getIdentity","entryLevelPublishingMetaFields","entry","getSystem","structuredClone","CreateEntryRevisionFromDataFactory","createImplementation","FactoryAbstraction","CmsContext","IdentityContext","TenantContext","AccessControl"],"mappings":";;;;;;;;;;;;;;;AA2BA,MAAMA,yBAAyB,CAACC;IAC5B,MAAM,EAAE,IAAIC,OAAO,EAAEC,OAAO,EAAE,GAAGC,gBAAgBH;IACjD,IAAI,CAACE,SACD,MAAM,IAAIE,MACN,+DACA,YACA;QACIJ;IACJ;IAGR,OAAO;QACH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YACT,WAAWa,QAAQvB,SAAS,SAAS,EAAEE,mBAAmB,SAAS;YACnE,SAASqB,QAAQvB,SAAS,OAAO,EAAEY;YACnC,YAAYW,QAAQvB,SAAS,UAAU,EAAEY;YACzC,WAAWV,mBAAmB,SAAS;YACvC,SAASsB,YAAYxB,SAAS,OAAO,EAAEW;YACvC,YAAYa,YAAYxB,SAAS,UAAU,EAAEW;YAC7C,GAAGc,8BAA8B;YACjC,mBAAmBF,QAAQvB,SAAS,iBAAiB,EAAEY;YACvD,iBAAiBW,QAAQvB,SAAS,eAAe,EAAEY;YACnD,oBAAoBW,QAAQvB,SAAS,kBAAkB,EAAE;YACzD,mBAAmBwB,YAAYxB,SAAS,iBAAiB,EAAEW;YAC3D,iBAAiBa,YAAYxB,SAAS,eAAe,EAAEW;YACvD,oBAAoBa,YAAYxB,SAAS,kBAAkB,EAAE;YAC7D,GAAGsB,iCAAiC;YACpCD;YACAP;YACAP;YACA,QAAQoB,UAAU;gBACd,OAAO3B;gBACP,UAAUC;YACd;YACA,MAAMA,cAAc,IAAI;YACxB,WAAW;QACf;QAEA,OAAO;YACHyB;YACA,OAAO;gBACH,GAAG1B,QAAQ;gBACX,QAAQ4B,gBAAgBrB;YAC5B;QACJ;IACJ;AACJ;AAEO,MAAMsB,wEAAqCC,qBAAqB;IACnE,aAAaC;IACb,gBAAgBtC;IAChB,cAAc;QAACuC;QAAYC;QAAiBC;QAAeC;KAAc;AAC7E"}
@@ -64,7 +64,7 @@ class UpdateEntryDataFactoryImpl {
64
64
  restoredOn: getDate(rawInput.restoredOn, null),
65
65
  firstPublishedOn: getDate(rawInput.firstPublishedOn, originalEntry.firstPublishedOn),
66
66
  lastPublishedOn: getDate(rawInput.lastPublishedOn, originalEntry.lastPublishedOn),
67
- createdBy: getIdentity(rawInput.createdBy, originalEntry.createdBy),
67
+ createdBy: originalEntry.createdBy,
68
68
  savedBy: getIdentity(rawInput.savedBy, currentIdentity),
69
69
  modifiedBy: getIdentity(rawInput.modifiedBy, currentIdentity),
70
70
  deletedBy: getIdentity(rawInput.deletedBy, null),
@@ -1 +1 @@
1
- {"version":3,"file":"features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.js","sources":["../../../../../src/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport {\n type IUpdateEntryDataFactory,\n type IUpdateEntryDataResponse,\n UpdateEntryDataFactory as FactoryAbstraction\n} from \"./abstractions.js\";\nimport { CmsContext } from \"~/features/shared/abstractions.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport type {\n CmsEntry,\n CmsEntryStatus,\n CmsEntryValues,\n CmsModel,\n UpdateCmsEntryInput,\n UpdateCmsEntryOptionsInput\n} from \"~/types/index.js\";\nimport { getDate } from \"~/utils/date.js\";\nimport { getIdentity } from \"~/utils/identity.js\";\nimport { validateModelEntryDataOrThrow } from \"~/crud/contentEntry/entryDataValidation.js\";\nimport { referenceFieldsMapping } from \"~/crud/contentEntry/referenceFieldsMapping.js\";\nimport { mapAndCleanUpdatedInputData } from \"../mapAndCleanUpdatedInputData.js\";\nimport { getSystem } from \"../system.js\";\nimport { getExpiresAt } from \"../expiresAt.js\";\n\nconst allowedEntryStatus: string[] = [\"draft\", \"published\", \"unpublished\"];\n\nconst transformEntryStatus = (status: CmsEntryStatus | string): CmsEntryStatus => {\n return allowedEntryStatus.includes(status) ? (status as CmsEntryStatus) : \"draft\";\n};\n\nclass UpdateEntryDataFactoryImpl implements IUpdateEntryDataFactory {\n public constructor(\n private readonly cmsContext: CmsContext.Interface,\n private readonly identityContext: IdentityContext.Interface\n ) {}\n\n public async create<TValues extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n rawInput: UpdateCmsEntryInput<TValues>,\n originalEntry: CmsEntry<TValues>,\n options?: UpdateCmsEntryOptionsInput\n ): Promise<IUpdateEntryDataResponse<TValues>> {\n const cleanedValues = mapAndCleanUpdatedInputData<TValues>(\n model,\n rawInput?.values || ({} as TValues)\n );\n\n await validateModelEntryDataOrThrow({\n context: this.cmsContext,\n model,\n values: cleanedValues,\n entry: originalEntry,\n skipValidators: options?.skipValidators\n });\n\n const mergedValues: TValues = {\n ...originalEntry.values,\n ...cleanedValues\n };\n\n const values = await referenceFieldsMapping<TValues>({\n context: this.cmsContext,\n model,\n values: mergedValues,\n validateEntries: false\n });\n\n const currentIdentity = this.identityContext.getIdentity();\n const currentDateTime = new Date();\n\n const entry: CmsEntry<TValues> = {\n ...originalEntry,\n revisionCreatedOn: getDate(rawInput.revisionCreatedOn, originalEntry.revisionCreatedOn),\n revisionModifiedOn: getDate(rawInput.revisionModifiedOn, currentDateTime),\n revisionSavedOn: getDate(rawInput.revisionSavedOn, currentDateTime),\n revisionDeletedOn: getDate(rawInput.revisionDeletedOn, null),\n revisionRestoredOn: getDate(rawInput.revisionRestoredOn, null),\n revisionFirstPublishedOn: getDate(\n rawInput.revisionFirstPublishedOn,\n originalEntry.revisionFirstPublishedOn\n ),\n revisionLastPublishedOn: getDate(\n rawInput.revisionLastPublishedOn,\n originalEntry.revisionLastPublishedOn\n ),\n revisionCreatedBy: getIdentity(\n rawInput.revisionCreatedBy,\n originalEntry.revisionCreatedBy\n )!,\n revisionModifiedBy: getIdentity(rawInput.revisionModifiedBy, currentIdentity),\n revisionSavedBy: getIdentity(rawInput.revisionSavedBy, currentIdentity)!,\n revisionDeletedBy: getIdentity(rawInput.revisionSavedBy, null),\n revisionRestoredBy: getIdentity(rawInput.revisionRestoredBy, null),\n revisionFirstPublishedBy: getIdentity(\n rawInput.revisionFirstPublishedBy,\n originalEntry.revisionFirstPublishedBy\n ),\n revisionLastPublishedBy: getIdentity(\n rawInput.revisionLastPublishedBy,\n originalEntry.revisionLastPublishedBy\n ),\n createdOn: getDate(rawInput.createdOn, originalEntry.createdOn),\n savedOn: getDate(rawInput.savedOn, currentDateTime),\n modifiedOn: getDate(rawInput.modifiedOn, currentDateTime),\n deletedOn: getDate(rawInput.deletedOn, null),\n restoredOn: getDate(rawInput.restoredOn, null),\n firstPublishedOn: getDate(rawInput.firstPublishedOn, originalEntry.firstPublishedOn),\n lastPublishedOn: getDate(rawInput.lastPublishedOn, originalEntry.lastPublishedOn),\n createdBy: getIdentity(rawInput.createdBy, originalEntry.createdBy)!,\n savedBy: getIdentity(rawInput.savedBy, currentIdentity)!,\n modifiedBy: getIdentity(rawInput.modifiedBy, currentIdentity),\n deletedBy: getIdentity(rawInput.deletedBy, null),\n restoredBy: getIdentity(rawInput.restoredBy, null),\n firstPublishedBy: getIdentity(\n rawInput.firstPublishedBy,\n originalEntry.firstPublishedBy\n ),\n lastPublishedBy: getIdentity(rawInput.lastPublishedBy, originalEntry.lastPublishedBy),\n values,\n status: transformEntryStatus(originalEntry.status),\n system: getSystem({\n input: rawInput,\n original: originalEntry\n }),\n live: originalEntry.live,\n expiresAt: getExpiresAt({ expiresAt: rawInput.expiresAt }, originalEntry)\n };\n\n const folderId = rawInput.wbyAco_location?.folderId;\n if (folderId) {\n entry.location = {\n folderId\n };\n }\n\n return {\n entry,\n input: {\n ...rawInput,\n values: structuredClone(values)\n }\n };\n }\n}\n\nexport const UpdateEntryDataFactory = createImplementation({\n abstraction: FactoryAbstraction,\n implementation: UpdateEntryDataFactoryImpl,\n dependencies: [CmsContext, IdentityContext]\n});\n"],"names":["allowedEntryStatus","transformEntryStatus","status","UpdateEntryDataFactoryImpl","cmsContext","identityContext","model","rawInput","originalEntry","options","cleanedValues","mapAndCleanUpdatedInputData","validateModelEntryDataOrThrow","mergedValues","values","referenceFieldsMapping","currentIdentity","currentDateTime","Date","entry","getDate","getIdentity","getSystem","getExpiresAt","folderId","structuredClone","UpdateEntryDataFactory","createImplementation","FactoryAbstraction","CmsContext","IdentityContext"],"mappings":";;;;;;;;;;;AAwBA,MAAMA,qBAA+B;IAAC;IAAS;IAAa;CAAc;AAE1E,MAAMC,uBAAuB,CAACC,SACnBF,mBA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cAAc;QAAC0B;QAAYC;KAAgB;AAC/C"}
1
+ {"version":3,"file":"features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.js","sources":["../../../../../src/features/contentEntry/entryDataFactories/UpdateEntryDataFactory/UpdateEntryDataFactory.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport {\n type IUpdateEntryDataFactory,\n type IUpdateEntryDataResponse,\n UpdateEntryDataFactory as FactoryAbstraction\n} from \"./abstractions.js\";\nimport { CmsContext } from \"~/features/shared/abstractions.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport type {\n CmsEntry,\n CmsEntryStatus,\n CmsEntryValues,\n CmsModel,\n UpdateCmsEntryInput,\n UpdateCmsEntryOptionsInput\n} from \"~/types/index.js\";\nimport { getDate } from \"~/utils/date.js\";\nimport { getIdentity } from \"~/utils/identity.js\";\nimport { validateModelEntryDataOrThrow } from \"~/crud/contentEntry/entryDataValidation.js\";\nimport { referenceFieldsMapping } from \"~/crud/contentEntry/referenceFieldsMapping.js\";\nimport { mapAndCleanUpdatedInputData } from \"../mapAndCleanUpdatedInputData.js\";\nimport { getSystem } from \"../system.js\";\nimport { getExpiresAt } from \"../expiresAt.js\";\n\nconst allowedEntryStatus: string[] = [\"draft\", \"published\", \"unpublished\"];\n\nconst transformEntryStatus = (status: CmsEntryStatus | string): CmsEntryStatus => {\n return allowedEntryStatus.includes(status) ? (status as CmsEntryStatus) : \"draft\";\n};\n\nclass UpdateEntryDataFactoryImpl implements IUpdateEntryDataFactory {\n public constructor(\n private readonly cmsContext: CmsContext.Interface,\n private readonly identityContext: IdentityContext.Interface\n ) {}\n\n public async create<TValues extends CmsEntryValues = CmsEntryValues>(\n model: CmsModel,\n rawInput: UpdateCmsEntryInput<TValues>,\n originalEntry: CmsEntry<TValues>,\n options?: UpdateCmsEntryOptionsInput\n ): Promise<IUpdateEntryDataResponse<TValues>> {\n const cleanedValues = mapAndCleanUpdatedInputData<TValues>(\n model,\n rawInput?.values || ({} as TValues)\n );\n\n await validateModelEntryDataOrThrow({\n context: this.cmsContext,\n model,\n values: cleanedValues,\n entry: originalEntry,\n skipValidators: options?.skipValidators\n });\n\n const mergedValues: TValues = {\n ...originalEntry.values,\n ...cleanedValues\n };\n\n const values = await referenceFieldsMapping<TValues>({\n context: this.cmsContext,\n model,\n values: mergedValues,\n validateEntries: false\n });\n\n const currentIdentity = this.identityContext.getIdentity();\n const currentDateTime = new Date();\n\n const entry: CmsEntry<TValues> = {\n ...originalEntry,\n revisionCreatedOn: getDate(rawInput.revisionCreatedOn, originalEntry.revisionCreatedOn),\n revisionModifiedOn: getDate(rawInput.revisionModifiedOn, currentDateTime),\n revisionSavedOn: getDate(rawInput.revisionSavedOn, currentDateTime),\n revisionDeletedOn: getDate(rawInput.revisionDeletedOn, null),\n revisionRestoredOn: getDate(rawInput.revisionRestoredOn, null),\n revisionFirstPublishedOn: getDate(\n rawInput.revisionFirstPublishedOn,\n originalEntry.revisionFirstPublishedOn\n ),\n revisionLastPublishedOn: getDate(\n rawInput.revisionLastPublishedOn,\n originalEntry.revisionLastPublishedOn\n ),\n revisionCreatedBy: getIdentity(\n rawInput.revisionCreatedBy,\n originalEntry.revisionCreatedBy\n )!,\n revisionModifiedBy: getIdentity(rawInput.revisionModifiedBy, currentIdentity),\n revisionSavedBy: getIdentity(rawInput.revisionSavedBy, currentIdentity)!,\n revisionDeletedBy: getIdentity(rawInput.revisionSavedBy, null),\n revisionRestoredBy: getIdentity(rawInput.revisionRestoredBy, null),\n revisionFirstPublishedBy: getIdentity(\n rawInput.revisionFirstPublishedBy,\n originalEntry.revisionFirstPublishedBy\n ),\n revisionLastPublishedBy: getIdentity(\n rawInput.revisionLastPublishedBy,\n originalEntry.revisionLastPublishedBy\n ),\n createdOn: getDate(rawInput.createdOn, originalEntry.createdOn),\n savedOn: getDate(rawInput.savedOn, currentDateTime),\n modifiedOn: getDate(rawInput.modifiedOn, currentDateTime),\n deletedOn: getDate(rawInput.deletedOn, null),\n restoredOn: getDate(rawInput.restoredOn, null),\n firstPublishedOn: getDate(rawInput.firstPublishedOn, originalEntry.firstPublishedOn),\n lastPublishedOn: getDate(rawInput.lastPublishedOn, originalEntry.lastPublishedOn),\n createdBy: originalEntry.createdBy,\n savedBy: getIdentity(rawInput.savedBy, currentIdentity)!,\n modifiedBy: getIdentity(rawInput.modifiedBy, currentIdentity),\n deletedBy: getIdentity(rawInput.deletedBy, null),\n restoredBy: getIdentity(rawInput.restoredBy, null),\n firstPublishedBy: getIdentity(\n rawInput.firstPublishedBy,\n originalEntry.firstPublishedBy\n ),\n lastPublishedBy: getIdentity(rawInput.lastPublishedBy, originalEntry.lastPublishedBy),\n values,\n status: transformEntryStatus(originalEntry.status),\n system: getSystem({\n input: rawInput,\n original: originalEntry\n }),\n live: originalEntry.live,\n expiresAt: getExpiresAt({ expiresAt: rawInput.expiresAt }, originalEntry)\n };\n\n const folderId = rawInput.wbyAco_location?.folderId;\n if (folderId) {\n entry.location = {\n folderId\n };\n }\n\n return {\n entry,\n input: {\n ...rawInput,\n values: structuredClone(values)\n }\n };\n }\n}\n\nexport const UpdateEntryDataFactory = createImplementation({\n abstraction: FactoryAbstraction,\n implementation: UpdateEntryDataFactoryImpl,\n dependencies: [CmsContext, IdentityContext]\n});\n"],"names":["allowedEntryStatus","transformEntryStatus","status","UpdateEntryDataFactoryImpl","cmsContext","identityContext","model","rawInput","originalEntry","options","cleanedValues","mapAndCleanUpdatedInputData","validateModelEntryDataOrThrow","mergedValues","values","referenceFieldsMapping","currentIdentity","currentDateTime","Date","entry","getDate","getIdentity","getSystem","getExpiresAt","folderId","structuredClone","UpdateEntryDataFactory","createImplementation","FactoryAbstraction","CmsContext","IdentityContext"],"mappings":";;;;;;;;;;;AAwBA,MAAMA,qBAA+B;IAAC;IAAS;IAAa;CAAc;AAE1E,MAAMC,uBAAuB,CAACC,SACnBF,mBAAmB,QAAQ,CAACE,UAAWA,SAA4B;AAG9E,MAAMC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} 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":";;;;;;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,WAAW;gBACP,IAAIE,SAAS,EAAE;gBACf,aAAaA,SAAS,WAAW;gBACjC,MAAMA,SAAS,IAAI;YACvB;YACA,WAAW,IAAII,OAAO,WAAW;YACjC,SAAS,IAAIA,OAAO,WAAW;YAC/B,QAAQZ,SAAS,MAAM,IAAIS,OAAO,EAAE;QACxC;QAGA,MAAMI,iBAAiB,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC;YAAEH;YAAO,KAAK;QAAI;QACjF,IAAI,CAACG,gBACD,OAAOhB,OAAO,IAAI,CAACC,wBAAwB,SAAS,CAACY;QAIzD,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAII,2BAA2B;YAAEJ;YAAOV;YAAU,OAAOM;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;gBACAV;gBACA,OAAOe,OAAO,KAAK;YACvB;YAEJ,OAAOlB,OAAO,IAAI,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,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,IAAIC,SAAS,SAAS,EAClB,OAAOH,OAAO,IAAI,CAAC,IAAII,mBAAmBP;QAI9C,MAAMQ,mBAAmB,MAAMC,kCAAkC,cAAc,CAAC;YAC5E,GAAGR,KAAK;YACR,aAAaA,MAAM,WAAW,IAAIK,SAAS,WAAW;QAC1D;QAEA,IAAI,CAACE,iBAAiB,OAAO,EAAE;YAC3B,MAAME,WAAWC,eAAeH,iBAAiB,KAAK;YACtD,OAAOL,OAAO,IAAI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,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"}
@@ -0,0 +1,30 @@
1
+ import type { CmsModel } from "../../../types/index.js";
2
+ /**
3
+ * An additional access rule for a content model, on top of the Headless CMS permissions.
4
+ * When a guard handles a model and denies access, the model and its entries are not accessible,
5
+ * whatever the Headless CMS permissions allow.
6
+ *
7
+ * Use it for a model that belongs to another application with its own permission.
8
+ */
9
+ export interface IModelAccessGuardParams {
10
+ /**
11
+ * The access being checked: "r" (read), "w" (write) or "d" (delete).
12
+ * Not set means read.
13
+ */
14
+ rwd?: string;
15
+ /**
16
+ * The publishing action being checked, for example "p" (publish) or "u" (unpublish).
17
+ */
18
+ pw?: string;
19
+ }
20
+ export interface IModelAccessGuard {
21
+ /** Does this guard apply to the given model? */
22
+ canHandle(model: Pick<CmsModel, "modelId">): boolean;
23
+ /** May the current identity access the model and its entries in the given way? */
24
+ canAccess(params: IModelAccessGuardParams): Promise<boolean>;
25
+ }
26
+ export declare const ModelAccessGuard: import("@webiny/di").Abstraction<IModelAccessGuard>;
27
+ export declare namespace ModelAccessGuard {
28
+ type Interface = IModelAccessGuard;
29
+ type Params = IModelAccessGuardParams;
30
+ }
@@ -0,0 +1,5 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ const ModelAccessGuard = createAbstraction("Cms/ModelAccessGuard");
3
+ export { ModelAccessGuard };
4
+
5
+ //# sourceMappingURL=abstractions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/contentModel/ModelAccessGuard/abstractions.js","sources":["../../../../src/features/contentModel/ModelAccessGuard/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { CmsModel } from \"~/types/index.js\";\n\n/**\n * An additional access rule for a content model, on top of the Headless CMS permissions.\n * When a guard handles a model and denies access, the model and its entries are not accessible,\n * whatever the Headless CMS permissions allow.\n *\n * Use it for a model that belongs to another application with its own permission.\n */\nexport interface IModelAccessGuardParams {\n /**\n * The access being checked: \"r\" (read), \"w\" (write) or \"d\" (delete).\n * Not set means read.\n */\n rwd?: string;\n /**\n * The publishing action being checked, for example \"p\" (publish) or \"u\" (unpublish).\n */\n pw?: string;\n}\n\nexport interface IModelAccessGuard {\n /** Does this guard apply to the given model? */\n canHandle(model: Pick<CmsModel, \"modelId\">): boolean;\n /** May the current identity access the model and its entries in the given way? */\n canAccess(params: IModelAccessGuardParams): Promise<boolean>;\n}\n\nexport const ModelAccessGuard = createAbstraction<IModelAccessGuard>(\"Cms/ModelAccessGuard\");\n\nexport namespace ModelAccessGuard {\n export type Interface = IModelAccessGuard;\n export type Params = IModelAccessGuardParams;\n}\n"],"names":["ModelAccessGuard","createAbstraction"],"mappings":";AA6BO,MAAMA,mBAAmBC,kBAAqC"}
@@ -0,0 +1,2 @@
1
+ export { ModelAccessGuard } from "./abstractions.js";
2
+ export type { IModelAccessGuard, IModelAccessGuardParams } from "./abstractions.js";
@@ -0,0 +1 @@
1
+ export { ModelAccessGuard } from "./abstractions.js";
@@ -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,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C,OAAO,CAC7B,IAAIE,sBAAsB;gBACtBf;gBACA,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,MA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AAI,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 +1 @@
1
- {"version":3,"file":"features/modelBuilder/fields/TextFieldType.js","sources":["../../../../src/features/modelBuilder/fields/TextFieldType.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport { DataFieldBuilder } from \"./FieldBuilder.js\";\nimport { FieldType, type IFieldTypeFactory } from \"./abstractions.js\";\nimport type { FieldTypeValidator } from \"./fieldTypeValidator.js\";\n\nexport enum TextFieldSubTypes {\n COMPRESSED = \"compressed\",\n ENCRYPTED = \"encrypted\"\n}\n\nexport enum TextFieldTypes {\n TEXT = \"text\",\n COMPRESSED = \"text:compressed\",\n ENCRYPTED = \"text:encrypted\"\n}\n\nexport interface ITextFieldBuilder\n extends\n DataFieldBuilder<\"text\">,\n FieldTypeValidator.Required,\n FieldTypeValidator.MinLength,\n FieldTypeValidator.MaxLength,\n FieldTypeValidator.Pattern,\n FieldTypeValidator.Email,\n FieldTypeValidator.Url,\n FieldTypeValidator.LowerCase,\n FieldTypeValidator.UpperCase,\n FieldTypeValidator.LowerCaseSpace,\n FieldTypeValidator.UpperCaseSpace,\n FieldTypeValidator.Unique {\n compress(): this;\n encrypt(): this;\n}\n\n// Module augmentation for TypeScript autocomplete\ndeclare module \"../abstractions.js\" {\n interface IFieldBuilderRegistry {\n text(): ITextFieldBuilder;\n }\n}\n\nclass TextFieldBuilder extends DataFieldBuilder<\"text\"> implements ITextFieldBuilder {\n public constructor() {\n super(\"text\");\n }\n\n required(message?: string): this {\n return this.validation({\n name: \"required\",\n message: message || \"Value is required.\",\n settings: {}\n });\n }\n\n minLength(value: number, message?: string): this {\n return this.validation({\n name: \"minLength\",\n message: message || \"Value is too short.\",\n settings: { value: String(value) }\n });\n }\n\n maxLength(value: number, message?: string): this {\n return this.validation({\n name: \"maxLength\",\n message: message || \"Value is too long.\",\n settings: { value: String(value) }\n });\n }\n\n pattern(regex: string, flags: string = \"\", message?: string): this {\n return this.validation({\n name: \"pattern\",\n message: message || \"Invalid value.\",\n settings: {\n preset: \"custom\",\n regex,\n flags\n }\n });\n }\n\n email(message?: string): this {\n return this.validation({\n name: \"pattern\",\n message: message || \"Please enter a valid e-mail.\",\n settings: {\n preset: \"email\",\n regex: null,\n flags: null\n }\n });\n }\n\n url(message?: string): this {\n return this.validation({\n name: \"pattern\",\n message: message || \"Please enter a valid URL.\",\n settings: {\n preset: \"url\",\n regex: null,\n flags: null\n }\n });\n }\n\n lowerCase(message?: string): this {\n return this.validation({\n name: \"pattern\",\n message: message || \"Only lower case characters are allowed.\",\n settings: {\n preset: \"lowerCase\",\n regex: null,\n flags: null\n }\n });\n }\n\n upperCase(message?: string): this {\n return this.validation({\n name: \"pattern\",\n message: message || \"Only upper case characters are allowed.\",\n settings: {\n preset: \"upperCase\",\n regex: null,\n flags: null\n }\n });\n }\n\n lowerCaseSpace(message?: string): this {\n return this.validation({\n name: \"pattern\",\n message: message || \"Only lower case characters and space are allowed.\",\n settings: {\n preset: \"lowerCaseSpace\",\n regex: null,\n flags: null\n }\n });\n }\n\n upperCaseSpace(message?: string): this {\n return this.validation({\n name: \"pattern\",\n message: message || \"Only upper case characters and space are allowed.\",\n settings: {\n preset: \"upperCaseSpace\",\n regex: null,\n flags: null\n }\n });\n }\n\n unique(message?: string): this {\n return this.validation({\n name: \"unique\",\n message: message || \"Value must be unique.\",\n settings: {}\n });\n }\n\n public compress(): this {\n this.setSubType(TextFieldSubTypes.COMPRESSED);\n\n this.settings({\n disableFullTextSearch: true\n });\n\n return this;\n }\n public encrypt(): this {\n this.setSubType(TextFieldSubTypes.ENCRYPTED);\n\n this.settings({\n disableFullTextSearch: true\n });\n\n return this;\n }\n}\n\nclass TextFieldTypeFactory implements IFieldTypeFactory {\n readonly type = \"text\";\n\n create(): ITextFieldBuilder {\n return new TextFieldBuilder();\n }\n}\n\nexport const TextFieldType = createImplementation({\n abstraction: FieldType,\n implementation: TextFieldTypeFactory,\n dependencies: []\n});\n"],"names":["TextFieldSubTypes","TextFieldTypes","TextFieldBuilder","DataFieldBuilder","message","value","String","regex","flags","TextFieldTypeFactory","TextFieldType","createImplementation","FieldType"],"mappings":";;;AAKO,IAAKA,kCAAiBA,WAAAA,GAAAA,SAAjBA,iBAAiB;;;WAAjBA;;AAKL,IAAKC,+BAAcA,WAAAA,GAAAA,SAAdA,cAAc;;;;WAAdA;;AA+BZ,MAAMC,yBAAyBC;IAC3B,aAAqB;QACjB,KAAK,CAAC;IACV;IAEA,SAASC,OAAgB,EAAQ;QAC7B,OAAO,IAAI,CAAC,UAAU,CAAC;YACnB,MAAM;YACN,SAASA,WAAW;YACpB,UAAU,CAAC;QACf;IACJ;IAEA,UAAUC,KAAa,EAAED,OAAgB,EAAQ;QAC7C,OAAO,IAAI,CAAC,UAAU,CAAC;YACnB,MAAM;YACN,SAASA,WAAW;YACpB,UAAU;gBAAE,OAAOE,OAAOD;YAAO;QACrC;IACJ;IAEA,UAAUA,KAAa,EAAED,OAAgB,EAAQ;QAC7C,OAAO,IAAI,CAAC,UAAU,CAAC;YACnB,MAAM;YACN,SAASA,WAAW;YACpB,UAAU;gBAAE,OAAOE,OAAOD;YAAO;QACrC;IACJ;IAEA,QAAQE,KAAa,EAAEC,QAAgB,EAAE,EAAEJ,OAAgB,EAAQ;QAC/D,OAAO,IAAI,CAAC,UAAU,CAAC;YACnB,MAAM;YACN,SAASA,WAAW;YACpB,UAAU;gBACN,QAAQ;gBACRG;gBACAC;YACJ;QACJ;IACJ;IAEA,MAAMJ,OAAgB,EAAQ;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC;YACnB,MAAM;YACN,SAASA,WAAW;YACpB,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MK;IAGF,SAA4B;QACxB,OAAO,IAAIP;IACf;;aAJS,IAAI,GAAG;;AAKpB;AAEO,MAAMQ,gBAAgBC,qBAAqB;IAC9C,aAAaC;IACb,gBAAgBH;IAChB,cAAc,EAAE;AACpB"}
1
+ {"version":3,"file":"features/modelBuilder/fields/TextFieldType.js","sources":["../../../../src/features/modelBuilder/fields/TextFieldType.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport { DataFieldBuilder } from \"./FieldBuilder.js\";\nimport { FieldType, type IFieldTypeFactory } from \"./abstractions.js\";\nimport type { FieldTypeValidator } from \"./fieldTypeValidator.js\";\n\nexport enum TextFieldSubTypes {\n COMPRESSED = \"compressed\",\n ENCRYPTED = \"encrypted\"\n}\n\nexport enum TextFieldTypes {\n TEXT = \"text\",\n COMPRESSED = \"text:compressed\",\n ENCRYPTED = \"text:encrypted\"\n}\n\nexport interface ITextFieldBuilder\n extends\n DataFieldBuilder<\"text\">,\n FieldTypeValidator.Required,\n FieldTypeValidator.MinLength,\n FieldTypeValidator.MaxLength,\n FieldTypeValidator.Pattern,\n FieldTypeValidator.Email,\n FieldTypeValidator.Url,\n FieldTypeValidator.LowerCase,\n FieldTypeValidator.UpperCase,\n FieldTypeValidator.LowerCaseSpace,\n FieldTypeValidator.UpperCaseSpace,\n FieldTypeValidator.Unique {\n compress(): this;\n encrypt(): this;\n}\n\n// Module augmentation for TypeScript autocomplete\ndeclare module \"../abstractions.js\" {\n interface IFieldBuilderRegistry {\n text(): ITextFieldBuilder;\n }\n}\n\nclass TextFieldBuilder extends DataFieldBuilder<\"text\"> implements ITextFieldBuilder {\n public constructor() {\n super(\"text\");\n }\n\n required(message?: string): this {\n return this.validation({\n name: \"required\",\n message: message || \"Value is required.\",\n settings: {}\n });\n }\n\n minLength(value: number, message?: string): this {\n return this.validation({\n name: \"minLength\",\n message: message || \"Value is too short.\",\n settings: { value: String(value) }\n });\n }\n\n maxLength(value: number, message?: string): this {\n return this.validation({\n name: \"maxLength\",\n message: message || \"Value is too long.\",\n settings: { value: String(value) }\n });\n }\n\n pattern(regex: string, flags: string = \"\", message?: string): this {\n return this.validation({\n name: \"pattern\",\n message: message || \"Invalid value.\",\n settings: {\n preset: \"custom\",\n regex,\n flags\n }\n });\n }\n\n email(message?: string): this {\n return this.validation({\n name: \"pattern\",\n message: message || \"Please enter a valid e-mail.\",\n settings: {\n preset: \"email\",\n regex: null,\n flags: null\n }\n });\n }\n\n url(message?: string): this {\n return this.validation({\n name: \"pattern\",\n message: message || \"Please enter a valid URL.\",\n settings: {\n preset: \"url\",\n regex: null,\n flags: null\n }\n });\n }\n\n lowerCase(message?: string): this {\n return this.validation({\n name: \"pattern\",\n message: message || \"Only lower case characters are allowed.\",\n settings: {\n preset: \"lowerCase\",\n regex: null,\n flags: null\n }\n });\n }\n\n upperCase(message?: string): this {\n return this.validation({\n name: \"pattern\",\n message: message || \"Only upper case characters are allowed.\",\n settings: {\n preset: \"upperCase\",\n regex: null,\n flags: null\n }\n });\n }\n\n lowerCaseSpace(message?: string): this {\n return this.validation({\n name: \"pattern\",\n message: message || \"Only lower case characters and space are allowed.\",\n settings: {\n preset: \"lowerCaseSpace\",\n regex: null,\n flags: null\n }\n });\n }\n\n upperCaseSpace(message?: string): this {\n return this.validation({\n name: \"pattern\",\n message: message || \"Only upper case characters and space are allowed.\",\n settings: {\n preset: \"upperCaseSpace\",\n regex: null,\n flags: null\n }\n });\n }\n\n unique(message?: string): this {\n return this.validation({\n name: \"unique\",\n message: message || \"Value must be unique.\",\n settings: {}\n });\n }\n\n public compress(): this {\n this.setSubType(TextFieldSubTypes.COMPRESSED);\n\n this.settings({\n disableFullTextSearch: true\n });\n\n return this;\n }\n public encrypt(): this {\n this.setSubType(TextFieldSubTypes.ENCRYPTED);\n\n this.settings({\n disableFullTextSearch: true\n });\n\n return this;\n }\n}\n\nclass TextFieldTypeFactory implements IFieldTypeFactory {\n readonly type = \"text\";\n\n create(): ITextFieldBuilder {\n return new TextFieldBuilder();\n }\n}\n\nexport const TextFieldType = createImplementation({\n abstraction: FieldType,\n implementation: TextFieldTypeFactory,\n dependencies: []\n});\n"],"names":["TextFieldSubTypes","TextFieldTypes","TextFieldBuilder","DataFieldBuilder","message","value","String","regex","flags","TextFieldTypeFactory","TextFieldType","createImplementation","FieldType"],"mappings":";;;AAKO,IAAKA,kCAAiBA,WAAAA,GAAAA,SAAAA,iBAAAA;;;;;AAKtB,IAAKC,+BAAcA,WAAAA,GAAAA,SAAAA,cAAAA;;;;;;AA+B1B,MAAMC,yBAAyBC;IAC3B,aAAqB;QACjB,KAAK,CAAC;IACV;IAEA,SAASC,OAAgB,EAAQ;QAC7B,OAAO,IAAI,CAAC,UAAU,CAAC;YACnB,MAAM;YACN,SAASA,WAAW;YACpB,UAAU,CAAC;QACf;IACJ;IAEA,UAAUC,KAAa,EAAED,OAAgB,EAAQ;QAC7C,OAAO,IAAI,CAAC,UAAU,CAAC;YACnB,MAAM;YACN,SAASA,WAAW;YACpB,UAAU;gBAAE,OAAOE,OAAOD;YAAO;QACrC;IACJ;IAEA,UAAUA,KAAa,EAAED,OAAgB,EAAQ;QAC7C,OAAO,IAAI,CAAC,UAAU,CAAC;YACnB,MAAM;YACN,SAASA,WAAW;YACpB,UAAU;gBAAE,OAAOE,OAAOD;YAAO;QACrC;IACJ;IAEA,QAAQE,KAAa,EAAEC,QAAgB,EAAE,EAAEJ,OAAgB,EAAQ;QAC/D,OAAO,IAAI,CAAC,UAAU,CAAC;YACnB,MAAM;YACN,SAASA,WAAW;YACpB,UAAU;gBACN,QAAQ;gBACRG;gBACAC;YACJ;QACJ;IACJ;IAEA,MAAMJ,OAAgB,EAAQ;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC;YACnB,MAAM;YACN,SAASA,WAAW;YACpB,UAAU;gBACN,QAAQ;gBACR,OAAO;gBACP,OAAO;YACX;QACJ;IACJ;IAEA,IAAIA,OAAgB,EAAQ;QACxB,OAAO,IAAI,CAAC,UAAU,CAAC;YACnB,M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