UNPKG

@zowe/cics-for-zowe-sdk

Version:
130 lines (129 loc) 6.24 kB
/** * This program and the accompanying materials are made available under the terms of the * Eclipse Public License v2.0 which accompanies this distribution, and is available at * https://www.eclipse.org/legal/epl-v20.html * * SPDX-License-Identifier: EPL-2.0 * * Copyright Contributors to the Zowe Project. * */ import { AbstractRestClient, type AbstractSession, type IImperativeError } from "@zowe/imperative"; import type { ICMCIApiResponse } from "../doc/ICMCIApiResponse"; import type { ICMCIRequestOptions } from "../doc/ICMCIRequestOptions"; /** * Wrapper for invoke CICS CMCI API through the RestClient to perform common error * handling and checking and resolve promises according to generic types * @export * @class CicsCmciRestClient * @extends {RestClient} */ export declare class CicsCmciRestClient extends AbstractRestClient { /** * If the API request is successful, this value should be in * api_response1 in the resultsummary object in the response */ static readonly CMCI_SUCCESS_RESPONSE_1 = "1024"; /** * If the API request is successful, this value should be in * api_response2 in the resultsummary object in the response */ static readonly CMCI_SUCCESS_RESPONSE_2 = "0"; /** * Convert an object to XML using the xml2js package * @param obj - the object to convert to XML * @returns {string} the string of XML generated by xml2js */ static convertObjectToXML(obj: any): string; /** * Call the RestClient.getExpectString function assuming the response is XML, then return a promise of the JSON representation. * @static * @param {AbstractSession} session - representing connection to this api * @param {string} resource - URI for which this request should go against * @param {any} reqHeaders - headers to include in the REST request * @returns {Promise<*>} - response body content from http(s) call * @throws {ImperativeError} verifyResponseCodes fails */ static getExpectParsedXml(session: AbstractSession, resource: string, reqHeaders?: any[], requestOptions?: ICMCIRequestOptions): Promise<ICMCIApiResponse>; /** * Call the RestClient.deleteExpectString function assuming the response is XML, then return a promise of the JSON representation. * @static * @param {AbstractSession} session - representing connection to this api * @param {string} resource - URI for which this request should go against * @param {any} reqHeaders - headers to include in the REST request * @returns {Promise<*>} - response body content from http(s) call * @throws {ImperativeError} verifyResponseCodes fails */ static deleteExpectParsedXml(session: AbstractSession, resource: string, reqHeaders?: any[]): Promise<ICMCIApiResponse>; /** * PUT a CMCI endpoint expecting an XML return value parsed into a JCL * Call the RestClient.putExpectString function assuming the response is XML, then return a promise of the JSON representation. * @static * @param {AbstractSession} session - representing connection to this api * @param {string} resource - URI for which this request should go against * @param {any} reqHeaders - headers to include in the REST request * @param payload - XML body to put or a javascript object to convert to XML * @returns {Promise<*>} - response body content from http(s) call * @throws {ImperativeError} verifyResponseCodes fails */ static putExpectParsedXml(session: AbstractSession, resource: string, reqHeaders: any[], payload: any, requestOptions?: ICMCIRequestOptions): Promise<ICMCIApiResponse>; /** * POST a CMCI endpoint expecting a XML return value * Calls the RestClient.postExpectString function assuming the response is XML, then return a promise of the JSON representation. * @static * @param {AbstractSession} session - representing connection to this api * @param {string} resource - URI for which this request should go against * @param {any} reqHeaders - headers to include in the REST request * @param payload - XML body to put or a javascript object to convert to XML * @returns {Promise<*>} - response body content from http(s) call * @throws {ImperativeError} verifyResponseCodes fails */ static postExpectParsedXml(session: AbstractSession, resource: string, reqHeaders: any[], payload: any): Promise<ICMCIApiResponse>; /** * Internal logger */ private static mLogger; /** * Internal parser */ private static mParser; /** * Detect if a payload is a string or an object * If it is an object, convert it to XML using xml2js * @param payload - the request body / payload * @returns {string} the XML that can be used as the request body */ private static convertPayloadToXML; /** * Use the Zowe logger instead of the imperative logger * @return {Logger} */ private static get log(); /** * Use a configured parser * @return {Parser} */ private static get parser(); /** * Check that we got the expected response codes from the API after a request * @param {ICMCIApiResponse} apiResponse - the parsed response * @returns {ICMCIApiResponse} - the response if it was correct * @throws {ImperativeError} if the request failed. The error might include records that were retrieved. */ private static verifyResponseCodes; /** * parse an XML string with XML2js * The API is already synchronous according to their documentation but requires a callback. * This is a wrapper that doesn't require a callback. * @param {string} str - the string of XML to parse * @returns {any} the object parsed from the XML * @throws {Error} xml2js.parseString fails */ private static parseStringSync; /** * Process an error encountered in the rest client * @param {IImperativeError} original - the original error automatically built by the abstract rest client * @returns {IImperativeError} - the processed error with details added */ protected processError(original: IImperativeError): IImperativeError; }