@webiny/api-core 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 (170) hide show
  1. package/ApiCoreFeature.js +5 -0
  2. package/ApiCoreFeature.js.map +1 -1
  3. package/exports/api.d.ts +1 -0
  4. package/exports/api.js +1 -0
  5. package/features/ai/AiSdkTools.d.ts +1 -1
  6. package/features/ai/AiSdkTools.js +3 -2
  7. package/features/ai/AiSdkTools.js.map +1 -1
  8. package/features/ai/abstractions.d.ts +9 -1
  9. package/features/ai/abstractions.js.map +1 -1
  10. package/features/ai/index.d.ts +1 -0
  11. package/features/ai/index.js +1 -0
  12. package/features/ai/isReadOnlyTool.d.ts +9 -0
  13. package/features/ai/isReadOnlyTool.js +4 -0
  14. package/features/ai/isReadOnlyTool.js.map +1 -0
  15. package/features/cdnCache/NullCdnCache.d.ts +8 -0
  16. package/features/cdnCache/NullCdnCache.js +11 -0
  17. package/features/cdnCache/NullCdnCache.js.map +1 -0
  18. package/features/cdnCache/abstractions.d.ts +20 -0
  19. package/features/cdnCache/abstractions.js +5 -0
  20. package/features/cdnCache/abstractions.js.map +1 -0
  21. package/features/cdnCache/feature.d.ts +8 -0
  22. package/features/cdnCache/feature.js +11 -0
  23. package/features/cdnCache/feature.js.map +1 -0
  24. package/features/cdnCache/index.d.ts +2 -0
  25. package/features/cdnCache/index.js +2 -0
  26. package/features/requestStorage/abstractions.d.ts +23 -0
  27. package/features/requestStorage/abstractions.js +5 -0
  28. package/features/requestStorage/abstractions.js.map +1 -0
  29. package/features/requestStorage/index.d.ts +1 -0
  30. package/features/requestStorage/index.js +1 -0
  31. package/features/security/CanAccessCurrentTenant/CanAccessCurrentTenantUseCase.d.ts +13 -0
  32. package/features/security/CanAccessCurrentTenant/CanAccessCurrentTenantUseCase.js +25 -0
  33. package/features/security/CanAccessCurrentTenant/CanAccessCurrentTenantUseCase.js.map +1 -0
  34. package/features/security/CanAccessCurrentTenant/abstractions.d.ts +12 -0
  35. package/features/security/CanAccessCurrentTenant/abstractions.js +5 -0
  36. package/features/security/CanAccessCurrentTenant/abstractions.js.map +1 -0
  37. package/features/security/CanAccessCurrentTenant/feature.d.ts +4 -0
  38. package/features/security/CanAccessCurrentTenant/feature.js +11 -0
  39. package/features/security/CanAccessCurrentTenant/feature.js.map +1 -0
  40. package/features/security/CanAccessCurrentTenant/index.d.ts +2 -0
  41. package/features/security/CanAccessCurrentTenant/index.js +2 -0
  42. package/features/security/SecurityFeature.js +4 -0
  43. package/features/security/SecurityFeature.js.map +1 -1
  44. package/features/security/ai/CreateRoleTool.d.ts +54 -0
  45. package/features/security/ai/CreateRoleTool.js +71 -0
  46. package/features/security/ai/CreateRoleTool.js.map +1 -0
  47. package/features/security/ai/CreateTeamTool.d.ts +49 -0
  48. package/features/security/ai/CreateTeamTool.js +56 -0
  49. package/features/security/ai/CreateTeamTool.js.map +1 -0
  50. package/features/security/ai/DeleteRoleTool.d.ts +52 -0
  51. package/features/security/ai/DeleteRoleTool.js +79 -0
  52. package/features/security/ai/DeleteRoleTool.js.map +1 -0
  53. package/features/security/ai/DeleteTeamTool.d.ts +47 -0
  54. package/features/security/ai/DeleteTeamTool.js +56 -0
  55. package/features/security/ai/DeleteTeamTool.js.map +1 -0
  56. package/features/security/ai/ListRolesTool.d.ts +40 -0
  57. package/features/security/ai/ListRolesTool.js +48 -0
  58. package/features/security/ai/ListRolesTool.js.map +1 -0
  59. package/features/security/ai/ListTeamsTool.d.ts +42 -0
  60. package/features/security/ai/ListTeamsTool.js +49 -0
  61. package/features/security/ai/ListTeamsTool.js.map +1 -0
  62. package/features/security/ai/UpdateRoleTool.d.ts +46 -0
  63. package/features/security/ai/UpdateRoleTool.js +53 -0
  64. package/features/security/ai/UpdateRoleTool.js.map +1 -0
  65. package/features/security/ai/UpdateTeamTool.d.ts +53 -0
  66. package/features/security/ai/UpdateTeamTool.js +56 -0
  67. package/features/security/ai/UpdateTeamTool.js.map +1 -0
  68. package/features/security/ai/feature.d.ts +10 -0
  69. package/features/security/ai/feature.js +25 -0
  70. package/features/security/ai/feature.js.map +1 -0
  71. package/features/security/ai/index.d.ts +9 -0
  72. package/features/security/ai/index.js +9 -0
  73. package/features/security/apiKeys/ApiKeyAuthorizer.js +1 -1
  74. package/features/security/apiKeys/ApiKeyAuthorizer.js.map +1 -1
  75. package/features/security/roles/NotifyRoleChange/NotifyOnRoleCreatedHandler.d.ts +11 -0
  76. package/features/security/roles/NotifyRoleChange/NotifyOnRoleCreatedHandler.js +24 -0
  77. package/features/security/roles/NotifyRoleChange/NotifyOnRoleCreatedHandler.js.map +1 -0
  78. package/features/security/roles/NotifyRoleChange/NotifyOnRoleDeletedHandler.d.ts +11 -0
  79. package/features/security/roles/NotifyRoleChange/NotifyOnRoleDeletedHandler.js +24 -0
  80. package/features/security/roles/NotifyRoleChange/NotifyOnRoleDeletedHandler.js.map +1 -0
  81. package/features/security/roles/NotifyRoleChange/NotifyOnRoleUpdatedHandler.d.ts +11 -0
  82. package/features/security/roles/NotifyRoleChange/NotifyOnRoleUpdatedHandler.js +24 -0
  83. package/features/security/roles/NotifyRoleChange/NotifyOnRoleUpdatedHandler.js.map +1 -0
  84. package/features/security/roles/NotifyRoleChange/feature.d.ts +5 -0
  85. package/features/security/roles/NotifyRoleChange/feature.js +15 -0
  86. package/features/security/roles/NotifyRoleChange/feature.js.map +1 -0
  87. package/features/security/roles/NotifyRoleChange/index.d.ts +2 -0
  88. package/features/security/roles/NotifyRoleChange/index.js +2 -0
  89. package/features/security/roles/NotifyRoleChange/recordType.d.ts +5 -0
  90. package/features/security/roles/NotifyRoleChange/recordType.js +4 -0
  91. package/features/security/roles/NotifyRoleChange/recordType.js.map +1 -0
  92. package/features/security/roles/UpdateRole/UpdateRoleUseCase.js +2 -1
  93. package/features/security/roles/UpdateRole/UpdateRoleUseCase.js.map +1 -1
  94. package/features/security/roles/feature.js +2 -0
  95. package/features/security/roles/feature.js.map +1 -1
  96. package/features/security/shared/definedOnly.d.ts +1 -0
  97. package/features/security/shared/definedOnly.js +8 -0
  98. package/features/security/shared/definedOnly.js.map +1 -0
  99. package/features/security/shared/index.d.ts +1 -0
  100. package/features/security/shared/index.js +1 -0
  101. package/features/security/teams/NotifyTeamChange/NotifyOnTeamChangeHandlers.d.ts +29 -0
  102. package/features/security/teams/NotifyTeamChange/NotifyOnTeamChangeHandlers.js +62 -0
  103. package/features/security/teams/NotifyTeamChange/NotifyOnTeamChangeHandlers.js.map +1 -0
  104. package/features/security/teams/NotifyTeamChange/feature.d.ts +5 -0
  105. package/features/security/teams/NotifyTeamChange/feature.js +13 -0
  106. package/features/security/teams/NotifyTeamChange/feature.js.map +1 -0
  107. package/features/security/teams/NotifyTeamChange/index.d.ts +2 -0
  108. package/features/security/teams/NotifyTeamChange/index.js +2 -0
  109. package/features/security/teams/NotifyTeamChange/recordType.d.ts +5 -0
  110. package/features/security/teams/NotifyTeamChange/recordType.js +4 -0
  111. package/features/security/teams/NotifyTeamChange/recordType.js.map +1 -0
  112. package/features/security/teams/UpdateTeam/UpdateTeamUseCase.js +2 -1
  113. package/features/security/teams/UpdateTeam/UpdateTeamUseCase.js.map +1 -1
  114. package/features/security/teams/feature.js +2 -0
  115. package/features/security/teams/feature.js.map +1 -1
  116. package/features/task/TaskService/abstractions.d.ts +7 -0
  117. package/features/task/TaskService/abstractions.js.map +1 -1
  118. package/features/users/AdminUsersFeature.js +4 -0
  119. package/features/users/AdminUsersFeature.js.map +1 -1
  120. package/features/users/CreateUser/CreateUserUseCase.js +1 -1
  121. package/features/users/CreateUser/CreateUserUseCase.js.map +1 -1
  122. package/features/users/NotifyUserChange/NotifyOnUserChangeHandlers.d.ts +29 -0
  123. package/features/users/NotifyUserChange/NotifyOnUserChangeHandlers.js +62 -0
  124. package/features/users/NotifyUserChange/NotifyOnUserChangeHandlers.js.map +1 -0
  125. package/features/users/NotifyUserChange/feature.d.ts +5 -0
  126. package/features/users/NotifyUserChange/feature.js +13 -0
  127. package/features/users/NotifyUserChange/feature.js.map +1 -0
  128. package/features/users/NotifyUserChange/index.d.ts +2 -0
  129. package/features/users/NotifyUserChange/index.js +2 -0
  130. package/features/users/NotifyUserChange/recordType.d.ts +5 -0
  131. package/features/users/NotifyUserChange/recordType.js +4 -0
  132. package/features/users/NotifyUserChange/recordType.js.map +1 -0
  133. package/features/users/ai/ListUsersTool.d.ts +39 -0
  134. package/features/users/ai/ListUsersTool.js +46 -0
  135. package/features/users/ai/ListUsersTool.js.map +1 -0
  136. package/features/users/ai/UpdateUserAccessTool.d.ts +59 -0
  137. package/features/users/ai/UpdateUserAccessTool.js +101 -0
  138. package/features/users/ai/UpdateUserAccessTool.js.map +1 -0
  139. package/features/users/ai/feature.d.ts +11 -0
  140. package/features/users/ai/feature.js +13 -0
  141. package/features/users/ai/feature.js.map +1 -0
  142. package/features/users/ai/index.d.ts +3 -0
  143. package/features/users/ai/index.js +3 -0
  144. package/features/websockets/NotifyRecordChange/NotifyRecordChangeUseCase.d.ts +12 -0
  145. package/features/websockets/NotifyRecordChange/NotifyRecordChangeUseCase.js +38 -0
  146. package/features/websockets/NotifyRecordChange/NotifyRecordChangeUseCase.js.map +1 -0
  147. package/features/websockets/NotifyRecordChange/abstractions.d.ts +39 -0
  148. package/features/websockets/NotifyRecordChange/abstractions.js +6 -0
  149. package/features/websockets/NotifyRecordChange/abstractions.js.map +1 -0
  150. package/features/websockets/NotifyRecordChange/feature.d.ts +5 -0
  151. package/features/websockets/NotifyRecordChange/feature.js +11 -0
  152. package/features/websockets/NotifyRecordChange/feature.js.map +1 -0
  153. package/features/websockets/NotifyRecordChange/index.d.ts +2 -0
  154. package/features/websockets/NotifyRecordChange/index.js +2 -0
  155. package/features/websockets/SendToIdentity/NullSendToIdentityUseCase.d.ts +20 -0
  156. package/features/websockets/SendToIdentity/NullSendToIdentityUseCase.js +24 -0
  157. package/features/websockets/SendToIdentity/NullSendToIdentityUseCase.js.map +1 -0
  158. package/features/websockets/SendToIdentity/abstractions.d.ts +19 -0
  159. package/features/websockets/SendToIdentity/abstractions.js +5 -0
  160. package/features/websockets/SendToIdentity/abstractions.js.map +1 -0
  161. package/features/websockets/WebsocketServiceError.d.ts +7 -0
  162. package/features/websockets/WebsocketServiceError.js +14 -0
  163. package/features/websockets/WebsocketServiceError.js.map +1 -0
  164. package/features/websockets/index.d.ts +7 -0
  165. package/features/websockets/index.js +4 -0
  166. package/features/websockets/types.d.ts +15 -0
  167. package/features/websockets/types.js +0 -0
  168. package/index.d.ts +1 -0
  169. package/index.js +1 -0
  170. package/package.json +11 -11
