@webiny/cognito 0.0.0-unstable.0156a4c312
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.d.ts +55 -0
- package/Cognito.js +104 -0
- package/Cognito.js.map +1 -0
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/admin/Cognito.d.ts +8 -0
- package/admin/Cognito.js +8 -0
- package/admin/Cognito.js.map +1 -0
- package/admin/CognitoLogin.d.ts +7 -0
- package/admin/CognitoLogin.js +13 -0
- package/admin/CognitoLogin.js.map +1 -0
- package/admin/DefaultCognitoSignInConfig.d.ts +23 -0
- package/admin/DefaultCognitoSignInConfig.js +51 -0
- package/admin/DefaultCognitoSignInConfig.js.map +1 -0
- package/admin/Extension.d.ts +2 -0
- package/admin/Extension.js +21 -0
- package/admin/Extension.js.map +1 -0
- package/admin/SignInExtension.d.ts +2 -0
- package/admin/SignInExtension.js +9 -0
- package/admin/SignInExtension.js.map +1 -0
- package/admin/federatedIdentityProviders.d.ts +9 -0
- package/admin/federatedIdentityProviders.js +10 -0
- package/admin/federatedIdentityProviders.js.map +1 -0
- package/admin/index.d.ts +2 -0
- package/admin/index.js +2 -0
- package/admin/presentation/Cognito/CognitoLoginScreen.d.ts +10 -0
- package/admin/presentation/Cognito/CognitoLoginScreen.js +60 -0
- package/admin/presentation/Cognito/CognitoLoginScreen.js.map +1 -0
- package/admin/presentation/Cognito/CognitoPresenter.d.ts +81 -0
- package/admin/presentation/Cognito/CognitoPresenter.js +386 -0
- package/admin/presentation/Cognito/CognitoPresenter.js.map +1 -0
- package/admin/presentation/Cognito/CognitoSignInConfig.d.ts +31 -0
- package/admin/presentation/Cognito/CognitoSignInConfig.js +5 -0
- package/admin/presentation/Cognito/CognitoSignInConfig.js.map +1 -0
- package/admin/presentation/Cognito/abstractions.d.ts +91 -0
- package/admin/presentation/Cognito/abstractions.js +5 -0
- package/admin/presentation/Cognito/abstractions.js.map +1 -0
- package/admin/presentation/Cognito/components/ConfirmTotpCode.d.ts +26 -0
- package/admin/presentation/Cognito/components/ConfirmTotpCode.js +45 -0
- package/admin/presentation/Cognito/components/ConfirmTotpCode.js.map +1 -0
- package/admin/presentation/Cognito/components/Divider.d.ts +20 -0
- package/admin/presentation/Cognito/components/Divider.js +16 -0
- package/admin/presentation/Cognito/components/Divider.js.map +1 -0
- package/admin/presentation/Cognito/components/FederatedLogin.d.ts +24 -0
- package/admin/presentation/Cognito/components/FederatedLogin.js +43 -0
- package/admin/presentation/Cognito/components/FederatedLogin.js.map +1 -0
- package/admin/presentation/Cognito/components/FederatedProviders.d.ts +44 -0
- package/admin/presentation/Cognito/components/FederatedProviders.js +11 -0
- package/admin/presentation/Cognito/components/FederatedProviders.js.map +1 -0
- package/admin/presentation/Cognito/components/FooterSignIn.d.ts +23 -0
- package/admin/presentation/Cognito/components/FooterSignIn.js +13 -0
- package/admin/presentation/Cognito/components/FooterSignIn.js.map +1 -0
- package/admin/presentation/Cognito/components/PasswordResetCodeSent.d.ts +27 -0
- package/admin/presentation/Cognito/components/PasswordResetCodeSent.js +40 -0
- package/admin/presentation/Cognito/components/PasswordResetCodeSent.js.map +1 -0
- package/admin/presentation/Cognito/components/RequestPasswordResetCode.d.ts +26 -0
- package/admin/presentation/Cognito/components/RequestPasswordResetCode.js +42 -0
- package/admin/presentation/Cognito/components/RequestPasswordResetCode.js.map +1 -0
- package/admin/presentation/Cognito/components/RequireNewPassword.d.ts +26 -0
- package/admin/presentation/Cognito/components/RequireNewPassword.js +52 -0
- package/admin/presentation/Cognito/components/RequireNewPassword.js.map +1 -0
- package/admin/presentation/Cognito/components/SetNewPassword.d.ts +26 -0
- package/admin/presentation/Cognito/components/SetNewPassword.js +79 -0
- package/admin/presentation/Cognito/components/SetNewPassword.js.map +1 -0
- package/admin/presentation/Cognito/components/SetupTotp.d.ts +25 -0
- package/admin/presentation/Cognito/components/SetupTotp.js +60 -0
- package/admin/presentation/Cognito/components/SetupTotp.js.map +1 -0
- package/admin/presentation/Cognito/components/SignIn.d.ts +26 -0
- package/admin/presentation/Cognito/components/SignIn.js +64 -0
- package/admin/presentation/Cognito/components/SignIn.js.map +1 -0
- package/admin/presentation/Cognito/components/View.d.ts +98 -0
- package/admin/presentation/Cognito/components/View.js +48 -0
- package/admin/presentation/Cognito/components/View.js.map +1 -0
- package/admin/presentation/Cognito/components/index.d.ts +292 -0
- package/admin/presentation/Cognito/components/index.js +29 -0
- package/admin/presentation/Cognito/components/index.js.map +1 -0
- package/admin/presentation/Cognito/feature.d.ts +3 -0
- package/admin/presentation/Cognito/feature.js +17 -0
- package/admin/presentation/Cognito/feature.js.map +1 -0
- package/admin/presentation/Cognito/signInFeature.d.ts +1 -0
- package/admin/presentation/Cognito/signInFeature.js +11 -0
- package/admin/presentation/Cognito/signInFeature.js.map +1 -0
- package/api/CognitoApiFeature.d.ts +4 -0
- package/api/CognitoApiFeature.js +26 -0
- package/api/CognitoApiFeature.js.map +1 -0
- package/api/domain/Username.d.ts +4 -0
- package/api/domain/Username.js +8 -0
- package/api/domain/Username.js.map +1 -0
- package/api/domain/errors.d.ts +37 -0
- package/api/domain/errors.js +44 -0
- package/api/domain/errors.js.map +1 -0
- package/api/features/CognitoIdp/CognitoIdentityProvider.d.ts +15 -0
- package/api/features/CognitoIdp/CognitoIdentityProvider.js +63 -0
- package/api/features/CognitoIdp/CognitoIdentityProvider.js.map +1 -0
- package/api/features/CognitoIdp/abstractions.d.ts +15 -0
- package/api/features/CognitoIdp/abstractions.js +5 -0
- package/api/features/CognitoIdp/abstractions.js.map +1 -0
- package/api/features/CognitoIdp/feature.d.ts +4 -0
- package/api/features/CognitoIdp/feature.js +11 -0
- package/api/features/CognitoIdp/feature.js.map +1 -0
- package/api/features/CognitoIdp/index.d.ts +2 -0
- package/api/features/CognitoIdp/index.js +2 -0
- package/api/features/CognitoService/CognitoService.d.ts +20 -0
- package/api/features/CognitoService/CognitoService.js +100 -0
- package/api/features/CognitoService/CognitoService.js.map +1 -0
- package/api/features/CognitoService/abstractions.d.ts +54 -0
- package/api/features/CognitoService/abstractions.js +6 -0
- package/api/features/CognitoService/abstractions.js.map +1 -0
- package/api/features/CognitoService/feature.d.ts +8 -0
- package/api/features/CognitoService/feature.js +13 -0
- package/api/features/CognitoService/feature.js.map +1 -0
- package/api/features/CognitoService/index.d.ts +1 -0
- package/api/features/CognitoService/index.js +1 -0
- package/api/features/CreateUser/CreateUserUseCase.d.ts +22 -0
- package/api/features/CreateUser/CreateUserUseCase.js +80 -0
- package/api/features/CreateUser/CreateUserUseCase.js.map +1 -0
- package/api/features/CreateUser/abstractions.d.ts +35 -0
- package/api/features/CreateUser/abstractions.js +5 -0
- package/api/features/CreateUser/abstractions.js.map +1 -0
- package/api/features/CreateUser/feature.d.ts +4 -0
- package/api/features/CreateUser/feature.js +11 -0
- package/api/features/CreateUser/feature.js.map +1 -0
- package/api/features/CreateUser/index.d.ts +2 -0
- package/api/features/CreateUser/index.js +2 -0
- package/api/features/CreateUser/schema.d.ts +15 -0
- package/api/features/CreateUser/schema.js +18 -0
- package/api/features/CreateUser/schema.js.map +1 -0
- package/api/features/DeleteUser/DeleteUserUseCase.d.ts +16 -0
- package/api/features/DeleteUser/DeleteUserUseCase.js +47 -0
- package/api/features/DeleteUser/DeleteUserUseCase.js.map +1 -0
- package/api/features/DeleteUser/abstractions.d.ts +19 -0
- package/api/features/DeleteUser/abstractions.js +5 -0
- package/api/features/DeleteUser/abstractions.js.map +1 -0
- package/api/features/DeleteUser/feature.d.ts +4 -0
- package/api/features/DeleteUser/feature.js +11 -0
- package/api/features/DeleteUser/feature.js.map +1 -0
- package/api/features/DeleteUser/index.d.ts +2 -0
- package/api/features/DeleteUser/index.js +2 -0
- package/api/features/UpdateUser/UpdateUserUseCase.d.ts +21 -0
- package/api/features/UpdateUser/UpdateUserUseCase.js +66 -0
- package/api/features/UpdateUser/UpdateUserUseCase.js.map +1 -0
- package/api/features/UpdateUser/abstractions.d.ts +33 -0
- package/api/features/UpdateUser/abstractions.js +5 -0
- package/api/features/UpdateUser/abstractions.js.map +1 -0
- package/api/features/UpdateUser/feature.d.ts +4 -0
- package/api/features/UpdateUser/feature.js +11 -0
- package/api/features/UpdateUser/feature.js.map +1 -0
- package/api/features/UpdateUser/index.d.ts +2 -0
- package/api/features/UpdateUser/index.js +2 -0
- package/api/features/UpdateUser/schema.d.ts +14 -0
- package/api/features/UpdateUser/schema.js +17 -0
- package/api/features/UpdateUser/schema.js.map +1 -0
- package/api/features/UserInstaller/UserInstaller.d.ts +27 -0
- package/api/features/UserInstaller/UserInstaller.js +48 -0
- package/api/features/UserInstaller/UserInstaller.js.map +1 -0
- package/api/features/UserInstaller/feature.d.ts +4 -0
- package/api/features/UserInstaller/feature.js +11 -0
- package/api/features/UserInstaller/feature.js.map +1 -0
- package/api/graphql/user.gql.d.ts +9 -0
- package/api/graphql/user.gql.js +147 -0
- package/api/graphql/user.gql.js.map +1 -0
- package/api/index.d.ts +1 -0
- package/api/index.js +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/infra/CognitoFederationPulumi.d.ts +8 -0
- package/infra/CognitoFederationPulumi.js +17 -0
- package/infra/CognitoFederationPulumi.js.map +1 -0
- package/package.json +50 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/CognitoIdp/abstractions.js","sources":["../../../../src/api/features/CognitoIdp/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type jwt from \"jsonwebtoken\";\nimport type { IdentityData } from \"@webiny/api-core/idp\";\n\nexport type CognitoIdentity = Omit<IdentityData, \"type\"> & {\n profile?: Omit<IdentityData[\"profile\"], \"external\">;\n};\n\nexport interface ICognitoIdpConfig {\n getIdentity(token: jwt.JwtPayload): Promise<CognitoIdentity> | CognitoIdentity;\n verifyTokenClaims?(token: jwt.JwtPayload): Promise<void> | void;\n}\n\nexport const CognitoIdpConfig = createAbstraction<ICognitoIdpConfig>(\"CognitoIdpConfig\");\n\nexport namespace CognitoIdpConfig {\n export type Interface = ICognitoIdpConfig;\n export type IdentityData = CognitoIdentity;\n export type JwtPayload = jwt.JwtPayload;\n}\n"],"names":["CognitoIdpConfig","createAbstraction"],"mappings":";AAaO,MAAMA,mBAAmBC,kBAAqC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { CognitoIdentityProvider } from "./CognitoIdentityProvider.js";
|
|
3
|
+
const CognitoIdpFeature = createFeature({
|
|
4
|
+
name: "CognitoIdp",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(CognitoIdentityProvider).inContainerScope();
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { CognitoIdpFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/CognitoIdp/feature.js","sources":["../../../../src/api/features/CognitoIdp/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { CognitoIdentityProvider } from \"./CognitoIdentityProvider.js\";\n\nexport const CognitoIdpFeature = createFeature({\n name: \"CognitoIdp\",\n register(container) {\n // Registered per request by CognitoApiFeature (the `<Cognito/>` extension). Container scoped:\n // one provider per request, built from the request container, so it sees the optional\n // CognitoIdpConfig that other extensions (e.g. Entra ID) register there.\n container.register(CognitoIdentityProvider).inContainerScope();\n }\n});\n"],"names":["CognitoIdpFeature","createFeature","container","CognitoIdentityProvider"],"mappings":";;AAGO,MAAMA,oBAAoBC,cAAc;IAC3C,MAAM;IACN,UAASC,SAAS;QAIdA,UAAU,QAAQ,CAACC,yBAAyB,gBAAgB;IAChE;AACJ"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CognitoConfig, CognitoService as ServiceAbstraction } from "./abstractions.js";
|
|
2
|
+
declare class CognitoServiceImpl implements ServiceAbstraction.Interface {
|
|
3
|
+
private config;
|
|
4
|
+
private cognito;
|
|
5
|
+
constructor(config: CognitoConfig.Interface);
|
|
6
|
+
userExists(username: string): Promise<boolean>;
|
|
7
|
+
createUser(params: {
|
|
8
|
+
username: string;
|
|
9
|
+
temporaryPassword: string;
|
|
10
|
+
attributes: ServiceAbstraction.UserAttributes;
|
|
11
|
+
}): Promise<void>;
|
|
12
|
+
setEmailVerified(username: string): Promise<void>;
|
|
13
|
+
setPermanentPassword(username: string, password: string): Promise<void>;
|
|
14
|
+
updateUserAttributes(username: string, attributes: Record<string, string>): Promise<void>;
|
|
15
|
+
deleteUser(username: string): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
export declare const CognitoService: typeof CognitoServiceImpl & {
|
|
18
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").ICognitoService>;
|
|
19
|
+
};
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { CognitoIdentityProvider } from "@webiny/aws-sdk/client-cognito-identity-provider/index.js";
|
|
2
|
+
import { CognitoConfig, CognitoService } from "./abstractions.js";
|
|
3
|
+
class CognitoServiceImpl {
|
|
4
|
+
constructor(config){
|
|
5
|
+
this.config = config;
|
|
6
|
+
this.cognito = new CognitoIdentityProvider({
|
|
7
|
+
region: config.region
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
async userExists(username) {
|
|
11
|
+
try {
|
|
12
|
+
await this.cognito.adminGetUser({
|
|
13
|
+
Username: username,
|
|
14
|
+
UserPoolId: this.config.userPoolId
|
|
15
|
+
});
|
|
16
|
+
return true;
|
|
17
|
+
} catch {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
async createUser(params) {
|
|
22
|
+
const createUserParams = {
|
|
23
|
+
UserPoolId: this.config.userPoolId,
|
|
24
|
+
Username: params.username,
|
|
25
|
+
DesiredDeliveryMediums: [],
|
|
26
|
+
ForceAliasCreation: false,
|
|
27
|
+
MessageAction: "SUPPRESS",
|
|
28
|
+
TemporaryPassword: params.temporaryPassword,
|
|
29
|
+
UserAttributes: [
|
|
30
|
+
{
|
|
31
|
+
Name: "given_name",
|
|
32
|
+
Value: params.attributes.givenName || ""
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
Name: "family_name",
|
|
36
|
+
Value: params.attributes.familyName || ""
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
Name: "preferred_username",
|
|
40
|
+
Value: params.attributes.preferredUsername
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
Name: "email",
|
|
44
|
+
Value: params.attributes.email
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
Name: "custom:id",
|
|
48
|
+
Value: params.attributes.customId
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
};
|
|
52
|
+
await this.cognito.adminCreateUser(createUserParams);
|
|
53
|
+
}
|
|
54
|
+
async setEmailVerified(username) {
|
|
55
|
+
await this.cognito.adminUpdateUserAttributes({
|
|
56
|
+
UserPoolId: this.config.userPoolId,
|
|
57
|
+
Username: username,
|
|
58
|
+
UserAttributes: [
|
|
59
|
+
{
|
|
60
|
+
Name: "email_verified",
|
|
61
|
+
Value: "true"
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
async setPermanentPassword(username, password) {
|
|
67
|
+
await this.cognito.adminSetUserPassword({
|
|
68
|
+
Permanent: true,
|
|
69
|
+
Password: password,
|
|
70
|
+
Username: username,
|
|
71
|
+
UserPoolId: this.config.userPoolId
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
async updateUserAttributes(username, attributes) {
|
|
75
|
+
const userAttributes = Object.entries(attributes).map(([name, value])=>({
|
|
76
|
+
Name: name,
|
|
77
|
+
Value: value
|
|
78
|
+
}));
|
|
79
|
+
await this.cognito.adminUpdateUserAttributes({
|
|
80
|
+
UserPoolId: this.config.userPoolId,
|
|
81
|
+
Username: username,
|
|
82
|
+
UserAttributes: userAttributes
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
async deleteUser(username) {
|
|
86
|
+
await this.cognito.adminDeleteUser({
|
|
87
|
+
UserPoolId: this.config.userPoolId,
|
|
88
|
+
Username: username
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const CognitoService_CognitoService = CognitoService.createImplementation({
|
|
93
|
+
implementation: CognitoServiceImpl,
|
|
94
|
+
dependencies: [
|
|
95
|
+
CognitoConfig
|
|
96
|
+
]
|
|
97
|
+
});
|
|
98
|
+
export { CognitoService_CognitoService as CognitoService };
|
|
99
|
+
|
|
100
|
+
//# sourceMappingURL=CognitoService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/CognitoService/CognitoService.js","sources":["../../../../src/api/features/CognitoService/CognitoService.ts"],"sourcesContent":["import type { AdminCreateUserRequest } from \"@webiny/aws-sdk/client-cognito-identity-provider/index.js\";\nimport { CognitoIdentityProvider } from \"@webiny/aws-sdk/client-cognito-identity-provider/index.js\";\nimport { CognitoConfig, CognitoService as ServiceAbstraction } from \"./abstractions.js\";\n\nclass CognitoServiceImpl implements ServiceAbstraction.Interface {\n private cognito: CognitoIdentityProvider;\n\n constructor(private config: CognitoConfig.Interface) {\n this.cognito = new CognitoIdentityProvider({ region: config.region });\n }\n\n async userExists(username: string): Promise<boolean> {\n try {\n await this.cognito.adminGetUser({\n Username: username,\n UserPoolId: this.config.userPoolId\n });\n return true;\n } catch {\n // User does not exist\n return false;\n }\n }\n\n async createUser(params: {\n username: string;\n temporaryPassword: string;\n attributes: ServiceAbstraction.UserAttributes;\n }): Promise<void> {\n const createUserParams: AdminCreateUserRequest = {\n UserPoolId: this.config.userPoolId,\n Username: params.username,\n DesiredDeliveryMediums: [],\n ForceAliasCreation: false,\n MessageAction: \"SUPPRESS\",\n TemporaryPassword: params.temporaryPassword,\n UserAttributes: [\n {\n Name: \"given_name\",\n Value: params.attributes.givenName || \"\"\n },\n {\n Name: \"family_name\",\n Value: params.attributes.familyName || \"\"\n },\n {\n Name: \"preferred_username\",\n Value: params.attributes.preferredUsername\n },\n {\n Name: \"email\",\n Value: params.attributes.email\n },\n {\n Name: \"custom:id\",\n Value: params.attributes.customId\n }\n ]\n };\n\n await this.cognito.adminCreateUser(createUserParams);\n }\n\n async setEmailVerified(username: string): Promise<void> {\n await this.cognito.adminUpdateUserAttributes({\n UserPoolId: this.config.userPoolId,\n Username: username,\n UserAttributes: [\n {\n Name: \"email_verified\",\n Value: \"true\"\n }\n ]\n });\n }\n\n async setPermanentPassword(username: string, password: string): Promise<void> {\n await this.cognito.adminSetUserPassword({\n Permanent: true,\n Password: password,\n Username: username,\n UserPoolId: this.config.userPoolId\n });\n }\n\n async updateUserAttributes(\n username: string,\n attributes: Record<string, string>\n ): Promise<void> {\n const userAttributes = Object.entries(attributes).map(([name, value]) => ({\n Name: name,\n Value: value\n }));\n\n await this.cognito.adminUpdateUserAttributes({\n UserPoolId: this.config.userPoolId,\n Username: username,\n UserAttributes: userAttributes\n });\n }\n\n async deleteUser(username: string): Promise<void> {\n await this.cognito.adminDeleteUser({\n UserPoolId: this.config.userPoolId,\n Username: username\n });\n }\n}\n\nexport const CognitoService = ServiceAbstraction.createImplementation({\n implementation: CognitoServiceImpl,\n dependencies: [CognitoConfig]\n});\n"],"names":["CognitoServiceImpl","config","CognitoIdentityProvider","username","params","createUserParams","password","attributes","userAttributes","Object","name","value","CognitoService","ServiceAbstraction","CognitoConfig"],"mappings":";;AAIA,MAAMA;IAGF,YAAoBC,MAA+B,CAAE;aAAjCA,MAAM,GAANA;QAChB,IAAI,CAAC,OAAO,GAAG,IAAIC,wBAAwB;YAAE,QAAQD,OAAO,MAAM;QAAC;IACvE;IAEA,MAAM,WAAWE,QAAgB,EAAoB;QACjD,IAAI;YACA,MAAM,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC;gBAC5B,UAAUA;gBACV,YAAY,IAAI,CAAC,MAAM,CAAC,UAAU;YACtC;YACA,OAAO;QACX,EAAE,OAAM;YAEJ,OAAO;QACX;IACJ;IAEA,MAAM,WAAWC,MAIhB,EAAiB;QACd,MAAMC,mBAA2C;YAC7C,YAAY,IAAI,CAAC,MAAM,CAAC,UAAU;YAClC,UAAUD,OAAO,QAAQ;YACzB,wBAAwB,EAAE;YAC1B,oBAAoB;YACpB,eAAe;YACf,mBAAmBA,OAAO,iBAAiB;YAC3C,gBAAgB;gBACZ;oBACI,MAAM;oBACN,OAAOA,OAAO,UAAU,CAAC,SAAS,IAAI;gBAC1C;gBACA;oBACI,MAAM;oBACN,OAAOA,OAAO,UAAU,CAAC,UAAU,IAAI;gBAC3C;gBACA;oBACI,MAAM;oBACN,OAAOA,OAAO,UAAU,CAAC,iBAAiB;gBAC9C;gBACA;oBACI,MAAM;oBACN,OAAOA,OAAO,UAAU,CAAC,KAAK;gBAClC;gBACA;oBACI,MAAM;oBACN,OAAOA,OAAO,UAAU,CAAC,QAAQ;gBACrC;aACH;QACL;QAEA,MAAM,IAAI,CAAC,OAAO,CAAC,eAAe,CAACC;IACvC;IAEA,MAAM,iBAAiBF,QAAgB,EAAiB;QACpD,MAAM,IAAI,CAAC,OAAO,CAAC,yBAAyB,CAAC;YACzC,YAAY,IAAI,CAAC,MAAM,CAAC,UAAU;YAClC,UAAUA;YACV,gBAAgB;gBACZ;oBACI,MAAM;oBACN,OAAO;gBACX;aACH;QACL;IACJ;IAEA,MAAM,qBAAqBA,QAAgB,EAAEG,QAAgB,EAAiB;QAC1E,MAAM,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC;YACpC,WAAW;YACX,UAAUA;YACV,UAAUH;YACV,YAAY,IAAI,CAAC,MAAM,CAAC,UAAU;QACtC;IACJ;IAEA,MAAM,qBACFA,QAAgB,EAChBI,UAAkC,EACrB;QACb,MAAMC,iBAAiBC,OAAO,OAAO,CAACF,YAAY,GAAG,CAAC,CAAC,CAACG,MAAMC,MAAM,GAAM;gBACtE,MAAMD;gBACN,OAAOC;YACX;QAEA,MAAM,IAAI,CAAC,OAAO,CAAC,yBAAyB,CAAC;YACzC,YAAY,IAAI,CAAC,MAAM,CAAC,UAAU;YAClC,UAAUR;YACV,gBAAgBK;QACpB;IACJ;IAEA,MAAM,WAAWL,QAAgB,EAAiB;QAC9C,MAAM,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC;YAC/B,YAAY,IAAI,CAAC,MAAM,CAAC,UAAU;YAClC,UAAUA;QACd;IACJ;AACJ;AAEO,MAAMS,gCAAiBC,eAAAA,oBAAuC,CAAC;IAClE,gBAAgBb;IAChB,cAAc;QAACc;KAAc;AACjC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { BaseUserAttributes } from "@webiny/api-core/types/users.js";
|
|
2
|
+
export interface AttributeGetter {
|
|
3
|
+
(user: BaseUserAttributes): string;
|
|
4
|
+
}
|
|
5
|
+
export interface ICognitoConfig {
|
|
6
|
+
region: string;
|
|
7
|
+
userPoolId: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const CognitoConfig: import("@webiny/di").Abstraction<ICognitoConfig>;
|
|
10
|
+
export declare namespace CognitoConfig {
|
|
11
|
+
type Interface = ICognitoConfig;
|
|
12
|
+
}
|
|
13
|
+
export interface CognitoUserAttributes {
|
|
14
|
+
givenName?: string;
|
|
15
|
+
familyName?: string;
|
|
16
|
+
preferredUsername: string;
|
|
17
|
+
email: string;
|
|
18
|
+
customId: string;
|
|
19
|
+
}
|
|
20
|
+
export interface ICognitoService {
|
|
21
|
+
/**
|
|
22
|
+
* Check if a user exists in Cognito User Pool
|
|
23
|
+
*/
|
|
24
|
+
userExists(username: string): Promise<boolean>;
|
|
25
|
+
/**
|
|
26
|
+
* Create a new user in Cognito User Pool
|
|
27
|
+
*/
|
|
28
|
+
createUser(params: {
|
|
29
|
+
username: string;
|
|
30
|
+
temporaryPassword: string;
|
|
31
|
+
attributes: CognitoUserAttributes;
|
|
32
|
+
}): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Set email as verified for a user
|
|
35
|
+
*/
|
|
36
|
+
setEmailVerified(username: string): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Set a permanent password for a user
|
|
39
|
+
*/
|
|
40
|
+
setPermanentPassword(username: string, password: string): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Update user attributes in Cognito
|
|
43
|
+
*/
|
|
44
|
+
updateUserAttributes(username: string, attributes: Record<string, string>): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Delete a user from Cognito User Pool
|
|
47
|
+
*/
|
|
48
|
+
deleteUser(username: string): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
export declare const CognitoService: import("@webiny/di").Abstraction<ICognitoService>;
|
|
51
|
+
export declare namespace CognitoService {
|
|
52
|
+
type Interface = ICognitoService;
|
|
53
|
+
type UserAttributes = CognitoUserAttributes;
|
|
54
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/CognitoService/abstractions.js","sources":["../../../../src/api/features/CognitoService/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { BaseUserAttributes } from \"@webiny/api-core/types/users.js\";\n\nexport interface AttributeGetter {\n (user: BaseUserAttributes): string;\n}\n\nexport interface ICognitoConfig {\n region: string;\n userPoolId: string;\n}\n\nexport const CognitoConfig = createAbstraction<ICognitoConfig>(\"CognitoConfig\");\n\nexport namespace CognitoConfig {\n export type Interface = ICognitoConfig;\n}\n\n// Cognito Service\n\nexport interface CognitoUserAttributes {\n givenName?: string;\n familyName?: string;\n preferredUsername: string;\n email: string;\n customId: string;\n}\n\nexport interface ICognitoService {\n /**\n * Check if a user exists in Cognito User Pool\n */\n userExists(username: string): Promise<boolean>;\n\n /**\n * Create a new user in Cognito User Pool\n */\n createUser(params: {\n username: string;\n temporaryPassword: string;\n attributes: CognitoUserAttributes;\n }): Promise<void>;\n\n /**\n * Set email as verified for a user\n */\n setEmailVerified(username: string): Promise<void>;\n\n /**\n * Set a permanent password for a user\n */\n setPermanentPassword(username: string, password: string): Promise<void>;\n\n /**\n * Update user attributes in Cognito\n */\n updateUserAttributes(username: string, attributes: Record<string, string>): Promise<void>;\n\n /**\n * Delete a user from Cognito User Pool\n */\n deleteUser(username: string): Promise<void>;\n}\n\nexport const CognitoService = createAbstraction<ICognitoService>(\"CognitoService\");\nexport namespace CognitoService {\n export type Interface = ICognitoService;\n export type UserAttributes = CognitoUserAttributes;\n}\n"],"names":["CognitoConfig","createAbstraction","CognitoService"],"mappings":";AAYO,MAAMA,gBAAgBC,kBAAkC;AAoDxD,MAAMC,iBAAiBD,kBAAmC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { CognitoService } from "./CognitoService.js";
|
|
3
|
+
import { CognitoConfig } from "./abstractions.js";
|
|
4
|
+
const CognitoServiceFeature = createFeature({
|
|
5
|
+
name: "cognitoService",
|
|
6
|
+
register (container, config) {
|
|
7
|
+
container.register(CognitoService).inSingletonScope();
|
|
8
|
+
container.registerInstance(CognitoConfig, config);
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
export { CognitoServiceFeature };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/CognitoService/feature.js","sources":["../../../../src/api/features/CognitoService/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { CognitoService } from \"./CognitoService.js\";\nimport { CognitoConfig } from \"./abstractions.js\";\n\nexport type UserPoolConfig = {\n region: string;\n userPoolId: string;\n};\n\nexport const CognitoServiceFeature = createFeature<UserPoolConfig>({\n name: \"cognitoService\",\n register(container, config) {\n container.register(CognitoService).inSingletonScope();\n\n container.registerInstance(CognitoConfig, config);\n }\n});\n"],"names":["CognitoServiceFeature","createFeature","container","config","CognitoService","CognitoConfig"],"mappings":";;;AASO,MAAMA,wBAAwBC,cAA8B;IAC/D,MAAM;IACN,UAASC,SAAS,EAAEC,MAAM;QACtBD,UAAU,QAAQ,CAACE,gBAAgB,gBAAgB;QAEnDF,UAAU,gBAAgB,CAACG,eAAeF;IAC9C;AACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./abstractions.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./abstractions.js";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { AdminUsersRepository } from "@webiny/api-core/features/users/shared/abstractions.js";
|
|
3
|
+
import type { AdminUser } from "@webiny/api-core/types/users.js";
|
|
4
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
5
|
+
import { CreateUserUseCase as CoreCreateUser } from "@webiny/api-core/features/users/CreateUser/index.js";
|
|
6
|
+
import { ListUsersUseCase } from "@webiny/api-core/features/users/ListUsers/index.js";
|
|
7
|
+
import { CreateUserUseCase as UseCaseAbstraction } from "./abstractions.js";
|
|
8
|
+
import type { CreateAdminUserInput } from "./abstractions.js";
|
|
9
|
+
import { CognitoService } from "../../../api/features/CognitoService/index.js";
|
|
10
|
+
declare class CreateUserUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
11
|
+
private identityContext;
|
|
12
|
+
private cognitoService;
|
|
13
|
+
private createUserUseCase;
|
|
14
|
+
private listUsersUseCase;
|
|
15
|
+
private repository;
|
|
16
|
+
constructor(identityContext: IdentityContext.Interface, cognitoService: CognitoService.Interface, createUserUseCase: CoreCreateUser.Interface, listUsersUseCase: ListUsersUseCase.Interface, repository: AdminUsersRepository.Interface);
|
|
17
|
+
execute(input: CreateAdminUserInput): Promise<Result<AdminUser, UseCaseAbstraction.Error>>;
|
|
18
|
+
}
|
|
19
|
+
export declare const CreateUserUseCase: typeof CreateUserUseCaseImpl & {
|
|
20
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").ICreateUserUseCase>;
|
|
21
|
+
};
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { AdminUsersRepository } from "@webiny/api-core/features/users/shared/abstractions.js";
|
|
3
|
+
import { NotAuthorizedError, UserValidationError } from "@webiny/api-core/features/users/shared/errors.js";
|
|
4
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
5
|
+
import { CreateUserUseCase } from "@webiny/api-core/features/users/CreateUser/index.js";
|
|
6
|
+
import { ListUsersUseCase } from "@webiny/api-core/features/users/ListUsers/index.js";
|
|
7
|
+
import { CreateUserUseCase as external_abstractions_js_CreateUserUseCase } from "./abstractions.js";
|
|
8
|
+
import { Username } from "../../domain/Username.js";
|
|
9
|
+
import { CognitoAccountExistsError, CognitoCreateUserError } from "../../domain/errors.js";
|
|
10
|
+
import { createAdminUserValidation } from "./schema.js";
|
|
11
|
+
import { CognitoService } from "../CognitoService/index.js";
|
|
12
|
+
class CreateUserUseCaseImpl {
|
|
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;
|
|
19
|
+
}
|
|
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;
|
|
33
|
+
try {
|
|
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));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
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
|
+
]
|
|
77
|
+
});
|
|
78
|
+
export { CreateUserUseCase_CreateUserUseCase as CreateUserUseCase };
|
|
79
|
+
|
|
80
|
+
//# sourceMappingURL=CreateUserUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/CreateUser/CreateUserUseCase.js","sources":["../../../../src/api/features/CreateUser/CreateUserUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { AdminUsersRepository } from \"@webiny/api-core/features/users/shared/abstractions.js\";\nimport {\n NotAuthorizedError,\n UserValidationError\n} from \"@webiny/api-core/features/users/shared/errors.js\";\nimport type { AdminUser } from \"@webiny/api-core/types/users.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { CreateUserUseCase as CoreCreateUser } from \"@webiny/api-core/features/users/CreateUser/index.js\";\nimport { ListUsersUseCase } from \"@webiny/api-core/features/users/ListUsers/index.js\";\n\nimport { CreateUserUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { Username } from \"~/api/domain/Username.js\";\nimport { CognitoAccountExistsError, CognitoCreateUserError } from \"~/api/domain/errors.js\";\nimport { createAdminUserValidation } from \"./schema.js\";\nimport type { CreateAdminUserInput } from \"./abstractions.js\";\nimport { CognitoService } from \"~/api/features/CognitoService/index.js\";\n\nclass CreateUserUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private cognitoService: CognitoService.Interface,\n private createUserUseCase: CoreCreateUser.Interface,\n private listUsersUseCase: ListUsersUseCase.Interface,\n private repository: AdminUsersRepository.Interface\n ) {}\n\n async execute(\n input: CreateAdminUserInput\n ): Promise<Result<AdminUser, UseCaseAbstraction.Error>> {\n const permission = await this.identityContext.getPermission(\"adminUsers.user\");\n if (!permission) {\n return Result.fail(new NotAuthorizedError());\n }\n\n // Validate input (including password)\n const validation = createAdminUserValidation.safeParse(input);\n if (!validation.success) {\n return Result.fail(new UserValidationError(validation.error.issues[0].message));\n }\n\n const data = validation.data;\n const { password, ...userDataWithoutPassword } = data;\n\n const username = Username.fromUser(data);\n\n // Check if user exists in database (faster than Cognito check)\n const existingUserResult = await this.repository.get({ email: data.email });\n if (existingUserResult.isOk()) {\n return Result.fail(new CognitoAccountExistsError(data.email));\n }\n\n let user: AdminUser | undefined = undefined;\n\n try {\n // Check if user exists in Cognito\n const userExists = await this.cognitoService.userExists(username);\n if (userExists) {\n return Result.fail(new CognitoAccountExistsError(data.email));\n }\n // Create user in api-core\n const createUserResult = await this.createUserUseCase.execute(userDataWithoutPassword);\n if (createUserResult.isFail()) {\n return Result.fail(createUserResult.error);\n }\n\n user = createUserResult.value;\n\n // Create user in Cognito\n await this.cognitoService.createUser({\n username,\n temporaryPassword: password,\n attributes: {\n givenName: data.firstName,\n familyName: data.lastName,\n preferredUsername: username,\n email: username,\n customId: user.id\n }\n });\n\n // Set email as verified\n await this.cognitoService.setEmailVerified(username);\n\n // Check if this is the first user in the system, and if so, set permanent password\n const usersResult = await this.listUsersUseCase.execute();\n if (usersResult.isFail()) {\n // Log error but don't fail the operation\n console.error(`Failed to list users: ${usersResult.error.message}`);\n } else {\n const users = usersResult.value;\n if (users.length <= 1) {\n // This is the first user, set permanent password\n await this.cognitoService.setPermanentPassword(username, password);\n }\n }\n\n return Result.ok(user);\n } catch (cognitoError) {\n if (user) {\n // Rollback: Delete user from api-core if Cognito creation failed\n try {\n await this.repository.delete(user);\n } catch (rollbackError) {\n console.error(\"Failed to rollback user creation:\", rollbackError);\n }\n }\n return Result.fail(new CognitoCreateUserError(cognitoError as Error));\n }\n }\n}\n\nexport const CreateUserUseCase = UseCaseAbstraction.createImplementation({\n implementation: CreateUserUseCaseImpl,\n dependencies: [\n IdentityContext,\n CognitoService,\n CoreCreateUser,\n ListUsersUseCase,\n AdminUsersRepository\n ]\n});\n"],"names":["CreateUserUseCaseImpl","identityContext","cognitoService","createUserUseCase","listUsersUseCase","repository","input","permission","Result","NotAuthorizedError","validation","createAdminUserValidation","UserValidationError","data","password","userDataWithoutPassword","username","Username","existingUserResult","CognitoAccountExistsError","user","userExists","createUserResult","usersResult","console","users","cognitoError","rollbackError","CognitoCreateUserError","CreateUserUseCase","UseCaseAbstraction","IdentityContext","CognitoService","CoreCreateUser","ListUsersUseCase","AdminUsersRepository"],"mappings":";;;;;;;;;;;AAkBA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,cAAwC,EACxCC,iBAA2C,EAC3CC,gBAA4C,EAC5CC,UAA0C,CACpD;aALUJ,eAAe,GAAfA;aACAC,cAAc,GAAdA;aACAC,iBAAiB,GAAjBA;aACAC,gBAAgB,GAAhBA;aACAC,UAAU,GAAVA;IACT;IAEH,MAAM,QACFC,KAA2B,EACyB;QACpD,MAAMC,aAAa,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC;QAC5D,IAAI,CAACA,YACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAI3B,MAAMC,aAAaC,0BAA0B,SAAS,CAACL;QACvD,IAAI,CAACI,WAAW,OAAO,EACnB,OAAOF,OAAO,IAAI,CAAC,IAAII,oBAAoBF,WAAW,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO;QAGjF,MAAMG,OAAOH,WAAW,IAAI;QAC5B,MAAM,EAAEI,QAAQ,EAAE,GAAGC,yBAAyB,GAAGF;QAEjD,MAAMG,WAAWC,SAAS,QAAQ,CAACJ;QAGnC,MAAMK,qBAAqB,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,OAAOL,KAAK,KAAK;QAAC;QACzE,IAAIK,mBAAmB,IAAI,IACvB,OAAOV,OAAO,IAAI,CAAC,IAAIW,0BAA0BN,KAAK,KAAK;QAG/D,IAAIO;QAEJ,IAAI;YAEA,MAAMC,aAAa,MAAM,IAAI,CAAC,cAAc,CAAC,UAAU,CAACL;YACxD,IAAIK,YACA,OAAOb,OAAO,IAAI,CAAC,IAAIW,0BAA0BN,KAAK,KAAK;YAG/D,MAAMS,mBAAmB,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAACP;YAC9D,IAAIO,iBAAiB,MAAM,IACvB,OAAOd,OAAO,IAAI,CAACc,iBAAiB,KAAK;YAG7CF,OAAOE,iBAAiB,KAAK;YAG7B,MAAM,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC;gBACjCN;gBACA,mBAAmBF;gBACnB,YAAY;oBACR,WAAWD,KAAK,SAAS;oBACzB,YAAYA,KAAK,QAAQ;oBACzB,mBAAmBG;oBACnB,OAAOA;oBACP,UAAUI,KAAK,EAAE;gBACrB;YACJ;YAGA,MAAM,IAAI,CAAC,cAAc,CAAC,gBAAgB,CAACJ;YAG3C,MAAMO,cAAc,MAAM,IAAI,CAAC,gBAAgB,CAAC,OAAO;YACvD,IAAIA,YAAY,MAAM,IAElBC,QAAQ,KAAK,CAAC,CAAC,sBAAsB,EAAED,YAAY,KAAK,CAAC,OAAO,EAAE;iBAC/D;gBACH,MAAME,QAAQF,YAAY,KAAK;gBAC/B,IAAIE,MAAM,MAAM,IAAI,GAEhB,MAAM,IAAI,CAAC,cAAc,CAAC,oBAAoB,CAACT,UAAUF;YAEjE;YAEA,OAAON,OAAO,EAAE,CAACY;QACrB,EAAE,OAAOM,cAAc;YACnB,IAAIN,MAEA,IAAI;gBACA,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAACA;YACjC,EAAE,OAAOO,eAAe;gBACpBH,QAAQ,KAAK,CAAC,qCAAqCG;YACvD;YAEJ,OAAOnB,OAAO,IAAI,CAAC,IAAIoB,uBAAuBF;QAClD;IACJ;AACJ;AAEO,MAAMG,sCAAoBC,2CAAAA,oBAAuC,CAAC;IACrE,gBAAgB9B;IAChB,cAAc;QACV+B;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Result } from "@webiny/feature/api";
|
|
2
|
+
import type { AdminUser } from "@webiny/api-core/types/users.js";
|
|
3
|
+
import type { NotAuthorizedError, EmailTakenError, UserValidationError } from "@webiny/api-core/features/users/shared/errors.js";
|
|
4
|
+
import type { RepositoryError } from "@webiny/api-core/features/users/shared/abstractions.js";
|
|
5
|
+
import type { CognitoAccountExistsError, CognitoCreateUserError } from "../../../api/domain/errors.js";
|
|
6
|
+
export interface CreateAdminUserInput {
|
|
7
|
+
id?: string;
|
|
8
|
+
displayName?: string;
|
|
9
|
+
email: string;
|
|
10
|
+
firstName?: string;
|
|
11
|
+
lastName?: string;
|
|
12
|
+
password: string;
|
|
13
|
+
avatar?: Record<string, any> | null;
|
|
14
|
+
roles?: string[];
|
|
15
|
+
teams?: string[];
|
|
16
|
+
}
|
|
17
|
+
export interface ICreateUserUseCaseErrors {
|
|
18
|
+
authorization: NotAuthorizedError;
|
|
19
|
+
validation: UserValidationError;
|
|
20
|
+
emailTaken: EmailTakenError;
|
|
21
|
+
repository: RepositoryError;
|
|
22
|
+
cognitoAccountExists: CognitoAccountExistsError;
|
|
23
|
+
cognitoCreateUser: CognitoCreateUserError;
|
|
24
|
+
}
|
|
25
|
+
type CreateAdminUserError = ICreateUserUseCaseErrors[keyof ICreateUserUseCaseErrors];
|
|
26
|
+
export interface ICreateUserUseCase {
|
|
27
|
+
execute(input: CreateAdminUserInput): Promise<Result<AdminUser, CreateAdminUserError>>;
|
|
28
|
+
}
|
|
29
|
+
export declare const CreateUserUseCase: import("@webiny/di").Abstraction<ICreateUserUseCase>;
|
|
30
|
+
export declare namespace CreateUserUseCase {
|
|
31
|
+
type Interface = ICreateUserUseCase;
|
|
32
|
+
type Input = CreateAdminUserInput;
|
|
33
|
+
type Error = CreateAdminUserError;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/CreateUser/abstractions.js","sources":["../../../../src/api/features/CreateUser/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Result } from \"@webiny/feature/api\";\nimport type { AdminUser } from \"@webiny/api-core/types/users.js\";\nimport type {\n NotAuthorizedError,\n EmailTakenError,\n UserValidationError\n} from \"@webiny/api-core/features/users/shared/errors.js\";\nimport type { RepositoryError } from \"@webiny/api-core/features/users/shared/abstractions.js\";\nimport type { CognitoAccountExistsError, CognitoCreateUserError } from \"~/api/domain/errors.js\";\n\nexport interface CreateAdminUserInput {\n id?: string;\n displayName?: string;\n email: string;\n firstName?: string;\n lastName?: string;\n password: string;\n avatar?: Record<string, any> | null;\n roles?: string[];\n teams?: string[];\n}\n\nexport interface ICreateUserUseCaseErrors {\n authorization: NotAuthorizedError;\n validation: UserValidationError;\n emailTaken: EmailTakenError;\n repository: RepositoryError;\n cognitoAccountExists: CognitoAccountExistsError;\n cognitoCreateUser: CognitoCreateUserError;\n}\n\ntype CreateAdminUserError = ICreateUserUseCaseErrors[keyof ICreateUserUseCaseErrors];\n\nexport interface ICreateUserUseCase {\n execute(input: CreateAdminUserInput): Promise<Result<AdminUser, CreateAdminUserError>>;\n}\n\nexport const CreateUserUseCase = createAbstraction<ICreateUserUseCase>(\"CreateUserUseCase\");\n\nexport namespace CreateUserUseCase {\n export type Interface = ICreateUserUseCase;\n export type Input = CreateAdminUserInput;\n export type Error = CreateAdminUserError;\n}\n"],"names":["CreateUserUseCase","createAbstraction"],"mappings":";AAsCO,MAAMA,oBAAoBC,kBAAsC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { CreateUserUseCase } from "./CreateUserUseCase.js";
|
|
3
|
+
const CreateUserFeature = createFeature({
|
|
4
|
+
name: "CreateUserFeature",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(CreateUserUseCase);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { CreateUserFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const createAdminUserValidation: z.ZodObject<{
|
|
3
|
+
id: z.ZodOptional<z.ZodString>;
|
|
4
|
+
displayName: z.ZodOptional<z.ZodString>;
|
|
5
|
+
email: z.ZodString;
|
|
6
|
+
firstName: z.ZodOptional<z.ZodString>;
|
|
7
|
+
lastName: z.ZodOptional<z.ZodString>;
|
|
8
|
+
password: z.ZodString;
|
|
9
|
+
avatar: z.ZodNullable<z.ZodOptional<z.ZodObject<{
|
|
10
|
+
id: z.ZodString;
|
|
11
|
+
src: z.ZodString;
|
|
12
|
+
}, z.core.$strip>>>;
|
|
13
|
+
roles: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString>>>;
|
|
14
|
+
teams: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString>>>;
|
|
15
|
+
}, z.core.$strip>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
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
|
+
});
|
|
16
|
+
export { createAdminUserValidation };
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { DeleteUserUseCase as CoreDeleteUser } from "@webiny/api-core/features/users/DeleteUser/index.js";
|
|
3
|
+
import { GetUserUseCase } from "@webiny/api-core/features/users/GetUser/index.js";
|
|
4
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
5
|
+
import { DeleteUserUseCase as UseCaseAbstraction } from "./abstractions.js";
|
|
6
|
+
import { CognitoService } from "../CognitoService/abstractions.js";
|
|
7
|
+
declare class DeleteUserUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
8
|
+
private identityContext;
|
|
9
|
+
private cognitoService;
|
|
10
|
+
private deleteUserUseCase;
|
|
11
|
+
private getUserUseCase;
|
|
12
|
+
constructor(identityContext: IdentityContext.Interface, cognitoService: CognitoService.Interface, deleteUserUseCase: CoreDeleteUser.Interface, getUserUseCase: GetUserUseCase.Interface);
|
|
13
|
+
execute(id: string): Promise<Result<void, UseCaseAbstraction.Error>>;
|
|
14
|
+
}
|
|
15
|
+
export declare const DeleteUserUseCase: import("@webiny/di").Implementation<typeof DeleteUserUseCaseImpl>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Result, createImplementation } from "@webiny/feature/api";
|
|
2
|
+
import { DeleteUserUseCase } from "@webiny/api-core/features/users/DeleteUser/index.js";
|
|
3
|
+
import { GetUserUseCase } from "@webiny/api-core/features/users/GetUser/index.js";
|
|
4
|
+
import { NotAuthorizedError } from "@webiny/api-core/features/users/shared/errors.js";
|
|
5
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
6
|
+
import { DeleteUserUseCase as external_abstractions_js_DeleteUserUseCase } from "./abstractions.js";
|
|
7
|
+
import { Username } from "../../domain/Username.js";
|
|
8
|
+
import { CognitoDeleteUserError } from "../../domain/errors.js";
|
|
9
|
+
import { CognitoService } from "../CognitoService/abstractions.js";
|
|
10
|
+
class DeleteUserUseCaseImpl {
|
|
11
|
+
constructor(identityContext, cognitoService, deleteUserUseCase, getUserUseCase){
|
|
12
|
+
this.identityContext = identityContext;
|
|
13
|
+
this.cognitoService = cognitoService;
|
|
14
|
+
this.deleteUserUseCase = deleteUserUseCase;
|
|
15
|
+
this.getUserUseCase = getUserUseCase;
|
|
16
|
+
}
|
|
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
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
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
|
+
]
|
|
44
|
+
});
|
|
45
|
+
export { DeleteUserUseCase_DeleteUserUseCase as DeleteUserUseCase };
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=DeleteUserUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/DeleteUser/DeleteUserUseCase.js","sources":["../../../../src/api/features/DeleteUser/DeleteUserUseCase.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport { DeleteUserUseCase as CoreDeleteUser } from \"@webiny/api-core/features/users/DeleteUser/index.js\";\nimport { GetUserUseCase } from \"@webiny/api-core/features/users/GetUser/index.js\";\nimport { NotAuthorizedError } from \"@webiny/api-core/features/users/shared/errors.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { DeleteUserUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { Username } from \"~/api/domain/Username.js\";\nimport { CognitoDeleteUserError } from \"~/api/domain/errors.js\";\nimport { CognitoService } from \"../CognitoService/abstractions.js\";\n\nclass DeleteUserUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private cognitoService: CognitoService.Interface,\n private deleteUserUseCase: CoreDeleteUser.Interface,\n private getUserUseCase: GetUserUseCase.Interface\n ) {}\n\n async execute(id: string): Promise<Result<void, UseCaseAbstraction.Error>> {\n const permission = await this.identityContext.getPermission(\"adminUsers.user\");\n if (!permission) {\n return Result.fail(new NotAuthorizedError());\n }\n\n // Get user to have email for Cognito deletion\n const getUserResult = await this.getUserUseCase.execute({ id });\n if (getUserResult.isFail()) {\n return Result.fail(getUserResult.error);\n }\n\n const user = getUserResult.value;\n\n // Delete user from the database\n const deleteUserResult = await this.deleteUserUseCase.execute(id);\n if (deleteUserResult.isFail()) {\n return Result.fail(deleteUserResult.error);\n }\n\n // Delete user from Cognito\n try {\n await this.cognitoService.deleteUser(Username.fromUser(user));\n\n return Result.ok();\n } catch (cognitoError) {\n return Result.fail(new CognitoDeleteUserError(cognitoError as Error));\n }\n }\n}\n\nexport const DeleteUserUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: DeleteUserUseCaseImpl,\n dependencies: [IdentityContext, CognitoService, CoreDeleteUser, GetUserUseCase]\n});\n"],"names":["DeleteUserUseCaseImpl","identityContext","cognitoService","deleteUserUseCase","getUserUseCase","id","permission","Result","NotAuthorizedError","getUserResult","user","deleteUserResult","Username","cognitoError","CognitoDeleteUserError","DeleteUserUseCase","createImplementation","UseCaseAbstraction","IdentityContext","CognitoService","CoreDeleteUser","GetUserUseCase"],"mappings":";;;;;;;;;AAWA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,cAAwC,EACxCC,iBAA2C,EAC3CC,cAAwC,CAClD;aAJUH,eAAe,GAAfA;aACAC,cAAc,GAAdA;aACAC,iBAAiB,GAAjBA;aACAC,cAAc,GAAdA;IACT;IAEH,MAAM,QAAQC,EAAU,EAAmD;QACvE,MAAMC,aAAa,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC;QAC5D,IAAI,CAACA,YACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAI3B,MAAMC,gBAAgB,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC;YAAEJ;QAAG;QAC7D,IAAII,cAAc,MAAM,IACpB,OAAOF,OAAO,IAAI,CAACE,cAAc,KAAK;QAG1C,MAAMC,OAAOD,cAAc,KAAK;QAGhC,MAAME,mBAAmB,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAACN;QAC9D,IAAIM,iBAAiB,MAAM,IACvB,OAAOJ,OAAO,IAAI,CAACI,iBAAiB,KAAK;QAI7C,IAAI;YACA,MAAM,IAAI,CAAC,cAAc,CAAC,UAAU,CAACC,SAAS,QAAQ,CAACF;YAEvD,OAAOH,OAAO,EAAE;QACpB,EAAE,OAAOM,cAAc;YACnB,OAAON,OAAO,IAAI,CAAC,IAAIO,uBAAuBD;QAClD;IACJ;AACJ;AAEO,MAAME,sCAAoBC,qBAAqB;IAClD,aAAaC;IACb,gBAAgBjB;IAChB,cAAc;QAACkB;QAAiBC;QAAgBC;QAAgBC;KAAe;AACnF"}
|