Socket
Socket
Sign inDemoInstall

twitter-lite

Package Overview
Dependencies
8
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.5.0 to 0.6.0

2

dist/twitter.js

@@ -1,2 +0,2 @@

var t=require("crypto"),e=require("oauth-1.0a"),r=require("cross-fetch"),n=require("querystring"),i=require("./stream"),o=function(t,e){return void 0===e&&(e="1.1"),"https://"+t+".twitter.com/"+e},s={subdomain:"api",consumer_key:null,consumer_secret:null,access_token_key:null,access_token_secret:null,bearer_token:null},u={"Content-Type":"application/json",Accept:"application/json"},c=function(r){var n,i=Object.assign({},s,r);this.authType=i.bearer_token?"App":"User",this.client=e({consumer:{key:(n={key:i.consumer_key,secret:i.consumer_secret}).key,secret:n.secret},signature_method:"HMAC-SHA1",hash_function:function(e,r){return t.createHmac("sha1",r).update(e).digest("base64")}}),this.token={key:i.access_token_key,secret:i.access_token_secret},this.url=o(i.subdomain),this.oauth=o(i.subdomain,"oauth"),this.config=i};c.prototype.getRequestToken=function(t){return new Promise(function(e,i){var o,s,c;return o={url:this.oauth+"/request_token",method:"POST"},s={},t&&(s={oauth_callback:t}),s&&(o.url+="?"+n.stringify(s)),{},c=this.client.toHeader(this.client.authorize(o,{})),r(o.url,{method:"POST",headers:Object.assign({},u,c)}).then(function(t){return t.text()}).then(function(t){return n.parse(t)}).then(function(t){try{return e(t)}catch(t){return i(t)}}.bind(this),i)}.bind(this))},c.prototype.getAccessToken=function(t){return new Promise(function(e,i){var o,s,c;return o={url:this.oauth+"/access_token",method:"POST"},(s={oauth_verifier:t.verifier})&&(o.url+="?"+n.stringify(s)),{},c=this.client.toHeader(this.client.authorize(o,{key:t.key,secret:t.secret})),r(o.url,{method:"POST",headers:Object.assign({},u,c)}).then(function(t){return t.text()}).then(function(t){return n.parse(t)}).then(function(t){try{return e(t)}catch(t){return i(t)}}.bind(this),i)}.bind(this))},c.prototype.get=function(t,e){return new Promise(function(i,o){var s,u;return s={url:this.url+"/"+t+".json",method:"GET"},e&&(s.url+="?"+n.stringify(e)),u={},u="User"===this.authType?this.client.toHeader(this.client.authorize(s,this.token)):{Authorization:"Bearer "+this.config.bearer_token},r(s.url,{headers:u}).then(function(t){return t.json()}).then(function(t){try{return i(t)}catch(t){return o(t)}}.bind(this),o)}.bind(this))},c.prototype.post=function(t,e,i){return new Promise(function(o,s){var c,h;return c={url:this.url+"/"+t+".json",method:"POST"},i&&(c.url+="?"+n.stringify(i)),h={},h="User"===this.authType?this.client.toHeader(this.client.authorize(c,this.token)):{Authorization:"Bearer "+this.config.bearer_token},r(c.url,{method:"POST",headers:Object.assign({},u,h),body:JSON.stringify(e)}).then(function(t){return t.json()}).then(function(t){try{return o(t)}catch(t){return s(t)}}.bind(this),s)}.bind(this))},c.prototype.stream=function(t,e){var s=this;if("User"!==this.authType)throw Error("Streams require user context authentication");var u=new i,c={url:o("stream")+"/"+t+".json",method:"GET"};e&&(c.url+="?"+n.stringify(e));var h=this.client.toHeader(this.client.authorize(c,this.token));return r(c.url,{headers:h}).then(function(t){s.stream.destroy=function(){return t.body.destroy()},200===t.status?u.emit("start",t):u.emit("error",Error("Status Code: "+t.status)),t.body.on("data",function(t){return u.parse(t)}).on("error",function(t){return u.emit("error",t)}).on("end",function(){return u.emit("end",t)})}).catch(function(t){return u.emit("error",t)}),u},module.exports=c;
var t=require("crypto"),e=require("oauth-1.0a"),r=require("cross-fetch"),n=require("querystring"),o=require("./stream"),i=function(t,e){return void 0===e&&(e="1.1"),"https://"+t+".twitter.com/"+e},s={subdomain:"api",consumer_key:null,consumer_secret:null,access_token_key:null,access_token_secret:null,bearer_token:null},u={"Content-Type":"application/json",Accept:"application/json"},c=function(r){var n,o=Object.assign({},s,r);this.authType=o.bearer_token?"App":"User",this.client=e({consumer:{key:(n={key:o.consumer_key,secret:o.consumer_secret}).key,secret:n.secret},signature_method:"HMAC-SHA1",hash_function:function(e,r){return t.createHmac("sha1",r).update(e).digest("base64")}}),this.token={key:o.access_token_key,secret:o.access_token_secret},this.url=i(o.subdomain),this.oauth=i(o.subdomain,"oauth"),this.config=o};c.prototype.getBearerToken=function(){return new Promise(function(t,e){var n;return n={Authorization:"Basic "+Buffer.from(this.config.consumer_key+":"+this.config.consumer_secret).toString("base64"),"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"},r("https://api.twitter.com/oauth2/token",{method:"POST",body:"grant_type=client_credentials",headers:n}).then(function(t){return t.json()}).then(function(r){try{return t(r)}catch(t){return e(t)}},e)}.bind(this))},c.prototype.getRequestToken=function(t){return new Promise(function(e,o){var i,s,c;return i={url:this.oauth+"/request_token",method:"POST"},s={},t&&(s={oauth_callback:t}),s&&(i.url+="?"+n.stringify(s)),{},c=this.client.toHeader(this.client.authorize(i,{})),r(i.url,{method:"POST",headers:Object.assign({},u,c)}).then(function(t){return t.text()}).then(function(t){return n.parse(t)}).then(function(t){try{return e(t)}catch(t){return o(t)}},o)}.bind(this))},c.prototype.getAccessToken=function(t){return new Promise(function(e,o){var i,s,c;return i={url:this.oauth+"/access_token",method:"POST"},(s={oauth_verifier:t.verifier})&&(i.url+="?"+n.stringify(s)),{},c=this.client.toHeader(this.client.authorize(i,{key:t.key,secret:t.secret})),r(i.url,{method:"POST",headers:Object.assign({},u,c)}).then(function(t){return t.text()}).then(function(t){return n.parse(t)}).then(function(t){try{return e(t)}catch(t){return o(t)}},o)}.bind(this))},c.prototype._makeRequest=function(t,e,r){var o={url:this.url+"/"+e+".json",method:t};r&&(o.url+="?"+n.stringify(r));return{requestData:o,headers:"User"===this.authType?this.client.toHeader(this.client.authorize(o,this.token)):{Authorization:"Bearer "+this.config.bearer_token}}},c.prototype.get=function(t,e){return new Promise(function(n,o){var i;return i=this._makeRequest("GET",t,e),r(i.requestData.url,{headers:i.headers}).then(function(t){return t.json()}).then(function(t){try{return n(t)}catch(t){return o(t)}},o)}.bind(this))},c.prototype.post=function(t,e,n){return new Promise(function(o,i){var s;return s=this._makeRequest("POST",t,n),r(s.requestData.url,{method:"POST",headers:Object.assign({},u,s.headers),body:JSON.stringify(e)}).then(function(t){return t.json()}).then(function(t){try{return o(t)}catch(t){return i(t)}},i)}.bind(this))},c.prototype.stream=function(t,e){var s=this;if("User"!==this.authType)throw Error("Streams require user context authentication");var u=new o,c={url:i("stream")+"/"+t+".json",method:"GET"};e&&(c.url+="?"+n.stringify(e));var a=this.client.toHeader(this.client.authorize(c,this.token));return r(c.url,{headers:a}).then(function(t){s.stream.destroy=function(){return t.body.destroy()},200===t.status?u.emit("start",t):u.emit("error",Error("Status Code: "+t.status)),t.body.on("data",function(t){return u.parse(t)}).on("error",function(t){return u.emit("error",t)}).on("end",function(){return u.emit("end",t)})}).catch(function(t){return u.emit("error",t)}),u},module.exports=c;
//# sourceMappingURL=twitter.js.map

