@webiny/cognito 6.6.0-alpha.12 → 6.6.0-alpha.13
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/admin/Cognito.js +7 -1
- package/admin/Cognito.js.map +1 -1
- package/admin/presentation/Cognito/CognitoLoginScreen.js +9 -1
- package/admin/presentation/Cognito/CognitoLoginScreen.js.map +1 -1
- package/admin/presentation/Cognito/CognitoPresenter.d.ts +10 -1
- package/admin/presentation/Cognito/CognitoPresenter.js +50 -4
- package/admin/presentation/Cognito/CognitoPresenter.js.map +1 -1
- package/admin/presentation/Cognito/CognitoPresenter.test.d.ts +1 -0
- package/admin/presentation/Cognito/CognitoPresenter.test.js +180 -0
- package/admin/presentation/Cognito/CognitoPresenter.test.js.map +1 -0
- package/admin/presentation/Cognito/abstractions.d.ts +8 -1
- package/admin/presentation/Cognito/abstractions.js.map +1 -1
- package/admin/presentation/Cognito/components/FederatedProviders.js +1 -1
- package/admin/presentation/Cognito/components/FederatedProviders.js.map +1 -1
- package/admin/presentation/Cognito/components/NoTenantAccess.d.ts +23 -0
- package/admin/presentation/Cognito/components/NoTenantAccess.js +10 -0
- package/admin/presentation/Cognito/components/NoTenantAccess.js.map +1 -0
- package/admin/presentation/Cognito/components/SelectTenant.d.ts +26 -0
- package/admin/presentation/Cognito/components/SelectTenant.js +15 -0
- package/admin/presentation/Cognito/components/SelectTenant.js.map +1 -0
- package/admin/presentation/Cognito/components/SetNewPassword.js.map +1 -1
- package/admin/presentation/Cognito/components/SetupTotp.js +6 -5
- package/admin/presentation/Cognito/components/SetupTotp.js.map +1 -1
- package/admin/presentation/Cognito/components/View.js +5 -5
- package/admin/presentation/Cognito/components/View.js.map +1 -1
- package/admin/presentation/Cognito/components/index.d.ts +38 -0
- package/admin/presentation/Cognito/components/index.js +4 -0
- package/admin/presentation/Cognito/components/index.js.map +1 -1
- package/api/CognitoApiFeature.js +6 -0
- package/api/CognitoApiFeature.js.map +1 -1
- package/api/domain/errors.d.ts +68 -0
- package/api/domain/errors.js +73 -1
- package/api/domain/errors.js.map +1 -1
- package/api/features/CheckEmail/CheckEmailUseCase.d.ts +16 -0
- package/api/features/CheckEmail/CheckEmailUseCase.js +47 -0
- package/api/features/CheckEmail/CheckEmailUseCase.js.map +1 -0
- package/api/features/CheckEmail/abstractions.d.ts +29 -0
- package/api/features/CheckEmail/abstractions.js +5 -0
- package/api/features/CheckEmail/abstractions.js.map +1 -0
- package/api/features/CheckEmail/feature.d.ts +4 -0
- package/api/features/CheckEmail/feature.js +11 -0
- package/api/features/CheckEmail/feature.js.map +1 -0
- package/api/features/CheckEmail/index.d.ts +2 -0
- package/api/features/CheckEmail/index.js +2 -0
- package/api/features/CognitoIdp/CognitoIdentityProvider.d.ts +2 -0
- package/api/features/CognitoIdp/CognitoIdentityProvider.js +20 -0
- package/api/features/CognitoIdp/CognitoIdentityProvider.js.map +1 -1
- package/api/features/CognitoIdp/abstractions.d.ts +6 -0
- package/api/features/CognitoIdp/abstractions.js.map +1 -1
- package/api/features/CognitoService/CognitoService.d.ts +2 -1
- package/api/features/CognitoService/CognitoService.js +20 -5
- package/api/features/CognitoService/CognitoService.js.map +1 -1
- package/api/features/CognitoService/abstractions.d.ts +13 -2
- package/api/features/CognitoService/abstractions.js.map +1 -1
- package/api/features/CognitoService/adminDeleteSoftwareToken.d.ts +16 -0
- package/api/features/CognitoService/adminDeleteSoftwareToken.js +69 -0
- package/api/features/CognitoService/adminDeleteSoftwareToken.js.map +1 -0
- package/api/features/CognitoService/adminDeleteSoftwareToken.test.d.ts +1 -0
- package/api/features/CognitoService/adminDeleteSoftwareToken.test.js +91 -0
- package/api/features/CognitoService/adminDeleteSoftwareToken.test.js.map +1 -0
- package/api/features/CreateUser/CreateUserUseCase.d.ts +1 -2
- package/api/features/CreateUser/CreateUserUseCase.js +3 -3
- package/api/features/CreateUser/CreateUserUseCase.js.map +1 -1
- package/api/features/CreateUser/abstractions.d.ts +3 -1
- package/api/features/CreateUser/abstractions.js.map +1 -1
- package/api/features/DeleteUser/DeleteUserUseCase.d.ts +3 -1
- package/api/features/DeleteUser/DeleteUserUseCase.js +11 -2
- package/api/features/DeleteUser/DeleteUserUseCase.js.map +1 -1
- package/api/features/DeleteUser/abstractions.d.ts +2 -0
- package/api/features/DeleteUser/abstractions.js.map +1 -1
- package/api/features/LinkUser/LinkUserUseCase.d.ts +22 -0
- package/api/features/LinkUser/LinkUserUseCase.js +83 -0
- package/api/features/LinkUser/LinkUserUseCase.js.map +1 -0
- package/api/features/LinkUser/abstractions.d.ts +36 -0
- package/api/features/LinkUser/abstractions.js +5 -0
- package/api/features/LinkUser/abstractions.js.map +1 -0
- package/api/features/LinkUser/feature.d.ts +4 -0
- package/api/features/LinkUser/feature.js +11 -0
- package/api/features/LinkUser/feature.js.map +1 -0
- package/api/features/LinkUser/index.d.ts +2 -0
- package/api/features/LinkUser/index.js +2 -0
- package/api/features/ResetUserMfa/ResetUserMfaUseCase.d.ts +18 -0
- package/api/features/ResetUserMfa/ResetUserMfaUseCase.js +59 -0
- package/api/features/ResetUserMfa/ResetUserMfaUseCase.js.map +1 -0
- package/api/features/ResetUserMfa/abstractions.d.ts +24 -0
- package/api/features/ResetUserMfa/abstractions.js +5 -0
- package/api/features/ResetUserMfa/abstractions.js.map +1 -0
- package/api/features/ResetUserMfa/feature.d.ts +4 -0
- package/api/features/ResetUserMfa/feature.js +11 -0
- package/api/features/ResetUserMfa/feature.js.map +1 -0
- package/api/features/ResetUserMfa/index.d.ts +2 -0
- package/api/features/ResetUserMfa/index.js +2 -0
- package/api/features/UpdateUser/UpdateUserUseCase.d.ts +24 -1
- package/api/features/UpdateUser/UpdateUserUseCase.js +97 -4
- package/api/features/UpdateUser/UpdateUserUseCase.js.map +1 -1
- package/api/features/UpdateUser/abstractions.d.ts +7 -1
- package/api/features/UpdateUser/abstractions.js.map +1 -1
- package/api/features/UserInstaller/UserInstaller.d.ts +3 -1
- package/api/features/UserInstaller/UserInstaller.js +18 -3
- package/api/features/UserInstaller/UserInstaller.js.map +1 -1
- package/api/graphql/user.gql.js +87 -0
- package/api/graphql/user.gql.js.map +1 -1
- package/package.json +24 -19
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { UpdateUserUseCase as CoreUpdateUser } from "@webiny/api-core/features/users/UpdateUser/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";
|
|
5
|
+
import { AdminUsersRepository } from "@webiny/api-core/features/users/shared/abstractions.js";
|
|
6
|
+
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
7
|
+
import { TenantScopes } from "@webiny/api-core/features/tenancy/TenantScopes/index.js";
|
|
8
|
+
import { GetTenantByIdUseCase } from "@webiny/api-core/features/tenancy/GetTenantById/index.js";
|
|
4
9
|
import type { AdminUser } from "@webiny/api-core/types/users.js";
|
|
5
10
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
6
11
|
import { UpdateUserUseCase as UseCaseAbstraction } from "./abstractions.js";
|
|
@@ -11,9 +16,27 @@ declare class UpdateUserUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
|
11
16
|
private cognitoService;
|
|
12
17
|
private updateUserUseCase;
|
|
13
18
|
private getUserUseCase;
|
|
19
|
+
private findUserRecords;
|
|
20
|
+
private repository;
|
|
21
|
+
private tenantContext;
|
|
22
|
+
private tenantScopes;
|
|
23
|
+
private getTenantById;
|
|
14
24
|
private updateAttributes;
|
|
15
|
-
constructor(identityContext: IdentityContext.Interface, cognitoService: CognitoService.Interface, updateUserUseCase: CoreUpdateUser.Interface, getUserUseCase: GetUserUseCase.Interface);
|
|
25
|
+
constructor(identityContext: IdentityContext.Interface, cognitoService: CognitoService.Interface, updateUserUseCase: CoreUpdateUser.Interface, getUserUseCase: GetUserUseCase.Interface, findUserRecords: FindUserRecordsUseCase.Interface, repository: AdminUsersRepository.Interface, tenantContext: TenantContext.Interface, tenantScopes: TenantScopes.Interface, getTenantById: GetTenantByIdUseCase.Interface);
|
|
16
26
|
execute(id: string, input: UpdateAdminUserInput): Promise<Result<AdminUser, UseCaseAbstraction.Error>>;
|
|
27
|
+
private syncProfile;
|
|
28
|
+
/**
|
|
29
|
+
* Puts the records back and fails with the original error. A record that can't be put back
|
|
30
|
+
* is tried again after each delay in `ROLLBACK_RETRY_DELAYS`. When some records still can't
|
|
31
|
+
* be put back, the error says which tenants no longer match the Cognito account.
|
|
32
|
+
*/
|
|
33
|
+
private rollback;
|
|
34
|
+
/**
|
|
35
|
+
* Writes a record in its own tenant's scope: the person's records in other tenants are written
|
|
36
|
+
* by those tenants' storage.
|
|
37
|
+
*/
|
|
38
|
+
private updateRecord;
|
|
39
|
+
private writeRecords;
|
|
17
40
|
}
|
|
18
41
|
export declare const UpdateUserUseCase: typeof UpdateUserUseCaseImpl & {
|
|
19
42
|
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IUpdateUserUseCase>;
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { UpdateUserUseCase } from "@webiny/api-core/features/users/UpdateUser/index.js";
|
|
3
3
|
import { GetUserUseCase } from "@webiny/api-core/features/users/GetUser/index.js";
|
|
4
|
-
import {
|
|
4
|
+
import { FindUserRecordsUseCase } from "@webiny/api-core/features/users/FindUserRecords/index.js";
|
|
5
|
+
import { AdminUsersRepository } from "@webiny/api-core/features/users/shared/abstractions.js";
|
|
6
|
+
import { NotAuthorizedError, UserStorageError, UserValidationError } from "@webiny/api-core/features/users/shared/errors.js";
|
|
7
|
+
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
8
|
+
import { TenantScopes } from "@webiny/api-core/features/tenancy/TenantScopes/index.js";
|
|
9
|
+
import { GetTenantByIdUseCase } from "@webiny/api-core/features/tenancy/GetTenantById/index.js";
|
|
5
10
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
6
11
|
import { UpdateUserUseCase as external_abstractions_js_UpdateUserUseCase } from "./abstractions.js";
|
|
7
12
|
import { Username } from "../../domain/Username.js";
|
|
8
|
-
import { CognitoUpdateUserError } from "../../domain/errors.js";
|
|
13
|
+
import { CognitoSharedAccountError, CognitoUpdateRollbackError, CognitoUpdateUserError } from "../../domain/errors.js";
|
|
9
14
|
import { updateAdminUserValidation } from "./schema.js";
|
|
10
15
|
import { CognitoService } from "../CognitoService/index.js";
|
|
11
16
|
const defaultUpdateAttributes = {
|
|
@@ -13,12 +18,22 @@ const defaultUpdateAttributes = {
|
|
|
13
18
|
given_name: "firstName",
|
|
14
19
|
preferred_username: "email"
|
|
15
20
|
};
|
|
21
|
+
const ROLLBACK_RETRY_DELAYS = [
|
|
22
|
+
100,
|
|
23
|
+
400
|
|
24
|
+
];
|
|
25
|
+
const sleep = (ms)=>new Promise((resolve)=>setTimeout(resolve, ms));
|
|
16
26
|
class UpdateUserUseCaseImpl {
|
|
17
|
-
constructor(identityContext, cognitoService, updateUserUseCase, getUserUseCase){
|
|
27
|
+
constructor(identityContext, cognitoService, updateUserUseCase, getUserUseCase, findUserRecords, repository, tenantContext, tenantScopes, getTenantById){
|
|
18
28
|
this.identityContext = identityContext;
|
|
19
29
|
this.cognitoService = cognitoService;
|
|
20
30
|
this.updateUserUseCase = updateUserUseCase;
|
|
21
31
|
this.getUserUseCase = getUserUseCase;
|
|
32
|
+
this.findUserRecords = findUserRecords;
|
|
33
|
+
this.repository = repository;
|
|
34
|
+
this.tenantContext = tenantContext;
|
|
35
|
+
this.tenantScopes = tenantScopes;
|
|
36
|
+
this.getTenantById = getTenantById;
|
|
22
37
|
this.updateAttributes = defaultUpdateAttributes;
|
|
23
38
|
}
|
|
24
39
|
async execute(id, input) {
|
|
@@ -34,9 +49,30 @@ class UpdateUserUseCaseImpl {
|
|
|
34
49
|
if (getUserResult.isFail()) return Result.fail(getUserResult.error);
|
|
35
50
|
const originalUser = getUserResult.value;
|
|
36
51
|
if (void 0 !== data.email && data.email !== originalUser.email) return Result.fail(new UserValidationError("The email address cannot be changed."));
|
|
52
|
+
const profileChanged = void 0 !== data.firstName && data.firstName !== originalUser.firstName || void 0 !== data.lastName && data.lastName !== originalUser.lastName;
|
|
53
|
+
let otherRecords = [];
|
|
54
|
+
if (profileChanged || password) {
|
|
55
|
+
const recordsResult = await this.findUserRecords.execute(id, {
|
|
56
|
+
exhaustive: true
|
|
57
|
+
});
|
|
58
|
+
if (recordsResult.isFail()) return Result.fail(recordsResult.error);
|
|
59
|
+
otherRecords = recordsResult.value.filter((record)=>record.tenant !== originalUser.tenant);
|
|
60
|
+
const isSelf = this.identityContext.getIdentity().id === id;
|
|
61
|
+
if (otherRecords.length > 0 && !isSelf) return Result.fail(new CognitoSharedAccountError(id));
|
|
62
|
+
}
|
|
37
63
|
const updateUserResult = await this.updateUserUseCase.execute(id, userDataWithoutPassword);
|
|
38
64
|
if (updateUserResult.isFail()) return Result.fail(updateUserResult.error);
|
|
39
65
|
const updatedUser = updateUserResult.value;
|
|
66
|
+
const writtenRecords = profileChanged ? [
|
|
67
|
+
originalUser,
|
|
68
|
+
...otherRecords
|
|
69
|
+
] : [
|
|
70
|
+
originalUser
|
|
71
|
+
];
|
|
72
|
+
if (profileChanged) {
|
|
73
|
+
const syncResult = await this.syncProfile(updatedUser, otherRecords);
|
|
74
|
+
if (syncResult.isFail()) return this.rollback(writtenRecords, syncResult.error);
|
|
75
|
+
}
|
|
40
76
|
try {
|
|
41
77
|
const attributes = {};
|
|
42
78
|
Object.keys(this.updateAttributes).forEach((attr)=>{
|
|
@@ -45,12 +81,64 @@ class UpdateUserUseCaseImpl {
|
|
|
45
81
|
attributes[attr] = attrValue;
|
|
46
82
|
});
|
|
47
83
|
await this.cognitoService.updateUserAttributes(Username.fromUser(originalUser), attributes);
|
|
84
|
+
} catch (cognitoError) {
|
|
85
|
+
return this.rollback(writtenRecords, new CognitoUpdateUserError(cognitoError));
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
48
88
|
if (password) await this.cognitoService.setPermanentPassword(Username.fromUser(updatedUser), password);
|
|
49
89
|
return Result.ok(updatedUser);
|
|
50
90
|
} catch (cognitoError) {
|
|
51
91
|
return Result.fail(new CognitoUpdateUserError(cognitoError));
|
|
52
92
|
}
|
|
53
93
|
}
|
|
94
|
+
async syncProfile(user, records) {
|
|
95
|
+
return this.writeRecords(records.map((record)=>({
|
|
96
|
+
...record,
|
|
97
|
+
email: user.email,
|
|
98
|
+
firstName: user.firstName,
|
|
99
|
+
lastName: user.lastName,
|
|
100
|
+
displayName: user.displayName
|
|
101
|
+
})));
|
|
102
|
+
}
|
|
103
|
+
async rollback(records, error) {
|
|
104
|
+
let pending = records;
|
|
105
|
+
let rollbackErrors = [];
|
|
106
|
+
for(let attempt = 0;; attempt++){
|
|
107
|
+
const results = await Promise.all(pending.map((record)=>this.updateRecord(record)));
|
|
108
|
+
const failed = [];
|
|
109
|
+
rollbackErrors = [];
|
|
110
|
+
results.forEach((result, index)=>{
|
|
111
|
+
if (result.isFail()) {
|
|
112
|
+
failed.push(pending[index]);
|
|
113
|
+
rollbackErrors.push(result.error);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
pending = failed;
|
|
117
|
+
if (0 === pending.length || attempt >= ROLLBACK_RETRY_DELAYS.length) break;
|
|
118
|
+
await sleep(ROLLBACK_RETRY_DELAYS[attempt]);
|
|
119
|
+
}
|
|
120
|
+
if (pending.length > 0) return Result.fail(new CognitoUpdateRollbackError(error, pending.map((record)=>record.tenant), rollbackErrors));
|
|
121
|
+
return Result.fail(error);
|
|
122
|
+
}
|
|
123
|
+
async updateRecord(record) {
|
|
124
|
+
if (record.tenant === this.tenantContext.getTenant().id) return this.repository.update(record);
|
|
125
|
+
const tenantResult = await this.getTenantById.execute(record.tenant);
|
|
126
|
+
if (tenantResult.isFail()) {
|
|
127
|
+
const error = tenantResult.error;
|
|
128
|
+
return Result.fail(new UserStorageError("UNKNOWN" === error.type ? error.cause : new Error(`Tenant "${record.tenant}" was not found.`)));
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
return await this.tenantScopes.withTenant(tenantResult.value, (scope)=>scope.resolve(AdminUsersRepository).update(record));
|
|
132
|
+
} catch (error) {
|
|
133
|
+
return Result.fail(new UserStorageError(error));
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
async writeRecords(records) {
|
|
137
|
+
const results = await Promise.all(records.map((record)=>this.updateRecord(record)));
|
|
138
|
+
const failed = results.find((result)=>result.isFail());
|
|
139
|
+
if (failed && failed.isFail()) return Result.fail(failed.error);
|
|
140
|
+
return Result.ok();
|
|
141
|
+
}
|
|
54
142
|
}
|
|
55
143
|
const UpdateUserUseCase_UpdateUserUseCase = external_abstractions_js_UpdateUserUseCase.createImplementation({
|
|
56
144
|
implementation: UpdateUserUseCaseImpl,
|
|
@@ -58,7 +146,12 @@ const UpdateUserUseCase_UpdateUserUseCase = external_abstractions_js_UpdateUserU
|
|
|
58
146
|
IdentityContext,
|
|
59
147
|
CognitoService,
|
|
60
148
|
UpdateUserUseCase,
|
|
61
|
-
GetUserUseCase
|
|
149
|
+
GetUserUseCase,
|
|
150
|
+
FindUserRecordsUseCase,
|
|
151
|
+
AdminUsersRepository,
|
|
152
|
+
TenantContext,
|
|
153
|
+
TenantScopes,
|
|
154
|
+
GetTenantByIdUseCase
|
|
62
155
|
]
|
|
63
156
|
});
|
|
64
157
|
export { UpdateUserUseCase_UpdateUserUseCase as UpdateUserUseCase };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api/features/UpdateUser/UpdateUserUseCase.js","sources":["../../../../src/api/features/UpdateUser/UpdateUserUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { UpdateUserUseCase as CoreUpdateUser } from \"@webiny/api-core/features/users/UpdateUser/index.js\";\nimport { GetUserUseCase } from \"@webiny/api-core/features/users/GetUser/index.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 { UpdateUserUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { Username } from \"~/api/domain/Username.js\";\nimport { CognitoUpdateUserError } from \"~/api/domain/errors.js\";\nimport { updateAdminUserValidation } from \"./schema.js\";\nimport type { UpdateAdminUserInput } from \"./abstractions.js\";\nimport { CognitoService } from \"~/api/features/CognitoService/index.js\";\n\ntype MappedAttrType = (user: AdminUser) => string | keyof AdminUser;\n\nconst defaultUpdateAttributes = {\n family_name: \"lastName\",\n given_name: \"firstName\",\n preferred_username: \"email\"\n};\n\nclass UpdateUserUseCaseImpl implements UseCaseAbstraction.Interface {\n private updateAttributes: Record<string, string | MappedAttrType>;\n\n constructor(\n private identityContext: IdentityContext.Interface,\n private cognitoService: CognitoService.Interface,\n private updateUserUseCase: CoreUpdateUser.Interface,\n private getUserUseCase: GetUserUseCase.Interface\n ) {\n this.updateAttributes = defaultUpdateAttributes;\n }\n\n async execute(\n id: string,\n input: UpdateAdminUserInput\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 = updateAdminUserValidation.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 // Get original user to know the email before update\n const getUserResult = await this.getUserUseCase.execute({ id });\n if (getUserResult.isFail()) {\n return Result.fail(getUserResult.error);\n }\n\n const originalUser = getUserResult.value;\n\n /*\n * The email is the user pool username, which Cognito cannot change, and the sign-in key.\n * api-core would drop it silently; saying so is better than reporting a change that did not\n * happen. The forms send the current address back unchanged, which is not a change.\n */\n if (data.email !== undefined && data.email !== originalUser.email) {\n return Result.fail(new UserValidationError(\"The email address cannot be changed.\"));\n }\n\n // Update user in api-core\n const updateUserResult = await this.updateUserUseCase.execute(id, userDataWithoutPassword);\n if (updateUserResult.isFail()) {\n return Result.fail(updateUserResult.error);\n }\n\n const updatedUser = updateUserResult.value;\n\n // Update user in Cognito\n try {\n // Build new attributes\n const attributes: Record<string, string> = {};\n\n Object.keys(this.updateAttributes).forEach(attr => {\n const mappedAttr = this.updateAttributes[\n attr as keyof typeof this.updateAttributes\n ] as MappedAttrType;\n const attrValue =\n typeof mappedAttr === \"function\"\n ? mappedAttr(updatedUser)\n : updatedUser[mappedAttr];\n attributes[attr] = attrValue;\n });\n\n await this.cognitoService.updateUserAttributes(\n Username.fromUser(originalUser),\n attributes\n );\n\n // Update password if provided\n if (password) {\n await this.cognitoService.setPermanentPassword(\n Username.fromUser(updatedUser),\n password\n );\n }\n\n return Result.ok(updatedUser);\n } catch (cognitoError) {\n return Result.fail(new CognitoUpdateUserError(cognitoError as Error));\n }\n }\n}\n\nexport const UpdateUserUseCase = UseCaseAbstraction.createImplementation({\n implementation: UpdateUserUseCaseImpl,\n dependencies: [IdentityContext, CognitoService, CoreUpdateUser, GetUserUseCase]\n});\n"],"names":["defaultUpdateAttributes","UpdateUserUseCaseImpl","identityContext","cognitoService","updateUserUseCase","getUserUseCase","id","input","permission","Result","NotAuthorizedError","validation","updateAdminUserValidation","UserValidationError","data","password","userDataWithoutPassword","getUserResult","originalUser","undefined","updateUserResult","updatedUser","attributes","Object","attr","mappedAttr","attrValue","Username","cognitoError","CognitoUpdateUserError","UpdateUserUseCase","UseCaseAbstraction","IdentityContext","CognitoService","CoreUpdateUser","GetUserUseCase"],"mappings":";;;;;;;;;;AAkBA,MAAMA,0BAA0B;IAC5B,aAAa;IACb,YAAY;IACZ,oBAAoB;AACxB;AAEA,MAAMC;IAGF,YACYC,eAA0C,EAC1CC,cAAwC,EACxCC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D,MAAME,YACF,AAAsB,cAAtB,OAAOD,aACDA,WAAWJ,eACXA,WAAW,CAACI,WAAW;gBACjCH,UAAU,CAACE,KAAK,GAAGE;YACvB;YAEA,MAAM,IAAI,CAAC,cAAc,CAAC,oBAAoB,CAC1CC,SAAS,QAAQ,CAACT,eAClBI;YAIJ,IAAIP,UACA,MAAM,IAAI,CAAC,cAAc,CAAC,oBAAoB,CAC1CY,SAAS,QAAQ,CAACN,cAClBN;YAIR,OAAON,OAAO,EAAE,CAACY;QACrB,EAAE,OAAOO,cAAc;YACnB,OAAOnB,OAAO,IAAI,CAAC,IAAIoB,uBAAuBD;QAClD;IACJ;AACJ;AAEO,MAAME,sCAAoBC,2CAAAA,oBAAuC,CAAC;IACrE,gBAAgB9B;IAChB,cAAc;QAAC+B;QAAiBC;QAAgBC;QAAgBC;KAAe;AACnF"}
|
|
1
|
+
{"version":3,"file":"api/features/UpdateUser/UpdateUserUseCase.js","sources":["../../../../src/api/features/UpdateUser/UpdateUserUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { UpdateUserUseCase as CoreUpdateUser } from \"@webiny/api-core/features/users/UpdateUser/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 { AdminUsersRepository } from \"@webiny/api-core/features/users/shared/abstractions.js\";\nimport {\n NotAuthorizedError,\n UserStorageError,\n UserValidationError\n} from \"@webiny/api-core/features/users/shared/errors.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { TenantScopes } from \"@webiny/api-core/features/tenancy/TenantScopes/index.js\";\nimport { GetTenantByIdUseCase } from \"@webiny/api-core/features/tenancy/GetTenantById/index.js\";\nimport type { AdminUser } from \"@webiny/api-core/types/users.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { UpdateUserUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { Username } from \"~/api/domain/Username.js\";\nimport {\n CognitoSharedAccountError,\n CognitoUpdateRollbackError,\n CognitoUpdateUserError\n} from \"~/api/domain/errors.js\";\nimport { updateAdminUserValidation } from \"./schema.js\";\nimport type { UpdateAdminUserInput } from \"./abstractions.js\";\nimport { CognitoService } from \"~/api/features/CognitoService/index.js\";\n\ntype MappedAttrType = (user: AdminUser) => string | keyof AdminUser;\n\nconst defaultUpdateAttributes = {\n family_name: \"lastName\",\n given_name: \"firstName\",\n preferred_username: \"email\"\n};\n\n/**\n * How long to wait, in milliseconds, before each retry of a rollback write that failed.\n */\nconst ROLLBACK_RETRY_DELAYS = [100, 400];\n\nconst sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));\n\nclass UpdateUserUseCaseImpl implements UseCaseAbstraction.Interface {\n private updateAttributes: Record<string, string | MappedAttrType>;\n\n constructor(\n private identityContext: IdentityContext.Interface,\n private cognitoService: CognitoService.Interface,\n private updateUserUseCase: CoreUpdateUser.Interface,\n private getUserUseCase: GetUserUseCase.Interface,\n private findUserRecords: FindUserRecordsUseCase.Interface,\n private repository: AdminUsersRepository.Interface,\n private tenantContext: TenantContext.Interface,\n private tenantScopes: TenantScopes.Interface,\n private getTenantById: GetTenantByIdUseCase.Interface\n ) {\n this.updateAttributes = defaultUpdateAttributes;\n }\n\n async execute(\n id: string,\n input: UpdateAdminUserInput\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 = updateAdminUserValidation.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 // Get original user to know the email before update\n const getUserResult = await this.getUserUseCase.execute({ id });\n if (getUserResult.isFail()) {\n return Result.fail(getUserResult.error);\n }\n\n const originalUser = getUserResult.value;\n\n /*\n * The email is the user pool username, which Cognito cannot change, and the sign-in key.\n * api-core would drop it silently; saying so is better than reporting a change that did not\n * happen. The forms send the current address back unchanged, which is not a change.\n */\n if (data.email !== undefined && data.email !== originalUser.email) {\n return Result.fail(new UserValidationError(\"The email address cannot be changed.\"));\n }\n\n /**\n * Name, email and password belong to the person's sign-in account, which all of their\n * tenants share. In a shared account, only the person changes them, and every tenant's\n * record gets the new name and email.\n */\n const profileChanged =\n (data.firstName !== undefined && data.firstName !== originalUser.firstName) ||\n (data.lastName !== undefined && data.lastName !== originalUser.lastName);\n\n let otherRecords: AdminUser[] = [];\n if (profileChanged || password) {\n const recordsResult = await this.findUserRecords.execute(id, { exhaustive: true });\n if (recordsResult.isFail()) {\n return Result.fail(recordsResult.error);\n }\n\n otherRecords = recordsResult.value.filter(\n record => record.tenant !== originalUser.tenant\n );\n\n const isSelf = this.identityContext.getIdentity().id === id;\n if (otherRecords.length > 0 && !isSelf) {\n return Result.fail(new CognitoSharedAccountError(id));\n }\n }\n\n // Update user in api-core\n const updateUserResult = await this.updateUserUseCase.execute(id, userDataWithoutPassword);\n if (updateUserResult.isFail()) {\n return Result.fail(updateUserResult.error);\n }\n\n const updatedUser = updateUserResult.value;\n\n /**\n * The records are written before Cognito, so a failed write never touches the sign-in\n * account. If the sync or Cognito fails, every record goes back to how it was, so the\n * records keep matching the sign-in account. A record that can't be put back is retried\n * with a backoff; if it still fails, the error names its tenant.\n */\n const writtenRecords = profileChanged ? [originalUser, ...otherRecords] : [originalUser];\n\n if (profileChanged) {\n const syncResult = await this.syncProfile(updatedUser, otherRecords);\n if (syncResult.isFail()) {\n return this.rollback(writtenRecords, syncResult.error);\n }\n }\n\n // Update user in Cognito\n try {\n // Build new attributes\n const attributes: Record<string, string> = {};\n\n Object.keys(this.updateAttributes).forEach(attr => {\n const mappedAttr = this.updateAttributes[\n attr as keyof typeof this.updateAttributes\n ] as MappedAttrType;\n const attrValue =\n typeof mappedAttr === \"function\"\n ? mappedAttr(updatedUser)\n : updatedUser[mappedAttr];\n attributes[attr] = attrValue;\n });\n\n await this.cognitoService.updateUserAttributes(\n Username.fromUser(originalUser),\n attributes\n );\n } catch (cognitoError) {\n return this.rollback(writtenRecords, new CognitoUpdateUserError(cognitoError as Error));\n }\n\n // The name and email are now in Cognito, so a failed password change keeps the records.\n try {\n if (password) {\n await this.cognitoService.setPermanentPassword(\n Username.fromUser(updatedUser),\n password\n );\n }\n\n return Result.ok(updatedUser);\n } catch (cognitoError) {\n return Result.fail(new CognitoUpdateUserError(cognitoError as Error));\n }\n }\n\n private async syncProfile(\n user: AdminUser,\n records: AdminUser[]\n ): Promise<Result<void, AdminUsersRepository.Error>> {\n return this.writeRecords(\n records.map(record => ({\n ...record,\n email: user.email,\n firstName: user.firstName,\n lastName: user.lastName,\n displayName: user.displayName\n }))\n );\n }\n\n /**\n * Puts the records back and fails with the original error. A record that can't be put back\n * is tried again after each delay in `ROLLBACK_RETRY_DELAYS`. When some records still can't\n * be put back, the error says which tenants no longer match the Cognito account.\n */\n private async rollback(\n records: AdminUser[],\n error: UseCaseAbstraction.Error\n ): Promise<Result<AdminUser, UseCaseAbstraction.Error>> {\n let pending = records;\n let rollbackErrors: Error[] = [];\n\n for (let attempt = 0; ; attempt++) {\n const results = await Promise.all(pending.map(record => this.updateRecord(record)));\n\n const failed: AdminUser[] = [];\n rollbackErrors = [];\n results.forEach((result, index) => {\n if (result.isFail()) {\n failed.push(pending[index]);\n rollbackErrors.push(result.error);\n }\n });\n\n pending = failed;\n if (pending.length === 0 || attempt >= ROLLBACK_RETRY_DELAYS.length) {\n break;\n }\n\n await sleep(ROLLBACK_RETRY_DELAYS[attempt]);\n }\n\n if (pending.length > 0) {\n return Result.fail(\n new CognitoUpdateRollbackError(\n error,\n pending.map(record => record.tenant),\n rollbackErrors\n )\n );\n }\n\n return Result.fail(error);\n }\n\n /**\n * Writes a record in its own tenant's scope: the person's records in other tenants are written\n * by those tenants' storage.\n */\n private async updateRecord(\n record: AdminUser\n ): Promise<Result<AdminUser, AdminUsersRepository.Error>> {\n if (record.tenant === this.tenantContext.getTenant().id) {\n return this.repository.update(record);\n }\n\n const tenantResult = await this.getTenantById.execute(record.tenant);\n if (tenantResult.isFail()) {\n const error = tenantResult.error;\n return Result.fail(\n new UserStorageError(\n error.type === \"UNKNOWN\"\n ? error.cause\n : new Error(`Tenant \"${record.tenant}\" was not found.`)\n )\n );\n }\n\n try {\n return await this.tenantScopes.withTenant(tenantResult.value, scope => {\n return scope.resolve(AdminUsersRepository).update(record);\n });\n } catch (error) {\n return Result.fail(new UserStorageError(error as Error));\n }\n }\n\n private async writeRecords(\n records: AdminUser[]\n ): Promise<Result<void, AdminUsersRepository.Error>> {\n const results = await Promise.all(records.map(record => this.updateRecord(record)));\n\n const failed = results.find(result => result.isFail());\n if (failed && failed.isFail()) {\n return Result.fail(failed.error);\n }\n\n return Result.ok();\n }\n}\n\nexport const UpdateUserUseCase = UseCaseAbstraction.createImplementation({\n implementation: UpdateUserUseCaseImpl,\n dependencies: [\n IdentityContext,\n CognitoService,\n CoreUpdateUser,\n GetUserUseCase,\n FindUserRecordsUseCase,\n AdminUsersRepository,\n TenantContext,\n TenantScopes,\n GetTenantByIdUseCase\n ]\n});\n"],"names":["defaultUpdateAttributes","ROLLBACK_RETRY_DELAYS","sleep","ms","Promise","resolve","setTimeout","UpdateUserUseCaseImpl","identityContext","cognitoService","updateUserUseCase","getUserUseCase","findUserRecords","repository","tenantContext","tenantScopes","getTenantById","id","input","permission","Result","NotAuthorizedError","validation","updateAdminUserValidation","UserValidationError","data","password","userDataWithoutPassword","getUserResult","originalUser","undefined","profileChanged","otherRecords","recordsResult","record","isSelf","CognitoSharedAccountError","updateUserResult","updatedUser","writtenRecords","syncResult","attributes","Object","attr","mappedAttr","attrValue","Username","cognitoError","CognitoUpdateUserError","user","records","error","pending","rollbackErrors","attempt","results","failed","result","index","CognitoUpdateRollbackError","tenantResult","UserStorageError","Error","scope","AdminUsersRepository","UpdateUserUseCase","UseCaseAbstraction","IdentityContext","CognitoService","CoreUpdateUser","GetUserUseCase","FindUserRecordsUseCase","TenantContext","TenantScopes","GetTenantByIdUseCase"],"mappings":";;;;;;;;;;;;;;;AA4BA,MAAMA,0BAA0B;IAC5B,aAAa;IACb,YAAY;IACZ,oBAAoB;AACxB;AAKA,MAAMC,wBAAwB;IAAC;IAAK;CAAI;AAExC,MAAMC,QAAQ,CAACC,KAAe,IAAIC,QAAQC,CAAAA,UAAWC,WAAWD,SAASF;AAEzE,MAAMI;IAGF,YACYC,eAA0C,EAC1CC,cAAwC,EACxCC,iBAA2C,EAC3CC,cAAwC,EACxCC,eAAiD,EACjDC,UAA0C,EAC1CC,aAAsC,EACtCC,YAAoC,EACpCC,aAA6C,CACvD;aATUR,eAAe,GAAfA;aACAC,cAAc,GAAdA;aACAC,iBAAiB,GAAjBA;aACAC,cAAc,GAAdA;aACAC,eAAe,GAAfA;aACAC,UAAU,GAAVA;aACAC,aAAa,GAAbA;aACAC,YAAY,GAAZA;aACAC,aAAa,GAAbA;QAER,IAAI,CAAC,gBAAgB,GAAGhB;IAC5B;IAEA,MAAM,QACFiB,EAAU,EACVC,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;QAGjD,MAAMG,gBAAgB,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC;YAAEX;QAAG;QAC7D,IAAIW,cAAc,MAAM,IACpB,OAAOR,OAAO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,MAAc,aACVD,OAAoB,EAC6B;QACjD,MAAMK,UAAU,MAAMnD,QAAQ,GAAG,CAAC8C,QAAQ,GAAG,CAAChB,CAAAA,SAAU,IAAI,CAAC,YAAY,CAACA;QAE1E,MAAMsB,SAASD,QAAQ,IAAI,CAACE,CAAAA,SAAUA,OAAO,MAAM;QACnD,IAAID,UAAUA,OAAO,MAAM,IACvB,OAAOpC,OAAO,IAAI,CAACoC,OAAO,KAAK;QAGnC,OAAOpC,OAAO,EAAE;IACpB;AACJ;AAEO,MAAM6C,sCAAoBC,2CAAAA,oBAAuC,CAAC;IACrE,gBAAgB3D;IAChB,cAAc;QACV4D;QACAC;QACAC;QACAC;QACAC;QACAP;QACAQ;QACAC;QACAC;KACH;AACL"}
|
|
@@ -2,7 +2,9 @@ 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 { UpdateUserUseCase as CoreUpdateUserUseCase } from "@webiny/api-core/features/users/UpdateUser/index.js";
|
|
5
|
-
import type {
|
|
5
|
+
import type { FindUserRecordsUseCase } from "@webiny/api-core/features/users/FindUserRecords/index.js";
|
|
6
|
+
import type { RepositoryError } from "@webiny/api-core/features/users/shared/abstractions.js";
|
|
7
|
+
import type { CognitoSharedAccountError, CognitoUpdateRollbackError, CognitoUpdateUserError } from "../../../api/domain/errors.js";
|
|
6
8
|
export interface UpdateAdminUserInput {
|
|
7
9
|
displayName?: string;
|
|
8
10
|
email?: string;
|
|
@@ -19,6 +21,10 @@ export interface IUpdateUserUseCaseErrors {
|
|
|
19
21
|
emailTaken: EmailTakenError;
|
|
20
22
|
updateAdminUser: CoreUpdateUserUseCase.Error;
|
|
21
23
|
cognitoUpdateUser: CognitoUpdateUserError;
|
|
24
|
+
updateRollback: CognitoUpdateRollbackError;
|
|
25
|
+
sharedAccount: CognitoSharedAccountError;
|
|
26
|
+
findUserRecords: FindUserRecordsUseCase.Error;
|
|
27
|
+
repository: RepositoryError;
|
|
22
28
|
}
|
|
23
29
|
type IUpdateAdminUserError = IUpdateUserUseCaseErrors[keyof IUpdateUserUseCaseErrors];
|
|
24
30
|
export interface IUpdateUserUseCase {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api/features/UpdateUser/abstractions.js","sources":["../../../../src/api/features/UpdateUser/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 { UpdateUserUseCase as CoreUpdateUserUseCase } from \"@webiny/api-core/features/users/UpdateUser/index.js\";\nimport type {
|
|
1
|
+
{"version":3,"file":"api/features/UpdateUser/abstractions.js","sources":["../../../../src/api/features/UpdateUser/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 { UpdateUserUseCase as CoreUpdateUserUseCase } from \"@webiny/api-core/features/users/UpdateUser/index.js\";\nimport type { FindUserRecordsUseCase } from \"@webiny/api-core/features/users/FindUserRecords/index.js\";\nimport type { RepositoryError } from \"@webiny/api-core/features/users/shared/abstractions.js\";\nimport type {\n CognitoSharedAccountError,\n CognitoUpdateRollbackError,\n CognitoUpdateUserError\n} from \"~/api/domain/errors.js\";\n\nexport interface UpdateAdminUserInput {\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 IUpdateUserUseCaseErrors {\n authorization: NotAuthorizedError;\n validation: UserValidationError;\n emailTaken: EmailTakenError;\n updateAdminUser: CoreUpdateUserUseCase.Error;\n cognitoUpdateUser: CognitoUpdateUserError;\n updateRollback: CognitoUpdateRollbackError;\n sharedAccount: CognitoSharedAccountError;\n findUserRecords: FindUserRecordsUseCase.Error;\n repository: RepositoryError;\n}\n\ntype IUpdateAdminUserError = IUpdateUserUseCaseErrors[keyof IUpdateUserUseCaseErrors];\n\nexport interface IUpdateUserUseCase {\n execute(\n id: string,\n input: UpdateAdminUserInput\n ): Promise<Result<AdminUser, IUpdateAdminUserError>>;\n}\n\nexport const UpdateUserUseCase = createAbstraction<IUpdateUserUseCase>(\"UpdateUserUseCase\");\n\nexport namespace UpdateUserUseCase {\n export type Interface = IUpdateUserUseCase;\n export type Input = UpdateAdminUserInput;\n export type Error = IUpdateAdminUserError;\n}\n"],"names":["UpdateUserUseCase","createAbstraction"],"mappings":";AAiDO,MAAMA,oBAAoBC,kBAAsC"}
|
|
@@ -3,6 +3,7 @@ import { AppInstaller } from "@webiny/api-core/features/tenancy/InstallTenant/in
|
|
|
3
3
|
import { GetRoleUseCase } from "@webiny/api-core/features/security/roles/GetRole/index.js";
|
|
4
4
|
import { DeleteUserUseCase } from "../../../api/features/DeleteUser/index.js";
|
|
5
5
|
import { CreateUserUseCase } from "../../../api/features/CreateUser/index.js";
|
|
6
|
+
import { LinkUserUseCase } from "../../../api/features/LinkUser/index.js";
|
|
6
7
|
interface UserInstallationData {
|
|
7
8
|
firstName: string;
|
|
8
9
|
lastName: string;
|
|
@@ -12,12 +13,13 @@ interface UserInstallationData {
|
|
|
12
13
|
declare class UsersInstallerImpl implements AppInstaller.Interface<UserInstallationData> {
|
|
13
14
|
private getRole;
|
|
14
15
|
private createUserUseCase;
|
|
16
|
+
private linkUserUseCase;
|
|
15
17
|
private deleteUserUseCase;
|
|
16
18
|
readonly alwaysRun = false;
|
|
17
19
|
readonly appName = "Cognito";
|
|
18
20
|
readonly dependsOn: string[];
|
|
19
21
|
private createdUser;
|
|
20
|
-
constructor(getRole: GetRoleUseCase.Interface, createUserUseCase: CreateUserUseCase.Interface, deleteUserUseCase: DeleteUserUseCase.Interface);
|
|
22
|
+
constructor(getRole: GetRoleUseCase.Interface, createUserUseCase: CreateUserUseCase.Interface, linkUserUseCase: LinkUserUseCase.Interface, deleteUserUseCase: DeleteUserUseCase.Interface);
|
|
21
23
|
install(_: Tenant, data: UserInstallationData): Promise<void>;
|
|
22
24
|
uninstall(): Promise<void>;
|
|
23
25
|
}
|
|
@@ -2,10 +2,12 @@ import { AppInstaller } from "@webiny/api-core/features/tenancy/InstallTenant/in
|
|
|
2
2
|
import { GetRoleUseCase } from "@webiny/api-core/features/security/roles/GetRole/index.js";
|
|
3
3
|
import { DeleteUserUseCase } from "../DeleteUser/index.js";
|
|
4
4
|
import { CreateUserUseCase } from "../CreateUser/index.js";
|
|
5
|
+
import { LinkUserUseCase } from "../LinkUser/index.js";
|
|
5
6
|
class UsersInstallerImpl {
|
|
6
|
-
constructor(getRole, createUserUseCase, deleteUserUseCase){
|
|
7
|
+
constructor(getRole, createUserUseCase, linkUserUseCase, deleteUserUseCase){
|
|
7
8
|
this.getRole = getRole;
|
|
8
9
|
this.createUserUseCase = createUserUseCase;
|
|
10
|
+
this.linkUserUseCase = linkUserUseCase;
|
|
9
11
|
this.deleteUserUseCase = deleteUserUseCase;
|
|
10
12
|
this.alwaysRun = false;
|
|
11
13
|
this.appName = "Cognito";
|
|
@@ -28,8 +30,20 @@ class UsersInstallerImpl {
|
|
|
28
30
|
teams: []
|
|
29
31
|
};
|
|
30
32
|
const createResult = await this.createUserUseCase.execute(userWithDisplayName);
|
|
31
|
-
if (createResult.
|
|
32
|
-
|
|
33
|
+
if (createResult.isOk()) {
|
|
34
|
+
this.createdUser = createResult.value;
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if ("Cognito/Account/ExistsInOtherTenant" !== createResult.error.code) throw new Error(`Failed to create admin user: ${createResult.error.message}`);
|
|
38
|
+
const linkResult = await this.linkUserUseCase.execute({
|
|
39
|
+
email: data.email,
|
|
40
|
+
roles: [
|
|
41
|
+
role.id
|
|
42
|
+
],
|
|
43
|
+
teams: []
|
|
44
|
+
});
|
|
45
|
+
if (linkResult.isFail()) throw new Error(`Failed to link admin user: ${linkResult.error.message}`);
|
|
46
|
+
this.createdUser = linkResult.value;
|
|
33
47
|
}
|
|
34
48
|
async uninstall() {
|
|
35
49
|
if (this.createdUser) await this.deleteUserUseCase.execute(this.createdUser.id);
|
|
@@ -40,6 +54,7 @@ const UserInstaller = AppInstaller.createImplementation({
|
|
|
40
54
|
dependencies: [
|
|
41
55
|
GetRoleUseCase,
|
|
42
56
|
CreateUserUseCase,
|
|
57
|
+
LinkUserUseCase,
|
|
43
58
|
DeleteUserUseCase
|
|
44
59
|
]
|
|
45
60
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api/features/UserInstaller/UserInstaller.js","sources":["../../../../src/api/features/UserInstaller/UserInstaller.ts"],"sourcesContent":["import type { Tenant } from \"@webiny/api-core/types/tenancy.js\";\nimport type { AdminUser } from \"@webiny/api-core/types/users.js\";\nimport { AppInstaller } from \"@webiny/api-core/features/tenancy/InstallTenant/index.js\";\nimport { GetRoleUseCase } from \"@webiny/api-core/features/security/roles/GetRole/index.js\";\nimport { DeleteUserUseCase } from \"~/api/features/DeleteUser/index.js\";\nimport { CreateUserUseCase } from \"~/api/features/CreateUser/index.js\";\n\ninterface UserInstallationData {\n firstName: string;\n lastName: string;\n email: string;\n password: string;\n}\n\nclass UsersInstallerImpl implements AppInstaller.Interface<UserInstallationData> {\n readonly alwaysRun = false;\n readonly appName = \"Cognito\";\n readonly dependsOn = [\"Security\"];\n private createdUser: AdminUser | undefined;\n\n constructor(\n private getRole: GetRoleUseCase.Interface,\n private createUserUseCase: CreateUserUseCase.Interface,\n private deleteUserUseCase: DeleteUserUseCase.Interface\n ) {}\n\n async install(_: Tenant, data: UserInstallationData): Promise<void> {\n // Load `full-access` role and assign it to the new user\n const roleResult = await this.getRole.execute({ slug: \"full-access\" });\n if (roleResult.isFail()) {\n throw new Error(`Failed to get full-access role: ${roleResult.error.message}`);\n }\n\n const role = roleResult.value;\n\n // Create user with displayName and full-access role\n const userWithDisplayName: CreateUserUseCase.Input = {\n ...data,\n displayName: `${data.firstName} ${data.lastName}`,\n roles: [role.id],\n teams: []\n };\n\n const createResult = await this.createUserUseCase.execute(userWithDisplayName);\n if (createResult.
|
|
1
|
+
{"version":3,"file":"api/features/UserInstaller/UserInstaller.js","sources":["../../../../src/api/features/UserInstaller/UserInstaller.ts"],"sourcesContent":["import type { Tenant } from \"@webiny/api-core/types/tenancy.js\";\nimport type { AdminUser } from \"@webiny/api-core/types/users.js\";\nimport { AppInstaller } from \"@webiny/api-core/features/tenancy/InstallTenant/index.js\";\nimport { GetRoleUseCase } from \"@webiny/api-core/features/security/roles/GetRole/index.js\";\nimport { DeleteUserUseCase } from \"~/api/features/DeleteUser/index.js\";\nimport { CreateUserUseCase } from \"~/api/features/CreateUser/index.js\";\nimport { LinkUserUseCase } from \"~/api/features/LinkUser/index.js\";\n\ninterface UserInstallationData {\n firstName: string;\n lastName: string;\n email: string;\n password: string;\n}\n\nclass UsersInstallerImpl implements AppInstaller.Interface<UserInstallationData> {\n readonly alwaysRun = false;\n readonly appName = \"Cognito\";\n readonly dependsOn = [\"Security\"];\n private createdUser: AdminUser | undefined;\n\n constructor(\n private getRole: GetRoleUseCase.Interface,\n private createUserUseCase: CreateUserUseCase.Interface,\n private linkUserUseCase: LinkUserUseCase.Interface,\n private deleteUserUseCase: DeleteUserUseCase.Interface\n ) {}\n\n async install(_: Tenant, data: UserInstallationData): Promise<void> {\n // Load `full-access` role and assign it to the new user\n const roleResult = await this.getRole.execute({ slug: \"full-access\" });\n if (roleResult.isFail()) {\n throw new Error(`Failed to get full-access role: ${roleResult.error.message}`);\n }\n\n const role = roleResult.value;\n\n // Create user with displayName and full-access role\n const userWithDisplayName: CreateUserUseCase.Input = {\n ...data,\n displayName: `${data.firstName} ${data.lastName}`,\n roles: [role.id],\n teams: []\n };\n\n const createResult = await this.createUserUseCase.execute(userWithDisplayName);\n if (createResult.isOk()) {\n this.createdUser = createResult.value;\n return;\n }\n\n if (createResult.error.code !== \"Cognito/Account/ExistsInOtherTenant\") {\n throw new Error(`Failed to create admin user: ${createResult.error.message}`);\n }\n\n // Creating a tenant for someone who already has an account is deliberate, so their\n // account is linked: they keep their name and password, and the given ones aren't used.\n const linkResult = await this.linkUserUseCase.execute({\n email: data.email,\n roles: [role.id],\n teams: []\n });\n if (linkResult.isFail()) {\n throw new Error(`Failed to link admin user: ${linkResult.error.message}`);\n }\n\n this.createdUser = linkResult.value;\n }\n\n async uninstall(): Promise<void> {\n if (this.createdUser) {\n await this.deleteUserUseCase.execute(this.createdUser.id);\n }\n }\n}\n\nexport const UserInstaller = AppInstaller.createImplementation({\n implementation: UsersInstallerImpl,\n dependencies: [GetRoleUseCase, CreateUserUseCase, LinkUserUseCase, DeleteUserUseCase]\n});\n"],"names":["UsersInstallerImpl","getRole","createUserUseCase","linkUserUseCase","deleteUserUseCase","_","data","roleResult","Error","role","userWithDisplayName","createResult","linkResult","UserInstaller","AppInstaller","GetRoleUseCase","CreateUserUseCase","LinkUserUseCase","DeleteUserUseCase"],"mappings":";;;;;AAeA,MAAMA;IAMF,YACYC,OAAiC,EACjCC,iBAA8C,EAC9CC,eAA0C,EAC1CC,iBAA8C,CACxD;aAJUH,OAAO,GAAPA;aACAC,iBAAiB,GAAjBA;aACAC,eAAe,GAAfA;aACAC,iBAAiB,GAAjBA;aATH,SAAS,GAAG;aACZ,OAAO,GAAG;aACV,SAAS,GAAG;YAAC;SAAW;IAQ9B;IAEH,MAAM,QAAQC,CAAS,EAAEC,IAA0B,EAAiB;QAEhE,MAAMC,aAAa,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;YAAE,MAAM;QAAc;QACpE,IAAIA,WAAW,MAAM,IACjB,MAAM,IAAIC,MAAM,CAAC,gCAAgC,EAAED,WAAW,KAAK,CAAC,OAAO,EAAE;QAGjF,MAAME,OAAOF,WAAW,KAAK;QAG7B,MAAMG,sBAA+C;YACjD,GAAGJ,IAAI;YACP,aAAa,GAAGA,KAAK,SAAS,CAAC,CAAC,EAAEA,KAAK,QAAQ,EAAE;YACjD,OAAO;gBAACG,KAAK,EAAE;aAAC;YAChB,OAAO,EAAE;QACb;QAEA,MAAME,eAAe,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAACD;QAC1D,IAAIC,aAAa,IAAI,IAAI;YACrB,IAAI,CAAC,WAAW,GAAGA,aAAa,KAAK;YACrC;QACJ;QAEA,IAAIA,AAA4B,0CAA5BA,aAAa,KAAK,CAAC,IAAI,EACvB,MAAM,IAAIH,MAAM,CAAC,6BAA6B,EAAEG,aAAa,KAAK,CAAC,OAAO,EAAE;QAKhF,MAAMC,aAAa,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC;YAClD,OAAON,KAAK,KAAK;YACjB,OAAO;gBAACG,KAAK,EAAE;aAAC;YAChB,OAAO,EAAE;QACb;QACA,IAAIG,WAAW,MAAM,IACjB,MAAM,IAAIJ,MAAM,CAAC,2BAA2B,EAAEI,WAAW,KAAK,CAAC,OAAO,EAAE;QAG5E,IAAI,CAAC,WAAW,GAAGA,WAAW,KAAK;IACvC;IAEA,MAAM,YAA2B;QAC7B,IAAI,IAAI,CAAC,WAAW,EAChB,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE;IAEhE;AACJ;AAEO,MAAMC,gBAAgBC,aAAa,oBAAoB,CAAC;IAC3D,gBAAgBd;IAChB,cAAc;QAACe;QAAgBC;QAAmBC;QAAiBC;KAAkB;AACzF"}
|
package/api/graphql/user.gql.js
CHANGED
|
@@ -7,6 +7,9 @@ import NotAuthorizedResponse from "@webiny/api-core/graphql/security/NotAuthoriz
|
|
|
7
7
|
import { CreateUserUseCase } from "../features/CreateUser/index.js";
|
|
8
8
|
import { UpdateUserUseCase } from "../features/UpdateUser/index.js";
|
|
9
9
|
import { DeleteUserUseCase } from "../features/DeleteUser/index.js";
|
|
10
|
+
import { ResetUserMfaUseCase } from "../features/ResetUserMfa/index.js";
|
|
11
|
+
import { LinkUserUseCase } from "../features/LinkUser/index.js";
|
|
12
|
+
import { CheckEmailUseCase } from "../features/CheckEmail/index.js";
|
|
10
13
|
class AdminUserSchemaImpl {
|
|
11
14
|
async execute(builder) {
|
|
12
15
|
builder.addTypeDefs(`
|
|
@@ -23,6 +26,16 @@ class AdminUserSchemaImpl {
|
|
|
23
26
|
teams: [RefInput!]
|
|
24
27
|
}
|
|
25
28
|
|
|
29
|
+
"""
|
|
30
|
+
This input type is used by administrators to give a person whose account exists in another tenant
|
|
31
|
+
access to their tenant. The person's name, email and password stay as they are.
|
|
32
|
+
"""
|
|
33
|
+
input AdminUsersLinkInput {
|
|
34
|
+
email: String!
|
|
35
|
+
roles: [RefInput!]
|
|
36
|
+
teams: [RefInput!]
|
|
37
|
+
}
|
|
38
|
+
|
|
26
39
|
"""
|
|
27
40
|
This input type is used by administrators to update other user's accounts within the same tenant.
|
|
28
41
|
"""
|
|
@@ -47,14 +60,41 @@ class AdminUserSchemaImpl {
|
|
|
47
60
|
avatar: JSON
|
|
48
61
|
}
|
|
49
62
|
|
|
63
|
+
enum AdminUsersEmailStatus {
|
|
64
|
+
"A new user can be created with this email."
|
|
65
|
+
AVAILABLE
|
|
66
|
+
"This tenant already has a user with this email."
|
|
67
|
+
EXISTS_HERE
|
|
68
|
+
"The email has an account in another tenant, which can be linked to this tenant."
|
|
69
|
+
EXISTS_ELSEWHERE
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
type AdminUsersCheckEmail {
|
|
73
|
+
status: AdminUsersEmailStatus!
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
type AdminUsersCheckEmailResponse {
|
|
77
|
+
data: AdminUsersCheckEmail
|
|
78
|
+
error: AdminUsersError
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
extend type AdminUsersQuery {
|
|
82
|
+
checkEmail(email: String!): AdminUsersCheckEmailResponse
|
|
83
|
+
}
|
|
84
|
+
|
|
50
85
|
extend type AdminUsersMutation {
|
|
51
86
|
updateCurrentUser(data: AdminUsersCurrentUserInput!): AdminUsersResponse
|
|
52
87
|
|
|
53
88
|
createUser(data: AdminUsersCreateInput!): AdminUsersResponse
|
|
54
89
|
|
|
90
|
+
linkUser(data: AdminUsersLinkInput!): AdminUsersResponse
|
|
91
|
+
|
|
55
92
|
updateUser(id: ID!, data: AdminUsersUpdateInput!): AdminUsersResponse
|
|
56
93
|
|
|
57
94
|
deleteUser(id: ID!): AdminUsersBooleanResponse
|
|
95
|
+
|
|
96
|
+
"Deletes the user's TOTP software token, so they set up MFA again on their next sign-in. Succeeds when the user has no token."
|
|
97
|
+
resetUserMfa(id: ID!): AdminUsersBooleanResponse
|
|
58
98
|
}
|
|
59
99
|
`);
|
|
60
100
|
builder.addResolver({
|
|
@@ -98,6 +138,38 @@ class AdminUserSchemaImpl {
|
|
|
98
138
|
return new Response(result.value);
|
|
99
139
|
}
|
|
100
140
|
});
|
|
141
|
+
builder.addResolver({
|
|
142
|
+
path: "AdminUsersMutation.linkUser",
|
|
143
|
+
dependencies: [
|
|
144
|
+
LinkUserUseCase
|
|
145
|
+
],
|
|
146
|
+
resolver: (linkUserUseCase)=>async ({ args })=>{
|
|
147
|
+
const result = await linkUserUseCase.execute(args.data);
|
|
148
|
+
if (result.isFail()) return new ErrorResponse({
|
|
149
|
+
message: result.error.message,
|
|
150
|
+
code: result.error.code,
|
|
151
|
+
data: result.error.data
|
|
152
|
+
});
|
|
153
|
+
return new Response(result.value);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
builder.addResolver({
|
|
157
|
+
path: "AdminUsersQuery.checkEmail",
|
|
158
|
+
dependencies: [
|
|
159
|
+
CheckEmailUseCase
|
|
160
|
+
],
|
|
161
|
+
resolver: (checkEmailUseCase)=>async ({ args })=>{
|
|
162
|
+
const result = await checkEmailUseCase.execute(args.email);
|
|
163
|
+
if (result.isFail()) return new ErrorResponse({
|
|
164
|
+
message: result.error.message,
|
|
165
|
+
code: result.error.code,
|
|
166
|
+
data: result.error.data
|
|
167
|
+
});
|
|
168
|
+
return new Response({
|
|
169
|
+
status: result.value
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
});
|
|
101
173
|
builder.addResolver({
|
|
102
174
|
path: "AdminUsersMutation.updateUser",
|
|
103
175
|
dependencies: [
|
|
@@ -132,6 +204,21 @@ class AdminUserSchemaImpl {
|
|
|
132
204
|
return new Response(true);
|
|
133
205
|
}
|
|
134
206
|
});
|
|
207
|
+
builder.addResolver({
|
|
208
|
+
path: "AdminUsersMutation.resetUserMfa",
|
|
209
|
+
dependencies: [
|
|
210
|
+
ResetUserMfaUseCase
|
|
211
|
+
],
|
|
212
|
+
resolver: (resetUserMfaUseCase)=>async ({ args })=>{
|
|
213
|
+
const result = await resetUserMfaUseCase.execute(args.id);
|
|
214
|
+
if (result.isFail()) return new ErrorResponse({
|
|
215
|
+
message: result.error.message,
|
|
216
|
+
code: result.error.code,
|
|
217
|
+
data: result.error.data
|
|
218
|
+
});
|
|
219
|
+
return new Response(true);
|
|
220
|
+
}
|
|
221
|
+
});
|
|
135
222
|
return builder;
|
|
136
223
|
}
|
|
137
224
|
constructor(){
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api/graphql/user.gql.js","sources":["../../../src/api/graphql/user.gql.ts"],"sourcesContent":["import { ErrorResponse, NotFoundResponse, Response } from \"@webiny/api-graphql/responses.js\";\nimport { staticSchemaKey } from \"@webiny/api-graphql/graphql/staticSchemaKey.js\";\nimport { CoreGraphQLSchemaFactory } from \"@webiny/api-graphql/graphql/abstractions.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { GetUserUseCase } from \"@webiny/api-core/features/users/GetUser/index.js\";\nimport NotAuthorizedResponse from \"@webiny/api-core/graphql/security/NotAuthorizedResponse.js\";\nimport { CreateUserUseCase } from \"~/api/features/CreateUser/index.js\";\nimport { UpdateUserUseCase } from \"~/api/features/UpdateUser/index.js\";\nimport { DeleteUserUseCase } from \"~/api/features/DeleteUser/index.js\";\n\nclass AdminUserSchemaImpl implements CoreGraphQLSchemaFactory.Interface {\n public getSchemaKey = staticSchemaKey(\"cognito/AdminUserSchemaImpl\");\n\n async execute(\n builder: CoreGraphQLSchemaFactory.SchemaBuilder\n ): CoreGraphQLSchemaFactory.Return {\n builder.addTypeDefs(/* GraphQL */ `\n \"\"\"\n This input type is used by administrators to create other user's accounts within the same tenant.\n \"\"\"\n input AdminUsersCreateInput {\n email: String!\n firstName: String!\n lastName: String!\n password: String!\n avatar: JSON\n roles: [RefInput!]\n teams: [RefInput!]\n }\n\n \"\"\"\n This input type is used by administrators to update other user's accounts within the same tenant.\n \"\"\"\n input AdminUsersUpdateInput {\n email: String\n firstName: String\n lastName: String\n password: String\n avatar: JSON\n roles: [RefInput!]\n teams: [RefInput!]\n }\n\n \"\"\"\n This input type is used by the user who is updating his own account\n \"\"\"\n input AdminUsersCurrentUserInput {\n email: String\n firstName: String\n lastName: String\n password: String\n avatar: JSON\n }\n\n extend type AdminUsersMutation {\n updateCurrentUser(data: AdminUsersCurrentUserInput!): AdminUsersResponse\n\n createUser(data: AdminUsersCreateInput!): AdminUsersResponse\n\n updateUser(id: ID!, data: AdminUsersUpdateInput!): AdminUsersResponse\n\n deleteUser(id: ID!): AdminUsersBooleanResponse\n }\n `);\n\n builder.addResolver({\n path: \"AdminUsersMutation.updateCurrentUser\",\n dependencies: [IdentityContext, GetUserUseCase, UpdateUserUseCase],\n resolver: (\n identityContext: IdentityContext.Interface,\n getUserUseCase: GetUserUseCase.Interface,\n updateUserUseCase: UpdateUserUseCase.Interface\n ) => {\n return async ({ args }) => {\n const identity = identityContext.getIdentity();\n if (!identity.isAdmin()) {\n return new NotAuthorizedResponse();\n }\n\n // Current user might not have permissions for `adminUsers`.\n return await identityContext.withoutAuthorization(async () => {\n const getUserResult = await getUserUseCase.execute({ id: identity.id });\n if (getUserResult.isFail()) {\n // TODO: check if current identity belongs to a different tenant.\n // TODO: If so, switch to that other tenant, and update his profile there.\n return new NotFoundResponse(\"User not found!\");\n }\n\n const user = getUserResult.value;\n\n // TODO: UpdateCurrentUser should be a dedicated use case\n const updateResult = await updateUserUseCase.execute(user.id, args.data);\n if (updateResult.isFail()) {\n return new ErrorResponse({\n message: updateResult.error.message,\n code: updateResult.error.code,\n data: updateResult.error.data\n });\n }\n\n return new Response(updateResult.value);\n });\n };\n }\n });\n\n builder.addResolver({\n path: \"AdminUsersMutation.createUser\",\n dependencies: [CreateUserUseCase],\n resolver: (createUserUseCase: CreateUserUseCase.Interface) => {\n return async ({ args }) => {\n const result = await createUserUseCase.execute(args.data);\n if (result.isFail()) {\n return new ErrorResponse({\n message: result.error.message,\n code: result.error.code,\n data: result.error.data\n });\n }\n\n return new Response(result.value);\n };\n }\n });\n\n builder.addResolver({\n path: \"AdminUsersMutation.updateUser\",\n dependencies: [UpdateUserUseCase, IdentityContext],\n resolver: (\n updateUserUseCase: UpdateUserUseCase.Interface,\n identityContext: IdentityContext.Interface\n ) => {\n return async ({ args }) => {\n if (args.id === identityContext.getIdentity().id) {\n return new ErrorResponse({\n message:\n \"You're not allowed to update your own account using this API.\",\n code: \"AdminUser/GraphQL/UpdateSelf\"\n });\n }\n\n const result = await updateUserUseCase.execute(args.id, args.data);\n if (result.isFail()) {\n return new ErrorResponse({\n message: result.error.message,\n code: result.error.code\n });\n }\n\n return new Response(result.value);\n };\n }\n });\n\n builder.addResolver({\n path: \"AdminUsersMutation.deleteUser\",\n dependencies: [DeleteUserUseCase],\n resolver: (deleteUserUseCase: DeleteUserUseCase.Interface) => {\n return async ({ args }) => {\n const result = await deleteUserUseCase.execute(args.id);\n if (result.isFail()) {\n return new ErrorResponse({\n message: result.error.message,\n code: result.error.code,\n data: result.error.data\n });\n }\n\n return new Response(true);\n };\n }\n });\n\n return builder;\n }\n}\n\nexport const AdminUsersSchema = CoreGraphQLSchemaFactory.createImplementation({\n implementation: AdminUserSchemaImpl,\n dependencies: []\n});\n"],"names":["AdminUserSchemaImpl","builder","IdentityContext","GetUserUseCase","UpdateUserUseCase","identityContext","getUserUseCase","updateUserUseCase","args","identity","NotAuthorizedResponse","getUserResult","NotFoundResponse","user","updateResult","ErrorResponse","Response","CreateUserUseCase","createUserUseCase","result","DeleteUserUseCase","deleteUserUseCase","staticSchemaKey","AdminUsersSchema","CoreGraphQLSchemaFactory"],"mappings":";;;;;;;;;AAUA,MAAMA;IAGF,MAAM,QACFC,OAA+C,EAChB;QAC/BA,QAAQ,WAAW,CAAe,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QA+CnC,CAAC;QAEDA,QAAQ,WAAW,CAAC;YAChB,MAAM;YACN,cAAc;gBAACC;gBAAiBC;gBAAgBC;aAAkB;YAClE,UAAU,CACNC,iBACAC,gBACAC,oBAEO,OAAO,EAAEC,IAAI,EAAE;oBAClB,MAAMC,WAAWJ,gBAAgB,WAAW;oBAC5C,IAAI,CAACI,SAAS,OAAO,IACjB,OAAO,IAAIC;oBAIf,OAAO,MAAML,gBAAgB,oBAAoB,CAAC;wBAC9C,MAAMM,gBAAgB,MAAML,eAAe,OAAO,CAAC;4BAAE,IAAIG,SAAS,EAAE;wBAAC;wBACrE,IAAIE,cAAc,MAAM,IAGpB,OAAO,IAAIC,iBAAiB;wBAGhC,MAAMC,OAAOF,cAAc,KAAK;wBAGhC,MAAMG,eAAe,MAAMP,kBAAkB,OAAO,CAACM,KAAK,EAAE,EAAEL,KAAK,IAAI;wBACvE,IAAIM,aAAa,MAAM,IACnB,OAAO,IAAIC,cAAc;4BACrB,SAASD,aAAa,KAAK,CAAC,OAAO;4BACnC,MAAMA,aAAa,KAAK,CAAC,IAAI;4BAC7B,MAAMA,aAAa,KAA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BACrB,SAASI,OAAO,KAAK,CAAC,OAAO;wBAC7B,MAAMA,OAAO,KAAK,CAAC,IAAI;wBACvB,MAAMA,OAAO,KAAK,CAAC,IAAI;oBAC3B;oBAGJ,OAAO,IAAIH,SAAS;gBACxB;QAER;QAEA,OAAOf;IACX;;aAnKO,YAAY,GAAGqB,gBAAgB;;AAoK1C;AAEO,MAAMC,mBAAmBC,yBAAyB,oBAAoB,CAAC;IAC1E,gBAAgBxB;IAChB,cAAc,EAAE;AACpB"}
|
|
1
|
+
{"version":3,"file":"api/graphql/user.gql.js","sources":["../../../src/api/graphql/user.gql.ts"],"sourcesContent":["import { ErrorResponse, NotFoundResponse, Response } from \"@webiny/api-graphql/responses.js\";\nimport { staticSchemaKey } from \"@webiny/api-graphql/graphql/staticSchemaKey.js\";\nimport { CoreGraphQLSchemaFactory } from \"@webiny/api-graphql/graphql/abstractions.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { GetUserUseCase } from \"@webiny/api-core/features/users/GetUser/index.js\";\nimport NotAuthorizedResponse from \"@webiny/api-core/graphql/security/NotAuthorizedResponse.js\";\nimport { CreateUserUseCase } from \"~/api/features/CreateUser/index.js\";\nimport { UpdateUserUseCase } from \"~/api/features/UpdateUser/index.js\";\nimport { DeleteUserUseCase } from \"~/api/features/DeleteUser/index.js\";\nimport { ResetUserMfaUseCase } from \"~/api/features/ResetUserMfa/index.js\";\nimport { LinkUserUseCase } from \"~/api/features/LinkUser/index.js\";\nimport { CheckEmailUseCase } from \"~/api/features/CheckEmail/index.js\";\n\nclass AdminUserSchemaImpl implements CoreGraphQLSchemaFactory.Interface {\n public getSchemaKey = staticSchemaKey(\"cognito/AdminUserSchemaImpl\");\n\n async execute(\n builder: CoreGraphQLSchemaFactory.SchemaBuilder\n ): CoreGraphQLSchemaFactory.Return {\n builder.addTypeDefs(/* GraphQL */ `\n \"\"\"\n This input type is used by administrators to create other user's accounts within the same tenant.\n \"\"\"\n input AdminUsersCreateInput {\n email: String!\n firstName: String!\n lastName: String!\n password: String!\n avatar: JSON\n roles: [RefInput!]\n teams: [RefInput!]\n }\n\n \"\"\"\n This input type is used by administrators to give a person whose account exists in another tenant\n access to their tenant. The person's name, email and password stay as they are.\n \"\"\"\n input AdminUsersLinkInput {\n email: String!\n roles: [RefInput!]\n teams: [RefInput!]\n }\n\n \"\"\"\n This input type is used by administrators to update other user's accounts within the same tenant.\n \"\"\"\n input AdminUsersUpdateInput {\n email: String\n firstName: String\n lastName: String\n password: String\n avatar: JSON\n roles: [RefInput!]\n teams: [RefInput!]\n }\n\n \"\"\"\n This input type is used by the user who is updating his own account\n \"\"\"\n input AdminUsersCurrentUserInput {\n email: String\n firstName: String\n lastName: String\n password: String\n avatar: JSON\n }\n\n enum AdminUsersEmailStatus {\n \"A new user can be created with this email.\"\n AVAILABLE\n \"This tenant already has a user with this email.\"\n EXISTS_HERE\n \"The email has an account in another tenant, which can be linked to this tenant.\"\n EXISTS_ELSEWHERE\n }\n\n type AdminUsersCheckEmail {\n status: AdminUsersEmailStatus!\n }\n\n type AdminUsersCheckEmailResponse {\n data: AdminUsersCheckEmail\n error: AdminUsersError\n }\n\n extend type AdminUsersQuery {\n checkEmail(email: String!): AdminUsersCheckEmailResponse\n }\n\n extend type AdminUsersMutation {\n updateCurrentUser(data: AdminUsersCurrentUserInput!): AdminUsersResponse\n\n createUser(data: AdminUsersCreateInput!): AdminUsersResponse\n\n linkUser(data: AdminUsersLinkInput!): AdminUsersResponse\n\n updateUser(id: ID!, data: AdminUsersUpdateInput!): AdminUsersResponse\n\n deleteUser(id: ID!): AdminUsersBooleanResponse\n\n \"Deletes the user's TOTP software token, so they set up MFA again on their next sign-in. Succeeds when the user has no token.\"\n resetUserMfa(id: ID!): AdminUsersBooleanResponse\n }\n `);\n\n builder.addResolver({\n path: \"AdminUsersMutation.updateCurrentUser\",\n dependencies: [IdentityContext, GetUserUseCase, UpdateUserUseCase],\n resolver: (\n identityContext: IdentityContext.Interface,\n getUserUseCase: GetUserUseCase.Interface,\n updateUserUseCase: UpdateUserUseCase.Interface\n ) => {\n return async ({ args }) => {\n const identity = identityContext.getIdentity();\n if (!identity.isAdmin()) {\n return new NotAuthorizedResponse();\n }\n\n // Current user might not have permissions for `adminUsers`.\n return await identityContext.withoutAuthorization(async () => {\n const getUserResult = await getUserUseCase.execute({ id: identity.id });\n if (getUserResult.isFail()) {\n // TODO: check if current identity belongs to a different tenant.\n // TODO: If so, switch to that other tenant, and update his profile there.\n return new NotFoundResponse(\"User not found!\");\n }\n\n const user = getUserResult.value;\n\n // TODO: UpdateCurrentUser should be a dedicated use case\n const updateResult = await updateUserUseCase.execute(user.id, args.data);\n if (updateResult.isFail()) {\n return new ErrorResponse({\n message: updateResult.error.message,\n code: updateResult.error.code,\n data: updateResult.error.data\n });\n }\n\n return new Response(updateResult.value);\n });\n };\n }\n });\n\n builder.addResolver({\n path: \"AdminUsersMutation.createUser\",\n dependencies: [CreateUserUseCase],\n resolver: (createUserUseCase: CreateUserUseCase.Interface) => {\n return async ({ args }) => {\n const result = await createUserUseCase.execute(args.data);\n if (result.isFail()) {\n return new ErrorResponse({\n message: result.error.message,\n code: result.error.code,\n data: result.error.data\n });\n }\n\n return new Response(result.value);\n };\n }\n });\n\n builder.addResolver({\n path: \"AdminUsersMutation.linkUser\",\n dependencies: [LinkUserUseCase],\n resolver: (linkUserUseCase: LinkUserUseCase.Interface) => {\n return async ({ args }) => {\n const result = await linkUserUseCase.execute(args.data);\n if (result.isFail()) {\n return new ErrorResponse({\n message: result.error.message,\n code: result.error.code,\n data: result.error.data\n });\n }\n\n return new Response(result.value);\n };\n }\n });\n\n builder.addResolver({\n path: \"AdminUsersQuery.checkEmail\",\n dependencies: [CheckEmailUseCase],\n resolver: (checkEmailUseCase: CheckEmailUseCase.Interface) => {\n return async ({ args }) => {\n const result = await checkEmailUseCase.execute(args.email);\n if (result.isFail()) {\n return new ErrorResponse({\n message: result.error.message,\n code: result.error.code,\n data: result.error.data\n });\n }\n\n return new Response({ status: result.value });\n };\n }\n });\n\n builder.addResolver({\n path: \"AdminUsersMutation.updateUser\",\n dependencies: [UpdateUserUseCase, IdentityContext],\n resolver: (\n updateUserUseCase: UpdateUserUseCase.Interface,\n identityContext: IdentityContext.Interface\n ) => {\n return async ({ args }) => {\n if (args.id === identityContext.getIdentity().id) {\n return new ErrorResponse({\n message:\n \"You're not allowed to update your own account using this API.\",\n code: \"AdminUser/GraphQL/UpdateSelf\"\n });\n }\n\n const result = await updateUserUseCase.execute(args.id, args.data);\n if (result.isFail()) {\n return new ErrorResponse({\n message: result.error.message,\n code: result.error.code\n });\n }\n\n return new Response(result.value);\n };\n }\n });\n\n builder.addResolver({\n path: \"AdminUsersMutation.deleteUser\",\n dependencies: [DeleteUserUseCase],\n resolver: (deleteUserUseCase: DeleteUserUseCase.Interface) => {\n return async ({ args }) => {\n const result = await deleteUserUseCase.execute(args.id);\n if (result.isFail()) {\n return new ErrorResponse({\n message: result.error.message,\n code: result.error.code,\n data: result.error.data\n });\n }\n\n return new Response(true);\n };\n }\n });\n\n builder.addResolver({\n path: \"AdminUsersMutation.resetUserMfa\",\n dependencies: [ResetUserMfaUseCase],\n resolver: (resetUserMfaUseCase: ResetUserMfaUseCase.Interface) => {\n return async ({ args }) => {\n const result = await resetUserMfaUseCase.execute(args.id);\n if (result.isFail()) {\n return new ErrorResponse({\n message: result.error.message,\n code: result.error.code,\n data: result.error.data\n });\n }\n\n return new Response(true);\n };\n }\n });\n\n return builder;\n }\n}\n\nexport const AdminUsersSchema = CoreGraphQLSchemaFactory.createImplementation({\n implementation: AdminUserSchemaImpl,\n dependencies: []\n});\n"],"names":["AdminUserSchemaImpl","builder","IdentityContext","GetUserUseCase","UpdateUserUseCase","identityContext","getUserUseCase","updateUserUseCase","args","identity","NotAuthorizedResponse","getUserResult","NotFoundResponse","user","updateResult","ErrorResponse","Response","CreateUserUseCase","createUserUseCase","result","LinkUserUseCase","linkUserUseCase","CheckEmailUseCase","checkEmailUseCase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