@scm-manager/ui-api 2.20.1-20210616-114029 → 2.20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/users.ts CHANGED
@@ -24,11 +24,10 @@
24
24
 
25
25
  import { ApiResult, useRequiredIndexLink } from "./base";
26
26
  import { useMutation, useQuery, useQueryClient } from "react-query";
27
- import {Link, Me, User, UserCollection, UserCreation} from "@scm-manager/ui-types";
27
+ import { Link, User, UserCollection, UserCreation } from "@scm-manager/ui-types";
28
28
  import { apiClient } from "./apiclient";
29
29
  import { createQueryString } from "./utils";
30
30
  import { concat } from "./urls";
31
- import { requiredLink } from "./links";
32
31
 
33
32
  export type UseUsersRequest = {
34
33
  page?: number | string;
@@ -49,11 +48,11 @@ export const useUsers = (request?: UseUsersRequest): ApiResult<UserCollection> =
49
48
 
50
49
  return useQuery<UserCollection, Error>(
51
50
  ["users", request?.search || "", request?.page || 0],
52
- () => apiClient.get(`${indexLink}?${createQueryString(queryParams)}`).then((response) => response.json()),
51
+ () => apiClient.get(`${indexLink}?${createQueryString(queryParams)}`).then(response => response.json()),
53
52
  {
54
53
  onSuccess: (users: UserCollection) => {
55
54
  users._embedded.users.forEach((user: User) => queryClient.setQueryData(["user", user.name], user));
56
- },
55
+ }
57
56
  }
58
57
  );
59
58
  };
@@ -61,7 +60,7 @@ export const useUsers = (request?: UseUsersRequest): ApiResult<UserCollection> =
61
60
  export const useUser = (name: string): ApiResult<User> => {
62
61
  const indexLink = useRequiredIndexLink("users");
63
62
  return useQuery<User, Error>(["user", name], () =>
64
- apiClient.get(concat(indexLink, name)).then((response) => response.json())
63
+ apiClient.get(concat(indexLink, name)).then(response => response.json())
65
64
  );
66
65
  };
67
66
 
@@ -69,14 +68,14 @@ const createUser = (link: string) => {
69
68
  return (user: UserCreation) => {
70
69
  return apiClient
71
70
  .post(link, user, "application/vnd.scmm-user+json;v=2")
72
- .then((response) => {
71
+ .then(response => {
73
72
  const location = response.headers.get("Location");
74
73
  if (!location) {
75
74
  throw new Error("Server does not return required Location header");
76
75
  }
77
76
  return apiClient.get(location);
78
77
  })
79
- .then((response) => response.json());
78
+ .then(response => response.json());
80
79
  };
81
80
  };
82
81
 
@@ -84,23 +83,23 @@ export const useCreateUser = () => {
84
83
  const queryClient = useQueryClient();
85
84
  const link = useRequiredIndexLink("users");
86
85
  const { mutate, data, isLoading, error } = useMutation<User, Error, UserCreation>(createUser(link), {
87
- onSuccess: (user) => {
86
+ onSuccess: user => {
88
87
  queryClient.setQueryData(["user", user.name], user);
89
88
  return queryClient.invalidateQueries(["users"]);
90
- },
89
+ }
91
90
  });
92
91
  return {
93
92
  create: (user: UserCreation) => mutate(user),
94
93
  isLoading,
95
94
  error,
96
- user: data,
95
+ user: data
97
96
  };
98
97
  };
99
98
 
100
99
  export const useUpdateUser = () => {
101
100
  const queryClient = useQueryClient();
102
101
  const { mutate, isLoading, error, data } = useMutation<unknown, Error, User>(
103
- (user) => {
102
+ user => {
104
103
  const updateUrl = (user._links.update as Link).href;
105
104
  return apiClient.put(updateUrl, user, "application/vnd.scmm-user+json;v=2");
106
105
  },
@@ -108,21 +107,21 @@ export const useUpdateUser = () => {
108
107
  onSuccess: async (_, user) => {
109
108
  await queryClient.invalidateQueries(["user", user.name]);
110
109
  await queryClient.invalidateQueries(["users"]);
111
- },
110
+ }
112
111
  }
113
112
  );
114
113
  return {
115
114
  update: (user: User) => mutate(user),
116
115
  isLoading,
117
116
  error,
118
- isUpdated: !!data,
117
+ isUpdated: !!data
119
118
  };
120
119
  };
121
120
 
122
121
  export const useDeleteUser = () => {
123
122
  const queryClient = useQueryClient();
124
123
  const { mutate, isLoading, error, data } = useMutation<unknown, Error, User>(
125
- (user) => {
124
+ user => {
126
125
  const deleteUrl = (user._links.delete as Link).href;
127
126
  return apiClient.delete(deleteUrl);
128
127
  },
@@ -130,14 +129,14 @@ export const useDeleteUser = () => {
130
129
  onSuccess: async (_, name) => {
131
130
  await queryClient.invalidateQueries(["user", name]);
132
131
  await queryClient.invalidateQueries(["users"]);
133
- },
132
+ }
134
133
  }
135
134
  );
136
135
  return {
137
136
  remove: (user: User) => mutate(user),
138
137
  isLoading,
139
138
  error,
140
- isDeleted: !!data,
139
+ isDeleted: !!data
141
140
  };
142
141
  };
143
142
 
@@ -145,7 +144,7 @@ const convertToInternal = (url: string, newPassword: string) => {
145
144
  return apiClient.put(
146
145
  url,
147
146
  {
148
- newPassword,
147
+ newPassword
149
148
  },
150
149
  "application/vnd.scmm-user+json;v=2"
151
150
  );
@@ -168,73 +167,32 @@ export const useConvertToInternal = () => {
168
167
  onSuccess: async (_, { user }) => {
169
168
  await queryClient.invalidateQueries(["user", user.name]);
170
169
  await queryClient.invalidateQueries(["users"]);
171
- },
170
+ }
172
171
  }
173
172
  );
174
173
  return {
175
174
  convertToInternal: (user: User, password: string) => mutate({ user, password }),
176
175
  isLoading,
177
176
  error,
178
- isConverted: !!data,
177
+ isConverted: !!data
179
178
  };
180
179
  };
