@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/plugins.ts
DELETED
|
@@ -1,259 +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, useIndexLink, useRequiredIndexLink } from "./base";
|
|
26
|
-
import { isPluginCollection, PendingPlugins, Plugin, PluginCollection } from "@scm-manager/ui-types";
|
|
27
|
-
import { useMutation, useQuery, useQueryClient } from "react-query";
|
|
28
|
-
import { apiClient } from "./apiclient";
|
|
29
|
-
import { requiredLink } from "./links";
|
|
30
|
-
import { BadGatewayError } from "./errors";
|
|
31
|
-
|
|
32
|
-
type WaitForRestartOptions = {
|
|
33
|
-
initialDelay?: number;
|
|
34
|
-
timeout?: number;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export const waitForRestartAfter = (
|
|
38
|
-
promise: Promise<any>,
|
|
39
|
-
{ initialDelay = 1000, timeout = 500 }: WaitForRestartOptions = {}
|
|
40
|
-
): Promise<void> => {
|
|
41
|
-
const endTime = Number(new Date()) + 4 * 60 * 1000;
|
|
42
|
-
let started = false;
|
|
43
|
-
|
|
44
|
-
const executor = <T = any>(data: T) => (resolve: (result: T) => void, reject: (error: Error) => void) => {
|
|
45
|
-
// we need some initial delay
|
|
46
|
-
if (!started) {
|
|
47
|
-
started = true;
|
|
48
|
-
setTimeout(executor(data), initialDelay, resolve, reject);
|
|
49
|
-
} else {
|
|
50
|
-
apiClient
|
|
51
|
-
.get("")
|
|
52
|
-
.then(() => resolve(data))
|
|
53
|
-
.catch(() => {
|
|
54
|
-
if (Number(new Date()) < endTime) {
|
|
55
|
-
setTimeout(executor(data), timeout, resolve, reject);
|
|
56
|
-
} else {
|
|
57
|
-
reject(new Error("timeout reached"));
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
return promise
|
|
64
|
-
.catch(err => {
|
|
65
|
-
if (err instanceof BadGatewayError) {
|
|
66
|
-
// in some rare cases the reverse proxy stops forwarding traffic to scm before the response is returned
|
|
67
|
-
// in such a case the reverse proxy returns 502 (bad gateway), so we treat 502 not as error
|
|
68
|
-
return "ok";
|
|
69
|
-
}
|
|
70
|
-
throw err;
|
|
71
|
-
})
|
|
72
|
-
.then(data => new Promise<void>(executor(data)));
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
export type UseAvailablePluginsOptions = {
|
|
76
|
-
enabled?: boolean;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
export const useAvailablePlugins = ({ enabled }: UseAvailablePluginsOptions = {}): ApiResult<PluginCollection> => {
|
|
80
|
-
const indexLink = useRequiredIndexLink("availablePlugins");
|
|
81
|
-
return useQuery<PluginCollection, Error>(
|
|
82
|
-
["plugins", "available"],
|
|
83
|
-
() => apiClient.get(indexLink).then(response => response.json()),
|
|
84
|
-
{
|
|
85
|
-
enabled,
|
|
86
|
-
retry: 3
|
|
87
|
-
}
|
|
88
|
-
);
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
export type UseInstalledPluginsOptions = {
|
|
92
|
-
enabled?: boolean;
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
export const useInstalledPlugins = ({ enabled }: UseInstalledPluginsOptions = {}): ApiResult<PluginCollection> => {
|
|
96
|
-
const indexLink = useRequiredIndexLink("installedPlugins");
|
|
97
|
-
return useQuery<PluginCollection, Error>(
|
|
98
|
-
["plugins", "installed"],
|
|
99
|
-
() => apiClient.get(indexLink).then(response => response.json()),
|
|
100
|
-
{
|
|
101
|
-
enabled,
|
|
102
|
-
retry: 3
|
|
103
|
-
}
|
|
104
|
-
);
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
export const usePendingPlugins = (): ApiResult<PendingPlugins> => {
|
|
108
|
-
const indexLink = useIndexLink("pendingPlugins");
|
|
109
|
-
return useQuery<PendingPlugins, Error>(
|
|
110
|
-
["plugins", "pending"],
|
|
111
|
-
() => apiClient.get(indexLink!).then(response => response.json()),
|
|
112
|
-
{
|
|
113
|
-
enabled: !!indexLink,
|
|
114
|
-
retry: 3
|
|
115
|
-
}
|
|
116
|
-
);
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
const linkWithRestart = (link: string, restart?: boolean) => {
|
|
120
|
-
if (restart) {
|
|
121
|
-
return link + "WithRestart";
|
|
122
|
-
}
|
|
123
|
-
return link;
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
type RestartOptions = WaitForRestartOptions & {
|
|
127
|
-
restart?: boolean;
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
type PluginActionOptions = {
|
|
131
|
-
plugin: Plugin;
|
|
132
|
-
restartOptions: RestartOptions;
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
export const useInstallPlugin = () => {
|
|
136
|
-
const queryClient = useQueryClient();
|
|
137
|
-
const { mutate, isLoading, error, data } = useMutation<unknown, Error, PluginActionOptions>(
|
|
138
|
-
({ plugin, restartOptions: { restart, ...waitForRestartOptions } }) => {
|
|
139
|
-
const promise = apiClient.post(requiredLink(plugin, linkWithRestart("install", restart)));
|
|
140
|
-
if (restart) {
|
|
141
|
-
return waitForRestartAfter(promise, waitForRestartOptions);
|
|
142
|
-
}
|
|
143
|
-
return promise;
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
onSuccess: () => queryClient.invalidateQueries("plugins")
|
|
147
|
-
}
|
|
148
|
-
);
|
|
149
|
-
return {
|
|
150
|
-
install: (plugin: Plugin, restartOptions: RestartOptions = {}) =>
|
|
151
|
-
mutate({
|
|
152
|
-
plugin,
|
|
153
|
-
restartOptions
|
|
154
|
-
}),
|
|
155
|
-
isLoading,
|
|
156
|
-
error,
|
|
157
|
-
data,
|
|
158
|
-
isInstalled: !!data
|
|
159
|
-
};
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
export const useUninstallPlugin = () => {
|
|
163
|
-
const queryClient = useQueryClient();
|
|
164
|
-
const { mutate, isLoading, error, data } = useMutation<unknown, Error, PluginActionOptions>(
|
|
165
|
-
({ plugin, restartOptions: { restart, ...waitForRestartOptions } }) => {
|
|
166
|
-
const promise = apiClient.post(requiredLink(plugin, linkWithRestart("uninstall", restart)));
|
|
167
|
-
if (restart) {
|
|
168
|
-
return waitForRestartAfter(promise, waitForRestartOptions);
|
|
169
|
-
}
|
|
170
|
-
return promise;
|
|
171
|
-
},
|
|
172
|
-
{
|
|
173
|
-
onSuccess: () => queryClient.invalidateQueries("plugins")
|
|
174
|
-
}
|
|
175
|
-
);
|
|
176
|
-
return {
|
|
177
|
-
uninstall: (plugin: Plugin, restartOptions: RestartOptions = {}) =>
|
|
178
|
-
mutate({
|
|
179
|
-
plugin,
|
|
180
|
-
restartOptions
|
|
181
|
-
}),
|
|
182
|
-
isLoading,
|
|
183
|
-
error,
|
|
184
|
-
isUninstalled: !!data
|
|
185
|
-
};
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
type UpdatePluginsOptions = {
|
|
189
|
-
plugins: Plugin | PluginCollection;
|
|
190
|
-
restartOptions: RestartOptions;
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
export const useUpdatePlugins = () => {
|
|
194
|
-
const queryClient = useQueryClient();
|
|
195
|
-
const { mutate, isLoading, error, data } = useMutation<unknown, Error, UpdatePluginsOptions>(
|
|
196
|
-
({ plugins, restartOptions: { restart, ...waitForRestartOptions } }) => {
|
|
197
|
-
const isCollection = isPluginCollection(plugins);
|
|
198
|
-
const promise = apiClient.post(
|
|
199
|
-
requiredLink(plugins, isCollection ? "update" : linkWithRestart("update", restart))
|
|
200
|
-
);
|
|
201
|
-
if (restart && !isCollection) {
|
|
202
|
-
return waitForRestartAfter(promise, waitForRestartOptions);
|
|
203
|
-
}
|
|
204
|
-
return promise;
|
|
205
|
-
},
|
|
206
|
-
{
|
|
207
|
-
onSuccess: () => queryClient.invalidateQueries("plugins")
|
|
208
|
-
}
|
|
209
|
-
);
|
|
210
|
-
return {
|
|
211
|
-
update: (plugin: Plugin | PluginCollection, restartOptions: RestartOptions = {}) =>
|
|
212
|
-
mutate({
|
|
213
|
-
plugins: plugin,
|
|
214
|
-
restartOptions
|
|
215
|
-
}),
|
|
216
|
-
isLoading,
|
|
217
|
-
error,
|
|
218
|
-
isUpdated: !!data
|
|
219
|
-
};
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
type ExecutePendingPlugins = {
|
|
223
|
-
pending: PendingPlugins;
|
|
224
|
-
restartOptions: WaitForRestartOptions;
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
export const useExecutePendingPlugins = () => {
|
|
228
|
-
const queryClient = useQueryClient();
|
|
229
|
-
const { mutate, isLoading, error, data } = useMutation<unknown, Error, ExecutePendingPlugins>(
|
|
230
|
-
({ pending, restartOptions }) =>
|
|
231
|
-
waitForRestartAfter(apiClient.post(requiredLink(pending, "execute")), restartOptions),
|
|
232
|
-
{
|
|
233
|
-
onSuccess: () => queryClient.invalidateQueries("plugins")
|
|
234
|
-
}
|
|
235
|
-
);
|
|
236
|
-
return {
|
|
237
|
-
update: (pending: PendingPlugins, restartOptions: WaitForRestartOptions = {}) =>
|
|
238
|
-
mutate({ pending, restartOptions }),
|
|
239
|
-
isLoading,
|
|
240
|
-
error,
|
|
241
|
-
isExecuted: !!data
|
|
242
|
-
};
|
|
243
|
-
};
|
|
244
|
-
|
|
245
|
-
export const useCancelPendingPlugins = () => {
|
|
246
|
-
const queryClient = useQueryClient();
|
|
247
|
-
const { mutate, isLoading, error, data } = useMutation<unknown, Error, PendingPlugins>(
|
|
248
|
-
pending => apiClient.post(requiredLink(pending, "cancel")),
|
|
249
|
-
{
|
|
250
|
-
onSuccess: () => queryClient.invalidateQueries("plugins")
|
|
251
|
-
}
|
|
252
|
-
);
|
|
253
|
-
return {
|
|
254
|
-
update: (pending: PendingPlugins) => mutate(pending),
|
|
255
|
-
isLoading,
|
|
256
|
-
error,
|
|
257
|
-
isCancelled: !!data
|
|
258
|
-
};
|
|
259
|
-
};
|
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
|
-
};
|