@scm-manager/ui-api 2.33.1-20220411-113741 → 2.34.0
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/package.json +2 -2
- package/src/ApiProvider.test.tsx +2 -2
- package/src/ApiProvider.tsx +3 -3
- package/src/LegacyContext.test.tsx +1 -1
- package/src/LegacyContext.tsx +2 -2
- package/src/alerts.ts +8 -8
- package/src/apiclient.test.ts +12 -12
- package/src/apiclient.ts +30 -17
- package/src/base.test.ts +34 -34
- package/src/branches.test.ts +20 -20
- package/src/branches.ts +23 -23
- package/src/changesets.test.ts +18 -18
- package/src/compare.ts +4 -4
- package/src/config.test.ts +7 -7
- package/src/config.ts +5 -5
- package/src/import.ts +8 -8
- package/src/login.test.ts +14 -14
- package/src/login.ts +11 -11
- package/src/loginInfo.ts +3 -3
- package/src/plugins.ts +40 -42
- package/src/repositories.test.ts +48 -48
- package/src/repositories.ts +33 -33
- package/src/sources.ts +1 -1
- package/src/usePluginCenterAuthInfo.ts +4 -4
package/src/branches.ts
CHANGED
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
BranchDetailsCollection,
|
|
30
30
|
Link,
|
|
31
31
|
NamespaceAndName,
|
|
32
|
-
Repository
|
|
32
|
+
Repository
|
|
33
33
|
} from "@scm-manager/ui-types";
|
|
34
34
|
import { requiredLink } from "./links";
|
|
35
35
|
import { useInfiniteQuery, useMutation, useQuery, useQueryClient } from "react-query";
|
|
@@ -44,11 +44,11 @@ export const useBranches = (repository: Repository): ApiResult<BranchCollection>
|
|
|
44
44
|
const link = requiredLink(repository, "branches");
|
|
45
45
|
return useQuery<BranchCollection, Error>(
|
|
46
46
|
repoQueryKey(repository, "branches"),
|
|
47
|
-
() => apiClient.get(link).then(
|
|
47
|
+
() => apiClient.get(link).then(response => response.json()),
|
|
48
48
|
{
|
|
49
49
|
onSuccess: () => {
|
|
50
50
|
return queryClient.invalidateQueries(branchDetailsQueryKey(repository));
|
|
51
|
-
}
|
|
51
|
+
}
|
|
52
52
|
}
|
|
53
53
|
// we do not populate the cache for a single branch,
|
|
54
54
|
// because we have no pagination for branches and if we have a lot of them
|
|
@@ -59,7 +59,7 @@ export const useBranches = (repository: Repository): ApiResult<BranchCollection>
|
|
|
59
59
|
export const useBranch = (repository: Repository, name: string): ApiResultWithFetching<Branch> => {
|
|
60
60
|
const link = requiredLink(repository, "branches");
|
|
61
61
|
return useQuery<Branch, Error>(branchQueryKey(repository, name), () =>
|
|
62
|
-
apiClient.get(concat(link, encodeURIComponent(name))).then(
|
|
62
|
+
apiClient.get(concat(link, encodeURIComponent(name))).then(response => response.json())
|
|
63
63
|
);
|
|
64
64
|
};
|
|
65
65
|
|
|
@@ -101,8 +101,8 @@ export const useBranchDetailsCollection = (repository: Repository, branches: Bra
|
|
|
101
101
|
>(
|
|
102
102
|
branchDetailsQueryKey(repository),
|
|
103
103
|
({ pageParam = 0 }) => {
|
|
104
|
-
const encodedBranches = chunks[pageParam]?.map(
|
|
105
|
-
return apiClient.get(concat(link, `?branches=${encodedBranches}`)).then(
|
|
104
|
+
const encodedBranches = chunks[pageParam]?.map(b => encodeURIComponent(b.name)).join("&branches=");
|
|
105
|
+
return apiClient.get(concat(link, `?branches=${encodedBranches}`)).then(response => response.json());
|
|
106
106
|
},
|
|
107
107
|
{
|
|
108
108
|
getNextPageParam: (lastPage, allPages) => {
|
|
@@ -111,12 +111,12 @@ export const useBranchDetailsCollection = (repository: Repository, branches: Bra
|
|
|
111
111
|
}
|
|
112
112
|
return allPages.length;
|
|
113
113
|
},
|
|
114
|
-
onSuccess:
|
|
114
|
+
onSuccess: newData => {
|
|
115
115
|
newData.pages
|
|
116
|
-
.flatMap(
|
|
117
|
-
.filter(
|
|
118
|
-
.forEach(
|
|
119
|
-
}
|
|
116
|
+
.flatMap(d => d._embedded?.branchDetails)
|
|
117
|
+
.filter(d => !!d)
|
|
118
|
+
.forEach(d => queryClient.setQueryData(branchDetailsQueryKey(repository, d!.branchName), () => d));
|
|
119
|
+
}
|
|
120
120
|
}
|
|
121
121
|
);
|
|
122
122
|
|
|
@@ -125,30 +125,30 @@ export const useBranchDetailsCollection = (repository: Repository, branches: Bra
|
|
|
125
125
|
}, [data, fetchNextPage]);
|
|
126
126
|
|
|
127
127
|
return {
|
|
128
|
-
data: data?.pages?.map(
|
|
128
|
+
data: data?.pages?.map(d => d._embedded?.branchDetails).flat(1),
|
|
129
129
|
isLoading,
|
|
130
|
-
error
|
|
130
|
+
error
|
|
131
131
|
};
|
|
132
132
|
};
|
|
133
133
|
|
|
134
134
|
export const useBranchDetails = (repository: Repository, branch: Branch) => {
|
|
135
135
|
const link = (branch._links.details as Link).href;
|
|
136
136
|
const queryKey = branchDetailsQueryKey(repository, branch.name);
|
|
137
|
-
return useQuery<BranchDetails, Error>(queryKey, () => apiClient.get(link).then(
|
|
137
|
+
return useQuery<BranchDetails, Error>(queryKey, () => apiClient.get(link).then(response => response.json()));
|
|
138
138
|
};
|
|
139
139
|
|
|
140
140
|
const createBranch = (link: string) => {
|
|
141
141
|
return (branch: BranchCreation) => {
|
|
142
142
|
return apiClient
|
|
143
143
|
.post(link, branch, "application/vnd.scmm-branchRequest+json;v=2")
|
|
144
|
-
.then(
|
|
144
|
+
.then(response => {
|
|
145
145
|
const location = response.headers.get("Location");
|
|
146
146
|
if (!location) {
|
|
147
147
|
throw new Error("Server does not return required Location header");
|
|
148
148
|
}
|
|
149
149
|
return apiClient.get(location);
|
|
150
150
|
})
|
|
151
|
-
.then(
|
|
151
|
+
.then(response => response.json());
|
|
152
152
|
};
|
|
153
153
|
};
|
|
154
154
|
|
|
@@ -156,23 +156,23 @@ export const useCreateBranch = (repository: Repository) => {
|
|
|
156
156
|
const queryClient = useQueryClient();
|
|
157
157
|
const link = requiredLink(repository, "branches");
|
|
158
158
|
const { mutate, isLoading, error, data } = useMutation<Branch, Error, BranchCreation>(createBranch(link), {
|
|
159
|
-
onSuccess: async
|
|
159
|
+
onSuccess: async branch => {
|
|
160
160
|
queryClient.setQueryData(branchQueryKey(repository, branch), branch);
|
|
161
161
|
await queryClient.invalidateQueries(repoQueryKey(repository, "branches"));
|
|
162
|
-
}
|
|
162
|
+
}
|
|
163
163
|
});
|
|
164
164
|
return {
|
|
165
165
|
create: (branch: BranchCreation) => mutate(branch),
|
|
166
166
|
isLoading,
|
|
167
167
|
error,
|
|
168
|
-
branch: data
|
|
168
|
+
branch: data
|
|
169
169
|
};
|
|
170
170
|
};
|
|
171
171
|
|
|
172
172
|
export const useDeleteBranch = (repository: Repository) => {
|
|
173
173
|
const queryClient = useQueryClient();
|
|
174
174
|
const { mutate, isLoading, error, data } = useMutation<unknown, Error, Branch>(
|
|
175
|
-
|
|
175
|
+
branch => {
|
|
176
176
|
const deleteUrl = (branch._links.delete as Link).href;
|
|
177
177
|
return apiClient.delete(deleteUrl);
|
|
178
178
|
},
|
|
@@ -180,14 +180,14 @@ export const useDeleteBranch = (repository: Repository) => {
|
|
|
180
180
|
onSuccess: async (_, branch) => {
|
|
181
181
|
queryClient.removeQueries(branchQueryKey(repository, branch));
|
|
182
182
|
await queryClient.invalidateQueries(repoQueryKey(repository, "branches"));
|
|
183
|
-
}
|
|
183
|
+
}
|
|
184
184
|
}
|
|
185
185
|
);
|
|
186
186
|
return {
|
|
187
187
|
remove: (branch: Branch) => mutate(branch),
|
|
188
188
|
isLoading,
|
|
189
189
|
error,
|
|
190
|
-
isDeleted: !!data
|
|
190
|
+
isDeleted: !!data
|
|
191
191
|
};
|
|
192
192
|
};
|
|
193
193
|
|
|
@@ -196,6 +196,6 @@ type DefaultBranch = { defaultBranch: string };
|
|
|
196
196
|
export const useDefaultBranch = (repository: Repository): ApiResult<DefaultBranch> => {
|
|
197
197
|
const link = requiredLink(repository, "defaultBranch");
|
|
198
198
|
return useQuery<DefaultBranch, Error>(branchQueryKey(repository, "__default-branch"), () =>
|
|
199
|
-
apiClient.get(link).then(
|
|
199
|
+
apiClient.get(link).then(response => response.json())
|
|
200
200
|
);
|
|
201
201
|
};
|
package/src/changesets.test.ts
CHANGED
|
@@ -35,9 +35,9 @@ describe("Test changeset hooks", () => {
|
|
|
35
35
|
type: "hg",
|
|
36
36
|
_links: {
|
|
37
37
|
changesets: {
|
|
38
|
-
href: "/r/c"
|
|
39
|
-
}
|
|
40
|
-
}
|
|
38
|
+
href: "/r/c"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
const develop: Branch = {
|
|
@@ -46,9 +46,9 @@ describe("Test changeset hooks", () => {
|
|
|
46
46
|
lastCommitter: { name: "trillian" },
|
|
47
47
|
_links: {
|
|
48
48
|
history: {
|
|
49
|
-
href: "/r/b/c"
|
|
50
|
-
}
|
|
51
|
-
}
|
|
49
|
+
href: "/r/b/c"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
52
|
};
|
|
53
53
|
|
|
54
54
|
const changeset: Changeset = {
|
|
@@ -56,19 +56,19 @@ describe("Test changeset hooks", () => {
|
|
|
56
56
|
description: "Awesome change",
|
|
57
57
|
date: new Date(),
|
|
58
58
|
author: {
|
|
59
|
-
name: "Arthur Dent"
|
|
59
|
+
name: "Arthur Dent"
|
|
60
60
|
},
|
|
61
61
|
_embedded: {},
|
|
62
|
-
_links: {}
|
|
62
|
+
_links: {}
|
|
63
63
|
};
|
|
64
64
|
|
|
65
65
|
const changesets: ChangesetCollection = {
|
|
66
66
|
page: 1,
|
|
67
67
|
pageTotal: 1,
|
|
68
68
|
_embedded: {
|
|
69
|
-
changesets: [changeset]
|
|
69
|
+
changesets: [changeset]
|
|
70
70
|
},
|
|
71
|
-
_links: {}
|
|
71
|
+
_links: {}
|
|
72
72
|
};
|
|
73
73
|
|
|
74
74
|
const expectChangesetCollection = (result?: ChangesetCollection) => {
|
|
@@ -86,7 +86,7 @@ describe("Test changeset hooks", () => {
|
|
|
86
86
|
const queryClient = createInfiniteCachingClient();
|
|
87
87
|
|
|
88
88
|
const { result, waitFor } = renderHook(() => useChangesets(repository), {
|
|
89
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
89
|
+
wrapper: createWrapper(undefined, queryClient)
|
|
90
90
|
});
|
|
91
91
|
|
|
92
92
|
await waitFor(() => {
|
|
@@ -99,14 +99,14 @@ describe("Test changeset hooks", () => {
|
|
|
99
99
|
it("should return changesets for page", async () => {
|
|
100
100
|
fetchMock.getOnce("/api/v2/r/c", changesets, {
|
|
101
101
|
query: {
|
|
102
|
-
page: 42
|
|
103
|
-
}
|
|
102
|
+
page: 42
|
|
103
|
+
}
|
|
104
104
|
});
|
|
105
105
|
|
|
106
106
|
const queryClient = createInfiniteCachingClient();
|
|
107
107
|
|
|
108
108
|
const { result, waitFor } = renderHook(() => useChangesets(repository, { page: 42 }), {
|
|
109
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
109
|
+
wrapper: createWrapper(undefined, queryClient)
|
|
110
110
|
});
|
|
111
111
|
|
|
112
112
|
await waitFor(() => {
|
|
@@ -122,7 +122,7 @@ describe("Test changeset hooks", () => {
|
|
|
122
122
|
const queryClient = createInfiniteCachingClient();
|
|
123
123
|
|
|
124
124
|
const { result, waitFor } = renderHook(() => useChangesets(repository, { branch: develop }), {
|
|
125
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
125
|
+
wrapper: createWrapper(undefined, queryClient)
|
|
126
126
|
});
|
|
127
127
|
|
|
128
128
|
await waitFor(() => {
|
|
@@ -138,7 +138,7 @@ describe("Test changeset hooks", () => {
|
|
|
138
138
|
const queryClient = createInfiniteCachingClient();
|
|
139
139
|
|
|
140
140
|
const { result, waitFor } = renderHook(() => useChangesets(repository), {
|
|
141
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
141
|
+
wrapper: createWrapper(undefined, queryClient)
|
|
142
142
|
});
|
|
143
143
|
|
|
144
144
|
await waitFor(() => {
|
|
@@ -150,7 +150,7 @@ describe("Test changeset hooks", () => {
|
|
|
150
150
|
"hitchhiker",
|
|
151
151
|
"heart-of-gold",
|
|
152
152
|
"changeset",
|
|
153
|
-
"42"
|
|
153
|
+
"42"
|
|
154
154
|
]);
|
|
155
155
|
|
|
156
156
|
expect(changeset?.id).toBe("42");
|
|
@@ -164,7 +164,7 @@ describe("Test changeset hooks", () => {
|
|
|
164
164
|
const queryClient = createInfiniteCachingClient();
|
|
165
165
|
|
|
166
166
|
const { result, waitFor } = renderHook(() => useChangeset(repository, "42"), {
|
|
167
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
167
|
+
wrapper: createWrapper(undefined, queryClient)
|
|
168
168
|
});
|
|
169
169
|
|
|
170
170
|
await waitFor(() => {
|
package/src/compare.ts
CHANGED
|
@@ -78,13 +78,13 @@ export const useIncomingChangesets = (
|
|
|
78
78
|
|
|
79
79
|
return useQuery<ChangesetCollection, Error>(
|
|
80
80
|
["repository", repository.namespace, repository.name, "compare", source, target, "changesets", request?.page || 0],
|
|
81
|
-
() => apiClient.get(link).then(
|
|
81
|
+
() => apiClient.get(link).then(response => response.json()),
|
|
82
82
|
{
|
|
83
|
-
onSuccess:
|
|
84
|
-
changesetCollection._embedded?.changesets.forEach(
|
|
83
|
+
onSuccess: changesetCollection => {
|
|
84
|
+
changesetCollection._embedded?.changesets.forEach(changeset => {
|
|
85
85
|
queryClient.setQueryData(changesetQueryKey(repository, changeset.id), changeset);
|
|
86
86
|
});
|
|
87
|
-
}
|
|
87
|
+
}
|
|
88
88
|
}
|
|
89
89
|
);
|
|
90
90
|
};
|
package/src/config.test.ts
CHANGED
|
@@ -63,9 +63,9 @@ describe("Test config hooks", () => {
|
|
|
63
63
|
skipFailedAuthenticators: false,
|
|
64
64
|
_links: {
|
|
65
65
|
update: {
|
|
66
|
-
href: "/config"
|
|
67
|
-
}
|
|
68
|
-
}
|
|
66
|
+
href: "/config"
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
69
|
};
|
|
70
70
|
|
|
71
71
|
afterEach(() => {
|
|
@@ -78,7 +78,7 @@ describe("Test config hooks", () => {
|
|
|
78
78
|
setIndexLink(queryClient, "config", "/config");
|
|
79
79
|
fetchMock.get("/api/v2/config", config);
|
|
80
80
|
const { result, waitFor } = renderHook(() => useConfig(), {
|
|
81
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
81
|
+
wrapper: createWrapper(undefined, queryClient)
|
|
82
82
|
});
|
|
83
83
|
await waitFor(() => !!result.current.data);
|
|
84
84
|
expect(result.current.data).toEqual(config);
|
|
@@ -92,15 +92,15 @@ describe("Test config hooks", () => {
|
|
|
92
92
|
|
|
93
93
|
const newConfig = {
|
|
94
94
|
...config,
|
|
95
|
-
baseUrl: "/hog"
|
|
95
|
+
baseUrl: "/hog"
|
|
96
96
|
};
|
|
97
97
|
|
|
98
98
|
fetchMock.putOnce("/api/v2/config", {
|
|
99
|
-
status: 200
|
|
99
|
+
status: 200
|
|
100
100
|
});
|
|
101
101
|
|
|
102
102
|
const { result, waitForNextUpdate } = renderHook(() => useUpdateConfig(), {
|
|
103
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
103
|
+
wrapper: createWrapper(undefined, queryClient)
|
|
104
104
|
});
|
|
105
105
|
|
|
106
106
|
await act(() => {
|
package/src/config.ts
CHANGED
|
@@ -30,15 +30,15 @@ import { requiredLink } from "./links";
|
|
|
30
30
|
|
|
31
31
|
export const useConfig = (): ApiResult<Config> => {
|
|
32
32
|
const indexLink = useIndexLink("config");
|
|
33
|
-
return useQuery<Config, Error>("config", () => apiClient.get(indexLink!).then(
|
|
34
|
-
enabled: !!indexLink
|
|
33
|
+
return useQuery<Config, Error>("config", () => apiClient.get(indexLink!).then(response => response.json()), {
|
|
34
|
+
enabled: !!indexLink
|
|
35
35
|
});
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
export const useUpdateConfig = () => {
|
|
39
39
|
const queryClient = useQueryClient();
|
|
40
40
|
const { mutate, isLoading, error, data, reset } = useMutation<unknown, Error, Config>(
|
|
41
|
-
|
|
41
|
+
config => {
|
|
42
42
|
const updateUrl = requiredLink(config, "update");
|
|
43
43
|
return apiClient.put(updateUrl, config, "application/vnd.scmm-config+json;v=2");
|
|
44
44
|
},
|
|
@@ -47,7 +47,7 @@ export const useUpdateConfig = () => {
|
|
|
47
47
|
await queryClient.invalidateQueries("config");
|
|
48
48
|
await queryClient.invalidateQueries("index");
|
|
49
49
|
await queryClient.invalidateQueries("pluginCenterAuth");
|
|
50
|
-
}
|
|
50
|
+
}
|
|
51
51
|
}
|
|
52
52
|
);
|
|
53
53
|
return {
|
|
@@ -55,6 +55,6 @@ export const useUpdateConfig = () => {
|
|
|
55
55
|
isLoading,
|
|
56
56
|
error,
|
|
57
57
|
isUpdated: !!data,
|
|
58
|
-
reset
|
|
58
|
+
reset
|
|
59
59
|
};
|
|
60
60
|
};
|
package/src/import.ts
CHANGED
|
@@ -30,12 +30,12 @@ import { requiredLink } from "./links";
|
|
|
30
30
|
|
|
31
31
|
export const useImportLog = (logId: string): ApiResult<string> => {
|
|
32
32
|
const link = useRequiredIndexLink("importLog").replace("{logId}", logId);
|
|
33
|
-
return useQuery<string, Error>(["importLog", logId], () => apiClient.get(link).then(
|
|
33
|
+
return useQuery<string, Error>(["importLog", logId], () => apiClient.get(link).then(response => response.text()));
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
export const useImportRepositoryFromUrl = (repositoryType: RepositoryType) => {
|
|
37
37
|
const url = requiredLink(repositoryType, "import", "url");
|
|
38
|
-
const { isLoading, error, data, mutate } = useMutation<Repository, Error, RepositoryUrlImport>(
|
|
38
|
+
const { isLoading, error, data, mutate } = useMutation<Repository, Error, RepositoryUrlImport>(repo =>
|
|
39
39
|
apiClient
|
|
40
40
|
.post(url, repo, "application/vnd.scmm-repository+json;v=2")
|
|
41
41
|
.then(fetchResourceFromLocationHeader)
|
|
@@ -46,13 +46,13 @@ export const useImportRepositoryFromUrl = (repositoryType: RepositoryType) => {
|
|
|
46
46
|
isLoading,
|
|
47
47
|
error,
|
|
48
48
|
importRepositoryFromUrl: (repository: RepositoryUrlImport) => mutate(repository),
|
|
49
|
-
importedRepository: data
|
|
49
|
+
importedRepository: data
|
|
50
50
|
};
|
|
51
51
|
};
|
|
52
52
|
|
|
53
53
|
const importRepository = (url: string, repository: RepositoryCreation, file: File, password?: string) => {
|
|
54
54
|
return apiClient
|
|
55
|
-
.postBinary(url,
|
|
55
|
+
.postBinary(url, formData => {
|
|
56
56
|
formData.append("bundle", file, file.name);
|
|
57
57
|
formData.append("repository", JSON.stringify({ ...repository, password }));
|
|
58
58
|
})
|
|
@@ -82,9 +82,9 @@ export const useImportRepositoryFromBundle = (repositoryType: RepositoryType) =>
|
|
|
82
82
|
repository,
|
|
83
83
|
file,
|
|
84
84
|
compressed,
|
|
85
|
-
password
|
|
85
|
+
password
|
|
86
86
|
}),
|
|
87
|
-
importedRepository: data
|
|
87
|
+
importedRepository: data
|
|
88
88
|
};
|
|
89
89
|
};
|
|
90
90
|
|
|
@@ -107,8 +107,8 @@ export const useImportFullRepository = (repositoryType: RepositoryType) => {
|
|
|
107
107
|
mutate({
|
|
108
108
|
repository,
|
|
109
109
|
file,
|
|
110
|
-
password
|
|
110
|
+
password
|
|
111
111
|
}),
|
|
112
|
-
importedRepository: data
|
|
112
|
+
importedRepository: data
|
|
113
113
|
};
|
|
114
114
|
};
|
package/src/login.test.ts
CHANGED
|
@@ -37,7 +37,7 @@ describe("Test login hooks", () => {
|
|
|
37
37
|
name: "tricia",
|
|
38
38
|
displayName: "Tricia",
|
|
39
39
|
groups: [],
|
|
40
|
-
_links: {}
|
|
40
|
+
_links: {}
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
describe("useMe tests", () => {
|
|
@@ -45,7 +45,7 @@ describe("Test login hooks", () => {
|
|
|
45
45
|
name: "tricia",
|
|
46
46
|
displayName: "Tricia",
|
|
47
47
|
groups: [],
|
|
48
|
-
_links: {}
|
|
48
|
+
_links: {}
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
it("should return me", async () => {
|
|
@@ -65,10 +65,10 @@ describe("Test login hooks", () => {
|
|
|
65
65
|
|
|
66
66
|
let me: Me;
|
|
67
67
|
const context: LegacyContext = {
|
|
68
|
-
onMeFetched:
|
|
68
|
+
onMeFetched: fetchedMe => {
|
|
69
69
|
me = fetchedMe;
|
|
70
70
|
},
|
|
71
|
-
initialize: () => null
|
|
71
|
+
initialize: () => null
|
|
72
72
|
};
|
|
73
73
|
|
|
74
74
|
const { result, waitFor } = renderHook(() => useMe(), { wrapper: createWrapper(context, queryClient) });
|
|
@@ -131,7 +131,7 @@ describe("Test login hooks", () => {
|
|
|
131
131
|
name: "_anonymous",
|
|
132
132
|
displayName: "Anonymous",
|
|
133
133
|
groups: [],
|
|
134
|
-
_links: {}
|
|
134
|
+
_links: {}
|
|
135
135
|
});
|
|
136
136
|
const { result } = renderHook(() => useSubject(), { wrapper: createWrapper(undefined, queryClient) });
|
|
137
137
|
|
|
@@ -159,8 +159,8 @@ describe("Test login hooks", () => {
|
|
|
159
159
|
cookie: true,
|
|
160
160
|
grant_type: "password",
|
|
161
161
|
username: "tricia",
|
|
162
|
-
password: "hitchhikersSecret!"
|
|
163
|
-
}
|
|
162
|
+
password: "hitchhikersSecret!"
|
|
163
|
+
}
|
|
164
164
|
});
|
|
165
165
|
|
|
166
166
|
// required because we invalidate the whole cache and react-query refetches the index
|
|
@@ -168,13 +168,13 @@ describe("Test login hooks", () => {
|
|
|
168
168
|
version: "x.y.z",
|
|
169
169
|
_links: {
|
|
170
170
|
login: {
|
|
171
|
-
href: "/second/login"
|
|
172
|
-
}
|
|
173
|
-
}
|
|
171
|
+
href: "/second/login"
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
174
|
});
|
|
175
175
|
|
|
176
176
|
const { result, waitForNextUpdate } = renderHook(() => useLogin(), {
|
|
177
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
177
|
+
wrapper: createWrapper(undefined, queryClient)
|
|
178
178
|
});
|
|
179
179
|
const { login } = result.current;
|
|
180
180
|
expect(login).toBeDefined();
|
|
@@ -195,7 +195,7 @@ describe("Test login hooks", () => {
|
|
|
195
195
|
queryClient.setQueryData("me", tricia);
|
|
196
196
|
|
|
197
197
|
const { result } = renderHook(() => useLogin(), {
|
|
198
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
198
|
+
wrapper: createWrapper(undefined, queryClient)
|
|
199
199
|
});
|
|
200
200
|
|
|
201
201
|
expect(result.current.login).toBeUndefined();
|
|
@@ -210,7 +210,7 @@ describe("Test login hooks", () => {
|
|
|
210
210
|
fetchMock.deleteOnce("/api/v2/logout", {});
|
|
211
211
|
|
|
212
212
|
const { result, waitForNextUpdate } = renderHook(() => useLogout(), {
|
|
213
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
213
|
+
wrapper: createWrapper(undefined, queryClient)
|
|
214
214
|
});
|
|
215
215
|
const { logout } = result.current;
|
|
216
216
|
expect(logout).toBeDefined();
|
|
@@ -230,7 +230,7 @@ describe("Test login hooks", () => {
|
|
|
230
230
|
setEmptyIndex(queryClient);
|
|
231
231
|
|
|
232
232
|
const { result } = renderHook(() => useLogout(), {
|
|
233
|
-
wrapper: createWrapper(undefined, queryClient)
|
|
233
|
+
wrapper: createWrapper(undefined, queryClient)
|
|
234
234
|
});
|
|
235
235
|
|
|
236
236
|
const { logout } = result.current;
|
package/src/login.ts
CHANGED
|
@@ -33,13 +33,13 @@ import { useCallback } from "react";
|
|
|
33
33
|
export const useMe = (): ApiResult<Me> => {
|
|
34
34
|
const legacy = useLegacyContext();
|
|
35
35
|
const link = useIndexLink("me");
|
|
36
|
-
return useQuery<Me, Error>("me", () => apiClient.get(link!).then(
|
|
36
|
+
return useQuery<Me, Error>("me", () => apiClient.get(link!).then(response => response.json()), {
|
|
37
37
|
enabled: !!link,
|
|
38
|
-
onSuccess:
|
|
38
|
+
onSuccess: me => {
|
|
39
39
|
if (legacy.onMeFetched) {
|
|
40
40
|
legacy.onMeFetched(me);
|
|
41
41
|
}
|
|
42
|
-
}
|
|
42
|
+
}
|
|
43
43
|
});
|
|
44
44
|
};
|
|
45
45
|
|
|
@@ -61,7 +61,7 @@ export const useSubject = () => {
|
|
|
61
61
|
isAnonymous,
|
|
62
62
|
isLoading,
|
|
63
63
|
error,
|
|
64
|
-
me
|
|
64
|
+
me
|
|
65
65
|
};
|
|
66
66
|
};
|
|
67
67
|
|
|
@@ -76,9 +76,9 @@ export const useLogin = () => {
|
|
|
76
76
|
const link = useIndexLink("login");
|
|
77
77
|
const reset = useReset();
|
|
78
78
|
const { mutate, isLoading, error } = useMutation<unknown, Error, Credentials>(
|
|
79
|
-
|
|
79
|
+
credentials => apiClient.post(link!, credentials),
|
|
80
80
|
{
|
|
81
|
-
onSuccess: reset
|
|
81
|
+
onSuccess: reset
|
|
82
82
|
}
|
|
83
83
|
);
|
|
84
84
|
|
|
@@ -92,7 +92,7 @@ export const useLogin = () => {
|
|
|
92
92
|
return {
|
|
93
93
|
login: link ? login : undefined,
|
|
94
94
|
isLoading,
|
|
95
|
-
error
|
|
95
|
+
error
|
|
96
96
|
};
|
|
97
97
|
};
|
|
98
98
|
|
|
@@ -105,14 +105,14 @@ export const useLogout = () => {
|
|
|
105
105
|
const reset = useReset();
|
|
106
106
|
|
|
107
107
|
const { mutate, isLoading, error, data } = useMutation<LogoutResponse, Error, unknown>(
|
|
108
|
-
() => apiClient.delete(link!).then(
|
|
108
|
+
() => apiClient.delete(link!).then(r => (r.status === 200 ? r.json() : {})),
|
|
109
109
|
{
|
|
110
|
-
onSuccess:
|
|
110
|
+
onSuccess: response => {
|
|
111
111
|
if (response?.logoutRedirect) {
|
|
112
112
|
window.location.assign(response.logoutRedirect);
|
|
113
113
|
}
|
|
114
114
|
return reset();
|
|
115
|
-
}
|
|
115
|
+
}
|
|
116
116
|
}
|
|
117
117
|
);
|
|
118
118
|
|
|
@@ -123,6 +123,6 @@ export const useLogout = () => {
|
|
|
123
123
|
return {
|
|
124
124
|
logout: link && !data ? logout : undefined,
|
|
125
125
|
isLoading,
|
|
126
|
-
error
|
|
126
|
+
error
|
|
127
127
|
};
|
|
128
128
|
};
|
package/src/loginInfo.ts
CHANGED
|
@@ -29,15 +29,15 @@ export const useLoginInfo = (disabled = false): ApiResult<LoginInfo> => {
|
|
|
29
29
|
const loginInfoLink = useIndexLink("loginInfo");
|
|
30
30
|
const { error, isLoading, data } = useQuery<LoginInfo, Error>(
|
|
31
31
|
["loginInfo"],
|
|
32
|
-
() => fetch(loginInfoLink!).then(
|
|
32
|
+
() => fetch(loginInfoLink!).then(response => response.json()),
|
|
33
33
|
{
|
|
34
34
|
enabled: !disabled && !!loginInfoLink,
|
|
35
|
-
refetchOnWindowFocus: false
|
|
35
|
+
refetchOnWindowFocus: false
|
|
36
36
|
}
|
|
37
37
|
);
|
|
38
38
|
return {
|
|
39
39
|
data,
|
|
40
40
|
error,
|
|
41
|
-
isLoading
|
|
41
|
+
isLoading
|
|
42
42
|
};
|
|
43
43
|
};
|