UNPKG

@sap-cloud-sdk/http-client

Version:

SAP Cloud SDK for JavaScript http-client

93 lines (92 loc) 5.95 kB
import type { DestinationHttpRequestConfig, ExecuteHttpRequestFn, HttpRequestConfig, HttpRequestConfigWithOrigin, HttpRequestOptions, HttpResponse, ParameterEncoder } from './http-client-types'; import type { Destination, HttpDestinationOrFetchOptions } from '@sap-cloud-sdk/connectivity'; /** * Builds a {@link DestinationHttpRequestConfig} for the given destination. * If a destination name (and a JWT) are provided, it will try to resolve the destination. * @param destination - A destination or a destination name and a JWT. * @returns A {@link DestinationHttpRequestConfig}. */ export declare function buildHttpRequest(destination: HttpDestinationOrFetchOptions): Promise<DestinationHttpRequestConfig>; /** * Takes as parameter a function that expects an {@link HttpRequest} and returns a Promise of {@link HttpResponse}. * Returns a function that takes a destination and a request-config (extends {@link HttpRequestConfig}), builds an {@link HttpRequest} from them, and calls * the provided execute function. * * NOTE: If you simply want to execute a request without passing your own execute function, use {@link executeHttpRequest} instead. * @param executeFn - A function that can execute an {@link HttpRequestConfig}. * @returns A function expecting destination and a request. * @internal */ export declare function execute(executeFn: ExecuteHttpRequestFn<HttpResponse>): <T extends HttpRequestConfigWithOrigin>(destination: HttpDestinationOrFetchOptions, requestConfig: T, options: HttpRequestOptions) => Promise<HttpResponse>; /** * Build an {@link HttpRequestConfigWithOrigin} from a given {@link HttpRequestConfigWithOrigin} or {@link HttpRequestConfig} * @param requestConfig - The given {@link HttpRequestConfigWithOrigin} or {@link HttpRequestConfig} * @returns The resulting {@link HttpRequestConfigWithOrigin} * @internal */ export declare function buildHttpRequestConfigWithOrigin(requestConfig: HttpRequestConfigWithOrigin | HttpRequestConfig | undefined): HttpRequestConfigWithOrigin; /** * This method does nothing and is only there to indicate that the call was made by a typed OData client and encoding already happened in the client. * @param params - Parameters which are returned. * @returns The parameters as they are without encoding. * @internal */ export declare const oDataTypedClientParameterEncoder: ParameterEncoder; /** * @internal * Build a request config from a given request config and a destination. * In addition to merging the information from the request config and the destination, it also picks values with higher priority for headers and query parameters. * @param requestConfig - Any object representing an HTTP request. * @param destination - A resolved {@link Destination} object. * @param destinationRequestConfig - A {@link DestinationHttpRequestConfig} object, that is built from a {@link Destination}. * @see {@link mergeOptionsWithPriority} * @returns A resulting request config. */ export declare function buildRequestWithMergedHeadersAndQueryParameters(requestConfig: HttpRequestConfigWithOrigin, destination: Destination, destinationRequestConfig: DestinationHttpRequestConfig, jwt?: string): Promise<HttpRequestConfig & DestinationHttpRequestConfig>; /** * Builds a {@link DestinationHttpRequestConfig} for the given destination, merges it into the given `requestConfig` and executes it (using Axios). * @param destination - A destination or a destination name and a JWT. * @param requestConfig - Any object representing an HTTP request. * @param options - An {@link HttpRequestOptions} of the HTTP request for configuring e.g., CSRF token delegation. By default, the SDK will fetch the CSRF token. * @returns A promise resolving to an {@link HttpResponse}. */ export declare function executeHttpRequest<T extends HttpRequestConfig>(destination: HttpDestinationOrFetchOptions, requestConfig?: T, options?: HttpRequestOptions): Promise<HttpResponse>; /** * Builds a {@link DestinationHttpRequestConfig} for the given destination, merges it into the given {@link HttpRequestConfigWithOrigin} * and executes it (using Axios). * The {@link HttpRequestConfigWithOrigin} supports defining header options and query parameter options with origins. * Equally named headers and query parameters are prioritized in the following order: * 1. `custom` * 2. Destination related headers/query parameters * 3. `requestConfig`. * @param destination - A destination or a destination name and a JWT. * @param requestConfig - Any object representing an HTTP request. * @param options - An {@link HttpRequestOptions} of the HTTP request for configuring e.g., CSRF token delegation. By default, the SDK will fetch the CSRF token. * @returns A promise resolving to an {@link HttpResponse}. * @see https://sap.github.io/cloud-sdk/docs/js/features/connectivity/query-parameters */ export declare function executeHttpRequestWithOrigin<T extends HttpRequestConfigWithOrigin>(destination: HttpDestinationOrFetchOptions, requestConfig?: T, options?: HttpRequestOptions): Promise<HttpResponse>; /** * Builds an Axios config with default configuration i.e. no_proxy, default http and https agent and GET as request method. * @returns RawAxiosRequestConfig with default parameters * @internal */ export declare function getAxiosConfigWithDefaults(): HttpRequestConfig; /** * @internal */ export declare function getAxiosConfigWithDefaultsWithoutMethod(): Omit<HttpRequestConfig, 'method'>; /** * @internal */ export declare function getDefaultHttpRequestConfigOptions(): HttpRequestConfigWithOrigin; /** * @internal */ export declare function getDefaultHttpRequestOptions(): HttpRequestOptions; /** * Encoder for encoding all query parameters (key and value) using encodeURIComponent. * @param parameter - Parameter to be encoded using encodeURIComponent. * @returns Encoded parameter object. */ export declare const encodeAllParameters: ParameterEncoder;