@webiny/api-core 6.6.0-alpha.11 → 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 (134) hide show
  1. package/ApiCoreFeature.js +2 -1
  2. package/ApiCoreFeature.js.map +1 -1
  3. package/features/ai/AiSdkTools.d.ts +1 -1
  4. package/features/ai/AiSdkTools.js +3 -2
  5. package/features/ai/AiSdkTools.js.map +1 -1
  6. package/features/ai/abstractions.d.ts +9 -1
  7. package/features/ai/abstractions.js.map +1 -1
  8. package/features/ai/index.d.ts +1 -0
  9. package/features/ai/index.js +1 -0
  10. package/features/ai/isReadOnlyTool.d.ts +9 -0
  11. package/features/ai/isReadOnlyTool.js +4 -0
  12. package/features/ai/isReadOnlyTool.js.map +1 -0
  13. package/features/security/CanAccessCurrentTenant/CanAccessCurrentTenantUseCase.d.ts +13 -0
  14. package/features/security/CanAccessCurrentTenant/CanAccessCurrentTenantUseCase.js +25 -0
  15. package/features/security/CanAccessCurrentTenant/CanAccessCurrentTenantUseCase.js.map +1 -0
  16. package/features/security/CanAccessCurrentTenant/abstractions.d.ts +12 -0
  17. package/features/security/CanAccessCurrentTenant/abstractions.js +5 -0
  18. package/features/security/CanAccessCurrentTenant/abstractions.js.map +1 -0
  19. package/features/security/CanAccessCurrentTenant/feature.d.ts +4 -0
  20. package/features/security/CanAccessCurrentTenant/feature.js +11 -0
  21. package/features/security/CanAccessCurrentTenant/feature.js.map +1 -0
  22. package/features/security/CanAccessCurrentTenant/index.d.ts +2 -0
  23. package/features/security/CanAccessCurrentTenant/index.js +2 -0
  24. package/features/security/SecurityFeature.js +4 -0
  25. package/features/security/SecurityFeature.js.map +1 -1
  26. package/features/security/ai/CreateRoleTool.d.ts +54 -0
  27. package/features/security/ai/CreateRoleTool.js +71 -0
  28. package/features/security/ai/CreateRoleTool.js.map +1 -0
  29. package/features/security/ai/CreateTeamTool.d.ts +49 -0
  30. package/features/security/ai/CreateTeamTool.js +56 -0
  31. package/features/security/ai/CreateTeamTool.js.map +1 -0
  32. package/features/security/ai/DeleteRoleTool.d.ts +52 -0
  33. package/features/security/ai/DeleteRoleTool.js +79 -0
  34. package/features/security/ai/DeleteRoleTool.js.map +1 -0
  35. package/features/security/ai/DeleteTeamTool.d.ts +47 -0
  36. package/features/security/ai/DeleteTeamTool.js +56 -0
  37. package/features/security/ai/DeleteTeamTool.js.map +1 -0
  38. package/features/security/ai/ListRolesTool.d.ts +40 -0
  39. package/features/security/ai/ListRolesTool.js +48 -0
  40. package/features/security/ai/ListRolesTool.js.map +1 -0
  41. package/features/security/ai/ListTeamsTool.d.ts +42 -0
  42. package/features/security/ai/ListTeamsTool.js +49 -0
  43. package/features/security/ai/ListTeamsTool.js.map +1 -0
  44. package/features/security/ai/UpdateRoleTool.d.ts +46 -0
  45. package/features/security/ai/UpdateRoleTool.js +53 -0
  46. package/features/security/ai/UpdateRoleTool.js.map +1 -0
  47. package/features/security/ai/UpdateTeamTool.d.ts +53 -0
  48. package/features/security/ai/UpdateTeamTool.js +56 -0
  49. package/features/security/ai/UpdateTeamTool.js.map +1 -0
  50. package/features/security/ai/feature.d.ts +10 -0
  51. package/features/security/ai/feature.js +25 -0
  52. package/features/security/ai/feature.js.map +1 -0
  53. package/features/security/ai/index.d.ts +9 -0
  54. package/features/security/ai/index.js +9 -0
  55. package/features/security/apiKeys/ApiKeyAuthorizer.js +1 -1
  56. package/features/security/apiKeys/ApiKeyAuthorizer.js.map +1 -1
  57. package/features/security/roles/NotifyRoleChange/NotifyOnRoleCreatedHandler.d.ts +3 -3
  58. package/features/security/roles/NotifyRoleChange/NotifyOnRoleCreatedHandler.js +7 -5
  59. package/features/security/roles/NotifyRoleChange/NotifyOnRoleCreatedHandler.js.map +1 -1
  60. package/features/security/roles/NotifyRoleChange/NotifyOnRoleDeletedHandler.d.ts +3 -3
  61. package/features/security/roles/NotifyRoleChange/NotifyOnRoleDeletedHandler.js +7 -5
  62. package/features/security/roles/NotifyRoleChange/NotifyOnRoleDeletedHandler.js.map +1 -1
  63. package/features/security/roles/NotifyRoleChange/NotifyOnRoleUpdatedHandler.d.ts +3 -3
  64. package/features/security/roles/NotifyRoleChange/NotifyOnRoleUpdatedHandler.js +7 -5
  65. package/features/security/roles/NotifyRoleChange/NotifyOnRoleUpdatedHandler.js.map +1 -1
  66. package/features/security/roles/NotifyRoleChange/feature.js +0 -2
  67. package/features/security/roles/NotifyRoleChange/feature.js.map +1 -1
  68. package/features/security/roles/NotifyRoleChange/index.d.ts +1 -1
  69. package/features/security/roles/NotifyRoleChange/index.js +1 -1
  70. package/features/security/roles/NotifyRoleChange/recordType.d.ts +5 -0
  71. package/features/security/roles/NotifyRoleChange/recordType.js +4 -0
  72. package/features/security/roles/NotifyRoleChange/recordType.js.map +1 -0
  73. package/features/security/teams/NotifyTeamChange/NotifyOnTeamChangeHandlers.d.ts +7 -7
  74. package/features/security/teams/NotifyTeamChange/NotifyOnTeamChangeHandlers.js +17 -13
  75. package/features/security/teams/NotifyTeamChange/NotifyOnTeamChangeHandlers.js.map +1 -1
  76. package/features/security/teams/NotifyTeamChange/feature.js +0 -2
  77. package/features/security/teams/NotifyTeamChange/feature.js.map +1 -1
  78. package/features/security/teams/NotifyTeamChange/index.d.ts +1 -1
  79. package/features/security/teams/NotifyTeamChange/index.js +1 -1
  80. package/features/security/teams/NotifyTeamChange/recordType.d.ts +5 -0
  81. package/features/security/teams/NotifyTeamChange/recordType.js +4 -0
  82. package/features/security/teams/NotifyTeamChange/recordType.js.map +1 -0
  83. package/features/users/AdminUsersFeature.js +4 -0
  84. package/features/users/AdminUsersFeature.js.map +1 -1
  85. package/features/users/CreateUser/CreateUserUseCase.js +1 -1
  86. package/features/users/CreateUser/CreateUserUseCase.js.map +1 -1
  87. package/features/users/NotifyUserChange/NotifyOnUserChangeHandlers.d.ts +29 -0
  88. package/features/users/NotifyUserChange/NotifyOnUserChangeHandlers.js +62 -0
  89. package/features/users/NotifyUserChange/NotifyOnUserChangeHandlers.js.map +1 -0
  90. package/features/users/NotifyUserChange/feature.d.ts +5 -0
  91. package/features/users/NotifyUserChange/feature.js +13 -0
  92. package/features/users/NotifyUserChange/feature.js.map +1 -0
  93. package/features/users/NotifyUserChange/index.d.ts +2 -0
  94. package/features/users/NotifyUserChange/index.js +2 -0
  95. package/features/users/NotifyUserChange/recordType.d.ts +5 -0
  96. package/features/users/NotifyUserChange/recordType.js +4 -0
  97. package/features/users/NotifyUserChange/recordType.js.map +1 -0
  98. package/features/users/ai/ListUsersTool.d.ts +39 -0
  99. package/features/users/ai/ListUsersTool.js +46 -0
  100. package/features/users/ai/ListUsersTool.js.map +1 -0
  101. package/features/users/ai/UpdateUserAccessTool.d.ts +59 -0
  102. package/features/users/ai/UpdateUserAccessTool.js +101 -0
  103. package/features/users/ai/UpdateUserAccessTool.js.map +1 -0
  104. package/features/users/ai/feature.d.ts +11 -0
  105. package/features/users/ai/feature.js +13 -0
  106. package/features/users/ai/feature.js.map +1 -0
  107. package/features/users/ai/index.d.ts +3 -0
  108. package/features/users/ai/index.js +3 -0
  109. package/features/websockets/NotifyRecordChange/NotifyRecordChangeUseCase.d.ts +12 -0
  110. package/features/websockets/NotifyRecordChange/NotifyRecordChangeUseCase.js +38 -0
  111. package/features/websockets/NotifyRecordChange/NotifyRecordChangeUseCase.js.map +1 -0
  112. package/features/websockets/NotifyRecordChange/abstractions.d.ts +39 -0
  113. package/features/websockets/NotifyRecordChange/abstractions.js +6 -0
  114. package/features/websockets/NotifyRecordChange/abstractions.js.map +1 -0
  115. package/features/websockets/NotifyRecordChange/feature.d.ts +5 -0
  116. package/features/websockets/NotifyRecordChange/feature.js +11 -0
  117. package/features/websockets/NotifyRecordChange/feature.js.map +1 -0
  118. package/features/websockets/NotifyRecordChange/index.d.ts +2 -0
  119. package/features/websockets/NotifyRecordChange/index.js +2 -0
  120. package/features/websockets/index.d.ts +1 -0
  121. package/features/websockets/index.js +1 -0
  122. package/package.json +11 -11
  123. package/features/security/roles/NotifyRoleChange/NotifyRoleChangeUseCase.d.ts +0 -11
  124. package/features/security/roles/NotifyRoleChange/NotifyRoleChangeUseCase.js +0 -40
  125. package/features/security/roles/NotifyRoleChange/NotifyRoleChangeUseCase.js.map +0 -1
  126. package/features/security/roles/NotifyRoleChange/abstractions.d.ts +0 -21
  127. package/features/security/roles/NotifyRoleChange/abstractions.js +0 -8
  128. package/features/security/roles/NotifyRoleChange/abstractions.js.map +0 -1
  129. package/features/security/teams/NotifyTeamChange/NotifyTeamChangeUseCase.d.ts +0 -11
  130. package/features/security/teams/NotifyTeamChange/NotifyTeamChangeUseCase.js +0 -40
  131. package/features/security/teams/NotifyTeamChange/NotifyTeamChangeUseCase.js.map +0 -1
  132. package/features/security/teams/NotifyTeamChange/abstractions.d.ts +0 -21
  133. package/features/security/teams/NotifyTeamChange/abstractions.js +0 -8
  134. package/features/security/teams/NotifyTeamChange/abstractions.js.map +0 -1