@@ -0,0 +1,49 @@
1
+ import { z } from "zod";
2
+ import { AiSdkToolDefinition, AiSdkToolHandler } from "../../ai/index.js";
3
+ import { ListTeamsUseCase } from "../teams/ListTeams/index.js";
4
+ const inputSchema = z.object({});
5
+ class ListTeamsToolHandlerImpl {
6
+ constructor(listTeams){
7
+ this.listTeams = listTeams;
8
+ }
9
+ async execute() {
10
+ const result = await this.listTeams.execute();
11
+ if (result.isFail()) throw new Error(`Could not list teams: ${result.error.message}`);
12
+ return result.value.map((team)=>{
13
+ const summary = {
14
+ id: team.id,
15
+ name: team.name,
16
+ slug: team.slug,
17
+ roles: team.roles
18
+ };
19
+ if (team.description) summary.description = team.description;
20
+ return summary;
21
+ });
22
+ }
23
+ }
24
+ const ListTeamsToolHandler = AiSdkToolHandler.createImplementation({
25
+ implementation: ListTeamsToolHandlerImpl,
26
+ dependencies: [
27
+ ListTeamsUseCase
28
+ ]
29
+ });
30
+ class ListTeamsToolImpl {
31
+ constructor(){
32
+ this.name = "listTeams";
33
+ this.title = "List teams";
34
+ this.description = "Lists the teams in this project with their ids, names, slugs and role ids. Folder permission targets use the SLUG (`team:<slug>`), not the id; updateTeam and deleteTeam take the id.";
35
+ this.inputSchema = inputSchema;
36
+ this.annotations = {
37
+ readOnlyHint: true,
38
+ idempotentHint: true
39
+ };
40
+ this.handler = ListTeamsToolHandler;
41
+ }
42
+ }
43
+ const ListTeamsTool = AiSdkToolDefinition.createImplementation({
44
+ implementation: ListTeamsToolImpl,
45
+ dependencies: []
46
+ });
47
+ export { ListTeamsTool };
48
+
49
+ //# sourceMappingURL=ListTeamsTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/security/ai/ListTeamsTool.js","sources":["../../../../src/features/security/ai/ListTeamsTool.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { AiSdkToolDefinition } from \"~/features/ai/index.js\";\nimport { AiSdkToolHandler } from \"~/features/ai/index.js\";\nimport { ListTeamsUseCase } from \"~/features/security/teams/ListTeams/index.js\";\n\nconst inputSchema = z.object({});\n\ntype Input = z.infer<typeof inputSchema>;\n\ninterface TeamSummary {\n id: string;\n name: string;\n slug: string;\n description?: string;\n /** Role ids, so `updateTeam` can be given the full list with one role added or removed. */\n roles: string[];\n}\n\nclass ListTeamsToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {\n constructor(private listTeams: ListTeamsUseCase.Interface) {}\n\n async execute(): Promise<TeamSummary[]> {\n const result = await this.listTeams.execute();\n\n if (result.isFail()) {\n throw new Error(`Could not list teams: ${result.error.message}`);\n }\n\n return result.value.map(team => {\n const summary: TeamSummary = {\n id: team.id,\n name: team.name,\n slug: team.slug,\n roles: team.roles\n };\n\n if (team.description) {\n summary.description = team.description;\n }\n\n return summary;\n });\n }\n}\n\nconst ListTeamsToolHandler = AiSdkToolHandler.createImplementation({\n implementation: ListTeamsToolHandlerImpl,\n dependencies: [ListTeamsUseCase]\n});\n\n/**\n * Resolves human names (\"team A\") to the ids folder permissions actually take.\n *\n * Kept separate from setFolderPermissions rather than accepting a team name there: the user approves\n * the arguments of a write, so the id has to be looked up and shown, not guessed inside the write.\n */\nclass ListTeamsToolImpl implements AiSdkToolDefinition.Interface<Input> {\n readonly name = \"listTeams\";\n readonly title = \"List teams\";\n readonly description =\n \"Lists the teams in this project with their ids, names, slugs and role ids. Folder permission targets use the SLUG (`team:<slug>`), not the id; updateTeam and deleteTeam take the id.\";\n readonly inputSchema = inputSchema;\n readonly annotations = { readOnlyHint: true, idempotentHint: true };\n readonly handler = ListTeamsToolHandler;\n}\n\nexport const ListTeamsTool = AiSdkToolDefinition.createImplementation({\n implementation: ListTeamsToolImpl,\n dependencies: []\n});\n"],"names":["inputSchema","z","ListTeamsToolHandlerImpl","listTeams","result","Error","team","summary","ListTeamsToolHandler","AiSdkToolHandler","ListTeamsUseCase","ListTeamsToolImpl","ListTeamsTool","AiSdkToolDefinition"],"mappings":";;;AAKA,MAAMA,cAAcC,EAAE,MAAM,CAAC,CAAC;AAa9B,MAAMC;IACF,YAAoBC,SAAqC,CAAE;aAAvCA,SAAS,GAATA;IAAwC;IAE5D,MAAM,UAAkC;QACpC,MAAMC,SAAS,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO;QAE3C,IAAIA,OAAO,MAAM,IACb,MAAM,IAAIC,MAAM,CAAC,sBAAsB,EAAED,OAAO,KAAK,CAAC,OAAO,EAAE;QAGnE,OAAOA,OAAO,KAAK,CAAC,GAAG,CAACE,CAAAA;YACpB,MAAMC,UAAuB;gBACzB,IAAID,KAAK,EAAE;gBACX,MAAMA,KAAK,IAAI;gBACf,MAAMA,KAAK,IAAI;gBACf,OAAOA,KAAK,KAAK;YACrB;YAEA,IAAIA,KAAK,WAAW,EAChBC,QAAQ,WAAW,GAAGD,KAAK,WAAW;YAG1C,OAAOC;QACX;IACJ;AACJ;AAEA,MAAMC,uBAAuBC,iBAAiB,oBAAoB,CAAC;IAC/D,gBAAgBP;IAChB,cAAc;QAACQ;KAAiB;AACpC;AAQA,MAAMC;;aACO,IAAI,GAAG;aACP,KAAK,GAAG;aACR,WAAW,GAChB;aACK,WAAW,GAAGX;aACd,WAAW,GAAG;YAAE,cAAc;YAAM,gBAAgB;QAAK;aACzD,OAAO,GAAGQ;;AACvB;AAEO,MAAMI,gBAAgBC,oBAAoB,oBAAoB,CAAC;IAClE,gBAAgBF;IAChB,cAAc,EAAE;AACpB"}
@@ -0,0 +1,46 @@
1
+ import { z } from "zod";
2
+ import { AiSdkToolDefinition } from "../../../features/ai/index.js";
3
+ import { AiSdkToolHandler } from "../../../features/ai/index.js";
4
+ import { UpdateRoleUseCase } from "../../../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("../../ai/abstractions").IAiSdkToolHandler<any>>;
41
+ };
42
+ }
43
+ export declare const UpdateRoleTool: typeof UpdateRoleToolImpl & {
44
+ __abstraction: import("@webiny/di").Abstraction<import("../../ai/abstractions").IAiSdkToolDefinition<any>>;
45
+ };
46
+ export {};
@@ -0,0 +1,53 @@
1
+ import { z } from "zod";
2
+ import { AiSdkToolDefinition, AiSdkToolHandler } from "../../ai/index.js";
3
+ import { UpdateRoleUseCase } from "../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/security/ai/UpdateRoleTool.js","sources":["../../../../src/features/security/ai/UpdateRoleTool.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { AiSdkToolDefinition } from \"~/features/ai/index.js\";\nimport { AiSdkToolHandler } from \"~/features/ai/index.js\";\nimport { UpdateRoleUseCase } from \"~/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,53 @@
1
+ import { z } from "zod";
2
+ import { AiSdkToolDefinition } from "../../../features/ai/index.js";
3
+ import { AiSdkToolHandler } from "../../../features/ai/index.js";
4
+ import { UpdateTeam } from "../../../features/security/teams/UpdateTeam/index.js";
5
+ declare const inputSchema: z.ZodObject<{
6
+ teamId: z.ZodString;
7
+ name: z.ZodOptional<z.ZodString>;
8
+ description: z.ZodOptional<z.ZodString>;
9
+ roles: z.ZodOptional<z.ZodArray<z.ZodString>>;
10
+ }, z.core.$strip>;
11
+ type Input = z.infer<typeof inputSchema>;
12
+ interface UpdatedTeam {
13
+ id: string;
14
+ name: string;
15
+ slug: string;
16
+ description: string;
17
+ roles: string[];
18
+ }
19
+ declare class UpdateTeamToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {
20
+ private updateTeam;
21
+ constructor(updateTeam: UpdateTeam.Interface);
22
+ execute(input: Input): Promise<UpdatedTeam>;
23
+ }
24
+ /**
25
+ * Changes a team's name, description or roles. The slug cannot change: folder permissions refer to
26
+ * teams by slug.
27
+ *
28
+ * Needs approval for the same reason as `createTeam`: the roles decide what the team's members can
29
+ * do. `roles` replaces the stored list, and the approval shows that whole list, so a role the model
30
+ * left out is visible as missing before anything is written.
31
+ */
32
+ declare class UpdateTeamToolImpl implements AiSdkToolDefinition.Interface<Input> {
33
+ readonly name = "updateTeam";
34
+ readonly title = "Update team";
35
+ 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.";
36
+ readonly inputSchema: z.ZodObject<{
37
+ teamId: z.ZodString;
38
+ name: z.ZodOptional<z.ZodString>;
39
+ description: z.ZodOptional<z.ZodString>;
40
+ roles: z.ZodOptional<z.ZodArray<z.ZodString>>;
41
+ }, z.core.$strip>;
42
+ readonly annotations: {
43
+ readOnlyHint: boolean;
44
+ idempotentHint: boolean;
45
+ };
46
+ readonly handler: typeof UpdateTeamToolHandlerImpl & {
47
+ __abstraction: import("@webiny/di").Abstraction<import("../../ai/abstractions").IAiSdkToolHandler<any>>;
48
+ };
49
+ }
50
+ export declare const UpdateTeamTool: typeof UpdateTeamToolImpl & {
51
+ __abstraction: import("@webiny/di").Abstraction<import("../../ai/abstractions").IAiSdkToolDefinition<any>>;
52
+ };
53
+ export {};
@@ -0,0 +1,56 @@
1
+ import { z } from "zod";
2
+ import { AiSdkToolDefinition, AiSdkToolHandler } from "../../ai/index.js";
3
+ import { UpdateTeam } from "../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/security/ai/UpdateTeamTool.js","sources":["../../../../src/features/security/ai/UpdateTeamTool.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { AiSdkToolDefinition } from \"~/features/ai/index.js\";\nimport { AiSdkToolHandler } from \"~/features/ai/index.js\";\nimport { UpdateTeam } from \"~/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":";;;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;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"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Team and role tools for AI callers.
3
+ *
4
+ * The list tools are read-only and run unattended. Creating, changing or deleting a team or a role is
5
+ * a write, so it pauses for the user to approve the exact arguments.
6
+ */
7
+ export declare const SecurityAiToolsFeature: {
8
+ name: string;
9
+ register(container: import("@webiny/di").Container): void;
10
+ };
@@ -0,0 +1,25 @@
1
+ import { createFeature } from "@webiny/feature/api";
2
+ import { ListTeamsTool } from "./ListTeamsTool.js";
3
+ import { CreateTeamTool } from "./CreateTeamTool.js";
4
+ import { UpdateTeamTool } from "./UpdateTeamTool.js";
5
+ import { DeleteTeamTool } from "./DeleteTeamTool.js";
6
+ import { ListRolesTool } from "./ListRolesTool.js";
7
+ import { CreateRoleTool } from "./CreateRoleTool.js";
8
+ import { UpdateRoleTool } from "./UpdateRoleTool.js";
9
+ import { DeleteRoleTool } from "./DeleteRoleTool.js";
10
+ const SecurityAiToolsFeature = createFeature({
11
+ name: "Security/AiTools",
12
+ register (container) {
13
+ container.register(ListTeamsTool);
14
+ container.register(CreateTeamTool);
15
+ container.register(UpdateTeamTool);
16
+ container.register(DeleteTeamTool);
17
+ container.register(ListRolesTool);
18
+ container.register(CreateRoleTool);
19
+ container.register(UpdateRoleTool);
20
+ container.register(DeleteRoleTool);
21
+ }
22
+ });
23
+ export { SecurityAiToolsFeature };
24
+
25
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/security/ai/feature.js","sources":["../../../../src/features/security/ai/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { ListTeamsTool } from \"./ListTeamsTool.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 * Team and role tools for AI callers.\n *\n * The list tools are read-only and run unattended. Creating, changing or deleting a team or a role is\n * a write, so it pauses for the user to approve the exact arguments.\n */\nexport const SecurityAiToolsFeature = createFeature({\n name: \"Security/AiTools\",\n register(container) {\n container.register(ListTeamsTool);\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":["SecurityAiToolsFeature","createFeature","container","ListTeamsTool","CreateTeamTool","UpdateTeamTool","DeleteTeamTool","ListRolesTool","CreateRoleTool","UpdateRoleTool","DeleteRoleTool"],"mappings":";;;;;;;;;AAgBO,MAAMA,yBAAyBC,cAAc;IAChD,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"}
@@ -0,0 +1,9 @@
1
+ export { SecurityAiToolsFeature } from "./feature.js";
2
+ export { ListTeamsTool } from "./ListTeamsTool.js";
3
+ export { CreateTeamTool } from "./CreateTeamTool.js";
4
+ export { UpdateTeamTool } from "./UpdateTeamTool.js";
5
+ export { DeleteTeamTool } from "./DeleteTeamTool.js";
6
+ export { ListRolesTool } from "./ListRolesTool.js";
7
+ export { CreateRoleTool } from "./CreateRoleTool.js";
8
+ export { UpdateRoleTool } from "./UpdateRoleTool.js";
9
+ export { DeleteRoleTool } from "./DeleteRoleTool.js";
@@ -0,0 +1,9 @@
1
+ export { SecurityAiToolsFeature } from "./feature.js";
2
+ export { ListTeamsTool } from "./ListTeamsTool.js";
3
+ export { CreateTeamTool } from "./CreateTeamTool.js";
4
+ export { UpdateTeamTool } from "./UpdateTeamTool.js";
5
+ export { DeleteTeamTool } from "./DeleteTeamTool.js";
6
+ export { ListRolesTool } from "./ListRolesTool.js";
7
+ export { CreateRoleTool } from "./CreateRoleTool.js";
8
+ export { UpdateRoleTool } from "./UpdateRoleTool.js";
9
+ export { DeleteRoleTool } from "./DeleteRoleTool.js";
@@ -1,7 +1,7 @@
1
1
  import { Authorizer } from "../authorization/Authorizer/abstractions.js";
2
2
  class ApiKeyAuthorizerImpl {
3
3
  async authorize(identity) {
4
- if (!identity || "api-key" !== identity.type) return null;
4
+ if ("api-key" !== identity.type) return null;
5
5
  const permissions = identity.permissions;
6
6
  return Array.isArray(permissions) ? permissions : [];
7
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"features/security/apiKeys/ApiKeyAuthorizer.js","sources":["../../../../src/features/security/apiKeys/ApiKeyAuthorizer.ts"],"sourcesContent":["import { Authorizer } from \"~/features/security/authorization/Authorizer/abstractions.js\";\nimport type { IAuthorizer } from \"~/features/security/authorization/Authorizer/abstractions.js\";\nimport type { Identity } from \"~/features/security/IdentityContext/Identity.js\";\nimport type { SecurityPermission } from \"~/types/security.js\";\n\nclass ApiKeyAuthorizerImpl implements IAuthorizer {\n async authorize(identity: Identity): Promise<SecurityPermission[] | null> {\n if (!identity || identity.type !== \"api-key\") {\n return null;\n }\n const permissions = (identity as any).permissions;\n return Array.isArray(permissions) ? (permissions as SecurityPermission[]) : [];\n }\n}\n\nexport const ApiKeyAuthorizer = Authorizer.createImplementation({\n implementation: ApiKeyAuthorizerImpl,\n dependencies: []\n});\n"],"names":["ApiKeyAuthorizerImpl","identity","permissions","Array","ApiKeyAuthorizer","Authorizer"],"mappings":";AAKA,MAAMA;IACF,MAAM,UAAUC,QAAkB,EAAwC;QACtE,IAAI,CAACA,YAAYA,AAAkB,cAAlBA,SAAS,IAAI,EAC1B,OAAO;QAEX,MAAMC,cAAeD,SAAiB,WAAW;QACjD,OAAOE,MAAM,OAAO,CAACD,eAAgBA,cAAuC,EAAE;IAClF;AACJ;AAEO,MAAME,mBAAmBC,WAAW,oBAAoB,CAAC;IAC5D,gBAAgBL;IAChB,cAAc,EAAE;AACpB"}
1
+ {"version":3,"file":"features/security/apiKeys/ApiKeyAuthorizer.js","sources":["../../../../src/features/security/apiKeys/ApiKeyAuthorizer.ts"],"sourcesContent":["import { Authorizer } from \"~/features/security/authorization/Authorizer/abstractions.js\";\nimport type { IAuthorizer } from \"~/features/security/authorization/Authorizer/abstractions.js\";\nimport type { Identity } from \"~/features/security/IdentityContext/Identity.js\";\nimport type { SecurityPermission } from \"~/types/security.js\";\n\nclass ApiKeyAuthorizerImpl implements IAuthorizer {\n async authorize(identity: Identity): Promise<SecurityPermission[] | null> {\n if (identity.type !== \"api-key\") {\n return null;\n }\n const permissions = (identity as any).permissions;\n return Array.isArray(permissions) ? (permissions as SecurityPermission[]) : [];\n }\n}\n\nexport const ApiKeyAuthorizer = Authorizer.createImplementation({\n implementation: ApiKeyAuthorizerImpl,\n dependencies: []\n});\n"],"names":["ApiKeyAuthorizerImpl","identity","permissions","Array","ApiKeyAuthorizer","Authorizer"],"mappings":";AAKA,MAAMA;IACF,MAAM,UAAUC,QAAkB,EAAwC;QACtE,IAAIA,AAAkB,cAAlBA,SAAS,IAAI,EACb,OAAO;QAEX,MAAMC,cAAeD,SAAiB,WAAW;QACjD,OAAOE,MAAM,OAAO,CAACD,eAAgBA,cAAuC,EAAE;IAClF;AACJ;AAEO,MAAME,mBAAmBC,WAAW,oBAAoB,CAAC;IAC5D,gBAAgBL;IAChB,cAAc,EAAE;AACpB"}
@@ -0,0 +1,11 @@
1
+ import { RoleAfterCreateEventHandler } from "../../../../features/security/roles/CreateRole/index.js";
2
+ import { NotifyRecordChangeUseCase } from "../../../../features/websockets/index.js";
3
+ declare class NotifyOnRoleCreatedHandlerImpl implements RoleAfterCreateEventHandler.Interface {
4
+ private notifyRecordChange;
5
+ constructor(notifyRecordChange: NotifyRecordChangeUseCase.Interface);
6
+ handle(event: RoleAfterCreateEventHandler.Event): Promise<void>;
7
+ }
8
+ export declare const NotifyOnRoleCreatedHandler: typeof NotifyOnRoleCreatedHandlerImpl & {
9
+ __abstraction: import("@webiny/di").Abstraction<import("../../../eventPublisher/abstractions.js").IEventHandler<import("~/features/security/roles/CreateRole/index.js").RoleAfterCreateEvent>>;
10
+ };
11
+ export {};
@@ -0,0 +1,24 @@
1
+ import { RoleAfterCreateEventHandler } from "../CreateRole/index.js";
2
+ import { NotifyRecordChangeUseCase } from "../../../websockets/index.js";
3
+ import { ROLE_RECORD_TYPE } from "./recordType.js";
4
+ class NotifyOnRoleCreatedHandlerImpl {
5
+ constructor(notifyRecordChange){
6
+ this.notifyRecordChange = notifyRecordChange;
7
+ }
8
+ async handle(event) {
9
+ await this.notifyRecordChange.execute({
10
+ type: ROLE_RECORD_TYPE,
11
+ id: event.payload.role.id,
12
+ change: "created"
13
+ });
14
+ }
15
+ }
16
+ const NotifyOnRoleCreatedHandler = RoleAfterCreateEventHandler.createImplementation({
17
+ implementation: NotifyOnRoleCreatedHandlerImpl,
18
+ dependencies: [
19
+ NotifyRecordChangeUseCase
20
+ ]
21
+ });
22
+ export { NotifyOnRoleCreatedHandler };
23
+
24
+ //# sourceMappingURL=NotifyOnRoleCreatedHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/security/roles/NotifyRoleChange/NotifyOnRoleCreatedHandler.js","sources":["../../../../../src/features/security/roles/NotifyRoleChange/NotifyOnRoleCreatedHandler.ts"],"sourcesContent":["import { RoleAfterCreateEventHandler } from \"~/features/security/roles/CreateRole/index.js\";\nimport { NotifyRecordChangeUseCase } from \"~/features/websockets/index.js\";\nimport { ROLE_RECORD_TYPE } from \"./recordType.js\";\n\nclass NotifyOnRoleCreatedHandlerImpl implements RoleAfterCreateEventHandler.Interface {\n constructor(private notifyRecordChange: NotifyRecordChangeUseCase.Interface) {}\n\n async handle(event: RoleAfterCreateEventHandler.Event): Promise<void> {\n await this.notifyRecordChange.execute({\n type: ROLE_RECORD_TYPE,\n id: event.payload.role.id,\n change: \"created\"\n });\n }\n}\n\nexport const NotifyOnRoleCreatedHandler = RoleAfterCreateEventHandler.createImplementation({\n implementation: NotifyOnRoleCreatedHandlerImpl,\n dependencies: [NotifyRecordChangeUseCase]\n});\n"],"names":["NotifyOnRoleCreatedHandlerImpl","notifyRecordChange","event","ROLE_RECORD_TYPE","NotifyOnRoleCreatedHandler","RoleAfterCreateEventHandler","NotifyRecordChangeUseCase"],"mappings":";;;AAIA,MAAMA;IACF,YAAoBC,kBAAuD,CAAE;aAAzDA,kBAAkB,GAAlBA;IAA0D;IAE9E,MAAM,OAAOC,KAAwC,EAAiB;QAClE,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC;YAClC,MAAMC;YACN,IAAID,MAAM,OAAO,CAAC,IAAI,CAAC,EAAE;YACzB,QAAQ;QACZ;IACJ;AACJ;AAEO,MAAME,6BAA6BC,4BAA4B,oBAAoB,CAAC;IACvF,gBAAgBL;IAChB,cAAc;QAACM;KAA0B;AAC7C"}
@@ -0,0 +1,11 @@
1
+ import { RoleAfterDeleteEventHandler } from "../../../../features/security/roles/DeleteRole/index.js";
2
+ import { NotifyRecordChangeUseCase } from "../../../../features/websockets/index.js";
3
+ declare class NotifyOnRoleDeletedHandlerImpl implements RoleAfterDeleteEventHandler.Interface {
4
+ private notifyRecordChange;
5
+ constructor(notifyRecordChange: NotifyRecordChangeUseCase.Interface);
6
+ handle(event: RoleAfterDeleteEventHandler.Event): Promise<void>;
7
+ }
8
+ export declare const NotifyOnRoleDeletedHandler: typeof NotifyOnRoleDeletedHandlerImpl & {
9
+ __abstraction: import("@webiny/di").Abstraction<import("../../../eventPublisher/abstractions.js").IEventHandler<import("~/features/security/roles/DeleteRole/index.js").RoleAfterDeleteEvent>>;
10
+ };
11
+ export {};
@@ -0,0 +1,24 @@
1
+ import { RoleAfterDeleteEventHandler } from "../DeleteRole/index.js";
2
+ import { NotifyRecordChangeUseCase } from "../../../websockets/index.js";
3
+ import { ROLE_RECORD_TYPE } from "./recordType.js";
4
+ class NotifyOnRoleDeletedHandlerImpl {
5
+ constructor(notifyRecordChange){
6
+ this.notifyRecordChange = notifyRecordChange;
7
+ }
8
+ async handle(event) {
9
+ await this.notifyRecordChange.execute({
10
+ type: ROLE_RECORD_TYPE,
11
+ id: event.payload.role.id,
12
+ change: "deleted"
13
+ });
14
+ }
15
+ }
16
+ const NotifyOnRoleDeletedHandler = RoleAfterDeleteEventHandler.createImplementation({
17
+ implementation: NotifyOnRoleDeletedHandlerImpl,
18
+ dependencies: [
19
+ NotifyRecordChangeUseCase
20
+ ]
21
+ });
22
+ export { NotifyOnRoleDeletedHandler };
23
+
24
+ //# sourceMappingURL=NotifyOnRoleDeletedHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/security/roles/NotifyRoleChange/NotifyOnRoleDeletedHandler.js","sources":["../../../../../src/features/security/roles/NotifyRoleChange/NotifyOnRoleDeletedHandler.ts"],"sourcesContent":["import { RoleAfterDeleteEventHandler } from \"~/features/security/roles/DeleteRole/index.js\";\nimport { NotifyRecordChangeUseCase } from \"~/features/websockets/index.js\";\nimport { ROLE_RECORD_TYPE } from \"./recordType.js\";\n\nclass NotifyOnRoleDeletedHandlerImpl implements RoleAfterDeleteEventHandler.Interface {\n constructor(private notifyRecordChange: NotifyRecordChangeUseCase.Interface) {}\n\n async handle(event: RoleAfterDeleteEventHandler.Event): Promise<void> {\n await this.notifyRecordChange.execute({\n type: ROLE_RECORD_TYPE,\n id: event.payload.role.id,\n change: \"deleted\"\n });\n }\n}\n\nexport const NotifyOnRoleDeletedHandler = RoleAfterDeleteEventHandler.createImplementation({\n implementation: NotifyOnRoleDeletedHandlerImpl,\n dependencies: [NotifyRecordChangeUseCase]\n});\n"],"names":["NotifyOnRoleDeletedHandlerImpl","notifyRecordChange","event","ROLE_RECORD_TYPE","NotifyOnRoleDeletedHandler","RoleAfterDeleteEventHandler","NotifyRecordChangeUseCase"],"mappings":";;;AAIA,MAAMA;IACF,YAAoBC,kBAAuD,CAAE;aAAzDA,kBAAkB,GAAlBA;IAA0D;IAE9E,MAAM,OAAOC,KAAwC,EAAiB;QAClE,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC;YAClC,MAAMC;YACN,IAAID,MAAM,OAAO,CAAC,IAAI,CAAC,EAAE;YACzB,QAAQ;QACZ;IACJ;AACJ;AAEO,MAAME,6BAA6BC,4BAA4B,oBAAoB,CAAC;IACvF,gBAAgBL;IAChB,cAAc;QAACM;KAA0B;AAC7C"}
@@ -0,0 +1,11 @@
1
+ import { RoleAfterUpdateEventHandler } from "../../../../features/security/roles/UpdateRole/index.js";
2
+ import { NotifyRecordChangeUseCase } from "../../../../features/websockets/index.js";
3
+ declare class NotifyOnRoleUpdatedHandlerImpl implements RoleAfterUpdateEventHandler.Interface {
4
+ private notifyRecordChange;
5
+ constructor(notifyRecordChange: NotifyRecordChangeUseCase.Interface);
6
+ handle(event: RoleAfterUpdateEventHandler.Event): Promise<void>;
7
+ }
8
+ export declare const NotifyOnRoleUpdatedHandler: typeof NotifyOnRoleUpdatedHandlerImpl & {
9
+ __abstraction: import("@webiny/di").Abstraction<import("../../../eventPublisher/abstractions.js").IEventHandler<import("~/features/security/roles/UpdateRole/index.js").RoleAfterUpdateEvent>>;
10
+ };
11
+ export {};
@@ -0,0 +1,24 @@
1
+ import { RoleAfterUpdateEventHandler } from "../UpdateRole/index.js";
2
+ import { NotifyRecordChangeUseCase } from "../../../websockets/index.js";
3
+ import { ROLE_RECORD_TYPE } from "./recordType.js";
4
+ class NotifyOnRoleUpdatedHandlerImpl {
5
+ constructor(notifyRecordChange){
6
+ this.notifyRecordChange = notifyRecordChange;
7
+ }
8
+ async handle(event) {
9
+ await this.notifyRecordChange.execute({
10
+ type: ROLE_RECORD_TYPE,
11
+ id: event.payload.updated.id,
12
+ change: "updated"
13
+ });
14
+ }
15
+ }
16
+ const NotifyOnRoleUpdatedHandler = RoleAfterUpdateEventHandler.createImplementation({
17
+ implementation: NotifyOnRoleUpdatedHandlerImpl,
18
+ dependencies: [
19
+ NotifyRecordChangeUseCase
20
+ ]
21
+ });
22
+ export { NotifyOnRoleUpdatedHandler };
23
+
24
+ //# sourceMappingURL=NotifyOnRoleUpdatedHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/security/roles/NotifyRoleChange/NotifyOnRoleUpdatedHandler.js","sources":["../../../../../src/features/security/roles/NotifyRoleChange/NotifyOnRoleUpdatedHandler.ts"],"sourcesContent":["import { RoleAfterUpdateEventHandler } from \"~/features/security/roles/UpdateRole/index.js\";\nimport { NotifyRecordChangeUseCase } from \"~/features/websockets/index.js\";\nimport { ROLE_RECORD_TYPE } from \"./recordType.js\";\n\nclass NotifyOnRoleUpdatedHandlerImpl implements RoleAfterUpdateEventHandler.Interface {\n constructor(private notifyRecordChange: NotifyRecordChangeUseCase.Interface) {}\n\n async handle(event: RoleAfterUpdateEventHandler.Event): Promise<void> {\n await this.notifyRecordChange.execute({\n type: ROLE_RECORD_TYPE,\n id: event.payload.updated.id,\n change: \"updated\"\n });\n }\n}\n\nexport const NotifyOnRoleUpdatedHandler = RoleAfterUpdateEventHandler.createImplementation({\n implementation: NotifyOnRoleUpdatedHandlerImpl,\n dependencies: [NotifyRecordChangeUseCase]\n});\n"],"names":["NotifyOnRoleUpdatedHandlerImpl","notifyRecordChange","event","ROLE_RECORD_TYPE","NotifyOnRoleUpdatedHandler","RoleAfterUpdateEventHandler","NotifyRecordChangeUseCase"],"mappings":";;;AAIA,MAAMA;IACF,YAAoBC,kBAAuD,CAAE;aAAzDA,kBAAkB,GAAlBA;IAA0D;IAE9E,MAAM,OAAOC,KAAwC,EAAiB;QAClE,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC;YAClC,MAAMC;YACN,IAAID,MAAM,OAAO,CAAC,OAAO,CAAC,EAAE;YAC5B,QAAQ;QACZ;IACJ;AACJ;AAEO,MAAME,6BAA6BC,4BAA4B,oBAAoB,CAAC;IACvF,gBAAgBL;IAChB,cAAc;QAACM;KAA0B;AAC7C"}
@@ -0,0 +1,5 @@
1
+ /** Tells the user's open admin tabs when a role is created, updated or deleted. */
2
+ export declare const NotifyRoleChangeFeature: {
3
+ name: string;
4
+ register(container: import("@webiny/di").Container): void;
5
+ };
@@ -0,0 +1,15 @@
1
+ import { createFeature } from "@webiny/feature/api";
2
+ import { NotifyOnRoleCreatedHandler } from "./NotifyOnRoleCreatedHandler.js";
3
+ import { NotifyOnRoleUpdatedHandler } from "./NotifyOnRoleUpdatedHandler.js";
4
+ import { NotifyOnRoleDeletedHandler } from "./NotifyOnRoleDeletedHandler.js";
5
+ const NotifyRoleChangeFeature = createFeature({
6
+ name: "NotifyRoleChange",
7
+ register (container) {
8
+ container.register(NotifyOnRoleCreatedHandler);
9
+ container.register(NotifyOnRoleUpdatedHandler);
10
+ container.register(NotifyOnRoleDeletedHandler);
11
+ }
12
+ });
13
+ export { NotifyRoleChangeFeature };
14
+
15
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/security/roles/NotifyRoleChange/feature.js","sources":["../../../../../src/features/security/roles/NotifyRoleChange/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { NotifyOnRoleCreatedHandler } from \"./NotifyOnRoleCreatedHandler.js\";\nimport { NotifyOnRoleUpdatedHandler } from \"./NotifyOnRoleUpdatedHandler.js\";\nimport { NotifyOnRoleDeletedHandler } from \"./NotifyOnRoleDeletedHandler.js\";\n\n/** Tells the user's open admin tabs when a role is created, updated or deleted. */\nexport const NotifyRoleChangeFeature = createFeature({\n name: \"NotifyRoleChange\",\n register(container) {\n container.register(NotifyOnRoleCreatedHandler);\n container.register(NotifyOnRoleUpdatedHandler);\n container.register(NotifyOnRoleDeletedHandler);\n }\n});\n"],"names":["NotifyRoleChangeFeature","createFeature","container","NotifyOnRoleCreatedHandler","NotifyOnRoleUpdatedHandler","NotifyOnRoleDeletedHandler"],"mappings":";;;;AAMO,MAAMA,0BAA0BC,cAAc;IACjD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;QACnBF,UAAU,QAAQ,CAACG;IACvB;AACJ"}
@@ -0,0 +1,2 @@
1
+ export { NotifyRoleChangeFeature } from "./feature.js";
2
+ export { ROLE_RECORD_TYPE } from "./recordType.js";
@@ -0,0 +1,2 @@
1
+ export { NotifyRoleChangeFeature } from "./feature.js";
2
+ export { ROLE_RECORD_TYPE } from "./recordType.js";
@@ -0,0 +1,5 @@
1
+ /**
2
+ * The `type` of the record-changed message sent when a role changes. The admin's
3
+ * `ApplyRoleChangeToCache` filters on the same string.
4
+ */
5
+ export declare const ROLE_RECORD_TYPE = "security.role";
@@ -0,0 +1,4 @@
1
+ const ROLE_RECORD_TYPE = "security.role";
2
+ export { ROLE_RECORD_TYPE };
3
+
4
+ //# sourceMappingURL=recordType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/security/roles/NotifyRoleChange/recordType.js","sources":["../../../../../src/features/security/roles/NotifyRoleChange/recordType.ts"],"sourcesContent":["/**\n * The `type` of the record-changed message sent when a role changes. The admin's\n * `ApplyRoleChangeToCache` filters on the same string.\n */\nexport const ROLE_RECORD_TYPE = \"security.role\";\n"],"names":["ROLE_RECORD_TYPE"],"mappings":"AAIO,MAAMA,mBAAmB"}
@@ -6,6 +6,7 @@ import { EventPublisher } from "../../../eventPublisher/index.js";
6
6
  import { updateRoleValidation } from "./schema.js";
