@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
@@ -0,0 +1,57 @@
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 { GetFolderUseCase } from "../../features/folder/GetFolder/index.js";
5
+ import { UpdateFolderUseCase } from "../../features/folder/UpdateFolder/index.js";
6
+ declare const inputSchema: z.ZodObject<{
7
+ folderId: z.ZodString;
8
+ currentTitle: z.ZodString;
9
+ title: z.ZodOptional<z.ZodString>;
10
+ slug: z.ZodOptional<z.ZodString>;
11
+ parentId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
12
+ }, z.core.$strip>;
13
+ type Input = z.infer<typeof inputSchema>;
14
+ interface UpdatedFolder {
15
+ id: string;
16
+ title: string;
17
+ slug: string;
18
+ path: string;
19
+ parentId: string | null;
20
+ type: string;
21
+ }
22
+ declare class UpdateFolderToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {
23
+ private getFolder;
24
+ private updateFolder;
25
+ constructor(getFolder: GetFolderUseCase.Interface, updateFolder: UpdateFolderUseCase.Interface);
26
+ execute(input: Input): Promise<UpdatedFolder>;
27
+ private ensureSameType;
28
+ }
29
+ /**
30
+ * Renames or moves one folder.
31
+ *
32
+ * Not destructive: the old title, slug and parent can be set again. A new slug or parent changes the
33
+ * folder's path and its subfolders' paths, and with them which code-defined access rules apply, so
34
+ * it still waits for the user to approve the exact arguments.
35
+ */
36
+ declare class UpdateFolderToolImpl implements AiSdkToolDefinition.Interface<Input> {
37
+ readonly name = "updateFolder";
38
+ readonly title = "Update folder";
39
+ readonly 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.";
40
+ readonly inputSchema: z.ZodObject<{
41
+ folderId: z.ZodString;
42
+ currentTitle: z.ZodString;
43
+ title: z.ZodOptional<z.ZodString>;
44
+ slug: z.ZodOptional<z.ZodString>;
45
+ parentId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
46
+ }, z.core.$strip>;
47
+ readonly annotations: {
48
+ readOnlyHint: boolean;
49
+ };
50
+ readonly handler: typeof UpdateFolderToolHandlerImpl & {
51
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/ai/abstractions").IAiSdkToolHandler<any>>;
52
+ };
53
+ }
54
+ export declare const UpdateFolderTool: typeof UpdateFolderToolImpl & {
55
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/ai/abstractions").IAiSdkToolDefinition<any>>;
56
+ };
57
+ export {};
@@ -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,SA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AAe,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"}
@@ -1,7 +1,7 @@
1
1
  /**
2
- * Folder and team tools for AI callers.
2
+ * Folder tools for AI callers. The team and role tools live in api-core, next to teams and roles.
3
3
  *
4
- * The list tools are read-only and run unattended. Anything that creates, deletes or changes access is a write,
4
+ * listFolders is read-only and runs 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.
@@ -1,23 +1,19 @@
1
1
  import { createFeature } from "@webiny/feature/api";
2
- import { ListTeamsTool } from "./ListTeamsTool.js";
3
2
  import { ListFoldersTool } from "./ListFoldersTool.js";
4
3
  import { GrantFolderAccessTool } from "./GrantFolderAccessTool.js";
5
4
  import { RevokeFolderAccessTool } from "./RevokeFolderAccessTool.js";
6
5
  import { CreateFolderTool } from "./CreateFolderTool.js";
6
+ import { UpdateFolderTool } from "./UpdateFolderTool.js";
7
7
  import { DeleteFolderTool } from "./DeleteFolderTool.js";
8
- import { CreateTeamTool } from "./CreateTeamTool.js";
9
- import { ListRolesTool } from "./ListRolesTool.js";
10
8
  const AcoAiToolsFeature = createFeature({
11
9
  name: "Aco/AiTools",
12
10
  register (container) {
13
- container.register(ListTeamsTool);
14
11
  container.register(ListFoldersTool);
15
12
  container.register(GrantFolderAccessTool);
16
13
  container.register(RevokeFolderAccessTool);
17
14
  container.register(CreateFolderTool);
15
+ container.register(UpdateFolderTool);
18
16
  container.register(DeleteFolderTool);
19
- container.register(CreateTeamTool);
20
- container.register(ListRolesTool);
21
17
  }
22
18
  });
23
19
  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 { 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\";\n\n/**\n * Folder tools for AI callers. The team and role tools live in api-core, next to teams and roles.\n *\n * listFolders is read-only and runs 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(ListFoldersTool);\n container.register(GrantFolderAccessTool);\n container.register(RevokeFolderAccessTool);\n container.register(CreateFolderTool);\n container.register(UpdateFolderTool);\n container.register(DeleteFolderTool);\n }\n});\n"],"names":["AcoAiToolsFeature","createFeature","container","ListFoldersTool","GrantFolderAccessTool","RevokeFolderAccessTool","CreateFolderTool","UpdateFolderTool","DeleteFolderTool"],"mappings":";;;;;;;AAgBO,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;IACvB;AACJ"}
@@ -1,9 +1,7 @@
1
1
  export { AcoAiToolsFeature } from "./feature.js";
2
- export { ListTeamsTool } from "./ListTeamsTool.js";
3
2
  export { ListFoldersTool } from "./ListFoldersTool.js";
4
- export { ListRolesTool } from "./ListRolesTool.js";
5
3
  export { GrantFolderAccessTool } from "./GrantFolderAccessTool.js";
6
4
  export { RevokeFolderAccessTool } from "./RevokeFolderAccessTool.js";
7
5
  export { CreateFolderTool } from "./CreateFolderTool.js";
6
+ export { UpdateFolderTool } from "./UpdateFolderTool.js";
8
7
  export { DeleteFolderTool } from "./DeleteFolderTool.js";
9
- export { CreateTeamTool } from "./CreateTeamTool.js";
@@ -1,9 +1,7 @@
1
1
  export { AcoAiToolsFeature } from "./feature.js";
2
- export { ListTeamsTool } from "./ListTeamsTool.js";
3
2
  export { ListFoldersTool } from "./ListFoldersTool.js";
4
- export { ListRolesTool } from "./ListRolesTool.js";
5
3
  export { GrantFolderAccessTool } from "./GrantFolderAccessTool.js";
6
4
  export { RevokeFolderAccessTool } from "./RevokeFolderAccessTool.js";
7
5
  export { CreateFolderTool } from "./CreateFolderTool.js";
6
+ export { UpdateFolderTool } from "./UpdateFolderTool.js";
8
7
  export { DeleteFolderTool } from "./DeleteFolderTool.js";
9
- export { CreateTeamTool } from "./CreateTeamTool.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"}
@@ -20,7 +20,6 @@ class FolderLevelPermissionsImpl {
20
20
  canUseFolderLevelPermissions(enabled) {
21
21
  if (false === enabled) return false;
22
22
  const identity = this.identityContext.getIdentity();
23
- if (!identity) return false;
24
23
  if ("admin" !== identity.type) return false;
25
24
  return this.featureFlags.get().isEnabled("advancedAccessControlLayer.folderLevelPermissions");
26
25
  }
@@ -1 +1 @@
1
- {"version":3,"file":"features/flp/FolderLevelPermissions/FolderLevelPermissions.js","sources":["../../../../src/features/flp/FolderLevelPermissions/FolderLevelPermissions.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/di\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { FeatureFlags } from \"@webiny/api-core/features/featureFlags/abstractions.js\";\nimport { ListUserTeamsUseCase } from \"@webiny/api-core/features/users/ListUserTeams/index.js\";\nimport { NotAuthorizedError } from \"@webiny/api-core/features/security/shared/index.js\";\nimport {\n CanAccessFolder,\n CanAccessFolderContent,\n type CanAccessFolderContentParams,\n type CanAccessFolderParams,\n CanCreateFolderInRoot,\n CheckNotInheritedPermissions,\n GetDefaultPermissions,\n GetDefaultPermissionsWithTeams,\n type IGetDefaultPermissions\n} from \"./useCases/index.js\";\nimport { FolderLevelPermissions as FolderLevelPermissionsAbstraction } from \"./abstractions.js\";\nimport { DefaultPermissionsMerger } from \"./useCases/GetDefaultPermissions/DefaultPermissionsMerger.js\";\nimport { expandTeamPermissions } from \"./useCases/GetDefaultPermissions/GetDefaultPermissionsWithTeams.js\";\nimport type { Team } from \"@webiny/api-core/types/security.js\";\nimport type { FolderLevelPermission, FolderPermission } from \"~/types.js\";\nimport type { ListFolderPermissionsParams } from \"~/features/flp/FolderPermissionsRepository/abstractions.js\";\nimport { ListFlpsUseCase } from \"~/features/flp/ListFlps/index.js\";\nimport { GetFlpUseCase } from \"~/features/flp/GetFlp/index.js\";\n\nclass FolderLevelPermissionsImpl implements FolderLevelPermissionsAbstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private featureFlags: FeatureFlags.Interface,\n private listUserTeamsUseCase: ListUserTeamsUseCase.Interface,\n private getFlpUseCase: GetFlpUseCase.Interface,\n private listFlpsUseCase: ListFlpsUseCase.Interface\n ) {}\n\n public canUseFolderLevelPermissions(enabled?: boolean): boolean {\n if (enabled === false) {\n return false;\n }\n\n const identity = this.identityContext.getIdentity();\n\n // FLPs only work with authenticated identities (logged-in users).\n if (!identity) {\n return false;\n }\n\n // At the moment, we only want FLP to be used with identities of type \"admin\".\n // This temporarily addresses the issue of API keys not being able to access content, because\n // FLPs doesn't work with them. Once we start adding FLPs to API keys, we can remove this check.\n if (identity.type !== \"admin\") {\n return false;\n }\n\n return this.featureFlags\n .get()\n .isEnabled(\"advancedAccessControlLayer.folderLevelPermissions\");\n }\n\n public canUseTeams(): boolean {\n return this.featureFlags.get().isEnabled(\"advancedAccessControlLayer.teams\");\n }\n\n public canCreateFolderInRoot(): boolean {\n const canCreateFolderInRootUseCase = new CanCreateFolderInRoot();\n return canCreateFolderInRootUseCase.execute();\n }\n\n public permissionsIncludeNonInheritedPermissions(permissions: FolderPermission[]): boolean {\n const checkNotInheritedPermissionsUseCase = new CheckNotInheritedPermissions();\n return checkNotInheritedPermissionsUseCase.execute(permissions);\n }\n\n public async canAccessFolder(params: CanAccessFolderParams): Promise<boolean> {\n if (\n !this.canUseFolderLevelPermissions() ||\n !this.identityContext.isAuthorizationEnabled()\n ) {\n return true;\n }\n\n const canAccessFolderUseCase = new CanAccessFolder(this.identityContext);\n return await canAccessFolderUseCase.execute(params);\n }\n\n public async canAccessFolderContent(params: CanAccessFolderContentParams): Promise<boolean> {\n const canUseFlp = this.canUseFolderLevelPermissions();\n const authEnabled = this.identityContext.isAuthorizationEnabled();\n\n if (!canUseFlp || !authEnabled) {\n return true;\n }\n\n const canAccessFolderContentUseCase = new CanAccessFolderContent(this.identityContext);\n return await canAccessFolderContentUseCase.execute(params);\n }\n\n public async ensureCanAccessFolder(params: CanAccessFolderParams): Promise<void> {\n const result = await this.canAccessFolder(params);\n if (!result) {\n throw new NotAuthorizedError();\n }\n }\n\n public async ensureCanAccessFolderContent(params: CanAccessFolderContentParams): Promise<void> {\n const result = await this.canAccessFolderContent(params);\n if (!result) {\n throw new NotAuthorizedError();\n }\n }\n\n public async canManageFolderContent(flp: FolderLevelPermission): Promise<boolean> {\n if (\n !this.canUseFolderLevelPermissions() ||\n !this.identityContext.isAuthorizationEnabled()\n ) {\n return true;\n }\n\n return await this.canAccessFolderContent({ permissions: flp.permissions, rwd: \"w\" });\n }\n\n public async canManageFolderStructure(flp: FolderLevelPermission): Promise<boolean> {\n if (\n !this.canUseFolderLevelPermissions() ||\n !this.identityContext.isAuthorizationEnabled()\n ) {\n return true;\n }\n\n return await this.canAccessFolder({ permissions: flp.permissions, rwd: \"w\" });\n }\n\n public async canManageFolderPermissions(flp: FolderLevelPermission): Promise<boolean> {\n if (!this.canUseFolderLevelPermissions()) {\n return false;\n }\n\n if (!this.identityContext.isAuthorizationEnabled()) {\n return true;\n }\n\n return await this.canAccessFolder({\n permissions: flp.permissions,\n rwd: \"w\",\n managePermissions: true\n });\n }\n\n // With teams enabled, every call loads the current user's teams through `ListUserTeamsUseCase`\n // (an admin user read plus a team list). Nothing caches them between calls.\n public getDefaultPermissions(permissions: FolderPermission[]): Promise<FolderPermission[]> {\n return this.createDefaultPermissions().execute(permissions);\n }\n\n public async getDefaultPermissionsBatch(\n permissionsList: FolderPermission[][]\n ): Promise<FolderPermission[][]> {\n if (permissionsList.length === 0) {\n return [];\n }\n const identity = this.identityContext.getIdentity();\n const identityPermissions = await this.identityContext.listPermissions();\n\n let identityTeams: Team[] = [];\n if (this.canUseTeams()) {\n const result = await this.listUserTeamsUseCase.execute(identity.id);\n identityTeams = result.isOk() ? result.value : [];\n }\n\n // The same steps as getDefaultPermissions(), with the lookups done once.\n return permissionsList.map(permissions =>\n DefaultPermissionsMerger.merge(\n identity,\n identityPermissions,\n this.canUseTeams()\n ? expandTeamPermissions(identity, identityTeams, permissions)\n : permissions\n )\n );\n }\n\n public async listFolderLevelPermissions(params: ListFolderPermissionsParams): Promise<\n Array<{\n id: string;\n permissions: FolderPermission[];\n }>\n > {\n const flps = await this.listFlpsUseCase.execute(params);\n\n // One instance for every listed record: with teams enabled, the user's teams are loaded\n // once per call, not once per record.\n const defaultPermissions = this.createDefaultPermissions();\n return Promise.all(\n flps.map(async flp => ({\n id: flp.id,\n permissions: await defaultPermissions.execute(flp.permissions)\n }))\n );\n }\n\n private createDefaultPermissions(): IGetDefaultPermissions {\n const getDefaultPermissionsUseCase = new GetDefaultPermissions(this.identityContext);\n if (!this.canUseTeams()) {\n return getDefaultPermissionsUseCase;\n }\n return new GetDefaultPermissionsWithTeams(\n this.identityContext,\n this.listUserTeamsUseCase,\n getDefaultPermissionsUseCase\n );\n }\n\n public async getFolderLevelPermissions(id: string): Promise<FolderPermission[]> {\n const flp = await this.getFlpUseCase.execute(id);\n return await this.getDefaultPermissions(flp?.permissions ?? []);\n }\n}\n\nexport const FolderLevelPermissions = createImplementation({\n abstraction: FolderLevelPermissionsAbstraction,\n implementation: FolderLevelPermissionsImpl,\n dependencies: [\n IdentityContext,\n FeatureFlags,\n ListUserTeamsUseCase,\n GetFlpUseCase,\n ListFlpsUseCase\n ]\n});\n"],"names":["FolderLevelPermissionsImpl","identityContext","featureFlags","listUserTeamsUseCase","getFlpUseCase","listFlpsUseCase","enabled","identity","canCreateFolderInRootUseCase","CanCreateFolderInRoot","permissions","checkNotInheritedPermissionsUseCase","CheckNotInheritedPermissions","params","canAccessFolderUseCase","CanAccessFolder","canUseFlp","authEnabled","canAccessFolderContentUseCase","CanAccessFolderContent","result","NotAuthorizedError","flp","permissionsList","identityPermissions","identityTeams","DefaultPermissionsMerger","expandTeamPermissions","flps","defaultPermissions","Promise","getDefaultPermissionsUseCase","GetDefaultPermissions","GetDefaultPermissionsWithTeams","id","FolderLevelPermissions","createImplementation","FolderLevelPermissionsAbstraction","IdentityContext","FeatureFlags","ListUserTeamsUseCase","GetFlpUseCase","ListFlpsUseCase"],"mappings":";;;;;;;;;;;AAyBA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,YAAoC,EACpCC,oBAAoD,EACpDC,aAAsC,EACtCC,eAA0C,CACpD;aALUJ,eAAe,GAAfA;aACAC,YAAY,GAAZA;aACAC,oBAAoB,GAApBA;aACAC,aAAa,GAAbA;aACAC,eAAe,GAAfA;IACT;IAEI,6BAA6BC,OAAiB,EAAW;QAC5D,IAAIA,AAAY,UAAZA,SACA,OAAO;QAGX,MAAMC,WAAW,IAAI,CAAC,eAAe,CAAC,WAAW;QAGjD,IAA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WAAW,KACVG,sBAAsBpB,UAAUkB,eAAef,eAC/CA;IAGlB;IAEA,MAAa,2BAA2BG,MAAmC,EAKzE;QACE,MAAMe,OAAO,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAACf;QAIhD,MAAMgB,qBAAqB,IAAI,CAAC,wBAAwB;QACxD,OAAOC,QAAQ,GAAG,CACdF,KAAK,GAAG,CAAC,OAAMN,MAAQ;gBACnB,IAAIA,IAAI,EAAE;gBACV,aAAa,MAAMO,mBAAmB,OAAO,CAACP,IAAI,WAAW;YACjE;IAER;IAEQ,2BAAmD;QACvD,MAAMS,+BAA+B,IAAIC,sBAAsB,IAAI,CAAC,eAAe;QACnF,IAAI,CAAC,IAAI,CAAC,WAAW,IACjB,OAAOD;QAEX,OAAO,IAAIE,+BACP,IAAI,CAAC,eAAe,EACpB,IAAI,CAAC,oBAAoB,EACzBF;IAER;IAEA,MAAa,0BAA0BG,EAAU,EAA+B;QAC5E,MAAMZ,MAAM,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAACY;QAC7C,OAAO,MAAM,IAAI,CAAC,qBAAqB,CAACZ,KAAK,eAAe,EAAE;IAClE;AACJ;AAEO,MAAMa,gDAAyBC,qBAAqB;IACvD,aAAaC;IACb,gBAAgBrC;IAChB,cAAc;QACVsC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
1
+ {"version":3,"file":"features/flp/FolderLevelPermissions/FolderLevelPermissions.js","sources":["../../../../src/features/flp/FolderLevelPermissions/FolderLevelPermissions.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/di\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { FeatureFlags } from \"@webiny/api-core/features/featureFlags/abstractions.js\";\nimport { ListUserTeamsUseCase } from \"@webiny/api-core/features/users/ListUserTeams/index.js\";\nimport { NotAuthorizedError } from \"@webiny/api-core/features/security/shared/index.js\";\nimport {\n CanAccessFolder,\n CanAccessFolderContent,\n type CanAccessFolderContentParams,\n type CanAccessFolderParams,\n CanCreateFolderInRoot,\n CheckNotInheritedPermissions,\n GetDefaultPermissions,\n GetDefaultPermissionsWithTeams,\n type IGetDefaultPermissions\n} from \"./useCases/index.js\";\nimport { FolderLevelPermissions as FolderLevelPermissionsAbstraction } from \"./abstractions.js\";\nimport { DefaultPermissionsMerger } from \"./useCases/GetDefaultPermissions/DefaultPermissionsMerger.js\";\nimport { expandTeamPermissions } from \"./useCases/GetDefaultPermissions/GetDefaultPermissionsWithTeams.js\";\nimport type { Team } from \"@webiny/api-core/types/security.js\";\nimport type { FolderLevelPermission, FolderPermission } from \"~/types.js\";\nimport type { ListFolderPermissionsParams } from \"~/features/flp/FolderPermissionsRepository/abstractions.js\";\nimport { ListFlpsUseCase } from \"~/features/flp/ListFlps/index.js\";\nimport { GetFlpUseCase } from \"~/features/flp/GetFlp/index.js\";\n\nclass FolderLevelPermissionsImpl implements FolderLevelPermissionsAbstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private featureFlags: FeatureFlags.Interface,\n private listUserTeamsUseCase: ListUserTeamsUseCase.Interface,\n private getFlpUseCase: GetFlpUseCase.Interface,\n private listFlpsUseCase: ListFlpsUseCase.Interface\n ) {}\n\n public canUseFolderLevelPermissions(enabled?: boolean): boolean {\n if (enabled === false) {\n return false;\n }\n\n const identity = this.identityContext.getIdentity();\n\n // At the moment, we only want FLP to be used with identities of type \"admin\".\n // This temporarily addresses the issue of API keys not being able to access content, because\n // FLPs doesn't work with them. Once we start adding FLPs to API keys, we can remove this check.\n if (identity.type !== \"admin\") {\n return false;\n }\n\n return this.featureFlags\n .get()\n .isEnabled(\"advancedAccessControlLayer.folderLevelPermissions\");\n }\n\n public canUseTeams(): boolean {\n return this.featureFlags.get().isEnabled(\"advancedAccessControlLayer.teams\");\n }\n\n public canCreateFolderInRoot(): boolean {\n const canCreateFolderInRootUseCase = new CanCreateFolderInRoot();\n return canCreateFolderInRootUseCase.execute();\n }\n\n public permissionsIncludeNonInheritedPermissions(permissions: FolderPermission[]): boolean {\n const checkNotInheritedPermissionsUseCase = new CheckNotInheritedPermissions();\n return checkNotInheritedPermissionsUseCase.execute(permissions);\n }\n\n public async canAccessFolder(params: CanAccessFolderParams): Promise<boolean> {\n if (\n !this.canUseFolderLevelPermissions() ||\n !this.identityContext.isAuthorizationEnabled()\n ) {\n return true;\n }\n\n const canAccessFolderUseCase = new CanAccessFolder(this.identityContext);\n return await canAccessFolderUseCase.execute(params);\n }\n\n public async canAccessFolderContent(params: CanAccessFolderContentParams): Promise<boolean> {\n const canUseFlp = this.canUseFolderLevelPermissions();\n const authEnabled = this.identityContext.isAuthorizationEnabled();\n\n if (!canUseFlp || !authEnabled) {\n return true;\n }\n\n const canAccessFolderContentUseCase = new CanAccessFolderContent(this.identityContext);\n return await canAccessFolderContentUseCase.execute(params);\n }\n\n public async ensureCanAccessFolder(params: CanAccessFolderParams): Promise<void> {\n const result = await this.canAccessFolder(params);\n if (!result) {\n throw new NotAuthorizedError();\n }\n }\n\n public async ensureCanAccessFolderContent(params: CanAccessFolderContentParams): Promise<void> {\n const result = await this.canAccessFolderContent(params);\n if (!result) {\n throw new NotAuthorizedError();\n }\n }\n\n public async canManageFolderContent(flp: FolderLevelPermission): Promise<boolean> {\n if (\n !this.canUseFolderLevelPermissions() ||\n !this.identityContext.isAuthorizationEnabled()\n ) {\n return true;\n }\n\n return await this.canAccessFolderContent({ permissions: flp.permissions, rwd: \"w\" });\n }\n\n public async canManageFolderStructure(flp: FolderLevelPermission): Promise<boolean> {\n if (\n !this.canUseFolderLevelPermissions() ||\n !this.identityContext.isAuthorizationEnabled()\n ) {\n return true;\n }\n\n return await this.canAccessFolder({ permissions: flp.permissions, rwd: \"w\" });\n }\n\n public async canManageFolderPermissions(flp: FolderLevelPermission): Promise<boolean> {\n if (!this.canUseFolderLevelPermissions()) {\n return false;\n }\n\n if (!this.identityContext.isAuthorizationEnabled()) {\n return true;\n }\n\n return await this.canAccessFolder({\n permissions: flp.permissions,\n rwd: \"w\",\n managePermissions: true\n });\n }\n\n // With teams enabled, every call loads the current user's teams through `ListUserTeamsUseCase`\n // (an admin user read plus a team list). Nothing caches them between calls.\n public getDefaultPermissions(permissions: FolderPermission[]): Promise<FolderPermission[]> {\n return this.createDefaultPermissions().execute(permissions);\n }\n\n public async getDefaultPermissionsBatch(\n permissionsList: FolderPermission[][]\n ): Promise<FolderPermission[][]> {\n if (permissionsList.length === 0) {\n return [];\n }\n const identity = this.identityContext.getIdentity();\n const identityPermissions = await this.identityContext.listPermissions();\n\n let identityTeams: Team[] = [];\n if (this.canUseTeams()) {\n const result = await this.listUserTeamsUseCase.execute(identity.id);\n identityTeams = result.isOk() ? result.value : [];\n }\n\n // The same steps as getDefaultPermissions(), with the lookups done once.\n return permissionsList.map(permissions =>\n DefaultPermissionsMerger.merge(\n identity,\n identityPermissions,\n this.canUseTeams()\n ? expandTeamPermissions(identity, identityTeams, permissions)\n : permissions\n )\n );\n }\n\n public async listFolderLevelPermissions(params: ListFolderPermissionsParams): Promise<\n Array<{\n id: string;\n permissions: FolderPermission[];\n }>\n > {\n const flps = await this.listFlpsUseCase.execute(params);\n\n // One instance for every listed record: with teams enabled, the user's teams are loaded\n // once per call, not once per record.\n const defaultPermissions = this.createDefaultPermissions();\n return Promise.all(\n flps.map(async flp => ({\n id: flp.id,\n permissions: await defaultPermissions.execute(flp.permissions)\n }))\n );\n }\n\n private createDefaultPermissions(): IGetDefaultPermissions {\n const getDefaultPermissionsUseCase = new GetDefaultPermissions(this.identityContext);\n if (!this.canUseTeams()) {\n return getDefaultPermissionsUseCase;\n }\n return new GetDefaultPermissionsWithTeams(\n this.identityContext,\n this.listUserTeamsUseCase,\n getDefaultPermissionsUseCase\n );\n }\n\n public async getFolderLevelPermissions(id: string): Promise<FolderPermission[]> {\n const flp = await this.getFlpUseCase.execute(id);\n return await this.getDefaultPermissions(flp?.permissions ?? []);\n }\n}\n\nexport const FolderLevelPermissions = createImplementation({\n abstraction: FolderLevelPermissionsAbstraction,\n implementation: FolderLevelPermissionsImpl,\n dependencies: [\n IdentityContext,\n FeatureFlags,\n ListUserTeamsUseCase,\n GetFlpUseCase,\n ListFlpsUseCase\n ]\n});\n"],"names":["FolderLevelPermissionsImpl","identityContext","featureFlags","listUserTeamsUseCase","getFlpUseCase","listFlpsUseCase","enabled","identity","canCreateFolderInRootUseCase","CanCreateFolderInRoot","permissions","checkNotInheritedPermissionsUseCase","CheckNotInheritedPermissions","params","canAccessFolderUseCase","CanAccessFolder","canUseFlp","authEnabled","canAccessFolderContentUseCase","CanAccessFolderContent","result","NotAuthorizedError","flp","permissionsList","identityPermissions","identityTeams","DefaultPermissionsMerger","expandTeamPermissions","flps","defaultPermissions","Promise","getDefaultPermissionsUseCase","GetDefaultPermissions","GetDefaultPermissionsWithTeams","id","FolderLevelPermissions","createImplementation","FolderLevelPermissionsAbstraction","IdentityContext","FeatureFlags","ListUserTeamsUseCase","GetFlpUseCase","ListFlpsUseCase"],"mappings":";;;;;;;;;;;AAyBA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,YAAoC,EACpCC,oBAAoD,EACpDC,aAAsC,EACtCC,eAA0C,CACpD;aALUJ,eAAe,GAAfA;aACAC,YAAY,GAAZA;aACAC,oBAAoB,GAApBA;aACAC,aAAa,GAAbA;aACAC,eAAe,GAAfA;IACT;IAEI,6BAA6BC,OAAiB,EAAW;QAC5D,IAAIA,AAAY,UAAZA,SACA,OAAO;QAGX,MAAMC,WAAW,IAAI,CAAC,eAAe,CAAC,WAAW;QAKjD,IAAIA,AAAkB,YAAlBA,SAAS,IAAI,EACb,OAAO;QAGX,OAAO,IAAI,CAAC,YAAY,CACnB,GAAG,GACH,SAAS,CAAC;IACnB;IAEO,cAAuB;QAC1B,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,GAAG,SAAS,CAAC;IAC7C;IAEO,wBAAiC;QACpC,MAAMC,+BAA+B,IAAIC;QACzC,OAAOD,6BAA6B,OAAO;IAC/C;IAEO,0CAA0CE,WAA+B,EA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ACP,IAAI,WAAW;YACjE;IAER;IAEQ,2BAAmD;QACvD,MAAMS,+BAA+B,IAAIC,sBAAsB,IAAI,CAAC,eAAe;QACnF,IAAI,CAAC,IAAI,CAAC,WAAW,IACjB,OAAOD;QAEX,OAAO,IAAIE,+BACP,IAAI,CAAC,eAAe,EACpB,IAAI,CAAC,oBAAoB,EACzBF;IAER;IAEA,MAAa,0BAA0BG,EAAU,EAA+B;QAC5E,MAAMZ,MAAM,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAACY;QAC7C,OAAO,MAAM,IAAI,CAAC,qBAAqB,CAACZ,KAAK,eAAe,EAAE;IAClE;AACJ;AAEO,MAAMa,gDAAyBC,qBAAqB;IACvD,aAAaC;IACb,gBAAgBrC;IAChB,cAAc;QACVsC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
@@ -1,6 +1,6 @@
1
1
  const mayAskAboutUser = async (identityContext, userId)=>{
2
2
  if (!identityContext.isAuthorizationEnabled()) return true;
3
- if (identityContext.getIdentity()?.id === userId) return true;
3
+ if (identityContext.getIdentity().id === userId) return true;
4
4
  const permissions = await identityContext.listPermissions();
5
5
  return permissions.some((permission)=>"*" === permission.name);
6
6
  };
@@ -1 +1 @@
1
- {"version":3,"file":"features/flp/ListFolderAccess/mayAskAboutUser.js","sources":["../../../../src/features/flp/ListFolderAccess/mayAskAboutUser.ts"],"sourcesContent":["import type { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/abstractions.js\";\n\n/** About oneself, always; about others, with full access (or authorization turned off). */\nexport const mayAskAboutUser = async (\n identityContext: IdentityContext.Interface,\n userId: string\n): Promise<boolean> => {\n if (!identityContext.isAuthorizationEnabled()) {\n return true;\n }\n if (identityContext.getIdentity()?.id === userId) {\n return true;\n }\n const permissions = await identityContext.listPermissions();\n return permissions.some(permission => permission.name === \"*\");\n};\n"],"names":["mayAskAboutUser","identityContext","userId","permissions","permission"],"mappings":"AAGO,MAAMA,kBAAkB,OAC3BC,iBACAC;IAEA,IAAI,CAACD,gBAAgB,sBAAsB,IACvC,OAAO;IAEX,IAAIA,gBAAgB,WAAW,IAAI,OAAOC,QACtC,OAAO;IAEX,MAAMC,cAAc,MAAMF,gBAAgB,eAAe;IACzD,OAAOE,YAAY,IAAI,CAACC,CAAAA,aAAcA,AAAoB,QAApBA,WAAW,IAAI;AACzD"}
1
+ {"version":3,"file":"features/flp/ListFolderAccess/mayAskAboutUser.js","sources":["../../../../src/features/flp/ListFolderAccess/mayAskAboutUser.ts"],"sourcesContent":["import type { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/abstractions.js\";\n\n/** About oneself, always; about others, with full access (or authorization turned off). */\nexport const mayAskAboutUser = async (\n identityContext: IdentityContext.Interface,\n userId: string\n): Promise<boolean> => {\n if (!identityContext.isAuthorizationEnabled()) {\n return true;\n }\n if (identityContext.getIdentity().id === userId) {\n return true;\n }\n const permissions = await identityContext.listPermissions();\n return permissions.some(permission => permission.name === \"*\");\n};\n"],"names":["mayAskAboutUser","identityContext","userId","permissions","permission"],"mappings":"AAGO,MAAMA,kBAAkB,OAC3BC,iBACAC;IAEA,IAAI,CAACD,gBAAgB,sBAAsB,IACvC,OAAO;IAEX,IAAIA,gBAAgB,WAAW,GAAG,EAAE,KAAKC,QACrC,OAAO;IAEX,MAAMC,cAAc,MAAMF,gBAAgB,eAAe;IACzD,OAAOE,YAAY,IAAI,CAACC,CAAAA,aAAcA,AAAoB,QAApBA,WAAW,IAAI;AACzD"}
@@ -1,9 +1,9 @@
1
1
  import { FolderAfterDeleteEventHandler } from "../../../features/folder/DeleteFolder/abstractions.js";
