Skip to content

Commit

Permalink
6.2.0 - require node >= 6.17.1 (ES6)
Browse files Browse the repository at this point in the history
Summary:
Upgrade minimal node version to 6.17.1 to support ES6 features directly.
https://node.green/

Reviewed By: ChrisyShine

Differential Revision: D34934957

fbshipit-source-id: 0529dbcbbfa28429f361c21f9b258663aea45f1c
  • Loading branch information
patapizza authored and facebook-github-bot committed Mar 17, 2022
1 parent d5469e7 commit f38e392
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 33 deletions.
8 changes: 0 additions & 8 deletions .babelrc

This file was deleted.

4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v6.2.0

Requires Node.js >= 6.17.1 to support ES6 directly.

## v6.1.1

- Basic `POST /speech` integration.
Expand Down
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@ npm install --save node-wit
Run in your terminal:

```bash
# Node.js <= 6.x.x, add the flag --harmony_destructuring
node --harmony_destructuring examples/basic.js <MY_TOKEN>
# Node.js >= v6.x.x
node examples/basic.js <MY_TOKEN>
node examples/basic.js <WIT_TOKEN>
```

See `examples` folder for more examples. Some examples have associated .zip files, do not forget to import those [when creating a new app](https://wit.ai/v2/apps) and grab your access token from the Settings section.
See `examples` folder for more examples. Some examples have associated .zip files, do not forget to import those [when creating a new app](https://wit.ai/apps) and grab your access token from the Settings section.

### Messenger integration example

Expand Down
21 changes: 11 additions & 10 deletions lib/wit.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,18 @@ const Url = require('url');
const HttpsProxyAgent = require('https-proxy-agent');
const {Readable} = require('stream');

function Wit(opts) {
if (!(this instanceof Wit)) {
return new Wit(opts);
class Wit {
constructor(opts) {
this.config = Object.freeze(validate(opts));
}

const {accessToken, apiVersion, headers, logger, witURL, proxy} =
(this.config = Object.freeze(validate(opts)));

this.message = (q, context, n) => {
message(q, context, n) {
if (typeof q !== 'string') {
throw new Error('Please provide a text input (string).');
}

const {apiVersion, headers, logger, proxy, witURL} = this.config;

const params = {
q,
v: apiVersion,
Expand All @@ -48,9 +47,9 @@ function Wit(opts) {
})
.then(response => Promise.all([response.json(), response.status]))
.then(makeWitResponseHandler(logger, 'message'));
};
}

this.speech = (contentType, body, context, n) => {
speech(contentType, body, context, n) {
if (typeof contentType !== 'string') {
throw new Error('Please provide a content-type (string).');
}
Expand All @@ -59,6 +58,8 @@ function Wit(opts) {
throw new Error('Please provide an audio stream (Readable).');
}

const {apiVersion, headers, logger, proxy, witURL} = this.config;

const params = {
v: apiVersion,
};
Expand Down Expand Up @@ -94,7 +95,7 @@ function Wit(opts) {
})
.catch(e => e)
.then(makeWitResponseHandler(logger, 'speech'));
};
}
}

const makeWitResponseHandler = (logger, endpoint) => rsp => {
Expand Down
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-wit",
"version": "6.1.1",
"version": "6.2.0",
"description": "Wit.ai Node.js SDK",
"keywords": [
"wit",
Expand All @@ -27,12 +27,9 @@
"uuid": "^3.0.0"
},
"engines": {
"node": ">=4.0.0"
"node": ">=6.17.1"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-preset-es2015": "^6.16.0",
"babel-preset-stage-0": "^6.16.0",
"chai": "^3.5.0",
"mocha": "^3.5.3",
"sinon": "^1.17.6"
Expand Down
6 changes: 3 additions & 3 deletions publish.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/bin/bash
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
# Copyright (c) Meta Platforms, Inc. and its affiliates. All rights reserved.

set -ex

mkdir -p dist
cp package.json dist
npx babel lib --out-dir dist/lib
npx babel index.js --out-file dist/index.js
cp index.js dist
cp -R lib dist/lib
mocha ./tests/dist.js
(
cd dist
Expand Down
5 changes: 3 additions & 2 deletions tests/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ module.exports.runTests = wit => {
});

it('tests that Wit has correct functions', () => {
const witFunctions = Object.keys(client);
expect(witFunctions).to.eql(['config', 'message', 'speech']);
expect(Object.keys(client)).to.eql(['config']);
expect(typeof client.message).to.eql('function');
expect(typeof client.speech).to.eql('function');
});

it('tests message', () => {
Expand Down

0 comments on commit f38e392

Please sign in to comment.