@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.
Files changed (79) hide show
  1. package/build/index.d.ts +735 -0
  2. package/build/index.js +3200 -0
  3. package/build/index.mjs +3031 -0
  4. package/package.json +15 -10
  5. package/LICENSE.txt +0 -21
  6. package/src/ApiProvider.test.tsx +0 -60
  7. package/src/ApiProvider.tsx +0 -80
  8. package/src/LegacyContext.test.tsx +0 -52
  9. package/src/LegacyContext.tsx +0 -75
  10. package/src/admin.test.ts +0 -55
  11. package/src/admin.ts +0 -42
  12. package/src/alerts.ts +0 -107
  13. package/src/annotations.ts +0 -45
  14. package/src/apiKeys.ts +0 -82
  15. package/src/apiclient.test.ts +0 -126
  16. package/src/apiclient.ts +0 -336
  17. package/src/base.test.ts +0 -238
  18. package/src/base.ts +0 -120
  19. package/src/branches.test.ts +0 -234
  20. package/src/branches.ts +0 -201
  21. package/src/changesets.test.ts +0 -178
  22. package/src/changesets.ts +0 -82
  23. package/src/compare.ts +0 -90
  24. package/src/config.test.ts +0 -118
  25. package/src/config.ts +0 -60
  26. package/src/configLink.test.ts +0 -169
  27. package/src/configLink.ts +0 -89
  28. package/src/contentType.ts +0 -58
  29. package/src/diff.test.ts +0 -234
  30. package/src/diff.ts +0 -93
  31. package/src/errors.test.ts +0 -59
  32. package/src/errors.ts +0 -133
  33. package/src/fileContent.ts +0 -33
  34. package/src/groupSuggestions.ts +0 -32
  35. package/src/groups.test.ts +0 -241
  36. package/src/groups.ts +0 -141
  37. package/src/help/search/modal.de.ts +0 -33
  38. package/src/help/search/modal.en.ts +0 -33
  39. package/src/help/search/syntax.de.ts +0 -148
  40. package/src/help/search/syntax.en.ts +0 -145
  41. package/src/history.ts +0 -62
  42. package/src/import.ts +0 -114
  43. package/src/index.ts +0 -72
  44. package/src/keys.ts +0 -48
  45. package/src/links.test.ts +0 -99
  46. package/src/links.ts +0 -54
  47. package/src/login.test.ts +0 -240
  48. package/src/login.ts +0 -128
  49. package/src/loginInfo.ts +0 -43
  50. package/src/namespaceSuggestions.ts +0 -32
  51. package/src/namespaces.test.ts +0 -95
  52. package/src/namespaces.ts +0 -43
  53. package/src/notifications.ts +0 -183
  54. package/src/permissions.test.ts +0 -345
  55. package/src/permissions.ts +0 -202
  56. package/src/plugins.test.ts +0 -336
  57. package/src/plugins.ts +0 -259
  58. package/src/publicKeys.ts +0 -83
  59. package/src/repositories.test.ts +0 -508
  60. package/src/repositories.ts +0 -375
  61. package/src/repository-roles.test.ts +0 -229
  62. package/src/repository-roles.ts +0 -142
  63. package/src/reset.ts +0 -36
  64. package/src/search.ts +0 -153
  65. package/src/sources.test.ts +0 -233
  66. package/src/sources.ts +0 -136
  67. package/src/suggestions.ts +0 -47
  68. package/src/tags.test.ts +0 -272
  69. package/src/tags.ts +0 -118
  70. package/src/tests/createInfiniteCachingClient.ts +0 -37
  71. package/src/tests/createWrapper.tsx +0 -37
  72. package/src/tests/indexLinks.ts +0 -43
  73. package/src/urls.test.ts +0 -104
  74. package/src/urls.ts +0 -118
  75. package/src/usePluginCenterAuthInfo.ts +0 -91
  76. package/src/userSuggestions.ts +0 -32
  77. package/src/users.test.ts +0 -310
  78. package/src/users.ts +0 -240
  79. package/src/utils.ts +0 -29
