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 1.2.0 to 1.3.0

123

CHANGELOG.md
# Changelog
## Unreleased
### Changed
## [1.3.0] - 2017-11-29
### Changed
* throw AccessDeniedError only on BadRequestError in PasswordGenerator
refreshToken
## [1.2.0] - 2017-11-10
### Changed
* fix response passed as error message in Errors
* throw AccessDeniedError on any Error in PasswordGenerator refreshToken
* allow to pass scope param in tokenGeneratorConfig
## [1.1.1] - 2017-10-08
### Changed
* upgrade rollup to 0.50.0
* upgrade rollup to 0.50.0
## [1.1.0] - 2017-08-30
### Changed
* Pass on response to serializer
* Upgrade dependencies (rollup 0.49, eslint 4, etc.)
* Add prettier to project
* Pass on response to serializer
* Upgrade dependencies (rollup 0.49, eslint 4, etc.)
* Add prettier to project
## [1.0.5] - 2017-08-30
### Changed
* Fix token loop when token is not valid anymore
* Fix token loop when token is not valid anymore
## [1.0.4] - 2017-07-28
### Changed
* Remove undefined headers
* Remove undefined headers
## [1.0.3] - 2017-07-27
### Changed
* Allow overriding base headers [#24](https://github.com/mapado/rest-client-js-sdk/pull/24)
* Allow overriding base headers
[#24](https://github.com/mapado/rest-client-js-sdk/pull/24)
## [1.0.2] - 2017-07-04

@@ -33,62 +60,93 @@

### Changed
* Rolled back to urijs because domurl use the default node implementation which is not compatible with the stack we use.
The real future solution will be to use Javascript `URL` object but too early and unstable for now
* Rolled back to urijs because domurl use the default node implementation which
is not compatible with the stack we use. The real future solution will be to
use Javascript `URL` object but too early and unstable for now
## [1.0.1] - 2017-07-03 - [YANKED]
### Changed
* Make urijs implementation work again but might be breaking
* Url constructor passed with `noTransform = true` for better perf and avoid potential bugs
* Make urijs implementation work again but might be breaking
* Url constructor passed with `noTransform = true` for better perf and avoid
potential bugs
## [1.0.0] - 2017-07-03 - [YANKED]
### Changed
* Replace [urijs](https://medialize.github.io/URI.js/) dependency by smaller [domurl](https://github.com/Mikhus/domurl)
* Replace [urijs](https://medialize.github.io/URI.js/) dependency by smaller
[domurl](https://github.com/Mikhus/domurl)
## [0.15.0] - 2017-06-27
### Added
* Added the current URI as referer for http calls
* Added the current URI as referer for http calls
## [0.14.x]
### breaking changes
Error responses in PasswordGenerator and ClientCredentialsGenerator now throw proper js errors instead of returning the response in the promise rejection
Error responses in PasswordGenerator and ClientCredentialsGenerator now throw
proper js errors instead of returning the response in the promise rejection
## [0.13.x]
### breaking changes
The library does not depends on `immutablejs` anymore, so we needed to make a few breaking changes:
The library does not depends on `immutablejs` anymore, so we needed to make a
few breaking changes:
* Do not depend on `@id` anymore: The `AbstractClient` need to implements a `getEntityURI(entity)` and return an query string from it. This is not a great pattern, but it will do for now. (https://github.com/mapado/rest-client-js-sdk/pull/19)
* The `entityFactory` does not exists anymore. It has been replaced by a `Serializer`: (https://github.com/mapado/rest-client-js-sdk/pull/21)
* If you used the default entityFactory, you will now receive plain Javascript objects instead of immutable's Map or List
* If you previously overrided the `entityFactory`, you will need to switch to the new `Serializer` object: It is much more extensible but is a bit more complex to extend. See README to know how to do it.
* the `createEntityFromJsonResponse` method has been renamed to `deserializeResponse`
* The library moved from ES5 to bundling with rollupjs, that should not break anything and should improve size of bundle but I am not so sure of this, so patch may follow (https://github.com/mapado/rest-client-js-sdk/pull/20)
* Do not depend on `@id` anymore: The `AbstractClient` need to implements a
`getEntityURI(entity)` and return an query string from it. This is not a great
pattern, but it will do for now.
(https://github.com/mapado/rest-client-js-sdk/pull/19)
* The `entityFactory` does not exists anymore. It has been replaced by a
`Serializer`: (https://github.com/mapado/rest-client-js-sdk/pull/21)
* If you used the default entityFactory, you will now receive plain Javascript
objects instead of immutable's Map or List
* If you previously overrided the `entityFactory`, you will need to switch to
the new `Serializer` object: It is much more extensible but is a bit more
complex to extend. See README to know how to do it.
* the `createEntityFromJsonResponse` method has been renamed to
`deserializeResponse`
* The library moved from ES5 to bundling with rollupjs, that should not break
anything and should improve size of bundle but I am not so sure of this, so
patch may follow (https://github.com/mapado/rest-client-js-sdk/pull/20)
## [0.12.x]
## [0.12.x]
### breaking changes
- a `delete` does not call `createEntityFromJsonResponse` anymore as it should return a "204 No Content" or a "404 Not Found"
* a `delete` does not call `createEntityFromJsonResponse` anymore as it should
return a "204 No Content" or a "404 Not Found"
## [0.11.x]
## [0.11.x]
### breaking changes
- `ProviderTokenGenerator` does not accept a param object anymore on its second argument.
* `ProviderTokenGenerator` does not accept a param object anymore on its second
argument.
### new features
- `ProviderTokenGenerator` now accept a function on its second argument which will be called on `refreshToken`, so you can fully customize the behavior. The function must return a Promise.
* `ProviderTokenGenerator` now accept a function on its second argument which
will be called on `refreshToken`, so you can fully customize the behavior. The
function must return a Promise.
## [0.9.x]
### breaking changes
- if the response status is 4xx or 5xx: an error is thrown [#13](https://github.com/mapado/rest-client-js-sdk/pull/13)
* if the response status is 4xx or 5xx: an error is thrown
[#13](https://github.com/mapado/rest-client-js-sdk/pull/13)
### new features
- memoize token generation and refresh [#12](https://github.com/mapado/rest-client-js-sdk/pull/12)
* memoize token generation and refresh
[#12](https://github.com/mapado/rest-client-js-sdk/pull/12)
## [0.6.x]
## [0.6.x]
### breaking changes

@@ -98,8 +156,9 @@

- `findAll(queryParam = {}, pathParameters = {})`
- `create(entity, queryParam = {}, pathParameters = {})`
* `findAll(queryParam = {}, pathParameters = {})`
* `create(entity, queryParam = {}, pathParameters = {})`
### new features
The `queryParam` argument was added where needed in the AbstractClient class:
- `update(entity, queryParam = {})`
* `update(entity, queryParam = {})`
{
"name": "rest-client-sdk",
"version": "1.2.0",
"version": "1.3.0",
"description": "Rest Client SDK for API",

@@ -11,3 +11,3 @@ "main": "dist/index.js",

"test":
"mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive",
"mocha --require babel-core/register --require ./test/test_helper.js --recursive",
"test:watch": "npm run test -- --watch",

@@ -20,3 +20,3 @@ "build": "rollup -c",

"dependencies": {
"urijs": "^1.18.1"
"urijs": "^1.19.0"
},

@@ -27,23 +27,23 @@ "devDependencies": {

"babel-plugin-external-helpers": "^6.22.0",
"babel-preset-env": "^1.6.0",
"bundlesize": "^0.14.2",
"chai": "^3.5.0",
"chai-as-promised": "^5.3.0",
"eslint": "^4.5.0",
"eslint-config-airbnb": "^15.1.0",
"eslint-config-prettier": "^2.3.0",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-jsx-a11y": "^5.1.1",
"eslint-plugin-prettier": "^2.2.0",
"eslint-plugin-react": "^7.3.0",
"fetch-mock": "^4.6.0",
"babel-preset-env": "^1.6.1",
"bundlesize": "^0.15.3",
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"eslint": "^4.11.0",
"eslint-config-airbnb": "^16.1.0",
"eslint-config-prettier": "^2.7.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-jsx-a11y": "^6.0.2",
"eslint-plugin-prettier": "^2.3.1",
"eslint-plugin-react": "^7.4.0",
"fetch-mock": "^5.13.1",
"form-data": "^2.1.2",
"husky": "^0.14.3",
"lint-staged": "^4.0.4",
"mocha": "^3.2.0",
"prettier": "^1.6.1",
"rimraf": "^2.5.4",
"rollup": "^0.50.0",
"lint-staged": "^5.0.0",
"mocha": "^4.0.1",
"prettier": "^1.8.2",
"rimraf": "^2.6.2",
"rollup": "^0.52.0",
"rollup-plugin-babel": "^3.0.2",
"rollup-plugin-commonjs": "^8.0.2",
"rollup-plugin-commonjs": "^8.2.6",
"rollup-plugin-node-resolve": "^3.0.0"

@@ -68,8 +68,8 @@ },

"path": "./dist/index.es.js",
"threshold": "31 Kb"
"maxSize": "31 Kb"
}
],
"lint-staged": {
"*.{js,jsx,json}": ["prettier --write", "git add"]
"*.{js,jsx,json,md}": ["prettier --write", "git add"]
}
}

@@ -1,9 +0,11 @@

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)
=================
# 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) [![Greenkeeper badge](https://badges.greenkeeper.io/mapado/rest-client-js-sdk.svg)](https://greenkeeper.io/)
Rest client SDK for API for Javascript usage.
This client tries to avoid the complexity of implementing a custom SDK for every API you have. You just have to implements your model and a little configuration and it will hide the complexity for you.
This client tries to avoid the complexity of implementing a custom SDK for every
API you have. You just have to implements your model and a little configuration
and it will hide the complexity for you.
## Installation
`npm install rest-client-sdk`

@@ -14,2 +16,3 @@

### Declare your clients
```js

@@ -24,7 +27,7 @@ import { AbstractClient } from 'rest-client-sdk';

getEntityURI(entity) {
return `${this.getPathBase}/${entity.id}`; // this will be the URI used by update / delete script
return `${this.getPathBase}/${entity.id}`; // this will be the URI used by update / delete script
}
getName() {
return 'SomeEntity'; // this will be passed to the serializer
return 'SomeEntity'; // this will be passed to the serializer
}

@@ -37,3 +40,5 @@ }

### Create the SDK
#### Create the token storage
```js

@@ -47,10 +52,16 @@ import { TokenStorage } from 'rest-client-sdk';

```
The token generator is a class implementing `generateToken` and `refreshToken`.
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.
The storage needs to be a class implementing `setItem(key, value)`,
`getItem(key)` and `removeItem(key)`. Those functions must return a promise.
At Mapado we use [localforage](http://mozilla.github.io/localForage/) in a browser environment and [React Native AsyncStorage](https://facebook.github.io/react-native/docs/asyncstorage.html) for React Native.
At Mapado we use [localforage](http://mozilla.github.io/localForage/) in a
browser environment and
[React Native AsyncStorage](https://facebook.github.io/react-native/docs/asyncstorage.html)
for React Native.
#### Configure the SDK
```js

@@ -60,13 +71,13 @@ import RestClientSdk from 'rest-client-sdk';

const config = {
path: 'api.me',
scheme: 'https',
port: 443,
segment: '/my-api',
authorizationType: 'Bearer', // default to "Bearer", but can be "Basic" or anything
useDefaultParameters: true,
path: 'api.me',
scheme: 'https',
port: 443,
segment: '/my-api',
authorizationType: 'Bearer', // default to "Bearer", but can be "Basic" or anything
useDefaultParameters: true,
}; // path and scheme are mandatory
const clients = {
someEntity: SomeEntityClient,
// ...
someEntity: SomeEntityClient,
// ...
};

@@ -78,4 +89,7 @@

### Make calls
#### Find
You can now call the clients this way:
You can now call the clients this way:
```js

@@ -90,2 +104,3 @@ sdk.someEntity.find(8); // will find the entity with id 8. ie. /v2/some_entities/8

#### Update / delete
```js

@@ -98,14 +113,19 @@ sdk.someEntity.update(entity);

### Custom serializer
You can inject a custom serializer to the SDK.
The serializer must extends the base `Serializer` class and implement 3 methods:
* `deserializeItem(rawData, type)` (type is the result of `getName`)
* `deserializeList(rawListData, type)` (type is the result of `getName`)
* `serializeItem(item, type)` (type is the result of `getName`)
All text response from GET / PUT / POST request will be send to `deserializeItem` or `deserializeList`.
All content fom `update` and `create` call will be send to `serializeItem`.
You can inject a custom serializer to the SDK. The serializer must extends the
base `Serializer` class and implement 3 methods:
The default serializer uses `JSON.parse` and `JSON.stringify`, so it converts string to JSON objects.
* `deserializeItem(rawData, type)` (type is the result of `getName`)
* `deserializeList(rawListData, type)` (type is the result of `getName`)
* `serializeItem(item, type)` (type is the result of `getName`)
All text response from GET / PUT / POST request will be send to
`deserializeItem` or `deserializeList`. All content fom `update` and `create`
call will be send to `serializeItem`.
The default serializer uses `JSON.parse` and `JSON.stringify`, so it converts
string to JSON objects.
#### Example with the default serializer
```js

@@ -125,3 +145,2 @@ import { Serializer } from 'rest-client-sdk';

serializeItem(entity, type) {

@@ -128,0 +147,0 @@ // prepare item for being sent in a request

@@ -6,3 +6,3 @@ /* global fetch */

import { memoizePromise } from '../decorator';
import { AccessDeniedError, handleBadResponse, HttpError } from '../Error';
import { AccessDeniedError, handleBadResponse, BadRequestError } from '../Error';

@@ -61,3 +61,3 @@ const ERROR_CONFIG_EMPTY = 'TokenGenerator config must be set';

.catch(err => {
if (err instanceof HttpError) {
if (err instanceof BadRequestError) {
throw new AccessDeniedError(null, err.baseResponse);

@@ -64,0 +64,0 @@ }

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

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