/** * Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * * WSO2 Inc. licenses this file to you under the Apache License, * Version 2.0 (the 'License'); you may not use this file except * in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import { IdentityClient } from "@asgardio/oidc-js"; import { AxiosError, AxiosResponse } from "axios"; import { CommonServiceResourcesEndpoints } from "../configs"; import { UserstoreConstants } from "../constants"; import { IdentityAppsApiException } from "../exceptions"; import { HTTPRequestHeaders } from "../helpers"; import { HttpMethods, UserstoreListResponseInterface } from "../models"; import { ContextUtils } from "../utils"; /** * Get an axios instance. * */ const httpClient = IdentityClient.getInstance().httpRequest.bind(IdentityClient.getInstance()); /** * Retrieve the list of user stores that are currently in the system. * TODO: Return `response.data` rather than `response` and stop returning any. * * @return {Promise} * @throws {IdentityAppsApiException} */ export const getUserStoreList = (): Promise => { const requestConfig = { headers: HTTPRequestHeaders(ContextUtils.getRuntimeConfig().clientHost), method: HttpMethods.GET, url: CommonServiceResourcesEndpoints(ContextUtils.getRuntimeConfig().serverHost).userstores }; return httpClient(requestConfig) .then((response: AxiosResponse) => { if (response.status !== 200) { throw new IdentityAppsApiException( UserstoreConstants.USERSTORES_FETCH_REQUEST_INVALID_RESPONSE_CODE_ERROR, null, response.status, response.request, response, response.config); } return Promise.resolve(response); }) .catch((error: AxiosError) => { throw new IdentityAppsApiException( UserstoreConstants.USERSTORES_FETCH_REQUEST_ERROR, error.stack, error.code, error.request, error.response, error.config); }); };