@ps-aux/api-client-axios 0.0.8-rc-6 → 0.0.9-rc-7

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.
@@ -311,6 +311,10 @@ const createHttpClient$1 = (axios, platform, urlConverter = noOpUrlConverter())
311
311
  const { query, type, body } = req;
312
312
  const isBlobResponse = req.format === 'document';
313
313
  const data = type === ContentType.FormData ? convertToFormData(body, platform) : body;
314
+ const headers = {};
315
+ if (type) {
316
+ headers['Content-Type'] = type;
317
+ }
314
318
  return axios
315
319
  .request({
316
320
  method: req.method,
@@ -319,10 +323,8 @@ const createHttpClient$1 = (axios, platform, urlConverter = noOpUrlConverter())
319
323
  // url: req.path,
320
324
  ...urlConverter(req),
321
325
  data,
322
- headers: {
323
- ContentType: type,
324
- },
325
- responseType: isBlobResponse ? 'blob' : 'json',
326
+ headers,
327
+ responseType: isBlobResponse ? platform.getFileAxiosResponseType() : 'json',
326
328
  })
327
329
  .then(r => {
328
330
  const { data } = r;
@@ -353,6 +355,7 @@ class BrowserPlatFormHelper {
353
355
  isFileList = (obj) => obj instanceof FileList;
354
356
  // @ts-ignore
355
357
  newFormData = () => new FormData();
358
+ getFileAxiosResponseType = () => 'blob';
356
359
  }
357
360
 
358
361
  const createHttpClient = (axios, urlConverter = noOpUrlConverter()) => {
package/dist/browser.js CHANGED
@@ -313,6 +313,10 @@ const createHttpClient$1 = (axios, platform, urlConverter = noOpUrlConverter())
313
313
  const { query, type, body } = req;
314
314
  const isBlobResponse = req.format === 'document';
315
315
  const data = type === ContentType.FormData ? convertToFormData(body, platform) : body;
316
+ const headers = {};
317
+ if (type) {
318
+ headers['Content-Type'] = type;
319
+ }
316
320
  return axios
317
321
  .request({
318
322
  method: req.method,
@@ -321,10 +325,8 @@ const createHttpClient$1 = (axios, platform, urlConverter = noOpUrlConverter())
321
325
  // url: req.path,
322
326
  ...urlConverter(req),
323
327
  data,
324
- headers: {
325
- ContentType: type,
326
- },
327
- responseType: isBlobResponse ? 'blob' : 'json',
328
+ headers,
329
+ responseType: isBlobResponse ? platform.getFileAxiosResponseType() : 'json',
328
330
  })
329
331
  .then(r => {
330
332
  const { data } = r;
@@ -355,6 +357,7 @@ class BrowserPlatFormHelper {
355
357
  isFileList = (obj) => obj instanceof FileList;
356
358
  // @ts-ignore
357
359
  newFormData = () => new FormData();
360
+ getFileAxiosResponseType = () => 'blob';
358
361
  }
359
362
 
360
363
  const createHttpClient = (axios, urlConverter = noOpUrlConverter()) => {
package/dist/node.esm.js CHANGED
@@ -313,6 +313,10 @@ const createHttpClient$1 = (axios, platform, urlConverter = noOpUrlConverter())
313
313
  const { query, type, body } = req;
314
314
  const isBlobResponse = req.format === 'document';
315
315
  const data = type === ContentType.FormData ? convertToFormData(body, platform) : body;
316
+ const headers = {};
317
+ if (type) {
318
+ headers['Content-Type'] = type;
319
+ }
316
320
  return axios
317
321
  .request({
318
322
  method: req.method,
@@ -321,10 +325,8 @@ const createHttpClient$1 = (axios, platform, urlConverter = noOpUrlConverter())
321
325
  // url: req.path,
322
326
  ...urlConverter(req),
323
327
  data,
324
- headers: {
325
- ContentType: type,
326
- },
327
- responseType: isBlobResponse ? 'blob' : 'json',
328
+ headers,
329
+ responseType: isBlobResponse ? platform.getFileAxiosResponseType() : 'json',
328
330
  })
329
331
  .then(r => {
330
332
  const { data } = r;
@@ -365,6 +367,7 @@ class NodePlatFormHelper {
365
367
  };
366
368
  // @ts-ignore
367
369
  newFormData = () => new NodeFormData();
370
+ getFileAxiosResponseType = () => 'arraybuffer';
368
371
  }
369
372
 
370
373
  const createHttpClient = (axios, urlConverter = noOpUrlConverter()) => {
package/dist/node.js CHANGED
@@ -315,6 +315,10 @@ const createHttpClient$1 = (axios, platform, urlConverter = noOpUrlConverter())
315
315
  const { query, type, body } = req;
316
316
  const isBlobResponse = req.format === 'document';
317
317
  const data = type === ContentType.FormData ? convertToFormData(body, platform) : body;
318
+ const headers = {};
319
+ if (type) {
320
+ headers['Content-Type'] = type;
321
+ }
318
322
  return axios
319
323
  .request({
320
324
  method: req.method,
@@ -323,10 +327,8 @@ const createHttpClient$1 = (axios, platform, urlConverter = noOpUrlConverter())
323
327
  // url: req.path,
324
328
  ...urlConverter(req),
325
329
  data,
326
- headers: {
327
- ContentType: type,
328
- },
329
- responseType: isBlobResponse ? 'blob' : 'json',
330
+ headers,
331
+ responseType: isBlobResponse ? platform.getFileAxiosResponseType() : 'json',
330
332
  })
331
333
  .then(r => {
332
334
  const { data } = r;
@@ -367,6 +369,7 @@ class NodePlatFormHelper {
367
369
  };
368
370
  // @ts-ignore
369
371
  newFormData = () => new NodeFormData();
372
+ getFileAxiosResponseType = () => 'arraybuffer';
370
373
  }
371
374
 
372
375
  const createHttpClient = (axios, urlConverter = noOpUrlConverter()) => {
@@ -1,10 +1,11 @@
1
1
  import { PlatformHelper } from './types';
2
2
  export declare class BrowserPlatFormHelper implements PlatformHelper {
3
- isFile: (obj: any) => boolean;
3
+ isFile: (obj: any) => obj is File;
4
4
  getFileAndName: (obj: any) => {
5
5
  file: File;
6
6
  name: string;
7
7
  };
8
- isFileList: (obj: any) => boolean;
8
+ isFileList: (obj: any) => obj is FileList;
9
9
  newFormData: () => FormData;
10
+ getFileAxiosResponseType: () => "blob";
10
11
  }
@@ -7,4 +7,5 @@ export declare class NodePlatFormHelper implements PlatformHelper {
7
7
  };
8
8
  isFileList: (obj: any) => boolean;
9
9
  newFormData: () => FormData;
10
+ getFileAxiosResponseType: () => "arraybuffer";
10
11
  }
@@ -6,4 +6,5 @@ export type PlatformHelper = {
6
6
  name: string;
7
7
  };
8
8
  isFileList: (obj: any) => boolean;
9
+ getFileAxiosResponseType: () => 'blob' | 'arraybuffer';
9
10
  };
package/package.json CHANGED
@@ -1,14 +1,16 @@
1
1
  {
2
2
  "name": "@ps-aux/api-client-axios",
3
- "version": "0.0.8-rc-6",
3
+ "version": "0.0.9-rc-7",
4
4
  "main": "dist/node.js",
5
5
  "module": "dist/node.esm.js",
6
6
  "browser": "dist/browser.esm.js",
7
7
  "types": "dist/api-client-axios/src/node.d.ts",
8
8
  "scripts": {
9
9
  "build": "rollup -c",
10
+ "pub": "npm run build && npm --access public publish",
10
11
  "dev": "rollup -c --watch",
11
- "tc": "tsc"
12
+ "tc": "tsc",
13
+ "test": "jest"
12
14
  },
13
15
  "author": "",
14
16
  "license": "ISC",
@@ -41,6 +41,10 @@ export const createHttpClient = (
41
41
  const data =
42
42
  type === ContentType.FormData ? convertToFormData(body, platform) : body
43
43
 
44
+ const headers: Record<string, string> = {}
45
+ if (type) {
46
+ headers['Content-Type'] = type
47
+ }
44
48
  return axios
45
49
  .request({
46
50
  method: req.method,
@@ -49,10 +53,8 @@ export const createHttpClient = (
49
53
  // url: req.path,
50
54
  ...urlConverter(req),
51
55
  data,
52
- headers: {
53
- ContentType: type,
54
- },
55
- responseType: isBlobResponse ? 'blob' : 'json',
56
+ headers,
57
+ responseType: isBlobResponse ? platform.getFileAxiosResponseType() : 'json',
56
58
  })
57
59
  .then(r => {
58
60
  const { data } = r
@@ -19,4 +19,6 @@ export class BrowserPlatFormHelper implements PlatformHelper {
19
19
  obj instanceof FileList
20
20
  // @ts-ignore
21
21
  newFormData = () => new FormData()
22
+
23
+ getFileAxiosResponseType = (): 'blob' => 'blob'
22
24
  }
@@ -31,4 +31,7 @@ export class NodePlatFormHelper implements PlatformHelper {
31
31
  }
32
32
  // @ts-ignore
33
33
  newFormData = (): FormData => new NodeFormData()
34
+
35
+ getFileAxiosResponseType = (): 'arraybuffer' => 'arraybuffer'
36
+
34
37
  }
@@ -6,4 +6,6 @@ export type PlatformHelper = {
6
6
  name: string
7
7
  }
8
8
  isFileList: (obj: any) => boolean
9
+
10
+ getFileAxiosResponseType: () => 'blob' | 'arraybuffer'
9
11
  }
@@ -0,0 +1,22 @@
1
+ import { AxiosApi } from '@ps-aux/api-client-api-testing/apis/axios/client'
2
+ import Axios from 'axios'
3
+ import { createHttpClient } from '../src/AxiosOpenApiHttpClient'
4
+ import { NodePlatFormHelper } from '../src/platform/node'
5
+ import { createHttpServer, MirroredReqRes } from '../../helpers/http-server'
6
+
7
+ const Api = (url: string) =>
8
+ new AxiosApi(createHttpClient(Axios.create({ baseURL: url }), new NodePlatFormHelper()))
9
+
10
+ it('test', async () => {
11
+
12
+ const server = createHttpServer()
13
+ const { url } = await server.start()
14
+ const api = Api(url)
15
+
16
+ try {
17
+ await api.app.getHello({ name: 'world' })
18
+ expect(server.lastRequest().url).toBe('/api/hello?name=world')
19
+ } finally {
20
+ await server.stop()
21
+ }
22
+ })