@webiny/cognito 0.0.0-unstable.3c5210ad37
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 +8 -0
- package/Cognito.js +29 -0
- package/Cognito.js.map +1 -0
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/admin/Cognito.d.ts +6 -0
- package/admin/Cognito.js +51 -0
- package/admin/Cognito.js.map +1 -0
- package/admin/CognitoLogin.d.ts +7 -0
- package/admin/CognitoLogin.js +18 -0
- package/admin/CognitoLogin.js.map +1 -0
- package/admin/Extension.d.ts +2 -0
- package/admin/Extension.js +20 -0
- package/admin/Extension.js.map +1 -0
- package/admin/SecurityPermission.d.ts +2 -0
- package/admin/SecurityPermission.js +26 -0
- package/admin/SecurityPermission.js.map +1 -0
- package/admin/federatedIdentityProviders.d.ts +9 -0
- package/admin/federatedIdentityProviders.js +9 -0
- package/admin/federatedIdentityProviders.js.map +1 -0
- package/admin/plugins/constants.d.ts +3 -0
- package/admin/plugins/constants.js +6 -0
- package/admin/plugins/constants.js.map +1 -0
- package/admin/plugins/userMenu/AccountDetails.d.ts +6 -0
- package/admin/plugins/userMenu/AccountDetails.js +23 -0
- package/admin/plugins/userMenu/AccountDetails.js.map +1 -0
- package/admin/plugins/userMenu/useIsDefaultTenant.d.ts +1 -0
- package/admin/plugins/userMenu/useIsDefaultTenant.js +15 -0
- package/admin/plugins/userMenu/useIsDefaultTenant.js.map +1 -0
- package/admin/presentation/Cognito/CognitoLoginScreen.d.ts +10 -0
- package/admin/presentation/Cognito/CognitoLoginScreen.js +54 -0
- package/admin/presentation/Cognito/CognitoLoginScreen.js.map +1 -0
- package/admin/presentation/Cognito/CognitoPresenter.d.ts +58 -0
- package/admin/presentation/Cognito/CognitoPresenter.js +277 -0
- package/admin/presentation/Cognito/CognitoPresenter.js.map +1 -0
- package/admin/presentation/Cognito/abstractions.d.ts +72 -0
- package/admin/presentation/Cognito/abstractions.js +4 -0
- package/admin/presentation/Cognito/abstractions.js.map +1 -0
- package/admin/presentation/Cognito/components/Divider.d.ts +2 -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 +7 -0
- package/admin/presentation/Cognito/components/FederatedLogin.js +32 -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 +14 -0
- package/admin/presentation/Cognito/components/FederatedProviders.js.map +1 -0
- package/admin/presentation/Cognito/components/FooterSignIn.d.ts +6 -0
- package/admin/presentation/Cognito/components/FooterSignIn.js +15 -0
- package/admin/presentation/Cognito/components/FooterSignIn.js.map +1 -0
- package/admin/presentation/Cognito/components/PasswordResetCodeSent.d.ts +9 -0
- package/admin/presentation/Cognito/components/PasswordResetCodeSent.js +43 -0
- package/admin/presentation/Cognito/components/PasswordResetCodeSent.js.map +1 -0
- package/admin/presentation/Cognito/components/RequestPasswordResetCode.d.ts +8 -0
- package/admin/presentation/Cognito/components/RequestPasswordResetCode.js +45 -0
- package/admin/presentation/Cognito/components/RequestPasswordResetCode.js.map +1 -0
- package/admin/presentation/Cognito/components/RequireNewPassword.d.ts +8 -0
- package/admin/presentation/Cognito/components/RequireNewPassword.js +55 -0
- package/admin/presentation/Cognito/components/RequireNewPassword.js.map +1 -0
- package/admin/presentation/Cognito/components/SetNewPassword.d.ts +8 -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/SignIn.d.ts +10 -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 +67 -0
- package/admin/presentation/Cognito/components/View.js.map +1 -0
- package/admin/presentation/Cognito/feature.d.ts +3 -0
- package/admin/presentation/Cognito/feature.js +16 -0
- package/admin/presentation/Cognito/feature.js.map +1 -0
- package/admin/presentation/shared/createPasswordValidator.d.ts +8 -0
- package/admin/presentation/shared/createPasswordValidator.js +27 -0
- package/admin/presentation/shared/createPasswordValidator.js.map +1 -0
- package/admin/presentation/shared/usePasswordValidator.d.ts +1 -0
- package/admin/presentation/shared/usePasswordValidator.js +15 -0
- package/admin/presentation/shared/usePasswordValidator.js.map +1 -0
- package/admin/routes.d.ts +10 -0
- package/admin/routes.js +21 -0
- package/admin/routes.js.map +1 -0
- package/admin/ui/UserItem.d.ts +10 -0
- package/admin/ui/UserItem.js +3 -0
- package/admin/ui/UserItem.js.map +1 -0
- package/admin/ui/components/AvatarImage/AvatarImage.d.ts +3 -0
- package/admin/ui/components/AvatarImage/AvatarImage.js +43 -0
- package/admin/ui/components/AvatarImage/AvatarImage.js.map +1 -0
- package/admin/ui/components/AvatarImage/AvatarImagePreview.d.ts +10 -0
- package/admin/ui/components/AvatarImage/AvatarImagePreview.js +55 -0
- package/admin/ui/components/AvatarImage/AvatarImagePreview.js.map +1 -0
- package/admin/ui/components/AvatarImage/AvatarImageTrigger.d.ts +7 -0
- package/admin/ui/components/AvatarImage/AvatarImageTrigger.js +29 -0
- package/admin/ui/components/AvatarImage/AvatarImageTrigger.js.map +1 -0
- package/admin/ui/components/AvatarImage/index.d.ts +1 -0
- package/admin/ui/components/AvatarImage/index.js +3 -0
- package/admin/ui/components/AvatarImage/index.js.map +1 -0
- package/admin/ui/views/Account/Account.d.ts +2 -0
- package/admin/ui/views/Account/Account.js +142 -0
- package/admin/ui/views/Account/Account.js.map +1 -0
- package/admin/ui/views/Account/graphql.d.ts +2 -0
- package/admin/ui/views/Account/graphql.js +40 -0
- package/admin/ui/views/Account/graphql.js.map +1 -0
- package/admin/ui/views/Account/index.d.ts +1 -0
- package/admin/ui/views/Account/index.js +3 -0
- package/admin/ui/views/Account/index.js.map +1 -0
- package/admin/ui/views/Users/UsersDataList.d.ts +3 -0
- package/admin/ui/views/Users/UsersDataList.js +172 -0
- package/admin/ui/views/Users/UsersDataList.js.map +1 -0
- package/admin/ui/views/Users/UsersForm.d.ts +5 -0
- package/admin/ui/views/Users/UsersForm.js +174 -0
- package/admin/ui/views/Users/UsersForm.js.map +1 -0
- package/admin/ui/views/Users/UsersView.d.ts +2 -0
- package/admin/ui/views/Users/UsersView.js +14 -0
- package/admin/ui/views/Users/UsersView.js.map +1 -0
- package/admin/ui/views/Users/components/DeleteAction.d.ts +7 -0
- package/admin/ui/views/Users/components/DeleteAction.js +36 -0
- package/admin/ui/views/Users/components/DeleteAction.js.map +1 -0
- package/admin/ui/views/Users/graphql.d.ts +5 -0
- package/admin/ui/views/Users/graphql.js +99 -0
- package/admin/ui/views/Users/graphql.js.map +1 -0
- package/admin/ui/views/Users/hooks/useUserForm.d.ts +27 -0
- package/admin/ui/views/Users/hooks/useUserForm.js +127 -0
- package/admin/ui/views/Users/hooks/useUserForm.js.map +1 -0
- package/admin/ui/views/Users/search.svg +20 -0
- package/admin/ui/views/utils.d.ts +3 -0
- package/admin/ui/views/utils.js +10 -0
- package/admin/ui/views/utils.js.map +1 -0
- package/api/CognitoApiFeature.d.ts +1 -0
- package/api/CognitoApiFeature.js +28 -0
- package/api/CognitoApiFeature.js.map +1 -0
- package/api/domain/Username.d.ts +4 -0
- package/api/domain/Username.js +7 -0
- package/api/domain/Username.js.map +1 -0
- package/api/domain/errors.d.ts +37 -0
- package/api/domain/errors.js +63 -0
- package/api/domain/errors.js.map +1 -0
- package/api/features/CognitoIdp/CognitoIdentityProvider.d.ts +15 -0
- package/api/features/CognitoIdp/CognitoIdentityProvider.js +61 -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 +4 -0
- package/api/features/CognitoIdp/abstractions.js.map +1 -0
- package/api/features/CognitoIdp/feature.d.ts +1 -0
- package/api/features/CognitoIdp/feature.js +10 -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 +4 -0
- package/api/features/CognitoIdp/index.js.map +1 -0
- package/api/features/CognitoService/CognitoService.d.ts +20 -0
- package/api/features/CognitoService/CognitoService.js +90 -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 +8 -0
- package/api/features/CognitoService/abstractions.js.map +1 -0
- package/api/features/CognitoService/feature.d.ts +5 -0
- package/api/features/CognitoService/feature.js +12 -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 +3 -0
- package/api/features/CognitoService/index.js.map +1 -0
- package/api/features/CreateUser/CreateUserUseCase.d.ts +22 -0
- package/api/features/CreateUser/CreateUserUseCase.js +106 -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 +4 -0
- package/api/features/CreateUser/abstractions.js.map +1 -0
- package/api/features/CreateUser/feature.d.ts +1 -0
- package/api/features/CreateUser/feature.js +10 -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 +4 -0
- package/api/features/CreateUser/index.js.map +1 -0
- package/api/features/CreateUser/schema.d.ts +47 -0
- package/api/features/CreateUser/schema.js +17 -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 +54 -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 +4 -0
- package/api/features/DeleteUser/abstractions.js.map +1 -0
- package/api/features/DeleteUser/feature.d.ts +1 -0
- package/api/features/DeleteUser/feature.js +10 -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 +4 -0
- package/api/features/DeleteUser/index.js.map +1 -0
- package/api/features/UpdateUser/UpdateUserUseCase.d.ts +21 -0
- package/api/features/UpdateUser/UpdateUserUseCase.js +88 -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 +4 -0
- package/api/features/UpdateUser/abstractions.js.map +1 -0
- package/api/features/UpdateUser/feature.d.ts +1 -0
- package/api/features/UpdateUser/feature.js +10 -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 +4 -0
- package/api/features/UpdateUser/index.js.map +1 -0
- package/api/features/UpdateUser/schema.d.ts +44 -0
- package/api/features/UpdateUser/schema.js +16 -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 +1 -0
- package/api/features/UserInstaller/feature.js +10 -0
- package/api/features/UserInstaller/feature.js.map +1 -0
- package/api/graphql/user.gql.d.ts +8 -0
- package/api/graphql/user.gql.js +167 -0
- package/api/graphql/user.gql.js.map +1 -0
- package/index.d.ts +2 -0
- package/index.js +4 -0
- package/index.js.map +1 -0
- package/package.json +48 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type UseUserForm = ReturnType<typeof useUserForm>;
|
|
2
|
+
interface SubmitUserCallableParams {
|
|
3
|
+
id?: string;
|
|
4
|
+
firstName: string;
|
|
5
|
+
lastName: string;
|
|
6
|
+
email: string;
|
|
7
|
+
password?: string;
|
|
8
|
+
avatar: {
|
|
9
|
+
src?: string;
|
|
10
|
+
};
|
|
11
|
+
external?: boolean;
|
|
12
|
+
}
|
|
13
|
+
interface SubmitUserCallable {
|
|
14
|
+
(data: SubmitUserCallableParams): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
export declare function useUserForm(): {
|
|
17
|
+
id: string | undefined;
|
|
18
|
+
loading: boolean;
|
|
19
|
+
user: any;
|
|
20
|
+
onSubmit: SubmitUserCallable;
|
|
21
|
+
isNewUser: boolean;
|
|
22
|
+
fullName: string;
|
|
23
|
+
showEmptyView: boolean;
|
|
24
|
+
createUser(): void;
|
|
25
|
+
cancelEditing(): void;
|
|
26
|
+
};
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { useMutation, useQuery } from "@apollo/react-hooks";
|
|
3
|
+
import isEmpty from "lodash/isEmpty.js";
|
|
4
|
+
import { useRoute, useRouter, useWcp } from "@webiny/app-admin";
|
|
5
|
+
import { CREATE_USER, LIST_USERS, READ_USER, UPDATE_USER } from "../graphql.js";
|
|
6
|
+
import omit from "lodash/omit.js";
|
|
7
|
+
import { Routes } from "../../../../routes.js";
|
|
8
|
+
import { useToast } from "@webiny/admin-ui";
|
|
9
|
+
export function useUserForm() {
|
|
10
|
+
const {
|
|
11
|
+
goToRoute
|
|
12
|
+
} = useRouter();
|
|
13
|
+
const {
|
|
14
|
+
route
|
|
15
|
+
} = useRoute(Routes.Users.List);
|
|
16
|
+
const toast = useToast();
|
|
17
|
+
const wcp = useWcp();
|
|
18
|
+
const teams = wcp.canUseTeams();
|
|
19
|
+
const id = route.params.id;
|
|
20
|
+
const newUser = route.params.new === true;
|
|
21
|
+
const {
|
|
22
|
+
data,
|
|
23
|
+
loading: userLoading
|
|
24
|
+
} = useQuery(READ_USER({
|
|
25
|
+
teams
|
|
26
|
+
}), {
|
|
27
|
+
variables: {
|
|
28
|
+
id
|
|
29
|
+
},
|
|
30
|
+
skip: !id,
|
|
31
|
+
onCompleted: data => {
|
|
32
|
+
if (!data) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const {
|
|
36
|
+
error
|
|
37
|
+
} = data.adminUsers.user;
|
|
38
|
+
if (error) {
|
|
39
|
+
goToRoute(Routes.Users.List);
|
|
40
|
+
toast.showWarningToast({
|
|
41
|
+
title: "Error loading user profile",
|
|
42
|
+
description: error.message,
|
|
43
|
+
duration: Infinity
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
const [create, {
|
|
49
|
+
loading: createLoading
|
|
50
|
+
}] = useMutation(CREATE_USER, {
|
|
51
|
+
refetchQueries: [{
|
|
52
|
+
query: LIST_USERS
|
|
53
|
+
}]
|
|
54
|
+
});
|
|
55
|
+
const [update, {
|
|
56
|
+
loading: updateLoading
|
|
57
|
+
}] = useMutation(UPDATE_USER({
|
|
58
|
+
teams
|
|
59
|
+
}), {
|
|
60
|
+
refetchQueries: [{
|
|
61
|
+
query: LIST_USERS
|
|
62
|
+
}]
|
|
63
|
+
});
|
|
64
|
+
const loading = userLoading || createLoading || updateLoading;
|
|
65
|
+
const onSubmit = useCallback(async data => {
|
|
66
|
+
const {
|
|
67
|
+
id,
|
|
68
|
+
...rest
|
|
69
|
+
} = data;
|
|
70
|
+
const [operation, args] = !newUser ? [update, {
|
|
71
|
+
variables: {
|
|
72
|
+
id,
|
|
73
|
+
data: omit(rest, ["external"])
|
|
74
|
+
}
|
|
75
|
+
}] : [create, {
|
|
76
|
+
variables: {
|
|
77
|
+
data
|
|
78
|
+
}
|
|
79
|
+
}];
|
|
80
|
+
const result = await operation(args);
|
|
81
|
+
const {
|
|
82
|
+
data: user,
|
|
83
|
+
error
|
|
84
|
+
} = result.data.adminUsers.user;
|
|
85
|
+
if (error) {
|
|
86
|
+
toast.showWarningToast({
|
|
87
|
+
title: "Error updating user profile",
|
|
88
|
+
description: error.message,
|
|
89
|
+
duration: Infinity
|
|
90
|
+
});
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (newUser) {
|
|
94
|
+
goToRoute(Routes.Users.List, {
|
|
95
|
+
id: user.id
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
toast.showSuccessToast({
|
|
99
|
+
title: "User saved successfully."
|
|
100
|
+
});
|
|
101
|
+
}, [id, newUser]);
|
|
102
|
+
const user = userLoading ? {} : data ? data.adminUsers.user.data : {};
|
|
103
|
+
const showEmptyView = !newUser && !userLoading && isEmpty(user);
|
|
104
|
+
return {
|
|
105
|
+
id,
|
|
106
|
+
loading,
|
|
107
|
+
user: {
|
|
108
|
+
...user,
|
|
109
|
+
group: user.group ? user.group.id : undefined,
|
|
110
|
+
team: user.team ? user.team.id : undefined
|
|
111
|
+
},
|
|
112
|
+
onSubmit,
|
|
113
|
+
isNewUser: newUser,
|
|
114
|
+
fullName: `${user.firstName || ""} ${user.lastName || ""}`.trim(),
|
|
115
|
+
showEmptyView,
|
|
116
|
+
createUser() {
|
|
117
|
+
goToRoute(Routes.Users.List, {
|
|
118
|
+
new: true
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
cancelEditing() {
|
|
122
|
+
goToRoute(Routes.Users.List);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
//# sourceMappingURL=useUserForm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useCallback","useMutation","useQuery","isEmpty","useRoute","useRouter","useWcp","CREATE_USER","LIST_USERS","READ_USER","UPDATE_USER","omit","Routes","useToast","useUserForm","goToRoute","route","Users","List","toast","wcp","teams","canUseTeams","id","params","newUser","new","data","loading","userLoading","variables","skip","onCompleted","error","adminUsers","user","showWarningToast","title","description","message","duration","Infinity","create","createLoading","refetchQueries","query","update","updateLoading","onSubmit","rest","operation","args","result","showSuccessToast","showEmptyView","group","undefined","team","isNewUser","fullName","firstName","lastName","trim","createUser","cancelEditing"],"sources":["useUserForm.ts"],"sourcesContent":["import { useCallback } from \"react\";\nimport { useMutation, useQuery } from \"@apollo/react-hooks\";\nimport isEmpty from \"lodash/isEmpty.js\";\nimport { useRoute, useRouter, useWcp } from \"@webiny/app-admin\";\nimport { CREATE_USER, LIST_USERS, READ_USER, UPDATE_USER } from \"~/admin/ui/views/Users/graphql.js\";\nimport omit from \"lodash/omit.js\";\nimport { Routes } from \"~/admin/routes.js\";\nimport { useToast } from \"@webiny/admin-ui\";\n\nexport type UseUserForm = ReturnType<typeof useUserForm>;\n\ninterface SubmitUserCallableParams {\n id?: string;\n firstName: string;\n lastName: string;\n email: string;\n password?: string;\n avatar: {\n src?: string;\n };\n external?: boolean;\n}\n\ninterface SubmitUserCallable {\n (data: SubmitUserCallableParams): Promise<void>;\n}\n\nexport function useUserForm() {\n const { goToRoute } = useRouter();\n const { route } = useRoute(Routes.Users.List);\n const toast = useToast();\n\n const wcp = useWcp();\n const teams = wcp.canUseTeams();\n\n const id = route.params.id;\n const newUser = route.params.new === true;\n\n const { data, loading: userLoading } = useQuery(READ_USER({ teams }), {\n variables: { id },\n skip: !id,\n onCompleted: data => {\n if (!data) {\n return;\n }\n\n const { error } = data.adminUsers.user;\n if (error) {\n goToRoute(Routes.Users.List);\n toast.showWarningToast({\n title: \"Error loading user profile\",\n description: error.message,\n duration: Infinity\n });\n }\n }\n });\n\n const [create, { loading: createLoading }] = useMutation(CREATE_USER, {\n refetchQueries: [{ query: LIST_USERS }]\n });\n\n const [update, { loading: updateLoading }] = useMutation(UPDATE_USER({ teams }), {\n refetchQueries: [{ query: LIST_USERS }]\n });\n\n const loading = userLoading || createLoading || updateLoading;\n\n const onSubmit = useCallback<SubmitUserCallable>(\n async data => {\n const { id, ...rest } = data;\n const [operation, args] = !newUser\n ? [update, { variables: { id, data: omit(rest, [\"external\"]) } }]\n : [create, { variables: { data } }];\n\n const result = await operation(args);\n\n const { data: user, error } = result.data.adminUsers.user;\n\n if (error) {\n toast.showWarningToast({\n title: \"Error updating user profile\",\n description: error.message,\n duration: Infinity\n });\n return;\n }\n\n if (newUser) {\n goToRoute(Routes.Users.List, { id: user.id });\n }\n toast.showSuccessToast({\n title: \"User saved successfully.\"\n });\n },\n [id, newUser]\n );\n\n const user = userLoading ? {} : data ? data.adminUsers.user.data : {};\n\n const showEmptyView = !newUser && !userLoading && isEmpty(user);\n\n return {\n id,\n loading,\n user: {\n ...user,\n group: user.group ? user.group.id : undefined,\n team: user.team ? user.team.id : undefined\n },\n onSubmit,\n isNewUser: newUser,\n fullName: `${user.firstName || \"\"} ${user.lastName || \"\"}`.trim(),\n showEmptyView,\n createUser() {\n goToRoute(Routes.Users.List, { new: true });\n },\n cancelEditing() {\n goToRoute(Routes.Users.List);\n }\n };\n}\n"],"mappings":"AAAA,SAASA,WAAW,QAAQ,OAAO;AACnC,SAASC,WAAW,EAAEC,QAAQ,QAAQ,qBAAqB;AAC3D,OAAOC,OAAO,MAAM,mBAAmB;AACvC,SAASC,QAAQ,EAAEC,SAAS,EAAEC,MAAM,QAAQ,mBAAmB;AAC/D,SAASC,WAAW,EAAEC,UAAU,EAAEC,SAAS,EAAEC,WAAW;AACxD,OAAOC,IAAI,MAAM,gBAAgB;AACjC,SAASC,MAAM;AACf,SAASC,QAAQ,QAAQ,kBAAkB;AAoB3C,OAAO,SAASC,WAAWA,CAAA,EAAG;EAC1B,MAAM;IAAEC;EAAU,CAAC,GAAGV,SAAS,CAAC,CAAC;EACjC,MAAM;IAAEW;EAAM,CAAC,GAAGZ,QAAQ,CAACQ,MAAM,CAACK,KAAK,CAACC,IAAI,CAAC;EAC7C,MAAMC,KAAK,GAAGN,QAAQ,CAAC,CAAC;EAExB,MAAMO,GAAG,GAAGd,MAAM,CAAC,CAAC;EACpB,MAAMe,KAAK,GAAGD,GAAG,CAACE,WAAW,CAAC,CAAC;EAE/B,MAAMC,EAAE,GAAGP,KAAK,CAACQ,MAAM,CAACD,EAAE;EAC1B,MAAME,OAAO,GAAGT,KAAK,CAACQ,MAAM,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ChC,EAAE,GAAGiC,SAAS;MAC7CC,IAAI,EAAEtB,IAAI,CAACsB,IAAI,GAAGtB,IAAI,CAACsB,IAAI,CAAClC,EAAE,GAAGiC;IACrC,CAAC;IACDR,QAAQ;IACRU,SAAS,EAAEjC,OAAO;IAClBkC,QAAQ,EAAE,GAAGxB,IAAI,CAACyB,SAAS,IAAI,EAAE,IAAIzB,IAAI,CAAC0B,QAAQ,IAAI,EAAE,EAAE,CAACC,IAAI,CAAC,CAAC;IACjER,aAAa;IACbS,UAAUA,CAAA,EAAG;MACThD,SAAS,CAACH,MAAM,CAACK,KAAK,CAACC,IAAI,EAAE;QAAEQ,GAAG,EAAE;MAAK,CAAC,CAAC;IAC/C,CAAC;IACDsC,aAAaA,CAAA,EAAG;MACZjD,SAAS,CAACH,MAAM,CAACK,KAAK,CAACC,IAAI,CAAC;IAChC;EACJ,CAAC;AACL","ignoreList":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<!-- Generator: Adobe Illustrator 19.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
|
3
|
+
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="24px"
|
|
4
|
+
height="24px" viewBox="0 0 24 24" enable-background="new 0 0 24 24" xml:space="preserve">
|
|
5
|
+
<g id="Header_x2F_BG" display="none">
|
|
6
|
+
<rect x="-358" y="-314" display="inline" fill="#F1F1F2" width="520" height="520"/>
|
|
7
|
+
</g>
|
|
8
|
+
<g id="Bounding_Boxes">
|
|
9
|
+
<g id="ui_x5F_spec_x5F_header_copy_3" display="none">
|
|
10
|
+
</g>
|
|
11
|
+
<path fill="none" d="M0,0h24v24H0V0z"/>
|
|
12
|
+
</g>
|
|
13
|
+
<g id="Rounded">
|
|
14
|
+
<g id="ui_x5F_spec_x5F_header_copy_5" display="none">
|
|
15
|
+
</g>
|
|
16
|
+
<path fill="currentColor" d="M15.5,14h-0.79l-0.28-0.27c1.2-1.4,1.82-3.31,1.48-5.34c-0.47-2.78-2.79-5-5.59-5.34c-4.23-0.52-7.79,3.04-7.27,7.27
|
|
17
|
+
c0.34,2.8,2.56,5.12,5.34,5.59c2.03,0.34,3.94-0.28,5.34-1.48L14,14.71v0.79l4.25,4.25c0.41,0.41,1.08,0.41,1.49,0l0,0
|
|
18
|
+
c0.41-0.41,0.41-1.08,0-1.49L15.5,14z M9.5,14C7.01,14,5,11.99,5,9.5S7.01,5,9.5,5S14,7.01,14,9.5S11.99,14,9.5,14z"/>
|
|
19
|
+
</g>
|
|
20
|
+
</svg>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const deserializeSorters = data => {
|
|
2
|
+
if (typeof data !== "string") {
|
|
3
|
+
return data;
|
|
4
|
+
}
|
|
5
|
+
const [field, orderBy] = data.split("_");
|
|
6
|
+
const order = String(orderBy).toLowerCase() === "asc" ? "asc" : "desc";
|
|
7
|
+
return [field, order];
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["deserializeSorters","data","field","orderBy","split","order","String","toLowerCase"],"sources":["utils.ts"],"sourcesContent":["type SortTypes = \"asc\" | \"desc\";\nexport const deserializeSorters = (data: string): [string, SortTypes] => {\n if (typeof data !== \"string\") {\n return data;\n }\n const [field, orderBy] = data.split(\"_\") as [string, SortTypes];\n const order = String(orderBy).toLowerCase() === \"asc\" ? \"asc\" : \"desc\";\n return [field, order];\n};\n"],"mappings":"AACA,OAAO,MAAMA,kBAAkB,GAAIC,IAAY,IAA0B;EACrE,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;IAC1B,OAAOA,IAAI;EACf;EACA,MAAM,CAACC,KAAK,EAAEC,OAAO,CAAC,GAAGF,IAAI,CAACG,KAAK,CAAC,GAAG,CAAwB;EAC/D,MAAMC,KAAK,GAAGC,MAAM,CAACH,OAAO,CAAC,CAACI,WAAW,CAAC,CAAC,KAAK,KAAK,GAAG,KAAK,GAAG,MAAM;EACtE,OAAO,CAACL,KAAK,EAAEG,KAAK,CAAC;AACzB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const CognitoApiFeature: import("@webiny/feature/api/createFeature.js").FeatureDefinition<unknown>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { AdminUsersSchema } from "./graphql/user.gql.js";
|
|
3
|
+
import { UserInstallerFeature } from "./features/UserInstaller/feature.js";
|
|
4
|
+
import { CognitoIdpFeature } from "./features/CognitoIdp/index.js";
|
|
5
|
+
import { CreateUserFeature } from "./features/CreateUser/index.js";
|
|
6
|
+
import { UpdateUserFeature } from "./features/UpdateUser/index.js";
|
|
7
|
+
import { DeleteUserFeature } from "./features/DeleteUser/index.js";
|
|
8
|
+
import { CognitoServiceFeature } from "./features/CognitoService/feature.js";
|
|
9
|
+
export const CognitoApiFeature = createFeature({
|
|
10
|
+
name: "CognitoApiFeature",
|
|
11
|
+
register(container) {
|
|
12
|
+
// Register features
|
|
13
|
+
CreateUserFeature.register(container);
|
|
14
|
+
UpdateUserFeature.register(container);
|
|
15
|
+
DeleteUserFeature.register(container);
|
|
16
|
+
UserInstallerFeature.register(container);
|
|
17
|
+
CognitoIdpFeature.register(container);
|
|
18
|
+
CognitoServiceFeature.register(container, {
|
|
19
|
+
region: String(process.env.COGNITO_REGION),
|
|
20
|
+
userPoolId: String(process.env.COGNITO_USER_POOL_ID)
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// Register GraphQL schema
|
|
24
|
+
container.register(AdminUsersSchema);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=CognitoApiFeature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createFeature","AdminUsersSchema","UserInstallerFeature","CognitoIdpFeature","CreateUserFeature","UpdateUserFeature","DeleteUserFeature","CognitoServiceFeature","CognitoApiFeature","name","register","container","region","String","process","env","COGNITO_REGION","userPoolId","COGNITO_USER_POOL_ID"],"sources":["CognitoApiFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { AdminUsersSchema } from \"~/api/graphql/user.gql.js\";\nimport { UserInstallerFeature } from \"./features/UserInstaller/feature.js\";\nimport { CognitoIdpFeature } from \"./features/CognitoIdp/index.js\";\nimport { CreateUserFeature } from \"./features/CreateUser/index.js\";\nimport { UpdateUserFeature } from \"./features/UpdateUser/index.js\";\nimport { DeleteUserFeature } from \"./features/DeleteUser/index.js\";\nimport { CognitoServiceFeature } from \"~/api/features/CognitoService/feature.js\";\n\nexport const CognitoApiFeature = createFeature({\n name: \"CognitoApiFeature\",\n register(container) {\n // Register features\n CreateUserFeature.register(container);\n UpdateUserFeature.register(container);\n DeleteUserFeature.register(container);\n UserInstallerFeature.register(container);\n CognitoIdpFeature.register(container);\n CognitoServiceFeature.register(container, {\n region: String(process.env.COGNITO_REGION),\n userPoolId: String(process.env.COGNITO_USER_POOL_ID)\n });\n\n // Register GraphQL schema\n container.register(AdminUsersSchema);\n }\n});\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,qBAAqB;AACnD,SAASC,gBAAgB;AACzB,SAASC,oBAAoB;AAC7B,SAASC,iBAAiB;AAC1B,SAASC,iBAAiB;AAC1B,SAASC,iBAAiB;AAC1B,SAASC,iBAAiB;AAC1B,SAASC,qBAAqB;AAE9B,OAAO,MAAMC,iBAAiB,GAAGR,aAAa,CAAC;EAC3CS,IAAI,EAAE,mBAAmB;EACzBC,QAAQA,CAACC,SAAS,EAAE;IAChB;IACAP,iBAAiB,CAACM,QAAQ,CAACC,SAAS,CAAC;IACrCN,iBAAiB,CAACK,QAAQ,CAACC,SAAS,CAAC;IACrCL,iBAAiB,CAACI,QAAQ,CAACC,SAAS,CAAC;IACrCT,oBAAoB,CAACQ,QAAQ,CAACC,SAAS,CAAC;IACxCR,iBAAiB,CAACO,QAAQ,CAACC,SAAS,CAAC;IACrCJ,qBAAqB,CAACG,QAAQ,CAACC,SAAS,EAAE;MACtCC,MAAM,EAAEC,MAAM,CAACC,OAAO,CAACC,GAAG,CAACC,cAAc,CAAC;MAC1CC,UAAU,EAAEJ,MAAM,CAACC,OAAO,CAACC,GAAG,CAACG,oBAAoB;IACvD,CAAC,CAAC;;IAEF;IACAP,SAAS,CAACD,QAAQ,CAACT,gBAAgB,CAAC;EACxC;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Username","fromUser","user","email","toLowerCase"],"sources":["Username.ts"],"sourcesContent":["import type { AdminUser, CreateUserInput } from \"@webiny/api-core/features/users/shared/types.js\";\n\nexport class Username {\n static fromUser(user: AdminUser | CreateUserInput) {\n return user.email.toLowerCase();\n }\n}\n"],"mappings":"AAEA,OAAO,MAAMA,QAAQ,CAAC;EAClB,OAAOC,QAAQA,CAACC,IAAiC,EAAE;IAC/C,OAAOA,IAAI,CAACC,KAAK,CAACC,WAAW,CAAC,CAAC;EACnC;AACJ","ignoreList":[]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { BaseError } from "@webiny/feature/api";
|
|
2
|
+
/**
|
|
3
|
+
* Error when a user already exists in Cognito User Pool
|
|
4
|
+
*/
|
|
5
|
+
export declare class CognitoAccountExistsError extends BaseError<{
|
|
6
|
+
email: string;
|
|
7
|
+
}> {
|
|
8
|
+
readonly code: "Cognito/Account/Exists";
|
|
9
|
+
constructor(email: string);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Error when creating a user in Cognito fails
|
|
13
|
+
*/
|
|
14
|
+
export declare class CognitoCreateUserError extends BaseError<{
|
|
15
|
+
error: Error;
|
|
16
|
+
}> {
|
|
17
|
+
readonly code: "Cognito/User/Create";
|
|
18
|
+
constructor(error: Error);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Error when updating a user in Cognito fails
|
|
22
|
+
*/
|
|
23
|
+
export declare class CognitoUpdateUserError extends BaseError<{
|
|
24
|
+
error: Error;
|
|
25
|
+
}> {
|
|
26
|
+
readonly code: "Cognito/User/Update";
|
|
27
|
+
constructor(error: Error);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Error when deleting a user from Cognito fails
|
|
31
|
+
*/
|
|
32
|
+
export declare class CognitoDeleteUserError extends BaseError<{
|
|
33
|
+
error: Error;
|
|
34
|
+
}> {
|
|
35
|
+
readonly code: "Cognito/User/Delete";
|
|
36
|
+
constructor(error: Error);
|
|
37
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { BaseError } from "@webiny/feature/api";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Error when a user already exists in Cognito User Pool
|
|
5
|
+
*/
|
|
6
|
+
export class CognitoAccountExistsError extends BaseError {
|
|
7
|
+
code = "Cognito/Account/Exists";
|
|
8
|
+
constructor(email) {
|
|
9
|
+
super({
|
|
10
|
+
message: `An account with this email already exists in your Cognito User Pool.`,
|
|
11
|
+
data: {
|
|
12
|
+
email
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Error when creating a user in Cognito fails
|
|
20
|
+
*/
|
|
21
|
+
export class CognitoCreateUserError extends BaseError {
|
|
22
|
+
code = "Cognito/User/Create";
|
|
23
|
+
constructor(error) {
|
|
24
|
+
super({
|
|
25
|
+
message: `Failed to create user in Cognito: ${error.message}`,
|
|
26
|
+
data: {
|
|
27
|
+
error
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Error when updating a user in Cognito fails
|
|
35
|
+
*/
|
|
36
|
+
export class CognitoUpdateUserError extends BaseError {
|
|
37
|
+
code = "Cognito/User/Update";
|
|
38
|
+
constructor(error) {
|
|
39
|
+
super({
|
|
40
|
+
message: `Failed to update user in Cognito: ${error.message}`,
|
|
41
|
+
data: {
|
|
42
|
+
error
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Error when deleting a user from Cognito fails
|
|
50
|
+
*/
|
|
51
|
+
export class CognitoDeleteUserError extends BaseError {
|
|
52
|
+
code = "Cognito/User/Delete";
|
|
53
|
+
constructor(error) {
|
|
54
|
+
super({
|
|
55
|
+
message: `Failed to delete user from Cognito: ${error.message}`,
|
|
56
|
+
data: {
|
|
57
|
+
error
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["BaseError","CognitoAccountExistsError","code","constructor","email","message","data","CognitoCreateUserError","error","CognitoUpdateUserError","CognitoDeleteUserError"],"sources":["errors.ts"],"sourcesContent":["import { BaseError } from \"@webiny/feature/api\";\n\n/**\n * Error when a user already exists in Cognito User Pool\n */\nexport class CognitoAccountExistsError extends BaseError<{ email: string }> {\n override readonly code = \"Cognito/Account/Exists\" as const;\n\n constructor(email: string) {\n super({\n message: `An account with this email already exists in your Cognito User Pool.`,\n data: { email }\n });\n }\n}\n\n/**\n * Error when creating a user in Cognito fails\n */\nexport class CognitoCreateUserError extends BaseError<{ error: Error }> {\n override readonly code = \"Cognito/User/Create\" as const;\n\n constructor(error: Error) {\n super({\n message: `Failed to create user in Cognito: ${error.message}`,\n data: { error }\n });\n }\n}\n\n/**\n * Error when updating a user in Cognito fails\n */\nexport class CognitoUpdateUserError extends BaseError<{ error: Error }> {\n override readonly code = \"Cognito/User/Update\" as const;\n\n constructor(error: Error) {\n super({\n message: `Failed to update user in Cognito: ${error.message}`,\n data: { error }\n });\n }\n}\n\n/**\n * Error when deleting a user from Cognito fails\n */\nexport class CognitoDeleteUserError extends BaseError<{ error: Error }> {\n override readonly code = \"Cognito/User/Delete\" as const;\n\n constructor(error: Error) {\n super({\n message: `Failed to delete user from Cognito: ${error.message}`,\n data: { error }\n });\n }\n}\n"],"mappings":"AAAA,SAASA,SAAS,QAAQ,qBAAqB;;AAE/C;AACA;AACA;AACA,OAAO,MAAMC,yBAAyB,SAASD,SAAS,CAAoB;EACtDE,IAAI,GAAG,wBAAwB;EAEjDC,WAAWA,CAACC,KAAa,EAAE;IACvB,KAAK,CAAC;MACFC,OAAO,EAAE,sEAAsE;MAC/EC,IAAI,EAAE;QAAEF;MAAM;IAClB,CAAC,CAAC;EACN;AACJ;;AAEA;AACA;AACA;AACA,OAAO,MAAMG,sBAAsB,SAASP,SAAS,CAAmB;EAClDE,IAAI,GAAG,qBAAqB;EAE9CC,WAAWA,CAACK,KAAY,EAAE;IACtB,KAAK,CAAC;MACFH,OAAO,EAAE,qCAAqCG,KAAK,CAACH,OAAO,EAAE;MAC7DC,IAAI,EAAE;QAAEE;MAAM;IAClB,CAAC,CAAC;EACN;AACJ;;AAEA;AACA;AACA;AACA,OAAO,MAAMC,sBAAsB,SAAST,SAAS,CAAmB;EAClDE,IAAI,GAAG,qBAAqB;EAE9CC,WAAWA,CAACK,KAAY,EAAE;IACtB,KAAK,CAAC;MACFH,OAAO,EAAE,qCAAqCG,KAAK,CAACH,OAAO,EAAE;MAC7DC,IAAI,EAAE;QAAEE;MAAM;IAClB,CAAC,CAAC;EACN;AACJ;;AAEA;AACA;AACA;AACA,OAAO,MAAME,sBAAsB,SAASV,SAAS,CAAmB;EAClDE,IAAI,GAAG,qBAAqB;EAE9CC,WAAWA,CAACK,KAAY,EAAE;IACtB,KAAK,CAAC;MACFH,OAAO,EAAE,uCAAuCG,KAAK,CAACH,OAAO,EAAE;MAC/DC,IAAI,EAAE;QAAEE;MAAM;IAClB,CAAC,CAAC;EACN;AACJ","ignoreList":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { OidcIdentityProvider } from "@webiny/api-core/idp";
|
|
2
|
+
import { CognitoIdpConfig } from "./abstractions.js";
|
|
3
|
+
declare class CognitoIdentityProviderImpl implements OidcIdentityProvider.Interface {
|
|
4
|
+
private config;
|
|
5
|
+
clientId: string;
|
|
6
|
+
issuer: string;
|
|
7
|
+
constructor(config: CognitoIdpConfig.Interface | undefined);
|
|
8
|
+
isApplicable(token: OidcIdentityProvider.JwtPayload): boolean;
|
|
9
|
+
getIdentity(token: OidcIdentityProvider.JwtPayload): Promise<OidcIdentityProvider.IdentityData>;
|
|
10
|
+
verifyTokenClaims(token: OidcIdentityProvider.JwtPayload): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
export declare const CognitoIdentityProvider: typeof CognitoIdentityProviderImpl & {
|
|
13
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/idp/abstractions.js").IOidcIdentityProvider>;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { OidcIdentityProvider } from "@webiny/api-core/idp";
|
|
2
|
+
import { CognitoIdpConfig } from "./abstractions.js";
|
|
3
|
+
class CognitoIdentityProviderImpl {
|
|
4
|
+
constructor(config) {
|
|
5
|
+
this.config = config;
|
|
6
|
+
const region = String(process.env.COGNITO_REGION);
|
|
7
|
+
const userPoolId = String(process.env.COGNITO_USER_POOL_ID);
|
|
8
|
+
this.clientId = String(process.env.COGNITO_CLIENT_ID);
|
|
9
|
+
this.issuer = `https://cognito-idp.${region}.amazonaws.com/${userPoolId}`;
|
|
10
|
+
}
|
|
11
|
+
isApplicable(token) {
|
|
12
|
+
const issuer = token.iss;
|
|
13
|
+
if (!issuer) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
return issuer === this.issuer;
|
|
17
|
+
}
|
|
18
|
+
async getIdentity(token) {
|
|
19
|
+
const customIdentity = this.config ? await this.config.getIdentity(token) : null;
|
|
20
|
+
if (customIdentity) {
|
|
21
|
+
return {
|
|
22
|
+
...customIdentity,
|
|
23
|
+
type: "admin",
|
|
24
|
+
profile: {
|
|
25
|
+
...customIdentity,
|
|
26
|
+
external: false
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Default identity
|
|
32
|
+
const customId = token["custom:id"];
|
|
33
|
+
const givenName = token["given_name"];
|
|
34
|
+
const familyName = token["family_name"];
|
|
35
|
+
const email = token["email"];
|
|
36
|
+
return {
|
|
37
|
+
id: customId || token.sub || "",
|
|
38
|
+
displayName: `${givenName || ""} ${familyName || ""}`.trim() || email || "Unknown User",
|
|
39
|
+
type: "admin",
|
|
40
|
+
profile: {
|
|
41
|
+
email: email || "",
|
|
42
|
+
firstName: givenName || "",
|
|
43
|
+
lastName: familyName || "",
|
|
44
|
+
external: false
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
async verifyTokenClaims(token) {
|
|
49
|
+
if (this.config?.verifyTokenClaims) {
|
|
50
|
+
await this.config.verifyTokenClaims(token);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export const CognitoIdentityProvider = OidcIdentityProvider.createImplementation({
|
|
55
|
+
implementation: CognitoIdentityProviderImpl,
|
|
56
|
+
dependencies: [[CognitoIdpConfig, {
|
|
57
|
+
optional: true
|
|
58
|
+
}]]
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=CognitoIdentityProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["OidcIdentityProvider","CognitoIdpConfig","CognitoIdentityProviderImpl","constructor","config","region","String","process","env","COGNITO_REGION","userPoolId","COGNITO_USER_POOL_ID","clientId","COGNITO_CLIENT_ID","issuer","isApplicable","token","iss","getIdentity","customIdentity","type","profile","external","customId","givenName","familyName","email","id","sub","displayName","trim","firstName","lastName","verifyTokenClaims","CognitoIdentityProvider","createImplementation","implementation","dependencies","optional"],"sources":["CognitoIdentityProvider.ts"],"sourcesContent":["import { OidcIdentityProvider } from \"@webiny/api-core/idp\";\nimport { CognitoIdpConfig } from \"./abstractions.js\";\n\nclass CognitoIdentityProviderImpl implements OidcIdentityProvider.Interface {\n public clientId: string;\n public issuer: string;\n\n constructor(private config: CognitoIdpConfig.Interface | undefined) {\n const region = String(process.env.COGNITO_REGION);\n const userPoolId = String(process.env.COGNITO_USER_POOL_ID);\n this.clientId = String(process.env.COGNITO_CLIENT_ID);\n this.issuer = `https://cognito-idp.${region}.amazonaws.com/${userPoolId}`;\n }\n\n isApplicable(token: OidcIdentityProvider.JwtPayload) {\n const issuer = token.iss as string;\n if (!issuer) {\n return false;\n }\n\n return issuer === this.issuer;\n }\n\n async getIdentity(\n token: OidcIdentityProvider.JwtPayload\n ): Promise<OidcIdentityProvider.IdentityData> {\n const customIdentity = this.config ? await this.config.getIdentity(token) : null;\n\n if (customIdentity) {\n return {\n ...customIdentity,\n type: \"admin\",\n profile: {\n ...customIdentity,\n external: false\n }\n };\n }\n\n // Default identity\n const customId = token[\"custom:id\"] as string | undefined;\n const givenName = token[\"given_name\"] as string | undefined;\n const familyName = token[\"family_name\"] as string | undefined;\n const email = token[\"email\"] as string | undefined;\n\n return {\n id: customId || token.sub || \"\",\n displayName: `${givenName || \"\"} ${familyName || \"\"}`.trim() || email || \"Unknown User\",\n type: \"admin\",\n profile: {\n email: email || \"\",\n firstName: givenName || \"\",\n lastName: familyName || \"\",\n external: false\n }\n };\n }\n\n async verifyTokenClaims(token: OidcIdentityProvider.JwtPayload): Promise<void> {\n if (this.config?.verifyTokenClaims) {\n await this.config.verifyTokenClaims(token);\n }\n }\n}\n\nexport const CognitoIdentityProvider = OidcIdentityProvider.createImplementation({\n implementation: CognitoIdentityProviderImpl,\n dependencies: [[CognitoIdpConfig, { optional: true }]]\n});\n"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ,sBAAsB;AAC3D,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W,EAAE,GAAGL,SAAS,IAAI,EAAE,IAAIC,UAAU,IAAI,EAAE,EAAE,CAACK,IAAI,CAAC,CAAC,IAAIJ,KAAK,IAAI,cAAc;MACvFN,IAAI,EAAE,OAAO;MACbC,OAAO,EAAE;QACLK,KAAK,EAAEA,KAAK,IAAI,EAAE;QAClBK,SAAS,EAAEP,SAAS,IAAI,EAAE;QAC1BQ,QAAQ,EAAEP,UAAU,IAAI,EAAE;QAC1BH,QAAQ,EAAE;MACd;IACJ,CAAC;EACL;EAEA,MAAMW,iBAAiBA,CAACjB,KAAsC,EAAiB;IAC3E,IAAI,IAAI,CAACZ,MAAM,EAAE6B,iBAAiB,EAAE;MAChC,MAAM,IAAI,CAAC7B,MAAM,CAAC6B,iBAAiB,CAACjB,KAAK,CAAC;IAC9C;EACJ;AACJ;AAEA,OAAO,MAAMkB,uBAAuB,GAAGlC,oBAAoB,CAACmC,oBAAoB,CAAC;EAC7EC,cAAc,EAAElC,2BAA2B;EAC3CmC,YAAY,EAAE,CAAC,CAACpC,gBAAgB,EAAE;IAAEqC,QAAQ,EAAE;EAAK,CAAC,CAAC;AACzD,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type jwt from "jsonwebtoken";
|
|
2
|
+
import type { IdentityData } from "@webiny/api-core/idp";
|
|
3
|
+
export type CognitoIdentity = Omit<IdentityData, "type"> & {
|
|
4
|
+
profile: Omit<IdentityData["profile"], "external">;
|
|
5
|
+
};
|
|
6
|
+
export interface ICognitoIdpConfig {
|
|
7
|
+
getIdentity(token: jwt.JwtPayload): Promise<CognitoIdentity> | CognitoIdentity;
|
|
8
|
+
verifyTokenClaims?(token: jwt.JwtPayload): Promise<void> | void;
|
|
9
|
+
}
|
|
10
|
+
export declare const CognitoIdpConfig: import("@webiny/di").Abstraction<ICognitoIdpConfig>;
|
|
11
|
+
export declare namespace CognitoIdpConfig {
|
|
12
|
+
type Interface = ICognitoIdpConfig;
|
|
13
|
+
type IdentityData = CognitoIdentity;
|
|
14
|
+
type JwtPayload = jwt.JwtPayload;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createAbstraction","CognitoIdpConfig"],"sources":["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"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,qBAAqB;AAavD,OAAO,MAAMC,gBAAgB,GAAGD,iBAAiB,CAAoB,kBAAkB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const CognitoIdpFeature: import("@webiny/feature/api/createFeature.js").FeatureDefinition<unknown>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { CognitoIdentityProvider } from "./CognitoIdentityProvider.js";
|
|
3
|
+
export const CognitoIdpFeature = createFeature({
|
|
4
|
+
name: "CognitoIdp",
|
|
5
|
+
register(container) {
|
|
6
|
+
container.register(CognitoIdentityProvider).inSingletonScope();
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createFeature","CognitoIdentityProvider","CognitoIdpFeature","name","register","container","inSingletonScope"],"sources":["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 container.register(CognitoIdentityProvider).inSingletonScope();\n }\n});\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,qBAAqB;AACnD,SAASC,uBAAuB;AAEhC,OAAO,MAAMC,iBAAiB,GAAGF,aAAa,CAAC;EAC3CG,IAAI,EAAE,YAAY;EAClBC,QAAQA,CAACC,SAAS,EAAE;IAChBA,SAAS,CAACD,QAAQ,CAACH,uBAAuB,CAAC,CAACK,gBAAgB,CAAC,CAAC;EAClE;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["CognitoIdpConfig","CognitoIdpFeature"],"sources":["index.ts"],"sourcesContent":["export { CognitoIdpConfig } from \"./abstractions.js\";\nexport { CognitoIdpFeature } from \"./feature.js\";\n"],"mappings":"AAAA,SAASA,gBAAgB;AACzB,SAASC,iBAAiB","ignoreList":[]}
|
|
@@ -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,90 @@
|
|
|
1
|
+
import { CognitoIdentityProvider } from "@webiny/aws-sdk/client-cognito-identity-provider/index.js";
|
|
2
|
+
import { CognitoConfig, CognitoService as ServiceAbstraction } 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
|
+
// User does not exist
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
async createUser(params) {
|
|
23
|
+
const createUserParams = {
|
|
24
|
+
UserPoolId: this.config.userPoolId,
|
|
25
|
+
Username: params.username,
|
|
26
|
+
DesiredDeliveryMediums: [],
|
|
27
|
+
ForceAliasCreation: false,
|
|
28
|
+
MessageAction: "SUPPRESS",
|
|
29
|
+
TemporaryPassword: params.temporaryPassword,
|
|
30
|
+
UserAttributes: [{
|
|
31
|
+
Name: "given_name",
|
|
32
|
+
Value: params.attributes.givenName || ""
|
|
33
|
+
}, {
|
|
34
|
+
Name: "family_name",
|
|
35
|
+
Value: params.attributes.familyName || ""
|
|
36
|
+
}, {
|
|
37
|
+
Name: "preferred_username",
|
|
38
|
+
Value: params.attributes.preferredUsername
|
|
39
|
+
}, {
|
|
40
|
+
Name: "email",
|
|
41
|
+
Value: params.attributes.email
|
|
42
|
+
}, {
|
|
43
|
+
Name: "custom:id",
|
|
44
|
+
Value: params.attributes.customId
|
|
45
|
+
}]
|
|
46
|
+
};
|
|
47
|
+
await this.cognito.adminCreateUser(createUserParams);
|
|
48
|
+
}
|
|
49
|
+
async setEmailVerified(username) {
|
|
50
|
+
await this.cognito.adminUpdateUserAttributes({
|
|
51
|
+
UserPoolId: this.config.userPoolId,
|
|
52
|
+
Username: username,
|
|
53
|
+
UserAttributes: [{
|
|
54
|
+
Name: "email_verified",
|
|
55
|
+
Value: "true"
|
|
56
|
+
}]
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
async setPermanentPassword(username, password) {
|
|
60
|
+
await this.cognito.adminSetUserPassword({
|
|
61
|
+
Permanent: true,
|
|
62
|
+
Password: password,
|
|
63
|
+
Username: username,
|
|
64
|
+
UserPoolId: this.config.userPoolId
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
async updateUserAttributes(username, attributes) {
|
|
68
|
+
const userAttributes = Object.entries(attributes).map(([name, value]) => ({
|
|
69
|
+
Name: name,
|
|
70
|
+
Value: value
|
|
71
|
+
}));
|
|
72
|
+
await this.cognito.adminUpdateUserAttributes({
|
|
73
|
+
UserPoolId: this.config.userPoolId,
|
|
74
|
+
Username: username,
|
|
75
|
+
UserAttributes: userAttributes
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
async deleteUser(username) {
|
|
79
|
+
await this.cognito.adminDeleteUser({
|
|
80
|
+
UserPoolId: this.config.userPoolId,
|
|
81
|
+
Username: username
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
export const CognitoService = ServiceAbstraction.createImplementation({
|
|
86
|
+
implementation: CognitoServiceImpl,
|
|
87
|
+
dependencies: [CognitoConfig]
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
//# sourceMappingURL=CognitoService.js.map
|