2
2
  import type { FolderAfterDeleteEvent } from "../../../features/folder/DeleteFolder/events.js";
3
- import { NotifyFolderChangeUseCase } from "./abstractions.js";
3
+ import { NotifyRecordChangeUseCase } from "@webiny/api-core/features/websockets/index.js";
4
4
  declare class NotifyOnFolderDeletedHandlerImpl implements FolderAfterDeleteEventHandler.Interface {
5
- private notifyFolderChange;
6
- constructor(notifyFolderChange: NotifyFolderChangeUseCase.Interface);
5
+ private notifyRecordChange;
6
+ constructor(notifyRecordChange: NotifyRecordChangeUseCase.Interface);
7
7
  handle(event: FolderAfterDeleteEvent): Promise<void>;
8
8
  }
9
9
  export declare const NotifyOnFolderDeletedHandler: typeof NotifyOnFolderDeletedHandlerImpl & {
@@ -1,22 +1,22 @@
1
1
  import { FolderAfterDeleteEventHandler } from "../DeleteFolder/abstractions.js";
2
- import { NotifyFolderChangeUseCase } from "./abstractions.js";
2
+ import { NotifyRecordChangeUseCase } from "@webiny/api-core/features/websockets/index.js";
3
+ import { FOLDER_RECORD_TYPE } from "./recordType.js";
3
4
  class NotifyOnFolderDeletedHandlerImpl {
4
- constructor(notifyFolderChange){
5
- this.notifyFolderChange = notifyFolderChange;
5
+ constructor(notifyRecordChange){
6
+ this.notifyRecordChange = notifyRecordChange;
6
7
  }
7
8
  async handle(event) {
8
- try {
9
- await this.notifyFolderChange.execute({
10
- id: event.payload.folder.id,
11
- change: "deleted"
12
- });
13
- } catch {}
9
+ await this.notifyRecordChange.execute({
10
+ type: FOLDER_RECORD_TYPE,
11
+ id: event.payload.folder.id,
12
+ change: "deleted"
13
+ });
14
14
  }
15
15
  }
16
16
  const NotifyOnFolderDeletedHandler = FolderAfterDeleteEventHandler.createImplementation({
17
17
  implementation: NotifyOnFolderDeletedHandlerImpl,
18
18
  dependencies: [
19
- NotifyFolderChangeUseCase
19
+ NotifyRecordChangeUseCase
20
20
  ]
21
21
  });
22
22
  export { NotifyOnFolderDeletedHandler };
@@ -1 +1 @@
1
- {"version":3,"file":"features/folder/NotifyFolderChange/NotifyOnFolderDeletedHandler.js","sources":["../../../../src/features/folder/NotifyFolderChange/NotifyOnFolderDeletedHandler.ts"],"sourcesContent":["import { FolderAfterDeleteEventHandler } from \"~/features/folder/DeleteFolder/abstractions.js\";\nimport type { FolderAfterDeleteEvent } from \"~/features/folder/DeleteFolder/events.js\";\nimport { NotifyFolderChangeUseCase } from \"./abstractions.js\";\n\n/*\n * Created and updated folders are announced by the FLP tasks, once the admin can read them back. A\n * deleted folder is only dropped from the admin's cache, so there is nothing to wait for.\n */\nclass NotifyOnFolderDeletedHandlerImpl implements FolderAfterDeleteEventHandler.Interface {\n constructor(private notifyFolderChange: NotifyFolderChangeUseCase.Interface) {}\n\n async handle(event: FolderAfterDeleteEvent): Promise<void> {\n try {\n await this.notifyFolderChange.execute({\n id: event.payload.folder.id,\n change: \"deleted\"\n });\n } catch {\n // The folder is gone either way; the admin drops it on its next reload.\n }\n }\n}\n\nexport const NotifyOnFolderDeletedHandler = FolderAfterDeleteEventHandler.createImplementation({\n implementation: NotifyOnFolderDeletedHandlerImpl,\n dependencies: [NotifyFolderChangeUseCase]\n});\n"],"names":["NotifyOnFolderDeletedHandlerImpl","notifyFolderChange","event","NotifyOnFolderDeletedHandler","FolderAfterDeleteEventHandler","NotifyFolderChangeUseCase"],"mappings":";;AAQA,MAAMA;IACF,YAAoBC,kBAAuD,CAAE;aAAzDA,kBAAkB,GAAlBA;IAA0D;IAE9E,MAAM,OAAOC,KAA6B,EAAiB;QACvD,IAAI;YACA,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC;gBAClC,IAAIA,MAAM,OAAO,CAAC,MAAM,CAAC,EAAE;gBAC3B,QAAQ;YACZ;QACJ,EAAE,OAAM,CAER;IACJ;AACJ;AAEO,MAAMC,+BAA+BC,8BAA8B,oBAAoB,CAAC;IAC3F,gBAAgBJ;IAChB,cAAc;QAACK;KAA0B;AAC7C"}
1
+ {"version":3,"file":"features/folder/NotifyFolderChange/NotifyOnFolderDeletedHandler.js","sources":["../../../../src/features/folder/NotifyFolderChange/NotifyOnFolderDeletedHandler.ts"],"sourcesContent":["import { FolderAfterDeleteEventHandler } from \"~/features/folder/DeleteFolder/abstractions.js\";\nimport type { FolderAfterDeleteEvent } from \"~/features/folder/DeleteFolder/events.js\";\nimport { NotifyRecordChangeUseCase } from \"@webiny/api-core/features/websockets/index.js\";\nimport { FOLDER_RECORD_TYPE } from \"./recordType.js\";\n\n/*\n * Created and updated folders are announced by the FLP tasks, once the admin can read them back. A\n * deleted folder is only dropped from the admin's cache, so there is nothing to wait for.\n */\nclass NotifyOnFolderDeletedHandlerImpl implements FolderAfterDeleteEventHandler.Interface {\n constructor(private notifyRecordChange: NotifyRecordChangeUseCase.Interface) {}\n\n async handle(event: FolderAfterDeleteEvent): Promise<void> {\n await this.notifyRecordChange.execute({\n type: FOLDER_RECORD_TYPE,\n id: event.payload.folder.id,\n change: \"deleted\"\n });\n }\n}\n\nexport const NotifyOnFolderDeletedHandler = FolderAfterDeleteEventHandler.createImplementation({\n implementation: NotifyOnFolderDeletedHandlerImpl,\n dependencies: [NotifyRecordChangeUseCase]\n});\n"],"names":["NotifyOnFolderDeletedHandlerImpl","notifyRecordChange","event","FOLDER_RECORD_TYPE","NotifyOnFolderDeletedHandler","FolderAfterDeleteEventHandler","NotifyRecordChangeUseCase"],"mappings":";;;AASA,MAAMA;IACF,YAAoBC,kBAAuD,CAAE;aAAzDA,kBAAkB,GAAlBA;IAA0D;IAE9E,MAAM,OAAOC,KAA6B,EAAiB;QACvD,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC;YAClC,MAAMC;YACN,IAAID,MAAM,OAAO,CAAC,MAAM,CAAC,EAAE;YAC3B,QAAQ;QACZ;IACJ;AACJ;AAEO,MAAME,+BAA+BC,8BAA8B,oBAAoB,CAAC;IAC3F,gBAAgBL;IAChB,cAAc;QAACM;KAA0B;AAC7C"}
@@ -1,10 +1,8 @@
1
1
  import { createFeature } from "@webiny/feature/api";
2
- import { NotifyFolderChangeUseCase } from "./NotifyFolderChangeUseCase.js";
3
2
  import { NotifyOnFolderDeletedHandler } from "./NotifyOnFolderDeletedHandler.js";
4
3
  const NotifyFolderChangeFeature = createFeature({
5
4
  name: "NotifyFolderChange",
6
5
  register (container) {
7
- container.register(NotifyFolderChangeUseCase);
8
6
  container.register(NotifyOnFolderDeletedHandler);
9
7
  }
10
8
  });
@@ -1 +1 @@
1
- {"version":3,"file":"features/folder/NotifyFolderChange/feature.js","sources":["../../../../src/features/folder/NotifyFolderChange/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { NotifyFolderChangeUseCase } from \"./NotifyFolderChangeUseCase.js\";\nimport { NotifyOnFolderDeletedHandler } from \"./NotifyOnFolderDeletedHandler.js\";\n\n/**\n * Tells the user's open admin tabs when a folder is created, updated or deleted. The FLP tasks send\n * created and updated (triggered by `TaskFolderCatalogSync`); deleted goes out from here.\n */\nexport const NotifyFolderChangeFeature = createFeature({\n name: \"NotifyFolderChange\",\n register(container) {\n container.register(NotifyFolderChangeUseCase);\n container.register(NotifyOnFolderDeletedHandler);\n }\n});\n"],"names":["NotifyFolderChangeFeature","createFeature","container","NotifyFolderChangeUseCase","NotifyOnFolderDeletedHandler"],"mappings":";;;AAQO,MAAMA,4BAA4BC,cAAc;IACnD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;IACvB;AACJ"}
1
+ {"version":3,"file":"features/folder/NotifyFolderChange/feature.js","sources":["../../../../src/features/folder/NotifyFolderChange/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { NotifyOnFolderDeletedHandler } from \"./NotifyOnFolderDeletedHandler.js\";\n\n/**\n * Tells the user's open admin tabs when a folder is created, updated or deleted. The FLP tasks send\n * created and updated (triggered by `TaskFolderCatalogSync`); deleted goes out from here.\n */\nexport const NotifyFolderChangeFeature = createFeature({\n name: \"NotifyFolderChange\",\n register(container) {\n container.register(NotifyOnFolderDeletedHandler);\n }\n});\n"],"names":["NotifyFolderChangeFeature","createFeature","container","NotifyOnFolderDeletedHandler"],"mappings":";;AAOO,MAAMA,4BAA4BC,cAAc;IACnD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
@@ -1,2 +1,2 @@
1
1
  export { NotifyFolderChangeFeature } from "./feature.js";
2
- export { NotifyFolderChangeUseCase, FOLDER_CREATED_WEBSOCKET_ACTION, FOLDER_UPDATED_WEBSOCKET_ACTION, FOLDER_DELETED_WEBSOCKET_ACTION } from "./abstractions.js";
2
+ export { FOLDER_RECORD_TYPE } from "./recordType.js";
@@ -1,2 +1,2 @@
1
1
  export { NotifyFolderChangeFeature } from "./feature.js";
2
- export { FOLDER_CREATED_WEBSOCKET_ACTION, FOLDER_DELETED_WEBSOCKET_ACTION, FOLDER_UPDATED_WEBSOCKET_ACTION, NotifyFolderChangeUseCase } from "./abstractions.js";
2
+ export { FOLDER_RECORD_TYPE } from "./recordType.js";
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The `type` of the record-changed message sent when a folder changes. The admin's
3
+ * `ApplyFolderChangeToCache` filters on the same string.
4
+ *
5
+ * `created` and `updated` go out when the FLP tasks finish, since folder reads report permissions
6
+ * from the FLP records. `deleted` goes out right after the delete: nothing is read back.
7
+ */
8
+ export declare const FOLDER_RECORD_TYPE = "aco.folder";
@@ -0,0 +1,4 @@
1
+ const FOLDER_RECORD_TYPE = "aco.folder";
2
+ export { FOLDER_RECORD_TYPE };
3
+
4
+ //# sourceMappingURL=recordType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/folder/NotifyFolderChange/recordType.js","sources":["../../../../src/features/folder/NotifyFolderChange/recordType.ts"],"sourcesContent":["/**\n * The `type` of the record-changed message sent when a folder changes. The admin's\n * `ApplyFolderChangeToCache` filters on the same string.\n *\n * `created` and `updated` go out when the FLP tasks finish, since folder reads report permissions\n * from the FLP records. `deleted` goes out right after the delete: nothing is read back.\n */\nexport const FOLDER_RECORD_TYPE = \"aco.folder\";\n"],"names":["FOLDER_RECORD_TYPE"],"mappings":"AAOO,MAAMA,qBAAqB"}
@@ -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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ewParent, 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,