@webiny/cognito 6.3.0 → 6.4.0-beta.1
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.
- package/Cognito.js +23 -24
- package/Cognito.js.map +1 -1
- package/admin/Cognito.js +35 -41
- package/admin/Cognito.js.map +1 -1
- package/admin/CognitoLogin.js +8 -13
- package/admin/CognitoLogin.js.map +1 -1
- package/admin/Extension.js +17 -16
- package/admin/Extension.js.map +1 -1
- package/admin/SecurityPermission.js +11 -14
- package/admin/SecurityPermission.js.map +1 -1
- package/admin/domain/permissionsSchema.js +14 -9
- package/admin/domain/permissionsSchema.js.map +1 -1
- package/admin/features/permissions/abstractions.js +2 -1
- package/admin/features/permissions/abstractions.js.map +1 -1
- package/admin/features/permissions/feature.js +2 -1
- package/admin/features/permissions/feature.js.map +1 -1
- package/admin/federatedIdentityProviders.js +7 -6
- package/admin/federatedIdentityProviders.js.map +1 -1
- package/admin/presentation/Cognito/CognitoLoginScreen.js +39 -42
- package/admin/presentation/Cognito/CognitoLoginScreen.js.map +1 -1
- package/admin/presentation/Cognito/CognitoPresenter.js +250 -275
- package/admin/presentation/Cognito/CognitoPresenter.js.map +1 -1
- package/admin/presentation/Cognito/abstractions.js +2 -1
- package/admin/presentation/Cognito/abstractions.js.map +1 -1
- package/admin/presentation/Cognito/components/Divider.js +12 -13
- package/admin/presentation/Cognito/components/Divider.js.map +1 -1
- package/admin/presentation/Cognito/components/FederatedLogin.js +24 -29
- package/admin/presentation/Cognito/components/FederatedLogin.js.map +1 -1
- package/admin/presentation/Cognito/components/FederatedProviders.js +7 -10
- package/admin/presentation/Cognito/components/FederatedProviders.js.map +1 -1
- package/admin/presentation/Cognito/components/FooterSignIn.js +9 -12
- package/admin/presentation/Cognito/components/FooterSignIn.js.map +1 -1
- package/admin/presentation/Cognito/components/PasswordResetCodeSent.js +33 -37
- package/admin/presentation/Cognito/components/PasswordResetCodeSent.js.map +1 -1
- package/admin/presentation/Cognito/components/RequestPasswordResetCode.js +35 -39
- package/admin/presentation/Cognito/components/RequestPasswordResetCode.js.map +1 -1
- package/admin/presentation/Cognito/components/RequireNewPassword.js +44 -48
- package/admin/presentation/Cognito/components/RequireNewPassword.js.map +1 -1
- package/admin/presentation/Cognito/components/SetNewPassword.js +70 -71
- package/admin/presentation/Cognito/components/SetNewPassword.js.map +1 -1
- package/admin/presentation/Cognito/components/SignIn.js +52 -59
- package/admin/presentation/Cognito/components/SignIn.js.map +1 -1
- package/admin/presentation/Cognito/components/View.js +41 -60
- package/admin/presentation/Cognito/components/View.js.map +1 -1
- package/admin/presentation/Cognito/feature.js +12 -11
- package/admin/presentation/Cognito/feature.js.map +1 -1
- package/admin/presentation/shared/createPasswordValidator.js +13 -24
- package/admin/presentation/shared/createPasswordValidator.js.map +1 -1
- package/admin/presentation/shared/usePasswordValidator.js +11 -10
- package/admin/presentation/shared/usePasswordValidator.js.map +1 -1
- package/admin/presentation/userMenu/AccountDetails.js +15 -18
- package/admin/presentation/userMenu/AccountDetails.js.map +1 -1
- package/admin/presentation/userMenu/useIsDefaultTenant.js +5 -11
- package/admin/presentation/userMenu/useIsDefaultTenant.js.map +1 -1
- package/admin/routes.js +16 -17
- package/admin/routes.js.map +1 -1
- package/admin/ui/UserItem.js +0 -3
- package/admin/ui/components/AvatarImage/AvatarImage.js +25 -37
- package/admin/ui/components/AvatarImage/AvatarImage.js.map +1 -1
- package/admin/ui/components/AvatarImage/AvatarImagePreview.js +49 -51
- package/admin/ui/components/AvatarImage/AvatarImagePreview.js.map +1 -1
- package/admin/ui/components/AvatarImage/AvatarImageTrigger.js +25 -26
- package/admin/ui/components/AvatarImage/AvatarImageTrigger.js.map +1 -1
- package/admin/ui/components/AvatarImage/index.js +0 -2
- package/admin/ui/views/Account/Account.js +117 -130
- package/admin/ui/views/Account/Account.js.map +1 -1
- package/admin/ui/views/Account/graphql.js +5 -4
- package/admin/ui/views/Account/graphql.js.map +1 -1
- package/admin/ui/views/Account/index.js +0 -2
- package/admin/ui/views/Users/UsersDataList.js +146 -159
- package/admin/ui/views/Users/UsersDataList.js.map +1 -1
- package/admin/ui/views/Users/UsersForm.js +151 -162
- package/admin/ui/views/Users/UsersForm.js.map +1 -1
- package/admin/ui/views/Users/UsersView.js +9 -9
- package/admin/ui/views/Users/UsersView.js.map +1 -1
- package/admin/ui/views/Users/components/DeleteAction.js +23 -30
- package/admin/ui/views/Users/components/DeleteAction.js.map +1 -1
- package/admin/ui/views/Users/graphql.js +9 -10
- package/admin/ui/views/Users/graphql.js.map +1 -1
- package/admin/ui/views/Users/hooks/useUserForm.js +104 -114
- package/admin/ui/views/Users/hooks/useUserForm.js.map +1 -1
- package/admin/ui/views/Users/search.js +21 -0
- package/admin/ui/views/Users/search.js.map +1 -0
- package/admin/ui/views/utils.js +9 -7
- package/admin/ui/views/utils.js.map +1 -1
- package/api/CognitoApiFeature.js +15 -17
- package/api/CognitoApiFeature.js.map +1 -1
- package/api/domain/Username.js +5 -4
- package/api/domain/Username.js.map +1 -1
- package/api/domain/errors.js +37 -56
- package/api/domain/errors.js.map +1 -1
- package/api/features/CognitoIdp/CognitoIdentityProvider.js +49 -51
- package/api/features/CognitoIdp/CognitoIdentityProvider.js.map +1 -1
- package/api/features/CognitoIdp/abstractions.js +2 -1
- package/api/features/CognitoIdp/abstractions.js.map +1 -1
- package/api/features/CognitoIdp/feature.js +6 -5
- package/api/features/CognitoIdp/feature.js.map +1 -1
- package/api/features/CognitoIdp/index.js +0 -2
- package/api/features/CognitoService/CognitoService.js +93 -83
- package/api/features/CognitoService/CognitoService.js.map +1 -1
- package/api/features/CognitoService/abstractions.js +3 -5
- package/api/features/CognitoService/abstractions.js.map +1 -1
- package/api/features/CognitoService/feature.js +7 -6
- package/api/features/CognitoService/feature.js.map +1 -1
- package/api/features/CognitoService/index.js +0 -2
- package/api/features/CreateUser/CreateUserUseCase.js +62 -88
- package/api/features/CreateUser/CreateUserUseCase.js.map +1 -1
- package/api/features/CreateUser/abstractions.js +2 -1
- package/api/features/CreateUser/abstractions.js.map +1 -1
- package/api/features/CreateUser/feature.js +6 -5
- package/api/features/CreateUser/feature.js.map +1 -1
- package/api/features/CreateUser/index.js +0 -2
- package/api/features/CreateUser/schema.js +14 -13
- package/api/features/CreateUser/schema.js.map +1 -1
- package/api/features/DeleteUser/DeleteUserUseCase.js +34 -41
- package/api/features/DeleteUser/DeleteUserUseCase.js.map +1 -1
- package/api/features/DeleteUser/abstractions.js +2 -1
- package/api/features/DeleteUser/abstractions.js.map +1 -1
- package/api/features/DeleteUser/feature.js +6 -5
- package/api/features/DeleteUser/feature.js.map +1 -1
- package/api/features/DeleteUser/index.js +0 -2
- package/api/features/UpdateUser/UpdateUserUseCase.js +49 -71
- package/api/features/UpdateUser/UpdateUserUseCase.js.map +1 -1
- package/api/features/UpdateUser/abstractions.js +2 -1
- package/api/features/UpdateUser/abstractions.js.map +1 -1
- package/api/features/UpdateUser/feature.js +6 -5
- package/api/features/UpdateUser/feature.js.map +1 -1
- package/api/features/UpdateUser/index.js +0 -2
- package/api/features/UpdateUser/schema.js +13 -12
- package/api/features/UpdateUser/schema.js.map +1 -1
- package/api/features/UserInstaller/UserInstaller.js +36 -36
- package/api/features/UserInstaller/UserInstaller.js.map +1 -1
- package/api/features/UserInstaller/feature.js +6 -5
- package/api/features/UserInstaller/feature.js.map +1 -1
- package/api/graphql/user.gql.js +83 -107
- package/api/graphql/user.gql.js.map +1 -1
- package/index.js +0 -2
- package/package.json +23 -24
- package/static/svg/search.43fa797c.svg +20 -0
- package/admin/ui/UserItem.js.map +0 -1
- package/admin/ui/components/AvatarImage/index.js.map +0 -1
- package/admin/ui/views/Account/index.js.map +0 -1
- package/api/features/CognitoIdp/index.js.map +0 -1
- package/api/features/CognitoService/index.js.map +0 -1
- package/api/features/CreateUser/index.js.map +0 -1
- package/api/features/DeleteUser/index.js.map +0 -1
- package/api/features/UpdateUser/index.js.map +0 -1
- package/index.js.map +0 -1
|
@@ -2,105 +2,79 @@ import { Result } from "@webiny/feature/api";
|
|
|
2
2
|
import { AdminUsersRepository } from "@webiny/api-core/features/users/shared/abstractions.js";
|
|
3
3
|
import { NotAuthorizedError, UserValidationError } from "@webiny/api-core/features/users/shared/errors.js";
|
|
4
4
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
5
|
-
import { CreateUserUseCase
|
|
5
|
+
import { CreateUserUseCase } from "@webiny/api-core/features/users/CreateUser/index.js";
|
|
6
6
|
import { ListUsersUseCase } from "@webiny/api-core/features/users/ListUsers/index.js";
|
|
7
|
-
import { CreateUserUseCase as
|
|
7
|
+
import { CreateUserUseCase as external_abstractions_js_CreateUserUseCase } from "./abstractions.js";
|
|
8
8
|
import { Username } from "../../domain/Username.js";
|
|
9
9
|
import { CognitoAccountExistsError, CognitoCreateUserError } from "../../domain/errors.js";
|
|
10
10
|
import { createAdminUserValidation } from "./schema.js";
|
|
11
11
|
import { CognitoService } from "../CognitoService/index.js";
|
|
12
12
|
class CreateUserUseCaseImpl {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
async execute(input) {
|
|
21
|
-
const permission = await this.identityContext.getPermission("adminUsers.user");
|
|
22
|
-
if (!permission) {
|
|
23
|
-
return Result.fail(new NotAuthorizedError());
|
|
13
|
+
constructor(identityContext, cognitoService, createUserUseCase, listUsersUseCase, repository){
|
|
14
|
+
this.identityContext = identityContext;
|
|
15
|
+
this.cognitoService = cognitoService;
|
|
16
|
+
this.createUserUseCase = createUserUseCase;
|
|
17
|
+
this.listUsersUseCase = listUsersUseCase;
|
|
18
|
+
this.repository = repository;
|
|
24
19
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
// Check if user exists in database (faster than Cognito check)
|
|
39
|
-
const existingUserResult = await this.repository.get({
|
|
40
|
-
email: data.email
|
|
41
|
-
});
|
|
42
|
-
if (existingUserResult.isOk()) {
|
|
43
|
-
return Result.fail(new CognitoAccountExistsError(data.email));
|
|
44
|
-
}
|
|
45
|
-
let user = undefined;
|
|
46
|
-
try {
|
|
47
|
-
// Check if user exists in Cognito
|
|
48
|
-
const userExists = await this.cognitoService.userExists(username);
|
|
49
|
-
if (userExists) {
|
|
50
|
-
return Result.fail(new CognitoAccountExistsError(data.email));
|
|
51
|
-
}
|
|
52
|
-
// Create user in api-core
|
|
53
|
-
const createUserResult = await this.createUserUseCase.execute(userDataWithoutPassword);
|
|
54
|
-
if (createUserResult.isFail()) {
|
|
55
|
-
return Result.fail(createUserResult.error);
|
|
56
|
-
}
|
|
57
|
-
user = createUserResult.value;
|
|
58
|
-
|
|
59
|
-
// Create user in Cognito
|
|
60
|
-
await this.cognitoService.createUser({
|
|
61
|
-
username,
|
|
62
|
-
temporaryPassword: password,
|
|
63
|
-
attributes: {
|
|
64
|
-
givenName: data.firstName,
|
|
65
|
-
familyName: data.lastName,
|
|
66
|
-
preferredUsername: username,
|
|
67
|
-
email: username,
|
|
68
|
-
customId: user.id
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
// Set email as verified
|
|
73
|
-
await this.cognitoService.setEmailVerified(username);
|
|
74
|
-
|
|
75
|
-
// Check if this is the first user in the system, and if so, set permanent password
|
|
76
|
-
const usersResult = await this.listUsersUseCase.execute();
|
|
77
|
-
if (usersResult.isFail()) {
|
|
78
|
-
// Log error but don't fail the operation
|
|
79
|
-
console.error(`Failed to list users: ${usersResult.error.message}`);
|
|
80
|
-
} else {
|
|
81
|
-
const users = usersResult.value;
|
|
82
|
-
if (users.length <= 1) {
|
|
83
|
-
// This is the first user, set permanent password
|
|
84
|
-
await this.cognitoService.setPermanentPassword(username, password);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return Result.ok(user);
|
|
88
|
-
} catch (cognitoError) {
|
|
89
|
-
if (user) {
|
|
90
|
-
// Rollback: Delete user from api-core if Cognito creation failed
|
|
20
|
+
async execute(input) {
|
|
21
|
+
const permission = await this.identityContext.getPermission("adminUsers.user");
|
|
22
|
+
if (!permission) return Result.fail(new NotAuthorizedError());
|
|
23
|
+
const validation = createAdminUserValidation.safeParse(input);
|
|
24
|
+
if (!validation.success) return Result.fail(new UserValidationError(validation.error.issues[0].message));
|
|
25
|
+
const data = validation.data;
|
|
26
|
+
const { password, ...userDataWithoutPassword } = data;
|
|
27
|
+
const username = Username.fromUser(data);
|
|
28
|
+
const existingUserResult = await this.repository.get({
|
|
29
|
+
email: data.email
|
|
30
|
+
});
|
|
31
|
+
if (existingUserResult.isOk()) return Result.fail(new CognitoAccountExistsError(data.email));
|
|
32
|
+
let user;
|
|
91
33
|
try {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
34
|
+
const userExists = await this.cognitoService.userExists(username);
|
|
35
|
+
if (userExists) return Result.fail(new CognitoAccountExistsError(data.email));
|
|
36
|
+
const createUserResult = await this.createUserUseCase.execute(userDataWithoutPassword);
|
|
37
|
+
if (createUserResult.isFail()) return Result.fail(createUserResult.error);
|
|
38
|
+
user = createUserResult.value;
|
|
39
|
+
await this.cognitoService.createUser({
|
|
40
|
+
username,
|
|
41
|
+
temporaryPassword: password,
|
|
42
|
+
attributes: {
|
|
43
|
+
givenName: data.firstName,
|
|
44
|
+
familyName: data.lastName,
|
|
45
|
+
preferredUsername: username,
|
|
46
|
+
email: username,
|
|
47
|
+
customId: user.id
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
await this.cognitoService.setEmailVerified(username);
|
|
51
|
+
const usersResult = await this.listUsersUseCase.execute();
|
|
52
|
+
if (usersResult.isFail()) console.error(`Failed to list users: ${usersResult.error.message}`);
|
|
53
|
+
else {
|
|
54
|
+
const users = usersResult.value;
|
|
55
|
+
if (users.length <= 1) await this.cognitoService.setPermanentPassword(username, password);
|
|
56
|
+
}
|
|
57
|
+
return Result.ok(user);
|
|
58
|
+
} catch (cognitoError) {
|
|
59
|
+
if (user) try {
|
|
60
|
+
await this.repository.delete(user);
|
|
61
|
+
} catch (rollbackError) {
|
|
62
|
+
console.error("Failed to rollback user creation:", rollbackError);
|
|
63
|
+
}
|
|
64
|
+
return Result.fail(new CognitoCreateUserError(cognitoError));
|
|
95
65
|
}
|
|
96
|
-
}
|
|
97
|
-
return Result.fail(new CognitoCreateUserError(cognitoError));
|
|
98
66
|
}
|
|
99
|
-
}
|
|
100
67
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
68
|
+
const CreateUserUseCase_CreateUserUseCase = external_abstractions_js_CreateUserUseCase.createImplementation({
|
|
69
|
+
implementation: CreateUserUseCaseImpl,
|
|
70
|
+
dependencies: [
|
|
71
|
+
IdentityContext,
|
|
72
|
+
CognitoService,
|
|
73
|
+
CreateUserUseCase,
|
|
74
|
+
ListUsersUseCase,
|
|
75
|
+
AdminUsersRepository
|
|
76
|
+
]
|
|
104
77
|
});
|
|
78
|
+
export { CreateUserUseCase_CreateUserUseCase as CreateUserUseCase };
|
|
105
79
|
|
|
106
80
|
//# sourceMappingURL=CreateUserUseCase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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,4 +1,5 @@
|
|
|
1
1
|
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
-
|
|
2
|
+
const CreateUserUseCase = createAbstraction("CreateUserUseCase");
|
|
3
|
+
export { CreateUserUseCase };
|
|
3
4
|
|
|
4
5
|
//# sourceMappingURL=abstractions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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,10 +1,11 @@
|
|
|
1
1
|
import { createFeature } from "@webiny/feature/api";
|
|
2
2
|
import { CreateUserUseCase } from "./CreateUserUseCase.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
const CreateUserFeature = createFeature({
|
|
4
|
+
name: "CreateUserFeature",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(CreateUserUseCase);
|
|
7
|
+
}
|
|
8
8
|
});
|
|
9
|
+
export { CreateUserFeature };
|
|
9
10
|
|
|
10
11
|
//# sourceMappingURL=feature.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"api/features/CreateUser/feature.js","sources":["../../../../src/api/features/CreateUser/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { CreateUserUseCase } from \"./CreateUserUseCase.js\";\n\nexport const CreateUserFeature = createFeature({\n name: \"CreateUserFeature\",\n register(container) {\n container.register(CreateUserUseCase);\n }\n});\n"],"names":["CreateUserFeature","createFeature","container","CreateUserUseCase"],"mappings":";;AAGO,MAAMA,oBAAoBC,cAAc;IAC3C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
2
|
+
const createAdminUserValidation = z.object({
|
|
3
|
+
id: z.string().min(1).optional(),
|
|
4
|
+
displayName: z.string().min(1).optional(),
|
|
5
|
+
email: z.string().email(),
|
|
6
|
+
firstName: z.string().optional(),
|
|
7
|
+
lastName: z.string().optional(),
|
|
8
|
+
password: z.string().min(8),
|
|
9
|
+
avatar: z.object({
|
|
10
|
+
id: z.string().min(1),
|
|
11
|
+
src: z.string().url()
|
|
12
|
+
}).optional().nullable(),
|
|
13
|
+
roles: z.array(z.string()).optional().default([]),
|
|
14
|
+
teams: z.array(z.string()).optional().default([])
|
|
15
15
|
});
|
|
16
|
+
export { createAdminUserValidation };
|
|
16
17
|
|
|
17
18
|
//# sourceMappingURL=schema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"api/features/CreateUser/schema.js","sources":["../../../../src/api/features/CreateUser/schema.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const createAdminUserValidation = z.object({\n id: z.string().min(1).optional(),\n displayName: z.string().min(1).optional(),\n email: z.string().email(),\n firstName: z.string().optional(),\n lastName: z.string().optional(),\n password: z.string().min(8),\n avatar: z\n .object({\n id: z.string().min(1),\n src: z.string().url()\n })\n .optional()\n .nullable(),\n roles: z.array(z.string()).optional().default([]),\n teams: z.array(z.string()).optional().default([])\n});\n"],"names":["createAdminUserValidation","z"],"mappings":";AAEO,MAAMA,4BAA4BC,EAAE,MAAM,CAAC;IAC9C,IAAIA,EAAE,MAAM,GAAG,GAAG,CAAC,GAAG,QAAQ;IAC9B,aAAaA,EAAE,MAAM,GAAG,GAAG,CAAC,GAAG,QAAQ;IACvC,OAAOA,EAAE,MAAM,GAAG,KAAK;IACvB,WAAWA,EAAE,MAAM,GAAG,QAAQ;IAC9B,UAAUA,EAAE,MAAM,GAAG,QAAQ;IAC7B,UAAUA,EAAE,MAAM,GAAG,GAAG,CAAC;IACzB,QAAQA,EAAAA,MACG,CAAC;QACJ,IAAIA,EAAE,MAAM,GAAG,GAAG,CAAC;QACnB,KAAKA,EAAE,MAAM,GAAG,GAAG;IACvB,GACC,QAAQ,GACR,QAAQ;IACb,OAAOA,EAAE,KAAK,CAACA,EAAE,MAAM,IAAI,QAAQ,GAAG,OAAO,CAAC,EAAE;IAChD,OAAOA,EAAE,KAAK,CAACA,EAAE,MAAM,IAAI,QAAQ,GAAG,OAAO,CAAC,EAAE;AACpD"}
|
|
@@ -1,54 +1,47 @@
|
|
|
1
|
-
import { createImplementation } from "@webiny/feature/api";
|
|
2
|
-
import {
|
|
3
|
-
import { DeleteUserUseCase as CoreDeleteUser } from "@webiny/api-core/features/users/DeleteUser/index.js";
|
|
1
|
+
import { Result, createImplementation } from "@webiny/feature/api";
|
|
2
|
+
import { DeleteUserUseCase } from "@webiny/api-core/features/users/DeleteUser/index.js";
|
|
4
3
|
import { GetUserUseCase } from "@webiny/api-core/features/users/GetUser/index.js";
|
|
5
4
|
import { NotAuthorizedError } from "@webiny/api-core/features/users/shared/errors.js";
|
|
6
5
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
7
|
-
import { DeleteUserUseCase as
|
|
6
|
+
import { DeleteUserUseCase as external_abstractions_js_DeleteUserUseCase } from "./abstractions.js";
|
|
8
7
|
import { Username } from "../../domain/Username.js";
|
|
9
8
|
import { CognitoDeleteUserError } from "../../domain/errors.js";
|
|
10
9
|
import { CognitoService } from "../CognitoService/abstractions.js";
|
|
11
10
|
class DeleteUserUseCaseImpl {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
async execute(id) {
|
|
19
|
-
const permission = await this.identityContext.getPermission("adminUsers.user");
|
|
20
|
-
if (!permission) {
|
|
21
|
-
return Result.fail(new NotAuthorizedError());
|
|
11
|
+
constructor(identityContext, cognitoService, deleteUserUseCase, getUserUseCase){
|
|
12
|
+
this.identityContext = identityContext;
|
|
13
|
+
this.cognitoService = cognitoService;
|
|
14
|
+
this.deleteUserUseCase = deleteUserUseCase;
|
|
15
|
+
this.getUserUseCase = getUserUseCase;
|
|
22
16
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// Delete user from Cognito
|
|
40
|
-
try {
|
|
41
|
-
await this.cognitoService.deleteUser(Username.fromUser(user));
|
|
42
|
-
return Result.ok();
|
|
43
|
-
} catch (cognitoError) {
|
|
44
|
-
return Result.fail(new CognitoDeleteUserError(cognitoError));
|
|
17
|
+
async execute(id) {
|
|
18
|
+
const permission = await this.identityContext.getPermission("adminUsers.user");
|
|
19
|
+
if (!permission) return Result.fail(new NotAuthorizedError());
|
|
20
|
+
const getUserResult = await this.getUserUseCase.execute({
|
|
21
|
+
id
|
|
22
|
+
});
|
|
23
|
+
if (getUserResult.isFail()) return Result.fail(getUserResult.error);
|
|
24
|
+
const user = getUserResult.value;
|
|
25
|
+
const deleteUserResult = await this.deleteUserUseCase.execute(id);
|
|
26
|
+
if (deleteUserResult.isFail()) return Result.fail(deleteUserResult.error);
|
|
27
|
+
try {
|
|
28
|
+
await this.cognitoService.deleteUser(Username.fromUser(user));
|
|
29
|
+
return Result.ok();
|
|
30
|
+
} catch (cognitoError) {
|
|
31
|
+
return Result.fail(new CognitoDeleteUserError(cognitoError));
|
|
32
|
+
}
|
|
45
33
|
}
|
|
46
|
-
}
|
|
47
34
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
35
|
+
const DeleteUserUseCase_DeleteUserUseCase = createImplementation({
|
|
36
|
+
abstraction: external_abstractions_js_DeleteUserUseCase,
|
|
37
|
+
implementation: DeleteUserUseCaseImpl,
|
|
38
|
+
dependencies: [
|
|
39
|
+
IdentityContext,
|
|
40
|
+
CognitoService,
|
|
41
|
+
DeleteUserUseCase,
|
|
42
|
+
GetUserUseCase
|
|
43
|
+
]
|
|
52
44
|
});
|
|
45
|
+
export { DeleteUserUseCase_DeleteUserUseCase as DeleteUserUseCase };
|
|
53
46
|
|
|
54
47
|
//# sourceMappingURL=DeleteUserUseCase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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,4 +1,5 @@
|
|
|
1
1
|
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
-
|
|
2
|
+
const DeleteUserUseCase = createAbstraction("DeleteUserUseCase");
|
|
3
|
+
export { DeleteUserUseCase };
|
|
3
4
|
|
|
4
5
|
//# sourceMappingURL=abstractions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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,10 +1,11 @@
|
|
|
1
1
|
import { createFeature } from "@webiny/feature/api";
|
|
2
2
|
import { DeleteUserUseCase } from "./DeleteUserUseCase.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
const DeleteUserFeature = createFeature({
|
|
4
|
+
name: "DeleteUserFeature",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(DeleteUserUseCase);
|
|
7
|
+
}
|
|
8
8
|
});
|
|
9
|
+
export { DeleteUserFeature };
|
|
9
10
|
|
|
10
11
|
//# sourceMappingURL=feature.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"api/features/DeleteUser/feature.js","sources":["../../../../src/api/features/DeleteUser/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { DeleteUserUseCase } from \"./DeleteUserUseCase.js\";\n\nexport const DeleteUserFeature = createFeature({\n name: \"DeleteUserFeature\",\n register(container) {\n container.register(DeleteUserUseCase);\n }\n});\n"],"names":["DeleteUserFeature","createFeature","container","DeleteUserUseCase"],"mappings":";;AAGO,MAAMA,oBAAoBC,cAAc;IAC3C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|