@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
@@ -0,0 +1,72 @@
1
+ import { z } from "zod";
2
+ import { AiSdkToolDefinition, AiSdkToolHandler } from "@webiny/api-core/features/ai/index.js";
3
+ import { GetFolderUseCase } from "../folder/GetFolder/index.js";
4
+ import { UpdateFolderUseCase } from "../folder/UpdateFolder/index.js";
5
+ const inputSchema = z.object({
6
+ folderId: z.string().describe("Folder id as returned by listFolders."),
7
+ currentTitle: z.string().describe("The folder's current title, exactly as listFolders returned it. The update is refused if it does not match."),
8
+ title: z.string().optional().describe("New title. Omit it to keep the current one."),
9
+ slug: z.string().optional().describe("New URL-safe identifier, lowercase with hyphens. It is part of the folder's path. Omit it to keep the current one; a new title does not change it."),
10
+ parentId: z.string().nullable().optional().describe("Id of the folder to move this one into, from listFolders and of the same type. null moves it to the root. Omit it to leave the folder where it is.")
11
+ });
12
+ class UpdateFolderToolHandlerImpl {
13
+ constructor(getFolder, updateFolder){
14
+ this.getFolder = getFolder;
15
+ this.updateFolder = updateFolder;
16
+ }
17
+ async execute(input) {
18
+ if (void 0 === input.title && void 0 === input.slug && void 0 === input.parentId) throw new Error("Nothing to update: pass a new title, a new slug or a parentId to move the folder.");
19
+ const found = await this.getFolder.execute(input.folderId);
20
+ if (found.isFail()) throw new Error(`Folder "${input.folderId}" not found: ${found.error.message}. Call listFolders for valid ids.`);
21
+ const folder = found.value;
22
+ if (folder.title !== input.currentTitle) throw new Error(`Folder "${input.folderId}" is titled "${folder.title}", not "${input.currentTitle}", so nothing was updated. Check the folder with listFolders.`);
23
+ if (input.parentId) await this.ensureSameType(folder, input.parentId);
24
+ const params = {};
25
+ if (void 0 !== input.title) params.title = input.title;
26
+ if (void 0 !== input.slug) params.slug = input.slug;
27
+ if (void 0 !== input.parentId) params.parentId = input.parentId;
28
+ const result = await this.updateFolder.execute(folder.id, params);
29
+ if (result.isFail()) throw new Error(`Could not update the folder: ${result.error.message}`);
30
+ const updated = result.value;
31
+ return {
32
+ id: updated.id,
33
+ title: updated.title,
34
+ slug: updated.slug,
35
+ path: updated.path,
36
+ parentId: updated.parentId ?? null,
37
+ type: updated.type
38
+ };
39
+ }
40
+ async ensureSameType(folder, parentId) {
41
+ const parentResult = await this.getFolder.execute(parentId);
42
+ if (parentResult.isFail()) throw new Error(`Parent folder "${parentId}" not found: ${parentResult.error.message}. Call listFolders for valid ids.`);
43
+ const parent = parentResult.value;
44
+ if (parent.type !== folder.type) throw new Error(`Folder "${parent.title}" is of type "${parent.type}", and this folder is "${folder.type}". A folder can only move within its own type.`);
45
+ }
46
+ }
47
+ const UpdateFolderToolHandler = AiSdkToolHandler.createImplementation({
48
+ implementation: UpdateFolderToolHandlerImpl,
49
+ dependencies: [
50
+ GetFolderUseCase,
51
+ UpdateFolderUseCase
52
+ ]
53
+ });
54
+ class UpdateFolderToolImpl {
55
+ constructor(){
56
+ this.name = "updateFolder";
57
+ this.title = "Update folder";
58
+ this.description = "Renames a folder, changes its slug, or moves it under another folder of the same type (parentId null moves it to the root). Call listFolders first for the id, the exact current title and the new parent. Access rules are changed with grantFolderAccess and revokeFolderAccess, not here. Requires user approval.";
59
+ this.inputSchema = inputSchema;
60
+ this.annotations = {
61
+ readOnlyHint: false
62
+ };
63
+ this.handler = UpdateFolderToolHandler;
64
+ }
65
+ }
66
+ const UpdateFolderTool = AiSdkToolDefinition.createImplementation({
67
+ implementation: UpdateFolderToolImpl,
68
+ dependencies: []
69
+ });
70
+ export { UpdateFolderTool };
71
+
72
+ //# sourceMappingURL=UpdateFolderTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/ai/UpdateFolderTool.js","sources":["../../../src/features/ai/UpdateFolderTool.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { AiSdkToolDefinition } from \"@webiny/api-core/features/ai/index.js\";\nimport { AiSdkToolHandler } from \"@webiny/api-core/features/ai/index.js\";\nimport { GetFolderUseCase } from \"~/features/folder/GetFolder/index.js\";\nimport { UpdateFolderUseCase } from \"~/features/folder/UpdateFolder/index.js\";\nimport type { UpdateFolderParams } from \"~/folder/folder.types.js\";\n\nconst inputSchema = z.object({\n folderId: z.string().describe(\"Folder id as returned by listFolders.\"),\n currentTitle: z\n .string()\n .describe(\n \"The folder's current title, exactly as listFolders returned it. The update is refused if it does not match.\"\n ),\n title: z.string().optional().describe(\"New title. Omit it to keep the current one.\"),\n slug: z\n .string()\n .optional()\n .describe(\n \"New URL-safe identifier, lowercase with hyphens. It is part of the folder's path. Omit it to keep the current one; a new title does not change it.\"\n ),\n parentId: z\n .string()\n .nullable()\n .optional()\n .describe(\n \"Id of the folder to move this one into, from listFolders and of the same type. null moves it to the root. Omit it to leave the folder where it is.\"\n )\n});\n\ntype Input = z.infer<typeof inputSchema>;\n\ninterface UpdatedFolder {\n id: string;\n title: string;\n slug: string;\n path: string;\n parentId: string | null;\n type: string;\n}\n\n/*\n * The current title is part of the input for the same reason as in deleteFolder: the approval then\n * names the folder that changes, and the handler checks that name against the stored folder.\n *\n * Only the fields the model passed are sent. Access rules are left out, so the update keeps the\n * stored ones, and `UpdateFolderUseCase` refuses a move into the folder itself or its subtree.\n *\n * A move under a folder of another type is refused here only. The folder feature accepts a parent\n * of another type on create and on update, but the admin lists each type's folders separately, so a\n * File Manager folder moved under a content model's folder disappears from both trees.\n */\nclass UpdateFolderToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {\n constructor(\n private getFolder: GetFolderUseCase.Interface,\n private updateFolder: UpdateFolderUseCase.Interface\n ) {}\n\n async execute(input: Input): Promise<UpdatedFolder> {\n if (input.title === undefined && input.slug === undefined && input.parentId === undefined) {\n throw new Error(\n \"Nothing to update: pass a new title, a new slug or a parentId to move the folder.\"\n );\n }\n\n const found = await this.getFolder.execute(input.folderId);\n\n if (found.isFail()) {\n throw new Error(\n `Folder \"${input.folderId}\" not found: ${found.error.message}. Call listFolders for valid ids.`\n );\n }\n\n const folder = found.value;\n\n if (folder.title !== input.currentTitle) {\n throw new Error(\n `Folder \"${input.folderId}\" is titled \"${folder.title}\", not \"${input.currentTitle}\", so nothing was updated. Check the folder with listFolders.`\n );\n }\n\n if (input.parentId) {\n await this.ensureSameType(folder, input.parentId);\n }\n\n const params: UpdateFolderParams = {};\n\n if (input.title !== undefined) {\n params.title = input.title;\n }\n\n if (input.slug !== undefined) {\n params.slug = input.slug;\n }\n\n if (input.parentId !== undefined) {\n params.parentId = input.parentId;\n }\n\n const result = await this.updateFolder.execute(folder.id, params);\n\n if (result.isFail()) {\n throw new Error(`Could not update the folder: ${result.error.message}`);\n }\n\n const updated = result.value;\n\n return {\n id: updated.id,\n title: updated.title,\n slug: updated.slug,\n path: updated.path,\n parentId: updated.parentId ?? null,\n type: updated.type\n };\n }\n\n private async ensureSameType(folder: { type: string }, parentId: string): Promise<void> {\n const parentResult = await this.getFolder.execute(parentId);\n\n if (parentResult.isFail()) {\n throw new Error(\n `Parent folder \"${parentId}\" not found: ${parentResult.error.message}. Call listFolders for valid ids.`\n );\n }\n\n const parent = parentResult.value;\n\n if (parent.type !== folder.type) {\n throw new Error(\n `Folder \"${parent.title}\" is of type \"${parent.type}\", and this folder is \"${folder.type}\". A folder can only move within its own type.`\n );\n }\n }\n}\n\nconst UpdateFolderToolHandler = AiSdkToolHandler.createImplementation({\n implementation: UpdateFolderToolHandlerImpl,\n dependencies: [GetFolderUseCase, UpdateFolderUseCase]\n});\n\n/**\n * Renames or moves one folder.\n *\n * Not destructive: the old title, slug and parent can be set again. A new slug or parent changes the\n * folder's path and its subfolders' paths, and with them which code-defined access rules apply, so\n * it still waits for the user to approve the exact arguments.\n */\nclass UpdateFolderToolImpl implements AiSdkToolDefinition.Interface<Input> {\n readonly name = \"updateFolder\";\n readonly title = \"Update folder\";\n readonly description =\n \"Renames a folder, changes its slug, or moves it under another folder of the same type (parentId null moves it to the root). Call listFolders first for the id, the exact current title and the new parent. Access rules are changed with grantFolderAccess and revokeFolderAccess, not here. Requires user approval.\";\n readonly inputSchema = inputSchema;\n readonly annotations = { readOnlyHint: false };\n readonly handler = UpdateFolderToolHandler;\n}\n\nexport const UpdateFolderTool = AiSdkToolDefinition.createImplementation({\n implementation: UpdateFolderToolImpl,\n dependencies: []\n});\n"],"names":["inputSchema","z","UpdateFolderToolHandlerImpl","getFolder","updateFolder","input","undefined","Error","found","folder","params","result","updated","parentId","parentResult","parent","UpdateFolderToolHandler","AiSdkToolHandler","GetFolderUseCase","UpdateFolderUseCase","UpdateFolderToolImpl","UpdateFolderTool","AiSdkToolDefinition"],"mappings":";;;;AAOA,MAAMA,cAAcC,EAAE,MAAM,CAAC;IACzB,UAAUA,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC9B,cAAcA,EAAAA,MACH,GACN,QAAQ,CACL;IAER,OAAOA,EAAE,MAAM,GAAG,QAAQ,GAAG,QAAQ,CAAC;IACtC,MAAMA,EAAAA,MACK,GACN,QAAQ,GACR,QAAQ,CACL;IAER,UAAUA,EAAAA,MACC,GACN,QAAQ,GACR,QAAQ,GACR,QAAQ,CACL;AAEZ;AAwBA,MAAMC;IACF,YACYC,SAAqC,EACrCC,YAA2C,CACrD;aAFUD,SAAS,GAATA;aACAC,YAAY,GAAZA;IACT;IAEH,MAAM,QAAQC,KAAY,EAA0B;QAChD,IAAIA,AAAgBC,WAAhBD,MAAM,KAAK,IAAkBA,AAAeC,WAAfD,MAAM,IAAI,IAAkBA,AAAmBC,WAAnBD,MAAM,QAAQ,EACvE,MAAM,IAAIE,MACN;QAIR,MAAMC,QAAQ,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAACH,MAAM,QAAQ;QAEzD,IAAIG,MAAM,MAAM,IACZ,MAAM,IAAID,MACN,CAAC,QAAQ,EAAEF,MAAM,QAAQ,CAAC,aAAa,EAAEG,MAAM,KAAK,CAAC,OAAO,CAAC,iCAAiC,CAAC;QAIvG,MAAMC,SAASD,MAAM,KAAK;QAE1B,IAAIC,OAAO,KAAK,KAAKJ,MAAM,YAAY,EACnC,MAAM,IAAIE,MACN,CAAC,QAAQ,EAAEF,MAAM,QAAQ,CAAC,aAAa,EAAEI,OAAO,KAAK,CAAC,QAAQ,EAAEJ,MAAM,YAAY,CAAC,6DAA6D,CAAC;QAIzJ,IAAIA,MAAM,QAAQ,EACd,MAAM,IAAI,CAAC,cAAc,CAACI,QAAQJ,MAAM,QAAQ;QAGpD,MAAMK,SAA6B,CAAC;QAEpC,IAAIL,AAAgBC,WAAhBD,MAAM,KAAK,EACXK,OAAO,KAAK,GAAGL,MAAM,KAAK;QAG9B,IAAIA,AAAeC,WAAfD,MAAM,IAAI,EACVK,OAAO,IAAI,GAAGL,MAAM,IAAI;QAG5B,IAAIA,AAAmBC,WAAnBD,MAAM,QAAQ,EACdK,OAAO,QAAQ,GAAGL,MAAM,QAAQ;QAGpC,MAAMM,SAAS,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,CAACF,OAAO,EAAE,EAAEC;QAE1D,IAAIC,OAAO,MAAM,IACb,MAAM,IAAIJ,MAAM,CAAC,6BAA6B,EAAEI,OAAO,KAAK,CAAC,OAAO,EAAE;QAG1E,MAAMC,UAAUD,OAAO,KAAK;QAE5B,OAAO;YACH,IAAIC,QAAQ,EAAE;YACd,OAAOA,QAAQ,KAAK;YACpB,MAAMA,QAAQ,IAAI;YAClB,MAAMA,QAAQ,IAAI;YAClB,UAAUA,QAAQ,QAAQ,IAAI;YAC9B,MAAMA,QAAQ,IAAI;QACtB;IACJ;IAEA,MAAc,eAAeH,MAAwB,EAAEI,QAAgB,EAAiB;QACpF,MAAMC,eAAe,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAACD;QAElD,IAAIC,aAAa,MAAM,IACnB,MAAM,IAAIP,MACN,CAAC,eAAe,EAAEM,SAAS,aAAa,EAAEC,aAAa,KAAK,CAAC,OAAO,CAAC,iCAAiC,CAAC;QAI/G,MAAMC,SAASD,aAAa,KAAK;QAEjC,IAAIC,OAAO,IAAI,KAAKN,OAAO,IAAI,EAC3B,MAAM,IAAIF,MACN,CAAC,QAAQ,EAAEQ,OAAO,KAAK,CAAC,cAAc,EAAEA,OAAO,IAAI,CAAC,uBAAuB,EAAEN,OAAO,IAAI,CAAC,8CAA8C,CAAC;IAGpJ;AACJ;AAEA,MAAMO,0BAA0BC,iBAAiB,oBAAoB,CAAC;IAClE,gBAAgBf;IAChB,cAAc;QAACgB;QAAkBC;KAAoB;AACzD;AASA,MAAMC;;aACO,IAAI,GAAG;aACP,KAAK,GAAG;aACR,WAAW,GAChB;aACK,WAAW,GAAGpB;aACd,WAAW,GAAG;YAAE,cAAc;QAAM;aACpC,OAAO,GAAGgB;;AACvB;AAEO,MAAMK,mBAAmBC,oBAAoB,oBAAoB,CAAC;IACrE,gBAAgBF;IAChB,cAAc,EAAE;AACpB"}
@@ -0,0 +1,46 @@
1
+ import { z } from "zod";
2
+ import { AiSdkToolDefinition } from "@webiny/api-core/features/ai/index.js";
3
+ import { AiSdkToolHandler } from "@webiny/api-core/features/ai/index.js";
4
+ import { UpdateRoleUseCase } from "@webiny/api-core/features/security/roles/UpdateRole/index.js";
5
+ declare const inputSchema: z.ZodObject<{
6
+ roleId: z.ZodString;
7
+ name: z.ZodOptional<z.ZodString>;
8
+ description: z.ZodOptional<z.ZodString>;
9
+ }, z.core.$strip>;
10
+ type Input = z.infer<typeof inputSchema>;
11
+ interface UpdatedRole {
12
+ id: string;
13
+ name: string;
14
+ slug: string;
15
+ description: string;
16
+ }
17
+ declare class UpdateRoleToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {
18
+ private updateRole;
19
+ constructor(updateRole: UpdateRoleUseCase.Interface);
20
+ execute(input: Input): Promise<UpdatedRole>;
21
+ }
22
+ /**
23
+ * Renames a role or changes its description. Permissions are out of reach for the same reason as in
24
+ * `createRole`. The slug cannot change because `UpdateRoleUseCase` does not accept one.
25
+ */
26
+ declare class UpdateRoleToolImpl implements AiSdkToolDefinition.Interface<Input> {
27
+ readonly name = "updateRole";
28
+ readonly title = "Update role";
29
+ readonly description = "Changes a role's name or description. Call listRoles first for the id. Permissions cannot be changed with this tool; the user edits them on the Roles screen. Roles defined in code cannot be changed. Requires user approval.";
30
+ readonly inputSchema: z.ZodObject<{
31
+ roleId: z.ZodString;
32
+ name: z.ZodOptional<z.ZodString>;
33
+ description: z.ZodOptional<z.ZodString>;
34
+ }, z.core.$strip>;
35
+ readonly annotations: {
36
+ readOnlyHint: boolean;
37
+ idempotentHint: boolean;
38
+ };
39
+ readonly handler: typeof UpdateRoleToolHandlerImpl & {
40
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/ai/abstractions").IAiSdkToolHandler<any>>;
41
+ };
42
+ }
43
+ export declare const UpdateRoleTool: typeof UpdateRoleToolImpl & {
44
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/ai/abstractions").IAiSdkToolDefinition<any>>;
45
+ };
46
+ export {};
@@ -0,0 +1,53 @@
1
+ import { z } from "zod";
2
+ import { AiSdkToolDefinition, AiSdkToolHandler } from "@webiny/api-core/features/ai/index.js";
3
+ import { UpdateRoleUseCase } from "@webiny/api-core/features/security/roles/UpdateRole/index.js";
4
+ const inputSchema = z.object({
5
+ roleId: z.string().describe("Role id as returned by listRoles."),
6
+ name: z.string().min(3).optional().describe("New role name. Omit it to keep the current one."),
7
+ description: z.string().max(500).optional().describe("New description. Omit it to keep the current one; an empty string clears it.")
8
+ });
9
+ class UpdateRoleToolHandlerImpl {
10
+ constructor(updateRole){
11
+ this.updateRole = updateRole;
12
+ }
13
+ async execute(input) {
14
+ const result = await this.updateRole.execute(input.roleId, {
15
+ name: input.name,
16
+ description: input.description
17
+ });
18
+ if (result.isFail()) throw new Error(`Could not update the role: ${result.error.message}`);
19
+ const role = result.value;
20
+ return {
21
+ id: role.id,
22
+ name: role.name,
23
+ slug: role.slug,
24
+ description: role.description
25
+ };
26
+ }
27
+ }
28
+ const UpdateRoleToolHandler = AiSdkToolHandler.createImplementation({
29
+ implementation: UpdateRoleToolHandlerImpl,
30
+ dependencies: [
31
+ UpdateRoleUseCase
32
+ ]
33
+ });
34
+ class UpdateRoleToolImpl {
35
+ constructor(){
36
+ this.name = "updateRole";
37
+ this.title = "Update role";
38
+ this.description = "Changes a role's name or description. Call listRoles first for the id. Permissions cannot be changed with this tool; the user edits them on the Roles screen. Roles defined in code cannot be changed. Requires user approval.";
39
+ this.inputSchema = inputSchema;
40
+ this.annotations = {
41
+ readOnlyHint: false,
42
+ idempotentHint: true
43
+ };
44
+ this.handler = UpdateRoleToolHandler;
45
+ }
46
+ }
47
+ const UpdateRoleTool = AiSdkToolDefinition.createImplementation({
48
+ implementation: UpdateRoleToolImpl,
49
+ dependencies: []
50
+ });
51
+ export { UpdateRoleTool };
52
+
53
+ //# sourceMappingURL=UpdateRoleTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/ai/UpdateRoleTool.js","sources":["../../../src/features/ai/UpdateRoleTool.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { AiSdkToolDefinition } from \"@webiny/api-core/features/ai/index.js\";\nimport { AiSdkToolHandler } from \"@webiny/api-core/features/ai/index.js\";\nimport { UpdateRoleUseCase } from \"@webiny/api-core/features/security/roles/UpdateRole/index.js\";\n\nconst inputSchema = z.object({\n roleId: z.string().describe(\"Role id as returned by listRoles.\"),\n name: z.string().min(3).optional().describe(\"New role name. Omit it to keep the current one.\"),\n description: z\n .string()\n .max(500)\n .optional()\n .describe(\"New description. Omit it to keep the current one; an empty string clears it.\")\n});\n\ntype Input = z.infer<typeof inputSchema>;\n\ninterface UpdatedRole {\n id: string;\n name: string;\n slug: string;\n description: string;\n}\n\nclass UpdateRoleToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {\n constructor(private updateRole: UpdateRoleUseCase.Interface) {}\n\n async execute(input: Input): Promise<UpdatedRole> {\n // A field the model left out arrives as `undefined`; `UpdateRoleUseCase` leaves those alone.\n const result = await this.updateRole.execute(input.roleId, {\n name: input.name,\n description: input.description\n });\n\n if (result.isFail()) {\n throw new Error(`Could not update the role: ${result.error.message}`);\n }\n\n const role = result.value;\n\n return { id: role.id, name: role.name, slug: role.slug, description: role.description };\n }\n}\n\nconst UpdateRoleToolHandler = AiSdkToolHandler.createImplementation({\n implementation: UpdateRoleToolHandlerImpl,\n dependencies: [UpdateRoleUseCase]\n});\n\n/**\n * Renames a role or changes its description. Permissions are out of reach for the same reason as in\n * `createRole`. The slug cannot change because `UpdateRoleUseCase` does not accept one.\n */\nclass UpdateRoleToolImpl implements AiSdkToolDefinition.Interface<Input> {\n readonly name = \"updateRole\";\n readonly title = \"Update role\";\n readonly description =\n \"Changes a role's name or description. Call listRoles first for the id. Permissions cannot be changed with this tool; the user edits them on the Roles screen. Roles defined in code cannot be changed. Requires user approval.\";\n readonly inputSchema = inputSchema;\n readonly annotations = { readOnlyHint: false, idempotentHint: true };\n readonly handler = UpdateRoleToolHandler;\n}\n\nexport const UpdateRoleTool = AiSdkToolDefinition.createImplementation({\n implementation: UpdateRoleToolImpl,\n dependencies: []\n});\n"],"names":["inputSchema","z","UpdateRoleToolHandlerImpl","updateRole","input","result","Error","role","UpdateRoleToolHandler","AiSdkToolHandler","UpdateRoleUseCase","UpdateRoleToolImpl","UpdateRoleTool","AiSdkToolDefinition"],"mappings":";;;AAKA,MAAMA,cAAcC,EAAE,MAAM,CAAC;IACzB,QAAQA,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC5B,MAAMA,EAAE,MAAM,GAAG,GAAG,CAAC,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAC5C,aAAaA,EAAAA,MACF,GACN,GAAG,CAAC,KACJ,QAAQ,GACR,QAAQ,CAAC;AAClB;AAWA,MAAMC;IACF,YAAoBC,UAAuC,CAAE;aAAzCA,UAAU,GAAVA;IAA0C;IAE9D,MAAM,QAAQC,KAAY,EAAwB;QAE9C,MAAMC,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAACD,MAAM,MAAM,EAAE;YACvD,MAAMA,MAAM,IAAI;YAChB,aAAaA,MAAM,WAAW;QAClC;QAEA,IAAIC,OAAO,MAAM,IACb,MAAM,IAAIC,MAAM,CAAC,2BAA2B,EAAED,OAAO,KAAK,CAAC,OAAO,EAAE;QAGxE,MAAME,OAAOF,OAAO,KAAK;QAEzB,OAAO;YAAE,IAAIE,KAAK,EAAE;YAAE,MAAMA,KAAK,IAAI;YAAE,MAAMA,KAAK,IAAI;YAAE,aAAaA,KAAK,WAAW;QAAC;IAC1F;AACJ;AAEA,MAAMC,wBAAwBC,iBAAiB,oBAAoB,CAAC;IAChE,gBAAgBP;IAChB,cAAc;QAACQ;KAAkB;AACrC;AAMA,MAAMC;;aACO,IAAI,GAAG;aACP,KAAK,GAAG;aACR,WAAW,GAChB;aACK,WAAW,GAAGX;aACd,WAAW,GAAG;YAAE,cAAc;YAAO,gBAAgB;QAAK;aAC1D,OAAO,GAAGQ;;AACvB;AAEO,MAAMI,iBAAiBC,oBAAoB,oBAAoB,CAAC;IACnE,gBAAgBF;IAChB,cAAc,EAAE;AACpB"}
@@ -0,0 +1,52 @@
1
+ import { z } from "zod";
2
+ import { AiSdkToolDefinition, AiSdkToolHandler } from "@webiny/api-core/features/ai/index.js";
3
+ import { UpdateTeam } from "@webiny/api-core/features/security/teams/UpdateTeam/index.js";
4
+ declare const inputSchema: z.ZodObject<{
5
+ teamId: z.ZodString;
6
+ name: z.ZodOptional<z.ZodString>;
7
+ description: z.ZodOptional<z.ZodString>;
8
+ roles: z.ZodOptional<z.ZodArray<z.ZodString>>;
9
+ }, z.core.$strip>;
10
+ type Input = z.infer<typeof inputSchema>;
11
+ interface UpdatedTeam {
12
+ id: string;
13
+ name: string;
14
+ slug: string;
15
+ description: string;
16
+ roles: string[];
17
+ }
18
+ declare class UpdateTeamToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {
19
+ private updateTeam;
20
+ constructor(updateTeam: UpdateTeam.Interface);
21
+ execute(input: Input): Promise<UpdatedTeam>;
22
+ }
23
+ /**
24
+ * Changes a team's name, description or roles. The slug cannot change: folder permissions refer to
25
+ * teams by slug.
26
+ *
27
+ * Needs approval for the same reason as `createTeam`: the roles decide what the team's members can
28
+ * do. `roles` replaces the stored list, and the approval shows that whole list, so a role the model
29
+ * left out is visible as missing before anything is written.
30
+ */
31
+ declare class UpdateTeamToolImpl implements AiSdkToolDefinition.Interface<Input> {
32
+ readonly name = "updateTeam";
33
+ readonly title = "Update team";
34
+ readonly description = "Changes a team's name, description or roles. Call listTeams first for the id. `roles` replaces the team's whole role list, so pass every role it should keep; call listRoles to resolve them. System teams and teams defined in code cannot be changed. Requires user approval.";
35
+ readonly inputSchema: z.ZodObject<{
36
+ teamId: z.ZodString;
37
+ name: z.ZodOptional<z.ZodString>;
38
+ description: z.ZodOptional<z.ZodString>;
39
+ roles: z.ZodOptional<z.ZodArray<z.ZodString>>;
40
+ }, z.core.$strip>;
41
+ readonly annotations: {
42
+ readOnlyHint: boolean;
43
+ idempotentHint: boolean;
44
+ };
45
+ readonly handler: typeof UpdateTeamToolHandlerImpl & {
46
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/ai/abstractions").IAiSdkToolHandler<any>>;
47
+ };
48
+ }
49
+ export declare const UpdateTeamTool: typeof UpdateTeamToolImpl & {
50
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/ai/abstractions").IAiSdkToolDefinition<any>>;
51
+ };
52
+ export {};
@@ -0,0 +1,56 @@
1
+ import { z } from "zod";
2
+ import { AiSdkToolDefinition, AiSdkToolHandler } from "@webiny/api-core/features/ai/index.js";
3
+ import { UpdateTeam } from "@webiny/api-core/features/security/teams/UpdateTeam/index.js";
4
+ const inputSchema = z.object({
5
+ teamId: z.string().describe("Team id as returned by listTeams."),
6
+ name: z.string().min(3).optional().describe("New team name. Omit it to keep the current one."),
7
+ description: z.string().max(500).optional().describe("New description. Omit it to keep the current one; an empty string clears it."),
8
+ roles: z.array(z.string()).optional().describe("The complete list of roles the team should have afterwards. It REPLACES the stored list, so include the roles to keep. Omit it to leave the roles alone. Resolve values with listRoles first.")
9
+ });
10
+ class UpdateTeamToolHandlerImpl {
11
+ constructor(updateTeam){
12
+ this.updateTeam = updateTeam;
13
+ }
14
+ async execute(input) {
15
+ const result = await this.updateTeam.execute(input.teamId, {
16
+ name: input.name,
17
+ description: input.description,
18
+ roles: input.roles
19
+ });
20
+ if (result.isFail()) throw new Error(`Could not update the team: ${result.error.message}`);
21
+ const team = result.value;
22
+ return {
23
+ id: team.id,
24
+ name: team.name,
25
+ slug: team.slug,
26
+ description: team.description,
27
+ roles: team.roles
28
+ };
29
+ }
30
+ }
31
+ const UpdateTeamToolHandler = AiSdkToolHandler.createImplementation({
32
+ implementation: UpdateTeamToolHandlerImpl,
33
+ dependencies: [
34
+ UpdateTeam
35
+ ]
36
+ });
37
+ class UpdateTeamToolImpl {
38
+ constructor(){
39
+ this.name = "updateTeam";
40
+ this.title = "Update team";
41
+ this.description = "Changes a team's name, description or roles. Call listTeams first for the id. `roles` replaces the team's whole role list, so pass every role it should keep; call listRoles to resolve them. System teams and teams defined in code cannot be changed. Requires user approval.";
42
+ this.inputSchema = inputSchema;
43
+ this.annotations = {
44
+ readOnlyHint: false,
45
+ idempotentHint: true
46
+ };
47
+ this.handler = UpdateTeamToolHandler;
48
+ }
49
+ }
50
+ const UpdateTeamTool = AiSdkToolDefinition.createImplementation({
51
+ implementation: UpdateTeamToolImpl,
52
+ dependencies: []
53
+ });
54
+ export { UpdateTeamTool };
55
+
56
+ //# sourceMappingURL=UpdateTeamTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/ai/UpdateTeamTool.js","sources":["../../../src/features/ai/UpdateTeamTool.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { AiSdkToolDefinition, AiSdkToolHandler } from \"@webiny/api-core/features/ai/index.js\";\nimport { UpdateTeam } from \"@webiny/api-core/features/security/teams/UpdateTeam/index.js\";\n\nconst inputSchema = z.object({\n teamId: z.string().describe(\"Team id as returned by listTeams.\"),\n name: z.string().min(3).optional().describe(\"New team name. Omit it to keep the current one.\"),\n description: z\n .string()\n .max(500)\n .optional()\n .describe(\"New description. Omit it to keep the current one; an empty string clears it.\"),\n roles: z\n .array(z.string())\n .optional()\n .describe(\n \"The complete list of roles the team should have afterwards. It REPLACES the stored list, so include the roles to keep. Omit it to leave the roles alone. Resolve values with listRoles first.\"\n )\n});\n\ntype Input = z.infer<typeof inputSchema>;\n\ninterface UpdatedTeam {\n id: string;\n name: string;\n slug: string;\n description: string;\n roles: string[];\n}\n\nclass UpdateTeamToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {\n constructor(private updateTeam: UpdateTeam.Interface) {}\n\n async execute(input: Input): Promise<UpdatedTeam> {\n // A field the model left out arrives as `undefined`; `UpdateTeam` leaves those alone.\n const result = await this.updateTeam.execute(input.teamId, {\n name: input.name,\n description: input.description,\n roles: input.roles\n });\n\n if (result.isFail()) {\n throw new Error(`Could not update 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 description: team.description,\n // From the updated team, so the caller sees the resolved ids that were actually stored.\n roles: team.roles\n };\n }\n}\n\nconst UpdateTeamToolHandler = AiSdkToolHandler.createImplementation({\n implementation: UpdateTeamToolHandlerImpl,\n dependencies: [UpdateTeam]\n});\n\n/**\n * Changes a team's name, description or roles. The slug cannot change: folder permissions refer to\n * teams by slug.\n *\n * Needs approval for the same reason as `createTeam`: the roles decide what the team's members can\n * do. `roles` replaces the stored list, and the approval shows that whole list, so a role the model\n * left out is visible as missing before anything is written.\n */\nclass UpdateTeamToolImpl implements AiSdkToolDefinition.Interface<Input> {\n readonly name = \"updateTeam\";\n readonly title = \"Update team\";\n readonly description =\n \"Changes a team's name, description or roles. Call listTeams first for the id. `roles` replaces the team's whole role list, so pass every role it should keep; call listRoles to resolve them. System teams and teams defined in code cannot be changed. Requires user approval.\";\n readonly inputSchema = inputSchema;\n readonly annotations = { readOnlyHint: false, idempotentHint: true };\n readonly handler = UpdateTeamToolHandler;\n}\n\nexport const UpdateTeamTool = AiSdkToolDefinition.createImplementation({\n implementation: UpdateTeamToolImpl,\n dependencies: []\n});\n"],"names":["inputSchema","z","UpdateTeamToolHandlerImpl","updateTeam","input","result","Error","team","UpdateTeamToolHandler","AiSdkToolHandler","UpdateTeam","UpdateTeamToolImpl","UpdateTeamTool","AiSdkToolDefinition"],"mappings":";;;AAIA,MAAMA,cAAcC,EAAE,MAAM,CAAC;IACzB,QAAQA,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC5B,MAAMA,EAAE,MAAM,GAAG,GAAG,CAAC,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAC5C,aAAaA,EAAAA,MACF,GACN,GAAG,CAAC,KACJ,QAAQ,GACR,QAAQ,CAAC;IACd,OAAOA,EAAAA,KACG,CAACA,EAAE,MAAM,IACd,QAAQ,GACR,QAAQ,CACL;AAEZ;AAYA,MAAMC;IACF,YAAoBC,UAAgC,CAAE;aAAlCA,UAAU,GAAVA;IAAmC;IAEvD,MAAM,QAAQC,KAAY,EAAwB;QAE9C,MAAMC,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAACD,MAAM,MAAM,EAAE;YACvD,MAAMA,MAAM,IAAI;YAChB,aAAaA,MAAM,WAAW;YAC9B,OAAOA,MAAM,KAAK;QACtB;QAEA,IAAIC,OAAO,MAAM,IACb,MAAM,IAAIC,MAAM,CAAC,2BAA2B,EAAED,OAAO,KAAK,CAAC,OAAO,EAAE;QAGxE,MAAME,OAAOF,OAAO,KAAK;QAEzB,OAAO;YACH,IAAIE,KAAK,EAAE;YACX,MAAMA,KAAK,IAAI;YACf,MAAMA,KAAK,IAAI;YACf,aAAaA,KAAK,WAAW;YAE7B,OAAOA,KAAK,KAAK;QACrB;IACJ;AACJ;AAEA,MAAMC,wBAAwBC,iBAAiB,oBAAoB,CAAC;IAChE,gBAAgBP;IAChB,cAAc;QAACQ;KAAW;AAC9B;AAUA,MAAMC;;aACO,IAAI,GAAG;aACP,KAAK,GAAG;aACR,WAAW,GAChB;aACK,WAAW,GAAGX;aACd,WAAW,GAAG;YAAE,cAAc;YAAO,gBAAgB;QAAK;aAC1D,OAAO,GAAGQ;;AACvB;AAEO,MAAMI,iBAAiBC,oBAAoB,oBAAoB,CAAC;IACnE,gBAAgBF;IAChB,cAAc,EAAE;AACpB"}
@@ -1,7 +1,7 @@
1
1
  /**
2
- * Folder and team tools for AI callers.
2
+ * Folder, team and role tools for AI callers.
3
3
  *
4
- * The list tools are read-only and run unattended. Anything that creates, deletes or changes access is a write,
4
+ * The list tools are read-only and run unattended. Anything that creates, renames, moves, deletes or changes access is a write,
5
5
  * so it pauses for the user to approve the exact arguments. Access changes are deliberately one target
6
6
  * per call — granting and revoking separately means the approval block shows the entire change, rather
7
7
  * than a desired end state whose omissions quietly remove somebody's access.
@@ -4,9 +4,15 @@ import { ListFoldersTool } from "./ListFoldersTool.js";
4
4
  import { GrantFolderAccessTool } from "./GrantFolderAccessTool.js";
5
5
  import { RevokeFolderAccessTool } from "./RevokeFolderAccessTool.js";
6
6
  import { CreateFolderTool } from "./CreateFolderTool.js";
7
+ import { UpdateFolderTool } from "./UpdateFolderTool.js";
7
8
  import { DeleteFolderTool } from "./DeleteFolderTool.js";
8
9
  import { CreateTeamTool } from "./CreateTeamTool.js";
10
+ import { UpdateTeamTool } from "./UpdateTeamTool.js";
11
+ import { DeleteTeamTool } from "./DeleteTeamTool.js";
9
12
  import { ListRolesTool } from "./ListRolesTool.js";
13
+ import { CreateRoleTool } from "./CreateRoleTool.js";
14
+ import { UpdateRoleTool } from "./UpdateRoleTool.js";
15
+ import { DeleteRoleTool } from "./DeleteRoleTool.js";
10
16
  const AcoAiToolsFeature = createFeature({
11
17
  name: "Aco/AiTools",
12
18
  register (container) {
@@ -15,9 +21,15 @@ const AcoAiToolsFeature = createFeature({
15
21
  container.register(GrantFolderAccessTool);
16
22
  container.register(RevokeFolderAccessTool);
17
23
  container.register(CreateFolderTool);
24
+ container.register(UpdateFolderTool);
18
25
  container.register(DeleteFolderTool);
19
26
  container.register(CreateTeamTool);
27
+ container.register(UpdateTeamTool);
28
+ container.register(DeleteTeamTool);
20
29
  container.register(ListRolesTool);
30
+ container.register(CreateRoleTool);
31
+ container.register(UpdateRoleTool);
32
+ container.register(DeleteRoleTool);
21
33
  }
22
34
  });
23
35
  export { AcoAiToolsFeature };
@@ -1 +1 @@
1
- {"version":3,"file":"features/ai/feature.js","sources":["../../../src/features/ai/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { ListTeamsTool } from \"./ListTeamsTool.js\";\nimport { ListFoldersTool } from \"./ListFoldersTool.js\";\nimport { GrantFolderAccessTool } from \"./GrantFolderAccessTool.js\";\nimport { RevokeFolderAccessTool } from \"./RevokeFolderAccessTool.js\";\nimport { CreateFolderTool } from \"./CreateFolderTool.js\";\nimport { DeleteFolderTool } from \"./DeleteFolderTool.js\";\nimport { CreateTeamTool } from \"./CreateTeamTool.js\";\nimport { ListRolesTool } from \"./ListRolesTool.js\";\n\n/**\n * Folder and team tools for AI callers.\n *\n * The list tools are read-only and run unattended. Anything that creates, deletes or changes access is a write,\n * so it pauses for the user to approve the exact arguments. Access changes are deliberately one target\n * per call — granting and revoking separately means the approval block shows the entire change, rather\n * than a desired end state whose omissions quietly remove somebody's access.\n */\nexport const AcoAiToolsFeature = createFeature({\n name: \"Aco/AiTools\",\n register(container) {\n container.register(ListTeamsTool);\n container.register(ListFoldersTool);\n container.register(GrantFolderAccessTool);\n container.register(RevokeFolderAccessTool);\n container.register(CreateFolderTool);\n container.register(DeleteFolderTool);\n container.register(CreateTeamTool);\n container.register(ListRolesTool);\n }\n});\n"],"names":["AcoAiToolsFeature","createFeature","container","ListTeamsTool","ListFoldersTool","GrantFolderAccessTool","RevokeFolderAccessTool","CreateFolderTool","DeleteFolderTool","CreateTeamTool","ListRolesTool"],"mappings":";;;;;;;;;AAkBO,MAAMA,oBAAoBC,cAAc;IAC3C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;QACnBF,UAAU,QAAQ,CAACG;QACnBH,UAAU,QAAQ,CAACI;QACnBJ,UAAU,QAAQ,CAACK;QACnBL,UAAU,QAAQ,CAACM;QACnBN,UAAU,QAAQ,CAACO;QACnBP,UAAU,QAAQ,CAACQ;IACvB;AACJ"}
1
+ {"version":3,"file":"features/ai/feature.js","sources":["../../../src/features/ai/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { ListTeamsTool } from \"./ListTeamsTool.js\";\nimport { ListFoldersTool } from \"./ListFoldersTool.js\";\nimport { GrantFolderAccessTool } from \"./GrantFolderAccessTool.js\";\nimport { RevokeFolderAccessTool } from \"./RevokeFolderAccessTool.js\";\nimport { CreateFolderTool } from \"./CreateFolderTool.js\";\nimport { UpdateFolderTool } from \"./UpdateFolderTool.js\";\nimport { DeleteFolderTool } from \"./DeleteFolderTool.js\";\nimport { CreateTeamTool } from \"./CreateTeamTool.js\";\nimport { UpdateTeamTool } from \"./UpdateTeamTool.js\";\nimport { DeleteTeamTool } from \"./DeleteTeamTool.js\";\nimport { ListRolesTool } from \"./ListRolesTool.js\";\nimport { CreateRoleTool } from \"./CreateRoleTool.js\";\nimport { UpdateRoleTool } from \"./UpdateRoleTool.js\";\nimport { DeleteRoleTool } from \"./DeleteRoleTool.js\";\n\n/**\n * Folder, team and role tools for AI callers.\n *\n * The list tools are read-only and run unattended. Anything that creates, renames, moves, deletes or changes access is a write,\n * so it pauses for the user to approve the exact arguments. Access changes are deliberately one target\n * per call — granting and revoking separately means the approval block shows the entire change, rather\n * than a desired end state whose omissions quietly remove somebody's access.\n */\nexport const AcoAiToolsFeature = createFeature({\n name: \"Aco/AiTools\",\n register(container) {\n container.register(ListTeamsTool);\n container.register(ListFoldersTool);\n container.register(GrantFolderAccessTool);\n container.register(RevokeFolderAccessTool);\n container.register(CreateFolderTool);\n container.register(UpdateFolderTool);\n container.register(DeleteFolderTool);\n container.register(CreateTeamTool);\n container.register(UpdateTeamTool);\n container.register(DeleteTeamTool);\n container.register(ListRolesTool);\n container.register(CreateRoleTool);\n container.register(UpdateRoleTool);\n container.register(DeleteRoleTool);\n }\n});\n"],"names":["AcoAiToolsFeature","createFeature","container","ListTeamsTool","ListFoldersTool","GrantFolderAccessTool","RevokeFolderAccessTool","CreateFolderTool","UpdateFolderTool","DeleteFolderTool","CreateTeamTool","UpdateTeamTool","DeleteTeamTool","ListRolesTool","CreateRoleTool","UpdateRoleTool","DeleteRoleTool"],"mappings":";;;;;;;;;;;;;;;AAwBO,MAAMA,oBAAoBC,cAAc;IAC3C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;QACnBF,UAAU,QAAQ,CAACG;QACnBH,UAAU,QAAQ,CAACI;QACnBJ,UAAU,QAAQ,CAACK;QACnBL,UAAU,QAAQ,CAACM;QACnBN,UAAU,QAAQ,CAACO;QACnBP,UAAU,QAAQ,CAACQ;QACnBR,UAAU,QAAQ,CAACS;QACnBT,UAAU,QAAQ,CAACU;QACnBV,UAAU,QAAQ,CAACW;QACnBX,UAAU,QAAQ,CAACY;QACnBZ,UAAU,QAAQ,CAACa;QACnBb,UAAU,QAAQ,CAACc;IACvB;AACJ"}
@@ -2,8 +2,14 @@ export { AcoAiToolsFeature } from "./feature.js";
2
2
  export { ListTeamsTool } from "./ListTeamsTool.js";
