watson-developer-cloud
Version:
Client library to use the IBM Watson Services
1,079 lines • 193 kB
JavaScript
"use strict";
/**
* Copyright 2018 IBM All Rights Reserved.
*
* 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.
*/
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var extend = require("extend");
var ibm_cloud_sdk_core_1 = require("ibm-cloud-sdk-core");
var common_1 = require("../lib/common");
/**
* The IBM Watson™ Discovery Service is a cognitive search and content analytics engine that you can add to applications to identify patterns, trends and actionable insights to drive better decision-making. Securely unify structured and unstructured data with pre-enriched content, and use a simplified query language to eliminate the need for manual filtering of results.
*/
var DiscoveryV1 = /** @class */ (function (_super) {
__extends(DiscoveryV1, _super);
/**
* Construct a DiscoveryV1 object.
*
* @param {Object} options - Options for the service.
* @param {string} options.version - The API version date to use with the service, in "YYYY-MM-DD" format. Whenever the API is changed in a backwards incompatible way, a new minor version of the API is released. The service uses the API version for the date you specify, or the most recent version before that date. Note that you should not programmatically specify the current date at runtime, in case the API has been updated since your application's release. Instead, specify a version date that is compatible with your application, and don't change it until your application is ready for a later version.
* @param {string} [options.url] - The base url to use when contacting the service (e.g. 'https://gateway.watsonplatform.net/discovery/api'). The base url may differ between Bluemix regions.
* @param {string} [options.username] - The username used to authenticate with the service. Username and password credentials are only required to run your application locally or outside of Bluemix. When running on Bluemix, the credentials will be automatically loaded from the `VCAP_SERVICES` environment variable.
* @param {string} [options.password] - The password used to authenticate with the service. Username and password credentials are only required to run your application locally or outside of Bluemix. When running on Bluemix, the credentials will be automatically loaded from the `VCAP_SERVICES` environment variable.
* @param {string} [options.iam_access_token] - An IAM access token fully managed by the application. Responsibility falls on the application to refresh the token, either before it expires or reactively upon receiving a 401 from the service, as any requests made with an expired token will fail.
* @param {string} [options.iam_apikey] - An API key that can be used to request IAM tokens. If this API key is provided, the SDK will manage the token and handle the refreshing.
* @param {string} [options.iam_url] - An optional URL for the IAM service API. Defaults to 'https://iam.bluemix.net/identity/token'.
* @param {boolean} [options.use_unauthenticated] - Set to `true` to avoid including an authorization header. This option may be useful for requests that are proxied.
* @param {Object} [options.headers] - Default headers that shall be included with every request to the service.
* @param {boolean} [options.headers.X-Watson-Learning-Opt-Out] - Set to `true` to opt-out of data collection. By default, all IBM Watson services log requests and their results. Logging is done only to improve the services for future users. The logged data is not shared or made public. If you are concerned with protecting the privacy of users' personal information or otherwise do not want your requests to be logged, you can opt out of logging.
* @constructor
* @returns {DiscoveryV1}
* @throws {Error}
*/
function DiscoveryV1(options) {
var _this = _super.call(this, options) || this;
// check if 'version' was provided
if (typeof _this._options.version === 'undefined') {
throw new Error('Argument error: version was not specified');
}
_this._options.qs.version = options.version;
return _this;
}
/*************************
* environments
************************/
/**
* Create an environment.
*
* Creates a new environment for private data. An environment must be created before collections can be created.
*
* **Note**: You can create only one environment for private data per service instance. An attempt to create another
* environment results in an error.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.name - Name that identifies the environment.
* @param {string} [params.description] - Description of the environment.
* @param {string} [params.size] - Size of the environment. In the Lite plan the default and only accepted value is
* `LT`, in all other plans the default is `S`.
* @param {Object} [params.headers] - Custom request headers
* @param {Function} [callback] - The callback that handles the response.
* @returns {Promise<any>|void}
*/
DiscoveryV1.prototype.createEnvironment = function (params, callback) {
var _this = this;
var _params = extend({}, params);
var _callback = callback;
var requiredParams = ['name'];
if (!_callback) {
return new Promise(function (resolve, reject) {
_this.createEnvironment(params, function (err, bod, res) {
err ? reject(err) : _params.return_response ? resolve(res) : resolve(bod);
});
});
}
var missingParams = ibm_cloud_sdk_core_1.getMissingParams(_params, requiredParams);
if (missingParams) {
return _callback(missingParams);
}
var body = {
'name': _params.name,
'description': _params.description,
'size': _params.size
};
var sdkHeaders = common_1.getSdkHeaders('discovery', 'v1', 'createEnvironment');
var parameters = {
options: {
url: '/v1/environments',
method: 'POST',
body: body,
},
defaultOptions: extend(true, {}, this._options, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters, _callback);
};
;
/**
* Delete environment.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.environment_id - The ID of the environment.
* @param {Object} [params.headers] - Custom request headers
* @param {Function} [callback] - The callback that handles the response.
* @returns {Promise<any>|void}
*/
DiscoveryV1.prototype.deleteEnvironment = function (params, callback) {
var _this = this;
var _params = extend({}, params);
var _callback = callback;
var requiredParams = ['environment_id'];
if (!_callback) {
return new Promise(function (resolve, reject) {
_this.deleteEnvironment(params, function (err, bod, res) {
err ? reject(err) : _params.return_response ? resolve(res) : resolve(bod);
});
});
}
var missingParams = ibm_cloud_sdk_core_1.getMissingParams(_params, requiredParams);
if (missingParams) {
return _callback(missingParams);
}
var path = {
'environment_id': _params.environment_id
};
var sdkHeaders = common_1.getSdkHeaders('discovery', 'v1', 'deleteEnvironment');
var parameters = {
options: {
url: '/v1/environments/{environment_id}',
method: 'DELETE',
path: path,
},
defaultOptions: extend(true, {}, this._options, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters, _callback);
};
;
/**
* Get environment info.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.environment_id - The ID of the environment.
* @param {Object} [params.headers] - Custom request headers
* @param {Function} [callback] - The callback that handles the response.
* @returns {Promise<any>|void}
*/
DiscoveryV1.prototype.getEnvironment = function (params, callback) {
var _this = this;
var _params = extend({}, params);
var _callback = callback;
var requiredParams = ['environment_id'];
if (!_callback) {
return new Promise(function (resolve, reject) {
_this.getEnvironment(params, function (err, bod, res) {
err ? reject(err) : _params.return_response ? resolve(res) : resolve(bod);
});
});
}
var missingParams = ibm_cloud_sdk_core_1.getMissingParams(_params, requiredParams);
if (missingParams) {
return _callback(missingParams);
}
var path = {
'environment_id': _params.environment_id
};
var sdkHeaders = common_1.getSdkHeaders('discovery', 'v1', 'getEnvironment');
var parameters = {
options: {
url: '/v1/environments/{environment_id}',
method: 'GET',
path: path,
},
defaultOptions: extend(true, {}, this._options, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters, _callback);
};
;
/**
* List environments.
*
* List existing environments for the service instance.
*
* @param {Object} [params] - The parameters to send to the service.
* @param {string} [params.name] - Show only the environment with the given name.
* @param {Object} [params.headers] - Custom request headers
* @param {Function} [callback] - The callback that handles the response.
* @returns {Promise<any>|void}
*/
DiscoveryV1.prototype.listEnvironments = function (params, callback) {
var _this = this;
var _params = (typeof params === 'function' && !callback) ? {} : extend({}, params);
var _callback = (typeof params === 'function' && !callback) ? params : callback;
if (!_callback) {
return new Promise(function (resolve, reject) {
_this.listEnvironments(params, function (err, bod, res) {
err ? reject(err) : _params.return_response ? resolve(res) : resolve(bod);
});
});
}
var query = {
'name': _params.name
};
var sdkHeaders = common_1.getSdkHeaders('discovery', 'v1', 'listEnvironments');
var parameters = {
options: {
url: '/v1/environments',
method: 'GET',
qs: query,
},
defaultOptions: extend(true, {}, this._options, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters, _callback);
};
;
/**
* List fields across collections.
*
* Gets a list of the unique fields (and their types) stored in the indexes of the specified collections.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.environment_id - The ID of the environment.
* @param {string[]} params.collection_ids - A comma-separated list of collection IDs to be queried against.
* @param {Object} [params.headers] - Custom request headers
* @param {Function} [callback] - The callback that handles the response.
* @returns {Promise<any>|void}
*/
DiscoveryV1.prototype.listFields = function (params, callback) {
var _this = this;
var _params = extend({}, params);
var _callback = callback;
var requiredParams = ['environment_id', 'collection_ids'];
if (!_callback) {
return new Promise(function (resolve, reject) {
_this.listFields(params, function (err, bod, res) {
err ? reject(err) : _params.return_response ? resolve(res) : resolve(bod);
});
});
}
var missingParams = ibm_cloud_sdk_core_1.getMissingParams(_params, requiredParams);
if (missingParams) {
return _callback(missingParams);
}
var query = {
'collection_ids': _params.collection_ids
};
var path = {
'environment_id': _params.environment_id
};
var sdkHeaders = common_1.getSdkHeaders('discovery', 'v1', 'listFields');
var parameters = {
options: {
url: '/v1/environments/{environment_id}/fields',
method: 'GET',
qs: query,
path: path,
},
defaultOptions: extend(true, {}, this._options, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters, _callback);
};
;
/**
* Update an environment.
*
* Updates an environment. The environment's **name** and **description** parameters can be changed. You must specify
* a **name** for the environment.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.environment_id - The ID of the environment.
* @param {string} [params.name] - Name that identifies the environment.
* @param {string} [params.description] - Description of the environment.
* @param {string} [params.size] - Size that the environment should be increased to. Environment size cannot be
* modified when using a Lite plan. Environment size can only increased and not decreased.
* @param {Object} [params.headers] - Custom request headers
* @param {Function} [callback] - The callback that handles the response.
* @returns {Promise<any>|void}
*/
DiscoveryV1.prototype.updateEnvironment = function (params, callback) {
var _this = this;
var _params = extend({}, params);
var _callback = callback;
var requiredParams = ['environment_id'];
if (!_callback) {
return new Promise(function (resolve, reject) {
_this.updateEnvironment(params, function (err, bod, res) {
err ? reject(err) : _params.return_response ? resolve(res) : resolve(bod);
});
});
}
var missingParams = ibm_cloud_sdk_core_1.getMissingParams(_params, requiredParams);
if (missingParams) {
return _callback(missingParams);
}
var body = {
'name': _params.name,
'description': _params.description,
'size': _params.size
};
var path = {
'environment_id': _params.environment_id
};
var sdkHeaders = common_1.getSdkHeaders('discovery', 'v1', 'updateEnvironment');
var parameters = {
options: {
url: '/v1/environments/{environment_id}',
method: 'PUT',
body: body,
path: path,
},
defaultOptions: extend(true, {}, this._options, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters, _callback);
};
;
/*************************
* configurations
************************/
/**
* Add configuration.
*
* Creates a new configuration.
*
* If the input configuration contains the **configuration_id**, **created**, or **updated** properties, then they are
* ignored and overridden by the system, and an error is not returned so that the overridden fields do not need to be
* removed when copying a configuration.
*
* The configuration can contain unrecognized JSON fields. Any such fields are ignored and do not generate an error.
* This makes it easier to use newer configuration files with older versions of the API and the service. It also makes
* it possible for the tooling to add additional metadata and information to the configuration.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.environment_id - The ID of the environment.
* @param {string} params.name - The name of the configuration.
* @param {string} [params.description] - The description of the configuration, if available.
* @param {Conversions} [params.conversions] - Document conversion settings.
* @param {Enrichment[]} [params.enrichments] - An array of document enrichment settings for the configuration.
* @param {NormalizationOperation[]} [params.normalizations] - Defines operations that can be used to transform the
* final output JSON into a normalized form. Operations are executed in the order that they appear in the array.
* @param {Source} [params.source] - Object containing source parameters for the configuration.
* @param {Object} [params.headers] - Custom request headers
* @param {Function} [callback] - The callback that handles the response.
* @returns {Promise<any>|void}
*/
DiscoveryV1.prototype.createConfiguration = function (params, callback) {
var _this = this;
var _params = extend({}, params);
var _callback = callback;
var requiredParams = ['environment_id', 'name'];
if (!_callback) {
return new Promise(function (resolve, reject) {
_this.createConfiguration(params, function (err, bod, res) {
err ? reject(err) : _params.return_response ? resolve(res) : resolve(bod);
});
});
}
var missingParams = ibm_cloud_sdk_core_1.getMissingParams(_params, requiredParams);
if (missingParams) {
return _callback(missingParams);
}
var body = {
'name': _params.name,
'description': _params.description,
'conversions': _params.conversions,
'enrichments': _params.enrichments,
'normalizations': _params.normalizations,
'source': _params.source
};
var path = {
'environment_id': _params.environment_id
};
var sdkHeaders = common_1.getSdkHeaders('discovery', 'v1', 'createConfiguration');
var parameters = {
options: {
url: '/v1/environments/{environment_id}/configurations',
method: 'POST',
body: body,
path: path,
},
defaultOptions: extend(true, {}, this._options, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters, _callback);
};
;
/**
* Delete a configuration.
*
* The deletion is performed unconditionally. A configuration deletion request succeeds even if the configuration is
* referenced by a collection or document ingestion. However, documents that have already been submitted for
* processing continue to use the deleted configuration. Documents are always processed with a snapshot of the
* configuration as it existed at the time the document was submitted.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.environment_id - The ID of the environment.
* @param {string} params.configuration_id - The ID of the configuration.
* @param {Object} [params.headers] - Custom request headers
* @param {Function} [callback] - The callback that handles the response.
* @returns {Promise<any>|void}
*/
DiscoveryV1.prototype.deleteConfiguration = function (params, callback) {
var _this = this;
var _params = extend({}, params);
var _callback = callback;
var requiredParams = ['environment_id', 'configuration_id'];
if (!_callback) {
return new Promise(function (resolve, reject) {
_this.deleteConfiguration(params, function (err, bod, res) {
err ? reject(err) : _params.return_response ? resolve(res) : resolve(bod);
});
});
}
var missingParams = ibm_cloud_sdk_core_1.getMissingParams(_params, requiredParams);
if (missingParams) {
return _callback(missingParams);
}
var path = {
'environment_id': _params.environment_id,
'configuration_id': _params.configuration_id
};
var sdkHeaders = common_1.getSdkHeaders('discovery', 'v1', 'deleteConfiguration');
var parameters = {
options: {
url: '/v1/environments/{environment_id}/configurations/{configuration_id}',
method: 'DELETE',
path: path,
},
defaultOptions: extend(true, {}, this._options, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters, _callback);
};
;
/**
* Get configuration details.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.environment_id - The ID of the environment.
* @param {string} params.configuration_id - The ID of the configuration.
* @param {Object} [params.headers] - Custom request headers
* @param {Function} [callback] - The callback that handles the response.
* @returns {Promise<any>|void}
*/
DiscoveryV1.prototype.getConfiguration = function (params, callback) {
var _this = this;
var _params = extend({}, params);
var _callback = callback;
var requiredParams = ['environment_id', 'configuration_id'];
if (!_callback) {
return new Promise(function (resolve, reject) {
_this.getConfiguration(params, function (err, bod, res) {
err ? reject(err) : _params.return_response ? resolve(res) : resolve(bod);
});
});
}
var missingParams = ibm_cloud_sdk_core_1.getMissingParams(_params, requiredParams);
if (missingParams) {
return _callback(missingParams);
}
var path = {
'environment_id': _params.environment_id,
'configuration_id': _params.configuration_id
};
var sdkHeaders = common_1.getSdkHeaders('discovery', 'v1', 'getConfiguration');
var parameters = {
options: {
url: '/v1/environments/{environment_id}/configurations/{configuration_id}',
method: 'GET',
path: path,
},
defaultOptions: extend(true, {}, this._options, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters, _callback);
};
;
/**
* List configurations.
*
* Lists existing configurations for the service instance.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.environment_id - The ID of the environment.
* @param {string} [params.name] - Find configurations with the given name.
* @param {Object} [params.headers] - Custom request headers
* @param {Function} [callback] - The callback that handles the response.
* @returns {Promise<any>|void}
*/
DiscoveryV1.prototype.listConfigurations = function (params, callback) {
var _this = this;
var _params = extend({}, params);
var _callback = callback;
var requiredParams = ['environment_id'];
if (!_callback) {
return new Promise(function (resolve, reject) {
_this.listConfigurations(params, function (err, bod, res) {
err ? reject(err) : _params.return_response ? resolve(res) : resolve(bod);
});
});
}
var missingParams = ibm_cloud_sdk_core_1.getMissingParams(_params, requiredParams);
if (missingParams) {
return _callback(missingParams);
}
var query = {
'name': _params.name
};
var path = {
'environment_id': _params.environment_id
};
var sdkHeaders = common_1.getSdkHeaders('discovery', 'v1', 'listConfigurations');
var parameters = {
options: {
url: '/v1/environments/{environment_id}/configurations',
method: 'GET',
qs: query,
path: path,
},
defaultOptions: extend(true, {}, this._options, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters, _callback);
};
;
/**
* Update a configuration.
*
* Replaces an existing configuration.
* * Completely replaces the original configuration.
* * The **configuration_id**, **updated**, and **created** fields are accepted in the request, but they are
* ignored, and an error is not generated. It is also acceptable for users to submit an updated configuration with
* none of the three properties.
* * Documents are processed with a snapshot of the configuration as it was at the time the document was submitted
* to be ingested. This means that already submitted documents will not see any updates made to the configuration.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.environment_id - The ID of the environment.
* @param {string} params.configuration_id - The ID of the configuration.
* @param {string} params.name - The name of the configuration.
* @param {string} [params.description] - The description of the configuration, if available.
* @param {Conversions} [params.conversions] - Document conversion settings.
* @param {Enrichment[]} [params.enrichments] - An array of document enrichment settings for the configuration.
* @param {NormalizationOperation[]} [params.normalizations] - Defines operations that can be used to transform the
* final output JSON into a normalized form. Operations are executed in the order that they appear in the array.
* @param {Source} [params.source] - Object containing source parameters for the configuration.
* @param {Object} [params.headers] - Custom request headers
* @param {Function} [callback] - The callback that handles the response.
* @returns {Promise<any>|void}
*/
DiscoveryV1.prototype.updateConfiguration = function (params, callback) {
var _this = this;
var _params = extend({}, params);
var _callback = callback;
var requiredParams = ['environment_id', 'configuration_id', 'name'];
if (!_callback) {
return new Promise(function (resolve, reject) {
_this.updateConfiguration(params, function (err, bod, res) {
err ? reject(err) : _params.return_response ? resolve(res) : resolve(bod);
});
});
}
var missingParams = ibm_cloud_sdk_core_1.getMissingParams(_params, requiredParams);
if (missingParams) {
return _callback(missingParams);
}
var body = {
'name': _params.name,
'description': _params.description,
'conversions': _params.conversions,
'enrichments': _params.enrichments,
'normalizations': _params.normalizations,
'source': _params.source
};
var path = {
'environment_id': _params.environment_id,
'configuration_id': _params.configuration_id
};
var sdkHeaders = common_1.getSdkHeaders('discovery', 'v1', 'updateConfiguration');
var parameters = {
options: {
url: '/v1/environments/{environment_id}/configurations/{configuration_id}',
method: 'PUT',
body: body,
path: path,
},
defaultOptions: extend(true, {}, this._options, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters, _callback);
};
;
/*************************
* testYourConfigurationOnADocument
************************/
/**
* Test configuration.
*
* Runs a sample document through the default or your configuration and returns diagnostic information designed to
* help you understand how the document was processed. The document is not added to the index.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.environment_id - The ID of the environment.
* @param {string} [params.configuration] - The configuration to use to process the document. If this part is
* provided, then the provided configuration is used to process the document. If the **configuration_id** is also
* provided (both are present at the same time), then request is rejected. The maximum supported configuration size is
* 1 MB. Configuration parts larger than 1 MB are rejected.
* See the `GET /configurations/{configuration_id}` operation for an example configuration.
* @param {NodeJS.ReadableStream|FileObject|Buffer} [params.file] - The content of the document to ingest. The maximum
* supported file size when adding a file to a collection is 50 megabytes, the maximum supported file size when
* testing a confiruration is 1 megabyte. Files larger than the supported size are rejected.
* @param {string} [params.filename] - The filename for file.
* @param {string} [params.file_content_type] - The content type of file.
* @param {string} [params.metadata] - If you're using the Data Crawler to upload your documents, you can test a
* document against the type of metadata that the Data Crawler might send. The maximum supported metadata file size is
* 1 MB. Metadata parts larger than 1 MB are rejected.
* Example: ``` {
* "Creator": "Johnny Appleseed",
* "Subject": "Apples"
* } ```.
* @param {string} [params.step] - Specify to only run the input document through the given step instead of running
* the input document through the entire ingestion workflow. Valid values are `convert`, `enrich`, and `normalize`.
* @param {string} [params.configuration_id] - The ID of the configuration to use to process the document. If the
* **configuration** form part is also provided (both are present at the same time), then the request will be
* rejected.
* @param {Object} [params.headers] - Custom request headers
* @param {Function} [callback] - The callback that handles the response.
* @returns {Promise<any>|void}
*/
DiscoveryV1.prototype.testConfigurationInEnvironment = function (params, callback) {
var _this = this;
var _params = extend({}, params);
var _callback = callback;
var requiredParams = ['environment_id'];
if (!_callback) {
return new Promise(function (resolve, reject) {
_this.testConfigurationInEnvironment(params, function (err, bod, res) {
err ? reject(err) : _params.return_response ? resolve(res) : resolve(bod);
});
});
}
var missingParams = ibm_cloud_sdk_core_1.getMissingParams(_params, requiredParams);
if (missingParams) {
return _callback(missingParams);
}
var formData = {
'configuration': _params.configuration,
'file': {
data: _params.file,
filename: _params.filename,
contentType: _params.file_content_type
},
'metadata': _params.metadata
};
var query = {
'step': _params.step,
'configuration_id': _params.configuration_id
};
var path = {
'environment_id': _params.environment_id
};
var sdkHeaders = common_1.getSdkHeaders('discovery', 'v1', 'testConfigurationInEnvironment');
var parameters = {
options: {
url: '/v1/environments/{environment_id}/preview',
method: 'POST',
qs: query,
path: path,
formData: formData
},
defaultOptions: extend(true, {}, this._options, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'multipart/form-data',
}, _params.headers),
}),
};
return this.createRequest(parameters, _callback);
};
;
/*************************
* collections
************************/
/**
* Create a collection.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.environment_id - The ID of the environment.
* @param {string} params.name - The name of the collection to be created.
* @param {string} [params.description] - A description of the collection.
* @param {string} [params.configuration_id] - The ID of the configuration in which the collection is to be created.
* @param {string} [params.language] - The language of the documents stored in the collection, in the form of an ISO
* 639-1 language code.
* @param {Object} [params.headers] - Custom request headers
* @param {Function} [callback] - The callback that handles the response.
* @returns {Promise<any>|void}
*/
DiscoveryV1.prototype.createCollection = function (params, callback) {
var _this = this;
var _params = extend({}, params);
var _callback = callback;
var requiredParams = ['environment_id', 'name'];
if (!_callback) {
return new Promise(function (resolve, reject) {
_this.createCollection(params, function (err, bod, res) {
err ? reject(err) : _params.return_response ? resolve(res) : resolve(bod);
});
});
}
var missingParams = ibm_cloud_sdk_core_1.getMissingParams(_params, requiredParams);
if (missingParams) {
return _callback(missingParams);
}
var body = {
'name': _params.name,
'description': _params.description,
'configuration_id': _params.configuration_id,
'language': _params.language
};
var path = {
'environment_id': _params.environment_id
};
var sdkHeaders = common_1.getSdkHeaders('discovery', 'v1', 'createCollection');
var parameters = {
options: {
url: '/v1/environments/{environment_id}/collections',
method: 'POST',
body: body,
path: path,
},
defaultOptions: extend(true, {}, this._options, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters, _callback);
};
;
/**
* Delete a collection.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.environment_id - The ID of the environment.
* @param {string} params.collection_id - The ID of the collection.
* @param {Object} [params.headers] - Custom request headers
* @param {Function} [callback] - The callback that handles the response.
* @returns {Promise<any>|void}
*/
DiscoveryV1.prototype.deleteCollection = function (params, callback) {
var _this = this;
var _params = extend({}, params);
var _callback = callback;
var requiredParams = ['environment_id', 'collection_id'];
if (!_callback) {
return new Promise(function (resolve, reject) {
_this.deleteCollection(params, function (err, bod, res) {
err ? reject(err) : _params.return_response ? resolve(res) : resolve(bod);
});
});
}
var missingParams = ibm_cloud_sdk_core_1.getMissingParams(_params, requiredParams);
if (missingParams) {
return _callback(missingParams);
}
var path = {
'environment_id': _params.environment_id,
'collection_id': _params.collection_id
};
var sdkHeaders = common_1.getSdkHeaders('discovery', 'v1', 'deleteCollection');
var parameters = {
options: {
url: '/v1/environments/{environment_id}/collections/{collection_id}',
method: 'DELETE',
path: path,
},
defaultOptions: extend(true, {}, this._options, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters, _callback);
};
;
/**
* Get collection details.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.environment_id - The ID of the environment.
* @param {string} params.collection_id - The ID of the collection.
* @param {Object} [params.headers] - Custom request headers
* @param {Function} [callback] - The callback that handles the response.
* @returns {Promise<any>|void}
*/
DiscoveryV1.prototype.getCollection = function (params, callback) {
var _this = this;
var _params = extend({}, params);
var _callback = callback;
var requiredParams = ['environment_id', 'collection_id'];
if (!_callback) {
return new Promise(function (resolve, reject) {
_this.getCollection(params, function (err, bod, res) {
err ? reject(err) : _params.return_response ? resolve(res) : resolve(bod);
});
});
}
var missingParams = ibm_cloud_sdk_core_1.getMissingParams(_params, requiredParams);
if (missingParams) {
return _callback(missingParams);
}
var path = {
'environment_id': _params.environment_id,
'collection_id': _params.collection_id
};
var sdkHeaders = common_1.getSdkHeaders('discovery', 'v1', 'getCollection');
var parameters = {
options: {
url: '/v1/environments/{environment_id}/collections/{collection_id}',
method: 'GET',
path: path,
},
defaultOptions: extend(true, {}, this._options, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters, _callback);
};
;
/**
* List collection fields.
*
* Gets a list of the unique fields (and their types) stored in the index.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.environment_id - The ID of the environment.
* @param {string} params.collection_id - The ID of the collection.
* @param {Object} [params.headers] - Custom request headers
* @param {Function} [callback] - The callback that handles the response.
* @returns {Promise<any>|void}
*/
DiscoveryV1.prototype.listCollectionFields = function (params, callback) {
var _this = this;
var _params = extend({}, params);
var _callback = callback;
var requiredParams = ['environment_id', 'collection_id'];
if (!_callback) {
return new Promise(function (resolve, reject) {
_this.listCollectionFields(params, function (err, bod, res) {
err ? reject(err) : _params.return_response ? resolve(res) : resolve(bod);
});
});
}
var missingParams = ibm_cloud_sdk_core_1.getMissingParams(_params, requiredParams);
if (missingParams) {
return _callback(missingParams);
}
var path = {
'environment_id': _params.environment_id,
'collection_id': _params.collection_id
};
var sdkHeaders = common_1.getSdkHeaders('discovery', 'v1', 'listCollectionFields');
var parameters = {
options: {
url: '/v1/environments/{environment_id}/collections/{collection_id}/fields',
method: 'GET',
path: path,
},
defaultOptions: extend(true, {}, this._options, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters, _callback);
};
;
/**
* List collections.
*
* Lists existing collections for the service instance.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.environment_id - The ID of the environment.
* @param {string} [params.name] - Find collections with the given name.
* @param {Object} [params.headers] - Custom request headers
* @param {Function} [callback] - The callback that handles the response.
* @returns {Promise<any>|void}
*/
DiscoveryV1.prototype.listCollections = function (params, callback) {
var _this = this;
var _params = extend({}, params);
var _callback = callback;
var requiredParams = ['environment_id'];
if (!_callback) {
return new Promise(function (resolve, reject) {
_this.listCollections(params, function (err, bod, res) {
err ? reject(err) : _params.return_response ? resolve(res) : resolve(bod);
});
});
}
var missingParams = ibm_cloud_sdk_core_1.getMissingParams(_params, requiredParams);
if (missingParams) {
return _callback(missingParams);
}
var query = {
'name': _params.name
};
var path = {
'environment_id': _params.environment_id
};
var sdkHeaders = common_1.getSdkHeaders('discovery', 'v1', 'listCollections');
var parameters = {
options: {
url: '/v1/environments/{environment_id}/collections',
method: 'GET',
qs: query,
path: path,
},
defaultOptions: extend(true, {}, this._options, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters, _callback);
};
;
/**
* Update a collection.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.environment_id - The ID of the environment.
* @param {string} params.collection_id - The ID of the collection.
* @param {string} params.name - The name of the collection.
* @param {string} [params.description] - A description of the collection.
* @param {string} [params.configuration_id] - The ID of the configuration in which the collection is to be updated.
* @param {Object} [params.headers] - Custom request headers
* @param {Function} [callback] - The callback that handles the response.
* @returns {Promise<any>|void}
*/
DiscoveryV1.prototype.updateCollection = function (params, callback) {
var _this = this;
var _params = extend({}, params);
var _callback = callback;
var requiredParams = ['environment_id', 'collection_id'];
if (!_callback) {
return new Promise(function (resolve, reject) {
_this.updateCollection(params, function (err, bod, res) {
err ? reject(err) : _params.return_response ? resolve(res) : resolve(bod);
});
});
}
var missingParams = ibm_cloud_sdk_core_1.getMissingParams(_params, requiredParams);
if (missingParams) {
return _callback(missingParams);
}
var body = {
'name': _params.name,
'description': _params.description,
'configuration_id': _params.configuration_id
};
var path = {
'environment_id': _params.environment_id,
'collection_id': _params.collection_id
};
var sdkHeaders = common_1.getSdkHeaders('discovery', 'v1', 'updateCollection');
var parameters = {
options: {
url: '/v1/environments/{environment_id}/collections/{collection_id}',
method: 'PUT',
body: body,
path: path,
},
defaultOptions: extend(true, {}, this._options, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters, _callback);
};
;
/*************************
* queryModifications
************************/
/**
* Create or update expansion list.
*
* Create or replace the Expansion list for this collection. The maximum number of expanded terms per collection is
* `500`.
* The current expansion list is replaced with the uploaded content.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.environment_id - The ID of the environment.
* @param {string} params.collection_id - The ID of the collection.
* @param {Expansion[]} params.expansions - An array of query expansion definitions.
*
* Each object in the **expansions** array represents a term or set of terms that will be expanded into other terms.
* Each expansion object can be configured as bidirectional or unidirectional. Bidirectional means that all terms are
* expanded to all other terms in the object. Unidirectional means that a set list of terms can be expanded into a
* second list of terms.
*
* To create a bi-directional expansion specify an **expanded_terms** array. When found in a query, all items in the
* **expanded_terms** array are then expanded to the other items in the same array.
*
* To create a uni-directional expansion, specify both an array of **input_terms** and an array of
* **expanded_terms**. When items in the **input_terms** array are present in a query, they are expanded using the
* items listed in the **expanded_terms** array.
* @param {Object} [params.headers] - Custom request headers
* @param {Function} [callback] - The callback that handles the response.
* @returns {Promise<any>|void}
*/
DiscoveryV1.prototype.create