@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/package.json
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scm-manager/ui-api",
|
|
3
|
-
"version": "2.36.
|
|
3
|
+
"version": "2.36.2-20220522-120507",
|
|
4
4
|
"description": "React hook api for the SCM-Manager backend",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "build/index.js",
|
|
6
|
+
"module": "build/index.mjs",
|
|
7
|
+
"types": "build/index.d.ts",
|
|
6
8
|
"files": [
|
|
7
|
-
"
|
|
8
|
-
"src"
|
|
9
|
+
"build"
|
|
9
10
|
],
|
|
10
11
|
"repository": "https://github.com/scm-manager/scm-manager",
|
|
11
12
|
"author": "SCM Team <scm-team@cloudogu.com>",
|
|
12
13
|
"license": "MIT",
|
|
13
14
|
"scripts": {
|
|
14
|
-
"
|
|
15
|
-
"typecheck": "tsc"
|
|
15
|
+
"build": "tsup ./src/index.ts -d build --format esm,cjs --dts",
|
|
16
|
+
"typecheck": "tsc",
|
|
17
|
+
"lint": "eslint src",
|
|
18
|
+
"test": "jest src/"
|
|
16
19
|
},
|
|
17
20
|
"devDependencies": {
|
|
18
21
|
"@scm-manager/babel-preset": "^2.13.1",
|
|
@@ -22,15 +25,17 @@
|
|
|
22
25
|
"@scm-manager/tsconfig": "^2.13.0",
|
|
23
26
|
"@testing-library/react-hooks": "^5.0.3",
|
|
24
27
|
"@types/react": "^17.0.1",
|
|
25
|
-
"react-test-renderer": "^17.0.1"
|
|
28
|
+
"react-test-renderer": "^17.0.1",
|
|
29
|
+
"tsup": "^5.12.6"
|
|
26
30
|
},
|
|
27
31
|
"dependencies": {
|
|
28
|
-
"@scm-manager/ui-types": "
|
|
32
|
+
"@scm-manager/ui-types": "2.36.2-20220522-120507",
|
|
29
33
|
"fetch-mock-jest": "^1.5.1",
|
|
30
34
|
"gitdiff-parser": "^0.2.2",
|
|
31
35
|
"query-string": "6.14.1",
|
|
32
36
|
"react": "^17.0.1",
|
|
33
|
-
"react-query": "^3.25.1"
|
|
37
|
+
"react-query": "^3.25.1",
|
|
38
|
+
"react-router-dom": "^5.3.1"
|
|
34
39
|
},
|
|
35
40
|
"babel": {
|
|
36
41
|
"presets": [
|
|
@@ -47,4 +52,4 @@
|
|
|
47
52
|
"publishConfig": {
|
|
48
53
|
"access": "public"
|
|
49
54
|
}
|
|
50
|
-
}
|
|
55
|
+
}
|
package/LICENSE.txt
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/src/ApiProvider.test.tsx
DELETED
|
@@ -1,60 +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 { LegacyContext, useLegacyContext } from "./LegacyContext";
|
|
26
|
-
import * as React from "react";
|
|
27
|
-
import { FC } from "react";
|
|
28
|
-
import { renderHook } from "@testing-library/react-hooks";
|
|
29
|
-
import ApiProvider from "./ApiProvider";
|
|
30
|
-
import { useQueryClient } from "react-query";
|
|
31
|
-
|
|
32
|
-
describe("ApiProvider tests", () => {
|
|
33
|
-
const createWrapper = (context: LegacyContext): FC => {
|
|
34
|
-
return ({ children }) => <ApiProvider {...context}>{children}</ApiProvider>;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
it("should register QueryClient", () => {
|
|
38
|
-
const { result } = renderHook(() => useQueryClient(), {
|
|
39
|
-
wrapper: createWrapper({ initialize: () => null })
|
|
40
|
-
});
|
|
41
|
-
expect(result.current).toBeDefined();
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("should pass legacy context QueryClient", () => {
|
|
45
|
-
let msg: string;
|
|
46
|
-
const onIndexFetched = () => {
|
|
47
|
-
msg = "hello";
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const { result } = renderHook(() => useLegacyContext(), {
|
|
51
|
-
wrapper: createWrapper({ onIndexFetched, initialize: () => null })
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
if (result.current?.onIndexFetched) {
|
|
55
|
-
result.current.onIndexFetched({ version: "a.b.c", _links: {}, instanceId: "123" });
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
expect(msg!).toEqual("hello");
|
|
59
|
-
});
|
|
60
|
-
});
|
package/src/ApiProvider.tsx
DELETED
|
@@ -1,80 +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 React, { FC, useEffect } from "react";
|
|
25
|
-
import { QueryClient, QueryClientProvider } from "react-query";
|
|
26
|
-
import { ReactQueryDevtools } from "react-query/devtools";
|
|
27
|
-
import { LegacyContext, LegacyContextProvider } from "./LegacyContext";
|
|
28
|
-
import { IndexResources, Me } from "@scm-manager/ui-types";
|
|
29
|
-
import { reset } from "./reset";
|
|
30
|
-
|
|
31
|
-
const queryClient = new QueryClient({
|
|
32
|
-
defaultOptions: {
|
|
33
|
-
queries: {
|
|
34
|
-
retry: false
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
type Props = LegacyContext & {
|
|
40
|
-
index?: IndexResources;
|
|
41
|
-
me?: Me;
|
|
42
|
-
devtools?: boolean;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const ApiProvider: FC<Props> = ({ children, index, me, onMeFetched, onIndexFetched, devtools = true }) => {
|
|
46
|
-
useEffect(() => {
|
|
47
|
-
if (index) {
|
|
48
|
-
queryClient.setQueryData("index", index);
|
|
49
|
-
if (onIndexFetched) {
|
|
50
|
-
onIndexFetched(index);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}, [index, onIndexFetched]);
|
|
54
|
-
useEffect(() => {
|
|
55
|
-
if (me) {
|
|
56
|
-
queryClient.setQueryData("me", me);
|
|
57
|
-
if (onMeFetched) {
|
|
58
|
-
onMeFetched(me);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}, [me, onMeFetched]);
|
|
62
|
-
return (
|
|
63
|
-
<QueryClientProvider client={queryClient}>
|
|
64
|
-
<LegacyContextProvider onIndexFetched={onIndexFetched} onMeFetched={onMeFetched}>
|
|
65
|
-
{children}
|
|
66
|
-
</LegacyContextProvider>
|
|
67
|
-
{devtools ? <ReactQueryDevtools initialIsOpen={false} /> : null}
|
|
68
|
-
</QueryClientProvider>
|
|
69
|
-
);
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
export { Props as ApiProviderProps };
|
|
73
|
-
|
|
74
|
-
export const clearCache = () => {
|
|
75
|
-
// we do a safe reset instead of clearing the whole cache
|
|
76
|
-
// this should avoid missing link errors for index
|
|
77
|
-
return reset(queryClient);
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
export default ApiProvider;
|
|
@@ -1,52 +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 { LegacyContext, LegacyContextProvider, useLegacyContext } from "./LegacyContext";
|
|
26
|
-
import * as React from "react";
|
|
27
|
-
import { FC } from "react";
|
|
28
|
-
import { renderHook } from "@testing-library/react-hooks";
|
|
29
|
-
import { QueryClient, QueryClientProvider } from "react-query";
|
|
30
|
-
|
|
31
|
-
describe("LegacyContext tests", () => {
|
|
32
|
-
const queryClient = new QueryClient();
|
|
33
|
-
const createWrapper = (context?: LegacyContext): FC => {
|
|
34
|
-
return ({ children }) => (
|
|
35
|
-
<QueryClientProvider client={queryClient}>
|
|
36
|
-
<LegacyContextProvider {...context}>{children}</LegacyContextProvider>
|
|
37
|
-
</QueryClientProvider>
|
|
38
|
-
);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
it("should return provided context", () => {
|
|
42
|
-
const { result } = renderHook(() => useLegacyContext(), {
|
|
43
|
-
wrapper: createWrapper()
|
|
44
|
-
});
|
|
45
|
-
expect(result.current).toBeDefined();
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("should fail without providers", () => {
|
|
49
|
-
const { result } = renderHook(() => useLegacyContext());
|
|
50
|
-
expect(result.error).toBeDefined();
|
|
51
|
-
});
|
|
52
|
-
});
|
package/src/LegacyContext.tsx
DELETED
|
@@ -1,75 +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 { IndexResources, Me } from "@scm-manager/ui-types";
|
|
26
|
-
import React, { createContext, FC, useContext } from "react";
|
|
27
|
-
import { QueryClient, useQueryClient } from "react-query";
|
|
28
|
-
|
|
29
|
-
export type BaseContext = {
|
|
30
|
-
onIndexFetched?: (index: IndexResources) => void;
|
|
31
|
-
onMeFetched?: (me: Me) => void;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export type LegacyContext = BaseContext & {
|
|
35
|
-
initialize: () => void;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const Context = createContext<LegacyContext | undefined>(undefined);
|
|
39
|
-
|
|
40
|
-
export const useLegacyContext = () => {
|
|
41
|
-
const context = useContext(Context);
|
|
42
|
-
if (!context) {
|
|
43
|
-
throw new Error("useLegacyContext can't be used outside of ApiProvider");
|
|
44
|
-
}
|
|
45
|
-
return context;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const createInitialContext = (queryClient: QueryClient, base: BaseContext): LegacyContext => {
|
|
49
|
-
const ctx = {
|
|
50
|
-
...base,
|
|
51
|
-
initialize: () => {
|
|
52
|
-
if (ctx.onIndexFetched) {
|
|
53
|
-
const index: IndexResources | undefined = queryClient.getQueryData("index");
|
|
54
|
-
if (index) {
|
|
55
|
-
ctx.onIndexFetched(index);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
if (ctx.onMeFetched) {
|
|
59
|
-
const me: Me | undefined = queryClient.getQueryData("me");
|
|
60
|
-
if (me) {
|
|
61
|
-
ctx.onMeFetched(me);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
return ctx;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export const LegacyContextProvider: FC<BaseContext> = ({ onIndexFetched, onMeFetched, children }) => {
|
|
71
|
-
const queryClient = useQueryClient();
|
|
72
|
-
const ctx = createInitialContext(queryClient, { onIndexFetched, onMeFetched });
|
|
73
|
-
|
|
74
|
-
return <Context.Provider value={ctx}>{children}</Context.Provider>;
|
|
75
|
-
};
|
package/src/admin.test.ts
DELETED
|
@@ -1,55 +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 createInfiniteCachingClient from "./tests/createInfiniteCachingClient";
|
|
27
|
-
import { renderHook } from "@testing-library/react-hooks";
|
|
28
|
-
import createWrapper from "./tests/createWrapper";
|
|
29
|
-
import { useUpdateInfo } from "./admin";
|
|
30
|
-
import { UpdateInfo } from "@scm-manager/ui-types";
|
|
31
|
-
import { setIndexLink } from "./tests/indexLinks";
|
|
32
|
-
|
|
33
|
-
describe("Test admin hooks", () => {
|
|
34
|
-
describe("useUpdateInfo tests", () => {
|
|
35
|
-
it("should get update info", async () => {
|
|
36
|
-
const updateInfo: UpdateInfo = {
|
|
37
|
-
latestVersion: "x.y.z",
|
|
38
|
-
link: "http://heartofgold@hitchhiker.com/x.y.z",
|
|
39
|
-
};
|
|
40
|
-
fetchMock.getOnce("/api/v2/updateInfo", updateInfo);
|
|
41
|
-
|
|
42
|
-
const queryClient = createInfiniteCachingClient();
|
|
43
|
-
setIndexLink(queryClient, "updateInfo", "/updateInfo");
|
|
44
|
-
|
|
45
|
-
const { result, waitFor } = renderHook(() => useUpdateInfo(), {
|
|
46
|
-
wrapper: createWrapper(undefined, queryClient),
|
|
47
|
-
});
|
|
48
|
-
await waitFor(() => {
|
|
49
|
-
return !!result.current.data;
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
expect(result.current.data).toEqual(updateInfo);
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
});
|
package/src/admin.ts
DELETED
|
@@ -1,42 +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 } from "./base";
|
|
26
|
-
import { UpdateInfo } from "@scm-manager/ui-types";
|
|
27
|
-
import { useQuery } from "react-query";
|
|
28
|
-
import { apiClient } from "./apiclient";
|
|
29
|
-
|
|
30
|
-
export const useUpdateInfo = (): ApiResult<UpdateInfo | null> => {
|
|
31
|
-
const indexLink = useIndexLink("updateInfo");
|
|
32
|
-
return useQuery<UpdateInfo | null, Error>(
|
|
33
|
-
"updateInfo",
|
|
34
|
-
() => {
|
|
35
|
-
if (!indexLink) {
|
|
36
|
-
throw new Error("could not find index data");
|
|
37
|
-
}
|
|
38
|
-
return apiClient.get(indexLink).then((response) => (response.status === 204 ? null : response.json()));
|
|
39
|
-
},
|
|
40
|
-
{ enabled: !!indexLink }
|
|
41
|
-
);
|
|
42
|
-
};
|
package/src/alerts.ts
DELETED
|
@@ -1,107 +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 { useQuery } from "react-query";
|
|
26
|
-
import { apiClient } from "./apiclient";
|
|
27
|
-
import { ApiResult, useIndexLink } from "./base";
|
|
28
|
-
import { AlertsResponse, HalRepresentation, Link } from "@scm-manager/ui-types";
|
|
29
|
-
|
|
30
|
-
type AlertRequest = HalRepresentation & {
|
|
31
|
-
checksum: string;
|
|
32
|
-
body: unknown;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
type LocalStorageAlerts = AlertsResponse & {
|
|
36
|
-
checksum: string;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const alertsFromStorage = (): LocalStorageAlerts | undefined => {
|
|
40
|
-
const item = localStorage.getItem("alerts");
|
|
41
|
-
if (item) {
|
|
42
|
-
return JSON.parse(item);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const fetchAlerts = (request: AlertRequest) => {
|
|
47
|
-
const url = (request._links["alerts"] as Link)?.href;
|
|
48
|
-
if (!url) {
|
|
49
|
-
throw new Error("no alerts link defined");
|
|
50
|
-
}
|
|
51
|
-
return fetch(url, {
|
|
52
|
-
method: "POST",
|
|
53
|
-
headers: {
|
|
54
|
-
"Content-Type": "application/json"
|
|
55
|
-
},
|
|
56
|
-
body: JSON.stringify(request.body)
|
|
57
|
-
})
|
|
58
|
-
.then(response => {
|
|
59
|
-
if (!response.ok) {
|
|
60
|
-
throw new Error("Failed to fetch alerts");
|
|
61
|
-
}
|
|
62
|
-
return response;
|
|
63
|
-
})
|
|
64
|
-
.then(response => response.json())
|
|
65
|
-
.then((data: AlertsResponse) => {
|
|
66
|
-
const storageItem: LocalStorageAlerts = {
|
|
67
|
-
...data,
|
|
68
|
-
checksum: request.checksum
|
|
69
|
-
};
|
|
70
|
-
localStorage.setItem("alerts", JSON.stringify(storageItem));
|
|
71
|
-
return data;
|
|
72
|
-
});
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const restoreOrFetch = (request: AlertRequest): Promise<AlertsResponse> => {
|
|
76
|
-
const storedAlerts = alertsFromStorage();
|
|
77
|
-
if (!storedAlerts || storedAlerts.checksum !== request.checksum) {
|
|
78
|
-
return fetchAlerts(request);
|
|
79
|
-
}
|
|
80
|
-
return Promise.resolve(storedAlerts);
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
export const useAlerts = (): ApiResult<AlertsResponse> => {
|
|
84
|
-
const link = useIndexLink("alerts");
|
|
85
|
-
const { data, error, isLoading } = useQuery<AlertsResponse, Error>(
|
|
86
|
-
"alerts",
|
|
87
|
-
() => {
|
|
88
|
-
if (!link) {
|
|
89
|
-
throw new Error("Could not find alert link");
|
|
90
|
-
}
|
|
91
|
-
return apiClient
|
|
92
|
-
.get(link)
|
|
93
|
-
.then(response => response.json())
|
|
94
|
-
.then(restoreOrFetch);
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
enabled: !!link,
|
|
98
|
-
staleTime: Infinity
|
|
99
|
-
}
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
return {
|
|
103
|
-
data,
|
|
104
|
-
error,
|
|
105
|
-
isLoading
|
|
106
|
-
};
|
|
107
|
-
};
|
package/src/annotations.ts
DELETED
|
@@ -1,45 +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 { ApiResultWithFetching } from "./base";
|
|
28
|
-
import { repoQueryKey } from "./keys";
|
|
29
|
-
|
|
30
|
-
export const useAnnotations = (
|
|
31
|
-
repository: Repository,
|
|
32
|
-
revision: string,
|
|
33
|
-
file: File
|
|
34
|
-
): ApiResultWithFetching<AnnotatedSource> => {
|
|
35
|
-
const { isLoading, isFetching, error, data } = useQuery<AnnotatedSource, Error>(
|
|
36
|
-
repoQueryKey(repository, "annotations", revision, file.path),
|
|
37
|
-
() => apiClient.get((file._links.annotate as Link).href).then((response) => response.json())
|
|
38
|
-
);
|
|
39
|
-
return {
|
|
40
|
-
isLoading,
|
|
41
|
-
isFetching,
|
|
42
|
-
error,
|
|
43
|
-
data,
|
|
44
|
-
};
|
|
45
|
-
};
|
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([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
|
-
};
|