3
3
  export { ListFoldersTool } from "./ListFoldersTool.js";
4
4
  export { ListRolesTool } from "./ListRolesTool.js";
5
+ export { CreateRoleTool } from "./CreateRoleTool.js";
6
+ export { UpdateRoleTool } from "./UpdateRoleTool.js";
7
+ export { DeleteRoleTool } from "./DeleteRoleTool.js";
5
8
  export { GrantFolderAccessTool } from "./GrantFolderAccessTool.js";
6
9
  export { RevokeFolderAccessTool } from "./RevokeFolderAccessTool.js";
7
10
  export { CreateFolderTool } from "./CreateFolderTool.js";
11
+ export { UpdateFolderTool } from "./UpdateFolderTool.js";
8
12
  export { DeleteFolderTool } from "./DeleteFolderTool.js";
9
13
  export { CreateTeamTool } from "./CreateTeamTool.js";
14
+ export { UpdateTeamTool } from "./UpdateTeamTool.js";
15
+ export { DeleteTeamTool } from "./DeleteTeamTool.js";
@@ -2,8 +2,14 @@ export { AcoAiToolsFeature } from "./feature.js";
2
2
  export { ListTeamsTool } from "./ListTeamsTool.js";
3
3
  export { ListFoldersTool } from "./ListFoldersTool.js";
