@weapnl/js-junction 0.1.3 → 0.2.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.
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;
@@ -80,12 +80,12 @@ declare class Request extends Mixins {
80
80
  post(data?: object): Promise<this>;
81
81
  put(data?: object): Promise<this>;
82
82
  setKey(key: string): this;
83
- delete(): Promise<this>;
83
+ delete(data?: object): 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;
@@ -126,7 +126,7 @@ export class Model extends Request {
126
126
 
127
127
  update(extraData?: JsonMap): Promise<Model>;
128
128
 
129
- destroy(): Promise<boolean>;
129
+ destroy(extraData?: JsonMap): Promise<boolean>;
130
130
 
131
131
  save(extraData?: JsonMap): Promise<Model>;
132
132
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weapnl/js-junction",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
4
  "description": "This project allows you to easily consume API's built with Junction.",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
@@ -202,7 +202,12 @@ export default class Model extends Request {
202
202
 
203
203
  this._response = await this._connection.post(
204
204
  this._queryString(),
205
- { ...this._attributes.toJson(this), ...this._mediaCollections.toJson(this), ...extraData },
205
+ {
206
+ ...this._attributes.toJson(this),
207
+ ...this._mediaCollections.toJson(this),
208
+ ..._.merge(...this._customParameters),
209
+ ...extraData,
210
+ },
206
211
  );
207
212
 
208
213
  this._connection.removeRequest(this);
@@ -234,7 +239,12 @@ export default class Model extends Request {
234
239
 
235
240
  this._response = await this._connection.put(
236
241
  this._queryString(this._identifier),
237
- { ...this._attributes.toJson(this), ...this._mediaCollections.toJson(this), ...extraData },
242
+ {
243
+ ...this._attributes.toJson(this),
244
+ ...this._mediaCollections.toJson(this),
245
+ ..._.merge(...this._customParameters),
246
+ ...extraData,
247
+ },
238
248
  );
239
249
 
240
250
  this._connection.removeRequest(this);
@@ -257,13 +267,19 @@ export default class Model extends Request {
257
267
  /**
258
268
  * Delete the current model.
259
269
  *
270
+ * @param {Object} [extraData] Extra data to send to the API
271
+ *
260
272
  * @returns {boolean} Whether the deletion was successful.
261
273
  */
262
- async destroy () {
274
+ async destroy (extraData = {}) {
263
275
  this._connection.cancelRunning(this);
264
276
 
265
277
  this._response = await this._connection.delete(
266
278
  this._queryString(this._identifier),
279
+ {
280
+ ..._.merge(...this._customParameters),
281
+ ...extraData,
282
+ },
267
283
  );
268
284
 
269
285
  this._connection.removeRequest(this);
package/src/connection.js CHANGED
@@ -49,12 +49,12 @@ export default class Connection {
49
49
  return this._execute(query, 'post', data);
50
50
  }
51
51
 
52
- async put (query, params) {
53
- return this._execute(query, 'put', params);
52
+ async put (query, data) {
53
+ return this._execute(query, 'put', data);
54
54
  }
55
55
 
56
- async delete (query) {
57
- return this._execute(query, 'delete');
56
+ async delete (query, data) {
57
+ return this._execute(query, 'delete', data);
58
58
  }
59
59
 
60
60
  async _execute (url, method, data) {
package/src/request.js CHANGED
@@ -150,15 +150,18 @@ export default class Request {
150
150
  }
151
151
 
152
152
  /**
153
+ * @param {Object} data
154
+ *
153
155
  * @returns {this} The current instance.
154
156
  */
155
- async delete () {
157
+ async delete (data = {}) {
156
158
  const url = this.url ?? this.constructor.endpoint;
157
159
 
158
160
  this._connection.cancelRunning(this);
159
161
 
160
162
  this._response = await this._connection.delete(
161
163
  url,
164
+ { ...data, ...this.bodyParameters },
162
165
  );
163
166
 
164
167
  this._connection.removeRequest(this);
@@ -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