- Fix handling refresh token failure
- Add a
onRefreshTokenFailure
method to sdk config when refresh token triggers a 401 error. #143
- [Minor BC] Handle error that should trigger a refresh token #142
- use default export for deep-diff as named export may be buggy
- Migrate to type module #141 by @jdeniau (It should have been released in the 7.0.0 as it might be breaking, but I do not want to push a new major two just some days after the last one as this package is not widely used)
-
[Breaking] If unitOfWork is disabled in the global configuration, then it will be disabled for all call to getRepository. #111. Waiting to resolve issue with
create
andupdate
to bump7.0.0
version. -
Start implementing a logger. You need to enable it with
config.loggerEnabled
if you want to log request:
A possible interesting configuration is to activate the logger on dev environment.
const sdk = new TicketingSdk(tokenStorage, {
path: process.env.API_DOMAIN,
scheme: 'https',
loggerEnabled: process.env.NODE_ENV === 'development',
});
- Add Logger in RestClientSdkInterface
- Add a helper to get JSON of an HttpError #122
- Fixed makeUri method to handle more than one URI segment #128
- Call toString on URLSearchParams body to ensure ReactNative compatibility #130
- Remove referer as it is handled by the browser #135 by @jdeniau
- Fix issue in handling 401 error with anything else than "invalid_grant" #137 by @jdeniau
- allow calling create, update, delete with a disabled unitOfWork #140 by @jdeniau
Remove referer as it is handled by the browser #135 by @jdeniau
Call toString on URLSearchParams body to ensure ReactNative compatibility #130
Fixed makeUri method to handle more than one URI segment #128
Add a helper to get JSON of an HttpError #122
Add Logger in RestClientSdkInterface
Fix issue with private logger in handleTokenResponse
- Start implementing a logger. You need to enable it with
config.loggerEnabled
if you want to log request:
A possible interesting configuration is to activate the logger on dev environment.
const sdk = new TicketingSdk(tokenStorage, {
path: process.env.API_DOMAIN,
scheme: 'https',
loggerEnabled: process.env.NODE_ENV === 'development',
});
- [Breaking] If unitOfWork is disabled in the global configuration, then it will be disabled for all call to getRepository. #111. Waiting to resolve issue with
create
andupdate
to bump7.0.0
version.
Fix issue with response body already consumed when an error occured while generating token
Do not use async / await to avoid regeneratorRuntime issue
- Add Authorization code flow token generator
- Better compatibility with the oauth spec: https://tools.ietf.org/html/rfc6749
- handle oauth error even if the TokenGenerator does not extends
AbstractTokenGenator
or call_manageOauthError
- [Minor BC]
TokenGenerator.generateToken
andTokenGenerator.generateToken
might return aResponse
instead of a plain object. This should not break anything as the response is handled by theTokenStorage
unless you call directly theTokenGenerator
(which you should not). Returning an object has been deprecated and is only used in theProvidedTokenGenerator
(which is also deprecated) - [Minor BC]
OauthError.previousError
might be undefined - [Deprecation] Deprecate
ProvidedTokenGenerator
. You should use one of the oauth2 generator or implement your own custom generator. - [Deprecation] Calling
AbstractTokenGenerator._manageOauthError
is deprecated. You should return theResponse
instead :
generateToken() {
const body = // … generate body
return fetch(url, {
method: 'POST',
body,
+ });
- }).then((response) => {
- if (response.status < 400) {
- return response;
- }
- return this._manageOauthError(response);
- });
}
Fix regression from 6.5.1
: TokenStorage.refreshToken
does now throws an Error anymore if there is no token stored in the storage.
- getItem from AsyncStorage interface might return null
TokenStorage.refreshToken
now throws an Error if there is no token stored in the storage.
Accept Relation.ONE_TO_ONE relation. It is basically handled the same way as MANY_TO_ONE, but has been added for semantic purpose. The comportment may differ later.
- withUnitOfWork returns a clone of the base repository to avoid race condition on
isUnitOfWorkEnabled
- allow unitOfWork deactivation on find* calls
Accept Relation.MANY_TO_MANY relation. It is basically handled the same way as ONE_TO_MANY, but has been added for semantic purpose. The comportment may differ later.
- [TypeScript] better handle deserializeResponse method definition
Export MetadataDefinition
for AbstractClient inheritance
- [BREAKING] UnitOfWork is disabled by default, one must add a prop
unitOfWorkEnabled
with value true to the config object passed to the RestClientSdk's constructor in order to enable it - TokenStorage's
generateToken
andrefreshToken
methods are now memoized in order to avoid bugs when making concurrent calls
This release is a migration to TypeScript, but the API stay the same. The only breaking changes are more fixed bugs that might be breaking in really improbable case.
-
[BREAKING] TokenGenerator's
refreshToken
method signature changed fromrefreshToken(accessToken, parameters)
torefreshToken(accessToken)
. If you did extend theAbstractToken
generator, you shouldn't relly on the second parameter. As a matter of fact, the auto-refreshed token inAbstractClient
did not send any parameters either, so it should not have been working before ! Accordingly TherefreshToken
method ofTokenStorage
signature changed fromrefreshToken(parameters)
torefreshToken()
-
[Might Break] all pseudo-private methods and attributes (starting with
_
) are unavailable and are now really private (or protected)._storeAccessToken
should be replace by aProvidedTokenGenerator
-
[Might Break]
ClassMetadata
,Attribute
andRelation
attributes are nowreadonly
. You can not change them after initialization. -
[Might Break]
AbstractTokenGenerator
is now abstract. It should not have been used directly anyway. It implies that the method that previously did thrown errors are not callable (generateToken
,refreshToken
andcheckTokenGeneratorConfig
). They should not have been called. They don't exist in JS land anymore. -
[Might Break]
canAutogenerateToken
has been removed from the token storages and replaced by aautogenerateToken()
method (it's not real POO, but I did not manage to deal with instance of for now) -
[Might Break] AbstractClient._refreshTokenAndRefetch does not take the response as a first argument (it wan unused). The method was supposed to be private be the way.
-
Make
SerializerInterace
andSerializer
input and output understandable
- export (and implement)
RestClientSdkInterface
andTokenStorageInterface
- export
TokenGeneratorInterface
andAsyncStorageInterface
- Passing a string as argument to
ProvidedTokenGenerator
is now deprecated. You should pass the token object instead. It should have had a weird comportment before by the way.
- Fix issue when two token generation are send on the same time : the second one will not throw an error now.
- Fix issue when no token is provided but the object is
{ expires_at: null }
- Fix issue with urijs 1.19.2
- replace object spread with Object.assign for build to work
- main AbstractClient CRUD methods accept additional requestParams for overriding fetch params like method, headers, etc.
- downgraded jest and babel-jest to ^23.6.0 in order to fix tests
- Do not generate token expires_at in _storeAccessToken since it is sometimes used from outside, in tests for instance (even though it is supposed to be private)
- [Breaking] throw new error types when oauth calls fail, they all wrap the originalError => InvalidGrantError, InvalidScopeError which both extend OauthError. Original error can be found at error.previousError. If it was an HttpError the response is at error.previousError.baseResponse
- Refactor error handling with error factory and handle 400's in refreshToken of PasswordGenerator
- Pre-emptively refresh the access token if it is close to expiration before doing any request
- Read json response in _manageUnauthorized when www-authenticate header is not available
- Store a new key
expires_at
in the access token (which is accessible withTokenStorage.getAccessTokenObject
) to have the timestamp after which the access token will be invalid, based on theexpires_in
- Add
TokenStorage.getCurrentTokenExpiresIn
function to known how many seconds are remaining for the access token currently stored
- [Breaking]
AccessDeniedError
is nowUnauthorizedError
- [Breaking] Default error is now
HttpError
- Add
ConflictError
to react to 409
TokenStorage
add possibility to pass access_token async storage key as constructor paramAbstractClient._manageAccessDenied
checks headers instead of json to ensure refreshing the token is required
TokenStorage.getAccessTokenObject()
returns an object and null if the stored token is not an object- [Might Break]
TokenStorage.getAccessTokenObject()
does not returnundefined
anymore butnull
if no token object is found
- Add possibility to pass null as tokenStorage argument of the sdk
- switch method names _doFetch and _fetchWithToken in AbstractClient for coherence
- Add method getAccessTokenObject to TokenStorage
- Better packaging system #48
- [Might break] Custom serializer can:
serializeItem
has been splitted intonormalizeItem
+encodeItem
deserializeItem
has been splitted intodenormalizeItem
+decodeItem
deserializeList
has been splitted intodenormalizeList
+decodeList
You must implement them if you have a custom serialization that do not use plain javascript objects.
- [Breaking] Calling
restClientSdk.foo.xxx
is deprecated, you must now callrestClientSdk.getRepository('foo').xxx
- [Breaking] RestClientSdk now takes a Mapping instance instead of a clientList. This instance is required
- [Breaking]
getName
has been removed and replaced by the classmetadata key. Its return was previously sent to the serializer, it's now the mapping that is sent now. Beware that now, thekey
is now used both to call the repository name, and passed to the serializer Before:
class SomeClient extends AbstractClient {
getName() {
return 'SomeClient';
}
}
new RestClientSdk(
// ...
{
foo: SomeClient,
}
);
Now:
const metadata = new ClassMetadata('foo', 'some_endpoint');
mapping = new Mapping();
mapping.setMapping([ metadata ]);
const sdk = new RestClientSdk(/* ... */, mapping); // `foo` will be used in serializer too
sdk.foo.find();
- [Breaking] Custom Serializer: If you had a Collection entity containing the result of you entities, you will need to implement the iterable protocol on this object, this way, we can register all entities in the unit of work.
- Dropped support for node 6
- AbstractClient does not need to specify
getPathBase
anymore: this is generated via the classmetata. You can still override it. getEntityURI
is not mandatory anymore. it will be autogenerate by the AbstractClient. You can still override it- There is no need to create an empty client extending
AbstractClient
now, the default will beAbstractClient
- config
prefix
is not used anymore, you should specify your prefix in the mapping:new Mapping('/v1')
Check relations in isValidMapping
Fix issue when setting a ManyToOne relatossue when setting a ManyToOne relation to null
n to null
add a function to test mapping validity
deserialize + normalize item in unitofwork
creating or updating an "complex" entity (not a basic JS object) would throw an error
remove async
method (that already returned a Promise object)
Fix issue when posting a ManyToOne relation with only the id as string
Fix bug in delete call (not returning the response)
Fix bug in serializer
Fix issue with list denormalized oo objects
Cleaner relations, matches the Arguments attributes
ONE_TO_MANY
andMANY_TO_ONE
constant are now exported via theRelation.ONE_TO_MANY
andRelation.MANY_TO_ONE
, not in the main package
See release note for 2.0.0
- fix simultaneous refresh token throwing error when trying to access to response body twice
- add error message to AccessDeniedError in PasswordGenerator's refreshToken
- throw AccessDeniedError only on BadRequestError in PasswordGenerator refreshToken
- fix response passed as error message in Errors
- throw AccessDeniedError on any Error in PasswordGenerator refreshToken
- allow to pass scope param in tokenGeneratorConfig
- upgrade rollup to 0.50.0
- Pass on response to serializer
- Upgrade dependencies (rollup 0.49, eslint 4, etc.)
- Add prettier to project
- Fix token loop when token is not valid anymore
- Remove undefined headers
- Allow overriding base headers #24
This release is the same as 0.15.0 and though fully compatible
- 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
- Make urijs implementation work again but might be breaking
- Url constructor passed with
noTransform = true
for better perf and avoid potential bugs
- Added the current URI as referer for http calls
Error responses in PasswordGenerator and ClientCredentialsGenerator now throw proper js errors instead of returning the response in the promise rejection
The library does not depends on immutablejs
anymore, so we needed to make a
few breaking changes:
- Do not depend on
@id
anymore: TheAbstractClient
need to implements agetEntityURI(entity)
and return an query string from it. This is not a great pattern, but it will do for now. (#19) - The
entityFactory
does not exists anymore. It has been replaced by aSerializer
: (#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 newSerializer
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 todeserializeResponse
- 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 (#20)
- a
delete
does not callcreateEntityFromJsonResponse
anymore as it should return a "204 No Content" or a "404 Not Found"
ProviderTokenGenerator
does not accept a param object anymore on its second argument.
ProviderTokenGenerator
now accept a function on its second argument which will be called onrefreshToken
, so you can fully customize the behavior. The function must return a Promise.
- if the response status is 4xx or 5xx: an error is thrown #13
- memoize token generation and refresh #12
The queryParam
argument was added where needed in the AbstractClient class:
findAll(queryParam = {}, pathParameters = {})
create(entity, queryParam = {}, pathParameters = {})
The queryParam
argument was added where needed in the AbstractClient class:
update(entity, queryParam = {})