Socket
Socket
Sign inDemoInstall

ibm-cloud-sdk-core

Package Overview
Dependencies
Maintainers
1
Versions
143
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ibm-cloud-sdk-core - npm Package Compare versions

Comparing version 1.0.0-rc5 to 1.0.0

auth/utils/read-credentials-file.browser.d.ts

4

auth/authenticators/basic-authenticator.d.ts

@@ -19,4 +19,4 @@ /**

export declare type Options = {
username?: string;
password?: string;
username: string;
password: string;
};

@@ -23,0 +23,0 @@ export declare class BasicAuthenticator extends Authenticator implements AuthenticatorInterface {

@@ -18,3 +18,3 @@ /**

import { OutgoingHttpHeaders } from 'http';
import { RequestWrapper } from '../../lib/requestwrapper';
import { RequestWrapper } from '../../lib/request-wrapper';
export declare type TokenManagerOptions = {

@@ -21,0 +21,0 @@ url?: string;

@@ -20,3 +20,3 @@ "use strict";

var jwt = require("jsonwebtoken");
var requestwrapper_1 = require("../../lib/requestwrapper");
var request_wrapper_1 = require("../../lib/request-wrapper");
function getCurrentTime() {

@@ -48,3 +48,3 @@ return Math.floor(Date.now() / 1000);

// any config options for the internal request library, like `proxy`, will be passed here
this.requestWrapperInstance = new requestwrapper_1.RequestWrapper(options);
this.requestWrapperInstance = new request_wrapper_1.RequestWrapper(options);
}

@@ -51,0 +51,0 @@ /**

@@ -0,1 +1,46 @@

# [1.0.0](https://github.com/IBM/node-sdk-core/compare/v0.3.6...v1.0.0) (2019-10-03)
### Bug Fixes
* Move check for serviceUrl to createRequest ([#47](https://github.com/IBM/node-sdk-core/issues/47)) ([6f04739](https://github.com/IBM/node-sdk-core/commit/6f04739))
* parse result from response in token managers ([6bbe423](https://github.com/IBM/node-sdk-core/commit/6bbe423))
* provide bundlers alternate file for browser support ([#58](https://github.com/IBM/node-sdk-core/issues/58)) ([88a9d16](https://github.com/IBM/node-sdk-core/commit/88a9d16))
### Build System
* drop support for Node versions 6 and 8 ([#33](https://github.com/IBM/node-sdk-core/issues/33)) ([d47c737](https://github.com/IBM/node-sdk-core/commit/d47c737))
### Code Refactoring
* look for credentials file in working dir before home dir ([#46](https://github.com/IBM/node-sdk-core/issues/46)) ([c5556de](https://github.com/IBM/node-sdk-core/commit/c5556de))
* return detailed response as second callback argument ([#34](https://github.com/IBM/node-sdk-core/issues/34)) ([dc24154](https://github.com/IBM/node-sdk-core/commit/dc24154))
### Features
* add `setServiceUrl` method as a setter for the `serviceUrl` property ([#41](https://github.com/IBM/node-sdk-core/issues/41)) ([cfb188f](https://github.com/IBM/node-sdk-core/commit/cfb188f))
* add specific error handling for SSL errors with cloud private instances ([#54](https://github.com/IBM/node-sdk-core/issues/54)) ([056ec9a](https://github.com/IBM/node-sdk-core/commit/056ec9a))
* export `UserOptions` interface from the BaseService ([#50](https://github.com/IBM/node-sdk-core/issues/50)) ([4f0075a](https://github.com/IBM/node-sdk-core/commit/4f0075a))
* implement new authenticators to handle sdk authentication ([#37](https://github.com/IBM/node-sdk-core/issues/37)) ([f876b6d](https://github.com/IBM/node-sdk-core/commit/f876b6d))
* refactor core to use Promises instead of callbacks ([#55](https://github.com/IBM/node-sdk-core/issues/55)) ([9ec8afd](https://github.com/IBM/node-sdk-core/commit/9ec8afd))
### BREAKING CHANGES
* None of the authenticators or request methods take callbacks as arguments anymore - they return Promises instead.
* Users that have credential files in both the working directory and the home directory will see a change in which one is used.
* The internal property `url` no longer exists on the `baseOptions` object, it has been renamed to `serviceUrl`
* The old style of passing credentials to the base service will no longer work. An Authenticator instance MUST be passed in to the base service constructor.
* token managers no longer support user access tokens. use BearerTokenAuthenticator instead
* The class names of the token managers have changed.
* `Icp4dTokenManagerV1` renamed to `Cp4dTokenManager`
* `IamTokenManagerV1` renamed to `IamTokenManager`
* `JwtTokenManagerV1` renamed to `JwtTokenManager`
* The public method `setAuthorizationInfo` is renamed to `setClientIdAndSecret`
* The response body is no longer the 2nd callback argument, the detailed response is. The body is located under the `result` property. The `data` property is removed.
* This SDK may no longer work with applications running on Node 6 or 8.
## [0.3.6](https://github.com/IBM/node-sdk-core/compare/v0.3.5...v0.3.6) (2019-09-16)

@@ -2,0 +47,0 @@

@@ -19,3 +19,3 @@ /**

*/
export { BaseService, UserOptions } from './lib/base_service';
export { BaseService, UserOptions } from './lib/base-service';
export * from './auth';