@@ -1,2 +0,2 @@

var t=require("crypto"),e=require("oauth-1.0a"),r=require("cross-fetch"),n=require("querystring"),i=require("./stream"),o=function(t,e){return void 0===e&&(e="1.1"),"https://"+t+".twitter.com/"+e},s={subdomain:"api",consumer_key:null,consumer_secret:null,access_token_key:null,access_token_secret:null,bearer_token:null},u={"Content-Type":"application/json",Accept:"application/json"},c=function(r){var n,i=Object.assign({},s,r);this.authType=i.bearer_token?"App":"User",this.client=e({consumer:{key:(n={key:i.consumer_key,secret:i.consumer_secret}).key,secret:n.secret},signature_method:"HMAC-SHA1",hash_function:function(e,r){return t.createHmac("sha1",r).update(e).digest("base64")}}),this.token={key:i.access_token_key,secret:i.access_token_secret},this.url=o(i.subdomain),this.oauth=o(i.subdomain,"oauth"),this.config=i};c.prototype.getRequestToken=function(t){return new Promise(function(e,i){var o,s,c;return o={url:this.oauth+"/request_token",method:"POST"},s={},t&&(s={oauth_callback:t}),s&&(o.url+="?"+n.stringify(s)),{},c=this.client.toHeader(this.client.authorize(o,{})),r(o.url,{method:"POST",headers:Object.assign({},u,c)}).then(function(t){return t.text()}).then(function(t){return n.parse(t)}).then(function(t){try{return e(t)}catch(t){return i(t)}}.bind(this),i)}.bind(this))},c.prototype.getAccessToken=function(t){return new Promise(function(e,i){var o,s,c;return o={url:this.oauth+"/access_token",method:"POST"},(s={oauth_verifier:t.verifier})&&(o.url+="?"+n.stringify(s)),{},c=this.client.toHeader(this.client.authorize(o,{key:t.key,secret:t.secret})),r(o.url,{method:"POST",headers:Object.assign({},u,c)}).then(function(t){return t.text()}).then(function(t){return n.parse(t)}).then(function(t){try{return e(t)}catch(t){return i(t)}}.bind(this),i)}.bind(this))},c.prototype.get=function(t,e){return new Promise(function(i,o){var s,u;return s={url:this.url+"/"+t+".json",method:"GET"},e&&(s.url+="?"+n.stringify(e)),u={},u="User"===this.authType?this.client.toHeader(this.client.authorize(s,this.token)):{Authorization:"Bearer "+this.config.bearer_token},r(s.url,{headers:u}).then(function(t){return t.json()}).then(function(t){try{return i(t)}catch(t){return o(t)}}.bind(this),o)}.bind(this))},c.prototype.post=function(t,e,i){return new Promise(function(o,s){var c,h;return c={url:this.url+"/"+t+".json",method:"POST"},i&&(c.url+="?"+n.stringify(i)),h={},h="User"===this.authType?this.client.toHeader(this.client.authorize(c,this.token)):{Authorization:"Bearer "+this.config.bearer_token},r(c.url,{method:"POST",headers:Object.assign({},u,h),body:JSON.stringify(e)}).then(function(t){return t.json()}).then(function(t){try{return o(t)}catch(t){return s(t)}}.bind(this),s)}.bind(this))},c.prototype.stream=function(t,e){var s=this;if("User"!==this.authType)throw Error("Streams require user context authentication");var u=new i,c={url:o("stream")+"/"+t+".json",method:"GET"};e&&(c.url+="?"+n.stringify(e));var h=this.client.toHeader(this.client.authorize(c,this.token));return r(c.url,{headers:h}).then(function(t){s.stream.destroy=function(){return t.body.destroy()},200===t.status?u.emit("start",t):u.emit("error",Error("Status Code: "+t.status)),t.body.on("data",function(t){return u.parse(t)}).on("error",function(t){return u.emit("error",t)}).on("end",function(){return u.emit("end",t)})}).catch(function(t){return u.emit("error",t)}),u},module.exports=c;
var t=require("crypto"),e=require("oauth-1.0a"),r=require("cross-fetch"),n=require("querystring"),o=require("./stream"),i=function(t,e){return void 0===e&&(e="1.1"),"https://"+t+".twitter.com/"+e},s={subdomain:"api",consumer_key:null,consumer_secret:null,access_token_key:null,access_token_secret:null,bearer_token:null},u={"Content-Type":"application/json",Accept:"application/json"},c=function(r){var n,o=Object.assign({},s,r);this.authType=o.bearer_token?"App":"User",this.client=e({consumer:{key:(n={key:o.consumer_key,secret:o.consumer_secret}).key,secret:n.secret},signature_method:"HMAC-SHA1",hash_function:function(e,r){return t.createHmac("sha1",r).update(e).digest("base64")}}),this.token={key:o.access_token_key,secret:o.access_token_secret},this.url=i(o.subdomain),this.oauth=i(o.subdomain,"oauth"),this.config=o};c.prototype.getBearerToken=function(){return new Promise(function(t,e){var n;return n={Authorization:"Basic "+Buffer.from(this.config.consumer_key+":"+this.config.consumer_secret).toString("base64"),"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"},r("https://api.twitter.com/oauth2/token",{method:"POST",body:"grant_type=client_credentials",headers:n}).then(function(t){return t.json()}).then(function(r){try{return t(r)}catch(t){return e(t)}},e)}.bind(this))},c.prototype.getRequestToken=function(t){return new Promise(function(e,o){var i,s,c;return i={url:this.oauth+"/request_token",method:"POST"},s={},t&&(s={oauth_callback:t}),s&&(i.url+="?"+n.stringify(s)),{},c=this.client.toHeader(this.client.authorize(i,{})),r(i.url,{method:"POST",headers:Object.assign({},u,c)}).then(function(t){return t.text()}).then(function(t){return n.parse(t)}).then(function(t){try{return e(t)}catch(t){return o(t)}},o)}.bind(this))},c.prototype.getAccessToken=function(t){return new Promise(function(e,o){var i,s,c;return i={url:this.oauth+"/access_token",method:"POST"},(s={oauth_verifier:t.verifier})&&(i.url+="?"+n.stringify(s)),{},c=this.client.toHeader(this.client.authorize(i,{key:t.key,secret:t.secret})),r(i.url,{method:"POST",headers:Object.assign({},u,c)}).then(function(t){return t.text()}).then(function(t){return n.parse(t)}).then(function(t){try{return e(t)}catch(t){return o(t)}},o)}.bind(this))},c.prototype._makeRequest=function(t,e,r){var o={url:this.url+"/"+e+".json",method:t};r&&(o.url+="?"+n.stringify(r));return{requestData:o,headers:"User"===this.authType?this.client.toHeader(this.client.authorize(o,this.token)):{Authorization:"Bearer "+this.config.bearer_token}}},c.prototype.get=function(t,e){return new Promise(function(n,o){var i;return i=this._makeRequest("GET",t,e),r(i.requestData.url,{headers:i.headers}).then(function(t){return t.json()}).then(function(t){try{return n(t)}catch(t){return o(t)}},o)}.bind(this))},c.prototype.post=function(t,e,n){return new Promise(function(o,i){var s;return s=this._makeRequest("POST",t,n),r(s.requestData.url,{method:"POST",headers:Object.assign({},u,s.headers),body:JSON.stringify(e)}).then(function(t){return t.json()}).then(function(t){try{return o(t)}catch(t){return i(t)}},i)}.bind(this))},c.prototype.stream=function(t,e){var s=this;if("User"!==this.authType)throw Error("Streams require user context authentication");var u=new o,c={url:i("stream")+"/"+t+".json",method:"GET"};e&&(c.url+="?"+n.stringify(e));var a=this.client.toHeader(this.client.authorize(c,this.token));return r(c.url,{headers:a}).then(function(t){s.stream.destroy=function(){return t.body.destroy()},200===t.status?u.emit("start",t):u.emit("error",Error("Status Code: "+t.status)),t.body.on("data",function(t){return u.parse(t)}).on("error",function(t){return u.emit("error",t)}).on("end",function(){return u.emit("end",t)})}).catch(function(t){return u.emit("error",t)}),u},module.exports=c;
//# sourceMappingURL=twitter.m.js.map