181
180
 
182
181
  export const useConvertToExternal = () => {
183
182
  const queryClient = useQueryClient();
184
183
  const { mutate, isLoading, error, data } = useMutation<unknown, Error, User>(
185
- (user) => convertToExternal((user._links.convertToExternal as Link).href),
184
+ user => convertToExternal((user._links.convertToExternal as Link).href),
186
185
  {
187
186
  onSuccess: async (_, user) => {
188
187
  await queryClient.invalidateQueries(["user", user.name]);
189
188
  await queryClient.invalidateQueries(["users"]);
190
- },
189
+ }
191
190
  }
192
191
  );
193
192
  return {
194
193
  convertToExternal: (user: User) => mutate(user),
195
194
  isLoading,
196
195
  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
196
+ isConverted: !!data
239
197
  };
240
198
  };
@@ -1,40 +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
- import { AnnotatedSource, File, Link, Repository } from "@scm-manager/ui-types";
25
- import { useQuery } from "react-query";
26
- import { apiClient } from "./apiclient";
27
- import { ApiResult } from "./base";
28
- import { repoQueryKey } from "./keys";
29
-
30
- export const useAnnotations = (repository: Repository, revision: string, file: File): ApiResult<AnnotatedSource> => {
31
- const { isLoading, error, data } = useQuery<AnnotatedSource, Error>(
32
- repoQueryKey(repository, "annotations", revision, file.path),
33
- () => apiClient.get((file._links.annotate as Link).href).then((response) => response.json())
34
- );
35
- return {
36
- isLoading,
37
- error,
38
- data,
39
- };
40
- };
package/src/apiKeys.ts DELETED
@@ -1,82 +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
- import { ApiKey, ApiKeyCreation, ApiKeysCollection, ApiKeyWithToken, Me, User } from "@scm-manager/ui-types";
25
- import { ApiResult } from "./base";
26
- import { useMutation, useQuery, useQueryClient } from "react-query";
27
- import { apiClient } from "./apiclient";
28
- import { requiredLink } from "./links";
29
-
30
- const CONTENT_TYPE_API_KEY = "application/vnd.scmm-apiKey+json;v=2";
31
-
32
- export const useApiKeys = (user: User | Me): ApiResult<ApiKeysCollection> =>
33
- useQuery(["user", user.name, "apiKeys"], () => apiClient.get(requiredLink(user, "apiKeys")).then((r) => r.json()));
34
-
35
- const createApiKey =
36
- (link: string) =>
37
- async (key: ApiKeyCreation): Promise<ApiKeyWithToken> => {
38
- const creationResponse = await apiClient.post(link, key, CONTENT_TYPE_API_KEY);
39
- const location = creationResponse.headers.get("Location");
40
- if (!location) {
41
- throw new Error("Server does not return required Location header");
42
- }
43
- const locationResponse = await apiClient.get(location);
44
- const [apiKey, token] = await Promise.all<ApiKey, string>([locationResponse.json(), creationResponse.text()]);
45
- return { ...apiKey, token } as ApiKeyWithToken;
46
- };
47
-
48
- export const useCreateApiKey = (user: User | Me, apiKeys: ApiKeysCollection) => {
49
- const queryClient = useQueryClient();
50
- const { mutate, data, isLoading, error, reset } = useMutation<ApiKeyWithToken, Error, ApiKeyCreation>(
51
- createApiKey(requiredLink(apiKeys, "create")),
52
- {
53
- onSuccess: () => queryClient.invalidateQueries(["user", user.name, "apiKeys"]),
54
- }
55
- );
56
- return {
57
- create: (key: ApiKeyCreation) => mutate(key),
58
- isLoading,
59
- error,
60
- apiKey: data,
61
- reset,
62
- };
63
- };
64
-
65
- export const useDeleteApiKey = (user: User | Me) => {
66
- const queryClient = useQueryClient();
67
- const { mutate, isLoading, error, data } = useMutation<unknown, Error, ApiKey>(
68
- (apiKey) => {
69
- const deleteUrl = requiredLink(apiKey, "delete");
70
- return apiClient.delete(deleteUrl);
71
- },
72
- {
73
- onSuccess: () => queryClient.invalidateQueries(["user", user.name, "apiKeys"]),
74
- }
75
- );
76
- return {
77
- remove: (apiKey: ApiKey) => mutate(apiKey),
78
- isLoading,
79
- error,
80
- isDeleted: !!data,
81
- };
82
- };
@@ -1,49 +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
- import { apiClient } from "./apiclient";
25
- import { useQuery } from "react-query";
26
- import { ApiResult } from "./base";
27
-
28
- export type ContentType = {
29
- type: string;
30
- language?: string;
31
- };
32
-
33
- function getContentType(url: string): Promise<ContentType> {
34
- return apiClient.head(url).then((response) => {
35
- return {
36
- type: response.headers.get("Content-Type") || "application/octet-stream",
37
- language: response.headers.get("X-Programming-Language") || undefined,
38
- };
39
- });
40
- }
41
-
42
- export const useContentType = (url: string): ApiResult<ContentType> => {
43
- const { isLoading, error, data } = useQuery<ContentType, Error>(["contentType", url], () => getContentType(url));
44
- return {
45
- isLoading,
46
- error,
47
- data,
48
- };
49
- };
@@ -1,33 +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
- import { File } from "@scm-manager/ui-types";
25
- import { useQuery } from "react-query";
26
- import { apiClient } from "./apiclient";
27
- import { requiredLink } from "./links";
28
- import { ApiResult } from "./base";
29
-
30
- export const useFileContent = (file: File): ApiResult<string> => {
31
- const selfLink = requiredLink(file, "self");
32
- return useQuery(["fileContent", selfLink], () => apiClient.get(selfLink).then((response) => response.text()));
33
- };
package/src/history.ts DELETED
@@ -1,62 +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
- import { ApiResult } from "./base";
25
- import { Changeset, ChangesetCollection, File, Link, Repository } from "@scm-manager/ui-types";
26
- import { useQuery, useQueryClient } from "react-query";
27
- import { apiClient } from "./apiclient";
28
- import { createQueryString } from "./utils";
29
- import { changesetQueryKey } from "./changesets";
30
- import { repoQueryKey } from "./keys";
31
-
32
- export type UseHistoryRequest = {
33
- page?: number | string;
34
- };
35
-
36
- export const useHistory = (
37
- repository: Repository,
38
- revision: string,
39
- file: File,
40
- request?: UseHistoryRequest
41
- ): ApiResult<ChangesetCollection> => {
42
- const queryClient = useQueryClient();
43
- const link = (file._links.history as Link).href;
44
-
45
- const queryParams: Record<string, string> = {};
46
- if (request?.page) {
47
- queryParams.page = request.page.toString();
48
- }
49
-
50
- return useQuery<ChangesetCollection, Error>(
51
- repoQueryKey(repository, "history", revision, file.path, request?.page || 0),
52
- () => apiClient.get(`${link}?${createQueryString(queryParams)}`).then((response) => response.json()),
53
- {
54
- keepPreviousData: true,
55
- onSuccess: (changesets: ChangesetCollection) => {
56
- changesets._embedded.changesets.forEach((changeset: Changeset) =>
57
- queryClient.setQueryData(changesetQueryKey(repository, changeset.id), changeset)
58
- );
59
- },
60
- }
61
- );
62
- };
package/src/publicKeys.ts DELETED
@@ -1,83 +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
- import { Me, PublicKey, PublicKeyCreation, PublicKeysCollection, User } from "@scm-manager/ui-types";
25
- import { ApiResult } from "./base";
26
- import { useMutation, useQuery, useQueryClient } from "react-query";
27
- import { apiClient } from "./apiclient";
28
- import { requiredLink } from "./links";
29
-
30
- export const CONTENT_TYPE_PUBLIC_KEY = "application/vnd.scmm-publicKey+json;v=2";
31
-
32
- export const usePublicKeys = (user: User | Me): ApiResult<PublicKeysCollection> =>
33
- useQuery(["user", user.name, "publicKeys"], () =>
34
- apiClient.get(requiredLink(user, "publicKeys")).then((r) => r.json())
35
- );
36
-
37
- const createPublicKey =
38
- (link: string) =>
39
- async (key: PublicKeyCreation): Promise<PublicKey> => {
40
- const creationResponse = await apiClient.post(link, key, CONTENT_TYPE_PUBLIC_KEY);
41
- const location = creationResponse.headers.get("Location");
42
- if (!location) {
43
- throw new Error("Server does not return required Location header");
44
- }
45
- const apiKeyResponse = await apiClient.get(location);
46
- return apiKeyResponse.json();
47
- };
48
-
49
- export const useCreatePublicKey = (user: User | Me, publicKeys: PublicKeysCollection) => {
50
- const queryClient = useQueryClient();
51
- const { mutate, data, isLoading, error, reset } = useMutation<PublicKey, Error, PublicKeyCreation>(
52
- createPublicKey(requiredLink(publicKeys, "create")),
53
- {
54
- onSuccess: () => queryClient.invalidateQueries(["user", user.name, "publicKeys"]),
55
- }
56
- );
57
- return {
58
- create: (key: PublicKeyCreation) => mutate(key),
59
- isLoading,
60
- error,
61
- apiKey: data,
62
- reset,
63
- };
64
- };
65
-
66
- export const useDeletePublicKey = (user: User | Me) => {
67
- const queryClient = useQueryClient();
68
- const { mutate, isLoading, error, data } = useMutation<unknown, Error, PublicKey>(
69
- (publicKey) => {
70
- const deleteUrl = requiredLink(publicKey, "delete");
71
- return apiClient.delete(deleteUrl);
72
- },
73
- {
74
- onSuccess: () => queryClient.invalidateQueries(["user", user.name, "publicKeys"]),
75
- }
76
- );
77
- return {
78
- remove: (publicKey: PublicKey) => mutate(publicKey),
79
- isLoading,
80
- error,
81
- isDeleted: !!data,
82
- };
83
- };
package/src/search.ts DELETED
@@ -1,56 +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 { QueryResult } from "@scm-manager/ui-types";
27
- import { apiClient } from "./apiclient";
28
- import { createQueryString } from "./utils";
29
- import { useQuery } from "react-query";
30
-
31
- export type SearchOptions = {
32
- page?: number;
33
- pageSize?: number;
34
- };
35
-
36
- const defaultSearchOptions: SearchOptions = {};
37
-
38
- export const useSearch = (query: string, options = defaultSearchOptions): ApiResult<QueryResult> => {
39
- const link = useRequiredIndexLink("search");
40
-
41
- const queryParams: Record<string, string> = {};
42
- queryParams.q = query;
43
- if (options.page) {
44
- queryParams.page = options.page.toString();
45
- }
46
- if (options.pageSize) {
47
- queryParams.pageSize = options.pageSize.toString();
48
- }
49
- return useQuery<QueryResult, Error>(
50
- ["search", query],
51
- () => apiClient.get(`${link}?${createQueryString(queryParams)}`).then((response) => response.json()),
52
- {
53
- enabled: query.length > 1,
54
- }
55
- );
56
- };