@@ -22,0 +22,0 @@ export * from './lib/helper';

@@ -24,3 +24,3 @@ "use strict";

*/
var base_service_1 = require("./lib/base_service");
var base_service_1 = require("./lib/base-service");
exports.BaseService = base_service_1.BaseService;

@@ -27,0 +27,0 @@ __export(require("./auth"));

@@ -72,10 +72,10 @@ /**

*
* @param {Object} parameters - service request options passed in by user.
* @param {string} parameters.options.method - the http method.
* @param {string} parameters.options.url - the path portion of the URL to be appended to the serviceUrl
* @param {string} parameters.options.path - the path to be appended to the service URL.
* @param {string} parameters.options.qs - the querystring to be included in the URL.
* @param {string} parameters.options.body - the data to be sent as the request body.
* @param {Object} parameters.options.form - an object containing the key/value pairs for a www-form-urlencoded request.
* @param {Object} parameters.options.formData - an object containing the contents for a multipart/form-data request.
* @param {object} parameters - service request options passed in by user
* @param {string} parameters.options.method - the http method
* @param {string} parameters.options.url - the path portion of the URL to be appended to the serviceUr
* @param {object} [parameters.options.path] - the path parameters to be inserted into the URL
* @param {object} [parameters.options.qs] - the querystring to be included in the URL
* @param {object} [parameters.options.body] - the data to be sent as the request body
* @param {object} [parameters.options.form] - an object containing the key/value pairs for a www-form-urlencoded request
* @param {object} [parameters.options.formData] - an object containing the contents for a multipart/form-data request
* The following processing is performed on formData values:

@@ -86,5 +86,5 @@ * - string: no special processing -- the value is sent as is

* - array: each element of the array is sent as a separate form part using any special processing as described above
* @param {Object} parameters.defaultOptions
* @param {object} parameters.defaultOptions
* @param {string} parameters.defaultOptions.serviceUrl - the base URL of the service
* @param {OutgoingHttpHeaders} parameters.defaultOptions.headers - additional headers to be passed on the request.
* @param {OutgoingHttpHeaders} parameters.defaultOptions.headers - additional headers to be passed on the request
* @returns {Promise<any>}

@@ -91,0 +91,0 @@ */

@@ -85,10 +85,10 @@ "use strict";

