@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
package/src/login.test.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 fetchMock from "fetch-mock-jest";
26
- import { renderHook } from "@testing-library/react-hooks";
27
- import { Me } from "@scm-manager/ui-types";
28
- import createWrapper from "./tests/createWrapper";
29
- import { useLogin, useLogout, useMe, useRequiredMe, useSubject } from "./login";
30
- import { setEmptyIndex, setIndexLink } from "./tests/indexLinks";
31
- import createInfiniteCachingClient from "./tests/createInfiniteCachingClient";
32
- import { LegacyContext } from "./LegacyContext";
33
- import { act } from "react-test-renderer";
34
-
35
- describe("Test login hooks", () => {
36
- const tricia: Me = {
37
- name: "tricia",
38
- displayName: "Tricia",
39
- groups: [],
40
- _links: {}
41
- };
42
-
43
- describe("useMe tests", () => {
44
- fetchMock.get("/api/v2/me", {
45
- name: "tricia",
46
- displayName: "Tricia",
47
- groups: [],
48
- _links: {}
49
- });
50
-
51
- it("should return me", async () => {
52
- const queryClient = createInfiniteCachingClient();
53
- setIndexLink(queryClient, "me", "/me");
54
-
55
- const { result, waitFor } = renderHook(() => useMe(), { wrapper: createWrapper(undefined, queryClient) });
56
- await waitFor(() => {
57
- return !!result.current.data;
58
- });
59
- expect(result.current?.data?.name).toEqual("tricia");
60
- });
61
-
62
- it("should call onMeFetched of LegacyContext", async () => {
63
- const queryClient = createInfiniteCachingClient();
64
- setIndexLink(queryClient, "me", "/me");
65
-
66
- let me: Me;
67
- const context: LegacyContext = {
68
- onMeFetched: fetchedMe => {
69
- me = fetchedMe;
70
- },
71
- initialize: () => null
72
- };
73
-
74
- const { result, waitFor } = renderHook(() => useMe(), { wrapper: createWrapper(context, queryClient) });
75
- await waitFor(() => {
76
- return !!result.current.data;
77
- });
78
- expect(me!.name).toEqual("tricia");
79
- });
80
-
81
- it("should return nothing without me link", () => {
82
- const queryClient = createInfiniteCachingClient();
83
- setEmptyIndex(queryClient);
84
-
85
- const { result } = renderHook(() => useMe(), { wrapper: createWrapper(undefined, queryClient) });
86
-
87
- expect(result.current.isLoading).toBe(false);
88
- expect(result.current?.data).toBeFalsy();
89
- expect(result.current?.error).toBeFalsy();
90
- });
91
- });
92
-
93
- describe("useRequiredMe tests", () => {
94
- it("should return me", async () => {
95
- const queryClient = createInfiniteCachingClient();
96
- queryClient.setQueryData("me", tricia);
97
- setIndexLink(queryClient, "me", "/me");
98
- const { result, waitFor } = renderHook(() => useRequiredMe(), { wrapper: createWrapper(undefined, queryClient) });
99
- await waitFor(() => {
100
- return !!result.current;
101
- });
102
- expect(result.current?.name).toBe("tricia");
103
- });
104
-
105
- it("should throw an error if me is not available", () => {
106
- const queryClient = createInfiniteCachingClient();
107
- setEmptyIndex(queryClient);
108
-
109
- const { result } = renderHook(() => useRequiredMe(), { wrapper: createWrapper(undefined, queryClient) });
110
-
111
- expect(result.error).toBeDefined();
112
- });
113
- });
114
-
115
- describe("useSubject tests", () => {
116
- it("should return authenticated subject", () => {
117
- const queryClient = createInfiniteCachingClient();
118
- setEmptyIndex(queryClient);
119
- queryClient.setQueryData("me", tricia);
120
- const { result } = renderHook(() => useSubject(), { wrapper: createWrapper(undefined, queryClient) });
121
-
122
- expect(result.current.isAuthenticated).toBe(true);
123
- expect(result.current.isAnonymous).toBe(false);
124
- expect(result.current.me).toEqual(tricia);
125
- });
126
-
127
- it("should return anonymous subject", () => {
128
- const queryClient = createInfiniteCachingClient();
129
- setIndexLink(queryClient, "login", "/login");
130
- queryClient.setQueryData("me", {
131
- name: "_anonymous",
132
- displayName: "Anonymous",
133
- groups: [],
134
- _links: {}
135
- });
136
- const { result } = renderHook(() => useSubject(), { wrapper: createWrapper(undefined, queryClient) });
137
-
138
- expect(result.current.isAuthenticated).toBe(false);
139
- expect(result.current.isAnonymous).toBe(true);
140
- });
141
-
142
- it("should return unauthenticated subject", () => {
143
- const queryClient = createInfiniteCachingClient();
144
- setIndexLink(queryClient, "login", "/login");
145
- const { result } = renderHook(() => useSubject(), { wrapper: createWrapper(undefined, queryClient) });
146
-
147
- expect(result.current.isAuthenticated).toBe(false);
148
- expect(result.current.isAnonymous).toBe(false);
149
- });
150
- });
151
-
152
- describe("useLogin tests", () => {
153
- it("should login", async () => {
154
- const queryClient = createInfiniteCachingClient();
155
- setIndexLink(queryClient, "login", "/login");
156
-
157
- fetchMock.post("/api/v2/login", "", {
158
- body: {
159
- cookie: true,
160
- grant_type: "password",
161
- username: "tricia",
162
- password: "hitchhikersSecret!"
163
- }
164
- });
165
-
166
- // required because we invalidate the whole cache and react-query refetches the index
167
- fetchMock.get("/api/v2/", {
168
- version: "x.y.z",
169
- _links: {
170
- login: {
171
- href: "/second/login"
172
- }
173
- }
174
- });
175
-
176
- const { result, waitForNextUpdate } = renderHook(() => useLogin(), {
177
- wrapper: createWrapper(undefined, queryClient)
178
- });
179
- const { login } = result.current;
180
- expect(login).toBeDefined();
181
-
182
- await act(() => {
183
- if (login) {
184
- login("tricia", "hitchhikersSecret!");
185
- }
186
- return waitForNextUpdate();
187
- });
188
-
189
- expect(result.current.error).toBeFalsy();
190
- });
191
-
192
- it("should not return login, if authenticated", () => {
193
- const queryClient = createInfiniteCachingClient();
194
- setEmptyIndex(queryClient);
195
- queryClient.setQueryData("me", tricia);
196
-
197
- const { result } = renderHook(() => useLogin(), {
198
- wrapper: createWrapper(undefined, queryClient)
199
- });
200
-
201
- expect(result.current.login).toBeUndefined();
202
- });
203
- });
204
-
205
- describe("useLogout tests", () => {
206
- it("should call logout", async () => {
207
- const queryClient = createInfiniteCachingClient();
208
- setIndexLink(queryClient, "logout", "/logout");
209
-
210
- fetchMock.deleteOnce("/api/v2/logout", {});
211
-
212
- const { result, waitForNextUpdate } = renderHook(() => useLogout(), {
213
- wrapper: createWrapper(undefined, queryClient)
214
- });
215
- const { logout } = result.current;
216
- expect(logout).toBeDefined();
217
-
218
- await act(() => {
219
- if (logout) {
220
- logout();
221
- }
222
- return waitForNextUpdate();
223
- });
224
-
225
- expect(result.current.error).toBeFalsy();
226
- });
227
-
228
- it("should not return logout without link", () => {
229
- const queryClient = createInfiniteCachingClient();
230
- setEmptyIndex(queryClient);
231
-
232
- const { result } = renderHook(() => useLogout(), {
233
- wrapper: createWrapper(undefined, queryClient)
234
- });
235
-
236
- const { logout } = result.current;
237
- expect(logout).toBeUndefined();
238
- });
239
- });
240
- });
package/src/login.ts DELETED
@@ -1,128 +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 { Me } from "@scm-manager/ui-types";
26
- import { useMutation, useQuery } from "react-query";
27
- import { apiClient } from "./apiclient";
28
- import { ApiResult, useIndexLink } from "./base";
29
- import { useLegacyContext } from "./LegacyContext";
30
- import { useReset } from "./reset";
31
- import { useCallback } from "react";
32
-
33
- export const useMe = (): ApiResult<Me> => {
34
- const legacy = useLegacyContext();
35
- const link = useIndexLink("me");
36
- return useQuery<Me, Error>("me", () => apiClient.get(link!).then(response => response.json()), {
37
- enabled: !!link,
38
- onSuccess: me => {
39
- if (legacy.onMeFetched) {
40
- legacy.onMeFetched(me);
41
- }
42
- }
43
- });
44
- };
45
-
46
- export const useRequiredMe = () => {
47
- const { data } = useMe();
48
- if (!data) {
49
- throw new Error("Could not find 'me' in cache");
50
- }
51
- return data;
52
- };
53
-
54
- export const useSubject = () => {
55
- const link = useIndexLink("login");
56
- const { isLoading, error, data: me } = useMe();
57
- const isAnonymous = me?.name === "_anonymous";
58
- const isAuthenticated = !isAnonymous && !!me && !link;
59
- return {
60
- isAuthenticated,
61
- isAnonymous,
62
- isLoading,
63
- error,
64
- me
65
- };
66
- };
67
-
68
- type Credentials = {
69
- username: string;
70
- password: string;
71
- cookie: boolean;
72
- grant_type: string;
73
- };
74
-
75
- export const useLogin = () => {
76
- const link = useIndexLink("login");
77
- const reset = useReset();
78
- const { mutate, isLoading, error } = useMutation<unknown, Error, Credentials>(
79
- credentials => apiClient.post(link!, credentials),
80
- {
81
- onSuccess: reset
82
- }
83
- );
84
-
85
- const login = (username: string, password: string) => {
86
- // grant_type is specified by the oauth standard with the underscore
87
- // so we stick with it, even if eslint does not like it.
88
- // eslint-disable-next-line @typescript-eslint/camelcase
89
- mutate({ cookie: true, grant_type: "password", username, password });
90
- };
91
-
92
- return {
93
- login: link ? login : undefined,
94
- isLoading,
95
- error
96
- };
97
- };
98
-
99
- type LogoutResponse = {
100
- logoutRedirect?: string;
101
- };
102
-
103
- export const useLogout = () => {
104
- const link = useIndexLink("logout");
105
- const reset = useReset();
106
-
107
- const { mutate, isLoading, error, data } = useMutation<LogoutResponse, Error, unknown>(
108
- () => apiClient.delete(link!).then(r => (r.status === 200 ? r.json() : {})),
109
- {
110
- onSuccess: response => {
111
- if (response?.logoutRedirect) {
112
- window.location.assign(response.logoutRedirect);
113
- }
114
- return reset();
115
- }
116
- }
117
- );
118
-
119
- const logout = useCallback(() => {
120
- mutate({});
121
- }, [mutate]);
122
-
123
- return {
124
- logout: link && !data ? logout : undefined,
125
- isLoading,
126
- error
127
- };
128
- };
package/src/loginInfo.ts DELETED
@@ -1,43 +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, useIndexLink } from "./base";
25
- import { useQuery } from "react-query";
26
- import { LoginInfo } from "@scm-manager/ui-types";
27
-
28
- export const useLoginInfo = (disabled = false): ApiResult<LoginInfo> => {
29
- const loginInfoLink = useIndexLink("loginInfo");
30
- const { error, isLoading, data } = useQuery<LoginInfo, Error>(
31
- ["loginInfo"],
32
- () => fetch(loginInfoLink!).then(response => response.json()),
33
- {
34
- enabled: !disabled && !!loginInfoLink,
35
- refetchOnWindowFocus: false
36
- }
37
- );
38
- return {
39
- data,
40
- error,
41
- isLoading
42
- };
43
- };
@@ -1,32 +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 { Link } from "@scm-manager/ui-types";
25
- import { useIndexLinks } from "./base";
26
- import { useSuggestions } from "./suggestions";
27
-
28
- export const useNamespaceSuggestions = () => {
29
- const indexLinks = useIndexLinks();
30
- const autocompleteLink = (indexLinks.autocomplete as Link[]).find((i) => i.name === "namespaces");
31
- return useSuggestions(autocompleteLink?.href);
32
- };
@@ -1,95 +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 createInfiniteCachingClient from "./tests/createInfiniteCachingClient";
25
- import { setIndexLink } from "./tests/indexLinks";
26
- import fetchMock from "fetch-mock-jest";
27
- import { renderHook } from "@testing-library/react-hooks";
28
- import { useNamespace, useNamespaces, useNamespaceStrategies } from "./namespaces";
29
- import createWrapper from "./tests/createWrapper";
30
-
31
- describe("Test namespace hooks", () => {
32
- describe("useNamespaces test", () => {
33
- it("should return namespaces", async () => {
34
- const queryClient = createInfiniteCachingClient();
35
- setIndexLink(queryClient, "namespaces", "/namespaces");
36
- fetchMock.get("/api/v2/namespaces", {
37
- _embedded: {
38
- namespaces: [
39
- {
40
- namespace: "spaceships",
41
- _links: {},
42
- },
43
- ],
44
- },
45
- });
46
-
47
- const { result, waitFor } = renderHook(() => useNamespaces(), {
48
- wrapper: createWrapper(undefined, queryClient),
49
- });
50
- await waitFor(() => {
51
- return !!result.current.data;
52
- });
53
- expect(result.current?.data?._embedded.namespaces[0].namespace).toBe("spaceships");
54
- });
55
- });
56
-
57
- describe("useNamespaceStrategies tests", () => {
58
- it("should return namespaces strategies", async () => {
59
- const queryClient = createInfiniteCachingClient();
60
- setIndexLink(queryClient, "namespaceStrategies", "/ns");
61
- fetchMock.get("/api/v2/ns", {
62
- current: "awesome",
63
- available: [],
64
- _links: {},
65
- });
66
-
67
- const { result, waitFor } = renderHook(() => useNamespaceStrategies(), {
68
- wrapper: createWrapper(undefined, queryClient),
69
- });
70
- await waitFor(() => {
71
- return !!result.current.data;
72
- });
73
- expect(result.current?.data?.current).toEqual("awesome");
74
- });
75
- });
76
-
77
- describe("useNamespace tests", () => {
78
- it("should return namespace", async () => {
79
- const queryClient = createInfiniteCachingClient();
80
- setIndexLink(queryClient, "namespaces", "/ns");
81
- fetchMock.get("/api/v2/ns/awesome", {
82
- namespace: "awesome",
83
- _links: {},
84
- });
85
-
86
- const { result, waitFor } = renderHook(() => useNamespace("awesome"), {
87
- wrapper: createWrapper(undefined, queryClient),
88
- });
89
- await waitFor(() => {
90
- return !!result.current.data;
91
- });
92
- expect(result.current?.data?.namespace).toEqual("awesome");
93
- });
94
- });
95
- });
package/src/namespaces.ts DELETED
@@ -1,43 +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, useIndexJsonResource, useRequiredIndexLink } from "./base";
25
- import { Namespace, NamespaceCollection, NamespaceStrategies } from "@scm-manager/ui-types";
26
- import { useQuery } from "react-query";
27
- import { apiClient } from "./apiclient";
28
- import { concat } from "./urls";
29
-
30
- export const useNamespaces = () => {
31
- return useIndexJsonResource<NamespaceCollection>("namespaces");
32
- };
33
-
34
- export const useNamespace = (name: string): ApiResult<Namespace> => {
35
- const namespacesLink = useRequiredIndexLink("namespaces");
36
- return useQuery<Namespace, Error>(["namespace", name], () =>
37
- apiClient.get(concat(namespacesLink, name)).then((response) => response.json())
38
- );
39
- };
40
-
41
- export const useNamespaceStrategies = () => {
42
- return useIndexJsonResource<NamespaceStrategies>("namespaceStrategies");
43
- };