/** * Provides APIs for making Pega's REST API calls. * These APIs can be used for different purposes such as validation messages, network failure messages etc. * @module RestClient */ import type { AxiosResponse } from 'axios'; import type { Interceptor, FetchOptions } from '../globals'; import CaseAPIs from './case-apis'; import type { RestAPIPayload } from './types'; /** * This API provides an entry point to the {@link module:HeaderProcessor} API object. * This exposes APIs that include: * * * @example Example for registerHeader api * PCore.getRestClient().getHeaderProcessor().registerHeader(key, value) * @example Example for unRegisterHeader api * PCore.getRestClient().getHeaderProcessor().unRegisterHeader(key) * @example Example for getRegisteredHeaders api * PCore.getRestClient().getHeaderProcessor().getRegisteredHeaders() * @function * @public */ export declare const getHeaderProcessor: () => { registerHeader: (args_0: string) => boolean; unRegisterHeader: (args_0: string) => void; getRegisteredHeaders: () => { [key: string]: string | null | undefined; }; }; /** * this function helps to invoke a Pega REST API * @function invokeRestApi * @public * @param routeKey - Route key for REST API e.g. "getFeedMessages" * @param restAPIPayload - object containing body, header and queryPayload provided for REST API call * @param context - name of the context eq., primary * @param options - object containing additional information for invoking a rest endpoint. * @returns Promise * * @example invokeRestApi() * Below example shows how to use invokeRestApi api to make REST API call to get Feed messages. * ``` * const { invokeRestApi } = PCore.getRestClient(); * const cancelTokenSource = getCancelTokenSource(); * invokeRestApi('getFeedMessages', { * queryPayload: { * filterForContext: 'DATA-PORTAL $SpaceTra', * filterByContext: 'context' * }, * body: {}, * headers: {}, * // passing cancel token so that we can cancel the request using cancelTokenSource * cancelTokenSource: cancelTokenSource.token * }) * .then(() => { * // handle the response * }) * .catch((error) => { * // handle error * if(isRequestCanceled(error)) { * // handle the canceled request using cancelTokenSource.cancel(); * } * }); *``` */ export declare const invokeRestApi: (routeKey: string, { body, queryPayload, cancelTokenSource, headers, responseType }: RestAPIPayload, context?: string, options?: FetchOptions) => Promise>; type RestApiConfigObject = { /** request method(GET, POST, PUT, PATCH, DELETE) to be used when making the request. Default is 'GET' */ method: string; /** the custom headers to be sent along with the request. */ headers?: object; /** data to be sent as the request body. Only applicable for request methods 'PUT', 'POST', and 'PATCH' */ body?: object; /** The flag that indicates whether default request headers must be sent along with the request. */ withoutDefaultHeaders: boolean; }; /** * Invokes a custom REST API using an endpoint URL. * The custom REST APIs can include external APIs or Pega APIs. * @function invokeCustomRestApi * @public * @param endpointUrl - URL of the REST endpoint. URL can be relative e.g. '/api/dev/v1/insights' or absolute e.g. 'https://cs.rpega.com/prweb/api/dev/v1/insights' * @param config - The object containing the information required to invoke the custom REST API * @param context - name of the context e.g. primary * @returns Promise * * @example Example for invokeCustomRestApi api * const { invokeCustomRestApi } = PCore.getRestClient(); * invokeCustomRestApi("/api/dev/v1/insights", { * method: "GET", * body: {}, * headers: {}, * }) * .then(() => { * // handle the response * }) * .catch((error) => { * // handle error * }); * // above example shows how to use invokeCustomRestApi api to make REST API call to get Feed messages. * */ export declare const invokeCustomRestApi: (endpointUrl: string, { method, body, headers, withoutDefaultHeaders }: RestApiConfigObject, context: string) => Promise; /** * this function helps to detect if a Pega REST API exists * @function doesRestApiExist * * @param routeKey api name. * @returns return whether key exists or not * * @example Example for doesRestApiExist api * const { doesRestApiExist } = PCore.getRestClient(); * const isExist = doesRestApiExist("getCaseFollowers"); * @private */ export declare const doesRestApiExist: (routeKey: string) => boolean; /** * this function helps to get a cancel token source object which contains token to be passed as signal to a request * so that the request could be canceled using same cancel token source object. * @function getCancelTokenSource * @public * @returns Cancel Token Source * * @example Example for getCancelTokenSource api * const { getCancelTokenSource } = PCore.getRestClient(); * const cancelTokenSource = getCancelTokenSource(); * // cancel the ongoing request using the cancelTokenSource * cancelTokenSource.cancel(); * // above example shows how to use getCancelTokenSource api to get the cancel token source using which we can cancel the ongoing request. */ export declare const getCancelTokenSource: () => import("axios").CancelTokenSource; /** * this function helps to know if a request is canceled using cancel token source. * @function isRequestCanceled * @public * @param err Error object * @returns Indicates if the request is canceled using getCancelTokenSource API * * @example Example for isRequestCanceled api * const { isRequestCanceled } = PCore.getRestClient(); * if(isRequestCanceled(error)) { * // handle the canceled request using cancelTokenSource.cancel(); * } * // above example shows how to use isRequestCanceled api to know if the request is canceled using cancel token source. */ export declare const isRequestCanceled: (err: { name?: string; message?: string; }) => boolean; /** * this function helps to intercept request and response. * @function registerInterceptor * Registers the proxy function to handle all rest apis, * This will be helpful whereever response has to be mocked eq., preview * @param interceptor function to handle all rest apis. * Example: { * request: (config) => { return config}, * response: (responseText) => {return responseText}, * * } * @private */ export declare const registerInterceptor: (interceptor: Interceptor) => void; export declare const getCaseApi: () => typeof CaseAPIs; export {};