@@ -1,183 +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 { useMe } from "./login";
26
- import { useMutation, useQuery, useQueryClient } from "react-query";
27
- import { Link, Notification, NotificationCollection } from "@scm-manager/ui-types";
28
- import { apiClient } from "./apiclient";
29
- import { useCallback, useEffect, useState } from "react";
30
- import { requiredLink } from "./links";
31
-
32
- export const useNotifications = () => {
33
- const { data: me } = useMe();
34
- const link = (me?._links["notifications"] as Link)?.href;
35
- const { data, error, isLoading, refetch } = useQuery<NotificationCollection, Error>(
36
- "notifications",
37
- () => apiClient.get(link).then((response) => response.json()),
38
- {
39
- enabled: !!link,
40
- }
41
- );
42
-
43
- const memoizedRefetch = useCallback(() => {
44
- return refetch().then((r) => r.data);
45
- }, [refetch]);
46
-
47
- return {
48
- data,
49
- error,
50
- isLoading,
51
- refetch: memoizedRefetch,
52
- };
53
- };
54
-
55
- export const useDismissNotification = (notification: Notification) => {
56
- const queryClient = useQueryClient();
57
- const link = requiredLink(notification, "dismiss");
58
- const { data, isLoading, error, mutate } = useMutation<Response, Error>(() => apiClient.delete(link), {
59
- onSuccess: () => {
60
- queryClient.invalidateQueries("notifications");
61
- },
62
- });
63
- return {
64
- isLoading,
65
- error,
66
- dismiss: () => mutate(),
67
- isCleared: !!data,
68
- };
69
- };
70
-
71
- export const useClearNotifications = (notificationCollection: NotificationCollection) => {
72
- const queryClient = useQueryClient();
73
- const link = requiredLink(notificationCollection, "clear");
74
- const { data, isLoading, error, mutate } = useMutation<Response, Error>(() => apiClient.delete(link), {
75
- onSuccess: () => {
76
- queryClient.invalidateQueries("notifications");
77
- },
78
- });
79
- return {
80
- isLoading,
81
- error,
82
- clear: () => mutate(),
83
- isCleared: !!data,
84
- };
85
- };
86
-
87
- const isEqual = (left: Notification, right: Notification) => {
88
- return left === right || (left.message === right.message && left.createdAt === right.createdAt);
89
- };
90
-
91
- export const useNotificationSubscription = (
92
- refetch: () => Promise<NotificationCollection | undefined>,
93
- notificationCollection?: NotificationCollection
94
- ) => {
95
- const [notifications, setNotifications] = useState<Notification[]>([]);
96
- const [disconnectedAt, setDisconnectedAt] = useState<Date>();
97
- const link = (notificationCollection?._links.subscribe as Link)?.href;
98
-
99
- const onVisible = useCallback(() => {
100
- // we don't need to catch the error,
101
- // because if the refetch throws an error the parent useNotifications should catch it
102
- refetch().then((collection) => {
103
- if (collection) {
104
- const newNotifications = collection._embedded?.notifications.filter((n) => {
105
- return disconnectedAt && disconnectedAt < new Date(n.createdAt);
106
- });
107
- if (newNotifications && newNotifications.length > 0) {
108
- setNotifications((previous) => [...previous, ...newNotifications]);
109
- }
110
- setDisconnectedAt(undefined);
111
- }
112
- });
113
- }, [disconnectedAt, refetch]);
114
-
115
- const onHide = useCallback(() => {
116
- setDisconnectedAt(new Date());
117
- }, []);
118
-
119
- const received = useCallback(
120
- (notification: Notification) => {
121
- setNotifications((previous) => [...previous, notification]);
122
- refetch();
123
- },
124
- [refetch]
125
- );
126
-
127
- useEffect(() => {
128
- if (link) {
129
- let cancel: () => void;
130
-
131
- const disconnect = () => {
132
- if (cancel) {
133
- cancel();
134
- }
135
- };
136
-
137
- const connect = () => {
138
- disconnect();
139
- cancel = apiClient.subscribe(link, {
140
- notification: (event) => {
141
- received(JSON.parse(event.data));
142
- },
143
- });
144
- };
145
-
146
- const handleVisibilityChange = () => {
147
- if (document.visibilityState === "visible") {
148
- onVisible();
149
- } else {
150
- onHide();
151
- }
152
- };
153
-
154
- if (document.visibilityState === "visible") {
155
- connect();
156
- }
157
-
158
- document.addEventListener("visibilitychange", handleVisibilityChange);
159
-
160
- return () => {
161
- disconnect();
162
- document.removeEventListener("visibilitychange", handleVisibilityChange);
163
- };
164
- }
165
- }, [link, onVisible, onHide, received]);
166
-
167
- const remove = useCallback(
168
- (notification: Notification) => {
169
- setNotifications((oldNotifications) => [...oldNotifications.filter((n) => !isEqual(n, notification))]);
170
- },
171
- [setNotifications]
172
- );
173
-
174
- const clear = useCallback(() => {
175
- setNotifications([]);
176
- }, [setNotifications]);
177
-
178
- return {
179
- notifications,
180
- remove,
181
- clear,
182
- };
183
- };
@@ -1,345 +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 { setIndexLink } from "./tests/indexLinks";
25
- import createInfiniteCachingClient from "./tests/createInfiniteCachingClient";
26
- import {
27
- Namespace,
28
- Permission,
29
- PermissionCollection,
30
- Repository,
31
- RepositoryRole,
32
- RepositoryRoleCollection,
33
- RepositoryVerbs,
34
- } from "@scm-manager/ui-types";
35
- import fetchMock from "fetch-mock-jest";
36
- import { renderHook } from "@testing-library/react-hooks";
37
- import createWrapper from "./tests/createWrapper";
38
- import {
39
- useAvailablePermissions,
40
- useCreatePermission,
41
- useDeletePermission,
42
- usePermissions,
43
- useRepositoryVerbs,
44
- useUpdatePermission,
45
- } from "./permissions";
46
- import { act } from "react-test-renderer";
47
-
48
- describe("permission hooks test", () => {
49
- const readRole: RepositoryRole = {
50
- name: "READ",
51
- verbs: ["read", "pull"],
52
- _links: {},
53
- };
54
-
55
- const roleCollection: RepositoryRoleCollection = {
56
- _embedded: {
57
- repositoryRoles: [readRole],
58
- },
59
- _links: {},
60
- page: 1,
61
- pageTotal: 1,
62
- };
63
-
64
- const verbCollection: RepositoryVerbs = {
65
- verbs: ["read", "pull"],
66
- _links: {},
67
- };
68
-
69
- const readPermission: Permission = {
70
- name: "trillian",
71
- role: "READ",
72
- verbs: [],
73
- groupPermission: false,
74
- _links: {
75
- update: {
76
- href: "/p/trillian",
77
- },
78
- },
79
- };
80
-
81
- const writePermission: Permission = {
82
- name: "dent",
83
- role: "WRITE",
84
- verbs: [],
85
- groupPermission: false,
86
- _links: {
87
- delete: {
88
- href: "/p/dent",
89
- },
90
- },
91
- };
92
-
93
- const permissionsRead: PermissionCollection = {
94
- _embedded: {
95
- permissions: [readPermission],
96
- },
97
- _links: {},
98
- };
99
-
100
- const permissionsWrite: PermissionCollection = {
101
- _embedded: {
102
- permissions: [writePermission],
103
- },
104
- _links: {},
105
- };
106
-
107
- const namespace: Namespace = {
108
- namespace: "spaceships",
109
- _links: {
110
- permissions: {
111
- href: "/ns/spaceships/permissions",
112
- },
113
- },
114
- };
115
-
116
- const repository: Repository = {
117
- namespace: "spaceships",
118
- name: "heart-of-gold",
119
- type: "git",
120
- _links: {
121
- permissions: {
122
- href: "/r/heart-of-gold/permissions",
123
- },
124
- },
125
- };
126
-
127
- const queryClient = createInfiniteCachingClient();
128
-
129
- beforeEach(() => {
130
- queryClient.clear();
131
- fetchMock.reset();
132
- });
133
-
134
- describe("useRepositoryVerbs tests", () => {
135
- it("should return available verbs", async () => {
136
- setIndexLink(queryClient, "repositoryVerbs", "/verbs");
137
- fetchMock.get("/api/v2/verbs", verbCollection);
138
-
139
- const { result, waitFor } = renderHook(() => useRepositoryVerbs(), {
140
- wrapper: createWrapper(undefined, queryClient),
141
- });
142
- await waitFor(() => {
143
- return !!result.current.data;
144
- });
145
- expect(result.current.data).toEqual(verbCollection);
146
- });
147
- });
148
-
149
- describe("useAvailablePermissions tests", () => {
150
- it("should return available roles and verbs", async () => {
151
- queryClient.setQueryData("index", {
152
- version: "x.y.z",
153
- _links: {
154
- repositoryRoles: {
155
- href: "/roles",
156
- },
157
- repositoryVerbs: {
158
- href: "/verbs",
159
- },
160
- },
161
- });
162
- fetchMock.get("/api/v2/roles", roleCollection);
163
- fetchMock.get("/api/v2/verbs", verbCollection);
164
-
165
- const { result, waitFor } = renderHook(() => useAvailablePermissions(), {
166
- wrapper: createWrapper(undefined, queryClient),
167
- });
168
- await waitFor(() => {
169
- return !!result.current.data;
170
- });
171
- expect(result.current.data?.repositoryRoles).toEqual(roleCollection._embedded?.repositoryRoles);
172
- expect(result.current.data?.repositoryVerbs).toEqual(verbCollection.verbs);
173
- });
174
- });
175
-
176
- describe("usePermissions tests", () => {
177
- const fetchPermissions = async (namespaceOrRepository: Namespace | Repository) => {
178
- const { result, waitFor } = renderHook(() => usePermissions(namespaceOrRepository), {
179
- wrapper: createWrapper(undefined, queryClient),
180
- });
181
- await waitFor(() => {
182
- return !!result.current.data;
183
- });
184
- return result.current.data;
185
- };
186
-
187
- it("should return permissions from namespace", async () => {
188
- fetchMock.getOnce("/api/v2/ns/spaceships/permissions", permissionsRead);
189
- const data = await fetchPermissions(namespace);
190
- expect(data).toEqual(permissionsRead);
191
- });
192
-
193
- it("should cache permissions for namespace", async () => {
194
- fetchMock.getOnce("/api/v2/ns/spaceships/permissions", permissionsRead);
195
- await fetchPermissions(namespace);
196
- const data = queryClient.getQueryData(["namespace", "spaceships", "permissions"]);
197
- expect(data).toEqual(permissionsRead);
198
- });
199
-
200
- it("should return permissions from repository", async () => {
201
- fetchMock.getOnce("/api/v2/r/heart-of-gold/permissions", permissionsWrite);
202
- const data = await fetchPermissions(repository);
203
- expect(data).toEqual(permissionsWrite);
204
- });
205
-
206
- it("should cache permissions for repository", async () => {
207
- fetchMock.getOnce("/api/v2/r/heart-of-gold/permissions", permissionsWrite);
208
- await fetchPermissions(repository);
209
- const data = queryClient.getQueryData(["repository", "spaceships", "heart-of-gold", "permissions"]);
210
- expect(data).toEqual(permissionsWrite);
211
- });
212
- });
213
-
214
- describe("useCreatePermission tests", () => {
215
- const createAndFetch = async () => {
216
- fetchMock.postOnce("/api/v2/ns/spaceships/permissions", {
217
- status: 201,
218
- headers: {
219
- Location: "/ns/spaceships/permissions/42",
220
- },
221
- });
222
-
223
- fetchMock.getOnce("/api/v2/ns/spaceships/permissions/42", readPermission);
224
-
225
- const { result, waitForNextUpdate } = renderHook(() => useCreatePermission(namespace), {
226
- wrapper: createWrapper(undefined, queryClient),
227
- });
228
-
229
- await act(() => {
230
- const { create } = result.current;
231
- create(readPermission);
232
- return waitForNextUpdate();
233
- });
234
- return result.current;
235
- };
236
-
237
- it("should create permission", async () => {
238
- const data = await createAndFetch();
239
- expect(data.permission).toEqual(readPermission);
240
- });
241
-
242
- it("should fail without location header", async () => {
243
- fetchMock.postOnce("/api/v2/ns/spaceships/permissions", {
244
- status: 201,
245
- });
246
-
247
- const { result, waitForNextUpdate } = renderHook(() => useCreatePermission(namespace), {
248
- wrapper: createWrapper(undefined, queryClient),
249
- });
250
-
251
- await act(() => {
252
- const { create } = result.current;
253
- create(readPermission);
254
- return waitForNextUpdate();
255
- });
256
-
257
- expect(result.current.error).toBeDefined();
258
- });
259
-
260
- it("should invalidate namespace cache", async () => {
261
- const key = ["namespace", "spaceships", "permissions"];
262
- queryClient.setQueryData(key, permissionsRead);
263
- await createAndFetch();
264
-
265
- const state = queryClient.getQueryState(key);
266
- expect(state?.isInvalidated).toBe(true);
267
- });
268
- });
269
-
270
- describe("useDeletePermission tests", () => {
271
- const deletePermission = async () => {
272
- fetchMock.deleteOnce("/api/v2/p/dent", {
273
- status: 204,
274
- });
275
-
276
- const { result, waitForNextUpdate } = renderHook(() => useDeletePermission(repository), {
277
- wrapper: createWrapper(undefined, queryClient),
278
- });
279
-
280
- await act(() => {
281
- const { remove } = result.current;
282
- remove(writePermission);
283
- return waitForNextUpdate();
284
- });
285
-
286
- return result.current;
287
- };
288
-
289
- const shouldInvalidateQuery = async (queryKey: string[], data: unknown) => {
290
- queryClient.setQueryData(queryKey, data);
291
- await deletePermission();
292
-
293
- const queryState = queryClient.getQueryState(queryKey);
294
- expect(queryState?.isInvalidated).toBe(true);
295
- };
296
-
297
- it("should delete permission", async () => {
298
- const { isDeleted } = await deletePermission();
299
-
300
- expect(isDeleted).toBe(true);
301
- });
302
-
303
- it("should invalidate permission cache", async () => {
304
- await shouldInvalidateQuery(["repository", "spaceships", "heart-of-gold", "permissions"], permissionsWrite);
305
- });
306
- });
307
-
308
- describe("useUpdatePermission tests", () => {
309
- const updatePermission = async () => {
310
- fetchMock.putOnce("/api/v2/p/trillian", {
311
- status: 204,
312
- });
313
-
314
- const { result, waitForNextUpdate } = renderHook(() => useUpdatePermission(repository), {
315
- wrapper: createWrapper(undefined, queryClient),
316
- });
317
-
318
- await act(() => {
319
- const { update } = result.current;
320
- update(readPermission);
321
- return waitForNextUpdate();
322
- });
323
-
324
- return result.current;
325
- };
326
-
327
- const shouldInvalidateQuery = async (queryKey: string[], data: unknown) => {
328
- queryClient.setQueryData(queryKey, data);
329
- await updatePermission();
330
-
331
- const queryState = queryClient.getQueryState(queryKey);
332
- expect(queryState?.isInvalidated).toBe(true);
333
- };
334
-
335
- it("should update permission", async () => {
336
- const { isUpdated } = await updatePermission();
337
-
338
- expect(isUpdated).toBe(true);
339
- });
340
-
341
- it("should invalidate permission cache", async () => {
342
- await shouldInvalidateQuery(["repository", "spaceships", "heart-of-gold", "permissions"], permissionsRead);
343
- });
344
- });
345
- });