@webiny/cognito 6.5.0-beta.9 → 6.5.1-beta.0

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 (141) hide show
  1. package/admin/Extension.js +9 -0
  2. package/admin/Extension.js.map +1 -1
  3. package/admin/features/users/checkEmail/CheckEmailGateway.d.ts +11 -0
  4. package/admin/features/users/checkEmail/CheckEmailGateway.js +44 -0
  5. package/admin/features/users/checkEmail/CheckEmailGateway.js.map +1 -0
  6. package/admin/features/users/checkEmail/CheckEmailUseCase.d.ts +10 -0
  7. package/admin/features/users/checkEmail/CheckEmailUseCase.js +18 -0
  8. package/admin/features/users/checkEmail/CheckEmailUseCase.js.map +1 -0
  9. package/admin/features/users/checkEmail/abstractions/CheckEmailGateway.d.ts +14 -0
  10. package/admin/features/users/checkEmail/abstractions/CheckEmailGateway.js +5 -0
  11. package/admin/features/users/checkEmail/abstractions/CheckEmailGateway.js.map +1 -0
  12. package/admin/features/users/checkEmail/abstractions/CheckEmailUseCase.d.ts +9 -0
  13. package/admin/features/users/checkEmail/abstractions/CheckEmailUseCase.js +5 -0
  14. package/admin/features/users/checkEmail/abstractions/CheckEmailUseCase.js.map +1 -0
  15. package/admin/features/users/checkEmail/abstractions/index.d.ts +2 -0
  16. package/admin/features/users/checkEmail/abstractions/index.js +2 -0
  17. package/admin/features/users/checkEmail/feature.d.ts +3 -0
  18. package/admin/features/users/checkEmail/feature.js +19 -0
  19. package/admin/features/users/checkEmail/feature.js.map +1 -0
  20. package/admin/features/users/checkEmail/index.d.ts +2 -0
  21. package/admin/features/users/checkEmail/index.js +2 -0
  22. package/admin/features/users/createUser/CreateUserGateway.js +2 -1
  23. package/admin/features/users/createUser/CreateUserGateway.js.map +1 -1
  24. package/admin/features/users/createUser/CreateUserUseCase.test.d.ts +1 -0
  25. package/admin/features/users/createUser/CreateUserUseCase.test.js +65 -0
  26. package/admin/features/users/createUser/CreateUserUseCase.test.js.map +1 -0
  27. package/admin/features/users/linkUser/LinkUserGateway.d.ts +11 -0
  28. package/admin/features/users/linkUser/LinkUserGateway.js +50 -0
  29. package/admin/features/users/linkUser/LinkUserGateway.js.map +1 -0
  30. package/admin/features/users/linkUser/LinkUserUseCase.d.ts +10 -0
  31. package/admin/features/users/linkUser/LinkUserUseCase.js +18 -0
  32. package/admin/features/users/linkUser/LinkUserUseCase.js.map +1 -0
  33. package/admin/features/users/linkUser/abstractions/LinkUserGateway.d.ts +18 -0
  34. package/admin/features/users/linkUser/abstractions/LinkUserGateway.js +5 -0
  35. package/admin/features/users/linkUser/abstractions/LinkUserGateway.js.map +1 -0
  36. package/admin/features/users/linkUser/abstractions/LinkUserUseCase.d.ts +15 -0
  37. package/admin/features/users/linkUser/abstractions/LinkUserUseCase.js +5 -0
  38. package/admin/features/users/linkUser/abstractions/LinkUserUseCase.js.map +1 -0
  39. package/admin/features/users/linkUser/abstractions/index.d.ts +2 -0
  40. package/admin/features/users/linkUser/abstractions/index.js +2 -0
  41. package/admin/features/users/linkUser/feature.d.ts +3 -0
  42. package/admin/features/users/linkUser/feature.js +19 -0
  43. package/admin/features/users/linkUser/feature.js.map +1 -0
  44. package/admin/features/users/linkUser/index.d.ts +2 -0
  45. package/admin/features/users/linkUser/index.js +2 -0
  46. package/admin/features/users/shared/AdminUsersError.d.ts +13 -0
  47. package/admin/features/users/shared/AdminUsersError.js +11 -0
  48. package/admin/features/users/shared/AdminUsersError.js.map +1 -0
  49. package/admin/presentation/Cognito/CognitoLoginScreen.js +9 -1
  50. package/admin/presentation/Cognito/CognitoLoginScreen.js.map +1 -1
  51. package/admin/presentation/Cognito/CognitoPresenter.d.ts +10 -1
  52. package/admin/presentation/Cognito/CognitoPresenter.js +50 -4
  53. package/admin/presentation/Cognito/CognitoPresenter.js.map +1 -1
  54. package/admin/presentation/Cognito/CognitoPresenter.test.d.ts +1 -0
  55. package/admin/presentation/Cognito/CognitoPresenter.test.js +180 -0
  56. package/admin/presentation/Cognito/CognitoPresenter.test.js.map +1 -0
  57. package/admin/presentation/Cognito/abstractions.d.ts +8 -1
  58. package/admin/presentation/Cognito/abstractions.js.map +1 -1
  59. package/admin/presentation/Cognito/components/NoTenantAccess.d.ts +23 -0
  60. package/admin/presentation/Cognito/components/NoTenantAccess.js +10 -0
  61. package/admin/presentation/Cognito/components/NoTenantAccess.js.map +1 -0
  62. package/admin/presentation/Cognito/components/SelectTenant.d.ts +26 -0
  63. package/admin/presentation/Cognito/components/SelectTenant.js +15 -0
  64. package/admin/presentation/Cognito/components/SelectTenant.js.map +1 -0
  65. package/admin/presentation/Cognito/components/index.d.ts +38 -0
  66. package/admin/presentation/Cognito/components/index.js +4 -0
  67. package/admin/presentation/Cognito/components/index.js.map +1 -1
  68. package/admin/presentation/users/UserForm/UserFormPresenter.d.ts +30 -0
  69. package/admin/presentation/users/UserForm/UserFormPresenter.js +118 -0
  70. package/admin/presentation/users/UserForm/UserFormPresenter.js.map +1 -0
  71. package/admin/presentation/users/UserForm/UserFormPresenter.test.d.ts +1 -0
  72. package/admin/presentation/users/UserForm/UserFormPresenter.test.js +248 -0
  73. package/admin/presentation/users/UserForm/UserFormPresenter.test.js.map +1 -0
  74. package/admin/presentation/users/UserForm/abstractions.d.ts +52 -0
  75. package/admin/presentation/users/UserForm/abstractions.js +5 -0
  76. package/admin/presentation/users/UserForm/abstractions.js.map +1 -0
  77. package/admin/presentation/users/UserForm/feature.d.ts +7 -0
  78. package/admin/presentation/users/UserForm/feature.js +17 -0
  79. package/admin/presentation/users/UserForm/feature.js.map +1 -0
  80. package/admin/ui/views/Users/UsersForm.d.ts +3 -1
  81. package/admin/ui/views/Users/UsersForm.js +43 -20
  82. package/admin/ui/views/Users/UsersForm.js.map +1 -1
  83. package/admin/ui/views/Users/components/LinkAccountAlert.d.ts +10 -0
  84. package/admin/ui/views/Users/components/LinkAccountAlert.js +17 -0
  85. package/admin/ui/views/Users/components/LinkAccountAlert.js.map +1 -0
  86. package/admin/ui/views/Users/hooks/useUserForm.d.ts +1 -0
  87. package/admin/ui/views/Users/hooks/useUserForm.js +31 -18
  88. package/admin/ui/views/Users/hooks/useUserForm.js.map +1 -1
  89. package/api/CognitoApiFeature.js +4 -0
  90. package/api/CognitoApiFeature.js.map +1 -1
  91. package/api/domain/errors.d.ts +49 -0
  92. package/api/domain/errors.js +53 -1
  93. package/api/domain/errors.js.map +1 -1
  94. package/api/features/CheckEmail/CheckEmailUseCase.d.ts +16 -0
  95. package/api/features/CheckEmail/CheckEmailUseCase.js +47 -0
  96. package/api/features/CheckEmail/CheckEmailUseCase.js.map +1 -0
  97. package/api/features/CheckEmail/abstractions.d.ts +29 -0
  98. package/api/features/CheckEmail/abstractions.js +5 -0
  99. package/api/features/CheckEmail/abstractions.js.map +1 -0
  100. package/api/features/CheckEmail/feature.d.ts +4 -0
  101. package/api/features/CheckEmail/feature.js +11 -0
  102. package/api/features/CheckEmail/feature.js.map +1 -0
  103. package/api/features/CheckEmail/index.d.ts +2 -0
  104. package/api/features/CheckEmail/index.js +2 -0
  105. package/api/features/CognitoService/CognitoService.d.ts +1 -1
  106. package/api/features/CognitoService/CognitoService.js +11 -5
  107. package/api/features/CognitoService/CognitoService.js.map +1 -1
  108. package/api/features/CognitoService/abstractions.d.ts +8 -2
  109. package/api/features/CognitoService/abstractions.js.map +1 -1
  110. package/api/features/CreateUser/CreateUserUseCase.d.ts +1 -2
  111. package/api/features/CreateUser/CreateUserUseCase.js +3 -3
  112. package/api/features/CreateUser/CreateUserUseCase.js.map +1 -1
  113. package/api/features/CreateUser/abstractions.d.ts +3 -1
  114. package/api/features/CreateUser/abstractions.js.map +1 -1
  115. package/api/features/DeleteUser/DeleteUserUseCase.d.ts +3 -1
  116. package/api/features/DeleteUser/DeleteUserUseCase.js +11 -2
  117. package/api/features/DeleteUser/DeleteUserUseCase.js.map +1 -1
  118. package/api/features/DeleteUser/abstractions.d.ts +2 -0
  119. package/api/features/DeleteUser/abstractions.js.map +1 -1
  120. package/api/features/LinkUser/LinkUserUseCase.d.ts +22 -0
  121. package/api/features/LinkUser/LinkUserUseCase.js +83 -0
  122. package/api/features/LinkUser/LinkUserUseCase.js.map +1 -0
  123. package/api/features/LinkUser/abstractions.d.ts +36 -0
  124. package/api/features/LinkUser/abstractions.js +5 -0
  125. package/api/features/LinkUser/abstractions.js.map +1 -0
  126. package/api/features/LinkUser/feature.d.ts +4 -0
  127. package/api/features/LinkUser/feature.js +11 -0
  128. package/api/features/LinkUser/feature.js.map +1 -0
  129. package/api/features/LinkUser/index.d.ts +2 -0
  130. package/api/features/LinkUser/index.js +2 -0
  131. package/api/features/UpdateUser/UpdateUserUseCase.d.ts +14 -1
  132. package/api/features/UpdateUser/UpdateUserUseCase.js +93 -4
  133. package/api/features/UpdateUser/UpdateUserUseCase.js.map +1 -1
  134. package/api/features/UpdateUser/abstractions.d.ts +7 -1
  135. package/api/features/UpdateUser/abstractions.js.map +1 -1
  136. package/api/features/UserInstaller/UserInstaller.d.ts +3 -1
  137. package/api/features/UserInstaller/UserInstaller.js +18 -3
  138. package/api/features/UserInstaller/UserInstaller.js.map +1 -1
  139. package/api/graphql/user.gql.js +68 -0
  140. package/api/graphql/user.gql.js.map +1 -1
  141. package/package.json +20 -20
