Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

twitter-lite

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

twitter-lite - npm Package Compare versions

Comparing version 0.8.2 to 0.9.0

CHANGELOG.md

2

dist/twitter.js

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

var e=require("crypto"),t=require("oauth-1.0a"),r=require("cross-fetch"),n=require("querystring"),s=require("./stream"),o=function(e,t){return void 0===t&&(t="1.1"),"https://"+e+".twitter.com/"+t},i={subdomain:"api",consumer_key:null,consumer_secret:null,access_token_key:null,access_token_secret:null,bearer_token:null},u=["direct_messages/events/new","direct_messages/welcome_messages/new","direct_messages/welcome_messages/rules/new"],a={"Content-Type":"application/json",Accept:"application/json"};function c(e){return e.replace(/!/g,"%21").replace(/\*/g,"%2A").replace(/'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29")}var h=function(r){var n,s=Object.assign({},i,r);this.authType=s.bearer_token?"App":"User",this.client=t({consumer:{key:(n={key:s.consumer_key,secret:s.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:s.access_token_key,secret:s.access_token_secret},this.url=o(s.subdomain),this.oauth=o(s.subdomain,"oauth"),this.config=s};h._handleResponse=function(e){var t=e.headers.raw();return e.json().then(function(e){return e._headers=t,e})},h.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(h._handleResponse).then(function(r){try{return e(r)}catch(e){return t(e)}},t)}.bind(this))},h.prototype.getRequestToken=function(e){return new Promise(function(t,s){var o,i,u;return o={url:this.oauth+"/request_token",method:"POST"},i={},e&&(i={oauth_callback:e}),i&&(o.url+="?"+n.stringify(i)),u=this.client.toHeader(this.client.authorize(o,{})),r(o.url,{method:"POST",headers:Object.assign({},a,u)}).then(function(e){return e.text()}).then(function(e){return n.parse(e)}).then(function(e){try{return t(e)}catch(e){return s(e)}},s)}.bind(this))},h.prototype.getAccessToken=function(e){return new Promise(function(t,s){var o,i,u;return o={url:this.oauth+"/access_token",method:"POST"},(i={oauth_verifier:e.verifier})&&(o.url+="?"+n.stringify(i)),u=this.client.toHeader(this.client.authorize(o,{key:e.key,secret:e.secret})),r(o.url,{method:"POST",headers:Object.assign({},a,u)}).then(function(e){return e.text()}).then(function(e){return n.parse(e)}).then(function(e){try{return t(e)}catch(e){return s(e)}},s)}.bind(this))},h.prototype._makeRequest=function(e,t,r){var s={url:this.url+"/"+t+".json",method:e};r&&("POST"===e?s.data=r:s.url+="?"+n.stringify(r));return{requestData:s,headers:"User"===this.authType?this.client.toHeader(this.client.authorize(s,this.token)):{Authorization:"Bearer "+this.config.bearer_token}}},h.prototype.get=function(e,t){var n=this._makeRequest("GET",e,t);return r(n.requestData.url,{headers:n.headers}).then(h._handleResponse).then(function(e){return"errors"in e?Promise.reject(e):e})},h.prototype.post=function(e,t,s){var o=this._makeRequest("POST",e,s),i=o.requestData,d=Object.assign({},a,o.headers);return u.includes(e)?t=JSON.stringify(t):(t=n.stringify(s),d["Content-Type"]="application/x-www-form-urlencoded"),r(i.url,{method:"POST",headers:d,body:c(t)}).then(h._handleResponse).then(function(e){return"errors"in e?Promise.reject(e):e})},h.prototype.stream=function(e,t){var i=this;if("User"!==this.authType)throw new Error("Streams require user context authentication");var u=new s,a={url:o("stream")+"/"+e+".json",method:"POST"};t&&(a.data=t);var h=this.client.toHeader(this.client.authorize(a,this.token));return r(a.url,{method:"POST",headers:Object.assign({},h,{"Content-Type":"application/x-www-form-urlencoded"}),body:c(n.stringify(t))}).then(function(e){u.destroy=i.stream.destroy=function(){return e.body.destroy()},200===e.status?u.emit("start",e):u.emit("error",Error("Status Code: "+e.status)),e.body.on("data",function(e){return u.parse(e)}).on("error",function(e){return u.emit("error",e)}).on("end",function(){return u.emit("end",e)})}).catch(function(e){return u.emit("error",e)}),u},module.exports=h;
var e=require("crypto"),t=require("oauth-1.0a"),r=require("cross-fetch"),n=require("querystring"),s=require("./stream"),o=function(e,t){return void 0===t&&(t="1.1"),"https://"+e+".twitter.com/"+t},i={subdomain:"api",consumer_key:null,consumer_secret:null,access_token_key:null,access_token_secret:null,bearer_token:null},u=["direct_messages/events/new","direct_messages/welcome_messages/new","direct_messages/welcome_messages/rules/new"],a={"Content-Type":"application/json",Accept:"application/json"};function c(e){return e.replace(/!/g,"%21").replace(/\*/g,"%2A").replace(/'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29")}var h=function(r){var n,s=Object.assign({},i,r);this.authType=s.bearer_token?"App":"User",this.client=t({consumer:{key:(n={key:s.consumer_key,secret:s.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:s.access_token_key,secret:s.access_token_secret},this.url=o(s.subdomain),this.oauth=o(s.subdomain,"oauth"),this.config=s};h._handleResponse=function(e){var t=e.headers.raw();return 204===e.status?{_headers:t}:e.json().then(function(e){return e._headers=t,e})},h.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(h._handleResponse).then(function(r){try{return e(r)}catch(e){return t(e)}},t)}.bind(this))},h.prototype.getRequestToken=function(e){return new Promise(function(t,s){var o,i,u;return o={url:this.oauth+"/request_token",method:"POST"},i={},e&&(i={oauth_callback:e}),i&&(o.url+="?"+n.stringify(i)),u=this.client.toHeader(this.client.authorize(o,{})),r(o.url,{method:"POST",headers:Object.assign({},a,u)}).then(function(e){return e.text()}).then(function(e){return n.parse(e)}).then(function(e){try{return t(e)}catch(e){return s(e)}},s)}.bind(this))},h.prototype.getAccessToken=function(e){return new Promise(function(t,s){var o,i,u;return o={url:this.oauth+"/access_token",method:"POST"},(i={oauth_verifier:e.verifier})&&(o.url+="?"+n.stringify(i)),u=this.client.toHeader(this.client.authorize(o,{key:e.key,secret:e.secret})),r(o.url,{method:"POST",headers:Object.assign({},a,u)}).then(function(e){return e.text()}).then(function(e){return n.parse(e)}).then(function(e){try{return t(e)}catch(e){return s(e)}},s)}.bind(this))},h.prototype._makeRequest=function(e,t,r){var s={url:this.url+"/"+t+".json",method:e};r&&("POST"===e?s.data=r:s.url+="?"+n.stringify(r));return{requestData:s,headers:"User"===this.authType?this.client.toHeader(this.client.authorize(s,this.token)):{Authorization:"Bearer "+this.config.bearer_token}}},h.prototype.get=function(e,t){var n=this._makeRequest("GET",e,t);return r(n.requestData.url,{headers:n.headers}).then(h._handleResponse).then(function(e){return"errors"in e?Promise.reject(e):e})},h.prototype.post=function(e,t){var s=this._makeRequest("POST",e,u.includes(e)?null:t),o=s.requestData,i=Object.assign({},a,s.headers);return u.includes(e)?t=JSON.stringify(t):(t=n.stringify(t),i["Content-Type"]="application/x-www-form-urlencoded"),r(o.url,{method:"POST",headers:i,body:c(t)}).then(h._handleResponse).then(function(e){return"errors"in e?Promise.reject(e):e})},h.prototype.stream=function(e,t){var i=this;if("User"!==this.authType)throw new Error("Streams require user context authentication");var u=new s,a={url:o("stream")+"/"+e+".json",method:"POST"};t&&(a.data=t);var h=this.client.toHeader(this.client.authorize(a,this.token));return r(a.url,{method:"POST",headers:Object.assign({},h,{"Content-Type":"application/x-www-form-urlencoded"}),body:c(n.stringify(t))}).then(function(e){u.destroy=i.stream.destroy=function(){return e.body.destroy()},200===e.status?u.emit("start",e):u.emit("error",Error("Status Code: "+e.status)),e.body.on("data",function(e){return u.parse(e)}).on("error",function(e){return u.emit("error",e)}).on("end",function(){return u.emit("end",e)})}).catch(function(e){return u.emit("error",e)}),u},module.exports=h;
//# sourceMappingURL=twitter.js.map

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

var e=require("crypto"),t=require("oauth-1.0a"),r=require("cross-fetch"),n=require("querystring"),s=require("./stream"),o=function(e,t){return void 0===t&&(t="1.1"),"https://"+e+".twitter.com/"+t},i={subdomain:"api",consumer_key:null,consumer_secret:null,access_token_key:null,access_token_secret:null,bearer_token:null},u=["direct_messages/events/new","direct_messages/welcome_messages/new","direct_messages/welcome_messages/rules/new"],a={"Content-Type":"application/json",Accept:"application/json"};function c(e){return e.replace(/!/g,"%21").replace(/\*/g,"%2A").replace(/'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29")}var h=function(r){var n,s=Object.assign({},i,r);this.authType=s.bearer_token?"App":"User",this.client=t({consumer:{key:(n={key:s.consumer_key,secret:s.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:s.access_token_key,secret:s.access_token_secret},this.url=o(s.subdomain),this.oauth=o(s.subdomain,"oauth"),this.config=s};h._handleResponse=function(e){var t=e.headers.raw();return e.json().then(function(e){return e._headers=t,e})},h.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(h._handleResponse).then(function(r){try{return e(r)}catch(e){return t(e)}},t)}.bind(this))},h.prototype.getRequestToken=function(e){return new Promise(function(t,s){var o,i,u;return o={url:this.oauth+"/request_token",method:"POST"},i={},e&&(i={oauth_callback:e}),i&&(o.url+="?"+n.stringify(i)),u=this.client.toHeader(this.client.authorize(o,{})),r(o.url,{method:"POST",headers:Object.assign({},a,u)}).then(function(e){return e.text()}).then(function(e){return n.parse(e)}).then(function(e){try{return t(e)}catch(e){return s(e)}},s)}.bind(this))},h.prototype.getAccessToken=function(e){return new Promise(function(t,s){var o,i,u;return o={url:this.oauth+"/access_token",method:"POST"},(i={oauth_verifier:e.verifier})&&(o.url+="?"+n.stringify(i)),u=this.client.toHeader(this.client.authorize(o,{key:e.key,secret:e.secret})),r(o.url,{method:"POST",headers:Object.assign({},a,u)}).then(function(e){return e.text()}).then(function(e){return n.parse(e)}).then(function(e){try{return t(e)}catch(e){return s(e)}},s)}.bind(this))},h.prototype._makeRequest=function(e,t,r){var s={url:this.url+"/"+t+".json",method:e};r&&("POST"===e?s.data=r:s.url+="?"+n.stringify(r));return{requestData:s,headers:"User"===this.authType?this.client.toHeader(this.client.authorize(s,this.token)):{Authorization:"Bearer "+this.config.bearer_token}}},h.prototype.get=function(e,t){var n=this._makeRequest("GET",e,t);return r(n.requestData.url,{headers:n.headers}).then(h._handleResponse).then(function(e){return"errors"in e?Promise.reject(e):e})},h.prototype.post=function(e,t,s){var o=this._makeRequest("POST",e,s),i=o.requestData,d=Object.assign({},a,o.headers);return u.includes(e)?t=JSON.stringify(t):(t=n.stringify(s),d["Content-Type"]="application/x-www-form-urlencoded"),r(i.url,{method:"POST",headers:d,body:c(t)}).then(h._handleResponse).then(function(e){return"errors"in e?Promise.reject(e):e})},h.prototype.stream=function(e,t){var i=this;if("User"!==this.authType)throw new Error("Streams require user context authentication");var u=new s,a={url:o("stream")+"/"+e+".json",method:"POST"};t&&(a.data=t);var h=this.client.toHeader(this.client.authorize(a,this.token));return r(a.url,{method:"POST",headers:Object.assign({},h,{"Content-Type":"application/x-www-form-urlencoded"}),body:c(n.stringify(t))}).then(function(e){u.destroy=i.stream.destroy=function(){return e.body.destroy()},200===e.status?u.emit("start",e):u.emit("error",Error("Status Code: "+e.status)),e.body.on("data",function(e){return u.parse(e)}).on("error",function(e){return u.emit("error",e)}).on("end",function(){return u.emit("end",e)})}).catch(function(e){return u.emit("error",e)}),u},module.exports=h;
var e=require("crypto"),t=require("oauth-1.0a"),r=require("cross-fetch"),n=require("querystring"),s=require("./stream"),o=function(e,t){return void 0===t&&(t="1.1"),"https://"+e+".twitter.com/"+t},i={subdomain:"api",consumer_key:null,consumer_secret:null,access_token_key:null,access_token_secret:null,bearer_token:null},u=["direct_messages/events/new","direct_messages/welcome_messages/new","direct_messages/welcome_messages/rules/new"],a={"Content-Type":"application/json",Accept:"application/json"};function c(e){return e.replace(/!/g,"%21").replace(/\*/g,"%2A").replace(/'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29")}var h=function(r){var n,s=Object.assign({},i,r);this.authType=s.bearer_token?"App":"User",this.client=t({consumer:{key:(n={key:s.consumer_key,secret:s.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:s.access_token_key,secret:s.access_token_secret},this.url=o(s.subdomain),this.oauth=o(s.subdomain,"oauth"),this.config=s};h._handleResponse=function(e){var t=e.headers.raw();return 204===e.status?{_headers:t}:e.json().then(function(e){return e._headers=t,e})},h.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(h._handleResponse).then(function(r){try{return e(r)}catch(e){return t(e)}},t)}.bind(this))},h.prototype.getRequestToken=function(e){return new Promise(function(t,s){var o,i,u;return o={url:this.oauth+"/request_token",method:"POST"},i={},e&&(i={oauth_callback:e}),i&&(o.url+="?"+n.stringify(i)),u=this.client.toHeader(this.client.authorize(o,{})),r(o.url,{method:"POST",headers:Object.assign({},a,u)}).then(function(e){return e.text()}).then(function(e){return n.parse(e)}).then(function(e){try{return t(e)}catch(e){return s(e)}},s)}.bind(this))},h.prototype.getAccessToken=function(e){return new Promise(function(t,s){var o,i,u;return o={url:this.oauth+"/access_token",method:"POST"},(i={oauth_verifier:e.verifier})&&(o.url+="?"+n.stringify(i)),u=this.client.toHeader(this.client.authorize(o,{key:e.key,secret:e.secret})),r(o.url,{method:"POST",headers:Object.assign({},a,u)}).then(function(e){return e.text()}).then(function(e){return n.parse(e)}).then(function(e){try{return t(e)}catch(e){return s(e)}},s)}.bind(this))},h.prototype._makeRequest=function(e,t,r){var s={url:this.url+"/"+t+".json",method:e};r&&("POST"===e?s.data=r:s.url+="?"+n.stringify(r));return{requestData:s,headers:"User"===this.authType?this.client.toHeader(this.client.authorize(s,this.token)):{Authorization:"Bearer "+this.config.bearer_token}}},h.prototype.get=function(e,t){var n=this._makeRequest("GET",e,t);return r(n.requestData.url,{headers:n.headers}).then(h._handleResponse).then(function(e){return"errors"in e?Promise.reject(e):e})},h.prototype.post=function(e,t){var s=this._makeRequest("POST",e,u.includes(e)?null:t),o=s.requestData,i=Object.assign({},a,s.headers);return u.includes(e)?t=JSON.stringify(t):(t=n.stringify(t),i["Content-Type"]="application/x-www-form-urlencoded"),r(o.url,{method:"POST",headers:i,body:c(t)}).then(h._handleResponse).then(function(e){return"errors"in e?Promise.reject(e):e})},h.prototype.stream=function(e,t){var i=this;if("User"!==this.authType)throw new Error("Streams require user context authentication");var u=new s,a={url:o("stream")+"/"+e+".json",method:"POST"};t&&(a.data=t);var h=this.client.toHeader(this.client.authorize(a,this.token));return r(a.url,{method:"POST",headers:Object.assign({},h,{"Content-Type":"application/x-www-form-urlencoded"}),body:c(n.stringify(t))}).then(function(e){u.destroy=i.stream.destroy=function(){return e.body.destroy()},200===e.status?u.emit("start",e):u.emit("error",Error("Status Code: "+e.status)),e.body.on("data",function(e){return u.parse(e)}).on("error",function(e){return u.emit("error",e)}).on("end",function(){return u.emit("end",e)})}).catch(function(e){return u.emit("error",e)}),u},module.exports=h;
//# sourceMappingURL=twitter.m.js.map

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

!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"),s=function(e,t){return void 0===t&&(t="1.1"),"https://"+e+".twitter.com/"+t},i={subdomain:"api",consumer_key:null,consumer_secret:null,access_token_key:null,access_token_secret:null,bearer_token:null},u=["direct_messages/events/new","direct_messages/welcome_messages/new","direct_messages/welcome_messages/rules/new"],a={"Content-Type":"application/json",Accept:"application/json"};function c(e){return e.replace(/!/g,"%21").replace(/\*/g,"%2A").replace(/'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29")}var h=function(r){var n,o=Object.assign({},i,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=s(o.subdomain),this.oauth=s(o.subdomain,"oauth"),this.config=o};h._handleResponse=function(e){var t=e.headers.raw();return e.json().then(function(e){return e._headers=t,e})},h.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(h._handleResponse).then(function(r){try{return e(r)}catch(e){return t(e)}},t)}.bind(this))},h.prototype.getRequestToken=function(e){return new Promise(function(t,o){var s,i,u;return s={url:this.oauth+"/request_token",method:"POST"},i={},e&&(i={oauth_callback:e}),i&&(s.url+="?"+n.stringify(i)),u=this.client.toHeader(this.client.authorize(s,{})),r(s.url,{method:"POST",headers:Object.assign({},a,u)}).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))},h.prototype.getAccessToken=function(e){return new Promise(function(t,o){var s,i,u;return s={url:this.oauth+"/access_token",method:"POST"},(i={oauth_verifier:e.verifier})&&(s.url+="?"+n.stringify(i)),u=this.client.toHeader(this.client.authorize(s,{key:e.key,secret:e.secret})),r(s.url,{method:"POST",headers:Object.assign({},a,u)}).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))},h.prototype._makeRequest=function(e,t,r){var o={url:this.url+"/"+t+".json",method:e};r&&("POST"===e?o.data=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}}},h.prototype.get=function(e,t){var n=this._makeRequest("GET",e,t);return r(n.requestData.url,{headers:n.headers}).then(h._handleResponse).then(function(e){return"errors"in e?Promise.reject(e):e})},h.prototype.post=function(e,t,o){var s=this._makeRequest("POST",e,o),i=s.requestData,d=Object.assign({},a,s.headers);return u.includes(e)?t=JSON.stringify(t):(t=n.stringify(o),d["Content-Type"]="application/x-www-form-urlencoded"),r(i.url,{method:"POST",headers:d,body:c(t)}).then(h._handleResponse).then(function(e){return"errors"in e?Promise.reject(e):e})},h.prototype.stream=function(e,t){var i=this;if("User"!==this.authType)throw new Error("Streams require user context authentication");var u=new o,a={url:s("stream")+"/"+e+".json",method:"POST"};t&&(a.data=t);var h=this.client.toHeader(this.client.authorize(a,this.token));return r(a.url,{method:"POST",headers:Object.assign({},h,{"Content-Type":"application/x-www-form-urlencoded"}),body:c(n.stringify(t))}).then(function(e){u.destroy=i.stream.destroy=function(){return e.body.destroy()},200===e.status?u.emit("start",e):u.emit("error",Error("Status Code: "+e.status)),e.body.on("data",function(e){return u.parse(e)}).on("error",function(e){return u.emit("error",e)}).on("end",function(){return u.emit("end",e)})}).catch(function(e){return u.emit("error",e)}),u},module.exports=h});
!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"),s=function(e,t){return void 0===t&&(t="1.1"),"https://"+e+".twitter.com/"+t},i={subdomain:"api",consumer_key:null,consumer_secret:null,access_token_key:null,access_token_secret:null,bearer_token:null},u=["direct_messages/events/new","direct_messages/welcome_messages/new","direct_messages/welcome_messages/rules/new"],a={"Content-Type":"application/json",Accept:"application/json"};function c(e){return e.replace(/!/g,"%21").replace(/\*/g,"%2A").replace(/'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29")}var h=function(r){var n,o=Object.assign({},i,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=s(o.subdomain),this.oauth=s(o.subdomain,"oauth"),this.config=o};h._handleResponse=function(e){var t=e.headers.raw();return 204===e.status?{_headers:t}:e.json().then(function(e){return e._headers=t,e})},h.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(h._handleResponse).then(function(r){try{return e(r)}catch(e){return t(e)}},t)}.bind(this))},h.prototype.getRequestToken=function(e){return new Promise(function(t,o){var s,i,u;return s={url:this.oauth+"/request_token",method:"POST"},i={},e&&(i={oauth_callback:e}),i&&(s.url+="?"+n.stringify(i)),u=this.client.toHeader(this.client.authorize(s,{})),r(s.url,{method:"POST",headers:Object.assign({},a,u)}).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))},h.prototype.getAccessToken=function(e){return new Promise(function(t,o){var s,i,u;return s={url:this.oauth+"/access_token",method:"POST"},(i={oauth_verifier:e.verifier})&&(s.url+="?"+n.stringify(i)),u=this.client.toHeader(this.client.authorize(s,{key:e.key,secret:e.secret})),r(s.url,{method:"POST",headers:Object.assign({},a,u)}).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))},h.prototype._makeRequest=function(e,t,r){var o={url:this.url+"/"+t+".json",method:e};r&&("POST"===e?o.data=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}}},h.prototype.get=function(e,t){var n=this._makeRequest("GET",e,t);return r(n.requestData.url,{headers:n.headers}).then(h._handleResponse).then(function(e){return"errors"in e?Promise.reject(e):e})},h.prototype.post=function(e,t){var o=this._makeRequest("POST",e,u.includes(e)?null:t),s=o.requestData,i=Object.assign({},a,o.headers);return u.includes(e)?t=JSON.stringify(t):(t=n.stringify(t),i["Content-Type"]="application/x-www-form-urlencoded"),r(s.url,{method:"POST",headers:i,body:c(t)}).then(h._handleResponse).then(function(e){return"errors"in e?Promise.reject(e):e})},h.prototype.stream=function(e,t){var i=this;if("User"!==this.authType)throw new Error("Streams require user context authentication");var u=new o,a={url:s("stream")+"/"+e+".json",method:"POST"};t&&(a.data=t);var h=this.client.toHeader(this.client.authorize(a,this.token));return r(a.url,{method:"POST",headers:Object.assign({},h,{"Content-Type":"application/x-www-form-urlencoded"}),body:c(n.stringify(t))}).then(function(e){u.destroy=i.stream.destroy=function(){return e.body.destroy()},200===e.status?u.emit("start",e):u.emit("error",Error("Status Code: "+e.status)),e.body.on("data",function(e){return u.parse(e)}).on("error",function(e){return u.emit("error",e)}).on("end",function(){return u.emit("end",e)})}).catch(function(e){return u.emit("error",e)}),u},module.exports=h});
//# sourceMappingURL=twitter.umd.js.map
{
"name": "twitter-lite",
"version": "0.8.2",
"version": "0.9.0",
"description": "A tiny, full-featured client / server library for the Twitter API",

@@ -11,4 +11,4 @@ "source": [

"module": "dist/twitter.m.js",
"repository": "preposterous/twitter-lite",
"homepage": "https://github.com/preposterous/twitter-lite",
"repository": "draftbit/twitter-lite",
"homepage": "https://github.com/draftbit/twitter-lite",
"author": "Peter Piekarczyk <peter@peterp.me>",

@@ -32,3 +32,3 @@ "license": "MIT",

"dependencies": {
"cross-fetch": "^1.1.1",
"cross-fetch": "^3.0.0",
"oauth-1.0a": "^2.2.4"

@@ -38,9 +38,9 @@ },

"@types/jest": "^23.3.10",
"dotenv": "^5.0.1",
"dotenv": "^6.2.0",
"flow-bin": "^0.68.0",
"husky": "^0.14.3",
"jest": "^22.4.4",
"lint-staged": "^7.0.5",
"jest": "^23.6.0",
"lint-staged": "^8.1.0",
"microbundle": "^0.4.3",
"prettier": "^1.11.1"
"prettier": "^1.15.3"
},

@@ -50,2 +50,3 @@ "scripts": {

"test": "jest",
"echover": "echo $npm_package_version",
"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",

@@ -55,3 +56,3 @@ "precommit": "lint-staged"

"lint-staged": {
"*.{js,json,css,md}": [
"*.{js,md}": [
"prettier --write",

@@ -58,0 +59,0 @@ "git add"

@@ -186,3 +186,3 @@ # Twitter Lite

After you've destroyed a stream, you can create another one - see the ["should switch from one stream to another" test](blob/master/test/stream.test.js#L131).
After you've destroyed a stream, you can create another one - see the ["should switch from one stream to another" test](https://github.com/draftbit/twitter-lite/blob/9e0845585c756aee10e8b0acaabfbc3e4f32b81c/test/stream.test.js#L131).

@@ -208,7 +208,7 @@ ## Methods

### .post(endpoint, body, parameters)
### .post(endpoint, parameters)
Same return as `.get()`.
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:
Use the `.post` method for actions that change state, or when the total size of the parameters might be too long for a GET request. 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:

@@ -223,3 +223,3 @@ ```es6

await client.post("friendships/create", null, {
await client.post("friendships/create", {
screen_name: "dandv"

@@ -229,4 +229,10 @@ });

Note: [for now](https://github.com/draftbit/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.
The second use case for POST is when you need to pass more parameters than suitable for the length of a URL, such as when [looking up a larger number of user ids or screen names](https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-users-lookup):
```es6
const users = await client.post("users/lookup", {
screen_name: "longScreenName1,longerScreeName2,...,veryLongScreenName100"
});
```
### .getBearerToken()

@@ -248,6 +254,4 @@

**Breaking change in v0.7**
`.get` and `.post` reject on error, so you can use try/catch to handle errors. The error object contains an `errors` property with the error `code` and `message`, and a `_headers` property with the the HTTP response code and [Headers](https://developer.twitter.com/en/docs/basics/rate-limiting.html) object returned by the Twitter API. Note that each `_headers` property is an array, usually of length 1.
Given that [developers expect promises to reject when they don't return the requested data](https://github.com/ttezel/twit/issues/256), `.get` and `.post` now reject instead of silently returning API errors as an array under the `errors` key of the response object. You can use try/catch to handle errors. The error object contains an `errors` property with the error `code` and `message`, and a `_headers` property with the the HTTP response code and [Headers](https://developer.twitter.com/en/docs/basics/rate-limiting.html) object returned by the Twitter API. Note that each `_headers` property is an array, usually of length 1.
```es6

@@ -300,3 +304,3 @@ try {

9. `npm run precommit` to lint with [prettier](https://www.npmjs.com/package/prettier)
10. Commit using a [descriptive message](https://chris.beams.io/posts/git-commit/) (please squash all your commits into one!)
10. Commit using a [descriptive message](https://chris.beams.io/posts/git-commit/) (please squash commits into one per fix/improvement!)
11. `git push` and submit your PR!

@@ -308,11 +312,11 @@

- [@dandv](https://github.com/dandv)
- [@peterpme](https://github.com/peterpme)
- [@dandv](https://github.com/dandv)
Over the years, thanks to:
- [@ttezel](https://github.com/ttezel)
- [@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)

@@ -79,5 +79,5 @@ const crypto = require("crypto");

/**
* Parse the JSON from a Response object and add the Headers under _headers
* Parse the JSON from a Response object and add the Headers under `_headers`
* @param {Response} response - the Response object returned by Fetch
* @return {Promise<Object>}
* @return {Promise<object>}
* @private

@@ -87,2 +87,8 @@ */

const headers = response.headers.raw(); // https://github.com/bitinn/node-fetch/issues/495
// Return empty response on 204 "No content"
if (response.status === 204)
return {
_headers: headers
};
// Otherwise, parse JSON response
return response.json().then(res => {

@@ -196,2 +202,9 @@ res._headers = headers; // TODO: this creates an array-like object when it adds _headers to an array response

/**
* Send a GET request
* @param {string} resource - endpoint, e.g. `followers/ids`
* @param {object} parameters
* @returns {Promise<object>} Promise resolving to the response from the Twitter API.
* The `_header` property will be set to the Response headers (useful for checking rate limits)
*/
get(resource, parameters) {

@@ -211,7 +224,15 @@ const { requestData, headers } = this._makeRequest(

post(resource, body, parameters) {
/**
* Send a POST request
* @param {string} resource - endpoint, e.g. `users/lookup`
* @param {object} body - POST parameters object.
* Will be encoded appropriately (JSON or urlencoded) based on the resource
* @returns {Promise<object>} Promise resolving to the response from the Twitter API.
* The `_header` property will be set to the Response headers (useful for checking rate limits)
*/
post(resource, body) {
const { requestData, headers } = this._makeRequest(
"POST",
resource,
parameters
JSON_ENDPOINTS.includes(resource) ? null : body // don't sign JSON bodies; only parameters
);

@@ -223,3 +244,3 @@

} else {
body = querystring.stringify(parameters);
body = querystring.stringify(body);
postHeaders["Content-Type"] = "application/x-www-form-urlencoded";

@@ -239,2 +260,8 @@ }

/**
*
* @param {string} resource - endpoint, e.g. `statuses/filter`
* @param {object} parameters
* @returns {Stream}
*/
stream(resource, parameters) {

@@ -241,0 +268,0 @@ if (this.authType !== "User")

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc