@webiny/api-aco 6.4.11 → 6.6.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/AcoFeature.d.ts +5 -0
  2. package/AcoFeature.js +129 -0
  3. package/AcoFeature.js.map +1 -0
  4. package/AcoFolderSchemaFactory.d.ts +30 -0
  5. package/AcoFolderSchemaFactory.js +64 -0
  6. package/AcoFolderSchemaFactory.js.map +1 -0
  7. package/createAcoGraphQL.d.ts +8 -4
  8. package/createAcoGraphQL.js +56 -96
  9. package/createAcoGraphQL.js.map +1 -1
  10. package/domain/folder/abstractions.d.ts +12 -5
  11. package/domain/folder/abstractions.js +2 -2
  12. package/domain/folder/abstractions.js.map +1 -1
  13. package/exports/api/aco/folder.d.ts +1 -1
  14. package/exports/api/aco/folder.js +1 -1
  15. package/features/ai/CreateFolderTool.d.ts +44 -0
  16. package/features/ai/CreateFolderTool.js +49 -0
  17. package/features/ai/CreateFolderTool.js.map +1 -0
  18. package/features/ai/CreateTeamTool.d.ts +43 -0
  19. package/features/ai/CreateTeamTool.js +47 -0
  20. package/features/ai/CreateTeamTool.js.map +1 -0
  21. package/features/ai/GrantFolderAccessTool.d.ts +72 -0
  22. package/features/ai/GrantFolderAccessTool.js +71 -0
  23. package/features/ai/GrantFolderAccessTool.js.map +1 -0
  24. package/features/ai/ListFoldersTool.d.ts +42 -0
  25. package/features/ai/ListFoldersTool.js +48 -0
  26. package/features/ai/ListFoldersTool.js.map +1 -0
  27. package/features/ai/ListRolesTool.d.ts +34 -0
  28. package/features/ai/ListRolesTool.js +39 -0
  29. package/features/ai/ListRolesTool.js.map +1 -0
  30. package/features/ai/ListTeamsTool.d.ts +34 -0
  31. package/features/ai/ListTeamsTool.js +39 -0
  32. package/features/ai/ListTeamsTool.js.map +1 -0
  33. package/features/ai/RevokeFolderAccessTool.d.ts +58 -0
  34. package/features/ai/RevokeFolderAccessTool.js +60 -0
  35. package/features/ai/RevokeFolderAccessTool.js.map +1 -0
  36. package/features/ai/assertTargetIsUsable.d.ts +10 -0
  37. package/features/ai/assertTargetIsUsable.js +14 -0
  38. package/features/ai/assertTargetIsUsable.js.map +1 -0
  39. package/features/ai/feature.d.ts +12 -0
  40. package/features/ai/feature.js +23 -0
  41. package/features/ai/feature.js.map +1 -0
  42. package/features/ai/index.d.ts +8 -0
  43. package/features/ai/index.js +8 -0
  44. package/features/ai/loadFolderPermissions.d.ts +16 -0
  45. package/features/ai/loadFolderPermissions.js +14 -0
  46. package/features/ai/loadFolderPermissions.js.map +1 -0
  47. package/features/cms/decorators/MoveEntryWithFlpDecorator.d.ts +1 -1
  48. package/features/flp/CreateFlp/CreateFlpUseCase.d.ts +3 -3
  49. package/features/flp/CreateFlp/CreateFlpUseCase.js +4 -4
  50. package/features/flp/CreateFlp/CreateFlpUseCase.js.map +1 -1
  51. package/features/flp/CreateFlp/feature.d.ts +1 -6
  52. package/features/flp/CreateFlp/feature.js +3 -2
  53. package/features/flp/CreateFlp/feature.js.map +1 -1
  54. package/features/flp/DeleteFlp/DeleteFlpUseCase.d.ts +3 -3
  55. package/features/flp/DeleteFlp/DeleteFlpUseCase.js +3 -3
  56. package/features/flp/DeleteFlp/DeleteFlpUseCase.js.map +1 -1
  57. package/features/flp/DeleteFlp/feature.d.ts +1 -6
  58. package/features/flp/DeleteFlp/feature.js +3 -2
  59. package/features/flp/DeleteFlp/feature.js.map +1 -1
  60. package/features/flp/FolderLevelPermissions/FolderLevelPermissions.d.ts +3 -3
  61. package/features/flp/FolderLevelPermissions/FolderLevelPermissions.js +6 -6
  62. package/features/flp/FolderLevelPermissions/FolderLevelPermissions.js.map +1 -1
  63. package/features/flp/FolderLevelPermissions/NoopFolderLevelPermissions.d.ts +25 -0
  64. package/features/flp/FolderLevelPermissions/NoopFolderLevelPermissions.js +48 -0
  65. package/features/flp/FolderLevelPermissions/NoopFolderLevelPermissions.js.map +1 -0
  66. package/features/flp/FolderLevelPermissions/index.d.ts +1 -0
  67. package/features/flp/FolderLevelPermissions/index.js +1 -0
  68. package/features/flp/GetFlp/feature.d.ts +1 -1
  69. package/features/flp/GetFlp/feature.js +3 -2
  70. package/features/flp/GetFlp/feature.js.map +1 -1
  71. package/features/flp/ListFlps/feature.d.ts +1 -1
  72. package/features/flp/ListFlps/feature.js +3 -2
  73. package/features/flp/ListFlps/feature.js.map +1 -1
  74. package/features/flp/UpdateFlp/UpdateFlpUseCase.d.ts +11 -3
  75. package/features/flp/UpdateFlp/UpdateFlpUseCase.js +15 -13
  76. package/features/flp/UpdateFlp/UpdateFlpUseCase.js.map +1 -1
  77. package/features/flp/UpdateFlp/feature.d.ts +1 -6
  78. package/features/flp/UpdateFlp/feature.js +7 -2
  79. package/features/flp/UpdateFlp/feature.js.map +1 -1
  80. package/features/folder/CreateFolder/CreateFolderRepository.d.ts +3 -3
  81. package/features/folder/CreateFolder/CreateFolderRepository.js +10 -7
  82. package/features/folder/CreateFolder/CreateFolderRepository.js.map +1 -1
  83. package/features/folder/DeleteFolder/DeleteFolderRepository.d.ts +3 -3
  84. package/features/folder/DeleteFolder/DeleteFolderRepository.js +6 -5
  85. package/features/folder/DeleteFolder/DeleteFolderRepository.js.map +1 -1
  86. package/features/folder/DeleteFolder/decorators/DeleteFolderWithFolderLevelPermissions.d.ts +1 -1
  87. package/features/folder/EnsureFolderIsEmpty/EnsureFolderIsEmpty.d.ts +1 -3
  88. package/features/folder/EnsureFolderIsEmpty/EnsureFolderIsEmpty.js +4 -7
  89. package/features/folder/EnsureFolderIsEmpty/EnsureFolderIsEmpty.js.map +1 -1
  90. package/features/folder/EnsureHcmsFolderIsEmptyOnDelete/ModelFolderBeforeDeleteHandler.js +4 -1
  91. package/features/folder/EnsureHcmsFolderIsEmptyOnDelete/ModelFolderBeforeDeleteHandler.js.map +1 -1
  92. package/features/folder/FolderModelProvider.d.ts +26 -0
  93. package/features/folder/FolderModelProvider.js +22 -0
  94. package/features/folder/FolderModelProvider.js.map +1 -0
  95. package/features/folder/GetAncestors/GetAncestorsRepository.d.ts +3 -3
  96. package/features/folder/GetAncestors/GetAncestorsRepository.js +6 -5
  97. package/features/folder/GetAncestors/GetAncestorsRepository.js.map +1 -1
  98. package/features/folder/GetFolder/GetFolderRepository.d.ts +3 -3
  99. package/features/folder/GetFolder/GetFolderRepository.js +6 -5
  100. package/features/folder/GetFolder/GetFolderRepository.js.map +1 -1
  101. package/features/folder/GetFolder/decorators/GetFolderWithFolderLevelPermissions.d.ts +8 -8
  102. package/features/folder/GetFolderHierarchy/GetFolderHierarchyRepository.d.ts +3 -3
  103. package/features/folder/GetFolderHierarchy/GetFolderHierarchyRepository.js +10 -8
  104. package/features/folder/GetFolderHierarchy/GetFolderHierarchyRepository.js.map +1 -1
  105. package/features/folder/ListFolders/ListFoldersRepository.d.ts +3 -3
  106. package/features/folder/ListFolders/ListFoldersRepository.js +8 -7
  107. package/features/folder/ListFolders/ListFoldersRepository.js.map +1 -1
  108. package/features/folder/UpdateFolder/UpdateFolderRepository.d.ts +3 -3
  109. package/features/folder/UpdateFolder/UpdateFolderRepository.js +11 -8
  110. package/features/folder/UpdateFolder/UpdateFolderRepository.js.map +1 -1
  111. package/features/folder/shared/abstractions.d.ts +14 -0
  112. package/features/folder/shared/abstractions.js +4 -1
  113. package/features/folder/shared/abstractions.js.map +1 -1
  114. package/filter/filter.gql.d.ts +2 -3
  115. package/filter/filter.gql.js +61 -27
  116. package/filter/filter.gql.js.map +1 -1
  117. package/filter/filter.so.d.ts +10 -2
  118. package/filter/filter.so.js +2 -2
  119. package/filter/filter.so.js.map +1 -1
  120. package/flp/index.d.ts +0 -1
  121. package/flp/index.js +0 -1
  122. package/flp/tasks/createFlp.task.d.ts +2 -2
  123. package/flp/tasks/deleteFlp.task.d.ts +2 -2
  124. package/flp/tasks/index.d.ts +0 -1
  125. package/flp/tasks/index.js +1 -14
  126. package/flp/tasks/index.js.map +1 -1
  127. package/flp/tasks/syncFlp.task.d.ts +2 -2
  128. package/flp/tasks/syncFlp.task.js +7 -1
  129. package/flp/tasks/syncFlp.task.js.map +1 -1
  130. package/flp/tasks/updateFlp.task.d.ts +2 -2
  131. package/folder/folder.gql.d.ts +1 -1
  132. package/folder/folder.gql.js +10 -4
  133. package/folder/folder.gql.js.map +1 -1
  134. package/index.d.ts +1 -6
  135. package/index.js +1 -11
  136. package/package.json +24 -25
  137. package/utils/createOperationsWrapper.d.ts +5 -2
  138. package/utils/createOperationsWrapper.js +2 -2
  139. package/utils/createOperationsWrapper.js.map +1 -1
  140. package/utils/decorators/CmsEntriesCrudDecorators.js +9 -5
  141. package/utils/decorators/CmsEntriesCrudDecorators.js.map +1 -1
  142. package/utils/resolve.d.ts +2 -2
  143. package/utils/resolve.js +1 -1
  144. package/utils/resolve.js.map +1 -1
  145. package/createAcoContext.d.ts +0 -9
  146. package/createAcoContext.js +0 -108
  147. package/createAcoContext.js.map +0 -1
  148. package/createAcoStorageOperations.d.ts +0 -12
  149. package/createAcoStorageOperations.js +0 -9
  150. package/createAcoStorageOperations.js.map +0 -1
  151. package/createAcoTasks.d.ts +0 -1
  152. package/createAcoTasks.js +0 -14
  153. package/createAcoTasks.js.map +0 -1
  154. package/flp/flp.so.d.ts +0 -20
  155. package/flp/flp.so.js +0 -183
  156. package/flp/flp.so.js.map +0 -1
  157. package/index.js.map +0 -1
