@webiny/api-aco 6.6.0-alpha.10 → 6.6.0-alpha.11

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 (44) hide show
  1. package/features/ai/CreateRoleTool.d.ts +54 -0
  2. package/features/ai/CreateRoleTool.js +71 -0
  3. package/features/ai/CreateRoleTool.js.map +1 -0
  4. package/features/ai/DeleteRoleTool.d.ts +52 -0
  5. package/features/ai/DeleteRoleTool.js +79 -0
  6. package/features/ai/DeleteRoleTool.js.map +1 -0
  7. package/features/ai/DeleteTeamTool.d.ts +46 -0
  8. package/features/ai/DeleteTeamTool.js +56 -0
  9. package/features/ai/DeleteTeamTool.js.map +1 -0
  10. package/features/ai/ListRolesTool.d.ts +1 -1
  11. package/features/ai/ListRolesTool.js +1 -1
  12. package/features/ai/ListRolesTool.js.map +1 -1
  13. package/features/ai/ListTeamsTool.d.ts +3 -1
  14. package/features/ai/ListTeamsTool.js +3 -2
  15. package/features/ai/ListTeamsTool.js.map +1 -1
  16. package/features/ai/UpdateFolderTool.d.ts +57 -0
  17. package/features/ai/UpdateFolderTool.js +72 -0
  18. package/features/ai/UpdateFolderTool.js.map +1 -0
  19. package/features/ai/UpdateRoleTool.d.ts +46 -0
  20. package/features/ai/UpdateRoleTool.js +53 -0
  21. package/features/ai/UpdateRoleTool.js.map +1 -0
  22. package/features/ai/UpdateTeamTool.d.ts +52 -0
  23. package/features/ai/UpdateTeamTool.js +56 -0
  24. package/features/ai/UpdateTeamTool.js.map +1 -0
  25. package/features/ai/feature.d.ts +2 -2
  26. package/features/ai/feature.js +12 -0
  27. package/features/ai/feature.js.map +1 -1
  28. package/features/ai/index.d.ts +6 -0
  29. package/features/ai/index.js +6 -0
  30. package/features/ai/loadFolderPermissions.d.ts +4 -1
  31. package/features/ai/loadFolderPermissions.js +1 -1
  32. package/features/ai/loadFolderPermissions.js.map +1 -1
  33. package/features/folder/NotifyFolderChange/NotifyFolderChangeUseCase.d.ts +1 -1
  34. package/features/folder/NotifyFolderChange/NotifyFolderChangeUseCase.js +1 -1
  35. package/features/folder/NotifyFolderChange/NotifyFolderChangeUseCase.js.map +1 -1
  36. package/features/folder/UpdateFolder/UpdateFolderUseCase.d.ts +1 -0
  37. package/features/folder/UpdateFolder/UpdateFolderUseCase.js +13 -0
  38. package/features/folder/UpdateFolder/UpdateFolderUseCase.js.map +1 -1
  39. package/features/folder/UpdateFolder/decorators/UpdateFolderWithFolderLevelPermissions.js +4 -2
  40. package/features/folder/UpdateFolder/decorators/UpdateFolderWithFolderLevelPermissions.js.map +1 -1
  41. package/flpTaskCatalog/tasks/syncFlp.task.js +20 -13
  42. package/flpTaskCatalog/tasks/syncFlp.task.js.map +1 -1
  43. package/folder/folder.types.d.ts +2 -1
  44. package/package.json +18 -19
