UNPKG

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

Version:

NodeJS wrapper for the OpenText Core Software Delivery Platform API

108 lines 6.82 kB
import { Params } from './octane'; import { AxiosHeaders, AxiosRequestConfig, AxiosResponse } from 'axios'; import { 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 _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<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<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<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<AxiosResponse<any, any>>; /** * A sign in request is fired. * * @throws - The error returned by the server if the request fails. */ authenticate(): Promise<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<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<AxiosResponse<any, any>>; /** * A sign-out request is fired. * * @throws - The error returned by the server if the request fails. */ signOut(): Promise<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 | AxiosHeaders) => Promise<AxiosResponse>, customHeaders?: RawAxiosRequestHeaders | AxiosHeaders): Promise<AxiosResponse>; updateCookieJarFromResponse(response: AxiosResponse, url: string): Promise<void>; getCookieHeaderForUrl(url: string): Promise<string>; private hasHeader; private filterOutHeaders; } export default RequestHandler; //# sourceMappingURL=requestHandler.d.ts.map