@ps-aux/api-client-axios 0.0.7-rc-2 → 0.0.7-rc-3
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/AxiosOpenApiHttpClient.d.ts +6 -0
- package/dist/browser.d.ts +4 -0
- package/dist/browser.esm.js +18 -17
- package/dist/browser.js +18 -16
- package/dist/commonExports.d.ts +2 -0
- package/dist/convertFormData.d.ts +2 -0
- package/dist/node.d.ts +4 -0
- package/dist/node.esm.js +18 -17
- package/dist/node.js +18 -16
- package/dist/platform/browser.d.ts +10 -0
- package/dist/platform/foo.d.ts +1 -0
- package/dist/platform/node.d.ts +10 -0
- package/dist/platform/types.d.ts +9 -0
- package/package.json +1 -2
- package/src/AxiosOpenApiHttpClient.ts +11 -17
- package/src/browser.ts +2 -3
- package/src/commonExports.ts +1 -2
- package/src/node.ts +2 -3
- package/src/t.ts +0 -22
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { PlatformHelper } from './platform/types';
|
|
3
|
+
import { UrlConverter, PromiseHttpClient } from '@ps-aux/api-client-common';
|
|
4
|
+
export declare const noOpUrlConverter: () => UrlConverter;
|
|
5
|
+
export declare const springBootUrlConverter: () => UrlConverter;
|
|
6
|
+
export declare const createHttpClient: (axios: AxiosInstance, platform: PlatformHelper, urlConverter?: UrlConverter) => PromiseHttpClient;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { PromiseHttpClient } from './commonExports';
|
|
3
|
+
export declare const createHttpClient: (axios: AxiosInstance, urlConverter?: import("@ps-aux/api-client-common").UrlConverter) => PromiseHttpClient;
|
|
4
|
+
export * from './commonExports';
|
package/dist/browser.esm.js
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import 'qs';
|
|
2
2
|
|
|
3
|
-
const ContentType = {
|
|
4
|
-
Json: 'application/json',
|
|
5
|
-
FormData: 'multipart/form-data',
|
|
6
|
-
};
|
|
7
|
-
|
|
8
3
|
const convertToFormData = (payload, platform) => {
|
|
9
4
|
const formData = platform.newFormData();
|
|
10
5
|
const addProp = (key, val) => {
|
|
@@ -284,6 +279,20 @@ const objectToParams = (obj) => {
|
|
|
284
279
|
return res;
|
|
285
280
|
};
|
|
286
281
|
|
|
282
|
+
const fileResFilenameRegex = /filename="([^"]+)"/;
|
|
283
|
+
const getFileNameFromContentDispositionHeader = (contentDispositionHeader) => {
|
|
284
|
+
if (!contentDispositionHeader)
|
|
285
|
+
return 'download-file';
|
|
286
|
+
const match = contentDispositionHeader.match(fileResFilenameRegex);
|
|
287
|
+
const fileName = match ? match[1] : 'downloaded-file';
|
|
288
|
+
return fileName;
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
const ContentType = {
|
|
292
|
+
Json: 'application/json',
|
|
293
|
+
FormData: 'multipart/form-data',
|
|
294
|
+
};
|
|
295
|
+
|
|
287
296
|
const noOpUrlConverter = () => ({ query, path }) => {
|
|
288
297
|
return {
|
|
289
298
|
url: path,
|
|
@@ -296,7 +305,6 @@ const springBootUrlConverter = () => ({ query, path }) => {
|
|
|
296
305
|
params: undefined,
|
|
297
306
|
};
|
|
298
307
|
};
|
|
299
|
-
const fileResFilenameRegex = /filename="([^"]+)"/;
|
|
300
308
|
const createHttpClient$1 = (axios, platform, urlConverter = noOpUrlConverter()) => {
|
|
301
309
|
return {
|
|
302
310
|
request: (req) => {
|
|
@@ -314,16 +322,16 @@ const createHttpClient$1 = (axios, platform, urlConverter = noOpUrlConverter())
|
|
|
314
322
|
headers: {
|
|
315
323
|
ContentType: type,
|
|
316
324
|
},
|
|
317
|
-
responseType: isBlobResponse ? 'blob' : 'json'
|
|
325
|
+
responseType: isBlobResponse ? 'blob' : 'json',
|
|
318
326
|
})
|
|
319
327
|
.then(r => {
|
|
320
328
|
const { data } = r;
|
|
321
329
|
if (isBlobResponse) {
|
|
322
330
|
const contDist = r.headers['content-disposition'];
|
|
323
|
-
const fileName =
|
|
331
|
+
const fileName = getFileNameFromContentDispositionHeader(contDist);
|
|
324
332
|
const type = r.headers['content-type'];
|
|
325
333
|
return new File([data], fileName, {
|
|
326
|
-
type
|
|
334
|
+
type,
|
|
327
335
|
});
|
|
328
336
|
}
|
|
329
337
|
return data;
|
|
@@ -331,13 +339,6 @@ const createHttpClient$1 = (axios, platform, urlConverter = noOpUrlConverter())
|
|
|
331
339
|
},
|
|
332
340
|
};
|
|
333
341
|
};
|
|
334
|
-
const getFileName = (contentDispositionHeader) => {
|
|
335
|
-
if (!contentDispositionHeader)
|
|
336
|
-
return 'download-file';
|
|
337
|
-
const match = contentDispositionHeader.match(fileResFilenameRegex);
|
|
338
|
-
const fileName = match ? match[1] : 'downloaded-file';
|
|
339
|
-
return fileName;
|
|
340
|
-
};
|
|
341
342
|
|
|
342
343
|
class BrowserPlatFormHelper {
|
|
343
344
|
isFile = (obj) => obj instanceof File;
|
|
@@ -358,4 +359,4 @@ const createHttpClient = (axios, urlConverter = noOpUrlConverter()) => {
|
|
|
358
359
|
return createHttpClient$1(axios, new BrowserPlatFormHelper(), urlConverter);
|
|
359
360
|
};
|
|
360
361
|
|
|
361
|
-
export { createHttpClient, noOpUrlConverter, springBootUrlConverter };
|
|
362
|
+
export { ContentType, createHttpClient, noOpUrlConverter, springBootUrlConverter };
|
package/dist/browser.js
CHANGED
|
@@ -2,11 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
require('qs');
|
|
4
4
|
|
|
5
|
-
const ContentType = {
|
|
6
|
-
Json: 'application/json',
|
|
7
|
-
FormData: 'multipart/form-data',
|
|
8
|
-
};
|
|
9
|
-
|
|
10
5
|
const convertToFormData = (payload, platform) => {
|
|
11
6
|
const formData = platform.newFormData();
|
|
12
7
|
const addProp = (key, val) => {
|
|
@@ -286,6 +281,20 @@ const objectToParams = (obj) => {
|
|
|
286
281
|
return res;
|
|
287
282
|
};
|
|
288
283
|
|
|
284
|
+
const fileResFilenameRegex = /filename="([^"]+)"/;
|
|
285
|
+
const getFileNameFromContentDispositionHeader = (contentDispositionHeader) => {
|
|
286
|
+
if (!contentDispositionHeader)
|
|
287
|
+
return 'download-file';
|
|
288
|
+
const match = contentDispositionHeader.match(fileResFilenameRegex);
|
|
289
|
+
const fileName = match ? match[1] : 'downloaded-file';
|
|
290
|
+
return fileName;
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
const ContentType = {
|
|
294
|
+
Json: 'application/json',
|
|
295
|
+
FormData: 'multipart/form-data',
|
|
296
|
+
};
|
|
297
|
+
|
|
289
298
|
const noOpUrlConverter = () => ({ query, path }) => {
|
|
290
299
|
return {
|
|
291
300
|
url: path,
|
|
@@ -298,7 +307,6 @@ const springBootUrlConverter = () => ({ query, path }) => {
|
|
|
298
307
|
params: undefined,
|
|
299
308
|
};
|
|
300
309
|
};
|
|
301
|
-
const fileResFilenameRegex = /filename="([^"]+)"/;
|
|
302
310
|
const createHttpClient$1 = (axios, platform, urlConverter = noOpUrlConverter()) => {
|
|
303
311
|
return {
|
|
304
312
|
request: (req) => {
|
|
@@ -316,16 +324,16 @@ const createHttpClient$1 = (axios, platform, urlConverter = noOpUrlConverter())
|
|
|
316
324
|
headers: {
|
|
317
325
|
ContentType: type,
|
|
318
326
|
},
|
|
319
|
-
responseType: isBlobResponse ? 'blob' : 'json'
|
|
327
|
+
responseType: isBlobResponse ? 'blob' : 'json',
|
|
320
328
|
})
|
|
321
329
|
.then(r => {
|
|
322
330
|
const { data } = r;
|
|
323
331
|
if (isBlobResponse) {
|
|
324
332
|
const contDist = r.headers['content-disposition'];
|
|
325
|
-
const fileName =
|
|
333
|
+
const fileName = getFileNameFromContentDispositionHeader(contDist);
|
|
326
334
|
const type = r.headers['content-type'];
|
|
327
335
|
return new File([data], fileName, {
|
|
328
|
-
type
|
|
336
|
+
type,
|
|
329
337
|
});
|
|
330
338
|
}
|
|
331
339
|
return data;
|
|
@@ -333,13 +341,6 @@ const createHttpClient$1 = (axios, platform, urlConverter = noOpUrlConverter())
|
|
|
333
341
|
},
|
|
334
342
|
};
|
|
335
343
|
};
|
|
336
|
-
const getFileName = (contentDispositionHeader) => {
|
|
337
|
-
if (!contentDispositionHeader)
|
|
338
|
-
return 'download-file';
|
|
339
|
-
const match = contentDispositionHeader.match(fileResFilenameRegex);
|
|
340
|
-
const fileName = match ? match[1] : 'downloaded-file';
|
|
341
|
-
return fileName;
|
|
342
|
-
};
|
|
343
344
|
|
|
344
345
|
class BrowserPlatFormHelper {
|
|
345
346
|
isFile = (obj) => obj instanceof File;
|
|
@@ -360,6 +361,7 @@ const createHttpClient = (axios, urlConverter = noOpUrlConverter()) => {
|
|
|
360
361
|
return createHttpClient$1(axios, new BrowserPlatFormHelper(), urlConverter);
|
|
361
362
|
};
|
|
362
363
|
|
|
364
|
+
exports.ContentType = ContentType;
|
|
363
365
|
exports.createHttpClient = createHttpClient;
|
|
364
366
|
exports.noOpUrlConverter = noOpUrlConverter;
|
|
365
367
|
exports.springBootUrlConverter = springBootUrlConverter;
|
package/dist/node.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { PromiseHttpClient } from './commonExports';
|
|
3
|
+
export declare const createHttpClient: (axios: AxiosInstance, urlConverter?: import("@ps-aux/api-client-common").UrlConverter) => PromiseHttpClient;
|
|
4
|
+
export * from './commonExports';
|
package/dist/node.esm.js
CHANGED
|
@@ -2,11 +2,6 @@ import 'qs';
|
|
|
2
2
|
import NodeFormData from 'form-data';
|
|
3
3
|
import stream from 'stream';
|
|
4
4
|
|
|
5
|
-
const ContentType = {
|
|
6
|
-
Json: 'application/json',
|
|
7
|
-
FormData: 'multipart/form-data',
|
|
8
|
-
};
|
|
9
|
-
|
|
10
5
|
const convertToFormData = (payload, platform) => {
|
|
11
6
|
const formData = platform.newFormData();
|
|
12
7
|
const addProp = (key, val) => {
|
|
@@ -286,6 +281,20 @@ const objectToParams = (obj) => {
|
|
|
286
281
|
return res;
|
|
287
282
|
};
|
|
288
283
|
|
|
284
|
+
const fileResFilenameRegex = /filename="([^"]+)"/;
|
|
285
|
+
const getFileNameFromContentDispositionHeader = (contentDispositionHeader) => {
|
|
286
|
+
if (!contentDispositionHeader)
|
|
287
|
+
return 'download-file';
|
|
288
|
+
const match = contentDispositionHeader.match(fileResFilenameRegex);
|
|
289
|
+
const fileName = match ? match[1] : 'downloaded-file';
|
|
290
|
+
return fileName;
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
const ContentType = {
|
|
294
|
+
Json: 'application/json',
|
|
295
|
+
FormData: 'multipart/form-data',
|
|
296
|
+
};
|
|
297
|
+
|
|
289
298
|
const noOpUrlConverter = () => ({ query, path }) => {
|
|
290
299
|
return {
|
|
291
300
|
url: path,
|
|
@@ -298,7 +307,6 @@ const springBootUrlConverter = () => ({ query, path }) => {
|
|
|
298
307
|
params: undefined,
|
|
299
308
|
};
|
|
300
309
|
};
|
|
301
|
-
const fileResFilenameRegex = /filename="([^"]+)"/;
|
|
302
310
|
const createHttpClient$1 = (axios, platform, urlConverter = noOpUrlConverter()) => {
|
|
303
311
|
return {
|
|
304
312
|
request: (req) => {
|
|
@@ -316,16 +324,16 @@ const createHttpClient$1 = (axios, platform, urlConverter = noOpUrlConverter())
|
|
|
316
324
|
headers: {
|
|
317
325
|
ContentType: type,
|
|
318
326
|
},
|
|
319
|
-
responseType: isBlobResponse ? 'blob' : 'json'
|
|
327
|
+
responseType: isBlobResponse ? 'blob' : 'json',
|
|
320
328
|
})
|
|
321
329
|
.then(r => {
|
|
322
330
|
const { data } = r;
|
|
323
331
|
if (isBlobResponse) {
|
|
324
332
|
const contDist = r.headers['content-disposition'];
|
|
325
|
-
const fileName =
|
|
333
|
+
const fileName = getFileNameFromContentDispositionHeader(contDist);
|
|
326
334
|
const type = r.headers['content-type'];
|
|
327
335
|
return new File([data], fileName, {
|
|
328
|
-
type
|
|
336
|
+
type,
|
|
329
337
|
});
|
|
330
338
|
}
|
|
331
339
|
return data;
|
|
@@ -333,13 +341,6 @@ const createHttpClient$1 = (axios, platform, urlConverter = noOpUrlConverter())
|
|
|
333
341
|
},
|
|
334
342
|
};
|
|
335
343
|
};
|
|
336
|
-
const getFileName = (contentDispositionHeader) => {
|
|
337
|
-
if (!contentDispositionHeader)
|
|
338
|
-
return 'download-file';
|
|
339
|
-
const match = contentDispositionHeader.match(fileResFilenameRegex);
|
|
340
|
-
const fileName = match ? match[1] : 'downloaded-file';
|
|
341
|
-
return fileName;
|
|
342
|
-
};
|
|
343
344
|
|
|
344
345
|
class NodePlatFormHelper {
|
|
345
346
|
isFile = (obj) => {
|
|
@@ -370,4 +371,4 @@ const createHttpClient = (axios, urlConverter = noOpUrlConverter()) => {
|
|
|
370
371
|
return createHttpClient$1(axios, new NodePlatFormHelper(), urlConverter);
|
|
371
372
|
};
|
|
372
373
|
|
|
373
|
-
export { createHttpClient, noOpUrlConverter, springBootUrlConverter };
|
|
374
|
+
export { ContentType, createHttpClient, noOpUrlConverter, springBootUrlConverter };
|
package/dist/node.js
CHANGED
|
@@ -4,11 +4,6 @@ require('qs');
|
|
|
4
4
|
var NodeFormData = require('form-data');
|
|
5
5
|
var stream = require('stream');
|
|
6
6
|
|
|
7
|
-
const ContentType = {
|
|
8
|
-
Json: 'application/json',
|
|
9
|
-
FormData: 'multipart/form-data',
|
|
10
|
-
};
|
|
11
|
-
|
|
12
7
|
const convertToFormData = (payload, platform) => {
|
|
13
8
|
const formData = platform.newFormData();
|
|
14
9
|
const addProp = (key, val) => {
|
|
@@ -288,6 +283,20 @@ const objectToParams = (obj) => {
|
|
|
288
283
|
return res;
|
|
289
284
|
};
|
|
290
285
|
|
|
286
|
+
const fileResFilenameRegex = /filename="([^"]+)"/;
|
|
287
|
+
const getFileNameFromContentDispositionHeader = (contentDispositionHeader) => {
|
|
288
|
+
if (!contentDispositionHeader)
|
|
289
|
+
return 'download-file';
|
|
290
|
+
const match = contentDispositionHeader.match(fileResFilenameRegex);
|
|
291
|
+
const fileName = match ? match[1] : 'downloaded-file';
|
|
292
|
+
return fileName;
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
const ContentType = {
|
|
296
|
+
Json: 'application/json',
|
|
297
|
+
FormData: 'multipart/form-data',
|
|
298
|
+
};
|
|
299
|
+
|
|
291
300
|
const noOpUrlConverter = () => ({ query, path }) => {
|
|
292
301
|
return {
|
|
293
302
|
url: path,
|
|
@@ -300,7 +309,6 @@ const springBootUrlConverter = () => ({ query, path }) => {
|
|
|
300
309
|
params: undefined,
|
|
301
310
|
};
|
|
302
311
|
};
|
|
303
|
-
const fileResFilenameRegex = /filename="([^"]+)"/;
|
|
304
312
|
const createHttpClient$1 = (axios, platform, urlConverter = noOpUrlConverter()) => {
|
|
305
313
|
return {
|
|
306
314
|
request: (req) => {
|
|
@@ -318,16 +326,16 @@ const createHttpClient$1 = (axios, platform, urlConverter = noOpUrlConverter())
|
|
|
318
326
|
headers: {
|
|
319
327
|
ContentType: type,
|
|
320
328
|
},
|
|
321
|
-
responseType: isBlobResponse ? 'blob' : 'json'
|
|
329
|
+
responseType: isBlobResponse ? 'blob' : 'json',
|
|
322
330
|
})
|
|
323
331
|
.then(r => {
|
|
324
332
|
const { data } = r;
|
|
325
333
|
if (isBlobResponse) {
|
|
326
334
|
const contDist = r.headers['content-disposition'];
|
|
327
|
-
const fileName =
|
|
335
|
+
const fileName = getFileNameFromContentDispositionHeader(contDist);
|
|
328
336
|
const type = r.headers['content-type'];
|
|
329
337
|
return new File([data], fileName, {
|
|
330
|
-
type
|
|
338
|
+
type,
|
|
331
339
|
});
|
|
332
340
|
}
|
|
333
341
|
return data;
|
|
@@ -335,13 +343,6 @@ const createHttpClient$1 = (axios, platform, urlConverter = noOpUrlConverter())
|
|
|
335
343
|
},
|
|
336
344
|
};
|
|
337
345
|
};
|
|
338
|
-
const getFileName = (contentDispositionHeader) => {
|
|
339
|
-
if (!contentDispositionHeader)
|
|
340
|
-
return 'download-file';
|
|
341
|
-
const match = contentDispositionHeader.match(fileResFilenameRegex);
|
|
342
|
-
const fileName = match ? match[1] : 'downloaded-file';
|
|
343
|
-
return fileName;
|
|
344
|
-
};
|
|
345
346
|
|
|
346
347
|
class NodePlatFormHelper {
|
|
347
348
|
isFile = (obj) => {
|
|
@@ -372,6 +373,7 @@ const createHttpClient = (axios, urlConverter = noOpUrlConverter()) => {
|
|
|
372
373
|
return createHttpClient$1(axios, new NodePlatFormHelper(), urlConverter);
|
|
373
374
|
};
|
|
374
375
|
|
|
376
|
+
exports.ContentType = ContentType;
|
|
375
377
|
exports.createHttpClient = createHttpClient;
|
|
376
378
|
exports.noOpUrlConverter = noOpUrlConverter;
|
|
377
379
|
exports.springBootUrlConverter = springBootUrlConverter;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PlatformHelper } from './types';
|
|
2
|
+
export declare class BrowserPlatFormHelper implements PlatformHelper {
|
|
3
|
+
isFile: (obj: any) => boolean;
|
|
4
|
+
getFileAndName: (obj: any) => {
|
|
5
|
+
file: File;
|
|
6
|
+
name: string;
|
|
7
|
+
};
|
|
8
|
+
isFileList: (obj: any) => boolean;
|
|
9
|
+
newFormData: () => FormData;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { BrowserPlatFormHelper as Platform } from './browser';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PlatformHelper } from './types';
|
|
2
|
+
export declare class NodePlatFormHelper implements PlatformHelper {
|
|
3
|
+
isFile: (obj: any) => boolean;
|
|
4
|
+
getFileAndName: (obj: any) => {
|
|
5
|
+
file: any;
|
|
6
|
+
name: any;
|
|
7
|
+
};
|
|
8
|
+
isFileList: (obj: any) => boolean;
|
|
9
|
+
newFormData: () => FormData;
|
|
10
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ps-aux/api-client-axios",
|
|
3
|
-
"version": "0.0.7-rc-
|
|
3
|
+
"version": "0.0.7-rc-3",
|
|
4
4
|
"main": "dist/node.js",
|
|
5
5
|
"module": "dist/node.esm.js",
|
|
6
6
|
"browser": "dist/browser.esm.js",
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "rollup -c",
|
|
10
10
|
"dev": "rollup -c --watch",
|
|
11
|
-
"publish": "npm run build && npm publish",
|
|
12
11
|
"tc": "tsc"
|
|
13
12
|
},
|
|
14
13
|
"author": "",
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { AxiosInstance } from 'axios'
|
|
2
|
-
import { ContentType, HttpClient } from './t'
|
|
3
2
|
import { convertToFormData } from './convertFormData'
|
|
4
3
|
import { PlatformHelper } from './platform/types'
|
|
5
|
-
import {
|
|
6
|
-
|
|
4
|
+
import {
|
|
5
|
+
serializeQueryForSpringBoot,
|
|
6
|
+
UrlConverter,
|
|
7
|
+
PromiseHttpClient,
|
|
8
|
+
ContentType,
|
|
9
|
+
getFileNameFromContentDispositionHeader,
|
|
10
|
+
} from '@ps-aux/api-client-common'
|
|
7
11
|
|
|
8
12
|
|
|
9
13
|
export const noOpUrlConverter: () => UrlConverter = () => ({ query, path }) => {
|
|
@@ -22,13 +26,12 @@ export const springBootUrlConverter: () => UrlConverter = () => ({ query, path }
|
|
|
22
26
|
}
|
|
23
27
|
|
|
24
28
|
|
|
25
|
-
const fileResFilenameRegex = /filename="([^"]+)"/
|
|
26
29
|
|
|
27
30
|
export const createHttpClient = (
|
|
28
31
|
axios: AxiosInstance,
|
|
29
32
|
platform: PlatformHelper,
|
|
30
33
|
urlConverter = noOpUrlConverter(),
|
|
31
|
-
):
|
|
34
|
+
): PromiseHttpClient => {
|
|
32
35
|
return {
|
|
33
36
|
request: (req) => {
|
|
34
37
|
const { query, type, body } = req
|
|
@@ -49,18 +52,18 @@ export const createHttpClient = (
|
|
|
49
52
|
headers: {
|
|
50
53
|
ContentType: type,
|
|
51
54
|
},
|
|
52
|
-
responseType: isBlobResponse ? 'blob' : 'json'
|
|
55
|
+
responseType: isBlobResponse ? 'blob' : 'json',
|
|
53
56
|
})
|
|
54
57
|
.then(r => {
|
|
55
58
|
const { data } = r
|
|
56
59
|
if (isBlobResponse) {
|
|
57
60
|
const contDist = r.headers['content-disposition']
|
|
58
|
-
const fileName =
|
|
61
|
+
const fileName = getFileNameFromContentDispositionHeader(contDist)
|
|
59
62
|
|
|
60
63
|
const type = r.headers['content-type']
|
|
61
64
|
|
|
62
65
|
return new File([data as Blob], fileName, {
|
|
63
|
-
type
|
|
66
|
+
type,
|
|
64
67
|
})
|
|
65
68
|
}
|
|
66
69
|
|
|
@@ -71,12 +74,3 @@ export const createHttpClient = (
|
|
|
71
74
|
}
|
|
72
75
|
|
|
73
76
|
|
|
74
|
-
const getFileName = (contentDispositionHeader?: string):string => {
|
|
75
|
-
if (!contentDispositionHeader)
|
|
76
|
-
return 'download-file'
|
|
77
|
-
|
|
78
|
-
const match = contentDispositionHeader.match(fileResFilenameRegex)
|
|
79
|
-
const fileName = match ? match[1] : 'downloaded-file'
|
|
80
|
-
|
|
81
|
-
return fileName
|
|
82
|
-
}
|
package/src/browser.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { AxiosInstance } from 'axios'
|
|
2
|
-
import { HttpClient } from './t'
|
|
3
|
-
|
|
4
2
|
import { createHttpClient as create, noOpUrlConverter } from './AxiosOpenApiHttpClient'
|
|
5
3
|
import { BrowserPlatFormHelper } from './platform/browser'
|
|
4
|
+
import { PromiseHttpClient } from './commonExports'
|
|
6
5
|
|
|
7
6
|
|
|
8
|
-
export const createHttpClient = (axios: AxiosInstance, urlConverter = noOpUrlConverter()):
|
|
7
|
+
export const createHttpClient = (axios: AxiosInstance, urlConverter = noOpUrlConverter()): PromiseHttpClient => {
|
|
9
8
|
return create(axios, new BrowserPlatFormHelper(), urlConverter)
|
|
10
9
|
}
|
|
11
10
|
|
package/src/commonExports.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export { UrlConverter } from '@ps-aux/api-client-common'
|
|
2
|
-
export { HttpClient, Request, RequestParams } from './t'
|
|
1
|
+
export { UrlConverter, PromiseHttpClient, ContentType } from '@ps-aux/api-client-common'
|
|
3
2
|
export { springBootUrlConverter, noOpUrlConverter } from './AxiosOpenApiHttpClient'
|
package/src/node.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { AxiosInstance } from 'axios'
|
|
2
|
-
import { HttpClient } from './t'
|
|
3
|
-
|
|
4
2
|
import { createHttpClient as create, noOpUrlConverter } from './AxiosOpenApiHttpClient'
|
|
5
3
|
import { NodePlatFormHelper } from './platform/node'
|
|
4
|
+
import { PromiseHttpClient } from './commonExports'
|
|
6
5
|
|
|
7
|
-
export const createHttpClient = (axios: AxiosInstance, urlConverter = noOpUrlConverter()):
|
|
6
|
+
export const createHttpClient = (axios: AxiosInstance, urlConverter = noOpUrlConverter()): PromiseHttpClient => {
|
|
8
7
|
return create(axios, new NodePlatFormHelper(), urlConverter)
|
|
9
8
|
}
|
|
10
9
|
|
package/src/t.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export type ContentType = {}
|
|
2
|
-
|
|
3
|
-
export type RequestParams = {}
|
|
4
|
-
|
|
5
|
-
export const ContentType = {
|
|
6
|
-
Json: 'application/json',
|
|
7
|
-
FormData: 'multipart/form-data',
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export type Request = {
|
|
11
|
-
path: string
|
|
12
|
-
method: 'GET' | 'POST' | 'PUT' | 'DELETE'
|
|
13
|
-
format?: 'json' | 'document'
|
|
14
|
-
query?: any
|
|
15
|
-
body?: any
|
|
16
|
-
type?: string
|
|
17
|
-
secure?: boolean
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export type HttpClient<Any = any> = {
|
|
21
|
-
request: <Data, A = any>(req: Request) => Promise<Data>
|
|
22
|
-
}
|