fastify-flux-cli 2.20.0 → 2.21.0
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/package.json
CHANGED
|
@@ -24,8 +24,6 @@ export interface FullRequestParams extends Omit<AxiosRequestConfig, "data" | "pa
|
|
|
24
24
|
export type RequestParams = Omit<FullRequestParams, "body" | "method" | "query" | "path">;
|
|
25
25
|
|
|
26
26
|
export interface ApiConfig<SecurityDataType = unknown> extends Omit<AxiosRequestConfig, "data" | "cancelToken"> {
|
|
27
|
-
securityWorker?: (securityData: SecurityDataType | null) => Promise<AxiosRequestConfig | void> | AxiosRequestConfig | void;
|
|
28
|
-
secure?: boolean;
|
|
29
27
|
format?: ResponseType;
|
|
30
28
|
}
|
|
31
29
|
|
|
@@ -37,51 +35,14 @@ export enum ContentType {
|
|
|
37
35
|
|
|
38
36
|
export class HttpClient<SecurityDataType = unknown> {
|
|
39
37
|
public instance: AxiosInstance;
|
|
40
|
-
private securityData: SecurityDataType | null = null;
|
|
41
|
-
private securityWorker?: ApiConfig<SecurityDataType>["securityWorker"];
|
|
42
|
-
private secure?: boolean;
|
|
43
38
|
private format?: ResponseType;
|
|
44
39
|
|
|
45
|
-
constructor({
|
|
40
|
+
constructor({ format, ...axiosConfig }: ApiConfig<SecurityDataType> = {}) {
|
|
46
41
|
this.instance = axios.create({ ...axiosConfig, baseURL: axiosConfig.baseURL || "<%~ apiConfig.baseUrl %>" })
|
|
47
|
-
this.secure = secure;
|
|
48
42
|
this.format = format;
|
|
49
|
-
this.securityWorker = securityWorker;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
public setSecurityData = (data: SecurityDataType | null) => {
|
|
53
|
-
this.securityData = data
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
private mergeRequestParams(params1: AxiosRequestConfig, params2?: AxiosRequestConfig): AxiosRequestConfig {
|
|
57
|
-
return {
|
|
58
|
-
...this.instance.defaults,
|
|
59
|
-
...params1,
|
|
60
|
-
...(params2 || {}),
|
|
61
|
-
headers: {
|
|
62
|
-
...(params1.headers || {}),
|
|
63
|
-
...((params2 && params2.headers) || {}),
|
|
64
|
-
},
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
private createFormData(input: Record<string, unknown>): FormData {
|
|
69
|
-
return Object.keys(input || {}).reduce((formData, key) => {
|
|
70
|
-
const property = input[key];
|
|
71
|
-
formData.append(
|
|
72
|
-
key,
|
|
73
|
-
property instanceof Blob ?
|
|
74
|
-
property :
|
|
75
|
-
typeof property === "object" && property !== null ?
|
|
76
|
-
JSON.stringify(property) :
|
|
77
|
-
`${property}`
|
|
78
|
-
);
|
|
79
|
-
return formData;
|
|
80
|
-
}, new FormData())
|
|
81
43
|
}
|
|
82
44
|
|
|
83
45
|
public request = async <T = any, _E = any>({
|
|
84
|
-
secure,
|
|
85
46
|
path,
|
|
86
47
|
type,
|
|
87
48
|
query,
|
|
@@ -89,13 +50,9 @@ export class HttpClient<SecurityDataType = unknown> {
|
|
|
89
50
|
body,
|
|
90
51
|
...params
|
|
91
52
|
}: FullRequestParams): Promise<T> => {
|
|
92
|
-
const
|
|
93
|
-
const requestParams = this.mergeRequestParams(params, secureParams);
|
|
53
|
+
const requestParams = params;
|
|
94
54
|
const responseFormat = (format && this.format) || void 0;
|
|
95
55
|
|
|
96
|
-
if (type === ContentType.FormData && body && body !== null && typeof body === "object") {
|
|
97
|
-
body = this.createFormData(body as Record<string, unknown>);
|
|
98
|
-
}
|
|
99
56
|
|
|
100
57
|
if (!type) {
|
|
101
58
|
type = ContentType.Json;
|