-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor rest api and manager services in spa (#2268)
* Refactor rest api and manager services in spa * fix test * clear token
- Loading branch information
1 parent
d086e59
commit e60fdc9
Showing
14 changed files
with
278 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
import { GetGitHubAppsUrlResponse } from "../../rest-interfaces/oauth-types"; | ||
import { AxiosInstanceWithJWT } from "../axiosInstance"; | ||
import { AxiosResponse } from "axios"; | ||
import { axiosRest } from "../axiosInstance"; | ||
|
||
const GitHubApps = { | ||
getAppNewInstallationUrl: (): Promise<AxiosResponse<GetGitHubAppsUrlResponse>> => AxiosInstanceWithJWT.get("/rest/app/cloud/installation/new"), | ||
export default { | ||
getAppNewInstallationUrl: () => axiosRest.get<GetGitHubAppsUrlResponse>("/rest/app/cloud/installation/new"), | ||
}; | ||
|
||
export default GitHubApps; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
import { GetRedirectUrlResponse, ExchangeTokenResponse } from "../../rest-interfaces/oauth-types"; | ||
import { AxiosInstanceWithJWT } from "../axiosInstance"; | ||
import { AxiosResponse } from "axios"; | ||
import { axiosRest } from "../axiosInstance"; | ||
|
||
const GitHubAuth = { | ||
generateOAuthUrl: (): Promise<AxiosResponse<GetRedirectUrlResponse>> => AxiosInstanceWithJWT.get("/rest/app/cloud/oauth/redirectUrl"), | ||
exchangeToken: (code: string, state: string): Promise<AxiosResponse<ExchangeTokenResponse>> => | ||
AxiosInstanceWithJWT.post<ExchangeTokenResponse>("/rest/app/cloud/oauth/exchangeToken", { code, state }) | ||
export default { | ||
generateOAuthUrl: () => axiosRest.get<GetRedirectUrlResponse>("/rest/app/cloud/oauth/redirectUrl"), | ||
exchangeToken: (code: string, state: string) => axiosRest.post<ExchangeTokenResponse>("/rest/app/cloud/oauth/exchangeToken", { code, state }), | ||
}; | ||
|
||
export default GitHubAuth; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { UsersGetAuthenticatedResponse } from "../../rest-interfaces/oauth-types"; | ||
import { axiosGitHub } from "../axiosInstance"; | ||
|
||
export default { | ||
getUserDetails: () => axiosGitHub.get<UsersGetAuthenticatedResponse>("https://api.github.com/user"), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
import Token from "./token"; | ||
import GitHubAuth from "./auth"; | ||
import GitHubApps from "./apps"; | ||
import Auth from "./auth"; | ||
import App from "./apps"; | ||
import Orgs from "./orgs"; | ||
import GitHub from "./github"; | ||
|
||
const ApiRequest = { | ||
token: Token, | ||
githubAuth: GitHubAuth, | ||
gitHubApp: GitHubApps, | ||
auth: Auth, | ||
gitHub: GitHub, | ||
app: App, | ||
orgs: Orgs | ||
}; | ||
|
||
export default ApiRequest; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { OrganizationsResponse } from "../../rest-interfaces/oauth-types"; | ||
import { axiosRestWithGitHubToken } from "../axiosInstance"; | ||
|
||
export default { | ||
getOrganizations: async () => axiosRestWithGitHubToken.get<OrganizationsResponse>("/rest/app/cloud/org"), | ||
connectOrganization: async (orgId: number) => axiosRestWithGitHubToken.post<OrganizationsResponse>("/rest/app/cloud/org", { installationId: orgId }), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,7 @@ | ||
import axios, { AxiosResponse } from "axios"; | ||
import { OrganizationsResponse, UsersGetAuthenticatedResponse } from "../../rest-interfaces/oauth-types"; | ||
import { AxiosInstanceWithGHToken } from "../axiosInstance"; | ||
import { clearGitHubToken, setGitHubToken, hasGitHubToken } from "../axiosInstance"; | ||
|
||
const Token = { | ||
getUserDetails: (token: string): Promise<AxiosResponse<UsersGetAuthenticatedResponse>> => axios.get("https://api.github.com/user", { | ||
headers: { Authorization: `Bearer ${token}`} | ||
}), | ||
getOrganizations: async (token: string): Promise<AxiosResponse<OrganizationsResponse>> => { | ||
const instance = await AxiosInstanceWithGHToken(token); | ||
return instance.get("/rest/app/cloud/org"); | ||
}, | ||
connectOrganization: async (token: string, orgId: number): Promise<AxiosResponse<OrganizationsResponse>> => { | ||
const instance = await AxiosInstanceWithGHToken(token); | ||
return instance.post("/rest/app/cloud/org", { installationId: orgId }); | ||
}, | ||
export default { | ||
hasGitHubToken, | ||
clearGitHubToken, | ||
setGitHubToken, | ||
}; | ||
|
||
export default Token; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.