@@ -1 +1 @@
1
- {"version":3,"file":"features/folder/UpdateFolder/decorators/UpdateFolderWithFolderLevelPermissions.js","sources":["../../../../../src/features/folder/UpdateFolder/decorators/UpdateFolderWithFolderLevelPermissions.ts"],"sourcesContent":["import { createDecorator, Result } from \"@webiny/feature/api\";\nimport type { Folder } from \"~/folder/folder.types.js\";\nimport type { UpdateFolderParams } from \"~/folder/folder.types.js\";\nimport type { FolderPermission } from \"~/flp/flp.types.js\";\nimport { FolderLevelPermissions } from \"~/features/flp/FolderLevelPermissions/index.js\";\nimport { UpdateFolderUseCase } from \"../abstractions.js\";\nimport { GetFolderUseCase } from \"~/features/folder/GetFolder/index.js\";\nimport { FolderCannotMoveToNewParent, FolderValidationError } from \"~/domain/folder/errors.js\";\nimport { CodeFlpMerger } from \"~/features/flp/shared/index.js\";\nimport { CodeFlpsProvider } from \"~/features/flp/shared/index.js\";\nimport { Path } from \"~/utils/Path.js\";\n\nclass UpdateFolderWithFolderLevelPermissionsImpl implements UpdateFolderUseCase.Interface {\n private folderLevelPermissions: FolderLevelPermissions.Interface;\n private readonly decoretee: UpdateFolderUseCase.Interface;\n private readonly codeFlpsProvider?: CodeFlpsProvider.Interface;\n\n constructor(\n private getFolder: GetFolderUseCase.Interface,\n folderLevelPermissions: FolderLevelPermissions.Interface,\n codeFlpsProvider: CodeFlpsProvider.Interface | undefined,\n decoretee: UpdateFolderUseCase.Interface\n ) {\n this.folderLevelPermissions = folderLevelPermissions;\n this.codeFlpsProvider = codeFlpsProvider;\n this.decoretee = decoretee;\n }\n\n async execute(id: string, params: UpdateFolderParams): UpdateFolderUseCase.Return {\n const originalResult = await this.getFolder.execute(id);\n\n if (originalResult.isFail()) {\n return Result.fail(originalResult.error);\n }\n\n const original = originalResult.value;\n\n const originalPermissions = await this.folderLevelPermissions.getFolderLevelPermissions(id);\n\n // Let's ensure current identity's permission allows the update operation.\n await this.folderLevelPermissions.ensureCanAccessFolder({\n permissions: originalPermissions,\n rwd: \"w\"\n });\n\n // The guard below asks whether the user keeps access once the update is saved. A new slug or\n // a new parent changes the path, and code-defined rules match on the path, so resolve them\n // against where the folder is going rather than where it is now.\n const targetFolder = await this.getTargetFolder(original, params);\n\n const submittedPermissions = await this.withCodePermissions(\n targetFolder,\n params.permissions ?? []\n );\n\n const permissions =\n await this.folderLevelPermissions.getDefaultPermissions(submittedPermissions);\n\n // Check if the user still has access to the folder with the provided permissions.\n const stillHasAccess = await this.folderLevelPermissions.canAccessFolder({\n permissions,\n rwd: \"w\"\n });\n\n if (!stillHasAccess) {\n return Result.fail(\n new FolderValidationError(\n `Cannot continue because you would loose access to this folder.`\n )\n );\n }\n\n // Validate data.\n if (Array.isArray(params.permissions)) {\n for (const permission of params.permissions) {\n const targetIsValid =\n permission.target.startsWith(\"admin:\") || permission.target.startsWith(\"team:\");\n if (!targetIsValid) {\n return Result.fail(\n new FolderValidationError(\n `Permission target \"${permission.target}\" is not valid.`\n )\n );\n }\n\n if (permission.inheritedFrom) {\n return Result.fail(\n new FolderValidationError(\n `Permission \"inheritedFrom\" cannot be set manually.`\n )\n );\n }\n\n if (permission.plugin) {\n return Result.fail(\n new FolderValidationError(\n `Permission \"plugin\" cannot be set manually. Code-defined permissions are managed via an \"FlpFactory\".`\n )\n );\n }\n }\n }\n\n // Parent change is not allowed if the user doesn't have access to the new parent.\n if (params.parentId && params.parentId !== original.parentId) {\n // Getting the parent folder permissions will throw an error if the user doesn't have access.\n const parentPermissions = await this.folderLevelPermissions.getFolderLevelPermissions(\n params.parentId\n );\n\n const canAccessFolder = await this.folderLevelPermissions.canAccessFolder({\n permissions: parentPermissions,\n rwd: \"w\"\n });\n\n if (!canAccessFolder) {\n return Result.fail(new FolderCannotMoveToNewParent());\n }\n }\n\n const result = await this.decoretee.execute(id, params);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n // Resolved again against the updated folder: a rename or a move changes the path, and with\n // it which code-defined rules apply.\n const updatedPermissions = await this.withCodePermissions(\n result.value,\n params.permissions ?? []\n );\n\n const updatedPermissionsWithDefaults =\n await this.folderLevelPermissions.getDefaultPermissions(updatedPermissions);\n\n return Result.ok({\n ...result.value,\n permissions: updatedPermissionsWithDefaults\n });\n }\n\n /**\n * The type and path the folder will have after this update, computed the same way\n * `UpdateFolderRepository` computes them: the submitted slug and parent, falling back to the\n * current ones.\n */\n private async getTargetFolder(\n original: Folder,\n params: UpdateFolderParams\n ): Promise<Pick<Folder, \"type\" | \"path\">> {\n const slug = params.slug || original.slug;\n const parentId = params.parentId !== undefined ? params.parentId : original.parentId;\n\n // Same parent: only the last segment of the path can change, so it is derived from the\n // current path. This avoids reading the parent, which the user may not have access to.\n if (parentId === original.parentId) {\n const parentPath = original.path.slice(0, -(original.slug.length + 1));\n const path = Path.create(slug, parentPath);\n\n return { type: original.type, path };\n }\n\n if (!parentId) {\n const path = Path.create(slug);\n\n return { type: original.type, path };\n }\n\n // A move. If the destination cannot be read, keep the current path: the parent check further\n // down rejects the move with its own error.\n const parentResult = await this.getFolder.execute(parentId);\n if (parentResult.isFail()) {\n return original;\n }\n\n const path = Path.create(slug, parentResult.value.path);\n\n return { type: original.type, path };\n }\n\n /**\n * Code-defined permissions are resolved from the folder's own type and path rather than the FLP\n * catalog, so they apply even when the stored record is missing or not yet written.\n */\n private async withCodePermissions(\n folder: Pick<Folder, \"type\" | \"path\">,\n permissions: FolderPermission[]\n ): Promise<FolderPermission[]> {\n if (!this.codeFlpsProvider) {\n return permissions;\n }\n\n const codePermissions = await this.codeFlpsProvider.getPermissions({\n type: folder.type,\n path: folder.path\n });\n\n return CodeFlpMerger.mergePermissions(permissions, codePermissions);\n }\n}\n\nexport const UpdateFolderWithFolderLevelPermissions = createDecorator({\n abstraction: UpdateFolderUseCase,\n decorator: UpdateFolderWithFolderLevelPermissionsImpl,\n // `CodeFlpsProvider` is optional: `CodeFlpsFeature` does not register it unless the project has\n // the folder-level permissions entitlement.\n dependencies: [GetFolderUseCase, FolderLevelPermissions, [CodeFlpsProvider, { optional: true }]]\n});\n"],"names":["UpdateFolderWithFolderLevelPermissionsImpl","getFolder","folderLevelPermissions","codeFlpsProvider","decoretee","id","params","originalResult","Result","original","originalPermissions","targetFolder","submittedPermissions","permissions","stillHasAccess","FolderValidationError","Array","permission","targetIsValid","parentPermissions","canAccessFolder","FolderCannotMoveToNewParent","result","updatedPermissions","updatedPermissionsWithDefaults","slug","parentId","undefined","parentPath","path","Path","parentResult","folder","codePermissions","CodeFlpMerger","UpdateFolderWithFolderLevelPermissions","createDecorator","UpdateFolderUseCase","GetFolderUseCase","FolderLevelPermissions","CodeFlpsProvider"],"mappings":";;;;;;;AAYA,MAAMA;IAKF,YACYC,SAAqC,EAC7CC,sBAAwD,EACxDC,gBAAwD,EACxDC,SAAwC,CAC1C;aAJUH,SAAS,GAATA;QAKR,IAAI,CAAC,sBAAsB,GAAGC;QAC9B,IAAI,CAAC,gBAAgB,GAAGC;QACxB,IAAI,CAAC,SAAS,GAAGC;IACrB;IAEA,MAAM,QAAQC,EAAU,EAAEC,MAA0B,EAA8B;QAC9E,MAAMC,iBAAiB,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAACF;QAEpD,IAAIE,eAAe,MAAM,IACrB,OAA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AI;QAEtD,OAAO;YAAE,MAAMtB,SAAS,IAAI;YAAEoB;QAAK;IACvC;IAMA,MAAc,oBACVG,MAAqC,EACrCnB,WAA+B,EACJ;QAC3B,IAAI,CAAC,IAAI,CAAC,gBAAgB,EACtB,OAAOA;QAGX,MAAMoB,kBAAkB,MAAM,IAAI,CAAC,gBAAgB,CAAC,cAAc,CAAC;YAC/D,MAAMD,OAAO,IAAI;YACjB,MAAMA,OAAO,IAAI;QACrB;QAEA,OAAOE,cAAc,gBAAgB,CAACrB,aAAaoB;IACvD;AACJ;AAEO,MAAME,yCAAyCC,gBAAgB;IAClE,aAAaC;IACb,WAAWrC;IAGX,cAAc;QAACsC;QAAkBC;QAAwB;YAACC;YAAkB;gBAAE,UAAU;YAAK;SAAE;KAAC;AACpG"}
1
+ {"version":3,"file":"features/folder/UpdateFolder/decorators/UpdateFolderWithFolderLevelPermissions.js","sources":["../../../../../src/features/folder/UpdateFolder/decorators/UpdateFolderWithFolderLevelPermissions.ts"],"sourcesContent":["import { createDecorator, Result } from \"@webiny/feature/api\";\nimport type { Folder } from \"~/folder/folder.types.js\";\nimport type { UpdateFolderParams } from \"~/folder/folder.types.js\";\nimport type { FolderPermission } from \"~/flp/flp.types.js\";\nimport { FolderLevelPermissions } from \"~/features/flp/FolderLevelPermissions/index.js\";\nimport { UpdateFolderUseCase } from \"../abstractions.js\";\nimport { GetFolderUseCase } from \"~/features/folder/GetFolder/index.js\";\nimport { FolderCannotMoveToNewParent, FolderValidationError } from \"~/domain/folder/errors.js\";\nimport { CodeFlpMerger } from \"~/features/flp/shared/index.js\";\nimport { CodeFlpsProvider } from \"~/features/flp/shared/index.js\";\nimport { Path } from \"~/utils/Path.js\";\n\n/**\n * The rules set on the folder itself. Inherited and code-defined rules are added on read, and the\n * update refuses either kind when it is submitted.\n */\nconst getOwnPermissions = (folder: Folder): FolderPermission[] => {\n return (folder.permissions ?? []).filter(\n permission => !permission.inheritedFrom && !permission.plugin\n );\n};\n\nclass UpdateFolderWithFolderLevelPermissionsImpl implements UpdateFolderUseCase.Interface {\n private folderLevelPermissions: FolderLevelPermissions.Interface;\n private readonly decoretee: UpdateFolderUseCase.Interface;\n private readonly codeFlpsProvider?: CodeFlpsProvider.Interface;\n\n constructor(\n private getFolder: GetFolderUseCase.Interface,\n folderLevelPermissions: FolderLevelPermissions.Interface,\n codeFlpsProvider: CodeFlpsProvider.Interface | undefined,\n decoretee: UpdateFolderUseCase.Interface\n ) {\n this.folderLevelPermissions = folderLevelPermissions;\n this.codeFlpsProvider = codeFlpsProvider;\n this.decoretee = decoretee;\n }\n\n async execute(id: string, params: UpdateFolderParams): UpdateFolderUseCase.Return {\n const originalResult = await this.getFolder.execute(id);\n\n if (originalResult.isFail()) {\n return Result.fail(originalResult.error);\n }\n\n const original = originalResult.value;\n\n const originalPermissions = await this.folderLevelPermissions.getFolderLevelPermissions(id);\n\n // Let's ensure current identity's permission allows the update operation.\n await this.folderLevelPermissions.ensureCanAccessFolder({\n permissions: originalPermissions,\n rwd: \"w\"\n });\n\n // An update without `permissions` leaves the stored rules in place, so the check and the\n // returned folder use those, not an empty list.\n const ownPermissions = params.permissions ?? getOwnPermissions(original);\n\n // The guard below asks whether the user keeps access once the update is saved. A new slug or\n // a new parent changes the path, and code-defined rules match on the path, so resolve them\n // against where the folder is going rather than where it is now.\n const targetFolder = await this.getTargetFolder(original, params);\n\n const submittedPermissions = await this.withCodePermissions(targetFolder, ownPermissions);\n\n const permissions =\n await this.folderLevelPermissions.getDefaultPermissions(submittedPermissions);\n\n // Check if the user still has access to the folder with the provided permissions.\n const stillHasAccess = await this.folderLevelPermissions.canAccessFolder({\n permissions,\n rwd: \"w\"\n });\n\n if (!stillHasAccess) {\n return Result.fail(\n new FolderValidationError(\n `Cannot continue because you would loose access to this folder.`\n )\n );\n }\n\n // Validate data.\n if (Array.isArray(params.permissions)) {\n for (const permission of params.permissions) {\n const targetIsValid =\n permission.target.startsWith(\"admin:\") || permission.target.startsWith(\"team:\");\n if (!targetIsValid) {\n return Result.fail(\n new FolderValidationError(\n `Permission target \"${permission.target}\" is not valid.`\n )\n );\n }\n\n if (permission.inheritedFrom) {\n return Result.fail(\n new FolderValidationError(\n `Permission \"inheritedFrom\" cannot be set manually.`\n )\n );\n }\n\n if (permission.plugin) {\n return Result.fail(\n new FolderValidationError(\n `Permission \"plugin\" cannot be set manually. Code-defined permissions are managed via an \"FlpFactory\".`\n )\n );\n }\n }\n }\n\n // Parent change is not allowed if the user doesn't have access to the new parent.\n if (params.parentId && params.parentId !== original.parentId) {\n // Getting the parent folder permissions will throw an error if the user doesn't have access.\n const parentPermissions = await this.folderLevelPermissions.getFolderLevelPermissions(\n params.parentId\n );\n\n const canAccessFolder = await this.folderLevelPermissions.canAccessFolder({\n permissions: parentPermissions,\n rwd: \"w\"\n });\n\n if (!canAccessFolder) {\n return Result.fail(new FolderCannotMoveToNewParent());\n }\n }\n\n const result = await this.decoretee.execute(id, params);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n // Resolved again against the updated folder: a rename or a move changes the path, and with\n // it which code-defined rules apply.\n const updatedPermissions = await this.withCodePermissions(result.value, ownPermissions);\n\n const updatedPermissionsWithDefaults =\n await this.folderLevelPermissions.getDefaultPermissions(updatedPermissions);\n\n return Result.ok({\n ...result.value,\n permissions: updatedPermissionsWithDefaults\n });\n }\n\n /**\n * The type and path the folder will have after this update, computed the same way\n * `UpdateFolderRepository` computes them: the submitted slug and parent, falling back to the\n * current ones.\n */\n private async getTargetFolder(\n original: Folder,\n params: UpdateFolderParams\n ): Promise<Pick<Folder, \"type\" | \"path\">> {\n const slug = params.slug || original.slug;\n const parentId = params.parentId !== undefined ? params.parentId : original.parentId;\n\n // Same parent: only the last segment of the path can change, so it is derived from the\n // current path. This avoids reading the parent, which the user may not have access to.\n if (parentId === original.parentId) {\n const parentPath = original.path.slice(0, -(original.slug.length + 1));\n const path = Path.create(slug, parentPath);\n\n return { type: original.type, path };\n }\n\n if (!parentId) {\n const path = Path.create(slug);\n\n return { type: original.type, path };\n }\n\n // A move. If the destination cannot be read, keep the current path: the parent check further\n // down rejects the move with its own error.\n const parentResult = await this.getFolder.execute(parentId);\n if (parentResult.isFail()) {\n return original;\n }\n\n const path = Path.create(slug, parentResult.value.path);\n\n return { type: original.type, path };\n }\n\n /**\n * Code-defined permissions are resolved from the folder's own type and path rather than the FLP\n * catalog, so they apply even when the stored record is missing or not yet written.\n */\n private async withCodePermissions(\n folder: Pick<Folder, \"type\" | \"path\">,\n permissions: FolderPermission[]\n ): Promise<FolderPermission[]> {\n if (!this.codeFlpsProvider) {\n return permissions;\n }\n\n const codePermissions = await this.codeFlpsProvider.getPermissions({\n type: folder.type,\n path: folder.path\n });\n\n return CodeFlpMerger.mergePermissions(permissions, codePermissions);\n }\n}\n\nexport const UpdateFolderWithFolderLevelPermissions = createDecorator({\n abstraction: UpdateFolderUseCase,\n decorator: UpdateFolderWithFolderLevelPermissionsImpl,\n // `CodeFlpsProvider` is optional: `CodeFlpsFeature` does not register it unless the project has\n // the folder-level permissions entitlement.\n dependencies: [GetFolderUseCase, FolderLevelPermissions, [CodeFlpsProvider, { optional: true }]]\n});\n"],"names":["getOwnPermissions","folder","permission","UpdateFolderWithFolderLevelPermissionsImpl","getFolder","folderLevelPermissions","codeFlpsProvider","decoretee","id","params","originalResult","Result","original","originalPermissions","ownPermissions","targetFolder","submittedPermissions","permissions","stillHasAccess","FolderValidationError","Array","targetIsValid","parentPermissions","canAccessFolder","FolderCannotMoveToNewParent","result","updatedPermissions","updatedPermissionsWithDefaults","slug","parentId","undefined","parentPath","path","Path","parentResult","codePermissions","CodeFlpMerger","UpdateFolderWithFolderLevelPermissions","createDecorator","UpdateFolderUseCase","GetFolderUseCase","FolderLevelPermissions","CodeFlpsProvider"],"mappings":";;;;;;;AAgBA,MAAMA,oBAAoB,CAACC,SACfA,AAAAA,CAAAA,OAAO,WAAW,IAAI,EAAC,EAAG,MAAM,CACpCC,CAAAA,aAAc,CAACA,WAAW,aAAa,IAAI,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MoB,OAAOC,KAAK,MAAM,CAACL,MAAMG;YAE/B,OAAO;gBAAE,MAAMnB,SAAS,IAAI;gBAAEoB;YAAK;QACvC;QAEA,IAAI,CAACH,UAAU;YACX,MAAMG,OAAOC,KAAK,MAAM,CAACL;YAEzB,OAAO;gBAAE,MAAMhB,SAAS,IAAI;gBAAEoB;YAAK;QACvC;QAIA,MAAME,eAAe,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAACL;QAClD,IAAIK,aAAa,MAAM,IACnB,OAAOtB;QAGX,MAAMoB,OAAOC,KAAK,MAAM,CAACL,MAAMM,aAAa,KAAK,CAAC,IAAI;QAEtD,OAAO;YAAE,MAAMtB,SAAS,IAAI;YAAEoB;QAAK;IACvC;IAMA,MAAc,oBACV/B,MAAqC,EACrCgB,WAA+B,EACJ;QAC3B,IAAI,CAAC,IAAI,CAAC,gBAAgB,EACtB,OAAOA;QAGX,MAAMkB,kBAAkB,MAAM,IAAI,CAAC,gBAAgB,CAAC,cAAc,CAAC;YAC/D,MAAMlC,OAAO,IAAI;YACjB,MAAMA,OAAO,IAAI;QACrB;QAEA,OAAOmC,cAAc,gBAAgB,CAACnB,aAAakB;IACvD;AACJ;AAEO,MAAME,yCAAyCC,gBAAgB;IAClE,aAAaC;IACb,WAAWpC;IAGX,cAAc;QAACqC;QAAkBC;QAAwB;YAACC;YAAkB;gBAAE,UAAU;YAAK;SAAE;KAAC;AACpG"}
@@ -17,12 +17,13 @@ class SyncFlpTaskHandlerImpl {
17
17
  const result = await this.getFolder.execute(input.folderId);
18
18
  if (result.isFail()) return controller.response.error(result.error);
19
19
  const folder = result.value;
20
- await controller.task.trigger({
20
+ const triggered = await controller.task.trigger({
21
21
  definition: UPDATE_FLP_TASK_ID,
22
22
  input: {
23
23
  folder
24
24
  }
25
25
  });
26
+ if (triggered.isFail()) return controller.response.error(triggered.error);
26
27
  return controller.response.done(`Task completed successfully: all FLP records for folderId "${input.folderId}" and its children have been queued to be synchronized.`);
27
28
  }
28
29
  if (input.type && "*" === input.type) {
@@ -52,12 +53,15 @@ class SyncFlpTaskHandlerImpl {
52
53
  continue;
53
54
  }
54
55
  const { folders } = result.value;
55
- for (const folder of folders)await controller.task.trigger({
56
- definition: UPDATE_FLP_TASK_ID,
57
- input: {
58
- folder
59
- }
60
- });
56
+ for (const folder of folders){
57
+ const triggered = await controller.task.trigger({
58
+ definition: UPDATE_FLP_TASK_ID,
59
+ input: {
60
+ folder
61
+ }
62
+ });
63
+ if (triggered.isFail()) return controller.response.error(triggered.error);
64
+ }
61
65
  await controller.logger.info({
62
66
  message: `FLP Update task triggered for type ${folderType}`,
63
67
  data: {
@@ -76,12 +80,15 @@ class SyncFlpTaskHandlerImpl {
76
80
  });
77
81
  if (result.isFail()) return controller.response.error(result.error);
78
82
  const { folders } = result.value;
79
- for (const folder of folders)await controller.task.trigger({
80
- definition: UPDATE_FLP_TASK_ID,
81
- input: {
82
- folder
83
- }
84
- });
83
+ for (const folder of folders){
84
+ const triggered = await controller.task.trigger({
85
+ definition: UPDATE_FLP_TASK_ID,
86
+ input: {
87
+ folder
88
+ }
89
+ });
90
+ if (triggered.isFail()) return controller.response.error(triggered.error);
91
+ }
85
92
  return controller.response.done(`Task completed successfully: all FLP records for type "${input.type}" have been queued to be synchronized.`);
86
93
  }
87
94
  return controller.response.error("Invalid input: please provide either `type` or `folderId`.");
@@ -1 +1 @@
1
- {"version":3,"file":"flpTaskCatalog/tasks/syncFlp.task.js","sources":["../../../src/flpTaskCatalog/tasks/syncFlp.task.ts"],"sourcesContent":["import {\n TaskDefinition,\n TaskHandler\n} from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport { ListModelsUseCase } from \"@webiny/api-headless-cms/features/contentModel/ListModels/index.js\";\nimport { SYNC_FLP_TASK_ID, UPDATE_FLP_TASK_ID } from \"~/flp/tasks/index.js\";\nimport { type ISyncFlpTaskInput, type IUpdateFlpTaskInput } from \"~/types.js\";\nimport { FM_FILE_TYPE } from \"~/constants.js\";\nimport { GetFolderUseCase } from \"~/features/folder/GetFolder/abstractions.js\";\nimport { ListFoldersUseCase } from \"~/features/folder/ListFolders/abstractions.js\";\n\nclass SyncFlpTaskHandlerImpl implements TaskHandler.Interface<ISyncFlpTaskInput> {\n public constructor(\n private getFolder: GetFolderUseCase.Interface,\n private listFolders: ListFoldersUseCase.Interface,\n private listModels: ListModelsUseCase.Interface\n ) {}\n\n async run({ input, controller }: TaskHandler.RunParams<ISyncFlpTaskInput>) {\n try {\n if (controller.runtime.isAborted()) {\n return controller.response.aborted();\n }\n\n /**\n * `folderId` provided in the task input. We need to:\n *\n * - update the FLP records for the found folder and all its descendants.\n */\n if (input.folderId) {\n const result = await this.getFolder.execute(input.folderId);\n if (result.isFail()) {\n return controller.response.error(result.error);\n }\n const folder = result.value;\n\n await controller.task.trigger<IUpdateFlpTaskInput>({\n definition: UPDATE_FLP_TASK_ID,\n input: {\n folder\n }\n });\n\n return controller.response.done(\n `Task completed successfully: all FLP records for folderId \"${input.folderId}\" and its children have been queued to be synchronized.`\n );\n }\n\n /**\n * Full update required. We need to:\n *\n * - list cms models to collect their types, together with the default ones [FM_FILE_TYPE]\n * - list all root folders\n * - update the FLP records for the found folders and all its descendants.\n */\n if (input.type && input.type === \"*\") {\n // Some folder types are fixed: pages and files.\n const folderTypes = [FM_FILE_TYPE];\n\n // List all non-private models\n const modelsResult = await this.listModels.execute();\n if (modelsResult.isOk()) {\n const models = modelsResult.value;\n for (const model of models) {\n folderTypes.push(`cms:${model.modelId}`);\n }\n }\n\n for (const folderType of folderTypes) {\n const result = await this.listFolders.execute({\n where: {\n type: folderType,\n parentId: null\n }\n });\n if (result.isFail()) {\n await controller.logger.error({\n message: `Failed to list root folders for type ${folderType}`,\n data: {\n type: folderType,\n error: result.error\n }\n });\n continue;\n }\n\n const { folders } = result.value;\n\n for (const folder of folders) {\n await controller.task.trigger<IUpdateFlpTaskInput>({\n definition: UPDATE_FLP_TASK_ID,\n input: {\n folder\n }\n });\n }\n\n await controller.logger.info({\n message: `FLP Update task triggered for type ${folderType}`,\n data: {\n type: folderType\n }\n });\n }\n\n return controller.response.done(\n `Task completed successfully: all FLP records have been queued to be synchronized.`\n );\n }\n\n /**\n * `type` provided in the task input. We need to:\n *\n * - list all root folders for the provided type\n * - update the FLP records for the found folders and all its descendants.\n */\n if (input.type) {\n const result = await this.listFolders.execute({\n where: {\n type: input.type!,\n parentId: null\n }\n });\n if (result.isFail()) {\n return controller.response.error(result.error);\n }\n\n const { folders } = result.value;\n\n for (const folder of folders) {\n await controller.task.trigger<IUpdateFlpTaskInput>({\n definition: UPDATE_FLP_TASK_ID,\n input: {\n folder\n }\n });\n }\n\n return controller.response.done(\n `Task completed successfully: all FLP records for type \"${input.type}\" have been queued to be synchronized.`\n );\n }\n\n return controller.response.error(\n \"Invalid input: please provide either `type` or `folderId`.\"\n );\n } catch (error) {\n return controller.response.error(error);\n }\n }\n}\n\nconst SyncFlpTaskHandler = TaskHandler.createImplementation({\n implementation: SyncFlpTaskHandlerImpl,\n dependencies: [GetFolderUseCase, ListFoldersUseCase, ListModelsUseCase]\n});\n\nclass SyncFlpTaskImpl implements TaskDefinition.Interface {\n public readonly id = SYNC_FLP_TASK_ID;\n public readonly title = \"ACO - Sync FLP record\";\n public readonly description =\n \"Synchronizes the FLP catalog by updating the FLP record and its descendants.\";\n public readonly databaseLogs = false;\n public readonly isPrivate = true;\n public readonly selfCleanup = [\"onSuccess\" as const, \"onAbort\" as const];\n\n handler = SyncFlpTaskHandler;\n}\n\nexport const SyncFlpTask = TaskDefinition.createImplementation({\n implementation: SyncFlpTaskImpl,\n dependencies: []\n});\n"],"names":["SyncFlpTaskHandlerImpl","getFolder","listFolders","listModels","input","controller","result","folder","UPDATE_FLP_TASK_ID","folderTypes","FM_FILE_TYPE","modelsResult","models","model","folderType","folders","error","SyncFlpTaskHandler","TaskHandler","GetFolderUseCase","ListFoldersUseCase","ListModelsUseCase","SyncFlpTaskImpl","SYNC_FLP_TASK_ID","SyncFlpTask","TaskDef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AChB,cAAc;QAACmB;QAAkBC;QAAoBC;KAAkB;AAC3E;AAEA,MAAMC;;aACc,EAAE,GAAGC;aACL,KAAK,GAAG;aACR,WAAW,GACvB;aACY,YAAY,GAAG;aACf,SAAS,GAAG;aACZ,WAAW,GAAG;YAAC;YAAsB;SAAmB;aAExE,OAAO,GAAGN;;AACd;AAEO,MAAMO,cAAcC,eAAe,oBAAoB,CAAC;IAC3D,gBAAgBH;IAChB,cAAc,EAAE;AACpB"}
1
+ {"version":3,"file":"flpTaskCatalog/tasks/syncFlp.task.js","sources":["../../../src/flpTaskCatalog/tasks/syncFlp.task.ts"],"sourcesContent":["import {\n TaskDefinition,\n TaskHandler\n} from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport { ListModelsUseCase } from \"@webiny/api-headless-cms/features/contentModel/ListModels/index.js\";\nimport { SYNC_FLP_TASK_ID, UPDATE_FLP_TASK_ID } from \"~/flp/tasks/index.js\";\nimport { type ISyncFlpTaskInput, type IUpdateFlpTaskInput } from \"~/types.js\";\nimport { FM_FILE_TYPE } from \"~/constants.js\";\nimport { GetFolderUseCase } from \"~/features/folder/GetFolder/abstractions.js\";\nimport { ListFoldersUseCase } from \"~/features/folder/ListFolders/abstractions.js\";\n\nclass SyncFlpTaskHandlerImpl implements TaskHandler.Interface<ISyncFlpTaskInput> {\n public constructor(\n private getFolder: GetFolderUseCase.Interface,\n private listFolders: ListFoldersUseCase.Interface,\n private listModels: ListModelsUseCase.Interface\n ) {}\n\n async run({ input, controller }: TaskHandler.RunParams<ISyncFlpTaskInput>) {\n try {\n if (controller.runtime.isAborted()) {\n return controller.response.aborted();\n }\n\n /**\n * `folderId` provided in the task input. We need to:\n *\n * - update the FLP records for the found folder and all its descendants.\n */\n if (input.folderId) {\n const result = await this.getFolder.execute(input.folderId);\n if (result.isFail()) {\n return controller.response.error(result.error);\n }\n const folder = result.value;\n\n const triggered = await controller.task.trigger<IUpdateFlpTaskInput>({\n definition: UPDATE_FLP_TASK_ID,\n input: {\n folder\n }\n });\n if (triggered.isFail()) {\n return controller.response.error(triggered.error);\n }\n\n return controller.response.done(\n `Task completed successfully: all FLP records for folderId \"${input.folderId}\" and its children have been queued to be synchronized.`\n );\n }\n\n /**\n * Full update required. We need to:\n *\n * - list cms models to collect their types, together with the default ones [FM_FILE_TYPE]\n * - list all root folders\n * - update the FLP records for the found folders and all its descendants.\n */\n if (input.type && input.type === \"*\") {\n // Some folder types are fixed: pages and files.\n const folderTypes = [FM_FILE_TYPE];\n\n // List all non-private models\n const modelsResult = await this.listModels.execute();\n if (modelsResult.isOk()) {\n const models = modelsResult.value;\n for (const model of models) {\n folderTypes.push(`cms:${model.modelId}`);\n }\n }\n\n for (const folderType of folderTypes) {\n const result = await this.listFolders.execute({\n where: {\n type: folderType,\n parentId: null\n }\n });\n if (result.isFail()) {\n await controller.logger.error({\n message: `Failed to list root folders for type ${folderType}`,\n data: {\n type: folderType,\n error: result.error\n }\n });\n continue;\n }\n\n const { folders } = result.value;\n\n for (const folder of folders) {\n const triggered = await controller.task.trigger<IUpdateFlpTaskInput>({\n definition: UPDATE_FLP_TASK_ID,\n input: {\n folder\n }\n });\n if (triggered.isFail()) {\n return controller.response.error(triggered.error);\n }\n }\n\n await controller.logger.info({\n message: `FLP Update task triggered for type ${folderType}`,\n data: {\n type: folderType\n }\n });\n }\n\n return controller.response.done(\n `Task completed successfully: all FLP records have been queued to be synchronized.`\n );\n }\n\n /**\n * `type` provided in the task input. We need to:\n *\n * - list all root folders for the provided type\n * - update the FLP records for the found folders and all its descendants.\n */\n if (input.type) {\n const result = await this.listFolders.execute({\n where: {\n type: input.type!,\n parentId: null\n }\n });\n if (result.isFail()) {\n return controller.response.error(result.error);\n }\n\n const { folders } = result.value;\n\n for (const folder of folders) {\n const triggered = await controller.task.trigger<IUpdateFlpTaskInput>({\n definition: UPDATE_FLP_TASK_ID,\n input: {\n folder\n }\n });\n if (triggered.isFail()) {\n return controller.response.error(triggered.error);\n }\n }\n\n return controller.response.done(\n `Task completed successfully: all FLP records for type \"${input.type}\" have been queued to be synchronized.`\n );\n }\n\n return controller.response.error(\n \"Invalid input: please provide either `type` or `folderId`.\"\n );\n } catch (error) {\n return controller.response.error(error);\n }\n }\n}\n\nconst SyncFlpTaskHandler = TaskHandler.createImplementation({\n implementation: SyncFlpTaskHandlerImpl,\n dependencies: [GetFolderUseCase, ListFoldersUseCase, ListModelsUseCase]\n});\n\nclass SyncFlpTaskImpl implements TaskDefinition.Interface {\n public readonly id = SYNC_FLP_TASK_ID;\n public readonly title = \"ACO - Sync FLP record\";\n public readonly description =\n \"Synchronizes the FLP catalog by updating the FLP record and its descendants.\";\n public readonly databaseLogs = false;\n public readonly isPrivate = true;\n public readonly selfCleanup = [\"onSuccess\" as const, \"onAbort\" as const];\n\n handler = SyncFlpTaskHandler;\n}\n\nexport const SyncFlpTask = TaskDefinition.createImplementation({\n implementation: SyncFlpTaskImpl,\n dependencies: []\n});\n"],"names":["SyncFlpTaskHandlerImpl","getFolder","listFolders","listModels","input","controller","result","folder","triggered","UPDATE_FLP_TASK_ID","folderTypes","FM_FILE_TYPE","modelsResult","models","model","folderType","folders","error","SyncFlpTaskHandler","TaskHandler","GetFolderUseCase","ListFoldersUseCase","ListModelsUseCase","SyncFlpTaskImpl","SYNC_FLP_TASK_ID","SyncFlpTask","TaskDefinition"],"mappings":";;;;;;AAWA,MAAMA;IACF,YACYC,SAAqC,EACrCC,WAAyC,EACzCC,UAAuC,CACjD;aAHUF,SAAS,GAATA;aACAC,WAAW,GAAXA;aACAC,UAAU,GAAVA;IACT;IAEH,MAAM,IAAI,EAAEC,KAAK,EAAEC,UAAU,EAA4C,EAAE;QACvE,IAAI;YACA,IAAIA,WAAW,OAAO,CAAC,SAAS,IAC5B,OAAOA,WAAW,QAAQ,CAAC,OAAO;YAQtC,IAAID,MAAM,QAAQ,EAAE;gBAChB,MAAME,SAAS,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAACF,MAAM,QAAQ;gBAC1D,IAAIE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ACR,WAAW,GACvB;aACY,YAAY,GAAG;aACf,SAAS,GAAG;aACZ,WAAW,GAAG;YAAC;YAAsB;SAAmB;aAExE,OAAO,GAAGN;;AACd;AAEO,MAAMO,cAAcC,eAAe,oBAAoB,CAAC;IAC3D,gBAAgBH;IAChB,cAAc,EAAE;AACpB"}
@@ -59,7 +59,8 @@ export interface UpdateFolderParams {
59
59
  title?: string;
60
60
  slug?: string;
61
61
  permissions?: FolderPermission[];
62
- parentId?: string;
62
+ /** null moves the folder to the root. */
63
+ parentId?: string | null;
63
64
  }
64
65
  export interface FolderLevelPermissionsTarget<TMeta = Record<string, any>> {
65
66
  id: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-aco",
3
- "version": "6.6.0-alpha.10",
3
+ "version": "6.6.0-alpha.11",
4
4
  "type": "module",
5
5
  "keywords": [
6
6
  "aco:base"
@@ -21,29 +21,28 @@
21
21
  ".": "./index.js"
22
22
  },
23
23
  "dependencies": {
24
- "@webiny/api-core": "6.6.0-alpha.10",
25
- "@webiny/api-graphql": "6.6.0-alpha.10",
26
- "@webiny/api-headless-cms": "6.6.0-alpha.10",
27
- "@webiny/api-websockets": "6.6.0-alpha.10",
24
+ "@webiny/api-core": "6.6.0-alpha.11",
25
+ "@webiny/api-graphql": "6.6.0-alpha.11",
26
+ "@webiny/api-headless-cms": "6.6.0-alpha.11",
28
27
  "@webiny/di": "2.0.0",
29
- "@webiny/error": "6.6.0-alpha.10",
30
- "@webiny/event-handler-core": "6.6.0-alpha.10",
31
- "@webiny/feature": "6.6.0-alpha.10",
32
- "@webiny/handler": "6.6.0-alpha.10",
33
- "@webiny/shared-aco": "6.6.0-alpha.10",
34
- "@webiny/utils": "6.6.0-alpha.10",
35
- "@webiny/validation": "6.6.0-alpha.10",
28
+ "@webiny/error": "6.6.0-alpha.11",
29
+ "@webiny/event-handler-core": "6.6.0-alpha.11",
30
+ "@webiny/feature": "6.6.0-alpha.11",
31
+ "@webiny/handler": "6.6.0-alpha.11",
32
+ "@webiny/shared-aco": "6.6.0-alpha.11",
33
+ "@webiny/utils": "6.6.0-alpha.11",
34
+ "@webiny/validation": "6.6.0-alpha.11",
36
35
  "lodash": "4.18.1",
37
36
  "zod": "4.6.7"
38
37
  },
39
38
  "devDependencies": {
40
- "@webiny/api": "6.6.0-alpha.10",
41
- "@webiny/api-core-testing": "6.6.0-alpha.10",
42
- "@webiny/api-file-manager": "6.6.0-alpha.10",
43
- "@webiny/api-headless-cms-testing": "6.6.0-alpha.10",
44
- "@webiny/build-tools": "6.6.0-alpha.10",
45
- "@webiny/plugins": "6.6.0-alpha.10",
46
- "@webiny/wcp": "6.6.0-alpha.10",
39
+ "@webiny/api": "6.6.0-alpha.11",
40
+ "@webiny/api-core-testing": "6.6.0-alpha.11",
41
+ "@webiny/api-file-manager": "6.6.0-alpha.11",
42
+ "@webiny/api-headless-cms-testing": "6.6.0-alpha.11",
43
+ "@webiny/build-tools": "6.6.0-alpha.11",
44
+ "@webiny/plugins": "6.6.0-alpha.11",
45
+ "@webiny/wcp": "6.6.0-alpha.11",
47
46
  "graphql": "16.14.2",
48
47
  "rimraf": "6.1.3",
49
48
  "typescript": "7.0.2",