Skip to content

Commit

Permalink
Release 2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pgom committed Apr 13, 2018
1 parent c1f3623 commit 1490224
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 32 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [v2.1.0](https://github.com/uphold/uphold-sdk-javascript/releases/tag/v2.1.0) (2018-04-13)
- Add ability to pass extra options on each request [\#12](https://github.com/uphold/uphold-sdk-javascript/pull/12) ([pgom](https://github.com/pgom))
- Add entire response object on each request response [\#14](https://github.com/uphold/uphold-sdk-javascript/pull/14) ([pgom](https://github.com/pgom))
- Update build script [\#13](https://github.com/uphold/uphold-sdk-javascript/pull/13) ([pgom](https://github.com/pgom))

## [v2.0.4](https://github.com/uphold/uphold-sdk-javascript/releases/tag/v2.0.4) (2017-11-23)
- Add support to invalid scope error [\#9](https://github.com/uphold/uphold-sdk-javascript/pull/9) ([SandroMachado](https://github.com/SandroMachado))

Expand Down
2 changes: 1 addition & 1 deletion dist/browser/uphold-sdk-javascript.js

Large diffs are not rendered by default.

49 changes: 25 additions & 24 deletions dist/core/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ class SDK {
}

api(uri) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
_ref$authenticate = _ref.authenticate;

let authenticate = _ref$authenticate === undefined ? true : _ref$authenticate,
body = _ref.body;
var _ref$headers = _ref.headers;
let headers = _ref$headers === undefined ? {} : _ref$headers;
var _ref$method = _ref.method;
let method = _ref$method === undefined ? 'get' : _ref$method,
queryParams = _ref.queryParams,
raw = _ref.raw;
var _ref$version = _ref.version;
let version = _ref$version === undefined ? this.options.version : _ref$version;
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var _options$authenticate = options.authenticate;
const authenticate = _options$authenticate === undefined ? true : _options$authenticate;
var _options$headers = options.headers;
const headers = _options$headers === undefined ? {} : _options$headers;
var _options$method = options.method;
const method = _options$method === undefined ? 'get' : _options$method,
queryParams = options.queryParams,
raw = options.raw;
var _options$version = options.version;
const version = _options$version === undefined ? this.options.version : _options$version;
let body = options.body;


const url = (0, _utils.buildUrl)(uri, this.options.baseUrl, version, queryParams);

Expand All @@ -76,15 +76,15 @@ class SDK {

if (authenticate && !headers.authorization) {
request = this.getToken().then(tokens => {
return this.client.request(url, method, body, _extends({}, (0, _utils.buildBearerAuthorizationHeader)(tokens.access_token), headers));
return this.client.request(url, method, body, _extends({}, (0, _utils.buildBearerAuthorizationHeader)(tokens.access_token), headers), options);
});
} else {
request = this.client.request(url, method, body, headers);
request = this.client.request(url, method, body, headers, options);
}

return request.then(data => {
return raw ? data : data.body;
}).catch(this._refreshToken(url, method, body, headers));
}).catch(this._refreshToken(url, method, body, headers, options));
}

authorize(code) {
Expand Down Expand Up @@ -149,18 +149,19 @@ class SDK {
}).then(() => token);
}

_authenticationRequest(_ref2) {
let body = _ref2.body,
headers = _ref2.headers,
url = _ref2.url;
_authenticationRequest(_ref) {
let body = _ref.body,
headers = _ref.headers,
url = _ref.url;

return this.client.request(url, 'post', body, headers).then((_ref3) => {
let body = _ref3.body;
return this.client.request(url, 'post', body, headers).then((_ref2) => {
let body = _ref2.body;
return this.setToken(body);
});
}

_refreshToken(url, method, body, headers) {
_refreshToken(url, method, body, headers, options) {
// eslint-disable-line max-params
return response => {
if (!response || !response.body || response.body.error !== 'invalid_token') {
return Promise.reject(response);
Expand All @@ -171,7 +172,7 @@ class SDK {
}

return this.refreshRequestPromise.then(tokens => {
return this.client.request(url, method, body, _extends({}, (0, _utils.buildBearerAuthorizationHeader)(tokens.access_token), headers)).then(data => data.body);
return this.client.request(url, method, body, _extends({}, (0, _utils.buildBearerAuthorizationHeader)(tokens.access_token), headers), options).then(data => data.body);
});
};
}
Expand Down
9 changes: 6 additions & 3 deletions dist/core/utils/error-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
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; };

exports.createError = createError;

var _errors = require('../errors');
Expand All @@ -11,10 +14,10 @@ var _errors2 = _interopRequireDefault(_errors);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function createError(response) {
function createError(error, response) {
for (const SDKError of _errors2.default) {
if (SDKError.hasError && SDKError.hasError(response)) {
return new SDKError(response);
if (SDKError.hasError && SDKError.hasError(error)) {
return new SDKError(_extends({}, error, { response: response }));
}
}
}
7 changes: 4 additions & 3 deletions dist/node/services/request-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
class RequestClient extends _core.Client {
request(url, method, body) {
let headers = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};

return (0, _requestPromise2.default)({
let options = arguments[4];
// eslint-disable-line max-params
return (0, _requestPromise2.default)(_extends({}, options, {
body: body,
headers: _extends({}, this.defaultHeaders, headers),
method: method,
resolveWithFullResponse: true,
strictSSL: false,
url: url
}).then(response => this._formatResponse(response)).catch(response => Promise.reject(response instanceof _errors.RequestError ? response : (0, _core.createError)(this._formatResponse(response.response))));
})).then(response => this._formatResponse(response)).catch(response => Promise.reject(response instanceof _errors.RequestError ? response : (0, _core.createError)(this._formatResponse(response.response), response)));
}

_formatResponse(_ref) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@uphold/uphold-sdk-javascript",
"version": "2.0.4",
"version": "2.1.0",
"description": "Uphold SDK for JavasScript",
"keywords": [
"api",
Expand Down

0 comments on commit 1490224

Please sign in to comment.