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.1.2 to 0.2.0

dist/TokenGenerator/AbstractTokenGenerator.js

12

dist/client/AbstractClient.js

@@ -7,3 +7,3 @@ 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.sdk=sdk;
this._oauthClient=sdk.oauthClient;
this._tokenStorage=sdk.tokenStorage;

@@ -80,3 +80,3 @@ this.entityFactory=sdk.entityFactory;}_createClass(AbstractClient,[{key:'getDefaultParameters',value:function getDefaultParameters()

then(function(response){return response.json();}).
then(function(val){return _this.entityFactory(val,listOrItem,_this.getName());});}},{key:'makeTicketingUri',value:function makeTicketingUri(
then(function(val){return _this.entityFactory(val,listOrItem,_this.getName());});}},{key:'makeUri',value:function makeUri(

@@ -99,3 +99,3 @@

input,init){
var url=this.makeTicketingUri(input);
var url=this.makeUri(input);

@@ -124,3 +124,3 @@ return this._doFetch(url.toString(),init);}},{key:'_generateUrlFromParams',value:function _generateUrlFromParams(

return this._oauthClient.getAccessToken().
return this._tokenStorage.getAccessToken().
then(function(token){return _this2._fetchWithToken(token,input,init);});}},{key:'_manageAccessDenied',value:function _manageAccessDenied(

@@ -136,4 +136,4 @@

case'The access token provided has expired.':
if(_this3._oauthClient){
return _this3._oauthClient.refreshToken().
if(_this3._tokenStorage){
return _this3._tokenStorage.refreshToken().
then(function(){return _this3._doFetch(input,init);}).

@@ -140,0 +140,0 @@ catch(function(){

@@ -1,10 +0,16 @@

Object.defineProperty(exports,"__esModule",{value:true});exports.AbstractClient=exports.AccessDeniedError=exports.OauthClient=undefined;var _RestClientSdk=require('./RestClientSdk');var _RestClientSdk2=_interopRequireDefault(_RestClientSdk);
Object.defineProperty(exports,"__esModule",{value:true});exports.TokenStorage=exports.PasswordGenerator=exports.ClientCredentialsGenerator=exports.AbstractTokenGenerator=exports.AccessDeniedError=exports.AbstractClient=undefined;var _RestClientSdk=require('./RestClientSdk');var _RestClientSdk2=_interopRequireDefault(_RestClientSdk);
var _Error=require('./Error');
var _AbstractClient=require('./client/AbstractClient');var _AbstractClient2=_interopRequireDefault(_AbstractClient);
var _OauthClient=require('./OauthClient');var _OauthClient2=_interopRequireDefault(_OauthClient);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}exports.default=_RestClientSdk2.default;exports.
var _TokenStorage=require('./TokenStorage');var _TokenStorage2=_interopRequireDefault(_TokenStorage);
var _AbstractTokenGenerator=require('./TokenGenerator/AbstractTokenGenerator');var _AbstractTokenGenerator2=_interopRequireDefault(_AbstractTokenGenerator);
var _ClientCredentialsGenerator=require('./TokenGenerator/ClientCredentialsGenerator');var _ClientCredentialsGenerator2=_interopRequireDefault(_ClientCredentialsGenerator);
var _PasswordGenerator=require('./TokenGenerator/PasswordGenerator');var _PasswordGenerator2=_interopRequireDefault(_PasswordGenerator);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}exports.default=_RestClientSdk2.default;exports.
OauthClient=_OauthClient2.default;exports.
AbstractClient=_AbstractClient2.default;exports.
AccessDeniedError=_Error.AccessDeniedError;exports.
AbstractClient=_AbstractClient2.default;
AbstractTokenGenerator=_AbstractTokenGenerator2.default;exports.
ClientCredentialsGenerator=_ClientCredentialsGenerator2.default;exports.
PasswordGenerator=_PasswordGenerator2.default;exports.
TokenStorage=_TokenStorage2.default;

@@ -8,7 +8,7 @@ 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");}}

RestClientSdk=function(){
function RestClientSdk(oauthClient,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);
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);
this._checkConfigValidity(config);
this.config=this._mergeWithBaseConfig(config);
this.oauthClient=oauthClient;
this.tokenStorage=tokenStorage;
this.entityFactory=entityFactory;

@@ -15,0 +15,0 @@

{
"name": "rest-client-sdk",
"version": "0.1.2",
"version": "0.2.0",
"description": "Rest Client SDK for API",

@@ -28,2 +28,4 @@ "main": "dist/index.js",

"eslint-plugin-import": "^1.9.2",
"eslint-plugin-jsx-a11y": "^1.5.5",
"eslint-plugin-react": "^5.2.2",
"fetch-mock": "^4.6.0",

@@ -30,0 +32,0 @@ "form-data": "^1.0.0-rc4",

@@ -31,9 +31,12 @@ Mapado Rest Client JS SDK [![Build Status](https://travis-ci.org/mapado/rest-client-js-sdk.svg?branch=master)](https://travis-ci.org/mapado/rest-client-js-sdk)

```js
import { OauthClient } from 'rest-client-sdk';
import { TokenStorage } from 'rest-client-sdk';
const tokenGeneratorConfig = { path: 'oauth.me', foo: 'bar' }
const tokenGenerator = new SomeTokenGenerator(tokenGeneratorConfig); // Some token generators are defined in `src/TokenGenerator/`
const storage = AsyncStorage; // create a storage instance if you are not on RN. In browser and node, localforage works fine
const clientId = 'myClientId';
const clientSecret = 'myClientSecret';
const oauthClient = new OauthClient({ path: 'oauth.me', scheme: 'https' }, clientId, clientSecret, storage);
const tokenStorage = new TokenStorage(tokenGenerator, asyncStorage);
```
The token generator is a class implementing `generateToken` and `refreshToken`.
Those methods must return an array containing an `access_token` key.
The storage needs to be a class implementing `setItem(key, value)`, `getItem(key)` and `removeItem(key)`. Those functions must return a promise.

@@ -58,3 +61,3 @@

const sdk = new RestClientSdk(oauthClient, config, clients);
const sdk = new RestClientSdk(tokenStorage, config, clients);
```

@@ -89,3 +92,3 @@

const sdk = new RestClientSdk(oauthClient, config, clients, entityFactory);
const sdk = new RestClientSdk(tokenStorage, config, clients, entityFactory);
```
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