UNPKG

@microfocus/alm-octane-js-rest-sdk

Version:

NodeJS wrapper for the OpenText Core Software Delivery Platform API

133 lines 8.18 kB
import { Params } from './octane'; import axios, { AxiosRequestConfig, AxiosResponse, RawAxiosRequestHeaders } from 'axios'; /** * @class * * @param {Object} params - configurations to access Octane REST API * @param {String} params.server - server of Octane REST API URL (ex: https://myOctane:8080) * @param {Number} params.user - Octane user * @param {Number} params.password - Octane password * @param {String} [params.proxy] - if set, using proxy to connect to Octane * @param {Object} [params.headers] - JSON containing headers which will be used for all the requests */ declare class RequestHandler { private readonly _user?; private readonly _password?; private readonly _token?; private _mutex; private _cookieJar; private readonly _options; private _requestor; private _needsAuthenication; constructor(params: Params); createProxyUrlWithCredentials(proxyUrl: string, username: string, password: string): string; /** * Fires a GET request for the given URL. In case the request fails with a 401 (Unauthorized) code, one attempt to reauthenticate is sent. If the authentication was successful the initial request is fired again and the response is returned. * * @param url - A url to the specific resource. The URL should exclude the server and point to the desired resource. * @param config - Extra configuration for the request (ex. headers) * @returns - The result of the operation returned by the server. * @throws - The error returned by the server if the request fails. */ get(url: string, config?: AxiosRequestConfig): Promise<axios.AxiosResponse<any, any, {}>>; /** * Fires a DELETE request for the given URL. In case the request fails with a 401 (Unauthorized) code, one attempt to reauthenticate is sent. If the authentication was successful the initial request is fired again and the response is returned. * * @param url - A url to the specific resource. The URL should exclude the server and point to the desired resource. * @param config - Extra configuration for the request (ex. headers) * @returns - The result of the operation returned by the server. * @throws - The error returned by the server if the request fails. */ delete(url: string, config?: AxiosRequestConfig): Promise<axios.AxiosResponse<any, any, {}>>; /** * Fires a PUT request for the given URL. In case the request fails with a 401 (Unauthorized) code, one attempt to reauthenticate is sent. If the authentication was successful the initial request is fired again and the response is returned. * * @param url - A url to the specific resource. The URL should exclude the server and point to the desired resource. * @param body - A JSON which will be passed in the body of the request. * @param config - Extra configuration for the request (ex. headers) * @returns - The result of the operation returned by the server. * @throws - The error returned by the server if the request fails. */ update(url: string, body?: object | string, config?: AxiosRequestConfig): Promise<axios.AxiosResponse<any, any, {}>>; /** * Fires a POST request for the given URL. In case the request fails with a 401 (Unauthorized) code, one attempt to reauthenticate is sent. If the authentication was successful the initial request is fired again and the response is returned. * * @param url - A url to the specific resource. The URL should exclude the server and point to the desired resource. * @param body - A JSON which will be passed in the body of the request. * @param config - Extra configuration for the request (ex. headers) * @returns - The result of the operation returned by the server. * @throws - The error returned by the server if the request fails. */ create(url: string, body?: object | string, config?: AxiosRequestConfig): Promise<axios.AxiosResponse<any, any, {}>>; /** * A sign in request is fired. * * @throws - The error returned by the server if the request fails. */ authenticate(): Promise<axios.AxiosResponse<any, any, {}>>; /** * Fires a GET request for the given URL. In case the request fails with a 401 (Unauthorized) code, one attempt to reauthenticate is sent. If the authentication was successful the initial request is fired again and the response is returned. * * @param url - A url to the specific resource. The URL should exclude the server and point to the desired resource. * @param config - Extra configuration for the request (ex. headers) * @returns - The result of the operation returned by the server. The result is the content of the targeted attachment. * @throws - The error returned by the server if the request fails. */ getAttachmentContent(url: string, config?: AxiosRequestConfig): Promise<axios.AxiosResponse<any, any, {}>>; /** * Fires a POST request for the given URL. This request should upload the attachment to Octane. In case the request fails with a 401 (Unauthorized) code, one attempt to reauthenticate is sent. If the authentication was successful the initial request is fired again and the response is returned. * * @param url - A url to the specific resource. The URL should exclude the server and point to the desired resource. * @param body - An object which will be passed in the body of the request. This object should contain the content of the attachment. * @param config - Extra configuration for the request (ex. headers) * @returns - The result of the operation returned by the server. * @throws - The error returned by the server if the request fails. */ uploadAttachment(url: string, body: object | string, config?: AxiosRequestConfig): Promise<axios.AxiosResponse<any, any, {}>>; /** * A sign-out request is fired. * * @throws - The error returned by the server if the request fails. */ signOut(): Promise<axios.AxiosResponse<any, any, {}>>; /** * In case the previous request had a 401 (Unauthorized) status code, an authentication request must be fired. * * @param {Object} err - The error code of the previous error thrown at the failed request. * @throws - The error returned by the server if the request fails. * @private */ private _reauthenticate; sendRequestWithCookies(url: string, callBack: (headersWithCookie?: RawAxiosRequestHeaders) => Promise<AxiosResponse>, customHeaders?: AxiosRequestConfig['headers']): Promise<AxiosResponse>; /** * Sends an HTTP request using cookie-based authentication. * Adds the `Cookie` header to the request using stored credentials. * Updates the cookie jar with any cookies received in the response. * * @param url The URL to send the request to. * @param callBack A callback that performs the actual HTTP request with the provided headers. * @param customHeaders Optional custom headers to include in the request. * @returns The Axios response from the server. * @throws Error if the request fails. */ private sendRequestWithCredentials; /** * Sends an HTTP request using token-based authentication. * Adds the `Authorization` header with the bearer token to the request. * If the server responds with a 401 status, throws an error indicating token authentication failure. * * @param url The URL to send the request to. * @param callBack A callback that performs the actual HTTP request with the provided headers. * @param customHeaders Optional custom headers to include in the request. * @returns The Axios response from the server. * @throws Error if token authentication fails (401) or another request error occurs. */ private sendRequestWithToken; updateCookieJarFromResponse(response: AxiosResponse, url: string): Promise<void>; getCookieHeaderForUrl(url: string): Promise<string>; private mergeHeaders; private hasHeader; private filterOutHeaders; } export default RequestHandler; //# sourceMappingURL=requestHandler.d.ts.map