UNPKG

ibm-cloud-sdk-core

Version:

Core functionality to support SDKs generated with IBM's OpenAPI SDK Generator.

1,155 lines (1,104 loc) 86.3 kB
/// <reference types="node" /> import { GenericAbortSignal as AbortSignal_2 } from 'axios'; import { AxiosInstance } from 'axios'; import type { CookieJar } from 'tough-cookie'; import { Debugger } from 'debug'; import { OutgoingHttpHeaders } from 'http'; import { Stream } from 'stream'; export { AbortSignal_2 as AbortSignal } /** * Checks for at least one of the given elements being defined. * * @param args - The spread of arguments to check * @returns true if one or more are defined; false if all are undefined */ export declare function atLeastOne(...args: any): boolean; /** * Verifies that no more than one of the given elements are defined. * Returns true if one or none are defined, and false otherwise. * * @param args - The spread of arguments to check * @returns false if more than one elements are defined, true otherwise */ export declare function atMostOne(...args: any): boolean; /** * The request object containing the headers property that * authentication information will be added to. */ declare interface AuthenticateOptions { /** * Headers to augment with authentication information. */ headers?: OutgoingHttpHeaders; [propName: string]: any; } /** * Base Authenticator class for other Authenticators to extend. Not intended * to be used as a stand-alone authenticator. */ export declare class Authenticator implements AuthenticatorInterface { /** * Constants that define the various authenticator types. */ static AUTHTYPE_BASIC: string; static AUTHTYPE_BEARERTOKEN: string; static AUTHTYPE_IAM: string; static AUTHTYPE_IAM_ASSUME: string; static AUTHTYPE_CONTAINER: string; static AUTHTYPE_CP4D: string; static AUTHTYPE_NOAUTH: string; static AUTHTYPE_VPC: string; static AUTHTYPE_MCSP: string; static AUTHTYPE_MCSPV2: string; static AUTHTYPE_UNKNOWN: string; /** * Create a new Authenticator instance. * * @throws Error: the "new" keyword was not used to construct the authenticator. */ constructor(); /** * Augment the request with authentication information. * * @param requestOptions - The request to augment with authentication information. * @throws Error: The authenticate method was not implemented by a subclass. */ authenticate(requestOptions: AuthenticateOptions): Promise<void>; /** * Retrieves the authenticator's type. * The returned value will be the same string that is used * when configuring an instance of the authenticator with the * \<service_name\>_AUTH_TYPE configuration property * (e.g. "basic", "iam", etc.). * This function should be overridden in each authenticator * implementation class that extends this class. * * @returns a string that indicates the authenticator's type */ authenticationType(): string; } /** * This interface defines the common methods associated with an Authenticator * implementation. */ export declare interface AuthenticatorInterface { /** * Add authentication information to the specified request. * * @param requestOptions - The request to which authentication information is added * (in the headers field). */ authenticate(requestOptions: AuthenticateOptions): Promise<void>; /** * Returns a string that indicates the authentication type. */ authenticationType(): string; } /** Configuration options for token-based authentication. */ declare type BaseOptions = { /** Headers to be sent with every outbound HTTP requests to token services. */ headers?: OutgoingHttpHeaders; /** * A flag that indicates whether verification of the token server's SSL * certificate should be disabled or not. */ disableSslVerification?: boolean; /** Endpoint for HTTP token requests. */ url?: string; /** Allow additional request config parameters */ [propName: string]: any; }; /** * Common functionality shared by generated service classes. * * The base service authenticates requests via its authenticator, and sends * them to the service endpoint. */ export declare class BaseService { static DEFAULT_SERVICE_URL: string; static DEFAULT_SERVICE_NAME: string; protected baseOptions: BaseServiceOptions; private authenticator; private requestWrapperInstance; private defaultUserAgent; /** * Configuration values for a service. * * @param userOptions - the configuration options to set on the service instance. * This should be an object with the following fields: * - authenticator: (required) an Object used to authenticate requests to the service. * - serviceUrl: (optional) the base url to use when contacting the service. * The base url may differ between IBM Cloud regions. * - headers: (optional) a set of HTTP headers that should be included with every request sent to the service * - disableSslVerification: (optional) a flag that indicates whether verification of the server's SSL certificate should be * disabled or not. */ constructor(userOptions: UserOptions); /** * Get the instance of the authenticator set on the service. * * @returns the Authenticator instance */ getAuthenticator(): any; /** * Set the service URL to send requests to. * * @param url - the base URL for the service. */ setServiceUrl(url: string): void; /** * Set the HTTP headers to be sent in every request. * * @param headers - the map of headers to include in requests. */ setDefaultHeaders(headers: OutgoingHttpHeaders): void; /** * Turn request body compression on or off. * * @param setting - Will turn it on if 'true', off if 'false'. */ setEnableGzipCompression(setting: boolean): void; /** * Get the Axios instance set on the service. * All requests will be made using this instance. */ getHttpClient(): AxiosInstance; /** * Enable retries for unfulfilled requests. * * @param retryOptions - the configuration for retries */ enableRetries(retryOptions?: RetryOptions): void; /** * Disables retries. */ disableRetries(): void; /** * Applies a given modifier function on a model object. * Since the model object can be a map, or an array, or a model, * these types needs different handling. * Considering whether the input object is a map happens with an explicit parameter. * @param input - the input model object * @param converterFn - the function that is applied on the input object * @param isMap - is `true` when the input object should be handled as a map */ static convertModel(input: any, converterFn: any, isMap?: boolean): any; /** * Configure the service using external configuration * * @param serviceName - the name of the service. This will be used to read from external * configuration. */ protected configureService(serviceName: string): void; /** * Wrapper around `sendRequest` that enforces the request will be authenticated. * * @param parameters - Service request options passed in by user. * This should be an object with the following fields: * - options.method: the http method * - options.url: the path portion of the URL to be appended to the serviceUrl * - options.path: the path parameters to be inserted into the URL * - options.qs: the querystring to be included in the URL * - options.body: the data to be sent as the request body * - options.form: an object containing the key/value pairs for a www-form-urlencoded request. * - options.formData: an object containing the contents for a multipart/form-data request * The following processing is performed on formData values: * - string: no special processing -- the value is sent as is * - object: the value is converted to a JSON string before insertion into the form body * - NodeJS.ReadableStream|Buffer|FileWithMetadata: sent as a file, with any associated metadata * - array: each element of the array is sent as a separate form part using any special processing as described above * - defaultOptions.serviceUrl: the base URL of the service * - defaultOptions.headers: additional HTTP headers to be sent with the request * @returns a Promise */ protected createRequest(parameters: any): Promise<any>; /** * Wrapper around `createRequest` that enforces arrived response to be deserialized. * @param parameters - see `parameters` in `createRequest` * @param deserializerFn - the deserializer function that is applied on the response object * @param isMap - is `true` when the response object should be handled as a map * @returns a Promise */ protected createRequestAndDeserializeResponse(parameters: any, deserializerFn: (any: any) => any, isMap?: boolean): Promise<any>; private readOptionsFromExternalConfig; private static convertArray; private static convertMap; } /** * Additional service configuration. */ declare interface BaseServiceOptions extends UserOptions { /** Querystring to be sent with every request. If not a string will be stringified. */ qs?: any; enableRetries?: boolean; maxRetries?: number; retryInterval?: number; } /** * The BasicAuthenticator is used to add basic authentication information to * requests. * * Basic Authorization will be sent as an Authorization header in the form: * * Authorization: Basic \<encoded username and password\> * */ export declare class BasicAuthenticator extends Authenticator { protected requiredOptions: string[]; protected authHeader: { Authorization: string; }; /** * Create a new BasicAuthenticator instance. * * @param options - Configuration options for basic authentication. * This should be an object containing these fields: * - username: the username portion of basic authentication * - password: the password portion of basic authentication * * @throws Error: the configuration options are not valid. */ constructor(options: Options); /** * Add basic authentication information to `requestOptions`. The basic authentication information * will be set in the Authorization property of `requestOptions.headers` in the form: * * Authorization: Basic \<encoded username and password\> * * @param requestOptions - The request to augment with authentication information. */ authenticate(requestOptions: AuthenticateOptions): Promise<void>; /** * Returns the authenticator's type ('basic'). * * @returns a string that indicates the authenticator's type */ authenticationType(): string; } /** * The BearerTokenAuthenticator will set a user-provided bearer token * in requests. * * The bearer token will be sent as an Authorization header in the form: * * Authorization: Bearer \<bearer-token\> */ export declare class BearerTokenAuthenticator extends Authenticator { protected requiredOptions: string[]; private bearerToken; /** * Create a new BearerTokenAuthenticator instance. * * @param options - Configuration options for bearer authentication. * This should be an object containing the "bearerToken" field. * * @throws Error: the options.bearerToken field is not valid, or unspecified */ constructor(options: Options_2); /** * Set a new bearer token to be sent in subsequent requests. * * @param bearerToken - The bearer token that will be sent in service * requests. */ setBearerToken(bearerToken: string): void; /** * Add a bearer token to `requestOptions`. The bearer token information * will be set in the Authorization property of "requestOptions.headers" in the form: * * Authorization: Bearer \<bearer-token\> * * @param requestOptions - The request to augment with authentication information. */ authenticate(requestOptions: AuthenticateOptions): Promise<void>; /** * Returns the authenticator's type ('bearertoken'). * * @returns a string that indicates the authenticator's type */ authenticationType(): string; } /** * This function builds a `form-data` object for each file parameter. * @param fileParam - The FileWithMetadata instance that contains the file information * @returns the FileObject instance */ export declare function buildRequestFileObject(fileParam: FileWithMetadata): Promise<FileObject>; /** * Checks credentials for common user mistakes of copying \{, \}, or \" characters from the documentation * * @param obj - the options object holding credentials * @param credsToCheck - an array containing the keys of the credentials to check for problems * @returns a string with the error message if there were problems, null if not */ export declare function checkCredentials(obj: any, credsToCheck: string[]): Error | null; /** * The CloudPakForDataAuthenticator will either use a username/password pair or a username/apikey pair to obtain * a bearer token from a token server. When the bearer token expires, a new token is obtained from the token server. * * The bearer token will be sent as an Authorization header in the form: * * Authorization: Bearer \<bearer-token\> */ export declare class CloudPakForDataAuthenticator extends TokenRequestBasedAuthenticator { protected requiredOptions: string[]; protected tokenManager: Cp4dTokenManager; private username; private password; private apikey; /** * Create a new CloudPakForDataAuthenticator instance. * * @param options - Configuration options for CloudPakForData authentication. * This should be an object containing these fields: * - url: (required) the endpoint URL for the CloudPakForData token service * - username: (required) the username used to obtain a bearer token * - password: (optional) the password used to obtain a bearer token (required if apikey is not specified) * - apikey: (optional) the API key used to obtain a bearer token (required if password is not specified) * - disableSslVerification: (optional) a flag that indicates whether verification of the token server's SSL certificate * should be disabled or not * - headers: (optional) a set of HTTP headers to be sent with each request to the token service * * @throws Error: the username, password, and/or url are not valid, or unspecified, for Cloud Pak For Data token requests. */ constructor(options: Options_4); /** * Returns the authenticator's type ('cp4d'). * * @returns a string that indicates the authenticator's type */ authenticationType(): string; } /** * (C) Copyright IBM Corp. 2019, 2024. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Compute and return a Basic Authorization header from a username and password. * * @param username - The username or client id * @param password - The password or client secret * @returns a Basic Auth header with format "Basic <encoded-credentials>" */ export declare function computeBasicAuthHeader(username: string, password: string): string; export declare function constructFilepath(filepath: string): string; /** * Constructs a service URL by formatting a parameterized URL. * * @param parameterizedUrl - a URL that contains variable placeholders, e.g. '\{scheme\}://ibm.com'. * @param defaultUrlVariables - a Map of variable names to default values. * Each variable in the parameterized URL must have a default value specified in this map. * @param providedUrlVariables - a Map of variable names to desired values. * If a variable is not provided in this map, the default variable value will be used instead. * @returns the formatted URL with all variable placeholders replaced by values. */ export declare function constructServiceUrl(parameterizedUrl: string, defaultUrlVariables: Map<string, string>, providedUrlVariables: Map<string, string> | null): string; /** * The ContainerAuthenticator will read a compute resource token from the file system * and use this value to obtain a bearer token from the IAM token server. When the bearer * token expires, a new token is obtained from the token server. * * The bearer token will be sent as an Authorization header in the form: * * Authorization: Bearer \<bearer-token\> */ export declare class ContainerAuthenticator extends IamRequestBasedAuthenticator { protected tokenManager: ContainerTokenManager; private crTokenFilename; private iamProfileName; private iamProfileId; /** * * Create a new ContainerAuthenticator instance. * * @param options - Configuration options for IAM authentication. * This should be an object containing these fields: * - url: (optional) the endpoint URL for the token service * - crTokenFilename: (optional) the file containing the compute resource token * - iamProfileName: (optional) the name of the IAM trusted profile associated with the compute resource token (required if iamProfileId is not specified) * - iamProfileId]: (optional) the ID of the IAM trusted profile associated with the compute resource token (required if iamProfileName is not specified) * - disableSslVerification: (optional) a flag that indicates whether verification of the token server's SSL certificate * should be disabled or not * - headers: (optional) a set of HTTP headers to be sent with each request to the token service * - clientId: (optional) the "clientId" and "clientSecret" fields are used to form a Basic * Authorization header to be included in each request to the token service * - clientSecret: (optional) the "clientId" and "clientSecret" fields are used to form a Basic * Authorization header to be included in each request to the token service * - scope: (optional) the "scope" parameter to use when fetching the bearer token from the token service * * @throws Error: the configuration options are not valid. */ constructor(options: Options_8); /** * Setter for the filename of the compute resource token. * @param crTokenFilename - A string containing a path to the CR token file */ setCrTokenFilename(crTokenFilename: string): void; /** * Setter for the "profile_name" parameter to use when fetching the bearer token from the IAM token server. * @param iamProfileName - the name of the IAM trusted profile */ setIamProfileName(iamProfileName: string): void; /** * Setter for the "profile_id" parameter to use when fetching the bearer token from the IAM token server. * @param iamProfileId - the ID of the IAM trusted profile */ setIamProfileId(iamProfileId: string): void; /** * Returns the authenticator's type ('container'). * * @returns a string that indicates the authenticator's type */ authenticationType(): string; /** * Return the most recently stored refresh token. * * @returns the refresh token string */ getRefreshToken(): string; } /** * The ContainerTokenManager retrieves a compute resource token from a file on the container. This token * is used to perform the necessary interactions with the IAM token service to obtain and store a suitable * bearer (access) token. */ export declare class ContainerTokenManager extends IamRequestBasedTokenManager { private crTokenFilename; private iamProfileName; private iamProfileId; /** * * Create a new ContainerTokenManager instance. * * @param options - Configuration options. * This should be an object containing these fields: * - url: (optional) the endpoint URL for the token service (default: "https://iam.cloud.ibm.com") * - crTokenFilename: (optional) the file containing the compute resource token (default: "/var/run/secrets/tokens/vault-token") * - iamProfileName: (optional) the name of the IAM trusted profile associated with the compute resource token (required if iamProfileId is not specified) * - iamProfileId]: (optional) the ID of the IAM trusted profile associated with the compute resource token (required if iamProfileName is not specified) * - headers: (optional) a set of HTTP headers to be sent with each request to the token service * - disableSslVerification: (optional) a flag that indicates whether verification of the token server's SSL certificate * should be disabled or not * - clientId: (optional) the "clientId" and "clientSecret" fields are used to form a Basic * Authorization header to be included in each request to the token service * - clientSecret: (optional) the "clientId" and "clientSecret" fields are used to form a Basic * Authorization header to be included in each request to the token service * * @throws Error: the configuration options were invalid */ constructor(options: Options_7); /** * Sets the "crTokenFilename" field * @param crTokenFilename - the name of the file containing the CR token */ setCrTokenFilename(crTokenFilename: string): void; /** * Sets the name of the IAM trusted profile to use when obtaining an access token from the IAM token server. * @param iamProfileName - the name of the IAM trusted profile */ setIamProfileName(iamProfileName: string): void; /** * Sets the ID of the IAM trusted profile to use when obtaining an access token from the IAM token server. * @param iamProfileId - the ID of the IAM trusted profile */ setIamProfileId(iamProfileId: string): void; /** * Returns the most recently stored refresh token. * * @returns the refresh token */ getRefreshToken(): string; /** * Request an IAM token using a compute resource token. */ protected requestToken(): Promise<any>; /** * Retrieves the CR token from a file using this search order: * 1. User-specified filename (if specified) * 2. Default file #1 (/var/run/secrets/tokens/vault-token) * 3. Default file #2 (/var/run/secrets/tokens/sa-token) * 4. Default file #3 (/var/run/secrets/codeengine.cloud.ibm.com/compute-resource-token/token) * First one found wins. * * @returns the CR token value as a string */ protected getCrToken(): string; } export declare const contentType: { fromFilename: (file: String | File | FileObject | NodeJS.ReadableStream | Buffer) => string; fromHeader: (buffer: Buffer) => string; }; /** * Token Manager of CloudPak for data. * * The Token Manager performs basic auth with a username and password * to acquire CP4D tokens. */ export declare class Cp4dTokenManager extends JwtTokenManager { protected requiredOptions: string[]; private username; private password; private apikey; /** * Create a new Cp4dTokenManager instance. * * @param options - Configuration options * This should be an object containing these fields: * - url: (required) the endpoint URL for the CloudPakForData token service * - username: (required) the username used to obtain a bearer token * - password: (optional) the password used to obtain a bearer token (required if apikey is not specified) * - apikey: (optional) the API key used to obtain a bearer token (required if password is not specified) * - disableSslVerification: (optional) a flag that indicates whether verification of the token server's SSL certificate * should be disabled or not * - headers: (optional) a set of HTTP headers to be sent with each request to the token service * * @throws Error: the configuration options were invalid. */ constructor(options: Options_3); protected requestToken(): Promise<any>; } export declare function fileExistsAtPath(filepath: string): boolean; /** * (C) Copyright IBM Corp. 2014, 2023. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /// <reference types="node" /> /// <reference types="node" /> /// <reference types="node" /> export declare interface FileObject { value: NodeJS.ReadableStream | Buffer | string; options?: FileOptions; } export declare interface FileOptions { filename?: string; contentType?: string; } export declare interface FileStream extends NodeJS.ReadableStream { path: string | Buffer; } export declare interface FileWithMetadata { data: NodeJS.ReadableStream | Buffer; filename: string; contentType: string; } /** * Look for external configuration of authenticator. * * Try to get authenticator from external sources, with the following priority: * 1. Credentials file (ibm-credentials.env) * 2. Environment variables * 3. VCAP Services (Cloud Foundry) * * @param serviceName - the service name prefix. * */ export declare function getAuthenticatorFromEnvironment(serviceName: string): Authenticator; /** * This function retrieves the content type of the input. * @param inputData - The data to retrieve content type for. * @returns the content type of the input. */ export declare function getContentType(inputData: NodeJS.ReadableStream | Buffer): Promise<string>; /** * Gets the current time. * * @returns the current time in seconds. */ export declare function getCurrentTime(): number; /** * Returns the first match from formats that is key the params map * otherwise null * @param params - The parameters. * @param requires - The keys we want to check */ export declare function getFormat(params: { [key: string]: any; }, formats: string[]): string; /** * Validates that all required params are provided * @param params - the method parameters. * @param requires - the required parameter names. * @returns null if no errors found, otherwise an Error instance */ export declare function getMissingParams(params: { [key: string]: any; }, requires: string[]): null | Error; /** * Return a new logger, formatted with a particular name. The logging functions, in * order of increasing verbosity, are: `error`, `warn`, `info`, `verbose`, and `debug`. * * The logger will be an instance of the `debug` package and utilizes its support for * configuration with environment variables. * * Additionally, the logger will be turned on automatically if the "NODE_DEBUG" * environment variable is set to "axios". * * @param moduleName - the namespace for the logger. The name will appear in * the logs and it will be the name used for configuring the log level. * * @returns the new logger */ export declare function getNewLogger(moduleName: string): SDKLogger; /** * Return a query parameter value from a URL * * @param urlStr - the url string. * @param param - the name of the query parameter whose value should be returned * @returns the value of the "param" query parameter */ export declare function getQueryParam(urlStr: string, param: string): string; /** * The IamAssumeAuthenticator obtains an IAM access token using the IAM "get-token" * operation's "assume" grant type. The authenticator obtains an initial IAM access * token from a user-supplied apikey, then exchanges this initial IAM access token * for another IAM access token that has "assumed the identity" of the specified * trusted profile. * * The bearer token will be sent as an Authorization header in the form: * * Authorization: Bearer \<bearer-token\> */ export declare class IamAssumeAuthenticator extends IamRequestBasedAuthenticatorImmutable { protected tokenManager: IamAssumeTokenManager; /** * * Create a new IamAssumeAuthenticator instance. * * @param options - Configuration options for IAM authentication. * This should be an object containing these fields: * - apikey: (required) the IAM api key for initial token request * - iamProfileId: (optional) the ID of the trusted profile to use * - iamProfileCrn: (optional) the CRN of the trusted profile to use * - iamProfileName: (optional) the name of the trusted profile to use (must be specified with iamAccountId) * - iamAccountId: (optional) the ID of the account the trusted profile is in (must be specified with iamProfileName) * - url: (optional) the endpoint URL for the token service * - disableSslVerification: (optional) a flag that indicates whether verification of the token server's SSL certificate * should be disabled or not * - headers: (optional) a set of HTTP headers to be sent with each request to the token service * - clientId: (optional) the "clientId" and "clientSecret" fields are used to form a Basic * Authorization header to be included in each request to the token service * - clientSecret: (optional) the "clientId" and "clientSecret" fields are used to form a Basic * Authorization header to be included in each request to the token service * - scope: (optional) the "scope" parameter to use when fetching the bearer token from the token service * * @throws Error: the configuration options are not valid. */ constructor(options: Options_16); /** * Returns the authenticator's type ('iamAssume'). * * @returns a string that indicates the authenticator's type */ authenticationType(): string; } /** * The IamAssumeTokenManager takes an api key, along with trusted profile information, and performs * the necessary interactions with the IAM token service to obtain and store a suitable bearer token * that "assumes" the identify of the trusted profile. */ export declare class IamAssumeTokenManager extends IamRequestBasedTokenManager { protected requiredOptions: string[]; private iamProfileId; private iamProfileCrn; private iamProfileName; private iamAccountId; private iamDelegate; /** * * Create a new IamAssumeTokenManager instance. * * @param options - Configuration options. * This should be an object containing these fields: * - apikey: (required) the IAM api key * - iamProfileId: (optional) the ID of the trusted profile to use * - iamProfileCrn: (optional) the CRN of the trusted profile to use * - iamProfileName: (optional) the name of the trusted profile to use (must be specified with iamAccountId) * - iamAccountId: (optional) the ID of the account the trusted profile is in (must be specified with iamProfileName) * - url: (optional) the endpoint URL for the IAM token service (default value: "https://iam.cloud.ibm.com") * - disableSslVerification: (optional) a flag that indicates whether verification of the token server's SSL certificate * should be disabled or not * - headers: (optional) a set of HTTP headers to be sent with each request to the token service * - clientId: (optional) the "clientId" and "clientSecret" fields are used to form a Basic * Authorization header to be included in each request to the token service * - clientSecret: (optional) the "clientId" and "clientSecret" fields are used to form a Basic * Authorization header to be included in each request to the token service * - scope: (optional) the "scope" parameter to use when fetching the bearer token from the token service * * @throws Error: the configuration options are not valid. */ constructor(options: Options_15); /** * Request an IAM token using a standard access token and a trusted profile. */ protected requestToken(): Promise<any>; /** * Extend this method from the parent class to erase the refresh token from * the class - we do not want to expose it for IAM Assume authentication. * * @param tokenResponse - the response object from JWT service request */ protected saveTokenInfo(tokenResponse: any): void; /** * Sets the IAM "scope" value. * This value is sent as the "scope" form parameter in the IAM delegate request. * * @param scope - a space-separated string that contains one or more scope names */ setScope(scope: string): void; /** * Sets the IAM "clientId" and "clientSecret" values for the IAM delegate. * * @param clientId - the client id. * @param clientSecret - the client secret. */ setClientIdAndSecret(clientId: string, clientSecret: string): void; /** * Sets the "disableSslVerification" property for the IAM delegate. * * @param value - the new value for the disableSslVerification property */ setDisableSslVerification(value: boolean): void; /** * Sets the headers to be included in the IAM delegate's requests. * * @param headers - the set of headers to send with each request to the token server */ setHeaders(headers: OutgoingHttpHeaders): void; } /** * The IamAuthenticator will use the user-supplied `apikey` * value to obtain a bearer token from a token server. When the bearer token * expires, a new token is obtained from the token server. If specified, the * optional, mutually inclusive "clientId" and "clientSecret" pair can be used to * influence rate-limiting for requests to the IAM token server. * * The bearer token will be sent as an Authorization header in the form: * * Authorization: Bearer \<bearer-token\> */ export declare class IamAuthenticator extends IamRequestBasedAuthenticator { protected requiredOptions: string[]; protected tokenManager: IamTokenManager; private apikey; /** * * Create a new IamAuthenticator instance. * * @param options - Configuration options for IAM authentication. * This should be an object containing these fields: * - url: (optional) the endpoint URL for the token service * - apikey: (required) the IAM api key * - disableSslVerification: (optional) a flag that indicates whether verification of the token server's SSL certificate * should be disabled or not * - headers: (optional) a set of HTTP headers to be sent with each request to the token service * - clientId: (optional) the "clientId" and "clientSecret" fields are used to form a Basic * Authorization header to be included in each request to the token service * - clientSecret: (optional) the "clientId" and "clientSecret" fields are used to form a Basic * Authorization header to be included in each request to the token service * - scope: (optional) the "scope" parameter to use when fetching the bearer token from the token service * * @throws Error: the configuration options are not valid. */ constructor(options: Options_6); /** * Returns the authenticator's type ('iam'). * * @returns a string that indicates the authenticator's type */ authenticationType(): string; /** * Return the most recently stored refresh token. * * @returns the refresh token string */ getRefreshToken(): string; } /** * The IamRequestBasedAuthenticator provides shared configuration and functionality * for authenticators that interact with the IAM token service. This authenticator * is not meant for use on its own. */ export declare class IamRequestBasedAuthenticator extends IamRequestBasedAuthenticatorImmutable { /** * Setter for the mutually inclusive "clientId" and the "clientSecret" fields. * @param clientId - the "clientId" value used to form a Basic Authorization header for IAM token requests * @param clientSecret - the "clientSecret" value used to form a Basic Authorization header for IAM token requests */ setClientIdAndSecret(clientId: string, clientSecret: string): void; /** * Setter for the "scope" parameter to use when fetching the bearer token from the IAM token server. * @param scope - (optional) a space-separated string that specifies one or more scopes to be * associated with IAM token requests */ setScope(scope: string): void; /** * Set the flag that indicates whether verification of the server's SSL * certificate should be disabled or not. * * @param value - a flag that indicates whether verification of the * token server's SSL certificate should be disabled or not. */ setDisableSslVerification(value: boolean): void; /** * Set headers. * * @param headers - a set of HTTP headers to be sent with each outbound token server request. * Overwrites previous default headers. */ setHeaders(headers: OutgoingHttpHeaders): void; } /** * The IamRequestBasedAuthenticatorImmutable provides shared configuration and functionality * for authenticators that interact with the IAM token service. This authenticator * is not meant for use on its own. */ declare class IamRequestBasedAuthenticatorImmutable extends TokenRequestBasedAuthenticatorImmutable { protected tokenManager: IamRequestBasedTokenManager; protected clientId: string; protected clientSecret: string; protected scope: string; /** * * Create a new IamRequestBasedAuthenticatorImmutable instance. * * @param options - Configuration options for IAM authentication. * This should be an object containing these fields: * - url: (optional) the endpoint URL for the token service * - disableSslVerification: (optional) a flag that indicates whether verification of the token server's SSL certificate * should be disabled or not * - headers: (optional) a set of HTTP headers to be sent with each request to the token service * - clientId: (optional) the "clientId" and "clientSecret" fields are used to form a Basic * Authorization header to be included in each request to the token service * - clientSecret: (optional) the "clientId" and "clientSecret" fields are used to form a Basic * Authorization header to be included in each request to the token service * - scope: (optional) the "scope" parameter to use when fetching the bearer token from the token service * * @throws Error: the configuration options are not valid. */ constructor(options: IamRequestOptions_2); } /** * The IamRequestBasedTokenManager class contains code relevant to any token manager that * interacts with the IAM service to manage a token. It stores information relevant to all * IAM requests, such as the client ID and secret, and performs the token request with a set * of request options common to any IAM token management scheme. It is intended that this * class be extended with specific implementations. */ export declare class IamRequestBasedTokenManager extends JwtTokenManager { protected clientId: string; protected clientSecret: string; protected scope: string; protected refreshToken: string; protected formData: any; /** * * Create a new IamRequestBasedTokenManager instance. * * @param options - Configuration options. * This should be an object containing these fields: * - url: (optional) the endpoint URL for the token service (default value: "https://iam.cloud.ibm.com") * - disableSslVerification: (optional) a flag that indicates whether verification of the token server's SSL certificate * should be disabled or not * - headers: (optional) a set of HTTP headers to be sent with each request to the token service * - clientId: (optional) the "clientId" and "clientSecret" fields are used to form a Basic * Authorization header to be included in each request to the token service * - clientSecret: (optional) the "clientId" and "clientSecret" fields are used to form a Basic * Authorization header to be included in each request to the token service * - scope: (optional) the "scope" parameter to use when fetching the bearer token from the token service * * @throws Error: the configuration options are not valid. */ constructor(options: IamRequestOptions); /** * Sets the IAM "scope" value. * This value is sent as the "scope" form parameter within the request sent to the IAM token service. * * @param scope - a space-separated string that contains one or more scope names */ setScope(scope: string): void; /** * Sets the IAM "clientId" and "clientSecret" values. * These values are used to compute the Authorization header used * when retrieving the IAM access token. * If these values are not set, no Authorization header will be * set on the request (it is not required). * * @param clientId - the client id. * @param clientSecret - the client secret. */ setClientIdAndSecret(clientId: string, clientSecret: string): void; /** * Extend this method from the parent class to extract the refresh token from * the request and save it. * * @param tokenResponse - the response object from JWT service request */ protected saveTokenInfo(tokenResponse: any): void; /** * Request an IAM access token using an API key. * * @returns Promise */ protected requestToken(): Promise<any>; /** * Returns true iff the currently-cached IAM access token is expired. * We'll consider an access token as expired when we reach its IAM server-reported * expiration time minus our expiration window (10 secs). * We do this to avoid using an access token that might expire in the middle of a long-running * transaction within an IBM Cloud service. * * @returns true if the token has expired, false otherwise */ protected isTokenExpired(): boolean; } /** Configuration options for IAM token retrieval. */ export declare interface IamRequestOptions extends JwtTokenManagerOptions { clientId?: string; clientSecret?: string; scope?: string; } /** Configuration options for IAM Request based authentication. */ declare interface IamRequestOptions_2 extends BaseOptions { /** * The `clientId` and `clientSecret` fields are used to form a "basic" * authorization header for IAM token requests. */ clientId?: string; /** * The `clientId` and `clientSecret` fields are used to form a "basic" * authorization header for IAM token requests. */ clientSecret?: string; /** * The "scope" parameter to use when fetching the bearer token from the IAM token server. */ scope?: string; } /** * The IamTokenManager takes an api key and performs the necessary interactions with * the IAM token service to obtain and store a suitable bearer token. Additionally, the IamTokenManager * will retrieve bearer tokens via basic auth using a supplied "clientId" and "clientSecret" pair. */ export declare class IamTokenManager extends IamRequestBasedTokenManager { protected requiredOptions: string[]; private apikey; /** * * Create a new IamTokenManager instance. * * @param options - Configuration options. * This should be an object containing these fields: * - url: (optional) the endpoint URL for the IAM token service (default value: "https://iam.cloud.ibm.com") * - apikey: (required) the IAM api key * - disableSslVerification: (optional) a flag that indicates whether verification of the token server's SSL certificate * should be disabled or not * - headers: (optional) a set of HTTP headers to be sent with each request to the token service * - clientId: (optional) the "clientId" and "clientSecret" fields are used to form a Basic * Authorization header to be included in each request to the token service * - clientSecret: (optional) the "clientId" and "clientSecret" fields are used to form a Basic * Authorization header to be included in each request to the token service * - scope: (optional) the "scope" parameter to use when fetching the bearer token from the token service * * @throws Error: the configuration options are not valid. */ constructor(options: Options_5); /** * Returns the most recently stored refresh token. * * @returns the refresh token */ getRefreshToken(): string; } export declare function isEmptyObject(obj: any): boolean; export declare function isFileData(obj: any): obj is NodeJS.ReadableStream | Buffer; export declare function isFileWithMetadata(obj: any): obj is FileWithMetadata; /** * Return true if 'text' is html * @param text - The 'text' to analyze * @returns true if 'text' has html tags */ export declare function isHTML(text: string): boolean; /** * Returns true if and only if "mimeType" is a "JSON-like" mime type * (e.g. "application/json; charset=utf-8"). * @param mimeType - the mimeType string * @returns true if "mimeType" represents a JSON media type and false otherwise */ export declare function isJsonMimeType(mimeType: string): boolean; /** * A class for shared functionality for parsing, storing, and requesting * JWT tokens. Intended to be used as a parent to be extended for token * request management. Child classes should implement `requestToken()` * to retrieve the bearer token from intended sources. */ export declare class JwtTokenManager extends TokenManager { protected tokenName: string; protected tokenInfo: any; /** * Create a new JwtTokenManager instance. * * @param options - Configuration options. * This should be an object containing these fields: * - url: (optional) the endpoint URL for the token service * - disableSslVerification: (optional) a flag that indicates whether verification of the token server's SSL certificate * should be disabled or not * - headers: (optional) a set of HTTP headers to be sent with each request to the token service */ constructor(options: JwtTokenManagerOptions); /** * Request a JWT using an API key. * * @returns Promise */ protected requestToken(): Promise<any>; /** * Save the JWT service response and the calculated expiration time to the object's state. * * @param tokenResponse - the response object from JWT service request */ protected saveTokenInfo(tokenResponse: any): void; } /** Configuration options for JWT token retrieval. */ export declare type JwtTokenManagerOptions = TokenManagerOptions; /** * The McspAuthenticator uses an apikey to obtain an access token from the MCSP token server. * When the access token expires, a new access token is obtained from the token server. * The access token will be added to outbound requests via the Authorization header * of the form: "Authorization: Bearer <access-token>" */ export declare class McspAuthenticator extends TokenRequestBasedAuthenticator { protected requiredOptions: string[]; protected tokenManager: McspTokenManager; private apikey; /** * Create a new McspAuthenticator instance. * * @param options - Configuration options for CloudPakForData authentication. * This should be an object containing these fields: * - url: (required) the endpoint URL for the CloudPakForData token service * - apikey: (optional) the API key used to obtain a bearer token (required if password is not specified) * - disableSslVerification: (optional) a flag that indicates whether verification of the token server's SSL certificate * should be disabled or not * - headers: (optional) a set of HTTP headers to be sent with each request to the tok