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

rest-client-sdk

Package Overview
Dependencies
Maintainers
1
Versions
109
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rest-client-sdk - npm Package Compare versions

Comparing version 0.5.0 to 0.6.0

138

dist/client/AbstractClient.js

@@ -11,38 +11,39 @@ Object.defineProperty(exports,"__esModule",{value:true});var _extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};}();var _urijs=require('urijs');var _urijs2=_interopRequireDefault(_urijs);

this._tokenStorage=sdk.tokenStorage;
this.entityFactory=sdk.entityFactory;
}_createClass(AbstractClient,[{key:'getDefaultParameters',value:function getDefaultParameters()
this.entityFactory=sdk.entityFactory;}_createClass(AbstractClient,[{key:'getDefaultParameters',value:function getDefaultParameters()
{
return[];
}},{key:'getPathBase',value:function getPathBase()
return[];}},{key:'getPathBase',value:function getPathBase()
{var pathParameters=arguments.length<=0||arguments[0]===undefined?{}:arguments[0];
throw new Error('AbstractClient::getPathBase can not be called directly.\n You must implement "getPathBase" method.');
throw new Error('AbstractClient::getPathBase can not be called directly.\n You must implement "getPathBase" method.');}},{key:'getName',value:function getName()
}},{key:'getName',value:function getName()
{
throw new Error('AbstractClient::getName can not be called directly.\n You must implement "getName" method.');
throw new Error('AbstractClient::getName can not be called directly.\n You must implement "getName" method.');}},{key:'find',value:function find(
}},{key:'find',value:function find(
id){var queryParam=arguments.length<=1||arguments[1]===undefined?{}:arguments[1];var pathParameters=arguments.length<=2||arguments[2]===undefined?{}:arguments[2];
var url=this._generateUrlFromParams(queryParam,pathParameters,id);
return this.createEntityFromJsonResponse(this.authorizedFetch(url),'item');
}},{key:'findBy',value:function findBy(
return this.createEntityFromJsonResponse(this.authorizedFetch(url),'item');}},{key:'findBy',value:function findBy(
criteria){var pathParameters=arguments.length<=1||arguments[1]===undefined?{}:arguments[1];
var url=this._generateUrlFromParams(criteria,pathParameters);
return this.createEntityFromJsonResponse(this.authorizedFetch(url),'list');
}},{key:'findAll',value:function findAll()
queryParam){var pathParameters=arguments.length<=1||arguments[1]===undefined?{}:arguments[1];
var url=this._generateUrlFromParams(queryParam,pathParameters);
{var pathParameters=arguments.length<=0||arguments[0]===undefined?{}:arguments[0];
return this.findBy({},pathParameters);
}},{key:'create',value:function create(
return this.createEntityFromJsonResponse(this.authorizedFetch(url),'list');}},{key:'findAll',value:function findAll()
entity){var pathParameters=arguments.length<=1||arguments[1]===undefined?{}:arguments[1];
var url=this.getPathBase(pathParameters);
{var queryParam=arguments.length<=0||arguments[0]===undefined?{}:arguments[0];var pathParameters=arguments.length<=1||arguments[1]===undefined?{}:arguments[1];
return this.findBy(queryParam,pathParameters);}},{key:'create',value:function create(
entity){var queryParam=arguments.length<=1||arguments[1]===undefined?{}:arguments[1];var pathParameters=arguments.length<=2||arguments[2]===undefined?{}:arguments[2];
var url=new _urijs2.default(this.getPathBase(pathParameters));
url.addSearch(queryParam);
return this.createEntityFromJsonResponse(

@@ -53,9 +54,10 @@ this.authorizedFetch(url,{

'item');
'item');}},{key:'update',value:function update(
}},{key:'update',value:function update(
entity){
var url=entity.get('@id');
entity){var queryParam=arguments.length<=1||arguments[1]===undefined?{}:arguments[1];
var url=new _urijs2.default(entity.get('@id'));
url.addSearch(queryParam);
return this.createEntityFromJsonResponse(

@@ -66,6 +68,6 @@ this.authorizedFetch(url,{

'item');
'item');}},{key:'delete',value:function _delete(
}},{key:'delete',value:function _delete(
entity){

@@ -77,13 +79,13 @@ var url=entity.get('@id');

'item');
'item');}},{key:'createEntityFromJsonResponse',value:function createEntityFromJsonResponse(
}},{key:'createEntityFromJsonResponse',value:function createEntityFromJsonResponse(
requestPromise,listOrItem){var _this=this;
return requestPromise.
then(function(response){return response.json();}).
then(function(val){return _this.entityFactory(val,listOrItem,_this.getName());});
then(function(val){return _this.entityFactory(val,listOrItem,_this.getName());});}},{key:'makeUri',value:function makeUri(
}},{key:'makeUri',value:function makeUri(
input){

@@ -96,26 +98,26 @@ var url=input instanceof _urijs2.default?input:new _urijs2.default(input);

if(this.sdk.config.port){
url.port(this.sdk.config.port);
}
url.port(this.sdk.config.port);}
if(this.sdk.config.prefix){
var segments=url.segment();
segments.unshift(this.sdk.config.prefix);
url.segment(segments);
}
url.segment(segments);}
return url;
}},{key:'authorizedFetch',value:function authorizedFetch(
return url;}},{key:'authorizedFetch',value:function authorizedFetch(
input,init){
var url=this.makeUri(input);
return this._doFetch(url.toString(),init);
}},{key:'_generateUrlFromParams',value:function _generateUrlFromParams(
return this._doFetch(url.toString(),init);}},{key:'_generateUrlFromParams',value:function _generateUrlFromParams(
queryParam){var pathParameters=arguments.length<=1||arguments[1]===undefined?{}:arguments[1];var id=arguments.length<=2||arguments[2]===undefined?null:arguments[2];
var params=queryParam;
if(this.sdk.config.useDefaultParameters){
_extends(params,this.getDefaultParameters());
}
_extends(params,this.getDefaultParameters());}
var url=new _urijs2.default(!!id?

@@ -126,18 +128,18 @@ this.getPathBase(pathParameters)+'/'+id:

if(params){
url.addSearch(params);
}
url.addSearch(params);}
return url;
}},{key:'_doFetch',value:function _doFetch(
return url;}},{key:'_doFetch',value:function _doFetch(
input,init){var _this2=this;
if(!input){
throw new Error('input is empty');
}
throw new Error('input is empty');}
return this._tokenStorage.getAccessToken().
then(function(token){return _this2._fetchWithToken(token,input,init);});
then(function(token){return _this2._fetchWithToken(token,input,init);});}},{key:'_manageAccessDenied',value:function _manageAccessDenied(
}},{key:'_manageAccessDenied',value:function _manageAccessDenied(
response,input,init){var _this3=this;

@@ -153,19 +155,19 @@ return response.json().

catch(function(){
throw new _Error.AccessDeniedError('Unable to renew access_token',response);
});
throw new _Error.AccessDeniedError('Unable to renew access_token',response);});}
}
break;
default:
throw new _Error.AccessDeniedError(body.error_description,response);}
throw new _Error.AccessDeniedError(body.error_description,response);}}
}
throw new _Error.AccessDeniedError('Unable to access ressource: 401 found !',response);
});
}},{key:'_fetchWithToken',value:function _fetchWithToken(
throw new _Error.AccessDeniedError('Unable to access ressource: 401 found !',response);});}},{key:'_fetchWithToken',value:function _fetchWithToken(
accessToken,input,init){var _this4=this;

@@ -180,24 +182,24 @@ var params=init;

if(!params.headers){
params.headers={};
}
params.headers={};}
params.headers=_extends(params.headers,tokenHeaders);
}else{
params={headers:tokenHeaders};
}
params.headers=_extends(params.headers,tokenHeaders);}else
{
params={headers:tokenHeaders};}
return fetch(input,params).
then(function(response){
if(response.status===401){
return _this4._manageAccessDenied(response,input,params);
}else if(response.status===403){
throw new _Error.ForbiddenError('Forbidden acces: 403 found !',response);
}
return _this4._manageAccessDenied(response,input,params);}else
if(response.status===403){
throw new _Error.ForbiddenError('Forbidden acces: 403 found !',response);}
return response;
});
}}]);return AbstractClient;}();exports.default=
return response;});}}]);return AbstractClient;}();exports.default=
AbstractClient;

