Package Exports
- ibm-cloud-sdk-core
- ibm-cloud-sdk-core/lib/sdk-test-helpers
- ibm-cloud-sdk-core/lib/sdk-test-helpers.browser
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ibm-cloud-sdk-core) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
IBM Node.js SDK Core
This project contains core functionality required by Node.js code generated by the IBM Cloud OpenAPI SDK Generator (openapi-sdkgen).
Installation
`npm install ibm-cloud-sdk-core`Usage
This package exports a single object containing a number of modules as top level properties.
Example:
// this is TypeScript, since the `openapi-sdkgen` project generates TypeScript
import { BaseService } from 'ibm-cloud-sdk-core';
class YourSDK extends BaseService { ... }Authentication
This library provides a set of Authenticators used to authenticate requests from an SDK. There are authenticators for the following authentication schemes:
- No Auth
- Basic
- Bearer Token
- IAM
- CP4D
- Container
There are two ways to create an authenticator:
- Creating an instance and providing credentials programmatically
- Using the
getAuthenticatorFromEnvironmentfunction to create an authenticator from externally-provided configuration
For more information about the various authentication types and how to use them with your services, click here.
Examples
Programmatic
import { IamAuthenticator } from 'ibm-cloud-sdk-core';
const authenticator = new IamAuthenticator({
apikey: '{apikey}',
});External configuration
import { getAuthenticatorFromEnvironment } from 'ibm-cloud-sdk-core';
// env vars
// MY_SERVICE_AUTH_TYPE=iam
// MY_SERVICE_APIKEY=<apikey>
const iamAuthenticator = getAuthenticatorFromEnvironment('my-service');Logging
This package uses debug for logging.
- Logging is disabled by default.
- Logging has been configured to use log levels which are assumed to be numerically ascending from most important to least important.
- In order to see the log output, set the environment variable
DEBUGincluding the desired log level.DEBUG=ibm-cloud-sdk-core:errorenables error logsDEBUG=ibm-cloud-sdk-core:warningenables warning logs and belowDEBUG=ibm-cloud-sdk-core:infoenables info logs and belowDEBUG=ibm-cloud-sdk-core:verboseenables verbose logs and belowDEBUG=ibm-cloud-sdk-core:debugenables debug logs and below
To see the output from all of the debugging levels you can use:
DEBUG=ibm-cloud-sdk-core*
The debug logger can be configured to be used for more than one library. In example, you can set a comma-separated string:
DEBUG=ibm-cloud-sdk-core:debug,other-lib:debug
Cookie Jar Support
By default, cookies are not supported in the SDK requests. If your SDK would benefit from this functionality, simply edit your code to instantiate a cookie jar (or instruct your users to do so) and pass it in the object containing configuration options to the BaseService class, as shown below.
import tough = require('tough-cookie');
class MyClass extends BaseService {
constructor(options: MyOptions) {
// pass the cookie jar object or simply pass the value `true`
// and a tough-cookie instance will be created by default
options.jar = new tough.CookieJar();
super(options);
}
}The example above uses Tough Cookie to provide these capabilities, but other cookie jar libraries can be used.
Issues
If you encounter an issue with this project, you are welcome to submit a bug report. Before opening a new issue, please search for similar issues. It's possible that someone has already reported it.
Tests
Run all test suites:
npm testContributing
See CONTRIBUTING.
License
This library is licensed under Apache 2.0. Full license text is available in LICENSE.