@@ -9,6 +9,8 @@ import { DeleteUserFeature } from "./DeleteUser/feature.js";
9
9
  import { ListUserTeamsFeature } from "./ListUserTeams/feature.js";
10
10
  import { AdminUsersStorageOperations } from "./shared/storageAbstractions.js";
11
11
  import { ExternalIdpUserSyncFeature } from "./ExternalIdpUserSync/index.js";
12
+ import { NotifyUserChangeFeature } from "./NotifyUserChange/index.js";
13
+ import { UsersAiToolsFeature } from "./ai/feature.js";
12
14
  const AdminUsersFeature = createFeature({
13
15
  name: "AdminUsers",
14
16
  register (container, storageOperations) {
@@ -21,6 +23,8 @@ const AdminUsersFeature = createFeature({
21
23
  UpdateUserFeature.register(container);
22
24
  DeleteUserFeature.register(container);
23
25
  ExternalIdpUserSyncFeature.register(container);
26
+ NotifyUserChangeFeature.register(container);
27
+ UsersAiToolsFeature.register(container);
24
28
  container.registerInstance(AdminUsersStorageOperations, storageOperations);
25
29
  }
26
30
  });
@@ -1 +1 @@
1
- {"version":3,"file":"features/users/AdminUsersFeature.js","sources":["../../../src/features/users/AdminUsersFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { AdminUsersRepository } from \"./shared/AdminUsersRepository.js\";\nimport { GetUserFeature } from \"./GetUser/feature.js\";\nimport { GetIdentityProfileFeature } from \"./GetIdentityProfile/feature.js\";\nimport { ListUsersFeature } from \"./ListUsers/feature.js\";\nimport { CreateUserFeature } from \"./CreateUser/feature.js\";\nimport { UpdateUserFeature } from \"./UpdateUser/feature.js\";\nimport { DeleteUserFeature } from \"./DeleteUser/feature.js\";\nimport { ListUserTeamsFeature } from \"./ListUserTeams/feature.js\";\nimport { AdminUsersStorageOperations } from \"./shared/storageAbstractions.js\";\nimport { ExternalIdpUserSyncFeature } from \"./ExternalIdpUserSync/index.js\";\n\nexport const AdminUsersFeature = createFeature<AdminUsersStorageOperations.Interface>({\n name: \"AdminUsers\",\n register(container, storageOperations) {\n // Register repository in singleton scope\n container.register(AdminUsersRepository).inSingletonScope();\n\n // Register all use cases\n GetUserFeature.register(container);\n GetIdentityProfileFeature.register(container);\n ListUsersFeature.register(container);\n ListUserTeamsFeature.register(container);\n CreateUserFeature.register(container);\n UpdateUserFeature.register(container);\n DeleteUserFeature.register(container);\n ExternalIdpUserSyncFeature.register(container);\n\n // Legacy storage ops\n container.registerInstance(AdminUsersStorageOperations, storageOperations);\n }\n});\n"],"names":["AdminUsersFeature","createFeature","container","storageOperations","AdminUsersRepository","GetUserFeature","GetIdentityProfileFeature","ListUsersFeature","ListUserTeamsFeature","CreateUserFeature","UpdateUserFeature","DeleteUserFeature","ExternalIdpUserSyncFeature","AdminUsersStorageOperations"],"mappings":";;;;;;;;;;;AAYO,MAAMA,oBAAoBC,cAAqD;IAClF,MAAM;IACN,UAASC,SAAS,EAAEC,iBAAiB;QAEjCD,UAAU,QAAQ,CAACE,sBAAsB,gBAAgB;QAGzDC,eAAe,QAAQ,CAACH;QACxBI,0BAA0B,QAAQ,CAACJ;QACnCK,iBAAiB,QAAQ,CAACL;QAC1BM,qBAAqB,QAAQ,CAACN;QAC9BO,kBAAkB,QAAQ,CAACP;QAC3BQ,kBAAkB,QAAQ,CAACR;QAC3BS,kBAAkB,QAAQ,CAACT;QAC3BU,2BAA2B,QAAQ,CAACV;QAGpCA,UAAU,gBAAgB,CAACW,6BAA6BV;IAC5D;AACJ"}
1
+ {"version":3,"file":"features/users/AdminUsersFeature.js","sources":["../../../src/features/users/AdminUsersFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { AdminUsersRepository } from \"./shared/AdminUsersRepository.js\";\nimport { GetUserFeature } from \"./GetUser/feature.js\";\nimport { GetIdentityProfileFeature } from \"./GetIdentityProfile/feature.js\";\nimport { ListUsersFeature } from \"./ListUsers/feature.js\";\nimport { CreateUserFeature } from \"./CreateUser/feature.js\";\nimport { UpdateUserFeature } from \"./UpdateUser/feature.js\";\nimport { DeleteUserFeature } from \"./DeleteUser/feature.js\";\nimport { ListUserTeamsFeature } from \"./ListUserTeams/feature.js\";\nimport { AdminUsersStorageOperations } from \"./shared/storageAbstractions.js\";\nimport { ExternalIdpUserSyncFeature } from \"./ExternalIdpUserSync/index.js\";\nimport { NotifyUserChangeFeature } from \"./NotifyUserChange/index.js\";\nimport { UsersAiToolsFeature } from \"./ai/feature.js\";\n\nexport const AdminUsersFeature = createFeature<AdminUsersStorageOperations.Interface>({\n name: \"AdminUsers\",\n register(container, storageOperations) {\n // Register repository in singleton scope\n container.register(AdminUsersRepository).inSingletonScope();\n\n // Register all use cases\n GetUserFeature.register(container);\n GetIdentityProfileFeature.register(container);\n ListUsersFeature.register(container);\n ListUserTeamsFeature.register(container);\n CreateUserFeature.register(container);\n UpdateUserFeature.register(container);\n DeleteUserFeature.register(container);\n ExternalIdpUserSyncFeature.register(container);\n NotifyUserChangeFeature.register(container);\n UsersAiToolsFeature.register(container);\n\n // Legacy storage ops\n container.registerInstance(AdminUsersStorageOperations, storageOperations);\n }\n});\n"],"names":["AdminUsersFeature","createFeature","container","storageOperations","AdminUsersRepository","GetUserFeature","GetIdentityProfileFeature","ListUsersFeature","ListUserTeamsFeature","CreateUserFeature","UpdateUserFeature","DeleteUserFeature","ExternalIdpUserSyncFeature","NotifyUserChangeFeature","UsersAiToolsFeature","AdminUsersStorageOperations"],"mappings":";;;;;;;;;;;;;AAcO,MAAMA,oBAAoBC,cAAqD;IAClF,MAAM;IACN,UAASC,SAAS,EAAEC,iBAAiB;QAEjCD,UAAU,QAAQ,CAACE,sBAAsB,gBAAgB;QAGzDC,eAAe,QAAQ,CAACH;QACxBI,0BAA0B,QAAQ,CAACJ;QACnCK,iBAAiB,QAAQ,CAACL;QAC1BM,qBAAqB,QAAQ,CAACN;QAC9BO,kBAAkB,QAAQ,CAACP;QAC3BQ,kBAAkB,QAAQ,CAACR;QAC3BS,kBAAkB,QAAQ,CAACT;QAC3BU,2BAA2B,QAAQ,CAACV;QACpCW,wBAAwB,QAAQ,CAACX;QACjCY,oBAAoB,QAAQ,CAACZ;QAG7BA,UAAU,gBAAgB,CAACa,6BAA6BZ;IAC5D;AACJ"}
@@ -31,7 +31,7 @@ class CreateUserUseCaseImpl {
31
31
  const tenant = this.tenantContext.getTenant().id;
32
32
  const identity = this.identityContext.getIdentity();
33
33
  let createdBy = null;
34
- if (identity) createdBy = {
34
+ if (!identity.isAnonymous()) createdBy = {
35
35
  id: identity.id,
36
36
  displayName: identity.displayName,
37
37
  type: identity.type
@@ -1 +1 @@
1
- {"version":3,"file":"features/users/CreateUser/CreateUserUseCase.js","sources":["../../../../src/features/users/CreateUser/CreateUserUseCase.ts"],"sourcesContent":["import { mdbid } from \"@webiny/utils\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport { TenantContext } from \"~/features/tenancy/TenantContext/index.js\";\nimport { IdentityContext } from \"~/features/security/IdentityContext/index.js\";\nimport { EventPublisher } from \"~/features/eventPublisher/index.js\";\nimport { CreateUserUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { AdminUsersRepository } from \"~/features/users/shared/abstractions.js\";\nimport { createUserValidation } from \"./schema.js\";\nimport {\n NotAuthorizedError,\n EmailTakenError,\n UserValidationError\n} from \"~/features/users/shared/errors.js\";\nimport { UserBeforeCreateEvent, UserAfterCreateEvent } from \"./events.js\";\nimport type { AdminUser } from \"~/features/users/shared/types.js\";\nimport type { CreateUserInput } from \"~/features/users/shared/types.js\";\nimport type { CreatedBy } from \"~/types/users.js\";\n\nclass CreateUserUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private tenantContext: TenantContext.Interface,\n private identityContext: IdentityContext.Interface,\n private eventPublisher: EventPublisher.Interface,\n private repository: AdminUsersRepository.Interface\n ) {}\n\n async execute(input: CreateUserInput): Promise<Result<AdminUser, UseCaseAbstraction.Error>> {\n // 1. Check permission\n const permission = await this.identityContext.getPermission(\"adminUsers.user\");\n if (!permission) {\n return Result.fail(new NotAuthorizedError());\n }\n\n // 2. Validate input\n const validation = createUserValidation.safeParse(input);\n if (!validation.success) {\n return Result.fail(new UserValidationError(validation.error.issues[0].message));\n }\n\n const data = validation.data;\n\n // 3. Check email uniqueness\n const existingUserResult = await this.repository.get({ email: data.email });\n if (existingUserResult.isOk()) {\n // This means the email is taken!\n return Result.fail(new EmailTakenError(data.email));\n }\n\n if (existingUserResult.error.code !== \"AdminUser/NotFound\") {\n return Result.fail(existingUserResult.error);\n }\n\n // 4. Generate ID if not provided\n const id = data.id || mdbid();\n\n // 5. Generate display name\n const displayName = this.getDisplayName(data);\n\n // 6. Get tenant and identity\n const tenant = this.tenantContext.getTenant().id;\n const identity = this.identityContext.getIdentity();\n\n let createdBy: CreatedBy | null = null;\n if (identity) {\n createdBy = {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n };\n }\n\n // 7. Create user entity\n const user: AdminUser = {\n ...data,\n id,\n email: data.email,\n displayName,\n createdOn: new Date().toISOString(),\n createdBy,\n tenant\n };\n\n // 8. Publish before event\n await this.eventPublisher.publish(new UserBeforeCreateEvent({ user, input: data }));\n\n // 10. Create user via repository\n const result = await this.repository.create(user);\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n // 11. Publish after event\n await this.eventPublisher.publish(\n new UserAfterCreateEvent({ user: result.value, input: data })\n );\n\n return Result.ok(result.value);\n }\n\n private getDisplayName(data: CreateUserInput): string {\n // If display name is not set, try to get it from the first name and last name.\n // If first name and last name are not set, use the e-mail address.\n if (data.displayName) {\n return data.displayName;\n }\n\n if (data.firstName || data.lastName) {\n return `${data.firstName || \"\"} ${data.lastName || \"\"}`.trim();\n }\n\n if (data.email) {\n return data.email;\n }\n\n return \"Missing display name\";\n }\n}\n\nexport const CreateUserUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: CreateUserUseCaseImpl,\n dependencies: [TenantContext, IdentityContext, EventPublisher, AdminUsersRepository]\n});\n"],"names":["CreateUserUseCaseImpl","tenantContext","identityContext","eventPublisher","repository","input","permission","Result","NotAuthorizedError","validation","createUserValidation","UserValidationError","data","existingUserResult","EmailTakenError","id","mdbid","displayName","tenant","identity","createdBy","user","Date","UserBeforeCreateEvent","result","UserAfterCreateEvent","CreateUserUseCase","createImplementation","UseCaseAbstraction","TenantContext","IdentityContext","EventPublisher","AdminUsersRepository"],"mappings":";;;;;;;;;;AAmBA,MAAMA;IACF,YACYC,aAAsC,EACtCC,eAA0C,EAC1CC,cAAwC,EACxCC,UAA0C,CACpD;aAJUH,aAAa,GAAbA;aACAC,eAAe,GAAfA;aACAC,cAAc,GAAdA;aACAC,UAAU,GAAVA;IACT;IAEH,MAAM,QAAQC,KAAsB,EAAwD;QAExF,MAAMC,aAAa,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC;QAC5D,IAAI,CAACA,YACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAI3B,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,OAAOH,WAAW,IAAI;QAG5B,MAAMI,qBAAqB,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,OAAOD,KAAK,KAAK;QAAC;QACzE,IAAIC,mBAAmB,IAAI,IAEvB,OAAON,OAAO,IAAI,CAAC,IAAIO,gBAAgBF,KAAK,KAAK;QAGrD,IAAIC,AAAkC,yBAAlCA,mBAAmB,KAAK,CAAC,IAAI,EAC7B,OAAON,OAAO,IAAI,CAACM,mBAAmB,KAAK;QAI/C,MAAME,KAAKH,KAAK,EAAE,IAAII;QAGtB,MAAMC,cAAc,IAAI,CAAC,cAAc,CAACL;QAGxC,MAAMM,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS,GAAG,EAAE;QAChD,MAAMC,WAAW,IAAI,CAAC,eAAe,CAAC,WAAW;QAEjD,IAAIC,YAA8B;QAClC,IAAID,UACAC,YAAY;YACR,IAAID,SAAS,EAAE;YACf,aAAaA,SAAS,WAAW;YACjC,MAAMA,SAAS,IAAI;QACvB;QAIJ,MAAME,OAAkB;YACpB,GAAGT,IAAI;YACPG;YACA,OAAOH,KAAK,KAAK;YACjBK;YACA,WAAW,IAAIK,OAAO,WAAW;YACjCF;YACAF;QACJ;QAGA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAIK,sBAAsB;YAAEF;YAAM,OAAOT;QAAK;QAGhF,MAAMY,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAACH;QAC5C,IAAIG,OAAO,MAAM,IACb,OAAOjB,OAAO,IAAI,CAACiB,OAAO,KAAK;QAInC,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIC,qBAAqB;YAAE,MAAMD,OAAO,KAAK;YAAE,OAAOZ;QAAK;QAG/D,OAAOL,OAAO,EAAE,CAACiB,OAAO,KAAK;IACjC;IAEQ,eAAeZ,IAAqB,EAAU;QAGlD,IAAIA,KAAK,WAAW,EAChB,OAAOA,KAAK,WAAW;QAG3B,IAAIA,KAAK,SAAS,IAAIA,KAAK,QAAQ,EAC/B,OAAO,GAAGA,KAAK,SAAS,IAAI,GAAG,CAAC,EAAEA,KAAK,QAAQ,IAAI,IAAI,CAAC,IAAI;QAGhE,IAAIA,KAAK,KAAK,EACV,OAAOA,KAAK,KAAK;QAGrB,OAAO;IACX;AACJ;AAEO,MAAMc,sCAAoBC,qBAAqB;IAClD,aAAaC;IACb,gBAAgB5B;IAChB,cAAc;QAAC6B;QAAeC;QAAiBC;QAAgBC;KAAqB;AACxF"}
1
+ {"version":3,"file":"features/users/CreateUser/CreateUserUseCase.js","sources":["../../../../src/features/users/CreateUser/CreateUserUseCase.ts"],"sourcesContent":["import { mdbid } from \"@webiny/utils\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport { TenantContext } from \"~/features/tenancy/TenantContext/index.js\";\nimport { IdentityContext } from \"~/features/security/IdentityContext/index.js\";\nimport { EventPublisher } from \"~/features/eventPublisher/index.js\";\nimport { CreateUserUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { AdminUsersRepository } from \"~/features/users/shared/abstractions.js\";\nimport { createUserValidation } from \"./schema.js\";\nimport {\n NotAuthorizedError,\n EmailTakenError,\n UserValidationError\n} from \"~/features/users/shared/errors.js\";\nimport { UserBeforeCreateEvent, UserAfterCreateEvent } from \"./events.js\";\nimport type { AdminUser } from \"~/features/users/shared/types.js\";\nimport type { CreateUserInput } from \"~/features/users/shared/types.js\";\nimport type { CreatedBy } from \"~/types/users.js\";\n\nclass CreateUserUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private tenantContext: TenantContext.Interface,\n private identityContext: IdentityContext.Interface,\n private eventPublisher: EventPublisher.Interface,\n private repository: AdminUsersRepository.Interface\n ) {}\n\n async execute(input: CreateUserInput): Promise<Result<AdminUser, UseCaseAbstraction.Error>> {\n // 1. Check permission\n const permission = await this.identityContext.getPermission(\"adminUsers.user\");\n if (!permission) {\n return Result.fail(new NotAuthorizedError());\n }\n\n // 2. Validate input\n const validation = createUserValidation.safeParse(input);\n if (!validation.success) {\n return Result.fail(new UserValidationError(validation.error.issues[0].message));\n }\n\n const data = validation.data;\n\n // 3. Check email uniqueness\n const existingUserResult = await this.repository.get({ email: data.email });\n if (existingUserResult.isOk()) {\n // This means the email is taken!\n return Result.fail(new EmailTakenError(data.email));\n }\n\n if (existingUserResult.error.code !== \"AdminUser/NotFound\") {\n return Result.fail(existingUserResult.error);\n }\n\n // 4. Generate ID if not provided\n const id = data.id || mdbid();\n\n // 5. Generate display name\n const displayName = this.getDisplayName(data);\n\n // 6. Get tenant and identity\n const tenant = this.tenantContext.getTenant().id;\n const identity = this.identityContext.getIdentity();\n\n // A user created with no one signed in (e.g. the first admin during installation) has no creator.\n let createdBy: CreatedBy | null = null;\n if (!identity.isAnonymous()) {\n createdBy = {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n };\n }\n\n // 7. Create user entity\n const user: AdminUser = {\n ...data,\n id,\n email: data.email,\n displayName,\n createdOn: new Date().toISOString(),\n createdBy,\n tenant\n };\n\n // 8. Publish before event\n await this.eventPublisher.publish(new UserBeforeCreateEvent({ user, input: data }));\n\n // 10. Create user via repository\n const result = await this.repository.create(user);\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n // 11. Publish after event\n await this.eventPublisher.publish(\n new UserAfterCreateEvent({ user: result.value, input: data })\n );\n\n return Result.ok(result.value);\n }\n\n private getDisplayName(data: CreateUserInput): string {\n // If display name is not set, try to get it from the first name and last name.\n // If first name and last name are not set, use the e-mail address.\n if (data.displayName) {\n return data.displayName;\n }\n\n if (data.firstName || data.lastName) {\n return `${data.firstName || \"\"} ${data.lastName || \"\"}`.trim();\n }\n\n if (data.email) {\n return data.email;\n }\n\n return \"Missing display name\";\n }\n}\n\nexport const CreateUserUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: CreateUserUseCaseImpl,\n dependencies: [TenantContext, IdentityContext, EventPublisher, AdminUsersRepository]\n});\n"],"names":["CreateUserUseCaseImpl","tenantContext","identityContext","eventPublisher","repository","input","permission","Result","NotAuthorizedError","validation","createUserValidation","UserValidationError","data","existingUserResult","EmailTakenError","id","mdbid","displayName","tenant","identity","createdBy","user","Date","UserBeforeCreateEvent","result","UserAfterCreateEvent","CreateUserUseCase","createImplementation","UseCaseAbstraction","TenantContext","IdentityContext","EventPublisher","AdminUsersRepository"],"mappings":";;;;;;;;;;AAmBA,MAAMA;IACF,YACYC,aAAsC,EACtCC,eAA0C,EAC1CC,cAAwC,EACxCC,UAA0C,CACpD;aAJUH,aAAa,GAAbA;aACAC,eAAe,GAAfA;aACAC,cAAc,GAAdA;aACAC,UAAU,GAAVA;IACT;IAEH,MAAM,QAAQC,KAAsB,EAAwD;QAExF,MAAMC,aAAa,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC;QAC5D,IAAI,CAACA,YACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAI3B,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,OAAOH,WAAW,IAAI;QAG5B,MAAMI,qBAAqB,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,OAAOD,KAAK,KAAK;QAAC;QACzE,IAAIC,mBAAmB,IAAI,IAEvB,OAAON,OAAO,IAAI,CAAC,IAAIO,gBAAgBF,KAAK,KAAK;QAGrD,IAAIC,AAAkC,yBAAlCA,mBAAmB,KAAK,CAAC,IAAI,EAC7B,OAAON,OAAO,IAAI,CAACM,mBAAmB,KAAK;QAI/C,MAAME,KAAKH,KAAK,EAAE,IAAII;QAGtB,MAAMC,cAAc,IAAI,CAAC,cAAc,CAACL;QAGxC,MAAMM,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS,GAAG,EAAE;QAChD,MAAMC,WAAW,IAAI,CAAC,eAAe,CAAC,WAAW;QAGjD,IAAIC,YAA8B;QAClC,IAAI,CAACD,SAAS,WAAW,IACrBC,YAAY;YACR,IAAID,SAAS,EAAE;YACf,aAAaA,SAAS,WAAW;YACjC,MAAMA,SAAS,IAAI;QACvB;QAIJ,MAAME,OAAkB;YACpB,GAAGT,IAAI;YACPG;YACA,OAAOH,KAAK,KAAK;YACjBK;YACA,WAAW,IAAIK,OAAO,WAAW;YACjCF;YACAF;QACJ;QAGA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAIK,sBAAsB;YAAEF;YAAM,OAAOT;QAAK;QAGhF,MAAMY,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAACH;QAC5C,IAAIG,OAAO,MAAM,IACb,OAAOjB,OAAO,IAAI,CAACiB,OAAO,KAAK;QAInC,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIC,qBAAqB;YAAE,MAAMD,OAAO,KAAK;YAAE,OAAOZ;QAAK;QAG/D,OAAOL,OAAO,EAAE,CAACiB,OAAO,KAAK;IACjC;IAEQ,eAAeZ,IAAqB,EAAU;QAGlD,IAAIA,KAAK,WAAW,EAChB,OAAOA,KAAK,WAAW;QAG3B,IAAIA,KAAK,SAAS,IAAIA,KAAK,QAAQ,EAC/B,OAAO,GAAGA,KAAK,SAAS,IAAI,GAAG,CAAC,EAAEA,KAAK,QAAQ,IAAI,IAAI,CAAC,IAAI;QAGhE,IAAIA,KAAK,KAAK,EACV,OAAOA,KAAK,KAAK;QAGrB,OAAO;IACX;AACJ;AAEO,MAAMc,sCAAoBC,qBAAqB;IAClD,aAAaC;IACb,gBAAgB5B;IAChB,cAAc;QAAC6B;QAAeC;QAAiBC;QAAgBC;KAAqB;AACxF"}
@@ -0,0 +1,29 @@
1
+ import { UserAfterCreateEventHandler } from "../../../features/users/CreateUser/index.js";
2
+ import { UserAfterUpdateEventHandler } from "../../../features/users/UpdateUser/index.js";
3
+ import { UserAfterDeleteEventHandler } from "../../../features/users/DeleteUser/index.js";
4
+ import { NotifyRecordChangeUseCase } from "../../../features/websockets/index.js";
5
+ declare class NotifyOnUserCreatedHandlerImpl implements UserAfterCreateEventHandler.Interface {
6
+ private notifyRecordChange;
7
+ constructor(notifyRecordChange: NotifyRecordChangeUseCase.Interface);
8
+ handle(event: UserAfterCreateEventHandler.Event): Promise<void>;
9
+ }
10
+ export declare const NotifyOnUserCreatedHandler: typeof NotifyOnUserCreatedHandlerImpl & {
11
+ __abstraction: import("@webiny/di").Abstraction<import("../../eventPublisher/abstractions.js").IEventHandler<import("~/features/users/CreateUser/index.js").UserAfterCreateEvent>>;
12
+ };
13
+ declare class NotifyOnUserUpdatedHandlerImpl implements UserAfterUpdateEventHandler.Interface {
14
+ private notifyRecordChange;
15
+ constructor(notifyRecordChange: NotifyRecordChangeUseCase.Interface);
16
+ handle(event: UserAfterUpdateEventHandler.Event): Promise<void>;
17
+ }
18
+ export declare const NotifyOnUserUpdatedHandler: typeof NotifyOnUserUpdatedHandlerImpl & {
19
+ __abstraction: import("@webiny/di").Abstraction<import("../../eventPublisher/abstractions.js").IEventHandler<import("~/features/users/UpdateUser/index.js").UserAfterUpdateEvent>>;
20
+ };
21
+ declare class NotifyOnUserDeletedHandlerImpl implements UserAfterDeleteEventHandler.Interface {
22
+ private notifyRecordChange;
23
+ constructor(notifyRecordChange: NotifyRecordChangeUseCase.Interface);
24
+ handle(event: UserAfterDeleteEventHandler.Event): Promise<void>;
25
+ }
26
+ export declare const NotifyOnUserDeletedHandler: typeof NotifyOnUserDeletedHandlerImpl & {
27
+ __abstraction: import("@webiny/di").Abstraction<import("../../eventPublisher/abstractions.js").IEventHandler<import("~/features/users/DeleteUser/index.js").UserAfterDeleteEvent>>;
28
+ };
29
+ export {};
@@ -0,0 +1,62 @@
1
+ import { UserAfterCreateEventHandler } from "../CreateUser/index.js";
2
+ import { UserAfterUpdateEventHandler } from "../UpdateUser/index.js";
3
+ import { UserAfterDeleteEventHandler } from "../DeleteUser/index.js";
4
+ import { NotifyRecordChangeUseCase } from "../../websockets/index.js";
5
+ import { USER_RECORD_TYPE } from "./recordType.js";
6
+ class NotifyOnUserCreatedHandlerImpl {
7
+ constructor(notifyRecordChange){
8
+ this.notifyRecordChange = notifyRecordChange;
9
+ }
10
+ async handle(event) {
11
+ await this.notifyRecordChange.execute({
12
+ type: USER_RECORD_TYPE,
13
+ id: event.payload.user.id,
14
+ change: "created"
15
+ });
16
+ }
17
+ }
18
+ const NotifyOnUserCreatedHandler = UserAfterCreateEventHandler.createImplementation({
19
+ implementation: NotifyOnUserCreatedHandlerImpl,
20
+ dependencies: [
21
+ NotifyRecordChangeUseCase
22
+ ]
23
+ });
24
+ class NotifyOnUserUpdatedHandlerImpl {
25
+ constructor(notifyRecordChange){
26
+ this.notifyRecordChange = notifyRecordChange;
27
+ }
28
+ async handle(event) {
29
+ await this.notifyRecordChange.execute({
30
+ type: USER_RECORD_TYPE,
31
+ id: event.payload.updatedUser.id,
32
+ change: "updated"
33
+ });
34
+ }
35
+ }
36
+ const NotifyOnUserUpdatedHandler = UserAfterUpdateEventHandler.createImplementation({
37
+ implementation: NotifyOnUserUpdatedHandlerImpl,
38
+ dependencies: [
39
+ NotifyRecordChangeUseCase
40
+ ]
41
+ });
42
+ class NotifyOnUserDeletedHandlerImpl {
43
+ constructor(notifyRecordChange){
44
+ this.notifyRecordChange = notifyRecordChange;
45
+ }
46
+ async handle(event) {
47
+ await this.notifyRecordChange.execute({
48
+ type: USER_RECORD_TYPE,
49
+ id: event.payload.user.id,
50
+ change: "deleted"
51
+ });
52
+ }
53
+ }
54
+ const NotifyOnUserDeletedHandler = UserAfterDeleteEventHandler.createImplementation({
55
+ implementation: NotifyOnUserDeletedHandlerImpl,
56
+ dependencies: [
57
+ NotifyRecordChangeUseCase
58
+ ]
59
+ });
60
+ export { NotifyOnUserCreatedHandler, NotifyOnUserDeletedHandler, NotifyOnUserUpdatedHandler };
61
+
62
+ //# sourceMappingURL=NotifyOnUserChangeHandlers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/users/NotifyUserChange/NotifyOnUserChangeHandlers.js","sources":["../../../../src/features/users/NotifyUserChange/NotifyOnUserChangeHandlers.ts"],"sourcesContent":["import { UserAfterCreateEventHandler } from \"~/features/users/CreateUser/index.js\";\nimport { UserAfterUpdateEventHandler } from \"~/features/users/UpdateUser/index.js\";\nimport { UserAfterDeleteEventHandler } from \"~/features/users/DeleteUser/index.js\";\nimport { NotifyRecordChangeUseCase } from \"~/features/websockets/index.js\";\nimport { USER_RECORD_TYPE } from \"./recordType.js\";\n\nclass NotifyOnUserCreatedHandlerImpl implements UserAfterCreateEventHandler.Interface {\n constructor(private notifyRecordChange: NotifyRecordChangeUseCase.Interface) {}\n\n async handle(event: UserAfterCreateEventHandler.Event): Promise<void> {\n await this.notifyRecordChange.execute({\n type: USER_RECORD_TYPE,\n id: event.payload.user.id,\n change: \"created\"\n });\n }\n}\n\nexport const NotifyOnUserCreatedHandler = UserAfterCreateEventHandler.createImplementation({\n implementation: NotifyOnUserCreatedHandlerImpl,\n dependencies: [NotifyRecordChangeUseCase]\n});\n\nclass NotifyOnUserUpdatedHandlerImpl implements UserAfterUpdateEventHandler.Interface {\n constructor(private notifyRecordChange: NotifyRecordChangeUseCase.Interface) {}\n\n async handle(event: UserAfterUpdateEventHandler.Event): Promise<void> {\n await this.notifyRecordChange.execute({\n type: USER_RECORD_TYPE,\n id: event.payload.updatedUser.id,\n change: \"updated\"\n });\n }\n}\n\nexport const NotifyOnUserUpdatedHandler = UserAfterUpdateEventHandler.createImplementation({\n implementation: NotifyOnUserUpdatedHandlerImpl,\n dependencies: [NotifyRecordChangeUseCase]\n});\n\nclass NotifyOnUserDeletedHandlerImpl implements UserAfterDeleteEventHandler.Interface {\n constructor(private notifyRecordChange: NotifyRecordChangeUseCase.Interface) {}\n\n async handle(event: UserAfterDeleteEventHandler.Event): Promise<void> {\n await this.notifyRecordChange.execute({\n type: USER_RECORD_TYPE,\n id: event.payload.user.id,\n change: \"deleted\"\n });\n }\n}\n\nexport const NotifyOnUserDeletedHandler = UserAfterDeleteEventHandler.createImplementation({\n implementation: NotifyOnUserDeletedHandlerImpl,\n dependencies: [NotifyRecordChangeUseCase]\n});\n"],"names":["NotifyOnUserCreatedHandlerImpl","notifyRecordChange","event","USER_RECORD_TYPE","NotifyOnUserCreatedHandler","UserAfterCreateEventHandler","NotifyRecordChangeUseCase","NotifyOnUserUpdatedHandlerImpl","NotifyOnUserUpdatedHandler","UserAfterUpdateEventHandler","NotifyOnUserDeletedHandlerImpl","NotifyOnUserDeletedHandler","UserAfterDeleteEventHandler"],"mappings":";;;;;AAMA,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;AAEA,MAAMC;IACF,YAAoBN,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,WAAW,CAAC,EAAE;YAChC,QAAQ;QACZ;IACJ;AACJ;AAEO,MAAMM,6BAA6BC,4BAA4B,oBAAoB,CAAC;IACvF,gBAAgBF;IAChB,cAAc;QAACD;KAA0B;AAC7C;AAEA,MAAMI;IACF,YAAoBT,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,MAAMS,6BAA6BC,4BAA4B,oBAAoB,CAAC;IACvF,gBAAgBF;IAChB,cAAc;QAACJ;KAA0B;AAC7C"}
@@ -0,0 +1,5 @@
1
+ /** Tells the user's open admin tabs when an admin user is created, updated or deleted. */
2
+ export declare const NotifyUserChangeFeature: {
3
+ name: string;
4
+ register(container: import("@webiny/di").Container): void;
5
+ };
@@ -0,0 +1,13 @@
1
+ import { createFeature } from "@webiny/feature/api";
2
+ import { NotifyOnUserCreatedHandler, NotifyOnUserDeletedHandler, NotifyOnUserUpdatedHandler } from "./NotifyOnUserChangeHandlers.js";
3
+ const NotifyUserChangeFeature = createFeature({
4
+ name: "NotifyUserChange",
5
+ register (container) {
6
+ container.register(NotifyOnUserCreatedHandler);
7
+ container.register(NotifyOnUserUpdatedHandler);
8
+ container.register(NotifyOnUserDeletedHandler);
9
+ }
10
+ });
11
+ export { NotifyUserChangeFeature };
12
+
13
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/users/NotifyUserChange/feature.js","sources":["../../../../src/features/users/NotifyUserChange/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport {\n NotifyOnUserCreatedHandler,\n NotifyOnUserDeletedHandler,\n NotifyOnUserUpdatedHandler\n} from \"./NotifyOnUserChangeHandlers.js\";\n\n/** Tells the user's open admin tabs when an admin user is created, updated or deleted. */\nexport const NotifyUserChangeFeature = createFeature({\n name: \"NotifyUserChange\",\n register(container) {\n container.register(NotifyOnUserCreatedHandler);\n container.register(NotifyOnUserUpdatedHandler);\n container.register(NotifyOnUserDeletedHandler);\n }\n});\n"],"names":["NotifyUserChangeFeature","createFeature","container","NotifyOnUserCreatedHandler","NotifyOnUserUpdatedHandler","NotifyOnUserDeletedHandler"],"mappings":";;AAQO,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 { NotifyUserChangeFeature } from "./feature.js";
2
+ export { USER_RECORD_TYPE } from "./recordType.js";
@@ -0,0 +1,2 @@
1
+ export { NotifyUserChangeFeature } from "./feature.js";
2
+ export { USER_RECORD_TYPE } from "./recordType.js";
@@ -0,0 +1,5 @@
1
+ /**
2
+ * The `type` of the record-changed message sent when an admin user changes. The admin's
3
+ * `MarkUsersChanged` filters on the same string.
4
+ */
5
+ export declare const USER_RECORD_TYPE = "adminUsers.user";
@@ -0,0 +1,4 @@
1
+ const USER_RECORD_TYPE = "adminUsers.user";
2
+ export { USER_RECORD_TYPE };
3
+
4
+ //# sourceMappingURL=recordType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/users/NotifyUserChange/recordType.js","sources":["../../../../src/features/users/NotifyUserChange/recordType.ts"],"sourcesContent":["/**\n * The `type` of the record-changed message sent when an admin user changes. The admin's\n * `MarkUsersChanged` filters on the same string.\n */\nexport const USER_RECORD_TYPE = \"adminUsers.user\";\n"],"names":["USER_RECORD_TYPE"],"mappings":"AAIO,MAAMA,mBAAmB"}
@@ -0,0 +1,39 @@
1
+ import { z } from "zod";
2
+ import { AiSdkToolDefinition } from "../../../features/ai/index.js";
3
+ import { AiSdkToolHandler } from "../../../features/ai/index.js";
4
+ import { ListUsersUseCase } from "../../../features/users/ListUsers/index.js";
5
+ interface UserSummary {
6
+ id: string;
7
+ displayName: string;
8
+ email: string;
9
+ /** Role ids, so `updateUserAccess` can be given the full list with one role added or removed. */
10
+ roles: string[];
11
+ /** Team ids, for the same reason. */
12
+ teams: string[];
13
+ }
14
+ declare class ListUsersToolHandlerImpl implements AiSdkToolHandler.Interface<Record<string, never>> {
15
+ private listUsers;
16
+ constructor(listUsers: ListUsersUseCase.Interface);
17
+ execute(): Promise<UserSummary[]>;
18
+ }
19
+ /**
20
+ * Resolves a person ("Jane", "jane@acme.com") to the user id `updateUserAccess` takes, and shows
21
+ * what access they have now.
22
+ */
23
+ declare class ListUsersToolImpl implements AiSdkToolDefinition.Interface<Record<string, never>> {
24
+ readonly name = "listUsers";
25
+ readonly title = "List users";
26
+ readonly description = "Lists the admin users in this project with their ids, display names, emails, role ids and team ids. updateUserAccess takes the id and the exact email. Folder permission targets for a user are 'admin:<id>'.";
27
+ readonly inputSchema: z.ZodObject<{}, z.core.$strip>;
28
+ readonly annotations: {
29
+ readOnlyHint: boolean;
30
+ idempotentHint: boolean;
31
+ };
32
+ readonly handler: typeof ListUsersToolHandlerImpl & {
33
+ __abstraction: import("@webiny/di").Abstraction<import("../../ai/abstractions").IAiSdkToolHandler<any>>;
34
+ };
35
+ }
36
+ export declare const ListUsersTool: typeof ListUsersToolImpl & {
37
+ __abstraction: import("@webiny/di").Abstraction<import("../../ai/abstractions").IAiSdkToolDefinition<any>>;
38
+ };
39
+ export {};
@@ -0,0 +1,46 @@
1
+ import { z } from "zod";
2
+ import { AiSdkToolDefinition, AiSdkToolHandler } from "../../ai/index.js";
3
+ import { ListUsersUseCase } from "../ListUsers/index.js";
4
+ const inputSchema = z.object({});
5
+ class ListUsersToolHandlerImpl {
6
+ constructor(listUsers){
7
+ this.listUsers = listUsers;
8
+ }
9
+ async execute() {
10
+ const result = await this.listUsers.execute();
11
+ if (result.isFail()) throw new Error(`Could not list users: ${result.error.message}`);
12
+ return result.value.map((user)=>({
13
+ id: user.id,
14
+ displayName: user.displayName,
15
+ email: user.email,
16
+ roles: user.roles ?? [],
17
+ teams: user.teams ?? []
18
+ }));
19
+ }
20
+ }
21
+ const ListUsersToolHandler = AiSdkToolHandler.createImplementation({
22
+ implementation: ListUsersToolHandlerImpl,
23
+ dependencies: [
24
+ ListUsersUseCase
25
+ ]
26
+ });
27
+ class ListUsersToolImpl {
28
+ constructor(){
29
+ this.name = "listUsers";
30
+ this.title = "List users";
31
+ this.description = "Lists the admin users in this project with their ids, display names, emails, role ids and team ids. updateUserAccess takes the id and the exact email. Folder permission targets for a user are 'admin:<id>'.";
32
+ this.inputSchema = inputSchema;
33
+ this.annotations = {
34
+ readOnlyHint: true,
35
+ idempotentHint: true
36
+ };
37
+ this.handler = ListUsersToolHandler;
38
+ }
39
+ }
40
+ const ListUsersTool = AiSdkToolDefinition.createImplementation({
41
+ implementation: ListUsersToolImpl,
42
+ dependencies: []
43
+ });
44
+ export { ListUsersTool };
45
+
46
+ //# sourceMappingURL=ListUsersTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/users/ai/ListUsersTool.js","sources":["../../../../src/features/users/ai/ListUsersTool.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { AiSdkToolDefinition } from \"~/features/ai/index.js\";\nimport { AiSdkToolHandler } from \"~/features/ai/index.js\";\nimport { ListUsersUseCase } from \"~/features/users/ListUsers/index.js\";\n\nconst inputSchema = z.object({});\n\ninterface UserSummary {\n id: string;\n displayName: string;\n email: string;\n /** Role ids, so `updateUserAccess` can be given the full list with one role added or removed. */\n roles: string[];\n /** Team ids, for the same reason. */\n teams: string[];\n}\n\nclass ListUsersToolHandlerImpl implements AiSdkToolHandler.Interface<Record<string, never>> {\n constructor(private listUsers: ListUsersUseCase.Interface) {}\n\n async execute(): Promise<UserSummary[]> {\n const result = await this.listUsers.execute();\n\n if (result.isFail()) {\n throw new Error(`Could not list users: ${result.error.message}`);\n }\n\n return result.value.map(user => ({\n id: user.id,\n displayName: user.displayName,\n email: user.email,\n roles: user.roles ?? [],\n teams: user.teams ?? []\n }));\n }\n}\n\nconst ListUsersToolHandler = AiSdkToolHandler.createImplementation({\n implementation: ListUsersToolHandlerImpl,\n dependencies: [ListUsersUseCase]\n});\n\n/**\n * Resolves a person (\"Jane\", \"jane@acme.com\") to the user id `updateUserAccess` takes, and shows\n * what access they have now.\n */\nclass ListUsersToolImpl implements AiSdkToolDefinition.Interface<Record<string, never>> {\n readonly name = \"listUsers\";\n readonly title = \"List users\";\n readonly description =\n \"Lists the admin users in this project with their ids, display names, emails, role ids and team ids. updateUserAccess takes the id and the exact email. Folder permission targets for a user are 'admin:<id>'.\";\n readonly inputSchema = inputSchema;\n readonly annotations = { readOnlyHint: true, idempotentHint: true };\n readonly handler = ListUsersToolHandler;\n}\n\nexport const ListUsersTool = AiSdkToolDefinition.createImplementation({\n implementation: ListUsersToolImpl,\n dependencies: []\n});\n"],"names":["inputSchema","z","ListUsersToolHandlerImpl","listUsers","result","Error","user","ListUsersToolHandler","AiSdkToolHandler","ListUsersUseCase","ListUsersToolImpl","ListUsersTool","AiSdkToolDefinition"],"mappings":";;;AAKA,MAAMA,cAAcC,EAAE,MAAM,CAAC,CAAC;AAY9B,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,OAAS;gBAC7B,IAAIA,KAAK,EAAE;gBACX,aAAaA,KAAK,WAAW;gBAC7B,OAAOA,KAAK,KAAK;gBACjB,OAAOA,KAAK,KAAK,IAAI,EAAE;gBACvB,OAAOA,KAAK,KAAK,IAAI,EAAE;YAC3B;IACJ;AACJ;AAEA,MAAMC,uBAAuBC,iBAAiB,oBAAoB,CAAC;IAC/D,gBAAgBN;IAChB,cAAc;QAACO;KAAiB;AACpC;AAMA,MAAMC;;aACO,IAAI,GAAG;aACP,KAAK,GAAG;aACR,WAAW,GAChB;aACK,WAAW,GAAGV;aACd,WAAW,GAAG;YAAE,cAAc;YAAM,gBAAgB;QAAK;aACzD,OAAO,GAAGO;;AACvB;AAEO,MAAMI,gBAAgBC,oBAAoB,oBAAoB,CAAC;IAClE,gBAAgBF;IAChB,cAAc,EAAE;AACpB"}
@@ -0,0 +1,59 @@
1
+ import { z } from "zod";
2
+ import { AiSdkToolDefinition } from "../../../features/ai/index.js";
3
+ import { AiSdkToolHandler } from "../../../features/ai/index.js";
4
+ import { IdentityContext } from "../../../features/security/IdentityContext/index.js";
5
+ import { GetUserUseCase } from "../../../features/users/GetUser/index.js";
6
+ import { UpdateUserUseCase } from "../../../features/users/UpdateUser/index.js";
7
+ import { ListRolesUseCase } from "../../../features/security/roles/ListRoles/index.js";
8
+ import { ListTeamsUseCase } from "../../../features/security/teams/ListTeams/index.js";
9
+ declare const inputSchema: z.ZodObject<{
10
+ userId: z.ZodString;
11
+ email: z.ZodString;
12
+ roles: z.ZodOptional<z.ZodArray<z.ZodString>>;
13
+ teams: z.ZodOptional<z.ZodArray<z.ZodString>>;
14
+ }, z.core.$strip>;
15
+ type Input = z.infer<typeof inputSchema>;
16
+ interface UpdatedUserAccess {
17
+ id: string;
18
+ email: string;
19
+ roles: string[];
20
+ teams: string[];
21
+ }
22
+ declare class UpdateUserAccessToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {
23
+ private identityContext;
24
+ private getUser;
25
+ private listRoles;
26
+ private listTeams;
27
+ private updateUser;
28
+ constructor(identityContext: IdentityContext.Interface, getUser: GetUserUseCase.Interface, listRoles: ListRolesUseCase.Interface, listTeams: ListTeamsUseCase.Interface, updateUser: UpdateUserUseCase.Interface);
29
+ execute(input: Input): Promise<UpdatedUserAccess>;
30
+ }
31
+ /**
32
+ * Changes which roles and teams a user has.
33
+ *
34
+ * Needs approval: roles and teams decide what the user can do. Each list replaces the stored one,
35
+ * and the approval shows the whole list, so a role the model left out is visible as missing before
36
+ * anything is written.
37
+ */
38
+ declare class UpdateUserAccessToolImpl implements AiSdkToolDefinition.Interface<Input> {
39
+ readonly name = "updateUserAccess";
40
+ readonly title = "Update user access";
41
+ readonly description = "Changes which roles and teams an admin user has. Call listUsers first for the id and exact email. `roles` and `teams` each replace the user's whole list, so pass everything the user should keep; resolve them with listRoles and listTeams. Cannot change the signed-in user or users from an external identity provider, and cannot change a user's name, email or password. Requires user approval.";
42
+ readonly inputSchema: z.ZodObject<{
43
+ userId: z.ZodString;
44
+ email: z.ZodString;
45
+ roles: z.ZodOptional<z.ZodArray<z.ZodString>>;
46
+ teams: z.ZodOptional<z.ZodArray<z.ZodString>>;
47
+ }, z.core.$strip>;
48
+ readonly annotations: {
49
+ readOnlyHint: boolean;
50
+ idempotentHint: boolean;
51
+ };
52
+ readonly handler: typeof UpdateUserAccessToolHandlerImpl & {
53
+ __abstraction: import("@webiny/di").Abstraction<import("../../ai/abstractions").IAiSdkToolHandler<any>>;
54
+ };
55
+ }
56
+ export declare const UpdateUserAccessTool: typeof UpdateUserAccessToolImpl & {
57
+ __abstraction: import("@webiny/di").Abstraction<import("../../ai/abstractions").IAiSdkToolDefinition<any>>;
58
+ };
59
+ export {};
@@ -0,0 +1,101 @@
1
+ import { z } from "zod";
2
+ import { AiSdkToolDefinition, AiSdkToolHandler } from "../../ai/index.js";
3
+ import { IdentityContext } from "../../security/IdentityContext/index.js";
4
+ import { GetUserUseCase } from "../GetUser/index.js";
5
+ import { UpdateUserUseCase } from "../UpdateUser/index.js";
6
+ import { ListRolesUseCase } from "../../security/roles/ListRoles/index.js";
7
+ import { ListTeamsUseCase } from "../../security/teams/ListTeams/index.js";
8
+ const inputSchema = z.object({
9
+ userId: z.string().describe("User id as returned by listUsers."),
10
+ email: z.string().describe("The user's current email, exactly as listUsers returned it. The change is refused if it does not match."),
11
+ roles: z.array(z.string()).optional().describe("The complete list of roles the user should have afterwards. It REPLACES the stored list, so include the roles to keep. Omit it to leave the roles alone. Role ids or slugs from listRoles."),
12
+ teams: z.array(z.string()).optional().describe("The complete list of teams the user should be in afterwards. It REPLACES the stored list, so include the teams to keep. Omit it to leave the teams alone. Team ids or slugs from listTeams.")
13
+ });
14
+ const toIds = (kind, values, known)=>{
15
+ const unknown = [];
16
+ const ids = values.map((value)=>{
17
+ const match = known.find((record)=>record.id === value || record.slug === value);
18
+ if (!match) {
19
+ unknown.push(value);
20
+ return value;
21
+ }
22
+ return match.id;
23
+ });
24
+ if (unknown.length > 0) {
25
+ const names = unknown.map((value)=>`"${value}"`).join(", ");
26
+ throw new Error(`Not a known ${kind} id or slug: ${names}. Nothing was changed. Call list${"role" === kind ? "Roles" : "Teams"} for valid values.`);
27
+ }
28
+ return Array.from(new Set(ids));
29
+ };
30
+ class UpdateUserAccessToolHandlerImpl {
31
+ constructor(identityContext, getUser, listRoles, listTeams, updateUser){
32
+ this.identityContext = identityContext;
33
+ this.getUser = getUser;
34
+ this.listRoles = listRoles;
35
+ this.listTeams = listTeams;
36
+ this.updateUser = updateUser;
37
+ }
38
+ async execute(input) {
39
+ if (void 0 === input.roles && void 0 === input.teams) throw new Error("Pass roles, teams or both. Nothing was changed.");
40
+ const found = await this.getUser.execute({
41
+ id: input.userId
42
+ });
43
+ if (found.isFail()) throw new Error(`User "${input.userId}" not found: ${found.error.message}. Call listUsers for valid ids.`);
44
+ const user = found.value;
45
+ if (user.email !== input.email) throw new Error(`User "${input.userId}" has the email "${user.email}", not "${input.email}", so nothing was changed. Check the user with listUsers.`);
46
+ if (user.id === this.identityContext.getIdentity().id) throw new Error("This is the signed-in user. Change your own roles and teams in the Users screen, so a mistake cannot lock you out. Nothing was changed.");
47
+ if (user.external) throw new Error(`"${user.email}" signs in through an external identity provider, which sets their roles and teams at every sign-in. Change them there. Nothing was changed.`);
48
+ const changes = {};
49
+ if (input.roles?.length === 0) changes.roles = [];
50
+ else if (void 0 !== input.roles) {
51
+ const roles = await this.listRoles.execute();
52
+ if (roles.isFail()) throw new Error(`Could not check the roles: ${roles.error.message}`);
53
+ changes.roles = toIds("role", input.roles, roles.value);
54
+ }
55
+ if (input.teams?.length === 0) changes.teams = [];
56
+ else if (void 0 !== input.teams) {
57
+ const teams = await this.listTeams.execute();
58
+ if (teams.isFail()) throw new Error(`Could not check the teams: ${teams.error.message}`);
59
+ changes.teams = toIds("team", input.teams, teams.value);
60
+ }
61
+ const result = await this.updateUser.execute(user.id, changes);
62
+ if (result.isFail()) throw new Error(`Could not update the user: ${result.error.message}`);
63
+ const updated = result.value;
64
+ return {
65
+ id: updated.id,
66
+ email: updated.email,
67
+ roles: updated.roles ?? [],
68
+ teams: updated.teams ?? []
69
+ };
70
+ }
71
+ }
72
+ const UpdateUserAccessToolHandler = AiSdkToolHandler.createImplementation({
73
+ implementation: UpdateUserAccessToolHandlerImpl,
74
+ dependencies: [
75
+ IdentityContext,
76
+ GetUserUseCase,
77
+ ListRolesUseCase,
78
+ ListTeamsUseCase,
79
+ UpdateUserUseCase
80
+ ]
81
+ });
82
+ class UpdateUserAccessToolImpl {
83
+ constructor(){
84
+ this.name = "updateUserAccess";
85
+ this.title = "Update user access";
86
+ this.description = "Changes which roles and teams an admin user has. Call listUsers first for the id and exact email. `roles` and `teams` each replace the user's whole list, so pass everything the user should keep; resolve them with listRoles and listTeams. Cannot change the signed-in user or users from an external identity provider, and cannot change a user's name, email or password. Requires user approval.";
87
+ this.inputSchema = inputSchema;
88
+ this.annotations = {
89
+ readOnlyHint: false,
90
+ idempotentHint: true
91
+ };
92
+ this.handler = UpdateUserAccessToolHandler;
93
+ }
94
+ }
95
+ const UpdateUserAccessTool = AiSdkToolDefinition.createImplementation({
96
+ implementation: UpdateUserAccessToolImpl,
97
+ dependencies: []
98
+ });
99
+ export { UpdateUserAccessTool };
100
+
101
+ //# sourceMappingURL=UpdateUserAccessTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/users/ai/UpdateUserAccessTool.js","sources":["../../../../src/features/users/ai/UpdateUserAccessTool.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { AiSdkToolDefinition } from \"~/features/ai/index.js\";\nimport { AiSdkToolHandler } from \"~/features/ai/index.js\";\nimport { IdentityContext } from \"~/features/security/IdentityContext/index.js\";\nimport { GetUserUseCase } from \"~/features/users/GetUser/index.js\";\nimport { UpdateUserUseCase } from \"~/features/users/UpdateUser/index.js\";\nimport { ListRolesUseCase } from \"~/features/security/roles/ListRoles/index.js\";\nimport { ListTeamsUseCase } from \"~/features/security/teams/ListTeams/index.js\";\n\nconst inputSchema = z.object({\n userId: z.string().describe(\"User id as returned by listUsers.\"),\n email: z\n .string()\n .describe(\n \"The user's current email, exactly as listUsers returned it. The change is refused if it does not match.\"\n ),\n roles: z\n .array(z.string())\n .optional()\n .describe(\n \"The complete list of roles the user should have afterwards. It REPLACES the stored list, so include the roles to keep. Omit it to leave the roles alone. Role ids or slugs from listRoles.\"\n ),\n teams: z\n .array(z.string())\n .optional()\n .describe(\n \"The complete list of teams the user should be in afterwards. It REPLACES the stored list, so include the teams to keep. Omit it to leave the teams alone. Team ids or slugs from listTeams.\"\n )\n});\n\ntype Input = z.infer<typeof inputSchema>;\n\ninterface UpdatedUserAccess {\n id: string;\n email: string;\n roles: string[];\n teams: string[];\n}\n\ninterface NamedRecord {\n id: string;\n slug: string;\n}\n\n/*\n * A user stores role and team ids, and sign-in loads them by id only. `UpdateUserUseCase` stores\n * whatever it is given, so a slug or a typo would be saved and silently grant nothing. The tool maps\n * each value to an id here and refuses any it cannot find.\n */\nconst toIds = (kind: string, values: string[], known: NamedRecord[]): string[] => {\n const unknown: string[] = [];\n\n const ids = values.map(value => {\n const match = known.find(record => record.id === value || record.slug === value);\n if (!match) {\n unknown.push(value);\n return value;\n }\n return match.id;\n });\n\n if (unknown.length > 0) {\n const names = unknown.map(value => `\"${value}\"`).join(\", \");\n throw new Error(\n `Not a known ${kind} id or slug: ${names}. Nothing was changed. Call list${kind === \"role\" ? \"Roles\" : \"Teams\"} for valid values.`\n );\n }\n\n return Array.from(new Set(ids));\n};\n\n/*\n * The checks run before anything is written:\n *\n * - The email is in the input so the approval shows whose access changes; it is checked against the\n * stored user, so what the user approved is what is changed.\n * - The signed-in user's own access is refused. One wrong role list would lock them out of the\n * screens they would need to undo it.\n * - Users from an external identity provider (Okta, Auth0) are refused. `ExternalIdpUserSync`\n * rewrites their roles and teams from the provider at every sign-in, so a change here would be\n * reported as done and then undone.\n * - Only roles and teams are written. Name, email and password belong to the identity provider too\n * (Cognito, self-hosted sign-in), and `UpdateUserUseCase` alone would change the Webiny record\n * without it. Roles and teams exist only in Webiny, so this is safe with any provider.\n */\nclass UpdateUserAccessToolHandlerImpl implements AiSdkToolHandler.Interface<Input> {\n constructor(\n private identityContext: IdentityContext.Interface,\n private getUser: GetUserUseCase.Interface,\n private listRoles: ListRolesUseCase.Interface,\n private listTeams: ListTeamsUseCase.Interface,\n private updateUser: UpdateUserUseCase.Interface\n ) {}\n\n async execute(input: Input): Promise<UpdatedUserAccess> {\n if (input.roles === undefined && input.teams === undefined) {\n throw new Error(\"Pass roles, teams or both. Nothing was changed.\");\n }\n\n const found = await this.getUser.execute({ id: input.userId });\n if (found.isFail()) {\n throw new Error(\n `User \"${input.userId}\" not found: ${found.error.message}. Call listUsers for valid ids.`\n );\n }\n\n const user = found.value;\n\n if (user.email !== input.email) {\n throw new Error(\n `User \"${input.userId}\" has the email \"${user.email}\", not \"${input.email}\", so nothing was changed. Check the user with listUsers.`\n );\n }\n\n if (user.id === this.identityContext.getIdentity().id) {\n throw new Error(\n \"This is the signed-in user. Change your own roles and teams in the Users screen, so a mistake cannot lock you out. Nothing was changed.\"\n );\n }\n\n if (user.external) {\n throw new Error(\n `\"${user.email}\" signs in through an external identity provider, which sets their roles and teams at every sign-in. Change them there. Nothing was changed.`\n );\n }\n\n const changes: { roles?: string[]; teams?: string[] } = {};\n\n // An empty list has nothing to look up. Reading the roles or teams anyway would make clearing\n // them need security.role or security.team on top of adminUsers.user.\n if (input.roles?.length === 0) {\n changes.roles = [];\n } else if (input.roles !== undefined) {\n const roles = await this.listRoles.execute();\n if (roles.isFail()) {\n throw new Error(`Could not check the roles: ${roles.error.message}`);\n }\n changes.roles = toIds(\"role\", input.roles, roles.value);\n }\n\n if (input.teams?.length === 0) {\n changes.teams = [];\n } else if (input.teams !== undefined) {\n const teams = await this.listTeams.execute();\n if (teams.isFail()) {\n throw new Error(`Could not check the teams: ${teams.error.message}`);\n }\n changes.teams = toIds(\"team\", input.teams, teams.value);\n }\n\n const result = await this.updateUser.execute(user.id, changes);\n if (result.isFail()) {\n throw new Error(`Could not update the user: ${result.error.message}`);\n }\n\n const updated = result.value;\n\n return {\n id: updated.id,\n email: updated.email,\n roles: updated.roles ?? [],\n teams: updated.teams ?? []\n };\n }\n}\n\nconst UpdateUserAccessToolHandler = AiSdkToolHandler.createImplementation({\n implementation: UpdateUserAccessToolHandlerImpl,\n dependencies: [\n IdentityContext,\n GetUserUseCase,\n ListRolesUseCase,\n ListTeamsUseCase,\n UpdateUserUseCase\n ]\n});\n\n/**\n * Changes which roles and teams a user has.\n *\n * Needs approval: roles and teams decide what the user can do. Each list replaces the stored one,\n * and the approval shows the whole list, so a role the model left out is visible as missing before\n * anything is written.\n */\nclass UpdateUserAccessToolImpl implements AiSdkToolDefinition.Interface<Input> {\n readonly name = \"updateUserAccess\";\n readonly title = \"Update user access\";\n readonly description =\n \"Changes which roles and teams an admin user has. Call listUsers first for the id and exact email. `roles` and `teams` each replace the user's whole list, so pass everything the user should keep; resolve them with listRoles and listTeams. Cannot change the signed-in user or users from an external identity provider, and cannot change a user's name, email or password. Requires user approval.\";\n readonly inputSchema = inputSchema;\n readonly annotations = { readOnlyHint: false, idempotentHint: true };\n readonly handler = UpdateUserAccessToolHandler;\n}\n\nexport const UpdateUserAccessTool = AiSdkToolDefinition.createImplementation({\n implementation: UpdateUserAccessToolImpl,\n dependencies: []\n});\n"],"names":["inputSchema","z","toIds","kind","values","known","unknown","ids","value","match","record","names","Error","Array","Set","UpdateUserAccessToolHandlerImpl","identityContext","getUser","listRoles","listTeams","updateUser","input","undefined","found","user","changes","roles","teams","result","updated","UpdateUserAccessToolHandler","AiSdkToolHandler","IdentityContext","GetUserUseCase","ListRolesUseCase","ListTeamsUseCase","UpdateUserUseCase","UpdateUserAccessToolImpl","UpdateUserAccessTool","AiSdkToolDefinition"],"mappings":"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"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Admin user tools for AI callers.
3
+ *
4
+ * There is no create or delete tool. A user's sign-in account lives with the identity provider
5
+ * (Cognito, self-hosted sign-in), which wraps the api-core use cases with its own. Creating or deleting
6
+ * through api-core alone would leave a user who cannot sign in, or a sign-in account with no user.
7
+ */
8
+ export declare const UsersAiToolsFeature: {
9
+ name: string;
10
+ register(container: import("@webiny/di").Container): void;
11
+ };
@@ -0,0 +1,13 @@
1
+ import { createFeature } from "@webiny/feature/api";
2
+ import { ListUsersTool } from "./ListUsersTool.js";
3
+ import { UpdateUserAccessTool } from "./UpdateUserAccessTool.js";
4
+ const UsersAiToolsFeature = createFeature({
5
+ name: "AdminUsers/AiTools",
6
+ register (container) {
7
+ container.register(ListUsersTool);
8
+ container.register(UpdateUserAccessTool);
9
+ }
10
+ });
11
+ export { UsersAiToolsFeature };
12
+
13
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/users/ai/feature.js","sources":["../../../../src/features/users/ai/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { ListUsersTool } from \"./ListUsersTool.js\";\nimport { UpdateUserAccessTool } from \"./UpdateUserAccessTool.js\";\n\n/**\n * Admin user tools for AI callers.\n *\n * There is no create or delete tool. A user's sign-in account lives with the identity provider\n * (Cognito, self-hosted sign-in), which wraps the api-core use cases with its own. Creating or deleting\n * through api-core alone would leave a user who cannot sign in, or a sign-in account with no user.\n */\nexport const UsersAiToolsFeature = createFeature({\n name: \"AdminUsers/AiTools\",\n register(container) {\n container.register(ListUsersTool);\n container.register(UpdateUserAccessTool);\n }\n});\n"],"names":["UsersAiToolsFeature","createFeature","container","ListUsersTool","UpdateUserAccessTool"],"mappings":";;;AAWO,MAAMA,sBAAsBC,cAAc;IAC7C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;IACvB;AACJ"}
@@ -0,0 +1,3 @@
1
+ export { UsersAiToolsFeature } from "./feature.js";
2
+ export { ListUsersTool } from "./ListUsersTool.js";
3
+ export { UpdateUserAccessTool } from "./UpdateUserAccessTool.js";
@@ -0,0 +1,3 @@
1
+ export { UsersAiToolsFeature } from "./feature.js";
2
+ export { ListUsersTool } from "./ListUsersTool.js";
3
+ export { UpdateUserAccessTool } from "./UpdateUserAccessTool.js";
@@ -0,0 +1,12 @@
1
+ import { IdentityContext } from "../../../features/security/IdentityContext/abstractions.js";
2
+ import { WebsocketsSendToIdentityUseCase } from "../../../features/websockets/SendToIdentity/abstractions.js";
3
+ import { NotifyRecordChangeUseCase as UseCaseAbstraction } from "./abstractions.js";
4
+ declare class NotifyRecordChangeUseCaseImpl implements UseCaseAbstraction.Interface {
5
+ private identityContext;
6
+ private sendToIdentity;
7
+ constructor(identityContext: IdentityContext.Interface, sendToIdentity: WebsocketsSendToIdentityUseCase.Interface);
8
+ execute({ identityId, ...data }: UseCaseAbstraction.Params): Promise<void>;
9
+ private getSignedInIdentityId;
10
+ }
11
+ export declare const NotifyRecordChangeUseCase: import("@webiny/di").Implementation<typeof NotifyRecordChangeUseCaseImpl>;
12
+ export {};