import {AxiosInstance, AxiosRequestConfig} from "axios";

import type {StoreType} from "@store/index";

import {customHeadersKeys, customHeaderValues} from "./AxiosServiceConstants";

/**
 * Mapping all the requestInterceptors defined as closures inside this function
 * to the axios-instance apiServer.
 *
 * Defined requestInterceptor closures needs to be registered to the constant object
 * axiosRequestInterceptors in order to get mapped.
 *
 * @param store
 * @param apiServer
 */
function AlthermaAxiosRequestInterceptors(
	store: StoreType | null,
	apiServer: AxiosInstance,
): void {
	/**
	 * Request Interceptor for adding X-API-KEY.
	 * @param {AxiosRequestConfig} config
	 */
	function requestXAPIKeyInterceptor(
		config: AxiosRequestConfig,
	): AxiosRequestConfig {
		return {
			...config,
			headers: {
				...config.headers,
				[customHeadersKeys.Accept]: customHeaderValues.Accept,
				[customHeadersKeys.Content_Type]: customHeaderValues.Content_Type,
			},
		};
	}

	/**
	 * All request-interceptors should be registered here.
	 *
	 * eg: {
	 *     requestAuthorizationInterceptor: requestAuthorizationInterceptor
	 * }
	 */
	const axiosRequestInterceptors = {
		requestXAPIKeyInterceptor,
	};

	/**
	 * Extracting and mapping each requestInterceptors with the axios-instance
	 * apiServer.
	 */
	// Adding type "any" until axios issue is fixed - https://github.com/axios/axios/issues/5494
	Object.values(axiosRequestInterceptors).forEach((requestInterceptor) => {
		apiServer.interceptors.request.use(requestInterceptor as any);
	});
}

export default AlthermaAxiosRequestInterceptors;
import {AxiosRequestConfig} from "axios";
import Config from "react-native-config";

import {DEFAULT_API_TIMEOUT} from "@config/constants/APITimeoutConstants";

export const API_SERVER_BASE_URL = Config.ALTHERMA_URL;

export const apiServerConfig: AxiosRequestConfig = Object.freeze({
	baseURL: API_SERVER_BASE_URL,
	timeout: DEFAULT_API_TIMEOUT,
});

export const customHeadersKeys = Object.freeze({
	Accept: "Accept",
	Content_Type: "Content-Type",
});

export const customHeaderValues = Object.freeze({
	Accept: "application/json",
	Content_Type: "application/json",
});

export const apiEndpoints = Object.freeze({
	wifi: {
		ap: {
			scan: "scan",
			networks: "networks",
			settings: "settings",
			info: "info",
		},
	},
});
import {AxiosError, AxiosInstance, AxiosResponse} from "axios";

import {
	iNetworkError,
	iNetworkResult,
	iWLANInfo,
	iWLANScanResponse,
	iWLANSettings,
} from "@config/types/AppDataTypes/AlthermaTypes";

import {apiEndpoints} from "./axiosConfig/AxiosServiceConstants";

type ApiResult<T> = iNetworkResult<T> | iNetworkError;

const AlthermaService = (apiServer: AxiosInstance) => {
	// TODO: The error type is currently unknown; consider updating the network interface in AlthermaTypes.ts to accommodate this.
	/**
	 * Generic method to handle API requests and responses
	 * @param requestFn API request function to execute
	 * @returns Promise with specified response
	 */
	const handleApiRequest = async <T>(
		requestFn: () => Promise<AxiosResponse<T>>,
	): Promise<ApiResult<T>> => {
		try {
			const response = await requestFn();
			return {
				error: null,
				status: response.status,
				data: response.data,
			} as iNetworkResult<T>;
		} catch (error) {
			const axiosError = error as AxiosError;
			if (axiosError.response) {
				const {status, data} = axiosError.response;
				return {
					error: data,
					status,
					data,
				} as iNetworkError;
			}
			// throw again if the error is not an Axios error with a response
			throw error;
		}
	};

	/**
	 * scan for available WiFi networks
	 */
	const scanWifiNetworks = () => {
		return handleApiRequest(() => {
			return apiServer.post(apiEndpoints.wifi.ap.scan);
		});
	};

	/**
	 * Fetch the list of available WiFi networks
	 */
	const getAvailableNetworks = () => {
		return handleApiRequest<iWLANScanResponse>(() => {
			return apiServer.get(apiEndpoints.wifi.ap.networks);
		});
	};

	/**
	 * Configures and connects to a WiFi network
	 */
	const configureWifiConnection = (settings: iWLANSettings) => {
		return handleApiRequest(() => {
			return apiServer.put(apiEndpoints.wifi.ap.settings, settings);
		});
	};

	/**
	 * Gets current WLAN connection information
	 */
	const getWlanInfo = () => {
		return handleApiRequest<iWLANInfo>(() => {
			return apiServer.get(apiEndpoints.wifi.ap.info);
		});
	};

	return {
		scanWifiNetworks,
		getAvailableNetworks,
		configureWifiConnection,
		getWlanInfo,
	};
};

export default AlthermaService; this is my code works fine in android but provides Network error in ios how to fix this note all the required permissions are provided