Skip to content
This repository was archived by the owner on Nov 24, 2020. It is now read-only.

Commit cc0ea44

Browse files
Merge pull request #117 from watson-developer-cloud/up
Update dependencies
2 parents d779f36 + 25ba6c6 commit cc0ea44

File tree

39 files changed

+14838
-9663
lines changed

39 files changed

+14838
-9663
lines changed

.env.example

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
# You need to provide either username and password
2-
DISCOVERY_USERNAME=
3-
DISCOVERY_PASSWORD=
4-
# OR IAM API key and URL
51
DISCOVERY_IAM_APIKEY=
62
DISCOVERY_IAM_URL=https://iam.bluemix.net/identity/token
7-
3+
DISCOVERY_URL=https://gateway.watsonplatform.net/discovery/api
84

95
ENVIRONMENT_ID=<environment>
106
COLLECTION_ID=<collection>
11-
# check your credentials to validate the url below is correct
12-
DISCOVERY_URL=https://gateway.watsonplatform.net/discovery/api
7+

.eslintrc.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
{
2-
"extends": ["react-app", "airbnb"],
3-
"plugins": [
4-
"react",
5-
"jsx-a11y",
6-
"import"
7-
]
2+
"extends": ["react-app"],
3+
"plugins": ["react", "jsx-a11y", "import"]
84
}

.travis.yml

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
11
language: node_js
2-
dist: trusty
32
sudo: required
4-
node_js: 8
3+
node_js: 12
54
cache:
65
directories:
7-
- node_modules
6+
- node_modules
87
env:
98
global:
10-
- BX_APP=discovery-news-demo
11-
- BX_API=https://api.ng.bluemix.net
12-
- BX_ORGANIZATION=WatsonPlatformServices
13-
- BX_SPACE=demos
9+
- BX_APP=discovery-news-demo
10+
- BX_API=https://api.ng.bluemix.net
11+
- BX_ORGANIZATION=WatsonPlatformServices
12+
- BX_SPACE=demos
1413
script:
15-
- npm run test
16-
- npm run build
14+
- npm run test
15+
- npm run build
1716
before_deploy: npm install -g bx-blue-green
1817
deploy:
19-
- provider: script
20-
skip_cleanup: true
21-
script:
22-
- bx-blue-green-travis
23-
on:
24-
branch: master
25-
repo: watson-developer-cloud/discovery-nodejs
26-
- provider: script
27-
skip_cleanup: true
28-
script: npx semantic-release
29-
on:
30-
node: 8
18+
- provider: script
19+
skip_cleanup: true
20+
script: bx-blue-green-travis
21+
on:
22+
branch: master
23+
repo: watson-developer-cloud/discovery-nodejs
24+
- provider: script
25+
skip_cleanup: true
26+
script: npx semantic-release

app.js

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
1-
const queryBuilder = require('./src/query-builder');
2-
3-
const NEWS_ENVIRONMENT_ID = 'system';
4-
const NEWS_COLLECTION_ID = 'news';
1+
const DISCOVERY_ENVIRONMENT_ID = 'system';
2+
const DISCOVERY_COLLECTION_ID = 'news';
53

6-
const DiscoveryV1 = require('watson-developer-cloud/discovery/v1');
4+
const DiscoveryV1 = require('ibm-watson/discovery/v1');
5+
const { IamAuthenticator } = require('ibm-watson/auth');
76

7+
// Create the service wrapper
88
const discovery = new DiscoveryV1({
9-
version: '2017-08-01',
10-
url: process.env.DISCOVERY_URL || 'https://gateway.watsonplatform.net/discovery/api',
9+
version: '2019-02-28',
10+
authenticator: new IamAuthenticator({
11+
apikey: process.env.DISCOVERY_IAM_APIKEY,
12+
}),
13+
url: process.env.DISCOVERY_URL,
1114
});
1215

1316
// Bootstrap application settings
1417
const express = require('express');
1518
const path = require('path');
19+
const queryBuilder = require('./src/query-builder');
1620

1721
const app = express();
1822
require('./config/express')(app);
1923

2024
function getWidgetQuery(request) {
21-
const widgetQueries = request.query.widgetQueries;
25+
const { widgetQueries } = request.query;
2226

2327
if (!widgetQueries) {
2428
return null;
@@ -34,12 +38,14 @@ function getWidgetQuery(request) {
3438
const currentAggregations = finalWidgetQuery.aggregations || [];
3539
delete queryBuilderWidgetQuery.aggregations;
3640

37-
return Object.assign({}, finalWidgetQuery, queryBuilderWidgetQuery, {
41+
return {
42+
...finalWidgetQuery,
43+
...queryBuilderWidgetQuery,
3844
aggregations: currentAggregations.concat(widgetAggregations),
39-
});
45+
};
4046
}
4147
}
42-
return Object.assign({}, finalWidgetQuery, queryBuilderWidgetQuery);
48+
return { ...finalWidgetQuery, ...queryBuilderWidgetQuery };
4349
}, {});
4450
}
4551

@@ -56,10 +62,11 @@ app.post('/api/query', (req, res, next) => {
5662
delete queryParams.aggregations;
5763
}
5864

59-
const params = Object.assign({}, queryParams, {
60-
environment_id: NEWS_ENVIRONMENT_ID,
61-
collection_id: NEWS_COLLECTION_ID,
62-
});
65+
const params = {
66+
...queryParams,
67+
environmentId: DISCOVERY_ENVIRONMENT_ID,
68+
collectionId: DISCOVERY_COLLECTION_ID,
69+
};
6370

6471
discovery.query(params, (error, response) => {
6572
if (error) {

casper-runner.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
require('dotenv').config();
2+
const { spawn } = require('child_process');
23
const app = require('./app');
3-
const spawn = require('child_process').spawn;
44

5-
if (!process.env.DISCOVERY_USERNAME && !process.env.DISCOVERY_IAM_APIKEY) {
5+
if (!process.env.DISCOVERY_IAM_APIKEY) {
66
// eslint-disable-next-line no-console
7-
console.log('Skipping integration tests because DISCOVERY_USERNAME and DISCOVERY_IAM_APIKEY are null');
7+
console.log('Skipping integration tests because DISCOVERY_IAM_APIKEY is null');
88
} else {
99
const port = 3000;
1010
const server = app.listen(port, () => {

config/security.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ module.exports = function secureApp(app) {
99

1010
const limiter = rateLimit({
1111
windowMs: 30 * 1000, // seconds
12-
delayMs: 0,
1312
max: 5,
1413
message: JSON.stringify({
1514
error: 'Too many requests, please try again in 30 seconds.',

0 commit comments

Comments
 (0)