rest-client-sdk
Advanced tools
Comparing version 0.10.0 to 0.11.0
@@ -9,6 +9,2 @@ 'use strict'; | ||
var _urijs = require('urijs'); | ||
var _urijs2 = _interopRequireDefault(_urijs); | ||
var _AbstractTokenGenerator = require('./AbstractTokenGenerator'); | ||
@@ -31,3 +27,3 @@ | ||
function ProvidedTokenGenerator(token) { | ||
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var refreshTokenFunc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
@@ -40,3 +36,3 @@ _classCallCheck(this, ProvidedTokenGenerator); | ||
_this.canAutogenerateToken = true; | ||
_this._params = params; | ||
_this._refreshTokenFunc = refreshTokenFunc; | ||
return _this; | ||
@@ -55,18 +51,4 @@ } | ||
value: function refreshToken() { | ||
if (this._params && this._params.refreshTokenUrl) { | ||
var uri = new _urijs2.default(this._params.refreshTokenUrl); | ||
var url = uri.toString(); | ||
return fetch(url, { | ||
method: 'POST' | ||
}).then(function (response) { | ||
if (response.status !== 200) { | ||
return response.json().then(function (responseData) { | ||
return Promise.reject(responseData); | ||
}); | ||
} | ||
return response.json(); | ||
}); | ||
if (typeof this._refreshTokenFunc === 'function') { | ||
return this._refreshTokenFunc(); | ||
} | ||
@@ -73,0 +55,0 @@ |
{ | ||
"name": "rest-client-sdk", | ||
"version": "0.10.0", | ||
"version": "0.11.0", | ||
"description": "Rest Client SDK for API", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
/* global fetch */ | ||
import URI from 'urijs'; | ||
import AbstractTokenGenerator from './AbstractTokenGenerator'; | ||
@@ -7,7 +6,7 @@ | ||
constructor(token, params = {}) { | ||
constructor(token, refreshTokenFunc = null) { | ||
super(); | ||
this._token = token; | ||
this.canAutogenerateToken = true; | ||
this._params = params; | ||
this._refreshTokenFunc = refreshTokenFunc; | ||
} | ||
@@ -22,19 +21,4 @@ | ||
refreshToken() { | ||
if (this._params && this._params.refreshTokenUrl) { | ||
const uri = new URI(this._params.refreshTokenUrl); | ||
const url = uri.toString(); | ||
return fetch(url, { | ||
method: 'POST', | ||
}) | ||
.then((response) => { | ||
if (response.status !== 200) { | ||
return response.json() | ||
.then(responseData => Promise.reject(responseData)); | ||
} | ||
return response.json(); | ||
}) | ||
; | ||
if (typeof this._refreshTokenFunc === 'function') { | ||
return this._refreshTokenFunc(); | ||
} | ||
@@ -41,0 +25,0 @@ |
6
61903
1313