node-sdk-core
This project contains the core functionality used by Node SDK's generated by the IBM OpenAPI 3 SDK Generator (openapi-sdkgen
).
Code generated by openapi-sdkgen
will depend on the functionality contained in this project.
Installation
npm install ibm-cloud-sdk-core
Usage
This package exports a single object containing a number of modules as top level properties.
Example:
import { BaseService } from 'ibm-cloud-sdk-core';
class YourSDK extends BaseService { ... }
Available Modules
BaseService
This Class is the base class that all generated service-specific classes inherit from. It implements credentials handling and other shared behavior.
IamTokenManagerV1
This Class contains logic for managing an IAM token over its lifetime. Tokens can be requested or set manually. When requested, the token manager will either return the current token, request a new token or refresh the current token if it is expired. If a token is manually set, it must be managed by the user.
isFileParam
This function takes an Object and returns true
if the object is a Stream, a Buffer, has a value
property, or has a data
property that is a file param (checked recursively).
isEmptyObject
This function takes an Object and returns true
if it is an empty object.
getContentType
This function attempts to retrieve the content type of the input and returns null
if not found.
stripTrailingSlash
This function takes a string and returns an identical string but with a forward slash removed from the end, if present.
getMissingParams
This function takes in a list of required parameters and a parameters object and returns null
if all required parameters are present and an Error if any are missing.
isHTML
This function returns true
if the given string is HTML.
getFormat
This function takes a parameters object and a list of "formats". It returns the first match from the formats array that is a key in the parameters object, or null
if there are no matches.
buildRequestFileObject
This function builds a "form-data" object for each file parameter.
toLowerKeys
This function takes an Object and returns the same object with all of the top-level keys converted to lower case. Note: it does not convert nested keys.
qs
This module includes one function, stringify
.
qs.stringify
This function takes an Object containing query parameters and returns a URI-encoded query String. This function is modified for use with Watson - the query parameter watson-token
will not be encoded, as the server requires non-encoded tokens for authentication.
contentType
This module includes two functions, fromHeader
and fromFilename
.
This function attempts to use the first bytes of a file to match the file contents with the associated mime type. Returns undefined
if no matching mime type is found.
contentType.fromFilename
This function attempts to parse the extension from a file and return the mime type associated with the file contents. Returns undefined
if no matching mime type is found.
streamToPromise
This function takes a Stream and converts it to a Promise that resolves with the final text, encoded with utf-8
.