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

rest-client-sdk

Package Overview
Dependencies
Maintainers
3
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 4.0.2 to 4.1.0

12

CHANGELOG.md
# Changelog
## 4.1.1
### Changed
- replace object spread with Object.assign for build to work
## 4.1.0
### Changed
- main AbstractClient CRUD methods accept additional requestParams for overriding fetch params like method, headers, etc.
## 4.0.1

@@ -4,0 +16,0 @@

63

dist/index.es.js

@@ -883,6 +883,7 @@ import diff from 'deep-diff';

var pathParameters = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var requestParams = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
var url = this._generateUrlFromParams(queryParam, pathParameters, id);
return this.deserializeResponse(this.authorizedFetch(url), 'item');
return this.deserializeResponse(this.authorizedFetch(url, requestParams), 'item');
}

@@ -893,6 +894,7 @@ }, {

var pathParameters = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var requestParams = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var url = this._generateUrlFromParams(queryParam, pathParameters);
return this.deserializeResponse(this.authorizedFetch(url), 'list');
return this.deserializeResponse(this.authorizedFetch(url, requestParams), 'list');
}

@@ -904,4 +906,5 @@ }, {

var pathParameters = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var requestParams = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
return this.findBy(queryParam, pathParameters);
return this.findBy(queryParam, pathParameters, requestParams);
}

@@ -913,2 +916,3 @@ }, {

var pathParameters = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var requestParams = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};

@@ -923,6 +927,6 @@ var url = new URI(this.getPathBase(pathParameters));

return this.deserializeResponse(this.authorizedFetch(url, {
return this.deserializeResponse(this.authorizedFetch(url, Object.assign({
method: 'POST',
body: this.serializer.encodeItem(diff$$1, this.metadata)
}), 'item');
}, requestParams)), 'item');
}

@@ -933,2 +937,3 @@ }, {

var queryParam = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var requestParams = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

@@ -947,6 +952,6 @@ var url = new URI(this.getEntityURI(entity));

return this.deserializeResponse(this.authorizedFetch(url, {
return this.deserializeResponse(this.authorizedFetch(url, Object.assign({
method: 'PUT',
body: this.serializer.encodeItem(newSerializedModel, this.metadata)
}), 'item');
}, requestParams)), 'item');
}

