@ps-aux/api-client-axios 0.7.0-rc.2 → 0.7.0-rc.4
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/browser.cjs +40 -12
- package/dist/browser.d.cts +10 -5
- package/dist/browser.d.mts +10 -5
- package/dist/browser.d.ts +10 -5
- package/dist/browser.mjs +40 -12
- package/dist/node.cjs +40 -12
- package/dist/node.d.cts +10 -5
- package/dist/node.d.mts +10 -5
- package/dist/node.d.ts +10 -5
- package/dist/node.mjs +40 -12
- package/package.json +3 -3
package/dist/browser.cjs
CHANGED
|
@@ -166,15 +166,15 @@ const createHttpClient$1 = (axios, opts) => {
|
|
|
166
166
|
return {
|
|
167
167
|
request: (req) => {
|
|
168
168
|
helper.validateRequest(req);
|
|
169
|
-
const { query,
|
|
169
|
+
const { query, contentType, body, headers: reqHeaders } = req;
|
|
170
170
|
const paramsSerializer = querySerializer ? (r) => helper.serializeQuery(r, querySerializer) : void 0;
|
|
171
|
-
const isBlobResponse = req.
|
|
171
|
+
const isBlobResponse = req.responseFormat === "document";
|
|
172
172
|
const headers = { ...reqHeaders || {} };
|
|
173
173
|
let data = body;
|
|
174
|
-
if (
|
|
174
|
+
if (contentType === "multipart/form-data") {
|
|
175
175
|
data = helper.convertToFormData(body);
|
|
176
|
-
} else if (
|
|
177
|
-
headers["Content-Type"] =
|
|
176
|
+
} else if (contentType) {
|
|
177
|
+
headers["Content-Type"] = contentType;
|
|
178
178
|
}
|
|
179
179
|
return axios.request({
|
|
180
180
|
method: req.method,
|
|
@@ -185,22 +185,50 @@ const createHttpClient$1 = (axios, opts) => {
|
|
|
185
185
|
headers,
|
|
186
186
|
responseType: isBlobResponse ? "arraybuffer" : "json"
|
|
187
187
|
}).then((r) => {
|
|
188
|
-
const
|
|
188
|
+
const headers2 = normalizeHeaders(
|
|
189
|
+
r.headers
|
|
190
|
+
);
|
|
191
|
+
const response = {
|
|
192
|
+
body: r.data,
|
|
193
|
+
headers: headers2,
|
|
194
|
+
status: r.status
|
|
195
|
+
};
|
|
189
196
|
if (isBlobResponse) {
|
|
190
|
-
const contDist =
|
|
197
|
+
const contDist = getHeaderValue(
|
|
198
|
+
headers2["content-disposition"]
|
|
199
|
+
);
|
|
191
200
|
const fileName = helper.getFileNameFromContentDispositionHeader(
|
|
192
201
|
contDist
|
|
193
202
|
);
|
|
194
|
-
const type =
|
|
195
|
-
return
|
|
196
|
-
|
|
197
|
-
|
|
203
|
+
const type = getHeaderValue(headers2["content-type"]);
|
|
204
|
+
return {
|
|
205
|
+
...response,
|
|
206
|
+
body: new File([r.data], fileName, {
|
|
207
|
+
type
|
|
208
|
+
})
|
|
209
|
+
};
|
|
198
210
|
}
|
|
199
|
-
return
|
|
211
|
+
return response;
|
|
200
212
|
});
|
|
201
213
|
}
|
|
202
214
|
};
|
|
203
215
|
};
|
|
216
|
+
const normalizeHeaders = (headers) => {
|
|
217
|
+
const normalized = {};
|
|
218
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
219
|
+
if (value == null) {
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
normalized[key.toLowerCase()] = Array.isArray(value) ? value.map(String) : String(value);
|
|
223
|
+
}
|
|
224
|
+
return normalized;
|
|
225
|
+
};
|
|
226
|
+
const getHeaderValue = (header) => {
|
|
227
|
+
if (Array.isArray(header)) {
|
|
228
|
+
return header[0];
|
|
229
|
+
}
|
|
230
|
+
return header;
|
|
231
|
+
};
|
|
204
232
|
|
|
205
233
|
const createHttpClient = (axios, opts) => {
|
|
206
234
|
return createHttpClient$1(axios, {
|
package/dist/browser.d.cts
CHANGED
|
@@ -4,19 +4,24 @@ type KnownRequestContentType = 'application/json' | 'multipart/form-data' | 'app
|
|
|
4
4
|
type RequestContentType = KnownRequestContentType | string;
|
|
5
5
|
type QueryValue = string | number | boolean | null | undefined | QueryValue[] | Record<string, any> | unknown;
|
|
6
6
|
type QueryParams = Record<string, QueryValue>;
|
|
7
|
-
type
|
|
7
|
+
type HttpRequest = {
|
|
8
8
|
path: string;
|
|
9
9
|
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
10
|
-
|
|
10
|
+
responseFormat?: 'json' | 'document';
|
|
11
11
|
headers?: Record<string, string>;
|
|
12
12
|
query?: QueryParams;
|
|
13
13
|
body?: any;
|
|
14
|
-
|
|
14
|
+
contentType?: RequestContentType;
|
|
15
|
+
};
|
|
16
|
+
type HttpResponse<Data> = {
|
|
17
|
+
body: Data;
|
|
18
|
+
headers: Record<string, string | string[]>;
|
|
19
|
+
status: number;
|
|
15
20
|
};
|
|
16
21
|
type QuerySerializer = (params: QueryParams) => string;
|
|
17
22
|
|
|
18
23
|
type HttpClient<RequestParams = never> = {
|
|
19
|
-
request: <Data>(req:
|
|
24
|
+
request: <Data>(req: HttpRequest, params?: RequestParams) => Promise<HttpResponse<Data>>;
|
|
20
25
|
};
|
|
21
26
|
|
|
22
27
|
/// <reference lib="esnext.asynciterable" />
|
|
@@ -36,4 +41,4 @@ declare const createHttpClient: (axios: AxiosInstance, opts: {
|
|
|
36
41
|
}) => HttpClient;
|
|
37
42
|
|
|
38
43
|
export { createHttpClient };
|
|
39
|
-
export type { HttpClient as PromiseHttpClient, QuerySerializer };
|
|
44
|
+
export type { HttpResponse, HttpClient as PromiseHttpClient, QuerySerializer };
|
package/dist/browser.d.mts
CHANGED
|
@@ -4,19 +4,24 @@ type KnownRequestContentType = 'application/json' | 'multipart/form-data' | 'app
|
|
|
4
4
|
type RequestContentType = KnownRequestContentType | string;
|
|
5
5
|
type QueryValue = string | number | boolean | null | undefined | QueryValue[] | Record<string, any> | unknown;
|
|
6
6
|
type QueryParams = Record<string, QueryValue>;
|
|
7
|
-
type
|
|
7
|
+
type HttpRequest = {
|
|
8
8
|
path: string;
|
|
9
9
|
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
10
|
-
|
|
10
|
+
responseFormat?: 'json' | 'document';
|
|
11
11
|
headers?: Record<string, string>;
|
|
12
12
|
query?: QueryParams;
|
|
13
13
|
body?: any;
|
|
14
|
-
|
|
14
|
+
contentType?: RequestContentType;
|
|
15
|
+
};
|
|
16
|
+
type HttpResponse<Data> = {
|
|
17
|
+
body: Data;
|
|
18
|
+
headers: Record<string, string | string[]>;
|
|
19
|
+
status: number;
|
|
15
20
|
};
|
|
16
21
|
type QuerySerializer = (params: QueryParams) => string;
|
|
17
22
|
|
|
18
23
|
type HttpClient<RequestParams = never> = {
|
|
19
|
-
request: <Data>(req:
|
|
24
|
+
request: <Data>(req: HttpRequest, params?: RequestParams) => Promise<HttpResponse<Data>>;
|
|
20
25
|
};
|
|
21
26
|
|
|
22
27
|
/// <reference lib="esnext.asynciterable" />
|
|
@@ -36,4 +41,4 @@ declare const createHttpClient: (axios: AxiosInstance, opts: {
|
|
|
36
41
|
}) => HttpClient;
|
|
37
42
|
|
|
38
43
|
export { createHttpClient };
|
|
39
|
-
export type { HttpClient as PromiseHttpClient, QuerySerializer };
|
|
44
|
+
export type { HttpResponse, HttpClient as PromiseHttpClient, QuerySerializer };
|
package/dist/browser.d.ts
CHANGED
|
@@ -4,19 +4,24 @@ type KnownRequestContentType = 'application/json' | 'multipart/form-data' | 'app
|
|
|
4
4
|
type RequestContentType = KnownRequestContentType | string;
|
|
5
5
|
type QueryValue = string | number | boolean | null | undefined | QueryValue[] | Record<string, any> | unknown;
|
|
6
6
|
type QueryParams = Record<string, QueryValue>;
|
|
7
|
-
type
|
|
7
|
+
type HttpRequest = {
|
|
8
8
|
path: string;
|
|
9
9
|
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
10
|
-
|
|
10
|
+
responseFormat?: 'json' | 'document';
|
|
11
11
|
headers?: Record<string, string>;
|
|
12
12
|
query?: QueryParams;
|
|
13
13
|
body?: any;
|
|
14
|
-
|
|
14
|
+
contentType?: RequestContentType;
|
|
15
|
+
};
|
|
16
|
+
type HttpResponse<Data> = {
|
|
17
|
+
body: Data;
|
|
18
|
+
headers: Record<string, string | string[]>;
|
|
19
|
+
status: number;
|
|
15
20
|
};
|
|
16
21
|
type QuerySerializer = (params: QueryParams) => string;
|
|
17
22
|
|
|
18
23
|
type HttpClient<RequestParams = never> = {
|
|
19
|
-
request: <Data>(req:
|
|
24
|
+
request: <Data>(req: HttpRequest, params?: RequestParams) => Promise<HttpResponse<Data>>;
|
|
20
25
|
};
|
|
21
26
|
|
|
22
27
|
/// <reference lib="esnext.asynciterable" />
|
|
@@ -36,4 +41,4 @@ declare const createHttpClient: (axios: AxiosInstance, opts: {
|
|
|
36
41
|
}) => HttpClient;
|
|
37
42
|
|
|
38
43
|
export { createHttpClient };
|
|
39
|
-
export type { HttpClient as PromiseHttpClient, QuerySerializer };
|
|
44
|
+
export type { HttpResponse, HttpClient as PromiseHttpClient, QuerySerializer };
|
package/dist/browser.mjs
CHANGED
|
@@ -164,15 +164,15 @@ const createHttpClient$1 = (axios, opts) => {
|
|
|
164
164
|
return {
|
|
165
165
|
request: (req) => {
|
|
166
166
|
helper.validateRequest(req);
|
|
167
|
-
const { query,
|
|
167
|
+
const { query, contentType, body, headers: reqHeaders } = req;
|
|
168
168
|
const paramsSerializer = querySerializer ? (r) => helper.serializeQuery(r, querySerializer) : void 0;
|
|
169
|
-
const isBlobResponse = req.
|
|
169
|
+
const isBlobResponse = req.responseFormat === "document";
|
|
170
170
|
const headers = { ...reqHeaders || {} };
|
|
171
171
|
let data = body;
|
|
172
|
-
if (
|
|
172
|
+
if (contentType === "multipart/form-data") {
|
|
173
173
|
data = helper.convertToFormData(body);
|
|
174
|
-
} else if (
|
|
175
|
-
headers["Content-Type"] =
|
|
174
|
+
} else if (contentType) {
|
|
175
|
+
headers["Content-Type"] = contentType;
|
|
176
176
|
}
|
|
177
177
|
return axios.request({
|
|
178
178
|
method: req.method,
|
|
@@ -183,22 +183,50 @@ const createHttpClient$1 = (axios, opts) => {
|
|
|
183
183
|
headers,
|
|
184
184
|
responseType: isBlobResponse ? "arraybuffer" : "json"
|
|
185
185
|
}).then((r) => {
|
|
186
|
-
const
|
|
186
|
+
const headers2 = normalizeHeaders(
|
|
187
|
+
r.headers
|
|
188
|
+
);
|
|
189
|
+
const response = {
|
|
190
|
+
body: r.data,
|
|
191
|
+
headers: headers2,
|
|
192
|
+
status: r.status
|
|
193
|
+
};
|
|
187
194
|
if (isBlobResponse) {
|
|
188
|
-
const contDist =
|
|
195
|
+
const contDist = getHeaderValue(
|
|
196
|
+
headers2["content-disposition"]
|
|
197
|
+
);
|
|
189
198
|
const fileName = helper.getFileNameFromContentDispositionHeader(
|
|
190
199
|
contDist
|
|
191
200
|
);
|
|
192
|
-
const type =
|
|
193
|
-
return
|
|
194
|
-
|
|
195
|
-
|
|
201
|
+
const type = getHeaderValue(headers2["content-type"]);
|
|
202
|
+
return {
|
|
203
|
+
...response,
|
|
204
|
+
body: new File([r.data], fileName, {
|
|
205
|
+
type
|
|
206
|
+
})
|
|
207
|
+
};
|
|
196
208
|
}
|
|
197
|
-
return
|
|
209
|
+
return response;
|
|
198
210
|
});
|
|
199
211
|
}
|
|
200
212
|
};
|
|
201
213
|
};
|
|
214
|
+
const normalizeHeaders = (headers) => {
|
|
215
|
+
const normalized = {};
|
|
216
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
217
|
+
if (value == null) {
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
normalized[key.toLowerCase()] = Array.isArray(value) ? value.map(String) : String(value);
|
|
221
|
+
}
|
|
222
|
+
return normalized;
|
|
223
|
+
};
|
|
224
|
+
const getHeaderValue = (header) => {
|
|
225
|
+
if (Array.isArray(header)) {
|
|
226
|
+
return header[0];
|
|
227
|
+
}
|
|
228
|
+
return header;
|
|
229
|
+
};
|
|
202
230
|
|
|
203
231
|
const createHttpClient = (axios, opts) => {
|
|
204
232
|
return createHttpClient$1(axios, {
|
package/dist/node.cjs
CHANGED
|
@@ -166,15 +166,15 @@ const createHttpClient$1 = (axios, opts) => {
|
|
|
166
166
|
return {
|
|
167
167
|
request: (req) => {
|
|
168
168
|
helper.validateRequest(req);
|
|
169
|
-
const { query,
|
|
169
|
+
const { query, contentType, body, headers: reqHeaders } = req;
|
|
170
170
|
const paramsSerializer = querySerializer ? (r) => helper.serializeQuery(r, querySerializer) : void 0;
|
|
171
|
-
const isBlobResponse = req.
|
|
171
|
+
const isBlobResponse = req.responseFormat === "document";
|
|
172
172
|
const headers = { ...reqHeaders || {} };
|
|
173
173
|
let data = body;
|
|
174
|
-
if (
|
|
174
|
+
if (contentType === "multipart/form-data") {
|
|
175
175
|
data = helper.convertToFormData(body);
|
|
176
|
-
} else if (
|
|
177
|
-
headers["Content-Type"] =
|
|
176
|
+
} else if (contentType) {
|
|
177
|
+
headers["Content-Type"] = contentType;
|
|
178
178
|
}
|
|
179
179
|
return axios.request({
|
|
180
180
|
method: req.method,
|
|
@@ -185,22 +185,50 @@ const createHttpClient$1 = (axios, opts) => {
|
|
|
185
185
|
headers,
|
|
186
186
|
responseType: isBlobResponse ? "arraybuffer" : "json"
|
|
187
187
|
}).then((r) => {
|
|
188
|
-
const
|
|
188
|
+
const headers2 = normalizeHeaders(
|
|
189
|
+
r.headers
|
|
190
|
+
);
|
|
191
|
+
const response = {
|
|
192
|
+
body: r.data,
|
|
193
|
+
headers: headers2,
|
|
194
|
+
status: r.status
|
|
195
|
+
};
|
|
189
196
|
if (isBlobResponse) {
|
|
190
|
-
const contDist =
|
|
197
|
+
const contDist = getHeaderValue(
|
|
198
|
+
headers2["content-disposition"]
|
|
199
|
+
);
|
|
191
200
|
const fileName = helper.getFileNameFromContentDispositionHeader(
|
|
192
201
|
contDist
|
|
193
202
|
);
|
|
194
|
-
const type =
|
|
195
|
-
return
|
|
196
|
-
|
|
197
|
-
|
|
203
|
+
const type = getHeaderValue(headers2["content-type"]);
|
|
204
|
+
return {
|
|
205
|
+
...response,
|
|
206
|
+
body: new File([r.data], fileName, {
|
|
207
|
+
type
|
|
208
|
+
})
|
|
209
|
+
};
|
|
198
210
|
}
|
|
199
|
-
return
|
|
211
|
+
return response;
|
|
200
212
|
});
|
|
201
213
|
}
|
|
202
214
|
};
|
|
203
215
|
};
|
|
216
|
+
const normalizeHeaders = (headers) => {
|
|
217
|
+
const normalized = {};
|
|
218
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
219
|
+
if (value == null) {
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
normalized[key.toLowerCase()] = Array.isArray(value) ? value.map(String) : String(value);
|
|
223
|
+
}
|
|
224
|
+
return normalized;
|
|
225
|
+
};
|
|
226
|
+
const getHeaderValue = (header) => {
|
|
227
|
+
if (Array.isArray(header)) {
|
|
228
|
+
return header[0];
|
|
229
|
+
}
|
|
230
|
+
return header;
|
|
231
|
+
};
|
|
204
232
|
|
|
205
233
|
const createHttpClient = (axios, opts) => {
|
|
206
234
|
return createHttpClient$1(axios, {
|
package/dist/node.d.cts
CHANGED
|
@@ -4,19 +4,24 @@ type KnownRequestContentType = 'application/json' | 'multipart/form-data' | 'app
|
|
|
4
4
|
type RequestContentType = KnownRequestContentType | string;
|
|
5
5
|
type QueryValue = string | number | boolean | null | undefined | QueryValue[] | Record<string, any> | unknown;
|
|
6
6
|
type QueryParams = Record<string, QueryValue>;
|
|
7
|
-
type
|
|
7
|
+
type HttpRequest = {
|
|
8
8
|
path: string;
|
|
9
9
|
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
10
|
-
|
|
10
|
+
responseFormat?: 'json' | 'document';
|
|
11
11
|
headers?: Record<string, string>;
|
|
12
12
|
query?: QueryParams;
|
|
13
13
|
body?: any;
|
|
14
|
-
|
|
14
|
+
contentType?: RequestContentType;
|
|
15
|
+
};
|
|
16
|
+
type HttpResponse<Data> = {
|
|
17
|
+
body: Data;
|
|
18
|
+
headers: Record<string, string | string[]>;
|
|
19
|
+
status: number;
|
|
15
20
|
};
|
|
16
21
|
type QuerySerializer = (params: QueryParams) => string;
|
|
17
22
|
|
|
18
23
|
type HttpClient<RequestParams = never> = {
|
|
19
|
-
request: <Data>(req:
|
|
24
|
+
request: <Data>(req: HttpRequest, params?: RequestParams) => Promise<HttpResponse<Data>>;
|
|
20
25
|
};
|
|
21
26
|
|
|
22
27
|
/// <reference lib="esnext.asynciterable" />
|
|
@@ -36,4 +41,4 @@ declare const createHttpClient: (axios: AxiosInstance, opts: {
|
|
|
36
41
|
}) => HttpClient;
|
|
37
42
|
|
|
38
43
|
export { createHttpClient };
|
|
39
|
-
export type { HttpClient as PromiseHttpClient, QuerySerializer };
|
|
44
|
+
export type { HttpResponse, HttpClient as PromiseHttpClient, QuerySerializer };
|
package/dist/node.d.mts
CHANGED
|
@@ -4,19 +4,24 @@ type KnownRequestContentType = 'application/json' | 'multipart/form-data' | 'app
|
|
|
4
4
|
type RequestContentType = KnownRequestContentType | string;
|
|
5
5
|
type QueryValue = string | number | boolean | null | undefined | QueryValue[] | Record<string, any> | unknown;
|
|
6
6
|
type QueryParams = Record<string, QueryValue>;
|
|
7
|
-
type
|
|
7
|
+
type HttpRequest = {
|
|
8
8
|
path: string;
|
|
9
9
|
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
10
|
-
|
|
10
|
+
responseFormat?: 'json' | 'document';
|
|
11
11
|
headers?: Record<string, string>;
|
|
12
12
|
query?: QueryParams;
|
|
13
13
|
body?: any;
|
|
14
|
-
|
|
14
|
+
contentType?: RequestContentType;
|
|
15
|
+
};
|
|
16
|
+
type HttpResponse<Data> = {
|
|
17
|
+
body: Data;
|
|
18
|
+
headers: Record<string, string | string[]>;
|
|
19
|
+
status: number;
|
|
15
20
|
};
|
|
16
21
|
type QuerySerializer = (params: QueryParams) => string;
|
|
17
22
|
|
|
18
23
|
type HttpClient<RequestParams = never> = {
|
|
19
|
-
request: <Data>(req:
|
|
24
|
+
request: <Data>(req: HttpRequest, params?: RequestParams) => Promise<HttpResponse<Data>>;
|
|
20
25
|
};
|
|
21
26
|
|
|
22
27
|
/// <reference lib="esnext.asynciterable" />
|
|
@@ -36,4 +41,4 @@ declare const createHttpClient: (axios: AxiosInstance, opts: {
|
|
|
36
41
|
}) => HttpClient;
|
|
37
42
|
|
|
38
43
|
export { createHttpClient };
|
|
39
|
-
export type { HttpClient as PromiseHttpClient, QuerySerializer };
|
|
44
|
+
export type { HttpResponse, HttpClient as PromiseHttpClient, QuerySerializer };
|
package/dist/node.d.ts
CHANGED
|
@@ -4,19 +4,24 @@ type KnownRequestContentType = 'application/json' | 'multipart/form-data' | 'app
|
|
|
4
4
|
type RequestContentType = KnownRequestContentType | string;
|
|
5
5
|
type QueryValue = string | number | boolean | null | undefined | QueryValue[] | Record<string, any> | unknown;
|
|
6
6
|
type QueryParams = Record<string, QueryValue>;
|
|
7
|
-
type
|
|
7
|
+
type HttpRequest = {
|
|
8
8
|
path: string;
|
|
9
9
|
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
10
|
-
|
|
10
|
+
responseFormat?: 'json' | 'document';
|
|
11
11
|
headers?: Record<string, string>;
|
|
12
12
|
query?: QueryParams;
|
|
13
13
|
body?: any;
|
|
14
|
-
|
|
14
|
+
contentType?: RequestContentType;
|
|
15
|
+
};
|
|
16
|
+
type HttpResponse<Data> = {
|
|
17
|
+
body: Data;
|
|
18
|
+
headers: Record<string, string | string[]>;
|
|
19
|
+
status: number;
|
|
15
20
|
};
|
|
16
21
|
type QuerySerializer = (params: QueryParams) => string;
|
|
17
22
|
|
|
18
23
|
type HttpClient<RequestParams = never> = {
|
|
19
|
-
request: <Data>(req:
|
|
24
|
+
request: <Data>(req: HttpRequest, params?: RequestParams) => Promise<HttpResponse<Data>>;
|
|
20
25
|
};
|
|
21
26
|
|
|
22
27
|
/// <reference lib="esnext.asynciterable" />
|
|
@@ -36,4 +41,4 @@ declare const createHttpClient: (axios: AxiosInstance, opts: {
|
|
|
36
41
|
}) => HttpClient;
|
|
37
42
|
|
|
38
43
|
export { createHttpClient };
|
|
39
|
-
export type { HttpClient as PromiseHttpClient, QuerySerializer };
|
|
44
|
+
export type { HttpResponse, HttpClient as PromiseHttpClient, QuerySerializer };
|
package/dist/node.mjs
CHANGED
|
@@ -164,15 +164,15 @@ const createHttpClient$1 = (axios, opts) => {
|
|
|
164
164
|
return {
|
|
165
165
|
request: (req) => {
|
|
166
166
|
helper.validateRequest(req);
|
|
167
|
-
const { query,
|
|
167
|
+
const { query, contentType, body, headers: reqHeaders } = req;
|
|
168
168
|
const paramsSerializer = querySerializer ? (r) => helper.serializeQuery(r, querySerializer) : void 0;
|
|
169
|
-
const isBlobResponse = req.
|
|
169
|
+
const isBlobResponse = req.responseFormat === "document";
|
|
170
170
|
const headers = { ...reqHeaders || {} };
|
|
171
171
|
let data = body;
|
|
172
|
-
if (
|
|
172
|
+
if (contentType === "multipart/form-data") {
|
|
173
173
|
data = helper.convertToFormData(body);
|
|
174
|
-
} else if (
|
|
175
|
-
headers["Content-Type"] =
|
|
174
|
+
} else if (contentType) {
|
|
175
|
+
headers["Content-Type"] = contentType;
|
|
176
176
|
}
|
|
177
177
|
return axios.request({
|
|
178
178
|
method: req.method,
|
|
@@ -183,22 +183,50 @@ const createHttpClient$1 = (axios, opts) => {
|
|
|
183
183
|
headers,
|
|
184
184
|
responseType: isBlobResponse ? "arraybuffer" : "json"
|
|
185
185
|
}).then((r) => {
|
|
186
|
-
const
|
|
186
|
+
const headers2 = normalizeHeaders(
|
|
187
|
+
r.headers
|
|
188
|
+
);
|
|
189
|
+
const response = {
|
|
190
|
+
body: r.data,
|
|
191
|
+
headers: headers2,
|
|
192
|
+
status: r.status
|
|
193
|
+
};
|
|
187
194
|
if (isBlobResponse) {
|
|
188
|
-
const contDist =
|
|
195
|
+
const contDist = getHeaderValue(
|
|
196
|
+
headers2["content-disposition"]
|
|
197
|
+
);
|
|
189
198
|
const fileName = helper.getFileNameFromContentDispositionHeader(
|
|
190
199
|
contDist
|
|
191
200
|
);
|
|
192
|
-
const type =
|
|
193
|
-
return
|
|
194
|
-
|
|
195
|
-
|
|
201
|
+
const type = getHeaderValue(headers2["content-type"]);
|
|
202
|
+
return {
|
|
203
|
+
...response,
|
|
204
|
+
body: new File([r.data], fileName, {
|
|
205
|
+
type
|
|
206
|
+
})
|
|
207
|
+
};
|
|
196
208
|
}
|
|
197
|
-
return
|
|
209
|
+
return response;
|
|
198
210
|
});
|
|
199
211
|
}
|
|
200
212
|
};
|
|
201
213
|
};
|
|
214
|
+
const normalizeHeaders = (headers) => {
|
|
215
|
+
const normalized = {};
|
|
216
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
217
|
+
if (value == null) {
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
normalized[key.toLowerCase()] = Array.isArray(value) ? value.map(String) : String(value);
|
|
221
|
+
}
|
|
222
|
+
return normalized;
|
|
223
|
+
};
|
|
224
|
+
const getHeaderValue = (header) => {
|
|
225
|
+
if (Array.isArray(header)) {
|
|
226
|
+
return header[0];
|
|
227
|
+
}
|
|
228
|
+
return header;
|
|
229
|
+
};
|
|
202
230
|
|
|
203
231
|
const createHttpClient = (axios, opts) => {
|
|
204
232
|
return createHttpClient$1(axios, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ps-aux/api-client-axios",
|
|
3
|
-
"version": "0.7.0-rc.
|
|
3
|
+
"version": "0.7.0-rc.4",
|
|
4
4
|
"main": "dist/node.cjs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
"author": "psaux",
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
"axios": "^1.
|
|
18
|
+
"axios": "^1.16.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"axios": "^1.
|
|
21
|
+
"axios": "^1.16.0"
|
|
22
22
|
},
|
|
23
23
|
"description": "Axios-based HTTP client for OpenAPI-generated APIs (Node and browser builds).",
|
|
24
24
|
"keywords": [
|