PromucFlow_constructor/app/client/src/api/Api.ts
Pranav Kanade 82cbf718d0
refactor: code splitting to support third party sso/oidc in EE (#10201)
* added config to support code split

* splitting config

* moved the window declaration in EE file as its dependency will be updated in EE

* CE: Splitting ApiConstants and SocialLogin constants

* CE: split login page

* CE: moved getSocialLoginButtonProps func to EE file as it's dependencies will be updated in EE

* added key icon

* CE: created a factory class to share social auths list

* Minor style fix for social btns

* Updated the third party auth styles

* updated jest config

* updated third party login registry class
2022-01-07 11:38:17 +05:30

102 lines
2.3 KiB
TypeScript

import axios, { AxiosInstance, AxiosRequestConfig } from "axios";
import { REQUEST_TIMEOUT_MS } from "@appsmith/constants/ApiConstants";
import { convertObjectToQueryParams } from "utils/AppsmithUtils";
import {
apiFailureResponseInterceptor,
apiRequestInterceptor,
apiSuccessResponseInterceptor,
} from "api/ApiUtils";
import { API_REQUEST_HEADERS } from "constants/AppsmithActionConstants/ActionConstants";
//TODO(abhinav): Refactor this to make more composable.
export const apiRequestConfig = {
baseURL: "/api/",
timeout: REQUEST_TIMEOUT_MS,
headers: API_REQUEST_HEADERS,
withCredentials: true,
};
const axiosInstance: AxiosInstance = axios.create();
axiosInstance.interceptors.request.use(apiRequestInterceptor);
axiosInstance.interceptors.response.use(
apiSuccessResponseInterceptor,
apiFailureResponseInterceptor,
);
class Api {
static get(
url: string,
queryParams?: any,
config: Partial<AxiosRequestConfig> = {},
) {
return axiosInstance.get(url + convertObjectToQueryParams(queryParams), {
...apiRequestConfig,
...config,
});
}
static post(
url: string,
body?: any,
queryParams?: any,
config: Partial<AxiosRequestConfig> = {},
) {
return axiosInstance.post(
url + convertObjectToQueryParams(queryParams),
body,
{
...apiRequestConfig,
...config,
},
);
}
static put(
url: string,
body?: any,
queryParams?: any,
config: Partial<AxiosRequestConfig> = {},
) {
return axiosInstance.put(
url + convertObjectToQueryParams(queryParams),
body,
{
...apiRequestConfig,
...config,
},
);
}
static patch(
url: string,
body?: any,
queryParams?: any,
config: Partial<AxiosRequestConfig> = {},
) {
return axiosInstance.patch(
url + convertObjectToQueryParams(queryParams),
body,
{
...apiRequestConfig,
...config,
},
);
}
static delete(
url: string,
queryParams?: any,
config: Partial<AxiosRequestConfig> = {},
) {
return axiosInstance.delete(url + convertObjectToQueryParams(queryParams), {
...apiRequestConfig,
...config,
});
}
}
export type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
export default Api;