debian-mirror-gitlab/app/assets/javascripts/jira_connect/subscriptions/api.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

98 lines
2.4 KiB
JavaScript
Raw Normal View History

2021-03-08 18:12:59 +05:30
import axios from 'axios';
2022-10-11 01:57:18 +05:30
import { buildApiUrl } from '~/api/api_utils';
import { GITLAB_COM_BASE_PATH } from '~/jira_connect/subscriptions/constants';
2021-10-27 15:23:28 +05:30
import { getJwt } from './utils';
2021-03-08 18:12:59 +05:30
2022-10-11 01:57:18 +05:30
const CURRENT_USER_PATH = '/api/:version/user';
const JIRA_CONNECT_SUBSCRIPTIONS_PATH = '/api/:version/integrations/jira_connect/subscriptions';
const JIRA_CONNECT_INSTALLATIONS_PATH = '/-/jira_connect/installations';
const JIRA_CONNECT_OAUTH_APPLICATION_ID_PATH = '/-/jira_connect/oauth_application_id';
// This export is only used for testing purposes
export const axiosInstance = axios.create();
export const setApiBaseURL = (baseURL = null) => {
axiosInstance.defaults.baseURL = baseURL;
};
2021-03-08 18:12:59 +05:30
export const addSubscription = async (addPath, namespace) => {
const jwt = await getJwt();
2022-10-11 01:57:18 +05:30
return axiosInstance.post(addPath, {
2021-03-08 18:12:59 +05:30
jwt,
namespace_path: namespace,
});
};
export const removeSubscription = async (removePath) => {
const jwt = await getJwt();
2022-10-11 01:57:18 +05:30
return axiosInstance.delete(removePath, {
2021-03-08 18:12:59 +05:30
params: {
jwt,
},
});
};
2021-04-29 21:17:54 +05:30
export const fetchGroups = async (groupsPath, { page, perPage, search }) => {
2022-10-11 01:57:18 +05:30
return axiosInstance.get(groupsPath, {
2021-03-08 18:12:59 +05:30
params: {
page,
per_page: perPage,
2021-04-29 21:17:54 +05:30
search,
2021-03-08 18:12:59 +05:30
},
});
};
2022-07-16 23:28:13 +05:30
export const fetchSubscriptions = async (subscriptionsPath) => {
const jwt = await getJwt();
2022-10-11 01:57:18 +05:30
return axiosInstance.get(subscriptionsPath, {
2022-07-16 23:28:13 +05:30
params: {
jwt,
},
});
};
2022-10-11 01:57:18 +05:30
export const getCurrentUser = (options) => {
const url = buildApiUrl(CURRENT_USER_PATH);
return axiosInstance.get(url, { ...options });
};
export const addJiraConnectSubscription = (namespacePath, { jwt, accessToken }) => {
const url = buildApiUrl(JIRA_CONNECT_SUBSCRIPTIONS_PATH);
return axiosInstance.post(
url,
{
jwt,
namespace_path: namespacePath,
},
{
headers: {
Authorization: `Bearer ${accessToken}`,
},
},
);
};
export const updateInstallation = async (instanceUrl) => {
const jwt = await getJwt();
return axiosInstance.put(JIRA_CONNECT_INSTALLATIONS_PATH, {
jwt,
installation: {
instance_url: instanceUrl === GITLAB_COM_BASE_PATH ? null : instanceUrl,
},
});
};
export const fetchOAuthApplicationId = () => {
return axiosInstance.get(JIRA_CONNECT_OAUTH_APPLICATION_ID_PATH);
};
export const fetchOAuthToken = (oauthTokenPath, data = {}) => {
return axiosInstance.post(oauthTokenPath, data);
};