Comparing version 6.0.0 to 6.0.1
@@ -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" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 4 instances in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
38873
6
25
624
1
119
2
80
12
6
- Removedrequest@^2.83.0
- Removedajv@6.12.6(transitive)
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@1.0.0(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaws-sign2@0.7.0(transitive)
- Removedaws4@1.13.2(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedcaseless@0.12.0(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcore-util-is@1.0.2(transitive)
- Removeddashdash@1.14.1(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedextend@3.0.2(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedforever-agent@0.6.1(transitive)
- Removedform-data@2.3.3(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedhar-schema@2.0.0(transitive)
- Removedhar-validator@5.1.5(transitive)
- Removedhttp-signature@1.2.0(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedoauth-sign@0.9.0(transitive)
- Removedperformance-now@2.1.0(transitive)
- Removedpsl@1.10.0(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedqs@6.5.3(transitive)
- Removedrequest@2.88.2(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedtough-cookie@2.5.0(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removeduri-js@4.4.1(transitive)
- Removedverror@1.10.0(transitive)