rest-client-sdk 6.6.2 → 6.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,6 +6,10 @@ import { ErrorBody, Token, TokenBody } from './TokenGenerator/types';
6
6
  declare class HttpError extends Error {
7
7
  baseResponse: Response;
8
8
  constructor(message: null | string, baseResponse: Response);
9
+ /**
10
+ * Get the JSON of the baseResponse directly, if possible
11
+ */
12
+ responseJson(): Promise<Record<string, unknown>>;
9
13
  }
10
14
  declare class OauthError extends Error {
11
15
  previousError: HttpError | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rest-client-sdk",
3
- "version": "6.6.2",
3
+ "version": "6.7.0",
4
4
  "description": "Rest Client SDK for API",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.es.js",
@@ -23,6 +23,13 @@ class HttpError extends Error {
23
23
  this.name = 'HttpError';
24
24
  this.baseResponse = baseResponse;
25
25
  }
26
+
27
+ /**
28
+ * Get the JSON of the baseResponse directly, if possible
29
+ */
30
+ public async responseJson(): Promise<Record<string, unknown>> {
31
+ return this.baseResponse.json();
32
+ }
26
33
  }
27
34
 
28
35
  class OauthError extends Error {
package/CHANGELOG.md DELETED
@@ -1,507 +0,0 @@
1
- # Changelog
2
-
3
- ## 6.6.2
4
-
5
- Fix issue with response body already consumed when an error occured while generating token
6
-
7
- ## 6.6.1
8
-
9
- Do not use async / await to avoid regeneratorRuntime issue
10
-
11
- ## 6.6.0
12
-
13
- - Add Authorization code flow token generator
14
- - Better compatibility with the oauth spec: https://tools.ietf.org/html/rfc6749
15
- - handle oauth error even if the TokenGenerator does not extends `AbstractTokenGenator` or call `_manageOauthError`
16
- - [Minor BC] `TokenGenerator.generateToken` and `TokenGenerator.generateToken` might return a `Response` instead of a plain object. This should not break anything as the response is handled by the `TokenStorage` unless you call directly the `TokenGenerator` (which you should not). Returning an object has been deprecated and is only used in the `ProvidedTokenGenerator` (which is also deprecated)
17
- - [Minor BC] `OauthError.previousError` might be undefined
18
- - [Deprecation] Deprecate `ProvidedTokenGenerator`. You should use one of the oauth2 generator or implement your own custom generator.
19
- - [Deprecation] Calling `AbstractTokenGenerator._manageOauthError` is deprecated. You should return the `Response` instead :
20
-
21
- ```diff
22
- generateToken() {
23
- const body = // … generate body
24
-
25
- return fetch(url, {
26
- method: 'POST',
27
- body,
28
- + });
29
- - }).then((response) => {
30
- - if (response.status < 400) {
31
- - return response;
32
- - }
33
-
34
- - return this._manageOauthError(response);
35
- - });
36
- }
37
- ```
38
-
39
- ## 6.5.2
40
-
41
- Fix regression from `6.5.1` : `TokenStorage.refreshToken` does now throws an Error anymore if there is no token stored in the storage.
42
-
43
- ## 6.5.1
44
-
45
- - getItem from AsyncStorage interface might return null
46
- - `TokenStorage.refreshToken` now throws an Error if there is no token stored in the storage.
47
-
48
- ## 6.5.0
49
-
50
- ### Added
51
-
52
- Accept Relation.ONE_TO_ONE relation.
53
- It is basically handled the same way as MANY_TO_ONE, but has been added for semantic purpose.
54
- The comportment may differ later.
55
-
56
- ## 6.4.1
57
-
58
- ### Fixed
59
-
60
- - withUnitOfWork returns a clone of the base repository to avoid race condition on `isUnitOfWorkEnabled`
61
-
62
- ## 6.4.0
63
-
64
- - allow unitOfWork deactivation on find\* calls
65
-
66
- ## 6.3.0
67
-
68
- ### Added
69
-
70
- Accept Relation.MANY_TO_MANY relation.
71
- It is basically handled the same way as ONE_TO_MANY, but has been added for semantic purpose.
72
- The comportment may differ later.
73
-
74
- ## 6.2.0
75
-
76
- ### Changed
77
-
78
- - [TypeScript] better handle deserializeResponse method definition
79
-
80
- ## 6.1.0
81
-
82
- ### Added
83
-
84
- Export `MetadataDefinition` for AbstractClient inheritance
85
-
86
- ## 6.0.0
87
-
88
- ### Changed
89
-
90
- - [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
91
- - TokenStorage's `generateToken` and `refreshToken` methods are now memoized in order to avoid bugs when making concurrent calls
92
-
93
- ## 5.0.0
94
-
95
- 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.
96
-
97
- ### Changed
98
-
99
- - [BREAKING] TokenGenerator's `refreshToken` method signature changed from `refreshToken(accessToken, parameters)` to `refreshToken(accessToken)`.
100
- If you did extend the `AbstractToken` generator, you shouldn't relly on the second parameter.
101
- As a matter of fact, the auto-refreshed token in `AbstractClient` did not send any parameters either, so it should not have been working before !
102
- Accordingly The `refreshToken` method of `TokenStorage` signature changed from `refreshToken(parameters)` to `refreshToken()`
103
- - [Might Break] all pseudo-private methods and attributes (starting with `_`) are unavailable and are now really private (or protected).
104
- - `_storeAccessToken` should be replace by a `ProvidedTokenGenerator`
105
- - [Might Break] `ClassMetadata`, `Attribute` and `Relation` attributes are now `readonly`. You can not change them after initialization.
106
- - [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` and `checkTokenGeneratorConfig`). They should not have been called. They don't exist in JS land anymore.
107
- - [Might Break] `canAutogenerateToken` has been removed from the token storages and replaced by a `autogenerateToken()` method (it's not real POO, but I did not manage to deal with instance of for now)
108
- - [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.
109
-
110
- - Make `SerializerInterace` and `Serializer` input and output understandable
111
-
112
- ### Added
113
-
114
- - export (and implement) `RestClientSdkInterface` and `TokenStorageInterface`
115
- - export `TokenGeneratorInterface` and `AsyncStorageInterface`
116
-
117
- ## 4.1.4
118
-
119
- ### Changed
120
-
121
- - 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.
122
-
123
- ### Fixed
124
-
125
- - Fix issue when two token generation are send on the same time : the second one will not throw an error now.
126
-
127
- ## 4.1.3
128
-
129
- ### Fixed
130
-
131
- - Fix issue when no token is provided but the object is `{ expires_at: null }`
132
-
133
- ## 4.1.2
134
-
135
- ### Fixed
136
-
137
- - Fix issue with urijs 1.19.2
138
-
139
- ## 4.1.1
140
-
141
- ### Changed
142
-
143
- - replace object spread with Object.assign for build to work
144
-
145
- ## 4.1.0
146
-
147
- ### Changed
148
-
149
- - main AbstractClient CRUD methods accept additional requestParams for overriding fetch params like method, headers, etc.
150
-
151
- ## 4.0.1
152
-
153
- ### Changed
154
-
155
- - downgraded jest and babel-jest to ^23.6.0 in order to fix tests
156
-
157
- ## 4.0.0
158
-
159
- ### Changed
160
-
161
- - 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)
162
- - [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
163
-
164
- ## 3.2.1
165
-
166
- ### Changed
167
-
168
- - Refactor error handling with error factory and handle 400's in refreshToken of PasswordGenerator
169
-
170
- ## 3.2.0
171
-
172
- ### Changed
173
-
174
- - Pre-emptively refresh the access token if it is close to expiration before doing any request
175
-
176
- ## 3.1.1
177
-
178
- ### Changed
179
-
180
- - Read json response in \_manageUnauthorized when www-authenticate header is not available
181
-
182
- ## 3.1.0
183
-
184
- ### Changed
185
-
186
- - Store a new key `expires_at` in the access token (which is accessible with `TokenStorage.getAccessTokenObject`) to have the timestamp after which the access token will be invalid, based on the `expires_in`
187
- - Add `TokenStorage.getCurrentTokenExpiresIn` function to known how many seconds are remaining for the access token currently stored
188
-
189
- ## 3.0.0
190
-
191
- ### Changed
192
-
193
- - [Breaking] `AccessDeniedError` is now `UnauthorizedError`
194
- - [Breaking] Default error is now `HttpError`
195
- - Add `ConflictError` to react to 409
196
-
197
- ## 2.3.0
198
-
199
- ### Changed
200
-
201
- - `TokenStorage` add possibility to pass access_token async storage key as constructor param
202
- - `AbstractClient._manageAccessDenied` checks headers instead of json to ensure refreshing the token is required
203
-
204
- ## 2.2.1
205
-
206
- ### Changed
207
-
208
- - `TokenStorage.getAccessTokenObject()` returns an object and null if the stored token is not an object
209
- - [Might Break] `TokenStorage.getAccessTokenObject()` does not return `undefined` anymore but `null` if no token object is found
210
-
211
- ## 2.2.0
212
-
213
- ### Changed
214
-
215
- - Add possibility to pass null as tokenStorage argument of the sdk
216
- - switch method names \_doFetch and \_fetchWithToken in AbstractClient for coherence
217
-
218
- ## 2.1.0
219
-
220
- ### Changed
221
-
222
- - Add method getAccessTokenObject to TokenStorage
223
-
224
- ## 2.0.1
225
-
226
- ### Changed
227
-
228
- - Better packaging system [#48](https://github.com/mapado/rest-client-js-sdk/pull/48)
229
-
230
- ## 2.0.0
231
-
232
- ### Added
233
-
234
- - [Might break] Custom serializer can:
235
- - `serializeItem` has been splitted into `normalizeItem` + `encodeItem`
236
- - `deserializeItem` has been splitted into `denormalizeItem` + `decodeItem`
237
- - `deserializeList` has been splitted into `denormalizeList` + `decodeList`
238
-
239
- You must implement them if you have a custom serialization that do not use plain javascript objects.
240
-
241
- ### Changed
242
-
243
- - [Breaking] Calling `restClientSdk.foo.xxx` is deprecated, you must now call `restClientSdk.getRepository('foo').xxx`
244
- - [Breaking] RestClientSdk now takes a Mapping instance instead of a clientList. This instance is required
245
- - [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.
246
- Beware that now, the `key` is now used both to call the repository name, and passed to the serializer
247
- Before:
248
-
249
- ```js
250
- class SomeClient extends AbstractClient {
251
- getName() {
252
- return 'SomeClient';
253
- }
254
- }
255
-
256
- new RestClientSdk(
257
- // ...
258
- {
259
- foo: SomeClient,
260
- }
261
- );
262
- ```
263
-
264
- Now:
265
-
266
- ```js
267
- const metadata = new ClassMetadata('foo', 'some_endpoint');
268
- mapping = new Mapping();
269
- mapping.setMapping([ metadata ]);
270
-
271
- const sdk = new RestClientSdk(/* ... */, mapping); // `foo` will be used in serializer too
272
- sdk.foo.find();
273
- ```
274
-
275
- - [Breaking] Custom Serializer: If you had a Collection entity containing the result of you entities, you will need to implement the [iterable protocol](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol) on this object, this way, we can register all entities in the unit of work.
276
-
277
- ### Removed
278
-
279
- - Dropped support for node 6
280
- - AbstractClient does not need to specify `getPathBase` anymore: this is generated via the classmetata. You can still override it.
281
- - `getEntityURI` is not mandatory anymore. it will be autogenerate by the AbstractClient. You can still override it
282
- - There is no need to create an empty client extending `AbstractClient` now, the default will be `AbstractClient`
283
- - config `prefix` is not used anymore, you should specify your prefix in the mapping: `new Mapping('/v1')`
284
-
285
- ## 2.0.0-rc.14
286
-
287
- Check relations in `isValidMapping`
288
-
289
- ## 2.0.0-rc.13
290
-
291
- Fix issue when setting a ManyToOne relatossue when setting a ManyToOne relation to `null`n to `null`
292
-
293
- ## 2.0.0-rc.12
294
-
295
- add a function to test mapping validity
296
-
297
- ## 2.0.0-rc.10 + 2.0.0-rc.11
298
-
299
- deserialize + normalize item in unitofwork
300
-
301
- ## 2.0.0-rc.9
302
-
303
- creating or updating an "complex" entity (not a basic JS object) would throw an error
304
-
305
- ## 2.0.0-rc.8
306
-
307
- remove `async` method (that already returned a Promise object)
308
-
309
- ## 2.0.0-rc.7
310
-
311
- Fix issue when posting a ManyToOne relation with only the id as string
312
-
313
- ## 2.0.0-rc.6
314
-
315
- Fix bug in delete call (not returning the response)
316
-
317
- ## 2.0.0-rc.5
318
-
319
- Fix bug in serializer
320
-
321
- ## 2.0.0-rc.4
322
-
323
- Fix issue with list denormalized oo objects
324
-
325
- ## 2.0.0-rc.3
326
-
327
- Cleaner relations, matches the Arguments attributes
328
-
329
- ## 2.0.0-rc.2
330
-
331
- ### Changed
332
-
333
- - `ONE_TO_MANY` and `MANY_TO_ONE` constant are now exported via the `Relation.ONE_TO_MANY` and `Relation.MANY_TO_ONE`, not in the main package
334
-
335
- ## 2.0.0-rc.1
336
-
337
- See release note for 2.0.0
338
-
339
- ## [1.3.2] - 2017-12-04
340
-
341
- ### Changed
342
-
343
- - fix simultaneous refresh token throwing error when trying to access to
344
- response body twice
345
-
346
- ## [1.3.1] - 2017-12-04
347
-
348
- ### Changed
349
-
350
- - add error message to AccessDeniedError in PasswordGenerator's refreshToken
351
-
352
- ## [1.3.0] - 2017-11-29
353
-
354
- ### Changed
355
-
356
- - throw AccessDeniedError only on BadRequestError in PasswordGenerator
357
- refreshToken
358
-
359
- ## [1.2.0] - 2017-11-10
360
-
361
- ### Changed
362
-
363
- - fix response passed as error message in Errors
364
- - throw AccessDeniedError on any Error in PasswordGenerator refreshToken
365
- - allow to pass scope param in tokenGeneratorConfig
366
-
367
- ## [1.1.1] - 2017-10-08
368
-
369
- ### Changed
370
-
371
- - upgrade rollup to 0.50.0
372
-
373
- ## [1.1.0] - 2017-08-30
374
-
375
- ### Changed
376
-
377
- - Pass on response to serializer
378
- - Upgrade dependencies (rollup 0.49, eslint 4, etc.)
379
- - Add prettier to project
380
-
381
- ## [1.0.5] - 2017-08-30
382
-
383
- ### Changed
384
-
385
- - Fix token loop when token is not valid anymore
386
-
387
- ## [1.0.4] - 2017-07-28
388
-
389
- ### Changed
390
-
391
- - Remove undefined headers
392
-
393
- ## [1.0.3] - 2017-07-27
394
-
395
- ### Changed
396
-
397
- - Allow overriding base headers
398
- [#24](https://github.com/mapado/rest-client-js-sdk/pull/24)
399
-
400
- ## [1.0.2] - 2017-07-04
401
-
402
- This release is the same as 0.15.0 and though fully compatible
403
-
404
- ### Changed
405
-
406
- - Rolled back to urijs because domurl use the default node implementation which
407
- is not compatible with the stack we use. The real future solution will be to
408
- use Javascript `URL` object but too early and unstable for now
409
-
410
- ## [1.0.1] - 2017-07-03 - [YANKED]
411
-
412
- ### Changed
413
-
414
- - Make urijs implementation work again but might be breaking
415
- - Url constructor passed with `noTransform = true` for better perf and avoid
416
- potential bugs
417
-
418
- ## [1.0.0] - 2017-07-03 - [YANKED]
419
-
420
- ### Changed
421
-
422
- - Replace [urijs](https://medialize.github.io/URI.js/) dependency by smaller
423
- [domurl](https://github.com/Mikhus/domurl)
424
-
425
- ## [0.15.0] - 2017-06-27
426
-
427
- ### Added
428
-
429
- - Added the current URI as referer for http calls
430
-
431
- ## [0.14.x]
432
-
433
- ### breaking changes
434
-
435
- Error responses in PasswordGenerator and ClientCredentialsGenerator now throw
436
- proper js errors instead of returning the response in the promise rejection
437
-
438
- ## [0.13.x]
439
-
440
- ### breaking changes
441
-
442
- The library does not depends on `immutablejs` anymore, so we needed to make a
443
- few breaking changes:
444
-
445
- - Do not depend on `@id` anymore: The `AbstractClient` need to implements a
446
- `getEntityURI(entity)` and return an query string from it. This is not a great
447
- pattern, but it will do for now.
448
- (https://github.com/mapado/rest-client-js-sdk/pull/19)
449
- - The `entityFactory` does not exists anymore. It has been replaced by a
450
- `Serializer`: (https://github.com/mapado/rest-client-js-sdk/pull/21)
451
- - If you used the default entityFactory, you will now receive plain Javascript
452
- objects instead of immutable's Map or List
453
- - If you previously overrided the `entityFactory`, you will need to switch to
454
- the new `Serializer` object: It is much more extensible but is a bit more
455
- complex to extend. See README to know how to do it.
456
- - the `createEntityFromJsonResponse` method has been renamed to
457
- `deserializeResponse`
458
- - The library moved from ES5 to bundling with rollupjs, that should not break
459
- anything and should improve size of bundle but I am not so sure of this, so
460
- patch may follow (https://github.com/mapado/rest-client-js-sdk/pull/20)
461
-
462
- ## [0.12.x]
463
-
464
- ### breaking changes
465
-
466
- - a `delete` does not call `createEntityFromJsonResponse` anymore as it should
467
- return a "204 No Content" or a "404 Not Found"
468
-
469
- ## [0.11.x]
470
-
471
- ### breaking changes
472
-
473
- - `ProviderTokenGenerator` does not accept a param object anymore on its second
474
- argument.
475
-
476
- ### new features
477
-
478
- - `ProviderTokenGenerator` now accept a function on its second argument which
479
- will be called on `refreshToken`, so you can fully customize the behavior. The
480
- function must return a Promise.
481
-
482
- ## [0.9.x]
483
-
484
- ### breaking changes
485
-
486
- - if the response status is 4xx or 5xx: an error is thrown
487
- [#13](https://github.com/mapado/rest-client-js-sdk/pull/13)
488
-
489
- ### new features
490
-
491
- - memoize token generation and refresh
492
- [#12](https://github.com/mapado/rest-client-js-sdk/pull/12)
493
-
494
- ## [0.6.x]
495
-
496
- ### breaking changes
497
-
498
- The `queryParam` argument was added where needed in the AbstractClient class:
499
-
500
- - `findAll(queryParam = {}, pathParameters = {})`
501
- - `create(entity, queryParam = {}, pathParameters = {})`
502
-
503
- ### new features
504
-
505
- The `queryParam` argument was added where needed in the AbstractClient class:
506
-
507
- - `update(entity, queryParam = {})`