@@ -1 +1 @@
1
- {"version":3,"file":"api/domain/errors.js","sources":["../../../src/api/domain/errors.ts"],"sourcesContent":["import { BaseError } from \"@webiny/feature/api\";\n\n/**\n * Error when a user already exists in Cognito User Pool\n */\nexport class CognitoAccountExistsError extends BaseError<{ email: string }> {\n override readonly code = \"Cognito/Account/Exists\" as const;\n\n constructor(email: string) {\n super({\n message: `An account with this email already exists in your Cognito User Pool.`,\n data: { email }\n });\n }\n}\n\n/**\n * Error when creating a user in Cognito fails\n */\nexport class CognitoCreateUserError extends BaseError<{ error: Error }> {\n override readonly code = \"Cognito/User/Create\" as const;\n\n constructor(error: Error) {\n super({\n message: `Failed to create user in Cognito: ${error.message}`,\n data: { error }\n });\n }\n}\n\n/**\n * Error when updating a user in Cognito fails\n */\nexport class CognitoUpdateUserError extends BaseError<{ error: Error }> {\n override readonly code = \"Cognito/User/Update\" as const;\n\n constructor(error: Error) {\n super({\n message: `Failed to update user in Cognito: ${error.message}`,\n data: { error }\n });\n }\n}\n\n/**\n * Error when deleting a user from Cognito fails\n */\nexport class CognitoDeleteUserError extends BaseError<{ error: Error }> {\n override readonly code = \"Cognito/User/Delete\" as const;\n\n constructor(error: Error) {\n super({\n message: `Failed to delete user from Cognito: ${error.message}`,\n data: { error }\n });\n }\n}\n"],"names":["CognitoAccountExistsError","BaseError","email","CognitoCreateUserError","error","CognitoUpdateUserError","CognitoDeleteUserError"],"mappings":";AAKO,MAAMA,kCAAkCC;IAG3C,YAAYC,KAAa,CAAE;QACvB,KAAK,CAAC;YACF,SAAS;YACT,MAAM;gBAAEA;YAAM;QAClB,SANc,IAAI,GAAG;IAOzB;AACJ;AAKO,MAAMC,+BAA+BF;IAGxC,YAAYG,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAAS,CAAC,kCAAkC,EAAEA,MAAM,OAAO,EAAE;YAC7D,MAAM;gBAAEA;YAAM;QAClB,SANc,IAAI,GAAG;IAOzB;AACJ;AAKO,MAAMC,+BAA+BJ;IAGxC,YAAYG,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAAS,CAAC,kCAAkC,EAAEA,MAAM,OAAO,EAAE;YAC7D,MAAM;gBAAEA;YAAM;QAClB,SANc,IAAI,GAAG;IAOzB;AACJ;AAKO,MAAME,+BAA+BL;IAGxC,YAAYG,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAAS,CAAC,oCAAoC,EAAEA,MAAM,OAAO,EAAE;YAC/D,MAAM;gBAAEA;YAAM;QAClB,SANc,IAAI,GAAG;IAOzB;AACJ"}
1
+ {"version":3,"file":"api/domain/errors.js","sources":["../../../src/api/domain/errors.ts"],"sourcesContent":["import { BaseError } from \"@webiny/feature/api\";\n\n/**\n * Error when a user already exists in Cognito User Pool\n */\nexport class CognitoAccountExistsError extends BaseError<{ email: string }> {\n override readonly code = \"Cognito/Account/Exists\" as const;\n\n constructor(email: string) {\n super({\n message: `An account with this email already exists in your Cognito User Pool.`,\n data: { email }\n });\n }\n}\n\n/**\n * Error when creating a user whose email already has an account in another tenant:\n * that account has to be linked to this tenant instead\n */\nexport class CognitoAccountInOtherTenantError extends BaseError<{ email: string }> {\n override readonly code = \"Cognito/Account/ExistsInOtherTenant\" as const;\n\n constructor(email: string) {\n super({\n message: `This email already has an account in another tenant. Link it instead.`,\n data: { email }\n });\n }\n}\n\n/**\n * Error when linking an email that has no account in the Cognito User Pool\n */\nexport class CognitoAccountNotFoundError extends BaseError<{ email: string }> {\n override readonly code = \"Cognito/Account/NotFound\" as const;\n\n constructor(email: string) {\n super({\n message: `There's no account with this email.`,\n data: { email }\n });\n }\n}\n\n/**\n * Error when loading an account from the Cognito User Pool fails\n */\nexport class CognitoGetUserError extends BaseError<{ error: Error }> {\n override readonly code = \"Cognito/User/Get\" as const;\n\n constructor(error: Error) {\n super({\n message: `Failed to load the account from Cognito: ${error.message}`,\n data: { error }\n });\n }\n}\n\n/**\n * Error when creating a user in Cognito fails\n */\nexport class CognitoCreateUserError extends BaseError<{ error: Error }> {\n override readonly code = \"Cognito/User/Create\" as const;\n\n constructor(error: Error) {\n super({\n message: `Failed to create user in Cognito: ${error.message}`,\n data: { error }\n });\n }\n}\n\n/**\n * Error when updating a user in Cognito fails\n */\nexport class CognitoUpdateUserError extends BaseError<{ error: Error }> {\n override readonly code = \"Cognito/User/Update\" as const;\n\n constructor(error: Error) {\n super({\n message: `Failed to update user in Cognito: ${error.message}`,\n data: { error }\n });\n }\n}\n\n/**\n * Error when updating a user fails and some tenants' records can't be put back,\n * so those records no longer match the Cognito account\n */\nexport class CognitoUpdateRollbackError extends BaseError<{\n error: Error;\n tenants: string[];\n rollbackErrors: Error[];\n}> {\n override readonly code = \"Cognito/User/UpdateRollback\" as const;\n\n constructor(error: Error, tenants: string[], rollbackErrors: Error[]) {\n super({\n message: `Failed to update user: ${error.message}. The user's records in tenants ${tenants.join(\", \")} could not be restored and no longer match the Cognito account.`,\n data: { error, tenants, rollbackErrors }\n });\n }\n}\n\n/**\n * Error when deleting a user from Cognito fails\n */\nexport class CognitoDeleteUserError extends BaseError<{ error: Error }> {\n override readonly code = \"Cognito/User/Delete\" as const;\n\n constructor(error: Error) {\n super({\n message: `Failed to delete user from Cognito: ${error.message}`,\n data: { error }\n });\n }\n}\n\n/**\n * Error when an administrator changes the sign-in details of an account that other tenants share\n */\nexport class CognitoSharedAccountError extends BaseError<{ id: string }> {\n override readonly code = \"Cognito/Account/Shared\" as const;\n\n constructor(id: string) {\n super({\n message: `This person's account is also used in other tenants, so only they can change its name, email and password.`,\n data: { id }\n });\n }\n}\n"],"names":["CognitoAccountExistsError","BaseError","email","CognitoAccountInOtherTenantError","CognitoAccountNotFoundError","CognitoGetUserError","error","CognitoCreateUserError","CognitoUpdateUserError","CognitoUpdateRollbackError","tenants","rollbackErrors","CognitoDeleteUserError","CognitoSharedAccountError","id"],"mappings":";AAKO,MAAMA,kCAAkCC;IAG3C,YAAYC,KAAa,CAAE;QACvB,KAAK,CAAC;YACF,SAAS;YACT,MAAM;gBAAEA;YAAM;QAClB,SANc,IAAI,GAAG;IAOzB;AACJ;AAMO,MAAMC,yCAAyCF;IAGlD,YAAYC,KAAa,CAAE;QACvB,KAAK,CAAC;YACF,SAAS;YACT,MAAM;gBAAEA;YAAM;QAClB,SANc,IAAI,GAAG;IAOzB;AACJ;AAKO,MAAME,oCAAoCH;IAG7C,YAAYC,KAAa,CAAE;QACvB,KAAK,CAAC;YACF,SAAS;YACT,MAAM;gBAAEA;YAAM;QAClB,SANc,IAAI,GAAG;IAOzB;AACJ;AAKO,MAAMG,4BAA4BJ;IAGrC,YAAYK,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAAS,CAAC,yCAAyC,EAAEA,MAAM,OAAO,EAAE;YACpE,MAAM;gBAAEA;YAAM;QAClB,SANc,IAAI,GAAG;IAOzB;AACJ;AAKO,MAAMC,+BAA+BN;IAGxC,YAAYK,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAAS,CAAC,kCAAkC,EAAEA,MAAM,OAAO,EAAE;YAC7D,MAAM;gBAAEA;YAAM;QAClB,SANc,IAAI,GAAG;IAOzB;AACJ;AAKO,MAAME,+BAA+BP;IAGxC,YAAYK,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAAS,CAAC,kCAAkC,EAAEA,MAAM,OAAO,EAAE;YAC7D,MAAM;gBAAEA;YAAM;QAClB,SANc,IAAI,GAAG;IAOzB;AACJ;AAMO,MAAMG,mCAAmCR;IAO5C,YAAYK,KAAY,EAAEI,OAAiB,EAAEC,cAAuB,CAAE;QAClE,KAAK,CAAC;YACF,SAAS,CAAC,uBAAuB,EAAEL,MAAM,OAAO,CAAC,gCAAgC,EAAEI,QAAQ,IAAI,CAAC,MAAM,+DAA+D,CAAC;YACtK,MAAM;gBAAEJ;gBAAOI;gBAASC;YAAe;QAC3C,SANc,IAAI,GAAG;IAOzB;AACJ;AAKO,MAAMC,+BAA+BX;IAGxC,YAAYK,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAAS,CAAC,oCAAoC,EAAEA,MAAM,OAAO,EAAE;YAC/D,MAAM;gBAAEA;YAAM;QAClB,SANc,IAAI,GAAG;IAOzB;AACJ;AAKO,MAAMO,kCAAkCZ;IAG3C,YAAYa,EAAU,CAAE;QACpB,KAAK,CAAC;YACF,SAAS;YACT,MAAM;gBAAEA;YAAG;QACf,SANc,IAAI,GAAG;IAOzB;AACJ"}
@@ -0,0 +1,16 @@
1
+ import { Result } from "@webiny/feature/api";
2
+ import { AdminUsersRepository } from "@webiny/api-core/features/users/shared/abstractions.js";
3
+ import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
4
+ import { CheckEmailUseCase as UseCaseAbstraction } from "./abstractions.js";
5
+ import { CognitoService } from "../../../api/features/CognitoService/index.js";
6
+ declare class CheckEmailUseCaseImpl implements UseCaseAbstraction.Interface {
7
+ private identityContext;
8
+ private cognitoService;
9
+ private repository;
10
+ constructor(identityContext: IdentityContext.Interface, cognitoService: CognitoService.Interface, repository: AdminUsersRepository.Interface);
11
+ execute(email: string): Promise<Result<UseCaseAbstraction.Status, UseCaseAbstraction.Error>>;
12
+ }
13
+ export declare const CheckEmailUseCase: typeof CheckEmailUseCaseImpl & {
14
+ __abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").ICheckEmailUseCase>;
15
+ };
16
+ export {};
@@ -0,0 +1,47 @@
1
+ import { z } from "zod";
2
+ import { Result } from "@webiny/feature/api";
3
+ import { AdminUsersRepository } from "@webiny/api-core/features/users/shared/abstractions.js";
4
+ import { NotAuthorizedError, UserValidationError } from "@webiny/api-core/features/users/shared/errors.js";
5
+ import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
6
+ import { CheckEmailUseCase } from "./abstractions.js";
7
+ import { Username } from "../../domain/Username.js";
8
+ import { CognitoGetUserError } from "../../domain/errors.js";
9
+ import { CognitoService } from "../CognitoService/index.js";
10
+ const emailValidation = z.string().email();
11
+ class CheckEmailUseCaseImpl {
12
+ constructor(identityContext, cognitoService, repository){
13
+ this.identityContext = identityContext;
14
+ this.cognitoService = cognitoService;
15
+ this.repository = repository;
16
+ }
17
+ async execute(email) {
18
+ const permission = await this.identityContext.getPermission("adminUsers.user");
19
+ if (!permission) return Result.fail(new NotAuthorizedError());
20
+ const validation = emailValidation.safeParse(email);
21
+ if (!validation.success) return Result.fail(new UserValidationError(validation.error.issues[0].message));
22
+ const existingUserResult = await this.repository.get({
23
+ email
24
+ });
25
+ if (existingUserResult.isOk()) return Result.ok("EXISTS_HERE");
26
+ try {
27
+ const cognitoUser = await this.cognitoService.getUser(Username.fromUser({
28
+ email
29
+ }));
30
+ if (cognitoUser?.attributes["custom:id"]) return Result.ok("EXISTS_ELSEWHERE");
31
+ } catch (error) {
32
+ return Result.fail(new CognitoGetUserError(error));
33
+ }
34
+ return Result.ok("AVAILABLE");
35
+ }
36
+ }
37
+ const CheckEmailUseCase_CheckEmailUseCase = CheckEmailUseCase.createImplementation({
38
+ implementation: CheckEmailUseCaseImpl,
39
+ dependencies: [
40
+ IdentityContext,
41
+ CognitoService,
42
+ AdminUsersRepository
43
+ ]
44
+ });
45
+ export { CheckEmailUseCase_CheckEmailUseCase as CheckEmailUseCase };
46
+
47
+ //# sourceMappingURL=CheckEmailUseCase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api/features/CheckEmail/CheckEmailUseCase.js","sources":["../../../../src/api/features/CheckEmail/CheckEmailUseCase.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { Result } from \"@webiny/feature/api\";\nimport { AdminUsersRepository } from \"@webiny/api-core/features/users/shared/abstractions.js\";\nimport {\n NotAuthorizedError,\n UserValidationError\n} from \"@webiny/api-core/features/users/shared/errors.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { CheckEmailUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { Username } from \"~/api/domain/Username.js\";\nimport { CognitoGetUserError } from \"~/api/domain/errors.js\";\nimport { CognitoService } from \"~/api/features/CognitoService/index.js\";\n\nconst emailValidation = z.string().email();\n\nclass CheckEmailUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private cognitoService: CognitoService.Interface,\n private repository: AdminUsersRepository.Interface\n ) {}\n\n async execute(\n email: string\n ): Promise<Result<UseCaseAbstraction.Status, UseCaseAbstraction.Error>> {\n const permission = await this.identityContext.getPermission(\"adminUsers.user\");\n if (!permission) {\n return Result.fail(new NotAuthorizedError());\n }\n\n const validation = emailValidation.safeParse(email);\n if (!validation.success) {\n return Result.fail(new UserValidationError(validation.error.issues[0].message));\n }\n\n const existingUserResult = await this.repository.get({ email });\n if (existingUserResult.isOk()) {\n return Result.ok(\"EXISTS_HERE\");\n }\n\n try {\n const cognitoUser = await this.cognitoService.getUser(Username.fromUser({ email }));\n // Only an account with a user ID can be linked. Any other account makes\n // creating the user fail, as it always has.\n if (cognitoUser?.attributes[\"custom:id\"]) {\n return Result.ok(\"EXISTS_ELSEWHERE\");\n }\n } catch (error) {\n return Result.fail(new CognitoGetUserError(error as Error));\n }\n\n return Result.ok(\"AVAILABLE\");\n }\n}\n\nexport const CheckEmailUseCase = UseCaseAbstraction.createImplementation({\n implementation: CheckEmailUseCaseImpl,\n dependencies: [IdentityContext, CognitoService, AdminUsersRepository]\n});\n"],"names":["emailValidation","z","CheckEmailUseCaseImpl","identityContext","cognitoService","repository","email","permission","Result","NotAuthorizedError","validation","UserValidationError","existingUserResult","cognitoUser","Username","error","CognitoGetUserError","CheckEmailUseCase","UseCaseAbstraction","IdentityContext","CognitoService","AdminUsersRepository"],"mappings":";;;;;;;;;AAaA,MAAMA,kBAAkBC,EAAE,MAAM,GAAG,KAAK;AAExC,MAAMC;IACF,YACYC,eAA0C,EAC1CC,cAAwC,EACxCC,UAA0C,CACpD;aAHUF,eAAe,GAAfA;aACAC,cAAc,GAAdA;aACAC,UAAU,GAAVA;IACT;IAEH,MAAM,QACFC,KAAa,EACuD;QACpE,MAAMC,aAAa,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC;QAC5D,IAAI,CAACA,YACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAMC,aAAaV,gBAAgB,SAAS,CAACM;QAC7C,IAAI,CAACI,WAAW,OAAO,EACnB,OAAOF,OAAO,IAAI,CAAC,IAAIG,oBAAoBD,WAAW,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO;QAGjF,MAAME,qBAAqB,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;YAAEN;QAAM;QAC7D,IAAIM,mBAAmB,IAAI,IACvB,OAAOJ,OAAO,EAAE,CAAC;QAGrB,IAAI;YACA,MAAMK,cAAc,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAACC,SAAS,QAAQ,CAAC;gBAAER;YAAM;YAGhF,IAAIO,aAAa,UAAU,CAAC,YAAY,EACpC,OAAOL,OAAO,EAAE,CAAC;QAEzB,EAAE,OAAOO,OAAO;YACZ,OAAOP,OAAO,IAAI,CAAC,IAAIQ,oBAAoBD;QAC/C;QAEA,OAAOP,OAAO,EAAE,CAAC;IACrB;AACJ;AAEO,MAAMS,sCAAoBC,kBAAAA,oBAAuC,CAAC;IACrE,gBAAgBhB;IAChB,cAAc;QAACiB;QAAiBC;QAAgBC;KAAqB;AACzE"}
@@ -0,0 +1,29 @@
1
+ import type { Result } from "@webiny/feature/api";
2
+ import type { NotAuthorizedError, UserValidationError } from "@webiny/api-core/features/users/shared/errors.js";
3
+ import type { CognitoGetUserError } from "../../../api/domain/errors.js";
4
+ /**
5
+ * - `AVAILABLE`: a new user can be created with this email.
6
+ * - `EXISTS_HERE`: the current tenant already has a user with this email.
7
+ * - `EXISTS_ELSEWHERE`: the email has an account in another tenant, which can be linked here.
8
+ */
9
+ export type EmailStatus = "AVAILABLE" | "EXISTS_HERE" | "EXISTS_ELSEWHERE";
10
+ export interface ICheckEmailUseCaseErrors {
11
+ authorization: NotAuthorizedError;
12
+ validation: UserValidationError;
13
+ cognito: CognitoGetUserError;
14
+ }
15
+ type CheckEmailError = ICheckEmailUseCaseErrors[keyof ICheckEmailUseCaseErrors];
16
+ /**
17
+ * Tells an administrator whether an email can be used for a new user in the current tenant.
18
+ * It only says whether an account exists elsewhere, never in which tenants.
19
+ */
20
+ export interface ICheckEmailUseCase {
21
+ execute(email: string): Promise<Result<EmailStatus, CheckEmailError>>;
22
+ }
23
+ export declare const CheckEmailUseCase: import("@webiny/di").Abstraction<ICheckEmailUseCase>;
24
+ export declare namespace CheckEmailUseCase {
25
+ type Interface = ICheckEmailUseCase;
26
+ type Status = EmailStatus;
27
+ type Error = CheckEmailError;
28
+ }
29
+ export {};
@@ -0,0 +1,5 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ const CheckEmailUseCase = createAbstraction("CheckEmailUseCase");
3
+ export { CheckEmailUseCase };
4
+
5
+ //# sourceMappingURL=abstractions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api/features/CheckEmail/abstractions.js","sources":["../../../../src/api/features/CheckEmail/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Result } from \"@webiny/feature/api\";\nimport type {\n NotAuthorizedError,\n UserValidationError\n} from \"@webiny/api-core/features/users/shared/errors.js\";\nimport type { CognitoGetUserError } from \"~/api/domain/errors.js\";\n\n/**\n * - `AVAILABLE`: a new user can be created with this email.\n * - `EXISTS_HERE`: the current tenant already has a user with this email.\n * - `EXISTS_ELSEWHERE`: the email has an account in another tenant, which can be linked here.\n */\nexport type EmailStatus = \"AVAILABLE\" | \"EXISTS_HERE\" | \"EXISTS_ELSEWHERE\";\n\nexport interface ICheckEmailUseCaseErrors {\n authorization: NotAuthorizedError;\n validation: UserValidationError;\n cognito: CognitoGetUserError;\n}\n\ntype CheckEmailError = ICheckEmailUseCaseErrors[keyof ICheckEmailUseCaseErrors];\n\n/**\n * Tells an administrator whether an email can be used for a new user in the current tenant.\n * It only says whether an account exists elsewhere, never in which tenants.\n */\nexport interface ICheckEmailUseCase {\n execute(email: string): Promise<Result<EmailStatus, CheckEmailError>>;\n}\n\nexport const CheckEmailUseCase = createAbstraction<ICheckEmailUseCase>(\"CheckEmailUseCase\");\n\nexport namespace CheckEmailUseCase {\n export type Interface = ICheckEmailUseCase;\n export type Status = EmailStatus;\n export type Error = CheckEmailError;\n}\n"],"names":["CheckEmailUseCase","createAbstraction"],"mappings":";AA+BO,MAAMA,oBAAoBC,kBAAsC"}
@@ -0,0 +1,4 @@
1
+ export declare const CheckEmailFeature: {
2
+ name: string;
3
+ register(container: import("@webiny/di").Container): void;
4
+ };
@@ -0,0 +1,11 @@
1
+ import { createFeature } from "@webiny/feature/api";
2
+ import { CheckEmailUseCase } from "./CheckEmailUseCase.js";
3
+ const CheckEmailFeature = createFeature({
4
+ name: "CheckEmailFeature",
5
+ register (container) {
6
+ container.register(CheckEmailUseCase);
7
+ }
8
+ });
9
+ export { CheckEmailFeature };
10
+
11
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api/features/CheckEmail/feature.js","sources":["../../../../src/api/features/CheckEmail/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { CheckEmailUseCase } from \"./CheckEmailUseCase.js\";\n\nexport const CheckEmailFeature = createFeature({\n name: \"CheckEmailFeature\",\n register(container) {\n container.register(CheckEmailUseCase);\n }\n});\n"],"names":["CheckEmailFeature","createFeature","container","CheckEmailUseCase"],"mappings":";;AAGO,MAAMA,oBAAoBC,cAAc;IAC3C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
@@ -0,0 +1,2 @@
1
+ export * from "./abstractions.js";
2
+ export * from "./feature.js";
@@ -0,0 +1,2 @@
1
+ export * from "./abstractions.js";
2
+ export * from "./feature.js";
@@ -3,7 +3,7 @@ declare class CognitoServiceImpl implements ServiceAbstraction.Interface {
3
3
  private config;
4
4
  private cognito;
5
5
  constructor(config: CognitoConfig.Interface);
6
- userExists(username: string): Promise<boolean>;
6
+ getUser(username: string): Promise<ServiceAbstraction.User | null>;
7
7
  createUser(params: {
8
8
  username: string;
9
9
  temporaryPassword: string;
@@ -7,15 +7,21 @@ class CognitoServiceImpl {
7
7
  region: config.region
8
8
  });
9
9
  }
10
- async userExists(username) {
10
+ async getUser(username) {
11
11
  try {
12
- await this.cognito.adminGetUser({
12
+ const response = await this.cognito.adminGetUser({
13
13
  Username: username,
14
14
  UserPoolId: this.config.userPoolId
15
15
  });
16
- return true;
17
- } catch {
18
- return false;
16
+ const attributes = {};
17
+ for (const attribute of response.UserAttributes ?? [])if (attribute.Name) attributes[attribute.Name] = attribute.Value ?? "";
18
+ return {
19
+ username: response.Username ?? username,
20
+ attributes
21
+ };
22
+ } catch (error) {
23
+ if ("UserNotFoundException" === error.name) return null;
24
+ throw error;
19
25
  }
20
26
  }
21
27
  async createUser(params) {
@@ -1 +1 @@
1
- {"version":3,"file":"api/features/CognitoService/CognitoService.js","sources":["../../../../src/api/features/CognitoService/CognitoService.ts"],"sourcesContent":["import type { AdminCreateUserRequest } from \"@webiny/aws-sdk/client-cognito-identity-provider/index.js\";\nimport { CognitoIdentityProvider } from \"@webiny/aws-sdk/client-cognito-identity-provider/index.js\";\nimport { CognitoConfig, CognitoService as ServiceAbstraction } from \"./abstractions.js\";\n\nclass CognitoServiceImpl implements ServiceAbstraction.Interface {\n private cognito: CognitoIdentityProvider;\n\n constructor(private config: CognitoConfig.Interface) {\n this.cognito = new CognitoIdentityProvider({ region: config.region });\n }\n\n async userExists(username: string): Promise<boolean> {\n try {\n await this.cognito.adminGetUser({\n Username: username,\n UserPoolId: this.config.userPoolId\n });\n return true;\n } catch {\n // User does not exist\n return false;\n }\n }\n\n async createUser(params: {\n username: string;\n temporaryPassword: string;\n attributes: ServiceAbstraction.UserAttributes;\n }): Promise<void> {\n const createUserParams: AdminCreateUserRequest = {\n UserPoolId: this.config.userPoolId,\n Username: params.username,\n DesiredDeliveryMediums: [],\n ForceAliasCreation: false,\n MessageAction: \"SUPPRESS\",\n TemporaryPassword: params.temporaryPassword,\n UserAttributes: [\n {\n Name: \"given_name\",\n Value: params.attributes.givenName || \"\"\n },\n {\n Name: \"family_name\",\n Value: params.attributes.familyName || \"\"\n },\n {\n Name: \"preferred_username\",\n Value: params.attributes.preferredUsername\n },\n {\n Name: \"email\",\n Value: params.attributes.email\n },\n {\n Name: \"custom:id\",\n Value: params.attributes.customId\n }\n ]\n };\n\n await this.cognito.adminCreateUser(createUserParams);\n }\n\n async setEmailVerified(username: string): Promise<void> {\n await this.cognito.adminUpdateUserAttributes({\n UserPoolId: this.config.userPoolId,\n Username: username,\n UserAttributes: [\n {\n Name: \"email_verified\",\n Value: \"true\"\n }\n ]\n });\n }\n\n async setPermanentPassword(username: string, password: string): Promise<void> {\n await this.cognito.adminSetUserPassword({\n Permanent: true,\n Password: password,\n Username: username,\n UserPoolId: this.config.userPoolId\n });\n }\n\n async updateUserAttributes(\n username: string,\n attributes: Record<string, string>\n ): Promise<void> {\n const userAttributes = Object.entries(attributes).map(([name, value]) => ({\n Name: name,\n Value: value\n }));\n\n await this.cognito.adminUpdateUserAttributes({\n UserPoolId: this.config.userPoolId,\n Username: username,\n UserAttributes: userAttributes\n });\n }\n\n async deleteUser(username: string): Promise<void> {\n await this.cognito.adminDeleteUser({\n UserPoolId: this.config.userPoolId,\n Username: username\n });\n }\n}\n\nexport const CognitoService = ServiceAbstraction.createImplementation({\n implementation: CognitoServiceImpl,\n dependencies: [CognitoConfig]\n});\n"],"names":["CognitoServiceImpl","config","CognitoIdentityProvider","username","params","createUserParams","password","attributes","userAttributes","Object","name","value","CognitoService","ServiceAbstraction","CognitoConfig"],"mappings":";;AAIA,MAAMA;IAGF,YAAoBC,MAA+B,CAAE;aAAjCA,MAAM,GAANA;QAChB,IAAI,CAAC,OAAO,GAAG,IAAIC,wBAAwB;YAAE,QAAQD,OAAO,MAAM;QAAC;IACvE;IAEA,MAAM,WAAWE,QAAgB,EAAoB;QACjD,IAAI;YACA,MAAM,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC;gBAC5B,UAAUA;gBACV,YAAY,IAAI,CAAC,MAAM,CAAC,UAAU;YACtC;YACA,OAAO;QACX,EAAE,OAAM;YAEJ,OAAO;QACX;IACJ;IAEA,MAAM,WAAWC,MAIhB,EAAiB;QACd,MAAMC,mBAA2C;YAC7C,YAAY,IAAI,CAAC,MAAM,CAAC,UAAU;YAClC,UAAUD,OAAO,QAAQ;YACzB,wBAAwB,EAAE;YAC1B,oBAAoB;YACpB,eAAe;YACf,mBAAmBA,OAAO,iBAAiB;YAC3C,gBAAgB;gBACZ;oBACI,MAAM;oBACN,OAAOA,OAAO,UAAU,CAAC,SAAS,IAAI;gBAC1C;gBACA;oBACI,MAAM;oBACN,OAAOA,OAAO,UAAU,CAAC,UAAU,IAAI;gBAC3C;gBACA;oBACI,MAAM;oBACN,OAAOA,OAAO,UAAU,CAAC,iBAAiB;gBAC9C;gBACA;oBACI,MAAM;oBACN,OAAOA,OAAO,UAAU,CAAC,KAAK;gBAClC;gBACA;oBACI,MAAM;oBACN,OAAOA,OAAO,UAAU,CAAC,QAAQ;gBACrC;aACH;QACL;QAEA,MAAM,IAAI,CAAC,OAAO,CAAC,eAAe,CAACC;IACvC;IAEA,MAAM,iBAAiBF,QAAgB,EAAiB;QACpD,MAAM,IAAI,CAAC,OAAO,CAAC,yBAAyB,CAAC;YACzC,YAAY,IAAI,CAAC,MAAM,CAAC,UAAU;YAClC,UAAUA;YACV,gBAAgB;gBACZ;oBACI,MAAM;oBACN,OAAO;gBACX;aACH;QACL;IACJ;IAEA,MAAM,qBAAqBA,QAAgB,EAAEG,QAAgB,EAAiB;QAC1E,MAAM,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC;YACpC,WAAW;YACX,UAAUA;YACV,UAAUH;YACV,YAAY,IAAI,CAAC,MAAM,CAAC,UAAU;QACtC;IACJ;IAEA,MAAM,qBACFA,QAAgB,EAChBI,UAAkC,EACrB;QACb,MAAMC,iBAAiBC,OAAO,OAAO,CAACF,YAAY,GAAG,CAAC,CAAC,CAACG,MAAMC,MAAM,GAAM;gBACtE,MAAMD;gBACN,OAAOC;YACX;QAEA,MAAM,IAAI,CAAC,OAAO,CAAC,yBAAyB,CAAC;YACzC,YAAY,IAAI,CAAC,MAAM,CAAC,UAAU;YAClC,UAAUR;YACV,gBAAgBK;QACpB;IACJ;IAEA,MAAM,WAAWL,QAAgB,EAAiB;QAC9C,MAAM,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC;YAC/B,YAAY,IAAI,CAAC,MAAM,CAAC,UAAU;YAClC,UAAUA;QACd;IACJ;AACJ;AAEO,MAAMS,gCAAiBC,eAAAA,oBAAuC,CAAC;IAClE,gBAAgBb;IAChB,cAAc;QAACc;KAAc;AACjC"}
1
+ {"version":3,"file":"api/features/CognitoService/CognitoService.js","sources":["../../../../src/api/features/CognitoService/CognitoService.ts"],"sourcesContent":["import type { AdminCreateUserRequest } from \"@webiny/aws-sdk/client-cognito-identity-provider/index.js\";\nimport { CognitoIdentityProvider } from \"@webiny/aws-sdk/client-cognito-identity-provider/index.js\";\nimport { CognitoConfig, CognitoService as ServiceAbstraction } from \"./abstractions.js\";\n\nclass CognitoServiceImpl implements ServiceAbstraction.Interface {\n private cognito: CognitoIdentityProvider;\n\n constructor(private config: CognitoConfig.Interface) {\n this.cognito = new CognitoIdentityProvider({ region: config.region });\n }\n\n async getUser(username: string): Promise<ServiceAbstraction.User | null> {\n try {\n const response = await this.cognito.adminGetUser({\n Username: username,\n UserPoolId: this.config.userPoolId\n });\n\n const attributes: Record<string, string> = {};\n for (const attribute of response.UserAttributes ?? []) {\n if (attribute.Name) {\n attributes[attribute.Name] = attribute.Value ?? \"\";\n }\n }\n\n return { username: response.Username ?? username, attributes };\n } catch (error) {\n if ((error as Error).name === \"UserNotFoundException\") {\n return null;\n }\n throw error;\n }\n }\n\n async createUser(params: {\n username: string;\n temporaryPassword: string;\n attributes: ServiceAbstraction.UserAttributes;\n }): Promise<void> {\n const createUserParams: AdminCreateUserRequest = {\n UserPoolId: this.config.userPoolId,\n Username: params.username,\n DesiredDeliveryMediums: [],\n ForceAliasCreation: false,\n MessageAction: \"SUPPRESS\",\n TemporaryPassword: params.temporaryPassword,\n UserAttributes: [\n {\n Name: \"given_name\",\n Value: params.attributes.givenName || \"\"\n },\n {\n Name: \"family_name\",\n Value: params.attributes.familyName || \"\"\n },\n {\n Name: \"preferred_username\",\n Value: params.attributes.preferredUsername\n },\n {\n Name: \"email\",\n Value: params.attributes.email\n },\n {\n Name: \"custom:id\",\n Value: params.attributes.customId\n }\n ]\n };\n\n await this.cognito.adminCreateUser(createUserParams);\n }\n\n async setEmailVerified(username: string): Promise<void> {\n await this.cognito.adminUpdateUserAttributes({\n UserPoolId: this.config.userPoolId,\n Username: username,\n UserAttributes: [\n {\n Name: \"email_verified\",\n Value: \"true\"\n }\n ]\n });\n }\n\n async setPermanentPassword(username: string, password: string): Promise<void> {\n await this.cognito.adminSetUserPassword({\n Permanent: true,\n Password: password,\n Username: username,\n UserPoolId: this.config.userPoolId\n });\n }\n\n async updateUserAttributes(\n username: string,\n attributes: Record<string, string>\n ): Promise<void> {\n const userAttributes = Object.entries(attributes).map(([name, value]) => ({\n Name: name,\n Value: value\n }));\n\n await this.cognito.adminUpdateUserAttributes({\n UserPoolId: this.config.userPoolId,\n Username: username,\n UserAttributes: userAttributes\n });\n }\n\n async deleteUser(username: string): Promise<void> {\n await this.cognito.adminDeleteUser({\n UserPoolId: this.config.userPoolId,\n Username: username\n });\n }\n}\n\nexport const CognitoService = ServiceAbstraction.createImplementation({\n implementation: CognitoServiceImpl,\n dependencies: [CognitoConfig]\n});\n"],"names":["CognitoServiceImpl","config","CognitoIdentityProvider","username","response","attributes","attribute","error","params","createUserParams","password","userAttributes","Object","name","value","CognitoService","ServiceAbstraction","CognitoConfig"],"mappings":";;AAIA,MAAMA;IAGF,YAAoBC,MAA+B,CAAE;aAAjCA,MAAM,GAANA;QAChB,IAAI,CAAC,OAAO,GAAG,IAAIC,wBAAwB;YAAE,QAAQD,OAAO,MAAM;QAAC;IACvE;IAEA,MAAM,QAAQE,QAAgB,EAA2C;QACrE,IAAI;YACA,MAAMC,WAAW,MAAM,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC;gBAC7C,UAAUD;gBACV,YAAY,IAAI,CAAC,MAAM,CAAC,UAAU;YACtC;YAEA,MAAME,aAAqC,CAAC;YAC5C,KAAK,MAAMC,aAAaF,SAAS,cAAc,IAAI,EAAE,CACjD,IAAIE,UAAU,IAAI,EACdD,UAAU,CAACC,UAAU,IAAI,CAAC,GAAGA,UAAU,KAAK,IAAI;YAIxD,OAAO;gBAAE,UAAUF,SAAS,QAAQ,IAAID;gBAAUE;YAAW;QACjE,EAAE,OAAOE,OAAO;YACZ,IAAKA,AAAyB,4BAAzBA,MAAgB,IAAI,EACrB,OAAO;YAEX,MAAMA;QACV;IACJ;IAEA,MAAM,WAAWC,MAIhB,EAAiB;QACd,MAAMC,mBAA2C;YAC7C,YAAY,IAAI,CAAC,MAAM,CAAC,UAAU;YAClC,UAAUD,OAAO,QAAQ;YACzB,wBAAwB,EAAE;YAC1B,oBAAoB;YACpB,eAAe;YACf,mBAAmBA,OAAO,iBAAiB;YAC3C,gBAAgB;gBACZ;oBACI,MAAM;oBACN,OAAOA,OAAO,UAAU,CAAC,SAAS,IAAI;gBAC1C;gBACA;oBACI,MAAM;oBACN,OAAOA,OAAO,UAAU,CAAC,UAAU,IAAI;gBAC3C;gBACA;oBACI,MAAM;oBACN,OAAOA,OAAO,UAAU,CAAC,iBAAiB;gBAC9C;gBACA;oBACI,MAAM;oBACN,OAAOA,OAAO,UAAU,CAAC,KAAK;gBAClC;gBACA;oBACI,MAAM;oBACN,OAAOA,OAAO,UAAU,CAAC,QAAQ;gBACrC;aACH;QACL;QAEA,MAAM,IAAI,CAAC,OAAO,CAAC,eAAe,CAACC;IACvC;IAEA,MAAM,iBAAiBN,QAAgB,EAAiB;QACpD,MAAM,IAAI,CAAC,OAAO,CAAC,yBAAyB,CAAC;YACzC,YAAY,IAAI,CAAC,MAAM,CAAC,UAAU;YAClC,UAAUA;YACV,gBAAgB;gBACZ;oBACI,MAAM;oBACN,OAAO;gBACX;aACH;QACL;IACJ;IAEA,MAAM,qBAAqBA,QAAgB,EAAEO,QAAgB,EAAiB;QAC1E,MAAM,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC;YACpC,WAAW;YACX,UAAUA;YACV,UAAUP;YACV,YAAY,IAAI,CAAC,MAAM,CAAC,UAAU;QACtC;IACJ;IAEA,MAAM,qBACFA,QAAgB,EAChBE,UAAkC,EACrB;QACb,MAAMM,iBAAiBC,OAAO,OAAO,CAACP,YAAY,GAAG,CAAC,CAAC,CAACQ,MAAMC,MAAM,GAAM;gBACtE,MAAMD;gBACN,OAAOC;YACX;QAEA,MAAM,IAAI,CAAC,OAAO,CAAC,yBAAyB,CAAC;YACzC,YAAY,IAAI,CAAC,MAAM,CAAC,UAAU;YAClC,UAAUX;YACV,gBAAgBQ;QACpB;IACJ;IAEA,MAAM,WAAWR,QAAgB,EAAiB;QAC9C,MAAM,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC;YAC/B,YAAY,IAAI,CAAC,MAAM,CAAC,UAAU;YAClC,UAAUA;QACd;IACJ;AACJ;AAEO,MAAMY,gCAAiBC,eAAAA,oBAAuC,CAAC;IAClE,gBAAgBhB;IAChB,cAAc;QAACiB;KAAc;AACjC"}
@@ -17,11 +17,16 @@ export interface CognitoUserAttributes {
17
17
  email: string;
18
18
  customId: string;
19
19
  }
20
+ export interface CognitoUser {
21
+ username: string;
22
+ /** The account's attributes by name: `email`, `given_name`, `custom:id`, ... */
23
+ attributes: Record<string, string>;
24
+ }
20
25
  export interface ICognitoService {
21
26
  /**
22
- * Check if a user exists in Cognito User Pool
27
+ * Load a user from Cognito User Pool, or `null` if there's no account with this username.
23
28
  */
24
- userExists(username: string): Promise<boolean>;
29
+ getUser(username: string): Promise<CognitoUser | null>;
25
30
  /**
26
31
  * Create a new user in Cognito User Pool
27
32
  */
@@ -51,4 +56,5 @@ export declare const CognitoService: import("@webiny/di").Abstraction<ICognitoSe
51
56
  export declare namespace CognitoService {
52
57
  type Interface = ICognitoService;
53
58
  type UserAttributes = CognitoUserAttributes;
59
+ type User = CognitoUser;
54
60
  }
@@ -1 +1 @@
1
- {"version":3,"file":"api/features/CognitoService/abstractions.js","sources":["../../../../src/api/features/CognitoService/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { BaseUserAttributes } from \"@webiny/api-core/types/users.js\";\n\nexport interface AttributeGetter {\n (user: BaseUserAttributes): string;\n}\n\nexport interface ICognitoConfig {\n region: string;\n userPoolId: string;\n}\n\nexport const CognitoConfig = createAbstraction<ICognitoConfig>(\"CognitoConfig\");\n\nexport namespace CognitoConfig {\n export type Interface = ICognitoConfig;\n}\n\n// Cognito Service\n\nexport interface CognitoUserAttributes {\n givenName?: string;\n familyName?: string;\n preferredUsername: string;\n email: string;\n customId: string;\n}\n\nexport interface ICognitoService {\n /**\n * Check if a user exists in Cognito User Pool\n */\n userExists(username: string): Promise<boolean>;\n\n /**\n * Create a new user in Cognito User Pool\n */\n createUser(params: {\n username: string;\n temporaryPassword: string;\n attributes: CognitoUserAttributes;\n }): Promise<void>;\n\n /**\n * Set email as verified for a user\n */\n setEmailVerified(username: string): Promise<void>;\n\n /**\n * Set a permanent password for a user\n */\n setPermanentPassword(username: string, password: string): Promise<void>;\n\n /**\n * Update user attributes in Cognito\n */\n updateUserAttributes(username: string, attributes: Record<string, string>): Promise<void>;\n\n /**\n * Delete a user from Cognito User Pool\n */\n deleteUser(username: string): Promise<void>;\n}\n\nexport const CognitoService = createAbstraction<ICognitoService>(\"CognitoService\");\nexport namespace CognitoService {\n export type Interface = ICognitoService;\n export type UserAttributes = CognitoUserAttributes;\n}\n"],"names":["CognitoConfig","createAbstraction","CognitoService"],"mappings":";AAYO,MAAMA,gBAAgBC,kBAAkC;AAoDxD,MAAMC,iBAAiBD,kBAAmC"}
1
+ {"version":3,"file":"api/features/CognitoService/abstractions.js","sources":["../../../../src/api/features/CognitoService/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { BaseUserAttributes } from \"@webiny/api-core/types/users.js\";\n\nexport interface AttributeGetter {\n (user: BaseUserAttributes): string;\n}\n\nexport interface ICognitoConfig {\n region: string;\n userPoolId: string;\n}\n\nexport const CognitoConfig = createAbstraction<ICognitoConfig>(\"CognitoConfig\");\n\nexport namespace CognitoConfig {\n export type Interface = ICognitoConfig;\n}\n\n// Cognito Service\n\nexport interface CognitoUserAttributes {\n givenName?: string;\n familyName?: string;\n preferredUsername: string;\n email: string;\n customId: string;\n}\n\nexport interface CognitoUser {\n username: string;\n /** The account's attributes by name: `email`, `given_name`, `custom:id`, ... */\n attributes: Record<string, string>;\n}\n\nexport interface ICognitoService {\n /**\n * Load a user from Cognito User Pool, or `null` if there's no account with this username.\n */\n getUser(username: string): Promise<CognitoUser | null>;\n\n /**\n * Create a new user in Cognito User Pool\n */\n createUser(params: {\n username: string;\n temporaryPassword: string;\n attributes: CognitoUserAttributes;\n }): Promise<void>;\n\n /**\n * Set email as verified for a user\n */\n setEmailVerified(username: string): Promise<void>;\n\n /**\n * Set a permanent password for a user\n */\n setPermanentPassword(username: string, password: string): Promise<void>;\n\n /**\n * Update user attributes in Cognito\n */\n updateUserAttributes(username: string, attributes: Record<string, string>): Promise<void>;\n\n /**\n * Delete a user from Cognito User Pool\n */\n deleteUser(username: string): Promise<void>;\n}\n\nexport const CognitoService = createAbstraction<ICognitoService>(\"CognitoService\");\nexport namespace CognitoService {\n export type Interface = ICognitoService;\n export type UserAttributes = CognitoUserAttributes;\n export type User = CognitoUser;\n}\n"],"names":["CognitoConfig","createAbstraction","CognitoService"],"mappings":";AAYO,MAAMA,gBAAgBC,kBAAkC;AA0DxD,MAAMC,iBAAiBD,kBAAmC"}
@@ -1,6 +1,5 @@
1
1
  import { Result } from "@webiny/feature/api";
2
2
  import { AdminUsersRepository } from "@webiny/api-core/features/users/shared/abstractions.js";
3
- import type { AdminUser } from "@webiny/api-core/types/users.js";
4
3
  import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
5
4
  import { CreateUserUseCase as CoreCreateUser } from "@webiny/api-core/features/users/CreateUser/index.js";
6
5
  import { ListUsersUseCase } from "@webiny/api-core/features/users/ListUsers/index.js";
@@ -14,7 +13,7 @@ declare class CreateUserUseCaseImpl implements UseCaseAbstraction.Interface {
14
13
  private listUsersUseCase;
15
14
  private repository;
16
15
  constructor(identityContext: IdentityContext.Interface, cognitoService: CognitoService.Interface, createUserUseCase: CoreCreateUser.Interface, listUsersUseCase: ListUsersUseCase.Interface, repository: AdminUsersRepository.Interface);
17
- execute(input: CreateAdminUserInput): Promise<Result<AdminUser, UseCaseAbstraction.Error>>;
16
+ execute(input: CreateAdminUserInput): Promise<Result<UseCaseAbstraction.Output, UseCaseAbstraction.Error>>;
18
17
  }
19
18
  export declare const CreateUserUseCase: typeof CreateUserUseCaseImpl & {
20
19
  __abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").ICreateUserUseCase>;
@@ -6,7 +6,7 @@ import { CreateUserUseCase } from "@webiny/api-core/features/users/CreateUser/in
6
6
  import { ListUsersUseCase } from "@webiny/api-core/features/users/ListUsers/index.js";
7
7
  import { CreateUserUseCase as external_abstractions_js_CreateUserUseCase } from "./abstractions.js";
8
8
  import { Username } from "../../domain/Username.js";
9
- import { CognitoAccountExistsError, CognitoCreateUserError } from "../../domain/errors.js";
9
+ import { CognitoAccountExistsError, CognitoAccountInOtherTenantError, CognitoCreateUserError } from "../../domain/errors.js";
10
10
  import { createAdminUserValidation } from "./schema.js";
11
11
  import { CognitoService } from "../CognitoService/index.js";
12
12
  class CreateUserUseCaseImpl {
@@ -31,8 +31,8 @@ class CreateUserUseCaseImpl {
31
31
  if (existingUserResult.isOk()) return Result.fail(new CognitoAccountExistsError(data.email));
32
32
  let user;
33
33
  try {
34
- const userExists = await this.cognitoService.userExists(username);
35
- if (userExists) return Result.fail(new CognitoAccountExistsError(data.email));
34
+ const cognitoUser = await this.cognitoService.getUser(username);
35
+ if (cognitoUser) return Result.fail(cognitoUser.attributes["custom:id"] ? new CognitoAccountInOtherTenantError(data.email) : new CognitoAccountExistsError(data.email));
36
36
  const createUserResult = await this.createUserUseCase.execute(userDataWithoutPassword);
37
37
  if (createUserResult.isFail()) return Result.fail(createUserResult.error);
38
38
  user = createUserResult.value;
@@ -1 +1 @@
1
- {"version":3,"file":"api/features/CreateUser/CreateUserUseCase.js","sources":["../../../../src/api/features/CreateUser/CreateUserUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { AdminUsersRepository } from \"@webiny/api-core/features/users/shared/abstractions.js\";\nimport {\n NotAuthorizedError,\n UserValidationError\n} from \"@webiny/api-core/features/users/shared/errors.js\";\nimport type { AdminUser } from \"@webiny/api-core/types/users.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { CreateUserUseCase as CoreCreateUser } from \"@webiny/api-core/features/users/CreateUser/index.js\";\nimport { ListUsersUseCase } from \"@webiny/api-core/features/users/ListUsers/index.js\";\n\nimport { CreateUserUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { Username } from \"~/api/domain/Username.js\";\nimport { CognitoAccountExistsError, CognitoCreateUserError } from \"~/api/domain/errors.js\";\nimport { createAdminUserValidation } from \"./schema.js\";\nimport type { CreateAdminUserInput } from \"./abstractions.js\";\nimport { CognitoService } from \"~/api/features/CognitoService/index.js\";\n\nclass CreateUserUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private cognitoService: CognitoService.Interface,\n private createUserUseCase: CoreCreateUser.Interface,\n private listUsersUseCase: ListUsersUseCase.Interface,\n private repository: AdminUsersRepository.Interface\n ) {}\n\n async execute(\n input: CreateAdminUserInput\n ): Promise<Result<AdminUser, UseCaseAbstraction.Error>> {\n const permission = await this.identityContext.getPermission(\"adminUsers.user\");\n if (!permission) {\n return Result.fail(new NotAuthorizedError());\n }\n\n // Validate input (including password)\n const validation = createAdminUserValidation.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 const { password, ...userDataWithoutPassword } = data;\n\n const username = Username.fromUser(data);\n\n // Check if user exists in database (faster than Cognito check)\n const existingUserResult = await this.repository.get({ email: data.email });\n if (existingUserResult.isOk()) {\n return Result.fail(new CognitoAccountExistsError(data.email));\n }\n\n let user: AdminUser | undefined = undefined;\n\n try {\n // Check if user exists in Cognito\n const userExists = await this.cognitoService.userExists(username);\n if (userExists) {\n return Result.fail(new CognitoAccountExistsError(data.email));\n }\n // Create user in api-core\n const createUserResult = await this.createUserUseCase.execute(userDataWithoutPassword);\n if (createUserResult.isFail()) {\n return Result.fail(createUserResult.error);\n }\n\n user = createUserResult.value;\n\n // Create user in Cognito\n await this.cognitoService.createUser({\n username,\n temporaryPassword: password,\n attributes: {\n givenName: data.firstName,\n familyName: data.lastName,\n preferredUsername: username,\n email: username,\n customId: user.id\n }\n });\n\n // Set email as verified\n await this.cognitoService.setEmailVerified(username);\n\n // Check if this is the first user in the system, and if so, set permanent password\n const usersResult = await this.listUsersUseCase.execute();\n if (usersResult.isFail()) {\n // Log error but don't fail the operation\n console.error(`Failed to list users: ${usersResult.error.message}`);\n } else {\n const users = usersResult.value;\n if (users.length <= 1) {\n // This is the first user, set permanent password\n await this.cognitoService.setPermanentPassword(username, password);\n }\n }\n\n return Result.ok(user);\n } catch (cognitoError) {\n if (user) {\n // Rollback: Delete user from api-core if Cognito creation failed\n try {\n await this.repository.delete(user);\n } catch (rollbackError) {\n console.error(\"Failed to rollback user creation:\", rollbackError);\n }\n }\n return Result.fail(new CognitoCreateUserError(cognitoError as Error));\n }\n }\n}\n\nexport const CreateUserUseCase = UseCaseAbstraction.createImplementation({\n implementation: CreateUserUseCaseImpl,\n dependencies: [\n IdentityContext,\n CognitoService,\n CoreCreateUser,\n ListUsersUseCase,\n AdminUsersRepository\n ]\n});\n"],"names":["CreateUserUseCaseImpl","identityContext","cognitoService","createUserUseCase","listUsersUseCase","repository","input","permission","Result","NotAuthorizedError","validation","createAdminUserValidation","UserValidationError","data","password","userDataWithoutPassword","username","Username","existingUserResult","CognitoAccountExistsError","user","userExists","createUserResult","usersResult","console","users","cognitoError","rollbackError","CognitoCreateUserError","CreateUserUseCase","UseCaseAbstraction","IdentityContext","CognitoService","CoreCreateUser","ListUsersUseCase","AdminUsersRepository"],"mappings":";;;;;;;;;;;AAkBA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,cAAwC,EACxCC,iBAA2C,EAC3CC,gBAA4C,EAC5CC,UAA0C,CACpD;aALUJ,eAAe,GAAfA;aACAC,cAAc,GAAdA;aACAC,iBAAiB,GAAjBA;aACAC,gBAAgB,GAAhBA;aACAC,UAAU,GAAVA;IACT;IAEH,MAAM,QACFC,KAA2B,EACyB;QACpD,MAAMC,aAAa,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC;QAC5D,IAAI,CAACA,YACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAI3B,MAAMC,aAAaC,0BAA0B,SAAS,CAACL;QACvD,IAAI,CAACI,WAAW,OAAO,EACnB,OAAOF,OAAO,IAAI,CAAC,IAAII,oBAAoBF,WAAW,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO;QAGjF,MAAMG,OAAOH,WAAW,IAAI;QAC5B,MAAM,EAAEI,QAAQ,EAAE,GAAGC,yBAAyB,GAAGF;QAEjD,MAAMG,WAAWC,SAAS,QAAQ,CAACJ;QAGnC,MAAMK,qBAAqB,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,OAAOL,KAAK,KAAK;QAAC;QACzE,IAAIK,mBAAmB,IAAI,IACvB,OAAOV,OAAO,IAAI,CAAC,IAAIW,0BAA0BN,KAAK,KAAK;QAG/D,IAAIO;QAEJ,IAAI;YAEA,MAAMC,aAAa,MAAM,IAAI,CAAC,cAAc,CAAC,UAAU,CAACL;YACxD,IAAIK,YACA,OAAOb,OAAO,IAAI,CAAC,IAAIW,0BAA0BN,KAAK,KAAK;YAG/D,MAAMS,mBAAmB,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAACP;YAC9D,IAAIO,iBAAiB,MAAM,IACvB,OAAOd,OAAO,IAAI,CAACc,iBAAiB,KAAK;YAG7CF,OAAOE,iBAAiB,KAAK;YAG7B,MAAM,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC;gBACjCN;gBACA,mBAAmBF;gBACnB,YAAY;oBACR,WAAWD,KAAK,SAAS;oBACzB,YAAYA,KAAK,QAAQ;oBACzB,mBAAmBG;oBACnB,OAAOA;oBACP,UAAUI,KAAK,EAAE;gBACrB;YACJ;YAGA,MAAM,IAAI,CAAC,cAAc,CAAC,gBAAgB,CAACJ;YAG3C,MAAMO,cAAc,MAAM,IAAI,CAAC,gBAAgB,CAAC,OAAO;YACvD,IAAIA,YAAY,MAAM,IAElBC,QAAQ,KAAK,CAAC,CAAC,sBAAsB,EAAED,YAAY,KAAK,CAAC,OAAO,EAAE;iBAC/D;gBACH,MAAME,QAAQF,YAAY,KAAK;gBAC/B,IAAIE,MAAM,MAAM,IAAI,GAEhB,MAAM,IAAI,CAAC,cAAc,CAAC,oBAAoB,CAACT,UAAUF;YAEjE;YAEA,OAAON,OAAO,EAAE,CAACY;QACrB,EAAE,OAAOM,cAAc;YACnB,IAAIN,MAEA,IAAI;gBACA,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAACA;YACjC,EAAE,OAAOO,eAAe;gBACpBH,QAAQ,KAAK,CAAC,qCAAqCG;YACvD;YAEJ,OAAOnB,OAAO,IAAI,CAAC,IAAIoB,uBAAuBF;QAClD;IACJ;AACJ;AAEO,MAAMG,sCAAoBC,2CAAAA,oBAAuC,CAAC;IACrE,gBAAgB9B;IAChB,cAAc;QACV+B;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
1
+ {"version":3,"file":"api/features/CreateUser/CreateUserUseCase.js","sources":["../../../../src/api/features/CreateUser/CreateUserUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { AdminUsersRepository } from \"@webiny/api-core/features/users/shared/abstractions.js\";\nimport {\n NotAuthorizedError,\n UserValidationError\n} from \"@webiny/api-core/features/users/shared/errors.js\";\nimport type { AdminUser } from \"@webiny/api-core/types/users.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { CreateUserUseCase as CoreCreateUser } from \"@webiny/api-core/features/users/CreateUser/index.js\";\nimport { ListUsersUseCase } from \"@webiny/api-core/features/users/ListUsers/index.js\";\n\nimport { CreateUserUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { Username } from \"~/api/domain/Username.js\";\nimport {\n CognitoAccountExistsError,\n CognitoAccountInOtherTenantError,\n CognitoCreateUserError\n} from \"~/api/domain/errors.js\";\nimport { createAdminUserValidation } from \"./schema.js\";\nimport type { CreateAdminUserInput } from \"./abstractions.js\";\nimport { CognitoService } from \"~/api/features/CognitoService/index.js\";\n\nclass CreateUserUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private cognitoService: CognitoService.Interface,\n private createUserUseCase: CoreCreateUser.Interface,\n private listUsersUseCase: ListUsersUseCase.Interface,\n private repository: AdminUsersRepository.Interface\n ) {}\n\n async execute(\n input: CreateAdminUserInput\n ): Promise<Result<UseCaseAbstraction.Output, UseCaseAbstraction.Error>> {\n const permission = await this.identityContext.getPermission(\"adminUsers.user\");\n if (!permission) {\n return Result.fail(new NotAuthorizedError());\n }\n\n // Validate input (including password)\n const validation = createAdminUserValidation.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 const { password, ...userDataWithoutPassword } = data;\n\n const username = Username.fromUser(data);\n\n // Check if user exists in database (faster than Cognito check)\n const existingUserResult = await this.repository.get({ email: data.email });\n if (existingUserResult.isOk()) {\n return Result.fail(new CognitoAccountExistsError(data.email));\n }\n\n let user: AdminUser | undefined = undefined;\n\n try {\n // An account from another tenant is never added silently: the caller links it.\n const cognitoUser = await this.cognitoService.getUser(username);\n if (cognitoUser) {\n return Result.fail(\n cognitoUser.attributes[\"custom:id\"]\n ? new CognitoAccountInOtherTenantError(data.email)\n : new CognitoAccountExistsError(data.email)\n );\n }\n\n // Create user in api-core\n const createUserResult = await this.createUserUseCase.execute(userDataWithoutPassword);\n if (createUserResult.isFail()) {\n return Result.fail(createUserResult.error);\n }\n\n user = createUserResult.value;\n\n // Create user in Cognito\n await this.cognitoService.createUser({\n username,\n temporaryPassword: password,\n attributes: {\n givenName: data.firstName,\n familyName: data.lastName,\n preferredUsername: username,\n email: username,\n customId: user.id\n }\n });\n\n // Set email as verified\n await this.cognitoService.setEmailVerified(username);\n\n // Check if this is the first user in the system, and if so, set permanent password\n const usersResult = await this.listUsersUseCase.execute();\n if (usersResult.isFail()) {\n // Log error but don't fail the operation\n console.error(`Failed to list users: ${usersResult.error.message}`);\n } else {\n const users = usersResult.value;\n if (users.length <= 1) {\n // This is the first user, set permanent password\n await this.cognitoService.setPermanentPassword(username, password);\n }\n }\n\n return Result.ok(user);\n } catch (cognitoError) {\n if (user) {\n // Rollback: Delete user from api-core if Cognito creation failed\n try {\n await this.repository.delete(user);\n } catch (rollbackError) {\n console.error(\"Failed to rollback user creation:\", rollbackError);\n }\n }\n return Result.fail(new CognitoCreateUserError(cognitoError as Error));\n }\n }\n}\n\nexport const CreateUserUseCase = UseCaseAbstraction.createImplementation({\n implementation: CreateUserUseCaseImpl,\n dependencies: [\n IdentityContext,\n CognitoService,\n CoreCreateUser,\n ListUsersUseCase,\n AdminUsersRepository\n ]\n});\n"],"names":["CreateUserUseCaseImpl","identityContext","cognitoService","createUserUseCase","listUsersUseCase","repository","input","permission","Result","NotAuthorizedError","validation","createAdminUserValidation","UserValidationError","data","password","userDataWithoutPassword","username","Username","existingUserResult","CognitoAccountExistsError","user","cognitoUser","CognitoAccountInOtherTenantError","createUserResult","usersResult","console","users","cognitoError","rollbackError","CognitoCreateUserError","CreateUserUseCase","UseCaseAbstraction","IdentityContext","CognitoService","CoreCreateUser","ListUsersUseCase","AdminUsersRepository"],"mappings":";;;;;;;;;;;AAsBA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,cAAwC,EACxCC,iBAA2C,EAC3CC,gBAA4C,EAC5CC,UAA0C,CACpD;aALUJ,eAAe,GAAfA;aACAC,cAAc,GAAdA;aACAC,iBAAiB,GAAjBA;aACAC,gBAAgB,GAAhBA;aACAC,UAAU,GAAVA;IACT;IAEH,MAAM,QACFC,KAA2B,EACyC;QACpE,MAAMC,aAAa,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC;QAC5D,IAAI,CAACA,YACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAI3B,MAAMC,aAAaC,0BAA0B,SAAS,CAACL;QACvD,IAAI,CAACI,WAAW,OAAO,EACnB,OAAOF,OAAO,IAAI,CAAC,IAAII,oBAAoBF,WAAW,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO;QAGjF,MAAMG,OAAOH,WAAW,IAAI;QAC5B,MAAM,EAAEI,QAAQ,EAAE,GAAGC,yBAAyB,GAAGF;QAEjD,MAAMG,WAAWC,SAAS,QAAQ,CAACJ;QAGnC,MAAMK,qBAAqB,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,OAAOL,KAAK,KAAK;QAAC;QACzE,IAAIK,mBAAmB,IAAI,IACvB,OAAOV,OAAO,IAAI,CAAC,IAAIW,0BAA0BN,KAAK,KAAK;QAG/D,IAAIO;QAEJ,IAAI;YAEA,MAAMC,cAAc,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAACL;YACtD,IAAIK,aACA,OAAOb,OAAO,IAAI,CACda,YAAY,UAAU,CAAC,YAAY,GAC7B,IAAIC,iCAAiCT,KAAK,KAAK,IAC/C,IAAIM,0BAA0BN,KAAK,KAAK;YAKtD,MAAMU,mBAAmB,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAACR;YAC9D,IAAIQ,iBAAiB,MAAM,IACvB,OAAOf,OAAO,IAAI,CAACe,iBAAiB,KAAK;YAG7CH,OAAOG,iBAAiB,KAAK;YAG7B,MAAM,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC;gBACjCP;gBACA,mBAAmBF;gBACnB,YAAY;oBACR,WAAWD,KAAK,SAAS;oBACzB,YAAYA,KAAK,QAAQ;oBACzB,mBAAmBG;oBACnB,OAAOA;oBACP,UAAUI,KAAK,EAAE;gBACrB;YACJ;YAGA,MAAM,IAAI,CAAC,cAAc,CAAC,gBAAgB,CAACJ;YAG3C,MAAMQ,cAAc,MAAM,IAAI,CAAC,gBAAgB,CAAC,OAAO;YACvD,IAAIA,YAAY,MAAM,IAElBC,QAAQ,KAAK,CAAC,CAAC,sBAAsB,EAAED,YAAY,KAAK,CAAC,OAAO,EAAE;iBAC/D;gBACH,MAAME,QAAQF,YAAY,KAAK;gBAC/B,IAAIE,MAAM,MAAM,IAAI,GAEhB,MAAM,IAAI,CAAC,cAAc,CAAC,oBAAoB,CAACV,UAAUF;YAEjE;YAEA,OAAON,OAAO,EAAE,CAACY;QACrB,EAAE,OAAOO,cAAc;YACnB,IAAIP,MAEA,IAAI;gBACA,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAACA;YACjC,EAAE,OAAOQ,eAAe;gBACpBH,QAAQ,KAAK,CAAC,qCAAqCG;YACvD;YAEJ,OAAOpB,OAAO,IAAI,CAAC,IAAIqB,uBAAuBF;QAClD;IACJ;AACJ;AAEO,MAAMG,sCAAoBC,2CAAAA,oBAAuC,CAAC;IACrE,gBAAgB/B;IAChB,cAAc;QACVgC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
@@ -2,7 +2,7 @@ import type { Result } from "@webiny/feature/api";
2
2
  import type { AdminUser } from "@webiny/api-core/types/users.js";
3
3
  import type { NotAuthorizedError, EmailTakenError, UserValidationError } from "@webiny/api-core/features/users/shared/errors.js";
4
4
  import type { RepositoryError } from "@webiny/api-core/features/users/shared/abstractions.js";
5
- import type { CognitoAccountExistsError, CognitoCreateUserError } from "../../../api/domain/errors.js";
5
+ import type { CognitoAccountExistsError, CognitoAccountInOtherTenantError, CognitoCreateUserError } from "../../../api/domain/errors.js";
6
6
  export interface CreateAdminUserInput {
7
7
  id?: string;
8
8
  displayName?: string;
@@ -20,6 +20,7 @@ export interface ICreateUserUseCaseErrors {
20
20
  emailTaken: EmailTakenError;
21
21
  repository: RepositoryError;
22
22
  cognitoAccountExists: CognitoAccountExistsError;
23
+ cognitoAccountInOtherTenant: CognitoAccountInOtherTenantError;
23
24
  cognitoCreateUser: CognitoCreateUserError;
24
25
  }
25
26
  type CreateAdminUserError = ICreateUserUseCaseErrors[keyof ICreateUserUseCaseErrors];
@@ -30,6 +31,7 @@ export declare const CreateUserUseCase: import("@webiny/di").Abstraction<ICreate
30
31
  export declare namespace CreateUserUseCase {
31
32
  type Interface = ICreateUserUseCase;
32
33
  type Input = CreateAdminUserInput;
34
+ type Output = AdminUser;
33
35
  type Error = CreateAdminUserError;
34
36
  }
35
37
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"api/features/CreateUser/abstractions.js","sources":["../../../../src/api/features/CreateUser/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Result } from \"@webiny/feature/api\";\nimport type { AdminUser } from \"@webiny/api-core/types/users.js\";\nimport type {\n NotAuthorizedError,\n EmailTakenError,\n UserValidationError\n} from \"@webiny/api-core/features/users/shared/errors.js\";\nimport type { RepositoryError } from \"@webiny/api-core/features/users/shared/abstractions.js\";\nimport type { CognitoAccountExistsError, CognitoCreateUserError } from \"~/api/domain/errors.js\";\n\nexport interface CreateAdminUserInput {\n id?: string;\n displayName?: string;\n email: string;\n firstName?: string;\n lastName?: string;\n password: string;\n avatar?: Record<string, any> | null;\n roles?: string[];\n teams?: string[];\n}\n\nexport interface ICreateUserUseCaseErrors {\n authorization: NotAuthorizedError;\n validation: UserValidationError;\n emailTaken: EmailTakenError;\n repository: RepositoryError;\n cognitoAccountExists: CognitoAccountExistsError;\n cognitoCreateUser: CognitoCreateUserError;\n}\n\ntype CreateAdminUserError = ICreateUserUseCaseErrors[keyof ICreateUserUseCaseErrors];\n\nexport interface ICreateUserUseCase {\n execute(input: CreateAdminUserInput): Promise<Result<AdminUser, CreateAdminUserError>>;\n}\n\nexport const CreateUserUseCase = createAbstraction<ICreateUserUseCase>(\"CreateUserUseCase\");\n\nexport namespace CreateUserUseCase {\n export type Interface = ICreateUserUseCase;\n export type Input = CreateAdminUserInput;\n export type Error = CreateAdminUserError;\n}\n"],"names":["CreateUserUseCase","createAbstraction"],"mappings":";AAsCO,MAAMA,oBAAoBC,kBAAsC"}
1
+ {"version":3,"file":"api/features/CreateUser/abstractions.js","sources":["../../../../src/api/features/CreateUser/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Result } from \"@webiny/feature/api\";\nimport type { AdminUser } from \"@webiny/api-core/types/users.js\";\nimport type {\n NotAuthorizedError,\n EmailTakenError,\n UserValidationError\n} from \"@webiny/api-core/features/users/shared/errors.js\";\nimport type { RepositoryError } from \"@webiny/api-core/features/users/shared/abstractions.js\";\nimport type {\n CognitoAccountExistsError,\n CognitoAccountInOtherTenantError,\n CognitoCreateUserError\n} from \"~/api/domain/errors.js\";\n\nexport interface CreateAdminUserInput {\n id?: string;\n displayName?: string;\n email: string;\n firstName?: string;\n lastName?: string;\n password: string;\n avatar?: Record<string, any> | null;\n roles?: string[];\n teams?: string[];\n}\n\nexport interface ICreateUserUseCaseErrors {\n authorization: NotAuthorizedError;\n validation: UserValidationError;\n emailTaken: EmailTakenError;\n repository: RepositoryError;\n cognitoAccountExists: CognitoAccountExistsError;\n cognitoAccountInOtherTenant: CognitoAccountInOtherTenantError;\n cognitoCreateUser: CognitoCreateUserError;\n}\n\ntype CreateAdminUserError = ICreateUserUseCaseErrors[keyof ICreateUserUseCaseErrors];\n\nexport interface ICreateUserUseCase {\n execute(input: CreateAdminUserInput): Promise<Result<AdminUser, CreateAdminUserError>>;\n}\n\nexport const CreateUserUseCase = createAbstraction<ICreateUserUseCase>(\"CreateUserUseCase\");\n\nexport namespace CreateUserUseCase {\n export type Interface = ICreateUserUseCase;\n export type Input = CreateAdminUserInput;\n export type Output = AdminUser;\n export type Error = CreateAdminUserError;\n}\n"],"names":["CreateUserUseCase","createAbstraction"],"mappings":";AA2CO,MAAMA,oBAAoBC,kBAAsC"}
@@ -1,6 +1,7 @@
1
1
  import { Result } from "@webiny/feature/api";
2
2
  import { DeleteUserUseCase as CoreDeleteUser } from "@webiny/api-core/features/users/DeleteUser/index.js";
3
3
  import { GetUserUseCase } from "@webiny/api-core/features/users/GetUser/index.js";
4
+ import { FindUserRecordsUseCase } from "@webiny/api-core/features/users/FindUserRecords/index.js";
4
5
  import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
5
6
  import { DeleteUserUseCase as UseCaseAbstraction } from "./abstractions.js";
6
7
  import { CognitoService } from "../CognitoService/abstractions.js";
@@ -9,7 +10,8 @@ declare class DeleteUserUseCaseImpl implements UseCaseAbstraction.Interface {
9
10
  private cognitoService;
10
11
  private deleteUserUseCase;
11
12
  private getUserUseCase;
12
- constructor(identityContext: IdentityContext.Interface, cognitoService: CognitoService.Interface, deleteUserUseCase: CoreDeleteUser.Interface, getUserUseCase: GetUserUseCase.Interface);
13
+ private findUserRecords;
14
+ constructor(identityContext: IdentityContext.Interface, cognitoService: CognitoService.Interface, deleteUserUseCase: CoreDeleteUser.Interface, getUserUseCase: GetUserUseCase.Interface, findUserRecords: FindUserRecordsUseCase.Interface);
13
15
  execute(id: string): Promise<Result<void, UseCaseAbstraction.Error>>;
14
16
  }
15
17
  export declare const DeleteUserUseCase: import("@webiny/di").Implementation<typeof DeleteUserUseCaseImpl>;
@@ -1,6 +1,7 @@
1
1
  import { Result, createImplementation } from "@webiny/feature/api";
2
2
  import { DeleteUserUseCase } from "@webiny/api-core/features/users/DeleteUser/index.js";
3
3
  import { GetUserUseCase } from "@webiny/api-core/features/users/GetUser/index.js";
4
+ import { FindUserRecordsUseCase } from "@webiny/api-core/features/users/FindUserRecords/index.js";
4
5
  import { NotAuthorizedError } from "@webiny/api-core/features/users/shared/errors.js";
5
6
  import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
6
7
  import { DeleteUserUseCase as external_abstractions_js_DeleteUserUseCase } from "./abstractions.js";
@@ -8,11 +9,12 @@ import { Username } from "../../domain/Username.js";
8
9
  import { CognitoDeleteUserError } from "../../domain/errors.js";
9
10
  import { CognitoService } from "../CognitoService/abstractions.js";
10
11
  class DeleteUserUseCaseImpl {
11
- constructor(identityContext, cognitoService, deleteUserUseCase, getUserUseCase){
12
+ constructor(identityContext, cognitoService, deleteUserUseCase, getUserUseCase, findUserRecords){
12
13
  this.identityContext = identityContext;
13
14
  this.cognitoService = cognitoService;
14
15
  this.deleteUserUseCase = deleteUserUseCase;
15
16
  this.getUserUseCase = getUserUseCase;
17
+ this.findUserRecords = findUserRecords;
16
18
  }
17
19
  async execute(id) {
18
20
  const permission = await this.identityContext.getPermission("adminUsers.user");
@@ -22,8 +24,14 @@ class DeleteUserUseCaseImpl {
22
24
  });
23
25
  if (getUserResult.isFail()) return Result.fail(getUserResult.error);
24
26
  const user = getUserResult.value;
27
+ const recordsResult = await this.findUserRecords.execute(id, {
28
+ exhaustive: true
29
+ });
30
+ if (recordsResult.isFail()) return Result.fail(recordsResult.error);
31
+ const inOtherTenants = recordsResult.value.some((record)=>record.tenant !== user.tenant);
25
32
  const deleteUserResult = await this.deleteUserUseCase.execute(id);
26
33
  if (deleteUserResult.isFail()) return Result.fail(deleteUserResult.error);
34
+ if (inOtherTenants) return Result.ok();
27
35
  try {
28
36
  await this.cognitoService.deleteUser(Username.fromUser(user));
29
37
  return Result.ok();
@@ -39,7 +47,8 @@ const DeleteUserUseCase_DeleteUserUseCase = createImplementation({
39
47
  IdentityContext,
40
48
  CognitoService,
41
49
  DeleteUserUseCase,
42
- GetUserUseCase
50
+ GetUserUseCase,
51
+ FindUserRecordsUseCase
43
52
  ]
44
53
  });
45
54
  export { DeleteUserUseCase_DeleteUserUseCase as DeleteUserUseCase };
@@ -1 +1 @@
1
- {"version":3,"file":"api/features/DeleteUser/DeleteUserUseCase.js","sources":["../../../../src/api/features/DeleteUser/DeleteUserUseCase.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport { DeleteUserUseCase as CoreDeleteUser } from \"@webiny/api-core/features/users/DeleteUser/index.js\";\nimport { GetUserUseCase } from \"@webiny/api-core/features/users/GetUser/index.js\";\nimport { NotAuthorizedError } from \"@webiny/api-core/features/users/shared/errors.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { DeleteUserUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { Username } from \"~/api/domain/Username.js\";\nimport { CognitoDeleteUserError } from \"~/api/domain/errors.js\";\nimport { CognitoService } from \"../CognitoService/abstractions.js\";\n\nclass DeleteUserUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private cognitoService: CognitoService.Interface,\n private deleteUserUseCase: CoreDeleteUser.Interface,\n private getUserUseCase: GetUserUseCase.Interface\n ) {}\n\n async execute(id: string): Promise<Result<void, UseCaseAbstraction.Error>> {\n const permission = await this.identityContext.getPermission(\"adminUsers.user\");\n if (!permission) {\n return Result.fail(new NotAuthorizedError());\n }\n\n // Get user to have email for Cognito deletion\n const getUserResult = await this.getUserUseCase.execute({ id });\n if (getUserResult.isFail()) {\n return Result.fail(getUserResult.error);\n }\n\n const user = getUserResult.value;\n\n // Delete user from the database\n const deleteUserResult = await this.deleteUserUseCase.execute(id);\n if (deleteUserResult.isFail()) {\n return Result.fail(deleteUserResult.error);\n }\n\n // Delete user from Cognito\n try {\n await this.cognitoService.deleteUser(Username.fromUser(user));\n\n return Result.ok();\n } catch (cognitoError) {\n return Result.fail(new CognitoDeleteUserError(cognitoError as Error));\n }\n }\n}\n\nexport const DeleteUserUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: DeleteUserUseCaseImpl,\n dependencies: [IdentityContext, CognitoService, CoreDeleteUser, GetUserUseCase]\n});\n"],"names":["DeleteUserUseCaseImpl","identityContext","cognitoService","deleteUserUseCase","getUserUseCase","id","permission","Result","NotAuthorizedError","getUserResult","user","deleteUserResult","Username","cognitoError","CognitoDeleteUserError","DeleteUserUseCase","createImplementation","UseCaseAbstraction","IdentityContext","CognitoService","CoreDeleteUser","GetUserUseCase"],"mappings":";;;;;;;;;AAWA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,cAAwC,EACxCC,iBAA2C,EAC3CC,cAAwC,CAClD;aAJUH,eAAe,GAAfA;aACAC,cAAc,GAAdA;aACAC,iBAAiB,GAAjBA;aACAC,cAAc,GAAdA;IACT;IAEH,MAAM,QAAQC,EAAU,EAAmD;QACvE,MAAMC,aAAa,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC;QAC5D,IAAI,CAACA,YACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAI3B,MAAMC,gBAAgB,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC;YAAEJ;QAAG;QAC7D,IAAII,cAAc,MAAM,IACpB,OAAOF,OAAO,IAAI,CAACE,cAAc,KAAK;QAG1C,MAAMC,OAAOD,cAAc,KAAK;QAGhC,MAAME,mBAAmB,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAACN;QAC9D,IAAIM,iBAAiB,MAAM,IACvB,OAAOJ,OAAO,IAAI,CAACI,iBAAiB,KAAK;QAI7C,IAAI;YACA,MAAM,IAAI,CAAC,cAAc,CAAC,UAAU,CAACC,SAAS,QAAQ,CAACF;YAEvD,OAAOH,OAAO,EAAE;QACpB,EAAE,OAAOM,cAAc;YACnB,OAAON,OAAO,IAAI,CAAC,IAAIO,uBAAuBD;QAClD;IACJ;AACJ;AAEO,MAAME,sCAAoBC,qBAAqB;IAClD,aAAaC;IACb,gBAAgBjB;IAChB,cAAc;QAACkB;QAAiBC;QAAgBC;QAAgBC;KAAe;AACnF"}
1
+ {"version":3,"file":"api/features/DeleteUser/DeleteUserUseCase.js","sources":["../../../../src/api/features/DeleteUser/DeleteUserUseCase.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport { DeleteUserUseCase as CoreDeleteUser } from \"@webiny/api-core/features/users/DeleteUser/index.js\";\nimport { GetUserUseCase } from \"@webiny/api-core/features/users/GetUser/index.js\";\nimport { FindUserRecordsUseCase } from \"@webiny/api-core/features/users/FindUserRecords/index.js\";\nimport { NotAuthorizedError } from \"@webiny/api-core/features/users/shared/errors.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { DeleteUserUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { Username } from \"~/api/domain/Username.js\";\nimport { CognitoDeleteUserError } from \"~/api/domain/errors.js\";\nimport { CognitoService } from \"../CognitoService/abstractions.js\";\n\nclass DeleteUserUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private cognitoService: CognitoService.Interface,\n private deleteUserUseCase: CoreDeleteUser.Interface,\n private getUserUseCase: GetUserUseCase.Interface,\n private findUserRecords: FindUserRecordsUseCase.Interface\n ) {}\n\n async execute(id: string): Promise<Result<void, UseCaseAbstraction.Error>> {\n const permission = await this.identityContext.getPermission(\"adminUsers.user\");\n if (!permission) {\n return Result.fail(new NotAuthorizedError());\n }\n\n // Get user to have email for Cognito deletion\n const getUserResult = await this.getUserUseCase.execute({ id });\n if (getUserResult.isFail()) {\n return Result.fail(getUserResult.error);\n }\n\n const user = getUserResult.value;\n\n // The sign-in account is shared by all of the user's tenants. Look them up before\n // deleting anything, so a failed lookup leaves everything as it was.\n const recordsResult = await this.findUserRecords.execute(id, { exhaustive: true });\n if (recordsResult.isFail()) {\n return Result.fail(recordsResult.error);\n }\n\n const inOtherTenants = recordsResult.value.some(record => record.tenant !== user.tenant);\n\n // Delete user from the database\n const deleteUserResult = await this.deleteUserUseCase.execute(id);\n if (deleteUserResult.isFail()) {\n return Result.fail(deleteUserResult.error);\n }\n\n if (inOtherTenants) {\n return Result.ok();\n }\n\n // Delete user from Cognito\n try {\n await this.cognitoService.deleteUser(Username.fromUser(user));\n\n return Result.ok();\n } catch (cognitoError) {\n return Result.fail(new CognitoDeleteUserError(cognitoError as Error));\n }\n }\n}\n\nexport const DeleteUserUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: DeleteUserUseCaseImpl,\n dependencies: [\n IdentityContext,\n CognitoService,\n CoreDeleteUser,\n GetUserUseCase,\n FindUserRecordsUseCase\n ]\n});\n"],"names":["DeleteUserUseCaseImpl","identityContext","cognitoService","deleteUserUseCase","getUserUseCase","findUserRecords","id","permission","Result","NotAuthorizedError","getUserResult","user","recordsResult","inOtherTenants","record","deleteUserResult","Username","cognitoError","CognitoDeleteUserError","DeleteUserUseCase","createImplementation","UseCaseAbstraction","IdentityContext","CognitoService","CoreDeleteUser","GetUserUseCase","FindUserRecordsUseCase"],"mappings":";;;;;;;;;;AAYA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,cAAwC,EACxCC,iBAA2C,EAC3CC,cAAwC,EACxCC,eAAiD,CAC3D;aALUJ,eAAe,GAAfA;aACAC,cAAc,GAAdA;aACAC,iBAAiB,GAAjBA;aACAC,cAAc,GAAdA;aACAC,eAAe,GAAfA;IACT;IAEH,MAAM,QAAQC,EAAU,EAAmD;QACvE,MAAMC,aAAa,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC;QAC5D,IAAI,CAACA,YACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAI3B,MAAMC,gBAAgB,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC;YAAEJ;QAAG;QAC7D,IAAII,cAAc,MAAM,IACpB,OAAOF,OAAO,IAAI,CAACE,cAAc,KAAK;QAG1C,MAAMC,OAAOD,cAAc,KAAK;QAIhC,MAAME,gBAAgB,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAACN,IAAI;YAAE,YAAY;QAAK;QAChF,IAAIM,cAAc,MAAM,IACpB,OAAOJ,OAAO,IAAI,CAACI,cAAc,KAAK;QAG1C,MAAMC,iBAAiBD,cAAc,KAAK,CAAC,IAAI,CAACE,CAAAA,SAAUA,OAAO,MAAM,KAAKH,KAAK,MAAM;QAGvF,MAAMI,mBAAmB,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAACT;QAC9D,IAAIS,iBAAiB,MAAM,IACvB,OAAOP,OAAO,IAAI,CAACO,iBAAiB,KAAK;QAG7C,IAAIF,gBACA,OAAOL,OAAO,EAAE;QAIpB,IAAI;YACA,MAAM,IAAI,CAAC,cAAc,CAAC,UAAU,CAACQ,SAAS,QAAQ,CAACL;YAEvD,OAAOH,OAAO,EAAE;QACpB,EAAE,OAAOS,cAAc;YACnB,OAAOT,OAAO,IAAI,CAAC,IAAIU,uBAAuBD;QAClD;IACJ;AACJ;AAEO,MAAME,sCAAoBC,qBAAqB;IAClD,aAAaC;IACb,gBAAgBrB;IAChB,cAAc;QACVsB;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
@@ -1,11 +1,13 @@
1
1
  import type { Result } from "@webiny/feature/api";
2
2
  import type { NotAuthorizedError } from "@webiny/api-core/features/users/shared/errors.js";
3
3
  import type { DeleteUserUseCase as CoreDeleteUser } from "@webiny/api-core/features/users/DeleteUser/index.js";
4
+ import type { FindUserRecordsUseCase } from "@webiny/api-core/features/users/FindUserRecords/index.js";
4
5
  import type { CognitoDeleteUserError } from "../../../api/domain/errors.js";
5
6
  export interface IDeleteUserUseCaseErrors {
6
7
  authorization: NotAuthorizedError;
7
8
  deleteUser: CoreDeleteUser.Error;
8
9
  cognitoDeleteUser: CognitoDeleteUserError;
10
+ findUserRecords: FindUserRecordsUseCase.Error;
9
11
  }
10
12
  type IDeleteAdminUserError = IDeleteUserUseCaseErrors[keyof IDeleteUserUseCaseErrors];
11
13
  export interface IDeleteUserUseCase {
@@ -1 +1 @@
1
- {"version":3,"file":"api/features/DeleteUser/abstractions.js","sources":["../../../../src/api/features/DeleteUser/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Result } from \"@webiny/feature/api\";\nimport type { NotAuthorizedError } from \"@webiny/api-core/features/users/shared/errors.js\";\nimport type { DeleteUserUseCase as CoreDeleteUser } from \"@webiny/api-core/features/users/DeleteUser/index.js\";\nimport type { CognitoDeleteUserError } from \"~/api/domain/errors.js\";\n\nexport interface IDeleteUserUseCaseErrors {\n authorization: NotAuthorizedError;\n deleteUser: CoreDeleteUser.Error;\n cognitoDeleteUser: CognitoDeleteUserError;\n}\n\ntype IDeleteAdminUserError = IDeleteUserUseCaseErrors[keyof IDeleteUserUseCaseErrors];\n\nexport interface IDeleteUserUseCase {\n execute(id: string): Promise<Result<void, IDeleteAdminUserError>>;\n}\n\nexport const DeleteUserUseCase = createAbstraction<IDeleteUserUseCase>(\"DeleteUserUseCase\");\n\nexport namespace DeleteUserUseCase {\n export type Interface = IDeleteUserUseCase;\n export type Error = IDeleteAdminUserError;\n}\n"],"names":["DeleteUserUseCase","createAbstraction"],"mappings":";AAkBO,MAAMA,oBAAoBC,kBAAsC"}
1
+ {"version":3,"file":"api/features/DeleteUser/abstractions.js","sources":["../../../../src/api/features/DeleteUser/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Result } from \"@webiny/feature/api\";\nimport type { NotAuthorizedError } from \"@webiny/api-core/features/users/shared/errors.js\";\nimport type { DeleteUserUseCase as CoreDeleteUser } from \"@webiny/api-core/features/users/DeleteUser/index.js\";\nimport type { FindUserRecordsUseCase } from \"@webiny/api-core/features/users/FindUserRecords/index.js\";\nimport type { CognitoDeleteUserError } from \"~/api/domain/errors.js\";\n\nexport interface IDeleteUserUseCaseErrors {\n authorization: NotAuthorizedError;\n deleteUser: CoreDeleteUser.Error;\n cognitoDeleteUser: CognitoDeleteUserError;\n findUserRecords: FindUserRecordsUseCase.Error;\n}\n\ntype IDeleteAdminUserError = IDeleteUserUseCaseErrors[keyof IDeleteUserUseCaseErrors];\n\nexport interface IDeleteUserUseCase {\n execute(id: string): Promise<Result<void, IDeleteAdminUserError>>;\n}\n\nexport const DeleteUserUseCase = createAbstraction<IDeleteUserUseCase>(\"DeleteUserUseCase\");\n\nexport namespace DeleteUserUseCase {\n export type Interface = IDeleteUserUseCase;\n export type Error = IDeleteAdminUserError;\n}\n"],"names":["DeleteUserUseCase","createAbstraction"],"mappings":";AAoBO,MAAMA,oBAAoBC,kBAAsC"}
@@ -0,0 +1,22 @@
1
+ import { Result } from "@webiny/feature/api";
2
+ import { AdminUsersRepository } from "@webiny/api-core/features/users/shared/abstractions.js";
3
+ import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
4
+ import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
5
+ import { CreateUserUseCase as CoreCreateUser } from "@webiny/api-core/features/users/CreateUser/index.js";
6
+ import { FindUserRecordsUseCase } from "@webiny/api-core/features/users/FindUserRecords/index.js";
7
+ import { LinkUserUseCase as UseCaseAbstraction } from "./abstractions.js";
8
+ import { CognitoService } from "../../../api/features/CognitoService/index.js";
9
+ declare class LinkUserUseCaseImpl implements UseCaseAbstraction.Interface {
10
+ private identityContext;
11
+ private tenantContext;
12
+ private cognitoService;
13
+ private createUserUseCase;
14
+ private findUserRecords;
15
+ private repository;
16
+ constructor(identityContext: IdentityContext.Interface, tenantContext: TenantContext.Interface, cognitoService: CognitoService.Interface, createUserUseCase: CoreCreateUser.Interface, findUserRecords: FindUserRecordsUseCase.Interface, repository: AdminUsersRepository.Interface);
17
+ execute(input: UseCaseAbstraction.Input): Promise<Result<UseCaseAbstraction.Output, UseCaseAbstraction.Error>>;
18
+ }
19
+ export declare const LinkUserUseCase: typeof LinkUserUseCaseImpl & {
20
+ __abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").ILinkUserUseCase>;
21
+ };
22
+ export {};