@@ -958,8 +963,10 @@ }, {

var requestParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var url = this.getEntityURI(entity);
var identifier = this._getEntityIdentifier(entity);
return this.authorizedFetch(url, {
return this.authorizedFetch(url, Object.assign({
method: 'DELETE'
}).then(function (response) {
}, requestParams)).then(function (response) {
_this.sdk.unitOfWork.clear(identifier);

@@ -1057,6 +1064,8 @@

key: 'authorizedFetch',
value: function authorizedFetch(input, init) {
value: function authorizedFetch(input) {
var requestParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var url = this.makeUri(input);
return this._fetchWithToken(url.toString(), init);
return this._fetchWithToken(url.toString(), requestParams);
}

@@ -1097,5 +1106,7 @@ }, {

key: '_fetchWithToken',
value: function _fetchWithToken(input, init) {
value: function _fetchWithToken(input) {
var _this3 = this;
var requestParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
if (!input) {

@@ -1119,20 +1130,22 @@ throw new Error('input is empty');

}).then(function (token) {
return _this3._doFetch(token, input, init);
return _this3._doFetch(token, input, requestParams);
});
}
return this._doFetch(null, input, init);
return this._doFetch(null, input, requestParams);
}
}, {
key: '_refreshTokenAndRefetch',
value: function _refreshTokenAndRefetch(response, input, init) {
value: function _refreshTokenAndRefetch(response, input) {
var _this4 = this;
var requestParams = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
return this._tokenStorage.refreshToken().then(function () {
var params = Object.assign({}, init, {
headers: Object.assign({}, init.headers)
var updatedRequestParams = Object.assign({}, requestParams, {
headers: Object.assign({}, requestParams.headers)
});
delete params.headers.Authorization;
delete updatedRequestParams.headers.Authorization;
return _this4._fetchWithToken(input, params);
return _this4._fetchWithToken(input, updatedRequestParams);
});

@@ -1142,5 +1155,7 @@ }

key: '_manageUnauthorized',
value: function _manageUnauthorized(response, input, init) {
value: function _manageUnauthorized(response, input) {
var _this5 = this;
var requestParams = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var error = getHttpErrorFromResponse(response);

@@ -1153,3 +1168,3 @@

if (invalidGrant && this._tokenStorage) {
return this._refreshTokenAndRefetch(response, input, init);
return this._refreshTokenAndRefetch(response, input, requestParams);
}

@@ -1162,3 +1177,3 @@

if (_this5._tokenStorage && body.error === 'invalid_grant') {
return _this5._refreshTokenAndRefetch(response, input, init);
return _this5._refreshTokenAndRefetch(response, input, requestParams);
}

@@ -1176,6 +1191,6 @@ throw error;

key: '_doFetch',
value: function _doFetch(accessToken, input, init) {
value: function _doFetch(accessToken, input, requestParams) {
var _this6 = this;
var params = init;
var params = requestParams;

@@ -1182,0 +1197,0 @@ var baseHeaders = {

{
"name": "rest-client-sdk",
"version": "4.0.2",
"version": "4.1.0",
"description": "Rest Client SDK for API",
"main": "dist/index.js",
"module": "dist/index.es.js",
"files": ["dist", "src"],
"files": [
"dist",
"src"
],
"scripts": {

@@ -56,3 +59,7 @@ "clean": "rimraf dist",

},
"keywords": ["Rest", "SDK", "API"],
"keywords": [
"Rest",
"SDK",
"API"
],
"author": "Mapado",

@@ -74,3 +81,6 @@ "license": "MIT",

"lint-staged": {
"*.{js,jsx,json,md}": ["yarn run prettier --write", "git add"]
"*.{js,jsx,json,md}": [
"yarn run prettier --write",
"git add"
]
},

@@ -77,0 +87,0 @@ "jest": {

@@ -37,19 +37,25 @@ import URI from 'urijs';

find(id, queryParam = {}, pathParameters = {}) {
find(id, queryParam = {}, pathParameters = {}, requestParams = {}) {
const url = this._generateUrlFromParams(queryParam, pathParameters, id);
return this.deserializeResponse(this.authorizedFetch(url), 'item');
return this.deserializeResponse(
this.authorizedFetch(url, requestParams),
'item'
);
}
findBy(queryParam, pathParameters = {}) {
findBy(queryParam, pathParameters = {}, requestParams = {}) {
const url = this._generateUrlFromParams(queryParam, pathParameters);
return this.deserializeResponse(this.authorizedFetch(url), 'list');
return this.deserializeResponse(
this.authorizedFetch(url, requestParams),
'list'
);
}
findAll(queryParam = {}, pathParameters = {}) {
return this.findBy(queryParam, pathParameters);
findAll(queryParam = {}, pathParameters = {}, requestParams = {}) {
return this.findBy(queryParam, pathParameters, requestParams);
}
create(entity, queryParam = {}, pathParameters = {}) {
create(entity, queryParam = {}, pathParameters = {}, requestParams = {}) {
const url = new URI(this.getPathBase(pathParameters));

@@ -71,6 +77,12 @@ url.addSearch(queryParam);

return this.deserializeResponse(
this.authorizedFetch(url, {
method: 'POST',
body: this.serializer.encodeItem(diff, this.metadata),
}),
this.authorizedFetch(
url,
Object.assign(
{
method: 'POST',
body: this.serializer.encodeItem(diff, this.metadata),
},
requestParams
)
),
'item'

@@ -80,3 +92,3 @@ );

update(entity, queryParam = {}) {
update(entity, queryParam = {}, requestParams = {}) {
const url = new URI(this.getEntityURI(entity));

@@ -102,6 +114,12 @@ url.addSearch(queryParam);

return this.deserializeResponse(
this.authorizedFetch(url, {
method: 'PUT',
body: this.serializer.encodeItem(newSerializedModel, this.metadata),
}),
this.authorizedFetch(
url,
Object.assign(
{
method: 'PUT',
body: this.serializer.encodeItem(newSerializedModel, this.metadata),
},
requestParams
)
),
'item'

@@ -111,9 +129,15 @@ );

delete(entity) {
delete(entity, requestParams = {}) {
const url = this.getEntityURI(entity);
const identifier = this._getEntityIdentifier(entity);
return this.authorizedFetch(url, {
method: 'DELETE',
}).then(response => {
return this.authorizedFetch(
url,
Object.assign(
{
method: 'DELETE',
},
requestParams
)
).then(response => {
this.sdk.unitOfWork.clear(identifier);

@@ -194,6 +218,6 @@

authorizedFetch(input, init) {
authorizedFetch(input, requestParams = {}) {
const url = this.makeUri(input);
return this._fetchWithToken(url.toString(), init);
return this._fetchWithToken(url.toString(), requestParams);
}

@@ -231,3 +255,3 @@

_fetchWithToken(input, init) {
_fetchWithToken(input, requestParams = {}) {
if (!input) {

@@ -254,20 +278,20 @@ throw new Error('input is empty');

})
.then(token => this._doFetch(token, input, init));
.then(token => this._doFetch(token, input, requestParams));
}
return this._doFetch(null, input, init);
return this._doFetch(null, input, requestParams);
}
_refreshTokenAndRefetch(response, input, init) {
_refreshTokenAndRefetch(response, input, requestParams = {}) {
return this._tokenStorage.refreshToken().then(() => {
const params = Object.assign({}, init, {
headers: Object.assign({}, init.headers),
const updatedRequestParams = Object.assign({}, requestParams, {
headers: Object.assign({}, requestParams.headers),
});
delete params.headers.Authorization;
delete updatedRequestParams.headers.Authorization;
return this._fetchWithToken(input, params);
return this._fetchWithToken(input, updatedRequestParams);
});
}
_manageUnauthorized(response, input, init) {
_manageUnauthorized(response, input, requestParams = {}) {
const error = getHttpErrorFromResponse(response);

@@ -282,3 +306,3 @@

if (invalidGrant && this._tokenStorage) {
return this._refreshTokenAndRefetch(response, input, init);
return this._refreshTokenAndRefetch(response, input, requestParams);
}

@@ -293,7 +317,7 @@

if (this._tokenStorage && body.error === 'invalid_grant') {
return this._refreshTokenAndRefetch(response, input, init);
return this._refreshTokenAndRefetch(response, input, requestParams);
}
throw error;
})
.catch((err) => {
.catch(err => {
if (err instanceof OauthError) {

@@ -307,4 +331,4 @@ throw err;

_doFetch(accessToken, input, init) {
let params = init;
_doFetch(accessToken, input, requestParams) {
let params = requestParams;

@@ -311,0 +335,0 @@ const baseHeaders = {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

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