4
4
  export { ListRolesTool } from "./ListRolesTool.js";
5
+ export { CreateRoleTool } from "./CreateRoleTool.js";
6
+ export { UpdateRoleTool } from "./UpdateRoleTool.js";
7
+ export { DeleteRoleTool } from "./DeleteRoleTool.js";
5
8
  export { GrantFolderAccessTool } from "./GrantFolderAccessTool.js";
6
9
  export { RevokeFolderAccessTool } from "./RevokeFolderAccessTool.js";
7
10
  export { CreateFolderTool } from "./CreateFolderTool.js";
11
+ export { UpdateFolderTool } from "./UpdateFolderTool.js";
8
12
  export { DeleteFolderTool } from "./DeleteFolderTool.js";
9
13
  export { CreateTeamTool } from "./CreateTeamTool.js";
14
+ export { UpdateTeamTool } from "./UpdateTeamTool.js";
15
+ export { DeleteTeamTool } from "./DeleteTeamTool.js";
@@ -2,7 +2,10 @@ import type { GetFolderUseCase } from "../../features/folder/GetFolder/index.js"
2
2
  import type { Folder, FolderPermission } from "../../types.js";
3
3
  export interface LoadedFolderPermissions {
4
4
  folder: Folder;
5
- /** Rules set on this folder. The only ones it may change. */
5
+ /**
6
+ * Rules set on this folder. The only ones it may change. Code-defined rules (`plugin`) are left
7
+ * out: they are merged in on read, and the update refuses any that are sent back.
8
+ */
6
9
  direct: FolderPermission[];
7
10
  /** Targets granted by an ancestor or a role. Writing these back would detach the inheritance. */
8
11
  inheritedTargets: Set<string>;
@@ -5,7 +5,7 @@ const loadFolderPermissions = async (getFolder, folderId)=>{
5
5
  const permissions = folder.permissions ?? [];
6
6
  return {
7
7
  folder,
8
- direct: permissions.filter((permission)=>!permission.inheritedFrom),
8
+ direct: permissions.filter((permission)=>!permission.inheritedFrom && !permission.plugin),
9
9
  inheritedTargets: new Set(permissions.filter((permission)=>permission.inheritedFrom).map((p)=>String(p.target)))
10
10
  };
11
11
  };
@@ -1 +1 @@
1
- {"version":3,"file":"features/ai/loadFolderPermissions.js","sources":["../../../src/features/ai/loadFolderPermissions.ts"],"sourcesContent":["import type { GetFolderUseCase } from \"~/features/folder/GetFolder/index.js\";\nimport type { Folder, FolderPermission } from \"~/types.js\";\n\nexport interface LoadedFolderPermissions {\n folder: Folder;\n /** Rules set on this folder. The only ones it may change. */\n direct: FolderPermission[];\n /** Targets granted by an ancestor or a role. Writing these back would detach the inheritance. */\n inheritedTargets: Set<string>;\n}\n\n/**\n * Reads a folder and separates the rules it owns from the ones it merely inherits.\n *\n * Every permission write starts here, because the field holds both kinds and a change has to preserve\n * the direct rules while leaving the inherited ones alone.\n */\nexport const loadFolderPermissions = async (\n getFolder: GetFolderUseCase.Interface,\n folderId: string\n): Promise<LoadedFolderPermissions> => {\n const result = await getFolder.execute(folderId);\n\n if (result.isFail()) {\n throw new Error(\n `Folder \"${folderId}\" not found: ${result.error.message}. Call listFolders for valid ids.`\n );\n }\n\n const folder = result.value;\n const permissions = folder.permissions ?? [];\n\n return {\n folder,\n direct: permissions.filter(permission => !permission.inheritedFrom),\n inheritedTargets: new Set(\n permissions.filter(permission => permission.inheritedFrom).map(p => String(p.target))\n )\n };\n};\n"],"names":["loadFolderPermissions","getFolder","folderId","result","Error","folder","permissions","permission","Set","p","String"],"mappings":"AAiBO,MAAMA,wBAAwB,OACjCC,WACAC;IAEA,MAAMC,SAAS,MAAMF,UAAU,OAAO,CAACC;IAEvC,IAAIC,OAAO,MAAM,IACb,MAAM,IAAIC,MACN,CAAC,QAAQ,EAAEF,SAAS,aAAa,EAAEC,OAAO,KAAK,CAAC,OAAO,CAAC,iCAAiC,CAAC;IAIlG,MAAME,SAASF,OAAO,KAAK;IAC3B,MAAMG,cAAcD,OAAO,WAAW,IAAI,EAAE;IAE5C,OAAO;QACHA;QACA,QAAQC,YAAY,MAAM,CAACC,CAAAA,aAAc,CAACA,WAAW,aAAa;QAClE,kBAAkB,IAAIC,IAClBF,YAAY,MAAM,CAACC,CAAAA,aAAcA,WAAW,aAAa,EAAE,GAAG,CAACE,CAAAA,IAAKC,OAAOD,EAAE,MAAM;IAE3F;AACJ"}
1
+ {"version":3,"file":"features/ai/loadFolderPermissions.js","sources":["../../../src/features/ai/loadFolderPermissions.ts"],"sourcesContent":["import type { GetFolderUseCase } from \"~/features/folder/GetFolder/index.js\";\nimport type { Folder, FolderPermission } from \"~/types.js\";\n\nexport interface LoadedFolderPermissions {\n folder: Folder;\n /**\n * Rules set on this folder. The only ones it may change. Code-defined rules (`plugin`) are left\n * out: they are merged in on read, and the update refuses any that are sent back.\n */\n direct: FolderPermission[];\n /** Targets granted by an ancestor or a role. Writing these back would detach the inheritance. */\n inheritedTargets: Set<string>;\n}\n\n/**\n * Reads a folder and separates the rules it owns from the ones it merely inherits.\n *\n * Every permission write starts here, because the field holds both kinds and a change has to preserve\n * the direct rules while leaving the inherited ones alone.\n */\nexport const loadFolderPermissions = async (\n getFolder: GetFolderUseCase.Interface,\n folderId: string\n): Promise<LoadedFolderPermissions> => {\n const result = await getFolder.execute(folderId);\n\n if (result.isFail()) {\n throw new Error(\n `Folder \"${folderId}\" not found: ${result.error.message}. Call listFolders for valid ids.`\n );\n }\n\n const folder = result.value;\n const permissions = folder.permissions ?? [];\n\n return {\n folder,\n direct: permissions.filter(permission => !permission.inheritedFrom && !permission.plugin),\n inheritedTargets: new Set(\n permissions.filter(permission => permission.inheritedFrom).map(p => String(p.target))\n )\n };\n};\n"],"names":["loadFolderPermissions","getFolder","folderId","result","Error","folder","permissions","permission","Set","p","String"],"mappings":"AAoBO,MAAMA,wBAAwB,OACjCC,WACAC;IAEA,MAAMC,SAAS,MAAMF,UAAU,OAAO,CAACC;IAEvC,IAAIC,OAAO,MAAM,IACb,MAAM,IAAIC,MACN,CAAC,QAAQ,EAAEF,SAAS,aAAa,EAAEC,OAAO,KAAK,CAAC,OAAO,CAAC,iCAAiC,CAAC;IAIlG,MAAME,SAASF,OAAO,KAAK;IAC3B,MAAMG,cAAcD,OAAO,WAAW,IAAI,EAAE;IAE5C,OAAO;QACHA;QACA,QAAQC,YAAY,MAAM,CAACC,CAAAA,aAAc,CAACA,WAAW,aAAa,IAAI,CAACA,WAAW,MAAM;QACxF,kBAAkB,IAAIC,IAClBF,YAAY,MAAM,CAACC,CAAAA,aAAcA,WAAW,aAAa,EAAE,GAAG,CAACE,CAAAA,IAAKC,OAAOD,EAAE,MAAM;IAE3F;AACJ"}
@@ -1,5 +1,5 @@
1
1
  import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/abstractions.js";
2
- import { WebsocketsSendToIdentityUseCase } from "@webiny/api-websockets/exports/api.js";
2
+ import { WebsocketsSendToIdentityUseCase } from "@webiny/api-core/features/websockets/index.js";
3
3
  import { NotifyFolderChangeUseCase as UseCaseAbstraction } from "./abstractions.js";
4
4
  declare class NotifyFolderChangeUseCaseImpl implements UseCaseAbstraction.Interface {
5
5
  private identityContext;
@@ -1,6 +1,6 @@
1
1
  import { createImplementation } from "@webiny/di";
2
2
  import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/abstractions.js";
3
- import { WebsocketsSendToIdentityUseCase } from "@webiny/api-websockets/exports/api.js";
3
+ import { WebsocketsSendToIdentityUseCase } from "@webiny/api-core/features/websockets/index.js";
4
4
  import { FOLDER_CREATED_WEBSOCKET_ACTION, FOLDER_DELETED_WEBSOCKET_ACTION, FOLDER_UPDATED_WEBSOCKET_ACTION, NotifyFolderChangeUseCase } from "./abstractions.js";
5
5
  const ACTIONS = {
6
6
  created: FOLDER_CREATED_WEBSOCKET_ACTION,
@@ -1 +1 @@
1
- {"version":3,"file":"features/folder/NotifyFolderChange/NotifyFolderChangeUseCase.js","sources":["../../../../src/features/folder/NotifyFolderChange/NotifyFolderChangeUseCase.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/di\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/abstractions.js\";\nimport { WebsocketsSendToIdentityUseCase } from \"@webiny/api-websockets/exports/api.js\";\nimport {\n FOLDER_CREATED_WEBSOCKET_ACTION,\n FOLDER_DELETED_WEBSOCKET_ACTION,\n FOLDER_UPDATED_WEBSOCKET_ACTION,\n NotifyFolderChangeUseCase as UseCaseAbstraction\n} from \"./abstractions.js\";\n\nconst ACTIONS: Record<UseCaseAbstraction.Params[\"change\"], string> = {\n created: FOLDER_CREATED_WEBSOCKET_ACTION,\n updated: FOLDER_UPDATED_WEBSOCKET_ACTION,\n deleted: FOLDER_DELETED_WEBSOCKET_ACTION\n};\n\n/*\n * The change is already saved whether or not the message goes out, so the send's result is not the\n * caller's result. When it fails, the admin shows the change after its next reload, as it did before.\n */\nclass NotifyFolderChangeUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private sendToIdentity: WebsocketsSendToIdentityUseCase.Interface\n ) {}\n\n async execute({ id, change, identityId }: UseCaseAbstraction.Params): Promise<void> {\n const recipient = identityId ?? this.identityContext.getIdentity()?.id;\n if (!recipient) {\n return;\n }\n\n await this.sendToIdentity.execute(\n { id: recipient },\n { action: ACTIONS[change], data: { id } }\n );\n }\n}\n\nexport const NotifyFolderChangeUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: NotifyFolderChangeUseCaseImpl,\n dependencies: [IdentityContext, WebsocketsSendToIdentityUseCase]\n});\n"],"names":["ACTIONS","FOLDER_CREATED_WEBSOCKET_ACTION","FOLDER_UPDATED_WEBSOCKET_ACTION","FOLDER_DELETED_WEBSOCKET_ACTION","NotifyFolderChangeUseCaseImpl","identityContext","sendToIdentity","id","change","identityId","recipient","NotifyFolderChangeUseCase","createImplementation","UseCaseAbstraction","IdentityContext","WebsocketsSendToIdentityUseCase"],"mappings":";;;;AAUA,MAAMA,UAA+D;IACjE,SAASC;IACT,SAASC;IACT,SAASC;AACb;AAMA,MAAMC;IACF,YACYC,eAA0C,EAC1CC,cAAyD,CACnE;aAFUD,eAAe,GAAfA;aACAC,cAAc,GAAdA;IACT;IAEH,MAAM,QAAQ,EAAEC,EAAE,EAAEC,MAAM,EAAEC,UAAU,EAA6B,EAAiB;QAChF,MAAMC,YAAYD,cAAc,IAAI,CAAC,eAAe,CAAC,WAAW,IAAI;QACpE,IAAI,CAACC,WACD;QAGJ,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B;YAAE,IAAIA;QAAU,GAChB;YAAE,QAAQV,OAAO,CAACQ,OAAO;YAAE,MAAM;gBAAED;YAAG;QAAE;IAEhD;AACJ;AAEO,MAAMI,sDAA4BC,qBAAqB;IAC1D,aAAaC;IACb,gBAAgBT;IAChB,cAAc;QAACU;QAAiBC;KAAgC;AACpE"}
1
+ {"version":3,"file":"features/folder/NotifyFolderChange/NotifyFolderChangeUseCase.js","sources":["../../../../src/features/folder/NotifyFolderChange/NotifyFolderChangeUseCase.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/di\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/abstractions.js\";\nimport { WebsocketsSendToIdentityUseCase } from \"@webiny/api-core/features/websockets/index.js\";\nimport {\n FOLDER_CREATED_WEBSOCKET_ACTION,\n FOLDER_DELETED_WEBSOCKET_ACTION,\n FOLDER_UPDATED_WEBSOCKET_ACTION,\n NotifyFolderChangeUseCase as UseCaseAbstraction\n} from \"./abstractions.js\";\n\nconst ACTIONS: Record<UseCaseAbstraction.Params[\"change\"], string> = {\n created: FOLDER_CREATED_WEBSOCKET_ACTION,\n updated: FOLDER_UPDATED_WEBSOCKET_ACTION,\n deleted: FOLDER_DELETED_WEBSOCKET_ACTION\n};\n\n/*\n * The change is already saved whether or not the message goes out, so the send's result is not the\n * caller's result. When it fails, the admin shows the change after its next reload, as it did before.\n */\nclass NotifyFolderChangeUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private sendToIdentity: WebsocketsSendToIdentityUseCase.Interface\n ) {}\n\n async execute({ id, change, identityId }: UseCaseAbstraction.Params): Promise<void> {\n const recipient = identityId ?? this.identityContext.getIdentity()?.id;\n if (!recipient) {\n return;\n }\n\n await this.sendToIdentity.execute(\n { id: recipient },\n { action: ACTIONS[change], data: { id } }\n );\n }\n}\n\nexport const NotifyFolderChangeUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: NotifyFolderChangeUseCaseImpl,\n dependencies: [IdentityContext, WebsocketsSendToIdentityUseCase]\n});\n"],"names":["ACTIONS","FOLDER_CREATED_WEBSOCKET_ACTION","FOLDER_UPDATED_WEBSOCKET_ACTION","FOLDER_DELETED_WEBSOCKET_ACTION","NotifyFolderChangeUseCaseImpl","identityContext","sendToIdentity","id","change","identityId","recipient","NotifyFolderChangeUseCase","createImplementation","UseCaseAbstraction","IdentityContext","WebsocketsSendToIdentityUseCase"],"mappings":";;;;AAUA,MAAMA,UAA+D;IACjE,SAASC;IACT,SAASC;IACT,SAASC;AACb;AAMA,MAAMC;IACF,YACYC,eAA0C,EAC1CC,cAAyD,CACnE;aAFUD,eAAe,GAAfA;aACAC,cAAc,GAAdA;IACT;IAEH,MAAM,QAAQ,EAAEC,EAAE,EAAEC,MAAM,EAAEC,UAAU,EAA6B,EAAiB;QAChF,MAAMC,YAAYD,cAAc,IAAI,CAAC,eAAe,CAAC,WAAW,IAAI;QACpE,IAAI,CAACC,WACD;QAGJ,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B;YAAE,IAAIA;QAAU,GAChB;YAAE,QAAQV,OAAO,CAACQ,OAAO;YAAE,MAAM;gBAAED;YAAG;QAAE;IAEhD;AACJ;AAEO,MAAMI,sDAA4BC,qBAAqB;IAC1D,aAAaC;IACb,gBAAgBT;IAChB,cAAc;QAACU;QAAiBC;KAAgC;AACpE"}
@@ -9,6 +9,7 @@ declare class UpdateFolderUseCaseImpl implements UseCaseAbstraction.Interface {
9
9
  private repository;
10
10
  constructor(eventPublisher: EventPublisherAbstraction.Interface, getFolderRepository: GetFolderRepository.Interface, repository: UpdateFolderRepository.Interface);
11
11
  execute(id: string, input: UpdateFolderParams): Promise<Result<Folder, UseCaseAbstraction.Error>>;
12
+ private ensureCanMoveInto;
12
13
  }
13
14
  export declare const UpdateFolderUseCase: import("@webiny/di").Implementation<typeof UpdateFolderUseCaseImpl>;
14
15
  export {};
@@ -3,6 +3,7 @@ import { EventPublisher } from "@webiny/api-core/features/eventPublisher/index.j
3
3
  import { UpdateFolderRepository, UpdateFolderUseCase } from "./abstractions.js";
4
4
  import { GetFolderRepository } from "../GetFolder/abstractions.js";
5
5
  import { FolderAfterUpdateEvent, FolderBeforeUpdateEvent } from "./events.js";
6
+ import { FolderValidationError } from "../../../domain/folder/errors.js";
6
7
  class UpdateFolderUseCaseImpl {
7
8
  constructor(eventPublisher, getFolderRepository, repository){
8
9
  this.eventPublisher = eventPublisher;
@@ -17,6 +18,10 @@ class UpdateFolderUseCaseImpl {
17
18
  const originalResult = await this.getFolderRepository.execute(id);
18
19
  if (originalResult.isFail()) return originalResult;
19
20
  const original = originalResult.value;
21
+ if (input.parentId && input.parentId !== original.parentId) {
22
+ const moveResult = await this.ensureCanMoveInto(original, input.parentId);
23
+ if (moveResult.isFail()) return Result.fail(moveResult.error);
24
+ }
20
25
  const beforeUpdateEvent = new FolderBeforeUpdateEvent({
21
26
  original,
22
27
  input: useCaseInput
@@ -33,6 +38,14 @@ class UpdateFolderUseCaseImpl {
33
38
  await this.eventPublisher.publish(afterUpdateEvent);
34
39
  return Result.ok(folder);
35
40
  }
41
+ async ensureCanMoveInto(folder, parentId) {
42
+ if (parentId === folder.id) return Result.fail(new FolderValidationError("A folder cannot be moved into itself."));
43
+ const parentResult = await this.getFolderRepository.execute(parentId);
44
+ if (parentResult.isFail()) return Result.fail(parentResult.error);
45
+ const parent = parentResult.value;
46
+ if (parent.path.startsWith(`${folder.path}/`)) return Result.fail(new FolderValidationError(`Folder "${parent.title}" is inside the folder being moved, so it cannot be its new parent.`));
47
+ return Result.ok();
48
+ }
36
49
  }
37
50
  const UpdateFolderUseCase_UpdateFolderUseCase = createImplementation({
38
51
  abstraction: UpdateFolderUseCase,
@@ -1 +1 @@
1
- {"version":3,"file":"features/folder/UpdateFolder/UpdateFolderUseCase.js","sources":["../../../../src/features/folder/UpdateFolder/UpdateFolderUseCase.ts"],"sourcesContent":["import { createImplementation, Result } from \"@webiny/feature/api\";\nimport {\n EventPublisher,\n EventPublisher as EventPublisherAbstraction\n} from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport {\n UpdateFolderRepository,\n UpdateFolderUseCase as UseCaseAbstraction\n} from \"./abstractions.js\";\nimport { GetFolderRepository } from \"../GetFolder/abstractions.js\";\nimport { FolderAfterUpdateEvent, FolderBeforeUpdateEvent } from \"./events.js\";\nimport type { Folder, UpdateFolderParams } from \"~/folder/folder.types.js\";\n\nclass UpdateFolderUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private eventPublisher: EventPublisherAbstraction.Interface,\n private getFolderRepository: GetFolderRepository.Interface,\n private repository: UpdateFolderRepository.Interface\n ) {}\n\n async execute(\n id: string,\n input: UpdateFolderParams\n ): Promise<Result<Folder, UseCaseAbstraction.Error>> {\n const useCaseInput = { id, data: input };\n\n // Get original folder for events\n const originalResult = await this.getFolderRepository.execute(id);\n\n if (originalResult.isFail()) {\n return originalResult;\n }\n\n const original = originalResult.value;\n\n // Publish before update event\n const beforeUpdateEvent = new FolderBeforeUpdateEvent({\n original,\n input: useCaseInput\n });\n\n await this.eventPublisher.publish(beforeUpdateEvent);\n\n // Execute the update operation\n const result = await this.repository.execute(id, input);\n\n if (result.isFail()) {\n return result;\n }\n\n const folder = result.value;\n\n // Publish after update event\n const afterUpdateEvent = new FolderAfterUpdateEvent({\n original,\n folder,\n input: useCaseInput\n });\n\n await this.eventPublisher.publish(afterUpdateEvent);\n\n return Result.ok(folder);\n }\n}\n\nexport const UpdateFolderUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: UpdateFolderUseCaseImpl,\n dependencies: [EventPublisher, GetFolderRepository, UpdateFolderRepository]\n});\n"],"names":["UpdateFolderUseCaseImpl","eventPublisher","getFolderRepository","repository","id","input","useCaseInput","originalResult","original","beforeUpdateEvent","FolderBeforeUpdateEvent","result","folder","afterUpdateEvent","FolderAfterUpdateEvent","Result","UpdateFolderUseCase","createImplementation","UseCaseAbstraction","EventPublisher","GetFolderRepository","UpdateFolderRepository"],"mappings":";;;;;AAaA,MAAMA;IACF,YACYC,cAAmD,EACnDC,mBAAkD,EAClDC,UAA4C,CACtD;aAHUF,cAAc,GAAdA;aACAC,mBAAmB,GAAnBA;aACAC,UAAU,GAAVA;IACT;IAEH,MAAM,QACFC,EAAU,EACVC,KAAyB,EACwB;QACjD,MAAMC,eAAe;YAAEF;YAAI,MAAMC;QAAM;QAGvC,MAAME,iBAAiB,MAAM,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAACH;QAE9D,IAAIG,eAAe,MAAM,IACrB,OAAOA;QAGX,MAAMC,WAAWD,eAAe,KAAK;QAGrC,MAAME,oBAAoB,IAAIC,wBAAwB;YAClDF;YACA,OAAOF;QACX;QAEA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAACG;QAGlC,MAAME,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAACP,IAAIC;QAEjD,IAAIM,OAAO,MAAM,IACb,OAAOA;QAGX,MAAMC,SAASD,OAAO,KAAK;QAG3B,MAAME,mBAAmB,IAAIC,uBAAuB;YAChDN;YACAI;YACA,OAAON;QACX;QAEA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAACO;QAElC,OAAOE,OAAO,EAAE,CAACH;IACrB;AACJ;AAEO,MAAMI,0CAAsBC,qBAAqB;IACpD,aAAaC;IACb,gBAAgBlB;IAChB,cAAc;QAACmB;QAAgBC;QAAqBC;KAAuB;AAC/E"}
1
+ {"version":3,"file":"features/folder/UpdateFolder/UpdateFolderUseCase.js","sources":["../../../../src/features/folder/UpdateFolder/UpdateFolderUseCase.ts"],"sourcesContent":["import { createImplementation, Result } from \"@webiny/feature/api\";\nimport {\n EventPublisher,\n EventPublisher as EventPublisherAbstraction\n} from \"@webiny/api-core/features/eventPublisher/index.js\";\nimport {\n UpdateFolderRepository,\n UpdateFolderUseCase as UseCaseAbstraction\n} from \"./abstractions.js\";\nimport { GetFolderRepository } from \"../GetFolder/abstractions.js\";\nimport { FolderAfterUpdateEvent, FolderBeforeUpdateEvent } from \"./events.js\";\nimport type { Folder, UpdateFolderParams } from \"~/folder/folder.types.js\";\nimport { FolderValidationError } from \"~/domain/folder/errors.js\";\n\nclass UpdateFolderUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private eventPublisher: EventPublisherAbstraction.Interface,\n private getFolderRepository: GetFolderRepository.Interface,\n private repository: UpdateFolderRepository.Interface\n ) {}\n\n async execute(\n id: string,\n input: UpdateFolderParams\n ): Promise<Result<Folder, UseCaseAbstraction.Error>> {\n const useCaseInput = { id, data: input };\n\n // Get original folder for events\n const originalResult = await this.getFolderRepository.execute(id);\n\n if (originalResult.isFail()) {\n return originalResult;\n }\n\n const original = originalResult.value;\n\n if (input.parentId && input.parentId !== original.parentId) {\n const moveResult = await this.ensureCanMoveInto(original, input.parentId);\n\n if (moveResult.isFail()) {\n return Result.fail(moveResult.error);\n }\n }\n\n // Publish before update event\n const beforeUpdateEvent = new FolderBeforeUpdateEvent({\n original,\n input: useCaseInput\n });\n\n await this.eventPublisher.publish(beforeUpdateEvent);\n\n // Execute the update operation\n const result = await this.repository.execute(id, input);\n\n if (result.isFail()) {\n return result;\n }\n\n const folder = result.value;\n\n // Publish after update event\n const afterUpdateEvent = new FolderAfterUpdateEvent({\n original,\n folder,\n input: useCaseInput\n });\n\n await this.eventPublisher.publish(afterUpdateEvent);\n\n return Result.ok(folder);\n }\n\n /*\n * Either move would cut the folder's subtree off from the root. The admin's tree never offers\n * them, but any caller can pass an arbitrary parent id.\n *\n * The subtree check compares stored paths. A move writes the moved folder's own path at once\n * and its descendants' paths later, from the FLP update task, so a second move made before\n * that task finishes is checked against the old paths.\n */\n private async ensureCanMoveInto(\n folder: Folder,\n parentId: string\n ): Promise<Result<void, UseCaseAbstraction.Error>> {\n if (parentId === folder.id) {\n return Result.fail(new FolderValidationError(\"A folder cannot be moved into itself.\"));\n }\n\n const parentResult = await this.getFolderRepository.execute(parentId);\n\n if (parentResult.isFail()) {\n return Result.fail(parentResult.error);\n }\n\n const parent = parentResult.value;\n\n if (parent.path.startsWith(`${folder.path}/`)) {\n return Result.fail(\n new FolderValidationError(\n `Folder \"${parent.title}\" is inside the folder being moved, so it cannot be its new parent.`\n )\n );\n }\n\n return Result.ok();\n }\n}\n\nexport const UpdateFolderUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: UpdateFolderUseCaseImpl,\n dependencies: [EventPublisher, GetFolderRepository, UpdateFolderRepository]\n});\n"],"names":["UpdateFolderUseCaseImpl","eventPublisher","getFolderRepository","repository","id","input","useCaseInput","originalResult","original","moveResult","Result","beforeUpdateEvent","FolderBeforeUpdateEvent","result","folder","afterUpdateEvent","FolderAfterUpdateEvent","parentId","FolderValidationError","parentResult","parent","UpdateFolderUseCase","createImplementation","UseCaseAbstraction","EventPublisher","GetFolderRepository","UpdateFolderRepository"],"mappings":";;;;;;AAcA,MAAMA;IACF,YACYC,cAAmD,EACnDC,mBAAkD,EAClDC,UAA4C,CACtD;aAHUF,cAAc,GAAdA;aACAC,mBAAmB,GAAnBA;aACAC,UAAU,GAAVA;IACT;IAEH,MAAM,QACFC,EAAU,EACVC,KAAyB,EACwB;QACjD,MAAMC,eAAe;YAAEF;YAAI,MAAMC;QAAM;QAGvC,MAAME,iBAAiB,MAAM,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAACH;QAE9D,IAAIG,eAAe,MAAM,IACrB,OAAOA;QAGX,MAAMC,WAAWD,eAAe,KAAK;QAErC,IAAIF,MAAM,QAAQ,IAAIA,MAAM,QAAQ,KAAKG,SAAS,QAAQ,EAAE;YACxD,MAAMC,aAAa,MAAM,IAAI,CAAC,iBAAiB,CAACD,UAAUH,MAAM,QAAQ;YAExE,IAAII,WAAW,MAAM,IACjB,OAAOC,OAAO,IAAI,CAACD,WAAW,KAAK;QAE3C;QAGA,MAAME,oBAAoB,IAAIC,wBAAwB;YAClDJ;YACA,OAAOF;QACX;QAEA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAACK;QAGlC,MAAME,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAACT,IAAIC;QAEjD,IAAIQ,OAAO,MAAM,IACb,OAAOA;QAGX,MAAMC,SAASD,OAAO,KAAK;QAG3B,MAAME,mBAAmB,IAAIC,uBAAuB;YAChDR;YACAM;YACA,OAAOR;QACX;QAEA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAACS;QAElC,OAAOL,OAAO,EAAE,CAACI;IACrB;IAUA,MAAc,kBACVA,MAAc,EACdG,QAAgB,EAC+B;QAC/C,IAAIA,aAAaH,OAAO,EAAE,EACtB,OAAOJ,OAAO,IAAI,CAAC,IAAIQ,sBAAsB;QAGjD,MAAMC,eAAe,MAAM,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAACF;QAE5D,IAAIE,aAAa,MAAM,IACnB,OAAOT,OAAO,IAAI,CAACS,aAAa,KAAK;QAGzC,MAAMC,SAASD,aAAa,KAAK;QAEjC,IAAIC,OAAO,IAAI,CAAC,UAAU,CAAC,GAAGN,OAAO,IAAI,CAAC,CAAC,CAAC,GACxC,OAAOJ,OAAO,IAAI,CACd,IAAIQ,sBACA,CAAC,QAAQ,EAAEE,OAAO,KAAK,CAAC,mEAAmE,CAAC;QAKxG,OAAOV,OAAO,EAAE;IACpB;AACJ;AAEO,MAAMW,0CAAsBC,qBAAqB;IACpD,aAAaC;IACb,gBAAgBvB;IAChB,cAAc;QAACwB;QAAgBC;QAAqBC;KAAuB;AAC/E"}
@@ -5,6 +5,7 @@ import { GetFolderUseCase } from "../../GetFolder/index.js";
5
5
  import { FolderCannotMoveToNewParent, FolderValidationError } from "../../../../domain/folder/errors.js";
6
6
  import { CodeFlpMerger, CodeFlpsProvider } from "../../../flp/shared/index.js";
7
7
  import { Path } from "../../../../utils/Path.js";
8
+ const getOwnPermissions = (folder)=>(folder.permissions ?? []).filter((permission)=>!permission.inheritedFrom && !permission.plugin);
8
9
  class UpdateFolderWithFolderLevelPermissionsImpl {
9
10
  constructor(getFolder, folderLevelPermissions, codeFlpsProvider, decoretee){
10
11
  this.getFolder = getFolder;
@@ -21,8 +22,9 @@ class UpdateFolderWithFolderLevelPermissionsImpl {
21
22
  permissions: originalPermissions,
22
23
  rwd: "w"
23
24
  });
25
+ const ownPermissions = params.permissions ?? getOwnPermissions(original);
24
26
  const targetFolder = await this.getTargetFolder(original, params);
25
- const submittedPermissions = await this.withCodePermissions(targetFolder, params.permissions ?? []);
27
+ const submittedPermissions = await this.withCodePermissions(targetFolder, ownPermissions);
26
28
  const permissions = await this.folderLevelPermissions.getDefaultPermissions(submittedPermissions);
27
29
  const stillHasAccess = await this.folderLevelPermissions.canAccessFolder({
28
30
  permissions,
@@ -45,7 +47,7 @@ class UpdateFolderWithFolderLevelPermissionsImpl {
45
47
  }
46
48
  const result = await this.decoretee.execute(id, params);
47
49
  if (result.isFail()) return Result.fail(result.error);
48
- const updatedPermissions = await this.withCodePermissions(result.value, params.permissions ?? []);
50
+ const updatedPermissions = await this.withCodePermissions(result.value, ownPermissions);
49
51
  const updatedPermissionsWithDefaults = await this.folderLevelPermissions.getDefaultPermissions(updatedPermissions);
50
52
  return Result.ok({
51
53
  ...result.value,