Socket
Socket
Sign inDemoInstall

node-wit

Package Overview
Dependencies
74
Maintainers
8
Versions
30
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 6.0.0 to 6.0.1

.babelrc

2

index.js

@@ -1,3 +0,1 @@

'use strict';
/**

@@ -4,0 +2,0 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.

@@ -1,3 +0,1 @@

'use strict';
/**

@@ -10,2 +8,2 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.

DEFAULT_WIT_URL: 'https://api.wit.ai'
};
};

@@ -7,17 +7,17 @@ /**

var logger = require('./log.js');
var readline = require('readline');
const logger = require('./log.js');
const readline = require('readline');
module.exports = function (wit, handleMessage, context) {
var rl = readline.createInterface({
module.exports = (wit, handleMessage, context) => {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
output: process.stdout,
});
rl.setPrompt('> ');
var prompt = function prompt() {
const prompt = () => {
rl.prompt();
rl.write(null, { ctrl: true, name: 'e' });
rl.write(null, {ctrl: true, name: 'e'});
};
prompt();
rl.on('line', function (line) {
rl.on('line', (line) => {
line = line.trim();

@@ -27,3 +27,4 @@ if (!line) {

}
wit.message(line, context).then(function (rsp) {
wit.message(line, context)
.then((rsp) => {
if (handleMessage) {

@@ -35,6 +36,5 @@ handleMessage(rsp);

prompt();
}).catch(function (err) {
return console.error(err);
});
})
.catch(err => console.error(err))
});
};
};

@@ -7,26 +7,25 @@ /**

var _funcs;
const DEBUG = 'debug';
const INFO = 'info';
const WARN = 'warn';
const ERROR = 'error';
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
const levels = [DEBUG, INFO, WARN, ERROR];
const funcs = {
[DEBUG]: console.debug.bind(console, '[wit][debug]'),
[INFO]: console.log.bind(console, '[wit]'),
[WARN]: console.warn.bind(console, '[wit]'),
[ERROR]: console.error.bind(console, '[wit]'),
};
const noop = () => {}
var DEBUG = 'debug';
var INFO = 'info';
var WARN = 'warn';
var ERROR = 'error';
var levels = [DEBUG, INFO, WARN, ERROR];
var funcs = (_funcs = {}, _defineProperty(_funcs, DEBUG, console.debug.bind(console, '[wit][debug]')), _defineProperty(_funcs, INFO, console.log.bind(console, '[wit]')), _defineProperty(_funcs, WARN, console.warn.bind(console, '[wit]')), _defineProperty(_funcs, ERROR, console.error.bind(console, '[wit]')), _funcs);
var noop = function noop() {};
var Logger = function Logger(lvl) {
var _this = this;
const Logger = function(lvl) {
this.level = lvl || INFO;
levels.forEach(function (x) {
var should = levels.indexOf(x) >= levels.indexOf(lvl);
_this[x] = should ? funcs[x] : noop;
levels.forEach((x) => {
const should = levels.indexOf(x) >= levels.indexOf(lvl);
this[x] = should ? funcs[x] : noop;
});
};
module.exports = { Logger: Logger, DEBUG: DEBUG, INFO: INFO, WARN: WARN, ERROR: ERROR };
module.exports = { Logger, DEBUG, INFO, WARN, ERROR };

@@ -7,25 +7,25 @@ /**

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
const {
DEFAULT_API_VERSION,
DEFAULT_WIT_URL
} = require('./config');
const fetch = require('isomorphic-fetch');
const log = require('./log');
const Url = require('url');
const HttpsProxyAgent = require('https-proxy-agent');
var _require = require('./config'),
DEFAULT_API_VERSION = _require.DEFAULT_API_VERSION,
DEFAULT_WIT_URL = _require.DEFAULT_WIT_URL;
const learnMore = 'Learn more at https://wit.ai/docs/quickstart';
var fetch = require('isomorphic-fetch');
var log = require('./log');
var Url = require('url');
var HttpsProxyAgent = require('https-proxy-agent');
var learnMore = 'Learn more at https://wit.ai/docs/quickstart';
function getProxyAgent(witURL) {
var url = Url.parse(witURL);
var proxy = url.protocol === "http:" ? process.env.http_proxy || process.env.HTTP_PROXY : process.env.https_proxy || process.env.HTTPS_PROXY;
var noProxy = process.env.no_proxy || process.env.NO_PROXY;
const url = Url.parse(witURL);
const proxy = url.protocol === "http:" ?
process.env.http_proxy || process.env.HTTP_PROXY :
process.env.https_proxy || process.env.HTTPS_PROXY;
const noProxy = process.env.no_proxy || process.env.NO_PROXY;
var shouldIgnore = noProxy && noProxy.indexOf(url.hostname) > -1;
const shouldIgnore = noProxy && noProxy.indexOf(url.hostname) > -1;
if (proxy && !shouldIgnore) {
return new HttpsProxyAgent(proxy);
}
if (!proxy) return null;
if(!proxy) return null;
}

@@ -38,14 +38,10 @@

var _config = this.config = Object.freeze(validate(opts)),
accessToken = _config.accessToken,
apiVersion = _config.apiVersion,
headers = _config.headers,
logger = _config.logger,
witURL = _config.witURL,
proxy = _config.proxy;
const {
accessToken, apiVersion, headers, logger, witURL, proxy
} = this.config = Object.freeze(validate(opts));
this._sessions = {};
this.message = function (message, context, n, verbose, junk) {
var qs = 'q=' + encodeURIComponent(message);
this.message = (message, context, n, verbose, junk) => {
let qs = 'q=' + encodeURIComponent(message);
if (context) {

@@ -63,19 +59,20 @@ qs += '&context=' + encodeURIComponent(JSON.stringify(context));

}
var method = 'GET';
var fullURL = witURL + '/message?' + qs;
var handler = makeWitResponseHandler(logger, 'message');
const method = 'GET';
const fullURL = witURL + '/message?' + qs;
const handler = makeWitResponseHandler(logger, 'message');
logger.debug(method, fullURL);
return fetch(fullURL, {
method: method,
headers: headers,
proxy: proxy
}).then(function (response) {
return Promise.all([response.json(), response.status]);
}).then(handler);
method,
headers,
proxy,
})
.then(response => Promise.all([response.json(), response.status]))
.then(handler)
;
};
}
var makeWitResponseHandler = function makeWitResponseHandler(logger, endpoint) {
return function (rsp) {
var error = function error(err) {
const makeWitResponseHandler = (logger, endpoint) => {
return rsp => {
const error = err => {
logger.error('[' + endpoint + '] Error: ' + err);

@@ -89,5 +86,3 @@ throw err;

var _rsp = _slicedToArray(rsp, 2),
json = _rsp[0],
status = _rsp[1];
const [json, status] = rsp;

@@ -98,3 +93,3 @@ if (json instanceof Error) {

var err = json.error || status !== 200 && json.body + ' (' + status + ')';
const err = json.error || status !== 200 && json.body + ' (' + status + ')';

@@ -107,6 +102,6 @@ if (err) {

return json;
};
}
};
var validate = function validate(opts) {
const validate = (opts) => {
if (!opts.accessToken) {

@@ -120,3 +115,3 @@ throw new Error('Could not find access token, learn more at https://wit.ai/docs');

'Accept': 'application/vnd.wit.' + opts.apiVersion + '+json',
'Content-Type': 'application/json'
'Content-Type': 'application/json',
};

@@ -129,2 +124,2 @@ opts.logger = opts.logger || new log.Logger(log.INFO);

module.exports = Wit;
module.exports = Wit;
{
"name": "node-wit",
"version": "6.0.0",
"version": "6.0.1",
"description": "Wit.ai Node.js SDK",

@@ -25,3 +25,2 @@ "keywords": [

"isomorphic-fetch": "^2.2.1",
"request": "^2.83.0",
"uuid": "^3.0.0",

@@ -28,0 +27,0 @@ "lodash": "^4.17.14"

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc