Skip to content

Commit d236e91

Browse files
authored
Merge pull request #288 from watson-developer-cloud/browser
Browser support 💥
2 parents 229affb + f748ff6 commit d236e91

63 files changed

Lines changed: 1315 additions & 828 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ jsdoc/
33
doc/
44
coverage/
55
dist/
6+
node_modules/
7+
examples/**/node_modules/

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module.exports = {
3939
],
4040
"dot-notation": 0,
4141
"eol-last": 0,
42-
"eqeqeq": 0,
42+
"eqeqeq": 2,
4343
"func-names": 0,
4444
"func-style": 0,
4545
"generator-star-spacing": 2,

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ test/resources/tts-output.ogg
99
doc/
1010
.vscode/
1111
dist/
12+
.env
13+
examples/browserify/node_modules/
14+

CHANGELOG.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# v2.0.0
2+
3+
* Breaking: prefer programatic (user-supplied) credentials over bluemix-provided ones (VCAP_SERVICES)
4+
* New preferred method of instantiating services: `new watson.PersonalityInsightsV2({/*...*/});` instead of `watson.personality_insights({/*...*/});`. Older method still works
5+
* Restructured code to support client-side usage via tools such as Browserify and Webpack. Most services support CORS; this will be documented and the remaining service teams will be nagged.
6+
* Added a changelog to capture both major breaking changes and smaller
7+
8+
9+
## Breaking Changes for v1.0
10+
11+
Several breaking changes were introduced with the v1.0.0 release:
12+
13+
* Experimental and Beta services now require the appropriate tag to be added to their version:
14+
* Concept Expansion `v1` is now `v1-beta`
15+
* Question and Answer `v1` is now `v1-beta`
16+
* Relationship Extraction `v1` is now `v1-beta`
17+
* Tone Analyzer `v3` is now `v3` (latest) or `v3-beta` (compatibility with old Beta plan)
18+
* Visual Insights `v1` is now `v1-experimental`
19+
* Visual Recognition `v1` is now `v1-beta`
20+
* Speech to Text gained a new `createRecognizeStream()` method replacing the existing live streaming methods with a simpler Read/Write stream.
21+
The older methods are still available in v1.0 but each log a deprecation warning (unless `{silent: true}` is passed in) and will be removed from a future release.
22+
The affected methods are:
23+
* `recognizeLive()`
24+
* `observeResult()`
25+
* `getRecognizeStatus()`
26+
* The Document Conversion API has been reduced to a single `convert()` method; it no longer offers batch conversion or cloud storage of files.
27+
* Several deprecated services have been removed:
28+
* Message Resonance
29+
* Tone Analyzer v1 and v2 (replaced by v3)
30+
* Search (replaced by Retrieve and Rank)
31+
* Dropped support for node.js v0.10.x (For reference: the WDC Node.js SDK now officially support the latest 0.12, LTS, and Stable releases of Node.js.)

README.md

Lines changed: 40 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Node client library to use the [Watson Developer Cloud][wdc] services, a collect
1111
APIs and SDKs that use cognitive computing to solve complex problems.
1212

