/** * @license * @preserve * * Copyright 2026 KeeeX SAS * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * */ import { type Awaitable } from "@keeex/utils/types/types.js"; import type * as axios from "axios"; /** Symbol used to trigger a retry of an axios request */ export declare const errorRetry: unique symbol; /** * Symbol used to trigger a retry of an axios request and reapply auth headers. * * If this is used instead of `errorRetry`, the auth headers (if available) will be reapplied to the * request. */ export declare const errorRetryAuth: unique symbol; /** * Hook called before `preRequest()` hooks on an authenticated API route call. * * If custom authentication data must be provided in the request, it should be setup here. * * @param authMethod - The requested authentication method in the API route definition */ export type PreAuthenticateHook = (axiosRequestConfig: axios.AxiosRequestConfig, authMethod: string | true) => Awaitable; /** * Hook called immediately before doing an actual Axios request. * * Local hook is called before global hook. * * The hook can alter anything in the request, which is then effectively passed down to axios as-is. * User must be careful to not break expectation regarding the API call. */ export type PreRequestHook = (axiosRequestConfig: axios.AxiosRequestConfig) => Awaitable; /** * Global hook called immediately after a successful Axios request. * * One of the main usage is to alter the response data. */ export type PostRequestHook = (axiosResponse: axios.AxiosResponse) => Awaitable; export type PostRequestProcess = (axiosResponse: axios.AxiosResponse) => Awaitable; /** * Global hook called immediately after an unsuccessful Axios request. * * @param axiosRequestConfig - The initial request config * @param error - The error that was raised. Should be an `AxiosError` most of the time. * * @returns * If the symbol `errorRetry` is returned, the request is retried directly with the content of * `axiosRequestConfig` (which can be altered here). * Note that no custom hooks are automatically called in this case. * If you re-authenticate, make sure to setup the authentication in both `MidSdk` and this request. * If the function returns `undefined`, the error processing continue. * If the function returns an object, it is considered a success and resume processing into the * `postRequest()` hooks using the returned value as the axios reply. */ export type PostErrorHook = (axiosRequestConfig: axios.AxiosRequestConfig, axiosResponse: Error | axios.AxiosError) => Awaitable; /** All possible hooks to set on a request/SDK config */ export interface Hooks { postError?: PostErrorHook; postRequest?: PostRequestHook; preAuthenticate?: PreAuthenticateHook; preRequest?: PreRequestHook; } /** Disable global hooks on specific API routes */ export interface DisableHooks { /** Disable calling global postError */ postError?: boolean; /** Disable calling global postRequest */ postRequest?: boolean; /** Disable calling global preAuthenticate */ preAuthenticate?: boolean; /** Disable calling global preRequest */ preRequest?: boolean; }