@@ -1,2 +0,2 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e():"function"==typeof define&&define.amd?define(e):e()}(0,function(){var t=require("crypto"),e=require("oauth-1.0a"),r=require("cross-fetch"),n=require("querystring"),i=require("./stream"),o=function(t,e){return void 0===e&&(e="1.1"),"https://"+t+".twitter.com/"+e},s={subdomain:"api",consumer_key:null,consumer_secret:null,access_token_key:null,access_token_secret:null,bearer_token:null},u={"Content-Type":"application/json",Accept:"application/json"},c=function(r){var n,i=Object.assign({},s,r);this.authType=i.bearer_token?"App":"User",this.client=e({consumer:{key:(n={key:i.consumer_key,secret:i.consumer_secret}).key,secret:n.secret},signature_method:"HMAC-SHA1",hash_function:function(e,r){return t.createHmac("sha1",r).update(e).digest("base64")}}),this.token={key:i.access_token_key,secret:i.access_token_secret},this.url=o(i.subdomain),this.oauth=o(i.subdomain,"oauth"),this.config=i};c.prototype.getRequestToken=function(t){return new Promise(function(e,i){var o,s,c;return o={url:this.oauth+"/request_token",method:"POST"},s={},t&&(s={oauth_callback:t}),s&&(o.url+="?"+n.stringify(s)),{},c=this.client.toHeader(this.client.authorize(o,{})),r(o.url,{method:"POST",headers:Object.assign({},u,c)}).then(function(t){return t.text()}).then(function(t){return n.parse(t)}).then(function(t){try{return e(t)}catch(t){return i(t)}}.bind(this),i)}.bind(this))},c.prototype.getAccessToken=function(t){return new Promise(function(e,i){var o,s,c;return o={url:this.oauth+"/access_token",method:"POST"},(s={oauth_verifier:t.verifier})&&(o.url+="?"+n.stringify(s)),{},c=this.client.toHeader(this.client.authorize(o,{key:t.key,secret:t.secret})),r(o.url,{method:"POST",headers:Object.assign({},u,c)}).then(function(t){return t.text()}).then(function(t){return n.parse(t)}).then(function(t){try{return e(t)}catch(t){return i(t)}}.bind(this),i)}.bind(this))},c.prototype.get=function(t,e){return new Promise(function(i,o){var s,u;return s={url:this.url+"/"+t+".json",method:"GET"},e&&(s.url+="?"+n.stringify(e)),u={},u="User"===this.authType?this.client.toHeader(this.client.authorize(s,this.token)):{Authorization:"Bearer "+this.config.bearer_token},r(s.url,{headers:u}).then(function(t){return t.json()}).then(function(t){try{return i(t)}catch(t){return o(t)}}.bind(this),o)}.bind(this))},c.prototype.post=function(t,e,i){return new Promise(function(o,s){var c,a;return c={url:this.url+"/"+t+".json",method:"POST"},i&&(c.url+="?"+n.stringify(i)),a={},a="User"===this.authType?this.client.toHeader(this.client.authorize(c,this.token)):{Authorization:"Bearer "+this.config.bearer_token},r(c.url,{method:"POST",headers:Object.assign({},u,a),body:JSON.stringify(e)}).then(function(t){return t.json()}).then(function(t){try{return o(t)}catch(t){return s(t)}}.bind(this),s)}.bind(this))},c.prototype.stream=function(t,e){var s=this;if("User"!==this.authType)throw Error("Streams require user context authentication");var u=new i,c={url:o("stream")+"/"+t+".json",method:"GET"};e&&(c.url+="?"+n.stringify(e));var a=this.client.toHeader(this.client.authorize(c,this.token));return r(c.url,{headers:a}).then(function(t){s.stream.destroy=function(){return t.body.destroy()},200===t.status?u.emit("start",t):u.emit("error",Error("Status Code: "+t.status)),t.body.on("data",function(t){return u.parse(t)}).on("error",function(t){return u.emit("error",t)}).on("end",function(){return u.emit("end",t)})}).catch(function(t){return u.emit("error",t)}),u},module.exports=c});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t():"function"==typeof define&&define.amd?define(t):t()}(0,function(){var e=require("crypto"),t=require("oauth-1.0a"),r=require("cross-fetch"),n=require("querystring"),o=require("./stream"),i=function(e,t){return void 0===t&&(t="1.1"),"https://"+e+".twitter.com/"+t},u={subdomain:"api",consumer_key:null,consumer_secret:null,access_token_key:null,access_token_secret:null,bearer_token:null},s={"Content-Type":"application/json",Accept:"application/json"},c=function(r){var n,o=Object.assign({},u,r);this.authType=o.bearer_token?"App":"User",this.client=t({consumer:{key:(n={key:o.consumer_key,secret:o.consumer_secret}).key,secret:n.secret},signature_method:"HMAC-SHA1",hash_function:function(t,r){return e.createHmac("sha1",r).update(t).digest("base64")}}),this.token={key:o.access_token_key,secret:o.access_token_secret},this.url=i(o.subdomain),this.oauth=i(o.subdomain,"oauth"),this.config=o};c.prototype.getBearerToken=function(){return new Promise(function(e,t){var n;return n={Authorization:"Basic "+Buffer.from(this.config.consumer_key+":"+this.config.consumer_secret).toString("base64"),"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"},r("https://api.twitter.com/oauth2/token",{method:"POST",body:"grant_type=client_credentials",headers:n}).then(function(e){return e.json()}).then(function(r){try{return e(r)}catch(e){return t(e)}},t)}.bind(this))},c.prototype.getRequestToken=function(e){return new Promise(function(t,o){var i,u,c;return i={url:this.oauth+"/request_token",method:"POST"},u={},e&&(u={oauth_callback:e}),u&&(i.url+="?"+n.stringify(u)),{},c=this.client.toHeader(this.client.authorize(i,{})),r(i.url,{method:"POST",headers:Object.assign({},s,c)}).then(function(e){return e.text()}).then(function(e){return n.parse(e)}).then(function(e){try{return t(e)}catch(e){return o(e)}},o)}.bind(this))},c.prototype.getAccessToken=function(e){return new Promise(function(t,o){var i,u,c;return i={url:this.oauth+"/access_token",method:"POST"},(u={oauth_verifier:e.verifier})&&(i.url+="?"+n.stringify(u)),{},c=this.client.toHeader(this.client.authorize(i,{key:e.key,secret:e.secret})),r(i.url,{method:"POST",headers:Object.assign({},s,c)}).then(function(e){return e.text()}).then(function(e){return n.parse(e)}).then(function(e){try{return t(e)}catch(e){return o(e)}},o)}.bind(this))},c.prototype._makeRequest=function(e,t,r){var o={url:this.url+"/"+t+".json",method:e};r&&(o.url+="?"+n.stringify(r));return{requestData:o,headers:"User"===this.authType?this.client.toHeader(this.client.authorize(o,this.token)):{Authorization:"Bearer "+this.config.bearer_token}}},c.prototype.get=function(e,t){return new Promise(function(n,o){var i;return i=this._makeRequest("GET",e,t),r(i.requestData.url,{headers:i.headers}).then(function(e){return e.json()}).then(function(e){try{return n(e)}catch(e){return o(e)}},o)}.bind(this))},c.prototype.post=function(e,t,n){return new Promise(function(o,i){var u;return u=this._makeRequest("POST",e,n),r(u.requestData.url,{method:"POST",headers:Object.assign({},s,u.headers),body:JSON.stringify(t)}).then(function(e){return e.json()}).then(function(e){try{return o(e)}catch(e){return i(e)}},i)}.bind(this))},c.prototype.stream=function(e,t){var u=this;if("User"!==this.authType)throw Error("Streams require user context authentication");var s=new o,c={url:i("stream")+"/"+e+".json",method:"GET"};t&&(c.url+="?"+n.stringify(t));var a=this.client.toHeader(this.client.authorize(c,this.token));return r(c.url,{headers:a}).then(function(e){u.stream.destroy=function(){return e.body.destroy()},200===e.status?s.emit("start",e):s.emit("error",Error("Status Code: "+e.status)),e.body.on("data",function(e){return s.parse(e)}).on("error",function(e){return s.emit("error",e)}).on("end",function(){return s.emit("end",e)})}).catch(function(e){return s.emit("error",e)}),s},module.exports=c});
//# sourceMappingURL=twitter.umd.js.map
{
"name": "twitter-lite",
"version": "0.5.0",
"description":
"A tiny, full-featured client / server library for the Twitter API",
"source": ["twitter.js", "stream.js"],
"version": "0.6.0",
"description": "A tiny, full-featured client / server library for the Twitter API",
"source": [
"twitter.js",
"stream.js"
],
"main": "dist/twitter.js",

@@ -13,3 +15,7 @@ "module": "dist/twitter.m.js",

"license": "MIT",
"files": ["twitter.js", "stream.js", "dist"],
"files": [
"twitter.js",
"stream.js",
"dist"
],
"keywords": [

@@ -30,6 +36,7 @@ "twitter",

"devDependencies": {
"dotenv": "^5.0.1",
"flow-bin": "^0.68.0",
"husky": "^0.14.3",
"jest": "^22.3.0",
"lint-staged": "^7.0.0",
"jest": "^22.4.4",
"lint-staged": "^7.0.5",
"microbundle": "^0.4.3",

@@ -41,9 +48,11 @@ "prettier": "^1.11.1"

"test": "jest",
"release":
"npm run -s prepare && npm test && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish",
"release": "npm run -s prepare && npm test && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish",
"precommit": "lint-staged"
},
"lint-staged": {
"*.{js,json,css,md}": ["prettier --write", "git add"]
"*.{js,json,css,md}": [
"prettier --write",
"git add"
]
}
}
# Twitter Lite
A tiny Nodejs library for the Twitter API
A tiny, full-featured, modern client / server library for the [Twitter API](https://developer.twitter.com/en/docs/basics/things-every-developer-should-know).

@@ -9,14 +9,21 @@ [![npm](https://img.shields.io/npm/v/twitter-lite.svg)](https://npm.im/twitter-lite) [![travis](https://travis-ci.org/Preposterous/twitter-lite.svg?branch=master)](https://travis-ci.org/Preposterous/twitter-lite)

* Promise driven via Async / Await
* Up-to-date APIs
* Stream support
* Under 1kb
- Promise driven via Async / Await
- Both REST and Stream support
- Works both in Node and in browsers
- Up-to-date APIs
- Under 1kb
- Minimal dependencies
- Test suite
## Why
We have built this library because existing ones [have not been recently maintained](https://github.com/desmondmorris/node-twitter), or depend on [outdated](https://github.com/ttezel/twit/issues/411) [libraries](https://github.com/ttezel/twit/issues/412).
## Installation
```zsh
```sh
yarn add twitter-lite
```
```zsh
```sh
npm install twitter-lite

@@ -27,23 +34,24 @@ ```

* Create an app on [https://apps.twitter.com/](https://apps.twitter.com)
* Grab the Consumer Key (API Key) and Consumer Secret (API Secret) from Keys and Access Tokens
* Make sure you set the right access level for your app
- Create an app on [https://apps.twitter.com/](https://apps.twitter.com)
- Grab the Consumer Key (API Key) and Consumer Secret (API Secret) from Keys and Access Tokens
- Make sure you set the right access level for your app
- If you want to use user-based authentication, grab the access token key and secret as well
### App vs. User
### App vs. User authentication
Twitter has two different authentication options:
* App: higher rate limits. Great for building your own Twitter App
* User: lower rate limits. Great for making requests on behalf of a User.
- App: higher rate limits. Great for building your own Twitter App.
- User: lower rate limits. Great for making requests on behalf of a User.
**User** authentication requires:
* `consumer_key`
* `consumer_secret`
* `access_token_key`
* `access_token_secret`
- `consumer_key`
- `consumer_secret`
- `access_token_key`
- `access_token_secret`
**App** authentication requires:
* `bearer_token`
- `bearer_token`

@@ -58,84 +66,91 @@ App authentication is a simple header behind the scenes:

### Oauth Authentication
According to the [docs](https://developer.twitter.com/en/docs/basics/authentication/api-reference/authenticate) this helps you get access token from your users.
You can get the bearer token by calling `.getBearerToken()`.
- [Request Token documentation](https://developer.twitter.com/en/docs/basics/authentication/api-reference/request_token)
- [Access Token documentation](https://developer.twitter.com/en/docs/basics/authentication/api-reference/access_token)
### Verifying credentials example (user auth)
```es6
const client = new Twitter({
consumer_key: "xyz",
consumer_secret: "xyz"
subdomain: "api",
consumer_key: "abc", // from Twitter.
consumer_secret: "def", // from Twitter.
access_token_key: "uvw", // from your User (oauth_token)
access_token_secret: "xyz" // from your User (oauth_token_secret)
});
client.getRequestToken("http://callbackurl.com")
.then(res => console.log({
reqTkn: res.oauth_token,
reqTknSecret: res.oauth_token_secret
}))
.catch(console.error);
client
.get("account/verify_credentials")
.then(results => {
console.log("results", results);
})
.catch(console.error);
```
Then you redirect your user to `https://api.twitter.com/oauth/authenticate?oauth_token=xyz123abc`, and once you get the verifier and the token, you pass them on to the next stage of the authentication.
### App authentication example
```es6
const client = new Twitter({
consumer_key: "xyz",
consumer_secret: "xyz"
const user = new Twitter({
consumer_key: "abc",
consumer_secret: "def",
});
client.getAccessToken({
key: requestToken,
secret: requestTokenSecret,
verifier: oauthVerifier
})
.then(res=>console.log({
accTkn: res.oauth_token,
accTknSecret: res.oauth_token_secret,
userId: res.user_id,
screenName: res.screen_name
}))
.catch(console.error);
const response = await user.getBearerToken();
const app = new Twitter({
bearer_token: response.access_token
});
```
And this will return you your `access_token` and `access_token_secret`.
### Oauth authentication
### Verifying Credentials Example (User auth)
According to the [docs](https://developer.twitter.com/en/docs/basics/authentication/api-reference/authenticate) this helps you get access token from your users.
- [Request Token documentation](https://developer.twitter.com/en/docs/basics/authentication/api-reference/request_token)
- [Access Token documentation](https://developer.twitter.com/en/docs/basics/authentication/api-reference/access_token)
```es6
const client = new Twitter({
subdomain: "api",
consumer_key: "xyz", // from Twitter.
consumer_secret: "xyz", // from Twitter.
access_token_key: "abc", // from your User (oauth_token)
access_token_secret: "abc" // from your User (oauth_token_secret)
consumer_key: "xyz",
consumer_secret: "xyz"
});
client
.get("account/verify_credentials")
.then(results => {
console.log("results", results);
})
.getRequestToken("http://callbackurl.com")
.then(res =>
console.log({
reqTkn: res.oauth_token,
reqTknSecret: res.oauth_token_secret
})
)
.catch(console.error);
```
### App authentication Example
Then you redirect your user to `https://api.twitter.com/oauth/authenticate?oauth_token=xyz123abc`, and once you get the verifier and the token, you pass them on to the next stage of the authentication.
```es6
const client = new Twitter({
subdomain: "api",
bearer_token: "Bearer ABC123XYZ" // generate a Bearer token
consumer_key: "xyz",
consumer_secret: "xyz"
});
client
.get("users/lookup")
.then(results => {
console.log("results", results);
.getAccessToken({
key: requestToken,
secret: requestTokenSecret,
verifier: oauthVerifier
})
.then(res =>
console.log({
accTkn: res.oauth_token,
accTknSecret: res.oauth_token_secret,
userId: res.user_id,
screenName: res.screen_name
})
)
.catch(console.error);
```
And this will return you your `access_token` and `access_token_secret`.
## Streams
To learn more about the streaming API visit the [Twitter Docs](https://developer.twitter.com/en/docs/tweets/filter-realtime/api-reference/post-statuses-filter.html).
To learn more about the streaming API visit the [Twitter Docs](https://developer.twitter.com/en/docs/tweets/filter-realtime/api-reference/post-statuses-filter.html). The streaming API works only in Node.

@@ -167,26 +182,95 @@ ```es6

## Troubleshooting
## Methods
### API Errors
### .get(endpoint, parameters)
Api errors are returned (with "catch" in the Promise api or with "err" param in the callback api) as an array of errors.
Thus errors described in twitter docs for example as:
```es6
const client = new Twitter({
consumer_key: "xyz",
consumer_secret: "xyz",
access_token_key: "abc",
access_token_secret: "abc"
});
```JSON
{ "errors": [ { "code": 88, "message": "Rate limit exceeded" } ] }
const rateLimits = await app.get("statuses/show", {
id: "1016078154497048576",
});
```
Would return as :
### .post(endpoint, body, parameters)
Use the `.post` method for actions that change state, as documented in the Twitter API. For [example](https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/post-friendships-create.html), to follow a user:
```es6
const client = new Twitter({
consumer_key: "xyz",
consumer_secret: "xyz",
access_token_key: "abc",
access_token_secret: "abc"
});
await client.post("friendships/create", null, {
screen_name: "dandv"
});
```
[ { "code": 88, "message": "Rate limit exceeded" } ]
```
## Credit
Note: [for now](https://github.com/Preposterous/twitter-lite/issues/15#issuecomment-402902433), make sure to pass a `null` body to `.post`. This is subject to change in a future version of the library.
### .getBearerToken()
See the [app authenticatio example](#app-authentication-example).
### .getRequestToken(twitterCallbackUrl)
See the [OAuth example](#oauth-authentication).
### .getAccessToken(options)
See the [OAuth example](#oauth-authentication).
## Troubleshooting
### API Errors
API errors are returned as an array of errors under the `errors` key of the response object. Make sure to check for the presence of this field, in addition to any try/catch blocks you may have.
### Numeric vs. string IDs
Twitter uses [numeric IDs](https://developer.twitter.com/en/docs/basics/twitter-ids.html) that in practice can be up to 18 characters long. Due to rounding errors, it's [unsafe to use numeric IDs in JavaScript](https://developer.twitter.com/en/docs/basics/things-every-developer-should-know). Always set `stringify_ids: true` when possible, so that Twitter will return strings instead of numbers, and rely on the `id_str` field, rather than on the `id` field.
## Contributing
With the library nearing v1.0, contributions are welcome! Areas especially in need of help involve multimedia (see [#33](https://github.com/Preposterous/twitter-lite/issues/33) for example), adding tests (see [these](https://github.com/ttezel/twit/tree/master/tests) for reference), and [getting v1.0 out the door](https://github.com/Preposterous/twitter-lite/issues/21).
### Development
1. Fork/clone the repo
2. `yarn/npm install`
3. Go to https://apps.twitter.com and create an app for testing this module. Make sure it has read/write permissions.
4. Grab the consumer key/secret, and the access token/secret and place them in a [.env](https://www.npmjs.com/package/dotenv) file in the project's root directory, under the following variables:
```
TWITTER_CONSUMER_KEY=...
TWITTER_CONSUMER_SECRET=...
ACCESS_TOKEN=...
ACCESS_TOKEN_SECRET=...
```
5. `yarn/npm test` and make sure all tests pass
6. Add your contribution, along with test case(s). Note: feel free to skip the ["should DM user"](https://github.com/Preposterous/twitter-lite/blob/34e8dbb3efb9a45564275f16473af59dbc4409e5/twitter.test.js#L167) test during development by changing that `it()` call to `it.skip()`, but remember to revert that change before committing. This will prevent your account from being flagged as [abusing the API to send too many DMs](https://github.com/Preposterous/twitter-lite/commit/5ee2ce4232faa07453ea2f0b4d63ee7a6d119ce7).
7. When all tests pass, run `npm run precommit` for linting with [prettier](https://www.npmjs.com/package/prettier)
8. Commit using a [descriptive message](https://chris.beams.io/posts/git-commit/) (please squash all your commits into one!)
9. `git push` and submit your PR!
## Credits
Authors:
- [@peterpme](https://github.com/peterpme)
- [@dandv](https://github.com/dandv)
Over the years, thanks to:
* [@technoweenie](http://github.com/technoweenie)
* [@jdub](http://github.com/jdub)
* [@desmondmorris](http://github.com/desmondmorris)
* [Node Twitter Community](https://github.com/desmondmorris/node-twitter/graphs/contributors)
- [@technoweenie](http://github.com/technoweenie)
- [@jdub](http://github.com/jdub)
- [@desmondmorris](http://github.com/desmondmorris)
- [@ttezel](https://github.com/ttezel)
- [Node Twitter Community](https://github.com/desmondmorris/node-twitter/graphs/contributors)

@@ -7,3 +7,4 @@ const crypto = require("crypto");

const getUrl = (subdomain, endpoint='1.1') => `https://${subdomain}.twitter.com/${endpoint}`;
const getUrl = (subdomain, endpoint = "1.1") =>
`https://${subdomain}.twitter.com/${endpoint}`;

@@ -57,4 +58,23 @@ const createOauthClient = ({ key, secret }) => {

}
async getRequestToken(twitterCallbackUrl) {
async getBearerToken() {
const headers = {
Authorization:
"Basic " +
Buffer.from(
this.config.consumer_key + ":" + this.config.consumer_secret
).toString("base64"),
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"
};
const results = await Fetch("https://api.twitter.com/oauth2/token", {
method: "POST",
body: "grant_type=client_credentials",
headers
}).then(res => res.json());
return results;
}
async getRequestToken(twitterCallbackUrl) {
const requestData = {

@@ -64,12 +84,10 @@ url: `${this.oauth}/request_token`,

};
var parameters = {};
if(twitterCallbackUrl) parameters = { "oauth_callback": twitterCallbackUrl };
let parameters = {};
if (twitterCallbackUrl) parameters = { oauth_callback: twitterCallbackUrl };
if (parameters) requestData.url += "?" + querystring.stringify(parameters);
let headers = {};
headers = this.client.toHeader(
this.client.authorize(requestData, {})
);
headers = this.client.toHeader(this.client.authorize(requestData, {}));
const results = await Fetch(requestData.url, {

@@ -79,9 +97,9 @@ method: "POST",

})
.then(res => res.text())
.then(txt => querystring.parse(txt));
.then(res => res.text())
.then(txt => querystring.parse(txt));
return results;
}
async getAccessToken(options) {
async getAccessToken(options) {
const requestData = {

@@ -91,4 +109,4 @@ url: `${this.oauth}/access_token`,

};
var parameters = { "oauth_verifier": options.verifier };
let parameters = { oauth_verifier: options.verifier };
if (parameters) requestData.url += "?" + querystring.stringify(parameters);

@@ -108,12 +126,12 @@

})
.then(res => res.text())
.then(txt => querystring.parse(txt));
.then(res => res.text())
.then(txt => querystring.parse(txt));
return results;
}
async get(resource, parameters) {
_makeRequest(method, resource, parameters) {
const requestData = {
url: `${this.url}/${resource}.json`,
method: "GET"
method
};

@@ -132,3 +150,15 @@ if (parameters) requestData.url += "?" + querystring.stringify(parameters);

}
return {
requestData,
headers
};
}
async get(resource, parameters) {
const { requestData, headers } = this._makeRequest(
"GET",
resource,
parameters
);
const results = await Fetch(requestData.url, { headers }).then(res =>

@@ -139,22 +169,10 @@ res.json()

}
async post(resource, body, parameters) {
const requestData = {
url: `${this.url}/${resource}.json`,
method: "POST"
};
const { requestData, headers } = this._makeRequest(
"POST",
resource,
parameters
);
if (parameters) requestData.url += "?" + querystring.stringify(parameters);
let headers = {};
if (this.authType === "User") {
headers = this.client.toHeader(
this.client.authorize(requestData, this.token)
);
} else {
headers = {
Authorization: `Bearer ${this.config.bearer_token}`
};
}
const results = await Fetch(requestData.url, {

@@ -206,2 +224,1 @@ method: "POST",

module.exports = Twitter;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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