laravel-request 1.2.24 → 1.2.26
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/@types/Api.d.ts +6 -0
- package/package.json +1 -1
- package/src/Api.js +50 -1
package/@types/Api.d.ts
CHANGED
|
@@ -12,18 +12,24 @@ declare module 'laravel-request' {
|
|
|
12
12
|
|
|
13
13
|
static putArg(controller: string, action: string, arg: any, data?: Record<string, any>): ApiRequest;
|
|
14
14
|
|
|
15
|
+
static patchArg(controller: string, action: string, arg: any, data?: Record<string, any>): ApiRequest;
|
|
16
|
+
|
|
15
17
|
static getUrl(url: string, data?: Record<string, any>): ApiRequest;
|
|
16
18
|
|
|
17
19
|
static postUrl(url: string, data?: Record<string, any>): ApiRequest;
|
|
18
20
|
|
|
19
21
|
static putUrl(url: string, data?: Record<string, any>): ApiRequest;
|
|
20
22
|
|
|
23
|
+
static patchUrl(url: string, data?: Record<string, any>): ApiRequest;
|
|
24
|
+
|
|
21
25
|
static get(controller: string, action: string, data?: Record<string, any>): ApiRequest;
|
|
22
26
|
|
|
23
27
|
static post(controller: string, action: string, data?: Record<string, any>): ApiRequest;
|
|
24
28
|
|
|
25
29
|
static put(controller: string, action: string, data?: Record<string, any>): ApiRequest;
|
|
26
30
|
|
|
31
|
+
static patch(controller: string, action: string, data?: Record<string, any>): ApiRequest;
|
|
32
|
+
|
|
27
33
|
static delete(controller: string, action: string, id: any, data?: Record<string, any>): ApiRequest;
|
|
28
34
|
|
|
29
35
|
static encodeQueryString(params: Record<string, any>): string;
|
package/package.json
CHANGED
package/src/Api.js
CHANGED
|
@@ -22,7 +22,10 @@ export default class Api {
|
|
|
22
22
|
*/
|
|
23
23
|
static tokenResolver = async () =>
|
|
24
24
|
{
|
|
25
|
-
|
|
25
|
+
if(typeof window !== 'undefined' && typeof window.document !== 'undefined')
|
|
26
|
+
{
|
|
27
|
+
return window.localStorage.getItem('api_token');
|
|
28
|
+
}
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
/**
|
|
@@ -88,6 +91,18 @@ export default class Api {
|
|
|
88
91
|
return this.put(controller, action, data).addArg(arg);
|
|
89
92
|
}
|
|
90
93
|
|
|
94
|
+
/**
|
|
95
|
+
*
|
|
96
|
+
* @param controller
|
|
97
|
+
* @param action
|
|
98
|
+
* @param arg
|
|
99
|
+
* @param data
|
|
100
|
+
* @return {ApiRequest}
|
|
101
|
+
*/
|
|
102
|
+
static patchArg(controller, action, arg, data = {}) {
|
|
103
|
+
return this.patch(controller, action, data).addArg(arg);
|
|
104
|
+
}
|
|
105
|
+
|
|
91
106
|
/**
|
|
92
107
|
*
|
|
93
108
|
* @param url
|
|
@@ -121,6 +136,28 @@ export default class Api {
|
|
|
121
136
|
return (new this.requestClass('', '', data, 'PUT')).setUrl(url);
|
|
122
137
|
}
|
|
123
138
|
|
|
139
|
+
/**
|
|
140
|
+
*
|
|
141
|
+
* @param url
|
|
142
|
+
* @param data
|
|
143
|
+
* @return {ApiRequest}
|
|
144
|
+
*/
|
|
145
|
+
static patchUrl(url, data = {})
|
|
146
|
+
{
|
|
147
|
+
return (new this.requestClass('', '', data, 'PATCH')).setUrl(url);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
*
|
|
152
|
+
* @param url
|
|
153
|
+
* @param data
|
|
154
|
+
* @return {ApiRequest}
|
|
155
|
+
*/
|
|
156
|
+
static patchUrl(url, data = {})
|
|
157
|
+
{
|
|
158
|
+
return (new this.requestClass('', '', data, 'PATCH')).setUrl(url);
|
|
159
|
+
}
|
|
160
|
+
|
|
124
161
|
/**
|
|
125
162
|
*
|
|
126
163
|
* @param controller
|
|
@@ -152,6 +189,17 @@ export default class Api {
|
|
|
152
189
|
return new this.requestClass(controller, action, data, 'PUT');
|
|
153
190
|
}
|
|
154
191
|
|
|
192
|
+
/**
|
|
193
|
+
*
|
|
194
|
+
* @param controller
|
|
195
|
+
* @param action
|
|
196
|
+
* @param data
|
|
197
|
+
* @returns {ApiRequest}
|
|
198
|
+
*/
|
|
199
|
+
static patch(controller, action, data = {}) {
|
|
200
|
+
return new this.requestClass(controller, action, data, 'PATCH');
|
|
201
|
+
}
|
|
202
|
+
|
|
155
203
|
/**
|
|
156
204
|
*
|
|
157
205
|
* @param controller
|
|
@@ -254,6 +302,7 @@ export default class Api {
|
|
|
254
302
|
} else {
|
|
255
303
|
// Неизвестный формат
|
|
256
304
|
console.warn(`Unsupported Content-Type: ${contentType}`);
|
|
305
|
+
console.warn(response.data);
|
|
257
306
|
return response.data; // Возвращаем данные "как есть"
|
|
258
307
|
}
|
|
259
308
|
} catch (error) {
|