@@ -0,0 +1,48 @@
1
+ import { FolderLevelPermissions } from "./abstractions.js";
2
+ class NoopFolderLevelPermissionsImpl {
3
+ canUseFolderLevelPermissions() {
4
+ return false;
5
+ }
6
+ canUseTeams() {
7
+ return false;
8
+ }
9
+ canCreateFolderInRoot() {
10
+ return true;
11
+ }
12
+ permissionsIncludeNonInheritedPermissions() {
13
+ return false;
14
+ }
15
+ async canAccessFolder() {
16
+ return true;
17
+ }
18
+ async canAccessFolderContent() {
19
+ return true;
20
+ }
21
+ async ensureCanAccessFolder() {}
22
+ async ensureCanAccessFolderContent() {}
23
+ async canManageFolderContent() {
24
+ return true;
25
+ }
26
+ async canManageFolderStructure() {
27
+ return true;
28
+ }
29
+ async canManageFolderPermissions() {
30
+ return true;
31
+ }
32
+ async getDefaultPermissions(permissions) {
33
+ return permissions;
34
+ }
35
+ async listFolderLevelPermissions() {
36
+ return [];
37
+ }
38
+ async getFolderLevelPermissions() {
39
+ return [];
40
+ }
41
+ }
42
+ const NoopFolderLevelPermissions = FolderLevelPermissions.createImplementation({
43
+ implementation: NoopFolderLevelPermissionsImpl,
44
+ dependencies: []
45
+ });
46
+ export { NoopFolderLevelPermissions };
47
+
48
+ //# sourceMappingURL=NoopFolderLevelPermissions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/flp/FolderLevelPermissions/NoopFolderLevelPermissions.js","sources":["../../../../src/features/flp/FolderLevelPermissions/NoopFolderLevelPermissions.ts"],"sourcesContent":["import { FolderLevelPermissions, type IFolderLevelPermissions } from \"./abstractions.js\";\nimport type { FolderPermission } from \"~/types.js\";\n\nclass NoopFolderLevelPermissionsImpl implements IFolderLevelPermissions {\n canUseFolderLevelPermissions(): boolean {\n return false;\n }\n\n canUseTeams(): boolean {\n return false;\n }\n\n canCreateFolderInRoot(): boolean {\n return true;\n }\n\n permissionsIncludeNonInheritedPermissions(): boolean {\n return false;\n }\n\n async canAccessFolder(): Promise<boolean> {\n return true;\n }\n\n async canAccessFolderContent(): Promise<boolean> {\n return true;\n }\n\n async ensureCanAccessFolder(): Promise<void> {\n return;\n }\n\n async ensureCanAccessFolderContent(): Promise<void> {\n return;\n }\n\n async canManageFolderContent(): Promise<boolean> {\n return true;\n }\n\n async canManageFolderStructure(): Promise<boolean> {\n return true;\n }\n\n async canManageFolderPermissions(): Promise<boolean> {\n return true;\n }\n\n async getDefaultPermissions(permissions: FolderPermission[]): Promise<FolderPermission[]> {\n return permissions;\n }\n\n async listFolderLevelPermissions(): Promise<\n Array<{ id: string; permissions: FolderPermission[] }>\n > {\n return [];\n }\n\n async getFolderLevelPermissions(): Promise<FolderPermission[]> {\n return [];\n }\n}\n\nexport const NoopFolderLevelPermissions = FolderLevelPermissions.createImplementation({\n implementation: NoopFolderLevelPermissionsImpl,\n dependencies: []\n});\n"],"names":["NoopFolderLevelPermissionsImpl","permissions","NoopFolderLevelPermissions","FolderLevelPermissions"],"mappings":";AAGA,MAAMA;IACF,+BAAwC;QACpC,OAAO;IACX;IAEA,cAAuB;QACnB,OAAO;IACX;IAEA,wBAAiC;QAC7B,OAAO;IACX;IAEA,4CAAqD;QACjD,OAAO;IACX;IAEA,MAAM,kBAAoC;QACtC,OAAO;IACX;IAEA,MAAM,yBAA2C;QAC7C,OAAO;IACX;IAEA,MAAM,wBAAuC,CAE7C;IAEA,MAAM,+BAA8C,CAEpD;IAEA,MAAM,yBAA2C;QAC7C,OAAO;IACX;IAEA,MAAM,2BAA6C;QAC/C,OAAO;IACX;IAEA,MAAM,6BAA+C;QACjD,OAAO;IACX;IAEA,MAAM,sBAAsBC,WAA+B,EAA+B;QACtF,OAAOA;IACX;IAEA,MAAM,6BAEJ;QACE,OAAO,EAAE;IACb;IAEA,MAAM,4BAAyD;QAC3D,OAAO,EAAE;IACb;AACJ;AAEO,MAAMC,6BAA6BC,uBAAuB,oBAAoB,CAAC;IAClF,gBAAgBH;IAChB,cAAc,EAAE;AACpB"}
@@ -1,2 +1,3 @@
1
1
  export { FolderLevelPermissionsFeature } from "./feature.js";
2
2
  export { FolderLevelPermissions } from "./abstractions.js";
3
+ export { NoopFolderLevelPermissions } from "./NoopFolderLevelPermissions.js";
@@ -1,2 +1,3 @@
1
1
  export { FolderLevelPermissionsFeature } from "./feature.js";
2
2
  export { FolderLevelPermissions } from "./abstractions.js";
3
+ export { NoopFolderLevelPermissions } from "./NoopFolderLevelPermissions.js";
@@ -1,4 +1,4 @@
1
1
  export declare const GetFlpFeature: {
2
2
  name: string;
3
- register(container: import("@webiny/di").Container, context: import("~/types.js").AcoFolderLevelPermissionsCrud): void;
3
+ register(container: import("@webiny/di").Container): void;
4
4
  };
@@ -1,10 +1,11 @@
1
1
  import { createFeature } from "@webiny/feature/api";
2
2
  import { GetFlpUseCase } from "./GetFlpUseCase.js";
3
3
  import { GetFlpUseCase as external_abstractions_js_GetFlpUseCase } from "./abstractions.js";