1313
## Table of Contents
14-
* [Breaking Changes for v1.0](#breaking-changes-for-v10)
14+
* [Major Changes for v2](#breaking-changes-for-v2)
1515
* [Installation](#installation)
1616
* [Usage](#usage)
1717
* [Getting the Service Credentials](#getting-the-service-credentials)
@@ -44,30 +44,44 @@ APIs and SDKs that use cognitive computing to solve complex problems.
4444
* [License](#license)
4545
* [Contributing](#contributing)
4646

47-
## Breaking Changes for v1.0
48-
49-
Several breaking changes were introduced with the v1.0.0 release:
50-
51-
* Experimental and Beta services now require the appropriate tag to be added to their version:
52-
* Concept Expansion `v1` is now `v1-beta`
53-
* Question and Answer `v1` is now `v1-beta`
54-
* Relationship Extraction `v1` is now `v1-beta`
55-
* Tone Analyzer `v3` is now `v3` (latest) or `v3-beta` (compatibility with old Beta plan)
56-
* Visual Insights `v1` is now `v1-experimental`
57-
* Visual Recognition `v1` is now `v1-beta`
58-
* Speech to Text gained a new `createRecognizeStream()` method replacing the existing live streaming methods with a simpler Read/Write stream.
59-
The older methods are still available in v1.0 but each log a deprecation warning (unless `{silent: true}` is passed in) and will be removed from a future release.
60-
The affected methods are:
61-
* `recognizeLive()`
62-
* `observeResult()`
63-
* `getRecognizeStatus()`
64-
* The Document Conversion API has been reduced to a single `convert()` method; it no longer offers batch conversion or cloud storage of files.
65-
* Several deprecated services have been removed:
66-
* Message Resonance
67-
* Tone Analyzer v1 and v2 (replaced by v3)
68-
* Search (replaced by Retrieve and Rank)
69-
* Dropped support for node.js v0.10.x (For reference: the WDC Node.js SDK now officially support the latest 0.12, LTS, and Stable releases of Node.js.)
7047

48+
## Major Changes for v2
49+
50+
* **Breaking**: user-supplied credentials are now preferred over Bluemix-supplied credentials.
51+
The order of preference is now:
52+
53+
1. User-supplied credentials passed to the service constructor
54+
2. SERVICE_NAME_USERNAME/PASSWORD environment properties (or _API_KEY when appropriate)
55+
3. Bluemix-supplied credentials (via the VCAP_SERVICES JSON-encoded environment property)
56+
57+
* Client-side support via [Browserify](http://browserify.org/)
58+
59+
`examples/browserify/` shows an example app that generates tokens server-side and uses the SDK client-side via browserify.
60+
61+
Note: Not all services currently support CORS, and therefore not all services can be used client-side.
62+
Of those that do, most require an auth token to be generated server-side via the [Authorization Service](#authorization)
63+
64+
* New recommended method for instantiating services:
65+
66+
```js
67+
var ToneAnalyzerV3 = require('watson-developer-cloud/tone-analyzer/v3');
68+
69+
var toneAnalyzer = new ToneAnalyzerV3({/*...*/});
70+
```
71+
72+
This was primarily done to enable smaller bundles for client-side usage, but also gives a small performance boost for server-side usage by only loading the portion of the library that is actually needed.
73+
74+
The following methods will also work, but cause the entire library to be loaded:
75+
76+
```js
77+
// Alternate methods using the library.
78+
// Not recommended, especially for client-side JS.
79+
var watson = require('watson-developer-cloud');
80+
81+
var toneAnalyzer = new watson.ToneAnalyzerV3({/*...*/});
82+
83+
var tone_analyzer = watson.tone_analyzer({version: 'v3', /*...*/});
84+
```
7185

7286
## Installation
7387

@@ -88,7 +102,7 @@ credentials; the library will get them for you by looking at the `VCAP_SERVICES`
88102
By default, [all requests are logged](http://www.ibm.com/watson/developercloud/doc/getting_started/gs-logging.shtml). This can be disabled of by setting the `X-Watson-Learning-Opt-Out` header when creating the service instance:
89103

90104
```js
91-
var myInstance = watson.whatever_service({
105+
var myInstance = new watson.WhateverServiceV1({
92106
/* username, password, version, etc... */
93107
headers: {
94108
"X-Watson-Learning-Opt-Out": "1"
@@ -226,32 +240,7 @@ authorization.getToken(params, function (err, token) {
226240
```
227241

228242
### Concept Insights
229-
Use the [Concept Insights][concept_insights] service to identify words in the
230-
text that correspond to concepts in a Wikipedia graph.
231-
232-
```javascript
233-
var watson = require('watson-developer-cloud');
234-
235-
var concept_insights = watson.concept_insights({
236-
username: '<username>',
237-
password: '<password>',
238-
version: 'v2'
239-
});
240-
241-
var params = {
242-
graph: '/graphs/wikipedia/en-20120601',
243-
text: 'IBM Watson won the Jeopardy television show hosted by Alex Trebek'
244-
};
245-
246-
// Retrieve the concepts for input text
247-
concept_insights.graphs.annotateText(params, function(err, res) {
248-
if (err)
249-
console.log(err);
250-
else {
251-
console.log(JSON.stringify(res, null, 2));
252-
}
253-
});
254-
```
243+
Concept Insights is deprecated as of July 12, 2016. The service will be removed on August 19th, 2016.
255244

256245
### Conversation
257246

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
'use strict';
1818

1919
var extend = require('extend');
20-
var requestFactory = require('../../lib/requestwrapper');
20+
var requestFactory = require('../lib/requestwrapper');
21+
var util = require('util');
22+
var BaseServiceAlchemy = require('../lib/base_service_alchemy');
2123

2224
function errorFormatter(cb) {
2325
return function(err, result, response) {
@@ -40,14 +42,14 @@ function errorFormatter(cb) {
4042
* @param options
4143
* @constructor
4244
*/
43-
function AlchemyDataNews(options) {
44-
// Default URL
45-
var serviceDefaults = {
46-
url: 'https://gateway-a.watsonplatform.net/calls'
47-
};
48-
// Replace default options with user provided
49-
this._options = extend(serviceDefaults, options);
45+
function AlchemyDataNewsV1(options) {
46+
BaseServiceAlchemy.call(this, options);
5047
}
48+
util.inherits(AlchemyDataNewsV1, BaseServiceAlchemy);
49+
50+
AlchemyDataNewsV1.prototype.name = 'alchemy_data_news';
51+
AlchemyDataNewsV1.prototype.version = 'v1';
52+
AlchemyDataNewsV1.URL = 'https://gateway-a.watsonplatform.net/calls';
5153

5254
/**
5355
* Extracts a grouped, ranked list of named entities (people, companies,
@@ -57,7 +59,7 @@ function AlchemyDataNews(options) {
5759
* @param params.start
5860
* @param {Function} callback
5961
*/
60-
AlchemyDataNews.prototype.getNews = function(params, callback ) {
62+
AlchemyDataNewsV1.prototype.getNews = function(params, callback ) {
6163
params = params || {};
6264

6365
var parameters = {
@@ -73,4 +75,4 @@ AlchemyDataNews.prototype.getNews = function(params, callback ) {
7375
return requestFactory(parameters, errorFormatter(callback));
7476
};
7577

76-
module.exports = AlchemyDataNews;
78+
module.exports = AlchemyDataNewsV1;

0 commit comments

Comments
 (0)