Socket
Socket
Sign inDemoInstall

node-wit

Package Overview
Dependencies
72
Maintainers
2
Versions
30
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 6.0.1 to 6.1.0

2

index.js

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

'use strict';
/**

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

8

lib/config.js

@@ -0,8 +1,10 @@

'use strict';
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
* Copyright (c) Meta Platforms, Inc. and its affiliates. All Rights Reserved.
*/
module.exports = {
DEFAULT_API_VERSION: '20200513',
DEFAULT_API_VERSION: '20210928',
DEFAULT_WIT_URL: 'https://api.wit.ai'
};
};
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
* Copyright (c) Meta Platforms, Inc. and its affiliates. All Rights Reserved.
*/

@@ -7,17 +7,16 @@

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

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

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

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

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

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

const DEBUG = 'debug';
const INFO = 'info';
const WARN = 'warn';
const ERROR = 'error';
var _funcs;
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 = () => {}
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 Logger = function(lvl) {
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;
this.level = lvl || INFO;
levels.forEach((x) => {
const should = levels.indexOf(x) >= levels.indexOf(lvl);
this[x] = should ? funcs[x] : noop;
levels.forEach(function (x) {
var should = levels.indexOf(x) >= levels.indexOf(lvl);
_this[x] = should ? funcs[x] : noop;
});
};
module.exports = { Logger, DEBUG, INFO, WARN, ERROR };
module.exports = { Logger: Logger, DEBUG: DEBUG, INFO: INFO, WARN: WARN, ERROR: ERROR };
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
* Copyright (c) Meta Platforms, Inc. and its affiliates. All Rights Reserved.
*/

@@ -7,27 +7,13 @@

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 _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 learnMore = 'Learn more at https://wit.ai/docs/quickstart';
var _require = require('./config'),
DEFAULT_API_VERSION = _require.DEFAULT_API_VERSION,
DEFAULT_WIT_URL = _require.DEFAULT_WIT_URL;
function getProxyAgent(witURL) {
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 fetch = require('isomorphic-fetch');
var log = require('./log');
var Url = require('url');
var HttpsProxyAgent = require('https-proxy-agent');
const shouldIgnore = noProxy && noProxy.indexOf(url.hostname) > -1;
if (proxy && !shouldIgnore) {
return new HttpsProxyAgent(proxy);
}
if(!proxy) return null;
}
function Wit(opts) {

@@ -38,40 +24,48 @@ if (!(this instanceof Wit)) {

const {
accessToken, apiVersion, headers, logger, witURL, proxy
} = this.config = Object.freeze(validate(opts));
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;
this._sessions = {};
this.message = (message, context, n, verbose, junk) => {
let qs = 'q=' + encodeURIComponent(message);
this.message = function (message, context, n) {
var params = {
v: apiVersion,
q: message
};
if (context) {
qs += '&context=' + encodeURIComponent(JSON.stringify(context));
params.context = JSON.stringify(context);
}
if (typeof n === 'number') {
qs += '&n=' + encodeURIComponent(JSON.stringify(n));
params.n = JSON.stringify(n);
}
if (verbose != null) {
qs += '&verbose=' + encodeURIComponent(JSON.stringify(verbose));
}
if (junk != null) {
qs += '&junk=true';
}
const method = 'GET';
const fullURL = witURL + '/message?' + qs;
const handler = makeWitResponseHandler(logger, 'message');
var method = 'GET';
var fullURL = witURL + '/message?' + Object.entries(params).map(function (_ref) {
var _ref2 = _slicedToArray(_ref, 2),
key = _ref2[0],
value = _ref2[1];
return key + '=' + encodeURIComponent(value);
}).join('&');
logger.debug(method, fullURL);
return fetch(fullURL, {
method,
headers,
proxy,
})
.then(response => Promise.all([response.json(), response.status]))
.then(handler)
;
method: method,
headers: headers,
proxy: proxy
}).then(function (response) {
return Promise.all([response.json(), response.status]);
}).then(makeWitResponseHandler(logger, 'message'));
};
}
const makeWitResponseHandler = (logger, endpoint) => {
return rsp => {
const error = err => {
var makeWitResponseHandler = function makeWitResponseHandler(logger, endpoint) {
return function (rsp) {
var error = function error(err) {
logger.error('[' + endpoint + '] Error: ' + err);

@@ -85,3 +79,5 @@ throw err;

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

@@ -92,3 +88,3 @@ if (json instanceof Error) {

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

@@ -101,15 +97,30 @@ if (err) {

return json;
};
};
var getProxyAgent = 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;
var shouldIgnore = noProxy && noProxy.indexOf(url.hostname) > -1;
if (proxy && !shouldIgnore) {
return new HttpsProxyAgent(proxy);
}
if (!proxy) {
return null;
}
};
const validate = (opts) => {
var validate = function validate(opts) {
if (!opts.accessToken) {
throw new Error('Could not find access token, learn more at https://wit.ai/docs');
}
opts.witURL = opts.witURL || DEFAULT_WIT_URL;
opts.apiVersion = opts.apiVersion || DEFAULT_API_VERSION;
opts.headers = opts.headers || {
'Authorization': 'Bearer ' + opts.accessToken,
'Accept': 'application/vnd.wit.' + opts.apiVersion + '+json',
'Content-Type': 'application/json',
Authorization: 'Bearer ' + opts.accessToken,
'Content-Type': 'application/json'
};

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

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

@@ -23,6 +23,6 @@ "keywords": [

"express": "^4.16.2",
"https-proxy-agent": "^2.2.3",
"https-proxy-agent": "^5.0.0",
"isomorphic-fetch": "^2.2.1",
"uuid": "^3.0.0",
"lodash": "^4.17.14"
"lodash": "^4.17.14",
"uuid": "^3.0.0"
},

@@ -29,0 +29,0 @@ "engines": {

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