@weapnl/js-junction 0.1.3 → 0.1.4

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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## v0.1.4
6
+ - Added response in `onSuccess` and `onValidationError` callbacks.
7
+
5
8
  ## v0.1.3
6
9
  - Added functionality to add the same global callback on an api multiple times.
7
10
  - Callbacks (response events) are now cleared from the Request after a request has been made and the response events have been called once.
package/README.md CHANGED
@@ -248,7 +248,7 @@ const users = api.request('users').get();
248
248
 
249
249
  // Custom POST request
250
250
  await api.request('users')
251
- .onSuccess((response) => {
251
+ .onSuccess((data, response) => {
252
252
  // Handle success
253
253
  })
254
254
  .post({
@@ -295,7 +295,7 @@ let request = await api.request('users/files')
295
295
  - You can set response events directly on requests so they will only be called for that specific request. After executing the request, they will be automatically reset.
296
296
  ```javascript
297
297
  let request = await api.request('users')
298
- .onSuccess((data) => {
298
+ .onSuccess((data, response) => {
299
299
  // Request successful.
300
300
  })
301
301
  .onUnauthorized((response) => {
@@ -304,7 +304,7 @@ let request = await api.request('users')
304
304
  .onForbidden((response) => {
305
305
  // Access not allowed.
306
306
  })
307
- .onValidationError((validation) => {
307
+ .onValidationError((validation, response) => {
308
308
  // validation.message
309
309
  // validation.errors
310
310
  })
package/index.d.ts CHANGED
@@ -24,9 +24,9 @@ declare class Api {
24
24
  setHeader(key: string, value: string): void;
25
25
  removeHeader(key: string): void;
26
26
 
27
- onSuccess(callback?: (data: any) => void): this;
27
+ onSuccess(callback?: (data: any, response: AxiosResponse) => void): this;
28
28
  onError(callback?: (response: AxiosResponse) => void): this;
29
- onValidationError(callback?: (validation: any) => void): this;
29
+ onValidationError(callback?: (validation: any, response: AxiosResponse) => void): this;
30
30
  onUnauthorized(callback?: (response: AxiosResponse) => void): this;
31
31
  onForbidden(callback?: (response: AxiosResponse) => void): this;
32
32
  onFinished(callback?: (response: AxiosResponse) => void): this;
@@ -83,9 +83,9 @@ declare class Request extends Mixins {
83
83
  delete(): Promise<this>;
84
84
  storeFiles(files?: object, data?: object, url?: string|null): Promise<this>;
85
85
  readonly bodyParameters: object;
86
- onSuccess<T = any>(callback?: (result: T, data: any) => void): this;
86
+ onSuccess<T = any>(callback?: (result: T, data: any, response: Response) => void): this;
87
87
  onError(callback?: (response: Response) => void): this;
88
- onValidationError(callback?: (validation: object) => void): this;
88
+ onValidationError(callback?: (validation: object, response: Response) => void): this;
89
89
  onUnauthorized(callback?: (response: Response) => void): this;
90
90
  onForbidden(callback?: (response: Response) => void): this;
91
91
  onFinished(callback?: (response: Response) => void): this;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weapnl/js-junction",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "This project allows you to easily consume API's built with Junction.",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
@@ -75,7 +75,8 @@ export default class ResponseEventsHandler {
75
75
  async _executeOnSuccessCallbacks (response) {
76
76
  await this._executeCallbacks(
77
77
  this._responseEventsList.flatMap((responseEvent) => responseEvent._onSuccessCallbacks),
78
- ...[this._onSuccessData, response.data].filter((value) => !! value)
78
+ ...[this._onSuccessData, response.data].filter((value) => !! value),
79
+ response
79
80
  );
80
81
  }
81
82
 
@@ -103,7 +104,8 @@ export default class ResponseEventsHandler {
103
104
 
104
105
  await this._executeCallbacks(
105
106
  this._responseEventsList.flatMap((responseEvent) => responseEvent._onValidationErrorCallbacks),
106
- validation
107
+ validation,
108
+ response
107
109
  );
108
110
  }
109
111