@orbis-systems/orbis-api-client
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function a(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}(),_Quotes=require("./categories/Quotes"),_Quotes2=_interopRequireDefault(_Quotes),_Research=require("./categories/Research"),_Research2=_interopRequireDefault(_Research),_User=require("./categories/User"),_User2=_interopRequireDefault(_User),_Options=require("./categories/Options"),_Options2=_interopRequireDefault(_Options),_Advisory=require("./categories/Advisory"),_Advisory2=_interopRequireDefault(_Advisory),_Watchlists=require("./categories/Watchlists"),_Watchlists2=_interopRequireDefault(_Watchlists),_ETFs=require("./categories/ETFs"),_ETFs2=_interopRequireDefault(_ETFs),_News=require("./categories/News"),_News2=_interopRequireDefault(_News),_CorporateActions=require("./categories/CorporateActions"),_CorporateActions2=_interopRequireDefault(_CorporateActions),_LocalStorage=require("./session_stores/LocalStorage"),_LocalStorage2=_interopRequireDefault(_LocalStorage),_axios=require("axios"),_axios2=_interopRequireDefault(_axios),_jsonwebtoken=require("jsonwebtoken"),_jsonwebtoken2=_interopRequireDefault(_jsonwebtoken),_base=require("base-64"),_base2=_interopRequireDefault(_base);function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function _asyncToGenerator(a){return function(){var b=a.apply(this,arguments);return new Promise(function(a,c){function d(e,f){try{var g=b[e](f),h=g.value}catch(a){return void c(a)}return g.done?void a(h):Promise.resolve(h).then(function(a){d("next",a)},function(a){d("throw",a)})}return d("next")})}}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}require("babel-core/register"),require("babel-polyfill");var APIClient=function(){function a(b){_classCallCheck(this,a),this.config=b,this.config.session_store||(this.config.session_store=_LocalStorage2.default),this.quotes=new _Quotes2.default(this),this.research=new _Research2.default(this),this.user=new _User2.default(this),this.options=new _Options2.default(this),this.advisory=new _Advisory2.default(this),this.watchlists=new _Watchlists2.default(this),this.etfs=new _ETFs2.default(this),this.news=new _News2.default(this),this.corporate_actions=new _CorporateActions2.default(this)}return _createClass(a,[{key:"login",value:function(){var a=_asyncToGenerator(regeneratorRuntime.mark(function a(b,c){var d;return regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.prev=0,a.next=3,this.post("auth/v1/login",{username:b,password:c});case 3:return d=a.sent,a.next=6,this.config.session_store.set("sessionId",d.sessionId,60);case 6:return a.abrupt("return",!0);case 9:return a.prev=9,a.t0=a["catch"](0),a.abrupt("return",!1);case 12:case"end":return a.stop();}},a,this,[[0,9]])}));return function(){return a.apply(this,arguments)}}()},{key:"logout",value:function(){var a=_asyncToGenerator(regeneratorRuntime.mark(function a(){return regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.prev=0,a.next=3,this.get("auth/v1/logout");case 3:return this.expireSession(),a.abrupt("return",!0);case 7:return a.prev=7,a.t0=a["catch"](0),a.abrupt("return",!1);case 10:case"end":return a.stop();}},a,this,[[0,7]])}));return function(){return a.apply(this,arguments)}}()},{key:"headers",value:function(){if(!this.hasSession())return{};var a=this.config.session_store,b=a.get("sessionId");console.log(b);var c=_jsonwebtoken2.default.sign({sub:b},"test",{expiresIn:"5s"});return{Referrer:"http://localhost",Authorization:"Session "+_base2.default.encode(c)}}},{key:"hasSession",value:function(){return this.config.session_store.has("sessionId")}},{key:"expireSession",value:function(){var a=this.config.session_store;a.set("sessionId",null,0)}},{key:"handleResponse",value:function(a){return 200===a.status?a.data:void(401===a.status?console.log({status:!1,message:"unauthorized"}):console.log({status:!1,message:a.status+" - "+a.statusText}))}},{key:"post",value:function(){var a=_asyncToGenerator(regeneratorRuntime.mark(function a(b,c){var d,e,f,g;return regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return d="auth/v1/login"===b?this.config.auth_url:this.config.base_url,e=d+b,f=this.headers(),a.prev=3,a.next=6,_axios2.default.post(e,c,{headers:f});case 6:return g=a.sent,a.abrupt("return",this.handleResponse(g));case 10:return a.prev=10,a.t0=a["catch"](3),a.abrupt("return",this.handleResponse(a.t0.response));case 13:case"end":return a.stop();}},a,this,[[3,10]])}));return function(){return a.apply(this,arguments)}}()},{key:"get",value:function(){var a=_asyncToGenerator(regeneratorRuntime.mark(function a(b,c){var d,e,f;return regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return d=this.config.base_url+b,e=this.headers(),console.log(d,c,e),a.prev=3,a.next=6,_axios2.default.get(d,{params:c,headers:e});case 6:return f=a.sent,a.abrupt("return",this.handleResponse(f));case 10:return a.prev=10,a.t0=a["catch"](3),a.abrupt("return",this.handleResponse(a.t0.response));case 13:case"end":return a.stop();}},a,this,[[3,10]])}));return function(){return a.apply(this,arguments)}}()}]),a}();exports.default=APIClient; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function a(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}(),_Quotes=require("./categories/Quotes"),_Quotes2=_interopRequireDefault(_Quotes),_Research=require("./categories/Research"),_Research2=_interopRequireDefault(_Research),_User=require("./categories/User"),_User2=_interopRequireDefault(_User),_Options=require("./categories/Options"),_Options2=_interopRequireDefault(_Options),_Advisory=require("./categories/Advisory"),_Advisory2=_interopRequireDefault(_Advisory),_Watchlists=require("./categories/Watchlists"),_Watchlists2=_interopRequireDefault(_Watchlists),_ETFs=require("./categories/ETFs"),_ETFs2=_interopRequireDefault(_ETFs),_News=require("./categories/News"),_News2=_interopRequireDefault(_News),_CorporateActions=require("./categories/CorporateActions"),_CorporateActions2=_interopRequireDefault(_CorporateActions),_LocalStorage=require("./session_stores/LocalStorage"),_LocalStorage2=_interopRequireDefault(_LocalStorage),_axios=require("axios"),_axios2=_interopRequireDefault(_axios),_jsonwebtoken=require("jsonwebtoken"),_jsonwebtoken2=_interopRequireDefault(_jsonwebtoken),_base=require("base-64"),_base2=_interopRequireDefault(_base);function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function _asyncToGenerator(a){return function(){var b=a.apply(this,arguments);return new Promise(function(a,c){function d(e,f){try{var g=b[e](f),h=g.value}catch(a){return void c(a)}return g.done?void a(h):Promise.resolve(h).then(function(a){d("next",a)},function(a){d("throw",a)})}return d("next")})}}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}require("babel-core/register"),require("babel-polyfill");var APIClient=function(){function a(b){_classCallCheck(this,a),this.config=b,this.config.session_store||(this.config.session_store=_LocalStorage2.default),this.quotes=new _Quotes2.default(this),this.research=new _Research2.default(this),this.user=new _User2.default(this),this.options=new _Options2.default(this),this.advisory=new _Advisory2.default(this),this.watchlists=new _Watchlists2.default(this),this.etfs=new _ETFs2.default(this),this.news=new _News2.default(this),this.corporate_actions=new _CorporateActions2.default(this)}return _createClass(a,[{key:"login",value:function(){var a=_asyncToGenerator(regeneratorRuntime.mark(function a(b,c){var d;return regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.prev=0,a.next=3,this.post("auth/v1/login",{username:b,password:c});case 3:return d=a.sent,a.next=6,this.config.session_store.set("sessionId",d.sessionId,60);case 6:return a.abrupt("return",!0);case 9:return a.prev=9,a.t0=a["catch"](0),a.abrupt("return",!1);case 12:case"end":return a.stop();}},a,this,[[0,9]])}));return function(){return a.apply(this,arguments)}}()},{key:"logout",value:function(){var a=_asyncToGenerator(regeneratorRuntime.mark(function a(){return regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.prev=0,a.next=3,this.get("auth/v1/logout");case 3:return this.expireSession(),a.abrupt("return",!0);case 7:return a.prev=7,a.t0=a["catch"](0),a.abrupt("return",!1);case 10:case"end":return a.stop();}},a,this,[[0,7]])}));return function(){return a.apply(this,arguments)}}()},{key:"headers",value:function(){if(!this.hasSession())return{};var a=this.config.session_store,b=a.get("sessionId");console.log(b);var c=_jsonwebtoken2.default.sign({sub:b},"test",{expiresIn:"5s"});return{Authorization:"Session "+_base2.default.encode(c)}}},{key:"hasSession",value:function(){return this.config.session_store.has("sessionId")}},{key:"expireSession",value:function(){var a=this.config.session_store;a.set("sessionId",null,0)}},{key:"handleResponse",value:function(a){return 200===a.status?a.data:void(401===a.status?console.log({status:!1,message:"unauthorized"}):console.log({status:!1,message:a.status+" - "+a.statusText}))}},{key:"post",value:function(){var a=_asyncToGenerator(regeneratorRuntime.mark(function a(b,c){var d,e,f,g;return regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return d="auth/v1/login"===b?this.config.auth_url:this.config.base_url,e=d+b,f=this.headers(),a.prev=3,a.next=6,_axios2.default.post(e,c,{headers:f});case 6:return g=a.sent,a.abrupt("return",this.handleResponse(g));case 10:return a.prev=10,a.t0=a["catch"](3),a.abrupt("return",this.handleResponse(a.t0.response));case 13:case"end":return a.stop();}},a,this,[[3,10]])}));return function(){return a.apply(this,arguments)}}()},{key:"get",value:function(){var a=_asyncToGenerator(regeneratorRuntime.mark(function a(b,c){var d,e,f;return regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return d=this.config.base_url+b,e=this.headers(),console.log(d,c,e),a.prev=3,a.next=6,_axios2.default.get(d,{params:c,headers:e});case 6:return f=a.sent,a.abrupt("return",this.handleResponse(f));case 10:return a.prev=10,a.t0=a["catch"](3),a.abrupt("return",this.handleResponse(a.t0.response));case 13:case"end":return a.stop();}},a,this,[[3,10]])}));return function(){return a.apply(this,arguments)}}()}]),a}();exports.default=APIClient; |
{ | ||
"name": "@orbis-systems/orbis-api-client", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/lib/index.js", |
Sorry, the diff of this file is too big to display
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
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
601587