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

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 (58) hide show
  1. package/features/ai/UpdateFolderTool.d.ts +57 -0
  2. package/features/ai/UpdateFolderTool.js +72 -0
  3. package/features/ai/UpdateFolderTool.js.map +1 -0
  4. package/features/ai/feature.d.ts +2 -2
  5. package/features/ai/feature.js +2 -6
  6. package/features/ai/feature.js.map +1 -1
  7. package/features/ai/index.d.ts +1 -3
  8. package/features/ai/index.js +1 -3
  9. package/features/ai/loadFolderPermissions.d.ts +4 -1
  10. package/features/ai/loadFolderPermissions.js +1 -1
  11. package/features/ai/loadFolderPermissions.js.map +1 -1
  12. package/features/flp/FolderLevelPermissions/FolderLevelPermissions.js +0 -1
  13. package/features/flp/FolderLevelPermissions/FolderLevelPermissions.js.map +1 -1
  14. package/features/flp/ListFolderAccess/mayAskAboutUser.js +1 -1
  15. package/features/flp/ListFolderAccess/mayAskAboutUser.js.map +1 -1
  16. package/features/folder/NotifyFolderChange/NotifyOnFolderDeletedHandler.d.ts +3 -3
  17. package/features/folder/NotifyFolderChange/NotifyOnFolderDeletedHandler.js +10 -10
  18. package/features/folder/NotifyFolderChange/NotifyOnFolderDeletedHandler.js.map +1 -1
  19. package/features/folder/NotifyFolderChange/feature.js +0 -2
  20. package/features/folder/NotifyFolderChange/feature.js.map +1 -1
  21. package/features/folder/NotifyFolderChange/index.d.ts +1 -1
  22. package/features/folder/NotifyFolderChange/index.js +1 -1
  23. package/features/folder/NotifyFolderChange/recordType.d.ts +8 -0
  24. package/features/folder/NotifyFolderChange/recordType.js +4 -0
  25. package/features/folder/NotifyFolderChange/recordType.js.map +1 -0
  26. package/features/folder/UpdateFolder/UpdateFolderUseCase.d.ts +1 -0
  27. package/features/folder/UpdateFolder/UpdateFolderUseCase.js +13 -0
  28. package/features/folder/UpdateFolder/UpdateFolderUseCase.js.map +1 -1
  29. package/features/folder/UpdateFolder/decorators/UpdateFolderWithFolderLevelPermissions.js +4 -2
  30. package/features/folder/UpdateFolder/decorators/UpdateFolderWithFolderLevelPermissions.js.map +1 -1
  31. package/flpTaskCatalog/TaskFolderCatalogSync.d.ts +1 -0
  32. package/flpTaskCatalog/TaskFolderCatalogSync.js +7 -2
  33. package/flpTaskCatalog/TaskFolderCatalogSync.js.map +1 -1
  34. package/flpTaskCatalog/tasks/createFlp.task.d.ts +3 -3
  35. package/flpTaskCatalog/tasks/createFlp.task.js +7 -5
  36. package/flpTaskCatalog/tasks/createFlp.task.js.map +1 -1
  37. package/flpTaskCatalog/tasks/syncFlp.task.js +20 -13
  38. package/flpTaskCatalog/tasks/syncFlp.task.js.map +1 -1
  39. package/flpTaskCatalog/tasks/updateFlp.task.d.ts +3 -3
  40. package/flpTaskCatalog/tasks/updateFlp.task.js +7 -5
  41. package/flpTaskCatalog/tasks/updateFlp.task.js.map +1 -1
  42. package/folder/folder.types.d.ts +2 -1
  43. package/package.json +18 -19
  44. package/features/ai/CreateTeamTool.d.ts +0 -48
  45. package/features/ai/CreateTeamTool.js +0 -56
  46. package/features/ai/CreateTeamTool.js.map +0 -1
  47. package/features/ai/ListRolesTool.d.ts +0 -39
  48. package/features/ai/ListRolesTool.js +0 -48
  49. package/features/ai/ListRolesTool.js.map +0 -1
  50. package/features/ai/ListTeamsTool.d.ts +0 -39
  51. package/features/ai/ListTeamsTool.js +0 -48
  52. package/features/ai/ListTeamsTool.js.map +0 -1
  53. package/features/folder/NotifyFolderChange/NotifyFolderChangeUseCase.d.ts +0 -11
  54. package/features/folder/NotifyFolderChange/NotifyFolderChangeUseCase.js +0 -38
  55. package/features/folder/NotifyFolderChange/NotifyFolderChangeUseCase.js.map +0 -1
  56. package/features/folder/NotifyFolderChange/abstractions.d.ts +0 -28
  57. package/features/folder/NotifyFolderChange/abstractions.js +0 -8
  58. package/features/folder/NotifyFolderChange/abstractions.js.map +0 -1
@@ -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,OAAOC,OAAO,IAAI,CAACD,eAAe,KAAK;QAG3C,MAAME,WAAWF,eAAe,KAAK;QAErC,MAAMG,sBAAsB,MAAM,IAAI,CAAC,sBAAsB,CAAC,yBAAyB,CAACL;QAGxF,MAAM,IAAI,CAAC,sBAAsB,CAAC,qBAAqB,CAAC;YACpD,aAAaK;YACb,KAAK;QACT;QAKA,MAAMC,eAAe,MAAM,IAAI,CAAC,eAAe,CAACF,UAAUH;QAE1D,MAAMM,uBAAuB,MAAM,IAAI,CAAC,mBAAmB,CACvDD,cACAL,OAAO,WAAW,IAAI,EAAE;QAG5B,MAAMO,cACF,MAAM,IAAI,CAAC,sBAAsB,CAAC,qBAAqB,CAACD;QAG5D,MAAME,iBAAiB,MAAM,IAAI,CAAC,sBAAsB,CAAC,eAAe,CAAC;YACrED;YACA,KAAK;QACT;QAEA,I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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,CAACA,WAAW,MAAM;AAIrE,MAAMC;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,OAAOC,OAAO,IAAI,CAACD,eAAe,KAAK;QAG3C,MAAME,WAAWF,eAAe,KAAK;QAErC,MAAMG,sBAAsB,MAAM,IAAI,CAAC,sBAAsB,CAAC,yBAAyB,CAACL;QAGxF,M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,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"}
@@ -21,6 +21,7 @@ declare class TaskFolderCatalogSyncImpl implements FolderCatalogSync.Interface {
21
21
  folderCreated(folder: Folder): Promise<void>;
22
22
  folderUpdated({ folder }: FolderCatalogSync.UpdatedParams): Promise<void>;
23
23
  folderDeleted(folder: Folder): Promise<void>;
24
+ private getNotifyIdentityId;
24
25
  private trigger;
25
26
  }