4
+ import { AcoFlpCrud } from "../../folder/shared/abstractions.js";
4
5
  const GetFlpFeature = createFeature({
5
6
  name: "GetFlpFeature",
6
- register (container, context) {
7
- container.registerFactory(external_abstractions_js_GetFlpUseCase, ()=>new GetFlpUseCase(context.get));
7
+ register (container) {
8
+ container.registerFactory(external_abstractions_js_GetFlpUseCase, ()=>new GetFlpUseCase(container.resolve(AcoFlpCrud).get));
8
9
  }
9
10
  });
10
11
  export { GetFlpFeature };
@@ -1 +1 @@
1
- {"version":3,"file":"features/flp/GetFlp/feature.js","sources":["../../../../src/features/flp/GetFlp/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { GetFlpUseCase } from \"./GetFlpUseCase.js\";\nimport { GetFlpUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport type { AcoContext } from \"~/types.js\";\n\nexport const GetFlpFeature = createFeature<AcoContext[\"aco\"][\"flp\"]>({\n name: \"GetFlpFeature\",\n register(container, context) {\n container.registerFactory(UseCaseAbstraction, () => {\n return new GetFlpUseCase(context.get);\n });\n }\n});\n"],"names":["GetFlpFeature","createFeature","container","context","UseCaseAbstraction","GetFlpUseCase"],"mappings":";;;AAKO,MAAMA,gBAAgBC,cAAwC;IACjE,MAAM;IACN,UAASC,SAAS,EAAEC,OAAO;QACvBD,UAAU,eAAe,CAACE,wCAAoB,IACnC,IAAIC,cAAcF,QAAQ,GAAG;IAE5C;AACJ"}
1
+ {"version":3,"file":"features/flp/GetFlp/feature.js","sources":["../../../../src/features/flp/GetFlp/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { GetFlpUseCase } from \"./GetFlpUseCase.js\";\nimport { GetFlpUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { AcoFlpCrud } from \"~/features/folder/shared/abstractions.js\";\n\nexport const GetFlpFeature = createFeature({\n name: \"GetFlpFeature\",\n register(container) {\n container.registerFactory(UseCaseAbstraction, () => {\n return new GetFlpUseCase(container.resolve(AcoFlpCrud).get);\n });\n }\n});\n"],"names":["GetFlpFeature","createFeature","container","UseCaseAbstraction","GetFlpUseCase","AcoFlpCrud"],"mappings":";;;;AAKO,MAAMA,gBAAgBC,cAAc;IACvC,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,eAAe,CAACC,wCAAoB,IACnC,IAAIC,cAAcF,UAAU,OAAO,CAACG,YAAY,GAAG;IAElE;AACJ"}
@@ -1,4 +1,4 @@
1
1
  export declare const ListFlpsFeature: {
2
2
  name: string;
3
- register(container: import("@webiny/di").Container, context: import("~/types.js").AcoFolderLevelPermissionsCrud): void;
3
+ register(container: import("@webiny/di").Container): void;
4
4
  };
@@ -1,10 +1,11 @@
1
1
  import { createFeature } from "@webiny/feature/api";
2
2
  import { ListFlpsUseCase } from "./ListFlpsUseCase.js";
3
3
  import { ListFlpsUseCase as external_abstractions_js_ListFlpsUseCase } from "./abstractions.js";
4
+ import { AcoFlpCrud } from "../../folder/shared/abstractions.js";
4
5
  const ListFlpsFeature = createFeature({
5
6
  name: "ListFlpsFeature",
6
- register (container, context) {
7
- container.registerFactory(external_abstractions_js_ListFlpsUseCase, ()=>new ListFlpsUseCase(context.list));
7
+ register (container) {
8
+ container.registerFactory(external_abstractions_js_ListFlpsUseCase, ()=>new ListFlpsUseCase(container.resolve(AcoFlpCrud).list));
8
9
  }
9
10
  });
10
11
  export { ListFlpsFeature };
@@ -1 +1 @@
1
- {"version":3,"file":"features/flp/ListFlps/feature.js","sources":["../../../../src/features/flp/ListFlps/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { ListFlpsUseCase } from \"./ListFlpsUseCase.js\";\nimport { ListFlpsUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport type { AcoContext } from \"~/types.js\";\n\nexport const ListFlpsFeature = createFeature<AcoContext[\"aco\"][\"flp\"]>({\n name: \"ListFlpsFeature\",\n register(container, context) {\n container.registerFactory(UseCaseAbstraction, () => {\n return new ListFlpsUseCase(context.list);\n });\n }\n});\n"],"names":["ListFlpsFeature","createFeature","container","context","UseCaseAbstraction","ListFlpsUseCase"],"mappings":";;;AAKO,MAAMA,kBAAkBC,cAAwC;IACnE,MAAM;IACN,UAASC,SAAS,EAAEC,OAAO;QACvBD,UAAU,eAAe,CAACE,0CAAoB,IACnC,IAAIC,gBAAgBF,QAAQ,IAAI;IAE/C;AACJ"}
1
+ {"version":3,"file":"features/flp/ListFlps/feature.js","sources":["../../../../src/features/flp/ListFlps/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { ListFlpsUseCase } from \"./ListFlpsUseCase.js\";\nimport { ListFlpsUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { AcoFlpCrud } from \"~/features/folder/shared/abstractions.js\";\n\nexport const ListFlpsFeature = createFeature({\n name: \"ListFlpsFeature\",\n register(container) {\n container.registerFactory(UseCaseAbstraction, () => {\n return new ListFlpsUseCase(container.resolve(AcoFlpCrud).list);\n });\n }\n});\n"],"names":["ListFlpsFeature","createFeature","container","UseCaseAbstraction","ListFlpsUseCase","AcoFlpCrud"],"mappings":";;;;AAKO,MAAMA,kBAAkBC,cAAc;IACzC,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,eAAe,CAACC,0CAAoB,IACnC,IAAIC,gBAAgBF,UAAU,OAAO,CAACG,YAAY,IAAI;IAErE;AACJ"}
@@ -1,12 +1,20 @@
1
1
  import type { UpdateFlpParams, UpdateFlpUseCase as UseCaseAbstraction } from "./abstractions.js";
2
- import type { AcoContext } from "../../../types.js";
2
+ import type { AcoFlpCrud } from "../../../features/folder/shared/abstractions.js";
3
+ import type { ListFoldersUseCase } from "../../../features/folder/ListFolders/index.js";
4
+ import type { FolderModelProvider } from "../../../domain/folder/abstractions.js";
5
+ import type { UpdateEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/UpdateEntry/index.js";
6
+ import type { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/abstractions.js";
3
7
  export declare class UpdateFlpUseCase implements UseCaseAbstraction.Interface {
4
- private context;
8
+ private flpCrud;
9
+ private listFoldersUseCase;
10
+ private folderModelProvider;
11
+ private updateEntryUseCase;
12
+ private identityContext;
5
13
  private isCloseToTimeout?;
6
14
  private handleTimeout?;
7
15
  private readonly queued;
8
16
  private readonly flpsToUpdate;
9
- constructor(context: AcoContext);
17
+ constructor(flpCrud: AcoFlpCrud.Interface, listFoldersUseCase: ListFoldersUseCase.Interface, folderModelProvider: FolderModelProvider.Interface, updateEntryUseCase: UpdateEntryUseCase.Interface, identityContext: IdentityContext.Interface);
10
18
  execute(params: UpdateFlpParams): Promise<void>;
11
19
  private collectBranchForUpdate;
12
20
  private executeBatchUpdate;
@@ -1,14 +1,16 @@
1
1
  import { WebinyError } from "@webiny/error";
2
2
  import { Path } from "../../../utils/Path.js";
3
3
  import { Permissions, ROOT_FOLDER } from "@webiny/shared-aco";
4
- import { ListFoldersUseCase } from "../../folder/ListFolders/index.js";
5
- import { FolderModel } from "../../../domain/folder/abstractions.js";
6
4
  import { EntryId } from "@webiny/api-headless-cms/exports/api/cms/entry.js";
7
5
  class UpdateFlpUseCase {
8
- constructor(context){
6
+ constructor(flpCrud, listFoldersUseCase, folderModelProvider, updateEntryUseCase, identityContext){
7
+ this.flpCrud = flpCrud;
8
+ this.listFoldersUseCase = listFoldersUseCase;
9
+ this.folderModelProvider = folderModelProvider;
10
+ this.updateEntryUseCase = updateEntryUseCase;
11
+ this.identityContext = identityContext;
9
12
  this.queued = new Set();
10
13
  this.flpsToUpdate = new Map();
11
- this.context = context;
12
14
  }
13
15
  async execute(params) {
14
16
  this.isCloseToTimeout = params.isCloseToTimeout;
@@ -20,7 +22,7 @@ class UpdateFlpUseCase {
20
22
  folder
21
23
  });
22
24
  const flp = await this.getFlp(folder);
23
- const parentFlp = folder.parentId ? await this.context.aco.flp.get(folder.parentId) : null;
25
+ const parentFlp = folder.parentId ? await this.flpCrud.get(folder.parentId) : null;
24
26
  this.flpsToUpdate.set(folder.id, {
25
27
  slug: folder.slug,
26
28
  parentId: folder.parentId ?? ROOT_FOLDER,
@@ -74,6 +76,7 @@ class UpdateFlpUseCase {
74
76
  }
75
77
  }
76
78
  async executeBatchUpdate() {
79
+ const folderModel = await this.folderModelProvider.get();
77
80
  try {
78
81
  const items = Array.from(this.flpsToUpdate.entries()).map(([id, { slug, parentId, path, permissions }])=>({
79
82
  id,
@@ -84,16 +87,16 @@ class UpdateFlpUseCase {
84
87
  permissions
85
88
  }
86
89
  }));
87
- await this.context.aco.flp.batchUpdate(items);
88
- const folderModel = this.context.container.resolve(FolderModel);
90
+ await this.flpCrud.batchUpdate(items);
89
91
  for (const item of items){
90
92
  const { id, data } = item;
91
93
  const entryId = EntryId.from(id);
92
- await this.context.cms.updateEntry(folderModel, entryId.toString(), {
94
+ const updateResult = await this.updateEntryUseCase.execute(folderModel, entryId.toString(), {
93
95
  values: {
94
96
  path: data.path
95
97
  }
96
98
  });
99
+ if (updateResult.isFail()) throw updateResult.error;
97
100
  }
98
101
  } catch (error) {
99
102
  throw WebinyError.from(error, {
@@ -121,8 +124,7 @@ class UpdateFlpUseCase {
121
124
  this.queued.clear();
122
125
  }
123
126
  async listDirectChildren(flp) {
124
- const listFolders = this.context.container.resolve(ListFoldersUseCase);
125
- const result = await this.context.security.withoutAuthorization(()=>listFolders.execute({
127
+ const result = await this.identityContext.withoutAuthorization(()=>this.listFoldersUseCase.execute({
126
128
  where: {
127
129
  type: flp.type,
128
130
  parentId: flp.id
@@ -132,10 +134,10 @@ class UpdateFlpUseCase {
132
134
  return await Promise.all(result.value.folders.map((folder)=>this.getFlp(folder)));
133
135
  }
134
136
  async getFlp({ id, type, parentId, slug, permissions }) {
135
- const flp = await this.context.aco.flp.get(id);
137
+ const flp = await this.flpCrud.get(id);
136
138
  if (!flp) {
137
- const parentFlp = parentId ? await this.context.aco.flp.get(parentId) : null;
138
- return await this.context.aco.flp.create({
139
+ const parentFlp = parentId ? await this.flpCrud.get(parentId) : null;
140
+ return await this.flpCrud.create({
139
141
  id,
140
142
  type,
141
143
  slug,
@@ -1 +1 @@
1
- {"version":3,"file":"features/flp/UpdateFlp/UpdateFlpUseCase.js","sources":["../../../../src/features/flp/UpdateFlp/UpdateFlpUseCase.ts"],"sourcesContent":["import { WebinyError } from \"@webiny/error\";\nimport { Path } from \"~/utils/Path.js\";\nimport { Permissions, ROOT_FOLDER } from \"@webiny/shared-aco\";\nimport type { UpdateFlpParams, UpdateFlpUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport type { AcoContext, Folder, FolderLevelPermission, FolderPermission } from \"~/types.js\";\nimport { ListFoldersUseCase } from \"~/features/folder/ListFolders/index.js\";\nimport { FolderModel } from \"~/domain/folder/abstractions.js\";\nimport { EntryId } from \"@webiny/api-headless-cms/exports/api/cms/entry.js\";\n\ninterface FlpUpdateData {\n parentId: string;\n slug: string;\n path: string;\n permissions: FolderPermission[];\n}\n\nexport class UpdateFlpUseCase implements UseCaseAbstraction.Interface {\n private context: AcoContext;\n private isCloseToTimeout?: () => boolean;\n private handleTimeout?: (updated: string[]) => void;\n\n private readonly queued: Set<string> = new Set();\n private readonly flpsToUpdate: Map<string, FlpUpdateData> = new Map();\n\n constructor(context: AcoContext) {\n this.context = context;\n }\n\n async execute(params: UpdateFlpParams): Promise<void> {\n this.isCloseToTimeout = params.isCloseToTimeout;\n this.handleTimeout = params.handleTimeout;\n\n if (params.queued) {\n params.queued.forEach(id => this.queued.add(id));\n }\n\n try {\n const { folder } = params;\n\n if (!folder) {\n throw new WebinyError(\n \"Missing `folder`, I can't update the FLP record.\",\n \"ERROR_UPDATING_FLP_USE_CASE_FOLDER_NOT_PROVIDED\",\n { folder }\n );\n }\n\n const flp = await this.getFlp(folder);\n const parentFlp = folder.parentId\n ? await this.context.aco.flp.get(folder.parentId)\n : null;\n\n // Add the root folder to the update collection\n this.flpsToUpdate.set(folder.id, {\n slug: folder.slug,\n parentId: folder.parentId ?? ROOT_FOLDER,\n path: Path.create(folder.slug, parentFlp?.path),\n permissions: Permissions.create(folder.permissions, parentFlp)\n });\n\n // Let's set the FLP as in queue\n this.setQueued(flp.id);\n\n // Get direct children and process each branch completely\n const directChildren = await this.listDirectChildren(flp);\n\n for (const child of directChildren) {\n if (this.isCloseToTimeout?.()) {\n await this.executeBatchUpdate();\n this.handleTimeout?.(this.getQueuedList());\n return;\n }\n await this.collectBranchForUpdate(child, flp);\n }\n\n // Execute batch update\n await this.executeBatchUpdate();\n } catch (error) {\n // Clear the update collection in case of error\n this.flpsToUpdate.clear();\n this.queued.clear();\n throw WebinyError.from(error, {\n message: \"Error while updating FLP\",\n code: \"ERROR_UPDATING_FLP_USE_CASE\"\n });\n }\n }\n\n private async collectBranchForUpdate(\n flp: FolderLevelPermission,\n parentFlp: FolderLevelPermission\n ): Promise<void> {\n if (this.isQueued(flp.id)) {\n return;\n }\n\n // Get the parent's permissions from the update collection if available\n const parentFlpData = this.flpsToUpdate.get(parentFlp.id);\n const currentParentFlp = {\n ...parentFlp,\n ...(parentFlpData && { ...parentFlpData })\n };\n\n // Add the FLP to the update collection with inherited permissions\n this.flpsToUpdate.set(flp.id, {\n slug: flp.slug,\n parentId: flp.parentId,\n path: Path.create(flp.slug, currentParentFlp.path),\n permissions: Permissions.create(flp.permissions, currentParentFlp)\n });\n\n // Add the FLP to the queue list so we don't fetch it again\n this.setQueued(flp.id);\n\n // Process all children of this folder before moving to siblings\n const children = await this.listDirectChildren(flp);\n\n for (const child of children) {\n if (this.isCloseToTimeout?.()) {\n await this.executeBatchUpdate();\n this.handleTimeout?.(this.getQueuedList());\n return;\n }\n // Pass the current FLP as the parent for the child\n await this.collectBranchForUpdate(child, flp);\n }\n }\n\n private async executeBatchUpdate(): Promise<void> {\n try {\n const items = Array.from(this.flpsToUpdate.entries()).map(\n ([id, { slug, parentId, path, permissions }]) => {\n return {\n id,\n data: {\n slug,\n parentId,\n path,\n permissions\n }\n };\n }\n );\n\n await this.context.aco.flp.batchUpdate(items);\n\n // Update all folders with the new path\n const folderModel = this.context.container.resolve(FolderModel);\n for (const item of items) {\n const { id, data } = item;\n // Directly update the folder in CMS storage to bypass any folder update event triggers.\n const entryId = EntryId.from(id);\n await this.context.cms.updateEntry(folderModel, entryId.toString(), {\n values: {\n path: data.path\n }\n });\n }\n } catch (error) {\n throw WebinyError.from(error, {\n message: \"Error while executing batch update of FLPs\",\n code: \"BATCH_UPDATE_FLP_ERROR\",\n data: {\n items: Array.from(this.flpsToUpdate.keys())\n }\n });\n } finally {\n // Clear the update collection after the batch update\n this.flpsToUpdate.clear();\n\n //Let's remove all the updated FLPs ids from the queue cache\n this.clearQueuedList();\n }\n }\n\n private getQueuedList(): string[] {\n return Array.from(this.queued);\n }\n\n private setQueued(id: string): void {\n this.queued.add(id);\n }\n\n private isQueued(id: string): boolean {\n return this.queued.has(id);\n }\n\n private clearQueuedList(): void {\n this.queued.clear();\n }\n\n private async listDirectChildren(flp: FolderLevelPermission): Promise<FolderLevelPermission[]> {\n const listFolders = this.context.container.resolve(ListFoldersUseCase);\n\n const result = await this.context.security.withoutAuthorization(() => {\n return listFolders.execute({\n where: {\n type: flp.type,\n parentId: flp.id\n }\n });\n });\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return await Promise.all(result.value.folders.map(folder => this.getFlp(folder)));\n }\n\n private async getFlp({\n id,\n type,\n parentId,\n slug,\n permissions\n }: Folder): Promise<FolderLevelPermission> {\n const flp = await this.context.aco.flp.get(id);\n\n if (!flp) {\n const parentFlp = parentId ? await this.context.aco.flp.get(parentId) : null;\n\n return await this.context.aco.flp.create({\n id,\n type,\n slug,\n parentId: parentId ?? ROOT_FOLDER,\n path: Path.create(slug, parentFlp?.path),\n permissions: Permissions.create(permissions, parentFlp)\n });\n }\n\n return flp;\n }\n}\n"],"names":["UpdateFlpUseCase","context","Set","Map","params","id","folder","WebinyError","flp","parentFlp","ROOT_FOLDER","Path","Permissions","directChildren","child","error","parentFlpData","currentParentFlp","children","items","Array","slug","parentId","path","permissions","folderModel","FolderModel","item","data","entryId","EntryId","listFolders","ListFoldersUseCase","result","Promise","type"],"mappings":";;;;;;AAgBO,MAAMA;IAQT,YAAYC,OAAmB,CAAE;aAHhB,MAAM,GAAgB,IAAIC;aAC1B,YAAY,GAA+B,IAAIC;QAG5D,IAAI,CAAC,OAAO,GAAGF;IACnB;IAEA,MAAM,QAAQG,MAAuB,EAAiB;QAClD,IAAI,CAAC,gBAAgB,GAAGA,OAAO,gBAAgB;QAC/C,IAAI,CAAC,aAAa,GAAGA,OAAO,aAAa;QAEzC,IAAIA,OAAO,MAAM,EACbA,OAAO,MAAM,CAAC,OAAO,CAACC,CAAAA,KAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAACA;QAGhD,IAAI;YACA,MAAM,EAAEC,MAAM,EAAE,GAAGF;YAEnB,IAAI,CAACE,QACD,MAAM,IAAIC,YACN,oDACA,mDACA;gBAAED;YAAO;YAIjB,MAAME,MAAM,MAAM,IAAI,CAAC,MAAM,CAACF;YAC9B,MAAMG,YAAYH,OAAO,QAAQ,GAC3B,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAACA,OAAO,QAAQ,IAC9C;YAGN,IAAI,CAAC,YAAY,CAAC,GAAG,CAACA,OAAO,EAAE,EAAE;gBAC7B,MAAMA,OAAO,IAAI;gBACjB,UAAUA,OAAO,QAAQ,IAAII;gBAC7B,MAAMC,KAAK,MAAM,CAACL,OAAO,IAAI,EAAEG,WAAW;gBAC1C,aAAaG,YAAY,MAAM,CAACN,OAAO,WAAW,EAAEG;YACxD;YAGA,IAAI,CAAC,SAAS,CAACD,IAAI,EAAE;YAGrB,MAAMK,iBAAiB,MAAM,IAAI,CAAC,kBAAkB,CAACL;YAErD,KAAK,MAAMM,SAASD,eAAgB;gBAChC,IAAI,IAAI,CAAC,gBAAgB,MAAM;oBAC3B,M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B,EAAoC;QAC3F,MAAMuB,cAAc,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAACC;QAEnD,MAAMC,SAAS,MAAM,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAC,IACrDF,YAAY,OAAO,CAAC;gBACvB,OAAO;oBACH,MAAMvB,IAAI,IAAI;oBACd,UAAUA,IAAI,EAAE;gBACpB;YACJ;QAGJ,IAAIyB,OAAO,MAAM,IACb,MAAMA,OAAO,KAAK;QAGtB,OAAO,MAAMC,QAAQ,GAAG,CAACD,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC3B,CAAAA,SAAU,IAAI,CAAC,MAAM,CAACA;IAC5E;IAEA,MAAc,OAAO,EACjBD,EAAE,EACF8B,IAAI,EACJb,QAAQ,EACRD,IAAI,EACJG,WAAW,EACN,EAAkC;QACvC,MAAMhB,MAAM,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAACH;QAE3C,IAAI,CAACG,KAAK;YACN,MAAMC,YAAYa,WAAW,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAACA,YAAY;YAExE,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC;gBACrCjB;gBACA8B;gBACAd;gBACA,UAAUC,YAAYZ;gBACtB,MAAMC,KAAK,MAAM,CAACU,MAAMZ,WAAW;gBACnC,aAAaG,YAAY,MAAM,CAACY,aAAaf;YACjD;QACJ;QAEA,OAAOD;IACX;AACJ"}
1
+ {"version":3,"file":"features/flp/UpdateFlp/UpdateFlpUseCase.js","sources":["../../../../src/features/flp/UpdateFlp/UpdateFlpUseCase.ts"],"sourcesContent":["import { WebinyError } from \"@webiny/error\";\nimport { Path } from \"~/utils/Path.js\";\nimport { Permissions, ROOT_FOLDER } from \"@webiny/shared-aco\";\nimport type { UpdateFlpParams, UpdateFlpUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport type { Folder, FolderLevelPermission, FolderPermission } from \"~/types.js\";\nimport type { AcoFlpCrud } from \"~/features/folder/shared/abstractions.js\";\nimport type { ListFoldersUseCase } from \"~/features/folder/ListFolders/index.js\";\nimport type { FolderModelProvider } from \"~/domain/folder/abstractions.js\";\nimport { EntryId } from \"@webiny/api-headless-cms/exports/api/cms/entry.js\";\nimport type { UpdateEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/UpdateEntry/index.js\";\nimport type { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/abstractions.js\";\n\ninterface FlpUpdateData {\n parentId: string;\n slug: string;\n path: string;\n permissions: FolderPermission[];\n}\n\nexport class UpdateFlpUseCase implements UseCaseAbstraction.Interface {\n private isCloseToTimeout?: () => boolean;\n private handleTimeout?: (updated: string[]) => void;\n\n private readonly queued: Set<string> = new Set();\n private readonly flpsToUpdate: Map<string, FlpUpdateData> = new Map();\n\n constructor(\n private flpCrud: AcoFlpCrud.Interface,\n private listFoldersUseCase: ListFoldersUseCase.Interface,\n private folderModelProvider: FolderModelProvider.Interface,\n private updateEntryUseCase: UpdateEntryUseCase.Interface,\n private identityContext: IdentityContext.Interface\n ) {}\n\n async execute(params: UpdateFlpParams): Promise<void> {\n this.isCloseToTimeout = params.isCloseToTimeout;\n this.handleTimeout = params.handleTimeout;\n\n if (params.queued) {\n params.queued.forEach(id => this.queued.add(id));\n }\n\n try {\n const { folder } = params;\n\n if (!folder) {\n throw new WebinyError(\n \"Missing `folder`, I can't update the FLP record.\",\n \"ERROR_UPDATING_FLP_USE_CASE_FOLDER_NOT_PROVIDED\",\n { folder }\n );\n }\n\n const flp = await this.getFlp(folder);\n const parentFlp = folder.parentId ? await this.flpCrud.get(folder.parentId) : null;\n\n // Add the root folder to the update collection\n this.flpsToUpdate.set(folder.id, {\n slug: folder.slug,\n parentId: folder.parentId ?? ROOT_FOLDER,\n path: Path.create(folder.slug, parentFlp?.path),\n permissions: Permissions.create(folder.permissions, parentFlp)\n });\n\n // Let's set the FLP as in queue\n this.setQueued(flp.id);\n\n // Get direct children and process each branch completely\n const directChildren = await this.listDirectChildren(flp);\n\n for (const child of directChildren) {\n if (this.isCloseToTimeout?.()) {\n await this.executeBatchUpdate();\n this.handleTimeout?.(this.getQueuedList());\n return;\n }\n await this.collectBranchForUpdate(child, flp);\n }\n\n // Execute batch update\n await this.executeBatchUpdate();\n } catch (error) {\n // Clear the update collection in case of error\n this.flpsToUpdate.clear();\n this.queued.clear();\n throw WebinyError.from(error, {\n message: \"Error while updating FLP\",\n code: \"ERROR_UPDATING_FLP_USE_CASE\"\n });\n }\n }\n\n private async collectBranchForUpdate(\n flp: FolderLevelPermission,\n parentFlp: FolderLevelPermission\n ): Promise<void> {\n if (this.isQueued(flp.id)) {\n return;\n }\n\n // Get the parent's permissions from the update collection if available\n const parentFlpData = this.flpsToUpdate.get(parentFlp.id);\n const currentParentFlp = {\n ...parentFlp,\n ...(parentFlpData && { ...parentFlpData })\n };\n\n // Add the FLP to the update collection with inherited permissions\n this.flpsToUpdate.set(flp.id, {\n slug: flp.slug,\n parentId: flp.parentId,\n path: Path.create(flp.slug, currentParentFlp.path),\n permissions: Permissions.create(flp.permissions, currentParentFlp)\n });\n\n // Add the FLP to the queue list so we don't fetch it again\n this.setQueued(flp.id);\n\n // Process all children of this folder before moving to siblings\n const children = await this.listDirectChildren(flp);\n\n for (const child of children) {\n if (this.isCloseToTimeout?.()) {\n await this.executeBatchUpdate();\n this.handleTimeout?.(this.getQueuedList());\n return;\n }\n // Pass the current FLP as the parent for the child\n await this.collectBranchForUpdate(child, flp);\n }\n }\n\n private async executeBatchUpdate(): Promise<void> {\n const folderModel = await this.folderModelProvider.get();\n try {\n const items = Array.from(this.flpsToUpdate.entries()).map(\n ([id, { slug, parentId, path, permissions }]) => {\n return {\n id,\n data: {\n slug,\n parentId,\n path,\n permissions\n }\n };\n }\n );\n\n await this.flpCrud.batchUpdate(items);\n\n // Update all folders with the new path\n for (const item of items) {\n const { id, data } = item;\n // Directly update the folder in CMS storage to bypass any folder update event triggers.\n const entryId = EntryId.from(id);\n const updateResult = await this.updateEntryUseCase.execute(\n folderModel,\n entryId.toString(),\n { values: { path: data.path } }\n );\n if (updateResult.isFail()) {\n throw updateResult.error;\n }\n }\n } catch (error) {\n throw WebinyError.from(error, {\n message: \"Error while executing batch update of FLPs\",\n code: \"BATCH_UPDATE_FLP_ERROR\",\n data: {\n items: Array.from(this.flpsToUpdate.keys())\n }\n });\n } finally {\n // Clear the update collection after the batch update\n this.flpsToUpdate.clear();\n\n //Let's remove all the updated FLPs ids from the queue cache\n this.clearQueuedList();\n }\n }\n\n private getQueuedList(): string[] {\n return Array.from(this.queued);\n }\n\n private setQueued(id: string): void {\n this.queued.add(id);\n }\n\n private isQueued(id: string): boolean {\n return this.queued.has(id);\n }\n\n private clearQueuedList(): void {\n this.queued.clear();\n }\n\n private async listDirectChildren(flp: FolderLevelPermission): Promise<FolderLevelPermission[]> {\n const result = await this.identityContext.withoutAuthorization(() => {\n return this.listFoldersUseCase.execute({\n where: {\n type: flp.type,\n parentId: flp.id\n }\n });\n });\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return await Promise.all(result.value.folders.map(folder => this.getFlp(folder)));\n }\n\n private async getFlp({\n id,\n type,\n parentId,\n slug,\n permissions\n }: Folder): Promise<FolderLevelPermission> {\n const flp = await this.flpCrud.get(id);\n\n if (!flp) {\n const parentFlp = parentId ? await this.flpCrud.get(parentId) : null;\n\n return await this.flpCrud.create({\n id,\n type,\n slug,\n parentId: parentId ?? ROOT_FOLDER,\n path: Path.create(slug, parentFlp?.path),\n permissions: Permissions.create(permissions, parentFlp)\n });\n }\n\n return flp;\n }\n}\n"],"names":["UpdateFlpUseCase","flpCrud","listFoldersUseCase","folderModelProvider","updateEntryUseCase","identityContext","Set","Map","params","id","folder","WebinyError","flp","parentFlp","ROOT_FOLDER","Path","Permissions","directChildren","child","error","parentFlpData","currentParentFlp","children","folderModel","items","Array","slug","parentId","path","permissions","item","data","entryId","EntryId","updateResult","result","Promise","type"],"mappings":";;;;AAmBO,MAAMA;IAOT,YACYC,OAA6B,EAC7BC,kBAAgD,EAChDC,mBAAkD,EAClDC,kBAAgD,EAChDC,eAA0C,CACpD;aALUJ,OAAO,GAAPA;aACAC,kBAAkB,GAAlBA;aACAC,mBAAmB,GAAnBA;aACAC,kBAAkB,GAAlBA;aACAC,eAAe,GAAfA;aARK,MAAM,GAAgB,IAAIC;aAC1B,YAAY,GAA+B,IAAIC;IAQ7D;IAEH,MAAM,QAAQC,MAAuB,EAAiB;QAClD,IAAI,CAAC,gBAAgB,GAAGA,OAAO,gBAAgB;QAC/C,IAAI,CAAC,aAAa,GAAGA,OAAO,aAAa;QAEzC,IAAIA,OAAO,MAAM,EACbA,OAAO,MAAM,CAAC,OAAO,CAACC,CAAAA,KAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAACA;QAGhD,IAAI;YACA,MAAM,EAAEC,MAAM,EAAE,GAAGF;YAEnB,IAAI,CAACE,QACD,MAAM,IAAIC,YACN,oDACA,mDACA;gBAAED;YAAO;YAIjB,MAAME,MAAM,MAAM,IAAI,CAAC,MAAM,CAACF;YAC9B,MAAMG,YAAYH,OAAO,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAACA,OAAO,QAAQ,IAAI;YAG9E,IAAI,CAAC,YAAY,CAAC,GAAG,CAACA,OAAO,EAAE,EAAE;gBAC7B,MAAMA,OAAO,IAAI;gBACjB,UAAUA,OAAO,QAAQ,IAAII;gBAC7B,MAAMC,KAAK,MAAM,CAACL,OAAO,IAAI,EAAEG,WAAW;gBAC1C,aAAaG,YAAY,MAAM,CAACN,OAAO,WAAW,EAAEG;YACxD;YAGA,IAAI,CAAC,SAAS,CAACD,IAAI,EAAE;YAGrB,MAAMK,iBAAiB,MAAM,IAAI,CAAC,kBAAkB,CAACL;YAErD,KAAK,MAAMM,SAASD,eAAgB;gBAChC,IAAI,IAAI,CAA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,MAAM,CAAC,KAAK;IACrB;IAEA,MAAc,mBAAmBG,GAA0B,EAAoC;QAC3F,MAAMuB,SAAS,MAAM,IAAI,CAAC,eAAe,CAAC,oBAAoB,CAAC,IACpD,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC;gBACnC,OAAO;oBACH,MAAMvB,IAAI,IAAI;oBACd,UAAUA,IAAI,EAAE;gBACpB;YACJ;QAGJ,IAAIuB,OAAO,MAAM,IACb,MAAMA,OAAO,KAAK;QAGtB,OAAO,MAAMC,QAAQ,GAAG,CAACD,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,CAACzB,CAAAA,SAAU,IAAI,CAAC,MAAM,CAACA;IAC5E;IAEA,MAAc,OAAO,EACjBD,EAAE,EACF4B,IAAI,EACJV,QAAQ,EACRD,IAAI,EACJG,WAAW,EACN,EAAkC;QACvC,MAAMjB,MAAM,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAACH;QAEnC,IAAI,CAACG,KAAK;YACN,MAAMC,YAAYc,WAAW,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAACA,YAAY;YAEhE,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;gBAC7BlB;gBACA4B;gBACAX;gBACA,UAAUC,YAAYb;gBACtB,MAAMC,KAAK,MAAM,CAACW,MAAMb,WAAW;gBACnC,aAAaG,YAAY,MAAM,CAACa,aAAahB;YACjD;QACJ;QAEA,OAAOD;IACX;AACJ"}
@@ -1,10 +1,5 @@
1
1
  import type { Container } from "@webiny/di";
2
- import type { AcoContext } from "../../../types.js";
3
- interface LegacyDeps {
4
- context: AcoContext;
5
- }
6
2
  export declare const UpdateFlpFeature: {
7
3
  name: string;
8
- register(container: Container, context: LegacyDeps): void;
4
+ register(container: Container): void;
9
5
  };
10
- export {};
@@ -1,10 +1,15 @@
1
1
  import { createFeature } from "@webiny/feature/api";
2
2
  import { UpdateFlpUseCase } from "./UpdateFlpUseCase.js";
3
3
  import { UpdateFlpUseCase as external_abstractions_js_UpdateFlpUseCase } from "./abstractions.js";
4
+ import { AcoFlpCrud } from "../../folder/shared/abstractions.js";
5
+ import { ListFoldersUseCase } from "../../folder/ListFolders/index.js";
6
+ import { FolderModelProvider } from "../../../domain/folder/abstractions.js";
7
+ import { UpdateEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/UpdateEntry/index.js";
8
+ import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/abstractions.js";
4
9
  const UpdateFlpFeature = createFeature({
5
10
  name: "UpdateFlp",
6
- register (container, deps) {
7
- container.registerFactory(external_abstractions_js_UpdateFlpUseCase, ()=>new UpdateFlpUseCase(deps.context));
11
+ register (container) {
12
+ container.registerFactory(external_abstractions_js_UpdateFlpUseCase, ()=>new UpdateFlpUseCase(container.resolve(AcoFlpCrud), container.resolve(ListFoldersUseCase), container.resolve(FolderModelProvider), container.resolve(UpdateEntryUseCase), container.resolve(IdentityContext)));
8
13
  }
9
14
  });
10
15
  export { UpdateFlpFeature };
@@ -1 +1 @@
1
- {"version":3,"file":"features/flp/UpdateFlp/feature.js","sources":["../../../../src/features/flp/UpdateFlp/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport type { Container } from \"@webiny/di\";\nimport { UpdateFlpUseCase } from \"./UpdateFlpUseCase.js\";\nimport { UpdateFlpUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport type { AcoContext } from \"~/types.js\";\n\ninterface LegacyDeps {\n context: AcoContext;\n}\n\nexport const UpdateFlpFeature = createFeature({\n name: \"UpdateFlp\",\n register(container: Container, deps: LegacyDeps) {\n container.registerFactory(UseCaseAbstraction, () => {\n return new UpdateFlpUseCase(deps.context);\n });\n }\n});\n"],"names":["UpdateFlpFeature","createFeature","container","deps","UseCaseAbstraction","UpdateFlpUseCase"],"mappings":";;;AAUO,MAAMA,mBAAmBC,cAAc;IAC1C,MAAM;IACN,UAASC,SAAoB,EAAEC,IAAgB;QAC3CD,UAAU,eAAe,CAACE,2CAAoB,IACnC,IAAIC,iBAAiBF,KAAK,OAAO;IAEhD;AACJ"}
1
+ {"version":3,"file":"features/flp/UpdateFlp/feature.js","sources":["../../../../src/features/flp/UpdateFlp/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport type { Container } from \"@webiny/di\";\nimport { UpdateFlpUseCase } from \"./UpdateFlpUseCase.js\";\nimport { UpdateFlpUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { AcoFlpCrud } from \"~/features/folder/shared/abstractions.js\";\nimport { ListFoldersUseCase } from \"~/features/folder/ListFolders/index.js\";\nimport { FolderModelProvider } from \"~/domain/folder/abstractions.js\";\nimport { UpdateEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/UpdateEntry/index.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/abstractions.js\";\n\nexport const UpdateFlpFeature = createFeature({\n name: \"UpdateFlp\",\n register(container: Container) {\n container.registerFactory(UseCaseAbstraction, () => {\n return new UpdateFlpUseCase(\n container.resolve(AcoFlpCrud),\n container.resolve(ListFoldersUseCase),\n container.resolve(FolderModelProvider),\n container.resolve(UpdateEntryUseCase),\n container.resolve(IdentityContext)\n );\n });\n }\n});\n"],"names":["UpdateFlpFeature","createFeature","container","UseCaseAbstraction","UpdateFlpUseCase","AcoFlpCrud","ListFoldersUseCase","FolderModelProvider","UpdateEntryUseCase","IdentityContext"],"mappings":";;;;;;;;AAUO,MAAMA,mBAAmBC,cAAc;IAC1C,MAAM;IACN,UAASC,SAAoB;QACzBA,UAAU,eAAe,CAACC,2CAAoB,IACnC,IAAIC,iBACPF,UAAU,OAAO,CAACG,aAClBH,UAAU,OAAO,CAACI,qBAClBJ,UAAU,OAAO,CAACK,sBAClBL,UAAU,OAAO,CAACM,qBAClBN,UAAU,OAAO,CAACO;IAG9B;AACJ"}
@@ -3,14 +3,14 @@ import { CreateFolderRepository as RepositoryAbstraction, type ICreateFolderRepo
3
3
  import { CreateEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/CreateEntry";
4
4
  import { ListLatestEntriesUseCase } from "@webiny/api-headless-cms/features/contentEntry/ListEntries";
5
5
  import { GetEntryByIdUseCase } from "@webiny/api-headless-cms/features/contentEntry/GetEntryById";
6
- import { FolderModel } from "../../../domain/folder/abstractions.js";
6
+ import { FolderModelProvider } from "../../../domain/folder/abstractions.js";
7
7
  import type { CreateFolderParams, Folder } from "../../../folder/folder.types.js";
8
8
  declare class CreateFolderRepositoryImpl implements ICreateFolderRepository {
9
9
  private createEntry;
10
10
  private listLatestEntries;
11
11
  private getEntryById;
12
- private folderModel;
13
- constructor(createEntry: CreateEntryUseCase.Interface, listLatestEntries: ListLatestEntriesUseCase.Interface, getEntryById: GetEntryByIdUseCase.Interface, folderModel: FolderModel.Interface);
12
+ private folderModelProvider;
13
+ constructor(createEntry: CreateEntryUseCase.Interface, listLatestEntries: ListLatestEntriesUseCase.Interface, getEntryById: GetEntryByIdUseCase.Interface, folderModelProvider: FolderModelProvider.Interface);
14
14
  execute(data: CreateFolderParams): Promise<Result<Folder, RepositoryAbstraction.Error>>;
15
15
  private checkExistingFolder;
16
16
  private createFolderPath;
@@ -3,19 +3,20 @@ import { CreateFolderRepository } from "./abstractions.js";
3
3
  import { CreateEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/CreateEntry";
4
4
  import { ListLatestEntriesUseCase } from "@webiny/api-headless-cms/features/contentEntry/ListEntries";
5
5
  import { GetEntryByIdUseCase } from "@webiny/api-headless-cms/features/contentEntry/GetEntryById";
6
- import { FolderModel } from "../../../domain/folder/abstractions.js";
6
+ import { FolderModelProvider } from "../../../domain/folder/abstractions.js";
7
7
  import { EntryToFolderMapper } from "../shared/EntryToFolderMapper.js";
8
8
  import { FolderPersistenceError, FolderValidationError } from "../../../domain/folder/errors.js";
9
9
  import { Path } from "../../../utils/Path.js";
10
10
  import { EntryId } from "@webiny/api-headless-cms/exports/api/cms/entry.js";
11
11
  class CreateFolderRepositoryImpl {
12
- constructor(createEntry, listLatestEntries, getEntryById, folderModel){
12
+ constructor(createEntry, listLatestEntries, getEntryById, folderModelProvider){
13
13
  this.createEntry = createEntry;
14
14
  this.listLatestEntries = listLatestEntries;
15
15
  this.getEntryById = getEntryById;
16
- this.folderModel = folderModel;
16
+ this.folderModelProvider = folderModelProvider;
17
17
  }
18
18
  async execute(data) {
19
+ const folderModel = await this.folderModelProvider.get();
19
20
  const checkResult = await this.checkExistingFolder({
20
21
  type: data.type,
21
22
  slug: data.slug,
@@ -27,7 +28,7 @@ class CreateFolderRepositoryImpl {
27
28
  parentId: data.parentId
28
29
  });
29
30
  if (pathResult.isFail()) return Result.fail(pathResult.error);
30
- const result = await this.createEntry.execute(this.folderModel, {
31
+ const result = await this.createEntry.execute(folderModel, {
31
32
  values: {
32
33
  ...data,
33
34
  parentId: data.parentId || null,
@@ -42,8 +43,9 @@ class CreateFolderRepositoryImpl {
42
43
  return Result.ok(folder);
43
44
  }
44
45
  async checkExistingFolder(params) {
46
+ const folderModel = await this.folderModelProvider.get();
45
47
  const { type, slug, parentId, excludeId } = params;
46
- const result = await this.listLatestEntries.execute(this.folderModel, {
48
+ const result = await this.listLatestEntries.execute(folderModel, {
47
49
  where: {
48
50
  latest: true,
49
51
  values: {
@@ -63,9 +65,10 @@ class CreateFolderRepositoryImpl {
63
65
  return Result.ok();
64
66
  }
65
67
  async createFolderPath(params) {
68
+ const folderModel = await this.folderModelProvider.get();
66
69
  const { slug, parentId } = params;
67
70
  if (!parentId) return Result.ok(Path.create(slug));
68
- const parentResult = await this.getEntryById.execute(this.folderModel, EntryId.from(parentId).toString());
71
+ const parentResult = await this.getEntryById.execute(folderModel, EntryId.from(parentId).toString());
69
72
  if (parentResult.isFail()) return Result.fail(new FolderPersistenceError(new Error("Parent folder not found. Unable to create the folder path")));
70
73
  const parentFolder = EntryToFolderMapper.toFolder(parentResult.value);
71
74
  return Result.ok(Path.create(slug, parentFolder.path));
@@ -77,7 +80,7 @@ const CreateFolderRepository_CreateFolderRepository = CreateFolderRepository.cre
77
80
  CreateEntryUseCase,
78
81
  ListLatestEntriesUseCase,
79
82
  GetEntryByIdUseCase,
80
- FolderModel
83
+ FolderModelProvider
81
84
  ]
82
85
  });
83
86
  export { CreateFolderRepository_CreateFolderRepository as CreateFolderRepository };
@@ -1 +1 @@
1
- {"version":3,"file":"features/folder/CreateFolder/CreateFolderRepository.js","sources":["../../../../src/features/folder/CreateFolder/CreateFolderRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n CreateFolderRepository as RepositoryAbstraction,\n type ICreateFolderRepository\n} from \"./abstractions.js\";\nimport { CreateEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/CreateEntry\";\nimport { ListLatestEntriesUseCase } from \"@webiny/api-headless-cms/features/contentEntry/ListEntries\";\nimport { GetEntryByIdUseCase } from \"@webiny/api-headless-cms/features/contentEntry/GetEntryById\";\nimport { FolderModel } from \"~/domain/folder/abstractions.js\";\nimport type { CmsEntryFolder, CreateFolderParams, Folder } from \"~/folder/folder.types.js\";\nimport { EntryToFolderMapper } from \"../shared/EntryToFolderMapper.js\";\nimport { FolderPersistenceError, FolderValidationError } from \"~/domain/folder/errors.js\";\nimport { Path } from \"~/utils/Path.js\";\nimport { EntryId } from \"@webiny/api-headless-cms/exports/api/cms/entry.js\";\n\nclass CreateFolderRepositoryImpl implements ICreateFolderRepository {\n constructor(\n private createEntry: CreateEntryUseCase.Interface,\n private listLatestEntries: ListLatestEntriesUseCase.Interface,\n private getEntryById: GetEntryByIdUseCase.Interface,\n private folderModel: FolderModel.Interface\n ) {}\n\n async execute(data: CreateFolderParams): Promise<Result<Folder, RepositoryAbstraction.Error>> {\n // Check if folder already exists\n const checkResult = await this.checkExistingFolder({\n type: data.type,\n slug: data.slug,\n parentId: data.parentId\n });\n\n if (checkResult.isFail()) {\n return Result.fail(checkResult.error);\n }\n\n // Create folder path\n const pathResult = await this.createFolderPath({\n slug: data.slug,\n parentId: data.parentId\n });\n\n if (pathResult.isFail()) {\n return Result.fail(pathResult.error);\n }\n\n // Create the entry\n const result = await this.createEntry.execute<CmsEntryFolder>(this.folderModel, {\n values: {\n ...data,\n parentId: data.parentId || null,\n path: pathResult.value\n }\n });\n\n if (result.isFail()) {\n if (result.error.code === \"Cms/Entry/ValidationError\") {\n return Result.fail(new FolderValidationError(result.error.message));\n }\n return Result.fail(new FolderPersistenceError(result.error));\n }\n\n const folder = EntryToFolderMapper.toFolder(result.value);\n return Result.ok(folder);\n }\n\n private async checkExistingFolder(params: {\n type: string;\n slug: string;\n parentId?: string | null;\n excludeId?: string;\n }): Promise<Result<void, RepositoryAbstraction.Error>> {\n const { type, slug, parentId, excludeId } = params;\n\n const result = await this.listLatestEntries.execute<CmsEntryFolder>(this.folderModel, {\n where: {\n latest: true,\n values: {\n type,\n slug,\n parentId\n },\n ...(excludeId ? { entryId_not: excludeId } : {})\n },\n limit: 1\n });\n\n if (result.isFail()) {\n return Result.fail(new FolderPersistenceError(result.error));\n }\n\n const { entries } = result.value;\n\n if (entries.length > 0) {\n return Result.fail(\n new FolderValidationError(\n `Folder with slug \"${slug}\" already exists at this level.`\n )\n );\n }\n\n return Result.ok();\n }\n\n private async createFolderPath(params: {\n slug: string;\n parentId?: string | null;\n }): Promise<Result<string, RepositoryAbstraction.Error>> {\n const { slug, parentId } = params;\n\n if (!parentId) {\n return Result.ok(Path.create(slug));\n }\n\n const parentResult = await this.getEntryById.execute<CmsEntryFolder>(\n this.folderModel,\n EntryId.from(parentId).toString()\n );\n\n if (parentResult.isFail()) {\n return Result.fail(\n new FolderPersistenceError(\n new Error(\"Parent folder not found. Unable to create the folder path\")\n )\n );\n }\n\n const parentFolder = EntryToFolderMapper.toFolder(parentResult.value);\n return Result.ok(Path.create(slug, parentFolder.path));\n }\n}\n\nexport const CreateFolderRepository = RepositoryAbstraction.createImplementation({\n implementation: CreateFolderRepositoryImpl,\n dependencies: [CreateEntryUseCase, ListLatestEntriesUseCase, GetEntryByIdUseCase, FolderModel]\n});\n"],"names":["CreateFolderRepositoryImpl","createEntry","listLatestEntries","getEntryById","folderModel","data","checkResult","Result","pathResult","result","FolderValidationError","FolderPersistenceError","folder","EntryToFolderMapper","params","type","slug","parentId","excludeId","entries","Path","parentResult","EntryId","Error","parentFolder","CreateFolderRepository","RepositoryAbstraction","CreateEntryUseCase","ListLatestEntriesUseCase","GetEntryByIdUseCase","FolderModel"],"mappings":";;;;;;;;;;AAeA,MAAMA;IACF,YACYC,WAAyC,EACzCC,iBAAqD,EACrDC,YAA2C,EAC3CC,WAAkC,CAC5C;aAJUH,WAAW,GAAXA;aACAC,iBAAiB,GAAjBA;aACAC,YAAY,GAAZA;aACAC,WAAW,GAAXA;IACT;IAEH,MAAM,QAAQC,IAAwB,EAAwD;QAE1F,MAAMC,cAAc,MAAM,IAAI,CAAC,mBAAmB,CAAC;YAC/C,MAAMD,KAAK,IAAI;YACf,MAAMA,KAAK,IAAI;YACf,UAAUA,KAAK,QAAQ;QAC3B;QAEA,IAAIC,YAAY,MAAM,IAClB,OAAOC,OAAO,IAAI,CAACD,YAAY,KAAK;QAIxC,MAAME,aAAa,MAAM,IAAI,CAAC,gBAAgB,CAAC;YAC3C,MAAMH,KAAK,IAAI;YACf,UAAUA,KAAK,QAAQ;QAC3B;QAEA,IAAIG,WAAW,MAAM,IACjB,OAAOD,OAAO,IAAI,CAACC,WAAW,KAAK;QAIvC,MAAMC,SAAS,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAiB,IAAI,CAAC,WAAW,EAAE;YAC5E,QAAQ;gBACJ,GAAGJ,IAAI;gBACP,UAAUA,KAAK,QAAQ,IAAI;gBAC3B,MAAMG,WAAW,KAAK;YAC1B;QACJ;QAEA,IAAIC,OAAO,MAAM,IAAI;YACjB,IAAIA,AAAsB,gCAAtBA,OAAO,KAAK,CAAC,IAAI,EACjB,OAAOF,OAAO,IAAI,CAAC,IAAIG,sBAAsBD,OAAO,KAAK,CAAC,OAAO;YAErE,OAAOF,OAAO,IAA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M,CAACJ,MAAMQ,aAAa,IAAI;IACxD;AACJ;AAEO,MAAMC,gDAAyBC,uBAAAA,oBAA0C,CAAC;IAC7E,gBAAgB1B;IAChB,cAAc;QAAC2B;QAAoBC;QAA0BC;QAAqBC;KAAY;AAClG"}
1
+ {"version":3,"file":"features/folder/CreateFolder/CreateFolderRepository.js","sources":["../../../../src/features/folder/CreateFolder/CreateFolderRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n CreateFolderRepository as RepositoryAbstraction,\n type ICreateFolderRepository\n} from \"./abstractions.js\";\nimport { CreateEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/CreateEntry\";\nimport { ListLatestEntriesUseCase } from \"@webiny/api-headless-cms/features/contentEntry/ListEntries\";\nimport { GetEntryByIdUseCase } from \"@webiny/api-headless-cms/features/contentEntry/GetEntryById\";\nimport { FolderModelProvider } from \"~/domain/folder/abstractions.js\";\nimport type { CmsEntryFolder, CreateFolderParams, Folder } from \"~/folder/folder.types.js\";\nimport { EntryToFolderMapper } from \"../shared/EntryToFolderMapper.js\";\nimport { FolderPersistenceError, FolderValidationError } from \"~/domain/folder/errors.js\";\nimport { Path } from \"~/utils/Path.js\";\nimport { EntryId } from \"@webiny/api-headless-cms/exports/api/cms/entry.js\";\n\nclass CreateFolderRepositoryImpl implements ICreateFolderRepository {\n constructor(\n private createEntry: CreateEntryUseCase.Interface,\n private listLatestEntries: ListLatestEntriesUseCase.Interface,\n private getEntryById: GetEntryByIdUseCase.Interface,\n private folderModelProvider: FolderModelProvider.Interface\n ) {}\n\n async execute(data: CreateFolderParams): Promise<Result<Folder, RepositoryAbstraction.Error>> {\n const folderModel = await this.folderModelProvider.get();\n // Check if folder already exists\n const checkResult = await this.checkExistingFolder({\n type: data.type,\n slug: data.slug,\n parentId: data.parentId\n });\n\n if (checkResult.isFail()) {\n return Result.fail(checkResult.error);\n }\n\n // Create folder path\n const pathResult = await this.createFolderPath({\n slug: data.slug,\n parentId: data.parentId\n });\n\n if (pathResult.isFail()) {\n return Result.fail(pathResult.error);\n }\n\n // Create the entry\n const result = await this.createEntry.execute<CmsEntryFolder>(folderModel, {\n values: {\n ...data,\n parentId: data.parentId || null,\n path: pathResult.value\n }\n });\n\n if (result.isFail()) {\n if (result.error.code === \"Cms/Entry/ValidationError\") {\n return Result.fail(new FolderValidationError(result.error.message));\n }\n return Result.fail(new FolderPersistenceError(result.error));\n }\n\n const folder = EntryToFolderMapper.toFolder(result.value);\n return Result.ok(folder);\n }\n\n private async checkExistingFolder(params: {\n type: string;\n slug: string;\n parentId?: string | null;\n excludeId?: string;\n }): Promise<Result<void, RepositoryAbstraction.Error>> {\n const folderModel = await this.folderModelProvider.get();\n const { type, slug, parentId, excludeId } = params;\n\n const result = await this.listLatestEntries.execute<CmsEntryFolder>(folderModel, {\n where: {\n latest: true,\n values: {\n type,\n slug,\n parentId\n },\n ...(excludeId ? { entryId_not: excludeId } : {})\n },\n limit: 1\n });\n\n if (result.isFail()) {\n return Result.fail(new FolderPersistenceError(result.error));\n }\n\n const { entries } = result.value;\n\n if (entries.length > 0) {\n return Result.fail(\n new FolderValidationError(\n `Folder with slug \"${slug}\" already exists at this level.`\n )\n );\n }\n\n return Result.ok();\n }\n\n private async createFolderPath(params: {\n slug: string;\n parentId?: string | null;\n }): Promise<Result<string, RepositoryAbstraction.Error>> {\n const folderModel = await this.folderModelProvider.get();\n const { slug, parentId } = params;\n\n if (!parentId) {\n return Result.ok(Path.create(slug));\n }\n\n const parentResult = await this.getEntryById.execute<CmsEntryFolder>(\n folderModel,\n EntryId.from(parentId).toString()\n );\n\n if (parentResult.isFail()) {\n return Result.fail(\n new FolderPersistenceError(\n new Error(\"Parent folder not found. Unable to create the folder path\")\n )\n );\n }\n\n const parentFolder = EntryToFolderMapper.toFolder(parentResult.value);\n return Result.ok(Path.create(slug, parentFolder.path));\n }\n}\n\nexport const CreateFolderRepository = RepositoryAbstraction.createImplementation({\n implementation: CreateFolderRepositoryImpl,\n dependencies: [\n CreateEntryUseCase,\n ListLatestEntriesUseCase,\n GetEntryByIdUseCase,\n FolderModelProvider\n ]\n});\n"],"names":["CreateFolderRepositoryImpl","createEntry","listLatestEntries","getEntryById","folderModelProvider","data","folderModel","checkResult","Result","pathResult","result","FolderValidationError","FolderPersistenceError","folder","EntryToFolderMapper","params","type","slug","parentId","excludeId","entries","Path","parentResult","EntryId","Error","parentFolder","CreateFolderRepository","RepositoryAbstraction","CreateEntryUseCase","ListLatestEntriesUseCase","GetEntryByIdUseCase","FolderModelProvider"],"mappings":";;;;;;;;;;AAeA,MAAMA;IACF,YACYC,WAAyC,EACzCC,iBAAqD,EACrDC,YAA2C,EAC3CC,mBAAkD,CAC5D;aAJUH,WAAW,GAAXA;aACAC,iBAAiB,GAAjBA;aACAC,YAAY,GAAZA;aACAC,mBAAmB,GAAnBA;IACT;IAEH,MAAM,QAAQC,IAAwB,EAAwD;QAC1F,MAAMC,cAAc,MAAM,IAAI,CAAC,mBAAmB,CAAC,GAAG;QAEtD,MAAMC,cAAc,MAAM,IAAI,CAAC,mBAAmB,CAAC;YAC/C,MAAMF,KAAK,IAAI;YACf,MAAMA,KAAK,IAAI;YACf,UAAUA,KAAK,QAAQ;QAC3B;QAEA,IAAIE,YAAY,MAAM,IAClB,OAAOC,OAAO,IAAI,CAACD,YAAY,KAAK;QAIxC,MAAME,aAAa,MAAM,IAAI,CAAC,gBAAgB,CAAC;YAC3C,MAAMJ,KAAK,IAAI;YACf,UAAUA,KAAK,QAAQ;QAC3B;QAEA,IAAII,WAAW,MAAM,IACjB,OAAOD,OAAO,IAAI,CAACC,WAAW,KAAK;QAIvC,MAAMC,SAAS,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAiBJ,aAAa;YACvE,QAAQ;gBACJ,GAAGD,IAAI;gBACP,UAAUA,KAAK,QAAQ,IAAI;gBAC3B,MAAMI,WAAW,KAAK;YAC1B;QACJ;QAEA,IAAIC,OAAO,MAAM,IAAI;YACjB,IAAIA,AAAsB,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iB,QAAQ,IAAI,CAACL,UAAU,QAAQ;QAGnC,IAAII,aAAa,MAAM,IACnB,OAAOd,OAAO,IAAI,CACd,IAAII,uBACA,IAAIY,MAAM;QAKtB,MAAMC,eAAeX,oBAAoB,QAAQ,CAACQ,aAAa,KAAK;QACpE,OAAOd,OAAO,EAAE,CAACa,KAAK,MAAM,CAACJ,MAAMQ,aAAa,IAAI;IACxD;AACJ;AAEO,MAAMC,gDAAyBC,uBAAAA,oBAA0C,CAAC;IAC7E,gBAAgB3B;IAChB,cAAc;QACV4B;QACAC;QACAC;QACAC;KACH;AACL"}
@@ -1,12 +1,12 @@
1
1
  import { Result } from "@webiny/feature/api";
2
2
  import { DeleteFolderRepository as RepositoryAbstraction, type IDeleteFolderRepository } from "./abstractions.js";
3
3
  import { DeleteEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/DeleteEntry";
4
- import { FolderModel } from "../../../domain/folder/abstractions.js";
4
+ import { FolderModelProvider } from "../../../domain/folder/abstractions.js";
5
5
  import type { Folder } from "../../../folder/folder.types.js";
6
6
  declare class DeleteFolderRepositoryImpl implements IDeleteFolderRepository {
7
7
  private deleteEntry;
8
- private folderModel;
9
- constructor(deleteEntry: DeleteEntryUseCase.Interface, folderModel: FolderModel.Interface);
8
+ private folderModelProvider;
9
+ constructor(deleteEntry: DeleteEntryUseCase.Interface, folderModelProvider: FolderModelProvider.Interface);
10
10
  execute(folder: Folder): Promise<Result<void, RepositoryAbstraction.Error>>;
11
11
  }
12
12
  export declare const DeleteFolderRepository: typeof DeleteFolderRepositoryImpl & {
@@ -1,15 +1,16 @@
1
1
  import { Result } from "@webiny/feature/api";
2
2
  import { DeleteFolderRepository } from "./abstractions.js";
3
3
  import { DeleteEntryUseCase } from "@webiny/api-headless-cms/features/contentEntry/DeleteEntry";
4
- import { FolderModel } from "../../../domain/folder/abstractions.js";
4
+ import { FolderModelProvider } from "../../../domain/folder/abstractions.js";
5
5
  import { FolderNotAuthorizedError, FolderPersistenceError } from "../../../domain/folder/errors.js";
6
6
  class DeleteFolderRepositoryImpl {
7
- constructor(deleteEntry, folderModel){
7
+ constructor(deleteEntry, folderModelProvider){
8
8
  this.deleteEntry = deleteEntry;
9
- this.folderModel = folderModel;
9
+ this.folderModelProvider = folderModelProvider;
10
10
  }
11
11
  async execute(folder) {
12
- const result = await this.deleteEntry.execute(this.folderModel, folder.id, {
12
+ const folderModel = await this.folderModelProvider.get();
13
+ const result = await this.deleteEntry.execute(folderModel, folder.id, {
13
14
  permanently: true,
14
15
  force: true
15
16
  });
@@ -24,7 +25,7 @@ const DeleteFolderRepository_DeleteFolderRepository = DeleteFolderRepository.cre
24
25
  implementation: DeleteFolderRepositoryImpl,
25
26
  dependencies: [
26
27
  DeleteEntryUseCase,
27
- FolderModel
28
+ FolderModelProvider
28
29
  ]
29
30
  });
30
31
  export { DeleteFolderRepository_DeleteFolderRepository as DeleteFolderRepository };
@@ -1 +1 @@
1
- {"version":3,"file":"features/folder/DeleteFolder/DeleteFolderRepository.js","sources":["../../../../src/features/folder/DeleteFolder/DeleteFolderRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n DeleteFolderRepository as RepositoryAbstraction,\n type IDeleteFolderRepository\n} from \"./abstractions.js\";\nimport { DeleteEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/DeleteEntry\";\nimport { FolderModel } from \"~/domain/folder/abstractions.js\";\nimport type { Folder } from \"~/folder/folder.types.js\";\nimport { FolderNotAuthorizedError, FolderPersistenceError } from \"~/domain/folder/errors.js\";\n\nclass DeleteFolderRepositoryImpl implements IDeleteFolderRepository {\n constructor(\n private deleteEntry: DeleteEntryUseCase.Interface,\n private folderModel: FolderModel.Interface\n ) {}\n\n async execute(folder: Folder): Promise<Result<void, RepositoryAbstraction.Error>> {\n const result = await this.deleteEntry.execute(this.folderModel, folder.id, {\n permanently: true,\n force: true\n });\n\n if (result.isFail()) {\n if (result.error.code === \"Cms/Entry/NotAuthorized\") {\n return Result.fail(new FolderNotAuthorizedError());\n }\n return Result.fail(new FolderPersistenceError(result.error));\n }\n\n return Result.ok();\n }\n}\n\nexport const DeleteFolderRepository = RepositoryAbstraction.createImplementation({\n implementation: DeleteFolderRepositoryImpl,\n dependencies: [DeleteEntryUseCase, FolderModel]\n});\n"],"names":["DeleteFolderRepositoryImpl","deleteEntry","folderModel","folder","result","Result","FolderNotAuthorizedError","FolderPersistenceError","DeleteFolderRepository","RepositoryAbstraction","DeleteEntryUseCase","FolderModel"],"mappings":";;;;;AAUA,MAAMA;IACF,YACYC,WAAyC,EACzCC,WAAkC,CAC5C;aAFUD,WAAW,GAAXA;aACAC,WAAW,GAAXA;IACT;IAEH,MAAM,QAAQC,MAAc,EAAsD;QAC9E,MAAMC,SAAS,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,EAAED,OAAO,EAAE,EAAE;YACvE,aAAa;YACb,OAAO;QACX;QAEA,IAAIC,OAAO,MAAM,IAAI;YACjB,IAAIA,AAAsB,8BAAtBA,OAAO,KAAK,CAAC,IAAI,EACjB,OAAOC,OAAO,IAAI,CAAC,IAAIC;YAE3B,OAAOD,OAAO,IAAI,CAAC,IAAIE,uBAAuBH,OAAO,KAAK;QAC9D;QAEA,OAAOC,OAAO,EAAE;IACpB;AACJ;AAEO,MAAMG,gDAAyBC,uBAAAA,oBAA0C,CAAC;IAC7E,gBAAgBT;IAChB,cAAc;QAACU;QAAoBC;KAAY;AACnD"}
1
+ {"version":3,"file":"features/folder/DeleteFolder/DeleteFolderRepository.js","sources":["../../../../src/features/folder/DeleteFolder/DeleteFolderRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n DeleteFolderRepository as RepositoryAbstraction,\n type IDeleteFolderRepository\n} from \"./abstractions.js\";\nimport { DeleteEntryUseCase } from \"@webiny/api-headless-cms/features/contentEntry/DeleteEntry\";\nimport { FolderModelProvider } from \"~/domain/folder/abstractions.js\";\nimport type { Folder } from \"~/folder/folder.types.js\";\nimport { FolderNotAuthorizedError, FolderPersistenceError } from \"~/domain/folder/errors.js\";\n\nclass DeleteFolderRepositoryImpl implements IDeleteFolderRepository {\n constructor(\n private deleteEntry: DeleteEntryUseCase.Interface,\n private folderModelProvider: FolderModelProvider.Interface\n ) {}\n\n async execute(folder: Folder): Promise<Result<void, RepositoryAbstraction.Error>> {\n const folderModel = await this.folderModelProvider.get();\n const result = await this.deleteEntry.execute(folderModel, folder.id, {\n permanently: true,\n force: true\n });\n\n if (result.isFail()) {\n if (result.error.code === \"Cms/Entry/NotAuthorized\") {\n return Result.fail(new FolderNotAuthorizedError());\n }\n return Result.fail(new FolderPersistenceError(result.error));\n }\n\n return Result.ok();\n }\n}\n\nexport const DeleteFolderRepository = RepositoryAbstraction.createImplementation({\n implementation: DeleteFolderRepositoryImpl,\n dependencies: [DeleteEntryUseCase, FolderModelProvider]\n});\n"],"names":["DeleteFolderRepositoryImpl","deleteEntry","folderModelProvider","folder","folderModel","result","Result","FolderNotAuthorizedError","FolderPersistenceError","DeleteFolderRepository","RepositoryAbstraction","DeleteEntryUseCase","FolderModelProvider"],"mappings":";;;;;AAUA,MAAMA;IACF,YACYC,WAAyC,EACzCC,mBAAkD,CAC5D;aAFUD,WAAW,GAAXA;aACAC,mBAAmB,GAAnBA;IACT;IAEH,MAAM,QAAQC,MAAc,EAAsD;QAC9E,MAAMC,cAAc,MAAM,IAAI,CAAC,mBAAmB,CAAC,GAAG;QACtD,MAAMC,SAAS,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAACD,aAAaD,OAAO,EAAE,EAAE;YAClE,aAAa;YACb,OAAO;QACX;QAEA,IAAIE,OAAO,MAAM,IAAI;YACjB,IAAIA,AAAsB,8BAAtBA,OAAO,KAAK,CAAC,IAAI,EACjB,OAAOC,OAAO,IAAI,CAAC,IAAIC;YAE3B,OAAOD,OAAO,IAAI,CAAC,IAAIE,uBAAuBH,OAAO,KAAK;QAC9D;QAEA,OAAOC,OAAO,EAAE;IACpB;AACJ;AAEO,MAAMG,gDAAyBC,uBAAAA,oBAA0C,CAAC;IAC7E,gBAAgBV;IAChB,cAAc;QAACW;QAAoBC;KAAoB;AAC3D"}
@@ -5,7 +5,7 @@ declare class DeleteFolderWithFolderLevelPermissionsImpl implements DeleteFolder
5
5
  private folderLevelPermissions;
6
6
  private readonly decoretee;
7
7
  constructor(folderLevelPermissions: FolderLevelPermissions.Interface, decoretee: DeleteFolderUseCase.Interface);
8
- execute(id: string): Promise<Result<void, never> | Result<never, import("../../../../domain/folder/errors.js").FolderNotFoundError | import("../../../../domain/folder/errors.js").FolderNotAuthorizedError | import("../../../../domain/folder/errors.js").FolderPersistenceError | import("../../../../domain/folder/errors.js").FolderNotEmptyError>>;
8
+ execute(id: string): Promise<Result<void, never> | Result<never, import("../../../../domain/folder/errors.js").FolderNotAuthorizedError | import("../../../../domain/folder/errors.js").FolderNotEmptyError | import("../../../../domain/folder/errors.js").FolderNotFoundError | import("../../../../domain/folder/errors.js").FolderPersistenceError>>;
9
9
  }
10
10
  export declare const DeleteFolderWithFolderLevelPermissions: typeof DeleteFolderWithFolderLevelPermissionsImpl;
11
11
  export {};
@@ -1,14 +1,12 @@
1
1
  import { FolderLevelPermissions } from "../../../features/flp/FolderLevelPermissions/index.js";
2
2
  import { ListFoldersUseCase } from "../../../features/folder/ListFolders/index.js";
3
3
  import { EnsureFolderIsEmpty as Abstraction } from "../../../features/folder/EnsureFolderIsEmpty/abstractions.js";
4
- import { Logger } from "@webiny/api-core/exports/api/logger.js";
5
4
  import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
6
5
  declare class EnsureFolderIsEmptyImpl implements Abstraction.Interface {
7
6
  private identityContext;
8
7
  private folderLevelPermissions;
9
8
  private listFoldersUseCase;
10
- private logger;
11
- constructor(identityContext: IdentityContext.Interface, folderLevelPermissions: FolderLevelPermissions.Interface, listFoldersUseCase: ListFoldersUseCase.Interface, logger: Logger.Interface);
9
+ constructor(identityContext: IdentityContext.Interface, folderLevelPermissions: FolderLevelPermissions.Interface, listFoldersUseCase: ListFoldersUseCase.Interface);
12
10
  execute(type: string, id: string, hasContentCallback: Abstraction.HasContentCallback): Abstraction.Return;
13
11
  }
14
12
  export declare const EnsureFolderIsEmpty: typeof EnsureFolderIsEmptyImpl & {
@@ -1,16 +1,14 @@
1
1
  import { FolderLevelPermissions } from "../../flp/FolderLevelPermissions/index.js";
2
2
  import { ListFoldersUseCase } from "../ListFolders/index.js";
3
3
  import { EnsureFolderIsEmpty } from "./abstractions.js";
4
- import { Logger } from "@webiny/api-core/exports/api/logger.js";
5
4
  import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
6
5
  import { FolderNotAuthorizedError, FolderNotEmptyError } from "../../../domain/folder/errors.js";
7
6
  import { Result } from "@webiny/feature/api";
8
7
  class EnsureFolderIsEmptyImpl {
9
- constructor(identityContext, folderLevelPermissions, listFoldersUseCase, logger){
8
+ constructor(identityContext, folderLevelPermissions, listFoldersUseCase){
10
9
  this.identityContext = identityContext;
11
10
  this.folderLevelPermissions = folderLevelPermissions;
12
11
  this.listFoldersUseCase = listFoldersUseCase;
13
- this.logger = logger;
14
12
  }
15
13
  async execute(type, id, hasContentCallback) {
16
14
  const hasFoldersCallback = async ()=>{
@@ -22,8 +20,8 @@ class EnsureFolderIsEmptyImpl {
22
20
  limit: 1
23
21
  });
24
22
  if (result.isFail()) {
25
- this.logger.error(result.error);
26
- return false;
23
+ console.error(result.error.message);
24
+ return true;
27
25
  }
28
26
  const { folders } = result.value;
29
27
  return folders.length > 0;
@@ -53,8 +51,7 @@ const EnsureFolderIsEmpty_EnsureFolderIsEmpty = EnsureFolderIsEmpty.createImplem
53
51
  dependencies: [
54
52
  IdentityContext,
55
53
  FolderLevelPermissions,
56
- ListFoldersUseCase,
57
- Logger
54
+ ListFoldersUseCase
58
55
  ]
59
56
  });
60
57
  export { EnsureFolderIsEmpty_EnsureFolderIsEmpty as EnsureFolderIsEmpty };