@@ -9,4 +9,4 @@ Object.defineProperty(exports,"__esModule",{value:true});/**

this.baseResponse=baseResponse;
this.stack=new Error().stack;
}
this.stack=new Error().stack;}
AccessDeniedError.prototype=Object.create(Error.prototype);

@@ -19,4 +19,4 @@ AccessDeniedError.prototype.constructor=AccessDeniedError;

this.baseResponse=baseResponse;
this.stack=new Error().stack;
}
this.stack=new Error().stack;}
ForbiddenError.prototype=Object.create(Error.prototype);

@@ -23,0 +23,0 @@ ForbiddenError.prototype.constructor=ForbiddenError;exports.

Object.defineProperty(exports,"__esModule",{value:true});var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};}();var _immutable=require('immutable');function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}
function createEntity(val,listOrItem){var type=arguments.length<=2||arguments[2]===undefined?null:arguments[2];
return(0,_immutable.fromJS)(val);
}var
return(0,_immutable.fromJS)(val);}var
RestClientSdk=function(){

@@ -16,6 +16,6 @@ function RestClientSdk(tokenStorage,config){var _this=this;var clientList=arguments.length<=2||arguments[2]===undefined?{}:arguments[2];var entityFactory=arguments.length<=3||arguments[3]===undefined?createEntity:arguments[3];_classCallCheck(this,RestClientSdk);

Object.keys(clientList).forEach(function(key){
_this[key]=new clientList[key](_this);
});
}_createClass(RestClientSdk,[{key:'_mergeWithBaseConfig',value:function _mergeWithBaseConfig(
_this[key]=new clientList[key](_this);});}_createClass(RestClientSdk,[{key:'_mergeWithBaseConfig',value:function _mergeWithBaseConfig(
config){

@@ -27,15 +27,15 @@ var newConfig=config;

return newConfig;
}},{key:'_checkConfigValidity',value:function _checkConfigValidity(
return newConfig;}},{key:'_checkConfigValidity',value:function _checkConfigValidity(
config){
if(!(config&&config.path&&config.scheme)){
throw new RangeError('SDK config is not valid, it should contain a "path", a "scheme" parameter,\n and may contain a "port" and a "useDefaultParameters" parameter');
throw new RangeError('SDK config is not valid, it should contain a "path", a "scheme" parameter,\n and may contain a "port" and a "useDefaultParameters" parameter');}}}]);return RestClientSdk;}();exports.default=
}
}}]);return RestClientSdk;}();exports.default=
RestClientSdk;

@@ -5,19 +5,19 @@ Object.defineProperty(exports,"__esModule",{value:true});var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};}();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var AbstractTokenGenerator=function(){

this.canAutogenerateToken=false;
this.checkTokenGeneratorConfig(this.tokenGeneratorConfig);
}_createClass(AbstractTokenGenerator,[{key:"generateToken",value:function generateToken(
this.checkTokenGeneratorConfig(this.tokenGeneratorConfig);}_createClass(AbstractTokenGenerator,[{key:"generateToken",value:function generateToken(
parameters){
throw new Error("AbstractTokenGenerator::generateToken can not be called directly.\n You must implement \"generateToken\" method.");
throw new Error("AbstractTokenGenerator::generateToken can not be called directly.\n You must implement \"generateToken\" method.");}},{key:"refreshToken",value:function refreshToken(
}},{key:"refreshToken",value:function refreshToken(
accessToken,parameters){
throw new Error("AbstractTokenGenerator::refreshToken can not be called directly.\n You must implement \"refreshToken\" method.");
throw new Error("AbstractTokenGenerator::refreshToken can not be called directly.\n You must implement \"refreshToken\" method.");}},{key:"checkTokenGeneratorConfig",value:function checkTokenGeneratorConfig(
}},{key:"checkTokenGeneratorConfig",value:function checkTokenGeneratorConfig(
config){
return true;
}},{key:"convertMapToFormData",value:function convertMapToFormData(
return true;}},{key:"convertMapToFormData",value:function convertMapToFormData(
parameters){

@@ -29,9 +29,9 @@ var keys=Object.keys(parameters);

for(var _iterator=keys,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[typeof Symbol==="function"?Symbol.iterator:"@@iterator"]();;){var _ref;if(_isArray){if(_i>=_iterator.length)break;_ref=_iterator[_i++];}else{_i=_iterator.next();if(_i.done)break;_ref=_i.value;}var key=_ref;
formData.append(key,parameters[key]);
}
formData.append(key,parameters[key]);}
return formData;
}}]);return AbstractTokenGenerator;}();exports.default=
return formData;}}]);return AbstractTokenGenerator;}();exports.default=
AbstractTokenGenerator;

@@ -8,3 +8,3 @@ Object.defineProperty(exports,"__esModule",{value:true});var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};}();var _urijs=require('urijs');var _urijs2=_interopRequireDefault(_urijs);

ClientCredentialsGenerator=function(_AbstractTokenGenerat){_inherits(ClientCredentialsGenerator,_AbstractTokenGenerat);function ClientCredentialsGenerator(){_classCallCheck(this,ClientCredentialsGenerator);return _possibleConstructorReturn(this,(ClientCredentialsGenerator.__proto__||Object.getPrototypeOf(ClientCredentialsGenerator)).apply(this,arguments));}_createClass(ClientCredentialsGenerator,[{key:'generateToken',value:function generateToken()
ClientCredentialsGenerator=function(_AbstractTokenGenerat){_inherits(ClientCredentialsGenerator,_AbstractTokenGenerat);function ClientCredentialsGenerator(){_classCallCheck(this,ClientCredentialsGenerator);return _possibleConstructorReturn(this,Object.getPrototypeOf(ClientCredentialsGenerator).apply(this,arguments));}_createClass(ClientCredentialsGenerator,[{key:'generateToken',value:function generateToken()
{var baseParameters=arguments.length<=0||arguments[0]===undefined?{}:arguments[0];

@@ -21,5 +21,5 @@ var parameters=baseParameters;

if(this.tokenGeneratorConfig.port){
uri.port(this.tokenGeneratorConfig.port);
}
uri.port(this.tokenGeneratorConfig.port);}
var url=uri.toString();

@@ -34,28 +34,28 @@

return response.json().
then(function(responseData){return Promise.reject(responseData);});
}
then(function(responseData){return Promise.reject(responseData);});}
return response.json();
});
}},{key:'refreshToken',value:function refreshToken(
return response.json();});}},{key:'refreshToken',value:function refreshToken(
accessToken,parameters){
return this.generateToken(parameters);
}},{key:'checkTokenGeneratorConfig',value:function checkTokenGeneratorConfig(
return this.generateToken(parameters);}},{key:'checkTokenGeneratorConfig',value:function checkTokenGeneratorConfig(
config){
if(!config||Object.keys(config).length===0){
throw new RangeError(ERROR_CONFIG_EMPTY);
}
throw new RangeError(ERROR_CONFIG_EMPTY);}
if(!(config.path&&config.scheme)){
throw new RangeError(ERROR_CONFIG_PATH_SCHEME);
}
throw new RangeError(ERROR_CONFIG_PATH_SCHEME);}
if(!(config.clientId&&config.clientSecret)){
throw new RangeError(ERROR_CONFIG_CLIENT_INFORMATIONS);
}
}}]);return ClientCredentialsGenerator;}(_AbstractTokenGenerator2.default);exports.default=
throw new RangeError(ERROR_CONFIG_CLIENT_INFORMATIONS);}}}]);return ClientCredentialsGenerator;}(_AbstractTokenGenerator2.default);exports.default=
ClientCredentialsGenerator;

@@ -12,3 +12,3 @@ Object.defineProperty(exports,"__esModule",{value:true});var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};}();var _urijs=require('urijs');var _urijs2=_interopRequireDefault(_urijs);

PasswordGenerator=function(_AbstractTokenGenerat){_inherits(PasswordGenerator,_AbstractTokenGenerat);function PasswordGenerator(){_classCallCheck(this,PasswordGenerator);return _possibleConstructorReturn(this,(PasswordGenerator.__proto__||Object.getPrototypeOf(PasswordGenerator)).apply(this,arguments));}_createClass(PasswordGenerator,[{key:'generateToken',value:function generateToken(
PasswordGenerator=function(_AbstractTokenGenerat){_inherits(PasswordGenerator,_AbstractTokenGenerat);function PasswordGenerator(){_classCallCheck(this,PasswordGenerator);return _possibleConstructorReturn(this,Object.getPrototypeOf(PasswordGenerator).apply(this,arguments));}_createClass(PasswordGenerator,[{key:'generateToken',value:function generateToken(
baseParameters){

@@ -22,10 +22,10 @@ var parameters=baseParameters;

return this._doFetch(parameters);
}},{key:'refreshToken',value:function refreshToken(
return this._doFetch(parameters);}},{key:'refreshToken',value:function refreshToken(
accessToken){var baseParameters=arguments.length<=1||arguments[1]===undefined?{}:arguments[1];
if(!(accessToken&&accessToken.refresh_token)){
throw new Error('refresh_token is not set. Did you called `generateToken` before ?');
}
throw new Error('refresh_token is not set. Did you called `generateToken` before ?');}
var parameters=baseParameters;

@@ -39,19 +39,19 @@

return this._doFetch(parameters);
}},{key:'checkTokenGeneratorConfig',value:function checkTokenGeneratorConfig(
return this._doFetch(parameters);}},{key:'checkTokenGeneratorConfig',value:function checkTokenGeneratorConfig(
config){
if(!config||Object.keys(config).length===0){
throw new RangeError(ERROR_CONFIG_EMPTY);
}
throw new RangeError(ERROR_CONFIG_EMPTY);}
if(!(config.path&&config.scheme)){
throw new RangeError(ERROR_CONFIG_PATH_SCHEME);
}
throw new RangeError(ERROR_CONFIG_PATH_SCHEME);}
if(!(config.clientId&&config.clientSecret)){
throw new RangeError(ERROR_CONFIG_CLIENT_INFORMATIONS);
}
}},{key:'_doFetch',value:function _doFetch(
throw new RangeError(ERROR_CONFIG_CLIENT_INFORMATIONS);}}},{key:'_doFetch',value:function _doFetch(
parameters){

@@ -62,5 +62,5 @@ var uri=new _urijs2.default(this.tokenGeneratorConfig.path);

if(this.tokenGeneratorConfig.port){
uri.port(this.tokenGeneratorConfig.port);
}
uri.port(this.tokenGeneratorConfig.port);}
var url=uri.toString();

@@ -75,20 +75,20 @@

return response.json().
then(function(responseData){return Promise.reject(responseData);});
}
then(function(responseData){return Promise.reject(responseData);});}
return response.json();
});
}},{key:'_checkGenerateParameters',value:function _checkGenerateParameters(
return response.json();});}},{key:'_checkGenerateParameters',value:function _checkGenerateParameters(
parameters){
if(!(parameters&&Object.keys(parameters).length>0)){
throw new RangeError(ERROR_TOKEN_EMPTY);
}
throw new RangeError(ERROR_TOKEN_EMPTY);}
if(!(parameters.username&&parameters.password)){
throw new RangeError(ERROR_TOKEN_USERNAME_PASSWORD);
}
}}]);return PasswordGenerator;}(_AbstractTokenGenerator2.default);exports.default=
throw new RangeError(ERROR_TOKEN_USERNAME_PASSWORD);}}}]);return PasswordGenerator;}(_AbstractTokenGenerator2.default);exports.default=
PasswordGenerator;

@@ -5,19 +5,19 @@ Object.defineProperty(exports,"__esModule",{value:true});var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};}();var _AbstractTokenGenerator=require('./AbstractTokenGenerator');var _AbstractTokenGenerator2=_interopRequireDefault(_AbstractTokenGenerator);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _possibleConstructorReturn(self,call){if(!self){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return call&&(typeof call==="object"||typeof call==="function")?call:self;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function, not "+typeof superClass);}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass;}var

function ProvidedTokenGenerator(token){_classCallCheck(this,ProvidedTokenGenerator);var _this=_possibleConstructorReturn(this,(ProvidedTokenGenerator.__proto__||Object.getPrototypeOf(ProvidedTokenGenerator)).call(this));
function ProvidedTokenGenerator(token){_classCallCheck(this,ProvidedTokenGenerator);var _this=_possibleConstructorReturn(this,Object.getPrototypeOf(ProvidedTokenGenerator).call(this));
_this._token=token;
_this.canAutogenerateToken=true;return _this;
}_createClass(ProvidedTokenGenerator,[{key:'generateToken',value:function generateToken()
_this.canAutogenerateToken=true;return _this;}_createClass(ProvidedTokenGenerator,[{key:'generateToken',value:function generateToken()
{
return Promise.resolve({
access_token:this._token});
access_token:this._token});}},{key:'refreshToken',value:function refreshToken()
}},{key:'refreshToken',value:function refreshToken()
{
return this.generateToken();
}}]);return ProvidedTokenGenerator;}(_AbstractTokenGenerator2.default);exports.default=
return this.generateToken();}}]);return ProvidedTokenGenerator;}(_AbstractTokenGenerator2.default);exports.default=
ProvidedTokenGenerator;

@@ -7,34 +7,34 @@ Object.defineProperty(exports,"__esModule",{value:true});var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};}();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}var ACCESS_TOKEN_KEY='rest_client_sdk.api.access_token';var

this._hasATokenBeenGenerated=false;
this.setAsyncStorage(asyncStorage);
}_createClass(TokenStorage,[{key:'setAsyncStorage',value:function setAsyncStorage(
this.setAsyncStorage(asyncStorage);}_createClass(TokenStorage,[{key:'setAsyncStorage',value:function setAsyncStorage(
asyncStorage){
this._asyncStorage=asyncStorage;
}},{key:'hasAccessToken',value:function hasAccessToken()
this._asyncStorage=asyncStorage;}},{key:'hasAccessToken',value:function hasAccessToken()
{
return this._asyncStorage.getItem(ACCESS_TOKEN_KEY).
then(function(accessToken){return!!accessToken;});
}},{key:'getAccessToken',value:function getAccessToken()
then(function(accessToken){return!!accessToken;});}},{key:'getAccessToken',value:function getAccessToken()
{var _this=this;
if(!this._hasATokenBeenGenerated&&!this._tokenGenerator.canAutogenerateToken){
throw new Error('No token has been generated yet.');
}
throw new Error('No token has been generated yet.');}
if(!this._hasATokenBeenGenerated&&this._tokenGenerator.canAutogenerateToken){
return this._tokenGenerator.generateToken().
then(function(){return _this._asyncStorage.getItem(ACCESS_TOKEN_KEY);}).
then(function(token){return token&&JSON.parse(token).access_token;});
then(function(token){return token&&JSON.parse(token).access_token;});}
}
return this._asyncStorage.getItem(ACCESS_TOKEN_KEY).
then(function(token){return token&&JSON.parse(token).access_token;});
then(function(token){return token&&JSON.parse(token).access_token;});}},{key:'logout',value:function logout()
}},{key:'logout',value:function logout()
{
return this._asyncStorage.removeItem(ACCESS_TOKEN_KEY);
}},{key:'generateToken',value:function generateToken(
return this._asyncStorage.removeItem(ACCESS_TOKEN_KEY);}},{key:'generateToken',value:function generateToken(
parameters){var _this2=this;

@@ -44,6 +44,6 @@ this._hasATokenBeenGenerated=true;

then(function(responseData){return _this2._storeAccessToken(responseData).
then(function(){return responseData;});});
then(function(){return responseData;});});}},{key:'refreshToken',value:function refreshToken(
}},{key:'refreshToken',value:function refreshToken(
parameters){var _this3=this;

@@ -56,15 +56,15 @@ return this._asyncStorage.getItem(ACCESS_TOKEN_KEY).

_this3._storeAccessToken(responseData).
then(function(){return responseData;}));}));});
then(function(){return responseData;}));}));});}},{key:'_storeAccessToken',value:function _storeAccessToken(
}},{key:'_storeAccessToken',value:function _storeAccessToken(
responseData){
return this._asyncStorage.
setItem(ACCESS_TOKEN_KEY,JSON.stringify(responseData));
setItem(ACCESS_TOKEN_KEY,JSON.stringify(responseData));}}]);return TokenStorage;}();exports.default=
}}]);return TokenStorage;}();exports.default=
TokenStorage;
{
"name": "rest-client-sdk",
"version": "0.5.0",
"version": "0.6.0",
"description": "Rest Client SDK for API",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

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