abbot-http-client 0.0.39 → 0.0.41
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/dist/index.cjs +16 -12
- package/dist/index.d.cts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +16 -12
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -253,33 +253,33 @@ var AbbotHttp = class extends Axios {
|
|
|
253
253
|
axios2.interceptors.request.use(
|
|
254
254
|
(config) => {
|
|
255
255
|
const req = { ...config };
|
|
256
|
-
if (
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
256
|
+
if (req.method && req.method.toLowerCase() === "post") {
|
|
257
|
+
req.responseType = option?.responseType ?? "json";
|
|
258
|
+
if (req.data) {
|
|
259
|
+
if (req.data instanceof FormData) {
|
|
260
|
+
if (req.data.get("param")) {
|
|
261
|
+
req.data.set(
|
|
261
262
|
"param",
|
|
262
|
-
cryp.encrypt(
|
|
263
|
+
cryp.encrypt(req.data.get("param")?.toString())
|
|
263
264
|
);
|
|
264
265
|
}
|
|
265
266
|
} else {
|
|
266
267
|
const payload = {};
|
|
267
|
-
payload.param = cryp.encrypt(JSON.stringify(
|
|
268
|
+
payload.param = cryp.encrypt(JSON.stringify(req.data));
|
|
268
269
|
const body = payload ? new URLSearchParams(payload).toString() : "";
|
|
269
270
|
req.data = body;
|
|
270
271
|
req.headers.setContentType(
|
|
271
272
|
option?.contentType ?? this.config.axios.headers.post.contentType
|
|
272
273
|
);
|
|
273
|
-
req.responseType = option?.responseType ?? "json";
|
|
274
274
|
}
|
|
275
275
|
}
|
|
276
276
|
}
|
|
277
277
|
req.headers.set("data-code", iv);
|
|
278
278
|
if (this.config.app.trackingId) {
|
|
279
|
-
|
|
279
|
+
req.headers.set("X-Trace-Id", this.config.app.trackingId);
|
|
280
280
|
}
|
|
281
281
|
if (this.config.app.userJwt) {
|
|
282
|
-
|
|
282
|
+
req.headers.setAuthorization(`Bearer ${this.config.app.userJwt}`);
|
|
283
283
|
}
|
|
284
284
|
return req;
|
|
285
285
|
},
|
|
@@ -288,10 +288,10 @@ var AbbotHttp = class extends Axios {
|
|
|
288
288
|
axios2.interceptors.response.use(
|
|
289
289
|
(response) => {
|
|
290
290
|
const res = { ...response };
|
|
291
|
-
res.data = cryp.decrypt(response.data);
|
|
292
291
|
if (option?.isDownload) {
|
|
293
292
|
return res;
|
|
294
293
|
}
|
|
294
|
+
res.data = cryp.decrypt(response.data);
|
|
295
295
|
return res.data;
|
|
296
296
|
},
|
|
297
297
|
(error) => {
|
|
@@ -400,7 +400,11 @@ var AbbotHttp = class extends Axios {
|
|
|
400
400
|
return response;
|
|
401
401
|
}
|
|
402
402
|
async download(url, param, option) {
|
|
403
|
-
const axios2 = this.createAxiosInstance({
|
|
403
|
+
const axios2 = this.createAxiosInstance({
|
|
404
|
+
...option,
|
|
405
|
+
isDownload: true,
|
|
406
|
+
responseType: "blob"
|
|
407
|
+
});
|
|
404
408
|
const response = await axios2.post(url, param);
|
|
405
409
|
if (this.config.devMode) {
|
|
406
410
|
axios2.log.LogRequest(axios2.cryp, "POST", url, param, response);
|
package/dist/index.d.cts
CHANGED
|
@@ -93,7 +93,11 @@ declare class AbbotHttp extends Axios {
|
|
|
93
93
|
post<T>(url: string, param?: Record<string, any> | null, option?: Partial<MethodOption>): Promise<AbbotResponse<T>>;
|
|
94
94
|
get<T>(url: string, option?: Partial<MethodOption>): Promise<AbbotResponse<T>>;
|
|
95
95
|
download(url: string, param?: Record<string, any> | null,
|
|
96
|
-
/**
|
|
96
|
+
/**
|
|
97
|
+
* isDownload is set to "true" mandatory
|
|
98
|
+
*
|
|
99
|
+
* responseType is set to "blob" mandatory
|
|
100
|
+
*/
|
|
97
101
|
option?: Partial<MethodOption>): Promise<AxiosResponse>;
|
|
98
102
|
uploadFile<T>(url: string, file: File, param?: Record<string, any> | null, option?: Partial<MethodOption>): Promise<AbbotResponse<T>>;
|
|
99
103
|
uploadFile<T>(url: string, file: File[], fileKeys: string[], param?: Record<string, any> | null, option?: Partial<MethodOption>): Promise<AbbotResponse<T>>;
|
package/dist/index.d.ts
CHANGED
|
@@ -93,7 +93,11 @@ declare class AbbotHttp extends Axios {
|
|
|
93
93
|
post<T>(url: string, param?: Record<string, any> | null, option?: Partial<MethodOption>): Promise<AbbotResponse<T>>;
|
|
94
94
|
get<T>(url: string, option?: Partial<MethodOption>): Promise<AbbotResponse<T>>;
|
|
95
95
|
download(url: string, param?: Record<string, any> | null,
|
|
96
|
-
/**
|
|
96
|
+
/**
|
|
97
|
+
* isDownload is set to "true" mandatory
|
|
98
|
+
*
|
|
99
|
+
* responseType is set to "blob" mandatory
|
|
100
|
+
*/
|
|
97
101
|
option?: Partial<MethodOption>): Promise<AxiosResponse>;
|
|
98
102
|
uploadFile<T>(url: string, file: File, param?: Record<string, any> | null, option?: Partial<MethodOption>): Promise<AbbotResponse<T>>;
|
|
99
103
|
uploadFile<T>(url: string, file: File[], fileKeys: string[], param?: Record<string, any> | null, option?: Partial<MethodOption>): Promise<AbbotResponse<T>>;
|
package/dist/index.js
CHANGED
|
@@ -214,33 +214,33 @@ var AbbotHttp = class extends Axios {
|
|
|
214
214
|
axios2.interceptors.request.use(
|
|
215
215
|
(config) => {
|
|
216
216
|
const req = { ...config };
|
|
217
|
-
if (
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
217
|
+
if (req.method && req.method.toLowerCase() === "post") {
|
|
218
|
+
req.responseType = option?.responseType ?? "json";
|
|
219
|
+
if (req.data) {
|
|
220
|
+
if (req.data instanceof FormData) {
|
|
221
|
+
if (req.data.get("param")) {
|
|
222
|
+
req.data.set(
|
|
222
223
|
"param",
|
|
223
|
-
cryp.encrypt(
|
|
224
|
+
cryp.encrypt(req.data.get("param")?.toString())
|
|
224
225
|
);
|
|
225
226
|
}
|
|
226
227
|
} else {
|
|
227
228
|
const payload = {};
|
|
228
|
-
payload.param = cryp.encrypt(JSON.stringify(
|
|
229
|
+
payload.param = cryp.encrypt(JSON.stringify(req.data));
|
|
229
230
|
const body = payload ? new URLSearchParams(payload).toString() : "";
|
|
230
231
|
req.data = body;
|
|
231
232
|
req.headers.setContentType(
|
|
232
233
|
option?.contentType ?? this.config.axios.headers.post.contentType
|
|
233
234
|
);
|
|
234
|
-
req.responseType = option?.responseType ?? "json";
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
237
|
}
|
|
238
238
|
req.headers.set("data-code", iv);
|
|
239
239
|
if (this.config.app.trackingId) {
|
|
240
|
-
|
|
240
|
+
req.headers.set("X-Trace-Id", this.config.app.trackingId);
|
|
241
241
|
}
|
|
242
242
|
if (this.config.app.userJwt) {
|
|
243
|
-
|
|
243
|
+
req.headers.setAuthorization(`Bearer ${this.config.app.userJwt}`);
|
|
244
244
|
}
|
|
245
245
|
return req;
|
|
246
246
|
},
|
|
@@ -249,10 +249,10 @@ var AbbotHttp = class extends Axios {
|
|
|
249
249
|
axios2.interceptors.response.use(
|
|
250
250
|
(response) => {
|
|
251
251
|
const res = { ...response };
|
|
252
|
-
res.data = cryp.decrypt(response.data);
|
|
253
252
|
if (option?.isDownload) {
|
|
254
253
|
return res;
|
|
255
254
|
}
|
|
255
|
+
res.data = cryp.decrypt(response.data);
|
|
256
256
|
return res.data;
|
|
257
257
|
},
|
|
258
258
|
(error) => {
|
|
@@ -361,7 +361,11 @@ var AbbotHttp = class extends Axios {
|
|
|
361
361
|
return response;
|
|
362
362
|
}
|
|
363
363
|
async download(url, param, option) {
|
|
364
|
-
const axios2 = this.createAxiosInstance({
|
|
364
|
+
const axios2 = this.createAxiosInstance({
|
|
365
|
+
...option,
|
|
366
|
+
isDownload: true,
|
|
367
|
+
responseType: "blob"
|
|
368
|
+
});
|
|
365
369
|
const response = await axios2.post(url, param);
|
|
366
370
|
if (this.config.devMode) {
|
|
367
371
|
axios2.log.LogRequest(axios2.cryp, "POST", url, param, response);
|