7
7
  import { RoleAfterUpdateEvent, RoleBeforeUpdateEvent } from "./events.js";
8
8
  import { descriptionOnUpdate } from "../../shared/description.js";
9
+ import { definedOnly } from "../../shared/definedOnly.js";
9
10
  import { CannotUpdatePluginRolesError, NotAuthorizedError, RoleValidationError } from "../shared/errors.js";
10
11
  class UpdateRoleUseCaseImpl {
11
12
  constructor(repository, identityContext, eventPublisher){
@@ -26,7 +27,7 @@ class UpdateRoleUseCaseImpl {
26
27
  if (existingRole.plugin) return Result.fail(new CannotUpdatePluginRolesError());
27
28
  const { description, ...rest } = validation.data;
28
29
  const changes = {
29
- ...rest,
30
+ ...definedOnly(rest),
30
31
  ...descriptionOnUpdate(description)
31
32
  };
32
33
  const updatedRole = {
@@ -1 +1 @@
1
- {"version":3,"file":"features/security/roles/UpdateRole/UpdateRoleUseCase.js","sources":["../../../../../src/features/security/roles/UpdateRole/UpdateRoleUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { UpdateRoleUseCase as UseCase } from \"./abstractions.js\";\nimport { RolesRepository } from \"../shared/abstractions.js\";\nimport { IdentityContext } from \"../../IdentityContext/abstractions.js\";\nimport { EventPublisher } from \"~/features/eventPublisher/index.js\";\nimport { updateRoleValidation } from \"./schema.js\";\nimport { RoleBeforeUpdateEvent, RoleAfterUpdateEvent } from \"./events.js\";\nimport type { Role, UpdateRoleInput } from \"../shared/types.js\";\nimport { descriptionOnUpdate } from \"../../shared/description.js\";\nimport {\n NotAuthorizedError,\n CannotUpdatePluginRolesError,\n RoleValidationError\n} from \"../shared/errors.js\";\n\nclass UpdateRoleUseCaseImpl implements UseCase.Interface {\n private repository: RolesRepository.Interface;\n private identityContext: IdentityContext.Interface;\n private eventPublisher: EventPublisher.Interface;\n\n constructor(\n repository: RolesRepository.Interface,\n identityContext: IdentityContext.Interface,\n eventPublisher: EventPublisher.Interface\n ) {\n this.repository = repository;\n this.identityContext = identityContext;\n this.eventPublisher = eventPublisher;\n }\n\n async execute(id: string, input: UpdateRoleInput): Promise<Result<Role, UseCase.Error>> {\n const hasPermission = await this.identityContext.getPermission(\"security.role\");\n if (!hasPermission) {\n return Result.fail(new NotAuthorizedError());\n }\n\n const validation = updateRoleValidation.safeParse(input);\n if (!validation.success) {\n return Result.fail(new RoleValidationError(validation.error.issues[0].message));\n }\n\n const existingResult = await this.repository.get({ id });\n if (existingResult.isFail()) {\n return Result.fail(existingResult.error);\n }\n\n const existingRole = existingResult.value;\n\n // Check if role is created via plugin\n if (existingRole.plugin) {\n return Result.fail(new CannotUpdatePluginRolesError());\n }\n\n // `description` is pulled out of the spread because it is the one field that accepts null.\n // Normalising it here keeps null out of both the entity and the published events, whose\n // input type declares `description?: string`.\n const { description, ...rest } = validation.data;\n\n const changes: UpdateRoleInput = {\n ...rest,\n ...descriptionOnUpdate(description)\n };\n\n const updatedRole: Role = {\n ...existingRole,\n ...changes\n };\n\n await this.eventPublisher.publish(\n new RoleBeforeUpdateEvent({\n original: existingRole,\n updated: updatedRole,\n input: changes\n })\n );\n\n const result = await this.repository.update(updatedRole);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n await this.eventPublisher.publish(\n new RoleAfterUpdateEvent({\n original: existingRole,\n updated: updatedRole,\n input: changes\n })\n );\n\n return Result.ok(updatedRole);\n }\n}\n\nexport const UpdateRoleUseCase = UseCase.createImplementation({\n implementation: UpdateRoleUseCaseImpl,\n dependencies: [RolesRepository, IdentityContext, EventPublisher]\n});\n"],"names":["UpdateRoleUseCaseImpl","repository","identityContext","eventPublisher","id","input","hasPermission","Result","NotAuthorizedError","validation","updateRoleValidation","RoleValidationError","existingResult","existingRole","CannotUpdatePluginRolesError","description","rest","changes","descriptionOnUpdate","updatedRole","RoleBeforeUpdateEvent","result","RoleAfterUpdateEvent","UpdateRoleUseCase","UseCase","RolesRepository","IdentityContext","EventPublisher"],"mappings":";;;;;;;;;AAeA,MAAMA;IAKF,YACIC,UAAqC,EACrCC,eAA0C,EAC1CC,cAAwC,CAC1C;QACE,IAAI,CAAC,UAAU,GAAGF;QAClB,IAAI,CAAC,eAAe,GAAGC;QACvB,IAAI,CAAC,cAAc,GAAGC;IAC1B;IAEA,MAAM,QAAQC,EAAU,EAAEC,KAAsB,EAAwC;QACpF,MAAMC,gBAAgB,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC;QAC/D,IAAI,CAACA,eACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAMC,aAAaC,qBAAqB,SAAS,CAACL;QAClD,IAAI,CAACI,WAAW,OAAO,EACnB,OAAOF,OAAO,IAAI,CAAC,IAAII,oBAAoBF,WAAW,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO;QAGjF,MAAMG,iBAAiB,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;YAAER;QAAG;QACtD,IAAIQ,eAAe,MAAM,IACrB,OAAOL,OAAO,IAAI,CAACK,eAAe,KAAK;QAG3C,MAAMC,eAAeD,eAAe,KAAK;QAGzC,IAAIC,aAAa,MAAM,EACnB,OAAON,OAAO,IAAI,CAAC,IAAIO;QAM3B,MAAM,EAAEC,WAAW,EAAE,GAAGC,MAAM,GAAGP,WAAW,IAAI;QAEhD,MAAMQ,UAA2B;YAC7B,GAAGD,IAAI;YACP,GAAGE,oBAAoBH,YAAY;QACvC;QAEA,MAAMI,cAAoB;YACtB,GAAGN,YAAY;YACf,GAAGI,OAAO;QACd;QAEA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIG,sBAAsB;YACtB,UAAUP;YACV,SAASM;YACT,OAAOF;QACX;QAGJ,MAAMI,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAACF;QAE5C,IAAIE,OAAO,MAAM,IACb,OAAOd,OAAO,IAAI,CAACc,OAAO,KAAK;QAGnC,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIC,qBAAqB;YACrB,UAAUT;YACV,SAASM;YACT,OAAOF;QACX;QAGJ,OAAOV,OAAO,EAAE,CAACY;IACrB;AACJ;AAEO,MAAMI,sCAAoBC,kBAAAA,oBAA4B,CAAC;IAC1D,gBAAgBxB;IAChB,cAAc;QAACyB;QAAiBC;QAAiBC;KAAe;AACpE"}
1
+ {"version":3,"file":"features/security/roles/UpdateRole/UpdateRoleUseCase.js","sources":["../../../../../src/features/security/roles/UpdateRole/UpdateRoleUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { UpdateRoleUseCase as UseCase } from \"./abstractions.js\";\nimport { RolesRepository } from \"../shared/abstractions.js\";\nimport { IdentityContext } from \"../../IdentityContext/abstractions.js\";\nimport { EventPublisher } from \"~/features/eventPublisher/index.js\";\nimport { updateRoleValidation } from \"./schema.js\";\nimport { RoleBeforeUpdateEvent, RoleAfterUpdateEvent } from \"./events.js\";\nimport type { Role, UpdateRoleInput } from \"../shared/types.js\";\nimport { descriptionOnUpdate } from \"../../shared/description.js\";\nimport { definedOnly } from \"../../shared/definedOnly.js\";\nimport {\n NotAuthorizedError,\n CannotUpdatePluginRolesError,\n RoleValidationError\n} from \"../shared/errors.js\";\n\nclass UpdateRoleUseCaseImpl implements UseCase.Interface {\n private repository: RolesRepository.Interface;\n private identityContext: IdentityContext.Interface;\n private eventPublisher: EventPublisher.Interface;\n\n constructor(\n repository: RolesRepository.Interface,\n identityContext: IdentityContext.Interface,\n eventPublisher: EventPublisher.Interface\n ) {\n this.repository = repository;\n this.identityContext = identityContext;\n this.eventPublisher = eventPublisher;\n }\n\n async execute(id: string, input: UpdateRoleInput): Promise<Result<Role, UseCase.Error>> {\n const hasPermission = await this.identityContext.getPermission(\"security.role\");\n if (!hasPermission) {\n return Result.fail(new NotAuthorizedError());\n }\n\n const validation = updateRoleValidation.safeParse(input);\n if (!validation.success) {\n return Result.fail(new RoleValidationError(validation.error.issues[0].message));\n }\n\n const existingResult = await this.repository.get({ id });\n if (existingResult.isFail()) {\n return Result.fail(existingResult.error);\n }\n\n const existingRole = existingResult.value;\n\n // Check if role is created via plugin\n if (existingRole.plugin) {\n return Result.fail(new CannotUpdatePluginRolesError());\n }\n\n // `description` is pulled out of the spread because it is the one field that accepts null.\n // Normalising it here keeps null out of both the entity and the published events, whose\n // input type declares `description?: string`.\n const { description, ...rest } = validation.data;\n\n const changes: UpdateRoleInput = {\n ...definedOnly(rest),\n ...descriptionOnUpdate(description)\n };\n\n const updatedRole: Role = {\n ...existingRole,\n ...changes\n };\n\n await this.eventPublisher.publish(\n new RoleBeforeUpdateEvent({\n original: existingRole,\n updated: updatedRole,\n input: changes\n })\n );\n\n const result = await this.repository.update(updatedRole);\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n await this.eventPublisher.publish(\n new RoleAfterUpdateEvent({\n original: existingRole,\n updated: updatedRole,\n input: changes\n })\n );\n\n return Result.ok(updatedRole);\n }\n}\n\nexport const UpdateRoleUseCase = UseCase.createImplementation({\n implementation: UpdateRoleUseCaseImpl,\n dependencies: [RolesRepository, IdentityContext, EventPublisher]\n});\n"],"names":["UpdateRoleUseCaseImpl","repository","identityContext","eventPublisher","id","input","hasPermission","Result","NotAuthorizedError","validation","updateRoleValidation","RoleValidationError","existingResult","existingRole","CannotUpdatePluginRolesError","description","rest","changes","definedOnly","descriptionOnUpdate","updatedRole","RoleBeforeUpdateEvent","result","RoleAfterUpdateEvent","UpdateRoleUseCase","UseCase","RolesRepository","IdentityContext","EventPublisher"],"mappings":";;;;;;;;;;AAgBA,MAAMA;IAKF,YACIC,UAAqC,EACrCC,eAA0C,EAC1CC,cAAwC,CAC1C;QACE,IAAI,CAAC,UAAU,GAAGF;QAClB,IAAI,CAAC,eAAe,GAAGC;QACvB,IAAI,CAAC,cAAc,GAAGC;IAC1B;IAEA,MAAM,QAAQC,EAAU,EAAEC,KAAsB,EAAwC;QACpF,MAAMC,gBAAgB,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC;QAC/D,IAAI,CAACA,eACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAMC,aAAaC,qBAAqB,SAAS,CAACL;QAClD,IAAI,CAACI,WAAW,OAAO,EACnB,OAAOF,OAAO,IAAI,CAAC,IAAII,oBAAoBF,WAAW,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO;QAGjF,MAAMG,iBAAiB,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;YAAER;QAAG;QACtD,IAAIQ,eAAe,MAAM,IACrB,OAAOL,OAAO,IAAI,CAACK,eAAe,KAAK;QAG3C,MAAMC,eAAeD,eAAe,KAAK;QAGzC,IAAIC,aAAa,MAAM,EACnB,OAAON,OAAO,IAAI,CAAC,IAAIO;QAM3B,MAAM,EAAEC,WAAW,EAAE,GAAGC,MAAM,GAAGP,WAAW,IAAI;QAEhD,MAAMQ,UAA2B;YAC7B,GAAGC,YAAYF,KAAK;YACpB,GAAGG,oBAAoBJ,YAAY;QACvC;QAEA,MAAMK,cAAoB;YACtB,GAAGP,YAAY;YACf,GAAGI,OAAO;QACd;QAEA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAII,sBAAsB;YACtB,UAAUR;YACV,SAASO;YACT,OAAOH;QACX;QAGJ,MAAMK,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAACF;QAE5C,IAAIE,OAAO,MAAM,IACb,OAAOf,OAAO,IAAI,CAACe,OAAO,KAAK;QAGnC,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIC,qBAAqB;YACrB,UAAUV;YACV,SAASO;YACT,OAAOH;QACX;QAGJ,OAAOV,OAAO,EAAE,CAACa;IACrB;AACJ;AAEO,MAAMI,sCAAoBC,kBAAAA,oBAA4B,CAAC;IAC1D,gBAAgBzB;IAChB,cAAc;QAAC0B;QAAiBC;QAAiBC;KAAe;AACpE"}