*
* @param {Object} parameters - service request options passed in by user.
* @param {string} parameters.options.method - the http method.
* @param {string} parameters.options.url - the path portion of the URL to be appended to the serviceUrl
* @param {string} parameters.options.path - the path to be appended to the service URL.
* @param {string} parameters.options.qs - the querystring to be included in the URL.
* @param {string} parameters.options.body - the data to be sent as the request body.
* @param {Object} parameters.options.form - an object containing the key/value pairs for a www-form-urlencoded request.
* @param {Object} parameters.options.formData - an object containing the contents for a multipart/form-data request.
* @param {object} parameters - service request options passed in by user
* @param {string} parameters.options.method - the http method
* @param {string} parameters.options.url - the path portion of the URL to be appended to the serviceUr
* @param {object} [parameters.options.path] - the path parameters to be inserted into the URL
* @param {object} [parameters.options.qs] - the querystring to be included in the URL
* @param {object} [parameters.options.body] - the data to be sent as the request body
* @param {object} [parameters.options.form] - an object containing the key/value pairs for a www-form-urlencoded request
* @param {object} [parameters.options.formData] - an object containing the contents for a multipart/form-data request
* The following processing is performed on formData values:

@@ -99,5 +99,5 @@ * - string: no special processing -- the value is sent as is

* - array: each element of the array is sent as a separate form part using any special processing as described above
* @param {Object} parameters.defaultOptions
* @param {object} parameters.defaultOptions
* @param {string} parameters.defaultOptions.serviceUrl - the base URL of the service
* @param {OutgoingHttpHeaders} parameters.defaultOptions.headers - additional headers to be passed on the request.
* @param {OutgoingHttpHeaders} parameters.defaultOptions.headers - additional headers to be passed on the request
* @returns {Promise<any>}

@@ -104,0 +104,0 @@ */

