@scm-manager/ui-api 2.36.1 → 2.36.2-20220522-120507
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/build/index.d.ts +735 -0
- package/build/index.js +3200 -0
- package/build/index.mjs +3031 -0
- package/package.json +15 -10
- package/LICENSE.txt +0 -21
- package/src/ApiProvider.test.tsx +0 -60
- package/src/ApiProvider.tsx +0 -80
- package/src/LegacyContext.test.tsx +0 -52
- package/src/LegacyContext.tsx +0 -75
- package/src/admin.test.ts +0 -55
- package/src/admin.ts +0 -42
- package/src/alerts.ts +0 -107
- package/src/annotations.ts +0 -45
- package/src/apiKeys.ts +0 -82
- package/src/apiclient.test.ts +0 -126
- package/src/apiclient.ts +0 -336
- package/src/base.test.ts +0 -238
- package/src/base.ts +0 -120
- package/src/branches.test.ts +0 -234
- package/src/branches.ts +0 -201
- package/src/changesets.test.ts +0 -178
- package/src/changesets.ts +0 -82
- package/src/compare.ts +0 -90
- package/src/config.test.ts +0 -118
- package/src/config.ts +0 -60
- package/src/configLink.test.ts +0 -169
- package/src/configLink.ts +0 -89
- package/src/contentType.ts +0 -58
- package/src/diff.test.ts +0 -234
- package/src/diff.ts +0 -93
- package/src/errors.test.ts +0 -59
- package/src/errors.ts +0 -133
- package/src/fileContent.ts +0 -33
- package/src/groupSuggestions.ts +0 -32
- package/src/groups.test.ts +0 -241
- package/src/groups.ts +0 -141
- package/src/help/search/modal.de.ts +0 -33
- package/src/help/search/modal.en.ts +0 -33
- package/src/help/search/syntax.de.ts +0 -148
- package/src/help/search/syntax.en.ts +0 -145
- package/src/history.ts +0 -62
- package/src/import.ts +0 -114
- package/src/index.ts +0 -72
- package/src/keys.ts +0 -48
- package/src/links.test.ts +0 -99
- package/src/links.ts +0 -54
- package/src/login.test.ts +0 -240
- package/src/login.ts +0 -128
- package/src/loginInfo.ts +0 -43
- package/src/namespaceSuggestions.ts +0 -32
- package/src/namespaces.test.ts +0 -95
- package/src/namespaces.ts +0 -43
- package/src/notifications.ts +0 -183
- package/src/permissions.test.ts +0 -345
- package/src/permissions.ts +0 -202
- package/src/plugins.test.ts +0 -336
- package/src/plugins.ts +0 -259
- package/src/publicKeys.ts +0 -83
- package/src/repositories.test.ts +0 -508
- package/src/repositories.ts +0 -375
- package/src/repository-roles.test.ts +0 -229
- package/src/repository-roles.ts +0 -142
- package/src/reset.ts +0 -36
- package/src/search.ts +0 -153
- package/src/sources.test.ts +0 -233
- package/src/sources.ts +0 -136
- package/src/suggestions.ts +0 -47
- package/src/tags.test.ts +0 -272
- package/src/tags.ts +0 -118
- package/src/tests/createInfiniteCachingClient.ts +0 -37
- package/src/tests/createWrapper.tsx +0 -37
- package/src/tests/indexLinks.ts +0 -43
- package/src/urls.test.ts +0 -104
- package/src/urls.ts +0 -118
- package/src/usePluginCenterAuthInfo.ts +0 -91
- package/src/userSuggestions.ts +0 -32
- package/src/users.test.ts +0 -310
- package/src/users.ts +0 -240
- package/src/utils.ts +0 -29
package/src/users.ts
DELETED
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* MIT License
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
import { ApiResult, useRequiredIndexLink } from "./base";
|
|
26
|
-
import { useMutation, useQuery, useQueryClient } from "react-query";
|
|
27
|
-
import { Link, Me, User, UserCollection, UserCreation } from "@scm-manager/ui-types";
|
|
28
|
-
import { apiClient } from "./apiclient";
|
|
29
|
-
import { createQueryString } from "./utils";
|
|
30
|
-
import { concat } from "./urls";
|
|
31
|
-
import { requiredLink } from "./links";
|
|
32
|
-
|
|
33
|
-
export type UseUsersRequest = {
|
|
34
|
-
page?: number | string;
|
|
35
|
-
search?: string;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export const useUsers = (request?: UseUsersRequest): ApiResult<UserCollection> => {
|
|
39
|
-
const queryClient = useQueryClient();
|
|
40
|
-
const indexLink = useRequiredIndexLink("users");
|
|
41
|
-
|
|
42
|
-
const queryParams: Record<string, string> = {};
|
|
43
|
-
if (request?.search) {
|
|
44
|
-
queryParams.q = request.search;
|
|
45
|
-
}
|
|
46
|
-
if (request?.page) {
|
|
47
|
-
queryParams.page = request.page.toString();
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return useQuery<UserCollection, Error>(
|
|
51
|
-
["users", request?.search || "", request?.page || 0],
|
|
52
|
-
() => apiClient.get(`${indexLink}?${createQueryString(queryParams)}`).then((response) => response.json()),
|
|
53
|
-
{
|
|
54
|
-
onSuccess: (users: UserCollection) => {
|
|
55
|
-
users._embedded?.users.forEach((user: User) => queryClient.setQueryData(["user", user.name], user));
|
|
56
|
-
},
|
|
57
|
-
}
|
|
58
|
-
);
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
export const useUser = (name: string): ApiResult<User> => {
|
|
62
|
-
const indexLink = useRequiredIndexLink("users");
|
|
63
|
-
return useQuery<User, Error>(["user", name], () =>
|
|
64
|
-
apiClient.get(concat(indexLink, name)).then((response) => response.json())
|
|
65
|
-
);
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const createUser = (link: string) => {
|
|
69
|
-
return (user: UserCreation) => {
|
|
70
|
-
return apiClient
|
|
71
|
-
.post(link, user, "application/vnd.scmm-user+json;v=2")
|
|
72
|
-
.then((response) => {
|
|
73
|
-
const location = response.headers.get("Location");
|
|
74
|
-
if (!location) {
|
|
75
|
-
throw new Error("Server does not return required Location header");
|
|
76
|
-
}
|
|
77
|
-
return apiClient.get(location);
|
|
78
|
-
})
|
|
79
|
-
.then((response) => response.json());
|
|
80
|
-
};
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
export const useCreateUser = () => {
|
|
84
|
-
const queryClient = useQueryClient();
|
|
85
|
-
const link = useRequiredIndexLink("users");
|
|
86
|
-
const { mutate, data, isLoading, error } = useMutation<User, Error, UserCreation>(createUser(link), {
|
|
87
|
-
onSuccess: (user) => {
|
|
88
|
-
queryClient.setQueryData(["user", user.name], user);
|
|
89
|
-
return queryClient.invalidateQueries(["users"]);
|
|
90
|
-
},
|
|
91
|
-
});
|
|
92
|
-
return {
|
|
93
|
-
create: (user: UserCreation) => mutate(user),
|
|
94
|
-
isLoading,
|
|
95
|
-
error,
|
|
96
|
-
user: data,
|
|
97
|
-
};
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
export const useUpdateUser = () => {
|
|
101
|
-
const queryClient = useQueryClient();
|
|
102
|
-
const { mutate, isLoading, error, data } = useMutation<unknown, Error, User>(
|
|
103
|
-
(user) => {
|
|
104
|
-
const updateUrl = (user._links.update as Link).href;
|
|
105
|
-
return apiClient.put(updateUrl, user, "application/vnd.scmm-user+json;v=2");
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
onSuccess: async (_, user) => {
|
|
109
|
-
await queryClient.invalidateQueries(["user", user.name]);
|
|
110
|
-
await queryClient.invalidateQueries(["users"]);
|
|
111
|
-
},
|
|
112
|
-
}
|
|
113
|
-
);
|
|
114
|
-
return {
|
|
115
|
-
update: (user: User) => mutate(user),
|
|
116
|
-
isLoading,
|
|
117
|
-
error,
|
|
118
|
-
isUpdated: !!data,
|
|
119
|
-
};
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
export const useDeleteUser = () => {
|
|
123
|
-
const queryClient = useQueryClient();
|
|
124
|
-
const { mutate, isLoading, error, data } = useMutation<unknown, Error, User>(
|
|
125
|
-
(user) => {
|
|
126
|
-
const deleteUrl = (user._links.delete as Link).href;
|
|
127
|
-
return apiClient.delete(deleteUrl);
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
onSuccess: async (_, name) => {
|
|
131
|
-
await queryClient.removeQueries(["user", name]);
|
|
132
|
-
await queryClient.invalidateQueries(["users"]);
|
|
133
|
-
},
|
|
134
|
-
}
|
|
135
|
-
);
|
|
136
|
-
return {
|
|
137
|
-
remove: (user: User) => mutate(user),
|
|
138
|
-
isLoading,
|
|
139
|
-
error,
|
|
140
|
-
isDeleted: !!data,
|
|
141
|
-
};
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
const convertToInternal = (url: string, newPassword: string) => {
|
|
145
|
-
return apiClient.put(
|
|
146
|
-
url,
|
|
147
|
-
{
|
|
148
|
-
newPassword,
|
|
149
|
-
},
|
|
150
|
-
"application/vnd.scmm-user+json;v=2"
|
|
151
|
-
);
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
const convertToExternal = (url: string) => {
|
|
155
|
-
return apiClient.put(url, {}, "application/vnd.scmm-user+json;v=2");
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
export type ConvertToInternalRequest = {
|
|
159
|
-
user: User;
|
|
160
|
-
password: string;
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
export const useConvertToInternal = () => {
|
|
164
|
-
const queryClient = useQueryClient();
|
|
165
|
-
const { mutate, isLoading, error, data } = useMutation<unknown, Error, ConvertToInternalRequest>(
|
|
166
|
-
({ user, password }) => convertToInternal((user._links.convertToInternal as Link).href, password),
|
|
167
|
-
{
|
|
168
|
-
onSuccess: async (_, { user }) => {
|
|
169
|
-
await queryClient.invalidateQueries(["user", user.name]);
|
|
170
|
-
await queryClient.invalidateQueries(["users"]);
|
|
171
|
-
},
|
|
172
|
-
}
|
|
173
|
-
);
|
|
174
|
-
return {
|
|
175
|
-
convertToInternal: (user: User, password: string) => mutate({ user, password }),
|
|
176
|
-
isLoading,
|
|
177
|
-
error,
|
|
178
|
-
isConverted: !!data,
|
|
179
|
-
};
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
export const useConvertToExternal = () => {
|
|
183
|
-
const queryClient = useQueryClient();
|
|
184
|
-
const { mutate, isLoading, error, data } = useMutation<unknown, Error, User>(
|
|
185
|
-
(user) => convertToExternal((user._links.convertToExternal as Link).href),
|
|
186
|
-
{
|
|
187
|
-
onSuccess: async (_, user) => {
|
|
188
|
-
await queryClient.invalidateQueries(["user", user.name]);
|
|
189
|
-
await queryClient.invalidateQueries(["users"]);
|
|
190
|
-
},
|
|
191
|
-
}
|
|
192
|
-
);
|
|
193
|
-
return {
|
|
194
|
-
convertToExternal: (user: User) => mutate(user),
|
|
195
|
-
isLoading,
|
|
196
|
-
error,
|
|
197
|
-
isConverted: !!data,
|
|
198
|
-
};
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
const CONTENT_TYPE_PASSWORD_OVERWRITE = "application/vnd.scmm-passwordOverwrite+json;v=2";
|
|
202
|
-
|
|
203
|
-
export const useSetUserPassword = (user: User) => {
|
|
204
|
-
const { data, isLoading, error, mutate, reset } = useMutation<unknown, Error, string>((password) =>
|
|
205
|
-
apiClient.put(
|
|
206
|
-
requiredLink(user, "password"),
|
|
207
|
-
{
|
|
208
|
-
newPassword: password,
|
|
209
|
-
},
|
|
210
|
-
CONTENT_TYPE_PASSWORD_OVERWRITE
|
|
211
|
-
)
|
|
212
|
-
);
|
|
213
|
-
return {
|
|
214
|
-
setPassword: (newPassword: string) => mutate(newPassword),
|
|
215
|
-
passwordOverwritten: !!data,
|
|
216
|
-
isLoading,
|
|
217
|
-
error,
|
|
218
|
-
reset,
|
|
219
|
-
};
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
const CONTENT_TYPE_PASSWORD_CHANGE = "application/vnd.scmm-passwordChange+json;v=2";
|
|
223
|
-
|
|
224
|
-
type ChangeUserPasswordRequest = {
|
|
225
|
-
oldPassword: string;
|
|
226
|
-
newPassword: string;
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
export const useChangeUserPassword = (user: User | Me) => {
|
|
230
|
-
const { data, isLoading, error, mutate, reset } = useMutation<unknown, Error, ChangeUserPasswordRequest>((request) =>
|
|
231
|
-
apiClient.put(requiredLink(user, "password"), request, CONTENT_TYPE_PASSWORD_CHANGE)
|
|
232
|
-
);
|
|
233
|
-
return {
|
|
234
|
-
changePassword: (oldPassword: string, newPassword: string) => mutate({ oldPassword, newPassword }),
|
|
235
|
-
passwordChanged: !!data,
|
|
236
|
-
isLoading,
|
|
237
|
-
error,
|
|
238
|
-
reset,
|
|
239
|
-
};
|
|
240
|
-
};
|
package/src/utils.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* MIT License
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
export const createQueryString = (params: Record<string, string>) => {
|
|
26
|
-
return Object.keys(params)
|
|
27
|
-
.map((k) => encodeURIComponent(k) + "=" + encodeURIComponent(params[k]))
|
|
28
|
-
.join("&");
|
|
29
|
-
};
|