26
27
  export declare const TaskFolderCatalogSync: typeof TaskFolderCatalogSyncImpl & {
@@ -12,13 +12,13 @@ class TaskFolderCatalogSyncImpl {
12
12
  async folderCreated(folder) {
13
13
  await this.trigger(CREATE_FLP_TASK_ID, {
14
14
  folder,
15
- notifyIdentityId: this.identityContext.getIdentity()?.id
15
+ notifyIdentityId: this.getNotifyIdentityId()
16
16
  }, "Could not trigger the task that creates the folder's FLP record.");
17
17
  }
18
18
  async folderUpdated({ folder }) {
19
19
  await this.trigger(UPDATE_FLP_TASK_ID, {
20
20
  folder,
21
- notifyIdentityId: this.identityContext.getIdentity()?.id
21
+ notifyIdentityId: this.getNotifyIdentityId()
22
22
  }, "Could not trigger the task that updates the FLP records of the folder and its subtree.");
23
23
  }
24
24
  async folderDeleted(folder) {
@@ -26,6 +26,11 @@ class TaskFolderCatalogSyncImpl {
26
26
  folder
27
27
  }, "Could not trigger the task that deletes the folder's FLP record.");
28
28
  }
29
+ getNotifyIdentityId() {
30
+ const identity = this.identityContext.getIdentity();
31
+ if (identity.isAnonymous()) return;
32
+ return identity.id;
33
+ }
29
34
  async trigger(definition, input, failureMessage) {
30
35
  try {
31
36
  const result = await this.tasks.trigger({
@@ -1 +1 @@
1
- {"version":3,"file":"flpTaskCatalog/TaskFolderCatalogSync.js","sources":["../../src/flpTaskCatalog/TaskFolderCatalogSync.ts"],"sourcesContent":["import { TaskService } from \"@webiny/api-core/features/task/TaskService/index.js\";\nimport { Logger } from \"@webiny/api-core/features/logger/index.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/abstractions.js\";\nimport { FolderCatalogSync } from \"~/features/flp/FolderCatalogSync/abstractions.js\";\nimport type { Folder } from \"~/folder/folder.types.js\";\nimport type { ICreateFlpTaskInput, IDeleteFlpTaskInput, IUpdateFlpTaskInput } from \"~/types.js\";\nimport { CREATE_FLP_TASK_ID, DELETE_FLP_TASK_ID, UPDATE_FLP_TASK_ID } from \"~/flp/tasks/index.js\";\n\n/**\n * Keeps the FLP catalog in step by triggering the FLP tasks.\n *\n * Folder reads report permissions from the FLP records, which the tasks write later. So the create\n * and update tasks, not this class, tell the admin about the change, and they need to know whom to\n * tell. A change rewrites the folder's record and every descendant's.\n *\n * The folder change is already saved, so it stands even when a task cannot be triggered. The logged\n * error is then the only trace of why the catalog is behind.\n */\nclass TaskFolderCatalogSyncImpl implements FolderCatalogSync.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private tasks: TaskService.Interface,\n private logger: Logger.Interface\n ) {}\n\n async folderCreated(folder: Folder): Promise<void> {\n await this.trigger<ICreateFlpTaskInput>(\n CREATE_FLP_TASK_ID,\n // Nobody to tell when there is no identity, as in some system calls.\n { folder, notifyIdentityId: this.identityContext.getIdentity()?.id },\n \"Could not trigger the task that creates the folder's FLP record.\"\n );\n }\n\n async folderUpdated({ folder }: FolderCatalogSync.UpdatedParams): Promise<void> {\n await this.trigger<IUpdateFlpTaskInput>(\n UPDATE_FLP_TASK_ID,\n // Nobody to tell when there is no identity, as in some system calls.\n { folder, notifyIdentityId: this.identityContext.getIdentity()?.id },\n \"Could not trigger the task that updates the FLP records of the folder and its subtree.\"\n );\n }\n\n async folderDeleted(folder: Folder): Promise<void> {\n await this.trigger<IDeleteFlpTaskInput>(\n DELETE_FLP_TASK_ID,\n { folder },\n \"Could not trigger the task that deletes the folder's FLP record.\"\n );\n }\n\n private async trigger<TInput extends { folder: Folder }>(\n definition: string,\n input: TInput,\n failureMessage: string\n ): Promise<void> {\n try {\n const result = await this.tasks.trigger<TInput>({ definition, input });\n if (result.isFail()) {\n this.logger.error(\n { error: result.error, folderId: input.folder.id },\n failureMessage\n );\n }\n } catch (error) {\n this.logger.error({ error, folderId: input.folder.id }, failureMessage);\n }\n }\n}\n\nexport const TaskFolderCatalogSync = FolderCatalogSync.createImplementation({\n implementation: TaskFolderCatalogSyncImpl,\n dependencies: [IdentityContext, TaskService, Logger]\n});\n"],"names":["TaskFolderCatalogSyncImpl","identityContext","tasks","logger","folder","CREATE_FLP_TASK_ID","UPDATE_FLP_TASK_ID","DELETE_FLP_TASK_ID","definition","input","failureMessage","result","error","TaskFolderCatalogSync","FolderCatalogSync","IdentityContext","TaskService","Logger"],"mappings":";;;;;AAkBA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,KAA4B,EAC5BC,MAAwB,CAClC;aAHUF,eAAe,GAAfA;aACAC,KAAK,GAALA;aACAC,MAAM,GAANA;IACT;IAEH,MAAM,cAAcC,MAAc,EAAiB;QAC/C,MAAM,IAAI,CAAC,OAAO,CACdC,oBAEA;YAAED;YAAQ,kBAAkB,IAAI,CAAC,eAAe,CAAC,WAAW,IAAI;QAAG,GACnE;IAER;IAEA,MAAM,cAAc,EAAEA,MAAM,EAAmC,EAAiB;QAC5E,MAAM,IAAI,CAAC,OAAO,CACdE,oBAEA;YAAEF;YAAQ,kBAAkB,IAAI,CAAC,eAAe,CAAC,WAAW,IAAI;QAAG,GACnE;IAER;IAEA,MAAM,cAAcA,MAAc,EAAiB;QAC/C,MAAM,IAAI,CAAC,OAAO,CACdG,oBACA;YAAEH;QAAO,GACT;IAER;IAEA,MAAc,QACVI,UAAkB,EAClBC,KAAa,EACbC,cAAsB,EACT;QACb,IAAI;YACA,MAAMC,SAAS,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAS;gBAAEH;gBAAYC;YAAM;YACpE,IAAIE,OAAO,MAAM,IACb,IAAI,CAAC,MAAM,CAAC,KAAK,CACb;gBAAE,OAAOA,OAAO,KAAK;gBAAE,UAAUF,MAAM,MAAM,CAAC,EAAE;YAAC,GACjDC;QAGZ,EAAE,OAAOE,OAAO;YACZ,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;gBAAEA;gBAAO,UAAUH,MAAM,MAAM,CAAC,EAAE;YAAC,GAAGC;QAC5D;IACJ;AACJ;AAEO,MAAMG,wBAAwBC,kBAAkB,oBAAoB,CAAC;IACxE,gBAAgBd;IAChB,cAAc;QAACe;QAAiBC;QAAaC;KAAO;AACxD"}
1
+ {"version":3,"file":"flpTaskCatalog/TaskFolderCatalogSync.js","sources":["../../src/flpTaskCatalog/TaskFolderCatalogSync.ts"],"sourcesContent":["import { TaskService } from \"@webiny/api-core/features/task/TaskService/index.js\";\nimport { Logger } from \"@webiny/api-core/features/logger/index.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/abstractions.js\";\nimport { FolderCatalogSync } from \"~/features/flp/FolderCatalogSync/abstractions.js\";\nimport type { Folder } from \"~/folder/folder.types.js\";\nimport type { ICreateFlpTaskInput, IDeleteFlpTaskInput, IUpdateFlpTaskInput } from \"~/types.js\";\nimport { CREATE_FLP_TASK_ID, DELETE_FLP_TASK_ID, UPDATE_FLP_TASK_ID } from \"~/flp/tasks/index.js\";\n\n/**\n * Keeps the FLP catalog in step by triggering the FLP tasks.\n *\n * Folder reads report permissions from the FLP records, which the tasks write later. So the create\n * and update tasks, not this class, tell the admin about the change, and they need to know whom to\n * tell. A change rewrites the folder's record and every descendant's.\n *\n * The folder change is already saved, so it stands even when a task cannot be triggered. The logged\n * error is then the only trace of why the catalog is behind.\n */\nclass TaskFolderCatalogSyncImpl implements FolderCatalogSync.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private tasks: TaskService.Interface,\n private logger: Logger.Interface\n ) {}\n\n async folderCreated(folder: Folder): Promise<void> {\n await this.trigger<ICreateFlpTaskInput>(\n CREATE_FLP_TASK_ID,\n { folder, notifyIdentityId: this.getNotifyIdentityId() },\n \"Could not trigger the task that creates the folder's FLP record.\"\n );\n }\n\n async folderUpdated({ folder }: FolderCatalogSync.UpdatedParams): Promise<void> {\n await this.trigger<IUpdateFlpTaskInput>(\n UPDATE_FLP_TASK_ID,\n { folder, notifyIdentityId: this.getNotifyIdentityId() },\n \"Could not trigger the task that updates the FLP records of the folder and its subtree.\"\n );\n }\n\n async folderDeleted(folder: Folder): Promise<void> {\n await this.trigger<IDeleteFlpTaskInput>(\n DELETE_FLP_TASK_ID,\n { folder },\n \"Could not trigger the task that deletes the folder's FLP record.\"\n );\n }\n\n // Nobody to tell when no one is signed in, as in some system calls.\n private getNotifyIdentityId(): string | undefined {\n const identity = this.identityContext.getIdentity();\n if (identity.isAnonymous()) {\n return undefined;\n }\n return identity.id;\n }\n\n private async trigger<TInput extends { folder: Folder }>(\n definition: string,\n input: TInput,\n failureMessage: string\n ): Promise<void> {\n try {\n const result = await this.tasks.trigger<TInput>({ definition, input });\n if (result.isFail()) {\n this.logger.error(\n { error: result.error, folderId: input.folder.id },\n failureMessage\n );\n }\n } catch (error) {\n this.logger.error({ error, folderId: input.folder.id }, failureMessage);\n }\n }\n}\n\nexport const TaskFolderCatalogSync = FolderCatalogSync.createImplementation({\n implementation: TaskFolderCatalogSyncImpl,\n dependencies: [IdentityContext, TaskService, Logger]\n});\n"],"names":["TaskFolderCatalogSyncImpl","identityContext","tasks","logger","folder","CREATE_FLP_TASK_ID","UPDATE_FLP_TASK_ID","DELETE_FLP_TASK_ID","identity","definition","input","failureMessage","result","error","TaskFolderCatalogSync","FolderCatalogSync","IdentityContext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1,11 @@
1
1
  import { TaskDefinition, TaskHandler } from "@webiny/api-core/features/task/TaskDefinition/index.js";
2
2
  import { type ICreateFlpTaskInput } from "../../types.js";
3
3
  import { CreateFlpUseCase } from "../../features/flp/CreateFlp/abstractions.js";
4
- import { NotifyFolderChangeUseCase } from "../../features/folder/NotifyFolderChange/abstractions.js";
4
+ import { NotifyRecordChangeUseCase } from "@webiny/api-core/features/websockets/index.js";
5
5
  declare class CreateFlpTaskHandlerImpl implements TaskHandler.Interface<ICreateFlpTaskInput> {
6
6
  private createFlp;
7
- private notifyFolderChange;
8
- constructor(createFlp: CreateFlpUseCase.Interface, notifyFolderChange: NotifyFolderChangeUseCase.Interface);
7
+ private notifyRecordChange;
8
+ constructor(createFlp: CreateFlpUseCase.Interface, notifyRecordChange: NotifyRecordChangeUseCase.Interface);
9
9
  run({ input, controller }: TaskHandler.RunParams<ICreateFlpTaskInput>): Promise<import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskResultAborted | import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskResultError | TaskDefinition.ResultContinue<ICreateFlpTaskInput> | TaskDefinition.ResultDone<import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskOutput>>;
10
10
  }
11
11
  declare class CreateFlpTaskImpl implements TaskDefinition.Interface {
@@ -1,18 +1,20 @@
1
1
  import { TaskDefinition, TaskHandler } from "@webiny/api-core/features/task/TaskDefinition/index.js";
2
2
  import { CREATE_FLP_TASK_ID } from "../../flp/tasks/index.js";
3
3
  import { CreateFlpUseCase } from "../../features/flp/CreateFlp/abstractions.js";
4
- import { NotifyFolderChangeUseCase } from "../../features/folder/NotifyFolderChange/abstractions.js";
4
+ import { NotifyRecordChangeUseCase } from "@webiny/api-core/features/websockets/index.js";
5
+ import { FOLDER_RECORD_TYPE } from "../../features/folder/NotifyFolderChange/recordType.js";
5
6
  class CreateFlpTaskHandlerImpl {
6
- constructor(createFlp, notifyFolderChange){
7
+ constructor(createFlp, notifyRecordChange){
7
8
  this.createFlp = createFlp;
8
- this.notifyFolderChange = notifyFolderChange;
9
+ this.notifyRecordChange = notifyRecordChange;
9
10
  }
10
11
  async run({ input, controller }) {
11
12
  try {
12
13
  if (controller.runtime.isAborted()) return controller.response.aborted();
13
14
  if (controller.runtime.isCloseToTimeout()) return controller.response.continue(input);
14
15
  await this.createFlp.execute(input.folder);
15
- if (input.notifyIdentityId) await this.notifyFolderChange.execute({
16
+ if (input.notifyIdentityId) await this.notifyRecordChange.execute({
17
+ type: FOLDER_RECORD_TYPE,
16
18
  id: input.folder.id,
17
19
  change: "created",
18
20
  identityId: input.notifyIdentityId
@@ -27,7 +29,7 @@ const CreateFlpTaskHandler = TaskHandler.createImplementation({
27
29
  implementation: CreateFlpTaskHandlerImpl,
28
30
  dependencies: [
29
31
  CreateFlpUseCase,
30
- NotifyFolderChangeUseCase
32
+ NotifyRecordChangeUseCase
31
33
  ]
32
34
  });
33
35
  class CreateFlpTaskImpl {
@@ -1 +1 @@
1
- {"version":3,"file":"flpTaskCatalog/tasks/createFlp.task.js","sources":["../../../src/flpTaskCatalog/tasks/createFlp.task.ts"],"sourcesContent":["import {\n TaskDefinition,\n TaskHandler\n} from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport { CREATE_FLP_TASK_ID } from \"~/flp/tasks/index.js\";\nimport { type ICreateFlpTaskInput } from \"~/types.js\";\nimport { CreateFlpUseCase } from \"~/features/flp/CreateFlp/abstractions.js\";\nimport { NotifyFolderChangeUseCase } from \"~/features/folder/NotifyFolderChange/abstractions.js\";\n\nclass CreateFlpTaskHandlerImpl implements TaskHandler.Interface<ICreateFlpTaskInput> {\n constructor(\n private createFlp: CreateFlpUseCase.Interface,\n private notifyFolderChange: NotifyFolderChangeUseCase.Interface\n ) {}\n\n async run({ input, controller }: TaskHandler.RunParams<ICreateFlpTaskInput>) {\n try {\n if (controller.runtime.isAborted()) {\n return controller.response.aborted();\n }\n\n if (controller.runtime.isCloseToTimeout()) {\n return controller.response.continue(input);\n }\n\n await this.createFlp.execute(input.folder);\n\n // Only now can the admin read the folder back with its permissions.\n if (input.notifyIdentityId) {\n await this.notifyFolderChange.execute({\n id: input.folder.id,\n change: \"created\",\n identityId: input.notifyIdentityId\n });\n }\n\n return controller.response.done(\"Task done: FLP record created.\");\n } catch (error) {\n return controller.response.error(error);\n }\n }\n}\n\nconst CreateFlpTaskHandler = TaskHandler.createImplementation({\n implementation: CreateFlpTaskHandlerImpl,\n dependencies: [CreateFlpUseCase, NotifyFolderChangeUseCase]\n});\n\nclass CreateFlpTaskImpl implements TaskDefinition.Interface {\n public readonly id = CREATE_FLP_TASK_ID;\n public readonly title = \"ACO - Create FLP record\";\n public readonly description =\n \"Synchronizes the FLP catalog by creating the FLP record based on the provided folder.\";\n public readonly databaseLogs = false;\n public readonly isPrivate = true;\n public readonly selfCleanup = [\"onSuccess\" as const, \"onAbort\" as const];\n\n handler = CreateFlpTaskHandler;\n}\n\nexport const CreateFlpTask = TaskDefinition.createImplementation({\n implementation: CreateFlpTaskImpl,\n dependencies: []\n});\n"],"names":["CreateFlpTaskHandlerImpl","createFlp","notifyFolderChange","input","controller","error","CreateFlpTaskHandler","TaskHandler","CreateFlpUseCase","NotifyFolderChangeUseCase","CreateFlpTaskImpl","CREATE_FLP_TASK_ID","CreateFlpTask","TaskDefinition"],"mappings":";;;;AASA,MAAMA;IACF,YACYC,SAAqC,EACrCC,kBAAuD,CACjE;aAFUD,SAAS,GAATA;aACAC,kBAAkB,GAAlBA;IACT;IAEH,MAAM,IAAI,EAAEC,KAAK,EAAEC,UAAU,EAA8C,EAAE;QACzE,IAAI;YACA,IAAIA,WAAW,OAAO,CAAC,SAAS,IAC5B,OAAOA,WAAW,QAAQ,CAAC,OAAO;YAGtC,IAAIA,WAAW,OAAO,CAAC,gBAAgB,IACnC,OAAOA,WAAW,QAAQ,CAAC,QAAQ,CAACD;YAGxC,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAACA,MAAM,MAAM;YAGzC,IAAIA,MAAM,gBAAgB,EACtB,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC;gBAClC,IAAIA,MAAM,MAAM,CAAC,EAAE;gBACnB,QAAQ;gBACR,YAAYA,MAAM,gBAAgB;YACtC;YAGJ,OAAOC,WAAW,QAAQ,CAAC,IAAI,CAAC;QACpC,EAAE,OAAOC,OAAO;YACZ,OAAOD,WAAW,QAAQ,CAAC,KAAK,CAACC;QACrC;IACJ;AACJ;AAEA,MAAMC,uBAAuBC,YAAY,oBAAoB,CAAC;IAC1D,gBAAgBP;IAChB,cAAc;QAACQ;QAAkBC;KAA0B;AAC/D;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,GAAGL;;AACd;AAEO,MAAMM,gBAAgBC,eAAe,oBAAoB,CAAC;IAC7D,gBAAgBH;IAChB,cAAc,EAAE;AACpB"}
1
+ {"version":3,"file":"flpTaskCatalog/tasks/createFlp.task.js","sources":["../../../src/flpTaskCatalog/tasks/createFlp.task.ts"],"sourcesContent":["import {\n TaskDefinition,\n TaskHandler\n} from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport { CREATE_FLP_TASK_ID } from \"~/flp/tasks/index.js\";\nimport { type ICreateFlpTaskInput } from \"~/types.js\";\nimport { CreateFlpUseCase } from \"~/features/flp/CreateFlp/abstractions.js\";\nimport { NotifyRecordChangeUseCase } from \"@webiny/api-core/features/websockets/index.js\";\nimport { FOLDER_RECORD_TYPE } from \"~/features/folder/NotifyFolderChange/recordType.js\";\n\nclass CreateFlpTaskHandlerImpl implements TaskHandler.Interface<ICreateFlpTaskInput> {\n constructor(\n private createFlp: CreateFlpUseCase.Interface,\n private notifyRecordChange: NotifyRecordChangeUseCase.Interface\n ) {}\n\n async run({ input, controller }: TaskHandler.RunParams<ICreateFlpTaskInput>) {\n try {\n if (controller.runtime.isAborted()) {\n return controller.response.aborted();\n }\n\n if (controller.runtime.isCloseToTimeout()) {\n return controller.response.continue(input);\n }\n\n await this.createFlp.execute(input.folder);\n\n // Only now can the admin read the folder back with its permissions.\n if (input.notifyIdentityId) {\n await this.notifyRecordChange.execute({\n type: FOLDER_RECORD_TYPE,\n id: input.folder.id,\n change: \"created\",\n identityId: input.notifyIdentityId\n });\n }\n\n return controller.response.done(\"Task done: FLP record created.\");\n } catch (error) {\n return controller.response.error(error);\n }\n }\n}\n\nconst CreateFlpTaskHandler = TaskHandler.createImplementation({\n implementation: CreateFlpTaskHandlerImpl,\n dependencies: [CreateFlpUseCase, NotifyRecordChangeUseCase]\n});\n\nclass CreateFlpTaskImpl implements TaskDefinition.Interface {\n public readonly id = CREATE_FLP_TASK_ID;\n public readonly title = \"ACO - Create FLP record\";\n public readonly description =\n \"Synchronizes the FLP catalog by creating the FLP record based on the provided folder.\";\n public readonly databaseLogs = false;\n public readonly isPrivate = true;\n public readonly selfCleanup = [\"onSuccess\" as const, \"onAbort\" as const];\n\n handler = CreateFlpTaskHandler;\n}\n\nexport const CreateFlpTask = TaskDefinition.createImplementation({\n implementation: CreateFlpTaskImpl,\n dependencies: []\n});\n"],"names":["CreateFlpTaskHandlerImpl","createFlp","notifyRecordChange","input","controller","FOLDER_RECORD_TYPE","error","CreateFlpTaskHandler","TaskHandler","CreateFlpUseCase","NotifyRecordChangeUseCase","CreateFlpTaskImpl","CREATE_FLP_TASK_ID","CreateFlpTask","TaskDefinition"],"mappings":";;;;;AAUA,MAAMA;IACF,YACYC,SAAqC,EACrCC,kBAAuD,CACjE;aAFUD,SAAS,GAATA;aACAC,kBAAkB,GAAlBA;IACT;IAEH,MAAM,IAAI,EAAEC,KAAK,EAAEC,UAAU,EAA8C,EAAE;QACzE,IAAI;YACA,IAAIA,WAAW,OAAO,CAAC,SAAS,IAC5B,OAAOA,WAAW,QAAQ,CAAC,OAAO;YAGtC,IAAIA,WAAW,OAAO,CAAC,gBAAgB,IACnC,OAAOA,WAAW,QAAQ,CAAC,QAAQ,CAACD;YAGxC,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAACA,MAAM,MAAM;YAGzC,IAAIA,MAAM,gBAAgB,EACtB,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC;gBAClC,MAAME;gBACN,IAAIF,MAAM,MAAM,CAAC,EAAE;gBACnB,QAAQ;gBACR,YAAYA,MAAM,gBAAgB;YACtC;YAGJ,OAAOC,WAAW,QAAQ,CAAC,IAAI,CAAC;QACpC,EAAE,OAAOE,OAAO;YACZ,OAAOF,WAAW,QAAQ,CAAC,KAAK,CAACE;QACrC;IACJ;AACJ;AAEA,MAAMC,uBAAuBC,YAAY,oBAAoB,CAAC;IAC1D,gBAAgBR;IAChB,cAAc;QAACS;QAAkBC;KAA0B;AAC/D;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,GAAGL;;AACd;AAEO,MAAMM,gBAAgBC,eAAe,oBAAoB,CAAC;IAC7D,gBAAgBH;IAChB,cAAc,EAAE;AACpB"}
@@ -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","TaskDefinition"],"mappings":";;;;;;AAWA,MAAMA;IACF,YACYC,SAAqC,EACrCC,WAAyC,EACzCC,UAAuC,CACjD;aAHUF,SAAS,GAATA;aACAC,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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,OAAO,MAAM,IACb,OAAOD,WAAW,QAAQ,CAAC,KAAK,CAACC,OAAO,KAAK;gBAEjD,MAAMC,SAASD,OAAO,KAAK;gBAE3B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ACd;AAEO,MAAMO,cAAcC,eAAe,oBAAoB,CAAC;IAC3D,gBAAgBH;IAChB,cAAc,EAAE;AACpB"}
@@ -1,11 +1,11 @@
1
1
  import { TaskDefinition, TaskHandler } from "@webiny/api-core/features/task/TaskDefinition/index.js";
2
2
  import { type IUpdateFlpTaskInput } from "../../types.js";
3
3
  import { UpdateFlpUseCase } from "../../features/flp/UpdateFlp/abstractions.js";
4
- import { NotifyFolderChangeUseCase } from "../../features/folder/NotifyFolderChange/abstractions.js";
4
+ import { NotifyRecordChangeUseCase } from "@webiny/api-core/features/websockets/index.js";
5
5
  declare class UpdateFlpTaskHandlerImpl implements TaskHandler.Interface<IUpdateFlpTaskInput> {
6
6
  private updateFlp;
7
- private notifyFolderChange;
8
- constructor(updateFlp: UpdateFlpUseCase.Interface, notifyFolderChange: NotifyFolderChangeUseCase.Interface);
7
+ private notifyRecordChange;
8
+ constructor(updateFlp: UpdateFlpUseCase.Interface, notifyRecordChange: NotifyRecordChangeUseCase.Interface);
9
9
  run({ input, controller }: TaskHandler.RunParams<IUpdateFlpTaskInput>): Promise<import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskResultAborted | import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskResultError | TaskDefinition.ResultContinue<IUpdateFlpTaskInput> | TaskDefinition.ResultDone<import("@webiny/api-core/features/task/TaskDefinition/abstractions").ITaskOutput>>;
10
10
  }
11
11
  declare class UpdateFlpTaskImpl implements TaskDefinition.Interface {
@@ -1,11 +1,12 @@
1
1
  import { TaskDefinition, TaskHandler } from "@webiny/api-core/features/task/TaskDefinition/index.js";
2
2
  import { UPDATE_FLP_TASK_ID } from "../../flp/tasks/index.js";
3
3
  import { UpdateFlpUseCase } from "../../features/flp/UpdateFlp/abstractions.js";
4
- import { NotifyFolderChangeUseCase } from "../../features/folder/NotifyFolderChange/abstractions.js";
4
+ import { NotifyRecordChangeUseCase } from "@webiny/api-core/features/websockets/index.js";
5
+ import { FOLDER_RECORD_TYPE } from "../../features/folder/NotifyFolderChange/recordType.js";
5
6
  class UpdateFlpTaskHandlerImpl {
6
- constructor(updateFlp, notifyFolderChange){
7
+ constructor(updateFlp, notifyRecordChange){
7
8
  this.updateFlp = updateFlp;
8
- this.notifyFolderChange = notifyFolderChange;
9
+ this.notifyRecordChange = notifyRecordChange;
9
10
  }
10
11
  async run({ input, controller }) {
11
12
  try {
@@ -23,7 +24,8 @@ class UpdateFlpTaskHandlerImpl {
23
24
  }
24
25
  });
25
26
  if (continuation) return continuation;
26
- if (input.notifyIdentityId) await this.notifyFolderChange.execute({
27
+ if (input.notifyIdentityId) await this.notifyRecordChange.execute({
28
+ type: FOLDER_RECORD_TYPE,
27
29
  id: input.folder.id,
28
30
  change: "updated",
29
31
  identityId: input.notifyIdentityId
@@ -38,7 +40,7 @@ const UpdateFlpTaskHandler = TaskHandler.createImplementation({
38
40
  implementation: UpdateFlpTaskHandlerImpl,
39
41
  dependencies: [
40
42
  UpdateFlpUseCase,
41
- NotifyFolderChangeUseCase
43
+ NotifyRecordChangeUseCase
42
44
  ]
43
45
  });
44
46
  class UpdateFlpTaskImpl {
@@ -1 +1 @@
1
- {"version":3,"file":"flpTaskCatalog/tasks/updateFlp.task.js","sources":["../../../src/flpTaskCatalog/tasks/updateFlp.task.ts"],"sourcesContent":["import {\n TaskDefinition,\n TaskHandler\n} from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport { UPDATE_FLP_TASK_ID } from \"~/flp/tasks/index.js\";\nimport { type IUpdateFlpTaskInput } from \"~/types.js\";\nimport { UpdateFlpUseCase } from \"~/features/flp/UpdateFlp/abstractions.js\";\nimport { NotifyFolderChangeUseCase } from \"~/features/folder/NotifyFolderChange/abstractions.js\";\n\nclass UpdateFlpTaskHandlerImpl implements TaskHandler.Interface<IUpdateFlpTaskInput> {\n public constructor(\n private updateFlp: UpdateFlpUseCase.Interface,\n private notifyFolderChange: NotifyFolderChangeUseCase.Interface\n ) {}\n\n async run({ input, controller }: TaskHandler.RunParams<IUpdateFlpTaskInput>) {\n try {\n if (controller.runtime.isAborted()) {\n return controller.response.aborted();\n }\n\n /*\n * `response.continue()` only builds the result; it does nothing until the task returns\n * it. Returning `done` regardless used to drop the continuation, leaving the rest of a\n * large subtree with its old permissions.\n */\n let continuation: ReturnType<typeof controller.response.continue> | undefined;\n\n await this.updateFlp.execute({\n folder: input.folder,\n completed: input.completed,\n isCloseToTimeout: controller.runtime.isCloseToTimeout,\n handleTimeout: completed => {\n continuation = controller.response.continue({ ...input, completed });\n }\n });\n\n if (continuation) {\n return continuation;\n }\n\n // Only the last run tells the admin: before it, part of the subtree is still stale.\n if (input.notifyIdentityId) {\n await this.notifyFolderChange.execute({\n id: input.folder.id,\n change: \"updated\",\n identityId: input.notifyIdentityId\n });\n }\n\n return controller.response.done(\"Task done: FLP record updated.\");\n } catch (error) {\n return controller.response.error(error);\n }\n }\n}\n\nconst UpdateFlpTaskHandler = TaskHandler.createImplementation({\n implementation: UpdateFlpTaskHandlerImpl,\n dependencies: [UpdateFlpUseCase, NotifyFolderChangeUseCase]\n});\n\nclass UpdateFlpTaskImpl implements TaskDefinition.Interface {\n public readonly id = UPDATE_FLP_TASK_ID;\n public readonly title = \"ACO - Update FLP record\";\n public readonly description =\n \"Synchronizes the FLP catalog by updating the FLP record and its descendants based on the provided folder.\";\n public readonly databaseLogs = false;\n public readonly isPrivate = true;\n public readonly selfCleanup = [\"onSuccess\" as const, \"onAbort\" as const];\n\n handler = UpdateFlpTaskHandler;\n}\n\nexport const UpdateFlpTask = TaskDefinition.createImplementation({\n implementation: UpdateFlpTaskImpl,\n dependencies: []\n});\n"],"names":["UpdateFlpTaskHandlerImpl","updateFlp","notifyFolderChange","input","controller","continuation","completed","error","UpdateFlpTaskHandler","TaskHandler","UpdateFlpUseCase","NotifyFolderChangeUseCase","UpdateFlpTaskImpl","UPDATE_FLP_TASK_ID","UpdateFlpTask","TaskDefinition"],"mappings":";;;;AASA,MAAMA;IACF,YACYC,SAAqC,EACrCC,k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updateFlp.task.ts"],"sourcesContent":["import {\n TaskDefinition,\n TaskHandler\n} from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\nimport { UPDATE_FLP_TASK_ID } from \"~/flp/tasks/index.js\";\nimport { type IUpdateFlpTaskInput } from \"~/types.js\";\nimport { UpdateFlpUseCase } from \"~/features/flp/UpdateFlp/abstractions.js\";\nimport { NotifyRecordChangeUseCase } from \"@webiny/api-core/features/websockets/index.js\";\nimport { FOLDER_RECORD_TYPE } from \"~/features/folder/NotifyFolderChange/recordType.js\";\n\nclass UpdateFlpTaskHandlerImpl implements TaskHandler.Interface<IUpdateFlpTaskInput> {\n public constructor(\n private updateFlp: UpdateFlpUseCase.Interface,\n private notifyRecordChange: NotifyRecordChangeUseCase.Interface\n ) {}\n\n async run({ input, controller }: TaskHandler.RunParams<IUpdateFlpTaskInput>) {\n try {\n if (controller.runtime.isAborted()) {\n return controller.response.aborted();\n }\n\n /*\n * `response.continue()` only builds the result; it does nothing until the task returns\n * it. Returning `done` regardless used to drop the continuation, leaving the rest of a\n * large subtree with its old permissions.\n */\n let continuation: ReturnType<typeof controller.response.continue> | undefined;\n\n await this.updateFlp.execute({\n folder: input.folder,\n completed: input.completed,\n isCloseToTimeout: controller.runtime.isCloseToTimeout,\n handleTimeout: completed => {\n continuation = controller.response.continue({ ...input, completed });\n }\n });\n\n if (continuation) {\n return continuation;\n }\n\n // Only the last run tells the admin: before it, part of the subtree is still stale.\n if (input.notifyIdentityId) {\n await this.notifyRecordChange.execute({\n type: FOLDER_RECORD_TYPE,\n id: input.folder.id,\n change: \"updated\",\n identityId: input.notifyIdentityId\n });\n }\n\n return controller.response.done(\"Task done: FLP record updated.\");\n } catch (error) {\n return controller.response.error(error);\n }\n }\n}\n\nconst UpdateFlpTaskHandler = TaskHandler.createImplementation({\n implementation: UpdateFlpTaskHandlerImpl,\n dependencies: [UpdateFlpUseCase, NotifyRecordChangeUseCase]\n});\n\nclass UpdateFlpTaskImpl implements TaskDefinition.Interface {\n public readonly id = UPDATE_FLP_TASK_ID;\n public readonly title = \"ACO - Update FLP record\";\n public readonly description =\n \"Synchronizes the FLP catalog by updating the FLP record and its descendants based on the provided folder.\";\n public readonly databaseLogs = false;\n public readonly isPrivate = true;\n public readonly selfCleanup = [\"onSuccess\" as const, \"onAbort\" as const];\n\n handler = UpdateFlpTaskHandler;\n}\n\nexport const UpdateFlpTask = TaskDefinition.createImplementation({\n implementation: UpdateFlpTaskImpl,\n dependencies: []\n});\n"],"names":["UpdateFlpTaskHandlerImpl","updateFlp","notifyRecordChange","input","controller","continuation","completed","FOLDER_RECORD_TYPE","error","UpdateFlpTaskHandler","TaskHandler","UpdateFlpUseCase","NotifyRecordChangeUseCase","UpdateFlpTaskImpl","UPDATE_FLP_TASK_ID","UpdateFlpTask","TaskDefinition"],"mappings":";;;;;AAUA,MAAMA;IACF,YACYC,SAAqC,EACrCC,kBAAuD,CACjE;aAFUD,SAAS,GAATA;aACAC,kBAAkB,GAAlBA;IACT;IAEH,MAAM,IAAI,EAAEC,KAAK,EAAEC,UAAU,EAA8C,EAAE;QACzE,IAAI;YACA,IAAIA,WAAW,OAAO,CAAC,SAAS,IAC5B,OAAOA,WAAW,QAAQ,CAAC,OAAO;YAQtC,IAAIC;YAEJ,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;gBACzB,QAAQF,MAAM,MAAM;gBACpB,WAAWA,MAAM,SAAS;gBAC1B,kBAAkBC,WAAW,OAAO,CAAC,gBAAgB;gBACrD,eAAeE,CAAAA;oBACXD,eAAeD,WAAW,QAAQ,CAAC,QAAQ,CAAC;wBAAE,GAAGD,KAAK;wBAAEG;oBAAU;gBACtE;YACJ;YAEA,IAAID,cACA,OAAOA;YAIX,IAAIF,MAAM,gBAAgB,EACtB,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC;gBAClC,MAAMI;gBACN,IAAIJ,MAAM,MAAM,CAAC,EAAE;gBACnB,QAAQ;gBACR,YAAYA,MAAM,gBAAgB;YACtC;YAGJ,OAAOC,WAAW,QAAQ,CAAC,IAAI,CAAC;QACpC,EAAE,OAAOI,OAAO;YACZ,OAAOJ,WAAW,QAAQ,CAAC,KAAK,CAACI;QACrC;IACJ;AACJ;AAEA,MAAMC,uBAAuBC,YAAY,oBAAoB,CAAC;IAC1D,gBAAgBV;IAChB,cAAc;QAACW;QAAkBC;KAA0B;AAC/D;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,GAAGL;;AACd;AAEO,MAAMM,gBAAgBC,eAAe,oBAAoB,CAAC;IAC7D,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.12",
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.12",
25
+ "@webiny/api-graphql": "6.6.0-alpha.12",
26
+ "@webiny/api-headless-cms": "6.6.0-alpha.12",
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.12",
29
+ "@webiny/event-handler-core": "6.6.0-alpha.12",
30
+ "@webiny/feature": "6.6.0-alpha.12",
31
+ "@webiny/handler": "6.6.0-alpha.12",
32
+ "@webiny/shared-aco": "6.6.0-alpha.12",
33
+ "@webiny/utils": "6.6.0-alpha.12",
34
+ "@webiny/validation": "6.6.0-alpha.12",
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.12",
40
+ "@webiny/api-core-testing": "6.6.0-alpha.12",
41
+ "@webiny/api-file-manager": "6.6.0-alpha.12",
42
+ "@webiny/api-headless-cms-testing": "6.6.0-alpha.12",
43
+ "@webiny/build-tools": "6.6.0-alpha.12",
44
+ "@webiny/plugins": "6.6.0-alpha.12",
45
+ "@webiny/wcp": "6.6.0-alpha.12",
47
46
  "graphql": "16.14.2",
48
47
  "rimraf": "6.1.3",
49
48
  "typescript": "7.0.2",
@@ -1,48 +0,0 @@
1
- import { z } from "zod";
2
- import { AiSdkToolDefinition, AiSdkToolHandler } from "@webiny/api-core/features/ai/index.js";
3
- import { CreateTeam } from "@webiny/api-core/features/security/teams/CreateTeam/index.js";
4
- declare const inputSchema: z.ZodObject<{
5
- name: z.ZodString;
6
- slug: z.ZodString;
7
- description: z.ZodOptional<z.ZodString>;
8
- roles: z.ZodArray<z.ZodString>;
9
- }, z.core.$strip>;
10
- type Input = z.infer<typeof inputSchema>;
11
- interface CreatedTeam {
12
- id: string;
13
- name: string;
14
- slug: string;
15
- roles: string[];
16
- }
17
- declare class CreateTeamToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {
18
- private createTeam;
19
- constructor(createTeam: CreateTeam.Interface);
20
- execute(input: Input): Promise<CreatedTeam>;
21
- }
22
- /**
23
- * Creates a team.
24
- *
25
- * Not read-only, so it needs approval: a team is an access-control object, and the roles it carries
26
- * decide what its members can do. The user should see which roles are being granted before it exists.
27
- */
28
- declare class CreateTeamToolImpl implements AiSdkToolDefinition.Interface<Input> {
29
- readonly name = "createTeam";
30
- readonly title = "Create team";
31
- readonly description = "Creates a team with a set of roles. Call listRoles first and pass what it returns; do not guess role identifiers. Requires user approval.";
32
- readonly inputSchema: z.ZodObject<{
33
- name: z.ZodString;
34
- slug: z.ZodString;
35
- description: z.ZodOptional<z.ZodString>;
36
- roles: z.ZodArray<z.ZodString>;
37
- }, z.core.$strip>;
38
- readonly annotations: {
39
- readOnlyHint: boolean;
40
- };
41
- readonly handler: typeof CreateTeamToolHandlerImpl & {
42
- __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/ai/abstractions").IAiSdkToolHandler<any>>;
43
- };
44
- }
45
- export declare const CreateTeamTool: typeof CreateTeamToolImpl & {
46
- __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/ai/abstractions").IAiSdkToolDefinition<any>>;
47
- };
48
- export {};
@@ -1,56 +0,0 @@
1
- import { z } from "zod";
2
- import { AiSdkToolDefinition, AiSdkToolHandler } from "@webiny/api-core/features/ai/index.js";
3
- import { CreateTeam } from "@webiny/api-core/features/security/teams/CreateTeam/index.js";
4
- import { descriptionOnCreate } from "@webiny/api-core/features/security/shared/index.js";
5
- const inputSchema = z.object({
6
- name: z.string().describe("Human-readable team name, e.g. 'Marketing'."),
7
- slug: z.string().describe("URL-safe identifier, e.g. 'marketing'. Lowercase, hyphens instead of spaces."),
8
- description: z.string().max(500).optional().describe("What the team is for. Shown in the admin UI. Omit it if the user did not say."),
9
- roles: z.array(z.string()).describe("Roles from listRoles. Prefer the `id`; a `slug` is accepted and resolved for you. Resolve them with listRoles first, since an unknown value is rejected rather than stored.")
10
- });
11
- class CreateTeamToolHandlerImpl {
12
- constructor(createTeam){
13
- this.createTeam = createTeam;
14
- }
15
- async execute(input) {
16
- const result = await this.createTeam.execute({
17
- name: input.name,
18
- slug: input.slug,
19
- description: descriptionOnCreate(input.description),
20
- roles: input.roles
21
- });
22
- if (result.isFail()) throw new Error(`Could not create the team: ${result.error.message}`);
23
- const team = result.value;
24
- return {
25
- id: team.id,
26
- name: team.name,
27
- slug: team.slug,
28
- roles: team.roles
29
- };
30
- }
31
- }
32
- const CreateTeamToolHandler = AiSdkToolHandler.createImplementation({
33
- implementation: CreateTeamToolHandlerImpl,
34
- dependencies: [
35
- CreateTeam
36
- ]
37
- });
38
- class CreateTeamToolImpl {
39
- constructor(){
40
- this.name = "createTeam";
41
- this.title = "Create team";
42
- this.description = "Creates a team with a set of roles. Call listRoles first and pass what it returns; do not guess role identifiers. Requires user approval.";
43
- this.inputSchema = inputSchema;
44
- this.annotations = {
45
- readOnlyHint: false
46
- };
47
- this.handler = CreateTeamToolHandler;
48
- }
49
- }
50
- const CreateTeamTool = AiSdkToolDefinition.createImplementation({
51
- implementation: CreateTeamToolImpl,
52
- dependencies: []
53
- });
54
- export { CreateTeamTool };
55
-
56
- //# sourceMappingURL=CreateTeamTool.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"features/ai/CreateTeamTool.js","sources":["../../../src/features/ai/CreateTeamTool.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { AiSdkToolDefinition, AiSdkToolHandler } from \"@webiny/api-core/features/ai/index.js\";\nimport { CreateTeam } from \"@webiny/api-core/features/security/teams/CreateTeam/index.js\";\nimport { descriptionOnCreate } from \"@webiny/api-core/features/security/shared/index.js\";\n\nconst inputSchema = z.object({\n name: z.string().describe(\"Human-readable team name, e.g. 'Marketing'.\"),\n slug: z\n .string()\n .describe(\"URL-safe identifier, e.g. 'marketing'. Lowercase, hyphens instead of spaces.\"),\n /*\n * Optional and capped, mirroring the use case's own schema. Requiring it made the model invent a\n * description for every team; `CreateTeam` treats an absent one as empty via `descriptionOnCreate`.\n */\n description: z\n .string()\n .max(500)\n .optional()\n .describe(\"What the team is for. Shown in the admin UI. Omit it if the user did not say.\"),\n roles: z\n .array(z.string())\n .describe(\n \"Roles from listRoles. Prefer the `id`; a `slug` is accepted and resolved for you. Resolve them with listRoles first, since an unknown value is rejected rather than stored.\"\n )\n});\n\ntype Input = z.infer<typeof inputSchema>;\n\ninterface CreatedTeam {\n id: string;\n name: string;\n slug: string;\n roles: string[];\n}\n\nclass CreateTeamToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {\n constructor(private createTeam: CreateTeam.Interface) {}\n\n async execute(input: Input): Promise<CreatedTeam> {\n /*\n * Roles go through untouched. `CreateTeam` accepts a role id or a slug and resolves either to\n * the id a team stores, so the tool has nothing to add: doing it here too would read the roles\n * a second time and leave two copies of the same rule to keep in step.\n */\n const result = await this.createTeam.execute({\n name: input.name,\n slug: input.slug,\n // An omitted description becomes \"\", the same mapping the use case applies to its own input.\n description: descriptionOnCreate(input.description),\n roles: input.roles\n });\n\n if (result.isFail()) {\n throw new Error(`Could not create the team: ${result.error.message}`);\n }\n\n const team = result.value;\n\n return {\n id: team.id,\n name: team.name,\n slug: team.slug,\n // From the created team, so the caller sees the resolved ids that were actually stored.\n roles: team.roles\n };\n }\n}\n\nconst CreateTeamToolHandler = AiSdkToolHandler.createImplementation({\n implementation: CreateTeamToolHandlerImpl,\n dependencies: [CreateTeam]\n});\n\n/**\n * Creates a team.\n *\n * Not read-only, so it needs approval: a team is an access-control object, and the roles it carries\n * decide what its members can do. The user should see which roles are being granted before it exists.\n */\nclass CreateTeamToolImpl implements AiSdkToolDefinition.Interface<Input> {\n readonly name = \"createTeam\";\n readonly title = \"Create team\";\n readonly description =\n \"Creates a team with a set of roles. Call listRoles first and pass what it returns; do not guess role identifiers. Requires user approval.\";\n readonly inputSchema = inputSchema;\n readonly annotations = { readOnlyHint: false };\n readonly handler = CreateTeamToolHandler;\n}\n\nexport const CreateTeamTool = AiSdkToolDefinition.createImplementation({\n implementation: CreateTeamToolImpl,\n dependencies: []\n});\n"],"names":["inputSchema","z","CreateTeamToolHandlerImpl","createTeam","input","result","descriptionOnCreate","Error","team","CreateTeamToolHandler","AiSdkToolHandler","CreateTeam","CreateTeamToolImpl","CreateTeamTool","AiSdkToolDefinition"],"mappings":";;;;AAKA,MAAMA,cAAcC,EAAE,MAAM,CAAC;IACzB,MAAMA,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC1B,MAAMA,EAAAA,MACK,GACN,QAAQ,CAAC;IAKd,aAAaA,EAAAA,MACF,GACN,GAAG,CAAC,KACJ,QAAQ,GACR,QAAQ,CAAC;IACd,OAAOA,EAAAA,KACG,CAACA,EAAE,MAAM,IACd,QAAQ,CACL;AAEZ;AAWA,MAAMC;IACF,YAAoBC,UAAgC,CAAE;aAAlCA,UAAU,GAAVA;IAAmC;IAEvD,MAAM,QAAQC,KAAY,EAAwB;QAM9C,MAAMC,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;YACzC,MAAMD,MAAM,IAAI;YAChB,MAAMA,MAAM,IAAI;YAEhB,aAAaE,oBAAoBF,MAAM,WAAW;YAClD,OAAOA,MAAM,KAAK;QACtB;QAEA,IAAIC,OAAO,MAAM,IACb,MAAM,IAAIE,MAAM,CAAC,2BAA2B,EAAEF,OAAO,KAAK,CAAC,OAAO,EAAE;QAGxE,MAAMG,OAAOH,OAAO,KAAK;QAEzB,OAAO;YACH,IAAIG,KAAK,EAAE;YACX,MAAMA,KAAK,IAAI;YACf,MAAMA,KAAK,IAAI;YAEf,OAAOA,KAAK,K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