{
"name": "ibm-cloud-sdk-core",
"version": "1.0.0-rc5",
"version": "1.0.0",
"description": "Core functionality to support SDKs generated with IBM's OpenAPI 3 SDK Generator.",

@@ -73,2 +73,5 @@ "main": "./index",

},
"browser": {
"./auth/utils/read-credentials-file": "./auth/utils/read-credentials-file.browser"
},
"engines": {

@@ -88,3 +91,3 @@ "node": ">=10"

"jest": "jest",
"test": "jest --verbose test/unit/",
"test": "jest test/unit/",
"test-travis": "jest --runInBand test/unit/",

@@ -91,0 +94,0 @@ "report-coverage": "codecov",

@@ -11,5 +11,2 @@ [![Build Status](https://travis-ci.com/IBM/node-sdk-core.svg?branch=master)](https://travis-ci.com/IBM/node-sdk-core)

## Notice
Support for Node versions **6** and **8** is deprecated and will be officially dropped in the next major release, which is expected to be in September, 2019. Version 6 reached end of life in April 2019 and Version 8 reaches end of life on 31 December 2019.
## Installation

@@ -23,3 +20,2 @@ `npm install ibm-cloud-sdk-core`

```js
// do some stuff
// this is TypeScript, since the `openapi-sdkgen` project generates TypeScript

@@ -31,62 +27,125 @@ import { BaseService } from 'ibm-cloud-sdk-core';

## Authentication Types
There are several flavors of authentication supported in this package. To specify the intended authentication pattern to use, the user can pass in the parameter `authentication_type`. This parameter is optional, but it may become required in a future major release. The options for this parameter are `basic`, `iam`, and `icp4d`.
## 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
### basic
This indicates Basic Auth is to be used. Users will pass in a `username` and `password` and the SDK will generate a Basic Auth header to send with requests to the service.
There are two ways to create an authenticator:
1. Creating an instance and providing credentials programmatically
2. Using the `getAuthenticatorFromEnvironment` function to create an authenticator from externally-provided configuration
### iam
This indicates that IAM token authentication is to be used. Users can pass in an `iam_apikey` or an `iam_access_token`. If an API key is used, the SDK will manage the token for the user. In either case, the SDK will generate a Bearer Auth header to send with requests to the service.
### NoAuth
Used for sending requests to an unprotected service or for testing.
### icp4d
This indicates that the service is an instance of ICP4D, which has its own version of token authentication. Users can pass in a `username` and `password`, or an `icp4d_access_token`. If a username and password is given, the SDK will manage the token for the user.
A `url` is **required** for this type. In order to use an SDK-managed token with ICP4D authentication, this option **must** be passed in.
Programmatic:
```js
import { NoAuthAuthenticator } from 'ibm-cloud-sdk-core';
## 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.
const authenticator = new NoAuthAuthenticator();
```
### 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 or request a new token if one is not saved or the the current token is expired. If a token is manually set, it must be managed by the user.
External config:
```js
import { getAuthenticatorFromEnvironment } from 'ibm-cloud-sdk-core';
### Icp4dTokenManagerV1
This Class is similar in function to IamTokenManagerV1. The only difference is that the `url` parameter is required, it takes a `username` and `password` instead of an API key, and manages tokens for instances of ICP4D. To use this token manager in an SDK, the parameter `authentication_type` must be set to `icp4d` in the constructor.
// env vars
// MY_SERVICE_AUTH_TYPE=noauth
const noAuthAuthenticator = getAuthenticatorFromEnvironment('my-service');
```
### isEmptyObject
This function takes an Object and returns `true` if it is an empty object.
### Basic
Used to generate an Authorization header with the format `Basic <encoded credentials>`.
### getContentType
This function attempts to retrieve the content type of the input and returns `null` if not found.
Programmatic:
```js
import { BasicAuthenticator } from 'ibm-cloud-sdk-core';
### stripTrailingSlash
This function takes a string and returns an identical string but with a forward slash removed from the end, if present.
const authenticator = new BasicAuthenticator({
username: '{username}',
password: '{password}',
});
```
### 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.
External config:
```js
import { getAuthenticatorFromEnvironment } from 'ibm-cloud-sdk-core';
### isHTML
This function returns `true` if the given string is HTML.
// env vars
// MY_SERVICE_AUTH_TYPE=basic
// MY_SERVICE_USERNAME=<username>
// MY_SERVICE_PASSWORD=<password>
const basicAuthenticator = getAuthenticatorFromEnvironment('my-service');
```
### 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.
### Bearer Token
Used to generate an Authorization header with the format `Bearer <token>`.
### 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.
Programmatic:
```js
import { BearerTokenAuthenticator } from 'ibm-cloud-sdk-core';
### qs
This module includes one function, `stringify`.
const authenticator = new BearerTokenAuthenticator({
bearerToken: '{bearerToken}',
});
```
#### 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.
External config:
```js
import { getAuthenticatorFromEnvironment } from 'ibm-cloud-sdk-core';
### contentType
This module includes two functions, `fromHeader` and `fromFilename`.
// env vars
// MY_SERVICE_AUTH_TYPE=bearerToken
// MY_SERVICE_BEARER_TOKEN=<bearerToken>
const bearerTokenAuthenticator = getAuthenticatorFromEnvironment('my-service');
```
#### contentType.fromHeader
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.
### IAM
Used to manage and authenticate with IAM tokens.
#### 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.
Programmatic:
```js
import { IamAuthenticator } from 'ibm-cloud-sdk-core';
### streamToPromise
This function takes a Stream and converts it to a Promise that resolves with the final text, encoded with `utf-8`.
const authenticator = new IamAuthenticator({
apikey: '{apikey}',
});
```
External config:
```js
import { getAuthenticatorFromEnvironment } from 'ibm-cloud-sdk-core';
// env vars
// MY_SERVICE_AUTH_TYPE=iam
// MY_SERVICE_APIKEY=<apikey>
const iamAuthenticator = getAuthenticatorFromEnvironment('my-service');
```
### CloudPakForData
Used to manage and authenticate with tokens for services on IBM Cloud Pak for Data.
Programmatic:
```js
import { CloudPakForDataAuthenticator } from 'ibm-cloud-sdk-core';
const authenticator = new CloudPakForDataAuthenticator({
username: '{username}',
password: '{password}',
url: '{url}',
});
```
External config:
```js
import { getAuthenticatorFromEnvironment } from 'ibm-cloud-sdk-core';
// env vars
// MY_SERVICE_AUTH_TYPE=cp4d
// MY_SERVICE_AUTH_URL=<url>
// MY_SERVICE_USERNAME=<username>
// MY_SERVICE_PASSWORD=<password>
const cp4dAuthenticator = getAuthenticatorFromEnvironment('my-service');
```

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc